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