From eaf773cf404fd5c5581740766e52941e0082e852 Mon Sep 17 00:00:00 2001 From: Kuan-Wei Chiu Date: Wed, 28 Jan 2026 15:58:42 +0000 Subject: [PATCH] [platform][qemu-virt-m68k] implement system reset and power off Implement system reset and power off for the qemu-virt-m68k platform by utilizing the virt-ctrl MMIO device. Previously, this platform lacked a specific platform_halt() implementation, causing it to fall back to the default behavior of spinning indefinitely. As a result, commands like 'reboot' or 'poweroff' would cause the kernel to hang with a "HALT: spinning forever" message instead of actually exiting or restarting the QEMU instance. Introduce the necessary virt-ctrl register definitions and command codes, and implements the platform_halt() callback to trigger the appropriate hardware reset and halt signals via the MMIO interface. Signed-off-by: Kuan-Wei Chiu --- platform/qemu-virt-m68k/include/platform/virt.h | 10 ++++++++++ platform/qemu-virt-m68k/platform.c | 12 ++++++++++++ 2 files changed, 22 insertions(+) diff --git a/platform/qemu-virt-m68k/include/platform/virt.h b/platform/qemu-virt-m68k/include/platform/virt.h index f30bfcfaae..6b411cb2b7 100644 --- a/platform/qemu-virt-m68k/include/platform/virt.h +++ b/platform/qemu-virt-m68k/include/platform/virt.h @@ -52,6 +52,16 @@ #define VIRT_CTRL_MMIO_BASE 0xff009000 /* MMIO: 0xff009000 - 0xff009fff */ #define VIRT_CTRL_IRQ_BASE PIC_IRQ(1, 1) /* PIC: #1, IRQ: #1 */ +/* virt-ctrl registers */ +#define VIRT_CTRL_REG_FEATURES 0x00 +#define VIRT_CTRL_REG_CMD 0x04 + +/* virt-ctrl command codes */ +#define VIRT_CTRL_CMD_NOOP 0 +#define VIRT_CTRL_CMD_RESET 1 +#define VIRT_CTRL_CMD_HALT 2 +#define VIRT_CTRL_CMD_PANIC 3 + /* * virtio-mmio size is 0x200 bytes * we use 4 goldfish-pic to attach them, diff --git a/platform/qemu-virt-m68k/platform.c b/platform/qemu-virt-m68k/platform.c index 565e491f38..adf8efac32 100644 --- a/platform/qemu-virt-m68k/platform.c +++ b/platform/qemu-virt-m68k/platform.c @@ -132,3 +132,15 @@ void platform_init(void) { } #endif } + +static void virt_ctrl_system_reset(void) { + writel(VIRT_CTRL_CMD_RESET, VIRT_CTRL_MMIO_BASE + VIRT_CTRL_REG_CMD); +} + +static void virt_ctrl_system_off(void) { + writel(VIRT_CTRL_CMD_HALT, VIRT_CTRL_MMIO_BASE + VIRT_CTRL_REG_CMD); +} + +void platform_halt(platform_halt_action action, platform_halt_reason reason) { + platform_halt_default(action, reason, &virt_ctrl_system_reset, &virt_ctrl_system_off); +}