]>
Commit | Line | Data |
---|---|---|
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 | 43 | EFI_STATUS\r |
44 | EFIAPI\r | |
45 | GetDeviceHandleInfo (\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 | |
361a8267 | 61 | UINTN TestHandle = 0x43;\r |
62 | \r | |
4ba49616 | 63 | if (TheHandle == NULL \r |
64 | || Type == NULL\r | |
65 | || Cfg == NULL\r | |
66 | || Diag == NULL\r | |
67 | || Parents == NULL\r | |
68 | || Devices == NULL\r | |
69 | || Children == NULL\r | |
70 | || Name == NULL ) {\r | |
71 | return (EFI_INVALID_PARAMETER);\r | |
72 | }\r | |
73 | \r | |
361a8267 | 74 | if (ConvertHandleToHandleIndex(TheHandle) == TestHandle) {\r |
75 | TestHandle = TestHandle;\r | |
76 | }\r | |
77 | \r | |
4ba49616 | 78 | *Cfg = FALSE;\r |
79 | *Diag = FALSE;\r | |
80 | *Children = 0;\r | |
81 | *Parents = 0;\r | |
82 | *Devices = 0;\r | |
83 | *Type = L' ';\r | |
84 | *Name = CHAR_NULL;\r | |
85 | HandleBuffer = NULL;\r | |
86 | Status = EFI_SUCCESS;\r | |
87 | \r | |
88 | gEfiShellProtocol->GetDeviceName(TheHandle, EFI_DEVICE_NAME_USE_COMPONENT_NAME|EFI_DEVICE_NAME_USE_DEVICE_PATH, (CHAR8*)Language, Name);\r | |
89 | \r | |
90 | Status = ParseHandleDatabaseForChildControllers(TheHandle, Children, NULL);\r | |
361a8267 | 91 | // if (!EFI_ERROR(Status)) {\r |
4ba49616 | 92 | Status = PARSE_HANDLE_DATABASE_PARENTS(TheHandle, Parents, NULL);\r |
93 | if (/*!EFI_ERROR(Status) && */Parents != NULL && Children != NULL) {\r | |
94 | if (*Parents == 0) {\r | |
95 | *Type = L'R';\r | |
96 | } else if (*Children > 0) {\r | |
97 | *Type = L'B';\r | |
98 | } else {\r | |
99 | *Type = L'D';\r | |
100 | }\r | |
101 | }\r | |
361a8267 | 102 | // }\r |
4ba49616 | 103 | Status = PARSE_HANDLE_DATABASE_UEFI_DRIVERS(TheHandle, Devices, &HandleBuffer);\r |
104 | if (!EFI_ERROR(Status) && Devices != NULL && HandleBuffer != NULL) {\r | |
105 | for (Count = 0 ; Count < *Devices ; Count++) {\r | |
106 | if (!EFI_ERROR(gBS->OpenProtocol(HandleBuffer[Count], &gEfiDriverConfigurationProtocolGuid, NULL, NULL, gImageHandle, EFI_OPEN_PROTOCOL_TEST_PROTOCOL))) {\r | |
107 | *Cfg = TRUE;\r | |
108 | }\r | |
109 | if (!EFI_ERROR(gBS->OpenProtocol(HandleBuffer[Count], &gEfiDriverDiagnosticsProtocolGuid, NULL, NULL, gImageHandle, EFI_OPEN_PROTOCOL_TEST_PROTOCOL))) {\r | |
110 | *Diag = TRUE;\r | |
111 | }\r | |
112 | if (!EFI_ERROR(gBS->OpenProtocol(HandleBuffer[Count], &gEfiDriverDiagnostics2ProtocolGuid, NULL, NULL, gImageHandle, EFI_OPEN_PROTOCOL_TEST_PROTOCOL))) {\r | |
113 | *Diag = TRUE;\r | |
114 | }\r | |
115 | }\r | |
116 | SHELL_FREE_NON_NULL(HandleBuffer);\r | |
117 | }\r | |
118 | \r | |
119 | return (Status);\r | |
120 | }\r | |
121 | \r | |
122 | STATIC CONST SHELL_PARAM_ITEM ParamList[] = {\r | |
123 | {L"-l", TypeValue},\r | |
124 | {NULL, TypeMax}\r | |
125 | };\r | |
126 | \r | |
127 | /**\r | |
128 | Function for 'devices' command.\r | |
129 | \r | |
130 | @param[in] ImageHandle Handle to the Image (NULL if Internal).\r | |
131 | @param[in] SystemTable Pointer to the System Table (NULL if Internal).\r | |
132 | **/\r | |
133 | SHELL_STATUS\r | |
134 | EFIAPI\r | |
135 | ShellCommandRunDevices (\r | |
136 | IN EFI_HANDLE ImageHandle,\r | |
137 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
138 | )\r | |
139 | {\r | |
140 | EFI_STATUS Status;\r | |
141 | LIST_ENTRY *Package;\r | |
142 | CHAR16 *ProblemParam;\r | |
143 | SHELL_STATUS ShellStatus;\r | |
144 | CHAR8 *Language;\r | |
145 | EFI_HANDLE *HandleList;\r | |
146 | EFI_HANDLE *HandleListWalker;\r | |
147 | CHAR16 Type;\r | |
148 | BOOLEAN Cfg;\r | |
149 | BOOLEAN Diag;\r | |
150 | UINTN Parents;\r | |
151 | UINTN Devices;\r | |
152 | UINTN Children;\r | |
153 | CHAR16 *Name;\r | |
154 | CONST CHAR16 *Lang;\r | |
155 | \r | |
156 | ShellStatus = SHELL_SUCCESS;\r | |
157 | Language = NULL;\r | |
158 | \r | |
159 | //\r | |
160 | // initialize the shell lib (we must be in non-auto-init...)\r | |
161 | //\r | |
162 | Status = ShellInitialize();\r | |
163 | ASSERT_EFI_ERROR(Status);\r | |
164 | \r | |
165 | Status = CommandInit();\r | |
166 | ASSERT_EFI_ERROR(Status);\r | |
167 | \r | |
168 | //\r | |
169 | // parse the command line\r | |
170 | //\r | |
171 | Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);\r | |
172 | if (EFI_ERROR(Status)) {\r | |
173 | if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {\r | |
174 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDriver1HiiHandle, ProblemParam);\r | |
175 | FreePool(ProblemParam);\r | |
176 | ShellStatus = SHELL_INVALID_PARAMETER;\r | |
177 | } else {\r | |
178 | ASSERT(FALSE);\r | |
179 | }\r | |
180 | } else {\r | |
181 | //\r | |
182 | // if more than 0 'value' parameters we have too many parameters\r | |
183 | //\r | |
184 | if (ShellCommandLineGetRawValue(Package, 1) != NULL){\r | |
185 | //\r | |
186 | // error for too many parameters\r | |
187 | //\r | |
188 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDriver1HiiHandle);\r | |
189 | ShellStatus = SHELL_INVALID_PARAMETER;\r | |
190 | } else {\r | |
191 | //\r | |
192 | // get the language if necessary\r | |
193 | //\r | |
194 | Lang = ShellCommandLineGetValue(Package, L"-l");\r | |
195 | if (Lang != NULL) {\r | |
196 | Language = AllocateZeroPool(StrSize(Lang));\r | |
197 | AsciiSPrint(Language, StrSize(Lang), "%S", Lang);\r | |
198 | } else if (!ShellCommandLineGetFlag(Package, L"-l")){\r | |
199 | ASSERT(Language == NULL);\r | |
200 | // Language = AllocateZeroPool(10);\r | |
201 | // AsciiSPrint(Language, 10, "en-us");\r | |
202 | } else {\r | |
203 | ASSERT(Language == NULL);\r | |
204 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDriver1HiiHandle, L"-l");\r | |
205 | ShellCommandLineFreeVarList (Package);\r | |
206 | return (SHELL_INVALID_PARAMETER);\r | |
207 | }\r | |
208 | \r | |
209 | \r | |
210 | //\r | |
211 | // Print Header\r | |
212 | //\r | |
213 | ShellPrintHiiEx(-1, -1, Language, STRING_TOKEN (STR_DEVICES_HEADER_LINES), gShellDriver1HiiHandle);\r | |
214 | \r | |
215 | //\r | |
216 | // loop through each handle\r | |
217 | //\r | |
218 | HandleList = GetHandleListByProtocol(NULL);\r | |
219 | ASSERT(HandleList != NULL);\r | |
220 | for (HandleListWalker = HandleList\r | |
221 | ; HandleListWalker != NULL && *HandleListWalker != NULL /*&& !EFI_ERROR(Status)*/\r | |
222 | ; HandleListWalker++\r | |
223 | ){\r | |
224 | \r | |
225 | //\r | |
226 | // get all the info on each handle\r | |
227 | //\r | |
228 | Name = NULL;\r | |
229 | Status = GetDeviceHandleInfo(*HandleListWalker, &Type, &Cfg, &Diag, &Parents, &Devices, &Children, &Name, Language);\r | |
361a8267 | 230 | if (Name != NULL && (Parents != 0 || Devices != 0 || Children != 0)) {\r |
4ba49616 | 231 | ShellPrintHiiEx(\r |
232 | -1,\r | |
233 | -1,\r | |
234 | Language,\r | |
235 | STRING_TOKEN (STR_DEVICES_ITEM_LINE),\r | |
236 | gShellDriver1HiiHandle,\r | |
237 | ConvertHandleToHandleIndex(*HandleListWalker),\r | |
238 | Type,\r | |
239 | Cfg?L'X':L'-',\r | |
240 | Diag?L'X':L'-',\r | |
241 | Parents,\r | |
242 | Devices,\r | |
243 | Children,\r | |
244 | Name!=NULL?Name:L"<UNKNOWN>");\r | |
245 | }\r | |
246 | if (Name != NULL) {\r | |
247 | FreePool(Name);\r | |
248 | }\r | |
249 | }\r | |
250 | \r | |
251 | if (HandleList != NULL) {\r | |
252 | FreePool(HandleList);\r | |
253 | }\r | |
254 | \r | |
255 | }\r | |
256 | SHELL_FREE_NON_NULL(Language);\r | |
257 | ShellCommandLineFreeVarList (Package);\r | |
258 | }\r | |
259 | return (ShellStatus);\r | |
260 | }\r | |
261 | \r |