mbox series

[0/2] mailbox: arm: introduce smc triggered mailbox

Message ID 20190523060437.11059-1-peng.fan@nxp.com (mailing list archive)
Headers show
Series mailbox: arm: introduce smc triggered mailbox | expand

Message

Peng Fan May 23, 2019, 5:50 a.m. UTC
This is a modified version from Andre Przywara's patch series
https://lore.kernel.org/patchwork/cover/812997/.
[1] is a draft implementation of i.MX8MM SCMI ATF implementation that
use smc as mailbox, power/clk is included, but only part of clk has been
implemented to work with hardware, power domain only supports get name
for now.

The traditional Linux mailbox mechanism uses some kind of dedicated hardware
IP to signal a condition to some other processing unit, typically a dedicated
management processor.
This mailbox feature is used for instance by the SCMI protocol to signal a
request for some action to be taken by the management processor.
However some SoCs does not have a dedicated management core to provide
those services. In order to service TEE and to avoid linux shutdown
power and clock that used by TEE, need let firmware to handle power
and clock, the firmware here is ARM Trusted Firmware that could also
run SCMI service.

The existing SCMI implementation uses a rather flexible shared memory
region to communicate commands and their parameters, it still requires a
mailbox to actually trigger the action.

This patch series provides a Linux mailbox compatible service which uses
smc calls to invoke firmware code, for instance taking care of SCMI requests.
The actual requests are still communicated using the standard SCMI way of
shared memory regions, but a dedicated mailbox hardware IP can be replaced via
this new driver.

This simple driver uses the architected SMC calling convention to trigger
firmware services, also allows for using "HVC" calls to call into hypervisors
or firmware layers running in the EL2 exception level.

Patch 1 contains the device tree binding documentation, patch 2 introduces
the actual mailbox driver.

Please note that this driver just provides a generic mailbox mechanism,
though this is synchronous and one-way only (triggered by the OS only,
without providing an asynchronous way of triggering request from the
firmware).
And while providing SCMI services was the reason for this exercise, this
driver is in no way bound to this use case, but can be used generically
where the OS wants to signal a mailbox condition to firmware or a
hypervisor.
Also the driver is in no way meant to replace any existing firmware
interface, but actually to complement existing interfaces.

[1] https://github.com/MrVan/arm-trusted-firmware/tree/scmi

Peng Fan (2):
  DT: mailbox: add binding doc for the ARM SMC mailbox
  mailbox: introduce ARM SMC based mailbox

 .../devicetree/bindings/mailbox/arm-smc.txt        |  96 +++++++++++++
 drivers/mailbox/Kconfig                            |   7 +
 drivers/mailbox/Makefile                           |   2 +
 drivers/mailbox/arm-smc-mailbox.c                  | 154 +++++++++++++++++++++
 include/linux/mailbox/arm-smc-mailbox.h            |  10 ++
 5 files changed, 269 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mailbox/arm-smc.txt
 create mode 100644 drivers/mailbox/arm-smc-mailbox.c
 create mode 100644 include/linux/mailbox/arm-smc-mailbox.h

Comments

Florian Fainelli May 23, 2019, 5:30 p.m. UTC | #1
Hi,

On 5/22/19 10:50 PM, Peng Fan wrote:
> This is a modified version from Andre Przywara's patch series
> https://lore.kernel.org/patchwork/cover/812997/.
> [1] is a draft implementation of i.MX8MM SCMI ATF implementation that
> use smc as mailbox, power/clk is included, but only part of clk has been
> implemented to work with hardware, power domain only supports get name
> for now.
> 
> The traditional Linux mailbox mechanism uses some kind of dedicated hardware
> IP to signal a condition to some other processing unit, typically a dedicated
> management processor.
> This mailbox feature is used for instance by the SCMI protocol to signal a
> request for some action to be taken by the management processor.
> However some SoCs does not have a dedicated management core to provide
> those services. In order to service TEE and to avoid linux shutdown
> power and clock that used by TEE, need let firmware to handle power
> and clock, the firmware here is ARM Trusted Firmware that could also
> run SCMI service.
> 
> The existing SCMI implementation uses a rather flexible shared memory
> region to communicate commands and their parameters, it still requires a
> mailbox to actually trigger the action.

We have had something similar done internally with a couple of minor
differences:

- a SGI is used to send SCMI notifications/delayed replies to support
asynchronism (patches are in the works to actually add that to the Linux
SCMI framework). There is no good support for SGI in the kernel right
now so we hacked up something from the existing SMP code and adding the
ability to register our own IPI handlers (SHAME!). Using a PPI should
work and should allow for using request_irq() AFAICT.

- the mailbox identifier is indicated as part of the SMC call such that
we can have multiple SCMI mailboxes serving both standard protocols and
non-standard (in the 0x80 and above) range, also they may have different
throughput (in hindsight, these could simply be different channels)

Your patch series looks both good and useful to me, I would just put a
provision in the binding to support an optional interrupt such that
asynchronism gets reasonably easy to plug in when it is available (and
desirable).

> 
> This patch series provides a Linux mailbox compatible service which uses
> smc calls to invoke firmware code, for instance taking care of SCMI requests.
> The actual requests are still communicated using the standard SCMI way of
> shared memory regions, but a dedicated mailbox hardware IP can be replaced via
> this new driver.
> 
> This simple driver uses the architected SMC calling convention to trigger
> firmware services, also allows for using "HVC" calls to call into hypervisors
> or firmware layers running in the EL2 exception level.
> 
> Patch 1 contains the device tree binding documentation, patch 2 introduces
> the actual mailbox driver.
> 
> Please note that this driver just provides a generic mailbox mechanism,
> though this is synchronous and one-way only (triggered by the OS only,
> without providing an asynchronous way of triggering request from the
> firmware).
> And while providing SCMI services was the reason for this exercise, this
> driver is in no way bound to this use case, but can be used generically
> where the OS wants to signal a mailbox condition to firmware or a
> hypervisor.
> Also the driver is in no way meant to replace any existing firmware
> interface, but actually to complement existing interfaces.
> 
> [1] https://github.com/MrVan/arm-trusted-firmware/tree/scmi
> 
> Peng Fan (2):
>   DT: mailbox: add binding doc for the ARM SMC mailbox
>   mailbox: introduce ARM SMC based mailbox
> 
>  .../devicetree/bindings/mailbox/arm-smc.txt        |  96 +++++++++++++
>  drivers/mailbox/Kconfig                            |   7 +
>  drivers/mailbox/Makefile                           |   2 +
>  drivers/mailbox/arm-smc-mailbox.c                  | 154 +++++++++++++++++++++
>  include/linux/mailbox/arm-smc-mailbox.h            |  10 ++
>  5 files changed, 269 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/mailbox/arm-smc.txt
>  create mode 100644 drivers/mailbox/arm-smc-mailbox.c
>  create mode 100644 include/linux/mailbox/arm-smc-mailbox.h
>
Sudeep Holla May 24, 2019, 5:56 p.m. UTC | #2
On Thu, May 23, 2019 at 10:30:50AM -0700, Florian Fainelli wrote:
> Hi,
>
> On 5/22/19 10:50 PM, Peng Fan wrote:
> > This is a modified version from Andre Przywara's patch series
> > https://lore.kernel.org/patchwork/cover/812997/.
> > [1] is a draft implementation of i.MX8MM SCMI ATF implementation that
> > use smc as mailbox, power/clk is included, but only part of clk has been
> > implemented to work with hardware, power domain only supports get name
> > for now.
> >
> > The traditional Linux mailbox mechanism uses some kind of dedicated hardware
> > IP to signal a condition to some other processing unit, typically a dedicated
> > management processor.
> > This mailbox feature is used for instance by the SCMI protocol to signal a
> > request for some action to be taken by the management processor.
> > However some SoCs does not have a dedicated management core to provide
> > those services. In order to service TEE and to avoid linux shutdown
> > power and clock that used by TEE, need let firmware to handle power
> > and clock, the firmware here is ARM Trusted Firmware that could also
> > run SCMI service.
> >
> > The existing SCMI implementation uses a rather flexible shared memory
> > region to communicate commands and their parameters, it still requires a
> > mailbox to actually trigger the action.
>
> We have had something similar done internally with a couple of minor
> differences:
>
> - a SGI is used to send SCMI notifications/delayed replies to support
> asynchronism (patches are in the works to actually add that to the Linux
> SCMI framework). There is no good support for SGI in the kernel right
> now so we hacked up something from the existing SMP code and adding the
> ability to register our own IPI handlers (SHAME!). Using a PPI should
> work and should allow for using request_irq() AFAICT.
>

