Skip to content

Commit

Permalink
riscv/virt: M-mode poweroff support
Browse files Browse the repository at this point in the history
This adds poweroff support to `rv-virt/nsh` and `rv-virt/nsh64`.

Signed-off-by: Yanfeng Liu <[email protected]>
  • Loading branch information
yf13 committed May 8, 2024
1 parent c9a2e4a commit 36d601f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 3 deletions.
2 changes: 2 additions & 0 deletions arch/risc-v/src/qemu-rv/hardware/qemu_rv_memorymap.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@
#define QEMU_RV_ACLINT_BASE 0x02f00000
#define QEMU_RV_PLIC_BASE 0x0c000000

#define QEMU_RV_RESET_BASE 0x100000

#endif /* __ARCH_RISCV_SRC_QEMU_RV_HARDWARE_QEMU_RV_MEMORYMAP_H */
8 changes: 8 additions & 0 deletions arch/risc-v/src/qemu-rv/qemu_rv_memorymap.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,12 @@
#define QEMU_RV_IDLESTACK_BASE _ebss
#endif

#ifndef CONFIG_BUILD_KERNEL
/* QEMU reset chocies */

#define QEMU_RV_RESET_DONE 0x5555
#define QEMU_RV_RESET_FAIL 0x3333
#define QEMU_RV_RESET_REBOOT 0x7777
#endif

#endif /* __ARCH_RISCV_SRC_QEMU_RV_QEMU_RV_MEMORYMAP_H */
2 changes: 1 addition & 1 deletion boards/risc-v/qemu-rv/rv-virt/configs/nsh/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ CONFIG_ARCH_CHIP_QEMU_RV_ISA_M=y
CONFIG_ARCH_INTERRUPTSTACK=2048
CONFIG_ARCH_RISCV=y
CONFIG_ARCH_STACKDUMP=y
CONFIG_BOARDCTL_POWEROFF=y
CONFIG_BOARD_LOOPSPERMSEC=6366
CONFIG_BUILTIN=y
CONFIG_DEBUG_FULLOPT=y
Expand All @@ -37,7 +38,6 @@ CONFIG_FS_HOSTFS=y
CONFIG_FS_PROCFS=y
CONFIG_IDLETHREAD_STACKSIZE=2048
CONFIG_INIT_ENTRYPOINT="nsh_main"
CONFIG_INTELHEX_BINARY=y
CONFIG_LIBC_ENVPATH=y
CONFIG_LIBC_EXECFUNCS=y
CONFIG_LIBC_PERROR_STDOUT=y
Expand Down
2 changes: 1 addition & 1 deletion boards/risc-v/qemu-rv/rv-virt/configs/nsh64/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ CONFIG_ARCH_INTERRUPTSTACK=2048
CONFIG_ARCH_RISCV=y
CONFIG_ARCH_STACKDUMP=y
CONFIG_BCH=y
CONFIG_BOARDCTL_POWEROFF=y
CONFIG_BOARD_LOOPSPERMSEC=6366
CONFIG_BUILTIN=y
CONFIG_DEBUG_FULLOPT=y
Expand All @@ -40,7 +41,6 @@ CONFIG_FS_PROCFS=y
CONFIG_IDLETHREAD_STACKSIZE=2048
CONFIG_INIT_ENTRYPOINT="nsh_main"
CONFIG_INIT_STACKSIZE=3072
CONFIG_INTELHEX_BINARY=y
CONFIG_LIBC_ENVPATH=y
CONFIG_LIBC_EXECFUNCS=y
CONFIG_LIBC_PERROR_STDOUT=y
Expand Down
6 changes: 5 additions & 1 deletion boards/risc-v/qemu-rv/rv-virt/src/qemu_rv_appinit.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@

#include <sys/mount.h>

#ifndef CONFIG_BUILD_KERNEL
#include "hardware/qemu_rv_memorymap.h"
#include "qemu_rv_memorymap.h"
#endif
#include "riscv_internal.h"
#include "romfs.h"

Expand Down Expand Up @@ -185,7 +189,7 @@ int board_power_off(int status)
#ifdef CONFIG_BUILD_KERNEL
riscv_sbi_system_reset(SBI_SRST_TYPE_SHUTDOWN, SBI_SRST_REASON_NONE);
#else
#warning "to be done"
*(FAR volatile uint32_t *)QEMU_RV_RESET_BASE = QEMU_RV_RESET_DONE;
#endif

UNUSED(status);
Expand Down

0 comments on commit 36d601f

Please sign in to comment.