Skip to contentSkip to conversation

This patches provide ADSP IPC support for MT8195.

PATCH Superseded allen-kh.cheng 2 participants 11 messages Nov 24, 2021 – Nov 25, 2021

Subsystems (3)

v3 of 18 Superseded Latest is v18 →

lore
Share & tools
lore
#0 lore raw

v3 cover This patches provide ADSP IPC support for MT8195.

Mediatek ADSP IPC is used to send notification or short message between processors with dsp.

It will place the message to the share buffer and will access the ADSP mailbox registers to kick dsp.

Two mailboxes used to send notification or short message between processors with dsp

Add changes history from series

changes since v2:
- seperate adsp_mailbox into two instances

changes since v1:
- fix dt_binding_check error

Allen-KH Cheng (3):
dt-bindings: mediatek: add adsp-mbox document
mailbox: mediatek: add support for adsp mailbox controller
firmware: mediatek: add adsp ipc protocol interface

 .../bindings/mailbox/mtk,adsp-mbox.yaml       |  53 +++++
 drivers/firmware/Kconfig                      |   1 +
 drivers/firmware/Makefile                     |   1 +
 drivers/firmware/mediatek/Kconfig             |  10 +
 drivers/firmware/mediatek/Makefile            |   2 +
 drivers/firmware/mediatek/mtk-adsp-ipc.c      | 130 ++++++++++++
 drivers/mailbox/Kconfig                       |   7 +
 drivers/mailbox/Makefile                      |   2 +
 drivers/mailbox/mtk-adsp-mailbox.c            | 187 ++++++++++++++++++
 .../linux/firmware/mediatek/mtk-adsp-ipc.h    |  72 +++++++
 10 files changed, 465 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mailbox/mtk,adsp-mbox.yaml
 create mode 100644 drivers/firmware/mediatek/Kconfig
 create mode 100644 drivers/firmware/mediatek/Makefile
 create mode 100644 drivers/firmware/mediatek/mtk-adsp-ipc.c
 create mode 100644 drivers/mailbox/mtk-adsp-mailbox.c
 create mode 100644 include/linux/firmware/mediatek/mtk-adsp-ipc.h
Signature · 1 line
2.18.0
#1 lore raw

PATCH v3 1/3 dt-bindings: mediatek: add adsp-mbox document

From: Allen-KH Cheng <[email protected]>

This patch adds document for mediatek adsp mbox

---
 .../bindings/mailbox/mtk,adsp-mbox.yaml       | 53 +++++++++++++++++++
 1 file changed, 53 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mailbox/mtk,adsp-mbox.yaml
Documentation/devicetree/bindings/mailbox/mtk,adsp-mbox.yaml new file +53 -0
new file mode 100644
index 000000000000..f365182fa598
@@ -0,0 +1,53 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mailbox/mtk,adsp-mbox.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Mediatek ADSP mailbox
+
+maintainers:
+  - Allen-KH Cheng <[email protected]>
+
+description: |
+  The MTK ADSP mailbox Inter-Processor Communication (IPC) enables the SoC
+  to ommunicate with ADSP by passing messages through two mailbox channels.
+  The MTK ADSP mailbox IPC also provides the ability for one processor to
+  signal the other processor using interrupts.
+
+properties:
+  compatible:
+    items:
+      - const: mediatek,mt8195-adsp-mbox
+
+  "#mbox-cells":
+    const: 0
+
+  reg:
+    description:
+      Physical address base for dsp mbox base registers.
+
+  interrupts:
+    description:
+      adsp mbox interrupt
+
+required:
+  - compatible
+  - "#mbox-cells"
+  - reg
+  - interrupts
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    adsp_mailbox0:adsp_mailbox0@10816000 {
+        compatible = "mediatek,mt8195-adsp-mbox";
+        #mbox-cells = <0>;
+        reg = <0x10816000 0x1000>;
+        interrupts = <GIC_SPI 702 IRQ_TYPE_LEVEL_HIGH 0>;
+    };
+
Signature · 7 lines
2.18.0


_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
#2 lore raw

PATCH v3 2/3 mailbox: mediatek: add support for adsp mailbox controller

In reply to allen-kh.cheng

From: Allen-KH Cheng <[email protected]>

This patch is to for MediaTek ADSP IPC mailbox controller driver It is used to send short messages between processors with adsp

---
 drivers/mailbox/Kconfig            |   7 ++
 drivers/mailbox/Makefile           |   2 +
 drivers/mailbox/mtk-adsp-mailbox.c | 187 +++++++++++++++++++++++++++++
 3 files changed, 196 insertions(+)
 create mode 100644 drivers/mailbox/mtk-adsp-mailbox.c
drivers/mailbox/Kconfig +7 -0
index c9fc06c7e685..fc99d9fc80af 100644
@@ -236,6 +236,13 @@ config MTK_CMDQ_MBOX
 	  critical time limitation, such as updating display configuration
 	  during the vblank.
 