We have been thinking this since we were asked if SMC can be transport.
Generally out of 16 SGIs, 8 are reserved for secure side and non-secure
has 8. Of these 8, IIUC 7 is already being used by kernel. So unless we
manage to get the last one reserved exclusive to SCMI, it makes it
difficult to add SGI support in SCMI.

We have been telling partners/vendors about this limitation if they
use SMC as transport and need to have dedicated h/w interrupt for the
notifications.

Another issue could be with virtualisation(using HVC) and EL handling
so called SCMI SGI. We need to think about those too. I will try to get
more info on this and come back on this.

--
Regards,
Sudeep
Andre Przywara May 26, 2019, 11:59 p.m. UTC | #3
On 24/05/2019 18:56, Sudeep Holla wrote:
> On Thu, May 23, 2019 at 10:30:50AM -0700, Florian Fainelli wrote:

Hi,

>> On 5/22/19 10:50 PM, Peng Fan wrote:
>>> This is a modified version from Andre Przywara's patch series
>>> https://lore.kernel.org/patchwork/cover/812997/.
>>> [1] is a draft implementation of i.MX8MM SCMI ATF implementation that
>>> use smc as mailbox, power/clk is included, but only part of clk has been
>>> implemented to work with hardware, power domain only supports get name
>>> for now.
>>>
>>> The traditional Linux mailbox mechanism uses some kind of dedicated hardware
>>> IP to signal a condition to some other processing unit, typically a dedicated
>>> management processor.
>>> This mailbox feature is used for instance by the SCMI protocol to signal a
>>> request for some action to be taken by the management processor.
>>> However some SoCs does not have a dedicated management core to provide
>>> those services. In order to service TEE and to avoid linux shutdown
>>> power and clock that used by TEE, need let firmware to handle power
>>> and clock, the firmware here is ARM Trusted Firmware that could also
>>> run SCMI service.
>>>
>>> The existing SCMI implementation uses a rather flexible shared memory
>>> region to communicate commands and their parameters, it still requires a
>>> mailbox to actually trigger the action.
>>
>> We have had something similar done internally with a couple of minor
>> differences:
>>
>> - a SGI is used to send SCMI notifications/delayed replies to support
>> asynchronism (patches are in the works to actually add that to the Linux
>> SCMI framework). There is no good support for SGI in the kernel right
>> now so we hacked up something from the existing SMP code and adding the
>> ability to register our own IPI handlers (SHAME!). Using a PPI should
>> work and should allow for using request_irq() AFAICT.
>>
> 
> We have been thinking this since we were asked if SMC can be transport.
> Generally out of 16 SGIs, 8 are reserved for secure side and non-secure
> has 8. Of these 8, IIUC 7 is already being used by kernel. So unless we
> manage to get the last one reserved exclusive to SCMI, it makes it
> difficult to add SGI support in SCMI.
> 
> We have been telling partners/vendors about this limitation if they
> use SMC as transport and need to have dedicated h/w interrupt for the
> notifications.
> 
> Another issue could be with virtualisation(using HVC) and EL handling
> so called SCMI SGI. We need to think about those too. I will try to get
> more info on this and come back on this.

I think regardless of the *current* feasibility of using SGIs in *Linux*
we should at least specify an "interrupts" property in the binding, to
allow for future usage. We might copy the pmuv3 way [1] of allowing to
specify multiple SPI interrupts as well, to give more flexibility.
After all an implementation could offload the asynchronous notification
to a separate core, and that could use SPIs, for instance.

Cheers,
Andre.

[1] Documentation/devicetree/bindings/arm/pmu.yaml:45
Jassi Brar May 27, 2019, 1:55 a.m. UTC | #4
On Thu, May 23, 2019 at 12:50 AM Peng Fan <peng.fan@nxp.com> wrote:
>
> This is a modified version from Andre Przywara's patch series
> https://lore.kernel.org/patchwork/cover/812997/.
>
Can you please specify exact modifications on top of Andre's last
submission? As in "Changes since v1: ...."

Thanks.
Peng Fan May 27, 2019, 2:06 a.m. UTC | #5
Hi Jassi,

> Subject: Re: [PATCH 0/2] mailbox: arm: introduce smc triggered mailbox
> 
> On Thu, May 23, 2019 at 12:50 AM Peng Fan <peng.fan@nxp.com> wrote:
> >
> > This is a modified version from Andre Przywara's patch series
> >
> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.ke
> rnel.org%2Fpatchwork%2Fcover%2F812997%2F&amp;data=02%7C01%7Cpe
> ng.fan%40nxp.com%7C40bb1632f99248f24e1308d6e2467c8b%7C686ea1d3b
> c2b4c6fa92cd99c5c301635%7C0%7C1%7C636945189705620796&amp;sdat
> a=v6mLyDKLO8NaBMlX6XlOCtOs2C41TuOG9yFDY%2F7q8nU%3D&amp;reser
> ved=0.
> >
> Can you please specify exact modifications on top of Andre's last submission?
> As in "Changes since v1: ...."

Since Andre's last v2 version was sent in 2017, I thought no need to add that.
The changes are mostly.
Introduce arm,num-chans
Introduce arm_smccc_mbox_cmd
txdone_poll and txdone_irq are both set to false
arm,func-ids are kept, but as an optional property.
Rewords SCPI to SCMI, because I am trying SCMI over SMC, not SCPI.

I'll add the changes information after I collect more comments in this patchset.

Thanks,
Peng.
> 
> Thanks.
Peng Fan May 27, 2019, 5:19 a.m. UTC | #6
Hi Florian,

