2 Provides interface to advanced shell functionality for parsing both handle and protocol database.
4 Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "UefiHandleParsingLib.h"
17 EFI_HANDLE mHandleParsingHiiHandle
;
18 HANDLE_INDEX_LIST mHandleList
= {{{NULL
,NULL
},0,0},0};
21 Constructor for the library.
23 @param[in] ImageHandle Ignored.
24 @param[in] SystemTable Ignored.
26 @retval EFI_SUCCESS The operation was successful.
30 HandleParsingLibConstructor (
31 IN EFI_HANDLE ImageHandle
,
32 IN EFI_SYSTEM_TABLE
*SystemTable
35 mHandleParsingHiiHandle
= HiiAddPackages (&gHandleParsingHiiGuid
, gImageHandle
, UefiHandleParsingLibStrings
, NULL
);
36 if (mHandleParsingHiiHandle
== NULL
) {
37 return (EFI_DEVICE_ERROR
);
44 Destructor for the library. free any resources.
46 @param[in] ImageHandle Ignored.
47 @param[in] SystemTable Ignored.
49 @retval EFI_SUCCESS The operation was successful.
53 HandleParsingLibDestructor (
54 IN EFI_HANDLE ImageHandle
,
55 IN EFI_SYSTEM_TABLE
*SystemTable
58 if (mHandleParsingHiiHandle
!= NULL
) {
59 HiiRemovePackages(mHandleParsingHiiHandle
);
67 LoadedImageProtocolDumpInformation(
68 IN CONST EFI_HANDLE TheHandle,
69 IN CONST BOOLEAN Verbose
72 EFI_LOADED_IMAGE_PROTOCOL *Image;
74 EFI_DEVICE_PATH_PROTOCOL *DevPath;
75 EFI_DEVICE_PATH_PROTOCOL *DevPathNode;
78 UINT32 AuthenticationStatus;
80 EFI_FIRMWARE_VOLUME_PROTOCOL *FV;
81 EFI_FIRMWARE_VOLUME2_PROTOCOL *FV2;
88 Status = HandleProtocol (
90 &gEfiLoadedImageProtocolGuid,
92 ASSERT_EFI_ERROR(Status);
94 DevPath = UnpackDevicePath (Image->FilePath);
96 if (DevPath == NULL) {
100 DevPathNode = DevPath;
102 while (!IsDevicePathEnd (DevPathNode)) {
104 // Find the Fv File path
106 NameGuid = GetNameGuidFromFwVolDevicePathNode ((MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *)DevPathNode);
107 if (NameGuid != NULL) {
108 Status = BS->HandleProtocol (
110 &gEfiFirmwareVolumeProtocolGuid,
113 if (!EFI_ERROR (Status)) {
114 Status = FV->ReadSection (
117 EFI_SECTION_USER_INTERFACE,
121 &AuthenticationStatus
123 if (!EFI_ERROR (Status)) {
129 Status = BS->HandleProtocol (
131 &gEfiFirmwareVolume2ProtocolGuid,
134 if (!EFI_ERROR (Status)) {
135 Status = FV2->ReadSection (
138 EFI_SECTION_USER_INTERFACE,
142 &AuthenticationStatus
144 if (!EFI_ERROR (Status)) {
153 // Next device path node
155 DevPathNode = NextDevicePathNode (DevPathNode);
164 Function to dump information about SimpleTextOut.
166 This will allocate the return buffer from boot services pool.
168 @param[in] TheHandle The handle that has SimpleTextOut installed.
169 @param[in] Verbose TRUE for additional information, FALSE otherwise.
171 @retval A poitner to a string containing the information.
175 TxtOutProtocolDumpInformation(
176 IN CONST EFI_HANDLE TheHandle
,
177 IN CONST BOOLEAN Verbose
180 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*Dev
;
197 Status
= gBS
->HandleProtocol(
199 &gEfiSimpleTextOutProtocolGuid
,
202 ASSERT_EFI_ERROR(Status
);
203 ASSERT (Dev
!= NULL
&& Dev
->Mode
!= NULL
);
205 Size
= (Dev
->Mode
->MaxMode
+ 1) * 80;
206 RetVal
= AllocateZeroPool(Size
);
208 Temp
= HiiGetString(mHandleParsingHiiHandle
, STRING_TOKEN(STR_TXT_OUT_DUMP_HEADER
), NULL
);
210 UnicodeSPrint(RetVal
, Size
, Temp
, Dev
, Dev
->Mode
->Attribute
);
217 Temp
= HiiGetString(mHandleParsingHiiHandle
, STRING_TOKEN(STR_TXT_OUT_DUMP_LINE
), NULL
);
218 for (Index
= 0; Index
< Dev
->Mode
->MaxMode
; Index
++) {
219 Status
= Dev
->QueryMode (Dev
, Index
, &Col
, &Row
);
220 NewSize
= Size
- StrSize(RetVal
);
222 RetVal
+ StrLen(RetVal
),
224 Temp
== NULL
?L
"":Temp
,
225 Index
== Dev
->Mode
->Mode
? L
'*' : L
' ',
227 !EFI_ERROR(Status
)?Col
:-1,
228 !EFI_ERROR(Status
)?Row
:-1
235 STATIC CONST UINTN VersionStringSize
= 60;
238 Function to dump information about EfiDriverSupportedEfiVersion protocol.
240 This will allocate the return buffer from boot services pool.
242 @param[in] TheHandle The handle that has the protocol installed.
243 @param[in] Verbose TRUE for additional information, FALSE otherwise.
245 @retval A poitner to a string containing the information.
249 DriverEfiVersionProtocolDumpInformation(
250 IN CONST EFI_HANDLE TheHandle
,
251 IN CONST BOOLEAN Verbose
254 EFI_DRIVER_SUPPORTED_EFI_VERSION_PROTOCOL
*DriverEfiVersion
;
258 Status
= gBS
->HandleProtocol(
260 &gEfiDriverSupportedEfiVersionProtocolGuid
,
261 (VOID
**)&DriverEfiVersion
);
263 ASSERT_EFI_ERROR(Status
);
265 RetVal
= AllocateZeroPool(VersionStringSize
);
266 ASSERT(RetVal
!= NULL
);
267 UnicodeSPrint(RetVal
, VersionStringSize
, L
"0x%08x", DriverEfiVersion
->FirmwareVersion
);
272 Function to dump information about DevicePath protocol.
274 This will allocate the return buffer from boot services pool.
276 @param[in] TheHandle The handle that has the protocol installed.
277 @param[in] Verbose TRUE for additional information, FALSE otherwise.
279 @retval A poitner to a string containing the information.
283 DevicePathProtocolDumpInformation(
284 IN CONST EFI_HANDLE TheHandle
,
285 IN CONST BOOLEAN Verbose
288 EFI_DEVICE_PATH_PROTOCOL
*DevPath
;
292 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL
*DevPathToText
;
295 Status
= gBS
->LocateProtocol(&gEfiDevicePathToTextProtocolGuid
, NULL
, (VOID
**)&DevPathToText
);
296 if (!EFI_ERROR(Status
)) {
297 Status
= gBS
->OpenProtocol(TheHandle
, &gEfiDevicePathProtocolGuid
, (VOID
**)&DevPath
, gImageHandle
, NULL
, EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
298 if (!EFI_ERROR(Status
)) {
300 // I cannot decide whether to allow shortcuts here (the second BOOLEAN on the next line)
302 Temp
= DevPathToText
->ConvertDevicePathToText(DevPath
, TRUE
, TRUE
);
303 gBS
->CloseProtocol(TheHandle
, &gEfiDevicePathProtocolGuid
, gImageHandle
, NULL
);
306 if (!Verbose
&& Temp
!= NULL
&& StrLen(Temp
) > 30) {
308 Temp2
= StrnCatGrow(&Temp2
, NULL
, Temp
+(StrLen(Temp
) - 30), 30);
316 // Put the information on the NT32 protocol GUIDs here so we are not dependant on the Nt32Pkg
318 #define LOCAL_EFI_WIN_NT_THUNK_PROTOCOL_GUID \
320 0x58c518b1, 0x76f3, 0x11d4, 0xbc, 0xea, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 \
323 #define LOCAL_EFI_WIN_NT_BUS_DRIVER_IO_PROTOCOL_GUID \
325 0x96eb4ad6, 0xa32a, 0x11d4, 0xbc, 0xfd, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 \
328 #define LOCAL_EFI_WIN_NT_SERIAL_PORT_GUID \
330 0xc95a93d, 0xa006, 0x11d4, 0xbc, 0xfa, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 \
332 STATIC CONST EFI_GUID WinNtThunkProtocolGuid
= LOCAL_EFI_WIN_NT_THUNK_PROTOCOL_GUID
;
333 STATIC CONST EFI_GUID WinNtIoProtocolGuid
= LOCAL_EFI_WIN_NT_BUS_DRIVER_IO_PROTOCOL_GUID
;
334 STATIC CONST EFI_GUID WinNtSerialPortGuid
= LOCAL_EFI_WIN_NT_SERIAL_PORT_GUID
;
336 STATIC CONST GUID_INFO_BLOCK mGuidStringListNT
[] = {
337 {STRING_TOKEN(STR_WINNT_THUNK
), (EFI_GUID
*)&WinNtThunkProtocolGuid
, NULL
},
338 {STRING_TOKEN(STR_WINNT_DRIVER_IO
), (EFI_GUID
*)&WinNtIoProtocolGuid
, NULL
},
339 {STRING_TOKEN(STR_WINNT_SERIAL_PORT
), (EFI_GUID
*)&WinNtSerialPortGuid
, NULL
},
340 {STRING_TOKEN(STR_UNKNOWN_DEVICE
), NULL
, NULL
},
343 STATIC CONST GUID_INFO_BLOCK mGuidStringList
[] = {
344 {STRING_TOKEN(STR_LOADED_IMAGE
), &gEfiLoadedImageProtocolGuid
, NULL
},
345 {STRING_TOKEN(STR_DEVICE_PATH
), &gEfiDevicePathProtocolGuid
, DevicePathProtocolDumpInformation
},
346 {STRING_TOKEN(STR_IMAGE_PATH
), &gEfiLoadedImageDevicePathProtocolGuid
, DevicePathProtocolDumpInformation
},
347 {STRING_TOKEN(STR_DEVICE_PATH_UTIL
), &gEfiDevicePathUtilitiesProtocolGuid
, NULL
},
348 {STRING_TOKEN(STR_DEVICE_PATH_TXT
), &gEfiDevicePathToTextProtocolGuid
, NULL
},
349 {STRING_TOKEN(STR_DEVICE_PATH_FTXT
), &gEfiDevicePathFromTextProtocolGuid
, NULL
},
350 {STRING_TOKEN(STR_DEVICE_PATH_PC
), &gEfiPcAnsiGuid
, NULL
},
351 {STRING_TOKEN(STR_DEVICE_PATH_VT100
), &gEfiVT100Guid
, NULL
},
352 {STRING_TOKEN(STR_DEVICE_PATH_VT100P
), &gEfiVT100PlusGuid
, NULL
},
353 {STRING_TOKEN(STR_DEVICE_PATH_VTUTF8
), &gEfiVTUTF8Guid
, NULL
},
354 {STRING_TOKEN(STR_DRIVER_BINDING
), &gEfiDriverBindingProtocolGuid
, NULL
},
355 {STRING_TOKEN(STR_PLATFORM_OVERRIDE
), &gEfiPlatformDriverOverrideProtocolGuid
, NULL
},
356 {STRING_TOKEN(STR_BUS_OVERRIDE
), &gEfiBusSpecificDriverOverrideProtocolGuid
, NULL
},
357 {STRING_TOKEN(STR_DRIVER_DIAG
), &gEfiDriverDiagnosticsProtocolGuid
, NULL
},
358 {STRING_TOKEN(STR_DRIVER_DIAG2
), &gEfiDriverDiagnostics2ProtocolGuid
, NULL
},
359 {STRING_TOKEN(STR_DRIVER_CN
), &gEfiComponentNameProtocolGuid
, NULL
},
360 {STRING_TOKEN(STR_DRIVER_CN2
), &gEfiComponentName2ProtocolGuid
, NULL
},
361 {STRING_TOKEN(STR_PLAT_DRV_CFG
), &gEfiPlatformToDriverConfigurationProtocolGuid
, NULL
},
362 {STRING_TOKEN(STR_DRIVER_VERSION
), &gEfiDriverSupportedEfiVersionProtocolGuid
, DriverEfiVersionProtocolDumpInformation
},
363 {STRING_TOKEN(STR_TXT_IN
), &gEfiSimpleTextInProtocolGuid
, NULL
},
364 {STRING_TOKEN(STR_TXT_IN_EX
), &gEfiSimpleTextInputExProtocolGuid
, NULL
},
365 {STRING_TOKEN(STR_TXT_OUT
), &gEfiSimpleTextOutProtocolGuid
, TxtOutProtocolDumpInformation
},
366 {STRING_TOKEN(STR_SIM_POINTER
), &gEfiSimplePointerProtocolGuid
, NULL
},
367 {STRING_TOKEN(STR_ABS_POINTER
), &gEfiAbsolutePointerProtocolGuid
, NULL
},
368 {STRING_TOKEN(STR_SERIAL_IO
), &gEfiSerialIoProtocolGuid
, NULL
},
369 {STRING_TOKEN(STR_GRAPHICS_OUTPUT
), &gEfiGraphicsOutputProtocolGuid
, NULL
},
370 {STRING_TOKEN(STR_EDID_DISCOVERED
), &gEfiEdidDiscoveredProtocolGuid
, NULL
},
371 {STRING_TOKEN(STR_EDID_ACTIVE
), &gEfiEdidActiveProtocolGuid
, NULL
},
372 {STRING_TOKEN(STR_EDID_OVERRIDE
), &gEfiEdidOverrideProtocolGuid
, NULL
},
373 {STRING_TOKEN(STR_CON_IN
), &gEfiConsoleInDeviceGuid
, NULL
},
374 {STRING_TOKEN(STR_CON_OUT
), &gEfiConsoleOutDeviceGuid
, NULL
},
375 {STRING_TOKEN(STR_STD_ERR
), &gEfiStandardErrorDeviceGuid
, NULL
},
376 {STRING_TOKEN(STR_LOAD_FILE
), &gEfiLoadFileProtocolGuid
, NULL
},
377 {STRING_TOKEN(STR_LOAD_FILE2
), &gEfiLoadFile2ProtocolGuid
, NULL
},
378 {STRING_TOKEN(STR_SIMPLE_FILE_SYS
), &gEfiSimpleFileSystemProtocolGuid
, NULL
},
379 {STRING_TOKEN(STR_TAPE_IO
), &gEfiTapeIoProtocolGuid
, NULL
},
380 {STRING_TOKEN(STR_DISK_IO
), &gEfiDiskIoProtocolGuid
, NULL
},
381 {STRING_TOKEN(STR_BLK_IO
), &gEfiBlockIoProtocolGuid
, NULL
},
382 {STRING_TOKEN(STR_UC
), &gEfiUnicodeCollationProtocolGuid
, NULL
},
383 {STRING_TOKEN(STR_UC2
), &gEfiUnicodeCollation2ProtocolGuid
, NULL
},
384 {STRING_TOKEN(STR_PCIRB_IO
), &gEfiPciRootBridgeIoProtocolGuid
, NULL
},
385 {STRING_TOKEN(STR_PCI_IO
), &gEfiPciIoProtocolGuid
, NULL
},
386 {STRING_TOKEN(STR_SCSI_PT
), &gEfiScsiPassThruProtocolGuid
, NULL
},
387 {STRING_TOKEN(STR_SCSI_IO
), &gEfiScsiIoProtocolGuid
, NULL
},
388 {STRING_TOKEN(STR_SCSI_PT_EXT
), &gEfiExtScsiPassThruProtocolGuid
, NULL
},
389 {STRING_TOKEN(STR_ISCSI
), &gEfiIScsiInitiatorNameProtocolGuid
, NULL
},
390 {STRING_TOKEN(STR_USB_IO
), &gEfiUsbIoProtocolGuid
, NULL
},
391 {STRING_TOKEN(STR_USB_HC
), &gEfiUsbHcProtocolGuid
, NULL
},
392 {STRING_TOKEN(STR_USB_HC2
), &gEfiUsb2HcProtocolGuid
, NULL
},
393 {STRING_TOKEN(STR_DEBUG_SUPPORT
), &gEfiDebugSupportProtocolGuid
, NULL
},
394 {STRING_TOKEN(STR_DEBUG_PORT
), &gEfiDebugPortProtocolGuid
, NULL
},
395 {STRING_TOKEN(STR_DECOMPRESS
), &gEfiDecompressProtocolGuid
, NULL
},
396 {STRING_TOKEN(STR_ACPI_TABLE
), &gEfiAcpiTableProtocolGuid
, NULL
},
397 {STRING_TOKEN(STR_EBC_INTERPRETER
), &gEfiEbcProtocolGuid
, NULL
},
398 {STRING_TOKEN(STR_SNP
), &gEfiSimpleNetworkProtocolGuid
, NULL
},
399 {STRING_TOKEN(STR_NII
), &gEfiNetworkInterfaceIdentifierProtocolGuid
, NULL
},
400 {STRING_TOKEN(STR_NII_31
), &gEfiNetworkInterfaceIdentifierProtocolGuid_31
, NULL
},
401 {STRING_TOKEN(STR_PXE_BC
), &gEfiPxeBaseCodeProtocolGuid
, NULL
},
402 {STRING_TOKEN(STR_PXE_CB
), &gEfiPxeBaseCodeCallbackProtocolGuid
, NULL
},
403 {STRING_TOKEN(STR_BIS
), &gEfiBisProtocolGuid
, NULL
},
404 {STRING_TOKEN(STR_MNP_SB
), &gEfiManagedNetworkServiceBindingProtocolGuid
, NULL
},
405 {STRING_TOKEN(STR_MNP
), &gEfiManagedNetworkProtocolGuid
, NULL
},
406 {STRING_TOKEN(STR_ARP_SB
), &gEfiArpServiceBindingProtocolGuid
, NULL
},
407 {STRING_TOKEN(STR_ARP
), &gEfiArpProtocolGuid
, NULL
},
408 {STRING_TOKEN(STR_DHCPV4_SB
), &gEfiDhcp4ServiceBindingProtocolGuid
, NULL
},
409 {STRING_TOKEN(STR_DHCPV4
), &gEfiDhcp4ProtocolGuid
, NULL
},
410 {STRING_TOKEN(STR_TCPV4_SB
), &gEfiTcp4ServiceBindingProtocolGuid
, NULL
},
411 {STRING_TOKEN(STR_TCPV4
), &gEfiTcp4ProtocolGuid
, NULL
},
412 {STRING_TOKEN(STR_IPV4_SB
), &gEfiIp4ServiceBindingProtocolGuid
, NULL
},
413 {STRING_TOKEN(STR_IPV4
), &gEfiIp4ProtocolGuid
, NULL
},
414 {STRING_TOKEN(STR_IPV4_CFG
), &gEfiIp4ConfigProtocolGuid
, NULL
},
415 {STRING_TOKEN(STR_SHELL_PARAMETERS
), &gEfiShellParametersProtocolGuid
, NULL
},
416 {STRING_TOKEN(STR_SHELL
), &gEfiShellProtocolGuid
, NULL
},
417 {STRING_TOKEN(STR_UDPV4_SB
), &gEfiUdp4ServiceBindingProtocolGuid
, NULL
},
418 {STRING_TOKEN(STR_UDPV4
), &gEfiUdp4ProtocolGuid
, NULL
},
419 {STRING_TOKEN(STR_MTFTPV4_SB
), &gEfiMtftp4ServiceBindingProtocolGuid
, NULL
},
420 {STRING_TOKEN(STR_MTFTPV4
), &gEfiMtftp4ProtocolGuid
, NULL
},
421 {STRING_TOKEN(STR_AUTH_INFO
), &gEfiAuthenticationInfoProtocolGuid
, NULL
},
422 {STRING_TOKEN(STR_HASH_SB
), &gEfiHashServiceBindingProtocolGuid
, NULL
},
423 {STRING_TOKEN(STR_HASH
), &gEfiHashProtocolGuid
, NULL
},
424 {STRING_TOKEN(STR_HII_FONT
), &gEfiHiiFontProtocolGuid
, NULL
},
425 {STRING_TOKEN(STR_HII_STRING
), &gEfiHiiStringProtocolGuid
, NULL
},
426 {STRING_TOKEN(STR_HII_IMAGE
), &gEfiHiiImageProtocolGuid
, NULL
},
427 {STRING_TOKEN(STR_HII_DATABASE
), &gEfiHiiDatabaseProtocolGuid
, NULL
},
428 {STRING_TOKEN(STR_HII_CONFIG_ROUT
), &gEfiHiiConfigRoutingProtocolGuid
, NULL
},
429 {STRING_TOKEN(STR_HII_CONFIG_ACC
), &gEfiHiiConfigAccessProtocolGuid
, NULL
},
430 {STRING_TOKEN(STR_HII_FORM_BROWSER2
), &gEfiFormBrowser2ProtocolGuid
, NULL
},
431 {STRING_TOKEN(STR_DRIVER_FAM_OVERRIDE
), &gEfiDriverFamilyOverrideProtocolGuid
, NULL
},
432 {STRING_TOKEN(STR_PCD
), &gPcdProtocolGuid
, NULL
},
433 {STRING_TOKEN(STR_TCG
), &gEfiTcgProtocolGuid
, NULL
},
434 {STRING_TOKEN(STR_HII_PACKAGE_LIST
), &gEfiHiiPackageListProtocolGuid
, NULL
},
437 // the ones under this are deprecated by the current UEFI Spec, but may be found anyways...
439 {STRING_TOKEN(STR_SHELL_INTERFACE
), &gEfiShellInterfaceGuid
, NULL
},
440 {STRING_TOKEN(STR_SHELL_ENV2
), &gEfiShellEnvironment2Guid
, NULL
},
441 {STRING_TOKEN(STR_SHELL_ENV
), &gEfiShellEnvironment2Guid
, NULL
},
442 {STRING_TOKEN(STR_DEVICE_IO
), &gEfiDeviceIoProtocolGuid
, NULL
},
443 {STRING_TOKEN(STR_UGA_DRAW
), &gEfiUgaDrawProtocolGuid
, NULL
},
444 {STRING_TOKEN(STR_UGA_IO
), &gEfiUgaIoProtocolGuid
, NULL
},
445 {STRING_TOKEN(STR_ESP
), &gEfiPartTypeSystemPartGuid
, NULL
},
446 {STRING_TOKEN(STR_GPT_NBR
), &gEfiPartTypeLegacyMbrGuid
, NULL
},
447 {STRING_TOKEN(STR_DRIVER_CONFIG
), &gEfiDriverConfigurationProtocolGuid
, NULL
},
448 {STRING_TOKEN(STR_DRIVER_CONFIG2
), &gEfiDriverConfiguration2ProtocolGuid
, NULL
},
451 // the ones under this are GUID identified structs, not protocols
453 {STRING_TOKEN(STR_FILE_INFO
), &gEfiFileInfoGuid
, NULL
},
454 {STRING_TOKEN(STR_FILE_SYS_INFO
), &gEfiFileSystemInfoGuid
, NULL
},
457 // the ones under this are misc GUIDS.
459 {STRING_TOKEN(STR_EFI_GLOBAL_VARIABLE
), &gEfiGlobalVariableGuid
, NULL
},
464 {STRING_TOKEN(STR_IP6_SB
), &gEfiIp6ServiceBindingProtocolGuid
, NULL
},
465 {STRING_TOKEN(STR_IP6
), &gEfiIp6ProtocolGuid
, NULL
},
466 {STRING_TOKEN(STR_IP6_CONFIG
), &gEfiIp6ConfigProtocolGuid
, NULL
},
467 {STRING_TOKEN(STR_MTFTP6_SB
), &gEfiMtftp6ServiceBindingProtocolGuid
, NULL
},
468 {STRING_TOKEN(STR_MTFTP6
), &gEfiMtftp6ProtocolGuid
, NULL
},
469 {STRING_TOKEN(STR_DHCP6_SB
), &gEfiDhcp6ServiceBindingProtocolGuid
, NULL
},
470 {STRING_TOKEN(STR_DHCP6
), &gEfiDhcp6ProtocolGuid
, NULL
},
471 {STRING_TOKEN(STR_UDP6_SB
), &gEfiUdp6ServiceBindingProtocolGuid
, NULL
},
472 {STRING_TOKEN(STR_UDP6
), &gEfiUdp6ProtocolGuid
, NULL
},
473 {STRING_TOKEN(STR_TCP6_SB
), &gEfiTcp6ServiceBindingProtocolGuid
, NULL
},
474 {STRING_TOKEN(STR_TCP6
), &gEfiTcp6ProtocolGuid
, NULL
},
475 {STRING_TOKEN(STR_VLAN_CONFIG
), &gEfiVlanConfigProtocolGuid
, NULL
},
476 {STRING_TOKEN(STR_EAP
), &gEfiEapProtocolGuid
, NULL
},
477 {STRING_TOKEN(STR_EAP_MGMT
), &gEfiEapManagementProtocolGuid
, NULL
},
478 {STRING_TOKEN(STR_FTP4_SB
), &gEfiFtp4ServiceBindingProtocolGuid
, NULL
},
479 {STRING_TOKEN(STR_FTP4
), &gEfiFtp4ProtocolGuid
, NULL
},
480 {STRING_TOKEN(STR_IP_SEC_CONFIG
), &gEfiIpSecConfigProtocolGuid
, NULL
},
481 {STRING_TOKEN(STR_DH
), &gEfiDriverHealthProtocolGuid
, NULL
},
482 {STRING_TOKEN(STR_DEF_IMG_LOAD
), &gEfiDeferredImageLoadProtocolGuid
, NULL
},
483 {STRING_TOKEN(STR_USER_CRED
), &gEfiUserCredentialProtocolGuid
, NULL
},
484 {STRING_TOKEN(STR_USER_MNGR
), &gEfiUserManagerProtocolGuid
, NULL
},
485 {STRING_TOKEN(STR_ATA_PASS_THRU
), &gEfiAtaPassThruProtocolGuid
, NULL
},
490 {STRING_TOKEN(STR_FW_MGMT
), &gEfiFirmwareManagementProtocolGuid
, NULL
},
491 {STRING_TOKEN(STR_IP_SEC
), &gEfiIpSecProtocolGuid
, NULL
},
492 {STRING_TOKEN(STR_IP_SEC2
), &gEfiIpSec2ProtocolGuid
, NULL
},
497 {STRING_TOKEN(STR_KMS
), &gEfiKmsProtocolGuid
, NULL
},
498 {STRING_TOKEN(STR_BLK_IO2
), &gEfiBlockIo2ProtocolGuid
, NULL
},
499 {STRING_TOKEN(STR_SSC
), &gEfiStorageSecurityCommandProtocolGuid
, NULL
},
500 {STRING_TOKEN(STR_UC2
), &gEfiUserCredential2ProtocolGuid
, NULL
},
505 {STRING_TOKEN(STR_UNKNOWN_DEVICE
), NULL
, NULL
},
509 Function to get the node for a protocol or struct from it's GUID.
511 if Guid is NULL, then ASSERT.
513 @param[in] Guid The GUID to look for the name of.
517 CONST GUID_INFO_BLOCK
*
519 InternalShellGetNodeFromGuid(
520 IN CONST EFI_GUID
* Guid
523 CONST GUID_INFO_BLOCK
*ListWalker
;
525 ASSERT(Guid
!= NULL
);
527 if (PcdGetBool(PcdShellIncludeNtGuids
)) {
528 for (ListWalker
= mGuidStringListNT
; ListWalker
!= NULL
&& ListWalker
->GuidId
!= NULL
; ListWalker
++) {
529 if (CompareGuid(ListWalker
->GuidId
, Guid
)) {
534 for (ListWalker
= mGuidStringList
; ListWalker
!= NULL
&& ListWalker
->GuidId
!= NULL
; ListWalker
++) {
535 if (CompareGuid(ListWalker
->GuidId
, Guid
)) {
543 Function to get the name of a protocol or struct from it's GUID.
545 if Guid is NULL, then ASSERT.
547 @param[in] Guid The GUID to look for the name of.
548 @param[in] Lang The language to use.
550 @return pointer to string of the name. The caller
551 is responsible to free this memory.
555 GetStringNameFromGuid(
556 IN CONST EFI_GUID
*Guid
,
557 IN CONST CHAR8
*Lang OPTIONAL
560 CONST GUID_INFO_BLOCK
*Id
;
562 Id
= InternalShellGetNodeFromGuid(Guid
);
563 return (HiiGetString(mHandleParsingHiiHandle
, Id
->StringId
, Lang
));
567 Function to dump protocol information from a handle.
569 This function will return a allocated string buffer containing the
570 information. The caller is responsible for freeing the memory.
572 If Guid is NULL, ASSERT().
573 If TheHandle is NULL, ASSERT().
575 @param[in] TheHandle The handle to dump information from.
576 @param[in] Guid The GUID of the protocol to dump.
577 @param[in] Verbose TRUE for extra info. FALSE otherwise.
579 @return The pointer to string.
580 @retval NULL An error was encountered.
584 GetProtocolInformationDump(
585 IN CONST EFI_HANDLE TheHandle
,
586 IN CONST EFI_GUID
*Guid
,
587 IN CONST BOOLEAN Verbose
590 CONST GUID_INFO_BLOCK
*Id
;
592 ASSERT(TheHandle
!= NULL
);
593 ASSERT(Guid
!= NULL
);
595 if (TheHandle
== NULL
|| Guid
== NULL
) {
599 Id
= InternalShellGetNodeFromGuid(Guid
);
600 if (Id
!= NULL
&& Id
->DumpInfo
!= NULL
) {
601 return (Id
->DumpInfo(TheHandle
, Verbose
));
607 Function to get the Guid for a protocol or struct based on it's string name.
609 @param[in] Name The pointer to the string name.
610 @param[in] Lang The pointer to the language code.
611 @param[in] Guid The pointer to the Guid.
613 @retval EFI_SUCCESS The operation was sucessful.
617 GetGuidFromStringName(
618 IN CONST CHAR16
*Name
,
619 IN CONST CHAR8
*Lang OPTIONAL
,
623 CONST GUID_INFO_BLOCK
*ListWalker
;
626 ASSERT(Guid
!= NULL
);
628 return (EFI_INVALID_PARAMETER
);
632 if (PcdGetBool(PcdShellIncludeNtGuids
)) {
633 for (ListWalker
= mGuidStringListNT
; ListWalker
!= NULL
&& ListWalker
->GuidId
!= NULL
; ListWalker
++) {
634 String
= HiiGetString(mHandleParsingHiiHandle
, ListWalker
->StringId
, Lang
);
635 if (Name
!= NULL
&& String
!= NULL
&& StrCmp(Name
, String
)==0) {
636 *Guid
= ListWalker
->GuidId
;
638 SHELL_FREE_NON_NULL(String
);
640 return (EFI_SUCCESS
);
644 for (ListWalker
= mGuidStringList
; ListWalker
!= NULL
&& ListWalker
->GuidId
!= NULL
; ListWalker
++) {
645 String
= HiiGetString(mHandleParsingHiiHandle
, ListWalker
->StringId
, Lang
);
646 if (Name
!= NULL
&& String
!= NULL
&& StrCmp(Name
, String
)==0) {
647 *Guid
= ListWalker
->GuidId
;
649 SHELL_FREE_NON_NULL(String
);
651 return (EFI_SUCCESS
);
654 return (EFI_NOT_FOUND
);
658 Function to retrieve the driver name (if possible) from the ComponentName or
659 ComponentName2 protocol
661 @param[in] TheHandle The driver handle to get the name of.
662 @param[in] Language The language to use.
664 @retval NULL The name could not be found.
665 @return A pointer to the string name. Do not de-allocate the memory.
669 GetStringNameFromHandle(
670 IN CONST EFI_HANDLE TheHandle
,
671 IN CONST CHAR8
*Language
674 EFI_COMPONENT_NAME2_PROTOCOL
*CompNameStruct
;
678 Status
= gBS
->OpenProtocol(
680 &gEfiComponentName2ProtocolGuid
,
681 (VOID
**)&CompNameStruct
,
684 EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
685 if (!EFI_ERROR(Status
)) {
686 Status
= CompNameStruct
->GetDriverName(CompNameStruct
, (CHAR8
*)Language
, &RetVal
);
687 if (!EFI_ERROR(Status
)) {
691 Status
= gBS
->OpenProtocol(
693 &gEfiComponentNameProtocolGuid
,
694 (VOID
**)&CompNameStruct
,
697 EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
698 if (!EFI_ERROR(Status
)) {
699 Status
= CompNameStruct
->GetDriverName(CompNameStruct
, (CHAR8
*)Language
, &RetVal
);
700 if (!EFI_ERROR(Status
)) {
708 Function to initialize the file global mHandleList object for use in
709 vonverting handles to index and index to handle.
711 @retval EFI_SUCCESS The operation was successful.
715 InternalShellInitHandleList(
720 EFI_HANDLE
*HandleBuffer
;
722 HANDLE_LIST
*ListWalker
;
724 if (mHandleList
.NextIndex
!= 0) {
727 InitializeListHead(&mHandleList
.List
.Link
);
728 mHandleList
.NextIndex
= 1;
729 Status
= gBS
->LocateHandleBuffer (
736 ASSERT_EFI_ERROR(Status
);
737 if (EFI_ERROR(Status
)) {
740 for (mHandleList
.NextIndex
= 1 ; mHandleList
.NextIndex
<= HandleCount
; mHandleList
.NextIndex
++){
741 ListWalker
= AllocateZeroPool(sizeof(HANDLE_LIST
));
742 ASSERT(ListWalker
!= NULL
);
743 ListWalker
->TheHandle
= HandleBuffer
[mHandleList
.NextIndex
-1];
744 ListWalker
->TheIndex
= mHandleList
.NextIndex
;
745 InsertTailList(&mHandleList
.List
.Link
,&ListWalker
->Link
);
747 FreePool(HandleBuffer
);
748 return (EFI_SUCCESS
);
752 Function to retrieve the human-friendly index of a given handle. If the handle
753 does not have a index one will be automatically assigned. The index value is valid
754 until the termination of the shell application.
756 @param[in] TheHandle The handle to retrieve an index for.
758 @retval 0 A memory allocation failed.
759 @return The index of the handle.
764 ConvertHandleToHandleIndex(
765 IN CONST EFI_HANDLE TheHandle
768 HANDLE_LIST
*ListWalker
;
769 if (TheHandle
== NULL
) {
773 InternalShellInitHandleList();
775 for (ListWalker
= (HANDLE_LIST
*)GetFirstNode(&mHandleList
.List
.Link
)
776 ; !IsNull(&mHandleList
.List
.Link
,&ListWalker
->Link
)
777 ; ListWalker
= (HANDLE_LIST
*)GetNextNode(&mHandleList
.List
.Link
,&ListWalker
->Link
)
779 if (ListWalker
->TheHandle
== TheHandle
) {
780 return (ListWalker
->TheIndex
);
783 ListWalker
= AllocateZeroPool(sizeof(HANDLE_LIST
));
784 ASSERT(ListWalker
!= NULL
);
785 ListWalker
->TheHandle
= TheHandle
;
786 ListWalker
->TheIndex
= mHandleList
.NextIndex
++;
787 InsertTailList(&mHandleList
.List
.Link
,&ListWalker
->Link
);
788 return (ListWalker
->TheIndex
);
794 Function to retrieve the EFI_HANDLE from the human-friendly index.
796 @param[in] TheIndex The index to retrieve the EFI_HANDLE for.
798 @retval NULL The index was invalid.
799 @return The EFI_HANDLE that index represents.
804 ConvertHandleIndexToHandle(
805 IN CONST UINTN TheIndex
808 HANDLE_LIST
*ListWalker
;
810 InternalShellInitHandleList();
812 if (TheIndex
>= mHandleList
.NextIndex
) {
816 for (ListWalker
= (HANDLE_LIST
*)GetFirstNode(&mHandleList
.List
.Link
)
817 ; !IsNull(&mHandleList
.List
.Link
,&ListWalker
->Link
)
818 ; ListWalker
= (HANDLE_LIST
*)GetNextNode(&mHandleList
.List
.Link
,&ListWalker
->Link
)
820 if (ListWalker
->TheIndex
== TheIndex
) {
821 return (ListWalker
->TheHandle
);
828 Gets all the related EFI_HANDLEs based on the mask supplied.
830 This function scans all EFI_HANDLES in the UEFI environment's handle database
831 and returns the ones with the specified relationship (Mask) to the specified
834 If both DriverBindingHandle and ControllerHandle are NULL, then ASSERT.
835 If MatchingHandleCount is NULL, then ASSERT.
837 If MatchingHandleBuffer is not NULL upon a successful return the memory must be
840 @param[in] DriverBindingHandle The handle with Driver Binding protocol on it.
841 @param[in] ControllerHandle The handle with Device Path protocol on it.
842 @param[in] MatchingHandleCount The pointer to UINTN that specifies the number of HANDLES in
843 MatchingHandleBuffer.
844 @param[out] MatchingHandleBuffer On a successful return, a buffer of MatchingHandleCount
845 EFI_HANDLEs with a terminating NULL EFI_HANDLE.
846 @param[out] HandleType An array of type information.
848 @retval EFI_SUCCESS The operation was successful, and any related handles
849 are in MatchingHandleBuffer.
850 @retval EFI_NOT_FOUND No matching handles were found.
851 @retval EFI_INVALID_PARAMETER A parameter was invalid or out of range.
855 ParseHandleDatabaseByRelationshipWithType (
856 IN CONST EFI_HANDLE DriverBindingHandle OPTIONAL
,
857 IN CONST EFI_HANDLE ControllerHandle OPTIONAL
,
858 IN UINTN
*HandleCount
,
859 OUT EFI_HANDLE
**HandleBuffer
,
860 OUT UINTN
**HandleType
865 EFI_GUID
**ProtocolGuidArray
;
868 EFI_OPEN_PROTOCOL_INFORMATION_ENTRY
*OpenInfo
;
873 ASSERT(HandleCount
!= NULL
);
874 ASSERT(HandleBuffer
!= NULL
);
875 ASSERT(HandleType
!= NULL
);
876 ASSERT(DriverBindingHandle
!= NULL
|| ControllerHandle
!= NULL
);
879 *HandleBuffer
= NULL
;
883 // Retrieve the list of all handles from the handle database
885 Status
= gBS
->LocateHandleBuffer (
892 if (EFI_ERROR (Status
)) {
896 *HandleType
= AllocateZeroPool (*HandleCount
* sizeof (UINTN
));
897 ASSERT(*HandleType
!= NULL
);
899 for (HandleIndex
= 0; HandleIndex
< *HandleCount
; HandleIndex
++) {
901 // Retrieve the list of all the protocols on each handle
903 Status
= gBS
->ProtocolsPerHandle (
904 (*HandleBuffer
)[HandleIndex
],
908 if (!EFI_ERROR (Status
)) {
910 for (ProtocolIndex
= 0; ProtocolIndex
< ArrayCount
; ProtocolIndex
++) {
913 // Set the bit describing what this handle has
915 if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiLoadedImageProtocolGuid
) ) {
916 (*HandleType
)[HandleIndex
] |= HR_IMAGE_HANDLE
;
917 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiDriverBindingProtocolGuid
) ) {
918 (*HandleType
)[HandleIndex
] |= HR_DRIVER_BINDING_HANDLE
;
919 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiDriverConfiguration2ProtocolGuid
)) {
920 (*HandleType
)[HandleIndex
] |= HR_DRIVER_CONFIGURATION_HANDLE
;
921 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiDriverConfigurationProtocolGuid
) ) {
922 (*HandleType
)[HandleIndex
] |= HR_DRIVER_CONFIGURATION_HANDLE
;
923 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiDriverDiagnostics2ProtocolGuid
) ) {
924 (*HandleType
)[HandleIndex
] |= HR_DRIVER_DIAGNOSTICS_HANDLE
;
925 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiDriverDiagnosticsProtocolGuid
) ) {
926 (*HandleType
)[HandleIndex
] |= HR_DRIVER_DIAGNOSTICS_HANDLE
;
927 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiComponentName2ProtocolGuid
) ) {
928 (*HandleType
)[HandleIndex
] |= HR_COMPONENT_NAME_HANDLE
;
929 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiComponentNameProtocolGuid
) ) {
930 (*HandleType
)[HandleIndex
] |= HR_COMPONENT_NAME_HANDLE
;
931 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiDevicePathProtocolGuid
) ) {
932 (*HandleType
)[HandleIndex
] |= HR_DEVICE_HANDLE
;
935 ASSERT((*HandleType
)[HandleIndex
] == (*HandleType
)[HandleIndex
]);
939 // Retrieve the list of agents that have opened each protocol
941 Status
= gBS
->OpenProtocolInformation (
942 (*HandleBuffer
)[HandleIndex
],
943 ProtocolGuidArray
[ProtocolIndex
],
947 if (!EFI_ERROR (Status
)) {
948 for (OpenInfoIndex
= 0; OpenInfoIndex
< OpenInfoCount
; OpenInfoIndex
++) {
949 if (DriverBindingHandle
!= NULL
&& OpenInfo
[OpenInfoIndex
].AgentHandle
== DriverBindingHandle
) {
950 if ((OpenInfo
[OpenInfoIndex
].Attributes
& EFI_OPEN_PROTOCOL_BY_DRIVER
) == EFI_OPEN_PROTOCOL_BY_DRIVER
) {
951 (*HandleType
)[HandleIndex
] |= (HR_DEVICE_HANDLE
| HR_CONTROLLER_HANDLE
);
953 if (ControllerHandle
!= NULL
&& (*HandleBuffer
)[HandleIndex
] == ControllerHandle
) {
954 if ((OpenInfo
[OpenInfoIndex
].Attributes
& EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
) == EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
) {
955 for (ChildIndex
= 0; ChildIndex
< *HandleCount
; ChildIndex
++) {
956 if ((*HandleBuffer
)[ChildIndex
] == OpenInfo
[OpenInfoIndex
].ControllerHandle
) {
957 (*HandleType
)[ChildIndex
] |= (HR_DEVICE_HANDLE
| HR_CHILD_HANDLE
);
963 if (DriverBindingHandle
== NULL
&& OpenInfo
[OpenInfoIndex
].ControllerHandle
== ControllerHandle
) {
964 if ((OpenInfo
[OpenInfoIndex
].Attributes
& EFI_OPEN_PROTOCOL_BY_DRIVER
) == EFI_OPEN_PROTOCOL_BY_DRIVER
) {
965 for (ChildIndex
= 0; ChildIndex
< *HandleCount
; ChildIndex
++) {
966 if ((*HandleBuffer
)[ChildIndex
] == OpenInfo
[OpenInfoIndex
].AgentHandle
) {
967 (*HandleType
)[ChildIndex
] |= HR_DEVICE_DRIVER
;
971 if ((OpenInfo
[OpenInfoIndex
].Attributes
& EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
) == EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
) {
972 (*HandleType
)[HandleIndex
] |= HR_PARENT_HANDLE
;
973 for (ChildIndex
= 0; ChildIndex
< *HandleCount
; ChildIndex
++) {
974 if ((*HandleBuffer
)[ChildIndex
] == OpenInfo
[OpenInfoIndex
].AgentHandle
) {
975 (*HandleType
)[ChildIndex
] |= HR_BUS_DRIVER
;
986 FreePool (ProtocolGuidArray
);
990 if (EFI_ERROR(Status
)) {
991 if (*HandleType
!= NULL
) {
992 FreePool (*HandleType
);
994 if (*HandleBuffer
!= NULL
) {
995 FreePool (*HandleBuffer
);
999 *HandleBuffer
= NULL
;
1007 Gets all the related EFI_HANDLEs based on the single EFI_HANDLE and the mask
1010 This function will scan all EFI_HANDLES in the UEFI environment's handle database
1011 and return all the ones with the specified relationship (Mask) to the specified
1014 If both DriverBindingHandle and ControllerHandle are NULL, then ASSERT.
1015 If MatchingHandleCount is NULL, then ASSERT.
1017 If MatchingHandleBuffer is not NULL upon a sucessful return the memory must be
1020 @param[in] DriverBindingHandle Handle to a object with Driver Binding protocol
1022 @param[in] ControllerHandle Handle to a device with Device Path protocol on it.
1023 @param[in] Mask Mask of what relationship(s) is desired.
1024 @param[in] MatchingHandleCount Poitner to UINTN specifying number of HANDLES in
1025 MatchingHandleBuffer.
1026 @param[out] MatchingHandleBuffer On a sucessful return a buffer of MatchingHandleCount
1027 EFI_HANDLEs and a terminating NULL EFI_HANDLE.
1029 @retval EFI_SUCCESS The operation was sucessful and any related handles
1030 are in MatchingHandleBuffer;
1031 @retval EFI_NOT_FOUND No matching handles were found.
1032 @retval EFI_INVALID_PARAMETER A parameter was invalid or out of range.
1036 ParseHandleDatabaseByRelationship (
1037 IN CONST EFI_HANDLE DriverBindingHandle OPTIONAL
,
1038 IN CONST EFI_HANDLE ControllerHandle OPTIONAL
,
1039 IN CONST UINTN Mask
,
1040 IN UINTN
*MatchingHandleCount
,
1041 OUT EFI_HANDLE
**MatchingHandleBuffer OPTIONAL
1046 EFI_HANDLE
*HandleBuffer
;
1050 ASSERT(MatchingHandleCount
!= NULL
);
1051 ASSERT(DriverBindingHandle
!= NULL
|| ControllerHandle
!= NULL
);
1053 if ((Mask
& HR_VALID_MASK
) != Mask
) {
1054 return (EFI_INVALID_PARAMETER
);
1057 if ((Mask
& HR_CHILD_HANDLE
) != 0 && DriverBindingHandle
== NULL
) {
1058 return (EFI_INVALID_PARAMETER
);
1061 *MatchingHandleCount
= 0;
1062 if (MatchingHandleBuffer
!= NULL
) {
1063 *MatchingHandleBuffer
= NULL
;
1066 HandleBuffer
= NULL
;
1069 Status
= ParseHandleDatabaseByRelationshipWithType (
1070 DriverBindingHandle
,
1076 if (!EFI_ERROR (Status
)) {
1078 // Count the number of handles that match the attributes in Mask
1080 for (HandleIndex
= 0; HandleIndex
< HandleCount
; HandleIndex
++) {
1081 if ((HandleType
[HandleIndex
] & Mask
) == Mask
) {
1082 (*MatchingHandleCount
)++;
1086 // If no handles match the attributes in Mask then return EFI_NOT_FOUND
1088 if (*MatchingHandleCount
== 0) {
1089 Status
= EFI_NOT_FOUND
;
1092 if (MatchingHandleBuffer
== NULL
) {
1094 // Someone just wanted the count...
1096 Status
= EFI_SUCCESS
;
1099 // Allocate a handle buffer for the number of handles that matched the attributes in Mask
1101 *MatchingHandleBuffer
= AllocateZeroPool ((*MatchingHandleCount
+1)* sizeof (EFI_HANDLE
));
1102 ASSERT(*MatchingHandleBuffer
!= NULL
);
1104 for (HandleIndex
= 0,*MatchingHandleCount
= 0
1105 ; HandleIndex
< HandleCount
1109 // Fill the allocated buffer with the handles that matched the attributes in Mask
1111 if ((HandleType
[HandleIndex
] & Mask
) == Mask
) {
1112 (*MatchingHandleBuffer
)[(*MatchingHandleCount
)++] = HandleBuffer
[HandleIndex
];
1117 // Make the last one NULL
1119 (*MatchingHandleBuffer
)[*MatchingHandleCount
] = NULL
;
1121 Status
= EFI_SUCCESS
;
1122 } // MacthingHandleBuffer == NULL (ELSE)
1123 } // *MatchingHandleCount == 0 (ELSE)
1124 } // no error on ParseHandleDatabaseByRelationshipWithType
1126 if (HandleBuffer
!= NULL
) {
1127 FreePool (HandleBuffer
);
1130 if (HandleType
!= NULL
) {
1131 FreePool (HandleType
);
1138 Gets handles for any child controllers of the passed in controller.
1140 @param[in] ControllerHandle The handle of the "parent controller"
1141 @param[in] MatchingHandleCount Pointer to the number of handles in
1142 MatchingHandleBuffer on return.
1143 @param[out] MatchingHandleBuffer Buffer containing handles on a successful
1147 @retval EFI_SUCCESS The operation was sucessful.
1151 ParseHandleDatabaseForChildControllers(
1152 IN CONST EFI_HANDLE ControllerHandle
,
1153 IN UINTN
*MatchingHandleCount
,
1154 OUT EFI_HANDLE
**MatchingHandleBuffer OPTIONAL
1158 // UINTN HandleIndex;
1159 UINTN DriverBindingHandleCount
;
1160 EFI_HANDLE
*DriverBindingHandleBuffer
;
1161 UINTN DriverBindingHandleIndex
;
1162 UINTN ChildControllerHandleCount
;
1163 EFI_HANDLE
*ChildControllerHandleBuffer
;
1164 UINTN ChildControllerHandleIndex
;
1166 EFI_HANDLE
*HandleBufferForReturn
;
1168 if (MatchingHandleCount
== NULL
) {
1169 return (EFI_INVALID_PARAMETER
);
1171 *MatchingHandleCount
= 0;
1173 Status
= PARSE_HANDLE_DATABASE_UEFI_DRIVERS (
1175 &DriverBindingHandleCount
,
1176 &DriverBindingHandleBuffer
1178 if (EFI_ERROR (Status
)) {
1183 // Get a buffer big enough for all the controllers.
1185 HandleBufferForReturn
= GetHandleListByProtocol(&gEfiDevicePathProtocolGuid
);
1186 if (HandleBufferForReturn
== NULL
) {
1187 FreePool (DriverBindingHandleBuffer
);
1188 return (EFI_NOT_FOUND
);
1191 for (DriverBindingHandleIndex
= 0; DriverBindingHandleIndex
< DriverBindingHandleCount
; DriverBindingHandleIndex
++) {
1192 Status
= PARSE_HANDLE_DATABASE_MANAGED_CHILDREN (
1193 DriverBindingHandleBuffer
[DriverBindingHandleIndex
],
1195 &ChildControllerHandleCount
,
1196 &ChildControllerHandleBuffer
1198 if (EFI_ERROR (Status
)) {
1202 for (ChildControllerHandleIndex
= 0;
1203 ChildControllerHandleIndex
< ChildControllerHandleCount
;
1204 ChildControllerHandleIndex
++
1207 HandleBufferForReturn
[(*MatchingHandleCount
)++] = ChildControllerHandleBuffer
[ChildControllerHandleIndex
];
1208 // for (HandleIndex = 0; HandleBufferForReturn[HandleIndex] != NULL; HandleIndex++) {
1209 // if (HandleBufferForReturn[HandleIndex] == ChildControllerHandleBuffer[ChildControllerHandleIndex]) {
1216 // HandleBufferForReturn[(*MatchingHandleCount)++] = ChildControllerHandleBuffer[ChildControllerHandleIndex];
1220 FreePool (ChildControllerHandleBuffer
);
1223 FreePool (DriverBindingHandleBuffer
);
1225 if (MatchingHandleBuffer
!= NULL
) {
1226 *MatchingHandleBuffer
= HandleBufferForReturn
;
1228 FreePool(HandleBufferForReturn
);
1231 return (EFI_SUCCESS
);
1235 Appends 1 buffer to another buffer. This will re-allocate the destination buffer
1236 if necessary to fit all of the data.
1238 If DestinationBuffer is NULL, then ASSERT().
1240 @param[in, out] DestinationBuffer The pointer to the pointer to the buffer to append onto.
1241 @param[in, out] DestinationSize The pointer to the size of DestinationBuffer.
1242 @param[in] SourceBuffer The pointer to the buffer to append onto DestinationBuffer.
1243 @param[in] SourceSize The number of bytes of SourceBuffer to append.
1245 @retval NULL A memory allocation failed.
1246 @retval NULL A parameter was invalid.
1247 @return A pointer to (*DestinationBuffer).
1252 IN OUT VOID
**DestinationBuffer
,
1253 IN OUT UINTN
*DestinationSize
,
1254 IN VOID
*SourceBuffer
,
1258 UINTN LocalDestinationSize
;
1259 UINTN LocalDestinationFinalSize
;
1261 ASSERT(DestinationBuffer
!= NULL
);
1263 if (SourceSize
== 0 || SourceBuffer
== NULL
) {
1264 return (*DestinationBuffer
);
1267 if (DestinationSize
== NULL
) {
1268 LocalDestinationSize
= 0;
1270 LocalDestinationSize
= *DestinationSize
;
1273 LocalDestinationFinalSize
= LocalDestinationSize
+ SourceSize
;
1275 if (DestinationSize
!= NULL
) {
1276 *DestinationSize
= LocalDestinationSize
;
1279 if (LocalDestinationSize
== 0) {
1281 *DestinationBuffer
= AllocateZeroPool(LocalDestinationFinalSize
);
1284 *DestinationBuffer
= ReallocatePool(LocalDestinationSize
, LocalDestinationFinalSize
, *DestinationBuffer
);
1287 ASSERT(*DestinationBuffer
!= NULL
);
1290 return (CopyMem(((UINT8
*)(*DestinationBuffer
)) + LocalDestinationSize
, SourceBuffer
, SourceSize
));
1294 Gets handles for any child devices produced by the passed in driver.
1296 @param[in] DriverHandle The handle of the driver.
1297 @param[in] MatchingHandleCount Pointer to the number of handles in
1298 MatchingHandleBuffer on return.
1299 @param[out] MatchingHandleBuffer Buffer containing handles on a successful
1301 @retval EFI_SUCCESS The operation was sucessful.
1302 @sa ParseHandleDatabaseByRelationship
1306 ParseHandleDatabaseForChildDevices(
1307 IN CONST EFI_HANDLE DriverHandle
,
1308 IN UINTN
*MatchingHandleCount
,
1309 OUT EFI_HANDLE
**MatchingHandleBuffer OPTIONAL
1313 EFI_HANDLE
*Buffer2
;
1318 UINTN HandleBufferSize
;
1320 ASSERT(MatchingHandleCount
!= NULL
);
1322 HandleBufferSize
= 0;
1325 *MatchingHandleCount
= 0;
1327 Status
= PARSE_HANDLE_DATABASE_DEVICES (
1332 if (!EFI_ERROR (Status
)) {
1333 for (HandleIndex
= 0; HandleIndex
< Count1
; HandleIndex
++) {
1335 // now find the children
1337 Status
= PARSE_HANDLE_DATABASE_MANAGED_CHILDREN (
1339 Buffer
[HandleIndex
],
1343 if (EFI_ERROR(Status
)) {
1347 // save out required and optional data elements
1349 *MatchingHandleCount
+= Count2
;
1350 if (MatchingHandleBuffer
!= NULL
) {
1351 *MatchingHandleBuffer
= BuffernCatGrow((VOID
**)MatchingHandleBuffer
, &HandleBufferSize
, Buffer2
, Count2
* sizeof(Buffer2
[0]));
1357 if (Buffer2
!= NULL
) {
1363 if (Buffer
!= NULL
) {
1370 Function to get all handles that support a given protocol or all handles.
1372 @param[in] ProtocolGuid The guid of the protocol to get handles for. If NULL
1373 then the function will return all handles.
1375 @retval NULL A memory allocation failed.
1376 @return A NULL terminated list of handles.
1380 GetHandleListByProtocol (
1381 IN CONST EFI_GUID
*ProtocolGuid OPTIONAL
1384 EFI_HANDLE
*HandleList
;
1392 // We cannot use LocateHandleBuffer since we need that NULL item on the ends of the list!
1394 if (ProtocolGuid
== NULL
) {
1395 Status
= gBS
->LocateHandle(AllHandles
, NULL
, NULL
, &Size
, HandleList
);
1396 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1397 HandleList
= AllocateZeroPool(Size
+ sizeof(EFI_HANDLE
));
1398 if (HandleList
== NULL
) {
1401 Status
= gBS
->LocateHandle(AllHandles
, NULL
, NULL
, &Size
, HandleList
);
1402 HandleList
[Size
/sizeof(EFI_HANDLE
)] = NULL
;
1405 Status
= gBS
->LocateHandle(ByProtocol
, (EFI_GUID
*)ProtocolGuid
, NULL
, &Size
, HandleList
);
1406 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1407 HandleList
= AllocateZeroPool(Size
+ sizeof(EFI_HANDLE
));
1408 if (HandleList
== NULL
) {
1411 Status
= gBS
->LocateHandle(ByProtocol
, (EFI_GUID
*)ProtocolGuid
, NULL
, &Size
, HandleList
);
1412 HandleList
[Size
/sizeof(EFI_HANDLE
)] = NULL
;
1415 if (EFI_ERROR(Status
)) {
1416 if (HandleList
!= NULL
) {
1417 FreePool(HandleList
);
1421 return (HandleList
);
1425 Function to get all handles that support some protocols.
1427 @param[in] ProtocolGuids A NULL terminated list of protocol GUIDs.
1429 @retval NULL A memory allocation failed.
1430 @retval NULL ProtocolGuids was NULL.
1431 @return A NULL terminated list of EFI_HANDLEs.
1435 GetHandleListByProtocolList (
1436 IN CONST EFI_GUID
**ProtocolGuids
1439 EFI_HANDLE
*HandleList
;
1444 CONST EFI_GUID
**GuidWalker
;
1445 EFI_HANDLE
*HandleWalker1
;
1446 EFI_HANDLE
*HandleWalker2
;
1450 TotalSize
= sizeof(EFI_HANDLE
);
1452 for (GuidWalker
= ProtocolGuids
; GuidWalker
!= NULL
&& *GuidWalker
!= NULL
; GuidWalker
++,Size
= 0){
1453 Status
= gBS
->LocateHandle(ByProtocol
, (EFI_GUID
*)(*GuidWalker
), NULL
, &Size
, NULL
);
1454 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1460 // No handles were found...
1462 if (TotalSize
== sizeof(EFI_HANDLE
)) {
1466 HandleList
= AllocateZeroPool(TotalSize
);
1467 if (HandleList
== NULL
) {
1472 for (GuidWalker
= ProtocolGuids
; GuidWalker
!= NULL
&& *GuidWalker
!= NULL
; GuidWalker
++){
1473 TempSize
= TotalSize
- Size
;
1474 Status
= gBS
->LocateHandle(ByProtocol
, (EFI_GUID
*)(*GuidWalker
), NULL
, &TempSize
, HandleList
+(Size
/sizeof(EFI_HANDLE
)));
1477 // Allow for missing protocols... Only update the 'used' size upon success.
1479 if (!EFI_ERROR(Status
)) {
1483 ASSERT(HandleList
[(TotalSize
/sizeof(EFI_HANDLE
))-1] == NULL
);
1485 for (HandleWalker1
= HandleList
; HandleWalker1
!= NULL
&& *HandleWalker1
!= NULL
; HandleWalker1
++) {
1486 for (HandleWalker2
= HandleWalker1
+ 1; HandleWalker2
!= NULL
&& *HandleWalker2
!= NULL
; HandleWalker2
++) {
1487 if (*HandleWalker1
== *HandleWalker2
) {
1489 // copy memory back 1 handle width.
1491 CopyMem(HandleWalker2
, HandleWalker2
+ 1, TotalSize
- ((HandleWalker2
-HandleList
+1)*sizeof(EFI_HANDLE
)));
1496 return (HandleList
);