From patchwork Fri Oct 28 19:38:32 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Baboval X-Patchwork-Id: 122491 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 2CBF4B6F7F for ; Sat, 29 Oct 2011 06:38:53 +1100 (EST) Received: from localhost ([::1]:38257 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RJsGL-0007db-PU for incoming@patchwork.ozlabs.org; Fri, 28 Oct 2011 15:38:45 -0400 Received: from eggs.gnu.org ([140.186.70.92]:48435) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RJsGC-0007NG-B5 for qemu-devel@nongnu.org; Fri, 28 Oct 2011 15:38:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RJsGB-00034y-2q for qemu-devel@nongnu.org; Fri, 28 Oct 2011 15:38:36 -0400 Received: from server514c.exghost.com ([72.32.253.76]:2880 helo=server514.appriver.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RJsGA-00034u-S4 for qemu-devel@nongnu.org; Fri, 28 Oct 2011 15:38:35 -0400 X-Note-AR-ScanTimeLocal: 10/28/2011 2:38:34 PM X-Policy: GLOBAL - virtualcomputer.com X-Primary: john.baboval@virtualcomputer.com X-Note: This Email was scanned by AppRiver SecureTide X-ALLOW: @virtualcomputer.com ALLOWED X-Virus-Scan: V- X-Note: Spam Tests Failed: X-Country-Path: PRIVATE->UNITED STATES->UNITED STATES->UNITED STATES X-Note-Sending-IP: 72.32.253.65 X-Note-Reverse-DNS: X-Note-WHTLIST: john.baboval@virtualcomputer.com X-Note: User Rule Hits: X-Note: Global Rule Hits: G211 G212 G213 G214 G218 G219 G230 G320 X-Note: Encrypt Rule Hits: X-Note: Mail Class: ALLOWEDSENDER X-Note: Headers Injected Received: from [72.32.253.65] (HELO FE03.exg4.exghost.com) by server514.appriver.com (CommuniGate Pro SMTP 5.4.1) with ESMTP id 239869195 for qemu-devel@nongnu.org; Fri, 28 Oct 2011 14:38:34 -0500 Received: from FE03.exg4.exghost.com ([72.32.253.150]) by FE03.exg4.exghost.com with Microsoft SMTPSVC(6.0.3790.4675); Fri, 28 Oct 2011 14:38:34 -0500 Received: from [10.1.1.240] ([67.192.118.153]) by FE03.exg4.exghost.com with Microsoft SMTPSVC(6.0.3790.4675); Fri, 28 Oct 2011 14:38:33 -0500 Message-ID: <4EAB04B8.2030505@virtualcomputer.com> Date: Fri, 28 Oct 2011 15:38:32 -0400 From: John Baboval User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.17) Gecko/20110516 Thunderbird/3.1.10 MIME-Version: 1.0 To: qemu-devel@nongnu.org X-OriginalArrivalTime: 28 Oct 2011 19:38:33.0821 (UTC) FILETIME=[2DDA88D0:01CC95A9] X-detected-operating-system: by eggs.gnu.org: Windows 2000 SP4, XP SP1+ X-Received-From: 72.32.253.76 Subject: [Qemu-devel] [PATCH 3/3] piix4 acpi xen support X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org When in xen mode, handle the view of pm ioport appropriately. I'm not entirely comfortable with this patch, since it relies on values that are hard coded into the DSDT that is shipped with Xen. There has to be a better way to handle it, but I haven't thought of what that might be yet... Perhaps there should be an acpi_xen.c. Or perhaps the Xen table should be modified to match the device model. Or perhaps there is a good way to match them up dynamically. Signed-off-by: John V. Baboval Signed-off-by: Tom Goetz --- hw/acpi_piix4.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 73 insertions(+), 9 deletions(-) (unsigned)addr, width, (unsigned)val); } + if (xen_enabled()) { + /* + * Only the PM control register is emulated in Qemu under Xen. The + * remaining registers are emulated by the hypervisor. + */ + int sus_typ; + s->pm1_cnt.cnt = val & ~(ACPI_BITMASK_SLEEP_ENABLE); + if (val & ACPI_BITMASK_SLEEP_ENABLE) { + /* change suspend type */ + sus_typ = (val >> 10) & 7; + switch(sus_typ) { + case 6: /* soft power off */ + case 7: /* soft power off */ + qemu_system_shutdown_request(); + break; + case 5: + /* ACPI_BITMASK_WAKE_STATUS should be set on resume. + Pretend that resume was caused by power button */ + qemu_system_reset_request(); + if (s->pm1_cnt.cmos_s3) { + qemu_irq_raise(s->pm1_cnt.cmos_s3); + } + default: + break; + } + } + return; + } + switch(addr) { case 0x00: acpi_pm1_evt_write_sts(&s->pm1a, &s->tmr, val); @@ -136,6 +166,15 @@ static void pm_ioport_read(IORange *ioport, uint64_t addr, unsigned width, PIIX4PMState *s = container_of(ioport, PIIX4PMState, ioport); uint32_t val; + if (xen_enabled()) { + /* + * Only the PM control register is emulated in Qemu under Xen. The + * remaining registers are emulated by the hypervisor. + */ + val = s->pm1_cnt.cnt; + return; + } + switch(addr) { case 0x00: val = acpi_pm1_evt_get_sts(&s->pm1a, s->tmr.overflow_time); @@ -181,19 +220,28 @@ static void acpi_dbg_writel(void *opaque, uint32_t addr, uint32_t val) PIIX4_DPRINTF("ACPI: DBG: 0x%08x\n", val); } +#define PMCNTRL 0x04 static void pm_io_space_update(PIIX4PMState *s) { - uint32_t pm_io_base; + uint32_t pm_io_base, size; + + if (!(s->dev.config[0x80] & 1) && !xen_enabled()) { + return; + } - if (s->dev.config[0x80] & 1) { - pm_io_base = le32_to_cpu(*(uint32_t *)(s->dev.config + 0x40)); - pm_io_base &= 0xffc0; + pm_io_base = le32_to_cpu(*(uint32_t *)(s->dev.config + 0x40)); + pm_io_base &= 0xffc0; + size = 16; - /* XXX: need to improve memory and ioport allocation */ - PIIX4_DPRINTF("PM: mapping to 0x%x\n", pm_io_base); - iorange_init(&s->ioport, &pm_iorange_ops, pm_io_base, 64); - ioport_register(&s->ioport); + if (xen_enabled()) { + size = 2; + pm_io_base += PMCNTRL; } + + /* XXX: need to improve memory and ioport allocation */ + PIIX4_DPRINTF("PM: mapping to 0x%x\n", pm_io_base); + iorange_init(&s->ioport, &pm_iorange_ops, pm_io_base, size); + ioport_register(&s->ioport); } static void pm_write_config(PCIDevice *d, @@ -326,6 +374,13 @@ static void piix4_pm_machine_ready(Notifier *n, void *opaque) } +#define PIIX4_BASE_IOADDR 0x1f40 +#define PIIX4_BASE_IOADDR_LO ((PIIX4_BASE_IOADDR) & 0xff) +#define PIIX4_BASE_IOADDR_HI ((PIIX4_BASE_IOADDR)>>8) + +/* PM1a_CNT bits, as defined in the ACPI specification. */ +#define SCI_EN (1 << 0) + static int piix4_pm_initfn(PCIDevice *dev) { PIIX4PMState *s = DO_UPCAST(PIIX4PMState, dev, dev); @@ -337,7 +392,13 @@ static int piix4_pm_initfn(PCIDevice *dev) pci_conf[0x09] = 0x00; pci_conf[0x3d] = 0x01; // interrupt pin 1 - pci_conf[0x40] = 0x01; /* PM io base read only bit */ + if (!xen_enabled()) { + pci_conf[0x40] = 0x01; /* PM io base read only bit */ + } else { + pci_conf[0x40] = PIIX4_BASE_IOADDR_LO | 0x01; /* Special device-specific BAR at 0x40 */ + pci_conf[0x41] = PIIX4_BASE_IOADDR_HI; + s->pm1_cnt.cnt = SCI_EN; + } /* APM */ apm_init(&s->apm, apm_ctrl_changed, s); @@ -369,6 +430,9 @@ static int piix4_pm_initfn(PCIDevice *dev) qemu_register_reset(piix4_reset, s); piix4_acpi_system_hot_add_init(dev->bus, s); + if (xen_enabled()) + pm_io_space_update(s); + return 0; } -- 1.7.4.1 diff --git a/hw/acpi_piix4.c b/hw/acpi_piix4.c index 29f0f76..277ae9f 100644 --- a/hw/acpi_piix4.c +++ b/hw/acpi_piix4.c @@ -24,6 +24,7 @@ #include "sysemu.h" #include "range.h" #include "ioport.h" +#include "xen.h" //#define DEBUG @@ -111,6 +112,35 @@ static void pm_ioport_write(IORange *ioport, uint64_t addr, unsigned width,