Skip to contentSkip to conversation

Add ACPI power button emulation

PATCH In review Gleb Natapov 2 participants 3 messages Apr 30, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add ACPI power button emulation

hw/acpi.c +9 -0
index 53c1fec..6141522 100644
@@ -752,6 +752,15 @@ void qemu_system_device_hot_add(int bus, int slot, int state)
     }
 }
 
+void qemu_press_power_button(void)
+{
+    gpe.sts |= (1 << 8);
+    if (gpe.en & (1 << 8)) {
+        qemu_set_irq(pm_state->irq, 1);
+        qemu_set_irq(pm_state->irq, 0);
+    }
+}
+
 struct acpi_table_header
 {
     char signature [4];    /* ACPI signature (4 ASCII characters) */
monitor.c +6 -0
index b33fea1..35202aa 100644
@@ -1211,6 +1211,11 @@ static void do_system_reset(Monitor *mon)
     qemu_system_reset_request();
 }
 
+static void do_press_pwrb(Monitor *mon)
+{
+    qemu_press_power_button();
+}
+
 static void do_system_powerdown(Monitor *mon)
 {
     qemu_system_powerdown_request();
@@ -1733,6 +1738,7 @@ static const mon_cmd_t mon_cmds[] = {
 #if defined(TARGET_I386)
     { "nmi", "i", do_inject_nmi,
       "cpu", "inject an NMI on the given CPU", },
+    { "press_power_button", "", do_press_pwrb, "", "press power button" },
 #endif
     { "migrate", "-ds", do_migrate,
       "[-d] uri", "migrate to URI (using -d to not wait for completion)" },
pc-bios/bios-pq/0015_add-power_button_aml_object.patch new file +27 -0
new file mode 100644
index 0000000..7477b71
@@ -0,0 +1,27 @@
+Add power button device object to AML.
+
+diff --git a/bios/acpi-dsdt.dsl b/bios/acpi-dsdt.dsl
+index 7bff30a..0ca129d 100644
+--- a/bios/acpi-dsdt.dsl
++++ b/bios/acpi-dsdt.dsl
+@@ -38,6 +38,11 @@ DefinitionBlock (
+ 
+     /* PCI Bus definition */
+     Scope(\_SB) {
++        Device (PWRB) {
++            Name (_HID, EisaId ("PNP0C0C"))
++            Name (_STA, 0x0B)
++        }
++
+         Device(PCI0) {
+             Name (_HID, EisaId ("PNP0A03"))
+             Name (_ADR, 0x00)
+@@ -724,7 +729,7 @@ DefinitionBlock (
+             Return(0x01)
+         }
+         Method(_L08) {
+-            Return(0x01)
++            Notify(\_SB.PWRB, 0x80)
+         }
+         Method(_L09) {
+             Return(0x01)
pc-bios/bios-pq/series +1 -0
index fdef179..85e587e 100644
@@ -12,3 +12,4 @@
 0012-load-smbios-entries-and-files-from-qemu.patch
 0013_fix-non-acpi-timer-interrupt-routing.patch
 0014_add-srat-acpi-table-support.patch
+015_add-power_button_aml_object.patch
sysemu.h +2 -0
index 50438a6..a8abb3c 100644
@@ -38,6 +38,8 @@ void qemu_system_powerdown_request(void);
 int qemu_shutdown_requested(void);
 int qemu_reset_requested(void);
 int qemu_powerdown_requested(void);
+void qemu_press_power_button(void);
+
 #if !defined(TARGET_SPARC) && !defined(TARGET_I386)
 // Please implement a power failure function to signal the OS
 #define qemu_system_powerdown() do{}while(0)

--
Gleb.

#1 lore raw
Quoted 38 lines · Gleb Natapov
hw/acpi.c +9 -0
index 53c1fec..6141522 100644
@@ -752,6 +752,15 @@ void qemu_system_device_hot_add(int bus, int slot, int state)
     }
 }
 
+void qemu_press_power_button(void)
+{
+    gpe.sts |= (1 << 8);
+    if (gpe.en & (1 << 8)) {
+        qemu_set_irq(pm_state->irq, 1);
+        qemu_set_irq(pm_state->irq, 0);
+    }
+}
+
 struct acpi_table_header
 {
     char signature [4];    /* ACPI signature (4 ASCII characters) */
monitor.c +5 -0
index b33fea1..35202aa 100644
@@ -1211,6 +1211,11 @@ static void do_system_reset(Monitor *mon)
     qemu_system_reset_request();
 }
 
+static void do_press_pwrb(Monitor *mon)
+{
+    qemu_press_power_button();
+}
+
 static void do_system_powerdown(Monitor *mon)
 {
     qemu_system_powerdown_request();

monitor.c static const mon_cmd_t mon_cmds[] = { · line 1741

Quoted 4 lines
monitor.c +1 -0
@@ -1733,6 +1738,7 @@ static const mon_cmd_t mon_cmds[] = {
 #if defined(TARGET_I386)
     { "nmi", "i", do_inject_nmi,
       "cpu", "inject an NMI on the given CPU", },
+    { "press_power_button", "", do_press_pwrb, "", "press power button" },

Dumb question: Why do we need a new monitor command? In qemu-kvm, I can currently issue a power button event via system_powerdown (while this command has currently no effect in qemu). Why not reuse it? Or what is the job of system_powerdown when ACPI is present?

Quoted 59 lines
monitor.c +0 -0
 #endif
     { "migrate", "-ds", do_migrate,
       "[-d] uri", "migrate to URI (using -d to not wait for completion)" },
pc-bios/bios-pq/0015_add-power_button_aml_object.patch new file +27 -0
new file mode 100644
index 0000000..7477b71
@@ -0,0 +1,27 @@
+Add power button device object to AML.
+
+diff --git a/bios/acpi-dsdt.dsl b/bios/acpi-dsdt.dsl
+index 7bff30a..0ca129d 100644
+--- a/bios/acpi-dsdt.dsl
++++ b/bios/acpi-dsdt.dsl
+@@ -38,6 +38,11 @@ DefinitionBlock (
+ 
+     /* PCI Bus definition */
+     Scope(\_SB) {
++        Device (PWRB) {
++            Name (_HID, EisaId ("PNP0C0C"))
++            Name (_STA, 0x0B)
++        }
++
+         Device(PCI0) {
+             Name (_HID, EisaId ("PNP0A03"))
+             Name (_ADR, 0x00)
+@@ -724,7 +729,7 @@ DefinitionBlock (
+             Return(0x01)
+         }
+         Method(_L08) {
+-            Return(0x01)
++            Notify(\_SB.PWRB, 0x80)
+         }
+         Method(_L09) {
+             Return(0x01)
pc-bios/bios-pq/series +1 -0
index fdef179..85e587e 100644
@@ -12,3 +12,4 @@
 0012-load-smbios-entries-and-files-from-qemu.patch
 0013_fix-non-acpi-timer-interrupt-routing.patch
 0014_add-srat-acpi-table-support.patch
+015_add-power_button_aml_object.patch
sysemu.h +2 -1
index 50438a6..a8abb3c 100644
@@ -38,6 +38,8 @@ void qemu_system_powerdown_request(void);
 int qemu_shutdown_requested(void);
 int qemu_reset_requested(void);
 int qemu_powerdown_requested(void);
+void qemu_press_power_button(void);
+
 #if !defined(TARGET_SPARC) && !defined(TARGET_I386)
 // Please implement a power failure function to signal the OS
 #define qemu_system_powerdown() do{}while(0)
--
Quoted 2 lines

Gleb.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux
#2 lore raw
Quoted 40 lines · Jan Kiszka
Quoted 39 lines · Gleb Natapov
hw/acpi.c +9 -0
index 53c1fec..6141522 100644
@@ -752,6 +752,15 @@ void qemu_system_device_hot_add(int bus, int slot, int state)
     }
 }
 
+void qemu_press_power_button(void)
+{
+    gpe.sts |= (1 << 8);
+    if (gpe.en & (1 << 8)) {
+        qemu_set_irq(pm_state->irq, 1);
+        qemu_set_irq(pm_state->irq, 0);
+    }
+}
+
 struct acpi_table_header
 {
     char signature [4];    /* ACPI signature (4 ASCII characters) */
monitor.c +5 -0
index b33fea1..35202aa 100644
@@ -1211,6 +1211,11 @@ static void do_system_reset(Monitor *mon)
     qemu_system_reset_request();
 }
 
+static void do_press_pwrb(Monitor *mon)
+{
+    qemu_press_power_button();
+}
+
 static void do_system_powerdown(Monitor *mon)
 {
     qemu_system_powerdown_request();
@@ -1733,6 +1738,7 @@ static const mon_cmd_t mon_cmds[] = {
 #if defined(TARGET_I386)
Quoted 9 lines

monitor.c static const mon_cmd_t mon_cmds[] = { · line 1741

Quoted 3 lines
monitor.c +1 -0
     { "nmi", "i", do_inject_nmi,
       "cpu", "inject an NMI on the given CPU", },
+    { "press_power_button", "", do_press_pwrb, "", "press power button" },

Dumb question: Why do we need a new monitor command? In qemu-kvm, I can currently issue a power button event via system_powerdown (while this command has currently no effect in qemu). Why not reuse it? Or what is the job of system_powerdown when ACPI is present?

Actually this is not a dump question :) If there is no advantage to use ACPI for power button (and I don't know if there is) better leave it as is. And patch bellow should make system_powerdown work on qemu too.

Enable power button even generation.

pc-bios/bios-pq/0015_enable-power-button-even-generation.patch new file +17 -0
new file mode 100644
index 0000000..96cc2b2
@@ -0,0 +1,17 @@
+Enable power button event generation.
+
+diff --git a/bios/rombios32.c b/bios/rombios32.c
+index 81e3bad..9986531 100644
+--- a/bios/rombios32.c
++++ b/bios/rombios32.c
+@@ -1767,8 +1767,8 @@ void acpi_bios_init(void)
+     fadt->plvl3_lat = cpu_to_le16(0xfff); // C3 state not supported
+     fadt->gpe0_blk = cpu_to_le32(0xafe0);
+     fadt->gpe0_blk_len = 4;
+-    /* WBINVD + PROC_C1 + PWR_BUTTON + SLP_BUTTON + FIX_RTC */
+-    fadt->flags = cpu_to_le32((1 << 0) | (1 << 2) | (1 << 4) | (1 << 5) | (1 << 6));
++    /* WBINVD + PROC_C1 + SLP_BUTTON + FIX_RTC */
++    fadt->flags = cpu_to_le32((1 << 0) | (1 << 2) | (1 << 5) | (1 << 6));
+     acpi_build_table_header((struct acpi_table_header *)fadt, "FACP",
+                             sizeof(*fadt), 1);
+ 
pc-bios/bios-pq/series +1 -0
index fdef179..aa5a375 100644
@@ -12,3 +12,4 @@
 0012-load-smbios-entries-and-files-from-qemu.patch
 0013_fix-non-acpi-timer-interrupt-routing.patch
 0014_add-srat-acpi-table-support.patch
+0015_enable-power-button-even-generation.patch

--
Gleb.