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
;
20 HANDLE_INDEX_LIST mHandleList
= {{{NULL
,NULL
},0,0},0};
23 Function to translate the EFI_MEMORY_TYPE into a string.
25 @param[in] Memory The memory type.
27 @retval A string representation of the type allocated from BS Pool.
32 IN CONST EFI_MEMORY_TYPE Memory
39 case EfiReservedMemoryType
: StrnCatGrow(&RetVal
, NULL
, L
"EfiReservedMemoryType", 0); break;
40 case EfiLoaderCode
: StrnCatGrow(&RetVal
, NULL
, L
"EfiLoaderCode", 0); break;
41 case EfiLoaderData
: StrnCatGrow(&RetVal
, NULL
, L
"EfiLoaderData", 0); break;
42 case EfiBootServicesCode
: StrnCatGrow(&RetVal
, NULL
, L
"EfiBootServicesCode", 0); break;
43 case EfiBootServicesData
: StrnCatGrow(&RetVal
, NULL
, L
"EfiBootServicesData", 0); break;
44 case EfiRuntimeServicesCode
: StrnCatGrow(&RetVal
, NULL
, L
"EfiRuntimeServicesCode", 0); break;
45 case EfiRuntimeServicesData
: StrnCatGrow(&RetVal
, NULL
, L
"EfiRuntimeServicesData", 0); break;
46 case EfiConventionalMemory
: StrnCatGrow(&RetVal
, NULL
, L
"EfiConventionalMemory", 0); break;
47 case EfiUnusableMemory
: StrnCatGrow(&RetVal
, NULL
, L
"EfiUnusableMemory", 0); break;
48 case EfiACPIReclaimMemory
: StrnCatGrow(&RetVal
, NULL
, L
"EfiACPIReclaimMemory", 0); break;
49 case EfiACPIMemoryNVS
: StrnCatGrow(&RetVal
, NULL
, L
"EfiACPIMemoryNVS", 0); break;
50 case EfiMemoryMappedIO
: StrnCatGrow(&RetVal
, NULL
, L
"EfiMemoryMappedIO", 0); break;
51 case EfiMemoryMappedIOPortSpace
: StrnCatGrow(&RetVal
, NULL
, L
"EfiMemoryMappedIOPortSpace", 0); break;
52 case EfiPalCode
: StrnCatGrow(&RetVal
, NULL
, L
"EfiPalCode", 0); break;
53 case EfiMaxMemoryType
: StrnCatGrow(&RetVal
, NULL
, L
"EfiMaxMemoryType", 0); break;
54 default: ASSERT(FALSE
);
60 Function to translate the EFI_GRAPHICS_PIXEL_FORMAT into a string.
62 @param[in] Memory The format type.
64 @retval A string representation of the type allocated from BS Pool.
69 IN CONST EFI_GRAPHICS_PIXEL_FORMAT Fmt
76 case PixelRedGreenBlueReserved8BitPerColor
: StrnCatGrow(&RetVal
, NULL
, L
"PixelRedGreenBlueReserved8BitPerColor", 0); break;
77 case PixelBlueGreenRedReserved8BitPerColor
: StrnCatGrow(&RetVal
, NULL
, L
"PixelBlueGreenRedReserved8BitPerColor", 0); break;
78 case PixelBitMask
: StrnCatGrow(&RetVal
, NULL
, L
"PixelBitMask", 0); break;
79 case PixelBltOnly
: StrnCatGrow(&RetVal
, NULL
, L
"PixelBltOnly", 0); break;
80 case PixelFormatMax
: StrnCatGrow(&RetVal
, NULL
, L
"PixelFormatMax", 0); break;
81 default: ASSERT(FALSE
);
87 Constructor for the library.
89 @param[in] ImageHandle Ignored.
90 @param[in] SystemTable Ignored.
92 @retval EFI_SUCCESS The operation was successful.
96 HandleParsingLibConstructor (
97 IN EFI_HANDLE ImageHandle
,
98 IN EFI_SYSTEM_TABLE
*SystemTable
101 mHandleParsingHiiHandle
= HiiAddPackages (&gHandleParsingHiiGuid
, gImageHandle
, UefiHandleParsingLibStrings
, NULL
);
102 if (mHandleParsingHiiHandle
== NULL
) {
103 return (EFI_DEVICE_ERROR
);
106 return (EFI_SUCCESS
);
110 Destructor for the library. free any resources.
112 @param[in] ImageHandle Ignored.
113 @param[in] SystemTable Ignored.
115 @retval EFI_SUCCESS The operation was successful.
119 HandleParsingLibDestructor (
120 IN EFI_HANDLE ImageHandle
,
121 IN EFI_SYSTEM_TABLE
*SystemTable
124 if (mHandleParsingHiiHandle
!= NULL
) {
125 HiiRemovePackages(mHandleParsingHiiHandle
);
127 return (EFI_SUCCESS
);
131 Function to dump information about LoadedImage.
133 This will allocate the return buffer from boot services pool.
135 @param[in] TheHandle The handle that has LoadedImage installed.
136 @param[in] Verbose TRUE for additional information, FALSE otherwise.
138 @retval A poitner to a string containing the information.
142 LoadedImageProtocolDumpInformation(
143 IN CONST EFI_HANDLE TheHandle
,
144 IN CONST BOOLEAN Verbose
147 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
155 return (CatSPrint(NULL
, L
"LoadedImage"));
158 Temp
= HiiGetString(mHandleParsingHiiHandle
, STRING_TOKEN(STR_LI_DUMP_MAIN
), NULL
);
159 RetVal
= AllocateZeroPool (PcdGet16 (PcdShellPrintBufferSize
));
160 if (Temp
== NULL
|| RetVal
== NULL
) {
161 SHELL_FREE_NON_NULL(Temp
);
162 SHELL_FREE_NON_NULL(RetVal
);
166 Status
= gBS
->OpenProtocol (
168 &gEfiLoadedImageProtocolGuid
,
169 (VOID
**)&LoadedImage
,
172 EFI_OPEN_PROTOCOL_GET_PROTOCOL
175 if (EFI_ERROR (Status
)) {
176 SHELL_FREE_NON_NULL (Temp
);
177 SHELL_FREE_NON_NULL (RetVal
);
181 DataType
= ConvertMemoryType(LoadedImage
->ImageDataType
);
182 CodeType
= ConvertMemoryType(LoadedImage
->ImageCodeType
);
184 RetVal
= CatSPrint(RetVal
,
186 LoadedImage
->Revision
,
187 LoadedImage
->ParentHandle
,
188 LoadedImage
->SystemTable
,
189 LoadedImage
->DeviceHandle
,
190 LoadedImage
->FilePath
,
191 LoadedImage
->LoadOptionsSize
,
192 LoadedImage
->LoadOptions
,
193 LoadedImage
->ImageBase
,
194 LoadedImage
->ImageSize
,
197 LoadedImage
->Unload
);
200 SHELL_FREE_NON_NULL(Temp
);
201 SHELL_FREE_NON_NULL(CodeType
);
202 SHELL_FREE_NON_NULL(DataType
);
208 Function to dump information about GOP.
210 This will allocate the return buffer from boot services pool.
212 @param[in] TheHandle The handle that has LoadedImage installed.
213 @param[in] Verbose TRUE for additional information, FALSE otherwise.
215 @retval A poitner to a string containing the information.
219 GraphicsOutputProtocolDumpInformation(
220 IN CONST EFI_HANDLE TheHandle
,
221 IN CONST BOOLEAN Verbose
224 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
231 return (CatSPrint(NULL
, L
"GraphicsOutput"));
234 Temp
= HiiGetString(mHandleParsingHiiHandle
, STRING_TOKEN(STR_GOP_DUMP_MAIN
), NULL
);
235 RetVal
= AllocateZeroPool (PcdGet16 (PcdShellPrintBufferSize
));
236 if (Temp
== NULL
|| RetVal
== NULL
) {
237 SHELL_FREE_NON_NULL(Temp
);
238 SHELL_FREE_NON_NULL(RetVal
);
242 Status
= gBS
->OpenProtocol (
244 &gEfiGraphicsOutputProtocolGuid
,
245 (VOID
**)&GraphicsOutput
,
248 EFI_OPEN_PROTOCOL_GET_PROTOCOL
251 if (EFI_ERROR (Status
)) {
252 SHELL_FREE_NON_NULL (Temp
);
253 SHELL_FREE_NON_NULL (RetVal
);
257 Fmt
= ConvertPixelFormat(GraphicsOutput
->Mode
->Info
->PixelFormat
);
259 RetVal
= CatSPrint(RetVal
,
261 GraphicsOutput
->Mode
->MaxMode
,
262 GraphicsOutput
->Mode
->Mode
,
263 GraphicsOutput
->Mode
->FrameBufferBase
,
264 (UINT64
)GraphicsOutput
->Mode
->FrameBufferSize
,
265 (UINT64
)GraphicsOutput
->Mode
->SizeOfInfo
,
266 GraphicsOutput
->Mode
->Info
->Version
,
267 GraphicsOutput
->Mode
->Info
->HorizontalResolution
,
268 GraphicsOutput
->Mode
->Info
->VerticalResolution
,
270 GraphicsOutput
->Mode
->Info
->PixelsPerScanLine
,
271 GraphicsOutput
->Mode
->Info
->PixelFormat
!=PixelBitMask
?0:GraphicsOutput
->Mode
->Info
->PixelInformation
.RedMask
,
272 GraphicsOutput
->Mode
->Info
->PixelFormat
!=PixelBitMask
?0:GraphicsOutput
->Mode
->Info
->PixelInformation
.GreenMask
,
273 GraphicsOutput
->Mode
->Info
->PixelFormat
!=PixelBitMask
?0:GraphicsOutput
->Mode
->Info
->PixelInformation
.BlueMask
276 SHELL_FREE_NON_NULL(Temp
);
277 SHELL_FREE_NON_NULL(Fmt
);
283 Function to dump information about PciRootBridgeIo.
285 This will allocate the return buffer from boot services pool.
287 @param[in] TheHandle The handle that has PciRootBridgeIo installed.
288 @param[in] Verbose TRUE for additional information, FALSE otherwise.
290 @retval A poitner to a string containing the information.
294 PciRootBridgeIoDumpInformation(
295 IN CONST EFI_HANDLE TheHandle
,
296 IN CONST BOOLEAN Verbose
299 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*PciRootBridgeIo
;
300 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*Configuration
;
311 return (CatSPrint(NULL
, L
"PciRootBridgeIo"));
314 Status
= gBS
->HandleProtocol(
316 &gEfiPciRootBridgeIoProtocolGuid
,
317 (VOID
**)&PciRootBridgeIo
);
319 if (EFI_ERROR(Status
)) {
323 Temp
= HiiGetString(mHandleParsingHiiHandle
, STRING_TOKEN(STR_PCIRB_DUMP_PH
), NULL
);
324 ASSERT (Temp
!= NULL
);
325 Temp2
= CatSPrint(L
"\r\n", Temp
, PciRootBridgeIo
->ParentHandle
);
330 Temp
= HiiGetString(mHandleParsingHiiHandle
, STRING_TOKEN(STR_PCIRB_DUMP_SEG
), NULL
);
331 ASSERT (Temp
!= NULL
);
332 Temp2
= CatSPrint(RetVal
, Temp
, PciRootBridgeIo
->SegmentNumber
);
340 Status
= PciRootBridgeIo
->GetAttributes (PciRootBridgeIo
, &Supports
, &Attributes
);
341 if (!EFI_ERROR(Status
)) {
342 Temp
= HiiGetString(mHandleParsingHiiHandle
, STRING_TOKEN(STR_PCIRB_DUMP_ATT
), NULL
);
343 ASSERT (Temp
!= NULL
);
344 Temp2
= CatSPrint(RetVal
, Temp
, Attributes
);
350 Temp
= HiiGetString(mHandleParsingHiiHandle
, STRING_TOKEN(STR_PCIRB_DUMP_SUPPORTS
), NULL
);
351 ASSERT (Temp
!= NULL
);
352 Temp2
= CatSPrint(RetVal
, Temp
, Supports
);
359 Configuration
= NULL
;
360 Status
= PciRootBridgeIo
->Configuration (PciRootBridgeIo
, (VOID
**) &Configuration
);
361 if (!EFI_ERROR(Status
) && Configuration
!= NULL
) {
362 Temp
= HiiGetString(mHandleParsingHiiHandle
, STRING_TOKEN(STR_PCIRB_DUMP_TITLE
), NULL
);
363 ASSERT (Temp
!= NULL
);
364 Temp2
= CatSPrint(RetVal
, Temp
, Supports
);
369 while (Configuration
->Desc
== ACPI_ADDRESS_SPACE_DESCRIPTOR
) {
371 switch (Configuration
->ResType
) {
372 case ACPI_ADDRESS_SPACE_TYPE_MEM
:
373 Temp
= HiiGetString(mHandleParsingHiiHandle
, STRING_TOKEN(STR_PCIRB_DUMP_MEM
), NULL
);
375 case ACPI_ADDRESS_SPACE_TYPE_IO
:
376 Temp
= HiiGetString(mHandleParsingHiiHandle
, STRING_TOKEN(STR_PCIRB_DUMP_IO
), NULL
);
378 case ACPI_ADDRESS_SPACE_TYPE_BUS
:
379 Temp
= HiiGetString(mHandleParsingHiiHandle
, STRING_TOKEN(STR_PCIRB_DUMP_BUS
), NULL
);
383 Temp2
= CatSPrint(RetVal
, L
"%s", Temp
);
390 Temp2
= CatSPrint(RetVal
,
391 L
"%H%02x %016lx %016lx %02x%N\r\n",
392 Configuration
->SpecificFlag
,
393 Configuration
->AddrRangeMin
,
394 Configuration
->AddrRangeMax
,
395 Configuration
->AddrSpaceGranularity
407 Function to dump information about SimpleTextOut.
409 This will allocate the return buffer from boot services pool.
411 @param[in] TheHandle The handle that has SimpleTextOut installed.
412 @param[in] Verbose TRUE for additional information, FALSE otherwise.
414 @retval A poitner to a string containing the information.
418 TxtOutProtocolDumpInformation(
419 IN CONST EFI_HANDLE TheHandle
,
420 IN CONST BOOLEAN Verbose
423 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*Dev
;
440 Status
= gBS
->HandleProtocol(
442 &gEfiSimpleTextOutProtocolGuid
,
445 ASSERT_EFI_ERROR(Status
);
446 ASSERT (Dev
!= NULL
&& Dev
->Mode
!= NULL
);
448 Size
= (Dev
->Mode
->MaxMode
+ 1) * 80;
449 RetVal
= AllocateZeroPool(Size
);
451 Temp
= HiiGetString(mHandleParsingHiiHandle
, STRING_TOKEN(STR_TXT_OUT_DUMP_HEADER
), NULL
);
453 UnicodeSPrint(RetVal
, Size
, Temp
, Dev
, Dev
->Mode
->Attribute
);
460 Temp
= HiiGetString(mHandleParsingHiiHandle
, STRING_TOKEN(STR_TXT_OUT_DUMP_LINE
), NULL
);
461 for (Index
= 0; Index
< Dev
->Mode
->MaxMode
; Index
++) {
462 Status
= Dev
->QueryMode (Dev
, Index
, &Col
, &Row
);
463 NewSize
= Size
- StrSize(RetVal
);
465 RetVal
+ StrLen(RetVal
),
467 Temp
== NULL
?L
"":Temp
,
468 Index
== Dev
->Mode
->Mode
? L
'*' : L
' ',
470 !EFI_ERROR(Status
)?(INTN
)Col
:-1,
471 !EFI_ERROR(Status
)?(INTN
)Row
:-1
478 STATIC CONST UINTN VersionStringSize
= 60;
481 Function to dump information about EfiDriverSupportedEfiVersion protocol.
483 This will allocate the return buffer from boot services pool.
485 @param[in] TheHandle The handle that has the protocol installed.
486 @param[in] Verbose TRUE for additional information, FALSE otherwise.
488 @retval A poitner to a string containing the information.
492 DriverEfiVersionProtocolDumpInformation(
493 IN CONST EFI_HANDLE TheHandle
,
494 IN CONST BOOLEAN Verbose
497 EFI_DRIVER_SUPPORTED_EFI_VERSION_PROTOCOL
*DriverEfiVersion
;
501 Status
= gBS
->HandleProtocol(
503 &gEfiDriverSupportedEfiVersionProtocolGuid
,
504 (VOID
**)&DriverEfiVersion
);
506 ASSERT_EFI_ERROR(Status
);
508 RetVal
= AllocateZeroPool(VersionStringSize
);
509 ASSERT(RetVal
!= NULL
);
510 UnicodeSPrint(RetVal
, VersionStringSize
, L
"0x%08x", DriverEfiVersion
->FirmwareVersion
);
515 Function to dump information about DevicePath protocol.
517 This will allocate the return buffer from boot services pool.
519 @param[in] TheHandle The handle that has the protocol installed.
520 @param[in] Verbose TRUE for additional information, FALSE otherwise.
522 @retval A poitner to a string containing the information.
526 DevicePathProtocolDumpInformation(
527 IN CONST EFI_HANDLE TheHandle
,
528 IN CONST BOOLEAN Verbose
531 EFI_DEVICE_PATH_PROTOCOL
*DevPath
;
537 Status
= gBS
->OpenProtocol(TheHandle
, &gEfiDevicePathProtocolGuid
, (VOID
**)&DevPath
, gImageHandle
, NULL
, EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
538 if (!EFI_ERROR(Status
)) {
540 // I cannot decide whether to allow shortcuts here (the second BOOLEAN on the next line)
542 Temp
= ConvertDevicePathToText(DevPath
, TRUE
, TRUE
);
543 gBS
->CloseProtocol(TheHandle
, &gEfiDevicePathProtocolGuid
, gImageHandle
, NULL
);
545 if (!Verbose
&& Temp
!= NULL
&& StrLen(Temp
) > 30) {
547 Temp2
= StrnCatGrow(&Temp2
, NULL
, Temp
+(StrLen(Temp
) - 30), 30);
555 // Put the information on the NT32 protocol GUIDs here so we are not dependant on the Nt32Pkg
557 #define LOCAL_EFI_WIN_NT_THUNK_PROTOCOL_GUID \
559 0x58c518b1, 0x76f3, 0x11d4, { 0xbc, 0xea, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 } \
562 #define LOCAL_EFI_WIN_NT_BUS_DRIVER_IO_PROTOCOL_GUID \
564 0x96eb4ad6, 0xa32a, 0x11d4, { 0xbc, 0xfd, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 } \
567 #define LOCAL_EFI_WIN_NT_SERIAL_PORT_GUID \
569 0xc95a93d, 0xa006, 0x11d4, { 0xbc, 0xfa, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 } \
571 STATIC CONST EFI_GUID WinNtThunkProtocolGuid
= LOCAL_EFI_WIN_NT_THUNK_PROTOCOL_GUID
;
572 STATIC CONST EFI_GUID WinNtIoProtocolGuid
= LOCAL_EFI_WIN_NT_BUS_DRIVER_IO_PROTOCOL_GUID
;
573 STATIC CONST EFI_GUID WinNtSerialPortGuid
= LOCAL_EFI_WIN_NT_SERIAL_PORT_GUID
;
575 STATIC CONST GUID_INFO_BLOCK mGuidStringListNT
[] = {
576 {STRING_TOKEN(STR_WINNT_THUNK
), (EFI_GUID
*)&WinNtThunkProtocolGuid
, NULL
},
577 {STRING_TOKEN(STR_WINNT_DRIVER_IO
), (EFI_GUID
*)&WinNtIoProtocolGuid
, NULL
},
578 {STRING_TOKEN(STR_WINNT_SERIAL_PORT
), (EFI_GUID
*)&WinNtSerialPortGuid
, NULL
},
579 {STRING_TOKEN(STR_UNKNOWN_DEVICE
), NULL
, NULL
},
582 STATIC CONST GUID_INFO_BLOCK mGuidStringList
[] = {
583 {STRING_TOKEN(STR_LOADED_IMAGE
), &gEfiLoadedImageProtocolGuid
, LoadedImageProtocolDumpInformation
},
584 {STRING_TOKEN(STR_DEVICE_PATH
), &gEfiDevicePathProtocolGuid
, DevicePathProtocolDumpInformation
},
585 {STRING_TOKEN(STR_IMAGE_PATH
), &gEfiLoadedImageDevicePathProtocolGuid
, DevicePathProtocolDumpInformation
},
586 {STRING_TOKEN(STR_DEVICE_PATH_UTIL
), &gEfiDevicePathUtilitiesProtocolGuid
, NULL
},
587 {STRING_TOKEN(STR_DEVICE_PATH_TXT
), &gEfiDevicePathToTextProtocolGuid
, NULL
},
588 {STRING_TOKEN(STR_DEVICE_PATH_FTXT
), &gEfiDevicePathFromTextProtocolGuid
, NULL
},
589 {STRING_TOKEN(STR_DEVICE_PATH_PC
), &gEfiPcAnsiGuid
, NULL
},
590 {STRING_TOKEN(STR_DEVICE_PATH_VT100
), &gEfiVT100Guid
, NULL
},
591 {STRING_TOKEN(STR_DEVICE_PATH_VT100P
), &gEfiVT100PlusGuid
, NULL
},
592 {STRING_TOKEN(STR_DEVICE_PATH_VTUTF8
), &gEfiVTUTF8Guid
, NULL
},
593 {STRING_TOKEN(STR_DRIVER_BINDING
), &gEfiDriverBindingProtocolGuid
, NULL
},
594 {STRING_TOKEN(STR_PLATFORM_OVERRIDE
), &gEfiPlatformDriverOverrideProtocolGuid
, NULL
},
595 {STRING_TOKEN(STR_BUS_OVERRIDE
), &gEfiBusSpecificDriverOverrideProtocolGuid
, NULL
},
596 {STRING_TOKEN(STR_DRIVER_DIAG
), &gEfiDriverDiagnosticsProtocolGuid
, NULL
},
597 {STRING_TOKEN(STR_DRIVER_DIAG2
), &gEfiDriverDiagnostics2ProtocolGuid
, NULL
},
598 {STRING_TOKEN(STR_DRIVER_CN
), &gEfiComponentNameProtocolGuid
, NULL
},
599 {STRING_TOKEN(STR_DRIVER_CN2
), &gEfiComponentName2ProtocolGuid
, NULL
},
600 {STRING_TOKEN(STR_PLAT_DRV_CFG
), &gEfiPlatformToDriverConfigurationProtocolGuid
, NULL
},
601 {STRING_TOKEN(STR_DRIVER_VERSION
), &gEfiDriverSupportedEfiVersionProtocolGuid
, DriverEfiVersionProtocolDumpInformation
},
602 {STRING_TOKEN(STR_TXT_IN
), &gEfiSimpleTextInProtocolGuid
, NULL
},
603 {STRING_TOKEN(STR_TXT_IN_EX
), &gEfiSimpleTextInputExProtocolGuid
, NULL
},
604 {STRING_TOKEN(STR_TXT_OUT
), &gEfiSimpleTextOutProtocolGuid
, TxtOutProtocolDumpInformation
},
605 {STRING_TOKEN(STR_SIM_POINTER
), &gEfiSimplePointerProtocolGuid
, NULL
},
606 {STRING_TOKEN(STR_ABS_POINTER
), &gEfiAbsolutePointerProtocolGuid
, NULL
},
607 {STRING_TOKEN(STR_SERIAL_IO
), &gEfiSerialIoProtocolGuid
, NULL
},
608 {STRING_TOKEN(STR_GRAPHICS_OUTPUT
), &gEfiGraphicsOutputProtocolGuid
, GraphicsOutputProtocolDumpInformation
},
609 {STRING_TOKEN(STR_EDID_DISCOVERED
), &gEfiEdidDiscoveredProtocolGuid
, NULL
},
610 {STRING_TOKEN(STR_EDID_ACTIVE
), &gEfiEdidActiveProtocolGuid
, NULL
},
611 {STRING_TOKEN(STR_EDID_OVERRIDE
), &gEfiEdidOverrideProtocolGuid
, NULL
},
612 {STRING_TOKEN(STR_CON_IN
), &gEfiConsoleInDeviceGuid
, NULL
},
613 {STRING_TOKEN(STR_CON_OUT
), &gEfiConsoleOutDeviceGuid
, NULL
},
614 {STRING_TOKEN(STR_STD_ERR
), &gEfiStandardErrorDeviceGuid
, NULL
},
615 {STRING_TOKEN(STR_LOAD_FILE
), &gEfiLoadFileProtocolGuid
, NULL
},
616 {STRING_TOKEN(STR_LOAD_FILE2
), &gEfiLoadFile2ProtocolGuid
, NULL
},
617 {STRING_TOKEN(STR_SIMPLE_FILE_SYS
), &gEfiSimpleFileSystemProtocolGuid
, NULL
},
618 {STRING_TOKEN(STR_TAPE_IO
), &gEfiTapeIoProtocolGuid
, NULL
},
619 {STRING_TOKEN(STR_DISK_IO
), &gEfiDiskIoProtocolGuid
, NULL
},
620 {STRING_TOKEN(STR_BLK_IO
), &gEfiBlockIoProtocolGuid
, NULL
},
621 {STRING_TOKEN(STR_UC
), &gEfiUnicodeCollationProtocolGuid
, NULL
},
622 {STRING_TOKEN(STR_UC2
), &gEfiUnicodeCollation2ProtocolGuid
, NULL
},
623 {STRING_TOKEN(STR_PCIRB_IO
), &gEfiPciRootBridgeIoProtocolGuid
, PciRootBridgeIoDumpInformation
},
624 {STRING_TOKEN(STR_PCI_IO
), &gEfiPciIoProtocolGuid
, NULL
},
625 {STRING_TOKEN(STR_SCSI_PT
), &gEfiScsiPassThruProtocolGuid
, NULL
},
626 {STRING_TOKEN(STR_SCSI_IO
), &gEfiScsiIoProtocolGuid
, NULL
},
627 {STRING_TOKEN(STR_SCSI_PT_EXT
), &gEfiExtScsiPassThruProtocolGuid
, NULL
},
628 {STRING_TOKEN(STR_ISCSI
), &gEfiIScsiInitiatorNameProtocolGuid
, NULL
},
629 {STRING_TOKEN(STR_USB_IO
), &gEfiUsbIoProtocolGuid
, NULL
},
630 {STRING_TOKEN(STR_USB_HC
), &gEfiUsbHcProtocolGuid
, NULL
},
631 {STRING_TOKEN(STR_USB_HC2
), &gEfiUsb2HcProtocolGuid
, NULL
},
632 {STRING_TOKEN(STR_DEBUG_SUPPORT
), &gEfiDebugSupportProtocolGuid
, NULL
},
633 {STRING_TOKEN(STR_DEBUG_PORT
), &gEfiDebugPortProtocolGuid
, NULL
},
634 {STRING_TOKEN(STR_DECOMPRESS
), &gEfiDecompressProtocolGuid
, NULL
},
635 {STRING_TOKEN(STR_ACPI_TABLE
), &gEfiAcpiTableProtocolGuid
, NULL
},
636 {STRING_TOKEN(STR_EBC_INTERPRETER
), &gEfiEbcProtocolGuid
, NULL
},
637 {STRING_TOKEN(STR_SNP
), &gEfiSimpleNetworkProtocolGuid
, NULL
},
638 {STRING_TOKEN(STR_NII
), &gEfiNetworkInterfaceIdentifierProtocolGuid
, NULL
},
639 {STRING_TOKEN(STR_NII_31
), &gEfiNetworkInterfaceIdentifierProtocolGuid_31
, NULL
},
640 {STRING_TOKEN(STR_PXE_BC
), &gEfiPxeBaseCodeProtocolGuid
, NULL
},
641 {STRING_TOKEN(STR_PXE_CB
), &gEfiPxeBaseCodeCallbackProtocolGuid
, NULL
},
642 {STRING_TOKEN(STR_BIS
), &gEfiBisProtocolGuid
, NULL
},
643 {STRING_TOKEN(STR_MNP_SB
), &gEfiManagedNetworkServiceBindingProtocolGuid
, NULL
},
644 {STRING_TOKEN(STR_MNP
), &gEfiManagedNetworkProtocolGuid
, NULL
},
645 {STRING_TOKEN(STR_ARP_SB
), &gEfiArpServiceBindingProtocolGuid
, NULL
},
646 {STRING_TOKEN(STR_ARP
), &gEfiArpProtocolGuid
, NULL
},
647 {STRING_TOKEN(STR_DHCPV4_SB
), &gEfiDhcp4ServiceBindingProtocolGuid
, NULL
},
648 {STRING_TOKEN(STR_DHCPV4
), &gEfiDhcp4ProtocolGuid
, NULL
},
649 {STRING_TOKEN(STR_TCPV4_SB
), &gEfiTcp4ServiceBindingProtocolGuid
, NULL
},
650 {STRING_TOKEN(STR_TCPV4
), &gEfiTcp4ProtocolGuid
, NULL
},
651 {STRING_TOKEN(STR_IPV4_SB
), &gEfiIp4ServiceBindingProtocolGuid
, NULL
},
652 {STRING_TOKEN(STR_IPV4
), &gEfiIp4ProtocolGuid
, NULL
},
653 {STRING_TOKEN(STR_IPV4_CFG
), &gEfiIp4ConfigProtocolGuid
, NULL
},
654 {STRING_TOKEN(STR_SHELL_PARAMETERS
), &gEfiShellParametersProtocolGuid
, NULL
},
655 {STRING_TOKEN(STR_SHELL
), &gEfiShellProtocolGuid
, NULL
},
656 {STRING_TOKEN(STR_UDPV4_SB
), &gEfiUdp4ServiceBindingProtocolGuid
, NULL
},
657 {STRING_TOKEN(STR_UDPV4
), &gEfiUdp4ProtocolGuid
, NULL
},
658 {STRING_TOKEN(STR_MTFTPV4_SB
), &gEfiMtftp4ServiceBindingProtocolGuid
, NULL
},
659 {STRING_TOKEN(STR_MTFTPV4
), &gEfiMtftp4ProtocolGuid
, NULL
},
660 {STRING_TOKEN(STR_AUTH_INFO
), &gEfiAuthenticationInfoProtocolGuid
, NULL
},
661 {STRING_TOKEN(STR_HASH_SB
), &gEfiHashServiceBindingProtocolGuid
, NULL
},
662 {STRING_TOKEN(STR_HASH
), &gEfiHashProtocolGuid
, NULL
},
663 {STRING_TOKEN(STR_HII_FONT
), &gEfiHiiFontProtocolGuid
, NULL
},
664 {STRING_TOKEN(STR_HII_STRING
), &gEfiHiiStringProtocolGuid
, NULL
},
665 {STRING_TOKEN(STR_HII_IMAGE
), &gEfiHiiImageProtocolGuid
, NULL
},
666 {STRING_TOKEN(STR_HII_DATABASE
), &gEfiHiiDatabaseProtocolGuid
, NULL
},
667 {STRING_TOKEN(STR_HII_CONFIG_ROUT
), &gEfiHiiConfigRoutingProtocolGuid
, NULL
},
668 {STRING_TOKEN(STR_HII_CONFIG_ACC
), &gEfiHiiConfigAccessProtocolGuid
, NULL
},
669 {STRING_TOKEN(STR_HII_FORM_BROWSER2
), &gEfiFormBrowser2ProtocolGuid
, NULL
},
670 {STRING_TOKEN(STR_DRIVER_FAM_OVERRIDE
), &gEfiDriverFamilyOverrideProtocolGuid
, NULL
},
671 {STRING_TOKEN(STR_PCD
), &gPcdProtocolGuid
, NULL
},
672 {STRING_TOKEN(STR_TCG
), &gEfiTcgProtocolGuid
, NULL
},
673 {STRING_TOKEN(STR_HII_PACKAGE_LIST
), &gEfiHiiPackageListProtocolGuid
, NULL
},
676 // the ones under this are deprecated by the current UEFI Spec, but may be found anyways...
678 {STRING_TOKEN(STR_SHELL_INTERFACE
), &gEfiShellInterfaceGuid
, NULL
},
679 {STRING_TOKEN(STR_SHELL_ENV2
), &gEfiShellEnvironment2Guid
, NULL
},
680 {STRING_TOKEN(STR_SHELL_ENV
), &gEfiShellEnvironment2Guid
, NULL
},
681 {STRING_TOKEN(STR_DEVICE_IO
), &gEfiDeviceIoProtocolGuid
, NULL
},
682 {STRING_TOKEN(STR_UGA_DRAW
), &gEfiUgaDrawProtocolGuid
, NULL
},
683 {STRING_TOKEN(STR_UGA_IO
), &gEfiUgaIoProtocolGuid
, NULL
},
684 {STRING_TOKEN(STR_ESP
), &gEfiPartTypeSystemPartGuid
, NULL
},
685 {STRING_TOKEN(STR_GPT_NBR
), &gEfiPartTypeLegacyMbrGuid
, NULL
},
686 {STRING_TOKEN(STR_DRIVER_CONFIG
), &gEfiDriverConfigurationProtocolGuid
, NULL
},
687 {STRING_TOKEN(STR_DRIVER_CONFIG2
), &gEfiDriverConfiguration2ProtocolGuid
, NULL
},
690 // the ones under this are GUID identified structs, not protocols
692 {STRING_TOKEN(STR_FILE_INFO
), &gEfiFileInfoGuid
, NULL
},
693 {STRING_TOKEN(STR_FILE_SYS_INFO
), &gEfiFileSystemInfoGuid
, NULL
},
696 // the ones under this are misc GUIDS.
698 {STRING_TOKEN(STR_EFI_GLOBAL_VARIABLE
), &gEfiGlobalVariableGuid
, NULL
},
703 {STRING_TOKEN(STR_IP6_SB
), &gEfiIp6ServiceBindingProtocolGuid
, NULL
},
704 {STRING_TOKEN(STR_IP6
), &gEfiIp6ProtocolGuid
, NULL
},
705 {STRING_TOKEN(STR_IP6_CONFIG
), &gEfiIp6ConfigProtocolGuid
, NULL
},
706 {STRING_TOKEN(STR_MTFTP6_SB
), &gEfiMtftp6ServiceBindingProtocolGuid
, NULL
},
707 {STRING_TOKEN(STR_MTFTP6
), &gEfiMtftp6ProtocolGuid
, NULL
},
708 {STRING_TOKEN(STR_DHCP6_SB
), &gEfiDhcp6ServiceBindingProtocolGuid
, NULL
},
709 {STRING_TOKEN(STR_DHCP6
), &gEfiDhcp6ProtocolGuid
, NULL
},
710 {STRING_TOKEN(STR_UDP6_SB
), &gEfiUdp6ServiceBindingProtocolGuid
, NULL
},
711 {STRING_TOKEN(STR_UDP6
), &gEfiUdp6ProtocolGuid
, NULL
},
712 {STRING_TOKEN(STR_TCP6_SB
), &gEfiTcp6ServiceBindingProtocolGuid
, NULL
},
713 {STRING_TOKEN(STR_TCP6
), &gEfiTcp6ProtocolGuid
, NULL
},
714 {STRING_TOKEN(STR_VLAN_CONFIG
), &gEfiVlanConfigProtocolGuid
, NULL
},
715 {STRING_TOKEN(STR_EAP
), &gEfiEapProtocolGuid
, NULL
},
716 {STRING_TOKEN(STR_EAP_MGMT
), &gEfiEapManagementProtocolGuid
, NULL
},
717 {STRING_TOKEN(STR_FTP4_SB
), &gEfiFtp4ServiceBindingProtocolGuid
, NULL
},
718 {STRING_TOKEN(STR_FTP4
), &gEfiFtp4ProtocolGuid
, NULL
},
719 {STRING_TOKEN(STR_IP_SEC_CONFIG
), &gEfiIpSecConfigProtocolGuid
, NULL
},
720 {STRING_TOKEN(STR_DH
), &gEfiDriverHealthProtocolGuid
, NULL
},
721 {STRING_TOKEN(STR_DEF_IMG_LOAD
), &gEfiDeferredImageLoadProtocolGuid
, NULL
},
722 {STRING_TOKEN(STR_USER_CRED
), &gEfiUserCredentialProtocolGuid
, NULL
},
723 {STRING_TOKEN(STR_USER_MNGR
), &gEfiUserManagerProtocolGuid
, NULL
},
724 {STRING_TOKEN(STR_ATA_PASS_THRU
), &gEfiAtaPassThruProtocolGuid
, NULL
},
729 {STRING_TOKEN(STR_FW_MGMT
), &gEfiFirmwareManagementProtocolGuid
, NULL
},
730 {STRING_TOKEN(STR_IP_SEC
), &gEfiIpSecProtocolGuid
, NULL
},
731 {STRING_TOKEN(STR_IP_SEC2
), &gEfiIpSec2ProtocolGuid
, NULL
},
736 {STRING_TOKEN(STR_KMS
), &gEfiKmsProtocolGuid
, NULL
},
737 {STRING_TOKEN(STR_BLK_IO2
), &gEfiBlockIo2ProtocolGuid
, NULL
},
738 {STRING_TOKEN(STR_SSC
), &gEfiStorageSecurityCommandProtocolGuid
, NULL
},
739 {STRING_TOKEN(STR_UCRED2
), &gEfiUserCredential2ProtocolGuid
, NULL
},
744 {STRING_TOKEN(STR_DISK_IO2
), &gEfiDiskIo2ProtocolGuid
, NULL
},
745 {STRING_TOKEN(STR_ADAPTER_INFO
), &gEfiAdapterInformationProtocolGuid
, NULL
},
750 {STRING_TOKEN(STR_IDE_CONT_INIT
), &gEfiIdeControllerInitProtocolGuid
, NULL
},
755 {STRING_TOKEN(STR_UNKNOWN_DEVICE
), NULL
, NULL
},
759 Function to get the node for a protocol or struct from it's GUID.
761 if Guid is NULL, then ASSERT.
763 @param[in] Guid The GUID to look for the name of.
767 CONST GUID_INFO_BLOCK
*
769 InternalShellGetNodeFromGuid(
770 IN CONST EFI_GUID
* Guid
773 CONST GUID_INFO_BLOCK
*ListWalker
;
775 ASSERT(Guid
!= NULL
);
777 if (PcdGetBool(PcdShellIncludeNtGuids
)) {
778 for (ListWalker
= mGuidStringListNT
; ListWalker
!= NULL
&& ListWalker
->GuidId
!= NULL
; ListWalker
++) {
779 if (CompareGuid(ListWalker
->GuidId
, Guid
)) {
784 for (ListWalker
= mGuidStringList
; ListWalker
!= NULL
&& ListWalker
->GuidId
!= NULL
; ListWalker
++) {
785 if (CompareGuid(ListWalker
->GuidId
, Guid
)) {
793 Function to get the name of a protocol or struct from it's GUID.
795 if Guid is NULL, then ASSERT.
797 @param[in] Guid The GUID to look for the name of.
798 @param[in] Lang The language to use.
800 @return pointer to string of the name. The caller
801 is responsible to free this memory.
805 GetStringNameFromGuid(
806 IN CONST EFI_GUID
*Guid
,
807 IN CONST CHAR8
*Lang OPTIONAL
810 CONST GUID_INFO_BLOCK
*Id
;
812 Id
= InternalShellGetNodeFromGuid(Guid
);
813 return (HiiGetString(mHandleParsingHiiHandle
, Id
->StringId
, Lang
));
817 Function to dump protocol information from a handle.
819 This function will return a allocated string buffer containing the
820 information. The caller is responsible for freeing the memory.
822 If Guid is NULL, ASSERT().
823 If TheHandle is NULL, ASSERT().
825 @param[in] TheHandle The handle to dump information from.
826 @param[in] Guid The GUID of the protocol to dump.
827 @param[in] Verbose TRUE for extra info. FALSE otherwise.
829 @return The pointer to string.
830 @retval NULL An error was encountered.
834 GetProtocolInformationDump(
835 IN CONST EFI_HANDLE TheHandle
,
836 IN CONST EFI_GUID
*Guid
,
837 IN CONST BOOLEAN Verbose
840 CONST GUID_INFO_BLOCK
*Id
;
842 ASSERT(TheHandle
!= NULL
);
843 ASSERT(Guid
!= NULL
);
845 if (TheHandle
== NULL
|| Guid
== NULL
) {
849 Id
= InternalShellGetNodeFromGuid(Guid
);
850 if (Id
!= NULL
&& Id
->DumpInfo
!= NULL
) {
851 return (Id
->DumpInfo(TheHandle
, Verbose
));
857 Function to get the Guid for a protocol or struct based on it's string name.
859 @param[in] Name The pointer to the string name.
860 @param[in] Lang The pointer to the language code.
861 @param[in] Guid The pointer to the Guid.
863 @retval EFI_SUCCESS The operation was sucessful.
867 GetGuidFromStringName(
868 IN CONST CHAR16
*Name
,
869 IN CONST CHAR8
*Lang OPTIONAL
,
873 CONST GUID_INFO_BLOCK
*ListWalker
;
876 ASSERT(Guid
!= NULL
);
878 return (EFI_INVALID_PARAMETER
);
882 if (PcdGetBool(PcdShellIncludeNtGuids
)) {
883 for (ListWalker
= mGuidStringListNT
; ListWalker
!= NULL
&& ListWalker
->GuidId
!= NULL
; ListWalker
++) {
884 String
= HiiGetString(mHandleParsingHiiHandle
, ListWalker
->StringId
, Lang
);
885 if (Name
!= NULL
&& String
!= NULL
&& StringNoCaseCompare (&Name
, &String
) == 0) {
886 *Guid
= ListWalker
->GuidId
;
888 SHELL_FREE_NON_NULL(String
);
890 return (EFI_SUCCESS
);
894 for (ListWalker
= mGuidStringList
; ListWalker
!= NULL
&& ListWalker
->GuidId
!= NULL
; ListWalker
++) {
895 String
= HiiGetString(mHandleParsingHiiHandle
, ListWalker
->StringId
, Lang
);
896 if (Name
!= NULL
&& String
!= NULL
&& StringNoCaseCompare (&Name
, &String
) == 0) {
897 *Guid
= ListWalker
->GuidId
;
899 SHELL_FREE_NON_NULL(String
);
901 return (EFI_SUCCESS
);
904 return (EFI_NOT_FOUND
);
908 Get best support language for this driver.
910 First base on the user input language to search, second base on the current
911 platform used language to search, third get the first language from the
912 support language list. The caller need to free the buffer of the best language.
914 @param[in] SupportedLanguages The support languages for this driver.
915 @param[in] InputLanguage The user input language.
916 @param[in] Iso639Language Whether get language for ISO639.
918 @return The best support language for this driver.
922 GetBestLanguageForDriver (
923 IN CONST CHAR8
*SupportedLanguages
,
924 IN CONST CHAR8
*InputLanguage
,
925 IN BOOLEAN Iso639Language
928 CHAR8
*LanguageVariable
;
931 LanguageVariable
= GetVariable (Iso639Language
? L
"Lang" : L
"PlatformLang", &gEfiGlobalVariableGuid
);
933 BestLanguage
= GetBestLanguage(
936 (InputLanguage
!= NULL
) ? InputLanguage
: "",
937 (LanguageVariable
!= NULL
) ? LanguageVariable
: "",
942 if (LanguageVariable
!= NULL
) {
943 FreePool (LanguageVariable
);
950 Function to retrieve the driver name (if possible) from the ComponentName or
951 ComponentName2 protocol
953 @param[in] TheHandle The driver handle to get the name of.
954 @param[in] Language The language to use.
956 @retval NULL The name could not be found.
957 @return A pointer to the string name. Do not de-allocate the memory.
961 GetStringNameFromHandle(
962 IN CONST EFI_HANDLE TheHandle
,
963 IN CONST CHAR8
*Language
966 EFI_COMPONENT_NAME2_PROTOCOL
*CompNameStruct
;
973 Status
= gBS
->OpenProtocol(
975 &gEfiComponentName2ProtocolGuid
,
976 (VOID
**)&CompNameStruct
,
979 EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
980 if (!EFI_ERROR(Status
)) {
981 BestLang
= GetBestLanguageForDriver (CompNameStruct
->SupportedLanguages
, Language
, FALSE
);
982 Status
= CompNameStruct
->GetDriverName(CompNameStruct
, BestLang
, &RetVal
);
983 if (BestLang
!= NULL
) {
987 if (!EFI_ERROR(Status
)) {
991 Status
= gBS
->OpenProtocol(
993 &gEfiComponentNameProtocolGuid
,
994 (VOID
**)&CompNameStruct
,
997 EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
998 if (!EFI_ERROR(Status
)) {
999 BestLang
= GetBestLanguageForDriver (CompNameStruct
->SupportedLanguages
, Language
, FALSE
);
1000 Status
= CompNameStruct
->GetDriverName(CompNameStruct
, BestLang
, &RetVal
);
1001 if (BestLang
!= NULL
) {
1002 FreePool (BestLang
);
1004 if (!EFI_ERROR(Status
)) {
1012 Function to initialize the file global mHandleList object for use in
1013 vonverting handles to index and index to handle.
1015 @retval EFI_SUCCESS The operation was successful.
1019 InternalShellInitHandleList(
1024 EFI_HANDLE
*HandleBuffer
;
1026 HANDLE_LIST
*ListWalker
;
1028 if (mHandleList
.NextIndex
!= 0) {
1031 InitializeListHead(&mHandleList
.List
.Link
);
1032 mHandleList
.NextIndex
= 1;
1033 Status
= gBS
->LocateHandleBuffer (
1040 ASSERT_EFI_ERROR(Status
);
1041 if (EFI_ERROR(Status
)) {
1044 for (mHandleList
.NextIndex
= 1 ; mHandleList
.NextIndex
<= HandleCount
; mHandleList
.NextIndex
++){
1045 ListWalker
= AllocateZeroPool(sizeof(HANDLE_LIST
));
1046 ASSERT(ListWalker
!= NULL
);
1047 ListWalker
->TheHandle
= HandleBuffer
[mHandleList
.NextIndex
-1];
1048 ListWalker
->TheIndex
= mHandleList
.NextIndex
;
1049 InsertTailList(&mHandleList
.List
.Link
,&ListWalker
->Link
);
1051 FreePool(HandleBuffer
);
1052 return (EFI_SUCCESS
);
1056 Function to retrieve the human-friendly index of a given handle. If the handle
1057 does not have a index one will be automatically assigned. The index value is valid
1058 until the termination of the shell application.
1060 @param[in] TheHandle The handle to retrieve an index for.
1062 @retval 0 A memory allocation failed.
1063 @return The index of the handle.
1068 ConvertHandleToHandleIndex(
1069 IN CONST EFI_HANDLE TheHandle
1073 EFI_GUID
**ProtocolBuffer
;
1074 UINTN ProtocolCount
;
1075 HANDLE_LIST
*ListWalker
;
1077 if (TheHandle
== NULL
) {
1081 InternalShellInitHandleList();
1083 for (ListWalker
= (HANDLE_LIST
*)GetFirstNode(&mHandleList
.List
.Link
)
1084 ; !IsNull(&mHandleList
.List
.Link
,&ListWalker
->Link
)
1085 ; ListWalker
= (HANDLE_LIST
*)GetNextNode(&mHandleList
.List
.Link
,&ListWalker
->Link
)
1087 if (ListWalker
->TheHandle
== TheHandle
) {
1089 // Verify that TheHandle is still present in the Handle Database
1091 Status
= gBS
->ProtocolsPerHandle(TheHandle
, &ProtocolBuffer
, &ProtocolCount
);
1092 if (EFI_ERROR (Status
)) {
1094 // TheHandle is not present in the Handle Database, so delete from the handle list
1096 RemoveEntryList (&ListWalker
->Link
);
1099 FreePool (ProtocolBuffer
);
1100 return (ListWalker
->TheIndex
);
1105 // Verify that TheHandle is valid handle
1107 Status
= gBS
->ProtocolsPerHandle(TheHandle
, &ProtocolBuffer
, &ProtocolCount
);
1108 if (EFI_ERROR (Status
)) {
1110 // TheHandle is not valid, so do not add to handle list
1114 FreePool (ProtocolBuffer
);
1116 ListWalker
= AllocateZeroPool(sizeof(HANDLE_LIST
));
1117 ASSERT(ListWalker
!= NULL
);
1118 ListWalker
->TheHandle
= TheHandle
;
1119 ListWalker
->TheIndex
= mHandleList
.NextIndex
++;
1120 InsertTailList(&mHandleList
.List
.Link
,&ListWalker
->Link
);
1121 return (ListWalker
->TheIndex
);
1127 Function to retrieve the EFI_HANDLE from the human-friendly index.
1129 @param[in] TheIndex The index to retrieve the EFI_HANDLE for.
1131 @retval NULL The index was invalid.
1132 @return The EFI_HANDLE that index represents.
1137 ConvertHandleIndexToHandle(
1138 IN CONST UINTN TheIndex
1142 EFI_GUID
**ProtocolBuffer
;
1143 UINTN ProtocolCount
;
1144 HANDLE_LIST
*ListWalker
;
1146 InternalShellInitHandleList();
1148 if (TheIndex
>= mHandleList
.NextIndex
) {
1152 for (ListWalker
= (HANDLE_LIST
*)GetFirstNode(&mHandleList
.List
.Link
)
1153 ; !IsNull(&mHandleList
.List
.Link
,&ListWalker
->Link
)
1154 ; ListWalker
= (HANDLE_LIST
*)GetNextNode(&mHandleList
.List
.Link
,&ListWalker
->Link
)
1156 if (ListWalker
->TheIndex
== TheIndex
&& ListWalker
->TheHandle
!= NULL
) {
1158 // Verify that LinkWalker->TheHandle is valid handle
1160 Status
= gBS
->ProtocolsPerHandle(ListWalker
->TheHandle
, &ProtocolBuffer
, &ProtocolCount
);
1161 if (EFI_ERROR (Status
)) {
1163 // TheHandle is not valid, so do not add to handle list
1165 ListWalker
->TheHandle
= NULL
;
1167 return (ListWalker
->TheHandle
);
1174 Gets all the related EFI_HANDLEs based on the mask supplied.
1176 This function scans all EFI_HANDLES in the UEFI environment's handle database
1177 and returns the ones with the specified relationship (Mask) to the specified
1180 If both DriverBindingHandle and ControllerHandle are NULL, then ASSERT.
1181 If MatchingHandleCount is NULL, then ASSERT.
1183 If MatchingHandleBuffer is not NULL upon a successful return the memory must be
1186 @param[in] DriverBindingHandle The handle with Driver Binding protocol on it.
1187 @param[in] ControllerHandle The handle with Device Path protocol on it.
1188 @param[in] MatchingHandleCount The pointer to UINTN that specifies the number of HANDLES in
1189 MatchingHandleBuffer.
1190 @param[out] MatchingHandleBuffer On a successful return, a buffer of MatchingHandleCount
1191 EFI_HANDLEs with a terminating NULL EFI_HANDLE.
1192 @param[out] HandleType An array of type information.
1194 @retval EFI_SUCCESS The operation was successful, and any related handles
1195 are in MatchingHandleBuffer.
1196 @retval EFI_NOT_FOUND No matching handles were found.
1197 @retval EFI_INVALID_PARAMETER A parameter was invalid or out of range.
1201 ParseHandleDatabaseByRelationshipWithType (
1202 IN CONST EFI_HANDLE DriverBindingHandle OPTIONAL
,
1203 IN CONST EFI_HANDLE ControllerHandle OPTIONAL
,
1204 IN UINTN
*HandleCount
,
1205 OUT EFI_HANDLE
**HandleBuffer
,
1206 OUT UINTN
**HandleType
1211 EFI_GUID
**ProtocolGuidArray
;
1213 UINTN ProtocolIndex
;
1214 EFI_OPEN_PROTOCOL_INFORMATION_ENTRY
*OpenInfo
;
1215 UINTN OpenInfoCount
;
1216 UINTN OpenInfoIndex
;
1218 INTN DriverBindingHandleIndex
;
1220 ASSERT(HandleCount
!= NULL
);
1221 ASSERT(HandleBuffer
!= NULL
);
1222 ASSERT(HandleType
!= NULL
);
1223 ASSERT(DriverBindingHandle
!= NULL
|| ControllerHandle
!= NULL
);
1226 *HandleBuffer
= NULL
;
1230 // Retrieve the list of all handles from the handle database
1232 Status
= gBS
->LocateHandleBuffer (
1239 if (EFI_ERROR (Status
)) {
1243 *HandleType
= AllocateZeroPool (*HandleCount
* sizeof (UINTN
));
1244 ASSERT(*HandleType
!= NULL
);
1246 DriverBindingHandleIndex
= -1;
1247 for (HandleIndex
= 0; HandleIndex
< *HandleCount
; HandleIndex
++) {
1248 if (DriverBindingHandle
!= NULL
&& (*HandleBuffer
)[HandleIndex
] == DriverBindingHandle
) {
1249 DriverBindingHandleIndex
= (INTN
)HandleIndex
;
1253 for (HandleIndex
= 0; HandleIndex
< *HandleCount
; HandleIndex
++) {
1255 // Retrieve the list of all the protocols on each handle
1257 Status
= gBS
->ProtocolsPerHandle (
1258 (*HandleBuffer
)[HandleIndex
],
1262 if (EFI_ERROR (Status
)) {
1266 for (ProtocolIndex
= 0; ProtocolIndex
< ArrayCount
; ProtocolIndex
++) {
1269 // Set the bit describing what this handle has
1271 if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiLoadedImageProtocolGuid
) ) {
1272 (*HandleType
)[HandleIndex
] |= HR_IMAGE_HANDLE
;
1273 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiDriverBindingProtocolGuid
) ) {
1274 (*HandleType
)[HandleIndex
] |= HR_DRIVER_BINDING_HANDLE
;
1275 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiDriverConfiguration2ProtocolGuid
)) {
1276 (*HandleType
)[HandleIndex
] |= HR_DRIVER_CONFIGURATION_HANDLE
;
1277 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiDriverConfigurationProtocolGuid
) ) {
1278 (*HandleType
)[HandleIndex
] |= HR_DRIVER_CONFIGURATION_HANDLE
;
1279 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiDriverDiagnostics2ProtocolGuid
) ) {
1280 (*HandleType
)[HandleIndex
] |= HR_DRIVER_DIAGNOSTICS_HANDLE
;
1281 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiDriverDiagnosticsProtocolGuid
) ) {
1282 (*HandleType
)[HandleIndex
] |= HR_DRIVER_DIAGNOSTICS_HANDLE
;
1283 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiComponentName2ProtocolGuid
) ) {
1284 (*HandleType
)[HandleIndex
] |= HR_COMPONENT_NAME_HANDLE
;
1285 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiComponentNameProtocolGuid
) ) {
1286 (*HandleType
)[HandleIndex
] |= HR_COMPONENT_NAME_HANDLE
;
1287 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiDevicePathProtocolGuid
) ) {
1288 (*HandleType
)[HandleIndex
] |= HR_DEVICE_HANDLE
;
1291 ASSERT((*HandleType
)[HandleIndex
] == (*HandleType
)[HandleIndex
]);
1295 // Retrieve the list of agents that have opened each protocol
1297 Status
= gBS
->OpenProtocolInformation (
1298 (*HandleBuffer
)[HandleIndex
],
1299 ProtocolGuidArray
[ProtocolIndex
],
1303 if (EFI_ERROR (Status
)) {
1307 if (ControllerHandle
== NULL
) {
1309 // ControllerHandle == NULL and DriverBindingHandle != NULL.
1310 // Return information on all the controller handles that the driver specified by DriverBindingHandle is managing
1312 for (OpenInfoIndex
= 0; OpenInfoIndex
< OpenInfoCount
; OpenInfoIndex
++) {
1313 if (OpenInfo
[OpenInfoIndex
].AgentHandle
== DriverBindingHandle
&& (OpenInfo
[OpenInfoIndex
].Attributes
& EFI_OPEN_PROTOCOL_BY_DRIVER
) != 0) {
1314 (*HandleType
)[HandleIndex
] |= (HR_DEVICE_HANDLE
| HR_CONTROLLER_HANDLE
);
1315 if (DriverBindingHandleIndex
!= -1) {
1316 (*HandleType
)[DriverBindingHandleIndex
] |= HR_DEVICE_DRIVER
;
1319 if (OpenInfo
[OpenInfoIndex
].AgentHandle
== DriverBindingHandle
&& (OpenInfo
[OpenInfoIndex
].Attributes
& EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
) != 0) {
1320 (*HandleType
)[HandleIndex
] |= (HR_DEVICE_HANDLE
| HR_CONTROLLER_HANDLE
);
1321 if (DriverBindingHandleIndex
!= -1) {
1322 (*HandleType
)[DriverBindingHandleIndex
] |= (HR_BUS_DRIVER
| HR_DEVICE_DRIVER
);
1324 for (ChildIndex
= 0; ChildIndex
< *HandleCount
; ChildIndex
++) {
1325 if (OpenInfo
[OpenInfoIndex
].ControllerHandle
== (*HandleBuffer
)[ChildIndex
]) {
1326 (*HandleType
)[ChildIndex
] |= (HR_DEVICE_HANDLE
| HR_CHILD_HANDLE
);
1332 if (DriverBindingHandle
== NULL
&& ControllerHandle
!= NULL
) {
1333 if (ControllerHandle
== (*HandleBuffer
)[HandleIndex
]) {
1334 (*HandleType
)[HandleIndex
] |= (HR_DEVICE_HANDLE
| HR_CONTROLLER_HANDLE
);
1335 for (OpenInfoIndex
= 0; OpenInfoIndex
< OpenInfoCount
; OpenInfoIndex
++) {
1336 if ((OpenInfo
[OpenInfoIndex
].Attributes
& EFI_OPEN_PROTOCOL_BY_DRIVER
) != 0) {
1337 for (ChildIndex
= 0; ChildIndex
< *HandleCount
; ChildIndex
++) {
1338 if (OpenInfo
[OpenInfoIndex
].AgentHandle
== (*HandleBuffer
)[ChildIndex
]) {
1339 (*HandleType
)[ChildIndex
] |= HR_DEVICE_DRIVER
;
1343 if ((OpenInfo
[OpenInfoIndex
].Attributes
& EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
) != 0) {
1344 for (ChildIndex
= 0; ChildIndex
< *HandleCount
; ChildIndex
++) {
1345 if (OpenInfo
[OpenInfoIndex
].AgentHandle
== (*HandleBuffer
)[ChildIndex
]) {
1346 (*HandleType
)[ChildIndex
] |= (HR_BUS_DRIVER
| HR_DEVICE_DRIVER
);
1348 if (OpenInfo
[OpenInfoIndex
].ControllerHandle
== (*HandleBuffer
)[ChildIndex
]) {
1349 (*HandleType
)[ChildIndex
] |= (HR_DEVICE_HANDLE
| HR_CHILD_HANDLE
);
1355 for (OpenInfoIndex
= 0; OpenInfoIndex
< OpenInfoCount
; OpenInfoIndex
++) {
1356 if ((OpenInfo
[OpenInfoIndex
].Attributes
& EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
) != 0) {
1357 if (OpenInfo
[OpenInfoIndex
].ControllerHandle
== ControllerHandle
) {
1358 (*HandleType
)[HandleIndex
] |= (HR_DEVICE_HANDLE
| HR_PARENT_HANDLE
);
1364 if (DriverBindingHandle
!= NULL
&& ControllerHandle
!= NULL
) {
1365 if (ControllerHandle
== (*HandleBuffer
)[HandleIndex
]) {
1366 (*HandleType
)[HandleIndex
] |= (HR_DEVICE_HANDLE
| HR_CONTROLLER_HANDLE
);
1367 for (OpenInfoIndex
= 0; OpenInfoIndex
< OpenInfoCount
; OpenInfoIndex
++) {
1368 if ((OpenInfo
[OpenInfoIndex
].Attributes
& EFI_OPEN_PROTOCOL_BY_DRIVER
) != 0) {
1369 if (OpenInfo
[OpenInfoIndex
].AgentHandle
== DriverBindingHandle
) {
1370 if (DriverBindingHandleIndex
!= -1) {
1371 (*HandleType
)[DriverBindingHandleIndex
] |= HR_DEVICE_DRIVER
;
1375 if ((OpenInfo
[OpenInfoIndex
].Attributes
& EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
) != 0) {
1376 if (OpenInfo
[OpenInfoIndex
].AgentHandle
== DriverBindingHandle
) {
1377 for (ChildIndex
= 0; ChildIndex
< *HandleCount
; ChildIndex
++) {
1378 if (OpenInfo
[OpenInfoIndex
].ControllerHandle
== (*HandleBuffer
)[ChildIndex
]) {
1379 (*HandleType
)[ChildIndex
] |= (HR_DEVICE_HANDLE
| HR_CHILD_HANDLE
);
1384 for (ChildIndex
= 0; ChildIndex
< *HandleCount
; ChildIndex
++) {
1385 if (OpenInfo
[OpenInfoIndex
].AgentHandle
== (*HandleBuffer
)[ChildIndex
]) {
1386 (*HandleType
)[ChildIndex
] |= (HR_BUS_DRIVER
| HR_DEVICE_DRIVER
);
1392 for (OpenInfoIndex
= 0; OpenInfoIndex
< OpenInfoCount
; OpenInfoIndex
++) {
1393 if ((OpenInfo
[OpenInfoIndex
].Attributes
& EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
) != 0) {
1394 if (OpenInfo
[OpenInfoIndex
].ControllerHandle
== ControllerHandle
) {
1395 (*HandleType
)[HandleIndex
] |= (HR_DEVICE_HANDLE
| HR_PARENT_HANDLE
);
1401 FreePool (OpenInfo
);
1403 FreePool (ProtocolGuidArray
);
1409 Gets all the related EFI_HANDLEs based on the single EFI_HANDLE and the mask
1412 This function will scan all EFI_HANDLES in the UEFI environment's handle database
1413 and return all the ones with the specified relationship (Mask) to the specified
1416 If both DriverBindingHandle and ControllerHandle are NULL, then ASSERT.
1417 If MatchingHandleCount is NULL, then ASSERT.
1419 If MatchingHandleBuffer is not NULL upon a sucessful return the memory must be
1422 @param[in] DriverBindingHandle Handle to a object with Driver Binding protocol
1424 @param[in] ControllerHandle Handle to a device with Device Path protocol on it.
1425 @param[in] Mask Mask of what relationship(s) is desired.
1426 @param[in] MatchingHandleCount Poitner to UINTN specifying number of HANDLES in
1427 MatchingHandleBuffer.
1428 @param[out] MatchingHandleBuffer On a sucessful return a buffer of MatchingHandleCount
1429 EFI_HANDLEs and a terminating NULL EFI_HANDLE.
1431 @retval EFI_SUCCESS The operation was sucessful and any related handles
1432 are in MatchingHandleBuffer;
1433 @retval EFI_NOT_FOUND No matching handles were found.
1434 @retval EFI_INVALID_PARAMETER A parameter was invalid or out of range.
1438 ParseHandleDatabaseByRelationship (
1439 IN CONST EFI_HANDLE DriverBindingHandle OPTIONAL
,
1440 IN CONST EFI_HANDLE ControllerHandle OPTIONAL
,
1441 IN CONST UINTN Mask
,
1442 IN UINTN
*MatchingHandleCount
,
1443 OUT EFI_HANDLE
**MatchingHandleBuffer OPTIONAL
1448 EFI_HANDLE
*HandleBuffer
;
1452 ASSERT(MatchingHandleCount
!= NULL
);
1453 ASSERT(DriverBindingHandle
!= NULL
|| ControllerHandle
!= NULL
);
1455 if ((Mask
& HR_VALID_MASK
) != Mask
) {
1456 return (EFI_INVALID_PARAMETER
);
1459 if ((Mask
& HR_CHILD_HANDLE
) != 0 && DriverBindingHandle
== NULL
) {
1460 return (EFI_INVALID_PARAMETER
);
1463 *MatchingHandleCount
= 0;
1464 if (MatchingHandleBuffer
!= NULL
) {
1465 *MatchingHandleBuffer
= NULL
;
1468 HandleBuffer
= NULL
;
1471 Status
= ParseHandleDatabaseByRelationshipWithType (
1472 DriverBindingHandle
,
1478 if (!EFI_ERROR (Status
)) {
1480 // Count the number of handles that match the attributes in Mask
1482 for (HandleIndex
= 0; HandleIndex
< HandleCount
; HandleIndex
++) {
1483 if ((HandleType
[HandleIndex
] & Mask
) == Mask
) {
1484 (*MatchingHandleCount
)++;
1488 // If no handles match the attributes in Mask then return EFI_NOT_FOUND
1490 if (*MatchingHandleCount
== 0) {
1491 Status
= EFI_NOT_FOUND
;
1494 if (MatchingHandleBuffer
== NULL
) {
1496 // Someone just wanted the count...
1498 Status
= EFI_SUCCESS
;
1501 // Allocate a handle buffer for the number of handles that matched the attributes in Mask
1503 *MatchingHandleBuffer
= AllocateZeroPool ((*MatchingHandleCount
+1)* sizeof (EFI_HANDLE
));
1504 ASSERT(*MatchingHandleBuffer
!= NULL
);
1506 for (HandleIndex
= 0,*MatchingHandleCount
= 0
1507 ; HandleIndex
< HandleCount
1511 // Fill the allocated buffer with the handles that matched the attributes in Mask
1513 if ((HandleType
[HandleIndex
] & Mask
) == Mask
) {
1514 (*MatchingHandleBuffer
)[(*MatchingHandleCount
)++] = HandleBuffer
[HandleIndex
];
1519 // Make the last one NULL
1521 (*MatchingHandleBuffer
)[*MatchingHandleCount
] = NULL
;
1523 Status
= EFI_SUCCESS
;
1524 } // MacthingHandleBuffer == NULL (ELSE)
1525 } // *MatchingHandleCount == 0 (ELSE)
1526 } // no error on ParseHandleDatabaseByRelationshipWithType
1528 if (HandleBuffer
!= NULL
) {
1529 FreePool (HandleBuffer
);
1532 if (HandleType
!= NULL
) {
1533 FreePool (HandleType
);
1540 Gets handles for any child controllers of the passed in controller.
1542 @param[in] ControllerHandle The handle of the "parent controller"
1543 @param[in] MatchingHandleCount Pointer to the number of handles in
1544 MatchingHandleBuffer on return.
1545 @param[out] MatchingHandleBuffer Buffer containing handles on a successful
1549 @retval EFI_SUCCESS The operation was sucessful.
1553 ParseHandleDatabaseForChildControllers(
1554 IN CONST EFI_HANDLE ControllerHandle
,
1555 IN UINTN
*MatchingHandleCount
,
1556 OUT EFI_HANDLE
**MatchingHandleBuffer OPTIONAL
1561 UINTN DriverBindingHandleCount
;
1562 EFI_HANDLE
*DriverBindingHandleBuffer
;
1563 UINTN DriverBindingHandleIndex
;
1564 UINTN ChildControllerHandleCount
;
1565 EFI_HANDLE
*ChildControllerHandleBuffer
;
1566 UINTN ChildControllerHandleIndex
;
1567 EFI_HANDLE
*HandleBufferForReturn
;
1569 if (MatchingHandleCount
== NULL
) {
1570 return (EFI_INVALID_PARAMETER
);
1572 *MatchingHandleCount
= 0;
1574 Status
= PARSE_HANDLE_DATABASE_UEFI_DRIVERS (
1576 &DriverBindingHandleCount
,
1577 &DriverBindingHandleBuffer
1579 if (EFI_ERROR (Status
)) {
1584 // Get a buffer big enough for all the controllers.
1586 HandleBufferForReturn
= GetHandleListByProtocol(NULL
);
1587 if (HandleBufferForReturn
== NULL
) {
1588 FreePool (DriverBindingHandleBuffer
);
1589 return (EFI_NOT_FOUND
);
1592 for (DriverBindingHandleIndex
= 0; DriverBindingHandleIndex
< DriverBindingHandleCount
; DriverBindingHandleIndex
++) {
1593 Status
= PARSE_HANDLE_DATABASE_MANAGED_CHILDREN (
1594 DriverBindingHandleBuffer
[DriverBindingHandleIndex
],
1596 &ChildControllerHandleCount
,
1597 &ChildControllerHandleBuffer
1599 if (EFI_ERROR (Status
)) {
1603 for (ChildControllerHandleIndex
= 0;
1604 ChildControllerHandleIndex
< ChildControllerHandleCount
;
1605 ChildControllerHandleIndex
++
1607 for (HandleIndex
= 0; HandleIndex
< *MatchingHandleCount
; HandleIndex
++) {
1608 if (HandleBufferForReturn
[HandleIndex
] == ChildControllerHandleBuffer
[ChildControllerHandleIndex
]) {
1612 if (HandleIndex
>= *MatchingHandleCount
) {
1613 HandleBufferForReturn
[(*MatchingHandleCount
)++] = ChildControllerHandleBuffer
[ChildControllerHandleIndex
];
1617 FreePool (ChildControllerHandleBuffer
);
1620 FreePool (DriverBindingHandleBuffer
);
1622 if (MatchingHandleBuffer
!= NULL
) {
1623 *MatchingHandleBuffer
= HandleBufferForReturn
;
1625 FreePool(HandleBufferForReturn
);
1628 return (EFI_SUCCESS
);
1632 Appends 1 buffer to another buffer. This will re-allocate the destination buffer
1633 if necessary to fit all of the data.
1635 If DestinationBuffer is NULL, then ASSERT().
1637 @param[in, out] DestinationBuffer The pointer to the pointer to the buffer to append onto.
1638 @param[in, out] DestinationSize The pointer to the size of DestinationBuffer.
1639 @param[in] SourceBuffer The pointer to the buffer to append onto DestinationBuffer.
1640 @param[in] SourceSize The number of bytes of SourceBuffer to append.
1642 @retval NULL A memory allocation failed.
1643 @retval NULL A parameter was invalid.
1644 @return A pointer to (*DestinationBuffer).
1649 IN OUT VOID
**DestinationBuffer
,
1650 IN OUT UINTN
*DestinationSize
,
1651 IN VOID
*SourceBuffer
,
1655 UINTN LocalDestinationSize
;
1656 UINTN LocalDestinationFinalSize
;
1658 ASSERT(DestinationBuffer
!= NULL
);
1660 if (SourceSize
== 0 || SourceBuffer
== NULL
) {
1661 return (*DestinationBuffer
);
1664 if (DestinationSize
== NULL
) {
1665 LocalDestinationSize
= 0;
1667 LocalDestinationSize
= *DestinationSize
;
1670 LocalDestinationFinalSize
= LocalDestinationSize
+ SourceSize
;
1672 if (DestinationSize
!= NULL
) {
1673 *DestinationSize
= LocalDestinationSize
;
1676 if (LocalDestinationSize
== 0) {
1678 *DestinationBuffer
= AllocateZeroPool(LocalDestinationFinalSize
);
1681 *DestinationBuffer
= ReallocatePool(LocalDestinationSize
, LocalDestinationFinalSize
, *DestinationBuffer
);
1684 ASSERT(*DestinationBuffer
!= NULL
);
1687 return (CopyMem(((UINT8
*)(*DestinationBuffer
)) + LocalDestinationSize
, SourceBuffer
, SourceSize
));
1691 Gets handles for any child devices produced by the passed in driver.
1693 @param[in] DriverHandle The handle of the driver.
1694 @param[in] MatchingHandleCount Pointer to the number of handles in
1695 MatchingHandleBuffer on return.
1696 @param[out] MatchingHandleBuffer Buffer containing handles on a successful
1698 @retval EFI_SUCCESS The operation was sucessful.
1699 @sa ParseHandleDatabaseByRelationship
1703 ParseHandleDatabaseForChildDevices(
1704 IN CONST EFI_HANDLE DriverHandle
,
1705 IN UINTN
*MatchingHandleCount
,
1706 OUT EFI_HANDLE
**MatchingHandleBuffer OPTIONAL
1710 EFI_HANDLE
*Buffer2
;
1715 UINTN HandleBufferSize
;
1717 ASSERT(MatchingHandleCount
!= NULL
);
1719 HandleBufferSize
= 0;
1722 *MatchingHandleCount
= 0;
1724 Status
= PARSE_HANDLE_DATABASE_DEVICES (
1729 if (!EFI_ERROR (Status
)) {
1730 for (HandleIndex
= 0; HandleIndex
< Count1
; HandleIndex
++) {
1732 // now find the children
1734 Status
= PARSE_HANDLE_DATABASE_MANAGED_CHILDREN (
1736 Buffer
[HandleIndex
],
1740 if (EFI_ERROR(Status
)) {
1744 // save out required and optional data elements
1746 *MatchingHandleCount
+= Count2
;
1747 if (MatchingHandleBuffer
!= NULL
) {
1748 *MatchingHandleBuffer
= BuffernCatGrow((VOID
**)MatchingHandleBuffer
, &HandleBufferSize
, Buffer2
, Count2
* sizeof(Buffer2
[0]));
1754 if (Buffer2
!= NULL
) {
1760 if (Buffer
!= NULL
) {
1767 Function to get all handles that support a given protocol or all handles.
1769 @param[in] ProtocolGuid The guid of the protocol to get handles for. If NULL
1770 then the function will return all handles.
1772 @retval NULL A memory allocation failed.
1773 @return A NULL terminated list of handles.
1777 GetHandleListByProtocol (
1778 IN CONST EFI_GUID
*ProtocolGuid OPTIONAL
1781 EFI_HANDLE
*HandleList
;
1789 // We cannot use LocateHandleBuffer since we need that NULL item on the ends of the list!
1791 if (ProtocolGuid
== NULL
) {
1792 Status
= gBS
->LocateHandle(AllHandles
, NULL
, NULL
, &Size
, HandleList
);
1793 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1794 HandleList
= AllocateZeroPool(Size
+ sizeof(EFI_HANDLE
));
1795 if (HandleList
== NULL
) {
1798 Status
= gBS
->LocateHandle(AllHandles
, NULL
, NULL
, &Size
, HandleList
);
1799 HandleList
[Size
/sizeof(EFI_HANDLE
)] = NULL
;
1802 Status
= gBS
->LocateHandle(ByProtocol
, (EFI_GUID
*)ProtocolGuid
, NULL
, &Size
, HandleList
);
1803 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1804 HandleList
= AllocateZeroPool(Size
+ sizeof(EFI_HANDLE
));
1805 if (HandleList
== NULL
) {
1808 Status
= gBS
->LocateHandle(ByProtocol
, (EFI_GUID
*)ProtocolGuid
, NULL
, &Size
, HandleList
);
1809 HandleList
[Size
/sizeof(EFI_HANDLE
)] = NULL
;
1812 if (EFI_ERROR(Status
)) {
1813 if (HandleList
!= NULL
) {
1814 FreePool(HandleList
);
1818 return (HandleList
);
1822 Function to get all handles that support some protocols.
1824 @param[in] ProtocolGuids A NULL terminated list of protocol GUIDs.
1826 @retval NULL A memory allocation failed.
1827 @retval NULL ProtocolGuids was NULL.
1828 @return A NULL terminated list of EFI_HANDLEs.
1832 GetHandleListByProtocolList (
1833 IN CONST EFI_GUID
**ProtocolGuids
1836 EFI_HANDLE
*HandleList
;
1841 CONST EFI_GUID
**GuidWalker
;
1842 EFI_HANDLE
*HandleWalker1
;
1843 EFI_HANDLE
*HandleWalker2
;
1847 TotalSize
= sizeof(EFI_HANDLE
);
1849 for (GuidWalker
= ProtocolGuids
; GuidWalker
!= NULL
&& *GuidWalker
!= NULL
; GuidWalker
++,Size
= 0){
1850 Status
= gBS
->LocateHandle(ByProtocol
, (EFI_GUID
*)(*GuidWalker
), NULL
, &Size
, NULL
);
1851 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1857 // No handles were found...
1859 if (TotalSize
== sizeof(EFI_HANDLE
)) {
1863 HandleList
= AllocateZeroPool(TotalSize
);
1864 if (HandleList
== NULL
) {
1869 for (GuidWalker
= ProtocolGuids
; GuidWalker
!= NULL
&& *GuidWalker
!= NULL
; GuidWalker
++){
1870 TempSize
= TotalSize
- Size
;
1871 Status
= gBS
->LocateHandle(ByProtocol
, (EFI_GUID
*)(*GuidWalker
), NULL
, &TempSize
, HandleList
+(Size
/sizeof(EFI_HANDLE
)));
1874 // Allow for missing protocols... Only update the 'used' size upon success.
1876 if (!EFI_ERROR(Status
)) {
1880 ASSERT(HandleList
[(TotalSize
/sizeof(EFI_HANDLE
))-1] == NULL
);
1882 for (HandleWalker1
= HandleList
; HandleWalker1
!= NULL
&& *HandleWalker1
!= NULL
; HandleWalker1
++) {
1883 for (HandleWalker2
= HandleWalker1
+ 1; HandleWalker2
!= NULL
&& *HandleWalker2
!= NULL
; HandleWalker2
++) {
1884 if (*HandleWalker1
== *HandleWalker2
) {
1886 // copy memory back 1 handle width.
1888 CopyMem(HandleWalker2
, HandleWalker2
+ 1, TotalSize
- ((HandleWalker2
-HandleList
+1)*sizeof(EFI_HANDLE
)));
1893 return (HandleList
);