TianoCore EDK2 master
Loading...
Searching...
No Matches
Devices.c
Go to the documentation of this file.
1
11
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 {
64 return (EFI_INVALID_PARAMETER);
65 }
66
67 *Cfg = FALSE;
68 *Diag = FALSE;
69 *Children = 0;
70 *Parents = 0;
71 *Devices = 0;
72 *Type = L' ';
73 *Name = CHAR_NULL;
74 HandleBuffer = NULL;
75 Status = EFI_SUCCESS;
76
77 gEfiShellProtocol->GetDeviceName (TheHandle, EFI_DEVICE_NAME_USE_COMPONENT_NAME|EFI_DEVICE_NAME_USE_DEVICE_PATH, (CHAR8 *)Language, Name);
78
79 Status = ParseHandleDatabaseForChildControllers (TheHandle, Children, NULL);
80 // if (!EFI_ERROR(Status)) {
81 Status = PARSE_HANDLE_DATABASE_PARENTS (TheHandle, Parents, NULL);
82 if ( (Parents != NULL) && (Children != NULL)) {
83 if (*Parents == 0) {
84 *Type = L'R';
85 } else if (*Children > 0) {
86 *Type = L'B';
87 } else {
88 *Type = L'D';
89 }
90 }
91
92 // }
93 Status = PARSE_HANDLE_DATABASE_UEFI_DRIVERS (TheHandle, Devices, &HandleBuffer);
94 if (!EFI_ERROR (Status) && (Devices != NULL) && (HandleBuffer != NULL)) {
95 for (Count = 0; Count < *Devices; Count++) {
96 if (!EFI_ERROR (gBS->OpenProtocol (HandleBuffer[Count], &gEfiDriverConfigurationProtocolGuid, NULL, NULL, gImageHandle, EFI_OPEN_PROTOCOL_TEST_PROTOCOL))) {
97 *Cfg = TRUE;
98 }
99
100 if (!EFI_ERROR (gBS->OpenProtocol (HandleBuffer[Count], &gEfiDriverDiagnosticsProtocolGuid, NULL, NULL, gImageHandle, EFI_OPEN_PROTOCOL_TEST_PROTOCOL))) {
101 *Diag = TRUE;
102 }
103
104 if (!EFI_ERROR (gBS->OpenProtocol (HandleBuffer[Count], &gEfiDriverDiagnostics2ProtocolGuid, NULL, NULL, gImageHandle, EFI_OPEN_PROTOCOL_TEST_PROTOCOL))) {
105 *Diag = TRUE;
106 }
107 }
108
109 SHELL_FREE_NON_NULL (HandleBuffer);
110 }
111
112 return (Status);
113}
114
115STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
116 { L"-sfo", TypeFlag },
117 { L"-l", TypeValue },
118 { NULL, TypeMax }
119};
120
128EFIAPI
130 IN EFI_HANDLE ImageHandle,
131 IN EFI_SYSTEM_TABLE *SystemTable
132 )
133{
134 EFI_STATUS Status;
135 LIST_ENTRY *Package;
136 CHAR16 *ProblemParam;
137 SHELL_STATUS ShellStatus;
138 CHAR8 *Language;
139 EFI_HANDLE *HandleList;
140 EFI_HANDLE *HandleListWalker;
141 CHAR16 Type;
142 BOOLEAN Cfg;
143 BOOLEAN Diag;
144 UINTN Parents;
145 UINTN Devices;
146 UINTN Children;
147 CHAR16 *Name;
148 CONST CHAR16 *Lang;
149 BOOLEAN SfoFlag;
150
151 ShellStatus = SHELL_SUCCESS;
152 Language = NULL;
153 SfoFlag = FALSE;
154
155 //
156 // initialize the shell lib (we must be in non-auto-init...)
157 //
158 Status = ShellInitialize ();
159 ASSERT_EFI_ERROR (Status);
160
161 Status = CommandInit ();
162 ASSERT_EFI_ERROR (Status);
163
164 //
165 // parse the command line
166 //
167 Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
168 if (EFI_ERROR (Status)) {
169 if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) {
170 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDriver1HiiHandle, L"devices", ProblemParam);
171 FreePool (ProblemParam);
172 ShellStatus = SHELL_INVALID_PARAMETER;
173 } else {
174 ASSERT (FALSE);
175 }
176 } else {
177 //
178 // if more than 0 'value' parameters we have too many parameters
179 //
180 if (ShellCommandLineGetRawValue (Package, 1) != NULL) {
181 //
182 // error for too many parameters
183 //
184 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDriver1HiiHandle, L"devices");
185 ShellStatus = SHELL_INVALID_PARAMETER;
186 } else {
187 //
188 // get the language if necessary
189 //
190 Lang = ShellCommandLineGetValue (Package, L"-l");
191 if (Lang != NULL) {
192 Language = AllocateZeroPool (StrSize (Lang));
193 if (Language == NULL) {
194 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellDriver1HiiHandle, L"devices");
196 return (SHELL_OUT_OF_RESOURCES);
197 }
198
199 AsciiSPrint (Language, StrSize (Lang), "%S", Lang);
200 } else if (!ShellCommandLineGetFlag (Package, L"-l")) {
201 ASSERT (Language == NULL);
202 // Language = AllocateZeroPool(10);
203 // AsciiSPrint(Language, 10, "en-us");
204 } else {
205 ASSERT (Language == NULL);
206 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDriver1HiiHandle, L"devices", L"-l");
209 }
210
211 //
212 // Print Header
213
214 //
215 if (ShellCommandLineGetFlag (Package, L"-sfo")) {
216 ShellPrintHiiEx (-1, -1, Language, STRING_TOKEN (STR_GEN_SFO_HEADER), gShellDriver1HiiHandle, L"devices");
217 SfoFlag = TRUE;
218 } else {
219 ShellPrintHiiEx (-1, -1, Language, STRING_TOKEN (STR_DEVICES_HEADER_LINES), gShellDriver1HiiHandle);
220 }
221
222 //
223 // loop through each handle
224 //
225 HandleList = GetHandleListByProtocol (NULL);
226 ASSERT (HandleList != NULL);
227 for (HandleListWalker = HandleList
228 ; HandleListWalker != NULL && *HandleListWalker != NULL /*&& !EFI_ERROR(Status)*/
229 ; HandleListWalker++
230 )
231 {
232 //
233 // get all the info on each handle
234 //
235 Name = NULL;
236 Status = GetDeviceHandleInfo (*HandleListWalker, &Type, &Cfg, &Diag, &Parents, &Devices, &Children, &Name, Language);
237 if ((Name != NULL) && ((Parents != 0) || (Devices != 0) || (Children != 0))) {
239 -1,
240 -1,
241 Language,
242 SfoFlag ? STRING_TOKEN (STR_DEVICES_ITEM_LINE_SFO) : STRING_TOKEN (STR_DEVICES_ITEM_LINE),
243 gShellDriver1HiiHandle,
244 ConvertHandleToHandleIndex (*HandleListWalker),
245 Type,
246 Cfg ? (SfoFlag ? L'Y' : L'X') : (SfoFlag ? L'N' : L'-'),
247 Diag ? (SfoFlag ? L'Y' : L'X') : (SfoFlag ? L'N' : L'-'),
248 Parents,
249 Devices,
250 Children,
251 Name != NULL ? Name : L"<UNKNOWN>"
252 );
253 }
254
255 if (Name != NULL) {
256 FreePool (Name);
257 }
258
260 ShellStatus = SHELL_ABORTED;
261 break;
262 }
263 }
264
265 if (HandleList != NULL) {
266 FreePool (HandleList);
267 }
268 }
269
270 SHELL_FREE_NON_NULL (Language);
272 }
273
274 return (ShellStatus);
275}
UINT64 UINTN
UINTN EFIAPI StrSize(IN CONST CHAR16 *String)
Definition: String.c:72
SHELL_STATUS EFIAPI ShellCommandRunDevices(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: Devices.c:129
EFI_STATUS GetDeviceHandleInfo(IN EFI_HANDLE TheHandle, IN OUT CHAR16 *Type, IN OUT BOOLEAN *Cfg, IN OUT BOOLEAN *Diag, IN OUT UINTN *Parents, IN OUT UINTN *Devices, IN OUT UINTN *Children, OUT CHAR16 **Name, IN CONST CHAR8 *Language)
Definition: Devices.c:39
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
#define PARSE_HANDLE_DATABASE_PARENTS(ControllerHandle, Count, Buffer)
#define PARSE_HANDLE_DATABASE_UEFI_DRIVERS(ControllerHandle, Count, Buffer)
UINTN EFIAPI ConvertHandleToHandleIndex(IN CONST EFI_HANDLE TheHandle)
EFI_STATUS EFIAPI ParseHandleDatabaseForChildControllers(IN CONST EFI_HANDLE ControllerHandle, OUT UINTN *MatchingHandleCount, OUT EFI_HANDLE **MatchingHandleBuffer OPTIONAL)
EFI_HANDLE *EFIAPI GetHandleListByProtocol(IN CONST EFI_GUID *ProtocolGuid OPTIONAL)
UINTN EFIAPI AsciiSPrint(OUT CHAR8 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR8 *FormatString,...)
Definition: PrintLib.c:813
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define STATIC
Definition: Base.h:264
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
SHELL_STATUS
Definition: Shell.h:21
@ SHELL_OUT_OF_RESOURCES
Definition: Shell.h:73
@ SHELL_ABORTED
Definition: Shell.h:128
@ SHELL_SUCCESS
Definition: Shell.h:25
@ SHELL_INVALID_PARAMETER
Definition: Shell.h:35
EFI_STATUS EFIAPI CommandInit(VOID)
CONST CHAR16 *EFIAPI ShellCommandLineGetValue(IN CONST LIST_ENTRY *CheckPackage, IN CHAR16 *KeyString)
BOOLEAN EFIAPI ShellGetExecutionBreakFlag(VOID)
#define ShellCommandLineParse(CheckList, CheckPackage, ProblemParam, AutoPageBreak)
Make it easy to upgrade from older versions of the shell library.
Definition: ShellLib.h:755
EFI_STATUS EFIAPI ShellPrintHiiEx(IN INT32 Col OPTIONAL, IN INT32 Row OPTIONAL, IN CONST CHAR8 *Language OPTIONAL, IN CONST EFI_STRING_ID HiiFormatStringId, IN CONST EFI_HII_HANDLE HiiFormatHandle,...)
BOOLEAN EFIAPI ShellCommandLineGetFlag(IN CONST LIST_ENTRY *CONST CheckPackage, IN CONST CHAR16 *CONST KeyString)
@ TypeValue
A flag that has some data following it with a space (IE "-a 1").
Definition: ShellLib.h:700
@ TypeFlag
A flag that is present or not present only (IE "-a").
Definition: ShellLib.h:699
VOID EFIAPI ShellCommandLineFreeVarList(IN LIST_ENTRY *CheckPackage)
EFI_STATUS EFIAPI ShellInitialize(VOID)
Definition: UefiShellLib.c:532
CONST CHAR16 *EFIAPI ShellCommandLineGetRawValue(IN CONST LIST_ENTRY *CONST CheckPackage, IN UINTN Position)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_HANDLE gImageHandle
EFI_BOOT_SERVICES * gBS
#define STRING_TOKEN(t)