> Subject: Re: [PATCH 0/2] mailbox: arm: introduce smc triggered mailbox
> 
> Hi,
> 
> On 5/22/19 10:50 PM, Peng Fan wrote:
> > This is a modified version from Andre Przywara's patch series
> >
> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.ke
> rnel.org%2Fpatchwork%2Fcover%2F812997%2F&amp;data=02%7C01%7Cpe
> ng.fan%40nxp.com%7C010c9ddd5df645c9c66b08d6dfa46cb2%7C686ea1d3b
> c2b4c6fa92cd99c5c301635%7C0%7C0%7C636942294631442665&amp;sdat
> a=BbS5ZQtzMANSwaKRDJ62NKrPrAyaED1%2BvymQaT6Qr8E%3D&amp;rese
> rved=0.
> > [1] is a draft implementation of i.MX8MM SCMI ATF implementation that
> > use smc as mailbox, power/clk is included, but only part of clk has
> > been implemented to work with hardware, power domain only supports get
> > name for now.
> >
> > The traditional Linux mailbox mechanism uses some kind of dedicated
> > hardware IP to signal a condition to some other processing unit,
> > typically a dedicated management processor.
> > This mailbox feature is used for instance by the SCMI protocol to
> > signal a request for some action to be taken by the management processor.
> > However some SoCs does not have a dedicated management core to
> provide
> > those services. In order to service TEE and to avoid linux shutdown
> > power and clock that used by TEE, need let firmware to handle power
> > and clock, the firmware here is ARM Trusted Firmware that could also
> > run SCMI service.
> >
> > The existing SCMI implementation uses a rather flexible shared memory
> > region to communicate commands and their parameters, it still requires
> > a mailbox to actually trigger the action.
> 
> We have had something similar done internally with a couple of minor
> differences:
> 
> - a SGI is used to send SCMI notifications/delayed replies to support
> asynchronism (patches are in the works to actually add that to the Linux SCMI
> framework). There is no good support for SGI in the kernel right now so we
> hacked up something from the existing SMP code and adding the ability to
> register our own IPI handlers (SHAME!). Using a PPI should work and should
> allow for using request_irq() AFAICT.

So you are also implementing a firmware inside ATF for SCMI usecase, right?

Introducing SGI in ATF to notify Linux will introduce complexity, there is
no good framework inside ATF for SCMI, and I use synchronization call for
simplicity for now.

> 
> - the mailbox identifier is indicated as part of the SMC call such that we can
> have multiple SCMI mailboxes serving both standard protocols and
> non-standard (in the 0x80 and above) range, also they may have different
> throughput (in hindsight, these could simply be different channels)
> 
> Your patch series looks both good and useful to me, I would just put a
> provision in the binding to support an optional interrupt such that
> asynchronism gets reasonably easy to plug in when it is available (and
> desirable).

Ok. Let me think about and add that in new version patch.

Thanks,
Peng.

> 
> >
> > This patch series provides a Linux mailbox compatible service which
> > uses smc calls to invoke firmware code, for instance taking care of SCMI
> requests.
> > The actual requests are still communicated using the standard SCMI way
> > of shared memory regions, but a dedicated mailbox hardware IP can be
> > replaced via this new driver.
> >
> > This simple driver uses the architected SMC calling convention to
> > trigger firmware services, also allows for using "HVC" calls to call
> > into hypervisors or firmware layers running in the EL2 exception level.
> >
> > Patch 1 contains the device tree binding documentation, patch 2
> > introduces the actual mailbox driver.
> >
> > Please note that this driver just provides a generic mailbox
> > mechanism, though this is synchronous and one-way only (triggered by
> > the OS only, without providing an asynchronous way of triggering
> > request from the firmware).
> > And while providing SCMI services was the reason for this exercise,
> > this driver is in no way bound to this use case, but can be used
> > generically where the OS wants to signal a mailbox condition to
> > firmware or a hypervisor.
> > Also the driver is in no way meant to replace any existing firmware
> > interface, but actually to complement existing interfaces.
> >
> > [1]
> > https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgith
> >
> ub.com%2FMrVan%2Farm-trusted-firmware%2Ftree%2Fscmi&amp;data=02
> %7C01%7
> >
> Cpeng.fan%40nxp.com%7C010c9ddd5df645c9c66b08d6dfa46cb2%7C686ea1
> d3bc2b4
> >
> c6fa92cd99c5c301635%7C0%7C0%7C636942294631442665&amp;sdata=kN
> 9bEFFcsZA
> > 1ePeNLLfHmONpVaG6O5ajVQvKMuaBXyk%3D&amp;reserved=0
> >
> > Peng Fan (2):
> >   DT: mailbox: add binding doc for the ARM SMC mailbox
> >   mailbox: introduce ARM SMC based mailbox
> >
> >  .../devicetree/bindings/mailbox/arm-smc.txt        |  96
> +++++++++++++
> >  drivers/mailbox/Kconfig                            |   7 +
> >  drivers/mailbox/Makefile                           |   2 +
> >  drivers/mailbox/arm-smc-mailbox.c                  | 154
> +++++++++++++++++++++
> >  include/linux/mailbox/arm-smc-mailbox.h            |  10 ++
> >  5 files changed, 269 insertions(+)
> >  create mode 100644
> > Documentation/devicetree/bindings/mailbox/arm-smc.txt
> >  create mode 100644 drivers/mailbox/arm-smc-mailbox.c  create mode
> > 100644 include/linux/mailbox/arm-smc-mailbox.h
> >
> 
> 
> --
> Florian
Peng Fan May 27, 2019, 6:18 a.m. UTC | #7
Hi Sudeep,

> Subject: Re: [PATCH 0/2] mailbox: arm: introduce smc triggered mailbox
> 
> On Thu, May 23, 2019 at 10:30:50AM -0700, Florian Fainelli wrote:
> > Hi,
> >
> > On 5/22/19 10:50 PM, Peng Fan wrote:
> > > This is a modified version from Andre Przywara's patch series
> > >
> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.ke
> rnel.org%2Fpatchwork%2Fcover%2F812997%2F&amp;data=02%7C01%7Cpe
> ng.fan%40nxp.com%7Cfa2ba15f479b49eb219f08d6e0713ea3%7C686ea1d3b
> c2b4c6fa92cd99c5c301635%7C0%7C0%7C636943174355592142&amp;sdat
> a=Y94rnxDEoMm9nyRyjJrYBqRduc5XkvvQhno7zfIQ%2B04%3D&amp;reserve
> d=0.
> > > [1] is a draft implementation of i.MX8MM SCMI ATF implementation
> > > that use smc as mailbox, power/clk is included, but only part of clk
> > > has been implemented to work with hardware, power domain only
> > > supports get name for now.
> > >
> > > The traditional Linux mailbox mechanism uses some kind of dedicated
> > > hardware IP to signal a condition to some other processing unit,
> > > typically a dedicated management processor.
> > > This mailbox feature is used for instance by the SCMI protocol to
> > > signal a request for some action to be taken by the management
> processor.
> > > However some SoCs does not have a dedicated management core to
> > > provide those services. In order to service TEE and to avoid linux
> > > shutdown power and clock that used by TEE, need let firmware to
> > > handle power and clock, the firmware here is ARM Trusted Firmware
> > > that could also run SCMI service.
> > >
> > > The existing SCMI implementation uses a rather flexible shared
> > > memory region to communicate commands and their parameters, it still
> > > requires a mailbox to actually trigger the action.
> >
> > We have had something similar done internally with a couple of minor
> > differences:
> >
> > - a SGI is used to send SCMI notifications/delayed replies to support
> > asynchronism (patches are in the works to actually add that to the
> > Linux SCMI framework). There is no good support for SGI in the kernel
> > right now so we hacked up something from the existing SMP code and
> > adding the ability to register our own IPI handlers (SHAME!). Using a
> > PPI should work and should allow for using request_irq() AFAICT.
> >
> 
> We have been thinking this since we were asked if SMC can be transport.
> Generally out of 16 SGIs, 8 are reserved for secure side and non-secure has 8.
> Of these 8, IIUC 7 is already being used by kernel. So unless we manage to get
> the last one reserved exclusive to SCMI, it makes it difficult to add SGI support
> in SCMI.
> 
> We have been telling partners/vendors about this limitation if they use SMC
> as transport and need to have dedicated h/w interrupt for the notifications.

