Mediatek MT8173 CMDQ support
Subsystems (2)
v13 cover Mediatek MT8173 CMDQ support
Hi,
This is Mediatek MT8173 Command Queue(CMDQ) driver. The CMDQ is used to help write registers with critical time limitation, such as updating display configuration during the vblank. It controls Global Command Engine (GCE) hardware to achieve this requirement.
These patches have a build dependency on top of v4.8-rc1.
Changes since v12:
- remove mediatek,gce from device tree
Best regards,
HS Liao
HS Liao (4):
dt-bindings: soc: Add documentation for the MediaTek GCE unit
CMDQ: Mediatek CMDQ driver
arm64: dts: mt8173: Add GCE node
CMDQ: save more energy in idle
.../devicetree/bindings/soc/mediatek/gce.txt | 44 + arch/arm64/boot/dts/mediatek/mt8173.dtsi | 10 + drivers/soc/mediatek/Kconfig | 11 + drivers/soc/mediatek/Makefile | 1 + drivers/soc/mediatek/mtk-cmdq.c | 983 +++++++++++++++++++++ include/soc/mediatek/cmdq.h | 180 ++++ 6 files changed, 1229 insertions(+) create mode 100644 Documentation/devicetree/bindings/soc/mediatek/gce.txt create mode 100644 drivers/soc/mediatek/mtk-cmdq.c create mode 100644 include/soc/mediatek/cmdq.h
Signature · 1 line
1.9.1
PATCH v13 1/4 dt-bindings: soc: Add documentation for the MediaTek GCE unit
This adds documentation for the MediaTek Global Command Engine (GCE) unit found in MT8173 SoCs.
--- .../devicetree/bindings/soc/mediatek/gce.txt | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Documentation/devicetree/bindings/soc/mediatek/gce.txt
Documentation/devicetree/bindings/soc/mediatek/gce.txt new file +44 -0
@@ -0,0 +1,44 @@ +MediaTek GCE +=============== + +The Global Command Engine (GCE) is used to help read/write registers with +critical time limitation, such as updating display configuration during the +vblank. The GCE can be used to implement the Command Queue (CMDQ) driver. + +CMDQ driver uses mailbox framework for communication. Please refer to +../../mailbox/mailbox.txt for generic information about mailbox device-tree +bindings. + +Required properties: +- compatible: Must be "mediatek,mt8173-gce" +- reg: Address range of the GCE unit +- interrupts: The interrupt signal from the GCE block +- clock: Clocks according to the common clock binding +- clock-names: Must be "gce" to stand for GCE clock +- #mbox-cells: Should be 2 + +Required properties for a client device: +- mboxes: client use mailbox to communicate with GCE, it should have this + property and list of phandle, mailbox channel specifiers, and atomic + execution flag. + +Example: + + gce: gce at 10212000 { + compatible = "mediatek,mt8173-gce"; + reg = <0 0x10212000 0 0x1000>; + interrupts = <GIC_SPI 135 IRQ_TYPE_LEVEL_LOW>; + clocks = <&infracfg CLK_INFRA_GCE>; + clock-names = "gce"; + + #mbox-cells = <2>; + }; + +Example for a client device: + + mmsys: clock-controller at 14000000 { + compatible = "mediatek,mt8173-mmsys"; + mboxes = <&gce 0 1 /* main display with atomic execution */ + &gce 1 1>; /* sub display with atomic execution */ + ... + };
Signature · 1 line
1.9.1
PATCH v13 2/4 CMDQ: Mediatek CMDQ driver
In reply to HS LiaoThis patch is first version of Mediatek Command Queue(CMDQ) driver. The CMDQ is used to help write registers with critical time limitation, such as updating display configuration during the vblank. It controls Global Command Engine (GCE) hardware to achieve this requirement. Currently, CMDQ only supports display related hardwares, but we expect it can be extended to other hardwares for future requirements.
--- drivers/soc/mediatek/Kconfig | 11 + drivers/soc/mediatek/Makefile | 1 + drivers/soc/mediatek/mtk-cmdq.c | 945 ++++++++++++++++++++++++++++++++++++++++ include/soc/mediatek/cmdq.h | 180 ++++++++ 4 files changed, 1137 insertions(+) create mode 100644 drivers/soc/mediatek/mtk-cmdq.c create mode 100644 include/soc/mediatek/cmdq.h
drivers/soc/mediatek/Kconfig +11 -0
@@ -1,6 +1,17 @@ # # MediaTek SoC drivers # +config MTK_CMDQ + bool "MediaTek CMDQ Support" + depends on ARM64 && ( ARCH_MEDIATEK || COMPILE_TEST ) + select MAILBOX + select MTK_INFRACFG + help + Say yes here to add support for the MediaTek Command Queue (CMDQ) + driver. The CMDQ is used to help read/write registers with critical + time limitation, such as updating display configuration during the + vblank. + config MTK_INFRACFG bool "MediaTek INFRACFG Support" depends on ARCH_MEDIATEK || COMPILE_TEST
drivers/soc/mediatek/Makefile +1 -0
@@ -1,3 +1,4 @@ +obj-$(CONFIG_MTK_CMDQ) += mtk-cmdq.o obj-$(CONFIG_MTK_INFRACFG) += mtk-infracfg.o obj-$(CONFIG_MTK_PMIC_WRAP) += mtk-pmic-wrap.o obj-$(CONFIG_MTK_SCPSYS) += mtk-scpsys.o
drivers/soc/mediatek/mtk-cmdq.c new file +945 -0
945 lines not on this page · raw message
include/soc/mediatek/cmdq.h new file +180 -0
180 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v13 3/4 arm64: dts: mt8173: Add GCE node
In reply to HS LiaoThis patch adds the device node of the GCE hardware for CMDQ module.
--- arch/arm64/boot/dts/mediatek/mt8173.dtsi | 10 ++++++++++ 1 file changed, 10 insertions(+)
arch/arm64/boot/dts/mediatek/mt8173.dtsi +10 -0
@@ -383,6 +383,16 @@ #clock-cells = <1>; }; + gce: gce at 10212000 { + compatible = "mediatek,mt8173-gce"; + reg = <0 0x10212000 0 0x1000>; + interrupts = <GIC_SPI 135 IRQ_TYPE_LEVEL_LOW>; + clocks = <&infracfg CLK_INFRA_GCE>; + clock-names = "gce"; + + #mbox-cells = <2>; + }; + mipi_tx0: mipi-dphy at 10215000 { compatible = "mediatek,mt8173-mipi-tx"; reg = <0 0x10215000 0 0x1000>;
Signature · 1 line
1.9.1
PATCH v13 4/4 CMDQ: save more energy in idle
In reply to HS LiaoUse clk_disable_unprepare instead of clk_disable to save more energy when CMDQ is idle.
--- drivers/soc/mediatek/mtk-cmdq.c | 54 +++++++++++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 8 deletions(-)
drivers/soc/mediatek/mtk-cmdq.c +46 -8
@@ -28,6 +28,7 @@#include <linux/spinlock.h> #include <linux/suspend.h> #include <linux/timer.h> +#include <linux/workqueue.h> #include <soc/mediatek/cmdq.h> #define CMDQ_THR_MAX_COUNT 3/* main, sub, general(misc) */
@@ -128,10 +129,16 @@ struct cmdq_task {struct cmdq_task_cb cb; }; +struct cmdq_clk_release { +struct cmdq *cmdq; +struct work_struct release_work; +}; +struct cmdq {struct mbox_controller mbox;void __iomem *base;u32 irq; +struct workqueue_struct *clk_release_wq;struct cmdq_thread thread[CMDQ_THR_MAX_COUNT ];struct mutex task_mutex;struct clk *clock;
@@ -297,11 +304,19 @@ static void cmdq_thread_wait_end(struct cmdq_thread *thread,static void cmdq_task_exec (struct cmdq_task *task,struct cmdq_thread *thread) {struct cmdq *cmdq = task->cmdq; -unsigned long curr_pa, end_pa; +unsigned long curr_pa, end_pa, flags; task->thread = thread;if (list_empty (&thread->task_busy_list)) { -WARN_ON (clk_enable (cmdq->clock) <0 ); +/* +* Unlock for clk prepare (sleeping function). +* We are safe to do that since we have task_mutex and +* only flush will add task. +*/ +spin_unlock_irqrestore (&thread->chan->lock, flags); +WARN_ON (clk_prepare_enable (cmdq->clock) <0 ); +spin_lock_irqsave (&thread->chan->lock, flags); +WARN_ON (cmdq_thread_reset (cmdq, thread) <0 );writel (task->pa_base, thread->base +CMDQ_THR_CURR_ADDR );
@@ -383,6 +398,26 @@ static void cmdq_task_handle_error(struct cmdq_task *task)cmdq_thread_resume (thread); } +static void cmdq_clk_release_work (struct work_struct *work_item) +{ +struct cmdq_clk_release *clk_release =container_of (work_item, + struct cmdq_clk_release, release_work); +struct cmdq *cmdq = clk_release->cmdq; + +clk_disable_unprepare (cmdq->clock); +kfree (clk_release); +} + +static void cmdq_clk_release_schedule (struct cmdq *cmdq) +{ +struct cmdq_clk_release *clk_release; + + clk_release =kmalloc (sizeof (*clk_release),GFP_ATOMIC ); + clk_release->cmdq = cmdq; +INIT_WORK (&clk_release->release_work, cmdq_clk_release_work); +queue_work (cmdq->clk_release_wq, &clk_release->release_work); +} +static void cmdq_thread_irq_handler (struct cmdq *cmdq,struct cmdq_thread *thread) {
@@ -432,7 +467,7 @@ static void cmdq_thread_irq_handler(struct cmdq *cmdq,if (list_empty (&thread->task_busy_list)) {cmdq_thread_disable (cmdq, thread); -clk_disable (cmdq->clock); +cmdq_clk_release_schedule (cmdq); }else {mod_timer (&thread->timeout, jiffies +msecs_to_jiffies (CMDQ_TIMEOUT_MS ));
@@ -491,7 +526,7 @@ static void cmdq_thread_handle_timeout(unsigned long data)cmdq_thread_resume (thread);cmdq_thread_disable (cmdq, thread); -clk_disable (cmdq->clock); +cmdq_clk_release_schedule (cmdq);spin_unlock_irqrestore (&thread->chan->lock, flags); }
@@ -779,7 +814,7 @@ static int cmdq_suspend(struct device *dev)msleep (20 ); } -clk_unprepare (cmdq->clock); +flush_workqueue (cmdq->clk_release_wq);return 0 ; }
@@ -787,7 +822,6 @@ static int cmdq_resume(struct device *dev) {struct cmdq *cmdq =dev_get_drvdata (dev); -WARN_ON (clk_prepare (cmdq->clock) <0 ); cmdq->suspended = false;return 0 ; }
@@ -796,8 +830,8 @@ static int cmdq_remove(struct platform_device *pdev) {struct cmdq *cmdq =platform_get_drvdata (pdev); +destroy_workqueue (cmdq->clk_release_wq);mbox_controller_unregister (&cmdq->mbox); -clk_unprepare (cmdq->clock);return 0 ; }
@@ -916,8 +950,12 @@ static int cmdq_probe(struct platform_device *pdev)return err; } + cmdq->clk_release_wq =alloc_ordered_workqueue ( +"%s" ,WQ_MEM_RECLAIM |WQ_HIGHPRI , +"cmdq_clk_release" ); +platform_set_drvdata (pdev, cmdq); -WARN_ON (clk_prepare (cmdq->clock) <0 ); +return 0 ; }
Signature · 1 line
1.9.1
Matthias Brugger
maintainerQuoted 8 lines · HS Liao
Hi,
This is Mediatek MT8173 Command Queue(CMDQ) driver. The CMDQ is used to help write registers with critical time limitation, such as updating display configuration during the vblank. It controls Global Command Engine (GCE) hardware to achieve this requirement.
Quoted 4 lines
These patches have a build dependency on top of v4.8-rc1.
Changes since v12:
- remove mediatek,gce from device tree
Why? The binding got accepted by Rob.
Quoted 10 lines
Best regards,
HS LiaoHS Liao (4):
dt-bindings: soc: Add documentation for the MediaTek GCE unit
CMDQ: Mediatek CMDQ driver
arm64: dts: mt8173: Add GCE node
CMDQ: save more energy in idle
Quoted 5 lines
.../devicetree/bindings/soc/mediatek/gce.txt | 44 + arch/arm64/boot/dts/mediatek/mt8173.dtsi | 10 + drivers/soc/mediatek/Kconfig | 11 + drivers/soc/mediatek/Makefile | 1 + drivers/soc/mediatek/mtk-cmdq.c | 983 +++++++++++++++++++++
The driver uses the mailbox framework, so it should live in the drivers/mailbox folder.
Please don't forget to add Jassi to the loop, as he is the maintainer of this subsystem and the last instance to decide if/when the driver will get accepted.
Thanks,
Matthias
Quoted 6 lines
include/soc/mediatek/cmdq.h | 180 ++++ 6 files changed, 1229 insertions(+) create mode 100644 Documentation/devicetree/bindings/soc/mediatek/gce.txt create mode 100644 drivers/soc/mediatek/mtk-cmdq.c create mode 100644 include/soc/mediatek/cmdq.h
Hi Matthias,
Quoted 1 line · Matthias Brugger
On 24/08/16 05:27, HS Liao wrote:
[...]
Quoted 4 lines
Quoted 2 lines
Changes since v12:
- remove mediatek,gce from device treeWhy? The binding got accepted by Rob.
We can get cmdq dev from mailbox controller,
so we don't need mediatek,gce anymore.
Quoted 10 lines
Quoted 10 lines
Best regards,
HS LiaoHS Liao (4):
dt-bindings: soc: Add documentation for the MediaTek GCE unit
CMDQ: Mediatek CMDQ driver
arm64: dts: mt8173: Add GCE node
CMDQ: save more energy in idle
Quoted 8 lines
Quoted 5 lines
.../devicetree/bindings/soc/mediatek/gce.txt | 44 + arch/arm64/boot/dts/mediatek/mt8173.dtsi | 10 + drivers/soc/mediatek/Kconfig | 11 + drivers/soc/mediatek/Makefile | 1 + drivers/soc/mediatek/mtk-cmdq.c | 983 +++++++++++++++++++++The driver uses the mailbox framework, so it should live in the
drivers/mailboxfolder.
As you know, the maximum number of gce threads is 16. However, we plan to support more clients in the future, and they may need to use more than 16 gce threads.
For this issue, our plan is to let multiple clients share the same gce thread; i.e. we will acquire gce thread for client dynamically by internal policy in cmdq driver.
Unfortunately. mailbox channel has exclusive feature.
Quote from comment of mbox_request_channel().
"The channel is exclusively allocated and can't be used by another client before the owner calls mbox_free_channel." Therefore, we plan to remove mailbox framework from cmdq driver in the future.
For current status, could you tell us your preference?
(1) Move cmdq to mailbox folder and then move it back here when we submit another patch to support more than 16 gce clients; or
(2) Remove mailbox framework from cmdq now for its future extensibility.
Thanks,
HS
Quoted 7 lines
Please don't forget to add Jassi to the loop, as he is the maintainer of this subsystem and the last instance to decide if/when the driver will get accepted.
Thanks,
Matthias
Quoted 36 lines · Horng-Shyang Liao
Hi Matthias,
Quoted 1 line · Matthias Brugger
On 24/08/16 05:27, HS Liao wrote:
[...]
Quoted 4 lines
Quoted 2 lines
Changes since v12:
- remove mediatek,gce from device treeWhy? The binding got accepted by Rob.
We can get cmdq dev from mailbox controller,
so we don't need mediatek,gce anymore.Quoted 10 lines
Quoted 10 lines
Best regards,
HS LiaoHS Liao (4):
dt-bindings: soc: Add documentation for the MediaTek GCE unit
CMDQ: Mediatek CMDQ driver
arm64: dts: mt8173: Add GCE node
CMDQ: save more energy in idleQuoted 8 lines
Quoted 5 lines
.../devicetree/bindings/soc/mediatek/gce.txt | 44 + arch/arm64/boot/dts/mediatek/mt8173.dtsi | 10 + drivers/soc/mediatek/Kconfig | 11 + drivers/soc/mediatek/Makefile | 1 + drivers/soc/mediatek/mtk-cmdq.c | 983 +++++++++++++++++++++The driver uses the mailbox framework, so it should live in the
drivers/mailboxfolder.As you know, the maximum number of gce threads is 16. However, we plan to support more clients in the future, and they may need to use more than 16 gce threads.
Quoted 10 lines
For this issue, our plan is to let multiple clients share the same gce thread; i.e. we will acquire gce thread for client dynamically by internal policy in cmdq driver.
Unfortunately. mailbox channel has exclusive feature.
Quote from comment ofmbox_request_channel().
"The channel is exclusively allocated and can't be used by another client before the owner callsmbox_free_channel." Therefore, we plan to remove mailbox framework from cmdq driver in the future.
Platforms that need shared access to a channel, implement a 'server' driver that serialise (which is needed still) the access to common channel. If you think you don't need mutual exclusion and don't care about replies, simply share the mailbox handle among different clients.
Hi Jassi,
Quoted 5 lines · Jassi Brar
Quoted 4 lines · Horng-Shyang Liao
Hi Matthias,
Quoted 1 line · Matthias Brugger
On 24/08/16 05:27, HS Liao wrote:
[...]
Quoted 29 lines
Quoted 19 lines
Quoted 6 lines
Quoted 6 lines
HS Liao (4):
dt-bindings: soc: Add documentation for the MediaTek GCE unit
CMDQ: Mediatek CMDQ driver
arm64: dts: mt8173: Add GCE node
CMDQ: save more energy in idleQuoted 8 lines
Quoted 5 lines
.../devicetree/bindings/soc/mediatek/gce.txt | 44 + arch/arm64/boot/dts/mediatek/mt8173.dtsi | 10 + drivers/soc/mediatek/Kconfig | 11 + drivers/soc/mediatek/Makefile | 1 + drivers/soc/mediatek/mtk-cmdq.c | 983 +++++++++++++++++++++The driver uses the mailbox framework, so it should live in the
drivers/mailboxfolder.As you know, the maximum number of gce threads is 16. However, we plan to support more clients in the future, and they may need to use more than 16 gce threads.
Quoted 10 lines
For this issue, our plan is to let multiple clients share the same gce thread; i.e. we will acquire gce thread for client dynamically by internal policy in cmdq driver.
Unfortunately. mailbox channel has exclusive feature.
Quote from comment ofmbox_request_channel().
"The channel is exclusively allocated and can't be used by another client before the owner callsmbox_free_channel." Therefore, we plan to remove mailbox framework from cmdq driver in the future.
Quoted 5 lines
Platforms that need shared access to a channel, implement a 'server' driver that serialise (which is needed still) the access to common channel. If you think you don't need mutual exclusion and don't care about replies, simply share the mailbox handle among different clients.
Thank you for your kindly reply.
We would like to discuss further with you on this topic.
Our requirement is
(1) cmdq task cannot be split, and
(2) cmdq thread can have multiple cmdq tasks from different clients.
According to your comment "implement a 'server' driver that serialise the access to common channel", do you mean we should implement cmdq client (mailbox client) as a server and other clients call the functions of cmdq client?
clients --> cmdq client (mailbox client) --> cmdq (mailbox controller)
If so, could you please tell us the benefit of using mailbox framework?
Our original plan is to let cmdq driver manage cmdq thread internally. Cmdq driver can choose a suitable cmdq thread to execute a flushed cmdq task dynamically, and client doesn't need to know the existence of cmdq thread.
Could you also please tell us the purpose of putting all mailbox driver into mailbox folder?
We know that some other drivers also follow this rule, and just want to know more details.
Thanks,
HS
Quoted 30 lines · Horng-Shyang Liao
Quoted 17 lines
Quoted 7 lines
Quoted 2 lines
The driver uses the mailbox framework, so it should live in the
drivers/mailboxfolder.As you know, the maximum number of gce threads is 16. However, we plan to support more clients in the future, and they may need to use more than 16 gce threads.
Quoted 10 lines
For this issue, our plan is to let multiple clients share the same gce thread; i.e. we will acquire gce thread for client dynamically by internal policy in cmdq driver.
Unfortunately. mailbox channel has exclusive feature.
Quote from comment ofmbox_request_channel().
"The channel is exclusively allocated and can't be used by another client before the owner callsmbox_free_channel." Therefore, we plan to remove mailbox framework from cmdq driver in the future.Quoted 5 lines
Platforms that need shared access to a channel, implement a 'server' driver that serialise (which is needed still) the access to common channel. If you think you don't need mutual exclusion and don't care about replies, simply share the mailbox handle among different clients.
Thank you for your kindly reply.
We would like to discuss further with you on this topic.Our requirement is
(1) cmdq task cannot be split, and
(2) cmdq thread can have multiple cmdq tasks from different clients.
Quoted 9 lines
According to your comment "implement a 'server' driver that serialise the access to common channel", do you mean we should implement cmdq client (mailbox client) as a server and other clients call the functions of cmdq client?
clients --> cmdq client (mailbox client) --> cmdq (mailbox controller)
If so, could you please tell us the benefit of using mailbox framework?
You don't have to reinvent 80% of the wheel and reuse the mailbox.c core that supports many features and is tested on many platforms. Your implementation is going to be quite similar, only you clump all the code in one file and you use different terminology.
You said "we will acquire gce thread for client dynamically by internal policy in cmdq driver"
On mailbox api, this maps to simply sharing the channel/thread handle, protected by a lock, among clients on some basis (like FCFS or whatever you internal policy is). So your server driver could be very thin. And all your clients could follow the mailbox api (which is good from the point of reusability/portability).
Quoted 11 lines
Our original plan is to let cmdq driver manage cmdq thread internally. Cmdq driver can choose a suitable cmdq thread to execute a flushed cmdq task dynamically, and client doesn't need to know the existence of cmdq thread.
Could you also please tell us the purpose of putting all mailbox driver into mailbox folder?
We know that some other drivers also follow this rule, and just want to know more details.
Any driver that implements the Mailbox API should live in drivers/mailbox/. And why you should implement mailbox api, is explained above.
Hi Jassi,
Quoted 1 line · Jassi Brar
On Wed, Aug 31, 2016 at 1:43 PM, Horng-Shyang Liao <[email protected]> wrote:
[...]
Quoted 41 lines
Quoted 13 lines
Quoted 5 lines
Platforms that need shared access to a channel, implement a 'server' driver that serialise (which is needed still) the access to common channel. If you think you don't need mutual exclusion and don't care about replies, simply share the mailbox handle among different clients.
Thank you for your kindly reply.
We would like to discuss further with you on this topic.Our requirement is
(1) cmdq task cannot be split, and
(2) cmdq thread can have multiple cmdq tasks from different clients.Quoted 9 lines
According to your comment "implement a 'server' driver that serialise the access to common channel", do you mean we should implement cmdq client (mailbox client) as a server and other clients call the functions of cmdq client?
clients --> cmdq client (mailbox client) --> cmdq (mailbox controller)
If so, could you please tell us the benefit of using mailbox framework?
You don't have to reinvent 80% of the wheel and reuse the
mailbox.ccore that supports many features and is tested on many platforms. Your implementation is going to be quite similar, only you clump all the code in one file and you use different terminology.You said "we will acquire gce thread for client dynamically by internal policy in cmdq driver"
On mailbox api, this maps to simply sharing the channel/thread handle, protected by a lock, among clients on some basis (like FCFS or whatever you internal policy is). So your server driver could be very thin. And all your clients could follow the mailbox api (which is good from the point of reusability/portability).Quoted 6 lines
Our original plan is to let cmdq driver manage cmdq thread internally. Cmdq driver can choose a suitable cmdq thread to execute a flushed cmdq task dynamically, and client doesn't need to know the existence of cmdq thread.
Quoted 8 lines
Quoted 5 lines
Could you also please tell us the purpose of putting all mailbox driver into mailbox folder?
We know that some other drivers also follow this rule, and just want to know more details.Any driver that implements the Mailbox API should live in
drivers/mailbox/. And why you should implement mailbox api, is explained above.
Thank you for your explanation.
I will move cmdq driver to mailbox folder in the next version.
Thanks,
HS