提交 3f84865a 编写于 作者: G Gerd Hoffmann 提交者: Anthony Liguori

pci: windup acpi-based hotplug

Switch over acpi-based PCI hotplug for pc over to the new
qdev-based pci hotplugging.
Signed-off-by: NGerd Hoffmann <kraxel@redhat.com>
Signed-off-by: NAnthony Liguori <aliguori@us.ibm.com>
上级 ee995ffb
...@@ -694,20 +694,30 @@ static uint32_t pciej_read(void *opaque, uint32_t addr) ...@@ -694,20 +694,30 @@ static uint32_t pciej_read(void *opaque, uint32_t addr)
static void pciej_write(void *opaque, uint32_t addr, uint32_t val) static void pciej_write(void *opaque, uint32_t addr, uint32_t val)
{ {
#if defined (TARGET_I386) BusState *bus = opaque;
DeviceState *qdev;
PCIDevice *dev;
int slot = ffs(val) - 1; int slot = ffs(val) - 1;
pci_device_hot_remove_success(0, slot); QLIST_FOREACH(qdev, &bus->children, sibling) {
dev = DO_UPCAST(PCIDevice, qdev, qdev);
if (PCI_SLOT(dev->devfn) == slot) {
#if defined (TARGET_I386)
pci_device_hot_remove_success(dev);
#endif #endif
qdev_free(qdev);
}
}
#if defined(DEBUG) #if defined(DEBUG)
printf("pciej write %x <== %d\n", addr, val); printf("pciej write %x <== %d\n", addr, val);
#endif #endif
} }
static void piix4_device_hot_add(int bus, int slot, int state); static int piix4_device_hotplug(PCIDevice *dev, int state);
void piix4_acpi_system_hot_add_init(void) void piix4_acpi_system_hot_add_init(PCIBus *bus)
{ {
register_ioport_write(GPE_BASE, 4, 1, gpe_writeb, &gpe); register_ioport_write(GPE_BASE, 4, 1, gpe_writeb, &gpe);
register_ioport_read(GPE_BASE, 4, 1, gpe_readb, &gpe); register_ioport_read(GPE_BASE, 4, 1, gpe_readb, &gpe);
...@@ -715,10 +725,10 @@ void piix4_acpi_system_hot_add_init(void) ...@@ -715,10 +725,10 @@ void piix4_acpi_system_hot_add_init(void)
register_ioport_write(PCI_BASE, 8, 4, pcihotplug_write, &pci0_status); register_ioport_write(PCI_BASE, 8, 4, pcihotplug_write, &pci0_status);
register_ioport_read(PCI_BASE, 8, 4, pcihotplug_read, &pci0_status); register_ioport_read(PCI_BASE, 8, 4, pcihotplug_read, &pci0_status);
register_ioport_write(PCI_EJ_BASE, 4, 4, pciej_write, NULL); register_ioport_write(PCI_EJ_BASE, 4, 4, pciej_write, bus);
register_ioport_read(PCI_EJ_BASE, 4, 4, pciej_read, NULL); register_ioport_read(PCI_EJ_BASE, 4, 4, pciej_read, bus);
qemu_system_device_hot_add_register(piix4_device_hot_add); pci_bus_hotplug(bus, piix4_device_hotplug);
} }
static void enable_device(struct pci_status *p, struct gpe_regs *g, int slot) static void enable_device(struct pci_status *p, struct gpe_regs *g, int slot)
...@@ -733,8 +743,10 @@ static void disable_device(struct pci_status *p, struct gpe_regs *g, int slot) ...@@ -733,8 +743,10 @@ static void disable_device(struct pci_status *p, struct gpe_regs *g, int slot)
p->down |= (1 << slot); p->down |= (1 << slot);
} }
static void piix4_device_hot_add(int bus, int slot, int state) static int piix4_device_hotplug(PCIDevice *dev, int state)
{ {
int slot = PCI_SLOT(dev->devfn);
pci0_status.up = 0; pci0_status.up = 0;
pci0_status.down = 0; pci0_status.down = 0;
if (state) if (state)
...@@ -745,18 +757,7 @@ static void piix4_device_hot_add(int bus, int slot, int state) ...@@ -745,18 +757,7 @@ static void piix4_device_hot_add(int bus, int slot, int state)
qemu_set_irq(pm_state->irq, 1); qemu_set_irq(pm_state->irq, 1);
qemu_set_irq(pm_state->irq, 0); qemu_set_irq(pm_state->irq, 0);
} }
} return 0;
static qemu_system_device_hot_add_t device_hot_add_callback;
void qemu_system_device_hot_add_register(qemu_system_device_hot_add_t callback)
{
device_hot_add_callback = callback;
}
void qemu_system_device_hot_add(int pcibus, int slot, int state)
{
if (device_hot_add_callback)
device_hot_add_callback(pcibus, slot, state);
} }
struct acpi_table_header struct acpi_table_header
......
...@@ -1353,8 +1353,6 @@ static void pc_init1(ram_addr_t ram_size, ...@@ -1353,8 +1353,6 @@ static void pc_init1(ram_addr_t ram_size,
pci_nic_init(nd, "e1000", NULL); pci_nic_init(nd, "e1000", NULL);
} }
piix4_acpi_system_hot_add_init();
if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) { if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) {
fprintf(stderr, "qemu: too many IDE bus\n"); fprintf(stderr, "qemu: too many IDE bus\n");
exit(1); exit(1);
...@@ -1405,6 +1403,7 @@ static void pc_init1(ram_addr_t ram_size, ...@@ -1405,6 +1403,7 @@ static void pc_init1(ram_addr_t ram_size,
qdev_prop_set_ptr(eeprom, "data", eeprom_buf + (i * 256)); qdev_prop_set_ptr(eeprom, "data", eeprom_buf + (i * 256));
qdev_init(eeprom); qdev_init(eeprom);
} }
piix4_acpi_system_hot_add_init(pci_bus);
} }
if (i440fx_state) { if (i440fx_state) {
......
...@@ -106,7 +106,7 @@ int acpi_table_add(const char *table_desc); ...@@ -106,7 +106,7 @@ int acpi_table_add(const char *table_desc);
i2c_bus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base, i2c_bus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base,
qemu_irq sci_irq); qemu_irq sci_irq);
void piix4_smbus_register_device(SMBusDevice *dev, uint8_t addr); void piix4_smbus_register_device(SMBusDevice *dev, uint8_t addr);
void piix4_acpi_system_hot_add_init(void); void piix4_acpi_system_hot_add_init(PCIBus *bus);
/* hpet.c */ /* hpet.c */
extern int no_hpet; extern int no_hpet;
......
...@@ -185,8 +185,6 @@ void pci_device_hot_add(Monitor *mon, const QDict *qdict) ...@@ -185,8 +185,6 @@ void pci_device_hot_add(Monitor *mon, const QDict *qdict)
monitor_printf(mon, "invalid type: %s\n", type); monitor_printf(mon, "invalid type: %s\n", type);
if (dev) { if (dev) {
qemu_system_device_hot_add(pci_bus_num(dev->bus),
PCI_SLOT(dev->devfn), 1);
monitor_printf(mon, "OK domain %d, bus %d, slot %d, function %d\n", monitor_printf(mon, "OK domain %d, bus %d, slot %d, function %d\n",
0, pci_bus_num(dev->bus), PCI_SLOT(dev->devfn), 0, pci_bus_num(dev->bus), PCI_SLOT(dev->devfn),
PCI_FUNC(dev->devfn)); PCI_FUNC(dev->devfn));
...@@ -210,8 +208,7 @@ void pci_device_hot_remove(Monitor *mon, const char *pci_addr) ...@@ -210,8 +208,7 @@ void pci_device_hot_remove(Monitor *mon, const char *pci_addr)
monitor_printf(mon, "slot %d empty\n", slot); monitor_printf(mon, "slot %d empty\n", slot);
return; return;
} }
qdev_unplug(&d->qdev);
qemu_system_device_hot_add(bus, slot, 0);
} }
void do_pci_device_hot_remove(Monitor *mon, const QDict *qdict) void do_pci_device_hot_remove(Monitor *mon, const QDict *qdict)
...@@ -230,16 +227,10 @@ static int pci_match_fn(void *dev_private, void *arg) ...@@ -230,16 +227,10 @@ static int pci_match_fn(void *dev_private, void *arg)
/* /*
* OS has executed _EJ0 method, we now can remove the device * OS has executed _EJ0 method, we now can remove the device
*/ */
void pci_device_hot_remove_success(int pcibus, int slot) void pci_device_hot_remove_success(PCIDevice *d)
{ {
PCIDevice *d = pci_find_device(pcibus, slot, 0);
int class_code; int class_code;
if (!d) {
monitor_printf(cur_mon, "invalid slot %d\n", slot);
return;
}
class_code = d->config_read(d, PCI_CLASS_DEVICE+1, 1); class_code = d->config_read(d, PCI_CLASS_DEVICE+1, 1);
switch(class_code) { switch(class_code) {
...@@ -250,7 +241,5 @@ void pci_device_hot_remove_success(int pcibus, int slot) ...@@ -250,7 +241,5 @@ void pci_device_hot_remove_success(int pcibus, int slot)
destroy_nic(pci_match_fn, d); destroy_nic(pci_match_fn, d);
break; break;
} }
qdev_free(&d->qdev);
} }
...@@ -199,11 +199,6 @@ BlockDriverState *qdev_init_bdrv(DeviceState *dev, BlockInterfaceType type); ...@@ -199,11 +199,6 @@ BlockDriverState *qdev_init_bdrv(DeviceState *dev, BlockInterfaceType type);
extern QemuOpts *drive_add(const char *file, const char *fmt, ...); extern QemuOpts *drive_add(const char *file, const char *fmt, ...);
extern DriveInfo *drive_init(QemuOpts *arg, void *machine, int *fatal_error); extern DriveInfo *drive_init(QemuOpts *arg, void *machine, int *fatal_error);
/* acpi */
typedef void (*qemu_system_device_hot_add_t)(int pcibus, int slot, int state);
void qemu_system_device_hot_add_register(qemu_system_device_hot_add_t callback);
void qemu_system_device_hot_add(int pcibus, int slot, int state);
/* device-hotplug */ /* device-hotplug */
typedef int (dev_match_fn)(void *dev_private, void *arg); typedef int (dev_match_fn)(void *dev_private, void *arg);
...@@ -217,7 +212,7 @@ void pci_device_hot_add(Monitor *mon, const QDict *qdict); ...@@ -217,7 +212,7 @@ void pci_device_hot_add(Monitor *mon, const QDict *qdict);
void drive_hot_add(Monitor *mon, const QDict *qdict); void drive_hot_add(Monitor *mon, const QDict *qdict);
void pci_device_hot_remove(Monitor *mon, const char *pci_addr); void pci_device_hot_remove(Monitor *mon, const char *pci_addr);
void do_pci_device_hot_remove(Monitor *mon, const QDict *qdict); void do_pci_device_hot_remove(Monitor *mon, const QDict *qdict);
void pci_device_hot_remove_success(int pcibus, int slot); void pci_device_hot_remove_success(PCIDevice *dev);
/* serial ports */ /* serial ports */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册
新手
引导
客服 返回
顶部