Skip to contentSkip to conversation

ASPEED: Add mailbox driver for AST2700 series

PATCH Superseded Jammy Huang 3 participants 9 messages Jun 25, 2025 – Jun 27, 2025

Subsystems (3)

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v5 cover ASPEED: Add mailbox driver for AST2700 series

Add mailbox controller driver for AST27XX SoCs, which provides independent tx/rx mailbox between different processors. There are 4 channels for each tx/rx mailbox and each channel has an 32-byte FIFO.

v5 changes:
- Update document
1. Separate reg from 1 to 2. 1st is tx controller; 2nd is rx.
2. Remove 'Reviewed-by' since the patch has changed.
- Update driver, no functional changes.
1. Update since there is 2 reg base now.
2. Refine reg definitions
3. Add spinlock to protect registers
4. Use bool as return value for ast2700_mbox_tx_done
5. Rename variable from drv_data to dev_data.

v4 changes:
- Update driver, no functional changes.
1. Remove unused variable, rx_buff, in struct ast2700_mbox.
2. Remove unneeded cast on device_get_match_data.
3. Remove the usage of writel/readl_relaxed.
4. Improve readability.
v3 changes:
- Correct document
1. Use 32-bit addressing in dts example property, reg.
v2 changes:
- Update document
1. Correct error in dts example.
2. Drop description for mbox-cell per suggestion previously.

Jammy Huang (2):
dt-bindings: mailbox: Add ASPEED AST2700 series SoC
mailbox: aspeed: add mailbox driver for AST27XX series SoC

 .../mailbox/aspeed,ast2700-mailbox.yaml       |  60 +++++
 drivers/mailbox/Kconfig                       |   8 +
 drivers/mailbox/Makefile                      |   2 +
 drivers/mailbox/ast2700-mailbox.c             | 240 ++++++++++++++++++
 4 files changed, 310 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mailbox/aspeed,ast2700-mailbox.yaml
 create mode 100644 drivers/mailbox/ast2700-mailbox.c

base-commit: ec7714e4947909190ffb3041a03311a975350fe0

Signature · 1 line
2.25.1
#1 lore raw

PATCH v5 1/2 dt-bindings: mailbox: Add ASPEED AST2700 series SoC

Introduce the mailbox module for AST27XX series SoC, which is responsible for interchanging messages between asymmetric processors.

---
 .../mailbox/aspeed,ast2700-mailbox.yaml       | 60 +++++++++++++++++++
 1 file changed, 60 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mailbox/aspeed,ast2700-mailbox.yaml
Documentation/devicetree/bindings/mailbox/aspeed,ast2700-mailbox.yaml new file +60 -0
new file mode 100644
index 000000000000..0a5f43de5f28
@@ -0,0 +1,60 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mailbox/aspeed,ast2700-mailbox.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: ASPEED AST2700 mailbox controller
+
+maintainers:
+  - Jammy Huang <[email protected]>
+
+description:
+  ASPEED AST2700 has multiple processors that need to communicate with each
+  other. The mailbox controller provides a way for these processors to send
+  messages to each other. It is a hardware-based inter-processor communication
+  mechanism that allows processors to send and receive messages through
+  dedicated channels.
+  The mailbox's tx/rx are independent, meaning that one processor can send a
+  message while another processor is receiving a message simultaneously.
+  There are 4 channels available for both tx and rx operations. Each channel
+  has a FIFO buffer that can hold messages of a fixed size (32 bytes in this
+  case).
+  The mailbox controller also supports interrupt generation, allowing
+  processors to notify each other when a message is available or when an event
+  occurs.
+
+properties:
+  compatible:
+    const: aspeed,ast2700-mailbox
+
+  reg:
+    maxItems: 2
+    description:
+      Contains the base addresses and sizes of the mailbox controller. 1st one
+      is for TX control register; 2nd one is for RX control register.
+
+  interrupts:
+    maxItems: 1
+
+  "#mbox-cells":
+    const: 1
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - "#mbox-cells"
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+
+    mailbox@12c1c200 {
+        compatible = "aspeed,ast2700-mailbox";
+        reg = <0x12c1c200 0x100>, <0x12c1c300 0x100>;
+        interrupts = <GIC_SPI 103 IRQ_TYPE_LEVEL_HIGH>;
+        #mbox-cells = <1>;
+    };
Signature · 1 line
2.25.1
maintainer
#2 lore raw

Re: [PATCH v5 1/2] dt-bindings: mailbox: Add ASPEED AST2700 series SoC

Quoted 4 lines · Jammy Huang

Introduce the mailbox module for AST27XX series SoC, which is responsible for interchanging messages between asymmetric processors.

You didn't add Krzysztof's Reviewed-by...

Quoted 13 lines
---
 .../mailbox/aspeed,ast2700-mailbox.yaml       | 60 +++++++++++++++++++
 1 file changed, 60 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mailbox/aspeed,ast2700-mailbox.yaml
Documentation/devicetree/bindings/mailbox/aspeed,ast2700-mailbox.yaml new file +2 -0
new file mode 100644
index 000000000000..0a5f43de5f28
@@ -0,0 +1,60 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2

Documentation/devicetree/bindings/mailbox/aspeed,ast2700-mailbox.yaml line 12

Quoted 10 lines
Documentation/devicetree/bindings/mailbox/aspeed,ast2700-mailbox.yaml new file +10 -0
+---
+$id: http://devicetree.org/schemas/mailbox/aspeed,ast2700-mailbox.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: ASPEED AST2700 mailbox controller
+
+maintainers:
+  - Jammy Huang <[email protected]>
+
+description:

You need '>' to preserve paragraphs.

Documentation/devicetree/bindings/mailbox/aspeed,ast2700-mailbox.yaml line 17

Quoted 5 lines
Documentation/devicetree/bindings/mailbox/aspeed,ast2700-mailbox.yaml new file +5 -0
+  ASPEED AST2700 has multiple processors that need to communicate with each
+  other. The mailbox controller provides a way for these processors to send
+  messages to each other. It is a hardware-based inter-processor communication
+  mechanism that allows processors to send and receive messages through
+  dedicated channels.

And a blank line between paragraphs.

Documentation/devicetree/bindings/mailbox/aspeed,ast2700-mailbox.yaml line 22

Quoted 5 lines
Documentation/devicetree/bindings/mailbox/aspeed,ast2700-mailbox.yaml new file +5 -0
+  The mailbox's tx/rx are independent, meaning that one processor can send a
+  message while another processor is receiving a message simultaneously.
+  There are 4 channels available for both tx and rx operations. Each channel
+  has a FIFO buffer that can hold messages of a fixed size (32 bytes in this
+  case).

And here.

Documentation/devicetree/bindings/mailbox/aspeed,ast2700-mailbox.yaml line 35

Quoted 13 lines
Documentation/devicetree/bindings/mailbox/aspeed,ast2700-mailbox.yaml new file +13 -0
+  The mailbox controller also supports interrupt generation, allowing
+  processors to notify each other when a message is available or when an event
+  occurs.
+
+properties:
+  compatible:
+    const: aspeed,ast2700-mailbox
+
+  reg:
+    maxItems: 2
+    description:
+      Contains the base addresses and sizes of the mailbox controller. 1st one
+      is for TX control register; 2nd one is for RX control register.

Instead, just:

items:
- description: TX control register
- description: RX control register

Quoted 28 lines
Documentation/devicetree/bindings/mailbox/aspeed,ast2700-mailbox.yaml new file +25 -0
+
+  interrupts:
+    maxItems: 1
+
+  "#mbox-cells":
+    const: 1
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - "#mbox-cells"
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+
+    mailbox@12c1c200 {
+        compatible = "aspeed,ast2700-mailbox";
+        reg = <0x12c1c200 0x100>, <0x12c1c300 0x100>;
+        interrupts = <GIC_SPI 103 IRQ_TYPE_LEVEL_HIGH>;
+        #mbox-cells = <1>;
+    };
Signature · 1 line
2.25.1
#3 lore raw

RE: [PATCH v5 1/2] dt-bindings: mailbox: Add ASPEED AST2700 series SoC

Quoted 7 lines · Jammy Huang
Quoted 4 lines

Introduce the mailbox module for AST27XX series SoC, which is responsible for interchanging messages between asymmetric processors.

You didn't add Krzysztof's Reviewed-by...

Hi Rob,

I checked submitting patches' guide, and it says that if the patch has changed substantially in following version, these tags might not be applicable anymore and thus should be removed. I also mentioned this in changelog on the cover.

I am not sure about this, so may I keep Krzk's Reviewed-by tag? If it's OK, I will add it back on next patch.

Quoted 25 lines
Quoted 3 lines
---
 .../mailbox/aspeed,ast2700-mailbox.yaml       | 60

+++++++++++++++++++

Quoted 21 lines
 1 file changed, 60 insertions(+)
 create mode 100644

Documentation/devicetree/bindings/mailbox/aspeed,ast2700-mailbox.yaml

diff --git a/Documentation/devicetree/bindings/mailbox/aspeed,ast2700-mailbox.yam l b/Documentation/devicetree/bindings/mailbox/aspeed,ast2700-mailbox.yam l
new file mode 100644
index 000000000000..0a5f43de5f28

