Skip to contentSkip to conversation

mailbox: arm_mhu: Add ARM MHU doorbell controller driver

PATCH Superseded Sudeep Holla 3 participants 11 messages Sep 28, 2020 – Oct 8, 2020

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover mailbox: arm_mhu: Add ARM MHU doorbell controller driver

Hi,

These series adds ARM MHU doorbell controller driver based on the discussion[1]. The DT patches are just repost from Viresh's last posting[2]

Regards,
Sudeep

[1] https://lore.kernel.org/lkml/20200909044618.deyx37pzocxiga7u@vireshk-i7
[2] https://lore.kernel.org/r/3874de094d193a08624a00a35067a3237e0b42b1.1600249102.git.viresh.kumar@linaro.org

Sudeep Holla (3):
dt-bindings: mailbox: add doorbell support to ARM MHU
mailbox: arm_mhu: Match only if compatible is "arm,mhu"
mailbox: arm_mhu: Add ARM MHU doorbell driver

Viresh Kumar (1):
dt-bindings: mailbox : arm,mhu: Convert to Json-schema

 .../devicetree/bindings/mailbox/arm,mhu.yaml  | 135 +++++++
 .../devicetree/bindings/mailbox/arm-mhu.txt   |  43 ---
 drivers/mailbox/Makefile                      |   2 +-
 drivers/mailbox/arm_mhu.c                     |   3 +
 drivers/mailbox/arm_mhu_db.c                  | 359 ++++++++++++++++++
 5 files changed, 498 insertions(+), 44 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/mailbox/arm,mhu.yaml
 delete mode 100644 Documentation/devicetree/bindings/mailbox/arm-mhu.txt
 create mode 100644 drivers/mailbox/arm_mhu_db.c
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/4 dt-bindings: mailbox : arm,mhu: Convert to Json-schema

From: Viresh Kumar <[email protected]>

Convert the DT binding over to Json-schema.

---
 .../devicetree/bindings/mailbox/arm,mhu.yaml  | 87 +++++++++++++++++++
 .../devicetree/bindings/mailbox/arm-mhu.txt   | 43 ---------
 2 files changed, 87 insertions(+), 43 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/mailbox/arm,mhu.yaml
 delete mode 100644 Documentation/devicetree/bindings/mailbox/arm-mhu.txt
Documentation/devicetree/bindings/mailbox/arm,mhu.yaml new file +87 -0
new file mode 100644
index 000000000000..2c8df7979c22
@@ -0,0 +1,87 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mailbox/arm,mhu.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: ARM MHU Mailbox Controller
+
+maintainers:
+  - Jassi Brar <[email protected]>
+
+description: |
+  The ARM's Message-Handling-Unit (MHU) is a mailbox controller that has 3
+  independent channels/links to communicate with remote processor(s).  MHU links
+  are hardwired on a platform. A link raises interrupt for any received data.
+  However, there is no specified way of knowing if the sent data has been read
+  by the remote. This driver assumes the sender polls STAT register and the
+  remote clears it after having read the data.  The last channel is specified to
+  be a 'Secure' resource, hence can't be used by Linux running NS.
+
+# We need a select here so we don't match all nodes with 'arm,primecell'
+select:
+  properties:
+    compatible:
+      contains:
+        const: arm,mhu
+  required:
+    - compatible
+
+properties:
+  compatible:
+    items:
+      - const: arm,mhu
+      - const: arm,primecell
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    items:
+      - description: low-priority non-secure
+      - description: high-priority non-secure
+      - description: Secure
+    maxItems: 3
+
+  clocks:
+    maxItems: 1
+
+  clock-names:
+    items:
+      - const: apb_pclk
+
+  '#mbox-cells':
+    description: Index of the channel.
+    const: 1
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - '#mbox-cells'
+
+additionalProperties: false
+
+examples:
+  - |
+    soc {
+        #address-cells = <2>;
+        #size-cells = <2>;
+
+        mhuA: mailbox@2b1f0000 {
+            #mbox-cells = <1>;
+            compatible = "arm,mhu", "arm,primecell";
+            reg = <0 0x2b1f0000 0 0x1000>;
+            interrupts = <0 36 4>, /* LP-NonSecure */
+                         <0 35 4>, /* HP-NonSecure */
+                         <0 37 4>; /* Secure */
+            clocks = <&clock 0 2 1>;
+            clock-names = "apb_pclk";
+        };
+
+        mhu_client_scb: scb@2e000000 {
+            compatible = "fujitsu,mb86s70-scb-1.0";
+            reg = <0 0x2e000000 0 0x4000>;
+            mboxes = <&mhuA 1>; /* HP-NonSecure */
+        };
+    };
Documentation/devicetree/bindings/mailbox/arm-mhu.txt deleted +0 -43

