Patchwork [V10,22/27] pci hotplug: add argument to pci hot plug callback.

login
register
mail settings
Submitter Isaku Yamahata
Date Dec. 24, 2009, 8:09 a.m.
Message ID <1261642160-22754-23-git-send-email-yamahata@valinux.co.jp>
Download mbox | patch
Permalink /patch/41748/
State New
Headers show

Comments

Isaku Yamahata - Dec. 24, 2009, 8:09 a.m.
The argument will be used later to remove global variable.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
---
 hw/acpi_piix4.c |    6 +++---
 hw/pci.c        |    8 +++++---
 hw/pci.h        |    4 ++--
 3 files changed, 10 insertions(+), 8 deletions(-)
Gerd Hoffmann - Jan. 4, 2010, 2:56 p.m.
On 12/24/09 09:09, Isaku Yamahata wrote:
> The argument will be used later to remove global variable.

> -static int piix4_device_hotplug(PCIDevice *dev, int state);
> +static int piix4_device_hotplug(void *opaque, PCIDevice *dev, int state);

You are using that to pass the piix4-pm device state.  How about using 
"DeviceState*" instead of "void*" then?

cheers,
   Gerd
Isaku Yamahata - Jan. 5, 2010, 5:34 a.m.
On Mon, Jan 04, 2010 at 03:56:50PM +0100, Gerd Hoffmann wrote:
> On 12/24/09 09:09, Isaku Yamahata wrote:
>> The argument will be used later to remove global variable.
>
>> -static int piix4_device_hotplug(PCIDevice *dev, int state);
>> +static int piix4_device_hotplug(void *opaque, PCIDevice *dev, int state);
>
> You are using that to pass the piix4-pm device state.  How about using  
> "DeviceState*" instead of "void*" then?

Ok. I'll use DeviceState*.

Patch

diff --git a/hw/acpi_piix4.c b/hw/acpi_piix4.c
index 0083731..94bbe59 100644
--- a/hw/acpi_piix4.c
+++ b/hw/acpi_piix4.c
@@ -562,7 +562,7 @@  static void pciej_write(void *opaque, uint32_t addr, uint32_t val)
 #endif
 }
 
-static int piix4_device_hotplug(PCIDevice *dev, int state);
+static int piix4_device_hotplug(void *opaque, PCIDevice *dev, int state);
 
 void piix4_acpi_system_hot_add_init(PCIBus *bus)
 {
@@ -575,7 +575,7 @@  void piix4_acpi_system_hot_add_init(PCIBus *bus)
     register_ioport_write(PCI_EJ_BASE, 4, 4, pciej_write, bus);
     register_ioport_read(PCI_EJ_BASE, 4, 4,  pciej_read, bus);
 
-    pci_bus_hotplug(bus, piix4_device_hotplug);
+    pci_bus_hotplug(bus, piix4_device_hotplug, NULL);
 }
 
 static void enable_device(struct pci_status *p, struct gpe_regs *g, int slot)
@@ -590,7 +590,7 @@  static void disable_device(struct pci_status *p, struct gpe_regs *g, int slot)
     p->down |= (1 << slot);
 }
 
-static int piix4_device_hotplug(PCIDevice *dev, int state)
+static int piix4_device_hotplug(void *opaque, PCIDevice *dev, int state)
 {
     int slot = PCI_SLOT(dev->devfn);
 
diff --git a/hw/pci.c b/hw/pci.c
index 9cc5a6a..6fc716a 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -41,6 +41,7 @@  struct PCIBus {
     pci_set_irq_fn set_irq;
     pci_map_irq_fn map_irq;
     pci_hotplug_fn hotplug;
+    void *hotplug_opaque;
     uint32_t config_reg; /* XXX: suppress */
     void *irq_opaque;
     PCIDevice *devices[256];
@@ -232,10 +233,11 @@  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]));
 }
 
-void pci_bus_hotplug(PCIBus *bus, pci_hotplug_fn hotplug)
+void pci_bus_hotplug(PCIBus *bus, pci_hotplug_fn hotplug, void *opaque)
 {
     bus->qbus.allow_hotplug = 1;
     bus->hotplug = hotplug;
+    bus->hotplug_opaque = opaque;
 }
 
 PCIBus *pci_register_bus(DeviceState *parent, const char *name,
@@ -1371,7 +1373,7 @@  static int pci_qdev_init(DeviceState *qdev, DeviceInfo *base)
     pci_add_option_rom(pci_dev);
 
     if (qdev->hotplugged)
-        bus->hotplug(pci_dev, 1);
+        bus->hotplug(bus->hotplug_opaque, pci_dev, 1);
     return 0;
 }
 
@@ -1379,7 +1381,7 @@  static int pci_unplug_device(DeviceState *qdev)
 {
     PCIDevice *dev = DO_UPCAST(PCIDevice, qdev, qdev);
 
-    dev->bus->hotplug(dev, 0);
+    dev->bus->hotplug(dev->bus->hotplug_opaque, dev, 0);
     return 0;
 }
 
diff --git a/hw/pci.h b/hw/pci.h
index e52e632..3d6f779 100644
--- a/hw/pci.h
+++ b/hw/pci.h
@@ -275,13 +275,13 @@  int pci_device_load(PCIDevice *s, QEMUFile *f);
 
 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_hotplug_fn)(PCIDevice *pci_dev, int state);
+typedef int (*pci_hotplug_fn)(void *opaque, PCIDevice *pci_dev, int state);
 void pci_bus_new_inplace(PCIBus *bus, 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 *irq_opaque, int nirq);
-void pci_bus_hotplug(PCIBus *bus, pci_hotplug_fn hotplug);
+void pci_bus_hotplug(PCIBus *bus, pci_hotplug_fn hotplug, void *opaque);
 PCIBus *pci_register_bus(DeviceState *parent, const char *name,
                          pci_set_irq_fn set_irq, pci_map_irq_fn map_irq,
                          void *irq_opaque, int devfn_min, int nirq);