Skip to contentSkip to conversation

mailbox: Add mhuv2 mailbox controller's support

PATCH In review Viresh Kumar 2 participants 6 messages Nov 17, 2020 – Dec 9, 2020

Subsystems (3)
lore
Share & tools
lore

Viresh Kumar

author maintainer
#0 lore raw

v5 cover mailbox: Add mhuv2 mailbox controller's support

Hi Jassi,

Here is the updated version based on your suggestions.

I feel bad that I haven't implemented the single-word protocol as a special case of multi-word one in the earlier attempt. Perhaps I was too consumed by the terminology used by the ARM folks in the previous version of the driver and the reference manual of the controller :)

V1/V4->V5

- The binding patch already had 4 versions, while the driver had only 1. To send everything together, I had to bump the entire thing to V5.

- Removed single-word and multi-word protocols and introduced data-transfer protocol which works with 1 or more windows.

- Moved register names to small case.

Rob, I have kept your Reviewed-by tag as is, please let me know if you would like to revoke it.

--
Viresh

Viresh Kumar (2):
dt-bindings: mailbox : arm,mhuv2: Add bindings
mailbox: arm_mhuv2: Add driver

 .../bindings/mailbox/arm,mhuv2.yaml           |  209 +++
 MAINTAINERS                                   |    9 +
 drivers/mailbox/Kconfig                       |    7 +
 drivers/mailbox/Makefile                      |    2 +
 drivers/mailbox/arm_mhuv2.c                   | 1136 +++++++++++++++++
 include/linux/mailbox/arm_mhuv2_message.h     |   20 +
 6 files changed, 1383 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mailbox/arm,mhuv2.yaml
 create mode 100644 drivers/mailbox/arm_mhuv2.c
 create mode 100644 include/linux/mailbox/arm_mhuv2_message.h
Signature · 1 line
2.25.0.rc1.19.g042ed3e048af
author maintainer
#1 lore raw

PATCH v5 1/2 dt-bindings: mailbox : arm,mhuv2: Add bindings

This patch adds device tree binding for ARM Message Handling Unit (MHU) controller version 2.

Based on earlier work by Morten Borup Petersen.

---
 .../bindings/mailbox/arm,mhuv2.yaml           | 209 ++++++++++++++++++
 1 file changed, 209 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mailbox/arm,mhuv2.yaml
