Skip to contentSkip to conversation

soc: imx: add scu firmware api support

PATCH Superseded Dong Aisheng 7 participants 28 messages Jul 8, 2018 – Jul 12, 2018

Subsystems (3)

v4 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v4 cover soc: imx: add scu firmware api support

Unlike the former i.MX Architectures, the new generation i.MX8 SoCs (e.g. MX8QXP and MX8QM) contain a system controller which runs on a dedicated Cortex-M core to provide power, clock, Pad, and resource management. Communication between the host processor running an OS and the system controller happens through a SCU protocol. This patchset adds the SCU APIs which is implemented based on MU and will be used by different system components.

It mainly consists of below parts:
1) MU mailbox driver
1) Implementation of the IPC functions based on MUs (client side).

Dong Aisheng (5):
dt-bindings: mailbox: allow mbox-cells to be equal to 0
dt-bindings: arm: fsl: add mu binding doc
mailbox: imx: add imx mu support
dt-bindings: arm: fsl: add scu binding doc
soc: imx: add SC firmware IPC and APIs

 .../devicetree/bindings/arm/freescale/fsl,scu.txt  |  65 ++
 .../devicetree/bindings/mailbox/fsl,mu.txt         |  34 +
 .../devicetree/bindings/mailbox/mailbox.txt        |   3 +-
 drivers/mailbox/Kconfig                            |   8 +
 drivers/mailbox/Makefile                           |   2 +
 drivers/mailbox/imx-mu.c                           | 341 +++++++++
 drivers/soc/imx/Kconfig                            |   4 +
 drivers/soc/imx/Makefile                           |   1 +
 drivers/soc/imx/sc/Makefile                        |   2 +
 drivers/soc/imx/sc/main/ipc.c                      | 185 +++++
 drivers/soc/imx/sc/main/rpc.h                      |  79 +++
 include/soc/imx/sc/ipc.h                           |  45 ++
 include/soc/imx/sc/scfw.h                          |  24 +
 include/soc/imx/sc/types.h                         | 764 +++++++++++++++++++++
 14 files changed, 1555 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/arm/freescale/fsl,scu.txt
 create mode 100644 Documentation/devicetree/bindings/mailbox/fsl,mu.txt
 create mode 100644 drivers/mailbox/imx-mu.c
 create mode 100644 drivers/soc/imx/sc/Makefile
 create mode 100644 drivers/soc/imx/sc/main/ipc.c
 create mode 100644 drivers/soc/imx/sc/main/rpc.h
 create mode 100644 include/soc/imx/sc/ipc.h
 create mode 100644 include/soc/imx/sc/scfw.h
 create mode 100644 include/soc/imx/sc/types.h
Signature · 1 line
2.7.4
#1 lore raw

PATCH v4 1/5 dt-bindings: mailbox: allow mbox-cells to be equal to 0

Mailbox devices may have only one channel which means the mbox-cells at least 1 does not make sense for this type devices. Let's remove that limitation to allow the mbox-cells to be equal to 0.

Cc Mark Rutland <[email protected]>
Cc Sudeep Holla <[email protected]>
Cc devicetree at vger.kernel.org
Cc linux-kernel at vger.kernel.org

---
ChangeLog:
* New patch introduced in v3 series
* Actually there're already users in kernel with mbox-cells set to 0. See:
arch/arm/boot/dts/bcm283x.dtsi:145: #mbox-cells = <0>;

---
 Documentation/devicetree/bindings/mailbox/mailbox.txt | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
Documentation/devicetree/bindings/mailbox/mailbox.txt +1 -2
index af8ecee..c2fcd05 100644
@@ -6,8 +6,7 @@ assign appropriate mailbox channel to client drivers.
 * Mailbox Controller
 
 Required property:
-- #mbox-cells: Must be at least 1. Number of cells in a mailbox
-		specifier.
+- #mbox-cells: Number of cells in a mailbox specifier.
 
 Example:
 	mailbox: mailbox {
Signature · 1 line
2.7.4
#2 lore raw

PATCH v4 2/5 dt-bindings: arm: fsl: add mu binding doc

In reply to Dong Aisheng

The Messaging Unit module enables two processors within the SoC to communicate and coordinate by passing messages (e.g. data, status and control) through the MU interface.

Cc Shawn Guo <[email protected]>
Cc Sascha Hauer <[email protected]>
Cc Fabio Estevam <[email protected]>
Cc Rob Herring <[email protected]>
Cc Mark Rutland <[email protected]>
Cc devicetree at vger.kernel.org

---
v3->v4:
* move into Documentation/devicetree/bindings/mailbox/fsl,mu.txt
v2->v3:
* change to mailbox binding
Currently mbox-cells has to be 0 for SCU MU.
Generic MU Mailbox support binding could be extended later.
v1->v2:
* typo fixes
* remove status property
* remove imx6&7 compatible string which may be added later for the generic mailbox binding

---
 .../devicetree/bindings/mailbox/fsl,mu.txt         | 34 ++++++++++++++++++++++
 1 file changed, 34 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mailbox/fsl,mu.txt
Documentation/devicetree/bindings/mailbox/fsl,mu.txt new file +34 -0
new file mode 100644
index 0000000..90e4905
@@ -0,0 +1,34 @@
+NXP i.MX Messaging Unit (MU)
+--------------------------------------------------------------------
+
+The Messaging Unit module enables two processors within the SoC to
+communicate and coordinate by passing messages (e.g. data, status
+and control) through the MU interface. The MU also provides the ability
+for one processor to signal the other processor using interrupts.
+
+Because the MU manages the messaging between processors, the MU uses
+different clocks (from each side of the different peripheral buses).
+Therefore, the MU must synchronize the accesses from one side to the
+other. The MU accomplishes synchronization using two sets of matching
+registers (Processor A-facing, Processor B-facing).
+
+Messaging Unit Device Node:
+=============================
+
+Required properties:
+-------------------
+- compatible :	should be "fsl,<chip>-mu", the supported chips include
+		imx8qxp, imx8qm.
+- reg :		Should contain the registers location and length
+- interrupts :	Interrupt number. The interrupt specifier format depends
+		on the interrupt controller parent.
+- #mbox-cells:  Must be 0. Number of cells in a mailbox
+
+Examples:
+--------
+lsio_mu0: mailbox at 5d1b0000 {
+	compatible = "fsl,imx8qxp-mu";
+	reg = <0x0 0x5d1b0000 0x0 0x10000>;
+	interrupts = <GIC_SPI 176 IRQ_TYPE_LEVEL_HIGH>;
+	#mbox-cells = <0>;
+};
Signature · 1 line
2.7.4
maintainer
#3 lore raw

PATCH v4 2/5 dt-bindings: arm: fsl: add mu binding doc

Quoted 23 lines · Dong Aisheng

The Messaging Unit module enables two processors within the SoC to communicate and coordinate by passing messages (e.g. data, status and control) through the MU interface.

Cc Shawn Guo <[email protected]>
Cc Sascha Hauer <[email protected]>
Cc Fabio Estevam <[email protected]>
Cc Rob Herring <[email protected]>
Cc Mark Rutland <[email protected]>
Cc devicetree at vger.kernel.org

---
v3->v4:
* move into Documentation/devicetree/bindings/mailbox/fsl,mu.txt
v2->v3:
* change to mailbox binding
Currently mbox-cells has to be 0 for SCU MU.
Generic MU Mailbox support binding could be extended later.
v1->v2:
* typo fixes
* remove status property
* remove imx6&7 compatible string which may be added later for the generic mailbox binding

Quoted 4 lines
---
 .../devicetree/bindings/mailbox/fsl,mu.txt         | 34 ++++++++++++++++++++++
 1 file changed, 34 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mailbox/fsl,mu.txt
#4 lore raw

PATCH v4 3/5 mailbox: imx: add imx mu support

In reply to Dong Aisheng

This is used for i.MX multi core communication.
e.g. A core to SCU firmware(M core) on MX8.

Tx is using polling mode while Rx is interrupt driven and schedule a hrtimer to receive remain words if have more than 4 words.

Cc Jassi Brar <[email protected]>
Cc linux-kernel at vger.kernel.org
Cc Shawn Guo <[email protected]>
Cc Sascha Hauer <[email protected]>
Cc Oleksij Rempel <[email protected]>
Cc Fabio Estevam <[email protected]>

---
v3->v4:
* New patch
Old MU library dropped

---
 drivers/mailbox/Kconfig  |   8 ++
 drivers/mailbox/Makefile |   2 +
 drivers/mailbox/imx-mu.c | 341 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 351 insertions(+)
 create mode 100644 drivers/mailbox/imx-mu.c
drivers/mailbox/Kconfig +8 -0
index a2bb274..4dd4823 100644
@@ -124,6 +124,14 @@ config HI6220_MBOX
 	  between application processors and MCU. Say Y here if you want to
 	  build Hi6220 mailbox controller driver.
 
+config IMX_MU
+	tristate "IMX MU Mailbox"
+	depends on ARCH_MXC && OF
+	help
+	  An implementation of the i.MX MU Mailbox. It is used to send message
+	  between application processors and other processors/MCU/DSP. Select
+	  Y here if you want to use i.MX MU Mailbox controller.
+
 config MAILBOX_TEST
 	tristate "Mailbox Test Client"
 	depends on OF
drivers/mailbox/Makefile +2 -0
index cc23c3a..fa62f07 100644
@@ -31,6 +31,8 @@ obj-$(CONFIG_HI3660_MBOX)	+= hi3660-mailbox.o
 
 obj-$(CONFIG_HI6220_MBOX)	+= hi6220-mailbox.o
 
+obj-$(CONFIG_IMX_MU)		+= imx-mu.o
+
 obj-$(CONFIG_BCM_PDC_MBOX)	+= bcm-pdc-mailbox.o
 
 obj-$(CONFIG_BCM_FLEXRM_MBOX)	+= bcm-flexrm-mailbox.o
drivers/mailbox/imx-mu.c new file +341 -0

341 lines not on this page · raw message

Signature · 1 line
2.7.4
maintainer
#5 lore raw

Re: [PATCH V4 3/5] mailbox: imx: add imx mu support

Hi,

Quoted 6 lines · Dong Aisheng

This is used for i.MX multi core communication.
e.g. A core to SCU firmware(M core) on MX8.

Tx is using polling mode while Rx is interrupt driven and schedule a hrtimer to receive remain words if have more than 4 words.

You told us that using interrupts is not possible due to miserable performance, we then provided you a way with which you could poll. Why are you using interrupts now?

We also suggested a way how the SCU mode could be integrated into the generic MU support driver Oleksij posted and now you send a driver which uses the same name as Oleksijs driver, but it only and exclusively works in SCU mode. This doesn't bring us forward.

We suggested a binding that allows coexisting of the SCU mode and the generic mode of the MU by putting the mode information into the second mbox-cell. Why don't you use this?

I don't think it's necessary to rewrite Oleksijs driver, instead it should rather be extended with the code I already provided as an example. With that we could make both of us happy since we can both have a suitable driver and even share most of the MU code.

Regards,
Sascha

Signature · 4 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
author
#6 lore raw

RE: [PATCH V4 3/5] mailbox: imx: add imx mu support

Hi Sascha,

Quoted 17 lines

-----Original Message-----
From: Sascha Hauer [mailto:s.hauer at pengutronix.de]
Sent: Tuesday, July 10, 2018 10:20 PM
To: A.s. Dong <[email protected]>
Cc: linux-arm-kernel at lists.infradead.org; dongas86 at gmail.com; Jassi Brar <[email protected]>; linux-kernel at vger.kernel.org; Oleksij Rempel <[email protected]>; dl-linux-imx <[email protected]>; kernel at pengutronix.de; Fabio Estevam <[email protected]>; shawnguo at kernel.org
Subject: Re: [PATCH V4 3/5] mailbox: imx: add imx mu support

Hi,

Quoted 3 lines · Dong Aisheng

This is used for i.MX multi core communication.
e.g. A core to SCU firmware(M core) on MX8.

Quoted 8 lines
Quoted 3 lines

Tx is using polling mode while Rx is interrupt driven and schedule a hrtimer to receive remain words if have more than
4 words.

You told us that using interrupts is not possible due to miserable performance, we then provided you a way with which you could poll. Why are you using interrupts now?

Because mailbox framework does not support sync rx now, I think we do not need to wait for that feature done first as it's independent and separate features of framework.

So for now, we're just using the common way in kernel as arm scpi and ti sci. When framework supports it, we can easily switch to it.

I optimized the performance a bit by removing the unnecessary memcopy between tx/tx messages. The test result of booting time shows there's no obvious regressions. I'm not sure whether it's due to we're booting a minimum system or the extra cost is very minor to be noticed due to not too much cmds sent during booting.
(Copy Peng to comments more as he tried and reported that performance drop with vendor tree)

Quoted 1 line

From the time measurement of sc_call_rpc, we can see that most rpc command

In polling mode can finish within 10us and very rare ones over 20us. If switched to irq mode, those 10us cmds will change to about 20us.

But the overall booting time did not increase much. Maybe the irq mode also saves some CPU MIPS to execute other works in parallel?

Quoted 5 lines

We also suggested a way how the SCU mode could be integrated into the generic MU support driver Oleksij posted and now you send a driver which uses the same name as Oleksijs driver, but it only and exclusively works in SCU mode. This doesn't bring us forward.

Can Oleksij's patch be implemented against this one?
As I remember you said we've still not determined whether Oleksij's approach is the most suitable way and it's still under discussion. (Actually TI's approach looks better which is more simiar as SCU way?)

Furthermore, from this patch, you will notice that Oleksij's patch almost did not work for SCU at all. I have to totally rewrite one for SCU. So I did not write against his patch as it does not help.
And Oleksij's patch is quite simple while the SCU one is much complicated than his one. So we probably better get SCU done first.

Quoted 4 lines

We suggested a binding that allows coexisting of the SCU mode and the generic mode of the MU by putting the mode information into the second mbox-cell. Why don't you use this?

You mean this?
+#define IMX_MU_CHANNEL0 0
+#define IMX_MU_CHANNEL1 1
+#define IMX_MU_CHANNEL2 2
+#define IMX_MU_CHANNEL3 3
+#define IMX_MU_CHANNEL_IMX8_SCU 4

