Make the qemu_cfg optionrom extraction code use an interface more
similar to the cbfs file interface.
Introduce a set of "romfile_" wrappers that select between cbfs and
qemu cfg interface. Use these new wrappers in the optionrom code.
---
src/coreboot.c | 15 +--------------
src/optionroms.c | 42 ++++++++++++------------------------------
src/paravirt.c | 48 +++++++++++++++++++++++++++++-------------------
src/paravirt.h | 24 +++++++++++++++++++++---
src/util.h | 3 +--
5 files changed, 64 insertions(+), 68 deletions(-)
diff --git a/src/coreboot.c b/src/coreboot.c
index 883834c..5d9a101 100644
--- a/src/coreboot.c
+++ b/src/coreboot.c
@@ -459,7 +459,7 @@ cbfs_findprefix(const char *prefix, struct cbfs_file *last)
}
// Find a file with the given filename (possibly with ".lzma" extension).
-static struct cbfs_file *
+struct cbfs_file *
cbfs_finddatafile(const char *fname)
{
int fnlen = strlen(fname);
@@ -531,19 +531,6 @@ cbfs_copyfile(struct cbfs_file *file, void *dst, u32 maxlen)
return size;
}
-// Find and copy the optionrom for the given vendor/device id.
-int
-cbfs_copy_optionrom(void *dst, u32 maxlen, u32 vendev)
-{
- if (!CONFIG_COREBOOT || !CONFIG_COREBOOT_FLASH)
- return -1;
-
- char fname[17];
- snprintf(fname, sizeof(fname), "pci%04x,%04x.rom"
- , (u16)vendev, vendev >> 16);
- return cbfs_copyfile(cbfs_finddatafile(fname), dst, maxlen);
-}
-
struct cbfs_payload_segment {
u32 type;
u32 compression;
diff --git a/src/optionroms.c b/src/optionroms.c
index f144d83..0b0f396 100644
--- a/src/optionroms.c
+++ b/src/optionroms.c
@@ -227,47 +227,31 @@ lookup_hardcode(u32 vendev)
&& ((OPTIONROM_VENDEV_2 >> 16)
| ((OPTIONROM_VENDEV_2 & 0xffff)) << 16) == vendev)
return copy_rom((void*)OPTIONROM_MEM_2);
- int ret = cbfs_copy_optionrom((void*)RomEnd, max_rom() - RomEnd, vendev);
- if (ret < 0)
+ char fname[17];
+ snprintf(fname, sizeof(fname), "pci%04x,%04x.rom"
+ , pci_vd_to_ven(vendev), pci_vd_to_dev(vendev));
+ int ret = romfile_copy(romfile_find(fname), (void*)RomEnd
+ , max_rom() - RomEnd);
+ if (ret <= 0)
return NULL;
return (void*)RomEnd;
}
// Run all roms in a given CBFS directory.
static void
-run_cbfs_roms(const char *prefix, int isvga)
+run_file_roms(const char *prefix, int isvga)
{
- struct cbfs_file *file = NULL;
+ u32 file = 0;
for (;;) {
- file = cbfs_findprefix(prefix, file);
+ file = romfile_findprefix(prefix, file);
if (!file)
break;
- int ret = cbfs_copyfile(file, (void*)RomEnd, max_rom() - RomEnd);
+ int ret = romfile_copy(file, (void*)RomEnd, max_rom() - RomEnd);
if (ret > 0)
init_optionrom((void*)RomEnd, 0, 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
@@ -397,8 +381,7 @@ optionrom_setup(void)
}
// Find and deploy CBFS roms not associated with a device.
- run_cbfs_roms("genroms/", 0);
- run_qemu_roms("genroms/", 0);
+ run_file_roms("genroms/", 0);
}
// All option roms found and deployed - now build BEV/BCV vectors.
@@ -457,8 +440,7 @@ vga_setup(void)
init_pcirom(bdf, 1);
// Find and deploy CBFS vga-style roms not associated with a device.
- run_cbfs_roms("vgaroms/", 1);
- run_qemu_roms("vgaroms/", 1);
+ run_file_roms("vgaroms/", 1);
}
if (RomEnd == BUILD_ROM_START) {
diff --git a/src/paravirt.c b/src/paravirt.c
index 5c77b5c..00ff58c 100644
--- a/src/paravirt.c
+++ b/src/paravirt.c
@@ -306,38 +306,48 @@ 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);
-}
+static QemuCfgFile LastFile;
-u16 qemu_cfg_next_file(QemuCfgFile *entry)
+static u32
+__cfg_next_prefix_file(const char *prefix, int prefixlen, u32 prevselect)
{
- u16 last = ntohs(entry->select);
- u32 e,count;
-
if (!qemu_cfg_present)
return 0;
+ u32 count;
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;
- }
+ count = ntohl(count);
+ u32 e;
+ for (e = 0; e < count; e++) {
+ qemu_cfg_read((void*)&LastFile, sizeof(LastFile));
+ u32 select = ntohs(LastFile.select);
+ if (select <= prevselect)
+ continue;
+ if (memcmp(prefix, LastFile.name, prefixlen) == 0)
+ return select;
}
return 0;
}
-u32 qemu_cfg_read_file(QemuCfgFile *entry, void *dst, u32 maxlen)
+u32 qemu_cfg_next_prefix_file(const char *prefix, u32 prevselect)
+{
+ return __cfg_next_prefix_file(prefix, strlen(prefix), prevselect);
+}
+
+u32 qemu_cfg_find_file(const char *name)
{
- int len = ntohl(entry->size);
+ return __cfg_next_prefix_file(name, strlen(name) + 1, 0);
+}
+int qemu_cfg_read_file(u32 select, void *dst, u32 maxlen)
+{
if (!qemu_cfg_present)
- return 0;
+ return -1;
+ if (!select || select != ntohs(LastFile.select))
+ return -1;
+ int len = ntohl(LastFile.size);
if (len > maxlen)
- return 0;
- qemu_cfg_read_entry(dst, ntohs(entry->select), len);
+ return -1;
+ qemu_cfg_read_entry(dst, select, len);
return len;
}
diff --git a/src/paravirt.h b/src/paravirt.h
index c46418f..83fe8ec 100644
--- a/src/paravirt.h
+++ b/src/paravirt.h
@@ -68,9 +68,27 @@ struct e820_reservation {
u32 type;
};
-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);
+u32 qemu_cfg_next_prefix_file(const char *prefix, u32 prevselect);
+u32 qemu_cfg_find_file(const char *name);
+int qemu_cfg_read_file(u32 select, void *dst, u32 maxlen);
+
+// Wrappers that select cbfs or qemu_cfg file interface.
+static inline u32 romfile_findprefix(const char *prefix, u32 previd) {
+ if (CONFIG_COREBOOT)
+ return (u32)cbfs_findprefix(prefix, (void*)previd);
+ return qemu_cfg_next_prefix_file(prefix, previd);
+}
+static inline u32 romfile_find(const char *name) {
+ if (CONFIG_COREBOOT)
+ return (u32)cbfs_finddatafile(name);
+ return qemu_cfg_find_file(name);
+}
+static inline int romfile_copy(u32 fileid, void *dst, u32 maxlen) {
+ if (CONFIG_COREBOOT)
+ return cbfs_copyfile((void*)fileid, dst, maxlen);
+ return qemu_cfg_read_file(fileid, dst, maxlen);
+}
+
u32 qemu_cfg_e820_entries(void);
void* qemu_cfg_e820_load_next(void *addr);
diff --git a/src/util.h b/src/util.h
index 7fd76bc..a630bc1 100644
--- a/src/util.h
+++ b/src/util.h
@@ -338,13 +338,12 @@ void smp_probe_setup(void);
// coreboot.c
struct cbfs_file;
+struct cbfs_file *cbfs_finddatafile(const char *fname);
struct cbfs_file *cbfs_findprefix(const char *prefix, struct cbfs_file *last);
u32 cbfs_datasize(struct cbfs_file *file);
const char *cbfs_filename(struct cbfs_file *file);
int cbfs_copyfile(struct cbfs_file *file, void *dst, u32 maxlen);
-int cbfs_copy_optionrom(void *dst, u32 maxlen, u32 vendev);
void cbfs_run_payload(struct cbfs_file *file);
-
void coreboot_copy_biostable(void);
void coreboot_setup(void);
--
1.7.0.1