fw_cfg: add etc/e820
v2 cover fw_cfg: add etc/e820
Hi,
Mini patch series adds a new file to fw_cfg, holding a e820 map with both reservations and ram regions. The existing fw_cfg entry with e820 reservations only is left as-is.
This allows to (a) support more than 1TB of memory (which is impossible using the current cmos entries) and (b) support non-contignous memory in the furure without having to introduce a new interface for that.
please review,
Gerd
Gerd Hoffmann (2):
pc: add etc/e820 fw_cfg file
pc: register e820 entries for ram
hw/i386/pc.c | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-)
Signature · 1 line
1.8.3.1
PATCH v2 1/2 pc: add etc/e820 fw_cfg file
Unlike the existing FW_CFG_E820_TABLE entry which carries reservations only the new etc/e820 file also has entries for RAM.
Format is simliar to the FW_CFG_E820_TABLE, it is a simple list of e820_entry structs. Unlike FW_CFG_E820_TABLE it has no count though as the number of entries can be figured from the file size.
--- hw/i386/pc.c | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-)
hw/i386/pc.c +28 -11
@@ -89,7 +89,9 @@ struct e820_table {struct e820_entry entry[E820_NR_ENTRIES ]; } QEMU_PACKED __attribute((__aligned__(4))); -static struct e820_table e820_table; +static struct e820_table e820_reserve; +static struct e820_entry *e820_table; +static unsigned e820_entries;struct hpet_fw_config hpet_cfg = {.count =UINT8_MAX };void gsi_handler (void *opaque,int n,int level)
@@ -576,19 +578,32 @@ static void handle_a20_line_change(void *opaque, int irq, int level)int e820_add_entry (uint64_t address,uint64_t length,uint32_t type) { -int index =le32_to_cpu (e820_table.count); +int index =le32_to_cpu (e820_reserve.count);struct e820_entry *entry; -if (index >=E820_NR_ENTRIES ) -return -EBUSY ; - entry = &e820_table.entry[index++]; +if (type !=E820_RAM ) { +/* old FW_CFG_E820_TABLE entry -- reservations only */ +if (index >=E820_NR_ENTRIES ) { +return -EBUSY ; + } + entry = &e820_reserve.entry[index++]; + + entry->address =cpu_to_le64 (address); + entry->length =cpu_to_le64 (length); + entry->type =cpu_to_le32 (type); + + e820_reserve.count =cpu_to_le32 (index); + } - entry->address =cpu_to_le64 (address); - entry->length =cpu_to_le64 (length); - entry->type =cpu_to_le32 (type); +/* new "etc/e820" file -- include ram too */ + e820_table =g_realloc (e820_table, +sizeof (struct e820_entry ) * (e820_entries+1 )); + e820_table[e820_entries].address =cpu_to_le64 (address); + e820_table[e820_entries].length =cpu_to_le64 (length); + e820_table[e820_entries].type =cpu_to_le32 (type); + e820_entries++; - e820_table.count =cpu_to_le32 (index); -return index; +return e820_entries; }/* Calculates the limit to CPU APIC ID values
@@ -639,7 +654,9 @@ static FWCfgState *bochs_bios_init(void)fw_cfg_add_bytes (fw_cfg,FW_CFG_SMBIOS_ENTRIES , smbios_table, smbios_len);fw_cfg_add_bytes (fw_cfg,FW_CFG_E820_TABLE , - &e820_table,sizeof (e820_table)); + &e820_reserve,sizeof (e820_reserve)); +fw_cfg_add_file (fw_cfg,"etc/e820" , e820_table, +sizeof (struct e820_entry ) * e820_entries);fw_cfg_add_bytes (fw_cfg,FW_CFG_HPET , &hpet_cfg,sizeof (hpet_cfg));/* allocate memory for the NUMA channel: one (64bit) word for the number
Signature · 1 line
1.8.3.1
PATCH v2 2/2 pc: register e820 entries for ram
In reply to Gerd HoffmannSo RAM shows up in the new etc/e820 fw_cfg file.
--- hw/i386/pc.c | 2 ++ 1 file changed, 2 insertions(+)
hw/i386/pc.c +2 -0
@@ -1151,12 +1151,14 @@ FWCfgState *pc_memory_init(MemoryRegion *system_memory,memory_region_init_alias (ram_below_4g,NULL ,"ram-below-4g" , ram,0 , below_4g_mem_size);memory_region_add_subregion (system_memory,0 , ram_below_4g); +e820_add_entry (0 , below_4g_mem_size,E820_RAM );if (above_4g_mem_size >0 ) { ram_above_4g =g_malloc (sizeof (*ram_above_4g));memory_region_init_alias (ram_above_4g,NULL ,"ram-above-4g" , ram, below_4g_mem_size, above_4g_mem_size);memory_region_add_subregion (system_memory,0x100000000ULL , ram_above_4g); +e820_add_entry (0x100000000ULL , above_4g_mem_size,E820_RAM ); }
Signature · 1 line
1.8.3.1