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