From: Lorenzo Pieralisi <lpieralisi@kernel.org>
To: Shivendra Pratap <shivendra.pratap@oss.qualcomm.com>
Cc: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>,
Bjorn Andersson <andersson@kernel.org>,
Sebastian Reichel <sre@kernel.org>, Rob Herring <robh@kernel.org>,
Sudeep Holla <sudeep.holla@arm.com>,
Souvik Chakravarty <Souvik.Chakravarty@arm.com>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Andy Yan <andy.yan@rock-chips.com>,
Mark Rutland <mark.rutland@arm.com>,
Arnd Bergmann <arnd@arndb.de>,
Konrad Dybcio <konradybcio@kernel.org>,
cros-qcom-dts-watchers@chromium.org,
Vinod Koul <vkoul@kernel.org>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>,
Florian Fainelli <florian.fainelli@broadcom.com>,
Moritz Fischer <moritz.fischer@ettus.com>,
John Stultz <john.stultz@linaro.org>,
Matthias Brugger <matthias.bgg@gmail.com>,
Krzysztof Kozlowski <krzk@kernel.org>,
Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>,
Mukesh Ojha <mukesh.ojha@oss.qualcomm.com>,
Stephen Boyd <swboyd@chromium.org>,
Andre Draszik <andre.draszik@linaro.org>,
Kathiravan Thirumoorthy
<kathiravan.thirumoorthy@oss.qualcomm.com>,
linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-arm-msm@vger.kernel.org,
Elliot Berman <quic_eberman@quicinc.com>,
Xin Liu <xin.liu@oss.qualcomm.com>,
Srinivas Kandagatla <srini@kernel.org>,
Umang Chheda <umang.chheda@oss.qualcomm.com>,
Nirmesh Kumar Singh <nirmesh.singh@oss.qualcomm.com>
Subject: Re: [PATCH v17 07/12] firmware: psci: Implement vendor-specific resets as reboot-mode
Date: Mon, 10 Nov 2025 18:22:59 +0100 [thread overview]
Message-ID: <aRIfc9iuC2b9DqI+@lpieralisi> (raw)
In-Reply-To: <20251109-arm-psci-system_reset2-vendor-reboots-v17-7-46e085bca4cc@oss.qualcomm.com>
On Sun, Nov 09, 2025 at 08:07:20PM +0530, Shivendra Pratap wrote:
> SoC vendors have different types of resets which are controlled
> through various hardware registers. For instance, Qualcomm SoC
> may have a requirement that reboot with “bootloader” command
> should reboot the device to bootloader flashing mode and reboot
> with “edl” should reboot the device into Emergency flashing mode.
> Setting up such reboots on Qualcomm devices can be inconsistent
> across SoC platforms and may require setting different HW
> registers, where some of these registers may not be accessible to
> HLOS. These knobs evolve over product generations and require
> more drivers. PSCI spec defines, SYSTEM_RESET2, vendor-specific
> reset which can help align this requirement. Add support for PSCI
> SYSTEM_RESET2, vendor-specific resets and align the implementation
> to allow user-space initiated reboots to trigger these resets.
>
> Implement the PSCI vendor-specific resets by registering to the
> reboot-mode framework.
I think that we should expose to user space _all_ PSCI reset types,
cold, warm + vendor specific - as a departure from using the reboot_mode
variable (and possibly deprecate it - or at least stop using it).
> As psci init is done at early kernel init, reboot-mode registration cannot
> be done at the time of psci init. This is because reboot-mode creates a
> “reboot-mode” class for exposing sysfs, which can fail at early kernel init.
> To overcome this, introduce a late_initcall to register PSCI vendor-specific
> resets as reboot modes. Implement a reboot-mode write function that sets
> reset_type and cookie values during the reboot notifier callback. Introduce
> a firmware-based call for SYSTEM_RESET2 vendor-specific reset in the
> psci_sys_reset path, using reset_type and cookie if supported by secure
> firmware. Register a panic notifier and clear vendor_reset valid status
> during panic. This is needed for any kernel panic that occurs post
> reboot_notifiers.
Is it because panic uses reboot_mode to determine the reset to issue ?
> By using the above implementation, userspace will be able to issue
> such resets using the reboot() system call with the "*arg"
> parameter as a string based command. The commands can be defined
> in PSCI device tree node under “reboot-mode” and are based on the
> reboot-mode based commands.
IMHO - it would be nice if could add mode-cold (or mode-normal in reboot mode
speak) and mode-warm by default (if PSCI supports them) so that userspace
could issue those resets too without having to set the reboot_mode variable.
Reason is, since we are doing this it is worth going the whole nine
yards and try to decouple the reboot_mode variable from the RESTART2
syscall argument.
Reworded: just use the new userspace interface you are adding for
all PSCI reset types.
Thoughts very much welcome - I understand this is controversial.
> Reviewed-by: Umang Chheda <umang.chheda@oss.qualcomm.com>
> Reviewed-by: Kathiravan Thirumoorthy <kathiravan.thirumoorthy@oss.qualcomm.com>
> Reviewed-by: Nirmesh Kumar Singh <nirmesh.singh@oss.qualcomm.com>
> Signed-off-by: Shivendra Pratap <shivendra.pratap@oss.qualcomm.com>
> ---
> drivers/firmware/psci/Kconfig | 2 +
> drivers/firmware/psci/psci.c | 92 ++++++++++++++++++++++++++++++++++++++++++-
> 2 files changed, 93 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/firmware/psci/Kconfig b/drivers/firmware/psci/Kconfig
> index 97944168b5e66aea1e38a7eb2d4ced8348fce64b..93ff7b071a0c364a376699733e6bc5654d56a17f 100644
> --- a/drivers/firmware/psci/Kconfig
> +++ b/drivers/firmware/psci/Kconfig
> @@ -1,6 +1,8 @@
> # SPDX-License-Identifier: GPL-2.0-only
> config ARM_PSCI_FW
> bool
> + select POWER_RESET
> + select REBOOT_MODE
>
> config ARM_PSCI_CHECKER
> bool "ARM PSCI checker"
> diff --git a/drivers/firmware/psci/psci.c b/drivers/firmware/psci/psci.c
> index 38ca190d4a22d6e7e0f06420e8478a2b0ec2fe6f..ff82e7f4c27d1609a75cedc3a9790affaf839801 100644
> --- a/drivers/firmware/psci/psci.c
> +++ b/drivers/firmware/psci/psci.c
> @@ -8,15 +8,18 @@
>
> #include <linux/acpi.h>
> #include <linux/arm-smccc.h>
> +#include <linux/bitops.h>
> #include <linux/cpuidle.h>
> #include <linux/debugfs.h>
> #include <linux/errno.h>
> #include <linux/linkage.h>
> #include <linux/of.h>
> +#include <linux/panic_notifier.h>
> #include <linux/pm.h>
> #include <linux/printk.h>
> #include <linux/psci.h>
> #include <linux/reboot.h>
> +#include <linux/reboot-mode.h>
> #include <linux/slab.h>
> #include <linux/suspend.h>
>
> @@ -51,6 +54,24 @@ static int resident_cpu = -1;
> struct psci_operations psci_ops;
> static enum arm_smccc_conduit psci_conduit = SMCCC_CONDUIT_NONE;
>
> +struct psci_vendor_sysreset2 {
> + u32 reset_type;
> + u32 cookie;
> + bool valid;
> +};
> +
> +static struct psci_vendor_sysreset2 vendor_reset;
I think this should represent all possible PSCI reset types, not vendor only
and its value is set by the reboot mode framework.
> +
> +static int psci_panic_event(struct notifier_block *nb, unsigned long v, void *p)
> +{
> + vendor_reset.valid = false;
I don't like this. Basically all you want this for is to make sure that
we don't override the reboot_mode variable.
One (hack) would consist in checking the reboot_mode variable here and
set the struct I mentioned above to the value represented in reboot_mode.
Good luck if reboot_mode == REBOOT_GPIO :-)
> + return NOTIFY_DONE;
> +}
> +
> +static struct notifier_block psci_panic_block = {
> + .notifier_call = psci_panic_event
> +};
> +
> bool psci_tos_resident_on(int cpu)
> {
> return cpu == resident_cpu;
> @@ -309,7 +330,10 @@ static int get_set_conduit_method(const struct device_node *np)
> static int psci_sys_reset(struct notifier_block *nb, unsigned long action,
> void *data)
> {
> - if ((reboot_mode == REBOOT_WARM || reboot_mode == REBOOT_SOFT) &&
> + if (vendor_reset.valid && psci_system_reset2_supported) {
> + invoke_psci_fn(PSCI_FN_NATIVE(1_1, SYSTEM_RESET2), vendor_reset.reset_type,
> + vendor_reset.cookie, 0);
See above. Two calls here: one for resets issued using the new userspace
interface you are adding and legacy below - no vendor vs reboot_mode, this
is a mess.
> + } else if ((reboot_mode == REBOOT_WARM || reboot_mode == REBOOT_SOFT) &&
> psci_system_reset2_supported) {
> /*
> * reset_type[31] = 0 (architectural)
> @@ -547,6 +571,72 @@ static const struct platform_suspend_ops psci_suspend_ops = {
> .enter = psci_system_suspend_enter,
> };
>
> +static int psci_set_vendor_sys_reset2(struct reboot_mode_driver *reboot, u64 magic)
> +{
> + u32 magic_32;
> +
> + if (psci_system_reset2_supported) {
> + magic_32 = magic & GENMASK(31, 0);
> + vendor_reset.reset_type = PSCI_1_1_RESET_TYPE_VENDOR_START | magic_32;
> + vendor_reset.cookie = (magic >> 32) & GENMASK(31, 0);
Use FIELD_PREP/GET() please (but as mentioned above the vendor reset type
bit[31] should be part of the reboot mode magic value, see above).
> + vendor_reset.valid = true;
> + }
> +
> + return NOTIFY_DONE;
> +}
> +
> +static int __init psci_init_vendor_reset(void)
> +{
> + struct reboot_mode_driver *reboot;
> + struct device_node *psci_np;
> + struct device_node *np;
> + int ret;
> +
> + if (!psci_system_reset2_supported)
> + return -EINVAL;
> +
> + psci_np = of_find_compatible_node(NULL, NULL, "arm,psci-1.0");
> + if (!psci_np)
> + return -ENODEV;
> +
> + np = of_find_node_by_name(psci_np, "reboot-mode");
> + if (!np) {
> + of_node_put(psci_np);
> + return -ENODEV;
> + }
> +
> + ret = atomic_notifier_chain_register(&panic_notifier_list, &psci_panic_block);
> + if (ret)
> + goto err_notifier;
> +
> + reboot = kzalloc(sizeof(*reboot), GFP_KERNEL);
> + if (!reboot) {
> + ret = -ENOMEM;
> + goto err_kzalloc;
> + }
> +
> + reboot->write = psci_set_vendor_sys_reset2;
> + reboot->driver_name = "psci";
> +
> + ret = reboot_mode_register(reboot, of_fwnode_handle(np));
> + if (ret)
> + goto err_register;
> +
> + of_node_put(psci_np);
> + of_node_put(np);
> + return 0;
> +
> +err_register:
> + kfree(reboot);
> +err_kzalloc:
> + atomic_notifier_chain_unregister(&panic_notifier_list, &psci_panic_block);
> +err_notifier:
> + of_node_put(psci_np);
> + of_node_put(np);
> + return ret;
> +}
> +late_initcall(psci_init_vendor_reset)
I don't like adding another initcall here.
I wonder whether this code belongs in a PSCI reboot mode driver, possibly a
faux device in a way similar to what we did for cpuidle-psci (that after all
is a consumer of PSCI_CPU_SUSPEND in a similar way as this code is a
PSCI_SYSTEM_RESET{2} consumer), that communicates with
drivers/firmware/psci/psci.c with the struct mentioned above.
Thanks,
Lorenzo
> +
> static void __init psci_init_system_reset2(void)
> {
> int ret;
>
> --
> 2.34.1
>
next prev parent reply other threads:[~2025-11-10 17:23 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-09 14:37 [PATCH v17 00/12] Implement vendor resets for PSCI SYSTEM_RESET2 Shivendra Pratap
2025-11-09 14:37 ` [PATCH v17 01/12] power: reset: reboot-mode: Remove devres based allocations Shivendra Pratap
2025-11-10 13:01 ` Mukesh Ojha
2025-11-10 13:20 ` Shivendra Pratap
2025-11-10 13:10 ` Bartosz Golaszewski
2025-11-10 13:17 ` Shivendra Pratap
2025-11-09 14:37 ` [PATCH v17 02/12] power: reset: reboot-mode: Add firmware node based registration Shivendra Pratap
2025-11-10 13:13 ` Mukesh Ojha
2025-11-10 13:21 ` Shivendra Pratap
2025-11-09 14:37 ` [PATCH v17 03/12] power: reset: reboot-mode: Add support for 64 bit magic Shivendra Pratap
2025-11-10 13:45 ` Mukesh Ojha
2025-11-10 14:38 ` Shivendra Pratap
2025-11-10 16:30 ` Bjorn Andersson
2025-11-10 17:52 ` Shivendra Pratap
2025-11-10 18:33 ` Bjorn Andersson
2025-11-11 14:50 ` Shivendra Pratap
2025-11-11 16:25 ` Bjorn Andersson
2025-11-11 16:30 ` Shivendra Pratap
2025-11-09 14:37 ` [PATCH v17 04/12] Documentation: ABI: Add sysfs-class-reboot-mode-reboot_modes Shivendra Pratap
2025-11-09 14:37 ` [PATCH v17 05/12] power: reset: reboot-mode: Expose sysfs for registered reboot_modes Shivendra Pratap
2025-11-10 15:14 ` Bartosz Golaszewski
2025-11-12 16:57 ` Shivendra Pratap
2025-11-10 16:15 ` Bjorn Andersson
2025-11-12 17:24 ` Shivendra Pratap
2025-11-09 14:37 ` [PATCH v17 06/12] dt-bindings: arm: Document reboot mode magic Shivendra Pratap
2025-11-09 14:37 ` [PATCH v17 07/12] firmware: psci: Implement vendor-specific resets as reboot-mode Shivendra Pratap
2025-11-10 4:40 ` Kathiravan Thirumoorthy
2025-11-10 14:41 ` Shivendra Pratap
2025-11-10 17:22 ` Lorenzo Pieralisi [this message]
2025-11-17 17:44 ` Shivendra Pratap
2025-11-18 12:28 ` Lorenzo Pieralisi
2025-11-18 17:41 ` Shivendra Pratap
2025-11-19 9:37 ` Lorenzo Pieralisi
2025-11-19 12:02 ` Shivendra Pratap
2025-11-26 17:18 ` Lorenzo Pieralisi
2025-11-26 17:43 ` Shivendra Pratap
2025-11-09 14:37 ` [PATCH v17 08/12] arm64: dts: qcom: qcm6490-idp: Add PSCI SYSTEM_RESET2 types Shivendra Pratap
2025-11-09 14:37 ` [PATCH v17 09/12] arm64: dts: qcom: qcs6490-rb3gen2: " Shivendra Pratap
2025-11-10 12:28 ` Mukesh Ojha
2025-11-10 15:30 ` Bjorn Andersson
2025-11-10 16:19 ` Mukesh Ojha
2025-11-11 16:52 ` Bjorn Andersson
2025-11-12 11:15 ` Mukesh Ojha
2025-11-12 17:25 ` Shivendra Pratap
2025-11-11 16:59 ` Bjorn Andersson
2025-11-12 17:29 ` Shivendra Pratap
2025-11-09 14:37 ` [PATCH v17 10/12] arm64: dts: qcom: lemans: " Shivendra Pratap
2025-11-09 14:37 ` [PATCH v17 11/12] arm64: dts: qcom: monaco: " Shivendra Pratap
2025-11-09 14:37 ` [PATCH v17 12/12] arm64: dts: qcom: talos: " Shivendra Pratap
2025-11-10 12:39 ` Mukesh Ojha
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aRIfc9iuC2b9DqI+@lpieralisi \
--to=lpieralisi@kernel.org \
--cc=Souvik.Chakravarty@arm.com \
--cc=andersson@kernel.org \
--cc=andre.draszik@linaro.org \
--cc=andy.yan@rock-chips.com \
--cc=arnd@arndb.de \
--cc=bartosz.golaszewski@linaro.org \
--cc=catalin.marinas@arm.com \
--cc=conor+dt@kernel.org \
--cc=cros-qcom-dts-watchers@chromium.org \
--cc=devicetree@vger.kernel.org \
--cc=dmitry.baryshkov@oss.qualcomm.com \
--cc=florian.fainelli@broadcom.com \
--cc=john.stultz@linaro.org \
--cc=kathiravan.thirumoorthy@oss.qualcomm.com \
--cc=konradybcio@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=krzk@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=matthias.bgg@gmail.com \
--cc=moritz.fischer@ettus.com \
--cc=mukesh.ojha@oss.qualcomm.com \
--cc=nirmesh.singh@oss.qualcomm.com \
--cc=quic_eberman@quicinc.com \
--cc=robh@kernel.org \
--cc=shivendra.pratap@oss.qualcomm.com \
--cc=sre@kernel.org \
--cc=srini@kernel.org \
--cc=sudeep.holla@arm.com \
--cc=swboyd@chromium.org \
--cc=umang.chheda@oss.qualcomm.com \
--cc=vkoul@kernel.org \
--cc=will@kernel.org \
--cc=xin.liu@oss.qualcomm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.