Documentation/devicetree/bindings/mailbox/aspeed,ast2700-mailbox new file +7 -0
+++ .yaml
@@ -0,0 +1,60 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) %YAML 1.2
+---
+$id:
+http://devicetree.org/schemas/mailbox/aspeed,ast2700-mailbox.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
Quoted 8 lines

Documentation/devicetree/bindings/mailbox/aspeed,ast2700-mailbox line 12

Quoted 6 lines
Documentation/devicetree/bindings/mailbox/aspeed,ast2700-mailbox new file +6 -0
+title: ASPEED AST2700 mailbox controller
+
+maintainers:
+  - Jammy Huang <[email protected]>
+
+description:

You need '>' to preserve paragraphs.

OK

Quoted 9 lines

Documentation/devicetree/bindings/mailbox/aspeed,ast2700-mailbox line 17

Quoted 6 lines
Documentation/devicetree/bindings/mailbox/aspeed,ast2700-mailbox new file +5 -0
+  ASPEED AST2700 has multiple processors that need to communicate
+ with each  other. The mailbox controller provides a way for these
+ processors to send  messages to each other. It is a hardware-based
+ inter-processor communication  mechanism that allows processors to
+ send and receive messages through  dedicated channels.

And a blank line between paragraphs.

OK

Quoted 9 lines

Documentation/devicetree/bindings/mailbox/aspeed,ast2700-mailbox line 19

Quoted 2 lines
Documentation/devicetree/bindings/mailbox/aspeed,ast2700-mailbox new file +2 -0
+  The mailbox's tx/rx are independent, meaning that one processor can
+ send a  message while another processor is receiving a message

simultaneously.

Documentation/devicetree/bindings/mailbox/aspeed,ast2700-mailbox line 22

Quoted 3 lines
Documentation/devicetree/bindings/mailbox/aspeed,ast2700-mailbox new file +3 -0
+  There are 4 channels available for both tx and rx operations. Each
+ channel  has a FIFO buffer that can hold messages of a fixed size
+ (32 bytes in this  case).

And here.

Sure.

Quoted 13 lines

Documentation/devicetree/bindings/mailbox/aspeed,ast2700-mailbox line 34

Quoted 12 lines
Documentation/devicetree/bindings/mailbox/aspeed,ast2700-mailbox new file +12 -0
+  The mailbox controller also supports interrupt generation, allowing
+ processors to notify each other when a message is available or when
+ an event  occurs.
+
+properties:
+  compatible:
+    const: aspeed,ast2700-mailbox
+
+  reg:
+    maxItems: 2
+    description:
+      Contains the base addresses and sizes of the mailbox controller. 1st

one

Quoted 8 lines

Documentation/devicetree/bindings/mailbox/aspeed,ast2700-mailbox line 35

Quoted 1 line
Documentation/devicetree/bindings/mailbox/aspeed,ast2700-mailbox new file +1 -0
+      is for TX control register; 2nd one is for RX control register.

Instead, just:

items:
- description: TX control register
- description: RX control register

Agree.

Quoted 20 lines
Quoted 20 lines
Documentation/devicetree/bindings/mailbox/aspeed,ast2700-mailbox new file +20 -0
+
+  interrupts:
+    maxItems: 1
+
+  "#mbox-cells":
+    const: 1
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - "#mbox-cells"
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+
+    mailbox@12c1c200 {
Quoted 8 lines
Quoted 8 lines
Documentation/devicetree/bindings/mailbox/aspeed,ast2700-mailbox new file +5 -1
+        compatible = "aspeed,ast2700-mailbox";
+        reg = <0x12c1c200 0x100>, <0x12c1c300 0x100>;
+        interrupts = <GIC_SPI 103 IRQ_TYPE_LEVEL_HIGH>;
+        #mbox-cells = <1>;
+    };
--

2.25.1

Thanks for your help.

Regards
Jammy

maintainer
#4 lore raw

Re: [PATCH v5 1/2] dt-bindings: mailbox: Add ASPEED AST2700 series SoC

In reply to Rob Herring
Quoted 6 lines · Rob Herring
Quoted 4 lines · Jammy Huang

Introduce the mailbox module for AST27XX series SoC, which is responsible for interchanging messages between asymmetric processors.

*snip*

Quoted 12 lines

Documentation/devicetree/bindings/mailbox/aspeed,ast2700-mailbox.yaml line 35

Quoted 9 lines
Documentation/devicetree/bindings/mailbox/aspeed,ast2700-mailbox.yaml new file +9 -0
+properties:
+  compatible:
+    const: aspeed,ast2700-mailbox
+
+  reg:
+    maxItems: 2
+    description:
+      Contains the base addresses and sizes of the mailbox controller. 1st one
+      is for TX control register; 2nd one is for RX control register.

Instead, just:

Quoted 3 lines

items:
  - description: TX control register
  - description: RX control register

