Skip to contentSkip to conversation

Apple Mailbox Controller support

PATCH Superseded Sven Peter 3 participants 7 messages Oct 17, 2021

Subsystems (3)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Sven Peter

author
#0 lore raw

v3 cover Apple Mailbox Controller support

Hi,

This is the second version of my series which adds support for the mailbox controllers found on the Apple M1.

v1: https://lore.kernel.org/lkml/[email protected]/
v2: https://lore.kernel.org/lkml/[email protected]/

Thanks again to Jassi and Mark for the review. I've addressed your comments with the following changes from v2 to v3:

- removed dma barriers since the mbox client will take care of these
- moved the of_device_id table and related code to the bottom of the file
- removed of_xlate
- dropped clock handling from the code and the binding since we now understand that these are actually power domains

Changes from v1 to v2:
- switched to txdone_irq instead of introducing a new mode
- switched to a threaded interrupt handler for receiving messages
- added co-processor examples to the device tree binding
- reformatted the register defines and clarified multiple comments

Best,

Sven

Sven Peter (2):
dt-bindings: mailbox: Add Apple mailbox bindings
mailbox: apple: Add driver for Apple mailboxes

 .../bindings/mailbox/apple,mailbox.yaml       |  79 ++++
 MAINTAINERS                                   |   3 +
 drivers/mailbox/Kconfig                       |  12 +
 drivers/mailbox/Makefile                      |   2 +
 drivers/mailbox/apple-mailbox.c               | 374 ++++++++++++++++++
 include/linux/apple-mailbox.h                 |  18 +
 6 files changed, 488 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml
 create mode 100644 drivers/mailbox/apple-mailbox.c
 create mode 100644 include/linux/apple-mailbox.h
Signature · 1 line
2.25.1
author
#1 lore raw

PATCH v3 1/2 dt-bindings: mailbox: Add Apple mailbox bindings

Apple mailbox controller are found on the M1 and are used for communication with various co-processors.

---
 .../bindings/mailbox/apple,mailbox.yaml       | 79 +++++++++++++++++++
 MAINTAINERS                                   |  1 +
 2 files changed, 80 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml
Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml new file +79 -0
new file mode 100644
index 000000000000..d488a4173072
@@ -0,0 +1,79 @@
+# SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/mailbox/apple,mailbox.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Apple Mailbox Controller
+
+maintainers:
+  - Hector Martin <[email protected]>
+  - Sven Peter <[email protected]>
+
+description:
+  The Apple mailbox consists of two FIFOs used to exchange 64+32 bit
+  messages between the main CPU and a co-processor. Multiple instances
+  of this mailbox can be found on Apple SoCs.
+  One of the two FIFOs is used to send data to a co-processor while the other
+  FIFO is used for the other direction.
+  Various clients implement different IPC protocols based on these simple
+  messages and shared memory buffers.
+
+properties:
+  compatible:
+    oneOf:
+      - description:
+          ASC mailboxes are the most common variant found on the M1 used
+          for example for the display controller, the system management
+          controller and the NVMe coprocessor.
+        items:
+          - const: apple,t8103-asc-mailbox
+
+      - description:
+          M3 mailboxes are an older variant with a slightly different MMIO
+          interface still found on the M1. It is used for the Thunderbolt
+          co-processors.
+        items:
+          - const: apple,t8103-m3-mailbox
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    minItems: 4
+    items:
+      - description: send fifo is empty interrupt
+      - description: send fifo is not empty interrupt
+      - description: receive fifo is empty interrupt
+      - description: receive fifo is not empty interrupt
+
+  interrupt-names:
+    minItems: 4
+    items:
+      - const: send-empty
+      - const: send-not-empty
+      - const: recv-empty
+      - const: recv-not-empty
+
+  "#mbox-cells":
+    const: 0
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - interrupt-names
+  - "#mbox-cells"
+
+additionalProperties: false
+
+examples:
+  - |
+        mailbox@77408000 {
+                compatible = "apple,t8103-asc-mailbox";
+                reg = <0x77408000 0x4000>;
+                interrupts = <1 583 4>, <1 584 4>, <1 585 4>, <1 586 4>;
+                interrupt-names = "send-empty", "send-not-empty",
+                 "recv-empty", "recv-not-empty";
+                #mbox-cells = <0>;
+        };
MAINTAINERS +1 -0
index a4a0c2baaf27..be83d20a33ef 100644
@@ -1723,6 +1723,7 @@ C:	irc://irc.oftc.net/asahi-dev
 T:	git https://github.com/AsahiLinux/linux.git
 F:	Documentation/devicetree/bindings/arm/apple.yaml
 F:	Documentation/devicetree/bindings/interrupt-controller/apple,aic.yaml
