From owner-dev-commits-src-all@freebsd.org Thu Feb 4 16:18:10 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 1FC60547EA5; Thu, 4 Feb 2021 16:18:10 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4DWkHQ0R1fz4YPm; Thu, 4 Feb 2021 16:18:10 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id EB37F6BAE; Thu, 4 Feb 2021 16:18:09 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 114GI9rD011044; Thu, 4 Feb 2021 16:18:09 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 114GI9YP011043; Thu, 4 Feb 2021 16:18:09 GMT (envelope-from git) Date: Thu, 4 Feb 2021 16:18:09 GMT Message-Id: <202102041618.114GI9YP011043@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mitchell Horne Subject: git: b680dba47653 - stable/13 - riscv: add SBI system reset extension MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mhorne X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: b680dba47653451aeda9292dd6dcda2f79b905e7 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 04 Feb 2021 16:18:10 -0000 The branch stable/13 has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=b680dba47653451aeda9292dd6dcda2f79b905e7 commit b680dba47653451aeda9292dd6dcda2f79b905e7 Author: Mitchell Horne AuthorDate: 2021-01-27 21:27:15 +0000 Commit: Mitchell Horne CommitDate: 2021-02-04 16:17:31 +0000 riscv: add SBI system reset extension (cherry picked from commit 9bae4ce661c59be88fec89b2531148e36dd1a23e) (cherry picked from commit a6405133b7e14929f8e8e61cf30d7152b1410e59) --- sys/riscv/include/sbi.h | 28 +++++++++++++++++++++------- sys/riscv/riscv/sbi.c | 34 ++++++++++++++++++++++++++-------- sys/riscv/riscv/vm_machdep.c | 2 +- 3 files changed, 48 insertions(+), 16 deletions(-) diff --git a/sys/riscv/include/sbi.h b/sys/riscv/include/sbi.h index 50cacb3e6e5a..9d3f4076dcb2 100644 --- a/sys/riscv/include/sbi.h +++ b/sys/riscv/include/sbi.h @@ -99,6 +99,15 @@ #define SBI_HSM_STATUS_START_PENDING 2 #define SBI_HSM_STATUS_STOP_PENDING 3 +/* System Reset (SRST) Extension */ +#define SBI_EXT_ID_SRST 0x53525354 +#define SBI_SRST_SYSTEM_RESET 0 +#define SBI_SRST_TYPE_SHUTDOWN 0 +#define SBI_SRST_TYPE_COLD_REBOOT 1 +#define SBI_SRST_TYPE_WARM_REBOOT 2 +#define SBI_SRST_REASON_NONE 0 +#define SBI_SRST_REASON_SYSTEM_FAILURE 1 + /* Legacy Extensions */ #define SBI_SET_TIMER 0 #define SBI_CONSOLE_PUTCHAR 1 @@ -199,6 +208,18 @@ void sbi_hsm_hart_stop(void); */ int sbi_hsm_hart_status(u_long hart); +/* System Reset extension functions. */ + +/* + * Reset the system based on the following 'type' and 'reason' chosen from: + * - SBI_SRST_TYPE_SHUTDOWN + * - SBI_SRST_TYPE_COLD_REBOOT + * - SBI_SRST_TYPE_WARM_REBOOT + * - SBI_SRST_REASON_NONE + * - SBI_SRST_REASON_SYSTEM_FAILURE + */ +void sbi_system_reset(u_long reset_type, u_long reset_reason); + /* Legacy extension functions. */ static __inline void sbi_console_putchar(int ch) @@ -218,13 +239,6 @@ sbi_console_getchar(void) return (SBI_CALL0(SBI_CONSOLE_GETCHAR, 0).error); } -static __inline void -sbi_shutdown(void) -{ - - (void)SBI_CALL0(SBI_SHUTDOWN, 0); -} - void sbi_print_version(void); void sbi_init(void); diff --git a/sys/riscv/riscv/sbi.c b/sys/riscv/riscv/sbi.c index d529d2d08351..6897fce9cad3 100644 --- a/sys/riscv/riscv/sbi.c +++ b/sys/riscv/riscv/sbi.c @@ -49,6 +49,7 @@ u_long sbi_impl_version; static bool has_time_extension = false; static bool has_ipi_extension = false; static bool has_rfnc_extension = false; +static bool has_srst_extension = false; static struct sbi_ret sbi_get_spec_version(void) @@ -90,7 +91,18 @@ static void sbi_shutdown_final(void *dummy __unused, int howto) { if ((howto & RB_POWEROFF) != 0) - sbi_shutdown(); + sbi_system_reset(SBI_SRST_TYPE_SHUTDOWN, SBI_SRST_REASON_NONE); +} + +void +sbi_system_reset(u_long reset_type, u_long reset_reason) +{ + /* Use the SRST extension, if available. */ + if (has_srst_extension) { + (void)SBI_CALL2(SBI_EXT_ID_SRST, SBI_SRST_SYSTEM_RESET, + reset_type, reset_reason); + } + (void)SBI_CALL0(SBI_SHUTDOWN, 0); } void @@ -111,10 +123,12 @@ sbi_print_version(void) printf("SBI: Berkely Boot Loader %lu\n", sbi_impl_version); break; case (SBI_IMPL_ID_XVISOR): - printf("SBI: eXtensible Versatile hypervISOR %lu\n", sbi_impl_version); + printf("SBI: eXtensible Versatile hypervISOR %lu\n", + sbi_impl_version); break; case (SBI_IMPL_ID_KVM): - printf("SBI: Kernel-based Virtual Machine %lu\n", sbi_impl_version); + printf("SBI: Kernel-based Virtual Machine %lu\n", + sbi_impl_version); break; case (SBI_IMPL_ID_RUSTSBI): printf("SBI: RustSBI %lu\n", sbi_impl_version); @@ -206,8 +220,9 @@ sbi_remote_sfence_vma_asid(const u_long *hart_mask, u_long start, u_long size, /* Use the RFENCE legacy replacement extension, if available. */ if (has_rfnc_extension) { - ret = SBI_CALL5(SBI_EXT_ID_RFNC, SBI_RFNC_REMOTE_SFENCE_VMA_ASID, - *hart_mask, 0, start, size, asid); + ret = SBI_CALL5(SBI_EXT_ID_RFNC, + SBI_RFNC_REMOTE_SFENCE_VMA_ASID, *hart_mask, 0, start, + size, asid); MPASS(ret.error == SBI_SUCCESS); } else { (void)SBI_CALL4(SBI_REMOTE_SFENCE_VMA_ASID, 0, @@ -220,7 +235,8 @@ sbi_hsm_hart_start(u_long hart, u_long start_addr, u_long priv) { struct sbi_ret ret; - ret = SBI_CALL3(SBI_EXT_ID_HSM, SBI_HSM_HART_START, hart, start_addr, priv); + ret = SBI_CALL3(SBI_EXT_ID_HSM, SBI_HSM_HART_START, hart, start_addr, + priv); return (ret.error != 0 ? (int)ret.error : 0); } @@ -273,6 +289,8 @@ sbi_init(void) has_ipi_extension = true; if (sbi_probe_extension(SBI_EXT_ID_RFNC) != 0) has_rfnc_extension = true; + if (sbi_probe_extension(SBI_EXT_ID_SRST) != 0) + has_srst_extension = true; /* * Probe for legacy extensions. We still rely on many of them to be @@ -295,8 +313,8 @@ sbi_init(void) KASSERT(has_rfnc_extension || sbi_probe_extension(SBI_REMOTE_SFENCE_VMA_ASID) != 0, ("SBI doesn't implement sbi_remote_sfence_vma_asid()")); - KASSERT(sbi_probe_extension(SBI_SHUTDOWN) != 0, - ("SBI doesn't implement sbi_shutdown()")); + KASSERT(has_srst_extension || sbi_probe_extension(SBI_SHUTDOWN) != 0, + ("SBI doesn't implement a shutdown or reset extension")); } static void diff --git a/sys/riscv/riscv/vm_machdep.c b/sys/riscv/riscv/vm_machdep.c index f38f1c04caa8..094662413f4e 100644 --- a/sys/riscv/riscv/vm_machdep.c +++ b/sys/riscv/riscv/vm_machdep.c @@ -110,7 +110,7 @@ void cpu_reset(void) { - sbi_shutdown(); + sbi_system_reset(SBI_SRST_TYPE_COLD_REBOOT, SBI_SRST_REASON_NONE); while(1); }