It's hard for me to believe it's correct and it's over abstract to HW. So I thought using mbox-cells to distinguish seems to be better.

Quoted 4 lines

I don't think it's necessary to rewrite Oleksijs driver, instead it should rather be extended with the code I already provided as an example. With that we could make both of us happy since we can both have a suitable driver and even share most of the MU code.

As I said above, I even can't reuse 90%+ code of Oleksijs driver. So I can't see the meaning to demo the code on top of this driver. We can review the SCU implementation directly with this driver which is more easy. Then we can decide how to merge them together.

Regards
Dong Aisheng

Quoted 14 lines

Regards,
Sascha

--
Pengutronix e.K. | |
Industrial Linux Solutions |
https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fww
w.pengutronix.de%2F&amp;data=02%7C01%7Caisheng.dong%40nxp.com%7 Cb359a3eddee54bf1b40a08d5e6702f22%7C686ea1d3bc2b4c6fa92cd99c5c301 635%7C0%7C0%7C636668291863846639&amp;sdata=hSucaLRfCB1j1McwlfO% 2FL0921QXiHg68sl%2B23CvEp4Q%3D&amp;reserved=0 |

Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
maintainer
#7 lore raw

Re: [PATCH V4 3/5] mailbox: imx: add imx mu support

Quoted 23 lines · A.s. Dong

Hi Sascha,

Quoted 21 lines

-----Original Message-----
From: Sascha Hauer [mailto:s.hauer at pengutronix.de]
Sent: Tuesday, July 10, 2018 10:20 PM
To: A.s. Dong <[email protected]>
Cc: linux-arm-kernel at lists.infradead.org; dongas86 at gmail.com; Jassi Brar <[email protected]>; linux-kernel at vger.kernel.org; Oleksij Rempel <[email protected]>; dl-linux-imx <[email protected]>; kernel at pengutronix.de; Fabio Estevam <[email protected]>; shawnguo at kernel.org
Subject: Re: [PATCH V4 3/5] mailbox: imx: add imx mu support

Hi,

Quoted 6 lines · Dong Aisheng

This is used for i.MX multi core communication.
e.g. A core to SCU firmware(M core) on MX8.

Tx is using polling mode while Rx is interrupt driven and schedule a hrtimer to receive remain words if have more than
4 words.

Quoted 8 lines
Quoted 4 lines

You told us that using interrupts is not possible due to miserable performance, we then provided you a way with which you could poll. Why are you using interrupts now?

Because mailbox framework does not support sync rx now, I think we do not need to wait for that feature done first as it's independent and separate features of framework.

You can wait forever for this feature, nobody will add it for you. It's up to you to add support for that feature. Who else should add this feature if not you? And when will you add that feature if not now when you actually need it?
It is common practice that you adjust the frameworks to your needs rather than working around them.

Quoted 9 lines

So for now, we're just using the common way in kernel as arm scpi and ti sci. When framework supports it, we can easily switch to it.

I optimized the performance a bit by removing the unnecessary memcopy between tx/tx messages. The test result of booting time shows there's no obvious regressions. I'm not sure whether it's due to we're booting a minimum system or the extra cost is very minor to be noticed due to not too much cmds sent during booting.

Your boot time argument seems to be a very weak one. unnecessary memcpys of a few bytes only take a fraction of the time interrupt latencies introduce.

Quoted 16 lines

(Copy Peng to comments more as he tried and reported that performance drop with vendor tree)

From the time measurement of sc_call_rpc, we can see that most rpc command In polling mode can finish within 10us and very rare ones over 20us. If switched to irq mode, those 10us cmds will change to about 20us.

But the overall booting time did not increase much. Maybe the irq mode also saves some CPU MIPS to execute other works in parallel?

Quoted 5 lines

We also suggested a way how the SCU mode could be integrated into the generic MU support driver Oleksij posted and now you send a driver which uses the same name as Oleksijs driver, but it only and exclusively works in SCU mode. This doesn't bring us forward.

Quoted 7 lines

Can Oleksij's patch be implemented against this one?
As I remember you said we've still not determined whether Oleksij's approach is the most suitable way and it's still under discussion. (Actually TI's approach looks better which is more simiar as SCU way?)

Furthermore, from this patch, you will notice that Oleksij's patch almost did not work for SCU at all. I have to totally rewrite one for SCU.

You are kidding. You have to rewrite it because you didn't follow my suggestion to implement polling in the mailbox framework.

Quoted 10 lines

So I did not write against his patch as it does not help.
And Oleksij's patch is quite simple while the SCU one is much complicated than his one. So we probably better get SCU done first.

Quoted 4 lines

We suggested a binding that allows coexisting of the SCU mode and the generic mode of the MU by putting the mode information into the second mbox-cell. Why don't you use this?

You mean this?

Review

Quoted 5 lines
(quoted diff) +5 -0
+#define IMX_MU_CHANNEL0		0
+#define IMX_MU_CHANNEL1		1
+#define IMX_MU_CHANNEL2		2
+#define IMX_MU_CHANNEL3		3
+#define IMX_MU_CHANNEL_IMX8_SCU 4

Yes.

Quoted 3 lines

It's hard for me to believe it's correct and it's over abstract to HW. So I thought using mbox-cells to distinguish seems to be better.

The MU has four rx registers, four tx registers and four interrupts. What else should this be than four channels? The number of channels the MU has is obviously defined by the software running at the other end of the MU. Yes, the SCU makes one channel from it, in other cases it's four channels.

Quoted 10 lines
Quoted 5 lines

I don't think it's necessary to rewrite Oleksijs driver, instead it should rather be extended with the code I already provided as an example. With that we could make both of us happy since we can both have a suitable driver and even share most of the MU code.

As I said above, I even can't reuse 90%+ code of Oleksijs driver. So I can't see the meaning to demo the code on top of this driver. We can review the SCU implementation directly with this driver which is more easy. Then we can decide how to merge them together.

You can only not share the code because the mailbox framework does not support polling. And yes, I even provided some code which implements SCU mode ontop of Oleksijs driver.

Honestly, what I expect from you is no rocket science and we would already be there if we didn't spend our time discussing this.

Sascha

Signature · 4 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
author
#8 lore raw

RE: [PATCH V4 3/5] mailbox: imx: add imx mu support

Quoted 44 lines

-----Original Message-----
From: Sascha Hauer [mailto:s.hauer at pengutronix.de]
Sent: Wednesday, July 11, 2018 3:55 PM
To: A.s. Dong <[email protected]>
Cc: linux-arm-kernel at lists.infradead.org; dongas86 at gmail.com; Jassi Brar <[email protected]>; linux-kernel at vger.kernel.org; Oleksij Rempel <[email protected]>; dl-linux-imx <[email protected]>; kernel at pengutronix.de; Fabio Estevam <[email protected]>; shawnguo at kernel.org
Subject: Re: [PATCH V4 3/5] mailbox: imx: add imx mu support

Quoted 23 lines · A.s. Dong

Hi Sascha,

Quoted 21 lines

-----Original Message-----
From: Sascha Hauer [mailto:s.hauer at pengutronix.de]
Sent: Tuesday, July 10, 2018 10:20 PM
To: A.s. Dong <[email protected]>
Cc: linux-arm-kernel at lists.infradead.org; dongas86 at gmail.com; Jassi Brar <[email protected]>; linux-kernel at vger.kernel.org; Oleksij Rempel <[email protected]>; dl-linux-imx <[email protected]>; kernel at pengutronix.de; Fabio Estevam <[email protected]>; shawnguo at kernel.org
Subject: Re: [PATCH V4 3/5] mailbox: imx: add imx mu support

Hi,

Quoted 6 lines · Dong Aisheng

This is used for i.MX multi core communication.
e.g. A core to SCU firmware(M core) on MX8.

Tx is using polling mode while Rx is interrupt driven and schedule a hrtimer to receive remain words if have more than
4 words.

Quoted 8 lines
Quoted 4 lines

You told us that using interrupts is not possible due to miserable performance, we then provided you a way with which you could poll. Why are you using interrupts now?

Because mailbox framework does not support sync rx now, I think we do not need to wait for that feature done first as it's independent and separate features of framework.

Quoted 6 lines

You can wait forever for this feature, nobody will add it for you. It's up to you to add support for that feature. Who else should add this feature if not you? And when will you add that feature if not now when you actually need it? It is common practice that you adjust the frameworks to your needs rather than working around them.

I'm willing to add it. Just because you said Jassi already had the idea on how to Implement it and does not add much complexity. So I just want to see his patches. But if he did not work on it, I can also help on it.

Another reason is i did not observe regression as before, so it looks like the irq is an applicable way currently and not must use polling at this point as that's an independent new feature of framework. So irq mode is the quickest way to demo the mbox using as we already had experience before.

Quoted 10 lines
Quoted 9 lines

So for now, we're just using the common way in kernel as arm scpi and ti sci. When framework supports it, we can easily switch to it.

I optimized the performance a bit by removing the unnecessary memcopy between tx/tx messages. The test result of booting time shows there's no obvious regressions. I'm not sure whether it's due to we're booting a minimum system or the extra cost is very minor to be noticed due to not too much cmds sent during booting.

Quoted 4 lines

Your boot time argument seems to be a very weak one. unnecessary memcpys of a few bytes only take a fraction of the time interrupt latencies introduce.

Yes, interrupt latency may be the major part.

Quoted 22 lines
Quoted 5 lines

(Copy Peng to comments more as he tried and reported that performance drop with vendor tree)

From the time measurement of sc_call_rpc, we can see that most rpc command In polling mode can finish within 10us and very rare ones over

20us.

Quoted 16 lines

If switched to irq mode, those 10us cmds will change to about 20us.

But the overall booting time did not increase much. Maybe the irq mode also saves some CPU MIPS to execute other works in parallel?

Quoted 5 lines

We also suggested a way how the SCU mode could be integrated into the generic MU support driver Oleksij posted and now you send a driver which uses the same name as Oleksijs driver, but it only and exclusively works in SCU mode. This doesn't bring us forward.

Can Oleksij's patch be implemented against this one?
As I remember you said we've still not determined whether Oleksij's approach is the most suitable way and it's still under discussion. (Actually TI's approach looks better which is more simiar as SCU way?)

Quoted 6 lines
Quoted 2 lines

Furthermore, from this patch, you will notice that Oleksij's patch almost did not work for SCU at all. I have to totally rewrite one for SCU.

You are kidding. You have to rewrite it because you didn't follow my suggestion to implement polling in the mailbox framework.

As I said, I did not observe regression when switch to irq way. And irq way is the common mbox approach in kernel. So i just use it to quickly demo the mbox using which we already implemented. It's simple!

But I got your meaning that we must switch to polling mode now, because we want to sync with M4, right?

Quoted 19 lines
Quoted 10 lines

So I did not write against his patch as it does not help. And Oleksij's patch is quite simple while the SCU one is much complicated than his one. So we probably better get SCU done first.

Quoted 4 lines

We suggested a binding that allows coexisting of the SCU mode and the generic mode of the MU by putting the mode information into the second mbox-cell. Why don't you use this?

You mean this?

Review

Quoted 5 lines
(quoted diff) +5 -0
+#define IMX_MU_CHANNEL0		0
+#define IMX_MU_CHANNEL1		1
+#define IMX_MU_CHANNEL2		2
+#define IMX_MU_CHANNEL3		3
+#define IMX_MU_CHANNEL_IMX8_SCU 4

Yes.

Quoted 1 line
Quoted 8 lines
Quoted 2 lines

It's hard for me to believe it's correct and it's over abstract to HW. So I thought using mbox-cells to distinguish seems to be better.

The MU has four rx registers, four tx registers and four interrupts. What else should this be than four channels? The number of channels the MU has is obviously defined by the software running at the other end of the MU. Yes, the SCU makes one channel from it, in other cases it's four channels.

