cbfs: Simplify load/map API names, remove type arguments

This patch renames cbfs_boot_map_with_leak() and cbfs_boot_load_file()
to cbfs_map() and cbfs_load() respectively. This is supposed to be the
start of a new, better organized CBFS API where the most common
operations have the most simple and straight-forward names. Less
commonly used variants of these operations (e.g. cbfs_ro_load() or
cbfs_region_load()) can be introduced later. It seems unnecessary to
keep carrying around "boot" in the names of most CBFS APIs if the vast
majority of accesses go to the boot CBFS (instead, more unusual
operations should have longer names that describe how they diverge from
the common ones).

cbfs_map() is paired with a new cbfs_unmap() to allow callers to cleanly
reap mappings when desired. A few new cbfs_unmap() calls are added to
generic code where it makes sense, but it seems unnecessary to introduce
this everywhere in platform or architecture specific code where the boot
medium is known to be memory-mapped anyway. In fact, even for
non-memory-mapped platforms, sometimes leaking a mapping to the CBFS
cache is a much cleaner solution than jumping through hoops to provide
some other storage for some long-lived file object, and it shouldn't be
outright forbidden when it makes sense.

Additionally, remove the type arguments from these function signatures.
The goal is to eventually remove type arguments for lookup from the
whole CBFS API. Filenames already uniquely identify CBFS files. The type
field is just informational, and there should be APIs to allow callers
to check it when desired, but it's not clear what we gain from forcing
this as a parameter into every single CBFS access when the vast majority
of the time it provides no additional value and is just clutter.

Signed-off-by: Julius Werner <jwerner@chromium.org>
Change-Id: Ib24325400815a9c3d25f66c61829a24a239bb88e
Reviewed-on: https://review.coreboot.org/c/coreboot/+/39304
Reviewed-by: Hung-Te Lin <hungte@chromium.org>
Reviewed-by: Wim Vervoorn <wvervoorn@eltan.com>
Reviewed-by: Mariusz Szafrański <mariuszx.szafranski@intel.com>
Reviewed-by: Patrick Georgi <pgeorgi@google.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
Julius Werner
2020-03-04 16:52:08 -08:00
committed by Patrick Georgi
parent 0d9072b1a1
commit 834b3ecd7c
76 changed files with 124 additions and 184 deletions

View File

@@ -26,8 +26,7 @@ void mainboard_get_spd(spd_raw_data *spd, bool id_only)
{
void *spd_file;
size_t spd_file_len = 0;
spd_file = cbfs_boot_map_with_leak("spd.bin", CBFS_TYPE_SPD,
&spd_file_len);
spd_file = cbfs_map("spd.bin", &spd_file_len);
if (spd_file && spd_file_len >= 1024) {
int i;
for (i = 0; i < 4; i++)

View File

@@ -442,8 +442,7 @@ void sch5545_update_ec_firmware(uint16_t ec_version)
uint32_t *ec_fw_file;
size_t ec_fw_file_size;
ec_fw_file = cbfs_boot_map_with_leak("sch5545_ecfw.bin", CBFS_TYPE_RAW,
&ec_fw_file_size);
ec_fw_file = cbfs_map("sch5545_ecfw.bin", &ec_fw_file_size);
if (!ec_fw_file || ec_fw_file_size != 0x1750) {
printk(BIOS_ERR, "EC firmware file not found in CBFS!\n");

View File

@@ -17,8 +17,7 @@ const struct sdram_info *get_sdram_config(void)
uint32_t ramcode = ram_code();
if (ramcode >= ARRAY_SIZE(sdram_configs) ||
cbfs_boot_load_file(sdram_configs[ramcode], &params, sizeof(params),
CBFS_TYPE_STRUCT) != sizeof(params))
cbfs_load(sdram_configs[ramcode], &params, sizeof(params)) != sizeof(params))
die("Cannot load SDRAM parameter file for RAM code: %#x", ramcode);
return &params;

View File

@@ -88,7 +88,7 @@ void mainboard_fill_spd_data(struct pei_data *pei_data)
spd_bits[1], spd_gpio[1],
spd_bits[0], spd_gpio[0]);
spd_file = cbfs_boot_map_with_leak("spd.bin", 0xab, &spd_file_len);
spd_file = cbfs_map("spd.bin", &spd_file_len);
if (!spd_file)
die("SPD data not found.");

View File

@@ -88,7 +88,7 @@ void mainboard_fill_spd_data(struct pei_data *pei_data)
spd_bits[1], spd_gpio[1],
spd_bits[0], spd_gpio[0]);
spd_file = cbfs_boot_map_with_leak("spd.bin", 0xab, &spd_file_len);
spd_file = cbfs_map("spd.bin", &spd_file_len);
if (!spd_file)
die("SPD data not found.");

