Add QEMU virt-ctrl driver and update m68k virt
Subsystems (3)
Kuan-Wei Chiu
maintainerv4 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)', 'reboot(LINUX_REBOOT_CMD_POWER_OFF)', and 'reboot(LINUX_REBOOT_CMD_HALT)' from userspace.
---
Changes in v4:
- Fix sparse warning caught by kernel test robot.
- Pass the struct qemu_virt_ctrl context to sys-off handlers instead of the __iomem pointer.
Changes in v3:
- Add a reboot notifier in the driver to handle LINUX_REBOOT_CMD_HALT.
- Handle native endianness in the driver instead of hardcoding big-endian I/O writes.
- Select POWER_RESET and POWER_RESET_QEMU_VIRT_CTRL in m68k Kconfig.machine.
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.
v2: https://lore.kernel.org/lkml/[email protected]/
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/Kconfig.machine | 2 + 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 | 122 +++++++++++++++++++++++++++ 7 files changed, 159 insertions(+), 44 deletions(-) create mode 100644 drivers/power/reset/qemu-virt-ctrl.c
Signature · 1 line
2.53.0.1213.gd9a14994de-goog
Kuan-Wei Chiu
maintainerPATCH v4 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 also registers a reboot notifier to catch SYS_HALT events, ensuring that LINUX_REBOOT_CMD_HALT is properly handled. It is designed to be generic and can be reused by other architectures utilizing this QEMU device.
---
Changes in v4:
- Fix sparse warning caught by kernel test robot.
- Pass the struct qemu_virt_ctrl context to sys-off handlers instead of the __iomem pointer.
MAINTAINERS | 6 ++ drivers/power/reset/Kconfig | 10 +++ drivers/power/reset/Makefile | 1 + drivers/power/reset/qemu-virt-ctrl.c | 122 +++++++++++++++++++++++++++ 4 files changed, 139 insertions(+) create mode 100644 drivers/power/reset/qemu-virt-ctrl.c
MAINTAINERS +6 -0
@@ -21441,6 +21441,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 +122 -0
122 lines not on this page · raw message
Signature · 1 line
2.53.0.1213.gd9a14994de-goog
Kuan-Wei Chiu
maintainerPATCH v4 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.
To prevent any regressions in reboot or power-off functionality when the driver is not built-in, explicitly select POWER_RESET and POWER_RESET_QEMU_VIRT_CTRL for the VIRT machine in Kconfig.machine.
--- arch/m68k/Kconfig.machine | 2 ++ arch/m68k/virt/config.c | 42 +-------------------------------------- arch/m68k/virt/platform.c | 20 ++++++++++++++++--- 3 files changed, 20 insertions(+), 44 deletions(-)
arch/m68k/Kconfig.machine +2 -0
@@ -133,6 +133,8 @@ config VIRT select GOLDFISH_TIMER select GOLDFISH_TTY select M68040 + select POWER_RESET + select POWER_RESET_QEMU_VIRT_CTRL select RTC_CLASS select RTC_DRV_GOLDFISH select TTY
arch/m68k/virt/config.c +1 -41
64 lines not on this page · raw message
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.1213.gd9a14994de-goog
Geert Uytterhoeven
maintainerHi Kuan-Wei,
Quoted 17 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)', 'reboot(LINUX_REBOOT_CMD_POWER_OFF)', and 'reboot(LINUX_REBOOT_CMD_HALT)' from userspace.
Quoted 6 lines
---
Changes in v4:
- Fix sparse warning caught by kernel test robot.
- Pass the structqemu_virt_ctrlcontext to sys-off handlers instead of the__iomempointer.
Thanks I replaced v3 with v4 in my queue in the m68k tree for v7.1, and will postpone my PR by a few days to give it some coverage in linux-next.
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds