Patchwork [13/27] pc: pass PCInitArgs struct to pc_memory_init()

login
register
mail settings
Submitter Eduardo Habkost
Date Oct. 24, 2012, 5:49 p.m.
Message ID <1351101001-14589-14-git-send-email-ehabkost@redhat.com>
Download mbox | patch
Permalink /patch/193897/
State New
Headers show

Comments

Eduardo Habkost - Oct. 24, 2012, 5:49 p.m.
Instead of having a large list of arguments, just pass the PCInitArgs
struct to pc_memory_init().

This is being done mainly to facilitate the addition of an argument to
be used by bochs_bios_init() (enabling compatibility mode for APIC ID
generation).

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 hw/pc.c      | 34 +++++++++++++++-------------------
 hw/pc.h      | 16 ++++++++--------
 hw/pc_piix.c | 45 +++++++++++++++++++--------------------------
 3 files changed, 42 insertions(+), 53 deletions(-)

Patch

diff --git a/hw/pc.c b/hw/pc.c
index f92c19f..dce9ce1 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -876,21 +876,14 @@  void pc_cpus_init(PCInitArgs *args)
     }
 }
 
-void *pc_memory_init(MemoryRegion *system_memory,
-                    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,
-                    MemoryRegion **ram_memory)
+void *pc_memory_init(PCInitArgs *args)
 {
     int linux_boot, i;
     MemoryRegion *ram, *option_rom_mr;
     MemoryRegion *ram_below_4g, *ram_above_4g;
     void *fw_cfg;
 
-    linux_boot = (kernel_filename != NULL);
+    linux_boot = (args->qemu_args->kernel_filename != NULL);
 
     /* Allocate RAM.  We allocate it as a single memory region and use
      * aliases to address portions of it, mostly for backwards compatibility
@@ -898,29 +891,29 @@  void *pc_memory_init(MemoryRegion *system_memory,
      */
     ram = g_malloc(sizeof(*ram));
     memory_region_init_ram(ram, "pc.ram",
-                           below_4g_mem_size + above_4g_mem_size);
+                           args->below_4g_mem_size + args->above_4g_mem_size);
     vmstate_register_ram_global(ram);
-    *ram_memory = ram;
+    args->ram_memory = ram;
     ram_below_4g = g_malloc(sizeof(*ram_below_4g));
     memory_region_init_alias(ram_below_4g, "ram-below-4g", ram,
-                             0, below_4g_mem_size);
-    memory_region_add_subregion(system_memory, 0, ram_below_4g);
-    if (above_4g_mem_size > 0) {
+                             0, args->below_4g_mem_size);
+    memory_region_add_subregion(args->system_memory, 0, ram_below_4g);
+    if (args->above_4g_mem_size > 0) {
         ram_above_4g = g_malloc(sizeof(*ram_above_4g));
         memory_region_init_alias(ram_above_4g, "ram-above-4g", ram,
-                                 below_4g_mem_size, above_4g_mem_size);
-        memory_region_add_subregion(system_memory, 0x100000000ULL,
+                                 args->below_4g_mem_size, args->above_4g_mem_size);
+        memory_region_add_subregion(args->system_memory, 0x100000000ULL,
                                     ram_above_4g);
     }
 
 
     /* Initialize PC system firmware */
