2 Provides interface to advanced shell functionality for parsing both handle and protocol database.
4 Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #ifndef __HANDLE_PARSING_LIB__
16 #define __HANDLE_PARSING_LIB__
21 Function to add a new GUID/Name mapping.
23 This cannot overwrite an existing mapping.
25 @param[in] Guid The Guid
26 @param[in] TheName The Guid's name
27 @param[in] Lang RFC4646 language code list or NULL
29 @retval EFI_SUCCESS The operation was sucessful
30 @retval EFI_ACCESS_DENIED There was a duplicate
31 @retval EFI_OUT_OF_RESOURCES A memory allocation failed
35 AddNewGuidNameMapping(
36 IN CONST EFI_GUID
*Guid
,
37 IN CONST CHAR16
*TheName
,
38 IN CONST CHAR8
*Lang OPTIONAL
42 Function to get the name of a protocol or struct from it's GUID.
44 If Guid is NULL, then ASSERT.
46 @param[in] Guid The GUID to look for the name of.
47 @param[in] Lang The language to use.
49 @return The pointer to a string of the name. The caller
50 is responsible to free this memory.
54 GetStringNameFromGuid(
55 IN CONST EFI_GUID
*Guid
,
56 IN CONST CHAR8
*Lang OPTIONAL
60 Function to get the Guid for a protocol or struct based on it's string name.
62 Do not free or modify the returned GUID.
64 @param[in] Name The pointer to the string name.
65 @param[in] Lang The pointer to the language code (string).
66 @param[out] Guid The pointer to the pointer to the Guid.
68 @retval EFI_SUCCESS The operation was successful.
72 GetGuidFromStringName(
73 IN CONST CHAR16
*Name
,
74 IN CONST CHAR8
*Lang OPTIONAL
,
79 Function to dump protocol information from a handle.
81 This function will return a allocated string buffer containing the
82 information. The caller is responsible for freeing the memory.
84 If Guid is NULL, ASSERT().
85 If TheHandle is NULL, ASSERT().
87 @param[in] TheHandle The handle to dump information from.
88 @param[in] Guid The GUID of the protocol to dump.
89 @param[in] Verbose TRUE for extra info. FALSE otherwise.
91 @return The pointer to string.
92 @retval NULL An error was encountered.
96 GetProtocolInformationDump(
97 IN CONST EFI_HANDLE TheHandle
,
98 IN CONST EFI_GUID
*Guid
,
99 IN CONST BOOLEAN Verbose
103 Function to retrieve the driver name (if possible) from the ComponentName or
104 ComponentName2 protocol.
106 The string returned must be callee freed.
108 @param[in] TheHandle The driver handle to get the name of.
109 @param[in] Language The language to use.
111 @retval NULL The name could not be found.
112 @return A pointer to the string name. Do not de-allocate the memory.
116 GetStringNameFromHandle(
117 IN CONST EFI_HANDLE TheHandle
,
118 IN CONST CHAR8
*Language
122 Get best support language for this driver.
124 First base on the user input language to search, second base on the current
125 platform used language to search, third get the first language from the
126 support language list. The caller need to free the buffer of the best language.
128 @param[in] SupportedLanguages The support languages for this driver.
129 @param[in] InputLanguage The user input language.
130 @param[in] Iso639Language Whether get language for ISO639.
132 @return The best support language for this driver.
136 GetBestLanguageForDriver (
137 IN CONST CHAR8
*SupportedLanguages
,
138 IN CONST CHAR8
*InputLanguage
,
139 IN BOOLEAN Iso639Language
143 #define HR_IMAGE_HANDLE BIT1
144 #define HR_DRIVER_BINDING_HANDLE BIT2 // has driver binding
145 #define HR_DEVICE_DRIVER BIT3 // device driver (hybrid?)
146 #define HR_BUS_DRIVER BIT4 // a bus driver (hybrid?)
147 #define HR_DRIVER_CONFIGURATION_HANDLE BIT5
148 #define HR_DRIVER_DIAGNOSTICS_HANDLE BIT6
149 #define HR_COMPONENT_NAME_HANDLE BIT7
150 #define HR_DEVICE_HANDLE BIT8
151 #define HR_PARENT_HANDLE BIT9
152 #define HR_CONTROLLER_HANDLE BIT10
153 #define HR_CHILD_HANDLE BIT11
154 #define HR_VALID_MASK (BIT1|BIT2|BIT3|BIT4|BIT5|BIT6|BIT7|BIT8|BIT9|BIT10|BIT11)
157 Gets all the related EFI_HANDLEs based on the mask supplied.
159 This function will scan all EFI_HANDLES in the UEFI environment's handle database
160 and return all the ones with the specified relationship (Mask) to the specified
163 If both DriverBindingHandle and ControllerHandle are NULL, then ASSERT.
164 If MatchingHandleCount is NULL, then ASSERT.
166 If MatchingHandleBuffer is not NULL upon a successful return, the memory must be
169 @param[in] DriverBindingHandle The handle with Driver Binding protocol on it.
170 @param[in] ControllerHandle The handle with Device Path protocol on it.
171 @param[in] Mask The mask of what relationship(s) is desired.
172 @param[in] MatchingHandleCount The pointer to UINTN specifying number of HANDLES in
173 MatchingHandleBuffer.
174 @param[out] MatchingHandleBuffer On a successful return, a buffer of MatchingHandleCount
175 EFI_HANDLEs with a terminating NULL EFI_HANDLE.
177 @retval EFI_SUCCESS The operation was successful, and any related handles
178 are in MatchingHandleBuffer.
179 @retval EFI_NOT_FOUND No matching handles were found.
180 @retval EFI_INVALID_PARAMETER A parameter was invalid or out of range.
181 @sa ParseHandleDatabaseByRelationshipWithType
185 ParseHandleDatabaseByRelationship (
186 IN CONST EFI_HANDLE DriverBindingHandle OPTIONAL
,
187 IN CONST EFI_HANDLE ControllerHandle OPTIONAL
,
189 IN UINTN
*MatchingHandleCount
,
190 OUT EFI_HANDLE
**MatchingHandleBuffer OPTIONAL
194 Gets all the related EFI_HANDLEs based on the mask supplied.
196 This function scans all EFI_HANDLES in the UEFI environment's handle database
197 and returns the ones with the specified relationship (Mask) to the specified
200 If both DriverBindingHandle and ControllerHandle are NULL, then ASSERT.
201 If MatchingHandleCount is NULL, then ASSERT.
203 If MatchingHandleBuffer is not NULL upon a successful return the memory must be
206 @param[in] DriverBindingHandle The handle with Driver Binding protocol on it.
207 @param[in] ControllerHandle The handle with Device Path protocol on it.
208 @param[in] MatchingHandleCount The pointer to UINTN that specifies the number of HANDLES in
209 MatchingHandleBuffer.
210 @param[out] MatchingHandleBuffer On a successful return, a buffer of MatchingHandleCount
211 EFI_HANDLEs with a terminating NULL EFI_HANDLE.
212 @param[out] HandleType An array of type information.
214 @retval EFI_SUCCESS The operation was successful, and any related handles
215 are in MatchingHandleBuffer.
216 @retval EFI_NOT_FOUND No matching handles were found.
217 @retval EFI_INVALID_PARAMETER A parameter was invalid or out of range.
221 ParseHandleDatabaseByRelationshipWithType (
222 IN CONST EFI_HANDLE DriverBindingHandle OPTIONAL
,
223 IN CONST EFI_HANDLE ControllerHandle OPTIONAL
,
224 IN UINTN
*HandleCount
,
225 OUT EFI_HANDLE
**HandleBuffer
,
226 OUT UINTN
**HandleType
230 Gets handles for any parents of the passed in controller.
232 @param[in] ControllerHandle The handle of the controller.
233 @param[in] Count The pointer to the number of handles in
234 MatchingHandleBuffer on return.
235 @param[out] Buffer The buffer containing handles on a successful
237 @retval EFI_SUCCESS The operation was successful.
238 @sa ParseHandleDatabaseByRelationship
240 #define PARSE_HANDLE_DATABASE_PARENTS(ControllerHandle, Count, Buffer) \
241 ParseHandleDatabaseByRelationship(NULL, ControllerHandle, HR_PARENT_HANDLE, Count, Buffer)
244 Gets handles for any UEFI drivers of the passed in controller.
246 @param[in] ControllerHandle The handle of the controller.
247 @param[in] Count The pointer to the number of handles in
248 MatchingHandleBuffer on return.
249 @param[out] Buffer The buffer containing handles on a successful
251 @retval EFI_SUCCESS The operation was successful.
252 @sa ParseHandleDatabaseByRelationship
254 #define PARSE_HANDLE_DATABASE_UEFI_DRIVERS(ControllerHandle, Count, Buffer) \
255 ParseHandleDatabaseByRelationship(NULL, ControllerHandle, HR_DRIVER_BINDING_HANDLE|HR_DEVICE_DRIVER, Count, Buffer)
258 Gets handles for any children of the passed in controller by the passed in driver handle.
260 @param[in] DriverHandle The handle of the driver.
261 @param[in] ControllerHandle The handle of the controller.
262 @param[in] Count The pointer to the number of handles in
263 MatchingHandleBuffer on return.
264 @param[out] Buffer The buffer containing handles on a successful
266 @retval EFI_SUCCESS The operation was successful.
267 @sa ParseHandleDatabaseByRelationship
269 #define PARSE_HANDLE_DATABASE_MANAGED_CHILDREN(DriverHandle, ControllerHandle, Count, Buffer) \
270 ParseHandleDatabaseByRelationship(DriverHandle, ControllerHandle, HR_CHILD_HANDLE|HR_DEVICE_HANDLE, Count, Buffer)
273 Gets handles for any devices managed by the passed in driver.
275 @param[in] DriverHandle The handle of the driver.
276 @param[in] Count The pointer to the number of handles in
277 MatchingHandleBuffer on return.
278 @param[out] Buffer The buffer containing handles on a successful
280 @retval EFI_SUCCESS The operation was successful.
281 @sa ParseHandleDatabaseByRelationship
283 #define PARSE_HANDLE_DATABASE_DEVICES(DriverHandle, Count, Buffer) \
284 ParseHandleDatabaseByRelationship(DriverHandle, NULL, HR_CONTROLLER_HANDLE|HR_DEVICE_HANDLE, Count, Buffer)
287 Gets handles for any child devices produced by the passed in driver.
289 @param[in] DriverHandle The handle of the driver.
290 @param[in] MatchingHandleCount The pointer to the number of handles in
291 MatchingHandleBuffer on return.
292 @param[out] MatchingHandleBuffer The buffer containing handles on a successful
294 @retval EFI_SUCCESS The operation was successful.
295 @sa ParseHandleDatabaseByRelationship
299 ParseHandleDatabaseForChildDevices(
300 IN CONST EFI_HANDLE DriverHandle
,
301 IN UINTN
*MatchingHandleCount
,
302 OUT EFI_HANDLE
**MatchingHandleBuffer OPTIONAL
306 Gets handles for any child controllers of the passed in controller.
308 @param[in] ControllerHandle The handle of the "parent controller".
309 @param[in] MatchingHandleCount The pointer to the number of handles in
310 MatchingHandleBuffer on return.
311 @param[out] MatchingHandleBuffer The buffer containing handles on a successful
313 @retval EFI_SUCCESS The operation was successful.
314 @sa ParseHandleDatabaseByRelationship
318 ParseHandleDatabaseForChildControllers(
319 IN CONST EFI_HANDLE ControllerHandle
,
320 IN UINTN
*MatchingHandleCount
,
321 OUT EFI_HANDLE
**MatchingHandleBuffer OPTIONAL
326 Function to retrieve the human-friendly index of a given handle. If the handle
327 does not have a index one will be automatically assigned. The index value is valid
328 until the termination of the shell application.
330 @param[in] TheHandle The handle to retrieve an index for.
332 @retval 0 A memory allocation failed.
333 @return The index of the handle.
338 ConvertHandleToHandleIndex(
339 IN CONST EFI_HANDLE TheHandle
343 Function to retrieve the EFI_HANDLE from the human-friendly index.
345 @param[in] TheIndex The index to retrieve the EFI_HANDLE for.
347 @retval NULL The index was invalid.
348 @return The EFI_HANDLE that index represents.
353 ConvertHandleIndexToHandle(
354 IN CONST UINTN TheIndex
358 Function to get all handles that support a given protocol or all handles.
360 The caller is responsible to free this memory.
362 @param[in] ProtocolGuid The guid of the protocol to get handles for. If NULL
363 then the function will return all handles.
365 @retval NULL A memory allocation failed.
366 @return A NULL terminated list of handles.
370 GetHandleListByProtocol (
371 IN CONST EFI_GUID
*ProtocolGuid OPTIONAL
375 Function to get all handles that support some protocols.
377 The caller is responsible to free this memory.
379 @param[in] ProtocolGuids A NULL terminated list of protocol GUIDs.
381 @retval NULL A memory allocation failed.
382 @retval NULL ProtocolGuids was NULL.
383 @return A NULL terminated list of EFI_HANDLEs.
387 GetHandleListByProtocolList (
388 IN CONST EFI_GUID
**ProtocolGuids
391 #endif // __HANDLE_PARSING_LIB__