[PATCH v2 0/2] Add QEMU virt-ctrl driver and update m68k virt

Kuan-Wei Chiu posted 2 patches 3 days, 22 hours ago
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
[PATCH v2 0/2] Add QEMU virt-ctrl driver and update m68k virt
Posted by Kuan-Wei Chiu 3 days, 22 hours ago
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.

Link: https://gitlab.com/qemu-project/qemu/-/blob/v10.2.0/hw/misc/virt_ctrl.c [1]
---
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/20260112182258.1851769-1-visitorckw@gmail.com/

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

-- 
2.53.0.rc1.225.gd81095ad13-goog
Re: [PATCH v2 0/2] Add QEMU virt-ctrl driver and update m68k virt
Posted by Geert Uytterhoeven 3 days, 7 hours ago
CC vivier

On Tue, 3 Feb 2026 at 18:08, Kuan-Wei Chiu <visitorckw@gmail.com> wrote:
> 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.
>
> Link: https://gitlab.com/qemu-project/qemu/-/blob/v10.2.0/hw/misc/virt_ctrl.c [1]
> ---
> 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/20260112182258.1851769-1-visitorckw@gmail.com/
>
> 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
>
> --
> 2.53.0.rc1.225.gd81095ad13-goog
Re: [PATCH v2 0/2] Add QEMU virt-ctrl driver and update m68k virt
Posted by Laurent Vivier 3 days, 6 hours ago
Le 04/02/2026 à 08:56, Geert Uytterhoeven a écrit :
> CC vivier

Thank you Geert

> On Tue, 3 Feb 2026 at 18:08, Kuan-Wei Chiu <visitorckw@gmail.com> wrote:
>> 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.
>>
>> Link: https://gitlab.com/qemu-project/qemu/-/blob/v10.2.0/hw/misc/virt_ctrl.c [1]
>> ---
>> 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/20260112182258.1851769-1-visitorckw@gmail.com/
>>
>> 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
>>
>> --
>> 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
Re: [PATCH v2 0/2] Add QEMU virt-ctrl driver and update m68k virt
Posted by Daniel Palmer 3 days, 2 hours ago
Hi Laurent,

On Wed, 4 Feb 2026 at 18:09, Laurent Vivier <laurent@vivier.eu> wrote:

> 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/177007672356.4123720.10843284111217950440.b4-ty@konsulko.com/
Re: [PATCH v2 0/2] Add QEMU virt-ctrl driver and update m68k virt
Posted by Laurent Vivier 3 days, 2 hours ago
Le 04/02/2026 à 13:47, Daniel Palmer a écrit :
> Hi Laurent,
> 
> On Wed, 4 Feb 2026 at 18:09, Laurent Vivier <laurent@vivier.eu> wrote:
> 
>> 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/177007672356.4123720.10843284111217950440.b4-ty@konsulko.com/

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
Re: [PATCH v2 0/2] Add QEMU virt-ctrl driver and update m68k virt
Posted by Daniel Palmer 3 days, 2 hours ago
Hi Laurent,

On Wed, 4 Feb 2026 at 21:53, Laurent Vivier <laurent@vivier.eu> wrote:
> 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
Re: [PATCH v2 0/2] Add QEMU virt-ctrl driver and update m68k virt
Posted by Laurent Vivier 3 days ago
Le 04/02/2026 à 14:02, Daniel Palmer a écrit :
> Hi Laurent,
> 
> On Wed, 4 Feb 2026 at 21:53, Laurent Vivier <laurent@vivier.eu> wrote:
>> 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