View File

@@ -129,9 +129,7 @@ static void program_mac_address(u16 io_base)
search_length = region_device_sz(&rdev);
}
} else {
search_address = cbfs_boot_map_with_leak("vpd.bin",
CBFS_TYPE_RAW,
&search_length);
search_address = cbfs_map("vpd.bin", &search_length);
}
if (search_address == NULL)

View File

@@ -88,7 +88,7 @@ void mainboard_fill_spd_data(struct pei_data *pei_data)
spd_bits[1], spd_gpio[1],
spd_bits[0], spd_gpio[0]);
spd_file = cbfs_boot_map_with_leak("spd.bin", 0xab, &spd_file_len);
spd_file = cbfs_map("spd.bin", &spd_file_len);
if (!spd_file)
die("SPD data not found.");

View File

@@ -92,7 +92,7 @@ void mainboard_fill_spd_data(struct pei_data *pei_data)
spd_bits[1], spd_gpio[1],
spd_bits[0], spd_gpio[0]);
spd_file = cbfs_boot_map_with_leak("spd.bin", 0xab, &spd_file_len);
spd_file = cbfs_map("spd.bin", &spd_file_len);
if (!spd_file)
die("SPD data not found.");

View File

@@ -88,7 +88,7 @@ void mainboard_fill_spd_data(struct pei_data *pei_data)
spd_bits[3], spd_gpio[3], spd_bits[2], spd_gpio[2],
spd_bits[1], spd_gpio[1], spd_bits[0], spd_gpio[0]);
spd_file = cbfs_boot_map_with_leak("spd.bin", 0xab, &spd_file_len);
spd_file = cbfs_map("spd.bin", &spd_file_len);
if (!spd_file)
die("SPD data not found.");

View File

@@ -110,9 +110,7 @@ static void program_mac_address(u16 io_base)
search_length = region_device_sz(&rdev);
}
} else {
search_address = cbfs_boot_map_with_leak("vpd.bin",
CBFS_TYPE_RAW,
&search_length);
search_address = cbfs_map("vpd.bin", &search_length);
}
if (search_address == NULL)

View File

@@ -180,8 +180,7 @@ static void mainboard_init(struct device *dev)
}
}
} else {
vpd_file = cbfs_boot_map_with_leak("vpd.bin", CBFS_TYPE_RAW,
&search_length);
vpd_file = cbfs_map("vpd.bin", &search_length);
if (vpd_file) {
search_address = (unsigned long)vpd_file;
} else {

View File

@@ -35,8 +35,7 @@ static void *get_spd_pointer(int *dual)
int spd_index = 0;
/* Find the SPD data in CBFS. */
spd_file = cbfs_boot_map_with_leak("spd.bin", CBFS_TYPE_SPD,
&spd_file_len);
spd_file = cbfs_map("spd.bin", &spd_file_len);
if (!spd_file)
die("SPD data not found.");

View File

@@ -82,8 +82,7 @@ uintptr_t mainboard_get_spd_data(void)
printk(BIOS_INFO, "SPD index %d\n", spd_index);
/* Load SPD data from CBFS */
spd_file = cbfs_boot_map_with_leak("spd.bin", CBFS_TYPE_SPD,
&spd_file_len);
spd_file = cbfs_map("spd.bin", &spd_file_len);
if (!spd_file)
die("SPD data not found.");

View File

@@ -79,8 +79,7 @@ void spd_memory_init_params(FSPM_UPD *mupd, int spd_index)
printk(BIOS_INFO, "SPD index %d\n", spd_index);
/* Load SPD data from CBFS */
spd_file = cbfs_boot_map_with_leak("spd.bin", CBFS_TYPE_SPD,
&spd_file_len);
spd_file = cbfs_map("spd.bin", &spd_file_len);
if (!spd_file)
die("SPD data not found.");

View File

@@ -53,8 +53,7 @@ const struct rk3399_sdram_params *get_sdram_config()
if (ramcode >= ARRAY_SIZE(sdram_configs) ||
!snprintf(config_file, sizeof(config_file), "%s-%d",
sdram_configs[ramcode], get_sdram_target_mhz()) ||
(cbfs_boot_load_file(config_file, &params, sizeof(params),
CBFS_TYPE_STRUCT) != sizeof(params)))
(cbfs_load(config_file, &params, sizeof(params)) != sizeof(params)))
die("Cannot load SDRAM parameter file!");
return &params;

View File

@@ -110,9 +110,7 @@ static void program_mac_address(u16 io_base)
search_length = region_device_sz(&rdev);
}
} else {
search_address = cbfs_boot_map_with_leak("vpd.bin",
CBFS_TYPE_RAW,
&search_length);
search_address = cbfs_map("vpd.bin", &search_length);
}
if (search_address == NULL)

