2 Main file for devices shell Driver1 function.
4 Copyright (c) 2010 - 2011, 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 "UefiShellDriver1CommandsLib.h"
18 Get lots of info about a device from its handle.
20 @param[in] TheHandle The device handle to get info on.
21 @param[in, out] Type On successful return R, B, or D (root, bus, or
22 device) will be placed in this buffer.
23 @param[in, out] Cfg On successful return this buffer will be
24 TRUE if the handle has configuration, FALSE
26 @param[in, out] Diag On successful return this buffer will be
27 TRUE if the handle has disgnostics, FALSE
29 @param[in, out] Parents On successful return this buffer will be
30 contain the number of parent handles.
31 @param[in, out] Devices On successful return this buffer will be
32 contain the number of devices controlled.
33 @param[in, out] Children On successful return this buffer will be
34 contain the number of child handles.
35 @param[out] Name The pointer to a buffer that will be allocated
36 and contain the string name of the handle.
37 The caller must free this memory.
38 @param[in] Language The language code as defined by the UEFI spec.
40 @retval EFI_SUCCESS The info is there.
41 @retval EFI_INVALID_PARAMETER A parameter was invalid.
46 IN EFI_HANDLE TheHandle
,
50 IN OUT UINTN
*Parents
,
51 IN OUT UINTN
*Devices
,
52 IN OUT UINTN
*Children
,
54 IN CONST CHAR8
*Language
58 EFI_HANDLE
*HandleBuffer
;
69 return (EFI_INVALID_PARAMETER
);
82 gEfiShellProtocol
->GetDeviceName(TheHandle
, EFI_DEVICE_NAME_USE_COMPONENT_NAME
|EFI_DEVICE_NAME_USE_DEVICE_PATH
, (CHAR8
*)Language
, Name
);
84 Status
= ParseHandleDatabaseForChildControllers(TheHandle
, Children
, NULL
);
85 // if (!EFI_ERROR(Status)) {
86 Status
= PARSE_HANDLE_DATABASE_PARENTS(TheHandle
, Parents
, NULL
);
87 if (/*!EFI_ERROR(Status) && */Parents
!= NULL
&& Children
!= NULL
) {
90 } else if (*Children
> 0) {
97 Status
= PARSE_HANDLE_DATABASE_UEFI_DRIVERS(TheHandle
, Devices
, &HandleBuffer
);
98 if (!EFI_ERROR(Status
) && Devices
!= NULL
&& HandleBuffer
!= NULL
) {
99 for (Count
= 0 ; Count
< *Devices
; Count
++) {
100 if (!EFI_ERROR(gBS
->OpenProtocol(HandleBuffer
[Count
], &gEfiDriverConfigurationProtocolGuid
, NULL
, NULL
, gImageHandle
, EFI_OPEN_PROTOCOL_TEST_PROTOCOL
))) {
103 if (!EFI_ERROR(gBS
->OpenProtocol(HandleBuffer
[Count
], &gEfiDriverDiagnosticsProtocolGuid
, NULL
, NULL
, gImageHandle
, EFI_OPEN_PROTOCOL_TEST_PROTOCOL
))) {
106 if (!EFI_ERROR(gBS
->OpenProtocol(HandleBuffer
[Count
], &gEfiDriverDiagnostics2ProtocolGuid
, NULL
, NULL
, gImageHandle
, EFI_OPEN_PROTOCOL_TEST_PROTOCOL
))) {
110 SHELL_FREE_NON_NULL(HandleBuffer
);
116 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
122 Function for 'devices' command.
124 @param[in] ImageHandle Handle to the Image (NULL if Internal).
125 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
129 ShellCommandRunDevices (
130 IN EFI_HANDLE ImageHandle
,
131 IN EFI_SYSTEM_TABLE
*SystemTable
136 CHAR16
*ProblemParam
;
137 SHELL_STATUS ShellStatus
;
139 EFI_HANDLE
*HandleList
;
140 EFI_HANDLE
*HandleListWalker
;
150 ShellStatus
= SHELL_SUCCESS
;
154 // initialize the shell lib (we must be in non-auto-init...)
156 Status
= ShellInitialize();
157 ASSERT_EFI_ERROR(Status
);
159 Status
= CommandInit();
160 ASSERT_EFI_ERROR(Status
);
163 // parse the command line
165 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
166 if (EFI_ERROR(Status
)) {
167 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
168 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDriver1HiiHandle
, ProblemParam
);
169 FreePool(ProblemParam
);
170 ShellStatus
= SHELL_INVALID_PARAMETER
;
176 // if more than 0 'value' parameters we have too many parameters
178 if (ShellCommandLineGetRawValue(Package
, 1) != NULL
){
180 // error for too many parameters
182 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellDriver1HiiHandle
);
183 ShellStatus
= SHELL_INVALID_PARAMETER
;
186 // get the language if necessary
188 Lang
= ShellCommandLineGetValue(Package
, L
"-l");
190 Language
= AllocateZeroPool(StrSize(Lang
));
191 AsciiSPrint(Language
, StrSize(Lang
), "%S", Lang
);
192 } else if (!ShellCommandLineGetFlag(Package
, L
"-l")){
193 ASSERT(Language
== NULL
);
194 // Language = AllocateZeroPool(10);
195 // AsciiSPrint(Language, 10, "en-us");
197 ASSERT(Language
== NULL
);
198 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_VALUE
), gShellDriver1HiiHandle
, L
"-l");
199 ShellCommandLineFreeVarList (Package
);
200 return (SHELL_INVALID_PARAMETER
);
207 ShellPrintHiiEx(-1, -1, Language
, STRING_TOKEN (STR_DEVICES_HEADER_LINES
), gShellDriver1HiiHandle
);
210 // loop through each handle
212 HandleList
= GetHandleListByProtocol(NULL
);
213 ASSERT(HandleList
!= NULL
);
214 for (HandleListWalker
= HandleList
215 ; HandleListWalker
!= NULL
&& *HandleListWalker
!= NULL
/*&& !EFI_ERROR(Status)*/
220 // get all the info on each handle
223 Status
= GetDeviceHandleInfo(*HandleListWalker
, &Type
, &Cfg
, &Diag
, &Parents
, &Devices
, &Children
, &Name
, Language
);
224 if (Name
!= NULL
&& (Parents
!= 0 || Devices
!= 0 || Children
!= 0)) {
229 STRING_TOKEN (STR_DEVICES_ITEM_LINE
),
230 gShellDriver1HiiHandle
,
231 ConvertHandleToHandleIndex(*HandleListWalker
),
238 Name
!=NULL
?Name
:L
"<UNKNOWN>");
245 if (HandleList
!= NULL
) {
246 FreePool(HandleList
);
250 SHELL_FREE_NON_NULL(Language
);
251 ShellCommandLineFreeVarList (Package
);
253 return (ShellStatus
);