From patchwork Tue Jan 5 06:27:26 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isaku Yamahata X-Patchwork-Id: 42193 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id A9ABDB6EED for ; Wed, 6 Jan 2010 08:25:34 +1100 (EST) Received: from localhost ([127.0.0.1]:41091 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NSGuA-00034t-QP for incoming@patchwork.ozlabs.org; Tue, 05 Jan 2010 16:25:30 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NSFPx-0007YD-32 for qemu-devel@nongnu.org; Tue, 05 Jan 2010 14:50:13 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NSFPr-0007UT-Vt for qemu-devel@nongnu.org; Tue, 05 Jan 2010 14:50:12 -0500 Received: from [199.232.76.173] (port=40922 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NSFPr-0007U9-On for qemu-devel@nongnu.org; Tue, 05 Jan 2010 14:50:07 -0500 Received: from mx20.gnu.org ([199.232.41.8]:36255) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1NSFPr-0003Ef-8u for qemu-devel@nongnu.org; Tue, 05 Jan 2010 14:50:07 -0500 Received: from mail.valinux.co.jp ([210.128.90.3]) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NS2uU-0003p6-Si for qemu-devel@nongnu.org; Tue, 05 Jan 2010 01:28:55 -0500 Received: from ps.local.valinux.co.jp (vagw.valinux.co.jp [210.128.90.14]) by mail.valinux.co.jp (Postfix) with SMTP id 591D718296; Tue, 5 Jan 2010 15:27:46 +0900 (JST) Received: (nullmailer pid 22650 invoked by uid 1000); Tue, 05 Jan 2010 06:27:50 -0000 From: Isaku Yamahata To: qemu-devel@nongnu.org, kraxel@redhat.com Date: Tue, 5 Jan 2010 15:27:26 +0900 Message-Id: <1262672870-22607-4-git-send-email-yamahata@valinux.co.jp> X-Mailer: git-send-email 1.6.5.4 In-Reply-To: <1262672870-22607-1-git-send-email-yamahata@valinux.co.jp> References: <1262672870-22607-1-git-send-email-yamahata@valinux.co.jp> X-Virus-Scanned: clamav-milter 0.95.2 at va-mail.local.valinux.co.jp X-Virus-Status: Clean X-detected-operating-system: by mx20.gnu.org: GNU/Linux 2.6 (newer, 3) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Cc: yamahata@valinux.co.jp Subject: [Qemu-devel] [PATCH V11 03/27] acpi: add acpi constants from linux header files and use them. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- 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 0e2f576..b83f8e6 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 + * 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 */