Add QEMU virt-ctrl driver and update m68k virt
Subsystems (3)
Kuan-Wei Chiu
maintainerv2 cover Add QEMU virt-ctrl driver and update m68k virt
Introduce a generic platform driver for the QEMU 'virt-ctrl' device [1] and transitions the m68k 'virt' machine to use it, replacing architecture-specific hooks.
The new driver ('qemu-virt-ctrl') registers a restart handler and populates the global 'pm_power_off' callback.
On the m68k side, the platform initialization is updated to register the 'qemu-virt-ctrl' platform device. Additionally, the 'mach_reset' hook is bridged to 'do_kernel_restart()' to ensure the kernel's restart handler chain is correctly invoked.
Verified on QEMU m68k virt. Both system reset and power-off were confirmed functional by invoking 'reboot(LINUX_REBOOT_CMD_RESTART)' and 'reboot(LINUX_REBOOT_CMD_POWER_OFF)' from userspace.
---
Changes in v2:
- Use devm_register_sys_off_handler() instead of register_restart_handler() and global pm_power_off.
- Switch Kconfig to tristate to support modular build.
- Add .id_table to platform_driver and use MODULE_DEVICE_TABLE() to correct module auto-loading.
v1: https://lore.kernel.org/lkml/[email protected]/
Kuan-Wei Chiu (2):
power: reset: Add QEMU virt-ctrl driver
m68k: virt: Switch to qemu-virt-ctrl driver
MAINTAINERS | 6 ++ arch/m68k/virt/config.c | 42 +------------ arch/m68k/virt/platform.c | 20 ++++++- drivers/power/reset/Kconfig | 10 ++++ drivers/power/reset/Makefile | 1 + drivers/power/reset/qemu-virt-ctrl.c | 89 ++++++++++++++++++++++++++++ 6 files changed, 124 insertions(+), 44 deletions(-) create mode 100644 drivers/power/reset/qemu-virt-ctrl.c
Signature · 1 line
2.53.0.rc1.225.gd81095ad13-goog
Kuan-Wei Chiu
maintainerPATCH v2 1/2 power: reset: Add QEMU virt-ctrl driver
Add a new driver for the 'virt-ctrl' device found on QEMU virt machines (e.g. m68k). This device provides a simple interface for system reset and power off [1].
This driver utilizes the modern system-off API to register callbacks for both system restart and power off. It is designed to be generic and can be reused by other architectures utilizing this QEMU device.
---
Changes in v2:
- Use devm_register_sys_off_handler() instead of register_restart_handler() and global pm_power_off.
- Switch Kconfig to tristate to support modular build.
- Add .id_table to platform_driver and use MODULE_DEVICE_TABLE() to correct module auto-loading.
MAINTAINERS | 6 ++ drivers/power/reset/Kconfig | 10 ++++ drivers/power/reset/Makefile | 1 + drivers/power/reset/qemu-virt-ctrl.c | 89 ++++++++++++++++++++++++++++ 4 files changed, 106 insertions(+) create mode 100644 drivers/power/reset/qemu-virt-ctrl.c
MAINTAINERS +6 -0
@@ -21190,6 +21190,12 @@ S: Maintained F: drivers/firmware/qemu_fw_cfg.c F: include/uapi/linux/qemu_fw_cfg.h +QEMU VIRT MACHINE SYSTEM CONTROLLER DRIVER +M: Kuan-Wei Chiu <[email protected]> +L: [email protected] +S: Maintained +F: drivers/power/reset/qemu-virt-ctrl.c + QLOGIC QL41xxx FCOE DRIVER M: Saurav Kashyap <[email protected]> M: Javed Hasan <[email protected]>
drivers/power/reset/Kconfig +10 -0
@@ -354,4 +354,14 @@ config POWER_MLXBF help This driver supports reset or low power mode handling for Mellanox BlueField. +config POWER_RESET_QEMU_VIRT_CTRL + tristate "QEMU Virt Machine System Controller" + depends on HAS_IOMEM + help + This driver supports the system reset and power off functionality + provided by the QEMU 'virt-ctrl' device. + + Say Y here if you are running Linux on a QEMU virtual machine that + provides this controller, such as the m68k virt machine. + endif
drivers/power/reset/Makefile +1 -0
@@ -41,3 +41,4 @@ obj-$(CONFIG_SYSCON_REBOOT_MODE) += syscon-reboot-mode.o obj-$(CONFIG_POWER_RESET_SC27XX) += sc27xx-poweroff.o obj-$(CONFIG_NVMEM_REBOOT_MODE) += nvmem-reboot-mode.o obj-$(CONFIG_POWER_MLXBF) += pwr-mlxbf.o +obj-$(CONFIG_POWER_RESET_QEMU_VIRT_CTRL) += qemu-virt-ctrl.o
drivers/power/reset/qemu-virt-ctrl.c new file +89 -0
89 lines not on this page · raw message
Signature · 1 line
2.53.0.rc1.225.gd81095ad13-goog
Kuan-Wei Chiu
maintainerPATCH v2 2/2 m68k: virt: Switch to qemu-virt-ctrl driver
In reply to Kuan-Wei ChiuRegister the "qemu-virt-ctrl" platform device during board initialization to utilize the new generic power/reset driver.
Consequently, remove the legacy reset and power-off implementations specific to the virt machine. The platform's mach_reset callback is updated to call do_kernel_restart(), bridging the legacy m68k reboot path to the generic kernel restart handler framework for this machine.
---
No Changes in v2.
arch/m68k/virt/config.c | 42 +-------------------------------------- arch/m68k/virt/platform.c | 20 ++++++++++++++++--- 2 files changed, 18 insertions(+), 44 deletions(-)
arch/m68k/virt/config.c +1 -41
@@ -13,18 +13,6 @@struct virt_booter_data virt_bi_data; -#define VIRT_CTRL_REG_FEATURES 0x00 -#define VIRT_CTRL_REG_CMD 0x04 - -static struct resource ctrlres; - -enum { -CMD_NOOP , -CMD_RESET , -CMD_HALT , -CMD_PANIC , -}; -static void virt_get_model (char *str) {/* str is 80 characters long */
@@ -33,25 +21,9 @@ static void virt_get_model(char *str) (u8)(virt_bi_data.qemu_version >>16 ), (u8)(virt_bi_data.qemu_version >> 8)); } - -static void virt_halt (void ) -{ -void __iomem *base = (void __iomem *)virt_bi_data.ctrl.mmio; - -iowrite32be (CMD_HALT , base +VIRT_CTRL_REG_CMD ); -local_irq_disable (); -while (1 ) - ; -} -static void virt_reset (void ) { -void __iomem *base = (void __iomem *)virt_bi_data.ctrl.mmio; - -iowrite32be (CMD_RESET , base +VIRT_CTRL_REG_CMD ); -local_irq_disable (); -while (1 ) - ; +do_kernel_restart (NULL ); }/*
@@ -113,20 +85,8 @@ void __init config_virt(void) virt_bi_data.tty.mmio);setup_earlycon (earlycon); - ctrlres = (struct resource ) -DEFINE_RES_MEM_NAMED (virt_bi_data.ctrl.mmio,0x100 , -"virtctrl" ); - -if (request_resource (&iomem_resource, &ctrlres)) { -pr_err ("Cannot allocate virt controller resource\n" ); -return ; - } - mach_init_IRQ = virt_init_IRQ; mach_sched_init = virt_sched_init; mach_get_model = virt_get_model; mach_reset = virt_reset; - mach_halt = virt_halt; - -register_platform_power_off (virt_halt); }
arch/m68k/virt/platform.c +17 -3
@@ -30,7 +30,10 @@ static int __init virt_platform_init(void)DEFINE_RES_MEM (virt_bi_data.rtc.mmio +0x1000 ,0x1000 ), DEFINE_RES_IRQ(virt_bi_data.rtc.irq + 1), }; -struct platform_device *pdev1, *pdev2; +const struct resource virt_ctrl_res[] = { +DEFINE_RES_MEM (virt_bi_data.ctrl.mmio,0x100 ), + }; +struct platform_device *pdev1, *pdev2, *pdev3;struct platform_device *pdevs[VIRTIO_BUS_NB ];unsigned int i;int ret =0 ;
@@ -57,19 +60,30 @@ static int __init virt_platform_init(void) goto err_unregister_tty; } + pdev3 =platform_device_register_simple ("qemu-virt-ctrl" , +PLATFORM_DEVID_NONE , + virt_ctrl_res, +ARRAY_SIZE (virt_ctrl_res)); +if (IS_ERR (pdev3)) { + ret =PTR_ERR (pdev3); + goto err_unregister_rtc; + } +for (i =0 ; i <VIRTIO_BUS_NB ; i++) { pdevs[i] =virt_virtio_init (i);if (IS_ERR (pdevs[i])) { ret =PTR_ERR (pdevs[i]); - goto err_unregister_rtc_virtio; + goto err_unregister_virtio; } }return 0 ; -err_unregister_rtc_virtio: +err_unregister_virtio:while (i >0 )platform_device_unregister (pdevs[--i]); +platform_device_unregister (pdev3); +err_unregister_rtc:platform_device_unregister (pdev2); err_unregister_tty:platform_device_unregister (pdev1);
Signature · 1 line
2.53.0.rc1.225.gd81095ad13-goog
Geert Uytterhoeven
maintainerCC vivier
Quoted 42 lines · Kuan-Wei Chiu
Introduce a generic platform driver for the QEMU 'virt-ctrl' device [1] and transitions the m68k 'virt' machine to use it, replacing architecture-specific hooks.
The new driver ('qemu-virt-ctrl') registers a restart handler and populates the global '
pm_power_off' callback.On the m68k side, the platform initialization is updated to register the 'qemu-virt-ctrl' platform device. Additionally, the '
mach_reset' hook is bridged to 'do_kernel_restart()' to ensure the kernel's restart handler chain is correctly invoked.Verified on QEMU m68k virt. Both system reset and power-off were confirmed functional by invoking '
reboot(LINUX_REBOOT_CMD_RESTART)' and 'reboot(LINUX_REBOOT_CMD_POWER_OFF)' from userspace.---
Changes in v2:
- Usedevm_register_sys_off_handler()instead ofregister_restart_handler()and globalpm_power_off.
- SwitchKconfigto tristate to support modular build.
- Add .id_table toplatform_driverand useMODULE_DEVICE_TABLE()to correct module auto-loading.v1: https://lore.kernel.org/lkml/[email protected]/
Kuan-Wei Chiu (2):
power: reset: Add QEMU virt-ctrl driver
m68k: virt: Switch to qemu-virt-ctrl driverMAINTAINERS | 6 ++ arch/m68k/virt/config.c | 42 +------------ arch/m68k/virt/platform.c | 20 ++++++- drivers/power/reset/Kconfig | 10 ++++ drivers/power/reset/Makefile | 1 + drivers/power/reset/qemu-virt-ctrl.c | 89 ++++++++++++++++++++++++++++ 6 files changed, 124 insertions(+), 44 deletions(-) create mode 100644 drivers/power/reset/qemu-virt-ctrl.c--
2.53.0.rc1.225.gd81095ad13-goog
Le 04/02/2026 à 08:56, Geert Uytterhoeven a écrit :
Quoted 1 line
CC vivier
Thank you Geert
Quoted 41 lines · Kuan-Wei Chiu
Quoted 40 lines
Introduce a generic platform driver for the QEMU 'virt-ctrl' device [1] and transitions the m68k 'virt' machine to use it, replacing architecture-specific hooks.
The new driver ('qemu-virt-ctrl') registers a restart handler and populates the global '
pm_power_off' callback.On the m68k side, the platform initialization is updated to register the 'qemu-virt-ctrl' platform device. Additionally, the '
mach_reset' hook is bridged to 'do_kernel_restart()' to ensure the kernel's restart handler chain is correctly invoked.Verified on QEMU m68k virt. Both system reset and power-off were confirmed functional by invoking '
reboot(LINUX_REBOOT_CMD_RESTART)' and 'reboot(LINUX_REBOOT_CMD_POWER_OFF)' from userspace.---
Changes in v2:
- Usedevm_register_sys_off_handler()instead ofregister_restart_handler()and globalpm_power_off.
- SwitchKconfigto tristate to support modular build.
- Add .id_table toplatform_driverand useMODULE_DEVICE_TABLE()to correct module auto-loading.v1: https://lore.kernel.org/lkml/[email protected]/
Kuan-Wei Chiu (2):
power: reset: Add QEMU virt-ctrl driver
m68k: virt: Switch to qemu-virt-ctrl driverMAINTAINERS | 6 ++ arch/m68k/virt/config.c | 42 +------------ arch/m68k/virt/platform.c | 20 ++++++- drivers/power/reset/Kconfig | 10 ++++ drivers/power/reset/Makefile | 1 + drivers/power/reset/qemu-virt-ctrl.c | 89 ++++++++++++++++++++++++++++ 6 files changed, 124 insertions(+), 44 deletions(-)create mode 100644
drivers/power/reset/qemu-virt-ctrl.c
Quoted 2 lines
Quoted 2 lines
--
2.53.0.rc1.225.gd81095ad13-goog
Some comments on the series:
- Please test LINUX_REBOOT_CMD_HALT as well. With mach_halt removed, HALT now falls back to machine_halt()’s infinite loop (no CMD_HALT), so behavior changes.
- Please add select POWER_RESET_QEMU_VIRT_CTRL under config VIRT in arch/m68k/Kconfig.machine to avoid a restart regression when the driver isn’t built-in.
- Endianness: QEMU’s virt-ctrl is DEVICE_NATIVE_ENDIAN, so BE on m68k but LE elsewhere. If the driver is meant to be generic, handle native endianness instead of hardcoding iowrite32be().
FWIW, I originally modeled virt-ctrl as a generic misc device, but since it only exposes power/reset today, keeping the driver under drivers/power/reset is fine...
Please cc: me on the next version
Thanks,
Laurent
Hi Laurent,
Quoted 1 line · Laurent Vivier
Please cc: me on the next version
FWIW support for the m68k virt machine also just got merged to u-boot:
https://lore.kernel.org/u-boot/[email protected]/
Le 04/02/2026 à 13:47, Daniel Palmer a écrit :
Quoted 8 lines
Hi Laurent,
Quoted 1 line · Laurent Vivier
Please cc: me on the next version
FWIW support for the m68k virt machine also just got merged to u-boot:
https://lore.kernel.org/u-boot/[email protected]/
It's great. I did a port of petitboot but never merged it to QEMU.
How to use it with QEMU? Do we need some changes in the code?
Thanks,
Laurent
Hi Laurent,
Quoted 1 line · Laurent Vivier
How to use it with QEMU? Do we need some changes in the code?
You just load u-boot instead of the linux kernel. I don't think you can actually do much with it because there's no virtio support to load linux etc yet.
But I have that all working in my own branch and now Kuan-Wei has got the first parts merged adding the remaining parts to boot linux shouldn't be too difficult.
Cheers,
Daniel
Le 04/02/2026 à 14:02, Daniel Palmer a écrit :
Quoted 12 lines
Hi Laurent,
Quoted 1 line · Laurent Vivier
How to use it with QEMU? Do we need some changes in the code?
You just load u-boot instead of the linux kernel. I don't think you can actually do much with it because there's no virtio support to load linux etc yet.
But I have that all working in my own branch and now Kuan-Wei has got the first parts merged adding the remaining parts to boot linux shouldn't be too difficult.
I have an old branch with a bootstrap ROM that can be used to start a bigger ROM, I use it with petitboot, but perhaps it can be used to load U-boot instead:
https://github.com/vivier/qemu/tree/m68k-virt-petitboot
In this case virt-ctrl is extended to control the firmware.
Thanks,
Laurent