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