qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH RFC 11/15] introduce ISAPc


From: Hu Tao
Subject: [Qemu-devel] [PATCH RFC 11/15] introduce ISAPc
Date: Thu, 20 Jun 2013 18:15:10 +0800

Previous refactor breaks isapc. This patch introduces ISAPc and move
isapc initializing code to ISAPc.

Signed-off-by: Hu Tao <address@hidden>
---
 hw/i386/pc_piix.c       | 15 +++++++++++----
 hw/isa/Makefile.objs    |  2 +-
 hw/isa/isa_pc.c         | 42 ++++++++++++++++++++++++++++++++++++++++++
 include/hw/isa/isa_pc.h | 26 ++++++++++++++++++++++++++
 4 files changed, 80 insertions(+), 5 deletions(-)
 create mode 100644 hw/isa/isa_pc.c
 create mode 100644 include/hw/isa/isa_pc.h

diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 77d7ef0..2e84cc2 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -49,6 +49,7 @@
 #ifdef CONFIG_XEN
 #  include <xen/hvm/hvm_info_table.h>
 #endif
+#include "hw/isa/isa_pc.h"
 
 #define MAX_IDE_BUS 2
 
@@ -72,7 +73,7 @@ static void pc_init1(MemoryRegion *system_memory,
 {
     int i;
     ram_addr_t below_4g_mem_size, above_4g_mem_size;
-    PCIBus *pci_bus;
+    PCIBus *pci_bus = NULL;
     ISABus *isa_bus;
     int piix3_devfn = -1;
     qemu_irq *cpu_irq;
@@ -88,6 +89,7 @@ static void pc_init1(MemoryRegion *system_memory,
     MemoryRegion *rom_memory;
     DeviceState *icc_bridge;
     FWCfgState *fw_cfg = NULL;
+    ISAPc *isapc = NULL;
 
     icc_bridge = qdev_create(NULL, TYPE_ICC_BRIDGE);
     object_property_add_child(qdev_get_machine(), "icc-bridge",
@@ -122,8 +124,13 @@ static void pc_init1(MemoryRegion *system_memory,
                               system_memory, system_io, ram_size,
                               &pci_memory);
     } else {
-        pci_bus = NULL;
-        isa_bus = isa_bus_new(NULL, system_io);
+        isapc = ISA_PC(object_new(TYPE_ISA_PC));
+        isapc->ram_size = ram_size;
+        isapc->address_space_mem = system_memory;
+        isapc->address_space_io = system_io;
+        qdev_init_nofail(DEVICE(isapc));
+
+        isa_bus = isapc->bus;
         no_hpet = 1;
     }
     isa_bus_irqs(isa_bus, gsi);
@@ -161,7 +168,7 @@ static void pc_init1(MemoryRegion *system_memory,
 
     pc_register_ferr_irq(gsi[13]);
 
-    pc_vga_init(isa_bus, pci_enabled ? pci_bus : NULL);
+    pc_vga_init(isa_bus, pci_bus);
     if (xen_enabled()) {
         pci_create_simple(pci_bus, -1, "xen-platform");
     }
diff --git a/hw/isa/Makefile.objs b/hw/isa/Makefile.objs
index 193746a..99e6a4f 100644
--- a/hw/isa/Makefile.objs
+++ b/hw/isa/Makefile.objs
@@ -1,4 +1,4 @@
-common-obj-y += isa-bus.o
+common-obj-y += isa-bus.o isa_pc.o
 common-obj-$(CONFIG_APM) += apm.o
 common-obj-$(CONFIG_I82378) += i82378.o
 common-obj-$(CONFIG_ISA_MMIO) += isa_mmio.o
diff --git a/hw/isa/isa_pc.c b/hw/isa/isa_pc.c
new file mode 100644
index 0000000..f73cddb
--- /dev/null
+++ b/hw/isa/isa_pc.c
@@ -0,0 +1,42 @@
+#include "hw/isa/isa_pc.h"
+
+static void isa_pc_realize(DeviceState *dev, Error **errp)
+{
+    ISAPc *isapc = ISA_PC(dev);
+
+    g_assert(isapc->address_space_mem != NULL);
+    g_assert(isapc->address_space_io != NULL);
+    g_assert(isapc->ram_size > 0);
+
+    isapc->bus = isa_bus_new(NULL, isapc->address_space_io);
+
+    /* Allocate RAM.  We allocate it as a single memory region and use
+     * aliases to address portions of it, mostly for backwards compatibility
+     * with older qemus that used qemu_ram_alloc().
+     */
+    memory_region_init_ram(&isapc->ram, "pc.ram", isapc->ram_size);
+    vmstate_register_ram_global(&isapc->ram);
+    memory_region_add_subregion(isapc->address_space_mem, 0, &isapc->ram);
+}
+
+static void isa_pc_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+
+    dc->realize = isa_pc_realize;
+    dc->no_user = 1;
+}
+
+static const TypeInfo isa_pc_type_info = {
+    .name = TYPE_ISA_PC,
+    .parent = TYPE_DEVICE,
+    .instance_size = sizeof(ISAPc),
+    .class_init = isa_pc_class_init,
+};
+
+static void isa_pc_register_types(void)
+{
+    type_register_static(&isa_pc_type_info);
+}
+
+type_init(isa_pc_register_types)
diff --git a/include/hw/isa/isa_pc.h b/include/hw/isa/isa_pc.h
new file mode 100644
index 0000000..91a0701
--- /dev/null
+++ b/include/hw/isa/isa_pc.h
@@ -0,0 +1,26 @@
+#ifndef ISA_PC_H
+#define ISA_PC_H
+
+#include "qom/object.h"
+#include "exec/memory.h"
+#include "hw/isa/isa.h"
+
+#define TYPE_ISA_PC "isa-pc"
+#define ISA_PC(obj) OBJECT_CHECK(ISAPc, (obj), TYPE_ISA_PC)
+
+typedef struct ISAPc ISAPc;
+
+struct ISAPc {
+    /*< private >*/
+    Object parent_obj;
+    /*< public >*/
+
+    ISABus *bus;
+
+    MemoryRegion *address_space_mem;
+    MemoryRegion *address_space_io;
+    MemoryRegion ram;
+    ram_addr_t ram_size;
+};
+
+#endif
-- 
1.8.3.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]