pci: hotplug windup
Create qdev infrastructure for pci hotplug. PCI bus implementations must register a handler for hotplug. Creating a new PCI device will automagically hot-plug it in case the PCI bus in question supports this. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
cb23117be7
commit
ee995ffbf7
25
hw/pci.c
25
hw/pci.c
@ -41,6 +41,7 @@ struct PCIBus {
|
|||||||
int devfn_min;
|
int devfn_min;
|
||||||
pci_set_irq_fn set_irq;
|
pci_set_irq_fn set_irq;
|
||||||
pci_map_irq_fn map_irq;
|
pci_map_irq_fn map_irq;
|
||||||
|
pci_hotplug_fn hotplug;
|
||||||
uint32_t config_reg; /* XXX: suppress */
|
uint32_t config_reg; /* XXX: suppress */
|
||||||
void *irq_opaque;
|
void *irq_opaque;
|
||||||
PCIDevice *devices[256];
|
PCIDevice *devices[256];
|
||||||
@ -132,6 +133,12 @@ void pci_bus_irqs(PCIBus *bus, pci_set_irq_fn set_irq, pci_map_irq_fn map_irq,
|
|||||||
bus->irq_count = qemu_mallocz(nirq * sizeof(bus->irq_count[0]));
|
bus->irq_count = qemu_mallocz(nirq * sizeof(bus->irq_count[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void pci_bus_hotplug(PCIBus *bus, pci_hotplug_fn hotplug)
|
||||||
|
{
|
||||||
|
bus->qbus.allow_hotplug = 1;
|
||||||
|
bus->hotplug = hotplug;
|
||||||
|
}
|
||||||
|
|
||||||
PCIBus *pci_register_bus(DeviceState *parent, const char *name,
|
PCIBus *pci_register_bus(DeviceState *parent, const char *name,
|
||||||
pci_set_irq_fn set_irq, pci_map_irq_fn map_irq,
|
pci_set_irq_fn set_irq, pci_map_irq_fn map_irq,
|
||||||
void *irq_opaque, int devfn_min, int nirq)
|
void *irq_opaque, int devfn_min, int nirq)
|
||||||
@ -946,19 +953,33 @@ static int pci_qdev_init(DeviceState *qdev, DeviceInfo *base)
|
|||||||
PCIDevice *pci_dev = (PCIDevice *)qdev;
|
PCIDevice *pci_dev = (PCIDevice *)qdev;
|
||||||
PCIDeviceInfo *info = container_of(base, PCIDeviceInfo, qdev);
|
PCIDeviceInfo *info = container_of(base, PCIDeviceInfo, qdev);
|
||||||
PCIBus *bus;
|
PCIBus *bus;
|
||||||
int devfn;
|
int devfn, rc;
|
||||||
|
|
||||||
bus = FROM_QBUS(PCIBus, qdev_get_parent_bus(qdev));
|
bus = FROM_QBUS(PCIBus, qdev_get_parent_bus(qdev));
|
||||||
devfn = pci_dev->devfn;
|
devfn = pci_dev->devfn;
|
||||||
pci_dev = do_pci_register_device(pci_dev, bus, base->name, devfn,
|
pci_dev = do_pci_register_device(pci_dev, bus, base->name, devfn,
|
||||||
info->config_read, info->config_write);
|
info->config_read, info->config_write);
|
||||||
assert(pci_dev);
|
assert(pci_dev);
|
||||||
return info->init(pci_dev);
|
rc = info->init(pci_dev);
|
||||||
|
if (rc != 0)
|
||||||
|
return rc;
|
||||||
|
if (qdev->hotplugged)
|
||||||
|
bus->hotplug(pci_dev, 1);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int pci_unplug_device(DeviceState *qdev)
|
||||||
|
{
|
||||||
|
PCIDevice *dev = DO_UPCAST(PCIDevice, qdev, qdev);
|
||||||
|
|
||||||
|
dev->bus->hotplug(dev, 0);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void pci_qdev_register(PCIDeviceInfo *info)
|
void pci_qdev_register(PCIDeviceInfo *info)
|
||||||
{
|
{
|
||||||
info->qdev.init = pci_qdev_init;
|
info->qdev.init = pci_qdev_init;
|
||||||
|
info->qdev.unplug = pci_unplug_device;
|
||||||
info->qdev.exit = pci_unregister_device;
|
info->qdev.exit = pci_unregister_device;
|
||||||
info->qdev.bus_info = &pci_bus_info;
|
info->qdev.bus_info = &pci_bus_info;
|
||||||
qdev_register(&info->qdev);
|
qdev_register(&info->qdev);
|
||||||
|
2
hw/pci.h
2
hw/pci.h
@ -246,11 +246,13 @@ int pci_device_load(PCIDevice *s, QEMUFile *f);
|
|||||||
|
|
||||||
typedef void (*pci_set_irq_fn)(void *opaque, int irq_num, int level);
|
typedef void (*pci_set_irq_fn)(void *opaque, int irq_num, int level);
|
||||||
typedef int (*pci_map_irq_fn)(PCIDevice *pci_dev, int irq_num);
|
typedef int (*pci_map_irq_fn)(PCIDevice *pci_dev, int irq_num);
|
||||||
|
typedef int (*pci_hotplug_fn)(PCIDevice *pci_dev, int state);
|
||||||
void pci_bus_new_inplace(PCIBus *bus, DeviceState *parent,
|
void pci_bus_new_inplace(PCIBus *bus, DeviceState *parent,
|
||||||
const char *name, int devfn_min);
|
const char *name, int devfn_min);
|
||||||
PCIBus *pci_bus_new(DeviceState *parent, const char *name, int devfn_min);
|
PCIBus *pci_bus_new(DeviceState *parent, const char *name, int devfn_min);
|
||||||
void pci_bus_irqs(PCIBus *bus, pci_set_irq_fn set_irq, pci_map_irq_fn map_irq,
|
void pci_bus_irqs(PCIBus *bus, pci_set_irq_fn set_irq, pci_map_irq_fn map_irq,
|
||||||
void *irq_opaque, int nirq);
|
void *irq_opaque, int nirq);
|
||||||
|
void pci_bus_hotplug(PCIBus *bus, pci_hotplug_fn hotplug);
|
||||||
PCIBus *pci_register_bus(DeviceState *parent, const char *name,
|
PCIBus *pci_register_bus(DeviceState *parent, const char *name,
|
||||||
pci_set_irq_fn set_irq, pci_map_irq_fn map_irq,
|
pci_set_irq_fn set_irq, pci_map_irq_fn map_irq,
|
||||||
void *irq_opaque, int devfn_min, int nirq);
|
void *irq_opaque, int devfn_min, int nirq);
|
||||||
|
Loading…
Reference in New Issue
Block a user