blob: e7c5fb43934339a6980646aff2bef8b8c12c447e [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 <ip_checksum.h>
Lee Leahyb5ad8272015-04-20 15:29:16 -07007#include <string.h>
Lee Leahy3dad4892015-05-05 11:14:02 -07008
Alexandru Gagniuc5c9a71e2015-08-28 18:49:40 -04009/* Compares two EFI GUIDs. Returns true of the GUIDs match, false otherwise. */
10static bool compare_guid(const EFI_GUID *guid1, const EFI_GUID *guid2)
Lee Leahy3dad4892015-05-05 11:14:02 -070011{
Alexandru Gagniuc5c9a71e2015-08-28 18:49:40 -040012 return !memcmp(guid1, guid2, sizeof(EFI_GUID));
Lee Leahyb5ad8272015-04-20 15:29:16 -070013}
14
15/* Returns the pointer to the HOB list. */
Alexandru Gagniuc5c9a71e2015-08-28 18:49:40 -040016void *get_hob_list(void)
Lee Leahyb5ad8272015-04-20 15:29:16 -070017{
18 void *hob_list;
19
20 hob_list = fsp_get_hob_list();
21 if (hob_list == NULL)
22 die("Call fsp_set_runtime() before this call!\n");
23 return hob_list;
24}
25
26/* Returns the next instance of a HOB type from the starting HOB. */
Arthur Heymans56ed0be2022-03-30 13:34:38 +020027static void *get_next_hob(uint16_t type, const void *hob_start)
Lee Leahyb5ad8272015-04-20 15:29:16 -070028{
29 EFI_PEI_HOB_POINTERS hob;
30
Alexandru Gagniuc5c9a71e2015-08-28 18:49:40 -040031 if (!hob_start)
32 return NULL;
Lee Leahyb5ad8272015-04-20 15:29:16 -070033
34 hob.Raw = (UINT8 *)hob_start;
35
36 /* Parse the HOB list until end of list or matching type is found. */
37 while (!END_OF_HOB_LIST(hob.Raw)) {
38 if (hob.Header->HobType == type)
39 return hob.Raw;
40 if (GET_HOB_LENGTH(hob.Raw) < sizeof(*hob.Header))
41 break;
42 hob.Raw = GET_NEXT_HOB(hob.Raw);
43 }
44 return NULL;
45}
46
Lee Leahyb5ad8272015-04-20 15:29:16 -070047/* Returns the next instance of the matched GUID HOB from the starting HOB. */
Arthur Heymansca74d7e2022-03-30 14:41:16 +020048void *get_guid_hob(const EFI_GUID *guid, const void *hob_start)
Lee Leahyb5ad8272015-04-20 15:29:16 -070049{
50 EFI_PEI_HOB_POINTERS hob;
51
Alexandru Gagniuc5c9a71e2015-08-28 18:49:40 -040052 hob.Raw = (uint8_t *)hob_start;
Lee Leahyb5ad8272015-04-20 15:29:16 -070053 while ((hob.Raw = get_next_hob(EFI_HOB_TYPE_GUID_EXTENSION, hob.Raw))
54 != NULL) {
55 if (compare_guid(guid, &hob.Guid->Name))
56 break;
57 hob.Raw = GET_NEXT_HOB(hob.Raw);
58 }
59 return hob.Raw;
60}
61
62/*
Lee Leahyb5ad8272015-04-20 15:29:16 -070063 * Returns the next instance of the matching resource HOB from the starting HOB.
64 */
Arthur Heymansca74d7e2022-03-30 14:41:16 +020065void *get_resource_hob(const EFI_GUID *guid, const void *hob_start)
Lee Leahyb5ad8272015-04-20 15:29:16 -070066{
67 EFI_PEI_HOB_POINTERS hob;
68
69 hob.Raw = (UINT8 *)hob_start;
70 while ((hob.Raw = get_next_hob(EFI_HOB_TYPE_RESOURCE_DESCRIPTOR,
71 hob.Raw)) != NULL) {
72 if (compare_guid(guid, &hob.ResourceDescriptor->Owner))
73 break;
74 hob.Raw = GET_NEXT_HOB(hob.Raw);
75 }
76 return hob.Raw;
77}
78
Lee Leahyb5ad8272015-04-20 15:29:16 -070079static void print_hob_mem_attributes(void *hob_ptr)
80{
Alexandru Gagniuc5c9a71e2015-08-28 18:49:40 -040081 EFI_MEMORY_TYPE hob_mem_type;
82 EFI_HOB_MEMORY_ALLOCATION *hob_memory_ptr = hob_ptr;
Lee Leahyb5ad8272015-04-20 15:29:16 -070083 u64 hob_mem_addr = hob_memory_ptr->AllocDescriptor.MemoryBaseAddress;
84 u64 hob_mem_length = hob_memory_ptr->AllocDescriptor.MemoryLength;
Lee Leahyb5ad8272015-04-20 15:29:16 -070085
Alexandru Gagniuc5c9a71e2015-08-28 18:49:40 -040086 hob_mem_type = hob_memory_ptr->AllocDescriptor.MemoryType;
87
88 static const char *hob_mem_type_names[15] = {
89 [EfiReservedMemoryType] = "EfiReservedMemoryType",
90 [EfiLoaderCode] = "EfiLoaderCode",
91 [EfiLoaderData] = "EfiLoaderData",
92 [EfiBootServicesCode] = "EfiBootServicesCode",
93 [EfiBootServicesData] = "EfiBootServicesData",
94 [EfiRuntimeServicesCode] = "EfiRuntimeServicesCode",
95 [EfiRuntimeServicesData] = "EfiRuntimeServicesData",
96 [EfiConventionalMemory] = "EfiConventionalMemory",
97 [EfiUnusableMemory] = "EfiUnusableMemory",
98 [EfiACPIReclaimMemory] = "EfiACPIReclaimMemory",
99 [EfiACPIMemoryNVS] = "EfiACPIMemoryNVS",
100 [EfiMemoryMappedIO] = "EfiMemoryMappedIO",
101 [EfiMemoryMappedIOPortSpace] = "EfiMemoryMappedIOPortSpace",
102 [EfiPalCode] = "EfiPalCode",
103 [EfiMaxMemoryType] = "EfiMaxMemoryType",
104 };
105
106 if (hob_mem_type >= ARRAY_SIZE(hob_mem_type_names))
107 hob_mem_type = EfiReservedMemoryType;
Lee Leahy3dad4892015-05-05 11:14:02 -0700108
109 printk(BIOS_SPEW, " Memory type %s (0x%x)\n",
Alexandru Gagniuc5c9a71e2015-08-28 18:49:40 -0400110 hob_mem_type_names[hob_mem_type],
Lee Leahyb5ad8272015-04-20 15:29:16 -0700111 (u32)hob_mem_type);
Lee Leahy3dad4892015-05-05 11:14:02 -0700112 printk(BIOS_SPEW, " at location 0x%0lx with length 0x%0lx\n",
Lee Leahyb5ad8272015-04-20 15:29:16 -0700113 (unsigned long)hob_mem_addr,
114 (unsigned long)hob_mem_length);
Lee Leahy3dad4892015-05-05 11:14:02 -0700115}
116
Lee Leahyb5ad8272015-04-20 15:29:16 -0700117static void print_hob_resource_attributes(void *hob_ptr)
Lee Leahy3dad4892015-05-05 11:14:02 -0700118{
Lee Leahyb5ad8272015-04-20 15:29:16 -0700119 EFI_HOB_RESOURCE_DESCRIPTOR *hob_resource_ptr =
120 (EFI_HOB_RESOURCE_DESCRIPTOR *)hob_ptr;
121 u32 hob_res_type = hob_resource_ptr->ResourceType;
122 u32 hob_res_attr = hob_resource_ptr->ResourceAttribute;
123 u64 hob_res_addr = hob_resource_ptr->PhysicalStart;
124 u64 hob_res_length = hob_resource_ptr->ResourceLength;
125 const char *hob_res_type_str = NULL;
Lee Leahy3dad4892015-05-05 11:14:02 -0700126
Lee Leahyb5ad8272015-04-20 15:29:16 -0700127 /* HOB Resource Types */
128 switch (hob_res_type) {
Lee Leahy3dad4892015-05-05 11:14:02 -0700129 case EFI_RESOURCE_SYSTEM_MEMORY:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700130 hob_res_type_str = "EFI_RESOURCE_SYSTEM_MEMORY";
131 break;
Lee Leahy3dad4892015-05-05 11:14:02 -0700132 case EFI_RESOURCE_MEMORY_MAPPED_IO:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700133 hob_res_type_str = "EFI_RESOURCE_MEMORY_MAPPED_IO";
134 break;
Lee Leahy3dad4892015-05-05 11:14:02 -0700135 case EFI_RESOURCE_IO:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700136 hob_res_type_str = "EFI_RESOURCE_IO";
137 break;
Lee Leahy3dad4892015-05-05 11:14:02 -0700138 case EFI_RESOURCE_FIRMWARE_DEVICE:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700139 hob_res_type_str = "EFI_RESOURCE_FIRMWARE_DEVICE";
140 break;
Lee Leahy3dad4892015-05-05 11:14:02 -0700141 case EFI_RESOURCE_MEMORY_MAPPED_IO_PORT:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700142 hob_res_type_str = "EFI_RESOURCE_MEMORY_MAPPED_IO_PORT";
143 break;
Lee Leahy3dad4892015-05-05 11:14:02 -0700144 case EFI_RESOURCE_MEMORY_RESERVED:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700145 hob_res_type_str = "EFI_RESOURCE_MEMORY_RESERVED";
146 break;
Lee Leahy3dad4892015-05-05 11:14:02 -0700147 case EFI_RESOURCE_IO_RESERVED:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700148 hob_res_type_str = "EFI_RESOURCE_IO_RESERVED";
149 break;
Lee Leahy3dad4892015-05-05 11:14:02 -0700150 case EFI_RESOURCE_MAX_MEMORY_TYPE:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700151 hob_res_type_str = "EFI_RESOURCE_MAX_MEMORY_TYPE";
152 break;
Lee Leahy3dad4892015-05-05 11:14:02 -0700153 default:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700154 hob_res_type_str = "EFI_RESOURCE_UNKNOWN";
155 break;
Lee Leahy3dad4892015-05-05 11:14:02 -0700156 }
157
158 printk(BIOS_SPEW, " Resource %s (0x%0x) has attributes 0x%0x\n",
Lee Leahyb5ad8272015-04-20 15:29:16 -0700159 hob_res_type_str, hob_res_type, hob_res_attr);
Lee Leahy3dad4892015-05-05 11:14:02 -0700160 printk(BIOS_SPEW, " at location 0x%0lx with length 0x%0lx\n",
Lee Leahyb5ad8272015-04-20 15:29:16 -0700161 (unsigned long)hob_res_addr,
162 (unsigned long)hob_res_length);
Lee Leahy3dad4892015-05-05 11:14:02 -0700163}
164
Lee Leahyb5ad8272015-04-20 15:29:16 -0700165static const char *get_hob_type_string(void *hob_ptr)
Lee Leahy3dad4892015-05-05 11:14:02 -0700166{
Lee Leahyb5ad8272015-04-20 15:29:16 -0700167 EFI_PEI_HOB_POINTERS hob;
Alexandru Gagniuc5c9a71e2015-08-28 18:49:40 -0400168 const char *hob_type_string;
Lee Leahyb5ad8272015-04-20 15:29:16 -0700169 const EFI_GUID fsp_reserved_guid =
170 FSP_RESERVED_MEMORY_RESOURCE_HOB_GUID;
171 const EFI_GUID mrc_guid = FSP_NON_VOLATILE_STORAGE_HOB_GUID;
172 const EFI_GUID bootldr_tmp_mem_guid =
173 FSP_BOOTLOADER_TEMP_MEMORY_HOB_GUID;
174 const EFI_GUID bootldr_tolum_guid = FSP_BOOTLOADER_TOLUM_HOB_GUID;
175 const EFI_GUID graphics_info_guid = EFI_PEI_GRAPHICS_INFO_HOB_GUID;
Lee Leahy4a8c19c2015-06-16 14:33:30 -0700176 const EFI_GUID memory_info_hob_guid = FSP_SMBIOS_MEMORY_INFO_GUID;
Lee Leahy3dad4892015-05-05 11:14:02 -0700177
Lee Leahyb5ad8272015-04-20 15:29:16 -0700178 hob.Header = (EFI_HOB_GENERIC_HEADER *)hob_ptr;
179 switch (hob.Header->HobType) {
Lee Leahy3dad4892015-05-05 11:14:02 -0700180 case EFI_HOB_TYPE_HANDOFF:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700181 hob_type_string = "EFI_HOB_TYPE_HANDOFF";
182 break;
Lee Leahy3dad4892015-05-05 11:14:02 -0700183 case EFI_HOB_TYPE_MEMORY_ALLOCATION:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700184 hob_type_string = "EFI_HOB_TYPE_MEMORY_ALLOCATION";
185 break;
Lee Leahy3dad4892015-05-05 11:14:02 -0700186 case EFI_HOB_TYPE_RESOURCE_DESCRIPTOR:
Lee Leahy4a8c19c2015-06-16 14:33:30 -0700187 if (compare_guid(&fsp_reserved_guid, &hob.Guid->Name))
188 hob_type_string = "FSP_RESERVED_MEMORY_RESOURCE_HOB";
189 else if (compare_guid(&bootldr_tolum_guid, &hob.Guid->Name))
190 hob_type_string = "FSP_BOOTLOADER_TOLUM_HOB_GUID";
Alexandru Gagniuc5c9a71e2015-08-28 18:49:40 -0400191 else
192 hob_type_string = "EFI_HOB_TYPE_RESOURCE_DESCRIPTOR";
Lee Leahyb5ad8272015-04-20 15:29:16 -0700193 break;
Lee Leahy3dad4892015-05-05 11:14:02 -0700194 case EFI_HOB_TYPE_GUID_EXTENSION:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700195 if (compare_guid(&bootldr_tmp_mem_guid, &hob.Guid->Name))
196 hob_type_string = "FSP_BOOTLOADER_TEMP_MEMORY_HOB";
Lee Leahyb5ad8272015-04-20 15:29:16 -0700197 else if (compare_guid(&mrc_guid, &hob.Guid->Name))
198 hob_type_string = "FSP_NON_VOLATILE_STORAGE_HOB";
Lee Leahyb5ad8272015-04-20 15:29:16 -0700199 else if (compare_guid(&graphics_info_guid, &hob.Guid->Name))
200 hob_type_string = "EFI_PEI_GRAPHICS_INFO_HOB_GUID";
Lee Leahy4a8c19c2015-06-16 14:33:30 -0700201 else if (compare_guid(&memory_info_hob_guid, &hob.Guid->Name))
202 hob_type_string = "FSP_SMBIOS_MEMORY_INFO_GUID";
Alexandru Gagniuc5c9a71e2015-08-28 18:49:40 -0400203 else
204 hob_type_string = "EFI_HOB_TYPE_GUID_EXTENSION";
Lee Leahyb5ad8272015-04-20 15:29:16 -0700205 break;
Lee Leahy3dad4892015-05-05 11:14:02 -0700206 case EFI_HOB_TYPE_MEMORY_POOL:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700207 hob_type_string = "EFI_HOB_TYPE_MEMORY_POOL";
208 break;
Lee Leahy3dad4892015-05-05 11:14:02 -0700209 case EFI_HOB_TYPE_UNUSED:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700210 hob_type_string = "EFI_HOB_TYPE_UNUSED";
211 break;
Lee Leahy3dad4892015-05-05 11:14:02 -0700212 case EFI_HOB_TYPE_END_OF_HOB_LIST:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700213 hob_type_string = "EFI_HOB_TYPE_END_OF_HOB_LIST";
214 break;
Lee Leahy3dad4892015-05-05 11:14:02 -0700215 default:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700216 hob_type_string = "EFI_HOB_TYPE_UNRECOGNIZED";
217 break;
Lee Leahy3dad4892015-05-05 11:14:02 -0700218 }
219
Lee Leahyb5ad8272015-04-20 15:29:16 -0700220 return hob_type_string;
Lee Leahy3dad4892015-05-05 11:14:02 -0700221}
222
Lee Leahyb5ad8272015-04-20 15:29:16 -0700223/*
224 * Print out a structure of all the HOBs
Lee Leahy3dad4892015-05-05 11:14:02 -0700225 * that match a certain type:
226 * Print all types (0x0000)
Lee Leahyb5ad8272015-04-20 15:29:16 -0700227 * EFI_HOB_TYPE_HANDOFF (0x0001)
Lee Leahy3dad4892015-05-05 11:14:02 -0700228 * EFI_HOB_TYPE_MEMORY_ALLOCATION (0x0002)
229 * EFI_HOB_TYPE_RESOURCE_DESCRIPTOR (0x0003)
230 * EFI_HOB_TYPE_GUID_EXTENSION (0x0004)
231 * EFI_HOB_TYPE_MEMORY_POOL (0x0007)
232 * EFI_HOB_TYPE_UNUSED (0xFFFE)
233 * EFI_HOB_TYPE_END_OF_HOB_LIST (0xFFFF)
234 */
Lee Leahyb5ad8272015-04-20 15:29:16 -0700235void print_hob_type_structure(u16 hob_type, void *hob_list_ptr)
Lee Leahy3dad4892015-05-05 11:14:02 -0700236{
Patrick Rudolphac49aaf2022-03-22 12:17:48 +0100237 void *current_hob;
Lee Leahyb5ad8272015-04-20 15:29:16 -0700238 u32 current_type;
239 const char *current_type_str;
Lee Leahy3dad4892015-05-05 11:14:02 -0700240
Lee Leahyb5ad8272015-04-20 15:29:16 -0700241 /*
242 * Print out HOBs of our desired type until
Lee Leahy3dad4892015-05-05 11:14:02 -0700243 * the end of the HOB list
244 */
245 printk(BIOS_DEBUG, "\n=== FSP HOB Data Structure ===\n");
Julius Werner540a9802019-12-09 13:03:29 -0800246 printk(BIOS_DEBUG, "%p: hob_list_ptr\n", hob_list_ptr);
Patrick Rudolphac49aaf2022-03-22 12:17:48 +0100247 for (current_hob = hob_list_ptr; !END_OF_HOB_LIST(current_hob);
248 current_hob = GET_NEXT_HOB(current_hob)) {
249
Lee Leahyb5ad8272015-04-20 15:29:16 -0700250 EFI_HOB_GENERIC_HEADER *current_header_ptr =
251 (EFI_HOB_GENERIC_HEADER *)current_hob;
Lee Leahy3dad4892015-05-05 11:14:02 -0700252
Lee Leahyb5ad8272015-04-20 15:29:16 -0700253 /* Get the type of this HOB */
254 current_type = current_header_ptr->HobType;
255 current_type_str = get_hob_type_string(current_hob);
256
257 if (current_type == hob_type || hob_type == 0x0000) {
Alexandru Gagniuc5c9a71e2015-08-28 18:49:40 -0400258 printk(BIOS_DEBUG, "HOB %p is an %s (type 0x%0x)\n",
259 current_hob, current_type_str,
Lee Leahyb5ad8272015-04-20 15:29:16 -0700260 current_type);
261 switch (current_type) {
Lee Leahy3dad4892015-05-05 11:14:02 -0700262 case EFI_HOB_TYPE_MEMORY_ALLOCATION:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700263 print_hob_mem_attributes(current_hob);
264 break;
Lee Leahy3dad4892015-05-05 11:14:02 -0700265 case EFI_HOB_TYPE_RESOURCE_DESCRIPTOR:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700266 print_hob_resource_attributes(current_hob);
267 break;
Lee Leahy3dad4892015-05-05 11:14:02 -0700268 }
269 }
Patrick Rudolphac49aaf2022-03-22 12:17:48 +0100270 }
Lee Leahy3dad4892015-05-05 11:14:02 -0700271 printk(BIOS_DEBUG, "=== End of FSP HOB Data Structure ===\n\n");
272}