Patchwork [RFC,15/15] move bios loading to MemoryController and ISAPc

login
register
mail settings
Submitter Hu Tao
Date June 20, 2013, 10:15 a.m.
Message ID <7dc6870b7653222b1262bfdc6b4ac4c313801824.1371721792.git.hutao@cn.fujitsu.com>
Download mbox | patch
Permalink /patch/252854/
State New
Headers show

Comments

Hu Tao - June 20, 2013, 10:15 a.m.
Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
---
 hw/i386/pc.c            | 35 ++++++++++++++---------------------
 hw/i386/pc_piix.c       | 13 ++-----------
 hw/i386/pc_q35.c        | 13 ++-----------
 hw/isa/isa_pc.c         | 11 +++++++++++
 include/hw/i386/pc.h    |  7 +++----
 include/hw/isa/isa_pc.h |  1 +
 6 files changed, 33 insertions(+), 47 deletions(-)

Patch

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index c28baa2..5bb4989 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1023,36 +1023,19 @@  void pc_acpi_init(const char *default_dsdt)
     }
 }
 
-FWCfgState *pc_memory_init(MemoryRegion *system_memory,
-                           const char *kernel_filename,
+FWCfgState *pc_memory_init(const char *kernel_filename,
                            const char *kernel_cmdline,
                            const char *initrd_filename,
                            ram_addr_t below_4g_mem_size,
-                           ram_addr_t above_4g_mem_size,
-                           MemoryRegion *rom_memory)
+                           ram_addr_t above_4g_mem_size)
 {
-    int linux_boot, i;
-    MemoryRegion *option_rom_mr;
+    int i;
     FWCfgState *fw_cfg;
 
-    linux_boot = (kernel_filename != NULL);
-
-
-    /* Initialize PC system firmware */
-    pc_system_firmware_init(rom_memory);
-
-    option_rom_mr = g_malloc(sizeof(*option_rom_mr));
-    memory_region_init_ram(option_rom_mr, "pc.rom", PC_ROM_SIZE);
-    vmstate_register_ram_global(option_rom_mr);
-    memory_region_add_subregion_overlap(rom_memory,
-                                        PC_ROM_MIN_VGA,
-                                        option_rom_mr,
-                                        1);
-
     fw_cfg = bochs_bios_init();
     rom_set_fw(fw_cfg);
 
-    if (linux_boot) {
+    if (kernel_filename) {
         load_linux(fw_cfg, kernel_filename, initrd_filename, kernel_cmdline, below_4g_mem_size);
     }
 
@@ -1380,6 +1363,16 @@  static int memory_controller_init(PCIDevice *dev)
     dev->config[0x72] = 0x02;
 
     cpu_smm_register(c->set_smm, m);
+
+    pc_system_firmware_init(m->pci_address_space);
+
+    memory_region_init_ram(&m->option_roms, "pc.rom", PC_ROM_SIZE);
+    vmstate_register_ram_global(&m->option_roms);
+    memory_region_add_subregion_overlap(m->pci_address_space,
+                                        PC_ROM_MIN_VGA,
+                                        &m->option_roms,
+                                        1);
+
     return 0;
 }
 
diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 2e84cc2..fb056df 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -86,7 +86,6 @@  static void pc_init1(MemoryRegion *system_memory,
     ISADevice *rtc_state;
     ISADevice *floppy;
     MemoryRegion *pci_memory;
-    MemoryRegion *rom_memory;
     DeviceState *icc_bridge;
     FWCfgState *fw_cfg = NULL;
     ISAPc *isapc = NULL;
@@ -135,18 +134,10 @@  static void pc_init1(MemoryRegion *system_memory,
     }
     isa_bus_irqs(isa_bus, gsi);
 
-    if (pci_enabled) {
-        rom_memory = pci_memory;
-    } else {
-        rom_memory = system_memory;
-    }
-
     /* allocate ram and load rom/bios */
     if (!xen_enabled()) {
-        fw_cfg = pc_memory_init(system_memory,
-                                kernel_filename, kernel_cmdline, initrd_filename,
-                                below_4g_mem_size, above_4g_mem_size,
-                                rom_memory);
+        fw_cfg = pc_memory_init(kernel_filename, kernel_cmdline, initrd_filename,
+                                below_4g_mem_size, above_4g_mem_size);
     }
 
     if (kvm_irqchip_in_kernel()) {
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index fde83b4..5fe14bb 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -64,7 +64,6 @@  static void pc_q35_init(QEMUMachineInitArgs *args)
     BusState *idebus[MAX_SATA_PORTS];
     ISADevice *rtc_state;
     ISADevice *floppy;
-    MemoryRegion *rom_memory;
     GSIState *gsi_state;
     ISABus *isa_bus;
     int pci_enabled = 1;
@@ -96,18 +95,10 @@  static void pc_q35_init(QEMUMachineInitArgs *args)
         below_4g_mem_size = ram_size;
     }
 
-    /* pci enabled */
-    if (pci_enabled) {
-        rom_memory = &q35_host->pci_address_space;
-    } else {
-        rom_memory = get_system_memory();
-    }
-
     /* allocate ram and load rom/bios */
     if (!xen_enabled()) {
-        pc_memory_init(get_system_memory(), kernel_filename, kernel_cmdline,
-                       initrd_filename, below_4g_mem_size, above_4g_mem_size,
-                       rom_memory);
+        pc_memory_init(kernel_filename, kernel_cmdline,
+                       initrd_filename, below_4g_mem_size, above_4g_mem_size);
     }
 
     /* irq lines */
diff --git a/hw/isa/isa_pc.c b/hw/isa/isa_pc.c
index f73cddb..ae9f2c8 100644
--- a/hw/isa/isa_pc.c
+++ b/hw/isa/isa_pc.c
@@ -1,4 +1,6 @@ 
+#include "hw/i386/pc.h"
 #include "hw/isa/isa_pc.h"
+#include "hw/loader.h"
 
 static void isa_pc_realize(DeviceState *dev, Error **errp)
 {
@@ -17,6 +19,15 @@  static void isa_pc_realize(DeviceState *dev, Error **errp)
     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);
+
+    pc_system_firmware_init(isapc->address_space_mem);
+
+    memory_region_init_ram(&isapc->option_roms, "pc.rom", PC_ROM_SIZE);
+    vmstate_register_ram_global(&isapc->option_roms);
+    memory_region_add_subregion_overlap(isapc->address_space_mem,
+                                        PC_ROM_MIN_VGA,
+                                        &isapc->option_roms,
+                                        1);
 }
 
 static void isa_pc_class_init(ObjectClass *klass, void *data)
diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index f06008b..5d36558 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -36,6 +36,7 @@  typedef struct MemoryController {
     MemoryRegion *system_memory;
     MemoryRegion *pci_address_space;
     MemoryRegion *ram_memory;
+    MemoryRegion option_roms;
     MemoryRegion pci_hole;
     MemoryRegion pci_hole_64bit;
     PAMMemoryRegion pam_regions[13];
@@ -128,13 +129,11 @@  void pc_acpi_smi_interrupt(void *opaque, int irq, int level);
 void pc_cpus_init(const char *cpu_model, DeviceState *icc_bridge);
 void pc_hot_add_cpu(const int64_t id, Error **errp);
 void pc_acpi_init(const char *default_dsdt);
-FWCfgState *pc_memory_init(MemoryRegion *system_memory,
-                           const char *kernel_filename,
+FWCfgState *pc_memory_init(const char *kernel_filename,
                            const char *kernel_cmdline,
                            const char *initrd_filename,
                            ram_addr_t below_4g_mem_size,
-                           ram_addr_t above_4g_mem_size,
-                           MemoryRegion *rom_memory);
+                           ram_addr_t above_4g_mem_size);
 qemu_irq *pc_allocate_cpu_irq(void);
 DeviceState *pc_vga_init(ISABus *isa_bus, PCIBus *pci_bus);
 void pc_basic_device_init(ISABus *isa_bus, qemu_irq *gsi,
diff --git a/include/hw/isa/isa_pc.h b/include/hw/isa/isa_pc.h
index 91a0701..33a2e95 100644
--- a/include/hw/isa/isa_pc.h
+++ b/include/hw/isa/isa_pc.h
@@ -19,6 +19,7 @@  struct ISAPc {
 
     MemoryRegion *address_space_mem;
     MemoryRegion *address_space_io;
+    MemoryRegion option_roms;
     MemoryRegion ram;
     ram_addr_t ram_size;
 };