41
42
#define GPE_BASE 0xafe0
43
#define PCI_BASE 0xae00
44
#define PCI_UP_BASE 0xae00
45
#define PCI_DOWN_BASE 0xae04
44
46
#define PCI_EJ_BASE 0xae08
45
47
#define PCI_RMV_BASE 0xae0c
47
49
#define PIIX4_PCI_HOTPLUG_STATUS 2
49
51
struct pci_status {
52
uint32_t up; /* deprecated, maintained for migration compatibility */
204
211
pm_io_space_update((PIIX4PMState *)d);
214
static void vmstate_pci_status_pre_save(void *opaque)
216
struct pci_status *pci0_status = opaque;
217
PIIX4PMState *s = container_of(pci0_status, PIIX4PMState, pci0_status);
219
/* We no longer track up, so build a safe value for migrating
220
* to a version that still does... of course these might get lost
221
* by an old buggy implementation, but we try. */
222
pci0_status->up = s->pci0_slot_device_present & s->pci0_hotplug_enable;
207
225
static int vmstate_acpi_post_load(void *opaque, int version_id)
209
227
PIIX4PMState *s = opaque;
241
259
.minimum_version_id = 1,
242
260
.minimum_version_id_old = 1,
261
.pre_save = vmstate_pci_status_pre_save,
243
262
.fields = (VMStateField []) {
244
263
VMSTATE_UINT32(up, struct pci_status),
245
264
VMSTATE_UINT32(down, struct pci_status),
290
static void acpi_piix_eject_slot(PIIX4PMState *s, unsigned slots)
292
BusChild *kid, *next;
293
BusState *bus = qdev_get_parent_bus(&s->dev.qdev);
294
int slot = ffs(slots) - 1;
295
bool slot_free = true;
297
/* Mark request as complete */
298
s->pci0_status.down &= ~(1U << slot);
300
QTAILQ_FOREACH_SAFE(kid, &bus->children, sibling, next) {
301
DeviceState *qdev = kid->child;
302
PCIDevice *dev = PCI_DEVICE(qdev);
303
PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(dev);
304
if (PCI_SLOT(dev->devfn) == slot) {
305
if (pc->no_hotplug) {
308
object_unparent(OBJECT(dev));
314
s->pci0_slot_device_present &= ~(1U << slot);
271
318
static void piix4_update_hotplug(PIIX4PMState *s)
273
320
PCIDevice *dev = &s->dev;
274
321
BusState *bus = qdev_get_parent_bus(&dev->qdev);
275
DeviceState *qdev, *next;
322
BusChild *kid, *next;
324
/* Execute any pending removes during reset */
325
while (s->pci0_status.down) {
326
acpi_piix_eject_slot(s, s->pci0_status.down);
277
329
s->pci0_hotplug_enable = ~0;
330
s->pci0_slot_device_present = 0;
279
QTAILQ_FOREACH_SAFE(qdev, &bus->children, sibling, next) {
332
QTAILQ_FOREACH_SAFE(kid, &bus->children, sibling, next) {
333
DeviceState *qdev = kid->child;
280
334
PCIDevice *pdev = PCI_DEVICE(qdev);
281
335
PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(pdev);
282
336
int slot = PCI_SLOT(pdev->devfn);
284
338
if (pc->no_hotplug) {
285
s->pci0_hotplug_enable &= ~(1 << slot);
339
s->pci0_hotplug_enable &= ~(1U << slot);
342
s->pci0_slot_device_present |= (1U << slot);
374
430
i2c_bus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base,
375
431
qemu_irq sci_irq, qemu_irq smi_irq,
432
int kvm_enabled, void *fw_cfg)
390
446
qdev_init_nofail(&dev->qdev);
449
uint8_t suspend[6] = {128, 0, 0, 129, 128, 128};
450
suspend[3] = 1 | ((!s->disable_s3) << 7);
451
suspend[4] = s->s4_val | ((!s->disable_s4) << 7);
453
fw_cfg_add_file(fw_cfg, "etc/system-states", g_memdup(suspend, 6), 6);
392
456
return s->smb.smbus;
395
459
static Property piix4_pm_properties[] = {
396
460
DEFINE_PROP_UINT32("smb_io_base", PIIX4PMState, smb_io_base, 0),
461
DEFINE_PROP_UINT8("disable_s3", PIIX4PMState, disable_s3, 0),
462
DEFINE_PROP_UINT8("disable_s4", PIIX4PMState, disable_s4, 0),
463
DEFINE_PROP_UINT8("s4_val", PIIX4PMState, s4_val, 2),
397
464
DEFINE_PROP_END_OF_LIST(),
448
515
PIIX4_DPRINTF("gpe write %x <== %d\n", addr, val);
451
static uint32_t pcihotplug_read(void *opaque, uint32_t addr)
454
struct pci_status *g = opaque;
466
PIIX4_DPRINTF("pcihotplug read %x == %x\n", addr, val);
470
static void pcihotplug_write(void *opaque, uint32_t addr, uint32_t val)
472
struct pci_status *g = opaque;
482
PIIX4_DPRINTF("pcihotplug write %x <== %d\n", addr, val);
485
static uint32_t pciej_read(void *opaque, uint32_t addr)
487
PIIX4_DPRINTF("pciej read %x\n", addr);
518
static uint32_t pci_up_read(void *opaque, uint32_t addr)
520
PIIX4PMState *s = opaque;
523
/* Manufacture an "up" value to cause a device check on any hotplug
524
* slot with a device. Extra device checks are harmless. */
525
val = s->pci0_slot_device_present & s->pci0_hotplug_enable;
527
PIIX4_DPRINTF("pci_up_read %x\n", val);
531
static uint32_t pci_down_read(void *opaque, uint32_t addr)
533
PIIX4PMState *s = opaque;
534
uint32_t val = s->pci0_status.down;
536
PIIX4_DPRINTF("pci_down_read %x\n", val);
540
static uint32_t pci_features_read(void *opaque, uint32_t addr)
542
/* No feature defined yet */
543
PIIX4_DPRINTF("pci_features_read %x\n", 0);
491
547
static void pciej_write(void *opaque, uint32_t addr, uint32_t val)
493
BusState *bus = opaque;
494
DeviceState *qdev, *next;
495
int slot = ffs(val) - 1;
497
QTAILQ_FOREACH_SAFE(qdev, &bus->children, sibling, next) {
498
PCIDevice *dev = PCI_DEVICE(qdev);
499
PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(dev);
500
if (PCI_SLOT(dev->devfn) == slot && !pc->no_hotplug) {
549
acpi_piix_eject_slot(opaque, val);
506
551
PIIX4_DPRINTF("pciej write %x <== %d\n", addr, val);
513
558
return s->pci0_hotplug_enable;
516
static void pcirmv_write(void *opaque, uint32_t addr, uint32_t val)
521
561
static int piix4_device_hotplug(DeviceState *qdev, PCIDevice *dev,
522
562
PCIHotplugState state);
524
564
static void piix4_acpi_system_hot_add_init(PCIBus *bus, PIIX4PMState *s)
526
struct pci_status *pci0_status = &s->pci0_status;
528
567
register_ioport_write(GPE_BASE, GPE_LEN, 1, gpe_writeb, s);
529
568
register_ioport_read(GPE_BASE, GPE_LEN, 1, gpe_readb, s);
530
569
acpi_gpe_blk(&s->ar, GPE_BASE);
532
register_ioport_write(PCI_BASE, 8, 4, pcihotplug_write, pci0_status);
533
register_ioport_read(PCI_BASE, 8, 4, pcihotplug_read, pci0_status);
535
register_ioport_write(PCI_EJ_BASE, 4, 4, pciej_write, bus);
536
register_ioport_read(PCI_EJ_BASE, 4, 4, pciej_read, bus);
538
register_ioport_write(PCI_RMV_BASE, 4, 4, pcirmv_write, s);
571
register_ioport_read(PCI_UP_BASE, 4, 4, pci_up_read, s);
572
register_ioport_read(PCI_DOWN_BASE, 4, 4, pci_down_read, s);
574
register_ioport_write(PCI_EJ_BASE, 4, 4, pciej_write, s);
575
register_ioport_read(PCI_EJ_BASE, 4, 4, pci_features_read, s);
539
577
register_ioport_read(PCI_RMV_BASE, 4, 4, pcirmv_read, s);
541
579
pci_bus_hotplug(bus, piix4_device_hotplug, &s->dev.qdev);
544
582
static void enable_device(PIIX4PMState *s, int slot)
546
584
s->ar.gpe.sts[0] |= PIIX4_PCI_HOTPLUG_STATUS;
547
s->pci0_status.up |= (1 << slot);
585
s->pci0_slot_device_present |= (1U << slot);
550
588
static void disable_device(PIIX4PMState *s, int slot)
552
590
s->ar.gpe.sts[0] |= PIIX4_PCI_HOTPLUG_STATUS;
553
s->pci0_status.down |= (1 << slot);
591
s->pci0_status.down |= (1U << slot);
556
594
static int piix4_device_hotplug(DeviceState *qdev, PCIDevice *dev,
564
602
* it is present on boot, no hotplug event is necessary. We do send an
565
603
* event when the device is disabled later. */
566
604
if (state == PCI_COLDPLUG_ENABLED) {
605
s->pci0_slot_device_present |= (1U << slot);
570
s->pci0_status.up = 0;
571
s->pci0_status.down = 0;
572
609
if (state == PCI_HOTPLUG_ENABLED) {
573
610
enable_device(s, slot);