MdePkg/UefiScsiLib: Wrong function parameter comments in UefiScsiLib. It should be...
[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
28cdb62b 4 Copyright (c) 2013 Hewlett-Packard Development Company, L.P.\r
efb76d1a 5 Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>\r
a405b86d 6 This program and the accompanying materials\r
7 are licensed and made available under the terms and conditions of the BSD License\r
8 which accompanies this distribution. The full text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.php\r
10\r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#include "UefiHandleParsingLib.h"\r
f4f3c6bf 17#include "IndustryStandard/Acpi10.h"\r
a405b86d 18\r
a405b86d 19EFI_HANDLE mHandleParsingHiiHandle;\r
20HANDLE_INDEX_LIST mHandleList = {{{NULL,NULL},0,0},0};\r
21\r
efb76d1a
JC
22/**\r
23 Function to translate the EFI_MEMORY_TYPE into a string.\r
24\r
25 @param[in] Memory The memory type.\r
26\r
27 @retval A string representation of the type allocated from BS Pool.\r
28**/\r
29CHAR16*\r
30EFIAPI\r
31ConvertMemoryType (\r
32 IN CONST EFI_MEMORY_TYPE Memory\r
33 )\r
34{\r
35 CHAR16 *RetVal;\r
36 RetVal = NULL;\r
37\r
38 switch (Memory) {\r
39 case EfiReservedMemoryType: StrnCatGrow(&RetVal, NULL, L"EfiReservedMemoryType", 0); break;\r
40 case EfiLoaderCode: StrnCatGrow(&RetVal, NULL, L"EfiLoaderCode", 0); break;\r
41 case EfiLoaderData: StrnCatGrow(&RetVal, NULL, L"EfiLoaderData", 0); break;\r
42 case EfiBootServicesCode: StrnCatGrow(&RetVal, NULL, L"EfiBootServicesCode", 0); break;\r
43 case EfiBootServicesData: StrnCatGrow(&RetVal, NULL, L"EfiBootServicesData", 0); break;\r
44 case EfiRuntimeServicesCode: StrnCatGrow(&RetVal, NULL, L"EfiRuntimeServicesCode", 0); break;\r
45 case EfiRuntimeServicesData: StrnCatGrow(&RetVal, NULL, L"EfiRuntimeServicesData", 0); break;\r
46 case EfiConventionalMemory: StrnCatGrow(&RetVal, NULL, L"EfiConventionalMemory", 0); break;\r
47 case EfiUnusableMemory: StrnCatGrow(&RetVal, NULL, L"EfiUnusableMemory", 0); break;\r
48 case EfiACPIReclaimMemory: StrnCatGrow(&RetVal, NULL, L"EfiACPIReclaimMemory", 0); break;\r
49 case EfiACPIMemoryNVS: StrnCatGrow(&RetVal, NULL, L"EfiACPIMemoryNVS", 0); break;\r
50 case EfiMemoryMappedIO: StrnCatGrow(&RetVal, NULL, L"EfiMemoryMappedIO", 0); break;\r
51 case EfiMemoryMappedIOPortSpace: StrnCatGrow(&RetVal, NULL, L"EfiMemoryMappedIOPortSpace", 0); break;\r
52 case EfiPalCode: StrnCatGrow(&RetVal, NULL, L"EfiPalCode", 0); break;\r
53 case EfiMaxMemoryType: StrnCatGrow(&RetVal, NULL, L"EfiMaxMemoryType", 0); break;\r
54 default: ASSERT(FALSE);\r
55 }\r
56 return (RetVal);\r
57}\r
58\r
a405b86d 59/**\r
60 Constructor for the library.\r
61\r
62 @param[in] ImageHandle Ignored.\r
63 @param[in] SystemTable Ignored.\r
64\r
65 @retval EFI_SUCCESS The operation was successful.\r
66**/\r
67EFI_STATUS\r
68EFIAPI\r
69HandleParsingLibConstructor (\r
70 IN EFI_HANDLE ImageHandle,\r
71 IN EFI_SYSTEM_TABLE *SystemTable\r
72 )\r
73{\r
bca163ff 74 mHandleParsingHiiHandle = HiiAddPackages (&gHandleParsingHiiGuid, gImageHandle, UefiHandleParsingLibStrings, NULL);\r
a405b86d 75 if (mHandleParsingHiiHandle == NULL) {\r
76 return (EFI_DEVICE_ERROR);\r
77 }\r
78\r
79 return (EFI_SUCCESS);\r
80}\r
81\r
82/**\r
83 Destructor for the library. free any resources.\r
84\r
85 @param[in] ImageHandle Ignored.\r
86 @param[in] SystemTable Ignored.\r
87\r
88 @retval EFI_SUCCESS The operation was successful.\r
89**/\r
90EFI_STATUS\r
91EFIAPI\r
92HandleParsingLibDestructor (\r
93 IN EFI_HANDLE ImageHandle,\r
94 IN EFI_SYSTEM_TABLE *SystemTable\r
95 )\r
96{\r
97 if (mHandleParsingHiiHandle != NULL) {\r
98 HiiRemovePackages(mHandleParsingHiiHandle);\r
99 }\r
100 return (EFI_SUCCESS);\r
101}\r
102\r
efb76d1a
JC
103/**\r
104 Function to dump information about LoadedImage.\r
105\r
106 This will allocate the return buffer from boot services pool.\r
107\r
108 @param[in] TheHandle The handle that has LoadedImage installed.\r
109 @param[in] Verbose TRUE for additional information, FALSE otherwise.\r
110\r
111 @retval A poitner to a string containing the information.\r
112**/\r
a405b86d 113CHAR16*\r
114EFIAPI\r
115LoadedImageProtocolDumpInformation(\r
116 IN CONST EFI_HANDLE TheHandle,\r
117 IN CONST BOOLEAN Verbose\r
118 )\r
119{\r
efb76d1a 120 EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;\r
a405b86d 121 EFI_STATUS Status;\r
efb76d1a
JC
122 CHAR16 *RetVal;\r
123 CHAR16 *Temp;\r
124 CHAR16 *CodeType;\r
125 CHAR16 *DataType;\r
a405b86d 126\r
efb76d1a
JC
127 if (!Verbose) {\r
128 return (CatSPrint(NULL, L"LoadedImage"));\r
a405b86d 129 }\r
130\r
efb76d1a
JC
131 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_LI_DUMP_MAIN), NULL);\r
132 RetVal = AllocateZeroPool (PcdGet16 (PcdShellPrintBufferSize));\r
133 if (Temp == NULL || RetVal == NULL) {\r
134 SHELL_FREE_NON_NULL(Temp);\r
135 SHELL_FREE_NON_NULL(RetVal);\r
136 return NULL;\r
a405b86d 137 }\r
138\r
efb76d1a
JC
139 Status = gBS->OpenProtocol (\r
140 TheHandle,\r
141 &gEfiLoadedImageProtocolGuid,\r
142 (VOID**)&LoadedImage,\r
143 gImageHandle,\r
144 NULL,\r
145 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
146 );\r
147\r
5f119dfc
HL
148 if (EFI_ERROR (Status)) {\r
149 SHELL_FREE_NON_NULL (Temp);\r
150 SHELL_FREE_NON_NULL (RetVal);\r
151 return NULL;\r
152 }\r
153\r
efb76d1a
JC
154 DataType = ConvertMemoryType(LoadedImage->ImageDataType);\r
155 CodeType = ConvertMemoryType(LoadedImage->ImageCodeType);\r
156\r
157 RetVal = CatSPrint(RetVal,\r
158 Temp,\r
159 LoadedImage->Revision,\r
160 LoadedImage->ParentHandle,\r
161 LoadedImage->SystemTable,\r
162 LoadedImage->DeviceHandle,\r
163 LoadedImage->FilePath,\r
164 LoadedImage->LoadOptionsSize,\r
165 LoadedImage->LoadOptions,\r
166 LoadedImage->ImageBase,\r
167 LoadedImage->ImageSize,\r
168 CodeType,\r
169 DataType,\r
170 LoadedImage->Unload);\r
171\r
172 \r
173 SHELL_FREE_NON_NULL(Temp);\r
174 SHELL_FREE_NON_NULL(CodeType);\r
175 SHELL_FREE_NON_NULL(DataType);\r
176\r
177 return RetVal;\r
a405b86d 178}\r
a405b86d 179\r
f4f3c6bf 180/**\r
181 Function to dump information about PciRootBridgeIo.\r
182\r
183 This will allocate the return buffer from boot services pool.\r
184\r
185 @param[in] TheHandle The handle that has PciRootBridgeIo installed.\r
186 @param[in] Verbose TRUE for additional information, FALSE otherwise.\r
187\r
188 @retval A poitner to a string containing the information.\r
189**/\r
190CHAR16*\r
191EFIAPI\r
192PciRootBridgeIoDumpInformation(\r
193 IN CONST EFI_HANDLE TheHandle,\r
194 IN CONST BOOLEAN Verbose\r
195 )\r
196{\r
197 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo;\r
198 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Configuration;\r
199 UINT64 Supports;\r
200 UINT64 Attributes;\r
201 CHAR16 *Temp;\r
202 CHAR16 *Temp2;\r
203 CHAR16 *RetVal;\r
204 EFI_STATUS Status;\r
205\r
206 RetVal = NULL;\r
207\r
208 if (!Verbose) {\r
209 return (CatSPrint(NULL, L"PciRootBridgeIo"));\r
210 }\r
211\r
212 Status = gBS->HandleProtocol(\r
213 TheHandle,\r
214 &gEfiPciRootBridgeIoProtocolGuid,\r
215 (VOID**)&PciRootBridgeIo);\r
216\r
217 if (EFI_ERROR(Status)) {\r
218 return NULL;\r
219 }\r
220\r
221 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIRB_DUMP_PH), NULL);\r
8d300003 222 ASSERT (Temp != NULL);\r
f4f3c6bf 223 Temp2 = CatSPrint(L"\r\n", Temp, PciRootBridgeIo->ParentHandle);\r
224 FreePool(Temp);\r
225 RetVal = Temp2;\r
226 Temp2 = NULL;\r
227 \r
228 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIRB_DUMP_SEG), NULL);\r
8d300003 229 ASSERT (Temp != NULL);\r
f4f3c6bf 230 Temp2 = CatSPrint(RetVal, Temp, PciRootBridgeIo->SegmentNumber);\r
231 FreePool(Temp);\r
232 FreePool(RetVal);\r
233 RetVal = Temp2;\r
234 Temp2 = NULL;\r
235\r
236 Supports = 0;\r
237 Attributes = 0;\r
238 Status = PciRootBridgeIo->GetAttributes (PciRootBridgeIo, &Supports, &Attributes);\r
239 if (!EFI_ERROR(Status)) {\r
240 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIRB_DUMP_ATT), NULL);\r
8d300003 241 ASSERT (Temp != NULL); \r
f4f3c6bf 242 Temp2 = CatSPrint(RetVal, Temp, Attributes);\r
243 FreePool(Temp);\r
244 FreePool(RetVal);\r
245 RetVal = Temp2;\r
246 Temp2 = NULL;\r
247 \r
248 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIRB_DUMP_SUPPORTS), NULL);\r
8d300003 249 ASSERT (Temp != NULL);\r
f4f3c6bf 250 Temp2 = CatSPrint(RetVal, Temp, Supports);\r
251 FreePool(Temp);\r
252 FreePool(RetVal);\r
253 RetVal = Temp2;\r
254 Temp2 = NULL;\r
255 }\r
256\r
257 Configuration = NULL;\r
258 Status = PciRootBridgeIo->Configuration (PciRootBridgeIo, (VOID **) &Configuration);\r
259 if (!EFI_ERROR(Status) && Configuration != NULL) {\r
260 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIRB_DUMP_TITLE), NULL);\r
8d300003 261 ASSERT (Temp != NULL);\r
f4f3c6bf 262 Temp2 = CatSPrint(RetVal, Temp, Supports);\r
263 FreePool(Temp);\r
264 FreePool(RetVal);\r
265 RetVal = Temp2;\r
266 Temp2 = NULL;\r
267 while (Configuration->Desc == ACPI_ADDRESS_SPACE_DESCRIPTOR) {\r
268 Temp = NULL;\r
269 switch (Configuration->ResType) {\r
270 case ACPI_ADDRESS_SPACE_TYPE_MEM:\r
271 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIRB_DUMP_MEM), NULL);\r
272 break;\r
273 case ACPI_ADDRESS_SPACE_TYPE_IO:\r
274 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIRB_DUMP_IO), NULL);\r
275 break;\r
276 case ACPI_ADDRESS_SPACE_TYPE_BUS:\r
277 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIRB_DUMP_BUS), NULL);\r
278 break;\r
279 }\r
280 if (Temp != NULL) {\r
281 Temp2 = CatSPrint(RetVal, L"%s", Temp);\r
282 FreePool(Temp);\r
283 FreePool(RetVal);\r
284 RetVal = Temp2;\r
285 Temp2 = NULL;\r
286 }\r
287\r
288 Temp2 = CatSPrint(RetVal, \r
289 L"%H%02x %016lx %016lx %02x%N\r\n",\r
290 Configuration->SpecificFlag,\r
291 Configuration->AddrRangeMin,\r
292 Configuration->AddrRangeMax,\r
293 Configuration->AddrSpaceGranularity\r
294 );\r
295 FreePool(RetVal);\r
296 RetVal = Temp2;\r
297 Temp2 = NULL;\r
298 Configuration++;\r
299 }\r
300 }\r
301 return (RetVal);\r
302}\r
303\r
a405b86d 304/**\r
305 Function to dump information about SimpleTextOut.\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 SimpleTextOut 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
316TxtOutProtocolDumpInformation(\r
317 IN CONST EFI_HANDLE TheHandle,\r
318 IN CONST BOOLEAN Verbose\r
319 )\r
320{\r
321 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Dev;\r
322 INTN Index;\r
323 UINTN Col;\r
324 UINTN Row;\r
325 EFI_STATUS Status;\r
326 CHAR16 *RetVal;\r
327 UINTN Size;\r
328 CHAR16 *Temp;\r
329 UINTN NewSize;\r
330\r
331 if (!Verbose) {\r
332 return (NULL);\r
333 }\r
334\r
335 RetVal = NULL;\r
336 Size = 0;\r
337\r
338 Status = gBS->HandleProtocol(\r
339 TheHandle,\r
340 &gEfiSimpleTextOutProtocolGuid,\r
341 (VOID**)&Dev);\r
342\r
343 ASSERT_EFI_ERROR(Status);\r
344 ASSERT (Dev != NULL && Dev->Mode != NULL);\r
345\r
346 Size = (Dev->Mode->MaxMode + 1) * 80;\r
347 RetVal = AllocateZeroPool(Size);\r
348\r
349 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_TXT_OUT_DUMP_HEADER), NULL);\r
ecae5117 350 if (Temp != NULL) {\r
351 UnicodeSPrint(RetVal, Size, Temp, Dev, Dev->Mode->Attribute);\r
352 FreePool(Temp);\r
353 }\r
a405b86d 354\r
355 //\r
356 // Dump TextOut Info\r
357 //\r
358 Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_TXT_OUT_DUMP_LINE), NULL);\r
359 for (Index = 0; Index < Dev->Mode->MaxMode; Index++) {\r
360 Status = Dev->QueryMode (Dev, Index, &Col, &Row);\r
361 NewSize = Size - StrSize(RetVal);\r
362 UnicodeSPrint(\r
363 RetVal + StrLen(RetVal),\r
364 NewSize,\r
ecae5117 365 Temp == NULL?L"":Temp,\r
a405b86d 366 Index == Dev->Mode->Mode ? L'*' : L' ',\r
367 Index,\r
28981267 368 !EFI_ERROR(Status)?(INTN)Col:-1,\r
369 !EFI_ERROR(Status)?(INTN)Row:-1\r
a405b86d 370 );\r
371 }\r
372 FreePool(Temp);\r
373 return (RetVal);\r
374}\r
375\r
376STATIC CONST UINTN VersionStringSize = 60;\r
377\r
378/**\r
379 Function to dump information about EfiDriverSupportedEfiVersion protocol.\r
380\r
381 This will allocate the return buffer from boot services pool.\r
382\r
383 @param[in] TheHandle The handle that has the protocol installed.\r
384 @param[in] Verbose TRUE for additional information, FALSE otherwise.\r
385\r
386 @retval A poitner to a string containing the information.\r
387**/\r
388CHAR16*\r
389EFIAPI\r
390DriverEfiVersionProtocolDumpInformation(\r
391 IN CONST EFI_HANDLE TheHandle,\r
392 IN CONST BOOLEAN Verbose\r
393 )\r
394{\r
395 EFI_DRIVER_SUPPORTED_EFI_VERSION_PROTOCOL *DriverEfiVersion;\r
396 EFI_STATUS Status;\r
397 CHAR16 *RetVal;\r
398\r
399 Status = gBS->HandleProtocol(\r
400 TheHandle,\r
401 &gEfiDriverSupportedEfiVersionProtocolGuid,\r
402 (VOID**)&DriverEfiVersion);\r
403\r
404 ASSERT_EFI_ERROR(Status);\r
405\r
78ed876b 406 RetVal = AllocateZeroPool(VersionStringSize);\r
a405b86d 407 ASSERT(RetVal != NULL);\r
408 UnicodeSPrint(RetVal, VersionStringSize, L"0x%08x", DriverEfiVersion->FirmwareVersion);\r
409 return (RetVal);\r
410}\r
411\r
412/**\r
413 Function to dump information about DevicePath protocol.\r
414\r
415 This will allocate the return buffer from boot services pool.\r
416\r
417 @param[in] TheHandle The handle that has the protocol installed.\r
418 @param[in] Verbose TRUE for additional information, FALSE otherwise.\r
419\r
420 @retval A poitner to a string containing the information.\r
421**/\r
422CHAR16*\r
423EFIAPI\r
424DevicePathProtocolDumpInformation(\r
425 IN CONST EFI_HANDLE TheHandle,\r
426 IN CONST BOOLEAN Verbose\r
427 )\r
428{\r
429 EFI_DEVICE_PATH_PROTOCOL *DevPath;\r
430 CHAR16 *Temp;\r
431 CHAR16 *Temp2;\r
432 EFI_STATUS Status;\r
a405b86d 433 Temp = NULL;\r
434\r
863986b3 435 Status = gBS->OpenProtocol(TheHandle, &gEfiDevicePathProtocolGuid, (VOID**)&DevPath, gImageHandle, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);\r
a405b86d 436 if (!EFI_ERROR(Status)) {\r
863986b3
RN
437 //\r
438 // I cannot decide whether to allow shortcuts here (the second BOOLEAN on the next line)\r
439 //\r
440 Temp = ConvertDevicePathToText(DevPath, TRUE, TRUE);\r
441 gBS->CloseProtocol(TheHandle, &gEfiDevicePathProtocolGuid, gImageHandle, NULL);\r
a405b86d 442 }\r
78ed876b 443 if (!Verbose && Temp != NULL && StrLen(Temp) > 30) {\r
a405b86d 444 Temp2 = NULL;\r
445 Temp2 = StrnCatGrow(&Temp2, NULL, Temp+(StrLen(Temp) - 30), 30);\r
446 FreePool(Temp);\r
447 Temp = Temp2;\r
448 }\r
449 return (Temp);\r
450}\r
451\r
452//\r
453// Put the information on the NT32 protocol GUIDs here so we are not dependant on the Nt32Pkg\r
454//\r
455#define LOCAL_EFI_WIN_NT_THUNK_PROTOCOL_GUID \\r
456 { \\r
ce68d3bc 457 0x58c518b1, 0x76f3, 0x11d4, { 0xbc, 0xea, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 } \\r
a405b86d 458 }\r
459\r
460#define LOCAL_EFI_WIN_NT_BUS_DRIVER_IO_PROTOCOL_GUID \\r
461 { \\r
ce68d3bc 462 0x96eb4ad6, 0xa32a, 0x11d4, { 0xbc, 0xfd, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 } \\r
a405b86d 463 }\r
464\r
465#define LOCAL_EFI_WIN_NT_SERIAL_PORT_GUID \\r
466 { \\r
ce68d3bc 467 0xc95a93d, 0xa006, 0x11d4, { 0xbc, 0xfa, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 } \\r
a405b86d 468 }\r
469STATIC CONST EFI_GUID WinNtThunkProtocolGuid = LOCAL_EFI_WIN_NT_THUNK_PROTOCOL_GUID;\r
470STATIC CONST EFI_GUID WinNtIoProtocolGuid = LOCAL_EFI_WIN_NT_BUS_DRIVER_IO_PROTOCOL_GUID;\r
471STATIC CONST EFI_GUID WinNtSerialPortGuid = LOCAL_EFI_WIN_NT_SERIAL_PORT_GUID;\r
472\r
dee34318 473STATIC CONST GUID_INFO_BLOCK mGuidStringListNT[] = {\r
a405b86d 474 {STRING_TOKEN(STR_WINNT_THUNK), (EFI_GUID*)&WinNtThunkProtocolGuid, NULL},\r
475 {STRING_TOKEN(STR_WINNT_DRIVER_IO), (EFI_GUID*)&WinNtIoProtocolGuid, NULL},\r
476 {STRING_TOKEN(STR_WINNT_SERIAL_PORT), (EFI_GUID*)&WinNtSerialPortGuid, NULL},\r
477 {STRING_TOKEN(STR_UNKNOWN_DEVICE), NULL, NULL},\r
478};\r
479\r
dee34318 480STATIC CONST GUID_INFO_BLOCK mGuidStringList[] = {\r
efb76d1a 481 {STRING_TOKEN(STR_LOADED_IMAGE), &gEfiLoadedImageProtocolGuid, LoadedImageProtocolDumpInformation},\r
a405b86d 482 {STRING_TOKEN(STR_DEVICE_PATH), &gEfiDevicePathProtocolGuid, DevicePathProtocolDumpInformation},\r
483 {STRING_TOKEN(STR_IMAGE_PATH), &gEfiLoadedImageDevicePathProtocolGuid, DevicePathProtocolDumpInformation},\r
484 {STRING_TOKEN(STR_DEVICE_PATH_UTIL), &gEfiDevicePathUtilitiesProtocolGuid, NULL},\r
485 {STRING_TOKEN(STR_DEVICE_PATH_TXT), &gEfiDevicePathToTextProtocolGuid, NULL},\r
486 {STRING_TOKEN(STR_DEVICE_PATH_FTXT), &gEfiDevicePathFromTextProtocolGuid, NULL},\r
487 {STRING_TOKEN(STR_DEVICE_PATH_PC), &gEfiPcAnsiGuid, NULL},\r
488 {STRING_TOKEN(STR_DEVICE_PATH_VT100), &gEfiVT100Guid, NULL},\r
489 {STRING_TOKEN(STR_DEVICE_PATH_VT100P), &gEfiVT100PlusGuid, NULL},\r
490 {STRING_TOKEN(STR_DEVICE_PATH_VTUTF8), &gEfiVTUTF8Guid, NULL},\r
491 {STRING_TOKEN(STR_DRIVER_BINDING), &gEfiDriverBindingProtocolGuid, NULL},\r
492 {STRING_TOKEN(STR_PLATFORM_OVERRIDE), &gEfiPlatformDriverOverrideProtocolGuid, NULL},\r
493 {STRING_TOKEN(STR_BUS_OVERRIDE), &gEfiBusSpecificDriverOverrideProtocolGuid, NULL},\r
494 {STRING_TOKEN(STR_DRIVER_DIAG), &gEfiDriverDiagnosticsProtocolGuid, NULL},\r
495 {STRING_TOKEN(STR_DRIVER_DIAG2), &gEfiDriverDiagnostics2ProtocolGuid, NULL},\r
496 {STRING_TOKEN(STR_DRIVER_CN), &gEfiComponentNameProtocolGuid, NULL},\r
497 {STRING_TOKEN(STR_DRIVER_CN2), &gEfiComponentName2ProtocolGuid, NULL},\r
498 {STRING_TOKEN(STR_PLAT_DRV_CFG), &gEfiPlatformToDriverConfigurationProtocolGuid, NULL},\r
499 {STRING_TOKEN(STR_DRIVER_VERSION), &gEfiDriverSupportedEfiVersionProtocolGuid, DriverEfiVersionProtocolDumpInformation},\r
500 {STRING_TOKEN(STR_TXT_IN), &gEfiSimpleTextInProtocolGuid, NULL},\r
501 {STRING_TOKEN(STR_TXT_IN_EX), &gEfiSimpleTextInputExProtocolGuid, NULL},\r
502 {STRING_TOKEN(STR_TXT_OUT), &gEfiSimpleTextOutProtocolGuid, TxtOutProtocolDumpInformation},\r
503 {STRING_TOKEN(STR_SIM_POINTER), &gEfiSimplePointerProtocolGuid, NULL},\r
504 {STRING_TOKEN(STR_ABS_POINTER), &gEfiAbsolutePointerProtocolGuid, NULL},\r
505 {STRING_TOKEN(STR_SERIAL_IO), &gEfiSerialIoProtocolGuid, NULL},\r
506 {STRING_TOKEN(STR_GRAPHICS_OUTPUT), &gEfiGraphicsOutputProtocolGuid, NULL},\r
507 {STRING_TOKEN(STR_EDID_DISCOVERED), &gEfiEdidDiscoveredProtocolGuid, NULL},\r
508 {STRING_TOKEN(STR_EDID_ACTIVE), &gEfiEdidActiveProtocolGuid, NULL},\r
509 {STRING_TOKEN(STR_EDID_OVERRIDE), &gEfiEdidOverrideProtocolGuid, NULL},\r
510 {STRING_TOKEN(STR_CON_IN), &gEfiConsoleInDeviceGuid, NULL},\r
511 {STRING_TOKEN(STR_CON_OUT), &gEfiConsoleOutDeviceGuid, NULL},\r
512 {STRING_TOKEN(STR_STD_ERR), &gEfiStandardErrorDeviceGuid, NULL},\r
513 {STRING_TOKEN(STR_LOAD_FILE), &gEfiLoadFileProtocolGuid, NULL},\r
514 {STRING_TOKEN(STR_LOAD_FILE2), &gEfiLoadFile2ProtocolGuid, NULL},\r
515 {STRING_TOKEN(STR_SIMPLE_FILE_SYS), &gEfiSimpleFileSystemProtocolGuid, NULL},\r
a405b86d 516 {STRING_TOKEN(STR_TAPE_IO), &gEfiTapeIoProtocolGuid, NULL},\r
517 {STRING_TOKEN(STR_DISK_IO), &gEfiDiskIoProtocolGuid, NULL},\r
518 {STRING_TOKEN(STR_BLK_IO), &gEfiBlockIoProtocolGuid, NULL},\r
519 {STRING_TOKEN(STR_UC), &gEfiUnicodeCollationProtocolGuid, NULL},\r
520 {STRING_TOKEN(STR_UC2), &gEfiUnicodeCollation2ProtocolGuid, NULL},\r
f4f3c6bf 521 {STRING_TOKEN(STR_PCIRB_IO), &gEfiPciRootBridgeIoProtocolGuid, PciRootBridgeIoDumpInformation},\r
a405b86d 522 {STRING_TOKEN(STR_PCI_IO), &gEfiPciIoProtocolGuid, NULL},\r
523 {STRING_TOKEN(STR_SCSI_PT), &gEfiScsiPassThruProtocolGuid, NULL},\r
524 {STRING_TOKEN(STR_SCSI_IO), &gEfiScsiIoProtocolGuid, NULL},\r
525 {STRING_TOKEN(STR_SCSI_PT_EXT), &gEfiExtScsiPassThruProtocolGuid, NULL},\r
526 {STRING_TOKEN(STR_ISCSI), &gEfiIScsiInitiatorNameProtocolGuid, NULL},\r
527 {STRING_TOKEN(STR_USB_IO), &gEfiUsbIoProtocolGuid, NULL},\r
528 {STRING_TOKEN(STR_USB_HC), &gEfiUsbHcProtocolGuid, NULL},\r
529 {STRING_TOKEN(STR_USB_HC2), &gEfiUsb2HcProtocolGuid, NULL},\r
530 {STRING_TOKEN(STR_DEBUG_SUPPORT), &gEfiDebugSupportProtocolGuid, NULL},\r
531 {STRING_TOKEN(STR_DEBUG_PORT), &gEfiDebugPortProtocolGuid, NULL},\r
532 {STRING_TOKEN(STR_DECOMPRESS), &gEfiDecompressProtocolGuid, NULL},\r
533 {STRING_TOKEN(STR_ACPI_TABLE), &gEfiAcpiTableProtocolGuid, NULL},\r
534 {STRING_TOKEN(STR_EBC_INTERPRETER), &gEfiEbcProtocolGuid, NULL},\r
535 {STRING_TOKEN(STR_SNP), &gEfiSimpleNetworkProtocolGuid, NULL},\r
536 {STRING_TOKEN(STR_NII), &gEfiNetworkInterfaceIdentifierProtocolGuid, NULL},\r
537 {STRING_TOKEN(STR_NII_31), &gEfiNetworkInterfaceIdentifierProtocolGuid_31, NULL},\r
538 {STRING_TOKEN(STR_PXE_BC), &gEfiPxeBaseCodeProtocolGuid, NULL},\r
539 {STRING_TOKEN(STR_PXE_CB), &gEfiPxeBaseCodeCallbackProtocolGuid, NULL},\r
540 {STRING_TOKEN(STR_BIS), &gEfiBisProtocolGuid, NULL},\r
541 {STRING_TOKEN(STR_MNP_SB), &gEfiManagedNetworkServiceBindingProtocolGuid, NULL},\r
542 {STRING_TOKEN(STR_MNP), &gEfiManagedNetworkProtocolGuid, NULL},\r
543 {STRING_TOKEN(STR_ARP_SB), &gEfiArpServiceBindingProtocolGuid, NULL},\r
544 {STRING_TOKEN(STR_ARP), &gEfiArpProtocolGuid, NULL},\r
545 {STRING_TOKEN(STR_DHCPV4_SB), &gEfiDhcp4ServiceBindingProtocolGuid, NULL},\r
546 {STRING_TOKEN(STR_DHCPV4), &gEfiDhcp4ProtocolGuid, NULL},\r
547 {STRING_TOKEN(STR_TCPV4_SB), &gEfiTcp4ServiceBindingProtocolGuid, NULL},\r
548 {STRING_TOKEN(STR_TCPV4), &gEfiTcp4ProtocolGuid, NULL},\r
549 {STRING_TOKEN(STR_IPV4_SB), &gEfiIp4ServiceBindingProtocolGuid, NULL},\r
550 {STRING_TOKEN(STR_IPV4), &gEfiIp4ProtocolGuid, NULL},\r
551 {STRING_TOKEN(STR_IPV4_CFG), &gEfiIp4ConfigProtocolGuid, NULL},\r
552 {STRING_TOKEN(STR_SHELL_PARAMETERS), &gEfiShellParametersProtocolGuid, NULL},\r
553 {STRING_TOKEN(STR_SHELL), &gEfiShellProtocolGuid, NULL},\r
a405b86d 554 {STRING_TOKEN(STR_UDPV4_SB), &gEfiUdp4ServiceBindingProtocolGuid, NULL},\r
555 {STRING_TOKEN(STR_UDPV4), &gEfiUdp4ProtocolGuid, NULL},\r
556 {STRING_TOKEN(STR_MTFTPV4_SB), &gEfiMtftp4ServiceBindingProtocolGuid, NULL},\r
557 {STRING_TOKEN(STR_MTFTPV4), &gEfiMtftp4ProtocolGuid, NULL},\r
558 {STRING_TOKEN(STR_AUTH_INFO), &gEfiAuthenticationInfoProtocolGuid, NULL},\r
559 {STRING_TOKEN(STR_HASH_SB), &gEfiHashServiceBindingProtocolGuid, NULL},\r
560 {STRING_TOKEN(STR_HASH), &gEfiHashProtocolGuid, NULL},\r
561 {STRING_TOKEN(STR_HII_FONT), &gEfiHiiFontProtocolGuid, NULL},\r
562 {STRING_TOKEN(STR_HII_STRING), &gEfiHiiStringProtocolGuid, NULL},\r
563 {STRING_TOKEN(STR_HII_IMAGE), &gEfiHiiImageProtocolGuid, NULL},\r
564 {STRING_TOKEN(STR_HII_DATABASE), &gEfiHiiDatabaseProtocolGuid, NULL},\r
565 {STRING_TOKEN(STR_HII_CONFIG_ROUT), &gEfiHiiConfigRoutingProtocolGuid, NULL},\r
566 {STRING_TOKEN(STR_HII_CONFIG_ACC), &gEfiHiiConfigAccessProtocolGuid, NULL},\r
567 {STRING_TOKEN(STR_HII_FORM_BROWSER2), &gEfiFormBrowser2ProtocolGuid, NULL},\r
dee34318 568 {STRING_TOKEN(STR_DRIVER_FAM_OVERRIDE), &gEfiDriverFamilyOverrideProtocolGuid, NULL},\r
569 {STRING_TOKEN(STR_PCD), &gPcdProtocolGuid, NULL},\r
570 {STRING_TOKEN(STR_TCG), &gEfiTcgProtocolGuid, NULL},\r
571 {STRING_TOKEN(STR_HII_PACKAGE_LIST), &gEfiHiiPackageListProtocolGuid, NULL},\r
572\r
573//\r
574// the ones under this are deprecated by the current UEFI Spec, but may be found anyways...\r
575//\r
a405b86d 576 {STRING_TOKEN(STR_SHELL_INTERFACE), &gEfiShellInterfaceGuid, NULL},\r
577 {STRING_TOKEN(STR_SHELL_ENV2), &gEfiShellEnvironment2Guid, NULL},\r
578 {STRING_TOKEN(STR_SHELL_ENV), &gEfiShellEnvironment2Guid, NULL},\r
579 {STRING_TOKEN(STR_DEVICE_IO), &gEfiDeviceIoProtocolGuid, NULL},\r
580 {STRING_TOKEN(STR_UGA_DRAW), &gEfiUgaDrawProtocolGuid, NULL},\r
581 {STRING_TOKEN(STR_UGA_IO), &gEfiUgaIoProtocolGuid, NULL},\r
582 {STRING_TOKEN(STR_ESP), &gEfiPartTypeSystemPartGuid, NULL},\r
583 {STRING_TOKEN(STR_GPT_NBR), &gEfiPartTypeLegacyMbrGuid, NULL},\r
584 {STRING_TOKEN(STR_DRIVER_CONFIG), &gEfiDriverConfigurationProtocolGuid, NULL},\r
585 {STRING_TOKEN(STR_DRIVER_CONFIG2), &gEfiDriverConfiguration2ProtocolGuid, NULL},\r
dee34318 586\r
587//\r
588// the ones under this are GUID identified structs, not protocols\r
589//\r
590 {STRING_TOKEN(STR_FILE_INFO), &gEfiFileInfoGuid, NULL},\r
591 {STRING_TOKEN(STR_FILE_SYS_INFO), &gEfiFileSystemInfoGuid, NULL},\r
592\r
593//\r
594// the ones under this are misc GUIDS.\r
595//\r
596 {STRING_TOKEN(STR_EFI_GLOBAL_VARIABLE), &gEfiGlobalVariableGuid, NULL},\r
597\r
598//\r
599// UEFI 2.2\r
600//\r
601 {STRING_TOKEN(STR_IP6_SB), &gEfiIp6ServiceBindingProtocolGuid, NULL},\r
602 {STRING_TOKEN(STR_IP6), &gEfiIp6ProtocolGuid, NULL},\r
603 {STRING_TOKEN(STR_IP6_CONFIG), &gEfiIp6ConfigProtocolGuid, NULL},\r
604 {STRING_TOKEN(STR_MTFTP6_SB), &gEfiMtftp6ServiceBindingProtocolGuid, NULL},\r
605 {STRING_TOKEN(STR_MTFTP6), &gEfiMtftp6ProtocolGuid, NULL},\r
606 {STRING_TOKEN(STR_DHCP6_SB), &gEfiDhcp6ServiceBindingProtocolGuid, NULL},\r
607 {STRING_TOKEN(STR_DHCP6), &gEfiDhcp6ProtocolGuid, NULL},\r
608 {STRING_TOKEN(STR_UDP6_SB), &gEfiUdp6ServiceBindingProtocolGuid, NULL},\r
609 {STRING_TOKEN(STR_UDP6), &gEfiUdp6ProtocolGuid, NULL},\r
610 {STRING_TOKEN(STR_TCP6_SB), &gEfiTcp6ServiceBindingProtocolGuid, NULL},\r
611 {STRING_TOKEN(STR_TCP6), &gEfiTcp6ProtocolGuid, NULL},\r
612 {STRING_TOKEN(STR_VLAN_CONFIG), &gEfiVlanConfigProtocolGuid, NULL},\r
613 {STRING_TOKEN(STR_EAP), &gEfiEapProtocolGuid, NULL},\r
614 {STRING_TOKEN(STR_EAP_MGMT), &gEfiEapManagementProtocolGuid, NULL},\r
615 {STRING_TOKEN(STR_FTP4_SB), &gEfiFtp4ServiceBindingProtocolGuid, NULL},\r
616 {STRING_TOKEN(STR_FTP4), &gEfiFtp4ProtocolGuid, NULL},\r
617 {STRING_TOKEN(STR_IP_SEC_CONFIG), &gEfiIpSecConfigProtocolGuid, NULL},\r
618 {STRING_TOKEN(STR_DH), &gEfiDriverHealthProtocolGuid, NULL},\r
619 {STRING_TOKEN(STR_DEF_IMG_LOAD), &gEfiDeferredImageLoadProtocolGuid, NULL},\r
620 {STRING_TOKEN(STR_USER_CRED), &gEfiUserCredentialProtocolGuid, NULL},\r
621 {STRING_TOKEN(STR_USER_MNGR), &gEfiUserManagerProtocolGuid, NULL},\r
622 {STRING_TOKEN(STR_ATA_PASS_THRU), &gEfiAtaPassThruProtocolGuid, NULL},\r
623\r
624//\r
625// UEFI 2.3\r
626//\r
627 {STRING_TOKEN(STR_FW_MGMT), &gEfiFirmwareManagementProtocolGuid, NULL},\r
628 {STRING_TOKEN(STR_IP_SEC), &gEfiIpSecProtocolGuid, NULL},\r
629 {STRING_TOKEN(STR_IP_SEC2), &gEfiIpSec2ProtocolGuid, NULL},\r
630\r
631//\r
632// UEFI 2.3.1\r
633//\r
634 {STRING_TOKEN(STR_KMS), &gEfiKmsProtocolGuid, NULL},\r
635 {STRING_TOKEN(STR_BLK_IO2), &gEfiBlockIo2ProtocolGuid, NULL},\r
636 {STRING_TOKEN(STR_SSC), &gEfiStorageSecurityCommandProtocolGuid, NULL},\r
12f1a36c 637 {STRING_TOKEN(STR_UCRED2), &gEfiUserCredential2ProtocolGuid, NULL},\r
dee34318 638\r
28cdb62b
CP
639//\r
640// UEFI 2.4\r
641//\r
642 {STRING_TOKEN(STR_DISK_IO2), &gEfiDiskIo2ProtocolGuid, NULL},\r
643\r
6b640b4a
JC
644//\r
645// PI Spec ones\r
646//\r
647 {STRING_TOKEN(STR_IDE_CONT_INIT), &gEfiIdeControllerInitProtocolGuid, NULL},\r
648\r
dee34318 649//\r
650// terminator\r
651//\r
a405b86d 652 {STRING_TOKEN(STR_UNKNOWN_DEVICE), NULL, NULL},\r
653};\r
654\r
655/**\r
656 Function to get the node for a protocol or struct from it's GUID.\r
657\r
658 if Guid is NULL, then ASSERT.\r
659\r
660 @param[in] Guid The GUID to look for the name of.\r
661\r
662 @return The node.\r
663**/\r
dee34318 664CONST GUID_INFO_BLOCK *\r
a405b86d 665EFIAPI\r
666InternalShellGetNodeFromGuid(\r
667 IN CONST EFI_GUID* Guid\r
668 )\r
669{\r
dee34318 670 CONST GUID_INFO_BLOCK *ListWalker;\r
a405b86d 671\r
672 ASSERT(Guid != NULL);\r
673\r
674 if (PcdGetBool(PcdShellIncludeNtGuids)) {\r
675 for (ListWalker = mGuidStringListNT ; ListWalker != NULL && ListWalker->GuidId != NULL ; ListWalker++) {\r
676 if (CompareGuid(ListWalker->GuidId, Guid)) {\r
677 return (ListWalker);\r
678 }\r
679 }\r
680 }\r
681 for (ListWalker = mGuidStringList ; ListWalker != NULL && ListWalker->GuidId != NULL ; ListWalker++) {\r
682 if (CompareGuid(ListWalker->GuidId, Guid)) {\r
683 return (ListWalker);\r
684 }\r
685 }\r
686 return (ListWalker);\r
687}\r
688\r
689/**\r
690 Function to get the name of a protocol or struct from it's GUID.\r
691\r
692 if Guid is NULL, then ASSERT.\r
693\r
694 @param[in] Guid The GUID to look for the name of.\r
695 @param[in] Lang The language to use.\r
696\r
697 @return pointer to string of the name. The caller\r
698 is responsible to free this memory.\r
699**/\r
700CHAR16*\r
701EFIAPI\r
702GetStringNameFromGuid(\r
703 IN CONST EFI_GUID *Guid,\r
704 IN CONST CHAR8 *Lang OPTIONAL\r
705 )\r
706{\r
dee34318 707 CONST GUID_INFO_BLOCK *Id;\r
a405b86d 708\r
709 Id = InternalShellGetNodeFromGuid(Guid);\r
710 return (HiiGetString(mHandleParsingHiiHandle, Id->StringId, Lang));\r
711}\r
712\r
713/**\r
714 Function to dump protocol information from a handle.\r
715\r
716 This function will return a allocated string buffer containing the\r
717 information. The caller is responsible for freeing the memory.\r
718\r
719 If Guid is NULL, ASSERT().\r
720 If TheHandle is NULL, ASSERT().\r
721\r
722 @param[in] TheHandle The handle to dump information from.\r
723 @param[in] Guid The GUID of the protocol to dump.\r
724 @param[in] Verbose TRUE for extra info. FALSE otherwise.\r
725\r
726 @return The pointer to string.\r
727 @retval NULL An error was encountered.\r
728**/\r
729CHAR16*\r
730EFIAPI\r
731GetProtocolInformationDump(\r
732 IN CONST EFI_HANDLE TheHandle,\r
733 IN CONST EFI_GUID *Guid,\r
734 IN CONST BOOLEAN Verbose\r
735 )\r
736{\r
dee34318 737 CONST GUID_INFO_BLOCK *Id;\r
a405b86d 738\r
739 ASSERT(TheHandle != NULL);\r
740 ASSERT(Guid != NULL);\r
741\r
742 if (TheHandle == NULL || Guid == NULL) {\r
743 return (NULL);\r
744 }\r
745\r
746 Id = InternalShellGetNodeFromGuid(Guid);\r
747 if (Id != NULL && Id->DumpInfo != NULL) {\r
748 return (Id->DumpInfo(TheHandle, Verbose));\r
749 }\r
750 return (NULL);\r
751}\r
752\r
753/**\r
754 Function to get the Guid for a protocol or struct based on it's string name.\r
755\r
756 @param[in] Name The pointer to the string name.\r
757 @param[in] Lang The pointer to the language code.\r
758 @param[in] Guid The pointer to the Guid.\r
759\r
760 @retval EFI_SUCCESS The operation was sucessful.\r
761**/\r
762EFI_STATUS\r
763EFIAPI\r
764GetGuidFromStringName(\r
765 IN CONST CHAR16 *Name,\r
766 IN CONST CHAR8 *Lang OPTIONAL,\r
767 IN EFI_GUID **Guid\r
768 )\r
769{\r
dee34318 770 CONST GUID_INFO_BLOCK *ListWalker;\r
a405b86d 771 CHAR16 *String;\r
772\r
773 ASSERT(Guid != NULL);\r
774 if (Guid == NULL) {\r
775 return (EFI_INVALID_PARAMETER);\r
776 }\r
777 *Guid = NULL;\r
778\r
779 if (PcdGetBool(PcdShellIncludeNtGuids)) {\r
780 for (ListWalker = mGuidStringListNT ; ListWalker != NULL && ListWalker->GuidId != NULL ; ListWalker++) {\r
781 String = HiiGetString(mHandleParsingHiiHandle, ListWalker->StringId, Lang);\r
28cdb62b 782 if (Name != NULL && String != NULL && StringNoCaseCompare (&Name, &String) == 0) {\r
a405b86d 783 *Guid = ListWalker->GuidId;\r
784 }\r
785 SHELL_FREE_NON_NULL(String);\r
786 if (*Guid != NULL) {\r
787 return (EFI_SUCCESS);\r
788 }\r
789 }\r
790 }\r
791 for (ListWalker = mGuidStringList ; ListWalker != NULL && ListWalker->GuidId != NULL ; ListWalker++) {\r
792 String = HiiGetString(mHandleParsingHiiHandle, ListWalker->StringId, Lang);\r
28cdb62b 793 if (Name != NULL && String != NULL && StringNoCaseCompare (&Name, &String) == 0) {\r
a405b86d 794 *Guid = ListWalker->GuidId;\r
795 }\r
796 SHELL_FREE_NON_NULL(String);\r
797 if (*Guid != NULL) {\r
798 return (EFI_SUCCESS);\r
799 }\r
800 }\r
801 return (EFI_NOT_FOUND);\r
802}\r
803\r
36384ceb
ED
804/**\r
805 Get best support language for this driver.\r
806 \r
a71003f2
ED
807 First base on the user input language to search, second base on the current \r
808 platform used language to search, third get the first language from the \r
809 support language list. The caller need to free the buffer of the best language.\r
36384ceb
ED
810\r
811 @param[in] SupportedLanguages The support languages for this driver.\r
a71003f2 812 @param[in] InputLanguage The user input language.\r
36384ceb
ED
813 @param[in] Iso639Language Whether get language for ISO639.\r
814\r
815 @return The best support language for this driver.\r
816**/\r
817CHAR8 *\r
a71003f2 818EFIAPI\r
36384ceb 819GetBestLanguageForDriver (\r
a71003f2
ED
820 IN CONST CHAR8 *SupportedLanguages,\r
821 IN CONST CHAR8 *InputLanguage,\r
36384ceb
ED
822 IN BOOLEAN Iso639Language\r
823 )\r
824{\r
825 CHAR8 *LanguageVariable;\r
826 CHAR8 *BestLanguage;\r
827\r
828 LanguageVariable = GetVariable (Iso639Language ? L"Lang" : L"PlatformLang", &gEfiGlobalVariableGuid);\r
829\r
830 BestLanguage = GetBestLanguage(\r
831 SupportedLanguages,\r
832 Iso639Language,\r
a71003f2 833 (InputLanguage != NULL) ? InputLanguage : "",\r
36384ceb 834 (LanguageVariable != NULL) ? LanguageVariable : "",\r
a71003f2 835 SupportedLanguages,\r
36384ceb
ED
836 NULL\r
837 );\r
838\r
839 if (LanguageVariable != NULL) {\r
840 FreePool (LanguageVariable);\r
841 }\r
842\r
843 return BestLanguage;\r
844}\r
845\r
a405b86d 846/**\r
847 Function to retrieve the driver name (if possible) from the ComponentName or\r
848 ComponentName2 protocol\r
849\r
850 @param[in] TheHandle The driver handle to get the name of.\r
851 @param[in] Language The language to use.\r
852\r
853 @retval NULL The name could not be found.\r
854 @return A pointer to the string name. Do not de-allocate the memory.\r
855**/\r
856CONST CHAR16*\r
857EFIAPI\r
858GetStringNameFromHandle(\r
859 IN CONST EFI_HANDLE TheHandle,\r
860 IN CONST CHAR8 *Language\r
861 )\r
862{\r
863 EFI_COMPONENT_NAME2_PROTOCOL *CompNameStruct;\r
864 EFI_STATUS Status;\r
865 CHAR16 *RetVal;\r
36384ceb
ED
866 CHAR8 *BestLang;\r
867\r
868 BestLang = NULL;\r
a405b86d 869\r
870 Status = gBS->OpenProtocol(\r
871 TheHandle,\r
872 &gEfiComponentName2ProtocolGuid,\r
873 (VOID**)&CompNameStruct,\r
874 gImageHandle,\r
875 NULL,\r
876 EFI_OPEN_PROTOCOL_GET_PROTOCOL);\r
877 if (!EFI_ERROR(Status)) {\r
a71003f2
ED
878 BestLang = GetBestLanguageForDriver (CompNameStruct->SupportedLanguages, Language, FALSE);\r
879 Status = CompNameStruct->GetDriverName(CompNameStruct, BestLang, &RetVal);\r
36384ceb
ED
880 if (BestLang != NULL) {\r
881 FreePool (BestLang);\r
882 BestLang = NULL;\r
883 }\r
a405b86d 884 if (!EFI_ERROR(Status)) {\r
885 return (RetVal);\r
886 }\r
887 }\r
888 Status = gBS->OpenProtocol(\r
889 TheHandle,\r
890 &gEfiComponentNameProtocolGuid,\r
891 (VOID**)&CompNameStruct,\r
892 gImageHandle,\r
893 NULL,\r
894 EFI_OPEN_PROTOCOL_GET_PROTOCOL);\r
895 if (!EFI_ERROR(Status)) {\r
a71003f2
ED
896 BestLang = GetBestLanguageForDriver (CompNameStruct->SupportedLanguages, Language, FALSE);\r
897 Status = CompNameStruct->GetDriverName(CompNameStruct, BestLang, &RetVal);\r
36384ceb
ED
898 if (BestLang != NULL) {\r
899 FreePool (BestLang);\r
900 }\r
a405b86d 901 if (!EFI_ERROR(Status)) {\r
902 return (RetVal);\r
903 }\r
904 }\r
905 return (NULL);\r
906}\r
907\r
908/**\r
909 Function to initialize the file global mHandleList object for use in\r
910 vonverting handles to index and index to handle.\r
911\r
912 @retval EFI_SUCCESS The operation was successful.\r
913**/\r
914EFI_STATUS\r
915EFIAPI\r
916InternalShellInitHandleList(\r
917 VOID\r
918 )\r
919{\r
920 EFI_STATUS Status;\r
921 EFI_HANDLE *HandleBuffer;\r
922 UINTN HandleCount;\r
923 HANDLE_LIST *ListWalker;\r
924\r
925 if (mHandleList.NextIndex != 0) {\r
926 return EFI_SUCCESS;\r
927 }\r
928 InitializeListHead(&mHandleList.List.Link);\r
929 mHandleList.NextIndex = 1;\r
930 Status = gBS->LocateHandleBuffer (\r
931 AllHandles,\r
932 NULL,\r
933 NULL,\r
934 &HandleCount,\r
935 &HandleBuffer\r
936 );\r
937 ASSERT_EFI_ERROR(Status);\r
938 if (EFI_ERROR(Status)) {\r
939 return (Status);\r
940 }\r
941 for (mHandleList.NextIndex = 1 ; mHandleList.NextIndex <= HandleCount ; mHandleList.NextIndex++){\r
78ed876b 942 ListWalker = AllocateZeroPool(sizeof(HANDLE_LIST));\r
a405b86d 943 ASSERT(ListWalker != NULL);\r
944 ListWalker->TheHandle = HandleBuffer[mHandleList.NextIndex-1];\r
945 ListWalker->TheIndex = mHandleList.NextIndex;\r
946 InsertTailList(&mHandleList.List.Link,&ListWalker->Link);\r
947 }\r
948 FreePool(HandleBuffer);\r
949 return (EFI_SUCCESS);\r
950}\r
951\r
952/**\r
953 Function to retrieve the human-friendly index of a given handle. If the handle\r
954 does not have a index one will be automatically assigned. The index value is valid\r
955 until the termination of the shell application.\r
956\r
957 @param[in] TheHandle The handle to retrieve an index for.\r
958\r
959 @retval 0 A memory allocation failed.\r
960 @return The index of the handle.\r
961\r
962**/\r
963UINTN\r
964EFIAPI\r
965ConvertHandleToHandleIndex(\r
966 IN CONST EFI_HANDLE TheHandle\r
967 )\r
968{\r
f330ff35 969 EFI_STATUS Status;\r
970 EFI_GUID **ProtocolBuffer;\r
971 UINTN ProtocolCount;\r
972 HANDLE_LIST *ListWalker;\r
973\r
78ed876b 974 if (TheHandle == NULL) {\r
975 return 0;\r
976 }\r
a405b86d 977\r
978 InternalShellInitHandleList();\r
979\r
980 for (ListWalker = (HANDLE_LIST*)GetFirstNode(&mHandleList.List.Link)\r
981 ; !IsNull(&mHandleList.List.Link,&ListWalker->Link)\r
982 ; ListWalker = (HANDLE_LIST*)GetNextNode(&mHandleList.List.Link,&ListWalker->Link)\r
983 ){\r
984 if (ListWalker->TheHandle == TheHandle) {\r
f330ff35 985 //\r
986 // Verify that TheHandle is still present in the Handle Database\r
987 //\r
988 Status = gBS->ProtocolsPerHandle(TheHandle, &ProtocolBuffer, &ProtocolCount);\r
989 if (EFI_ERROR (Status)) {\r
990 //\r
991 // TheHandle is not present in the Handle Database, so delete from the handle list\r
992 //\r
993 RemoveEntryList (&ListWalker->Link);\r
994 return 0;\r
995 }\r
996 FreePool (ProtocolBuffer);\r
a405b86d 997 return (ListWalker->TheIndex);\r
998 }\r
999 }\r
f330ff35 1000\r
1001 //\r
1002 // Verify that TheHandle is valid handle\r
1003 //\r
1004 Status = gBS->ProtocolsPerHandle(TheHandle, &ProtocolBuffer, &ProtocolCount);\r
1005 if (EFI_ERROR (Status)) {\r
1006 //\r
1007 // TheHandle is not valid, so do not add to handle list\r
1008 //\r
1009 return 0;\r
1010 }\r
1011 FreePool (ProtocolBuffer);\r
1012\r
78ed876b 1013 ListWalker = AllocateZeroPool(sizeof(HANDLE_LIST));\r
a405b86d 1014 ASSERT(ListWalker != NULL);\r
1015 ListWalker->TheHandle = TheHandle;\r
1016 ListWalker->TheIndex = mHandleList.NextIndex++;\r
1017 InsertTailList(&mHandleList.List.Link,&ListWalker->Link);\r
1018 return (ListWalker->TheIndex);\r
1019}\r
1020\r
1021\r
1022\r
1023/**\r
1024 Function to retrieve the EFI_HANDLE from the human-friendly index.\r
1025\r
1026 @param[in] TheIndex The index to retrieve the EFI_HANDLE for.\r
1027\r
1028 @retval NULL The index was invalid.\r
1029 @return The EFI_HANDLE that index represents.\r
1030\r
1031**/\r
1032EFI_HANDLE\r
1033EFIAPI\r
1034ConvertHandleIndexToHandle(\r
1035 IN CONST UINTN TheIndex\r
1036 )\r
1037{\r
f330ff35 1038 EFI_STATUS Status;\r
1039 EFI_GUID **ProtocolBuffer;\r
1040 UINTN ProtocolCount;\r
a405b86d 1041 HANDLE_LIST *ListWalker;\r
1042\r
1043 InternalShellInitHandleList();\r
1044\r
1045 if (TheIndex >= mHandleList.NextIndex) {\r
f330ff35 1046 return NULL;\r
a405b86d 1047 }\r
1048\r
1049 for (ListWalker = (HANDLE_LIST*)GetFirstNode(&mHandleList.List.Link)\r
1050 ; !IsNull(&mHandleList.List.Link,&ListWalker->Link)\r
1051 ; ListWalker = (HANDLE_LIST*)GetNextNode(&mHandleList.List.Link,&ListWalker->Link)\r
1052 ){\r
f330ff35 1053 if (ListWalker->TheIndex == TheIndex && ListWalker->TheHandle != NULL) {\r
1054 //\r
1055 // Verify that LinkWalker->TheHandle is valid handle\r
1056 //\r
1057 Status = gBS->ProtocolsPerHandle(ListWalker->TheHandle, &ProtocolBuffer, &ProtocolCount);\r
1058 if (EFI_ERROR (Status)) {\r
1059 //\r
1060 // TheHandle is not valid, so do not add to handle list\r
1061 //\r
1062 ListWalker->TheHandle = NULL;\r
1063 }\r
a405b86d 1064 return (ListWalker->TheHandle);\r
1065 }\r
1066 }\r
f330ff35 1067 return NULL;\r
a405b86d 1068}\r
1069\r
1070/**\r
1071 Gets all the related EFI_HANDLEs based on the mask supplied.\r
1072\r
1073 This function scans all EFI_HANDLES in the UEFI environment's handle database\r
1074 and returns the ones with the specified relationship (Mask) to the specified\r
1075 controller handle.\r
1076\r
1077 If both DriverBindingHandle and ControllerHandle are NULL, then ASSERT.\r
1078 If MatchingHandleCount is NULL, then ASSERT.\r
1079\r
1080 If MatchingHandleBuffer is not NULL upon a successful return the memory must be\r
1081 caller freed.\r
1082\r
1083 @param[in] DriverBindingHandle The handle with Driver Binding protocol on it.\r
1084 @param[in] ControllerHandle The handle with Device Path protocol on it.\r
1085 @param[in] MatchingHandleCount The pointer to UINTN that specifies the number of HANDLES in\r
1086 MatchingHandleBuffer.\r
1087 @param[out] MatchingHandleBuffer On a successful return, a buffer of MatchingHandleCount\r
1088 EFI_HANDLEs with a terminating NULL EFI_HANDLE.\r
1089 @param[out] HandleType An array of type information.\r
1090\r
1091 @retval EFI_SUCCESS The operation was successful, and any related handles\r
1092 are in MatchingHandleBuffer.\r
1093 @retval EFI_NOT_FOUND No matching handles were found.\r
1094 @retval EFI_INVALID_PARAMETER A parameter was invalid or out of range.\r
1095**/\r
1096EFI_STATUS\r
1097EFIAPI\r
1098ParseHandleDatabaseByRelationshipWithType (\r
1099 IN CONST EFI_HANDLE DriverBindingHandle OPTIONAL,\r
1100 IN CONST EFI_HANDLE ControllerHandle OPTIONAL,\r
1101 IN UINTN *HandleCount,\r
1102 OUT EFI_HANDLE **HandleBuffer,\r
1103 OUT UINTN **HandleType\r
1104 )\r
1105{\r
1106 EFI_STATUS Status;\r
1107 UINTN HandleIndex;\r
1108 EFI_GUID **ProtocolGuidArray;\r
1109 UINTN ArrayCount;\r
1110 UINTN ProtocolIndex;\r
1111 EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfo;\r
1112 UINTN OpenInfoCount;\r
1113 UINTN OpenInfoIndex;\r
1114 UINTN ChildIndex;\r
f330ff35 1115 INTN DriverBindingHandleIndex;\r
a405b86d 1116\r
1117 ASSERT(HandleCount != NULL);\r
1118 ASSERT(HandleBuffer != NULL);\r
1119 ASSERT(HandleType != NULL);\r
1120 ASSERT(DriverBindingHandle != NULL || ControllerHandle != NULL);\r
1121\r
1122 *HandleCount = 0;\r
1123 *HandleBuffer = NULL;\r
1124 *HandleType = NULL;\r
1125\r
1126 //\r
1127 // Retrieve the list of all handles from the handle database\r
1128 //\r
1129 Status = gBS->LocateHandleBuffer (\r
1130 AllHandles,\r
1131 NULL,\r
1132 NULL,\r
1133 HandleCount,\r
1134 HandleBuffer\r
1135 );\r
1136 if (EFI_ERROR (Status)) {\r
1137 return (Status);\r
1138 }\r
1139\r
1140 *HandleType = AllocateZeroPool (*HandleCount * sizeof (UINTN));\r
1141 ASSERT(*HandleType != NULL);\r
1142\r
f330ff35 1143 DriverBindingHandleIndex = -1;\r
1144 for (HandleIndex = 0; HandleIndex < *HandleCount; HandleIndex++) {\r
1145 if (DriverBindingHandle != NULL && (*HandleBuffer)[HandleIndex] == DriverBindingHandle) {\r
1146 DriverBindingHandleIndex = (INTN)HandleIndex;\r
1147 }\r
1148 }\r
1149\r
a405b86d 1150 for (HandleIndex = 0; HandleIndex < *HandleCount; HandleIndex++) {\r
1151 //\r
1152 // Retrieve the list of all the protocols on each handle\r
1153 //\r
1154 Status = gBS->ProtocolsPerHandle (\r
1155 (*HandleBuffer)[HandleIndex],\r
1156 &ProtocolGuidArray,\r
1157 &ArrayCount\r
1158 );\r
f330ff35 1159 if (EFI_ERROR (Status)) {\r
1160 continue;\r
1161 }\r
a405b86d 1162\r
f330ff35 1163 for (ProtocolIndex = 0; ProtocolIndex < ArrayCount; ProtocolIndex++) {\r
a405b86d 1164\r
f330ff35 1165 //\r
1166 // Set the bit describing what this handle has\r
1167 //\r
1168 if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiLoadedImageProtocolGuid) ) {\r
1169 (*HandleType)[HandleIndex] |= HR_IMAGE_HANDLE;\r
1170 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverBindingProtocolGuid) ) {\r
1171 (*HandleType)[HandleIndex] |= HR_DRIVER_BINDING_HANDLE;\r
1172 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverConfiguration2ProtocolGuid)) {\r
1173 (*HandleType)[HandleIndex] |= HR_DRIVER_CONFIGURATION_HANDLE;\r
1174 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverConfigurationProtocolGuid) ) {\r
1175 (*HandleType)[HandleIndex] |= HR_DRIVER_CONFIGURATION_HANDLE;\r
1176 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverDiagnostics2ProtocolGuid) ) {\r
1177 (*HandleType)[HandleIndex] |= HR_DRIVER_DIAGNOSTICS_HANDLE;\r
1178 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDriverDiagnosticsProtocolGuid) ) {\r
1179 (*HandleType)[HandleIndex] |= HR_DRIVER_DIAGNOSTICS_HANDLE;\r
1180 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiComponentName2ProtocolGuid) ) {\r
1181 (*HandleType)[HandleIndex] |= HR_COMPONENT_NAME_HANDLE;\r
1182 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiComponentNameProtocolGuid) ) {\r
1183 (*HandleType)[HandleIndex] |= HR_COMPONENT_NAME_HANDLE;\r
1184 } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDevicePathProtocolGuid) ) {\r
1185 (*HandleType)[HandleIndex] |= HR_DEVICE_HANDLE;\r
1186 } else {\r
1187 DEBUG_CODE_BEGIN();\r
1188 ASSERT((*HandleType)[HandleIndex] == (*HandleType)[HandleIndex]);\r
1189 DEBUG_CODE_END();\r
1190 }\r
1191 //\r
1192 // Retrieve the list of agents that have opened each protocol\r
1193 //\r
1194 Status = gBS->OpenProtocolInformation (\r
a405b86d 1195 (*HandleBuffer)[HandleIndex],\r
1196 ProtocolGuidArray[ProtocolIndex],\r
1197 &OpenInfo,\r
1198 &OpenInfoCount\r
1199 );\r
f330ff35 1200 if (EFI_ERROR (Status)) {\r
1201 continue;\r
1202 }\r
1203\r
1204 if (ControllerHandle == NULL) {\r
1205 //\r
1206 // ControllerHandle == NULL and DriverBindingHandle != NULL. \r
1207 // Return information on all the controller handles that the driver specified by DriverBindingHandle is managing\r
1208 //\r
1209 for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) {\r
1210 if (OpenInfo[OpenInfoIndex].AgentHandle == DriverBindingHandle && (OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) != 0) {\r
1211 (*HandleType)[HandleIndex] |= (HR_DEVICE_HANDLE | HR_CONTROLLER_HANDLE);\r
1212 if (DriverBindingHandleIndex != -1) {\r
1213 (*HandleType)[DriverBindingHandleIndex] |= HR_DEVICE_DRIVER;\r
1214 }\r
1215 }\r
1216 if (OpenInfo[OpenInfoIndex].AgentHandle == DriverBindingHandle && (OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {\r
1217 (*HandleType)[HandleIndex] |= (HR_DEVICE_HANDLE | HR_CONTROLLER_HANDLE);\r
1218 if (DriverBindingHandleIndex != -1) {\r
1219 (*HandleType)[DriverBindingHandleIndex] |= (HR_BUS_DRIVER | HR_DEVICE_DRIVER);\r
1220 }\r
1221 for (ChildIndex = 0; ChildIndex < *HandleCount; ChildIndex++) {\r
1222 if (OpenInfo[OpenInfoIndex].ControllerHandle == (*HandleBuffer)[ChildIndex]) {\r
1223 (*HandleType)[ChildIndex] |= (HR_DEVICE_HANDLE | HR_CHILD_HANDLE);\r
1224 }\r
1225 }\r
1226 }\r
1227 }\r
1228 }\r
1229 if (DriverBindingHandle == NULL && ControllerHandle != NULL) {\r
1230 if (ControllerHandle == (*HandleBuffer)[HandleIndex]) {\r
1231 (*HandleType)[HandleIndex] |= (HR_DEVICE_HANDLE | HR_CONTROLLER_HANDLE);\r
a405b86d 1232 for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) {\r
f330ff35 1233 if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) != 0) {\r
1234 for (ChildIndex = 0; ChildIndex < *HandleCount; ChildIndex++) {\r
1235 if (OpenInfo[OpenInfoIndex].AgentHandle == (*HandleBuffer)[ChildIndex]) {\r
1236 (*HandleType)[ChildIndex] |= HR_DEVICE_DRIVER;\r
1237 }\r
a405b86d 1238 }\r
f330ff35 1239 }\r
1240 if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {\r
1241 for (ChildIndex = 0; ChildIndex < *HandleCount; ChildIndex++) {\r
1242 if (OpenInfo[OpenInfoIndex].AgentHandle == (*HandleBuffer)[ChildIndex]) {\r
1243 (*HandleType)[ChildIndex] |= (HR_BUS_DRIVER | HR_DEVICE_DRIVER);\r
1244 }\r
1245 if (OpenInfo[OpenInfoIndex].ControllerHandle == (*HandleBuffer)[ChildIndex]) {\r
1246 (*HandleType)[ChildIndex] |= (HR_DEVICE_HANDLE | HR_CHILD_HANDLE);\r
a405b86d 1247 }\r
1248 }\r
1249 }\r
f330ff35 1250 }\r
1251 } else {\r
1252 for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) {\r
1253 if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {\r
1254 if (OpenInfo[OpenInfoIndex].ControllerHandle == ControllerHandle) {\r
1255 (*HandleType)[HandleIndex] |= (HR_DEVICE_HANDLE | HR_PARENT_HANDLE);\r
1256 }\r
1257 }\r
1258 }\r
1259 }\r
1260 }\r
1261 if (DriverBindingHandle != NULL && ControllerHandle != NULL) {\r
1262 if (ControllerHandle == (*HandleBuffer)[HandleIndex]) {\r
1263 (*HandleType)[HandleIndex] |= (HR_DEVICE_HANDLE | HR_CONTROLLER_HANDLE);\r
1264 for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) {\r
1265 if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) != 0) {\r
1266 if (OpenInfo[OpenInfoIndex].AgentHandle == DriverBindingHandle) {\r
1267 if (DriverBindingHandleIndex != -1) {\r
1268 (*HandleType)[DriverBindingHandleIndex] |= HR_DEVICE_DRIVER;\r
a405b86d 1269 }\r
1270 }\r
f330ff35 1271 }\r
1272 if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {\r
1273 if (OpenInfo[OpenInfoIndex].AgentHandle == DriverBindingHandle) {\r
a405b86d 1274 for (ChildIndex = 0; ChildIndex < *HandleCount; ChildIndex++) {\r
f330ff35 1275 if (OpenInfo[OpenInfoIndex].ControllerHandle == (*HandleBuffer)[ChildIndex]) {\r
1276 (*HandleType)[ChildIndex] |= (HR_DEVICE_HANDLE | HR_CHILD_HANDLE);\r
a405b86d 1277 }\r
1278 }\r
1279 }\r
f330ff35 1280\r
1281 for (ChildIndex = 0; ChildIndex < *HandleCount; ChildIndex++) {\r
1282 if (OpenInfo[OpenInfoIndex].AgentHandle == (*HandleBuffer)[ChildIndex]) {\r
1283 (*HandleType)[ChildIndex] |= (HR_BUS_DRIVER | HR_DEVICE_DRIVER);\r
1284 }\r
1285 }\r
1286 }\r
1287 }\r
1288 } else {\r
1289 for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) {\r
1290 if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {\r
1291 if (OpenInfo[OpenInfoIndex].ControllerHandle == ControllerHandle) {\r
1292 (*HandleType)[HandleIndex] |= (HR_DEVICE_HANDLE | HR_PARENT_HANDLE);\r
1293 }\r
a405b86d 1294 }\r
1295 }\r
a405b86d 1296 }\r
1297 }\r
f330ff35 1298 FreePool (OpenInfo);\r
a405b86d 1299 }\r
f330ff35 1300 FreePool (ProtocolGuidArray);\r
a405b86d 1301 }\r
f330ff35 1302 return EFI_SUCCESS;\r
a405b86d 1303}\r
1304\r
1305/**\r
1306 Gets all the related EFI_HANDLEs based on the single EFI_HANDLE and the mask\r
1307 supplied.\r
1308\r
1309 This function will scan all EFI_HANDLES in the UEFI environment's handle database\r
1310 and return all the ones with the specified relationship (Mask) to the specified\r
1311 controller handle.\r
1312\r
1313 If both DriverBindingHandle and ControllerHandle are NULL, then ASSERT.\r
1314 If MatchingHandleCount is NULL, then ASSERT.\r
1315\r
1316 If MatchingHandleBuffer is not NULL upon a sucessful return the memory must be\r
1317 caller freed.\r
1318\r
1319 @param[in] DriverBindingHandle Handle to a object with Driver Binding protocol\r
1320 on it.\r
1321 @param[in] ControllerHandle Handle to a device with Device Path protocol on it.\r
1322 @param[in] Mask Mask of what relationship(s) is desired.\r
1323 @param[in] MatchingHandleCount Poitner to UINTN specifying number of HANDLES in\r
1324 MatchingHandleBuffer.\r
1325 @param[out] MatchingHandleBuffer On a sucessful return a buffer of MatchingHandleCount\r
1326 EFI_HANDLEs and a terminating NULL EFI_HANDLE.\r
1327\r
1328 @retval EFI_SUCCESS The operation was sucessful and any related handles\r
1329 are in MatchingHandleBuffer;\r
1330 @retval EFI_NOT_FOUND No matching handles were found.\r
1331 @retval EFI_INVALID_PARAMETER A parameter was invalid or out of range.\r
1332**/\r
1333EFI_STATUS\r
1334EFIAPI\r
1335ParseHandleDatabaseByRelationship (\r
1336 IN CONST EFI_HANDLE DriverBindingHandle OPTIONAL,\r
1337 IN CONST EFI_HANDLE ControllerHandle OPTIONAL,\r
1338 IN CONST UINTN Mask,\r
1339 IN UINTN *MatchingHandleCount,\r
1340 OUT EFI_HANDLE **MatchingHandleBuffer OPTIONAL\r
1341 )\r
1342{\r
1343 EFI_STATUS Status;\r
1344 UINTN HandleCount;\r
1345 EFI_HANDLE *HandleBuffer;\r
1346 UINTN *HandleType;\r
1347 UINTN HandleIndex;\r
1348\r
1349 ASSERT(MatchingHandleCount != NULL);\r
1350 ASSERT(DriverBindingHandle != NULL || ControllerHandle != NULL);\r
1351\r
1352 if ((Mask & HR_VALID_MASK) != Mask) {\r
1353 return (EFI_INVALID_PARAMETER);\r
1354 }\r
1355\r
1356 if ((Mask & HR_CHILD_HANDLE) != 0 && DriverBindingHandle == NULL) {\r
1357 return (EFI_INVALID_PARAMETER);\r
1358 }\r
1359\r
1360 *MatchingHandleCount = 0;\r
1361 if (MatchingHandleBuffer != NULL) {\r
1362 *MatchingHandleBuffer = NULL;\r
1363 }\r
1364\r
1365 HandleBuffer = NULL;\r
1366 HandleType = NULL;\r
1367\r
1368 Status = ParseHandleDatabaseByRelationshipWithType (\r
1369 DriverBindingHandle,\r
1370 ControllerHandle,\r
1371 &HandleCount,\r
1372 &HandleBuffer,\r
1373 &HandleType\r
1374 );\r
1375 if (!EFI_ERROR (Status)) {\r
1376 //\r
1377 // Count the number of handles that match the attributes in Mask\r
1378 //\r
1379 for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {\r
1380 if ((HandleType[HandleIndex] & Mask) == Mask) {\r
1381 (*MatchingHandleCount)++;\r
1382 }\r
1383 }\r
1384 //\r
1385 // If no handles match the attributes in Mask then return EFI_NOT_FOUND\r
1386 //\r
1387 if (*MatchingHandleCount == 0) {\r
1388 Status = EFI_NOT_FOUND;\r
1389 } else {\r
1390\r
1391 if (MatchingHandleBuffer == NULL) {\r
1392 //\r
1393 // Someone just wanted the count...\r
1394 //\r
1395 Status = EFI_SUCCESS;\r
1396 } else {\r
1397 //\r
1398 // Allocate a handle buffer for the number of handles that matched the attributes in Mask\r
1399 //\r
78ed876b 1400 *MatchingHandleBuffer = AllocateZeroPool ((*MatchingHandleCount +1)* sizeof (EFI_HANDLE));\r
a405b86d 1401 ASSERT(*MatchingHandleBuffer != NULL);\r
1402\r
1403 for (HandleIndex = 0,*MatchingHandleCount = 0\r
1404 ; HandleIndex < HandleCount\r
1405 ; HandleIndex++\r
1406 ){\r
1407 //\r
1408 // Fill the allocated buffer with the handles that matched the attributes in Mask\r
1409 //\r
1410 if ((HandleType[HandleIndex] & Mask) == Mask) {\r
1411 (*MatchingHandleBuffer)[(*MatchingHandleCount)++] = HandleBuffer[HandleIndex];\r
1412 }\r
1413 }\r
1414\r
1415 //\r
1416 // Make the last one NULL\r
1417 //\r
1418 (*MatchingHandleBuffer)[*MatchingHandleCount] = NULL;\r
1419\r
1420 Status = EFI_SUCCESS;\r
1421 } // MacthingHandleBuffer == NULL (ELSE)\r
1422 } // *MatchingHandleCount == 0 (ELSE)\r
1423 } // no error on ParseHandleDatabaseByRelationshipWithType\r
1424\r
1425 if (HandleBuffer != NULL) {\r
1426 FreePool (HandleBuffer);\r
1427 }\r
1428\r
1429 if (HandleType != NULL) {\r
1430 FreePool (HandleType);\r
1431 }\r
1432\r
1433 return Status;\r
1434}\r
1435\r
1436/**\r
1437 Gets handles for any child controllers of the passed in controller.\r
1438\r
1439 @param[in] ControllerHandle The handle of the "parent controller"\r
1440 @param[in] MatchingHandleCount Pointer to the number of handles in\r
1441 MatchingHandleBuffer on return.\r
1442 @param[out] MatchingHandleBuffer Buffer containing handles on a successful\r
1443 return.\r
1444\r
1445\r
1446 @retval EFI_SUCCESS The operation was sucessful.\r
1447**/\r
1448EFI_STATUS\r
1449EFIAPI\r
1450ParseHandleDatabaseForChildControllers(\r
1451 IN CONST EFI_HANDLE ControllerHandle,\r
1452 IN UINTN *MatchingHandleCount,\r
1453 OUT EFI_HANDLE **MatchingHandleBuffer OPTIONAL\r
1454 )\r
1455{\r
1456 EFI_STATUS Status;\r
f330ff35 1457 UINTN HandleIndex;\r
a405b86d 1458 UINTN DriverBindingHandleCount;\r
1459 EFI_HANDLE *DriverBindingHandleBuffer;\r
1460 UINTN DriverBindingHandleIndex;\r
1461 UINTN ChildControllerHandleCount;\r
1462 EFI_HANDLE *ChildControllerHandleBuffer;\r
1463 UINTN ChildControllerHandleIndex;\r
a405b86d 1464 EFI_HANDLE *HandleBufferForReturn;\r
1465\r
ff51746b 1466 if (MatchingHandleCount == NULL) {\r
1467 return (EFI_INVALID_PARAMETER);\r
1468 }\r
64d753f1 1469 *MatchingHandleCount = 0;\r
a405b86d 1470\r
1471 Status = PARSE_HANDLE_DATABASE_UEFI_DRIVERS (\r
1472 ControllerHandle,\r
1473 &DriverBindingHandleCount,\r
1474 &DriverBindingHandleBuffer\r
1475 );\r
1476 if (EFI_ERROR (Status)) {\r
1477 return Status;\r
1478 }\r
1479\r
ff51746b 1480 //\r
1481 // Get a buffer big enough for all the controllers.\r
1482 //\r
f330ff35 1483 HandleBufferForReturn = GetHandleListByProtocol(NULL);\r
a405b86d 1484 if (HandleBufferForReturn == NULL) {\r
1485 FreePool (DriverBindingHandleBuffer);\r
ff51746b 1486 return (EFI_NOT_FOUND);\r
a405b86d 1487 }\r
1488\r
a405b86d 1489 for (DriverBindingHandleIndex = 0; DriverBindingHandleIndex < DriverBindingHandleCount; DriverBindingHandleIndex++) {\r
1490 Status = PARSE_HANDLE_DATABASE_MANAGED_CHILDREN (\r
1491 DriverBindingHandleBuffer[DriverBindingHandleIndex],\r
1492 ControllerHandle,\r
1493 &ChildControllerHandleCount,\r
1494 &ChildControllerHandleBuffer\r
1495 );\r
1496 if (EFI_ERROR (Status)) {\r
1497 continue;\r
1498 }\r
1499\r
1500 for (ChildControllerHandleIndex = 0;\r
1501 ChildControllerHandleIndex < ChildControllerHandleCount;\r
1502 ChildControllerHandleIndex++\r
1503 ) {\r
f330ff35 1504 for (HandleIndex = 0; HandleIndex < *MatchingHandleCount; HandleIndex++) {\r
1505 if (HandleBufferForReturn[HandleIndex] == ChildControllerHandleBuffer[ChildControllerHandleIndex]) {\r
1506 break;\r
1507 }\r
1508 }\r
1509 if (HandleIndex >= *MatchingHandleCount) {\r
1510 HandleBufferForReturn[(*MatchingHandleCount)++] = ChildControllerHandleBuffer[ChildControllerHandleIndex];\r
1511 }\r
a405b86d 1512 }\r
1513\r
1514 FreePool (ChildControllerHandleBuffer);\r
1515 }\r
1516\r
1517 FreePool (DriverBindingHandleBuffer);\r
1518\r
1519 if (MatchingHandleBuffer != NULL) {\r
1520 *MatchingHandleBuffer = HandleBufferForReturn;\r
1521 } else {\r
1522 FreePool(HandleBufferForReturn);\r
1523 }\r
1524\r
1525 return (EFI_SUCCESS);\r
1526}\r
1527\r
1528/**\r
1529 Appends 1 buffer to another buffer. This will re-allocate the destination buffer\r
1530 if necessary to fit all of the data.\r
1531\r
1532 If DestinationBuffer is NULL, then ASSERT().\r
1533\r
4ff7e37b
ED
1534 @param[in, out] DestinationBuffer The pointer to the pointer to the buffer to append onto.\r
1535 @param[in, out] DestinationSize The pointer to the size of DestinationBuffer.\r
1536 @param[in] SourceBuffer The pointer to the buffer to append onto DestinationBuffer.\r
1537 @param[in] SourceSize The number of bytes of SourceBuffer to append.\r
a405b86d 1538\r
1539 @retval NULL A memory allocation failed.\r
1540 @retval NULL A parameter was invalid.\r
1541 @return A pointer to (*DestinationBuffer).\r
1542**/\r
1543VOID*\r
1544EFIAPI\r
1545BuffernCatGrow (\r
1546 IN OUT VOID **DestinationBuffer,\r
1547 IN OUT UINTN *DestinationSize,\r
1548 IN VOID *SourceBuffer,\r
1549 IN UINTN SourceSize\r
1550 )\r
1551{\r
1552 UINTN LocalDestinationSize;\r
1553 UINTN LocalDestinationFinalSize;\r
1554\r
1555 ASSERT(DestinationBuffer != NULL);\r
1556\r
1557 if (SourceSize == 0 || SourceBuffer == NULL) {\r
1558 return (*DestinationBuffer);\r
1559 }\r
1560\r
1561 if (DestinationSize == NULL) {\r
1562 LocalDestinationSize = 0;\r
1563 } else {\r
1564 LocalDestinationSize = *DestinationSize;\r
1565 }\r
1566\r
1567 LocalDestinationFinalSize = LocalDestinationSize + SourceSize;\r
1568\r
1569 if (DestinationSize != NULL) {\r
1570 *DestinationSize = LocalDestinationSize;\r
1571 }\r
1572\r
1573 if (LocalDestinationSize == 0) {\r
1574 // allcoate\r
78ed876b 1575 *DestinationBuffer = AllocateZeroPool(LocalDestinationFinalSize);\r
a405b86d 1576 } else {\r
1577 // reallocate\r
1578 *DestinationBuffer = ReallocatePool(LocalDestinationSize, LocalDestinationFinalSize, *DestinationBuffer);\r
1579 }\r
1580\r
1581 ASSERT(*DestinationBuffer != NULL);\r
1582\r
1583 // copy\r
1584 return (CopyMem(((UINT8*)(*DestinationBuffer)) + LocalDestinationSize, SourceBuffer, SourceSize));\r
1585}\r
1586\r
1587/**\r
1588 Gets handles for any child devices produced by the passed in driver.\r
1589\r
1590 @param[in] DriverHandle The handle of the driver.\r
1591 @param[in] MatchingHandleCount Pointer to the number of handles in\r
1592 MatchingHandleBuffer on return.\r
1593 @param[out] MatchingHandleBuffer Buffer containing handles on a successful\r
1594 return.\r
1595 @retval EFI_SUCCESS The operation was sucessful.\r
1596 @sa ParseHandleDatabaseByRelationship\r
1597**/\r
1598EFI_STATUS\r
1599EFIAPI\r
1600ParseHandleDatabaseForChildDevices(\r
1601 IN CONST EFI_HANDLE DriverHandle,\r
1602 IN UINTN *MatchingHandleCount,\r
1603 OUT EFI_HANDLE **MatchingHandleBuffer OPTIONAL\r
1604 )\r
1605{\r
1606 EFI_HANDLE *Buffer;\r
1607 EFI_HANDLE *Buffer2;\r
1608 UINTN Count1;\r
1609 UINTN Count2;\r
1610 UINTN HandleIndex;\r
1611 EFI_STATUS Status;\r
1612 UINTN HandleBufferSize;\r
1613\r
1614 ASSERT(MatchingHandleCount != NULL);\r
1615\r
1616 HandleBufferSize = 0;\r
1617 Buffer = NULL;\r
1618 Buffer2 = NULL;\r
1619 *MatchingHandleCount = 0;\r
1620\r
1621 Status = PARSE_HANDLE_DATABASE_DEVICES (\r
1622 DriverHandle,\r
1623 &Count1,\r
1624 &Buffer\r
1625 );\r
1626 if (!EFI_ERROR (Status)) {\r
1627 for (HandleIndex = 0; HandleIndex < Count1; HandleIndex++) {\r
1628 //\r
1629 // now find the children\r
1630 //\r
1631 Status = PARSE_HANDLE_DATABASE_MANAGED_CHILDREN (\r
1632 DriverHandle,\r
1633 Buffer[HandleIndex],\r
1634 &Count2,\r
1635 &Buffer2\r
1636 );\r
1637 if (EFI_ERROR(Status)) {\r
1638 break;\r
1639 }\r
1640 //\r
1641 // save out required and optional data elements\r
1642 //\r
1643 *MatchingHandleCount += Count2;\r
1644 if (MatchingHandleBuffer != NULL) {\r
1645 *MatchingHandleBuffer = BuffernCatGrow((VOID**)MatchingHandleBuffer, &HandleBufferSize, Buffer2, Count2 * sizeof(Buffer2[0]));\r
1646 }\r
1647\r
1648 //\r
1649 // free the memory\r
1650 //\r
1651 if (Buffer2 != NULL) {\r
1652 FreePool(Buffer2);\r
1653 }\r
1654 }\r
1655 }\r
1656\r
1657 if (Buffer != NULL) {\r
1658 FreePool(Buffer);\r
1659 }\r
1660 return (Status);\r
1661}\r
1662\r
1663/**\r
1664 Function to get all handles that support a given protocol or all handles.\r
1665\r
1666 @param[in] ProtocolGuid The guid of the protocol to get handles for. If NULL\r
1667 then the function will return all handles.\r
1668\r
1669 @retval NULL A memory allocation failed.\r
1670 @return A NULL terminated list of handles.\r
1671**/\r
1672EFI_HANDLE*\r
1673EFIAPI\r
40d7a9cf 1674GetHandleListByProtocol (\r
a405b86d 1675 IN CONST EFI_GUID *ProtocolGuid OPTIONAL\r
1676 )\r
1677{\r
1678 EFI_HANDLE *HandleList;\r
1679 UINTN Size;\r
1680 EFI_STATUS Status;\r
1681\r
1682 Size = 0;\r
1683 HandleList = NULL;\r
1684\r
1685 //\r
1686 // We cannot use LocateHandleBuffer since we need that NULL item on the ends of the list!\r
1687 //\r
1688 if (ProtocolGuid == NULL) {\r
1689 Status = gBS->LocateHandle(AllHandles, NULL, NULL, &Size, HandleList);\r
1690 if (Status == EFI_BUFFER_TOO_SMALL) {\r
78ed876b 1691 HandleList = AllocateZeroPool(Size + sizeof(EFI_HANDLE));\r
40d7a9cf 1692 if (HandleList == NULL) {\r
1693 return (NULL);\r
1694 }\r
a405b86d 1695 Status = gBS->LocateHandle(AllHandles, NULL, NULL, &Size, HandleList);\r
1696 HandleList[Size/sizeof(EFI_HANDLE)] = NULL;\r
1697 }\r
1698 } else {\r
1699 Status = gBS->LocateHandle(ByProtocol, (EFI_GUID*)ProtocolGuid, NULL, &Size, HandleList);\r
1700 if (Status == EFI_BUFFER_TOO_SMALL) {\r
78ed876b 1701 HandleList = AllocateZeroPool(Size + sizeof(EFI_HANDLE));\r
40d7a9cf 1702 if (HandleList == NULL) {\r
1703 return (NULL);\r
1704 }\r
a405b86d 1705 Status = gBS->LocateHandle(ByProtocol, (EFI_GUID*)ProtocolGuid, NULL, &Size, HandleList);\r
1706 HandleList[Size/sizeof(EFI_HANDLE)] = NULL;\r
1707 }\r
1708 }\r
1709 if (EFI_ERROR(Status)) {\r
1710 if (HandleList != NULL) {\r
1711 FreePool(HandleList);\r
1712 }\r
1713 return (NULL);\r
1714 }\r
1715 return (HandleList);\r
1716}\r
1717\r
1718/**\r
1719 Function to get all handles that support some protocols.\r
1720\r
1721 @param[in] ProtocolGuids A NULL terminated list of protocol GUIDs.\r
1722\r
1723 @retval NULL A memory allocation failed.\r
ff51746b 1724 @retval NULL ProtocolGuids was NULL.\r
1725 @return A NULL terminated list of EFI_HANDLEs.\r
a405b86d 1726**/\r
1727EFI_HANDLE*\r
1728EFIAPI\r
40d7a9cf 1729GetHandleListByProtocolList (\r
a405b86d 1730 IN CONST EFI_GUID **ProtocolGuids\r
1731 )\r
1732{\r
1733 EFI_HANDLE *HandleList;\r
1734 UINTN Size;\r
1735 UINTN TotalSize;\r
40d7a9cf 1736 UINTN TempSize;\r
a405b86d 1737 EFI_STATUS Status;\r
1738 CONST EFI_GUID **GuidWalker;\r
1739 EFI_HANDLE *HandleWalker1;\r
1740 EFI_HANDLE *HandleWalker2;\r
1741\r
1742 Size = 0;\r
1743 HandleList = NULL;\r
1744 TotalSize = sizeof(EFI_HANDLE);\r
1745\r
1746 for (GuidWalker = ProtocolGuids ; GuidWalker != NULL && *GuidWalker != NULL ; GuidWalker++,Size = 0){\r
1747 Status = gBS->LocateHandle(ByProtocol, (EFI_GUID*)(*GuidWalker), NULL, &Size, NULL);\r
1748 if (Status == EFI_BUFFER_TOO_SMALL) {\r
1749 TotalSize += Size;\r
1750 }\r
1751 }\r
40d7a9cf 1752\r
1753 //\r
1754 // No handles were found... \r
1755 //\r
1756 if (TotalSize == sizeof(EFI_HANDLE)) {\r
1757 return (NULL);\r
1758 }\r
1759\r
1760 HandleList = AllocateZeroPool(TotalSize);\r
a405b86d 1761 if (HandleList == NULL) {\r
1762 return (NULL);\r
1763 }\r
1764\r
1765 Size = 0;\r
1766 for (GuidWalker = ProtocolGuids ; GuidWalker != NULL && *GuidWalker != NULL ; GuidWalker++){\r
40d7a9cf 1767 TempSize = TotalSize - Size;\r
ff51746b 1768 Status = gBS->LocateHandle(ByProtocol, (EFI_GUID*)(*GuidWalker), NULL, &TempSize, HandleList+(Size/sizeof(EFI_HANDLE)));\r
40d7a9cf 1769\r
1770 //\r
1771 // Allow for missing protocols... Only update the 'used' size upon success.\r
1772 //\r
1773 if (!EFI_ERROR(Status)) {\r
ff51746b 1774 Size += TempSize;\r
40d7a9cf 1775 }\r
a405b86d 1776 }\r
ff51746b 1777 ASSERT(HandleList[(TotalSize/sizeof(EFI_HANDLE))-1] == NULL);\r
a405b86d 1778\r
1779 for (HandleWalker1 = HandleList ; HandleWalker1 != NULL && *HandleWalker1 != NULL ; HandleWalker1++) {\r
1780 for (HandleWalker2 = HandleWalker1 + 1; HandleWalker2 != NULL && *HandleWalker2 != NULL ; HandleWalker2++) {\r
1781 if (*HandleWalker1 == *HandleWalker2) {\r
1782 //\r
1783 // copy memory back 1 handle width.\r
1784 //\r
1785 CopyMem(HandleWalker2, HandleWalker2 + 1, TotalSize - ((HandleWalker2-HandleList+1)*sizeof(EFI_HANDLE)));\r
1786 }\r
1787 }\r
1788 }\r
1789\r
1790 return (HandleList);\r
1791}\r
1792\r
1793\r
1794\r
1795\r
1796\r
1797\r
1798\r
1799\r
1800\r
1801\r