[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 6/9] acpi/piix4pm: convert ACPI PCI hotplug to use h
From: |
Igor Mammedov |
Subject: |
[Qemu-devel] [PATCH 6/9] acpi/piix4pm: convert ACPI PCI hotplug to use hotplug-handler API |
Date: |
Tue, 14 Jan 2014 17:55:51 +0100 |
Split piix4_device_hotplug() into hotplug/unplug callbacks
and register them as "hotplug-handler" interface implementation of
PIIX4_PM device.
Replace pci_bus_hotplug() wiring with setting link on
PCI BUS "hotplug-handler" property to PIIX4_PM device.
Signed-off-by: Igor Mammedov <address@hidden>
---
v2:
* use error_abort to make error handling less verbose
---
hw/acpi/piix4.c | 68 ++++++++++++++++++++++++++++--------------------------
1 files changed, 35 insertions(+), 33 deletions(-)
diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index c292753..20b1ea3 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -30,6 +30,8 @@
#include "hw/nvram/fw_cfg.h"
#include "exec/address-spaces.h"
#include "hw/acpi/piix4.h"
+#include "qapi/qmp/qerror.h"
+#include "hw/hotplug.h"
//#define DEBUG
@@ -107,7 +109,7 @@ typedef struct PIIX4PMState {
OBJECT_CHECK(PIIX4PMState, (obj), TYPE_PIIX4_PM)
static void piix4_acpi_system_hot_add_init(MemoryRegion *parent,
- PCIBus *bus, PIIX4PMState *s);
+ BusState *bus, PIIX4PMState *s);
#define ACPI_ENABLE 0xf1
#define ACPI_DISABLE 0xf0
@@ -459,7 +461,7 @@ static int piix4_pm_initfn(PCIDevice *dev)
qemu_add_machine_init_done_notifier(&s->machine_ready);
qemu_register_reset(piix4_reset, s);
- piix4_acpi_system_hot_add_init(pci_address_space_io(dev), dev->bus, s);
+ piix4_acpi_system_hot_add_init(pci_address_space_io(dev), BUS(dev->bus),
s);
piix4_pm_add_propeties(s);
return 0;
@@ -645,11 +647,8 @@ static void piix4_cpu_added_req(Notifier *n, void *opaque)
piix4_cpu_hotplug_req(s, CPU(opaque), PLUG);
}
-static int piix4_device_hotplug(DeviceState *qdev, PCIDevice *dev,
- PCIHotplugState state);
-
static void piix4_acpi_system_hot_add_init(MemoryRegion *parent,
- PCIBus *bus, PIIX4PMState *s)
+ BusState *bus, PIIX4PMState *s)
{
CPUState *cpu;
@@ -661,7 +660,9 @@ static void piix4_acpi_system_hot_add_init(MemoryRegion
*parent,
"acpi-pci-hotplug", PCI_HOTPLUG_SIZE);
memory_region_add_subregion(parent, PCI_HOTPLUG_ADDR,
&s->io_pci);
- pci_bus_hotplug(bus, piix4_device_hotplug, DEVICE(s));
+ object_property_set_link(OBJECT(bus), OBJECT(s),
+ QDEV_HOTPLUG_HANDLER_PROPERTY, &error_abort);
+ bus->allow_hotplug = 1;
CPU_FOREACH(cpu) {
CPUClass *cc = CPU_GET_CLASS(cpu);
@@ -677,41 +678,35 @@ static void piix4_acpi_system_hot_add_init(MemoryRegion
*parent,
qemu_register_cpu_added_notifier(&s->cpu_added_notifier);
}
-static void enable_device(PIIX4PMState *s, int slot)
+static void piix4_pci_device_hotplug_cb(HotplugHandler *hotplug_dev,
+ DeviceState *dev, Error **errp)
{
- s->ar.gpe.sts[0] |= PIIX4_PCI_HOTPLUG_STATUS;
- s->pci0_slot_device_present |= (1U << slot);
-}
-
-static void disable_device(PIIX4PMState *s, int slot)
-{
- s->ar.gpe.sts[0] |= PIIX4_PCI_HOTPLUG_STATUS;
- s->pci0_status.down |= (1U << slot);
-}
-
-static int piix4_device_hotplug(DeviceState *qdev, PCIDevice *dev,
- PCIHotplugState state)
-{
- int slot = PCI_SLOT(dev->devfn);
- PIIX4PMState *s = PIIX4_PM(qdev);
+ PCIDevice *pci_dev = PCI_DEVICE(dev);
+ int slot = PCI_SLOT(pci_dev->devfn);
+ PIIX4PMState *s = PIIX4_PM(hotplug_dev);
+ s->pci0_slot_device_present |= (1U << slot);
/* Don't send event when device is enabled during qemu machine creation:
* it is present on boot, no hotplug event is necessary. We do send an
* event when the device is disabled later. */
- if (state == PCI_COLDPLUG_ENABLED) {
- s->pci0_slot_device_present |= (1U << slot);
- return 0;
- }
-
- if (state == PCI_HOTPLUG_ENABLED) {
- enable_device(s, slot);
- } else {
- disable_device(s, slot);
+ if (!dev->hotplugged) {
+ return;
}
+ s->ar.gpe.sts[0] |= PIIX4_PCI_HOTPLUG_STATUS;
acpi_update_sci(&s->ar, s->irq);
+}
- return 0;
+static void piix4_pci_device_hot_unplug_cb(HotplugHandler *hotplug_dev,
+ DeviceState *dev, Error **errp)
+{
+ PCIDevice *pci_dev = PCI_DEVICE(dev);
+ int slot = PCI_SLOT(pci_dev->devfn);
+ PIIX4PMState *s = PIIX4_PM(hotplug_dev);
+
+ s->pci0_status.down |= (1U << slot);
+ s->ar.gpe.sts[0] |= PIIX4_PCI_HOTPLUG_STATUS;
+ acpi_update_sci(&s->ar, s->irq);
}
static Property piix4_pm_properties[] = {
@@ -726,6 +721,7 @@ static void piix4_pm_class_init(ObjectClass *klass, void
*data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+ HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(klass);
k->init = piix4_pm_initfn;
k->config_write = pm_write_config;
@@ -742,6 +738,8 @@ static void piix4_pm_class_init(ObjectClass *klass, void
*data)
*/
dc->cannot_instantiate_with_device_add_yet = true;
dc->hotpluggable = false;
+ hc->plug = piix4_pci_device_hotplug_cb;
+ hc->unplug = piix4_pci_device_hot_unplug_cb;
}
static const TypeInfo piix4_pm_info = {
@@ -749,6 +747,10 @@ static const TypeInfo piix4_pm_info = {
.parent = TYPE_PCI_DEVICE,
.instance_size = sizeof(PIIX4PMState),
.class_init = piix4_pm_class_init,
+ .interfaces = (InterfaceInfo[]) {
+ { TYPE_HOTPLUG_HANDLER },
+ { }
+ }
};
static void piix4_pm_register_types(void)
--
1.7.1
- [Qemu-devel] [PATCH 0/9 v4] Refactor PCI/SHPC/PCIE hotplug to use a more generic hotplug API, Igor Mammedov, 2014/01/14
- [Qemu-devel] [PATCH 1/9] define hotplug interface, Igor Mammedov, 2014/01/14
- [Qemu-devel] [PATCH 3/9] qdev: add "hotpluggable" property to Device, Igor Mammedov, 2014/01/14
- [Qemu-devel] [PATCH 2/9] qdev: add to BusState "hotplug-handler" link, Igor Mammedov, 2014/01/14
- [Qemu-devel] [PATCH 4/9] hw/acpi: move typeinfo to the file end, Igor Mammedov, 2014/01/14
- [Qemu-devel] [PATCH 5/9] qdev:pci: refactor PCIDevice to use generic "hotpluggable" property, Igor Mammedov, 2014/01/14
- [Qemu-devel] [PATCH 7/9] pci/shpc: convert SHPC hotplug to use hotplug-handler API, Igor Mammedov, 2014/01/14
- [Qemu-devel] [PATCH 8/9] pci/pcie: convert PCIE hotplug to use hotplug-handler API, Igor Mammedov, 2014/01/14
- [Qemu-devel] [PATCH 6/9] acpi/piix4pm: convert ACPI PCI hotplug to use hotplug-handler API,
Igor Mammedov <=
- [Qemu-devel] [PATCH 9/9] hw/pci: switch to a generic hotplug handling for PCIDevice, Igor Mammedov, 2014/01/14
- Re: [Qemu-devel] [PATCH 0/9 v4] Refactor PCI/SHPC/PCIE hotplug to use a more generic hotplug API, Michael S. Tsirkin, 2014/01/16