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