2 Provides interface to advanced shell functionality for parsing both handle and protocol database.
4 Copyright (c) 2013 - 2014, Hewlett-Packard Development Company, L.P.<BR>
5 Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "UefiHandleParsingLib.h"
17 #include "IndustryStandard/Acpi10.h"
19 EFI_HANDLE mHandleParsingHiiHandle
= NULL
;
20 HANDLE_INDEX_LIST mHandleList
= {{{NULL
,NULL
},0,0},0};
21 GUID_INFO_BLOCK
*GuidList
;
24 Function to translate the EFI_MEMORY_TYPE into a string.
26 @param[in] Memory The memory type.
28 @retval A string representation of the type allocated from BS Pool.
33 IN CONST EFI_MEMORY_TYPE Memory
40 case EfiReservedMemoryType
: StrnCatGrow(&RetVal
, NULL
, L
"EfiReservedMemoryType", 0); break;
41 case EfiLoaderCode
: StrnCatGrow(&RetVal
, NULL
, L
"EfiLoaderCode", 0); break;
42 case EfiLoaderData
: StrnCatGrow(&RetVal
, NULL
, L
"EfiLoaderData", 0); break;
43 case EfiBootServicesCode
: StrnCatGrow(&RetVal
, NULL
, L
"EfiBootServicesCode", 0); break;
44 case EfiBootServicesData
: StrnCatGrow(&RetVal
, NULL
, L
"EfiBootServicesData", 0); break;
45 case EfiRuntimeServicesCode
: StrnCatGrow(&RetVal
, NULL
, L
"EfiRuntimeServicesCode", 0); break;
46 case EfiRuntimeServicesData
: StrnCatGrow(&RetVal
, NULL
, L
"EfiRuntimeServicesData", 0); break;
47 case EfiConventionalMemory
: StrnCatGrow(&RetVal
, NULL
, L
"EfiConventionalMemory", 0); break;
48 case EfiUnusableMemory
: StrnCatGrow(&RetVal
, NULL
, L
"EfiUnusableMemory", 0); break;
49 case EfiACPIReclaimMemory
: StrnCatGrow(&RetVal
, NULL
, L
"EfiACPIReclaimMemory", 0); break;
50 case EfiACPIMemoryNVS
: StrnCatGrow(&RetVal
, NULL
, L
"EfiACPIMemoryNVS", 0); break;
51 case EfiMemoryMappedIO
: StrnCatGrow(&RetVal
, NULL
, L
"EfiMemoryMappedIO", 0); break;
52 case EfiMemoryMappedIOPortSpace
: StrnCatGrow(&RetVal
, NULL
, L
"EfiMemoryMappedIOPortSpace", 0); break;
53 case EfiPalCode
: StrnCatGrow(&RetVal
, NULL
, L
"EfiPalCode", 0); break;
54 case EfiMaxMemoryType
: StrnCatGrow(&RetVal
, NULL
, L
"EfiMaxMemoryType", 0); break;
55 default: ASSERT(FALSE
);
61 Function to translate the EFI_GRAPHICS_PIXEL_FORMAT into a string.
63 @param[in] Fmt The format type.
65 @retval A string representation of the type allocated from BS Pool.
70 IN CONST EFI_GRAPHICS_PIXEL_FORMAT Fmt
77 case PixelRedGreenBlueReserved8BitPerColor
: StrnCatGrow(&RetVal
, NULL
, L
"PixelRedGreenBlueReserved8BitPerColor", 0); break;
78 case PixelBlueGreenRedReserved8BitPerColor
: StrnCatGrow(&RetVal
, NULL
, L
"PixelBlueGreenRedReserved8BitPerColor", 0); break;
79 case PixelBitMask
: StrnCatGrow(&RetVal
, NULL
, L
"PixelBitMask", 0); break;
80 case PixelBltOnly
: StrnCatGrow(&RetVal
, NULL
, L
"PixelBltOnly", 0); break;
81 case PixelFormatMax
: StrnCatGrow(&RetVal
, NULL
, L
"PixelFormatMax", 0); break;
82 default: ASSERT(FALSE
);
88 Constructor for the library.
90 @param[in] ImageHandle Ignored.
91 @param[in] SystemTable Ignored.
93 @retval EFI_SUCCESS The operation was successful.
97 HandleParsingLibConstructor (
98 IN EFI_HANDLE ImageHandle
,
99 IN EFI_SYSTEM_TABLE
*SystemTable
106 // Do nothing with mHandleParsingHiiHandle. Initialize HII as needed.
108 return (EFI_SUCCESS
);
112 Initialization function for HII packages.
116 HandleParsingHiiInit (VOID
)
118 if (mHandleParsingHiiHandle
== NULL
) {
119 mHandleParsingHiiHandle
= HiiAddPackages (&gHandleParsingHiiGuid
, gImageHandle
, UefiHandleParsingLibStrings
, NULL
);
120 ASSERT (mHandleParsingHiiHandle
!= NULL
);
125 Destructor for the library. free any resources.
127 @param[in] ImageHandle Ignored.
128 @param[in] SystemTable Ignored.
130 @retval EFI_SUCCESS The operation was successful.
134 HandleParsingLibDestructor (
135 IN EFI_HANDLE ImageHandle
,
136 IN EFI_SYSTEM_TABLE
*SystemTable
141 for (LoopCount
= 0; GuidList
!= NULL
&& LoopCount
< GuidListCount
; LoopCount
++) {
142 SHELL_FREE_NON_NULL(GuidList
[LoopCount
].GuidId
);
145 SHELL_FREE_NON_NULL(GuidList
);
146 if (mHandleParsingHiiHandle
!= NULL
) {
147 HiiRemovePackages(mHandleParsingHiiHandle
);
149 return (EFI_SUCCESS
);
153 Function to dump information about LoadedImage.
155 This will allocate the return buffer from boot services pool.
157 @param[in] TheHandle The handle that has LoadedImage installed.
158 @param[in] Verbose TRUE for additional information, FALSE otherwise.
160 @retval A poitner to a string containing the information.
164 LoadedImageProtocolDumpInformation(
165 IN CONST EFI_HANDLE TheHandle
,
166 IN CONST BOOLEAN Verbose
169 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
177 return (CatSPrint(NULL
, L
"LoadedImage"));
180 HandleParsingHiiInit();
182 Temp
= HiiGetString(mHandleParsingHiiHandle
, STRING_TOKEN(STR_LI_DUMP_MAIN
), NULL
);
183 RetVal
= AllocateZeroPool (PcdGet16 (PcdShellPrintBufferSize
));
184 if (Temp
== NULL
|| RetVal
== NULL
) {
185 SHELL_FREE_NON_NULL(Temp
);
186 SHELL_FREE_NON_NULL(RetVal
);
190 Status
= gBS
->OpenProtocol (
192 &gEfiLoadedImageProtocolGuid
,
193 (VOID
**)&LoadedImage
,
196 EFI_OPEN_PROTOCOL_GET_PROTOCOL
199 if (EFI_ERROR (Status
)) {
200 SHELL_FREE_NON_NULL (Temp
);
201 SHELL_FREE_NON_NULL (RetVal
);
205 DataType
= ConvertMemoryType(LoadedImage
->ImageDataType
);
206 CodeType
= ConvertMemoryType(LoadedImage
->ImageCodeType
);
208 RetVal
= CatSPrint(RetVal
,
210 LoadedImage
->Revision
,
211 LoadedImage
->ParentHandle
,
212 LoadedImage
->SystemTable
,
213 LoadedImage
->DeviceHandle
,
214 LoadedImage
->FilePath
,
215 LoadedImage
->LoadOptionsSize
,
216 LoadedImage
->LoadOptions
,
217 LoadedImage
->ImageBase
,
218 LoadedImage
->ImageSize
,
221 LoadedImage
->Unload
);
224 SHELL_FREE_NON_NULL(Temp
);
225 SHELL_FREE_NON_NULL(CodeType
);
226 SHELL_FREE_NON_NULL(DataType
);
232 Function to dump information about GOP.
234 This will allocate the return buffer from boot services pool.
236 @param[in] TheHandle The handle that has LoadedImage installed.
237 @param[in] Verbose TRUE for additional information, FALSE otherwise.
239 @retval A poitner to a string containing the information.
243 GraphicsOutputProtocolDumpInformation(
244 IN CONST EFI_HANDLE TheHandle
,
245 IN CONST BOOLEAN Verbose
248 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
255 return (CatSPrint(NULL
, L
"GraphicsOutput"));
258 HandleParsingHiiInit();
260 Temp
= HiiGetString(mHandleParsingHiiHandle
, STRING_TOKEN(STR_GOP_DUMP_MAIN
), NULL
);
261 RetVal
= AllocateZeroPool (PcdGet16 (PcdShellPrintBufferSize
));
262 if (Temp
== NULL
|| RetVal
== NULL
) {
263 SHELL_FREE_NON_NULL(Temp
);
264 SHELL_FREE_NON_NULL(RetVal
);
268 Status
= gBS
->OpenProtocol (
270 &gEfiGraphicsOutputProtocolGuid
,
271 (VOID
**)&GraphicsOutput
,
274 EFI_OPEN_PROTOCOL_GET_PROTOCOL
277 if (EFI_ERROR (Status
)) {
278 SHELL_FREE_NON_NULL (Temp
);
279 SHELL_FREE_NON_NULL (RetVal
);
283 Fmt
= ConvertPixelFormat(GraphicsOutput
->Mode
->Info
->PixelFormat
);
285 RetVal
= CatSPrint(RetVal
,
287 GraphicsOutput
->Mode
->MaxMode
,
288 GraphicsOutput
->Mode
->Mode
,
289 GraphicsOutput
->Mode
->FrameBufferBase
,
290 (UINT64
)GraphicsOutput
->Mode
->FrameBufferSize
,
291 (UINT64
)GraphicsOutput
->Mode
->SizeOfInfo
,
292 GraphicsOutput
->Mode
->Info
->Version
,
293 GraphicsOutput
->Mode
->Info
->HorizontalResolution
,
294 GraphicsOutput
->Mode
->Info
->VerticalResolution
,
296 GraphicsOutput
->Mode
->Info
->PixelsPerScanLine
,
297 GraphicsOutput
->Mode
->Info
->PixelFormat
!=PixelBitMask
?0:GraphicsOutput
->Mode
->Info
->PixelInformation
.RedMask
,
298 GraphicsOutput
->Mode
->Info
->PixelFormat
!=PixelBitMask
?0:GraphicsOutput
->Mode
->Info
->PixelInformation
.GreenMask
,
299 GraphicsOutput
->Mode
->Info
->PixelFormat
!=PixelBitMask
?0:GraphicsOutput
->Mode
->Info
->PixelInformation
.BlueMask
302 SHELL_FREE_NON_NULL(Temp
);
303 SHELL_FREE_NON_NULL(Fmt
);
309 Function to dump information about PciRootBridgeIo.
311 This will allocate the return buffer from boot services pool.
313 @param[in] TheHandle The handle that has PciRootBridgeIo installed.
314 @param[in] Verbose TRUE for additional information, FALSE otherwise.
316 @retval A poitner to a string containing the information.
320 PciRootBridgeIoDumpInformation(
321 IN CONST EFI_HANDLE TheHandle
,
322 IN CONST BOOLEAN Verbose
325 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
326 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*Configuration
;
337 return (CatSPrint(NULL
, L
"PciRootBridgeIo"));
340 HandleParsingHiiInit();
342 Status
= gBS
->HandleProtocol(
344 &gEfiPciRootBridgeIoProtocolGuid
,
345 (VOID
**)&PciRootBridgeIo
);
347 if (EFI_ERROR(Status
)) {
351 Temp
= HiiGetString(mHandleParsingHiiHandle
, STRING_TOKEN(STR_PCIRB_DUMP_PH
), NULL
);
352 ASSERT (Temp
!= NULL
);
353 Temp2
= CatSPrint(L
"\r\n", Temp
, PciRootBridgeIo
->ParentHandle
);
358 Temp
= HiiGetString(mHandleParsingHiiHandle
, STRING_TOKEN(STR_PCIRB_DUMP_SEG
), NULL
);
359 ASSERT (Temp
!= NULL
);
360 Temp2
= CatSPrint(RetVal
, Temp
, PciRootBridgeIo
->SegmentNumber
);
368 Status
= PciRootBridgeIo
->GetAttributes (PciRootBridgeIo
, &Supports
, &Attributes
);
369 if (!EFI_ERROR(Status
)) {
370 Temp
= HiiGetString(mHandleParsingHiiHandle
, STRING_TOKEN(STR_PCIRB_DUMP_ATT
), NULL
);
371 ASSERT (Temp
!= NULL
);
372 Temp2
= CatSPrint(RetVal
, Temp
, Attributes
);
378 Temp
= HiiGetString(mHandleParsingHiiHandle
, STRING_TOKEN(STR_PCIRB_DUMP_SUPPORTS
), NULL
);
379 ASSERT (Temp
!= NULL
);
380 Temp2
= CatSPrint(RetVal
, Temp
, Supports
);
387 Configuration
= NULL
;
388 Status
= PciRootBridgeIo
->Configuration (PciRootBridgeIo
, (VOID
**) &Configuration
);
389 if (!EFI_ERROR(Status
) && Configuration
!= NULL
) {
390 Temp
= HiiGetString(mHandleParsingHiiHandle
, STRING_TOKEN(STR_PCIRB_DUMP_TITLE
), NULL
);
391 ASSERT (Temp
!= NULL
);
392 Temp2
= CatSPrint(RetVal
, Temp
, Supports
);
397 while (Configuration
->Desc
== ACPI_ADDRESS_SPACE_DESCRIPTOR
) {
399 switch (Configuration
->ResType
) {
400 case ACPI_ADDRESS_SPACE_TYPE_MEM
:
401 Temp
= HiiGetString(mHandleParsingHiiHandle
, STRING_TOKEN(STR_PCIRB_DUMP_MEM
), NULL
);
403 case ACPI_ADDRESS_SPACE_TYPE_IO
:
404 Temp
= HiiGetString(mHandleParsingHiiHandle
, STRING_TOKEN(STR_PCIRB_DUMP_IO
), NULL
);
406 case ACPI_ADDRESS_SPACE_TYPE_BUS
:
407 Temp
= HiiGetString(mHandleParsingHiiHandle
, STRING_TOKEN(STR_PCIRB_DUMP_BUS
), NULL
);
411 Temp2
= CatSPrint(RetVal
, L
"%s", Temp
);
418 Temp2
= CatSPrint(RetVal
,
419 L
"%H%02x %016lx %016lx %02x%N\r\n",
420 Configuration
->SpecificFlag
,
421 Configuration
->AddrRangeMin
,
422 Configuration
->AddrRangeMax
,
423 Configuration
->AddrSpaceGranularity
435 Function to dump information about SimpleTextOut.
437 This will allocate the return buffer from boot services pool.
439 @param[in] TheHandle The handle that has SimpleTextOut installed.
440 @param[in] Verbose TRUE for additional information, FALSE otherwise.
442 @retval A poitner to a string containing the information.
446 TxtOutProtocolDumpInformation(
447 IN CONST EFI_HANDLE TheHandle
,
448 IN CONST BOOLEAN Verbose
451 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*Dev
;
465 HandleParsingHiiInit();
470 Status
= gBS
->HandleProtocol(
472 &gEfiSimpleTextOutProtocolGuid
,
475 ASSERT_EFI_ERROR(Status
);
476 ASSERT (Dev
!= NULL
&& Dev
->Mode
!= NULL
);
478 Size
= (Dev
->Mode
->MaxMode
+ 1) * 80;
479 RetVal
= AllocateZeroPool(Size
);
481 Temp
= HiiGetString(mHandleParsingHiiHandle
, STRING_TOKEN(STR_TXT_OUT_DUMP_HEADER
), NULL
);
483 UnicodeSPrint(RetVal
, Size
, Temp
, Dev
, Dev
->Mode
->Attribute
);
490 Temp
= HiiGetString(mHandleParsingHiiHandle
, STRING_TOKEN(STR_TXT_OUT_DUMP_LINE
), NULL
);
491 for (Index
= 0; Index
< Dev
->Mode
->MaxMode
; Index
++) {
492 Status
= Dev
->QueryMode (Dev
, Index
, &Col
, &Row
);
493 NewSize
= Size
- StrSize(RetVal
);
495 RetVal
+ StrLen(RetVal
),
497 Temp
== NULL
?L
"":Temp
,
498 Index
== Dev
->Mode
->Mode
? L
'*' : L
' ',
500 !EFI_ERROR(Status
)?(INTN
)Col
:-1,
501 !EFI_ERROR(Status
)?(INTN
)Row
:-1
508 STATIC CONST UINTN VersionStringSize
= 60;
511 Function to dump information about EfiDriverSupportedEfiVersion protocol.
513 This will allocate the return buffer from boot services pool.
515 @param[in] TheHandle The handle that has the protocol installed.
516 @param[in] Verbose TRUE for additional information, FALSE otherwise.
518 @retval A poitner to a string containing the information.
522 DriverEfiVersionProtocolDumpInformation(
523 IN CONST EFI_HANDLE TheHandle
,
524 IN CONST BOOLEAN Verbose
527 EFI_DRIVER_SUPPORTED_EFI_VERSION_PROTOCOL
*DriverEfiVersion
;
531 Status
= gBS
->HandleProtocol(
533 &gEfiDriverSupportedEfiVersionProtocolGuid
,
534 (VOID
**)&DriverEfiVersion
);
536 ASSERT_EFI_ERROR(Status
);
538 RetVal
= AllocateZeroPool(VersionStringSize
);
539 ASSERT(RetVal
!= NULL
);
540 UnicodeSPrint(RetVal
, VersionStringSize
, L
"0x%08x", DriverEfiVersion
->FirmwareVersion
);
545 Function to dump information about DevicePath protocol.
547 This will allocate the return buffer from boot services pool.
549 @param[in] TheHandle The handle that has the protocol installed.
550 @param[in] Verbose TRUE for additional information, FALSE otherwise.
552 @retval A poitner to a string containing the information.
556 DevicePathProtocolDumpInformation(
557 IN CONST EFI_HANDLE TheHandle
,
558 IN CONST BOOLEAN Verbose
561 EFI_DEVICE_PATH_PROTOCOL
*DevPath
;
567 Status
= gBS
->OpenProtocol(TheHandle
, &gEfiDevicePathProtocolGuid
, (VOID
**)&DevPath
, gImageHandle
, NULL
, EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
568 if (!EFI_ERROR(Status
)) {
570 // I cannot decide whether to allow shortcuts here (the second BOOLEAN on the next line)
572 Temp
= ConvertDevicePathToText(DevPath
, TRUE
, TRUE
);
573 gBS
->CloseProtocol(TheHandle
, &gEfiDevicePathProtocolGuid
, gImageHandle
, NULL
);
575 if (!Verbose
&& Temp
!= NULL
&& StrLen(Temp
) > 30) {
577 Temp2
= StrnCatGrow(&Temp2
, NULL
, Temp
+(StrLen(Temp
) - 30), 30);
585 Function to dump information about EfiAdapterInformation Protocol.
587 @param[in] TheHandle The handle that has the protocol installed.
588 @param[in] Verbose TRUE for additional information, FALSE otherwise.
590 @retval A pointer to a string containing the information.
594 AdapterInformationDumpInformation (
595 IN CONST EFI_HANDLE TheHandle
,
596 IN CONST BOOLEAN Verbose
600 EFI_ADAPTER_INFORMATION_PROTOCOL
*EfiAdptrInfoProtocol
;
601 UINTN InfoTypesBufferCount
;
603 EFI_GUID
*InfoTypesBuffer
;
607 VOID
*InformationBlock
;
608 UINTN InformationBlockSize
;
611 return (CatSPrint(NULL
, L
"AdapterInfo"));
615 // Allocate print buffer to store data
617 RetVal
= AllocateZeroPool (PcdGet16(PcdShellPrintBufferSize
));
618 if (RetVal
== NULL
) {
622 Status
= gBS
->OpenProtocol (
623 (EFI_HANDLE
) (TheHandle
),
624 &gEfiAdapterInformationProtocolGuid
,
625 (VOID
**) &EfiAdptrInfoProtocol
,
628 EFI_OPEN_PROTOCOL_GET_PROTOCOL
631 if (EFI_ERROR (Status
)) {
632 SHELL_FREE_NON_NULL (RetVal
);
637 // Get a list of supported information types for this instance of the protocol.
639 Status
= EfiAdptrInfoProtocol
->GetSupportedTypes (
640 EfiAdptrInfoProtocol
,
642 &InfoTypesBufferCount
644 if (EFI_ERROR (Status
)) {
645 TempStr
= HiiGetString (mHandleParsingHiiHandle
, STRING_TOKEN(STR_GET_SUPP_TYPES_FAILED
), NULL
);
646 RetVal
= CatSPrint (RetVal
, TempStr
, Status
);
648 TempStr
= HiiGetString (mHandleParsingHiiHandle
, STRING_TOKEN(STR_SUPP_TYPE_HEADER
), NULL
);
649 RetVal
= CatSPrint (RetVal
, TempStr
);
650 SHELL_FREE_NON_NULL (TempStr
);
652 for (GuidIndex
= 0; GuidIndex
< InfoTypesBufferCount
; GuidIndex
++) {
653 TempStr
= HiiGetString (mHandleParsingHiiHandle
, STRING_TOKEN(STR_GUID_NUMBER
), NULL
);
654 RetVal
= CatSPrint (RetVal
, TempStr
, (GuidIndex
+ 1), InfoTypesBuffer
[GuidIndex
]);
655 SHELL_FREE_NON_NULL (TempStr
);
657 TempStr
= HiiGetString (mHandleParsingHiiHandle
, STRING_TOKEN(STR_GUID_STRING
), NULL
);
659 if (CompareGuid (&InfoTypesBuffer
[GuidIndex
], &gEfiAdapterInfoMediaStateGuid
)) {
660 RetVal
= CatSPrint (RetVal
, TempStr
, L
"gEfiAdapterInfoMediaStateGuid");
661 } else if (CompareGuid (&InfoTypesBuffer
[GuidIndex
], &gEfiAdapterInfoNetworkBootGuid
)) {
662 RetVal
= CatSPrint (RetVal
, TempStr
, L
"gEfiAdapterInfoNetworkBootGuid");
663 } else if (CompareGuid (&InfoTypesBuffer
[GuidIndex
], &gEfiAdapterInfoSanMacAddressGuid
)) {
664 RetVal
= CatSPrint (RetVal
, TempStr
, L
"gEfiAdapterInfoSanMacAddressGuid");
667 GuidStr
= GetStringNameFromGuid (&InfoTypesBuffer
[GuidIndex
], NULL
);
669 if (GuidStr
!= NULL
) {
670 if (StrCmp(GuidStr
, L
"UnknownDevice") == 0) {
671 RetVal
= CatSPrint (RetVal
, TempStr
, L
"UnknownInfoType");
673 SHELL_FREE_NON_NULL (TempStr
);
674 SHELL_FREE_NON_NULL(GuidStr
);
676 // So that we never have to pass this UnknownInfoType to the parsing function "GetInformation" service of AIP
680 RetVal
= CatSPrint (RetVal
, TempStr
, GuidStr
);
681 SHELL_FREE_NON_NULL(GuidStr
);
686 SHELL_FREE_NON_NULL (TempStr
);
688 Status
= EfiAdptrInfoProtocol
->GetInformation (
689 EfiAdptrInfoProtocol
,
690 &InfoTypesBuffer
[GuidIndex
],
692 &InformationBlockSize
695 if (EFI_ERROR (Status
)) {
696 TempStr
= HiiGetString (mHandleParsingHiiHandle
, STRING_TOKEN(STR_GETINFO_FAILED
), NULL
);
697 RetVal
= CatSPrint (RetVal
, TempStr
, Status
);
699 if (CompareGuid (&InfoTypesBuffer
[GuidIndex
], &gEfiAdapterInfoMediaStateGuid
)) {
700 TempStr
= HiiGetString (mHandleParsingHiiHandle
, STRING_TOKEN(STR_MEDIA_STATE
), NULL
);
704 ((EFI_ADAPTER_INFO_MEDIA_STATE
*)InformationBlock
)->MediaState
,
705 ((EFI_ADAPTER_INFO_MEDIA_STATE
*)InformationBlock
)->MediaState
707 } else if (CompareGuid (&InfoTypesBuffer
[GuidIndex
], &gEfiAdapterInfoNetworkBootGuid
)) {
708 TempStr
= HiiGetString (mHandleParsingHiiHandle
, STRING_TOKEN(STR_NETWORK_BOOT_INFO
), NULL
);
712 ((EFI_ADAPTER_INFO_NETWORK_BOOT
*)InformationBlock
)->iScsiIpv4BootCapablity
,
713 ((EFI_ADAPTER_INFO_NETWORK_BOOT
*)InformationBlock
)->iScsiIpv6BootCapablity
,
714 ((EFI_ADAPTER_INFO_NETWORK_BOOT
*)InformationBlock
)->FCoeBootCapablity
,
715 ((EFI_ADAPTER_INFO_NETWORK_BOOT
*)InformationBlock
)->OffloadCapability
,
716 ((EFI_ADAPTER_INFO_NETWORK_BOOT
*)InformationBlock
)->iScsiMpioCapability
,
717 ((EFI_ADAPTER_INFO_NETWORK_BOOT
*)InformationBlock
)->iScsiIpv4Boot
,
718 ((EFI_ADAPTER_INFO_NETWORK_BOOT
*)InformationBlock
)->iScsiIpv6Boot
,
719 ((EFI_ADAPTER_INFO_NETWORK_BOOT
*)InformationBlock
)->FCoeBoot
721 } else if (CompareGuid (&InfoTypesBuffer
[GuidIndex
], &gEfiAdapterInfoSanMacAddressGuid
) == TRUE
) {
722 TempStr
= HiiGetString (mHandleParsingHiiHandle
, STRING_TOKEN(STR_SAN_MAC_ADDRESS_INFO
), NULL
);
726 ((EFI_ADAPTER_INFO_SAN_MAC_ADDRESS
*)InformationBlock
)->SanMacAddress
.Addr
[0],
727 ((EFI_ADAPTER_INFO_SAN_MAC_ADDRESS
*)InformationBlock
)->SanMacAddress
.Addr
[1],
728 ((EFI_ADAPTER_INFO_SAN_MAC_ADDRESS
*)InformationBlock
)->SanMacAddress
.Addr
[2],
729 ((EFI_ADAPTER_INFO_SAN_MAC_ADDRESS
*)InformationBlock
)->SanMacAddress
.Addr
[3],
730 ((EFI_ADAPTER_INFO_SAN_MAC_ADDRESS
*)InformationBlock
)->SanMacAddress
.Addr
[4],
731 ((EFI_ADAPTER_INFO_SAN_MAC_ADDRESS
*)InformationBlock
)->SanMacAddress
.Addr
[5]
734 TempStr
= HiiGetString (mHandleParsingHiiHandle
, STRING_TOKEN(STR_UNKNOWN_INFO_TYPE
), NULL
);
735 RetVal
= CatSPrint (RetVal
, TempStr
, &InfoTypesBuffer
[GuidIndex
]);
738 SHELL_FREE_NON_NULL (TempStr
);
739 SHELL_FREE_NON_NULL (InformationBlock
);
746 // Put the information on the NT32 protocol GUIDs here so we are not dependant on the Nt32Pkg
748 #define LOCAL_EFI_WIN_NT_THUNK_PROTOCOL_GUID \
750 0x58c518b1, 0x76f3, 0x11d4, { 0xbc, 0xea, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 } \
753 #define LOCAL_EFI_WIN_NT_BUS_DRIVER_IO_PROTOCOL_GUID \
755 0x96eb4ad6, 0xa32a, 0x11d4, { 0xbc, 0xfd, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 } \
758 #define LOCAL_EFI_WIN_NT_SERIAL_PORT_GUID \
760 0xc95a93d, 0xa006, 0x11d4, { 0xbc, 0xfa, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 } \
762 STATIC CONST EFI_GUID WinNtThunkProtocolGuid
= LOCAL_EFI_WIN_NT_THUNK_PROTOCOL_GUID
;
763 STATIC CONST EFI_GUID WinNtIoProtocolGuid
= LOCAL_EFI_WIN_NT_BUS_DRIVER_IO_PROTOCOL_GUID
;
764 STATIC CONST EFI_GUID WinNtSerialPortGuid
= LOCAL_EFI_WIN_NT_SERIAL_PORT_GUID
;
766 STATIC CONST GUID_INFO_BLOCK mGuidStringListNT
[] = {
767 {STRING_TOKEN(STR_WINNT_THUNK
), (EFI_GUID
*)&WinNtThunkProtocolGuid
, NULL
},
768 {STRING_TOKEN(STR_WINNT_DRIVER_IO
), (EFI_GUID
*)&WinNtIoProtocolGuid
, NULL
},
769 {STRING_TOKEN(STR_WINNT_SERIAL_PORT
), (EFI_GUID
*)&WinNtSerialPortGuid
, NULL
},
770 {STRING_TOKEN(STR_UNKNOWN_DEVICE
), NULL
, NULL
},
773 STATIC CONST GUID_INFO_BLOCK mGuidStringList
[] = {
774 {STRING_TOKEN(STR_LOADED_IMAGE
), &gEfiLoadedImageProtocolGuid
, LoadedImageProtocolDumpInformation
},
775 {STRING_TOKEN(STR_DEVICE_PATH
), &gEfiDevicePathProtocolGuid
, DevicePathProtocolDumpInformation
},
776 {STRING_TOKEN(STR_IMAGE_PATH
), &gEfiLoadedImageDevicePathProtocolGuid
, DevicePathProtocolDumpInformation
},
777 {STRING_TOKEN(STR_DEVICE_PATH_UTIL
), &gEfiDevicePathUtilitiesProtocolGuid
, NULL
},
778 {STRING_TOKEN(STR_DEVICE_PATH_TXT
), &gEfiDevicePathToTextProtocolGuid
, NULL
},
779 {STRING_TOKEN(STR_DEVICE_PATH_FTXT
), &gEfiDevicePathFromTextProtocolGuid
, NULL
},
780 {STRING_TOKEN(STR_DEVICE_PATH_PC
), &gEfiPcAnsiGuid
, NULL
},
781 {STRING_TOKEN(STR_DEVICE_PATH_VT100
), &gEfiVT100Guid
, NULL
},
782 {STRING_TOKEN(STR_DEVICE_PATH_VT100P
), &gEfiVT100PlusGuid
, NULL
},
783 {STRING_TOKEN(STR_DEVICE_PATH_VTUTF8
), &gEfiVTUTF8Guid
, NULL
},
784 {STRING_TOKEN(STR_DRIVER_BINDING
), &gEfiDriverBindingProtocolGuid
, NULL
},
785 {STRING_TOKEN(STR_PLATFORM_OVERRIDE
), &gEfiPlatformDriverOverrideProtocolGuid
, NULL
},
786 {STRING_TOKEN(STR_BUS_OVERRIDE
), &gEfiBusSpecificDriverOverrideProtocolGuid
, NULL
},
787 {STRING_TOKEN(STR_DRIVER_DIAG
), &gEfiDriverDiagnosticsProtocolGuid
, NULL
},
788 {STRING_TOKEN(STR_DRIVER_DIAG2
), &gEfiDriverDiagnostics2ProtocolGuid
, NULL
},
789 {STRING_TOKEN(STR_DRIVER_CN
), &gEfiComponentNameProtocolGuid
, NULL
},
790 {STRING_TOKEN(STR_DRIVER_CN2
), &gEfiComponentName2ProtocolGuid
, NULL
},
791 {STRING_TOKEN(STR_PLAT_DRV_CFG
), &gEfiPlatformToDriverConfigurationProtocolGuid
, NULL
},
792 {STRING_TOKEN(STR_DRIVER_VERSION
), &gEfiDriverSupportedEfiVersionProtocolGuid
, DriverEfiVersionProtocolDumpInformation
},
793 {STRING_TOKEN(STR_TXT_IN
), &gEfiSimpleTextInProtocolGuid
, NULL
},
794 {STRING_TOKEN(STR_TXT_IN_EX
), &gEfiSimpleTextInputExProtocolGuid
, NULL
},
795 {STRING_TOKEN(STR_TXT_OUT
), &gEfiSimpleTextOutProtocolGuid
, TxtOutProtocolDumpInformation
},
796 {STRING_TOKEN(STR_SIM_POINTER
), &gEfiSimplePointerProtocolGuid
, NULL
},
797 {STRING_TOKEN(STR_ABS_POINTER
), &gEfiAbsolutePointerProtocolGuid
, NULL
},
798 {STRING_TOKEN(STR_SERIAL_IO
), &gEfiSerialIoProtocolGuid
, NULL
},
799 {STRING_TOKEN(STR_GRAPHICS_OUTPUT
), &gEfiGraphicsOutputProtocolGuid
, GraphicsOutputProtocolDumpInformation
},
800 {STRING_TOKEN(STR_EDID_DISCOVERED
), &gEfiEdidDiscoveredProtocolGuid
, NULL
},
801 {STRING_TOKEN(STR_EDID_ACTIVE
), &gEfiEdidActiveProtocolGuid
, NULL
},
802 {STRING_TOKEN(STR_EDID_OVERRIDE
), &gEfiEdidOverrideProtocolGuid
, NULL
},
803 {STRING_TOKEN(STR_CON_IN
), &gEfiConsoleInDeviceGuid
, NULL
},
804 {STRING_TOKEN(STR_CON_OUT
), &gEfiConsoleOutDeviceGuid
, NULL
},
805 {STRING_TOKEN(STR_STD_ERR
), &gEfiStandardErrorDeviceGuid
, NULL
},
806 {STRING_TOKEN(STR_LOAD_FILE
), &gEfiLoadFileProtocolGuid
, NULL
},
807 {STRING_TOKEN(STR_LOAD_FILE2
), &gEfiLoadFile2ProtocolGuid
, NULL
},
808 {STRING_TOKEN(STR_SIMPLE_FILE_SYS
), &gEfiSimpleFileSystemProtocolGuid
, NULL
},
809 {STRING_TOKEN(STR_TAPE_IO
), &gEfiTapeIoProtocolGuid
, NULL
},
810 {STRING_TOKEN(STR_DISK_IO
), &gEfiDiskIoProtocolGuid
, NULL
},
811 {STRING_TOKEN(STR_BLK_IO
), &gEfiBlockIoProtocolGuid
, NULL
},
812 {STRING_TOKEN(STR_UC
), &gEfiUnicodeCollationProtocolGuid
, NULL
},
813 {STRING_TOKEN(STR_UC2
), &gEfiUnicodeCollation2ProtocolGuid
, NULL
},
814 {STRING_TOKEN(STR_PCIRB_IO
), &gEfiPciRootBridgeIoProtocolGuid
, PciRootBridgeIoDumpInformation
},
815 {STRING_TOKEN(STR_PCI_IO
), &gEfiPciIoProtocolGuid
, NULL
},
816 {STRING_TOKEN(STR_SCSI_PT
), &gEfiScsiPassThruProtocolGuid
, NULL
},
817 {STRING_TOKEN(STR_SCSI_IO
), &gEfiScsiIoProtocolGuid
, NULL
},
818 {STRING_TOKEN(STR_SCSI_PT_EXT
), &gEfiExtScsiPassThruProtocolGuid
, NULL
},
819 {STRING_TOKEN(STR_ISCSI
), &gEfiIScsiInitiatorNameProtocolGuid
, NULL
},
820 {STRING_TOKEN(STR_USB_IO
), &gEfiUsbIoProtocolGuid
, NULL
},
821 {STRING_TOKEN(STR_USB_HC
), &gEfiUsbHcProtocolGuid
, NULL
},
822 {STRING_TOKEN(STR_USB_HC2
), &gEfiUsb2HcProtocolGuid
, NULL
},
823 {STRING_TOKEN(STR_DEBUG_SUPPORT
), &gEfiDebugSupportProtocolGuid
, NULL
},
824 {STRING_TOKEN(STR_DEBUG_PORT
), &gEfiDebugPortProtocolGuid
, NULL
},
825 {STRING_TOKEN(STR_DECOMPRESS
), &gEfiDecompressProtocolGuid
, NULL
},
826 {STRING_TOKEN(STR_ACPI_TABLE
), &gEfiAcpiTableProtocolGuid
, NULL
},
827 {STRING_TOKEN(STR_EBC_INTERPRETER
), &gEfiEbcProtocolGuid
, NULL
},
828 {STRING_TOKEN(STR_SNP
), &gEfiSimpleNetworkProtocolGuid
, NULL
},
829 {STRING_TOKEN(STR_NII
), &gEfiNetworkInterfaceIdentifierProtocolGuid
, NULL
},
830 {STRING_TOKEN(STR_NII_31
), &gEfiNetworkInterfaceIdentifierProtocolGuid_31
, NULL
},
831 {STRING_TOKEN(STR_PXE_BC
), &gEfiPxeBaseCodeProtocolGuid
, NULL
},
832 {STRING_TOKEN(STR_PXE_CB
), &gEfiPxeBaseCodeCallbackProtocolGuid
, NULL
},
833 {STRING_TOKEN(STR_BIS
), &gEfiBisProtocolGuid
, NULL
},
834 {STRING_TOKEN(STR_MNP_SB
), &gEfiManagedNetworkServiceBindingProtocolGuid
, NULL
},
835 {STRING_TOKEN(STR_MNP
), &gEfiManagedNetworkProtocolGuid
, NULL
},
836 {STRING_TOKEN(STR_ARP_SB
), &gEfiArpServiceBindingProtocolGuid
, NULL
},
837 {STRING_TOKEN(STR_ARP
), &gEfiArpProtocolGuid
, NULL
},
838 {STRING_TOKEN(STR_DHCPV4_SB
), &gEfiDhcp4ServiceBindingProtocolGuid
, NULL
},
839 {STRING_TOKEN(STR_DHCPV4
), &gEfiDhcp4ProtocolGuid
, NULL
},
840 {STRING_TOKEN(STR_TCPV4_SB
), &gEfiTcp4ServiceBindingProtocolGuid
, NULL
},
841 {STRING_TOKEN(STR_TCPV4
), &gEfiTcp4ProtocolGuid
, NULL
},
842 {STRING_TOKEN(STR_IPV4_SB
), &gEfiIp4ServiceBindingProtocolGuid
, NULL
},
843 {STRING_TOKEN(STR_IPV4
), &gEfiIp4ProtocolGuid
, NULL
},
844 {STRING_TOKEN(STR_IPV4_CFG
), &gEfiIp4ConfigProtocolGuid
, NULL
},
845 {STRING_TOKEN(STR_UDPV4_SB
), &gEfiUdp4ServiceBindingProtocolGuid
, NULL
},
846 {STRING_TOKEN(STR_UDPV4
), &gEfiUdp4ProtocolGuid
, NULL
},
847 {STRING_TOKEN(STR_MTFTPV4_SB
), &gEfiMtftp4ServiceBindingProtocolGuid
, NULL
},
848 {STRING_TOKEN(STR_MTFTPV4
), &gEfiMtftp4ProtocolGuid
, NULL
},
849 {STRING_TOKEN(STR_AUTH_INFO
), &gEfiAuthenticationInfoProtocolGuid
, NULL
},
850 {STRING_TOKEN(STR_HASH_SB
), &gEfiHashServiceBindingProtocolGuid
, NULL
},
851 {STRING_TOKEN(STR_HASH
), &gEfiHashProtocolGuid
, NULL
},
852 {STRING_TOKEN(STR_HII_FONT
), &gEfiHiiFontProtocolGuid
, NULL
},
853 {STRING_TOKEN(STR_HII_STRING
), &gEfiHiiStringProtocolGuid
, NULL
},
854 {STRING_TOKEN(STR_HII_IMAGE
), &gEfiHiiImageProtocolGuid
, NULL
},
855 {STRING_TOKEN(STR_HII_DATABASE
), &gEfiHiiDatabaseProtocolGuid
, NULL
},
856 {STRING_TOKEN(STR_HII_CONFIG_ROUT
), &gEfiHiiConfigRoutingProtocolGuid
, NULL
},
857 {STRING_TOKEN(STR_HII_CONFIG_ACC
), &gEfiHiiConfigAccessProtocolGuid
, NULL
},
858 {STRING_TOKEN(STR_HII_FORM_BROWSER2
), &gEfiFormBrowser2ProtocolGuid
, NULL
},
859 {STRING_TOKEN(STR_DRIVER_FAM_OVERRIDE
), &gEfiDriverFamilyOverrideProtocolGuid
, NULL
},
860 {STRING_TOKEN(STR_PCD
), &gPcdProtocolGuid
, NULL
},
861 {STRING_TOKEN(STR_TCG
), &gEfiTcgProtocolGuid
, NULL
},
862 {STRING_TOKEN(STR_HII_PACKAGE_LIST
), &gEfiHiiPackageListProtocolGuid
, NULL
},
865 // the ones under this are deprecated by the current UEFI Spec, but may be found anyways...
867 {STRING_TOKEN(STR_SHELL_INTERFACE
), &gEfiShellInterfaceGuid
, NULL
},
868 {STRING_TOKEN(STR_SHELL_ENV2
), &gEfiShellEnvironment2Guid
, NULL
},
869 {STRING_TOKEN(STR_SHELL_ENV
), &gEfiShellEnvironment2Guid
, NULL
},
870 {STRING_TOKEN(STR_DEVICE_IO
), &gEfiDeviceIoProtocolGuid
, NULL
},
871 {STRING_TOKEN(STR_UGA_DRAW
), &gEfiUgaDrawProtocolGuid
, NULL
},
872 {STRING_TOKEN(STR_UGA_IO
), &gEfiUgaIoProtocolGuid
, NULL
},
873 {STRING_TOKEN(STR_ESP
), &gEfiPartTypeSystemPartGuid
, NULL
},
874 {STRING_TOKEN(STR_GPT_NBR
), &gEfiPartTypeLegacyMbrGuid
, NULL
},
875 {STRING_TOKEN(STR_DRIVER_CONFIG
), &gEfiDriverConfigurationProtocolGuid
, NULL
},
876 {STRING_TOKEN(STR_DRIVER_CONFIG2
), &gEfiDriverConfiguration2ProtocolGuid
, NULL
},
877 {STRING_TOKEN(STR_ISA_IO
), &gEfiIsaIoProtocolGuid
, NULL
},
878 {STRING_TOKEN(STR_ISA_ACPI
), &gEfiIsaAcpiProtocolGuid
, NULL
},
881 // the ones under this are GUID identified structs, not protocols
883 {STRING_TOKEN(STR_FILE_INFO
), &gEfiFileInfoGuid
, NULL
},
884 {STRING_TOKEN(STR_FILE_SYS_INFO
), &gEfiFileSystemInfoGuid
, NULL
},
887 // the ones under this are misc GUIDS.
889 {STRING_TOKEN(STR_EFI_GLOBAL_VARIABLE
), &gEfiGlobalVariableGuid
, NULL
},
894 {STRING_TOKEN(STR_IP6_SB
), &gEfiIp6ServiceBindingProtocolGuid
, NULL
},
895 {STRING_TOKEN(STR_IP6
), &gEfiIp6ProtocolGuid
, NULL
},
896 {STRING_TOKEN(STR_IP6_CONFIG
), &gEfiIp6ConfigProtocolGuid
, NULL
},
897 {STRING_TOKEN(STR_MTFTP6_SB
), &gEfiMtftp6ServiceBindingProtocolGuid
, NULL
},
898 {STRING_TOKEN(STR_MTFTP6
), &gEfiMtftp6ProtocolGuid
, NULL
},
899 {STRING_TOKEN(STR_DHCP6_SB
), &gEfiDhcp6ServiceBindingProtocolGuid
, NULL
},
900 {STRING_TOKEN(STR_DHCP6
), &gEfiDhcp6ProtocolGuid
, NULL
},
901 {STRING_TOKEN(STR_UDP6_SB
), &gEfiUdp6ServiceBindingProtocolGuid
, NULL
},
902 {STRING_TOKEN(STR_UDP6
), &gEfiUdp6ProtocolGuid
, NULL
},
903 {STRING_TOKEN(STR_TCP6_SB
), &gEfiTcp6ServiceBindingProtocolGuid
, NULL
},
904 {STRING_TOKEN(STR_TCP6
), &gEfiTcp6ProtocolGuid
, NULL
},
905 {STRING_TOKEN(STR_VLAN_CONFIG
), &gEfiVlanConfigProtocolGuid
, NULL
},
906 {STRING_TOKEN(STR_EAP
), &gEfiEapProtocolGuid
, NULL
},
907 {STRING_TOKEN(STR_EAP_MGMT
), &gEfiEapManagementProtocolGuid
, NULL
},
908 {STRING_TOKEN(STR_FTP4_SB
), &gEfiFtp4ServiceBindingProtocolGuid
, NULL
},
909 {STRING_TOKEN(STR_FTP4
), &gEfiFtp4ProtocolGuid
, NULL
},
910 {STRING_TOKEN(STR_IP_SEC_CONFIG
), &gEfiIpSecConfigProtocolGuid
, NULL
},
911 {STRING_TOKEN(STR_DH
), &gEfiDriverHealthProtocolGuid
, NULL
},
912 {STRING_TOKEN(STR_DEF_IMG_LOAD
), &gEfiDeferredImageLoadProtocolGuid
, NULL
},
913 {STRING_TOKEN(STR_USER_CRED
), &gEfiUserCredentialProtocolGuid
, NULL
},
914 {STRING_TOKEN(STR_USER_MNGR
), &gEfiUserManagerProtocolGuid
, NULL
},
915 {STRING_TOKEN(STR_ATA_PASS_THRU
), &gEfiAtaPassThruProtocolGuid
, NULL
},
920 {STRING_TOKEN(STR_FW_MGMT
), &gEfiFirmwareManagementProtocolGuid
, NULL
},
921 {STRING_TOKEN(STR_IP_SEC
), &gEfiIpSecProtocolGuid
, NULL
},
922 {STRING_TOKEN(STR_IP_SEC2
), &gEfiIpSec2ProtocolGuid
, NULL
},
927 {STRING_TOKEN(STR_KMS
), &gEfiKmsProtocolGuid
, NULL
},
928 {STRING_TOKEN(STR_BLK_IO2
), &gEfiBlockIo2ProtocolGuid
, NULL
},
929 {STRING_TOKEN(STR_SSC
), &gEfiStorageSecurityCommandProtocolGuid
, NULL
},
930 {STRING_TOKEN(STR_UCRED2
), &gEfiUserCredential2ProtocolGuid
, NULL
},
935 {STRING_TOKEN(STR_DISK_IO2
), &gEfiDiskIo2ProtocolGuid
, NULL
},
936 {STRING_TOKEN(STR_ADAPTER_INFO
), &gEfiAdapterInformationProtocolGuid
, AdapterInformationDumpInformation
},
941 {STRING_TOKEN(STR_IDE_CONT_INIT
), &gEfiIdeControllerInitProtocolGuid
, NULL
},
944 // UEFI Shell Spec 2.0
946 {STRING_TOKEN(STR_SHELL_PARAMETERS
), &gEfiShellParametersProtocolGuid
, NULL
},
947 {STRING_TOKEN(STR_SHELL
), &gEfiShellProtocolGuid
, NULL
},
950 // UEFI Shell Spec 2.1
952 {STRING_TOKEN(STR_SHELL_DYNAMIC
), &gEfiShellDynamicCommandProtocolGuid
, NULL
},
957 {STRING_TOKEN(STR_UNKNOWN_DEVICE
), NULL
, NULL
},
961 Function to get the node for a protocol or struct from it's GUID.
963 if Guid is NULL, then ASSERT.
965 @param[in] Guid The GUID to look for the name of.
969 CONST GUID_INFO_BLOCK
*
971 InternalShellGetNodeFromGuid(
972 IN CONST EFI_GUID
* Guid
975 CONST GUID_INFO_BLOCK
*ListWalker
;
978 ASSERT(Guid
!= NULL
);
980 for (LoopCount
= 0, ListWalker
= GuidList
; GuidList
!= NULL
&& LoopCount
< GuidListCount
; LoopCount
++, ListWalker
++) {
981 if (CompareGuid(ListWalker
->GuidId
, Guid
)) {
986 if (PcdGetBool(PcdShellIncludeNtGuids
)) {
987 for (ListWalker
= mGuidStringListNT
; ListWalker
!= NULL
&& ListWalker
->GuidId
!= NULL
; ListWalker
++) {
988 if (CompareGuid(ListWalker
->GuidId
, Guid
)) {
993 for (ListWalker
= mGuidStringList
; ListWalker
!= NULL
&& ListWalker
->GuidId
!= NULL
; ListWalker
++) {
994 if (CompareGuid(ListWalker
->GuidId
, Guid
)) {
1002 Function to add a new GUID/Name mapping.
1004 @param[in] Guid The Guid
1005 @param[in] NameID The STRING id of the HII string to use
1006 @param[in] DumpFunc The pointer to the dump function
1009 @retval EFI_SUCCESS The operation was sucessful
1010 @retval EFI_OUT_OF_RESOURCES A memory allocation failed
1011 @retval EFI_INVALID_PARAMETER Guid NameId was invalid
1015 InsertNewGuidNameMapping(
1016 IN CONST EFI_GUID
*Guid
,
1017 IN CONST EFI_STRING_ID NameID
,
1018 IN CONST DUMP_PROTOCOL_INFO DumpFunc OPTIONAL
1021 ASSERT(Guid
!= NULL
);
1022 ASSERT(NameID
!= 0);
1024 GuidList
= ReallocatePool(GuidListCount
* sizeof(GUID_INFO_BLOCK
), GuidListCount
+1 * sizeof(GUID_INFO_BLOCK
), GuidList
);
1025 if (GuidList
== NULL
) {
1027 return (EFI_OUT_OF_RESOURCES
);
1031 GuidList
[GuidListCount
- 1].GuidId
= AllocateCopyPool(sizeof(EFI_GUID
), Guid
);
1032 GuidList
[GuidListCount
- 1].StringId
= NameID
;
1033 GuidList
[GuidListCount
- 1].DumpInfo
= DumpFunc
;
1035 if (GuidList
[GuidListCount
- 1].GuidId
== NULL
) {
1036 return (EFI_OUT_OF_RESOURCES
);
1039 return (EFI_SUCCESS
);
1043 Function to add a new GUID/Name mapping.
1045 This cannot overwrite an existing mapping.
1047 @param[in] Guid The Guid
1048 @param[in] TheName The Guid's name
1049 @param[in] Lang RFC4646 language code list or NULL
1051 @retval EFI_SUCCESS The operation was sucessful
1052 @retval EFI_ACCESS_DENIED There was a duplicate
1053 @retval EFI_OUT_OF_RESOURCES A memory allocation failed
1054 @retval EFI_INVALID_PARAMETER Guid or TheName was NULL
1058 AddNewGuidNameMapping(
1059 IN CONST EFI_GUID
*Guid
,
1060 IN CONST CHAR16
*TheName
,
1061 IN CONST CHAR8
*Lang OPTIONAL
1064 EFI_STRING_ID NameID
;
1066 HandleParsingHiiInit();
1068 if (Guid
== NULL
|| TheName
== NULL
){
1069 return (EFI_INVALID_PARAMETER
);
1072 if ((InternalShellGetNodeFromGuid(Guid
)) != NULL
) {
1073 return (EFI_ACCESS_DENIED
);
1076 NameID
= HiiSetString(mHandleParsingHiiHandle
, 0, (CHAR16
*)TheName
, Lang
);
1078 return (EFI_OUT_OF_RESOURCES
);
1081 return (InsertNewGuidNameMapping(Guid
, NameID
, NULL
));
1085 Function to get the name of a protocol or struct from it's GUID.
1087 if Guid is NULL, then ASSERT.
1089 @param[in] Guid The GUID to look for the name of.
1090 @param[in] Lang The language to use.
1092 @return pointer to string of the name. The caller
1093 is responsible to free this memory.
1097 GetStringNameFromGuid(
1098 IN CONST EFI_GUID
*Guid
,
1099 IN CONST CHAR8
*Lang OPTIONAL
1102 CONST GUID_INFO_BLOCK
*Id
;
1104 HandleParsingHiiInit();
1106 Id
= InternalShellGetNodeFromGuid(Guid
);
1107 return (HiiGetString(mHandleParsingHiiHandle
, Id
==NULL
?STRING_TOKEN(STR_UNKNOWN_DEVICE
):Id
->StringId
, Lang
));
1111 Function to dump protocol information from a handle.
1113 This function will return a allocated string buffer containing the
1114 information. The caller is responsible for freeing the memory.
1116 If Guid is NULL, ASSERT().
1117 If TheHandle is NULL, ASSERT().
1119 @param[in] TheHandle The handle to dump information from.
1120 @param[in] Guid The GUID of the protocol to dump.
1121 @param[in] Verbose TRUE for extra info. FALSE otherwise.
1123 @return The pointer to string.
1124 @retval NULL An error was encountered.
1128 GetProtocolInformationDump(
1129 IN CONST EFI_HANDLE TheHandle
,
1130 IN CONST EFI_GUID
*Guid
,
1131 IN CONST BOOLEAN Verbose
1134 CONST GUID_INFO_BLOCK
*Id
;
1136 ASSERT(TheHandle
!= NULL
);
1137 ASSERT(Guid
!= NULL
);
1139 if (TheHandle
== NULL
|| Guid
== NULL
) {
1143 Id
= InternalShellGetNodeFromGuid(Guid
);
1144 if (Id
!= NULL
&& Id
->DumpInfo
!= NULL
) {
1145 return (Id
->DumpInfo(TheHandle
, Verbose
));
1151 Function to get the Guid for a protocol or struct based on it's string name.
1153 do not modify the returned Guid.
1155 @param[in] Name The pointer to the string name.
1156 @param[in] Lang The pointer to the language code.
1157 @param[out] Guid The pointer to the Guid.
1159 @retval EFI_SUCCESS The operation was sucessful.
1163 GetGuidFromStringName(
1164 IN CONST CHAR16
*Name
,
1165 IN CONST CHAR8
*Lang OPTIONAL
,
1169 CONST GUID_INFO_BLOCK
*ListWalker
;
1173 HandleParsingHiiInit();
1175 ASSERT(Guid
!= NULL
);
1177 return (EFI_INVALID_PARAMETER
);
1181 if (PcdGetBool(PcdShellIncludeNtGuids
)) {
1182 for (ListWalker
= mGuidStringListNT
; ListWalker
!= NULL
&& ListWalker
->GuidId
!= NULL
; ListWalker
++) {
1183 String
= HiiGetString(mHandleParsingHiiHandle
, ListWalker
->StringId
, Lang
);
1184 if (Name
!= NULL
&& String
!= NULL
&& StringNoCaseCompare (&Name
, &String
) == 0) {
1185 *Guid
= ListWalker
->GuidId
;
1187 SHELL_FREE_NON_NULL(String
);
1188 if (*Guid
!= NULL
) {
1189 return (EFI_SUCCESS
);
1193 for (ListWalker
= mGuidStringList
; ListWalker
!= NULL
&& ListWalker
->GuidId
!= NULL
; ListWalker
++) {
1194 String
= HiiGetString(mHandleParsingHiiHandle
, ListWalker
->StringId
, Lang
);
1195 if (Name
!= NULL
&& String
!= NULL
&& StringNoCaseCompare (&Name
, &String
) == 0) {
1196 *Guid
= ListWalker
->GuidId
;
1198 SHELL_FREE_NON_NULL(String
);
1199 if (*Guid
!= NULL
) {
1200 return (EFI_SUCCESS
);
1204 for (LoopCount
= 0, ListWalker
= GuidList
; GuidList
!= NULL
&& LoopCount
< GuidListCount
; LoopCount
++, ListWalker
++) {
1205 String
= HiiGetString(mHandleParsingHiiHandle
, ListWalker
->StringId
, Lang
);
1206 if (Name
!= NULL
&& String
!= NULL
&& StringNoCaseCompare (&Name
, &String
) == 0) {
1207 *Guid
= ListWalker
->GuidId
;
1209 SHELL_FREE_NON_NULL(String
);
1210 if (*Guid
!= NULL
) {
1211 return (EFI_SUCCESS
);
1215 return (EFI_NOT_FOUND
);
1219 Get best support language for this driver.
1221 First base on the user input language to search, second base on the current
1222 platform used language to search, third get the first language from the
1223 support language list. The caller need to free the buffer of the best language.
1225 @param[in] SupportedLanguages The support languages for this driver.
1226 @param[in] InputLanguage The user input language.
1227 @param[in] Iso639Language Whether get language for ISO639.
1229 @return The best support language for this driver.
1233 GetBestLanguageForDriver (
1234 IN CONST CHAR8
*SupportedLanguages
,
1235 IN CONST CHAR8
*InputLanguage
,
1236 IN BOOLEAN Iso639Language
1239 CHAR8
*LanguageVariable
;
1240 CHAR8
*BestLanguage
;
1242 LanguageVariable
= GetVariable (Iso639Language
? L
"Lang" : L
"PlatformLang", &gEfiGlobalVariableGuid
);
1244 BestLanguage
= GetBestLanguage(
1247 (InputLanguage
!= NULL
) ? InputLanguage
: "",
1248 (LanguageVariable
!= NULL
) ? LanguageVariable
: "",
1253 if (LanguageVariable
!= NULL
) {
1254 FreePool (LanguageVariable
);
1257 return BestLanguage
;
1261 Function to retrieve the driver name (if possible) from the ComponentName or
1262 ComponentName2 protocol
1264 @param[in] TheHandle The driver handle to get the name of.
1265 @param[in] Language The language to use.
1267 @retval NULL The name could not be found.
1268 @return A pointer to the string name. Do not de-allocate the memory.
1272 GetStringNameFromHandle(
1273 IN CONST EFI_HANDLE TheHandle
,
1274 IN CONST CHAR8
*Language
1277 EFI_COMPONENT_NAME2_PROTOCOL
*CompNameStruct
;
1284 Status
= gBS
->OpenProtocol(
1286 &gEfiComponentName2ProtocolGuid
,
1287 (VOID
**)&CompNameStruct
,
1290 EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
1291 if (!EFI_ERROR(Status
)) {
1292 BestLang
= GetBestLanguageForDriver (CompNameStruct
->SupportedLanguages
, Language
, FALSE
);
1293 Status
= CompNameStruct
->GetDriverName(CompNameStruct
, BestLang
, &RetVal
);
1294 if (BestLang
!= NULL
) {
1295 FreePool (BestLang
);
1298 if (!EFI_ERROR(Status
)) {
1302 Status
= gBS
->OpenProtocol(
1304 &gEfiComponentNameProtocolGuid
,
1305 (VOID
**)&CompNameStruct
,
1308 EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
1309 if (!EFI_ERROR(Status
)) {
1310 BestLang
= GetBestLanguageForDriver (CompNameStruct
->SupportedLanguages
, Language
, FALSE
);
1311 Status
= CompNameStruct
->GetDriverName(CompNameStruct
, BestLang
, &RetVal
);
1312 if (BestLang
!= NULL
) {
1313 FreePool (BestLang
);
1315 if (!EFI_ERROR(Status
)) {
1323 Function to initialize the file global mHandleList object for use in
1324 vonverting handles to index and index to handle.
1326 @retval EFI_SUCCESS The operation was successful.
1330 InternalShellInitHandleList(
1335 EFI_HANDLE
*HandleBuffer
;
1337 HANDLE_LIST
*ListWalker
;
1339 if (mHandleList
.NextIndex
!= 0) {
1342 InitializeListHead(&mHandleList
.List
.Link
);
1343 mHandleList
.NextIndex
= 1;
1344 Status
= gBS
->LocateHandleBuffer (
1351 ASSERT_EFI_ERROR(Status
);
1352 if (EFI_ERROR(Status
)) {
1355 for (mHandleList
.NextIndex
= 1 ; mHandleList
.NextIndex
<= HandleCount
; mHandleList
.NextIndex
++){
1356 ListWalker
= AllocateZeroPool(sizeof(HANDLE_LIST
));
1357 ASSERT(ListWalker
!= NULL
);
1358 ListWalker
->TheHandle
= HandleBuffer
[mHandleList
.NextIndex
-1];
1359 ListWalker
->TheIndex
= mHandleList
.NextIndex
;
1360 InsertTailList(&mHandleList
.List
.Link
,&ListWalker
->Link
);
1362 FreePool(HandleBuffer
);
1363 return (EFI_SUCCESS
);
1367 Function to retrieve the human-friendly index of a given handle. If the handle
1368 does not have a index one will be automatically assigned. The index value is valid
1369 until the termination of the shell application.
1371 @param[in] TheHandle The handle to retrieve an index for.
1373 @retval 0 A memory allocation failed.
1374 @return The index of the handle.
1379 ConvertHandleToHandleIndex(
1380 IN CONST EFI_HANDLE TheHandle
1384 EFI_GUID
**ProtocolBuffer
;
1385 UINTN ProtocolCount
;
1386 HANDLE_LIST
*ListWalker
;
1388 if (TheHandle
== NULL
) {
1392 InternalShellInitHandleList();
1394 for (ListWalker
= (HANDLE_LIST
*)GetFirstNode(&mHandleList
.List
.Link
)
1395 ; !IsNull(&mHandleList
.List
.Link
,&ListWalker
->Link
)
1396 ; ListWalker
= (HANDLE_LIST
*)GetNextNode(&mHandleList
.List
.Link
,&ListWalker
->Link
)
1398 if (ListWalker
->TheHandle
== TheHandle
) {
1400 // Verify that TheHandle is still present in the Handle Database
1402 Status
= gBS
->ProtocolsPerHandle(TheHandle
, &ProtocolBuffer
, &ProtocolCount
);
1403 if (EFI_ERROR (Status
)) {
1405 // TheHandle is not present in the Handle Database, so delete from the handle list
1407 RemoveEntryList (&ListWalker
->Link
);
1410 FreePool (ProtocolBuffer
);
1411 return (ListWalker
->TheIndex
);
1416 // Verify that TheHandle is valid handle
1418 Status
= gBS
->ProtocolsPerHandle(TheHandle
, &ProtocolBuffer
, &ProtocolCount
);
1419 if (EFI_ERROR (Status
)) {
1421 // TheHandle is not valid, so do not add to handle list
1425 FreePool (ProtocolBuffer
);
1427 ListWalker
= AllocateZeroPool(sizeof(HANDLE_LIST
));
1428 ASSERT(ListWalker
!= NULL
);
1429 ListWalker
->TheHandle
= TheHandle
;
1430 ListWalker
->TheIndex
= mHandleList
.NextIndex
++;
1431 InsertTailList(&mHandleList
.List
.Link
,&ListWalker
->Link
);
1432 return (ListWalker
->TheIndex
);
1438 Function to retrieve the EFI_HANDLE from the human-friendly index.
1440 @param[in] TheIndex The index to retrieve the EFI_HANDLE for.
1442 @retval NULL The index was invalid.
1443 @return The EFI_HANDLE that index represents.
1448 ConvertHandleIndexToHandle(
1449 IN CONST UINTN TheIndex
1453 EFI_GUID
**ProtocolBuffer
;
1454 UINTN ProtocolCount
;
1455 HANDLE_LIST
*ListWalker
;
1457 InternalShellInitHandleList();
1459 if (TheIndex
>= mHandleList
.NextIndex
) {
1463 for (ListWalker
= (HANDLE_LIST
*)GetFirstNode(&mHandleList
.List
.Link
)
1464 ; !IsNull(&mHandleList
.List
.Link
,&ListWalker
->Link
)
1465 ; ListWalker
= (HANDLE_LIST
*)GetNextNode(&mHandleList
.List
.Link
,&ListWalker
->Link
)
1467 if (ListWalker
->TheIndex
== TheIndex
&& ListWalker
->TheHandle
!= NULL
) {
1469 // Verify that LinkWalker->TheHandle is valid handle
1471 Status
= gBS
->ProtocolsPerHandle(ListWalker
->TheHandle
, &ProtocolBuffer
, &ProtocolCount
);
1472 if (EFI_ERROR (Status
)) {
1474 // TheHandle is not valid, so do not add to handle list
1476 ListWalker
->TheHandle
= NULL
;
1478 return (ListWalker
->TheHandle
);
1485 Gets all the related EFI_HANDLEs based on the mask supplied.
1487 This function scans all EFI_HANDLES in the UEFI environment's handle database
1488 and returns the ones with the specified relationship (Mask) to the specified
1491 If both DriverBindingHandle and ControllerHandle are NULL, then ASSERT.
1492 If MatchingHandleCount is NULL, then ASSERT.
1494 If MatchingHandleBuffer is not NULL upon a successful return the memory must be
1497 @param[in] DriverBindingHandle The handle with Driver Binding protocol on it.
1498 @param[in] ControllerHandle The handle with Device Path protocol on it.
1499 @param[in] MatchingHandleCount The pointer to UINTN that specifies the number of HANDLES in
1500 MatchingHandleBuffer.
1501 @param[out] MatchingHandleBuffer On a successful return, a buffer of MatchingHandleCount
1502 EFI_HANDLEs with a terminating NULL EFI_HANDLE.
1503 @param[out] HandleType An array of type information.
1505 @retval EFI_SUCCESS The operation was successful, and any related handles
1506 are in MatchingHandleBuffer.
1507 @retval EFI_NOT_FOUND No matching handles were found.
1508 @retval EFI_INVALID_PARAMETER A parameter was invalid or out of range.
1512 ParseHandleDatabaseByRelationshipWithType (
1513 IN CONST EFI_HANDLE DriverBindingHandle OPTIONAL
,
1514 IN CONST EFI_HANDLE ControllerHandle OPTIONAL
,
1515 IN UINTN
*HandleCount
,
1516 OUT EFI_HANDLE
**HandleBuffer
,
1517 OUT UINTN
**HandleType
1522 EFI_GUID
**ProtocolGuidArray
;
1524 UINTN ProtocolIndex
;
1525 EFI_OPEN_PROTOCOL_INFORMATION_ENTRY
*OpenInfo
;
1526 UINTN OpenInfoCount
;
1527 UINTN OpenInfoIndex
;
1529 INTN DriverBindingHandleIndex
;
1531 ASSERT(HandleCount
!= NULL
);
1532 ASSERT(HandleBuffer
!= NULL
);
1533 ASSERT(HandleType
!= NULL
);
1534 ASSERT(DriverBindingHandle
!= NULL
|| ControllerHandle
!= NULL
);
1537 *HandleBuffer
= NULL
;
1541 // Retrieve the list of all handles from the handle database
1543 Status
= gBS
->LocateHandleBuffer (
1550 if (EFI_ERROR (Status
)) {
1554 *HandleType
= AllocateZeroPool (*HandleCount
* sizeof (UINTN
));
1555 ASSERT(*HandleType
!= NULL
);
1557 DriverBindingHandleIndex
= -1;
1558 for (HandleIndex
= 0; HandleIndex
< *HandleCount
; HandleIndex
++) {
1559 if (DriverBindingHandle
!= NULL
&& (*HandleBuffer
)[HandleIndex
] == DriverBindingHandle
) {
1560 DriverBindingHandleIndex
= (INTN
)HandleIndex
;
1564 for (HandleIndex
= 0; HandleIndex
< *HandleCount
; HandleIndex
++) {
1566 // Retrieve the list of all the protocols on each handle
1568 Status
= gBS
->ProtocolsPerHandle (
1569 (*HandleBuffer
)[HandleIndex
],
1573 if (EFI_ERROR (Status
)) {
1577 for (ProtocolIndex
= 0; ProtocolIndex
< ArrayCount
; ProtocolIndex
++) {
1580 // Set the bit describing what this handle has
1582 if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiLoadedImageProtocolGuid
) ) {
1583 (*HandleType
)[HandleIndex
] |= (UINTN
)HR_IMAGE_HANDLE
;
1584 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiDriverBindingProtocolGuid
) ) {
1585 (*HandleType
)[HandleIndex
] |= (UINTN
)HR_DRIVER_BINDING_HANDLE
;
1586 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiDriverConfiguration2ProtocolGuid
)) {
1587 (*HandleType
)[HandleIndex
] |= (UINTN
)HR_DRIVER_CONFIGURATION_HANDLE
;
1588 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiDriverConfigurationProtocolGuid
) ) {
1589 (*HandleType
)[HandleIndex
] |= (UINTN
)HR_DRIVER_CONFIGURATION_HANDLE
;
1590 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiDriverDiagnostics2ProtocolGuid
) ) {
1591 (*HandleType
)[HandleIndex
] |= (UINTN
)HR_DRIVER_DIAGNOSTICS_HANDLE
;
1592 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiDriverDiagnosticsProtocolGuid
) ) {
1593 (*HandleType
)[HandleIndex
] |= (UINTN
)HR_DRIVER_DIAGNOSTICS_HANDLE
;
1594 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiComponentName2ProtocolGuid
) ) {
1595 (*HandleType
)[HandleIndex
] |= (UINTN
)HR_COMPONENT_NAME_HANDLE
;
1596 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiComponentNameProtocolGuid
) ) {
1597 (*HandleType
)[HandleIndex
] |= (UINTN
)HR_COMPONENT_NAME_HANDLE
;
1598 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiDevicePathProtocolGuid
) ) {
1599 (*HandleType
)[HandleIndex
] |= (UINTN
)HR_DEVICE_HANDLE
;
1602 ASSERT((*HandleType
)[HandleIndex
] == (*HandleType
)[HandleIndex
]);
1606 // Retrieve the list of agents that have opened each protocol
1608 Status
= gBS
->OpenProtocolInformation (
1609 (*HandleBuffer
)[HandleIndex
],
1610 ProtocolGuidArray
[ProtocolIndex
],
1614 if (EFI_ERROR (Status
)) {
1618 if (ControllerHandle
== NULL
) {
1620 // ControllerHandle == NULL and DriverBindingHandle != NULL.
1621 // Return information on all the controller handles that the driver specified by DriverBindingHandle is managing
1623 for (OpenInfoIndex
= 0; OpenInfoIndex
< OpenInfoCount
; OpenInfoIndex
++) {
1624 if (OpenInfo
[OpenInfoIndex
].AgentHandle
== DriverBindingHandle
&& (OpenInfo
[OpenInfoIndex
].Attributes
& EFI_OPEN_PROTOCOL_BY_DRIVER
) != 0) {
1625 (*HandleType
)[HandleIndex
] |= (UINTN
)(HR_DEVICE_HANDLE
| HR_CONTROLLER_HANDLE
);
1626 if (DriverBindingHandleIndex
!= -1) {
1627 (*HandleType
)[DriverBindingHandleIndex
] |= (UINTN
)HR_DEVICE_DRIVER
;
1630 if (OpenInfo
[OpenInfoIndex
].AgentHandle
== DriverBindingHandle
&& (OpenInfo
[OpenInfoIndex
].Attributes
& EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
) != 0) {
1631 (*HandleType
)[HandleIndex
] |= (UINTN
)(HR_DEVICE_HANDLE
| HR_CONTROLLER_HANDLE
);
1632 if (DriverBindingHandleIndex
!= -1) {
1633 (*HandleType
)[DriverBindingHandleIndex
] |= (UINTN
)(HR_BUS_DRIVER
| HR_DEVICE_DRIVER
);
1635 for (ChildIndex
= 0; ChildIndex
< *HandleCount
; ChildIndex
++) {
1636 if (OpenInfo
[OpenInfoIndex
].ControllerHandle
== (*HandleBuffer
)[ChildIndex
]) {
1637 (*HandleType
)[ChildIndex
] |= (UINTN
)(HR_DEVICE_HANDLE
| HR_CHILD_HANDLE
);
1643 if (DriverBindingHandle
== NULL
&& ControllerHandle
!= NULL
) {
1644 if (ControllerHandle
== (*HandleBuffer
)[HandleIndex
]) {
1645 (*HandleType
)[HandleIndex
] |= (UINTN
)(HR_DEVICE_HANDLE
| HR_CONTROLLER_HANDLE
);
1646 for (OpenInfoIndex
= 0; OpenInfoIndex
< OpenInfoCount
; OpenInfoIndex
++) {
1647 if ((OpenInfo
[OpenInfoIndex
].Attributes
& EFI_OPEN_PROTOCOL_BY_DRIVER
) != 0) {
1648 for (ChildIndex
= 0; ChildIndex
< *HandleCount
; ChildIndex
++) {
1649 if (OpenInfo
[OpenInfoIndex
].AgentHandle
== (*HandleBuffer
)[ChildIndex
]) {
1650 (*HandleType
)[ChildIndex
] |= (UINTN
)HR_DEVICE_DRIVER
;
1654 if ((OpenInfo
[OpenInfoIndex
].Attributes
& EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
) != 0) {
1655 for (ChildIndex
= 0; ChildIndex
< *HandleCount
; ChildIndex
++) {
1656 if (OpenInfo
[OpenInfoIndex
].AgentHandle
== (*HandleBuffer
)[ChildIndex
]) {
1657 (*HandleType
)[ChildIndex
] |= (UINTN
)(HR_BUS_DRIVER
| HR_DEVICE_DRIVER
);
1659 if (OpenInfo
[OpenInfoIndex
].ControllerHandle
== (*HandleBuffer
)[ChildIndex
]) {
1660 (*HandleType
)[ChildIndex
] |= (UINTN
)(HR_DEVICE_HANDLE
| HR_CHILD_HANDLE
);
1666 for (OpenInfoIndex
= 0; OpenInfoIndex
< OpenInfoCount
; OpenInfoIndex
++) {
1667 if ((OpenInfo
[OpenInfoIndex
].Attributes
& EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
) != 0) {
1668 if (OpenInfo
[OpenInfoIndex
].ControllerHandle
== ControllerHandle
) {
1669 (*HandleType
)[HandleIndex
] |= (UINTN
)(HR_DEVICE_HANDLE
| HR_PARENT_HANDLE
);
1675 if (DriverBindingHandle
!= NULL
&& ControllerHandle
!= NULL
) {
1676 if (ControllerHandle
== (*HandleBuffer
)[HandleIndex
]) {
1677 (*HandleType
)[HandleIndex
] |= (UINTN
)(HR_DEVICE_HANDLE
| HR_CONTROLLER_HANDLE
);
1678 for (OpenInfoIndex
= 0; OpenInfoIndex
< OpenInfoCount
; OpenInfoIndex
++) {
1679 if ((OpenInfo
[OpenInfoIndex
].Attributes
& EFI_OPEN_PROTOCOL_BY_DRIVER
) != 0) {
1680 if (OpenInfo
[OpenInfoIndex
].AgentHandle
== DriverBindingHandle
) {
1681 if (DriverBindingHandleIndex
!= -1) {
1682 (*HandleType
)[DriverBindingHandleIndex
] |= (UINTN
)HR_DEVICE_DRIVER
;
1686 if ((OpenInfo
[OpenInfoIndex
].Attributes
& EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
) != 0) {
1687 if (OpenInfo
[OpenInfoIndex
].AgentHandle
== DriverBindingHandle
) {
1688 for (ChildIndex
= 0; ChildIndex
< *HandleCount
; ChildIndex
++) {
1689 if (OpenInfo
[OpenInfoIndex
].ControllerHandle
== (*HandleBuffer
)[ChildIndex
]) {
1690 (*HandleType
)[ChildIndex
] |= (UINTN
)(HR_DEVICE_HANDLE
| HR_CHILD_HANDLE
);
1695 for (ChildIndex
= 0; ChildIndex
< *HandleCount
; ChildIndex
++) {
1696 if (OpenInfo
[OpenInfoIndex
].AgentHandle
== (*HandleBuffer
)[ChildIndex
]) {
1697 (*HandleType
)[ChildIndex
] |= (UINTN
)(HR_BUS_DRIVER
| HR_DEVICE_DRIVER
);
1703 for (OpenInfoIndex
= 0; OpenInfoIndex
< OpenInfoCount
; OpenInfoIndex
++) {
1704 if ((OpenInfo
[OpenInfoIndex
].Attributes
& EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
) != 0) {
1705 if (OpenInfo
[OpenInfoIndex
].ControllerHandle
== ControllerHandle
) {
1706 (*HandleType
)[HandleIndex
] |= (UINTN
)(HR_DEVICE_HANDLE
| HR_PARENT_HANDLE
);
1712 FreePool (OpenInfo
);
1714 FreePool (ProtocolGuidArray
);
1720 Gets all the related EFI_HANDLEs based on the single EFI_HANDLE and the mask
1723 This function will scan all EFI_HANDLES in the UEFI environment's handle database
1724 and return all the ones with the specified relationship (Mask) to the specified
1727 If both DriverBindingHandle and ControllerHandle are NULL, then ASSERT.
1728 If MatchingHandleCount is NULL, then ASSERT.
1730 If MatchingHandleBuffer is not NULL upon a sucessful return the memory must be
1733 @param[in] DriverBindingHandle Handle to a object with Driver Binding protocol
1735 @param[in] ControllerHandle Handle to a device with Device Path protocol on it.
1736 @param[in] Mask Mask of what relationship(s) is desired.
1737 @param[in] MatchingHandleCount Poitner to UINTN specifying number of HANDLES in
1738 MatchingHandleBuffer.
1739 @param[out] MatchingHandleBuffer On a sucessful return a buffer of MatchingHandleCount
1740 EFI_HANDLEs and a terminating NULL EFI_HANDLE.
1742 @retval EFI_SUCCESS The operation was sucessful and any related handles
1743 are in MatchingHandleBuffer;
1744 @retval EFI_NOT_FOUND No matching handles were found.
1745 @retval EFI_INVALID_PARAMETER A parameter was invalid or out of range.
1749 ParseHandleDatabaseByRelationship (
1750 IN CONST EFI_HANDLE DriverBindingHandle OPTIONAL
,
1751 IN CONST EFI_HANDLE ControllerHandle OPTIONAL
,
1752 IN CONST UINTN Mask
,
1753 IN UINTN
*MatchingHandleCount
,
1754 OUT EFI_HANDLE
**MatchingHandleBuffer OPTIONAL
1759 EFI_HANDLE
*HandleBuffer
;
1763 ASSERT(MatchingHandleCount
!= NULL
);
1764 ASSERT(DriverBindingHandle
!= NULL
|| ControllerHandle
!= NULL
);
1766 if ((Mask
& HR_VALID_MASK
) != Mask
) {
1767 return (EFI_INVALID_PARAMETER
);
1770 if ((Mask
& HR_CHILD_HANDLE
) != 0 && DriverBindingHandle
== NULL
) {
1771 return (EFI_INVALID_PARAMETER
);
1774 *MatchingHandleCount
= 0;
1775 if (MatchingHandleBuffer
!= NULL
) {
1776 *MatchingHandleBuffer
= NULL
;
1779 HandleBuffer
= NULL
;
1782 Status
= ParseHandleDatabaseByRelationshipWithType (
1783 DriverBindingHandle
,
1789 if (!EFI_ERROR (Status
)) {
1791 // Count the number of handles that match the attributes in Mask
1793 for (HandleIndex
= 0; HandleIndex
< HandleCount
; HandleIndex
++) {
1794 if ((HandleType
[HandleIndex
] & Mask
) == Mask
) {
1795 (*MatchingHandleCount
)++;
1799 // If no handles match the attributes in Mask then return EFI_NOT_FOUND
1801 if (*MatchingHandleCount
== 0) {
1802 Status
= EFI_NOT_FOUND
;
1805 if (MatchingHandleBuffer
== NULL
) {
1807 // Someone just wanted the count...
1809 Status
= EFI_SUCCESS
;
1812 // Allocate a handle buffer for the number of handles that matched the attributes in Mask
1814 *MatchingHandleBuffer
= AllocateZeroPool ((*MatchingHandleCount
+1)* sizeof (EFI_HANDLE
));
1815 ASSERT(*MatchingHandleBuffer
!= NULL
);
1817 for (HandleIndex
= 0,*MatchingHandleCount
= 0
1818 ; HandleIndex
< HandleCount
1822 // Fill the allocated buffer with the handles that matched the attributes in Mask
1824 if ((HandleType
[HandleIndex
] & Mask
) == Mask
) {
1825 (*MatchingHandleBuffer
)[(*MatchingHandleCount
)++] = HandleBuffer
[HandleIndex
];
1830 // Make the last one NULL
1832 (*MatchingHandleBuffer
)[*MatchingHandleCount
] = NULL
;
1834 Status
= EFI_SUCCESS
;
1835 } // MacthingHandleBuffer == NULL (ELSE)
1836 } // *MatchingHandleCount == 0 (ELSE)
1837 } // no error on ParseHandleDatabaseByRelationshipWithType
1839 if (HandleBuffer
!= NULL
) {
1840 FreePool (HandleBuffer
);
1843 if (HandleType
!= NULL
) {
1844 FreePool (HandleType
);
1851 Gets handles for any child controllers of the passed in controller.
1853 @param[in] ControllerHandle The handle of the "parent controller"
1854 @param[in] MatchingHandleCount Pointer to the number of handles in
1855 MatchingHandleBuffer on return.
1856 @param[out] MatchingHandleBuffer Buffer containing handles on a successful
1860 @retval EFI_SUCCESS The operation was sucessful.
1864 ParseHandleDatabaseForChildControllers(
1865 IN CONST EFI_HANDLE ControllerHandle
,
1866 IN UINTN
*MatchingHandleCount
,
1867 OUT EFI_HANDLE
**MatchingHandleBuffer OPTIONAL
1872 UINTN DriverBindingHandleCount
;
1873 EFI_HANDLE
*DriverBindingHandleBuffer
;
1874 UINTN DriverBindingHandleIndex
;
1875 UINTN ChildControllerHandleCount
;
1876 EFI_HANDLE
*ChildControllerHandleBuffer
;
1877 UINTN ChildControllerHandleIndex
;
1878 EFI_HANDLE
*HandleBufferForReturn
;
1880 if (MatchingHandleCount
== NULL
) {
1881 return (EFI_INVALID_PARAMETER
);
1883 *MatchingHandleCount
= 0;
1885 Status
= PARSE_HANDLE_DATABASE_UEFI_DRIVERS (
1887 &DriverBindingHandleCount
,
1888 &DriverBindingHandleBuffer
1890 if (EFI_ERROR (Status
)) {
1895 // Get a buffer big enough for all the controllers.
1897 HandleBufferForReturn
= GetHandleListByProtocol(NULL
);
1898 if (HandleBufferForReturn
== NULL
) {
1899 FreePool (DriverBindingHandleBuffer
);
1900 return (EFI_NOT_FOUND
);
1903 for (DriverBindingHandleIndex
= 0; DriverBindingHandleIndex
< DriverBindingHandleCount
; DriverBindingHandleIndex
++) {
1904 Status
= PARSE_HANDLE_DATABASE_MANAGED_CHILDREN (
1905 DriverBindingHandleBuffer
[DriverBindingHandleIndex
],
1907 &ChildControllerHandleCount
,
1908 &ChildControllerHandleBuffer
1910 if (EFI_ERROR (Status
)) {
1914 for (ChildControllerHandleIndex
= 0;
1915 ChildControllerHandleIndex
< ChildControllerHandleCount
;
1916 ChildControllerHandleIndex
++
1918 for (HandleIndex
= 0; HandleIndex
< *MatchingHandleCount
; HandleIndex
++) {
1919 if (HandleBufferForReturn
[HandleIndex
] == ChildControllerHandleBuffer
[ChildControllerHandleIndex
]) {
1923 if (HandleIndex
>= *MatchingHandleCount
) {
1924 HandleBufferForReturn
[(*MatchingHandleCount
)++] = ChildControllerHandleBuffer
[ChildControllerHandleIndex
];
1928 FreePool (ChildControllerHandleBuffer
);
1931 FreePool (DriverBindingHandleBuffer
);
1933 if (MatchingHandleBuffer
!= NULL
) {
1934 *MatchingHandleBuffer
= HandleBufferForReturn
;
1936 FreePool(HandleBufferForReturn
);
1939 return (EFI_SUCCESS
);
1943 Appends 1 buffer to another buffer. This will re-allocate the destination buffer
1944 if necessary to fit all of the data.
1946 If DestinationBuffer is NULL, then ASSERT().
1948 @param[in, out] DestinationBuffer The pointer to the pointer to the buffer to append onto.
1949 @param[in, out] DestinationSize The pointer to the size of DestinationBuffer.
1950 @param[in] SourceBuffer The pointer to the buffer to append onto DestinationBuffer.
1951 @param[in] SourceSize The number of bytes of SourceBuffer to append.
1953 @retval NULL A memory allocation failed.
1954 @retval NULL A parameter was invalid.
1955 @return A pointer to (*DestinationBuffer).
1960 IN OUT VOID
**DestinationBuffer
,
1961 IN OUT UINTN
*DestinationSize
,
1962 IN VOID
*SourceBuffer
,
1966 UINTN LocalDestinationSize
;
1967 UINTN LocalDestinationFinalSize
;
1969 ASSERT(DestinationBuffer
!= NULL
);
1971 if (SourceSize
== 0 || SourceBuffer
== NULL
) {
1972 return (*DestinationBuffer
);
1975 if (DestinationSize
== NULL
) {
1976 LocalDestinationSize
= 0;
1978 LocalDestinationSize
= *DestinationSize
;
1981 LocalDestinationFinalSize
= LocalDestinationSize
+ SourceSize
;
1983 if (DestinationSize
!= NULL
) {
1984 *DestinationSize
= LocalDestinationSize
;
1987 if (LocalDestinationSize
== 0) {
1989 *DestinationBuffer
= AllocateZeroPool(LocalDestinationFinalSize
);
1992 *DestinationBuffer
= ReallocatePool(LocalDestinationSize
, LocalDestinationFinalSize
, *DestinationBuffer
);
1995 ASSERT(*DestinationBuffer
!= NULL
);
1998 return (CopyMem(((UINT8
*)(*DestinationBuffer
)) + LocalDestinationSize
, SourceBuffer
, SourceSize
));
2002 Gets handles for any child devices produced by the passed in driver.
2004 @param[in] DriverHandle The handle of the driver.
2005 @param[in] MatchingHandleCount Pointer to the number of handles in
2006 MatchingHandleBuffer on return.
2007 @param[out] MatchingHandleBuffer Buffer containing handles on a successful
2009 @retval EFI_SUCCESS The operation was sucessful.
2010 @sa ParseHandleDatabaseByRelationship
2014 ParseHandleDatabaseForChildDevices(
2015 IN CONST EFI_HANDLE DriverHandle
,
2016 IN UINTN
*MatchingHandleCount
,
2017 OUT EFI_HANDLE
**MatchingHandleBuffer OPTIONAL
2021 EFI_HANDLE
*Buffer2
;
2026 UINTN HandleBufferSize
;
2028 ASSERT(MatchingHandleCount
!= NULL
);
2030 HandleBufferSize
= 0;
2033 *MatchingHandleCount
= 0;
2035 Status
= PARSE_HANDLE_DATABASE_DEVICES (
2040 if (!EFI_ERROR (Status
)) {
2041 for (HandleIndex
= 0; HandleIndex
< Count1
; HandleIndex
++) {
2043 // now find the children
2045 Status
= PARSE_HANDLE_DATABASE_MANAGED_CHILDREN (
2047 Buffer
[HandleIndex
],
2051 if (EFI_ERROR(Status
)) {
2055 // save out required and optional data elements
2057 *MatchingHandleCount
+= Count2
;
2058 if (MatchingHandleBuffer
!= NULL
) {
2059 *MatchingHandleBuffer
= BuffernCatGrow((VOID
**)MatchingHandleBuffer
, &HandleBufferSize
, Buffer2
, Count2
* sizeof(Buffer2
[0]));
2065 if (Buffer2
!= NULL
) {
2071 if (Buffer
!= NULL
) {
2078 Function to get all handles that support a given protocol or all handles.
2080 @param[in] ProtocolGuid The guid of the protocol to get handles for. If NULL
2081 then the function will return all handles.
2083 @retval NULL A memory allocation failed.
2084 @return A NULL terminated list of handles.
2088 GetHandleListByProtocol (
2089 IN CONST EFI_GUID
*ProtocolGuid OPTIONAL
2092 EFI_HANDLE
*HandleList
;
2100 // We cannot use LocateHandleBuffer since we need that NULL item on the ends of the list!
2102 if (ProtocolGuid
== NULL
) {
2103 Status
= gBS
->LocateHandle(AllHandles
, NULL
, NULL
, &Size
, HandleList
);
2104 if (Status
== EFI_BUFFER_TOO_SMALL
) {
2105 HandleList
= AllocateZeroPool(Size
+ sizeof(EFI_HANDLE
));
2106 if (HandleList
== NULL
) {
2109 Status
= gBS
->LocateHandle(AllHandles
, NULL
, NULL
, &Size
, HandleList
);
2110 HandleList
[Size
/sizeof(EFI_HANDLE
)] = NULL
;
2113 Status
= gBS
->LocateHandle(ByProtocol
, (EFI_GUID
*)ProtocolGuid
, NULL
, &Size
, HandleList
);
2114 if (Status
== EFI_BUFFER_TOO_SMALL
) {
2115 HandleList
= AllocateZeroPool(Size
+ sizeof(EFI_HANDLE
));
2116 if (HandleList
== NULL
) {
2119 Status
= gBS
->LocateHandle(ByProtocol
, (EFI_GUID
*)ProtocolGuid
, NULL
, &Size
, HandleList
);
2120 HandleList
[Size
/sizeof(EFI_HANDLE
)] = NULL
;
2123 if (EFI_ERROR(Status
)) {
2124 if (HandleList
!= NULL
) {
2125 FreePool(HandleList
);
2129 return (HandleList
);
2133 Function to get all handles that support some protocols.
2135 @param[in] ProtocolGuids A NULL terminated list of protocol GUIDs.
2137 @retval NULL A memory allocation failed.
2138 @retval NULL ProtocolGuids was NULL.
2139 @return A NULL terminated list of EFI_HANDLEs.
2143 GetHandleListByProtocolList (
2144 IN CONST EFI_GUID
**ProtocolGuids
2147 EFI_HANDLE
*HandleList
;
2152 CONST EFI_GUID
**GuidWalker
;
2153 EFI_HANDLE
*HandleWalker1
;
2154 EFI_HANDLE
*HandleWalker2
;
2158 TotalSize
= sizeof(EFI_HANDLE
);
2160 for (GuidWalker
= ProtocolGuids
; GuidWalker
!= NULL
&& *GuidWalker
!= NULL
; GuidWalker
++,Size
= 0){
2161 Status
= gBS
->LocateHandle(ByProtocol
, (EFI_GUID
*)(*GuidWalker
), NULL
, &Size
, NULL
);
2162 if (Status
== EFI_BUFFER_TOO_SMALL
) {
2168 // No handles were found...
2170 if (TotalSize
== sizeof(EFI_HANDLE
)) {
2174 HandleList
= AllocateZeroPool(TotalSize
);
2175 if (HandleList
== NULL
) {
2180 for (GuidWalker
= ProtocolGuids
; GuidWalker
!= NULL
&& *GuidWalker
!= NULL
; GuidWalker
++){
2181 TempSize
= TotalSize
- Size
;
2182 Status
= gBS
->LocateHandle(ByProtocol
, (EFI_GUID
*)(*GuidWalker
), NULL
, &TempSize
, HandleList
+(Size
/sizeof(EFI_HANDLE
)));
2185 // Allow for missing protocols... Only update the 'used' size upon success.
2187 if (!EFI_ERROR(Status
)) {
2191 ASSERT(HandleList
[(TotalSize
/sizeof(EFI_HANDLE
))-1] == NULL
);
2193 for (HandleWalker1
= HandleList
; HandleWalker1
!= NULL
&& *HandleWalker1
!= NULL
; HandleWalker1
++) {
2194 for (HandleWalker2
= HandleWalker1
+ 1; HandleWalker2
!= NULL
&& *HandleWalker2
!= NULL
; HandleWalker2
++) {
2195 if (*HandleWalker1
== *HandleWalker2
) {
2197 // copy memory back 1 handle width.
2199 CopyMem(HandleWalker2
, HandleWalker2
+ 1, TotalSize
- ((HandleWalker2
-HandleList
+1)*sizeof(EFI_HANDLE
)));
2204 return (HandleList
);