Revision e927d487

b/hw/acpi_piix4.c
585 585
    PIIX4_DPRINTF("pciej write %x <== %d\n", addr, val);
586 586
}
587 587

  
588
static int piix4_device_hotplug(DeviceState *qdev, PCIDevice *dev, int state);
588
static int piix4_device_hotplug(DeviceState *qdev, PCIDevice *dev,
589
                                PCIHotplugState state);
589 590

  
590 591
static void piix4_acpi_system_hot_add_init(PCIBus *bus, PIIX4PMState *s)
591 592
{
......
615 616
    s->pci0_status.down |= (1 << slot);
616 617
}
617 618

  
618
static int piix4_device_hotplug(DeviceState *qdev, PCIDevice *dev, int state)
619
static int piix4_device_hotplug(DeviceState *qdev, PCIDevice *dev,
620
				PCIHotplugState state)
619 621
{
620 622
    int slot = PCI_SLOT(dev->devfn);
621 623
    PIIX4PMState *s = DO_UPCAST(PIIX4PMState, dev,
622 624
                                DO_UPCAST(PCIDevice, qdev, qdev));
623 625

  
624
    if (!dev->qdev.hotplugged)
626
    /* Don't send event when device is enabled during qemu machine creation:
627
     * it is present on boot, no hotplug event is necessary. We do send an
628
     * event when the device is disabled later. */
629
    if (state == PCI_COLDPLUG_ENABLED) {
625 630
        return 0;
631
    }
626 632

  
627 633
    s->pci0_status.up = 0;
628 634
    s->pci0_status.down = 0;
629
    if (state) {
635
    if (state == PCI_HOTPLUG_ENABLED) {
630 636
        enable_device(s, slot);
631 637
    } else {
632 638
        disable_device(s, slot);
b/hw/pci.c
1558 1558
    pci_add_option_rom(pci_dev);
1559 1559

  
1560 1560
    if (bus->hotplug) {
1561
        /* lower layer must check qdev->hotplugged */
1562
        rc = bus->hotplug(bus->hotplug_qdev, pci_dev, 1);
1561
        /* Let buses differentiate between hotplug and when device is
1562
         * enabled during qemu machine creation. */
1563
        rc = bus->hotplug(bus->hotplug_qdev, pci_dev,
1564
                          qdev->hotplugged ? PCI_HOTPLUG_ENABLED:
1565
                          PCI_COLDPLUG_ENABLED);
1563 1566
        if (rc != 0) {
1564 1567
            int r = pci_unregister_device(&pci_dev->qdev);
1565 1568
            assert(!r);
......
1573 1576
{
1574 1577
    PCIDevice *dev = DO_UPCAST(PCIDevice, qdev, qdev);
1575 1578

  
1576
    return dev->bus->hotplug(dev->bus->hotplug_qdev, dev, 0);
1579
    return dev->bus->hotplug(dev->bus->hotplug_qdev, dev,
1580
                             PCI_HOTPLUG_DISABLED);
1577 1581
}
1578 1582

  
1579 1583
void pci_qdev_register(PCIDeviceInfo *info)
b/hw/pci.h
214 214

  
215 215
typedef void (*pci_set_irq_fn)(void *opaque, int irq_num, int level);
216 216
typedef int (*pci_map_irq_fn)(PCIDevice *pci_dev, int irq_num);
217
typedef int (*pci_hotplug_fn)(DeviceState *qdev, PCIDevice *pci_dev, int state);
217

  
218
typedef enum {
219
    PCI_HOTPLUG_DISABLED,
220
    PCI_HOTPLUG_ENABLED,
221
    PCI_COLDPLUG_ENABLED,
222
} PCIHotplugState;
223

  
224
typedef int (*pci_hotplug_fn)(DeviceState *qdev, PCIDevice *pci_dev,
225
                              PCIHotplugState state);
218 226
void pci_bus_new_inplace(PCIBus *bus, DeviceState *parent,
219 227
                         const char *name, int devfn_min);
220 228
PCIBus *pci_bus_new(DeviceState *parent, const char *name, int devfn_min);
b/hw/pcie.c
192 192
}
193 193

  
194 194
static int pcie_cap_slot_hotplug(DeviceState *qdev,
195
                                 PCIDevice *pci_dev, int state)
195
                                 PCIDevice *pci_dev, PCIHotplugState state)
196 196
{
197 197
    PCIDevice *d = DO_UPCAST(PCIDevice, qdev, qdev);
198 198
    uint8_t *exp_cap = d->config + d->exp.exp_cap;
199 199
    uint16_t sltsta = pci_get_word(exp_cap + PCI_EXP_SLTSTA);
200 200

  
201
    if (!pci_dev->qdev.hotplugged) {
202
        assert(state); /* this case only happens at machine creation. */
201
    /* Don't send event when device is enabled during qemu machine creation:
202
     * it is present on boot, no hotplug event is necessary. We do send an
203
     * event when the device is disabled later. */
204
    if (state == PCI_COLDPLUG_ENABLED) {
203 205
        pci_word_test_and_set_mask(exp_cap + PCI_EXP_SLTSTA,
204 206
                                   PCI_EXP_SLTSTA_PDS);
205 207
        return 0;
......
219 221
     */
220 222
    assert(PCI_FUNC(pci_dev->devfn) == 0);
221 223

  
222
    if (state) {
224
    if (state == PCI_HOTPLUG_ENABLED) {
223 225
        pci_word_test_and_set_mask(exp_cap + PCI_EXP_SLTSTA,
224 226
                                   PCI_EXP_SLTSTA_PDS);
225 227
        pcie_cap_slot_event(d, PCI_EXP_HP_EV_PDC);

Also available in: Unified diff