mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Aurelien Jarno <aurelien@aurel32.net>
To: Anand Moon <linux.amoon@gmail.com>
Cc: "Paul Walmsley" <pjw@kernel.org>,
	"Palmer Dabbelt" <palmer@dabbelt.com>,
	"Albert Ou" <aou@eecs.berkeley.edu>,
	"Alexandre Ghiti" <alex@ghiti.fr>,
	"Troy Mitchell" <troy.mitchell@linux.spacemit.com>,
	"Andi Shyti" <andi.shyti@kernel.org>,
	"Sebastian Reichel" <sre@kernel.org>,
	"Yixun Lan" <dlan@kernel.org>,
	"Radim Krčmář" <rkrcmar@ventanamicro.com>,
	"open list:RISC-V ARCHITECTURE" <linux-riscv@lists.infradead.org>,
	"open list" <linux-kernel@vger.kernel.org>,
	"open list:I2C SUBSYSTEM HOST DRIVERS"
	<linux-i2c@vger.kernel.org>,
	"open list:SYSTEM RESET/SHUTDOWN DRIVERS"
	<linux-pm@vger.kernel.org>,
	"open list:RISC-V SPACEMIT SoC Support"
	<spacemit@lists.linux.dev>
Subject: Re: [PATCH v2 2/3] riscv: sbi: Register SRST handlers with firmware priority
Date: Mon, 23 Nov 2026 23:21:39 +0100	[thread overview]
Message-ID: <awS8c3RFkv1D07dc@aurel32.net> (raw)
In-Reply-To: <20261118104935.1716-2-linux.amoon@gmail.com>

On 2026-11-18 16:19, Anand Moon wrote:
> The SBI System Reset (SRST) extension currently registers its poweroff
> handler using register_platform_power_off(), which assigns it a lower
> priority than the default PMIC poweroff handlers.
> 
> On platforms where OpenSBI handles system poweroff, a PMIC handler may
> run first and perform I2C-backed regmap operations in atomic context,
> triggering invalid wait context and scheduling-while-atomic warnings.
> 
> Register both SBI SRST restart and poweroff handlers using
> register_sys_off_handler() with SYS_OFF_PRIO_FIRMWARE. This gives firmware
> handlers precedence over default-priority PMIC handlers and avoids
> board-specific workarounds in individual PMIC drivers.
> 
> Defer handler registration to a device initcall because sbi_init() runs
> during early architecture initialization, before dynamic memory
> allocation required by register_sys_off_handler() is available.
> 
> Preserve warm and cold reboot selection, retain the existing legacy
> poweroff fallback, and report handler registration failures.
> 
> Cc: Troy Mitchell <troy.mitchell@linux.spacemit.com>
> Cc: Aurelien Jarno <aurelien@aurel32.net>
> Suggested-by: Aurelien Jarno <aurelien@aurel32.net>
> Signed-off-by: Anand Moon <linux.amoon@gmail.com>
> ---
> New patch:
>    Link: https://lore.kernel.org/all/20261110061429.2036-2-linux.amoon@gmail.com/
> ---
>  arch/riscv/kernel/sbi.c | 43 +++++++++++++++++++++++++++++++----------
>  1 file changed, 33 insertions(+), 10 deletions(-)
> 
> diff --git a/arch/riscv/kernel/sbi.c b/arch/riscv/kernel/sbi.c
> index af1ccea222f1..ab6e5bf25411 100644
> --- a/arch/riscv/kernel/sbi.c
> +++ b/arch/riscv/kernel/sbi.c
> @@ -512,23 +512,50 @@ static void sbi_srst_reset(unsigned long type, unsigned long reason)
>  		__func__, type, reason);
>  }
>  
> -static int sbi_srst_reboot(struct notifier_block *this,
> -			   unsigned long mode, void *cmd)
> +static int sbi_srst_reboot(struct sys_off_data *data)
>  {
> -	sbi_srst_reset((mode == REBOOT_WARM || mode == REBOOT_SOFT) ?
> +	sbi_srst_reset((reboot_mode == REBOOT_WARM ||
> +			reboot_mode == REBOOT_SOFT) ?
>  		       SBI_SRST_RESET_TYPE_WARM_REBOOT :
>  		       SBI_SRST_RESET_TYPE_COLD_REBOOT,
>  		       SBI_SRST_RESET_REASON_NONE);
> +
>  	return NOTIFY_DONE;
>  }
>  
> -static struct notifier_block sbi_srst_reboot_nb;
> -
> -static void sbi_srst_power_off(void)
> +static int sbi_srst_power_off(struct sys_off_data *data)
>  {
>  	sbi_srst_reset(SBI_SRST_RESET_TYPE_SHUTDOWN,
>  		       SBI_SRST_RESET_REASON_NONE);
> +
> +	return NOTIFY_DONE;
> +}
> +
> +static int __init sbi_srst_sys_off_init(void)
> +{
> +	struct sys_off_handler *handler;
> +
> +	if (sbi_spec_version < sbi_mk_version(0, 3) ||
> +	    !sbi_probe_extension(SBI_EXT_SRST))
> +		return 0;
> +
> +	handler = register_sys_off_handler(SYS_OFF_MODE_RESTART,
> +					   SYS_OFF_PRIO_FIRMWARE,
> +					   sbi_srst_reboot, NULL);
> +	if (IS_ERR(handler))
> +		pr_warn("Failed to register SBI SRST restart handler: %ld\n",
> +			PTR_ERR(handler));
> +
> +	handler = register_sys_off_handler(SYS_OFF_MODE_POWER_OFF,
> +					   SYS_OFF_PRIO_FIRMWARE,
> +					   sbi_srst_power_off, NULL);
> +	if (IS_ERR(handler))
> +		pr_warn("Failed to register SBI SRST poweroff handler: %ld\n",
> +			PTR_ERR(handler));
> +
> +	return 0;
>  }
> +device_initcall(sbi_srst_sys_off_init);
>  
>  /**
>   * sbi_probe_extension() - Check if an SBI extension ID is supported or not.
> @@ -677,11 +704,7 @@ void __init sbi_init(void)
>  		if (sbi_spec_version >= sbi_mk_version(0, 3) &&
>  		    sbi_probe_extension(SBI_EXT_SRST)) {
>  			pr_info("SBI SRST extension detected\n");
> -			register_platform_power_off(sbi_srst_power_off);
>  			srst_power_off = true;
> -			sbi_srst_reboot_nb.notifier_call = sbi_srst_reboot;
> -			sbi_srst_reboot_nb.priority = 192;
> -			register_restart_handler(&sbi_srst_reboot_nb);
>  		}
>  		if (sbi_spec_version >= sbi_mk_version(2, 0) &&
>  		    sbi_probe_extension(SBI_EXT_DBCN) > 0) {

Reviewed-by: Aurelien Jarno <aurelien@aurel32.net>
Tested-by: Aurelien Jarno <aurelien@aurel32.net>

-- 
Aurelien Jarno                          GPG: 4096R/1DDD8C9B
aurelien@aurel32.net                     http://aurel32.net

  reply	other threads:[~2026-11-23 22:21 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 10:49 [PATCH v2 1/3] i2c: spacemit: Avoid sleeping during bus reset in atomic context Anand Moon
2026-11-18 10:49 ` [PATCH v2 2/3] riscv: sbi: Register SRST handlers with firmware priority Anand Moon
2026-11-23 22:21   ` Aurelien Jarno [this message]
2026-11-18 10:49 ` [PATCH v2 3/3] power: reset: Remove SpacemiT P1 reboot driver Anand Moon
2026-11-23 22:23   ` Aurelien Jarno

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=awS8c3RFkv1D07dc@aurel32.net \
    --to=aurelien@aurel32.net \
    --cc=alex@ghiti.fr \
    --cc=andi.shyti@kernel.org \
    --cc=aou@eecs.berkeley.edu \
    --cc=dlan@kernel.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=linux.amoon@gmail.com \
    --cc=palmer@dabbelt.com \
    --cc=pjw@kernel.org \
    --cc=rkrcmar@ventanamicro.com \
    --cc=spacemit@lists.linux.dev \
    --cc=sre@kernel.org \
    --cc=troy.mitchell@linux.spacemit.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®