2 Provides interface to advanced shell functionality for parsing both handle and protocol database.
4 Copyright (c) 2010, 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 get the name of a protocol or struct from it's GUID.
23 If Guid is NULL, then ASSERT.
25 @param[in] Guid The GUID to look for the name of.
26 @param[in] Lang The language to use.
28 @return The pointer to a string of the name. The caller
29 is responsible to free this memory.
33 GetStringNameFromGuid(
34 IN CONST EFI_GUID
*Guid
,
35 IN CONST CHAR8
*Lang OPTIONAL
39 Function to get the Guid for a protocol or struct based on it's string name.
41 @param[in] Name The pointer to the string name.
42 @param[in] Lang The pointer to the language code (string).
43 @param[in] Guid The pointer to the pointer to the Guid.
45 @retval EFI_SUCCESS The operation was successful.
49 GetGuidFromStringName(
50 IN CONST CHAR16
*Name
,
51 IN CONST CHAR8
*Lang OPTIONAL
,
56 Function to dump protocol information from a handle.
58 This function will return a allocated string buffer containing the
59 information. The caller is responsible for freeing the memory.
61 If Guid is NULL, ASSERT().
62 If TheHandle is NULL, ASSERT().
64 @param[in] TheHandle The handle to dump information from.
65 @param[in] Guid The GUID of the protocol to dump.
66 @param[in] Verbose TRUE for extra info. FALSE otherwise.
68 @return The pointer to string.
69 @retval NULL An error was encountered.
73 GetProtocolInformationDump(
74 IN CONST EFI_HANDLE TheHandle
,
75 IN CONST EFI_GUID
*Guid
,
76 IN CONST BOOLEAN Verbose
80 Function to retrieve the driver name (if possible) from the ComponentName or
81 ComponentName2 protocol.
83 The string returned must be callee freed.
85 @param[in] TheHandle The driver handle to get the name of.
86 @param[in] Language The language to use.
88 @retval NULL The name could not be found.
89 @return A pointer to the string name. Do not de-allocate the memory.
93 GetStringNameFromHandle(
94 IN CONST EFI_HANDLE TheHandle
,
95 IN CONST CHAR8
*Language
99 #define HR_IMAGE_HANDLE BIT1
100 #define HR_DRIVER_BINDING_HANDLE BIT2 // has driver binding
101 #define HR_DEVICE_DRIVER BIT3 // device driver (hybrid?)
102 #define HR_BUS_DRIVER BIT4 // a bus driver (hybrid?)
103 #define HR_DRIVER_CONFIGURATION_HANDLE BIT5
104 #define HR_DRIVER_DIAGNOSTICS_HANDLE BIT6
105 #define HR_COMPONENT_NAME_HANDLE BIT7
106 #define HR_DEVICE_HANDLE BIT8
107 #define HR_PARENT_HANDLE BIT9
108 #define HR_CONTROLLER_HANDLE BIT10
109 #define HR_CHILD_HANDLE BIT11
110 #define HR_VALID_MASK (BIT1|BIT2|BIT3|BIT4|BIT5|BIT6|BIT7|BIT8|BIT9|BIT10|BIT11)
113 Gets all the related EFI_HANDLEs based on the mask supplied.
115 This function will scan all EFI_HANDLES in the UEFI environment's handle database
116 and return all the ones with the specified relationship (Mask) to the specified
119 If both DriverBindingHandle and ControllerHandle are NULL, then ASSERT.
120 If MatchingHandleCount is NULL, then ASSERT.
122 If MatchingHandleBuffer is not NULL upon a successful return, the memory must be
125 @param[in] DriverBindingHandle The handle with Driver Binding protocol on it.
126 @param[in] ControllerHandle The handle with Device Path protocol on it.
127 @param[in] Mask The mask of what relationship(s) is desired.
128 @param[in] MatchingHandleCount The pointer to UINTN specifying number of HANDLES in
129 MatchingHandleBuffer.
130 @param[out] MatchingHandleBuffer On a successful return, a buffer of MatchingHandleCount
131 EFI_HANDLEs with a terminating NULL EFI_HANDLE.
133 @retval EFI_SUCCESS The operation was successful, and any related handles
134 are in MatchingHandleBuffer.
135 @retval EFI_NOT_FOUND No matching handles were found.
136 @retval EFI_INVALID_PARAMETER A parameter was invalid or out of range.
137 @sa ParseHandleDatabaseByRelationshipWithType
141 ParseHandleDatabaseByRelationship (
142 IN CONST EFI_HANDLE DriverBindingHandle OPTIONAL
,
143 IN CONST EFI_HANDLE ControllerHandle OPTIONAL
,
145 IN UINTN
*MatchingHandleCount
,
146 OUT EFI_HANDLE
**MatchingHandleBuffer OPTIONAL
150 Gets all the related EFI_HANDLEs based on the mask supplied.
152 This function scans all EFI_HANDLES in the UEFI environment's handle database
153 and returns the ones with the specified relationship (Mask) to the specified
156 If both DriverBindingHandle and ControllerHandle are NULL, then ASSERT.
157 If MatchingHandleCount is NULL, then ASSERT.
159 If MatchingHandleBuffer is not NULL upon a successful return the memory must be
162 @param[in] DriverBindingHandle The handle with Driver Binding protocol on it.
163 @param[in] ControllerHandle The handle with Device Path protocol on it.
164 @param[in] MatchingHandleCount The pointer to UINTN that specifies the number of HANDLES in
165 MatchingHandleBuffer.
166 @param[out] MatchingHandleBuffer On a successful return, a buffer of MatchingHandleCount
167 EFI_HANDLEs with a terminating NULL EFI_HANDLE.
168 @param[out] HandleType An array of type information.
170 @retval EFI_SUCCESS The operation was successful, and any related handles
171 are in MatchingHandleBuffer.
172 @retval EFI_NOT_FOUND No matching handles were found.
173 @retval EFI_INVALID_PARAMETER A parameter was invalid or out of range.
177 ParseHandleDatabaseByRelationshipWithType (
178 IN CONST EFI_HANDLE DriverBindingHandle OPTIONAL
,
179 IN CONST EFI_HANDLE ControllerHandle OPTIONAL
,
180 IN UINTN
*HandleCount
,
181 OUT EFI_HANDLE
**HandleBuffer
,
182 OUT UINTN
**HandleType
186 Gets handles for any parents of the passed in controller.
188 @param[in] ControllerHandle The handle of the controller.
189 @param[in] Count The pointer to the number of handles in
190 MatchingHandleBuffer on return.
191 @param[out] Buffer The buffer containing handles on a successful
193 @retval EFI_SUCCESS The operation was successful.
194 @sa ParseHandleDatabaseByRelationship
196 #define PARSE_HANDLE_DATABASE_PARENTS(ControllerHandle, Count, Buffer) \
197 ParseHandleDatabaseByRelationship(NULL, ControllerHandle, HR_PARENT_HANDLE, Count, Buffer)
200 Gets handles for any UEFI drivers of the passed in controller.
202 @param[in] ControllerHandle The handle of the controller.
203 @param[in] Count The pointer to the number of handles in
204 MatchingHandleBuffer on return.
205 @param[out] Buffer The buffer containing handles on a successful
207 @retval EFI_SUCCESS The operation was successful.
208 @sa ParseHandleDatabaseByRelationship
210 #define PARSE_HANDLE_DATABASE_UEFI_DRIVERS(ControllerHandle, Count, Buffer) \
211 ParseHandleDatabaseByRelationship(NULL, ControllerHandle, HR_DRIVER_BINDING_HANDLE|HR_DEVICE_DRIVER, Count, Buffer)
214 Gets handles for any children of the passed in controller by the passed in driver handle.
216 @param[in] DriverHandle The handle of the driver.
217 @param[in] ControllerHandle The handle of the controller.
218 @param[in] Count The pointer to the number of handles in
219 MatchingHandleBuffer on return.
220 @param[out] Buffer The buffer containing handles on a successful
222 @retval EFI_SUCCESS The operation was successful.
223 @sa ParseHandleDatabaseByRelationship
225 #define PARSE_HANDLE_DATABASE_MANAGED_CHILDREN(DriverHandle, ControllerHandle, Count, Buffer) \
226 ParseHandleDatabaseByRelationship(DriverHandle, ControllerHandle, HR_CHILD_HANDLE|HR_DEVICE_HANDLE, Count, Buffer)
229 Gets handles for any devices managed by the passed in driver.
231 @param[in] DriverHandle The handle of the driver.
232 @param[in] Count The pointer to the number of handles in
233 MatchingHandleBuffer on return.
234 @param[out] Buffer The buffer containing handles on a successful
236 @retval EFI_SUCCESS The operation was successful.
237 @sa ParseHandleDatabaseByRelationship
239 #define PARSE_HANDLE_DATABASE_DEVICES(DriverHandle, Count, Buffer) \
240 ParseHandleDatabaseByRelationship(DriverHandle, NULL, HR_CONTROLLER_HANDLE|HR_DEVICE_HANDLE, Count, Buffer)
243 Gets handles for any child devices produced by the passed in driver.
245 @param[in] DriverHandle The handle of the driver.
246 @param[in] MatchingHandleCount The pointer to the number of handles in
247 MatchingHandleBuffer on return.
248 @param[out] MatchingHandleBuffer The buffer containing handles on a successful
250 @retval EFI_SUCCESS The operation was successful.
251 @sa ParseHandleDatabaseByRelationship
255 ParseHandleDatabaseForChildDevices(
256 IN CONST EFI_HANDLE DriverHandle
,
257 IN UINTN
*MatchingHandleCount
,
258 OUT EFI_HANDLE
**MatchingHandleBuffer OPTIONAL
262 Gets handles for any child controllers of the passed in controller.
264 @param[in] ControllerHandle The handle of the "parent controller".
265 @param[in] MatchingHandleCount The pointer to the number of handles in
266 MatchingHandleBuffer on return.
267 @param[out] MatchingHandleBuffer The buffer containing handles on a successful
269 @retval EFI_SUCCESS The operation was successful.
270 @sa ParseHandleDatabaseByRelationship
274 ParseHandleDatabaseForChildControllers(
275 IN CONST EFI_HANDLE ControllerHandle
,
276 IN UINTN
*MatchingHandleCount
,
277 OUT EFI_HANDLE
**MatchingHandleBuffer OPTIONAL
282 Function to retrieve the human-friendly index of a given handle. If the handle
283 does not have a index one will be automatically assigned. The index value is valid
284 until the termination of the shell application.
286 @param[in] TheHandle The handle to retrieve an index for.
288 @retval 0 A memory allocation failed.
289 @return The index of the handle.
294 ConvertHandleToHandleIndex(
295 IN CONST EFI_HANDLE TheHandle
299 Function to retrieve the EFI_HANDLE from the human-friendly index.
301 @param[in] TheIndex The index to retrieve the EFI_HANDLE for.
303 @retval NULL The index was invalid.
304 @return The EFI_HANDLE that index represents.
309 ConvertHandleIndexToHandle(
310 IN CONST UINTN TheIndex
314 Function to get all handles that support a given protocol or all handles.
316 @param[in] ProtocolGuid The guid of the protocol to get handles for. If NULL
317 then the function will return all handles.
319 @retval NULL A memory allocation failed.
320 @return A NULL terminated list of handles.
324 GetHandleListByProtocol (
325 IN CONST EFI_GUID
*ProtocolGuid OPTIONAL
329 Function to get all handles that support some protocols.
331 @param[in] ProtocolGuids A NULL terminated list of protocol GUIDs.
333 @retval NULL A memory allocation failed.
334 @return A NULL terminated list of handles.
338 GetHandleListByProtocolList (
339 IN CONST EFI_GUID
**ProtocolGuids
342 #endif // __HANDLE_PARSING_LIB__