This is an option, and we could add optional property.

> 
> Another issue could be with virtualisation(using HVC) and EL handling so called
> SCMI SGI. We need to think about those too. 

Using dedicated HW for virtualization that support vcpu scheduling might be
not a good choice, do you mean this? Dedicated pin vcpu to pcpu should be fine,
just like jailhouse hypervisor.

I will try to get more info on this
> and come back on this.

Looking forward.

Thanks,
Peng.

> 
> --
> Regards,
> Sudeep
Peng Fan May 27, 2019, 6:29 a.m. UTC | #8
Hi Andre,

> Subject: Re: [PATCH 0/2] mailbox: arm: introduce smc triggered mailbox
> 
> On 24/05/2019 18:56, Sudeep Holla wrote:
> > On Thu, May 23, 2019 at 10:30:50AM -0700, Florian Fainelli wrote:
> 
> Hi,
> 
> >> On 5/22/19 10:50 PM, Peng Fan wrote:
> >>> This is a modified version from Andre Przywara's patch series
> >>>
> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.ke
> rnel.org%2Fpatchwork%2Fcover%2F812997%2F&amp;data=02%7C01%7Cpe
> ng.fan%40nxp.com%7C02ee9487370c4eb9158008d6e2363ca0%7C686ea1d3
> bc2b4c6fa92cd99c5c301635%7C0%7C0%7C636945119959534576&amp;sda
> ta=U8FzX3FX2PoEZhRuRMhFbkaAnb3cqjZsb9%2FTdt8OfuY%3D&amp;reserve
> d=0.
> >>> [1] is a draft implementation of i.MX8MM SCMI ATF implementation
> >>> that use smc as mailbox, power/clk is included, but only part of clk
> >>> has been implemented to work with hardware, power domain only
> >>> supports get name for now.
> >>>
> >>> The traditional Linux mailbox mechanism uses some kind of dedicated
> >>> hardware IP to signal a condition to some other processing unit,
> >>> typically a dedicated management processor.
> >>> This mailbox feature is used for instance by the SCMI protocol to
> >>> signal a request for some action to be taken by the management
> processor.
> >>> However some SoCs does not have a dedicated management core to
> >>> provide those services. In order to service TEE and to avoid linux
> >>> shutdown power and clock that used by TEE, need let firmware to
> >>> handle power and clock, the firmware here is ARM Trusted Firmware
> >>> that could also run SCMI service.
> >>>
> >>> The existing SCMI implementation uses a rather flexible shared
> >>> memory region to communicate commands and their parameters, it still
> >>> requires a mailbox to actually trigger the action.
> >>
> >> We have had something similar done internally with a couple of minor
> >> differences:
> >>
> >> - a SGI is used to send SCMI notifications/delayed replies to support
> >> asynchronism (patches are in the works to actually add that to the
> >> Linux SCMI framework). There is no good support for SGI in the kernel
> >> right now so we hacked up something from the existing SMP code and
> >> adding the ability to register our own IPI handlers (SHAME!). Using a
> >> PPI should work and should allow for using request_irq() AFAICT.
> >>
> >
> > We have been thinking this since we were asked if SMC can be transport.
> > Generally out of 16 SGIs, 8 are reserved for secure side and
> > non-secure has 8. Of these 8, IIUC 7 is already being used by kernel.
> > So unless we manage to get the last one reserved exclusive to SCMI, it
> > makes it difficult to add SGI support in SCMI.
> >
> > We have been telling partners/vendors about this limitation if they
> > use SMC as transport and need to have dedicated h/w interrupt for the
> > notifications.
> >
> > Another issue could be with virtualisation(using HVC) and EL handling
> > so called SCMI SGI. We need to think about those too. I will try to
> > get more info on this and come back on this.
> 
> I think regardless of the *current* feasibility of using SGIs in *Linux* we
> should at least specify an "interrupts" property in the binding, to allow for
> future usage. We might copy the pmuv3 way [1] of allowing to specify
> multiple SPI interrupts as well, to give more flexibility.

This needs to go with an optional property, agree?
That means smc mailbox needs to support synchronous and asynchronous
communication. I'll try to add that and write some porotype code to
verify.

Thanks,
Peng.

> After all an implementation could offload the asynchronous notification to a
> separate core, and that could use SPIs, for instance.
> 
> Cheers,
> Andre.
> 
> [1] Documentation/devicetree/bindings/arm/pmu.yaml:45
Florian Fainelli May 27, 2019, 7:11 p.m. UTC | #9
On 5/26/2019 10:19 PM, Peng Fan wrote:
> Hi Florian,
> 
>> Subject: Re: [PATCH 0/2] mailbox: arm: introduce smc triggered mailbox
>>
>> Hi,
>>
>> On 5/22/19 10:50 PM, Peng Fan wrote:
>>> This is a modified version from Andre Przywara's patch series
>>>
>> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.ke
>> rnel.org%2Fpatchwork%2Fcover%2F812997%2F&amp;data=02%7C01%7Cpe
>> ng.fan%40nxp.com%7C010c9ddd5df645c9c66b08d6dfa46cb2%7C686ea1d3b
>> c2b4c6fa92cd99c5c301635%7C0%7C0%7C636942294631442665&amp;sdat
>> a=BbS5ZQtzMANSwaKRDJ62NKrPrAyaED1%2BvymQaT6Qr8E%3D&amp;rese
>> rved=0.
>>> [1] is a draft implementation of i.MX8MM SCMI ATF implementation that
>>> use smc as mailbox, power/clk is included, but only part of clk has
>>> been implemented to work with hardware, power domain only supports get
>>> name for now.
>>>
>>> The traditional Linux mailbox mechanism uses some kind of dedicated
>>> hardware IP to signal a condition to some other processing unit,
>>> typically a dedicated management processor.
>>> This mailbox feature is used for instance by the SCMI protocol to
>>> signal a request for some action to be taken by the management processor.
>>> However some SoCs does not have a dedicated management core to
>> provide
>>> those services. In order to service TEE and to avoid linux shutdown
>>> power and clock that used by TEE, need let firmware to handle power
>>> and clock, the firmware here is ARM Trusted Firmware that could also
>>> run SCMI service.
>>>
>>> The existing SCMI implementation uses a rather flexible shared memory
>>> region to communicate commands and their parameters, it still requires
>>> a mailbox to actually trigger the action.
>>
>> We have had something similar done internally with a couple of minor
>> differences:
>>
>> - a SGI is used to send SCMI notifications/delayed replies to support
>> asynchronism (patches are in the works to actually add that to the Linux SCMI
>> framework). There is no good support for SGI in the kernel right now so we
>> hacked up something from the existing SMP code and adding the ability to
>> register our own IPI handlers (SHAME!). Using a PPI should work and should
>> allow for using request_irq() AFAICT.
> 
> So you are also implementing a firmware inside ATF for SCMI usecase, right?