43 lines not on this page · raw message

Signature · 1 line
2.17.1
#2 lore raw

PATCH 2/4 dt-bindings: mailbox: add doorbell support to ARM MHU

In reply to Sudeep Holla

The ARM MHU's reference manual states following:

"The MHU drives the signal using a 32-bit register, with all 32 bits logically ORed together. The MHU provides a set of registers to enable software to set, clear, and check the status of each of the bits of this register independently. The use of 32 bits for each interrupt line enables software to provide more information about the source of the interrupt. For example, each bit of the register can be associated with a type of event that can contribute to raising the interrupt."

This patch thus extends the MHU controller's DT binding to add support for doorbell mode.

Though the same MHU hardware controller is used in the two modes, A new compatible string is added here to represent the combination of the MHU hardware and the firmware sitting on the other side (which expects each bit to represent a different signal now).

---
 .../devicetree/bindings/mailbox/arm,mhu.yaml  | 60 +++++++++++++++++--
 1 file changed, 54 insertions(+), 6 deletions(-)
Documentation/devicetree/bindings/mailbox/arm,mhu.yaml +54 -6
index 2c8df7979c22..d43791a2dde7 100644
@@ -18,20 +18,40 @@ description: |
   remote clears it after having read the data.  The last channel is specified to
   be a 'Secure' resource, hence can't be used by Linux running NS.
 
+  The MHU hardware also allows operations in doorbell mode. The MHU drives the
+  interrupt signal using a 32-bit register, with all 32-bits logically ORed
+  together. It provides a set of registers to enable software to set, clear and
+  check the status of each of the bits of this register independently. The use
+  of 32 bits per interrupt line enables software to provide more information
+  about the source of the interrupt. For example, each bit of the register can
+  be associated with a type of event that can contribute to raising the
+  interrupt. Each of the 32-bits can be used as "doorbell" to alert the remote
+  processor.
+
 # We need a select here so we don't match all nodes with 'arm,primecell'
 select:
   properties:
     compatible:
       contains:
-        const: arm,mhu
+        enum:
+          - arm,mhu
+          - arm,mhu-doorbell
   required:
     - compatible
 
 properties:
   compatible:
-    items:
-      - const: arm,mhu
-      - const: arm,primecell
+    oneOf:
+      - description: Data transfer mode
+        items:
+          - const: arm,mhu
+          - const: arm,primecell
+
+      - description: Doorbell mode
+        items:
+          - const: arm,mhu-doorbell
+          - const: arm,primecell
+
 
   reg:
     maxItems: 1
@@ -51,8 +71,11 @@ description: |
       - const: apb_pclk
 
   '#mbox-cells':
-    description: Index of the channel.
-    const: 1
+    description: |
+      Set to 1 in data transfer mode and represents index of the channel.
+      Set to 2 in doorbell mode and represents index of the channel and doorbell
+      number.
+    enum: [ 1, 2 ]
 
 required:
   - compatible
@@ -63,6 +86,7 @@ description: |
 additionalProperties: false
 
 examples:
