amd: refcode_loader: Switch to new CBFS API

This patch rewrites some parts of the Agesa refcode loader to eliminate
the passing of raw rdevs between functions, so that we can get rid of
cbfs_boot_locate() in favor of more high-level APIs.

Signed-off-by: Julius Werner <jwerner@chromium.org>
Change-Id: I2a6e1158ed7425c69c214462bc52e8694a69997a
Reviewed-on: https://review.coreboot.org/c/coreboot/+/50349
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
This commit is contained in:
Julius Werner 2021-02-05 17:04:04 -08:00 committed by Patrick Georgi
parent 77639e4537
commit 806deb6661
1 changed files with 19 additions and 42 deletions

View File

@ -9,32 +9,19 @@
#include <amdblocks/agesawrapper.h> #include <amdblocks/agesawrapper.h>
#include <amdblocks/image.h> #include <amdblocks/image.h>
static int agesa_locate_file(const char *name, struct region_device *rdev, static void *agesa_map_raw_file(const char *name, size_t *size)
uint32_t type)
{ {
struct cbfsf fh; enum cbfs_type type = CBFS_TYPE_RAW;
return cbfs_type_map(name, size, &type);
if (cbfs_boot_locate(&fh, name, &type))
return -1;
cbfs_file_data(rdev, &fh);
return 0;
} }
static int agesa_locate_raw_file(const char *name, struct region_device *rdev) static void *agesa_map_stage_file_early(const char *name, size_t *size)
{ {
return agesa_locate_file(name, rdev, CBFS_TYPE_RAW); enum cbfs_type type = CBFS_TYPE_STAGE;
return cbfs_type_map(name, size, &type);
} }
static int agesa_locate_stage_file_early(const char *name, static void *agesa_map_stage_file_ramstage(const char *name, size_t *size)
struct region_device *rdev)
{
if (agesa_locate_file(name, rdev, CBFS_TYPE_STAGE))
return -1;
}
static int agesa_locate_stage_file_ramstage(const char *name,
struct region_device *rdev)
{ {
struct prog prog = PROG_INIT(PROG_REFCODE, name); struct prog prog = PROG_INIT(PROG_REFCODE, name);
struct rmod_stage_load rmod_agesa = { struct rmod_stage_load rmod_agesa = {
@ -46,21 +33,20 @@ static int agesa_locate_stage_file_ramstage(const char *name,
stage_cache_load_stage(STAGE_REFCODE, &prog); stage_cache_load_stage(STAGE_REFCODE, &prog);
} else { } else {
if (rmodule_stage_load(&rmod_agesa) < 0) if (rmodule_stage_load(&rmod_agesa) < 0)
return -1; return NULL;
stage_cache_add(STAGE_REFCODE, &prog); stage_cache_add(STAGE_REFCODE, &prog);
} }
prog_chain_rdev(&prog, rdev); *size = prog_size(&prog);
return prog_start(&prog);
return 0;
} }
static int agesa_locate_stage_file(const char *name, struct region_device *rdev) static void *agesa_map_stage_file(const char *name, size_t *size)
{ {
if (!ENV_RAMSTAGE || !CONFIG(AGESA_SPLIT_MEMORY_FILES)) if (!ENV_RAMSTAGE || !CONFIG(AGESA_SPLIT_MEMORY_FILES))
return agesa_locate_stage_file_early(name, rdev); return agesa_map_stage_file_early(name, size);
return agesa_locate_stage_file_ramstage(name, rdev); return agesa_map_stage_file_ramstage(name, size);
} }
static const char *get_agesa_cbfs_name(void) static const char *get_agesa_cbfs_name(void)
@ -76,27 +62,18 @@ const void *agesawrapper_locate_module(const char name[8])
{ {
const void *agesa; const void *agesa;
const AMD_IMAGE_HEADER *image; const AMD_IMAGE_HEADER *image;
struct region_device rdev;
size_t file_size; size_t file_size;
const char *fname; const char *fname;
int ret;
fname = get_agesa_cbfs_name();
if (CONFIG(AGESA_BINARY_PI_AS_STAGE))
ret = agesa_locate_stage_file(fname, &rdev);
else
ret = agesa_locate_raw_file(fname, &rdev);
if (ret)
return NULL;
file_size = region_device_sz(&rdev);
/* Assume boot device is memory mapped so the mapping can leak. */ /* Assume boot device is memory mapped so the mapping can leak. */
assert(CONFIG(BOOT_DEVICE_MEMORY_MAPPED)); assert(CONFIG(BOOT_DEVICE_MEMORY_MAPPED));
agesa = rdev_mmap_full(&rdev); fname = get_agesa_cbfs_name();
if (CONFIG(AGESA_BINARY_PI_AS_STAGE))
agesa = agesa_map_stage_file(fname, &file_size);
else
agesa = agesa_map_raw_file(fname, &file_size);
if (!agesa) if (!agesa)
return NULL; return NULL;