Read additional ACPI tables from a VM
PATCH 1/1 Read additional ACPI tables from a VM
bios/rombios32.c +64 -20
@@ -455,6 +455,8 @@ unsigned long bios_table_end_addr;#define QEMU_CFG_SIGNATURE 0x00#define QEMU_CFG_ID 0x01#define QEMU_CFG_UUID 0x02 +#define FW_CFG_ARCH_LOCAL 0x8000 +#define FW_CFG_ACPI_TABLES (FW_CFG_ARCH_LOCAL + 0)int qemu_cfg_port;
@@ -482,6 +484,27 @@ void qemu_cfg_read(uint8_t *buf, int len)while (len--) *(buf++) = inb(QEMU_CFG_DATA_PORT); } + +static int acpi_additional_tables (void ) +{ +uint16_t cnt; + +qemu_cfg_select (FW_CFG_ACPI_TABLES ); +qemu_cfg_read ((uint8_t *)&cnt,sizeof (cnt)); + +return cnt; +} + +static int acpi_load_table (int i,uint32_t addr,uint16_t *len) +{ +qemu_cfg_read ((uint8_t *)len,sizeof (*len)); + +if (!*len) +return -1 ; + +qemu_cfg_read ((uint8_t *)addr, *len); +return 0 ; +}#endif void init_smp_msrs (void )
@@ -1545,8 +1568,8 @@ void acpi_bios_init(void)uint32_t hpet_addr;#endif uint32_t base_addr, rsdt_addr, fadt_addr, addr, facs_addr, dsdt_addr, ssdt_addr; -uint32_t acpi_tables_size, madt_addr, madt_size; -int i; +uint32_t acpi_tables_size, madt_addr, madt_size, rsdt_size; +int i, ext_tbl;/* reserve memory space for tables */ #ifdef BX_USE_EBDA_TABLES
@@ -1559,10 +1582,17 @@ void acpi_bios_init(void) bios_table_cur_addr +=sizeof (*rsdp);#endif +#ifdef BX_QEMU + ext_tbl =acpi_additional_tables (); +#else + ext_tbl =0 ; +#endif + addr = base_addr = ram_size -ACPI_DATA_SIZE ; rsdt_addr = addr; rsdt = (void *)(addr); - addr +=sizeof (*rsdt); + rsdt_size =sizeof (*rsdt) + ext_tbl *sizeof (rsdt->table_offset_entry[0 ]); + addr += rsdt_size; fadt_addr = addr; fadt = (void *)(addr);
@@ -1601,12 +1631,6 @@ void acpi_bios_init(void) addr +=sizeof (*hpet);#endif - acpi_tables_size = addr - base_addr; - -BX_INFO ("ACPI tables: RSDP addr=0x%08lx ACPI DATA addr=0x%08lx size=0x%x\n" , - (unsigned long )rsdp, - (unsigned long )rsdt, acpi_tables_size); -/* RSDP */ memset (rsdp,0 ,sizeof (*rsdp));memcpy (rsdp->signature,"RSD PTR " ,8 );
@@ -1618,17 +1642,6 @@ void acpi_bios_init(void) rsdp->rsdt_physical_address =cpu_to_le32 (rsdt_addr); rsdp->checksum =acpi_checksum ((void *)rsdp,20 ); -/* RSDT */ -memset (rsdt,0 ,sizeof (*rsdt)); - rsdt->table_offset_entry[0 ] =cpu_to_le32 (fadt_addr); - rsdt->table_offset_entry[1 ] =cpu_to_le32 (madt_addr); - rsdt->table_offset_entry[2 ] =cpu_to_le32 (ssdt_addr); -#ifdef BX_QEMU - rsdt->table_offset_entry[3 ] =cpu_to_le32 (hpet_addr); -#endif -acpi_build_table_header ((struct acpi_table_header *)rsdt, -"RSDT" ,sizeof (*rsdt),1 ); -/* FADT */ memset (fadt,0 ,sizeof (*fadt)); fadt->firmware_ctrl =cpu_to_le32 (facs_addr);
@@ -1715,6 +1728,37 @@ void acpi_bios_init(void) "HPET", sizeof(*hpet), 1);#endif + +#ifdef BX_QEMU +acpi_additional_tables ();/* resets cfg to required entry */ +for (i =0 ; i < ext_tbl; i++) { +uint16_t len; +if (addr >= ram_size) +BX_PANIC ("ACPI table overflow\n" ); +if (acpi_load_table (i, addr, &len) <0 ) +BX_PANIC ("Fail to load ACPI table from QEMU\n" ); + rsdt->table_offset_entry[i+4 ] =cpu_to_le32 (addr); + addr += len; + } +#endif + +/* RSDT */ +memset (rsdt,0 ,sizeof (*rsdt)); + rsdt->table_offset_entry[0 ] =cpu_to_le32 (fadt_addr); + rsdt->table_offset_entry[1 ] =cpu_to_le32 (madt_addr); + rsdt->table_offset_entry[2 ] =cpu_to_le32 (ssdt_addr); +#ifdef BX_QEMU + rsdt->table_offset_entry[3 ] =cpu_to_le32 (hpet_addr); +#endif +acpi_build_table_header ((struct acpi_table_header *)rsdt, +"RSDT" , rsdt_size,1 ); + + acpi_tables_size = addr - base_addr; + +BX_INFO ("ACPI tables: RSDP addr=0x%08lx ACPI DATA addr=0x%08lx size=0x%x\n" , + (unsigned long )rsdp, + (unsigned long )rsdt, acpi_tables_size); + }/* SMBIOS entry point -- must be written to a 16-bit aligned address
--
Gleb.
Gleb Natapov wrote:
Just a quick review.
bios/rombios32.c unsigned long bios_table_end_addr; · line 459
Quoted 10 lines
bios/rombios32.c +2
-0@@ -455,6 +455,8 @@ unsigned long bios_table_end_addr;#define QEMU_CFG_SIGNATURE 0x00#define QEMU_CFG_ID 0x01#define QEMU_CFG_UUID 0x02 +#define FW_CFG_ARCH_LOCAL 0x8000 +#define FW_CFG_ACPI_TABLES (FW_CFG_ARCH_LOCAL + 0)
No more QEMU_CFG prefix? Or is this different?
Quoted 20 lines
bios/rombios32.c +14
-0int qemu_cfg_port;@@ -482,6 +484,27 @@ void qemu_cfg_read(uint8_t *buf, int len)while (len--) *(buf++) =inb (QEMU_CFG_DATA_PORT ); } + +static int acpi_additional_tables (void ) +{ +uint16_t cnt; + +qemu_cfg_select (FW_CFG_ACPI_TABLES ); +qemu_cfg_read ((uint8_t *)&cnt,sizeof (cnt)); + +return cnt; +} + +static int acpi_load_table (int i,uint32_t addr,uint16_t *len) +{ +qemu_cfg_read ((uint8_t *)len,sizeof (*len));
bios/rombios32.c void qemu_cfg_read(uint8_t *buf, int len) · line 510
Quoted 10 lines
bios/rombios32.c +7
-0+ +if (!*len) +return -1 ; + +qemu_cfg_read ((uint8_t *)addr, *len); + return 0; +}#endif void init_smp_msrs (void )
Can you please diff against bochs cvs?
bios/rombios32.c void acpi_bios_init(void) · line 1572
Quoted 8 lines
bios/rombios32.c +2
-2@@ -1545,8 +1568,8 @@ void acpi_bios_init(void)uint32_t hpet_addr;#endif uint32_t base_addr, rsdt_addr, fadt_addr, addr, facs_addr, dsdt_addr, ssdt_addr; -uint32_t acpi_tables_size, madt_addr, madt_size; -int i; +uint32_t acpi_tables_size, madt_addr, madt_size, rsdt_size; +int i, ext_tbl;
Might change to uint32_t or uint16_t and ext_tbl to something little more descriptive like external_tables.
Quoted 8 lines
bios/rombios32.c +1
-0/* reserve memory space for tables */ #ifdef BX_USE_EBDA_TABLES @@ -1559,10 +1582,17 @@ void acpi_bios_init(void) bios_table_cur_addr +=sizeof (*rsdp);#endif +#ifdef BX_QEMU
bios/rombios32.c void acpi_bios_init(void) · line 1594
Quoted 10 lines
bios/rombios32.c +6
-1+ ext_tbl =acpi_additional_tables (); +#else + ext_tbl =0 ; +#endif + addr = base_addr = ram_size -ACPI_DATA_SIZE ; rsdt_addr = addr; rsdt = (void *)(addr); - addr +=sizeof (*rsdt); + rsdt_size =sizeof (*rsdt) + ext_tbl *sizeof (rsdt->table_offset_entry[0 ]);
Can use 4 instead of the sizeof() since its defined as a 32-bit address.
Quoted 36 lines
bios/rombios32.c +1
-17+ addr += rsdt_size; fadt_addr = addr; fadt = (void *)(addr);@@ -1601,12 +1631,6 @@ void acpi_bios_init(void) addr +=sizeof (*hpet);#endif - acpi_tables_size = addr - base_addr; - -BX_INFO ("ACPI tables: RSDP addr=0x%08lx ACPI DATA addr=0x%08lx size=0x%x\n" , - (unsigned long )rsdp, - (unsigned long )rsdt, acpi_tables_size); -/* RSDP */ memset (rsdp,0 ,sizeof (*rsdp));memcpy (rsdp->signature,"RSD PTR " ,8 );@@ -1618,17 +1642,6 @@ void acpi_bios_init(void) rsdp->rsdt_physical_address =cpu_to_le32 (rsdt_addr); rsdp->checksum =acpi_checksum ((void *)rsdp,20 ); -/* RSDT */ -memset (rsdt,0 ,sizeof (*rsdt)); - rsdt->table_offset_entry[0 ] =cpu_to_le32 (fadt_addr); - rsdt->table_offset_entry[1 ] =cpu_to_le32 (madt_addr); - rsdt->table_offset_entry[2 ] =cpu_to_le32 (ssdt_addr); -#ifdef BX_QEMU - rsdt->table_offset_entry[3 ] =cpu_to_le32 (hpet_addr); -#endif -acpi_build_table_header ((struct acpi_table_header *)rsdt, -"RSDT" ,sizeof (*rsdt),1 ); -/* FADT */ memset (fadt,0 ,sizeof (*fadt)); fadt->firmware_ctrl =cpu_to_le32 (facs_addr);
bios/rombios32.c void acpi_bios_init(void) · line 1731
Quoted 4 lines
bios/rombios32.c +1
-0@@ -1715,6 +1728,37 @@ void acpi_bios_init(void) "HPET", sizeof(*hpet), 1);#endif +
Stray empty line; might also unite it into one #ifdef #endif pair.
bios/rombios32.c void acpi_bios_init(void) · line 1739
Quoted 8 lines
bios/rombios32.c +8
-0+#ifdef BX_QEMU +acpi_additional_tables ();/* resets cfg to required entry */ +for (i =0 ; i < ext_tbl; i++) { +uint16_t len; +if (addr >= ram_size) +BX_PANIC ("ACPI table overflow\n" ); +if (acpi_load_table (i, addr, &len) <0 ) +BX_PANIC ("Fail to load ACPI table from QEMU\n" );
Failed?
bios/rombios32.c void acpi_bios_init(void) · line 1746
Quoted 7 lines
bios/rombios32.c +7
-0+ rsdt->table_offset_entry[i+4 ] =cpu_to_le32 (addr); + addr += len; + } +#endif + +/* RSDT */ +memset (rsdt,0 ,sizeof (*rsdt));
This overwrites the "rsdt->table_offset_entry[i+4] = cpu_to_le32(addr);" assignment from above?
Quoted 9 lines
bios/rombios32.c +9
-0+ rsdt->table_offset_entry[0 ] =cpu_to_le32 (fadt_addr); + rsdt->table_offset_entry[1 ] =cpu_to_le32 (madt_addr); + rsdt->table_offset_entry[2 ] =cpu_to_le32 (ssdt_addr); +#ifdef BX_QEMU + rsdt->table_offset_entry[3 ] =cpu_to_le32 (hpet_addr); +#endif +acpi_build_table_header ((struct acpi_table_header *)rsdt, +"RSDT" , rsdt_size,1 ); +
bios/rombios32.c void acpi_bios_init(void)
Quoted 10 lines
bios/rombios32.c +6
-1+ acpi_tables_size = addr - base_addr; + +BX_INFO ("ACPI tables: RSDP addr=0x%08lx ACPI DATA addr=0x%08lx size=0x%x\n" , + (unsigned long )rsdp, + (unsigned long )rsdt, acpi_tables_size); + }/* SMBIOS entry point -- must be written to a 16-bit aligned address --
- Sebastian
Quoted 4 lines · Sebastian Herbszt
Gleb Natapov wrote:
Just a quick review.
Quoted 13 lines
bios/rombios32.c unsigned long bios_table_end_addr; · line 459
Quoted 10 lines
bios/rombios32.c +2
-0@@ -455,6 +455,8 @@ unsigned long bios_table_end_addr;#define QEMU_CFG_SIGNATURE 0x00#define QEMU_CFG_ID 0x01#define QEMU_CFG_UUID 0x02 +#define FW_CFG_ARCH_LOCAL 0x8000 +#define FW_CFG_ACPI_TABLES (FW_CFG_ARCH_LOCAL + 0)No more
QEMU_CFGprefix? Or is this different?
It is not. I'll change it to QEMU_CFG.
Quoted 13 lines
Quoted 13 lines
bios/rombios32.c +11
-0+ +static int acpi_load_table (int i,uint32_t addr,uint16_t *len) +{ +qemu_cfg_read ((uint8_t *)len,sizeof (*len)); + +if (!*len) +return -1 ; + +qemu_cfg_read ((uint8_t *)addr, *len); +return 0 ; +}#endif
Quoted 4 lines
Quoted 1 line
void
init_smp_msrs(void)Can you please diff against bochs cvs?
Will do. This patch was initially intended to go to qemu patch series so I did it against patched bios source. And unpatched bochs bios does not boot linux with qemu. IRQ routing problem or something.
Quoted 9 lines
bios/rombios32.c void acpi_bios_init(void) · line 1746
Quoted 7 lines
bios/rombios32.c +7
-0+ rsdt->table_offset_entry[i+4 ] =cpu_to_le32 (addr); + addr += len; + } +#endif + +/* RSDT */ +memset (rsdt,0 ,sizeof (*rsdt));This overwrites the "rsdt->table_offset_entry[i+4] =
cpu_to_le32(addr);" assignment from above?
No since sizeof(*rstd) is less then that. But I'll move memset up, it will be less confusing.
--
Gleb.
Quoted 13 lines · Gleb Natapov
Quoted 13 lines
Quoted 13 lines
bios/rombios32.c +11
-0+ +static int acpi_load_table (int i,uint32_t addr,uint16_t *len) +{ +qemu_cfg_read ((uint8_t *)len,sizeof (*len)); + +if (!*len) +return -1 ; + +qemu_cfg_read ((uint8_t *)addr, *len); +return 0 ; +}#endif
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
void
init_smp_msrs(void)Can you please diff against bochs cvs?
Will do. This patch was initially intended to go to qemu patch series so I did it against patched bios source.
I'm happy to update to a more recent BIOS snapshot...
Quoted 3 lines
And unpatched bochs bios does not
boot linux with qemu. IRQ routing problem or something.
Unless upstream Bochs has regressed. Did you apply the other patches in the QEMU series? Some are no longer needed I think.
Regards,
Anthony Liguori
Quoted 5 lines
--
Gleb.
Quoted 22 lines · Anthony Liguori
Quoted 13 lines · Gleb Natapov
Quoted 13 lines
Quoted 13 lines
bios/rombios32.c +11
-0+ +static int acpi_load_table (int i,uint32_t addr,uint16_t *len) +{ +qemu_cfg_read ((uint8_t *)len,sizeof (*len)); + +if (!*len) +return -1 ; + +qemu_cfg_read ((uint8_t *)addr, *len); +return 0 ; +}#endif
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
void
init_smp_msrs(void)Can you please diff against bochs cvs?
Will do. This patch was initially intended to go to qemu patch series so I did it against patched bios source.
Quoted 9 lines
I'm happy to update to a more recent BIOS snapshot...
Quoted 3 lines
And unpatched bochs bios does not
boot linux with qemu. IRQ routing problem or something.Unless upstream Bochs has regressed. Did you apply the other patches in the QEMU series? Some are no longer needed I think.
With all qemu patches IRQ problem goes away. (One qemu patch conflicts with the last bochs commit so I reverted it before applying qemu series).
--
Gleb.
Quoted 29 lines · Gleb Natapov
Quoted 28 lines · Anthony Liguori
Quoted 13 lines · Gleb Natapov
Quoted 13 lines
Quoted 13 lines
(quoted diff) +11
-0+ +static int acpi_load_table(int i, uint32_t addr, uint16_t *len) +{ + qemu_cfg_read((uint8_t*)len, sizeof(*len)); + + if (!*len) + return -1; + + qemu_cfg_read((uint8_t*)addr, *len); + return 0; +}#endif
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
void
init_smp_msrs(void)Can you please diff against bochs cvs?
Will do. This patch was initially intended to go to qemu patch series so I did it against patched bios source.
I'm happy to update to a more recent BIOS snapshot...
Quoted 3 lines
And unpatched bochs bios does not
boot linux with qemu. IRQ routing problem or something.
Quoted 5 lines
Quoted 3 lines
Unless upstream Bochs has regressed. Did you apply the other patches in the QEMU series? Some are no longer needed I think.
With all qemu patches IRQ problem goes away. (One qemu patch conflicts with the last bochs commit so I reverted it before applying qemu series).
Ugh, I was getting "GRUB Error 16: Inconsistent filesystem structure" which appeared to be caused by 864034d9a3190e0c2c10382ae015b5b5fd16718a.
But now its magically working again. Or not?
Anthony, attached are updated patches + series to sync with Bochs. Please give it a try.
bios/rombios.h +1 -1
@@ -19,7 +19,7 @@// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /* define it to include QEMU specific code */ -//#define BX_QEMU +#define BX_QEMU #ifndef LEGACY # define BX_ROMBIOS32 1
update SMBIOS table to report memory above 4G (Alex Williamson)
bios/rombios32.c +13 -3
@@ -429,6 +429,7 @@ uint32_t cpuid_signature;uint32_t cpuid_features;uint32_t cpuid_ext_features;unsigned long ram_size; +uint64_t ram_end;uint8_t bios_uuid[16 ];#ifdef BX_USE_EBDA_TABLES unsigned long ebda_cur_addr;
@@ -570,6 +571,14 @@ void ram_probe(void)else ram_size = (cmos_readb (0x30 ) | (cmos_readb (0x31 ) <<8 )) *1024 +1 *1024 *1024 ; +if (cmos_readb (0x5b ) |cmos_readb (0x5c ) |cmos_readb (0x5d )) + ram_end = (((uint64_t )cmos_readb (0x5b ) <<16 ) | + ((uint64_t )cmos_readb (0x5c ) <<24 ) | + ((uint64_t )cmos_readb (0x5d ) <<32 )) + (1ull <<32 ); +else + ram_end = ram_size; +BX_INFO ("end of ram=%ldMB\n" , ram_end >>20 ); +BX_INFO ("ram_size=0x%08lx\n" , ram_size);#ifdef BX_USE_EBDA_TABLES ebda_cur_addr = ((*(uint16_t *)(0x40e )) <<4 ) +0x380 ;
@@ -2174,7 +2183,8 @@ void smbios_init(void) {unsigned cpu_num, nr_structs =0 , max_struct_size =0 ;char *start, *p, *q; -int memsize = ram_size / (1024 *1024 ); +int memsize = (ram_end == ram_size) ? ram_size / (1024 *1024 ) : + (ram_end - (1ull <<32 ) + ram_size) / (1024 *1024 );#ifdef BX_USE_EBDA_TABLES ebda_cur_addr =align (ebda_cur_addr,16 );
@@ -2201,8 +2211,8 @@ void smbios_init(void)add_struct (smbios_type_4_init (p, cpu_num));add_struct (smbios_type_16_init (p, memsize));add_struct (smbios_type_17_init (p, memsize)); -add_struct (smbios_type_19_init (p, memsize)); -add_struct (smbios_type_20_init (p, memsize)); +add_struct (smbios_type_19_init (p, ram_end / (1024 *1024 ))); +add_struct (smbios_type_20_init (p, ram_end / (1024 *1024 )));add_struct (smbios_type_32_init (p));add_struct (smbios_type_127_init (p));
generate mptable unconditionally (Avi Kivity)
VMware ESX requires an mptable even for uniprocessor guests.
bios/rombios32.c +0 -5
@@ -970,11 +970,6 @@ static void mptable_init(void)int ioapic_id, i, len;int mp_config_table_size; -#ifdef BX_QEMU -if (smp_cpus <=1 ) -return ; -#endif -#ifdef BX_USE_EBDA_TABLES mp_config_table = (uint8_t *)(ram_size -ACPI_DATA_SIZE -MPTABLE_MAX_SIZE );#else
resolve memory device roll over reporting issues with >32G guests (Bill Rieske)
The field within the Memory Device type 17 is only a word with the MSB being used to report MB/KB. Thereby, a guest with 32G and greater would report incorrect memory device information rolling over to 0.
This presents more than one memory device and associated memory structures if the memory is larger than 16G
bios/rombios32.c +45 -25
156 lines not on this page · raw message
fix smbios memory device length boundary condition (Bill Rieske)
dev_memsize ends up 0 when it shouldn't be on 16G boundary conditions.
bios/rombios32.c +1 -1
@@ -2218,7 +2218,7 @@ void smbios_init(void)for ( i =0 ; i < nr_mem_devs; i++ ) {uint32_t dev_memsize = ((i == (nr_mem_devs -1 )) - ? (memsize &0x3fff ) :0x4000 ); + ? (((memsize-1 ) &0x3fff )+1 ) :0x4000 );add_struct (smbios_type_17_init (p, dev_memsize, i));add_struct (smbios_type_19_init (p, dev_memsize, i));add_struct (smbios_type_20_init (p, dev_memsize, i));
0001_bx-qemu.patch 0002_kvm-bios-update-smbios-table-to-report-memory-above-4g.patch 0003_kvm-bios-generate-mptable-unconditionally.patch 0004_kvm-bios-resolve-memory-device-roll-over-reporting--issues-with-32g-guests.patch 0005_kvm-bios-fix-smbios-memory-device-length-boundary--condition.patch
Re: [Qemu-devel] Re: [Bochs-developers] [PATCH] Read additionalACPI tables from a VM
In reply to Gleb NatapovQuoted 10 lines · Gleb Natapov
Quoted 7 lines · Anthony Liguori
Quoted 3 lines · Gleb Natapov
And unpatched bochs bios does not
boot linux with qemu. IRQ routing problem or something.Unless upstream Bochs has regressed. Did you apply the other patches in the QEMU series? Some are no longer needed I think.
With all qemu patches IRQ problem goes away. (One qemu patch conflicts with the last bochs commit so I reverted it before applying qemu series).
Can you please try upstream bochs with only 0010_bios-mark-the-acpi-sci-interrupt-as-connected-to-irq-9.patch applied from the qemu bios patch queue?
- Sebastian
Re: [Qemu-devel] Re: [Bochs-developers] [PATCH] Read additionalACPI tables from a VM
Quoted 7 lines · Sebastian Herbszt
Quoted 6 lines · Gleb Natapov
Quoted 5 lines · Anthony Liguori
Quoted 3 lines · Gleb Natapov
And unpatched bochs bios does not
boot linux with qemu. IRQ routing problem or something.
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines
Unless upstream Bochs has regressed. Did you apply the other patches in the QEMU series? Some are no longer needed I think.
With all qemu patches IRQ problem goes away. (One qemu patch conflicts with the last bochs commit so I reverted it before applying qemu series).
Can you please try upstream bochs with only 0010_bios-mark-the-acpi-sci-interrupt-as-connected-to-irq-9.patch applied from the qemu bios patch queue?
For some strange reason this no longer happens. May be something in qemu changed.
--
Gleb.