+  # Data transfer mode.
   - |
     soc {
         #address-cells = <2>;
@@ -85,3 +109,27 @@ additionalProperties: false
             mboxes = <&mhuA 1>; /* HP-NonSecure */
         };
     };
+
+  # Doorbell mode.
+  - |
+    soc {
+        #address-cells = <2>;
+        #size-cells = <2>;
+
+        mhuB: mailbox@2b2f0000 {
+            #mbox-cells = <2>;
+            compatible = "arm,mhu-doorbell", "arm,primecell";
+            reg = <0 0x2b2f0000 0 0x1000>;
+            interrupts = <0 36 4>, /* LP-NonSecure */
+                         <0 35 4>, /* HP-NonSecure */
+                         <0 37 4>; /* Secure */
+            clocks = <&clock 0 2 1>;
+            clock-names = "apb_pclk";
+        };
+
+        mhu_client_scpi: scpi@2f000000 {
+            compatible = "arm,scpi";
+            reg = <0 0x2f000000 0 0x200>;
+            mboxes = <&mhuB 1 4>; /* HP-NonSecure, 5th doorbell */
+        };
+    };
Signature · 1 line
2.17.1
#3 lore raw

PATCH 3/4 mailbox: arm_mhu: Match only if compatible is "arm,mhu"

In reply to Sudeep Holla

Since we will be soon adding a separate driver based on this ARM MHU driver to support doorbell mode, let us add explicit check to match the default compatible for this driver. This is needed as the probe and match reuses the AMBA device ids currently and don't have any explicit compatible check.

---
 drivers/mailbox/arm_mhu.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/mailbox/arm_mhu.c +3 -0
index 9da236552bd7..b7fbf276eb62 100644
@@ -113,6 +113,9 @@ static int mhu_probe(struct amba_device *adev, const struct amba_id *id)
 	struct device *dev = &adev->dev;
 	int mhu_reg[MHU_CHANS] = {MHU_LP_OFFSET, MHU_HP_OFFSET, MHU_SEC_OFFSET};
 
+	if (!of_device_is_compatible(dev->of_node, "arm,mhu"))
+		return -ENODEV;
+
 	/* Allocate memory for device */
 	mhu = devm_kzalloc(dev, sizeof(*mhu), GFP_KERNEL);
 	if (!mhu)
Signature · 1 line
2.17.1
#4 lore raw

PATCH 4/4 mailbox: arm_mhu: Add ARM MHU doorbell driver

In reply to Sudeep Holla

The MHU drives the signal using a 32-bit register, with all 32 bits logically ORed together. The MHU provides a set of registers to enable software to set, clear, and check the status of each of the bits of this register independently. The use of 32 bits for each interrupt line enables software to provide more information about the source of the interrupt. For example, each bit of the register can be associated with a type of event that can contribute to raising the interrupt.

This patch adds a separate the MHU controller driver for doorbel mode of operation using the extended DT binding to add support the same.

---
 drivers/mailbox/Makefile     |   2 +-
 drivers/mailbox/arm_mhu_db.c | 359 +++++++++++++++++++++++++++++++++++
 2 files changed, 360 insertions(+), 1 deletion(-)
 create mode 100644 drivers/mailbox/arm_mhu_db.c
drivers/mailbox/Makefile +1 -1
index 60d224b723a1..2e06e02b2e03 100644
@@ -5,7 +5,7 @@ obj-$(CONFIG_MAILBOX)		+= mailbox.o
 
 obj-$(CONFIG_MAILBOX_TEST)	+= mailbox-test.o
 
-obj-$(CONFIG_ARM_MHU)	+= arm_mhu.o
+obj-$(CONFIG_ARM_MHU)	+= arm_mhu.o arm_mhu_db.o
 
 obj-$(CONFIG_IMX_MBOX)	+= imx-mailbox.o
 
drivers/mailbox/arm_mhu_db.c new file +359 -0

