]> git.proxmox.com Git - mirror_edk2.git/blame - EdkCompatibilityPkg/Foundation/Library/Pei/Hob/PeiHobLib.c
Fix a bug in BuidHobGuidType() of PeiHobLib that it does not adjust the hob length...
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Library / Pei / Hob / PeiHobLib.c
CommitLineData
3eb9473e 1\r
2/*++\r
3\r
4Copyright (c) 2004 - 2007, Intel Corporation \r
5All rights reserved. This program and the accompanying materials \r
6are licensed and made available under the terms and conditions of the BSD License \r
7which accompanies this distribution. The full text of the license may be found at \r
8http://opensource.org/licenses/bsd-license.php \r
9 \r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
12\r
13MemoryAllocationModule Name:\r
14\r
15 Peihoblib.c\r
16\r
17Abstract:\r
18\r
19 PEI Library Functions\r
20 \r
21--*/\r
22\r
23#include "Tiano.h"\r
24#include "PeiHob.h"\r
0dbeedde 25#include "PeiHobLib.h"\r
26#include "PeiLib.h"\r
3eb9473e 27#include EFI_GUID_DEFINITION(MemoryAllocationHob)\r
28\r
29\r
30EFI_PEI_HOB_POINTERS\r
31BuildHobEndOfHobList (\r
32 IN VOID *HobStart\r
33 )\r
34/*++\r
35\r
36Routine Description:\r
37\r
38 Builds an end of HOB list HOB\r
39\r
40Arguments:\r
41\r
42 HobStart - The HOB to build\r
43\r
44Returns:\r
45\r
46 A pointer to the next HOB\r
47\r
48--*/\r
49{\r
50 EFI_PEI_HOB_POINTERS Hob;\r
51\r
52 Hob.Raw = HobStart;\r
53 \r
54 Hob.Header->HobType = EFI_HOB_TYPE_END_OF_HOB_LIST;\r
55 Hob.Header->HobLength = sizeof(EFI_HOB_GENERIC_HEADER);\r
56\r
57 Hob.Header++;\r
58 return Hob;\r
59}\r
60\r
61EFI_STATUS\r
62BuildHobHandoffInfoTable (\r
63 IN VOID *HobStart,\r
64 IN UINT16 Version,\r
65 IN EFI_BOOT_MODE BootMode,\r
66 IN EFI_PHYSICAL_ADDRESS EfiMemoryTop,\r
67 IN EFI_PHYSICAL_ADDRESS EfiMemoryBottom,\r
68 IN EFI_PHYSICAL_ADDRESS EfiFreeMemoryTop,\r
69 IN EFI_PHYSICAL_ADDRESS EfiFreeMemoryBottom\r
70 )\r
71/*++\r
72\r
73Routine Description:\r
74\r
75 Builds a HandoffInformationTable Information Table HOB\r
76\r
77Arguments:\r
78\r
79 HobStart - Start pointer of hob list\r
80 Version - The version number pertaining to the PHIT HOB definition.\r
81 BootMode - The system boot mode as determined during the HOB producer phase.\r
82 EfiMemoryTop - The highest address location of memory that is allocated for use by the HOB\r
83 producer phase.\r
84 EfiMemoryBottom - The lowest address location of memory that is allocated for use by the HOB\r
85 producer phase.\r
86 EfiFreeMemoryTop - The highest address location of free memory that is currently available for use\r
87 by the HOB producer phase.\r
88 EfiFreeMemoryBottom - The lowest address location of free memory that is available for \r
89 use by the HOB producer phase.\r
90 \r
91Returns:\r
92\r
93 EFI_SUCCESS\r
94\r
95--*/\r
96{\r
97 EFI_PEI_HOB_POINTERS HandOffHob;\r
98 EFI_PEI_HOB_POINTERS Hob;\r
99 EFI_PEI_HOB_POINTERS HobEnd;\r
100 \r
101\r
102 HandOffHob.Raw = HobStart;\r
103 Hob.Raw = HobStart;\r
104 Hob.Header->HobType = EFI_HOB_TYPE_HANDOFF;\r
105 Hob.Header->HobLength = sizeof(EFI_HOB_HANDOFF_INFO_TABLE);\r
106\r
107 Hob.HandoffInformationTable->Version = Version;\r
108 Hob.HandoffInformationTable->BootMode = BootMode;\r
109 \r
110 Hob.HandoffInformationTable->EfiMemoryTop = EfiMemoryTop;\r
111 Hob.HandoffInformationTable->EfiMemoryBottom = EfiMemoryBottom;\r
112 Hob.HandoffInformationTable->EfiFreeMemoryTop = EfiFreeMemoryTop;\r
113 Hob.HandoffInformationTable->EfiFreeMemoryBottom = EfiFreeMemoryBottom;\r
114 \r
115 HobEnd.Raw = (VOID*)(Hob.HandoffInformationTable + 1);\r
116 Hob.HandoffInformationTable->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS) (UINTN) HobEnd.Raw;\r
117 Hob = BuildHobEndOfHobList (HobEnd.Raw);\r
118 HandOffHob.HandoffInformationTable->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN) Hob.Raw;\r
119 return EFI_SUCCESS;\r
120}\r
121\r
122\r
123\r
124EFI_STATUS\r
125BuildHobModule (\r
126 IN VOID *HobStart,\r
127 IN EFI_GUID *ModuleName,\r
128 IN EFI_PHYSICAL_ADDRESS MemoryAllocationModule,\r
129 IN UINT64 ModuleLength,\r
130 IN EFI_PHYSICAL_ADDRESS EntryPoint\r
131 )\r
132/*++\r
133\r
134Routine Description:\r
135\r
136 Builds a HOB for a loaded PE32 module\r
137\r
138Arguments:\r
139\r
140 HobStart - Start pointer of hob list\r
141\r
142 ModuleName - The GUID File Name of the HON from the Firmware Volume\r
143\r
144 MemoryAllocationModule - The 64 bit physical address of the module\r
145\r
146 ModuleLength - The length of the module in bytes\r
147\r
148 EntryPoint - The 64 bit physical address of the entry point to the module\r
149\r
150Returns:\r
151\r
152 EFI_SUCCESS\r
153 EFI_NOT_AVAILABLE_YET\r
154\r
155--*/\r
156{\r
157 EFI_PEI_HOB_POINTERS Hob;\r
158 EFI_PEI_HOB_POINTERS HandOffHob;\r
159 \r
160 HandOffHob.Raw = HobStart;\r
161 Hob.Raw = (VOID*)(UINTN)(HandOffHob.HandoffInformationTable->EfiEndOfHobList);\r
162\r
163 Hob.Header->HobType = EFI_HOB_TYPE_MEMORY_ALLOCATION;\r
164 Hob.Header->HobLength = sizeof(EFI_HOB_MEMORY_ALLOCATION_MODULE);\r
165 \r
166 CopyMem(&(Hob.MemoryAllocationModule->ModuleName), ModuleName, sizeof(EFI_GUID));\r
167 CopyMem(&(Hob.MemoryAllocationModule->MemoryAllocationHeader.Name), &gEfiHobMemeryAllocModuleGuid, sizeof(EFI_GUID));\r
168 Hob.MemoryAllocationModule->MemoryAllocationHeader.MemoryBaseAddress = MemoryAllocationModule;\r
169 Hob.MemoryAllocationModule->MemoryAllocationHeader.MemoryLength = ModuleLength;\r
170 Hob.MemoryAllocationModule->MemoryAllocationHeader.MemoryType = EfiConventionalMemory;\r
171\r
172 Hob.MemoryAllocationModule->EntryPoint = EntryPoint;\r
173\r
174 Hob.MemoryAllocationModule++;\r
175 HandOffHob.HandoffInformationTable->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS) (UINTN) Hob.Raw;\r
176 Hob = BuildHobEndOfHobList(Hob.Raw);\r
177 HandOffHob.HandoffInformationTable->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN) Hob.Raw;\r
178 return EFI_SUCCESS;\r
179}\r
180\r
181EFI_STATUS\r
182BuildHobResourceDescriptor (\r
183 IN VOID * HobStart,\r
184 IN EFI_RESOURCE_TYPE ResourceType,\r
185 IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute,\r
186 IN EFI_PHYSICAL_ADDRESS PhysicalStart,\r
187 IN UINT64 NumberOfBytes\r
188 )\r
189/*++\r
190\r
191Routine Description:\r
192\r
193 Builds a HOB that describes a chunck of system memory\r
194\r
195Arguments:\r
196\r
197 HobStart - Start pointer of hob list\r
198\r
199 ResourceType - The type of memory described by this HOB\r
200\r
201 ResourceAttribute - The memory attributes of the memory described by this HOB\r
202\r
203 PhysicalStart - The 64 bit physical address of memory described by this HOB\r
204\r
205 NumberOfBytes - The length of the memoty described by this HOB in bytes\r
206\r
207Returns:\r
208\r
209 EFI_SUCCESS\r
210 EFI_NOT_AVAILABLE_YET\r
211\r
212--*/\r
213{\r
214 EFI_PEI_HOB_POINTERS Hob;\r
215 EFI_PEI_HOB_POINTERS HandOffHob;\r
216 \r
217 HandOffHob.Raw = HobStart;\r
218 Hob.Raw = (VOID *)(UINTN)(HandOffHob.HandoffInformationTable->EfiEndOfHobList);\r
219 \r
220 Hob.Header->HobType = EFI_HOB_TYPE_RESOURCE_DESCRIPTOR;\r
221 Hob.Header->HobLength = sizeof(EFI_HOB_RESOURCE_DESCRIPTOR);\r
222\r
223 Hob.ResourceDescriptor->ResourceType = ResourceType;\r
224 Hob.ResourceDescriptor->ResourceAttribute = ResourceAttribute;\r
225 Hob.ResourceDescriptor->PhysicalStart = PhysicalStart;\r
226 Hob.ResourceDescriptor->ResourceLength = NumberOfBytes; \r
227\r
228 Hob.ResourceDescriptor++;\r
229 HandOffHob.HandoffInformationTable->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS) (UINTN) Hob.Raw;\r
230 Hob = BuildHobEndOfHobList(Hob.Raw);\r
231 HandOffHob.HandoffInformationTable->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN) Hob.Raw;\r
232 return EFI_SUCCESS;\r
233}\r
234\r
235EFI_STATUS\r
236BuildHobGuidType (\r
237 IN VOID *HobStart,\r
238 IN EFI_GUID *Guid,\r
239 IN VOID *Buffer,\r
240 IN UINTN BufferSize\r
241 )\r
242/*++\r
243\r
244Routine Description:\r
245\r
246 Builds a custom HOB that is tagged with a GUID for identification\r
247\r
248Arguments:\r
249\r
250 HobStart - Start pointer of hob list\r
251\r
252 Guid - The GUID of the custome HOB type\r
253\r
254 Buffer - A pointer to the data for the custom HOB type\r
255\r
256 BufferSize - The size in byte of BufferSize\r
257\r
258Returns:\r
259\r
260 EFI_SUCCESS\r
261 EFI_NOT_AVAILABLE_YET\r
262\r
263--*/\r
264{\r
265 EFI_PEI_HOB_POINTERS Hob;\r
266 EFI_PEI_HOB_POINTERS HandOffHob;\r
267 UINTN Length;\r
268 \r
269 \r
270 HandOffHob.Raw = HobStart;\r
271 Hob.Raw = (VOID *)(UINTN)HandOffHob.HandoffInformationTable->EfiEndOfHobList; \r
272\r
273\r
274 Hob.Header->HobType = EFI_HOB_TYPE_GUID_EXTENSION;\r
275 Length = sizeof(EFI_HOB_GUID_TYPE) + BufferSize;\r
ada3f18c 276 Length = (Length + 0x7) & (~0x7);\r
3eb9473e 277 Hob.Header->HobLength = (UINT16)Length;\r
278 CopyMem(&Hob.Guid->Name, Guid, sizeof(EFI_GUID));\r
279 CopyMem(Hob.Raw + sizeof(EFI_HOB_GUID_TYPE), Buffer, BufferSize);\r
280 Hob.Raw += Length;\r
281\r
282 HandOffHob.HandoffInformationTable->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS) (UINTN) Hob.Raw;\r
283 Hob = BuildHobEndOfHobList(Hob.Raw);\r
284 HandOffHob.HandoffInformationTable->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN) Hob.Raw;\r
285 return EFI_SUCCESS;\r
286}\r
287\r
288EFI_STATUS\r
289BuildHobFvDescriptor (\r
290 IN VOID *HobStart,\r
291 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
292 IN UINT64 Length\r
293 )\r
294/*++\r
295\r
296Routine Description:\r
297\r
298 Builds a Firmware Volume HOB\r
299\r
300Arguments:\r
301\r
302 HobStart - Start pointer of hob list\r
303\r
304 BaseAddress - The base address of the Firmware Volume\r
305\r
306 Length - The size of the Firmware Volume in bytes\r
307\r
308Returns:\r
309\r
310 EFI_SUCCESS\r
311 EFI_NOT_AVAILABLE_YET\r
312\r
313--*/\r
314{\r
315 EFI_PEI_HOB_POINTERS Hob;\r
316 EFI_PEI_HOB_POINTERS HandOffHob;\r
317 \r
318 HandOffHob.Raw = HobStart;\r
319 Hob.Raw = (VOID*)(UINTN)(HandOffHob.HandoffInformationTable->EfiEndOfHobList); \r
320\r
321 Hob.Header->HobType = EFI_HOB_TYPE_FV;\r
322 Hob.Header->HobLength = sizeof(EFI_HOB_FIRMWARE_VOLUME);\r
323\r
324 Hob.FirmwareVolume->BaseAddress = BaseAddress;\r
325 Hob.FirmwareVolume->Length = Length;\r
326\r
327 Hob.FirmwareVolume++;\r
328\r
329 HandOffHob.HandoffInformationTable->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS) (UINTN) Hob.Raw;\r
330 Hob = BuildHobEndOfHobList(Hob.Raw);\r
331 HandOffHob.HandoffInformationTable->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN) Hob.Raw;\r
332 return EFI_SUCCESS;\r
333}\r
334\r
335EFI_STATUS\r
336BuildHobCpu (\r
337 IN VOID *HobStart,\r
338 IN UINT8 SizeOfMemorySpace,\r
339 IN UINT8 SizeOfIoSpace\r
340 )\r
341/*++\r
342\r
343Routine Description:\r
344\r
345 Builds a HOB for the CPU\r
346\r
347Arguments:\r
348\r
349 HobStart - Start pointer of hob list\r
350\r
351 SizeOfMemorySpace - Identifies the maximum \r
352 physical memory addressibility of the processor.\r
353\r
354 SizeOfIoSpace - Identifies the maximum physical I/O addressibility \r
355 of the processor.\r
356\r
357Returns:\r
358\r
359 EFI_SUCCESS\r
360 EFI_NOT_AVAILABLE_YET\r
361\r
362--*/\r
363{\r
364 EFI_PEI_HOB_POINTERS Hob;\r
365 EFI_PEI_HOB_POINTERS HandOffHob;\r
366\r
367 HandOffHob.Raw = HobStart;\r
368 Hob.Raw = (VOID*)(UINTN)HandOffHob.HandoffInformationTable->EfiEndOfHobList;\r
369\r
370 Hob.Header->HobType = EFI_HOB_TYPE_CPU;\r
371 Hob.Header->HobLength = sizeof(EFI_HOB_CPU);\r
372\r
373 Hob.Cpu->SizeOfMemorySpace = SizeOfMemorySpace;\r
374 Hob.Cpu->SizeOfIoSpace = SizeOfIoSpace;\r
375\r
376 Hob.Cpu++;\r
377 HandOffHob.HandoffInformationTable->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS) (UINTN) Hob.Raw;\r
378 Hob = BuildHobEndOfHobList(Hob.Raw);\r
379 HandOffHob.HandoffInformationTable->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN) Hob.Raw;\r
380 return EFI_SUCCESS;\r
381}\r
382\r
383\r
384\r
385EFI_STATUS\r
386BuildHobStack (\r
387 IN VOID *HobStart,\r
388 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
389 IN UINT64 Length\r
390 )\r
391/*++\r
392\r
393Routine Description:\r
394\r
395 Builds a HOB for the Stack\r
396\r
397Arguments:\r
398\r
399 HobStart - Start pointer of hob list\r
400\r
401 BaseAddress - The 64 bit physical address of the Stack\r
402\r
403 Length - The length of the stack in bytes\r
404\r
405Returns:\r
406\r
407 EFI_SUCCESS\r
408 EFI_NOT_AVAILABLE_YET\r
409\r
410--*/\r
411{\r
412 EFI_PEI_HOB_POINTERS Hob;\r
413 EFI_PEI_HOB_POINTERS HandOffHob;\r
414 \r
415 HandOffHob.Raw = HobStart;\r
416 Hob.Raw = (VOID*)(UINTN)HandOffHob.HandoffInformationTable->EfiEndOfHobList;\r
417\r
418 Hob.Header->HobType = EFI_HOB_TYPE_MEMORY_ALLOCATION;\r
419 Hob.Header->HobLength = sizeof(EFI_HOB_MEMORY_ALLOCATION_STACK);\r
420\r
421 CopyMem(&(Hob.MemoryAllocationStack->AllocDescriptor.Name), &gEfiHobMemeryAllocStackGuid, sizeof(EFI_GUID));\r
422 (Hob.MemoryAllocationStack->AllocDescriptor).MemoryBaseAddress = BaseAddress;\r
423 (Hob.MemoryAllocationStack->AllocDescriptor).MemoryLength = Length;\r
c7f33ca4 424 (Hob.MemoryAllocationStack->AllocDescriptor).MemoryType = EfiBootServicesData;\r
3eb9473e 425\r
426 Hob.MemoryAllocationStack++;\r
427 HandOffHob.HandoffInformationTable->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS) (UINTN) Hob.Raw;\r
428 Hob = BuildHobEndOfHobList(Hob.Raw);\r
429 HandOffHob.HandoffInformationTable->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN) Hob.Raw;\r
430 return EFI_SUCCESS;\r
431}\r
432\r
433\r
434\r
435EFI_STATUS\r
436BuildHobBspStore (\r
437 IN VOID *HobStart,\r
438 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
439 IN UINT64 Length,\r
440 IN EFI_MEMORY_TYPE MemoryType\r
441 )\r
442/*++\r
443\r
444Routine Description:\r
445\r
446 Builds a HOB for the bsp store\r
447\r
448Arguments:\r
449\r
450 HobStart - Start pointer of hob list\r
451\r
452 BaseAddress - The 64 bit physical address of bsp store\r
453\r
454 Length - The length of the bsp store in bytes\r
455 \r
456 MemoryType - Memory type of the bsp store\r
457\r
458Returns:\r
459\r
460 EFI_SUCCESS\r
461 EFI_NOT_AVAILABLE_YET\r
462\r
463--*/\r
464{\r
465 EFI_PEI_HOB_POINTERS Hob;\r
466 EFI_PEI_HOB_POINTERS HandOffHob;\r
467\r
468 HandOffHob.Raw = HobStart;\r
469 Hob.Raw = (VOID *)(UINTN)HandOffHob.HandoffInformationTable->EfiEndOfHobList;\r
470 Hob.Header->HobType = EFI_HOB_TYPE_MEMORY_ALLOCATION;\r
471 Hob.Header->HobLength = sizeof(EFI_HOB_MEMORY_ALLOCATION_BSP_STORE);\r
472\r
473 (Hob.MemoryAllocationBspStore->AllocDescriptor).MemoryBaseAddress = BaseAddress;\r
474 (Hob.MemoryAllocationBspStore->AllocDescriptor).MemoryLength = Length;\r
475 (Hob.MemoryAllocationBspStore->AllocDescriptor).MemoryType = MemoryType;\r
476 CopyMem(&(Hob.MemoryAllocationBspStore->AllocDescriptor).Name, &gEfiHobMemeryAllocBspStoreGuid, sizeof(EFI_GUID));\r
477 Hob.MemoryAllocationBspStore++;\r
478\r
479 HandOffHob.HandoffInformationTable->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS) (UINTN) Hob.Raw;\r
480 Hob = BuildHobEndOfHobList(Hob.Raw);\r
481 HandOffHob.HandoffInformationTable->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN) Hob.Raw;\r
482 return EFI_SUCCESS;\r
483}\r
484\r
485\r
486EFI_STATUS\r
487BuildMemoryAllocationHob (\r
488 IN VOID *HobStart,\r
489 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
490 IN UINT64 Length,\r
491 IN EFI_GUID *Name,\r
492 IN EFI_MEMORY_TYPE MemoryType\r
493 )\r
494/*++\r
495\r
496Routine Description:\r
497\r
498 Builds a HOB for memory allocation\r
499\r
500Arguments:\r
501\r
502 HobStart - Start pointer of hob list\r
503\r
504 BaseAddress - The base address of memory allocated by this HOB.\r
505\r
506 Length - The length in bytes of memory allocated by this HOB.\r
507 \r
fd0d281b 508 Name - A GUID that defines the memory allocation region's type and purpose, \r
3eb9473e 509 as well as other fields within the memory allocation HOB.\r
510 \r
511 MemoryType - Defines the type of memory allocated by this HOB.\r
512\r
513Returns:\r
514\r
515 EFI_SUCCESS\r
516 EFI_NOT_AVAILABLE_YET\r
517\r
518--*/\r
519{\r
520 EFI_PEI_HOB_POINTERS Hob;\r
521 EFI_PEI_HOB_POINTERS HandOffHob;\r
522 \r
523 \r
524 HandOffHob.Raw = HobStart;\r
525 Hob.Raw = (VOID*)(UINTN)HandOffHob.HandoffInformationTable->EfiEndOfHobList;\r
526\r
527 Hob.Header->HobType = EFI_HOB_TYPE_MEMORY_ALLOCATION;\r
528 Hob.Header->HobLength = sizeof(EFI_HOB_MEMORY_ALLOCATION);\r
529\r
530 if (Name != NULL) {\r
531 CopyMem(&(Hob.MemoryAllocation->AllocDescriptor.Name), &Name, sizeof(EFI_GUID));\r
532 } else {\r
533 ZeroMem(&Hob.MemoryAllocation->AllocDescriptor.Name, sizeof(EFI_GUID));\r
534 }\r
535\r
536 (Hob.MemoryAllocation->AllocDescriptor).MemoryBaseAddress = BaseAddress;\r
537 (Hob.MemoryAllocation->AllocDescriptor).MemoryLength = Length;\r
538 (Hob.MemoryAllocation->AllocDescriptor).MemoryType = MemoryType;\r
539\r
540 Hob.MemoryAllocation++;\r
541 HandOffHob.HandoffInformationTable->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS) (UINTN) Hob.Raw;\r
542 Hob = BuildHobEndOfHobList(Hob.Raw);\r
543 HandOffHob.HandoffInformationTable->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN) Hob.Raw;\r
544 return EFI_SUCCESS;\r
545}\r
546\r
547EFI_STATUS\r
548GetFirstGuidHob (\r
549 IN VOID **HobStart,\r
550 IN EFI_GUID *Guid,\r
551 OUT VOID **Buffer,\r
552 OUT UINTN *BufferSize OPTIONAL\r
553 ) \r
554/*++\r
555\r
556Routine Description:\r
557\r
558 This function searches the first instance of a HOB among the whole HOB list. \r
559\r
560Arguments:\r
561\r
562 HobStart - A pointer to the start pointer of hob list.\r
563\r
564 Guid - A pointer to the GUID to match with in the HOB list.\r
565\r
566 Buffer - A pointer to the pointer to the data for the custom HOB type.\r
567\r
568 BufferSize - A Pointer to the size in byte of BufferSize.\r
569\r
570Returns:\r
571 EFI_SUCCESS\r
572 The first instance of the matched GUID HOB among the whole HOB list\r
573\r
574--*/\r
575{\r
576 EFI_STATUS Status;\r
577 EFI_PEI_HOB_POINTERS GuidHob;\r
578 \r
579 GuidHob.Raw = *HobStart;\r
580\r
581 for (Status = EFI_NOT_FOUND; EFI_ERROR (Status); ) {\r
582 \r
583 if (END_OF_HOB_LIST (GuidHob)) {\r
584 return EFI_NOT_FOUND;\r
585 }\r
586 \r
587 if (GuidHob.Header->HobType == EFI_HOB_TYPE_GUID_EXTENSION) { \r
588 if ( ((INT32 *)Guid)[0] == ((INT32 *)&GuidHob.Guid->Name)[0] &&\r
589 ((INT32 *)Guid)[1] == ((INT32 *)&GuidHob.Guid->Name)[1] &&\r
590 ((INT32 *)Guid)[2] == ((INT32 *)&GuidHob.Guid->Name)[2] &&\r
591 ((INT32 *)Guid)[3] == ((INT32 *)&GuidHob.Guid->Name)[3] ) {\r
592 Status = EFI_SUCCESS;\r
593 *Buffer = (VOID *)((UINT8 *)(&GuidHob.Guid->Name) + sizeof (EFI_GUID));\r
594 if (BufferSize) {\r
595 *BufferSize = GuidHob.Header->HobLength - sizeof (EFI_HOB_GUID_TYPE);\r
596 }\r
597 }\r
598 }\r
599\r
600 GuidHob.Raw = GET_NEXT_HOB (GuidHob);\r
601 }\r
602\r
603 return Status;\r
604}\r
c7f33ca4 605\r
606VOID *\r
607GetHob (\r
608 IN UINT16 Type,\r
609 IN VOID *HobStart\r
610 )\r
611/*++\r
612\r
613Routine Description:\r
614\r
615 This function returns the first instance of a HOB type in a HOB list.\r
616 \r
617Arguments:\r
618\r
619 Type The HOB type to return.\r
620 HobStart The first HOB in the HOB list.\r
621 \r
622Returns:\r
623\r
624 HobStart There were no HOBs found with the requested type.\r
625 else Returns the first HOB with the matching type.\r
626\r
627--*/\r
628{\r
629 EFI_PEI_HOB_POINTERS Hob;\r
630\r
631 Hob.Raw = HobStart;\r
632 //\r
633 // Return input if not found\r
634 //\r
635 if (HobStart == NULL) {\r
636 return HobStart;\r
637 }\r
638\r
639 //\r
640 // Parse the HOB list, stop if end of list or matching type found.\r
641 //\r
642 while (!END_OF_HOB_LIST (Hob)) {\r
643\r
644 if (Hob.Header->HobType == Type) {\r
645 break;\r
646 }\r
647\r
648 Hob.Raw = GET_NEXT_HOB (Hob);\r
649 }\r
650 \r
651 //\r
652 // Return input if not found\r
653 //\r
654 if (END_OF_HOB_LIST (Hob)) {\r
655 return HobStart;\r
656 }\r
657\r
658 return (VOID *) (Hob.Raw);\r
659}\r
660\r
661EFI_STATUS\r
662GetNextGuidHob (\r
663 IN OUT VOID **HobStart,\r
664 IN EFI_GUID * Guid,\r
665 OUT VOID **Buffer,\r
666 OUT UINTN *BufferSize OPTIONAL\r
667 )\r
668/*++\r
669\r
670Routine Description:\r
671 Get the next guid hob.\r
672 \r
673Arguments:\r
674 HobStart A pointer to the start hob.\r
675 Guid A pointer to a guid.\r
676 Buffer A pointer to the buffer.\r
677 BufferSize Buffer size.\r
678 \r
679Returns:\r
680 Status code.\r
681\r
682 EFI_NOT_FOUND - Next Guid hob not found\r
683 \r
684 EFI_SUCCESS - Next Guid hob found and data for this Guid got\r
685 \r
686 EFI_INVALID_PARAMETER - invalid parameter\r
687\r
688--*/\r
689{\r
690 EFI_STATUS Status;\r
691 EFI_PEI_HOB_POINTERS GuidHob;\r
692\r
693 if (Buffer == NULL) {\r
694 return EFI_INVALID_PARAMETER;\r
695 }\r
696\r
697 for (Status = EFI_NOT_FOUND; EFI_ERROR (Status);) {\r
698\r
699 GuidHob.Raw = *HobStart;\r
700 if (END_OF_HOB_LIST (GuidHob)) {\r
701 return EFI_NOT_FOUND;\r
702 }\r
703\r
704 GuidHob.Raw = GetHob (EFI_HOB_TYPE_GUID_EXTENSION, *HobStart);\r
705 if (GuidHob.Header->HobType == EFI_HOB_TYPE_GUID_EXTENSION) {\r
706 if ( ((INT32 *)Guid)[0] == ((INT32 *)&GuidHob.Guid->Name)[0] &&\r
707 ((INT32 *)Guid)[1] == ((INT32 *)&GuidHob.Guid->Name)[1] &&\r
708 ((INT32 *)Guid)[2] == ((INT32 *)&GuidHob.Guid->Name)[2] &&\r
709 ((INT32 *)Guid)[3] == ((INT32 *)&GuidHob.Guid->Name)[3] ) {\r
710 Status = EFI_SUCCESS;\r
711 *Buffer = (VOID *) ((UINT8 *) (&GuidHob.Guid->Name) + sizeof (EFI_GUID));\r
712 if (BufferSize != NULL) {\r
713 *BufferSize = GuidHob.Header->HobLength - sizeof (EFI_HOB_GUID_TYPE);\r
714 }\r
715 }\r
716 }\r
717\r
718 *HobStart = GET_NEXT_HOB (GuidHob);\r
719 }\r
720\r
721 return Status;\r
722}\r