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