I'm not against 4 four channels. Just feel SCU using is strange because SCU is using it as one channel from HW point of view. Not four. And make them into four channels for M4 also lose the HW capability to send Up to 4 words at one time. That's also an issue.
(I guess we're assuming no actual users of multi words sending, right?)

So using mbox-cells to distinguish seems more reasonable. e.g.
For one channel case: (communicate with SCU) Mbox-cells = <0>;

Client_node {
	....
	Mbox =<&lsio_mu0>;
}

For 4 channel case: (communicate with M4)
Mbox-cells = <1>;

Client_node {
	....
	mbox =<&mu0 1>;
}

Anything wrong with it?

It seems more reflect the real HW and will not introduce confusion.

Quoted 11 lines
Quoted 10 lines
Quoted 5 lines

I don't think it's necessary to rewrite Oleksijs driver, instead it should rather be extended with the code I already provided as an example. With that we could make both of us happy since we can both have a suitable driver and even share most of the MU code.

As I said above, I even can't reuse 90%+ code of Oleksijs driver. So I can't see the meaning to demo the code on top of this driver. We can review the SCU implementation directly with this driver which is more easy. Then we can decide how to merge them together.

Quoted 7 lines

You can only not share the code because the mailbox framework does not support polling. And yes, I even provided some code which implements SCU mode ontop of Oleksijs driver.

Honestly, what I expect from you is no rocket science and we would already be there if we didn't spend our time discussing this.

I actually spent a lot time on it to switch to mbox to demo the using step by step, and try to merge them with M4 users later. Although I don't think it's quite worthy to do that, but I still do it Just because I respect you guys.

Quoted 1 line

From our point of view, we just tried to be more careful about the change request

as we have more information than outside.

I also don't want to stop at this point. So I will try to add sync polling in mailbox Framework and switch to it now.

Regards
Dong Aisheng

Quoted 12 lines

Sascha

--
Pengutronix e.K. | |
Industrial Linux Solutions |
https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fww
w.pengutronix.de%2F&amp;data=02%7C01%7Caisheng.dong%40nxp.com%7 Cb49570c607cf4057563d08d5e7039a70%7C686ea1d3bc2b4c6fa92cd99c5c3016 35%7C0%7C0%7C636668925017826212&amp;sdata=UT5AhUX%2FV7mCtUit0 1KSgJtf%2FdmOmmDMVz8EVebBaVk%3D&amp;reserved=0 |

Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
maintainer
#9 lore raw

Re: [PATCH V4 3/5] mailbox: imx: add imx mu support

Quoted 52 lines · A.s. Dong
Quoted 45 lines

-----Original Message-----
From: Sascha Hauer [mailto:s.hauer at pengutronix.de]
Sent: Wednesday, July 11, 2018 3:55 PM
To: A.s. Dong <[email protected]>
Cc: linux-arm-kernel at lists.infradead.org; dongas86 at gmail.com; Jassi Brar <[email protected]>; linux-kernel at vger.kernel.org; Oleksij Rempel <[email protected]>; dl-linux-imx <[email protected]>; kernel at pengutronix.de; Fabio Estevam <[email protected]>; shawnguo at kernel.org
Subject: Re: [PATCH V4 3/5] mailbox: imx: add imx mu support

Quoted 23 lines · A.s. Dong

Hi Sascha,

Quoted 21 lines

-----Original Message-----
From: Sascha Hauer [mailto:s.hauer at pengutronix.de]
Sent: Tuesday, July 10, 2018 10:20 PM
To: A.s. Dong <[email protected]>
Cc: linux-arm-kernel at lists.infradead.org; dongas86 at gmail.com; Jassi Brar <[email protected]>; linux-kernel at vger.kernel.org; Oleksij Rempel <[email protected]>; dl-linux-imx <[email protected]>; kernel at pengutronix.de; Fabio Estevam <[email protected]>; shawnguo at kernel.org
Subject: Re: [PATCH V4 3/5] mailbox: imx: add imx mu support

Hi,

Quoted 6 lines · Dong Aisheng

This is used for i.MX multi core communication.
e.g. A core to SCU firmware(M core) on MX8.

Tx is using polling mode while Rx is interrupt driven and schedule a hrtimer to receive remain words if have more than
4 words.

Quoted 8 lines
Quoted 4 lines

You told us that using interrupts is not possible due to miserable performance, we then provided you a way with which you could poll. Why are you using interrupts now?

Because mailbox framework does not support sync rx now, I think we do not need to wait for that feature done first as it's independent and separate features of framework.

Quoted 6 lines

You can wait forever for this feature, nobody will add it for you. It's up to you to add support for that feature. Who else should add this feature if not you? And when will you add that feature if not now when you actually need it? It is common practice that you adjust the frameworks to your needs rather than working around them.

Quoted 4 lines

I'm willing to add it. Just because you said Jassi already had the idea on how to Implement it and does not add much complexity. So I just want to see his patches. But if he did not work on it, I can also help on it.

I am not much aware of the history of this conversation... but it seems you need to make use of mbox_chan_ops.peek_data().

If not that, please let me know the requirement.

Cheers!

author
#10 lore raw

RE: [PATCH V4 3/5] mailbox: imx: add imx mu support

Hi Jassi,

Quoted 69 lines

-----Original Message-----
From: Jassi Brar [mailto:jassisinghbrar at gmail.com]
Sent: Wednesday, July 11, 2018 6:44 PM
To: A.s. Dong <[email protected]>
Cc: Sascha Hauer <[email protected]>; linux-arm-
kernel at lists.infradead.org; dongas86 at gmail.com; linux- kernel at vger.kernel.org; Oleksij Rempel <[email protected]>; dl- linux-imx <[email protected]>; kernel at pengutronix.de; Fabio Estevam <[email protected]>; shawnguo at kernel.org
Subject: Re: [PATCH V4 3/5] mailbox: imx: add imx mu support

Quoted 33 lines · A.s. Dong
Quoted 33 lines

-----Original Message-----
From: Sascha Hauer [mailto:s.hauer at pengutronix.de]
Sent: Wednesday, July 11, 2018 3:55 PM
To: A.s. Dong <[email protected]>
Cc: linux-arm-kernel at lists.infradead.org; dongas86 at gmail.com; Jassi Brar <[email protected]>; linux-kernel at vger.kernel.org; Oleksij Rempel <[email protected]>; dl-linux-imx <[email protected]>; kernel at pengutronix.de; Fabio Estevam <[email protected]>; shawnguo at kernel.org
Subject: Re: [PATCH V4 3/5] mailbox: imx: add imx mu support

Quoted 20 lines · A.s. Dong

Hi Sascha,

Quoted 18 lines

-----Original Message-----
From: Sascha Hauer [mailto:s.hauer at pengutronix.de]
Sent: Tuesday, July 10, 2018 10:20 PM
To: A.s. Dong <[email protected]>
Cc: linux-arm-kernel at lists.infradead.org; dongas86 at gmail.com; Jassi Brar <[email protected]>;
linux-kernel at vger.kernel.org; Oleksij Rempel <[email protected]>; dl-linux-imx <[email protected]>; kernel at pengutronix.de; Fabio Estevam <[email protected]>; shawnguo at kernel.org
Subject: Re: [PATCH V4 3/5] mailbox: imx: add imx mu support

Hi,

Quoted 3 lines · Dong Aisheng

This is used for i.MX multi core communication.
e.g. A core to SCU firmware(M core) on MX8.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

Tx is using polling mode while Rx is interrupt driven and schedule a hrtimer to receive remain words if have more than 4 words.

You told us that using interrupts is not possible due to miserable performance, we then provided you a way with which you

could poll.

Quoted 9 lines
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines

Why are you using interrupts now?

Because mailbox framework does not support sync rx now, I think we do not need to wait for that feature done first as it's independent and separate features of framework.

You can wait forever for this feature, nobody will add it for you. It's up to you to add support for that feature. Who else should add this

feature if not you?

Quoted 7 lines
Quoted 4 lines

And when will you add that feature if not now when you actually need it? It is common practice that you adjust the frameworks to your needs rather than working around them.

I'm willing to add it. Just because you said Jassi already had the idea on how to Implement it and does not add much complexity. So I just

Quoted 8 lines

want to see his patches.

Quoted 2 lines

But if he did not work on it, I can also help on it.

I am not much aware of the history of this conversation... but it seems you need to make use of mbox_chan_ops.peek_data().

If not that, please let me know the requirement.

Thanks for the suggestion.
It looks to me may work.

Quoted 1 line

From the definition, it seems it's used to pull data from remote side.

/**
* mbox_client_peek_data - A way for client driver to pull data
* received from remote by the controller.
* @chan: Mailbox channel assigned to this client.
*
* A poke to controller driver for any received data.
* The data is actually passed onto client via the
* mbox_chan_received_data()
* The call can be made from atomic context, so the controller's
* implementation of peek_data() must not sleep.
*
* Return: True, if controller has, and is going to push after this,
* some data.
* False, if controller doesn't have any data to be read.
*/
bool mbox_client_peek_data(struct mbox_chan *chan)

{
        if (chan->mbox->ops->peek_data)
                return chan->mbox->ops->peek_data(chan);
        
        return false;
}       

EXPORT_SYMBOL_GPL(mbox_client_peek_data);
But it seems most users in kernel simply implement it as a data available Checking rather than receiving it.
See:
drivers/mailbox/ti-msgmgr.c
drivers/mailbox/mailbox-altera.c

Only bcm uses it to receive data.
drivers/mailbox/bcm-flexrm-mailbox.c

For our requirement, we want to implement sync receiving protocol like:
Sc_call_rpc()

{
	mbox_send_message(chan, msg)
	If (!no_resp)
		// rx also stored in msg
		mbox_receive_msg_in_polling(chan, msg);
	mbox_client_txdone();
}

If using peek_data, it can be:
Sc_call_rpc()

{
	mbox_send_message(chan, msg)
	If (!no_resp)
		// rx also stored in msg
		Mbox_client_peek_data(chan);
	mbox_client_txdone();
}

And for mu controller driver .peek_data():
imx_mu_peek_data(chan)

{
        // get first word and parse data size
        imx_mu_receive_msg(&mu->chans, 0, mu->msg);

        raw_data = (u8 *)mu->msg;
        size = raw_data[1];

        // receive rest of them 
        for (i = 1; i < size; i++) {
                ret = imx_mu_receive_msg(&mu->chans, i % 4, mu->msg + i);
                if (ret)
                        return false;
        }

        mbox_chan_received_data(&mu->chans, (void *)mu->msg);

        return true;
}

It is much specific to SCU.
Do you think such peek_data using for sync receiving mode is ok?

Regards
Dong Aisheng

Quoted 1 line

Cheers!

maintainer
#11 lore raw

Re: [PATCH V4 3/5] mailbox: imx: add imx mu support

Quoted 126 lines · A.s. Dong

Hi Jassi,

Quoted 69 lines

-----Original Message-----
From: Jassi Brar [mailto:jassisinghbrar at gmail.com]
Sent: Wednesday, July 11, 2018 6:44 PM
To: A.s. Dong <[email protected]>
Cc: Sascha Hauer <[email protected]>; linux-arm-
kernel at lists.infradead.org; dongas86 at gmail.com; linux- kernel at vger.kernel.org; Oleksij Rempel <[email protected]>; dl- linux-imx <[email protected]>; kernel at pengutronix.de; Fabio Estevam <[email protected]>; shawnguo at kernel.org
Subject: Re: [PATCH V4 3/5] mailbox: imx: add imx mu support

Quoted 33 lines · A.s. Dong
Quoted 33 lines

-----Original Message-----
From: Sascha Hauer [mailto:s.hauer at pengutronix.de]
Sent: Wednesday, July 11, 2018 3:55 PM
To: A.s. Dong <[email protected]>
Cc: linux-arm-kernel at lists.infradead.org; dongas86 at gmail.com; Jassi Brar <[email protected]>; linux-kernel at vger.kernel.org; Oleksij Rempel <[email protected]>; dl-linux-imx <[email protected]>; kernel at pengutronix.de; Fabio Estevam <[email protected]>; shawnguo at kernel.org
Subject: Re: [PATCH V4 3/5] mailbox: imx: add imx mu support

Quoted 20 lines · A.s. Dong

Hi Sascha,

Quoted 18 lines

-----Original Message-----
From: Sascha Hauer [mailto:s.hauer at pengutronix.de]
Sent: Tuesday, July 10, 2018 10:20 PM
To: A.s. Dong <[email protected]>
Cc: linux-arm-kernel at lists.infradead.org; dongas86 at gmail.com; Jassi Brar <[email protected]>;
linux-kernel at vger.kernel.org; Oleksij Rempel <[email protected]>; dl-linux-imx <[email protected]>; kernel at pengutronix.de; Fabio Estevam <[email protected]>; shawnguo at kernel.org
Subject: Re: [PATCH V4 3/5] mailbox: imx: add imx mu support

Hi,

Quoted 3 lines · Dong Aisheng

This is used for i.MX multi core communication.
e.g. A core to SCU firmware(M core) on MX8.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

Tx is using polling mode while Rx is interrupt driven and schedule a hrtimer to receive remain words if have more than 4 words.

You told us that using interrupts is not possible due to miserable performance, we then provided you a way with which you

could poll.

Quoted 9 lines
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines

Why are you using interrupts now?

Because mailbox framework does not support sync rx now, I think we do not need to wait for that feature done first as it's independent and separate features of framework.

You can wait forever for this feature, nobody will add it for you. It's up to you to add support for that feature. Who else should add this

feature if not you?

Quoted 7 lines
Quoted 4 lines

And when will you add that feature if not now when you actually need it? It is common practice that you adjust the frameworks to your needs rather than working around them.

I'm willing to add it. Just because you said Jassi already had the idea on how to Implement it and does not add much complexity. So I just

Quoted 8 lines

want to see his patches.

Quoted 2 lines

But if he did not work on it, I can also help on it.

I am not much aware of the history of this conversation... but it seems you need to make use of mbox_chan_ops.peek_data().

If not that, please let me know the requirement.

Thanks for the suggestion.
It looks to me may work.

From the definition, it seems it's used to pull data from remote side. /**
* mbox_client_peek_data - A way for client driver to pull data
* received from remote by the controller.
* @chan: Mailbox channel assigned to this client.
*
* A poke to controller driver for any received data.
* The data is actually passed onto client via the
* mbox_chan_received_data()
* The call can be made from atomic context, so the controller's
* implementation of peek_data() must not sleep.
*
* Return: True, if controller has, and is going to push after this,
* some data.
* False, if controller doesn't have any data to be read.
*/
bool mbox_client_peek_data(struct mbox_chan *chan)

{
        if (chan->mbox->ops->peek_data)
                return chan->mbox->ops->peek_data(chan);

        return false;
}

EXPORT_SYMBOL_GPL(mbox_client_peek_data);
But it seems most users in kernel simply implement it as a data available Checking rather than receiving it.
See:
drivers/mailbox/ti-msgmgr.c
drivers/mailbox/mailbox-altera.c

Only bcm uses it to receive data.
drivers/mailbox/bcm-flexrm-mailbox.c

For our requirement, we want to implement sync receiving protocol like:
Sc_call_rpc()

{
        mbox_send_message(chan, msg)
        If (!no_resp)
                // rx also stored in msg
                mbox_receive_msg_in_polling(chan, msg);
        mbox_client_txdone();
}
Quoted 8 lines

If using peek_data, it can be:
Sc_call_rpc()

{
        mbox_send_message(chan, msg)
        If (!no_resp)
                // rx also stored in msg
                Mbox_client_peek_data(chan);

Yes, and you may want to loop for a certain amount of time if peek keeps returning false.

Quoted 5 lines
        mbox_client_txdone();
}

And for mu controller driver .peek_data():
imx_mu_peek_data(chan)

Quoted 16 lines
{
        // get first word and parse data size
        imx_mu_receive_msg(&mu->chans, 0, mu->msg);

        raw_data = (u8 *)mu->msg;
        size = raw_data[1];

        // receive rest of them
        for (i = 1; i < size; i++) {
                ret = imx_mu_receive_msg(&mu->chans, i % 4, mu->msg + i);
                if (ret)
                        return false;
        }

        mbox_chan_received_data(&mu->chans, (void *)mu->msg);

Not sure how your controller works. But the peek() callback only _checks_ if there is some data available to be read. Please note that peek() can not sleep.
So if the data fetching doesn't sleep you can do that here, otherwise peek has to schedule the actual fetching of data from remote and providing to the client via mbox_chan_received_data.

-jassi

author
#12 lore raw

RE: [PATCH V4 3/5] mailbox: imx: add imx mu support

Hi Jassi,

Quoted 175 lines

-----Original Message-----
From: Jassi Brar [mailto:jassisinghbrar at gmail.com]
Sent: Thursday, July 12, 2018 12:32 AM
To: A.s. Dong <[email protected]>
Cc: Sascha Hauer <[email protected]>; linux-arm-
kernel at lists.infradead.org; dongas86 at gmail.com; linux- kernel at vger.kernel.org; Oleksij Rempel <[email protected]>; dl- linux-imx <[email protected]>; kernel at pengutronix.de; Fabio Estevam <[email protected]>; shawnguo at kernel.org
Subject: Re: [PATCH V4 3/5] mailbox: imx: add imx mu support

Quoted 14 lines · A.s. Dong

Hi Jassi,

Quoted 12 lines

-----Original Message-----
From: Jassi Brar [mailto:jassisinghbrar at gmail.com]
Sent: Wednesday, July 11, 2018 6:44 PM
To: A.s. Dong <[email protected]>
Cc: Sascha Hauer <[email protected]>; linux-arm-
kernel at lists.infradead.org; dongas86 at gmail.com; linux- kernel at vger.kernel.org; Oleksij Rempel <[email protected]>; dl- linux-imx <[email protected]>; kernel at pengutronix.de; Fabio Estevam <[email protected]>; shawnguo at kernel.org
Subject: Re: [PATCH V4 3/5] mailbox: imx: add imx mu support

On Wed, Jul 11, 2018 at 4:07 PM, A.s. Dong <[email protected]>

Quoted 16 lines · wrote:
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines

-----Original Message-----
From: Sascha Hauer [mailto:s.hauer at pengutronix.de]
Sent: Wednesday, July 11, 2018 3:55 PM
To: A.s. Dong <[email protected]>
Cc: linux-arm-kernel at lists.infradead.org; dongas86 at gmail.com; Jassi Brar <[email protected]>;
linux-kernel at vger.kernel.org; Oleksij Rempel <[email protected]>; dl-linux-imx <[email protected]>; kernel at pengutronix.de; Fabio Estevam <[email protected]>; shawnguo at kernel.org
Subject: Re: [PATCH V4 3/5] mailbox: imx: add imx mu support

Quoted 2 lines · A.s. Dong

Hi Sascha,

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

-----Original Message-----
From: Sascha Hauer [mailto:s.hauer at pengutronix.de]
Sent: Tuesday, July 10, 2018 10:20 PM
To: A.s. Dong <[email protected]>
Cc: linux-arm-kernel at lists.infradead.org; dongas86 at gmail.com; Jassi Brar <[email protected]>;
linux-kernel at vger.kernel.org; Oleksij Rempel <[email protected]>; dl-linux-imx <[email protected]>; kernel at pengutronix.de; Fabio Estevam

<[email protected]>;

Quoted 25 lines
Quoted 25 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

shawnguo at kernel.org
Subject: Re: [PATCH V4 3/5] mailbox: imx: add imx mu support

Hi,

Quoted 3 lines · Dong Aisheng

This is used for i.MX multi core communication.
e.g. A core to SCU firmware(M core) on MX8.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

Tx is using polling mode while Rx is interrupt driven and schedule a hrtimer to receive remain words if have more than
4 words.

You told us that using interrupts is not possible due to miserable performance, we then provided you a way with which you

could poll.

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines

Why are you using interrupts now?

Because mailbox framework does not support sync rx now, I think we do not need to wait for that feature done first as it's independent and separate features of framework.

Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines

You can wait forever for this feature, nobody will add it for you. It's up to you to add support for that feature. Who else should add this

feature if not you?

Quoted 1 line
Quoted 1 line

And when will you add that feature if not now when you actually need

it?

Quoted 61 lines
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

It is common practice that you adjust the frameworks to your needs rather than working around them.

I'm willing to add it. Just because you said Jassi already had the idea on how to Implement it and does not add much complexity. So I just

Quoted 8 lines

want to see his patches.

Quoted 2 lines

But if he did not work on it, I can also help on it.

I am not much aware of the history of this conversation... but it seems you need to make use of mbox_chan_ops.peek_data().

If not that, please let me know the requirement.

Thanks for the suggestion.
It looks to me may work.

From the definition, it seems it's used to pull data from remote side. /**
* mbox_client_peek_data - A way for client driver to pull data
* received from remote by the controller.
* @chan: Mailbox channel assigned to this client.
*
* A poke to controller driver for any received data.
* The data is actually passed onto client via the
* mbox_chan_received_data()
* The call can be made from atomic context, so the controller's
* implementation of peek_data() must not sleep.
*
* Return: True, if controller has, and is going to push after this,
* some data.
* False, if controller doesn't have any data to be read.
*/

bool mbox_client_peek_data(struct mbox_chan *chan) {
        if (chan->mbox->ops->peek_data)
                return chan->mbox->ops->peek_data(chan);

        return false;
}

EXPORT_SYMBOL_GPL(mbox_client_peek_data);
But it seems most users in kernel simply implement it as a data available Checking rather than receiving it.
See:
drivers/mailbox/ti-msgmgr.c drivers/mailbox/mailbox-altera.c

Only bcm uses it to receive data.
drivers/mailbox/bcm-flexrm-mailbox.c

For our requirement, we want to implement sync receiving protocol like:
Sc_call_rpc()

{
        mbox_send_message(chan, msg)
        If (!no_resp)
                // rx also stored in msg
                mbox_receive_msg_in_polling(chan, msg);
        mbox_client_txdone();
}
Quoted 8 lines

If using peek_data, it can be:
Sc_call_rpc()

{
        mbox_send_message(chan, msg)
        If (!no_resp)
                // rx also stored in msg
                Mbox_client_peek_data(chan);

Yes, and you may want to loop for a certain amount of time if peek keeps returning false.

Quoted 19 lines
        mbox_client_txdone();
}

And for mu controller driver .peek_data():
imx_mu_peek_data(chan)

{
        // get first word and parse data size
        imx_mu_receive_msg(&mu->chans, 0, mu->msg);

        raw_data = (u8 *)mu->msg;
        size = raw_data[1];

        // receive rest of them
        for (i = 1; i < size; i++) {
                ret = imx_mu_receive_msg(&mu->chans, i % 4, mu->msg + i);
                if (ret)
                        return false;
        }
Quoted 9 lines
Quoted 2 lines
        mbox_chan_received_data(&mu->chans, (void *)mu->msg);

Not sure how your controller works. But the peek() callback only _checks_ if there is some data available to be read. Please note that
peek() can not sleep.
So if the data fetching doesn't sleep you can do that here, otherwise peek has to schedule the actual fetching of data from remote and providing to the client via mbox_chan_received_data.

bcm seems is using peek to receive data, not only checking the data availability, right?
drivers/mailbox/bcm-flexrm-mailbox.c

So I did the similar way for i.MX. I just sent out that new patch series. Please help review if any problem of it.
BTW i.MX peek is using busy polling, so won't sleep.

Regards
Dong Aisheng

Quoted 1 line

-jassi

maintainer
#13 lore raw

Re: [PATCH V4 3/5] mailbox: imx: add imx mu support

Quoted 187 lines · A.s. Dong

Hi Jassi,

Quoted 175 lines

-----Original Message-----
From: Jassi Brar [mailto:jassisinghbrar at gmail.com]
Sent: Thursday, July 12, 2018 12:32 AM
To: A.s. Dong <[email protected]>
Cc: Sascha Hauer <[email protected]>; linux-arm-
kernel at lists.infradead.org; dongas86 at gmail.com; linux- kernel at vger.kernel.org; Oleksij Rempel <[email protected]>; dl- linux-imx <[email protected]>; kernel at pengutronix.de; Fabio Estevam <[email protected]>; shawnguo at kernel.org
Subject: Re: [PATCH V4 3/5] mailbox: imx: add imx mu support

Quoted 14 lines · A.s. Dong

Hi Jassi,

Quoted 12 lines

-----Original Message-----
From: Jassi Brar [mailto:jassisinghbrar at gmail.com]
Sent: Wednesday, July 11, 2018 6:44 PM
To: A.s. Dong <[email protected]>
Cc: Sascha Hauer <[email protected]>; linux-arm-
kernel at lists.infradead.org; dongas86 at gmail.com; linux- kernel at vger.kernel.org; Oleksij Rempel <[email protected]>; dl- linux-imx <[email protected]>; kernel at pengutronix.de; Fabio Estevam <[email protected]>; shawnguo at kernel.org
Subject: Re: [PATCH V4 3/5] mailbox: imx: add imx mu support

On Wed, Jul 11, 2018 at 4:07 PM, A.s. Dong <[email protected]>

Quoted 16 lines · wrote:
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines

-----Original Message-----
From: Sascha Hauer [mailto:s.hauer at pengutronix.de]
Sent: Wednesday, July 11, 2018 3:55 PM
To: A.s. Dong <[email protected]>
Cc: linux-arm-kernel at lists.infradead.org; dongas86 at gmail.com; Jassi Brar <[email protected]>;
linux-kernel at vger.kernel.org; Oleksij Rempel <[email protected]>; dl-linux-imx <[email protected]>; kernel at pengutronix.de; Fabio Estevam <[email protected]>; shawnguo at kernel.org
Subject: Re: [PATCH V4 3/5] mailbox: imx: add imx mu support

Quoted 2 lines · A.s. Dong

Hi Sascha,

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

-----Original Message-----
From: Sascha Hauer [mailto:s.hauer at pengutronix.de]
Sent: Tuesday, July 10, 2018 10:20 PM
To: A.s. Dong <[email protected]>
Cc: linux-arm-kernel at lists.infradead.org; dongas86 at gmail.com; Jassi Brar <[email protected]>;
linux-kernel at vger.kernel.org; Oleksij Rempel <[email protected]>; dl-linux-imx <[email protected]>; kernel at pengutronix.de; Fabio Estevam

<[email protected]>;

Quoted 25 lines
Quoted 25 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

shawnguo at kernel.org
Subject: Re: [PATCH V4 3/5] mailbox: imx: add imx mu support

Hi,

Quoted 3 lines · Dong Aisheng

This is used for i.MX multi core communication.
e.g. A core to SCU firmware(M core) on MX8.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

Tx is using polling mode while Rx is interrupt driven and schedule a hrtimer to receive remain words if have more than
4 words.

You told us that using interrupts is not possible due to miserable performance, we then provided you a way with which you

could poll.

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines

Why are you using interrupts now?

Because mailbox framework does not support sync rx now, I think we do not need to wait for that feature done first as it's independent and separate features of framework.

Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines

You can wait forever for this feature, nobody will add it for you. It's up to you to add support for that feature. Who else should add this

feature if not you?

Quoted 1 line
Quoted 1 line

And when will you add that feature if not now when you actually need

it?

Quoted 61 lines
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

It is common practice that you adjust the frameworks to your needs rather than working around them.

I'm willing to add it. Just because you said Jassi already had the idea on how to Implement it and does not add much complexity. So I just

Quoted 8 lines

want to see his patches.

Quoted 2 lines

But if he did not work on it, I can also help on it.

I am not much aware of the history of this conversation... but it seems you need to make use of mbox_chan_ops.peek_data().

If not that, please let me know the requirement.

Thanks for the suggestion.
It looks to me may work.

From the definition, it seems it's used to pull data from remote side. /**
* mbox_client_peek_data - A way for client driver to pull data
* received from remote by the controller.
* @chan: Mailbox channel assigned to this client.
*
* A poke to controller driver for any received data.
* The data is actually passed onto client via the
* mbox_chan_received_data()
* The call can be made from atomic context, so the controller's
* implementation of peek_data() must not sleep.
*
* Return: True, if controller has, and is going to push after this,
* some data.
* False, if controller doesn't have any data to be read.
*/

bool mbox_client_peek_data(struct mbox_chan *chan) {
        if (chan->mbox->ops->peek_data)
                return chan->mbox->ops->peek_data(chan);

        return false;
}

EXPORT_SYMBOL_GPL(mbox_client_peek_data);
But it seems most users in kernel simply implement it as a data available Checking rather than receiving it.
See:
drivers/mailbox/ti-msgmgr.c drivers/mailbox/mailbox-altera.c

Only bcm uses it to receive data.
drivers/mailbox/bcm-flexrm-mailbox.c

For our requirement, we want to implement sync receiving protocol like:
Sc_call_rpc()

{
        mbox_send_message(chan, msg)
        If (!no_resp)
                // rx also stored in msg
                mbox_receive_msg_in_polling(chan, msg);
        mbox_client_txdone();
}
Quoted 8 lines

If using peek_data, it can be:
Sc_call_rpc()

{
        mbox_send_message(chan, msg)
        If (!no_resp)
                // rx also stored in msg
                Mbox_client_peek_data(chan);

Yes, and you may want to loop for a certain amount of time if peek keeps returning false.

Quoted 19 lines
        mbox_client_txdone();
}

And for mu controller driver .peek_data():
imx_mu_peek_data(chan)

{
        // get first word and parse data size
        imx_mu_receive_msg(&mu->chans, 0, mu->msg);

        raw_data = (u8 *)mu->msg;
        size = raw_data[1];

        // receive rest of them
        for (i = 1; i < size; i++) {
                ret = imx_mu_receive_msg(&mu->chans, i % 4, mu->msg + i);
                if (ret)
                        return false;
        }
Quoted 9 lines
Quoted 2 lines
        mbox_chan_received_data(&mu->chans, (void *)mu->msg);

Not sure how your controller works. But the peek() callback only _checks_ if there is some data available to be read. Please note that
peek() can not sleep.
So if the data fetching doesn't sleep you can do that here, otherwise peek has to schedule the actual fetching of data from remote and providing to the client via mbox_chan_received_data.

Quoted 4 lines

bcm seems is using peek to receive data, not only checking the data availability, right?
drivers/mailbox/bcm-flexrm-mailbox.c

As I said, if fetching data from remote don't need to sleep, you can call mbox_chan_received_data() from peek(). Otherwise not.

author
#14 lore raw

RE: [PATCH V4 3/5] mailbox: imx: add imx mu support

Hi Jassi,

Quoted 10 lines

-----Original Message-----
From: Jassi Brar [mailto:jassisinghbrar at gmail.com]
Sent: Thursday, July 12, 2018 1:01 AM
To: A.s. Dong <[email protected]>
Cc: Sascha Hauer <[email protected]>; linux-arm-
kernel at lists.infradead.org; dongas86 at gmail.com; linux- kernel at vger.kernel.org; Oleksij Rempel <[email protected]>; dl- linux-imx <[email protected]>; kernel at pengutronix.de; Fabio Estevam <[email protected]>; shawnguo at kernel.org
Subject: Re: [PATCH V4 3/5] mailbox: imx: add imx mu support

....

Quoted 7 lines
Quoted 5 lines

bcm seems is using peek to receive data, not only checking the data availability, right? drivers/mailbox/bcm-flexrm-mailbox.c

As I said, if fetching data from remote don't need to sleep, you can call mbox_chan_received_data() from peek(). Otherwise not.

Got it. So it seems work for i.MX.
Thanks.

Regards
Dong Aisheng

#15 lore raw

RE: [PATCH V4 3/5] mailbox: imx: add imx mu support

In reply to A.s. Dong

Hi A.S

Quoted 46 lines

-----Original Message-----
From: A.s. Dong
Sent: 2018?7?11? 15:30
To: Sascha Hauer <[email protected]>
Cc: linux-arm-kernel at lists.infradead.org; dongas86 at gmail.com; Jassi Brar <[email protected]>; linux-kernel at vger.kernel.org; Oleksij Rempel <[email protected]>; dl-linux-imx <[email protected]>; kernel at pengutronix.de; Fabio Estevam <[email protected]>; shawnguo at kernel.org
Subject: RE: [PATCH V4 3/5] mailbox: imx: add imx mu support

Hi Sascha,

Quoted 17 lines

-----Original Message-----
From: Sascha Hauer [mailto:s.hauer at pengutronix.de]
Sent: Tuesday, July 10, 2018 10:20 PM
To: A.s. Dong <[email protected]>
Cc: linux-arm-kernel at lists.infradead.org; dongas86 at gmail.com; Jassi Brar <[email protected]>; linux-kernel at vger.kernel.org; Oleksij Rempel <[email protected]>; dl-linux-imx <[email protected]>; kernel at pengutronix.de; Fabio Estevam <[email protected]>; shawnguo at kernel.org
Subject: Re: [PATCH V4 3/5] mailbox: imx: add imx mu support

Hi,

Quoted 3 lines · Dong Aisheng

This is used for i.MX multi core communication.
e.g. A core to SCU firmware(M core) on MX8.

Quoted 8 lines
Quoted 3 lines

Tx is using polling mode while Rx is interrupt driven and schedule a hrtimer to receive remain words if have more than
4 words.

You told us that using interrupts is not possible due to miserable performance, we then provided you a way with which you could poll. Why are you using interrupts now?

Because mailbox framework does not support sync rx now, I think we do not need to wait for that feature done first as it's independent and separate features of framework.

So for now, we're just using the common way in kernel as arm scpi and ti sci. When framework supports it, we can easily switch to it.

Quoted 7 lines

I optimized the performance a bit by removing the unnecessary memcopy between tx/tx messages. The test result of booting time shows there's no obvious regressions. I'm not sure whether it's due to we're booting a minimum system or the extra cost is very minor to be noticed due to not too much cmds sent during booting.
(Copy Peng to comments more as he tried and reported that performance drop with vendor tree)

The txpoll_period is set 1, the minimum is 1ms. So it introduces latency in the initial mailbox for SCU communication.

Regards,
Peng

Quoted 72 lines

From the time measurement of sc_call_rpc, we can see that most rpc command In polling mode can finish within 10us and very rare ones over 20us. If switched to irq mode, those 10us cmds will change to about 20us.

But the overall booting time did not increase much. Maybe the irq mode also saves some CPU MIPS to execute other works in parallel?

Quoted 5 lines

We also suggested a way how the SCU mode could be integrated into the generic MU support driver Oleksij posted and now you send a driver which uses the same name as Oleksijs driver, but it only and exclusively works in SCU mode. This doesn't bring us forward.

Can Oleksij's patch be implemented against this one?
As I remember you said we've still not determined whether Oleksij's approach is the most suitable way and it's still under discussion.
(Actually TI's approach looks better which is more simiar as SCU way?)

Furthermore, from this patch, you will notice that Oleksij's patch almost did not work for SCU at all. I have to totally rewrite one for SCU.
So I did not write against his patch as it does not help.
And Oleksij's patch is quite simple while the SCU one is much complicated than his one. So we probably better get SCU done first.

Quoted 4 lines

We suggested a binding that allows coexisting of the SCU mode and the generic mode of the MU by putting the mode information into the second mbox-cell. Why don't you use this?

You mean this?

(quoted diff) +5 -0
+#define IMX_MU_CHANNEL0		0
+#define IMX_MU_CHANNEL1		1
+#define IMX_MU_CHANNEL2		2
+#define IMX_MU_CHANNEL3		3
+#define IMX_MU_CHANNEL_IMX8_SCU 4

It's hard for me to believe it's correct and it's over abstract to HW. So I thought using mbox-cells to distinguish seems to be better.

Quoted 4 lines

I don't think it's necessary to rewrite Oleksijs driver, instead it should rather be extended with the code I already provided as an example. With that we could make both of us happy since we can both have a suitable driver and even share most of the MU code.

As I said above, I even can't reuse 90%+ code of Oleksijs driver. So I can't see the meaning to demo the code on top of this driver. We can review the SCU implementation directly with this driver which is more easy.
Then we can decide how to merge them together.

Regards
Dong Aisheng

Quoted 6 lines

Regards,
Sascha

--
Pengutronix e.K. |

|

Quoted 4 lines

Industrial Linux Solutions |
https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fww
w.pengutronix.de%2F&amp;data=02%7C01%7Caisheng.dong%40nxp.com%7

Cb359a3eddee54bf1b40a08d5e6702f22%7C686ea1d3bc2b4c6fa92cd99c5c301

Quoted 1 line

635%7C0%7C0%7C636668291863846639&amp;sdata=hSucaLRfCB1j1McwlfO%

Quoted 2 lines

2FL0921QXiHg68sl%2B23CvEp4Q%3D&amp;reserved=0 |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0

|

Quoted 1 line

Amtsgericht Hildesheim, HRA 2686 | Fax:

+49-5121-206917-5555 |

#16 lore raw

PATCH v4 4/5 dt-bindings: arm: fsl: add scu binding doc

In reply to Dong Aisheng

The System Controller Firmware (SCFW) is a low-level system function which runs on a dedicated Cortex-M core to provide power, clock, and resource management. It exists on some i.MX8 processors. e.g. i.MX8QM (QM, QP), and i.MX8QX (QXP, DX).

Cc Shawn Guo <[email protected]>
Cc Sascha Hauer <[email protected]>
Cc Fabio Estevam <[email protected]>
Cc Rob Herring <[email protected]>
Cc Mark Rutland <[email protected]>
Cc devicetree at vger.kernel.org

---
v3->v4:
* fully change to mailbox binding
* add child node description
v2->v3:
* update a bit to mailbox binding
v1->v2:
* remove status
* changed to mu1

---
 .../devicetree/bindings/arm/freescale/fsl,scu.txt  | 65 ++++++++++++++++++++++
 1 file changed, 65 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/arm/freescale/fsl,scu.txt
Documentation/devicetree/bindings/arm/freescale/fsl,scu.txt new file +65 -0
new file mode 100644
index 0000000..11e732a
@@ -0,0 +1,65 @@
+NXP i.MX System Controller Firmware (SCFW)
+--------------------------------------------------------------------
+
+The System Controller Firmware (SCFW) is a low-level system function
+which runs on a dedicated Cortex-M core to provide power, clock, and
+resource management. It exists on some i.MX8 processors. e.g. i.MX8QM
+(QM, QP), and i.MX8QX (QXP, DX).
+
+The AP communicates with the SC using a multi-ported MU module found
+in the LSIO subsystem. The current definition of this MU module provides
+5 remote AP connections to the SC to support up to 5 execution environments
+(TZ, HV, standard Linux, etc.). The SC side of this MU module interfaces
+with the LSIO DSC IP bus. The SC firmware will communicate with this MU
+using the MSI bus.
+
+System Controller Device Node:
+=============================
+
+Required properties:
+-------------------
+- compatible: should be "fsl,imx-scu"
+- mboxes: List of phandle of MU mailbox. Should be one of LSIO
+	  MU0~M4 for imx8qxp and imx8qm. Users need to make
+	  sure not use the one which is conflict with other
+	  execution environments. e.g. ATF.
+
+Examples:
+--------
+lsio_mu1: mailbox at 5d1c0000 {
+	compatible = "fsl,imx8qxp-mu";
+	reg = <0x0 0x5d1c0000 0x0 0x10000>;
+	interrupts = <GIC_SPI 176 IRQ_TYPE_LEVEL_HIGH>;
+	#mbox-cells = <0>;
+};
+
+scu {
+	compatible = "fsl,imx-scu";
+	mboxes = <&lsio_mu1>;
+};
+
+
+i.MX SCU Client Device Node:
+=========================
+
+Client nodes are maintained as children of the relevant IMX-SCU device node.
+
+Example (imx8qxp):
+-------------
+scu {
+	compatible = "fsl,imx-scu";
+	...
+
+	clk: clk {
+		...
+	};
+
+	iomuxc: iomuxc {
+		...
+	};
+
+	imx8qx-pm {
+		...
+	}
+	...
+};
Signature · 1 line
2.7.4
maintainer
#17 lore raw

PATCH v4 4/5 dt-bindings: arm: fsl: add scu binding doc

Quoted 39 lines · Dong Aisheng

The System Controller Firmware (SCFW) is a low-level system function which runs on a dedicated Cortex-M core to provide power, clock, and resource management. It exists on some i.MX8 processors. e.g. i.MX8QM (QM, QP), and i.MX8QX (QXP, DX).

Cc Shawn Guo <[email protected]>
Cc Sascha Hauer <[email protected]>
Cc Fabio Estevam <[email protected]>
Cc Rob Herring <[email protected]>
Cc Mark Rutland <[email protected]>
Cc devicetree at vger.kernel.org

---
v3->v4:
* fully change to mailbox binding
* add child node description
v2->v3:
* update a bit to mailbox binding
v1->v2:
* remove status
* changed to mu1

---
 .../devicetree/bindings/arm/freescale/fsl,scu.txt  | 65 ++++++++++++++++++++++
 1 file changed, 65 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/arm/freescale/fsl,scu.txt
Documentation/devicetree/bindings/arm/freescale/fsl,scu.txt new file +7 -0
new file mode 100644
index 0000000..11e732a
@@ -0,0 +1,65 @@
+NXP i.MX System Controller Firmware (SCFW)
+--------------------------------------------------------------------
+
+The System Controller Firmware (SCFW) is a low-level system function
+which runs on a dedicated Cortex-M core to provide power, clock, and
+resource management. It exists on some i.MX8 processors. e.g. i.MX8QM
+(QM, QP), and i.MX8QX (QXP, DX).

Documentation/devicetree/bindings/arm/freescale/fsl,scu.txt line 17

Quoted 10 lines
Documentation/devicetree/bindings/arm/freescale/fsl,scu.txt new file +10 -0
+
+The AP communicates with the SC using a multi-ported MU module found
+in the LSIO subsystem. The current definition of this MU module provides
+5 remote AP connections to the SC to support up to 5 execution environments
+(TZ, HV, standard Linux, etc.). The SC side of this MU module interfaces
+with the LSIO DSC IP bus. The SC firmware will communicate with this MU
+using the MSI bus.
+
+System Controller Device Node:
+=============================

Need to specify this is a child of /firmware node.

Quoted 37 lines
Documentation/devicetree/bindings/arm/freescale/fsl,scu.txt new file +37 -0
+
+Required properties:
+-------------------
+- compatible: should be "fsl,imx-scu"
+- mboxes: List of phandle of MU mailbox. Should be one of LSIO
+	  MU0~M4 for imx8qxp and imx8qm. Users need to make
+	  sure not use the one which is conflict with other
+	  execution environments. e.g. ATF.
+
+Examples:
+--------
+lsio_mu1: mailbox at 5d1c0000 {
+	compatible = "fsl,imx8qxp-mu";
+	reg = <0x0 0x5d1c0000 0x0 0x10000>;
+	interrupts = <GIC_SPI 176 IRQ_TYPE_LEVEL_HIGH>;
+	#mbox-cells = <0>;
+};
+
+scu {
+	compatible = "fsl,imx-scu";
+	mboxes = <&lsio_mu1>;
+};
+
+
+i.MX SCU Client Device Node:
+=========================
+
+Client nodes are maintained as children of the relevant IMX-SCU device node.
+
+Example (imx8qxp):
+-------------
+scu {
+	compatible = "fsl,imx-scu";
+	...
+
+	clk: clk {
+		...

Documentation/devicetree/bindings/arm/freescale/fsl,scu.txt line 64

Quoted 10 lines
Documentation/devicetree/bindings/arm/freescale/fsl,scu.txt new file +10 -0
+	};
+
+	iomuxc: iomuxc {
+		...
+	};
+
+	imx8qx-pm {
+		...
+	}
+	...

If you plan to have child nodes, you need to document them now. However, other than pinctrl, you probably don't need child nodes. The parent node can be a clock and power-domain provider.

Rob

author
#18 lore raw

PATCH v4 4/5 dt-bindings: arm: fsl: add scu binding doc

Quoted 59 lines

-----Original Message-----
From: Rob Herring [mailto:robh at kernel.org]
Sent: Wednesday, July 11, 2018 11:09 PM
To: A.s. Dong <[email protected]>
Cc: linux-arm-kernel at lists.infradead.org; dongas86 at gmail.com; kernel at pengutronix.de; shawnguo at kernel.org; Fabio Estevam <[email protected]>; dl-linux-imx <[email protected]>; Mark Rutland <[email protected]>; devicetree at vger.kernel.org
Subject: Re: [PATCH V4 4/5] dt-bindings: arm: fsl: add scu binding doc

Quoted 48 lines · Dong Aisheng

The System Controller Firmware (SCFW) is a low-level system function which runs on a dedicated Cortex-M core to provide power, clock, and resource management. It exists on some i.MX8 processors. e.g. i.MX8QM (QM, QP), and i.MX8QX (QXP, DX).

Cc Shawn Guo <[email protected]>
Cc Sascha Hauer <[email protected]>
Cc Fabio Estevam <[email protected]>
Cc Rob Herring <[email protected]>
Cc Mark Rutland <[email protected]>
Cc devicetree at vger.kernel.org

---
v3->v4:
* fully change to mailbox binding
* add child node description
v2->v3:
* update a bit to mailbox binding
v1->v2:
* remove status
* changed to mu1

---
 .../devicetree/bindings/arm/freescale/fsl,scu.txt  | 65
++++++++++++++++++++++
 1 file changed, 65 insertions(+)
 create mode 100644

Documentation/devicetree/bindings/arm/freescale/fsl,scu.txt

diff --git a/Documentation/devicetree/bindings/arm/freescale/fsl,scu.txt b/Documentation/devicetree/bindings/arm/freescale/fsl,scu.txt new file mode 100644
index 0000000..11e732a

Documentation/devicetree/bindings/arm/freescale/fsl,scu.txt new file +12 -0
@@ -0,0 +1,65 @@
+NXP i.MX System Controller Firmware (SCFW)
+--------------------------------------------------------------------
+
+The System Controller Firmware (SCFW) is a low-level system function
+which runs on a dedicated Cortex-M core to provide power, clock, and
+resource management. It exists on some i.MX8 processors. e.g. i.MX8QM
+(QM, QP), and i.MX8QX (QXP, DX).
+
+The AP communicates with the SC using a multi-ported MU module found
+in the LSIO subsystem. The current definition of this MU module
+provides
+5 remote AP connections to the SC to support up to 5 execution
Quoted 9 lines

Documentation/devicetree/bindings/arm/freescale/fsl,scu.txt line 17

Quoted 6 lines
Documentation/devicetree/bindings/arm/freescale/fsl,scu.txt new file +6 -0
+environments (TZ, HV, standard Linux, etc.). The SC side of this MU
+module interfaces with the LSIO DSC IP bus. The SC firmware will
+communicate with this MU using the MSI bus.
+
+System Controller Device Node:
+=============================

Need to specify this is a child of /firmware node.

Got it.

Quoted 44 lines
Quoted 18 lines
Documentation/devicetree/bindings/arm/freescale/fsl,scu.txt new file +18 -0
+
+Required properties:
+-------------------
+- compatible: should be "fsl,imx-scu"
+- mboxes: List of phandle of MU mailbox. Should be one of LSIO
+	  MU0~M4 for imx8qxp and imx8qm. Users need to make
+	  sure not use the one which is conflict with other
+	  execution environments. e.g. ATF.
+
+Examples:
+--------
+lsio_mu1: mailbox at 5d1c0000 {
+	compatible = "fsl,imx8qxp-mu";
+	reg = <0x0 0x5d1c0000 0x0 0x10000>;
+	interrupts = <GIC_SPI 176 IRQ_TYPE_LEVEL_HIGH>;
+	#mbox-cells = <0>;
+};
+

Documentation/devicetree/bindings/arm/freescale/fsl,scu.txt

Quoted 10 lines
Documentation/devicetree/bindings/arm/freescale/fsl,scu.txt new file +10 -0
+scu {
+	compatible = "fsl,imx-scu";
+	mboxes = <&lsio_mu1>;
+};
+
+
+i.MX SCU Client Device Node:
+=========================
+
+Client nodes are maintained as children of the relevant IMX-SCU device

node.

Quoted 15 lines
Documentation/devicetree/bindings/arm/freescale/fsl,scu.txt new file +15 -0
+
+Example (imx8qxp):
+-------------
+scu {
+	compatible = "fsl,imx-scu";
+	...
+
+	clk: clk {
+		...
+	};
+
+	iomuxc: iomuxc {
+		...
+	};
+
Quoted 9 lines

Documentation/devicetree/bindings/arm/freescale/fsl,scu.txt line 64

Quoted 4 lines
Documentation/devicetree/bindings/arm/freescale/fsl,scu.txt new file +4 -0
+	imx8qx-pm {
+		...
+	}
+	...

If you plan to have child nodes, you need to document them now. However, other than pinctrl, you probably don't need child nodes. The parent node can be a clock and power-domain provider.

Sorry I did not get the point.
This is referred to what TI does (arm scpi binding seems similar):
Documentation/devicetree/bindings/arm/keystone/ti,sci.txt Documentation/devicetree/bindings/clock/ti,sci-clk.txt

arch/arm/boot/dts/keystone-k2g.dtsi

pmmc: pmmc at 2921c00 {
        compatible = "ti,k2g-sci";
	....

        k2g_pds: power-controller {
                compatible = "ti,sci-pm-domain";
                #power-domain-cells = <1>;
        };

        k2g_clks: clocks {
                compatible = "ti,k2g-sci-clk";
                #clock-cells = <2>;
        };

        k2g_reset: reset-controller {
                compatible = "ti,sci-reset";
                #reset-cells = <2>;
        };
};

For i.MX SCU, it's quite similar:

firmware {
        scu {
                compatible = "fsl,imx-scu";
                mboxes = <&lsio_mu1>;

                clk: clk {
                        compatible = "fsl,imx8qxp-clk";
                        #clock-cells = <1>;
                        mboxes = <&lsio_mu2>; //optinoal
                };

                iomuxc: iomuxc {
                        compatible = "fsl,imx8qxp-iomuxc";
                        fsl,mu = <&lsio_mu3>; //optinoal
                };

                imx8qx-pm {
                        compatible = "fsl,scu-pd";
                        #address-cells = <1>;
                        #size-cells = <0>;
                        fsl,mu = <&lsio_mu4>; //optinoal

                        pd_lsio: PD_LSIO {
                                #power-domain-cells = <0>;
                                #address-cells = <1>;
                                #size-cells = <0>;

                                pd_lsio_pwm0: lsio_pwm0 at SC_R_PWM_0 {
                                        reg = <SC_R_PWM_0>;
                                        #power-domain-cells = <0>;
                                        power-domains = <&pd_lsio>;
                                };
                                ...
                        };

                        pd_dma: dma_power_domain {
                                #power-domain-cells = <0>;
                                #address-cells = <1>;
                                #size-cells = <0>;
                        };
                        ...
                };

                other_funcs {
                        compatible = "xxx";
                        ...
                };
        };
};

1. The child allows to specify a different mbox to use (planned optional)
2. we have separate clk, pinctrl, power domain drivers and etc.
3. we need define child pd nodes under the power domain node

Am I understanding correct that you are saying we can merge the clk and pd driver into scu driver then scu behaviors both clk and pd provider? It means we need implement both clk driver and pd driver in scu driver which may bloat the scu driver a lot and make us no able to specify different mbox for subnodes.
And clk driver has a lot clock type definitions which is under clock drivers. Not sure suitable to be moved into scu.
See:
https://patchwork.ozlabs.org/cover/905920/

It will be like:

firmware {                              
        scu {                           
                compatible = "fsl,imx-scu";
                mboxes = <&lsio_mu1>;
                #clock-cells = <1>;
                #address-cells = <1>;
                #size-cells = <0>;

                iomuxc: iomuxc {
                        compatible = "fsl,imx8qxp-iomuxc";
                        fsl,mu = <&lsio_mu3>;
                };

                other_funcs: {
                        compatible = "thermal...";
                        ...
                };

                pd_lsio: PD_LSIO {
                        #power-domain-cells = <0>;
                        #address-cells = <1>;
                        #size-cells = <0>;

                        pd_lsio_pwm0: lsio_pwm0 at SC_R_PWM_0 {
                                reg = <SC_R_PWM_0>;
                                #power-domain-cells = <0>;
                                power-domains = <&pd_lsio>;
                        };
                        ...
                };

                pd_vpu: vpu-power-domain at SC_R_VPU_PID0 {
                        reg = <SC_R_VPU_PID0>;
                        #power-domain-cells = <0>;
                        #address-cells = <1>;
                        #size-cells = <0>;
                };

                pd_xxx {
                        ...
                }
                ....
        };
};

How would you suggest for such case?

Regards
Dong Aisheng

Quoted 1 line

Rob

#19 lore raw

PATCH v4 5/5 soc: imx: add SC firmware IPC and APIs

In reply to Dong Aisheng

The System Controller Firmware (SCFW) is a low-level system function which runs on a dedicated Cortex-M core to provide power, clock, and resource management. It exists on some i.MX8 processors. e.g. i.MX8QM (QM, QP), and i.MX8QX (QXP, DX).

This patch adds the SC firmware service APIs used by the system. It mainly consists of two parts:
1) Implementation of the IPC functions using MUs (client side).
2) SCU firmware services APIs implemented based on RPC calls

Cc Shawn Guo <[email protected]>
Cc Sascha Hauer <[email protected]>
Cc Fabio Estevam <[email protected]>

---
v3->v4:
* change to use mailbox
* separate the IPC part and RPC API for easy review
* headfiles cleanup
v2->v3:
* add the ipc read/write error check
v1->v2:
* change the type of sc_ipc_t from uint32_t to unsigned long.
This can make it be capable of storing 64 bit pointer in ARMv8 system.
* Update to use the new MU library implemenation (handle iomem privately)
* remove unused delcarations e.g. sc_rpc_dispatch and sc_rpc_xlate.
* remove unneeded pad ctl functions

---
 drivers/soc/imx/Kconfig       |   4 +
 drivers/soc/imx/Makefile      |   1 +
 drivers/soc/imx/sc/Makefile   |   2 +
 drivers/soc/imx/sc/main/ipc.c | 185 ++++++++++
 drivers/soc/imx/sc/main/rpc.h |  79 +++++
 include/soc/imx/sc/ipc.h      |  45 +++
 include/soc/imx/sc/scfw.h     |  24 ++
 include/soc/imx/sc/types.h    | 764 ++++++++++++++++++++++++++++++++++++++++++
 8 files changed, 1104 insertions(+)
 create mode 100644 drivers/soc/imx/sc/Makefile
 create mode 100644 drivers/soc/imx/sc/main/ipc.c
 create mode 100644 drivers/soc/imx/sc/main/rpc.h
 create mode 100644 include/soc/imx/sc/ipc.h
 create mode 100644 include/soc/imx/sc/scfw.h
 create mode 100644 include/soc/imx/sc/types.h
drivers/soc/imx/Kconfig +4 -0
index a5b86a2..8a28474 100644
@@ -7,4 +7,8 @@ config IMX7_PM_DOMAINS
 	select PM_GENERIC_DOMAINS
 	default y if SOC_IMX7D
 
+config HAVE_IMX_SCU
+	bool
+	depends on IMX_MU
+
 endmenu
drivers/soc/imx/Makefile +1 -0
index aab41a5c..be79f67 100644
@@ -1,2 +1,3 @@
 obj-$(CONFIG_HAVE_IMX_GPC) += gpc.o
 obj-$(CONFIG_IMX7_PM_DOMAINS) += gpcv2.o
+obj-$(CONFIG_HAVE_IMX_SCU) += sc/
drivers/soc/imx/sc/Makefile new file +2 -0
new file mode 100644
index 0000000..a3db142
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0
+obj-y += main/ipc.o
drivers/soc/imx/sc/main/ipc.c new file +185 -0

185 lines not on this page · raw message

drivers/soc/imx/sc/main/rpc.h new file +79 -0

79 lines not on this page · raw message

include/soc/imx/sc/ipc.h new file +45 -0

45 lines not on this page · raw message

include/soc/imx/sc/scfw.h new file +24 -0
new file mode 100644
index 0000000..b66925b
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (C) 2016 Freescale Semiconductor, Inc.
+ * Copyright 2017~2018 NXP
+ */
+
+#ifndef _SC_SCFW_H
+#define _SC_SCFW_H
+
+#include <linux/types.h>
+
+/*
+ * This type is used to declare a handle for an IPC communication
+ * channel. Its meaning is specific to the IPC implementation.
+ */
+typedef unsigned long sc_ipc_t;
+
+/*
+ * This type is used to declare an ID for an IPC communication
+ * channel. Its meaning is specific to the IPC implementation.
+ */
+typedef unsigned long sc_ipc_id_t;
+
+#endif /* _SC_SCFW_H */
include/soc/imx/sc/types.h new file +764 -0

764 lines not on this page · raw message

Signature · 1 line
2.7.4
maintainer
#20 lore raw

PATCH v4 5/5 soc: imx: add SC firmware IPC and APIs

Hi,

Thank you for removing the majority of this patch. It really helps readability.

Quoted 4 lines · Dong Aisheng
drivers/soc/imx/sc/main/ipc.c new file +4 -0
+/* Initialization of the MU code. */
+static int imx_sc_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;

drivers/soc/imx/sc/main/ipc.c line 166

Quoted 10 lines
drivers/soc/imx/sc/main/ipc.c new file +10 -0
+	int ret;
+
+	ret = sc_ipc_open(&scu_ipc_handle, dev);
+	if (ret)
+		return ret;
+
+	pr_info("NXP i.MX SCU Initialized\n");
+
+	return devm_of_platform_populate(dev);
+}

I see that you have turned the SCU code into a driver and I really welcome that. Now when you have a driver a global scu_ipc_handle is no longer necessary. You can call platform_set_drvdata(pdev, sc_ipc); and can get that from the child devices using dev_get_drvdata(pdev->dev.parent) like for example most mfd devices do.

Quoted 16 lines
drivers/soc/imx/sc/main/ipc.c new file +16 -0
+	{ /* Sentinel */ }
+};
+
+static struct platform_driver imx_sc_driver = {
+	.driver = {
+		.name = "imx-scu",
+		.of_match_table = imx_sc_match,
+	},
+	.probe = imx_sc_probe,
+};
+
+static int __init imx_sc_init(void)
+{
+	return platform_driver_register(&imx_sc_driver);
+}
+core_initcall(imx_sc_init);

...

drivers/soc/imx/sc/main/rpc.h line 33

Quoted 12 lines
drivers/soc/imx/sc/main/rpc.h new file +12 -0
+
+#define RPC_VER(MSG)            ((MSG)->version)
+#define RPC_SIZE(MSG)           ((MSG)->size)
+#define RPC_SVC(MSG)            ((MSG)->svc)
+#define RPC_FUNC(MSG)           ((MSG)->func)
+#define RPC_R8(MSG)             ((MSG)->func)
+#define RPC_I32(MSG, IDX)       ((MSG)->DATA.i32[(IDX) / 4])
+#define RPC_I16(MSG, IDX)       ((MSG)->DATA.i16[(IDX) / 2])
+#define RPC_I8(MSG, IDX)        ((MSG)->DATA.i8[(IDX)])
+#define RPC_U32(MSG, IDX)       ((MSG)->DATA.u32[(IDX) / 4])
+#define RPC_U16(MSG, IDX)       ((MSG)->DATA.u16[(IDX) / 2])
+#define RPC_U8(MSG, IDX)        ((MSG)->DATA.u8[(IDX)])

Same as I said more than once: These macros only reduce readability of the code. Please drop them.

Quoted 4 lines
drivers/soc/imx/sc/main/rpc.h new file +4 -0
+typedef struct sc_rpc_msg_s {
+	uint8_t version;
+	uint8_t size;
+	uint8_t svc;

drivers/soc/imx/sc/main/rpc.h line 62

Quoted 10 lines
drivers/soc/imx/sc/main/rpc.h new file +10 -0
+	uint8_t func;
+	union {
+		int32_t i32[(SC_RPC_MAX_MSG - 1)];
+		int16_t i16[(SC_RPC_MAX_MSG - 1) * 2];
+		int8_t i8[(SC_RPC_MAX_MSG - 1) * 4];
+		uint32_t u32[(SC_RPC_MAX_MSG - 1)];
+		uint16_t u16[(SC_RPC_MAX_MSG - 1) * 2];
+		uint8_t u8[(SC_RPC_MAX_MSG - 1) * 4];
+	} DATA;
+} sc_rpc_msg_t;

I am pretty sure now that you should only define a common header struct, like:

struct sc_rpc_msg {
	uint8_t version;
	uint8_t size;
	uint8_t svc;
	uint8_t func;
};

This can be embedded into structs that the consumers (like clock driver) use.

include/soc/imx/sc/types.h line 24

Quoted 8 lines
include/soc/imx/sc/types.h new file +8 -0
+
+/*
+ * @name Defines for common frequencies
+ */
+#define SC_32KHZ            32768	/* 32KHz */
+#define SC_10MHZ         10000000	/* 10MHz */
+#define SC_20MHZ         20000000	/* 20MHz */
+#define SC_25MHZ         25000000	/* 25MHz */

What is the usecase for these defines? Can we add them along with the users of the defines so that we can decide then if we really want to have them?

Regards
Sascha

Signature · 4 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
author
#21 lore raw

PATCH v4 5/5 soc: imx: add SC firmware IPC and APIs

Quoted 24 lines

-----Original Message-----
From: Sascha Hauer [mailto:s.hauer at pengutronix.de]
Sent: Tuesday, July 10, 2018 10:45 PM
To: A.s. Dong <[email protected]>
Cc: linux-arm-kernel at lists.infradead.org; dongas86 at gmail.com; dl-linux-imx <[email protected]>; kernel at pengutronix.de; Fabio Estevam <[email protected]>; shawnguo at kernel.org
Subject: Re: [PATCH V4 5/5] soc: imx: add SC firmware IPC and APIs

Hi,

Thank you for removing the majority of this patch. It really helps readability.

Quoted 10 lines · Dong Aisheng
drivers/soc/imx/sc/main/ipc.c new file +10 -0
+/* Initialization of the MU code. */
+static int imx_sc_probe(struct platform_device *pdev) {
+	struct device *dev = &pdev->dev;
+	int ret;
+
+	ret = sc_ipc_open(&scu_ipc_handle, dev);
+	if (ret)
+		return ret;
+
+	pr_info("NXP i.MX SCU Initialized\n");
Quoted 9 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+	return devm_of_platform_populate(dev); }

I see that you have turned the SCU code into a driver and I really welcome that. Now when you have a driver a global scu_ipc_handle is no longer necessary. You can call platform_set_drvdata(pdev, sc_ipc); and can get that from the child devices using
dev_get_drvdata(pdev->dev.parent) like for example most mfd devices do.

It looks like a good idea.
One question: That means that the SCU users much have a node under SCU node and have struct device point, it seems ok for all normal devices like clk, pinctrl, pd. But I found some special device like soc device which does not have node and struct device, but also use SCU. How to treat for those devices? Possible anymore of them?

Quoted 54 lines
Quoted 17 lines
drivers/soc/imx/sc/main/ipc.c new file +16 -0
+	{ /* Sentinel */ }
+};
+
+static struct platform_driver imx_sc_driver = {
+	.driver = {
+		.name = "imx-scu",
+		.of_match_table = imx_sc_match,
+	},
+	.probe = imx_sc_probe,
+};
+
+static int __init imx_sc_init(void)
+{
+	return platform_driver_register(&imx_sc_driver);
+}
+core_initcall(imx_sc_init);

...

drivers/soc/imx/sc/main/rpc.h line 33

Quoted 12 lines
drivers/soc/imx/sc/main/rpc.h new file +12 -0
+
+#define RPC_VER(MSG)            ((MSG)->version)
+#define RPC_SIZE(MSG)           ((MSG)->size)
+#define RPC_SVC(MSG)            ((MSG)->svc)
+#define RPC_FUNC(MSG)           ((MSG)->func)
+#define RPC_R8(MSG)             ((MSG)->func)
+#define RPC_I32(MSG, IDX)       ((MSG)->DATA.i32[(IDX) / 4])
+#define RPC_I16(MSG, IDX)       ((MSG)->DATA.i16[(IDX) / 2])
+#define RPC_I8(MSG, IDX)        ((MSG)->DATA.i8[(IDX)])
+#define RPC_U32(MSG, IDX)       ((MSG)->DATA.u32[(IDX) / 4])
+#define RPC_U16(MSG, IDX)       ((MSG)->DATA.u16[(IDX) / 2])
+#define RPC_U8(MSG, IDX)        ((MSG)->DATA.u8[(IDX)])

Same as I said more than once: These macros only reduce readability of the code. Please drop them.

Quoted 4 lines
drivers/soc/imx/sc/main/rpc.h new file +4 -0
+typedef struct sc_rpc_msg_s {
+	uint8_t version;
+	uint8_t size;
+	uint8_t svc;

drivers/soc/imx/sc/main/rpc.h line 62

Quoted 10 lines
drivers/soc/imx/sc/main/rpc.h new file +10 -0
+	uint8_t func;
+	union {
+		int32_t i32[(SC_RPC_MAX_MSG - 1)];
+		int16_t i16[(SC_RPC_MAX_MSG - 1) * 2];
+		int8_t i8[(SC_RPC_MAX_MSG - 1) * 4];
+		uint32_t u32[(SC_RPC_MAX_MSG - 1)];
+		uint16_t u16[(SC_RPC_MAX_MSG - 1) * 2];
+		uint8_t u8[(SC_RPC_MAX_MSG - 1) * 4];
+	} DATA;
+} sc_rpc_msg_t;

I am pretty sure now that you should only define a common header struct, like:

Quoted 9 lines
struct sc_rpc_msg {
	uint8_t version;
	uint8_t size;
	uint8_t svc;
	uint8_t func;
};

This can be embedded into structs that the consumers (like clock driver) use.

Did you mean something like below (similar as TI does):

struct sc_rpc_msg {
        uint8_t ver;
        uint8_t size; 
        uint8_t svc;
        uint8_t func; 
};

// we need have two structures for each type SCU request and response

struct imx_sc_msg_req_get_clock_rate {
        struct sc_rpc_msg hdr;
        u16 resource;
        u8 clk;
} __packed;
struct imx_sc_msg_resp_get_clock_rate {
        struct sc_rpc_msg hdr;
        u32 rate;
} __packed;

sc_err_t sc_pm_get_clock_rate(sc_ipc_t ipc, sc_rsrc_t resource,
sc_pm_clk_t clk, sc_pm_clock_rate_t *rate)

{
        struct imx_sc_msg_req_get_clock_rate *msg;
        struct imx_sc_msg_resp_get_clock_rate *resp;
        struct sc_rpc_msg *hdr = &msg->hdr;
        uint8_t result;
        int ret;

        hdr->ver = SC_RPC_VERSION;
        hdr->svc = (uint8_t)SC_RPC_SVC_PM;
        hdr->func = (uint8_t)PM_FUNC_GET_CLOCK_RATE;
        hdr->size = 2;

        msg->resource = resource;
        msg->clk = clk;

        ret = sc_call_rpc(ipc, &msg, false);
        if (ret)
                return SC_ERR_FAIL;

        resp = (struct imx_sc_msg_resp_get_clock_rate *)msg;
        if (rate != NULL)
                *rate = resp->rate;

        result = resp->hdr.func;
        return (sc_err_t)result;
}

Are you okay with this?

Quoted 11 lines

include/soc/imx/sc/types.h line 24

Quoted 7 lines
include/soc/imx/sc/types.h new file +7 -0
+
+/*
+ * @name Defines for common frequencies  */
+#define SC_32KHZ            32768	/* 32KHz */
+#define SC_10MHZ         10000000	/* 10MHz */
+#define SC_20MHZ         20000000	/* 20MHz */
+#define SC_25MHZ         25000000	/* 25MHz */

What is the usecase for these defines? Can we add them along with the users of the defines so that we can decide then if we really want to have them?

Okay, I could remove them from this patch.

Regards
Dong Aisheng

Quoted 14 lines

Regards
Sascha

--
Pengutronix e.K. | |
Industrial Linux Solutions |
https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fww
w.pengutronix.de%2F&amp;data=02%7C01%7Caisheng.dong%40nxp.com%7 C8f4321d863924a5d649b08d5e673b523%7C686ea1d3bc2b4c6fa92cd99c5c3016 35%7C0%7C0%7C636668306989011249&amp;sdata=pG94K1r%2F%2Feyng%2 F1reGHfO0TEYLNJKtYTa5y%2FZqNfJjc%3D&amp;reserved=0 |

Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
maintainer
#22 lore raw

PATCH v4 5/5 soc: imx: add SC firmware IPC and APIs

Quoted 34 lines · A.s. Dong
Quoted 24 lines

-----Original Message-----
From: Sascha Hauer [mailto:s.hauer at pengutronix.de]
Sent: Tuesday, July 10, 2018 10:45 PM
To: A.s. Dong <[email protected]>
Cc: linux-arm-kernel at lists.infradead.org; dongas86 at gmail.com; dl-linux-imx <[email protected]>; kernel at pengutronix.de; Fabio Estevam <[email protected]>; shawnguo at kernel.org
Subject: Re: [PATCH V4 5/5] soc: imx: add SC firmware IPC and APIs

Hi,

Thank you for removing the majority of this patch. It really helps readability.

Quoted 10 lines · Dong Aisheng
drivers/soc/imx/sc/main/ipc.c new file +10 -0
+/* Initialization of the MU code. */
+static int imx_sc_probe(struct platform_device *pdev) {
+	struct device *dev = &pdev->dev;
+	int ret;
+
+	ret = sc_ipc_open(&scu_ipc_handle, dev);
+	if (ret)
+		return ret;
+
+	pr_info("NXP i.MX SCU Initialized\n");
Quoted 9 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+	return devm_of_platform_populate(dev); }

I see that you have turned the SCU code into a driver and I really welcome that. Now when you have a driver a global scu_ipc_handle is no longer necessary. You can call platform_set_drvdata(pdev, sc_ipc); and can get that from the child devices using
dev_get_drvdata(pdev->dev.parent) like for example most mfd devices do.

Quoted 5 lines

It looks like a good idea.
One question: That means that the SCU users much have a node under SCU node and have struct device point, it seems ok for all normal devices like clk, pinctrl, pd. But I found some special device like soc device which does not have node and struct device, but also use SCU. How to treat for those devices? Possible anymore of them?

Not sure. What kind of device is it? I'm sure we'll find a solution so maybe ask again once we are there?

Quoted 53 lines
Quoted 2 lines

This can be embedded into structs that the consumers (like clock driver) use.

Did you mean something like below (similar as TI does):

struct sc_rpc_msg {
        uint8_t ver;
        uint8_t size; 
        uint8_t svc;
        uint8_t func; 
};

// we need have two structures for each type SCU request and response

struct imx_sc_msg_req_get_clock_rate {
        struct sc_rpc_msg hdr;
        u16 resource;
        u8 clk;
} __packed;
struct imx_sc_msg_resp_get_clock_rate {
        struct sc_rpc_msg hdr;
        u32 rate;
} __packed;

sc_err_t sc_pm_get_clock_rate(sc_ipc_t ipc, sc_rsrc_t resource,
sc_pm_clk_t clk, sc_pm_clock_rate_t *rate)

{
        struct imx_sc_msg_req_get_clock_rate *msg;
        struct imx_sc_msg_resp_get_clock_rate *resp;
        struct sc_rpc_msg *hdr = &msg->hdr;
        uint8_t result;
        int ret;

        hdr->ver = SC_RPC_VERSION;
        hdr->svc = (uint8_t)SC_RPC_SVC_PM;
        hdr->func = (uint8_t)PM_FUNC_GET_CLOCK_RATE;
        hdr->size = 2;

        msg->resource = resource;
        msg->clk = clk;

        ret = sc_call_rpc(ipc, &msg, false);
        if (ret)
                return SC_ERR_FAIL;

        resp = (struct imx_sc_msg_resp_get_clock_rate *)msg;
        if (rate != NULL)
                *rate = resp->rate;

        result = resp->hdr.func;
        return (sc_err_t)result;
}
Quoted 1 line

Are you okay with this?

Yes, that's what I meant. Put this function into the clock driver directly rather than in the SCU code and we are done.

Sascha

Signature · 4 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
author
#23 lore raw

PATCH v4 5/5 soc: imx: add SC firmware IPC and APIs

Quoted 49 lines

-----Original Message-----
From: Sascha Hauer [mailto:s.hauer at pengutronix.de]
Sent: Wednesday, July 11, 2018 6:32 PM
To: A.s. Dong <[email protected]>
Cc: linux-arm-kernel at lists.infradead.org; dongas86 at gmail.com; dl-linux-imx <[email protected]>; kernel at pengutronix.de; Fabio Estevam <[email protected]>; shawnguo at kernel.org
Subject: Re: [PATCH V4 5/5] soc: imx: add SC firmware IPC and APIs

Quoted 9 lines · A.s. Dong
Quoted 9 lines

-----Original Message-----
From: Sascha Hauer [mailto:s.hauer at pengutronix.de]
Sent: Tuesday, July 10, 2018 10:45 PM
To: A.s. Dong <[email protected]>
Cc: linux-arm-kernel at lists.infradead.org; dongas86 at gmail.com; dl-linux-imx <[email protected]>; kernel at pengutronix.de; Fabio Estevam <[email protected]>; shawnguo at kernel.org
Subject: Re: [PATCH V4 5/5] soc: imx: add SC firmware IPC and APIs

Quoted 3 lines
Quoted 3 lines

Hi,

Thank you for removing the majority of this patch. It really helps

readability.

Quoted 12 lines
Quoted 12 lines · Dong Aisheng
Quoted 10 lines
drivers/soc/imx/sc/main/ipc.c new file +10 -0
+/* Initialization of the MU code. */ static int
+imx_sc_probe(struct platform_device *pdev) {
+	struct device *dev = &pdev->dev;
+	int ret;
+
+	ret = sc_ipc_open(&scu_ipc_handle, dev);
+	if (ret)
+		return ret;
+
+	pr_info("NXP i.MX SCU Initialized\n");
Quoted 8 lines
Quoted 8 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+	return devm_of_platform_populate(dev); }

I see that you have turned the SCU code into a driver and I really welcome that. Now when you have a driver a global scu_ipc_handle is no longer necessary. You can call platform_set_drvdata(pdev, sc_ipc); and can get that from the child devices using dev_get_drvdata(pdev->dev.parent) like for example most mfd devices

do.

Quoted 4 lines
Quoted 1 line

It looks like a good idea.
One question: That means that the SCU users much have a node under

SCU

Quoted 9 lines
Quoted 1 line

node and have struct device point, it seems ok for all normal devices like clk,

pinctrl, pd.

Quoted 2 lines

But I found some special device like soc device which does not have node and struct device, but also use SCU. How to treat for those devices?

Possible anymore of them?

Not sure. What kind of device is it? I'm sure we'll find a solution so maybe ask again once we are there?

See:
include/linux/sys_soc.h
arch/arm/mach-imx/cpu.c: imx_soc_device_init().

struct soc_device_attribute {
        const char *machine;
        const char *family;
        const char *revision;   
        const char *soc_id;
        const void *data;
};

And I found there's also SC services used by other normal devices Which is not under SCU node. So I wonder dev_get_drvdata(parent) may not work for them quite well.

Quoted 50 lines
Quoted 1 line
Quoted 1 line

This can be embedded into structs that the consumers (like clock driver)

use.

Quoted 48 lines
Quoted 1 line

Did you mean something like below (similar as TI does):

struct sc_rpc_msg {
        uint8_t ver;
        uint8_t size;
        uint8_t svc;
        uint8_t func;
};

// we need have two structures for each type SCU request and response

struct imx_sc_msg_req_get_clock_rate {
        struct sc_rpc_msg hdr;
        u16 resource;
        u8 clk;
} __packed;
struct imx_sc_msg_resp_get_clock_rate {
        struct sc_rpc_msg hdr;
        u32 rate;
} __packed;

sc_err_t sc_pm_get_clock_rate(sc_ipc_t ipc, sc_rsrc_t resource,
sc_pm_clk_t clk, sc_pm_clock_rate_t

*rate) {
        struct imx_sc_msg_req_get_clock_rate *msg;
        struct imx_sc_msg_resp_get_clock_rate *resp;
        struct sc_rpc_msg *hdr = &msg->hdr;
        uint8_t result;
        int ret;

        hdr->ver = SC_RPC_VERSION;
        hdr->svc = (uint8_t)SC_RPC_SVC_PM;
        hdr->func = (uint8_t)PM_FUNC_GET_CLOCK_RATE;
        hdr->size = 2;

        msg->resource = resource;
        msg->clk = clk;

        ret = sc_call_rpc(ipc, &msg, false);
        if (ret)
                return SC_ERR_FAIL;

        resp = (struct imx_sc_msg_resp_get_clock_rate *)msg;
        if (rate != NULL)
                *rate = resp->rate;
Quoted 9 lines
Quoted 5 lines
        result = resp->hdr.func;
        return (sc_err_t)result;
}

Are you okay with this?

Yes, that's what I meant. Put this function into the clock driver directly rather than in the SCU code and we are done.

It seems those are procotol services, both arm scpi and ti sci Implemented them in scu driver. drivers/firmware/ti_sci.c
drivers/firmware/arm_scpi.c
You do want to implement in each induvial client drivers?

Regards
Dong Aisheng

Quoted 13 lines

Sascha

--
Pengutronix e.K. | |
Industrial Linux Solutions |
https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fww
w.pengutronix.de%2F&amp;data=02%7C01%7Caisheng.dong%40nxp.com%7 C4d1cdc88f66c4c6e8b2c08d5e7198a09%7C686ea1d3bc2b4c6fa92cd99c5c3016 35%7C0%7C0%7C636669019236875606&amp;sdata=lpP6lpObOOKajQFz9mTai BbqLklnoLbWGrMzPxhrjpU%3D&amp;reserved=0 |

Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
#24 lore raw

v4 cover soc: imx: add scu firmware api support

In reply to Dong Aisheng
Quoted 8 lines · Dong Aisheng

Unlike the former i.MX Architectures, the new generation i.MX8 SoCs (e.g. MX8QXP and MX8QM) contain a system controller which runs on a dedicated Cortex-M core to provide power, clock, Pad, and resource management. Communication between the host processor running an OS and the system controller happens through a SCU protocol. This patchset adds the SCU APIs which is implemented based on MU and will be used by different system components.

Quoted 5 lines

It mainly consists of below parts:
1) MU mailbox driver
1) Implementation of the IPC functions based on MUs (client side).

