Signed-off-by: Hu Tao <hu...@cn.fujitsu.com> --- hw/i386/pc.c | 24 +----------------------- hw/i386/pc_piix.c | 5 ++--- hw/pci-host/piix.c | 39 +++++++++++++++++++++++++++++++-------- include/hw/i386/pc.h | 3 +-- 4 files changed, 35 insertions(+), 36 deletions(-)
diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 5e8f143..909307e 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1033,33 +1033,11 @@ FWCfgState *pc_memory_init(MemoryRegion *system_memory, MemoryRegion **ram_memory) { int linux_boot, i; - MemoryRegion *ram, *option_rom_mr; - MemoryRegion *ram_below_4g, *ram_above_4g; + MemoryRegion *option_rom_mr; FWCfgState *fw_cfg; linux_boot = (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 - * with older qemus that used qemu_ram_alloc(). - */ - ram = g_malloc(sizeof(*ram)); - memory_region_init_ram(ram, "pc.ram", - below_4g_mem_size + above_4g_mem_size); - vmstate_register_ram_global(ram); - *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) { - 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, - ram_above_4g); - } - /* Initialize PC system firmware */ pc_system_firmware_init(rom_memory); diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c index 1ca705c..4614c07 100644 --- a/hw/i386/pc_piix.c +++ b/hw/i386/pc_piix.c @@ -84,7 +84,6 @@ static void pc_init1(MemoryRegion *system_memory, BusState *idebus[MAX_IDE_BUS]; ISADevice *rtc_state; ISADevice *floppy; - MemoryRegion *ram_memory; MemoryRegion *pci_memory; MemoryRegion *rom_memory; DeviceState *icc_bridge; @@ -121,7 +120,7 @@ static void pc_init1(MemoryRegion *system_memory, if (pci_enabled) { pci_bus = i440fx_init(&piix3_devfn, &isa_bus, gsi, system_memory, system_io, ram_size, - &pci_memory, ram_memory); + &pci_memory); } else { pci_bus = NULL; isa_bus = isa_bus_new(NULL, system_io); @@ -140,7 +139,7 @@ static void pc_init1(MemoryRegion *system_memory, 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); + rom_memory, NULL); } if (kvm_irqchip_in_kernel()) { diff --git a/hw/pci-host/piix.c b/hw/pci-host/piix.c index 604a66e..5318ddc 100644 --- a/hw/pci-host/piix.c +++ b/hw/pci-host/piix.c @@ -96,6 +96,10 @@ struct I440FXPMCState { MemoryRegion smram_region; uint8_t smm_enabled; ram_addr_t ram_size; + MemoryRegion ram; + MemoryRegion ram_below_4g; + MemoryRegion ram_above_4g; + }; #define TYPE_I440FX_DEVICE "i440FX" @@ -250,18 +254,39 @@ static int i440fx_pmc_initfn(PCIDevice *dev) { I440FXPMCState *d = I440FX_PMC_DEVICE(dev); ram_addr_t ram_size; + hwaddr below_4g_mem_size, above_4g_mem_size; hwaddr pci_hole_start, pci_hole_size; hwaddr pci_hole64_start, pci_hole64_size; int i; g_assert(d->system_memory != NULL); - g_assert(d->ram_memory != NULL); if(d->ram_size > I440FX_PMC_PCI_HOLE) { - pci_hole_start = I440FX_PMC_PCI_HOLE; + below_4g_mem_size = I440FX_PMC_PCI_HOLE; + above_4g_mem_size = d->ram_size - I440FX_PMC_PCI_HOLE; } else { - pci_hole_start = d->ram_size; + below_4g_mem_size = d->ram_size; + above_4g_mem_size = 0; } + + /* 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(&d->ram, "pc.ram", + below_4g_mem_size + above_4g_mem_size); + vmstate_register_ram_global(&d->ram); + memory_region_init_alias(&d->ram_below_4g, "ram-below-4g", &d->ram, + 0, below_4g_mem_size); + memory_region_add_subregion(d->system_memory, 0, &d->ram_below_4g); + if (above_4g_mem_size > 0) { + memory_region_init_alias(&d->ram_above_4g, "ram-above-4g", &d->ram, + below_4g_mem_size, above_4g_mem_size); + memory_region_add_subregion(d->system_memory, I440FX_PMC_PCI_HOLE_END, + &d->ram_above_4g); + } + + pci_hole_start = below_4g_mem_size; pci_hole_size = I440FX_PMC_PCI_HOLE_END - pci_hole_start; pci_hole64_start = I440FX_PMC_PCI_HOLE_END + d->ram_size - pci_hole_start; @@ -316,8 +341,7 @@ static PCIBus *i440fx_common_init(const char *device_name, MemoryRegion *address_space_mem, MemoryRegion *address_space_io, ram_addr_t ram_size, - MemoryRegion **pci_address_space, - MemoryRegion *ram_memory) + MemoryRegion **pci_address_space) { PCIHostState *s; PIIX3State *piix3; @@ -332,7 +356,6 @@ static PCIBus *i440fx_common_init(const char *device_name, f = &i440fx->pmc; f->ram_size = ram_size; f->system_memory = address_space_mem; - f->ram_memory = ram_memory; object_property_add_child(qdev_get_machine(), "i440fx", OBJECT(i440fx), NULL); @@ -369,7 +392,7 @@ PCIBus *i440fx_init(int *piix3_devfn, MemoryRegion *address_space_mem, MemoryRegion *address_space_io, ram_addr_t ram_size, - MemoryRegion **pci_memory, MemoryRegion *ram_memory) + MemoryRegion **pci_memory) { PCIBus *b; @@ -377,7 +400,7 @@ PCIBus *i440fx_init(int *piix3_devfn, b = i440fx_common_init(TYPE_I440FX_PMC_DEVICE, piix3_devfn, isa_bus, pic, address_space_mem, address_space_io, ram_size, - pci_memory, ram_memory); + pci_memory); return b; } diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index fa14c49..702a63c 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -131,8 +131,7 @@ PCIBus *i440fx_init(int *piix_devfn, MemoryRegion *address_space_mem, MemoryRegion *address_space_io, ram_addr_t ram_size, - MemoryRegion **pci_memory, - MemoryRegion *ram_memory); + MemoryRegion **pci_memory); /* piix4.c */ extern PCIDevice *piix4_dev; -- 1.8.3.1