359 lines not on this page · raw message

Signature · 1 line
2.17.1
maintainer
#5 lore raw

Re: [PATCH 4/4] mailbox: arm_mhu: Add ARM MHU doorbell driver

Quoted 10 lines · Sudeep Holla
drivers/mailbox/arm_mhu_db.c new file +9 -0
+
+static void mhu_db_shutdown(struct mbox_chan *chan)
+{
+       struct mhu_db_channel *chan_info = chan->con_priv;
+       struct mbox_controller *mbox = &chan_info->mhu->mbox;
+       int i;
+
+       for (i = 0; i < mbox->num_chans; i++)
+               if (chan == &mbox->chans[i])

drivers/mailbox/arm_mhu_db.c line 184

Quoted 10 lines
drivers/mailbox/arm_mhu_db.c new file +10 -0
+                       break;
+
+       if (mbox->num_chans == i) {
+               dev_warn(mbox->dev, "Request to free non-existent channel\n");
+               return;
+       }
+
+       /* Reset channel */
+       mhu_db_mbox_clear_irq(chan);
+       chan->con_priv = NULL;

request->free->request will fail because of this NULL assignment. Maybe add a 'taken' flag in mhu_db_channel, which should also be checked before calling mbox_chan_received_data because the data may arrive for a now relinquished channel.

Quoted 21 lines
drivers/mailbox/arm_mhu_db.c new file +21 -0
+
+static struct mbox_chan *mhu_db_mbox_xlate(struct mbox_controller *mbox,
+                                          const struct of_phandle_args *spec)
+{
+       struct arm_mhu *mhu = dev_get_drvdata(mbox->dev);
+       struct mhu_db_channel *chan_info;
+       struct mbox_chan *chan = NULL;
+       unsigned int pchan = spec->args[0];
+       unsigned int doorbell = spec->args[1];
+       int i;
+
+       /* Bounds checking */
+       if (pchan >= MHU_CHANS || doorbell >= MHU_NUM_DOORBELLS) {
+               dev_err(mbox->dev,
+                       "Invalid channel requested pchan: %d doorbell: %d\n",
+                       pchan, doorbell);
+               return ERR_PTR(-EINVAL);
+       }
+
+       for (i = 0; i < mbox->num_chans; i++) {
+               chan_info = mbox->chans[i].con_priv;

drivers/mailbox/arm_mhu_db.c line 216

Quoted 10 lines
drivers/mailbox/arm_mhu_db.c new file +10 -0
+
+               /* Is requested channel free? */
+               if (chan_info &&
+                   mbox->dev == chan_info->mhu->dev &&
+                   pchan == chan_info->pchan &&
+                   doorbell == chan_info->doorbell) {
+                       dev_err(mbox->dev, "Channel in use\n");
+                       return ERR_PTR(-EBUSY);
+               }
+

You may want to reuse mhu_db_mbox_to_channel.

#6 lore raw

Re: [PATCH 4/4] mailbox: arm_mhu: Add ARM MHU doorbell driver

Quoted 18 lines · Jassi Brar
Quoted 16 lines · Sudeep Holla
drivers/mailbox/arm_mhu_db.c new file +16 -0
+
+static void mhu_db_shutdown(struct mbox_chan *chan)
+{
+       struct mhu_db_channel *chan_info = chan->con_priv;
+       struct mbox_controller *mbox = &chan_info->mhu->mbox;
+       int i;
+
+       for (i = 0; i < mbox->num_chans; i++)
+               if (chan == &mbox->chans[i])
+                       break;
+
+       if (mbox->num_chans == i) {
+               dev_warn(mbox->dev, "Request to free non-existent channel\n");
+               return;
+       }
+
Quoted 9 lines

drivers/mailbox/arm_mhu_db.c line 184

Quoted 4 lines
drivers/mailbox/arm_mhu_db.c new file +3 -0
+       /* Reset channel */
+       mhu_db_mbox_clear_irq(chan);
+       chan->con_priv = NULL;

request->free->request will fail because of this NULL assignment. Maybe add a 'taken' flag in mhu_db_channel, which should also be checked before calling mbox_chan_received_data because the data may arrive for a now relinquished channel.

Good point, but the new 'taken' flag will have the same race as con_priv. We need a lock here and can we use chan->lock or do you prefer this driver maintains it own for this purpose.

mbox_request_channel releases the lock before calling startup and mbox_free_channel acquires the after shutdown returns, so technically we can reuse the same lock.

Quoted 24 lines
Quoted 24 lines
drivers/mailbox/arm_mhu_db.c new file +24 -0
+
+static struct mbox_chan *mhu_db_mbox_xlate(struct mbox_controller *mbox,
+                                          const struct of_phandle_args *spec)
+{
+       struct arm_mhu *mhu = dev_get_drvdata(mbox->dev);
+       struct mhu_db_channel *chan_info;
+       struct mbox_chan *chan = NULL;
+       unsigned int pchan = spec->args[0];
+       unsigned int doorbell = spec->args[1];
+       int i;
+
+       /* Bounds checking */
+       if (pchan >= MHU_CHANS || doorbell >= MHU_NUM_DOORBELLS) {
+               dev_err(mbox->dev,
+                       "Invalid channel requested pchan: %d doorbell: %d\n",
+                       pchan, doorbell);
+               return ERR_PTR(-EINVAL);
+       }
+
+       for (i = 0; i < mbox->num_chans; i++) {
+               chan_info = mbox->chans[i].con_priv;
+
+               /* Is requested channel free? */
+               if (chan_info &&
Quoted 8 lines

drivers/mailbox/arm_mhu_db.c line 216

Quoted 7 lines
drivers/mailbox/arm_mhu_db.c new file +7 -0
+                   mbox->dev == chan_info->mhu->dev &&
+                   pchan == chan_info->pchan &&
+                   doorbell == chan_info->doorbell) {
+                       dev_err(mbox->dev, "Channel in use\n");
+                       return ERR_PTR(-EBUSY);
+               }
+

You may want to reuse mhu_db_mbox_to_channel.

Good point, thanks for pointing that out, will update.

Signature · 2 lines
Regards,
Sudeep
maintainer
#7 lore raw

Re: [PATCH 4/4] mailbox: arm_mhu: Add ARM MHU doorbell driver

Quoted 30 lines · Sudeep Holla
Quoted 18 lines · Jassi Brar
Quoted 16 lines · Sudeep Holla
drivers/mailbox/arm_mhu_db.c new file +16 -0
+
+static void mhu_db_shutdown(struct mbox_chan *chan)
+{
+       struct mhu_db_channel *chan_info = chan->con_priv;
+       struct mbox_controller *mbox = &chan_info->mhu->mbox;
+       int i;
+
+       for (i = 0; i < mbox->num_chans; i++)
+               if (chan == &mbox->chans[i])
+                       break;
+
+       if (mbox->num_chans == i) {
+               dev_warn(mbox->dev, "Request to free non-existent channel\n");
+               return;
+       }
+
Quoted 9 lines

drivers/mailbox/arm_mhu_db.c line 184

Quoted 4 lines
drivers/mailbox/arm_mhu_db.c new file +3 -0
+       /* Reset channel */
+       mhu_db_mbox_clear_irq(chan);
+       chan->con_priv = NULL;

request->free->request will fail because of this NULL assignment. Maybe add a 'taken' flag in mhu_db_channel, which should also be checked before calling mbox_chan_received_data because the data may arrive for a now relinquished channel.

Quoted 4 lines

Good point, but the new 'taken' flag will have the same race as con_priv. We need a lock here and can we use chan->lock or do you prefer this driver maintains it own for this purpose.

I meant the con_priv is allocated in mhu_db_mbox_xlate and simply assigning it NULL leaks memory, if not a crash by some other path. At least free it before.

-j

#8 lore raw

Re: [PATCH 4/4] mailbox: arm_mhu: Add ARM MHU doorbell driver

Quoted 31 lines · Jassi Brar
Quoted 30 lines · Sudeep Holla
Quoted 27 lines · Jassi Brar
Quoted 10 lines · Sudeep Holla
drivers/mailbox/arm_mhu_db.c new file +9 -0
+
+static void mhu_db_shutdown(struct mbox_chan *chan)
+{
+       struct mhu_db_channel *chan_info = chan->con_priv;
+       struct mbox_controller *mbox = &chan_info->mhu->mbox;
+       int i;
+
+       for (i = 0; i < mbox->num_chans; i++)
+               if (chan == &mbox->chans[i])

drivers/mailbox/arm_mhu_db.c line 184

Quoted 10 lines
drivers/mailbox/arm_mhu_db.c new file +10 -0
+                       break;
+
+       if (mbox->num_chans == i) {
+               dev_warn(mbox->dev, "Request to free non-existent channel\n");
+               return;
+       }
+
+       /* Reset channel */
+       mhu_db_mbox_clear_irq(chan);
+       chan->con_priv = NULL;

request->free->request will fail because of this NULL assignment. Maybe add a 'taken' flag in mhu_db_channel, which should also be checked before calling mbox_chan_received_data because the data may arrive for a now relinquished channel.

Quoted 8 lines
Quoted 4 lines

Good point, but the new 'taken' flag will have the same race as con_priv. We need a lock here and can we use chan->lock or do you prefer this driver maintains it own for this purpose.

I meant the con_priv is allocated in mhu_db_mbox_xlate and simply assigning it NULL leaks memory, if not a crash by some other path. At least free it before.

Ah right, sorry got confused. Too much reliance on devm_* apis and I didn't realise it was not in probe but in xlate which is mbox_startup path. Fixed now, will post v2 with both issues addressed.

--
Regards,
Sudeep

#9 lore raw

Re: [PATCH 4/4] mailbox: arm_mhu: Add ARM MHU doorbell driver

In reply to Sudeep Holla
Quoted 8 lines · Sudeep Holla

The MHU drives the signal using a 32-bit register, with all 32 bits logically ORed together. The MHU provides a set of registers to enable software to set, clear, and check the status of each of the bits of this register independently. The use of 32 bits for each interrupt line enables software to provide more information about the source of the interrupt. For example, each bit of the register can be associated with a type of event that can contribute to raising the interrupt.

Quoted 7 lines

This patch adds a separate the MHU controller driver for doorbel mode of operation using the extended DT binding to add support the same.

---
 drivers/mailbox/Makefile     |   2 +-
 drivers/mailbox/arm_mhu_db.c | 359 +++++++++++++++++++++++++++++++++++

Please put an entry in MAINTAINERS as well for this.

Signature · 1 line
viresh
#10 lore raw

Re: [PATCH 4/4] mailbox: arm_mhu: Add ARM MHU doorbell driver

Quoted 12 lines · Viresh Kumar
Quoted 11 lines · Sudeep Holla

The MHU drives the signal using a 32-bit register, with all 32 bits logically ORed together. The MHU provides a set of registers to enable software to set, clear, and check the status of each of the bits of this register independently. The use of 32 bits for each interrupt line enables software to provide more information about the source of the interrupt. For example, each bit of the register can be associated with a type of event that can contribute to raising the interrupt.

This patch adds a separate the MHU controller driver for doorbel mode of operation using the extended DT binding to add support the same.

Quoted 6 lines
Quoted 4 lines
---
 drivers/mailbox/Makefile     |   2 +-
 drivers/mailbox/arm_mhu_db.c | 359 +++++++++++++++++++++++++++++++++++

Please put an entry in MAINTAINERS as well for this.

Sure.

Signature · 2 lines
Regards,
Sudeep