I do understand the firmware might be already released for the current generation of platforms, but instead of adding to the fragmentation, it would be good to migrated to ARM SCMI for future platforms.

This system controller communication protocol is already so fragmented (we have TI SCI, QCOM RPM, Nvidia Tegra BPMP, ARM SCPI and so on.. and now this i.MX specific one added to that), the main intention of ARM SCMI is to stop that. The idea is for any Power Control System Architecture(PCSA) compliant systems or any similar systems, SCMI should be the standard communication protocol.

Signature · 2 lines
Regards,
Sudeep
author
#25 lore raw

v4 cover soc: imx: add scu firmware api support

Hi Sudeep,

Quoted 31 lines

-----Original Message-----
From: Sudeep Holla [mailto:sudeep.holla at arm.com]
Sent: Thursday, July 12, 2018 12:49 AM
To: A.s. Dong <[email protected]>; linux-arm-
kernel at lists.infradead.org
Cc: Sudeep Holla <[email protected]>; dongas86 at gmail.com; dl-linux- imx <[email protected]>; kernel at pengutronix.de; Fabio Estevam <[email protected]>; shawnguo at kernel.org; Cl?ment Faure <[email protected]>
Subject: Re: [PATCH V4 0/5] soc: imx: add scu firmware api support

Quoted 4 lines · Dong Aisheng