View File

@@ -89,9 +89,7 @@ const char *smbios_mainboard_manufacturer(void)
if (manuf)
return manuf;
if (cbfs_boot_load_file("oem.bin", oem_bin_data,
sizeof(oem_bin_data) - 1,
CBFS_TYPE_RAW))
if (cbfs_load("oem.bin", oem_bin_data, sizeof(oem_bin_data) - 1))
manuf = &oem_bin_data[0];
else
manuf = CONFIG_MAINBOARD_SMBIOS_MANUFACTURER;

View File

@@ -101,9 +101,7 @@ const char *smbios_mainboard_manufacturer(void)
if (manuf)
return manuf;
if (cbfs_boot_load_file("oem.bin", oem_bin_data,
sizeof(oem_bin_data) - 1,
CBFS_TYPE_RAW))
if (cbfs_load("oem.bin", oem_bin_data, sizeof(oem_bin_data) - 1))
manuf = &oem_bin_data[0];
else
manuf = CONFIG_MAINBOARD_SMBIOS_MANUFACTURER;

View File

@@ -101,9 +101,7 @@ const char *smbios_mainboard_manufacturer(void)
if (manuf)
return manuf;
if (cbfs_boot_load_file("oem.bin", oem_bin_data,
sizeof(oem_bin_data) - 1,
CBFS_TYPE_RAW))
if (cbfs_load("oem.bin", oem_bin_data, sizeof(oem_bin_data) - 1))
manuf = &oem_bin_data[0];
else
manuf = CONFIG_MAINBOARD_SMBIOS_MANUFACTURER;

View File

@@ -112,8 +112,7 @@ struct panel_description *get_panel_from_cbfs(struct panel_description *desc)
return NULL;
snprintf(cbfs_name, sizeof(cbfs_name), "panel-%s", desc->name);
if (cbfs_boot_load_file(cbfs_name, buffer.raw, sizeof(buffer),
CBFS_TYPE_STRUCT))
if (cbfs_load(cbfs_name, buffer.raw, sizeof(buffer)))
desc->s = &buffer.s;
else
printk(BIOS_ERR, "Missing %s in CBFS.\n", cbfs_name);

View File

@@ -43,8 +43,7 @@ const struct sdram_params *get_sdram_config(void)
if (ramcode < ARRAY_SIZE(sdram_configs))
name = sdram_configs[ramcode];
if (!name || cbfs_boot_load_file(name, &params, sizeof(params),
CBFS_TYPE_STRUCT) != sizeof(params))
if (!name || cbfs_load(name, &params, sizeof(params)) != sizeof(params))
die("Cannot load SDRAM parameter file for RAM code %#02x: %s!",
ramcode, name ? name : "unknown");

View File

