2 Main file for DrvDiag shell Driver1 function.
4 (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
5 Copyright (c) 2010 - 2013, 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 "UefiShellDriver1CommandsLib.h"
18 STATIC CONST EFI_GUID
*DiagGuidList
[] = {&gEfiDriverDiagnosticsProtocolGuid
, &gEfiDriverDiagnostics2ProtocolGuid
, NULL
};
20 // We need 1 more item on the list...
23 TestModeStandard
= EfiDriverDiagnosticTypeStandard
,
24 TestModeExtended
= EfiDriverDiagnosticTypeExtended
,
25 TestModeManufacturing
= EfiDriverDiagnosticTypeManufacturing
,
31 Do the diagnostics call for some set of handles.
33 @param[in] Mode The type of diagnostic test to run.
34 @param[in] Lang The language code to use.
35 @param[in] AllChilds Should the test be on all children.
36 @param[in] DriverHandle The driver handle to test with.
37 @param[in] ControllerHandle The specific controller handle to test.
38 @param[in] ChildHandle The specific child handle to test.
40 @retval EFI_SUCCESS The operation was successful.
41 @retval EFI_INVALID_PARAMETER A parameter had an invalid value.
42 @retval EFI_NOT_FOUND No diagnostic handle could be found.
47 IN CONST DRV_DIAG_TEST_MODE Mode
,
49 IN CONST BOOLEAN AllChilds
,
50 IN CONST EFI_HANDLE DriverHandle
,
51 IN CONST EFI_HANDLE ControllerHandle
,
52 IN CONST EFI_HANDLE ChildHandle
55 EFI_DRIVER_DIAGNOSTICS_PROTOCOL
*DriverDiagnostics
;
56 EFI_DRIVER_DIAGNOSTICS2_PROTOCOL
*DriverDiagnostics2
;
57 EFI_HANDLE
*DriverHandleList
;
58 EFI_HANDLE
*ControllerHandleList
;
59 EFI_HANDLE
*ChildHandleList
;
61 UINTN DriverHandleListCount
;
62 UINTN ControllerHandleListCount
;
63 UINTN ChildHandleListCount
;
64 UINTN DriverHandleListLoop
;
65 UINTN ControllerHandleListLoop
;
66 UINTN ChildHandleListLoop
;
77 if ((ChildHandle
!= NULL
&& AllChilds
) || (Mode
>= TestModeMax
)){
78 return (EFI_INVALID_PARAMETER
);
81 DriverDiagnostics
= NULL
;
82 DriverDiagnostics2
= NULL
;
84 Status2
= EFI_SUCCESS
;
85 DriverHandleList
= NULL
;
86 ControllerHandleList
= NULL
;
87 ChildHandleList
= NULL
;
91 DriverHandleListCount
= 0;
92 ControllerHandleListCount
= 0;
93 ChildHandleListCount
= 0;
95 if (DriverHandle
!= NULL
) {
96 DriverHandleList
= AllocateZeroPool(2*sizeof(EFI_HANDLE
));
97 ASSERT(DriverHandleList
!=NULL
);
98 DriverHandleList
[0] = DriverHandle
;
99 DriverHandleListCount
= 1;
101 DriverHandleList
= GetHandleListByProtocolList(DiagGuidList
);
102 if (DriverHandleList
== NULL
) {
103 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROTOCOL_NF
), gShellDriver1HiiHandle
, L
"drvdiag", L
"gEfiDriverDiagnosticsProtocolGuid", &gEfiDriverDiagnosticsProtocolGuid
);
104 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROTOCOL_NF
), gShellDriver1HiiHandle
, L
"drvdiag", L
"gEfiDriverDiagnostics2ProtocolGuid", &gEfiDriverDiagnostics2ProtocolGuid
);
105 return (EFI_NOT_FOUND
);
107 for (Walker
= DriverHandleList
; Walker
!= NULL
&& *Walker
!= NULL
; DriverHandleListCount
++, Walker
++);
110 if (ControllerHandle
!= NULL
) {
111 ControllerHandleList
= AllocateZeroPool(2*sizeof(EFI_HANDLE
));
112 ASSERT(ControllerHandleList
!=NULL
);
113 ControllerHandleList
[0] = ControllerHandle
;
114 ControllerHandleListCount
= 1;
116 ControllerHandleList
= NULL
;
119 if (ChildHandle
!= NULL
) {
120 ChildHandleList
= AllocateZeroPool(2*sizeof(EFI_HANDLE
));
121 ASSERT(ChildHandleList
!=NULL
);
122 ChildHandleList
[0] = ChildHandle
;
123 ChildHandleListCount
= 1;
124 } else if (AllChilds
) {
125 ChildHandleList
= NULL
;
127 // This gets handled in the loop below.
130 ChildHandleList
= NULL
;
133 if (Mode
== TestModeList
) {
134 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_DRVDIAG_HEADER
), gShellDriver1HiiHandle
);
136 for (DriverHandleListLoop
= 0
137 ; DriverHandleListLoop
< DriverHandleListCount
138 ; DriverHandleListLoop
++
140 if (Mode
== TestModeList
) {
141 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_DRVDIAG_DRIVER_HEADER
), gShellDriver1HiiHandle
, ConvertHandleToHandleIndex(DriverHandleList
[DriverHandleListLoop
]));
143 if (ControllerHandle
== NULL
) {
144 PARSE_HANDLE_DATABASE_DEVICES(DriverHandleList
[DriverHandleListLoop
], &ControllerHandleListCount
, &ControllerHandleList
);
146 if (ControllerHandleListCount
== 0) {
147 if (Mode
== TestModeList
) {
148 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_DRVDIAG_DRIVER_NO_HANDLES
), gShellDriver1HiiHandle
);
151 if (Mode
== TestModeList
) {
152 ShellPrintEx(-1, -1, L
"\r\n");
154 for (ControllerHandleListLoop
= 0
155 ; ControllerHandleListLoop
< ControllerHandleListCount
156 ; ControllerHandleListLoop
++
159 ASSERT(ChildHandleList
== NULL
);
160 PARSE_HANDLE_DATABASE_MANAGED_CHILDREN(
161 DriverHandleList
[DriverHandleListLoop
],
162 ControllerHandleList
[ControllerHandleListLoop
],
163 &ChildHandleListCount
,
166 for (ChildHandleListLoop
= 0
167 ; (ChildHandleListLoop
< ChildHandleListCount
|| ChildHandleList
== NULL
)
168 ; ChildHandleListLoop
++
171 if (Mode
!= TestModeList
) {
172 if (Lang
== NULL
|| Lang
[2] == '-') {
174 // Get the protocol pointer and call the function
176 Status
= gBS
->OpenProtocol(
177 DriverHandleList
[DriverHandleListLoop
],
178 &gEfiDriverDiagnostics2ProtocolGuid
,
179 (VOID
**)&DriverDiagnostics2
,
182 EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
183 if (!EFI_ERROR(Status
) && (DriverDiagnostics2
!= NULL
)) {
184 Language
= GetBestLanguageForDriver(DriverDiagnostics2
->SupportedLanguages
, Lang
, FALSE
);
186 Status
= DriverDiagnostics2
->RunDiagnostics(
188 ControllerHandleList
[ControllerHandleListLoop
],
189 ChildHandleList
== NULL
?NULL
:ChildHandleList
[ChildHandleListLoop
],
190 (EFI_DRIVER_DIAGNOSTIC_TYPE
)Mode
,
198 if (!Found
&& (Lang
== NULL
||(Lang
!=NULL
&&(Lang
[2]!='-')))){
199 Status
= gBS
->OpenProtocol(
200 DriverHandleList
[DriverHandleListLoop
],
201 &gEfiDriverDiagnosticsProtocolGuid
,
202 (VOID
**)&DriverDiagnostics
,
205 EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
206 if (!EFI_ERROR(Status
)) {
207 Language
= GetBestLanguageForDriver(DriverDiagnostics
->SupportedLanguages
, Lang
, FALSE
);
208 Status
= DriverDiagnostics
->RunDiagnostics(
210 ControllerHandleList
[ControllerHandleListLoop
],
211 ChildHandleList
== NULL
?NULL
:ChildHandleList
[ChildHandleListLoop
],
212 (EFI_DRIVER_DIAGNOSTIC_TYPE
)Mode
,
220 if (EFI_ERROR(Status
)) {
223 HandleIndex1
= ConvertHandleToHandleIndex(DriverHandleList
[DriverHandleListLoop
]);
224 HandleIndex2
= ConvertHandleToHandleIndex(ControllerHandleList
[ControllerHandleListLoop
]);
229 STRING_TOKEN (STR_3P_RESULT
),
230 gShellDriver1HiiHandle
,
234 ChildHandleList
== NULL
?0:ConvertHandleToHandleIndex(ChildHandleList
[ChildHandleListLoop
]),
236 if (OutBuffer
!=NULL
) {
240 if (ErrorType
!=NULL
) {
245 HandleIndex1
= ConvertHandleToHandleIndex(DriverHandleList
[DriverHandleListLoop
]);
246 HandleIndex2
= ConvertHandleToHandleIndex(ControllerHandleList
[ControllerHandleListLoop
]);
248 // Print out the information that this set can be tested
254 STRING_TOKEN (STR_DRV_DIAG_ITEM_LINE
),
255 gShellDriver1HiiHandle
,
258 ChildHandleList
== NULL
?0:ConvertHandleToHandleIndex(ChildHandleList
[ChildHandleListLoop
])
263 // If we are doing a single pass with NULL child jump out after a single loop
265 if (ChildHandleList
== NULL
) {
270 SHELL_FREE_NON_NULL(ChildHandleList
);
271 ChildHandleList
= NULL
;
272 ChildHandleListCount
= 0;
275 if (ControllerHandle
== NULL
) {
276 SHELL_FREE_NON_NULL(ControllerHandleList
);
277 ControllerHandleList
= NULL
;
278 ControllerHandleListCount
= 0;
283 if (DriverHandleList
!= NULL
) {
284 FreePool(DriverHandleList
);
286 if (ControllerHandleList
!= NULL
) {
287 FreePool(ControllerHandleList
);
289 if (ChildHandleList
!= NULL
) {
290 FreePool(ChildHandleList
);
296 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
306 Function for 'drvdiag' command.
308 @param[in] ImageHandle Handle to the Image (NULL if Internal).
309 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
313 ShellCommandRunDrvDiag (
314 IN EFI_HANDLE ImageHandle
,
315 IN EFI_SYSTEM_TABLE
*SystemTable
320 CHAR16
*ProblemParam
;
321 SHELL_STATUS ShellStatus
;
322 DRV_DIAG_TEST_MODE Mode
;
324 CONST CHAR16
*DriverHandleStr
;
325 CONST CHAR16
*ControllerHandleStr
;
326 CONST CHAR16
*ChildHandleStr
;
333 ShellStatus
= SHELL_SUCCESS
;
338 // initialize the shell lib (we must be in non-auto-init...)
340 Status
= ShellInitialize();
341 ASSERT_EFI_ERROR(Status
);
343 Status
= CommandInit();
344 ASSERT_EFI_ERROR(Status
);
347 // parse the command line
349 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
350 if (EFI_ERROR(Status
)) {
351 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
352 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDriver1HiiHandle
, L
"drvdiag", ProblemParam
);
353 FreePool(ProblemParam
);
354 ShellStatus
= SHELL_INVALID_PARAMETER
;
360 // if more than 3 'value' parameters (plus the name one) or we have any 2 mode flags
362 if ((ShellCommandLineGetCount(Package
) > 4)
363 ||(ShellCommandLineGetFlag(Package
, L
"-s") && ShellCommandLineGetFlag(Package
, L
"-e"))
364 ||(ShellCommandLineGetFlag(Package
, L
"-s") && ShellCommandLineGetFlag(Package
, L
"-m"))
365 ||(ShellCommandLineGetFlag(Package
, L
"-e") && ShellCommandLineGetFlag(Package
, L
"-m"))
368 // error for too many parameters
370 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellDriver1HiiHandle
, L
"drvdiag");
371 ShellStatus
= SHELL_INVALID_PARAMETER
;
372 } else if ((ShellCommandLineGetFlag(Package
, L
"-s"))
373 || (ShellCommandLineGetFlag(Package
, L
"-e"))
374 || (ShellCommandLineGetFlag(Package
, L
"-m"))
377 // Run the apropriate test
379 if (ShellCommandLineGetFlag(Package
, L
"-s")) {
380 Mode
= TestModeStandard
;
381 } else if (ShellCommandLineGetFlag(Package
, L
"-e")) {
382 Mode
= TestModeExtended
;
383 } else if (ShellCommandLineGetFlag(Package
, L
"-m")) {
384 Mode
= TestModeManufacturing
;
390 // Do a listing of what's available to test
395 Lang
= ShellCommandLineGetValue(Package
, L
"-l");
396 if (ShellCommandLineGetFlag(Package
, L
"-l") && Lang
== NULL
) {
397 ASSERT(Language
== NULL
);
398 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_VALUE
), gShellDriver1HiiHandle
, L
"drvdiag", L
"-l");
399 ShellCommandLineFreeVarList (Package
);
400 return (SHELL_INVALID_PARAMETER
);
401 } else if (Lang
!= NULL
) {
402 Language
= AllocateZeroPool(StrSize(Lang
));
403 AsciiSPrint(Language
, StrSize(Lang
), "%S", Lang
);
406 DriverHandleStr
= ShellCommandLineGetRawValue(Package
, 1);
407 ControllerHandleStr
= ShellCommandLineGetRawValue(Package
, 2);
408 ChildHandleStr
= ShellCommandLineGetRawValue(Package
, 3);
410 if (DriverHandleStr
== NULL
) {
413 ShellConvertStringToUint64(DriverHandleStr
, &Intermediate
, TRUE
, FALSE
);
414 Handle1
= ConvertHandleIndexToHandle((UINTN
)Intermediate
);
416 if (ControllerHandleStr
== NULL
) {
419 ShellConvertStringToUint64(ControllerHandleStr
, &Intermediate
, TRUE
, FALSE
);
420 Handle2
= ConvertHandleIndexToHandle((UINTN
)Intermediate
);
422 if (ChildHandleStr
== NULL
) {
425 ShellConvertStringToUint64(ChildHandleStr
, &Intermediate
, TRUE
, FALSE
);
426 Handle3
= ConvertHandleIndexToHandle((UINTN
)Intermediate
);
429 Status
= DoDiagnostics (
432 ShellCommandLineGetFlag(Package
, L
"-c"),
438 SHELL_FREE_NON_NULL(Language
);
439 ShellCommandLineFreeVarList (Package
);
442 if (ShellStatus
== SHELL_SUCCESS
) {
443 if (Status
== EFI_SECURITY_VIOLATION
) {
444 ShellStatus
= SHELL_SECURITY_VIOLATION
;
445 } else if (Status
== EFI_INVALID_PARAMETER
) {
446 ShellStatus
= SHELL_INVALID_PARAMETER
;
447 } else if (Status
== EFI_NOT_FOUND
) {
448 ShellStatus
= SHELL_NOT_FOUND
;
449 } else if (EFI_ERROR(Status
)) {
450 ShellStatus
= SHELL_NOT_FOUND
;
454 return (ShellStatus
);