Unlike the former i.MX Architectures, the new generation i.MX8 SoCs (e.g. MX8QXP and MX8QM) contain a system controller which runs on a dedicated Cortex-M core to provide power, clock, Pad, and resource management. Communication between the host processor running an OS

and

Quoted 9 lines

the system controller happens through a SCU protocol. This patchset adds the SCU APIs which is implemented based on MU and will be used by different system components.

It mainly consists of below parts:
1) MU mailbox driver
1) Implementation of the IPC functions based on MUs (client side).

I do understand the firmware might be already released for the current generation of platforms, but instead of adding to the fragmentation, it would be good to migrated to ARM SCMI for future platforms.

Quoted 6 lines

This system controller communication protocol is already so fragmented (we have TI SCI, QCOM RPM, Nvidia Tegra BPMP, ARM SCPI and so on.. and now this i.MX specific one added to that), the main intention of ARM SCMI is to stop that. The idea is for any Power Control System Architecture(PCSA) compliant systems or any similar systems, SCMI should be the standard communication protocol.

That sounds good and worth a look.
Copy SCU firmware guys if more comments.
BTW, i.MX SCU provides more services than just power related. Not sure if ARM SCMI can cover it.

Regards
Dong Aisheng

Quoted 4 lines

--
Regards,
Sudeep