+F:	Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml
 F:	Documentation/devicetree/bindings/pinctrl/apple,pinctrl.yaml
 F:	arch/arm64/boot/dts/apple/
 F:	drivers/irqchip/irq-apple-aic.c
Signature · 1 line
2.25.1
maintainer
#2 lore raw

Re: [PATCH v3 1/2] dt-bindings: mailbox: Add Apple mailbox bindings

Quoted 7 lines · Sven Peter

Apple mailbox controller are found on the M1 and are used for communication with various co-processors.

Quoted 6 lines
---
 .../bindings/mailbox/apple,mailbox.yaml       | 79 +++++++++++++++++++
 MAINTAINERS                                   |  1 +
 2 files changed, 80 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml

My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check' on your patch (DT_CHECKER_FLAGS is new in v5.13):

yamllint warnings/errors:

dtschema/dtc warnings/errors:
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml: properties:interrupts: 'oneOf' conditional failed, one must be fixed:
[{'description': 'send fifo is empty interrupt'}, {'description': 'send fifo is not empty interrupt'}, {'description': 'receive fifo is empty interrupt'}, {'description': 'receive fifo is not empty interrupt'}] is too long [{'description': 'send fifo is empty interrupt'}, {'description': 'send fifo is not empty interrupt'}, {'description': 'receive fifo is empty interrupt'}, {'description': 'receive fifo is not empty interrupt'}] is too short False schema does not allow 4
1 was expected
4 is greater than the maximum of 2
4 is greater than the maximum of 3
hint: "minItems" is only needed if less than the "items" list length
from schema $id: http://devicetree.org/meta-schemas/items.yaml#
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml: properties:interrupt-names: 'oneOf' conditional failed, one must be fixed:
[{'const': 'send-empty'}, {'const': 'send-not-empty'}, {'const': 'recv-empty'}, {'const': 'recv-not-empty'}] is too long
[{'const': 'send-empty'}, {'const': 'send-not-empty'}, {'const': 'recv-empty'}, {'const': 'recv-not-empty'}] is too short
False schema does not allow 4
1 was expected
4 is greater than the maximum of 2
4 is greater than the maximum of 3
hint: "minItems" is only needed if less than the "items" list length
from schema $id: http://devicetree.org/meta-schemas/items.yaml#
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml: ignoring, error in schema: properties: interrupts
warning: no schema found in file: ./Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml
Documentation/devicetree/bindings/mailbox/apple,mailbox.example.dt.yaml:0:0: /example-0/mailbox@77408000: failed to match any schema with compatible: ['apple,t8103-asc-mailbox']

doc reference errors (make refcheckdocs):

See https://patchwork.ozlabs.org/patch/1542209

This check can fail if there are any dependencies. The base for a patch series is generally the most recent rc1.

If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:

pip3 install dtschema --upgrade

Please check and re-submit.

author
#3 lore raw

Re: [PATCH v3 1/2] dt-bindings: mailbox: Add Apple mailbox bindings

Quoted 65 lines · Rob Herring
Quoted 7 lines · Sven Peter

Apple mailbox controller are found on the M1 and are used for communication with various co-processors.

Quoted 6 lines
---
 .../bindings/mailbox/apple,mailbox.yaml       | 79 +++++++++++++++++++
 MAINTAINERS                                   |  1 +
 2 files changed, 80 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml

My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check' on your patch (DT_CHECKER_FLAGS is new in v5.13):

yamllint warnings/errors:

