VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/ShellPkg/Library/UefiShellDriver1CommandsLib/Devices.c@ 80721

Last change on this file since 80721 was 80721, checked in by vboxsync, 6 years ago

Devices/EFI/FirmwareNew: Start upgrade process to edk2-stable201908 (compiles on Windows and works to some extent), bugref:4643

  • Property svn:eol-style set to native
File size: 8.3 KB
Line 
1/** @file
2 Main file for devices shell Driver1 function.
3
4 (C) Copyright 2012-2015 Hewlett-Packard Development Company, L.P.<BR>
5 Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8**/
9
10#include "UefiShellDriver1CommandsLib.h"
11
12/**
13 Get lots of info about a device from its handle.
14
15 @param[in] TheHandle The device handle to get info on.
16 @param[in, out] Type On successful return R, B, or D (root, bus, or
17 device) will be placed in this buffer.
18 @param[in, out] Cfg On successful return this buffer will be
19 TRUE if the handle has configuration, FALSE
20 otherwise.
21 @param[in, out] Diag On successful return this buffer will be
22 TRUE if the handle has disgnostics, FALSE
23 otherwise.
24 @param[in, out] Parents On successful return this buffer will be
25 contain the number of parent handles.
26 @param[in, out] Devices On successful return this buffer will be
27 contain the number of devices controlled.
28 @param[in, out] Children On successful return this buffer will be
29 contain the number of child handles.
30 @param[out] Name The pointer to a buffer that will be allocated
31 and contain the string name of the handle.
32 The caller must free this memory.
33 @param[in] Language The language code as defined by the UEFI spec.
34
35 @retval EFI_SUCCESS The info is there.
36 @retval EFI_INVALID_PARAMETER A parameter was invalid.
37**/
38EFI_STATUS
39GetDeviceHandleInfo (
40 IN EFI_HANDLE TheHandle,
41 IN OUT CHAR16 *Type,
42 IN OUT BOOLEAN *Cfg,
43 IN OUT BOOLEAN *Diag,
44 IN OUT UINTN *Parents,
45 IN OUT UINTN *Devices,
46 IN OUT UINTN *Children,
47 OUT CHAR16 **Name,
48 IN CONST CHAR8 *Language
49 )
50{
51 EFI_STATUS Status;
52 EFI_HANDLE *HandleBuffer;
53 UINTN Count;
54
55 if (TheHandle == NULL
56 || Type == NULL
57 || Cfg == NULL
58 || Diag == NULL
59 || Parents == NULL
60 || Devices == NULL
61 || Children == NULL
62 || Name == NULL ) {
63 return (EFI_INVALID_PARAMETER);
64 }
65
66 *Cfg = FALSE;
67 *Diag = FALSE;
68 *Children = 0;
69 *Parents = 0;
70 *Devices = 0;
71 *Type = L' ';
72 *Name = CHAR_NULL;
73 HandleBuffer = NULL;
74 Status = EFI_SUCCESS;
75
76 gEfiShellProtocol->GetDeviceName(TheHandle, EFI_DEVICE_NAME_USE_COMPONENT_NAME|EFI_DEVICE_NAME_USE_DEVICE_PATH, (CHAR8*)Language, Name);
77
78 Status = ParseHandleDatabaseForChildControllers(TheHandle, Children, NULL);
79// if (!EFI_ERROR(Status)) {
80 Status = PARSE_HANDLE_DATABASE_PARENTS(TheHandle, Parents, NULL);
81 if (/*!EFI_ERROR(Status) && */Parents != NULL && Children != NULL) {
82 if (*Parents == 0) {
83 *Type = L'R';
84 } else if (*Children > 0) {
85 *Type = L'B';
86 } else {
87 *Type = L'D';
88 }
89 }
90// }
91 Status = PARSE_HANDLE_DATABASE_UEFI_DRIVERS(TheHandle, Devices, &HandleBuffer);
92 if (!EFI_ERROR(Status) && Devices != NULL && HandleBuffer != NULL) {
93 for (Count = 0 ; Count < *Devices ; Count++) {
94 if (!EFI_ERROR(gBS->OpenProtocol(HandleBuffer[Count], &gEfiDriverConfigurationProtocolGuid, NULL, NULL, gImageHandle, EFI_OPEN_PROTOCOL_TEST_PROTOCOL))) {
95 *Cfg = TRUE;
96 }
97 if (!EFI_ERROR(gBS->OpenProtocol(HandleBuffer[Count], &gEfiDriverDiagnosticsProtocolGuid, NULL, NULL, gImageHandle, EFI_OPEN_PROTOCOL_TEST_PROTOCOL))) {
98 *Diag = TRUE;
99 }
100 if (!EFI_ERROR(gBS->OpenProtocol(HandleBuffer[Count], &gEfiDriverDiagnostics2ProtocolGuid, NULL, NULL, gImageHandle, EFI_OPEN_PROTOCOL_TEST_PROTOCOL))) {
101 *Diag = TRUE;
102 }
103 }
104 SHELL_FREE_NON_NULL(HandleBuffer);
105 }
106
107 return (Status);
108}
109
110STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
111 {L"-sfo", TypeFlag},
112 {L"-l", TypeValue},
113 {NULL, TypeMax}
114 };
115
116/**
117 Function for 'devices' command.
118
119 @param[in] ImageHandle Handle to the Image (NULL if Internal).
120 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
121**/
122SHELL_STATUS
123EFIAPI
124ShellCommandRunDevices (
125 IN EFI_HANDLE ImageHandle,
126 IN EFI_SYSTEM_TABLE *SystemTable
127 )
128{
129 EFI_STATUS Status;
130 LIST_ENTRY *Package;
131 CHAR16 *ProblemParam;
132 SHELL_STATUS ShellStatus;
133 CHAR8 *Language;
134 EFI_HANDLE *HandleList;
135 EFI_HANDLE *HandleListWalker;
136 CHAR16 Type;
137 BOOLEAN Cfg;
138 BOOLEAN Diag;
139 UINTN Parents;
140 UINTN Devices;
141 UINTN Children;
142 CHAR16 *Name;
143 CONST CHAR16 *Lang;
144 BOOLEAN SfoFlag;
145
146 ShellStatus = SHELL_SUCCESS;
147 Language = NULL;
148 SfoFlag = FALSE;
149
150 //
151 // initialize the shell lib (we must be in non-auto-init...)
152 //
153 Status = ShellInitialize();
154 ASSERT_EFI_ERROR(Status);
155
156 Status = CommandInit();
157 ASSERT_EFI_ERROR(Status);
158
159 //
160 // parse the command line
161 //
162 Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
163 if (EFI_ERROR(Status)) {
164 if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
165 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDriver1HiiHandle, L"devices", ProblemParam);
166 FreePool(ProblemParam);
167 ShellStatus = SHELL_INVALID_PARAMETER;
168 } else {
169 ASSERT(FALSE);
170 }
171 } else {
172 //
173 // if more than 0 'value' parameters we have too many parameters
174 //
175 if (ShellCommandLineGetRawValue(Package, 1) != NULL){
176 //
177 // error for too many parameters
178 //
179 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDriver1HiiHandle, L"devices");
180 ShellStatus = SHELL_INVALID_PARAMETER;
181 } else {
182 //
183 // get the language if necessary
184 //
185 Lang = ShellCommandLineGetValue(Package, L"-l");
186 if (Lang != NULL) {
187 Language = AllocateZeroPool(StrSize(Lang));
188 AsciiSPrint(Language, StrSize(Lang), "%S", Lang);
189 } else if (!ShellCommandLineGetFlag(Package, L"-l")){
190 ASSERT(Language == NULL);
191// Language = AllocateZeroPool(10);
192// AsciiSPrint(Language, 10, "en-us");
193 } else {
194 ASSERT(Language == NULL);
195 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDriver1HiiHandle, L"devices", L"-l");
196 ShellCommandLineFreeVarList (Package);
197 return (SHELL_INVALID_PARAMETER);
198 }
199
200
201 //
202 // Print Header
203
204 //
205 if (ShellCommandLineGetFlag (Package, L"-sfo")) {
206 ShellPrintHiiEx (-1, -1, Language, STRING_TOKEN (STR_GEN_SFO_HEADER), gShellDriver1HiiHandle, L"devices");
207 SfoFlag = TRUE;
208 } else {
209 ShellPrintHiiEx (-1, -1, Language, STRING_TOKEN (STR_DEVICES_HEADER_LINES), gShellDriver1HiiHandle);
210 }
211
212 //
213 // loop through each handle
214 //
215 HandleList = GetHandleListByProtocol(NULL);
216 ASSERT(HandleList != NULL);
217 for (HandleListWalker = HandleList
218 ; HandleListWalker != NULL && *HandleListWalker != NULL /*&& !EFI_ERROR(Status)*/
219 ; HandleListWalker++
220 ){
221
222 //
223 // get all the info on each handle
224 //
225 Name = NULL;
226 Status = GetDeviceHandleInfo(*HandleListWalker, &Type, &Cfg, &Diag, &Parents, &Devices, &Children, &Name, Language);
227 if (Name != NULL && (Parents != 0 || Devices != 0 || Children != 0)) {
228 ShellPrintHiiEx (
229 -1,
230 -1,
231 Language,
232 SfoFlag?STRING_TOKEN (STR_DEVICES_ITEM_LINE_SFO):STRING_TOKEN (STR_DEVICES_ITEM_LINE),
233 gShellDriver1HiiHandle,
234 ConvertHandleToHandleIndex (*HandleListWalker),
235 Type,
236 Cfg?(SfoFlag?L'Y':L'X'):(SfoFlag?L'N':L'-'),
237 Diag?(SfoFlag?L'Y':L'X'):(SfoFlag?L'N':L'-'),
238 Parents,
239 Devices,
240 Children,
241 Name!=NULL?Name:L"<UNKNOWN>");
242 }
243 if (Name != NULL) {
244 FreePool(Name);
245 }
246 if (ShellGetExecutionBreakFlag ()) {
247 ShellStatus = SHELL_ABORTED;
248 break;
249 }
250
251 }
252
253 if (HandleList != NULL) {
254 FreePool(HandleList);
255 }
256
257 }
258 SHELL_FREE_NON_NULL(Language);
259 ShellCommandLineFreeVarList (Package);
260 }
261 return (ShellStatus);
262}
263
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette