Skip to content

Commit 56f2958

Browse files
visitorckwgeertu
authored andcommitted
m68k: virt: Switch to qemu-virt-ctrl driver
Register 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. Signed-off-by: Kuan-Wei Chiu <visitorckw@gmail.com> Reviewed-by: Geert Uytterhoeven <geert@linux-m68k.org> Link: https://patch.msgid.link/20260412211952.3564033-3-visitorckw@gmail.com Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
1 parent ad9d2cd commit 56f2958

3 files changed

Lines changed: 20 additions & 44 deletions

File tree

arch/m68k/Kconfig.machine

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ config VIRT
133133
select GOLDFISH_TIMER
134134
select GOLDFISH_TTY
135135
select M68040
136+
select POWER_RESET
137+
select POWER_RESET_QEMU_VIRT_CTRL
136138
select RTC_CLASS
137139
select RTC_DRV_GOLDFISH
138140
select TTY

arch/m68k/virt/config.c

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,6 @@
1313

1414
struct virt_booter_data virt_bi_data;
1515

16-
#define VIRT_CTRL_REG_FEATURES 0x00
17-
#define VIRT_CTRL_REG_CMD 0x04
18-
19-
static struct resource ctrlres;
20-
21-
enum {
22-
CMD_NOOP,
23-
CMD_RESET,
24-
CMD_HALT,
25-
CMD_PANIC,
26-
};
27-
2816
static void virt_get_model(char *str)
2917
{
3018
/* str is 80 characters long */
@@ -33,25 +21,9 @@ static void virt_get_model(char *str)
3321
(u8)(virt_bi_data.qemu_version >> 16),
3422
(u8)(virt_bi_data.qemu_version >> 8));
3523
}
36-
37-
static void virt_halt(void)
38-
{
39-
void __iomem *base = (void __iomem *)virt_bi_data.ctrl.mmio;
40-
41-
iowrite32be(CMD_HALT, base + VIRT_CTRL_REG_CMD);
42-
local_irq_disable();
43-
while (1)
44-
;
45-
}
46-
4724
static void virt_reset(void)
4825
{
49-
void __iomem *base = (void __iomem *)virt_bi_data.ctrl.mmio;
50-
51-
iowrite32be(CMD_RESET, base + VIRT_CTRL_REG_CMD);
52-
local_irq_disable();
53-
while (1)
54-
;
26+
do_kernel_restart(NULL);
5527
}
5628

5729
/*
@@ -113,20 +85,8 @@ void __init config_virt(void)
11385
virt_bi_data.tty.mmio);
11486
setup_earlycon(earlycon);
11587

116-
ctrlres = (struct resource)
117-
DEFINE_RES_MEM_NAMED(virt_bi_data.ctrl.mmio, 0x100,
118-
"virtctrl");
119-
120-
if (request_resource(&iomem_resource, &ctrlres)) {
121-
pr_err("Cannot allocate virt controller resource\n");
122-
return;
123-
}
124-
12588
mach_init_IRQ = virt_init_IRQ;
12689
mach_sched_init = virt_sched_init;
12790
mach_get_model = virt_get_model;
12891
mach_reset = virt_reset;
129-
mach_halt = virt_halt;
130-
131-
register_platform_power_off(virt_halt);
13292
}

arch/m68k/virt/platform.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ static int __init virt_platform_init(void)
3030
DEFINE_RES_MEM(virt_bi_data.rtc.mmio + 0x1000, 0x1000),
3131
DEFINE_RES_IRQ(virt_bi_data.rtc.irq + 1),
3232
};
33-
struct platform_device *pdev1, *pdev2;
33+
const struct resource virt_ctrl_res[] = {
34+
DEFINE_RES_MEM(virt_bi_data.ctrl.mmio, 0x100),
35+
};
36+
struct platform_device *pdev1, *pdev2, *pdev3;
3437
struct platform_device *pdevs[VIRTIO_BUS_NB];
3538
unsigned int i;
3639
int ret = 0;
@@ -57,19 +60,30 @@ static int __init virt_platform_init(void)
5760
goto err_unregister_tty;
5861
}
5962

63+
pdev3 = platform_device_register_simple("qemu-virt-ctrl",
64+
PLATFORM_DEVID_NONE,
65+
virt_ctrl_res,
66+
ARRAY_SIZE(virt_ctrl_res));
67+
if (IS_ERR(pdev3)) {
68+
ret = PTR_ERR(pdev3);
69+
goto err_unregister_rtc;
70+
}
71+
6072
for (i = 0; i < VIRTIO_BUS_NB; i++) {
6173
pdevs[i] = virt_virtio_init(i);
6274
if (IS_ERR(pdevs[i])) {
6375
ret = PTR_ERR(pdevs[i]);
64-
goto err_unregister_rtc_virtio;
76+
goto err_unregister_virtio;
6577
}
6678
}
6779

6880
return 0;
6981

70-
err_unregister_rtc_virtio:
82+
err_unregister_virtio:
7183
while (i > 0)
7284
platform_device_unregister(pdevs[--i]);
85+
platform_device_unregister(pdev3);
86+
err_unregister_rtc:
7387
platform_device_unregister(pdev2);
7488
err_unregister_tty:
7589
platform_device_unregister(pdev1);

0 commit comments

Comments
 (0)