ShellPkg: Convert all .uni files to utf-8
[mirror_edk2.git] / ShellPkg / Library / UefiHandleParsingLib / UefiHandleParsingLib.c
CommitLineData
a405b86d 1/** @file\r
2 Provides interface to advanced shell functionality for parsing both handle and protocol database.\r
3\r
1a6f74d9 4 (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>\r
4024c116 5 (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.<BR>\r
00a6ad1b 6 Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR>\r
a405b86d 7 This program and the accompanying materials\r
8 are licensed and made available under the terms and conditions of the BSD License\r
9 which accompanies this distribution. The full text of the license may be found at\r
10 http://opensource.org/licenses/bsd-license.php\r
11\r
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14\r
15**/\r
16\r
17#include "UefiHandleParsingLib.h"\r
f4f3c6bf 18#include "IndustryStandard/Acpi10.h"\r
a405b86d 19\r
e7e0e42b 20EFI_HANDLE mHandleParsingHiiHandle = NULL;\r
a405b86d 21HANDLE_INDEX_LIST mHandleList = {{{NULL,NULL},0,0},0};\r
6306fd90
JC
22GUID_INFO_BLOCK *GuidList;\r
23UINTN GuidListCount;\r
efb76d1a
JC
24/**\r
25 Function to translate the EFI_MEMORY_TYPE into a string.\r
26\r
27 @param[in] Memory The memory type.\r
28\r
29 @retval A string representation of the type allocated from BS Pool.\r
30**/\r
31CHAR16*\r
32EFIAPI\r
33ConvertMemoryType (\r
34 IN CONST EFI_MEMORY_TYPE Memory\r
35 )\r
36{\r
37 CHAR16 *RetVal;\r
38 RetVal = NULL;\r
39\r
40 switch (Memory) {\r
41 case EfiReservedMemoryType: StrnCatGrow(&RetVal, NULL, L"EfiReservedMemoryType", 0); break;\r
42 case EfiLoaderCode: StrnCatGrow(&RetVal, NULL, L"EfiLoaderCode", 0); break;\r
43 case EfiLoaderData: StrnCatGrow(&RetVal, NULL, L"EfiLoaderData", 0); break;\r
44 case EfiBootServicesCode: StrnCatGrow(&RetVal, NULL, L"EfiBootServicesCode", 0); break;\r
45 case EfiBootServicesData: StrnCatGrow(&RetVal, NULL, L"EfiBootServicesData", 0); break;\r
46 case EfiRuntimeServicesCode: StrnCatGrow(&RetVal, NULL, L"EfiRuntimeServicesCode", 0); break;\r
47 case EfiRuntimeServicesData: StrnCatGrow(&RetVal, NULL, L"EfiRuntimeServicesData", 0); break;\r
48 case EfiConventionalMemory: StrnCatGrow(&RetVal, NULL, L"EfiConventionalMemory", 0); break;\r
49 case EfiUnusableMemory: StrnCatGrow(&RetVal, NULL, L"EfiUnusableMemory", 0); break;\r
50 case EfiACPIReclaimMemory: StrnCatGrow(&RetVal, NULL, L"EfiACPIReclaimMemory", 0); break;\r
51 case EfiACPIMemoryNVS: StrnCatGrow(&RetVal, NULL, L"EfiACPIMemoryNVS", 0); break;\r
52 case EfiMemoryMappedIO: StrnCatGrow(&RetVal, NULL, L"EfiMemoryMappedIO", 0); break;\r
53 case EfiMemoryMappedIOPortSpace: StrnCatGrow(&RetVal, NULL, L"EfiMemoryMappedIOPortSpace", 0); break;\r
54 case EfiPalCode: StrnCatGrow(&RetVal, NULL, L"EfiPalCode", 0); break;\r
55 case EfiMaxMemoryType: StrnCatGrow(&RetVal, NULL, L"EfiMaxMemoryType", 0); break;\r
56 default: ASSERT(FALSE);\r
57 }\r
58 return (RetVal);\r
59}\r
60\r
609e0c58
JC
61/**\r
62 Function to translate the EFI_GRAPHICS_PIXEL_FORMAT into a string.\r
63\r
9145d314 64 @param[in] Fmt The format type.\r
609e0c58
JC
65\r
66 @retval A string representation of the type allocated from BS Pool.\r
67**/\r
68CHAR16*\r
69EFIAPI\r
70ConvertPixelFormat (\r
71 IN CONST EFI_GRAPHICS_PIXEL_FORMAT Fmt\r
72 )\r
73{\r
74 CHAR16 *RetVal;\r
75 RetVal = NULL;\r
76\r
77 switch (Fmt) {\r
78 case PixelRedGreenBlueReserved8BitPerColor: StrnCatGrow(&RetVal, NULL, L"PixelRedGreenBlueReserved8BitPerColor", 0); break;\r
79 case PixelBlueGreenRedReserved8BitPerColor: StrnCatGrow(&RetVal, NULL, L"PixelBlueGreenRedReserved8BitPerColor", 0); break;\r
80 case PixelBitMask: StrnCatGrow(&RetVal, NULL, L"PixelBitMask", 0); break;\r
81 case PixelBltOnly: StrnCatGrow(&RetVal, NULL, L"PixelBltOnly", 0); break;\r
82 case PixelFormatMax: StrnCatGrow(&RetVal, NULL, L"PixelFormatMax", 0); break;\r
83 default: ASSERT(FALSE);\r
84 }\r
85 return (RetVal);\r
86}\r
87\r
a405b86d 88/**\r
89 Constructor for the library.\r
90\r
91 @param[in] ImageHandle Ignored.\r
92 @param[in] SystemTable Ignored.\r
93\r
94 @retval EFI_SUCCESS The operation was successful.\r
95**/\r
96EFI_STATUS\r
97EFIAPI\r
98HandleParsingLibConstructor (\r
99 IN EFI_HANDLE ImageHandle,\r
100 IN EFI_SYSTEM_TABLE *SystemTable\r
101 )\r
102{\r
6306fd90
JC
103 GuidListCount = 0;\r
104 GuidList = NULL;\r
105\r
e7e0e42b
CP
106 //\r
107 // Do nothing with mHandleParsingHiiHandle. Initialize HII as needed.\r
108 //\r
109 return (EFI_SUCCESS);\r
110}\r
111\r
1a6f74d9 112/**\r
e7e0e42b 113 Initialization function for HII packages.\r
1a6f74d9 114\r
e7e0e42b
CP
115**/\r
116VOID\r
117HandleParsingHiiInit (VOID)\r
118{\r
a405b86d 119 if (mHandleParsingHiiHandle == NULL) {\r
e7e0e42b
CP
120 mHandleParsingHiiHandle = HiiAddPackages (&gHandleParsingHiiGuid, gImageHandle, UefiHandleParsingLibStrings, NULL);\r
121 ASSERT (mHandleParsingHiiHandle != NULL);\r
a405b86d 122 }\r
a405b86d 123}\r
124\r
125/**\r
126 Destructor for the library. free any resources.\r
127\r
128 @param[in] ImageHandle Ignored.\r
129 @param[in] SystemTable Ignored.\r
130\r
131 @retval EFI_SUCCESS The operation was successful.\r
132**/\r
133EFI_STATUS\r
134EFIAPI\r
135HandleParsingLibDestructor (\r
136 IN EFI_HANDLE ImageHandle,\r
137 IN EFI_SYSTEM_TABLE *SystemTable\r
138 )\r
139{\r
6306fd90
JC
140 UINTN LoopCount;\r
141\r
142 for (LoopCount = 0; GuidList != NULL && LoopCount < GuidListCount; LoopCount++) {\r
143 SHELL_FREE_NON_NULL(GuidList[LoopCount].GuidId);\r
144 }\r
145\r
146 SHELL_FREE_NON_NULL(GuidList);\r
a405b86d 147 if (mHandleParsingHiiHandle != NULL) {\r
148 HiiRemovePackages(mHandleParsingHiiHandle);\r
149 }\r
150 return (EFI_SUCCESS);\r
151}\r
152\r
efb76d1a
JC
153/**\r
154 Function to dump information about LoadedImage.\r
155\r
156 This will allocate the return buffer from boot services pool.\r
157\r
158 @param[in] TheHandle The handle that has LoadedImage installed.\r
159 @param[in] Verbose TRUE for additional information, FALSE otherwise.\r
160\r
161 @retval A poitner to a string containing the information.\r
162**/\r
a405b86d 163CHAR16*\r
164EFIAPI\r
165LoadedImageProtocolDumpInformation(\r
166 IN CONST EFI_HANDLE TheHandle,\r
167 IN CONST BOOLEAN Verbose\r
168 )\r
169{\r
efb76d1a 170 EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;\r
a405b86d 171 EFI_STATUS Status;\r
efb76d1a
JC
172 CHAR16 *RetVal;\r
173 CHAR16 *Temp;\r
174 CHAR16 *CodeType;\r
175 CHAR16 *DataType;\r
a405b86d 176\r
efb76d1a
JC
177 if (!Verbose) {\r
178 return (CatSPrint(NULL, L"LoadedImage"));\r
a405b86d 179 }\r
180\r
e7e0e42b
CP
181 HandleParsingHiiInit();\r
182\r
efb76d1a 183 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_LI_DUMP_MAIN), NULL);\r
1a6f74d9 184 if (Temp == NULL) {\r
efb76d1a 185 return NULL;\r
a405b86d 186 }\r
187\r
efb76d1a
JC
188 Status = gBS->OpenProtocol (\r
189 TheHandle,\r
190 &gEfiLoadedImageProtocolGuid,\r
191 (VOID**)&LoadedImage,\r
192 gImageHandle,\r
193 NULL,\r
194 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
195 );\r
196\r
5f119dfc
HL
197 if (EFI_ERROR (Status)) {\r
198 SHELL_FREE_NON_NULL (Temp);\r
5f119dfc
HL
199 return NULL;\r
200 }\r
201\r
efb76d1a
JC
202 DataType = ConvertMemoryType(LoadedImage->ImageDataType);\r
203 CodeType = ConvertMemoryType(LoadedImage->ImageCodeType);\r
204\r
1a6f74d9
CS
205 RetVal = CatSPrint(\r
206 NULL,\r
207 Temp,\r
208 LoadedImage->Revision,\r
209 LoadedImage->ParentHandle,\r
210 LoadedImage->SystemTable,\r
211 LoadedImage->DeviceHandle,\r
212 LoadedImage->FilePath,\r
213 LoadedImage->LoadOptionsSize,\r
214 LoadedImage->LoadOptions,\r
215 LoadedImage->ImageBase,\r
216 LoadedImage->ImageSize,\r
217 CodeType,\r
218 DataType,\r
219 LoadedImage->Unload\r
220 );\r
221\r
222\r
efb76d1a
JC
223 SHELL_FREE_NON_NULL(Temp);\r
224 SHELL_FREE_NON_NULL(CodeType);\r
225 SHELL_FREE_NON_NULL(DataType);\r
226\r
227 return RetVal;\r
a405b86d 228}\r
a405b86d 229\r
609e0c58
JC
230/**\r
231 Function to dump information about GOP.\r
232\r
233 This will allocate the return buffer from boot services pool.\r
234\r
235 @param[in] TheHandle The handle that has LoadedImage installed.\r
236 @param[in] Verbose TRUE for additional information, FALSE otherwise.\r
237\r
238 @retval A poitner to a string containing the information.\r
239**/\r
240CHAR16*\r
241EFIAPI\r
242GraphicsOutputProtocolDumpInformation(\r
243 IN CONST EFI_HANDLE TheHandle,\r
244 IN CONST BOOLEAN Verbose\r
245 )\r
246{\r
247 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;\r
248 EFI_STATUS Status;\r
249 CHAR16 *RetVal;\r
250 CHAR16 *Temp;\r
251 CHAR16 *Fmt;\r
252\r
253 if (!Verbose) {\r
254 return (CatSPrint(NULL, L"GraphicsOutput"));\r
255 }\r
256\r
e7e0e42b
CP
257 HandleParsingHiiInit();\r
258\r
609e0c58 259 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_GOP_DUMP_MAIN), NULL);\r
1a6f74d9 260 if (Temp == NULL) {\r
609e0c58
JC
261 return NULL;\r
262 }\r
263\r
264 Status = gBS->OpenProtocol (\r
265 TheHandle,\r
266 &gEfiGraphicsOutputProtocolGuid,\r
267 (VOID**)&GraphicsOutput,\r
268 gImageHandle,\r
269 NULL,\r
270 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
271 );\r
272\r
273 if (EFI_ERROR (Status)) {\r
274 SHELL_FREE_NON_NULL (Temp);\r
609e0c58
JC
275 return NULL;\r
276 }\r
277\r
278 Fmt = ConvertPixelFormat(GraphicsOutput->Mode->Info->PixelFormat);\r
279\r
1a6f74d9
CS
280 RetVal = CatSPrint(\r
281 NULL,\r
282 Temp,\r
283 GraphicsOutput->Mode->MaxMode,\r
284 GraphicsOutput->Mode->Mode,\r
285 GraphicsOutput->Mode->FrameBufferBase,\r
286 (UINT64)GraphicsOutput->Mode->FrameBufferSize,\r
287 (UINT64)GraphicsOutput->Mode->SizeOfInfo,\r
288 GraphicsOutput->Mode->Info->Version,\r
289 GraphicsOutput->Mode->Info->HorizontalResolution,\r
290 GraphicsOutput->Mode->Info->VerticalResolution,\r
291 Fmt,\r
292 GraphicsOutput->Mode->Info->PixelsPerScanLine,\r
293 GraphicsOutput->Mode->Info->PixelFormat!=PixelBitMask?0:GraphicsOutput->Mode->Info->PixelInformation.RedMask,\r
294 GraphicsOutput->Mode->Info->PixelFormat!=PixelBitMask?0:GraphicsOutput->Mode->Info->PixelInformation.GreenMask,\r
295 GraphicsOutput->Mode->Info->PixelFormat!=PixelBitMask?0:GraphicsOutput->Mode->Info->PixelInformation.BlueMask\r
296 );\r
297\r
609e0c58
JC
298 SHELL_FREE_NON_NULL(Temp);\r
299 SHELL_FREE_NON_NULL(Fmt);\r
300\r
301 return RetVal;\r
302}\r
303\r
f4f3c6bf 304/**\r
305 Function to dump information about PciRootBridgeIo.\r
306\r
307 This will allocate the return buffer from boot services pool.\r
308\r
309 @param[in] TheHandle The handle that has PciRootBridgeIo installed.\r
310 @param[in] Verbose TRUE for additional information, FALSE otherwise.\r
311\r
312 @retval A poitner to a string containing the information.\r
313**/\r
314CHAR16*\r
315EFIAPI\r
316PciRootBridgeIoDumpInformation(\r
317 IN CONST EFI_HANDLE TheHandle,\r
318 IN CONST BOOLEAN Verbose\r
319 )\r
320{\r
321 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo;\r
322 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Configuration;\r
323 UINT64 Supports;\r
324 UINT64 Attributes;\r
325 CHAR16 *Temp;\r
326 CHAR16 *Temp2;\r
327 CHAR16 *RetVal;\r
328 EFI_STATUS Status;\r
329\r
330 RetVal = NULL;\r
331\r
332 if (!Verbose) {\r
333 return (CatSPrint(NULL, L"PciRootBridgeIo"));\r
334 }\r
335\r
e7e0e42b
CP
336 HandleParsingHiiInit();\r
337\r
f4f3c6bf 338 Status = gBS->HandleProtocol(\r
339 TheHandle,\r
340 &gEfiPciRootBridgeIoProtocolGuid,\r
341 (VOID**)&PciRootBridgeIo);\r
342\r
343 if (EFI_ERROR(Status)) {\r
344 return NULL;\r
345 }\r
346\r
347 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIRB_DUMP_PH), NULL);\r
1d6ccad2
QS
348 if (Temp == NULL) {\r
349 return NULL;\r
350 }\r
f4f3c6bf 351 Temp2 = CatSPrint(L"\r\n", Temp, PciRootBridgeIo->ParentHandle);\r
352 FreePool(Temp);\r
353 RetVal = Temp2;\r
354 Temp2 = NULL;\r
1a6f74d9 355\r
f4f3c6bf 356 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIRB_DUMP_SEG), NULL);\r
1d6ccad2
QS
357 if (Temp == NULL) {\r
358 SHELL_FREE_NON_NULL(RetVal);\r
359 return NULL;\r
360 }\r
f4f3c6bf 361 Temp2 = CatSPrint(RetVal, Temp, PciRootBridgeIo->SegmentNumber);\r
362 FreePool(Temp);\r
363 FreePool(RetVal);\r
364 RetVal = Temp2;\r
365 Temp2 = NULL;\r
366\r
367 Supports = 0;\r
368 Attributes = 0;\r
369 Status = PciRootBridgeIo->GetAttributes (PciRootBridgeIo, &Supports, &Attributes);\r
370 if (!EFI_ERROR(Status)) {\r
371 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIRB_DUMP_ATT), NULL);\r
1d6ccad2
QS
372 if (Temp == NULL) {\r
373 SHELL_FREE_NON_NULL(RetVal);\r
374 return NULL;\r
1a6f74d9 375 }\r
f4f3c6bf 376 Temp2 = CatSPrint(RetVal, Temp, Attributes);\r
377 FreePool(Temp);\r
378 FreePool(RetVal);\r
379 RetVal = Temp2;\r
380 Temp2 = NULL;\r
1a6f74d9 381\r
f4f3c6bf 382 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIRB_DUMP_SUPPORTS), NULL);\r
1d6ccad2
QS
383 if (Temp == NULL) {\r
384 SHELL_FREE_NON_NULL(RetVal);\r
385 return NULL;\r
386 }\r
f4f3c6bf 387 Temp2 = CatSPrint(RetVal, Temp, Supports);\r
388 FreePool(Temp);\r
389 FreePool(RetVal);\r
390 RetVal = Temp2;\r
391 Temp2 = NULL;\r
392 }\r
393\r
394 Configuration = NULL;\r
395 Status = PciRootBridgeIo->Configuration (PciRootBridgeIo, (VOID **) &Configuration);\r
396 if (!EFI_ERROR(Status) && Configuration != NULL) {\r
397 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIRB_DUMP_TITLE), NULL);\r
1d6ccad2
QS
398 if (Temp == NULL) {\r
399 SHELL_FREE_NON_NULL(RetVal);\r
400 return NULL;\r
401 }\r
f4f3c6bf 402 Temp2 = CatSPrint(RetVal, Temp, Supports);\r
403 FreePool(Temp);\r
404 FreePool(RetVal);\r
405 RetVal = Temp2;\r
406 Temp2 = NULL;\r
407 while (Configuration->Desc == ACPI_ADDRESS_SPACE_DESCRIPTOR) {\r
408 Temp = NULL;\r
409 switch (Configuration->ResType) {\r
410 case ACPI_ADDRESS_SPACE_TYPE_MEM:\r
411 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIRB_DUMP_MEM), NULL);\r
412 break;\r
413 case ACPI_ADDRESS_SPACE_TYPE_IO:\r
414 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIRB_DUMP_IO), NULL);\r
415 break;\r
416 case ACPI_ADDRESS_SPACE_TYPE_BUS:\r
417 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIRB_DUMP_BUS), NULL);\r
418 break;\r
419 }\r
420 if (Temp != NULL) {\r
421 Temp2 = CatSPrint(RetVal, L"%s", Temp);\r
422 FreePool(Temp);\r
423 FreePool(RetVal);\r
424 RetVal = Temp2;\r
425 Temp2 = NULL;\r
426 }\r
427\r
1a6f74d9 428 Temp2 = CatSPrint(RetVal,\r
f4f3c6bf 429 L"%H%02x %016lx %016lx %02x%N\r\n",\r
430 Configuration->SpecificFlag,\r
431 Configuration->AddrRangeMin,\r
432 Configuration->AddrRangeMax,\r
433 Configuration->AddrSpaceGranularity\r
434 );\r
435 FreePool(RetVal);\r
436 RetVal = Temp2;\r
437 Temp2 = NULL;\r
438 Configuration++;\r
439 }\r
440 }\r
441 return (RetVal);\r
442}\r
443\r
a405b86d 444/**\r
445 Function to dump information about SimpleTextOut.\r
446\r
447 This will allocate the return buffer from boot services pool.\r
448\r
449 @param[in] TheHandle The handle that has SimpleTextOut installed.\r
450 @param[in] Verbose TRUE for additional information, FALSE otherwise.\r
451\r
452 @retval A poitner to a string containing the information.\r
453**/\r
454CHAR16*\r
455EFIAPI\r
456TxtOutProtocolDumpInformation(\r
457 IN CONST EFI_HANDLE TheHandle,\r
458 IN CONST BOOLEAN Verbose\r
459 )\r
460{\r
461 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Dev;\r
462 INTN Index;\r
463 UINTN Col;\r
464 UINTN Row;\r
465 EFI_STATUS Status;\r
466 CHAR16 *RetVal;\r
467 UINTN Size;\r
468 CHAR16 *Temp;\r
469 UINTN NewSize;\r
470\r
471 if (!Verbose) {\r
472 return (NULL);\r
473 }\r
474\r
e7e0e42b
CP
475 HandleParsingHiiInit();\r
476\r
a405b86d 477 RetVal = NULL;\r
478 Size = 0;\r
479\r
480 Status = gBS->HandleProtocol(\r
481 TheHandle,\r
482 &gEfiSimpleTextOutProtocolGuid,\r
483 (VOID**)&Dev);\r
484\r
485 ASSERT_EFI_ERROR(Status);\r
486 ASSERT (Dev != NULL && Dev->Mode != NULL);\r
487\r
488 Size = (Dev->Mode->MaxMode + 1) * 80;\r
489 RetVal = AllocateZeroPool(Size);\r
490\r
491 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_TXT_OUT_DUMP_HEADER), NULL);\r
ecae5117 492 if (Temp != NULL) {\r
493 UnicodeSPrint(RetVal, Size, Temp, Dev, Dev->Mode->Attribute);\r
494 FreePool(Temp);\r
495 }\r
a405b86d 496\r
497 //\r
498 // Dump TextOut Info\r
499 //\r
500 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_TXT_OUT_DUMP_LINE), NULL);\r
501 for (Index = 0; Index < Dev->Mode->MaxMode; Index++) {\r
502 Status = Dev->QueryMode (Dev, Index, &Col, &Row);\r
503 NewSize = Size - StrSize(RetVal);\r
504 UnicodeSPrint(\r
505 RetVal + StrLen(RetVal),\r
506 NewSize,\r
ecae5117 507 Temp == NULL?L"":Temp,\r
a405b86d 508 Index == Dev->Mode->Mode ? L'*' : L' ',\r
509 Index,\r
28981267 510 !EFI_ERROR(Status)?(INTN)Col:-1,\r
511 !EFI_ERROR(Status)?(INTN)Row:-1\r
a405b86d 512 );\r
513 }\r
514 FreePool(Temp);\r
515 return (RetVal);\r
516}\r
517\r
518STATIC CONST UINTN VersionStringSize = 60;\r
519\r
520/**\r
521 Function to dump information about EfiDriverSupportedEfiVersion protocol.\r
522\r
523 This will allocate the return buffer from boot services pool.\r
524\r
525 @param[in] TheHandle The handle that has the protocol installed.\r
526 @param[in] Verbose TRUE for additional information, FALSE otherwise.\r
527\r
528 @retval A poitner to a string containing the information.\r
529**/\r
530CHAR16*\r
531EFIAPI\r
532DriverEfiVersionProtocolDumpInformation(\r
533 IN CONST EFI_HANDLE TheHandle,\r
534 IN CONST BOOLEAN Verbose\r
535 )\r
536{\r
537 EFI_DRIVER_SUPPORTED_EFI_VERSION_PROTOCOL *DriverEfiVersion;\r
538 EFI_STATUS Status;\r
539 CHAR16 *RetVal;\r
540\r
541 Status = gBS->HandleProtocol(\r
542 TheHandle,\r
543 &gEfiDriverSupportedEfiVersionProtocolGuid,\r
544 (VOID**)&DriverEfiVersion);\r
545\r
546 ASSERT_EFI_ERROR(Status);\r
547\r
78ed876b 548 RetVal = AllocateZeroPool(VersionStringSize);\r
a405b86d 549 ASSERT(RetVal != NULL);\r
550 UnicodeSPrint(RetVal, VersionStringSize, L"0x%08x", DriverEfiVersion->FirmwareVersion);\r
551 return (RetVal);\r
552}\r
553\r
554/**\r
555 Function to dump information about DevicePath protocol.\r
556\r
557 This will allocate the return buffer from boot services pool.\r
558\r
559 @param[in] TheHandle The handle that has the protocol installed.\r
560 @param[in] Verbose TRUE for additional information, FALSE otherwise.\r
561\r
562 @retval A poitner to a string containing the information.\r
563**/\r
564CHAR16*\r
565EFIAPI\r
566DevicePathProtocolDumpInformation(\r
567 IN CONST EFI_HANDLE TheHandle,\r
568 IN CONST BOOLEAN Verbose\r
569 )\r
570{\r
571 EFI_DEVICE_PATH_PROTOCOL *DevPath;\r
572 CHAR16 *Temp;\r
573 CHAR16 *Temp2;\r
574 EFI_STATUS Status;\r
a405b86d 575 Temp = NULL;\r
576\r
863986b3 577 Status = gBS->OpenProtocol(TheHandle, &gEfiDevicePathProtocolGuid, (VOID**)&DevPath, gImageHandle, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);\r
a405b86d 578 if (!EFI_ERROR(Status)) {\r
863986b3
RN
579 //\r
580 // I cannot decide whether to allow shortcuts here (the second BOOLEAN on the next line)\r
581 //\r
582 Temp = ConvertDevicePathToText(DevPath, TRUE, TRUE);\r
583 gBS->CloseProtocol(TheHandle, &gEfiDevicePathProtocolGuid, gImageHandle, NULL);\r
a405b86d 584 }\r
78ed876b 585 if (!Verbose && Temp != NULL && StrLen(Temp) > 30) {\r
a405b86d 586 Temp2 = NULL;\r
587 Temp2 = StrnCatGrow(&Temp2, NULL, Temp+(StrLen(Temp) - 30), 30);\r
588 FreePool(Temp);\r
589 Temp = Temp2;\r
590 }\r
591 return (Temp);\r
592}\r
593\r
59febea1
SEHM
594/**\r
595 Function to dump information about EfiAdapterInformation Protocol.\r
596\r
597 @param[in] TheHandle The handle that has the protocol installed.\r
598 @param[in] Verbose TRUE for additional information, FALSE otherwise.\r
599\r
600 @retval A pointer to a string containing the information.\r
601**/\r
602CHAR16*\r
603EFIAPI\r
604AdapterInformationDumpInformation (\r
605 IN CONST EFI_HANDLE TheHandle,\r
606 IN CONST BOOLEAN Verbose\r
607 )\r
608{\r
609 EFI_STATUS Status;\r
610 EFI_ADAPTER_INFORMATION_PROTOCOL *EfiAdptrInfoProtocol;\r
611 UINTN InfoTypesBufferCount;\r
612 UINTN GuidIndex;\r
613 EFI_GUID *InfoTypesBuffer;\r
614 CHAR16 *GuidStr;\r
615 CHAR16 *TempStr;\r
616 CHAR16 *RetVal;\r
1a6f74d9 617 CHAR16 *TempRetVal;\r
59febea1
SEHM
618 VOID *InformationBlock;\r
619 UINTN InformationBlockSize;\r
1a6f74d9 620\r
59febea1
SEHM
621 if (!Verbose) {\r
622 return (CatSPrint(NULL, L"AdapterInfo"));\r
623 }\r
624\r
1d6ccad2
QS
625 InfoTypesBuffer = NULL;\r
626 InformationBlock = NULL;\r
1a6f74d9 627\r
59febea1
SEHM
628\r
629 Status = gBS->OpenProtocol (\r
630 (EFI_HANDLE) (TheHandle),\r
631 &gEfiAdapterInformationProtocolGuid,\r
632 (VOID **) &EfiAdptrInfoProtocol,\r
633 NULL,\r
634 NULL,\r
635 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
636 );\r
637\r
638 if (EFI_ERROR (Status)) {\r
59febea1
SEHM
639 return NULL;\r
640 }\r
641\r
642 //\r
643 // Get a list of supported information types for this instance of the protocol.\r
644 //\r
645 Status = EfiAdptrInfoProtocol->GetSupportedTypes (\r
646 EfiAdptrInfoProtocol,\r
1a6f74d9 647 &InfoTypesBuffer,\r
59febea1
SEHM
648 &InfoTypesBufferCount\r
649 );\r
1a6f74d9 650 RetVal = NULL;\r
59febea1
SEHM
651 if (EFI_ERROR (Status)) {\r
652 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_GET_SUPP_TYPES_FAILED), NULL);\r
1d6ccad2 653 if (TempStr != NULL) {\r
1a6f74d9 654 RetVal = CatSPrint (NULL, TempStr, Status);\r
1d6ccad2
QS
655 } else {\r
656 goto ERROR_EXIT;\r
1a6f74d9 657 }\r
59febea1
SEHM
658 } else {\r
659 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_SUPP_TYPE_HEADER), NULL);\r
1d6ccad2
QS
660 if (TempStr == NULL) {\r
661 goto ERROR_EXIT;\r
662 }\r
1a6f74d9 663 RetVal = CatSPrint (NULL, TempStr);\r
59febea1
SEHM
664 SHELL_FREE_NON_NULL (TempStr);\r
665\r
666 for (GuidIndex = 0; GuidIndex < InfoTypesBufferCount; GuidIndex++) {\r
667 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_GUID_NUMBER), NULL);\r
1d6ccad2
QS
668 if (TempStr == NULL) {\r
669 goto ERROR_EXIT;\r
670 }\r
1a6f74d9
CS
671 TempRetVal = CatSPrint (RetVal, TempStr, (GuidIndex + 1), InfoTypesBuffer[GuidIndex]);\r
672 SHELL_FREE_NON_NULL (RetVal);\r
673 RetVal = TempRetVal;\r
59febea1
SEHM
674 SHELL_FREE_NON_NULL (TempStr);\r
675\r
676 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_GUID_STRING), NULL);\r
1d6ccad2
QS
677 if (TempStr == NULL) {\r
678 goto ERROR_EXIT;\r
679 }\r
59febea1
SEHM
680\r
681 if (CompareGuid (&InfoTypesBuffer[GuidIndex], &gEfiAdapterInfoMediaStateGuid)) {\r
1a6f74d9
CS
682 TempRetVal = CatSPrint (RetVal, TempStr, L"gEfiAdapterInfoMediaStateGuid");\r
683 SHELL_FREE_NON_NULL (RetVal);\r
684 RetVal = TempRetVal;\r
59febea1 685 } else if (CompareGuid (&InfoTypesBuffer[GuidIndex], &gEfiAdapterInfoNetworkBootGuid)) {\r
1a6f74d9
CS
686 TempRetVal = CatSPrint (RetVal, TempStr, L"gEfiAdapterInfoNetworkBootGuid");\r
687 SHELL_FREE_NON_NULL (RetVal);\r
688 RetVal = TempRetVal;\r
59febea1 689 } else if (CompareGuid (&InfoTypesBuffer[GuidIndex], &gEfiAdapterInfoSanMacAddressGuid)) {\r
1a6f74d9
CS
690 TempRetVal = CatSPrint (RetVal, TempStr, L"gEfiAdapterInfoSanMacAddressGuid");\r
691 SHELL_FREE_NON_NULL (RetVal);\r
692 RetVal = TempRetVal;\r
59febea1
SEHM
693 } else {\r
694\r
695 GuidStr = GetStringNameFromGuid (&InfoTypesBuffer[GuidIndex], NULL);\r
1a6f74d9 696\r
59febea1
SEHM
697 if (GuidStr != NULL) {\r
698 if (StrCmp(GuidStr, L"UnknownDevice") == 0) {\r
1a6f74d9
CS
699 TempRetVal = CatSPrint (RetVal, TempStr, L"UnknownInfoType");\r
700 SHELL_FREE_NON_NULL (RetVal);\r
701 RetVal = TempRetVal;\r
702\r
59febea1
SEHM
703 SHELL_FREE_NON_NULL (TempStr);\r
704 SHELL_FREE_NON_NULL(GuidStr);\r
705 //\r
706 // So that we never have to pass this UnknownInfoType to the parsing function "GetInformation" service of AIP\r
707 //\r
1a6f74d9 708 continue;\r
59febea1 709 } else {\r
1a6f74d9
CS
710 TempRetVal = CatSPrint (RetVal, TempStr, GuidStr);\r
711 SHELL_FREE_NON_NULL (RetVal);\r
712 RetVal = TempRetVal;\r
59febea1
SEHM
713 SHELL_FREE_NON_NULL(GuidStr);\r
714 }\r
715 }\r
716 }\r
1a6f74d9 717\r
59febea1
SEHM
718 SHELL_FREE_NON_NULL (TempStr);\r
719\r
720 Status = EfiAdptrInfoProtocol->GetInformation (\r
721 EfiAdptrInfoProtocol,\r
722 &InfoTypesBuffer[GuidIndex],\r
723 &InformationBlock,\r
724 &InformationBlockSize\r
725 );\r
726\r
727 if (EFI_ERROR (Status)) {\r
728 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_GETINFO_FAILED), NULL);\r
1d6ccad2
QS
729 if (TempStr == NULL) {\r
730 goto ERROR_EXIT;\r
731 }\r
1a6f74d9
CS
732 TempRetVal = CatSPrint (RetVal, TempStr, Status);\r
733 SHELL_FREE_NON_NULL (RetVal);\r
734 RetVal = TempRetVal;\r
59febea1
SEHM
735 } else {\r
736 if (CompareGuid (&InfoTypesBuffer[GuidIndex], &gEfiAdapterInfoMediaStateGuid)) {\r
737 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_MEDIA_STATE), NULL);\r
1d6ccad2
QS
738 if (TempStr == NULL) {\r
739 goto ERROR_EXIT;\r
740 }\r
1a6f74d9
CS
741 TempRetVal = CatSPrint (\r
742 RetVal,\r
743 TempStr,\r
744 ((EFI_ADAPTER_INFO_MEDIA_STATE *)InformationBlock)->MediaState,\r
745 ((EFI_ADAPTER_INFO_MEDIA_STATE *)InformationBlock)->MediaState\r
746 );\r
747 SHELL_FREE_NON_NULL (RetVal);\r
748 RetVal = TempRetVal;\r
59febea1
SEHM
749 } else if (CompareGuid (&InfoTypesBuffer[GuidIndex], &gEfiAdapterInfoNetworkBootGuid)) {\r
750 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_NETWORK_BOOT_INFO), NULL);\r
1d6ccad2
QS
751 if (TempStr == NULL) {\r
752 goto ERROR_EXIT;\r
753 }\r
1a6f74d9
CS
754 TempRetVal = CatSPrint (\r
755 RetVal,\r
756 TempStr,\r
757 ((EFI_ADAPTER_INFO_NETWORK_BOOT *)InformationBlock)->iScsiIpv4BootCapablity,\r
758 ((EFI_ADAPTER_INFO_NETWORK_BOOT *)InformationBlock)->iScsiIpv6BootCapablity,\r
759 ((EFI_ADAPTER_INFO_NETWORK_BOOT *)InformationBlock)->FCoeBootCapablity,\r
760 ((EFI_ADAPTER_INFO_NETWORK_BOOT *)InformationBlock)->OffloadCapability,\r
761 ((EFI_ADAPTER_INFO_NETWORK_BOOT *)InformationBlock)->iScsiMpioCapability,\r
762 ((EFI_ADAPTER_INFO_NETWORK_BOOT *)InformationBlock)->iScsiIpv4Boot,\r
763 ((EFI_ADAPTER_INFO_NETWORK_BOOT *)InformationBlock)->iScsiIpv6Boot,\r
764 ((EFI_ADAPTER_INFO_NETWORK_BOOT *)InformationBlock)->FCoeBoot\r
765 );\r
766 SHELL_FREE_NON_NULL (RetVal);\r
767 RetVal = TempRetVal;\r
768 } else if (CompareGuid (&InfoTypesBuffer[GuidIndex], &gEfiAdapterInfoSanMacAddressGuid) == TRUE) {\r
59febea1 769 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_SAN_MAC_ADDRESS_INFO), NULL);\r
1d6ccad2
QS
770 if (TempStr == NULL) {\r
771 goto ERROR_EXIT;\r
772 }\r
1a6f74d9
CS
773 TempRetVal = CatSPrint (\r
774 RetVal,\r
775 TempStr,\r
776 ((EFI_ADAPTER_INFO_SAN_MAC_ADDRESS *)InformationBlock)->SanMacAddress.Addr[0],\r
777 ((EFI_ADAPTER_INFO_SAN_MAC_ADDRESS *)InformationBlock)->SanMacAddress.Addr[1],\r
778 ((EFI_ADAPTER_INFO_SAN_MAC_ADDRESS *)InformationBlock)->SanMacAddress.Addr[2],\r
779 ((EFI_ADAPTER_INFO_SAN_MAC_ADDRESS *)InformationBlock)->SanMacAddress.Addr[3],\r
780 ((EFI_ADAPTER_INFO_SAN_MAC_ADDRESS *)InformationBlock)->SanMacAddress.Addr[4],\r
781 ((EFI_ADAPTER_INFO_SAN_MAC_ADDRESS *)InformationBlock)->SanMacAddress.Addr[5]\r
782 );\r
783 SHELL_FREE_NON_NULL (RetVal);\r
784 RetVal = TempRetVal;\r
59febea1
SEHM
785 } else {\r
786 TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_UNKNOWN_INFO_TYPE), NULL);\r
1d6ccad2
QS
787 if (TempStr == NULL) {\r
788 goto ERROR_EXIT;\r
789 }\r
1a6f74d9
CS
790 TempRetVal = CatSPrint (RetVal, TempStr, &InfoTypesBuffer[GuidIndex]);\r
791 SHELL_FREE_NON_NULL (RetVal);\r
792 RetVal = TempRetVal;\r
59febea1
SEHM
793 }\r
794 }\r
795 SHELL_FREE_NON_NULL (TempStr);\r
796 SHELL_FREE_NON_NULL (InformationBlock);\r
797 }\r
798 }\r
799\r
1d6ccad2 800 SHELL_FREE_NON_NULL (InfoTypesBuffer);\r
59febea1 801 return RetVal;\r
1d6ccad2
QS
802\r
803ERROR_EXIT:\r
804 SHELL_FREE_NON_NULL (RetVal);\r
805 SHELL_FREE_NON_NULL (InfoTypesBuffer);\r
806 SHELL_FREE_NON_NULL (InformationBlock);\r
807 return NULL;\r
59febea1 808}\r
a405b86d 809//\r
810// Put the information on the NT32 protocol GUIDs here so we are not dependant on the Nt32Pkg\r
811//\r
812#define LOCAL_EFI_WIN_NT_THUNK_PROTOCOL_GUID \\r
813 { \\r
ce68d3bc 814 0x58c518b1, 0x76f3, 0x11d4, { 0xbc, 0xea, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 } \\r
a405b86d 815 }\r
816\r
817#define LOCAL_EFI_WIN_NT_BUS_DRIVER_IO_PROTOCOL_GUID \\r
818 { \\r
ce68d3bc 819 0x96eb4ad6, 0xa32a, 0x11d4, { 0xbc, 0xfd, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 } \\r
a405b86d 820 }\r
821\r
822#define LOCAL_EFI_WIN_NT_SERIAL_PORT_GUID \\r
823 { \\r
ce68d3bc 824 0xc95a93d, 0xa006, 0x11d4, { 0xbc, 0xfa, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 } \\r
a405b86d 825 }\r
826STATIC CONST EFI_GUID WinNtThunkProtocolGuid = LOCAL_EFI_WIN_NT_THUNK_PROTOCOL_GUID;\r
827STATIC CONST EFI_GUID WinNtIoProtocolGuid = LOCAL_EFI_WIN_NT_BUS_DRIVER_IO_PROTOCOL_GUID;\r
828STATIC CONST EFI_GUID WinNtSerialPortGuid = LOCAL_EFI_WIN_NT_SERIAL_PORT_GUID;\r
829\r
2c23ddaa 830//\r
831// Deprecated protocols we dont want to link from IntelFrameworkModulePkg\r
832//\r
833#define LOCAL_EFI_ISA_IO_PROTOCOL_GUID \\r
834 { \\r
835 0x7ee2bd44, 0x3da0, 0x11d4, { 0x9a, 0x38, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d } \\r
1a6f74d9 836 }\r
2c23ddaa 837#define LOCAL_EFI_ISA_ACPI_PROTOCOL_GUID \\r
838 { \\r
839 0x64a892dc, 0x5561, 0x4536, { 0x92, 0xc7, 0x79, 0x9b, 0xfc, 0x18, 0x33, 0x55 } \\r
840 }\r
841STATIC CONST EFI_GUID EfiIsaIoProtocolGuid = LOCAL_EFI_ISA_IO_PROTOCOL_GUID;\r
842STATIC CONST EFI_GUID EfiIsaAcpiProtocolGuid = LOCAL_EFI_ISA_ACPI_PROTOCOL_GUID;\r
843\r
844\r
dee34318 845STATIC CONST GUID_INFO_BLOCK mGuidStringListNT[] = {\r
a405b86d 846 {STRING_TOKEN(STR_WINNT_THUNK), (EFI_GUID*)&WinNtThunkProtocolGuid, NULL},\r
847 {STRING_TOKEN(STR_WINNT_DRIVER_IO), (EFI_GUID*)&WinNtIoProtocolGuid, NULL},\r
848 {STRING_TOKEN(STR_WINNT_SERIAL_PORT), (EFI_GUID*)&WinNtSerialPortGuid, NULL},\r
849 {STRING_TOKEN(STR_UNKNOWN_DEVICE), NULL, NULL},\r
850};\r
851\r
dee34318 852STATIC CONST GUID_INFO_BLOCK mGuidStringList[] = {\r
efb76d1a 853 {STRING_TOKEN(STR_LOADED_IMAGE), &gEfiLoadedImageProtocolGuid, LoadedImageProtocolDumpInformation},\r
a405b86d 854 {STRING_TOKEN(STR_DEVICE_PATH), &gEfiDevicePathProtocolGuid, DevicePathProtocolDumpInformation},\r
855 {STRING_TOKEN(STR_IMAGE_PATH), &gEfiLoadedImageDevicePathProtocolGuid, DevicePathProtocolDumpInformation},\r
856 {STRING_TOKEN(STR_DEVICE_PATH_UTIL), &gEfiDevicePathUtilitiesProtocolGuid, NULL},\r
857 {STRING_TOKEN(STR_DEVICE_PATH_TXT), &gEfiDevicePathToTextProtocolGuid, NULL},\r
858 {STRING_TOKEN(STR_DEVICE_PATH_FTXT), &gEfiDevicePathFromTextProtocolGuid, NULL},\r
859 {STRING_TOKEN(STR_DEVICE_PATH_PC), &gEfiPcAnsiGuid, NULL},\r
860 {STRING_TOKEN(STR_DEVICE_PATH_VT100), &gEfiVT100Guid, NULL},\r
861 {STRING_TOKEN(STR_DEVICE_PATH_VT100P), &gEfiVT100PlusGuid, NULL},\r
862 {STRING_TOKEN(STR_DEVICE_PATH_VTUTF8), &gEfiVTUTF8Guid, NULL},\r
863 {STRING_TOKEN(STR_DRIVER_BINDING), &gEfiDriverBindingProtocolGuid, NULL},\r
864 {STRING_TOKEN(STR_PLATFORM_OVERRIDE), &gEfiPlatformDriverOverrideProtocolGuid, NULL},\r
865 {STRING_TOKEN(STR_BUS_OVERRIDE), &gEfiBusSpecificDriverOverrideProtocolGuid, NULL},\r
866 {STRING_TOKEN(STR_DRIVER_DIAG), &gEfiDriverDiagnosticsProtocolGuid, NULL},\r
867 {STRING_TOKEN(STR_DRIVER_DIAG2), &gEfiDriverDiagnostics2ProtocolGuid, NULL},\r
868 {STRING_TOKEN(STR_DRIVER_CN), &gEfiComponentNameProtocolGuid, NULL},\r
869 {STRING_TOKEN(STR_DRIVER_CN2), &gEfiComponentName2ProtocolGuid, NULL},\r
870 {STRING_TOKEN(STR_PLAT_DRV_CFG), &gEfiPlatformToDriverConfigurationProtocolGuid, NULL},\r
871 {STRING_TOKEN(STR_DRIVER_VERSION), &gEfiDriverSupportedEfiVersionProtocolGuid, DriverEfiVersionProtocolDumpInformation},\r
872 {STRING_TOKEN(STR_TXT_IN), &gEfiSimpleTextInProtocolGuid, NULL},\r
873 {STRING_TOKEN(STR_TXT_IN_EX), &gEfiSimpleTextInputExProtocolGuid, NULL},\r
874 {STRING_TOKEN(STR_TXT_OUT), &gEfiSimpleTextOutProtocolGuid, TxtOutProtocolDumpInformation},\r
875 {STRING_TOKEN(STR_SIM_POINTER), &gEfiSimplePointerProtocolGuid, NULL},\r
876 {STRING_TOKEN(STR_ABS_POINTER), &gEfiAbsolutePointerProtocolGuid, NULL},\r
877 {STRING_TOKEN(STR_SERIAL_IO), &gEfiSerialIoProtocolGuid, NULL},\r
609e0c58 878 {STRING_TOKEN(STR_GRAPHICS_OUTPUT), &gEfiGraphicsOutputProtocolGuid, GraphicsOutputProtocolDumpInformation},\r
a405b86d 879 {STRING_TOKEN(STR_EDID_DISCOVERED), &gEfiEdidDiscoveredProtocolGuid, NULL},\r
880 {STRING_TOKEN(STR_EDID_ACTIVE), &gEfiEdidActiveProtocolGuid, NULL},\r
881 {STRING_TOKEN(STR_EDID_OVERRIDE), &gEfiEdidOverrideProtocolGuid, NULL},\r
882 {STRING_TOKEN(STR_CON_IN), &gEfiConsoleInDeviceGuid, NULL},\r
883 {STRING_TOKEN(STR_CON_OUT), &gEfiConsoleOutDeviceGuid, NULL},\r
884 {STRING_TOKEN(STR_STD_ERR), &gEfiStandardErrorDeviceGuid, NULL},\r
885 {STRING_TOKEN(STR_LOAD_FILE), &gEfiLoadFileProtocolGuid, NULL},\r
886 {STRING_TOKEN(STR_LOAD_FILE2), &gEfiLoadFile2ProtocolGuid, NULL},\r
887 {STRING_TOKEN(STR_SIMPLE_FILE_SYS), &gEfiSimpleFileSystemProtocolGuid, NULL},\r
a405b86d 888 {STRING_TOKEN(STR_TAPE_IO), &gEfiTapeIoProtocolGuid, NULL},\r
889 {STRING_TOKEN(STR_DISK_IO), &gEfiDiskIoProtocolGuid, NULL},\r
890 {STRING_TOKEN(STR_BLK_IO), &gEfiBlockIoProtocolGuid, NULL},\r
891 {STRING_TOKEN(STR_UC), &gEfiUnicodeCollationProtocolGuid, NULL},\r
892 {STRING_TOKEN(STR_UC2), &gEfiUnicodeCollation2ProtocolGuid, NULL},\r
f4f3c6bf 893 {STRING_TOKEN(STR_PCIRB_IO), &gEfiPciRootBridgeIoProtocolGuid, PciRootBridgeIoDumpInformation},\r
a405b86d 894 {STRING_TOKEN(STR_PCI_IO), &gEfiPciIoProtocolGuid, NULL},\r
895 {STRING_TOKEN(STR_SCSI_PT), &gEfiScsiPassThruProtocolGuid, NULL},\r
896 {STRING_TOKEN(STR_SCSI_IO), &gEfiScsiIoProtocolGuid, NULL},\r
897 {STRING_TOKEN(STR_SCSI_PT_EXT), &gEfiExtScsiPassThruProtocolGuid, NULL},\r
898 {STRING_TOKEN(STR_ISCSI), &gEfiIScsiInitiatorNameProtocolGuid, NULL},\r
899 {STRING_TOKEN(STR_USB_IO), &gEfiUsbIoProtocolGuid, NULL},\r
900 {STRING_TOKEN(STR_USB_HC), &gEfiUsbHcProtocolGuid, NULL},\r
901 {STRING_TOKEN(STR_USB_HC2), &gEfiUsb2HcProtocolGuid, NULL},\r
902 {STRING_TOKEN(STR_DEBUG_SUPPORT), &gEfiDebugSupportProtocolGuid, NULL},\r
903 {STRING_TOKEN(STR_DEBUG_PORT), &gEfiDebugPortProtocolGuid, NULL},\r
904 {STRING_TOKEN(STR_DECOMPRESS), &gEfiDecompressProtocolGuid, NULL},\r
905 {STRING_TOKEN(STR_ACPI_TABLE), &gEfiAcpiTableProtocolGuid, NULL},\r
906 {STRING_TOKEN(STR_EBC_INTERPRETER), &gEfiEbcProtocolGuid, NULL},\r
907 {STRING_TOKEN(STR_SNP), &gEfiSimpleNetworkProtocolGuid, NULL},\r
908 {STRING_TOKEN(STR_NII), &gEfiNetworkInterfaceIdentifierProtocolGuid, NULL},\r
909 {STRING_TOKEN(STR_NII_31), &gEfiNetworkInterfaceIdentifierProtocolGuid_31, NULL},\r
910 {STRING_TOKEN(STR_PXE_BC), &gEfiPxeBaseCodeProtocolGuid, NULL},\r
911 {STRING_TOKEN(STR_PXE_CB), &gEfiPxeBaseCodeCallbackProtocolGuid, NULL},\r
912 {STRING_TOKEN(STR_BIS), &gEfiBisProtocolGuid, NULL},\r
913 {STRING_TOKEN(STR_MNP_SB), &gEfiManagedNetworkServiceBindingProtocolGuid, NULL},\r
914 {STRING_TOKEN(STR_MNP), &gEfiManagedNetworkProtocolGuid, NULL},\r
915 {STRING_TOKEN(STR_ARP_SB), &gEfiArpServiceBindingProtocolGuid, NULL},\r
916 {STRING_TOKEN(STR_ARP), &gEfiArpProtocolGuid, NULL},\r
917 {STRING_TOKEN(STR_DHCPV4_SB), &gEfiDhcp4ServiceBindingProtocolGuid, NULL},\r
918 {STRING_TOKEN(STR_DHCPV4), &gEfiDhcp4ProtocolGuid, NULL},\r
919 {STRING_TOKEN(STR_TCPV4_SB), &gEfiTcp4ServiceBindingProtocolGuid, NULL},\r
920 {STRING_TOKEN(STR_TCPV4), &gEfiTcp4ProtocolGuid, NULL},\r
921 {STRING_TOKEN(STR_IPV4_SB), &gEfiIp4ServiceBindingProtocolGuid, NULL},\r
922 {STRING_TOKEN(STR_IPV4), &gEfiIp4ProtocolGuid, NULL},\r
923 {STRING_TOKEN(STR_IPV4_CFG), &gEfiIp4ConfigProtocolGuid, NULL},\r
00a6ad1b 924 {STRING_TOKEN(STR_IPV4_CFG2), &gEfiIp4Config2ProtocolGuid, NULL},\r
a405b86d 925 {STRING_TOKEN(STR_UDPV4_SB), &gEfiUdp4ServiceBindingProtocolGuid, NULL},\r
926 {STRING_TOKEN(STR_UDPV4), &gEfiUdp4ProtocolGuid, NULL},\r
927 {STRING_TOKEN(STR_MTFTPV4_SB), &gEfiMtftp4ServiceBindingProtocolGuid, NULL},\r
928 {STRING_TOKEN(STR_MTFTPV4), &gEfiMtftp4ProtocolGuid, NULL},\r
929 {STRING_TOKEN(STR_AUTH_INFO), &gEfiAuthenticationInfoProtocolGuid, NULL},\r
930 {STRING_TOKEN(STR_HASH_SB), &gEfiHashServiceBindingProtocolGuid, NULL},\r
931 {STRING_TOKEN(STR_HASH), &gEfiHashProtocolGuid, NULL},\r
932 {STRING_TOKEN(STR_HII_FONT), &gEfiHiiFontProtocolGuid, NULL},\r
933 {STRING_TOKEN(STR_HII_STRING), &gEfiHiiStringProtocolGuid, NULL},\r
934 {STRING_TOKEN(STR_HII_IMAGE), &gEfiHiiImageProtocolGuid, NULL},\r
935 {STRING_TOKEN(STR_HII_DATABASE), &gEfiHiiDatabaseProtocolGuid, NULL},\r
936 {STRING_TOKEN(STR_HII_CONFIG_ROUT), &gEfiHiiConfigRoutingProtocolGuid, NULL},\r
937 {STRING_TOKEN(STR_HII_CONFIG_ACC), &gEfiHiiConfigAccessProtocolGuid, NULL},\r
938 {STRING_TOKEN(STR_HII_FORM_BROWSER2), &gEfiFormBrowser2ProtocolGuid, NULL},\r
dee34318 939 {STRING_TOKEN(STR_DRIVER_FAM_OVERRIDE), &gEfiDriverFamilyOverrideProtocolGuid, NULL},\r
940 {STRING_TOKEN(STR_PCD), &gPcdProtocolGuid, NULL},\r
941 {STRING_TOKEN(STR_TCG), &gEfiTcgProtocolGuid, NULL},\r
942 {STRING_TOKEN(STR_HII_PACKAGE_LIST), &gEfiHiiPackageListProtocolGuid, NULL},\r
943\r
944//\r
945// the ones under this are deprecated by the current UEFI Spec, but may be found anyways...\r
946//\r
a405b86d 947 {STRING_TOKEN(STR_SHELL_INTERFACE), &gEfiShellInterfaceGuid, NULL},\r
948 {STRING_TOKEN(STR_SHELL_ENV2), &gEfiShellEnvironment2Guid, NULL},\r
949 {STRING_TOKEN(STR_SHELL_ENV), &gEfiShellEnvironment2Guid, NULL},\r
950 {STRING_TOKEN(STR_DEVICE_IO), &gEfiDeviceIoProtocolGuid, NULL},\r
951 {STRING_TOKEN(STR_UGA_DRAW), &gEfiUgaDrawProtocolGuid, NULL},\r
952 {STRING_TOKEN(STR_UGA_IO), &gEfiUgaIoProtocolGuid, NULL},\r
953 {STRING_TOKEN(STR_ESP), &gEfiPartTypeSystemPartGuid, NULL},\r
954 {STRING_TOKEN(STR_GPT_NBR), &gEfiPartTypeLegacyMbrGuid, NULL},\r
955 {STRING_TOKEN(STR_DRIVER_CONFIG), &gEfiDriverConfigurationProtocolGuid, NULL},\r
956 {STRING_TOKEN(STR_DRIVER_CONFIG2), &gEfiDriverConfiguration2ProtocolGuid, NULL},\r
2c23ddaa 957\r
958//\r
959// these are using local (non-global) definitions to reduce package dependancy.\r
960//\r
961 {STRING_TOKEN(STR_ISA_IO), (EFI_GUID*)&EfiIsaIoProtocolGuid, NULL},\r
962 {STRING_TOKEN(STR_ISA_ACPI), (EFI_GUID*)&EfiIsaAcpiProtocolGuid, NULL},\r
dee34318 963\r
964//\r
965// the ones under this are GUID identified structs, not protocols\r
966//\r
967 {STRING_TOKEN(STR_FILE_INFO), &gEfiFileInfoGuid, NULL},\r
968 {STRING_TOKEN(STR_FILE_SYS_INFO), &gEfiFileSystemInfoGuid, NULL},\r
969\r
970//\r
971// the ones under this are misc GUIDS.\r
972//\r
973 {STRING_TOKEN(STR_EFI_GLOBAL_VARIABLE), &gEfiGlobalVariableGuid, NULL},\r
974\r
975//\r
976// UEFI 2.2\r
977//\r
978 {STRING_TOKEN(STR_IP6_SB), &gEfiIp6ServiceBindingProtocolGuid, NULL},\r
979 {STRING_TOKEN(STR_IP6), &gEfiIp6ProtocolGuid, NULL},\r
980 {STRING_TOKEN(STR_IP6_CONFIG), &gEfiIp6ConfigProtocolGuid, NULL},\r
981 {STRING_TOKEN(STR_MTFTP6_SB), &gEfiMtftp6ServiceBindingProtocolGuid, NULL},\r
982 {STRING_TOKEN(STR_MTFTP6), &gEfiMtftp6ProtocolGuid, NULL},\r
983 {STRING_TOKEN(STR_DHCP6_SB), &gEfiDhcp6ServiceBindingProtocolGuid, NULL},\r
984 {STRING_TOKEN(STR_DHCP6), &gEfiDhcp6ProtocolGuid, NULL},\r
985 {STRING_TOKEN(STR_UDP6_SB), &gEfiUdp6ServiceBindingProtocolGuid, NULL},\r
986 {STRING_TOKEN(STR_UDP6), &gEfiUdp6ProtocolGuid, NULL},\r
987 {STRING_TOKEN(STR_TCP6_SB), &gEfiTcp6ServiceBindingProtocolGuid, NULL},\r
988 {STRING_TOKEN(STR_TCP6), &gEfiTcp6ProtocolGuid, NULL},\r
989 {STRING_TOKEN(STR_VLAN_CONFIG), &gEfiVlanConfigProtocolGuid, NULL},\r
990 {STRING_TOKEN(STR_EAP), &gEfiEapProtocolGuid, NULL},\r
991 {STRING_TOKEN(STR_EAP_MGMT), &gEfiEapManagementProtocolGuid, NULL},\r
992 {STRING_TOKEN(STR_FTP4_SB), &gEfiFtp4ServiceBindingProtocolGuid, NULL},\r
993 {STRING_TOKEN(STR_FTP4), &gEfiFtp4ProtocolGuid, NULL},\r
994 {STRING_TOKEN(STR_IP_SEC_CONFIG), &gEfiIpSecConfigProtocolGuid, NULL},\r
995 {STRING_TOKEN(STR_DH), &gEfiDriverHealthProtocolGuid, NULL},\r
996 {STRING_TOKEN(STR_DEF_IMG_LOAD), &gEfiDeferredImageLoadProtocolGuid, NULL},\r
997 {STRING_TOKEN(STR_USER_CRED), &gEfiUserCredentialProtocolGuid, NULL},\r
998 {STRING_TOKEN(STR_USER_MNGR), &gEfiUserManagerProtocolGuid, NULL},\r
999 {STRING_TOKEN(STR_ATA_PASS_THRU), &gEfiAtaPassThruProtocolGuid, NULL},\r
1000\r
1001//\r
1002// UEFI 2.3\r
1003//\r
1004 {STRING_TOKEN(STR_FW_MGMT), &gEfiFirmwareManagementProtocolGuid, NULL},\r
1005 {STRING_TOKEN(STR_IP_SEC), &gEfiIpSecProtocolGuid, NULL},\r
1006 {STRING_TOKEN(STR_IP_SEC2), &gEfiIpSec2ProtocolGuid, NULL},\r
1007\r
1008//\r
1009// UEFI 2.3.1\r
1010//\r
1011 {STRING_TOKEN(STR_KMS), &gEfiKmsProtocolGuid, NULL},\r
1012 {STRING_TOKEN(STR_BLK_IO2), &gEfiBlockIo2ProtocolGuid, NULL},\r
1013 {STRING_TOKEN(STR_SSC), &gEfiStorageSecurityCommandProtocolGuid, NULL},\r
12f1a36c 1014 {STRING_TOKEN(STR_UCRED2), &gEfiUserCredential2ProtocolGuid, NULL},\r
dee34318 1015\r
28cdb62b
CP
1016//\r
1017// UEFI 2.4\r
1018//\r
1019 {STRING_TOKEN(STR_DISK_IO2), &gEfiDiskIo2ProtocolGuid, NULL},\r
59febea1 1020 {STRING_TOKEN(STR_ADAPTER_INFO), &gEfiAdapterInformationProtocolGuid, AdapterInformationDumpInformation},\r
28cdb62b 1021\r
6b640b4a
JC
1022//\r
1023// PI Spec ones\r
1024//\r
1025 {STRING_TOKEN(STR_IDE_CONT_INIT), &gEfiIdeControllerInitProtocolGuid, NULL},\r
4024c116 1026 {STRING_TOKEN(STR_DISK_INFO), &gEfiDiskInfoProtocolGuid, NULL},\r
6b640b4a 1027\r
0a1eb97d
JC
1028//\r
1029// UEFI Shell Spec 2.0\r
1030//\r
1031 {STRING_TOKEN(STR_SHELL_PARAMETERS), &gEfiShellParametersProtocolGuid, NULL},\r
1032 {STRING_TOKEN(STR_SHELL), &gEfiShellProtocolGuid, NULL},\r
1033\r
1034//\r
1035// UEFI Shell Spec 2.1\r
1036//\r
1037 {STRING_TOKEN(STR_SHELL_DYNAMIC), &gEfiShellDynamicCommandProtocolGuid, NULL},\r
1038\r
dee34318 1039//\r
1040// terminator\r
1041//\r
a405b86d 1042 {STRING_TOKEN(STR_UNKNOWN_DEVICE), NULL, NULL},\r
1043};\r
1044\r
1045/**\r
1046 Function to get the node for a protocol or struct from it's GUID.\r
1047\r
1048 if Guid is NULL, then ASSERT.\r
1049\r
1050 @param[in] Guid The GUID to look for the name of.\r
1051\r
1052 @return The node.\r
1053**/\r
dee34318 1054CONST GUID_INFO_BLOCK *\r
a405b86d 1055EFIAPI\r
1056InternalShellGetNodeFromGuid(\r
1057 IN CONST EFI_GUID* Guid\r
1058 )\r
1059{\r
dee34318 1060 CONST GUID_INFO_BLOCK *ListWalker;\r
6306fd90 1061 UINTN LoopCount;\r
a405b86d 1062\r
1063 ASSERT(Guid != NULL);\r
1064\r
6306fd90
JC
1065 for (LoopCount = 0, ListWalker = GuidList; GuidList != NULL && LoopCount < GuidListCount; LoopCount++, ListWalker++) {\r
1066 if (CompareGuid(ListWalker->GuidId, Guid)) {\r
1067 return (ListWalker);\r
1068 }\r
1069 }\r
1070\r
a405b86d 1071 if (PcdGetBool(PcdShellIncludeNtGuids)) {\r
1072 for (ListWalker = mGuidStringListNT ; ListWalker != NULL && ListWalker->GuidId != NULL ; ListWalker++) {\r
1073 if (CompareGuid(ListWalker->GuidId, Guid)) {\r
1074 return (ListWalker);\r
1075 }\r
1076 }\r
1077 }\r
1078 for (ListWalker = mGuidStringList ; ListWalker != NULL && ListWalker->GuidId != NULL ; ListWalker++) {\r
1079 if (CompareGuid(ListWalker->GuidId, Guid)) {\r
1080 return (ListWalker);\r
1081 }\r
1082 }\r
6306fd90
JC
1083 return (NULL);\r
1084}\r
1085\r
1086/**\r
1087Function to add a new GUID/Name mapping.\r
1088\r
1089@param[in] Guid The Guid\r
f5ba4007
QS
1090@param[in] NameID The STRING id of the HII string to use\r
1091@param[in] DumpFunc The pointer to the dump function\r
6306fd90
JC
1092\r
1093\r
1094@retval EFI_SUCCESS The operation was sucessful\r
1095@retval EFI_OUT_OF_RESOURCES A memory allocation failed\r
1096@retval EFI_INVALID_PARAMETER Guid NameId was invalid\r
1097**/\r
6306fd90
JC
1098EFI_STATUS\r
1099EFIAPI\r
1100InsertNewGuidNameMapping(\r
1101 IN CONST EFI_GUID *Guid,\r
1102 IN CONST EFI_STRING_ID NameID,\r
1103 IN CONST DUMP_PROTOCOL_INFO DumpFunc OPTIONAL\r
1104 )\r
1105{\r
1106 ASSERT(Guid != NULL);\r
1107 ASSERT(NameID != 0);\r
1108\r
1109 GuidList = ReallocatePool(GuidListCount * sizeof(GUID_INFO_BLOCK), GuidListCount+1 * sizeof(GUID_INFO_BLOCK), GuidList);\r
1110 if (GuidList == NULL) {\r
1111 GuidListCount = 0;\r
1112 return (EFI_OUT_OF_RESOURCES);\r
1113 }\r
1114 GuidListCount++;\r
1115\r
1116 GuidList[GuidListCount - 1].GuidId = AllocateCopyPool(sizeof(EFI_GUID), Guid);\r
1117 GuidList[GuidListCount - 1].StringId = NameID;\r
1118 GuidList[GuidListCount - 1].DumpInfo = DumpFunc;\r
1119\r
1120 if (GuidList[GuidListCount - 1].GuidId == NULL) {\r
1121 return (EFI_OUT_OF_RESOURCES);\r
1122 }\r
1123\r
1124 return (EFI_SUCCESS);\r
1125}\r
1126\r
1127/**\r
1128 Function to add a new GUID/Name mapping.\r
1129\r
1130 This cannot overwrite an existing mapping.\r
1131\r
1132 @param[in] Guid The Guid\r
1133 @param[in] TheName The Guid's name\r
1134 @param[in] Lang RFC4646 language code list or NULL\r
1135\r
1136 @retval EFI_SUCCESS The operation was sucessful\r
1137 @retval EFI_ACCESS_DENIED There was a duplicate\r
1138 @retval EFI_OUT_OF_RESOURCES A memory allocation failed\r
1139 @retval EFI_INVALID_PARAMETER Guid or TheName was NULL\r
1140**/\r
1141EFI_STATUS\r
1142EFIAPI\r
1143AddNewGuidNameMapping(\r
1144 IN CONST EFI_GUID *Guid,\r
1145 IN CONST CHAR16 *TheName,\r
1146 IN CONST CHAR8 *Lang OPTIONAL\r
1147 )\r
1148{\r
6306fd90
JC
1149 EFI_STRING_ID NameID;\r
1150\r
e7e0e42b
CP
1151 HandleParsingHiiInit();\r
1152\r
6306fd90
JC
1153 if (Guid == NULL || TheName == NULL){\r
1154 return (EFI_INVALID_PARAMETER);\r
1155 }\r
1156\r
931b2cff 1157 if ((InternalShellGetNodeFromGuid(Guid)) != NULL) {\r
6306fd90
JC
1158 return (EFI_ACCESS_DENIED);\r
1159 }\r
1160\r
1161 NameID = HiiSetString(mHandleParsingHiiHandle, 0, (CHAR16*)TheName, Lang);\r
1162 if (NameID == 0) {\r
1163 return (EFI_OUT_OF_RESOURCES);\r
1164 }\r
1165\r
1166 return (InsertNewGuidNameMapping(Guid, NameID, NULL));\r
a405b86d 1167}\r
1168\r
1169/**\r
1170 Function to get the name of a protocol or struct from it's GUID.\r
1171\r
1172 if Guid is NULL, then ASSERT.\r
1173\r
1174 @param[in] Guid The GUID to look for the name of.\r
1175 @param[in] Lang The language to use.\r
1176\r
1177 @return pointer to string of the name. The caller\r
1178 is responsible to free this memory.\r
1179**/\r
1180CHAR16*\r
1181EFIAPI\r
1182GetStringNameFromGuid(\r
1183 IN CONST EFI_GUID *Guid,\r
1184 IN CONST CHAR8 *Lang OPTIONAL\r
1185 )\r
1186{\r
dee34318 1187 CONST GUID_INFO_BLOCK *Id;\r
a405b86d 1188\r
e7e0e42b
CP
1189 HandleParsingHiiInit();\r
1190\r
a405b86d 1191 Id = InternalShellGetNodeFromGuid(Guid);\r
6306fd90 1192 return (HiiGetString(mHandleParsingHiiHandle, Id==NULL?STRING_TOKEN(STR_UNKNOWN_DEVICE):Id->StringId, Lang));\r
a405b86d 1193}\r
1194\r
1195/**\r
1196 Function to dump protocol information from a handle.\r
1197\r
1198 This function will return a allocated string buffer containing the\r
1199 information. The caller is responsible for freeing the memory.\r
1200\r
1201 If Guid is NULL, ASSERT().\r
1202 If TheHandle is NULL, ASSERT().\r
1203\r
1204 @param[in] TheHandle The handle to dump information from.\r
1205 @param[in] Guid The GUID of the protocol to dump.\r
1206 @param[in] Verbose TRUE for extra info. FALSE otherwise.\r
1207\r
1208 @return The pointer to string.\r
1209 @retval NULL An error was encountered.\r
1210**/\r
1211CHAR16*\r
1212EFIAPI\r
1213GetProtocolInformationDump(\r
1214 IN CONST EFI_HANDLE TheHandle,\r
1215 IN CONST EFI_GUID *Guid,\r
1216 IN CONST BOOLEAN Verbose\r
1217 )\r
1218{\r
dee34318 1219 CONST GUID_INFO_BLOCK *Id;\r
a405b86d 1220\r
1221 ASSERT(TheHandle != NULL);\r
1222 ASSERT(Guid != NULL);\r
1223\r
1224 if (TheHandle == NULL || Guid == NULL) {\r
1225 return (NULL);\r
1226 }\r
1227\r
1228 Id = InternalShellGetNodeFromGuid(Guid);\r
1229 if (Id != NULL && Id->DumpInfo != NULL) {\r
1230 return (Id->DumpInfo(TheHandle, Verbose));\r
1231 }\r
1232 return (NULL);\r
1233}\r
1234\r
1235/**\r
1236 Function to get the Guid for a protocol or struct based on it's string name.\r
1237\r
0a1eb97d
JC
1238 do not modify the returned Guid.\r
1239\r
a405b86d 1240 @param[in] Name The pointer to the string name.\r
1241 @param[in] Lang The pointer to the language code.\r
0a1eb97d 1242 @param[out] Guid The pointer to the Guid.\r
a405b86d 1243\r
1244 @retval EFI_SUCCESS The operation was sucessful.\r
1245**/\r
1246EFI_STATUS\r
1247EFIAPI\r
1248GetGuidFromStringName(\r
1249 IN CONST CHAR16 *Name,\r
1250 IN CONST CHAR8 *Lang OPTIONAL,\r
0a1eb97d 1251 OUT EFI_GUID **Guid\r
a405b86d 1252 )\r
1253{\r
dee34318 1254 CONST GUID_INFO_BLOCK *ListWalker;\r
a405b86d 1255 CHAR16 *String;\r
6306fd90 1256 UINTN LoopCount;\r
a405b86d 1257\r
e7e0e42b
CP
1258 HandleParsingHiiInit();\r
1259\r
a405b86d 1260 ASSERT(Guid != NULL);\r
1261 if (Guid == NULL) {\r
1262 return (EFI_INVALID_PARAMETER);\r
1263 }\r
1264 *Guid = NULL;\r
1265\r
1266 if (PcdGetBool(PcdShellIncludeNtGuids)) {\r
1267 for (ListWalker = mGuidStringListNT ; ListWalker != NULL && ListWalker->GuidId != NULL ; ListWalker++) {\r
1268 String = HiiGetString(mHandleParsingHiiHandle, ListWalker->StringId, Lang);\r
28cdb62b 1269 if (Name != NULL && String != NULL && StringNoCaseCompare (&Name, &String) == 0) {\r
a405b86d 1270 *Guid = ListWalker->GuidId;\r
1271 }\r
1272 SHELL_FREE_NON_NULL(String);\r
1273 if (*Guid != NULL) {\r
1274 return (EFI_SUCCESS);\r
1275 }\r
1276 }\r
1277 }\r
1278 for (ListWalker = mGuidStringList ; ListWalker != NULL && ListWalker->GuidId != NULL ; ListWalker++) {\r
1279 String = HiiGetString(mHandleParsingHiiHandle, ListWalker->StringId, Lang);\r
28cdb62b 1280 if (Name != NULL && String != NULL && StringNoCaseCompare (&Name, &String) == 0) {\r
a405b86d 1281 *Guid = ListWalker->GuidId;\r
1282 }\r
1283 SHELL_FREE_NON_NULL(String);\r
1284 if (*Guid != NULL) {\r
1285 return (EFI_SUCCESS);\r
1286 }\r
1287 }\r
6306fd90
JC
1288\r
1289 for (LoopCount = 0, ListWalker = GuidList; GuidList != NULL && LoopCount < GuidListCount; LoopCount++, ListWalker++) {\r
1290 String = HiiGetString(mHandleParsingHiiHandle, ListWalker->StringId, Lang);\r
1291 if (Name != NULL && String != NULL && StringNoCaseCompare (&Name, &String) == 0) {\r
1292 *Guid = ListWalker->GuidId;\r
1293 }\r
1294 SHELL_FREE_NON_NULL(String);\r
1295 if (*Guid != NULL) {\r
1296 return (EFI_SUCCESS);\r
1297 }\r
1298 }\r
1299\r
a405b86d 1300 return (EFI_NOT_FOUND);\r
1301}\r
1302\r
36384ceb
ED
1303/**\r
1304 Get best support language for this driver.\r
1a6f74d9
CS
1305\r
1306 First base on the user input language to search, second base on the current\r
1307 platform used language to search, third get the first language from the\r
a71003f2 1308 support language list. The caller need to free the buffer of the best language.\r
36384ceb
ED
1309\r
1310 @param[in] SupportedLanguages The support languages for this driver.\r
a71003f2 1311 @param[in] InputLanguage The user input language.\r
36384ceb
ED
1312 @param[in] Iso639Language Whether get language for ISO639.\r
1313\r
1314 @return The best support language for this driver.\r
1315**/\r
1316CHAR8 *\r
a71003f2 1317EFIAPI\r
36384ceb 1318GetBestLanguageForDriver (\r
a71003f2
ED
1319 IN CONST CHAR8 *SupportedLanguages,\r
1320 IN CONST CHAR8 *InputLanguage,\r
36384ceb
ED
1321 IN BOOLEAN Iso639Language\r
1322 )\r
1323{\r
1324 CHAR8 *LanguageVariable;\r
1325 CHAR8 *BestLanguage;\r
1326\r
3cdd434e 1327 GetVariable2 (Iso639Language ? L"Lang" : L"PlatformLang", &gEfiGlobalVariableGuid, (VOID**)&LanguageVariable, NULL);\r
36384ceb
ED
1328\r
1329 BestLanguage = GetBestLanguage(\r
1330 SupportedLanguages,\r
1331 Iso639Language,\r
a71003f2 1332 (InputLanguage != NULL) ? InputLanguage : "",\r
36384ceb 1333 (LanguageVariable != NULL) ? LanguageVariable : "",\r
a71003f2 1334 SupportedLanguages,\r
36384ceb
ED
1335 NULL\r
1336 );\r
1337\r
1338 if (LanguageVariable != NULL) {\r
1339 FreePool (LanguageVariable);\r
1340 }\r
1341\r
1342 return BestLanguage;\r
1343}\r
1344\r
a405b86d 1345/**\r
1346 Function to retrieve the driver name (if possible) from the ComponentName or\r
1347 ComponentName2 protocol\r
1348\r
1349 @param[in] TheHandle The driver handle to get the name of.\r
1350 @param[in] Language The language to use.\r
1351\r
1352 @retval NULL The name could not be found.\r
1353 @return A pointer to the string name. Do not de-allocate the memory.\r
1354**/\r
1355CONST CHAR16*\r
1356EFIAPI\r
1357GetStringNameFromHandle(\r
1358 IN CONST EFI_HANDLE TheHandle,\r
1359 IN CONST CHAR8 *Language\r
1360 )\r
1361{\r
1362 EFI_COMPONENT_NAME2_PROTOCOL *CompNameStruct;\r
1363 EFI_STATUS Status;\r
1364 CHAR16 *RetVal;\r
36384ceb
ED
1365 CHAR8 *BestLang;\r
1366\r
1367 BestLang = NULL;\r
a405b86d 1368\r
1369 Status = gBS->OpenProtocol(\r
1370 TheHandle,\r
1371 &gEfiComponentName2ProtocolGuid,\r
1372 (VOID**)&CompNameStruct,\r
1373 gImageHandle,\r
1374 NULL,\r
1375 EFI_OPEN_PROTOCOL_GET_PROTOCOL);\r
1376 if (!EFI_ERROR(Status)) {\r
a71003f2
ED
1377 BestLang = GetBestLanguageForDriver (CompNameStruct->SupportedLanguages, Language, FALSE);\r
1378 Status = CompNameStruct->GetDriverName(CompNameStruct, BestLang, &RetVal);\r
36384ceb
ED
1379 if (BestLang != NULL) {\r
1380 FreePool (BestLang);\r
1381 BestLang = NULL;\r
1382 }\r
a405b86d 1383 if (!EFI_ERROR(Status)) {\r
1384 return (RetVal);\r
1385 }\r
1386 }\r
1387 Status = gBS->OpenProtocol(\r
1388 TheHandle,\r
1389 &gEfiComponentNameProtocolGuid,\r
1390 (VOID**)&CompNameStruct,\r
1391 gImageHandle,\r
1392 NULL,\r
1393 EFI_OPEN_PROTOCOL_GET_PROTOCOL);\r
1394 if (!EFI_ERROR(Status)) {\r
a71003f2
ED
1395 BestLang = GetBestLanguageForDriver (CompNameStruct->SupportedLanguages, Language, FALSE);\r
1396 Status = CompNameStruct->GetDriverName(CompNameStruct, BestLang, &RetVal);\r
36384ceb
ED
1397 if (BestLang != NULL) {\r
1398 FreePool (BestLang);\r
1399 }\r
a405b86d 1400 if (!EFI_ERROR(Status)) {\r
1401 return (RetVal);\r
1402 }\r
1403 }\r
1404 return (NULL);\r
1405}\r
1406\r
1407/**\r
1408 Function to initialize the file global mHandleList object for use in\r
1409 vonverting handles to index and index to handle.\r
1410\r
1411 @retval EFI_SUCCESS The operation was successful.\r
1412**/\r
1413EFI_STATUS\r
1414EFIAPI\r
1415InternalShellInitHandleList(\r
1416 VOID\r
1417 )\r
1418{\r
1419 EFI_STATUS Status;\r
1420 EFI_HANDLE *HandleBuffer;\r
1421 UINTN HandleCount;\r
1422 HANDLE_LIST *ListWalker;\r
1423\r
1424 if (mHandleList.NextIndex != 0) {\r
1425 return EFI_SUCCESS;\r
1426 }\r
1427 InitializeListHead(&mHandleList.List.Link);\r
1428 mHandleList.NextIndex = 1;\r
1429 Status = gBS->LocateHandleBuffer (\r
1430 AllHandles,\r
1431 NULL,\r
1432 NULL,\r
1433 &HandleCount,\r
1434 &HandleBuffer\r
1435 );\r
1436 ASSERT_EFI_ERROR(Status);\r
1437 if (EFI_ERROR(Status)) {\r
1438 return (Status);\r
1439 }\r
1440 for (mHandleList.NextIndex = 1 ; mHandleList.NextIndex <= HandleCount ; mHandleList.NextIndex++){\r
78ed876b 1441 ListWalker = AllocateZeroPool(sizeof(HANDLE_LIST));\r
a405b86d 1442 ASSERT(ListWalker != NULL);\r
1443 ListWalker->TheHandle = HandleBuffer[mHandleList.NextIndex-1];\r
1444 ListWalker->TheIndex = mHandleList.NextIndex;\r
1445 InsertTailList(&mHandleList.List.Link,&ListWalker->Link);\r
1446 }\r
1447 FreePool(HandleBuffer);\r
1448 return (EFI_SUCCESS);\r
1449}\r
1450\r
1451/**\r
1452 Function to retrieve the human-friendly index of a given handle. If the handle\r
1453 does not have a index one will be automatically assigned. The index value is valid\r
1454 until the termination of the shell application.\r
1455\r
1456 @param[in] TheHandle The handle to retrieve an index for.\r
1457\r
1458 @retval 0 A memory allocation failed.\r
1459 @return The index of the handle.\r
1460\r
1461**/\r
1462UINTN\r
1463EFIAPI\r
1464ConvertHandleToHandleIndex(\r
1465 IN CONST EFI_HANDLE TheHandle\r
1466 )\r
1467{\r
f330ff35 1468 EFI_STATUS Status;\r
1469 EFI_GUID **ProtocolBuffer;\r
1470 UINTN ProtocolCount;\r
1471 HANDLE_LIST *ListWalker;\r
1472\r
78ed876b 1473 if (TheHandle == NULL) {\r
1474 return 0;\r
1475 }\r
a405b86d 1476\r
1477 InternalShellInitHandleList();\r
1478\r
1479 for (ListWalker = (HANDLE_LIST*)GetFirstNode(&mHandleList.List.Link)\r
1480 ; !IsNull(&mHandleList.List.Link,&ListWalker->Link)\r
1481 ; ListWalker = (HANDLE_LIST*)GetNextNode(&mHandleList.List.Link,&ListWalker->Link)\r
1482 ){\r
1483 if (ListWalker->TheHandle == TheHandle) {\r
f330ff35 1484 //\r
1485 // Verify that TheHandle is still present in the Handle Database\r
1486 //\r
1487 Status = gBS->ProtocolsPerHandle(TheHandle, &ProtocolBuffer, &ProtocolCount);\r
1488 if (EFI_ERROR (Status)) {\r
1489 //\r
1490 // TheHandle is not present in the Handle Database, so delete from the handle list\r
1491 //\r
1492 RemoveEntryList (&ListWalker->Link);\r
1493 return 0;\r
1494 }\r
1495 FreePool (ProtocolBuffer);\r
a405b86d 1496 return (ListWalker->TheIndex);\r
1497 }\r
1498 }\r
f330ff35 1499\r
1500 //\r
1501 // Verify that TheHandle is valid handle\r
1502 //\r
1503 Status = gBS->ProtocolsPerHandle(TheHandle, &ProtocolBuffer, &ProtocolCount);\r
1504 if (EFI_ERROR (Status)) {\r
1505 //\r
1506 // TheHandle is not valid, so do not add to handle list\r
1507 //\r
1508 return 0;\r
1509 }\r
1510 FreePool (ProtocolBuffer);\r
1511\r
78ed876b 1512 ListWalker = AllocateZeroPool(sizeof(HANDLE_LIST));\r
a405b86d 1513 ASSERT(ListWalker != NULL);\r
1514 ListWalker->TheHandle = TheHandle;\r
1515 ListWalker->TheIndex = mHandleList.NextIndex++;\r
1516 InsertTailList(&mHandleList.List.Link,&ListWalker->Link);\r
1517 return (ListWalker->TheIndex);\r
1518}\r
1519\r
1520\r
1521\r
1522/**\r
1523 Function to retrieve the EFI_HANDLE from the human-friendly index.\r
1524\r
1525 @param[in] TheIndex The index to retrieve the EFI_HANDLE for.\r
1526\r
1527 @retval NULL The index was invalid.\r
1528 @return The EFI_HANDLE that index represents.\r
1529\r
1530**/\r
1531EFI_HANDLE\r
1532EFIAPI\r
1533ConvertHandleIndexToHandle(\r
1534 IN CONST UINTN TheIndex\r
1535 )\r
1536{\r
f330ff35 1537 EFI_STATUS Status;\r
1538 EFI_GUID **ProtocolBuffer;\r
1539 UINTN ProtocolCount;\r
a405b86d 1540 HANDLE_LIST *ListWalker;\r
1541\r
1542 InternalShellInitHandleList();\r
1543\r
1544 if (TheIndex >= mHandleList.NextIndex) {\r
f330ff35 1545 return NULL;\r
a405b86d 1546 }\r
1547\r
1548 for (ListWalker = (HANDLE_LIST*)GetFirstNode(&mHandleList.List.Link)\r
1549 ; !IsNull(&mHandleList.List.Link,&ListWalker->Link)\r
1550 ; ListWalker = (HANDLE_LIST*)GetNextNode(&mHandleList.List.Link,&ListWalker->Link)\r
1551 ){\r
f330ff35 1552 if (ListWalker->TheIndex == TheIndex && ListWalker->TheHandle != NULL) {\r
1553 //\r
1554 // Verify that LinkWalker->TheHandle is valid handle\r
1555 //\r
1556 Status = gBS->ProtocolsPerHandle(ListWalker->TheHandle, &ProtocolBuffer, &ProtocolCount);\r
1557 if (EFI_ERROR (Status)) {\r
1558 //\r
1559 // TheHandle is not valid, so do not add to handle list\r
1560 //\r
1561 ListWalker->TheHandle = NULL;\r
1562 }\r
a405b86d 1563 return (ListWalker->TheHandle);\r
1564 }\r
1565 }\r
f330ff35 1566 return NULL;\r
a405b86d 1567}\r
1568\r
1569/**\r
1570 Gets all the related EFI_HANDLEs based on the mask supplied.\r
1571\r
1572 This function scans all EFI_HANDLES in the UEFI environment's handle database\r
1573 and returns the ones with the specified relationship (Mask) to the specified\r
1574 controller handle.\r
1575\r
1576 If both DriverBindingHandle and ControllerHandle are NULL, then ASSERT.\r
1577 If MatchingHandleCount is NULL, then ASSERT.\r
1578\r
1579 If MatchingHandleBuffer is not NULL upon a successful return the memory must be\r
1580 caller freed.\r
1581\r
1582 @param[in] DriverBindingHandle The handle with Driver Binding protocol on it.\r
1583 @param[in] ControllerHandle The handle with Device Path protocol on it.\r
1584 @param[in] MatchingHandleCount The pointer to UINTN that specifies the number of HANDLES in\r
1585 MatchingHandleBuffer.\r
1586 @param[out] MatchingHandleBuffer On a successful return, a buffer of MatchingHandleCount\r
1587 EFI_HANDLEs with a terminating NULL EFI_HANDLE.\r
1588 @param[out] HandleType An array of type information.\r
1589\r
1590 @retval EFI_SUCCESS The operation was successful, and any related handles\r
1591 are in MatchingHandleBuffer.\r
1592 @retval EFI_NOT_FOUND No matching handles were found.\r
1593 @retval EFI_INVALID_PARAMETER A parameter was invalid or out of range.\r
1594**/\r
1595EFI_STATUS\r
1596EFIAPI\r
1597ParseHandleDatabaseByRelationshipWithType (\r
1598 IN CONST EFI_HANDLE DriverBindingHandle OPTIONAL,\r
1599 IN CONST EFI_HANDLE ControllerHandle OPTIONAL,\r
1600 IN UINTN *HandleCount,\r
1601 OUT EFI_HANDLE **HandleBuffer,\r
1602 OUT UINTN **HandleType\r
1603 )\r
1604{\r
1605 EFI_STATUS Status;\r
1606 UINTN HandleIndex;\r
1607 EFI_GUID **ProtocolGuidArray;\r
1608 UINTN ArrayCount;\r
1609 UINTN ProtocolIndex;\r
1610 EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfo;\r
1611 UINTN OpenInfoCount;\r
1612 UINTN OpenInfoIndex;\r
1613 UINTN ChildIndex;\r
f330ff35 1614 INTN DriverBindingHandleIndex;\r
a405b86d 1615\r
1616 ASSERT(HandleCount != NULL);\r
1617 ASSERT(HandleBuffer != NULL);\r
1618 ASSERT(HandleType != NULL);\r
1619 ASSERT(DriverBindingHandle != NULL || ControllerHandle != NULL);\r
1620\r
1621 *HandleCount = 0;\r
1622 *HandleBuffer = NULL;\r
1623 *HandleType = NULL;\r
1624\r
1625 //\r
1626 // Retrieve the list of all handles from the handle database\r
1627 //\r
1628 Status = gBS->LocateHandleBuffer (\r
1629 AllHandles,\r
1630 NULL,\r
1631 NULL,\r
1632 HandleCount,\r
1633 HandleBuffer\r
1634 );\r
1635 if (EFI_ERROR (Status)) {\r
1636 return (Status);\r
1637 }\r
1638\r
1639 *HandleType = AllocateZeroPool (*HandleCount * sizeof (UINTN));\r
1640 ASSERT(*HandleType != NULL);\r
1641\r
f330ff35 1642 DriverBindingHandleIndex = -1;\r
1643 for (HandleIndex = 0; HandleIndex < *HandleCount; HandleIndex++) {\r
1644 if (DriverBindingHandle != NULL && (*HandleBuffer)[HandleIndex] == DriverBindingHandle) {\r
1645 DriverBindingHandleIndex = (INTN)HandleIndex;\r
1646 }\r
1647 }\r
1648\r
a405b86d 1649 for (HandleIndex = 0; HandleIndex < *HandleCount; HandleIndex++) {\r
1650 //\r
1651 // Retrieve the list of all the protocols on each handle\r
1652 //\r
1653 Status = gBS->ProtocolsPerHandle (\r
1654 (*HandleBuffer)[HandleIndex],\r
1655 &ProtocolGuidArray,\r
1656 &ArrayCount\r
1657 );\r
f330ff35 1658 if (EFI_ERROR (Status)) {\r
1659 continue;\r
1660 }\r
a405b86d 1661\r
f330ff35 1662 for (ProtocolIndex = 0; ProtocolIndex < ArrayCount; ProtocolIndex++) {\r
a405b86d 1663\r
f330ff35 1664 //\r
1665 // Set the bit describing what this handle has\r
1666 //\r
1667 if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiLoadedImageProtocolGuid) ) {\r
7aae3c35 1668 (*HandleType)[HandleIndex] |= (UINTN)HR_IMAGE_HANDLE;\r
f330ff35 1669 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverBindingProtocolGuid) ) {\r
7aae3c35 1670 (*HandleType)[HandleIndex] |= (UINTN)HR_DRIVER_BINDING_HANDLE;\r
f330ff35 1671 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverConfiguration2ProtocolGuid)) {\r
7aae3c35 1672 (*HandleType)[HandleIndex] |= (UINTN)HR_DRIVER_CONFIGURATION_HANDLE;\r
f330ff35 1673 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverConfigurationProtocolGuid) ) {\r
7aae3c35 1674 (*HandleType)[HandleIndex] |= (UINTN)HR_DRIVER_CONFIGURATION_HANDLE;\r
f330ff35 1675 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverDiagnostics2ProtocolGuid) ) {\r
7aae3c35 1676 (*HandleType)[HandleIndex] |= (UINTN)HR_DRIVER_DIAGNOSTICS_HANDLE;\r
f330ff35 1677 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverDiagnosticsProtocolGuid) ) {\r
7aae3c35 1678 (*HandleType)[HandleIndex] |= (UINTN)HR_DRIVER_DIAGNOSTICS_HANDLE;\r
f330ff35 1679 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiComponentName2ProtocolGuid) ) {\r
7aae3c35 1680 (*HandleType)[HandleIndex] |= (UINTN)HR_COMPONENT_NAME_HANDLE;\r
f330ff35 1681 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiComponentNameProtocolGuid) ) {\r
7aae3c35 1682 (*HandleType)[HandleIndex] |= (UINTN)HR_COMPONENT_NAME_HANDLE;\r
f330ff35 1683 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDevicePathProtocolGuid) ) {\r
7aae3c35 1684 (*HandleType)[HandleIndex] |= (UINTN)HR_DEVICE_HANDLE;\r
f330ff35 1685 } else {\r
1686 DEBUG_CODE_BEGIN();\r
1687 ASSERT((*HandleType)[HandleIndex] == (*HandleType)[HandleIndex]);\r
1688 DEBUG_CODE_END();\r
1689 }\r
1690 //\r
1691 // Retrieve the list of agents that have opened each protocol\r
1692 //\r
1693 Status = gBS->OpenProtocolInformation (\r
a405b86d 1694 (*HandleBuffer)[HandleIndex],\r
1695 ProtocolGuidArray[ProtocolIndex],\r
1696 &OpenInfo,\r
1697 &OpenInfoCount\r
1698 );\r
f330ff35 1699 if (EFI_ERROR (Status)) {\r
1700 continue;\r
1701 }\r
1702\r
1703 if (ControllerHandle == NULL) {\r
1704 //\r
1a6f74d9 1705 // ControllerHandle == NULL and DriverBindingHandle != NULL.\r
f330ff35 1706 // Return information on all the controller handles that the driver specified by DriverBindingHandle is managing\r
1707 //\r
1708 for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) {\r
1709 if (OpenInfo[OpenInfoIndex].AgentHandle == DriverBindingHandle && (OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) != 0) {\r
7aae3c35 1710 (*HandleType)[HandleIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_CONTROLLER_HANDLE);\r
f330ff35 1711 if (DriverBindingHandleIndex != -1) {\r
7aae3c35 1712 (*HandleType)[DriverBindingHandleIndex] |= (UINTN)HR_DEVICE_DRIVER;\r
f330ff35 1713 }\r
1714 }\r
1715 if (OpenInfo[OpenInfoIndex].AgentHandle == DriverBindingHandle && (OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {\r
7aae3c35 1716 (*HandleType)[HandleIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_CONTROLLER_HANDLE);\r
f330ff35 1717 if (DriverBindingHandleIndex != -1) {\r
7aae3c35 1718 (*HandleType)[DriverBindingHandleIndex] |= (UINTN)(HR_BUS_DRIVER | HR_DEVICE_DRIVER);\r
f330ff35 1719 }\r
1720 for (ChildIndex = 0; ChildIndex < *HandleCount; ChildIndex++) {\r
1721 if (OpenInfo[OpenInfoIndex].ControllerHandle == (*HandleBuffer)[ChildIndex]) {\r
7aae3c35 1722 (*HandleType)[ChildIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_CHILD_HANDLE);\r
f330ff35 1723 }\r
1724 }\r
1725 }\r
1726 }\r
1727 }\r
1728 if (DriverBindingHandle == NULL && ControllerHandle != NULL) {\r
1729 if (ControllerHandle == (*HandleBuffer)[HandleIndex]) {\r
7aae3c35 1730 (*HandleType)[HandleIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_CONTROLLER_HANDLE);\r
a405b86d 1731 for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) {\r
f330ff35 1732 if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) != 0) {\r
1733 for (ChildIndex = 0; ChildIndex < *HandleCount; ChildIndex++) {\r
1734 if (OpenInfo[OpenInfoIndex].AgentHandle == (*HandleBuffer)[ChildIndex]) {\r
7aae3c35 1735 (*HandleType)[ChildIndex] |= (UINTN)HR_DEVICE_DRIVER;\r
f330ff35 1736 }\r
a405b86d 1737 }\r
f330ff35 1738 }\r
1739 if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {\r
1740 for (ChildIndex = 0; ChildIndex < *HandleCount; ChildIndex++) {\r
1741 if (OpenInfo[OpenInfoIndex].AgentHandle == (*HandleBuffer)[ChildIndex]) {\r
7aae3c35 1742 (*HandleType)[ChildIndex] |= (UINTN)(HR_BUS_DRIVER | HR_DEVICE_DRIVER);\r
f330ff35 1743 }\r
1744 if (OpenInfo[OpenInfoIndex].ControllerHandle == (*HandleBuffer)[ChildIndex]) {\r
7aae3c35 1745 (*HandleType)[ChildIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_CHILD_HANDLE);\r
a405b86d 1746 }\r
1747 }\r
1748 }\r
f330ff35 1749 }\r
1750 } else {\r
1751 for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) {\r
1752 if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {\r
1753 if (OpenInfo[OpenInfoIndex].ControllerHandle == ControllerHandle) {\r
7aae3c35 1754 (*HandleType)[HandleIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_PARENT_HANDLE);\r
f330ff35 1755 }\r
1756 }\r
1757 }\r
1758 }\r
1759 }\r
1760 if (DriverBindingHandle != NULL && ControllerHandle != NULL) {\r
1761 if (ControllerHandle == (*HandleBuffer)[HandleIndex]) {\r
7aae3c35 1762 (*HandleType)[HandleIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_CONTROLLER_HANDLE);\r
f330ff35 1763 for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) {\r
1764 if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) != 0) {\r
1765 if (OpenInfo[OpenInfoIndex].AgentHandle == DriverBindingHandle) {\r
1766 if (DriverBindingHandleIndex != -1) {\r
7aae3c35 1767 (*HandleType)[DriverBindingHandleIndex] |= (UINTN)HR_DEVICE_DRIVER;\r
a405b86d 1768 }\r
1769 }\r
f330ff35 1770 }\r
1771 if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {\r
1772 if (OpenInfo[OpenInfoIndex].AgentHandle == DriverBindingHandle) {\r
a405b86d 1773 for (ChildIndex = 0; ChildIndex < *HandleCount; ChildIndex++) {\r
f330ff35 1774 if (OpenInfo[OpenInfoIndex].ControllerHandle == (*HandleBuffer)[ChildIndex]) {\r
7aae3c35 1775 (*HandleType)[ChildIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_CHILD_HANDLE);\r
a405b86d 1776 }\r
1777 }\r
1778 }\r
f330ff35 1779\r
1780 for (ChildIndex = 0; ChildIndex < *HandleCount; ChildIndex++) {\r
1781 if (OpenInfo[OpenInfoIndex].AgentHandle == (*HandleBuffer)[ChildIndex]) {\r
7aae3c35 1782 (*HandleType)[ChildIndex] |= (UINTN)(HR_BUS_DRIVER | HR_DEVICE_DRIVER);\r
f330ff35 1783 }\r
1784 }\r
1785 }\r
1786 }\r
1787 } else {\r
1788 for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) {\r
1789 if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {\r
1790 if (OpenInfo[OpenInfoIndex].ControllerHandle == ControllerHandle) {\r
7aae3c35 1791 (*HandleType)[HandleIndex] |= (UINTN)(HR_DEVICE_HANDLE | HR_PARENT_HANDLE);\r
f330ff35 1792 }\r
a405b86d 1793 }\r
1794 }\r
a405b86d 1795 }\r
1796 }\r
f330ff35 1797 FreePool (OpenInfo);\r
a405b86d 1798 }\r
f330ff35 1799 FreePool (ProtocolGuidArray);\r
a405b86d 1800 }\r
f330ff35 1801 return EFI_SUCCESS;\r
a405b86d 1802}\r
1803\r
1804/**\r
1805 Gets all the related EFI_HANDLEs based on the single EFI_HANDLE and the mask\r
1806 supplied.\r
1807\r
1808 This function will scan all EFI_HANDLES in the UEFI environment's handle database\r
1809 and return all the ones with the specified relationship (Mask) to the specified\r
1810 controller handle.\r
1811\r
1812 If both DriverBindingHandle and ControllerHandle are NULL, then ASSERT.\r
1813 If MatchingHandleCount is NULL, then ASSERT.\r
1814\r
1815 If MatchingHandleBuffer is not NULL upon a sucessful return the memory must be\r
1816 caller freed.\r
1817\r
1818 @param[in] DriverBindingHandle Handle to a object with Driver Binding protocol\r
1819 on it.\r
1820 @param[in] ControllerHandle Handle to a device with Device Path protocol on it.\r
1821 @param[in] Mask Mask of what relationship(s) is desired.\r
1822 @param[in] MatchingHandleCount Poitner to UINTN specifying number of HANDLES in\r
1823 MatchingHandleBuffer.\r
1824 @param[out] MatchingHandleBuffer On a sucessful return a buffer of MatchingHandleCount\r
1825 EFI_HANDLEs and a terminating NULL EFI_HANDLE.\r
1826\r
1827 @retval EFI_SUCCESS The operation was sucessful and any related handles\r
1828 are in MatchingHandleBuffer;\r
1829 @retval EFI_NOT_FOUND No matching handles were found.\r
1830 @retval EFI_INVALID_PARAMETER A parameter was invalid or out of range.\r
1831**/\r
1832EFI_STATUS\r
1833EFIAPI\r
1834ParseHandleDatabaseByRelationship (\r
1835 IN CONST EFI_HANDLE DriverBindingHandle OPTIONAL,\r
1836 IN CONST EFI_HANDLE ControllerHandle OPTIONAL,\r
1837 IN CONST UINTN Mask,\r
1838 IN UINTN *MatchingHandleCount,\r
1839 OUT EFI_HANDLE **MatchingHandleBuffer OPTIONAL\r
1840 )\r
1841{\r
1842 EFI_STATUS Status;\r
1843 UINTN HandleCount;\r
1844 EFI_HANDLE *HandleBuffer;\r
1845 UINTN *HandleType;\r
1846 UINTN HandleIndex;\r
1847\r
1848 ASSERT(MatchingHandleCount != NULL);\r
1849 ASSERT(DriverBindingHandle != NULL || ControllerHandle != NULL);\r
1850\r
1851 if ((Mask & HR_VALID_MASK) != Mask) {\r
1852 return (EFI_INVALID_PARAMETER);\r
1853 }\r
1854\r
1855 if ((Mask & HR_CHILD_HANDLE) != 0 && DriverBindingHandle == NULL) {\r
1856 return (EFI_INVALID_PARAMETER);\r
1857 }\r
1858\r
1859 *MatchingHandleCount = 0;\r
1860 if (MatchingHandleBuffer != NULL) {\r
1861 *MatchingHandleBuffer = NULL;\r
1862 }\r
1863\r
1864 HandleBuffer = NULL;\r
1865 HandleType = NULL;\r
1866\r
1867 Status = ParseHandleDatabaseByRelationshipWithType (\r
1868 DriverBindingHandle,\r
1869 ControllerHandle,\r
1870 &HandleCount,\r
1871 &HandleBuffer,\r
1872 &HandleType\r
1873 );\r
1874 if (!EFI_ERROR (Status)) {\r
1875 //\r
1876 // Count the number of handles that match the attributes in Mask\r
1877 //\r
1878 for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {\r
1879 if ((HandleType[HandleIndex] & Mask) == Mask) {\r
1880 (*MatchingHandleCount)++;\r
1881 }\r
1882 }\r
1883 //\r
1884 // If no handles match the attributes in Mask then return EFI_NOT_FOUND\r
1885 //\r
1886 if (*MatchingHandleCount == 0) {\r
1887 Status = EFI_NOT_FOUND;\r
1888 } else {\r
1889\r
1890 if (MatchingHandleBuffer == NULL) {\r
1891 //\r
1892 // Someone just wanted the count...\r
1893 //\r
1894 Status = EFI_SUCCESS;\r
1895 } else {\r
1896 //\r
1897 // Allocate a handle buffer for the number of handles that matched the attributes in Mask\r
1898 //\r
78ed876b 1899 *MatchingHandleBuffer = AllocateZeroPool ((*MatchingHandleCount +1)* sizeof (EFI_HANDLE));\r
a405b86d 1900 ASSERT(*MatchingHandleBuffer != NULL);\r
1901\r
1902 for (HandleIndex = 0,*MatchingHandleCount = 0\r
1903 ; HandleIndex < HandleCount\r
1904 ; HandleIndex++\r
1905 ){\r
1906 //\r
1907 // Fill the allocated buffer with the handles that matched the attributes in Mask\r
1908 //\r
1909 if ((HandleType[HandleIndex] & Mask) == Mask) {\r
1910 (*MatchingHandleBuffer)[(*MatchingHandleCount)++] = HandleBuffer[HandleIndex];\r
1911 }\r
1912 }\r
1913\r
1914 //\r
1915 // Make the last one NULL\r
1916 //\r
1917 (*MatchingHandleBuffer)[*MatchingHandleCount] = NULL;\r
1918\r
1919 Status = EFI_SUCCESS;\r
1920 } // MacthingHandleBuffer == NULL (ELSE)\r
1921 } // *MatchingHandleCount == 0 (ELSE)\r
1922 } // no error on ParseHandleDatabaseByRelationshipWithType\r
1923\r
1924 if (HandleBuffer != NULL) {\r
1925 FreePool (HandleBuffer);\r
1926 }\r
1927\r
1928 if (HandleType != NULL) {\r
1929 FreePool (HandleType);\r
1930 }\r
1931\r
1932 return Status;\r
1933}\r
1934\r
1935/**\r
1936 Gets handles for any child controllers of the passed in controller.\r
1937\r
1938 @param[in] ControllerHandle The handle of the "parent controller"\r
1939 @param[in] MatchingHandleCount Pointer to the number of handles in\r
1940 MatchingHandleBuffer on return.\r
1941 @param[out] MatchingHandleBuffer Buffer containing handles on a successful\r
1942 return.\r
1943\r
1944\r
1945 @retval EFI_SUCCESS The operation was sucessful.\r
1946**/\r
1947EFI_STATUS\r
1948EFIAPI\r
1949ParseHandleDatabaseForChildControllers(\r
1950 IN CONST EFI_HANDLE ControllerHandle,\r
1951 IN UINTN *MatchingHandleCount,\r
1952 OUT EFI_HANDLE **MatchingHandleBuffer OPTIONAL\r
1953 )\r
1954{\r
1955 EFI_STATUS Status;\r
f330ff35 1956 UINTN HandleIndex;\r
a405b86d 1957 UINTN DriverBindingHandleCount;\r
1958 EFI_HANDLE *DriverBindingHandleBuffer;\r
1959 UINTN DriverBindingHandleIndex;\r
1960 UINTN ChildControllerHandleCount;\r
1961 EFI_HANDLE *ChildControllerHandleBuffer;\r
1962 UINTN ChildControllerHandleIndex;\r
a405b86d 1963 EFI_HANDLE *HandleBufferForReturn;\r
1964\r
ff51746b 1965 if (MatchingHandleCount == NULL) {\r
1966 return (EFI_INVALID_PARAMETER);\r
1967 }\r
64d753f1 1968 *MatchingHandleCount = 0;\r
a405b86d 1969\r
1970 Status = PARSE_HANDLE_DATABASE_UEFI_DRIVERS (\r
1971 ControllerHandle,\r
1972 &DriverBindingHandleCount,\r
1973 &DriverBindingHandleBuffer\r
1974 );\r
1975 if (EFI_ERROR (Status)) {\r
1976 return Status;\r
1977 }\r
1978\r
ff51746b 1979 //\r
1980 // Get a buffer big enough for all the controllers.\r
1981 //\r
f330ff35 1982 HandleBufferForReturn = GetHandleListByProtocol(NULL);\r
a405b86d 1983 if (HandleBufferForReturn == NULL) {\r
1984 FreePool (DriverBindingHandleBuffer);\r
ff51746b 1985 return (EFI_NOT_FOUND);\r
a405b86d 1986 }\r
1987\r
a405b86d 1988 for (DriverBindingHandleIndex = 0; DriverBindingHandleIndex < DriverBindingHandleCount; DriverBindingHandleIndex++) {\r
1989 Status = PARSE_HANDLE_DATABASE_MANAGED_CHILDREN (\r
1990 DriverBindingHandleBuffer[DriverBindingHandleIndex],\r
1991 ControllerHandle,\r
1992 &ChildControllerHandleCount,\r
1993 &ChildControllerHandleBuffer\r
1994 );\r
1995 if (EFI_ERROR (Status)) {\r
1996 continue;\r
1997 }\r
1998\r
1999 for (ChildControllerHandleIndex = 0;\r
2000 ChildControllerHandleIndex < ChildControllerHandleCount;\r
2001 ChildControllerHandleIndex++\r
2002 ) {\r
f330ff35 2003 for (HandleIndex = 0; HandleIndex < *MatchingHandleCount; HandleIndex++) {\r
2004 if (HandleBufferForReturn[HandleIndex] == ChildControllerHandleBuffer[ChildControllerHandleIndex]) {\r
2005 break;\r
2006 }\r
2007 }\r
2008 if (HandleIndex >= *MatchingHandleCount) {\r
2009 HandleBufferForReturn[(*MatchingHandleCount)++] = ChildControllerHandleBuffer[ChildControllerHandleIndex];\r
2010 }\r
a405b86d 2011 }\r
2012\r
2013 FreePool (ChildControllerHandleBuffer);\r
2014 }\r
2015\r
2016 FreePool (DriverBindingHandleBuffer);\r
2017\r
2018 if (MatchingHandleBuffer != NULL) {\r
2019 *MatchingHandleBuffer = HandleBufferForReturn;\r
2020 } else {\r
2021 FreePool(HandleBufferForReturn);\r
2022 }\r
2023\r
2024 return (EFI_SUCCESS);\r
2025}\r
2026\r
2027/**\r
2028 Appends 1 buffer to another buffer. This will re-allocate the destination buffer\r
2029 if necessary to fit all of the data.\r
2030\r
2031 If DestinationBuffer is NULL, then ASSERT().\r
2032\r
4ff7e37b
ED
2033 @param[in, out] DestinationBuffer The pointer to the pointer to the buffer to append onto.\r
2034 @param[in, out] DestinationSize The pointer to the size of DestinationBuffer.\r
2035 @param[in] SourceBuffer The pointer to the buffer to append onto DestinationBuffer.\r
2036 @param[in] SourceSize The number of bytes of SourceBuffer to append.\r
a405b86d 2037\r
2038 @retval NULL A memory allocation failed.\r
2039 @retval NULL A parameter was invalid.\r
2040 @return A pointer to (*DestinationBuffer).\r
2041**/\r
2042VOID*\r
2043EFIAPI\r
2044BuffernCatGrow (\r
2045 IN OUT VOID **DestinationBuffer,\r
2046 IN OUT UINTN *DestinationSize,\r
2047 IN VOID *SourceBuffer,\r
2048 IN UINTN SourceSize\r
2049 )\r
2050{\r
2051 UINTN LocalDestinationSize;\r
2052 UINTN LocalDestinationFinalSize;\r
2053\r
2054 ASSERT(DestinationBuffer != NULL);\r
2055\r
2056 if (SourceSize == 0 || SourceBuffer == NULL) {\r
2057 return (*DestinationBuffer);\r
2058 }\r
2059\r
2060 if (DestinationSize == NULL) {\r
2061 LocalDestinationSize = 0;\r
2062 } else {\r
2063 LocalDestinationSize = *DestinationSize;\r
2064 }\r
2065\r
2066 LocalDestinationFinalSize = LocalDestinationSize + SourceSize;\r
2067\r
2068 if (DestinationSize != NULL) {\r
2069 *DestinationSize = LocalDestinationSize;\r
2070 }\r
2071\r
2072 if (LocalDestinationSize == 0) {\r
2073 // allcoate\r
78ed876b 2074 *DestinationBuffer = AllocateZeroPool(LocalDestinationFinalSize);\r
a405b86d 2075 } else {\r
2076 // reallocate\r
2077 *DestinationBuffer = ReallocatePool(LocalDestinationSize, LocalDestinationFinalSize, *DestinationBuffer);\r
2078 }\r
2079\r
2080 ASSERT(*DestinationBuffer != NULL);\r
2081\r
2082 // copy\r
2083 return (CopyMem(((UINT8*)(*DestinationBuffer)) + LocalDestinationSize, SourceBuffer, SourceSize));\r
2084}\r
2085\r
2086/**\r
2087 Gets handles for any child devices produced by the passed in driver.\r
2088\r
2089 @param[in] DriverHandle The handle of the driver.\r
2090 @param[in] MatchingHandleCount Pointer to the number of handles in\r
2091 MatchingHandleBuffer on return.\r
2092 @param[out] MatchingHandleBuffer Buffer containing handles on a successful\r
2093 return.\r
2094 @retval EFI_SUCCESS The operation was sucessful.\r
2095 @sa ParseHandleDatabaseByRelationship\r
2096**/\r
2097EFI_STATUS\r
2098EFIAPI\r
2099ParseHandleDatabaseForChildDevices(\r
2100 IN CONST EFI_HANDLE DriverHandle,\r
2101 IN UINTN *MatchingHandleCount,\r
2102 OUT EFI_HANDLE **MatchingHandleBuffer OPTIONAL\r
2103 )\r
2104{\r
2105 EFI_HANDLE *Buffer;\r
2106 EFI_HANDLE *Buffer2;\r
2107 UINTN Count1;\r
2108 UINTN Count2;\r
2109 UINTN HandleIndex;\r
2110 EFI_STATUS Status;\r
2111 UINTN HandleBufferSize;\r
2112\r
2113 ASSERT(MatchingHandleCount != NULL);\r
2114\r
2115 HandleBufferSize = 0;\r
2116 Buffer = NULL;\r
2117 Buffer2 = NULL;\r
2118 *MatchingHandleCount = 0;\r
2119\r
2120 Status = PARSE_HANDLE_DATABASE_DEVICES (\r
2121 DriverHandle,\r
2122 &Count1,\r
2123 &Buffer\r
2124 );\r
2125 if (!EFI_ERROR (Status)) {\r
2126 for (HandleIndex = 0; HandleIndex < Count1; HandleIndex++) {\r
2127 //\r
2128 // now find the children\r
2129 //\r
2130 Status = PARSE_HANDLE_DATABASE_MANAGED_CHILDREN (\r
2131 DriverHandle,\r
2132 Buffer[HandleIndex],\r
2133 &Count2,\r
2134 &Buffer2\r
2135 );\r
2136 if (EFI_ERROR(Status)) {\r
2137 break;\r
2138 }\r
2139 //\r
2140 // save out required and optional data elements\r
2141 //\r
2142 *MatchingHandleCount += Count2;\r
2143 if (MatchingHandleBuffer != NULL) {\r
2144 *MatchingHandleBuffer = BuffernCatGrow((VOID**)MatchingHandleBuffer, &HandleBufferSize, Buffer2, Count2 * sizeof(Buffer2[0]));\r
2145 }\r
2146\r
2147 //\r
2148 // free the memory\r
2149 //\r
2150 if (Buffer2 != NULL) {\r
2151 FreePool(Buffer2);\r
2152 }\r
2153 }\r
2154 }\r
2155\r
2156 if (Buffer != NULL) {\r
2157 FreePool(Buffer);\r
2158 }\r
2159 return (Status);\r
2160}\r
2161\r
2162/**\r
2163 Function to get all handles that support a given protocol or all handles.\r
2164\r
2165 @param[in] ProtocolGuid The guid of the protocol to get handles for. If NULL\r
2166 then the function will return all handles.\r
2167\r
2168 @retval NULL A memory allocation failed.\r
2169 @return A NULL terminated list of handles.\r
2170**/\r
2171EFI_HANDLE*\r
2172EFIAPI\r
40d7a9cf 2173GetHandleListByProtocol (\r
a405b86d 2174 IN CONST EFI_GUID *ProtocolGuid OPTIONAL\r
2175 )\r
2176{\r
2177 EFI_HANDLE *HandleList;\r
2178 UINTN Size;\r
2179 EFI_STATUS Status;\r
2180\r
2181 Size = 0;\r
2182 HandleList = NULL;\r
2183\r
2184 //\r
2185 // We cannot use LocateHandleBuffer since we need that NULL item on the ends of the list!\r
2186 //\r
2187 if (ProtocolGuid == NULL) {\r
2188 Status = gBS->LocateHandle(AllHandles, NULL, NULL, &Size, HandleList);\r
2189 if (Status == EFI_BUFFER_TOO_SMALL) {\r
78ed876b 2190 HandleList = AllocateZeroPool(Size + sizeof(EFI_HANDLE));\r
40d7a9cf 2191 if (HandleList == NULL) {\r
2192 return (NULL);\r
2193 }\r
a405b86d 2194 Status = gBS->LocateHandle(AllHandles, NULL, NULL, &Size, HandleList);\r
2195 HandleList[Size/sizeof(EFI_HANDLE)] = NULL;\r
2196 }\r
2197 } else {\r
2198 Status = gBS->LocateHandle(ByProtocol, (EFI_GUID*)ProtocolGuid, NULL, &Size, HandleList);\r
2199 if (Status == EFI_BUFFER_TOO_SMALL) {\r
78ed876b 2200 HandleList = AllocateZeroPool(Size + sizeof(EFI_HANDLE));\r
40d7a9cf 2201 if (HandleList == NULL) {\r
2202 return (NULL);\r
2203 }\r
a405b86d 2204 Status = gBS->LocateHandle(ByProtocol, (EFI_GUID*)ProtocolGuid, NULL, &Size, HandleList);\r
2205 HandleList[Size/sizeof(EFI_HANDLE)] = NULL;\r
2206 }\r
2207 }\r
2208 if (EFI_ERROR(Status)) {\r
2209 if (HandleList != NULL) {\r
2210 FreePool(HandleList);\r
2211 }\r
2212 return (NULL);\r
2213 }\r
2214 return (HandleList);\r
2215}\r
2216\r
2217/**\r
2218 Function to get all handles that support some protocols.\r
2219\r
2220 @param[in] ProtocolGuids A NULL terminated list of protocol GUIDs.\r
2221\r
2222 @retval NULL A memory allocation failed.\r
ff51746b 2223 @retval NULL ProtocolGuids was NULL.\r
2224 @return A NULL terminated list of EFI_HANDLEs.\r
a405b86d 2225**/\r
2226EFI_HANDLE*\r
2227EFIAPI\r
40d7a9cf 2228GetHandleListByProtocolList (\r
a405b86d 2229 IN CONST EFI_GUID **ProtocolGuids\r
2230 )\r
2231{\r
2232 EFI_HANDLE *HandleList;\r
2233 UINTN Size;\r
2234 UINTN TotalSize;\r
40d7a9cf 2235 UINTN TempSize;\r
a405b86d 2236 EFI_STATUS Status;\r
2237 CONST EFI_GUID **GuidWalker;\r
2238 EFI_HANDLE *HandleWalker1;\r
2239 EFI_HANDLE *HandleWalker2;\r
2240\r
2241 Size = 0;\r
2242 HandleList = NULL;\r
2243 TotalSize = sizeof(EFI_HANDLE);\r
2244\r
2245 for (GuidWalker = ProtocolGuids ; GuidWalker != NULL && *GuidWalker != NULL ; GuidWalker++,Size = 0){\r
2246 Status = gBS->LocateHandle(ByProtocol, (EFI_GUID*)(*GuidWalker), NULL, &Size, NULL);\r
2247 if (Status == EFI_BUFFER_TOO_SMALL) {\r
2248 TotalSize += Size;\r
2249 }\r
2250 }\r
40d7a9cf 2251\r
2252 //\r
2253 // No handles were found... \r
2254 //\r
2255 if (TotalSize == sizeof(EFI_HANDLE)) {\r
2256 return (NULL);\r
2257 }\r
2258\r
2259 HandleList = AllocateZeroPool(TotalSize);\r
a405b86d 2260 if (HandleList == NULL) {\r
2261 return (NULL);\r
2262 }\r
2263\r
2264 Size = 0;\r
2265 for (GuidWalker = ProtocolGuids ; GuidWalker != NULL && *GuidWalker != NULL ; GuidWalker++){\r
40d7a9cf 2266 TempSize = TotalSize - Size;\r
ff51746b 2267 Status = gBS->LocateHandle(ByProtocol, (EFI_GUID*)(*GuidWalker), NULL, &TempSize, HandleList+(Size/sizeof(EFI_HANDLE)));\r
40d7a9cf 2268\r
2269 //\r
2270 // Allow for missing protocols... Only update the 'used' size upon success.\r
2271 //\r
2272 if (!EFI_ERROR(Status)) {\r
ff51746b 2273 Size += TempSize;\r
40d7a9cf 2274 }\r
a405b86d 2275 }\r
ff51746b 2276 ASSERT(HandleList[(TotalSize/sizeof(EFI_HANDLE))-1] == NULL);\r
a405b86d 2277\r
2278 for (HandleWalker1 = HandleList ; HandleWalker1 != NULL && *HandleWalker1 != NULL ; HandleWalker1++) {\r
2279 for (HandleWalker2 = HandleWalker1 + 1; HandleWalker2 != NULL && *HandleWalker2 != NULL ; HandleWalker2++) {\r
2280 if (*HandleWalker1 == *HandleWalker2) {\r
2281 //\r
2282 // copy memory back 1 handle width.\r
2283 //\r
2284 CopyMem(HandleWalker2, HandleWalker2 + 1, TotalSize - ((HandleWalker2-HandleList+1)*sizeof(EFI_HANDLE)));\r
2285 }\r
2286 }\r
2287 }\r
2288\r
2289 return (HandleList);\r
2290}\r
2291\r
2292\r
2293\r
2294\r
2295\r
2296\r
2297\r
2298\r
2299\r
2300\r