[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] Re: [Qemu-devel] [PATCH 15/15] xen: Add a Xen specific ACPI Implementation to target-xen
On Thu, Aug 12, 2010 at 2:10 PM, <stefano.stabellini@xxxxxxxxxxxxx> wrote: > From: Anthony PERARD <anthony.perard@xxxxxxxxxx> > > Xen currently uses a different BIOS (hvmloader + rombios) therefore the > Qemu acpi_piix4 implementation wouldn't work correctly with Xen. > We plan on fixing this properly but at the moment we are just adding a > new Xen specific acpi_piix4 implementation. I'd suppose the proper fix is to modify acpi_piix4 instead of copy&paste. > This patch is optional; without it the VM boots but it cannot shutdown > properly or go to S3. > > Signed-off-by: Anthony PERARD <anthony.perard@xxxxxxxxxx> > Signed-off-by: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx> > --- > ÂMakefile.target   |  Â1 + > Âhw/xen_acpi_piix4.c | Â424 > +++++++++++++++++++++++++++++++++++++++++++++++++++ > Âhw/xen_common.h   |  Â3 + > Âhw/xen_machine_fv.c |  Â6 +- > Â4 files changed, 429 insertions(+), 5 deletions(-) > Âcreate mode 100644 hw/xen_acpi_piix4.c > > diff --git a/Makefile.target b/Makefile.target > index 1984cdd..a2d9217 100644 > --- a/Makefile.target > +++ b/Makefile.target > @@ -325,6 +325,7 @@ obj-xen-y += piix_pci.o > Âobj-xen-y += mc146818rtc.o > Âobj-xen-y += xenstore.o > Âobj-xen-y += xen_platform.o > +obj-xen-y += xen_acpi_piix4.o > > Âobj-xen-y += xen_mapcache.o > Âobj-xen-y += stub-functions.o > diff --git a/hw/xen_acpi_piix4.c b/hw/xen_acpi_piix4.c > new file mode 100644 > index 0000000..3c65963 > --- /dev/null > +++ b/hw/xen_acpi_piix4.c > @@ -0,0 +1,424 @@ > + /* > + * PIIX4 ACPI controller emulation > + * > + * Winston liwen Wang, winston.l.wang@xxxxxxxxx > + * Copyright (c) 2006 , Intel Corporation. > + * > + * Permission is hereby granted, free of charge, to any person obtaining a > copy > + * of this software and associated documentation files (the "Software"), to > deal > + * in the Software without restriction, including without limitation the > rights > + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell > + * copies of the Software, and to permit persons to whom the Software is > + * furnished to do so, subject to the following conditions: > + * > + * The above copyright notice and this permission notice shall be included in > + * all copies or substantial portions of the Software. > + * > + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR > + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, > + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL > + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER > + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING > FROM, > + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN > + * THE SOFTWARE. > + */ > + > +#include "hw.h" > +#include "pc.h" > +#include "pci.h" > +#include "sysemu.h" > +#include "acpi.h" > + > +#include "xen_backend.h" > +#include "xen_common.h" > +#include "qemu-log.h" > + > +#include <xen/hvm/ioreq.h> > +#include <xen/hvm/params.h> > + > +#define PIIX4ACPI_LOG_ERROR 0 > +#define PIIX4ACPI_LOG_INFO 1 > +#define PIIX4ACPI_LOG_DEBUG 2 > +#define PIIX4ACPI_LOGLEVEL PIIX4ACPI_LOG_INFO > +#define PIIX4ACPI_LOG(level, fmt, ...) do { if (level <= PIIX4ACPI_LOGLEVEL) > qemu_log(fmt, ## __VA_ARGS__); } while (0) > + > +/* Sleep state type codes as defined by the \_Sx objects in the DSDT. */ > +/* These must be kept in sync with the DSDT (hvmloader/acpi/dsdt.asl) */ > +#define SLP_TYP_S4    Â(6 << 10) > +#define SLP_TYP_S3    Â(5 << 10) > +#define SLP_TYP_S5    Â(7 << 10) > + > +#define ACPI_DBG_IO_ADDR Â0xb044 > +#define ACPI_PHP_IO_ADDR Â0x10c0 > + > +#define PHP_EVT_ADD   0x0 > +#define PHP_EVT_REMOVE Â0x3 > + > +/* The bit in GPE0_STS/EN to notify the pci hotplug event */ > +#define ACPI_PHP_GPE_BIT 3 > + > +#define DEVFN_TO_PHP_SLOT_REG(devfn) (devfn >> 1) > +#define PHP_SLOT_REG_TO_DEVFN(reg, hilo) ((reg << 1) | hilo) > + > +/* ioport to monitor cpu add/remove status */ > +#define PROC_BASE 0xaf00 > + > +typedef struct PCIAcpiState { > +  ÂPCIDevice dev; > +  Âuint16_t pm1_control; /* pm1a_ECNT_BLK */ > +  Âqemu_irq irq; > +  Âqemu_irq cmos_s3; > +} PCIAcpiState; > + > +typedef struct GPEState { > +  Â/* GPE0 block */ > +  Âuint8_t gpe0_sts[ACPI_GPE0_BLK_LEN / 2]; > +  Âuint8_t gpe0_en[ACPI_GPE0_BLK_LEN / 2]; > + > +  Â/* CPU bitmap */ > +  Âuint8_t cpus_sts[32]; > + > +  Â/* SCI IRQ level */ > +  Âuint8_t sci_asserted; > + > +} GPEState; > + > +static GPEState gpe_state; > + > +static qemu_irq sci_irq; > + > +typedef struct AcpiDeviceState AcpiDeviceState; > +AcpiDeviceState *acpi_device_table; > + > +static const VMStateDescription vmstate_acpi = { > +  Â.name = "PIIX4 ACPI", > +  Â.version_id = 1, > +  Â.fields   Â= (VMStateField []) { > +    ÂVMSTATE_PCI_DEVICE(dev, PCIAcpiState), > +    ÂVMSTATE_UINT16(pm1_control, PCIAcpiState), > +    ÂVMSTATE_END_OF_LIST() > +  Â} > +}; > + > +static void acpiPm1Control_writeb(void *opaque, uint32_t addr, uint32_t val) > +{ > +  ÂPCIAcpiState *s = opaque; > +  Âs->pm1_control = (s->pm1_control & 0xff00) | (val & 0xff); > +} > + > +static uint32_t acpiPm1Control_readb(void *opaque, uint32_t addr) > +{ > +  ÂPCIAcpiState *s = opaque; > +  Â/* Mask out the write-only bits */ > +  Âreturn (uint8_t)(s->pm1_control & > ~(ACPI_BITMASK_GLOBAL_LOCK_RELEASE|ACPI_BITMASK_SLEEP_ENABLE)); > +} > + > +static void acpi_shutdown(PCIAcpiState *s, uint32_t val) > +{ > +  Âif (!(val & ACPI_BITMASK_SLEEP_ENABLE)) > +    Âreturn; > + > +  Âswitch (val & ACPI_BITMASK_SLEEP_TYPE) { > +  Âcase SLP_TYP_S3: > +    Âqemu_system_reset(); > +    Âqemu_irq_raise(s->cmos_s3); > +    Âxc_set_hvm_param(xen_xc, xen_domid, HVM_PARAM_ACPI_S_STATE, 3); > +    Âbreak; > +  Âcase SLP_TYP_S4: > +  Âcase SLP_TYP_S5: > +    Âqemu_system_shutdown_request(); > +    Âbreak; > +  Âdefault: > +    Âbreak; > +  Â} > +} > + > +static void acpiPm1ControlP1_writeb(void *opaque, uint32_t addr, uint32_t > val) > +{ > +  ÂPCIAcpiState *s = opaque; > + > +  Âval <<= 8; > +  Âs->pm1_control = ((s->pm1_control & 0xff) | val) & > ~ACPI_BITMASK_SLEEP_ENABLE; > + > +  Âacpi_shutdown(s, val); > +} > + > +static uint32_t acpiPm1ControlP1_readb(void *opaque, uint32_t addr) > +{ > +  ÂPCIAcpiState *s = opaque; > +  Â/* Mask out the write-only bits */ > +  Âreturn (uint8_t)((s->pm1_control & > ~(ACPI_BITMASK_GLOBAL_LOCK_RELEASE|ACPI_BITMASK_SLEEP_ENABLE)) >> 8); > +} > + > +static void acpiPm1Control_writew(void *opaque, uint32_t addr, uint32_t val) > +{ > +  ÂPCIAcpiState *s = opaque; > + > +  Âs->pm1_control = val & ~ACPI_BITMASK_SLEEP_ENABLE; > + > +  Âacpi_shutdown(s, val); > +} > + > +static uint32_t acpiPm1Control_readw(void *opaque, uint32_t addr) > +{ > +  ÂPCIAcpiState *s = opaque; > +  Â/* Mask out the write-only bits */ > +  Âreturn (s->pm1_control & > ~(ACPI_BITMASK_GLOBAL_LOCK_RELEASE|ACPI_BITMASK_SLEEP_ENABLE)); > +} > + > +static void acpi_map(PCIDevice *pci_dev, int region_num, > +           uint32_t addr, uint32_t size, int type) > +{ > +  ÂPCIAcpiState *d = (PCIAcpiState *)pci_dev; > + > +  Â/* Byte access */ > +  Âregister_ioport_write(addr + 4, 1, 1, acpiPm1Control_writeb, d); > +  Âregister_ioport_read(addr + 4, 1, 1, acpiPm1Control_readb, d); > +  Âregister_ioport_write(addr + 4 + 1, 1, 1, acpiPm1ControlP1_writeb, d); > +  Âregister_ioport_read(addr + 4 +1, 1, 1, acpiPm1ControlP1_readb, d); > + > +  Â/* Word access */ > +  Âregister_ioport_write(addr + 4, 2, 2, acpiPm1Control_writew, d); > +  Âregister_ioport_read(addr + 4, 2, 2, acpiPm1Control_readw, d); > +} > + > +static inline int test_bit(uint8_t *map, int bit) > +{ > +  Âreturn ( map[bit / 8] & (1 << (bit % 8)) ); > +} > + > +static inline void set_bit(uint8_t *map, int bit) > +{ > +  Âmap[bit / 8] |= (1 << (bit % 8)); > +} > + > +static inline void clear_bit(uint8_t *map, int bit) > +{ > +  Âmap[bit / 8] &= ~(1 << (bit % 8)); > +} > + > +static void acpi_dbg_writel(void *opaque, uint32_t addr, uint32_t val) > +{ > +  ÂPIIX4ACPI_LOG(PIIX4ACPI_LOG_DEBUG, "ACPI: DBG: 0x%08x\n", val); > +  ÂPIIX4ACPI_LOG(PIIX4ACPI_LOG_INFO, "ACPI:debug: write addr=0x%x, > val=0x%x.\n", addr, val); > +} > + > +/* GPEx_STS occupy 1st half of the block, while GPEx_EN 2nd half */ > +static uint32_t gpe_sts_read(void *opaque, uint32_t addr) > +{ > +  ÂGPEState *s = opaque; > + > +  Âreturn s->gpe0_sts[addr - ACPI_GPE0_BLK_ADDRESS]; > +} > + > +/* write 1 to clear specific GPE bits */ > +static void gpe_sts_write(void *opaque, uint32_t addr, uint32_t val) > +{ > +  ÂGPEState *s = opaque; > +  Âint hotplugged = 0; > + > +  ÂPIIX4ACPI_LOG(PIIX4ACPI_LOG_DEBUG, "gpe_sts_write: addr=0x%x, > val=0x%x.\n", addr, val); > + > +  Âhotplugged = test_bit(&s->gpe0_sts[0], ACPI_PHP_GPE_BIT); > +  Âs->gpe0_sts[addr - ACPI_GPE0_BLK_ADDRESS] &= ~val; > +  Âif ( s->sci_asserted && > +     hotplugged && > +     !test_bit(&s->gpe0_sts[0], ACPI_PHP_GPE_BIT)) { > +    ÂPIIX4ACPI_LOG(PIIX4ACPI_LOG_INFO, "Clear the GPE0_STS bit for ACPI > hotplug & deassert the IRQ.\n"); > +    Âqemu_irq_lower(sci_irq); > +  Â} > + > +} > + > +static uint32_t gpe_en_read(void *opaque, uint32_t addr) > +{ > +  ÂGPEState *s = opaque; > + > +  Âreturn s->gpe0_en[addr - (ACPI_GPE0_BLK_ADDRESS + ACPI_GPE0_BLK_LEN / > 2)]; > +} > + > +/* write 0 to clear en bit */ > +static void gpe_en_write(void *opaque, uint32_t addr, uint32_t val) > +{ > +  ÂGPEState *s = opaque; > +  Âint reg_count; > + > +  ÂPIIX4ACPI_LOG(PIIX4ACPI_LOG_DEBUG, "gpe_en_write: addr=0x%x, > val=0x%x.\n", addr, val); > +  Âreg_count = addr - (ACPI_GPE0_BLK_ADDRESS + ACPI_GPE0_BLK_LEN / 2); > +  Âs->gpe0_en[reg_count] = val; > +  Â/* If disable GPE bit right after generating SCI on it, > +   * need deassert the intr to avoid redundant intrs > +   */ > +  Âif ( s->sci_asserted && > +     reg_count == (ACPI_PHP_GPE_BIT / 8) && > +     !(val & (1 << (ACPI_PHP_GPE_BIT % 8))) ) { > +    ÂPIIX4ACPI_LOG(PIIX4ACPI_LOG_INFO, "deassert due to disable GPE > bit.\n"); > +    Âs->sci_asserted = 0; > +    Âqemu_irq_lower(sci_irq); > +  Â} > + > +} > + > +static void gpe_save(QEMUFile* f, void* opaque) > +{ > +  ÂGPEState *s = (GPEState*)opaque; > +  Âint i; > + > +  Âfor ( i = 0; i < ACPI_GPE0_BLK_LEN / 2; i++ ) { > +    Âqemu_put_8s(f, &s->gpe0_sts[i]); > +    Âqemu_put_8s(f, &s->gpe0_en[i]); > +  Â} > + > +  Âqemu_put_8s(f, &s->sci_asserted); > +  Âif ( s->sci_asserted ) { > +    ÂPIIX4ACPI_LOG(PIIX4ACPI_LOG_INFO, "gpe_save with sci asserted!\n"); > +  Â} > +} > + > +static int gpe_load(QEMUFile* f, void* opaque, int version_id) > +{ > +  ÂGPEState *s = (GPEState*)opaque; > +  Âint i; > +  Âif (version_id != 1) > +    Âreturn -EINVAL; > + > +  Âfor ( i = 0; i < ACPI_GPE0_BLK_LEN / 2; i++ ) { > +    Âqemu_get_8s(f, &s->gpe0_sts[i]); > +    Âqemu_get_8s(f, &s->gpe0_en[i]); > +  Â} > + > +  Âqemu_get_8s(f, &s->sci_asserted); > +  Âreturn 0; > +} > + > +static uint32_t gpe_cpus_readb(void *opaque, uint32_t addr) > +{ > +  Âuint32_t val = 0; > +  ÂGPEState *g = opaque; > + > +  Âswitch (addr) { > +    Âcase PROC_BASE ... PROC_BASE+31: > +      Âval = g->cpus_sts[addr - PROC_BASE]; > +    Âdefault: > +      Âbreak; > +  Â} > + > +  Âreturn val; > +} > + > +static void gpe_cpus_writeb(void *opaque, uint32_t addr, uint32_t val) > +{ > +  Â/* GPEState *g = opaque; */ > + > +  Âswitch (addr) { > +    Âcase PROC_BASE ... PROC_BASE + 31: > +      Â/* don't allow to change cpus_sts from inside a guest */ > +      Âbreak; > +    Âdefault: > +      Âbreak; > +  Â} > +} > + > +static void gpe_acpi_init(void) > +{ > +  ÂGPEState *s = &gpe_state; > +  Âmemset(s, 0, sizeof(GPEState)); > + > +  Âs->cpus_sts[0] = 1; > + > +  Âregister_ioport_read(PROC_BASE, 32, 1, Âgpe_cpus_readb, s); > +  Âregister_ioport_write(PROC_BASE, 32, 1, gpe_cpus_writeb, s); > + > +  Âregister_ioport_read(ACPI_GPE0_BLK_ADDRESS, > +             ACPI_GPE0_BLK_LEN / 2, > +             1, > +             gpe_sts_read, > +             s); > +  Âregister_ioport_read(ACPI_GPE0_BLK_ADDRESS + ACPI_GPE0_BLK_LEN / 2, > +             ACPI_GPE0_BLK_LEN / 2, > +             1, > +             gpe_en_read, > +             s); > + > +  Âregister_ioport_write(ACPI_GPE0_BLK_ADDRESS, > +             ÂACPI_GPE0_BLK_LEN / 2, > +             Â1, > +             Âgpe_sts_write, > +             Âs); > +  Âregister_ioport_write(ACPI_GPE0_BLK_ADDRESS + ACPI_GPE0_BLK_LEN / 2, > +             ÂACPI_GPE0_BLK_LEN / 2, > +             Â1, > +             Âgpe_en_write, > +             Âs); > + > +  Âregister_savevm(NULL, "gpe", 0, 1, gpe_save, gpe_load, s); > +} > + > +static int piix4_pm_xen_initfn(PCIDevice *dev) > +{ > +  ÂPCIAcpiState *s = DO_UPCAST(PCIAcpiState, dev, dev); > +  Âuint8_t *pci_conf; > + > +  Âpci_conf = s->dev.config; > +  Âpci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_INTEL); > +  Âpci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82371AB_3); > +  Âpci_conf[0x08] = 0x01; Â/* B0 stepping */ > +  Âpci_conf[0x09] = 0x00; Â/* base class */ > +  Âpci_config_set_class(pci_conf, PCI_CLASS_BRIDGE_OTHER); > +  Âpci_conf[PCI_HEADER_TYPE] = PCI_HEADER_TYPE_NORMAL; /* header_type */ > +  Âpci_conf[0x3d] = 0x01; Â/* Hardwired to PIRQA is used */ > + > +  Â/* PMBA POWER MANAGEMENT BASE ADDRESS, hardcoded to 0x1f40 > +   * to make shutdown work for IPF, due to IPF Guest Firmware > +   * will enumerate pci devices. > +   * > +   * TODO: Âif Guest Firmware or Guest OS will change this PMBA, > +   * More logic will be added. > +   */ > +  Âpci_conf[0x40] = 0x41; /* Special device-specific BAR at 0x40 */ > +  Âpci_conf[0x41] = 0x1f; > +  Âpci_conf[0x42] = 0x00; > +  Âpci_conf[0x43] = 0x00; > + > +  Âs->pm1_control = ACPI_BITMASK_SCI_ENABLE; > + > +  Âacpi_map((PCIDevice *)s, 0, 0x1f40, 0x10, PCI_BASE_ADDRESS_SPACE_IO); > + > +  Âgpe_acpi_init(); > + > +  Âregister_ioport_write(ACPI_DBG_IO_ADDR, 4, 4, acpi_dbg_writel, s); > + > +  Âreturn 0; > +} > + > +void piix4_pm_xen_init(PCIBus *bus, int devfn, qemu_irq sci_irq_spec, > qemu_irq cmos_s3) > +{ > +  ÂPCIDevice *dev; > +  ÂPCIAcpiState *s; > + > +  Âsci_irq = sci_irq_spec; > + > +  Âdev = pci_create(bus, devfn, "PIIX4 ACPI"); > + > +  Âs = DO_UPCAST(PCIAcpiState, dev, dev); > + > +  Âs->irq = sci_irq_spec; > +  Âs->cmos_s3 = cmos_s3; > + > +  Âqdev_init_nofail(&dev->qdev); > +} > + > +static PCIDeviceInfo piix4_pm_xen_info = { > +  Â.qdev.name  Â= "PIIX4 ACPI", > +  Â.qdev.desc  Â= "dm", > +  Â.qdev.size  Â= sizeof(PCIAcpiState), > +  Â.qdev.vmsd  Â= &vmstate_acpi, > +  Â.init     = piix4_pm_xen_initfn, > +}; > + > +static void piix4_pm_xen_register(void) > +{ > +  Âpci_qdev_register(&piix4_pm_xen_info); > +} > + > +device_init(piix4_pm_xen_register); > diff --git a/hw/xen_common.h b/hw/xen_common.h > index 020fdd7..e1f07ba 100644 > --- a/hw/xen_common.h > +++ b/hw/xen_common.h > @@ -34,4 +34,7 @@ > Â/* hw/i8259-xen-stub.c */ > Âqemu_irq *i8259_xen_init(void); > > +/* hw/xen_acpi_piix4.c */ > +void piix4_pm_xen_init(PCIBus *bus, int devfn, qemu_irq sci_irq_spec, > qemu_irq cmos_s3); > + > Â#endif /* QEMU_HW_XEN_COMMON_H */ > diff --git a/hw/xen_machine_fv.c b/hw/xen_machine_fv.c > index 77563db..bfda944 100644 > --- a/hw/xen_machine_fv.c > +++ b/hw/xen_machine_fv.c > @@ -92,7 +92,6 @@ static void xen_init_fv(ram_addr_t ram_size, >   qemu_irq *isa_irq; >   qemu_irq *i8259; >   qemu_irq *cmos_s3; > -  Âqemu_irq *smi_irq; >   IsaIrqState *isa_irq_state; >   DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS]; >   FDCtrl *floppy_controller; > @@ -208,10 +207,7 @@ static void xen_init_fv(ram_addr_t ram_size, > >   if (acpi_enabled) { >     cmos_s3 = qemu_allocate_irqs(pc_cmos_set_s3_resume, rtc_state, 1); > -    Âsmi_irq = qemu_allocate_irqs(pc_acpi_smi_interrupt, first_cpu, 1); > -    Âpiix4_pm_init(pci_bus, piix3_devfn + 3, 0xb100, > -        Âisa_reserve_irq(9), *cmos_s3, *smi_irq, > -        Â0); > +    Âpiix4_pm_xen_init(pci_bus, piix3_devfn + 3, isa_reserve_irq(9), > *cmos_s3); >   } > >   if (i440fx_state) { > -- > 1.7.0.4 > > > _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |