]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Conf/Migration/R8Lib.c
Add link Map option for GCC tool to generate map file.
[mirror_edk2.git] / Tools / Conf / Migration / R8Lib.c
1 /** @file
2 Obsolete library interfaces.
3
4 This file contains part of obsolete library interfaces in EDK.
5 User is recommended to follow the porting Guide in R8Lib.c to elimante them.
6
7 Copyright (c) 2006, Intel Corporation
8 All rights reserved. This program and the accompanying materials
9 are licensed and made available under the terms and conditions of the BSD License
10 which accompanies this distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
12
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15
16 **/
17
18 ////#UefiBootServicesTableLib
19 EFI_STATUS
20 R8_EfiLibInstallDriverBinding (
21 IN EFI_HANDLE ImageHandle,
22 IN EFI_SYSTEM_TABLE *SystemTable,
23 IN EFI_DRIVER_BINDING_PROTOCOL *DriverBinding,
24 IN EFI_HANDLE DriverBindingHandle
25 )
26 /*++
27
28 Routine Description:
29
30 Intialize a driver by installing the Driver Binding Protocol onto the
31 driver's DriverBindingHandle. This is typically the same as the driver's
32 ImageHandle, but it can be different if the driver produces multiple
33 DriverBinding Protocols. This function also initializes the EFI Driver
34 Library that initializes the global variables gST, gBS, gRT.
35
36 Arguments:
37
38 ImageHandle - The image handle of the driver.
39 SystemTable - The EFI System Table that was passed to the driver's entry point
40 DriverBinding - A Driver Binding Protocol instance that this driver is producing
41 DriverBindingHandle - The handle that DriverBinding is to be installe onto. If this
42 parameter is NULL, then a new handle is created.
43
44 Returns:
45
46 EFI_SUCCESS - DriverBinding is installed onto DriverBindingHandle
47 Others - Some error occurs when executing gBS->InstallProtocolInterface()
48
49 --*/
50 {
51 //
52 // Porting Guide:
53 // This obsolete Edk library interface installs driver binding protocol.
54 // If the entry point of that module ONLY invokes this function, it can
55 // use UefiDriverModuleLib in MdePkg and expose "DriverBinding" protocol interface
56 // at the <Externs> tag, build tool will auto generate code to handle it.
57 // For example:
58 // <Externs>
59 // <Extern>
60 // <DriverBinding>gFatDriverBinding</DriverBinding>
61 // </Extern>
62 // </Externs>
63 //
64 DriverBinding->ImageHandle = ImageHandle;
65 DriverBinding->DriverBindingHandle = DriverBindingHandle;
66
67 return gBS->InstallProtocolInterface (
68 &DriverBinding->DriverBindingHandle,
69 &gEfiDriverBindingProtocolGuid,
70 EFI_NATIVE_INTERFACE,
71 DriverBinding
72 );
73 }
74 ////~
75
76 ////#UefiBootServicesTableLib
77 EFI_STATUS
78 R8_EfiLibInstallAllDriverProtocols (
79 IN EFI_HANDLE ImageHandle,
80 IN EFI_SYSTEM_TABLE *SystemTable,
81 IN EFI_DRIVER_BINDING_PROTOCOL *DriverBinding,
82 IN EFI_HANDLE DriverBindingHandle,
83 IN EFI_COMPONENT_NAME_PROTOCOL *ComponentName, OPTIONAL
84 IN EFI_DRIVER_CONFIGURATION_PROTOCOL *DriverConfiguration, OPTIONAL
85 IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL *DriverDiagnostics OPTIONAL
86 )
87 /*++
88
89 Routine Description:
90
91 Intialize a driver by installing the Driver Binding Protocol onto the
92 driver's DriverBindingHandle. This is typically the same as the driver's
93 ImageHandle, but it can be different if the driver produces multiple
94 DriverBinding Protocols. This function also initializes the EFI Driver
95 Library that initializes the global variables gST, gBS, gRT.
96
97 Arguments:
98
99 ImageHandle - The image handle of the driver
100 SystemTable - The EFI System Table that was passed to the driver's entry point
101 DriverBinding - A Driver Binding Protocol instance that this driver is producing
102 DriverBindingHandle - The handle that DriverBinding is to be installe onto. If this
103 parameter is NULL, then a new handle is created.
104 ComponentName - A Component Name Protocol instance that this driver is producing
105 DriverConfiguration - A Driver Configuration Protocol instance that this driver is producing
106 DriverDiagnostics - A Driver Diagnostics Protocol instance that this driver is producing
107
108 Returns:
109
110 EFI_SUCCESS - DriverBinding is installed onto DriverBindingHandle
111 Others - Some error occurs when executing gBS->InstallProtocolInterface()
112
113 --*/
114 {
115 //
116 // Porting Guide:
117 // This obsolete Edk library interface installs driver binding protocol
118 // with optional component name, driver configuration & driver diagnotics protocols.
119 // If the entry point of that module ONLY invokes this function, it can
120 // use UefiDriverModuleLib in MdePkg and expose "DriverBinding", "ComponentName",
121 // "DriverConfiguration" and "DriverDiagnostics" protocol interfaces.
122 // at the <Externs> tag, build tool will auto generate code to handle it.
123 // For example:
124 // <Externs>
125 // <Extern>
126 // <DriverBinding>gFatDriverBinding</DriverBinding>
127 // </Extern>
128 // <Extern>
129 // <ComponentName>gFatComponentName</ComponentName>
130 // </Extern>
131 // </Externs>
132 //
133 EFI_STATUS Status;
134
135 DriverBinding->ImageHandle = ImageHandle;
136 DriverBinding->DriverBindingHandle = DriverBindingHandle;
137
138 Status = gBS->InstallProtocolInterface (
139 &DriverBinding->DriverBindingHandle,
140 &gEfiDriverBindingProtocolGuid,
141 EFI_NATIVE_INTERFACE,
142 DriverBinding
143 );
144 if (EFI_ERROR (Status)) {
145 return Status;
146 }
147
148 if (ComponentName != NULL) {
149 Status = gBS->InstallProtocolInterface (
150 &DriverBinding->DriverBindingHandle,
151 &gEfiComponentNameProtocolGuid,
152 EFI_NATIVE_INTERFACE,
153 ComponentName
154 );
155 if (EFI_ERROR (Status)) {
156 return Status;
157 }
158 }
159
160 if (DriverConfiguration != NULL) {
161 Status = gBS->InstallProtocolInterface (
162 &DriverBinding->DriverBindingHandle,
163 &gEfiDriverConfigurationProtocolGuid,
164 EFI_NATIVE_INTERFACE,
165 DriverConfiguration
166 );
167 if (EFI_ERROR (Status)) {
168 return Status;
169 }
170 }
171
172 if (DriverDiagnostics != NULL) {
173 Status = gBS->InstallProtocolInterface (
174 &DriverBinding->DriverBindingHandle,
175 &gEfiDriverDiagnosticsProtocolGuid,
176 EFI_NATIVE_INTERFACE,
177 DriverDiagnostics
178 );
179 if (EFI_ERROR (Status)) {
180 return Status;
181 }
182 }
183
184 return EFI_SUCCESS;
185 }
186 ////~
187
188 ////
189 BOOLEAN
190 R8_EfiLibCompareLanguage (
191 IN CHAR8 *Language1,
192 IN CHAR8 *Language2
193 )
194 /*++
195
196 Routine Description:
197
198 Compare whether two names of languages are identical.
199
200 Arguments:
201
202 Language1 - Name of language 1
203 Language2 - Name of language 2
204
205 Returns:
206
207 TRUE - same
208 FALSE - not same
209
210 --*/
211 {
212 //
213 // Porting Guide:
214 // This library interface is simply obsolete.
215 // Include the source code to user code.
216 //
217 UINTN Index;
218
219 for (Index = 0; Index < 3; Index++) {
220 if (Language1[Index] != Language2[Index]) {
221 return FALSE;
222 }
223 }
224
225 return TRUE;
226 }
227 ////~
228
229 ////#BaseLib
230 EFI_STATUS
231 R8_BufToHexString (
232 IN OUT CHAR16 *Str,
233 IN OUT UINTN *HexStringBufferLength,
234 IN UINT8 *Buf,
235 IN UINTN Len
236 )
237 /*++
238
239 Routine Description:
240 Converts binary buffer to Unicode string.
241 At a minimum, any blob of data could be represented as a hex string.
242
243 Arguments:
244 Str - Pointer to the string.
245 HexStringBufferLength - Length in bytes of buffer to hold the hex string. Includes tailing '\0' character.
246 If routine return with EFI_SUCCESS, containing length of hex string buffer.
247 If routine return with EFI_BUFFER_TOO_SMALL, containg length of hex string buffer desired.
248 Buf - Buffer to be converted from.
249 Len - Length in bytes of the buffer to be converted.
250
251 Returns:
252 EFI_SUCCESS - Routine success.
253 EFI_BUFFER_TOO_SMALL - The hex string buffer is too small.
254
255 --*/
256 {
257 //
258 // Porting Guide:
259 // This library interface is simply obsolete.
260 // Include the source code to user code.
261 //
262 UINTN Idx;
263 UINT8 Byte;
264 UINTN StrLen;
265
266 //
267 // Make sure string is either passed or allocate enough.
268 // It takes 2 Unicode characters (4 bytes) to represent 1 byte of the binary buffer.
269 // Plus the Unicode termination character.
270 //
271 StrLen = Len * 2;
272 if (StrLen > ((*HexStringBufferLength) - 1)) {
273 *HexStringBufferLength = StrLen + 1;
274 return EFI_BUFFER_TOO_SMALL;
275 }
276
277 *HexStringBufferLength = StrLen + 1;
278 //
279 // Ends the string.
280 //
281 Str[StrLen] = L'\0';
282
283 for (Idx = 0; Idx < Len; Idx++) {
284
285 Byte = Buf[Idx];
286 Str[StrLen - 1 - Idx * 2] = NibbleToHexChar (Byte);
287 Str[StrLen - 2 - Idx * 2] = NibbleToHexChar ((UINT8)(Byte >> 4));
288 }
289
290 return EFI_SUCCESS;
291 }
292 ////~
293
294 ////
295 VOID
296 R8_EfiStrTrim (
297 IN OUT CHAR16 *str,
298 IN CHAR16 CharC
299 )
300 /*++
301
302 Routine Description:
303
304 Removes (trims) specified leading and trailing characters from a string.
305
306 Arguments:
307
308 str - Pointer to the null-terminated string to be trimmed. On return,
309 str will hold the trimmed string.
310 CharC - Character will be trimmed from str.
311
312 --*/
313 {
314 //
315 // Porting Guide:
316 // This library interface is simply obsolete.
317 // Include the source code to user code.
318 //
319 CHAR16 *p1;
320 CHAR16 *p2;
321
322 if (*str == 0) {
323 return;
324 }
325
326 //
327 // Trim off the leading and trailing characters c
328 //
329 for (p1 = str; *p1 && *p1 == CharC; p1++) {
330 ;
331 }
332
333 p2 = str;
334 if (p2 == p1) {
335 while (*p1) {
336 p2++;
337 p1++;
338 }
339 } else {
340 while (*p1) {
341 *p2 = *p1;
342 p1++;
343 p2++;
344 }
345 *p2 = 0;
346 }
347
348
349 for (p1 = str + StrLen(str) - 1; p1 >= str && *p1 == CharC; p1--) {
350 ;
351 }
352 if (p1 != str + StrLen(str) - 1) {
353 *(p1 + 1) = 0;
354 }
355 }
356 ////~
357
358 ////#PrintLib
359 UINTN
360 R8_EfiValueToHexStr (
361 IN OUT CHAR16 *Buffer,
362 IN UINT64 Value,
363 IN UINTN Flags,
364 IN UINTN Width
365 )
366 /*++
367
368 Routine Description:
369
370 VSPrint worker function that prints a Value as a hex number in Buffer
371
372 Arguments:
373
374 Buffer - Location to place ascii hex string of Value.
375 Value - Hex value to convert to a string in Buffer.
376 Flags - Flags to use in printing Hex string, see file header for details.
377 Width - Width of hex value.
378
379 Returns:
380
381 Number of characters printed.
382
383 --*/
384 {
385 //
386 // Porting Guide:
387 // Edk II BasePrintLib function UnicodeValueToString does not support
388 // to convert Value to Hex String.
389 // Include the source code to user code or use the full PrintLib funtion
390 // UnicodeVSPrintAsciiFormat (Buffer, MAXIMUM_VALUE_CHARACTERS, "%x", Value) instead.
391 //
392
393 CHAR16 TempBuffer[MAXIMUM_VALUE_CHARACTERS];
394 CHAR16 *TempStr;
395 CHAR16 Prefix;
396 CHAR16 *BufferPtr;
397 UINTN Count;
398 UINTN Index;
399
400 TempStr = TempBuffer;
401 BufferPtr = Buffer;
402
403 //
404 // Count starts at one since we will null terminate. Each iteration of the
405 // loop picks off one nibble. Oh yea TempStr ends up backwards
406 //
407 Count = 0;
408
409 if (Width > MAXIMUM_VALUE_CHARACTERS - 1) {
410 Width = MAXIMUM_VALUE_CHARACTERS - 1;
411 }
412
413 do {
414 //
415 // If Width == 0, it means no limit.
416 //
417 if ((Width != 0) && (Count >= Width)) {
418 break;
419 }
420
421 Index = ((UINTN)Value & 0xf);
422 *(TempStr++) = mHexStr[Index];
423 Value = RShiftU64 (Value, 4);
424 Count++;
425 } while (Value != 0);
426
427 if (Flags & PREFIX_ZERO) {
428 Prefix = '0';
429 } else {
430 Prefix = ' ';
431 }
432
433 Index = Count;
434 if (!(Flags & LEFT_JUSTIFY)) {
435 for (; Index < Width; Index++) {
436 *(TempStr++) = Prefix;
437 }
438 }
439
440 //
441 // Reverse temp string into Buffer.
442 //
443 while (TempStr != TempBuffer) {
444 *(BufferPtr++) = *(--TempStr);
445 }
446
447 *BufferPtr = 0;
448 return Index;
449 }
450 ////~
451
452
453
454 ////
455 EFI_STATUS
456 R8_HexStringToBuf (
457 IN OUT UINT8 *Buf,
458 IN OUT UINTN *Len,
459 IN CHAR16 *Str,
460 OUT UINTN *ConvertedStrLen OPTIONAL
461 )
462 /*++
463
464 Routine Description:
465 Converts Unicode string to binary buffer.
466 The conversion may be partial.
467 The first character in the string that is not hex digit stops the conversion.
468 At a minimum, any blob of data could be represented as a hex string.
469
470 Arguments:
471 Buf - Pointer to buffer that receives the data.
472 Len - Length in bytes of the buffer to hold converted data.
473 If routine return with EFI_SUCCESS, containing length of converted data.
474 If routine return with EFI_BUFFER_TOO_SMALL, containg length of buffer desired.
475 Str - String to be converted from.
476 ConvertedStrLen - Length of the Hex String consumed.
477
478 Returns:
479 EFI_SUCCESS - Routine Success.
480 EFI_BUFFER_TOO_SMALL - The buffer is too small to hold converted data.
481
482 --*/
483 {
484 //
485 // Porting Guide:
486 // This library interface is simply obsolete.
487 // Include the source code to user code.
488 //
489
490 UINTN HexCnt;
491 UINTN Idx;
492 UINTN BufferLength;
493 UINT8 Digit;
494 UINT8 Byte;
495
496 //
497 // Find out how many hex characters the string has.
498 //
499 for (Idx = 0, HexCnt = 0; IsHexDigit (&Digit, Str[Idx]); Idx++, HexCnt++);
500
501 if (HexCnt == 0) {
502 *Len = 0;
503 return EFI_SUCCESS;
504 }
505 //
506 // Two Unicode characters make up 1 buffer byte. Round up.
507 //
508 BufferLength = (HexCnt + 1) / 2;
509
510 //
511 // Test if buffer is passed enough.
512 //
513 if (BufferLength > (*Len)) {
514 *Len = BufferLength;
515 return EFI_BUFFER_TOO_SMALL;
516 }
517
518 *Len = BufferLength;
519
520 for (Idx = 0; Idx < HexCnt; Idx++) {
521
522 IsHexDigit (&Digit, Str[HexCnt - 1 - Idx]);
523
524 //
525 // For odd charaters, write the lower nibble for each buffer byte,
526 // and for even characters, the upper nibble.
527 //
528 if ((Idx & 1) == 0) {
529 Byte = Digit;
530 } else {
531 Byte = Buf[Idx / 2];
532 Byte &= 0x0F;
533 Byte |= Digit << 4;
534 }
535
536 Buf[Idx / 2] = Byte;
537 }
538
539 if (ConvertedStrLen != NULL) {
540 *ConvertedStrLen = HexCnt;
541 }
542
543 return EFI_SUCCESS;
544 }
545 ////~
546
547 ////
548 BOOLEAN
549 R8_IsHexDigit (
550 OUT UINT8 *Digit,
551 IN CHAR16 Char
552 )
553 /*++
554
555 Routine Description:
556 Determines if a Unicode character is a hexadecimal digit.
557 The test is case insensitive.
558
559 Arguments:
560 Digit - Pointer to byte that receives the value of the hex character.
561 Char - Unicode character to test.
562
563 Returns:
564 TRUE - If the character is a hexadecimal digit.
565 FALSE - Otherwise.
566
567 --*/
568 {
569 //
570 // Porting Guide:
571 // This library interface is simply obsolete.
572 // Include the source code to user code.
573 //
574
575 if ((Char >= L'0') && (Char <= L'9')) {
576 *Digit = (UINT8) (Char - L'0');
577 return TRUE;
578 }
579
580 if ((Char >= L'A') && (Char <= L'F')) {
581 *Digit = (UINT8) (Char - L'A' + 0x0A);
582 return TRUE;
583 }
584
585 if ((Char >= L'a') && (Char <= L'f')) {
586 *Digit = (UINT8) (Char - L'a' + 0x0A);
587 return TRUE;
588 }
589
590 return FALSE;
591 }
592 ////~
593
594 ////
595 CHAR16
596 R8_NibbleToHexChar (
597 IN UINT8 Nibble
598 )
599 /*++
600
601 Routine Description:
602 Converts the low nibble of a byte to hex unicode character.
603
604 Arguments:
605 Nibble - lower nibble of a byte.
606
607 Returns:
608 Hex unicode character.
609
610 --*/
611 {
612 //
613 // Porting Guide:
614 // This library interface is simply obsolete.
615 // Include the source code to user code.
616 //
617
618 Nibble &= 0x0F;
619 if (Nibble <= 0x9) {
620 return (CHAR16)(Nibble + L'0');
621 }
622
623 return (CHAR16)(Nibble - 0xA + L'A');
624 }
625 ////~
626
627 ////#HobLib
628 VOID *
629 R8_GetHob (
630 IN UINT16 Type,
631 IN VOID *HobStart
632 )
633 /*++
634
635 Routine Description:
636
637 This function returns the first instance of a HOB type in a HOB list.
638
639 Arguments:
640
641 Type - The HOB type to return.
642 HobStart - The first HOB in the HOB list.
643
644 Returns:
645
646 HobStart - There were no HOBs found with the requested type.
647 Other - The first HOB with the matching type.
648
649 --*/
650 {
651 //
652 // Porting Guide:
653 // Edk II HobLib GetNextHob () is an equivelent function with the following exceptions:
654 // 1. GetNextHob () does not allow NULL value as the argument of HobStart by ASSERT ()
655 // 2. GetNextHob () will return NULL instead of returning HobStart when such kind of
656 // HOB can be retrieved, so caller does not need to re-check the return HOB type any longer.
657 //
658
659 VOID *Hob;
660 //
661 // Return input if not found
662 //
663 if (HobStart == NULL) {
664 return HobStart;
665 }
666 Hob = GetNextHob (Type, HobStart);
667 if (Hob == NULL) {
668 return HobStart;
669 }
670
671 return Hob;
672 }
673 ////~
674
675 ////
676 UINTN
677 R8_GetHobListSize (
678 IN VOID *HobStart
679 )
680 /*++
681
682 Routine Description:
683
684 Get size of hob list.
685
686 Arguments:
687
688 HobStart - Start pointer of hob list
689
690 Returns:
691
692 Size of hob list.
693
694 --*/
695 {
696 //
697 // Porting Guide:
698 // This library interface is simply obsolete.
699 // Include the source code to user code.
700 //
701 EFI_PEI_HOB_POINTERS Hob;
702 UINTN Size;
703
704 Hob.Raw = HobStart;
705 Size = 0;
706
707 while (Hob.Header->HobType != EFI_HOB_TYPE_END_OF_HOB_LIST) {
708 Size += Hob.Header->HobLength;
709 Hob.Raw += Hob.Header->HobLength;
710 }
711
712 Size += Hob.Header->HobLength;
713
714 return Size;
715 }
716 ////~
717
718 ////
719 UINT32
720 R8_GetHobVersion (
721 IN VOID *HobStart
722 )
723 /*++
724
725 Routine Description:
726
727 Get hob version.
728
729 Arguments:
730
731 HobStart - Start pointer of hob list
732
733 Returns:
734
735 Hob version.
736
737 --*/
738 {
739 //
740 // Porting Guide:
741 // This library interface is simply obsolete.
742 // Include the source code to user code.
743 //
744
745 EFI_PEI_HOB_POINTERS Hob;
746
747 Hob.Raw = HobStart;
748 return Hob.HandoffInformationTable->Version;
749 }
750 ////~
751
752 ////
753 EFI_STATUS
754 R8_GetHobBootMode (
755 IN VOID *HobStart,
756 OUT EFI_BOOT_MODE *BootMode
757 )
758 /*++
759
760 Routine Description:
761
762 Get current boot mode.
763
764 Arguments:
765
766 HobStart - Start pointer of hob list
767 BootMode - Current boot mode recorded in PHIT hob
768
769 Returns:
770
771 EFI_NOT_FOUND - Invalid hob header
772 EFI_SUCCESS - Boot mode found
773
774 --*/
775 {
776 //
777 // Porting Guide:
778 // This library interface is simply obsolete.
779 // Include the source code to user code.
780 // In fact, since EFI_HANDOFF_HOB must be the first Hob,
781 // the following code can retrieve boot mode.
782 //
783 // EFI_HOB_HANDOFF_INFO_TABLE *HandOffHob;
784 //
785 // HandOffHob = GetHobList ();
786 // ASSERT (HandOffHob->Header.HobType == EFI_HOB_TYPE_HANDOFF);
787 //
788 // BootMode = HandOffHob->BootMode;
789 //
790 EFI_PEI_HOB_POINTERS Hob;
791
792 Hob.Raw = HobStart;
793 if (Hob.Header->HobType != EFI_HOB_TYPE_HANDOFF) {
794 return EFI_NOT_FOUND;
795 }
796
797 *BootMode = Hob.HandoffInformationTable->BootMode;
798 return EFI_SUCCESS;
799 }
800 ////~
801
802
803 ////#HobLib
804 EFI_STATUS
805 R8_GetCpuHobInfo (
806 IN VOID *HobStart,
807 OUT UINT8 *SizeOfMemorySpace,
808 OUT UINT8 *SizeOfIoSpace
809 )
810 /*++
811
812 Routine Description:
813
814 Get information recorded in CPU hob (Memory space size, Io space size)
815
816 Arguments:
817
818 HobStart - Start pointer of hob list
819 SizeOfMemorySpace - Size of memory size
820 SizeOfIoSpace - Size of IO size
821
822 Returns:
823
824 EFI_NOT_FOUND - CPU hob not found
825 EFI_SUCCESS - CPU hob found and information got.
826
827 --*/
828 {
829 //
830 // Porting Guide:
831 // This library interface is simply obsolete.
832 // Include the source code to user code.
833 // If Cpu HOB info is indispensable, user is able to ASSERT ()
834 // first to save error handling code
835 // For example:
836 //
837 // EFI_HOB_CPU *CpuHob;
838 //
839 // CpuHob = GetHob (EFI_HOB_TYPE_CPU, HobStart);
840 // ASSERT (CpuHob != NULL);
841 //
842 // ...
843 //
844 EFI_HOB_CPU *CpuHob;
845
846 CpuHob = GetHob (EFI_HOB_TYPE_CPU, HobStart);
847 if (CpuHob == NULL) {
848 return EFI_NOT_FOUND;
849 }
850
851 *SizeOfMemorySpace = CpuHob->SizeOfMemorySpace;
852 *SizeOfIoSpace = CpuHob->SizeOfIoSpace;
853 return EFI_SUCCESS;
854 }
855 ////~
856
857 ////#HobLib
858 EFI_STATUS
859 R8_GetDxeCoreHobInfo (
860 IN VOID *HobStart,
861 OUT EFI_PHYSICAL_ADDRESS *BaseAddress,
862 OUT UINT64 *Length,
863 OUT VOID **EntryPoint,
864 OUT EFI_GUID **FileName
865 )
866 /*++
867
868 Routine Description:
869
870 Get memory allocation hob created for DXE core and extract its information
871
872 Arguments:
873
874 HobStart - Start pointer of the hob list
875 BaseAddress - Start address of memory allocated for DXE core
876 Length - Length of memory allocated for DXE core
877 EntryPoint - DXE core file name
878 FileName - File Name
879
880 Returns:
881
882 EFI_NOT_FOUND - DxeCoreHob not found
883 EFI_SUCCESS - DxeCoreHob found and information got
884
885 --*/
886 {
887 //
888 // Porting Guide:
889 // This library interface is simply obsolete.
890 // Include the source code to user code.
891 //
892 EFI_PEI_HOB_POINTERS DxeCoreHob;
893
894 for (DxeCoreHob.Raw = HobStart;
895 (DxeCoreHob.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, DxeCoreHob.Raw)) != NULL;
896 DxeCoreHob.Raw = GET_NEXT_HOB (DxeCoreHob)) {
897 if (CompareGuid (&DxeCoreHob.MemoryAllocationModule->MemoryAllocationHeader.Name,
898 &gEfiHobMemeryAllocModuleGuid)) {
899 *BaseAddress = DxeCoreHob.MemoryAllocationModule->MemoryAllocationHeader.MemoryBaseAddress;
900 *Length = DxeCoreHob.MemoryAllocationModule->MemoryAllocationHeader.MemoryLength;
901 *EntryPoint = (VOID *) (UINTN) DxeCoreHob.MemoryAllocationModule->EntryPoint;
902 *FileName = &DxeCoreHob.MemoryAllocationModule->ModuleName;
903 return EFI_SUCCESS;
904 }
905 }
906
907 return EFI_NOT_FOUND;
908 }
909 ////~
910
911 ////#HobLib
912 EFI_STATUS
913 R8_GetNextFirmwareVolumeHob (
914 IN OUT VOID **HobStart,
915 OUT EFI_PHYSICAL_ADDRESS *BaseAddress,
916 OUT UINT64 *Length
917 )
918 /*++
919
920 Routine Description:
921
922 Get next firmware volume hob from HobStart
923
924 Arguments:
925
926 HobStart - Start pointer of hob list
927 BaseAddress - Start address of next firmware volume
928 Length - Length of next firmware volume
929
930 Returns:
931
932 EFI_NOT_FOUND - Next firmware volume not found
933 EFI_SUCCESS - Next firmware volume found with address information
934
935 --*/
936 {
937 //
938 // Porting Guide:
939 // This library interface is simply obsolete.
940 // Include the source code to user code.
941 // Pay attention that caller is REQUIRED to update HobStart with:
942 // *HobStart = GET_NEXT_HOB (FirmwareVolumeHob)
943 //
944 // If FV HOB info is indispensable, user is able to ASSERT ()
945 // first to save error handling code
946 // For example:
947 //
948 // EFI_HOB_FIRMWARE_VOLUME *FirmwareVolumeHob;
949 //
950 // FirmwareVolumeHob = GetHob (EFI_HOB_TYPE_FV, HobStart);
951 // ASSERT (FirmwareVolumeHob != NULL);
952 //
953 // ...
954 //
955
956 EFI_PEI_HOB_POINTERS FirmwareVolumeHob;
957
958 FirmwareVolumeHob.Raw = GetNextHob (EFI_HOB_TYPE_FV, *HobStart);
959 if (FirmwareVolumeHob.Raw != NULL) {
960 return EFI_NOT_FOUND;
961 }
962
963 *BaseAddress = FirmwareVolumeHob.FirmwareVolume->BaseAddress;
964 *Length = FirmwareVolumeHob.FirmwareVolume->Length;
965
966 *HobStart = GET_NEXT_HOB (FirmwareVolumeHob);
967
968 return EFI_SUCCESS;
969 }
970 ////~
971
972 ////#HobLib
973 EFI_STATUS
974 R8_GetNextGuidHob (
975 IN OUT VOID **HobStart,
976 IN EFI_GUID * Guid,
977 OUT VOID **Buffer,
978 OUT UINTN *BufferSize OPTIONAL
979 )
980 /*++
981
982 Routine Description:
983 Get the next guid hob.
984
985 Arguments:
986 HobStart - A pointer to the start hob.
987 Guid - A pointer to a guid.
988 Buffer - A pointer to the buffer.
989 BufferSize - Buffer size.
990
991 Returns:
992 EFI_NOT_FOUND - Next Guid hob not found
993 EFI_SUCCESS - Next Guid hob found and data for this Guid got
994 EFI_INVALID_PARAMETER - invalid parameter
995
996 --*/
997 {
998 //
999 // Porting Guide:
1000 // This library interface is changed substantially with R9 counerpart GetNextGuidHob ().
1001 // 1. R9 GetNextGuidHob has two parameters and returns the matched GUID HOB from the StartHob.
1002 // 2. R9 GetNextGuidHob does not strip the HOB header, so caller is required to apply
1003 // GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE () to extract the data section and its
1004 // size info respectively.
1005 // 3. this function does not skip the starting HOB pointer unconditionally:
1006 // it returns HobStart back if HobStart itself meets the requirement;
1007 // caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.
1008 //
1009 EFI_PEI_HOB_POINTERS GuidHob;
1010
1011 if (Buffer == NULL) {
1012 return EFI_INVALID_PARAMETER;
1013 }
1014
1015 GuidHob.Raw = GetNextGuidHob (Guid, *HobStart);
1016 if (GuidHob.Raw == NULL) {
1017 return EFI_NOT_FOUND;
1018 }
1019
1020 *Buffer = GET_GUID_HOB_DATA (GuidHob.Guid);
1021 if (BufferSize != NULL) {
1022 *BufferSize = GET_GUID_HOB_DATA_SIZE (GuidHob.Guid);
1023 }
1024
1025 *HobStart = GET_NEXT_HOB (GuidHob);
1026
1027 return EFI_SUCCESS;
1028 }
1029 ////~
1030
1031 ////#HobLib
1032 EFI_STATUS
1033 R8_GetPalEntryHobInfo (
1034 IN VOID *HobStart,
1035 OUT EFI_PHYSICAL_ADDRESS *PalEntry
1036 )
1037 /*++
1038
1039 Routine Description:
1040
1041 Get PAL entry from PalEntryHob
1042
1043 Arguments:
1044
1045 HobStart - Start pointer of hob list
1046 PalEntry - Pointer to PAL entry
1047
1048 Returns:
1049
1050 Status code.
1051
1052 --*/
1053 {
1054 EFI_HOB_GUID_TYPE *GuidHob;
1055
1056 GuidHob = GetNextGuidHob (&gPalEntryHob, HobStart);
1057
1058 if (GuidHob == NULL) {
1059 return EFI_NOT_FOUND;
1060 }
1061
1062 *PalEntry = *((EFI_PHYSICAL_ADDRESS *) GET_GUID_HOB_DATA (GuidHob));
1063 return EFI_SUCCESS;
1064 }
1065 ////~
1066
1067 ////#HobLib
1068 EFI_STATUS
1069 R8_GetIoPortSpaceAddressHobInfo (
1070 IN VOID *HobStart,
1071 OUT EFI_PHYSICAL_ADDRESS *IoPortSpaceAddress
1072 )
1073 /*++
1074
1075 Routine Description:
1076
1077 Get IO port space address from IoBaseHob.
1078
1079 Arguments:
1080
1081 HobStart - Start pointer of hob list
1082 IoPortSpaceAddress - IO port space address
1083
1084 Returns:
1085
1086 Status code
1087
1088 --*/
1089 {
1090 //
1091 // Porting Guide:
1092 // This library interface is simply obsolete.
1093 // Include the source code to user code.
1094 //
1095 EFI_HOB_GUID_TYPE *GuidHob;
1096
1097 GuidHob = GetNextGuidHob (&gEfiIoBaseHobGuid, HobStart);
1098
1099 if (GuidHob == NULL) {
1100 return EFI_NOT_FOUND;
1101 }
1102
1103 *IoPortSpaceAddress = *((EFI_PHYSICAL_ADDRESS *) GET_GUID_HOB_DATA (GuidHob));
1104 return EFI_SUCCESS;
1105 }
1106 ////~
1107
1108 ////#HobLib
1109 EFI_STATUS
1110 R8_PeiBuildHobGuid (
1111 IN EFI_GUID *Guid,
1112 IN UINTN DataLength,
1113 OUT VOID **Hob
1114 )
1115 /*++
1116
1117 Routine Description:
1118
1119 Builds a custom HOB that is tagged with a GUID for identification
1120
1121 Arguments:
1122
1123 Guid - The GUID of the custome HOB type
1124 DataLength - The size of the data payload for the GUIDed HOB
1125 Hob - Pointer to pointer to the created Hob
1126
1127 Returns:
1128
1129 EFI_SUCCESS - Hob is successfully built.
1130 Others - Errors occur while creating new Hob
1131
1132 --*/
1133 {
1134 //
1135 // Porting Guide: Apply the new interface of BuildGuidHob in R9 HobLib.
1136 // Pay attention that the return value has been changed to the start address of
1137 // GUID HOB data so that caller can fill the customized data.
1138 // For BuildGuidHob (), the HOB Header and Name field is already stripped..
1139 //
1140 VOID *HobData;
1141
1142 HobData = BuildGuidHob (Guid, DataLength);
1143 //
1144 // This step is necessary to be compatible with R8 interface!
1145 //
1146 *Hob = (VOID *) ((UINT8 *) HobData - sizeof (EFI_HOB_GUID_TYPE));
1147
1148 return EFI_SUCCESS;
1149 }
1150 ////~