Documentation/devicetree/bindings/mailbox/arm,mhuv2.yaml new file +209 -0
new file mode 100644
index 000000000000..6608545ea66f
@@ -0,0 +1,209 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mailbox/arm,mhuv2.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: ARM MHUv2 Mailbox Controller
+
+maintainers:
+  - Tushar Khandelwal <[email protected]>
+  - Viresh Kumar <[email protected]>
+
+description: |
+  The Arm Message Handling Unit (MHU) Version 2 is a mailbox controller that has
+  between 1 and 124 channel windows (each 32-bit wide) to provide unidirectional
+  communication with remote processor(s), where the number of channel windows
+  are implementation dependent.
+
+  Given the unidirectional nature of the controller, an MHUv2 mailbox may only
+  be written to or read from. If a pair of MHU controllers is implemented
+  between two processing elements to provide bidirectional communication, these
+  must be specified as two separate mailboxes.
+
+  If the interrupts property is present in device tree node, then its treated as
+  a "receiver" mailbox, otherwise a "sender".
+
+  An MHU controller must be specified along with the supported transport
+  protocols. The transport protocols determine the method of data transmission
+  as well as the number of provided mailbox channels.
+
+  Following are the possible transport protocols.
+
+  - Data-transfer: Each transfer is made of one or more words, using one or more
+    channel windows.
+
+  - Doorbell: Each transfer is made up of single bit flag, using any one of the
+    bits in a channel window. A channel window can support up to 32 doorbells
+    and the entire window shall be used in doorbell protocol.  Optionally, data
+    may be transmitted through a shared memory region, wherein the MHU is used
+    strictly as an interrupt generation mechanism but that is out of the scope
+    of these bindings.
+
+# We need a select here so we don't match all nodes with 'arm,primecell'
+select:
+  properties:
+    compatible:
+      contains:
+        enum:
+          - arm,mhuv2-tx
+          - arm,mhuv2-rx
+  required:
+    - compatible
+
+properties:
+  compatible:
+    oneOf:
+      - description: Sender mode
+        items:
+          - const: arm,mhuv2-tx
+          - const: arm,primecell
+
+      - description: Receiver-mode
+        items:
+          - const: arm,mhuv2-rx
+          - const: arm,primecell
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    description: |
+      The MHUv2 controller always implements an interrupt in the "receiver"
+      mode, while the interrupt in the "sender" mode was not available in the
+      version MHUv2.0, but the later versions do have it.
+    maxItems: 1
+
+  clocks:
+    maxItems: 1
+
+  clock-names:
+    maxItems: 1
+
+  arm,mhuv2-protocols:
+    $ref: /schemas/types.yaml#/definitions/uint32-matrix
+    description: |
+      The MHUv2 controller may contain up to 124 channel windows (each 32-bit
+      wide). The hardware and the DT bindings allows any combination of those to
+      be used for various transport protocols.
+
+      This property allows a platform to describe how these channel windows are
+      used in various transport protocols. The entries in this property shall be
+      present as an array of tuples, where each tuple describes details about
+      one of the transport protocol being implemented over some channel
+      window(s).
+
+      The first field of a tuple signifies the transfer protocol, 0 is reserved
+      for doorbell protocol, and 1 is reserved for data-transfer protocol.
+      Using any other value in the first field of a tuple makes it invalid.
+
+      The second field of a tuple signifies the number of channel windows where
+      the protocol would be used and should be set to a non zero value. For
+      doorbell protocol this field signifies the number of 32-bit channel
+      windows that implement the doorbell protocol. For data-transfer protocol,
+      this field signifies the number of 32-bit channel windows that implement
+      the data-transfer protocol.
+
+      The total number of channel windows specified here shouldn't be more than
+      the ones implemented by the platform, though one can specify lesser number
+      of windows here than what the platform implements.
+
+      mhu: mailbox@2b1f0000 {
+          ...
+
+          arm,mhuv2-protocols = <0 2>, <1 1>, <1 5>, <1 7>;
+      }
+
+      The above example defines the protocols of an ARM MHUv2 mailbox
+      controller, where a total of 15 channel windows are used. The first two
+      windows are used in doorbell protocol (64 doorbells), followed by 1, 5 and
+      7 windows (separately) used in data-transfer protocol.
+
+    minItems: 1
+    maxItems: 124
+    items:
+      items:
+        - enum: [ 0, 1 ]
+        - minimum: 0
+          maximum: 124
+
+
+  '#mbox-cells':
+    description: |
+      It is always set to 2. The first argument in the consumers 'mboxes'
+      property represents the channel window group, which may be used in
+      doorbell, or data-transfer protocol, and the second argument (only
+      relevant in doorbell protocol, should be 0 otherwise) represents the
+      doorbell number within the 32 bit wide channel window.
+
+      From the example given above for arm,mhuv2-protocols, here is how a client
+      node can reference them.
+
+      mboxes = <&mhu 0 5>; // Channel Window Group 0, doorbell 5.
+      mboxes = <&mhu 1 7>; // Channel Window Group 1, doorbell 7.
+      mboxes = <&mhu 2 0>; // Channel Window Group 2, data transfer protocol with 1 window.
+      mboxes = <&mhu 3 0>; // Channel Window Group 3, data transfer protocol with 5 windows.
+      mboxes = <&mhu 4 0>; // Channel Window Group 4, data transfer protocol with 7 windows.
+
+    const: 2
+
+if:
+  # Interrupt is compulsory for receiver
+  properties:
+    compatible:
+      contains:
+        const: arm,mhuv2-rx
+then:
+  required:
+    - interrupts
+
+required:
+  - compatible
+  - reg
+  - '#mbox-cells'
+  - arm,mhuv2-protocols
+
+additionalProperties: false
+
+examples:
+  # Multiple transport protocols implemented by the mailbox controllers
+  - |
+    soc {
+        #address-cells = <2>;
+        #size-cells = <2>;
+
+        mhu_tx: mailbox@2b1f0000 {
+            #mbox-cells = <2>;
+            compatible = "arm,mhuv2-tx", "arm,primecell";
+            reg = <0 0x2b1f0000 0 0x1000>;
+            clocks = <&clock 0>;
+            clock-names = "apb_pclk";
+            interrupts = <0 45 4>;
+            arm,mhuv2-protocols = <1 5>, <1 2>, <1 5>, <1 7>, <0 2>;
+        };
+
+        mhu_rx: mailbox@2b1f1000 {
+            #mbox-cells = <2>;
+            compatible = "arm,mhuv2-rx", "arm,primecell";
+            reg = <0 0x2b1f1000 0 0x1000>;
+            clocks = <&clock 0>;
+            clock-names = "apb_pclk";
+            interrupts = <0 46 4>;
+            arm,mhuv2-protocols = <1 1>, <1 7>, <0 2>;
+        };
+
+        mhu_client: scb@2e000000 {
+            compatible = "fujitsu,mb86s70-scb-1.0";
+            reg = <0 0x2e000000 0 0x4000>;
+
+            mboxes =
+                     //data-transfer protocol with 5 windows, mhu-tx
+                     <&mhu_tx 2 0>,
+                     //data-transfer protocol with 7 windows, mhu-tx
+                     <&mhu_tx 3 0>,
+                     //doorbell protocol channel 4, doorbell 27, mhu-tx
+                     <&mhu_tx 4 27>,
+                     //data-transfer protocol with 1 window, mhu-rx
+                     <&mhu_rx 0 0>;
+        };
+    };
Signature · 1 line
2.25.0.rc1.19.g042ed3e048af
author maintainer
#2 lore raw

PATCH v5 2/2 mailbox: arm_mhuv2: Add driver

In reply to Viresh Kumar

This adds driver for the ARM MHUv2 (Message Handling Unit) mailbox controller.

This is based on the accepted DT bindings of the controller and supports combination of both transport protocols, i.e. doorbell and data-transfer.

Transmitting and receiving data through the mailbox framework is done through struct arm_mhuv2_mbox_msg.

Based on the initial work done by Morten Borup Petersen from ARM.

---
 MAINTAINERS                               |    9 +
 drivers/mailbox/Kconfig                   |    7 +
 drivers/mailbox/Makefile                  |    2 +
 drivers/mailbox/arm_mhuv2.c               | 1136 +++++++++++++++++++++
 include/linux/mailbox/arm_mhuv2_message.h |   20 +
 5 files changed, 1174 insertions(+)
 create mode 100644 drivers/mailbox/arm_mhuv2.c
 create mode 100644 include/linux/mailbox/arm_mhuv2_message.h
MAINTAINERS +9 -0
index e73636b75f29..87f5ba48417e 100644
@@ -10450,6 +10450,15 @@ F:	drivers/mailbox/
 F:	include/linux/mailbox_client.h
 F:	include/linux/mailbox_controller.h
 
+MAILBOX ARM MHUv2
+M:	Viresh Kumar <[email protected]>
+M:	Tushar Khandelwal <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/mailbox/arm_mhuv2.c
+F:	include/linux/mailbox/arm_mhuv2_message.h
+F:	Documentation/devicetree/bindings/mailbox/arm,mhuv2.yaml
+
 MAN-PAGES: MANUAL PAGES FOR LINUX -- Sections 2, 3, 4, 5, and 7
 M:	Michael Kerrisk <[email protected]>
 L:	[email protected]
drivers/mailbox/Kconfig +7 -0
index 05b1009e2820..3c0ea96a0a8b 100644
@@ -16,6 +16,13 @@ config ARM_MHU
 	  The controller has 3 mailbox channels, the last of which can be
 	  used in Secure mode only.
 
+config ARM_MHU_V2
+	tristate "ARM MHUv2 Mailbox"
+	depends on ARM_AMBA
+	help
+	  Say Y here if you want to build the ARM MHUv2 controller driver,
+	  which provides unidirectional mailboxes between processing elements.
+
 config IMX_MBOX
 	tristate "i.MX Mailbox"
 	depends on ARCH_MXC || COMPILE_TEST
drivers/mailbox/Makefile +2 -0
index 2e06e02b2e03..7194fa92c787 100644
@@ -7,6 +7,8 @@ obj-$(CONFIG_MAILBOX_TEST)	+= mailbox-test.o
 
 obj-$(CONFIG_ARM_MHU)	+= arm_mhu.o arm_mhu_db.o
 
+obj-$(CONFIG_ARM_MHU_V2)	+= arm_mhuv2.o
+
 obj-$(CONFIG_IMX_MBOX)	+= imx-mailbox.o
 
 obj-$(CONFIG_ARMADA_37XX_RWTM_MBOX)	+= armada-37xx-rwtm-mailbox.o
drivers/mailbox/arm_mhuv2.c new file +1136 -0

1,136 lines not on this page · raw message

include/linux/mailbox/arm_mhuv2_message.h new file +20 -0
new file mode 100644
index 000000000000..821b9d96daa4
@@ -0,0 +1,20 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * ARM MHUv2 Mailbox Message
+ *
+ * Copyright (C) 2020 Arm Ltd.
+ * Copyright (C) 2020 Linaro Ltd.
+ */
+
+#ifndef _LINUX_ARM_MHUV2_MESSAGE_H_
+#define _LINUX_ARM_MHUV2_MESSAGE_H_
+
+#include <linux/types.h>
+
+/* Data structure for data-transfer protocol */
+struct arm_mhuv2_mbox_msg {
+	void *data;
+	size_t len;
+};
+
+#endif /* _LINUX_ARM_MHUV2_MESSAGE_H_ */
Signature · 1 line
2.25.0.rc1.19.g042ed3e048af
maintainer
#3 lore raw

Re: [PATCH V5 2/2] mailbox: arm_mhuv2: Add driver

