Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2013-2014 Sage Electronic Engineering, LLC. |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 5 | * Copyright (C) 2015 Intel Corp. |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
Patrick Georgi | b890a12 | 2015-03-26 15:17:45 +0100 | [diff] [blame] | 18 | * Foundation, Inc. |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 19 | */ |
| 20 | |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 21 | #include <bootstate.h> |
| 22 | #include <cbmem.h> |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 23 | #include <console/console.h> |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 24 | #include "fsp_util.h" |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 25 | #include <timestamp.h> |
| 26 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 27 | /* Locate the FSP binary in the coreboot filesystem */ |
| 28 | FSP_INFO_HEADER *find_fsp(void) |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 29 | { |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 30 | union { |
| 31 | EFI_FFS_FILE_HEADER *ffh; |
| 32 | FSP_INFO_HEADER *fih; |
| 33 | EFI_FIRMWARE_VOLUME_EXT_HEADER *fveh; |
| 34 | EFI_FIRMWARE_VOLUME_HEADER *fvh; |
| 35 | EFI_RAW_SECTION *rs; |
| 36 | u8 *u8; |
| 37 | u32 u32; |
| 38 | } fsp_ptr; |
| 39 | u32 *image_id; |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 40 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 41 | for (;;) { |
| 42 | /* Get the FSP binary base address in CBFS */ |
| 43 | fsp_ptr.u8 = (u8 *)CONFIG_FSP_LOC; |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 44 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 45 | /* Check the FV signature, _FVH */ |
| 46 | if (fsp_ptr.fvh->Signature != 0x4856465F) { |
| 47 | fsp_ptr.u8 = (u8 *)ERROR_NO_FV_SIG; |
| 48 | break; |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 49 | } |
| 50 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 51 | /* Locate the file header which follows the FV header. */ |
| 52 | fsp_ptr.u8 += fsp_ptr.fvh->ExtHeaderOffset; |
| 53 | fsp_ptr.u8 += fsp_ptr.fveh->ExtHeaderSize; |
Alexandru Gagniuc | 3f2a945 | 2015-08-29 18:25:10 -0700 | [diff] [blame] | 54 | fsp_ptr.u8 = (u8 *)ALIGN_UP(fsp_ptr.u32, 8); |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 55 | |
| 56 | /* Check the FFS GUID */ |
| 57 | if ((((u32 *)&fsp_ptr.ffh->Name)[0] != 0x912740BE) |
| 58 | || (((u32 *)&fsp_ptr.ffh->Name)[1] != 0x47342284) |
| 59 | || (((u32 *)&fsp_ptr.ffh->Name)[2] != 0xB08471B9) |
| 60 | || (((u32 *)&fsp_ptr.ffh->Name)[3] != 0x0C3F3527)) { |
| 61 | fsp_ptr.u8 = (u8 *)ERROR_NO_FFS_GUID; |
| 62 | break; |
| 63 | } |
| 64 | |
| 65 | /* Locate the Raw Section Header */ |
| 66 | fsp_ptr.u8 += sizeof(EFI_FFS_FILE_HEADER); |
| 67 | |
| 68 | if (fsp_ptr.rs->Type != EFI_SECTION_RAW) { |
| 69 | fsp_ptr.u8 = (u8 *)ERROR_NO_INFO_HEADER; |
| 70 | break; |
| 71 | } |
| 72 | |
| 73 | /* Locate the FSP INFO Header which follows the Raw Header. */ |
| 74 | fsp_ptr.u8 += sizeof(EFI_RAW_SECTION); |
| 75 | |
| 76 | /* Verify that the FSP base address.*/ |
| 77 | if (fsp_ptr.fih->ImageBase != CONFIG_FSP_LOC) { |
| 78 | fsp_ptr.u8 = (u8 *)ERROR_IMAGEBASE_MISMATCH; |
| 79 | break; |
| 80 | } |
| 81 | |
| 82 | /* Verify the FSP Signature */ |
| 83 | if (fsp_ptr.fih->Signature != FSP_SIG) { |
| 84 | fsp_ptr.u8 = (u8 *)ERROR_INFO_HEAD_SIG_MISMATCH; |
| 85 | break; |
| 86 | } |
| 87 | |
| 88 | /* Verify the FSP ID */ |
| 89 | image_id = (u32 *)&fsp_ptr.fih->ImageId[0]; |
| 90 | if ((image_id[0] != CONFIG_FSP_IMAGE_ID_DWORD0) |
| 91 | || (image_id[1] != CONFIG_FSP_IMAGE_ID_DWORD1)) |
| 92 | fsp_ptr.u8 = (u8 *)ERROR_FSP_SIG_MISMATCH; |
| 93 | break; |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 94 | } |
| 95 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 96 | return fsp_ptr.fih; |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 97 | } |
| 98 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 99 | void print_fsp_info(FSP_INFO_HEADER *fsp_header) |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 100 | { |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 101 | u8 *fsp_base; |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 102 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 103 | fsp_base = (u8 *)fsp_header->ImageBase; |
| 104 | printk(BIOS_SPEW, "FSP_INFO_HEADER: %p\n", fsp_header); |
| 105 | printk(BIOS_INFO, "FSP Signature: %c%c%c%c%c%c%c%c\n", |
| 106 | fsp_header->ImageId[0], fsp_header->ImageId[1], |
| 107 | fsp_header->ImageId[2], fsp_header->ImageId[3], |
| 108 | fsp_header->ImageId[4], fsp_header->ImageId[5], |
| 109 | fsp_header->ImageId[6], fsp_header->ImageId[7]); |
| 110 | printk(BIOS_INFO, "FSP Header Version: %d\n", |
| 111 | fsp_header->HeaderRevision); |
| 112 | printk(BIOS_INFO, "FSP Revision: %d.%d\n", |
| 113 | (u8)((fsp_header->ImageRevision >> 8) & 0xff), |
| 114 | (u8)(fsp_header->ImageRevision & 0xff)); |
| 115 | #if IS_ENABLED(CONFIG_DISPLAY_FSP_ENTRY_POINTS) |
| 116 | printk(BIOS_SPEW, "FSP Entry Points:\n"); |
| 117 | printk(BIOS_SPEW, " 0x%p: Image Base\n", fsp_base); |
| 118 | printk(BIOS_SPEW, " 0x%p: TempRamInit\n", |
| 119 | &fsp_base[fsp_header->TempRamInitEntryOffset]); |
| 120 | printk(BIOS_SPEW, " 0x%p: FspInit\n", |
| 121 | &fsp_base[fsp_header->FspInitEntryOffset]); |
| 122 | if (fsp_header->HeaderRevision >= FSP_HEADER_REVISION_2) { |
| 123 | printk(BIOS_SPEW, " 0x%p: MemoryInit\n", |
| 124 | &fsp_base[fsp_header->FspMemoryInitEntryOffset]); |
| 125 | printk(BIOS_SPEW, " 0x%p: TempRamExit\n", |
| 126 | &fsp_base[fsp_header->TempRamExitEntryOffset]); |
| 127 | printk(BIOS_SPEW, " 0x%p: SiliconInit\n", |
| 128 | &fsp_base[fsp_header->FspSiliconInitEntryOffset]); |
| 129 | } |
| 130 | printk(BIOS_SPEW, " 0x%p: NotifyPhase\n", |
| 131 | &fsp_base[fsp_header->NotifyPhaseEntryOffset]); |
| 132 | printk(BIOS_SPEW, " 0x%p: Image End\n", |
| 133 | &fsp_base[fsp_header->ImageSize]); |
| 134 | #endif |
| 135 | } |
| 136 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 137 | void fsp_notify(u32 phase) |
| 138 | { |
| 139 | FSP_NOTIFY_PHASE notify_phase_proc; |
| 140 | NOTIFY_PHASE_PARAMS notify_phase_params; |
| 141 | EFI_STATUS status; |
| 142 | FSP_INFO_HEADER *fsp_header_ptr; |
| 143 | |
| 144 | fsp_header_ptr = fsp_get_fih(); |
| 145 | if (fsp_header_ptr == NULL) { |
| 146 | fsp_header_ptr = (void *)find_fsp(); |
| 147 | if ((u32)fsp_header_ptr < 0xff) { |
| 148 | /* output something in case there is no serial */ |
| 149 | post_code(0x4F); |
| 150 | die("Can't find the FSP!\n"); |
| 151 | } |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 152 | } |
| 153 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 154 | /* call FSP PEI to Notify PostPciEnumeration */ |
| 155 | notify_phase_proc = (FSP_NOTIFY_PHASE)(fsp_header_ptr->ImageBase + |
| 156 | fsp_header_ptr->NotifyPhaseEntryOffset); |
| 157 | notify_phase_params.Phase = phase; |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 158 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 159 | timestamp_add_now(phase == EnumInitPhaseReadyToBoot ? |
| 160 | TS_FSP_BEFORE_FINALIZE : TS_FSP_BEFORE_ENUMERATE); |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 161 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 162 | status = notify_phase_proc(¬ify_phase_params); |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 163 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 164 | timestamp_add_now(phase == EnumInitPhaseReadyToBoot ? |
| 165 | TS_FSP_AFTER_FINALIZE : TS_FSP_AFTER_ENUMERATE); |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 166 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 167 | if (status != 0) |
| 168 | printk(BIOS_ERR, "FSP API NotifyPhase failed for phase 0x%x with status: 0x%x\n", |
| 169 | phase, status); |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 170 | } |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 171 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 172 | static void fsp_notify_boot_state_callback(void *arg) |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 173 | { |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 174 | u32 phase = (u32)arg; |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 175 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 176 | printk(BIOS_SPEW, "Calling FspNotify(0x%08x)\n", phase); |
| 177 | fsp_notify(phase); |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 178 | } |
| 179 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 180 | BOOT_STATE_INIT_ENTRY(BS_DEV_RESOURCES, BS_ON_EXIT, |
| 181 | fsp_notify_boot_state_callback, |
| 182 | (void *)EnumInitPhaseAfterPciEnumeration); |
| 183 | BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_EXIT, |
| 184 | fsp_notify_boot_state_callback, |
| 185 | (void *)EnumInitPhaseReadyToBoot); |
| 186 | BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, |
| 187 | fsp_notify_boot_state_callback, |
| 188 | (void *)EnumInitPhaseReadyToBoot); |
| 189 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 190 | struct fsp_runtime { |
| 191 | uint32_t fih; |
| 192 | uint32_t hob_list; |
| 193 | } __attribute__((packed)); |
| 194 | |
| 195 | |
| 196 | void fsp_set_runtime(FSP_INFO_HEADER *fih, void *hob_list) |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 197 | { |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 198 | struct fsp_runtime *fspr; |
| 199 | |
| 200 | fspr = cbmem_add(CBMEM_ID_FSP_RUNTIME, sizeof(*fspr)); |
| 201 | |
| 202 | if (fspr == NULL) |
| 203 | die("Can't save FSP runtime information.\n"); |
| 204 | |
| 205 | fspr->fih = (uintptr_t)fih; |
| 206 | fspr->hob_list = (uintptr_t)hob_list; |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 207 | } |
| 208 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 209 | FSP_INFO_HEADER *fsp_get_fih(void) |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 210 | { |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 211 | struct fsp_runtime *fspr; |
| 212 | |
| 213 | fspr = cbmem_find(CBMEM_ID_FSP_RUNTIME); |
| 214 | |
| 215 | if (fspr == NULL) |
| 216 | return NULL; |
| 217 | |
| 218 | return (void *)(uintptr_t)fspr->fih; |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 219 | } |
| 220 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 221 | void *fsp_get_hob_list(void) |
| 222 | { |
| 223 | struct fsp_runtime *fspr; |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 224 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 225 | fspr = cbmem_find(CBMEM_ID_FSP_RUNTIME); |
| 226 | |
| 227 | if (fspr == NULL) |
| 228 | return NULL; |
| 229 | |
| 230 | return (void *)(uintptr_t)fspr->hob_list; |
| 231 | } |
| 232 | |
| 233 | void fsp_update_fih(FSP_INFO_HEADER *fih) |
| 234 | { |
| 235 | struct fsp_runtime *fspr; |
| 236 | |
| 237 | fspr = cbmem_find(CBMEM_ID_FSP_RUNTIME); |
| 238 | |
| 239 | if (fspr == NULL) |
| 240 | die("Can't update FSP runtime information.\n"); |
| 241 | |
| 242 | fspr->fih = (uintptr_t)fih; |
| 243 | } |