blob: 1aa3aec92c8c143f8ed8510bc898b094afec3c3e [file] [log] [blame]
Lee Leahy3dad4892015-05-05 11:14:02 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2013-2014 Sage Electronic Engineering, LLC.
Lee Leahyb5ad8272015-04-20 15:29:16 -07005 * Copyright (C) 2015 Intel Corp.
Lee Leahy3dad4892015-05-05 11:14:02 -07006 *
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.
Lee Leahy3dad4892015-05-05 11:14:02 -070015 */
16
Lee Leahy3dad4892015-05-05 11:14:02 -070017#include <bootstate.h>
18#include <cbmem.h>
Lee Leahyb5ad8272015-04-20 15:29:16 -070019#include <console/console.h>
Aaron Durbin789f2b62015-09-09 17:05:06 -050020#include <fsp/util.h>
Lee Leahy3dad4892015-05-05 11:14:02 -070021#include <timestamp.h>
22
Lee Leahyb5ad8272015-04-20 15:29:16 -070023/* Locate the FSP binary in the coreboot filesystem */
Lee Leahya8874922015-08-26 14:58:29 -070024FSP_INFO_HEADER *find_fsp(uintptr_t fsp_base_address)
Lee Leahy3dad4892015-05-05 11:14:02 -070025{
Lee Leahyb5ad8272015-04-20 15:29:16 -070026 union {
27 EFI_FFS_FILE_HEADER *ffh;
28 FSP_INFO_HEADER *fih;
29 EFI_FIRMWARE_VOLUME_EXT_HEADER *fveh;
30 EFI_FIRMWARE_VOLUME_HEADER *fvh;
31 EFI_RAW_SECTION *rs;
32 u8 *u8;
33 u32 u32;
34 } fsp_ptr;
Alexandru Gagniuc5c261222015-08-29 18:53:43 -070035 static const union {
36 char str_id[8];
37 u32 int_id[2];
38 } fsp_id = {
39 .str_id = CONFIG_FSP_IMAGE_ID_STRING
40 };
41
Lee Leahyb5ad8272015-04-20 15:29:16 -070042 u32 *image_id;
Lee Leahy3dad4892015-05-05 11:14:02 -070043
Lee Leahyb5ad8272015-04-20 15:29:16 -070044 for (;;) {
45 /* Get the FSP binary base address in CBFS */
Lee Leahya8874922015-08-26 14:58:29 -070046 fsp_ptr.u32 = fsp_base_address;
Lee Leahy3dad4892015-05-05 11:14:02 -070047
Lee Leahyb5ad8272015-04-20 15:29:16 -070048 /* Check the FV signature, _FVH */
49 if (fsp_ptr.fvh->Signature != 0x4856465F) {
50 fsp_ptr.u8 = (u8 *)ERROR_NO_FV_SIG;
51 break;
Lee Leahy3dad4892015-05-05 11:14:02 -070052 }
53
Lee Leahyb5ad8272015-04-20 15:29:16 -070054 /* Locate the file header which follows the FV header. */
55 fsp_ptr.u8 += fsp_ptr.fvh->ExtHeaderOffset;
56 fsp_ptr.u8 += fsp_ptr.fveh->ExtHeaderSize;
Alexandru Gagniuc3f2a9452015-08-29 18:25:10 -070057 fsp_ptr.u8 = (u8 *)ALIGN_UP(fsp_ptr.u32, 8);
Lee Leahyb5ad8272015-04-20 15:29:16 -070058
59 /* Check the FFS GUID */
60 if ((((u32 *)&fsp_ptr.ffh->Name)[0] != 0x912740BE)
61 || (((u32 *)&fsp_ptr.ffh->Name)[1] != 0x47342284)
62 || (((u32 *)&fsp_ptr.ffh->Name)[2] != 0xB08471B9)
63 || (((u32 *)&fsp_ptr.ffh->Name)[3] != 0x0C3F3527)) {
64 fsp_ptr.u8 = (u8 *)ERROR_NO_FFS_GUID;
65 break;
66 }
67
68 /* Locate the Raw Section Header */
69 fsp_ptr.u8 += sizeof(EFI_FFS_FILE_HEADER);
70
71 if (fsp_ptr.rs->Type != EFI_SECTION_RAW) {
72 fsp_ptr.u8 = (u8 *)ERROR_NO_INFO_HEADER;
73 break;
74 }
75
76 /* Locate the FSP INFO Header which follows the Raw Header. */
77 fsp_ptr.u8 += sizeof(EFI_RAW_SECTION);
78
79 /* Verify that the FSP base address.*/
Lee Leahya8874922015-08-26 14:58:29 -070080 if (fsp_ptr.fih->ImageBase != fsp_base_address) {
Lee Leahyb5ad8272015-04-20 15:29:16 -070081 fsp_ptr.u8 = (u8 *)ERROR_IMAGEBASE_MISMATCH;
82 break;
83 }
84
85 /* Verify the FSP Signature */
86 if (fsp_ptr.fih->Signature != FSP_SIG) {
87 fsp_ptr.u8 = (u8 *)ERROR_INFO_HEAD_SIG_MISMATCH;
88 break;
89 }
90
91 /* Verify the FSP ID */
92 image_id = (u32 *)&fsp_ptr.fih->ImageId[0];
Alexandru Gagniuc5c261222015-08-29 18:53:43 -070093 if ((image_id[0] != fsp_id.int_id[0])
94 || (image_id[1] != fsp_id.int_id[1]))
Lee Leahyb5ad8272015-04-20 15:29:16 -070095 fsp_ptr.u8 = (u8 *)ERROR_FSP_SIG_MISMATCH;
96 break;
Lee Leahy3dad4892015-05-05 11:14:02 -070097 }
98
Lee Leahyb5ad8272015-04-20 15:29:16 -070099 return fsp_ptr.fih;
Lee Leahy3dad4892015-05-05 11:14:02 -0700100}
101
Lee Leahyb5ad8272015-04-20 15:29:16 -0700102void print_fsp_info(FSP_INFO_HEADER *fsp_header)
Lee Leahy3dad4892015-05-05 11:14:02 -0700103{
Lee Leahyb5ad8272015-04-20 15:29:16 -0700104 u8 *fsp_base;
Lee Leahy3dad4892015-05-05 11:14:02 -0700105
Lee Leahyb5ad8272015-04-20 15:29:16 -0700106 fsp_base = (u8 *)fsp_header->ImageBase;
107 printk(BIOS_SPEW, "FSP_INFO_HEADER: %p\n", fsp_header);
108 printk(BIOS_INFO, "FSP Signature: %c%c%c%c%c%c%c%c\n",
109 fsp_header->ImageId[0], fsp_header->ImageId[1],
110 fsp_header->ImageId[2], fsp_header->ImageId[3],
111 fsp_header->ImageId[4], fsp_header->ImageId[5],
112 fsp_header->ImageId[6], fsp_header->ImageId[7]);
113 printk(BIOS_INFO, "FSP Header Version: %d\n",
114 fsp_header->HeaderRevision);
Dhaval Sharma590ac642015-11-02 17:12:10 +0530115 printk(BIOS_INFO, "FSP Revision: %d.%d.%d.%d\n",
116 (u8)((fsp_header->ImageRevision >> 24) & 0xff),
117 (u8)((fsp_header->ImageRevision >> 16) & 0xff),
Lee Leahyb5ad8272015-04-20 15:29:16 -0700118 (u8)((fsp_header->ImageRevision >> 8) & 0xff),
119 (u8)(fsp_header->ImageRevision & 0xff));
120#if IS_ENABLED(CONFIG_DISPLAY_FSP_ENTRY_POINTS)
121 printk(BIOS_SPEW, "FSP Entry Points:\n");
122 printk(BIOS_SPEW, " 0x%p: Image Base\n", fsp_base);
123 printk(BIOS_SPEW, " 0x%p: TempRamInit\n",
124 &fsp_base[fsp_header->TempRamInitEntryOffset]);
125 printk(BIOS_SPEW, " 0x%p: FspInit\n",
126 &fsp_base[fsp_header->FspInitEntryOffset]);
127 if (fsp_header->HeaderRevision >= FSP_HEADER_REVISION_2) {
128 printk(BIOS_SPEW, " 0x%p: MemoryInit\n",
129 &fsp_base[fsp_header->FspMemoryInitEntryOffset]);
130 printk(BIOS_SPEW, " 0x%p: TempRamExit\n",
131 &fsp_base[fsp_header->TempRamExitEntryOffset]);
132 printk(BIOS_SPEW, " 0x%p: SiliconInit\n",
133 &fsp_base[fsp_header->FspSiliconInitEntryOffset]);
134 }
135 printk(BIOS_SPEW, " 0x%p: NotifyPhase\n",
136 &fsp_base[fsp_header->NotifyPhaseEntryOffset]);
137 printk(BIOS_SPEW, " 0x%p: Image End\n",
138 &fsp_base[fsp_header->ImageSize]);
139#endif
140}
141
Lee Leahyb5ad8272015-04-20 15:29:16 -0700142void fsp_notify(u32 phase)
143{
144 FSP_NOTIFY_PHASE notify_phase_proc;
145 NOTIFY_PHASE_PARAMS notify_phase_params;
146 EFI_STATUS status;
147 FSP_INFO_HEADER *fsp_header_ptr;
148
149 fsp_header_ptr = fsp_get_fih();
150 if (fsp_header_ptr == NULL) {
Lee Leahya8874922015-08-26 14:58:29 -0700151 fsp_header_ptr = (void *)find_fsp(CONFIG_FSP_LOC);
Lee Leahyb5ad8272015-04-20 15:29:16 -0700152 if ((u32)fsp_header_ptr < 0xff) {
153 /* output something in case there is no serial */
154 post_code(0x4F);
155 die("Can't find the FSP!\n");
156 }
Lee Leahy3dad4892015-05-05 11:14:02 -0700157 }
158
Lee Leahyb5ad8272015-04-20 15:29:16 -0700159 /* call FSP PEI to Notify PostPciEnumeration */
160 notify_phase_proc = (FSP_NOTIFY_PHASE)(fsp_header_ptr->ImageBase +
161 fsp_header_ptr->NotifyPhaseEntryOffset);
162 notify_phase_params.Phase = phase;
Lee Leahy3dad4892015-05-05 11:14:02 -0700163
Duncan Lauriefb509832015-11-22 14:53:57 -0800164 if (phase == EnumInitPhaseReadyToBoot) {
Duncan Lauriefb509832015-11-22 14:53:57 -0800165 timestamp_add_now(TS_FSP_BEFORE_FINALIZE);
166 post_code(POST_FSP_NOTIFY_BEFORE_FINALIZE);
Lee Leahya5244c32015-12-17 11:13:01 -0800167 } else {
168 timestamp_add_now(TS_FSP_BEFORE_ENUMERATE);
169 post_code(POST_FSP_NOTIFY_BEFORE_ENUMERATE);
Duncan Lauriefb509832015-11-22 14:53:57 -0800170 }
Lee Leahy3dad4892015-05-05 11:14:02 -0700171
Lee Leahyb5ad8272015-04-20 15:29:16 -0700172 status = notify_phase_proc(&notify_phase_params);
Lee Leahy3dad4892015-05-05 11:14:02 -0700173
Lee Leahyb5ad8272015-04-20 15:29:16 -0700174 timestamp_add_now(phase == EnumInitPhaseReadyToBoot ?
175 TS_FSP_AFTER_FINALIZE : TS_FSP_AFTER_ENUMERATE);
Lee Leahy3dad4892015-05-05 11:14:02 -0700176
Lee Leahyb5ad8272015-04-20 15:29:16 -0700177 if (status != 0)
178 printk(BIOS_ERR, "FSP API NotifyPhase failed for phase 0x%x with status: 0x%x\n",
179 phase, status);
Lee Leahy3dad4892015-05-05 11:14:02 -0700180}
Lee Leahy3dad4892015-05-05 11:14:02 -0700181
Lee Leahyb5ad8272015-04-20 15:29:16 -0700182static void fsp_notify_boot_state_callback(void *arg)
Lee Leahy3dad4892015-05-05 11:14:02 -0700183{
Lee Leahyb5ad8272015-04-20 15:29:16 -0700184 u32 phase = (u32)arg;
Lee Leahy3dad4892015-05-05 11:14:02 -0700185
Lee Leahyb5ad8272015-04-20 15:29:16 -0700186 printk(BIOS_SPEW, "Calling FspNotify(0x%08x)\n", phase);
187 fsp_notify(phase);
Lee Leahy3dad4892015-05-05 11:14:02 -0700188}
189
Lee Leahyb5ad8272015-04-20 15:29:16 -0700190BOOT_STATE_INIT_ENTRY(BS_DEV_RESOURCES, BS_ON_EXIT,
191 fsp_notify_boot_state_callback,
192 (void *)EnumInitPhaseAfterPciEnumeration);
193BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_EXIT,
194 fsp_notify_boot_state_callback,
195 (void *)EnumInitPhaseReadyToBoot);
196BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY,
197 fsp_notify_boot_state_callback,
198 (void *)EnumInitPhaseReadyToBoot);
199
Lee Leahyb5ad8272015-04-20 15:29:16 -0700200struct fsp_runtime {
201 uint32_t fih;
202 uint32_t hob_list;
203} __attribute__((packed));
204
205
206void fsp_set_runtime(FSP_INFO_HEADER *fih, void *hob_list)
Lee Leahy3dad4892015-05-05 11:14:02 -0700207{
Lee Leahyb5ad8272015-04-20 15:29:16 -0700208 struct fsp_runtime *fspr;
209
210 fspr = cbmem_add(CBMEM_ID_FSP_RUNTIME, sizeof(*fspr));
211
212 if (fspr == NULL)
213 die("Can't save FSP runtime information.\n");
214
215 fspr->fih = (uintptr_t)fih;
216 fspr->hob_list = (uintptr_t)hob_list;
Lee Leahy3dad4892015-05-05 11:14:02 -0700217}
218
Lee Leahyb5ad8272015-04-20 15:29:16 -0700219FSP_INFO_HEADER *fsp_get_fih(void)
Lee Leahy3dad4892015-05-05 11:14:02 -0700220{
Lee Leahyb5ad8272015-04-20 15:29:16 -0700221 struct fsp_runtime *fspr;
222
223 fspr = cbmem_find(CBMEM_ID_FSP_RUNTIME);
224
225 if (fspr == NULL)
226 return NULL;
227
228 return (void *)(uintptr_t)fspr->fih;
Lee Leahy3dad4892015-05-05 11:14:02 -0700229}
230
Lee Leahyb5ad8272015-04-20 15:29:16 -0700231void *fsp_get_hob_list(void)
232{
233 struct fsp_runtime *fspr;
Lee Leahy3dad4892015-05-05 11:14:02 -0700234
Lee Leahyb5ad8272015-04-20 15:29:16 -0700235 fspr = cbmem_find(CBMEM_ID_FSP_RUNTIME);
236
237 if (fspr == NULL)
238 return NULL;
239
240 return (void *)(uintptr_t)fspr->hob_list;
241}
242
243void fsp_update_fih(FSP_INFO_HEADER *fih)
244{
245 struct fsp_runtime *fspr;
246
247 fspr = cbmem_find(CBMEM_ID_FSP_RUNTIME);
248
249 if (fspr == NULL)
250 die("Can't update FSP runtime information.\n");
251
252 fspr->fih = (uintptr_t)fih;
253}
Lee Leahy94b856e2015-10-15 12:07:03 -0700254
Lee Leahy66208bd2015-10-15 16:17:58 -0700255void fsp_display_upd_value(const char *name, uint32_t size, uint64_t old,
Lee Leahy94b856e2015-10-15 12:07:03 -0700256 uint64_t new)
257{
258 if (old == new) {
259 switch (size) {
260 case 1:
261 printk(BIOS_SPEW, " 0x%02llx: %s\n", new, name);
262 break;
263
264 case 2:
265 printk(BIOS_SPEW, " 0x%04llx: %s\n", new, name);
266 break;
267
268 case 4:
269 printk(BIOS_SPEW, " 0x%08llx: %s\n", new, name);
270 break;
271
272 case 8:
273 printk(BIOS_SPEW, " 0x%016llx: %s\n", new, name);
274 break;
275 }
276 } else {
277 switch (size) {
278 case 1:
279 printk(BIOS_SPEW, " 0x%02llx --> 0x%02llx: %s\n", old,
280 new, name);
281 break;
282
283 case 2:
284 printk(BIOS_SPEW, " 0x%04llx --> 0x%04llx: %s\n", old,
285 new, name);
286 break;
287
288 case 4:
289 printk(BIOS_SPEW, " 0x%08llx --> 0x%08llx: %s\n", old,
290 new, name);
291 break;
292
293 case 8:
294 printk(BIOS_SPEW, " 0x%016llx --> 0x%016llx: %s\n",
295 old, new, name);
296 break;
297 }
298 }
299}