Correct, SCMI is implemented in part within the trusted firmware (it is
not ATF, something custom), and in part using an external processor for
specific tasks.

> 
> Introducing SGI in ATF to notify Linux will introduce complexity, there is
> no good framework inside ATF for SCMI, and I use synchronization call for
> simplicity for now.

Sure that's fine, the point we all seem to agree upon is that putting
provision in the binding document for an optional interrupt is already
known to be desirable.

> 
>>
>> - the mailbox identifier is indicated as part of the SMC call such that we can
>> have multiple SCMI mailboxes serving both standard protocols and
>> non-standard (in the 0x80 and above) range, also they may have different
>> throughput (in hindsight, these could simply be different channels)
>>
>> Your patch series looks both good and useful to me, I would just put a
>> provision in the binding to support an optional interrupt such that
>> asynchronism gets reasonably easy to plug in when it is available (and
>> desirable).
> 
> Ok. Let me think about and add that in new version patch.
> 
> Thanks,
> Peng.
> 
>>
>>>
>>> This patch series provides a Linux mailbox compatible service which
>>> uses smc calls to invoke firmware code, for instance taking care of SCMI
>> requests.
>>> The actual requests are still communicated using the standard SCMI way
>>> of shared memory regions, but a dedicated mailbox hardware IP can be
>>> replaced via this new driver.
>>>
>>> This simple driver uses the architected SMC calling convention to
>>> trigger firmware services, also allows for using "HVC" calls to call
>>> into hypervisors or firmware layers running in the EL2 exception level.
>>>
>>> Patch 1 contains the device tree binding documentation, patch 2
>>> introduces the actual mailbox driver.
>>>
>>> Please note that this driver just provides a generic mailbox
>>> mechanism, though this is synchronous and one-way only (triggered by
>>> the OS only, without providing an asynchronous way of triggering
>>> request from the firmware).
>>> And while providing SCMI services was the reason for this exercise,
>>> this driver is in no way bound to this use case, but can be used
>>> generically where the OS wants to signal a mailbox condition to
>>> firmware or a hypervisor.
>>> Also the driver is in no way meant to replace any existing firmware
>>> interface, but actually to complement existing interfaces.
>>>
>>> [1]
>>> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgith
>>>
>> ub.com%2FMrVan%2Farm-trusted-firmware%2Ftree%2Fscmi&amp;data=02
>> %7C01%7
>>>
>> Cpeng.fan%40nxp.com%7C010c9ddd5df645c9c66b08d6dfa46cb2%7C686ea1
>> d3bc2b4
>>>
>> c6fa92cd99c5c301635%7C0%7C0%7C636942294631442665&amp;sdata=kN
>> 9bEFFcsZA
>>> 1ePeNLLfHmONpVaG6O5ajVQvKMuaBXyk%3D&amp;reserved=0
>>>
>>> Peng Fan (2):
>>>   DT: mailbox: add binding doc for the ARM SMC mailbox
>>>   mailbox: introduce ARM SMC based mailbox
>>>
>>>  .../devicetree/bindings/mailbox/arm-smc.txt        |  96
>> +++++++++++++
>>>  drivers/mailbox/Kconfig                            |   7 +
>>>  drivers/mailbox/Makefile                           |   2 +
>>>  drivers/mailbox/arm-smc-mailbox.c                  | 154
>> +++++++++++++++++++++
>>>  include/linux/mailbox/arm-smc-mailbox.h            |  10 ++
>>>  5 files changed, 269 insertions(+)
>>>  create mode 100644
>>> Documentation/devicetree/bindings/mailbox/arm-smc.txt
>>>  create mode 100644 drivers/mailbox/arm-smc-mailbox.c  create mode
>>> 100644 include/linux/mailbox/arm-smc-mailbox.h
>>>
>>
>>
>> --
>> Florian
Andre Przywara May 30, 2019, 11:23 a.m. UTC | #10
On Mon, 27 May 2019 05:19:41 +0000
Peng Fan <peng.fan@nxp.com> wrote:

Hi,

> > Subject: Re: [PATCH 0/2] mailbox: arm: introduce smc triggered mailbox
> > 
> > Hi,
> > 
> > On 5/22/19 10:50 PM, Peng Fan wrote:  
> > > This is a modified version from Andre Przywara's patch series
> > >  
> > https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.ke
> > rnel.org%2Fpatchwork%2Fcover%2F812997%2F&amp;data=02%7C01%7Cpe
> > ng.fan%40nxp.com%7C010c9ddd5df645c9c66b08d6dfa46cb2%7C686ea1d3b
> > c2b4c6fa92cd99c5c301635%7C0%7C0%7C636942294631442665&amp;sdat
> > a=BbS5ZQtzMANSwaKRDJ62NKrPrAyaED1%2BvymQaT6Qr8E%3D&amp;rese
> > rved=0.  
> > > [1] is a draft implementation of i.MX8MM SCMI ATF implementation that
> > > use smc as mailbox, power/clk is included, but only part of clk has
> > > been implemented to work with hardware, power domain only supports get
> > > name for now.
> > >
> > > The traditional Linux mailbox mechanism uses some kind of dedicated
> > > hardware IP to signal a condition to some other processing unit,
> > > typically a dedicated management processor.
> > > This mailbox feature is used for instance by the SCMI protocol to
> > > signal a request for some action to be taken by the management processor.
> > > However some SoCs does not have a dedicated management core to  
> > provide  
> > > those services. In order to service TEE and to avoid linux shutdown
> > > power and clock that used by TEE, need let firmware to handle power
> > > and clock, the firmware here is ARM Trusted Firmware that could also
> > > run SCMI service.
> > >
> > > The existing SCMI implementation uses a rather flexible shared memory
> > > region to communicate commands and their parameters, it still requires
> > > a mailbox to actually trigger the action.  
> > 
> > We have had something similar done internally with a couple of minor
> > differences:
> > 
> > - a SGI is used to send SCMI notifications/delayed replies to support
> > asynchronism (patches are in the works to actually add that to the Linux SCMI
> > framework). There is no good support for SGI in the kernel right now so we
> > hacked up something from the existing SMP code and adding the ability to
> > register our own IPI handlers (SHAME!). Using a PPI should work and should
> > allow for using request_irq() AFAICT.  
> 
> So you are also implementing a firmware inside ATF for SCMI usecase, right?
> 
> Introducing SGI in ATF to notify Linux will introduce complexity, there is
> no good framework inside ATF for SCMI, and I use synchronization call for
> simplicity for now.