Maybe also specify reg-names with "tx" and "rx"? That way we can use devm_platform_ioremap_resource_byname() in the linux driver implementation, which should look tidier.

Andrew

#5 lore raw

RE: [PATCH v5 1/2] dt-bindings: mailbox: Add ASPEED AST2700 series SoC

Quoted 23 lines · Rob Herring
Quoted 6 lines · Jammy Huang
Quoted 4 lines

Introduce the mailbox module for AST27XX series SoC, which is responsible for interchanging messages between asymmetric processors.

*snip*

Quoted 13 lines

Documentation/devicetree/bindings/mailbox/aspeed,ast2700-mailbox.yaml line 35

Quoted 10 lines
Documentation/devicetree/bindings/mailbox/aspeed,ast2700-mailbox.yaml new file +10 -0
+properties:
+  compatible:
+    const: aspeed,ast2700-mailbox
+
+  reg:
+    maxItems: 2
+    description:
+      Contains the base addresses and sizes of the mailbox
+controller. 1st one
+      is for TX control register; 2nd one is for RX control register.

Instead, just:

Quoted 7 lines
Quoted 3 lines

items:
  - description: TX control register
  - description: RX control register

Maybe also specify reg-names with "tx" and "rx"? That way we can use devm_platform_ioremap_resource_byname() in the linux driver implementation, which should look tidier.

Sounds good. I will do it.

Quoted 2 lines

Andrew

Regards
Jammy

#6 lore raw

PATCH v5 2/2 mailbox: aspeed: add mailbox driver for AST27XX series SoC

In reply to Jammy Huang

Add mailbox controller driver for AST27XX SoCs, which provides independent tx/rx mailbox between different processors. There are 4 channels for each tx/rx mailbox and each channel has an 32-byte FIFO.

---
 drivers/mailbox/Kconfig           |   8 +
 drivers/mailbox/Makefile          |   2 +
 drivers/mailbox/ast2700-mailbox.c | 240 ++++++++++++++++++++++++++++++
 3 files changed, 250 insertions(+)
 create mode 100644 drivers/mailbox/ast2700-mailbox.c
drivers/mailbox/Kconfig +8 -0
index 68eeed660a4a..1c38cd570091 100644
@@ -340,4 +340,12 @@ config THEAD_TH1520_MBOX
 	  kernel is running, and E902 core used for power management among other
 	  things.
 
+config AST2700_MBOX
+	tristate "ASPEED AST2700 IPC driver"
+	depends on ARCH_ASPEED || COMPILE_TEST
+	help
+	  Mailbox driver implementation for ASPEED AST27XX SoCs. This driver
+	  can be used to send message between different processors in SoC.
+	  The driver provides mailbox support for sending interrupts to the
+	  clients. Say Y here if you want to build this driver.
 endif
drivers/mailbox/Makefile +2 -0
index 13a3448b3271..9a9add9a7548 100644
@@ -72,3 +72,5 @@ obj-$(CONFIG_QCOM_CPUCP_MBOX)	+= qcom-cpucp-mbox.o
 obj-$(CONFIG_QCOM_IPCC)		+= qcom-ipcc.o
 
 obj-$(CONFIG_THEAD_TH1520_MBOX)	+= mailbox-th1520.o
+
+obj-$(CONFIG_AST2700_MBOX)	+= ast2700-mailbox.o
drivers/mailbox/ast2700-mailbox.c new file +240 -0

240 lines not on this page · raw message

Signature · 1 line
2.25.1
maintainer
#7 lore raw

Re: [PATCH v5 2/2] mailbox: aspeed: add mailbox driver for AST27XX series SoC

Quoted 93 lines · Jammy Huang

Add mailbox controller driver for AST27XX SoCs, which provides independent tx/rx mailbox between different processors. There are 4 channels for each tx/rx mailbox and each channel has an 32-byte FIFO.

---
 drivers/mailbox/Kconfig           |   8 + drivers/mailbox/Makefile          |   2 + drivers/mailbox/ast2700-mailbox.c | 240 ++++++++++++++++++++++++++++++

 3 files changed, 250 insertions(+)

 create mode 100644 drivers/mailbox/ast2700-mailbox.c

drivers/mailbox/Kconfig +0 -0
index 68eeed660a4a..1c38cd570091 100644
@@ -340,4 +340,12 @@ config THEAD_TH1520_MBOX

          kernel is running, and E902 core used for power management among other things.

+config AST2700_MBOX
+       tristate "ASPEED AST2700 IPC driver"
+       depends on ARCH_ASPEED || COMPILE_TEST
+       help
+         Mailbox driver implementation for ASPEED AST27XX SoCs. This driver +         can be used to send message between different processors in SoC. +         The driver provides mailbox support for sending interrupts to the +         clients. Say Y here if you want to build this driver. endif

