qemu option loading
cover qemu option loading
Hi,
qemu is about to change the way how option roms are loaded. pci roms will be loaded into a option rom bar (like real hardware does). non-pci roms can be loaded using the qemu firmware interface.
With this change seabios will deploy all roms instead of having qemu copy them to the 0xc0000 -> 0e0000 range. Advantages are:
* roms can be packed better, especially in case they resize themself (like the gPXE roms do).
* rom area is a bit larger as seabios can additionally use the
unused regions of the 0xe0000 segment.
* the whole process comes closer to what happens on real hardware.
cheers,
Gerd
PATCH 1/4 Do not guard qemu shadow ram work around in CONFIG_OPTIONROMS_DEPLOYED
From: Anthony Liguori <[email protected]>
As we are going to disable CONFIG_OPTIONROMS_DEPLOYED under QEMU so that we can make proper use of DDIM.
--- src/shadow.c | 20 ++++++++------------ 1 files changed, 8 insertions(+), 12 deletions(-)
src/shadow.c +8 -12
@@ -29,18 +29,14 @@ __make_bios_writable(u16 bdf)int clear =0 ;int i;for (i=0 ; i<6 ; i++) { -if (CONFIG_OPTIONROMS_DEPLOYED ) { -int reg =pci_config_readb (bdf,0x5a + i); -if ((reg &0x11 ) !=0x11 ) { -// Need to copy optionroms to work around qemu implementation -void *mem = (void *)(BUILD_ROM_START + i *32 *1024 ); -memcpy ((void *)BUILD_BIOS_TMP_ADDR , mem,32 *1024 ); -pci_config_writeb (bdf,0x5a + i,0x33 ); -memcpy (mem, (void *)BUILD_BIOS_TMP_ADDR ,32 *1024 ); - clear =1 ; - }else { -pci_config_writeb (bdf,0x5a + i,0x33 ); - } +int reg =pci_config_readb (bdf,0x5a + i); +if ((reg &0x11 ) !=0x11 ) { +// Need to copy optionroms to work around qemu implementation +void *mem = (void *)(BUILD_ROM_START + i *32 *1024 ); +memcpy ((void *)BUILD_BIOS_TMP_ADDR , mem,32 *1024 ); +pci_config_writeb (bdf,0x5a + i,0x33 ); +memcpy (mem, (void *)BUILD_BIOS_TMP_ADDR ,32 *1024 ); + clear =1 ; }else {pci_config_writeb (bdf,0x5a + i,0x33 ); }
Signature · 1 line
1.6.5.2
PATCH 2/4 Disable CONFIG_OPTIONROMS_DEPLOYED by default
In reply to Gerd HoffmannFrom: Anthony Liguori <[email protected]>
Since qemu now supports loading option roms through PCI
--- src/config.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
src/config.h +1 -1
@@ -87,7 +87,7 @@// Support finding and running option roms during post. #define CONFIG_OPTIONROMS 1// Set if option roms are already copied to 0xc0000-0xf0000 -#define CONFIG_OPTIONROMS_DEPLOYED 1 +#define CONFIG_OPTIONROMS_DEPLOYED 0// When option roms are not pre-deployed, SeaBIOS can copy an optionrom // from flash for up to 2 devices. #define OPTIONROM_VENDEV_1 0x00000000
Signature · 1 line
1.6.5.2
PATCH 3/4 move htonl() + friends to util.h
In reply to Gerd HoffmannAs the next patch will add one more user of the macros move them to util.h. Also add the 16bit variants.
--- src/coreboot.c | 5 ----- src/util.h | 7 +++++++ 2 files changed, 7 insertions(+), 5 deletions(-)
src/coreboot.c +0 -5
@@ -351,11 +351,6 @@ ulzma(u8 *dst, u32 maxlen, const u8 *src, u32 srclen)* Coreboot flash format ****************************************************************/ -// XXX - optimize -#define ntohl (x) ((((x)&0xff)<<24) | (((x)&0xff00)<<8) | \ - (((x)&0xff0000) >> 8) | (((x)&0xff000000) >> 24)) -#define htonl (x) ntohl(x) -#define CBFS_HEADER_MAGIC 0x4F524243#define CBFS_HEADPTR_ADDR 0xFFFFFFFc#define CBFS_VERSION1 0x31313131
src/util.h +7 -0
@@ -367,4 +367,11 @@ extern u8 BiosChecksum;// version (auto generated file out/version.c) extern const char VERSION []; +// XXX - optimize +#define ntohl (x) ((((x)&0xff)<<24) | (((x)&0xff00)<<8) | \ + (((x)&0xff0000) >> 8) | (((x)&0xff000000) >> 24)) +#define htonl (x) ntohl(x) +#define ntohs (x) ((((x)&0xff)<<8) | (((x)&0xff00)>>8)) +#define htons (x) ntohs(x) +#endif // util.h
Signature · 1 line
1.6.5.2
PATCH 4/4 qemu: add rom loading via fw_cfg
In reply to Gerd HoffmannAdd support for loading roms using the qemu fw_cfg interface, modeled after the existing cbfs support. Use it to look for vgabios (vgaroms/*) and option roms (genroms/*).
--- src/optionroms.c | 22 ++++++++++++++++++++++ src/paravirt.c | 37 +++++++++++++++++++++++++++++++++++++ src/paravirt.h | 11 +++++++++++ 3 files changed, 70 insertions(+), 0 deletions(-)
src/optionroms.c +22 -0
@@ -247,6 +247,26 @@ run_cbfs_roms(const char *prefix, int isvga) } } +static void +run_qemu_roms (const char *prefix,int isvga) +{ +struct QemuCfgFile entry; +int plen =strlen (prefix); +int rc, dlen; + + rc =qemu_cfg_first_file (&entry); +while (rc >0 ) { +if (memcmp (prefix, entry.name, plen) ==0 ) { + dlen =qemu_cfg_read_file (&entry, (void *)RomEnd,max_rom () - RomEnd); +if (dlen >0 ) { +dprintf (1 ,"init qemu rom: %s\n" , entry.name); +init_optionrom ((void *)RomEnd,0 , isvga); + } + } + rc =qemu_cfg_next_file (&entry); + } +} +/**************************************************************** * PCI roms
@@ -375,6 +395,7 @@ optionrom_setup()// Find and deploy CBFS roms not associated with a device. run_cbfs_roms ("genroms/" ,0 ); +run_qemu_roms ("genroms/" ,0 ); }// All option roms found and deployed - now build BEV/BCV vectors.
@@ -434,6 +455,7 @@ vga_setup()// Find and deploy CBFS vga-style roms not associated with a device. run_cbfs_roms ("vgaroms/" ,1 ); +run_qemu_roms ("vgaroms/" ,1 ); }if (RomEnd ==BUILD_ROM_START ) {
src/paravirt.c +37 -0
@@ -8,6 +8,7 @@// This file may be distributed under the terms of the GNU LGPLv3 license. #include "config.h" // CONFIG_COREBOOT +#include "util.h" // ntoh[ls] #include "ioport.h" // outw #include "paravirt.h" // qemu_cfg_port_probe #include "smbios.h" // struct smbios_structure_header
@@ -287,3 +288,39 @@ u16 qemu_cfg_get_max_cpus(void)return cnt; } + +u16 qemu_cfg_first_file (QemuCfgFile *entry) +{ +memset (entry,0 ,sizeof (*entry)); +return qemu_cfg_next_file (entry); +} + +u16 qemu_cfg_next_file (QemuCfgFile *entry) +{ +u16 last =ntohs (entry->select); +u32 e,count; + +if (!qemu_cfg_present) +return 0 ; + +qemu_cfg_read_entry (&count,QEMU_CFG_FILE_DIR ,sizeof (count)); +for (e =0 ; e <ntohl (count); e++) { +qemu_cfg_read ((void *)entry,sizeof (*entry)); +if (ntohs (entry->select) > last) { +return 1 ; + } + } +return 0 ; +} + +u32 qemu_cfg_read_file (QemuCfgFile *entry,void *dst,u32 maxlen) +{ +int len =ntohl (entry->size); + +if (!qemu_cfg_present) +return 0 ; +if (len > maxlen) +return 0 ; +qemu_cfg_read_entry (dst,ntohs (entry->select), len); +return len; +}
src/paravirt.h +11 -0
@@ -31,6 +31,7 @@ static inline int kvm_para_available(void)#define QEMU_CFG_NUMA 0x0d#define QEMU_CFG_BOOT_MENU 0x0e#define QEMU_CFG_MAX_CPUS 0x0f +#define QEMU_CFG_FILE_DIR 0x19#define QEMU_CFG_ARCH_LOCAL 0x8000#define QEMU_CFG_ACPI_TABLES (QEMU_CFG_ARCH_LOCAL + 0)#define QEMU_CFG_SMBIOS_ENTRIES (QEMU_CFG_ARCH_LOCAL + 1)
@@ -53,4 +54,14 @@ int qemu_cfg_get_numa_nodes(void);void qemu_cfg_get_numa_data (u64 *data,int n);u16 qemu_cfg_get_max_cpus (void ); +typedef struct QemuCfgFile { +u32 size;/* file size */ +u16 select;/* write this to 0x510 to read it */ +u16 reserved; +char name[56 ]; +}QemuCfgFile ; + +u16 qemu_cfg_first_file (QemuCfgFile *entry); +u16 qemu_cfg_next_file (QemuCfgFile *entry); +#endif
Signature · 1 line
1.6.5.2
I needed the following patch for this series to build:
src/optionroms.c +0 -0
@@ -13,6 +13,7 @@
#include "pci_regs.h" // PCI_ROM_ADDRESS
#include "pci_ids.h" // PCI_CLASS_DISPLAY_VGA
#include "boot.h" // IPL
+#include "paravirt.h" // qemu_cfg_*
/****************************************************************
src/paravirt.h +0 -0
@@ -63,5 +63,6 @@ typedef struct QemuCfgFile {
u16 qemu_cfg_first_file(QemuCfgFile *entry);
u16 qemu_cfg_next_file(QemuCfgFile *entry);
+u32 qemu_cfg_read_file(QemuCfgFile *entry, void *dst, u32 maxlen);
#endif
Regards,
Anthony Liguori
src/paravirt.h
Quoted 10 lines · Anthony Liguori
I needed the following patch for this series to build:
src/optionroms.c +1
-0@@ -13,6 +13,7 @@ +#include "paravirt.h" // qemu_cfg_* src/paravirt.h +1
-0+u32 qemu_cfg_read_file (QemuCfgFile *entry,void *dst,u32 maxlen);
Patch is very reasonable.
/me wonders how it did build for me without warning about the missing prototype ...
cheers,
Gerd
Quoted 8 lines · Gerd Hoffmann
Quoted 6 lines · Anthony Liguori
I needed the following patch for this series to build:
src/optionroms.c +1
-0@@ -13,6 +13,7 @@ +#include "paravirt.h" // qemu_cfg_*
Quoted 7 lines
src/paravirt.h
Quoted 3 lines
src/paravirt.h +1
-0+u32 qemu_cfg_read_file (QemuCfgFile *entry,void *dst,u32 maxlen);Patch is very reasonable.
/me wonders how it did build for me without warning about the missing prototype ...
I think your fw_cfg.h changes also broke the optionroms/multiboot build. Haven't debugged yet though.
Regards,
Anthony Liguori
Quoted 2 lines · Anthony Liguori
I think your
fw_cfg.hchanges also broke the optionroms/multiboot build. Haven't debugged yet though.
That one is easy to fix, see attachment
cheers,
Gerd
hw/fw_cfg.h +1 -1
@@ -38,6 +38,7 @@#define FW_CFG_INVALID 0xffff +#ifndef NO_QEMU_PROTOS typedef struct FWCfgFile { uint32_t size; /* file size */ uint16_t select; /* write this to 0x510 to read it */
@@ -50,7 +51,6 @@ typedef struct FWCfgFiles {FWCfgFile f[]; } FWCfgFiles; -#ifndef NO_QEMU_PROTOS typedef void (*FWCfgCallback )(void *opaque,uint8_t *data);typedef struct _FWCfgState FWCfgState ;
Quoted 8 lines · Gerd Hoffmann
Quoted 6 lines · Anthony Liguori
I needed the following patch for this series to build:
src/optionroms.c +1
-0@@ -13,6 +13,7 @@ +#include "paravirt.h" // qemu_cfg_*
Quoted 8 lines
src/paravirt.h
Quoted 3 lines
src/paravirt.h +1
-0+u32 qemu_cfg_read_file (QemuCfgFile *entry,void *dst,u32 maxlen);Patch is very reasonable.
/me wonders how it did build for me without warning about the missing prototype ...
SeaBIOS tries to use -fwhole-program to optimize the build. Unfortunately, that option appears to be a bit "bleeding edge", and some gcc versions have a hard time with it. So, SeaBIOS supports two ways to build with -fwhole-program - one with "-combine", and one with a textual inclusion of all files. Unfortunately, some errors can be masked in one type of build that are exposed in the other type.
The next major version of gcc should have support for "-flto". Once distros start shipping it, I think seabios should just support the new lto mechanism and the standard non-whole-program build. That should simplify these build issues.
-Kevin
Quoted 6 lines · Gerd Hoffmann
Hi,
qemu is about to change the way how option roms are loaded. pci roms will be loaded into a option rom bar (like real hardware does). non-pci roms can be loaded using the qemu firmware interface.
Quoted 8 lines
With this change seabios will deploy all roms instead of having qemu copy them to the
0xc0000-> 0e0000 range. Advantages are:* roms can be packed better, especially in case they resize themself (like the gPXE roms do).
* rom area is a bit larger as seabios can additionally use theunused regions of the 0xe0000 segment.* the whole process comes closer to what happens on real hardware.
The SeaBIOS changes all look reasonable to me. Just need to make sure they are coordinated with the associated qemu changes.
Anthony - it looks like you've made some changes to your seabios repo, but I don't think you've pushed them yet.
-Kevin
Quoted 18 lines · Kevin O'Connor
Quoted 6 lines · Gerd Hoffmann
Hi,
qemu is about to change the way how option roms are loaded. pci roms will be loaded into a option rom bar (like real hardware does). non-pci roms can be loaded using the qemu firmware interface.
Quoted 9 lines
With this change seabios will deploy all roms instead of having qemu copy them to the
0xc0000-> 0e0000 range. Advantages are:* roms can be packed better, especially in case they resize themself (like the gPXE roms do).
* rom area is a bit larger as seabios can additionally use theunused regions of the 0xe0000 segment.* the whole process comes closer to what happens on real hardware.
Quoted 6 lines
The SeaBIOS changes all look reasonable to me. Just need to make sure they are coordinated with the associated qemu changes.
Anthony - it looks like you've made some changes to your seabios repo, but I don't think you've pushed them yet.
I've pushed now. Don't worry about merging them from me though, it's easy enough to let git do it's magic here.
Regards,
Anthony Liguori
Kevin O'Connor
AppliedQuoted 5 lines · Anthony Liguori
Quoted 2 lines
Anthony - it looks like you've made some changes to your seabios repo, but I don't think you've pushed them yet.
I've pushed now. Don't worry about merging them from me though, it's easy enough to let git do it's magic here.
I've merged the changes. Thanks Gerd. Thanks Anthony.
-Kevin