dtschema/dtc warnings/errors:
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml:
properties:interrupts: 'oneOf' conditional failed, one must be fixed:
[{'description': 'send fifo is empty interrupt'}, {'description':
'send fifo is not empty interrupt'}, {'description': 'receive fifo is
empty interrupt'}, {'description': 'receive fifo is not empty
interrupt'}] is too long
[{'description': 'send fifo is empty interrupt'}, {'description':
'send fifo is not empty interrupt'}, {'description': 'receive fifo is
empty interrupt'}, {'description': 'receive fifo is not empty
interrupt'}] is too short
False schema does not allow 4
1 was expected
4 is greater than the maximum of 2
4 is greater than the maximum of 3
hint: "minItems" is only needed if less than the "items" list length from schema $id: http://devicetree.org/meta-schemas/items.yaml#
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml:
properties:interrupt-names: 'oneOf' conditional failed, one must be
fixed:

	[{'const': 'send-empty'}, {'const': 'send-not-empty'}, {'const': 
'recv-empty'}, {'const': 'recv-not-empty'}] is too long
	[{'const': 'send-empty'}, {'const': 'send-not-empty'}, {'const': 

'recv-empty'}, {'const': 'recv-not-empty'}] is too short
False schema does not allow 4
1 was expected
4 is greater than the maximum of 2
4 is greater than the maximum of 3
hint: "minItems" is only needed if less than the "items" list length from schema $id: http://devicetree.org/meta-schemas/items.yaml#
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml:
ignoring, error in schema: properties: interrupts
warning: no schema found in file:
./Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml Documentation/devicetree/bindings/mailbox/apple,mailbox.example.dt.yaml:0:0:
/example-0/mailbox@77408000: failed to match any schema with
compatible: ['apple,t8103-asc-mailbox']

doc reference errors (make refcheckdocs):

See https://patchwork.ozlabs.org/patch/1542209

This check can fail if there are any dependencies. The base for a patch series is generally the most recent rc1.

Quoted 7 lines

If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:

pip3 install dtschema --upgrade

Please check and re-submit.

Whoops, looks like this fails some new check added since I submitted the last version a month ago.
I'll drop the "minItems: 4" since the number of items is constant anyway.

Sven

author
#4 lore raw

PATCH v3 2/2 mailbox: apple: Add driver for Apple mailboxes

In reply to Sven Peter

Apple SoCs such as the M1 come with various co-processors. Mailboxes are used to communicate with those. This driver adds support for two variants of those mailboxes.

---
 MAINTAINERS                     |   2 +
 drivers/mailbox/Kconfig         |  12 +
 drivers/mailbox/Makefile        |   2 +
 drivers/mailbox/apple-mailbox.c | 374 ++++++++++++++++++++++++++++++++
 include/linux/apple-mailbox.h   |  18 ++
 5 files changed, 408 insertions(+)
 create mode 100644 drivers/mailbox/apple-mailbox.c
 create mode 100644 include/linux/apple-mailbox.h
MAINTAINERS +2 -0
index be83d20a33ef..e149f7d7258a 100644
@@ -1727,8 +1727,10 @@ F:	Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml
 F:	Documentation/devicetree/bindings/pinctrl/apple,pinctrl.yaml
 F:	arch/arm64/boot/dts/apple/
 F:	drivers/irqchip/irq-apple-aic.c
+F:	drivers/mailbox/apple-mailbox.c
 F:	include/dt-bindings/interrupt-controller/apple-aic.h
 F:	include/dt-bindings/pinctrl/apple.h
+F:	include/linux/apple-mailbox.h
 
 ARM/ARTPEC MACHINE SUPPORT
 M:	Jesper Nilsson <[email protected]>
drivers/mailbox/Kconfig +12 -0
index c9fc06c7e685..d9cd3606040e 100644
@@ -8,6 +8,18 @@ menuconfig MAILBOX
 
 if MAILBOX
 
+config APPLE_MAILBOX
+	tristate "Apple Mailbox driver"
+	depends on ARCH_APPLE || (ARM64 && COMPILE_TEST)
+	default ARCH_APPLE
+	help
+	  Apple SoCs have various co-processors required for certain
+	  peripherals to work (NVMe, display controller, etc.). This
+	  driver adds support for the mailbox controller used to
+	  communicate with those.
+
+	  Say Y here if you have a Apple SoC.
+
 config ARM_MHU
 	tristate "ARM MHU Mailbox"
 	depends on ARM_AMBA
drivers/mailbox/Makefile +2 -0
index c2089f04887e..338cc05e5431 100644
@@ -58,3 +58,5 @@ obj-$(CONFIG_SUN6I_MSGBOX)	+= sun6i-msgbox.o
 obj-$(CONFIG_SPRD_MBOX)		+= sprd-mailbox.o
 
 obj-$(CONFIG_QCOM_IPCC)		+= qcom-ipcc.o
+
+obj-$(CONFIG_APPLE_MAILBOX)	+= apple-mailbox.o
drivers/mailbox/apple-mailbox.c new file +374 -0

374 lines not on this page · raw message

include/linux/apple-mailbox.h new file +18 -0
new file mode 100644
index 000000000000..c455e0f9c73b
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0-only OR MIT */
+/*
+ * Apple mailbox message format
+ *
+ * Copyright (C) 2021 The Asahi Linux Contributors
+ */
+
+#ifndef _LINUX_APPLE_MAILBOX_H_
+#define _LINUX_APPLE_MAILBOX_H_
+
+#include <linux/types.h>
+
+struct apple_mbox_msg {
+	u64 msg0;
+	u32 msg1;
+};
+
+#endif
Signature · 1 line
2.25.1
#5 lore raw

Re: [PATCH v3 2/2] mailbox: apple: Add driver for Apple mailboxes

Quoted 6 lines

Apple SoCs such as the M1 come with various co-processors. Mailboxes are used to communicate with those. This driver adds support for two variants of those mailboxes.

In the future, Reviewed-by tags should be dropped after making major changes to a patch.

drivers/mailbox/apple-mailbox.c line 237

Quoted 3 lines
drivers/mailbox/apple-mailbox.c new file +3 -0
+		writel_relaxed(apple_mbox->hw->irq_bit_recv_not_empty |
+				       apple_mbox->hw->irq_bit_send_empty,
+			       apple_mbox->regs + apple_mbox->hw->irq_enable);

Nit: weird wrapping, much easier to read as:

+ writel_relaxed(apple_mbox->hw->irq_bit_recv_not_empty |
+ apple_mbox->hw->irq_bit_send_empty,
+ apple_mbox->regs + apple_mbox->hw->irq_enable);

Quoted 4 lines
drivers/mailbox/apple-mailbox.c new file +4 -0
+static const struct apple_mbox_hw apple_mbox_asc_hw = {
+	.control_full = APPLE_ASC_MBOX_CONTROL_FULL,
+	.control_empty = APPLE_ASC_MBOX_CONTROL_EMPTY,
+

drivers/mailbox/apple-mailbox.c line 335

Quoted 10 lines
drivers/mailbox/apple-mailbox.c new file +10 -0
+	.a2i_control = APPLE_ASC_MBOX_A2I_CONTROL,
+	.a2i_send0 = APPLE_ASC_MBOX_A2I_SEND0,
+	.a2i_send1 = APPLE_ASC_MBOX_A2I_SEND1,
+
+	.i2a_control = APPLE_ASC_MBOX_I2A_CONTROL,
+	.i2a_recv0 = APPLE_ASC_MBOX_I2A_RECV0,
+	.i2a_recv1 = APPLE_ASC_MBOX_I2A_RECV1,
+
+	.has_irq_controls = false,
+};

Nit: consider dropping the has_irq_controls = false assignment. Clearly there are none, or you'd have to fill out the irq_* fields too.

drivers/mailbox/apple-mailbox.c line 360

Quoted 5 lines
drivers/mailbox/apple-mailbox.c new file +5 -0
+static const struct of_device_id apple_mbox_of_match[] = {
+	{ .compatible = "apple,t8103-asc-mailbox", .data = &apple_mbox_asc_hw },
+	{ .compatible = "apple,t8103-m3-mailbox", .data = &apple_mbox_m3_hw },
+	{}
+};

No generic compatibles? I assume this driver hasn't changed much in recent iPhones, and hopefully it won't change much in M1X...

Quoted 8 lines
include/linux/apple-mailbox.h new file +8 -0
+/* SPDX-License-Identifier: GPL-2.0-only OR MIT */
+/*
+ * Apple mailbox message format
+ *
+ * Copyright (C) 2021 The Asahi Linux Contributors
+ */
+
+#ifndef _LINUX_APPLE_MAILBOX_H_

include/linux/apple-mailbox.h line 18

Quoted 10 lines
include/linux/apple-mailbox.h new file +10 -0
+#define _LINUX_APPLE_MAILBOX_H_
+
+#include <linux/types.h>
+
+struct apple_mbox_msg {
+	u64 msg0;
+	u32 msg1;
+};
+
+#endif

Given this file lacks the context of the driver, and the questions raised in v2 review, it might be beneficial to add a quick comment to apple_mbox_msg explaiing that no, really, this is a 96-bit message.

author
#6 lore raw

Re: [PATCH v3 2/2] mailbox: apple: Add driver for Apple mailboxes

Hi,

Quoted 9 lines · Alyssa Rosenzweig
Quoted 6 lines

Apple SoCs such as the M1 come with various co-processors. Mailboxes are used to communicate with those. This driver adds support for two variants of those mailboxes.

In the future, Reviewed-by tags should be dropped after making major changes to a patch.

I don't think there were any major changes since v2, but sure, I'll drop your tag in the future. All your comments below already apply to v2.

drivers/mailbox/apple-mailbox.c line 237

Quoted 11 lines

drivers/mailbox/apple-mailbox.c line 237

Quoted 4 lines
drivers/mailbox/apple-mailbox.c new file +3 -0
+		writel_relaxed(apple_mbox->hw->irq_bit_recv_not_empty |
+				       apple_mbox->hw->irq_bit_send_empty,
+			       apple_mbox->regs + apple_mbox->hw->irq_enable);

Nit: weird wrapping, much easier to read as:

drivers/mailbox/apple-mailbox.c new file +3 -0
+		writel_relaxed(apple_mbox->hw->irq_bit_recv_not_empty |
+			       apple_mbox->hw->irq_bit_send_empty,
+			       apple_mbox->regs + apple_mbox->hw->irq_enable);

This is just what clang-format does and I'd rather keep it this way. Note that the first two lines are the first argument combined with an OR.

Quoted 9 lines
Quoted 9 lines
drivers/mailbox/apple-mailbox.c new file +9 -0
+static const struct apple_mbox_hw apple_mbox_asc_hw = {
+	.control_full = APPLE_ASC_MBOX_CONTROL_FULL,
+	.control_empty = APPLE_ASC_MBOX_CONTROL_EMPTY,
+
+	.a2i_control = APPLE_ASC_MBOX_A2I_CONTROL,
+	.a2i_send0 = APPLE_ASC_MBOX_A2I_SEND0,
+	.a2i_send1 = APPLE_ASC_MBOX_A2I_SEND1,
+
+	.i2a_control = APPLE_ASC_MBOX_I2A_CONTROL,
Quoted 8 lines

drivers/mailbox/apple-mailbox.c line 335

Quoted 5 lines
drivers/mailbox/apple-mailbox.c new file +5 -0
+	.i2a_recv0 = APPLE_ASC_MBOX_I2A_RECV0,
+	.i2a_recv1 = APPLE_ASC_MBOX_I2A_RECV1,
+
+	.has_irq_controls = false,
+};

Nit: consider dropping the has_irq_controls = false assignment. Clearly there are none, or you'd have to fill out the irq_* fields too.

I'd rather keep it explicit as false here to make the intent clear.

Quoted 9 lines

drivers/mailbox/apple-mailbox.c line 360

Quoted 6 lines
drivers/mailbox/apple-mailbox.c new file +5 -0
+static const struct of_device_id apple_mbox_of_match[] = {
+	{ .compatible = "apple,t8103-asc-mailbox", .data = &apple_mbox_asc_hw },
+	{ .compatible = "apple,t8103-m3-mailbox", .data = &apple_mbox_m3_hw },
+	{}
+};

No generic compatibles? I assume this driver hasn't changed much in recent iPhones, and hopefully it won't change much in M1X...

Then we can always have apple,tXXX-asc-mailbox, apple,t8103-asc-mailbox in the device tree. From what I can tell this specific mailbox has only appeared in this SoC generation.

Quoted 15 lines
Quoted 15 lines
include/linux/apple-mailbox.h new file +14 -0
+/* SPDX-License-Identifier: GPL-2.0-only OR MIT */
+/*
+ * Apple mailbox message format
+ *
+ * Copyright (C) 2021 The Asahi Linux Contributors
+ */
+
+#ifndef _LINUX_APPLE_MAILBOX_H_
+#define _LINUX_APPLE_MAILBOX_H_
+
+#include <linux/types.h>
+
+struct apple_mbox_msg {
+	u64 msg0;
Quoted 8 lines

include/linux/apple-mailbox.h line 18

Quoted 4 lines
include/linux/apple-mailbox.h new file +4 -0
+	u32 msg1;
+};
+
+#endif

Given this file lacks the context of the driver, and the questions raised in v2 review, it might be beneficial to add a quick comment to apple_mbox_msg explaiing that no, really, this is a 96-bit message.

I don't think that's necessary but it doesn't hurt either I guess.

Sven