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