ioapic: convert to qdev
authorBlue Swirl <blauwirbel@gmail.com>
Sat, 19 Jun 2010 07:41:43 +0000 (07:41 +0000)
committerBlue Swirl <blauwirbel@gmail.com>
Sat, 19 Jun 2010 07:41:43 +0000 (07:41 +0000)
Convert to qdev.

Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
hw/apic.h
hw/ioapic.c
hw/pc.h
hw/pc_piix.c

index e1954f45844051c88cc8cdc21f954ba4f2716356..dc41400b4022f5149bde19259195af8df9589b25 100644 (file)
--- a/hw/apic.h
+++ b/hw/apic.h
@@ -1,7 +1,6 @@
 #ifndef APIC_H
 #define APIC_H
 
-typedef struct IOAPICState IOAPICState;
 void apic_deliver_irq(uint8_t dest, uint8_t dest_mode,
                              uint8_t delivery_mode,
                              uint8_t vector_num, uint8_t polarity,
@@ -10,7 +9,6 @@ int apic_init(CPUState *env);
 int apic_accept_pic_intr(CPUState *env);
 void apic_deliver_pic_intr(CPUState *env, int level);
 int apic_get_interrupt(CPUState *env);
-qemu_irq *ioapic_init(void);
 void apic_reset_irq_delivered(void);
 int apic_get_irq_delivered(void);
 
index e3f8a46e48c59d6e193033ba6a1b392e3b2cc7a5..5ae21e910f3451f0f51dcea01ee8edad7aea7dac 100644 (file)
@@ -25,6 +25,7 @@
 #include "apic.h"
 #include "qemu-timer.h"
 #include "host-utils.h"
+#include "sysbus.h"
 
 //#define DEBUG_IOAPIC
 
@@ -35,7 +36,6 @@
 #define DPRINTF(fmt, ...)
 #endif
 
-#define IOAPIC_NUM_PINS                        0x18
 #define IOAPIC_LVT_MASKED              (1<<16)
 
 #define IOAPIC_TRIGGER_EDGE            0
 #define IOAPIC_DM_SIPI                 0x5
 #define IOAPIC_DM_EXTINT               0x7
 
+typedef struct IOAPICState IOAPICState;
+
 struct IOAPICState {
+    SysBusDevice busdev;
     uint8_t id;
     uint8_t ioregsel;
 
@@ -209,12 +212,14 @@ static const VMStateDescription vmstate_ioapic = {
     }
 };
 
-static void ioapic_reset(void *opaque)
+static void ioapic_reset(DeviceState *d)
 {
-    IOAPICState *s = opaque;
+    IOAPICState *s = DO_UPCAST(IOAPICState, busdev.qdev, d);
     int i;
 
-    memset(s, 0, sizeof(*s));
+    s->id = 0;
+    s->ioregsel = 0;
+    s->irr = 0;
     for(i = 0; i < IOAPIC_NUM_PINS; i++)
         s->ioredtbl[i] = 1 << 16; /* mask LVT */
 }
@@ -231,22 +236,32 @@ static CPUWriteMemoryFunc * const ioapic_mem_write[3] = {
     ioapic_mem_writel,
 };
 
-qemu_irq *ioapic_init(void)
+static int ioapic_init1(SysBusDevice *dev)
 {
-    IOAPICState *s;
-    qemu_irq *irq;
+    IOAPICState *s = FROM_SYSBUS(IOAPICState, dev);
     int io_memory;
 
-    s = qemu_mallocz(sizeof(IOAPICState));
-    ioapic_reset(s);
-
     io_memory = cpu_register_io_memory(ioapic_mem_read,
                                        ioapic_mem_write, s);
-    cpu_register_physical_memory(0xfec00000, 0x1000, io_memory);
+    sysbus_init_mmio(dev, 0x1000, io_memory);
 
-    vmstate_register(0, &vmstate_ioapic, s);
-    qemu_register_reset(ioapic_reset, s);
-    irq = qemu_allocate_irqs(ioapic_set_irq, s, IOAPIC_NUM_PINS);
+    qdev_init_gpio_in(&dev->qdev, ioapic_set_irq, IOAPIC_NUM_PINS);
 
-    return irq;
+    return 0;
 }
+
+static SysBusDeviceInfo ioapic_info = {
+    .init = ioapic_init1,
+    .qdev.name = "ioapic",
+    .qdev.size = sizeof(IOAPICState),
+    .qdev.vmsd = &vmstate_ioapic,
+    .qdev.reset = ioapic_reset,
+    .qdev.no_user = 1,
+};
+
+static void ioapic_register_devices(void)
+{
+    sysbus_register_withprop(&ioapic_info);
+}
+
+device_init(ioapic_register_devices)
diff --git a/hw/pc.h b/hw/pc.h
index 0e52933eebcf56c8bc8e21676a2fb73feea444e0..ccfd7add99c6c93b7cf746ac47c934319056cd88 100644 (file)
--- a/hw/pc.h
+++ b/hw/pc.h
@@ -39,9 +39,11 @@ void pic_info(Monitor *mon);
 void irq_info(Monitor *mon);
 
 /* ISA */
+#define IOAPIC_NUM_PINS 0x18
+
 typedef struct isa_irq_state {
     qemu_irq *i8259;
-    qemu_irq *ioapic;
+    qemu_irq ioapic[IOAPIC_NUM_PINS];
 } IsaIrqState;
 
 void isa_irq_handler(void *opaque, int n, int level);
index dc46846923aa341676e10d665267134ad348f6e5..68040b7394600631a75f6e48df90fabad8f8a8c2 100644 (file)
@@ -33,6 +33,7 @@
 #include "ide.h"
 #include "kvm.h"
 #include "sysemu.h"
+#include "sysbus.h"
 
 #define MAX_IDE_BUS 2
 
@@ -40,6 +41,22 @@ static const int ide_iobase[MAX_IDE_BUS] = { 0x1f0, 0x170 };
 static const int ide_iobase2[MAX_IDE_BUS] = { 0x3f6, 0x376 };
 static const int ide_irq[MAX_IDE_BUS] = { 14, 15 };
 
+static void ioapic_init(IsaIrqState *isa_irq_state)
+{
+    DeviceState *dev;
+    SysBusDevice *d;
+    unsigned int i;
+
+    dev = qdev_create(NULL, "ioapic");
+    qdev_init_nofail(dev);
+    d = sysbus_from_qdev(dev);
+    sysbus_mmio_map(d, 0, 0xfec00000);
+
+    for (i = 0; i < IOAPIC_NUM_PINS; i++) {
+        isa_irq_state->ioapic[i] = qdev_get_gpio_in(dev, i);
+    }
+}
+
 /* PC hardware initialisation */
 static void pc_init1(ram_addr_t ram_size,
                      const char *boot_device,
@@ -77,7 +94,7 @@ static void pc_init1(ram_addr_t ram_size,
     isa_irq_state = qemu_mallocz(sizeof(*isa_irq_state));
     isa_irq_state->i8259 = i8259;
     if (pci_enabled) {
-        isa_irq_state->ioapic = ioapic_init();
+        ioapic_init(isa_irq_state);
     }
     isa_irq = qemu_allocate_irqs(isa_irq_handler, isa_irq_state, 24);