diff mbox series

parisc: Add qemu power-off handler

Message ID ZSMlH4LkRTbOt8xr@p100 (mailing list archive)
State Accepted, archived
Headers show
Series parisc: Add qemu power-off handler | expand

Commit Message

Helge Deller Oct. 8, 2023, 9:54 p.m. UTC
When running on qemu, use the artificial "system halt" instruction
to power the system off.

Signed-off-by: Helge Deller <deller@gmx.de>
diff mbox series

Patch

diff --git a/arch/parisc/kernel/setup.c b/arch/parisc/kernel/setup.c
index 2f434f2da185..c934ec47d915 100644
--- a/arch/parisc/kernel/setup.c
+++ b/arch/parisc/kernel/setup.c
@@ -25,6 +25,7 @@ 
 #include <linux/sched.h>
 #include <linux/sched/clock.h>
 #include <linux/start_kernel.h>
+#include <linux/reboot.h>
 
 #include <asm/cacheflush.h>
 #include <asm/processor.h>
@@ -235,6 +236,13 @@  static int __init parisc_init_resources(void)
 	return 0;
 }
 
+static int qemu_power_off(struct sys_off_data *data)
+{
+	/* call qemu artificial "system halt" instruction */
+	asm volatile(".word 0xfffdead0": : :"memory");
+	return NOTIFY_DONE;
+}
+
 static int __init parisc_init(void)
 {
 	u32 osid = (OS_ID_LINUX << 16);
@@ -242,6 +250,11 @@  static int __init parisc_init(void)
 	parisc_init_resources();
 	do_device_inventory();                  /* probe for hardware */
 
+	/* register QEMU power off function */
+	if (running_on_qemu)
+		register_sys_off_handler(SYS_OFF_MODE_POWER_OFF,
+			SYS_OFF_PRIO_DEFAULT, qemu_power_off, NULL);
+
 	parisc_pdc_chassis_init();
 	
 	/* set up a new led state on systems shipped LED State panel */