Patchwork [50/61] pci hotadd, acpi_piix4: remove global variables.

login
register
mail settings
Submitter Isaku Yamahata
Date Sept. 30, 2009, 10:18 a.m.
Message ID <1254305917-14784-51-git-send-email-yamahata@valinux.co.jp>
Download mbox | patch
Permalink /patch/34527/
State Superseded
Headers show

Comments

Isaku Yamahata - Sept. 30, 2009, 10:18 a.m.
remove global variables.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
---
 hw/acpi_piix4.c |   53 +++++++++++++++++++++++++++++++++--------------------
 hw/pc.h         |    1 -
 hw/pc_piix.c    |    2 --
 3 files changed, 33 insertions(+), 23 deletions(-)

Patch

diff --git a/hw/acpi_piix4.c b/hw/acpi_piix4.c
index c11e1b9..38c6a53 100644
--- a/hw/acpi_piix4.c
+++ b/hw/acpi_piix4.c
@@ -47,11 +47,11 @@  typedef struct PIIX4PMState {
     qemu_irq irq;
 } PIIX4PMState;
 
+static void piix4_acpi_system_hot_add_init(PIIX4PMState *s);
+
 #define ACPI_ENABLE 0xf1
 #define ACPI_DISABLE 0xf0
 
-static PIIX4PMState *pm_state;
-
 static uint32_t get_pmtmr(PIIX4PMState *s)
 {
     uint32_t d;
@@ -328,7 +328,8 @@  i2c_bus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base,
     s = (PIIX4PMState *)pci_register_device(bus,
                                          "PM", sizeof(PIIX4PMState),
                                          devfn, NULL, pm_write_config);
-    pm_state = s;
+    piix4_acpi_system_hot_add_init(s);
+
     pci_conf = s->dev.config;
     pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_INTEL);
     pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82371AB_3);
@@ -393,9 +394,6 @@  struct pci_status {
     uint32_t down;
 };
 
-static struct gpe_regs gpe;
-static struct pci_status pci0_status;
-
 static uint32_t gpe_read_val(uint16_t val, uint32_t addr)
 {
     if (addr & 1)
@@ -526,20 +524,33 @@  static void pciej_write(void *opaque, uint32_t addr, uint32_t val)
 #endif
 }
 
-static void piix4_device_hot_add(int bus, int slot, int state, void* opaque);
+static void piix4_device_hot_add(int bus, int slot, int state, void *opaque);
 
-void piix4_acpi_system_hot_add_init(void)
+struct piix4_hot_add {
+    struct gpe_regs *gpe;
+    struct pci_status *pci0_status;
+    PIIX4PMState *pm_state;
+};
+
+static void piix4_acpi_system_hot_add_init(PIIX4PMState *s)
 {
-    register_ioport_write(GPE_BASE, 4, 1, gpe_writeb, &gpe);
-    register_ioport_read(GPE_BASE, 4, 1,  gpe_readb, &gpe);
+    struct gpe_regs *gpe = qemu_mallocz(sizeof(*gpe));
+    struct pci_status *pci0_status = qemu_mallocz(sizeof(*pci0_status));
+    struct piix4_hot_add *hot_add_arg = qemu_malloc(sizeof(*hot_add_arg));
+    hot_add_arg->gpe = gpe;
+    hot_add_arg->pci0_status = pci0_status;
+    hot_add_arg->pm_state = s;
 
-    register_ioport_write(PCI_BASE, 8, 4, pcihotplug_write, &pci0_status);
-    register_ioport_read(PCI_BASE, 8, 4,  pcihotplug_read, &pci0_status);
+    register_ioport_write(GPE_BASE, 4, 1, gpe_writeb, gpe);
+    register_ioport_read(GPE_BASE, 4, 1,  gpe_readb, gpe);
+
+    register_ioport_write(PCI_BASE, 8, 4, pcihotplug_write, 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_read(PCI_EJ_BASE, 4, 4,  pciej_read, NULL);
 
-    qemu_system_device_hot_add_register(piix4_device_hot_add, NULL);
+    qemu_system_device_hot_add_register(piix4_device_hot_add, hot_add_arg);
 }
 
 static void enable_device(struct pci_status *p, struct gpe_regs *g, int slot)
@@ -556,14 +567,16 @@  static void disable_device(struct pci_status *p, struct gpe_regs *g, int slot)
 
 static void piix4_device_hot_add(int bus, int slot, int state, void *opaque)
 {
-    pci0_status.up = 0;
-    pci0_status.down = 0;
+    struct piix4_hot_add *hot_add_arg = opaque;
+
+    hot_add_arg->pci0_status->up = 0;
+    hot_add_arg->pci0_status->down = 0;
     if (state)
-        enable_device(&pci0_status, &gpe, slot);
+        enable_device(hot_add_arg->pci0_status, hot_add_arg->gpe, slot);
     else
-        disable_device(&pci0_status, &gpe, slot);
-    if (gpe.en & 2) {
-        qemu_set_irq(pm_state->irq, 1);
-        qemu_set_irq(pm_state->irq, 0);
+        disable_device(hot_add_arg->pci0_status, hot_add_arg->gpe, slot);
+    if (hot_add_arg->gpe->en & 2) {
+        qemu_set_irq(hot_add_arg->pm_state->irq, 1);
+        qemu_set_irq(hot_add_arg->pm_state->irq, 0);
     }
 }
diff --git a/hw/pc.h b/hw/pc.h
index dcb62a4..cf34db6 100644
--- a/hw/pc.h
+++ b/hw/pc.h
@@ -148,7 +148,6 @@  int acpi_table_add(const char *table_desc);
 i2c_bus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base,
                        qemu_irq sci_irq);
 void piix4_smbus_register_device(SMBusDevice *dev, uint8_t addr);
-void piix4_acpi_system_hot_add_init(void);
 
 /* hpet.c */
 extern int no_hpet;
diff --git a/hw/pc_piix.c b/hw/pc_piix.c
index 4c8bb27..55b53d0 100644
--- a/hw/pc_piix.c
+++ b/hw/pc_piix.c
@@ -108,8 +108,6 @@  static void pc_init1(ram_addr_t ram_size,
             pci_nic_init(nd, "e1000", NULL);
     }
 
-    piix4_acpi_system_hot_add_init();
-
     if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) {
         fprintf(stderr, "qemu: too many IDE bus\n");
         exit(1);