This patch adds two things. First it allows QEMU to distinguish between regular powerdown and S4 powerdown. Later separate QMP notification will be added for S4 powerdown. Second it allows S3/S4 states to be disabled from QEMU command line. Some guests known to be broken with regards to power management, but allow to use it anyway. Using new properties management will be able to disable S3/S4 for such guests. Supported system state are passed to a firmware using new fw_cfg file. The file contains 6 byte array. Each byte represents one system state. If byte at offset X has its MSB set it means that system state X is supported and to enter it guest should use the value from lowest 3 bits. Signed-off-by: Gleb Natapov Signed-off-by: Anthony Liguori Signed-off-by: Michal Novotny --- hw/acpi.c | 20 +++++++++++++++++++- hw/ipf.c | 2 +- hw/mips_malta.c | 2 +- hw/pc.c | 2 +- hw/pc.h | 2 +- 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/hw/acpi.c b/hw/acpi.c index cb2edde..7c9a855 100644 --- a/hw/acpi.c +++ b/hw/acpi.c @@ -84,6 +84,10 @@ typedef struct PIIX4PMState { struct pci_status pci0_status; uint32_t pci0_hotplug_enable; uint32_t pci0_slot_device_present; + + uint8_t disable_s3; + uint8_t disable_s4; + uint8_t s4_val; } PIIX4PMState; #define RSM_STS (1 << 15) @@ -219,6 +223,9 @@ static void pm_ioport_writew(void *opaque, uint32_t addr, uint32_t val) qemu_system_suspend_request(); break; default: + if (sus_typ == s->s4_val) { /* S4 request */ + qemu_system_shutdown_request(); + } break; } } @@ -726,7 +733,7 @@ static int piix4_pm_initfn(PCIDevice *dev) } i2c_bus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base, - qemu_irq sci_irq) + qemu_irq sci_irq, void *fw_cfg) { PCIDevice *dev; PIIX4PMState *s; @@ -739,6 +746,14 @@ i2c_bus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base, qdev_init_nofail(&dev->qdev); + if (fw_cfg) { + uint8_t suspend[6] = {128, 0, 0, 129, 128, 128}; + suspend[3] = 1 | ((!s->disable_s3) << 7); + suspend[4] = s->s4_val | ((!s->disable_s4) << 7); + + fw_cfg_add_file(fw_cfg, "etc/system-states", g_memdup(suspend, 6), 6); + } + return s->smbus; } @@ -752,6 +767,9 @@ static PCIDeviceInfo piix4_pm_info = { .config_write = pm_write_config, .qdev.props = (Property[]) { DEFINE_PROP_UINT32("smb_io_base", PIIX4PMState, smb_io_base, 0), + DEFINE_PROP_UINT8("disable_s3", PIIX4PMState, disable_s3, 0), + DEFINE_PROP_UINT8("disable_s4", PIIX4PMState, disable_s4, 0), + DEFINE_PROP_UINT8("s4_val", PIIX4PMState, s4_val, 2), DEFINE_PROP_END_OF_LIST(), } }; diff --git a/hw/ipf.c b/hw/ipf.c index 5ea9122..c1db876 100644 --- a/hw/ipf.c +++ b/hw/ipf.c @@ -601,7 +601,7 @@ static void ipf_init1(ram_addr_t ram_size, i2c_bus *smbus; /* TODO: Populate SPD eeprom data. */ - smbus = piix4_pm_init(pci_bus, piix3_devfn + 3, 0xb100, i8259[9]); + smbus = piix4_pm_init(pci_bus, piix3_devfn + 3, 0xb100, i8259[9], NULL); for (i = 0; i < 8; i++) { DeviceState *eeprom; eeprom = qdev_create((BusState *)smbus, "smbus-eeprom"); diff --git a/hw/mips_malta.c b/hw/mips_malta.c index c9895d9..6d536e3 100644 --- a/hw/mips_malta.c +++ b/hw/mips_malta.c @@ -927,7 +927,7 @@ void mips_malta_init (ram_addr_t ram_size, isa_bus_irqs(i8259); pci_piix4_ide_init(pci_bus, hd, piix4_devfn + 1); usb_uhci_piix4_init(pci_bus, piix4_devfn + 2); - smbus = piix4_pm_init(pci_bus, piix4_devfn + 3, 0x1100, isa_get_irq(9)); + smbus = piix4_pm_init(pci_bus, piix4_devfn + 3, 0x1100, isa_get_irq(9), NULL); eeprom_buf = qemu_mallocz(8 * 256); /* XXX: make this persistent */ for (i = 0; i < 8; i++) { /* TODO: Populate SPD eeprom data. */ diff --git a/hw/pc.c b/hw/pc.c index 6bc2e2d..1947690 100644 --- a/hw/pc.c +++ b/hw/pc.c @@ -1343,7 +1343,7 @@ static void pc_init1(ram_addr_t ram_size, /* TODO: Populate SPD eeprom data. */ smbus = piix4_pm_init(pci_bus, piix3_devfn + 3, 0xb100, - isa_get_irq(9)); + isa_get_irq(9), fw_cfg); for (i = 0; i < 8; i++) { DeviceState *eeprom; eeprom = qdev_create((BusState *)smbus, "smbus-eeprom"); diff --git a/hw/pc.h b/hw/pc.h index c79e45b..f351cbb 100644 --- a/hw/pc.h +++ b/hw/pc.h @@ -120,7 +120,7 @@ int acpi_table_add(const char *table_desc); /* acpi_piix.c */ i2c_bus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base, - qemu_irq sci_irq); + qemu_irq sci_irq, void *fw_cfg); void piix4_smbus_register_device(SMBusDevice *dev, uint8_t addr); void piix4_acpi_system_hot_add_init(PCIBus *bus, const char *model); -- 1.7.11.4