* [RFC PATCH] RISC-V: Use SBI SRST extension when available
@ 2020-09-25 11:30 Anup Patel
2020-09-26 4:35 ` Anup Patel
0 siblings, 1 reply; 2+ messages in thread
From: Anup Patel @ 2020-09-25 11:30 UTC (permalink / raw)
To: Palmer Dabbelt, Palmer Dabbelt, Paul Walmsley, Albert Ou
Cc: Anup Patel, Anup Patel, linux-kernel, Atish Patra,
Alistair Francis, linux-riscv
The SBI SRST extension provides a standard way to poweroff and
reboot the system irrespective to whether Linux RISC-V S-mode
is running natively (HS-mode) or inside Guest/VM (VS-mode).
The draft specification of SBI SRST extension is available in
srbt_v1 branch of: https://github.com/avpatel/riscv-sbi-doc.
This patch extends Linux RISC-V SBI implementation to detect
and use SBI SRST extension.
Signed-off-by: Anup Patel <anup.patel@wdc.com>
---
arch/riscv/include/asm/sbi.h | 7 +++++++
arch/riscv/kernel/sbi.c | 25 +++++++++++++++++++++++++
2 files changed, 32 insertions(+)
diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h
index 653edb25d495..2fcecec7dd0c 100644
--- a/arch/riscv/include/asm/sbi.h
+++ b/arch/riscv/include/asm/sbi.h
@@ -27,6 +27,7 @@ enum sbi_ext_id {
SBI_EXT_IPI = 0x735049,
SBI_EXT_RFENCE = 0x52464E43,
SBI_EXT_HSM = 0x48534D,
+ SBI_EXT_SRST = 0x53525354,
};
enum sbi_ext_base_fid {
@@ -70,6 +71,12 @@ enum sbi_hsm_hart_status {
SBI_HSM_HART_STATUS_STOP_PENDING,
};
+enum sbi_ext_srst_fid {
+ SBI_EXT_SRST_SHUTDOWN = 0,
+ SBI_EXT_SRST_COLD_REBOOT,
+ SBI_EXT_SRST_WARM_REBOOT
+};
+
#define SBI_SPEC_VERSION_DEFAULT 0x1
#define SBI_SPEC_VERSION_MAJOR_SHIFT 24
#define SBI_SPEC_VERSION_MAJOR_MASK 0x7f
diff --git a/arch/riscv/kernel/sbi.c b/arch/riscv/kernel/sbi.c
index 226ccce0f9e0..865e028a9a4b 100644
--- a/arch/riscv/kernel/sbi.c
+++ b/arch/riscv/kernel/sbi.c
@@ -7,6 +7,7 @@
#include <linux/init.h>
#include <linux/pm.h>
+#include <linux/reboot.h>
#include <asm/sbi.h>
#include <asm/smp.h>
@@ -501,6 +502,23 @@ int sbi_remote_hfence_vvma_asid(const unsigned long *hart_mask,
}
EXPORT_SYMBOL(sbi_remote_hfence_vvma_asid);
+static int sbi_srst_reboot(struct notifier_block *this,
+ unsigned long mode, void *cmd)
+{
+ sbi_ecall(SBI_EXT_SRST, (mode == REBOOT_WARM || mode == REBOOT_SOFT) ?
+ SBI_EXT_SRST_WARM_REBOOT : SBI_EXT_SRST_COLD_REBOOT,
+ 0, 0, 0, 0, 0, 0);
+
+ return NOTIFY_DONE;
+}
+
+static struct notifier_block sbi_srst_reboot_nb;
+
+static void sbi_srst_power_off(void)
+{
+ sbi_ecall(SBI_EXT_SRST, SBI_EXT_SRST_SHUTDOWN, 0, 0, 0, 0, 0, 0);
+}
+
/**
* sbi_probe_extension() - Check if an SBI extension ID is supported or not.
* @extid: The extension ID to be probed.
@@ -593,6 +611,13 @@ int __init sbi_init(void)
} else {
__sbi_rfence = __sbi_rfence_v01;
}
+ if (sbi_probe_extension(SBI_EXT_SRST) > 0) {
+ pr_info("SBI v0.2 SRST extension detected\n");
+ pm_power_off = sbi_srst_power_off;
+ sbi_srst_reboot_nb.notifier_call = sbi_srst_reboot;
+ sbi_srst_reboot_nb.priority = 192;
+ register_restart_handler(&sbi_srst_reboot_nb);
+ }
} else {
__sbi_set_timer = __sbi_set_timer_v01;
__sbi_send_ipi = __sbi_send_ipi_v01;
--
2.25.1
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related [flat|nested] 2+ messages in thread
* RE: [RFC PATCH] RISC-V: Use SBI SRST extension when available
2020-09-25 11:30 [RFC PATCH] RISC-V: Use SBI SRST extension when available Anup Patel
@ 2020-09-26 4:35 ` Anup Patel
0 siblings, 0 replies; 2+ messages in thread
From: Anup Patel @ 2020-09-26 4:35 UTC (permalink / raw)
To: Palmer Dabbelt, Palmer Dabbelt, Paul Walmsley, Albert Ou
Cc: Atish Patra, linux-riscv, Alistair Francis, linux-kernel, Anup Patel
> -----Original Message-----
> From: Anup Patel <Anup.Patel@wdc.com>
> Sent: 25 September 2020 17:01
> To: Palmer Dabbelt <palmer@dabbelt.com>; Palmer Dabbelt
> <palmerdabbelt@google.com>; Paul Walmsley <paul.walmsley@sifive.com>;
> Albert Ou <aou@eecs.berkeley.edu>
> Cc: Atish Patra <Atish.Patra@wdc.com>; Alistair Francis
> <Alistair.Francis@wdc.com>; Anup Patel <anup@brainfault.org>; linux-
> riscv@lists.infradead.org; linux-kernel@vger.kernel.org; Anup Patel
> <Anup.Patel@wdc.com>
> Subject: [RFC PATCH] RISC-V: Use SBI SRST extension when available
>
> The SBI SRST extension provides a standard way to poweroff and reboot the
> system irrespective to whether Linux RISC-V S-mode is running natively (HS-
> mode) or inside Guest/VM (VS-mode).
>
> The draft specification of SBI SRST extension is available in
> srbt_v1 branch of: https://github.com/avpatel/riscv-sbi-doc.
>
> This patch extends Linux RISC-V SBI implementation to detect and use SBI
> SRST extension.
>
> Signed-off-by: Anup Patel <anup.patel@wdc.com>
> ---
> arch/riscv/include/asm/sbi.h | 7 +++++++
> arch/riscv/kernel/sbi.c | 25 +++++++++++++++++++++++++
> 2 files changed, 32 insertions(+)
>
> diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h index
> 653edb25d495..2fcecec7dd0c 100644
> --- a/arch/riscv/include/asm/sbi.h
> +++ b/arch/riscv/include/asm/sbi.h
> @@ -27,6 +27,7 @@ enum sbi_ext_id {
> SBI_EXT_IPI = 0x735049,
> SBI_EXT_RFENCE = 0x52464E43,
> SBI_EXT_HSM = 0x48534D,
> + SBI_EXT_SRST = 0x53525354,
> };
>
> enum sbi_ext_base_fid {
> @@ -70,6 +71,12 @@ enum sbi_hsm_hart_status {
> SBI_HSM_HART_STATUS_STOP_PENDING,
> };
>
> +enum sbi_ext_srst_fid {
> + SBI_EXT_SRST_SHUTDOWN = 0,
> + SBI_EXT_SRST_COLD_REBOOT,
> + SBI_EXT_SRST_WARM_REBOOT
> +};
> +
I referred older SBI SRST extension draft where we have separate
function ID for shutdown, cold reboot, and warm reboot.
I will send v2 patch as-per latest SBI SRST extension draft.
My apologies for the noise.
Regards,
Anup
> #define SBI_SPEC_VERSION_DEFAULT 0x1
> #define SBI_SPEC_VERSION_MAJOR_SHIFT 24
> #define SBI_SPEC_VERSION_MAJOR_MASK 0x7f
> diff --git a/arch/riscv/kernel/sbi.c b/arch/riscv/kernel/sbi.c index
> 226ccce0f9e0..865e028a9a4b 100644
> --- a/arch/riscv/kernel/sbi.c
> +++ b/arch/riscv/kernel/sbi.c
> @@ -7,6 +7,7 @@
>
> #include <linux/init.h>
> #include <linux/pm.h>
> +#include <linux/reboot.h>
> #include <asm/sbi.h>
> #include <asm/smp.h>
>
> @@ -501,6 +502,23 @@ int sbi_remote_hfence_vvma_asid(const unsigned
> long *hart_mask, } EXPORT_SYMBOL(sbi_remote_hfence_vvma_asid);
>
> +static int sbi_srst_reboot(struct notifier_block *this,
> + unsigned long mode, void *cmd)
> +{
> + sbi_ecall(SBI_EXT_SRST, (mode == REBOOT_WARM || mode ==
> REBOOT_SOFT) ?
> + SBI_EXT_SRST_WARM_REBOOT :
> SBI_EXT_SRST_COLD_REBOOT,
> + 0, 0, 0, 0, 0, 0);
> +
> + return NOTIFY_DONE;
> +}
> +
> +static struct notifier_block sbi_srst_reboot_nb;
> +
> +static void sbi_srst_power_off(void)
> +{
> + sbi_ecall(SBI_EXT_SRST, SBI_EXT_SRST_SHUTDOWN, 0, 0, 0, 0, 0, 0); }
> +
> /**
> * sbi_probe_extension() - Check if an SBI extension ID is supported or not.
> * @extid: The extension ID to be probed.
> @@ -593,6 +611,13 @@ int __init sbi_init(void)
> } else {
> __sbi_rfence = __sbi_rfence_v01;
> }
> + if (sbi_probe_extension(SBI_EXT_SRST) > 0) {
> + pr_info("SBI v0.2 SRST extension detected\n");
> + pm_power_off = sbi_srst_power_off;
> + sbi_srst_reboot_nb.notifier_call = sbi_srst_reboot;
> + sbi_srst_reboot_nb.priority = 192;
> + register_restart_handler(&sbi_srst_reboot_nb);
> + }
> } else {
> __sbi_set_timer = __sbi_set_timer_v01;
> __sbi_send_ipi = __sbi_send_ipi_v01;
> --
> 2.25.1
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-09-26 4:35 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-25 11:30 [RFC PATCH] RISC-V: Use SBI SRST extension when available Anup Patel
2020-09-26 4:35 ` Anup Patel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).