fsp2_0: Replace fspld->get_destination() callback with CBFS allocator
The Intel FSP 2.0 driver contains a custom construct that basically
serves the same purpose as the new CBFS allocator concept: a callback
function to customize placement of a loaded CBFS file whose size is
initially unknown. This patch removes the existing implementation and
replaces it with a CBFS allocator.
Signed-off-by: Julius Werner <jwerner@chromium.org>
Change-Id: I0b7b446a0d2af87ec337fb80ad54f2d404e69668
Reviewed-on: https://review.coreboot.org/c/coreboot/+/52082
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Reviewed-by: Furquan Shaikh <furquan@google.com>
diff --git a/src/drivers/intel/fsp2_0/memory_init.c b/src/drivers/intel/fsp2_0/memory_init.c
index 0ea5c08..bbc26bc 100644
--- a/src/drivers/intel/fsp2_0/memory_init.c
+++ b/src/drivers/intel/fsp2_0/memory_init.c
@@ -339,40 +339,20 @@
fsp_debug_after_memory_init(status);
}
-static int fspm_get_dest(const struct fsp_load_descriptor *fspld, void **dest,
- size_t size, const struct region_device *source)
+static void *fspm_allocator(void *arg, size_t size, const union cbfs_mdata *unused)
{
+ const struct fsp_load_descriptor *fspld = arg;
struct fspm_context *context = fspld->arg;
- struct fsp_header *hdr = &context->header;
struct memranges *memmap = &context->memmap;
- uintptr_t fspm_begin;
- uintptr_t fspm_end;
-
- if (CONFIG(FSP_M_XIP)) {
- if (fsp_validate_component(hdr, source) != CB_SUCCESS)
- return -1;
-
- *dest = rdev_mmap_full(source);
- if ((uintptr_t)*dest != hdr->image_base) {
- printk(BIOS_CRIT, "FSPM XIP base does not match: %p vs %p\n",
- (void *)(uintptr_t)hdr->image_base, *dest);
- return -1;
- }
- /* Since the component is XIP it's already in the address space.
- Thus, there's no need to rdev_munmap(). */
- return 0;
- }
/* Non XIP FSP-M uses FSP-M address */
- fspm_begin = (uintptr_t)CONFIG_FSP_M_ADDR;
- fspm_end = fspm_begin + size;
+ uintptr_t fspm_begin = (uintptr_t)CONFIG_FSP_M_ADDR;
+ uintptr_t fspm_end = fspm_begin + size;
if (check_region_overlap(memmap, "FSPM", fspm_begin, fspm_end) != CB_SUCCESS)
- return -1;
+ return NULL;
- *dest = (void *)fspm_begin;
-
- return 0;
+ return (void *)fspm_begin;
}
void fsp_memory_init(bool s3wake)
@@ -381,12 +361,15 @@
struct fspm_context context;
struct fsp_load_descriptor fspld = {
.fsp_prog = PROG_INIT(PROG_REFCODE, CONFIG_FSP_M_CBFS),
- .get_destination = fspm_get_dest,
.arg = &context,
};
struct fsp_header *hdr = &context.header;
struct memranges *memmap = &context.memmap;
+ /* For FSP-M XIP we leave alloc NULL to get a direct mapping to flash. */
+ if (!CONFIG(FSP_M_XIP))
+ fspld.alloc = fspm_allocator;
+
elog_boot_notify(s3wake);
/* Build up memory map of romstage address space including CAR. */
@@ -399,6 +382,10 @@
if (fsp_load_component(&fspld, hdr) != CB_SUCCESS)
die("FSPM not available or failed to load!\n");
+ if (CONFIG(FSP_M_XIP) && (uintptr_t)prog_start(&fspld.fsp_prog) != hdr->image_base)
+ die("FSPM XIP base does not match: %p vs %p\n",
+ (void *)(uintptr_t)hdr->image_base, prog_start(&fspld.fsp_prog));
+
timestamp_add_now(TS_BEFORE_INITRAM);
do_fsp_memory_init(&context, s3wake);