From patchwork Wed Mar 16 09:29:34 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isaku Yamahata X-Patchwork-Id: 87206 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 B9AFAB6FF4 for ; Wed, 16 Mar 2011 20:59:05 +1100 (EST) Received: from localhost ([127.0.0.1]:42022 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PznVJ-0002Gz-2B for incoming@patchwork.ozlabs.org; Wed, 16 Mar 2011 05:58:57 -0400 Received: from [140.186.70.92] (port=34503 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pzn38-0006Ic-Cx for qemu-devel@nongnu.org; Wed, 16 Mar 2011 05:29:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Pzn30-0006DW-Mi for qemu-devel@nongnu.org; Wed, 16 Mar 2011 05:29:49 -0400 Received: from mail.valinux.co.jp ([210.128.90.3]:37354) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Pzn30-0006BQ-0g for qemu-devel@nongnu.org; Wed, 16 Mar 2011 05:29:42 -0400 Received: from ps.local.valinux.co.jp (vagw.valinux.co.jp [210.128.90.14]) by mail.valinux.co.jp (Postfix) with SMTP id C149E18935; Wed, 16 Mar 2011 18:29:40 +0900 (JST) Received: (nullmailer pid 18381 invoked by uid 1000); Wed, 16 Mar 2011 09:29:37 -0000 From: Isaku Yamahata To: qemu-devel@nongnu.org Date: Wed, 16 Mar 2011 18:29:34 +0900 Message-Id: <26b906b75fa50c61b94571dde15d9935c7a76297.1300266238.git.yamahata@valinux.co.jp> X-Mailer: git-send-email 1.7.1.1 In-Reply-To: References: In-Reply-To: References: X-Virus-Scanned: clamav-milter 0.95.2 at va-mail.local.valinux.co.jp X-Virus-Status: Clean X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 210.128.90.3 Cc: yamahata@valinux.co.jp Subject: [Qemu-devel] [PATCH 23/26] acpi, acpi_piix: factor out PM1_CNT logic 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 factor out ACPI PM1_CNT logic. This will be used by ich9 acpi. Signed-off-by: Isaku Yamahata --- hw/acpi.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ hw/acpi.h | 14 ++++++++++++++ hw/acpi_piix4.c | 40 ++++++---------------------------------- 3 files changed, 69 insertions(+), 34 deletions(-) diff --git a/hw/acpi.c b/hw/acpi.c index 158f30d..24c878a 100644 --- a/hw/acpi.c +++ b/hw/acpi.c @@ -299,3 +299,52 @@ void acpi_pm_tmr_reset(ACPIPMTimer *tmr) tmr->overflow_time = 0; qemu_del_timer(tmr->timer); } + +/* ACPI PM1aCNT */ +void acpi_pm1_cnt_init(ACPIPM1CNT *pm1_cnt, qemu_irq cmos_s3) +{ + pm1_cnt->cmos_s3 = cmos_s3; +} + +void acpi_pm1_cnt_write(ACPIPM1EVT *pm1a, ACPIPM1CNT *pm1_cnt, uint16_t val) +{ + pm1_cnt->cnt = val & ~(ACPI_BITMASK_SLEEP_ENABLE); + + if (val & ACPI_BITMASK_SLEEP_ENABLE) { + /* change suspend type */ + uint16_t sus_typ = (val >> 10) & 7; + switch(sus_typ) { + case 0: /* soft power off */ + qemu_system_shutdown_request(); + break; + case 1: + /* ACPI_BITMASK_WAKE_STATUS should be set on resume. + Pretend that resume was caused by power button */ + pm1a->sts |= + (ACPI_BITMASK_WAKE_STATUS | ACPI_BITMASK_POWER_BUTTON_STATUS); + qemu_system_reset_request(); + qemu_irq_raise(pm1_cnt->cmos_s3); + default: + break; + } + } +} + +void acpi_pm1_cnt_update(ACPIPM1CNT *pm1_cnt, + bool sci_enable, bool sci_disable) +{ + /* ACPI specs 3.0, 4.7.2.5 */ + if (sci_enable) { + pm1_cnt->cnt |= ACPI_BITMASK_SCI_ENABLE; + } else if (sci_disable) { + pm1_cnt->cnt &= ~ACPI_BITMASK_SCI_ENABLE; + } +} + +void acpi_pm1_cnt_reset(ACPIPM1CNT *pm1_cnt) +{ + pm1_cnt->cnt = 0; + if (pm1_cnt->cmos_s3) { + qemu_irq_lower(pm1_cnt->cmos_s3); + } +} diff --git a/hw/acpi.h b/hw/acpi.h index f79939f..ab70c00 100644 --- a/hw/acpi.h +++ b/hw/acpi.h @@ -112,4 +112,18 @@ void acpi_pm1_evt_write_sts(ACPIPM1EVT *pm1, ACPIPMTimer *tmr, uint16_t val); void acpi_pm1_evt_power_down(ACPIPM1EVT *pm1, ACPIPMTimer *tmr); void acpi_pm1_evt_reset(ACPIPM1EVT *pm1); +/* PM1a_CNT: piix and ich9 don't implement PM1b CNT. */ +struct ACPIPM1CNT { + uint16_t cnt; + + qemu_irq cmos_s3; +}; +typedef struct ACPIPM1CNT ACPIPM1CNT; + +void acpi_pm1_cnt_init(ACPIPM1CNT *pm1_cnt, qemu_irq cmos_s3); +void acpi_pm1_cnt_write(ACPIPM1EVT *pm1a, ACPIPM1CNT *pm1_cnt, uint16_t val); +void acpi_pm1_cnt_update(ACPIPM1CNT *pm1_cnt, + bool sci_enable, bool sci_disable); +void acpi_pm1_cnt_reset(ACPIPM1CNT *pm1_cnt); + #endif /* !QEMU_HW_ACPI_H */ diff --git a/hw/acpi_piix4.c b/hw/acpi_piix4.c index 5b4eef5..ce86ee3 100644 --- a/hw/acpi_piix4.c +++ b/hw/acpi_piix4.c @@ -55,7 +55,7 @@ typedef struct PIIX4PMState { PCIDevice dev; IORange ioport; ACPIPM1EVT pm1a; - uint16_t pmcntrl; + ACPIPM1CNT pm1_cnt; APMState apm; @@ -65,7 +65,6 @@ typedef struct PIIX4PMState { uint32_t smb_io_base; qemu_irq irq; - qemu_irq cmos_s3; qemu_irq smi_irq; int kvm_enabled; @@ -124,30 +123,7 @@ static void pm_ioport_write(IORange *ioport, uint64_t addr, unsigned width, pm_update_sci(s); break; case 0x04: - { - int sus_typ; - s->pmcntrl = val & ~(ACPI_BITMASK_SLEEP_ENABLE); - if (val & ACPI_BITMASK_SLEEP_ENABLE) { - /* change suspend type */ - sus_typ = (val >> 10) & 7; - switch(sus_typ) { - case 0: /* soft power off */ - qemu_system_shutdown_request(); - break; - case 1: - /* ACPI_BITMASK_WAKE_STATUS should be set on resume. - Pretend that resume was caused by power button */ - s->pm1a.sts |= (ACPI_BITMASK_WAKE_STATUS | - ACPI_BITMASK_POWER_BUTTON_STATUS); - qemu_system_reset_request(); - if (s->cmos_s3) { - qemu_irq_raise(s->cmos_s3); - } - default: - break; - } - } - } + acpi_pm1_cnt_write(&s->pm1a, &s->pm1_cnt, val); break; default: break; @@ -169,7 +145,7 @@ static void pm_ioport_read(IORange *ioport, uint64_t addr, unsigned width, val = s->pm1a.en; break; case 0x04: - val = s->pmcntrl; + val = s->pm1_cnt.cnt; break; case 0x08: val = acpi_pm_tmr_get(&s->tmr); @@ -192,11 +168,7 @@ static void apm_ctrl_changed(uint32_t val, void *arg) PIIX4PMState *s = arg; /* ACPI specs 3.0, 4.7.2.5 */ - if (val == ACPI_ENABLE) { - s->pmcntrl |= ACPI_BITMASK_SCI_ENABLE; - } else if (val == ACPI_DISABLE) { - s->pmcntrl &= ~ACPI_BITMASK_SCI_ENABLE; - } + acpi_pm1_cnt_update(&s->pm1_cnt, val == ACPI_ENABLE, val == ACPI_DISABLE); if (s->dev.config[0x5b] & (1 << 1)) { if (s->smi_irq) { @@ -275,7 +247,7 @@ static const VMStateDescription vmstate_acpi = { VMSTATE_PCI_DEVICE(dev, PIIX4PMState), VMSTATE_UINT16(pm1a.sts, PIIX4PMState), VMSTATE_UINT16(pm1a.en, PIIX4PMState), - VMSTATE_UINT16(pmcntrl, PIIX4PMState), + VMSTATE_UINT16(pm1_cnt.cnt, PIIX4PMState), VMSTATE_STRUCT(apm, PIIX4PMState, 0, vmstate_apm, APMState), VMSTATE_TIMER(tmr.timer, PIIX4PMState), VMSTATE_INT64(tmr.overflow_time, PIIX4PMState), @@ -395,7 +367,7 @@ i2c_bus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base, s = DO_UPCAST(PIIX4PMState, dev, dev); s->irq = sci_irq; - s->cmos_s3 = cmos_s3; + acpi_pm1_cnt_init(&s->pm1_cnt, cmos_s3); s->smi_irq = smi_irq; s->kvm_enabled = kvm_enabled;