blob: ecc6bad845ab17c363bfa26f33067ae1c0d55f14 [file] [log] [blame]
Lee Leahy3dad4892015-05-05 11:14:02 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2013-2014 Sage Electronic Engineering, LLC.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
Patrick Georgib890a122015-03-26 15:17:45 +010017 * Foundation, Inc.
Lee Leahy3dad4892015-05-05 11:14:02 -070018 */
19
20#include <types.h>
21#include <string.h>
22#include <console/console.h>
23#include <lib.h> // hexdump
24#include "fsp_util.h"
25
26
27/** Displays a GUID's address and value
28 *
29 * @param guid pointer to the GUID to display
30 */
31void printguid(EFI_GUID *guid)
32{
33 printk(BIOS_SPEW,"Address: %p Guid: %08lx-%04x-%04x-",
34 guid, (unsigned long)guid->Data1,
35 guid->Data2, guid->Data3);
36 printk(BIOS_SPEW,"%02x%02x%02x%02x%02x%02x%02x%02x\n",
37 guid->Data4[0], guid->Data4[1],
38 guid->Data4[2], guid->Data4[3],
39 guid->Data4[4], guid->Data4[5],
40 guid->Data4[6], guid->Data4[7] );
41}
42
43void print_hob_mem_attributes(void *Hobptr)
44{
45 EFI_HOB_MEMORY_ALLOCATION *HobMemoryPtr = (EFI_HOB_MEMORY_ALLOCATION *)Hobptr;
46 EFI_MEMORY_TYPE Hobmemtype = HobMemoryPtr->AllocDescriptor.MemoryType;
47 u64 Hobmemaddr = HobMemoryPtr->AllocDescriptor.MemoryBaseAddress;
48 u64 Hobmemlength = HobMemoryPtr->AllocDescriptor.MemoryLength;
49 const char * Hobmemtypenames[15];
50
51 Hobmemtypenames[0] = "EfiReservedMemoryType";
52 Hobmemtypenames[1] = "EfiLoaderCode";
53 Hobmemtypenames[2] = "EfiLoaderData";
54 Hobmemtypenames[3] = "EfiBootServicesCode";
55 Hobmemtypenames[4] = "EfiBootServicesData";
56 Hobmemtypenames[5] = "EfiRuntimeServicesCode";
57 Hobmemtypenames[6] = "EfiRuntimeServicesData";
58 Hobmemtypenames[7] = "EfiConventionalMemory";
59 Hobmemtypenames[8] = "EfiUnusableMemory";
60 Hobmemtypenames[9] = "EfiACPIReclaimMemory";
61 Hobmemtypenames[10] = "EfiACPIMemoryNVS";
62 Hobmemtypenames[11] = "EfiMemoryMappedIO";
63 Hobmemtypenames[12] = "EfiMemoryMappedIOPortSpace";
64 Hobmemtypenames[13] = "EfiPalCode";
65 Hobmemtypenames[14] = "EfiMaxMemoryType";
66
67 printk(BIOS_SPEW, " Memory type %s (0x%x)\n",
68 Hobmemtypenames[(u32)Hobmemtype], (u32) Hobmemtype);
69 printk(BIOS_SPEW, " at location 0x%0lx with length 0x%0lx\n",
70 (unsigned long)Hobmemaddr, (unsigned long)Hobmemlength);
71}
72
73void print_hob_resource_attributes(void *Hobptr)
74{
75 EFI_HOB_RESOURCE_DESCRIPTOR *HobResourcePtr =
76 (EFI_HOB_RESOURCE_DESCRIPTOR *)Hobptr;
77 u32 Hobrestype = HobResourcePtr->ResourceType;
78 u32 Hobresattr = HobResourcePtr->ResourceAttribute;
79 u64 Hobresaddr = HobResourcePtr->PhysicalStart;
80 u64 Hobreslength = HobResourcePtr->ResourceLength;
81 const char *Hobrestypestr = NULL;
82
83 // HOB Resource Types
84 switch (Hobrestype) {
85 case EFI_RESOURCE_SYSTEM_MEMORY:
86 Hobrestypestr = "EFI_RESOURCE_SYSTEM_MEMORY"; break;
87 case EFI_RESOURCE_MEMORY_MAPPED_IO:
88 Hobrestypestr = "EFI_RESOURCE_MEMORY_MAPPED_IO"; break;
89 case EFI_RESOURCE_IO:
90 Hobrestypestr = "EFI_RESOURCE_IO"; break;
91 case EFI_RESOURCE_FIRMWARE_DEVICE:
92 Hobrestypestr = "EFI_RESOURCE_FIRMWARE_DEVICE"; break;
93 case EFI_RESOURCE_MEMORY_MAPPED_IO_PORT:
94 Hobrestypestr = "EFI_RESOURCE_MEMORY_MAPPED_IO_PORT"; break;
95 case EFI_RESOURCE_MEMORY_RESERVED:
96 Hobrestypestr = "EFI_RESOURCE_MEMORY_RESERVED"; break;
97 case EFI_RESOURCE_IO_RESERVED:
98 Hobrestypestr = "EFI_RESOURCE_IO_RESERVED"; break;
99 case EFI_RESOURCE_MAX_MEMORY_TYPE:
100 Hobrestypestr = "EFI_RESOURCE_MAX_MEMORY_TYPE"; break;
101 default:
102 Hobrestypestr = "EFI_RESOURCE_UNKNOWN"; break;
103 }
104
105 printk(BIOS_SPEW, " Resource %s (0x%0x) has attributes 0x%0x\n",
106 Hobrestypestr, Hobrestype, Hobresattr);
107 printk(BIOS_SPEW, " at location 0x%0lx with length 0x%0lx\n",
108 (unsigned long)Hobresaddr, (unsigned long)Hobreslength);
109}
110
111const char * get_hob_type_string(void *Hobptr)
112{
113 EFI_HOB_GENERIC_HEADER *HobHeaderPtr = (EFI_HOB_GENERIC_HEADER *)Hobptr;
114 u16 Hobtype = HobHeaderPtr->HobType;
115 const char *Hobtypestring = NULL;
116
117 switch (Hobtype) {
118 case EFI_HOB_TYPE_HANDOFF:
119 Hobtypestring = "EFI_HOB_TYPE_HANDOFF"; break;
120 case EFI_HOB_TYPE_MEMORY_ALLOCATION:
121 Hobtypestring = "EFI_HOB_TYPE_MEMORY_ALLOCATION"; break;
122 case EFI_HOB_TYPE_RESOURCE_DESCRIPTOR:
123 Hobtypestring = "EFI_HOB_TYPE_RESOURCE_DESCRIPTOR"; break;
124 case EFI_HOB_TYPE_GUID_EXTENSION:
125 Hobtypestring = "EFI_HOB_TYPE_GUID_EXTENSION"; break;
126 case EFI_HOB_TYPE_MEMORY_POOL:
127 Hobtypestring = "EFI_HOB_TYPE_MEMORY_POOL"; break;
128 case EFI_HOB_TYPE_UNUSED:
129 Hobtypestring = "EFI_HOB_TYPE_UNUSED"; break;
130 case EFI_HOB_TYPE_END_OF_HOB_LIST:
131 Hobtypestring = "EFI_HOB_TYPE_END_OF_HOB_LIST"; break;
132 default:
133 Hobtypestring = "EFI_HOB_TYPE_UNRECOGNIZED"; break;
134 }
135
136 return Hobtypestring;
137}
138
139/** Displays the length, location, and GUID value of a GUID extension
140 *
141 * The EFI_HOB_GUID_TYPE is very basic - it just contains the standard
142 * HOB header containing the HOB type and length, and a GUID for
143 * identification. The rest of the data is undefined and must be known
144 * based on the GUID.
145 *
146 * This displays the entire HOB length, and the location of the start
147 * of the HOB, *NOT* the length of or the start of the data inside the HOB.
148 *
149 * @param Hobptr
150 */
151void print_guid_type_attributes(void *Hobptr)
152{
153 printk(BIOS_SPEW, " at location %p with length0x%0lx\n ",
154 Hobptr, (unsigned long)(((EFI_PEI_HOB_POINTERS *) \
155 Hobptr)->Guid->Header.HobLength));
156 printguid(&(((EFI_HOB_GUID_TYPE *)Hobptr)->Name));
157
158}
159
160/* Print out a structure of all the HOBs
161 * that match a certain type:
162 * Print all types (0x0000)
163 * EFI_HOB_TYPE_HANDOFF (0x0001)
164 * EFI_HOB_TYPE_MEMORY_ALLOCATION (0x0002)
165 * EFI_HOB_TYPE_RESOURCE_DESCRIPTOR (0x0003)
166 * EFI_HOB_TYPE_GUID_EXTENSION (0x0004)
167 * EFI_HOB_TYPE_MEMORY_POOL (0x0007)
168 * EFI_HOB_TYPE_UNUSED (0xFFFE)
169 * EFI_HOB_TYPE_END_OF_HOB_LIST (0xFFFF)
170 */
171void print_hob_type_structure(u16 Hobtype, void *Hoblistptr)
172{
173 u32 *Currenthob;
174 u32 *Nexthob = 0;
175 u8 Lasthob = 0;
176 u32 Currenttype;
177 const char *Currenttypestr;
178
179 Currenthob = Hoblistptr;
180
181 /* Print out HOBs of our desired type until
182 * the end of the HOB list
183 */
184 printk(BIOS_DEBUG, "\n=== FSP HOB Data Structure ===\n");
185 printk(BIOS_DEBUG, "FSP Hoblistptr: 0x%0x\n",
186 (u32) Hoblistptr);
187 do {
188 EFI_HOB_GENERIC_HEADER *CurrentHeaderPtr =
189 (EFI_HOB_GENERIC_HEADER *)Currenthob;
190 Currenttype = CurrentHeaderPtr->HobType; /* Get the type of this HOB */
191 Currenttypestr = get_hob_type_string(Currenthob);
192
193 if (Currenttype == Hobtype || Hobtype == 0x0000) {
194 printk(BIOS_DEBUG, "HOB 0x%0x is an %s (type 0x%0x)\n",
195 (u32) Currenthob, Currenttypestr, Currenttype);
196 switch (Currenttype) {
197 case EFI_HOB_TYPE_MEMORY_ALLOCATION:
198 print_hob_mem_attributes(Currenthob); break;
199 case EFI_HOB_TYPE_RESOURCE_DESCRIPTOR:
200 print_hob_resource_attributes(Currenthob); break;
201 case EFI_HOB_TYPE_GUID_EXTENSION:
202 print_guid_type_attributes(Currenthob); break;
203 }
204 }
205
206 Lasthob = END_OF_HOB_LIST(Currenthob); /* Check for end of HOB list */
207 if (!Lasthob) {
208 Nexthob = GET_NEXT_HOB(Currenthob); /* Get next HOB pointer */
209 Currenthob = Nexthob; // Start on next HOB
210 }
211 } while (!Lasthob);
212 printk(BIOS_DEBUG, "=== End of FSP HOB Data Structure ===\n\n");
213}
214
215
216/** Finds a HOB entry based on type and guid
217 *
218 * @param current_hob pointer to the start of the HOB list
219 * @param guid the GUID of the HOB entry to find
220 * @return pointer to the start of the requested HOB or NULL if not found.
221 */
222void * find_hob_by_guid(void *current_hob, EFI_GUID *guid)
223{
224 do {
225 switch (((EFI_HOB_GENERIC_HEADER *)current_hob)->HobType) {
226
227 case EFI_HOB_TYPE_MEMORY_ALLOCATION:
228 if (guids_are_equal(guid, &(((EFI_HOB_MEMORY_ALLOCATION *) \
229 current_hob)->AllocDescriptor.Name)))
230 return current_hob;
231 break;
232 case EFI_HOB_TYPE_RESOURCE_DESCRIPTOR:
233 if (guids_are_equal(guid,
234 &(((EFI_HOB_RESOURCE_DESCRIPTOR *) \
235 current_hob)->Owner)))
236 return current_hob;
237 break;
238 case EFI_HOB_TYPE_GUID_EXTENSION:
239 if (guids_are_equal(guid, &(((EFI_HOB_GUID_TYPE *) \
240 current_hob)->Name)))
241 return current_hob;
242 break;
243 }
244
245 if (!END_OF_HOB_LIST(current_hob))
246 current_hob = GET_NEXT_HOB(current_hob); /* Get next HOB pointer */
247 } while (!END_OF_HOB_LIST(current_hob));
248
249 return NULL;
250}
251
252/** Compares a pair of GUIDs to see if they are equal
253 *
254 * GUIDs are 128 bits long, so compare them as pairs of quadwords.
255 *
256 * @param guid1 pointer to the first of the GUIDs to compare
257 * @param guid2 pointer to the second of the GUIDs to compare
258 * @return 1 if the GUIDs were equal, 0 if GUIDs were not equal
259 */
260uint8_t guids_are_equal(EFI_GUID *guid1, EFI_GUID *guid2)
261{
262 uint64_t* guid_1 = (void *) guid1;
263 uint64_t* guid_2 = (void *) guid2;
264
265 if ((*(guid_1) != *(guid_2)) || (*(guid_1 + 1) != *(guid_2 + 1)))
266 return 0;
267
268 return 1;
269}