blob: 2738c789880094987e81d908be580ddd62348cdd [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
Subrata Banik73b67dc2018-01-23 16:31:03 +053035static const uint8_t uuid_fv_info[16] = {
36 0x2e, 0x72, 0x8e, 0x79, 0xb2, 0x15, 0x13, 0x4e,
37 0x8a, 0xe9, 0x6b, 0xa3, 0x0f, 0xf7, 0xf1, 0x67
38};
39
Alexandru Gagniuc9b2e9bd2016-02-25 14:20:38 -080040/*
41 * Utilities for walking HOBs
42 */
43
Lee Leahyac3b0a62016-07-27 07:40:25 -070044bool fsp_guid_compare(const uint8_t guid1[16], const uint8_t guid2[16])
Alexandru Gagniuc9b2e9bd2016-02-25 14:20:38 -080045{
Lee Leahyac3b0a62016-07-27 07:40:25 -070046 return !memcmp(guid1, guid2, 16);
Alexandru Gagniuc9b2e9bd2016-02-25 14:20:38 -080047}
48
Lee Leahyac3b0a62016-07-27 07:40:25 -070049const struct hob_header *fsp_next_hob(const struct hob_header *parent)
Alexandru Gagniuc9b2e9bd2016-02-25 14:20:38 -080050{
51 union {
52 const struct hob_header *hob;
53 uintptr_t addr;
54 } hob_walker;
55
56 hob_walker.hob = parent;
57 hob_walker.addr += parent->length;
58 return hob_walker.hob;
59}
60
61static const void *hob_header_to_struct(const struct hob_header *hob)
62{
63 union {
64 const struct hob_header *hob_hdr;
65 const void *hob_descr;
66 uintptr_t addr;
67 } hob_walker;
68
69 hob_walker.hob_hdr = hob;
70 hob_walker.addr += HOB_HEADER_LEN;
71 return hob_walker.hob_descr;
72}
73
74static const void *hob_header_to_extension_hob(const struct hob_header *hob)
75{
76 union {
77 const struct hob_header *hob_hdr;
78 const void *hob_descr;
79 uintptr_t addr;
80 } hob_walker;
81
82 hob_walker.hob_hdr = hob;
Lee Leahyac3b0a62016-07-27 07:40:25 -070083 hob_walker.addr += HOB_HEADER_LEN + 16; /* header and 16-byte GUID */
Alexandru Gagniuc9b2e9bd2016-02-25 14:20:38 -080084 return hob_walker.hob_descr;
85}
86
Lee Leahyac3b0a62016-07-27 07:40:25 -070087const
88struct hob_resource *fsp_hob_header_to_resource(const struct hob_header *hob)
Alexandru Gagniuc9b2e9bd2016-02-25 14:20:38 -080089{
90 return hob_header_to_struct(hob);
91}
92
93/*
94 * Utilities for locating and identifying HOBs
95 */
96
Arthur Heymans75c20152019-05-25 10:37:26 +020097static void *fsp_hob_list_ptr;
Lee Leahyac3b0a62016-07-27 07:40:25 -070098
99static void save_hob_list(int is_recovery)
Alexandru Gagniuc9b2e9bd2016-02-25 14:20:38 -0800100{
Aaron Durbina3a06ae2016-07-16 17:29:47 -0500101 uint32_t *cbmem_loc;
Subrata Banik097bd952017-07-24 19:09:31 +0530102 const void *hob_list;
Aaron Durbina3a06ae2016-07-16 17:29:47 -0500103 cbmem_loc = cbmem_add(CBMEM_ID_FSP_RUNTIME, sizeof(*cbmem_loc));
Martin Roth53bd26f2016-11-18 12:02:18 -0700104 if (cbmem_loc == NULL)
105 die("Error: Could not add cbmem area for hob list.\n");
Subrata Banik097bd952017-07-24 19:09:31 +0530106 hob_list = fsp_get_hob_list();
107 if (!hob_list)
108 die("Error: Could not locate hob list pointer.\n");
109 *cbmem_loc = (uintptr_t)hob_list;
Alexandru Gagniuc9b2e9bd2016-02-25 14:20:38 -0800110}
111
Kyösti Mälkkifa3bc042022-03-31 07:40:10 +0300112CBMEM_CREATION_HOOK(save_hob_list);
Lee Leahyac3b0a62016-07-27 07:40:25 -0700113
Alexandru Gagniuc9b2e9bd2016-02-25 14:20:38 -0800114const void *fsp_get_hob_list(void)
115{
Lee Leahyac3b0a62016-07-27 07:40:25 -0700116 uint32_t *list_loc;
Alexandru Gagniuc9b2e9bd2016-02-25 14:20:38 -0800117
Kyösti Mälkki11cac782022-04-07 07:16:48 +0300118 if (ENV_RAMINIT)
Arthur Heymans75c20152019-05-25 10:37:26 +0200119 return fsp_hob_list_ptr;
Lee Leahyac3b0a62016-07-27 07:40:25 -0700120 list_loc = cbmem_find(CBMEM_ID_FSP_RUNTIME);
Aaron Durbina3a06ae2016-07-16 17:29:47 -0500121 return (list_loc) ? (void *)(uintptr_t)(*list_loc) : NULL;
Alexandru Gagniuc9b2e9bd2016-02-25 14:20:38 -0800122}
123
Lee Leahyac3b0a62016-07-27 07:40:25 -0700124void *fsp_get_hob_list_ptr(void)
125{
Arthur Heymans75c20152019-05-25 10:37:26 +0200126 return &fsp_hob_list_ptr;
Lee Leahyac3b0a62016-07-27 07:40:25 -0700127}
128
Felix Held79db9872022-11-09 16:09:17 +0100129enum cb_err fsp_hob_iterator_init(const struct hob_header **hob_iterator)
130{
131 *hob_iterator = fsp_get_hob_list();
132 return *hob_iterator ? CB_SUCCESS : CB_ERR;
133}
134
135static enum cb_err fsp_hob_iterator_get_next(const struct hob_header **hob_iterator,
136 uint16_t hob_type,
137 const struct hob_header **hob)
138{
139 const struct hob_header *current_hob;
140 while ((*hob_iterator)->type != HOB_TYPE_END_OF_HOB_LIST) {
141 current_hob = *hob_iterator;
142 *hob_iterator = fsp_next_hob(*hob_iterator);
143 if (current_hob->type == hob_type) {
144 *hob = current_hob;
145 return CB_SUCCESS;
146 }
147 }
148 return CB_ERR;
149}
150
151enum cb_err fsp_hob_iterator_get_next_resource(const struct hob_header **hob_iterator,
152 const struct hob_resource **res)
153{
154 const struct hob_header *hob;
155 while (fsp_hob_iterator_get_next(hob_iterator, HOB_TYPE_RESOURCE_DESCRIPTOR, &hob) == CB_SUCCESS) {
156 *res = fsp_hob_header_to_resource(hob);
157 return CB_SUCCESS;
158 }
159 return CB_ERR;
160}
161
162enum cb_err fsp_hob_iterator_get_next_guid_resource(const struct hob_header **hob_iterator,
163 const uint8_t guid[16],
164 const struct hob_resource **res)
165{
166 const struct hob_resource *res_hob;
167 while (fsp_hob_iterator_get_next_resource(hob_iterator, &res_hob) == CB_SUCCESS) {
168 if (fsp_guid_compare(res_hob->owner_guid, guid)) {
169 *res = res_hob;
170 return CB_SUCCESS;
171 }
172 }
173 return CB_ERR;
174}
175
176enum cb_err fsp_hob_iterator_get_next_guid_extension(const struct hob_header **hob_iterator,
177 const uint8_t guid[16],
178 const void **data, size_t *size)
179{
180 const struct hob_header *hob;
181 const uint8_t *guid_hob;
182 while (fsp_hob_iterator_get_next(hob_iterator, HOB_TYPE_GUID_EXTENSION, &hob) == CB_SUCCESS) {
183 guid_hob = hob_header_to_struct(hob);
184 if (fsp_guid_compare(guid_hob, guid)) {
185 *size = hob->length - (HOB_HEADER_LEN + 16);
186 *data = hob_header_to_extension_hob(hob);
187 return CB_SUCCESS;
188 }
189 }
190 return CB_ERR;
191}
192
Lee Leahy52d0c682016-08-01 15:47:42 -0700193void fsp_print_guid(const void *base)
194{
195 uint32_t big;
196 uint16_t mid[2];
197
198 const uint8_t *id = base;
199 big = read32(id + 0);
200 mid[0] = read16(id + 4);
201 mid[1] = read16(id + 6);
202
203 printk(BIOS_SPEW, "%08x-%04x-%04x-%02x%02x%02x%02x%02x%02x%02x%02x",
204 big, mid[0], mid[1],
205 id[8], id[9], id[10], id[11], id[12], id[13], id[14], id[15]);
206}
207
208int fsp_find_range_hob(struct range_entry *re, const uint8_t guid[16])
Alexandru Gagniuc9b2e9bd2016-02-25 14:20:38 -0800209{
Felix Held25169472022-11-12 01:42:39 +0100210 const struct hob_header *hob_iterator;
Alexandru Gagniuc9b2e9bd2016-02-25 14:20:38 -0800211 const struct hob_resource *fsp_mem;
212
Felix Held25169472022-11-12 01:42:39 +0100213 if (fsp_hob_iterator_init(&hob_iterator) != CB_SUCCESS)
Subrata Banik097bd952017-07-24 19:09:31 +0530214 return -1;
215
Aaron Durbin0fcd6f92016-03-08 11:23:52 -0600216 range_entry_init(re, 0, 0, 0);
Alexandru Gagniuc9b2e9bd2016-02-25 14:20:38 -0800217
Felix Held25169472022-11-12 01:42:39 +0100218 if (fsp_hob_iterator_get_next_guid_resource(&hob_iterator, guid, &fsp_mem) != CB_SUCCESS) {
Lee Leahy52d0c682016-08-01 15:47:42 -0700219 fsp_print_guid(guid);
220 printk(BIOS_SPEW, " not found!\n");
221 return -1;
Alexandru Gagniuc9b2e9bd2016-02-25 14:20:38 -0800222 }
223
Aaron Durbin0fcd6f92016-03-08 11:23:52 -0600224 range_entry_init(re, fsp_mem->addr, fsp_mem->addr + fsp_mem->length, 0);
Lee Leahy52d0c682016-08-01 15:47:42 -0700225 return 0;
226}
227
Michael Niewöhnerbc1dbb32019-10-24 22:58:25 +0200228void fsp_find_reserved_memory(struct range_entry *re)
Lee Leahy52d0c682016-08-01 15:47:42 -0700229{
Michael Niewöhnerbc1dbb32019-10-24 22:58:25 +0200230 if (fsp_find_range_hob(re, fsp_reserved_memory_guid))
231 die("9.1: FSP_RESERVED_MEMORY_RESOURCE_HOB missing!\n");
Alexandru Gagniuc9b2e9bd2016-02-25 14:20:38 -0800232}
233
Lee Leahyac3b0a62016-07-27 07:40:25 -0700234const void *fsp_find_extension_hob_by_guid(const uint8_t *guid, size_t *size)
Alexandru Gagniuc9b2e9bd2016-02-25 14:20:38 -0800235{
Lee Leahyac3b0a62016-07-27 07:40:25 -0700236 const uint8_t *hob_guid;
Alexandru Gagniuc9b2e9bd2016-02-25 14:20:38 -0800237 const struct hob_header *hob = fsp_get_hob_list();
238
239 if (!hob)
240 return NULL;
241
Felix Held9405dd02022-11-08 21:14:34 +0100242 for (; hob->type != HOB_TYPE_END_OF_HOB_LIST; hob = fsp_next_hob(hob)) {
Alexandru Gagniuc9b2e9bd2016-02-25 14:20:38 -0800243 if (hob->type != HOB_TYPE_GUID_EXTENSION)
244 continue;
245
Lee Leahyac3b0a62016-07-27 07:40:25 -0700246 hob_guid = hob_header_to_struct(hob);
247 if (fsp_guid_compare(hob_guid, guid)) {
Alexandru Gagniuc9b2e9bd2016-02-25 14:20:38 -0800248 *size = hob->length - (HOB_HEADER_LEN + 16);
249 return hob_header_to_extension_hob(hob);
250 }
251 }
252
253 return NULL;
254}
Hannah Williams3503b3f2016-03-04 12:14:52 -0800255
Elyes HAOUAS83b62832020-08-07 15:28:51 +0200256static void display_fsp_version_info_hob(const void *hob)
Subrata Banik73b67dc2018-01-23 16:31:03 +0530257{
Ronak Kanabarc7762462020-10-01 19:22:51 +0530258#if CONFIG(DISPLAY_FSP_VERSION_INFO) || CONFIG(DISPLAY_FSP_VERSION_INFO_2)
259
260 int index, cnt, tcount;
261 char *str_ptr;
262 uint8_t vs;
Julius Wernercd49cce2019-03-05 16:53:33 -0800263#if CONFIG(DISPLAY_FSP_VERSION_INFO)
Subrata Banik73b67dc2018-01-23 16:31:03 +0530264 const FIRMWARE_VERSION_INFO *fvi;
Felix Held9405dd02022-11-08 21:14:34 +0100265 const FIRMWARE_VERSION_INFO_HOB *fvih = (FIRMWARE_VERSION_INFO_HOB *)hob;
Subrata Banik73b67dc2018-01-23 16:31:03 +0530266
267 fvi = (void *)&fvih[1];
Felix Held9405dd02022-11-08 21:14:34 +0100268 str_ptr = (char *)((uintptr_t)fvi + (fvih->Count * sizeof(FIRMWARE_VERSION_INFO)));
Ronak Kanabarc7762462020-10-01 19:22:51 +0530269 tcount = fvih->Count;
270#elif CONFIG(DISPLAY_FSP_VERSION_INFO_2)
Subrata Banik73b67dc2018-01-23 16:31:03 +0530271
Ronak Kanabarc7762462020-10-01 19:22:51 +0530272 uint8_t *hobstart = (uint8_t *) hob;
273 hobstart += sizeof(EFI_HOB_GUID_TYPE);
274
275 const SMBIOS_TABLE_TYPE_OEM_INTEL_FVI *stfvi =
276 (SMBIOS_TABLE_TYPE_OEM_INTEL_FVI *)hobstart;
277 const INTEL_FIRMWARE_VERSION_INFO *fvi;
278
279 str_ptr = ((char *) &(stfvi->Fvi[0])) +
280 (stfvi->Count * sizeof(INTEL_FIRMWARE_VERSION_INFO));
281 tcount = stfvi->Count;
282 fvi = &stfvi->Fvi[0];
283#endif
284
285 for (index = 0; index < tcount; index++) {
Subrata Banik73b67dc2018-01-23 16:31:03 +0530286 cnt = strlen(str_ptr);
287
Ronak Kanabarc7762462020-10-01 19:22:51 +0530288#if CONFIG(DISPLAY_FSP_VERSION_INFO)
289 vs = fvi[index].VersionStringIndex;
290#elif CONFIG(DISPLAY_FSP_VERSION_INFO_2)
291 vs = fvi[index].VersionString;
292#endif
Subrata Banik73b67dc2018-01-23 16:31:03 +0530293 /* Don't show ingredient name and version if its all 0xFF */
294 if (fvi[index].Version.MajorVersion == 0xFF &&
Elyes HAOUAS365cb142019-05-19 23:31:48 +0200295 fvi[index].Version.MinorVersion == 0xFF &&
296 fvi[index].Version.Revision == 0xFF &&
297 fvi[index].Version.BuildNumber == 0xFF &&
Ronak Kanabarc7762462020-10-01 19:22:51 +0530298 vs == 0) {
Felix Held9405dd02022-11-08 21:14:34 +0100299 str_ptr = (char *)((uintptr_t)str_ptr + cnt + sizeof(uint8_t));
Subrata Banik73b67dc2018-01-23 16:31:03 +0530300 continue;
301 }
302 /*
Elyes HAOUAS8bffebe2018-05-27 22:45:31 +0200303 * Firmware Version String consist of 2 pieces of information
Subrata Banik73b67dc2018-01-23 16:31:03 +0530304 * 1. Component Name: string type data holds FW type name.
305 * 2. Version Information : Either a string type data or
306 * numeric field holds FW version information.
307 */
308 printk(BIOS_DEBUG, "%s = ", str_ptr);
309
Ronak Kanabarc7762462020-10-01 19:22:51 +0530310 if (!vs)
Subrata Banik73b67dc2018-01-23 16:31:03 +0530311 printk(BIOS_DEBUG, "%x.%x.%x.%x\n",
312 fvi[index].Version.MajorVersion,
313 fvi[index].Version.MinorVersion,
314 fvi[index].Version.Revision,
315 fvi[index].Version.BuildNumber);
316 else {
Felix Held9405dd02022-11-08 21:14:34 +0100317 str_ptr = (char *)((uintptr_t)str_ptr + cnt + sizeof(uint8_t));
Subrata Banik73b67dc2018-01-23 16:31:03 +0530318 cnt = strlen(str_ptr);
319 printk(BIOS_DEBUG, "%s\n", str_ptr);
320 }
Felix Held9405dd02022-11-08 21:14:34 +0100321 str_ptr = (char *)((uintptr_t)str_ptr + cnt + sizeof(uint8_t));
Subrata Banik73b67dc2018-01-23 16:31:03 +0530322 }
323#endif
324}
325
326void fsp_display_fvi_version_hob(void)
327{
328 const uint8_t *hob_uuid;
329 const struct hob_header *hob = fsp_get_hob_list();
Subrata Banik73b67dc2018-01-23 16:31:03 +0530330
331 if (!hob)
332 return;
333
Subrata Banik90557f42020-03-25 18:40:41 +0530334 printk(BIOS_DEBUG, "Display FSP Version Info HOB\n");
Felix Held9405dd02022-11-08 21:14:34 +0100335 for (; hob->type != HOB_TYPE_END_OF_HOB_LIST; hob = fsp_next_hob(hob)) {
Subrata Banik73b67dc2018-01-23 16:31:03 +0530336 if (hob->type != HOB_TYPE_GUID_EXTENSION)
337 continue;
338
339 hob_uuid = hob_header_to_struct(hob);
340
341 if (fsp_guid_compare(hob_uuid, uuid_fv_info)) {
Elyes HAOUAS83b62832020-08-07 15:28:51 +0200342 display_fsp_version_info_hob(hob);
Subrata Banik73b67dc2018-01-23 16:31:03 +0530343 }
344 }
345}
346
Hannah Williams3503b3f2016-03-04 12:14:52 -0800347const void *fsp_find_nv_storage_data(size_t *size)
348{
Anil Kumar0dd03682021-11-24 14:31:04 -0800349 if (CONFIG(PLATFORM_USES_FSP2_3)) {
350 const struct fsp_nvs_hob2_data_region_header *hob;
351
352 hob = (const struct fsp_nvs_hob2_data_region_header *)
353 fsp_find_extension_hob_by_guid(fsp_nv_storage_guid_2, size);
354 if (hob != NULL) {
355 *size = hob->nvs_data_length;
356 return (void *)(uintptr_t)hob->nvs_data_ptr;
357 }
358 }
Lee Leahyac3b0a62016-07-27 07:40:25 -0700359 return fsp_find_extension_hob_by_guid(fsp_nv_storage_guid, size);
Hannah Williams3503b3f2016-03-04 12:14:52 -0800360}
Michael Niewöhner68da4542019-10-19 11:57:05 +0200361
362void fsp_find_bootloader_tolum(struct range_entry *re)
363{
364 if (fsp_find_range_hob(re, fsp_bootloader_tolum_guid))
365 die("9.3: FSP_BOOTLOADER_TOLUM_HOB missing!\n");
366}