blob: 0e6a39f0ee7e26aad7e6c10e22536f7d0e7c3b8e [file] [log] [blame]
Patrick Georgiac959032020-05-05 22:49:26 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Alexandru Gagniuc9b2e9bd2016-02-25 14:20:38 -08002
Kyösti Mälkki13f66502019-03-03 08:01:05 +02003#include <device/mmio.h>
Alexandru Gagniuc9b2e9bd2016-02-25 14:20:38 -08004#include <cbmem.h>
5#include <commonlib/helpers.h>
6#include <console/console.h>
Subrata Banik73b67dc2018-01-23 16:31:03 +05307#include <fsp/api.h>
Alexandru Gagniuc9b2e9bd2016-02-25 14:20:38 -08008#include <fsp/util.h>
Jacob Garber5cf9ccc2019-08-08 13:35:31 -06009#include <stdint.h>
Alexandru Gagniuc9b2e9bd2016-02-25 14:20:38 -080010#include <string.h>
11
12#define HOB_HEADER_LEN 8
13
Lee Leahyac3b0a62016-07-27 07:40:25 -070014/* GUIDs in little-endian, so they can be used with memcmp() */
Lee Leahy52d0c682016-08-01 15:47:42 -070015const uint8_t fsp_bootloader_tolum_guid[16] = {
16 0x56, 0x4f, 0xff, 0x73, 0x8e, 0xaa, 0x51, 0x44,
17 0xb3, 0x16, 0x36, 0x35, 0x36, 0x67, 0xad, 0x44,
18};
19
Lee Leahyac3b0a62016-07-27 07:40:25 -070020const uint8_t fsp_reserved_memory_guid[16] = {
Alexandru Gagniuc9b2e9bd2016-02-25 14:20:38 -080021 0x59, 0x97, 0xa7, 0x69, 0x73, 0x13, 0x67, 0x43,
22 0xa6, 0xc4, 0xc7, 0xf5, 0x9e, 0xfd, 0x98, 0x6e,
23};
24
Anil Kumar0dd03682021-11-24 14:31:04 -080025const uint8_t fsp_nv_storage_guid_2[16] = {
26 0x8f, 0x78, 0x66, 0x48, 0xa8, 0x6b, 0xd8, 0x47,
27 0x83, 0x6, 0xac, 0xf7, 0x7f, 0x55, 0x10, 0x46
28};
29
Lee Leahyac3b0a62016-07-27 07:40:25 -070030const uint8_t fsp_nv_storage_guid[16] = {
Ravi Sarawadi98e0ee62016-08-17 23:39:37 -070031 0x02, 0xcf, 0x1a, 0x72, 0x77, 0x4d, 0x2a, 0x4c,
32 0xb3, 0xdc, 0x27, 0x0b, 0x7b, 0xa9, 0xe4, 0xb0
33};
34
Ray Han Lim, Ng65b72192022-01-21 14:33:11 +080035const uint8_t fsp_error_info_guid[16] = {
36 0x88, 0x6a, 0x1e, 0x61, 0xb7, 0xad, 0x01, 0x43,
37 0x93, 0xff, 0xe4, 0x73, 0x04, 0xb4, 0x3d, 0xa6
38};
39
Subrata Banik73b67dc2018-01-23 16:31:03 +053040static const uint8_t uuid_fv_info[16] = {
41 0x2e, 0x72, 0x8e, 0x79, 0xb2, 0x15, 0x13, 0x4e,
42 0x8a, 0xe9, 0x6b, 0xa3, 0x0f, 0xf7, 0xf1, 0x67
43};
44
Alexandru Gagniuc9b2e9bd2016-02-25 14:20:38 -080045/*
46 * Utilities for walking HOBs
47 */
48
Lee Leahyac3b0a62016-07-27 07:40:25 -070049bool fsp_guid_compare(const uint8_t guid1[16], const uint8_t guid2[16])
Alexandru Gagniuc9b2e9bd2016-02-25 14:20:38 -080050{
Lee Leahyac3b0a62016-07-27 07:40:25 -070051 return !memcmp(guid1, guid2, 16);
Alexandru Gagniuc9b2e9bd2016-02-25 14:20:38 -080052}
53
Lee Leahyac3b0a62016-07-27 07:40:25 -070054const struct hob_header *fsp_next_hob(const struct hob_header *parent)
Alexandru Gagniuc9b2e9bd2016-02-25 14:20:38 -080055{
56 union {
57 const struct hob_header *hob;
58 uintptr_t addr;
59 } hob_walker;
60
61 hob_walker.hob = parent;
62 hob_walker.addr += parent->length;
63 return hob_walker.hob;
64}
65
66static const void *hob_header_to_struct(const struct hob_header *hob)
67{
68 union {
69 const struct hob_header *hob_hdr;
70 const void *hob_descr;
71 uintptr_t addr;
72 } hob_walker;
73
74 hob_walker.hob_hdr = hob;
75 hob_walker.addr += HOB_HEADER_LEN;
76 return hob_walker.hob_descr;
77}
78
79static const void *hob_header_to_extension_hob(const struct hob_header *hob)
80{
81 union {
82 const struct hob_header *hob_hdr;
83 const void *hob_descr;
84 uintptr_t addr;
85 } hob_walker;
86
87 hob_walker.hob_hdr = hob;
Lee Leahyac3b0a62016-07-27 07:40:25 -070088 hob_walker.addr += HOB_HEADER_LEN + 16; /* header and 16-byte GUID */
Alexandru Gagniuc9b2e9bd2016-02-25 14:20:38 -080089 return hob_walker.hob_descr;
90}
91
Lee Leahyac3b0a62016-07-27 07:40:25 -070092const
93struct hob_resource *fsp_hob_header_to_resource(const struct hob_header *hob)
Alexandru Gagniuc9b2e9bd2016-02-25 14:20:38 -080094{
95 return hob_header_to_struct(hob);
96}
97
98/*
99 * Utilities for locating and identifying HOBs
100 */
101
Arthur Heymans75c20152019-05-25 10:37:26 +0200102static void *fsp_hob_list_ptr;
Lee Leahyac3b0a62016-07-27 07:40:25 -0700103
104static void save_hob_list(int is_recovery)
Alexandru Gagniuc9b2e9bd2016-02-25 14:20:38 -0800105{
Aaron Durbina3a06ae2016-07-16 17:29:47 -0500106 uint32_t *cbmem_loc;
Subrata Banik097bd952017-07-24 19:09:31 +0530107 const void *hob_list;
Aaron Durbina3a06ae2016-07-16 17:29:47 -0500108 cbmem_loc = cbmem_add(CBMEM_ID_FSP_RUNTIME, sizeof(*cbmem_loc));
Martin Roth53bd26f2016-11-18 12:02:18 -0700109 if (cbmem_loc == NULL)
110 die("Error: Could not add cbmem area for hob list.\n");
Subrata Banik097bd952017-07-24 19:09:31 +0530111 hob_list = fsp_get_hob_list();
112 if (!hob_list)
113 die("Error: Could not locate hob list pointer.\n");
114 *cbmem_loc = (uintptr_t)hob_list;
Alexandru Gagniuc9b2e9bd2016-02-25 14:20:38 -0800115}
116
Kyösti Mälkkifa3bc042022-03-31 07:40:10 +0300117CBMEM_CREATION_HOOK(save_hob_list);
Lee Leahyac3b0a62016-07-27 07:40:25 -0700118
Alexandru Gagniuc9b2e9bd2016-02-25 14:20:38 -0800119const void *fsp_get_hob_list(void)
120{
Lee Leahyac3b0a62016-07-27 07:40:25 -0700121 uint32_t *list_loc;
Alexandru Gagniuc9b2e9bd2016-02-25 14:20:38 -0800122
Kyösti Mälkki11cac782022-04-07 07:16:48 +0300123 if (ENV_RAMINIT)
Arthur Heymans75c20152019-05-25 10:37:26 +0200124 return fsp_hob_list_ptr;
Lee Leahyac3b0a62016-07-27 07:40:25 -0700125 list_loc = cbmem_find(CBMEM_ID_FSP_RUNTIME);
Aaron Durbina3a06ae2016-07-16 17:29:47 -0500126 return (list_loc) ? (void *)(uintptr_t)(*list_loc) : NULL;
Alexandru Gagniuc9b2e9bd2016-02-25 14:20:38 -0800127}
128
Lee Leahyac3b0a62016-07-27 07:40:25 -0700129void *fsp_get_hob_list_ptr(void)
130{
Arthur Heymans75c20152019-05-25 10:37:26 +0200131 return &fsp_hob_list_ptr;
Lee Leahyac3b0a62016-07-27 07:40:25 -0700132}
133
Felix Held79db9872022-11-09 16:09:17 +0100134enum cb_err fsp_hob_iterator_init(const struct hob_header **hob_iterator)
135{
136 *hob_iterator = fsp_get_hob_list();
137 return *hob_iterator ? CB_SUCCESS : CB_ERR;
138}
139
140static enum cb_err fsp_hob_iterator_get_next(const struct hob_header **hob_iterator,
141 uint16_t hob_type,
142 const struct hob_header **hob)
143{
144 const struct hob_header *current_hob;
145 while ((*hob_iterator)->type != HOB_TYPE_END_OF_HOB_LIST) {
146 current_hob = *hob_iterator;
147 *hob_iterator = fsp_next_hob(*hob_iterator);
148 if (current_hob->type == hob_type) {
149 *hob = current_hob;
150 return CB_SUCCESS;
151 }
152 }
153 return CB_ERR;
154}
155
156enum cb_err fsp_hob_iterator_get_next_resource(const struct hob_header **hob_iterator,
157 const struct hob_resource **res)
158{
159 const struct hob_header *hob;
160 while (fsp_hob_iterator_get_next(hob_iterator, HOB_TYPE_RESOURCE_DESCRIPTOR, &hob) == CB_SUCCESS) {
161 *res = fsp_hob_header_to_resource(hob);
162 return CB_SUCCESS;
163 }
164 return CB_ERR;
165}
166
167enum cb_err fsp_hob_iterator_get_next_guid_resource(const struct hob_header **hob_iterator,
168 const uint8_t guid[16],
169 const struct hob_resource **res)
170{
171 const struct hob_resource *res_hob;
172 while (fsp_hob_iterator_get_next_resource(hob_iterator, &res_hob) == CB_SUCCESS) {
173 if (fsp_guid_compare(res_hob->owner_guid, guid)) {
174 *res = res_hob;
175 return CB_SUCCESS;
176 }
177 }
178 return CB_ERR;
179}
180
181enum cb_err fsp_hob_iterator_get_next_guid_extension(const struct hob_header **hob_iterator,
182 const uint8_t guid[16],
183 const void **data, size_t *size)
184{
185 const struct hob_header *hob;
186 const uint8_t *guid_hob;
187 while (fsp_hob_iterator_get_next(hob_iterator, HOB_TYPE_GUID_EXTENSION, &hob) == CB_SUCCESS) {
188 guid_hob = hob_header_to_struct(hob);
189 if (fsp_guid_compare(guid_hob, guid)) {
190 *size = hob->length - (HOB_HEADER_LEN + 16);
191 *data = hob_header_to_extension_hob(hob);
192 return CB_SUCCESS;
193 }
194 }
195 return CB_ERR;
196}
197
Felix Held50c0a6d2022-11-14 22:11:56 +0100198void fsp_print_guid(int level, const void *base)
Lee Leahy52d0c682016-08-01 15:47:42 -0700199{
200 uint32_t big;
201 uint16_t mid[2];
202
203 const uint8_t *id = base;
204 big = read32(id + 0);
205 mid[0] = read16(id + 4);
206 mid[1] = read16(id + 6);
207
Subrata Banik79158842023-04-26 13:41:43 +0530208 printk(level, "%08x-%04x-%04x-%02x%02x%02x%02x%02x%02x%02x%02x\n",
Lee Leahy52d0c682016-08-01 15:47:42 -0700209 big, mid[0], mid[1],
210 id[8], id[9], id[10], id[11], id[12], id[13], id[14], id[15]);
211}
212
Felix Held1aa094a2023-03-29 15:58:36 +0200213enum cb_err fsp_find_range_hob(struct range_entry *re, const uint8_t guid[16])
Alexandru Gagniuc9b2e9bd2016-02-25 14:20:38 -0800214{
Felix Held25169472022-11-12 01:42:39 +0100215 const struct hob_header *hob_iterator;
Alexandru Gagniuc9b2e9bd2016-02-25 14:20:38 -0800216 const struct hob_resource *fsp_mem;
217
Felix Held25169472022-11-12 01:42:39 +0100218 if (fsp_hob_iterator_init(&hob_iterator) != CB_SUCCESS)
Felix Held1aa094a2023-03-29 15:58:36 +0200219 return CB_ERR;
Subrata Banik097bd952017-07-24 19:09:31 +0530220
Aaron Durbin0fcd6f92016-03-08 11:23:52 -0600221 range_entry_init(re, 0, 0, 0);
Alexandru Gagniuc9b2e9bd2016-02-25 14:20:38 -0800222
Felix Held25169472022-11-12 01:42:39 +0100223 if (fsp_hob_iterator_get_next_guid_resource(&hob_iterator, guid, &fsp_mem) != CB_SUCCESS) {
Felix Held50c0a6d2022-11-14 22:11:56 +0100224 fsp_print_guid(BIOS_SPEW, guid);
Lee Leahy52d0c682016-08-01 15:47:42 -0700225 printk(BIOS_SPEW, " not found!\n");
Felix Held1aa094a2023-03-29 15:58:36 +0200226 return CB_ERR;
Alexandru Gagniuc9b2e9bd2016-02-25 14:20:38 -0800227 }
228
Aaron Durbin0fcd6f92016-03-08 11:23:52 -0600229 range_entry_init(re, fsp_mem->addr, fsp_mem->addr + fsp_mem->length, 0);
Felix Held1aa094a2023-03-29 15:58:36 +0200230 return CB_SUCCESS;
Lee Leahy52d0c682016-08-01 15:47:42 -0700231}
232
Michael Niewöhnerbc1dbb32019-10-24 22:58:25 +0200233void fsp_find_reserved_memory(struct range_entry *re)
Lee Leahy52d0c682016-08-01 15:47:42 -0700234{
Felix Held1aa094a2023-03-29 15:58:36 +0200235 if (fsp_find_range_hob(re, fsp_reserved_memory_guid) != CB_SUCCESS)
Michael Niewöhnerbc1dbb32019-10-24 22:58:25 +0200236 die("9.1: FSP_RESERVED_MEMORY_RESOURCE_HOB missing!\n");
Alexandru Gagniuc9b2e9bd2016-02-25 14:20:38 -0800237}
238
Lee Leahyac3b0a62016-07-27 07:40:25 -0700239const void *fsp_find_extension_hob_by_guid(const uint8_t *guid, size_t *size)
Alexandru Gagniuc9b2e9bd2016-02-25 14:20:38 -0800240{
Felix Helde2949b72022-11-12 01:52:52 +0100241 const struct hob_header *hob_iterator;
242 const void *hob_guid;
Alexandru Gagniuc9b2e9bd2016-02-25 14:20:38 -0800243
Felix Helde2949b72022-11-12 01:52:52 +0100244 if (fsp_hob_iterator_init(&hob_iterator) != CB_SUCCESS)
Alexandru Gagniuc9b2e9bd2016-02-25 14:20:38 -0800245 return NULL;
246
Felix Helde2949b72022-11-12 01:52:52 +0100247 if (fsp_hob_iterator_get_next_guid_extension(&hob_iterator, guid, &hob_guid, size) == CB_SUCCESS)
248 return hob_guid;
Alexandru Gagniuc9b2e9bd2016-02-25 14:20:38 -0800249
250 return NULL;
251}
Hannah Williams3503b3f2016-03-04 12:14:52 -0800252
Pratikkumar Prajapatif5f756d2023-02-01 17:25:07 -0800253const void *fsp_find_resource_hob_by_guid(const uint8_t *guid)
254{
255 const struct hob_header *hob_iterator;
256 const struct hob_resource *res_hob;
257
258 if (fsp_hob_iterator_init(&hob_iterator) != CB_SUCCESS)
259 return NULL;
260
261 if (fsp_hob_iterator_get_next_guid_resource(&hob_iterator, guid, &res_hob) == CB_SUCCESS)
262 return res_hob;
263
264 return NULL;
265}
266
Elyes HAOUAS83b62832020-08-07 15:28:51 +0200267static void display_fsp_version_info_hob(const void *hob)
Subrata Banik73b67dc2018-01-23 16:31:03 +0530268{
Ronak Kanabarc7762462020-10-01 19:22:51 +0530269#if CONFIG(DISPLAY_FSP_VERSION_INFO) || CONFIG(DISPLAY_FSP_VERSION_INFO_2)
270
271 int index, cnt, tcount;
272 char *str_ptr;
273 uint8_t vs;
Julius Wernercd49cce2019-03-05 16:53:33 -0800274#if CONFIG(DISPLAY_FSP_VERSION_INFO)
Subrata Banik73b67dc2018-01-23 16:31:03 +0530275 const FIRMWARE_VERSION_INFO *fvi;
Felix Held9405dd02022-11-08 21:14:34 +0100276 const FIRMWARE_VERSION_INFO_HOB *fvih = (FIRMWARE_VERSION_INFO_HOB *)hob;
Subrata Banik73b67dc2018-01-23 16:31:03 +0530277
278 fvi = (void *)&fvih[1];
Felix Held9405dd02022-11-08 21:14:34 +0100279 str_ptr = (char *)((uintptr_t)fvi + (fvih->Count * sizeof(FIRMWARE_VERSION_INFO)));
Ronak Kanabarc7762462020-10-01 19:22:51 +0530280 tcount = fvih->Count;
281#elif CONFIG(DISPLAY_FSP_VERSION_INFO_2)
Subrata Banik73b67dc2018-01-23 16:31:03 +0530282
Elyes Haouas1ef547e2022-11-18 15:05:39 +0100283 uint8_t *hobstart = (uint8_t *)hob;
Ronak Kanabarc7762462020-10-01 19:22:51 +0530284 hobstart += sizeof(EFI_HOB_GUID_TYPE);
285
286 const SMBIOS_TABLE_TYPE_OEM_INTEL_FVI *stfvi =
287 (SMBIOS_TABLE_TYPE_OEM_INTEL_FVI *)hobstart;
288 const INTEL_FIRMWARE_VERSION_INFO *fvi;
289
Elyes Haouas1ef547e2022-11-18 15:05:39 +0100290 str_ptr = ((char *)&(stfvi->Fvi[0])) +
Ronak Kanabarc7762462020-10-01 19:22:51 +0530291 (stfvi->Count * sizeof(INTEL_FIRMWARE_VERSION_INFO));
292 tcount = stfvi->Count;
293 fvi = &stfvi->Fvi[0];
294#endif
295
296 for (index = 0; index < tcount; index++) {
Subrata Banik73b67dc2018-01-23 16:31:03 +0530297 cnt = strlen(str_ptr);
298
Ronak Kanabarc7762462020-10-01 19:22:51 +0530299#if CONFIG(DISPLAY_FSP_VERSION_INFO)
300 vs = fvi[index].VersionStringIndex;
301#elif CONFIG(DISPLAY_FSP_VERSION_INFO_2)
302 vs = fvi[index].VersionString;
303#endif
Subrata Banik73b67dc2018-01-23 16:31:03 +0530304 /* Don't show ingredient name and version if its all 0xFF */
305 if (fvi[index].Version.MajorVersion == 0xFF &&
Elyes HAOUAS365cb142019-05-19 23:31:48 +0200306 fvi[index].Version.MinorVersion == 0xFF &&
307 fvi[index].Version.Revision == 0xFF &&
308 fvi[index].Version.BuildNumber == 0xFF &&
Ronak Kanabarc7762462020-10-01 19:22:51 +0530309 vs == 0) {
Felix Held9405dd02022-11-08 21:14:34 +0100310 str_ptr = (char *)((uintptr_t)str_ptr + cnt + sizeof(uint8_t));
Subrata Banik73b67dc2018-01-23 16:31:03 +0530311 continue;
312 }
313 /*
Elyes HAOUAS8bffebe2018-05-27 22:45:31 +0200314 * Firmware Version String consist of 2 pieces of information
Subrata Banik73b67dc2018-01-23 16:31:03 +0530315 * 1. Component Name: string type data holds FW type name.
316 * 2. Version Information : Either a string type data or
317 * numeric field holds FW version information.
318 */
319 printk(BIOS_DEBUG, "%s = ", str_ptr);
320
Ronak Kanabarc7762462020-10-01 19:22:51 +0530321 if (!vs)
Subrata Banik73b67dc2018-01-23 16:31:03 +0530322 printk(BIOS_DEBUG, "%x.%x.%x.%x\n",
323 fvi[index].Version.MajorVersion,
324 fvi[index].Version.MinorVersion,
325 fvi[index].Version.Revision,
326 fvi[index].Version.BuildNumber);
327 else {
Felix Held9405dd02022-11-08 21:14:34 +0100328 str_ptr = (char *)((uintptr_t)str_ptr + cnt + sizeof(uint8_t));
Subrata Banik73b67dc2018-01-23 16:31:03 +0530329 cnt = strlen(str_ptr);
330 printk(BIOS_DEBUG, "%s\n", str_ptr);
331 }
Felix Held9405dd02022-11-08 21:14:34 +0100332 str_ptr = (char *)((uintptr_t)str_ptr + cnt + sizeof(uint8_t));
Subrata Banik73b67dc2018-01-23 16:31:03 +0530333 }
334#endif
335}
336
337void fsp_display_fvi_version_hob(void)
338{
339 const uint8_t *hob_uuid;
340 const struct hob_header *hob = fsp_get_hob_list();
Subrata Banik73b67dc2018-01-23 16:31:03 +0530341
342 if (!hob)
343 return;
344
Subrata Banik90557f42020-03-25 18:40:41 +0530345 printk(BIOS_DEBUG, "Display FSP Version Info HOB\n");
Felix Held9405dd02022-11-08 21:14:34 +0100346 for (; hob->type != HOB_TYPE_END_OF_HOB_LIST; hob = fsp_next_hob(hob)) {
Subrata Banik73b67dc2018-01-23 16:31:03 +0530347 if (hob->type != HOB_TYPE_GUID_EXTENSION)
348 continue;
349
350 hob_uuid = hob_header_to_struct(hob);
351
352 if (fsp_guid_compare(hob_uuid, uuid_fv_info)) {
Elyes HAOUAS83b62832020-08-07 15:28:51 +0200353 display_fsp_version_info_hob(hob);
Subrata Banik73b67dc2018-01-23 16:31:03 +0530354 }
355 }
356}
357
Hannah Williams3503b3f2016-03-04 12:14:52 -0800358const void *fsp_find_nv_storage_data(size_t *size)
359{
Anil Kumar0dd03682021-11-24 14:31:04 -0800360 if (CONFIG(PLATFORM_USES_FSP2_3)) {
361 const struct fsp_nvs_hob2_data_region_header *hob;
362
363 hob = (const struct fsp_nvs_hob2_data_region_header *)
364 fsp_find_extension_hob_by_guid(fsp_nv_storage_guid_2, size);
365 if (hob != NULL) {
366 *size = hob->nvs_data_length;
367 return (void *)(uintptr_t)hob->nvs_data_ptr;
368 }
369 }
Lee Leahyac3b0a62016-07-27 07:40:25 -0700370 return fsp_find_extension_hob_by_guid(fsp_nv_storage_guid, size);
Hannah Williams3503b3f2016-03-04 12:14:52 -0800371}
Michael Niewöhner68da4542019-10-19 11:57:05 +0200372
373void fsp_find_bootloader_tolum(struct range_entry *re)
374{
Felix Held1aa094a2023-03-29 15:58:36 +0200375 if (fsp_find_range_hob(re, fsp_bootloader_tolum_guid) != CB_SUCCESS)
Michael Niewöhner68da4542019-10-19 11:57:05 +0200376 die("9.3: FSP_BOOTLOADER_TOLUM_HOB missing!\n");
377}
Ray Han Lim, Ng65b72192022-01-21 14:33:11 +0800378
379bool fsp_display_error_info(void)
380{
381 if (!CONFIG(ENABLE_FSP_ERROR_INFO))
382 return false;
383
384 const struct hob_header *hob;
385 size_t size;
386
387 hob = (const struct hob_header *)fsp_find_extension_hob_by_guid(
388 fsp_error_info_guid, &size);
389 if (hob != NULL) {
390 display_fsp_error_info_hob(hob);
391 return true;
392 }
393
394 return false;
395}