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.
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 // Put the information on the NT32 protocol GUIDs here so we are not dependant on the Nt32Pkg
587 #define LOCAL_EFI_WIN_NT_THUNK_PROTOCOL_GUID \
589 0x58c518b1, 0x76f3, 0x11d4, { 0xbc, 0xea, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 } \
592 #define LOCAL_EFI_WIN_NT_BUS_DRIVER_IO_PROTOCOL_GUID \
594 0x96eb4ad6, 0xa32a, 0x11d4, { 0xbc, 0xfd, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 } \
597 #define LOCAL_EFI_WIN_NT_SERIAL_PORT_GUID \
599 0xc95a93d, 0xa006, 0x11d4, { 0xbc, 0xfa, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 } \
601 STATIC CONST EFI_GUID WinNtThunkProtocolGuid
= LOCAL_EFI_WIN_NT_THUNK_PROTOCOL_GUID
;
602 STATIC CONST EFI_GUID WinNtIoProtocolGuid
= LOCAL_EFI_WIN_NT_BUS_DRIVER_IO_PROTOCOL_GUID
;
603 STATIC CONST EFI_GUID WinNtSerialPortGuid
= LOCAL_EFI_WIN_NT_SERIAL_PORT_GUID
;
605 STATIC CONST GUID_INFO_BLOCK mGuidStringListNT
[] = {
606 {STRING_TOKEN(STR_WINNT_THUNK
), (EFI_GUID
*)&WinNtThunkProtocolGuid
, NULL
},
607 {STRING_TOKEN(STR_WINNT_DRIVER_IO
), (EFI_GUID
*)&WinNtIoProtocolGuid
, NULL
},
608 {STRING_TOKEN(STR_WINNT_SERIAL_PORT
), (EFI_GUID
*)&WinNtSerialPortGuid
, NULL
},
609 {STRING_TOKEN(STR_UNKNOWN_DEVICE
), NULL
, NULL
},
612 STATIC CONST GUID_INFO_BLOCK mGuidStringList
[] = {
613 {STRING_TOKEN(STR_LOADED_IMAGE
), &gEfiLoadedImageProtocolGuid
, LoadedImageProtocolDumpInformation
},
614 {STRING_TOKEN(STR_DEVICE_PATH
), &gEfiDevicePathProtocolGuid
, DevicePathProtocolDumpInformation
},
615 {STRING_TOKEN(STR_IMAGE_PATH
), &gEfiLoadedImageDevicePathProtocolGuid
, DevicePathProtocolDumpInformation
},
616 {STRING_TOKEN(STR_DEVICE_PATH_UTIL
), &gEfiDevicePathUtilitiesProtocolGuid
, NULL
},
617 {STRING_TOKEN(STR_DEVICE_PATH_TXT
), &gEfiDevicePathToTextProtocolGuid
, NULL
},
618 {STRING_TOKEN(STR_DEVICE_PATH_FTXT
), &gEfiDevicePathFromTextProtocolGuid
, NULL
},
619 {STRING_TOKEN(STR_DEVICE_PATH_PC
), &gEfiPcAnsiGuid
, NULL
},
620 {STRING_TOKEN(STR_DEVICE_PATH_VT100
), &gEfiVT100Guid
, NULL
},
621 {STRING_TOKEN(STR_DEVICE_PATH_VT100P
), &gEfiVT100PlusGuid
, NULL
},
622 {STRING_TOKEN(STR_DEVICE_PATH_VTUTF8
), &gEfiVTUTF8Guid
, NULL
},
623 {STRING_TOKEN(STR_DRIVER_BINDING
), &gEfiDriverBindingProtocolGuid
, NULL
},
624 {STRING_TOKEN(STR_PLATFORM_OVERRIDE
), &gEfiPlatformDriverOverrideProtocolGuid
, NULL
},
625 {STRING_TOKEN(STR_BUS_OVERRIDE
), &gEfiBusSpecificDriverOverrideProtocolGuid
, NULL
},
626 {STRING_TOKEN(STR_DRIVER_DIAG
), &gEfiDriverDiagnosticsProtocolGuid
, NULL
},
627 {STRING_TOKEN(STR_DRIVER_DIAG2
), &gEfiDriverDiagnostics2ProtocolGuid
, NULL
},
628 {STRING_TOKEN(STR_DRIVER_CN
), &gEfiComponentNameProtocolGuid
, NULL
},
629 {STRING_TOKEN(STR_DRIVER_CN2
), &gEfiComponentName2ProtocolGuid
, NULL
},
630 {STRING_TOKEN(STR_PLAT_DRV_CFG
), &gEfiPlatformToDriverConfigurationProtocolGuid
, NULL
},
631 {STRING_TOKEN(STR_DRIVER_VERSION
), &gEfiDriverSupportedEfiVersionProtocolGuid
, DriverEfiVersionProtocolDumpInformation
},
632 {STRING_TOKEN(STR_TXT_IN
), &gEfiSimpleTextInProtocolGuid
, NULL
},
633 {STRING_TOKEN(STR_TXT_IN_EX
), &gEfiSimpleTextInputExProtocolGuid
, NULL
},
634 {STRING_TOKEN(STR_TXT_OUT
), &gEfiSimpleTextOutProtocolGuid
, TxtOutProtocolDumpInformation
},
635 {STRING_TOKEN(STR_SIM_POINTER
), &gEfiSimplePointerProtocolGuid
, NULL
},
636 {STRING_TOKEN(STR_ABS_POINTER
), &gEfiAbsolutePointerProtocolGuid
, NULL
},
637 {STRING_TOKEN(STR_SERIAL_IO
), &gEfiSerialIoProtocolGuid
, NULL
},
638 {STRING_TOKEN(STR_GRAPHICS_OUTPUT
), &gEfiGraphicsOutputProtocolGuid
, GraphicsOutputProtocolDumpInformation
},
639 {STRING_TOKEN(STR_EDID_DISCOVERED
), &gEfiEdidDiscoveredProtocolGuid
, NULL
},
640 {STRING_TOKEN(STR_EDID_ACTIVE
), &gEfiEdidActiveProtocolGuid
, NULL
},
641 {STRING_TOKEN(STR_EDID_OVERRIDE
), &gEfiEdidOverrideProtocolGuid
, NULL
},
642 {STRING_TOKEN(STR_CON_IN
), &gEfiConsoleInDeviceGuid
, NULL
},
643 {STRING_TOKEN(STR_CON_OUT
), &gEfiConsoleOutDeviceGuid
, NULL
},
644 {STRING_TOKEN(STR_STD_ERR
), &gEfiStandardErrorDeviceGuid
, NULL
},
645 {STRING_TOKEN(STR_LOAD_FILE
), &gEfiLoadFileProtocolGuid
, NULL
},
646 {STRING_TOKEN(STR_LOAD_FILE2
), &gEfiLoadFile2ProtocolGuid
, NULL
},
647 {STRING_TOKEN(STR_SIMPLE_FILE_SYS
), &gEfiSimpleFileSystemProtocolGuid
, NULL
},
648 {STRING_TOKEN(STR_TAPE_IO
), &gEfiTapeIoProtocolGuid
, NULL
},
649 {STRING_TOKEN(STR_DISK_IO
), &gEfiDiskIoProtocolGuid
, NULL
},
650 {STRING_TOKEN(STR_BLK_IO
), &gEfiBlockIoProtocolGuid
, NULL
},
651 {STRING_TOKEN(STR_UC
), &gEfiUnicodeCollationProtocolGuid
, NULL
},
652 {STRING_TOKEN(STR_UC2
), &gEfiUnicodeCollation2ProtocolGuid
, NULL
},
653 {STRING_TOKEN(STR_PCIRB_IO
), &gEfiPciRootBridgeIoProtocolGuid
, PciRootBridgeIoDumpInformation
},
654 {STRING_TOKEN(STR_PCI_IO
), &gEfiPciIoProtocolGuid
, NULL
},
655 {STRING_TOKEN(STR_SCSI_PT
), &gEfiScsiPassThruProtocolGuid
, NULL
},
656 {STRING_TOKEN(STR_SCSI_IO
), &gEfiScsiIoProtocolGuid
, NULL
},
657 {STRING_TOKEN(STR_SCSI_PT_EXT
), &gEfiExtScsiPassThruProtocolGuid
, NULL
},
658 {STRING_TOKEN(STR_ISCSI
), &gEfiIScsiInitiatorNameProtocolGuid
, NULL
},
659 {STRING_TOKEN(STR_USB_IO
), &gEfiUsbIoProtocolGuid
, NULL
},
660 {STRING_TOKEN(STR_USB_HC
), &gEfiUsbHcProtocolGuid
, NULL
},
661 {STRING_TOKEN(STR_USB_HC2
), &gEfiUsb2HcProtocolGuid
, NULL
},
662 {STRING_TOKEN(STR_DEBUG_SUPPORT
), &gEfiDebugSupportProtocolGuid
, NULL
},
663 {STRING_TOKEN(STR_DEBUG_PORT
), &gEfiDebugPortProtocolGuid
, NULL
},
664 {STRING_TOKEN(STR_DECOMPRESS
), &gEfiDecompressProtocolGuid
, NULL
},
665 {STRING_TOKEN(STR_ACPI_TABLE
), &gEfiAcpiTableProtocolGuid
, NULL
},
666 {STRING_TOKEN(STR_EBC_INTERPRETER
), &gEfiEbcProtocolGuid
, NULL
},
667 {STRING_TOKEN(STR_SNP
), &gEfiSimpleNetworkProtocolGuid
, NULL
},
668 {STRING_TOKEN(STR_NII
), &gEfiNetworkInterfaceIdentifierProtocolGuid
, NULL
},
669 {STRING_TOKEN(STR_NII_31
), &gEfiNetworkInterfaceIdentifierProtocolGuid_31
, NULL
},
670 {STRING_TOKEN(STR_PXE_BC
), &gEfiPxeBaseCodeProtocolGuid
, NULL
},
671 {STRING_TOKEN(STR_PXE_CB
), &gEfiPxeBaseCodeCallbackProtocolGuid
, NULL
},
672 {STRING_TOKEN(STR_BIS
), &gEfiBisProtocolGuid
, NULL
},
673 {STRING_TOKEN(STR_MNP_SB
), &gEfiManagedNetworkServiceBindingProtocolGuid
, NULL
},
674 {STRING_TOKEN(STR_MNP
), &gEfiManagedNetworkProtocolGuid
, NULL
},
675 {STRING_TOKEN(STR_ARP_SB
), &gEfiArpServiceBindingProtocolGuid
, NULL
},
676 {STRING_TOKEN(STR_ARP
), &gEfiArpProtocolGuid
, NULL
},
677 {STRING_TOKEN(STR_DHCPV4_SB
), &gEfiDhcp4ServiceBindingProtocolGuid
, NULL
},
678 {STRING_TOKEN(STR_DHCPV4
), &gEfiDhcp4ProtocolGuid
, NULL
},
679 {STRING_TOKEN(STR_TCPV4_SB
), &gEfiTcp4ServiceBindingProtocolGuid
, NULL
},
680 {STRING_TOKEN(STR_TCPV4
), &gEfiTcp4ProtocolGuid
, NULL
},
681 {STRING_TOKEN(STR_IPV4_SB
), &gEfiIp4ServiceBindingProtocolGuid
, NULL
},
682 {STRING_TOKEN(STR_IPV4
), &gEfiIp4ProtocolGuid
, NULL
},
683 {STRING_TOKEN(STR_IPV4_CFG
), &gEfiIp4ConfigProtocolGuid
, NULL
},
684 {STRING_TOKEN(STR_UDPV4_SB
), &gEfiUdp4ServiceBindingProtocolGuid
, NULL
},
685 {STRING_TOKEN(STR_UDPV4
), &gEfiUdp4ProtocolGuid
, NULL
},
686 {STRING_TOKEN(STR_MTFTPV4_SB
), &gEfiMtftp4ServiceBindingProtocolGuid
, NULL
},
687 {STRING_TOKEN(STR_MTFTPV4
), &gEfiMtftp4ProtocolGuid
, NULL
},
688 {STRING_TOKEN(STR_AUTH_INFO
), &gEfiAuthenticationInfoProtocolGuid
, NULL
},
689 {STRING_TOKEN(STR_HASH_SB
), &gEfiHashServiceBindingProtocolGuid
, NULL
},
690 {STRING_TOKEN(STR_HASH
), &gEfiHashProtocolGuid
, NULL
},
691 {STRING_TOKEN(STR_HII_FONT
), &gEfiHiiFontProtocolGuid
, NULL
},
692 {STRING_TOKEN(STR_HII_STRING
), &gEfiHiiStringProtocolGuid
, NULL
},
693 {STRING_TOKEN(STR_HII_IMAGE
), &gEfiHiiImageProtocolGuid
, NULL
},
694 {STRING_TOKEN(STR_HII_DATABASE
), &gEfiHiiDatabaseProtocolGuid
, NULL
},
695 {STRING_TOKEN(STR_HII_CONFIG_ROUT
), &gEfiHiiConfigRoutingProtocolGuid
, NULL
},
696 {STRING_TOKEN(STR_HII_CONFIG_ACC
), &gEfiHiiConfigAccessProtocolGuid
, NULL
},
697 {STRING_TOKEN(STR_HII_FORM_BROWSER2
), &gEfiFormBrowser2ProtocolGuid
, NULL
},
698 {STRING_TOKEN(STR_DRIVER_FAM_OVERRIDE
), &gEfiDriverFamilyOverrideProtocolGuid
, NULL
},
699 {STRING_TOKEN(STR_PCD
), &gPcdProtocolGuid
, NULL
},
700 {STRING_TOKEN(STR_TCG
), &gEfiTcgProtocolGuid
, NULL
},
701 {STRING_TOKEN(STR_HII_PACKAGE_LIST
), &gEfiHiiPackageListProtocolGuid
, NULL
},
704 // the ones under this are deprecated by the current UEFI Spec, but may be found anyways...
706 {STRING_TOKEN(STR_SHELL_INTERFACE
), &gEfiShellInterfaceGuid
, NULL
},
707 {STRING_TOKEN(STR_SHELL_ENV2
), &gEfiShellEnvironment2Guid
, NULL
},
708 {STRING_TOKEN(STR_SHELL_ENV
), &gEfiShellEnvironment2Guid
, NULL
},
709 {STRING_TOKEN(STR_DEVICE_IO
), &gEfiDeviceIoProtocolGuid
, NULL
},
710 {STRING_TOKEN(STR_UGA_DRAW
), &gEfiUgaDrawProtocolGuid
, NULL
},
711 {STRING_TOKEN(STR_UGA_IO
), &gEfiUgaIoProtocolGuid
, NULL
},
712 {STRING_TOKEN(STR_ESP
), &gEfiPartTypeSystemPartGuid
, NULL
},
713 {STRING_TOKEN(STR_GPT_NBR
), &gEfiPartTypeLegacyMbrGuid
, NULL
},
714 {STRING_TOKEN(STR_DRIVER_CONFIG
), &gEfiDriverConfigurationProtocolGuid
, NULL
},
715 {STRING_TOKEN(STR_DRIVER_CONFIG2
), &gEfiDriverConfiguration2ProtocolGuid
, NULL
},
718 // the ones under this are GUID identified structs, not protocols
720 {STRING_TOKEN(STR_FILE_INFO
), &gEfiFileInfoGuid
, NULL
},
721 {STRING_TOKEN(STR_FILE_SYS_INFO
), &gEfiFileSystemInfoGuid
, NULL
},
724 // the ones under this are misc GUIDS.
726 {STRING_TOKEN(STR_EFI_GLOBAL_VARIABLE
), &gEfiGlobalVariableGuid
, NULL
},
731 {STRING_TOKEN(STR_IP6_SB
), &gEfiIp6ServiceBindingProtocolGuid
, NULL
},
732 {STRING_TOKEN(STR_IP6
), &gEfiIp6ProtocolGuid
, NULL
},
733 {STRING_TOKEN(STR_IP6_CONFIG
), &gEfiIp6ConfigProtocolGuid
, NULL
},
734 {STRING_TOKEN(STR_MTFTP6_SB
), &gEfiMtftp6ServiceBindingProtocolGuid
, NULL
},
735 {STRING_TOKEN(STR_MTFTP6
), &gEfiMtftp6ProtocolGuid
, NULL
},
736 {STRING_TOKEN(STR_DHCP6_SB
), &gEfiDhcp6ServiceBindingProtocolGuid
, NULL
},
737 {STRING_TOKEN(STR_DHCP6
), &gEfiDhcp6ProtocolGuid
, NULL
},
738 {STRING_TOKEN(STR_UDP6_SB
), &gEfiUdp6ServiceBindingProtocolGuid
, NULL
},
739 {STRING_TOKEN(STR_UDP6
), &gEfiUdp6ProtocolGuid
, NULL
},
740 {STRING_TOKEN(STR_TCP6_SB
), &gEfiTcp6ServiceBindingProtocolGuid
, NULL
},
741 {STRING_TOKEN(STR_TCP6
), &gEfiTcp6ProtocolGuid
, NULL
},
742 {STRING_TOKEN(STR_VLAN_CONFIG
), &gEfiVlanConfigProtocolGuid
, NULL
},
743 {STRING_TOKEN(STR_EAP
), &gEfiEapProtocolGuid
, NULL
},
744 {STRING_TOKEN(STR_EAP_MGMT
), &gEfiEapManagementProtocolGuid
, NULL
},
745 {STRING_TOKEN(STR_FTP4_SB
), &gEfiFtp4ServiceBindingProtocolGuid
, NULL
},
746 {STRING_TOKEN(STR_FTP4
), &gEfiFtp4ProtocolGuid
, NULL
},
747 {STRING_TOKEN(STR_IP_SEC_CONFIG
), &gEfiIpSecConfigProtocolGuid
, NULL
},
748 {STRING_TOKEN(STR_DH
), &gEfiDriverHealthProtocolGuid
, NULL
},
749 {STRING_TOKEN(STR_DEF_IMG_LOAD
), &gEfiDeferredImageLoadProtocolGuid
, NULL
},
750 {STRING_TOKEN(STR_USER_CRED
), &gEfiUserCredentialProtocolGuid
, NULL
},
751 {STRING_TOKEN(STR_USER_MNGR
), &gEfiUserManagerProtocolGuid
, NULL
},
752 {STRING_TOKEN(STR_ATA_PASS_THRU
), &gEfiAtaPassThruProtocolGuid
, NULL
},
757 {STRING_TOKEN(STR_FW_MGMT
), &gEfiFirmwareManagementProtocolGuid
, NULL
},
758 {STRING_TOKEN(STR_IP_SEC
), &gEfiIpSecProtocolGuid
, NULL
},
759 {STRING_TOKEN(STR_IP_SEC2
), &gEfiIpSec2ProtocolGuid
, NULL
},
764 {STRING_TOKEN(STR_KMS
), &gEfiKmsProtocolGuid
, NULL
},
765 {STRING_TOKEN(STR_BLK_IO2
), &gEfiBlockIo2ProtocolGuid
, NULL
},
766 {STRING_TOKEN(STR_SSC
), &gEfiStorageSecurityCommandProtocolGuid
, NULL
},
767 {STRING_TOKEN(STR_UCRED2
), &gEfiUserCredential2ProtocolGuid
, NULL
},
772 {STRING_TOKEN(STR_DISK_IO2
), &gEfiDiskIo2ProtocolGuid
, NULL
},
773 {STRING_TOKEN(STR_ADAPTER_INFO
), &gEfiAdapterInformationProtocolGuid
, NULL
},
778 {STRING_TOKEN(STR_IDE_CONT_INIT
), &gEfiIdeControllerInitProtocolGuid
, NULL
},
781 // UEFI Shell Spec 2.0
783 {STRING_TOKEN(STR_SHELL_PARAMETERS
), &gEfiShellParametersProtocolGuid
, NULL
},
784 {STRING_TOKEN(STR_SHELL
), &gEfiShellProtocolGuid
, NULL
},
787 // UEFI Shell Spec 2.1
789 {STRING_TOKEN(STR_SHELL_DYNAMIC
), &gEfiShellDynamicCommandProtocolGuid
, NULL
},
794 {STRING_TOKEN(STR_UNKNOWN_DEVICE
), NULL
, NULL
},
798 Function to get the node for a protocol or struct from it's GUID.
800 if Guid is NULL, then ASSERT.
802 @param[in] Guid The GUID to look for the name of.
806 CONST GUID_INFO_BLOCK
*
808 InternalShellGetNodeFromGuid(
809 IN CONST EFI_GUID
* Guid
812 CONST GUID_INFO_BLOCK
*ListWalker
;
815 ASSERT(Guid
!= NULL
);
817 for (LoopCount
= 0, ListWalker
= GuidList
; GuidList
!= NULL
&& LoopCount
< GuidListCount
; LoopCount
++, ListWalker
++) {
818 if (CompareGuid(ListWalker
->GuidId
, Guid
)) {
823 if (PcdGetBool(PcdShellIncludeNtGuids
)) {
824 for (ListWalker
= mGuidStringListNT
; ListWalker
!= NULL
&& ListWalker
->GuidId
!= NULL
; ListWalker
++) {
825 if (CompareGuid(ListWalker
->GuidId
, Guid
)) {
830 for (ListWalker
= mGuidStringList
; ListWalker
!= NULL
&& ListWalker
->GuidId
!= NULL
; ListWalker
++) {
831 if (CompareGuid(ListWalker
->GuidId
, Guid
)) {
839 Function to add a new GUID/Name mapping.
841 @param[in] Guid The Guid
842 @param[in] NameID The STRING id of the HII string to use
843 @param[in] DumpFunc The pointer to the dump function
846 @retval EFI_SUCCESS The operation was sucessful
847 @retval EFI_OUT_OF_RESOURCES A memory allocation failed
848 @retval EFI_INVALID_PARAMETER Guid NameId was invalid
852 InsertNewGuidNameMapping(
853 IN CONST EFI_GUID
*Guid
,
854 IN CONST EFI_STRING_ID NameID
,
855 IN CONST DUMP_PROTOCOL_INFO DumpFunc OPTIONAL
858 ASSERT(Guid
!= NULL
);
861 GuidList
= ReallocatePool(GuidListCount
* sizeof(GUID_INFO_BLOCK
), GuidListCount
+1 * sizeof(GUID_INFO_BLOCK
), GuidList
);
862 if (GuidList
== NULL
) {
864 return (EFI_OUT_OF_RESOURCES
);
868 GuidList
[GuidListCount
- 1].GuidId
= AllocateCopyPool(sizeof(EFI_GUID
), Guid
);
869 GuidList
[GuidListCount
- 1].StringId
= NameID
;
870 GuidList
[GuidListCount
- 1].DumpInfo
= DumpFunc
;
872 if (GuidList
[GuidListCount
- 1].GuidId
== NULL
) {
873 return (EFI_OUT_OF_RESOURCES
);
876 return (EFI_SUCCESS
);
880 Function to add a new GUID/Name mapping.
882 This cannot overwrite an existing mapping.
884 @param[in] Guid The Guid
885 @param[in] TheName The Guid's name
886 @param[in] Lang RFC4646 language code list or NULL
888 @retval EFI_SUCCESS The operation was sucessful
889 @retval EFI_ACCESS_DENIED There was a duplicate
890 @retval EFI_OUT_OF_RESOURCES A memory allocation failed
891 @retval EFI_INVALID_PARAMETER Guid or TheName was NULL
895 AddNewGuidNameMapping(
896 IN CONST EFI_GUID
*Guid
,
897 IN CONST CHAR16
*TheName
,
898 IN CONST CHAR8
*Lang OPTIONAL
901 EFI_STRING_ID NameID
;
903 HandleParsingHiiInit();
905 if (Guid
== NULL
|| TheName
== NULL
){
906 return (EFI_INVALID_PARAMETER
);
909 if ((InternalShellGetNodeFromGuid(Guid
)) != NULL
) {
910 return (EFI_ACCESS_DENIED
);
913 NameID
= HiiSetString(mHandleParsingHiiHandle
, 0, (CHAR16
*)TheName
, Lang
);
915 return (EFI_OUT_OF_RESOURCES
);
918 return (InsertNewGuidNameMapping(Guid
, NameID
, NULL
));
922 Function to get the name of a protocol or struct from it's GUID.
924 if Guid is NULL, then ASSERT.
926 @param[in] Guid The GUID to look for the name of.
927 @param[in] Lang The language to use.
929 @return pointer to string of the name. The caller
930 is responsible to free this memory.
934 GetStringNameFromGuid(
935 IN CONST EFI_GUID
*Guid
,
936 IN CONST CHAR8
*Lang OPTIONAL
939 CONST GUID_INFO_BLOCK
*Id
;
941 HandleParsingHiiInit();
943 Id
= InternalShellGetNodeFromGuid(Guid
);
944 return (HiiGetString(mHandleParsingHiiHandle
, Id
==NULL
?STRING_TOKEN(STR_UNKNOWN_DEVICE
):Id
->StringId
, Lang
));
948 Function to dump protocol information from a handle.
950 This function will return a allocated string buffer containing the
951 information. The caller is responsible for freeing the memory.
953 If Guid is NULL, ASSERT().
954 If TheHandle is NULL, ASSERT().
956 @param[in] TheHandle The handle to dump information from.
957 @param[in] Guid The GUID of the protocol to dump.
958 @param[in] Verbose TRUE for extra info. FALSE otherwise.
960 @return The pointer to string.
961 @retval NULL An error was encountered.
965 GetProtocolInformationDump(
966 IN CONST EFI_HANDLE TheHandle
,
967 IN CONST EFI_GUID
*Guid
,
968 IN CONST BOOLEAN Verbose
971 CONST GUID_INFO_BLOCK
*Id
;
973 ASSERT(TheHandle
!= NULL
);
974 ASSERT(Guid
!= NULL
);
976 if (TheHandle
== NULL
|| Guid
== NULL
) {
980 Id
= InternalShellGetNodeFromGuid(Guid
);
981 if (Id
!= NULL
&& Id
->DumpInfo
!= NULL
) {
982 return (Id
->DumpInfo(TheHandle
, Verbose
));
988 Function to get the Guid for a protocol or struct based on it's string name.
990 do not modify the returned Guid.
992 @param[in] Name The pointer to the string name.
993 @param[in] Lang The pointer to the language code.
994 @param[out] Guid The pointer to the Guid.
996 @retval EFI_SUCCESS The operation was sucessful.
1000 GetGuidFromStringName(
1001 IN CONST CHAR16
*Name
,
1002 IN CONST CHAR8
*Lang OPTIONAL
,
1006 CONST GUID_INFO_BLOCK
*ListWalker
;
1010 HandleParsingHiiInit();
1012 ASSERT(Guid
!= NULL
);
1014 return (EFI_INVALID_PARAMETER
);
1018 if (PcdGetBool(PcdShellIncludeNtGuids
)) {
1019 for (ListWalker
= mGuidStringListNT
; ListWalker
!= NULL
&& ListWalker
->GuidId
!= NULL
; ListWalker
++) {
1020 String
= HiiGetString(mHandleParsingHiiHandle
, ListWalker
->StringId
, Lang
);
1021 if (Name
!= NULL
&& String
!= NULL
&& StringNoCaseCompare (&Name
, &String
) == 0) {
1022 *Guid
= ListWalker
->GuidId
;
1024 SHELL_FREE_NON_NULL(String
);
1025 if (*Guid
!= NULL
) {
1026 return (EFI_SUCCESS
);
1030 for (ListWalker
= mGuidStringList
; ListWalker
!= NULL
&& ListWalker
->GuidId
!= NULL
; ListWalker
++) {
1031 String
= HiiGetString(mHandleParsingHiiHandle
, ListWalker
->StringId
, Lang
);
1032 if (Name
!= NULL
&& String
!= NULL
&& StringNoCaseCompare (&Name
, &String
) == 0) {
1033 *Guid
= ListWalker
->GuidId
;
1035 SHELL_FREE_NON_NULL(String
);
1036 if (*Guid
!= NULL
) {
1037 return (EFI_SUCCESS
);
1041 for (LoopCount
= 0, ListWalker
= GuidList
; GuidList
!= NULL
&& LoopCount
< GuidListCount
; LoopCount
++, ListWalker
++) {
1042 String
= HiiGetString(mHandleParsingHiiHandle
, ListWalker
->StringId
, Lang
);
1043 if (Name
!= NULL
&& String
!= NULL
&& StringNoCaseCompare (&Name
, &String
) == 0) {
1044 *Guid
= ListWalker
->GuidId
;
1046 SHELL_FREE_NON_NULL(String
);
1047 if (*Guid
!= NULL
) {
1048 return (EFI_SUCCESS
);
1052 return (EFI_NOT_FOUND
);
1056 Get best support language for this driver.
1058 First base on the user input language to search, second base on the current
1059 platform used language to search, third get the first language from the
1060 support language list. The caller need to free the buffer of the best language.
1062 @param[in] SupportedLanguages The support languages for this driver.
1063 @param[in] InputLanguage The user input language.
1064 @param[in] Iso639Language Whether get language for ISO639.
1066 @return The best support language for this driver.
1070 GetBestLanguageForDriver (
1071 IN CONST CHAR8
*SupportedLanguages
,
1072 IN CONST CHAR8
*InputLanguage
,
1073 IN BOOLEAN Iso639Language
1076 CHAR8
*LanguageVariable
;
1077 CHAR8
*BestLanguage
;
1079 LanguageVariable
= GetVariable (Iso639Language
? L
"Lang" : L
"PlatformLang", &gEfiGlobalVariableGuid
);
1081 BestLanguage
= GetBestLanguage(
1084 (InputLanguage
!= NULL
) ? InputLanguage
: "",
1085 (LanguageVariable
!= NULL
) ? LanguageVariable
: "",
1090 if (LanguageVariable
!= NULL
) {
1091 FreePool (LanguageVariable
);
1094 return BestLanguage
;
1098 Function to retrieve the driver name (if possible) from the ComponentName or
1099 ComponentName2 protocol
1101 @param[in] TheHandle The driver handle to get the name of.
1102 @param[in] Language The language to use.
1104 @retval NULL The name could not be found.
1105 @return A pointer to the string name. Do not de-allocate the memory.
1109 GetStringNameFromHandle(
1110 IN CONST EFI_HANDLE TheHandle
,
1111 IN CONST CHAR8
*Language
1114 EFI_COMPONENT_NAME2_PROTOCOL
*CompNameStruct
;
1121 Status
= gBS
->OpenProtocol(
1123 &gEfiComponentName2ProtocolGuid
,
1124 (VOID
**)&CompNameStruct
,
1127 EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
1128 if (!EFI_ERROR(Status
)) {
1129 BestLang
= GetBestLanguageForDriver (CompNameStruct
->SupportedLanguages
, Language
, FALSE
);
1130 Status
= CompNameStruct
->GetDriverName(CompNameStruct
, BestLang
, &RetVal
);
1131 if (BestLang
!= NULL
) {
1132 FreePool (BestLang
);
1135 if (!EFI_ERROR(Status
)) {
1139 Status
= gBS
->OpenProtocol(
1141 &gEfiComponentNameProtocolGuid
,
1142 (VOID
**)&CompNameStruct
,
1145 EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
1146 if (!EFI_ERROR(Status
)) {
1147 BestLang
= GetBestLanguageForDriver (CompNameStruct
->SupportedLanguages
, Language
, FALSE
);
1148 Status
= CompNameStruct
->GetDriverName(CompNameStruct
, BestLang
, &RetVal
);
1149 if (BestLang
!= NULL
) {
1150 FreePool (BestLang
);
1152 if (!EFI_ERROR(Status
)) {
1160 Function to initialize the file global mHandleList object for use in
1161 vonverting handles to index and index to handle.
1163 @retval EFI_SUCCESS The operation was successful.
1167 InternalShellInitHandleList(
1172 EFI_HANDLE
*HandleBuffer
;
1174 HANDLE_LIST
*ListWalker
;
1176 if (mHandleList
.NextIndex
!= 0) {
1179 InitializeListHead(&mHandleList
.List
.Link
);
1180 mHandleList
.NextIndex
= 1;
1181 Status
= gBS
->LocateHandleBuffer (
1188 ASSERT_EFI_ERROR(Status
);
1189 if (EFI_ERROR(Status
)) {
1192 for (mHandleList
.NextIndex
= 1 ; mHandleList
.NextIndex
<= HandleCount
; mHandleList
.NextIndex
++){
1193 ListWalker
= AllocateZeroPool(sizeof(HANDLE_LIST
));
1194 ASSERT(ListWalker
!= NULL
);
1195 ListWalker
->TheHandle
= HandleBuffer
[mHandleList
.NextIndex
-1];
1196 ListWalker
->TheIndex
= mHandleList
.NextIndex
;
1197 InsertTailList(&mHandleList
.List
.Link
,&ListWalker
->Link
);
1199 FreePool(HandleBuffer
);
1200 return (EFI_SUCCESS
);
1204 Function to retrieve the human-friendly index of a given handle. If the handle
1205 does not have a index one will be automatically assigned. The index value is valid
1206 until the termination of the shell application.
1208 @param[in] TheHandle The handle to retrieve an index for.
1210 @retval 0 A memory allocation failed.
1211 @return The index of the handle.
1216 ConvertHandleToHandleIndex(
1217 IN CONST EFI_HANDLE TheHandle
1221 EFI_GUID
**ProtocolBuffer
;
1222 UINTN ProtocolCount
;
1223 HANDLE_LIST
*ListWalker
;
1225 if (TheHandle
== NULL
) {
1229 InternalShellInitHandleList();
1231 for (ListWalker
= (HANDLE_LIST
*)GetFirstNode(&mHandleList
.List
.Link
)
1232 ; !IsNull(&mHandleList
.List
.Link
,&ListWalker
->Link
)
1233 ; ListWalker
= (HANDLE_LIST
*)GetNextNode(&mHandleList
.List
.Link
,&ListWalker
->Link
)
1235 if (ListWalker
->TheHandle
== TheHandle
) {
1237 // Verify that TheHandle is still present in the Handle Database
1239 Status
= gBS
->ProtocolsPerHandle(TheHandle
, &ProtocolBuffer
, &ProtocolCount
);
1240 if (EFI_ERROR (Status
)) {
1242 // TheHandle is not present in the Handle Database, so delete from the handle list
1244 RemoveEntryList (&ListWalker
->Link
);
1247 FreePool (ProtocolBuffer
);
1248 return (ListWalker
->TheIndex
);
1253 // Verify that TheHandle is valid handle
1255 Status
= gBS
->ProtocolsPerHandle(TheHandle
, &ProtocolBuffer
, &ProtocolCount
);
1256 if (EFI_ERROR (Status
)) {
1258 // TheHandle is not valid, so do not add to handle list
1262 FreePool (ProtocolBuffer
);
1264 ListWalker
= AllocateZeroPool(sizeof(HANDLE_LIST
));
1265 ASSERT(ListWalker
!= NULL
);
1266 ListWalker
->TheHandle
= TheHandle
;
1267 ListWalker
->TheIndex
= mHandleList
.NextIndex
++;
1268 InsertTailList(&mHandleList
.List
.Link
,&ListWalker
->Link
);
1269 return (ListWalker
->TheIndex
);
1275 Function to retrieve the EFI_HANDLE from the human-friendly index.
1277 @param[in] TheIndex The index to retrieve the EFI_HANDLE for.
1279 @retval NULL The index was invalid.
1280 @return The EFI_HANDLE that index represents.
1285 ConvertHandleIndexToHandle(
1286 IN CONST UINTN TheIndex
1290 EFI_GUID
**ProtocolBuffer
;
1291 UINTN ProtocolCount
;
1292 HANDLE_LIST
*ListWalker
;
1294 InternalShellInitHandleList();
1296 if (TheIndex
>= mHandleList
.NextIndex
) {
1300 for (ListWalker
= (HANDLE_LIST
*)GetFirstNode(&mHandleList
.List
.Link
)
1301 ; !IsNull(&mHandleList
.List
.Link
,&ListWalker
->Link
)
1302 ; ListWalker
= (HANDLE_LIST
*)GetNextNode(&mHandleList
.List
.Link
,&ListWalker
->Link
)
1304 if (ListWalker
->TheIndex
== TheIndex
&& ListWalker
->TheHandle
!= NULL
) {
1306 // Verify that LinkWalker->TheHandle is valid handle
1308 Status
= gBS
->ProtocolsPerHandle(ListWalker
->TheHandle
, &ProtocolBuffer
, &ProtocolCount
);
1309 if (EFI_ERROR (Status
)) {
1311 // TheHandle is not valid, so do not add to handle list
1313 ListWalker
->TheHandle
= NULL
;
1315 return (ListWalker
->TheHandle
);
1322 Gets all the related EFI_HANDLEs based on the mask supplied.
1324 This function scans all EFI_HANDLES in the UEFI environment's handle database
1325 and returns the ones with the specified relationship (Mask) to the specified
1328 If both DriverBindingHandle and ControllerHandle are NULL, then ASSERT.
1329 If MatchingHandleCount is NULL, then ASSERT.
1331 If MatchingHandleBuffer is not NULL upon a successful return the memory must be
1334 @param[in] DriverBindingHandle The handle with Driver Binding protocol on it.
1335 @param[in] ControllerHandle The handle with Device Path protocol on it.
1336 @param[in] MatchingHandleCount The pointer to UINTN that specifies the number of HANDLES in
1337 MatchingHandleBuffer.
1338 @param[out] MatchingHandleBuffer On a successful return, a buffer of MatchingHandleCount
1339 EFI_HANDLEs with a terminating NULL EFI_HANDLE.
1340 @param[out] HandleType An array of type information.
1342 @retval EFI_SUCCESS The operation was successful, and any related handles
1343 are in MatchingHandleBuffer.
1344 @retval EFI_NOT_FOUND No matching handles were found.
1345 @retval EFI_INVALID_PARAMETER A parameter was invalid or out of range.
1349 ParseHandleDatabaseByRelationshipWithType (
1350 IN CONST EFI_HANDLE DriverBindingHandle OPTIONAL
,
1351 IN CONST EFI_HANDLE ControllerHandle OPTIONAL
,
1352 IN UINTN
*HandleCount
,
1353 OUT EFI_HANDLE
**HandleBuffer
,
1354 OUT UINTN
**HandleType
1359 EFI_GUID
**ProtocolGuidArray
;
1361 UINTN ProtocolIndex
;
1362 EFI_OPEN_PROTOCOL_INFORMATION_ENTRY
*OpenInfo
;
1363 UINTN OpenInfoCount
;
1364 UINTN OpenInfoIndex
;
1366 INTN DriverBindingHandleIndex
;
1368 ASSERT(HandleCount
!= NULL
);
1369 ASSERT(HandleBuffer
!= NULL
);
1370 ASSERT(HandleType
!= NULL
);
1371 ASSERT(DriverBindingHandle
!= NULL
|| ControllerHandle
!= NULL
);
1374 *HandleBuffer
= NULL
;
1378 // Retrieve the list of all handles from the handle database
1380 Status
= gBS
->LocateHandleBuffer (
1387 if (EFI_ERROR (Status
)) {
1391 *HandleType
= AllocateZeroPool (*HandleCount
* sizeof (UINTN
));
1392 ASSERT(*HandleType
!= NULL
);
1394 DriverBindingHandleIndex
= -1;
1395 for (HandleIndex
= 0; HandleIndex
< *HandleCount
; HandleIndex
++) {
1396 if (DriverBindingHandle
!= NULL
&& (*HandleBuffer
)[HandleIndex
] == DriverBindingHandle
) {
1397 DriverBindingHandleIndex
= (INTN
)HandleIndex
;
1401 for (HandleIndex
= 0; HandleIndex
< *HandleCount
; HandleIndex
++) {
1403 // Retrieve the list of all the protocols on each handle
1405 Status
= gBS
->ProtocolsPerHandle (
1406 (*HandleBuffer
)[HandleIndex
],
1410 if (EFI_ERROR (Status
)) {
1414 for (ProtocolIndex
= 0; ProtocolIndex
< ArrayCount
; ProtocolIndex
++) {
1417 // Set the bit describing what this handle has
1419 if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiLoadedImageProtocolGuid
) ) {
1420 (*HandleType
)[HandleIndex
] |= (UINTN
)HR_IMAGE_HANDLE
;
1421 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiDriverBindingProtocolGuid
) ) {
1422 (*HandleType
)[HandleIndex
] |= (UINTN
)HR_DRIVER_BINDING_HANDLE
;
1423 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiDriverConfiguration2ProtocolGuid
)) {
1424 (*HandleType
)[HandleIndex
] |= (UINTN
)HR_DRIVER_CONFIGURATION_HANDLE
;
1425 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiDriverConfigurationProtocolGuid
) ) {
1426 (*HandleType
)[HandleIndex
] |= (UINTN
)HR_DRIVER_CONFIGURATION_HANDLE
;
1427 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiDriverDiagnostics2ProtocolGuid
) ) {
1428 (*HandleType
)[HandleIndex
] |= (UINTN
)HR_DRIVER_DIAGNOSTICS_HANDLE
;
1429 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiDriverDiagnosticsProtocolGuid
) ) {
1430 (*HandleType
)[HandleIndex
] |= (UINTN
)HR_DRIVER_DIAGNOSTICS_HANDLE
;
1431 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiComponentName2ProtocolGuid
) ) {
1432 (*HandleType
)[HandleIndex
] |= (UINTN
)HR_COMPONENT_NAME_HANDLE
;
1433 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiComponentNameProtocolGuid
) ) {
1434 (*HandleType
)[HandleIndex
] |= (UINTN
)HR_COMPONENT_NAME_HANDLE
;
1435 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiDevicePathProtocolGuid
) ) {
1436 (*HandleType
)[HandleIndex
] |= (UINTN
)HR_DEVICE_HANDLE
;
1439 ASSERT((*HandleType
)[HandleIndex
] == (*HandleType
)[HandleIndex
]);
1443 // Retrieve the list of agents that have opened each protocol
1445 Status
= gBS
->OpenProtocolInformation (
1446 (*HandleBuffer
)[HandleIndex
],
1447 ProtocolGuidArray
[ProtocolIndex
],
1451 if (EFI_ERROR (Status
)) {
1455 if (ControllerHandle
== NULL
) {
1457 // ControllerHandle == NULL and DriverBindingHandle != NULL.
1458 // Return information on all the controller handles that the driver specified by DriverBindingHandle is managing
1460 for (OpenInfoIndex
= 0; OpenInfoIndex
< OpenInfoCount
; OpenInfoIndex
++) {
1461 if (OpenInfo
[OpenInfoIndex
].AgentHandle
== DriverBindingHandle
&& (OpenInfo
[OpenInfoIndex
].Attributes
& EFI_OPEN_PROTOCOL_BY_DRIVER
) != 0) {
1462 (*HandleType
)[HandleIndex
] |= (UINTN
)(HR_DEVICE_HANDLE
| HR_CONTROLLER_HANDLE
);
1463 if (DriverBindingHandleIndex
!= -1) {
1464 (*HandleType
)[DriverBindingHandleIndex
] |= (UINTN
)HR_DEVICE_DRIVER
;
1467 if (OpenInfo
[OpenInfoIndex
].AgentHandle
== DriverBindingHandle
&& (OpenInfo
[OpenInfoIndex
].Attributes
& EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
) != 0) {
1468 (*HandleType
)[HandleIndex
] |= (UINTN
)(HR_DEVICE_HANDLE
| HR_CONTROLLER_HANDLE
);
1469 if (DriverBindingHandleIndex
!= -1) {
1470 (*HandleType
)[DriverBindingHandleIndex
] |= (UINTN
)(HR_BUS_DRIVER
| HR_DEVICE_DRIVER
);
1472 for (ChildIndex
= 0; ChildIndex
< *HandleCount
; ChildIndex
++) {
1473 if (OpenInfo
[OpenInfoIndex
].ControllerHandle
== (*HandleBuffer
)[ChildIndex
]) {
1474 (*HandleType
)[ChildIndex
] |= (UINTN
)(HR_DEVICE_HANDLE
| HR_CHILD_HANDLE
);
1480 if (DriverBindingHandle
== NULL
&& ControllerHandle
!= NULL
) {
1481 if (ControllerHandle
== (*HandleBuffer
)[HandleIndex
]) {
1482 (*HandleType
)[HandleIndex
] |= (UINTN
)(HR_DEVICE_HANDLE
| HR_CONTROLLER_HANDLE
);
1483 for (OpenInfoIndex
= 0; OpenInfoIndex
< OpenInfoCount
; OpenInfoIndex
++) {
1484 if ((OpenInfo
[OpenInfoIndex
].Attributes
& EFI_OPEN_PROTOCOL_BY_DRIVER
) != 0) {
1485 for (ChildIndex
= 0; ChildIndex
< *HandleCount
; ChildIndex
++) {
1486 if (OpenInfo
[OpenInfoIndex
].AgentHandle
== (*HandleBuffer
)[ChildIndex
]) {
1487 (*HandleType
)[ChildIndex
] |= (UINTN
)HR_DEVICE_DRIVER
;
1491 if ((OpenInfo
[OpenInfoIndex
].Attributes
& EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
) != 0) {
1492 for (ChildIndex
= 0; ChildIndex
< *HandleCount
; ChildIndex
++) {
1493 if (OpenInfo
[OpenInfoIndex
].AgentHandle
== (*HandleBuffer
)[ChildIndex
]) {
1494 (*HandleType
)[ChildIndex
] |= (UINTN
)(HR_BUS_DRIVER
| HR_DEVICE_DRIVER
);
1496 if (OpenInfo
[OpenInfoIndex
].ControllerHandle
== (*HandleBuffer
)[ChildIndex
]) {
1497 (*HandleType
)[ChildIndex
] |= (UINTN
)(HR_DEVICE_HANDLE
| HR_CHILD_HANDLE
);
1503 for (OpenInfoIndex
= 0; OpenInfoIndex
< OpenInfoCount
; OpenInfoIndex
++) {
1504 if ((OpenInfo
[OpenInfoIndex
].Attributes
& EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
) != 0) {
1505 if (OpenInfo
[OpenInfoIndex
].ControllerHandle
== ControllerHandle
) {
1506 (*HandleType
)[HandleIndex
] |= (UINTN
)(HR_DEVICE_HANDLE
| HR_PARENT_HANDLE
);
1512 if (DriverBindingHandle
!= NULL
&& ControllerHandle
!= NULL
) {
1513 if (ControllerHandle
== (*HandleBuffer
)[HandleIndex
]) {
1514 (*HandleType
)[HandleIndex
] |= (UINTN
)(HR_DEVICE_HANDLE
| HR_CONTROLLER_HANDLE
);
1515 for (OpenInfoIndex
= 0; OpenInfoIndex
< OpenInfoCount
; OpenInfoIndex
++) {
1516 if ((OpenInfo
[OpenInfoIndex
].Attributes
& EFI_OPEN_PROTOCOL_BY_DRIVER
) != 0) {
1517 if (OpenInfo
[OpenInfoIndex
].AgentHandle
== DriverBindingHandle
) {
1518 if (DriverBindingHandleIndex
!= -1) {
1519 (*HandleType
)[DriverBindingHandleIndex
] |= (UINTN
)HR_DEVICE_DRIVER
;
1523 if ((OpenInfo
[OpenInfoIndex
].Attributes
& EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
) != 0) {
1524 if (OpenInfo
[OpenInfoIndex
].AgentHandle
== DriverBindingHandle
) {
1525 for (ChildIndex
= 0; ChildIndex
< *HandleCount
; ChildIndex
++) {
1526 if (OpenInfo
[OpenInfoIndex
].ControllerHandle
== (*HandleBuffer
)[ChildIndex
]) {
1527 (*HandleType
)[ChildIndex
] |= (UINTN
)(HR_DEVICE_HANDLE
| HR_CHILD_HANDLE
);
1532 for (ChildIndex
= 0; ChildIndex
< *HandleCount
; ChildIndex
++) {
1533 if (OpenInfo
[OpenInfoIndex
].AgentHandle
== (*HandleBuffer
)[ChildIndex
]) {
1534 (*HandleType
)[ChildIndex
] |= (UINTN
)(HR_BUS_DRIVER
| HR_DEVICE_DRIVER
);
1540 for (OpenInfoIndex
= 0; OpenInfoIndex
< OpenInfoCount
; OpenInfoIndex
++) {
1541 if ((OpenInfo
[OpenInfoIndex
].Attributes
& EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
) != 0) {
1542 if (OpenInfo
[OpenInfoIndex
].ControllerHandle
== ControllerHandle
) {
1543 (*HandleType
)[HandleIndex
] |= (UINTN
)(HR_DEVICE_HANDLE
| HR_PARENT_HANDLE
);
1549 FreePool (OpenInfo
);
1551 FreePool (ProtocolGuidArray
);
1557 Gets all the related EFI_HANDLEs based on the single EFI_HANDLE and the mask
1560 This function will scan all EFI_HANDLES in the UEFI environment's handle database
1561 and return all the ones with the specified relationship (Mask) to the specified
1564 If both DriverBindingHandle and ControllerHandle are NULL, then ASSERT.
1565 If MatchingHandleCount is NULL, then ASSERT.
1567 If MatchingHandleBuffer is not NULL upon a sucessful return the memory must be
1570 @param[in] DriverBindingHandle Handle to a object with Driver Binding protocol
1572 @param[in] ControllerHandle Handle to a device with Device Path protocol on it.
1573 @param[in] Mask Mask of what relationship(s) is desired.
1574 @param[in] MatchingHandleCount Poitner to UINTN specifying number of HANDLES in
1575 MatchingHandleBuffer.
1576 @param[out] MatchingHandleBuffer On a sucessful return a buffer of MatchingHandleCount
1577 EFI_HANDLEs and a terminating NULL EFI_HANDLE.
1579 @retval EFI_SUCCESS The operation was sucessful and any related handles
1580 are in MatchingHandleBuffer;
1581 @retval EFI_NOT_FOUND No matching handles were found.
1582 @retval EFI_INVALID_PARAMETER A parameter was invalid or out of range.
1586 ParseHandleDatabaseByRelationship (
1587 IN CONST EFI_HANDLE DriverBindingHandle OPTIONAL
,
1588 IN CONST EFI_HANDLE ControllerHandle OPTIONAL
,
1589 IN CONST UINTN Mask
,
1590 IN UINTN
*MatchingHandleCount
,
1591 OUT EFI_HANDLE
**MatchingHandleBuffer OPTIONAL
1596 EFI_HANDLE
*HandleBuffer
;
1600 ASSERT(MatchingHandleCount
!= NULL
);
1601 ASSERT(DriverBindingHandle
!= NULL
|| ControllerHandle
!= NULL
);
1603 if ((Mask
& HR_VALID_MASK
) != Mask
) {
1604 return (EFI_INVALID_PARAMETER
);
1607 if ((Mask
& HR_CHILD_HANDLE
) != 0 && DriverBindingHandle
== NULL
) {
1608 return (EFI_INVALID_PARAMETER
);
1611 *MatchingHandleCount
= 0;
1612 if (MatchingHandleBuffer
!= NULL
) {
1613 *MatchingHandleBuffer
= NULL
;
1616 HandleBuffer
= NULL
;
1619 Status
= ParseHandleDatabaseByRelationshipWithType (
1620 DriverBindingHandle
,
1626 if (!EFI_ERROR (Status
)) {
1628 // Count the number of handles that match the attributes in Mask
1630 for (HandleIndex
= 0; HandleIndex
< HandleCount
; HandleIndex
++) {
1631 if ((HandleType
[HandleIndex
] & Mask
) == Mask
) {
1632 (*MatchingHandleCount
)++;
1636 // If no handles match the attributes in Mask then return EFI_NOT_FOUND
1638 if (*MatchingHandleCount
== 0) {
1639 Status
= EFI_NOT_FOUND
;
1642 if (MatchingHandleBuffer
== NULL
) {
1644 // Someone just wanted the count...
1646 Status
= EFI_SUCCESS
;
1649 // Allocate a handle buffer for the number of handles that matched the attributes in Mask
1651 *MatchingHandleBuffer
= AllocateZeroPool ((*MatchingHandleCount
+1)* sizeof (EFI_HANDLE
));
1652 ASSERT(*MatchingHandleBuffer
!= NULL
);
1654 for (HandleIndex
= 0,*MatchingHandleCount
= 0
1655 ; HandleIndex
< HandleCount
1659 // Fill the allocated buffer with the handles that matched the attributes in Mask
1661 if ((HandleType
[HandleIndex
] & Mask
) == Mask
) {
1662 (*MatchingHandleBuffer
)[(*MatchingHandleCount
)++] = HandleBuffer
[HandleIndex
];
1667 // Make the last one NULL
1669 (*MatchingHandleBuffer
)[*MatchingHandleCount
] = NULL
;
1671 Status
= EFI_SUCCESS
;
1672 } // MacthingHandleBuffer == NULL (ELSE)
1673 } // *MatchingHandleCount == 0 (ELSE)
1674 } // no error on ParseHandleDatabaseByRelationshipWithType
1676 if (HandleBuffer
!= NULL
) {
1677 FreePool (HandleBuffer
);
1680 if (HandleType
!= NULL
) {
1681 FreePool (HandleType
);
1688 Gets handles for any child controllers of the passed in controller.
1690 @param[in] ControllerHandle The handle of the "parent controller"
1691 @param[in] MatchingHandleCount Pointer to the number of handles in
1692 MatchingHandleBuffer on return.
1693 @param[out] MatchingHandleBuffer Buffer containing handles on a successful
1697 @retval EFI_SUCCESS The operation was sucessful.
1701 ParseHandleDatabaseForChildControllers(
1702 IN CONST EFI_HANDLE ControllerHandle
,
1703 IN UINTN
*MatchingHandleCount
,
1704 OUT EFI_HANDLE
**MatchingHandleBuffer OPTIONAL
1709 UINTN DriverBindingHandleCount
;
1710 EFI_HANDLE
*DriverBindingHandleBuffer
;
1711 UINTN DriverBindingHandleIndex
;
1712 UINTN ChildControllerHandleCount
;
1713 EFI_HANDLE
*ChildControllerHandleBuffer
;
1714 UINTN ChildControllerHandleIndex
;
1715 EFI_HANDLE
*HandleBufferForReturn
;
1717 if (MatchingHandleCount
== NULL
) {
1718 return (EFI_INVALID_PARAMETER
);
1720 *MatchingHandleCount
= 0;
1722 Status
= PARSE_HANDLE_DATABASE_UEFI_DRIVERS (
1724 &DriverBindingHandleCount
,
1725 &DriverBindingHandleBuffer
1727 if (EFI_ERROR (Status
)) {
1732 // Get a buffer big enough for all the controllers.
1734 HandleBufferForReturn
= GetHandleListByProtocol(NULL
);
1735 if (HandleBufferForReturn
== NULL
) {
1736 FreePool (DriverBindingHandleBuffer
);
1737 return (EFI_NOT_FOUND
);
1740 for (DriverBindingHandleIndex
= 0; DriverBindingHandleIndex
< DriverBindingHandleCount
; DriverBindingHandleIndex
++) {
1741 Status
= PARSE_HANDLE_DATABASE_MANAGED_CHILDREN (
1742 DriverBindingHandleBuffer
[DriverBindingHandleIndex
],
1744 &ChildControllerHandleCount
,
1745 &ChildControllerHandleBuffer
1747 if (EFI_ERROR (Status
)) {
1751 for (ChildControllerHandleIndex
= 0;
1752 ChildControllerHandleIndex
< ChildControllerHandleCount
;
1753 ChildControllerHandleIndex
++
1755 for (HandleIndex
= 0; HandleIndex
< *MatchingHandleCount
; HandleIndex
++) {
1756 if (HandleBufferForReturn
[HandleIndex
] == ChildControllerHandleBuffer
[ChildControllerHandleIndex
]) {
1760 if (HandleIndex
>= *MatchingHandleCount
) {
1761 HandleBufferForReturn
[(*MatchingHandleCount
)++] = ChildControllerHandleBuffer
[ChildControllerHandleIndex
];
1765 FreePool (ChildControllerHandleBuffer
);
1768 FreePool (DriverBindingHandleBuffer
);
1770 if (MatchingHandleBuffer
!= NULL
) {
1771 *MatchingHandleBuffer
= HandleBufferForReturn
;
1773 FreePool(HandleBufferForReturn
);
1776 return (EFI_SUCCESS
);
1780 Appends 1 buffer to another buffer. This will re-allocate the destination buffer
1781 if necessary to fit all of the data.
1783 If DestinationBuffer is NULL, then ASSERT().
1785 @param[in, out] DestinationBuffer The pointer to the pointer to the buffer to append onto.
1786 @param[in, out] DestinationSize The pointer to the size of DestinationBuffer.
1787 @param[in] SourceBuffer The pointer to the buffer to append onto DestinationBuffer.
1788 @param[in] SourceSize The number of bytes of SourceBuffer to append.
1790 @retval NULL A memory allocation failed.
1791 @retval NULL A parameter was invalid.
1792 @return A pointer to (*DestinationBuffer).
1797 IN OUT VOID
**DestinationBuffer
,
1798 IN OUT UINTN
*DestinationSize
,
1799 IN VOID
*SourceBuffer
,
1803 UINTN LocalDestinationSize
;
1804 UINTN LocalDestinationFinalSize
;
1806 ASSERT(DestinationBuffer
!= NULL
);
1808 if (SourceSize
== 0 || SourceBuffer
== NULL
) {
1809 return (*DestinationBuffer
);
1812 if (DestinationSize
== NULL
) {
1813 LocalDestinationSize
= 0;
1815 LocalDestinationSize
= *DestinationSize
;
1818 LocalDestinationFinalSize
= LocalDestinationSize
+ SourceSize
;
1820 if (DestinationSize
!= NULL
) {
1821 *DestinationSize
= LocalDestinationSize
;
1824 if (LocalDestinationSize
== 0) {
1826 *DestinationBuffer
= AllocateZeroPool(LocalDestinationFinalSize
);
1829 *DestinationBuffer
= ReallocatePool(LocalDestinationSize
, LocalDestinationFinalSize
, *DestinationBuffer
);
1832 ASSERT(*DestinationBuffer
!= NULL
);
1835 return (CopyMem(((UINT8
*)(*DestinationBuffer
)) + LocalDestinationSize
, SourceBuffer
, SourceSize
));
1839 Gets handles for any child devices produced by the passed in driver.
1841 @param[in] DriverHandle The handle of the driver.
1842 @param[in] MatchingHandleCount Pointer to the number of handles in
1843 MatchingHandleBuffer on return.
1844 @param[out] MatchingHandleBuffer Buffer containing handles on a successful
1846 @retval EFI_SUCCESS The operation was sucessful.
1847 @sa ParseHandleDatabaseByRelationship
1851 ParseHandleDatabaseForChildDevices(
1852 IN CONST EFI_HANDLE DriverHandle
,
1853 IN UINTN
*MatchingHandleCount
,
1854 OUT EFI_HANDLE
**MatchingHandleBuffer OPTIONAL
1858 EFI_HANDLE
*Buffer2
;
1863 UINTN HandleBufferSize
;
1865 ASSERT(MatchingHandleCount
!= NULL
);
1867 HandleBufferSize
= 0;
1870 *MatchingHandleCount
= 0;
1872 Status
= PARSE_HANDLE_DATABASE_DEVICES (
1877 if (!EFI_ERROR (Status
)) {
1878 for (HandleIndex
= 0; HandleIndex
< Count1
; HandleIndex
++) {
1880 // now find the children
1882 Status
= PARSE_HANDLE_DATABASE_MANAGED_CHILDREN (
1884 Buffer
[HandleIndex
],
1888 if (EFI_ERROR(Status
)) {
1892 // save out required and optional data elements
1894 *MatchingHandleCount
+= Count2
;
1895 if (MatchingHandleBuffer
!= NULL
) {
1896 *MatchingHandleBuffer
= BuffernCatGrow((VOID
**)MatchingHandleBuffer
, &HandleBufferSize
, Buffer2
, Count2
* sizeof(Buffer2
[0]));
1902 if (Buffer2
!= NULL
) {
1908 if (Buffer
!= NULL
) {
1915 Function to get all handles that support a given protocol or all handles.
1917 @param[in] ProtocolGuid The guid of the protocol to get handles for. If NULL
1918 then the function will return all handles.
1920 @retval NULL A memory allocation failed.
1921 @return A NULL terminated list of handles.
1925 GetHandleListByProtocol (
1926 IN CONST EFI_GUID
*ProtocolGuid OPTIONAL
1929 EFI_HANDLE
*HandleList
;
1937 // We cannot use LocateHandleBuffer since we need that NULL item on the ends of the list!
1939 if (ProtocolGuid
== NULL
) {
1940 Status
= gBS
->LocateHandle(AllHandles
, NULL
, NULL
, &Size
, HandleList
);
1941 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1942 HandleList
= AllocateZeroPool(Size
+ sizeof(EFI_HANDLE
));
1943 if (HandleList
== NULL
) {
1946 Status
= gBS
->LocateHandle(AllHandles
, NULL
, NULL
, &Size
, HandleList
);
1947 HandleList
[Size
/sizeof(EFI_HANDLE
)] = NULL
;
1950 Status
= gBS
->LocateHandle(ByProtocol
, (EFI_GUID
*)ProtocolGuid
, NULL
, &Size
, HandleList
);
1951 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1952 HandleList
= AllocateZeroPool(Size
+ sizeof(EFI_HANDLE
));
1953 if (HandleList
== NULL
) {
1956 Status
= gBS
->LocateHandle(ByProtocol
, (EFI_GUID
*)ProtocolGuid
, NULL
, &Size
, HandleList
);
1957 HandleList
[Size
/sizeof(EFI_HANDLE
)] = NULL
;
1960 if (EFI_ERROR(Status
)) {
1961 if (HandleList
!= NULL
) {
1962 FreePool(HandleList
);
1966 return (HandleList
);
1970 Function to get all handles that support some protocols.
1972 @param[in] ProtocolGuids A NULL terminated list of protocol GUIDs.
1974 @retval NULL A memory allocation failed.
1975 @retval NULL ProtocolGuids was NULL.
1976 @return A NULL terminated list of EFI_HANDLEs.
1980 GetHandleListByProtocolList (
1981 IN CONST EFI_GUID
**ProtocolGuids
1984 EFI_HANDLE
*HandleList
;
1989 CONST EFI_GUID
**GuidWalker
;
1990 EFI_HANDLE
*HandleWalker1
;
1991 EFI_HANDLE
*HandleWalker2
;
1995 TotalSize
= sizeof(EFI_HANDLE
);
1997 for (GuidWalker
= ProtocolGuids
; GuidWalker
!= NULL
&& *GuidWalker
!= NULL
; GuidWalker
++,Size
= 0){
1998 Status
= gBS
->LocateHandle(ByProtocol
, (EFI_GUID
*)(*GuidWalker
), NULL
, &Size
, NULL
);
1999 if (Status
== EFI_BUFFER_TOO_SMALL
) {
2005 // No handles were found...
2007 if (TotalSize
== sizeof(EFI_HANDLE
)) {
2011 HandleList
= AllocateZeroPool(TotalSize
);
2012 if (HandleList
== NULL
) {
2017 for (GuidWalker
= ProtocolGuids
; GuidWalker
!= NULL
&& *GuidWalker
!= NULL
; GuidWalker
++){
2018 TempSize
= TotalSize
- Size
;
2019 Status
= gBS
->LocateHandle(ByProtocol
, (EFI_GUID
*)(*GuidWalker
), NULL
, &TempSize
, HandleList
+(Size
/sizeof(EFI_HANDLE
)));
2022 // Allow for missing protocols... Only update the 'used' size upon success.
2024 if (!EFI_ERROR(Status
)) {
2028 ASSERT(HandleList
[(TotalSize
/sizeof(EFI_HANDLE
))-1] == NULL
);
2030 for (HandleWalker1
= HandleList
; HandleWalker1
!= NULL
&& *HandleWalker1
!= NULL
; HandleWalker1
++) {
2031 for (HandleWalker2
= HandleWalker1
+ 1; HandleWalker2
!= NULL
&& *HandleWalker2
!= NULL
; HandleWalker2
++) {
2032 if (*HandleWalker1
== *HandleWalker2
) {
2034 // copy memory back 1 handle width.
2036 CopyMem(HandleWalker2
, HandleWalker2
+ 1, TotalSize
- ((HandleWalker2
-HandleList
+1)*sizeof(EFI_HANDLE
)));
2041 return (HandleList
);