#26 lore raw

v4 cover soc: imx: add scu firmware api support

Quoted 40 lines · A.s. Dong

Hi Sudeep,

Quoted 31 lines

-----Original Message-----
From: Sudeep Holla [mailto:sudeep.holla at arm.com]
Sent: Thursday, July 12, 2018 12:49 AM
To: A.s. Dong <[email protected]>; linux-arm-
kernel at lists.infradead.org
Cc: Sudeep Holla <[email protected]>; dongas86 at gmail.com; dl-linux- imx <[email protected]>; kernel at pengutronix.de; Fabio Estevam <[email protected]>; shawnguo at kernel.org; Cl?ment Faure <[email protected]>
Subject: Re: [PATCH V4 0/5] soc: imx: add scu firmware api support

Quoted 4 lines · Dong Aisheng

Unlike the former i.MX Architectures, the new generation i.MX8 SoCs (e.g. MX8QXP and MX8QM) contain a system controller which runs on a dedicated Cortex-M core to provide power, clock, Pad, and resource management. Communication between the host processor running an OS

and

Quoted 9 lines

the system controller happens through a SCU protocol. This patchset adds the SCU APIs which is implemented based on MU and will be used by different system components.

It mainly consists of below parts:
1) MU mailbox driver
1) Implementation of the IPC functions based on MUs (client side).

