Commit 56f29585 authored by Kuan-Wei Chiu's avatar Kuan-Wei Chiu Committed by Geert Uytterhoeven
Browse files

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: default avatarKuan-Wei Chiu <visitorckw@gmail.com>
Reviewed-by: default avatarGeert Uytterhoeven <geert@linux-m68k.org>
Link: https://patch.msgid.link/20260412211952.3564033-3-visitorckw@gmail.com


Signed-off-by: default avatarGeert Uytterhoeven <geert@linux-m68k.org>
parent ad9d2cd0
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -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
+1 −41
Original line number Diff line number Diff line
@@ -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);
}
+17 −3
Original line number Diff line number Diff line
@@ -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);