qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 03/17] acpi.c: make qemu_system_powerdown() piix ind


From: Isaku Yamahata
Subject: [Qemu-devel] [PATCH 03/17] acpi.c: make qemu_system_powerdown() piix independent.
Date: Wed, 15 Jul 2009 16:19:03 +0900

Make qemu_system_powerdown() piix independent by
registering callback function.
convert acpi, sun4m and sun4u to use it.

Signed-off-by: Isaku Yamahata <address@hidden>
Cc: Marcelo Tosatti <address@hidden>
---
 hw/acpi.c  |   25 +++++++++++++------------
 hw/sun4m.c |   13 +++++++++----
 hw/sun4u.c |    3 ++-
 sysemu.h   |   11 ++++-------
 vl.c       |   17 +++++++++++++++++
 5 files changed, 45 insertions(+), 24 deletions(-)

diff --git a/hw/acpi.c b/hw/acpi.c
index 7351947..904c5d7 100644
--- a/hw/acpi.c
+++ b/hw/acpi.c
@@ -323,6 +323,18 @@ static void piix4_reset(void *opaque)
     }
 }
 
+static void piix4_pm_powerdown(void *arg)
+{
+#if defined(TARGET_I386)
+    PIIX4PMState *pm_state = (PIIX4PMState*) arg;
+
+    if (pm_state->pmen & PWRBTN_EN) {
+        pm_state->pmsts |= PWRBTN_EN;
+        pm_update_sci(pm_state);
+    }
+#endif
+}
+
 i2c_bus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base,
                        qemu_irq sci_irq)
 {
@@ -377,22 +389,11 @@ i2c_bus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t 
smb_io_base,
     pc_smbus_init(&s->smb);
     s->irq = sci_irq;
     qemu_register_reset(piix4_reset, s);
+    qemu_system_powerdown_register(piix4_pm_powerdown, pm_state);
 
     return s->smb.smbus;
 }
 
-#if defined(TARGET_I386)
-void qemu_system_powerdown(void)
-{
-    if (!pm_state) {
-        qemu_system_shutdown_request();
-    } else if (pm_state->pmen & PWRBTN_EN) {
-        pm_state->pmsts |= PWRBTN_EN;
-       pm_update_sci(pm_state);
-    }
-}
-#endif
-
 #define GPE_BASE 0xafe0
 #define PCI_BASE 0xae00
 #define PCI_EJ_BASE 0xae08
diff --git a/hw/sun4m.c b/hw/sun4m.c
index 5953611..577b6ea 100644
--- a/hw/sun4m.c
+++ b/hw/sun4m.c
@@ -283,11 +283,11 @@ static void dummy_cpu_set_irq(void *opaque, int irq, int 
level)
 {
 }
 
-static void *slavio_misc;
-
-void qemu_system_powerdown(void)
+static void system_powerdown(void *slavio_misc)
 {
-    slavio_set_power_fail(slavio_misc, 1);
+    if (slavio_misc) {
+        slavio_set_power_fail(slavio_misc, 1);
+    }
 }
 
 static void main_cpu_reset(void *opaque)
@@ -391,6 +391,7 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef, 
ram_addr_t RAM_size,
     CPUState *env, *envs[MAX_CPUS];
     unsigned int i;
     void *iommu, *espdma, *ledma, *nvram;
+    void *slavio_misc;
     qemu_irq *cpu_irqs[MAX_CPUS], *slavio_irq, *slavio_cpu_irq,
         *espdma_irq, *ledma_irq;
     qemu_irq *esp_reset, *le_reset;
@@ -575,6 +576,7 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef, 
ram_addr_t RAM_size,
     fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, 0); // not used
     fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, boot_device[0]);
     qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
+    qemu_system_powerdown_register(&system_powerdown, slavio_misc);
 }
 
 enum {
@@ -1327,6 +1329,7 @@ static void sun4d_hw_init(const struct sun4d_hwdef 
*hwdef, ram_addr_t RAM_size,
     fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, 0); // not used
     fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, boot_device[0]);
     qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
+    qemu_system_powerdown_register(&system_powerdown, NULL);
 }
 
 /* SPARCserver 1000 hardware initialisation */
@@ -1406,6 +1409,7 @@ static void sun4c_hw_init(const struct sun4c_hwdef 
*hwdef, ram_addr_t RAM_size,
 {
     CPUState *env;
     void *iommu, *espdma, *ledma, *nvram;
+    void *slavio_misc;
     qemu_irq *cpu_irqs, *slavio_irq, *espdma_irq, *ledma_irq;
     qemu_irq *esp_reset, *le_reset;
     qemu_irq *fdc_tc;
@@ -1552,6 +1556,7 @@ static void sun4c_hw_init(const struct sun4c_hwdef 
*hwdef, ram_addr_t RAM_size,
     fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, 0); // not used
     fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, boot_device[0]);
     qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
+    qemu_system_powerdown_register(&system_powerdown, slavio_misc);
 }
 
 /* SPARCstation 2 hardware initialisation */
diff --git a/hw/sun4u.c b/hw/sun4u.c
index eb7737f..f5258a8 100644
--- a/hw/sun4u.c
+++ b/hw/sun4u.c
@@ -200,7 +200,7 @@ static void cpu_set_irq(void *opaque, int irq, int level)
     }
 }
 
-void qemu_system_powerdown(void)
+static void system_powerdown(void *unused)
 {
 }
 
@@ -527,6 +527,7 @@ static void sun4uv_init(ram_addr_t RAM_size,
     fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, initrd_size);
     fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, boot_devices[0]);
     qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
+    qemu_system_powerdown_register(&system_powerdown, NULL);
 }
 
 enum {
diff --git a/sysemu.h b/sysemu.h
index 4fedfd0..1f8f525 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -46,14 +46,11 @@ void qemu_system_powerdown_request(void);
 int qemu_shutdown_requested(void);
 int qemu_reset_requested(void);
 int qemu_powerdown_requested(void);
-#ifdef NEED_CPU_H
-#if !defined(TARGET_SPARC) && !defined(TARGET_I386)
-// Please implement a power failure function to signal the OS
-#define qemu_system_powerdown() do{}while(0)
-#else
+
+typedef void (*qemu_powerdown_t)(void *arg);
+void qemu_system_powerdown_register(qemu_powerdown_t callback, void *arg);
 void qemu_system_powerdown(void);
-#endif
-#endif
+
 void qemu_system_reset(void);
 
 void do_savevm(Monitor *mon, const char *name);
diff --git a/vl.c b/vl.c
index 8708337..514843d 100644
--- a/vl.c
+++ b/vl.c
@@ -3471,6 +3471,8 @@ static int shutdown_requested;
 static int powerdown_requested;
 static int debug_requested;
 static int vmstop_requested;
+static qemu_powerdown_t powerdown_callback;
+static void *powerdown_arg;
 
 int qemu_shutdown_requested(void)
 {
@@ -3571,6 +3573,21 @@ void qemu_system_powerdown_request(void)
     qemu_notify_event();
 }
 
+void qemu_system_powerdown_register(qemu_powerdown_t callback, void *arg)
+{
+    powerdown_callback = callback;
+    powerdown_arg = arg;
+}
+
+void qemu_system_powerdown(void)
+{
+    if (!powerdown_callback) {
+        qemu_system_shutdown_request();
+    } else {
+        powerdown_callback(powerdown_arg);
+    }
+}
+
 #ifdef CONFIG_IOTHREAD
 static void qemu_system_vmstop_request(int reason)
 {
-- 
1.6.0.2





reply via email to

[Prev in Thread] Current Thread [Next in Thread]