I do understand the firmware might be already released for the current generation of platforms, but instead of adding to the fragmentation, it would be good to migrated to ARM SCMI for future platforms.

Quoted 6 lines

This system controller communication protocol is already so fragmented (we have TI SCI, QCOM RPM, Nvidia Tegra BPMP, ARM SCPI and so on.. and now this i.MX specific one added to that), the main intention of ARM SCMI is to stop that. The idea is for any Power Control System Architecture(PCSA) compliant systems or any similar systems, SCMI should be the standard communication protocol.

Quoted 5 lines

That sounds good and worth a look.
Copy SCU firmware guys if more comments.
BTW, i.MX SCU provides more services than just power related. Not sure if ARM SCMI can cover it.

Sure, we can extend the specification to cover those as generic protocols. If they are too NXP specific, then SCMI has options to use vendor specific protocols. I am interested to know the requirements.

Signature · 2 lines
Regards,
Sudeep
#27 lore raw

v4 cover soc: imx: add scu firmware api support

Quoted 26 lines · Sudeep Holla
Quoted 25 lines · A.s. Dong

Hi Sudeep,

Quoted 23 lines · Dong Aisheng
Quoted 11 lines

Unlike the former i.MX Architectures, the new generation i.MX8 SoCs (e.g. MX8QXP and MX8QM) contain a system controller which runs on a dedicated Cortex-M core to provide power, clock, Pad, and resource management. Communication between the host processor running an OS and the system controller happens through a SCU protocol.
This patchset adds the SCU APIs which is implemented based on MU and will be used by different system components.

