HandleParsingLib.h 15 KB

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