qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [PATCH 05/18] acpi: add acpi constants from linux header fi


From: Isaku Yamahata
Subject: [Qemu-devel] [PATCH 05/18] acpi: add acpi constants from linux header files and use them.
Date: Thu, 18 Jun 2009 19:57:04 +0900

add acpi constants from linux header files and
replace the old constants with them.
The acpi constants will be used by other file.

Signed-off-by: Isaku Yamahata <address@hidden>
---
 hw/acpi.c |   55 ++++++++++++++++++++++++-------------------------------
 hw/acpi.h |   56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 80 insertions(+), 31 deletions(-)

diff --git a/hw/acpi.c b/hw/acpi.c
index 66cc4b2..4d0690e 100644
--- a/hw/acpi.c
+++ b/hw/acpi.c
@@ -29,9 +29,6 @@
 
 //#define DEBUG
 
-/* i82731AB (PIIX4) compatible power management function */
-#define PM_FREQ 3579545
-
 #define ACPI_DBG_IO_ADDR  0xb044
 
 typedef struct PIIX4PMState {
@@ -50,17 +47,6 @@ typedef struct PIIX4PMState {
     qemu_irq irq;
 } PIIX4PMState;
 
-#define RSM_STS (1 << 15)
-#define PWRBTN_STS (1 << 8)
-#define RTC_EN (1 << 10)
-#define PWRBTN_EN (1 << 8)
-#define GBL_EN (1 << 5)
-#define TMROF_EN (1 << 0)
-
-#define SCI_EN (1 << 0)
-
-#define SUS_EN (1 << 13)
-
 #define ACPI_ENABLE 0xf1
 #define ACPI_DISABLE 0xf0
 
@@ -69,7 +55,7 @@ static PIIX4PMState *pm_state;
 static uint32_t get_pmtmr(PIIX4PMState *s)
 {
     uint32_t d;
-    d = muldiv64(qemu_get_clock(vm_clock), PM_FREQ, ticks_per_sec);
+    d = muldiv64(qemu_get_clock(vm_clock), PM_TIMER_FREQUENCY, ticks_per_sec);
     return d & 0xffffff;
 }
 
@@ -78,9 +64,9 @@ static int get_pmsts(PIIX4PMState *s)
     int64_t d;
     int pmsts;
     pmsts = s->pmsts;
-    d = muldiv64(qemu_get_clock(vm_clock), PM_FREQ, ticks_per_sec);
+    d = muldiv64(qemu_get_clock(vm_clock), PM_TIMER_FREQUENCY, ticks_per_sec);
     if (d >= s->tmr_overflow_time)
-        s->pmsts |= TMROF_EN;
+        s->pmsts |= ACPI_BITMASK_TIMER_STATUS;
     return s->pmsts;
 }
 
@@ -91,11 +77,16 @@ static void pm_update_sci(PIIX4PMState *s)
 
     pmsts = get_pmsts(s);
     sci_level = (((pmsts & s->pmen) &
-                  (RTC_EN | PWRBTN_EN | GBL_EN | TMROF_EN)) != 0);
+                  (ACPI_BITMASK_RT_CLOCK_ENABLE |
+                   ACPI_BITMASK_POWER_BUTTON_ENABLE |
+                   ACPI_BITMASK_GLOBAL_LOCK_ENABLE |
+                   ACPI_BITMASK_TIMER_ENABLE)) != 0);
     qemu_set_irq(s->irq, sci_level);
     /* schedule a timer interruption if needed */
