Angel Pons | 8a3453f | 2020-04-02 23:48:19 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 2 | |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 3 | #include <bootstate.h> |
| 4 | #include <cbmem.h> |
Elyes HAOUAS | 2195f7a | 2019-06-21 07:20:12 +0200 | [diff] [blame] | 5 | #include <commonlib/helpers.h> |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 6 | #include <console/console.h> |
Lee Leahy | c52a4f7 | 2016-08-09 09:02:13 -0700 | [diff] [blame] | 7 | #include <console/streams.h> |
Aaron Durbin | 789f2b6 | 2015-09-09 17:05:06 -0500 | [diff] [blame] | 8 | #include <fsp/util.h> |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 9 | #include <timestamp.h> |
| 10 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 11 | /* Locate the FSP binary in the coreboot filesystem */ |
Lee Leahy | a887492 | 2015-08-26 14:58:29 -0700 | [diff] [blame] | 12 | FSP_INFO_HEADER *find_fsp(uintptr_t fsp_base_address) |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 13 | { |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 14 | union { |
| 15 | EFI_FFS_FILE_HEADER *ffh; |
| 16 | FSP_INFO_HEADER *fih; |
| 17 | EFI_FIRMWARE_VOLUME_EXT_HEADER *fveh; |
| 18 | EFI_FIRMWARE_VOLUME_HEADER *fvh; |
| 19 | EFI_RAW_SECTION *rs; |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 20 | u32 u32; |
| 21 | } fsp_ptr; |
Alexandru Gagniuc | 5c26122 | 2015-08-29 18:53:43 -0700 | [diff] [blame] | 22 | |
Nico Huber | e7947df | 2017-05-09 16:03:24 +0200 | [diff] [blame] | 23 | u64 *image_id; |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 24 | |
Lee Leahy | 00c35c1 | 2016-05-17 08:57:42 -0700 | [diff] [blame] | 25 | /* Get the FSP binary base address in CBFS */ |
| 26 | fsp_ptr.u32 = fsp_base_address; |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 27 | |
Lee Leahy | 00c35c1 | 2016-05-17 08:57:42 -0700 | [diff] [blame] | 28 | /* Check the FV signature, _FVH */ |
Lee Leahy | 216712a | 2017-03-17 11:23:32 -0700 | [diff] [blame] | 29 | if (fsp_ptr.fvh->Signature != 0x4856465F) |
Lee Leahy | 00c35c1 | 2016-05-17 08:57:42 -0700 | [diff] [blame] | 30 | return (FSP_INFO_HEADER *)ERROR_NO_FV_SIG; |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 31 | |
Lee Leahy | 00c35c1 | 2016-05-17 08:57:42 -0700 | [diff] [blame] | 32 | /* Locate the file header which follows the FV header. */ |
Lee Leahy | d3989a2 | 2016-05-17 09:29:09 -0700 | [diff] [blame] | 33 | fsp_ptr.u32 += fsp_ptr.fvh->ExtHeaderOffset; |
| 34 | fsp_ptr.u32 += fsp_ptr.fveh->ExtHeaderSize; |
| 35 | fsp_ptr.u32 = ALIGN_UP(fsp_ptr.u32, 8); |
Lee Leahy | 00c35c1 | 2016-05-17 08:57:42 -0700 | [diff] [blame] | 36 | |
| 37 | /* Check the FFS GUID */ |
| 38 | if ((((u32 *)&fsp_ptr.ffh->Name)[0] != 0x912740BE) |
| 39 | || (((u32 *)&fsp_ptr.ffh->Name)[1] != 0x47342284) |
| 40 | || (((u32 *)&fsp_ptr.ffh->Name)[2] != 0xB08471B9) |
| 41 | || (((u32 *)&fsp_ptr.ffh->Name)[3] != 0x0C3F3527)) { |
| 42 | return (FSP_INFO_HEADER *)ERROR_NO_FFS_GUID; |
| 43 | } |
| 44 | |
| 45 | /* Locate the Raw Section Header */ |
Lee Leahy | d3989a2 | 2016-05-17 09:29:09 -0700 | [diff] [blame] | 46 | fsp_ptr.u32 += sizeof(EFI_FFS_FILE_HEADER); |
Lee Leahy | 00c35c1 | 2016-05-17 08:57:42 -0700 | [diff] [blame] | 47 | |
Lee Leahy | 216712a | 2017-03-17 11:23:32 -0700 | [diff] [blame] | 48 | if (fsp_ptr.rs->Type != EFI_SECTION_RAW) |
Lee Leahy | 00c35c1 | 2016-05-17 08:57:42 -0700 | [diff] [blame] | 49 | return (FSP_INFO_HEADER *)ERROR_NO_INFO_HEADER; |
Lee Leahy | 00c35c1 | 2016-05-17 08:57:42 -0700 | [diff] [blame] | 50 | |
| 51 | /* Locate the FSP INFO Header which follows the Raw Header. */ |
Lee Leahy | d3989a2 | 2016-05-17 09:29:09 -0700 | [diff] [blame] | 52 | fsp_ptr.u32 += sizeof(EFI_RAW_SECTION); |
Lee Leahy | 00c35c1 | 2016-05-17 08:57:42 -0700 | [diff] [blame] | 53 | |
| 54 | /* Verify that the FSP base address.*/ |
Lee Leahy | 216712a | 2017-03-17 11:23:32 -0700 | [diff] [blame] | 55 | if (fsp_ptr.fih->ImageBase != fsp_base_address) |
Lee Leahy | 00c35c1 | 2016-05-17 08:57:42 -0700 | [diff] [blame] | 56 | return (FSP_INFO_HEADER *)ERROR_IMAGEBASE_MISMATCH; |
Lee Leahy | 00c35c1 | 2016-05-17 08:57:42 -0700 | [diff] [blame] | 57 | |
| 58 | /* Verify the FSP Signature */ |
Lee Leahy | 216712a | 2017-03-17 11:23:32 -0700 | [diff] [blame] | 59 | if (fsp_ptr.fih->Signature != FSP_SIG) |
Lee Leahy | 00c35c1 | 2016-05-17 08:57:42 -0700 | [diff] [blame] | 60 | return (FSP_INFO_HEADER *)ERROR_INFO_HEAD_SIG_MISMATCH; |
Lee Leahy | 00c35c1 | 2016-05-17 08:57:42 -0700 | [diff] [blame] | 61 | |
| 62 | /* Verify the FSP ID */ |
Nico Huber | e7947df | 2017-05-09 16:03:24 +0200 | [diff] [blame] | 63 | image_id = (u64 *)&fsp_ptr.fih->ImageId[0]; |
| 64 | if (*image_id != FSP_IMAGE_ID) |
Lee Leahy | 00c35c1 | 2016-05-17 08:57:42 -0700 | [diff] [blame] | 65 | return (FSP_INFO_HEADER *)ERROR_FSP_SIG_MISMATCH; |
| 66 | |
Nico Huber | e7947df | 2017-05-09 16:03:24 +0200 | [diff] [blame] | 67 | /* Verify the FSP Revision */ |
Matt DeVillier | 77c01e1 | 2017-09-07 11:28:53 -0500 | [diff] [blame] | 68 | if (fsp_ptr.fih->ImageRevision > FSP_IMAGE_REV) |
Nico Huber | e7947df | 2017-05-09 16:03:24 +0200 | [diff] [blame] | 69 | return (FSP_INFO_HEADER *)ERROR_FSP_REV_MISMATCH; |
| 70 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 71 | return fsp_ptr.fih; |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 72 | } |
| 73 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 74 | void print_fsp_info(FSP_INFO_HEADER *fsp_header) |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 75 | { |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 76 | u8 *fsp_base; |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 77 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 78 | fsp_base = (u8 *)fsp_header->ImageBase; |
| 79 | printk(BIOS_SPEW, "FSP_INFO_HEADER: %p\n", fsp_header); |
| 80 | printk(BIOS_INFO, "FSP Signature: %c%c%c%c%c%c%c%c\n", |
| 81 | fsp_header->ImageId[0], fsp_header->ImageId[1], |
| 82 | fsp_header->ImageId[2], fsp_header->ImageId[3], |
| 83 | fsp_header->ImageId[4], fsp_header->ImageId[5], |
| 84 | fsp_header->ImageId[6], fsp_header->ImageId[7]); |
| 85 | printk(BIOS_INFO, "FSP Header Version: %d\n", |
| 86 | fsp_header->HeaderRevision); |
Dhaval Sharma | 590ac64 | 2015-11-02 17:12:10 +0530 | [diff] [blame] | 87 | printk(BIOS_INFO, "FSP Revision: %d.%d.%d.%d\n", |
| 88 | (u8)((fsp_header->ImageRevision >> 24) & 0xff), |
| 89 | (u8)((fsp_header->ImageRevision >> 16) & 0xff), |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 90 | (u8)((fsp_header->ImageRevision >> 8) & 0xff), |
| 91 | (u8)(fsp_header->ImageRevision & 0xff)); |
Arthur Heymans | 3473d16 | 2022-03-24 00:26:57 +0100 | [diff] [blame] | 92 | if (CONFIG(DISPLAY_FSP_ENTRY_POINTS)) { |
| 93 | printk(BIOS_SPEW, "FSP Entry Points:\n"); |
| 94 | printk(BIOS_SPEW, " %p: Image Base\n", fsp_base); |
| 95 | printk(BIOS_SPEW, " %p: TempRamInit\n", |
| 96 | &fsp_base[fsp_header->TempRamInitEntryOffset]); |
| 97 | printk(BIOS_SPEW, " %p: FspInit\n", |
| 98 | &fsp_base[fsp_header->FspInitEntryOffset]); |
| 99 | if (fsp_header->HeaderRevision >= FSP_HEADER_REVISION_2) { |
| 100 | printk(BIOS_SPEW, " %p: MemoryInit\n", |
| 101 | &fsp_base[fsp_header->FspMemoryInitEntryOffset]); |
| 102 | printk(BIOS_SPEW, " %p: TempRamExit\n", |
| 103 | &fsp_base[fsp_header->TempRamExitEntryOffset]); |
| 104 | printk(BIOS_SPEW, " %p: SiliconInit\n", |
| 105 | &fsp_base[fsp_header->FspSiliconInitEntryOffset]); |
| 106 | } |
| 107 | printk(BIOS_SPEW, " %p: NotifyPhase\n", |
| 108 | &fsp_base[fsp_header->NotifyPhaseEntryOffset]); |
| 109 | printk(BIOS_SPEW, " %p: Image End\n", |
| 110 | &fsp_base[fsp_header->ImageSize]); |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 111 | } |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 112 | } |
| 113 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 114 | void fsp_notify(u32 phase) |
| 115 | { |
| 116 | FSP_NOTIFY_PHASE notify_phase_proc; |
| 117 | NOTIFY_PHASE_PARAMS notify_phase_params; |
| 118 | EFI_STATUS status; |
| 119 | FSP_INFO_HEADER *fsp_header_ptr; |
| 120 | |
| 121 | fsp_header_ptr = fsp_get_fih(); |
| 122 | if (fsp_header_ptr == NULL) { |
Lee Leahy | a887492 | 2015-08-26 14:58:29 -0700 | [diff] [blame] | 123 | fsp_header_ptr = (void *)find_fsp(CONFIG_FSP_LOC); |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 124 | if ((u32)fsp_header_ptr < 0xff) { |
| 125 | /* output something in case there is no serial */ |
| 126 | post_code(0x4F); |
| 127 | die("Can't find the FSP!\n"); |
| 128 | } |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 129 | } |
| 130 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 131 | /* call FSP PEI to Notify PostPciEnumeration */ |
| 132 | notify_phase_proc = (FSP_NOTIFY_PHASE)(fsp_header_ptr->ImageBase + |
| 133 | fsp_header_ptr->NotifyPhaseEntryOffset); |
| 134 | notify_phase_params.Phase = phase; |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 135 | |
Duncan Laurie | fb50983 | 2015-11-22 14:53:57 -0800 | [diff] [blame] | 136 | if (phase == EnumInitPhaseReadyToBoot) { |
Jakub Czapiga | ad6157e | 2022-02-15 11:50:31 +0100 | [diff] [blame] | 137 | timestamp_add_now(TS_FSP_FINALIZE_START); |
lilacious | 40cb3fe | 2023-06-21 23:24:14 +0200 | [diff] [blame] | 138 | post_code(POSTCODE_FSP_NOTIFY_BEFORE_FINALIZE); |
Lee Leahy | a5244c3 | 2015-12-17 11:13:01 -0800 | [diff] [blame] | 139 | } else { |
Jakub Czapiga | ad6157e | 2022-02-15 11:50:31 +0100 | [diff] [blame] | 140 | timestamp_add_now(TS_FSP_ENUMERATE_START); |
lilacious | 40cb3fe | 2023-06-21 23:24:14 +0200 | [diff] [blame] | 141 | post_code(POSTCODE_FSP_NOTIFY_BEFORE_ENUMERATE); |
Duncan Laurie | fb50983 | 2015-11-22 14:53:57 -0800 | [diff] [blame] | 142 | } |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 143 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 144 | status = notify_phase_proc(¬ify_phase_params); |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 145 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 146 | timestamp_add_now(phase == EnumInitPhaseReadyToBoot ? |
Jakub Czapiga | ad6157e | 2022-02-15 11:50:31 +0100 | [diff] [blame] | 147 | TS_FSP_FINALIZE_END : TS_FSP_ENUMERATE_END); |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 148 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 149 | if (status != 0) |
| 150 | printk(BIOS_ERR, "FSP API NotifyPhase failed for phase 0x%x with status: 0x%x\n", |
| 151 | phase, status); |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 152 | } |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 153 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 154 | static void fsp_notify_boot_state_callback(void *arg) |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 155 | { |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 156 | u32 phase = (u32)arg; |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 157 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 158 | printk(BIOS_SPEW, "Calling FspNotify(0x%08x)\n", phase); |
| 159 | fsp_notify(phase); |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 160 | } |
| 161 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 162 | BOOT_STATE_INIT_ENTRY(BS_DEV_RESOURCES, BS_ON_EXIT, |
| 163 | fsp_notify_boot_state_callback, |
| 164 | (void *)EnumInitPhaseAfterPciEnumeration); |
| 165 | BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_EXIT, |
| 166 | fsp_notify_boot_state_callback, |
| 167 | (void *)EnumInitPhaseReadyToBoot); |
| 168 | BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, |
| 169 | fsp_notify_boot_state_callback, |
| 170 | (void *)EnumInitPhaseReadyToBoot); |
| 171 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 172 | struct fsp_runtime { |
| 173 | uint32_t fih; |
| 174 | uint32_t hob_list; |
Stefan Reinauer | 6a00113 | 2017-07-13 02:20:27 +0200 | [diff] [blame] | 175 | } __packed; |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 176 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 177 | void fsp_set_runtime(FSP_INFO_HEADER *fih, void *hob_list) |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 178 | { |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 179 | struct fsp_runtime *fspr; |
| 180 | |
| 181 | fspr = cbmem_add(CBMEM_ID_FSP_RUNTIME, sizeof(*fspr)); |
| 182 | |
| 183 | if (fspr == NULL) |
| 184 | die("Can't save FSP runtime information.\n"); |
| 185 | |
| 186 | fspr->fih = (uintptr_t)fih; |
| 187 | fspr->hob_list = (uintptr_t)hob_list; |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 188 | } |
| 189 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 190 | FSP_INFO_HEADER *fsp_get_fih(void) |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 191 | { |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 192 | struct fsp_runtime *fspr; |
| 193 | |
| 194 | fspr = cbmem_find(CBMEM_ID_FSP_RUNTIME); |
| 195 | |
| 196 | if (fspr == NULL) |
| 197 | return NULL; |
| 198 | |
| 199 | return (void *)(uintptr_t)fspr->fih; |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 200 | } |
| 201 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 202 | void *fsp_get_hob_list(void) |
| 203 | { |
| 204 | struct fsp_runtime *fspr; |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 205 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 206 | fspr = cbmem_find(CBMEM_ID_FSP_RUNTIME); |
| 207 | |
| 208 | if (fspr == NULL) |
| 209 | return NULL; |
| 210 | |
| 211 | return (void *)(uintptr_t)fspr->hob_list; |
| 212 | } |
| 213 | |
| 214 | void fsp_update_fih(FSP_INFO_HEADER *fih) |
| 215 | { |
| 216 | struct fsp_runtime *fspr; |
| 217 | |
| 218 | fspr = cbmem_find(CBMEM_ID_FSP_RUNTIME); |
| 219 | |
| 220 | if (fspr == NULL) |
| 221 | die("Can't update FSP runtime information.\n"); |
| 222 | |
| 223 | fspr->fih = (uintptr_t)fih; |
| 224 | } |
Lee Leahy | 94b856e | 2015-10-15 12:07:03 -0700 | [diff] [blame] | 225 | |
Lee Leahy | 66208bd | 2015-10-15 16:17:58 -0700 | [diff] [blame] | 226 | void fsp_display_upd_value(const char *name, uint32_t size, uint64_t old, |
Lee Leahy | 94b856e | 2015-10-15 12:07:03 -0700 | [diff] [blame] | 227 | uint64_t new) |
| 228 | { |
| 229 | if (old == new) { |
| 230 | switch (size) { |
| 231 | case 1: |
| 232 | printk(BIOS_SPEW, " 0x%02llx: %s\n", new, name); |
| 233 | break; |
| 234 | |
| 235 | case 2: |
| 236 | printk(BIOS_SPEW, " 0x%04llx: %s\n", new, name); |
| 237 | break; |
| 238 | |
| 239 | case 4: |
| 240 | printk(BIOS_SPEW, " 0x%08llx: %s\n", new, name); |
| 241 | break; |
| 242 | |
| 243 | case 8: |
| 244 | printk(BIOS_SPEW, " 0x%016llx: %s\n", new, name); |
| 245 | break; |
| 246 | } |
| 247 | } else { |
| 248 | switch (size) { |
| 249 | case 1: |
| 250 | printk(BIOS_SPEW, " 0x%02llx --> 0x%02llx: %s\n", old, |
| 251 | new, name); |
| 252 | break; |
| 253 | |
| 254 | case 2: |
| 255 | printk(BIOS_SPEW, " 0x%04llx --> 0x%04llx: %s\n", old, |
| 256 | new, name); |
| 257 | break; |
| 258 | |
| 259 | case 4: |
| 260 | printk(BIOS_SPEW, " 0x%08llx --> 0x%08llx: %s\n", old, |
| 261 | new, name); |
| 262 | break; |
| 263 | |
| 264 | case 8: |
| 265 | printk(BIOS_SPEW, " 0x%016llx --> 0x%016llx: %s\n", |
| 266 | old, new, name); |
| 267 | break; |
| 268 | } |
| 269 | } |
| 270 | } |