I think we don't disagree, but just to clarify on one thing:

I think we should avoid tying this driver to specific protocol or software on the other end, be it ATF or SCMI. After all it's just a mailbox driver, meant to signal some event (and parameters) to some external entity. Yes, SCMI (or SCPI back then) was the reason to push for this, but it should be independent from that. I am not even sure we should mention it too much in the documentation.

So whether the receiving end is ATF or something else it irrelevant, I think. For instance we have had discussions in Xen to provide guests some virtualised device management support, and using an HVC mailbox seems like a neat solution. This could be using the SCMI (or SCPI) protocol, but that's not a requirement. In this case the Xen hypervisor would be the one to pick up the mailbox trigger, probably forwarding the request to something else (Dom0 in this case).
Also having a generic SMC mailbox could avoid having the actual hardware mailbox drivers in the kernel, so EL3 firmware could forward the request to an external management processor, and Linux would just work, without the need to describe the actual hardware mailbox device in some firmware tables. This might help ACPI on those devices.

Cheers,
Andre.

> > 
> > - the mailbox identifier is indicated as part of the SMC call such that we can
> > have multiple SCMI mailboxes serving both standard protocols and
> > non-standard (in the 0x80 and above) range, also they may have different
> > throughput (in hindsight, these could simply be different channels)
> > 
> > Your patch series looks both good and useful to me, I would just put a
> > provision in the binding to support an optional interrupt such that
> > asynchronism gets reasonably easy to plug in when it is available (and
> > desirable).  
> 
> Ok. Let me think about and add that in new version patch.
> 
> Thanks,
> Peng.
> 
> >   
> > >
> > > This patch series provides a Linux mailbox compatible service which
> > > uses smc calls to invoke firmware code, for instance taking care of SCMI  
> > requests.  
> > > The actual requests are still communicated using the standard SCMI way
> > > of shared memory regions, but a dedicated mailbox hardware IP can be
> > > replaced via this new driver.
> > >
> > > This simple driver uses the architected SMC calling convention to
> > > trigger firmware services, also allows for using "HVC" calls to call
> > > into hypervisors or firmware layers running in the EL2 exception level.
> > >
> > > Patch 1 contains the device tree binding documentation, patch 2
> > > introduces the actual mailbox driver.
> > >
> > > Please note that this driver just provides a generic mailbox
> > > mechanism, though this is synchronous and one-way only (triggered by
> > > the OS only, without providing an asynchronous way of triggering
> > > request from the firmware).
> > > And while providing SCMI services was the reason for this exercise,
> > > this driver is in no way bound to this use case, but can be used
> > > generically where the OS wants to signal a mailbox condition to
> > > firmware or a hypervisor.
> > > Also the driver is in no way meant to replace any existing firmware
> > > interface, but actually to complement existing interfaces.
> > >
> > > [1]
> > > https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgith
> > >  
> > ub.com%2FMrVan%2Farm-trusted-firmware%2Ftree%2Fscmi&amp;data=02
> > %7C01%7  
> > >  
> > Cpeng.fan%40nxp.com%7C010c9ddd5df645c9c66b08d6dfa46cb2%7C686ea1
> > d3bc2b4  
> > >  
> > c6fa92cd99c5c301635%7C0%7C0%7C636942294631442665&amp;sdata=kN
> > 9bEFFcsZA  
> > > 1ePeNLLfHmONpVaG6O5ajVQvKMuaBXyk%3D&amp;reserved=0
> > >
> > > Peng Fan (2):
> > >   DT: mailbox: add binding doc for the ARM SMC mailbox
> > >   mailbox: introduce ARM SMC based mailbox
> > >
> > >  .../devicetree/bindings/mailbox/arm-smc.txt        |  96  
> > +++++++++++++  
> > >  drivers/mailbox/Kconfig                            |   7 +
> > >  drivers/mailbox/Makefile                           |   2 +
> > >  drivers/mailbox/arm-smc-mailbox.c                  | 154  
> > +++++++++++++++++++++  
> > >  include/linux/mailbox/arm-smc-mailbox.h            |  10 ++
> > >  5 files changed, 269 insertions(+)
> > >  create mode 100644
> > > Documentation/devicetree/bindings/mailbox/arm-smc.txt
> > >  create mode 100644 drivers/mailbox/arm-smc-mailbox.c  create mode
> > > 100644 include/linux/mailbox/arm-smc-mailbox.h
> > >  
> > 
> > 
> > --
> > Florian
Peng Fan May 31, 2019, 1:39 a.m. UTC | #11
> 
> > > Subject: Re: [PATCH 0/2] mailbox: arm: introduce smc triggered
> > > mailbox
> > >
> > > Hi,
> > >
> > > On 5/22/19 10:50 PM, Peng Fan wrote:
> > > > This is a modified version from Andre Przywara's patch series
> > > >
> > > https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flo
> > > re.ke
> rnel.org%2Fpatchwork%2Fcover%2F812997%2F&amp;data=02%7C01%7Cpe
> > >
> ng.fan%40nxp.com%7C010c9ddd5df645c9c66b08d6dfa46cb2%7C686ea1d3b
> > >
> c2b4c6fa92cd99c5c301635%7C0%7C0%7C636942294631442665&amp;sdat
> > >
> a=BbS5ZQtzMANSwaKRDJ62NKrPrAyaED1%2BvymQaT6Qr8E%3D&amp;rese
> > > rved=0.
> > > > [1] is a draft implementation of i.MX8MM SCMI ATF implementation
> > > > that use smc as mailbox, power/clk is included, but only part of
> > > > clk has been implemented to work with hardware, power domain only
> > > > supports get name for now.
> > > >
> > > > The traditional Linux mailbox mechanism uses some kind of
> > > > dedicated hardware IP to signal a condition to some other
> > > > processing unit, typically a dedicated management processor.
> > > > This mailbox feature is used for instance by the SCMI protocol to
> > > > signal a request for some action to be taken by the management
> processor.
> > > > However some SoCs does not have a dedicated management core to
> > > provide
> > > > those services. In order to service TEE and to avoid linux
> > > > shutdown power and clock that used by TEE, need let firmware to
> > > > handle power and clock, the firmware here is ARM Trusted Firmware
> > > > that could also run SCMI service.
> > > >
> > > > The existing SCMI implementation uses a rather flexible shared
> > > > memory region to communicate commands and their parameters, it
> > > > still requires a mailbox to actually trigger the action.
> > >
> > > We have had something similar done internally with a couple of minor
> > > differences:
> > >
> > > - a SGI is used to send SCMI notifications/delayed replies to
> > > support asynchronism (patches are in the works to actually add that
> > > to the Linux SCMI framework). There is no good support for SGI in
> > > the kernel right now so we hacked up something from the existing SMP
> > > code and adding the ability to register our own IPI handlers
> > > (SHAME!). Using a PPI should work and should allow for using request_irq()
> AFAICT.
> >
> > So you are also implementing a firmware inside ATF for SCMI usecase, right?
> >
> > Introducing SGI in ATF to notify Linux will introduce complexity,
> > there is no good framework inside ATF for SCMI, and I use
> > synchronization call for simplicity for now.
> 
> I think we don't disagree, but just to clarify on one thing:
> 
> I think we should avoid tying this driver to specific protocol or software on the
> other end, be it ATF or SCMI. After all it's just a mailbox driver, meant to signal
> some event (and parameters) to some external entity. Yes, SCMI (or SCPI back
> then) was the reason to push for this, but it should be independent from that.

