mailbox: arm: introduce smc triggered mailbox
Subsystems (2)
v2 cover mailbox: arm: introduce smc triggered mailbox
From: Peng Fan <[email protected]>
This is a modified version from Andre Przywara's patch series
https://lore.kernel.org/patchwork/cover/812997/.
The modification are mostly:
Introduce arm,num-chans
Introduce arm_smccc_mbox_cmdtxdone_poll and txdone_irq are both set to false arm,func-ids are kept, but as an optional property. Rewords SCPI to SCMI, because I am trying SCMI over SMC, not SCPI. Introduce interrupts notification.
[1] is a draft implementation of i.MX8MM SCMI ATF implementation that use smc as mailbox, power/clk is included, but only part of clk has been implemented to work with hardware, power domain only supports get name for now.
The traditional Linux mailbox mechanism uses some kind of dedicated hardware IP to signal a condition to some other processing unit, typically a dedicated management processor.
This mailbox feature is used for instance by the SCMI protocol to signal a request for some action to be taken by the management processor. However some SoCs does not have a dedicated management core to provide those services. In order to service TEE and to avoid linux shutdown power and clock that used by TEE, need let firmware to handle power and clock, the firmware here is ARM Trusted Firmware that could also run SCMI service.
The existing SCMI implementation uses a rather flexible shared memory region to communicate commands and their parameters, it still requires a mailbox to actually trigger the action.
This patch series provides a Linux mailbox compatible service which uses smc calls to invoke firmware code, for instance taking care of SCMI requests. The actual requests are still communicated using the standard SCMI way of shared memory regions, but a dedicated mailbox hardware IP can be replaced via this new driver.
This simple driver uses the architected SMC calling convention to trigger firmware services, also allows for using "HVC" calls to call into hypervisors or firmware layers running in the EL2 exception level.
Patch 1 contains the device tree binding documentation, patch 2 introduces the actual mailbox driver.
Please note that this driver just provides a generic mailbox mechanism, It could support synchronous TX/RX, or synchronous TX with asynchronous RX. And while providing SCMI services was the reason for this exercise, this driver is in no way bound to this use case, but can be used generically where the OS wants to signal a mailbox condition to firmware or a hypervisor.
Also the driver is in no way meant to replace any existing firmware interface, but actually to complement existing interfaces.
[1] https://github.com/MrVan/arm-trusted-firmware/tree/scmi
Peng Fan (2):
DT: mailbox: add binding doc for the ARM SMC mailbox
mailbox: introduce ARM SMC based mailbox
.../devicetree/bindings/mailbox/arm-smc.txt | 101 +++++++++++ drivers/mailbox/Kconfig | 7 + drivers/mailbox/Makefile | 2 + drivers/mailbox/arm-smc-mailbox.c | 190 +++++++++++++++++++++ include/linux/mailbox/arm-smc-mailbox.h | 10 ++ 5 files changed, 310 insertions(+) create mode 100644 Documentation/devicetree/bindings/mailbox/arm-smc.txt create mode 100644 drivers/mailbox/arm-smc-mailbox.c create mode 100644 include/linux/mailbox/arm-smc-mailbox.h
Signature · 1 line
2.16.4
PATCH v2 1/2 DT: mailbox: add binding doc for the ARM SMC mailbox
From: Peng Fan <[email protected]>
The ARM SMC mailbox binding describes a firmware interface to trigger actions in software layers running in the EL2 or EL3 exception levels. The term "ARM" here relates to the SMC instruction as part of the ARM instruction set, not as a standard endorsed by ARM Ltd.
---
V2:
Introduce interrupts as a property.
V1:
arm,func-ids is still kept as an optional property, because there is no defined SMC funciton id passed from SCMI. So in my test, I still use arm,func-ids for ARM SIP service.
.../devicetree/bindings/mailbox/arm-smc.txt | 101 +++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 Documentation/devicetree/bindings/mailbox/arm-smc.txt
Documentation/devicetree/bindings/mailbox/arm-smc.txt new file +101 -0
@@ -0,0 +1,101 @@ +ARM SMC Mailbox Interface +========================= + +This mailbox uses the ARM smc (secure monitor call) instruction to trigger +a mailbox-connected activity in firmware, executing on the very same core +as the caller. By nature this operation is synchronous and this mailbox +provides no way for asynchronous messages to be delivered the other way +round, from firmware to the OS, but asynchronous notification could also +be supported. However the value of r0/w0/x0 the firmware returns after +the smc call is delivered as a received message to the mailbox framework, +so a synchronous communication can be established, for a asynchronous +notification, no value will be returned. The exact meaning of both the +action the mailbox triggers as well as the return value is defined by +their users and is not subject to this binding. + +One use case of this mailbox is the SCMI interface, which uses shared memory +to transfer commands and parameters, and a mailbox to trigger a function +call. This allows SoCs without a separate management processor (or when +such a processor is not available or used) to use this standardized +interface anyway. + +This binding describes no hardware, but establishes a firmware interface. +Upon receiving an SMC using one of the described SMC function identifiers, +the firmware is expected to trigger some mailbox connected functionality. +The communication follows the ARM SMC calling convention[1]. +Firmware expects an SMC function identifier in r0 or w0. The supported +identifiers are passed from consumers, or listed in the the arm,func-ids +properties as described below. The firmware can return one value in +the first SMC result register, it is expected to be an error value, +which shall be propagated to the mailbox client. + +Any core which supports the SMC or HVC instruction can be used, as long as +a firmware component running in EL3 or EL2 is handling these calls. + +Mailbox Device Node: +==================== + +This node is expected to be a child of the /firmware node. + +Required properties: +-------------------- +- compatible: Shall be "arm,smc-mbox" +- #mbox-cells Shall be 1 - the index of the channel needed. +- arm,num-chans The number of channels supported. +- method: A string, either: + "hvc": if the driver shall use an HVC call, or + "smc": if the driver shall use an SMC call. + +Optional properties: +- arm,func-ids An array of 32-bit values specifying the function + IDs used by each mailbox channel. Those function IDs + follow the ARM SMC calling convention standard [1]. + There is one identifier per channel and the number + of supported channels is determined by the length + of this array. +- interrupts SPI interrupts may be listed for notification, + each channel should use a dedicated interrupt + line. + +Example: +-------- + + sram@910000 { + compatible = "mmio-sram"; + reg = <0x0 0x93f000 0x0 0x1000>; + #address-cells = <1>; + #size-cells = <1>; + ranges = <0 0x0 0x93f000 0x1000>; + + cpu_scp_lpri: scp-shmem@0 { + compatible = "arm,scmi-shmem"; + reg = <0x0 0x200>; + }; + + cpu_scp_hpri: scp-shmem@200 { + compatible = "arm,scmi-shmem"; + reg = <0x200 0x200>; + }; + }; + + smc_mbox: mailbox { + #mbox-cells = <1>; + compatible = "arm,smc-mbox"; + method = "smc"; + arm,num-chans = <0x2>; + /* Optional */ + arm,func-ids = <0xc20000fe>, <0xc20000ff>; + }; + + firmware { + scmi { + compatible = "arm,scmi"; + mboxes = <&mailbox 0 &mailbox 1>; + mbox-names = "tx", "rx"; + shmem = <&cpu_scp_lpri &cpu_scp_hpri>; + }; + }; + + +[1] +http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.den0028a/index.html
Signature · 1 line
2.16.4
PATCH v2 2/2 mailbox: introduce ARM SMC based mailbox
In reply to [email protected]From: Peng Fan <[email protected]>
This mailbox driver implements a mailbox which signals transmitted data via an ARM smc (secure monitor call) instruction. The mailbox receiver is implemented in firmware and can synchronously return data when it returns execution to the non-secure world again.
An asynchronous receive path is not implemented.
This allows the usage of a mailbox to trigger firmware actions on SoCs which either don't have a separate management processor or on which such a core is not available. A user of this mailbox could be the SCP interface.
Modified from Andre Przywara's v2 patch
https://lore.kernel.org/patchwork/patch/812999/
---
V2:
Add interrupts notification support.
drivers/mailbox/Kconfig | 7 ++ drivers/mailbox/Makefile | 2 + drivers/mailbox/arm-smc-mailbox.c | 190 ++++++++++++++++++++++++++++++++ include/linux/mailbox/arm-smc-mailbox.h | 10 ++ 4 files changed, 209 insertions(+) create mode 100644 drivers/mailbox/arm-smc-mailbox.c create mode 100644 include/linux/mailbox/arm-smc-mailbox.h
drivers/mailbox/Kconfig +7 -0
@@ -15,6 +15,13 @@ config ARM_MHU The controller has 3 mailbox channels, the last of which can be used in Secure mode only. +config ARM_SMC_MBOX + tristate "Generic ARM smc mailbox" + depends on OF && HAVE_ARM_SMCCC + help + Generic mailbox driver which uses ARM smc calls to call into + firmware for triggering mailboxes. + config IMX_MBOX tristate "i.MX Mailbox" depends on ARCH_MXC || COMPILE_TEST
drivers/mailbox/Makefile +2 -0
@@ -7,6 +7,8 @@ obj-$(CONFIG_MAILBOX_TEST) += mailbox-test.o obj-$(CONFIG_ARM_MHU) += arm_mhu.o +obj-$(CONFIG_ARM_SMC_MBOX) += arm-smc-mailbox.o + obj-$(CONFIG_IMX_MBOX) += imx-mailbox.o obj-$(CONFIG_ARMADA_37XX_RWTM_MBOX) += armada-37xx-rwtm-mailbox.o
drivers/mailbox/arm-smc-mailbox.c new file +190 -0
190 lines not on this page · raw message
include/linux/mailbox/arm-smc-mailbox.h new file +10 -0
@@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef _LINUX_ARM_SMC_MAILBOX_H_ +#define _LINUX_ARM_SMC_MAILBOX_H_ + +struct arm_smccc_mbox_cmd { +unsigned long a0, a1, a2, a3, a4, a5, a6, a7; +}; + +#endif /* _LINUX_ARM_SMC_MAILBOX_H_ */
Signature · 1 line
2.16.4
Re: [PATCH V2 1/2] DT: mailbox: add binding doc for the ARM SMC mailbox
In reply to [email protected]Quoted 28 lines · On 6/3/19 1:30 AM, [email protected] wrote:
From: Peng Fan <[email protected]>
The ARM SMC mailbox binding describes a firmware interface to trigger actions in software layers running in the EL2 or EL3 exception levels. The term "ARM" here relates to the SMC instruction as part of the ARM instruction set, not as a standard endorsed by ARM Ltd.
Signed-off-by Peng Fan <[email protected]>---
V2:
Introduce interrupts as a property.V1:
arm,func-ids is still kept as an optional property, because there is no defined SMC funciton id passed from SCMI. So in my test, I still use arm,func-ids for ARM SIP service..../devicetree/bindings/mailbox/arm-smc.txt | 101 +++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 Documentation/devicetree/bindings/mailbox/arm-smc.txtDocumentation/devicetree/bindings/mailbox/arm-smc.txt new file +0
-0
Documentation/devicetree/bindings/mailbox/arm-smc.txt line 6
Quoted 6 lines
Documentation/devicetree/bindings/mailbox/arm-smc.txt new file +6
-0@@ -0,0 +1,101 @@ +ARM SMC Mailbox Interface +========================= + +This mailbox uses the ARM smc (secure monitor call) instruction to trigger +a mailbox-connected activity in firmware, executing on the very same core +as the caller.
The binding defines both hvc and smc as being valid methods for the mailbox.
Quoted 43 lines
By nature this operation is synchronous and this mailbox
Documentation/devicetree/bindings/mailbox/arm-smc.txt new file +42
-0+provides no way for asynchronous messages to be delivered the other way +round, from firmware to the OS, but asynchronous notification could also +be supported. However the value of r0/w0/x0 the firmware returns after +the smc call is delivered as a received message to the mailbox framework, +so a synchronous communication can be established, for a asynchronous +notification, no value will be returned. The exact meaning of both the +action the mailbox triggers as well as the return value is defined by +their users and is not subject to this binding. + +One use case of this mailbox is the SCMI interface, which uses shared memory +to transfer commands and parameters, and a mailbox to trigger a function +call. This allows SoCs without a separate management processor (or when +such a processor is not available or used) to use this standardized +interface anyway. + +This binding describes no hardware, but establishes a firmware interface. +Upon receiving an SMC using one of the described SMC function identifiers, +the firmware is expected to trigger some mailbox connected functionality. +The communication follows the ARM SMC calling convention[1]. +Firmware expects an SMC function identifier in r0 or w0. The supported +identifiers are passed from consumers, or listed in the the arm,func-ids +properties as described below. The firmware can return one value in +the first SMC result register, it is expected to be an error value, +which shall be propagated to the mailbox client. + +Any core which supports the SMC or HVC instruction can be used, as long as +a firmware component running in EL3 or EL2 is handling these calls. + +Mailbox Device Node: +==================== + +This node is expected to be a child of the /firmware node. + +Required properties: +-------------------- +- compatible: Shall be "arm,smc-mbox" +- #mbox-cells Shall be 1 - the index of the channel needed. +- arm,num-chans The number of channels supported. +- method: A string, either: + "hvc": if the driver shall use an HVC call, or + "smc": if the driver shall use an SMC call. +
Documentation/devicetree/bindings/mailbox/arm-smc.txt line 58
Quoted 10 lines
Documentation/devicetree/bindings/mailbox/arm-smc.txt new file +10
-0+Optional properties: +- arm,func-ids An array of 32-bit values specifying the function + IDs used by each mailbox channel. Those function IDs + follow the ARM SMC calling convention standard [1]. + There is one identifier per channel and the number + of supported channels is determined by the length + of this array. +- interrupts SPI interrupts may be listed for notification, + each channel should use a dedicated interrupt + line.
I would not go about defining a specific kind of interrupt, since SPI is a GIC terminology, this firmware interface could be used in premise with any parent interrupt controller, for which the concept of a SPI/PPI/SGI may not be relevant.
Quoted 25 lines
Documentation/devicetree/bindings/mailbox/arm-smc.txt new file +25
-0+ +Example: +-------- + + sram@910000 { + compatible = "mmio-sram"; + reg = <0x0 0x93f000 0x0 0x1000>; + #address-cells = <1>; + #size-cells = <1>; + ranges = <0 0x0 0x93f000 0x1000>; + + cpu_scp_lpri: scp-shmem@0 { + compatible = "arm,scmi-shmem"; + reg = <0x0 0x200>; + }; + + cpu_scp_hpri: scp-shmem@200 { + compatible = "arm,scmi-shmem"; + reg = <0x200 0x200>; + }; + }; + + smc_mbox: mailbox { + #mbox-cells = <1>; + compatible = "arm,smc-mbox";
Documentation/devicetree/bindings/mailbox/arm-smc.txt line 93
Quoted 10 lines
Documentation/devicetree/bindings/mailbox/arm-smc.txt new file +10
-0+ method = "smc"; + arm,num-chans = <0x2>; + /* Optional */ + arm,func-ids = <0xc20000fe>, <0xc20000ff>; + }; + + firmware { + scmi { + compatible = "arm,scmi"; + mboxes = <&mailbox 0 &mailbox 1>;
It is visually nicer (and more consistent with yoyr arm,func-ids example to use:
mboxes = <&mailbox 0>, <&mailbox 1>;
Documentation/devicetree/bindings/mailbox/arm-smc.txt line 95
Quoted 2 lines
Documentation/devicetree/bindings/mailbox/arm-smc.txt new file +2
-0+ mbox-names = "tx", "rx"; + shmem = <&cpu_scp_lpri &cpu_scp_hpri>;
shmem = <&cpu_scp_lpri>, <&cpu_scp_hpri>;
Other than those, LGTM!
Signature · 1 line
Florian
Re: [PATCH V2 2/2] mailbox: introduce ARM SMC based mailbox
In reply to [email protected]Quoted 12 lines · On 6/3/19 1:30 AM, [email protected] wrote:
From: Peng Fan <[email protected]>
This mailbox driver implements a mailbox which signals transmitted data via an ARM smc (secure monitor call) instruction. The mailbox receiver is implemented in firmware and can synchronously return data when it returns execution to the non-secure world again.
An asynchronous receive path is not implemented.
This allows the usage of a mailbox to trigger firmware actions on SoCs which either don't have a separate management processor or on which such a core is not available. A user of this mailbox could be the SCP interface.
Quoted 6 lines
Modified from Andre Przywara's v2 patch
https://lore.kernel.org/patchwork/patch/812999/Cc Andre Przywara <[email protected]>Signed-off-by Peng Fan <[email protected]>---
[snip]
+#define ARM_SMC_MBOX_USB_IRQ BIT(1)
That flag appears unused.
Quoted 6 lines
drivers/mailbox/arm-smc-mailbox.c new file +6
-0+static int arm_smc_mbox_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct mbox_controller *mbox; +struct arm_smc_chan_data *chan_data; +const char *method;
drivers/mailbox/arm-smc-mailbox.c line 80
Quoted 10 lines
drivers/mailbox/arm-smc-mailbox.c new file +10
-0+bool use_hvc = false; +int ret, irq_count, i; +u32 val; + +if (!of_property_read_u32 (dev->of_node,"arm,num-chans" , &val)) { +if (val <1 || val >INT_MAX ) { +dev_err (dev,"invalid arm,num-chans value %u of %pOFn\n" , val, pdev->dev.of_node); +return -EINVAL ; + } + }
Should not the upper bound check be done against UINT_MAX since val is an unsigned int?
drivers/mailbox/arm-smc-mailbox.c line 87
Quoted 7 lines
drivers/mailbox/arm-smc-mailbox.c new file +7
-0+ + irq_count =platform_irq_count (pdev); +if (irq_count == -EPROBE_DEFER ) +return irq_count; + +if (irq_count && irq_count != val) { +dev_err (dev,"Interrupts not match num-chans\n" );
Interrupts property does not match \"arm,num-chans\" would be more correct.
Quoted 4 lines
drivers/mailbox/arm-smc-mailbox.c new file +4
-0+return -EINVAL ; + } + +if (!of_property_read_string (dev->of_node,"method" , &method)) {
drivers/mailbox/arm-smc-mailbox.c line 101
Quoted 10 lines
drivers/mailbox/arm-smc-mailbox.c new file +10
-0+if (!strcmp ("hvc" , method)) { + use_hvc = true; + }else if (!strcmp ("smc" , method)) { + use_hvc = false; + }else { +dev_warn (dev,"invalid \"method\" property: %s\n" , + method); + +return -EINVAL ; + }
Having at least one method specified does not seem to be checked later on in the code, so if I omitted to specify that property, we would still register the mailbox and default to use "smc" since the ARM_SMC_MBOX_USE_HVC flag would not be set, would not we want to make sure that we do have in fact a valid method specified given the binding documents that property as mandatory?
[snip]
drivers/mailbox/arm-smc-mailbox.c line 157
Quoted 10 lines
drivers/mailbox/arm-smc-mailbox.c new file +10
-0+ mbox->txdone_poll = false; + mbox->txdone_irq = false; + mbox->ops = &arm_smc_mbox_chan_ops; + mbox->dev = dev; + + ret =mbox_controller_register (mbox); +if (ret) +return ret; + +platform_set_drvdata (pdev, mbox);
I would move this above mbox_controller_register() that way there is no room for race conditions in case another part of the driver expects to have pdev->dev.drvdata set before the mbox controller is registered. Since you use devm_* functions for everything, you may even remove that call.
[snip]
include/linux/mailbox/arm-smc-mailbox.h line 8
Quoted 6 lines
include/linux/mailbox/arm-smc-mailbox.h new file +6
-0+#ifndef _LINUX_ARM_SMC_MAILBOX_H_ +#define _LINUX_ARM_SMC_MAILBOX_H_ + +struct arm_smccc_mbox_cmd { +unsigned long a0, a1, a2, a3, a4, a5, a6, a7; +};
Do you expect this to be used by other in-kernel users? If so, it might be good to document how a0 can have a special meaning and be used as a substitute for the function_id?
Signature · 1 line
Florian
Re: [PATCH V2 1/2] DT: mailbox: add binding doc for the ARM SMC mailbox
In reply to Florian FainelliQuoted 29 lines · Florian Fainelli
Quoted 28 lines · On 6/3/19 1:30 AM, [email protected] wrote:
From: Peng Fan <[email protected]>
The ARM SMC mailbox binding describes a firmware interface to trigger actions in software layers running in the EL2 or EL3 exception levels. The term "ARM" here relates to the SMC instruction as part of the ARM instruction set, not as a standard endorsed by ARM Ltd.
Signed-off-by Peng Fan <[email protected]>---
V2:
Introduce interrupts as a property.V1:
arm,func-ids is still kept as an optional property, because there is no defined SMC funciton id passed from SCMI. So in my test, I still use arm,func-ids for ARM SIP service..../devicetree/bindings/mailbox/arm-smc.txt | 101 +++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 Documentation/devicetree/bindings/mailbox/arm-smc.txtDocumentation/devicetree/bindings/mailbox/arm-smc.txt new file +0
-0@@ -0,0 +1,101 @@
[...]
Quoted 7 lines
Quoted 7 lines
Documentation/devicetree/bindings/mailbox/arm-smc.txt new file +7
-0+Optional properties: +- arm,func-ids An array of 32-bit values specifying the function + IDs used by each mailbox channel. Those function IDs + follow the ARM SMC calling convention standard [1]. + There is one identifier per channel and the number + of supported channels is determined by the length + of this array.
Quoted 9 lines
Documentation/devicetree/bindings/mailbox/arm-smc.txt line 58
Quoted 3 lines
+- interrupts SPI interrupts may be listed for notification,
Documentation/devicetree/bindings/mailbox/arm-smc.txt new file +2
-0+ each channel should use a dedicated interrupt + line.I would not go about defining a specific kind of interrupt, since SPI is a GIC terminology, this firmware interface could be used in premise with any parent interrupt controller, for which the concept of a SPI/PPI/SGI may not be relevant.
While I agree the binding document may not contain specifics, I still don't see how to use SGI with this. Also note it's generally reserved for OS future use(IPC) and using this for other than IPC may be bit challenging IMO. It opens up lots of questions.
--
Regards,
Sudeep
Re: [PATCH V2 1/2] DT: mailbox: add binding doc for the ARM SMC mailbox
On Mon, 3 Jun 2019 17:56:51 +0100
Sudeep Holla <[email protected]> wrote:
Hi,
Quoted 50 lines · Florian Fainelli
Quoted 29 lines · On 6/3/19 1:30 AM, [email protected] wrote:
Quoted 28 lines
From: Peng Fan <[email protected]>
The ARM SMC mailbox binding describes a firmware interface to trigger actions in software layers running in the EL2 or EL3 exception levels. The term "ARM" here relates to the SMC instruction as part of the ARM instruction set, not as a standard endorsed by ARM Ltd.
Signed-off-by Peng Fan <[email protected]>---
V2:
Introduce interrupts as a property.V1:
arm,func-ids is still kept as an optional property, because there is no defined SMC funciton id passed from SCMI. So in my test, I still use arm,func-ids for ARM SIP service..../devicetree/bindings/mailbox/arm-smc.txt | 101 +++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 Documentation/devicetree/bindings/mailbox/arm-smc.txtDocumentation/devicetree/bindings/mailbox/arm-smc.txt new file +0
-0@@ -0,0 +1,101 @@[...]
Quoted 7 lines
Quoted 7 lines
Documentation/devicetree/bindings/mailbox/arm-smc.txt new file +7
-0+Optional properties: +- arm,func-ids An array of 32-bit values specifying the function + IDs used by each mailbox channel. Those function IDs + follow the ARM SMC calling convention standard [1]. + There is one identifier per channel and the number + of supported channels is determined by the length + of this array.Quoted 9 lines
Documentation/devicetree/bindings/mailbox/arm-smc.txt line 58
Quoted 3 lines
+- interrupts SPI interrupts may be listed for notification,
Documentation/devicetree/bindings/mailbox/arm-smc.txt new file +2
-0+ each channel should use a dedicated interrupt + line.I would not go about defining a specific kind of interrupt, since SPI is a GIC terminology, this firmware interface could be used in premise with any parent interrupt controller, for which the concept of a SPI/PPI/SGI may not be relevant.
Quoted 4 lines
While I agree the binding document may not contain specifics, I still don't see how to use SGI with this. Also note it's generally reserved for OS future use(IPC) and using this for other than IPC may be bit challenging IMO. It opens up lots of questions.
Well, a PPI might be possible to use, although it's somewhat dodgy to hijack the GIC's (re-)distributor from EL3 to write to GICD_ISPENDR<n>. Need to ask Marc about his feelings towards this. But it's definitely possible from a hypervisor to inject arbitrary interrupts into a guest.
But more importantly: is there any actual reason this needs to be a GIC interrupt? If I understand the code correctly, this could just be any interrupt, including one of an interrupt combiner or a GPIO chip. So why not just use the standard wording of: "exactly one interrupt specifier for each channel"?
By the way: Shouldn't new bindings use the YAML format instead?
Cheers,
Andre.
Re: [PATCH V2 1/2] DT: mailbox: add binding doc for the ARM SMC mailbox
Quoted 55 lines · Andre Przywara
On Mon, 3 Jun 2019 17:56:51 +0100
Sudeep Holla <[email protected]> wrote:Hi,
Quoted 50 lines · Florian Fainelli
Quoted 29 lines · On 6/3/19 1:30 AM, [email protected] wrote:
Quoted 28 lines
From: Peng Fan <[email protected]>
The ARM SMC mailbox binding describes a firmware interface to trigger actions in software layers running in the EL2 or EL3 exception levels. The term "ARM" here relates to the SMC instruction as part of the ARM instruction set, not as a standard endorsed by ARM Ltd.
Signed-off-by Peng Fan <[email protected]>---
V2:
Introduce interrupts as a property.V1:
arm,func-ids is still kept as an optional property, because there is no defined SMC funciton id passed from SCMI. So in my test, I still use arm,func-ids for ARM SIP service..../devicetree/bindings/mailbox/arm-smc.txt | 101 +++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 Documentation/devicetree/bindings/mailbox/arm-smc.txtDocumentation/devicetree/bindings/mailbox/arm-smc.txt new file +0
-0@@ -0,0 +1,101 @@[...]
Quoted 16 lines
Documentation/devicetree/bindings/mailbox/arm-smc.txt line 58
Quoted 10 lines
Documentation/devicetree/bindings/mailbox/arm-smc.txt new file +10
-0+Optional properties: +- arm,func-ids An array of 32-bit values specifying the function + IDs used by each mailbox channel. Those function IDs + follow the ARM SMC calling convention standard [1]. + There is one identifier per channel and the number + of supported channels is determined by the length + of this array. +- interrupts SPI interrupts may be listed for notification, + each channel should use a dedicated interrupt + line.I would not go about defining a specific kind of interrupt, since SPI is a GIC terminology, this firmware interface could be used in premise with any parent interrupt controller, for which the concept of a SPI/PPI/SGI may not be relevant.
Quoted 8 lines
Quoted 4 lines
While I agree the binding document may not contain specifics, I still don't see how to use SGI with this. Also note it's generally reserved for OS future use(IPC) and using this for other than IPC may be bit challenging IMO. It opens up lots of questions.
Well, a PPI might be possible to use, although it's somewhat dodgy to hijack the GIC's (re-)distributor from EL3 to write to GICD_ISPENDR<n>. Need to ask Marc about his feelings towards this. But it's definitely possible from a hypervisor to inject arbitrary interrupts into a guest.
But more importantly: is there any actual reason this needs to be a GIC interrupt? If I understand the code correctly, this could just be any interrupt, including one of an interrupt combiner or a GPIO chip. So why not just use the standard wording of: "exactly one interrupt specifier for each channel"?
That was my point, I am not stuck on using an SGI, or PPI, or anything (even if that's what we have been using at the moment), any interrupt would/should do here so the wording should be exactly as you indicated.
Signature · 1 line
Florian
RE: [PATCH V2 1/2] DT: mailbox: add binding doc for the ARM SMC mailbox
In reply to Andre PrzywaraQuoted 66 lines
Subject: Re: [PATCH V2 1/2] DT: mailbox: add binding doc for the ARM SMC mailbox
On Mon, 3 Jun 2019 17:56:51 +0100
Sudeep Holla <[email protected]> wrote:Hi,
Quoted 6 lines · Florian Fainelli
Quoted 5 lines · On 6/3/19 1:30 AM, [email protected] wrote:
Quoted 4 lines
From: Peng Fan <[email protected]>
The ARM SMC mailbox binding describes a firmware interface to trigger actions in software layers running in the EL2 or EL3 exception
levels.
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
The term "ARM" here relates to the SMC instruction as part of the ARM instruction set, not as a standard endorsed by ARM Ltd.
Signed-off-by Peng Fan <[email protected]>---
V2:
Introduce interrupts as a property.Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
V1:
arm,func-ids is still kept as an optional property, because there is no defined SMC funciton id passed from SCMI. So in my test, I still use arm,func-ids for ARM SIP service..../devicetree/bindings/mailbox/arm-smc.txt | 101+++++++++++++++++++++
Quoted 30 lines
Quoted 10 lines
Quoted 10 lines
1 file changed, 101 insertions(+) create mode 100644
Documentation/devicetree/bindings/mailbox/arm-smc.txtDocumentation/devicetree/bindings/mailbox/arm-smc.txt new file +0
-0@@ -0,0 +1,101 @@[...]
Quoted 7 lines
Quoted 7 lines
Documentation/devicetree/bindings/mailbox/arm-smc.txt new file +7
-0+Optional properties: +- arm,func-ids An array of 32-bit values specifying the function + IDs used by each mailbox channel. Those function IDs + follow the ARM SMC calling convention standard [1]. + There is one identifier per channel and the number + of supported channels is determined by the length + of this array.Quoted 9 lines
Documentation/devicetree/bindings/mailbox/arm-smc.txt line 58
Quoted 3 lines
+- interrupts SPI interrupts may be listed for notification,
Documentation/devicetree/bindings/mailbox/arm-smc.txt new file +2
-0+ each channel should use a dedicated interrupt + line.I would not go about defining a specific kind of interrupt, since SPI is a GIC terminology, this firmware interface could be used in premise with any parent interrupt controller, for which the concept of a SPI/PPI/SGI may not be relevant.
Quoted 4 lines
While I agree the binding document may not contain specifics, I still don't see how to use SGI with this. Also note it's generally reserved for OS future use(IPC) and using this for other than IPC may be bit challenging IMO. It opens up lots of questions.
Quoted 7 lines
Well, a PPI might be possible to use, although it's somewhat dodgy to hijack the GIC's (re-)distributor from EL3 to write to GICD_ISPENDR<n>. Need to ask Marc about his feelings towards this. But it's definitely possible from a hypervisor to inject arbitrary interrupts into a guest.
But more importantly: is there any actual reason this needs to be a GIC interrupt?
No. I just test ATF with SPI when I posting out this. Should not restrict to be GIC.
If I understand the code correctly, this could just be any interrupt,
Quoted 2 lines
including one of an interrupt combiner or a GPIO chip. So why not just use the standard wording of: "exactly one interrupt specifier for each channel"?
Agree.
Quoted 2 lines
By the way: Shouldn't new bindings use the YAML format instead?
I'll convert to YAML in next version.
Thanks,
Peng.
Quoted 3 lines
Cheers,
Andre.
RE: [PATCH V2 2/2] mailbox: introduce ARM SMC based mailbox
In reply to Florian FainelliQuoted 31 lines
Subject: Re: [PATCH V2 2/2] mailbox: introduce ARM SMC based mailbox
Quoted 12 lines · On 6/3/19 1:30 AM, [email protected] wrote:
From: Peng Fan <[email protected]>
This mailbox driver implements a mailbox which signals transmitted data via an ARM smc (secure monitor call) instruction. The mailbox receiver is implemented in firmware and can synchronously return data when it returns execution to the non-secure world again.
An asynchronous receive path is not implemented.
This allows the usage of a mailbox to trigger firmware actions on SoCs which either don't have a separate management processor or on which such a core is not available. A user of this mailbox could be the SCP interface.Quoted 3 lines
Modified from Andre Przywara's v2 patch
https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore
.kernel.org%2Fpatchwork%2Fpatch%2F812999%2F&data=02%7C01%7Cpeng.fa
Quoted 1 line
n%40nxp.com%7Caa396ba11ba244111fe408d6e8411fba%7C686ea1d3bc2b4
c6fa92cdQuoted 1 line
99c5c301635%7C0%7C0%7C636951763738548621&sdata=UlNESNg7I7 4TM9xp%2F
Quoted 5 lines
VMce4CSbMuJ95lh68cQw%2FnQMOw%3D&reserved=0
Cc Andre Przywara <[email protected]>Signed-off-by Peng Fan <[email protected]>---
Quoted 5 lines
[snip]
+#define
ARM_SMC_MBOX_USB_IRQBIT(1)That flag appears unused.
I'll remove this in V3.
Quoted 14 lines
drivers/mailbox/arm-smc-mailbox.c
Quoted 13 lines
drivers/mailbox/arm-smc-mailbox.c new file +12
-0+static int arm_smc_mbox_probe (struct platform_device *pdev) { +struct device *dev = &pdev->dev; +struct mbox_controller *mbox; +struct arm_smc_chan_data *chan_data; +const char *method; +bool use_hvc = false; +int ret, irq_count, i; +u32 val; + +if (!of_property_read_u32 (dev->of_node,"arm,num-chans" , &val)) { +if (val <1 || val >INT_MAX ) { + dev_err(dev, "invalid arm,num-chans value %u of %pOFn\n",val,
pdev->dev.of_node);
Quoted 6 lines
drivers/mailbox/arm-smc-mailbox.c line 80
Quoted 3 lines
drivers/mailbox/arm-smc-mailbox.c new file +3
-0+return -EINVAL ; + } + }Should not the upper bound check be done against
UINT_MAXsince val is an unsigned int?
Fix in V3.
Quoted 11 lines
drivers/mailbox/arm-smc-mailbox.c line 87
Quoted 8 lines
drivers/mailbox/arm-smc-mailbox.c new file +7
-0+ + irq_count =platform_irq_count (pdev); +if (irq_count == -EPROBE_DEFER ) +return irq_count; + +if (irq_count && irq_count != val) { +dev_err (dev,"Interrupts not match num-chans\n" );Interrupts property does not match \"arm,num-chans\" would be more correct.
Fix in V3.
Quoted 14 lines
Quoted 14 lines
drivers/mailbox/arm-smc-mailbox.c new file +13
-0+return -EINVAL ; + } + +if (!of_property_read_string (dev->of_node,"method" , &method)) { +if (!strcmp ("hvc" , method)) { + use_hvc = true; + }else if (!strcmp ("smc" , method)) { + use_hvc = false; + }else { +dev_warn (dev,"invalid \"method\" property: %s\n" , + method); + +return -EINVAL ;
Quoted 8 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ }Having at least one method specified does not seem to be checked later on in the code, so if I omitted to specify that property, we would still register the mailbox and default to use "smc" since the
ARM_SMC_MBOX_USE_HVCflag would not be set, would not we want to make sure that we do have in fact a valid method specified given the binding documents that property as mandatory?
When arm_smc_send_data, it will check ARM_SMC_MBOX_USE_HVC, you mean there are other places needs this flag check?
Quoted 17 lines
[snip]
drivers/mailbox/arm-smc-mailbox.c line 157
Quoted 10 lines
drivers/mailbox/arm-smc-mailbox.c new file +10
-0+ mbox->txdone_poll = false; + mbox->txdone_irq = false; + mbox->ops = &arm_smc_mbox_chan_ops; + mbox->dev = dev; + + ret =mbox_controller_register (mbox); +if (ret) +return ret; + +platform_set_drvdata (pdev, mbox);I would move this above
mbox_controller_register()that way there is no room for race conditions in case another part of the driver expects to havepdev->dev.drvdataset before the mbox controller is registered.
Right.
Quoted 2 lines
Since you use devm_* functions for everything, you may even remove that call.
You mean remove " platform_set_drvdata(pdev, mbox);" ?
Quoted 12 lines
[snip]
include/linux/mailbox/arm-smc-mailbox.h
Quoted 5 lines
include/linux/mailbox/arm-smc-mailbox.h new file +5
-0+#ifndef _LINUX_ARM_SMC_MAILBOX_H_ +#define _LINUX_ARM_SMC_MAILBOX_H_ + +struct arm_smccc_mbox_cmd { +unsigned long a0, a1, a2, a3, a4, a5, a6, a7; };Do you expect this to be used by other in-kernel users? If so, it might be good to document how a0 can have a special meaning and be used as a substitute for the
function_id?
This was to address comments here:
https://lore.kernel.org/patchwork/patch/812999/#1010433
Thanks,
Peng.
Quoted 2 lines
--
Florian
Re: [PATCH V2 2/2] mailbox: introduce ARM SMC based mailbox
In reply to Florian FainelliOn Mon, 3 Jun 2019 09:32:42 -0700
Florian Fainelli <[email protected]> wrote:
Hi,
Quoted 26 lines · On 6/3/19 1:30 AM, [email protected] wrote:
Quoted 12 lines
From: Peng Fan <[email protected]>
This mailbox driver implements a mailbox which signals transmitted data via an ARM smc (secure monitor call) instruction. The mailbox receiver is implemented in firmware and can synchronously return data when it returns execution to the non-secure world again.
An asynchronous receive path is not implemented.
This allows the usage of a mailbox to trigger firmware actions on SoCs which either don't have a separate management processor or on which such a core is not available. A user of this mailbox could be the SCP interface.Quoted 6 lines
Modified from Andre Przywara's v2 patch
https://lore.kernel.org/patchwork/patch/812999/Cc Andre Przywara <[email protected]>Signed-off-by Peng Fan <[email protected]>---
[snip]
+#define
ARM_SMC_MBOX_USB_IRQBIT(1)That flag appears unused.
Quoted 13 lines
drivers/mailbox/arm-smc-mailbox.c line 77
Quoted 13 lines
drivers/mailbox/arm-smc-mailbox.c new file +13
-0+static int arm_smc_mbox_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct mbox_controller *mbox; +struct arm_smc_chan_data *chan_data; +const char *method; +bool use_hvc = false; +int ret, irq_count, i; +u32 val; + +if (!of_property_read_u32 (dev->of_node,"arm,num-chans" , &val)) { +if (val <1 || val >INT_MAX ) { +dev_err (dev,"invalid arm,num-chans value %u of %pOFn\n" , val, pdev->dev.of_node);
Isn't the of_node parameter redundant, because dev_err() already takes care of that?
Quoted 6 lines
drivers/mailbox/arm-smc-mailbox.c line 80
Quoted 3 lines
drivers/mailbox/arm-smc-mailbox.c new file +3
-0+return -EINVAL ; + } + }Should not the upper bound check be done against
UINT_MAXsince val is an unsigned int?
But wouldn't that be somewhat pointless, given that val is a u32? So I guess we could just condense this down to:
...
if (!val) {...
Quoted 9 lines
drivers/mailbox/arm-smc-mailbox.c line 87
Quoted 7 lines
drivers/mailbox/arm-smc-mailbox.c new file +7
-0+ + irq_count =platform_irq_count (pdev); +if (irq_count == -EPROBE_DEFER ) +return irq_count; + +if (irq_count && irq_count != val) { +dev_err (dev,"Interrupts not match num-chans\n" );Interrupts property does not match \"arm,num-chans\" would be more correct.
Given that interrupts are optional, do we have to rely on this? Do we actually need one interrupt per channel?
Quoted 43 lines
Quoted 4 lines
drivers/mailbox/arm-smc-mailbox.c new file +4
-0+return -EINVAL ; + } + +if (!of_property_read_string (dev->of_node,"method" , &method)) {drivers/mailbox/arm-smc-mailbox.c line 101
Quoted 10 lines
drivers/mailbox/arm-smc-mailbox.c new file +10
-0+if (!strcmp ("hvc" , method)) { + use_hvc = true; + }else if (!strcmp ("smc" , method)) { + use_hvc = false; + }else { +dev_warn (dev,"invalid \"method\" property: %s\n" , + method); + +return -EINVAL ; + }Having at least one method specified does not seem to be checked later on in the code, so if I omitted to specify that property, we would still register the mailbox and default to use "smc" since the
ARM_SMC_MBOX_USE_HVCflag would not be set, would not we want to make sure that we do have in fact a valid method specified given the binding documents that property as mandatory?[snip]
drivers/mailbox/arm-smc-mailbox.c line 157
Quoted 10 lines
drivers/mailbox/arm-smc-mailbox.c new file +10
-0+ mbox->txdone_poll = false; + mbox->txdone_irq = false; + mbox->ops = &arm_smc_mbox_chan_ops; + mbox->dev = dev; + + ret =mbox_controller_register (mbox); +if (ret) +return ret; + +platform_set_drvdata (pdev, mbox);I would move this above
mbox_controller_register()that way there is no room for race conditions in case another part of the driver expects to havepdev->dev.drvdataset before the mbox controller is registered. Since you use devm_* functions for everything, you may even remove that call.[snip]
Quoted 10 lines
include/linux/mailbox/arm-smc-mailbox.h line 8
Quoted 6 lines
include/linux/mailbox/arm-smc-mailbox.h new file +6
-0+#ifndef _LINUX_ARM_SMC_MAILBOX_H_ +#define _LINUX_ARM_SMC_MAILBOX_H_ + +struct arm_smccc_mbox_cmd { +unsigned long a0, a1, a2, a3, a4, a5, a6, a7; +};Do you expect this to be used by other in-kernel users? If so, it might be good to document how a0 can have a special meaning and be used as a substitute for the
function_id?
I don't think we should really expose this outside of the driver. From a mailbox point of view this is just the payload, transported according to the SMCCC. Also using "long" here sounds somewhat troublesome.
Also, looking at the SMCCC, I only see six parameters in addition to the function identifier. Shall we reflect this here?
Cheers,
Andre.
RE: [PATCH V2 2/2] mailbox: introduce ARM SMC based mailbox
Hi Andre,
Quoted 56 lines
Subject: Re: [PATCH V2 2/2] mailbox: introduce ARM SMC based mailbox
On Mon, 3 Jun 2019 09:32:42 -0700
Florian Fainelli <[email protected]> wrote:Hi,
Quoted 13 lines · On 6/3/19 1:30 AM, [email protected] wrote:
Quoted 12 lines
From: Peng Fan <[email protected]>
This mailbox driver implements a mailbox which signals transmitted data via an ARM smc (secure monitor call) instruction. The mailbox receiver is implemented in firmware and can synchronously return data when it returns execution to the non-secure world again. An asynchronous receive path is not implemented.
This allows the usage of a mailbox to trigger firmware actions on SoCs which either don't have a separate management processor or on which such a core is not available. A user of this mailbox could be the SCP interface.Quoted 3 lines
Quoted 3 lines
Modified from Andre Przywara's v2 patch
https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Fpatchwork%2Fpatch%2F812999%2F&data=02%7C01% 7Cpen
Quoted 1 line
Quoted 1 line
g.fan%40nxp.com%7C15c4180b8fe5405d3de808d6ea81d5f1%7C686ea1d3bc 2b4c6
Quoted 1 line
Quoted 1 line
fa92cd99c5c301635%7C0%7C0%7C636954240720601454&sdata=1Cp WSgTH7lF
Quoted 12 lines
Quoted 5 lines
cBKxJnLeIDw%2FDAQJJO%2FVypV1LUU1BRQA%3D&reserved=0
Cc Andre Przywara <[email protected]>Signed-off-by Peng Fan <[email protected]>---
[snip]
+#define
ARM_SMC_MBOX_USB_IRQBIT(1)That flag appears unused.
Quoted 12 lines
drivers/mailbox/arm-smc-mailbox.c
Quoted 12 lines
drivers/mailbox/arm-smc-mailbox.c new file +12
-0+static int arm_smc_mbox_probe (struct platform_device *pdev) { +struct device *dev = &pdev->dev; +struct mbox_controller *mbox; +struct arm_smc_chan_data *chan_data; +const char *method; +bool use_hvc = false; +int ret, irq_count, i; +u32 val; + +if (!of_property_read_u32 (dev->of_node,"arm,num-chans" , &val)) { +if (val <1 || val >INT_MAX ) { + dev_err(dev, "invalid arm,num-chans value %uof %pOFn\n", val,
Quoted 4 lines
Quoted 1 line
Quoted 1 line
+pdev->dev.of_node);
Isn't the
of_nodeparameter redundant, becausedev_err()already takes care of that?
I'll remove that.
Quoted 8 lines
Quoted 7 lines
drivers/mailbox/arm-smc-mailbox.c line 80
Quoted 4 lines
drivers/mailbox/arm-smc-mailbox.c new file +3
-0+return -EINVAL ; + } + }Should not the upper bound check be done against
UINT_MAXsince val is an unsigned int?
Quoted 5 lines
But wouldn't that be somewhat pointless, given that val is a u32? So I guess we could just condense this down to:
...if (!val) {...
make sense.
Quoted 10 lines
Quoted 10 lines
drivers/mailbox/arm-smc-mailbox.c line 87
Quoted 8 lines
drivers/mailbox/arm-smc-mailbox.c new file +7
-0+ + irq_count =platform_irq_count (pdev); +if (irq_count == -EPROBE_DEFER ) +return irq_count; + +if (irq_count && irq_count != val) { +dev_err (dev,"Interrupts not match num-chans\n" );Interrupts property does not match \"arm,num-chans\" would be more
Quoted 3 lines
correct.
Given that interrupts are optional, do we have to rely on this?
If there is interrupt property, the interrupts should match channel counts.
Do we actually
Quoted 1 line
need one interrupt per channel?
I thought about this, provide one interrupt for all channels. But there is no good way to let interrupt handlers know which channel triggers the interrupt. So I use one interrupt per channel.
Quoted 55 lines
Quoted 12 lines
Quoted 12 lines
drivers/mailbox/arm-smc-mailbox.c new file +11
-0+return -EINVAL ; + } + +if (!of_property_read_string (dev->of_node,"method" , &method)) { +if (!strcmp ("hvc" , method)) { + use_hvc = true; + }else if (!strcmp ("smc" , method)) { + use_hvc = false; + }else { +dev_warn (dev,"invalid \"method\" property: %s\n" , + method);Quoted 8 lines
drivers/mailbox/arm-smc-mailbox.c line 79
Quoted 3 lines
drivers/mailbox/arm-smc-mailbox.c new file +3
-0+ +return -EINVAL ; + }Having at least one method specified does not seem to be checked later on in the code, so if I omitted to specify that property, we would still register the mailbox and default to use "smc" since the
ARM_SMC_MBOX_USE_HVCflag would not be set, would not we want tomake
Quoted 24 lines
sure that we do have in fact a valid method specified given the binding documents that property as mandatory?
[snip]
drivers/mailbox/arm-smc-mailbox.c line 157
Quoted 10 lines
drivers/mailbox/arm-smc-mailbox.c new file +10
-0+ mbox->txdone_poll = false; + mbox->txdone_irq = false; + mbox->ops = &arm_smc_mbox_chan_ops; + mbox->dev = dev; + + ret =mbox_controller_register (mbox); +if (ret) +return ret; + +platform_set_drvdata (pdev, mbox);I would move this above
mbox_controller_register()that way there is no room for race conditions in case another part of the driver expects to havepdev->dev.drvdataset before the mbox controller is registered. Since you use devm_* functions for everything, you may even remove that call.[snip]
Quoted 9 lines
include/linux/mailbox/arm-smc-mailbox.h
Quoted 5 lines
include/linux/mailbox/arm-smc-mailbox.h new file +5
-0+#ifndef _LINUX_ARM_SMC_MAILBOX_H_ +#define _LINUX_ARM_SMC_MAILBOX_H_ + +struct arm_smccc_mbox_cmd { +unsigned long a0, a1, a2, a3, a4, a5, a6, a7; };Do you expect this to be used by other in-kernel users? If so, it might be good to document how a0 can have a special meaning and be used as a substitute for the
function_id?
Quoted 6 lines
I don't think we should really expose this outside of the driver. From a mailbox point of view this is just the payload, transported according to the SMCCC. Also using "long" here sounds somewhat troublesome.
Also, looking at the SMCCC, I only see six parameters in addition to the function identifier. Shall we reflect this here?
I could move it to driver code. Jassi, do you have any comments?
Thanks,
Peng.
Quoted 3 lines
Cheers,
Andre.
Re: [PATCH V2 2/2] mailbox: introduce ARM SMC based mailbox
On Mon, 10 Jun 2019 01:32:49 +0000
Peng Fan <[email protected]> wrote:
Hi Peng,
[ ... ]
Quoted 13 lines
Quoted 9 lines
Quoted 9 lines
drivers/mailbox/arm-smc-mailbox.c line 87
Quoted 7 lines
drivers/mailbox/arm-smc-mailbox.c new file +7
-0+ + irq_count =platform_irq_count (pdev); +if (irq_count == -EPROBE_DEFER ) +return irq_count; + +if (irq_count && irq_count != val) { +dev_err (dev,"Interrupts not match num-chans\n" );Interrupts property does not match \"arm,num-chans\" would be more
Quoted 3 lines
correct.
Given that interrupts are optional, do we have to rely on this?
Quoted 8 lines
If there is interrupt property, the interrupts should match channel counts.
Do we actually
Quoted 1 line
need one interrupt per channel?
I thought about this, provide one interrupt for all channels. But there is no good way to let interrupt handlers know which channel triggers the interrupt. So I use one interrupt per channel.
Yeah, I was wondering about this as well. Seems like we need this indeed. Just sounds wasteful, but I guess we don't expect many channels anyway, normally.
Cheers,
Andre.
RE: [PATCH V2 2/2] mailbox: introduce ARM SMC based mailbox
In reply to Peng FanHi Andre,
Quoted 164 lines
Subject: RE: [PATCH V2 2/2] mailbox: introduce ARM SMC based mailbox
Hi Andre,
Quoted 25 lines
Subject: Re: [PATCH V2 2/2] mailbox: introduce ARM SMC based mailbox
On Mon, 3 Jun 2019 09:32:42 -0700
Florian Fainelli <[email protected]> wrote:Hi,
Quoted 17 lines · On 6/3/19 1:30 AM, [email protected] wrote:
Quoted 16 lines
From: Peng Fan <[email protected]>
This mailbox driver implements a mailbox which signals transmitted data via an ARM smc (secure monitor call) instruction. The mailbox receiver is implemented in firmware and can synchronously return data when it returns execution to the non-secure world again. An asynchronous receive path is not implemented.
This allows the usage of a mailbox to trigger firmware actions on SoCs which either don't have a separate management processor or on which such a core is not available. A user of this mailbox could be the SCP interface.Modified from Andre Przywara's v2 patch
https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2F
lore.kernel.org%2Fpatchwork%2Fpatch%2F812999%2F&data=02%7C01%
Quoted 3 lines
7Cpen
Quoted 1 line
Quoted 1 line
g.fan%40nxp.com%7C15c4180b8fe5405d3de808d6ea81d5f1%7C686ea1d3bc
Quoted 29 lines
2b4c6
Quoted 1 line
Quoted 1 line
fa92cd99c5c301635%7C0%7C0%7C636954240720601454&sdata=1Cp WSgTH7lF
Quoted 12 lines
Quoted 5 lines
cBKxJnLeIDw%2FDAQJJO%2FVypV1LUU1BRQA%3D&reserved=0
Cc Andre Przywara <[email protected]>Signed-off-by Peng Fan <[email protected]>---
[snip]
+#define
ARM_SMC_MBOX_USB_IRQBIT(1)That flag appears unused.
Quoted 12 lines
drivers/mailbox/arm-smc-mailbox.c
Quoted 12 lines
drivers/mailbox/arm-smc-mailbox.c new file +12
-0+static int arm_smc_mbox_probe (struct platform_device *pdev) { +struct device *dev = &pdev->dev; +struct mbox_controller *mbox; +struct arm_smc_chan_data *chan_data; +const char *method; +bool use_hvc = false; +int ret, irq_count, i; +u32 val; + +if (!of_property_read_u32 (dev->of_node,"arm,num-chans" , &val)) { +if (val <1 || val >INT_MAX ) { + dev_err(dev, "invalid arm,num-chans value %uof %pOFn\n", val,
Quoted 4 lines
Quoted 1 line
Quoted 1 line
+pdev->dev.of_node);
Isn't the
of_nodeparameter redundant, becausedev_err()already takes care of that?I'll remove that.
Quoted 8 lines
Quoted 7 lines
drivers/mailbox/arm-smc-mailbox.c line 80
Quoted 4 lines
drivers/mailbox/arm-smc-mailbox.c new file +3
-0+return -EINVAL ; + } + }Should not the upper bound check be done against
UINT_MAXsince val is an unsigned int?Quoted 5 lines
But wouldn't that be somewhat pointless, given that val is a u32? So I guess we could just condense this down to:
...if (!val) {...
make sense.
Quoted 10 lines
Quoted 10 lines
drivers/mailbox/arm-smc-mailbox.c line 87
Quoted 8 lines
drivers/mailbox/arm-smc-mailbox.c new file +7
-0+ + irq_count =platform_irq_count (pdev); +if (irq_count == -EPROBE_DEFER ) +return irq_count; + +if (irq_count && irq_count != val) { +dev_err (dev,"Interrupts not match num-chans\n" );Interrupts property does not match \"arm,num-chans\" would be more
Quoted 3 lines
correct.
Given that interrupts are optional, do we have to rely on this?
If there is interrupt property, the interrupts should match channel counts.
Do we actually
Quoted 1 line
need one interrupt per channel?
I thought about this, provide one interrupt for all channels. But there is no good way to let interrupt handlers know which channel triggers the interrupt. So I use one interrupt per channel.
Quoted 20 lines
Quoted 12 lines
Quoted 12 lines
drivers/mailbox/arm-smc-mailbox.c new file +11
-0+return -EINVAL ; + } + +if (!of_property_read_string (dev->of_node,"method" , &method)) { +if (!strcmp ("hvc" , method)) { + use_hvc = true; + }else if (!strcmp ("smc" , method)) { + use_hvc = false; + }else { +dev_warn (dev,"invalid \"method\" property: %s\n" , + method);Quoted 8 lines
drivers/mailbox/arm-smc-mailbox.c line 79
Quoted 3 lines
drivers/mailbox/arm-smc-mailbox.c new file +3
-0+ +return -EINVAL ; + }Having at least one method specified does not seem to be checked later on in the code, so if I omitted to specify that property, we would still register the mailbox and default to use "smc" since the
ARM_SMC_MBOX_USE_HVCflag would not be set, would not we want toQuoted 20 lines
make
Quoted 19 lines
sure that we do have in fact a valid method specified given the binding documents that property as mandatory?
[snip]
drivers/mailbox/arm-smc-mailbox.c line 157
Quoted 10 lines
drivers/mailbox/arm-smc-mailbox.c new file +10
-0+ mbox->txdone_poll = false; + mbox->txdone_irq = false; + mbox->ops = &arm_smc_mbox_chan_ops; + mbox->dev = dev; + + ret =mbox_controller_register (mbox); +if (ret) +return ret; + +platform_set_drvdata (pdev, mbox);I would move this above
mbox_controller_register()that way there is no room for race conditions in case another part of the driver expects to havepdev->dev.drvdataset before the mbox controller isregistered.
Quoted 15 lines
Quoted 14 lines
Since you use devm_* functions for everything, you may even remove that call.
[snip]
Review
Quoted 5 lines
(quoted diff) +5
-0+#ifndef _LINUX_ARM_SMC_MAILBOX_H_ #define +_LINUX_ARM_SMC_MAILBOX_H_ + +struct arm_smccc_mbox_cmd { + unsigned long a0, a1, a2, a3, a4, a5, a6, a7; };Do you expect this to be used by other in-kernel users? If so, it might be good to document how a0 can have a special meaning and be used as a substitute for the
function_id?
Quoted 4 lines
Quoted 2 lines
I don't think we should really expose this outside of the driver. From a mailbox point of view this is just the payload, transported according to the
SMCCC.
Quoted 1 line
Also using "long" here sounds somewhat troublesome.
Long on ARM64 is 64bit, and 32bit on ARM32, so I use long. Do you forsee any issues?
Quoted 3 lines
Quoted 3 lines
Also, looking at the SMCCC, I only see six parameters in addition to the function identifier. Shall we reflect this here?
a0 is used as function id, not no arm,func-ids provided in dts. a1-a7 are also passed to smc.
If arm,func-ids is provided, a0 will be omitted just for consistency as above.
You mean write comments in the code for it?
Thanks,
Peng.
Quoted 9 lines
I could move it to driver code. Jassi, do you have any comments?
Thanks,
Peng.Quoted 3 lines
Cheers,
Andre.
Re: [PATCH V2 2/2] mailbox: introduce ARM SMC based mailbox
On Wed, 12 Jun 2019 12:59:04 +0000
Peng Fan <[email protected]> wrote:
Hi,
Quoted 164 lines
Quoted 164 lines
Subject: RE: [PATCH V2 2/2] mailbox: introduce ARM SMC based mailbox
Hi Andre,
Quoted 25 lines
Subject: Re: [PATCH V2 2/2] mailbox: introduce ARM SMC based mailbox
On Mon, 3 Jun 2019 09:32:42 -0700
Florian Fainelli <[email protected]> wrote:Hi,
Quoted 17 lines · On 6/3/19 1:30 AM, [email protected] wrote:
Quoted 16 lines
From: Peng Fan <[email protected]>
This mailbox driver implements a mailbox which signals transmitted data via an ARM smc (secure monitor call) instruction. The mailbox receiver is implemented in firmware and can synchronously return data when it returns execution to the non-secure world again. An asynchronous receive path is not implemented.
This allows the usage of a mailbox to trigger firmware actions on SoCs which either don't have a separate management processor or on which such a core is not available. A user of this mailbox could be the SCP interface.Modified from Andre Przywara's v2 patch
https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2F
lore.kernel.org%2Fpatchwork%2Fpatch%2F812999%2F&data=02%7C01%
Quoted 3 lines
7Cpen
Quoted 1 line
Quoted 1 line
g.fan%40nxp.com%7C15c4180b8fe5405d3de808d6ea81d5f1%7C686ea1d3bc
Quoted 29 lines
2b4c6
Quoted 1 line
Quoted 1 line
fa92cd99c5c301635%7C0%7C0%7C636954240720601454&sdata=1Cp WSgTH7lF
Quoted 12 lines
Quoted 5 lines
cBKxJnLeIDw%2FDAQJJO%2FVypV1LUU1BRQA%3D&reserved=0
Cc Andre Przywara <[email protected]>Signed-off-by Peng Fan <[email protected]>---
[snip]
+#define
ARM_SMC_MBOX_USB_IRQBIT(1)That flag appears unused.
Quoted 12 lines
drivers/mailbox/arm-smc-mailbox.c
Quoted 12 lines
drivers/mailbox/arm-smc-mailbox.c new file +12
-0+static int arm_smc_mbox_probe (struct platform_device *pdev) { +struct device *dev = &pdev->dev; +struct mbox_controller *mbox; +struct arm_smc_chan_data *chan_data; +const char *method; +bool use_hvc = false; +int ret, irq_count, i; +u32 val; + +if (!of_property_read_u32 (dev->of_node,"arm,num-chans" , &val)) { +if (val <1 || val >INT_MAX ) { + dev_err(dev, "invalid arm,num-chans value %uof %pOFn\n", val,
Quoted 4 lines
Quoted 1 line
Quoted 1 line
+pdev->dev.of_node);
Isn't the
of_nodeparameter redundant, becausedev_err()already takes care of that?I'll remove that.
Quoted 8 lines
Quoted 7 lines
drivers/mailbox/arm-smc-mailbox.c line 80
Quoted 4 lines
drivers/mailbox/arm-smc-mailbox.c new file +3
-0+return -EINVAL ; + } + }Should not the upper bound check be done against
UINT_MAXsince val is an unsigned int?Quoted 5 lines
But wouldn't that be somewhat pointless, given that val is a u32? So I guess we could just condense this down to:
...if (!val) {...
make sense.
Quoted 10 lines
Quoted 10 lines
drivers/mailbox/arm-smc-mailbox.c line 87
Quoted 8 lines
drivers/mailbox/arm-smc-mailbox.c new file +7
-0+ + irq_count =platform_irq_count (pdev); +if (irq_count == -EPROBE_DEFER ) +return irq_count; + +if (irq_count && irq_count != val) { +dev_err (dev,"Interrupts not match num-chans\n" );Interrupts property does not match \"arm,num-chans\" would be more
Quoted 3 lines
correct.
Given that interrupts are optional, do we have to rely on this?
If there is interrupt property, the interrupts should match channel counts.
Do we actually
Quoted 1 line
need one interrupt per channel?
I thought about this, provide one interrupt for all channels. But there is no good way to let interrupt handlers know which channel triggers the interrupt. So I use one interrupt per channel.
Quoted 20 lines
Quoted 12 lines
Quoted 12 lines
drivers/mailbox/arm-smc-mailbox.c new file +11
-0+return -EINVAL ; + } + +if (!of_property_read_string (dev->of_node,"method" , &method)) { +if (!strcmp ("hvc" , method)) { + use_hvc = true; + }else if (!strcmp ("smc" , method)) { + use_hvc = false; + }else { +dev_warn (dev,"invalid \"method\" property: %s\n" , + method);Quoted 8 lines
drivers/mailbox/arm-smc-mailbox.c line 79
Quoted 3 lines
drivers/mailbox/arm-smc-mailbox.c new file +3
-0+ +return -EINVAL ; + }Having at least one method specified does not seem to be checked later on in the code, so if I omitted to specify that property, we would still register the mailbox and default to use "smc" since the
ARM_SMC_MBOX_USE_HVCflag would not be set, would not we want toQuoted 20 lines
make
Quoted 19 lines
sure that we do have in fact a valid method specified given the binding documents that property as mandatory?
[snip]
drivers/mailbox/arm-smc-mailbox.c line 157
Quoted 10 lines
drivers/mailbox/arm-smc-mailbox.c new file +10
-0+ mbox->txdone_poll = false; + mbox->txdone_irq = false; + mbox->ops = &arm_smc_mbox_chan_ops; + mbox->dev = dev; + + ret =mbox_controller_register (mbox); +if (ret) +return ret; + +platform_set_drvdata (pdev, mbox);I would move this above
mbox_controller_register()that way there is no room for race conditions in case another part of the driver expects to havepdev->dev.drvdataset before the mbox controller isregistered.
Quoted 15 lines
Quoted 14 lines
Since you use devm_* functions for everything, you may even remove that call.
[snip]
Review
Quoted 5 lines
(quoted diff) +5
-0+#ifndef _LINUX_ARM_SMC_MAILBOX_H_ #define +_LINUX_ARM_SMC_MAILBOX_H_ + +struct arm_smccc_mbox_cmd { + unsigned long a0, a1, a2, a3, a4, a5, a6, a7; };Do you expect this to be used by other in-kernel users? If so, it might be good to document how a0 can have a special meaning and be used as a substitute for the
function_id?
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
I don't think we should really expose this outside of the driver. From a mailbox point of view this is just the payload, transported according to the
SMCCC.
Quoted 1 line
Also using "long" here sounds somewhat troublesome.
Long on ARM64 is 64bit, and 32bit on ARM32, so I use long. Do you forsee any issues?
Yes, because having different sizes depending on the underlying instruction set asks for trouble when talking about protocols. If I compile a kernel with this driver once for arm(32) and once for arm64 and run it on the same machine with the same firmware, does that behave differently? Not saying it's impossible to handle, but we should make sure there is no ambiguity.
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
Also, looking at the SMCCC, I only see six parameters in addition to the function identifier. Shall we reflect this here?
a0 is used as function id, not no arm,func-ids provided in dts. a1-a7 are also passed to smc.
Yes, so those are *7* parameters on top of the function IDs, whereas the SMCCC only speaks of 6:
"When the SMC64/HVC64 convention is used, the SMC or HVC instruction takes up to six 64-bit arguments in registers ..."
"When the SMC32/HVC32 convention is used, an SMC or HVC instruction takes a Function Identifier and up to six 32-bit register values as arguments, ..."
Quoted 3 lines
If arm,func-ids is provided, a0 will be omitted just for consistency as above.
You mean write comments in the code for it?
I think we should prevent people expecting anything useful to happen with the seventh argument.
Cheers,
Andre
Re: [PATCH V2 1/2] DT: mailbox: add binding doc for the ARM SMC mailbox
In reply to [email protected]Quoted 77 lines · On Mon, Jun 03, 2019 at 04:30:04PM +0800, [email protected] wrote:
From: Peng Fan <[email protected]>
The ARM SMC mailbox binding describes a firmware interface to trigger actions in software layers running in the EL2 or EL3 exception levels. The term "ARM" here relates to the SMC instruction as part of the ARM instruction set, not as a standard endorsed by ARM Ltd.
Signed-off-by Peng Fan <[email protected]>---
V2:
Introduce interrupts as a property.V1:
arm,func-ids is still kept as an optional property, because there is no defined SMC funciton id passed from SCMI. So in my test, I still use arm,func-ids for ARM SIP service..../devicetree/bindings/mailbox/arm-smc.txt | 101 +++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 Documentation/devicetree/bindings/mailbox/arm-smc.txtDocumentation/devicetree/bindings/mailbox/arm-smc.txt new file +49
-0@@ -0,0 +1,101 @@ +ARM SMC Mailbox Interface +========================= + +This mailbox uses the ARM smc (secure monitor call) instruction to trigger +a mailbox-connected activity in firmware, executing on the very same core +as the caller. By nature this operation is synchronous and this mailbox +provides no way for asynchronous messages to be delivered the other way +round, from firmware to the OS, but asynchronous notification could also +be supported. However the value of r0/w0/x0 the firmware returns after +the smc call is delivered as a received message to the mailbox framework, +so a synchronous communication can be established, for a asynchronous +notification, no value will be returned. The exact meaning of both the +action the mailbox triggers as well as the return value is defined by +their users and is not subject to this binding. + +One use case of this mailbox is the SCMI interface, which uses shared memory +to transfer commands and parameters, and a mailbox to trigger a function +call. This allows SoCs without a separate management processor (or when +such a processor is not available or used) to use this standardized +interface anyway. + +This binding describes no hardware, but establishes a firmware interface. +Upon receiving an SMC using one of the described SMC function identifiers, +the firmware is expected to trigger some mailbox connected functionality. +The communication follows the ARM SMC calling convention[1]. +Firmware expects an SMC function identifier in r0 or w0. The supported +identifiers are passed from consumers, or listed in the the arm,func-ids +properties as described below. The firmware can return one value in +the first SMC result register, it is expected to be an error value, +which shall be propagated to the mailbox client. + +Any core which supports the SMC or HVC instruction can be used, as long as +a firmware component running in EL3 or EL2 is handling these calls. + +Mailbox Device Node: +==================== + +This node is expected to be a child of the /firmware node. + +Required properties: +-------------------- +- compatible: Shall be "arm,smc-mbox" +- #mbox-cells Shall be 1 - the index of the channel needed. +- arm,num-chans The number of channels supported. +- method: A string, either: + "hvc": if the driver shall use an HVC call, or + "smc": if the driver shall use an SMC call. + +Optional properties:
Documentation/devicetree/bindings/mailbox/arm-smc.txt line 59
Quoted 10 lines
Documentation/devicetree/bindings/mailbox/arm-smc.txt new file +10
-0+- arm,func-ids An array of 32-bit values specifying the function + IDs used by each mailbox channel. Those function IDs + follow the ARM SMC calling convention standard [1]. + There is one identifier per channel and the number + of supported channels is determined by the length + of this array. +- interrupts SPI interrupts may be listed for notification, + each channel should use a dedicated interrupt + line. +
I think SMC mailbox as mostly unidirectional/Tx only channel. And the interrupts here as stated are for notifications, so I prefer to keep them separate channel. I assume SMC call return indicates completion. Or do you plan to use these interrupts as the indication for completion of the command? I see in patch 2/2 the absence of IRQ is anyway dealt the way I mention above.
Does it make sense or am I missing something here ?
--
Regards,
Sudeep
Re: [PATCH V2 2/2] mailbox: introduce ARM SMC based mailbox
In reply to [email protected]Quoted 100 lines · On Mon, Jun 03, 2019 at 04:30:05PM +0800, [email protected] wrote:
From: Peng Fan <[email protected]>
This mailbox driver implements a mailbox which signals transmitted data via an ARM smc (secure monitor call) instruction. The mailbox receiver is implemented in firmware and can synchronously return data when it returns execution to the non-secure world again.
An asynchronous receive path is not implemented.
This allows the usage of a mailbox to trigger firmware actions on SoCs which either don't have a separate management processor or on which such a core is not available. A user of this mailbox could be the SCP interface.Modified from Andre Przywara's v2 patch
https://lore.kernel.org/patchwork/patch/812999/Cc Andre Przywara <[email protected]>Signed-off-by Peng Fan <[email protected]>---
V2:
Add interrupts notification support.drivers/mailbox/Kconfig | 7 ++ drivers/mailbox/Makefile | 2 + drivers/mailbox/arm-smc-mailbox.c | 190 ++++++++++++++++++++++++++++++++ include/linux/mailbox/arm-smc-mailbox.h | 10 ++ 4 files changed, 209 insertions(+) create mode 100644 drivers/mailbox/arm-smc-mailbox.c create mode 100644 include/linux/mailbox/arm-smc-mailbox.hdrivers/mailbox/Kconfig +7
-0@@ -15,6 +15,13 @@ config ARM_MHU The controller has 3 mailbox channels, the last of which can be used in Secure mode only. +config ARM_SMC_MBOX + tristate "Generic ARM smc mailbox" + depends on OF && HAVE_ARM_SMCCC + help + Generic mailbox driver which uses ARM smc calls to call into + firmware for triggering mailboxes. + config IMX_MBOX tristate "i.MX Mailbox" depends on ARCH_MXC || COMPILE_TESTdrivers/mailbox/Makefile +2
-0@@ -7,6 +7,8 @@ obj-$(CONFIG_MAILBOX_TEST) += mailbox-test.o obj-$(CONFIG_ARM_MHU) += arm_mhu.o +obj-$(CONFIG_ARM_SMC_MBOX) += arm-smc-mailbox.o + obj-$(CONFIG_IMX_MBOX) += imx-mailbox.o obj-$(CONFIG_ARMADA_37XX_RWTM_MBOX) += armada-37xx-rwtm-mailbox.odrivers/mailbox/arm-smc-mailbox.c new file +33
-0@@ -0,0 +1,190 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2016,2017 ARM Ltd. +* Copyright 2019 NXP +*/ + +#include <linux/arm-smccc.h> +#include <linux/device.h> +#include <linux/kernel.h> +#include <linux/interrupt.h> +#include <linux/mailbox_controller.h> +#include <linux/mailbox/arm-smc-mailbox.h> +#include <linux/module.h> +#include <linux/platform_device.h> + +#define ARM_SMC_MBOX_USE_HVC BIT(0) +#define ARM_SMC_MBOX_USB_IRQ BIT(1) + +struct arm_smc_chan_data { +u32 function_id; +u32 flags; +int irq; +}; + +static int arm_smc_send_data (struct mbox_chan *link,void *data) +{ +struct arm_smc_chan_data *chan_data = link->con_priv; +struct arm_smccc_mbox_cmd *cmd = data; +struct arm_smccc_res res; +u32 function_id; + +if (chan_data->function_id !=UINT_MAX ) + function_id = chan_data->function_id;
drivers/mailbox/arm-smc-mailbox.c line 43
Quoted 10 lines
drivers/mailbox/arm-smc-mailbox.c new file +10
-0+else + function_id = cmd->a0; + +if (chan_data->flags &ARM_SMC_MBOX_USE_HVC ) +arm_smccc_hvc (function_id, cmd->a1, cmd->a2, cmd->a3, cmd->a4, + cmd->a5, cmd->a6, cmd->a7, &res); +else +arm_smccc_smc (function_id, cmd->a1, cmd->a2, cmd->a3, cmd->a4, + cmd->a5, cmd->a6, cmd->a7, &res); +
So how will the SMC/HVC handler in EL3/2 find which mailbox is being referred with this command ? I prefer 2nd argument to be the mailbox number.
--
Regards,
Sudeep
RE: [PATCH V2 2/2] mailbox: introduce ARM SMC based mailbox
Hi Sudeep,
Quoted 124 lines
Subject: Re: [PATCH V2 2/2] mailbox: introduce ARM SMC based mailbox
Quoted 12 lines · On Mon, Jun 03, 2019 at 04:30:05PM +0800, [email protected] wrote:
From: Peng Fan <[email protected]>
This mailbox driver implements a mailbox which signals transmitted data via an ARM smc (secure monitor call) instruction. The mailbox receiver is implemented in firmware and can synchronously return data when it returns execution to the non-secure world again.
An asynchronous receive path is not implemented.
This allows the usage of a mailbox to trigger firmware actions on SoCs which either don't have a separate management processor or on which such a core is not available. A user of this mailbox could be the SCP interface.Quoted 3 lines
Modified from Andre Przywara's v2 patch
https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore
.kernel.org%2Fpatchwork%2Fpatch%2F812999%2F&data=02%7C01%7Cpeng.fa
Quoted 1 line
n%40nxp.com%7C6b37f78032e446be750e08d6f560e707%7C686ea1d3bc2b4
c6fa92cdQuoted 1 line
99c5c301635%7C0%7C0%7C636966193913988679&sdata=UNM4MTPs brqoMqWStEy
Quoted 4 lines
YzzwMEWTmX7hHO3TeNEz%2BOAw%3D&reserved=0
Cc Andre Przywara <[email protected]>Signed-off-by Peng Fan <[email protected]>Quoted 8 lines
---
V2:
Add interrupts notification support.drivers/mailbox/Kconfig | 7 ++ drivers/mailbox/Makefile | 2 + drivers/mailbox/arm-smc-mailbox.c | 190++++++++++++++++++++++++++++++++
Quoted 28 lines
include/linux/mailbox/arm-smc-mailbox.h | 10 ++ 4 files changed, 209 insertions(+) create mode 100644 drivers/mailbox/arm-smc-mailbox.c create mode100644
include/linux/mailbox/arm-smc-mailbox.hdrivers/mailbox/Kconfig index renamed from drivers/mailbox/Kconfig +0
-0
595542bfae85..c3bd0f1ddcd8100644drivers/mailbox/Kconfig +7
-0@@ -15,6 +15,13 @@ config ARM_MHU The controller has 3 mailbox channels, the last of which can be used in Secure mode only. +config ARM_SMC_MBOX + tristate "Generic ARM smc mailbox" + depends on OF && HAVE_ARM_SMCCC + help + Generic mailbox driver which uses ARM smc calls to call into + firmware for triggering mailboxes. + config IMX_MBOX tristate "i.MX Mailbox" depends on ARCH_MXC || COMPILE_TESTdrivers/mailbox/Makefile index renamed from drivers/mailbox/Makefile +0
-0
c22fad6f696b..93918a84c91b100644drivers/mailbox/Makefile obj-$(CONFIG_MAILBOX_TEST) += mailbox-test.o · line 14
Quoted 8 lines
drivers/mailbox/Makefile +2
-0@@ -7,6 +7,8 @@ obj-$(CONFIG_MAILBOX_TEST) += mailbox-test.o obj-$(CONFIG_ARM_MHU) += arm_mhu.o +obj-$(CONFIG_ARM_SMC_MBOX) += arm-smc-mailbox.o + obj-$(CONFIG_IMX_MBOX) += imx-mailbox.o obj-$(CONFIG_ARMADA_37XX_RWTM_MBOX) +=armada-37xx-rwtm-mailbox.o
Quoted 34 lines
drivers/mailbox/arm-smc-mailbox.c new file +27
-0@@ -0,0 +1,190 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2016,2017 ARM Ltd. +* Copyright 2019 NXP +*/ + +#include <linux/arm-smccc.h> +#include <linux/device.h> +#include <linux/kernel.h> +#include <linux/interrupt.h> +#include <linux/mailbox_controller.h> #include +<linux/mailbox/arm-smc-mailbox.h> +#include <linux/module.h> +#include <linux/platform_device.h> + +#define ARM_SMC_MBOX_USE_HVC BIT(0) +#define ARM_SMC_MBOX_USB_IRQ BIT(1) + +struct arm_smc_chan_data { +u32 function_id; +u32 flags; +int irq; +}; + +static int arm_smc_send_data (struct mbox_chan *link,void *data) { +struct arm_smc_chan_data *chan_data = link->con_priv; +struct arm_smccc_mbox_cmd *cmd = data;drivers/mailbox/arm-smc-mailbox.c line 37
Quoted 10 lines
drivers/mailbox/arm-smc-mailbox.c new file +10
-0+struct arm_smccc_res res; +u32 function_id; + +if (chan_data->function_id !=UINT_MAX ) + function_id = chan_data->function_id; +else + function_id = cmd->a0; + +if (chan_data->flags &ARM_SMC_MBOX_USE_HVC ) + arm_smccc_hvc(function_id, cmd->a1, cmd->a2, cmd->a3,
cmd->a4,drivers/mailbox/arm-smc-mailbox.c
Quoted 3 lines
drivers/mailbox/arm-smc-mailbox.c new file +3
-0+ cmd->a5, cmd->a6, cmd->a7, &res); + else + arm_smccc_smc(function_id, cmd->a1, cmd->a2, cmd->a3,
cmd->a4,
Quoted 6 lines
drivers/mailbox/arm-smc-mailbox.c line 42
Quoted 2 lines
drivers/mailbox/arm-smc-mailbox.c new file +2
-0+ cmd->a5, cmd->a6, cmd->a7, &res); +So how will the SMC/HVC handler in EL3/2 find which mailbox is being referred with this command ? I prefer 2nd argument to be the mailbox number.
You mean channel number as following?
@@ -37,10 +38,10 @@ static int arm_smc_send_data(struct mbox_chan *link, void *data)
function_id = cmd->a0;
if (chan_data->flags & ARM_SMC_MBOX_USE_HVC)
- arm_smccc_hvc(function_id, cmd->a1, cmd->a2, cmd->a3, cmd->a4,
+ arm_smccc_hvc(function_id, chan_data->chan_id, cmd->a2, cmd->a3, cmd->a4,
cmd->a5, cmd->a6, cmd->a7, &res);
else
- arm_smccc_smc(function_id, cmd->a1, cmd->a2, cmd->a3, cmd->a4,
+ arm_smccc_smc(function_id, chan_data->chan_id, cmd->a2, cmd->a3, cmd->a4,
cmd->a5, cmd->a6, cmd->a7, &res);Or should that be passed from firmware driver?
If not from firmware driver, just as above, I do not have a good idea which should be passed to smc, from cmd->a1 to a5 or from cmd->a2 to a6.
Thanks,
Peng.
Quoted 4 lines
--
Regards,
Sudeep
Re: [PATCH V2 2/2] mailbox: introduce ARM SMC based mailbox
Quoted 136 lines · Peng Fan
Hi Sudeep,
Quoted 124 lines
Subject: Re: [PATCH V2 2/2] mailbox: introduce ARM SMC based mailbox
Quoted 12 lines · On Mon, Jun 03, 2019 at 04:30:05PM +0800, [email protected] wrote:
From: Peng Fan <[email protected]>
This mailbox driver implements a mailbox which signals transmitted data via an ARM smc (secure monitor call) instruction. The mailbox receiver is implemented in firmware and can synchronously return data when it returns execution to the non-secure world again.
An asynchronous receive path is not implemented.
This allows the usage of a mailbox to trigger firmware actions on SoCs which either don't have a separate management processor or on which such a core is not available. A user of this mailbox could be the SCP interface.Quoted 3 lines
Modified from Andre Przywara's v2 patch
https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore
.kernel.org%2Fpatchwork%2Fpatch%2F812999%2F&data=02%7C01%7Cpeng.fa
Quoted 1 line
n%40nxp.com%7C6b37f78032e446be750e08d6f560e707%7C686ea1d3bc2b4
c6fa92cdQuoted 1 line
99c5c301635%7C0%7C0%7C636966193913988679&sdata=UNM4MTPs brqoMqWStEy
Quoted 4 lines
YzzwMEWTmX7hHO3TeNEz%2BOAw%3D&reserved=0
Cc Andre Przywara <[email protected]>Signed-off-by Peng Fan <[email protected]>Quoted 8 lines
---
V2:
Add interrupts notification support.drivers/mailbox/Kconfig | 7 ++ drivers/mailbox/Makefile | 2 + drivers/mailbox/arm-smc-mailbox.c | 190++++++++++++++++++++++++++++++++
Quoted 28 lines
include/linux/mailbox/arm-smc-mailbox.h | 10 ++ 4 files changed, 209 insertions(+) create mode 100644 drivers/mailbox/arm-smc-mailbox.c create mode100644
include/linux/mailbox/arm-smc-mailbox.hdrivers/mailbox/Kconfig index renamed from drivers/mailbox/Kconfig +0
-0
595542bfae85..c3bd0f1ddcd8100644drivers/mailbox/Kconfig +7
-0@@ -15,6 +15,13 @@ config ARM_MHU The controller has 3 mailbox channels, the last of which can be used in Secure mode only. +config ARM_SMC_MBOX + tristate "Generic ARM smc mailbox" + depends on OF && HAVE_ARM_SMCCC + help + Generic mailbox driver which uses ARM smc calls to call into + firmware for triggering mailboxes. + config IMX_MBOX tristate "i.MX Mailbox" depends on ARCH_MXC || COMPILE_TESTdrivers/mailbox/Makefile index renamed from drivers/mailbox/Makefile +0
-0
c22fad6f696b..93918a84c91b100644drivers/mailbox/Makefile obj-$(CONFIG_MAILBOX_TEST) += mailbox-test.o · line 14
Quoted 8 lines
drivers/mailbox/Makefile +2
-0@@ -7,6 +7,8 @@ obj-$(CONFIG_MAILBOX_TEST) += mailbox-test.o obj-$(CONFIG_ARM_MHU) += arm_mhu.o +obj-$(CONFIG_ARM_SMC_MBOX) += arm-smc-mailbox.o + obj-$(CONFIG_IMX_MBOX) += imx-mailbox.o obj-$(CONFIG_ARMADA_37XX_RWTM_MBOX) +=armada-37xx-rwtm-mailbox.o
Quoted 34 lines
drivers/mailbox/arm-smc-mailbox.c new file +27
-0@@ -0,0 +1,190 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2016,2017 ARM Ltd. +* Copyright 2019 NXP +*/ + +#include <linux/arm-smccc.h> +#include <linux/device.h> +#include <linux/kernel.h> +#include <linux/interrupt.h> +#include <linux/mailbox_controller.h> #include +<linux/mailbox/arm-smc-mailbox.h> +#include <linux/module.h> +#include <linux/platform_device.h> + +#define ARM_SMC_MBOX_USE_HVC BIT(0) +#define ARM_SMC_MBOX_USB_IRQ BIT(1) + +struct arm_smc_chan_data { +u32 function_id; +u32 flags; +int irq; +}; + +static int arm_smc_send_data (struct mbox_chan *link,void *data) { +struct arm_smc_chan_data *chan_data = link->con_priv; +struct arm_smccc_mbox_cmd *cmd = data;drivers/mailbox/arm-smc-mailbox.c line 37
Quoted 10 lines
drivers/mailbox/arm-smc-mailbox.c new file +10
-0+struct arm_smccc_res res; +u32 function_id; + +if (chan_data->function_id !=UINT_MAX ) + function_id = chan_data->function_id; +else + function_id = cmd->a0; + +if (chan_data->flags &ARM_SMC_MBOX_USE_HVC ) + arm_smccc_hvc(function_id, cmd->a1, cmd->a2, cmd->a3,
cmd->a4,drivers/mailbox/arm-smc-mailbox.c
Quoted 3 lines
drivers/mailbox/arm-smc-mailbox.c new file +3
-0+ cmd->a5, cmd->a6, cmd->a7, &res); + else + arm_smccc_smc(function_id, cmd->a1, cmd->a2, cmd->a3,
cmd->a4,Quoted 6 lines
drivers/mailbox/arm-smc-mailbox.c line 42
Quoted 2 lines
drivers/mailbox/arm-smc-mailbox.c new file +2
-0+ cmd->a5, cmd->a6, cmd->a7, &res); +So how will the SMC/HVC handler in EL3/2 find which mailbox is being referred with this command ? I prefer 2nd argument to be the mailbox number.
You mean channel number as following?
(quoted diff) +0
-0@@ -37,10 +38,10 @@ static int arm_smc_send_data(struct mbox_chan *link, void *data) function_id = cmd->a0;
Review static int arm_smc_send_data(struct mbox_chan *link, void *data) · line 46
Quoted 10 lines
(quoted diff) +2
-2if (chan_data->flags & ARM_SMC_MBOX_USE_HVC) - arm_smccc_hvc(function_id, cmd->a1, cmd->a2, cmd->a3, cmd->a4, + arm_smccc_hvc(function_id, chan_data->chan_id, cmd->a2, cmd->a3, cmd->a4, cmd->a5, cmd->a6, cmd->a7, &res); else - arm_smccc_smc(function_id, cmd->a1, cmd->a2, cmd->a3, cmd->a4, + arm_smccc_smc(function_id, chan_data->chan_id, cmd->a2, cmd->a3, cmd->a4, cmd->a5, cmd->a6, cmd->a7, &res);
Yes something like above. There's a brief description of the same in latest SCMI specification though it's not related to SCMI, it more general note for SMC based mailbox.
"In case the doorbell is SMC/HVC based, it should follow the SMC Calling Convention [SMCCC] and needs to provide the identifier of the Shared Memory area that contains the payload. On return from the call, the Shared Memory area which contained the payload is now updated with the SCMI return response. The identifier of the Shared Memory area should be 32-bits and each identifier should denote a distinct Shared Memory area."
Quoted 2 lines
Or should that be passed from firmware driver?
No, we can't assume the id's in DT are 1-1 translation to mailbox ID used though it may be the same most of the time.
Quoted 3 lines
If not from firmware driver, just as above, I do not have a good idea which should be passed to smc, from
cmd->a1to a5 or fromcmd->a2to a6.
Also I found copying those registers may not be always needed and can be sub-optimal. May be a way to indicate that this in DT whether register based transfers are used or using memory. Just a thought.
--
Regards,
Sudeep
Re: [PATCH V2 1/2] DT: mailbox: add binding doc for the ARM SMC mailbox
In reply to Sudeep HollaQuoted 96 lines · On Thu, 20 Jun 2019 10:22:41 +0100 Sudeep Holla <[email protected]> wrote:
Quoted 77 lines · On Mon, Jun 03, 2019 at 04:30:04PM +0800, [email protected] wrote:
From: Peng Fan <[email protected]>
The ARM SMC mailbox binding describes a firmware interface to trigger actions in software layers running in the EL2 or EL3 exception levels. The term "ARM" here relates to the SMC instruction as part of the ARM instruction set, not as a standard endorsed by ARM Ltd.
Signed-off-by Peng Fan <[email protected]>---
V2:
Introduce interrupts as a property.V1:
arm,func-ids is still kept as an optional property, because there is no defined SMC funciton id passed from SCMI. So in my test, I still use arm,func-ids for ARM SIP service..../devicetree/bindings/mailbox/arm-smc.txt | 101 +++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 Documentation/devicetree/bindings/mailbox/arm-smc.txtDocumentation/devicetree/bindings/mailbox/arm-smc.txt new file +49
-0@@ -0,0 +1,101 @@ +ARM SMC Mailbox Interface +========================= + +This mailbox uses the ARM smc (secure monitor call) instruction to trigger +a mailbox-connected activity in firmware, executing on the very same core +as the caller. By nature this operation is synchronous and this mailbox +provides no way for asynchronous messages to be delivered the other way +round, from firmware to the OS, but asynchronous notification could also +be supported. However the value of r0/w0/x0 the firmware returns after +the smc call is delivered as a received message to the mailbox framework, +so a synchronous communication can be established, for a asynchronous +notification, no value will be returned. The exact meaning of both the +action the mailbox triggers as well as the return value is defined by +their users and is not subject to this binding. + +One use case of this mailbox is the SCMI interface, which uses shared memory +to transfer commands and parameters, and a mailbox to trigger a function +call. This allows SoCs without a separate management processor (or when +such a processor is not available or used) to use this standardized +interface anyway. + +This binding describes no hardware, but establishes a firmware interface. +Upon receiving an SMC using one of the described SMC function identifiers, +the firmware is expected to trigger some mailbox connected functionality. +The communication follows the ARM SMC calling convention[1]. +Firmware expects an SMC function identifier in r0 or w0. The supported +identifiers are passed from consumers, or listed in the the arm,func-ids +properties as described below. The firmware can return one value in +the first SMC result register, it is expected to be an error value, +which shall be propagated to the mailbox client. + +Any core which supports the SMC or HVC instruction can be used, as long as +a firmware component running in EL3 or EL2 is handling these calls. + +Mailbox Device Node: +==================== + +This node is expected to be a child of the /firmware node. + +Required properties: +-------------------- +- compatible: Shall be "arm,smc-mbox" +- #mbox-cells Shall be 1 - the index of the channel needed. +- arm,num-chans The number of channels supported. +- method: A string, either: + "hvc": if the driver shall use an HVC call, or + "smc": if the driver shall use an SMC call. + +Optional properties:Documentation/devicetree/bindings/mailbox/arm-smc.txt line 59
Quoted 10 lines
Documentation/devicetree/bindings/mailbox/arm-smc.txt new file +10
-0+- arm,func-ids An array of 32-bit values specifying the function + IDs used by each mailbox channel. Those function IDs + follow the ARM SMC calling convention standard [1]. + There is one identifier per channel and the number + of supported channels is determined by the length + of this array. +- interrupts SPI interrupts may be listed for notification, + each channel should use a dedicated interrupt + line. +I think SMC mailbox as mostly unidirectional/Tx only channel. And the interrupts here as stated are for notifications, so I prefer to keep them separate channel. I assume SMC call return indicates completion. Or do you plan to use these interrupts as the indication for completion of the command? I see in patch 2/2 the absence of IRQ is anyway dealt the way I mention above.
Quoted 1 line
Does it make sense or am I missing something here ?
I think you are right. From a mailbox point of view "completion" means that the trigger has reached the other side. A returning smc call is a perfect indication of this fact. Whether the action triggered by this mailbox command has completed is a totally separate question and out of the scope of the mailbox. This should be handled by a higher level protocol (SCPI in this case). Which could mean that this employs a separate return mailbox channel, which is RX only and implemented by interrupts. Which could or could not be part of this driver.
Cheers,
Andre
Jassi Brar
maintainerRe: [PATCH V2 1/2] DT: mailbox: add binding doc for the ARM SMC mailbox
Quoted 100 lines · Andre Przywara
Quoted 96 lines · On Thu, 20 Jun 2019 10:22:41 +0100 Sudeep Holla <[email protected]> wrote:
Quoted 77 lines · On Mon, Jun 03, 2019 at 04:30:04PM +0800, [email protected] wrote:
From: Peng Fan <[email protected]>
The ARM SMC mailbox binding describes a firmware interface to trigger actions in software layers running in the EL2 or EL3 exception levels. The term "ARM" here relates to the SMC instruction as part of the ARM instruction set, not as a standard endorsed by ARM Ltd.
Signed-off-by Peng Fan <[email protected]>---
V2:
Introduce interrupts as a property.V1:
arm,func-ids is still kept as an optional property, because there is no defined SMC funciton id passed from SCMI. So in my test, I still use arm,func-ids for ARM SIP service..../devicetree/bindings/mailbox/arm-smc.txt | 101 +++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 Documentation/devicetree/bindings/mailbox/arm-smc.txtDocumentation/devicetree/bindings/mailbox/arm-smc.txt new file +49
-0@@ -0,0 +1,101 @@ +ARM SMC Mailbox Interface +========================= + +This mailbox uses the ARM smc (secure monitor call) instruction to trigger +a mailbox-connected activity in firmware, executing on the very same core +as the caller. By nature this operation is synchronous and this mailbox +provides no way for asynchronous messages to be delivered the other way +round, from firmware to the OS, but asynchronous notification could also +be supported. However the value of r0/w0/x0 the firmware returns after +the smc call is delivered as a received message to the mailbox framework, +so a synchronous communication can be established, for a asynchronous +notification, no value will be returned. The exact meaning of both the +action the mailbox triggers as well as the return value is defined by +their users and is not subject to this binding. + +One use case of this mailbox is the SCMI interface, which uses shared memory +to transfer commands and parameters, and a mailbox to trigger a function +call. This allows SoCs without a separate management processor (or when +such a processor is not available or used) to use this standardized +interface anyway. + +This binding describes no hardware, but establishes a firmware interface. +Upon receiving an SMC using one of the described SMC function identifiers, +the firmware is expected to trigger some mailbox connected functionality. +The communication follows the ARM SMC calling convention[1]. +Firmware expects an SMC function identifier in r0 or w0. The supported +identifiers are passed from consumers, or listed in the the arm,func-ids +properties as described below. The firmware can return one value in +the first SMC result register, it is expected to be an error value, +which shall be propagated to the mailbox client. + +Any core which supports the SMC or HVC instruction can be used, as long as +a firmware component running in EL3 or EL2 is handling these calls. + +Mailbox Device Node: +==================== + +This node is expected to be a child of the /firmware node. + +Required properties: +-------------------- +- compatible: Shall be "arm,smc-mbox" +- #mbox-cells Shall be 1 - the index of the channel needed. +- arm,num-chans The number of channels supported. +- method: A string, either: + "hvc": if the driver shall use an HVC call, or + "smc": if the driver shall use an SMC call. + +Optional properties:Documentation/devicetree/bindings/mailbox/arm-smc.txt line 59
Quoted 10 lines
Documentation/devicetree/bindings/mailbox/arm-smc.txt new file +10
-0+- arm,func-ids An array of 32-bit values specifying the function + IDs used by each mailbox channel. Those function IDs + follow the ARM SMC calling convention standard [1]. + There is one identifier per channel and the number + of supported channels is determined by the length + of this array. +- interrupts SPI interrupts may be listed for notification, + each channel should use a dedicated interrupt + line. +I think SMC mailbox as mostly unidirectional/Tx only channel. And the interrupts here as stated are for notifications, so I prefer to keep them separate channel. I assume SMC call return indicates completion. Or do you plan to use these interrupts as the indication for completion of the command? I see in patch 2/2 the absence of IRQ is anyway dealt the way I mention above.
Quoted 6 lines
Quoted 1 line
Does it make sense or am I missing something here ?
I think you are right. From a mailbox point of view "completion" means that the trigger has reached the other side. A returning smc call is a perfect indication of this fact.
Yes. mailbox only cares about message delivery.
Quoted 4 lines
Whether the action triggered by this
mailbox command has completed is a totally separate question and out of the scope of the mailbox.
Yes, whether the message is accepted/rejected at protocol level is a matter of upper layer (protocol).
Quoted 5 lines
This should be handled by a higher level
protocol (SCPI in this case). Which could mean that this employs a separate return mailbox channel, which is RX only and implemented by interrupts. Which could or could not be part of this driver.
Any message received over the same class of channel should be handled in this driver.
Cheers
Jassi Brar
maintainerRe: [PATCH V2 2/2] mailbox: introduce ARM SMC based mailbox
In reply to [email protected]Quoted 76 lines · On Mon, Jun 3, 2019 at 3:28 AM <[email protected]> wrote:
From: Peng Fan <[email protected]>
This mailbox driver implements a mailbox which signals transmitted data via an ARM smc (secure monitor call) instruction. The mailbox receiver is implemented in firmware and can synchronously return data when it returns execution to the non-secure world again.
An asynchronous receive path is not implemented.
This allows the usage of a mailbox to trigger firmware actions on SoCs which either don't have a separate management processor or on which such a core is not available. A user of this mailbox could be the SCP interface.Modified from Andre Przywara's v2 patch
https://lore.kernel.org/patchwork/patch/812999/Cc Andre Przywara <[email protected]>Signed-off-by Peng Fan <[email protected]>---
V2:
Add interrupts notification support.drivers/mailbox/Kconfig | 7 ++ drivers/mailbox/Makefile | 2 + drivers/mailbox/arm-smc-mailbox.c | 190 ++++++++++++++++++++++++++++++++ include/linux/mailbox/arm-smc-mailbox.h | 10 ++ 4 files changed, 209 insertions(+) create mode 100644 drivers/mailbox/arm-smc-mailbox.c create mode 100644 include/linux/mailbox/arm-smc-mailbox.hdrivers/mailbox/Kconfig +7
-0@@ -15,6 +15,13 @@ config ARM_MHU The controller has 3 mailbox channels, the last of which can be used in Secure mode only. +config ARM_SMC_MBOX + tristate "Generic ARM smc mailbox" + depends on OF && HAVE_ARM_SMCCC + help + Generic mailbox driver which uses ARM smc calls to call into + firmware for triggering mailboxes. + config IMX_MBOX tristate "i.MX Mailbox" depends on ARCH_MXC || COMPILE_TESTdrivers/mailbox/Makefile +2
-0@@ -7,6 +7,8 @@ obj-$(CONFIG_MAILBOX_TEST) += mailbox-test.o obj-$(CONFIG_ARM_MHU) += arm_mhu.o +obj-$(CONFIG_ARM_SMC_MBOX) += arm-smc-mailbox.o + obj-$(CONFIG_IMX_MBOX) += imx-mailbox.o obj-$(CONFIG_ARMADA_37XX_RWTM_MBOX) += armada-37xx-rwtm-mailbox.odrivers/mailbox/arm-smc-mailbox.c new file +8
-0@@ -0,0 +1,190 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2016,2017 ARM Ltd. +* Copyright 2019 NXP +*/ + +#include <linux/arm-smccc.h> +#include <linux/device.h>
drivers/mailbox/arm-smc-mailbox.c line 18
Quoted 10 lines
drivers/mailbox/arm-smc-mailbox.c new file +10
-0+#include <linux/kernel.h> +#include <linux/interrupt.h> +#include <linux/mailbox_controller.h> +#include <linux/mailbox/arm-smc-mailbox.h> +#include <linux/module.h> +#include <linux/platform_device.h> + +#define ARM_SMC_MBOX_USE_HVC BIT(0) +#define ARM_SMC_MBOX_USB_IRQ BIT(1) +
IRQ bit is unused (and unnecessary IMO)
Quoted 8 lines
drivers/mailbox/arm-smc-mailbox.c new file +8
-0+struct arm_smc_chan_data { +u32 function_id; +u32 flags; +int irq; +}; + +static int arm_smc_send_data (struct mbox_chan *link,void *data) +{
drivers/mailbox/arm-smc-mailbox.c line 36
Quoted 10 lines
drivers/mailbox/arm-smc-mailbox.c new file +10
-0+struct arm_smc_chan_data *chan_data = link->con_priv; +struct arm_smccc_mbox_cmd *cmd = data; +struct arm_smccc_res res; +u32 function_id; + +if (chan_data->function_id !=UINT_MAX ) + function_id = chan_data->function_id; +else + function_id = cmd->a0; +
Not sure about chan_data->function_id. Why restrict from DT? 'a0' is the function_id register, let the user pass func-id via the 'a0' like other values via 'a[1-7]'
drivers/mailbox/arm-smc-mailbox.c line 46
Quoted 10 lines
drivers/mailbox/arm-smc-mailbox.c new file +10
-0+if (chan_data->flags &ARM_SMC_MBOX_USE_HVC ) +arm_smccc_hvc (function_id, cmd->a1, cmd->a2, cmd->a3, cmd->a4, + cmd->a5, cmd->a6, cmd->a7, &res); +else +arm_smccc_smc (function_id, cmd->a1, cmd->a2, cmd->a3, cmd->a4, + cmd->a5, cmd->a6, cmd->a7, &res); + +if (chan_data->irq) +return 0 ; +
This irq thing seems like oob signalling, that is, a protocol thing. And then it provides lesser info via chan_irq_handler (returns NULL) than res.a0 - which can always be ignored if not needed.
So the irq should be implemented in the upper layer if the protocol needs it.
drivers/mailbox/arm-smc-mailbox.c line 48
Quoted 2 lines
drivers/mailbox/arm-smc-mailbox.c new file +2
-0+mbox_chan_received_data (link, (void *)res.a0); +
This is fine.
RE: [PATCH V2 2/2] mailbox: introduce ARM SMC based mailbox
Hi Jassi,
Quoted 106 lines
-----Original Message-----
From: Jassi Brar [mailto:[email protected]]
Sent: 2019年6月21日 0:50
To: Peng Fan <[email protected]>
Cc: Rob Herring <[email protected]>; Mark Rutland <[email protected]>; Sudeep Holla <[email protected]>; Florian Fainelli <[email protected]>; , Sascha Hauer <[email protected]>; dl-linux-imx <[email protected]>; Shawn Guo <[email protected]>; [email protected]; Devicetree List <[email protected]>; Linux Kernel Mailing List <[email protected]>; [email protected]; Andre Przywara <[email protected]>; [email protected]
Subject: Re: [PATCH V2 2/2] mailbox: introduce ARM SMC based mailboxQuoted 13 lines · On Mon, Jun 3, 2019 at 3:28 AM <[email protected]> wrote:
From: Peng Fan <[email protected]>
This mailbox driver implements a mailbox which signals transmitted data via an ARM smc (secure monitor call) instruction. The mailbox receiver is implemented in firmware and can synchronously return data when it returns execution to the non-secure world again.
An asynchronous receive path is not implemented.
This allows the usage of a mailbox to trigger firmware actions on SoCs which either don't have a separate management processor or on which such a core is not available. A user of this mailbox could be the SCP interface.Quoted 3 lines
Modified from Andre Przywara's v2 patch
https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore
.kernel.org%2Fpatchwork%2Fpatch%2F812999%2F&data=02%7C01%7Cpeng.fa
Quoted 1 line
n%40nxp.com%7C1237677cb01044ad714508d6f59f648f%7C686ea1d3bc2b4
c6fa92cdQuoted 1 line
99c5c301635%7C0%7C0%7C636966462272457978&sdata=Hzgeu43m5 ZkeRMtL8Bx
Quoted 4 lines
gUm3%2B6FBObib1OPHPlSccE%2B0%3D&reserved=0
Cc Andre Przywara <[email protected]>Signed-off-by Peng Fan <[email protected]>Quoted 8 lines
---
V2:
Add interrupts notification support.drivers/mailbox/Kconfig | 7 ++ drivers/mailbox/Makefile | 2 + drivers/mailbox/arm-smc-mailbox.c | 190++++++++++++++++++++++++++++++++
Quoted 28 lines
include/linux/mailbox/arm-smc-mailbox.h | 10 ++ 4 files changed, 209 insertions(+) create mode 100644 drivers/mailbox/arm-smc-mailbox.c create mode100644
include/linux/mailbox/arm-smc-mailbox.hdrivers/mailbox/Kconfig index renamed from drivers/mailbox/Kconfig +0
-0
595542bfae85..c3bd0f1ddcd8100644drivers/mailbox/Kconfig +7
-0@@ -15,6 +15,13 @@ config ARM_MHU The controller has 3 mailbox channels, the last of which can be used in Secure mode only. +config ARM_SMC_MBOX + tristate "Generic ARM smc mailbox" + depends on OF && HAVE_ARM_SMCCC + help + Generic mailbox driver which uses ARM smc calls to call into + firmware for triggering mailboxes. + config IMX_MBOX tristate "i.MX Mailbox" depends on ARCH_MXC || COMPILE_TEST diff --gita/drivers/mailbox/Makefile b/drivers/mailbox/Makefile index
c22fad6f696b..93918a84c91b100644drivers/mailbox/Makefile obj-$(CONFIG_MAILBOX_TEST) += mailbox-test.o · line 14
Quoted 8 lines
drivers/mailbox/Makefile +2
-0@@ -7,6 +7,8 @@ obj-$(CONFIG_MAILBOX_TEST) += mailbox-test.o obj-$(CONFIG_ARM_MHU) += arm_mhu.o +obj-$(CONFIG_ARM_SMC_MBOX) += arm-smc-mailbox.o + obj-$(CONFIG_IMX_MBOX) += imx-mailbox.o obj-$(CONFIG_ARMADA_37XX_RWTM_MBOX) +=armada-37xx-rwtm-mailbox.o
Quoted 18 lines
drivers/mailbox/arm-smc-mailbox.c new file +11
-0@@ -0,0 +1,190 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2016,2017 ARM Ltd. +* Copyright 2019 NXP +*/ + +#include <linux/arm-smccc.h> +#include <linux/device.h> +#include <linux/kernel.h> +#include <linux/interrupt.h> +#include <linux/mailbox_controller.h> #include
Quoted 8 lines
drivers/mailbox/arm-smc-mailbox.c line 18
Quoted 7 lines
drivers/mailbox/arm-smc-mailbox.c new file +7
-0+<linux/mailbox/arm-smc-mailbox.h> +#include <linux/module.h> +#include <linux/platform_device.h> + +#define ARM_SMC_MBOX_USE_HVC BIT(0) +#define ARM_SMC_MBOX_USB_IRQ BIT(1) +IRQ bit is unused (and unnecessary IMO)
This will be removed in next version.
Quoted 30 lines
Quoted 8 lines
drivers/mailbox/arm-smc-mailbox.c new file +7
-0+struct arm_smc_chan_data { +u32 function_id; +u32 flags; +int irq; +}; + +static int arm_smc_send_data (struct mbox_chan *link,void *data) {drivers/mailbox/arm-smc-mailbox.c line 36
Quoted 10 lines
drivers/mailbox/arm-smc-mailbox.c new file +10
-0+struct arm_smc_chan_data *chan_data = link->con_priv; +struct arm_smccc_mbox_cmd *cmd = data; +struct arm_smccc_res res; +u32 function_id; + +if (chan_data->function_id !=UINT_MAX ) + function_id = chan_data->function_id; +else + function_id = cmd->a0; +Not sure about
chan_data->function_id. Why restrict from DT?
'a0' is thefunction_idregister, let the user pass func-id via the 'a0' like other values via 'a[1-7]'drivers/mailbox/arm-smc-mailbox.c line 37
Quoted 2 lines
drivers/mailbox/arm-smc-mailbox.c new file +2
-0+if (chan_data->flags &ARM_SMC_MBOX_USE_HVC ) + arm_smccc_hvc(function_id, cmd->a1, cmd->a2,
cmd->a3,cmd->a4,drivers/mailbox/arm-smc-mailbox.c
Quoted 3 lines
drivers/mailbox/arm-smc-mailbox.c new file +3
-0+ cmd->a5, cmd->a6, cmd->a7, &res); + else + arm_smccc_smc(function_id, cmd->a1, cmd->a2,
cmd->a3,cmd->a4,
Quoted 9 lines
drivers/mailbox/arm-smc-mailbox.c line 46
Quoted 5 lines
drivers/mailbox/arm-smc-mailbox.c new file +5
-0+ cmd->a5, cmd->a6, cmd->a7, &res); + +if (chan_data->irq) +return 0 ; +This irq thing seems like oob signalling, that is, a protocol thing. And then it provides lesser info via
chan_irq_handler(returns NULL) than res.a0 - which can always be ignored if not needed.
So the irq should be implemented in the upper layer if the protocol needs it.
The interrupts was added here because in v1, Florian suggest "
I would just put a
provision in the binding to support an optional interrupt such that asynchronism gets reasonably easy to plug in when it is available (and desirable).
"
So I introduced interrupt in V2. In my testcase, after smc call done, it means firmware->smc mailbox->firmware done. Interrupt notification from firmware->Linux, means firmware has done the operation.
When using interrupts, we could not know res.a0 as smc sync call.
Interrupts is not a must in my testcase, Florian, Andre, do you have any comments? Should I keep interrupts in V3 or drop it as Jassi comments?
Thanks,
Peng.
Quoted 4 lines
drivers/mailbox/arm-smc-mailbox.c line 47
Quoted 3 lines
drivers/mailbox/arm-smc-mailbox.c new file +2
-0+mbox_chan_received_data (link, (void *)res.a0); +This is fine.
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
RE: [PATCH V2 2/2] mailbox: introduce ARM SMC based mailbox
In reply to Sudeep HollaHi Sudeep,
Quoted 162 lines
Subject: Re: [PATCH V2 2/2] mailbox: introduce ARM SMC based mailbox
Quoted 19 lines · Peng Fan
Hi Sudeep,
Quoted 17 lines
Subject: Re: [PATCH V2 2/2] mailbox: introduce ARM SMC based mailbox
Quoted 14 lines · On Mon, Jun 03, 2019 at 04:30:05PM +0800, [email protected] wrote:
From: Peng Fan <[email protected]>
This mailbox driver implements a mailbox which signals transmitted data via an ARM smc (secure monitor call) instruction. The mailbox receiver is implemented in firmware and can synchronously return data when it returns execution to the non-secure world again. An asynchronous receive path is not implemented.
This allows the usage of a mailbox to trigger firmware actions on SoCs which either don't have a separate management processor or on which such a core is not available. A user of this mailbox could be the SCP interface.Modified from Andre Przywara's v2 patch https://lore
.kernel.org%2Fpatchwork%2Fpatch%2F812999%2F&data=02%7C01%7
Quoted 3 lines
Quoted 3 lines
Cpeng.fa
Quoted 1 line
n%40nxp.com%7C6b37f78032e446be750e08d6f560e707%7C686ea1d3bc2b4
Quoted 3 lines
Quoted 3 lines
c6fa92cdQuoted 1 line
99c5c301635%7C0%7C0%7C636966193913988679&sdata=UNM4MTPs
Quoted 10 lines
Quoted 10 lines
brqoMqWStEy
Quoted 9 lines
YzzwMEWTmX7hHO3TeNEz%2BOAw%3D&reserved=0
Cc Andre Przywara <[email protected]>Signed-off-by Peng Fan <[email protected]>---
V2:
Add interrupts notification support.Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
drivers/mailbox/Kconfig | 7 ++ drivers/mailbox/Makefile | 2 + drivers/mailbox/arm-smc-mailbox.c | 190++++++++++++++++++++++++++++++++
Quoted 3 lines
include/linux/mailbox/arm-smc-mailbox.h | 10 ++ 4 files changed, 209 insertions(+) create mode 100644 drivers/mailbox/arm-smc-mailbox.c createmode
Review static int arm_smc_send_data(struct mbox_chan
Quoted 92 lines
Quoted 83 lines
Quoted 25 lines
100644
include/linux/mailbox/arm-smc-mailbox.hdrivers/mailbox/Kconfig index renamed from drivers/mailbox/Kconfig +0
-0
595542bfae85..c3bd0f1ddcd8100644drivers/mailbox/Kconfig +7
-0@@ -15,6 +15,13 @@ config ARM_MHU The controller has 3 mailbox channels, the last of which can be used in Secure mode only. +config ARM_SMC_MBOX + tristate "Generic ARM smc mailbox" + depends on OF && HAVE_ARM_SMCCC + help + Generic mailbox driver which uses ARM smc calls to call into + firmware for triggering mailboxes. + config IMX_MBOX tristate "i.MX Mailbox" depends on ARCH_MXC || COMPILE_TESTdrivers/mailbox/Makefile index renamed from drivers/mailbox/Makefile +0
-0
c22fad6f696b..93918a84c91b100644drivers/mailbox/Makefile obj-$(CONFIG_MAILBOX_TEST) += mailbox-test.o · line 14
Quoted 8 lines
drivers/mailbox/Makefile +2
-0@@ -7,6 +7,8 @@ obj-$(CONFIG_MAILBOX_TEST) += mailbox-test.o obj-$(CONFIG_ARM_MHU) += arm_mhu.o +obj-$(CONFIG_ARM_SMC_MBOX) += arm-smc-mailbox.o + obj-$(CONFIG_IMX_MBOX) += imx-mailbox.o obj-$(CONFIG_ARMADA_37XX_RWTM_MBOX) +=armada-37xx-rwtm-mailbox.o
Quoted 34 lines
drivers/mailbox/arm-smc-mailbox.c new file +27
-0@@ -0,0 +1,190 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2016,2017 ARM Ltd. +* Copyright 2019 NXP +*/ + +#include <linux/arm-smccc.h> +#include <linux/device.h> +#include <linux/kernel.h> +#include <linux/interrupt.h> +#include <linux/mailbox_controller.h> #include +<linux/mailbox/arm-smc-mailbox.h> +#include <linux/module.h> +#include <linux/platform_device.h> + +#define ARM_SMC_MBOX_USE_HVC BIT(0) +#define ARM_SMC_MBOX_USB_IRQ BIT(1) + +struct arm_smc_chan_data { +u32 function_id; +u32 flags; +int irq; +}; + +static int arm_smc_send_data (struct mbox_chan *link,void *data) { +struct arm_smc_chan_data *chan_data = link->con_priv; +struct arm_smccc_mbox_cmd *cmd = data;drivers/mailbox/arm-smc-mailbox.c line 37
Quoted 10 lines
drivers/mailbox/arm-smc-mailbox.c new file +10
-0+struct arm_smccc_res res; +u32 function_id; + +if (chan_data->function_id !=UINT_MAX ) + function_id = chan_data->function_id; +else + function_id = cmd->a0; + +if (chan_data->flags &ARM_SMC_MBOX_USE_HVC ) + arm_smccc_hvc(function_id, cmd->a1, cmd->a2, cmd->a3,
cmd->a4,drivers/mailbox/arm-smc-mailbox.c
Quoted 3 lines
drivers/mailbox/arm-smc-mailbox.c new file +3
-0+ cmd->a5, cmd->a6, cmd->a7, &res); + else + arm_smccc_smc(function_id, cmd->a1, cmd->a2, cmd->a3,
cmd->a4,Quoted 6 lines
drivers/mailbox/arm-smc-mailbox.c line 42
Quoted 2 lines
drivers/mailbox/arm-smc-mailbox.c new file +2
-0+ cmd->a5, cmd->a6, cmd->a7, &res); +So how will the SMC/HVC handler in EL3/2 find which mailbox is being referred with this command ? I prefer 2nd argument to be the mailbox number.
You mean channel number as following?
(quoted diff) +0
-0@@ -37,10 +38,10 @@ static int arm_smc_send_data(struct mbox_chan*link, void *data)
Review static int arm_smc_send_data(struct mbox_chan · line 40
Quoted 4 lines
(quoted diff) +0
-1function_id = cmd->a0; if (chan_data->flags & ARM_SMC_MBOX_USE_HVC) - arm_smccc_hvc(function_id, cmd->a1, cmd->a2,
cmd->a3,cmd->a4,Review static int arm_smc_send_data(struct mbox_chan · line 41
Quoted 1 line
(quoted diff) +1
-0+ arm_smccc_hvc(function_id, chan_data->chan_id,
cmd->a2,cmd->a3,cmd->a4,Review static int arm_smc_send_data(struct mbox_chan · line 43
Quoted 3 lines
(quoted diff) +0
-1cmd->a5, cmd->a6, cmd->a7, &res); else - arm_smccc_smc(function_id, cmd->a1, cmd->a2,
cmd->a3,cmd->a4,Review static int arm_smc_send_data(struct mbox_chan · line 44
Quoted 1 line
(quoted diff) +1
-0+ arm_smccc_smc(function_id, chan_data->chan_id,
cmd->a2,cmd->a3,cmd->a4,Review static int arm_smc_send_data(struct mbox_chan · line 46
Quoted 2 lines
(quoted diff) +0
-0cmd->a5, cmd->a6, cmd->a7, &res);Yes something like above. There's a brief description of the same in latest SCMI specification though it's not related to SCMI, it more general note for SMC based mailbox.
Quoted 9 lines
"In case the doorbell is SMC/HVC based, it should follow the SMC Calling Convention [SMCCC] and needs to provide the identifier of the Shared Memory
area that contains the payload. On return from the call, the Shared Memory area which contained the payload is now updated with the SCMI return response.
The identifier of the Shared Memory area should be 32-bits and each identifier
should denote a distinct Shared Memory area."
Thanks for the info, it make sense to pass channel id to firmware.
Quoted 6 lines
Quoted 3 lines
Or should that be passed from firmware driver?
No, we can't assume the id's in DT are 1-1 translation to mailbox ID used though it may be the same most of the time.
Understand.
Quoted 8 lines
Quoted 4 lines
If not from firmware driver, just as above, I do not have a good idea which should be passed to smc, from
cmd->a1to a5 or fromcmd->a2to a6.Also I found copying those registers may not be always needed and can be sub-optimal. May be a way to indicate that this in DT whether register based transfers are used or using memory. Just a thought.
"reg-transport" or "mem-transport" should help here.
Thanks,
peng.
Quoted 4 lines
--
Regards,
Sudeep
RE: [PATCH V2 2/2] mailbox: introduce ARM SMC based mailbox
In reply to Jassi BrarHi Jassi
Quoted 115 lines
Subject: Re: [PATCH V2 2/2] mailbox: introduce ARM SMC based mailbox
Quoted 13 lines · On Mon, Jun 3, 2019 at 3:28 AM <[email protected]> wrote:
From: Peng Fan <[email protected]>
This mailbox driver implements a mailbox which signals transmitted data via an ARM smc (secure monitor call) instruction. The mailbox receiver is implemented in firmware and can synchronously return data when it returns execution to the non-secure world again.
An asynchronous receive path is not implemented.
This allows the usage of a mailbox to trigger firmware actions on SoCs which either don't have a separate management processor or on which such a core is not available. A user of this mailbox could be the SCP interface.Quoted 3 lines
Modified from Andre Przywara's v2 patch
https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore
.kernel.org%2Fpatchwork%2Fpatch%2F812999%2F&data=02%7C01%7Cpeng.fa
Quoted 1 line
n%40nxp.com%7C1237677cb01044ad714508d6f59f648f%7C686ea1d3bc2b4
c6fa92cdQuoted 1 line
99c5c301635%7C0%7C0%7C636966462272457978&sdata=Hzgeu43m5 ZkeRMtL8Bx
Quoted 4 lines
gUm3%2B6FBObib1OPHPlSccE%2B0%3D&reserved=0
Cc Andre Przywara <[email protected]>Signed-off-by Peng Fan <[email protected]>Quoted 8 lines
---
V2:
Add interrupts notification support.drivers/mailbox/Kconfig | 7 ++ drivers/mailbox/Makefile | 2 + drivers/mailbox/arm-smc-mailbox.c | 190++++++++++++++++++++++++++++++++
Quoted 28 lines
include/linux/mailbox/arm-smc-mailbox.h | 10 ++ 4 files changed, 209 insertions(+) create mode 100644 drivers/mailbox/arm-smc-mailbox.c create mode100644
include/linux/mailbox/arm-smc-mailbox.hdrivers/mailbox/Kconfig index renamed from drivers/mailbox/Kconfig +0
-0
595542bfae85..c3bd0f1ddcd8100644drivers/mailbox/Kconfig +7
-0@@ -15,6 +15,13 @@ config ARM_MHU The controller has 3 mailbox channels, the last of which can be used in Secure mode only. +config ARM_SMC_MBOX + tristate "Generic ARM smc mailbox" + depends on OF && HAVE_ARM_SMCCC + help + Generic mailbox driver which uses ARM smc calls to call into + firmware for triggering mailboxes. + config IMX_MBOX tristate "i.MX Mailbox" depends on ARCH_MXC || COMPILE_TEST diff --gita/drivers/mailbox/Makefile b/drivers/mailbox/Makefile index
c22fad6f696b..93918a84c91b100644drivers/mailbox/Makefile obj-$(CONFIG_MAILBOX_TEST) += mailbox-test.o · line 14
Quoted 8 lines
drivers/mailbox/Makefile +2
-0@@ -7,6 +7,8 @@ obj-$(CONFIG_MAILBOX_TEST) += mailbox-test.o obj-$(CONFIG_ARM_MHU) += arm_mhu.o +obj-$(CONFIG_ARM_SMC_MBOX) += arm-smc-mailbox.o + obj-$(CONFIG_IMX_MBOX) += imx-mailbox.o obj-$(CONFIG_ARMADA_37XX_RWTM_MBOX) +=armada-37xx-rwtm-mailbox.o
Quoted 15 lines
drivers/mailbox/arm-smc-mailbox.c new file +8
-0@@ -0,0 +1,190 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2016,2017 ARM Ltd. +* Copyright 2019 NXP +*/ + +#include <linux/arm-smccc.h> +#include <linux/device.h> drivers/mailbox/arm-smc-mailbox.c line 18
Quoted 10 lines
drivers/mailbox/arm-smc-mailbox.c new file +10
-0+#include <linux/kernel.h> +#include <linux/interrupt.h> +#include <linux/mailbox_controller.h> #include +<linux/mailbox/arm-smc-mailbox.h> +#include <linux/module.h> +#include <linux/platform_device.h> + +#define ARM_SMC_MBOX_USE_HVC BIT(0) +#define ARM_SMC_MBOX_USB_IRQ BIT(1) +IRQ bit is unused (and unnecessary IMO)
Quoted 12 lines
drivers/mailbox/arm-smc-mailbox.c new file +12
-0+struct arm_smc_chan_data { +u32 function_id; +u32 flags; +int irq; +}; + +static int arm_smc_send_data (struct mbox_chan *link,void *data) { +struct arm_smc_chan_data *chan_data = link->con_priv; +struct arm_smccc_mbox_cmd *cmd = data; +struct arm_smccc_res res; +u32 function_id; +
Quoted 8 lines
drivers/mailbox/arm-smc-mailbox.c line 36
Quoted 5 lines
drivers/mailbox/arm-smc-mailbox.c new file +5
-0+if (chan_data->function_id !=UINT_MAX ) + function_id = chan_data->function_id; +else + function_id = cmd->a0; +Not sure about
chan_data->function_id. Why restrict from DT?
'a0' is thefunction_idregister, let the user pass func-id via the 'a0' like other values via 'a[1-7]'
Missed to reply this comment.
The firmware driver might not have func-id, such as SCMI/SCPI. So add an optional func-id to let smc mailbox driver could use smc SiP func id.
Thanks,
Peng.
Quoted 22 lines
drivers/mailbox/arm-smc-mailbox.c line 37
Quoted 4 lines
drivers/mailbox/arm-smc-mailbox.c new file +2
-0+if (chan_data->flags &ARM_SMC_MBOX_USE_HVC ) + arm_smccc_hvc(function_id, cmd->a1, cmd->a2,
cmd->a3,cmd->a4,drivers/mailbox/arm-smc-mailbox.c
Quoted 3 lines
drivers/mailbox/arm-smc-mailbox.c new file +3
-0+ cmd->a5, cmd->a6, cmd->a7, &res); + else + arm_smccc_smc(function_id, cmd->a1, cmd->a2,
cmd->a3,cmd->a4,drivers/mailbox/arm-smc-mailbox.c line 46
Quoted 5 lines
drivers/mailbox/arm-smc-mailbox.c new file +5
-0+ cmd->a5, cmd->a6, cmd->a7, &res); + +if (chan_data->irq) +return 0 ; +This irq thing seems like oob signalling, that is, a protocol thing. And then it provides lesser info via
chan_irq_handler(returns NULL) than res.a0 - which can always be ignored if not needed.
So the irq should be implemented in the upper layer if the protocol needs it.drivers/mailbox/arm-smc-mailbox.c line 47
Quoted 2 lines
drivers/mailbox/arm-smc-mailbox.c new file +2
-0+mbox_chan_received_data (link, (void *)res.a0); +This is fine.
Jassi Brar
maintainerRe: [PATCH V2 2/2] mailbox: introduce ARM SMC based mailbox
Quoted 127 lines · Peng Fan
Hi Jassi
Quoted 115 lines
Subject: Re: [PATCH V2 2/2] mailbox: introduce ARM SMC based mailbox
Quoted 13 lines · On Mon, Jun 3, 2019 at 3:28 AM <[email protected]> wrote:
From: Peng Fan <[email protected]>
This mailbox driver implements a mailbox which signals transmitted data via an ARM smc (secure monitor call) instruction. The mailbox receiver is implemented in firmware and can synchronously return data when it returns execution to the non-secure world again.
An asynchronous receive path is not implemented.
This allows the usage of a mailbox to trigger firmware actions on SoCs which either don't have a separate management processor or on which such a core is not available. A user of this mailbox could be the SCP interface.Quoted 3 lines
Modified from Andre Przywara's v2 patch
https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore
.kernel.org%2Fpatchwork%2Fpatch%2F812999%2F&data=02%7C01%7Cpeng.fa
Quoted 1 line
n%40nxp.com%7C1237677cb01044ad714508d6f59f648f%7C686ea1d3bc2b4
c6fa92cdQuoted 1 line
99c5c301635%7C0%7C0%7C636966462272457978&sdata=Hzgeu43m5 ZkeRMtL8Bx
Quoted 4 lines
gUm3%2B6FBObib1OPHPlSccE%2B0%3D&reserved=0
Cc Andre Przywara <[email protected]>Signed-off-by Peng Fan <[email protected]>Quoted 8 lines
---
V2:
Add interrupts notification support.drivers/mailbox/Kconfig | 7 ++ drivers/mailbox/Makefile | 2 + drivers/mailbox/arm-smc-mailbox.c | 190++++++++++++++++++++++++++++++++
Quoted 28 lines
include/linux/mailbox/arm-smc-mailbox.h | 10 ++ 4 files changed, 209 insertions(+) create mode 100644 drivers/mailbox/arm-smc-mailbox.c create mode100644
include/linux/mailbox/arm-smc-mailbox.hdrivers/mailbox/Kconfig index renamed from drivers/mailbox/Kconfig +0
-0
595542bfae85..c3bd0f1ddcd8100644drivers/mailbox/Kconfig +7
-0@@ -15,6 +15,13 @@ config ARM_MHU The controller has 3 mailbox channels, the last of which can be used in Secure mode only. +config ARM_SMC_MBOX + tristate "Generic ARM smc mailbox" + depends on OF && HAVE_ARM_SMCCC + help + Generic mailbox driver which uses ARM smc calls to call into + firmware for triggering mailboxes. + config IMX_MBOX tristate "i.MX Mailbox" depends on ARCH_MXC || COMPILE_TEST diff --gita/drivers/mailbox/Makefile b/drivers/mailbox/Makefile index
c22fad6f696b..93918a84c91b100644drivers/mailbox/Makefile obj-$(CONFIG_MAILBOX_TEST) += mailbox-test.o · line 14
Quoted 8 lines
drivers/mailbox/Makefile +2
-0@@ -7,6 +7,8 @@ obj-$(CONFIG_MAILBOX_TEST) += mailbox-test.o obj-$(CONFIG_ARM_MHU) += arm_mhu.o +obj-$(CONFIG_ARM_SMC_MBOX) += arm-smc-mailbox.o + obj-$(CONFIG_IMX_MBOX) += imx-mailbox.o obj-$(CONFIG_ARMADA_37XX_RWTM_MBOX) +=armada-37xx-rwtm-mailbox.o
Quoted 15 lines
drivers/mailbox/arm-smc-mailbox.c new file +8
-0@@ -0,0 +1,190 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2016,2017 ARM Ltd. +* Copyright 2019 NXP +*/ + +#include <linux/arm-smccc.h> +#include <linux/device.h> drivers/mailbox/arm-smc-mailbox.c line 18
Quoted 10 lines
drivers/mailbox/arm-smc-mailbox.c new file +10
-0+#include <linux/kernel.h> +#include <linux/interrupt.h> +#include <linux/mailbox_controller.h> #include +<linux/mailbox/arm-smc-mailbox.h> +#include <linux/module.h> +#include <linux/platform_device.h> + +#define ARM_SMC_MBOX_USE_HVC BIT(0) +#define ARM_SMC_MBOX_USB_IRQ BIT(1) +IRQ bit is unused (and unnecessary IMO)
Quoted 12 lines
drivers/mailbox/arm-smc-mailbox.c new file +12
-0+struct arm_smc_chan_data { +u32 function_id; +u32 flags; +int irq; +}; + +static int arm_smc_send_data (struct mbox_chan *link,void *data) { +struct arm_smc_chan_data *chan_data = link->con_priv; +struct arm_smccc_mbox_cmd *cmd = data; +struct arm_smccc_res res; +u32 function_id; +Quoted 8 lines
drivers/mailbox/arm-smc-mailbox.c line 36
Quoted 5 lines
drivers/mailbox/arm-smc-mailbox.c new file +5
-0+if (chan_data->function_id !=UINT_MAX ) + function_id = chan_data->function_id; +else + function_id = cmd->a0; +Not sure about
chan_data->function_id. Why restrict from DT?
'a0' is thefunction_idregister, let the user pass func-id via the 'a0' like other values via 'a[1-7]'
Quoted 6 lines
Missed to reply this comment.
The firmware driver might not have func-id, such as SCMI/SCPI. So add an optional func-id to let smc mailbox driver could use smc SiP func id.
There is no end to conforming to protocols. Controller drivers should be written having no particular client in mind.
RE: [PATCH V2 2/2] mailbox: introduce ARM SMC based mailbox
Hi All,
Quoted 136 lines
Subject: Re: [PATCH V2 2/2] mailbox: introduce ARM SMC based mailbox
Quoted 21 lines · Peng Fan
Hi Jassi
Quoted 18 lines
Subject: Re: [PATCH V2 2/2] mailbox: introduce ARM SMC based mailbox
Quoted 15 lines · On Mon, Jun 3, 2019 at 3:28 AM <[email protected]> wrote:
From: Peng Fan <[email protected]>
This mailbox driver implements a mailbox which signals transmitted data via an ARM smc (secure monitor call) instruction. The mailbox receiver is implemented in firmware and can synchronously return data when it returns execution to the non-secure world again. An asynchronous receive path is not implemented.
This allows the usage of a mailbox to trigger firmware actions on SoCs which either don't have a separate management processor or on which such a core is not available. A user of this mailbox could be the SCP interface.Modified from Andre Przywara's v2 patch https://lore
.kernel.org%2Fpatchwork%2Fpatch%2F812999%2F&data=02%7C01%7
Quoted 3 lines
Quoted 3 lines
Cpeng.fa
Quoted 1 line
n%40nxp.com%7C1237677cb01044ad714508d6f59f648f%7C686ea1d3bc2b4
Quoted 3 lines
Quoted 3 lines
c6fa92cdQuoted 1 line
99c5c301635%7C0%7C0%7C636966462272457978&sdata=Hzgeu43m5
Quoted 10 lines
Quoted 10 lines
ZkeRMtL8Bx
Quoted 9 lines
gUm3%2B6FBObib1OPHPlSccE%2B0%3D&reserved=0
Cc Andre Przywara <[email protected]>Signed-off-by Peng Fan <[email protected]>---
V2:
Add interrupts notification support.Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
drivers/mailbox/Kconfig | 7 ++ drivers/mailbox/Makefile | 2 + drivers/mailbox/arm-smc-mailbox.c | 190++++++++++++++++++++++++++++++++
Quoted 3 lines
include/linux/mailbox/arm-smc-mailbox.h | 10 ++ 4 files changed, 209 insertions(+) create mode 100644 drivers/mailbox/arm-smc-mailbox.c createmode
Quoted 8 lines
Quoted 8 lines
drivers/mailbox/Kconfig config ARM_MHU · line 15
Quoted 8 lines
100644
include/linux/mailbox/arm-smc-mailbox.hdrivers/mailbox/Kconfig index renamed from drivers/mailbox/Kconfig +0
-0
595542bfae85..c3bd0f1ddcd8100644drivers/mailbox/Kconfig +0
-0@@ -15,6 +15,13 @@ config ARM_MHU The controller has 3 mailbox channels, the last of which canbe
Quoted 17 lines
Quoted 17 lines
drivers/mailbox/Makefile obj-$(CONFIG_MAILBOX_TEST) +=
Quoted 17 lines
drivers/mailbox/Kconfig +7
-0used in Secure mode only. +config ARM_SMC_MBOX + tristate "Generic ARM smc mailbox" + depends on OF && HAVE_ARM_SMCCC + help + Generic mailbox driver which uses ARM smc calls to call into + firmware for triggering mailboxes. + config IMX_MBOX tristate "i.MX Mailbox" depends on ARCH_MXC || COMPILE_TEST diff --gita/drivers/mailbox/Makefile b/drivers/mailbox/Makefile index
c22fad6f696b..93918a84c91b100644drivers/mailbox/Makefile +0
-0@@ -7,6 +7,8 @@ obj-$(CONFIG_MAILBOX_TEST) +=mailbox-test.o
Quoted 47 lines
Quoted 47 lines
drivers/mailbox/Makefile obj-$(CONFIG_MAILBOX_TEST) += mailbox-test.o
Quoted 8 lines
drivers/mailbox/Makefile +2
-0obj-$(CONFIG_ARM_MHU) += arm_mhu.o +obj-$(CONFIG_ARM_SMC_MBOX) += arm-smc-mailbox.o + obj-$(CONFIG_IMX_MBOX) += imx-mailbox.o obj-$(CONFIG_ARMADA_37XX_RWTM_MBOX) +=armada-37xx-rwtm-mailbox.o
Quoted 15 lines
drivers/mailbox/arm-smc-mailbox.c new file +8
-0@@ -0,0 +1,190 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2016,2017 ARM Ltd. +* Copyright 2019 NXP +*/ + +#include <linux/arm-smccc.h> +#include <linux/device.h> drivers/mailbox/arm-smc-mailbox.c line 18
Quoted 10 lines
drivers/mailbox/arm-smc-mailbox.c new file +10
-0+#include <linux/kernel.h> +#include <linux/interrupt.h> +#include <linux/mailbox_controller.h> #include +<linux/mailbox/arm-smc-mailbox.h> +#include <linux/module.h> +#include <linux/platform_device.h> + +#define ARM_SMC_MBOX_USE_HVC BIT(0) +#define ARM_SMC_MBOX_USB_IRQ BIT(1) +IRQ bit is unused (and unnecessary IMO)
Quoted 11 lines
drivers/mailbox/arm-smc-mailbox.c new file +11
-0+struct arm_smc_chan_data { +u32 function_id; +u32 flags; +int irq; +}; + +static int arm_smc_send_data (struct mbox_chan *link,void *data) { +struct arm_smc_chan_data *chan_data = link->con_priv; +struct arm_smccc_mbox_cmd *cmd = data; +struct arm_smccc_res res; +u32 function_id;Quoted 8 lines
Quoted 8 lines
drivers/mailbox/arm-smc-mailbox.c line 36
Quoted 6 lines
drivers/mailbox/arm-smc-mailbox.c new file +6
-0+ +if (chan_data->function_id !=UINT_MAX ) + function_id = chan_data->function_id; +else + function_id = cmd->a0; +Not sure about
chan_data->function_id. Why restrict from DT? 'a0' is thefunction_idregister, let the user pass func-id via the 'a0' likeother
Quoted 2 lines
Quoted 1 line
values via 'a[1-7]'
Quoted 8 lines
Quoted 6 lines
Missed to reply this comment.
The firmware driver might not have func-id, such as SCMI/SCPI. So add an optional func-id to let smc mailbox driver could use smc SiP func id.
There is no end to conforming to protocols. Controller drivers should be written having no particular client in mind.
If the func-id needs be passed from user, then the chan_id suggested by Sudeep should also be passed from user, not in mailbox driver.
Jassi, so from your point, arm_smc_send_data just send a0 - a6 to firmware, right?
Sudeep, Andre, Florian,
What's your suggestion? SCMI not support, do you have plan to add smc transport in SCMI?
Thanks,
Peng.
Jassi Brar
maintainerRe: [PATCH V2 2/2] mailbox: introduce ARM SMC based mailbox
Quoted 146 lines · Peng Fan
Hi All,
Quoted 142 lines
Subject: Re: [PATCH V2 2/2] mailbox: introduce ARM SMC based mailbox
Quoted 21 lines · Peng Fan
Hi Jassi
Quoted 18 lines
Subject: Re: [PATCH V2 2/2] mailbox: introduce ARM SMC based mailbox
Quoted 15 lines · On Mon, Jun 3, 2019 at 3:28 AM <[email protected]> wrote:
From: Peng Fan <[email protected]>
This mailbox driver implements a mailbox which signals transmitted data via an ARM smc (secure monitor call) instruction. The mailbox receiver is implemented in firmware and can synchronously return data when it returns execution to the non-secure world again. An asynchronous receive path is not implemented.
This allows the usage of a mailbox to trigger firmware actions on SoCs which either don't have a separate management processor or on which such a core is not available. A user of this mailbox could be the SCP interface.Modified from Andre Przywara's v2 patch https://lore
.kernel.org%2Fpatchwork%2Fpatch%2F812999%2F&data=02%7C01%7
Quoted 3 lines
Quoted 3 lines
Cpeng.fa
Quoted 1 line
n%40nxp.com%7C1237677cb01044ad714508d6f59f648f%7C686ea1d3bc2b4
Quoted 3 lines
Quoted 3 lines
c6fa92cdQuoted 1 line
99c5c301635%7C0%7C0%7C636966462272457978&sdata=Hzgeu43m5
Quoted 10 lines
Quoted 10 lines
ZkeRMtL8Bx
Quoted 9 lines
gUm3%2B6FBObib1OPHPlSccE%2B0%3D&reserved=0
Cc Andre Przywara <[email protected]>Signed-off-by Peng Fan <[email protected]>---
V2:
Add interrupts notification support.Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
drivers/mailbox/Kconfig | 7 ++ drivers/mailbox/Makefile | 2 + drivers/mailbox/arm-smc-mailbox.c | 190++++++++++++++++++++++++++++++++
Quoted 3 lines
include/linux/mailbox/arm-smc-mailbox.h | 10 ++ 4 files changed, 209 insertions(+) create mode 100644 drivers/mailbox/arm-smc-mailbox.c createmode
Quoted 8 lines
Quoted 8 lines
drivers/mailbox/Kconfig config ARM_MHU · line 15
Quoted 8 lines
100644
include/linux/mailbox/arm-smc-mailbox.hdrivers/mailbox/Kconfig index renamed from drivers/mailbox/Kconfig +0
-0
595542bfae85..c3bd0f1ddcd8100644drivers/mailbox/Kconfig +0
-0@@ -15,6 +15,13 @@ config ARM_MHU The controller has 3 mailbox channels, the last of which canbe
Quoted 17 lines
Quoted 17 lines
drivers/mailbox/Makefile obj-$(CONFIG_MAILBOX_TEST) +=
Quoted 17 lines
drivers/mailbox/Kconfig +7
-0used in Secure mode only. +config ARM_SMC_MBOX + tristate "Generic ARM smc mailbox" + depends on OF && HAVE_ARM_SMCCC + help + Generic mailbox driver which uses ARM smc calls to call into + firmware for triggering mailboxes. + config IMX_MBOX tristate "i.MX Mailbox" depends on ARCH_MXC || COMPILE_TEST diff --gita/drivers/mailbox/Makefile b/drivers/mailbox/Makefile index
c22fad6f696b..93918a84c91b100644drivers/mailbox/Makefile +0
-0@@ -7,6 +7,8 @@ obj-$(CONFIG_MAILBOX_TEST) +=mailbox-test.o
Quoted 47 lines
Quoted 47 lines
drivers/mailbox/Makefile obj-$(CONFIG_MAILBOX_TEST) += mailbox-test.o
Quoted 8 lines
drivers/mailbox/Makefile +2
-0obj-$(CONFIG_ARM_MHU) += arm_mhu.o +obj-$(CONFIG_ARM_SMC_MBOX) += arm-smc-mailbox.o + obj-$(CONFIG_IMX_MBOX) += imx-mailbox.o obj-$(CONFIG_ARMADA_37XX_RWTM_MBOX) +=armada-37xx-rwtm-mailbox.o
Quoted 15 lines
drivers/mailbox/arm-smc-mailbox.c new file +8
-0@@ -0,0 +1,190 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2016,2017 ARM Ltd. +* Copyright 2019 NXP +*/ + +#include <linux/arm-smccc.h> +#include <linux/device.h> drivers/mailbox/arm-smc-mailbox.c line 18
Quoted 10 lines
drivers/mailbox/arm-smc-mailbox.c new file +10
-0+#include <linux/kernel.h> +#include <linux/interrupt.h> +#include <linux/mailbox_controller.h> #include +<linux/mailbox/arm-smc-mailbox.h> +#include <linux/module.h> +#include <linux/platform_device.h> + +#define ARM_SMC_MBOX_USE_HVC BIT(0) +#define ARM_SMC_MBOX_USB_IRQ BIT(1) +IRQ bit is unused (and unnecessary IMO)
Quoted 11 lines
drivers/mailbox/arm-smc-mailbox.c new file +11
-0+struct arm_smc_chan_data { +u32 function_id; +u32 flags; +int irq; +}; + +static int arm_smc_send_data (struct mbox_chan *link,void *data) { +struct arm_smc_chan_data *chan_data = link->con_priv; +struct arm_smccc_mbox_cmd *cmd = data; +struct arm_smccc_res res; +u32 function_id;Quoted 8 lines
Quoted 8 lines
drivers/mailbox/arm-smc-mailbox.c line 36
Quoted 6 lines
drivers/mailbox/arm-smc-mailbox.c new file +6
-0+ +if (chan_data->function_id !=UINT_MAX ) + function_id = chan_data->function_id; +else + function_id = cmd->a0; +Not sure about
chan_data->function_id. Why restrict from DT? 'a0' is thefunction_idregister, let the user pass func-id via the 'a0' likeother
Quoted 8 lines
Quoted 1 line
values via 'a[1-7]'
Missed to reply this comment.
The firmware driver might not have func-id, such as SCMI/SCPI. So add an optional func-id to let smc mailbox driver could use smc SiP func id.
Quoted 6 lines
Quoted 2 lines
There is no end to conforming to protocols. Controller drivers should be written having no particular client in mind.
If the func-id needs be passed from user, then the
chan_idsuggested by Sudeep should also be passed from user, not in mailbox driver.
Isn't it already so?
Quoted 3 lines
Jassi, so from your point,
arm_smc_send_datajust send a0 - a6 to firmware, right?
Yes.
Quoted 5 lines
Sudeep, Andre, Florian,
What's your suggestion? SCMI not support, do you have plan to add smc transport in SCMI?
Not replying on their behalf .... but SCMI should eventually support more than MHU. And I can't see why that matters here?
thanks.
Re: [PATCH V2 2/2] mailbox: introduce ARM SMC based mailbox
In reply to Peng FanQuoted 10 lines · Peng Fan
Quoted 6 lines
Quoted 4 lines
The firmware driver might not have func-id, such as SCMI/SCPI. So add an optional func-id to let smc mailbox driver could use smc SiP func id.
There is no end to conforming to protocols. Controller drivers should be written having no particular client in mind.
If the func-id needs be passed from user, then the
chan_idsuggested by Sudeep should also be passed from user, not in mailbox driver.
Quoted 7 lines
Jassi, so from your point,
arm_smc_send_datajust send a0 - a6 to firmware, right?Sudeep, Andre, Florian,
What's your suggestion? SCMI not support, do you have plan to add smc transport in SCMI?
On the platforms that I work with, we have taken the liberty of implementing SCMI in our monitor firmware because the other MCU we use for dynamic voltage and frequency scaling did not have enough memory to support that and we still had the ability to make that firmware be trusted enough we could give it power management responsibilities. I would certainly feel more comfortable if the SCMI specification was amended to indicate that the Agent could be such a software entity, still residing on the same host CPU as the Platform(s), but if not, that's fine.
This has lead us to implement a mailbox driver that uses a proprietary SMC call for the P2A path ("tx" channel) and the return being done via either that same SMC or through SGI. You can take a look at it in our downstream tree here actually:
https://github.com/Broadcom/stblinux-4.9/blob/master/linux/drivers/mailbox/brcmstb-mailbox.c
If we can get rid of our own driver and uses a standard SMC based mailbox driver that supports our use case that involves interrupts (we can always change their kind without our firmware/boot loader since FDT is generated from that component), that would be great.
Signature · 1 line
Florian
Re: [PATCH V2 2/2] mailbox: introduce ARM SMC based mailbox
In reply to Peng FanQuoted 145 lines · Peng Fan
Hi All,
Quoted 142 lines
Subject: Re: [PATCH V2 2/2] mailbox: introduce ARM SMC based mailbox
Quoted 21 lines · Peng Fan
Hi Jassi
Quoted 18 lines
Subject: Re: [PATCH V2 2/2] mailbox: introduce ARM SMC based mailbox
Quoted 15 lines · On Mon, Jun 3, 2019 at 3:28 AM <[email protected]> wrote:
From: Peng Fan <[email protected]>
This mailbox driver implements a mailbox which signals transmitted data via an ARM smc (secure monitor call) instruction. The mailbox receiver is implemented in firmware and can synchronously return data when it returns execution to the non-secure world again. An asynchronous receive path is not implemented.
This allows the usage of a mailbox to trigger firmware actions on SoCs which either don't have a separate management processor or on which such a core is not available. A user of this mailbox could be the SCP interface.Modified from Andre Przywara's v2 patch https://lore
.kernel.org%2Fpatchwork%2Fpatch%2F812999%2F&data=02%7C01%7
Quoted 3 lines
Quoted 3 lines
Cpeng.fa
Quoted 1 line
n%40nxp.com%7C1237677cb01044ad714508d6f59f648f%7C686ea1d3bc2b4
Quoted 3 lines
Quoted 3 lines
c6fa92cdQuoted 1 line
99c5c301635%7C0%7C0%7C636966462272457978&sdata=Hzgeu43m5
Quoted 10 lines
Quoted 10 lines
ZkeRMtL8Bx
Quoted 9 lines
gUm3%2B6FBObib1OPHPlSccE%2B0%3D&reserved=0
Cc Andre Przywara <[email protected]>Signed-off-by Peng Fan <[email protected]>---
V2:
Add interrupts notification support.Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
drivers/mailbox/Kconfig | 7 ++ drivers/mailbox/Makefile | 2 + drivers/mailbox/arm-smc-mailbox.c | 190++++++++++++++++++++++++++++++++
Quoted 3 lines
include/linux/mailbox/arm-smc-mailbox.h | 10 ++ 4 files changed, 209 insertions(+) create mode 100644 drivers/mailbox/arm-smc-mailbox.c createmode
Quoted 8 lines
Quoted 8 lines
drivers/mailbox/Kconfig config ARM_MHU · line 15
Quoted 8 lines
100644
include/linux/mailbox/arm-smc-mailbox.hdrivers/mailbox/Kconfig index renamed from drivers/mailbox/Kconfig +0
-0
595542bfae85..c3bd0f1ddcd8100644drivers/mailbox/Kconfig +0
-0@@ -15,6 +15,13 @@ config ARM_MHU The controller has 3 mailbox channels, the last of which canbe
Quoted 17 lines
Quoted 17 lines
drivers/mailbox/Makefile obj-$(CONFIG_MAILBOX_TEST) +=
Quoted 17 lines
drivers/mailbox/Kconfig +7
-0used in Secure mode only. +config ARM_SMC_MBOX + tristate "Generic ARM smc mailbox" + depends on OF && HAVE_ARM_SMCCC + help + Generic mailbox driver which uses ARM smc calls to call into + firmware for triggering mailboxes. + config IMX_MBOX tristate "i.MX Mailbox" depends on ARCH_MXC || COMPILE_TEST diff --gita/drivers/mailbox/Makefile b/drivers/mailbox/Makefile index
c22fad6f696b..93918a84c91b100644drivers/mailbox/Makefile +0
-0@@ -7,6 +7,8 @@ obj-$(CONFIG_MAILBOX_TEST) +=mailbox-test.o
Quoted 47 lines
Quoted 47 lines
drivers/mailbox/Makefile obj-$(CONFIG_MAILBOX_TEST) += mailbox-test.o
Quoted 8 lines
drivers/mailbox/Makefile +2
-0obj-$(CONFIG_ARM_MHU) += arm_mhu.o +obj-$(CONFIG_ARM_SMC_MBOX) += arm-smc-mailbox.o + obj-$(CONFIG_IMX_MBOX) += imx-mailbox.o obj-$(CONFIG_ARMADA_37XX_RWTM_MBOX) +=armada-37xx-rwtm-mailbox.o
Quoted 15 lines
drivers/mailbox/arm-smc-mailbox.c new file +8
-0@@ -0,0 +1,190 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2016,2017 ARM Ltd. +* Copyright 2019 NXP +*/ + +#include <linux/arm-smccc.h> +#include <linux/device.h> drivers/mailbox/arm-smc-mailbox.c line 18
Quoted 10 lines
drivers/mailbox/arm-smc-mailbox.c new file +10
-0+#include <linux/kernel.h> +#include <linux/interrupt.h> +#include <linux/mailbox_controller.h> #include +<linux/mailbox/arm-smc-mailbox.h> +#include <linux/module.h> +#include <linux/platform_device.h> + +#define ARM_SMC_MBOX_USE_HVC BIT(0) +#define ARM_SMC_MBOX_USB_IRQ BIT(1) +IRQ bit is unused (and unnecessary IMO)
Quoted 11 lines
drivers/mailbox/arm-smc-mailbox.c new file +11
-0+struct arm_smc_chan_data { +u32 function_id; +u32 flags; +int irq; +}; + +static int arm_smc_send_data (struct mbox_chan *link,void *data) { +struct arm_smc_chan_data *chan_data = link->con_priv; +struct arm_smccc_mbox_cmd *cmd = data; +struct arm_smccc_res res; +u32 function_id;Quoted 8 lines
Quoted 8 lines
drivers/mailbox/arm-smc-mailbox.c line 36
Quoted 6 lines
drivers/mailbox/arm-smc-mailbox.c new file +6
-0+ +if (chan_data->function_id !=UINT_MAX ) + function_id = chan_data->function_id; +else + function_id = cmd->a0; +Not sure about
chan_data->function_id. Why restrict from DT? 'a0' is thefunction_idregister, let the user pass func-id via the 'a0' likeother
Quoted 8 lines
Quoted 1 line
values via 'a[1-7]'
Missed to reply this comment.
The firmware driver might not have func-id, such as SCMI/SCPI. So add an optional func-id to let smc mailbox driver could use smc SiP func id.
Quoted 6 lines
Quoted 2 lines
There is no end to conforming to protocols. Controller drivers should be written having no particular client in mind.
If the func-id needs be passed from user, then the
chan_idsuggested by Sudeep should also be passed from user, not in mailbox driver.
Why ? I understand SMC may have 1-1 mapping from DT to channel id, but that may not be true for other mailbox controller. The client is provided with mbox handle in DT and the mbox APIs are used to get the controller handle. The client just uses the same and when it calls say send_data, controller understands which channel the handle is mapped to and client need not have remote idea on channel id. If by user you mean DT yes but as described as it's indirect.
Quoted 8 lines
Jassi, so from your point,
arm_smc_send_datajust send a0 - a6 to firmware, right?Sudeep, Andre, Florian,
What's your suggestion? SCMI not support, do you have plan to add smc transport in SCMI?
I *wish* we could abstract all the transport protocol behind the mailbox APIs and SCMI just deals with message protocol as it is a message protocol specification.
--
Regards,
Sudeep
Re: [PATCH V2 2/2] mailbox: introduce ARM SMC based mailbox
In reply to Peng FanQuoted 167 lines · Peng Fan
Hi Jassi,
Quoted 106 lines
-----Original Message-----
From: Jassi Brar [mailto:[email protected]]
Sent: 2019年6月21日 0:50
To: Peng Fan <[email protected]>
Cc: Rob Herring <[email protected]>; Mark Rutland <[email protected]>; Sudeep Holla <[email protected]>; Florian Fainelli <[email protected]>; , Sascha Hauer <[email protected]>; dl-linux-imx <[email protected]>; Shawn Guo <[email protected]>; [email protected]; Devicetree List <[email protected]>; Linux Kernel Mailing List <[email protected]>; [email protected]; Andre Przywara <[email protected]>; [email protected]
Subject: Re: [PATCH V2 2/2] mailbox: introduce ARM SMC based mailboxQuoted 13 lines · On Mon, Jun 3, 2019 at 3:28 AM <[email protected]> wrote:
From: Peng Fan <[email protected]>
This mailbox driver implements a mailbox which signals transmitted data via an ARM smc (secure monitor call) instruction. The mailbox receiver is implemented in firmware and can synchronously return data when it returns execution to the non-secure world again.
An asynchronous receive path is not implemented.
This allows the usage of a mailbox to trigger firmware actions on SoCs which either don't have a separate management processor or on which such a core is not available. A user of this mailbox could be the SCP interface.Quoted 3 lines
Modified from Andre Przywara's v2 patch
https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore
.kernel.org%2Fpatchwork%2Fpatch%2F812999%2F&data=02%7C01%7Cpeng.fa
Quoted 1 line
n%40nxp.com%7C1237677cb01044ad714508d6f59f648f%7C686ea1d3bc2b4
c6fa92cdQuoted 1 line
99c5c301635%7C0%7C0%7C636966462272457978&sdata=Hzgeu43m5 ZkeRMtL8Bx
Quoted 4 lines
gUm3%2B6FBObib1OPHPlSccE%2B0%3D&reserved=0
Cc Andre Przywara <[email protected]>Signed-off-by Peng Fan <[email protected]>Quoted 8 lines
---
V2:
Add interrupts notification support.drivers/mailbox/Kconfig | 7 ++ drivers/mailbox/Makefile | 2 + drivers/mailbox/arm-smc-mailbox.c | 190++++++++++++++++++++++++++++++++
Quoted 28 lines
include/linux/mailbox/arm-smc-mailbox.h | 10 ++ 4 files changed, 209 insertions(+) create mode 100644 drivers/mailbox/arm-smc-mailbox.c create mode100644
include/linux/mailbox/arm-smc-mailbox.hdrivers/mailbox/Kconfig index renamed from drivers/mailbox/Kconfig +0
-0
595542bfae85..c3bd0f1ddcd8100644drivers/mailbox/Kconfig +7
-0@@ -15,6 +15,13 @@ config ARM_MHU The controller has 3 mailbox channels, the last of which can be used in Secure mode only. +config ARM_SMC_MBOX + tristate "Generic ARM smc mailbox" + depends on OF && HAVE_ARM_SMCCC + help + Generic mailbox driver which uses ARM smc calls to call into + firmware for triggering mailboxes. + config IMX_MBOX tristate "i.MX Mailbox" depends on ARCH_MXC || COMPILE_TEST diff --gita/drivers/mailbox/Makefile b/drivers/mailbox/Makefile index
c22fad6f696b..93918a84c91b100644drivers/mailbox/Makefile obj-$(CONFIG_MAILBOX_TEST) += mailbox-test.o · line 14
Quoted 8 lines
drivers/mailbox/Makefile +2
-0@@ -7,6 +7,8 @@ obj-$(CONFIG_MAILBOX_TEST) += mailbox-test.o obj-$(CONFIG_ARM_MHU) += arm_mhu.o +obj-$(CONFIG_ARM_SMC_MBOX) += arm-smc-mailbox.o + obj-$(CONFIG_IMX_MBOX) += imx-mailbox.o obj-$(CONFIG_ARMADA_37XX_RWTM_MBOX) +=armada-37xx-rwtm-mailbox.o
Quoted 18 lines
drivers/mailbox/arm-smc-mailbox.c new file +11
-0@@ -0,0 +1,190 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2016,2017 ARM Ltd. +* Copyright 2019 NXP +*/ + +#include <linux/arm-smccc.h> +#include <linux/device.h> +#include <linux/kernel.h> +#include <linux/interrupt.h> +#include <linux/mailbox_controller.h> #includeQuoted 8 lines
drivers/mailbox/arm-smc-mailbox.c line 18
Quoted 7 lines
drivers/mailbox/arm-smc-mailbox.c new file +7
-0+<linux/mailbox/arm-smc-mailbox.h> +#include <linux/module.h> +#include <linux/platform_device.h> + +#define ARM_SMC_MBOX_USE_HVC BIT(0) +#define ARM_SMC_MBOX_USB_IRQ BIT(1) +IRQ bit is unused (and unnecessary IMO)
This will be removed in next version.
Quoted 30 lines
Quoted 8 lines
drivers/mailbox/arm-smc-mailbox.c new file +7
-0+struct arm_smc_chan_data { +u32 function_id; +u32 flags; +int irq; +}; + +static int arm_smc_send_data (struct mbox_chan *link,void *data) {drivers/mailbox/arm-smc-mailbox.c line 36
Quoted 10 lines
drivers/mailbox/arm-smc-mailbox.c new file +10
-0+struct arm_smc_chan_data *chan_data = link->con_priv; +struct arm_smccc_mbox_cmd *cmd = data; +struct arm_smccc_res res; +u32 function_id; + +if (chan_data->function_id !=UINT_MAX ) + function_id = chan_data->function_id; +else + function_id = cmd->a0; +Not sure about
chan_data->function_id. Why restrict from DT?
'a0' is thefunction_idregister, let the user pass func-id via the 'a0' like other values via 'a[1-7]'drivers/mailbox/arm-smc-mailbox.c line 37
Quoted 2 lines
drivers/mailbox/arm-smc-mailbox.c new file +2
-0+if (chan_data->flags &ARM_SMC_MBOX_USE_HVC ) + arm_smccc_hvc(function_id, cmd->a1, cmd->a2,
cmd->a3,cmd->a4,drivers/mailbox/arm-smc-mailbox.c
Quoted 3 lines
drivers/mailbox/arm-smc-mailbox.c new file +3
-0+ cmd->a5, cmd->a6, cmd->a7, &res); + else + arm_smccc_smc(function_id, cmd->a1, cmd->a2,
cmd->a3,cmd->a4,Quoted 9 lines
drivers/mailbox/arm-smc-mailbox.c line 46
Quoted 5 lines
drivers/mailbox/arm-smc-mailbox.c new file +5
-0+ cmd->a5, cmd->a6, cmd->a7, &res); + +if (chan_data->irq) +return 0 ; +This irq thing seems like oob signalling, that is, a protocol thing. And then it provides lesser info via
chan_irq_handler(returns NULL) than res.a0 - which can always be ignored if not needed.
So the irq should be implemented in the upper layer if the protocol needs it.The interrupts was added here because in v1, Florian suggest "
I would just put a
provision in the binding to support an optional interrupt such that asynchronism gets reasonably easy to plug in when it is available (and desirable).
"
Quoted 8 lines
So I introduced interrupt in V2. In my testcase, after smc call done, it means
firmware->smcmailbox->firmwaredone. Interrupt notification fromfirmware->Linux, means firmware has done the operation.When using interrupts, we could not know res.a0 as smc sync call.
Interrupts is not a must in my testcase, Florian, Andre, do you have any comments? Should I keep interrupts in V3 or drop it as Jassi comments?
The smc mailbox is by its very design a one-way channel - and it's synchronous. I think this is all the mailbox driver should be concerned about. The fact that there is a protocol user that would benefit from a return channel is a separate issue.
The SCMI binding explicitly mentions *two* mailboxes, one TX, one RX, so the return channel could be very well implemented by a separate driver. I am wondering if we get away without a functioning return channel, at least for a subset of SCMI functionality? Can we use some dummy driver? Or specify another smc channel with some unhandled/ignored channel ID for that purpose?
So I would leave the IRQ return channel out for now, unless we desperately need it.
Cheers,
Andre.
Re: [PATCH V2 2/2] mailbox: introduce ARM SMC based mailbox
Quoted 20 lines · André Przywara
Quoted 8 lines
So I introduced interrupt in V2. In my testcase, after smc call done, it means
firmware->smcmailbox->firmwaredone. Interrupt notification fromfirmware->Linux, means firmware has done the operation.When using interrupts, we could not know res.a0 as smc sync call.
Interrupts is not a must in my testcase, Florian, Andre, do you have any comments? Should I keep interrupts in V3 or drop it as Jassi comments?
The smc mailbox is by its very design a one-way channel - and it's synchronous. I think this is all the mailbox driver should be concerned about. The fact that there is a protocol user that would benefit from a return channel is a separate issue.
The SCMI binding explicitly mentions *two* mailboxes, one TX, one RX, so the return channel could be very well implemented by a separate driver. I am wondering if we get away without a functioning return channel, at least for a subset of SCMI functionality? Can we use some dummy driver? Or specify another smc channel with some unhandled/ignored channel ID for that purpose?
Quoted 2 lines
So I would leave the IRQ return channel out for now, unless we desperately need it.
That's fine, the initial point was specifically about the binding already defining an optional interrupt property, but that can be removed too if this is too much confusion or opens up the discussion beyond this submission.
Signature · 1 line
Florian
Re: [PATCH V2 2/2] mailbox: introduce ARM SMC based mailbox
In reply to Florian FainelliQuoted 19 lines · Florian Fainelli
Quoted 10 lines · Peng Fan
Quoted 6 lines
Quoted 4 lines
The firmware driver might not have func-id, such as SCMI/SCPI. So add an optional func-id to let smc mailbox driver could use smc SiP func id.
There is no end to conforming to protocols. Controller drivers should be written having no particular client in mind.
If the func-id needs be passed from user, then the
chan_idsuggested by Sudeep should also be passed from user, not in mailbox driver.Quoted 7 lines
Jassi, so from your point,
arm_smc_send_datajust send a0 - a6 to firmware, right?Sudeep, Andre, Florian,
What's your suggestion? SCMI not support, do you have plan to add smc transport in SCMI?
Quoted 10 lines
On the platforms that I work with, we have taken the liberty of implementing SCMI in our monitor firmware because the other MCU we use for dynamic voltage and frequency scaling did not have enough memory to support that and we still had the ability to make that firmware be trusted enough we could give it power management responsibilities. I would certainly feel more comfortable if the SCMI specification was amended to indicate that the Agent could be such a software entity, still residing on the same host CPU as the Platform(s), but if not, that's fine.
That's completely legal and there's nothing in the specification that prohibits. I understand it's not explicitly not mentioned and I have been trying to get such things clarified. But since it's main focus is on the message protocol, the clarity on transport mechanism is very thin and there's hesitation to add more details under the impression that it may restrict the usage.
But as I mentioned, I understand what you need there :)
Quoted 7 lines
This has lead us to implement a mailbox driver that uses a proprietary SMC call for the P2A path ("tx" channel) and the return being done via either that same SMC or through SGI. You can take a look at it in our downstream tree here actually:
https://github.com/Broadcom/stblinux-4.9/blob/master/linux/drivers/mailbox/brcmstb-mailbox.c
Just curious, I see it's fast call and why do you still depend on interrupt to indicate completion of the message. Will the return from SMC not suffice ? Sorry if I am missing something obvious.
--
Regards,
Sudeep
Jassi Brar
maintainerRe: [PATCH V2 2/2] mailbox: introduce ARM SMC based mailbox
In reply to Florian FainelliQuoted 35 lines · Florian Fainelli
Quoted 10 lines · Peng Fan
Quoted 6 lines
Quoted 4 lines
The firmware driver might not have func-id, such as SCMI/SCPI. So add an optional func-id to let smc mailbox driver could use smc SiP func id.
There is no end to conforming to protocols. Controller drivers should be written having no particular client in mind.
If the func-id needs be passed from user, then the
chan_idsuggested by Sudeep should also be passed from user, not in mailbox driver.Quoted 7 lines
Jassi, so from your point,
arm_smc_send_datajust send a0 - a6 to firmware, right?Sudeep, Andre, Florian,
What's your suggestion? SCMI not support, do you have plan to add smc transport in SCMI?
On the platforms that I work with, we have taken the liberty of implementing SCMI in our monitor firmware because the other MCU we use for dynamic voltage and frequency scaling did not have enough memory to support that and we still had the ability to make that firmware be trusted enough we could give it power management responsibilities. I would certainly feel more comfortable if the SCMI specification was amended to indicate that the Agent could be such a software entity, still residing on the same host CPU as the Platform(s), but if not, that's fine.
This has lead us to implement a mailbox driver that uses a proprietary SMC call for the P2A path ("tx" channel) and the return being done via either that same SMC or through SGI. You can take a look at it in our downstream tree here actually:
Quoted 7 lines
https://github.com/Broadcom/stblinux-4.9/blob/master/linux/drivers/mailbox/brcmstb-mailbox.c
If we can get rid of our own driver and uses a standard SMC based mailbox driver that supports our use case that involves interrupts (we can always change their kind without our
firmware/bootloader since FDT is generated from that component), that would be great.
static irqreturn_t brcm_isr(void)
{
mbox_chan_received_data(&chans[0], NULL);
return IRQ_HANDLED;
}Sorry, I fail to understand why the irq can't be moved inside the client driver itself? There can't be more cost to it and there definitely is no functionality lost.
Re: [PATCH V2 2/2] mailbox: introduce ARM SMC based mailbox
Quoted 44 lines · Jassi Brar
Quoted 35 lines · Florian Fainelli
Quoted 10 lines · Peng Fan
Quoted 6 lines
Quoted 4 lines
The firmware driver might not have func-id, such as SCMI/SCPI. So add an optional func-id to let smc mailbox driver could use smc SiP func id.
There is no end to conforming to protocols. Controller drivers should be written having no particular client in mind.
If the func-id needs be passed from user, then the
chan_idsuggested by Sudeep should also be passed from user, not in mailbox driver.Quoted 7 lines
Jassi, so from your point,
arm_smc_send_datajust send a0 - a6 to firmware, right?Sudeep, Andre, Florian,
What's your suggestion? SCMI not support, do you have plan to add smc transport in SCMI?
On the platforms that I work with, we have taken the liberty of implementing SCMI in our monitor firmware because the other MCU we use for dynamic voltage and frequency scaling did not have enough memory to support that and we still had the ability to make that firmware be trusted enough we could give it power management responsibilities. I would certainly feel more comfortable if the SCMI specification was amended to indicate that the Agent could be such a software entity, still residing on the same host CPU as the Platform(s), but if not, that's fine.
This has lead us to implement a mailbox driver that uses a proprietary SMC call for the P2A path ("tx" channel) and the return being done via either that same SMC or through SGI. You can take a look at it in our downstream tree here actually:
Quoted 7 lines
https://github.com/Broadcom/stblinux-4.9/blob/master/linux/drivers/mailbox/brcmstb-mailbox.c
If we can get rid of our own driver and uses a standard SMC based mailbox driver that supports our use case that involves interrupts (we can always change their kind without our
firmware/bootloader since FDT is generated from that component), that would be great.static
irqreturn_tbrcm_isr(void)
Quoted 8 lines
{ mbox_chan_received_data(&chans[0], NULL); return IRQ_HANDLED; }Sorry, I fail to understand why the irq can't be moved inside the client driver itself? There can't be more cost to it and there definitely is no functionality lost.
What if there are multiple clients ?
And I assume you are referring to case like this where IRQ is not tied to the mailbox IP.
--
Regards,
Sudeep
Jassi Brar
maintainerRe: [PATCH V2 2/2] mailbox: introduce ARM SMC based mailbox
Quoted 51 lines · Sudeep Holla
Quoted 49 lines · Jassi Brar
Quoted 35 lines · Florian Fainelli
Quoted 10 lines · Peng Fan
Quoted 6 lines
Quoted 4 lines
The firmware driver might not have func-id, such as SCMI/SCPI. So add an optional func-id to let smc mailbox driver could use smc SiP func id.
There is no end to conforming to protocols. Controller drivers should be written having no particular client in mind.
If the func-id needs be passed from user, then the
chan_idsuggested by Sudeep should also be passed from user, not in mailbox driver.Quoted 7 lines
Jassi, so from your point,
arm_smc_send_datajust send a0 - a6 to firmware, right?Sudeep, Andre, Florian,
What's your suggestion? SCMI not support, do you have plan to add smc transport in SCMI?
On the platforms that I work with, we have taken the liberty of implementing SCMI in our monitor firmware because the other MCU we use for dynamic voltage and frequency scaling did not have enough memory to support that and we still had the ability to make that firmware be trusted enough we could give it power management responsibilities. I would certainly feel more comfortable if the SCMI specification was amended to indicate that the Agent could be such a software entity, still residing on the same host CPU as the Platform(s), but if not, that's fine.
This has lead us to implement a mailbox driver that uses a proprietary SMC call for the P2A path ("tx" channel) and the return being done via either that same SMC or through SGI. You can take a look at it in our downstream tree here actually:
Quoted 7 lines
https://github.com/Broadcom/stblinux-4.9/blob/master/linux/drivers/mailbox/brcmstb-mailbox.c
If we can get rid of our own driver and uses a standard SMC based mailbox driver that supports our use case that involves interrupts (we can always change their kind without our
firmware/bootloader since FDT is generated from that component), that would be great.static
irqreturn_tbrcm_isr(void){ mbox_chan_received_data(&chans[0], NULL); return IRQ_HANDLED; }
Quoted 6 lines
Quoted 3 lines
Sorry, I fail to understand why the irq can't be moved inside the client driver itself? There can't be more cost to it and there definitely is no functionality lost.
What if there are multiple clients ?
There is a flag IRQF_SHARED for such situations.
(good to see you considering multiple clients per channel as a legit scenario)
Quoted 3 lines
And I assume you are referring to case like this where IRQ is not tied to the mailbox IP.
Yes, and that is the reason the irq should not be managed by the mailbox driver.
Re: [PATCH V2 2/2] mailbox: introduce ARM SMC based mailbox
Quoted 52 lines · Jassi Brar
Quoted 51 lines · Sudeep Holla
Quoted 49 lines · Jassi Brar
Quoted 35 lines · Florian Fainelli
Quoted 10 lines · Peng Fan
Quoted 6 lines
Quoted 4 lines
The firmware driver might not have func-id, such as SCMI/SCPI. So add an optional func-id to let smc mailbox driver could use smc SiP func id.
There is no end to conforming to protocols. Controller drivers should be written having no particular client in mind.
If the func-id needs be passed from user, then the
chan_idsuggested by Sudeep should also be passed from user, not in mailbox driver.Quoted 7 lines
Jassi, so from your point,
arm_smc_send_datajust send a0 - a6 to firmware, right?Sudeep, Andre, Florian,
What's your suggestion? SCMI not support, do you have plan to add smc transport in SCMI?
On the platforms that I work with, we have taken the liberty of implementing SCMI in our monitor firmware because the other MCU we use for dynamic voltage and frequency scaling did not have enough memory to support that and we still had the ability to make that firmware be trusted enough we could give it power management responsibilities. I would certainly feel more comfortable if the SCMI specification was amended to indicate that the Agent could be such a software entity, still residing on the same host CPU as the Platform(s), but if not, that's fine.
This has lead us to implement a mailbox driver that uses a proprietary SMC call for the P2A path ("tx" channel) and the return being done via either that same SMC or through SGI. You can take a look at it in our downstream tree here actually:
Quoted 7 lines
https://github.com/Broadcom/stblinux-4.9/blob/master/linux/drivers/mailbox/brcmstb-mailbox.c
If we can get rid of our own driver and uses a standard SMC based mailbox driver that supports our use case that involves interrupts (we can always change their kind without our
firmware/bootloader since FDT is generated from that component), that would be great.static
irqreturn_tbrcm_isr(void){ mbox_chan_received_data(&chans[0], NULL); return IRQ_HANDLED; }
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
Sorry, I fail to understand why the irq can't be moved inside the client driver itself? There can't be more cost to it and there definitely is no functionality lost.
What if there are multiple clients ?
There is a flag
IRQF_SHAREDfor such situations.
Indeed, we can use it.
Quoted 2 lines
(good to see you considering multiple clients per channel as a legit scenario)
Not single channel, but single IRQ shared by multiple channels. We can have multiple SMC based mailbox but one shared IRQ.
Quoted 4 lines
Quoted 3 lines
And I assume you are referring to case like this where IRQ is not tied to the mailbox IP.
Yes, and that is the reason the irq should not be manageid by the mailbox driver.
Thanks for confirmation.
--
Regards,
Sudeep
Re: [PATCH V2 2/2] mailbox: introduce ARM SMC based mailbox
In reply to Sudeep HollaQuoted 45 lines · Sudeep Holla
Quoted 19 lines · Florian Fainelli
Quoted 10 lines · Peng Fan
Quoted 6 lines
Quoted 4 lines
The firmware driver might not have func-id, such as SCMI/SCPI. So add an optional func-id to let smc mailbox driver could use smc SiP func id.
There is no end to conforming to protocols. Controller drivers should be written having no particular client in mind.
If the func-id needs be passed from user, then the
chan_idsuggested by Sudeep should also be passed from user, not in mailbox driver.Quoted 7 lines
Jassi, so from your point,
arm_smc_send_datajust send a0 - a6 to firmware, right?Sudeep, Andre, Florian,
What's your suggestion? SCMI not support, do you have plan to add smc transport in SCMI?
Quoted 10 lines
On the platforms that I work with, we have taken the liberty of implementing SCMI in our monitor firmware because the other MCU we use for dynamic voltage and frequency scaling did not have enough memory to support that and we still had the ability to make that firmware be trusted enough we could give it power management responsibilities. I would certainly feel more comfortable if the SCMI specification was amended to indicate that the Agent could be such a software entity, still residing on the same host CPU as the Platform(s), but if not, that's fine.
That's completely legal and there's nothing in the specification that prohibits. I understand it's not explicitly not mentioned and I have been trying to get such things clarified. But since it's main focus is on the message protocol, the clarity on transport mechanism is very thin and there's hesitation to add more details under the impression that it may restrict the usage.
But as I mentioned, I understand what you need there :)
Quoted 5 lines
This has lead us to implement a mailbox driver that uses a proprietary SMC call for the P2A path ("tx" channel) and the return being done via either that same SMC or through SGI. You can take a look at it in our downstream tree here actually:
Quoted 6 lines
Quoted 2 lines
https://github.com/Broadcom/stblinux-4.9/blob/master/linux/drivers/mailbox/brcmstb-mailbox.c
Just curious, I see it's fast call and why do you still depend on interrupt to indicate completion of the message. Will the return from SMC not suffice ? Sorry if I am missing something obvious.
It is currently used for synchronous delayed responses where the SMC call returns early, but the operation is carried out asynchronously by e.g: the MCU that does voltage scaling a few milliseconds later. We'd rather not block the caller for too long and that's where it stems from.
Signature · 1 line
Florian
Rob Herring
maintainerRe: [PATCH V2 1/2] DT: mailbox: add binding doc for the ARM SMC mailbox
In reply to [email protected]Quoted 99 lines · On Mon, Jun 03, 2019 at 04:30:04PM +0800, [email protected] wrote:
From: Peng Fan <[email protected]>
The ARM SMC mailbox binding describes a firmware interface to trigger actions in software layers running in the EL2 or EL3 exception levels. The term "ARM" here relates to the SMC instruction as part of the ARM instruction set, not as a standard endorsed by ARM Ltd.
Signed-off-by Peng Fan <[email protected]>---
V2:
Introduce interrupts as a property.V1:
arm,func-ids is still kept as an optional property, because there is no defined SMC funciton id passed from SCMI. So in my test, I still use arm,func-ids for ARM SIP service..../devicetree/bindings/mailbox/arm-smc.txt | 101 +++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 Documentation/devicetree/bindings/mailbox/arm-smc.txtDocumentation/devicetree/bindings/mailbox/arm-smc.txt new file +71
-0@@ -0,0 +1,101 @@ +ARM SMC Mailbox Interface +========================= + +This mailbox uses the ARM smc (secure monitor call) instruction to trigger +a mailbox-connected activity in firmware, executing on the very same core +as the caller. By nature this operation is synchronous and this mailbox +provides no way for asynchronous messages to be delivered the other way +round, from firmware to the OS, but asynchronous notification could also +be supported. However the value of r0/w0/x0 the firmware returns after +the smc call is delivered as a received message to the mailbox framework, +so a synchronous communication can be established, for a asynchronous +notification, no value will be returned. The exact meaning of both the +action the mailbox triggers as well as the return value is defined by +their users and is not subject to this binding. + +One use case of this mailbox is the SCMI interface, which uses shared memory +to transfer commands and parameters, and a mailbox to trigger a function +call. This allows SoCs without a separate management processor (or when +such a processor is not available or used) to use this standardized +interface anyway. + +This binding describes no hardware, but establishes a firmware interface. +Upon receiving an SMC using one of the described SMC function identifiers, +the firmware is expected to trigger some mailbox connected functionality. +The communication follows the ARM SMC calling convention[1]. +Firmware expects an SMC function identifier in r0 or w0. The supported +identifiers are passed from consumers, or listed in the the arm,func-ids +properties as described below. The firmware can return one value in +the first SMC result register, it is expected to be an error value, +which shall be propagated to the mailbox client. + +Any core which supports the SMC or HVC instruction can be used, as long as +a firmware component running in EL3 or EL2 is handling these calls. + +Mailbox Device Node: +==================== + +This node is expected to be a child of the /firmware node. + +Required properties: +-------------------- +- compatible: Shall be "arm,smc-mbox" +- #mbox-cells Shall be 1 - the index of the channel needed. +- arm,num-chans The number of channels supported. +- method: A string, either: + "hvc": if the driver shall use an HVC call, or + "smc": if the driver shall use an SMC call. + +Optional properties: +- arm,func-ids An array of 32-bit values specifying the function + IDs used by each mailbox channel. Those function IDs + follow the ARM SMC calling convention standard [1]. + There is one identifier per channel and the number + of supported channels is determined by the length + of this array. +- interrupts SPI interrupts may be listed for notification, + each channel should use a dedicated interrupt + line. + +Example: +-------- + + sram@910000 { + compatible = "mmio-sram"; + reg = <0x0 0x93f000 0x0 0x1000>; + #address-cells = <1>; + #size-cells = <1>; + ranges = <0 0x0 0x93f000 0x1000>; + + cpu_scp_lpri: scp-shmem@0 { + compatible = "arm,scmi-shmem";
Documentation/devicetree/bindings/mailbox/arm-smc.txt line 81
Quoted 10 lines
Documentation/devicetree/bindings/mailbox/arm-smc.txt new file +10
-0+ reg = <0x0 0x200>; + }; + + cpu_scp_hpri: scp-shmem@200 { + compatible = "arm,scmi-shmem"; + reg = <0x200 0x200>; + }; + }; + + smc_mbox: mailbox {
This should be a child of 'firmware' node at least and really a child of the firmware component that implements the feature.
Quoted 23 lines
Documentation/devicetree/bindings/mailbox/arm-smc.txt new file +20
-0+ #mbox-cells = <1>; + compatible = "arm,smc-mbox"; + method = "smc"; + arm,num-chans = <0x2>; + /* Optional */ + arm,func-ids = <0xc20000fe>, <0xc20000ff>; + }; + + firmware { + scmi { + compatible = "arm,scmi"; + mboxes = <&mailbox 0 &mailbox 1>; + mbox-names = "tx", "rx"; + shmem = <&cpu_scp_lpri &cpu_scp_hpri>; + }; + }; + + +[1] +http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.den0028a/index.htmlSignature · 1 line
2.16.4
RE: [PATCH V2 1/2] DT: mailbox: add binding doc for the ARM SMC mailbox
Hi Rob,
Quoted 113 lines
Subject: Re: [PATCH V2 1/2] DT: mailbox: add binding doc for the ARM SMC mailbox
Quoted 13 lines · On Mon, Jun 03, 2019 at 04:30:04PM +0800, [email protected] wrote:
From: Peng Fan <[email protected]>
The ARM SMC mailbox binding describes a firmware interface to trigger actions in software layers running in the EL2 or EL3 exception levels. The term "ARM" here relates to the SMC instruction as part of the ARM instruction set, not as a standard endorsed by ARM Ltd.
Signed-off-by Peng Fan <[email protected]>---
V2:
Introduce interrupts as a property.Quoted 6 lines
V1:
arm,func-ids is still kept as an optional property, because there is no defined SMC funciton id passed from SCMI. So in my test, I still use arm,func-ids for ARM SIP service..../devicetree/bindings/mailbox/arm-smc.txt | 101+++++++++++++++++++++
Quoted 15 lines
1 file changed, 101 insertions(+) create mode 100644
Documentation/devicetree/bindings/mailbox/arm-smc.txtDocumentation/devicetree/bindings/mailbox/arm-smc.txt new file +4
-0@@ -0,0 +1,101 @@ +ARM SMC Mailbox Interface +========================= + +This mailbox uses the ARM smc (secure monitor call) instruction toDocumentation/devicetree/bindings/mailbox/arm-smc.txt line 14
Quoted 10 lines
Documentation/devicetree/bindings/mailbox/arm-smc.txt new file +10
-0+trigger a mailbox-connected activity in firmware, executing on the +very same core as the caller. By nature this operation is synchronous +and this mailbox provides no way for asynchronous messages to be +delivered the other way round, from firmware to the OS, but +asynchronous notification could also be supported. However the value +of r0/w0/x0 the firmware returns after the smc call is delivered as a +received message to the mailbox framework, so a synchronous +communication can be established, for a asynchronous notification, no +value will be returned. The exact meaning of both the action the +mailbox triggers as well as the return value is defined by their users and isnot subject to this binding.
Documentation/devicetree/bindings/mailbox/arm-smc.txt line 24
Quoted 10 lines
Documentation/devicetree/bindings/mailbox/arm-smc.txt new file +10
-0+ +One use case of this mailbox is the SCMI interface, which uses shared +memory to transfer commands and parameters, and a mailbox to trigger +a function call. This allows SoCs without a separate management +processor (or when such a processor is not available or used) to use +this standardized interface anyway. + +This binding describes no hardware, but establishes a firmware interface. +Upon receiving an SMC using one of the described SMC function +identifiers, the firmware is expected to trigger some mailbox connectedfunctionality.
Quoted 52 lines
Documentation/devicetree/bindings/mailbox/arm-smc.txt new file +52
-0+The communication follows the ARM SMC calling convention[1]. +Firmware expects an SMC function identifier in r0 or w0. The +supported identifiers are passed from consumers, or listed in the the +arm,func-ids properties as described below. The firmware can return +one value in the first SMC result register, it is expected to be an +error value, which shall be propagated to the mailbox client. + +Any core which supports the SMC or HVC instruction can be used, as +long as a firmware component running in EL3 or EL2 is handling these calls. + +Mailbox Device Node: +==================== + +This node is expected to be a child of the /firmware node. + +Required properties: +-------------------- +- compatible: Shall be "arm,smc-mbox" +- #mbox-cells Shall be 1 - the index of the channel needed. +- arm,num-chans The number of channels supported. +- method: A string, either: + "hvc": if the driver shall use an HVC call, or + "smc": if the driver shall use an SMC call. + +Optional properties: +- arm,func-ids An array of 32-bit values specifying the function + IDs used by each mailbox channel. Those function IDs + follow the ARM SMC calling convention standard [1]. + There is one identifier per channel and the number + of supported channels is determined by the length + of this array. +- interrupts SPI interrupts may be listed for notification, + each channel should use a dedicated interrupt + line. + +Example: +-------- + + sram@910000 { + compatible = "mmio-sram"; + reg = <0x0 0x93f000 0x0 0x1000>; + #address-cells = <1>; + #size-cells = <1>; + ranges = <0 0x0 0x93f000 0x1000>; + + cpu_scp_lpri: scp-shmem@0 { + compatible = "arm,scmi-shmem"; + reg = <0x0 0x200>; + }; + + cpu_scp_hpri: scp-shmem@200 { + compatible = "arm,scmi-shmem";
Quoted 8 lines
Documentation/devicetree/bindings/mailbox/arm-smc.txt line 81
Quoted 5 lines
Documentation/devicetree/bindings/mailbox/arm-smc.txt new file +5
-0+ reg = <0x200 0x200>; + }; + }; + + smc_mbox: mailbox {This should be a child of 'firmware' node at least and really a child of the firmware component that implements the feature.
I checked other mbox driver, including the mbox used by ti sci, mbox used by i.MX8QXP. both mbox dts node not a child a firmware node,
I am not sure why put mbox node into a child a firmware node here.
Thanks,
Peng.
Quoted 37 lines
Quoted 12 lines
Documentation/devicetree/bindings/mailbox/arm-smc.txt new file +10
-0+ #mbox-cells = <1>; + compatible = "arm,smc-mbox"; + method = "smc"; + arm,num-chans = <0x2>; + /* Optional */ + arm,func-ids = <0xc20000fe>, <0xc20000ff>; + }; + + firmware { + scmi {Documentation/devicetree/bindings/mailbox/arm-smc.txt
Quoted 10 lines
Documentation/devicetree/bindings/mailbox/arm-smc.txt new file +10
-0+ compatible = "arm,scmi"; + mboxes = <&mailbox 0 &mailbox 1>; + mbox-names = "tx", "rx"; + shmem = <&cpu_scp_lpri &cpu_scp_hpri>; + }; + }; + + +[1] +https://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Finfo+center.arm.com%2Fhelp%2Findex.jsp%3Ftopic%3D%2Fcom.arm.doc.den002 8a%2
Quoted 1 line
+Findex.html&data=02%7C01%7Cpeng.fan%40nxp.com%7Cd8cf8b81b4f b49be5
Quoted 1 line
+97c08d703f26576%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C1%7 C63698221
Quoted 1 line
+1931902513&sdata=RtHkNN07b%2FuzdJkiu0QujeJ6czrcwOwEI6Y6JW VpPkY%3D
Quoted 4 lines
+&reserved=0
--
2.16.4
Rob Herring
maintainerRe: [PATCH V2 1/2] DT: mailbox: add binding doc for the ARM SMC mailbox
Quoted 125 lines · Peng Fan
Hi Rob,
Quoted 113 lines
Subject: Re: [PATCH V2 1/2] DT: mailbox: add binding doc for the ARM SMC mailbox
Quoted 13 lines · On Mon, Jun 03, 2019 at 04:30:04PM +0800, [email protected] wrote:
From: Peng Fan <[email protected]>
The ARM SMC mailbox binding describes a firmware interface to trigger actions in software layers running in the EL2 or EL3 exception levels. The term "ARM" here relates to the SMC instruction as part of the ARM instruction set, not as a standard endorsed by ARM Ltd.
Signed-off-by Peng Fan <[email protected]>---
V2:
Introduce interrupts as a property.Quoted 6 lines
V1:
arm,func-ids is still kept as an optional property, because there is no defined SMC funciton id passed from SCMI. So in my test, I still use arm,func-ids for ARM SIP service..../devicetree/bindings/mailbox/arm-smc.txt | 101+++++++++++++++++++++
Quoted 15 lines
1 file changed, 101 insertions(+) create mode 100644
Documentation/devicetree/bindings/mailbox/arm-smc.txtDocumentation/devicetree/bindings/mailbox/arm-smc.txt new file +4
-0@@ -0,0 +1,101 @@ +ARM SMC Mailbox Interface +========================= + +This mailbox uses the ARM smc (secure monitor call) instruction toDocumentation/devicetree/bindings/mailbox/arm-smc.txt line 14
Quoted 10 lines
Documentation/devicetree/bindings/mailbox/arm-smc.txt new file +10
-0+trigger a mailbox-connected activity in firmware, executing on the +very same core as the caller. By nature this operation is synchronous +and this mailbox provides no way for asynchronous messages to be +delivered the other way round, from firmware to the OS, but +asynchronous notification could also be supported. However the value +of r0/w0/x0 the firmware returns after the smc call is delivered as a +received message to the mailbox framework, so a synchronous +communication can be established, for a asynchronous notification, no +value will be returned. The exact meaning of both the action the +mailbox triggers as well as the return value is defined by their users and isnot subject to this binding.
Documentation/devicetree/bindings/mailbox/arm-smc.txt line 24
Quoted 10 lines
Documentation/devicetree/bindings/mailbox/arm-smc.txt new file +10
-0+ +One use case of this mailbox is the SCMI interface, which uses shared +memory to transfer commands and parameters, and a mailbox to trigger +a function call. This allows SoCs without a separate management +processor (or when such a processor is not available or used) to use +this standardized interface anyway. + +This binding describes no hardware, but establishes a firmware interface. +Upon receiving an SMC using one of the described SMC function +identifiers, the firmware is expected to trigger some mailbox connectedfunctionality.
Quoted 52 lines
Documentation/devicetree/bindings/mailbox/arm-smc.txt new file +52
-0+The communication follows the ARM SMC calling convention[1]. +Firmware expects an SMC function identifier in r0 or w0. The +supported identifiers are passed from consumers, or listed in the the +arm,func-ids properties as described below. The firmware can return +one value in the first SMC result register, it is expected to be an +error value, which shall be propagated to the mailbox client. + +Any core which supports the SMC or HVC instruction can be used, as +long as a firmware component running in EL3 or EL2 is handling these calls. + +Mailbox Device Node: +==================== + +This node is expected to be a child of the /firmware node. + +Required properties: +-------------------- +- compatible: Shall be "arm,smc-mbox" +- #mbox-cells Shall be 1 - the index of the channel needed. +- arm,num-chans The number of channels supported. +- method: A string, either: + "hvc": if the driver shall use an HVC call, or + "smc": if the driver shall use an SMC call. + +Optional properties: +- arm,func-ids An array of 32-bit values specifying the function + IDs used by each mailbox channel. Those function IDs + follow the ARM SMC calling convention standard [1]. + There is one identifier per channel and the number + of supported channels is determined by the length + of this array. +- interrupts SPI interrupts may be listed for notification, + each channel should use a dedicated interrupt + line. + +Example: +-------- + + sram@910000 { + compatible = "mmio-sram"; + reg = <0x0 0x93f000 0x0 0x1000>; + #address-cells = <1>; + #size-cells = <1>; + ranges = <0 0x0 0x93f000 0x1000>; + + cpu_scp_lpri: scp-shmem@0 { + compatible = "arm,scmi-shmem"; + reg = <0x0 0x200>; + }; + + cpu_scp_hpri: scp-shmem@200 { + compatible = "arm,scmi-shmem";Quoted 8 lines
Documentation/devicetree/bindings/mailbox/arm-smc.txt line 81
Quoted 5 lines
Documentation/devicetree/bindings/mailbox/arm-smc.txt new file +5
-0+ reg = <0x200 0x200>; + }; + }; + + smc_mbox: mailbox {This should be a child of 'firmware' node at least and really a child of the firmware component that implements the feature.
Quoted 2 lines
I checked other mbox driver, including the mbox used by ti sci, mbox used by i.MX8QXP. both mbox dts node not a child a firmware node,
Because those are actual h/w blocks and not implemented in firmware calls?
Quoted 1 line
I am not sure why put mbox node into a child a firmware node here.
If it is an interface provided by firmware, then it goes under /firmware.
Rob