drivers/mailbox/Makefile +0 -0
index 13a3448b3271..9a9add9a7548 100644
@@ -72,3 +72,5 @@ obj-$(CONFIG_QCOM_CPUCP_MBOX) += qcom-cpucp-mbox.o

 obj-$(CONFIG_QCOM_IPCC)                += qcom-ipcc.o
 obj-$(CONFIG_THEAD_TH1520_MBOX)        += mailbox-th1520.o

drivers/mailbox/Makefile +2 -0
+
+obj-$(CONFIG_AST2700_MBOX)     += ast2700-mailbox.o
drivers/mailbox/ast2700-mailbox.c new file +48 -0
new file mode 100644
index 000000000000..5470053f8139
@@ -0,0 +1,240 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright Aspeed Technology Inc. (C) 2025. All rights reserved
+ */
+
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/iopoll.h>
+#include <linux/kernel.h>
+#include <linux/mailbox_controller.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+
+/* Each bit in the register represents an IPC ID */
+#define IPCR_TX_TRIG           0x00
+#define IPCR_ENABLE            0x04
+#define IPCR_STATUS            0x08
+#define  RX_IRQ(n)             BIT(n)
+#define  RX_IRQ_MASK           0xf
+#define IPCR_DATA              0x10
+
+struct ast2700_mbox_data {
+       u8 num_chans;
+       u8 msg_size;
+};
+
+struct ast2700_mbox {
+       struct mbox_controller mbox;
+       u8 msg_size;
+       void __iomem *tx_regs;
+       void __iomem *rx_regs;
+       spinlock_t lock;
+};
+
+static inline int ch_num(struct mbox_chan *chan)
+{
+       return chan - chan->mbox->chans;
+}
+
+static inline bool ast2700_mbox_tx_done(struct ast2700_mbox *mb, int idx)
+{
+       return !(readl(mb->tx_regs + IPCR_STATUS) & BIT(idx));
+}
+
+static irqreturn_t ast2700_mbox_irq(int irq, void *p)
+{

drivers/mailbox/ast2700-mailbox.c line 58

Quoted 10 lines
drivers/mailbox/ast2700-mailbox.c new file +10 -0
+       struct ast2700_mbox *mb = p;
+       void __iomem *data_reg;
+       int num_words;
+       u32 *word_data;
+       u32 status;
+       int n;
+
+       /* Only examine channels that are currently enabled. */
+       status = readl(mb->rx_regs + IPCR_ENABLE) &
+                readl(mb->rx_regs + IPCR_STATUS);

Also need to lock over these reads to handle concurrent startup/shutdown?

Quoted 12 lines
drivers/mailbox/ast2700-mailbox.c new file +12 -0
+
+       if (!(status & RX_IRQ_MASK))
+               return IRQ_NONE;
+
+       for (n = 0; n < mb->mbox.num_chans; ++n) {
+               struct mbox_chan *chan = &mb->mbox.chans[n];
+
+               if (!(status & RX_IRQ(n)))
+                       continue;
+
+               /* Read the message data */
+               for (data_reg = mb->rx_regs + IPCR_DATA + mb->msg_size * n,

drivers/mailbox/ast2700-mailbox.c line 80

Quoted 10 lines
drivers/mailbox/ast2700-mailbox.c new file +10 -0
+                    word_data = chan->con_priv,
+                    num_words = (mb->msg_size / sizeof(u32));
+                    num_words;
+                    num_words--, data_reg += sizeof(u32), word_data++)
+                       *word_data = readl(data_reg);
+
+               mbox_chan_received_data(chan, chan->con_priv);
+
+               /* The IRQ can be cleared only once the FIFO is empty. */
+               writel(RX_IRQ(n), mb->rx_regs + IPCR_STATUS);

Can we rather clear the status once outside the loop immediately before return?

writel(status, mb->rx_regs + IPCR_STATUS);

Quoted 6 lines
drivers/mailbox/ast2700-mailbox.c new file +6 -0
+       }
+
+       return IRQ_HANDLED;
+}
+
+static int ast2700_mbox_send_data(struct mbox_chan *chan, void *data)

drivers/mailbox/ast2700-mailbox.c line 96