Thanks, I agree.

> I am not even sure we should mention it too much in the documentation.

I think we need a usecase here, so it should be fine.

> 
> So whether the receiving end is ATF or something else it irrelevant, I think. For
> instance we have had discussions in Xen to provide guests some virtualised
> device management support, and using an HVC mailbox seems like a neat
> solution. This could be using the SCMI (or SCPI) protocol, but that's not a
> requirement. In this case the Xen hypervisor would be the one to pick up the
> mailbox trigger, probably forwarding the request to something else (Dom0 in
> this case).

I do not get the point "forwarding the request", DomU HVC will trap to Xen,
so how to forward to Dom0?

Thanks,
Peng.

> Also having a generic SMC mailbox could avoid having the actual hardware
> mailbox drivers in the kernel, so EL3 firmware could forward the request to an
> external management processor, and Linux would just work, without the need
> to describe the actual hardware mailbox device in some firmware tables. This
> might help ACPI on those devices.
> 
> Cheers,
> Andre.
> 
> > >
> > > - the mailbox identifier is indicated as part of the SMC call such
> > > that we can have multiple SCMI mailboxes serving both standard
> > > protocols and non-standard (in the 0x80 and above) range, also they
> > > may have different throughput (in hindsight, these could simply be
> > > different channels)
> > >
> > > Your patch series looks both good and useful to me, I would just put
> > > a provision in the binding to support an optional interrupt such
> > > that asynchronism gets reasonably easy to plug in when it is
> > > available (and desirable).
> >
> > Ok. Let me think about and add that in new version patch.
> >
> > Thanks,
> > Peng.
> >
> > >
> > > >
> > > > This patch series provides a Linux mailbox compatible service
> > > > which uses smc calls to invoke firmware code, for instance taking
> > > > care of SCMI
> > > requests.
> > > > The actual requests are still communicated using the standard SCMI
> > > > way of shared memory regions, but a dedicated mailbox hardware IP
> > > > can be replaced via this new driver.
> > > >
> > > > This simple driver uses the architected SMC calling convention to
> > > > trigger firmware services, also allows for using "HVC" calls to
> > > > call into hypervisors or firmware layers running in the EL2 exception
> level.
> > > >
> > > > Patch 1 contains the device tree binding documentation, patch 2
> > > > introduces the actual mailbox driver.
> > > >
> > > > Please note that this driver just provides a generic mailbox
> > > > mechanism, though this is synchronous and one-way only (triggered
> > > > by the OS only, without providing an asynchronous way of
> > > > triggering request from the firmware).
> > > > And while providing SCMI services was the reason for this
> > > > exercise, this driver is in no way bound to this use case, but can
> > > > be used generically where the OS wants to signal a mailbox
> > > > condition to firmware or a hypervisor.
> > > > Also the driver is in no way meant to replace any existing
> > > > firmware interface, but actually to complement existing interfaces.
> > > >
> > > > [1]
> > > > https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2F
> > > > gith
> > > >
> > >
> ub.com%2FMrVan%2Farm-trusted-firmware%2Ftree%2Fscmi&amp;data=02
> > > %7C01%7
> > > >
> > >
> Cpeng.fan%40nxp.com%7C010c9ddd5df645c9c66b08d6dfa46cb2%7C686ea1
> > > d3bc2b4
> > > >
> > >
> c6fa92cd99c5c301635%7C0%7C0%7C636942294631442665&amp;sdata=kN
> > > 9bEFFcsZA
> > > > 1ePeNLLfHmONpVaG6O5ajVQvKMuaBXyk%3D&amp;reserved=0
> > > >
> > > > Peng Fan (2):
> > > >   DT: mailbox: add binding doc for the ARM SMC mailbox
> > > >   mailbox: introduce ARM SMC based mailbox
> > > >
> > > >  .../devicetree/bindings/mailbox/arm-smc.txt        |  96
> > > +++++++++++++
> > > >  drivers/mailbox/Kconfig                            |   7 +
> > > >  drivers/mailbox/Makefile                           |   2 +
> > > >  drivers/mailbox/arm-smc-mailbox.c                  | 154
> > > +++++++++++++++++++++
> > > >  include/linux/mailbox/arm-smc-mailbox.h            |  10 ++
> > > >  5 files changed, 269 insertions(+)  create mode 100644
> > > > Documentation/devicetree/bindings/mailbox/arm-smc.txt
> > > >  create mode 100644 drivers/mailbox/arm-smc-mailbox.c  create
> mode
> > > > 100644 include/linux/mailbox/arm-smc-mailbox.h
> > > >
> > >
> > >
> > > --
> > > Florian
Andre Przywara June 3, 2019, 5:24 p.m. UTC | #12
On Fri, 31 May 2019 01:39:45 +0000
Peng Fan <peng.fan@nxp.com> wrote:

Hi,

(CC:ing Julien for Xen)

