2 Provides interface to advanced shell functionality for parsing both handle and protocol database.
4 Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "UefiHandleParsingLib.h"
18 STATIC CONST EFI_GUID mHandleParsingHiiGuid
= \
20 0xb8969637, 0x81de, 0x43af, { 0xbc, 0x9a, 0x24, 0xd9, 0x89, 0x13, 0xf2, 0xf6 } \
22 EFI_HANDLE mHandleParsingHiiHandle
;
23 HANDLE_INDEX_LIST mHandleList
= {{{NULL
,NULL
},0,0},0};
26 Constructor for the library.
28 @param[in] ImageHandle Ignored.
29 @param[in] SystemTable Ignored.
31 @retval EFI_SUCCESS The operation was successful.
35 HandleParsingLibConstructor (
36 IN EFI_HANDLE ImageHandle
,
37 IN EFI_SYSTEM_TABLE
*SystemTable
40 mHandleParsingHiiHandle
= HiiAddPackages (&mHandleParsingHiiGuid
, gImageHandle
, UefiHandleParsingLibStrings
, NULL
);
41 if (mHandleParsingHiiHandle
== NULL
) {
42 return (EFI_DEVICE_ERROR
);
49 Destructor for the library. free any resources.
51 @param[in] ImageHandle Ignored.
52 @param[in] SystemTable Ignored.
54 @retval EFI_SUCCESS The operation was successful.
58 HandleParsingLibDestructor (
59 IN EFI_HANDLE ImageHandle
,
60 IN EFI_SYSTEM_TABLE
*SystemTable
63 if (mHandleParsingHiiHandle
!= NULL
) {
64 HiiRemovePackages(mHandleParsingHiiHandle
);
72 LoadedImageProtocolDumpInformation(
73 IN CONST EFI_HANDLE TheHandle,
74 IN CONST BOOLEAN Verbose
77 EFI_LOADED_IMAGE_PROTOCOL *Image;
79 EFI_DEVICE_PATH_PROTOCOL *DevPath;
80 EFI_DEVICE_PATH_PROTOCOL *DevPathNode;
83 UINT32 AuthenticationStatus;
85 EFI_FIRMWARE_VOLUME_PROTOCOL *FV;
86 EFI_FIRMWARE_VOLUME2_PROTOCOL *FV2;
93 Status = HandleProtocol (
95 &gEfiLoadedImageProtocolGuid,
97 ASSERT_EFI_ERROR(Status);
99 DevPath = UnpackDevicePath (Image->FilePath);
101 if (DevPath == NULL) {
105 DevPathNode = DevPath;
107 while (!IsDevicePathEnd (DevPathNode)) {
109 // Find the Fv File path
111 NameGuid = GetNameGuidFromFwVolDevicePathNode ((MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *)DevPathNode);
112 if (NameGuid != NULL) {
113 Status = BS->HandleProtocol (
115 &gEfiFirmwareVolumeProtocolGuid,
118 if (!EFI_ERROR (Status)) {
119 Status = FV->ReadSection (
122 EFI_SECTION_USER_INTERFACE,
126 &AuthenticationStatus
128 if (!EFI_ERROR (Status)) {
134 Status = BS->HandleProtocol (
136 &gEfiFirmwareVolume2ProtocolGuid,
139 if (!EFI_ERROR (Status)) {
140 Status = FV2->ReadSection (
143 EFI_SECTION_USER_INTERFACE,
147 &AuthenticationStatus
149 if (!EFI_ERROR (Status)) {
158 // Next device path node
160 DevPathNode = NextDevicePathNode (DevPathNode);
169 Function to dump information about SimpleTextOut.
171 This will allocate the return buffer from boot services pool.
173 @param[in] TheHandle The handle that has SimpleTextOut installed.
174 @param[in] Verbose TRUE for additional information, FALSE otherwise.
176 @retval A poitner to a string containing the information.
180 TxtOutProtocolDumpInformation(
181 IN CONST EFI_HANDLE TheHandle
,
182 IN CONST BOOLEAN Verbose
185 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*Dev
;
202 Status
= gBS
->HandleProtocol(
204 &gEfiSimpleTextOutProtocolGuid
,
207 ASSERT_EFI_ERROR(Status
);
208 ASSERT (Dev
!= NULL
&& Dev
->Mode
!= NULL
);
210 Size
= (Dev
->Mode
->MaxMode
+ 1) * 80;
211 RetVal
= AllocateZeroPool(Size
);
213 Temp
= HiiGetString(mHandleParsingHiiHandle
, STRING_TOKEN(STR_TXT_OUT_DUMP_HEADER
), NULL
);
214 UnicodeSPrint(RetVal
, Size
, Temp
, Dev
, Dev
->Mode
->Attribute
);
220 Temp
= HiiGetString(mHandleParsingHiiHandle
, STRING_TOKEN(STR_TXT_OUT_DUMP_LINE
), NULL
);
221 for (Index
= 0; Index
< Dev
->Mode
->MaxMode
; Index
++) {
222 Status
= Dev
->QueryMode (Dev
, Index
, &Col
, &Row
);
223 NewSize
= Size
- StrSize(RetVal
);
225 RetVal
+ StrLen(RetVal
),
228 Index
== Dev
->Mode
->Mode
? L
'*' : L
' ',
230 !EFI_ERROR(Status
)?Col
:-1,
231 !EFI_ERROR(Status
)?Row
:-1
238 STATIC CONST UINTN VersionStringSize
= 60;
241 Function to dump information about EfiDriverSupportedEfiVersion protocol.
243 This will allocate the return buffer from boot services pool.
245 @param[in] TheHandle The handle that has the protocol installed.
246 @param[in] Verbose TRUE for additional information, FALSE otherwise.
248 @retval A poitner to a string containing the information.
252 DriverEfiVersionProtocolDumpInformation(
253 IN CONST EFI_HANDLE TheHandle
,
254 IN CONST BOOLEAN Verbose
257 EFI_DRIVER_SUPPORTED_EFI_VERSION_PROTOCOL
*DriverEfiVersion
;
261 Status
= gBS
->HandleProtocol(
263 &gEfiDriverSupportedEfiVersionProtocolGuid
,
264 (VOID
**)&DriverEfiVersion
);
266 ASSERT_EFI_ERROR(Status
);
268 RetVal
= AllocatePool(VersionStringSize
);
269 ASSERT(RetVal
!= NULL
);
270 UnicodeSPrint(RetVal
, VersionStringSize
, L
"0x%08x", DriverEfiVersion
->FirmwareVersion
);
275 Function to dump information about DevicePath protocol.
277 This will allocate the return buffer from boot services pool.
279 @param[in] TheHandle The handle that has the protocol installed.
280 @param[in] Verbose TRUE for additional information, FALSE otherwise.
282 @retval A poitner to a string containing the information.
286 DevicePathProtocolDumpInformation(
287 IN CONST EFI_HANDLE TheHandle
,
288 IN CONST BOOLEAN Verbose
291 EFI_DEVICE_PATH_PROTOCOL
*DevPath
;
295 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL
*DevPathToText
;
298 Status
= gBS
->LocateProtocol(&gEfiDevicePathToTextProtocolGuid
, NULL
, (VOID
**)&DevPathToText
);
299 if (!EFI_ERROR(Status
)) {
300 Status
= gBS
->OpenProtocol(TheHandle
, &gEfiDevicePathProtocolGuid
, (VOID
**)&DevPath
, gImageHandle
, NULL
, EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
301 if (!EFI_ERROR(Status
)) {
303 // I cannot decide whether to allow shortcuts here (the second BOOLEAN on the next line)
305 Temp
= DevPathToText
->ConvertDevicePathToText(DevPath
, TRUE
, TRUE
);
306 gBS
->CloseProtocol(TheHandle
, &gEfiDevicePathProtocolGuid
, gImageHandle
, NULL
);
309 if (Verbose
&& Temp
!= NULL
&& StrLen(Temp
) > 30) {
311 Temp2
= StrnCatGrow(&Temp2
, NULL
, Temp
+(StrLen(Temp
) - 30), 30);
319 // Put the information on the NT32 protocol GUIDs here so we are not dependant on the Nt32Pkg
321 #define LOCAL_EFI_WIN_NT_THUNK_PROTOCOL_GUID \
323 0x58c518b1, 0x76f3, 0x11d4, 0xbc, 0xea, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 \
326 #define LOCAL_EFI_WIN_NT_BUS_DRIVER_IO_PROTOCOL_GUID \
328 0x96eb4ad6, 0xa32a, 0x11d4, 0xbc, 0xfd, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 \
331 #define LOCAL_EFI_WIN_NT_SERIAL_PORT_GUID \
333 0xc95a93d, 0xa006, 0x11d4, 0xbc, 0xfa, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 \
335 STATIC CONST EFI_GUID WinNtThunkProtocolGuid
= LOCAL_EFI_WIN_NT_THUNK_PROTOCOL_GUID
;
336 STATIC CONST EFI_GUID WinNtIoProtocolGuid
= LOCAL_EFI_WIN_NT_BUS_DRIVER_IO_PROTOCOL_GUID
;
337 STATIC CONST EFI_GUID WinNtSerialPortGuid
= LOCAL_EFI_WIN_NT_SERIAL_PORT_GUID
;
339 STATIC CONST PROTOCOL_INFO_BLOCK mGuidStringListNT
[] = {
340 {STRING_TOKEN(STR_WINNT_THUNK
), (EFI_GUID
*)&WinNtThunkProtocolGuid
, NULL
},
341 {STRING_TOKEN(STR_WINNT_DRIVER_IO
), (EFI_GUID
*)&WinNtIoProtocolGuid
, NULL
},
342 {STRING_TOKEN(STR_WINNT_SERIAL_PORT
), (EFI_GUID
*)&WinNtSerialPortGuid
, NULL
},
343 {STRING_TOKEN(STR_UNKNOWN_DEVICE
), NULL
, NULL
},
346 STATIC CONST PROTOCOL_INFO_BLOCK mGuidStringList
[] = {
347 {STRING_TOKEN(STR_LOADED_IMAGE
), &gEfiLoadedImageProtocolGuid
, NULL
},
348 {STRING_TOKEN(STR_DEVICE_PATH
), &gEfiDevicePathProtocolGuid
, DevicePathProtocolDumpInformation
},
349 {STRING_TOKEN(STR_IMAGE_PATH
), &gEfiLoadedImageDevicePathProtocolGuid
, DevicePathProtocolDumpInformation
},
350 {STRING_TOKEN(STR_DEVICE_PATH_UTIL
), &gEfiDevicePathUtilitiesProtocolGuid
, NULL
},
351 {STRING_TOKEN(STR_DEVICE_PATH_TXT
), &gEfiDevicePathToTextProtocolGuid
, NULL
},
352 {STRING_TOKEN(STR_DEVICE_PATH_FTXT
), &gEfiDevicePathFromTextProtocolGuid
, NULL
},
353 {STRING_TOKEN(STR_DEVICE_PATH_PC
), &gEfiPcAnsiGuid
, NULL
},
354 {STRING_TOKEN(STR_DEVICE_PATH_VT100
), &gEfiVT100Guid
, NULL
},
355 {STRING_TOKEN(STR_DEVICE_PATH_VT100P
), &gEfiVT100PlusGuid
, NULL
},
356 {STRING_TOKEN(STR_DEVICE_PATH_VTUTF8
), &gEfiVTUTF8Guid
, NULL
},
357 {STRING_TOKEN(STR_DRIVER_BINDING
), &gEfiDriverBindingProtocolGuid
, NULL
},
358 {STRING_TOKEN(STR_PLATFORM_OVERRIDE
), &gEfiPlatformDriverOverrideProtocolGuid
, NULL
},
359 {STRING_TOKEN(STR_BUS_OVERRIDE
), &gEfiBusSpecificDriverOverrideProtocolGuid
, NULL
},
360 {STRING_TOKEN(STR_DRIVER_DIAG
), &gEfiDriverDiagnosticsProtocolGuid
, NULL
},
361 {STRING_TOKEN(STR_DRIVER_DIAG2
), &gEfiDriverDiagnostics2ProtocolGuid
, NULL
},
362 {STRING_TOKEN(STR_DRIVER_CN
), &gEfiComponentNameProtocolGuid
, NULL
},
363 {STRING_TOKEN(STR_DRIVER_CN2
), &gEfiComponentName2ProtocolGuid
, NULL
},
364 {STRING_TOKEN(STR_PLAT_DRV_CFG
), &gEfiPlatformToDriverConfigurationProtocolGuid
, NULL
},
365 {STRING_TOKEN(STR_DRIVER_VERSION
), &gEfiDriverSupportedEfiVersionProtocolGuid
, DriverEfiVersionProtocolDumpInformation
},
366 {STRING_TOKEN(STR_TXT_IN
), &gEfiSimpleTextInProtocolGuid
, NULL
},
367 {STRING_TOKEN(STR_TXT_IN_EX
), &gEfiSimpleTextInputExProtocolGuid
, NULL
},
368 {STRING_TOKEN(STR_TXT_OUT
), &gEfiSimpleTextOutProtocolGuid
, TxtOutProtocolDumpInformation
},
369 {STRING_TOKEN(STR_SIM_POINTER
), &gEfiSimplePointerProtocolGuid
, NULL
},
370 {STRING_TOKEN(STR_ABS_POINTER
), &gEfiAbsolutePointerProtocolGuid
, NULL
},
371 {STRING_TOKEN(STR_SERIAL_IO
), &gEfiSerialIoProtocolGuid
, NULL
},
372 {STRING_TOKEN(STR_GRAPHICS_OUTPUT
), &gEfiGraphicsOutputProtocolGuid
, NULL
},
373 {STRING_TOKEN(STR_EDID_DISCOVERED
), &gEfiEdidDiscoveredProtocolGuid
, NULL
},
374 {STRING_TOKEN(STR_EDID_ACTIVE
), &gEfiEdidActiveProtocolGuid
, NULL
},
375 {STRING_TOKEN(STR_EDID_OVERRIDE
), &gEfiEdidOverrideProtocolGuid
, NULL
},
376 {STRING_TOKEN(STR_CON_IN
), &gEfiConsoleInDeviceGuid
, NULL
},
377 {STRING_TOKEN(STR_CON_OUT
), &gEfiConsoleOutDeviceGuid
, NULL
},
378 {STRING_TOKEN(STR_STD_ERR
), &gEfiStandardErrorDeviceGuid
, NULL
},
379 {STRING_TOKEN(STR_LOAD_FILE
), &gEfiLoadFileProtocolGuid
, NULL
},
380 {STRING_TOKEN(STR_LOAD_FILE2
), &gEfiLoadFile2ProtocolGuid
, NULL
},
381 {STRING_TOKEN(STR_SIMPLE_FILE_SYS
), &gEfiSimpleFileSystemProtocolGuid
, NULL
},
382 {STRING_TOKEN(STR_FILE_INFO
), &gEfiFileInfoGuid
, NULL
},
383 {STRING_TOKEN(STR_FILE_SYS_INFO
), &gEfiFileSystemInfoGuid
, NULL
},
384 {STRING_TOKEN(STR_TAPE_IO
), &gEfiTapeIoProtocolGuid
, NULL
},
385 {STRING_TOKEN(STR_DISK_IO
), &gEfiDiskIoProtocolGuid
, NULL
},
386 {STRING_TOKEN(STR_BLK_IO
), &gEfiBlockIoProtocolGuid
, NULL
},
387 {STRING_TOKEN(STR_UC
), &gEfiUnicodeCollationProtocolGuid
, NULL
},
388 {STRING_TOKEN(STR_UC2
), &gEfiUnicodeCollation2ProtocolGuid
, NULL
},
389 {STRING_TOKEN(STR_PCIRB_IO
), &gEfiPciRootBridgeIoProtocolGuid
, NULL
},
390 {STRING_TOKEN(STR_PCI_IO
), &gEfiPciIoProtocolGuid
, NULL
},
391 {STRING_TOKEN(STR_SCSI_PT
), &gEfiScsiPassThruProtocolGuid
, NULL
},
392 {STRING_TOKEN(STR_SCSI_IO
), &gEfiScsiIoProtocolGuid
, NULL
},
393 {STRING_TOKEN(STR_SCSI_PT_EXT
), &gEfiExtScsiPassThruProtocolGuid
, NULL
},
394 {STRING_TOKEN(STR_ISCSI
), &gEfiIScsiInitiatorNameProtocolGuid
, NULL
},
395 {STRING_TOKEN(STR_USB_IO
), &gEfiUsbIoProtocolGuid
, NULL
},
396 {STRING_TOKEN(STR_USB_HC
), &gEfiUsbHcProtocolGuid
, NULL
},
397 {STRING_TOKEN(STR_USB_HC2
), &gEfiUsb2HcProtocolGuid
, NULL
},
398 {STRING_TOKEN(STR_DEBUG_SUPPORT
), &gEfiDebugSupportProtocolGuid
, NULL
},
399 {STRING_TOKEN(STR_DEBUG_PORT
), &gEfiDebugPortProtocolGuid
, NULL
},
400 {STRING_TOKEN(STR_DECOMPRESS
), &gEfiDecompressProtocolGuid
, NULL
},
401 {STRING_TOKEN(STR_ACPI_TABLE
), &gEfiAcpiTableProtocolGuid
, NULL
},
402 {STRING_TOKEN(STR_EBC_INTERPRETER
), &gEfiEbcProtocolGuid
, NULL
},
403 {STRING_TOKEN(STR_SNP
), &gEfiSimpleNetworkProtocolGuid
, NULL
},
404 {STRING_TOKEN(STR_NII
), &gEfiNetworkInterfaceIdentifierProtocolGuid
, NULL
},
405 {STRING_TOKEN(STR_NII_31
), &gEfiNetworkInterfaceIdentifierProtocolGuid_31
, NULL
},
406 {STRING_TOKEN(STR_PXE_BC
), &gEfiPxeBaseCodeProtocolGuid
, NULL
},
407 {STRING_TOKEN(STR_PXE_CB
), &gEfiPxeBaseCodeCallbackProtocolGuid
, NULL
},
408 {STRING_TOKEN(STR_BIS
), &gEfiBisProtocolGuid
, NULL
},
409 {STRING_TOKEN(STR_MNP_SB
), &gEfiManagedNetworkServiceBindingProtocolGuid
, NULL
},
410 {STRING_TOKEN(STR_MNP
), &gEfiManagedNetworkProtocolGuid
, NULL
},
411 {STRING_TOKEN(STR_ARP_SB
), &gEfiArpServiceBindingProtocolGuid
, NULL
},
412 {STRING_TOKEN(STR_ARP
), &gEfiArpProtocolGuid
, NULL
},
413 {STRING_TOKEN(STR_DHCPV4_SB
), &gEfiDhcp4ServiceBindingProtocolGuid
, NULL
},
414 {STRING_TOKEN(STR_DHCPV4
), &gEfiDhcp4ProtocolGuid
, NULL
},
415 {STRING_TOKEN(STR_TCPV4_SB
), &gEfiTcp4ServiceBindingProtocolGuid
, NULL
},
416 {STRING_TOKEN(STR_TCPV4
), &gEfiTcp4ProtocolGuid
, NULL
},
417 {STRING_TOKEN(STR_IPV4_SB
), &gEfiIp4ServiceBindingProtocolGuid
, NULL
},
418 {STRING_TOKEN(STR_IPV4
), &gEfiIp4ProtocolGuid
, NULL
},
419 {STRING_TOKEN(STR_IPV4_CFG
), &gEfiIp4ConfigProtocolGuid
, NULL
},
420 {STRING_TOKEN(STR_SHELL_PARAMETERS
), &gEfiShellParametersProtocolGuid
, NULL
},
421 {STRING_TOKEN(STR_SHELL
), &gEfiShellProtocolGuid
, NULL
},
422 {STRING_TOKEN(STR_EFI_GLOBAL_VARIABLE
), &gEfiGlobalVariableGuid
, NULL
},
423 {STRING_TOKEN(STR_UDPV4_SB
), &gEfiUdp4ServiceBindingProtocolGuid
, NULL
},
424 {STRING_TOKEN(STR_UDPV4
), &gEfiUdp4ProtocolGuid
, NULL
},
425 {STRING_TOKEN(STR_MTFTPV4_SB
), &gEfiMtftp4ServiceBindingProtocolGuid
, NULL
},
426 {STRING_TOKEN(STR_MTFTPV4
), &gEfiMtftp4ProtocolGuid
, NULL
},
427 {STRING_TOKEN(STR_AUTH_INFO
), &gEfiAuthenticationInfoProtocolGuid
, NULL
},
428 {STRING_TOKEN(STR_HASH_SB
), &gEfiHashServiceBindingProtocolGuid
, NULL
},
429 {STRING_TOKEN(STR_HASH
), &gEfiHashProtocolGuid
, NULL
},
430 {STRING_TOKEN(STR_HII_FONT
), &gEfiHiiFontProtocolGuid
, NULL
},
431 {STRING_TOKEN(STR_HII_STRING
), &gEfiHiiStringProtocolGuid
, NULL
},
432 {STRING_TOKEN(STR_HII_IMAGE
), &gEfiHiiImageProtocolGuid
, NULL
},
433 {STRING_TOKEN(STR_HII_DATABASE
), &gEfiHiiDatabaseProtocolGuid
, NULL
},
434 {STRING_TOKEN(STR_HII_CONFIG_ROUT
), &gEfiHiiConfigRoutingProtocolGuid
, NULL
},
435 {STRING_TOKEN(STR_HII_CONFIG_ACC
), &gEfiHiiConfigAccessProtocolGuid
, NULL
},
436 {STRING_TOKEN(STR_HII_FORM_BROWSER2
), &gEfiFormBrowser2ProtocolGuid
, NULL
},
437 {STRING_TOKEN(STR_SHELL_INTERFACE
), &gEfiShellInterfaceGuid
, NULL
},
438 {STRING_TOKEN(STR_SHELL_ENV2
), &gEfiShellEnvironment2Guid
, NULL
},
439 {STRING_TOKEN(STR_SHELL_ENV
), &gEfiShellEnvironment2Guid
, NULL
},
440 {STRING_TOKEN(STR_DEVICE_IO
), &gEfiDeviceIoProtocolGuid
, NULL
},
441 {STRING_TOKEN(STR_UGA_DRAW
), &gEfiUgaDrawProtocolGuid
, NULL
},
442 {STRING_TOKEN(STR_UGA_IO
), &gEfiUgaIoProtocolGuid
, NULL
},
443 {STRING_TOKEN(STR_ESP
), &gEfiPartTypeSystemPartGuid
, NULL
},
444 {STRING_TOKEN(STR_GPT_NBR
), &gEfiPartTypeLegacyMbrGuid
, NULL
},
445 {STRING_TOKEN(STR_DRIVER_CONFIG
), &gEfiDriverConfigurationProtocolGuid
, NULL
},
446 {STRING_TOKEN(STR_DRIVER_CONFIG2
), &gEfiDriverConfiguration2ProtocolGuid
, NULL
},
447 {STRING_TOKEN(STR_UNKNOWN_DEVICE
), NULL
, NULL
},
451 Function to get the node for a protocol or struct from it's GUID.
453 if Guid is NULL, then ASSERT.
455 @param[in] Guid The GUID to look for the name of.
459 CONST PROTOCOL_INFO_BLOCK
*
461 InternalShellGetNodeFromGuid(
462 IN CONST EFI_GUID
* Guid
465 CONST PROTOCOL_INFO_BLOCK
*ListWalker
;
467 ASSERT(Guid
!= NULL
);
469 if (PcdGetBool(PcdShellIncludeNtGuids
)) {
470 for (ListWalker
= mGuidStringListNT
; ListWalker
!= NULL
&& ListWalker
->GuidId
!= NULL
; ListWalker
++) {
471 if (CompareGuid(ListWalker
->GuidId
, Guid
)) {
476 for (ListWalker
= mGuidStringList
; ListWalker
!= NULL
&& ListWalker
->GuidId
!= NULL
; ListWalker
++) {
477 if (CompareGuid(ListWalker
->GuidId
, Guid
)) {
485 Function to get the name of a protocol or struct from it's GUID.
487 if Guid is NULL, then ASSERT.
489 @param[in] Guid The GUID to look for the name of.
490 @param[in] Lang The language to use.
492 @return pointer to string of the name. The caller
493 is responsible to free this memory.
497 GetStringNameFromGuid(
498 IN CONST EFI_GUID
*Guid
,
499 IN CONST CHAR8
*Lang OPTIONAL
502 CONST PROTOCOL_INFO_BLOCK
*Id
;
504 Id
= InternalShellGetNodeFromGuid(Guid
);
505 return (HiiGetString(mHandleParsingHiiHandle
, Id
->StringId
, Lang
));
509 Function to dump protocol information from a handle.
511 This function will return a allocated string buffer containing the
512 information. The caller is responsible for freeing the memory.
514 If Guid is NULL, ASSERT().
515 If TheHandle is NULL, ASSERT().
517 @param[in] TheHandle The handle to dump information from.
518 @param[in] Guid The GUID of the protocol to dump.
519 @param[in] Verbose TRUE for extra info. FALSE otherwise.
521 @return The pointer to string.
522 @retval NULL An error was encountered.
526 GetProtocolInformationDump(
527 IN CONST EFI_HANDLE TheHandle
,
528 IN CONST EFI_GUID
*Guid
,
529 IN CONST BOOLEAN Verbose
532 CONST PROTOCOL_INFO_BLOCK
*Id
;
534 ASSERT(TheHandle
!= NULL
);
535 ASSERT(Guid
!= NULL
);
537 if (TheHandle
== NULL
|| Guid
== NULL
) {
541 Id
= InternalShellGetNodeFromGuid(Guid
);
542 if (Id
!= NULL
&& Id
->DumpInfo
!= NULL
) {
543 return (Id
->DumpInfo(TheHandle
, Verbose
));
549 Function to get the Guid for a protocol or struct based on it's string name.
551 @param[in] Name The pointer to the string name.
552 @param[in] Lang The pointer to the language code.
553 @param[in] Guid The pointer to the Guid.
555 @retval EFI_SUCCESS The operation was sucessful.
559 GetGuidFromStringName(
560 IN CONST CHAR16
*Name
,
561 IN CONST CHAR8
*Lang OPTIONAL
,
565 CONST PROTOCOL_INFO_BLOCK
*ListWalker
;
568 ASSERT(Guid
!= NULL
);
570 return (EFI_INVALID_PARAMETER
);
574 if (PcdGetBool(PcdShellIncludeNtGuids
)) {
575 for (ListWalker
= mGuidStringListNT
; ListWalker
!= NULL
&& ListWalker
->GuidId
!= NULL
; ListWalker
++) {
576 String
= HiiGetString(mHandleParsingHiiHandle
, ListWalker
->StringId
, Lang
);
577 if (Name
!= NULL
&& String
!= NULL
&& StrCmp(Name
, String
)==0) {
578 *Guid
= ListWalker
->GuidId
;
580 SHELL_FREE_NON_NULL(String
);
582 return (EFI_SUCCESS
);
586 for (ListWalker
= mGuidStringList
; ListWalker
!= NULL
&& ListWalker
->GuidId
!= NULL
; ListWalker
++) {
587 String
= HiiGetString(mHandleParsingHiiHandle
, ListWalker
->StringId
, Lang
);
588 if (Name
!= NULL
&& String
!= NULL
&& StrCmp(Name
, String
)==0) {
589 *Guid
= ListWalker
->GuidId
;
591 SHELL_FREE_NON_NULL(String
);
593 return (EFI_SUCCESS
);
596 return (EFI_NOT_FOUND
);
600 Function to retrieve the driver name (if possible) from the ComponentName or
601 ComponentName2 protocol
603 @param[in] TheHandle The driver handle to get the name of.
604 @param[in] Language The language to use.
606 @retval NULL The name could not be found.
607 @return A pointer to the string name. Do not de-allocate the memory.
611 GetStringNameFromHandle(
612 IN CONST EFI_HANDLE TheHandle
,
613 IN CONST CHAR8
*Language
616 EFI_COMPONENT_NAME2_PROTOCOL
*CompNameStruct
;
620 Status
= gBS
->OpenProtocol(
622 &gEfiComponentName2ProtocolGuid
,
623 (VOID
**)&CompNameStruct
,
626 EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
627 if (!EFI_ERROR(Status
)) {
628 Status
= CompNameStruct
->GetDriverName(CompNameStruct
, (CHAR8
*)Language
, &RetVal
);
629 if (!EFI_ERROR(Status
)) {
633 Status
= gBS
->OpenProtocol(
635 &gEfiComponentNameProtocolGuid
,
636 (VOID
**)&CompNameStruct
,
639 EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
640 if (!EFI_ERROR(Status
)) {
641 Status
= CompNameStruct
->GetDriverName(CompNameStruct
, (CHAR8
*)Language
, &RetVal
);
642 if (!EFI_ERROR(Status
)) {
650 Function to initialize the file global mHandleList object for use in
651 vonverting handles to index and index to handle.
653 @retval EFI_SUCCESS The operation was successful.
657 InternalShellInitHandleList(
662 EFI_HANDLE
*HandleBuffer
;
664 HANDLE_LIST
*ListWalker
;
666 if (mHandleList
.NextIndex
!= 0) {
669 InitializeListHead(&mHandleList
.List
.Link
);
670 mHandleList
.NextIndex
= 1;
671 Status
= gBS
->LocateHandleBuffer (
678 ASSERT_EFI_ERROR(Status
);
679 if (EFI_ERROR(Status
)) {
682 for (mHandleList
.NextIndex
= 1 ; mHandleList
.NextIndex
<= HandleCount
; mHandleList
.NextIndex
++){
683 ListWalker
= AllocatePool(sizeof(HANDLE_LIST
));
684 ASSERT(ListWalker
!= NULL
);
685 ListWalker
->TheHandle
= HandleBuffer
[mHandleList
.NextIndex
-1];
686 ListWalker
->TheIndex
= mHandleList
.NextIndex
;
687 InsertTailList(&mHandleList
.List
.Link
,&ListWalker
->Link
);
689 FreePool(HandleBuffer
);
690 return (EFI_SUCCESS
);
694 Function to retrieve the human-friendly index of a given handle. If the handle
695 does not have a index one will be automatically assigned. The index value is valid
696 until the termination of the shell application.
698 @param[in] TheHandle The handle to retrieve an index for.
700 @retval 0 A memory allocation failed.
701 @return The index of the handle.
706 ConvertHandleToHandleIndex(
707 IN CONST EFI_HANDLE TheHandle
710 HANDLE_LIST
*ListWalker
;
711 ASSERT(TheHandle
!=NULL
);
713 InternalShellInitHandleList();
715 for (ListWalker
= (HANDLE_LIST
*)GetFirstNode(&mHandleList
.List
.Link
)
716 ; !IsNull(&mHandleList
.List
.Link
,&ListWalker
->Link
)
717 ; ListWalker
= (HANDLE_LIST
*)GetNextNode(&mHandleList
.List
.Link
,&ListWalker
->Link
)
719 if (ListWalker
->TheHandle
== TheHandle
) {
720 return (ListWalker
->TheIndex
);
723 ListWalker
= AllocatePool(sizeof(HANDLE_LIST
));
724 ASSERT(ListWalker
!= NULL
);
725 ListWalker
->TheHandle
= TheHandle
;
726 ListWalker
->TheIndex
= mHandleList
.NextIndex
++;
727 InsertTailList(&mHandleList
.List
.Link
,&ListWalker
->Link
);
728 return (ListWalker
->TheIndex
);
734 Function to retrieve the EFI_HANDLE from the human-friendly index.
736 @param[in] TheIndex The index to retrieve the EFI_HANDLE for.
738 @retval NULL The index was invalid.
739 @return The EFI_HANDLE that index represents.
744 ConvertHandleIndexToHandle(
745 IN CONST UINTN TheIndex
748 HANDLE_LIST
*ListWalker
;
750 InternalShellInitHandleList();
752 if (TheIndex
>= mHandleList
.NextIndex
) {
756 for (ListWalker
= (HANDLE_LIST
*)GetFirstNode(&mHandleList
.List
.Link
)
757 ; !IsNull(&mHandleList
.List
.Link
,&ListWalker
->Link
)
758 ; ListWalker
= (HANDLE_LIST
*)GetNextNode(&mHandleList
.List
.Link
,&ListWalker
->Link
)
760 if (ListWalker
->TheIndex
== TheIndex
) {
761 return (ListWalker
->TheHandle
);
768 Gets all the related EFI_HANDLEs based on the mask supplied.
770 This function scans all EFI_HANDLES in the UEFI environment's handle database
771 and returns the ones with the specified relationship (Mask) to the specified
774 If both DriverBindingHandle and ControllerHandle are NULL, then ASSERT.
775 If MatchingHandleCount is NULL, then ASSERT.
777 If MatchingHandleBuffer is not NULL upon a successful return the memory must be
780 @param[in] DriverBindingHandle The handle with Driver Binding protocol on it.
781 @param[in] ControllerHandle The handle with Device Path protocol on it.
782 @param[in] MatchingHandleCount The pointer to UINTN that specifies the number of HANDLES in
783 MatchingHandleBuffer.
784 @param[out] MatchingHandleBuffer On a successful return, a buffer of MatchingHandleCount
785 EFI_HANDLEs with a terminating NULL EFI_HANDLE.
786 @param[out] HandleType An array of type information.
788 @retval EFI_SUCCESS The operation was successful, and any related handles
789 are in MatchingHandleBuffer.
790 @retval EFI_NOT_FOUND No matching handles were found.
791 @retval EFI_INVALID_PARAMETER A parameter was invalid or out of range.
795 ParseHandleDatabaseByRelationshipWithType (
796 IN CONST EFI_HANDLE DriverBindingHandle OPTIONAL
,
797 IN CONST EFI_HANDLE ControllerHandle OPTIONAL
,
798 IN UINTN
*HandleCount
,
799 OUT EFI_HANDLE
**HandleBuffer
,
800 OUT UINTN
**HandleType
805 EFI_GUID
**ProtocolGuidArray
;
808 EFI_OPEN_PROTOCOL_INFORMATION_ENTRY
*OpenInfo
;
813 ASSERT(HandleCount
!= NULL
);
814 ASSERT(HandleBuffer
!= NULL
);
815 ASSERT(HandleType
!= NULL
);
816 ASSERT(DriverBindingHandle
!= NULL
|| ControllerHandle
!= NULL
);
819 *HandleBuffer
= NULL
;
823 // Retrieve the list of all handles from the handle database
825 Status
= gBS
->LocateHandleBuffer (
832 if (EFI_ERROR (Status
)) {
836 *HandleType
= AllocateZeroPool (*HandleCount
* sizeof (UINTN
));
837 ASSERT(*HandleType
!= NULL
);
839 for (HandleIndex
= 0; HandleIndex
< *HandleCount
; HandleIndex
++) {
841 // Retrieve the list of all the protocols on each handle
843 Status
= gBS
->ProtocolsPerHandle (
844 (*HandleBuffer
)[HandleIndex
],
848 if (!EFI_ERROR (Status
)) {
850 for (ProtocolIndex
= 0; ProtocolIndex
< ArrayCount
; ProtocolIndex
++) {
853 // Set the bit describing what this handle has
855 if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiLoadedImageProtocolGuid
) ) {
856 (*HandleType
)[HandleIndex
] |= HR_IMAGE_HANDLE
;
857 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiDriverBindingProtocolGuid
) ) {
858 (*HandleType
)[HandleIndex
] |= HR_DRIVER_BINDING_HANDLE
;
859 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiDriverConfiguration2ProtocolGuid
)) {
860 (*HandleType
)[HandleIndex
] |= HR_DRIVER_CONFIGURATION_HANDLE
;
861 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiDriverConfigurationProtocolGuid
) ) {
862 (*HandleType
)[HandleIndex
] |= HR_DRIVER_CONFIGURATION_HANDLE
;
863 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiDriverDiagnostics2ProtocolGuid
) ) {
864 (*HandleType
)[HandleIndex
] |= HR_DRIVER_DIAGNOSTICS_HANDLE
;
865 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiDriverDiagnosticsProtocolGuid
) ) {
866 (*HandleType
)[HandleIndex
] |= HR_DRIVER_DIAGNOSTICS_HANDLE
;
867 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiComponentName2ProtocolGuid
) ) {
868 (*HandleType
)[HandleIndex
] |= HR_COMPONENT_NAME_HANDLE
;
869 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiComponentNameProtocolGuid
) ) {
870 (*HandleType
)[HandleIndex
] |= HR_COMPONENT_NAME_HANDLE
;
871 } else if (CompareGuid (ProtocolGuidArray
[ProtocolIndex
], &gEfiDevicePathProtocolGuid
) ) {
872 (*HandleType
)[HandleIndex
] |= HR_DEVICE_HANDLE
;
875 ASSERT((*HandleType
)[HandleIndex
] == (*HandleType
)[HandleIndex
]);
879 // Retrieve the list of agents that have opened each protocol
881 Status
= gBS
->OpenProtocolInformation (
882 (*HandleBuffer
)[HandleIndex
],
883 ProtocolGuidArray
[ProtocolIndex
],
887 if (!EFI_ERROR (Status
)) {
888 for (OpenInfoIndex
= 0; OpenInfoIndex
< OpenInfoCount
; OpenInfoIndex
++) {
889 if (DriverBindingHandle
!= NULL
&& OpenInfo
[OpenInfoIndex
].AgentHandle
== DriverBindingHandle
) {
890 if ((OpenInfo
[OpenInfoIndex
].Attributes
& EFI_OPEN_PROTOCOL_BY_DRIVER
) == EFI_OPEN_PROTOCOL_BY_DRIVER
) {
891 (*HandleType
)[HandleIndex
] |= (HR_DEVICE_HANDLE
| HR_CONTROLLER_HANDLE
);
893 if (ControllerHandle
!= NULL
&& (*HandleBuffer
)[HandleIndex
] == ControllerHandle
) {
894 if ((OpenInfo
[OpenInfoIndex
].Attributes
& EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
) == EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
) {
895 for (ChildIndex
= 0; ChildIndex
< *HandleCount
; ChildIndex
++) {
896 if ((*HandleBuffer
)[ChildIndex
] == OpenInfo
[OpenInfoIndex
].ControllerHandle
) {
897 (*HandleType
)[ChildIndex
] |= (HR_DEVICE_HANDLE
| HR_CHILD_HANDLE
);
903 if (DriverBindingHandle
== NULL
&& OpenInfo
[OpenInfoIndex
].ControllerHandle
== ControllerHandle
) {
904 if ((OpenInfo
[OpenInfoIndex
].Attributes
& EFI_OPEN_PROTOCOL_BY_DRIVER
) == EFI_OPEN_PROTOCOL_BY_DRIVER
) {
905 for (ChildIndex
= 0; ChildIndex
< *HandleCount
; ChildIndex
++) {
906 if ((*HandleBuffer
)[ChildIndex
] == OpenInfo
[OpenInfoIndex
].AgentHandle
) {
907 (*HandleType
)[ChildIndex
] |= HR_DEVICE_DRIVER
;
911 if ((OpenInfo
[OpenInfoIndex
].Attributes
& EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
) == EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
) {
912 (*HandleType
)[HandleIndex
] |= HR_PARENT_HANDLE
;
913 for (ChildIndex
= 0; ChildIndex
< *HandleCount
; ChildIndex
++) {
914 if ((*HandleBuffer
)[ChildIndex
] == OpenInfo
[OpenInfoIndex
].AgentHandle
) {
915 (*HandleType
)[ChildIndex
] |= HR_BUS_DRIVER
;
926 FreePool (ProtocolGuidArray
);
930 if (EFI_ERROR(Status
)) {
931 if (*HandleType
!= NULL
) {
932 FreePool (*HandleType
);
934 if (*HandleBuffer
!= NULL
) {
935 FreePool (*HandleBuffer
);
939 *HandleBuffer
= NULL
;
947 Gets all the related EFI_HANDLEs based on the single EFI_HANDLE and the mask
950 This function will scan all EFI_HANDLES in the UEFI environment's handle database
951 and return all the ones with the specified relationship (Mask) to the specified
954 If both DriverBindingHandle and ControllerHandle are NULL, then ASSERT.
955 If MatchingHandleCount is NULL, then ASSERT.
957 If MatchingHandleBuffer is not NULL upon a sucessful return the memory must be
960 @param[in] DriverBindingHandle Handle to a object with Driver Binding protocol
962 @param[in] ControllerHandle Handle to a device with Device Path protocol on it.
963 @param[in] Mask Mask of what relationship(s) is desired.
964 @param[in] MatchingHandleCount Poitner to UINTN specifying number of HANDLES in
965 MatchingHandleBuffer.
966 @param[out] MatchingHandleBuffer On a sucessful return a buffer of MatchingHandleCount
967 EFI_HANDLEs and a terminating NULL EFI_HANDLE.
969 @retval EFI_SUCCESS The operation was sucessful and any related handles
970 are in MatchingHandleBuffer;
971 @retval EFI_NOT_FOUND No matching handles were found.
972 @retval EFI_INVALID_PARAMETER A parameter was invalid or out of range.
976 ParseHandleDatabaseByRelationship (
977 IN CONST EFI_HANDLE DriverBindingHandle OPTIONAL
,
978 IN CONST EFI_HANDLE ControllerHandle OPTIONAL
,
980 IN UINTN
*MatchingHandleCount
,
981 OUT EFI_HANDLE
**MatchingHandleBuffer OPTIONAL
986 EFI_HANDLE
*HandleBuffer
;
990 ASSERT(MatchingHandleCount
!= NULL
);
991 ASSERT(DriverBindingHandle
!= NULL
|| ControllerHandle
!= NULL
);
993 if ((Mask
& HR_VALID_MASK
) != Mask
) {
994 return (EFI_INVALID_PARAMETER
);
997 if ((Mask
& HR_CHILD_HANDLE
) != 0 && DriverBindingHandle
== NULL
) {
998 return (EFI_INVALID_PARAMETER
);
1001 *MatchingHandleCount
= 0;
1002 if (MatchingHandleBuffer
!= NULL
) {
1003 *MatchingHandleBuffer
= NULL
;
1006 HandleBuffer
= NULL
;
1009 Status
= ParseHandleDatabaseByRelationshipWithType (
1010 DriverBindingHandle
,
1016 if (!EFI_ERROR (Status
)) {
1018 // Count the number of handles that match the attributes in Mask
1020 for (HandleIndex
= 0; HandleIndex
< HandleCount
; HandleIndex
++) {
1021 if ((HandleType
[HandleIndex
] & Mask
) == Mask
) {
1022 (*MatchingHandleCount
)++;
1026 // If no handles match the attributes in Mask then return EFI_NOT_FOUND
1028 if (*MatchingHandleCount
== 0) {
1029 Status
= EFI_NOT_FOUND
;
1032 if (MatchingHandleBuffer
== NULL
) {
1034 // Someone just wanted the count...
1036 Status
= EFI_SUCCESS
;
1039 // Allocate a handle buffer for the number of handles that matched the attributes in Mask
1041 *MatchingHandleBuffer
= AllocatePool ((*MatchingHandleCount
+1)* sizeof (EFI_HANDLE
));
1042 ASSERT(*MatchingHandleBuffer
!= NULL
);
1044 for (HandleIndex
= 0,*MatchingHandleCount
= 0
1045 ; HandleIndex
< HandleCount
1049 // Fill the allocated buffer with the handles that matched the attributes in Mask
1051 if ((HandleType
[HandleIndex
] & Mask
) == Mask
) {
1052 (*MatchingHandleBuffer
)[(*MatchingHandleCount
)++] = HandleBuffer
[HandleIndex
];
1057 // Make the last one NULL
1059 (*MatchingHandleBuffer
)[*MatchingHandleCount
] = NULL
;
1061 Status
= EFI_SUCCESS
;
1062 } // MacthingHandleBuffer == NULL (ELSE)
1063 } // *MatchingHandleCount == 0 (ELSE)
1064 } // no error on ParseHandleDatabaseByRelationshipWithType
1066 if (HandleBuffer
!= NULL
) {
1067 FreePool (HandleBuffer
);
1070 if (HandleType
!= NULL
) {
1071 FreePool (HandleType
);
1078 Gets handles for any child controllers of the passed in controller.
1080 @param[in] ControllerHandle The handle of the "parent controller"
1081 @param[in] MatchingHandleCount Pointer to the number of handles in
1082 MatchingHandleBuffer on return.
1083 @param[out] MatchingHandleBuffer Buffer containing handles on a successful
1087 @retval EFI_SUCCESS The operation was sucessful.
1091 ParseHandleDatabaseForChildControllers(
1092 IN CONST EFI_HANDLE ControllerHandle
,
1093 IN UINTN
*MatchingHandleCount
,
1094 OUT EFI_HANDLE
**MatchingHandleBuffer OPTIONAL
1099 UINTN DriverBindingHandleCount
;
1100 EFI_HANDLE
*DriverBindingHandleBuffer
;
1101 UINTN DriverBindingHandleIndex
;
1102 UINTN ChildControllerHandleCount
;
1103 EFI_HANDLE
*ChildControllerHandleBuffer
;
1104 UINTN ChildControllerHandleIndex
;
1106 EFI_HANDLE
*HandleBufferForReturn
;
1108 ASSERT (MatchingHandleCount
!= NULL
);
1110 Status
= PARSE_HANDLE_DATABASE_UEFI_DRIVERS (
1112 &DriverBindingHandleCount
,
1113 &DriverBindingHandleBuffer
1115 if (EFI_ERROR (Status
)) {
1119 HandleBufferForReturn
= GetHandleListByPotocol(&gEfiDriverBindingProtocolGuid
);
1120 if (HandleBufferForReturn
== NULL
) {
1121 FreePool (DriverBindingHandleBuffer
);
1125 *MatchingHandleCount
= 0;
1126 for (DriverBindingHandleIndex
= 0; DriverBindingHandleIndex
< DriverBindingHandleCount
; DriverBindingHandleIndex
++) {
1127 Status
= PARSE_HANDLE_DATABASE_MANAGED_CHILDREN (
1128 DriverBindingHandleBuffer
[DriverBindingHandleIndex
],
1130 &ChildControllerHandleCount
,
1131 &ChildControllerHandleBuffer
1133 if (EFI_ERROR (Status
)) {
1137 for (ChildControllerHandleIndex
= 0;
1138 ChildControllerHandleIndex
< ChildControllerHandleCount
;
1139 ChildControllerHandleIndex
++
1142 for (HandleIndex
= 0; HandleBufferForReturn
[HandleIndex
] != NULL
; HandleIndex
++) {
1143 if (HandleBufferForReturn
[HandleIndex
] == ChildControllerHandleBuffer
[ChildControllerHandleIndex
]) {
1150 HandleBufferForReturn
[(*MatchingHandleCount
)++] = ChildControllerHandleBuffer
[ChildControllerHandleIndex
];
1154 FreePool (ChildControllerHandleBuffer
);
1157 FreePool (DriverBindingHandleBuffer
);
1159 if (MatchingHandleBuffer
!= NULL
) {
1160 *MatchingHandleBuffer
= HandleBufferForReturn
;
1162 FreePool(HandleBufferForReturn
);
1165 return (EFI_SUCCESS
);
1169 Appends 1 buffer to another buffer. This will re-allocate the destination buffer
1170 if necessary to fit all of the data.
1172 If DestinationBuffer is NULL, then ASSERT().
1174 @param[in,out] DestinationBuffer The pointer to the pointer to the buffer to append onto.
1175 @param[in,out] DestinationSize The pointer to the size of DestinationBuffer.
1176 @param[in] SourceBuffer The pointer to the buffer to append onto DestinationBuffer.
1177 @param[in] SourceSize The number of bytes of SourceBuffer to append.
1179 @retval NULL A memory allocation failed.
1180 @retval NULL A parameter was invalid.
1181 @return A pointer to (*DestinationBuffer).
1186 IN OUT VOID
**DestinationBuffer
,
1187 IN OUT UINTN
*DestinationSize
,
1188 IN VOID
*SourceBuffer
,
1192 UINTN LocalDestinationSize
;
1193 UINTN LocalDestinationFinalSize
;
1195 ASSERT(DestinationBuffer
!= NULL
);
1197 if (SourceSize
== 0 || SourceBuffer
== NULL
) {
1198 return (*DestinationBuffer
);
1201 if (DestinationSize
== NULL
) {
1202 LocalDestinationSize
= 0;
1204 LocalDestinationSize
= *DestinationSize
;
1207 LocalDestinationFinalSize
= LocalDestinationSize
+ SourceSize
;
1209 if (DestinationSize
!= NULL
) {
1210 *DestinationSize
= LocalDestinationSize
;
1213 if (LocalDestinationSize
== 0) {
1215 *DestinationBuffer
= AllocatePool(LocalDestinationFinalSize
);
1218 *DestinationBuffer
= ReallocatePool(LocalDestinationSize
, LocalDestinationFinalSize
, *DestinationBuffer
);
1221 ASSERT(*DestinationBuffer
!= NULL
);
1224 return (CopyMem(((UINT8
*)(*DestinationBuffer
)) + LocalDestinationSize
, SourceBuffer
, SourceSize
));
1228 Gets handles for any child devices produced by the passed in driver.
1230 @param[in] DriverHandle The handle of the driver.
1231 @param[in] MatchingHandleCount Pointer to the number of handles in
1232 MatchingHandleBuffer on return.
1233 @param[out] MatchingHandleBuffer Buffer containing handles on a successful
1235 @retval EFI_SUCCESS The operation was sucessful.
1236 @sa ParseHandleDatabaseByRelationship
1240 ParseHandleDatabaseForChildDevices(
1241 IN CONST EFI_HANDLE DriverHandle
,
1242 IN UINTN
*MatchingHandleCount
,
1243 OUT EFI_HANDLE
**MatchingHandleBuffer OPTIONAL
1247 EFI_HANDLE
*Buffer2
;
1252 UINTN HandleBufferSize
;
1254 ASSERT(MatchingHandleCount
!= NULL
);
1256 HandleBufferSize
= 0;
1259 *MatchingHandleCount
= 0;
1261 Status
= PARSE_HANDLE_DATABASE_DEVICES (
1266 if (!EFI_ERROR (Status
)) {
1267 for (HandleIndex
= 0; HandleIndex
< Count1
; HandleIndex
++) {
1269 // now find the children
1271 Status
= PARSE_HANDLE_DATABASE_MANAGED_CHILDREN (
1273 Buffer
[HandleIndex
],
1277 if (EFI_ERROR(Status
)) {
1281 // save out required and optional data elements
1283 *MatchingHandleCount
+= Count2
;
1284 if (MatchingHandleBuffer
!= NULL
) {
1285 *MatchingHandleBuffer
= BuffernCatGrow((VOID
**)MatchingHandleBuffer
, &HandleBufferSize
, Buffer2
, Count2
* sizeof(Buffer2
[0]));
1291 if (Buffer2
!= NULL
) {
1297 if (Buffer
!= NULL
) {
1304 Function to get all handles that support a given protocol or all handles.
1306 @param[in] ProtocolGuid The guid of the protocol to get handles for. If NULL
1307 then the function will return all handles.
1309 @retval NULL A memory allocation failed.
1310 @return A NULL terminated list of handles.
1314 GetHandleListByPotocol (
1315 IN CONST EFI_GUID
*ProtocolGuid OPTIONAL
1318 EFI_HANDLE
*HandleList
;
1326 // We cannot use LocateHandleBuffer since we need that NULL item on the ends of the list!
1328 if (ProtocolGuid
== NULL
) {
1329 Status
= gBS
->LocateHandle(AllHandles
, NULL
, NULL
, &Size
, HandleList
);
1330 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1331 HandleList
= AllocatePool(Size
+ sizeof(EFI_HANDLE
));
1332 Status
= gBS
->LocateHandle(AllHandles
, NULL
, NULL
, &Size
, HandleList
);
1333 HandleList
[Size
/sizeof(EFI_HANDLE
)] = NULL
;
1336 Status
= gBS
->LocateHandle(ByProtocol
, (EFI_GUID
*)ProtocolGuid
, NULL
, &Size
, HandleList
);
1337 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1338 HandleList
= AllocatePool(Size
+ sizeof(EFI_HANDLE
));
1339 Status
= gBS
->LocateHandle(ByProtocol
, (EFI_GUID
*)ProtocolGuid
, NULL
, &Size
, HandleList
);
1340 HandleList
[Size
/sizeof(EFI_HANDLE
)] = NULL
;
1343 if (EFI_ERROR(Status
)) {
1344 if (HandleList
!= NULL
) {
1345 FreePool(HandleList
);
1349 return (HandleList
);
1353 Function to get all handles that support some protocols.
1355 @param[in] ProtocolGuids A NULL terminated list of protocol GUIDs.
1357 @retval NULL A memory allocation failed.
1358 @return A NULL terminated list of handles.
1362 GetHandleListByPotocolList (
1363 IN CONST EFI_GUID
**ProtocolGuids
1366 EFI_HANDLE
*HandleList
;
1370 CONST EFI_GUID
**GuidWalker
;
1371 EFI_HANDLE
*HandleWalker1
;
1372 EFI_HANDLE
*HandleWalker2
;
1376 TotalSize
= sizeof(EFI_HANDLE
);
1378 for (GuidWalker
= ProtocolGuids
; GuidWalker
!= NULL
&& *GuidWalker
!= NULL
; GuidWalker
++,Size
= 0){
1379 Status
= gBS
->LocateHandle(ByProtocol
, (EFI_GUID
*)(*GuidWalker
), NULL
, &Size
, NULL
);
1380 if (Status
== EFI_BUFFER_TOO_SMALL
) {
1384 HandleList
= AllocatePool(TotalSize
);
1385 ASSERT(HandleList
!= NULL
);
1386 if (HandleList
== NULL
) {
1391 for (GuidWalker
= ProtocolGuids
; GuidWalker
!= NULL
&& *GuidWalker
!= NULL
; GuidWalker
++){
1392 Size
= TotalSize
- Size
;
1393 Status
= gBS
->LocateHandle(ByProtocol
, (EFI_GUID
*)(*GuidWalker
), NULL
, &Size
, HandleList
+((TotalSize
- Size
)/sizeof(EFI_HANDLE
)));
1394 ASSERT_EFI_ERROR(Status
);
1396 HandleList
[(TotalSize
/sizeof(EFI_HANDLE
))-1] = NULL
;
1398 for (HandleWalker1
= HandleList
; HandleWalker1
!= NULL
&& *HandleWalker1
!= NULL
; HandleWalker1
++) {
1399 for (HandleWalker2
= HandleWalker1
+ 1; HandleWalker2
!= NULL
&& *HandleWalker2
!= NULL
; HandleWalker2
++) {
1400 if (*HandleWalker1
== *HandleWalker2
) {
1402 // copy memory back 1 handle width.
1404 CopyMem(HandleWalker2
, HandleWalker2
+ 1, TotalSize
- ((HandleWalker2
-HandleList
+1)*sizeof(EFI_HANDLE
)));
1409 return (HandleList
);