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 - 2013, 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 Constructor for the library.
25 @param[in] ImageHandle Ignored.
26 @param[in] SystemTable Ignored.
28 @retval EFI_SUCCESS The operation was successful.
32 HandleParsingLibConstructor (
33 IN EFI_HANDLE ImageHandle
,
34 IN EFI_SYSTEM_TABLE
*SystemTable
37 mHandleParsingHiiHandle
= HiiAddPackages (&gHandleParsingHiiGuid
, gImageHandle
, UefiHandleParsingLibStrings
, NULL
);
38 if (mHandleParsingHiiHandle
== NULL
) {
39 return (EFI_DEVICE_ERROR
);
46 Destructor for the library. free any resources.
48 @param[in] ImageHandle Ignored.
49 @param[in] SystemTable Ignored.
51 @retval EFI_SUCCESS The operation was successful.
55 HandleParsingLibDestructor (
56 IN EFI_HANDLE ImageHandle
,
57 IN EFI_SYSTEM_TABLE
*SystemTable
60 if (mHandleParsingHiiHandle
!= NULL
) {
61 HiiRemovePackages(mHandleParsingHiiHandle
);
69 LoadedImageProtocolDumpInformation(
70 IN CONST EFI_HANDLE TheHandle,
71 IN CONST BOOLEAN Verbose
74 EFI_LOADED_IMAGE_PROTOCOL *Image;
76 EFI_DEVICE_PATH_PROTOCOL *DevPath;
77 EFI_DEVICE_PATH_PROTOCOL *DevPathNode;
80 UINT32 AuthenticationStatus;
82 EFI_FIRMWARE_VOLUME_PROTOCOL *FV;
83 EFI_FIRMWARE_VOLUME2_PROTOCOL *FV2;
90 Status = HandleProtocol (
92 &gEfiLoadedImageProtocolGuid,
94 ASSERT_EFI_ERROR(Status);
96 DevPath = UnpackDevicePath (Image->FilePath);
98 if (DevPath == NULL) {
102 DevPathNode = DevPath;
104 while (!IsDevicePathEnd (DevPathNode)) {
106 // Find the Fv File path
108 NameGuid = GetNameGuidFromFwVolDevicePathNode ((MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *)DevPathNode);
109 if (NameGuid != NULL) {
110 Status = BS->HandleProtocol (
112 &gEfiFirmwareVolumeProtocolGuid,
115 if (!EFI_ERROR (Status)) {
116 Status = FV->ReadSection (
119 EFI_SECTION_USER_INTERFACE,
123 &AuthenticationStatus
125 if (!EFI_ERROR (Status)) {
131 Status = BS->HandleProtocol (
133 &gEfiFirmwareVolume2ProtocolGuid,
136 if (!EFI_ERROR (Status)) {
137 Status = FV2->ReadSection (
140 EFI_SECTION_USER_INTERFACE,
144 &AuthenticationStatus
146 if (!EFI_ERROR (Status)) {
155 // Next device path node
157 DevPathNode = NextDevicePathNode (DevPathNode);
166 Function to dump information about PciRootBridgeIo.
168 This will allocate the return buffer from boot services pool.
170 @param[in] TheHandle The handle that has PciRootBridgeIo installed.
171 @param[in] Verbose TRUE for additional information, FALSE otherwise.
173 @retval A poitner to a string containing the information.
177 PciRootBridgeIoDumpInformation(
178 IN CONST EFI_HANDLE TheHandle
,
179 IN CONST BOOLEAN Verbose
182 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
183 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*Configuration
;
194 return (CatSPrint(NULL
, L
"PciRootBridgeIo"));
197 Status
= gBS
->HandleProtocol(
199 &gEfiPciRootBridgeIoProtocolGuid
,
200 (VOID
**)&PciRootBridgeIo
);
202 if (EFI_ERROR(Status
)) {
206 Temp
= HiiGetString(mHandleParsingHiiHandle
, STRING_TOKEN(STR_PCIRB_DUMP_PH
), NULL
);
207 ASSERT (Temp
!= NULL
);
208 Temp2
= CatSPrint(L
"\r\n", Temp
, PciRootBridgeIo
->ParentHandle
);
213 Temp
= HiiGetString(mHandleParsingHiiHandle
, STRING_TOKEN(STR_PCIRB_DUMP_SEG
), NULL
);
214 ASSERT (Temp
!= NULL
);
215 Temp2
= CatSPrint(RetVal
, Temp
, PciRootBridgeIo
->SegmentNumber
);
223 Status
= PciRootBridgeIo
->GetAttributes (PciRootBridgeIo
, &Supports
, &Attributes
);
224 if (!EFI_ERROR(Status
)) {
225 Temp
= HiiGetString(mHandleParsingHiiHandle
, STRING_TOKEN(STR_PCIRB_DUMP_ATT
), NULL
);
226 ASSERT (Temp
!= NULL
);
227 Temp2
= CatSPrint(RetVal
, Temp
, Attributes
);
233 Temp
= HiiGetString(mHandleParsingHiiHandle
, STRING_TOKEN(STR_PCIRB_DUMP_SUPPORTS
), NULL
);
234 ASSERT (Temp
!= NULL
);
235 Temp2
= CatSPrint(RetVal
, Temp
, Supports
);
242 Configuration
= NULL
;
243 Status
= PciRootBridgeIo
->Configuration (PciRootBridgeIo
, (VOID
**) &Configuration
);
244 if (!EFI_ERROR(Status
) && Configuration
!= NULL
) {
245 Temp
= HiiGetString(mHandleParsingHiiHandle
, STRING_TOKEN(STR_PCIRB_DUMP_TITLE
), NULL
);
246 ASSERT (Temp
!= NULL
);
247 Temp2
= CatSPrint(RetVal
, Temp
, Supports
);
252 while (Configuration
->Desc
== ACPI_ADDRESS_SPACE_DESCRIPTOR
) {
254 switch (Configuration
->ResType
) {
255 case ACPI_ADDRESS_SPACE_TYPE_MEM
:
256 Temp
= HiiGetString(mHandleParsingHiiHandle
, STRING_TOKEN(STR_PCIRB_DUMP_MEM
), NULL
);
258 case ACPI_ADDRESS_SPACE_TYPE_IO
:
259 Temp
= HiiGetString(mHandleParsingHiiHandle
, STRING_TOKEN(STR_PCIRB_DUMP_IO
), NULL
);
261 case ACPI_ADDRESS_SPACE_TYPE_BUS
:
262 Temp
= HiiGetString(mHandleParsingHiiHandle
, STRING_TOKEN(STR_PCIRB_DUMP_BUS
), NULL
);
266 Temp2
= CatSPrint(RetVal
, L
"%s", Temp
);
273 Temp2
= CatSPrint(RetVal
,
274 L
"%H%02x %016lx %016lx %02x%N\r\n",
275 Configuration
->SpecificFlag
,
276 Configuration
->AddrRangeMin
,
277 Configuration
->AddrRangeMax
,
278 Configuration
->AddrSpaceGranularity
290 Function to dump information about SimpleTextOut.
292 This will allocate the return buffer from boot services pool.
294 @param[in] TheHandle The handle that has SimpleTextOut installed.
295 @param[in] Verbose TRUE for additional information, FALSE otherwise.
297 @retval A poitner to a string containing the information.
301 TxtOutProtocolDumpInformation(
302 IN CONST EFI_HANDLE TheHandle
,
303 IN CONST BOOLEAN Verbose
306 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*Dev
;
323 Status
= gBS
->HandleProtocol(
325 &gEfiSimpleTextOutProtocolGuid
,
328 ASSERT_EFI_ERROR(Status
);
329 ASSERT (Dev
!= NULL
&& Dev
->Mode
!= NULL
);
331 Size
= (Dev
->Mode
->MaxMode
+ 1) * 80;
332 RetVal
= AllocateZeroPool(Size
);
334 Temp
= HiiGetString(mHandleParsingHiiHandle
, STRING_TOKEN(STR_TXT_OUT_DUMP_HEADER
), NULL
);
336 UnicodeSPrint(RetVal
, Size
, Temp
, Dev
, Dev
->Mode
->Attribute
);
343 Temp
= HiiGetString(mHandleParsingHiiHandle
, STRING_TOKEN(STR_TXT_OUT_DUMP_LINE
), NULL
);
344 for (Index
= 0; Index
< Dev
->Mode
->MaxMode
; Index
++) {
345 Status
= Dev
->QueryMode (Dev
, Index
, &Col
, &Row
);
346 NewSize
= Size
- StrSize(RetVal
);
348 RetVal
+ StrLen(RetVal
),
350 Temp
== NULL
?L
"":Temp
,
351 Index
== Dev
->Mode
->Mode
? L
'*' : L
' ',
353 !EFI_ERROR(Status
)?(INTN
)Col
:-1,
354 !EFI_ERROR(Status
)?(INTN
)Row
:-1
361 STATIC CONST UINTN VersionStringSize
= 60;
364 Function to dump information about EfiDriverSupportedEfiVersion protocol.
366 This will allocate the return buffer from boot services pool.
368 @param[in] TheHandle The handle that has the protocol installed.
369 @param[in] Verbose TRUE for additional information, FALSE otherwise.
371 @retval A poitner to a string containing the information.
375 DriverEfiVersionProtocolDumpInformation(
376 IN CONST EFI_HANDLE TheHandle
,
377 IN CONST BOOLEAN Verbose
380 EFI_DRIVER_SUPPORTED_EFI_VERSION_PROTOCOL
*DriverEfiVersion
;
384 Status
= gBS
->HandleProtocol(
386 &gEfiDriverSupportedEfiVersionProtocolGuid
,
387 (VOID
**)&DriverEfiVersion
);
389 ASSERT_EFI_ERROR(Status
);
391 RetVal
= AllocateZeroPool(VersionStringSize
);
392 ASSERT(RetVal
!= NULL
);
393 UnicodeSPrint(RetVal
, VersionStringSize
, L
"0x%08x", DriverEfiVersion
->FirmwareVersion
);
398 Function to dump information about DevicePath protocol.
400 This will allocate the return buffer from boot services pool.
402 @param[in] TheHandle The handle that has the protocol installed.
403 @param[in] Verbose TRUE for additional information, FALSE otherwise.
405 @retval A poitner to a string containing the information.
409 DevicePathProtocolDumpInformation(
410 IN CONST EFI_HANDLE TheHandle
,
411 IN CONST BOOLEAN Verbose
414 EFI_DEVICE_PATH_PROTOCOL
*DevPath
;
420 Status
= gBS
->OpenProtocol(TheHandle
, &gEfiDevicePathProtocolGuid
, (VOID
**)&DevPath
, gImageHandle
, NULL
, EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
421 if (!EFI_ERROR(Status
)) {
423 // I cannot decide whether to allow shortcuts here (the second BOOLEAN on the next line)
425 Temp
= ConvertDevicePathToText(DevPath
, TRUE
, TRUE
);
426 gBS
->CloseProtocol(TheHandle
, &gEfiDevicePathProtocolGuid
, gImageHandle
, NULL
);
428 if (!Verbose
&& Temp
!= NULL
&& StrLen(Temp
) > 30) {
430 Temp2
= StrnCatGrow(&Temp2
, NULL
, Temp
+(StrLen(Temp
) - 30), 30);
438 // Put the information on the NT32 protocol GUIDs here so we are not dependant on the Nt32Pkg
440 #define LOCAL_EFI_WIN_NT_THUNK_PROTOCOL_GUID \
442 0x58c518b1, 0x76f3, 0x11d4, { 0xbc, 0xea, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 } \
445 #define LOCAL_EFI_WIN_NT_BUS_DRIVER_IO_PROTOCOL_GUID \
447 0x96eb4ad6, 0xa32a, 0x11d4, { 0xbc, 0xfd, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 } \
450 #define LOCAL_EFI_WIN_NT_SERIAL_PORT_GUID \
452 0xc95a93d, 0xa006, 0x11d4, { 0xbc, 0xfa, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 } \
454 STATIC CONST EFI_GUID WinNtThunkProtocolGuid
= LOCAL_EFI_WIN_NT_THUNK_PROTOCOL_GUID
;
455 STATIC CONST EFI_GUID WinNtIoProtocolGuid
= LOCAL_EFI_WIN_NT_BUS_DRIVER_IO_PROTOCOL_GUID
;
456 STATIC CONST EFI_GUID WinNtSerialPortGuid
= LOCAL_EFI_WIN_NT_SERIAL_PORT_GUID
;
458 STATIC CONST GUID_INFO_BLOCK mGuidStringListNT
[] = {
459 {STRING_TOKEN(STR_WINNT_THUNK
), (EFI_GUID
*)&WinNtThunkProtocolGuid
, NULL
},
460 {STRING_TOKEN(STR_WINNT_DRIVER_IO
), (EFI_GUID
*)&WinNtIoProtocolGuid
, NULL
},
461 {STRING_TOKEN(STR_WINNT_SERIAL_PORT
), (EFI_GUID
*)&WinNtSerialPortGuid
, NULL
},
462 {STRING_TOKEN(STR_UNKNOWN_DEVICE
), NULL
, NULL
},
465 STATIC CONST GUID_INFO_BLOCK mGuidStringList
[] = {
466 {STRING_TOKEN(STR_LOADED_IMAGE
), &gEfiLoadedImageProtocolGuid
, NULL
},
467 {STRING_TOKEN(STR_DEVICE_PATH
), &gEfiDevicePathProtocolGuid
, DevicePathProtocolDumpInformation
},
468 {STRING_TOKEN(STR_IMAGE_PATH
), &gEfiLoadedImageDevicePathProtocolGuid
, DevicePathProtocolDumpInformation
},
469 {STRING_TOKEN(STR_DEVICE_PATH_UTIL
), &gEfiDevicePathUtilitiesProtocolGuid
, NULL
},
470 {STRING_TOKEN(STR_DEVICE_PATH_TXT
), &gEfiDevicePathToTextProtocolGuid
, NULL
},
471 {STRING_TOKEN(STR_DEVICE_PATH_FTXT
), &gEfiDevicePathFromTextProtocolGuid
, NULL
},
472 {STRING_TOKEN(STR_DEVICE_PATH_PC
), &gEfiPcAnsiGuid
, NULL
},
473 {STRING_TOKEN(STR_DEVICE_PATH_VT100
), &gEfiVT100Guid
, NULL
},
474 {STRING_TOKEN(STR_DEVICE_PATH_VT100P
), &gEfiVT100PlusGuid
, NULL
},
475 {STRING_TOKEN(STR_DEVICE_PATH_VTUTF8
), &gEfiVTUTF8Guid
, NULL
},
476 {STRING_TOKEN(STR_DRIVER_BINDING
), &gEfiDriverBindingProtocolGuid
, NULL
},
477 {STRING_TOKEN(STR_PLATFORM_OVERRIDE
), &gEfiPlatformDriverOverrideProtocolGuid
, NULL
},
478 {STRING_TOKEN(STR_BUS_OVERRIDE
), &gEfiBusSpecificDriverOverrideProtocolGuid
, NULL
},
479 {STRING_TOKEN(STR_DRIVER_DIAG
), &gEfiDriverDiagnosticsProtocolGuid
, NULL
},
480 {STRING_TOKEN(STR_DRIVER_DIAG2
), &gEfiDriverDiagnostics2ProtocolGuid
, NULL
},
481 {STRING_TOKEN(STR_DRIVER_CN
), &gEfiComponentNameProtocolGuid
, NULL
},
482 {STRING_TOKEN(STR_DRIVER_CN2
), &gEfiComponentName2ProtocolGuid
, NULL
},
483 {STRING_TOKEN(STR_PLAT_DRV_CFG
), &gEfiPlatformToDriverConfigurationProtocolGuid
, NULL
},
484 {STRING_TOKEN(STR_DRIVER_VERSION
), &gEfiDriverSupportedEfiVersionProtocolGuid
, DriverEfiVersionProtocolDumpInformation
},
485 {STRING_TOKEN(STR_TXT_IN
), &gEfiSimpleTextInProtocolGuid
, NULL
},
486 {STRING_TOKEN(STR_TXT_IN_EX
), &gEfiSimpleTextInputExProtocolGuid
, NULL
},
487 {STRING_TOKEN(STR_TXT_OUT
), &gEfiSimpleTextOutProtocolGuid
, TxtOutProtocolDumpInformation
},
488 {STRING_TOKEN(STR_SIM_POINTER
), &gEfiSimplePointerProtocolGuid
, NULL
},
489 {STRING_TOKEN(STR_ABS_POINTER
), &gEfiAbsolutePointerProtocolGuid
, NULL
},
490 {STRING_TOKEN(STR_SERIAL_IO
), &gEfiSerialIoProtocolGuid
, NULL
},
491 {STRING_TOKEN(STR_GRAPHICS_OUTPUT
), &gEfiGraphicsOutputProtocolGuid
, NULL
},
492 {STRING_TOKEN(STR_EDID_DISCOVERED
), &gEfiEdidDiscoveredProtocolGuid
, NULL
},
493 {STRING_TOKEN(STR_EDID_ACTIVE
), &gEfiEdidActiveProtocolGuid
, NULL
},
494 {STRING_TOKEN(STR_EDID_OVERRIDE
), &gEfiEdidOverrideProtocolGuid
, NULL
},
495 {STRING_TOKEN(STR_CON_IN
), &gEfiConsoleInDeviceGuid
, NULL
},
496 {STRING_TOKEN(STR_CON_OUT
), &gEfiConsoleOutDeviceGuid
, NULL
},
497 {STRING_TOKEN(STR_STD_ERR
), &gEfiStandardErrorDeviceGuid
, NULL
},
498 {STRING_TOKEN(STR_LOAD_FILE
), &gEfiLoadFileProtocolGuid
, NULL
},
499 {STRING_TOKEN(STR_LOAD_FILE2
), &gEfiLoadFile2ProtocolGuid
, NULL
},
500 {STRING_TOKEN(STR_SIMPLE_FILE_SYS
), &gEfiSimpleFileSystemProtocolGuid
, NULL
},
501 {STRING_TOKEN(STR_TAPE_IO
), &gEfiTapeIoProtocolGuid
, NULL
},
502 {STRING_TOKEN(STR_DISK_IO
), &gEfiDiskIoProtocolGuid
, NULL
},
503 {STRING_TOKEN(STR_BLK_IO
), &gEfiBlockIoProtocolGuid
, NULL
},
504 {STRING_TOKEN(STR_UC
), &gEfiUnicodeCollationProtocolGuid
, NULL
},
505 {STRING_TOKEN(STR_UC2
), &gEfiUnicodeCollation2ProtocolGuid
, NULL
},
506 {STRING_TOKEN(STR_PCIRB_IO
), &gEfiPciRootBridgeIoProtocolGuid
, PciRootBridgeIoDumpInformation
},
507 {STRING_TOKEN(STR_PCI_IO
), &gEfiPciIoProtocolGuid
, NULL
},
508 {STRING_TOKEN(STR_SCSI_PT
), &gEfiScsiPassThruProtocolGuid
, NULL
},
509 {STRING_TOKEN(STR_SCSI_IO
), &gEfiScsiIoProtocolGuid
, NULL
},
510 {STRING_TOKEN(STR_SCSI_PT_EXT
), &gEfiExtScsiPassThruProtocolGuid
, NULL
},
511 {STRING_TOKEN(STR_ISCSI
), &gEfiIScsiInitiatorNameProtocolGuid
, NULL
},
512 {STRING_TOKEN(STR_USB_IO
), &gEfiUsbIoProtocolGuid
, NULL
},
513 {STRING_TOKEN(STR_USB_HC
), &gEfiUsbHcProtocolGuid
, NULL
},
514 {STRING_TOKEN(STR_USB_HC2
), &gEfiUsb2HcProtocolGuid
, NULL
},
515 {STRING_TOKEN(STR_DEBUG_SUPPORT
), &gEfiDebugSupportProtocolGuid
, NULL
},
516 {STRING_TOKEN(STR_DEBUG_PORT
), &gEfiDebugPortProtocolGuid
, NULL
},
517 {STRING_TOKEN(STR_DECOMPRESS
), &gEfiDecompressProtocolGuid
, NULL
},
518 {STRING_TOKEN(STR_ACPI_TABLE
), &gEfiAcpiTableProtocolGuid
, NULL
},
519 {STRING_TOKEN(STR_EBC_INTERPRETER
), &gEfiEbcProtocolGuid
, NULL
},
520 {STRING_TOKEN(STR_SNP
), &gEfiSimpleNetworkProtocolGuid
, NULL
},
521 {STRING_TOKEN(STR_NII
), &gEfiNetworkInterfaceIdentifierProtocolGuid
, NULL
},
522 {STRING_TOKEN(STR_NII_31
), &gEfiNetworkInterfaceIdentifierProtocolGuid_31
, NULL
},
523 {STRING_TOKEN(STR_PXE_BC
), &gEfiPxeBaseCodeProtocolGuid
, NULL
},
524 {STRING_TOKEN(STR_PXE_CB
), &gEfiPxeBaseCodeCallbackProtocolGuid
, NULL
},
525 {STRING_TOKEN(STR_BIS
), &gEfiBisProtocolGuid
, NULL
},
526 {STRING_TOKEN(STR_MNP_SB
), &gEfiManagedNetworkServiceBindingProtocolGuid
, NULL
},
527 {STRING_TOKEN(STR_MNP
), &gEfiManagedNetworkProtocolGuid
, NULL
},
528 {STRING_TOKEN(STR_ARP_SB
), &gEfiArpServiceBindingProtocolGuid
, NULL
},
529 {STRING_TOKEN(STR_ARP
), &gEfiArpProtocolGuid
, NULL
},
530 {STRING_TOKEN(STR_DHCPV4_SB
), &gEfiDhcp4ServiceBindingProtocolGuid
, NULL
},
531 {STRING_TOKEN(STR_DHCPV4
), &gEfiDhcp4ProtocolGuid
, NULL
},
532 {STRING_TOKEN(STR_TCPV4_SB
), &gEfiTcp4ServiceBindingProtocolGuid
, NULL
},
533 {STRING_TOKEN(STR_TCPV4
), &gEfiTcp4ProtocolGuid
, NULL
},
534 {STRING_TOKEN(STR_IPV4_SB
), &gEfiIp4ServiceBindingProtocolGuid
, NULL
},
535 {STRING_TOKEN(STR_IPV4
), &gEfiIp4ProtocolGuid
, NULL
},
536 {STRING_TOKEN(STR_IPV4_CFG
), &gEfiIp4ConfigProtocolGuid
, NULL
},
537 {STRING_TOKEN(STR_SHELL_PARAMETERS
), &gEfiShellParametersProtocolGuid
, NULL
},
538 {STRING_TOKEN(STR_SHELL
), &gEfiShellProtocolGuid
, NULL
},
539 {STRING_TOKEN(STR_UDPV4_SB
), &gEfiUdp4ServiceBindingProtocolGuid
, NULL
},
540 {STRING_TOKEN(STR_UDPV4
), &gEfiUdp4ProtocolGuid
, NULL
},
541 {STRING_TOKEN(STR_MTFTPV4_SB
), &gEfiMtftp4ServiceBindingProtocolGuid
, NULL
},
542 {STRING_TOKEN(STR_MTFTPV4
), &gEfiMtftp4ProtocolGuid
, NULL
},
543 {STRING_TOKEN(STR_AUTH_INFO
), &gEfiAuthenticationInfoProtocolGuid
, NULL
},
544 {STRING_TOKEN(STR_HASH_SB
), &gEfiHashServiceBindingProtocolGuid
, NULL
},
545 {STRING_TOKEN(STR_HASH
), &gEfiHashProtocolGuid
, NULL
},
546 {STRING_TOKEN(STR_HII_FONT
), &gEfiHiiFontProtocolGuid
, NULL
},
547 {STRING_TOKEN(STR_HII_STRING
), &gEfiHiiStringProtocolGuid
, NULL
},
548 {STRING_TOKEN(STR_HII_IMAGE
), &gEfiHiiImageProtocolGuid
, NULL
},
549 {STRING_TOKEN(STR_HII_DATABASE
), &gEfiHiiDatabaseProtocolGuid
, NULL
},
550 {STRING_TOKEN(STR_HII_CONFIG_ROUT
), &gEfiHiiConfigRoutingProtocolGuid
, NULL
},
551 {STRING_TOKEN(STR_HII_CONFIG_ACC
), &gEfiHiiConfigAccessProtocolGuid
, NULL
},
552 {STRING_TOKEN(STR_HII_FORM_BROWSER2
), &gEfiFormBrowser2ProtocolGuid
, NULL
},
553 {STRING_TOKEN(STR_DRIVER_FAM_OVERRIDE
), &gEfiDriverFamilyOverrideProtocolGuid
, NULL
},
554 {STRING_TOKEN(STR_PCD
), &gPcdProtocolGuid
, NULL
},
555 {STRING_TOKEN(STR_TCG
), &gEfiTcgProtocolGuid
, NULL
},
556 {STRING_TOKEN(STR_HII_PACKAGE_LIST
), &gEfiHiiPackageListProtocolGuid
, NULL
},
559 // the ones under this are deprecated by the current UEFI Spec, but may be found anyways...
561 {STRING_TOKEN(STR_SHELL_INTERFACE
), &gEfiShellInterfaceGuid
, NULL
},
562 {STRING_TOKEN(STR_SHELL_ENV2
), &gEfiShellEnvironment2Guid
, NULL
},
563 {STRING_TOKEN(STR_SHELL_ENV
), &gEfiShellEnvironment2Guid
, NULL
},
564 {STRING_TOKEN(STR_DEVICE_IO
), &gEfiDeviceIoProtocolGuid
, NULL
},
565 {STRING_TOKEN(STR_UGA_DRAW
), &gEfiUgaDrawProtocolGuid
, NULL
},
566 {STRING_TOKEN(STR_UGA_IO
), &gEfiUgaIoProtocolGuid
, NULL
},
567 {STRING_TOKEN(STR_ESP
), &gEfiPartTypeSystemPartGuid
, NULL
},
568 {STRING_TOKEN(STR_GPT_NBR
), &gEfiPartTypeLegacyMbrGuid
, NULL
},
569 {STRING_TOKEN(STR_DRIVER_CONFIG
), &gEfiDriverConfigurationProtocolGuid
, NULL
},
570 {STRING_TOKEN(STR_DRIVER_CONFIG2
), &gEfiDriverConfiguration2ProtocolGuid
, NULL
},
573 // the ones under this are GUID identified structs, not protocols
575 {STRING_TOKEN(STR_FILE_INFO
), &gEfiFileInfoGuid
, NULL
},
576 {STRING_TOKEN(STR_FILE_SYS_INFO
), &gEfiFileSystemInfoGuid
, NULL
},
579 // the ones under this are misc GUIDS.
581 {STRING_TOKEN(STR_EFI_GLOBAL_VARIABLE
), &gEfiGlobalVariableGuid
, NULL
},
586 {STRING_TOKEN(STR_IP6_SB
), &gEfiIp6ServiceBindingProtocolGuid
, NULL
},
587 {STRING_TOKEN(STR_IP6
), &gEfiIp6ProtocolGuid
, NULL
},
588 {STRING_TOKEN(STR_IP6_CONFIG
), &gEfiIp6ConfigProtocolGuid
, NULL
},
589 {STRING_TOKEN(STR_MTFTP6_SB
), &gEfiMtftp6ServiceBindingProtocolGuid
, NULL
},
590 {STRING_TOKEN(STR_MTFTP6
), &gEfiMtftp6ProtocolGuid
, NULL
},
591 {STRING_TOKEN(STR_DHCP6_SB
), &gEfiDhcp6ServiceBindingProtocolGuid
, NULL
},
592 {STRING_TOKEN(STR_DHCP6
), &gEfiDhcp6ProtocolGuid
, NULL
},
593 {STRING_TOKEN(STR_UDP6_SB
), &gEfiUdp6ServiceBindingProtocolGuid
, NULL
},
594 {STRING_TOKEN(STR_UDP6
), &gEfiUdp6ProtocolGuid
, NULL
},
595 {STRING_TOKEN(STR_TCP6_SB
), &gEfiTcp6ServiceBindingProtocolGuid
, NULL
},
596 {STRING_TOKEN(STR_TCP6
), &gEfiTcp6ProtocolGuid
, NULL
},
597 {STRING_TOKEN(STR_VLAN_CONFIG
), &gEfiVlanConfigProtocolGuid
, NULL
},
598 {STRING_TOKEN(STR_EAP
), &gEfiEapProtocolGuid
, NULL
},
599 {STRING_TOKEN(STR_EAP_MGMT
), &gEfiEapManagementProtocolGuid
, NULL
},
600 {STRING_TOKEN(STR_FTP4_SB
), &gEfiFtp4ServiceBindingProtocolGuid
, NULL
},
601 {STRING_TOKEN(STR_FTP4
), &gEfiFtp4ProtocolGuid
, NULL
},
602 {STRING_TOKEN(STR_IP_SEC_CONFIG
), &gEfiIpSecConfigProtocolGuid
, NULL
},
603 {STRING_TOKEN(STR_DH
), &gEfiDriverHealthProtocolGuid
, NULL
},
604 {STRING_TOKEN(STR_DEF_IMG_LOAD
), &gEfiDeferredImageLoadProtocolGuid
, NULL
},
605 {STRING_TOKEN(STR_USER_CRED
), &gEfiUserCredentialProtocolGuid
, NULL
},
606 {STRING_TOKEN(STR_USER_MNGR
), &gEfiUserManagerProtocolGuid
, NULL
},
607 {STRING_TOKEN(STR_ATA_PASS_THRU
), &gEfiAtaPassThruProtocolGuid
, NULL
},
612 {STRING_TOKEN(STR_FW_MGMT
), &gEfiFirmwareManagementProtocolGuid
, NULL
},
613 {STRING_TOKEN(STR_IP_SEC
), &gEfiIpSecProtocolGuid
, NULL
},
614 {STRING_TOKEN(STR_IP_SEC2
), &gEfiIpSec2ProtocolGuid
, NULL
},
619 {STRING_TOKEN(STR_KMS
), &gEfiKmsProtocolGuid
, NULL
},
620 {STRING_TOKEN(STR_BLK_IO2
), &gEfiBlockIo2ProtocolGuid
, NULL
},
621 {STRING_TOKEN(STR_SSC
), &gEfiStorageSecurityCommandProtocolGuid
, NULL
},
622 {STRING_TOKEN(STR_UCRED2
), &gEfiUserCredential2ProtocolGuid
, NULL
},
627 {STRING_TOKEN(STR_DISK_IO2
), &gEfiDiskIo2ProtocolGuid
, NULL
},
632 {STRING_TOKEN(STR_IDE_CONT_INIT
), &gEfiIdeControllerInitProtocolGuid
, NULL
},
637 {STRING_TOKEN(STR_UNKNOWN_DEVICE
), NULL
, NULL
},
641 Function to get the node for a protocol or struct from it's GUID.
643 if Guid is NULL, then ASSERT.
645 @param[in] Guid The GUID to look for the name of.
649 CONST GUID_INFO_BLOCK
*
651 InternalShellGetNodeFromGuid(
652 IN CONST EFI_GUID
* Guid
655 CONST GUID_INFO_BLOCK
*ListWalker
;
657 ASSERT(Guid
!= NULL
);
659 if (PcdGetBool(PcdShellIncludeNtGuids
)) {
660 for (ListWalker
= mGuidStringListNT
; ListWalker
!= NULL
&& ListWalker
->GuidId
!= NULL
; ListWalker
++) {
661 if (CompareGuid(ListWalker
->GuidId
, Guid
)) {
666 for (ListWalker
= mGuidStringList
; ListWalker
!= NULL
&& ListWalker
->GuidId
!= NULL
; ListWalker
++) {
667 if (CompareGuid(ListWalker
->GuidId
, Guid
)) {
675 Function to get the name of a protocol or struct from it's GUID.
677 if Guid is NULL, then ASSERT.
679 @param[in] Guid The GUID to look for the name of.
680 @param[in] Lang The language to use.
682 @return pointer to string of the name. The caller
683 is responsible to free this memory.
687 GetStringNameFromGuid(
688 IN CONST EFI_GUID
*Guid
,
689 IN CONST CHAR8
*Lang OPTIONAL
692 CONST GUID_INFO_BLOCK
*Id
;
694 Id
= InternalShellGetNodeFromGuid(Guid
);
695 return (HiiGetString(mHandleParsingHiiHandle
, Id
->StringId
, Lang
));
699 Function to dump protocol information from a handle.
701 This function will return a allocated string buffer containing the
702 information. The caller is responsible for freeing the memory.
704 If Guid is NULL, ASSERT().
705 If TheHandle is NULL, ASSERT().
707 @param[in] TheHandle The handle to dump information from.
708 @param[in] Guid The GUID of the protocol to dump.
709 @param[in] Verbose TRUE for extra info. FALSE otherwise.
711 @return The pointer to string.
712 @retval NULL An error was encountered.
716 GetProtocolInformationDump(
717 IN CONST EFI_HANDLE TheHandle
,
718 IN CONST EFI_GUID
*Guid
,
719 IN CONST BOOLEAN Verbose
722 CONST GUID_INFO_BLOCK
*Id
;
724 ASSERT(TheHandle
!= NULL
);
725 ASSERT(Guid
!= NULL
);
727 if (TheHandle
== NULL
|| Guid
== NULL
) {
731 Id
= InternalShellGetNodeFromGuid(Guid
);
732 if (Id
!= NULL
&& Id
->DumpInfo
!= NULL
) {
733 return (Id
->DumpInfo(TheHandle
, Verbose
));
739 Function to get the Guid for a protocol or struct based on it's string name.
741 @param[in] Name The pointer to the string name.
742 @param[in] Lang The pointer to the language code.
743 @param[in] Guid The pointer to the Guid.
745 @retval EFI_SUCCESS The operation was sucessful.
749 GetGuidFromStringName(
750 IN CONST CHAR16
*Name
,
751 IN CONST CHAR8
*Lang OPTIONAL
,
755 CONST GUID_INFO_BLOCK
*ListWalker
;
758 ASSERT(Guid
!= NULL
);
760 return (EFI_INVALID_PARAMETER
);
764 if (PcdGetBool(PcdShellIncludeNtGuids
)) {
765 for (ListWalker
= mGuidStringListNT
; ListWalker
!= NULL
&& ListWalker
->GuidId
!= NULL
; ListWalker
++) {
766 String
= HiiGetString(mHandleParsingHiiHandle
, ListWalker
->StringId
, Lang
);
767 if (Name
!= NULL
&& String
!= NULL
&& StringNoCaseCompare (&Name
, &String
) == 0) {
768 *Guid
= ListWalker
->GuidId
;
770 SHELL_FREE_NON_NULL(String
);
772 return (EFI_SUCCESS
);
776 for (ListWalker
= mGuidStringList
; ListWalker
!= NULL
&& ListWalker
->GuidId
!= NULL
; ListWalker
++) {
777 String
= HiiGetString(mHandleParsingHiiHandle
, ListWalker
->StringId
, Lang
);
778 if (Name
!= NULL
&& String
!= NULL
&& StringNoCaseCompare (&Name
, &String
) == 0) {
779 *Guid
= ListWalker
->GuidId
;
781 SHELL_FREE_NON_NULL(String
);
783 return (EFI_SUCCESS
);
786 return (EFI_NOT_FOUND
);
790 Get best support language for this driver.
792 First base on the user input language to search, second base on the current
793 platform used language to search, third get the first language from the
794 support language list. The caller need to free the buffer of the best language.
796 @param[in] SupportedLanguages The support languages for this driver.
797 @param[in] InputLanguage The user input language.
798 @param[in] Iso639Language Whether get language for ISO639.
800 @return The best support language for this driver.
804 GetBestLanguageForDriver (
805 IN CONST CHAR8
*SupportedLanguages
,
806 IN CONST CHAR8
*InputLanguage
,
807 IN BOOLEAN Iso639Language
810 CHAR8
*LanguageVariable
;
813 LanguageVariable
= GetVariable (Iso639Language
? L
"Lang" : L
"PlatformLang", &gEfiGlobalVariableGuid
);
815 BestLanguage
= GetBestLanguage(
818 (InputLanguage
!= NULL
) ? InputLanguage
: "",
819 (LanguageVariable
!= NULL
) ? LanguageVariable
: "",
824 if (LanguageVariable
!= NULL
) {
825 FreePool (LanguageVariable
);
832 Function to retrieve the driver name (if possible) from the ComponentName or
833 ComponentName2 protocol
835 @param[in] TheHandle The driver handle to get the name of.
836 @param[in] Language The language to use.
838 @retval NULL The name could not be found.
839 @return A pointer to the string name. Do not de-allocate the memory.
843 GetStringNameFromHandle(
844 IN CONST EFI_HANDLE TheHandle
,
845 IN CONST CHAR8
*Language
848 EFI_COMPONENT_NAME2_PROTOCOL
*CompNameStruct
;
855 Status
= gBS
->OpenProtocol(
857 &gEfiComponentName2ProtocolGuid
,
858 (VOID
**)&CompNameStruct
,
861 EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
862 if (!EFI_ERROR(Status
)) {
863 BestLang
= GetBestLanguageForDriver (CompNameStruct
->SupportedLanguages
, Language
, FALSE
);
864 Status
= CompNameStruct
->GetDriverName(CompNameStruct
, BestLang
, &RetVal
);
865 if (BestLang
!= NULL
) {
869 if (!EFI_ERROR(Status
)) {
873 Status
= gBS
->OpenProtocol(
875 &gEfiComponentNameProtocolGuid
,
876 (VOID
**)&CompNameStruct
,
879 EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
880 if (!EFI_ERROR(Status
)) {
881 BestLang
= GetBestLanguageForDriver (CompNameStruct
->SupportedLanguages
, Language
, FALSE
);
882 Status
= CompNameStruct
->GetDriverName(CompNameStruct
, BestLang
, &RetVal
);
883 if (BestLang
!= NULL
) {
886 if (!EFI_ERROR(Status
)) {
894 Function to initialize the file global mHandleList object for use in
895 vonverting handles to index and index to handle.
897 @retval EFI_SUCCESS The operation was successful.
901 InternalShellInitHandleList(
906 EFI_HANDLE
*HandleBuffer
;
908 HANDLE_LIST
*ListWalker
;
910 if (mHandleList
.NextIndex
!= 0) {
913 InitializeListHead(&mHandleList
.List
.Link
);
914 mHandleList
.NextIndex
= 1;
915 Status
= gBS
->LocateHandleBuffer (
922 ASSERT_EFI_ERROR(Status
);
923 if (EFI_ERROR(Status
)) {
926 for (mHandleList
.NextIndex
= 1 ; mHandleList
.NextIndex
<= HandleCount
; mHandleList
.NextIndex
++){
927 ListWalker
= AllocateZeroPool(sizeof(HANDLE_LIST
));
928 ASSERT(ListWalker
!= NULL
);
929 ListWalker
->TheHandle
= HandleBuffer
[mHandleList
.NextIndex
-1];
930 ListWalker
->TheIndex
= mHandleList
.NextIndex
;
931 InsertTailList(&mHandleList
.List
.Link
,&ListWalker
->Link
);
933 FreePool(HandleBuffer
);
934 return (EFI_SUCCESS
);
938 Function to retrieve the human-friendly index of a given handle. If the handle
939 does not have a index one will be automatically assigned. The index value is valid
940 until the termination of the shell application.
942 @param[in] TheHandle The handle to retrieve an index for.
944 @retval 0 A memory allocation failed.
945 @return The index of the handle.
950 ConvertHandleToHandleIndex(
951 IN CONST EFI_HANDLE TheHandle
955 EFI_GUID
**ProtocolBuffer
;
957 HANDLE_LIST
*ListWalker
;
959 if (TheHandle
== NULL
) {
963 InternalShellInitHandleList();
965 for (ListWalker
= (HANDLE_LIST
*)GetFirstNode(&mHandleList
.List
.Link
)
966 ; !IsNull(&mHandleList
.List
.Link
,&ListWalker
->Link
)
967 ; ListWalker
= (HANDLE_LIST
*)GetNextNode(&mHandleList
.List
.Link
,&ListWalker
->Link
)
969 if (ListWalker
->TheHandle
== TheHandle
) {
971 // Verify that TheHandle is still present in the Handle Database
973 Status
= gBS
->ProtocolsPerHandle(TheHandle
, &ProtocolBuffer
, &ProtocolCount
);
974 if (EFI_ERROR (Status
)) {
976 // TheHandle is not present in the Handle Database, so delete from the handle list
978 RemoveEntryList (&ListWalker
->Link
);
981 FreePool (ProtocolBuffer
);
982 return (ListWalker
->TheIndex
);
987 // Verify that TheHandle is valid handle
989 Status
= gBS
->ProtocolsPerHandle(TheHandle
, &ProtocolBuffer
, &ProtocolCount
);
990 if (EFI_ERROR (Status
)) {
992 // TheHandle is not valid, so do not add to handle list
996 FreePool (ProtocolBuffer
);
998 ListWalker
= AllocateZeroPool(sizeof(HANDLE_LIST
));
999 ASSERT(ListWalker
!= NULL
);
1000 ListWalker
->TheHandle
= TheHandle
;
1001 ListWalker
->TheIndex
= mHandleList
.NextIndex
++;
1002 InsertTailList(&mHandleList
.List
.Link
,&ListWalker
->Link
);
1003 return (ListWalker
->TheIndex
);
1009 Function to retrieve the EFI_HANDLE from the human-friendly index.
1011 @param[in] TheIndex The index to retrieve the EFI_HANDLE for.
1013 @retval NULL The index was invalid.
1014 @return The EFI_HANDLE that index represents.
1019 ConvertHandleIndexToHandle(
1020 IN CONST UINTN TheIndex
1024 EFI_GUID
**ProtocolBuffer
;
1025 UINTN ProtocolCount
;
1026 HANDLE_LIST
*ListWalker
;
1028 InternalShellInitHandleList();
1030 if (TheIndex
>= mHandleList
.NextIndex
) {
1034 for (ListWalker
= (HANDLE_LIST
*)GetFirstNode(&mHandleList
.List
.Link
)
1035 ; !IsNull(&mHandleList
.List
.Link
,&ListWalker
->Link
)
1036 ; ListWalker
= (HANDLE_LIST
*)GetNextNode(&mHandleList
.List
.Link
,&ListWalker
->Link
)
1038 if (ListWalker
->TheIndex
== TheIndex
&& ListWalker
->TheHandle
!= NULL
) {
1040 // Verify that LinkWalker->TheHandle is valid handle
1042 Status
= gBS
->ProtocolsPerHandle(ListWalker
->TheHandle
, &ProtocolBuffer
, &ProtocolCount
);
1043 if (EFI_ERROR (Status
)) {
1045 // TheHandle is not valid, so do not add to handle list
1047 ListWalker
->TheHandle
= NULL
;
1049 return (ListWalker
->TheHandle
);
1056 Gets all the related EFI_HANDLEs based on the mask supplied.
1058 This function scans all EFI_HANDLES in the UEFI environment's handle database
1059 and returns the ones with the specified relationship (Mask) to the specified
1062 If both DriverBindingHandle and ControllerHandle are NULL, then ASSERT.
1063 If MatchingHandleCount is NULL, then ASSERT.
1065 If MatchingHandleBuffer is not NULL upon a successful return the memory must be
1068 @param[in] DriverBindingHandle The handle with Driver Binding protocol on it.
1069 @param[in] ControllerHandle The handle with Device Path protocol on it.
1070 @param[in] MatchingHandleCount The pointer to UINTN that specifies the number of HANDLES in
1071 MatchingHandleBuffer.
1072 @param[out] MatchingHandleBuffer On a successful return, a buffer of MatchingHandleCount
1073 EFI_HANDLEs with a terminating NULL EFI_HANDLE.
1074 @param[out] HandleType An array of type information.
1076 @retval EFI_SUCCESS The operation was successful, and any related handles
1077 are in MatchingHandleBuffer.
1078 @retval EFI_NOT_FOUND No matching handles were found.
1079 @retval EFI_INVALID_PARAMETER A parameter was invalid or out of range.
1083 ParseHandleDatabaseByRelationshipWithType (
1084 IN CONST EFI_HANDLE DriverBindingHandle OPTIONAL
,
1085 IN CONST EFI_HANDLE ControllerHandle OPTIONAL
,
1086 IN UINTN
*HandleCount
,
1087 OUT EFI_HANDLE
**HandleBuffer
,
1088 OUT UINTN
**HandleType
1093 EFI_GUID
**ProtocolGuidArray
;
1095 UINTN ProtocolIndex
;
1096 EFI_OPEN_PROTOCOL_INFORMATION_ENTRY
*OpenInfo
;
1097 UINTN OpenInfoCount
;
1098 UINTN OpenInfoIndex
;
1100 INTN DriverBindingHandleIndex
;
1102 ASSERT(HandleCount
!= NULL
);
1103 ASSERT(HandleBuffer
!= NULL
);
1104 ASSERT(HandleType
!= NULL
);
1105 ASSERT(DriverBindingHandle
!= NULL
|| ControllerHandle
!= NULL
);
1108 *HandleBuffer
= NULL
;
1112 // Retrieve the list of all handles from the handle database
1114 Status
= gBS
->LocateHandleBuffer (
1121 if (EFI_ERROR (Status
)) {
1125 *HandleType
= AllocateZeroPool (*HandleCount
* sizeof (UINTN
));
1126 ASSERT(*HandleType
!= NULL
);
1128 DriverBindingHandleIndex
= -1;
1129 for (HandleIndex
= 0; HandleIndex
< *HandleCount
; HandleIndex
++) {
1130 if (DriverBindingHandle
!= NULL
&& (*HandleBuffer
)[HandleIndex
] == DriverBindingHandle
) {
1131 DriverBindingHandleIndex
= (INTN
)HandleIndex
;
1135 for (HandleIndex
= 0; HandleIndex
< *HandleCount
; HandleIndex
++) {
1137 // Retrieve the list of all the protocols on each handle
1139 Status
= gBS
->ProtocolsPerHandle (
1140 (*HandleBuffer
)[HandleIndex
],
1144 if (EFI_ERROR (Status
)) {
1148 for (ProtocolIndex
= 0; ProtocolIndex
< ArrayCount
; ProtocolIndex
++) {
1151 // Set the bit describing what this handle has
1153 if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiLoadedImageProtocolGuid
) ) {
1154 (*HandleType
)[HandleIndex
] |= HR_IMAGE_HANDLE
;
1155 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiDriverBindingProtocolGuid
) ) {
1156 (*HandleType
)[HandleIndex
] |= HR_DRIVER_BINDING_HANDLE
;
1157 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiDriverConfiguration2ProtocolGuid
)) {
1158 (*HandleType
)[HandleIndex
] |= HR_DRIVER_CONFIGURATION_HANDLE
;
1159 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiDriverConfigurationProtocolGuid
) ) {
1160 (*HandleType
)[HandleIndex
] |= HR_DRIVER_CONFIGURATION_HANDLE
;
1161 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiDriverDiagnostics2ProtocolGuid
) ) {
1162 (*HandleType
)[HandleIndex
] |= HR_DRIVER_DIAGNOSTICS_HANDLE
;
1163 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiDriverDiagnosticsProtocolGuid
) ) {
1164 (*HandleType
)[HandleIndex
] |= HR_DRIVER_DIAGNOSTICS_HANDLE
;
1165 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiComponentName2ProtocolGuid
) ) {
1166 (*HandleType
)[HandleIndex
] |= HR_COMPONENT_NAME_HANDLE
;
1167 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiComponentNameProtocolGuid
) ) {
1168 (*HandleType
)[HandleIndex
] |= HR_COMPONENT_NAME_HANDLE
;
1169 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiDevicePathProtocolGuid
) ) {
1170 (*HandleType
)[HandleIndex
] |= HR_DEVICE_HANDLE
;
1173 ASSERT((*HandleType
)[HandleIndex
] == (*HandleType
)[HandleIndex
]);
1177 // Retrieve the list of agents that have opened each protocol
1179 Status
= gBS
->OpenProtocolInformation (
1180 (*HandleBuffer
)[HandleIndex
],
1181 ProtocolGuidArray
[ProtocolIndex
],
1185 if (EFI_ERROR (Status
)) {
1189 if (ControllerHandle
== NULL
) {
1191 // ControllerHandle == NULL and DriverBindingHandle != NULL.
1192 // Return information on all the controller handles that the driver specified by DriverBindingHandle is managing
1194 for (OpenInfoIndex
= 0; OpenInfoIndex
< OpenInfoCount
; OpenInfoIndex
++) {
1195 if (OpenInfo
[OpenInfoIndex
].AgentHandle
== DriverBindingHandle
&& (OpenInfo
[OpenInfoIndex
].Attributes
& EFI_OPEN_PROTOCOL_BY_DRIVER
) != 0) {
1196 (*HandleType
)[HandleIndex
] |= (HR_DEVICE_HANDLE
| HR_CONTROLLER_HANDLE
);
1197 if (DriverBindingHandleIndex
!= -1) {
1198 (*HandleType
)[DriverBindingHandleIndex
] |= HR_DEVICE_DRIVER
;
1201 if (OpenInfo
[OpenInfoIndex
].AgentHandle
== DriverBindingHandle
&& (OpenInfo
[OpenInfoIndex
].Attributes
& EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
) != 0) {
1202 (*HandleType
)[HandleIndex
] |= (HR_DEVICE_HANDLE
| HR_CONTROLLER_HANDLE
);
1203 if (DriverBindingHandleIndex
!= -1) {
1204 (*HandleType
)[DriverBindingHandleIndex
] |= (HR_BUS_DRIVER
| HR_DEVICE_DRIVER
);
1206 for (ChildIndex
= 0; ChildIndex
< *HandleCount
; ChildIndex
++) {
1207 if (OpenInfo
[OpenInfoIndex
].ControllerHandle
== (*HandleBuffer
)[ChildIndex
]) {
1208 (*HandleType
)[ChildIndex
] |= (HR_DEVICE_HANDLE
| HR_CHILD_HANDLE
);
1214 if (DriverBindingHandle
== NULL
&& ControllerHandle
!= NULL
) {
1215 if (ControllerHandle
== (*HandleBuffer
)[HandleIndex
]) {
1216 (*HandleType
)[HandleIndex
] |= (HR_DEVICE_HANDLE
| HR_CONTROLLER_HANDLE
);
1217 for (OpenInfoIndex
= 0; OpenInfoIndex
< OpenInfoCount
; OpenInfoIndex
++) {
1218 if ((OpenInfo
[OpenInfoIndex
].Attributes
& EFI_OPEN_PROTOCOL_BY_DRIVER
) != 0) {
1219 for (ChildIndex
= 0; ChildIndex
< *HandleCount
; ChildIndex
++) {
1220 if (OpenInfo
[OpenInfoIndex
].AgentHandle
== (*HandleBuffer
)[ChildIndex
]) {
1221 (*HandleType
)[ChildIndex
] |= HR_DEVICE_DRIVER
;
1225 if ((OpenInfo
[OpenInfoIndex
].Attributes
& EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
) != 0) {
1226 for (ChildIndex
= 0; ChildIndex
< *HandleCount
; ChildIndex
++) {
1227 if (OpenInfo
[OpenInfoIndex
].AgentHandle
== (*HandleBuffer
)[ChildIndex
]) {
1228 (*HandleType
)[ChildIndex
] |= (HR_BUS_DRIVER
| HR_DEVICE_DRIVER
);
1230 if (OpenInfo
[OpenInfoIndex
].ControllerHandle
== (*HandleBuffer
)[ChildIndex
]) {
1231 (*HandleType
)[ChildIndex
] |= (HR_DEVICE_HANDLE
| HR_CHILD_HANDLE
);
1237 for (OpenInfoIndex
= 0; OpenInfoIndex
< OpenInfoCount
; OpenInfoIndex
++) {
1238 if ((OpenInfo
[OpenInfoIndex
].Attributes
& EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
) != 0) {
1239 if (OpenInfo
[OpenInfoIndex
].ControllerHandle
== ControllerHandle
) {
1240 (*HandleType
)[HandleIndex
] |= (HR_DEVICE_HANDLE
| HR_PARENT_HANDLE
);
1246 if (DriverBindingHandle
!= NULL
&& ControllerHandle
!= NULL
) {
1247 if (ControllerHandle
== (*HandleBuffer
)[HandleIndex
]) {
1248 (*HandleType
)[HandleIndex
] |= (HR_DEVICE_HANDLE
| HR_CONTROLLER_HANDLE
);
1249 for (OpenInfoIndex
= 0; OpenInfoIndex
< OpenInfoCount
; OpenInfoIndex
++) {
1250 if ((OpenInfo
[OpenInfoIndex
].Attributes
& EFI_OPEN_PROTOCOL_BY_DRIVER
) != 0) {
1251 if (OpenInfo
[OpenInfoIndex
].AgentHandle
== DriverBindingHandle
) {
1252 if (DriverBindingHandleIndex
!= -1) {
1253 (*HandleType
)[DriverBindingHandleIndex
] |= HR_DEVICE_DRIVER
;
1257 if ((OpenInfo
[OpenInfoIndex
].Attributes
& EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
) != 0) {
1258 if (OpenInfo
[OpenInfoIndex
].AgentHandle
== DriverBindingHandle
) {
1259 for (ChildIndex
= 0; ChildIndex
< *HandleCount
; ChildIndex
++) {
1260 if (OpenInfo
[OpenInfoIndex
].ControllerHandle
== (*HandleBuffer
)[ChildIndex
]) {
1261 (*HandleType
)[ChildIndex
] |= (HR_DEVICE_HANDLE
| HR_CHILD_HANDLE
);
1266 for (ChildIndex
= 0; ChildIndex
< *HandleCount
; ChildIndex
++) {
1267 if (OpenInfo
[OpenInfoIndex
].AgentHandle
== (*HandleBuffer
)[ChildIndex
]) {
1268 (*HandleType
)[ChildIndex
] |= (HR_BUS_DRIVER
| HR_DEVICE_DRIVER
);
1274 for (OpenInfoIndex
= 0; OpenInfoIndex
< OpenInfoCount
; OpenInfoIndex
++) {
1275 if ((OpenInfo
[OpenInfoIndex
].Attributes
& EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
) != 0) {
1276 if (OpenInfo
[OpenInfoIndex
].ControllerHandle
== ControllerHandle
) {
1277 (*HandleType
)[HandleIndex
] |= (HR_DEVICE_HANDLE
| HR_PARENT_HANDLE
);
1283 FreePool (OpenInfo
);
1285 FreePool (ProtocolGuidArray
);
1291 Gets all the related EFI_HANDLEs based on the single EFI_HANDLE and the mask
1294 This function will scan all EFI_HANDLES in the UEFI environment's handle database
1295 and return all the ones with the specified relationship (Mask) to the specified
1298 If both DriverBindingHandle and ControllerHandle are NULL, then ASSERT.
1299 If MatchingHandleCount is NULL, then ASSERT.
1301 If MatchingHandleBuffer is not NULL upon a sucessful return the memory must be
1304 @param[in] DriverBindingHandle Handle to a object with Driver Binding protocol
1306 @param[in] ControllerHandle Handle to a device with Device Path protocol on it.
1307 @param[in] Mask Mask of what relationship(s) is desired.
1308 @param[in] MatchingHandleCount Poitner to UINTN specifying number of HANDLES in
1309 MatchingHandleBuffer.
1310 @param[out] MatchingHandleBuffer On a sucessful return a buffer of MatchingHandleCount
1311 EFI_HANDLEs and a terminating NULL EFI_HANDLE.
1313 @retval EFI_SUCCESS The operation was sucessful and any related handles
1314 are in MatchingHandleBuffer;
1315 @retval EFI_NOT_FOUND No matching handles were found.
1316 @retval EFI_INVALID_PARAMETER A parameter was invalid or out of range.
1320 ParseHandleDatabaseByRelationship (
1321 IN CONST EFI_HANDLE DriverBindingHandle OPTIONAL
,
1322 IN CONST EFI_HANDLE ControllerHandle OPTIONAL
,
1323 IN CONST UINTN Mask
,
1324 IN UINTN
*MatchingHandleCount
,
1325 OUT EFI_HANDLE
**MatchingHandleBuffer OPTIONAL
1330 EFI_HANDLE
*HandleBuffer
;
1334 ASSERT(MatchingHandleCount
!= NULL
);
1335 ASSERT(DriverBindingHandle
!= NULL
|| ControllerHandle
!= NULL
);
1337 if ((Mask
& HR_VALID_MASK
) != Mask
) {
1338 return (EFI_INVALID_PARAMETER
);
1341 if ((Mask
& HR_CHILD_HANDLE
) != 0 && DriverBindingHandle
== NULL
) {
1342 return (EFI_INVALID_PARAMETER
);
1345 *MatchingHandleCount
= 0;
1346 if (MatchingHandleBuffer
!= NULL
) {
1347 *MatchingHandleBuffer
= NULL
;
1350 HandleBuffer
= NULL
;
1353 Status
= ParseHandleDatabaseByRelationshipWithType (
1354 DriverBindingHandle
,
1360 if (!EFI_ERROR (Status
)) {
1362 // Count the number of handles that match the attributes in Mask
1364 for (HandleIndex
= 0; HandleIndex
< HandleCount
; HandleIndex
++) {
1365 if ((HandleType
[HandleIndex
] & Mask
) == Mask
) {
1366 (*MatchingHandleCount
)++;
1370 // If no handles match the attributes in Mask then return EFI_NOT_FOUND
1372 if (*MatchingHandleCount
== 0) {
1373 Status
= EFI_NOT_FOUND
;
1376 if (MatchingHandleBuffer
== NULL
) {
1378 // Someone just wanted the count...
1380 Status
= EFI_SUCCESS
;
1383 // Allocate a handle buffer for the number of handles that matched the attributes in Mask
1385 *MatchingHandleBuffer
= AllocateZeroPool ((*MatchingHandleCount
+1)* sizeof (EFI_HANDLE
));
1386 ASSERT(*MatchingHandleBuffer
!= NULL
);
1388 for (HandleIndex
= 0,*MatchingHandleCount
= 0
1389 ; HandleIndex
< HandleCount
1393 // Fill the allocated buffer with the handles that matched the attributes in Mask
1395 if ((HandleType
[HandleIndex
] & Mask
) == Mask
) {
1396 (*MatchingHandleBuffer
)[(*MatchingHandleCount
)++] = HandleBuffer
[HandleIndex
];
1401 // Make the last one NULL
1403 (*MatchingHandleBuffer
)[*MatchingHandleCount
] = NULL
;
1405 Status
= EFI_SUCCESS
;
1406 } // MacthingHandleBuffer == NULL (ELSE)
1407 } // *MatchingHandleCount == 0 (ELSE)
1408 } // no error on ParseHandleDatabaseByRelationshipWithType
1410 if (HandleBuffer
!= NULL
) {
1411 FreePool (HandleBuffer
);
1414 if (HandleType
!= NULL
) {
1415 FreePool (HandleType
);
1422 Gets handles for any child controllers of the passed in controller.
1424 @param[in] ControllerHandle The handle of the "parent controller"
1425 @param[in] MatchingHandleCount Pointer to the number of handles in
1426 MatchingHandleBuffer on return.
1427 @param[out] MatchingHandleBuffer Buffer containing handles on a successful
1431 @retval EFI_SUCCESS The operation was sucessful.
1435 ParseHandleDatabaseForChildControllers(
1436 IN CONST EFI_HANDLE ControllerHandle
,
1437 IN UINTN
*MatchingHandleCount
,
1438 OUT EFI_HANDLE
**MatchingHandleBuffer OPTIONAL
1443 UINTN DriverBindingHandleCount
;
1444 EFI_HANDLE
*DriverBindingHandleBuffer
;
1445 UINTN DriverBindingHandleIndex
;
1446 UINTN ChildControllerHandleCount
;
1447 EFI_HANDLE
*ChildControllerHandleBuffer
;
1448 UINTN ChildControllerHandleIndex
;
1449 EFI_HANDLE
*HandleBufferForReturn
;
1451 if (MatchingHandleCount
== NULL
) {
1452 return (EFI_INVALID_PARAMETER
);
1454 *MatchingHandleCount
= 0;
1456 Status
= PARSE_HANDLE_DATABASE_UEFI_DRIVERS (
1458 &DriverBindingHandleCount
,
1459 &DriverBindingHandleBuffer
1461 if (EFI_ERROR (Status
)) {
1466 // Get a buffer big enough for all the controllers.
1468 HandleBufferForReturn
= GetHandleListByProtocol(NULL
);
1469 if (HandleBufferForReturn
== NULL
) {
1470 FreePool (DriverBindingHandleBuffer
);
1471 return (EFI_NOT_FOUND
);
1474 for (DriverBindingHandleIndex
= 0; DriverBindingHandleIndex
< DriverBindingHandleCount
; DriverBindingHandleIndex
++) {
1475 Status
= PARSE_HANDLE_DATABASE_MANAGED_CHILDREN (
1476 DriverBindingHandleBuffer
[DriverBindingHandleIndex
],
1478 &ChildControllerHandleCount
,
1479 &ChildControllerHandleBuffer
1481 if (EFI_ERROR (Status
)) {
1485 for (ChildControllerHandleIndex
= 0;
1486 ChildControllerHandleIndex
< ChildControllerHandleCount
;
1487 ChildControllerHandleIndex
++
1489 for (HandleIndex
= 0; HandleIndex
< *MatchingHandleCount
; HandleIndex
++) {
1490 if (HandleBufferForReturn
[HandleIndex
] == ChildControllerHandleBuffer
[ChildControllerHandleIndex
]) {
1494 if (HandleIndex
>= *MatchingHandleCount
) {
1495 HandleBufferForReturn
[(*MatchingHandleCount
)++] = ChildControllerHandleBuffer
[ChildControllerHandleIndex
];
1499 FreePool (ChildControllerHandleBuffer
);
1502 FreePool (DriverBindingHandleBuffer
);
1504 if (MatchingHandleBuffer
!= NULL
) {
1505 *MatchingHandleBuffer
= HandleBufferForReturn
;
1507 FreePool(HandleBufferForReturn
);
1510 return (EFI_SUCCESS
);
1514 Appends 1 buffer to another buffer. This will re-allocate the destination buffer
1515 if necessary to fit all of the data.
1517 If DestinationBuffer is NULL, then ASSERT().
1519 @param[in, out] DestinationBuffer The pointer to the pointer to the buffer to append onto.
1520 @param[in, out] DestinationSize The pointer to the size of DestinationBuffer.
1521 @param[in] SourceBuffer The pointer to the buffer to append onto DestinationBuffer.
1522 @param[in] SourceSize The number of bytes of SourceBuffer to append.
1524 @retval NULL A memory allocation failed.
1525 @retval NULL A parameter was invalid.
1526 @return A pointer to (*DestinationBuffer).
1531 IN OUT VOID
**DestinationBuffer
,
1532 IN OUT UINTN
*DestinationSize
,
1533 IN VOID
*SourceBuffer
,
1537 UINTN LocalDestinationSize
;
1538 UINTN LocalDestinationFinalSize
;
1540 ASSERT(DestinationBuffer
!= NULL
);
1542 if (SourceSize
== 0 || SourceBuffer
== NULL
) {
1543 return (*DestinationBuffer
);
1546 if (DestinationSize
== NULL
) {
1547 LocalDestinationSize
= 0;
1549 LocalDestinationSize
= *DestinationSize
;
1552 LocalDestinationFinalSize
= LocalDestinationSize
+ SourceSize
;
1554 if (DestinationSize
!= NULL
) {
1555 *DestinationSize
= LocalDestinationSize
;
1558 if (LocalDestinationSize
== 0) {
1560 *DestinationBuffer
= AllocateZeroPool(LocalDestinationFinalSize
);
1563 *DestinationBuffer
= ReallocatePool(LocalDestinationSize
, LocalDestinationFinalSize
, *DestinationBuffer
);
1566 ASSERT(*DestinationBuffer
!= NULL
);
1569 return (CopyMem(((UINT8
*)(*DestinationBuffer
)) + LocalDestinationSize
, SourceBuffer
, SourceSize
));
1573 Gets handles for any child devices produced by the passed in driver.
1575 @param[in] DriverHandle The handle of the driver.
1576 @param[in] MatchingHandleCount Pointer to the number of handles in
1577 MatchingHandleBuffer on return.
1578 @param[out] MatchingHandleBuffer Buffer containing handles on a successful
1580 @retval EFI_SUCCESS The operation was sucessful.
1581 @sa ParseHandleDatabaseByRelationship
1585 ParseHandleDatabaseForChildDevices(
1586 IN CONST EFI_HANDLE DriverHandle
,
1587 IN UINTN
*MatchingHandleCount
,
1588 OUT EFI_HANDLE
**MatchingHandleBuffer OPTIONAL
1592 EFI_HANDLE
*Buffer2
;
1597 UINTN HandleBufferSize
;
1599 ASSERT(MatchingHandleCount
!= NULL
);
1601 HandleBufferSize
= 0;
1604 *MatchingHandleCount
= 0;
1606 Status
= PARSE_HANDLE_DATABASE_DEVICES (
1611 if (!EFI_ERROR (Status
)) {
1612 for (HandleIndex
= 0; HandleIndex
< Count1
; HandleIndex
++) {
1614 // now find the children
1616 Status
= PARSE_HANDLE_DATABASE_MANAGED_CHILDREN (
1618 Buffer
[HandleIndex
],
1622 if (EFI_ERROR(Status
)) {
1626 // save out required and optional data elements
1628 *MatchingHandleCount
+= Count2
;
1629 if (MatchingHandleBuffer
!= NULL
) {
1630 *MatchingHandleBuffer
= BuffernCatGrow((VOID
**)MatchingHandleBuffer
, &HandleBufferSize
, Buffer2
, Count2
* sizeof(Buffer2
[0]));
1636 if (Buffer2
!= NULL
) {
1642 if (Buffer
!= NULL
) {
1649 Function to get all handles that support a given protocol or all handles.
1651 @param[in] ProtocolGuid The guid of the protocol to get handles for. If NULL
1652 then the function will return all handles.
1654 @retval NULL A memory allocation failed.
1655 @return A NULL terminated list of handles.
1659 GetHandleListByProtocol (
1660 IN CONST EFI_GUID
*ProtocolGuid OPTIONAL
1663 EFI_HANDLE
*HandleList
;
1671 // We cannot use LocateHandleBuffer since we need that NULL item on the ends of the list!
1673 if (ProtocolGuid
== NULL
) {
1674 Status
= gBS
->LocateHandle(AllHandles
, NULL
, NULL
, &Size
, HandleList
);
1675 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1676 HandleList
= AllocateZeroPool(Size
+ sizeof(EFI_HANDLE
));
1677 if (HandleList
== NULL
) {
1680 Status
= gBS
->LocateHandle(AllHandles
, NULL
, NULL
, &Size
, HandleList
);
1681 HandleList
[Size
/sizeof(EFI_HANDLE
)] = NULL
;
1684 Status
= gBS
->LocateHandle(ByProtocol
, (EFI_GUID
*)ProtocolGuid
, NULL
, &Size
, HandleList
);
1685 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1686 HandleList
= AllocateZeroPool(Size
+ sizeof(EFI_HANDLE
));
1687 if (HandleList
== NULL
) {
1690 Status
= gBS
->LocateHandle(ByProtocol
, (EFI_GUID
*)ProtocolGuid
, NULL
, &Size
, HandleList
);
1691 HandleList
[Size
/sizeof(EFI_HANDLE
)] = NULL
;
1694 if (EFI_ERROR(Status
)) {
1695 if (HandleList
!= NULL
) {
1696 FreePool(HandleList
);
1700 return (HandleList
);
1704 Function to get all handles that support some protocols.
1706 @param[in] ProtocolGuids A NULL terminated list of protocol GUIDs.
1708 @retval NULL A memory allocation failed.
1709 @retval NULL ProtocolGuids was NULL.
1710 @return A NULL terminated list of EFI_HANDLEs.
1714 GetHandleListByProtocolList (
1715 IN CONST EFI_GUID
**ProtocolGuids
1718 EFI_HANDLE
*HandleList
;
1723 CONST EFI_GUID
**GuidWalker
;
1724 EFI_HANDLE
*HandleWalker1
;
1725 EFI_HANDLE
*HandleWalker2
;
1729 TotalSize
= sizeof(EFI_HANDLE
);
1731 for (GuidWalker
= ProtocolGuids
; GuidWalker
!= NULL
&& *GuidWalker
!= NULL
; GuidWalker
++,Size
= 0){
1732 Status
= gBS
->LocateHandle(ByProtocol
, (EFI_GUID
*)(*GuidWalker
), NULL
, &Size
, NULL
);
1733 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1739 // No handles were found...
1741 if (TotalSize
== sizeof(EFI_HANDLE
)) {
1745 HandleList
= AllocateZeroPool(TotalSize
);
1746 if (HandleList
== NULL
) {
1751 for (GuidWalker
= ProtocolGuids
; GuidWalker
!= NULL
&& *GuidWalker
!= NULL
; GuidWalker
++){
1752 TempSize
= TotalSize
- Size
;
1753 Status
= gBS
->LocateHandle(ByProtocol
, (EFI_GUID
*)(*GuidWalker
), NULL
, &TempSize
, HandleList
+(Size
/sizeof(EFI_HANDLE
)));
1756 // Allow for missing protocols... Only update the 'used' size upon success.
1758 if (!EFI_ERROR(Status
)) {
1762 ASSERT(HandleList
[(TotalSize
/sizeof(EFI_HANDLE
))-1] == NULL
);
1764 for (HandleWalker1
= HandleList
; HandleWalker1
!= NULL
&& *HandleWalker1
!= NULL
; HandleWalker1
++) {
1765 for (HandleWalker2
= HandleWalker1
+ 1; HandleWalker2
!= NULL
&& *HandleWalker2
!= NULL
; HandleWalker2
++) {
1766 if (*HandleWalker1
== *HandleWalker2
) {
1768 // copy memory back 1 handle width.
1770 CopyMem(HandleWalker2
, HandleWalker2
+ 1, TotalSize
- ((HandleWalker2
-HandleList
+1)*sizeof(EFI_HANDLE
)));
1775 return (HandleList
);