Mediatek MT8173 CMDQ support
Subsystems (3)
v20 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.10-rc2.
Changes since v19:
- rebase to v4.10-rc2
Best regards,
HS Liao
HS Liao (4):
dt-bindings: soc: Add documentation for the MediaTek GCE unit
mailbox: mediatek: Add Mediatek CMDQ driver
arm64: dts: mt8173: Add GCE node
soc: mediatek: Add Mediatek CMDQ helper
.../devicetree/bindings/mailbox/mtk-gce.txt | 43 ++ arch/arm64/boot/dts/mediatek/mt8173.dtsi | 10 + drivers/mailbox/Kconfig | 10 + drivers/mailbox/Makefile | 2 + drivers/mailbox/mtk-cmdq-mailbox.c | 596 +++++++++++++++++++++ drivers/soc/mediatek/Kconfig | 12 + drivers/soc/mediatek/Makefile | 1 + drivers/soc/mediatek/mtk-cmdq-helper.c | 310 +++++++++++ include/linux/mailbox/mtk-cmdq-mailbox.h | 75 +++ include/linux/soc/mediatek/mtk-cmdq.h | 174 ++++++ 10 files changed, 1233 insertions(+) create mode 100644 Documentation/devicetree/bindings/mailbox/mtk-gce.txt create mode 100644 drivers/mailbox/mtk-cmdq-mailbox.c create mode 100644 drivers/soc/mediatek/mtk-cmdq-helper.c create mode 100644 include/linux/mailbox/mtk-cmdq-mailbox.h create mode 100644 include/linux/soc/mediatek/mtk-cmdq.h
Signature · 1 line
1.9.1
PATCH v20 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/mailbox/mtk-gce.txt | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 Documentation/devicetree/bindings/mailbox/mtk-gce.txt
Documentation/devicetree/bindings/mailbox/mtk-gce.txt new file +43 -0
@@ -0,0 +1,43 @@ +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.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 v20 2/4 mailbox: mediatek: Add 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/mailbox/Kconfig | 10 + drivers/mailbox/Makefile | 2 + drivers/mailbox/mtk-cmdq-mailbox.c | 596 +++++++++++++++++++++++++++++++ include/linux/mailbox/mtk-cmdq-mailbox.h | 75 ++++ 4 files changed, 683 insertions(+) create mode 100644 drivers/mailbox/mtk-cmdq-mailbox.c create mode 100644 include/linux/mailbox/mtk-cmdq-mailbox.h
drivers/mailbox/Kconfig +10 -0
@@ -152,4 +152,14 @@ config BCM_PDC_MBOX Mailbox implementation for the Broadcom PDC ring manager, which provides access to various offload engines on Broadcom SoCs. Say Y here if you want to use the Broadcom PDC. + +config MTK_CMDQ_MBOX + bool "MediaTek CMDQ Mailbox Support" + depends on ARM64 && ( ARCH_MEDIATEK || COMPILE_TEST ) + select MTK_INFRACFG + help + Say yes here to add support for the MediaTek Command Queue (CMDQ) + mailbox driver. The CMDQ is used to help read/write registers with + critical time limitation, such as updating display configuration + during the vblank. endif
drivers/mailbox/Makefile +2 -0
@@ -31,3 +31,5 @@ obj-$(CONFIG_HI6220_MBOX) += hi6220-mailbox.o obj-$(CONFIG_BCM_PDC_MBOX) += bcm-pdc-mailbox.o obj-$(CONFIG_TEGRA_HSP_MBOX) += tegra-hsp.o + +obj-$(CONFIG_MTK_CMDQ_MBOX) += mtk-cmdq-mailbox.o
drivers/mailbox/mtk-cmdq-mailbox.c new file +596 -0
596 lines not on this page · raw message
include/linux/mailbox/mtk-cmdq-mailbox.h new file +75 -0
75 lines not on this page · raw message
Signature · 1 line
1.9.1
Jassi Brar
maintainerRe: [PATCH v20 2/4] mailbox: mediatek: Add Mediatek CMDQ driver
Quoted 5 lines · HS Liao
drivers/mailbox/mtk-cmdq-mailbox.c new file +0
-0
...
Quoted 7 lines
drivers/mailbox/mtk-cmdq-mailbox.c new file +6
-0+static void cmdq_task_exec (struct cmdq_pkt *pkt,struct cmdq_thread *thread) +{ +struct cmdq *cmdq; +struct cmdq_task *task; +unsigned long curr_pa, end_pa; +
drivers/mailbox/mtk-cmdq-mailbox.c line 217
Quoted 10 lines
drivers/mailbox/mtk-cmdq-mailbox.c new file +10
-0+ cmdq =dev_get_drvdata (thread->chan->mbox->dev); + +/* Client should not flush new tasks if suspended. */ +WARN_ON (cmdq->suspended); + + task =kzalloc (sizeof (*task),GFP_ATOMIC ); + task->cmdq = cmdq; +INIT_LIST_HEAD (&task->list_entry); + task->pa_base =dma_map_single (cmdq->mbox.dev, pkt->va_base, + pkt->cmd_buf_size,DMA_TO_DEVICE );
You seem to parse the requests and responses, that should ideally be done in client driver.
Also, we are here in atomic context, can you move it in client driver (before the spin_lock)?
Maybe by adding a new 'pa_base' member as well in 'cmdq_pkt'.
....
drivers/mailbox/mtk-cmdq-mailbox.c line 554
Quoted 11 lines
drivers/mailbox/mtk-cmdq-mailbox.c new file +10
-0+ + cmdq->mbox.num_chans =CMDQ_THR_MAX_COUNT ; + cmdq->mbox.ops = &cmdq_mbox_chan_ops; + cmdq->mbox.of_xlate = cmdq_xlate; + +/* make use of TXDONE_BY_ACK */ + cmdq->mbox.txdone_irq = false; + cmdq->mbox.txdone_poll = false; + +for (i =0 ; i <ARRAY_SIZE (cmdq->thread); i++) {
You mean i < CMDQ_THR_MAX_COUNT
drivers/mailbox/mtk-cmdq-mailbox.c line 557
Quoted 4 lines
drivers/mailbox/mtk-cmdq-mailbox.c new file +3
-0+ cmdq->thread[i].base = cmdq->base +CMDQ_THR_BASE + +CMDQ_THR_SIZE * i; +INIT_LIST_HEAD (&cmdq->thread[i].task_busy_list);
You seem the queue mailbox requests in this controller driver? why not use the mailbox api for that?
drivers/mailbox/mtk-cmdq-mailbox.c line 560
Quoted 4 lines
drivers/mailbox/mtk-cmdq-mailbox.c new file +3
-0+init_timer (&cmdq->thread[i].timeout); + cmdq->thread[i].timeout.function = cmdq_thread_handle_timeout; + cmdq->thread[i].timeout.data = (unsigned long )&cmdq->thread[i];
Here again... you seem to ignore the polling mechanism provided by the mailbox api, and implement your own.
Quoted 5 lines
include/linux/mailbox/mtk-cmdq-mailbox.h new file +0
-0
....
include/linux/mailbox/mtk-cmdq-mailbox.h line 69
Quoted 4 lines
include/linux/mailbox/mtk-cmdq-mailbox.h new file +3
-0+ +struct cmdq_pkt { +void *va_base;
maybe add 'pa_base' here so you don't have to do dma_map_single() in send_data
Quoted 9 lines
include/linux/mailbox/mtk-cmdq-mailbox.h new file +6
-1+size_t cmd_buf_size;/* command occupied size */ +size_t buf_size;/* real buffer size */ + struct cmdq_task_cb cb; +}; + +#endif /* __MTK_CMDQ_MAILBOX_H__ */ --1.9.1
Re: [PATCH v20 2/4] mailbox: mediatek: Add Mediatek CMDQ driver
Hi Jassi,
Quoted 24 lines · Jassi Brar
Quoted 5 lines · HS Liao
drivers/mailbox/mtk-cmdq-mailbox.c new file +0
-0...
Quoted 14 lines
drivers/mailbox/mtk-cmdq-mailbox.c new file +14
-0+static void cmdq_task_exec (struct cmdq_pkt *pkt,struct cmdq_thread *thread) +{ +struct cmdq *cmdq; +struct cmdq_task *task; +unsigned long curr_pa, end_pa; + + cmdq =dev_get_drvdata (thread->chan->mbox->dev); + +/* Client should not flush new tasks if suspended. */ +WARN_ON (cmdq->suspended); + + task =kzalloc (sizeof (*task),GFP_ATOMIC ); + task->cmdq = cmdq; +INIT_LIST_HEAD (&task->list_entry);
Quoted 8 lines
drivers/mailbox/mtk-cmdq-mailbox.c line 217
Quoted 3 lines
drivers/mailbox/mtk-cmdq-mailbox.c new file +2
-0+ task->pa_base =dma_map_single (cmdq->mbox.dev, pkt->va_base, + pkt->cmd_buf_size,DMA_TO_DEVICE );You seem to parse the requests and responses, that should ideally be done in client driver.
Also, we are here in atomic context, can you move it in client driver (before thespin_lock)?
Maybe by adding a new 'pa_base' member as well in 'cmdq_pkt'.
will do
Quoted 13 lines
....
drivers/mailbox/mtk-cmdq-mailbox.c line 554
Quoted 11 lines
drivers/mailbox/mtk-cmdq-mailbox.c new file +10
-0+ + cmdq->mbox.num_chans =CMDQ_THR_MAX_COUNT ; + cmdq->mbox.ops = &cmdq_mbox_chan_ops; + cmdq->mbox.of_xlate = cmdq_xlate; + +/* make use of TXDONE_BY_ACK */ + cmdq->mbox.txdone_irq = false; + cmdq->mbox.txdone_poll = false; + +for (i =0 ; i <ARRAY_SIZE (cmdq->thread); i++) {You mean i <
CMDQ_THR_MAX_COUNT
will do
Quoted 7 lines
drivers/mailbox/mtk-cmdq-mailbox.c line 557
Quoted 4 lines
drivers/mailbox/mtk-cmdq-mailbox.c new file +3
-0+ cmdq->thread[i].base = cmdq->base +CMDQ_THR_BASE + +CMDQ_THR_SIZE * i; +INIT_LIST_HEAD (&cmdq->thread[i].task_busy_list);You seem the queue mailbox requests in this controller driver? why not use the mailbox api for that?
Quoted 6 lines
drivers/mailbox/mtk-cmdq-mailbox.c line 560
Quoted 4 lines
drivers/mailbox/mtk-cmdq-mailbox.c new file +3
-0+init_timer (&cmdq->thread[i].timeout); + cmdq->thread[i].timeout.function = cmdq_thread_handle_timeout; + cmdq->thread[i].timeout.data = (unsigned long )&cmdq->thread[i];Here again... you seem to ignore the polling mechanism provided by the mailbox api, and implement your own.
The queue is used to record the tasks which are flushed into CMDQ hardware (GCE). We are handling time critical tasks, so we have to queue them in GCE rather than a software queue (e.g. mailbox buffer). Let me use display as an example. Many display tasks are flushed into CMDQ to wait next vsync event. When vsync event is triggered by display hardware, GCE needs to process all flushed tasks "within vblank" to prevent garbage on screen. This is all done by GCE (without CPU) to fulfill time critical requirement. After GCE finish its work, it will generate interrupts, and then CMDQ driver will let clients know which tasks are done.
We have discussed the similar thing before. Please take a look at the following link, especially from 2016/10/5 to.2016/10/11 about tx_done.
https://patchwork.kernel.org/patch/9312953/
Quoted 11 lines
Quoted 5 lines
include/linux/mailbox/mtk-cmdq-mailbox.h new file +0
-0....
include/linux/mailbox/mtk-cmdq-mailbox.h line 69
Quoted 4 lines
include/linux/mailbox/mtk-cmdq-mailbox.h new file +3
-0+ +struct cmdq_pkt { +void *va_base;maybe add '
pa_base' here so you don't have to dodma_map_single()insend_data
will do
Quoted 9 lines
Quoted 9 lines
include/linux/mailbox/mtk-cmdq-mailbox.h new file +6
-1+size_t cmd_buf_size;/* command occupied size */ +size_t buf_size;/* real buffer size */ + struct cmdq_task_cb cb; +}; + +#endif /* __MTK_CMDQ_MAILBOX_H__ */ --1.9.1
Thanks,
HS
Jassi Brar
maintainerRe: [PATCH v20 2/4] mailbox: mediatek: Add Mediatek CMDQ driver
Quoted 68 lines · Horng-Shyang Liao
Hi Jassi,
Quoted 24 lines · Jassi Brar
Quoted 5 lines · HS Liao
drivers/mailbox/mtk-cmdq-mailbox.c new file +0
-0...
Quoted 14 lines
drivers/mailbox/mtk-cmdq-mailbox.c new file +14
-0+static void cmdq_task_exec (struct cmdq_pkt *pkt,struct cmdq_thread *thread) +{ +struct cmdq *cmdq; +struct cmdq_task *task; +unsigned long curr_pa, end_pa; + + cmdq =dev_get_drvdata (thread->chan->mbox->dev); + +/* Client should not flush new tasks if suspended. */ +WARN_ON (cmdq->suspended); + + task =kzalloc (sizeof (*task),GFP_ATOMIC ); + task->cmdq = cmdq; +INIT_LIST_HEAD (&task->list_entry);Quoted 8 lines
drivers/mailbox/mtk-cmdq-mailbox.c line 217
Quoted 3 lines
drivers/mailbox/mtk-cmdq-mailbox.c new file +2
-0+ task->pa_base =dma_map_single (cmdq->mbox.dev, pkt->va_base, + pkt->cmd_buf_size,DMA_TO_DEVICE );You seem to parse the requests and responses, that should ideally be done in client driver.
Also, we are here in atomic context, can you move it in client driver (before thespin_lock)?
Maybe by adding a new 'pa_base' member as well in 'cmdq_pkt'.will do
Quoted 13 lines
....
drivers/mailbox/mtk-cmdq-mailbox.c line 554
Quoted 11 lines
drivers/mailbox/mtk-cmdq-mailbox.c new file +10
-0+ + cmdq->mbox.num_chans =CMDQ_THR_MAX_COUNT ; + cmdq->mbox.ops = &cmdq_mbox_chan_ops; + cmdq->mbox.of_xlate = cmdq_xlate; + +/* make use of TXDONE_BY_ACK */ + cmdq->mbox.txdone_irq = false; + cmdq->mbox.txdone_poll = false; + +for (i =0 ; i <ARRAY_SIZE (cmdq->thread); i++) {You mean i <
CMDQ_THR_MAX_COUNTwill do
Quoted 7 lines
drivers/mailbox/mtk-cmdq-mailbox.c line 557
Quoted 4 lines
drivers/mailbox/mtk-cmdq-mailbox.c new file +3
-0+ cmdq->thread[i].base = cmdq->base +CMDQ_THR_BASE + +CMDQ_THR_SIZE * i; +INIT_LIST_HEAD (&cmdq->thread[i].task_busy_list);You seem the queue mailbox requests in this controller driver? why not use the mailbox api for that?
Quoted 6 lines
drivers/mailbox/mtk-cmdq-mailbox.c line 560
Quoted 4 lines
drivers/mailbox/mtk-cmdq-mailbox.c new file +3
-0+init_timer (&cmdq->thread[i].timeout); + cmdq->thread[i].timeout.function = cmdq_thread_handle_timeout; + cmdq->thread[i].timeout.data = (unsigned long )&cmdq->thread[i];Here again... you seem to ignore the polling mechanism provided by the mailbox api, and implement your own.
Quoted 11 lines
The queue is used to record the tasks which are flushed into CMDQ hardware (GCE). We are handling time critical tasks, so we have to queue them in GCE rather than a software queue (e.g. mailbox buffer). Let me use display as an example. Many display tasks are flushed into CMDQ to wait next vsync event. When vsync event is triggered by display hardware, GCE needs to process all flushed tasks "within vblank" to prevent garbage on screen. This is all done by GCE (without CPU) to fulfill time critical requirement. After GCE finish its work, it will generate interrupts, and then CMDQ driver will let clients know which tasks are done.
Does the GCE provide any 'lock' to prevent modifying (by adding tasks to) the GCE h/w buffer when it is processing it at vsync? Otherwise there maybe race/error. If there is such a 'lock' flag/irq, that could help here. However, you are supposed to know your h/w better, so I will accept this implementation assuming it can't be done any better.
Please address other comments and resubmit.
Thanks
Re: [PATCH v20 2/4] mailbox: mediatek: Add Mediatek CMDQ driver
Hi Jassi,
Quoted 37 lines · Jassi Brar
Quoted 36 lines · Horng-Shyang Liao
Hi Jassi,
Quoted 32 lines · Jassi Brar
Quoted 5 lines · HS Liao
drivers/mailbox/mtk-cmdq-mailbox.c new file +0
-0...
Quoted 7 lines
drivers/mailbox/mtk-cmdq-mailbox.c new file +6
-0+static void cmdq_task_exec (struct cmdq_pkt *pkt,struct cmdq_thread *thread) +{ +struct cmdq *cmdq; +struct cmdq_task *task; +unsigned long curr_pa, end_pa; +drivers/mailbox/mtk-cmdq-mailbox.c line 217
Quoted 10 lines
drivers/mailbox/mtk-cmdq-mailbox.c new file +10
-0+ cmdq =dev_get_drvdata (thread->chan->mbox->dev); + +/* Client should not flush new tasks if suspended. */ +WARN_ON (cmdq->suspended); + + task =kzalloc (sizeof (*task),GFP_ATOMIC ); + task->cmdq = cmdq; +INIT_LIST_HEAD (&task->list_entry); + task->pa_base =dma_map_single (cmdq->mbox.dev, pkt->va_base, + pkt->cmd_buf_size,DMA_TO_DEVICE );You seem to parse the requests and responses, that should ideally be done in client driver.
Also, we are here in atomic context, can you move it in client driver (before thespin_lock)?
Maybe by adding a new 'pa_base' member as well in 'cmdq_pkt'.
Quoted 1 line
Quoted 1 line
will do
I agree with moving dma_map_single out from spin_lock.
However, mailbox clients cannot map virtual memory to mailbox controller's device for DMA. In our previous discussion, we decided to remove mailbox_controller.h from clients to restrict their capabilities.
Please take a look at following link from 2016/9/22 to 2016/9/30 about mailbox_controller.h.
https://patchwork.kernel.org/patch/9312953/
Is there any better place to do dma_map_single?
Quoted 41 lines
Quoted 30 lines
Quoted 13 lines
....
drivers/mailbox/mtk-cmdq-mailbox.c line 554
Quoted 11 lines
drivers/mailbox/mtk-cmdq-mailbox.c new file +10
-0+ + cmdq->mbox.num_chans =CMDQ_THR_MAX_COUNT ; + cmdq->mbox.ops = &cmdq_mbox_chan_ops; + cmdq->mbox.of_xlate = cmdq_xlate; + +/* make use of TXDONE_BY_ACK */ + cmdq->mbox.txdone_irq = false; + cmdq->mbox.txdone_poll = false; + +for (i =0 ; i <ARRAY_SIZE (cmdq->thread); i++) {You mean i <
CMDQ_THR_MAX_COUNTwill do
Quoted 7 lines
drivers/mailbox/mtk-cmdq-mailbox.c line 557
Quoted 4 lines
drivers/mailbox/mtk-cmdq-mailbox.c new file +3
-0+ cmdq->thread[i].base = cmdq->base +CMDQ_THR_BASE + +CMDQ_THR_SIZE * i; +INIT_LIST_HEAD (&cmdq->thread[i].task_busy_list);You seem the queue mailbox requests in this controller driver? why not use the mailbox api for that?
Quoted 6 lines
drivers/mailbox/mtk-cmdq-mailbox.c line 560
Quoted 4 lines
drivers/mailbox/mtk-cmdq-mailbox.c new file +3
-0+init_timer (&cmdq->thread[i].timeout); + cmdq->thread[i].timeout.function = cmdq_thread_handle_timeout; + cmdq->thread[i].timeout.data = (unsigned long )&cmdq->thread[i];Here again... you seem to ignore the polling mechanism provided by the mailbox api, and implement your own.
Quoted 11 lines
The queue is used to record the tasks which are flushed into CMDQ hardware (GCE). We are handling time critical tasks, so we have to queue them in GCE rather than a software queue (e.g. mailbox buffer). Let me use display as an example. Many display tasks are flushed into CMDQ to wait next vsync event. When vsync event is triggered by display hardware, GCE needs to process all flushed tasks "within vblank" to prevent garbage on screen. This is all done by GCE (without CPU) to fulfill time critical requirement. After GCE finish its work, it will generate interrupts, and then CMDQ driver will let clients know which tasks are done.
Quoted 2 lines
Does the GCE provide any 'lock' to prevent modifying (by adding tasks to) the GCE h/w buffer when it is processing it at vsync? Otherwise
CPU will suspend GCE when adding a task (cmdq_thread_suspend), and resume GCE after adding task is done (cmdq_thread_resume). If GCE is processing task(s) at vsync and CPU wants to add a new task at the same time, CPU will detect this situation
(by cmdq_thread_is_in_wfe), resume GCE immediately, and then add following task(s) to wait for next vsync event.
All the above logic is implemented at cmdq_task_exec.
Quoted 7 lines
there maybe race/error. If there is such a 'lock' flag/irq, that could help here. However, you are supposed to know your h/w better, so I will accept this implementation assuming it can't be done any better.
Please address other comments and resubmit.
Thanks
After we figure out a better solution for dma_map_single issue, I will resubmit a new version.
Thanks,
HS
Re: [PATCH v20 2/4] mailbox: mediatek: Add Mediatek CMDQ driver
Quoted 48 lines · Horng-Shyang Liao
Hi Jassi,
Quoted 37 lines · Jassi Brar
Quoted 36 lines · Horng-Shyang Liao
Hi Jassi,
Quoted 32 lines · Jassi Brar
Quoted 5 lines · HS Liao
drivers/mailbox/mtk-cmdq-mailbox.c new file +0
-0...
Quoted 7 lines
drivers/mailbox/mtk-cmdq-mailbox.c new file +6
-0+static void cmdq_task_exec (struct cmdq_pkt *pkt,struct cmdq_thread *thread) +{ +struct cmdq *cmdq; +struct cmdq_task *task; +unsigned long curr_pa, end_pa; +drivers/mailbox/mtk-cmdq-mailbox.c line 217
Quoted 10 lines
drivers/mailbox/mtk-cmdq-mailbox.c new file +10
-0+ cmdq =dev_get_drvdata (thread->chan->mbox->dev); + +/* Client should not flush new tasks if suspended. */ +WARN_ON (cmdq->suspended); + + task =kzalloc (sizeof (*task),GFP_ATOMIC ); + task->cmdq = cmdq; +INIT_LIST_HEAD (&task->list_entry); + task->pa_base =dma_map_single (cmdq->mbox.dev, pkt->va_base, + pkt->cmd_buf_size,DMA_TO_DEVICE );You seem to parse the requests and responses, that should ideally be done in client driver.
Also, we are here in atomic context, can you move it in client driver (before thespin_lock)?
Maybe by adding a new 'pa_base' member as well in 'cmdq_pkt'.Quoted 1 line
Quoted 1 line
will do
I agree with moving
dma_map_singleout fromspin_lock.However, mailbox clients cannot map virtual memory to mailbox controller's device for DMA. In our previous discussion, we decided to remove
mailbox_controller.hfrom clients to restrict their capabilities.
Quoted 5 lines
Please take a look at following link from 2016/9/22 to 2016/9/30 about
mailbox_controller.h.
https://patchwork.kernel.org/patch/9312953/Is there any better place to do
dma_map_single?
Hi Jassi,
According to previous discussion, we have two requirements:
(1) CMDQ clients should not access mailbox_controller.h;
(2) dma_map_single should not put inside spin_lock.
I think a trade-off solution is to put in mtk-cmdq-helper.c. Although it is a mailbox client, it is not a CMDQ client. We can include mailbox_controller.h in mtk-cmdq-helper.c (instead of mtk-cmdq.h), and then map dma at cmdq_pkt_flush_async before mbox_send_message.
pkt->pa_base = dma_map_single(client->chan->mbox->dev, pkt->va_base,
pkt->cmd_buf_size, DMA_TO_DEVICE);
What do you think?
Thanks,
HS
Quoted 65 lines
Quoted 41 lines
Quoted 30 lines
Quoted 13 lines
....
drivers/mailbox/mtk-cmdq-mailbox.c line 554
Quoted 11 lines
drivers/mailbox/mtk-cmdq-mailbox.c new file +10
-0+ + cmdq->mbox.num_chans =CMDQ_THR_MAX_COUNT ; + cmdq->mbox.ops = &cmdq_mbox_chan_ops; + cmdq->mbox.of_xlate = cmdq_xlate; + +/* make use of TXDONE_BY_ACK */ + cmdq->mbox.txdone_irq = false; + cmdq->mbox.txdone_poll = false; + +for (i =0 ; i <ARRAY_SIZE (cmdq->thread); i++) {You mean i <
CMDQ_THR_MAX_COUNTwill do
Quoted 7 lines
drivers/mailbox/mtk-cmdq-mailbox.c line 557
Quoted 4 lines
drivers/mailbox/mtk-cmdq-mailbox.c new file +3
-0+ cmdq->thread[i].base = cmdq->base +CMDQ_THR_BASE + +CMDQ_THR_SIZE * i; +INIT_LIST_HEAD (&cmdq->thread[i].task_busy_list);You seem the queue mailbox requests in this controller driver? why not use the mailbox api for that?
Quoted 6 lines
drivers/mailbox/mtk-cmdq-mailbox.c line 560
Quoted 4 lines
drivers/mailbox/mtk-cmdq-mailbox.c new file +3
-0+init_timer (&cmdq->thread[i].timeout); + cmdq->thread[i].timeout.function = cmdq_thread_handle_timeout; + cmdq->thread[i].timeout.data = (unsigned long )&cmdq->thread[i];Here again... you seem to ignore the polling mechanism provided by the mailbox api, and implement your own.
Quoted 11 lines
The queue is used to record the tasks which are flushed into CMDQ hardware (GCE). We are handling time critical tasks, so we have to queue them in GCE rather than a software queue (e.g. mailbox buffer). Let me use display as an example. Many display tasks are flushed into CMDQ to wait next vsync event. When vsync event is triggered by display hardware, GCE needs to process all flushed tasks "within vblank" to prevent garbage on screen. This is all done by GCE (without CPU) to fulfill time critical requirement. After GCE finish its work, it will generate interrupts, and then CMDQ driver will let clients know which tasks are done.
Quoted 2 lines
Does the GCE provide any 'lock' to prevent modifying (by adding tasks to) the GCE h/w buffer when it is processing it at vsync? Otherwise
CPU will suspend GCE when adding a task (
cmdq_thread_suspend), and resume GCE after adding task is done (cmdq_thread_resume). If GCE is processing task(s) at vsync and CPU wants to add a new task at the same time, CPU will detect this situation
(bycmdq_thread_is_in_wfe), resume GCE immediately, and then add following task(s) to wait for next vsync event.
All the above logic is implemented atcmdq_task_exec.Quoted 7 lines
there maybe race/error. If there is such a 'lock' flag/irq, that could help here. However, you are supposed to know your h/w better, so I will accept this implementation assuming it can't be done any better.
Please address other comments and resubmit.
Thanks
After we figure out a better solution for
dma_map_singleissue, I will resubmit a new version.Thanks,
HS
Jassi Brar
maintainerRe: [PATCH v20 2/4] mailbox: mediatek: Add Mediatek CMDQ driver
In reply to Horng-Shyang LiaoQuoted 40 lines · Horng-Shyang Liao
Hi Jassi,
Quoted 37 lines · Jassi Brar
Quoted 36 lines · Horng-Shyang Liao
Hi Jassi,
Quoted 32 lines · Jassi Brar
Quoted 5 lines · HS Liao
drivers/mailbox/mtk-cmdq-mailbox.c new file +0
-0...
Quoted 7 lines
drivers/mailbox/mtk-cmdq-mailbox.c new file +6
-0+static void cmdq_task_exec (struct cmdq_pkt *pkt,struct cmdq_thread *thread) +{ +struct cmdq *cmdq; +struct cmdq_task *task; +unsigned long curr_pa, end_pa; +drivers/mailbox/mtk-cmdq-mailbox.c line 217
Quoted 10 lines
drivers/mailbox/mtk-cmdq-mailbox.c new file +10
-0+ cmdq =dev_get_drvdata (thread->chan->mbox->dev); + +/* Client should not flush new tasks if suspended. */ +WARN_ON (cmdq->suspended); + + task =kzalloc (sizeof (*task),GFP_ATOMIC ); + task->cmdq = cmdq; +INIT_LIST_HEAD (&task->list_entry); + task->pa_base =dma_map_single (cmdq->mbox.dev, pkt->va_base, + pkt->cmd_buf_size,DMA_TO_DEVICE );You seem to parse the requests and responses, that should ideally be done in client driver.
Also, we are here in atomic context, can you move it in client driver (before thespin_lock)?
Maybe by adding a new 'pa_base' member as well in 'cmdq_pkt'.
Quoted 7 lines
Quoted 1 line
Quoted 1 line
will do
I agree with moving
dma_map_singleout fromspin_lock.However, mailbox clients cannot map virtual memory to mailbox controller's device for DMA.
If DMA is a resource used by MBox to transfer data, then yes the mapping needs to be done in the Mbox controller driver. To map memory outside of spinlock, you could schedule a tasklet in send_data() ?
Re: [PATCH v20 2/4] mailbox: mediatek: Add Mediatek CMDQ driver
Quoted 43 lines · Jassi Brar
Quoted 42 lines · Horng-Shyang Liao
Hi Jassi,
Quoted 38 lines · Jassi Brar
Quoted 37 lines · Horng-Shyang Liao
Hi Jassi,
Quoted 24 lines · Jassi Brar
Quoted 5 lines · HS Liao
drivers/mailbox/mtk-cmdq-mailbox.c new file +0
-0...
Quoted 14 lines
drivers/mailbox/mtk-cmdq-mailbox.c new file +14
-0+static void cmdq_task_exec (struct cmdq_pkt *pkt,struct cmdq_thread *thread) +{ +struct cmdq *cmdq; +struct cmdq_task *task; +unsigned long curr_pa, end_pa; + + cmdq =dev_get_drvdata (thread->chan->mbox->dev); + +/* Client should not flush new tasks if suspended. */ +WARN_ON (cmdq->suspended); + + task =kzalloc (sizeof (*task),GFP_ATOMIC ); + task->cmdq = cmdq; +INIT_LIST_HEAD (&task->list_entry);Quoted 8 lines
drivers/mailbox/mtk-cmdq-mailbox.c line 217
Quoted 3 lines
drivers/mailbox/mtk-cmdq-mailbox.c new file +2
-0+ task->pa_base =dma_map_single (cmdq->mbox.dev, pkt->va_base, + pkt->cmd_buf_size,DMA_TO_DEVICE );You seem to parse the requests and responses, that should ideally be done in client driver.
Also, we are here in atomic context, can you move it in client driver (before thespin_lock)?
Maybe by adding a new 'pa_base' member as well in 'cmdq_pkt'.will do
Quoted 8 lines
Quoted 5 lines
I agree with moving
dma_map_singleout fromspin_lock.However, mailbox clients cannot map virtual memory to mailbox controller's device for DMA.
If DMA is a resource used by MBox to transfer data, then yes the mapping needs to be done in the Mbox controller driver. To map memory outside of spinlock, you could schedule a tasklet in
send_data()?
Hi Jassi,
For CMDQ, the order of CMDQ tasks should be guaranteed. However, it seems tasklet cannot ensure this requirement.
Quote from Linux Device Drivers 3rd edition ch7.
"void tasklet_schedule(struct tasklet_struct *t);
Schedule the tasklet for execution. If a tasklet is scheduled again
before it has a chance to run, it runs only once...."
May I use workqueue instead of tasklet?
Thanks,
HS
Jassi Brar
maintainerRe: [PATCH v20 2/4] mailbox: mediatek: Add Mediatek CMDQ driver
Quoted 55 lines · Horng-Shyang Liao
Quoted 43 lines · Jassi Brar
Quoted 42 lines · Horng-Shyang Liao
Hi Jassi,
Quoted 38 lines · Jassi Brar
Quoted 37 lines · Horng-Shyang Liao
Hi Jassi,
Quoted 24 lines · Jassi Brar
Quoted 5 lines · HS Liao
drivers/mailbox/mtk-cmdq-mailbox.c new file +0
-0...
Quoted 14 lines
drivers/mailbox/mtk-cmdq-mailbox.c new file +14
-0+static void cmdq_task_exec (struct cmdq_pkt *pkt,struct cmdq_thread *thread) +{ +struct cmdq *cmdq; +struct cmdq_task *task; +unsigned long curr_pa, end_pa; + + cmdq =dev_get_drvdata (thread->chan->mbox->dev); + +/* Client should not flush new tasks if suspended. */ +WARN_ON (cmdq->suspended); + + task =kzalloc (sizeof (*task),GFP_ATOMIC ); + task->cmdq = cmdq; +INIT_LIST_HEAD (&task->list_entry);Quoted 8 lines
drivers/mailbox/mtk-cmdq-mailbox.c
Quoted 3 lines
drivers/mailbox/mtk-cmdq-mailbox.c new file +2
-0+ task->pa_base =dma_map_single (cmdq->mbox.dev, pkt->va_base, + pkt->cmd_buf_size,DMA_TO_DEVICE );You seem to parse the requests and responses, that should ideally be done in client driver.
Also, we are here in atomic context, can you move it in client driver (before thespin_lock)?
Maybe by adding a new 'pa_base' member as well in 'cmdq_pkt'.will do
Quoted 8 lines
Quoted 5 lines
I agree with moving
dma_map_singleout fromspin_lock.However, mailbox clients cannot map virtual memory to mailbox controller's device for DMA.
If DMA is a resource used by MBox to transfer data, then yes the mapping needs to be done in the Mbox controller driver. To map memory outside of spinlock, you could schedule a tasklet in
send_data()?Hi Jassi,
Quoted 8 lines
For CMDQ, the order of CMDQ tasks should be guaranteed. However, it seems tasklet cannot ensure this requirement.
Quote from Linux Device Drivers 3rd edition ch7.
"voidtasklet_schedule(struct tasklet_struct *t);
Schedule the tasklet for execution. If a tasklet is scheduled again
before it has a chance to run, it runs only once...."
Not sure what bothers you.
If you only add requests to a list, protected by some spinlock, during send_datam you could always iterate over (submit) requests in the order you queued them.
Re: [PATCH v20 2/4] mailbox: mediatek: Add Mediatek CMDQ driver
Quoted 64 lines · Jassi Brar
Quoted 55 lines · Horng-Shyang Liao
Quoted 43 lines · Jassi Brar
Quoted 42 lines · Horng-Shyang Liao
Hi Jassi,
Quoted 38 lines · Jassi Brar
Quoted 37 lines · Horng-Shyang Liao
Hi Jassi,
Quoted 24 lines · Jassi Brar
Quoted 5 lines · HS Liao
drivers/mailbox/mtk-cmdq-mailbox.c new file +0
-0...
Quoted 14 lines
drivers/mailbox/mtk-cmdq-mailbox.c new file +14
-0+static void cmdq_task_exec (struct cmdq_pkt *pkt,struct cmdq_thread *thread) +{ +struct cmdq *cmdq; +struct cmdq_task *task; +unsigned long curr_pa, end_pa; + + cmdq =dev_get_drvdata (thread->chan->mbox->dev); + +/* Client should not flush new tasks if suspended. */ +WARN_ON (cmdq->suspended); + + task =kzalloc (sizeof (*task),GFP_ATOMIC ); + task->cmdq = cmdq; +INIT_LIST_HEAD (&task->list_entry);Quoted 8 lines
drivers/mailbox/mtk-cmdq-mailbox.c
Quoted 3 lines
drivers/mailbox/mtk-cmdq-mailbox.c new file +2
-0+ task->pa_base =dma_map_single (cmdq->mbox.dev, pkt->va_base, + pkt->cmd_buf_size,DMA_TO_DEVICE );You seem to parse the requests and responses, that should ideally be done in client driver.
Also, we are here in atomic context, can you move it in client driver (before thespin_lock)?
Maybe by adding a new 'pa_base' member as well in 'cmdq_pkt'.will do
Quoted 8 lines
Quoted 5 lines
I agree with moving
dma_map_singleout fromspin_lock.However, mailbox clients cannot map virtual memory to mailbox controller's device for DMA.
If DMA is a resource used by MBox to transfer data, then yes the mapping needs to be done in the Mbox controller driver. To map memory outside of spinlock, you could schedule a tasklet in
send_data()?Hi Jassi,
Quoted 8 lines
For CMDQ, the order of CMDQ tasks should be guaranteed. However, it seems tasklet cannot ensure this requirement.
Quote from Linux Device Drivers 3rd edition ch7.
"voidtasklet_schedule(struct tasklet_struct *t);
Schedule the tasklet for execution. If a tasklet is scheduled again
before it has a chance to run, it runs only once...."
Quoted 4 lines
Not sure what bothers you.
If you only add requests to a list, protected by some spinlock, duringsend_datamyou could always iterate over (submit) requests in the order you queued them.
Hi Jassi,
OK. I will do it.
Thanks,
HS
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: FW: [PATCH v20 2/4] mailbox: mediatek: Add Mediatek CMDQ driver
Hi Jassi,
Sorry for reply so late.
According to previous discussion, there are two methods to move dma_map_single() outside of spin_lock.
(1) put in mtk-cmdq-helper.c, as described by HS on 2017-02-09.
Quoted 3 lines
I think a trade-off solution is to put in
mtk-cmdq-helper.c. Although it is a mailbox client, it is not a CMDQ client. We can includemailbox_controller.hinmtk-cmdq-helper.c(instead of
mtk-cmdq.h), and then map dma at cmdq_pkt_flush_async before mbox_send_message.
Quoted 2 lines
pkt->pa_base= dma_map_single(client->chan->mbox->dev,pkt->va_base,pkt->cmd_buf_size, DMA_TO_DEVICE);
(2) schedule a tasklet in send_data().
After internal discussion with HS and other experts, now we prefer method (1).
How do you think about it?
Thanks
Houlong
Quoted 5 lines
-----Original Message-----
From: Horng-Shyang Liao [mailto:[email protected]]
Sent: Thursday, February 23, 2017 8:48 PM
To: Jassi Brar <[email protected]>
Cc: Rob Herring <[email protected]>; Matthias Brugger <[email protected]>; Daniel Kurtz <[email protected]>; Sascha Hauer <[email protected]>; Devicetree List <[email protected]>; Linux Kernel Mailing List <[email protected]>; [email protected]; [email protected];srv_heupstream<[email protected]>; Sascha Hauer <[email protected]>; Philipp Zabel <[email protected]>; Nicolas Boichat <[email protected]>; CK Hu (胡俊光) <[email protected]>; Cawa Cheng (鄭曄禧) <[email protected]>; Bibby Hsieh (謝濟遠) <[email protected]>; YT Shen (沈岳霆) <[email protected]>; Daoyuan Huang (黃道原) <[email protected]>; Damon Chu (朱峻賢) <[email protected]>; Josh-YC
Liu (劉育誠) <[email protected]>; Glory Hung (洪智瑋) <[email protected]>; Jiaguang Zhang (张加广) <[email protected]>; Dennis-YC Hsieh (謝宇哲) <[email protected]>; Monica Wang (王孟婷) <[email protected]>; Houlong Wei (魏厚龙) <[email protected]>; Hs Liao (廖宏祥) <[email protected]>
Quoted 83 lines
Subject: Re: [PATCH v20 2/4] mailbox: mediatek: Add Mediatek CMDQ driver
Quoted 66 lines · Jassi Brar
Quoted 57 lines · Horng-Shyang Liao
Quoted 45 lines · Jassi Brar
Quoted 44 lines · Horng-Shyang Liao
Hi Jassi,
Quoted 40 lines · Jassi Brar
Quoted 39 lines · Horng-Shyang Liao
Hi Jassi,
Quoted 26 lines · Jassi Brar
Quoted 6 lines · HS Liao
drivers/mailbox/mtk-cmdq-mailbox.c new file +0
-0...
Quoted 15 lines
drivers/mailbox/mtk-cmdq-mailbox.c new file +15
-0+static void cmdq_task_exec (struct cmdq_pkt *pkt,struct +cmdq_thread *thread) { +struct cmdq *cmdq; +struct cmdq_task *task; +unsigned long curr_pa, end_pa; + + cmdq =dev_get_drvdata (thread->chan->mbox->dev); + +/* Client should not flush new tasks if suspended. */ +WARN_ON (cmdq->suspended); + + task =kzalloc (sizeof (*task),GFP_ATOMIC ); + task->cmdq = cmdq; +INIT_LIST_HEAD (&task->list_entry); + task->pa_base = dma_map_single(cmdq->mbox.dev, pkt->va_base,Quoted 8 lines
Quoted 3 lines
+
pkt->cmd_buf_size,
+DMA_TO_DEVICE);You seem to parse the requests and responses, that should ideally be done in client driver.
Also, we are here in atomic context, can you move it in client driver (before thespin_lock)?
Maybe by adding a new 'pa_base' member as well in 'cmdq_pkt'.will do
Quoted 8 lines
Quoted 5 lines
I agree with moving
dma_map_singleout fromspin_lock.However, mailbox clients cannot map virtual memory to mailbox controller's device for DMA.
If DMA is a resource used by MBox to transfer data, then yes the mapping needs to be done in the Mbox controller driver. To map memory outside of spinlock, you could schedule a tasklet in
send_data()?Hi Jassi,
Quoted 8 lines
For CMDQ, the order of CMDQ tasks should be guaranteed. However, it seems tasklet cannot ensure this requirement.
Quote from Linux Device Drivers 3rd edition ch7. "void
tasklet_schedule(struct tasklet_struct *t);
Schedule the tasklet for execution. If a tasklet is scheduled
again before it has a chance to run, it runs only once...."Quoted 4 lines
Not sure what bothers you.
If you only add requests to a list, protected by some spinlock, duringsend_datamyou could always iterate over (submit) requests in the order you queued them.Hi Jassi,
OK. I will do it.
Thanks,
HS
Re: [PATCH v20 2/4] mailbox: mediatek: Add Mediatek CMDQ driver
Hi Jassi,
We prefer to use method (1) to move dma_map_single() outside of spin_lock. Do you have any comment about this?
Thanks,
Houlong
Quoted 14 lines · houlong wei
Hi Jassi,
Sorry for reply so late.
According to previous discussion, there are two methods to movedma_map_single()outside ofspin_lock.
(1) put inmtk-cmdq-helper.c, as described by HS on 2017-02-09.Quoted 3 lines
I think a trade-off solution is to put in
mtk-cmdq-helper.c. Although it is a mailbox client, it is not a CMDQ client. We can includemailbox_controller.hinmtk-cmdq-helper.c(instead of
mtk-cmdq.h), and then map dma atcmdq_pkt_flush_asyncbeforembox_send_message.Quoted 2 lines
pkt->pa_base= dma_map_single(client->chan->mbox->dev,pkt->va_base,pkt->cmd_buf_size, DMA_TO_DEVICE);
Quoted 15 lines
(2) schedule a tasklet in
send_data().After internal discussion with HS and other experts, now we prefer method (1).
How do you think about it?Thanks
HoulongQuoted 5 lines
-----Original Message-----
From: Horng-Shyang Liao [mailto:hs.liao-NuS5LvNUpcJWk0Htik3J/[email protected]]
Sent: Thursday, February 23, 2017 8:48 PM
To: Jassi Brar <[email protected]>
Cc: Rob Herring <[email protected]>; Matthias Brugger <[email protected]>; Daniel Kurtz <[email protected]>; Sascha Hauer <[email protected]>; Devicetree List <[email protected]>; Linux Kernel Mailing List <[email protected]>; linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org; [email protected];srv_heupstream<srv_heupstream-NuS5LvNUpcJWk0Htik3J/[email protected]>; Sascha Hauer <[email protected]>; Philipp Zabel <[email protected]>; Nicolas Boichat <[email protected]>; CK Hu (胡俊光) <ck.hu-NuS5LvNUpcJWk0Htik3J/[email protected]>; Cawa Cheng (鄭曄禧) <cawa.cheng-NuS5LvNUpcJWk0Htik3J/[email protected]>; Bibby Hsieh (謝濟遠) <Bibby.Hsieh-NuS5LvNUpcJWk0Htik3J/[email protected]>; YT Shen (沈岳霆) <yt.shen-NuS5LvNUpcJWk0Htik3J/[email protected]>; Daoyuan Huang (黃道原) <Daoyuan.Huang-NuS5LvNUpcJWk0Htik3J/[email protected]>; Damon Chu (朱峻賢) <damon.chu-NuS5LvNUpcJWk0Htik3J/[email protected]>; Josh-Y
C Liu (劉育誠) <Josh-YC.Liu-NuS5LvNUpcJWk0Htik3J/[email protected]>; Glory Hung (洪智瑋) <glory.hung-NuS5LvNUpcJWk0Htik3J/[email protected]>; Jiaguang Zhang (张加广) <Jiaguang.Zhang-NuS5LvNUpcJWk0Htik3J/[email protected]>; Dennis-YC Hsieh (謝宇哲) <Dennis-YC.Hsieh-NuS5LvNUpcJWk0Htik3J/[email protected]>; Monica Wang (王孟婷) <monica.wang-NuS5LvNUpcJWk0Htik3J/[email protected]>; Houlong Wei (魏厚龙) <houlong.wei-NuS5LvNUpcJWk0Htik3J/[email protected]>; Hs Liao (廖宏祥) <hs.liao-NuS5LvNUpcJWk0Htik3J/[email protected]>
Quoted 76 lines
Quoted 76 lines
Subject: Re: [PATCH v20 2/4] mailbox: mediatek: Add Mediatek CMDQ driver
Quoted 66 lines · Jassi Brar
Quoted 57 lines · Horng-Shyang Liao
Quoted 45 lines · Jassi Brar
Quoted 44 lines · Horng-Shyang Liao
Hi Jassi,
Quoted 40 lines · Jassi Brar
Quoted 39 lines · Horng-Shyang Liao
Hi Jassi,
Quoted 26 lines · Jassi Brar
Quoted 6 lines · HS Liao
drivers/mailbox/mtk-cmdq-mailbox.c new file +0
-0...
Quoted 15 lines
drivers/mailbox/mtk-cmdq-mailbox.c new file +15
-0+static void cmdq_task_exec (struct cmdq_pkt *pkt,struct +cmdq_thread *thread) { +struct cmdq *cmdq; +struct cmdq_task *task; +unsigned long curr_pa, end_pa; + + cmdq =dev_get_drvdata (thread->chan->mbox->dev); + +/* Client should not flush new tasks if suspended. */ +WARN_ON (cmdq->suspended); + + task =kzalloc (sizeof (*task),GFP_ATOMIC ); + task->cmdq = cmdq; +INIT_LIST_HEAD (&task->list_entry); + task->pa_base = dma_map_single(cmdq->mbox.dev, pkt->va_base,Quoted 8 lines
Quoted 3 lines
+
pkt->cmd_buf_size,
+DMA_TO_DEVICE);You seem to parse the requests and responses, that should ideally be done in client driver.
Also, we are here in atomic context, can you move it in client driver (before thespin_lock)?
Maybe by adding a new 'pa_base' member as well in 'cmdq_pkt'.will do
Quoted 8 lines
Quoted 5 lines
I agree with moving
dma_map_singleout fromspin_lock.However, mailbox clients cannot map virtual memory to mailbox controller's device for DMA.
If DMA is a resource used by MBox to transfer data, then yes the mapping needs to be done in the Mbox controller driver. To map memory outside of spinlock, you could schedule a tasklet in
send_data()?Hi Jassi,
Quoted 8 lines
For CMDQ, the order of CMDQ tasks should be guaranteed. However, it seems tasklet cannot ensure this requirement.
Quote from Linux Device Drivers 3rd edition ch7. "void
tasklet_schedule(struct tasklet_struct *t);
Schedule the tasklet for execution. If a tasklet is scheduled
again before it has a chance to run, it runs only once...."Quoted 4 lines
Not sure what bothers you.
If you only add requests to a list, protected by some spinlock, duringsend_datamyou could always iterate over (submit) requests in the order you queued them.Hi Jassi,
Quoted 9 lines
Quoted 7 lines
OK. I will do it.
Thanks,
HS
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: FW: [PATCH v20 2/4] mailbox: mediatek: Add Mediatek CMDQ driver
In reply to houlong weiSorry to send the mail again because I missed some mail lists by mistake.
Hi Jassi,
We prefer to use method (1) to move dma_map_single() outside of spin_lock. Do you have any comment about this?
Thanks,
Houlong
Quoted 14 lines · houlong wei
Hi Jassi,
Sorry for reply so late.
According to previous discussion, there are two methods to movedma_map_single()outside ofspin_lock.
(1) put inmtk-cmdq-helper.c, as described by HS on 2017-02-09.Quoted 3 lines
I think a trade-off solution is to put in
mtk-cmdq-helper.c. Although it is a mailbox client, it is not a CMDQ client. We can includemailbox_controller.hinmtk-cmdq-helper.c(instead of
mtk-cmdq.h), and then map dma atcmdq_pkt_flush_asyncbeforembox_send_message.Quoted 2 lines
pkt->pa_base= dma_map_single(client->chan->mbox->dev,pkt->va_base,pkt->cmd_buf_size, DMA_TO_DEVICE);
Quoted 15 lines
(2) schedule a tasklet in
send_data().After internal discussion with HS and other experts, now we prefer method (1).
How do you think about it?Thanks
HoulongQuoted 5 lines
-----Original Message-----
From: Horng-Shyang Liao [mailto:hs.liao-NuS5LvNUpcJWk0Htik3J/[email protected]]
Sent: Thursday, February 23, 2017 8:48 PM
To: Jassi Brar <[email protected]>
Cc: Rob Herring <[email protected]>; Matthias Brugger <[email protected]>; Daniel Kurtz <[email protected]>; Sascha Hauer <[email protected]>; Devicetree List <[email protected]>; Linux Kernel Mailing List <[email protected]>; linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org; [email protected];srv_heupstream<srv_heupstream-NuS5LvNUpcJWk0Htik3J/[email protected]>; Sascha Hauer <[email protected]>; Philipp Zabel <[email protected]>; Nicolas Boichat <[email protected]>; CK Hu (胡俊光) <ck.hu-NuS5LvNUpcJWk0Htik3J/[email protected]>; Cawa Cheng (鄭曄禧) <cawa.cheng-NuS5LvNUpcJWk0Htik3J/[email protected]>; Bibby Hsieh (謝濟遠) <Bibby.Hsieh-NuS5LvNUpcJWk0Htik3J/[email protected]>; YT Shen (沈岳霆) <yt.shen-NuS5LvNUpcJWk0Htik3J/[email protected]>; Daoyuan Huang (黃道原) <Daoyuan.Huang-NuS5LvNUpcJWk0Htik3J/[email protected]>; Damon Chu (朱峻賢) <damon.chu-NuS5LvNUpcJWk0Htik3J/[email protected]>; Josh-Y
C Liu (劉育誠) <Josh-YC.Liu-NuS5LvNUpcJWk0Htik3J/[email protected]>; Glory Hung (洪智瑋) <glory.hung-NuS5LvNUpcJWk0Htik3J/[email protected]>; Jiaguang Zhang (张加广) <Jiaguang.Zhang-NuS5LvNUpcJWk0Htik3J/[email protected]>; Dennis-YC Hsieh (謝宇哲) <Dennis-YC.Hsieh-NuS5LvNUpcJWk0Htik3J/[email protected]>; Monica Wang (王孟婷) <monica.wang-NuS5LvNUpcJWk0Htik3J/[email protected]>; Houlong Wei (魏厚龙) <houlong.wei-NuS5LvNUpcJWk0Htik3J/[email protected]>; Hs Liao (廖宏祥) <hs.liao-NuS5LvNUpcJWk0Htik3J/[email protected]>
Quoted 76 lines
Quoted 76 lines
Subject: Re: [PATCH v20 2/4] mailbox: mediatek: Add Mediatek CMDQ driver
Quoted 66 lines · Jassi Brar
Quoted 57 lines · Horng-Shyang Liao
Quoted 45 lines · Jassi Brar
Quoted 44 lines · Horng-Shyang Liao
Hi Jassi,
Quoted 40 lines · Jassi Brar
Quoted 39 lines · Horng-Shyang Liao
Hi Jassi,
Quoted 26 lines · Jassi Brar
Quoted 6 lines · HS Liao
drivers/mailbox/mtk-cmdq-mailbox.c new file +0
-0...
Quoted 15 lines
drivers/mailbox/mtk-cmdq-mailbox.c new file +15
-0+static void cmdq_task_exec (struct cmdq_pkt *pkt,struct +cmdq_thread *thread) { +struct cmdq *cmdq; +struct cmdq_task *task; +unsigned long curr_pa, end_pa; + + cmdq =dev_get_drvdata (thread->chan->mbox->dev); + +/* Client should not flush new tasks if suspended. */ +WARN_ON (cmdq->suspended); + + task =kzalloc (sizeof (*task),GFP_ATOMIC ); + task->cmdq = cmdq; +INIT_LIST_HEAD (&task->list_entry); + task->pa_base = dma_map_single(cmdq->mbox.dev, pkt->va_base,Quoted 8 lines
Quoted 3 lines
+
pkt->cmd_buf_size,
+DMA_TO_DEVICE);You seem to parse the requests and responses, that should ideally be done in client driver.
Also, we are here in atomic context, can you move it in client driver (before thespin_lock)?
Maybe by adding a new 'pa_base' member as well in 'cmdq_pkt'.will do
Quoted 8 lines
Quoted 5 lines
I agree with moving
dma_map_singleout fromspin_lock.However, mailbox clients cannot map virtual memory to mailbox controller's device for DMA.
If DMA is a resource used by MBox to transfer data, then yes the mapping needs to be done in the Mbox controller driver. To map memory outside of spinlock, you could schedule a tasklet in
send_data()?Hi Jassi,
Quoted 8 lines
For CMDQ, the order of CMDQ tasks should be guaranteed. However, it seems tasklet cannot ensure this requirement.
Quote from Linux Device Drivers 3rd edition ch7. "void
tasklet_schedule(struct tasklet_struct *t);
Schedule the tasklet for execution. If a tasklet is scheduled
again before it has a chance to run, it runs only once...."Quoted 4 lines
Not sure what bothers you.
If you only add requests to a list, protected by some spinlock, duringsend_datamyou could always iterate over (submit) requests in the order you queued them.Hi Jassi,
Quoted 8 lines
Quoted 7 lines
OK. I will do it.
Thanks,
HS
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Jassi Brar
maintainerRe: FW: [PATCH v20 2/4] mailbox: mediatek: Add Mediatek CMDQ driver
In reply to houlong weiQuoted 12 lines · houlong wei
Hi Jassi,
Sorry for reply so late.
According to previous discussion, there are two methods to movedma_map_single()outside ofspin_lock.
(1) put inmtk-cmdq-helper.c, as described by HS on 2017-02-09.Quoted 3 lines
I think a trade-off solution is to put in
mtk-cmdq-helper.c. Although it is a mailbox client, it is not a CMDQ client. We can includemailbox_controller.hinmtk-cmdq-helper.c(instead of
mtk-cmdq.h), and then map dma atcmdq_pkt_flush_asyncbeforembox_send_message.
Quoted 8 lines
Quoted 2 lines
pkt->pa_base= dma_map_single(client->chan->mbox->dev,pkt->va_base,pkt->cmd_buf_size, DMA_TO_DEVICE);(2) schedule a tasklet in
send_data().After internal discussion with HS and other experts, now we prefer method (1).
How do you think about it?
I don't exactly see how you mean but please remember send_data() callback is supposed to be atomic ... it is protected by spin_lock_irqsave/restore in drivers/mailbox/mailbox.c:msg_submit()
BTW, how many requests max can be queued in the GCE h/w buffer? And since it's been over a year now, could you please resubmit after checking for checkpatch with the --strict option?
Thanks.
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: FW: [PATCH v20 2/4] mailbox: mediatek: Add Mediatek CMDQ driver
Hi Jassi,
There is one request for one GCE h/w buffer which contains a list of registers operation.
I will resubmit a version and please review again.
Thanks,
Houlong
Quoted 30 lines · Jassi Brar
Quoted 12 lines · houlong wei
Hi Jassi,
Sorry for reply so late.
According to previous discussion, there are two methods to movedma_map_single()outside ofspin_lock.
(1) put inmtk-cmdq-helper.c, as described by HS on 2017-02-09.Quoted 3 lines
I think a trade-off solution is to put in
mtk-cmdq-helper.c. Although it is a mailbox client, it is not a CMDQ client. We can includemailbox_controller.hinmtk-cmdq-helper.c(instead of
mtk-cmdq.h), and then map dma atcmdq_pkt_flush_asyncbeforembox_send_message.Quoted 8 lines
Quoted 2 lines
pkt->pa_base= dma_map_single(client->chan->mbox->dev,pkt->va_base,pkt->cmd_buf_size, DMA_TO_DEVICE);(2) schedule a tasklet in
send_data().After internal discussion with HS and other experts, now we prefer method (1).
How do you think about it?I don't exactly see how you mean but please remember
send_data()callback is supposed to be atomic ... it is protected by spin_lock_irqsave/restore in drivers/mailbox/mailbox.c:msg_submit()BTW, how many requests max can be queued in the GCE h/w buffer? And since it's been over a year now, could you please resubmit after checking for checkpatch with the --strict option?
Thanks.
PATCH v20 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
@@ -422,6 +422,16 @@ status = "disabled"; }; + 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 v20 4/4 soc: mediatek: Add Mediatek CMDQ helper
In reply to HS LiaoAdd Mediatek CMDQ helper to create CMDQ packet and assemble GCE op code.
--- drivers/soc/mediatek/Kconfig | 12 ++ drivers/soc/mediatek/Makefile | 1 + drivers/soc/mediatek/mtk-cmdq-helper.c | 310 +++++++++++++++++++++++++++++++++ include/linux/soc/mediatek/mtk-cmdq.h | 174 ++++++++++++++++++ 4 files changed, 497 insertions(+) create mode 100644 drivers/soc/mediatek/mtk-cmdq-helper.c create mode 100644 include/linux/soc/mediatek/mtk-cmdq.h
drivers/soc/mediatek/Kconfig +12 -0
@@ -1,6 +1,18 @@ # # MediaTek SoC drivers # +config MTK_CMDQ + bool "MediaTek CMDQ Support" + depends on ARM64 && ( ARCH_MEDIATEK || COMPILE_TEST ) + select MAILBOX + select MTK_CMDQ_MBOX + 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-helper.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-helper.c new file +310 -0
310 lines not on this page · raw message
include/linux/soc/mediatek/mtk-cmdq.h new file +174 -0
174 lines not on this page · raw message
Signature · 1 line
1.9.1
Quoted 21 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.
These patches have a build dependency on top of v4.10-rc2.
Changes since v19:
- rebase to v4.10-rc2Best regards,
HS LiaoHS Liao (4):
dt-bindings: soc: Add documentation for the MediaTek GCE unit
mailbox: mediatek: Add Mediatek CMDQ driver
arm64: dts: mt8173: Add GCE node
soc: mediatek: Add Mediatek CMDQ helper
Quoted 17 lines
.../devicetree/bindings/mailbox/mtk-gce.txt | 43 ++ arch/arm64/boot/dts/mediatek/mt8173.dtsi | 10 + drivers/mailbox/Kconfig | 10 + drivers/mailbox/Makefile | 2 + drivers/mailbox/mtk-cmdq-mailbox.c | 596 +++++++++++++++++++++ drivers/soc/mediatek/Kconfig | 12 + drivers/soc/mediatek/Makefile | 1 + drivers/soc/mediatek/mtk-cmdq-helper.c | 310 +++++++++++ include/linux/mailbox/mtk-cmdq-mailbox.h | 75 +++ include/linux/soc/mediatek/mtk-cmdq.h | 174 ++++++ 10 files changed, 1233 insertions(+) create mode 100644 Documentation/devicetree/bindings/mailbox/mtk-gce.txt create mode 100644 drivers/mailbox/mtk-cmdq-mailbox.c create mode 100644 drivers/soc/mediatek/mtk-cmdq-helper.c create mode 100644 include/linux/mailbox/mtk-cmdq-mailbox.h create mode 100644 include/linux/soc/mediatek/mtk-cmdq.h
Hi Jassi, Matthias,
Sorry to disturb you.
Do you have any further comments on CMDQ v20?
Thanks.
HS
Quoted 40 lines · Horng-Shyang Liao
Quoted 21 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.
These patches have a build dependency on top of v4.10-rc2.
Changes since v19:
- rebase to v4.10-rc2Best regards,
HS LiaoHS Liao (4):
dt-bindings: soc: Add documentation for the MediaTek GCE unit
mailbox: mediatek: Add Mediatek CMDQ driver
arm64: dts: mt8173: Add GCE node
soc: mediatek: Add Mediatek CMDQ helperQuoted 17 lines
.../devicetree/bindings/mailbox/mtk-gce.txt | 43 ++ arch/arm64/boot/dts/mediatek/mt8173.dtsi | 10 + drivers/mailbox/Kconfig | 10 + drivers/mailbox/Makefile | 2 + drivers/mailbox/mtk-cmdq-mailbox.c | 596 +++++++++++++++++++++ drivers/soc/mediatek/Kconfig | 12 + drivers/soc/mediatek/Makefile | 1 + drivers/soc/mediatek/mtk-cmdq-helper.c | 310 +++++++++++ include/linux/mailbox/mtk-cmdq-mailbox.h | 75 +++ include/linux/soc/mediatek/mtk-cmdq.h | 174 ++++++ 10 files changed, 1233 insertions(+) create mode 100644 Documentation/devicetree/bindings/mailbox/mtk-gce.txt create mode 100644 drivers/mailbox/mtk-cmdq-mailbox.c create mode 100644 drivers/soc/mediatek/mtk-cmdq-helper.c create mode 100644 include/linux/mailbox/mtk-cmdq-mailbox.h create mode 100644 include/linux/soc/mediatek/mtk-cmdq.h
Quoted 7 lines
Hi Jassi, Matthias,
Sorry to disturb you.
Do you have any further comments on CMDQ v20?Thanks.
HS
Hi Jassi, Matthias,
Sorry to disturb you again.
Do you have any further comments on CMDQ v20?
Thanks.
HS