blob: e0c49be6357b7663dc348b5bc3f236326eed39b8 [file] [log] [blame]
Bin Meng2922b3e2014-12-12 21:05:28 +08001/*
2 * Copyright (C) 2013, Intel Corporation
3 * Copyright (C) 2014, Bin Meng <bmeng.cn@gmail.com>
4 *
5 * SPDX-License-Identifier: Intel
6 */
7
Bin Meng01223e32014-12-12 21:05:29 +08008#include <common.h>
Simon Glassb93abfc2015-01-27 22:13:36 -07009#include <asm/fsp/fsp_support.h>
Bin Meng01223e32014-12-12 21:05:29 +080010#include <asm/post.h>
Bin Meng2922b3e2014-12-12 21:05:28 +080011
12/**
Bin Meng2922b3e2014-12-12 21:05:28 +080013 * Compares two GUIDs
14 *
Bin Mengdb60d862014-12-17 15:50:49 +080015 * If the GUIDs are identical then true is returned.
16 * If there are any bit differences in the two GUIDs, then false is returned.
Bin Meng2922b3e2014-12-12 21:05:28 +080017 *
18 * @guid1: A pointer to a 128 bit GUID.
19 * @guid2: A pointer to a 128 bit GUID.
20 *
Bin Mengdb60d862014-12-17 15:50:49 +080021 * @retval true: guid1 and guid2 are identical.
22 * @retval false: guid1 and guid2 are not identical.
Bin Meng2922b3e2014-12-12 21:05:28 +080023 */
Bin Mengdb60d862014-12-17 15:50:49 +080024static bool compare_guid(const struct efi_guid *guid1,
25 const struct efi_guid *guid2)
Bin Meng2922b3e2014-12-12 21:05:28 +080026{
Bin Mengdb60d862014-12-17 15:50:49 +080027 if (memcmp(guid1, guid2, sizeof(struct efi_guid)) == 0)
28 return true;
29 else
30 return false;
Bin Meng2922b3e2014-12-12 21:05:28 +080031}
32
Simon Glass457191e2015-01-27 22:13:37 -070033struct fsp_header *__attribute__((optimize("O0"))) find_fsp_header(void)
Bin Meng2922b3e2014-12-12 21:05:28 +080034{
Bin Mengdb60d862014-12-17 15:50:49 +080035 /*
36 * This function may be called before the a stack is established,
37 * so special care must be taken. First, it cannot declare any local
38 * variable using stack. Only register variable can be used here.
39 * Secondly, some compiler version will add prolog or epilog code
40 * for the C function. If so the function call may not work before
41 * stack is ready.
42 *
43 * GCC 4.8.1 has been verified to be working for the following codes.
44 */
Bin Meng2922b3e2014-12-12 21:05:28 +080045 volatile register u8 *fsp asm("eax");
46
47 /* Initalize the FSP base */
Bin Meng293f4972014-12-17 15:50:42 +080048 fsp = (u8 *)CONFIG_FSP_ADDR;
Bin Meng2922b3e2014-12-12 21:05:28 +080049
50 /* Check the FV signature, _FVH */
Bin Mengdb60d862014-12-17 15:50:49 +080051 if (((struct fv_header *)fsp)->sign == EFI_FVH_SIGNATURE) {
Bin Meng2922b3e2014-12-12 21:05:28 +080052 /* Go to the end of the FV header and align the address */
Bin Mengdb60d862014-12-17 15:50:49 +080053 fsp += ((struct fv_header *)fsp)->ext_hdr_off;
54 fsp += ((struct fv_ext_header *)fsp)->ext_hdr_size;
Bin Meng2922b3e2014-12-12 21:05:28 +080055 fsp = (u8 *)(((u32)fsp + 7) & 0xFFFFFFF8);
56 } else {
57 fsp = 0;
58 }
59
60 /* Check the FFS GUID */
61 if (fsp &&
Bin Mengdb60d862014-12-17 15:50:49 +080062 ((struct ffs_file_header *)fsp)->name.data1 == FSP_GUID_DATA1 &&
63 ((struct ffs_file_header *)fsp)->name.data2 == FSP_GUID_DATA2 &&
64 ((struct ffs_file_header *)fsp)->name.data3 == FSP_GUID_DATA3 &&
65 ((struct ffs_file_header *)fsp)->name.data4[0] == FSP_GUID_DATA4_0 &&
66 ((struct ffs_file_header *)fsp)->name.data4[1] == FSP_GUID_DATA4_1 &&
67 ((struct ffs_file_header *)fsp)->name.data4[2] == FSP_GUID_DATA4_2 &&
68 ((struct ffs_file_header *)fsp)->name.data4[3] == FSP_GUID_DATA4_3 &&
69 ((struct ffs_file_header *)fsp)->name.data4[4] == FSP_GUID_DATA4_4 &&
70 ((struct ffs_file_header *)fsp)->name.data4[5] == FSP_GUID_DATA4_5 &&
71 ((struct ffs_file_header *)fsp)->name.data4[6] == FSP_GUID_DATA4_6 &&
72 ((struct ffs_file_header *)fsp)->name.data4[7] == FSP_GUID_DATA4_7) {
Bin Meng2922b3e2014-12-12 21:05:28 +080073 /* Add the FFS header size to find the raw section header */
Bin Mengdb60d862014-12-17 15:50:49 +080074 fsp += sizeof(struct ffs_file_header);
Bin Meng2922b3e2014-12-12 21:05:28 +080075 } else {
76 fsp = 0;
77 }
78
79 if (fsp &&
Bin Mengdb60d862014-12-17 15:50:49 +080080 ((struct raw_section *)fsp)->type == EFI_SECTION_RAW) {
Bin Meng2922b3e2014-12-12 21:05:28 +080081 /* Add the raw section header size to find the FSP header */
Bin Mengdb60d862014-12-17 15:50:49 +080082 fsp += sizeof(struct raw_section);
Bin Meng2922b3e2014-12-12 21:05:28 +080083 } else {
84 fsp = 0;
85 }
86
Simon Glass457191e2015-01-27 22:13:37 -070087 return (struct fsp_header *)fsp;
Bin Meng2922b3e2014-12-12 21:05:28 +080088}
89
Bin Meng001d5c72015-12-10 22:02:56 -080090void fsp_continue(u32 status, void *hob_list)
Bin Meng2922b3e2014-12-12 21:05:28 +080091{
Bin Meng01223e32014-12-12 21:05:29 +080092 post_code(POST_MRC);
93
Bin Mengdb60d862014-12-17 15:50:49 +080094 assert(status == 0);
Bin Meng2922b3e2014-12-12 21:05:28 +080095
Bin Meng2922b3e2014-12-12 21:05:28 +080096 /* The boot loader main function entry */
Bin Meng01223e32014-12-12 21:05:29 +080097 fsp_init_done(hob_list);
Bin Meng2922b3e2014-12-12 21:05:28 +080098}
99
100void fsp_init(u32 stack_top, u32 boot_mode, void *nvs_buf)
101{
Bin Menga0c94dc2015-12-10 22:02:59 -0800102 struct fsp_config_data config_data;
Bin Meng2922b3e2014-12-12 21:05:28 +0800103 fsp_init_f init;
Bin Mengdb60d862014-12-17 15:50:49 +0800104 struct fsp_init_params params;
105 struct fspinit_rtbuf rt_buf;
Bin Mengdb60d862014-12-17 15:50:49 +0800106 struct fsp_header *fsp_hdr;
107 struct fsp_init_params *params_ptr;
Bin Mengf9a61892015-12-10 22:03:01 -0800108#ifdef CONFIG_FSP_USE_UPD
109 struct vpd_region *fsp_vpd;
Bin Mengdb60d862014-12-17 15:50:49 +0800110 struct upd_region *fsp_upd;
Bin Mengf9a61892015-12-10 22:03:01 -0800111#endif
Bin Meng2922b3e2014-12-12 21:05:28 +0800112
Simon Glass8afe6ff2015-01-27 22:13:40 -0700113 fsp_hdr = find_fsp_header();
Bin Meng2922b3e2014-12-12 21:05:28 +0800114 if (fsp_hdr == NULL) {
115 /* No valid FSP info header was found */
Bin Mengdb60d862014-12-17 15:50:49 +0800116 panic("Invalid FSP header");
Bin Meng2922b3e2014-12-12 21:05:28 +0800117 }
118
Bin Mengc24aebd2015-12-10 22:03:00 -0800119 config_data.common.fsp_hdr = fsp_hdr;
120 config_data.common.stack_top = stack_top;
121 config_data.common.boot_mode = boot_mode;
122
Bin Mengf9a61892015-12-10 22:03:01 -0800123#ifdef CONFIG_FSP_USE_UPD
Bin Meng2922b3e2014-12-12 21:05:28 +0800124 /* Get VPD region start */
Bin Mengdb60d862014-12-17 15:50:49 +0800125 fsp_vpd = (struct vpd_region *)(fsp_hdr->img_base +
Bin Meng2922b3e2014-12-12 21:05:28 +0800126 fsp_hdr->cfg_region_off);
127
Simon Glass8afe6ff2015-01-27 22:13:40 -0700128 /* Verify the VPD data region is valid */
Bin Mengc44ed642015-08-08 22:01:23 +0800129 assert(fsp_vpd->sign == VPD_IMAGE_ID);
Bin Meng2922b3e2014-12-12 21:05:28 +0800130
Bin Mengf9a61892015-12-10 22:03:01 -0800131 fsp_upd = &config_data.fsp_upd;
132
Bin Meng2922b3e2014-12-12 21:05:28 +0800133 /* Copy default data from Flash */
134 memcpy(fsp_upd, (void *)(fsp_hdr->img_base + fsp_vpd->upd_offset),
Bin Mengdb60d862014-12-17 15:50:49 +0800135 sizeof(struct upd_region));
Bin Meng2922b3e2014-12-12 21:05:28 +0800136
Simon Glass8afe6ff2015-01-27 22:13:40 -0700137 /* Verify the UPD data region is valid */
Bin Mengdb60d862014-12-17 15:50:49 +0800138 assert(fsp_upd->terminator == UPD_TERMINATOR);
Bin Mengf9a61892015-12-10 22:03:01 -0800139#endif
140
141 memset(&rt_buf, 0, sizeof(struct fspinit_rtbuf));
142
Bin Mengc24aebd2015-12-10 22:03:00 -0800143 /* Override any configuration if required */
Bin Meng4a076fe2015-12-10 22:03:04 -0800144 update_fsp_configs(&config_data, &rt_buf);
Bin Meng2922b3e2014-12-12 21:05:28 +0800145
Bin Mengdb60d862014-12-17 15:50:49 +0800146 memset(&params, 0, sizeof(struct fsp_init_params));
Bin Meng2922b3e2014-12-12 21:05:28 +0800147 params.nvs_buf = nvs_buf;
Bin Mengdb60d862014-12-17 15:50:49 +0800148 params.rt_buf = (struct fspinit_rtbuf *)&rt_buf;
Bin Meng2922b3e2014-12-12 21:05:28 +0800149 params.continuation = (fsp_continuation_f)asm_continuation;
150
151 init = (fsp_init_f)(fsp_hdr->img_base + fsp_hdr->fsp_init);
152 params_ptr = &params;
153
Bin Meng01223e32014-12-12 21:05:29 +0800154 post_code(POST_PRE_MRC);
155
Bin Menga3c9fb02015-06-07 11:33:13 +0800156 /* Load GDT for FSP */
157 setup_fsp_gdt();
158
Bin Meng2922b3e2014-12-12 21:05:28 +0800159 /*
Bin Meng001d5c72015-12-10 22:02:56 -0800160 * Use ASM code to ensure the register value in EAX & EDX
161 * will be passed into fsp_continue
Bin Meng2922b3e2014-12-12 21:05:28 +0800162 */
163 asm volatile (
164 "pushl %0;"
165 "call *%%eax;"
166 ".global asm_continuation;"
167 "asm_continuation:;"
Bin Meng001d5c72015-12-10 22:02:56 -0800168 "movl 4(%%esp), %%eax;" /* status */
169 "movl 8(%%esp), %%edx;" /* hob_list */
Bin Meng2922b3e2014-12-12 21:05:28 +0800170 "jmp fsp_continue;"
Bin Meng001d5c72015-12-10 22:02:56 -0800171 : : "m"(params_ptr), "a"(init)
Bin Meng2922b3e2014-12-12 21:05:28 +0800172 );
173
174 /*
175 * Should never get here.
Bin Mengdb60d862014-12-17 15:50:49 +0800176 * Control will continue from fsp_continue.
Bin Meng2922b3e2014-12-12 21:05:28 +0800177 * This line below is to prevent the compiler from optimizing
178 * structure intialization.
Bin Mengdb60d862014-12-17 15:50:49 +0800179 *
180 * DO NOT REMOVE!
Bin Meng2922b3e2014-12-12 21:05:28 +0800181 */
182 init(&params);
Bin Meng2922b3e2014-12-12 21:05:28 +0800183}
184
Bin Mengdb60d862014-12-17 15:50:49 +0800185u32 fsp_notify(struct fsp_header *fsp_hdr, u32 phase)
Bin Meng2922b3e2014-12-12 21:05:28 +0800186{
187 fsp_notify_f notify;
Bin Mengdb60d862014-12-17 15:50:49 +0800188 struct fsp_notify_params params;
189 struct fsp_notify_params *params_ptr;
Bin Meng2922b3e2014-12-12 21:05:28 +0800190 u32 status;
191
192 if (!fsp_hdr)
Bin Mengdb60d862014-12-17 15:50:49 +0800193 fsp_hdr = (struct fsp_header *)find_fsp_header();
Bin Meng2922b3e2014-12-12 21:05:28 +0800194
195 if (fsp_hdr == NULL) {
196 /* No valid FSP info header */
Bin Mengdb60d862014-12-17 15:50:49 +0800197 panic("Invalid FSP header");
Bin Meng2922b3e2014-12-12 21:05:28 +0800198 }
199
200 notify = (fsp_notify_f)(fsp_hdr->img_base + fsp_hdr->fsp_notify);
201 params.phase = phase;
Bin Meng01223e32014-12-12 21:05:29 +0800202 params_ptr = &params;
203
204 /*
205 * Use ASM code to ensure correct parameter is on the stack for
206 * FspNotify as U-Boot is using different ABI from FSP
207 */
208 asm volatile (
209 "pushl %1;" /* push notify phase */
210 "call *%%eax;" /* call FspNotify */
211 "addl $4, %%esp;" /* clean up the stack */
212 : "=a"(status) : "m"(params_ptr), "a"(notify), "m"(*params_ptr)
213 );
Bin Meng2922b3e2014-12-12 21:05:28 +0800214
215 return status;
216}
217
Bin Mengdb60d862014-12-17 15:50:49 +0800218u32 fsp_get_usable_lowmem_top(const void *hob_list)
Bin Meng2922b3e2014-12-12 21:05:28 +0800219{
Bin Meng2b215982014-12-30 16:02:05 +0800220 const struct hob_header *hdr;
221 struct hob_res_desc *res_desc;
Bin Meng2922b3e2014-12-12 21:05:28 +0800222 phys_addr_t phys_start;
223 u32 top;
Bin Meng4c836c92016-02-17 00:16:23 -0800224#ifdef CONFIG_FSP_BROKEN_HOB
225 struct hob_mem_alloc *res_mem;
226 phys_addr_t mem_base = 0;
227#endif
Bin Meng2922b3e2014-12-12 21:05:28 +0800228
229 /* Get the HOB list for processing */
Bin Meng2b215982014-12-30 16:02:05 +0800230 hdr = hob_list;
Bin Meng2922b3e2014-12-12 21:05:28 +0800231
232 /* * Collect memory ranges */
Bin Mengdb60d862014-12-17 15:50:49 +0800233 top = FSP_LOWMEM_BASE;
Bin Meng2b215982014-12-30 16:02:05 +0800234 while (!end_of_hob(hdr)) {
Bin Meng2f848bc2015-01-06 14:04:36 +0800235 if (hdr->type == HOB_TYPE_RES_DESC) {
Bin Meng2b215982014-12-30 16:02:05 +0800236 res_desc = (struct hob_res_desc *)hdr;
237 if (res_desc->type == RES_SYS_MEM) {
238 phys_start = res_desc->phys_start;
Bin Meng2922b3e2014-12-12 21:05:28 +0800239 /* Need memory above 1MB to be collected here */
Bin Mengdb60d862014-12-17 15:50:49 +0800240 if (phys_start >= FSP_LOWMEM_BASE &&
241 phys_start < (phys_addr_t)FSP_HIGHMEM_BASE)
Bin Meng2b215982014-12-30 16:02:05 +0800242 top += (u32)(res_desc->len);
Bin Meng2922b3e2014-12-12 21:05:28 +0800243 }
244 }
Bin Meng4c836c92016-02-17 00:16:23 -0800245
246#ifdef CONFIG_FSP_BROKEN_HOB
247 /*
248 * Find out the lowest memory base address allocated by FSP
249 * for the boot service data
250 */
251 if (hdr->type == HOB_TYPE_MEM_ALLOC) {
252 res_mem = (struct hob_mem_alloc *)hdr;
253 if (!mem_base)
254 mem_base = res_mem->mem_base;
255 if (res_mem->mem_base < mem_base)
256 mem_base = res_mem->mem_base;
257 }
258#endif
259
Bin Meng2b215982014-12-30 16:02:05 +0800260 hdr = get_next_hob(hdr);
Bin Meng2922b3e2014-12-12 21:05:28 +0800261 }
262
Bin Meng4c836c92016-02-17 00:16:23 -0800263#ifdef CONFIG_FSP_BROKEN_HOB
264 /*
265 * Check whether the memory top address is below the FSP HOB list.
266 * If not, use the lowest memory base address allocated by FSP as
267 * the memory top address. This is to prevent U-Boot relocation
268 * overwrites the important boot service data which is used by FSP,
269 * otherwise the subsequent call to fsp_notify() will fail.
270 */
271 if (top > (u32)hob_list) {
272 debug("Adjust memory top address due to a buggy FSP\n");
273 top = (u32)mem_base;
274 }
275#endif
276
Bin Meng2922b3e2014-12-12 21:05:28 +0800277 return top;
278}
279
Bin Mengdb60d862014-12-17 15:50:49 +0800280u64 fsp_get_usable_highmem_top(const void *hob_list)
Bin Meng2922b3e2014-12-12 21:05:28 +0800281{
Bin Meng2b215982014-12-30 16:02:05 +0800282 const struct hob_header *hdr;
283 struct hob_res_desc *res_desc;
Bin Meng2922b3e2014-12-12 21:05:28 +0800284 phys_addr_t phys_start;
285 u64 top;
286
287 /* Get the HOB list for processing */
Bin Meng2b215982014-12-30 16:02:05 +0800288 hdr = hob_list;
Bin Meng2922b3e2014-12-12 21:05:28 +0800289
290 /* Collect memory ranges */
Bin Mengdb60d862014-12-17 15:50:49 +0800291 top = FSP_HIGHMEM_BASE;
Bin Meng2b215982014-12-30 16:02:05 +0800292 while (!end_of_hob(hdr)) {
Bin Meng2f848bc2015-01-06 14:04:36 +0800293 if (hdr->type == HOB_TYPE_RES_DESC) {
Bin Meng2b215982014-12-30 16:02:05 +0800294 res_desc = (struct hob_res_desc *)hdr;
295 if (res_desc->type == RES_SYS_MEM) {
296 phys_start = res_desc->phys_start;
Andrew Bradford17194d52015-05-22 15:11:23 -0400297 /* Need memory above 4GB to be collected here */
Bin Mengdb60d862014-12-17 15:50:49 +0800298 if (phys_start >= (phys_addr_t)FSP_HIGHMEM_BASE)
Bin Meng2b215982014-12-30 16:02:05 +0800299 top += (u32)(res_desc->len);
Bin Meng2922b3e2014-12-12 21:05:28 +0800300 }
301 }
Bin Meng2b215982014-12-30 16:02:05 +0800302 hdr = get_next_hob(hdr);
Bin Meng2922b3e2014-12-12 21:05:28 +0800303 }
304
305 return top;
306}
307
Bin Mengdb60d862014-12-17 15:50:49 +0800308u64 fsp_get_reserved_mem_from_guid(const void *hob_list, u64 *len,
309 struct efi_guid *guid)
Bin Meng2922b3e2014-12-12 21:05:28 +0800310{
Bin Meng2b215982014-12-30 16:02:05 +0800311 const struct hob_header *hdr;
312 struct hob_res_desc *res_desc;
Bin Meng2922b3e2014-12-12 21:05:28 +0800313
314 /* Get the HOB list for processing */
Bin Meng2b215982014-12-30 16:02:05 +0800315 hdr = hob_list;
Bin Meng2922b3e2014-12-12 21:05:28 +0800316
317 /* Collect memory ranges */
Bin Meng2b215982014-12-30 16:02:05 +0800318 while (!end_of_hob(hdr)) {
Bin Meng2f848bc2015-01-06 14:04:36 +0800319 if (hdr->type == HOB_TYPE_RES_DESC) {
Bin Meng2b215982014-12-30 16:02:05 +0800320 res_desc = (struct hob_res_desc *)hdr;
321 if (res_desc->type == RES_MEM_RESERVED) {
322 if (compare_guid(&res_desc->owner, guid)) {
Bin Meng2922b3e2014-12-12 21:05:28 +0800323 if (len)
Bin Meng2b215982014-12-30 16:02:05 +0800324 *len = (u32)(res_desc->len);
Bin Meng2922b3e2014-12-12 21:05:28 +0800325
Bin Meng2b215982014-12-30 16:02:05 +0800326 return (u64)(res_desc->phys_start);
Bin Meng2922b3e2014-12-12 21:05:28 +0800327 }
328 }
329 }
Bin Meng2b215982014-12-30 16:02:05 +0800330 hdr = get_next_hob(hdr);
Bin Meng2922b3e2014-12-12 21:05:28 +0800331 }
332
333 return 0;
334}
335
Bin Mengdb60d862014-12-17 15:50:49 +0800336u32 fsp_get_fsp_reserved_mem(const void *hob_list, u32 *len)
Bin Meng2922b3e2014-12-12 21:05:28 +0800337{
Bin Mengdb60d862014-12-17 15:50:49 +0800338 const struct efi_guid guid = FSP_HOB_RESOURCE_OWNER_FSP_GUID;
Bin Meng2922b3e2014-12-12 21:05:28 +0800339 u64 length;
340 u32 base;
341
Bin Mengdb60d862014-12-17 15:50:49 +0800342 base = (u32)fsp_get_reserved_mem_from_guid(hob_list,
343 &length, (struct efi_guid *)&guid);
Bin Meng2922b3e2014-12-12 21:05:28 +0800344 if ((len != 0) && (base != 0))
345 *len = (u32)length;
346
347 return base;
348}
349
Bin Mengdb60d862014-12-17 15:50:49 +0800350u32 fsp_get_tseg_reserved_mem(const void *hob_list, u32 *len)
Bin Meng2922b3e2014-12-12 21:05:28 +0800351{
Bin Mengdb60d862014-12-17 15:50:49 +0800352 const struct efi_guid guid = FSP_HOB_RESOURCE_OWNER_TSEG_GUID;
Bin Meng2922b3e2014-12-12 21:05:28 +0800353 u64 length;
354 u32 base;
355
Bin Mengdb60d862014-12-17 15:50:49 +0800356 base = (u32)fsp_get_reserved_mem_from_guid(hob_list,
357 &length, (struct efi_guid *)&guid);
Bin Meng2922b3e2014-12-12 21:05:28 +0800358 if ((len != 0) && (base != 0))
359 *len = (u32)length;
360
361 return base;
362}
363
Bin Meng2f848bc2015-01-06 14:04:36 +0800364const struct hob_header *fsp_get_next_hob(uint type, const void *hob_list)
Bin Meng2922b3e2014-12-12 21:05:28 +0800365{
Bin Meng2b215982014-12-30 16:02:05 +0800366 const struct hob_header *hdr;
Bin Meng2922b3e2014-12-12 21:05:28 +0800367
Bin Meng2b215982014-12-30 16:02:05 +0800368 hdr = hob_list;
Bin Meng2922b3e2014-12-12 21:05:28 +0800369
370 /* Parse the HOB list until end of list or matching type is found */
Bin Meng2b215982014-12-30 16:02:05 +0800371 while (!end_of_hob(hdr)) {
Bin Meng2f848bc2015-01-06 14:04:36 +0800372 if (hdr->type == type)
Bin Meng2b215982014-12-30 16:02:05 +0800373 return hdr;
Bin Meng2922b3e2014-12-12 21:05:28 +0800374
Bin Meng2b215982014-12-30 16:02:05 +0800375 hdr = get_next_hob(hdr);
Bin Meng2922b3e2014-12-12 21:05:28 +0800376 }
377
378 return NULL;
379}
380
Bin Meng2b215982014-12-30 16:02:05 +0800381const struct hob_header *fsp_get_next_guid_hob(const struct efi_guid *guid,
382 const void *hob_list)
Bin Meng2922b3e2014-12-12 21:05:28 +0800383{
Bin Meng2b215982014-12-30 16:02:05 +0800384 const struct hob_header *hdr;
385 struct hob_guid *guid_hob;
Bin Meng2922b3e2014-12-12 21:05:28 +0800386
Bin Meng2b215982014-12-30 16:02:05 +0800387 hdr = hob_list;
388 while ((hdr = fsp_get_next_hob(HOB_TYPE_GUID_EXT,
389 hdr)) != NULL) {
390 guid_hob = (struct hob_guid *)hdr;
391 if (compare_guid(guid, &(guid_hob->name)))
Bin Meng2922b3e2014-12-12 21:05:28 +0800392 break;
Bin Meng2b215982014-12-30 16:02:05 +0800393 hdr = get_next_hob(hdr);
Bin Meng2922b3e2014-12-12 21:05:28 +0800394 }
395
Bin Meng2b215982014-12-30 16:02:05 +0800396 return hdr;
Bin Meng2922b3e2014-12-12 21:05:28 +0800397}
398
Bin Mengdb60d862014-12-17 15:50:49 +0800399void *fsp_get_guid_hob_data(const void *hob_list, u32 *len,
400 struct efi_guid *guid)
Bin Meng2922b3e2014-12-12 21:05:28 +0800401{
Bin Meng2b215982014-12-30 16:02:05 +0800402 const struct hob_header *guid_hob;
Bin Meng2922b3e2014-12-12 21:05:28 +0800403
Bin Mengdb60d862014-12-17 15:50:49 +0800404 guid_hob = fsp_get_next_guid_hob(guid, hob_list);
Bin Meng2922b3e2014-12-12 21:05:28 +0800405 if (guid_hob == NULL) {
406 return NULL;
407 } else {
408 if (len)
Bin Mengdb60d862014-12-17 15:50:49 +0800409 *len = get_guid_hob_data_size(guid_hob);
Bin Meng2922b3e2014-12-12 21:05:28 +0800410
Bin Mengdb60d862014-12-17 15:50:49 +0800411 return get_guid_hob_data(guid_hob);
Bin Meng2922b3e2014-12-12 21:05:28 +0800412 }
413}
414
Bin Mengdb60d862014-12-17 15:50:49 +0800415void *fsp_get_nvs_data(const void *hob_list, u32 *len)
Bin Meng2922b3e2014-12-12 21:05:28 +0800416{
Bin Mengdb60d862014-12-17 15:50:49 +0800417 const struct efi_guid guid = FSP_NON_VOLATILE_STORAGE_HOB_GUID;
Bin Meng2922b3e2014-12-12 21:05:28 +0800418
Bin Mengdb60d862014-12-17 15:50:49 +0800419 return fsp_get_guid_hob_data(hob_list, len, (struct efi_guid *)&guid);
Bin Meng2922b3e2014-12-12 21:05:28 +0800420}
421
Bin Mengdb60d862014-12-17 15:50:49 +0800422void *fsp_get_bootloader_tmp_mem(const void *hob_list, u32 *len)
Bin Meng2922b3e2014-12-12 21:05:28 +0800423{
Bin Mengdb60d862014-12-17 15:50:49 +0800424 const struct efi_guid guid = FSP_BOOTLOADER_TEMP_MEM_HOB_GUID;
Bin Meng2922b3e2014-12-12 21:05:28 +0800425
Bin Mengdb60d862014-12-17 15:50:49 +0800426 return fsp_get_guid_hob_data(hob_list, len, (struct efi_guid *)&guid);
Bin Meng2922b3e2014-12-12 21:05:28 +0800427}
Bin Meng3c8b48a2017-08-15 22:41:52 -0700428
429void *fsp_get_graphics_info(const void *hob_list, u32 *len)
430{
431 const struct efi_guid guid = FSP_GRAPHICS_INFO_HOB_GUID;
432
433 return fsp_get_guid_hob_data(hob_list, len, (struct efi_guid *)&guid);
434}