coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
refcode_loader.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <cbfs.h>
4 #include <cbmem.h>
5 #include <rmodule.h>
6 #include <stage_cache.h>
8 #include <amdblocks/image.h>
9 
10 static void *agesa_map_raw_file(const char *name, size_t *size)
11 {
13  return cbfs_type_map(name, size, &type);
14 }
15 
16 static void *agesa_map_stage_file_early(const char *name, size_t *size)
17 {
19  return cbfs_type_map(name, size, &type);
20 }
21 
22 static void *agesa_map_stage_file_ramstage(const char *name, size_t *size)
23 {
24  struct prog prog = PROG_INIT(PROG_REFCODE, name);
25  struct rmod_stage_load rmod_agesa = {
27  .prog = &prog,
28  };
29 
32  } else {
33  if (rmodule_stage_load(&rmod_agesa) < 0)
34  return NULL;
35 
37  }
38 
39  *size = prog_size(&prog);
40  return prog_start(&prog);
41 }
42 
43 static void *agesa_map_stage_file(const char *name, size_t *size)
44 {
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);
48 }
49 
50 static const char *get_agesa_cbfs_name(void)
51 {
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;
57 }
58 
59 const void *agesawrapper_locate_module(const char name[8])
60 {
61  const void *agesa;
62  const AMD_IMAGE_HEADER *image;
63  size_t file_size;
64  const char *fname;
65 
66  /* Assume boot device is memory mapped so the mapping can leak. */
67  assert(CONFIG(BOOT_DEVICE_MEMORY_MAPPED));
68 
69  fname = get_agesa_cbfs_name();
70 
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);
75 
76  if (!agesa)
77  return NULL;
78 
79  image = amd_find_image(agesa, agesa + file_size, 4096, name);
80 
81  if (!image)
82  return NULL;
83 
84  return (AMD_MODULE_HEADER *)image->ModuleInfoOffset;
85 }
86 
88 
90 {
91  const AMD_MODULE_HEADER *module;
92  static const char id[8] = AGESA_ID;
93 
94  if (agesa_dispatcher != NULL)
95  return agesa_dispatcher;
96 
97  module = agesawrapper_locate_module(id);
98  if (!module)
99  return NULL;
100 
101  agesa_dispatcher = module->ModuleDispatcher;
102  return agesa_dispatcher;
103 }
AGESA_STATUS(* MODULE_ENTRY)(IN OUT void *ConfigPtr)
Definition: Amd.h:49
const char * name
Definition: mmu.c:92
#define assert(statement)
Definition: assert.h:74
static void * cbfs_type_map(const char *name, size_t *size_out, enum cbfs_type *type)
Definition: cbfs.h:256
cbfs_type
@ CBFS_TYPE_STAGE
@ CBFS_TYPE_RAW
#define CBMEM_ID_REFCODE
Definition: cbmem_id.h:47
@ CONFIG
Definition: dsi_common.h:201
void * amd_find_image(const void *start_address, const void *end_address, uint32_t alignment, const char name[8])
Definition: image.c:28
unsigned int type
Definition: edid.c:57
#define PROG_INIT(type_, name_)
static void * prog_start(const struct prog *prog)
static size_t prog_size(const struct prog *prog)
@ PROG_REFCODE
static MODULE_ENTRY agesa_dispatcher
static void * agesa_map_stage_file_early(const char *name, size_t *size)
static void * agesa_map_stage_file(const char *name, size_t *size)
static void * agesa_map_stage_file_ramstage(const char *name, size_t *size)
static void * agesa_map_raw_file(const char *name, size_t *size)
static const char * get_agesa_cbfs_name(void)
MODULE_ENTRY agesa_get_dispatcher(void)
const void * agesawrapper_locate_module(const char name[8])
int rmodule_stage_load(struct rmod_stage_load *rsl)
Definition: rmodule.c:249
#define ENV_RAMSTAGE
Definition: rules.h:150
@ STAGE_REFCODE
Definition: stage_cache.h:14
static void stage_cache_load_stage(int stage_id, struct prog *stage)
Definition: stage_cache.h:36
static int resume_from_stage_cache(void)
Definition: stage_cache.h:42
static void stage_cache_add(int stage_id, const struct prog *stage)
Definition: stage_cache.h:35
#define NULL
Definition: stddef.h:19
AGESA Binary module header structure.
Definition: Amd.h:87
IN unsigned int ModuleInfoOffset
Offset of module.
Definition: Amd.h:91
AGESA Binary module header structure.
Definition: Amd.h:102
struct prog * prog
Definition: rmodule.h:44
uint32_t cbmem_id
Definition: rmodule.h:43