@@ -66,8 +66,7 @@ static uint8_t *locate_spd(void)
int spd_index = get_gpios(gpio_vector);
printk(BIOS_DEBUG, "spd index %d\n", spd_index);
spd_file = cbfs_boot_map_with_leak("spd.bin", CBFS_TYPE_SPD,
&spd_file_len);
spd_file = cbfs_map("spd.bin", &spd_file_len);
if (!spd_file)
die("SPD data not found.");

View File

@@ -112,8 +112,7 @@ static uintptr_t mainboard_get_spd_data(enum memory_type type, bool use_sec_spd)
printk(BIOS_INFO, "SPD index %d\n", spd_index);
/* Load SPD data from CBFS */
spd_file = cbfs_boot_map_with_leak(spd_bin, CBFS_TYPE_SPD,
&spd_file_len);
spd_file = cbfs_map(spd_bin, &spd_file_len);
if (!spd_file)
die("SPD data not found.");

View File

@@ -155,9 +155,8 @@ const char *smbios_mainboard_manufacturer(void)
if (oem_id == OEM_UNKNOWN)
return CONFIG_MAINBOARD_SMBIOS_MANUFACTURER;
oem_data_size = cbfs_boot_load_file("oem.bin", oem_bin_data,
sizeof(oem_bin_data),
CBFS_TYPE_RAW);
oem_data_size = cbfs_load("oem.bin", oem_bin_data,
sizeof(oem_bin_data));
while ((curr < oem_data_size) &&
((oem_data_size - curr) >= sizeof(*oem_entry))) {

View File

@@ -48,8 +48,7 @@ void mainboard_fill_mrc_params(struct mrc_params *mp)
void *spd_file;
size_t spd_fsize;
spd_file = cbfs_boot_map_with_leak("spd.bin", CBFS_TYPE_SPD,
&spd_fsize);
spd_file = cbfs_map("spd.bin", &spd_fsize);
if (!spd_file)
die("SPD data not found.");

View File

@@ -109,9 +109,7 @@ static void program_mac_address(u16 io_base)
search_length = region_device_sz(&rdev);
}
} else {
search_address = cbfs_boot_map_with_leak("vpd.bin",
CBFS_TYPE_RAW,
&search_length);
search_address = cbfs_map("vpd.bin", &search_length);
}
if (search_address == NULL)

View File

@@ -109,9 +109,7 @@ static void program_mac_address(u16 io_base)
search_length = region_device_sz(&rdev);
}
} else {
search_address = cbfs_boot_map_with_leak("vpd.bin",
CBFS_TYPE_RAW,
&search_length);
search_address = cbfs_map("vpd.bin", &search_length);
}
if (search_address == NULL)

View File

@@ -21,8 +21,7 @@ void copy_spd(struct pei_data *peid)
size_t spd_len = sizeof(peid->spd_data[0]);
printk(BIOS_DEBUG, "SPD index %d\n", spd_index);
spd_file = cbfs_boot_map_with_leak("spd.bin", CBFS_TYPE_SPD,
&spd_file_len);
spd_file = cbfs_map("spd.bin", &spd_file_len);
if (!spd_file)
die("SPD data not found.");

View File

@@ -20,8 +20,7 @@ void copy_spd(struct pei_data *peid)
size_t spd_len = sizeof(peid->spd_data[0]);
printk(BIOS_DEBUG, "SPD index %d\n", spd_index);
spd_file = cbfs_boot_map_with_leak("spd.bin", CBFS_TYPE_SPD,
&spd_file_len);
spd_file = cbfs_map("spd.bin", &spd_file_len);
if (!spd_file)
die("SPD data not found.");

View File

@@ -24,8 +24,7 @@ void copy_spd(struct pei_data *peid)
uint32_t board_version = PEPPY_BOARD_VERSION_PROTO;
printk(BIOS_DEBUG, "SPD index %d\n", spd_index);
spd_file = cbfs_boot_map_with_leak("spd.bin", CBFS_TYPE_SPD,
&spd_file_len);
spd_file = cbfs_map("spd.bin", &spd_file_len);
if (!spd_file)
die("SPD data not found.");

View File

