[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] Re: [Qemu-devel] [PATCH RFC V3 12/12] xen: Add a Xen specific ACPI Implementation to target-xen
On Fri, Sep 17, 2010 at 11:15 AM, <anthony.perard@xxxxxxxxxx> 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. > 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 | Â405 > +++++++++++++++++++++++++++++++++++++++++++++++++++ > Âhw/xen_common.h   |  Â3 + > Âhw/xen_machine_fv.c |  Â6 +- > Â4 files changed, 410 insertions(+), 5 deletions(-) > Âcreate mode 100644 hw/xen_acpi_piix4.c > > diff --git a/Makefile.target b/Makefile.target > index ea14393..db7f96b 100644 > --- a/Makefile.target > +++ b/Makefile.target > @@ -189,6 +189,7 @@ obj-$(CONFIG_NO_XEN) += xen-stub.o > Â# xen full virtualized machine > Âobj-$(CONFIG_XEN) += xen_machine_fv.o > Âobj-$(CONFIG_XEN) += xen_platform.o > +obj-$(CONFIG_XEN) += xen_acpi_piix4.o > > Â# USB layer > Âobj-$(CONFIG_USB_OHCI) += usb-ohci.o > diff --git a/hw/xen_acpi_piix4.c b/hw/xen_acpi_piix4.c > new file mode 100644 > index 0000000..f4792f2 > --- /dev/null > +++ b/hw/xen_acpi_piix4.c > @@ -0,0 +1,405 @@ > + /* > + * 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 { 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; The above globals and static variable should be eliminated, see ac4040955b1669f0aac5937f623d6587d5210679. > + > +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) acpi_pm1_control_writeb(). > +{ > +  ÂPCIAcpiState *s = opaque; > +  Âs->pm1_control = (s->pm1_control & 0xff00) | (val & 0xff); > +} > + > +static uint32_t acpiPm1Control_readb(void *opaque, uint32_t addr) Likewise. > +{ > +  ÂPCIAcpiState *s = opaque; > +  Â/* Mask out the write-only bits */ > +  Âreturn (uint8_t)(s->pm1_control & > ~(ACPI_BITMASK_GLOBAL_LOCK_RELEASE|ACPI_BITMASK_SLEEP_ENABLE)); Please add spaces around '|' and break the line. Adding ACPI_BITMASK_WRITEONLY may help. > +} > + > +static void acpi_shutdown(PCIAcpiState *s, uint32_t val) > +{ > +  Âif (!(val & ACPI_BITMASK_SLEEP_ENABLE)) > +    Âreturn; braces > + > +  Â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 const VMStateDescription vmstate_gpe = { > +  Â.name = "gpe", > +  Â.version_id = 2, > +  Â.minimum_version_id = 2, > +  Â.minimum_version_id_old = 2, > +  Â.fields = (VMStateField []) { > +    ÂVMSTATE_BUFFER(gpe0_sts, GPEState), > +    ÂVMSTATE_BUFFER(gpe0_en, GPEState), > +    ÂVMSTATE_UINT8(sci_asserted, GPEState), > +    ÂVMSTATE_END_OF_LIST() > +  Â} > +}; > + > +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]; break; > +    Â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); > + > +  Âvmstate_register(NULL, 0, &vmstate_gpe, 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; Please extract this line to a reset function. _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |