]> git.proxmox.com Git - mirror_edk2.git/blame - ShellPkg/Include/Library/HandleParsingLib.h
ShellPkg: Move UpdateMapping() out of Map command and added to UefiShellCommandLib...
[mirror_edk2.git] / ShellPkg / Include / Library / HandleParsingLib.h
CommitLineData
a405b86d 1/** @file\r
2 Provides interface to advanced shell functionality for parsing both handle and protocol database.\r
3\r
a71003f2 4 Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>\r
a405b86d 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#ifndef __HANDLE_PARSING_LIB__\r
16#define __HANDLE_PARSING_LIB__\r
17\r
18#include <Uefi.h>\r
19\r
20/**\r
21 Function to get the name of a protocol or struct from it's GUID.\r
22\r
23 If Guid is NULL, then ASSERT.\r
24\r
25 @param[in] Guid The GUID to look for the name of.\r
26 @param[in] Lang The language to use.\r
27\r
28 @return The pointer to a string of the name. The caller\r
29 is responsible to free this memory.\r
30**/\r
31CHAR16*\r
32EFIAPI\r
33GetStringNameFromGuid(\r
34 IN CONST EFI_GUID *Guid,\r
35 IN CONST CHAR8 *Lang OPTIONAL\r
36 );\r
37\r
38/**\r
39 Function to get the Guid for a protocol or struct based on it's string name.\r
40\r
41 @param[in] Name The pointer to the string name.\r
42 @param[in] Lang The pointer to the language code (string).\r
43 @param[in] Guid The pointer to the pointer to the Guid.\r
44\r
45 @retval EFI_SUCCESS The operation was successful.\r
46**/\r
47EFI_STATUS\r
48EFIAPI\r
49GetGuidFromStringName(\r
50 IN CONST CHAR16 *Name,\r
51 IN CONST CHAR8 *Lang OPTIONAL,\r
52 IN EFI_GUID **Guid\r
53 );\r
54\r
55/**\r
56 Function to dump protocol information from a handle.\r
57\r
58 This function will return a allocated string buffer containing the\r
59 information. The caller is responsible for freeing the memory.\r
60\r
61 If Guid is NULL, ASSERT().\r
62 If TheHandle is NULL, ASSERT().\r
63\r
64 @param[in] TheHandle The handle to dump information from.\r
65 @param[in] Guid The GUID of the protocol to dump.\r
66 @param[in] Verbose TRUE for extra info. FALSE otherwise.\r
67\r
68 @return The pointer to string.\r
69 @retval NULL An error was encountered.\r
70**/\r
71CHAR16*\r
72EFIAPI\r
73GetProtocolInformationDump(\r
74 IN CONST EFI_HANDLE TheHandle,\r
75 IN CONST EFI_GUID *Guid,\r
76 IN CONST BOOLEAN Verbose\r
77 );\r
78\r
79/**\r
80 Function to retrieve the driver name (if possible) from the ComponentName or\r
81 ComponentName2 protocol.\r
82\r
83 The string returned must be callee freed.\r
84\r
85 @param[in] TheHandle The driver handle to get the name of.\r
86 @param[in] Language The language to use.\r
87\r
88 @retval NULL The name could not be found.\r
89 @return A pointer to the string name. Do not de-allocate the memory.\r
90**/\r
91CONST CHAR16*\r
92EFIAPI\r
93GetStringNameFromHandle(\r
94 IN CONST EFI_HANDLE TheHandle,\r
95 IN CONST CHAR8 *Language\r
96 );\r
97\r
a71003f2
ED
98/**\r
99 Get best support language for this driver.\r
100 \r
101 First base on the user input language to search, second base on the current \r
102 platform used language to search, third get the first language from the \r
103 support language list. The caller need to free the buffer of the best language.\r
104\r
105 @param[in] SupportedLanguages The support languages for this driver.\r
106 @param[in] InputLanguage The user input language.\r
107 @param[in] Iso639Language Whether get language for ISO639.\r
108\r
109 @return The best support language for this driver.\r
110**/\r
111CHAR8 *\r
112EFIAPI\r
113GetBestLanguageForDriver (\r
114 IN CONST CHAR8 *SupportedLanguages,\r
115 IN CONST CHAR8 *InputLanguage,\r
116 IN BOOLEAN Iso639Language\r
117 );\r
118\r
a405b86d 119#define HR_UNKNOWN 0\r
120#define HR_IMAGE_HANDLE BIT1\r
121#define HR_DRIVER_BINDING_HANDLE BIT2 // has driver binding\r
122#define HR_DEVICE_DRIVER BIT3 // device driver (hybrid?)\r
123#define HR_BUS_DRIVER BIT4 // a bus driver (hybrid?)\r
124#define HR_DRIVER_CONFIGURATION_HANDLE BIT5\r
125#define HR_DRIVER_DIAGNOSTICS_HANDLE BIT6\r
126#define HR_COMPONENT_NAME_HANDLE BIT7\r
127#define HR_DEVICE_HANDLE BIT8\r
128#define HR_PARENT_HANDLE BIT9\r
129#define HR_CONTROLLER_HANDLE BIT10\r
130#define HR_CHILD_HANDLE BIT11\r
131#define HR_VALID_MASK (BIT1|BIT2|BIT3|BIT4|BIT5|BIT6|BIT7|BIT8|BIT9|BIT10|BIT11)\r
132\r
133/**\r
134 Gets all the related EFI_HANDLEs based on the mask supplied.\r
135\r
136 This function will scan all EFI_HANDLES in the UEFI environment's handle database\r
137 and return all the ones with the specified relationship (Mask) to the specified\r
138 controller handle.\r
139\r
140 If both DriverBindingHandle and ControllerHandle are NULL, then ASSERT.\r
141 If MatchingHandleCount is NULL, then ASSERT.\r
142\r
143 If MatchingHandleBuffer is not NULL upon a successful return, the memory must be\r
144 caller freed.\r
145\r
146 @param[in] DriverBindingHandle The handle with Driver Binding protocol on it.\r
147 @param[in] ControllerHandle The handle with Device Path protocol on it.\r
148 @param[in] Mask The mask of what relationship(s) is desired.\r
149 @param[in] MatchingHandleCount The pointer to UINTN specifying number of HANDLES in\r
150 MatchingHandleBuffer.\r
151 @param[out] MatchingHandleBuffer On a successful return, a buffer of MatchingHandleCount\r
152 EFI_HANDLEs with a terminating NULL EFI_HANDLE.\r
153\r
154 @retval EFI_SUCCESS The operation was successful, and any related handles\r
155 are in MatchingHandleBuffer.\r
156 @retval EFI_NOT_FOUND No matching handles were found.\r
157 @retval EFI_INVALID_PARAMETER A parameter was invalid or out of range.\r
158 @sa ParseHandleDatabaseByRelationshipWithType\r
159**/\r
160EFI_STATUS\r
161EFIAPI\r
162ParseHandleDatabaseByRelationship (\r
163 IN CONST EFI_HANDLE DriverBindingHandle OPTIONAL,\r
164 IN CONST EFI_HANDLE ControllerHandle OPTIONAL,\r
165 IN CONST UINTN Mask,\r
166 IN UINTN *MatchingHandleCount,\r
167 OUT EFI_HANDLE **MatchingHandleBuffer OPTIONAL\r
168 );\r
169\r
170/**\r
171 Gets all the related EFI_HANDLEs based on the mask supplied.\r
172\r
173 This function scans all EFI_HANDLES in the UEFI environment's handle database\r
174 and returns the ones with the specified relationship (Mask) to the specified\r
175 controller handle.\r
176\r
177 If both DriverBindingHandle and ControllerHandle are NULL, then ASSERT.\r
178 If MatchingHandleCount is NULL, then ASSERT.\r
179\r
180 If MatchingHandleBuffer is not NULL upon a successful return the memory must be\r
181 caller freed.\r
182\r
183 @param[in] DriverBindingHandle The handle with Driver Binding protocol on it.\r
184 @param[in] ControllerHandle The handle with Device Path protocol on it.\r
185 @param[in] MatchingHandleCount The pointer to UINTN that specifies the number of HANDLES in\r
186 MatchingHandleBuffer.\r
187 @param[out] MatchingHandleBuffer On a successful return, a buffer of MatchingHandleCount\r
188 EFI_HANDLEs with a terminating NULL EFI_HANDLE.\r
189 @param[out] HandleType An array of type information.\r
190\r
191 @retval EFI_SUCCESS The operation was successful, and any related handles\r
192 are in MatchingHandleBuffer.\r
193 @retval EFI_NOT_FOUND No matching handles were found.\r
194 @retval EFI_INVALID_PARAMETER A parameter was invalid or out of range.\r
195**/\r
196EFI_STATUS\r
197EFIAPI\r
198ParseHandleDatabaseByRelationshipWithType (\r
199 IN CONST EFI_HANDLE DriverBindingHandle OPTIONAL,\r
200 IN CONST EFI_HANDLE ControllerHandle OPTIONAL,\r
201 IN UINTN *HandleCount,\r
202 OUT EFI_HANDLE **HandleBuffer,\r
203 OUT UINTN **HandleType\r
204 );\r
205\r
206/**\r
207 Gets handles for any parents of the passed in controller.\r
208\r
209 @param[in] ControllerHandle The handle of the controller.\r
210 @param[in] Count The pointer to the number of handles in\r
211 MatchingHandleBuffer on return.\r
212 @param[out] Buffer The buffer containing handles on a successful\r
213 return.\r
214 @retval EFI_SUCCESS The operation was successful.\r
215 @sa ParseHandleDatabaseByRelationship\r
216**/\r
217#define PARSE_HANDLE_DATABASE_PARENTS(ControllerHandle, Count, Buffer) \\r
218 ParseHandleDatabaseByRelationship(NULL, ControllerHandle, HR_PARENT_HANDLE, Count, Buffer)\r
219\r
220/**\r
221 Gets handles for any UEFI drivers of the passed in controller.\r
222\r
223 @param[in] ControllerHandle The handle of the controller.\r
224 @param[in] Count The pointer to the number of handles in\r
225 MatchingHandleBuffer on return.\r
226 @param[out] Buffer The buffer containing handles on a successful\r
227 return.\r
228 @retval EFI_SUCCESS The operation was successful.\r
229 @sa ParseHandleDatabaseByRelationship\r
230**/\r
231#define PARSE_HANDLE_DATABASE_UEFI_DRIVERS(ControllerHandle, Count, Buffer) \\r
232 ParseHandleDatabaseByRelationship(NULL, ControllerHandle, HR_DRIVER_BINDING_HANDLE|HR_DEVICE_DRIVER, Count, Buffer)\r
233\r
234/**\r
235 Gets handles for any children of the passed in controller by the passed in driver handle.\r
236\r
237 @param[in] DriverHandle The handle of the driver.\r
238 @param[in] ControllerHandle The handle of the controller.\r
239 @param[in] Count The pointer to the number of handles in\r
240 MatchingHandleBuffer on return.\r
241 @param[out] Buffer The buffer containing handles on a successful\r
242 return.\r
243 @retval EFI_SUCCESS The operation was successful.\r
244 @sa ParseHandleDatabaseByRelationship\r
245**/\r
246#define PARSE_HANDLE_DATABASE_MANAGED_CHILDREN(DriverHandle, ControllerHandle, Count, Buffer) \\r
247 ParseHandleDatabaseByRelationship(DriverHandle, ControllerHandle, HR_CHILD_HANDLE|HR_DEVICE_HANDLE, Count, Buffer)\r
248\r
249/**\r
250 Gets handles for any devices managed by the passed in driver.\r
251\r
252 @param[in] DriverHandle The handle of the driver.\r
253 @param[in] Count The pointer to the number of handles in\r
254 MatchingHandleBuffer on return.\r
255 @param[out] Buffer The buffer containing handles on a successful\r
256 return.\r
257 @retval EFI_SUCCESS The operation was successful.\r
258 @sa ParseHandleDatabaseByRelationship\r
259**/\r
260#define PARSE_HANDLE_DATABASE_DEVICES(DriverHandle, Count, Buffer) \\r
261 ParseHandleDatabaseByRelationship(DriverHandle, NULL, HR_CONTROLLER_HANDLE|HR_DEVICE_HANDLE, Count, Buffer)\r
262\r
263/**\r
264 Gets handles for any child devices produced by the passed in driver.\r
265\r
266 @param[in] DriverHandle The handle of the driver.\r
267 @param[in] MatchingHandleCount The pointer to the number of handles in\r
268 MatchingHandleBuffer on return.\r
269 @param[out] MatchingHandleBuffer The buffer containing handles on a successful\r
270 return.\r
271 @retval EFI_SUCCESS The operation was successful.\r
272 @sa ParseHandleDatabaseByRelationship\r
273**/\r
274EFI_STATUS\r
275EFIAPI\r
276ParseHandleDatabaseForChildDevices(\r
277 IN CONST EFI_HANDLE DriverHandle,\r
278 IN UINTN *MatchingHandleCount,\r
279 OUT EFI_HANDLE **MatchingHandleBuffer OPTIONAL\r
280 );\r
281\r
282/**\r
283 Gets handles for any child controllers of the passed in controller.\r
284\r
285 @param[in] ControllerHandle The handle of the "parent controller".\r
286 @param[in] MatchingHandleCount The pointer to the number of handles in\r
287 MatchingHandleBuffer on return.\r
288 @param[out] MatchingHandleBuffer The buffer containing handles on a successful\r
289 return.\r
290 @retval EFI_SUCCESS The operation was successful.\r
291 @sa ParseHandleDatabaseByRelationship\r
292**/\r
293EFI_STATUS\r
294EFIAPI\r
295ParseHandleDatabaseForChildControllers(\r
296 IN CONST EFI_HANDLE ControllerHandle,\r
297 IN UINTN *MatchingHandleCount,\r
298 OUT EFI_HANDLE **MatchingHandleBuffer OPTIONAL\r
299 );\r
300\r
301\r
302/**\r
303 Function to retrieve the human-friendly index of a given handle. If the handle\r
304 does not have a index one will be automatically assigned. The index value is valid\r
305 until the termination of the shell application.\r
306\r
307 @param[in] TheHandle The handle to retrieve an index for.\r
308\r
309 @retval 0 A memory allocation failed.\r
310 @return The index of the handle.\r
311\r
312**/\r
313UINTN\r
314EFIAPI\r
315ConvertHandleToHandleIndex(\r
316 IN CONST EFI_HANDLE TheHandle\r
317 );\r
318\r
319/**\r
320 Function to retrieve the EFI_HANDLE from the human-friendly index.\r
321\r
322 @param[in] TheIndex The index to retrieve the EFI_HANDLE for.\r
323\r
324 @retval NULL The index was invalid.\r
325 @return The EFI_HANDLE that index represents.\r
326\r
327**/\r
328EFI_HANDLE\r
329EFIAPI\r
330ConvertHandleIndexToHandle(\r
331 IN CONST UINTN TheIndex\r
332 );\r
333\r
334/**\r
335 Function to get all handles that support a given protocol or all handles.\r
336\r
337 @param[in] ProtocolGuid The guid of the protocol to get handles for. If NULL\r
338 then the function will return all handles.\r
339\r
340 @retval NULL A memory allocation failed.\r
341 @return A NULL terminated list of handles.\r
342**/\r
343EFI_HANDLE*\r
344EFIAPI\r
40d7a9cf 345GetHandleListByProtocol (\r
a405b86d 346 IN CONST EFI_GUID *ProtocolGuid OPTIONAL\r
347 );\r
348\r
349/**\r
350 Function to get all handles that support some protocols.\r
351\r
352 @param[in] ProtocolGuids A NULL terminated list of protocol GUIDs.\r
353\r
354 @retval NULL A memory allocation failed.\r
ff51746b 355 @retval NULL ProtocolGuids was NULL.\r
356 @return A NULL terminated list of EFI_HANDLEs.\r
a405b86d 357**/\r
358EFI_HANDLE*\r
359EFIAPI\r
40d7a9cf 360GetHandleListByProtocolList (\r
a405b86d 361 IN CONST EFI_GUID **ProtocolGuids\r
362 );\r
363\r
364#endif // __HANDLE_PARSING_LIB__\r