Quoted 10 lines
drivers/mailbox/ast2700-mailbox.c new file +10 -0
+{
+       struct ast2700_mbox *mb = dev_get_drvdata(chan->mbox->dev);
+       void __iomem *data_reg;
+       u32 *word_data;
+       int num_words;
+       int idx = ch_num(chan);
+
+       if (!(readl(mb->tx_regs + IPCR_ENABLE) & BIT(idx))) {
+               dev_warn(mb->mbox.dev, "%s: Ch-%d not enabled yet\n", __func__, idx);
+               return -EBUSY;

-ENODEV? I wouldn't say it's busy here :)

Quoted 11 lines
drivers/mailbox/ast2700-mailbox.c new file +11 -0
+       }
+
+       if (!(ast2700_mbox_tx_done(mb, idx))) {
+               dev_warn(mb->mbox.dev, "%s: Ch-%d last data has not finished\n", __func__, idx);
+               return -EBUSY;
+       }
+
+       /* Write the message data */
+       for (data_reg = mb->tx_regs + IPCR_DATA + mb->msg_size * idx,
+            word_data = (u32 *)data,
+            num_words = (mb->msg_size / sizeof(u32));

drivers/mailbox/ast2700-mailbox.c line 117

Quoted 10 lines
drivers/mailbox/ast2700-mailbox.c new file +10 -0
+            num_words;
+            num_words--, data_reg += sizeof(u32), word_data++)
+               writel(*word_data, data_reg);
+
+       writel(BIT(idx), mb->tx_regs + IPCR_TX_TRIG);
+       dev_dbg(mb->mbox.dev, "%s: Ch-%d sent\n", __func__, idx);
+
+       return 0;
+}
+

*snip*

