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 | 001d5c7 | 2015-12-10 22:02:56 -0800 | [diff] [blame] | 90 | void fsp_continue(u32 status, void *hob_list) |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 91 | { |
Bin Meng | 01223e3 | 2014-12-12 21:05:29 +0800 | [diff] [blame] | 92 | post_code(POST_MRC); |
| 93 | |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 94 | assert(status == 0); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 95 | |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 96 | /* The boot loader main function entry */ |
Bin Meng | 01223e3 | 2014-12-12 21:05:29 +0800 | [diff] [blame] | 97 | fsp_init_done(hob_list); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | void fsp_init(u32 stack_top, u32 boot_mode, void *nvs_buf) |
| 101 | { |
Bin Meng | a0c94dc | 2015-12-10 22:02:59 -0800 | [diff] [blame] | 102 | struct fsp_config_data config_data; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 103 | fsp_init_f init; |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 104 | struct fsp_init_params params; |
| 105 | struct fspinit_rtbuf rt_buf; |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 106 | struct fsp_header *fsp_hdr; |
| 107 | struct fsp_init_params *params_ptr; |
Bin Meng | f9a6189 | 2015-12-10 22:03:01 -0800 | [diff] [blame] | 108 | #ifdef CONFIG_FSP_USE_UPD |
| 109 | struct vpd_region *fsp_vpd; |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 110 | struct upd_region *fsp_upd; |
Bin Meng | f9a6189 | 2015-12-10 22:03:01 -0800 | [diff] [blame] | 111 | #endif |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 112 | |
Simon Glass | 4661c2c | 2015-01-27 22:13:42 -0700 | [diff] [blame] | 113 | #ifdef CONFIG_DEBUG_UART |
Stefan Roese | a377b7c | 2016-01-19 14:24:12 +0100 | [diff] [blame] | 114 | setup_internal_uart(1); |
Simon Glass | 4661c2c | 2015-01-27 22:13:42 -0700 | [diff] [blame] | 115 | #endif |
| 116 | |
Simon Glass | 8afe6ff | 2015-01-27 22:13:40 -0700 | [diff] [blame] | 117 | fsp_hdr = find_fsp_header(); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 118 | if (fsp_hdr == NULL) { |
| 119 | /* No valid FSP info header was found */ |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 120 | panic("Invalid FSP header"); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 121 | } |
| 122 | |
Bin Meng | c24aebd | 2015-12-10 22:03:00 -0800 | [diff] [blame] | 123 | config_data.common.fsp_hdr = fsp_hdr; |
| 124 | config_data.common.stack_top = stack_top; |
| 125 | config_data.common.boot_mode = boot_mode; |
| 126 | |
Bin Meng | f9a6189 | 2015-12-10 22:03:01 -0800 | [diff] [blame] | 127 | #ifdef CONFIG_FSP_USE_UPD |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 128 | /* Get VPD region start */ |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 129 | fsp_vpd = (struct vpd_region *)(fsp_hdr->img_base + |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 130 | fsp_hdr->cfg_region_off); |
| 131 | |
Simon Glass | 8afe6ff | 2015-01-27 22:13:40 -0700 | [diff] [blame] | 132 | /* Verify the VPD data region is valid */ |
Bin Meng | c44ed64 | 2015-08-08 22:01:23 +0800 | [diff] [blame] | 133 | assert(fsp_vpd->sign == VPD_IMAGE_ID); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 134 | |
Bin Meng | f9a6189 | 2015-12-10 22:03:01 -0800 | [diff] [blame] | 135 | fsp_upd = &config_data.fsp_upd; |
| 136 | |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 137 | /* Copy default data from Flash */ |
| 138 | memcpy(fsp_upd, (void *)(fsp_hdr->img_base + fsp_vpd->upd_offset), |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 139 | sizeof(struct upd_region)); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 140 | |
Simon Glass | 8afe6ff | 2015-01-27 22:13:40 -0700 | [diff] [blame] | 141 | /* Verify the UPD data region is valid */ |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 142 | assert(fsp_upd->terminator == UPD_TERMINATOR); |
Bin Meng | f9a6189 | 2015-12-10 22:03:01 -0800 | [diff] [blame] | 143 | #endif |
| 144 | |
| 145 | memset(&rt_buf, 0, sizeof(struct fspinit_rtbuf)); |
| 146 | |
Bin Meng | c24aebd | 2015-12-10 22:03:00 -0800 | [diff] [blame] | 147 | /* Override any configuration if required */ |
Bin Meng | 4a076fe | 2015-12-10 22:03:04 -0800 | [diff] [blame] | 148 | update_fsp_configs(&config_data, &rt_buf); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 149 | |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 150 | memset(¶ms, 0, sizeof(struct fsp_init_params)); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 151 | params.nvs_buf = nvs_buf; |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 152 | params.rt_buf = (struct fspinit_rtbuf *)&rt_buf; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 153 | params.continuation = (fsp_continuation_f)asm_continuation; |
| 154 | |
| 155 | init = (fsp_init_f)(fsp_hdr->img_base + fsp_hdr->fsp_init); |
| 156 | params_ptr = ¶ms; |
| 157 | |
Bin Meng | 01223e3 | 2014-12-12 21:05:29 +0800 | [diff] [blame] | 158 | post_code(POST_PRE_MRC); |
| 159 | |
Bin Meng | a3c9fb0 | 2015-06-07 11:33:13 +0800 | [diff] [blame] | 160 | /* Load GDT for FSP */ |
| 161 | setup_fsp_gdt(); |
| 162 | |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 163 | /* |
Bin Meng | 001d5c7 | 2015-12-10 22:02:56 -0800 | [diff] [blame] | 164 | * Use ASM code to ensure the register value in EAX & EDX |
| 165 | * will be passed into fsp_continue |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 166 | */ |
| 167 | asm volatile ( |
| 168 | "pushl %0;" |
| 169 | "call *%%eax;" |
| 170 | ".global asm_continuation;" |
| 171 | "asm_continuation:;" |
Bin Meng | 001d5c7 | 2015-12-10 22:02:56 -0800 | [diff] [blame] | 172 | "movl 4(%%esp), %%eax;" /* status */ |
| 173 | "movl 8(%%esp), %%edx;" /* hob_list */ |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 174 | "jmp fsp_continue;" |
Bin Meng | 001d5c7 | 2015-12-10 22:02:56 -0800 | [diff] [blame] | 175 | : : "m"(params_ptr), "a"(init) |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 176 | ); |
| 177 | |
| 178 | /* |
| 179 | * Should never get here. |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 180 | * Control will continue from fsp_continue. |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 181 | * This line below is to prevent the compiler from optimizing |
| 182 | * structure intialization. |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 183 | * |
| 184 | * DO NOT REMOVE! |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 185 | */ |
| 186 | init(¶ms); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 187 | } |
| 188 | |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 189 | u32 fsp_notify(struct fsp_header *fsp_hdr, u32 phase) |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 190 | { |
| 191 | fsp_notify_f notify; |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 192 | struct fsp_notify_params params; |
| 193 | struct fsp_notify_params *params_ptr; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 194 | u32 status; |
| 195 | |
| 196 | if (!fsp_hdr) |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 197 | fsp_hdr = (struct fsp_header *)find_fsp_header(); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 198 | |
| 199 | if (fsp_hdr == NULL) { |
| 200 | /* No valid FSP info header */ |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 201 | panic("Invalid FSP header"); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | notify = (fsp_notify_f)(fsp_hdr->img_base + fsp_hdr->fsp_notify); |
| 205 | params.phase = phase; |
Bin Meng | 01223e3 | 2014-12-12 21:05:29 +0800 | [diff] [blame] | 206 | params_ptr = ¶ms; |
| 207 | |
| 208 | /* |
| 209 | * Use ASM code to ensure correct parameter is on the stack for |
| 210 | * FspNotify as U-Boot is using different ABI from FSP |
| 211 | */ |
| 212 | asm volatile ( |
| 213 | "pushl %1;" /* push notify phase */ |
| 214 | "call *%%eax;" /* call FspNotify */ |
| 215 | "addl $4, %%esp;" /* clean up the stack */ |
| 216 | : "=a"(status) : "m"(params_ptr), "a"(notify), "m"(*params_ptr) |
| 217 | ); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 218 | |
| 219 | return status; |
| 220 | } |
| 221 | |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 222 | u32 fsp_get_usable_lowmem_top(const void *hob_list) |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 223 | { |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 224 | const struct hob_header *hdr; |
| 225 | struct hob_res_desc *res_desc; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 226 | phys_addr_t phys_start; |
| 227 | u32 top; |
Bin Meng | 4c836c9 | 2016-02-17 00:16:23 -0800 | [diff] [blame^] | 228 | #ifdef CONFIG_FSP_BROKEN_HOB |
| 229 | struct hob_mem_alloc *res_mem; |
| 230 | phys_addr_t mem_base = 0; |
| 231 | #endif |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 232 | |
| 233 | /* Get the HOB list for processing */ |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 234 | hdr = hob_list; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 235 | |
| 236 | /* * Collect memory ranges */ |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 237 | top = FSP_LOWMEM_BASE; |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 238 | while (!end_of_hob(hdr)) { |
Bin Meng | 2f848bc | 2015-01-06 14:04:36 +0800 | [diff] [blame] | 239 | if (hdr->type == HOB_TYPE_RES_DESC) { |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 240 | res_desc = (struct hob_res_desc *)hdr; |
| 241 | if (res_desc->type == RES_SYS_MEM) { |
| 242 | phys_start = res_desc->phys_start; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 243 | /* Need memory above 1MB to be collected here */ |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 244 | if (phys_start >= FSP_LOWMEM_BASE && |
| 245 | phys_start < (phys_addr_t)FSP_HIGHMEM_BASE) |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 246 | top += (u32)(res_desc->len); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 247 | } |
| 248 | } |
Bin Meng | 4c836c9 | 2016-02-17 00:16:23 -0800 | [diff] [blame^] | 249 | |
| 250 | #ifdef CONFIG_FSP_BROKEN_HOB |
| 251 | /* |
| 252 | * Find out the lowest memory base address allocated by FSP |
| 253 | * for the boot service data |
| 254 | */ |
| 255 | if (hdr->type == HOB_TYPE_MEM_ALLOC) { |
| 256 | res_mem = (struct hob_mem_alloc *)hdr; |
| 257 | if (!mem_base) |
| 258 | mem_base = res_mem->mem_base; |
| 259 | if (res_mem->mem_base < mem_base) |
| 260 | mem_base = res_mem->mem_base; |
| 261 | } |
| 262 | #endif |
| 263 | |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 264 | hdr = get_next_hob(hdr); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 265 | } |
| 266 | |
Bin Meng | 4c836c9 | 2016-02-17 00:16:23 -0800 | [diff] [blame^] | 267 | #ifdef CONFIG_FSP_BROKEN_HOB |
| 268 | /* |
| 269 | * Check whether the memory top address is below the FSP HOB list. |
| 270 | * If not, use the lowest memory base address allocated by FSP as |
| 271 | * the memory top address. This is to prevent U-Boot relocation |
| 272 | * overwrites the important boot service data which is used by FSP, |
| 273 | * otherwise the subsequent call to fsp_notify() will fail. |
| 274 | */ |
| 275 | if (top > (u32)hob_list) { |
| 276 | debug("Adjust memory top address due to a buggy FSP\n"); |
| 277 | top = (u32)mem_base; |
| 278 | } |
| 279 | #endif |
| 280 | |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 281 | return top; |
| 282 | } |
| 283 | |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 284 | u64 fsp_get_usable_highmem_top(const void *hob_list) |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 285 | { |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 286 | const struct hob_header *hdr; |
| 287 | struct hob_res_desc *res_desc; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 288 | phys_addr_t phys_start; |
| 289 | u64 top; |
| 290 | |
| 291 | /* Get the HOB list for processing */ |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 292 | hdr = hob_list; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 293 | |
| 294 | /* Collect memory ranges */ |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 295 | top = FSP_HIGHMEM_BASE; |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 296 | while (!end_of_hob(hdr)) { |
Bin Meng | 2f848bc | 2015-01-06 14:04:36 +0800 | [diff] [blame] | 297 | if (hdr->type == HOB_TYPE_RES_DESC) { |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 298 | res_desc = (struct hob_res_desc *)hdr; |
| 299 | if (res_desc->type == RES_SYS_MEM) { |
| 300 | phys_start = res_desc->phys_start; |
Andrew Bradford | 17194d5 | 2015-05-22 15:11:23 -0400 | [diff] [blame] | 301 | /* Need memory above 4GB to be collected here */ |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 302 | if (phys_start >= (phys_addr_t)FSP_HIGHMEM_BASE) |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 303 | top += (u32)(res_desc->len); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 304 | } |
| 305 | } |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 306 | hdr = get_next_hob(hdr); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | return top; |
| 310 | } |
| 311 | |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 312 | u64 fsp_get_reserved_mem_from_guid(const void *hob_list, u64 *len, |
| 313 | struct efi_guid *guid) |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 314 | { |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 315 | const struct hob_header *hdr; |
| 316 | struct hob_res_desc *res_desc; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 317 | |
| 318 | /* Get the HOB list for processing */ |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 319 | hdr = hob_list; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 320 | |
| 321 | /* Collect memory ranges */ |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 322 | while (!end_of_hob(hdr)) { |
Bin Meng | 2f848bc | 2015-01-06 14:04:36 +0800 | [diff] [blame] | 323 | if (hdr->type == HOB_TYPE_RES_DESC) { |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 324 | res_desc = (struct hob_res_desc *)hdr; |
| 325 | if (res_desc->type == RES_MEM_RESERVED) { |
| 326 | if (compare_guid(&res_desc->owner, guid)) { |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 327 | if (len) |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 328 | *len = (u32)(res_desc->len); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 329 | |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 330 | return (u64)(res_desc->phys_start); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 331 | } |
| 332 | } |
| 333 | } |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 334 | hdr = get_next_hob(hdr); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | return 0; |
| 338 | } |
| 339 | |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 340 | u32 fsp_get_fsp_reserved_mem(const void *hob_list, u32 *len) |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 341 | { |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 342 | const struct efi_guid guid = FSP_HOB_RESOURCE_OWNER_FSP_GUID; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 343 | u64 length; |
| 344 | u32 base; |
| 345 | |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 346 | base = (u32)fsp_get_reserved_mem_from_guid(hob_list, |
| 347 | &length, (struct efi_guid *)&guid); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 348 | if ((len != 0) && (base != 0)) |
| 349 | *len = (u32)length; |
| 350 | |
| 351 | return base; |
| 352 | } |
| 353 | |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 354 | u32 fsp_get_tseg_reserved_mem(const void *hob_list, u32 *len) |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 355 | { |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 356 | const struct efi_guid guid = FSP_HOB_RESOURCE_OWNER_TSEG_GUID; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 357 | u64 length; |
| 358 | u32 base; |
| 359 | |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 360 | base = (u32)fsp_get_reserved_mem_from_guid(hob_list, |
| 361 | &length, (struct efi_guid *)&guid); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 362 | if ((len != 0) && (base != 0)) |
| 363 | *len = (u32)length; |
| 364 | |
| 365 | return base; |
| 366 | } |
| 367 | |
Bin Meng | 2f848bc | 2015-01-06 14:04:36 +0800 | [diff] [blame] | 368 | 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] | 369 | { |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 370 | const struct hob_header *hdr; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 371 | |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 372 | hdr = hob_list; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 373 | |
| 374 | /* 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] | 375 | while (!end_of_hob(hdr)) { |
Bin Meng | 2f848bc | 2015-01-06 14:04:36 +0800 | [diff] [blame] | 376 | if (hdr->type == type) |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 377 | return hdr; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 378 | |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 379 | hdr = get_next_hob(hdr); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | return NULL; |
| 383 | } |
| 384 | |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 385 | const struct hob_header *fsp_get_next_guid_hob(const struct efi_guid *guid, |
| 386 | const void *hob_list) |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 387 | { |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 388 | const struct hob_header *hdr; |
| 389 | struct hob_guid *guid_hob; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 390 | |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 391 | hdr = hob_list; |
| 392 | while ((hdr = fsp_get_next_hob(HOB_TYPE_GUID_EXT, |
| 393 | hdr)) != NULL) { |
| 394 | guid_hob = (struct hob_guid *)hdr; |
| 395 | if (compare_guid(guid, &(guid_hob->name))) |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 396 | break; |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 397 | hdr = get_next_hob(hdr); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 398 | } |
| 399 | |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 400 | return hdr; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 401 | } |
| 402 | |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 403 | void *fsp_get_guid_hob_data(const void *hob_list, u32 *len, |
| 404 | struct efi_guid *guid) |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 405 | { |
Bin Meng | 2b21598 | 2014-12-30 16:02:05 +0800 | [diff] [blame] | 406 | const struct hob_header *guid_hob; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 407 | |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 408 | guid_hob = fsp_get_next_guid_hob(guid, hob_list); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 409 | if (guid_hob == NULL) { |
| 410 | return NULL; |
| 411 | } else { |
| 412 | if (len) |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 413 | *len = get_guid_hob_data_size(guid_hob); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 414 | |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 415 | return get_guid_hob_data(guid_hob); |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 416 | } |
| 417 | } |
| 418 | |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 419 | void *fsp_get_nvs_data(const void *hob_list, u32 *len) |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 420 | { |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 421 | const struct efi_guid guid = FSP_NON_VOLATILE_STORAGE_HOB_GUID; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 422 | |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 423 | 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] | 424 | } |
| 425 | |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 426 | void *fsp_get_bootloader_tmp_mem(const void *hob_list, u32 *len) |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 427 | { |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 428 | const struct efi_guid guid = FSP_BOOTLOADER_TEMP_MEM_HOB_GUID; |
Bin Meng | 2922b3e | 2014-12-12 21:05:28 +0800 | [diff] [blame] | 429 | |
Bin Meng | db60d86 | 2014-12-17 15:50:49 +0800 | [diff] [blame] | 430 | 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] | 431 | } |