+config MTK_ADSP_IPC_MBOX
+	tristate "MediaTek ADSP Mailbox Controller"
+	depends on ARCH_MEDIATEK || COMPILE_TEST
+	help
+	  Say yes here to add support for MediaTek ADSP IPC mailbox controller
+	  driver. It is used to send short messages between processors with dsp.
+
 config ZYNQMP_IPI_MBOX
 	bool "Xilinx ZynqMP IPI Mailbox"
 	depends on ARCH_ZYNQMP && OF
drivers/mailbox/Makefile +2 -0
index c2089f04887e..479a9ae56d5e 100644
@@ -51,6 +51,8 @@ obj-$(CONFIG_STM32_IPCC) 	+= stm32-ipcc.o
 
 obj-$(CONFIG_MTK_CMDQ_MBOX)	+= mtk-cmdq-mailbox.o
 
+obj-$(CONFIG_MTK_ADSP_IPC_MBOX)	+= mtk-adsp-mailbox.o
+
 obj-$(CONFIG_ZYNQMP_IPI_MBOX)	+= zynqmp-ipi-mailbox.o
 
 obj-$(CONFIG_SUN6I_MSGBOX)	+= sun6i-msgbox.o
drivers/mailbox/mtk-adsp-mailbox.c new file +187 -0

187 lines not on this page · raw message

Signature · 1 line
2.18.0
#3 lore raw

Re: [PATCH v3 2/3] mailbox: mediatek: add support for adsp mailbox controller

Quoted 5 lines · allen-kh.cheng
drivers/mailbox/Kconfig +0 -0
index c9fc06c7e685..fc99d9fc80af 100644

drivers/mailbox/Kconfig config MTK_CMDQ_MBOX · line 244

Quoted 9 lines
drivers/mailbox/Kconfig +6 -0
@@ -236,6 +236,13 @@ config MTK_CMDQ_MBOX
 	  critical time limitation, such as updating display configuration
 	  during the vblank.
 
+config MTK_ADSP_IPC_MBOX
+	tristate "MediaTek ADSP Mailbox Controller"
+	depends on ARCH_MEDIATEK || COMPILE_TEST
+	help
+	  Say yes here to add support for MediaTek ADSP IPC mailbox controller
+	  driver. It is used to send short messages between processors with dsp.

Although the file didn't maintain alphabetical order, to be neat, moving MTK_ADSP_IPC_MBOX before MTK_CMDQ_MBOX makes more sense.

drivers/mailbox/Makefile obj-$(CONFIG_STM32_IPCC) += stm32-ipcc.o · line 55

Quoted 10 lines
drivers/mailbox/Makefile +2 -0
index c2089f04887e..479a9ae56d5e 100644
@@ -51,6 +51,8 @@ obj-$(CONFIG_STM32_IPCC) 	+= stm32-ipcc.o
 
 obj-$(CONFIG_MTK_CMDQ_MBOX)	+= mtk-cmdq-mailbox.o
 
+obj-$(CONFIG_MTK_ADSP_IPC_MBOX)	+= mtk-adsp-mailbox.o
+

Ditto. Move CONFIG_MTK_ADSP_IPC_MBOX before CONFIG_MTK_CMDQ_MBOX without blank line separation.

Quoted 1 line
drivers/mailbox/mtk-adsp-mailbox.c +0 -0

[...]

drivers/mailbox/mtk-adsp-mailbox.c line 35

