1 /* SPDX-License-Identifier: GPL-2.0-only */
4 #include <console/console.h>
8 /* Compares two EFI GUIDs. Returns true of the GUIDs match, false otherwise. */
9 static bool compare_guid(const EFI_GUID
*guid1
, const EFI_GUID
*guid2
)
11 return !memcmp(guid1
, guid2
, sizeof(EFI_GUID
));
14 /* Returns the pointer to the HOB list. */
15 void *get_hob_list(void)
19 hob_list
= fsp_get_hob_list();
21 die("Call fsp_set_runtime() before this call!\n");
25 /* Returns the next instance of a HOB type from the starting HOB. */
26 static void *get_next_hob(uint16_t type
, const void *hob_start
)
28 EFI_PEI_HOB_POINTERS hob
;
33 hob
.Raw
= (UINT8
*)hob_start
;
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
)
39 if (GET_HOB_LENGTH(hob
.Raw
) < sizeof(*hob
.Header
))
41 hob
.Raw
= GET_NEXT_HOB(hob
.Raw
);
46 /* Returns the next instance of the matched GUID HOB from the starting HOB. */
47 void *get_guid_hob(const EFI_GUID
*guid
, const void *hob_start
)
49 EFI_PEI_HOB_POINTERS hob
;
51 hob
.Raw
= (uint8_t *)hob_start
;
52 while ((hob
.Raw
= get_next_hob(EFI_HOB_TYPE_GUID_EXTENSION
, hob
.Raw
))
54 if (compare_guid(guid
, &hob
.Guid
->Name
))
56 hob
.Raw
= GET_NEXT_HOB(hob
.Raw
);
62 * Returns the next instance of the matching resource HOB from the starting HOB.
64 void *get_resource_hob(const EFI_GUID
*guid
, const void *hob_start
)
66 EFI_PEI_HOB_POINTERS hob
;
68 hob
.Raw
= (UINT8
*)hob_start
;
69 while ((hob
.Raw
= get_next_hob(EFI_HOB_TYPE_RESOURCE_DESCRIPTOR
,
71 if (compare_guid(guid
, &hob
.ResourceDescriptor
->Owner
))
73 hob
.Raw
= GET_NEXT_HOB(hob
.Raw
);
78 static void print_hob_mem_attributes(void *hob_ptr
)
80 EFI_MEMORY_TYPE hob_mem_type
;
81 EFI_HOB_MEMORY_ALLOCATION
*hob_memory_ptr
= hob_ptr
;
82 u64 hob_mem_addr
= hob_memory_ptr
->AllocDescriptor
.MemoryBaseAddress
;
83 u64 hob_mem_length
= hob_memory_ptr
->AllocDescriptor
.MemoryLength
;
85 hob_mem_type
= hob_memory_ptr
->AllocDescriptor
.MemoryType
;
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",
105 if (hob_mem_type
>= ARRAY_SIZE(hob_mem_type_names
))
106 hob_mem_type
= EfiReservedMemoryType
;
108 printk(BIOS_SPEW
, " Memory type %s (0x%x)\n",
109 hob_mem_type_names
[hob_mem_type
],
111 printk(BIOS_SPEW
, " at location 0x%0lx with length 0x%0lx\n",
112 (unsigned long)hob_mem_addr
,
113 (unsigned long)hob_mem_length
);
116 static void print_hob_resource_attributes(void *hob_ptr
)
118 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
;
126 /* HOB Resource Types */
127 switch (hob_res_type
) {
128 case EFI_RESOURCE_SYSTEM_MEMORY
:
129 hob_res_type_str
= "EFI_RESOURCE_SYSTEM_MEMORY";
131 case EFI_RESOURCE_MEMORY_MAPPED_IO
:
132 hob_res_type_str
= "EFI_RESOURCE_MEMORY_MAPPED_IO";
134 case EFI_RESOURCE_IO
:
135 hob_res_type_str
= "EFI_RESOURCE_IO";
137 case EFI_RESOURCE_FIRMWARE_DEVICE
:
138 hob_res_type_str
= "EFI_RESOURCE_FIRMWARE_DEVICE";
140 case EFI_RESOURCE_MEMORY_MAPPED_IO_PORT
:
141 hob_res_type_str
= "EFI_RESOURCE_MEMORY_MAPPED_IO_PORT";
143 case EFI_RESOURCE_MEMORY_RESERVED
:
144 hob_res_type_str
= "EFI_RESOURCE_MEMORY_RESERVED";
146 case EFI_RESOURCE_IO_RESERVED
:
147 hob_res_type_str
= "EFI_RESOURCE_IO_RESERVED";
149 case EFI_RESOURCE_MAX_MEMORY_TYPE
:
150 hob_res_type_str
= "EFI_RESOURCE_MAX_MEMORY_TYPE";
153 hob_res_type_str
= "EFI_RESOURCE_UNKNOWN";
157 printk(BIOS_SPEW
, " Resource %s (0x%0x) has attributes 0x%0x\n",
158 hob_res_type_str
, hob_res_type
, hob_res_attr
);
159 printk(BIOS_SPEW
, " at location 0x%0lx with length 0x%0lx\n",
160 (unsigned long)hob_res_addr
,
161 (unsigned long)hob_res_length
);
164 static const char *get_hob_type_string(void *hob_ptr
)
166 EFI_PEI_HOB_POINTERS hob
;
167 const char *hob_type_string
;
168 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
;
175 const EFI_GUID memory_info_hob_guid
= FSP_SMBIOS_MEMORY_INFO_GUID
;
177 hob
.Header
= (EFI_HOB_GENERIC_HEADER
*)hob_ptr
;
178 switch (hob
.Header
->HobType
) {
179 case EFI_HOB_TYPE_HANDOFF
:
180 hob_type_string
= "EFI_HOB_TYPE_HANDOFF";
182 case EFI_HOB_TYPE_MEMORY_ALLOCATION
:
183 hob_type_string
= "EFI_HOB_TYPE_MEMORY_ALLOCATION";
185 case EFI_HOB_TYPE_RESOURCE_DESCRIPTOR
:
186 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";
191 hob_type_string
= "EFI_HOB_TYPE_RESOURCE_DESCRIPTOR";
193 case EFI_HOB_TYPE_GUID_EXTENSION
:
194 if (compare_guid(&bootldr_tmp_mem_guid
, &hob
.Guid
->Name
))
195 hob_type_string
= "FSP_BOOTLOADER_TEMP_MEMORY_HOB";
196 else if (compare_guid(&mrc_guid
, &hob
.Guid
->Name
))
197 hob_type_string
= "FSP_NON_VOLATILE_STORAGE_HOB";
198 else if (compare_guid(&graphics_info_guid
, &hob
.Guid
->Name
))
199 hob_type_string
= "EFI_PEI_GRAPHICS_INFO_HOB_GUID";
200 else if (compare_guid(&memory_info_hob_guid
, &hob
.Guid
->Name
))
201 hob_type_string
= "FSP_SMBIOS_MEMORY_INFO_GUID";
203 hob_type_string
= "EFI_HOB_TYPE_GUID_EXTENSION";
205 case EFI_HOB_TYPE_MEMORY_POOL
:
206 hob_type_string
= "EFI_HOB_TYPE_MEMORY_POOL";
208 case EFI_HOB_TYPE_UNUSED
:
209 hob_type_string
= "EFI_HOB_TYPE_UNUSED";
211 case EFI_HOB_TYPE_END_OF_HOB_LIST
:
212 hob_type_string
= "EFI_HOB_TYPE_END_OF_HOB_LIST";
215 hob_type_string
= "EFI_HOB_TYPE_UNRECOGNIZED";
219 return hob_type_string
;
223 * Print out a structure of all the HOBs
224 * that match a certain type:
225 * Print all types (0x0000)
226 * EFI_HOB_TYPE_HANDOFF (0x0001)
227 * 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)
234 void print_hob_type_structure(u16 hob_type
, void *hob_list_ptr
)
238 const char *current_type_str
;
241 * Print out HOBs of our desired type until
242 * the end of the HOB list
244 printk(BIOS_DEBUG
, "\n=== FSP HOB Data Structure ===\n");
245 printk(BIOS_DEBUG
, "%p: hob_list_ptr\n", hob_list_ptr
);
246 for (current_hob
= hob_list_ptr
; !END_OF_HOB_LIST(current_hob
);
247 current_hob
= GET_NEXT_HOB(current_hob
)) {
248 EFI_HOB_GENERIC_HEADER
*current_header_ptr
=
249 (EFI_HOB_GENERIC_HEADER
*)current_hob
;
251 /* Get the type of this HOB */
252 current_type
= current_header_ptr
->HobType
;
253 current_type_str
= get_hob_type_string(current_hob
);
255 if (current_type
== hob_type
|| hob_type
== 0x0000) {
256 printk(BIOS_DEBUG
, "HOB %p is an %s (type 0x%0x)\n",
257 current_hob
, current_type_str
,
259 switch (current_type
) {
260 case EFI_HOB_TYPE_MEMORY_ALLOCATION
:
261 print_hob_mem_attributes(current_hob
);
263 case EFI_HOB_TYPE_RESOURCE_DESCRIPTOR
:
264 print_hob_resource_attributes(current_hob
);
269 printk(BIOS_DEBUG
, "=== End of FSP HOB Data Structure ===\n\n");