drivers/usb/acpi: Don't add GPIOs to _CRS for Intel Bluetooth
[coreboot2.git] / src / soc / amd / common / pi / refcode_loader.c
blobfb62796b1317eb3bef01b8b834dfcddc040a5b66
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <cbfs.h>
4 #include <cbmem.h>
5 #include <rmodule.h>
6 #include <stage_cache.h>
7 #include <amdblocks/agesawrapper.h>
8 #include <amdblocks/image.h>
10 static void *agesa_map_raw_file(const char *name, size_t *size)
12 enum cbfs_type type = CBFS_TYPE_RAW;
13 return cbfs_type_map(name, size, &type);
16 static void *agesa_map_stage_file_early(const char *name, size_t *size)
18 enum cbfs_type type = CBFS_TYPE_STAGE;
19 return cbfs_type_map(name, size, &type);
22 static void *agesa_map_stage_file_ramstage(const char *name, size_t *size)
24 struct prog prog = PROG_INIT(PROG_REFCODE, name);
25 struct rmod_stage_load rmod_agesa = {
26 .cbmem_id = CBMEM_ID_REFCODE,
27 .prog = &prog,
30 if (resume_from_stage_cache()) {
31 stage_cache_load_stage(STAGE_REFCODE, &prog);
32 } else {
33 if (rmodule_stage_load(&rmod_agesa) < 0)
34 return NULL;
36 stage_cache_add(STAGE_REFCODE, &prog);
39 *size = prog_size(&prog);
40 return prog_start(&prog);
43 static void *agesa_map_stage_file(const char *name, size_t *size)
45 if (!ENV_RAMSTAGE || !CONFIG(AGESA_SPLIT_MEMORY_FILES))
46 return agesa_map_stage_file_early(name, size);
47 return agesa_map_stage_file_ramstage(name, size);
50 static const char *get_agesa_cbfs_name(void)
52 if (!CONFIG(AGESA_SPLIT_MEMORY_FILES))
53 return CONFIG_AGESA_CBFS_NAME;
54 if (!ENV_RAMSTAGE)
55 return CONFIG_AGESA_PRE_MEMORY_CBFS_NAME;
56 return CONFIG_AGESA_POST_MEMORY_CBFS_NAME;
59 const void *agesawrapper_locate_module(const char name[8])
61 const void *agesa;
62 const AMD_IMAGE_HEADER *image;
63 size_t file_size;
64 const char *fname;
66 /* Assume boot device is memory mapped so the mapping can leak. */
67 assert(CONFIG(BOOT_DEVICE_MEMORY_MAPPED));
69 fname = get_agesa_cbfs_name();
71 if (CONFIG(AGESA_BINARY_PI_AS_STAGE))
72 agesa = agesa_map_stage_file(fname, &file_size);
73 else
74 agesa = agesa_map_raw_file(fname, &file_size);
76 if (!agesa)
77 return NULL;
79 image = amd_find_image(agesa, agesa + file_size, 4096, name);
81 if (!image)
82 return NULL;
84 return (AMD_MODULE_HEADER *)image->ModuleInfoOffset;
87 static MODULE_ENTRY agesa_dispatcher;
89 MODULE_ENTRY agesa_get_dispatcher(void)
91 const AMD_MODULE_HEADER *module;
92 static const char id[8] = AGESA_ID;
94 if (agesa_dispatcher != NULL)
95 return agesa_dispatcher;
97 module = agesawrapper_locate_module(id);
98 if (!module)
99 return NULL;
101 agesa_dispatcher = module->ModuleDispatcher;
102 return agesa_dispatcher;