[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [RFC PATCH v3 08/19] pc: calculate dimm physical addres
From: |
Blue Swirl |
Subject: |
Re: [Qemu-devel] [RFC PATCH v3 08/19] pc: calculate dimm physical addresses and adjust memory map |
Date: |
Sat, 22 Sep 2012 14:15:28 +0000 |
On Fri, Sep 21, 2012 at 11:17 AM, Vasilis Liaskovitis
<address@hidden> wrote:
> Dimm physical address offsets are calculated automatically and memory map is
> adjusted accordingly. If a DIMM can fit before the PCI_HOLE_START (currently
> 0xe0000000), it will be added normally, otherwise its physical address will be
> above 4GB.
>
> Also create memory bus on i440fx-pcihost device.
>
> Signed-off-by: Vasilis Liaskovitis <address@hidden>
> ---
> hw/pc.c | 41 +++++++++++++++++++++++++++++++++++++++++
> hw/pc.h | 6 ++++++
> hw/pc_piix.c | 20 ++++++++++++++------
> vl.c | 1 +
> 4 files changed, 62 insertions(+), 6 deletions(-)
>
> diff --git a/hw/pc.c b/hw/pc.c
> index 112739a..2c9664d 100644
> --- a/hw/pc.c
> +++ b/hw/pc.c
> @@ -52,6 +52,7 @@
> #include "arch_init.h"
> #include "bitmap.h"
> #include "vga-pci.h"
> +#include "dimm.h"
>
> /* output Bochs bios info messages */
> //#define DEBUG_BIOS
> @@ -93,6 +94,9 @@ struct e820_table {
> static struct e820_table e820_table;
> struct hpet_fw_config hpet_cfg = {.count = UINT8_MAX};
>
> +ram_addr_t below_4g_hp_mem_size = 0;
> +ram_addr_t above_4g_hp_mem_size = 0;
> +extern target_phys_addr_t ram_hp_offset;
extern declarations belong to headers only.
> void gsi_handler(void *opaque, int n, int level)
> {
> GSIState *s = opaque;
> @@ -1160,3 +1164,40 @@ void pc_pci_device_init(PCIBus *pci_bus)
> pci_create_simple(pci_bus, -1, "lsi53c895a");
> }
> }
> +
> +
> +/* Function to configure memory offsets of hotpluggable dimms */
> +
> +target_phys_addr_t pc_set_hp_memory_offset(uint64_t size)
> +{
> + target_phys_addr_t ret;
> +
> + /* on first call, initialize ram_hp_offset */
> + if (!ram_hp_offset) {
> + if (ram_size >= PCI_HOLE_START ) {
> + ram_hp_offset = 0x100000000LL + (ram_size - PCI_HOLE_START);
> + } else {
> + ram_hp_offset = ram_size;
> + }
> + }
> +
> + if (ram_hp_offset >= 0x100000000LL) {
> + ret = ram_hp_offset;
> + above_4g_hp_mem_size += size;
> + ram_hp_offset += size;
> + }
> + /* if dimm fits before pci hole, append it normally */
> + else if (ram_hp_offset + size <= PCI_HOLE_START) {
} else if ...
> + ret = ram_hp_offset;
> + below_4g_hp_mem_size += size;
> + ram_hp_offset += size;
> + }
> + /* otherwise place it above 4GB */
> + else {
} else {
> + ret = 0x100000000LL;
> + above_4g_hp_mem_size += size;
> + ram_hp_offset = 0x100000000LL + size;
> + }
> +
> + return ret;
> +}
But the function and use of lots of global variables is ugly. The dimm
devices should be just created in piix_pci.c (i440fx) directly with
correct offsets and sizes, so all below_4g_mem_size etc. calculations
should be moved there. That would implement the PMC part of i440fx.
For ISA PC, probably the board should create the DIMMs since there may
not be a memory controller. The >4G logic does not make sense there
anyway.
> diff --git a/hw/pc.h b/hw/pc.h
> index e4db071..f3304fc 100644
> --- a/hw/pc.h
> +++ b/hw/pc.h
> @@ -10,6 +10,7 @@
> #include "memory.h"
> #include "ioapic.h"
>
> +#define PCI_HOLE_START 0xe0000000
> /* PC-style peripherals (also used by other machines). */
>
> /* serial.c */
> @@ -214,6 +215,11 @@ static inline bool isa_ne2000_init(ISABus *bus, int
> base, int irq, NICInfo *nd)
> /* pc_sysfw.c */
> void pc_system_firmware_init(MemoryRegion *rom_memory);
>
> +/* memory hotplug */
> +target_phys_addr_t pc_set_hp_memory_offset(uint64_t size);
> +extern ram_addr_t below_4g_hp_mem_size;
> +extern ram_addr_t above_4g_hp_mem_size;
> +
> /* e820 types */
> #define E820_RAM 1
> #define E820_RESERVED 2
> diff --git a/hw/pc_piix.c b/hw/pc_piix.c
> index 88ff041..d1fd276 100644
> --- a/hw/pc_piix.c
> +++ b/hw/pc_piix.c
> @@ -43,6 +43,7 @@
> #include "xen.h"
> #include "memory.h"
> #include "exec-memory.h"
> +#include "dimm.h"
> #ifdef CONFIG_XEN
> # include <xen/hvm/hvm_info_table.h>
> #endif
> @@ -155,9 +156,9 @@ static void pc_init1(MemoryRegion *system_memory,
> kvmclock_create();
> }
>
> - if (ram_size >= 0xe0000000 ) {
> - above_4g_mem_size = ram_size - 0xe0000000;
> - below_4g_mem_size = 0xe0000000;
> + if (ram_size >= PCI_HOLE_START ) {
> + above_4g_mem_size = ram_size - PCI_HOLE_START;
> + below_4g_mem_size = PCI_HOLE_START;
> } else {
> above_4g_mem_size = 0;
> below_4g_mem_size = ram_size;
> @@ -172,6 +173,9 @@ static void pc_init1(MemoryRegion *system_memory,
> rom_memory = system_memory;
> }
>
> + /* adjust memory map for hotplug dimms */
> + dimm_calc_offsets(pc_set_hp_memory_offset);
> +
> /* allocate ram and load rom/bios */
> if (!xen_enabled()) {
> fw_cfg = pc_memory_init(system_memory,
> @@ -192,9 +196,11 @@ 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,
> + below_4g_mem_size + below_4g_hp_mem_size,
> + 0x100000000ULL - below_4g_mem_size
> + - below_4g_hp_mem_size,
> + 0x100000000ULL + above_4g_mem_size
> + + above_4g_hp_mem_size,
> (sizeof(target_phys_addr_t) == 4
> ? 0
> : ((uint64_t)1 << 62)),
> @@ -223,6 +229,8 @@ static void pc_init1(MemoryRegion *system_memory,
> ioapic_init(gsi_state);
> }
>
> + main_memory_bus_create(object_resolve_path("i440fx", NULL));
> +
> pc_register_ferr_irq(gsi[13]);
>
> pc_vga_init(isa_bus, pci_enabled ? pci_bus : NULL);
> diff --git a/vl.c b/vl.c
> index af1745c..2282910 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -184,6 +184,7 @@ DisplayType display_type = DT_DEFAULT;
> int display_remote = 0;
> const char* keyboard_layout = NULL;
> ram_addr_t ram_size;
> +ram_addr_t ram_hp_offset;
> const char *mem_path = NULL;
> #ifdef MAP_POPULATE
> int mem_prealloc = 0; /* force preallocation of physical target memory */
> --
> 1.7.9
>
- Re: [Qemu-devel] [RFC PATCH v3 06/19] Implement "-dimm" command line option, (continued)
[Qemu-devel] [RFC PATCH v3 01/19][SeaBIOS] Add ACPI_EXTRACT_DEVICE* macros, Vasilis Liaskovitis, 2012/09/21
[Qemu-devel] [RFC PATCH v3 03/19][SeaBIOS] acpi-dsdt: Implement functions for memory hotplug, Vasilis Liaskovitis, 2012/09/21
[Qemu-devel] [RFC PATCH v3 05/19] Implement dimm device abstraction, Vasilis Liaskovitis, 2012/09/21
[Qemu-devel] [RFC PATCH v3 04/19][SeaBIOS] acpi: generate hotplug memory devices, Vasilis Liaskovitis, 2012/09/21
[Qemu-devel] [RFC PATCH v3 07/19] acpi_piix4: Implement memory device hotplug registers, Vasilis Liaskovitis, 2012/09/21
[Qemu-devel] [RFC PATCH v3 08/19] pc: calculate dimm physical addresses and adjust memory map, Vasilis Liaskovitis, 2012/09/21
- Re: [Qemu-devel] [RFC PATCH v3 08/19] pc: calculate dimm physical addresses and adjust memory map,
Blue Swirl <=
[Qemu-devel] [RFC PATCH v3 09/19] pc: Add dimm paravirt SRAT info, Vasilis Liaskovitis, 2012/09/21
[Qemu-devel] [RFC PATCH v3 11/19] Implement qmp and hmp commands for notification lists, Vasilis Liaskovitis, 2012/09/21
[Qemu-devel] [RFC PATCH v3 12/19] Implement "info memory-total" and "query-memory-total", Vasilis Liaskovitis, 2012/09/21
[Qemu-devel] [RFC PATCH v3 17/19][SeaBIOS] Implement _PS3 method for memory device, Vasilis Liaskovitis, 2012/09/21