Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 1 | /* |
| 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 Meng | 01223e3 | 2014-12-12 21:05:29 +0800 | [diff] [blame] | 8 | #include <common.h> |
Simon Glass | b93abfc | 2015-01-27 22:13:36 -0700 | [diff] [blame] | 9 | #include <asm/fsp/fsp_support.h> |
Bin Meng | 01223e3 | 2014-12-12 21:05:29 +0800 | [diff] [blame] | 10 | #include <asm/post.h> |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 11 | |
| 12 | /** |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 13 | * Compares two GUIDs |
| 14 | * |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 15 | * 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 Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 17 | * |
| 18 | * @guid1: A pointer to a 128 bit GUID. |
| 19 | * @guid2: A pointer to a 128 bit GUID. |
| 20 | * |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 21 | * @retval true: guid1 and guid2 are identical. |
| 22 | * @retval false: guid1 and guid2 are not identical. |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 23 | */ |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 24 | static bool compare_guid(const struct efi_guid *guid1, |
| 25 | const struct efi_guid *guid2) |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 26 | { |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 27 | if (memcmp(guid1, guid2, sizeof(struct efi_guid)) == 0) |
| 28 | return true; |
| 29 | else |
| 30 | return false; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 31 | } |
| 32 | |
Simon Glass | 457191e | 2015-01-27 22:13:37 -0700 | [diff] [blame] | 33 | struct fsp_header *__attribute__((optimize("O0"))) find_fsp_header(void) |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 34 | { |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 35 | /* |
| 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 Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 45 | volatile register u8 *fsp asm("eax"); |
| 46 | |
| 47 | /* Initalize the FSP base */ |
Bin Meng | 293f497 | 2014-12-17 15:50:42 +0800 | [diff] [blame] | 48 | fsp = (u8 *)CONFIG_FSP_ADDR; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 49 | |
| 50 | /* Check the FV signature, _FVH */ |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 51 | if (((struct fv_header *)fsp)->sign == EFI_FVH_SIGNATURE) { |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 52 | /* Go to the end of the FV header and align the address */ |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 53 | fsp += ((struct fv_header *)fsp)->ext_hdr_off; |
| 54 | fsp += ((struct fv_ext_header *)fsp)->ext_hdr_size; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 55 | fsp = (u8 *)(((u32)fsp + 7) & 0xFFFFFFF8); |
| 56 | } else { |
| 57 | fsp = 0; |
| 58 | } |
| 59 | |
| 60 | /* Check the FFS GUID */ |
| 61 | if (fsp && |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 62 | ((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 Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 73 | /* Add the FFS header size to find the raw section header */ |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 74 | fsp += sizeof(struct ffs_file_header); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 75 | } else { |
| 76 | fsp = 0; |
| 77 | } |
| 78 | |
| 79 | if (fsp && |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 80 | ((struct raw_section *)fsp)->type == EFI_SECTION_RAW) { |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 81 | /* Add the raw section header size to find the FSP header */ |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 82 | fsp += sizeof(struct raw_section); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 83 | } else { |
| 84 | fsp = 0; |
| 85 | } |
| 86 | |
Simon Glass | 457191e | 2015-01-27 22:13:37 -0700 | [diff] [blame] | 87 | return (struct fsp_header *)fsp; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 88 | } |
| 89 | |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 90 | void fsp_continue(struct shared_data *shared_data, u32 status, void *hob_list) |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 91 | { |
| 92 | u32 stack_len; |
| 93 | u32 stack_base; |
| 94 | u32 stack_top; |
| 95 | |
Bin Meng | 01223e3 | 2014-12-12 21:05:29 +0800 | [diff] [blame] | 96 | post_code(POST_MRC); |
| 97 | |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 98 | assert(status == 0); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 99 | |
| 100 | /* Get the migrated stack in normal memory */ |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 101 | stack_base = (u32)fsp_get_bootloader_tmp_mem(hob_list, &stack_len); |
| 102 | assert(stack_base != 0); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 103 | stack_top = stack_base + stack_len - sizeof(u32); |
| 104 | |
| 105 | /* |
| 106 | * Old stack base is stored at the very end of the stack top, |
| 107 | * use it to calculate the migrated shared data base |
| 108 | */ |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 109 | shared_data = (struct shared_data *)(stack_base + |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 110 | ((u32)shared_data - *(u32 *)stack_top)); |
| 111 | |
| 112 | /* The boot loader main function entry */ |
Bin Meng | 01223e3 | 2014-12-12 21:05:29 +0800 | [diff] [blame] | 113 | fsp_init_done(hob_list); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | void fsp_init(u32 stack_top, u32 boot_mode, void *nvs_buf) |
| 117 | { |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 118 | struct shared_data shared_data; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 119 | fsp_init_f init; |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 120 | struct fsp_init_params params; |
| 121 | struct fspinit_rtbuf rt_buf; |
| 122 | struct vpd_region *fsp_vpd; |
| 123 | struct fsp_header *fsp_hdr; |
| 124 | struct fsp_init_params *params_ptr; |
| 125 | struct upd_region *fsp_upd; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 126 | |
Simon Glass | 4661c2c | 2015-01-27 22:13:42 -0700 | [diff] [blame] | 127 | #ifdef CONFIG_DEBUG_UART |
| 128 | setup_early_uart(); |
| 129 | #endif |
| 130 | |
Simon Glass | 8afe6ff | 2015-01-27 22:13:40 -0700 | [diff] [blame] | 131 | fsp_hdr = find_fsp_header(); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 132 | if (fsp_hdr == NULL) { |
| 133 | /* No valid FSP info header was found */ |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 134 | panic("Invalid FSP header"); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 135 | } |
| 136 | |
Simon Glass | 8afe6ff | 2015-01-27 22:13:40 -0700 | [diff] [blame] | 137 | fsp_upd = &shared_data.fsp_upd; |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 138 | memset(&rt_buf, 0, sizeof(struct fspinit_rtbuf)); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 139 | |
| 140 | /* Reserve a gap in stack top */ |
| 141 | rt_buf.common.stack_top = (u32 *)stack_top - 32; |
| 142 | rt_buf.common.boot_mode = boot_mode; |
Simon Glass | 8afe6ff | 2015-01-27 22:13:40 -0700 | [diff] [blame] | 143 | rt_buf.common.upd_data = fsp_upd; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 144 | |
| 145 | /* Get VPD region start */ |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 146 | fsp_vpd = (struct vpd_region *)(fsp_hdr->img_base + |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 147 | fsp_hdr->cfg_region_off); |
| 148 | |
Simon Glass | 8afe6ff | 2015-01-27 22:13:40 -0700 | [diff] [blame] | 149 | /* Verify the VPD data region is valid */ |
Bin Meng | c44ed64 | 2015-08-08 22:01:23 +0800 | [diff] [blame^] | 150 | assert(fsp_vpd->sign == VPD_IMAGE_ID); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 151 | |
| 152 | /* Copy default data from Flash */ |
| 153 | memcpy(fsp_upd, (void *)(fsp_hdr->img_base + fsp_vpd->upd_offset), |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 154 | sizeof(struct upd_region)); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 155 | |
Simon Glass | 8afe6ff | 2015-01-27 22:13:40 -0700 | [diff] [blame] | 156 | /* Verify the UPD data region is valid */ |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 157 | assert(fsp_upd->terminator == UPD_TERMINATOR); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 158 | |
| 159 | /* Override any UPD setting if required */ |
| 160 | update_fsp_upd(fsp_upd); |
| 161 | |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 162 | memset(¶ms, 0, sizeof(struct fsp_init_params)); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 163 | params.nvs_buf = nvs_buf; |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 164 | params.rt_buf = (struct fspinit_rtbuf *)&rt_buf; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 165 | params.continuation = (fsp_continuation_f)asm_continuation; |
| 166 | |
| 167 | init = (fsp_init_f)(fsp_hdr->img_base + fsp_hdr->fsp_init); |
| 168 | params_ptr = ¶ms; |
| 169 | |
| 170 | shared_data.fsp_hdr = fsp_hdr; |
| 171 | shared_data.stack_top = (u32 *)stack_top; |
| 172 | |
Bin Meng | 01223e3 | 2014-12-12 21:05:29 +0800 | [diff] [blame] | 173 | post_code(POST_PRE_MRC); |
| 174 | |
Bin Meng | a3c9fb0 | 2015-06-07 11:33:13 +0800 | [diff] [blame] | 175 | /* Load GDT for FSP */ |
| 176 | setup_fsp_gdt(); |
| 177 | |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 178 | /* |
| 179 | * Use ASM code to ensure the register value in EAX & ECX |
| 180 | * will be passed into BlContinuationFunc |
| 181 | */ |
| 182 | asm volatile ( |
| 183 | "pushl %0;" |
| 184 | "call *%%eax;" |
| 185 | ".global asm_continuation;" |
| 186 | "asm_continuation:;" |
Bin Meng | 01223e3 | 2014-12-12 21:05:29 +0800 | [diff] [blame] | 187 | "movl %%ebx, %%eax;" /* shared_data */ |
| 188 | "movl 4(%%esp), %%edx;" /* status */ |
| 189 | "movl 8(%%esp), %%ecx;" /* hob_list */ |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 190 | "jmp fsp_continue;" |
Bin Meng | 01223e3 | 2014-12-12 21:05:29 +0800 | [diff] [blame] | 191 | : : "m"(params_ptr), "a"(init), "b"(&shared_data) |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 192 | ); |
| 193 | |
| 194 | /* |
| 195 | * Should never get here. |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 196 | * Control will continue from fsp_continue. |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 197 | * This line below is to prevent the compiler from optimizing |
| 198 | * structure intialization. |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 199 | * |
| 200 | * DO NOT REMOVE! |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 201 | */ |
| 202 | init(¶ms); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 203 | } |
| 204 | |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 205 | u32 fsp_notify(struct fsp_header *fsp_hdr, u32 phase) |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 206 | { |
| 207 | fsp_notify_f notify; |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 208 | struct fsp_notify_params params; |
| 209 | struct fsp_notify_params *params_ptr; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 210 | u32 status; |
| 211 | |
| 212 | if (!fsp_hdr) |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 213 | fsp_hdr = (struct fsp_header *)find_fsp_header(); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 214 | |
| 215 | if (fsp_hdr == NULL) { |
| 216 | /* No valid FSP info header */ |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 217 | panic("Invalid FSP header"); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | notify = (fsp_notify_f)(fsp_hdr->img_base + fsp_hdr->fsp_notify); |
| 221 | params.phase = phase; |
Bin Meng | 01223e3 | 2014-12-12 21:05:29 +0800 | [diff] [blame] | 222 | params_ptr = ¶ms; |
| 223 | |
| 224 | /* |
| 225 | * Use ASM code to ensure correct parameter is on the stack for |
| 226 | * FspNotify as U-Boot is using different ABI from FSP |
| 227 | */ |
| 228 | asm volatile ( |
| 229 | "pushl %1;" /* push notify phase */ |
| 230 | "call *%%eax;" /* call FspNotify */ |
| 231 | "addl $4, %%esp;" /* clean up the stack */ |
| 232 | : "=a"(status) : "m"(params_ptr), "a"(notify), "m"(*params_ptr) |
| 233 | ); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 234 | |
| 235 | return status; |
| 236 | } |
| 237 | |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 238 | u32 fsp_get_usable_lowmem_top(const void *hob_list) |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 239 | { |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 240 | const struct hob_header *hdr; |
| 241 | struct hob_res_desc *res_desc; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 242 | phys_addr_t phys_start; |
| 243 | u32 top; |
| 244 | |
| 245 | /* Get the HOB list for processing */ |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 246 | hdr = hob_list; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 247 | |
| 248 | /* * Collect memory ranges */ |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 249 | top = FSP_LOWMEM_BASE; |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 250 | while (!end_of_hob(hdr)) { |
Bin Meng | 2f848bc | 2015-01-06 14:04:36 +0800 | [diff] [blame] | 251 | if (hdr->type == HOB_TYPE_RES_DESC) { |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 252 | res_desc = (struct hob_res_desc *)hdr; |
| 253 | if (res_desc->type == RES_SYS_MEM) { |
| 254 | phys_start = res_desc->phys_start; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 255 | /* Need memory above 1MB to be collected here */ |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 256 | if (phys_start >= FSP_LOWMEM_BASE && |
| 257 | phys_start < (phys_addr_t)FSP_HIGHMEM_BASE) |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 258 | top += (u32)(res_desc->len); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 259 | } |
| 260 | } |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 261 | hdr = get_next_hob(hdr); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | return top; |
| 265 | } |
| 266 | |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 267 | u64 fsp_get_usable_highmem_top(const void *hob_list) |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 268 | { |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 269 | const struct hob_header *hdr; |
| 270 | struct hob_res_desc *res_desc; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 271 | phys_addr_t phys_start; |
| 272 | u64 top; |
| 273 | |
| 274 | /* Get the HOB list for processing */ |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 275 | hdr = hob_list; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 276 | |
| 277 | /* Collect memory ranges */ |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 278 | top = FSP_HIGHMEM_BASE; |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 279 | while (!end_of_hob(hdr)) { |
Bin Meng | 2f848bc | 2015-01-06 14:04:36 +0800 | [diff] [blame] | 280 | if (hdr->type == HOB_TYPE_RES_DESC) { |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 281 | res_desc = (struct hob_res_desc *)hdr; |
| 282 | if (res_desc->type == RES_SYS_MEM) { |
| 283 | phys_start = res_desc->phys_start; |
Andrew Bradford | 17194d5 | 2015-05-22 15:11:23 -0400 | [diff] [blame] | 284 | /* Need memory above 4GB to be collected here */ |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 285 | if (phys_start >= (phys_addr_t)FSP_HIGHMEM_BASE) |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 286 | top += (u32)(res_desc->len); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 287 | } |
| 288 | } |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 289 | hdr = get_next_hob(hdr); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | return top; |
| 293 | } |
| 294 | |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 295 | u64 fsp_get_reserved_mem_from_guid(const void *hob_list, u64 *len, |
| 296 | struct efi_guid *guid) |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 297 | { |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 298 | const struct hob_header *hdr; |
| 299 | struct hob_res_desc *res_desc; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 300 | |
| 301 | /* Get the HOB list for processing */ |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 302 | hdr = hob_list; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 303 | |
| 304 | /* Collect memory ranges */ |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 305 | while (!end_of_hob(hdr)) { |
Bin Meng | 2f848bc | 2015-01-06 14:04:36 +0800 | [diff] [blame] | 306 | if (hdr->type == HOB_TYPE_RES_DESC) { |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 307 | res_desc = (struct hob_res_desc *)hdr; |
| 308 | if (res_desc->type == RES_MEM_RESERVED) { |
| 309 | if (compare_guid(&res_desc->owner, guid)) { |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 310 | if (len) |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 311 | *len = (u32)(res_desc->len); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 312 | |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 313 | return (u64)(res_desc->phys_start); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 314 | } |
| 315 | } |
| 316 | } |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 317 | hdr = get_next_hob(hdr); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | return 0; |
| 321 | } |
| 322 | |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 323 | u32 fsp_get_fsp_reserved_mem(const void *hob_list, u32 *len) |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 324 | { |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 325 | const struct efi_guid guid = FSP_HOB_RESOURCE_OWNER_FSP_GUID; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 326 | u64 length; |
| 327 | u32 base; |
| 328 | |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 329 | base = (u32)fsp_get_reserved_mem_from_guid(hob_list, |
| 330 | &length, (struct efi_guid *)&guid); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 331 | if ((len != 0) && (base != 0)) |
| 332 | *len = (u32)length; |
| 333 | |
| 334 | return base; |
| 335 | } |
| 336 | |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 337 | u32 fsp_get_tseg_reserved_mem(const void *hob_list, u32 *len) |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 338 | { |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 339 | const struct efi_guid guid = FSP_HOB_RESOURCE_OWNER_TSEG_GUID; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 340 | u64 length; |
| 341 | u32 base; |
| 342 | |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 343 | base = (u32)fsp_get_reserved_mem_from_guid(hob_list, |
| 344 | &length, (struct efi_guid *)&guid); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 345 | if ((len != 0) && (base != 0)) |
| 346 | *len = (u32)length; |
| 347 | |
| 348 | return base; |
| 349 | } |
| 350 | |
Bin Meng | 2f848bc | 2015-01-06 14:04:36 +0800 | [diff] [blame] | 351 | const struct hob_header *fsp_get_next_hob(uint type, const void *hob_list) |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 352 | { |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 353 | const struct hob_header *hdr; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 354 | |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 355 | hdr = hob_list; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 356 | |
| 357 | /* Parse the HOB list until end of list or matching type is found */ |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 358 | while (!end_of_hob(hdr)) { |
Bin Meng | 2f848bc | 2015-01-06 14:04:36 +0800 | [diff] [blame] | 359 | if (hdr->type == type) |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 360 | return hdr; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 361 | |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 362 | hdr = get_next_hob(hdr); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | return NULL; |
| 366 | } |
| 367 | |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 368 | const struct hob_header *fsp_get_next_guid_hob(const struct efi_guid *guid, |
| 369 | const void *hob_list) |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 370 | { |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 371 | const struct hob_header *hdr; |
| 372 | struct hob_guid *guid_hob; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 373 | |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 374 | hdr = hob_list; |
| 375 | while ((hdr = fsp_get_next_hob(HOB_TYPE_GUID_EXT, |
| 376 | hdr)) != NULL) { |
| 377 | guid_hob = (struct hob_guid *)hdr; |
| 378 | if (compare_guid(guid, &(guid_hob->name))) |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 379 | break; |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 380 | hdr = get_next_hob(hdr); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 381 | } |
| 382 | |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 383 | return hdr; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 384 | } |
| 385 | |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 386 | void *fsp_get_guid_hob_data(const void *hob_list, u32 *len, |
| 387 | struct efi_guid *guid) |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 388 | { |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 389 | const struct hob_header *guid_hob; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 390 | |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 391 | guid_hob = fsp_get_next_guid_hob(guid, hob_list); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 392 | if (guid_hob == NULL) { |
| 393 | return NULL; |
| 394 | } else { |
| 395 | if (len) |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 396 | *len = get_guid_hob_data_size(guid_hob); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 397 | |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 398 | return get_guid_hob_data(guid_hob); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 399 | } |
| 400 | } |
| 401 | |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 402 | void *fsp_get_nvs_data(const void *hob_list, u32 *len) |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 403 | { |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 404 | const struct efi_guid guid = FSP_NON_VOLATILE_STORAGE_HOB_GUID; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 405 | |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 406 | return fsp_get_guid_hob_data(hob_list, len, (struct efi_guid *)&guid); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 407 | } |
| 408 | |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 409 | void *fsp_get_bootloader_tmp_mem(const void *hob_list, u32 *len) |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 410 | { |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 411 | const struct efi_guid guid = FSP_BOOTLOADER_TEMP_MEM_HOB_GUID; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 412 | |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 413 | return fsp_get_guid_hob_data(hob_list, len, (struct efi_guid *)&guid); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 414 | } |