[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 03/61] acpi: add acpi constants from linux header fi
From: |
Isaku Yamahata |
Subject: |
[Qemu-devel] [PATCH 03/61] acpi: add acpi constants from linux header files and use them. |
Date: |
Wed, 30 Sep 2009 19:17:39 +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 | 56 +++++++++++++++++++------------------------
hw/acpi.h | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 103 insertions(+), 31 deletions(-)
create mode 100644 hw/acpi.h
diff --git a/hw/acpi.c b/hw/acpi.c
index 16b69c0..e88a83b 100644
--- a/hw/acpi.c
+++ b/hw/acpi.c
@@ -25,12 +25,10 @@
#include "i2c.h"
#include "smbus.h"
#include "kvm.h"
+#include "acpi.h"
//#define DEBUG
-/* i82731AB (PIIX4) compatible power management function */
-#define PM_FREQ 3579545
-
#define ACPI_DBG_IO_ADDR 0xb044
typedef struct PIIX4PMState {
@@ -49,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
@@ -68,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, get_ticks_per_sec());
+ d = muldiv64(qemu_get_clock(vm_clock), PM_TIMER_FREQUENCY,
get_ticks_per_sec());
return d & 0xffffff;
}
@@ -77,9 +64,10 @@ static int get_pmsts(PIIX4PMState *s)
int64_t d;
int pmsts;
pmsts = s->pmsts;
- d = muldiv64(qemu_get_clock(vm_clock), PM_FREQ, get_ticks_per_sec());
+ d = muldiv64(qemu_get_clock(vm_clock), PM_TIMER_FREQUENCY,
+ get_ticks_per_sec());
if (d >= s->tmr_overflow_time)
- s->pmsts |= TMROF_EN;
+ s->pmsts |= ACPI_BITMASK_TIMER_STATUS;
return s->pmsts;
}
@@ -90,11 +78,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, get_ticks_per_sec(),
PM_FREQ);
+ if ((s->pmen & ACPI_BITMASK_TIMER_ENABLE) &&
+ !(pmsts & ACPI_BITMASK_TIMER_STATUS)) {
+ expire_time = muldiv64(s->tmr_overflow_time, get_ticks_per_sec(),
+ PM_TIMER_FREQUENCY);
qemu_mod_timer(s->tmr_timer, expire_time);
} else {
qemu_del_timer(s->tmr_timer);
@@ -117,9 +110,9 @@ 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,
+ d = muldiv64(qemu_get_clock(vm_clock), PM_TIMER_FREQUENCY,
get_ticks_per_sec());
s->tmr_overflow_time = (d + 0x800000LL) & ~0x7fffffLL;
}
@@ -134,8 +127,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 +136,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 +219,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)) {
@@ -318,8 +312,8 @@ static void piix4_powerdown(void *opaque, int irq, int
power_failing)
if (!s) {
qemu_system_shutdown_request();
- } else if (s->pmen & PWRBTN_EN) {
- s->pmsts |= PWRBTN_EN;
+ } else if (s->pmen & ACPI_BITMASK_POWER_BUTTON_ENABLE) {
+ s->pmsts |= ACPI_BITMASK_POWER_BUTTON_STATUS;
pm_update_sci(s);
}
#endif
diff --git a/hw/acpi.h b/hw/acpi.h
new file mode 100644
index 0000000..51b56b6
--- /dev/null
+++ b/hw/acpi.h
@@ -0,0 +1,78 @@
+#ifndef QEMU_HW_ACPI_H
+#define QEMU_HW_ACPI_H
+/*
+ * Copyright (c) 2009 Isaku Yamahata <yamahata at valinux co jp>
+ * VA Linux Systems Japan K.K.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA
+ */
+
+/* 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
- [Qemu-devel] [PATCH 04/61] acpi: split acpi.c into the common part and the piix4 part., (continued)
- [Qemu-devel] [PATCH 04/61] acpi: split acpi.c into the common part and the piix4 part., Isaku Yamahata, 2009/09/30
- [Qemu-devel] [PATCH 28/61] pci: factor out while(bus) bus->next loop logic into pci_find_bus_from()., Isaku Yamahata, 2009/09/30
- [Qemu-devel] [PATCH 21/61] pci: introduce constant PCI_NUM_PINS for the number of interrupt pins, 4., Isaku Yamahata, 2009/09/30
- [Qemu-devel] [PATCH 17/61] pc: split out pci device init from pc_init1() into pc_pci_device_init(), Isaku Yamahata, 2009/09/30
- [Qemu-devel] [PATCH 15/61] pc: split out vga initialization from pc_init1() into pc_vga_init()., Isaku Yamahata, 2009/09/30
- [Qemu-devel] [PATCH 09/61] pc: remove a global variable, floppy_controller., Isaku Yamahata, 2009/09/30
- [Qemu-devel] [PATCH 59/61] ioapic: make irr accept more than 32 pins., Isaku Yamahata, 2009/09/30
- [Qemu-devel] [PATCH 16/61] pc: split out basic device init from pc_init1() into pc_basic_device_init(), Isaku Yamahata, 2009/09/30
- [Qemu-devel] [PATCH 14/61] pc: split out memory allocation from pc_init1() into pc_memory_init(), Isaku Yamahata, 2009/09/30
- [Qemu-devel] [PATCH 56/61] ioapic: clean up of #ifdef DEBUG_IOAPIC., Isaku Yamahata, 2009/09/30
- [Qemu-devel] [PATCH 03/61] acpi: add acpi constants from linux header files and use them.,
Isaku Yamahata <=
- [Qemu-devel] [PATCH 49/61] pci hot add: pass opaque argument to callback., Isaku Yamahata, 2009/09/30
- [Qemu-devel] [PATCH 01/61] acpi: split out pc smbus routines from acpi.c into pc_smbus.c, Isaku Yamahata, 2009/09/30
- [Qemu-devel] [PATCH 61/61] pc_q35: apic mode for pci interrupt routing., Isaku Yamahata, 2009/09/30
- [Qemu-devel] [PATCH 11/61] pc: introduce a function to allocate cpu irq., Isaku Yamahata, 2009/09/30
- [Qemu-devel] [PATCH 51/61] vmstate: add a macro for pointer to struct, VMSTATE_STRUCT_POINTER., Isaku Yamahata, 2009/09/30
- [Qemu-devel] [PATCH 54/61] pci: add opaque argument to pci_map_irq_fn()., Isaku Yamahata, 2009/09/30
- [Qemu-devel] [PATCH 30/61] pci_host.h: split non-inline static function in pci_host.h into pci_host_c.h, Isaku Yamahata, 2009/09/30
- [Qemu-devel] [PATCH 37/61] pci: add helper function for pci config write function to check address., Isaku Yamahata, 2009/09/30
- [Qemu-devel] [PATCH 36/61] pci: use QLIST_ macro instead of direct list manipulation., Isaku Yamahata, 2009/09/30