It mainly consists of below parts:
1) MU mailbox driver
1) Implementation of the IPC functions based on MUs (client side).

I do understand the firmware might be already released for the current generation of platforms, but instead of adding to the fragmentation, it would be good to migrated to ARM SCMI for future platforms.

This system controller communication protocol is already so fragmented (we have TI SCI, QCOM RPM, Nvidia Tegra BPMP, ARM SCPI and so on.. and now this i.MX specific one added to that), the main intention of ARM SCMI is to stop that. The idea is for any Power Control System Architecture(PCSA) compliant systems or any similar systems, SCMI should be the standard communication protocol.

Quoted 8 lines
Quoted 4 lines

That sounds good and worth a look.
Copy SCU firmware guys if more comments.
BTW, i.MX SCU provides more services than just power related. Not sure if ARM SCMI can cover it.

Sure, we can extend the specification to cover those as generic protocols. If they are too NXP specific, then SCMI has options to use vendor specific protocols. I am interested to know the requirements.

On major thing that is missing is pin control: on 8qm/8qx this is done through the SCU but SCMI doesn't define a protocol for this. It would be a big thing to implement as a vendor extension and is required for basic functionality. Maybe SCMI will handle this in the future? If SCMI eventually includes this imx might be asked to rewrite the vendor- specific stuff anyway.

Another issue is that there doesn't seem to be any way to implement clk_set_parent through SCMI (SC API does have this). This might be intentional ("protocol does not cover discovery of clock dependencies, which must be described through firmware tables instead"). But how would the "assigned-clock-parents" DT property be implemented through SCMI?

Even if SCMI doesn't define a clock tree it might be still have something for explicit clk mux control?

One possible path to eventually using SCMI would be to define a SMC "transport" and implement SCMI calls inside ATF on top of SC API. This way ATF would hide clk implementation details in the same way that it hides hotplug and suspend details. Does this make sense?