-    if ((s->pmen & TMROF_EN) && !(pmsts & TMROF_EN)) {
-        expire_time = muldiv64(s->tmr_overflow_time, ticks_per_sec, PM_FREQ);
+    if ((s->pmen & ACPI_BITMASK_TIMER_ENABLE) &&
+        !(pmsts & ACPI_BITMASK_TIMER_STATUS)) {
+        expire_time = muldiv64(s->tmr_overflow_time, ticks_per_sec,
+                               PM_TIMER_FREQUENCY);
         qemu_mod_timer(s->tmr_timer, expire_time);
     } else {
         qemu_del_timer(s->tmr_timer);
@@ -118,9 +109,10 @@ static void pm_ioport_writew(void *opaque, uint32_t addr, 
uint32_t val)
             int64_t d;
             int pmsts;
             pmsts = get_pmsts(s);
-            if (pmsts & val & TMROF_EN) {
+            if (pmsts & val & ACPI_BITMASK_TIMER_STATUS) {
                 /* if TMRSTS is reset, then compute the new overflow time */
-                d = muldiv64(qemu_get_clock(vm_clock), PM_FREQ, ticks_per_sec);
+                d = muldiv64(qemu_get_clock(vm_clock), PM_TIMER_FREQUENCY,
+                             ticks_per_sec);
                 s->tmr_overflow_time = (d + 0x800000LL) & ~0x7fffffLL;
             }
             s->pmsts &= ~val;
@@ -134,8 +126,8 @@ static void pm_ioport_writew(void *opaque, uint32_t addr, 
uint32_t val)
     case 0x04:
         {
             int sus_typ;
-            s->pmcntrl = val & ~(SUS_EN);
-            if (val & SUS_EN) {
+            s->pmcntrl = val & ~(ACPI_BITMASK_SLEEP_ENABLE);
+            if (val & ACPI_BITMASK_SLEEP_ENABLE) {
                 /* change suspend type */
                 sus_typ = (val >> 10) & 7;
                 switch(sus_typ) {
@@ -143,9 +135,10 @@ static void pm_ioport_writew(void *opaque, uint32_t addr, 
uint32_t val)
                     qemu_system_shutdown_request();
                     break;
                 case 1:
-                    /* RSM_STS should be set on resume. Pretend that resume
-                       was caused by power button */
-                    s->pmsts |= (RSM_STS | PWRBTN_STS);
+                    /* ACPI_BITMASK_WAKE_STATUS should be set on resume.
+                       Pretend that resume was caused by power button */
+                    s->pmsts |= (ACPI_BITMASK_WAKE_STATUS |
+                                 ACPI_BITMASK_POWER_BUTTON_STATUS);
                     qemu_system_reset_request();
 #if defined(TARGET_I386)
                     cmos_set_s3_resume();
@@ -225,9 +218,9 @@ static void apm_ctrl_changed(uint32_t val, void *arg)
 
     /* ACPI specs 3.0, 4.7.2.5 */
     if (val == ACPI_ENABLE) {
-        s->pmcntrl |= SCI_EN;
+        s->pmcntrl |= ACPI_BITMASK_SCI_ENABLE;
     } else if (val == ACPI_DISABLE) {
-        s->pmcntrl &= ~SCI_EN;
+        s->pmcntrl &= ~ACPI_BITMASK_SCI_ENABLE;
     }
 
     if (s->dev.config[0x5b] & (1 << 1)) {
@@ -328,8 +321,8 @@ static void piix4_pm_powerdown(void *arg)
 {
     PIIX4PMState *pm_state = (PIIX4PMState*) arg;
 
-    if (pm_state->pmen & PWRBTN_EN) {
-        pm_state->pmsts |= PWRBTN_EN;
+    if (pm_state->pmen & ACPI_BITMASK_POWER_BUTTON_ENABLE) {
+        pm_state->pmsts |= ACPI_BITMASK_POWER_BUTTON_STATUS;
         pm_update_sci(pm_state);
     }
 }
diff --git a/hw/acpi.h b/hw/acpi.h
index 884512c..d686b50 100644
--- a/hw/acpi.h
+++ b/hw/acpi.h
@@ -26,4 +26,60 @@ void qemu_system_powerdown_register(qemu_powerdown_t 
callback, void *arg);
 #define qemu_system_powerdown_register(callback, arg)   do { } while (0)
 #endif
 
+/* from linux include/acpi/actype.h */
+/* Default ACPI register widths */
+
+#define ACPI_GPE_REGISTER_WIDTH         8
+#define ACPI_PM1_REGISTER_WIDTH         16
+#define ACPI_PM2_REGISTER_WIDTH         8
+#define ACPI_PM_TIMER_WIDTH             32
+
+/* PM Timer ticks per second (HZ) */
+#define PM_TIMER_FREQUENCY  3579545
+
+
+/* ACPI fixed hardware registers */
+
+/* from linux/drivers/acpi/acpica/aclocal.h */
+/* Masks used to access the bit_registers */
+
+/* PM1x_STS */
+#define ACPI_BITMASK_TIMER_STATUS               0x0001
+#define ACPI_BITMASK_BUS_MASTER_STATUS          0x0010
+#define ACPI_BITMASK_GLOBAL_LOCK_STATUS         0x0020
+#define ACPI_BITMASK_POWER_BUTTON_STATUS        0x0100
+#define ACPI_BITMASK_SLEEP_BUTTON_STATUS        0x0200
+#define ACPI_BITMASK_RT_CLOCK_STATUS            0x0400
+#define ACPI_BITMASK_PCIEXP_WAKE_STATUS         0x4000 /* ACPI 3.0 */
+#define ACPI_BITMASK_WAKE_STATUS                0x8000
+
+#define ACPI_BITMASK_ALL_FIXED_STATUS           (\
+       ACPI_BITMASK_TIMER_STATUS          | \
+       ACPI_BITMASK_BUS_MASTER_STATUS     | \
+       ACPI_BITMASK_GLOBAL_LOCK_STATUS    | \
+       ACPI_BITMASK_POWER_BUTTON_STATUS   | \
+       ACPI_BITMASK_SLEEP_BUTTON_STATUS   | \
+       ACPI_BITMASK_RT_CLOCK_STATUS       | \
+       ACPI_BITMASK_WAKE_STATUS)
+
+/* PM1x_EN */
+#define ACPI_BITMASK_TIMER_ENABLE               0x0001
+#define ACPI_BITMASK_GLOBAL_LOCK_ENABLE         0x0020
+#define ACPI_BITMASK_POWER_BUTTON_ENABLE        0x0100
+#define ACPI_BITMASK_SLEEP_BUTTON_ENABLE        0x0200
+#define ACPI_BITMASK_RT_CLOCK_ENABLE            0x0400
+#define ACPI_BITMASK_PCIEXP_WAKE_DISABLE        0x4000 /* ACPI 3.0 */
+
+/* PM1x_CNT */
+#define ACPI_BITMASK_SCI_ENABLE                 0x0001
+#define ACPI_BITMASK_BUS_MASTER_RLD             0x0002
+#define ACPI_BITMASK_GLOBAL_LOCK_RELEASE        0x0004
+#define ACPI_BITMASK_SLEEP_TYPE                 0x1C00
+#define ACPI_BITMASK_SLEEP_ENABLE               0x2000
+
+/* PM2_CNT */
+#define ACPI_BITMASK_ARB_DISABLE                0x0001
+
+/* PM_TMR */
+
 #endif /* !QEMU_HW_ACPI_H */
-- 
1.6.0.2





reply via email to

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