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