-    pc_system_firmware_init(rom_memory);
+    pc_system_firmware_init(args->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,
+    memory_region_add_subregion_overlap(args->rom_memory,
                                         PC_ROM_MIN_VGA,
                                         option_rom_mr,
                                         1);
@@ -929,7 +922,10 @@  void *pc_memory_init(MemoryRegion *system_memory,
     rom_set_fw(fw_cfg);
 
     if (linux_boot) {
-        load_linux(fw_cfg, kernel_filename, initrd_filename, kernel_cmdline, below_4g_mem_size);
+        load_linux(fw_cfg, args->qemu_args->kernel_filename,
+                   args->qemu_args->initrd_filename,
+                   args->qemu_args->kernel_cmdline,
+                   args->below_4g_mem_size);
     }
 
     for (i = 0; i < nb_option_roms; i++) {
diff --git a/hw/pc.h b/hw/pc.h
index 26388ba..53883f5 100644
--- a/hw/pc.h
+++ b/hw/pc.h
@@ -81,20 +81,20 @@  typedef struct PCInitArgs {
     QEMUMachineInitArgs *qemu_args;
     bool pci_enabled;
     bool kvmclock_enabled;
+
+    /* Memory regions & sizes: */
+    MemoryRegion *system_memory;
+    MemoryRegion *system_io;
+    MemoryRegion *rom_memory;
+    MemoryRegion *ram_memory;
+    ram_addr_t below_4g_mem_size, above_4g_mem_size;
 } PCInitArgs;
 
 void pc_register_ferr_irq(qemu_irq irq);
 void pc_acpi_smi_interrupt(void *opaque, int irq, int level);
 
 void pc_cpus_init(PCInitArgs *args);
-void *pc_memory_init(MemoryRegion *system_memory,
-                    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,
-                    MemoryRegion **ram_memory);
+void *pc_memory_init(PCInitArgs *args);
 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/hw/pc_piix.c b/hw/pc_piix.c
index 57d0c3b..7de8f0d 100644
--- a/hw/pc_piix.c
+++ b/hw/pc_piix.c
@@ -121,7 +121,6 @@  static void ioapic_init(GSIState *gsi_state)
 static void pc_init1(PCInitArgs *pc_args)
 {
     int i;
-    ram_addr_t below_4g_mem_size, above_4g_mem_size;
     PCIBus *pci_bus;
     ISABus *isa_bus;
     PCII440FXState *i440fx_state;
@@ -135,20 +134,16 @@  static void pc_init1(PCInitArgs *pc_args)
     BusState *idebus[MAX_IDE_BUS];
     ISADevice *rtc_state;
     ISADevice *floppy;
-    MemoryRegion *ram_memory;
     MemoryRegion *pci_memory;
-    MemoryRegion *rom_memory;
-    MemoryRegion *system_memory = get_system_memory();
-    MemoryRegion *system_io = get_system_io();
     void *fw_cfg = NULL;
     QEMUMachineInitArgs *qemu_args = pc_args->qemu_args;
     ram_addr_t ram_size = qemu_args->ram_size;
-    const char *kernel_filename = qemu_args->kernel_filename;
-    const char *kernel_cmdline = qemu_args->kernel_cmdline;
-    const char *initrd_filename = qemu_args->initrd_filename;
     const char *boot_device = qemu_args->boot_device;
     bool pci_enabled = pc_args->pci_enabled;
 
+    pc_args->system_memory = get_system_memory();
+    pc_args->system_io = get_system_io();
+
     pc_cpus_init(pc_args);
 
     if (pc_args->kvmclock_enabled) {
@@ -156,28 +151,26 @@  static void pc_init1(PCInitArgs *pc_args)
     }
 
     if (ram_size >= 0xe0000000 ) {
-        above_4g_mem_size = ram_size - 0xe0000000;
-        below_4g_mem_size = 0xe0000000;
+        pc_args->above_4g_mem_size = ram_size - 0xe0000000;
+        pc_args->below_4g_mem_size = 0xe0000000;
     } else {
-        above_4g_mem_size = 0;
-        below_4g_mem_size = ram_size;
+        pc_args->above_4g_mem_size = 0;
+        pc_args->below_4g_mem_size = ram_size;
     }
 
     if (pci_enabled) {
         pci_memory = g_new(MemoryRegion, 1);
         memory_region_init(pci_memory, "pci", INT64_MAX);
-        rom_memory = pci_memory;
+        pc_args->rom_memory = pci_memory;
     } else {
         pci_memory = NULL;
-        rom_memory = system_memory;
+        pc_args->rom_memory = pc_args->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, &ram_memory);
+        /* pc_memory_init() will set pc_args->ram_memory */
+        fw_cfg = pc_memory_init(pc_args);
     }
 
     gsi_state = g_malloc0(sizeof(*gsi_state));
@@ -191,18 +184,18 @@  static void pc_init1(PCInitArgs *pc_args)
 
     if (pci_enabled) {
         pci_bus = i440fx_init(&i440fx_state, &piix3_devfn, &isa_bus, gsi,
-                              system_memory, system_io, ram_size,
-                              below_4g_mem_size,
-                              0x100000000ULL - below_4g_mem_size,
-                              0x100000000ULL + above_4g_mem_size,
+                              pc_args->system_memory, pc_args->system_io,
+                              ram_size, pc_args->below_4g_mem_size,
+                              0x100000000ULL - pc_args->below_4g_mem_size,
+                              0x100000000ULL + pc_args->above_4g_mem_size,
                               (sizeof(hwaddr) == 4
                                ? 0
                                : ((uint64_t)1 << 62)),
-                              pci_memory, ram_memory);
+                              pci_memory, pc_args->ram_memory);
     } else {
         pci_bus = NULL;
         i440fx_state = NULL;
-        isa_bus = isa_bus_new(NULL, system_io);
+        isa_bus = isa_bus_new(NULL, pc_args->system_io);
         no_hpet = 1;
     }
     isa_bus_irqs(isa_bus, gsi);
@@ -264,8 +257,8 @@  static void pc_init1(PCInitArgs *pc_args)
 
     audio_init(isa_bus, pci_enabled ? pci_bus : NULL);
 
-    pc_cmos_init(below_4g_mem_size, above_4g_mem_size, boot_device,
-                 floppy, idebus[0], idebus[1], rtc_state);
+    pc_cmos_init(pc_args->below_4g_mem_size, pc_args->above_4g_mem_size,
+                 boot_device, floppy, idebus[0], idebus[1], rtc_state);
 
     if (pci_enabled && usb_enabled) {
         pci_create_simple(pci_bus, piix3_devfn + 2, "piix3-usb-uhci");