Quoted 3 lines
drivers/mailbox/mtk-adsp-mailbox.c +3 -0
+static irqreturn_t mtk_adsp_ipc_irq_handler(int irq, void *data)
+{
+	struct mbox_chan *ch = (struct mbox_chan *)data;

The cast should be able to remove.

drivers/mailbox/mtk-adsp-mailbox.c line 47

Quoted 3 lines
drivers/mailbox/mtk-adsp-mailbox.c +3 -0
+static irqreturn_t mtk_adsp_ipc_handler(int irq, void *data)
+{
+	struct mbox_chan *ch = (struct mbox_chan *)data;

The cast should be able to remove.

Quoted 6 lines
drivers/mailbox/mtk-adsp-mailbox.c +6 -0
+static int mtk_adsp_mbox_startup(struct mbox_chan *chan)
+{
+	struct adsp_mbox_ch_info *ch_info = chan->con_priv;
+	void __iomem *reg = ch_info->va_reg;
+
+	/* Clear DSP mbox command */

drivers/mailbox/mtk-adsp-mailbox.c line 76

Quoted 10 lines
drivers/mailbox/mtk-adsp-mailbox.c +10 -0
+	writel(0xFFFFFFFF, reg + MTK_ADSP_MBOX_IN_CMD_CLR);
+	writel(0xFFFFFFFF, reg + MTK_ADSP_MBOX_OUT_CMD_CLR);
+
+	return 0;
+}
+
+static void mtk_adsp_mbox_shutdown(struct mbox_chan *chan)
+{
+	chan->con_priv = NULL;
+}

Shall mtk_adsp_mbox_shutdown() also clear DSP mbox? I.e.:
writel(0xFFFFFFFF, reg + MTK_ADSP_MBOX_IN_CMD_CLR); writel(0xFFFFFFFF, reg + MTK_ADSP_MBOX_OUT_CMD_CLR);

drivers/mailbox/mtk-adsp-mailbox.c line 85

Quoted 8 lines
drivers/mailbox/mtk-adsp-mailbox.c +8 -0
+static int mtk_adsp_mbox_send_data(struct mbox_chan *chan, void *data)
+{
+	struct adsp_mbox_ch_info *ch_info = chan->con_priv;
+	void __iomem *reg = ch_info->va_reg;
+
+	spin_lock(&ch_info->lock);
+	writel(ch_info->ipc_op_val, reg + MTK_ADSP_MBOX_IN_CMD);
+	spin_unlock(&ch_info->lock);

Why does it need the lock?

Is the write to MTK_ADSP_MBOX_IN_CMD a synchronous operation?
- If yes, I failed to understand why does it need the lock. Every calls to mtk_adsp_mbox_send_data() should wait for the data transfer completion.
- If no, I also failed to understand why. mtk_adsp_mbox_send_data() has no way to be aware of the transfer completion. Would expect a loop for checking the completion for the case.

drivers/mailbox/mtk-adsp-mailbox.c line 96

Quoted 7 lines
drivers/mailbox/mtk-adsp-mailbox.c +7 -0
+static bool mtk_adsp_mbox_last_tx_done(struct mbox_chan *chan)
+{
+	struct adsp_mbox_ch_info *ch_info = chan->con_priv;
+	void __iomem *reg = ch_info->va_reg;
+	u32 op = readl(reg + MTK_ADSP_MBOX_IN_CMD);
+
+	return (op == 0) ? true : false;

To be concise, return readl(...) == 0;

Quoted 2 lines
drivers/mailbox/mtk-adsp-mailbox.c +2 -0
+static int mtk_adsp_mbox_probe(struct platform_device *pdev)
+{

[...]

drivers/mailbox/mtk-adsp-mailbox.c line 141

Quoted 10 lines
drivers/mailbox/mtk-adsp-mailbox.c +10 -0
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res) {
+		dev_err(dev, "no adsp mbox register resource\n");
+		return -ENXIO;
+	}
+
+	size = resource_size(res);
+	priv->va_mboxreg = devm_ioremap(dev, (phys_addr_t)res->start, size);
+	if (IS_ERR(priv->va_mboxreg))
+		return PTR_ERR(priv->va_mboxreg);

Use devm_platform_ioremap_resource(), it should be equivalent.

drivers/mailbox/mtk-adsp-mailbox.c line 155

Quoted 2 lines
drivers/mailbox/mtk-adsp-mailbox.c +2 -0
+	/* set adsp mbox channel info */
+	ch_info = devm_kzalloc(mbox->dev, sizeof(*ch_info), GFP_KERNEL);

To be neat, use dev instead of mbox->dev.

drivers/mailbox/mtk-adsp-mailbox.c line 167

Quoted 5 lines
drivers/mailbox/mtk-adsp-mailbox.c +5 -0
+	ret = devm_mbox_controller_register(dev, &priv->mbox);
+	if (ret < 0)
+		dev_err(dev, "error: failed to register mailbox:%d\n", ret);
+
+	return ret;

To be concise, return devm_mbox_controller_register(...);

#4 lore raw

Re: [PATCH v3 2/3] mailbox: mediatek: add support for adsp mailbox controller

Hi Tzung-Bi,

Thanks for your suggestions.

Quoted 96 lines · Tzung-Bi Shih
Quoted 96 lines · allen-kh.cheng
Quoted 9 lines
Quoted 9 lines
drivers/mailbox/Kconfig +0 -0
index c9fc06c7e685..fc99d9fc80af 100644
@@ -236,6 +236,13 @@ config MTK_CMDQ_MBOX
     critical time limitation, such as updating display

configuration
during the vblank.

Quoted 7 lines
Quoted 7 lines
drivers/mailbox/Kconfig +5 -0
+config MTK_ADSP_IPC_MBOX
+  tristate "MediaTek ADSP Mailbox Controller"
+  depends on ARCH_MEDIATEK || COMPILE_TEST
+  help
+    Say yes here to add support for MediaTek ADSP IPC mailbox

controller
+ driver. It is used to send short messages between

processors

Quoted 1 line
Quoted 1 line

with dsp.

Although the file didn't maintain alphabetical order, to be neat, moving MTK_ADSP_IPC_MBOX before MTK_CMDQ_MBOX makes more sense.

Quoted 1 line

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/mailbox/Makefile

Quoted 9 lines

drivers/mailbox/Makefile obj-$(CONFIG_STM32_IPCC) += stm32-ipcc.o · line 55

Quoted 9 lines

index c2089f04887e..479a9ae56d5e 100644

drivers/mailbox/Makefile +2 -0
@@ -51,6 +51,8 @@ obj-$(CONFIG_STM32_IPCC)  += stm32-ipcc.o
 
 obj-$(CONFIG_MTK_CMDQ_MBOX) += mtk-cmdq-mailbox.o
 
+obj-$(CONFIG_MTK_ADSP_IPC_MBOX) += mtk-adsp-mailbox.o
+

Ditto. Move CONFIG_MTK_ADSP_IPC_MBOX before CONFIG_MTK_CMDQ_MBOX without blank line separation.

Quoted 2 lines
Quoted 2 lines
drivers/mailbox/mtk-adsp-mailbox.c +0 -0

[...]

Quoted 1 line
Quoted 1 line

+static irqreturn_t mtk_adsp_ipc_irq_handler(int irq, void

*data)

Quoted 2 lines

drivers/mailbox/mtk-adsp-mailbox.c

Quoted 2 lines
drivers/mailbox/mtk-adsp-mailbox.c +2 -0
+{
+  struct mbox_chan *ch = (struct mbox_chan *)data;

The cast should be able to remove.

Quoted 3 lines

drivers/mailbox/mtk-adsp-mailbox.c line 47

Quoted 3 lines
drivers/mailbox/mtk-adsp-mailbox.c +3 -0
+static irqreturn_t mtk_adsp_ipc_handler(int irq, void *data)
+{
+  struct mbox_chan *ch = (struct mbox_chan *)data;

The cast should be able to remove.

Quoted 8 lines
Quoted 8 lines
drivers/mailbox/mtk-adsp-mailbox.c +8 -0
+static int mtk_adsp_mbox_startup(struct mbox_chan *chan)
+{
+  struct adsp_mbox_ch_info *ch_info = chan->con_priv;
+  void __iomem *reg = ch_info->va_reg;
+
+  /* Clear DSP mbox command */
+  writel(0xFFFFFFFF, reg + MTK_ADSP_MBOX_IN_CMD_CLR);
+  writel(0xFFFFFFFF, reg + MTK_ADSP_MBOX_OUT_CMD_CLR);
Quoted 8 lines

drivers/mailbox/mtk-adsp-mailbox.c line 76

Quoted 8 lines
drivers/mailbox/mtk-adsp-mailbox.c +8 -0
+
+  return 0;
+}
+
+static void mtk_adsp_mbox_shutdown(struct mbox_chan *chan)
+{
+  chan->con_priv = NULL;
+}

Shall mtk_adsp_mbox_shutdown() also clear DSP mbox? I.e.:
writel(0xFFFFFFFF, reg + MTK_ADSP_MBOX_IN_CMD_CLR); writel(0xFFFFFFFF, reg + MTK_ADSP_MBOX_OUT_CMD_CLR);

Quoted 1 line
Quoted 1 line

+static int mtk_adsp_mbox_send_data(struct mbox_chan *chan,

void

Quoted 8 lines

drivers/mailbox/mtk-adsp-mailbox.c line 85

Quoted 8 lines

*data)

drivers/mailbox/mtk-adsp-mailbox.c +7 -0
+{
+  struct adsp_mbox_ch_info *ch_info = chan->con_priv;
+  void __iomem *reg = ch_info->va_reg;
+
+  spin_lock(&ch_info->lock);
+  writel(ch_info->ipc_op_val, reg + MTK_ADSP_MBOX_IN_CMD);
+  spin_unlock(&ch_info->lock);

Why does it need the lock?

Quoted 11 lines
Quoted 3 lines

Is the write to MTK_ADSP_MBOX_IN_CMD a synchronous operation?
- If yes, I failed to understand why does it need the lock. Every calls to mtk_adsp_mbox_send_data() should wait for the data

transfer

Quoted 2 lines

completion.
- If no, I also failed to understand

why. mtk_adsp_mbox_send_data()

Quoted 3 lines

has no way to be aware of the transfer completion. Would expect a loop for checking the completion for the case.

In ADSP MBOX IPC flow,

Host would call mbox send data when the shared data transfer completed.

(mtk_adsp_mbox_send_data will notice client using MTK_ADSP_MBOX_IN_CMD)

It’s more like a signal.

In general case,

There may be some hosts use the same mbox channel.

I think it’s better using lock to protect access to MTK_ADSP_MBOX_IN_CMD registers

Thanks,
Allen

Quoted 47 lines
Quoted 47 lines
Quoted 7 lines

drivers/mailbox/mtk-adsp-mailbox.c line 96

Quoted 7 lines
drivers/mailbox/mtk-adsp-mailbox.c +7 -0
+static bool mtk_adsp_mbox_last_tx_done(struct mbox_chan *chan)
+{
+  struct adsp_mbox_ch_info *ch_info = chan->con_priv;
+  void __iomem *reg = ch_info->va_reg;
+  u32 op = readl(reg + MTK_ADSP_MBOX_IN_CMD);
+
+  return (op == 0) ? true : false;

To be concise, return readl(...) == 0;

Quoted 2 lines
Quoted 2 lines
drivers/mailbox/mtk-adsp-mailbox.c +2 -0
+static int mtk_adsp_mbox_probe(struct platform_device *pdev)
+{

[...]

Quoted 8 lines

drivers/mailbox/mtk-adsp-mailbox.c

Quoted 8 lines
drivers/mailbox/mtk-adsp-mailbox.c +8 -0
+  res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+  if (!res) {
+      dev_err(dev, "no adsp mbox register resource\n");
+      return -ENXIO;
+  }
+
+  size = resource_size(res);
+  priv->va_mboxreg = devm_ioremap(dev, (phys_addr_t)res-
Quoted 4 lines

start,

Quoted 3 lines

size);

drivers/mailbox/mtk-adsp-mailbox.c +2 -0
+  if (IS_ERR(priv->va_mboxreg))
+      return PTR_ERR(priv->va_mboxreg);

Use devm_platform_ioremap_resource(), it should be equivalent.

Quoted 3 lines
Quoted 3 lines
drivers/mailbox/mtk-adsp-mailbox.c +2 -0
+  /* set adsp mbox channel info */
+  ch_info = devm_kzalloc(mbox->dev, sizeof(*ch_info),

GFP_KERNEL);

To be neat, use dev instead of mbox->dev.

Quoted 6 lines
Quoted 6 lines
drivers/mailbox/mtk-adsp-mailbox.c +3 -0
+  ret = devm_mbox_controller_register(dev, &priv->mbox);
+  if (ret < 0)
+      dev_err(dev, "error: failed to register mailbox:%d\n",

ret);

drivers/mailbox/mtk-adsp-mailbox.c +2 -0
+
+  return ret;
Quoted 4 lines
Quoted 1 line

To be concise, return devm_mbox_controller_register(...);

_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek

#5 lore raw

Re: [PATCH v3 2/3] mailbox: mediatek: add support for adsp mailbox controller

Quoted 34 lines · allen-kh.cheng
Quoted 15 lines · Tzung-Bi Shih
Quoted 15 lines · allen-kh.cheng
Quoted 1 line
Quoted 1 line

+static int mtk_adsp_mbox_send_data(struct mbox_chan *chan,

void

Quoted 8 lines

drivers/mailbox/mtk-adsp-mailbox.c line 85

Quoted 8 lines

*data)

drivers/mailbox/mtk-adsp-mailbox.c new file +7 -0
+{
+  struct adsp_mbox_ch_info *ch_info = chan->con_priv;
+  void __iomem *reg = ch_info->va_reg;
+
+  spin_lock(&ch_info->lock);
+  writel(ch_info->ipc_op_val, reg + MTK_ADSP_MBOX_IN_CMD);
+  spin_unlock(&ch_info->lock);

Why does it need the lock?

Quoted 11 lines
Quoted 3 lines

Is the write to MTK_ADSP_MBOX_IN_CMD a synchronous operation?
- If yes, I failed to understand why does it need the lock. Every calls to mtk_adsp_mbox_send_data() should wait for the data

transfer

Quoted 2 lines

completion.
- If no, I also failed to understand

why. mtk_adsp_mbox_send_data()

Quoted 3 lines

has no way to be aware of the transfer completion. Would expect a loop for checking the completion for the case.

In ADSP MBOX IPC flow,

Host would call mbox send data when the shared data transfer completed.

(mtk_adsp_mbox_send_data will notice client using MTK_ADSP_MBOX_IN_CMD)

Quoted 8 lines

It’s more like a signal.

In general case,

There may be some hosts use the same mbox channel.

I think it’s better using lock to protect access to MTK_ADSP_MBOX_IN_CMD registers

I still failed to understand. What if 2 hosts notify the same client by writing MTK_ADSP_MBOX_IN_CMD at the same time?

_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek

#6 lore raw

Re: [PATCH v3 2/3] mailbox: mediatek: add support for adsp mailbox controller

Quoted 59 lines · Tzung-Bi Shih
Quoted 59 lines · allen-kh.cheng
Quoted 58 lines
Quoted 58 lines · Tzung-Bi Shih
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

On Wed, Nov 24, 2021 at 04:45:13PM +0800, allen-

Quoted 13 lines · kh.cheng
Quoted 13 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

+static int mtk_adsp_mbox_send_data(struct

mbox_chan *chan,

Quoted 10 lines
Quoted 5 lines

void

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

*data)

(quoted diff) +2 -0
+{
+  struct adsp_mbox_ch_info *ch_info = chan-

con_priv;

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/mailbox/mtk-adsp-mailbox.c new file +4 -0
+  void __iomem *reg = ch_info->va_reg;
+
+  spin_lock(&ch_info->lock);
+  writel(ch_info->ipc_op_val, reg +
Quoted 7 lines
Quoted 7 lines

MTK_ADSP_MBOX_IN_CMD);

Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

+ spin_unlock(&ch_info->lock);

Why does it need the lock?

Is the write to MTK_ADSP_MBOX_IN_CMD a synchronous

operation?

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

- If yes, I failed to understand why does it need the lock. Every
calls to mtk_adsp_mbox_send_data() should wait for the

data

Quoted 8 lines
Quoted 8 lines

transfer

Quoted 2 lines
Quoted 2 lines

completion.
- If no, I also failed to understand

why. mtk_adsp_mbox_send_data()

Quoted 1 line
Quoted 1 line

has no way to be aware of the transfer

completion. Would

Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
Quoted 3 lines

expect a
loop for checking the completion for the case.

In ADSP MBOX IPC flow,

Host would call mbox send data when the shared data transfer completed.

(mtk_adsp_mbox_send_data will notice client using
MTK_ADSP_MBOX_IN_CMD)

It’s more like a signal.

In general case,

Quoted 9 lines
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

There may be some hosts use the same mbox channel.

I think it’s better using lock to protect access to MTK_ADSP_MBOX_IN_CMD registers

I still failed to understand. What if 2 hosts notify the same

client

Quoted 1 line

by writing MTK_ADSP_MBOX_IN_CMD at the same time?

Hi Tzung-Bi,

After I think carefully. There is no need to add lock in mtk_adsp_mbox_send_data.

In our dsp ipc design, we only have one host(ap) and one client(dsp).

If sof ip message transfer is complete, host will use mbox notice dsp message arrived.

(MTK_ADSP_MBOX_IN_CMD is signal to trigger mbox irq)

I will remove this in next version.

#7 lore raw

PATCH v3 3/3 firmware: mediatek: add adsp ipc protocol interface

In reply to allen-kh.cheng

From: Allen-KH Cheng <[email protected]>

Some of mediatek processors contain
the Tensilica HiFix DSP for audio processing.

The communication between Host CPU and DSP firmware is taking place using a shared memory area for message passing.

ADSP IPC protocol offers (send/recv) interfaces using mediatek-mailbox APIs.

We use two mbox channels to implement a request-reply protocol.

---
 drivers/firmware/Kconfig                      |   1 +
 drivers/firmware/Makefile                     |   1 +
 drivers/firmware/mediatek/Kconfig             |  10 ++
 drivers/firmware/mediatek/Makefile            |   2 +
 drivers/firmware/mediatek/mtk-adsp-ipc.c      | 130 ++++++++++++++++++
 .../linux/firmware/mediatek/mtk-adsp-ipc.h    |  72 ++++++++++
 6 files changed, 216 insertions(+)
 create mode 100644 drivers/firmware/mediatek/Kconfig
 create mode 100644 drivers/firmware/mediatek/Makefile
 create mode 100644 drivers/firmware/mediatek/mtk-adsp-ipc.c
 create mode 100644 include/linux/firmware/mediatek/mtk-adsp-ipc.h
drivers/firmware/Kconfig +1 -0
index 220a58cf0a44..005f76a9a31a 100644
@@ -301,6 +301,7 @@ source "drivers/firmware/broadcom/Kconfig"
 source "drivers/firmware/google/Kconfig"
 source "drivers/firmware/efi/Kconfig"
 source "drivers/firmware/imx/Kconfig"
+source "drivers/firmware/mediatek/Kconfig"
 source "drivers/firmware/meson/Kconfig"
 source "drivers/firmware/psci/Kconfig"
 source "drivers/firmware/smccc/Kconfig"
drivers/firmware/Makefile +1 -0
index 5ced0673d94b..c0d1f3bdeae4 100644
@@ -33,6 +33,7 @@ obj-$(CONFIG_GOOGLE_FIRMWARE)	+= google/
 obj-$(CONFIG_EFI)		+= efi/
 obj-$(CONFIG_UEFI_CPER)		+= efi/
 obj-y				+= imx/
+obj-y				+= mediatek/
 obj-y				+= psci/
 obj-y				+= smccc/
 obj-y				+= tegra/
drivers/firmware/mediatek/Kconfig new file +10 -0
new file mode 100644
index 000000000000..84a3b3bf5146
@@ -0,0 +1,10 @@
+# SPDX-License-Identifier: GPL-2.0-only
+config MTK_ADSP_IPC
+	tristate "MTK ADSP IPC Protocol driver"
+	depends on MTK_ADSP_IPC_MBOX
+	help
+	  Say yes here to add support for the MediaTek ADSP IPC protocol
+	  between host AP (Linux) and the firmware running on ADSP.
+	  ADSP exists on some mtk processors.
+	  Client might use shared memory to exchange information with ADSP side.
+
drivers/firmware/mediatek/Makefile new file +2 -0
new file mode 100644
index 000000000000..4e840b65650d
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0
+obj-$(CONFIG_MTK_ADSP_IPC)		+= mtk-adsp-ipc.o
drivers/firmware/mediatek/mtk-adsp-ipc.c new file +130 -0

130 lines not on this page · raw message

include/linux/firmware/mediatek/mtk-adsp-ipc.h new file +72 -0

72 lines not on this page · raw message

Signature · 7 lines
2.18.0


_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
#8 lore raw

Re: [PATCH v3 3/3] firmware: mediatek: add adsp ipc protocol interface

Quoted 11 lines · allen-kh.cheng
 drivers/firmware/Kconfig                      |   1 +
 drivers/firmware/Makefile                     |   1 +
 drivers/firmware/mediatek/Kconfig             |  10 ++
 drivers/firmware/mediatek/Makefile            |   2 +
 drivers/firmware/mediatek/mtk-adsp-ipc.c      | 130 ++++++++++++++++++
 .../linux/firmware/mediatek/mtk-adsp-ipc.h    |  72 ++++++++++
 6 files changed, 216 insertions(+)
 create mode 100644 drivers/firmware/mediatek/Kconfig
 create mode 100644 drivers/firmware/mediatek/Makefile
 create mode 100644 drivers/firmware/mediatek/mtk-adsp-ipc.c
 create mode 100644 include/linux/firmware/mediatek/mtk-adsp-ipc.h

The patch should move before the 2nd patch in the series as the 2nd patch uses mtk-adsp-ipc.h.

Quoted 1 line
drivers/firmware/mediatek/mtk-adsp-ipc.c +0 -0

[...]

drivers/firmware/mediatek/mtk-adsp-ipc.c line 22

Quoted 8 lines
drivers/firmware/mediatek/mtk-adsp-ipc.c +8 -0
+int adsp_ipc_send(struct mtk_adsp_ipc *ipc, unsigned int idx, uint32_t op)
+{
+	struct mtk_adsp_chan *dsp_chan = &ipc->chans[idx];
+	struct adsp_mbox_ch_info *ch_info = dsp_chan->ch->con_priv;
+	int ret;
+
+	if (idx >= MTK_ADSP_MBOX_NUM)
+		return -EINVAL;

If idx >= MTK_ADSP_MBOX_NUM, the invalid memory access has occurred at beginning of the function.

Quoted 2 lines
drivers/firmware/mediatek/mtk-adsp-ipc.c +2 -0
+static int mtk_adsp_ipc_probe(struct platform_device *pdev)
+{

[...]

drivers/firmware/mediatek/mtk-adsp-ipc.c line 53

Quoted 1 line
drivers/firmware/mediatek/mtk-adsp-ipc.c +1 -0
+	device_set_of_node_from_dev(&pdev->dev, pdev->dev.parent);

Why does it need to call device_set_of_node_from_dev()?

Quoted 11 lines
drivers/firmware/mediatek/mtk-adsp-ipc.c +11 -0
+	for (i = 0; i < MTK_ADSP_MBOX_NUM; i++) {
+		chan_name = kasprintf(GFP_KERNEL, "mbox%d", i);
+		if (!chan_name)
+			return -ENOMEM;
+
+		dsp_chan = &dsp_ipc->chans[i];
+		cl = &dsp_chan->cl;
+		cl->dev = dev->parent;
+		cl->tx_block = false;
+		cl->knows_txdone = false;
+		cl->tx_prepare = NULL;

drivers/firmware/mediatek/mtk-adsp-ipc.c line 79

Quoted 10 lines
drivers/firmware/mediatek/mtk-adsp-ipc.c +10 -0
+		cl->rx_callback = adsp_ipc_recv;
+
+		dsp_chan->ipc = dsp_ipc;
+		dsp_chan->idx = i;
+		dsp_chan->ch = mbox_request_channel_byname(cl, chan_name);
+		if (IS_ERR(dsp_chan->ch)) {
+			ret = PTR_ERR(dsp_chan->ch);
+			if (ret != -EPROBE_DEFER)
+				dev_err(dev, "Failed to request mbox chan %d ret %d\n",
+					i, ret);

If ret == -EPROBE_DEFER, wouldn't it need to return -EPROBE_DEFER? It doesn't retry later if -EPROBE_DEFER.

#9 lore raw

Re: [PATCH v3 3/3] firmware: mediatek: add adsp ipc protocol interface

Hi Tzung-Bi,

Thanks for your suggestions.

Quoted 34 lines · Tzung-Bi Shih
Quoted 4 lines · allen-kh.cheng
 drivers/firmware/Kconfig                      |   1 +
 drivers/firmware/Makefile                     |   1 +
 drivers/firmware/mediatek/Kconfig             |  10 ++
 drivers/firmware/mediatek/Makefile            |   2 +
Quoted 8 lines
 drivers/firmware/mediatek/mtk-adsp-ipc.c      | 130
++++++++++++++++++
 .../linux/firmware/mediatek/mtk-adsp-ipc.h    |  72 ++++++++++
 6 files changed, 216 insertions(+)
 create mode 100644 drivers/firmware/mediatek/Kconfig
 create mode 100644 drivers/firmware/mediatek/Makefile
 create mode 100644 drivers/firmware/mediatek/mtk-adsp-ipc.c
 create mode 100644 include/linux/firmware/mediatek/mtk-adsp-ipc.h

The patch should move before the 2nd patch in the series as the 2nd patch uses mtk-adsp-ipc.h.

Quoted 2 lines
drivers/firmware/mediatek/mtk-adsp-ipc.c +0 -0

[...]

drivers/firmware/mediatek/mtk-adsp-ipc.c line 22

Quoted 9 lines

+int adsp_ipc_send(struct mtk_adsp_ipc *ipc, unsigned int idx, uint32_t op)

drivers/firmware/mediatek/mtk-adsp-ipc.c +7 -0
+{
+	struct mtk_adsp_chan *dsp_chan = &ipc->chans[idx];
+	struct adsp_mbox_ch_info *ch_info = dsp_chan->ch->con_priv;
+	int ret;
+
+	if (idx >= MTK_ADSP_MBOX_NUM)
+		return -EINVAL;

If idx >= MTK_ADSP_MBOX_NUM, the invalid memory access has occurred at beginning of the function.

Quoted 7 lines
Quoted 2 lines
drivers/firmware/mediatek/mtk-adsp-ipc.c +2 -0
+static int mtk_adsp_ipc_probe(struct platform_device *pdev)
+{

[...]

drivers/firmware/mediatek/mtk-adsp-ipc.c line 53

Quoted 1 line
drivers/firmware/mediatek/mtk-adsp-ipc.c +1 -0
+	device_set_of_node_from_dev(&pdev->dev, pdev->dev.parent);

Why does it need to call device_set_of_node_from_dev()?

The original design regards mt8195 sof of_node as a parent deivce of mtk-adsp-ipc.

device_set_of_node_from_dev will set of_node_reuse flag to prevent driver from attempting to claim any mbox ipc resources already claimed by the sof dsp device.

Quoted 19 lines
Quoted 19 lines
drivers/firmware/mediatek/mtk-adsp-ipc.c +16 -0
+	for (i = 0; i < MTK_ADSP_MBOX_NUM; i++) {
+		chan_name = kasprintf(GFP_KERNEL, "mbox%d", i);
+		if (!chan_name)
+			return -ENOMEM;
+
+		dsp_chan = &dsp_ipc->chans[i];
+		cl = &dsp_chan->cl;
+		cl->dev = dev->parent;
+		cl->tx_block = false;
+		cl->knows_txdone = false;
+		cl->tx_prepare = NULL;
+		cl->rx_callback = adsp_ipc_recv;
+
+		dsp_chan->ipc = dsp_ipc;
+		dsp_chan->idx = i;
+		dsp_chan->ch = mbox_request_channel_byname(cl,

chan_name);

drivers/firmware/mediatek/mtk-adsp-ipc.c +1 -0
+		if (IS_ERR(dsp_chan->ch)) {
Quoted 8 lines

drivers/firmware/mediatek/mtk-adsp-ipc.c line 79

Quoted 5 lines
drivers/firmware/mediatek/mtk-adsp-ipc.c +3 -0
+			ret = PTR_ERR(dsp_chan->ch);
+			if (ret != -EPROBE_DEFER)
+				dev_err(dev, "Failed to request mbox

chan %d ret %d\n",

drivers/firmware/mediatek/mtk-adsp-ipc.c +1 -0
+					i, ret);

If ret == -EPROBE_DEFER, wouldn't it need to return -EPROBE_DEFER? It doesn't retry later if -EPROBE_DEFER.

If ret != -EPROBE_DEFER, it will show a error message then goto out.

If ret == -EPROBE_DEFER, probe funcation also will goto out.

Both of them will return ret. will not go to next round.

Thanks,
Allen

_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek

#10 lore raw

Re: [PATCH v3 3/3] firmware: mediatek: add adsp ipc protocol interface

Quoted 29 lines · allen-kh.cheng
Quoted 19 lines · Tzung-Bi Shih
Quoted 18 lines · allen-kh.cheng
drivers/firmware/mediatek/mtk-adsp-ipc.c new file +16 -0
+	for (i = 0; i < MTK_ADSP_MBOX_NUM; i++) {
+		chan_name = kasprintf(GFP_KERNEL, "mbox%d", i);
+		if (!chan_name)
+			return -ENOMEM;
+
+		dsp_chan = &dsp_ipc->chans[i];
+		cl = &dsp_chan->cl;
+		cl->dev = dev->parent;
+		cl->tx_block = false;
+		cl->knows_txdone = false;
+		cl->tx_prepare = NULL;
+		cl->rx_callback = adsp_ipc_recv;
+
+		dsp_chan->ipc = dsp_ipc;
+		dsp_chan->idx = i;
+		dsp_chan->ch = mbox_request_channel_byname(cl,

chan_name);

drivers/firmware/mediatek/mtk-adsp-ipc.c new file +1 -0
+		if (IS_ERR(dsp_chan->ch)) {
Quoted 8 lines

drivers/firmware/mediatek/mtk-adsp-ipc.c line 79

Quoted 5 lines
drivers/firmware/mediatek/mtk-adsp-ipc.c new file +3 -0
+			ret = PTR_ERR(dsp_chan->ch);
+			if (ret != -EPROBE_DEFER)
+				dev_err(dev, "Failed to request mbox

chan %d ret %d\n",

drivers/firmware/mediatek/mtk-adsp-ipc.c new file +1 -0
+					i, ret);

If ret == -EPROBE_DEFER, wouldn't it need to return -EPROBE_DEFER? It doesn't retry later if -EPROBE_DEFER.

Quoted 6 lines

If ret != -EPROBE_DEFER, it will show a error message then goto out.

If ret == -EPROBE_DEFER, probe funcation also will goto out.

Both of them will return ret. will not go to next round.

I see. I misunderstood.

_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek