mb/emulation/qemu-i440fx: change file handling
Reduce the number of fw_find_file calls by returning the file structure at fw_cfg_check_file. The file structure can then be used to allocate memory and access the file content directly without recurrence searching. Remove now unnecessary function fw_cfg_load_file. Fixed breaking function calls and add include guard at fw_cfg_if.h. Change-Id: I48cc943aaa999e4323e9d7e5dd666c5316533dcc Signed-off-by: Thomas Heijligen <thomas.heijligen@secunet.com> Reviewed-on: https://review.coreboot.org/c/30845 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Patrick Rudolph <siro@das-labor.org>
This commit is contained in:
parent
d053f393c4
commit
bcd84fe149
|
@ -81,28 +81,16 @@ static FWCfgFile *fw_cfg_find_file(const char *name)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int fw_cfg_check_file(const char *name)
|
int fw_cfg_check_file(FWCfgFile *file, const char *name)
|
||||||
{
|
{
|
||||||
FWCfgFile *file;
|
FWCfgFile *f;
|
||||||
|
|
||||||
if (!fw_cfg_present())
|
if (!fw_cfg_present())
|
||||||
return -1;
|
return -1;
|
||||||
file = fw_cfg_find_file(name);
|
f = fw_cfg_find_file(name);
|
||||||
if (!file)
|
if (!f)
|
||||||
return -1;
|
return -1;
|
||||||
return file->size;
|
*file = *f;
|
||||||
}
|
return 0;
|
||||||
|
|
||||||
void fw_cfg_load_file(const char *name, void *dst)
|
|
||||||
{
|
|
||||||
FWCfgFile *file;
|
|
||||||
|
|
||||||
if (!fw_cfg_present())
|
|
||||||
return;
|
|
||||||
file = fw_cfg_find_file(name);
|
|
||||||
if (!file)
|
|
||||||
return;
|
|
||||||
fw_cfg_get(file->select, dst, file->size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int fw_cfg_max_cpus(void)
|
int fw_cfg_max_cpus(void)
|
||||||
|
@ -202,21 +190,21 @@ enum {
|
||||||
|
|
||||||
unsigned long fw_cfg_acpi_tables(unsigned long start)
|
unsigned long fw_cfg_acpi_tables(unsigned long start)
|
||||||
{
|
{
|
||||||
|
FWCfgFile f;
|
||||||
BiosLinkerLoaderEntry *s;
|
BiosLinkerLoaderEntry *s;
|
||||||
unsigned long *addrs, current;
|
unsigned long *addrs, current;
|
||||||
uint8_t *ptr;
|
uint8_t *ptr;
|
||||||
int rc, i, j, src, dst, max;
|
int i, j, src, dst, max;
|
||||||
|
|
||||||
rc = fw_cfg_check_file("etc/table-loader");
|
if (fw_cfg_check_file(&f, "etc/table-loader"))
|
||||||
if (rc < 0)
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
printk(BIOS_DEBUG, "QEMU: found ACPI tables in fw_cfg.\n");
|
printk(BIOS_DEBUG, "QEMU: found ACPI tables in fw_cfg.\n");
|
||||||
|
|
||||||
max = rc / sizeof(*s);
|
max = f.size / sizeof(*s);
|
||||||
s = malloc(rc);
|
s = malloc(f.size);
|
||||||
addrs = malloc(max * sizeof(*addrs));
|
addrs = malloc(max * sizeof(*addrs));
|
||||||
fw_cfg_load_file("etc/table-loader", s);
|
fw_cfg_get(f.select, s, f.size);
|
||||||
|
|
||||||
current = start;
|
current = start;
|
||||||
for (i = 0; i < max && s[i].command != 0; i++) {
|
for (i = 0; i < max && s[i].command != 0; i++) {
|
||||||
|
@ -227,14 +215,14 @@ unsigned long fw_cfg_acpi_tables(unsigned long start)
|
||||||
switch (s[i].command) {
|
switch (s[i].command) {
|
||||||
case BIOS_LINKER_LOADER_COMMAND_ALLOCATE:
|
case BIOS_LINKER_LOADER_COMMAND_ALLOCATE:
|
||||||
current = ALIGN(current, s[i].alloc.align);
|
current = ALIGN(current, s[i].alloc.align);
|
||||||
rc = fw_cfg_check_file(s[i].alloc.file);
|
if (fw_cfg_check_file(&f, s[i].alloc.file))
|
||||||
if (rc < 0)
|
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
printk(BIOS_DEBUG, "QEMU: loading \"%s\" to 0x%lx (len %d)\n",
|
printk(BIOS_DEBUG, "QEMU: loading \"%s\" to 0x%lx (len %d)\n",
|
||||||
s[i].alloc.file, current, rc);
|
s[i].alloc.file, current, f.size);
|
||||||
fw_cfg_load_file(s[i].alloc.file, (void*)current);
|
fw_cfg_get(f.select, (void *)current, sizeof(current));
|
||||||
addrs[i] = current;
|
addrs[i] = current;
|
||||||
current += rc;
|
current += f.size;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BIOS_LINKER_LOADER_COMMAND_ADD_POINTER:
|
case BIOS_LINKER_LOADER_COMMAND_ADD_POINTER:
|
||||||
|
@ -400,15 +388,16 @@ static unsigned long smbios_next(unsigned long current)
|
||||||
*/
|
*/
|
||||||
unsigned long fw_cfg_smbios_tables(int *handle, unsigned long *current)
|
unsigned long fw_cfg_smbios_tables(int *handle, unsigned long *current)
|
||||||
{
|
{
|
||||||
|
FWCfgFile f;
|
||||||
struct smbios_type0 *t0;
|
struct smbios_type0 *t0;
|
||||||
unsigned long start, end;
|
unsigned long start, end;
|
||||||
int len, ret, i, count = 1;
|
int ret, i, count = 1;
|
||||||
char *str;
|
char *str;
|
||||||
|
|
||||||
len = fw_cfg_check_file("etc/smbios/smbios-tables");
|
if (fw_cfg_check_file(&f, "etc/smbios/smbios-tables"))
|
||||||
if (len < 0)
|
|
||||||
return 0;
|
return 0;
|
||||||
printk(BIOS_DEBUG, "QEMU: found smbios tables in fw_cfg (len %d).\n", len);
|
|
||||||
|
printk(BIOS_DEBUG, "QEMU: found smbios tables in fw_cfg (len %d).\n", f.size);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Search backwards for "coreboot" (first string in type0 table,
|
* Search backwards for "coreboot" (first string in type0 table,
|
||||||
|
@ -434,7 +423,7 @@ unsigned long fw_cfg_smbios_tables(int *handle, unsigned long *current)
|
||||||
* We'll exclude the end marker as coreboot will add one.
|
* We'll exclude the end marker as coreboot will add one.
|
||||||
*/
|
*/
|
||||||
printk(BIOS_DEBUG, "QEMU: loading smbios tables to 0x%lx\n", start);
|
printk(BIOS_DEBUG, "QEMU: loading smbios tables to 0x%lx\n", start);
|
||||||
fw_cfg_load_file("etc/smbios/smbios-tables", (void*)start);
|
fw_cfg_get(f.select, (void *)start, sizeof(start));
|
||||||
end = start;
|
end = start;
|
||||||
do {
|
do {
|
||||||
t0 = (struct smbios_type0*)end;
|
t0 = (struct smbios_type0*)end;
|
||||||
|
@ -442,7 +431,7 @@ unsigned long fw_cfg_smbios_tables(int *handle, unsigned long *current)
|
||||||
break;
|
break;
|
||||||
end = smbios_next(end);
|
end = smbios_next(end);
|
||||||
count++;
|
count++;
|
||||||
} while (end < start + len);
|
} while (end < start + f.size);
|
||||||
|
|
||||||
/* final fixups. */
|
/* final fixups. */
|
||||||
ret = end - *current;
|
ret = end - *current;
|
||||||
|
|
|
@ -10,9 +10,13 @@
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*/
|
*/
|
||||||
|
#ifndef FW_CFG_H
|
||||||
|
#define FW_CFG_H
|
||||||
|
#include "fw_cfg_if.h"
|
||||||
|
|
||||||
void fw_cfg_get(int entry, void *dst, int dstlen);
|
void fw_cfg_get(int entry, void *dst, int dstlen);
|
||||||
int fw_cfg_check_file(const char *name);
|
int fw_cfg_check_file(FWCfgFile *file, const char *name);
|
||||||
void fw_cfg_load_file(const char *name, void *dst);
|
|
||||||
int fw_cfg_max_cpus(void);
|
int fw_cfg_max_cpus(void);
|
||||||
unsigned long fw_cfg_smbios_tables(int *handle, unsigned long *current);
|
unsigned long fw_cfg_smbios_tables(int *handle, unsigned long *current);
|
||||||
|
|
||||||
|
#endif /* FW_CFG_H */
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
* This are the qemu firmware config interface defines and structs.
|
* This are the qemu firmware config interface defines and structs.
|
||||||
* Copyed over from qemu soure tree, include/hw/nvram/fw_cfg.h
|
* Copyed over from qemu soure tree, include/hw/nvram/fw_cfg.h
|
||||||
*/
|
*/
|
||||||
|
#ifndef FW_CFG_IF_H
|
||||||
|
#define FW_CFG_IF_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
@ -90,3 +92,5 @@ typedef struct FwCfgSmbios {
|
||||||
uint8_t tabletype;
|
uint8_t tabletype;
|
||||||
uint16_t fieldoffset;
|
uint16_t fieldoffset;
|
||||||
} FwCfgSmbios;
|
} FwCfgSmbios;
|
||||||
|
|
||||||
|
#endif /* FW_CFG_IF_H */
|
||||||
|
|
|
@ -59,17 +59,16 @@ static void cpu_pci_domain_read_resources(struct device *dev)
|
||||||
struct resource *res;
|
struct resource *res;
|
||||||
unsigned long tomk = 0, high;
|
unsigned long tomk = 0, high;
|
||||||
int idx = 10;
|
int idx = 10;
|
||||||
int size;
|
FWCfgFile f;
|
||||||
|
|
||||||
pci_domain_read_resources(dev);
|
pci_domain_read_resources(dev);
|
||||||
|
|
||||||
size = fw_cfg_check_file("etc/e820");
|
if (!fw_cfg_check_file(&f, "etc/e820") && f.size > 0) {
|
||||||
if (size > 0) {
|
|
||||||
/* supported by qemu 1.7+ */
|
/* supported by qemu 1.7+ */
|
||||||
FwCfgE820Entry *list = malloc(size);
|
FwCfgE820Entry *list = malloc(f.size);
|
||||||
int i;
|
int i;
|
||||||
fw_cfg_load_file("etc/e820", list);
|
fw_cfg_get(f.select, list, f.size);
|
||||||
for (i = 0; i < size/sizeof(*list); i++) {
|
for (i = 0; i < f.size / sizeof(*list); i++) {
|
||||||
switch (list[i].type) {
|
switch (list[i].type) {
|
||||||
case 1: /* RAM */
|
case 1: /* RAM */
|
||||||
printk(BIOS_DEBUG, "QEMU: e820/ram: 0x%08llx +0x%08llx\n",
|
printk(BIOS_DEBUG, "QEMU: e820/ram: 0x%08llx +0x%08llx\n",
|
||||||
|
|
Loading…
Reference in New Issue