@@ -21,8 +21,7 @@ void copy_spd(struct pei_data *peid)
size_t spd_len = sizeof(peid->spd_data[0]);
printk(BIOS_DEBUG, "SPD index %d\n", spd_index);
spd_file = cbfs_boot_map_with_leak("spd.bin", CBFS_TYPE_SPD,
&spd_file_len);
spd_file = cbfs_map("spd.bin", &spd_file_len);
if (!spd_file)
die("SPD data not found.");

View File

@@ -39,8 +39,7 @@ void mainboard_get_spd(spd_raw_data *spd, bool id_only)
{
/* C1S0 is a soldered RAM with no real SPD. Use stored SPD. */
size_t spd_file_len = 0;
void *spd_file = cbfs_boot_map_with_leak("spd.bin", CBFS_TYPE_SPD,
&spd_file_len);
void *spd_file = cbfs_map("spd.bin", &spd_file_len);
if (!spd_file || spd_file_len < sizeof(spd_raw_data))
die("SPD data for C1S0 not found.");

View File

@@ -15,8 +15,7 @@ uint8_t *mainboard_find_spd_data()
spd_index = 0;
spd_file = cbfs_boot_map_with_leak("spd.bin", CBFS_TYPE_SPD,
&spd_file_len);
spd_file = cbfs_map("spd.bin", &spd_file_len);
if (!spd_file)
die("SPD data not found.");

View File

@@ -68,8 +68,7 @@ uintptr_t mainboard_get_spd_data(void)
printk(BIOS_INFO, "SPD index %d\n", spd_index);
/* Load SPD data from CBFS */
spd_file = cbfs_boot_map_with_leak("spd.bin", CBFS_TYPE_SPD,
&spd_file_len);
spd_file = cbfs_map("spd.bin", &spd_file_len);
if (!spd_file)
die("SPD data not found.");

View File

@@ -70,8 +70,7 @@ void mainboard_get_spd(spd_raw_data *spd, bool id_only)
spd_index, mainboard_spd_names[spd_index]);
/* C0S0 is a soldered RAM with no real SPD. Use stored SPD. */
spd_file = cbfs_boot_map_with_leak("spd.bin", CBFS_TYPE_SPD,
&spd_file_len);
spd_file = cbfs_map("spd.bin", &spd_file_len);
if (!spd_file || spd_file_len < SPD_LEN * spd_index + SPD_LEN)
die("SPD data not found.");

View File

@@ -28,8 +28,7 @@ void mainboard_get_spd(spd_raw_data *spd, bool id_only)
{
/* C1S0 is a soldered RAM with no real SPD. Use stored SPD. */
size_t spd_file_len = 0;
void *spd_file = cbfs_boot_map_with_leak("spd.bin", CBFS_TYPE_SPD,
&spd_file_len);
void *spd_file = cbfs_map("spd.bin", &spd_file_len);
if (!spd_file || spd_file_len < sizeof(spd_raw_data))
die("SPD data for C1S0 not found.");

View File

@@ -32,8 +32,7 @@ static uint8_t *get_spd_data(int spd_index)
size_t spd_file_len;
printk(BIOS_DEBUG, "spd index %d\n", spd_index);
spd_file = cbfs_boot_map_with_leak("spd.bin", CBFS_TYPE_SPD,
&spd_file_len);
spd_file = cbfs_map("spd.bin", &spd_file_len);
if (!spd_file)
die("SPD data not found.");

View File

@@ -104,8 +104,7 @@ static const uint8_t *locate_spd(void)
break;
}
spd_data = cbfs_boot_map_with_leak("spd.bin", CBFS_TYPE_SPD,
&spd_file_len);
spd_data = cbfs_map("spd.bin", &spd_file_len);
if (!spd_data)
die("SPD data not found.");
if (spd_file_len < (spd_index + 1) * 256)

View File

@@ -72,7 +72,7 @@ static void fixup_fdt(void *unused)
struct device_tree *tree;
/* load flat dt from cbfs */
fdt_rom = cbfs_boot_map_with_leak("fallback/DTB", CBFS_TYPE_RAW, NULL);
fdt_rom = cbfs_map("fallback/DTB", NULL);
if (fdt_rom == NULL) {
printk(BIOS_ERR, "Unable to load fallback/DTB from CBFS\n");