]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
efi_driver: provide SBI based runtime system reset
authorHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Mon, 12 Feb 2024 16:18:37 +0000 (17:18 +0100)
committerHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Wed, 28 Feb 2024 13:38:47 +0000 (14:38 +0100)
On RISC-V systems system the Supervisory Binary Interface provides system
reset and poweroff. Use it at EFI runtime.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
lib/efi_driver/Makefile
lib/efi_driver/efi_reset_riscv.c [new file with mode: 0644]
lib/efi_loader/Kconfig

index f2b6c05cc2404be5af1ca8244588a9257ed3e551..0da20fe91d369de3b8724a9ae2d944c67f72978a 100644 (file)
@@ -9,3 +9,4 @@ obj-y += efi_uclass.o
 ifeq ($(CONFIG_PARTITIONS),y)
 obj-y += efi_block_device.o
 endif
+obj-$(CONFIG_SYSRESET_SBI) += efi_reset_riscv.o
diff --git a/lib/efi_driver/efi_reset_riscv.c b/lib/efi_driver/efi_reset_riscv.c
new file mode 100644 (file)
index 0000000..89b2352
--- /dev/null
@@ -0,0 +1,29 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include <efi_loader.h>
+#include <asm/sbi.h>
+
+void __efi_runtime EFIAPI efi_reset_system(enum efi_reset_type reset_type,
+                                          efi_status_t reset_status,
+                                          unsigned long data_size,
+                                          void *reset_data)
+{
+       register unsigned long eid asm("a7") = SBI_EXT_SRST;
+       register unsigned long fid asm("a6") = SBI_EXT_SRST_RESET;
+       register unsigned long type asm("a0");
+       register unsigned long reason asm("a1") = SBI_SRST_RESET_REASON_NONE;
+
+       switch (reset_type) {
+       case EFI_RESET_WARM:
+               type = SBI_SRST_RESET_TYPE_WARM_REBOOT;
+               break;
+       case EFI_RESET_SHUTDOWN:
+               type = SBI_SRST_RESET_TYPE_SHUTDOWN;
+               break;
+       default:
+               type = SBI_SRST_RESET_TYPE_COLD_REBOOT;
+               break;
+       }
+       asm volatile ("ecall\n"
+                     : : "r" (eid), "r" (fid), "r" (type), "r" (reason));
+}
index db5571de1d9506447de48640baefec097e48c7c0..a7c3e05c13a0f606d05e67ec52117163042c95dc 100644 (file)
@@ -366,7 +366,7 @@ config EFI_HAVE_RUNTIME_RESET
        bool
        default y
        depends on ARCH_BCM283X || FSL_LAYERSCAPE || PSCI_RESET || \
-                  SANDBOX || SYSRESET_X86
+                  SANDBOX || SYSRESET_SBI || SYSRESET_X86
 
 config EFI_GRUB_ARM32_WORKAROUND
        bool "Workaround for GRUB on 32bit ARM"