From patchwork Thu Jan 26 19:01:00 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Liguori X-Patchwork-Id: 138038 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (unknown [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id EC8AFB6EF7 for ; Fri, 27 Jan 2012 07:47:07 +1100 (EST) Received: from localhost ([::1]:52625 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RqUaz-0001qc-Kd for incoming@patchwork.ozlabs.org; Thu, 26 Jan 2012 14:02:53 -0500 Received: from [140.186.70.92] (port=53792 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RqUaQ-0000tf-4T for qemu-devel@nongnu.org; Thu, 26 Jan 2012 14:02:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RqUaE-0007am-32 for qemu-devel@nongnu.org; Thu, 26 Jan 2012 14:02:12 -0500 Received: from cpe-70-123-132-139.austin.res.rr.com ([70.123.132.139]:42950 helo=localhost6.localdomain6) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RqUaD-0007aO-SB for qemu-devel@nongnu.org; Thu, 26 Jan 2012 14:02:06 -0500 Received: from localhost6.localdomain6 (localhost.localdomain [127.0.0.1]) by localhost6.localdomain6 (8.14.4/8.14.4/Debian-2ubuntu1) with ESMTP id q0QJ1xbQ031430; Thu, 26 Jan 2012 13:02:00 -0600 Received: (from anthony@localhost) by localhost6.localdomain6 (8.14.4/8.14.4/Submit) id q0QJ1w6g031428; Thu, 26 Jan 2012 13:01:58 -0600 From: Anthony Liguori To: qemu-devel@nongnu.org Date: Thu, 26 Jan 2012 13:01:00 -0600 Message-Id: <1327604460-31142-16-git-send-email-aliguori@us.ibm.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1327604460-31142-1-git-send-email-aliguori@us.ibm.com> References: <1327604460-31142-1-git-send-email-aliguori@us.ibm.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 70.123.132.139 Cc: Peter Maydell , Anthony Liguori , Jan Kiszka , Markus Armbruster , Avi Kivity , Paolo Bonzini Subject: [Qemu-devel] [PATCH 15/15] i440fx: move ram initialization into i440fx-pmc X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org --- hw/pc.c | 44 ++------------------------------------------ hw/pc.h | 6 ------ hw/piix_pci.c | 46 ++++++++++++++++++++++++++++++++-------------- 3 files changed, 34 insertions(+), 62 deletions(-) diff --git a/hw/pc.c b/hw/pc.c index 4964a64..90bd638 100644 --- a/hw/pc.c +++ b/hw/pc.c @@ -993,36 +993,13 @@ static void pc_memory_init(MemoryRegion *system_memory, const char *kernel_cmdline, const char *initrd_filename, ram_addr_t below_4g_mem_size, - ram_addr_t above_4g_mem_size, - MemoryRegion **ram_memory) + ram_addr_t above_4g_mem_size) { int linux_boot, i; - MemoryRegion *ram, *ram_below_4g, *ram_above_4g; void *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); - } - fw_cfg = bochs_bios_init(); rom_set_fw(fw_cfg); @@ -1239,8 +1216,6 @@ static void pc_init1(MemoryRegion *system_memory, BusState *idebus[MAX_IDE_BUS]; ISADevice *rtc_state; ISADevice *floppy; - MemoryRegion *ram_memory = NULL; - MemoryRegion *pci_memory; DeviceState *dev; pc_cpus_init(cpu_model); @@ -1257,19 +1232,11 @@ static void pc_init1(MemoryRegion *system_memory, below_4g_mem_size = ram_size; } - if (pci_enabled) { - pci_memory = g_new(MemoryRegion, 1); - memory_region_init(pci_memory, "pci", INT64_MAX); - } else { - pci_memory = NULL; - } - /* allocate ram and load rom/bios */ if (!xen_enabled()) { pc_memory_init(system_memory, kernel_filename, kernel_cmdline, initrd_filename, - below_4g_mem_size, above_4g_mem_size, - &ram_memory); + below_4g_mem_size, above_4g_mem_size); } gsi_state = g_malloc0(sizeof(*gsi_state)); @@ -1284,13 +1251,6 @@ static void pc_init1(MemoryRegion *system_memory, 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, - (sizeof(target_phys_addr_t) == 4 - ? 0 - : ((uint64_t)1 << 62)), - pci_memory, ram_memory, bios_name); } else { pci_bus = NULL; diff --git a/hw/pc.h b/hw/pc.h index 530f417..71bbfb3 100644 --- a/hw/pc.h +++ b/hw/pc.h @@ -161,12 +161,6 @@ PCIBus *i440fx_init(I440FXPMCState **pi440fx_state, int *piix_devfn, MemoryRegion *address_space_mem, MemoryRegion *address_space_io, ram_addr_t ram_size, - target_phys_addr_t pci_hole_start, - target_phys_addr_t pci_hole_size, - target_phys_addr_t pci_hole64_start, - target_phys_addr_t pci_hole64_size, - MemoryRegion *pci_memory, - MemoryRegion *ram_memory, const char *bios_name); /* piix4.c */ diff --git a/hw/piix_pci.c b/hw/piix_pci.c index 6dda019..0c2226b 100644 --- a/hw/piix_pci.c +++ b/hw/piix_pci.c @@ -111,7 +111,11 @@ struct I440FXPMCState { PAMMemoryRegion pam_regions[13]; 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 "i440FX" @@ -390,24 +394,46 @@ static void i440fx_initfn(Object *obj) memory_region_init(&s->pci_address_space, "pci", INT64_MAX); } -static int i440fx_pmc_initfn(PCIDevice *dev) +static int i440fx_pmc_realize(PCIDevice *dev) { I440FXPMCState *d = DO_UPCAST(I440FXPMCState, dev, dev); ram_addr_t ram_size; + uint64_t below_4g_mem_size, above_4g_mem_size; uint64_t pci_hole_start, pci_hole_size; uint64_t pci_hole64_start, pci_hole64_size; g_assert(d->ram_size != 0); g_assert(d->system_memory != NULL); g_assert(d->pci_address_space != NULL); - g_assert(d->ram_memory != NULL); - /* Calculate PCI geometry from RAM size */ + /* Calculate memory geometry from RAM size */ 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, 0x100000000ULL, + &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; @@ -451,11 +477,6 @@ PCIBus *i440fx_init(I440FXPMCState **pi440fx_state, int *piix3_devfn, MemoryRegion *address_space_mem, MemoryRegion *address_space_io, ram_addr_t ram_size, - target_phys_addr_t pci_hole_start, - target_phys_addr_t pci_hole_size, - target_phys_addr_t pci_hole64_start, - target_phys_addr_t pci_hole64_size, - MemoryRegion *pci_address_space, MemoryRegion *ram_memory, const char *bios_name) { I440FXState *s; @@ -472,9 +493,6 @@ PCIBus *i440fx_init(I440FXPMCState **pi440fx_state, int *piix3_devfn, g_free(s->bios_name); s->bios_name = g_strdup(bios_name); } - - /* FIXME pmc should create ram_memory */ - s->pmc.ram_memory = ram_memory; s->pmc.ram_size = ram_size; qdev_set_parent_bus(DEVICE(s), sysbus_get_default()); @@ -737,7 +755,7 @@ static void i440fx_pmc_class_init(ObjectClass *klass, void *data) PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); k->no_hotplug = 1; - k->init = i440fx_pmc_initfn; + k->init = i440fx_pmc_realize; k->config_write = i440fx_pmc_write_config; k->vendor_id = PCI_VENDOR_ID_INTEL; k->device_id = PCI_DEVICE_ID_INTEL_82441;