mbox series

[v2,0/4] Implement vendor resets for PSCI SYSTEM_RESET2

Message ID 20240414-arm-psci-system_reset2-vendor-reboots-v2-0-da9a055a648f@quicinc.com
Headers show
Series Implement vendor resets for PSCI SYSTEM_RESET2 | expand

Message

Elliot Berman April 14, 2024, 7:30 p.m. UTC
The PSCI SYSTEM_RESET2 call allows vendor firmware to define additional
reset types which could be mapped to the reboot argument.

Setting up reboot on Qualcomm devices can be inconsistent from chipset
to chipset.  Generally, there is a PMIC register that gets written to
decide the reboot type. There is also sometimes a cookie that can be
written to indicate that the bootloader should behave differently than a
regular boot. These knobs evolve over product generations and require 
more drivers. Qualcomm firmwares are beginning to expose vendor
SYSTEM_RESET2 types to simplify driver requirements from Linux.

Add support in PSCI to statically wire reboot mode commands from
userspace to a vendor reset and cookie value using the device tree. The
DT bindings are similar to reboot mode framework except that 2
integers are accepted (the type and cookie). Also, reboot mode framework
is intended to program, but not reboot, the host. PSCI SYSTEM_RESET2
does both. I've not added support for reading ACPI tables since I don't
have any device which provides them + firmware that supports vendor
SYSTEM_RESET2 types.

Previous discussions around SYSTEM_RESET2:
- https://lore.kernel.org/lkml/20230724223057.1208122-2-quic_eberman@quicinc.com/T/
- https://lore.kernel.org/all/4a679542-b48d-7e11-f33a-63535a5c68cb@quicinc.com/

Signed-off-by: Elliot Berman <quic_eberman@quicinc.com>
---
Changes in v2:
- Fixes to schema as suggested by Rob and Krzysztof
- Add qcm6490 idp as first Qualcomm device to support
- Link to v1: https://lore.kernel.org/r/20231117-arm-psci-system_reset2-vendor-reboots-v1-0-03c4612153e2@quicinc.com

Changes in v1:
- Reference reboot-mode bindings as suggeted by Rob.
- Link to RFC: https://lore.kernel.org/r/20231030-arm-psci-system_reset2-vendor-reboots-v1-0-dcdd63352ad1@quicinc.com

---
Elliot Berman (4):
      dt-bindings: power: reset: Convert mode-.* properties to array
      dt-bindings: arm: Document reboot mode magic
      firmware: psci: Read and use vendor reset types
      arm64: dts: qcom: Add PSCI SYSTEM_RESET2 types for qcm6490-idp

 Documentation/devicetree/bindings/arm/psci.yaml    | 38 ++++++++-
 .../bindings/power/reset/nvmem-reboot-mode.yaml    |  4 +
 .../devicetree/bindings/power/reset/qcom,pon.yaml  |  4 +
 .../bindings/power/reset/reboot-mode.yaml          | 12 ++-
 .../bindings/power/reset/syscon-reboot-mode.yaml   |  4 +
 arch/arm64/boot/dts/qcom/qcm6490-idp.dts           |  5 ++
 drivers/firmware/psci/psci.c                       | 90 ++++++++++++++++++++++
 7 files changed, 153 insertions(+), 4 deletions(-)
---
base-commit: b5d2afe8745bf3eef5a59a13313798d24f2af983
change-id: 20231016-arm-psci-system_reset2-vendor-reboots-cc3ad456c070

Best regards,

Comments

