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: Thu, 9 Jul 2009 17:13:06 +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 c67bf0b..356d5bc 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)
@@ -392,6 +392,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;
@@ -576,6 +577,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 {
@@ -1328,6 +1330,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 */
@@ -1407,6 +1410,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;
@@ -1553,6 +1557,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 40f0c59..903613e 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)
 {
 }
 
@@ -533,6 +533,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 06dc4c6..03a71eb 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -45,14 +45,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 7b7489c..71a42da 100644
--- a/vl.c
+++ b/vl.c
@@ -3620,6 +3620,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)
 {
@@ -3712,6 +3714,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]