> > > > Subject: Re: [PATCH 0/2] mailbox: arm: introduce smc triggered
> > > > mailbox
> > > >
> > > > Hi,
> > > >
> > > > On 5/22/19 10:50 PM, Peng Fan wrote:  
> > > > > This is a modified version from Andre Przywara's patch series
> > > > >  
> > > > https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flo
> > > > re.ke  
> > rnel.org%2Fpatchwork%2Fcover%2F812997%2F&amp;data=02%7C01%7Cpe  
> > > >  
> > ng.fan%40nxp.com%7C010c9ddd5df645c9c66b08d6dfa46cb2%7C686ea1d3b  
> > > >  
> > c2b4c6fa92cd99c5c301635%7C0%7C0%7C636942294631442665&amp;sdat  
> > > >  
> > a=BbS5ZQtzMANSwaKRDJ62NKrPrAyaED1%2BvymQaT6Qr8E%3D&amp;rese  
> > > > rved=0.  
> > > > > [1] is a draft implementation of i.MX8MM SCMI ATF implementation
> > > > > that use smc as mailbox, power/clk is included, but only part of
> > > > > clk has been implemented to work with hardware, power domain only
> > > > > supports get name for now.
> > > > >
> > > > > The traditional Linux mailbox mechanism uses some kind of
> > > > > dedicated hardware IP to signal a condition to some other
> > > > > processing unit, typically a dedicated management processor.
> > > > > This mailbox feature is used for instance by the SCMI protocol to
> > > > > signal a request for some action to be taken by the management  
> > processor.  
> > > > > However some SoCs does not have a dedicated management core to  
> > > > provide  
> > > > > those services. In order to service TEE and to avoid linux
> > > > > shutdown power and clock that used by TEE, need let firmware to
> > > > > handle power and clock, the firmware here is ARM Trusted Firmware
> > > > > that could also run SCMI service.
> > > > >
> > > > > The existing SCMI implementation uses a rather flexible shared
> > > > > memory region to communicate commands and their parameters, it
> > > > > still requires a mailbox to actually trigger the action.  
> > > >
> > > > We have had something similar done internally with a couple of minor
> > > > differences:
> > > >
> > > > - a SGI is used to send SCMI notifications/delayed replies to
> > > > support asynchronism (patches are in the works to actually add that
> > > > to the Linux SCMI framework). There is no good support for SGI in
> > > > the kernel right now so we hacked up something from the existing SMP
> > > > code and adding the ability to register our own IPI handlers
> > > > (SHAME!). Using a PPI should work and should allow for using request_irq()  
> > AFAICT.  
> > >
> > > So you are also implementing a firmware inside ATF for SCMI usecase, right?
> > >
> > > Introducing SGI in ATF to notify Linux will introduce complexity,
> > > there is no good framework inside ATF for SCMI, and I use
> > > synchronization call for simplicity for now.  
> > 
> > I think we don't disagree, but just to clarify on one thing:
> > 
> > I think we should avoid tying this driver to specific protocol or software on the
> > other end, be it ATF or SCMI. After all it's just a mailbox driver, meant to signal
> > some event (and parameters) to some external entity. Yes, SCMI (or SCPI back
> > then) was the reason to push for this, but it should be independent from that.  
> 
> Thanks, I agree.
> 
> > I am not even sure we should mention it too much in the documentation.  
> 
> I think we need a usecase here, so it should be fine.
> 
> > 
> > So whether the receiving end is ATF or something else it irrelevant, I think. For
> > instance we have had discussions in Xen to provide guests some virtualised
> > device management support, and using an HVC mailbox seems like a neat
> > solution. This could be using the SCMI (or SCPI) protocol, but that's not a
> > requirement. In this case the Xen hypervisor would be the one to pick up the
> > mailbox trigger, probably forwarding the request to something else (Dom0 in
> > this case).  
> 
> I do not get the point "forwarding the request", DomU HVC will trap to Xen,
> so how to forward to Dom0?

I don't think there is something easily available in Xen/ARM at the moment, but we could either use something like an event channel, or utilise some planned extension to allow Dom0 to register on MMIO traps.
My point was that most likely Dom0 would be in control of the resources handled by the interface (clocks, regulators), so Xen wouldn't know how to deal with those requests.

Cheers,
Andre.


> 
> Thanks,
> Peng.
> 
> > Also having a generic SMC mailbox could avoid having the actual hardware
> > mailbox drivers in the kernel, so EL3 firmware could forward the request to an
> > external management processor, and Linux would just work, without the need
> > to describe the actual hardware mailbox device in some firmware tables. This
> > might help ACPI on those devices.
> > 
> > Cheers,
> > Andre.
> >   
> > > >
> > > > - the mailbox identifier is indicated as part of the SMC call such
> > > > that we can have multiple SCMI mailboxes serving both standard
> > > > protocols and non-standard (in the 0x80 and above) range, also they
> > > > may have different throughput (in hindsight, these could simply be
> > > > different channels)
> > > >
> > > > Your patch series looks both good and useful to me, I would just put
> > > > a provision in the binding to support an optional interrupt such
> > > > that asynchronism gets reasonably easy to plug in when it is
> > > > available (and desirable).  
> > >
> > > Ok. Let me think about and add that in new version patch.
> > >
> > > Thanks,
> > > Peng.
> > >  
> > > >  
> > > > >
> > > > > This patch series provides a Linux mailbox compatible service
> > > > > which uses smc calls to invoke firmware code, for instance taking
> > > > > care of SCMI  
> > > > requests.  
> > > > > The actual requests are still communicated using the standard SCMI
> > > > > way of shared memory regions, but a dedicated mailbox hardware IP
> > > > > can be replaced via this new driver.
> > > > >
> > > > > This simple driver uses the architected SMC calling convention to
> > > > > trigger firmware services, also allows for using "HVC" calls to
> > > > > call into hypervisors or firmware layers running in the EL2 exception  
> > level.  
> > > > >
> > > > > Patch 1 contains the device tree binding documentation, patch 2
> > > > > introduces the actual mailbox driver.
> > > > >
> > > > > Please note that this driver just provides a generic mailbox
> > > > > mechanism, though this is synchronous and one-way only (triggered
> > > > > by the OS only, without providing an asynchronous way of
> > > > > triggering request from the firmware).
> > > > > And while providing SCMI services was the reason for this
> > > > > exercise, this driver is in no way bound to this use case, but can
> > > > > be used generically where the OS wants to signal a mailbox
> > > > > condition to firmware or a hypervisor.
> > > > > Also the driver is in no way meant to replace any existing
> > > > > firmware interface, but actually to complement existing interfaces.
> > > > >
> > > > > [1]
> > > > > https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2F
> > > > > gith
> > > > >  
> > > >  
> > ub.com%2FMrVan%2Farm-trusted-firmware%2Ftree%2Fscmi&amp;data=02  
> > > > %7C01%7  
> > > > >  
> > > >  
> > Cpeng.fan%40nxp.com%7C010c9ddd5df645c9c66b08d6dfa46cb2%7C686ea1  
> > > > d3bc2b4  
> > > > >  
> > > >  
> > c6fa92cd99c5c301635%7C0%7C0%7C636942294631442665&amp;sdata=kN  
> > > > 9bEFFcsZA  
> > > > > 1ePeNLLfHmONpVaG6O5ajVQvKMuaBXyk%3D&amp;reserved=0
> > > > >
> > > > > Peng Fan (2):
> > > > >   DT: mailbox: add binding doc for the ARM SMC mailbox
> > > > >   mailbox: introduce ARM SMC based mailbox
> > > > >
> > > > >  .../devicetree/bindings/mailbox/arm-smc.txt        |  96  
> > > > +++++++++++++  
> > > > >  drivers/mailbox/Kconfig                            |   7 +
> > > > >  drivers/mailbox/Makefile                           |   2 +
> > > > >  drivers/mailbox/arm-smc-mailbox.c                  | 154  
> > > > +++++++++++++++++++++  
> > > > >  include/linux/mailbox/arm-smc-mailbox.h            |  10 ++
> > > > >  5 files changed, 269 insertions(+)  create mode 100644
> > > > > Documentation/devicetree/bindings/mailbox/arm-smc.txt
> > > > >  create mode 100644 drivers/mailbox/arm-smc-mailbox.c  create  
> > mode  
> > > > > 100644 include/linux/mailbox/arm-smc-mailbox.h
> > > > >  
> > > >
> > > >
> > > > --
> > > > Florian  
>