Quoted 23 lines
drivers/mailbox/ast2700-mailbox.c new file +23 -0
+
+static int ast2700_mbox_probe(struct platform_device *pdev)
+{
+       struct ast2700_mbox *mb;
+       const struct ast2700_mbox_data *dev_data;
+       struct device *dev = &pdev->dev;
+       int irq, ret;
+
+       if (!pdev->dev.of_node)
+               return -ENODEV;
+
+       dev_data = device_get_match_data(&pdev->dev);
+
+       mb = devm_kzalloc(dev, sizeof(*mb), GFP_KERNEL);
+       if (!mb)
+               return -ENOMEM;
+
+       mb->mbox.chans = devm_kcalloc(&pdev->dev, dev_data->num_chans,
+                                     sizeof(*mb->mbox.chans), GFP_KERNEL);
+       if (!mb->mbox.chans)
+               return -ENOMEM;
+
+       /* con_priv of each channel is used to store the message received */

drivers/mailbox/ast2700-mailbox.c line 190

Quoted 10 lines
drivers/mailbox/ast2700-mailbox.c new file +10 -0
+       for (int i = 0; i < dev_data->num_chans; i++) {
+               mb->mbox.chans[i].con_priv = devm_kcalloc(dev, dev_data->msg_size,
+                                                         sizeof(u8), GFP_KERNEL);
+               if (!mb->mbox.chans[i].con_priv)
+                       return -ENOMEM;
+       }
+
+       platform_set_drvdata(pdev, mb);
+
+       mb->tx_regs = devm_platform_ioremap_resource(pdev, 0);

See the thought about reg-names on the binding.

Andrew

#8 lore raw

RE: [PATCH v5 2/2] mailbox: aspeed: add mailbox driver for AST27XX series SoC

Quoted 101 lines · Jammy Huang
Quoted 18 lines

Add mailbox controller driver for AST27XX SoCs, which provides independent tx/rx mailbox between different processors. There are 4 channels for each tx/rx mailbox and each channel has an 32-byte FIFO.

---
 drivers/mailbox/Kconfig           |   8 +
 drivers/mailbox/Makefile          |   2 +
 drivers/mailbox/ast2700-mailbox.c | 240
++++++++++++++++++++++++++++++

 3 files changed, 250 insertions(+)

 create mode 100644 drivers/mailbox/ast2700-mailbox.c

drivers/mailbox/Kconfig index renamed from drivers/mailbox/Kconfig +0 -0

68eeed660a4a..1c38cd570091 100644

drivers/mailbox/Kconfig +0 -0
@@ -340,4 +340,12 @@ config THEAD_TH1520_MBOX
Quoted 1 line

          kernel is running, and E902 core used for power

management

Quoted 8 lines

among other
          things.

+config AST2700_MBOX
+       tristate "ASPEED AST2700 IPC driver"
+       depends on ARCH_ASPEED || COMPILE_TEST
+       help
+         Mailbox driver implementation for ASPEED AST27XX SoCs.

This

Quoted 2 lines

+driver
+         can be used to send message between different processors in

SoC.

drivers/mailbox/Makefile obj-$(CONFIG_QCOM_CPUCP_MBOX) +=

Quoted 9 lines

+         The driver provides mailbox support for sending interrupts +to the
+         clients. Say Y here if you want to build this driver. endif

drivers/mailbox/Makefile index renamed from drivers/mailbox/Makefile +0 -0

13a3448b3271..9a9add9a7548 100644

drivers/mailbox/Makefile +0 -0
@@ -72,3 +72,5 @@ obj-$(CONFIG_QCOM_CPUCP_MBOX) +=

qcom-cpucp-mbox.o

Quoted 16 lines

 obj-$(CONFIG_QCOM_IPCC)                += qcom-ipcc.o

 obj-$(CONFIG_THEAD_TH1520_MBOX)        += mailbox-th1520.o

drivers/mailbox/Makefile +2 -0
+
+obj-$(CONFIG_AST2700_MBOX)     += ast2700-mailbox.o
drivers/mailbox/ast2700-mailbox.c new file +4 -0
new file mode 100644
index 000000000000..5470053f8139
@@ -0,0 +1,240 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright Aspeed Technology Inc. (C) 2025. All rights reserved  */
+

drivers/mailbox/ast2700-mailbox.c line 14

Quoted 10 lines
drivers/mailbox/ast2700-mailbox.c new file +10 -0
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/iopoll.h>
+#include <linux/kernel.h>
+#include <linux/mailbox_controller.h> #include <linux/module.h>
+#include <linux/of.h> #include <linux/platform_device.h> #include
+<linux/slab.h>
+
+/* Each bit in the register represents an IPC ID */ #define
+IPCR_TX_TRIG           0x00 #define

IPCR_ENABLE            0x04

drivers/mailbox/ast2700-mailbox.c line 19

Quoted 1 line
drivers/mailbox/ast2700-mailbox.c new file +1 -0
+#define IPCR_STATUS            0x08

#define  RX_IRQ(n)

drivers/mailbox/ast2700-mailbox.c line 16

Quoted 1 line
drivers/mailbox/ast2700-mailbox.c new file +1 -0
+BIT(n) #define  RX_IRQ_MASK           0xf #define

IPCR_DATA

Quoted 27 lines
drivers/mailbox/ast2700-mailbox.c new file +27 -0
+0x10
+
+struct ast2700_mbox_data {
+       u8 num_chans;
+       u8 msg_size;
+};
+
+struct ast2700_mbox {
+       struct mbox_controller mbox;
+       u8 msg_size;
+       void __iomem *tx_regs;
+       void __iomem *rx_regs;
+       spinlock_t lock;
+};
+
+static inline int ch_num(struct mbox_chan *chan) {
+       return chan - chan->mbox->chans; }
+
+static inline bool ast2700_mbox_tx_done(struct ast2700_mbox *mb, int
+idx) {
+       return !(readl(mb->tx_regs + IPCR_STATUS) & BIT(idx)); }
+
+static irqreturn_t ast2700_mbox_irq(int irq, void *p) {
+       struct ast2700_mbox *mb = p;
+       void __iomem *data_reg;
+       int num_words;
+       u32 *word_data;
Quoted 8 lines

drivers/mailbox/ast2700-mailbox.c line 58

Quoted 6 lines
drivers/mailbox/ast2700-mailbox.c new file +6 -0
+       u32 status;
+       int n;
+
+       /* Only examine channels that are currently enabled. */
+       status = readl(mb->rx_regs + IPCR_ENABLE) &
+                readl(mb->rx_regs + IPCR_STATUS);

Also need to lock over these reads to handle concurrent startup/shutdown?

It read-only here. I think it's fine.

Quoted 26 lines

drivers/mailbox/ast2700-mailbox.c

Quoted 13 lines
drivers/mailbox/ast2700-mailbox.c new file +12 -0
+
+       if (!(status & RX_IRQ_MASK))
+               return IRQ_NONE;
+
+       for (n = 0; n < mb->mbox.num_chans; ++n) {
+               struct mbox_chan *chan = &mb->mbox.chans[n];
+
+               if (!(status & RX_IRQ(n)))
+                       continue;
+
+               /* Read the message data */
+               for (data_reg = mb->rx_regs + IPCR_DATA +

mb->msg_size

drivers/mailbox/ast2700-mailbox.c

Quoted 11 lines
drivers/mailbox/ast2700-mailbox.c new file +11 -0
+* n,
+                    word_data = chan->con_priv,
+                    num_words = (mb->msg_size / sizeof(u32));
+                    num_words;
+                    num_words--, data_reg += sizeof(u32),
+word_data++)
+                       *word_data = readl(data_reg);
+
+               mbox_chan_received_data(chan, chan->con_priv);
+
+               /* The IRQ can be cleared only once the FIFO is

empty.

Quoted 7 lines

drivers/mailbox/ast2700-mailbox.c line 74

Quoted 2 lines
drivers/mailbox/ast2700-mailbox.c new file +2 -0
+*/
+               writel(RX_IRQ(n), mb->rx_regs + IPCR_STATUS);

Can we rather clear the status once outside the loop immediately before return?

writel(status, mb->rx_regs + IPCR_STATUS);

I think it's better to keep current way. Because tx side could polling check rx-status to know if tx is done. mbox_chan_received_data() here will invoke the callback registered by mailbox-client. It could take times depending on how the callback is implemented. Since we have 4 channels now, clear it earlier can have better performance.

Quoted 82 lines

drivers/mailbox/ast2700-mailbox.c

Quoted 9 lines
drivers/mailbox/ast2700-mailbox.c new file +8 -0
+       }
+
+       return IRQ_HANDLED;
+}
+
+static int ast2700_mbox_send_data(struct mbox_chan *chan, void *data)
+{
+       struct ast2700_mbox *mb =

dev_get_drvdata(chan->mbox->dev);

drivers/mailbox/ast2700-mailbox.c

Quoted 7 lines
drivers/mailbox/ast2700-mailbox.c new file +7 -0
+       void __iomem *data_reg;
+       u32 *word_data;
+       int num_words;
+       int idx = ch_num(chan);
+
+       if (!(readl(mb->tx_regs + IPCR_ENABLE) & BIT(idx))) {
+               dev_warn(mb->mbox.dev, "%s: Ch-%d not enabled

yet\n",

drivers/mailbox/ast2700-mailbox.c line 91

Quoted 2 lines
drivers/mailbox/ast2700-mailbox.c new file +2 -0
+__func__, idx);
+               return -EBUSY;

-ENODEV? I wouldn't say it's busy here :)

drivers/mailbox/ast2700-mailbox.c

Quoted 4 lines
drivers/mailbox/ast2700-mailbox.c new file +4 -0
+       }
+
+       if (!(ast2700_mbox_tx_done(mb, idx))) {
+               dev_warn(mb->mbox.dev, "%s: Ch-%d last data has

not

Quoted 8 lines
drivers/mailbox/ast2700-mailbox.c new file +8 -0
+finished\n", __func__, idx);
+               return -EBUSY;
+       }
+
+       /* Write the message data */
+       for (data_reg = mb->tx_regs + IPCR_DATA + mb->msg_size * idx,
+            word_data = (u32 *)data,
+            num_words = (mb->msg_size / sizeof(u32));

drivers/mailbox/ast2700-mailbox.c line 117

Quoted 10 lines
drivers/mailbox/ast2700-mailbox.c new file +10 -0
+            num_words;
+            num_words--, data_reg += sizeof(u32), word_data++)
+               writel(*word_data, data_reg);
+
+       writel(BIT(idx), mb->tx_regs + IPCR_TX_TRIG);
+       dev_dbg(mb->mbox.dev, "%s: Ch-%d sent\n", __func__, idx);
+
+       return 0;
+}
+

*snip*

Quoted 7 lines
drivers/mailbox/ast2700-mailbox.c new file +7 -0
+
+static int ast2700_mbox_probe(struct platform_device *pdev) {
+       struct ast2700_mbox *mb;
+       const struct ast2700_mbox_data *dev_data;
+       struct device *dev = &pdev->dev;
+       int irq, ret;
+

drivers/mailbox/ast2700-mailbox.c

Quoted 10 lines
drivers/mailbox/ast2700-mailbox.c new file +10 -0
+       if (!pdev->dev.of_node)
+               return -ENODEV;
+
+       dev_data = device_get_match_data(&pdev->dev);
+
+       mb = devm_kzalloc(dev, sizeof(*mb), GFP_KERNEL);
+       if (!mb)
+               return -ENOMEM;
+
+       mb->mbox.chans = devm_kcalloc(&pdev->dev,

dev_data->num_chans,

Quoted 1 line

+                                     sizeof(*mb->mbox.c hans),

drivers/mailbox/ast2700-mailbox.c

Quoted 10 lines
drivers/mailbox/ast2700-mailbox.c new file +9 -0
+GFP_KERNEL);
+       if (!mb->mbox.chans)
+               return -ENOMEM;
+
+       /* con_priv of each channel is used to store the message
+received */
+       for (int i = 0; i < dev_data->num_chans; i++) {
+               mb->mbox.chans[i].con_priv = devm_kcalloc(dev,
+dev_data->msg_size,

+
       sizeof(u8),

Quoted 10 lines

drivers/mailbox/ast2700-mailbox.c line 190

Quoted 8 lines
drivers/mailbox/ast2700-mailbox.c new file +8 -0
+GFP_KERNEL);
+               if (!mb->mbox.chans[i].con_priv)
+                       return -ENOMEM;
+       }
+
+       platform_set_drvdata(pdev, mb);
+
+       mb->tx_regs = devm_platform_ioremap_resource(pdev, 0);

See the thought about reg-names on the binding.

Agree.

Quoted 2 lines

Andrew

Regards
Jammy