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