Quoted 20 lines · Viresh Kumar
drivers/mailbox/arm_mhuv2.c new file +19 -0
+
+/**
+ * struct mhuv2 - MHUv2 mailbox controller data
+ *
+ * @mbox:      Mailbox controller belonging to the MHU frame.
+ * @send/recv: Base address of the register mapping region.
+ * @frame:     Frame type: RECEIVER_FRAME or SENDER_FRAME.
+ * @irq:       Interrupt.
+ * @windows:   Channel windows implemented by the platform.
+ * @minor:     Minor version of the controller.
+ * @length:    Length of the protocols array in bytes.
+ * @protocols: Raw protocol information, derived from device tree.
+ * @doorbell_pending_lock: spinlock required for correct operation of Tx
+ *             interrupt for doorbells.
+ */
+struct mhuv2 {
+       struct mbox_controller mbox;
+       union {
+               struct mhu2_send_frame_reg __iomem *send;

drivers/mailbox/arm_mhuv2.c line 186

Quoted 10 lines
drivers/mailbox/arm_mhuv2.c new file +10 -0
+               struct mhu2_recv_frame_reg __iomem *recv;
+       };
+       enum mhuv2_frame frame;
+       unsigned int irq;
+       unsigned int windows;
+       unsigned int minor;
+       unsigned int length;
+       u32 *protocols;
+
+       spinlock_t doorbell_pending_lock;

Can you please explain the need of this lock? Some usecase?
It should be unnecessary if the controller natively supports doorbell mode.

thanks.

author maintainer
#4 lore raw

Re: [PATCH V5 2/2] mailbox: arm_mhuv2: Add driver

Quoted 26 lines · Jassi Brar
Quoted 24 lines · Viresh Kumar
drivers/mailbox/arm_mhuv2.c new file +24 -0
+
+/**
+ * struct mhuv2 - MHUv2 mailbox controller data
+ *
+ * @mbox:      Mailbox controller belonging to the MHU frame.
+ * @send/recv: Base address of the register mapping region.
+ * @frame:     Frame type: RECEIVER_FRAME or SENDER_FRAME.
+ * @irq:       Interrupt.
+ * @windows:   Channel windows implemented by the platform.
+ * @minor:     Minor version of the controller.
+ * @length:    Length of the protocols array in bytes.
+ * @protocols: Raw protocol information, derived from device tree.
+ * @doorbell_pending_lock: spinlock required for correct operation of Tx
+ *             interrupt for doorbells.
+ */
+struct mhuv2 {
+       struct mbox_controller mbox;
+       union {
+               struct mhu2_send_frame_reg __iomem *send;
+               struct mhu2_recv_frame_reg __iomem *recv;
+       };
+       enum mhuv2_frame frame;
+       unsigned int irq;
+       unsigned int windows;
Quoted 8 lines

drivers/mailbox/arm_mhuv2.c line 186

Quoted 6 lines
drivers/mailbox/arm_mhuv2.c new file +5 -0
+       unsigned int minor;
+       unsigned int length;
+       u32 *protocols;
+
+       spinlock_t doorbell_pending_lock;

Can you please explain the need of this lock? Some usecase?
It should be unnecessary if the controller natively supports doorbell mode.

Yes, the controller does have native doorbell support, it provides bit wise access of the registers and interrupt gets generated for every bit of the register.

This lock is needed only in the case where an interrupt is provided in the tx case as well (since minor version 1). This is how hardware works in this case:

- Sender (Linux) writes to a bit of 'stat_set' register to do a doorbell operation.

- The receiver receives an interrupt for it and sets the same bit in 'stat_clear' register in order to clear the interrupt.

- With this the sender gets an interrupt and needs to check which bit of 'stat' register went from 1 to 0 to know which doorbell's operation got finished. The sender clears the interrupt for the entire window by writing 1 to int_clr register of the corresponding window.

Now another doorbell transfer can start right after we read the 'stat' register in the tx interrupt handler and we will see that a bit went from 1 to 0 and think that the transfer has completed, while it may not have as the bit may still be 1. And so we need to make sure to not start a new transfer for the same window while interrupt handler is processing the doorbell tx interrupt.

Another way of doing this lockless would be to not use the tx interrupt and rather poll the bit, but that would be less efficient.

Signature · 1 line
viresh
author maintainer
#5 lore raw
In reply to Viresh Kumar
Quoted 10 lines · Viresh Kumar

Hi Jassi,

Here is the updated version based on your suggestions.

I feel bad that I haven't implemented the single-word protocol as a special case of multi-word one in the earlier attempt. Perhaps I was too consumed by the terminology used by the ARM folks in the previous version of the driver and the reference manual of the controller :)

V1/V4->V5

Hi Jassi,

I still don't see this here, hope it is going to get merged in the coming merge window.

https://git.linaro.org/landing-teams/working/fujitsu/integration.git/log/?h=mailbox-for-next

Please let me know if you have any other concerns. Thanks.

Signature · 1 line
viresh