blob: 8b2d56a8050b3c0d9abf612f3129450dbe94c8b3 [file] [log] [blame]
Angel Pons8a3453f2020-04-02 23:48:19 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Lee Leahy3dad4892015-05-05 11:14:02 -07002
Lee Leahyb5ad8272015-04-20 15:29:16 -07003#include <arch/hlt.h>
Lee Leahy3dad4892015-05-05 11:14:02 -07004#include <console/console.h>
Aaron Durbin789f2b62015-09-09 17:05:06 -05005#include <fsp/util.h>
Lee Leahyb5ad8272015-04-20 15:29:16 -07006#include <string.h>
Lee Leahy3dad4892015-05-05 11:14:02 -07007
Alexandru Gagniuc5c9a71e2015-08-28 18:49:40 -04008/* Compares two EFI GUIDs. Returns true of the GUIDs match, false otherwise. */
9static bool compare_guid(const EFI_GUID *guid1, const EFI_GUID *guid2)
Lee Leahy3dad4892015-05-05 11:14:02 -070010{
Alexandru Gagniuc5c9a71e2015-08-28 18:49:40 -040011 return !memcmp(guid1, guid2, sizeof(EFI_GUID));
Lee Leahyb5ad8272015-04-20 15:29:16 -070012}
13
14/* Returns the pointer to the HOB list. */
Alexandru Gagniuc5c9a71e2015-08-28 18:49:40 -040015void *get_hob_list(void)
Lee Leahyb5ad8272015-04-20 15:29:16 -070016{
17 void *hob_list;
18
19 hob_list = fsp_get_hob_list();
20 if (hob_list == NULL)
21 die("Call fsp_set_runtime() before this call!\n");
22 return hob_list;
23}
24
25/* Returns the next instance of a HOB type from the starting HOB. */
Arthur Heymans56ed0be2022-03-30 13:34:38 +020026static void *get_next_hob(uint16_t type, const void *hob_start)
Lee Leahyb5ad8272015-04-20 15:29:16 -070027{
28 EFI_PEI_HOB_POINTERS hob;
29
Alexandru Gagniuc5c9a71e2015-08-28 18:49:40 -040030 if (!hob_start)
31 return NULL;
Lee Leahyb5ad8272015-04-20 15:29:16 -070032
33 hob.Raw = (UINT8 *)hob_start;
34
35 /* Parse the HOB list until end of list or matching type is found. */
36 while (!END_OF_HOB_LIST(hob.Raw)) {
37 if (hob.Header->HobType == type)
38 return hob.Raw;
39 if (GET_HOB_LENGTH(hob.Raw) < sizeof(*hob.Header))
40 break;
41 hob.Raw = GET_NEXT_HOB(hob.Raw);
42 }
43 return NULL;
44}
45
Lee Leahyb5ad8272015-04-20 15:29:16 -070046/* Returns the next instance of the matched GUID HOB from the starting HOB. */
Arthur Heymansca74d7e2022-03-30 14:41:16 +020047void *get_guid_hob(const EFI_GUID *guid, const void *hob_start)
Lee Leahyb5ad8272015-04-20 15:29:16 -070048{
49 EFI_PEI_HOB_POINTERS hob;
50
Alexandru Gagniuc5c9a71e2015-08-28 18:49:40 -040051 hob.Raw = (uint8_t *)hob_start;
Lee Leahyb5ad8272015-04-20 15:29:16 -070052 while ((hob.Raw = get_next_hob(EFI_HOB_TYPE_GUID_EXTENSION, hob.Raw))
53 != NULL) {
54 if (compare_guid(guid, &hob.Guid->Name))
55 break;
56 hob.Raw = GET_NEXT_HOB(hob.Raw);
57 }
58 return hob.Raw;
59}
60
61/*
Lee Leahyb5ad8272015-04-20 15:29:16 -070062 * Returns the next instance of the matching resource HOB from the starting HOB.
63 */
Arthur Heymansca74d7e2022-03-30 14:41:16 +020064void *get_resource_hob(const EFI_GUID *guid, const void *hob_start)
Lee Leahyb5ad8272015-04-20 15:29:16 -070065{
66 EFI_PEI_HOB_POINTERS hob;
67
68 hob.Raw = (UINT8 *)hob_start;
69 while ((hob.Raw = get_next_hob(EFI_HOB_TYPE_RESOURCE_DESCRIPTOR,
70 hob.Raw)) != NULL) {
71 if (compare_guid(guid, &hob.ResourceDescriptor->Owner))
72 break;
73 hob.Raw = GET_NEXT_HOB(hob.Raw);
74 }
75 return hob.Raw;
76}
77
Lee Leahyb5ad8272015-04-20 15:29:16 -070078static void print_hob_mem_attributes(void *hob_ptr)
79{
Alexandru Gagniuc5c9a71e2015-08-28 18:49:40 -040080 EFI_MEMORY_TYPE hob_mem_type;
81 EFI_HOB_MEMORY_ALLOCATION *hob_memory_ptr = hob_ptr;
Lee Leahyb5ad8272015-04-20 15:29:16 -070082 u64 hob_mem_addr = hob_memory_ptr->AllocDescriptor.MemoryBaseAddress;
83 u64 hob_mem_length = hob_memory_ptr->AllocDescriptor.MemoryLength;
Lee Leahyb5ad8272015-04-20 15:29:16 -070084
Alexandru Gagniuc5c9a71e2015-08-28 18:49:40 -040085 hob_mem_type = hob_memory_ptr->AllocDescriptor.MemoryType;
86
87 static const char *hob_mem_type_names[15] = {
88 [EfiReservedMemoryType] = "EfiReservedMemoryType",
89 [EfiLoaderCode] = "EfiLoaderCode",
90 [EfiLoaderData] = "EfiLoaderData",
91 [EfiBootServicesCode] = "EfiBootServicesCode",
92 [EfiBootServicesData] = "EfiBootServicesData",
93 [EfiRuntimeServicesCode] = "EfiRuntimeServicesCode",
94 [EfiRuntimeServicesData] = "EfiRuntimeServicesData",
95 [EfiConventionalMemory] = "EfiConventionalMemory",
96 [EfiUnusableMemory] = "EfiUnusableMemory",
97 [EfiACPIReclaimMemory] = "EfiACPIReclaimMemory",
98 [EfiACPIMemoryNVS] = "EfiACPIMemoryNVS",
99 [EfiMemoryMappedIO] = "EfiMemoryMappedIO",
100 [EfiMemoryMappedIOPortSpace] = "EfiMemoryMappedIOPortSpace",
101 [EfiPalCode] = "EfiPalCode",
102 [EfiMaxMemoryType] = "EfiMaxMemoryType",
103 };
104
105 if (hob_mem_type >= ARRAY_SIZE(hob_mem_type_names))
106 hob_mem_type = EfiReservedMemoryType;
Lee Leahy3dad4892015-05-05 11:14:02 -0700107
108 printk(BIOS_SPEW, " Memory type %s (0x%x)\n",
Alexandru Gagniuc5c9a71e2015-08-28 18:49:40 -0400109 hob_mem_type_names[hob_mem_type],
Lee Leahyb5ad8272015-04-20 15:29:16 -0700110 (u32)hob_mem_type);
Lee Leahy3dad4892015-05-05 11:14:02 -0700111 printk(BIOS_SPEW, " at location 0x%0lx with length 0x%0lx\n",
Lee Leahyb5ad8272015-04-20 15:29:16 -0700112 (unsigned long)hob_mem_addr,
113 (unsigned long)hob_mem_length);
Lee Leahy3dad4892015-05-05 11:14:02 -0700114}
115
Lee Leahyb5ad8272015-04-20 15:29:16 -0700116static void print_hob_resource_attributes(void *hob_ptr)
Lee Leahy3dad4892015-05-05 11:14:02 -0700117{
Lee Leahyb5ad8272015-04-20 15:29:16 -0700118 EFI_HOB_RESOURCE_DESCRIPTOR *hob_resource_ptr =
119 (EFI_HOB_RESOURCE_DESCRIPTOR *)hob_ptr;
120 u32 hob_res_type = hob_resource_ptr->ResourceType;
121 u32 hob_res_attr = hob_resource_ptr->ResourceAttribute;
122 u64 hob_res_addr = hob_resource_ptr->PhysicalStart;
123 u64 hob_res_length = hob_resource_ptr->ResourceLength;
124 const char *hob_res_type_str = NULL;
Lee Leahy3dad4892015-05-05 11:14:02 -0700125
Lee Leahyb5ad8272015-04-20 15:29:16 -0700126 /* HOB Resource Types */
127 switch (hob_res_type) {
Lee Leahy3dad4892015-05-05 11:14:02 -0700128 case EFI_RESOURCE_SYSTEM_MEMORY:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700129 hob_res_type_str = "EFI_RESOURCE_SYSTEM_MEMORY";
130 break;
Lee Leahy3dad4892015-05-05 11:14:02 -0700131 case EFI_RESOURCE_MEMORY_MAPPED_IO:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700132 hob_res_type_str = "EFI_RESOURCE_MEMORY_MAPPED_IO";
133 break;
Lee Leahy3dad4892015-05-05 11:14:02 -0700134 case EFI_RESOURCE_IO:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700135 hob_res_type_str = "EFI_RESOURCE_IO";
136 break;
Lee Leahy3dad4892015-05-05 11:14:02 -0700137 case EFI_RESOURCE_FIRMWARE_DEVICE:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700138 hob_res_type_str = "EFI_RESOURCE_FIRMWARE_DEVICE";
139 break;
Lee Leahy3dad4892015-05-05 11:14:02 -0700140 case EFI_RESOURCE_MEMORY_MAPPED_IO_PORT:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700141 hob_res_type_str = "EFI_RESOURCE_MEMORY_MAPPED_IO_PORT";
142 break;
Lee Leahy3dad4892015-05-05 11:14:02 -0700143 case EFI_RESOURCE_MEMORY_RESERVED:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700144 hob_res_type_str = "EFI_RESOURCE_MEMORY_RESERVED";
145 break;
Lee Leahy3dad4892015-05-05 11:14:02 -0700146 case EFI_RESOURCE_IO_RESERVED:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700147 hob_res_type_str = "EFI_RESOURCE_IO_RESERVED";
148 break;
Lee Leahy3dad4892015-05-05 11:14:02 -0700149 case EFI_RESOURCE_MAX_MEMORY_TYPE:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700150 hob_res_type_str = "EFI_RESOURCE_MAX_MEMORY_TYPE";
151 break;
Lee Leahy3dad4892015-05-05 11:14:02 -0700152 default:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700153 hob_res_type_str = "EFI_RESOURCE_UNKNOWN";
154 break;
Lee Leahy3dad4892015-05-05 11:14:02 -0700155 }
156
157 printk(BIOS_SPEW, " Resource %s (0x%0x) has attributes 0x%0x\n",
Lee Leahyb5ad8272015-04-20 15:29:16 -0700158 hob_res_type_str, hob_res_type, hob_res_attr);
Lee Leahy3dad4892015-05-05 11:14:02 -0700159 printk(BIOS_SPEW, " at location 0x%0lx with length 0x%0lx\n",
Lee Leahyb5ad8272015-04-20 15:29:16 -0700160 (unsigned long)hob_res_addr,
161 (unsigned long)hob_res_length);
Lee Leahy3dad4892015-05-05 11:14:02 -0700162}
163
Lee Leahyb5ad8272015-04-20 15:29:16 -0700164static const char *get_hob_type_string(void *hob_ptr)
Lee Leahy3dad4892015-05-05 11:14:02 -0700165{
Lee Leahyb5ad8272015-04-20 15:29:16 -0700166 EFI_PEI_HOB_POINTERS hob;
Alexandru Gagniuc5c9a71e2015-08-28 18:49:40 -0400167 const char *hob_type_string;
Lee Leahyb5ad8272015-04-20 15:29:16 -0700168 const EFI_GUID fsp_reserved_guid =
169 FSP_RESERVED_MEMORY_RESOURCE_HOB_GUID;
170 const EFI_GUID mrc_guid = FSP_NON_VOLATILE_STORAGE_HOB_GUID;
171 const EFI_GUID bootldr_tmp_mem_guid =
172 FSP_BOOTLOADER_TEMP_MEMORY_HOB_GUID;
173 const EFI_GUID bootldr_tolum_guid = FSP_BOOTLOADER_TOLUM_HOB_GUID;
174 const EFI_GUID graphics_info_guid = EFI_PEI_GRAPHICS_INFO_HOB_GUID;
Lee Leahy4a8c19c2015-06-16 14:33:30 -0700175 const EFI_GUID memory_info_hob_guid = FSP_SMBIOS_MEMORY_INFO_GUID;
Lee Leahy3dad4892015-05-05 11:14:02 -0700176
Lee Leahyb5ad8272015-04-20 15:29:16 -0700177 hob.Header = (EFI_HOB_GENERIC_HEADER *)hob_ptr;
178 switch (hob.Header->HobType) {
Lee Leahy3dad4892015-05-05 11:14:02 -0700179 case EFI_HOB_TYPE_HANDOFF:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700180 hob_type_string = "EFI_HOB_TYPE_HANDOFF";
181 break;
Lee Leahy3dad4892015-05-05 11:14:02 -0700182 case EFI_HOB_TYPE_MEMORY_ALLOCATION:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700183 hob_type_string = "EFI_HOB_TYPE_MEMORY_ALLOCATION";
184 break;
Lee Leahy3dad4892015-05-05 11:14:02 -0700185 case EFI_HOB_TYPE_RESOURCE_DESCRIPTOR:
Lee Leahy4a8c19c2015-06-16 14:33:30 -0700186 if (compare_guid(&fsp_reserved_guid, &hob.Guid->Name))
187 hob_type_string = "FSP_RESERVED_MEMORY_RESOURCE_HOB";
188 else if (compare_guid(&bootldr_tolum_guid, &hob.Guid->Name))
189 hob_type_string = "FSP_BOOTLOADER_TOLUM_HOB_GUID";
Alexandru Gagniuc5c9a71e2015-08-28 18:49:40 -0400190 else
191 hob_type_string = "EFI_HOB_TYPE_RESOURCE_DESCRIPTOR";
Lee Leahyb5ad8272015-04-20 15:29:16 -0700192 break;
Lee Leahy3dad4892015-05-05 11:14:02 -0700193 case EFI_HOB_TYPE_GUID_EXTENSION:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700194 if (compare_guid(&bootldr_tmp_mem_guid, &hob.Guid->Name))
195 hob_type_string = "FSP_BOOTLOADER_TEMP_MEMORY_HOB";
Lee Leahyb5ad8272015-04-20 15:29:16 -0700196 else if (compare_guid(&mrc_guid, &hob.Guid->Name))
197 hob_type_string = "FSP_NON_VOLATILE_STORAGE_HOB";
Lee Leahyb5ad8272015-04-20 15:29:16 -0700198 else if (compare_guid(&graphics_info_guid, &hob.Guid->Name))
199 hob_type_string = "EFI_PEI_GRAPHICS_INFO_HOB_GUID";
Lee Leahy4a8c19c2015-06-16 14:33:30 -0700200 else if (compare_guid(&memory_info_hob_guid, &hob.Guid->Name))
201 hob_type_string = "FSP_SMBIOS_MEMORY_INFO_GUID";
Alexandru Gagniuc5c9a71e2015-08-28 18:49:40 -0400202 else
203 hob_type_string = "EFI_HOB_TYPE_GUID_EXTENSION";
Lee Leahyb5ad8272015-04-20 15:29:16 -0700204 break;
Lee Leahy3dad4892015-05-05 11:14:02 -0700205 case EFI_HOB_TYPE_MEMORY_POOL:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700206 hob_type_string = "EFI_HOB_TYPE_MEMORY_POOL";
207 break;
Lee Leahy3dad4892015-05-05 11:14:02 -0700208 case EFI_HOB_TYPE_UNUSED:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700209 hob_type_string = "EFI_HOB_TYPE_UNUSED";
210 break;
Lee Leahy3dad4892015-05-05 11:14:02 -0700211 case EFI_HOB_TYPE_END_OF_HOB_LIST:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700212 hob_type_string = "EFI_HOB_TYPE_END_OF_HOB_LIST";
213 break;
Lee Leahy3dad4892015-05-05 11:14:02 -0700214 default:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700215 hob_type_string = "EFI_HOB_TYPE_UNRECOGNIZED";
216 break;
Lee Leahy3dad4892015-05-05 11:14:02 -0700217 }
218
Lee Leahyb5ad8272015-04-20 15:29:16 -0700219 return hob_type_string;
Lee Leahy3dad4892015-05-05 11:14:02 -0700220}
221
Lee Leahyb5ad8272015-04-20 15:29:16 -0700222/*
223 * Print out a structure of all the HOBs
Lee Leahy3dad4892015-05-05 11:14:02 -0700224 * that match a certain type:
225 * Print all types (0x0000)
Lee Leahyb5ad8272015-04-20 15:29:16 -0700226 * EFI_HOB_TYPE_HANDOFF (0x0001)
Lee Leahy3dad4892015-05-05 11:14:02 -0700227 * EFI_HOB_TYPE_MEMORY_ALLOCATION (0x0002)
228 * EFI_HOB_TYPE_RESOURCE_DESCRIPTOR (0x0003)
229 * EFI_HOB_TYPE_GUID_EXTENSION (0x0004)
230 * EFI_HOB_TYPE_MEMORY_POOL (0x0007)
231 * EFI_HOB_TYPE_UNUSED (0xFFFE)
232 * EFI_HOB_TYPE_END_OF_HOB_LIST (0xFFFF)
233 */
Lee Leahyb5ad8272015-04-20 15:29:16 -0700234void print_hob_type_structure(u16 hob_type, void *hob_list_ptr)
Lee Leahy3dad4892015-05-05 11:14:02 -0700235{
Patrick Rudolphac49aaf2022-03-22 12:17:48 +0100236 void *current_hob;
Lee Leahyb5ad8272015-04-20 15:29:16 -0700237 u32 current_type;
238 const char *current_type_str;
Lee Leahy3dad4892015-05-05 11:14:02 -0700239
Lee Leahyb5ad8272015-04-20 15:29:16 -0700240 /*
241 * Print out HOBs of our desired type until
Lee Leahy3dad4892015-05-05 11:14:02 -0700242 * the end of the HOB list
243 */
244 printk(BIOS_DEBUG, "\n=== FSP HOB Data Structure ===\n");
Julius Werner540a9802019-12-09 13:03:29 -0800245 printk(BIOS_DEBUG, "%p: hob_list_ptr\n", hob_list_ptr);
Patrick Rudolphac49aaf2022-03-22 12:17:48 +0100246 for (current_hob = hob_list_ptr; !END_OF_HOB_LIST(current_hob);
247 current_hob = GET_NEXT_HOB(current_hob)) {
Lee Leahyb5ad8272015-04-20 15:29:16 -0700248 EFI_HOB_GENERIC_HEADER *current_header_ptr =
249 (EFI_HOB_GENERIC_HEADER *)current_hob;
Lee Leahy3dad4892015-05-05 11:14:02 -0700250
Lee Leahyb5ad8272015-04-20 15:29:16 -0700251 /* Get the type of this HOB */
252 current_type = current_header_ptr->HobType;
253 current_type_str = get_hob_type_string(current_hob);
254
255 if (current_type == hob_type || hob_type == 0x0000) {
Alexandru Gagniuc5c9a71e2015-08-28 18:49:40 -0400256 printk(BIOS_DEBUG, "HOB %p is an %s (type 0x%0x)\n",
257 current_hob, current_type_str,
Lee Leahyb5ad8272015-04-20 15:29:16 -0700258 current_type);
259 switch (current_type) {
Lee Leahy3dad4892015-05-05 11:14:02 -0700260 case EFI_HOB_TYPE_MEMORY_ALLOCATION:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700261 print_hob_mem_attributes(current_hob);
262 break;
Lee Leahy3dad4892015-05-05 11:14:02 -0700263 case EFI_HOB_TYPE_RESOURCE_DESCRIPTOR:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700264 print_hob_resource_attributes(current_hob);
265 break;
Lee Leahy3dad4892015-05-05 11:14:02 -0700266 }
267 }
Patrick Rudolphac49aaf2022-03-22 12:17:48 +0100268 }
Lee Leahy3dad4892015-05-05 11:14:02 -0700269 printk(BIOS_DEBUG, "=== End of FSP HOB Data Structure ===\n\n");
270}