Dmitry Baryshkov April 14, 2024, 11:13 p.m. UTC | #1
On Sun, 14 Apr 2024 at 22:32, Elliot Berman <quic_eberman@quicinc.com> wrote:
>
> Add nodes for the vendor-defined system resets. "bootloader" will cause
> device to reboot and stop in the bootloader's fastboot mode. "edl" will
> cause device to reboot into "emergency download mode", which permits
> loading images via the Firehose protocol.
>
> Co-developed-by: Shivendra Pratap <quic_spratap@quicinc.com>
> Signed-off-by: Shivendra Pratap <quic_spratap@quicinc.com>
> Signed-off-by: Elliot Berman <quic_eberman@quicinc.com>
> ---
>  arch/arm64/boot/dts/qcom/qcm6490-idp.dts | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/arch/arm64/boot/dts/qcom/qcm6490-idp.dts b/arch/arm64/boot/dts/qcom/qcm6490-idp.dts
> index e4bfad50a669..a966f6c8dd7c 100644
> --- a/arch/arm64/boot/dts/qcom/qcm6490-idp.dts
> +++ b/arch/arm64/boot/dts/qcom/qcm6490-idp.dts
> @@ -126,6 +126,11 @@ debug_vm_mem: debug-vm@d0600000 {
>                 };
>         };
>
> +       psci {

Please use a label instead. Otherwise it looks as if you are adding
new device node.

> +               mode-bootloader = <0x10001 0x2>;
> +               mode-edl = <0 0x1>;
> +       };
> +
>         vph_pwr: vph-pwr-regulator {
>                 compatible = "regulator-fixed";
>                 regulator-name = "vph_pwr";
>
> --
> 2.34.1
>
>
Elliot Berman April 15, 2024, 12:32 a.m. UTC | #2
On Mon, Apr 15, 2024 at 02:13:29AM +0300, Dmitry Baryshkov wrote:
> On Sun, 14 Apr 2024 at 22:32, Elliot Berman <quic_eberman@quicinc.com> wrote:
> >
> > Add nodes for the vendor-defined system resets. "bootloader" will cause
> > device to reboot and stop in the bootloader's fastboot mode. "edl" will
> > cause device to reboot into "emergency download mode", which permits
> > loading images via the Firehose protocol.
> >
> > Co-developed-by: Shivendra Pratap <quic_spratap@quicinc.com>
> > Signed-off-by: Shivendra Pratap <quic_spratap@quicinc.com>
> > Signed-off-by: Elliot Berman <quic_eberman@quicinc.com>
> > ---
> >  arch/arm64/boot/dts/qcom/qcm6490-idp.dts | 5 +++++
> >  1 file changed, 5 insertions(+)
> >
> > diff --git a/arch/arm64/boot/dts/qcom/qcm6490-idp.dts b/arch/arm64/boot/dts/qcom/qcm6490-idp.dts
> > index e4bfad50a669..a966f6c8dd7c 100644
> > --- a/arch/arm64/boot/dts/qcom/qcm6490-idp.dts
> > +++ b/arch/arm64/boot/dts/qcom/qcm6490-idp.dts
> > @@ -126,6 +126,11 @@ debug_vm_mem: debug-vm@d0600000 {
> >                 };
> >         };
> >
> > +       psci {
> 
> Please use a label instead. Otherwise it looks as if you are adding
> new device node.
> 

Right. Fixed for the next revision.

Thanks,
Elliot

> > +               mode-bootloader = <0x10001 0x2>;
> > +               mode-edl = <0 0x1>;
> > +       };
> > +
> >         vph_pwr: vph-pwr-regulator {
> >                 compatible = "regulator-fixed";
> >                 regulator-name = "vph_pwr";
> >
> > --
> > 2.34.1
> >
> >
> 
> 
> -- 
> With best wishes
> Dmitry
Konrad Dybcio April 15, 2024, 7:39 p.m. UTC | #3
On 4/14/24 21:30, Elliot Berman wrote:
> SoC vendors have different types of resets and are controlled through
> various registers. For instance, Qualcomm chipsets can reboot to a
> "download mode" that allows a RAM dump to be collected. Another example
> is they also support writing a cookie that can be read by bootloader
> during next boot. PSCI offers a mechanism, SYSTEM_RESET2, for these
> vendor reset types to be implemented without requiring drivers for every
> register/cookie.
> 
> Add support in PSCI to statically map reboot mode commands from
> userspace to a vendor reset and cookie value using the device tree.
> 
> Reboot mode framework is close but doesn't quite fit with the
> design and requirements for PSCI SYSTEM_RESET2. Some of these issues can
> be solved but doesn't seem reasonable in sum:
>   1. reboot mode registers against the reboot_notifier_list, which is too
>      early to call SYSTEM_RESET2. PSCI would need to remember the reset
>      type from the reboot-mode framework callback and use it
>      psci_sys_reset.
>   2. reboot mode assumes only one cookie/parameter is described in the
>      device tree. SYSTEM_RESET2 uses 2: one for the type and one for
>      cookie.
>   3. psci cpuidle driver already registers a driver against the
>      arm,psci-1.0 compatible. Refactoring would be needed to have both a
>      cpuidle and reboot-mode driver.
> 
> Signed-off-by: Elliot Berman <quic_eberman@quicinc.com>
> ---

[...]

> +arch_initcall(psci_init_system_reset2_modes);

Perhaps this could be called from \/

Konrad

> +
>   int __init psci_dt_init(void)
>   {
>   	struct device_node *np;
>
Konrad Dybcio April 15, 2024, 7:42 p.m. UTC | #4
On 4/15/24 02:32, Elliot Berman wrote:
> On Mon, Apr 15, 2024 at 02:13:29AM +0300, Dmitry Baryshkov wrote:
>> On Sun, 14 Apr 2024 at 22:32, Elliot Berman <quic_eberman@quicinc.com> wrote:
>>>
>>> Add nodes for the vendor-defined system resets. "bootloader" will cause
>>> device to reboot and stop in the bootloader's fastboot mode. "edl" will
>>> cause device to reboot into "emergency download mode", which permits
>>> loading images via the Firehose protocol.
>>>
>>> Co-developed-by: Shivendra Pratap <quic_spratap@quicinc.com>
>>> Signed-off-by: Shivendra Pratap <quic_spratap@quicinc.com>
>>> Signed-off-by: Elliot Berman <quic_eberman@quicinc.com>
>>> ---
>>>   arch/arm64/boot/dts/qcom/qcm6490-idp.dts | 5 +++++
>>>   1 file changed, 5 insertions(+)
>>>
>>> diff --git a/arch/arm64/boot/dts/qcom/qcm6490-idp.dts b/arch/arm64/boot/dts/qcom/qcm6490-idp.dts
>>> index e4bfad50a669..a966f6c8dd7c 100644
>>> --- a/arch/arm64/boot/dts/qcom/qcm6490-idp.dts
>>> +++ b/arch/arm64/boot/dts/qcom/qcm6490-idp.dts
>>> @@ -126,6 +126,11 @@ debug_vm_mem: debug-vm@d0600000 {
>>>                  };
>>>          };
>>>
>>> +       psci {
>>
>> Please use a label instead. Otherwise it looks as if you are adding
>> new device node.
>>
> 
> Right. Fixed for the next revision.

Are you guys planning to make this sorta ABI-like?

If so (which would be greatly appreciated by the way..), perhaps you
could stick these magic values in dt-bindings and give them cool names

FWIW DEN0022 (my second-favorite book) suggests these values are almost
totally vendor-defined, so if I were Qualcomm, I'd take the creative
liberty to come up with a set of numbers and never ever ever change
them

Konrad
Elliot Berman April 16, 2024, 1:11 a.m. UTC | #5
On Mon, Apr 15, 2024 at 09:42:40PM +0200, Konrad Dybcio wrote:
> 
> 
> On 4/15/24 02:32, Elliot Berman wrote:
> > On Mon, Apr 15, 2024 at 02:13:29AM +0300, Dmitry Baryshkov wrote:
> > > On Sun, 14 Apr 2024 at 22:32, Elliot Berman <quic_eberman@quicinc.com> wrote:
> > > > 
> > > > Add nodes for the vendor-defined system resets. "bootloader" will cause
> > > > device to reboot and stop in the bootloader's fastboot mode. "edl" will
> > > > cause device to reboot into "emergency download mode", which permits
> > > > loading images via the Firehose protocol.
> > > > 
> > > > Co-developed-by: Shivendra Pratap <quic_spratap@quicinc.com>
> > > > Signed-off-by: Shivendra Pratap <quic_spratap@quicinc.com>
> > > > Signed-off-by: Elliot Berman <quic_eberman@quicinc.com>
> > > > ---
> > > >   arch/arm64/boot/dts/qcom/qcm6490-idp.dts | 5 +++++
> > > >   1 file changed, 5 insertions(+)
> > > > 
> > > > diff --git a/arch/arm64/boot/dts/qcom/qcm6490-idp.dts b/arch/arm64/boot/dts/qcom/qcm6490-idp.dts
> > > > index e4bfad50a669..a966f6c8dd7c 100644
> > > > --- a/arch/arm64/boot/dts/qcom/qcm6490-idp.dts
> > > > +++ b/arch/arm64/boot/dts/qcom/qcm6490-idp.dts
> > > > @@ -126,6 +126,11 @@ debug_vm_mem: debug-vm@d0600000 {
> > > >                  };
> > > >          };
> > > > 
> > > > +       psci {
> > > 
> > > Please use a label instead. Otherwise it looks as if you are adding
> > > new device node.
> > > 
> > 
> > Right. Fixed for the next revision.
> 
> Are you guys planning to make this sorta ABI-like?
> 
> If so (which would be greatly appreciated by the way..), perhaps you
> could stick these magic values in dt-bindings and give them cool names
> 
> FWIW DEN0022 (my second-favorite book) suggests these values are almost
> totally vendor-defined, so if I were Qualcomm, I'd take the creative
> liberty to come up with a set of numbers and never ever ever change
> them

This is my goal as well. I'd like to keep the magic values out of
dt-bindings until we get the vendor SYSTEM_RESET2 spread across more
devices, as things might need a bit of settling. Since having stable
vendor reset2 is (IMO) primarily a benefit to Qualcomm, I expect this
will happen naturally.
Sudeep Holla April 16, 2024, 9:35 a.m. UTC | #6
On Sun, Apr 14, 2024 at 12:30:23PM -0700, Elliot Berman wrote:
> The PSCI SYSTEM_RESET2 call allows vendor firmware to define additional
> reset types which could be mapped to the reboot argument.
>
> Setting up reboot on Qualcomm devices can be inconsistent from chipset
> to chipset.

That doesn't sound good. Do you mean PSCI SYSTEM_RESET doesn't work as
expected ? Does it mean it is not conformant to the specification ?

> Generally, there is a PMIC register that gets written to
> decide the reboot type. There is also sometimes a cookie that can be
> written to indicate that the bootloader should behave differently than a
> regular boot. These knobs evolve over product generations and require
> more drivers. Qualcomm firmwares are beginning to expose vendor
> SYSTEM_RESET2 types to simplify driver requirements from Linux.
>

Why can't this be fully userspace driven ? What is the need to keep the
cookie in the DT ?
Florian Fainelli April 17, 2024, 5:50 p.m. UTC | #7
On 4/16/24 02:35, Sudeep Holla wrote:
> On Sun, Apr 14, 2024 at 12:30:23PM -0700, Elliot Berman wrote:
>> The PSCI SYSTEM_RESET2 call allows vendor firmware to define additional
>> reset types which could be mapped to the reboot argument.
>>
>> Setting up reboot on Qualcomm devices can be inconsistent from chipset
>> to chipset.
> 
> That doesn't sound good. Do you mean PSCI SYSTEM_RESET doesn't work as
> expected ? Does it mean it is not conformant to the specification ?
> 
>> Generally, there is a PMIC register that gets written to
>> decide the reboot type. There is also sometimes a cookie that can be
>> written to indicate that the bootloader should behave differently than a
>> regular boot. These knobs evolve over product generations and require
>> more drivers. Qualcomm firmwares are beginning to expose vendor
>> SYSTEM_RESET2 types to simplify driver requirements from Linux.
>>
> 
> Why can't this be fully userspace driven ? What is the need to keep the
> cookie in the DT ?
> 
> 

Using the second example in the Device Tree:

mode-bootloader = <1 2>;

are you suggesting that within psci_vendor_sys_reset2() we would look at 
the data argument and assume that we have something like this in memory:

const char *cmd = data;

cmd[] = "bootloader 2"

where "bootloader" is the reboot command, and "2" is the cookie? From an 
util-linux, busybox, toybox, etc. we would have to concatenate those 
arguments with a space, but I suppose that would be doable.

For the use cases that I am after we did not have a need for the cookie, 
so I admit I did not think too much about it.
Elliot Berman April 17, 2024, 9:54 p.m. UTC | #8
On Tue, Apr 16, 2024 at 10:35:22AM +0100, Sudeep Holla wrote:
> On Sun, Apr 14, 2024 at 12:30:23PM -0700, Elliot Berman wrote:
> > The PSCI SYSTEM_RESET2 call allows vendor firmware to define additional
> > reset types which could be mapped to the reboot argument.
> >
> > Setting up reboot on Qualcomm devices can be inconsistent from chipset
> > to chipset.
> 
> That doesn't sound good. Do you mean PSCI SYSTEM_RESET doesn't work as
> expected ? Does it mean it is not conformant to the specification ?
> 

I was motivating the reason for using SYSTEM_RESET2. How to set the PMIC
register and IMEM cookie can change between chipsets. Using
SYSTEM_RESET2 alows us to abstract how to perform the reset.

> > Generally, there is a PMIC register that gets written to
> > decide the reboot type. There is also sometimes a cookie that can be
> > written to indicate that the bootloader should behave differently than a
> > regular boot. These knobs evolve over product generations and require
> > more drivers. Qualcomm firmwares are beginning to expose vendor
> > SYSTEM_RESET2 types to simplify driver requirements from Linux.
> >
> 
> Why can't this be fully userspace driven ? What is the need to keep the
> cookie in the DT ?

As Dmitry pointed out, this information isn't discoverable. I suppose
we could technically use bootconfig or kernel command-line to convey the
map although I think devicetree is the right spot for this mapping.

- Other vendor-specific bits for PSCI are described in the devicetree.
  One example is the suspend param (e.g. the StateID) for cpu idle
  states.
- Describing firmware bits in the DT isn't unprecedented, and putting
  this information outside the DT means that other OSes (besides Linux)
  need their own way to convey this information.
- PSCI would be the odd one out that reboot mode map is not described in
  DT. Other reboot-mode drivers specify the mapping in the DT. Userspace
  that runs with firmware that support vendor reset2 need to make sure
  they can configure the mapping early enough.

Thanks,
Elliot
Florian Fainelli April 17, 2024, 10:01 p.m. UTC | #9
On 4/17/24 14:54, Elliot Berman wrote:
> On Tue, Apr 16, 2024 at 10:35:22AM +0100, Sudeep Holla wrote:
>> On Sun, Apr 14, 2024 at 12:30:23PM -0700, Elliot Berman wrote:
>>> The PSCI SYSTEM_RESET2 call allows vendor firmware to define additional
>>> reset types which could be mapped to the reboot argument.
>>>
>>> Setting up reboot on Qualcomm devices can be inconsistent from chipset
>>> to chipset.
>>
>> That doesn't sound good. Do you mean PSCI SYSTEM_RESET doesn't work as
>> expected ? Does it mean it is not conformant to the specification ?
>>
> 
> I was motivating the reason for using SYSTEM_RESET2. How to set the PMIC
> register and IMEM cookie can change between chipsets. Using
> SYSTEM_RESET2 alows us to abstract how to perform the reset.
> 
>>> Generally, there is a PMIC register that gets written to
>>> decide the reboot type. There is also sometimes a cookie that can be
>>> written to indicate that the bootloader should behave differently than a
>>> regular boot. These knobs evolve over product generations and require
>>> more drivers. Qualcomm firmwares are beginning to expose vendor
>>> SYSTEM_RESET2 types to simplify driver requirements from Linux.
>>>
>>
>> Why can't this be fully userspace driven ? What is the need to keep the
>> cookie in the DT ?
> 
> As Dmitry pointed out, this information isn't discoverable. I suppose
> we could technically use bootconfig or kernel command-line to convey the
> map although I think devicetree is the right spot for this mapping.
> 
> - Other vendor-specific bits for PSCI are described in the devicetree.
>    One example is the suspend param (e.g. the StateID) for cpu idle
>    states.
> - Describing firmware bits in the DT isn't unprecedented, and putting
>    this information outside the DT means that other OSes (besides Linux)
>    need their own way to convey this information.
> - PSCI would be the odd one out that reboot mode map is not described in
>    DT. Other reboot-mode drivers specify the mapping in the DT. Userspace
>    that runs with firmware that support vendor reset2 need to make sure
>    they can configure the mapping early enough.

FWIW, I read Sudeep's response as being specifically inquiring about the 
'cookie' parameter, do you see a need for that to be in described in the 
DT or could that just be an user-space parameter that is conveyed 
through the reboot system call?
Elliot Berman April 18, 2024, 5:52 p.m. UTC | #10
On Wed, Apr 17, 2024 at 03:01:00PM -0700, Florian Fainelli wrote:
> On 4/17/24 14:54, Elliot Berman wrote:
> > On Tue, Apr 16, 2024 at 10:35:22AM +0100, Sudeep Holla wrote:
> > > On Sun, Apr 14, 2024 at 12:30:23PM -0700, Elliot Berman wrote:
> > > > The PSCI SYSTEM_RESET2 call allows vendor firmware to define additional
> > > > reset types which could be mapped to the reboot argument.
> > > > 
> > > > Setting up reboot on Qualcomm devices can be inconsistent from chipset
> > > > to chipset.
> > > 
> > > That doesn't sound good. Do you mean PSCI SYSTEM_RESET doesn't work as
> > > expected ? Does it mean it is not conformant to the specification ?
> > > 
> > 
> > I was motivating the reason for using SYSTEM_RESET2. How to set the PMIC
> > register and IMEM cookie can change between chipsets. Using
> > SYSTEM_RESET2 alows us to abstract how to perform the reset.
> > 
> > > > Generally, there is a PMIC register that gets written to
> > > > decide the reboot type. There is also sometimes a cookie that can be
> > > > written to indicate that the bootloader should behave differently than a
> > > > regular boot. These knobs evolve over product generations and require
> > > > more drivers. Qualcomm firmwares are beginning to expose vendor
> > > > SYSTEM_RESET2 types to simplify driver requirements from Linux.
> > > > 
> > > 
> > > Why can't this be fully userspace driven ? What is the need to keep the
> > > cookie in the DT ?
> > 
> > As Dmitry pointed out, this information isn't discoverable. I suppose
> > we could technically use bootconfig or kernel command-line to convey the
> > map although I think devicetree is the right spot for this mapping.
> > 
> > - Other vendor-specific bits for PSCI are described in the devicetree.
> >    One example is the suspend param (e.g. the StateID) for cpu idle
> >    states.
> > - Describing firmware bits in the DT isn't unprecedented, and putting
> >    this information outside the DT means that other OSes (besides Linux)
> >    need their own way to convey this information.
> > - PSCI would be the odd one out that reboot mode map is not described in
> >    DT. Other reboot-mode drivers specify the mapping in the DT. Userspace
> >    that runs with firmware that support vendor reset2 need to make sure
> >    they can configure the mapping early enough.
> 
> FWIW, I read Sudeep's response as being specifically inquiring about the
> 'cookie' parameter, do you see a need for that to be in described in the DT
> or could that just be an user-space parameter that is conveyed through the
> reboot system call?

Ah, I had thought the ask was for the reboot type as well as the cookie.
We don't do this for hardware-based reboot mode cookies and I didn't see
why we should ask userspace to do something different for PSCI.
It seems to me that SYSTEM_RESET2 fits nicely with the existing design
for reboot-mode bindings.
Sudeep Holla April 19, 2024, 8:53 a.m. UTC | #11
On Wed, Apr 17, 2024 at 02:54:41PM -0700, Elliot Berman wrote:
> On Tue, Apr 16, 2024 at 10:35:22AM +0100, Sudeep Holla wrote:
> > On Sun, Apr 14, 2024 at 12:30:23PM -0700, Elliot Berman wrote:
> > > The PSCI SYSTEM_RESET2 call allows vendor firmware to define additional
> > > reset types which could be mapped to the reboot argument.
> > >
> > > Setting up reboot on Qualcomm devices can be inconsistent from chipset
> > > to chipset.
> >
> > That doesn't sound good. Do you mean PSCI SYSTEM_RESET doesn't work as
> > expected ? Does it mean it is not conformant to the specification ?
> >
>
> I was motivating the reason for using SYSTEM_RESET2. How to set the PMIC
> register and IMEM cookie can change between chipsets. Using
> SYSTEM_RESET2 alows us to abstract how to perform the reset.

Fair enough. But I assume you are not providing the details of PMIC register
or IMEM cookie via DT.

Anyways you did confirm if PSCI SYSTEM_RESET works as expected or not. That
is default and must work.

> > > Generally, there is a PMIC register that gets written to
> > > decide the reboot type. There is also sometimes a cookie that can be
> > > written to indicate that the bootloader should behave differently than a
> > > regular boot. These knobs evolve over product generations and require
> > > more drivers. Qualcomm firmwares are beginning to expose vendor
> > > SYSTEM_RESET2 types to simplify driver requirements from Linux.
> > >
> >
> > Why can't this be fully userspace driven ? What is the need to keep the
> > cookie in the DT ?
>
> As Dmitry pointed out, this information isn't discoverable. I suppose
> we could technically use bootconfig or kernel command-line to convey the
> map although I think devicetree is the right spot for this mapping.
>

Yes and as usual DT has become dumping ground for firmware that don't
make things discoverable. Make crap that Qcom puts in the DT are firmware
related and can be make discoverable. Anyways it is sad that no efforts
to make it so are done as DT is always there to provide shortcuts.

> - Other vendor-specific bits for PSCI are described in the devicetree.
>   One example is the suspend param (e.g. the StateID) for cpu idle
>   states.

You are right, but that is the only example I can see and it was done
in very early days of PSCI. It shouldn't be example if there are better
ways.

> - Describing firmware bits in the DT isn't unprecedented, and putting
>   this information outside the DT means that other OSes (besides Linux)
>   need their own way to convey this information.

Correct but it can be Qcom specific firmware interface. There are so many
already. This splitting information between firmware and DT works well
for vertically integrated things which probably is the case with most of
Qcom SoCs but it is prone to issues if DT and firmware mismatch. Firmware
discovery eliminates such issues.

> - PSCI would be the odd one out that reboot mode map is not described in
>   DT. Other reboot-mode drivers specify the mapping in the DT. Userspace
>   that runs with firmware that support vendor reset2 need to make sure
>   they can configure the mapping early enough.
>

Well I am not saying not to this yet, just exploring and getting more info
so that whatever is done here can be reused on all PSCI based systems.

--
Regards,
Sudeep
Sudeep Holla April 19, 2024, 12:38 p.m. UTC | #12
On Wed, Apr 17, 2024 at 10:50:07AM -0700, Florian Fainelli wrote:
> On 4/16/24 02:35, Sudeep Holla wrote:
> > On Sun, Apr 14, 2024 at 12:30:23PM -0700, Elliot Berman wrote:
> > > The PSCI SYSTEM_RESET2 call allows vendor firmware to define additional
> > > reset types which could be mapped to the reboot argument.
> > >
> > > Setting up reboot on Qualcomm devices can be inconsistent from chipset
> > > to chipset.
> >
> > That doesn't sound good. Do you mean PSCI SYSTEM_RESET doesn't work as
> > expected ? Does it mean it is not conformant to the specification ?
> >
> > > Generally, there is a PMIC register that gets written to
> > > decide the reboot type. There is also sometimes a cookie that can be
> > > written to indicate that the bootloader should behave differently than a
> > > regular boot. These knobs evolve over product generations and require
> > > more drivers. Qualcomm firmwares are beginning to expose vendor
> > > SYSTEM_RESET2 types to simplify driver requirements from Linux.
> > >
> >
> > Why can't this be fully userspace driven ? What is the need to keep the
> > cookie in the DT ?
> >
> >
>
> Using the second example in the Device Tree:
>
> mode-bootloader = <1 2>;
>
> are you suggesting that within psci_vendor_sys_reset2() we would look at the
> data argument and assume that we have something like this in memory:
>
> const char *cmd = data;
>
> cmd[] = "bootloader 2"
>
> where "bootloader" is the reboot command, and "2" is the cookie? From an
> util-linux, busybox, toybox, etc. we would have to concatenate those
> arguments with a space, but I suppose that would be doable.
>

Yes that was my thought when I wrote the email. But since I have looked at
existing bindings and support in the kernel in little more detail I would say.
So I am not sure what would be the better choice for PSCI SYSTEM_RESET2
especially when there is some ground support to build.

So I am open for alternatives including this approach.

--
Regards,
Sudeep
Elliot Berman April 19, 2024, 11:31 p.m. UTC | #13
On Fri, Apr 19, 2024 at 09:53:45AM +0100, Sudeep Holla wrote:
> On Wed, Apr 17, 2024 at 02:54:41PM -0700, Elliot Berman wrote:
> > On Tue, Apr 16, 2024 at 10:35:22AM +0100, Sudeep Holla wrote:
> > > On Sun, Apr 14, 2024 at 12:30:23PM -0700, Elliot Berman wrote:
> > > > The PSCI SYSTEM_RESET2 call allows vendor firmware to define additional
> > > > reset types which could be mapped to the reboot argument.
> > > >
> > > > Setting up reboot on Qualcomm devices can be inconsistent from chipset
> > > > to chipset.
> > >
> > > That doesn't sound good. Do you mean PSCI SYSTEM_RESET doesn't work as
> > > expected ? Does it mean it is not conformant to the specification ?
> > >
> >
> > I was motivating the reason for using SYSTEM_RESET2. How to set the PMIC
> > register and IMEM cookie can change between chipsets. Using
> > SYSTEM_RESET2 alows us to abstract how to perform the reset.
> 
> Fair enough. But I assume you are not providing the details of PMIC register
> or IMEM cookie via DT.

Kernel doesn't need this info.

> 
> Anyways you did confirm if PSCI SYSTEM_RESET works as expected or not. That
> is default and must work.
> 

Yes, SYSTEM_RESET works on Quacomm firmware. The bindings disallow
trying to override the default reboot. (reboot command = NULL or "") The
PSCI parsing of the DT also doesn't have any of the special handling to
deal with "mode-normal".

> > > > Generally, there is a PMIC register that gets written to
> > > > decide the reboot type. There is also sometimes a cookie that can be
> > > > written to indicate that the bootloader should behave differently than a
> > > > regular boot. These knobs evolve over product generations and require
> > > > more drivers. Qualcomm firmwares are beginning to expose vendor
> > > > SYSTEM_RESET2 types to simplify driver requirements from Linux.
> > > >
> > >
> > > Why can't this be fully userspace driven ? What is the need to keep the
> > > cookie in the DT ?
> >
> > As Dmitry pointed out, this information isn't discoverable. I suppose
> > we could technically use bootconfig or kernel command-line to convey the
> > map although I think devicetree is the right spot for this mapping.
> >
> 
> Yes and as usual DT has become dumping ground for firmware that don't
> make things discoverable. Make crap that Qcom puts in the DT are firmware
> related and can be make discoverable. Anyways it is sad that no efforts
> to make it so are done as DT is always there to provide shortcuts.
> 
> > - Other vendor-specific bits for PSCI are described in the devicetree.
> >   One example is the suspend param (e.g. the StateID) for cpu idle
> >   states.
> 
> You are right, but that is the only example I can see and it was done
> in very early days of PSCI. It shouldn't be example if there are better
> ways.
> 
> > - Describing firmware bits in the DT isn't unprecedented, and putting
> >   this information outside the DT means that other OSes (besides Linux)
> >   need their own way to convey this information.
> 
> Correct but it can be Qcom specific firmware interface. There are so many
> already. This splitting information between firmware and DT works well
> for vertically integrated things which probably is the case with most of
> Qcom SoCs but it is prone to issues if DT and firmware mismatch. Firmware
> discovery eliminates such issues.
> 

I worry about designing interfaces both in Qualcomm firmware and in
the PSCI driver which doesn't really suit handling the discovery. We can
implement the dynamic discovery mechanims once there is a board which
needs it.

Thanks,
Elliot
Elliot Berman May 2, 2024, 2:21 a.m. UTC | #14
On Fri, Apr 19, 2024 at 01:38:47PM +0100, Sudeep Holla wrote:
> On Wed, Apr 17, 2024 at 10:50:07AM -0700, Florian Fainelli wrote:
> > On 4/16/24 02:35, Sudeep Holla wrote:
> > > On Sun, Apr 14, 2024 at 12:30:23PM -0700, Elliot Berman wrote:
> > > > The PSCI SYSTEM_RESET2 call allows vendor firmware to define additional
> > > > reset types which could be mapped to the reboot argument.
> > > >
> > > > Setting up reboot on Qualcomm devices can be inconsistent from chipset
> > > > to chipset.
> > >
> > > That doesn't sound good. Do you mean PSCI SYSTEM_RESET doesn't work as
> > > expected ? Does it mean it is not conformant to the specification ?
> > >
> > > > Generally, there is a PMIC register that gets written to
> > > > decide the reboot type. There is also sometimes a cookie that can be
> > > > written to indicate that the bootloader should behave differently than a
> > > > regular boot. These knobs evolve over product generations and require
> > > > more drivers. Qualcomm firmwares are beginning to expose vendor
> > > > SYSTEM_RESET2 types to simplify driver requirements from Linux.
> > > >
> > >
> > > Why can't this be fully userspace driven ? What is the need to keep the
> > > cookie in the DT ?
> > >
> > >
> >
> > Using the second example in the Device Tree:
> >
> > mode-bootloader = <1 2>;
> >
> > are you suggesting that within psci_vendor_sys_reset2() we would look at the
> > data argument and assume that we have something like this in memory:
> >
> > const char *cmd = data;
> >
> > cmd[] = "bootloader 2"
> >
> > where "bootloader" is the reboot command, and "2" is the cookie? From an
> > util-linux, busybox, toybox, etc. we would have to concatenate those
> > arguments with a space, but I suppose that would be doable.
> >
> 
> Yes that was my thought when I wrote the email. But since I have looked at
> existing bindings and support in the kernel in little more detail I would say.
> So I am not sure what would be the better choice for PSCI SYSTEM_RESET2
> especially when there is some ground support to build.
> 
> So I am open for alternatives including this approach.

If we can't go with the DT approach, my preference would be to go with a
bootconfig and sysfs for controlling the mappings, although I don't
think userspace need/should control the mappings of cmd -> cookies.

I wanted to check if you are okay with proceeding with the reboot-mode
DT bindings approach unless we have some other better standard? If yes,
do you have any preference based on Konrad's comment [1]? I can send out
v3 with the couple comments from Dmitry and Krzysztof's addressed.

Thanks,
Elliot

[1]: https://lore.kernel.org/all/20240419123847.ica22nft3sejqnm7@bogus/