]> git.proxmox.com Git - mirror_edk2.git/blob - 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
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 Length = (Length + 0x7) & (~0x7);
277 Hob.Header->HobLength = (UINT16)Length;
278 CopyMem(&Hob.Guid->Name, Guid, sizeof(EFI_GUID));
279 CopyMem(Hob.Raw + sizeof(EFI_HOB_GUID_TYPE), Buffer, BufferSize);
280 Hob.Raw += Length;
281
282 HandOffHob.HandoffInformationTable->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS) (UINTN) Hob.Raw;
283 Hob = BuildHobEndOfHobList(Hob.Raw);
284 HandOffHob.HandoffInformationTable->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN) Hob.Raw;
285 return EFI_SUCCESS;
286 }
287
288 EFI_STATUS
289 BuildHobFvDescriptor (
290 IN VOID *HobStart,
291 IN EFI_PHYSICAL_ADDRESS BaseAddress,
292 IN UINT64 Length
293 )
294 /*++
295
296 Routine Description:
297
298 Builds a Firmware Volume HOB
299
300 Arguments:
301
302 HobStart - Start pointer of hob list
303
304 BaseAddress - The base address of the Firmware Volume
305
306 Length - The size of the Firmware Volume in bytes
307
308 Returns:
309
310 EFI_SUCCESS
311 EFI_NOT_AVAILABLE_YET
312
313 --*/
314 {
315 EFI_PEI_HOB_POINTERS Hob;
316 EFI_PEI_HOB_POINTERS HandOffHob;
317
318 HandOffHob.Raw = HobStart;
319 Hob.Raw = (VOID*)(UINTN)(HandOffHob.HandoffInformationTable->EfiEndOfHobList);
320
321 Hob.Header->HobType = EFI_HOB_TYPE_FV;
322 Hob.Header->HobLength = sizeof(EFI_HOB_FIRMWARE_VOLUME);
323
324 Hob.FirmwareVolume->BaseAddress = BaseAddress;
325 Hob.FirmwareVolume->Length = Length;
326
327 Hob.FirmwareVolume++;
328
329 HandOffHob.HandoffInformationTable->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS) (UINTN) Hob.Raw;
330 Hob = BuildHobEndOfHobList(Hob.Raw);
331 HandOffHob.HandoffInformationTable->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN) Hob.Raw;
332 return EFI_SUCCESS;
333 }
334
335 EFI_STATUS
336 BuildHobCpu (
337 IN VOID *HobStart,
338 IN UINT8 SizeOfMemorySpace,
339 IN UINT8 SizeOfIoSpace
340 )
341 /*++
342
343 Routine Description:
344
345 Builds a HOB for the CPU
346
347 Arguments:
348
349 HobStart - Start pointer of hob list
350
351 SizeOfMemorySpace - Identifies the maximum
352 physical memory addressibility of the processor.
353
354 SizeOfIoSpace - Identifies the maximum physical I/O addressibility
355 of the processor.
356
357 Returns:
358
359 EFI_SUCCESS
360 EFI_NOT_AVAILABLE_YET
361
362 --*/
363 {
364 EFI_PEI_HOB_POINTERS Hob;
365 EFI_PEI_HOB_POINTERS HandOffHob;
366
367 HandOffHob.Raw = HobStart;
368 Hob.Raw = (VOID*)(UINTN)HandOffHob.HandoffInformationTable->EfiEndOfHobList;
369
370 Hob.Header->HobType = EFI_HOB_TYPE_CPU;
371 Hob.Header->HobLength = sizeof(EFI_HOB_CPU);
372
373 Hob.Cpu->SizeOfMemorySpace = SizeOfMemorySpace;
374 Hob.Cpu->SizeOfIoSpace = SizeOfIoSpace;
375
376 Hob.Cpu++;
377 HandOffHob.HandoffInformationTable->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS) (UINTN) Hob.Raw;
378 Hob = BuildHobEndOfHobList(Hob.Raw);
379 HandOffHob.HandoffInformationTable->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN) Hob.Raw;
380 return EFI_SUCCESS;
381 }
382
383
384
385 EFI_STATUS
386 BuildHobStack (
387 IN VOID *HobStart,
388 IN EFI_PHYSICAL_ADDRESS BaseAddress,
389 IN UINT64 Length
390 )
391 /*++
392
393 Routine Description:
394
395 Builds a HOB for the Stack
396
397 Arguments:
398
399 HobStart - Start pointer of hob list
400
401 BaseAddress - The 64 bit physical address of the Stack
402
403 Length - The length of the stack in bytes
404
405 Returns:
406
407 EFI_SUCCESS
408 EFI_NOT_AVAILABLE_YET
409
410 --*/
411 {
412 EFI_PEI_HOB_POINTERS Hob;
413 EFI_PEI_HOB_POINTERS HandOffHob;
414
415 HandOffHob.Raw = HobStart;
416 Hob.Raw = (VOID*)(UINTN)HandOffHob.HandoffInformationTable->EfiEndOfHobList;
417
418 Hob.Header->HobType = EFI_HOB_TYPE_MEMORY_ALLOCATION;
419 Hob.Header->HobLength = sizeof(EFI_HOB_MEMORY_ALLOCATION_STACK);
420
421 CopyMem(&(Hob.MemoryAllocationStack->AllocDescriptor.Name), &gEfiHobMemeryAllocStackGuid, sizeof(EFI_GUID));
422 (Hob.MemoryAllocationStack->AllocDescriptor).MemoryBaseAddress = BaseAddress;
423 (Hob.MemoryAllocationStack->AllocDescriptor).MemoryLength = Length;
424 (Hob.MemoryAllocationStack->AllocDescriptor).MemoryType = EfiBootServicesData;
425
426 Hob.MemoryAllocationStack++;
427 HandOffHob.HandoffInformationTable->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS) (UINTN) Hob.Raw;
428 Hob = BuildHobEndOfHobList(Hob.Raw);
429 HandOffHob.HandoffInformationTable->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN) Hob.Raw;
430 return EFI_SUCCESS;
431 }
432
433
434
435 EFI_STATUS
436 BuildHobBspStore (
437 IN VOID *HobStart,
438 IN EFI_PHYSICAL_ADDRESS BaseAddress,
439 IN UINT64 Length,
440 IN EFI_MEMORY_TYPE MemoryType
441 )
442 /*++
443
444 Routine Description:
445
446 Builds a HOB for the bsp store
447
448 Arguments:
449
450 HobStart - Start pointer of hob list
451
452 BaseAddress - The 64 bit physical address of bsp store
453
454 Length - The length of the bsp store in bytes
455
456 MemoryType - Memory type of the bsp store
457
458 Returns:
459
460 EFI_SUCCESS
461 EFI_NOT_AVAILABLE_YET
462
463 --*/
464 {
465 EFI_PEI_HOB_POINTERS Hob;
466 EFI_PEI_HOB_POINTERS HandOffHob;
467
468 HandOffHob.Raw = HobStart;
469 Hob.Raw = (VOID *)(UINTN)HandOffHob.HandoffInformationTable->EfiEndOfHobList;
470 Hob.Header->HobType = EFI_HOB_TYPE_MEMORY_ALLOCATION;
471 Hob.Header->HobLength = sizeof(EFI_HOB_MEMORY_ALLOCATION_BSP_STORE);
472
473 (Hob.MemoryAllocationBspStore->AllocDescriptor).MemoryBaseAddress = BaseAddress;
474 (Hob.MemoryAllocationBspStore->AllocDescriptor).MemoryLength = Length;
475 (Hob.MemoryAllocationBspStore->AllocDescriptor).MemoryType = MemoryType;
476 CopyMem(&(Hob.MemoryAllocationBspStore->AllocDescriptor).Name, &gEfiHobMemeryAllocBspStoreGuid, sizeof(EFI_GUID));
477 Hob.MemoryAllocationBspStore++;
478
479 HandOffHob.HandoffInformationTable->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS) (UINTN) Hob.Raw;
480 Hob = BuildHobEndOfHobList(Hob.Raw);
481 HandOffHob.HandoffInformationTable->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN) Hob.Raw;
482 return EFI_SUCCESS;
483 }
484
485
486 EFI_STATUS
487 BuildMemoryAllocationHob (
488 IN VOID *HobStart,
489 IN EFI_PHYSICAL_ADDRESS BaseAddress,
490 IN UINT64 Length,
491 IN EFI_GUID *Name,
492 IN EFI_MEMORY_TYPE MemoryType
493 )
494 /*++
495
496 Routine Description:
497
498 Builds a HOB for memory allocation
499
500 Arguments:
501
502 HobStart - Start pointer of hob list
503
504 BaseAddress - The base address of memory allocated by this HOB.
505
506 Length - The length in bytes of memory allocated by this HOB.
507
508 Name - A GUID that defines the memory allocation region's type and purpose,
509 as well as other fields within the memory allocation HOB.
510
511 MemoryType - Defines the type of memory allocated by this HOB.
512
513 Returns:
514
515 EFI_SUCCESS
516 EFI_NOT_AVAILABLE_YET
517
518 --*/
519 {
520 EFI_PEI_HOB_POINTERS Hob;
521 EFI_PEI_HOB_POINTERS HandOffHob;
522
523
524 HandOffHob.Raw = HobStart;
525 Hob.Raw = (VOID*)(UINTN)HandOffHob.HandoffInformationTable->EfiEndOfHobList;
526
527 Hob.Header->HobType = EFI_HOB_TYPE_MEMORY_ALLOCATION;
528 Hob.Header->HobLength = sizeof(EFI_HOB_MEMORY_ALLOCATION);
529
530 if (Name != NULL) {
531 CopyMem(&(Hob.MemoryAllocation->AllocDescriptor.Name), &Name, sizeof(EFI_GUID));
532 } else {
533 ZeroMem(&Hob.MemoryAllocation->AllocDescriptor.Name, sizeof(EFI_GUID));
534 }
535
536 (Hob.MemoryAllocation->AllocDescriptor).MemoryBaseAddress = BaseAddress;
537 (Hob.MemoryAllocation->AllocDescriptor).MemoryLength = Length;
538 (Hob.MemoryAllocation->AllocDescriptor).MemoryType = MemoryType;
539
540 Hob.MemoryAllocation++;
541 HandOffHob.HandoffInformationTable->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS) (UINTN) Hob.Raw;
542 Hob = BuildHobEndOfHobList(Hob.Raw);
543 HandOffHob.HandoffInformationTable->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN) Hob.Raw;
544 return EFI_SUCCESS;
545 }
546
547 EFI_STATUS
548 GetFirstGuidHob (
549 IN VOID **HobStart,
550 IN EFI_GUID *Guid,
551 OUT VOID **Buffer,
552 OUT UINTN *BufferSize OPTIONAL
553 )
554 /*++
555
556 Routine Description:
557
558 This function searches the first instance of a HOB among the whole HOB list.
559
560 Arguments:
561
562 HobStart - A pointer to the start pointer of hob list.
563
564 Guid - A pointer to the GUID to match with in the HOB list.
565
566 Buffer - A pointer to the pointer to the data for the custom HOB type.
567
568 BufferSize - A Pointer to the size in byte of BufferSize.
569
570 Returns:
571 EFI_SUCCESS
572 The first instance of the matched GUID HOB among the whole HOB list
573
574 --*/
575 {
576 EFI_STATUS Status;
577 EFI_PEI_HOB_POINTERS GuidHob;
578
579 GuidHob.Raw = *HobStart;
580
581 for (Status = EFI_NOT_FOUND; EFI_ERROR (Status); ) {
582
583 if (END_OF_HOB_LIST (GuidHob)) {
584 return EFI_NOT_FOUND;
585 }
586
587 if (GuidHob.Header->HobType == EFI_HOB_TYPE_GUID_EXTENSION) {
588 if ( ((INT32 *)Guid)[0] == ((INT32 *)&GuidHob.Guid->Name)[0] &&
589 ((INT32 *)Guid)[1] == ((INT32 *)&GuidHob.Guid->Name)[1] &&
590 ((INT32 *)Guid)[2] == ((INT32 *)&GuidHob.Guid->Name)[2] &&
591 ((INT32 *)Guid)[3] == ((INT32 *)&GuidHob.Guid->Name)[3] ) {
592 Status = EFI_SUCCESS;
593 *Buffer = (VOID *)((UINT8 *)(&GuidHob.Guid->Name) + sizeof (EFI_GUID));
594 if (BufferSize) {
595 *BufferSize = GuidHob.Header->HobLength - sizeof (EFI_HOB_GUID_TYPE);
596 }
597 }
598 }
599
600 GuidHob.Raw = GET_NEXT_HOB (GuidHob);
601 }
602
603 return Status;
604 }
605
606 VOID *
607 GetHob (
608 IN UINT16 Type,
609 IN VOID *HobStart
610 )
611 /*++
612
613 Routine Description:
614
615 This function returns the first instance of a HOB type in a HOB list.
616
617 Arguments:
618
619 Type The HOB type to return.
620 HobStart The first HOB in the HOB list.
621
622 Returns:
623
624 HobStart There were no HOBs found with the requested type.
625 else Returns the first HOB with the matching type.
626
627 --*/
628 {
629 EFI_PEI_HOB_POINTERS Hob;
630
631 Hob.Raw = HobStart;
632 //
633 // Return input if not found
634 //
635 if (HobStart == NULL) {
636 return HobStart;
637 }
638
639 //
640 // Parse the HOB list, stop if end of list or matching type found.
641 //
642 while (!END_OF_HOB_LIST (Hob)) {
643
644 if (Hob.Header->HobType == Type) {
645 break;
646 }
647
648 Hob.Raw = GET_NEXT_HOB (Hob);
649 }
650
651 //
652 // Return input if not found
653 //
654 if (END_OF_HOB_LIST (Hob)) {
655 return HobStart;
656 }
657
658 return (VOID *) (Hob.Raw);
659 }
660
661 EFI_STATUS
662 GetNextGuidHob (
663 IN OUT VOID **HobStart,
664 IN EFI_GUID * Guid,
665 OUT VOID **Buffer,
666 OUT UINTN *BufferSize OPTIONAL
667 )
668 /*++
669
670 Routine Description:
671 Get the next guid hob.
672
673 Arguments:
674 HobStart A pointer to the start hob.
675 Guid A pointer to a guid.
676 Buffer A pointer to the buffer.
677 BufferSize Buffer size.
678
679 Returns:
680 Status code.
681
682 EFI_NOT_FOUND - Next Guid hob not found
683
684 EFI_SUCCESS - Next Guid hob found and data for this Guid got
685
686 EFI_INVALID_PARAMETER - invalid parameter
687
688 --*/
689 {
690 EFI_STATUS Status;
691 EFI_PEI_HOB_POINTERS GuidHob;
692
693 if (Buffer == NULL) {
694 return EFI_INVALID_PARAMETER;
695 }
696
697 for (Status = EFI_NOT_FOUND; EFI_ERROR (Status);) {
698
699 GuidHob.Raw = *HobStart;
700 if (END_OF_HOB_LIST (GuidHob)) {
701 return EFI_NOT_FOUND;
702 }
703
704 GuidHob.Raw = GetHob (EFI_HOB_TYPE_GUID_EXTENSION, *HobStart);
705 if (GuidHob.Header->HobType == EFI_HOB_TYPE_GUID_EXTENSION) {
706 if ( ((INT32 *)Guid)[0] == ((INT32 *)&GuidHob.Guid->Name)[0] &&
707 ((INT32 *)Guid)[1] == ((INT32 *)&GuidHob.Guid->Name)[1] &&
708 ((INT32 *)Guid)[2] == ((INT32 *)&GuidHob.Guid->Name)[2] &&
709 ((INT32 *)Guid)[3] == ((INT32 *)&GuidHob.Guid->Name)[3] ) {
710 Status = EFI_SUCCESS;
711 *Buffer = (VOID *) ((UINT8 *) (&GuidHob.Guid->Name) + sizeof (EFI_GUID));
712 if (BufferSize != NULL) {
713 *BufferSize = GuidHob.Header->HobLength - sizeof (EFI_HOB_GUID_TYPE);
714 }
715 }
716 }
717
718 *HobStart = GET_NEXT_HOB (GuidHob);
719 }
720
721 return Status;
722 }