2 Provides interface to advanced shell functionality for parsing both handle and protocol database.
4 Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
5 Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "UefiHandleParsingLib.h"
17 #include "IndustryStandard/Acpi10.h"
19 EFI_HANDLE mHandleParsingHiiHandle
;
20 HANDLE_INDEX_LIST mHandleList
= {{{NULL
,NULL
},0,0},0};
23 Function to translate the EFI_MEMORY_TYPE into a string.
25 @param[in] Memory The memory type.
27 @retval A string representation of the type allocated from BS Pool.
32 IN CONST EFI_MEMORY_TYPE Memory
39 case EfiReservedMemoryType
: StrnCatGrow(&RetVal
, NULL
, L
"EfiReservedMemoryType", 0); break;
40 case EfiLoaderCode
: StrnCatGrow(&RetVal
, NULL
, L
"EfiLoaderCode", 0); break;
41 case EfiLoaderData
: StrnCatGrow(&RetVal
, NULL
, L
"EfiLoaderData", 0); break;
42 case EfiBootServicesCode
: StrnCatGrow(&RetVal
, NULL
, L
"EfiBootServicesCode", 0); break;
43 case EfiBootServicesData
: StrnCatGrow(&RetVal
, NULL
, L
"EfiBootServicesData", 0); break;
44 case EfiRuntimeServicesCode
: StrnCatGrow(&RetVal
, NULL
, L
"EfiRuntimeServicesCode", 0); break;
45 case EfiRuntimeServicesData
: StrnCatGrow(&RetVal
, NULL
, L
"EfiRuntimeServicesData", 0); break;
46 case EfiConventionalMemory
: StrnCatGrow(&RetVal
, NULL
, L
"EfiConventionalMemory", 0); break;
47 case EfiUnusableMemory
: StrnCatGrow(&RetVal
, NULL
, L
"EfiUnusableMemory", 0); break;
48 case EfiACPIReclaimMemory
: StrnCatGrow(&RetVal
, NULL
, L
"EfiACPIReclaimMemory", 0); break;
49 case EfiACPIMemoryNVS
: StrnCatGrow(&RetVal
, NULL
, L
"EfiACPIMemoryNVS", 0); break;
50 case EfiMemoryMappedIO
: StrnCatGrow(&RetVal
, NULL
, L
"EfiMemoryMappedIO", 0); break;
51 case EfiMemoryMappedIOPortSpace
: StrnCatGrow(&RetVal
, NULL
, L
"EfiMemoryMappedIOPortSpace", 0); break;
52 case EfiPalCode
: StrnCatGrow(&RetVal
, NULL
, L
"EfiPalCode", 0); break;
53 case EfiMaxMemoryType
: StrnCatGrow(&RetVal
, NULL
, L
"EfiMaxMemoryType", 0); break;
54 default: ASSERT(FALSE
);
60 Constructor for the library.
62 @param[in] ImageHandle Ignored.
63 @param[in] SystemTable Ignored.
65 @retval EFI_SUCCESS The operation was successful.
69 HandleParsingLibConstructor (
70 IN EFI_HANDLE ImageHandle
,
71 IN EFI_SYSTEM_TABLE
*SystemTable
74 mHandleParsingHiiHandle
= HiiAddPackages (&gHandleParsingHiiGuid
, gImageHandle
, UefiHandleParsingLibStrings
, NULL
);
75 if (mHandleParsingHiiHandle
== NULL
) {
76 return (EFI_DEVICE_ERROR
);
83 Destructor for the library. free any resources.
85 @param[in] ImageHandle Ignored.
86 @param[in] SystemTable Ignored.
88 @retval EFI_SUCCESS The operation was successful.
92 HandleParsingLibDestructor (
93 IN EFI_HANDLE ImageHandle
,
94 IN EFI_SYSTEM_TABLE
*SystemTable
97 if (mHandleParsingHiiHandle
!= NULL
) {
98 HiiRemovePackages(mHandleParsingHiiHandle
);
100 return (EFI_SUCCESS
);
104 Function to dump information about LoadedImage.
106 This will allocate the return buffer from boot services pool.
108 @param[in] TheHandle The handle that has LoadedImage installed.
109 @param[in] Verbose TRUE for additional information, FALSE otherwise.
111 @retval A poitner to a string containing the information.
115 LoadedImageProtocolDumpInformation(
116 IN CONST EFI_HANDLE TheHandle
,
117 IN CONST BOOLEAN Verbose
120 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
128 return (CatSPrint(NULL
, L
"LoadedImage"));
131 Temp
= HiiGetString(mHandleParsingHiiHandle
, STRING_TOKEN(STR_LI_DUMP_MAIN
), NULL
);
132 RetVal
= AllocateZeroPool (PcdGet16 (PcdShellPrintBufferSize
));
133 if (Temp
== NULL
|| RetVal
== NULL
) {
134 SHELL_FREE_NON_NULL(Temp
);
135 SHELL_FREE_NON_NULL(RetVal
);
139 Status
= gBS
->OpenProtocol (
141 &gEfiLoadedImageProtocolGuid
,
142 (VOID
**)&LoadedImage
,
145 EFI_OPEN_PROTOCOL_GET_PROTOCOL
148 if (EFI_ERROR (Status
)) {
149 SHELL_FREE_NON_NULL (Temp
);
150 SHELL_FREE_NON_NULL (RetVal
);
154 DataType
= ConvertMemoryType(LoadedImage
->ImageDataType
);
155 CodeType
= ConvertMemoryType(LoadedImage
->ImageCodeType
);
157 RetVal
= CatSPrint(RetVal
,
159 LoadedImage
->Revision
,
160 LoadedImage
->ParentHandle
,
161 LoadedImage
->SystemTable
,
162 LoadedImage
->DeviceHandle
,
163 LoadedImage
->FilePath
,
164 LoadedImage
->LoadOptionsSize
,
165 LoadedImage
->LoadOptions
,
166 LoadedImage
->ImageBase
,
167 LoadedImage
->ImageSize
,
170 LoadedImage
->Unload
);
173 SHELL_FREE_NON_NULL(Temp
);
174 SHELL_FREE_NON_NULL(CodeType
);
175 SHELL_FREE_NON_NULL(DataType
);
181 Function to dump information about PciRootBridgeIo.
183 This will allocate the return buffer from boot services pool.
185 @param[in] TheHandle The handle that has PciRootBridgeIo installed.
186 @param[in] Verbose TRUE for additional information, FALSE otherwise.
188 @retval A poitner to a string containing the information.
192 PciRootBridgeIoDumpInformation(
193 IN CONST EFI_HANDLE TheHandle
,
194 IN CONST BOOLEAN Verbose
197 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
198 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*Configuration
;
209 return (CatSPrint(NULL
, L
"PciRootBridgeIo"));
212 Status
= gBS
->HandleProtocol(
214 &gEfiPciRootBridgeIoProtocolGuid
,
215 (VOID
**)&PciRootBridgeIo
);
217 if (EFI_ERROR(Status
)) {
221 Temp
= HiiGetString(mHandleParsingHiiHandle
, STRING_TOKEN(STR_PCIRB_DUMP_PH
), NULL
);
222 ASSERT (Temp
!= NULL
);
223 Temp2
= CatSPrint(L
"\r\n", Temp
, PciRootBridgeIo
->ParentHandle
);
228 Temp
= HiiGetString(mHandleParsingHiiHandle
, STRING_TOKEN(STR_PCIRB_DUMP_SEG
), NULL
);
229 ASSERT (Temp
!= NULL
);
230 Temp2
= CatSPrint(RetVal
, Temp
, PciRootBridgeIo
->SegmentNumber
);
238 Status
= PciRootBridgeIo
->GetAttributes (PciRootBridgeIo
, &Supports
, &Attributes
);
239 if (!EFI_ERROR(Status
)) {
240 Temp
= HiiGetString(mHandleParsingHiiHandle
, STRING_TOKEN(STR_PCIRB_DUMP_ATT
), NULL
);
241 ASSERT (Temp
!= NULL
);
242 Temp2
= CatSPrint(RetVal
, Temp
, Attributes
);
248 Temp
= HiiGetString(mHandleParsingHiiHandle
, STRING_TOKEN(STR_PCIRB_DUMP_SUPPORTS
), NULL
);
249 ASSERT (Temp
!= NULL
);
250 Temp2
= CatSPrint(RetVal
, Temp
, Supports
);
257 Configuration
= NULL
;
258 Status
= PciRootBridgeIo
->Configuration (PciRootBridgeIo
, (VOID
**) &Configuration
);
259 if (!EFI_ERROR(Status
) && Configuration
!= NULL
) {
260 Temp
= HiiGetString(mHandleParsingHiiHandle
, STRING_TOKEN(STR_PCIRB_DUMP_TITLE
), NULL
);
261 ASSERT (Temp
!= NULL
);
262 Temp2
= CatSPrint(RetVal
, Temp
, Supports
);
267 while (Configuration
->Desc
== ACPI_ADDRESS_SPACE_DESCRIPTOR
) {
269 switch (Configuration
->ResType
) {
270 case ACPI_ADDRESS_SPACE_TYPE_MEM
:
271 Temp
= HiiGetString(mHandleParsingHiiHandle
, STRING_TOKEN(STR_PCIRB_DUMP_MEM
), NULL
);
273 case ACPI_ADDRESS_SPACE_TYPE_IO
:
274 Temp
= HiiGetString(mHandleParsingHiiHandle
, STRING_TOKEN(STR_PCIRB_DUMP_IO
), NULL
);
276 case ACPI_ADDRESS_SPACE_TYPE_BUS
:
277 Temp
= HiiGetString(mHandleParsingHiiHandle
, STRING_TOKEN(STR_PCIRB_DUMP_BUS
), NULL
);
281 Temp2
= CatSPrint(RetVal
, L
"%s", Temp
);
288 Temp2
= CatSPrint(RetVal
,
289 L
"%H%02x %016lx %016lx %02x%N\r\n",
290 Configuration
->SpecificFlag
,
291 Configuration
->AddrRangeMin
,
292 Configuration
->AddrRangeMax
,
293 Configuration
->AddrSpaceGranularity
305 Function to dump information about SimpleTextOut.
307 This will allocate the return buffer from boot services pool.
309 @param[in] TheHandle The handle that has SimpleTextOut installed.
310 @param[in] Verbose TRUE for additional information, FALSE otherwise.
312 @retval A poitner to a string containing the information.
316 TxtOutProtocolDumpInformation(
317 IN CONST EFI_HANDLE TheHandle
,
318 IN CONST BOOLEAN Verbose
321 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*Dev
;
338 Status
= gBS
->HandleProtocol(
340 &gEfiSimpleTextOutProtocolGuid
,
343 ASSERT_EFI_ERROR(Status
);
344 ASSERT (Dev
!= NULL
&& Dev
->Mode
!= NULL
);
346 Size
= (Dev
->Mode
->MaxMode
+ 1) * 80;
347 RetVal
= AllocateZeroPool(Size
);
349 Temp
= HiiGetString(mHandleParsingHiiHandle
, STRING_TOKEN(STR_TXT_OUT_DUMP_HEADER
), NULL
);
351 UnicodeSPrint(RetVal
, Size
, Temp
, Dev
, Dev
->Mode
->Attribute
);
358 Temp
= HiiGetString(mHandleParsingHiiHandle
, STRING_TOKEN(STR_TXT_OUT_DUMP_LINE
), NULL
);
359 for (Index
= 0; Index
< Dev
->Mode
->MaxMode
; Index
++) {
360 Status
= Dev
->QueryMode (Dev
, Index
, &Col
, &Row
);
361 NewSize
= Size
- StrSize(RetVal
);
363 RetVal
+ StrLen(RetVal
),
365 Temp
== NULL
?L
"":Temp
,
366 Index
== Dev
->Mode
->Mode
? L
'*' : L
' ',
368 !EFI_ERROR(Status
)?(INTN
)Col
:-1,
369 !EFI_ERROR(Status
)?(INTN
)Row
:-1
376 STATIC CONST UINTN VersionStringSize
= 60;
379 Function to dump information about EfiDriverSupportedEfiVersion protocol.
381 This will allocate the return buffer from boot services pool.
383 @param[in] TheHandle The handle that has the protocol installed.
384 @param[in] Verbose TRUE for additional information, FALSE otherwise.
386 @retval A poitner to a string containing the information.
390 DriverEfiVersionProtocolDumpInformation(
391 IN CONST EFI_HANDLE TheHandle
,
392 IN CONST BOOLEAN Verbose
395 EFI_DRIVER_SUPPORTED_EFI_VERSION_PROTOCOL
*DriverEfiVersion
;
399 Status
= gBS
->HandleProtocol(
401 &gEfiDriverSupportedEfiVersionProtocolGuid
,
402 (VOID
**)&DriverEfiVersion
);
404 ASSERT_EFI_ERROR(Status
);
406 RetVal
= AllocateZeroPool(VersionStringSize
);
407 ASSERT(RetVal
!= NULL
);
408 UnicodeSPrint(RetVal
, VersionStringSize
, L
"0x%08x", DriverEfiVersion
->FirmwareVersion
);
413 Function to dump information about DevicePath protocol.
415 This will allocate the return buffer from boot services pool.
417 @param[in] TheHandle The handle that has the protocol installed.
418 @param[in] Verbose TRUE for additional information, FALSE otherwise.
420 @retval A poitner to a string containing the information.
424 DevicePathProtocolDumpInformation(
425 IN CONST EFI_HANDLE TheHandle
,
426 IN CONST BOOLEAN Verbose
429 EFI_DEVICE_PATH_PROTOCOL
*DevPath
;
435 Status
= gBS
->OpenProtocol(TheHandle
, &gEfiDevicePathProtocolGuid
, (VOID
**)&DevPath
, gImageHandle
, NULL
, EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
436 if (!EFI_ERROR(Status
)) {
438 // I cannot decide whether to allow shortcuts here (the second BOOLEAN on the next line)
440 Temp
= ConvertDevicePathToText(DevPath
, TRUE
, TRUE
);
441 gBS
->CloseProtocol(TheHandle
, &gEfiDevicePathProtocolGuid
, gImageHandle
, NULL
);
443 if (!Verbose
&& Temp
!= NULL
&& StrLen(Temp
) > 30) {
445 Temp2
= StrnCatGrow(&Temp2
, NULL
, Temp
+(StrLen(Temp
) - 30), 30);
453 // Put the information on the NT32 protocol GUIDs here so we are not dependant on the Nt32Pkg
455 #define LOCAL_EFI_WIN_NT_THUNK_PROTOCOL_GUID \
457 0x58c518b1, 0x76f3, 0x11d4, { 0xbc, 0xea, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 } \
460 #define LOCAL_EFI_WIN_NT_BUS_DRIVER_IO_PROTOCOL_GUID \
462 0x96eb4ad6, 0xa32a, 0x11d4, { 0xbc, 0xfd, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 } \
465 #define LOCAL_EFI_WIN_NT_SERIAL_PORT_GUID \
467 0xc95a93d, 0xa006, 0x11d4, { 0xbc, 0xfa, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 } \
469 STATIC CONST EFI_GUID WinNtThunkProtocolGuid
= LOCAL_EFI_WIN_NT_THUNK_PROTOCOL_GUID
;
470 STATIC CONST EFI_GUID WinNtIoProtocolGuid
= LOCAL_EFI_WIN_NT_BUS_DRIVER_IO_PROTOCOL_GUID
;
471 STATIC CONST EFI_GUID WinNtSerialPortGuid
= LOCAL_EFI_WIN_NT_SERIAL_PORT_GUID
;
473 STATIC CONST GUID_INFO_BLOCK mGuidStringListNT
[] = {
474 {STRING_TOKEN(STR_WINNT_THUNK
), (EFI_GUID
*)&WinNtThunkProtocolGuid
, NULL
},
475 {STRING_TOKEN(STR_WINNT_DRIVER_IO
), (EFI_GUID
*)&WinNtIoProtocolGuid
, NULL
},
476 {STRING_TOKEN(STR_WINNT_SERIAL_PORT
), (EFI_GUID
*)&WinNtSerialPortGuid
, NULL
},
477 {STRING_TOKEN(STR_UNKNOWN_DEVICE
), NULL
, NULL
},
480 STATIC CONST GUID_INFO_BLOCK mGuidStringList
[] = {
481 {STRING_TOKEN(STR_LOADED_IMAGE
), &gEfiLoadedImageProtocolGuid
, LoadedImageProtocolDumpInformation
},
482 {STRING_TOKEN(STR_DEVICE_PATH
), &gEfiDevicePathProtocolGuid
, DevicePathProtocolDumpInformation
},
483 {STRING_TOKEN(STR_IMAGE_PATH
), &gEfiLoadedImageDevicePathProtocolGuid
, DevicePathProtocolDumpInformation
},
484 {STRING_TOKEN(STR_DEVICE_PATH_UTIL
), &gEfiDevicePathUtilitiesProtocolGuid
, NULL
},
485 {STRING_TOKEN(STR_DEVICE_PATH_TXT
), &gEfiDevicePathToTextProtocolGuid
, NULL
},
486 {STRING_TOKEN(STR_DEVICE_PATH_FTXT
), &gEfiDevicePathFromTextProtocolGuid
, NULL
},
487 {STRING_TOKEN(STR_DEVICE_PATH_PC
), &gEfiPcAnsiGuid
, NULL
},
488 {STRING_TOKEN(STR_DEVICE_PATH_VT100
), &gEfiVT100Guid
, NULL
},
489 {STRING_TOKEN(STR_DEVICE_PATH_VT100P
), &gEfiVT100PlusGuid
, NULL
},
490 {STRING_TOKEN(STR_DEVICE_PATH_VTUTF8
), &gEfiVTUTF8Guid
, NULL
},
491 {STRING_TOKEN(STR_DRIVER_BINDING
), &gEfiDriverBindingProtocolGuid
, NULL
},
492 {STRING_TOKEN(STR_PLATFORM_OVERRIDE
), &gEfiPlatformDriverOverrideProtocolGuid
, NULL
},
493 {STRING_TOKEN(STR_BUS_OVERRIDE
), &gEfiBusSpecificDriverOverrideProtocolGuid
, NULL
},
494 {STRING_TOKEN(STR_DRIVER_DIAG
), &gEfiDriverDiagnosticsProtocolGuid
, NULL
},
495 {STRING_TOKEN(STR_DRIVER_DIAG2
), &gEfiDriverDiagnostics2ProtocolGuid
, NULL
},
496 {STRING_TOKEN(STR_DRIVER_CN
), &gEfiComponentNameProtocolGuid
, NULL
},
497 {STRING_TOKEN(STR_DRIVER_CN2
), &gEfiComponentName2ProtocolGuid
, NULL
},
498 {STRING_TOKEN(STR_PLAT_DRV_CFG
), &gEfiPlatformToDriverConfigurationProtocolGuid
, NULL
},
499 {STRING_TOKEN(STR_DRIVER_VERSION
), &gEfiDriverSupportedEfiVersionProtocolGuid
, DriverEfiVersionProtocolDumpInformation
},
500 {STRING_TOKEN(STR_TXT_IN
), &gEfiSimpleTextInProtocolGuid
, NULL
},
501 {STRING_TOKEN(STR_TXT_IN_EX
), &gEfiSimpleTextInputExProtocolGuid
, NULL
},
502 {STRING_TOKEN(STR_TXT_OUT
), &gEfiSimpleTextOutProtocolGuid
, TxtOutProtocolDumpInformation
},
503 {STRING_TOKEN(STR_SIM_POINTER
), &gEfiSimplePointerProtocolGuid
, NULL
},
504 {STRING_TOKEN(STR_ABS_POINTER
), &gEfiAbsolutePointerProtocolGuid
, NULL
},
505 {STRING_TOKEN(STR_SERIAL_IO
), &gEfiSerialIoProtocolGuid
, NULL
},
506 {STRING_TOKEN(STR_GRAPHICS_OUTPUT
), &gEfiGraphicsOutputProtocolGuid
, NULL
},
507 {STRING_TOKEN(STR_EDID_DISCOVERED
), &gEfiEdidDiscoveredProtocolGuid
, NULL
},
508 {STRING_TOKEN(STR_EDID_ACTIVE
), &gEfiEdidActiveProtocolGuid
, NULL
},
509 {STRING_TOKEN(STR_EDID_OVERRIDE
), &gEfiEdidOverrideProtocolGuid
, NULL
},
510 {STRING_TOKEN(STR_CON_IN
), &gEfiConsoleInDeviceGuid
, NULL
},
511 {STRING_TOKEN(STR_CON_OUT
), &gEfiConsoleOutDeviceGuid
, NULL
},
512 {STRING_TOKEN(STR_STD_ERR
), &gEfiStandardErrorDeviceGuid
, NULL
},
513 {STRING_TOKEN(STR_LOAD_FILE
), &gEfiLoadFileProtocolGuid
, NULL
},
514 {STRING_TOKEN(STR_LOAD_FILE2
), &gEfiLoadFile2ProtocolGuid
, NULL
},
515 {STRING_TOKEN(STR_SIMPLE_FILE_SYS
), &gEfiSimpleFileSystemProtocolGuid
, NULL
},
516 {STRING_TOKEN(STR_TAPE_IO
), &gEfiTapeIoProtocolGuid
, NULL
},
517 {STRING_TOKEN(STR_DISK_IO
), &gEfiDiskIoProtocolGuid
, NULL
},
518 {STRING_TOKEN(STR_BLK_IO
), &gEfiBlockIoProtocolGuid
, NULL
},
519 {STRING_TOKEN(STR_UC
), &gEfiUnicodeCollationProtocolGuid
, NULL
},
520 {STRING_TOKEN(STR_UC2
), &gEfiUnicodeCollation2ProtocolGuid
, NULL
},
521 {STRING_TOKEN(STR_PCIRB_IO
), &gEfiPciRootBridgeIoProtocolGuid
, PciRootBridgeIoDumpInformation
},
522 {STRING_TOKEN(STR_PCI_IO
), &gEfiPciIoProtocolGuid
, NULL
},
523 {STRING_TOKEN(STR_SCSI_PT
), &gEfiScsiPassThruProtocolGuid
, NULL
},
524 {STRING_TOKEN(STR_SCSI_IO
), &gEfiScsiIoProtocolGuid
, NULL
},
525 {STRING_TOKEN(STR_SCSI_PT_EXT
), &gEfiExtScsiPassThruProtocolGuid
, NULL
},
526 {STRING_TOKEN(STR_ISCSI
), &gEfiIScsiInitiatorNameProtocolGuid
, NULL
},
527 {STRING_TOKEN(STR_USB_IO
), &gEfiUsbIoProtocolGuid
, NULL
},
528 {STRING_TOKEN(STR_USB_HC
), &gEfiUsbHcProtocolGuid
, NULL
},
529 {STRING_TOKEN(STR_USB_HC2
), &gEfiUsb2HcProtocolGuid
, NULL
},
530 {STRING_TOKEN(STR_DEBUG_SUPPORT
), &gEfiDebugSupportProtocolGuid
, NULL
},
531 {STRING_TOKEN(STR_DEBUG_PORT
), &gEfiDebugPortProtocolGuid
, NULL
},
532 {STRING_TOKEN(STR_DECOMPRESS
), &gEfiDecompressProtocolGuid
, NULL
},
533 {STRING_TOKEN(STR_ACPI_TABLE
), &gEfiAcpiTableProtocolGuid
, NULL
},
534 {STRING_TOKEN(STR_EBC_INTERPRETER
), &gEfiEbcProtocolGuid
, NULL
},
535 {STRING_TOKEN(STR_SNP
), &gEfiSimpleNetworkProtocolGuid
, NULL
},
536 {STRING_TOKEN(STR_NII
), &gEfiNetworkInterfaceIdentifierProtocolGuid
, NULL
},
537 {STRING_TOKEN(STR_NII_31
), &gEfiNetworkInterfaceIdentifierProtocolGuid_31
, NULL
},
538 {STRING_TOKEN(STR_PXE_BC
), &gEfiPxeBaseCodeProtocolGuid
, NULL
},
539 {STRING_TOKEN(STR_PXE_CB
), &gEfiPxeBaseCodeCallbackProtocolGuid
, NULL
},
540 {STRING_TOKEN(STR_BIS
), &gEfiBisProtocolGuid
, NULL
},
541 {STRING_TOKEN(STR_MNP_SB
), &gEfiManagedNetworkServiceBindingProtocolGuid
, NULL
},
542 {STRING_TOKEN(STR_MNP
), &gEfiManagedNetworkProtocolGuid
, NULL
},
543 {STRING_TOKEN(STR_ARP_SB
), &gEfiArpServiceBindingProtocolGuid
, NULL
},
544 {STRING_TOKEN(STR_ARP
), &gEfiArpProtocolGuid
, NULL
},
545 {STRING_TOKEN(STR_DHCPV4_SB
), &gEfiDhcp4ServiceBindingProtocolGuid
, NULL
},
546 {STRING_TOKEN(STR_DHCPV4
), &gEfiDhcp4ProtocolGuid
, NULL
},
547 {STRING_TOKEN(STR_TCPV4_SB
), &gEfiTcp4ServiceBindingProtocolGuid
, NULL
},
548 {STRING_TOKEN(STR_TCPV4
), &gEfiTcp4ProtocolGuid
, NULL
},
549 {STRING_TOKEN(STR_IPV4_SB
), &gEfiIp4ServiceBindingProtocolGuid
, NULL
},
550 {STRING_TOKEN(STR_IPV4
), &gEfiIp4ProtocolGuid
, NULL
},
551 {STRING_TOKEN(STR_IPV4_CFG
), &gEfiIp4ConfigProtocolGuid
, NULL
},
552 {STRING_TOKEN(STR_SHELL_PARAMETERS
), &gEfiShellParametersProtocolGuid
, NULL
},
553 {STRING_TOKEN(STR_SHELL
), &gEfiShellProtocolGuid
, NULL
},
554 {STRING_TOKEN(STR_UDPV4_SB
), &gEfiUdp4ServiceBindingProtocolGuid
, NULL
},
555 {STRING_TOKEN(STR_UDPV4
), &gEfiUdp4ProtocolGuid
, NULL
},
556 {STRING_TOKEN(STR_MTFTPV4_SB
), &gEfiMtftp4ServiceBindingProtocolGuid
, NULL
},
557 {STRING_TOKEN(STR_MTFTPV4
), &gEfiMtftp4ProtocolGuid
, NULL
},
558 {STRING_TOKEN(STR_AUTH_INFO
), &gEfiAuthenticationInfoProtocolGuid
, NULL
},
559 {STRING_TOKEN(STR_HASH_SB
), &gEfiHashServiceBindingProtocolGuid
, NULL
},
560 {STRING_TOKEN(STR_HASH
), &gEfiHashProtocolGuid
, NULL
},
561 {STRING_TOKEN(STR_HII_FONT
), &gEfiHiiFontProtocolGuid
, NULL
},
562 {STRING_TOKEN(STR_HII_STRING
), &gEfiHiiStringProtocolGuid
, NULL
},
563 {STRING_TOKEN(STR_HII_IMAGE
), &gEfiHiiImageProtocolGuid
, NULL
},
564 {STRING_TOKEN(STR_HII_DATABASE
), &gEfiHiiDatabaseProtocolGuid
, NULL
},
565 {STRING_TOKEN(STR_HII_CONFIG_ROUT
), &gEfiHiiConfigRoutingProtocolGuid
, NULL
},
566 {STRING_TOKEN(STR_HII_CONFIG_ACC
), &gEfiHiiConfigAccessProtocolGuid
, NULL
},
567 {STRING_TOKEN(STR_HII_FORM_BROWSER2
), &gEfiFormBrowser2ProtocolGuid
, NULL
},
568 {STRING_TOKEN(STR_DRIVER_FAM_OVERRIDE
), &gEfiDriverFamilyOverrideProtocolGuid
, NULL
},
569 {STRING_TOKEN(STR_PCD
), &gPcdProtocolGuid
, NULL
},
570 {STRING_TOKEN(STR_TCG
), &gEfiTcgProtocolGuid
, NULL
},
571 {STRING_TOKEN(STR_HII_PACKAGE_LIST
), &gEfiHiiPackageListProtocolGuid
, NULL
},
574 // the ones under this are deprecated by the current UEFI Spec, but may be found anyways...
576 {STRING_TOKEN(STR_SHELL_INTERFACE
), &gEfiShellInterfaceGuid
, NULL
},
577 {STRING_TOKEN(STR_SHELL_ENV2
), &gEfiShellEnvironment2Guid
, NULL
},
578 {STRING_TOKEN(STR_SHELL_ENV
), &gEfiShellEnvironment2Guid
, NULL
},
579 {STRING_TOKEN(STR_DEVICE_IO
), &gEfiDeviceIoProtocolGuid
, NULL
},
580 {STRING_TOKEN(STR_UGA_DRAW
), &gEfiUgaDrawProtocolGuid
, NULL
},
581 {STRING_TOKEN(STR_UGA_IO
), &gEfiUgaIoProtocolGuid
, NULL
},
582 {STRING_TOKEN(STR_ESP
), &gEfiPartTypeSystemPartGuid
, NULL
},
583 {STRING_TOKEN(STR_GPT_NBR
), &gEfiPartTypeLegacyMbrGuid
, NULL
},
584 {STRING_TOKEN(STR_DRIVER_CONFIG
), &gEfiDriverConfigurationProtocolGuid
, NULL
},
585 {STRING_TOKEN(STR_DRIVER_CONFIG2
), &gEfiDriverConfiguration2ProtocolGuid
, NULL
},
588 // the ones under this are GUID identified structs, not protocols
590 {STRING_TOKEN(STR_FILE_INFO
), &gEfiFileInfoGuid
, NULL
},
591 {STRING_TOKEN(STR_FILE_SYS_INFO
), &gEfiFileSystemInfoGuid
, NULL
},
594 // the ones under this are misc GUIDS.
596 {STRING_TOKEN(STR_EFI_GLOBAL_VARIABLE
), &gEfiGlobalVariableGuid
, NULL
},
601 {STRING_TOKEN(STR_IP6_SB
), &gEfiIp6ServiceBindingProtocolGuid
, NULL
},
602 {STRING_TOKEN(STR_IP6
), &gEfiIp6ProtocolGuid
, NULL
},
603 {STRING_TOKEN(STR_IP6_CONFIG
), &gEfiIp6ConfigProtocolGuid
, NULL
},
604 {STRING_TOKEN(STR_MTFTP6_SB
), &gEfiMtftp6ServiceBindingProtocolGuid
, NULL
},
605 {STRING_TOKEN(STR_MTFTP6
), &gEfiMtftp6ProtocolGuid
, NULL
},
606 {STRING_TOKEN(STR_DHCP6_SB
), &gEfiDhcp6ServiceBindingProtocolGuid
, NULL
},
607 {STRING_TOKEN(STR_DHCP6
), &gEfiDhcp6ProtocolGuid
, NULL
},
608 {STRING_TOKEN(STR_UDP6_SB
), &gEfiUdp6ServiceBindingProtocolGuid
, NULL
},
609 {STRING_TOKEN(STR_UDP6
), &gEfiUdp6ProtocolGuid
, NULL
},
610 {STRING_TOKEN(STR_TCP6_SB
), &gEfiTcp6ServiceBindingProtocolGuid
, NULL
},
611 {STRING_TOKEN(STR_TCP6
), &gEfiTcp6ProtocolGuid
, NULL
},
612 {STRING_TOKEN(STR_VLAN_CONFIG
), &gEfiVlanConfigProtocolGuid
, NULL
},
613 {STRING_TOKEN(STR_EAP
), &gEfiEapProtocolGuid
, NULL
},
614 {STRING_TOKEN(STR_EAP_MGMT
), &gEfiEapManagementProtocolGuid
, NULL
},
615 {STRING_TOKEN(STR_FTP4_SB
), &gEfiFtp4ServiceBindingProtocolGuid
, NULL
},
616 {STRING_TOKEN(STR_FTP4
), &gEfiFtp4ProtocolGuid
, NULL
},
617 {STRING_TOKEN(STR_IP_SEC_CONFIG
), &gEfiIpSecConfigProtocolGuid
, NULL
},
618 {STRING_TOKEN(STR_DH
), &gEfiDriverHealthProtocolGuid
, NULL
},
619 {STRING_TOKEN(STR_DEF_IMG_LOAD
), &gEfiDeferredImageLoadProtocolGuid
, NULL
},
620 {STRING_TOKEN(STR_USER_CRED
), &gEfiUserCredentialProtocolGuid
, NULL
},
621 {STRING_TOKEN(STR_USER_MNGR
), &gEfiUserManagerProtocolGuid
, NULL
},
622 {STRING_TOKEN(STR_ATA_PASS_THRU
), &gEfiAtaPassThruProtocolGuid
, NULL
},
627 {STRING_TOKEN(STR_FW_MGMT
), &gEfiFirmwareManagementProtocolGuid
, NULL
},
628 {STRING_TOKEN(STR_IP_SEC
), &gEfiIpSecProtocolGuid
, NULL
},
629 {STRING_TOKEN(STR_IP_SEC2
), &gEfiIpSec2ProtocolGuid
, NULL
},
634 {STRING_TOKEN(STR_KMS
), &gEfiKmsProtocolGuid
, NULL
},
635 {STRING_TOKEN(STR_BLK_IO2
), &gEfiBlockIo2ProtocolGuid
, NULL
},
636 {STRING_TOKEN(STR_SSC
), &gEfiStorageSecurityCommandProtocolGuid
, NULL
},
637 {STRING_TOKEN(STR_UCRED2
), &gEfiUserCredential2ProtocolGuid
, NULL
},
642 {STRING_TOKEN(STR_DISK_IO2
), &gEfiDiskIo2ProtocolGuid
, NULL
},
647 {STRING_TOKEN(STR_IDE_CONT_INIT
), &gEfiIdeControllerInitProtocolGuid
, NULL
},
652 {STRING_TOKEN(STR_UNKNOWN_DEVICE
), NULL
, NULL
},
656 Function to get the node for a protocol or struct from it's GUID.
658 if Guid is NULL, then ASSERT.
660 @param[in] Guid The GUID to look for the name of.
664 CONST GUID_INFO_BLOCK
*
666 InternalShellGetNodeFromGuid(
667 IN CONST EFI_GUID
* Guid
670 CONST GUID_INFO_BLOCK
*ListWalker
;
672 ASSERT(Guid
!= NULL
);
674 if (PcdGetBool(PcdShellIncludeNtGuids
)) {
675 for (ListWalker
= mGuidStringListNT
; ListWalker
!= NULL
&& ListWalker
->GuidId
!= NULL
; ListWalker
++) {
676 if (CompareGuid(ListWalker
->GuidId
, Guid
)) {
681 for (ListWalker
= mGuidStringList
; ListWalker
!= NULL
&& ListWalker
->GuidId
!= NULL
; ListWalker
++) {
682 if (CompareGuid(ListWalker
->GuidId
, Guid
)) {
690 Function to get the name of a protocol or struct from it's GUID.
692 if Guid is NULL, then ASSERT.
694 @param[in] Guid The GUID to look for the name of.
695 @param[in] Lang The language to use.
697 @return pointer to string of the name. The caller
698 is responsible to free this memory.
702 GetStringNameFromGuid(
703 IN CONST EFI_GUID
*Guid
,
704 IN CONST CHAR8
*Lang OPTIONAL
707 CONST GUID_INFO_BLOCK
*Id
;
709 Id
= InternalShellGetNodeFromGuid(Guid
);
710 return (HiiGetString(mHandleParsingHiiHandle
, Id
->StringId
, Lang
));
714 Function to dump protocol information from a handle.
716 This function will return a allocated string buffer containing the
717 information. The caller is responsible for freeing the memory.
719 If Guid is NULL, ASSERT().
720 If TheHandle is NULL, ASSERT().
722 @param[in] TheHandle The handle to dump information from.
723 @param[in] Guid The GUID of the protocol to dump.
724 @param[in] Verbose TRUE for extra info. FALSE otherwise.
726 @return The pointer to string.
727 @retval NULL An error was encountered.
731 GetProtocolInformationDump(
732 IN CONST EFI_HANDLE TheHandle
,
733 IN CONST EFI_GUID
*Guid
,
734 IN CONST BOOLEAN Verbose
737 CONST GUID_INFO_BLOCK
*Id
;
739 ASSERT(TheHandle
!= NULL
);
740 ASSERT(Guid
!= NULL
);
742 if (TheHandle
== NULL
|| Guid
== NULL
) {
746 Id
= InternalShellGetNodeFromGuid(Guid
);
747 if (Id
!= NULL
&& Id
->DumpInfo
!= NULL
) {
748 return (Id
->DumpInfo(TheHandle
, Verbose
));
754 Function to get the Guid for a protocol or struct based on it's string name.
756 @param[in] Name The pointer to the string name.
757 @param[in] Lang The pointer to the language code.
758 @param[in] Guid The pointer to the Guid.
760 @retval EFI_SUCCESS The operation was sucessful.
764 GetGuidFromStringName(
765 IN CONST CHAR16
*Name
,
766 IN CONST CHAR8
*Lang OPTIONAL
,
770 CONST GUID_INFO_BLOCK
*ListWalker
;
773 ASSERT(Guid
!= NULL
);
775 return (EFI_INVALID_PARAMETER
);
779 if (PcdGetBool(PcdShellIncludeNtGuids
)) {
780 for (ListWalker
= mGuidStringListNT
; ListWalker
!= NULL
&& ListWalker
->GuidId
!= NULL
; ListWalker
++) {
781 String
= HiiGetString(mHandleParsingHiiHandle
, ListWalker
->StringId
, Lang
);
782 if (Name
!= NULL
&& String
!= NULL
&& StringNoCaseCompare (&Name
, &String
) == 0) {
783 *Guid
= ListWalker
->GuidId
;
785 SHELL_FREE_NON_NULL(String
);
787 return (EFI_SUCCESS
);
791 for (ListWalker
= mGuidStringList
; ListWalker
!= NULL
&& ListWalker
->GuidId
!= NULL
; ListWalker
++) {
792 String
= HiiGetString(mHandleParsingHiiHandle
, ListWalker
->StringId
, Lang
);
793 if (Name
!= NULL
&& String
!= NULL
&& StringNoCaseCompare (&Name
, &String
) == 0) {
794 *Guid
= ListWalker
->GuidId
;
796 SHELL_FREE_NON_NULL(String
);
798 return (EFI_SUCCESS
);
801 return (EFI_NOT_FOUND
);
805 Get best support language for this driver.
807 First base on the user input language to search, second base on the current
808 platform used language to search, third get the first language from the
809 support language list. The caller need to free the buffer of the best language.
811 @param[in] SupportedLanguages The support languages for this driver.
812 @param[in] InputLanguage The user input language.
813 @param[in] Iso639Language Whether get language for ISO639.
815 @return The best support language for this driver.
819 GetBestLanguageForDriver (
820 IN CONST CHAR8
*SupportedLanguages
,
821 IN CONST CHAR8
*InputLanguage
,
822 IN BOOLEAN Iso639Language
825 CHAR8
*LanguageVariable
;
828 LanguageVariable
= GetVariable (Iso639Language
? L
"Lang" : L
"PlatformLang", &gEfiGlobalVariableGuid
);
830 BestLanguage
= GetBestLanguage(
833 (InputLanguage
!= NULL
) ? InputLanguage
: "",
834 (LanguageVariable
!= NULL
) ? LanguageVariable
: "",
839 if (LanguageVariable
!= NULL
) {
840 FreePool (LanguageVariable
);
847 Function to retrieve the driver name (if possible) from the ComponentName or
848 ComponentName2 protocol
850 @param[in] TheHandle The driver handle to get the name of.
851 @param[in] Language The language to use.
853 @retval NULL The name could not be found.
854 @return A pointer to the string name. Do not de-allocate the memory.
858 GetStringNameFromHandle(
859 IN CONST EFI_HANDLE TheHandle
,
860 IN CONST CHAR8
*Language
863 EFI_COMPONENT_NAME2_PROTOCOL
*CompNameStruct
;
870 Status
= gBS
->OpenProtocol(
872 &gEfiComponentName2ProtocolGuid
,
873 (VOID
**)&CompNameStruct
,
876 EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
877 if (!EFI_ERROR(Status
)) {
878 BestLang
= GetBestLanguageForDriver (CompNameStruct
->SupportedLanguages
, Language
, FALSE
);
879 Status
= CompNameStruct
->GetDriverName(CompNameStruct
, BestLang
, &RetVal
);
880 if (BestLang
!= NULL
) {
884 if (!EFI_ERROR(Status
)) {
888 Status
= gBS
->OpenProtocol(
890 &gEfiComponentNameProtocolGuid
,
891 (VOID
**)&CompNameStruct
,
894 EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
895 if (!EFI_ERROR(Status
)) {
896 BestLang
= GetBestLanguageForDriver (CompNameStruct
->SupportedLanguages
, Language
, FALSE
);
897 Status
= CompNameStruct
->GetDriverName(CompNameStruct
, BestLang
, &RetVal
);
898 if (BestLang
!= NULL
) {
901 if (!EFI_ERROR(Status
)) {
909 Function to initialize the file global mHandleList object for use in
910 vonverting handles to index and index to handle.
912 @retval EFI_SUCCESS The operation was successful.
916 InternalShellInitHandleList(
921 EFI_HANDLE
*HandleBuffer
;
923 HANDLE_LIST
*ListWalker
;
925 if (mHandleList
.NextIndex
!= 0) {
928 InitializeListHead(&mHandleList
.List
.Link
);
929 mHandleList
.NextIndex
= 1;
930 Status
= gBS
->LocateHandleBuffer (
937 ASSERT_EFI_ERROR(Status
);
938 if (EFI_ERROR(Status
)) {
941 for (mHandleList
.NextIndex
= 1 ; mHandleList
.NextIndex
<= HandleCount
; mHandleList
.NextIndex
++){
942 ListWalker
= AllocateZeroPool(sizeof(HANDLE_LIST
));
943 ASSERT(ListWalker
!= NULL
);
944 ListWalker
->TheHandle
= HandleBuffer
[mHandleList
.NextIndex
-1];
945 ListWalker
->TheIndex
= mHandleList
.NextIndex
;
946 InsertTailList(&mHandleList
.List
.Link
,&ListWalker
->Link
);
948 FreePool(HandleBuffer
);
949 return (EFI_SUCCESS
);
953 Function to retrieve the human-friendly index of a given handle. If the handle
954 does not have a index one will be automatically assigned. The index value is valid
955 until the termination of the shell application.
957 @param[in] TheHandle The handle to retrieve an index for.
959 @retval 0 A memory allocation failed.
960 @return The index of the handle.
965 ConvertHandleToHandleIndex(
966 IN CONST EFI_HANDLE TheHandle
970 EFI_GUID
**ProtocolBuffer
;
972 HANDLE_LIST
*ListWalker
;
974 if (TheHandle
== NULL
) {
978 InternalShellInitHandleList();
980 for (ListWalker
= (HANDLE_LIST
*)GetFirstNode(&mHandleList
.List
.Link
)
981 ; !IsNull(&mHandleList
.List
.Link
,&ListWalker
->Link
)
982 ; ListWalker
= (HANDLE_LIST
*)GetNextNode(&mHandleList
.List
.Link
,&ListWalker
->Link
)
984 if (ListWalker
->TheHandle
== TheHandle
) {
986 // Verify that TheHandle is still present in the Handle Database
988 Status
= gBS
->ProtocolsPerHandle(TheHandle
, &ProtocolBuffer
, &ProtocolCount
);
989 if (EFI_ERROR (Status
)) {
991 // TheHandle is not present in the Handle Database, so delete from the handle list
993 RemoveEntryList (&ListWalker
->Link
);
996 FreePool (ProtocolBuffer
);
997 return (ListWalker
->TheIndex
);
1002 // Verify that TheHandle is valid handle
1004 Status
= gBS
->ProtocolsPerHandle(TheHandle
, &ProtocolBuffer
, &ProtocolCount
);
1005 if (EFI_ERROR (Status
)) {
1007 // TheHandle is not valid, so do not add to handle list
1011 FreePool (ProtocolBuffer
);
1013 ListWalker
= AllocateZeroPool(sizeof(HANDLE_LIST
));
1014 ASSERT(ListWalker
!= NULL
);
1015 ListWalker
->TheHandle
= TheHandle
;
1016 ListWalker
->TheIndex
= mHandleList
.NextIndex
++;
1017 InsertTailList(&mHandleList
.List
.Link
,&ListWalker
->Link
);
1018 return (ListWalker
->TheIndex
);
1024 Function to retrieve the EFI_HANDLE from the human-friendly index.
1026 @param[in] TheIndex The index to retrieve the EFI_HANDLE for.
1028 @retval NULL The index was invalid.
1029 @return The EFI_HANDLE that index represents.
1034 ConvertHandleIndexToHandle(
1035 IN CONST UINTN TheIndex
1039 EFI_GUID
**ProtocolBuffer
;
1040 UINTN ProtocolCount
;
1041 HANDLE_LIST
*ListWalker
;
1043 InternalShellInitHandleList();
1045 if (TheIndex
>= mHandleList
.NextIndex
) {
1049 for (ListWalker
= (HANDLE_LIST
*)GetFirstNode(&mHandleList
.List
.Link
)
1050 ; !IsNull(&mHandleList
.List
.Link
,&ListWalker
->Link
)
1051 ; ListWalker
= (HANDLE_LIST
*)GetNextNode(&mHandleList
.List
.Link
,&ListWalker
->Link
)
1053 if (ListWalker
->TheIndex
== TheIndex
&& ListWalker
->TheHandle
!= NULL
) {
1055 // Verify that LinkWalker->TheHandle is valid handle
1057 Status
= gBS
->ProtocolsPerHandle(ListWalker
->TheHandle
, &ProtocolBuffer
, &ProtocolCount
);
1058 if (EFI_ERROR (Status
)) {
1060 // TheHandle is not valid, so do not add to handle list
1062 ListWalker
->TheHandle
= NULL
;
1064 return (ListWalker
->TheHandle
);
1071 Gets all the related EFI_HANDLEs based on the mask supplied.
1073 This function scans all EFI_HANDLES in the UEFI environment's handle database
1074 and returns the ones with the specified relationship (Mask) to the specified
1077 If both DriverBindingHandle and ControllerHandle are NULL, then ASSERT.
1078 If MatchingHandleCount is NULL, then ASSERT.
1080 If MatchingHandleBuffer is not NULL upon a successful return the memory must be
1083 @param[in] DriverBindingHandle The handle with Driver Binding protocol on it.
1084 @param[in] ControllerHandle The handle with Device Path protocol on it.
1085 @param[in] MatchingHandleCount The pointer to UINTN that specifies the number of HANDLES in
1086 MatchingHandleBuffer.
1087 @param[out] MatchingHandleBuffer On a successful return, a buffer of MatchingHandleCount
1088 EFI_HANDLEs with a terminating NULL EFI_HANDLE.
1089 @param[out] HandleType An array of type information.
1091 @retval EFI_SUCCESS The operation was successful, and any related handles
1092 are in MatchingHandleBuffer.
1093 @retval EFI_NOT_FOUND No matching handles were found.
1094 @retval EFI_INVALID_PARAMETER A parameter was invalid or out of range.
1098 ParseHandleDatabaseByRelationshipWithType (
1099 IN CONST EFI_HANDLE DriverBindingHandle OPTIONAL
,
1100 IN CONST EFI_HANDLE ControllerHandle OPTIONAL
,
1101 IN UINTN
*HandleCount
,
1102 OUT EFI_HANDLE
**HandleBuffer
,
1103 OUT UINTN
**HandleType
1108 EFI_GUID
**ProtocolGuidArray
;
1110 UINTN ProtocolIndex
;
1111 EFI_OPEN_PROTOCOL_INFORMATION_ENTRY
*OpenInfo
;
1112 UINTN OpenInfoCount
;
1113 UINTN OpenInfoIndex
;
1115 INTN DriverBindingHandleIndex
;
1117 ASSERT(HandleCount
!= NULL
);
1118 ASSERT(HandleBuffer
!= NULL
);
1119 ASSERT(HandleType
!= NULL
);
1120 ASSERT(DriverBindingHandle
!= NULL
|| ControllerHandle
!= NULL
);
1123 *HandleBuffer
= NULL
;
1127 // Retrieve the list of all handles from the handle database
1129 Status
= gBS
->LocateHandleBuffer (
1136 if (EFI_ERROR (Status
)) {
1140 *HandleType
= AllocateZeroPool (*HandleCount
* sizeof (UINTN
));
1141 ASSERT(*HandleType
!= NULL
);
1143 DriverBindingHandleIndex
= -1;
1144 for (HandleIndex
= 0; HandleIndex
< *HandleCount
; HandleIndex
++) {
1145 if (DriverBindingHandle
!= NULL
&& (*HandleBuffer
)[HandleIndex
] == DriverBindingHandle
) {
1146 DriverBindingHandleIndex
= (INTN
)HandleIndex
;
1150 for (HandleIndex
= 0; HandleIndex
< *HandleCount
; HandleIndex
++) {
1152 // Retrieve the list of all the protocols on each handle
1154 Status
= gBS
->ProtocolsPerHandle (
1155 (*HandleBuffer
)[HandleIndex
],
1159 if (EFI_ERROR (Status
)) {
1163 for (ProtocolIndex
= 0; ProtocolIndex
< ArrayCount
; ProtocolIndex
++) {
1166 // Set the bit describing what this handle has
1168 if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiLoadedImageProtocolGuid
) ) {
1169 (*HandleType
)[HandleIndex
] |= HR_IMAGE_HANDLE
;
1170 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiDriverBindingProtocolGuid
) ) {
1171 (*HandleType
)[HandleIndex
] |= HR_DRIVER_BINDING_HANDLE
;
1172 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiDriverConfiguration2ProtocolGuid
)) {
1173 (*HandleType
)[HandleIndex
] |= HR_DRIVER_CONFIGURATION_HANDLE
;
1174 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiDriverConfigurationProtocolGuid
) ) {
1175 (*HandleType
)[HandleIndex
] |= HR_DRIVER_CONFIGURATION_HANDLE
;
1176 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiDriverDiagnostics2ProtocolGuid
) ) {
1177 (*HandleType
)[HandleIndex
] |= HR_DRIVER_DIAGNOSTICS_HANDLE
;
1178 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiDriverDiagnosticsProtocolGuid
) ) {
1179 (*HandleType
)[HandleIndex
] |= HR_DRIVER_DIAGNOSTICS_HANDLE
;
1180 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiComponentName2ProtocolGuid
) ) {
1181 (*HandleType
)[HandleIndex
] |= HR_COMPONENT_NAME_HANDLE
;
1182 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiComponentNameProtocolGuid
) ) {
1183 (*HandleType
)[HandleIndex
] |= HR_COMPONENT_NAME_HANDLE
;
1184 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiDevicePathProtocolGuid
) ) {
1185 (*HandleType
)[HandleIndex
] |= HR_DEVICE_HANDLE
;
1188 ASSERT((*HandleType
)[HandleIndex
] == (*HandleType
)[HandleIndex
]);
1192 // Retrieve the list of agents that have opened each protocol
1194 Status
= gBS
->OpenProtocolInformation (
1195 (*HandleBuffer
)[HandleIndex
],
1196 ProtocolGuidArray
[ProtocolIndex
],
1200 if (EFI_ERROR (Status
)) {
1204 if (ControllerHandle
== NULL
) {
1206 // ControllerHandle == NULL and DriverBindingHandle != NULL.
1207 // Return information on all the controller handles that the driver specified by DriverBindingHandle is managing
1209 for (OpenInfoIndex
= 0; OpenInfoIndex
< OpenInfoCount
; OpenInfoIndex
++) {
1210 if (OpenInfo
[OpenInfoIndex
].AgentHandle
== DriverBindingHandle
&& (OpenInfo
[OpenInfoIndex
].Attributes
& EFI_OPEN_PROTOCOL_BY_DRIVER
) != 0) {
1211 (*HandleType
)[HandleIndex
] |= (HR_DEVICE_HANDLE
| HR_CONTROLLER_HANDLE
);
1212 if (DriverBindingHandleIndex
!= -1) {
1213 (*HandleType
)[DriverBindingHandleIndex
] |= HR_DEVICE_DRIVER
;
1216 if (OpenInfo
[OpenInfoIndex
].AgentHandle
== DriverBindingHandle
&& (OpenInfo
[OpenInfoIndex
].Attributes
& EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
) != 0) {
1217 (*HandleType
)[HandleIndex
] |= (HR_DEVICE_HANDLE
| HR_CONTROLLER_HANDLE
);
1218 if (DriverBindingHandleIndex
!= -1) {
1219 (*HandleType
)[DriverBindingHandleIndex
] |= (HR_BUS_DRIVER
| HR_DEVICE_DRIVER
);
1221 for (ChildIndex
= 0; ChildIndex
< *HandleCount
; ChildIndex
++) {
1222 if (OpenInfo
[OpenInfoIndex
].ControllerHandle
== (*HandleBuffer
)[ChildIndex
]) {
1223 (*HandleType
)[ChildIndex
] |= (HR_DEVICE_HANDLE
| HR_CHILD_HANDLE
);
1229 if (DriverBindingHandle
== NULL
&& ControllerHandle
!= NULL
) {
1230 if (ControllerHandle
== (*HandleBuffer
)[HandleIndex
]) {
1231 (*HandleType
)[HandleIndex
] |= (HR_DEVICE_HANDLE
| HR_CONTROLLER_HANDLE
);
1232 for (OpenInfoIndex
= 0; OpenInfoIndex
< OpenInfoCount
; OpenInfoIndex
++) {
1233 if ((OpenInfo
[OpenInfoIndex
].Attributes
& EFI_OPEN_PROTOCOL_BY_DRIVER
) != 0) {
1234 for (ChildIndex
= 0; ChildIndex
< *HandleCount
; ChildIndex
++) {
1235 if (OpenInfo
[OpenInfoIndex
].AgentHandle
== (*HandleBuffer
)[ChildIndex
]) {
1236 (*HandleType
)[ChildIndex
] |= HR_DEVICE_DRIVER
;
1240 if ((OpenInfo
[OpenInfoIndex
].Attributes
& EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
) != 0) {
1241 for (ChildIndex
= 0; ChildIndex
< *HandleCount
; ChildIndex
++) {
1242 if (OpenInfo
[OpenInfoIndex
].AgentHandle
== (*HandleBuffer
)[ChildIndex
]) {
1243 (*HandleType
)[ChildIndex
] |= (HR_BUS_DRIVER
| HR_DEVICE_DRIVER
);
1245 if (OpenInfo
[OpenInfoIndex
].ControllerHandle
== (*HandleBuffer
)[ChildIndex
]) {
1246 (*HandleType
)[ChildIndex
] |= (HR_DEVICE_HANDLE
| HR_CHILD_HANDLE
);
1252 for (OpenInfoIndex
= 0; OpenInfoIndex
< OpenInfoCount
; OpenInfoIndex
++) {
1253 if ((OpenInfo
[OpenInfoIndex
].Attributes
& EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
) != 0) {
1254 if (OpenInfo
[OpenInfoIndex
].ControllerHandle
== ControllerHandle
) {
1255 (*HandleType
)[HandleIndex
] |= (HR_DEVICE_HANDLE
| HR_PARENT_HANDLE
);
1261 if (DriverBindingHandle
!= NULL
&& ControllerHandle
!= NULL
) {
1262 if (ControllerHandle
== (*HandleBuffer
)[HandleIndex
]) {
1263 (*HandleType
)[HandleIndex
] |= (HR_DEVICE_HANDLE
| HR_CONTROLLER_HANDLE
);
1264 for (OpenInfoIndex
= 0; OpenInfoIndex
< OpenInfoCount
; OpenInfoIndex
++) {
1265 if ((OpenInfo
[OpenInfoIndex
].Attributes
& EFI_OPEN_PROTOCOL_BY_DRIVER
) != 0) {
1266 if (OpenInfo
[OpenInfoIndex
].AgentHandle
== DriverBindingHandle
) {
1267 if (DriverBindingHandleIndex
!= -1) {
1268 (*HandleType
)[DriverBindingHandleIndex
] |= HR_DEVICE_DRIVER
;
1272 if ((OpenInfo
[OpenInfoIndex
].Attributes
& EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
) != 0) {
1273 if (OpenInfo
[OpenInfoIndex
].AgentHandle
== DriverBindingHandle
) {
1274 for (ChildIndex
= 0; ChildIndex
< *HandleCount
; ChildIndex
++) {
1275 if (OpenInfo
[OpenInfoIndex
].ControllerHandle
== (*HandleBuffer
)[ChildIndex
]) {
1276 (*HandleType
)[ChildIndex
] |= (HR_DEVICE_HANDLE
| HR_CHILD_HANDLE
);
1281 for (ChildIndex
= 0; ChildIndex
< *HandleCount
; ChildIndex
++) {
1282 if (OpenInfo
[OpenInfoIndex
].AgentHandle
== (*HandleBuffer
)[ChildIndex
]) {
1283 (*HandleType
)[ChildIndex
] |= (HR_BUS_DRIVER
| HR_DEVICE_DRIVER
);
1289 for (OpenInfoIndex
= 0; OpenInfoIndex
< OpenInfoCount
; OpenInfoIndex
++) {
1290 if ((OpenInfo
[OpenInfoIndex
].Attributes
& EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
) != 0) {
1291 if (OpenInfo
[OpenInfoIndex
].ControllerHandle
== ControllerHandle
) {
1292 (*HandleType
)[HandleIndex
] |= (HR_DEVICE_HANDLE
| HR_PARENT_HANDLE
);
1298 FreePool (OpenInfo
);
1300 FreePool (ProtocolGuidArray
);
1306 Gets all the related EFI_HANDLEs based on the single EFI_HANDLE and the mask
1309 This function will scan all EFI_HANDLES in the UEFI environment's handle database
1310 and return all the ones with the specified relationship (Mask) to the specified
1313 If both DriverBindingHandle and ControllerHandle are NULL, then ASSERT.
1314 If MatchingHandleCount is NULL, then ASSERT.
1316 If MatchingHandleBuffer is not NULL upon a sucessful return the memory must be
1319 @param[in] DriverBindingHandle Handle to a object with Driver Binding protocol
1321 @param[in] ControllerHandle Handle to a device with Device Path protocol on it.
1322 @param[in] Mask Mask of what relationship(s) is desired.
1323 @param[in] MatchingHandleCount Poitner to UINTN specifying number of HANDLES in
1324 MatchingHandleBuffer.
1325 @param[out] MatchingHandleBuffer On a sucessful return a buffer of MatchingHandleCount
1326 EFI_HANDLEs and a terminating NULL EFI_HANDLE.
1328 @retval EFI_SUCCESS The operation was sucessful and any related handles
1329 are in MatchingHandleBuffer;
1330 @retval EFI_NOT_FOUND No matching handles were found.
1331 @retval EFI_INVALID_PARAMETER A parameter was invalid or out of range.
1335 ParseHandleDatabaseByRelationship (
1336 IN CONST EFI_HANDLE DriverBindingHandle OPTIONAL
,
1337 IN CONST EFI_HANDLE ControllerHandle OPTIONAL
,
1338 IN CONST UINTN Mask
,
1339 IN UINTN
*MatchingHandleCount
,
1340 OUT EFI_HANDLE
**MatchingHandleBuffer OPTIONAL
1345 EFI_HANDLE
*HandleBuffer
;
1349 ASSERT(MatchingHandleCount
!= NULL
);
1350 ASSERT(DriverBindingHandle
!= NULL
|| ControllerHandle
!= NULL
);
1352 if ((Mask
& HR_VALID_MASK
) != Mask
) {
1353 return (EFI_INVALID_PARAMETER
);
1356 if ((Mask
& HR_CHILD_HANDLE
) != 0 && DriverBindingHandle
== NULL
) {
1357 return (EFI_INVALID_PARAMETER
);
1360 *MatchingHandleCount
= 0;
1361 if (MatchingHandleBuffer
!= NULL
) {
1362 *MatchingHandleBuffer
= NULL
;
1365 HandleBuffer
= NULL
;
1368 Status
= ParseHandleDatabaseByRelationshipWithType (
1369 DriverBindingHandle
,
1375 if (!EFI_ERROR (Status
)) {
1377 // Count the number of handles that match the attributes in Mask
1379 for (HandleIndex
= 0; HandleIndex
< HandleCount
; HandleIndex
++) {
1380 if ((HandleType
[HandleIndex
] & Mask
) == Mask
) {
1381 (*MatchingHandleCount
)++;
1385 // If no handles match the attributes in Mask then return EFI_NOT_FOUND
1387 if (*MatchingHandleCount
== 0) {
1388 Status
= EFI_NOT_FOUND
;
1391 if (MatchingHandleBuffer
== NULL
) {
1393 // Someone just wanted the count...
1395 Status
= EFI_SUCCESS
;
1398 // Allocate a handle buffer for the number of handles that matched the attributes in Mask
1400 *MatchingHandleBuffer
= AllocateZeroPool ((*MatchingHandleCount
+1)* sizeof (EFI_HANDLE
));
1401 ASSERT(*MatchingHandleBuffer
!= NULL
);
1403 for (HandleIndex
= 0,*MatchingHandleCount
= 0
1404 ; HandleIndex
< HandleCount
1408 // Fill the allocated buffer with the handles that matched the attributes in Mask
1410 if ((HandleType
[HandleIndex
] & Mask
) == Mask
) {
1411 (*MatchingHandleBuffer
)[(*MatchingHandleCount
)++] = HandleBuffer
[HandleIndex
];
1416 // Make the last one NULL
1418 (*MatchingHandleBuffer
)[*MatchingHandleCount
] = NULL
;
1420 Status
= EFI_SUCCESS
;
1421 } // MacthingHandleBuffer == NULL (ELSE)
1422 } // *MatchingHandleCount == 0 (ELSE)
1423 } // no error on ParseHandleDatabaseByRelationshipWithType
1425 if (HandleBuffer
!= NULL
) {
1426 FreePool (HandleBuffer
);
1429 if (HandleType
!= NULL
) {
1430 FreePool (HandleType
);
1437 Gets handles for any child controllers of the passed in controller.
1439 @param[in] ControllerHandle The handle of the "parent controller"
1440 @param[in] MatchingHandleCount Pointer to the number of handles in
1441 MatchingHandleBuffer on return.
1442 @param[out] MatchingHandleBuffer Buffer containing handles on a successful
1446 @retval EFI_SUCCESS The operation was sucessful.
1450 ParseHandleDatabaseForChildControllers(
1451 IN CONST EFI_HANDLE ControllerHandle
,
1452 IN UINTN
*MatchingHandleCount
,
1453 OUT EFI_HANDLE
**MatchingHandleBuffer OPTIONAL
1458 UINTN DriverBindingHandleCount
;
1459 EFI_HANDLE
*DriverBindingHandleBuffer
;
1460 UINTN DriverBindingHandleIndex
;
1461 UINTN ChildControllerHandleCount
;
1462 EFI_HANDLE
*ChildControllerHandleBuffer
;
1463 UINTN ChildControllerHandleIndex
;
1464 EFI_HANDLE
*HandleBufferForReturn
;
1466 if (MatchingHandleCount
== NULL
) {
1467 return (EFI_INVALID_PARAMETER
);
1469 *MatchingHandleCount
= 0;
1471 Status
= PARSE_HANDLE_DATABASE_UEFI_DRIVERS (
1473 &DriverBindingHandleCount
,
1474 &DriverBindingHandleBuffer
1476 if (EFI_ERROR (Status
)) {
1481 // Get a buffer big enough for all the controllers.
1483 HandleBufferForReturn
= GetHandleListByProtocol(NULL
);
1484 if (HandleBufferForReturn
== NULL
) {
1485 FreePool (DriverBindingHandleBuffer
);
1486 return (EFI_NOT_FOUND
);
1489 for (DriverBindingHandleIndex
= 0; DriverBindingHandleIndex
< DriverBindingHandleCount
; DriverBindingHandleIndex
++) {
1490 Status
= PARSE_HANDLE_DATABASE_MANAGED_CHILDREN (
1491 DriverBindingHandleBuffer
[DriverBindingHandleIndex
],
1493 &ChildControllerHandleCount
,
1494 &ChildControllerHandleBuffer
1496 if (EFI_ERROR (Status
)) {
1500 for (ChildControllerHandleIndex
= 0;
1501 ChildControllerHandleIndex
< ChildControllerHandleCount
;
1502 ChildControllerHandleIndex
++
1504 for (HandleIndex
= 0; HandleIndex
< *MatchingHandleCount
; HandleIndex
++) {
1505 if (HandleBufferForReturn
[HandleIndex
] == ChildControllerHandleBuffer
[ChildControllerHandleIndex
]) {
1509 if (HandleIndex
>= *MatchingHandleCount
) {
1510 HandleBufferForReturn
[(*MatchingHandleCount
)++] = ChildControllerHandleBuffer
[ChildControllerHandleIndex
];
1514 FreePool (ChildControllerHandleBuffer
);
1517 FreePool (DriverBindingHandleBuffer
);
1519 if (MatchingHandleBuffer
!= NULL
) {
1520 *MatchingHandleBuffer
= HandleBufferForReturn
;
1522 FreePool(HandleBufferForReturn
);
1525 return (EFI_SUCCESS
);
1529 Appends 1 buffer to another buffer. This will re-allocate the destination buffer
1530 if necessary to fit all of the data.
1532 If DestinationBuffer is NULL, then ASSERT().
1534 @param[in, out] DestinationBuffer The pointer to the pointer to the buffer to append onto.
1535 @param[in, out] DestinationSize The pointer to the size of DestinationBuffer.
1536 @param[in] SourceBuffer The pointer to the buffer to append onto DestinationBuffer.
1537 @param[in] SourceSize The number of bytes of SourceBuffer to append.
1539 @retval NULL A memory allocation failed.
1540 @retval NULL A parameter was invalid.
1541 @return A pointer to (*DestinationBuffer).
1546 IN OUT VOID
**DestinationBuffer
,
1547 IN OUT UINTN
*DestinationSize
,
1548 IN VOID
*SourceBuffer
,
1552 UINTN LocalDestinationSize
;
1553 UINTN LocalDestinationFinalSize
;
1555 ASSERT(DestinationBuffer
!= NULL
);
1557 if (SourceSize
== 0 || SourceBuffer
== NULL
) {
1558 return (*DestinationBuffer
);
1561 if (DestinationSize
== NULL
) {
1562 LocalDestinationSize
= 0;
1564 LocalDestinationSize
= *DestinationSize
;
1567 LocalDestinationFinalSize
= LocalDestinationSize
+ SourceSize
;
1569 if (DestinationSize
!= NULL
) {
1570 *DestinationSize
= LocalDestinationSize
;
1573 if (LocalDestinationSize
== 0) {
1575 *DestinationBuffer
= AllocateZeroPool(LocalDestinationFinalSize
);
1578 *DestinationBuffer
= ReallocatePool(LocalDestinationSize
, LocalDestinationFinalSize
, *DestinationBuffer
);
1581 ASSERT(*DestinationBuffer
!= NULL
);
1584 return (CopyMem(((UINT8
*)(*DestinationBuffer
)) + LocalDestinationSize
, SourceBuffer
, SourceSize
));
1588 Gets handles for any child devices produced by the passed in driver.
1590 @param[in] DriverHandle The handle of the driver.
1591 @param[in] MatchingHandleCount Pointer to the number of handles in
1592 MatchingHandleBuffer on return.
1593 @param[out] MatchingHandleBuffer Buffer containing handles on a successful
1595 @retval EFI_SUCCESS The operation was sucessful.
1596 @sa ParseHandleDatabaseByRelationship
1600 ParseHandleDatabaseForChildDevices(
1601 IN CONST EFI_HANDLE DriverHandle
,
1602 IN UINTN
*MatchingHandleCount
,
1603 OUT EFI_HANDLE
**MatchingHandleBuffer OPTIONAL
1607 EFI_HANDLE
*Buffer2
;
1612 UINTN HandleBufferSize
;
1614 ASSERT(MatchingHandleCount
!= NULL
);
1616 HandleBufferSize
= 0;
1619 *MatchingHandleCount
= 0;
1621 Status
= PARSE_HANDLE_DATABASE_DEVICES (
1626 if (!EFI_ERROR (Status
)) {
1627 for (HandleIndex
= 0; HandleIndex
< Count1
; HandleIndex
++) {
1629 // now find the children
1631 Status
= PARSE_HANDLE_DATABASE_MANAGED_CHILDREN (
1633 Buffer
[HandleIndex
],
1637 if (EFI_ERROR(Status
)) {
1641 // save out required and optional data elements
1643 *MatchingHandleCount
+= Count2
;
1644 if (MatchingHandleBuffer
!= NULL
) {
1645 *MatchingHandleBuffer
= BuffernCatGrow((VOID
**)MatchingHandleBuffer
, &HandleBufferSize
, Buffer2
, Count2
* sizeof(Buffer2
[0]));
1651 if (Buffer2
!= NULL
) {
1657 if (Buffer
!= NULL
) {
1664 Function to get all handles that support a given protocol or all handles.
1666 @param[in] ProtocolGuid The guid of the protocol to get handles for. If NULL
1667 then the function will return all handles.
1669 @retval NULL A memory allocation failed.
1670 @return A NULL terminated list of handles.
1674 GetHandleListByProtocol (
1675 IN CONST EFI_GUID
*ProtocolGuid OPTIONAL
1678 EFI_HANDLE
*HandleList
;
1686 // We cannot use LocateHandleBuffer since we need that NULL item on the ends of the list!
1688 if (ProtocolGuid
== NULL
) {
1689 Status
= gBS
->LocateHandle(AllHandles
, NULL
, NULL
, &Size
, HandleList
);
1690 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1691 HandleList
= AllocateZeroPool(Size
+ sizeof(EFI_HANDLE
));
1692 if (HandleList
== NULL
) {
1695 Status
= gBS
->LocateHandle(AllHandles
, NULL
, NULL
, &Size
, HandleList
);
1696 HandleList
[Size
/sizeof(EFI_HANDLE
)] = NULL
;
1699 Status
= gBS
->LocateHandle(ByProtocol
, (EFI_GUID
*)ProtocolGuid
, NULL
, &Size
, HandleList
);
1700 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1701 HandleList
= AllocateZeroPool(Size
+ sizeof(EFI_HANDLE
));
1702 if (HandleList
== NULL
) {
1705 Status
= gBS
->LocateHandle(ByProtocol
, (EFI_GUID
*)ProtocolGuid
, NULL
, &Size
, HandleList
);
1706 HandleList
[Size
/sizeof(EFI_HANDLE
)] = NULL
;
1709 if (EFI_ERROR(Status
)) {
1710 if (HandleList
!= NULL
) {
1711 FreePool(HandleList
);
1715 return (HandleList
);
1719 Function to get all handles that support some protocols.
1721 @param[in] ProtocolGuids A NULL terminated list of protocol GUIDs.
1723 @retval NULL A memory allocation failed.
1724 @retval NULL ProtocolGuids was NULL.
1725 @return A NULL terminated list of EFI_HANDLEs.
1729 GetHandleListByProtocolList (
1730 IN CONST EFI_GUID
**ProtocolGuids
1733 EFI_HANDLE
*HandleList
;
1738 CONST EFI_GUID
**GuidWalker
;
1739 EFI_HANDLE
*HandleWalker1
;
1740 EFI_HANDLE
*HandleWalker2
;
1744 TotalSize
= sizeof(EFI_HANDLE
);
1746 for (GuidWalker
= ProtocolGuids
; GuidWalker
!= NULL
&& *GuidWalker
!= NULL
; GuidWalker
++,Size
= 0){
1747 Status
= gBS
->LocateHandle(ByProtocol
, (EFI_GUID
*)(*GuidWalker
), NULL
, &Size
, NULL
);
1748 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1754 // No handles were found...
1756 if (TotalSize
== sizeof(EFI_HANDLE
)) {
1760 HandleList
= AllocateZeroPool(TotalSize
);
1761 if (HandleList
== NULL
) {
1766 for (GuidWalker
= ProtocolGuids
; GuidWalker
!= NULL
&& *GuidWalker
!= NULL
; GuidWalker
++){
1767 TempSize
= TotalSize
- Size
;
1768 Status
= gBS
->LocateHandle(ByProtocol
, (EFI_GUID
*)(*GuidWalker
), NULL
, &TempSize
, HandleList
+(Size
/sizeof(EFI_HANDLE
)));
1771 // Allow for missing protocols... Only update the 'used' size upon success.
1773 if (!EFI_ERROR(Status
)) {
1777 ASSERT(HandleList
[(TotalSize
/sizeof(EFI_HANDLE
))-1] == NULL
);
1779 for (HandleWalker1
= HandleList
; HandleWalker1
!= NULL
&& *HandleWalker1
!= NULL
; HandleWalker1
++) {
1780 for (HandleWalker2
= HandleWalker1
+ 1; HandleWalker2
!= NULL
&& *HandleWalker2
!= NULL
; HandleWalker2
++) {
1781 if (*HandleWalker1
== *HandleWalker2
) {
1783 // copy memory back 1 handle width.
1785 CopyMem(HandleWalker2
, HandleWalker2
+ 1, TotalSize
- ((HandleWalker2
-HandleList
+1)*sizeof(EFI_HANDLE
)));
1790 return (HandleList
);