Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: Intel |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2013, Intel Corporation |
| 4 | * Copyright (C) 2014, Bin Meng <bmeng.cn@gmail.com> |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 5 | */ |
| 6 | |
Bin Meng | 01223e3 | 2014-12-12 21:05:29 +0800 | [diff] [blame] | 7 | #include <common.h> |
Simon Glass | 6c34fc1 | 2019-09-25 08:00:11 -0600 | [diff] [blame^] | 8 | #include <asm/fsp1/fsp_support.h> |
Bin Meng | 01223e3 | 2014-12-12 21:05:29 +0800 | [diff] [blame] | 9 | #include <asm/post.h> |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 10 | |
Simon Glass | 457191e | 2015-01-27 22:13:37 -0700 | [diff] [blame] | 11 | struct fsp_header *__attribute__((optimize("O0"))) find_fsp_header(void) |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 12 | { |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 13 | /* |
| 14 | * This function may be called before the a stack is established, |
| 15 | * so special care must be taken. First, it cannot declare any local |
| 16 | * variable using stack. Only register variable can be used here. |
| 17 | * Secondly, some compiler version will add prolog or epilog code |
| 18 | * for the C function. If so the function call may not work before |
| 19 | * stack is ready. |
| 20 | * |
| 21 | * GCC 4.8.1 has been verified to be working for the following codes. |
| 22 | */ |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 23 | volatile register u8 *fsp asm("eax"); |
| 24 | |
| 25 | /* Initalize the FSP base */ |
Bin Meng | 293f497 | 2014-12-17 15:50:42 +0800 | [diff] [blame] | 26 | fsp = (u8 *)CONFIG_FSP_ADDR; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 27 | |
| 28 | /* Check the FV signature, _FVH */ |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 29 | if (((struct fv_header *)fsp)->sign == EFI_FVH_SIGNATURE) { |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 30 | /* Go to the end of the FV header and align the address */ |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 31 | fsp += ((struct fv_header *)fsp)->ext_hdr_off; |
| 32 | fsp += ((struct fv_ext_header *)fsp)->ext_hdr_size; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 33 | fsp = (u8 *)(((u32)fsp + 7) & 0xFFFFFFF8); |
| 34 | } else { |
| 35 | fsp = 0; |
| 36 | } |
| 37 | |
| 38 | /* Check the FFS GUID */ |
| 39 | if (fsp && |
Park, Aiden | 0961cf7 | 2019-08-03 08:30:20 +0000 | [diff] [blame] | 40 | ((struct ffs_file_header *)fsp)->name.b[0] == FSP_GUID_BYTE0 && |
| 41 | ((struct ffs_file_header *)fsp)->name.b[1] == FSP_GUID_BYTE1 && |
| 42 | ((struct ffs_file_header *)fsp)->name.b[2] == FSP_GUID_BYTE2 && |
| 43 | ((struct ffs_file_header *)fsp)->name.b[3] == FSP_GUID_BYTE3 && |
| 44 | ((struct ffs_file_header *)fsp)->name.b[4] == FSP_GUID_BYTE4 && |
| 45 | ((struct ffs_file_header *)fsp)->name.b[5] == FSP_GUID_BYTE5 && |
| 46 | ((struct ffs_file_header *)fsp)->name.b[6] == FSP_GUID_BYTE6 && |
| 47 | ((struct ffs_file_header *)fsp)->name.b[7] == FSP_GUID_BYTE7 && |
| 48 | ((struct ffs_file_header *)fsp)->name.b[8] == FSP_GUID_BYTE8 && |
| 49 | ((struct ffs_file_header *)fsp)->name.b[9] == FSP_GUID_BYTE9 && |
| 50 | ((struct ffs_file_header *)fsp)->name.b[10] == FSP_GUID_BYTE10 && |
| 51 | ((struct ffs_file_header *)fsp)->name.b[11] == FSP_GUID_BYTE11 && |
| 52 | ((struct ffs_file_header *)fsp)->name.b[12] == FSP_GUID_BYTE12 && |
| 53 | ((struct ffs_file_header *)fsp)->name.b[13] == FSP_GUID_BYTE13 && |
| 54 | ((struct ffs_file_header *)fsp)->name.b[14] == FSP_GUID_BYTE14 && |
| 55 | ((struct ffs_file_header *)fsp)->name.b[15] == FSP_GUID_BYTE15) { |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 56 | /* Add the FFS header size to find the raw section header */ |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 57 | fsp += sizeof(struct ffs_file_header); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 58 | } else { |
| 59 | fsp = 0; |
| 60 | } |
| 61 | |
| 62 | if (fsp && |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 63 | ((struct raw_section *)fsp)->type == EFI_SECTION_RAW) { |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 64 | /* Add the raw section header size to find the FSP header */ |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 65 | fsp += sizeof(struct raw_section); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 66 | } else { |
| 67 | fsp = 0; |
| 68 | } |
| 69 | |
Simon Glass | 457191e | 2015-01-27 22:13:37 -0700 | [diff] [blame] | 70 | return (struct fsp_header *)fsp; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 71 | } |
| 72 | |
Bin Meng | 001d5c7 | 2015-12-10 22:02:56 -0800 | [diff] [blame] | 73 | void fsp_continue(u32 status, void *hob_list) |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 74 | { |
Bin Meng | 01223e3 | 2014-12-12 21:05:29 +0800 | [diff] [blame] | 75 | post_code(POST_MRC); |
| 76 | |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 77 | assert(status == 0); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 78 | |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 79 | /* The boot loader main function entry */ |
Bin Meng | 01223e3 | 2014-12-12 21:05:29 +0800 | [diff] [blame] | 80 | fsp_init_done(hob_list); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | void fsp_init(u32 stack_top, u32 boot_mode, void *nvs_buf) |
| 84 | { |
Bin Meng | a0c94dc | 2015-12-10 22:02:59 -0800 | [diff] [blame] | 85 | struct fsp_config_data config_data; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 86 | fsp_init_f init; |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 87 | struct fsp_init_params params; |
| 88 | struct fspinit_rtbuf rt_buf; |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 89 | struct fsp_header *fsp_hdr; |
| 90 | struct fsp_init_params *params_ptr; |
Bin Meng | f9a6189 | 2015-12-10 22:03:01 -0800 | [diff] [blame] | 91 | #ifdef CONFIG_FSP_USE_UPD |
| 92 | struct vpd_region *fsp_vpd; |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 93 | struct upd_region *fsp_upd; |
Bin Meng | f9a6189 | 2015-12-10 22:03:01 -0800 | [diff] [blame] | 94 | #endif |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 95 | |
Simon Glass | 8afe6ff | 2015-01-27 22:13:40 -0700 | [diff] [blame] | 96 | fsp_hdr = find_fsp_header(); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 97 | if (fsp_hdr == NULL) { |
| 98 | /* No valid FSP info header was found */ |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 99 | panic("Invalid FSP header"); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 100 | } |
| 101 | |
Bin Meng | c24aebd | 2015-12-10 22:03:00 -0800 | [diff] [blame] | 102 | config_data.common.fsp_hdr = fsp_hdr; |
| 103 | config_data.common.stack_top = stack_top; |
| 104 | config_data.common.boot_mode = boot_mode; |
| 105 | |
Bin Meng | f9a6189 | 2015-12-10 22:03:01 -0800 | [diff] [blame] | 106 | #ifdef CONFIG_FSP_USE_UPD |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 107 | /* Get VPD region start */ |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 108 | fsp_vpd = (struct vpd_region *)(fsp_hdr->img_base + |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 109 | fsp_hdr->cfg_region_off); |
| 110 | |
Simon Glass | 8afe6ff | 2015-01-27 22:13:40 -0700 | [diff] [blame] | 111 | /* Verify the VPD data region is valid */ |
Bin Meng | c44ed64 | 2015-08-08 22:01:23 +0800 | [diff] [blame] | 112 | assert(fsp_vpd->sign == VPD_IMAGE_ID); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 113 | |
Bin Meng | f9a6189 | 2015-12-10 22:03:01 -0800 | [diff] [blame] | 114 | fsp_upd = &config_data.fsp_upd; |
| 115 | |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 116 | /* Copy default data from Flash */ |
| 117 | memcpy(fsp_upd, (void *)(fsp_hdr->img_base + fsp_vpd->upd_offset), |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 118 | sizeof(struct upd_region)); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 119 | |
Simon Glass | 8afe6ff | 2015-01-27 22:13:40 -0700 | [diff] [blame] | 120 | /* Verify the UPD data region is valid */ |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 121 | assert(fsp_upd->terminator == UPD_TERMINATOR); |
Bin Meng | f9a6189 | 2015-12-10 22:03:01 -0800 | [diff] [blame] | 122 | #endif |
| 123 | |
| 124 | memset(&rt_buf, 0, sizeof(struct fspinit_rtbuf)); |
| 125 | |
Bin Meng | c24aebd | 2015-12-10 22:03:00 -0800 | [diff] [blame] | 126 | /* Override any configuration if required */ |
Bin Meng | 4a076fe | 2015-12-10 22:03:04 -0800 | [diff] [blame] | 127 | update_fsp_configs(&config_data, &rt_buf); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 128 | |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 129 | memset(¶ms, 0, sizeof(struct fsp_init_params)); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 130 | params.nvs_buf = nvs_buf; |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 131 | params.rt_buf = (struct fspinit_rtbuf *)&rt_buf; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 132 | params.continuation = (fsp_continuation_f)asm_continuation; |
| 133 | |
| 134 | init = (fsp_init_f)(fsp_hdr->img_base + fsp_hdr->fsp_init); |
| 135 | params_ptr = ¶ms; |
| 136 | |
Bin Meng | 01223e3 | 2014-12-12 21:05:29 +0800 | [diff] [blame] | 137 | post_code(POST_PRE_MRC); |
| 138 | |
Bin Meng | a3c9fb0 | 2015-06-07 11:33:13 +0800 | [diff] [blame] | 139 | /* Load GDT for FSP */ |
| 140 | setup_fsp_gdt(); |
| 141 | |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 142 | /* |
Bin Meng | 001d5c7 | 2015-12-10 22:02:56 -0800 | [diff] [blame] | 143 | * Use ASM code to ensure the register value in EAX & EDX |
| 144 | * will be passed into fsp_continue |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 145 | */ |
| 146 | asm volatile ( |
| 147 | "pushl %0;" |
| 148 | "call *%%eax;" |
| 149 | ".global asm_continuation;" |
| 150 | "asm_continuation:;" |
Bin Meng | 001d5c7 | 2015-12-10 22:02:56 -0800 | [diff] [blame] | 151 | "movl 4(%%esp), %%eax;" /* status */ |
| 152 | "movl 8(%%esp), %%edx;" /* hob_list */ |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 153 | "jmp fsp_continue;" |
Bin Meng | 001d5c7 | 2015-12-10 22:02:56 -0800 | [diff] [blame] | 154 | : : "m"(params_ptr), "a"(init) |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 155 | ); |
| 156 | |
| 157 | /* |
| 158 | * Should never get here. |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 159 | * Control will continue from fsp_continue. |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 160 | * This line below is to prevent the compiler from optimizing |
| 161 | * structure intialization. |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 162 | * |
| 163 | * DO NOT REMOVE! |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 164 | */ |
| 165 | init(¶ms); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 166 | } |
| 167 | |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 168 | u32 fsp_notify(struct fsp_header *fsp_hdr, u32 phase) |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 169 | { |
| 170 | fsp_notify_f notify; |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 171 | struct fsp_notify_params params; |
| 172 | struct fsp_notify_params *params_ptr; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 173 | u32 status; |
| 174 | |
| 175 | if (!fsp_hdr) |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 176 | fsp_hdr = (struct fsp_header *)find_fsp_header(); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 177 | |
| 178 | if (fsp_hdr == NULL) { |
| 179 | /* No valid FSP info header */ |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 180 | panic("Invalid FSP header"); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | notify = (fsp_notify_f)(fsp_hdr->img_base + fsp_hdr->fsp_notify); |
| 184 | params.phase = phase; |
Bin Meng | 01223e3 | 2014-12-12 21:05:29 +0800 | [diff] [blame] | 185 | params_ptr = ¶ms; |
| 186 | |
| 187 | /* |
| 188 | * Use ASM code to ensure correct parameter is on the stack for |
| 189 | * FspNotify as U-Boot is using different ABI from FSP |
| 190 | */ |
| 191 | asm volatile ( |
| 192 | "pushl %1;" /* push notify phase */ |
| 193 | "call *%%eax;" /* call FspNotify */ |
| 194 | "addl $4, %%esp;" /* clean up the stack */ |
| 195 | : "=a"(status) : "m"(params_ptr), "a"(notify), "m"(*params_ptr) |
| 196 | ); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 197 | |
| 198 | return status; |
| 199 | } |
| 200 | |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 201 | u32 fsp_get_usable_lowmem_top(const void *hob_list) |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 202 | { |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 203 | const struct hob_header *hdr; |
| 204 | struct hob_res_desc *res_desc; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 205 | phys_addr_t phys_start; |
| 206 | u32 top; |
Bin Meng | 4c836c9 | 2016-02-17 00:16:23 -0800 | [diff] [blame] | 207 | #ifdef CONFIG_FSP_BROKEN_HOB |
| 208 | struct hob_mem_alloc *res_mem; |
| 209 | phys_addr_t mem_base = 0; |
| 210 | #endif |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 211 | |
| 212 | /* Get the HOB list for processing */ |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 213 | hdr = hob_list; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 214 | |
| 215 | /* * Collect memory ranges */ |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 216 | top = FSP_LOWMEM_BASE; |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 217 | while (!end_of_hob(hdr)) { |
Bin Meng | 2f848bc | 2015-01-06 14:04:36 +0800 | [diff] [blame] | 218 | if (hdr->type == HOB_TYPE_RES_DESC) { |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 219 | res_desc = (struct hob_res_desc *)hdr; |
| 220 | if (res_desc->type == RES_SYS_MEM) { |
| 221 | phys_start = res_desc->phys_start; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 222 | /* Need memory above 1MB to be collected here */ |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 223 | if (phys_start >= FSP_LOWMEM_BASE && |
| 224 | phys_start < (phys_addr_t)FSP_HIGHMEM_BASE) |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 225 | top += (u32)(res_desc->len); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 226 | } |
| 227 | } |
Bin Meng | 4c836c9 | 2016-02-17 00:16:23 -0800 | [diff] [blame] | 228 | |
| 229 | #ifdef CONFIG_FSP_BROKEN_HOB |
| 230 | /* |
| 231 | * Find out the lowest memory base address allocated by FSP |
| 232 | * for the boot service data |
| 233 | */ |
| 234 | if (hdr->type == HOB_TYPE_MEM_ALLOC) { |
| 235 | res_mem = (struct hob_mem_alloc *)hdr; |
| 236 | if (!mem_base) |
| 237 | mem_base = res_mem->mem_base; |
| 238 | if (res_mem->mem_base < mem_base) |
| 239 | mem_base = res_mem->mem_base; |
| 240 | } |
| 241 | #endif |
| 242 | |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 243 | hdr = get_next_hob(hdr); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 244 | } |
| 245 | |
Bin Meng | 4c836c9 | 2016-02-17 00:16:23 -0800 | [diff] [blame] | 246 | #ifdef CONFIG_FSP_BROKEN_HOB |
| 247 | /* |
| 248 | * Check whether the memory top address is below the FSP HOB list. |
| 249 | * If not, use the lowest memory base address allocated by FSP as |
| 250 | * the memory top address. This is to prevent U-Boot relocation |
| 251 | * overwrites the important boot service data which is used by FSP, |
| 252 | * otherwise the subsequent call to fsp_notify() will fail. |
| 253 | */ |
| 254 | if (top > (u32)hob_list) { |
| 255 | debug("Adjust memory top address due to a buggy FSP\n"); |
| 256 | top = (u32)mem_base; |
| 257 | } |
| 258 | #endif |
| 259 | |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 260 | return top; |
| 261 | } |
| 262 | |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 263 | u64 fsp_get_usable_highmem_top(const void *hob_list) |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 264 | { |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 265 | const struct hob_header *hdr; |
| 266 | struct hob_res_desc *res_desc; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 267 | phys_addr_t phys_start; |
| 268 | u64 top; |
| 269 | |
| 270 | /* Get the HOB list for processing */ |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 271 | hdr = hob_list; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 272 | |
| 273 | /* Collect memory ranges */ |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 274 | top = FSP_HIGHMEM_BASE; |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 275 | while (!end_of_hob(hdr)) { |
Bin Meng | 2f848bc | 2015-01-06 14:04:36 +0800 | [diff] [blame] | 276 | if (hdr->type == HOB_TYPE_RES_DESC) { |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 277 | res_desc = (struct hob_res_desc *)hdr; |
| 278 | if (res_desc->type == RES_SYS_MEM) { |
| 279 | phys_start = res_desc->phys_start; |
Andrew Bradford | 17194d5 | 2015-05-22 15:11:23 -0400 | [diff] [blame] | 280 | /* Need memory above 4GB to be collected here */ |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 281 | if (phys_start >= (phys_addr_t)FSP_HIGHMEM_BASE) |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 282 | top += (u32)(res_desc->len); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 283 | } |
| 284 | } |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 285 | hdr = get_next_hob(hdr); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | return top; |
| 289 | } |
| 290 | |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 291 | u64 fsp_get_reserved_mem_from_guid(const void *hob_list, u64 *len, |
Park, Aiden | 0961cf7 | 2019-08-03 08:30:20 +0000 | [diff] [blame] | 292 | const efi_guid_t *guid) |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 293 | { |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 294 | const struct hob_header *hdr; |
| 295 | struct hob_res_desc *res_desc; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 296 | |
| 297 | /* Get the HOB list for processing */ |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 298 | hdr = hob_list; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 299 | |
| 300 | /* Collect memory ranges */ |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 301 | while (!end_of_hob(hdr)) { |
Bin Meng | 2f848bc | 2015-01-06 14:04:36 +0800 | [diff] [blame] | 302 | if (hdr->type == HOB_TYPE_RES_DESC) { |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 303 | res_desc = (struct hob_res_desc *)hdr; |
| 304 | if (res_desc->type == RES_MEM_RESERVED) { |
Park, Aiden | 0961cf7 | 2019-08-03 08:30:20 +0000 | [diff] [blame] | 305 | if (!guidcmp(&res_desc->owner, guid)) { |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 306 | if (len) |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 307 | *len = (u32)(res_desc->len); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 308 | |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 309 | return (u64)(res_desc->phys_start); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 310 | } |
| 311 | } |
| 312 | } |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 313 | hdr = get_next_hob(hdr); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | return 0; |
| 317 | } |
| 318 | |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 319 | u32 fsp_get_fsp_reserved_mem(const void *hob_list, u32 *len) |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 320 | { |
Park, Aiden | 0961cf7 | 2019-08-03 08:30:20 +0000 | [diff] [blame] | 321 | const efi_guid_t guid = FSP_HOB_RESOURCE_OWNER_FSP_GUID; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 322 | u64 length; |
| 323 | u32 base; |
| 324 | |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 325 | base = (u32)fsp_get_reserved_mem_from_guid(hob_list, |
Park, Aiden | 0961cf7 | 2019-08-03 08:30:20 +0000 | [diff] [blame] | 326 | &length, &guid); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 327 | if ((len != 0) && (base != 0)) |
| 328 | *len = (u32)length; |
| 329 | |
| 330 | return base; |
| 331 | } |
| 332 | |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 333 | u32 fsp_get_tseg_reserved_mem(const void *hob_list, u32 *len) |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 334 | { |
Park, Aiden | 0961cf7 | 2019-08-03 08:30:20 +0000 | [diff] [blame] | 335 | const efi_guid_t guid = FSP_HOB_RESOURCE_OWNER_TSEG_GUID; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 336 | u64 length; |
| 337 | u32 base; |
| 338 | |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 339 | base = (u32)fsp_get_reserved_mem_from_guid(hob_list, |
Park, Aiden | 0961cf7 | 2019-08-03 08:30:20 +0000 | [diff] [blame] | 340 | &length, &guid); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 341 | if ((len != 0) && (base != 0)) |
| 342 | *len = (u32)length; |
| 343 | |
| 344 | return base; |
| 345 | } |
| 346 | |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 347 | void *fsp_get_nvs_data(const void *hob_list, u32 *len) |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 348 | { |
Park, Aiden | 0961cf7 | 2019-08-03 08:30:20 +0000 | [diff] [blame] | 349 | const efi_guid_t guid = FSP_NON_VOLATILE_STORAGE_HOB_GUID; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 350 | |
Park, Aiden | 538aec9 | 2019-08-03 08:30:31 +0000 | [diff] [blame] | 351 | return hob_get_guid_hob_data(hob_list, len, &guid); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 352 | } |
| 353 | |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 354 | void *fsp_get_bootloader_tmp_mem(const void *hob_list, u32 *len) |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 355 | { |
Park, Aiden | 0961cf7 | 2019-08-03 08:30:20 +0000 | [diff] [blame] | 356 | const efi_guid_t guid = FSP_BOOTLOADER_TEMP_MEM_HOB_GUID; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 357 | |
Park, Aiden | 538aec9 | 2019-08-03 08:30:31 +0000 | [diff] [blame] | 358 | return hob_get_guid_hob_data(hob_list, len, &guid); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 359 | } |
Bin Meng | 3c8b48a | 2017-08-15 22:41:52 -0700 | [diff] [blame] | 360 | |
| 361 | void *fsp_get_graphics_info(const void *hob_list, u32 *len) |
| 362 | { |
Park, Aiden | 0961cf7 | 2019-08-03 08:30:20 +0000 | [diff] [blame] | 363 | const efi_guid_t guid = FSP_GRAPHICS_INFO_HOB_GUID; |
Bin Meng | 3c8b48a | 2017-08-15 22:41:52 -0700 | [diff] [blame] | 364 | |
Park, Aiden | 538aec9 | 2019-08-03 08:30:31 +0000 | [diff] [blame] | 365 | return hob_get_guid_hob_data(hob_list, len, &guid); |
Bin Meng | 3c8b48a | 2017-08-15 22:41:52 -0700 | [diff] [blame] | 366 | } |