ComponentName.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. /**@file
  2. Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
  3. SPDX-License-Identifier: BSD-2-Clause-Patent
  4. Module Name:
  5. ComponentName.c
  6. Abstract:
  7. **/
  8. #include "EmuBlockIo.h"
  9. //
  10. // EFI Component Name Functions
  11. //
  12. /**
  13. Retrieves a Unicode string that is the user readable name of the driver.
  14. This function retrieves the user readable name of a driver in the form of a
  15. Unicode string. If the driver specified by This has a user readable name in
  16. the language specified by Language, then a pointer to the driver name is
  17. returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
  18. by This does not support the language specified by Language,
  19. then EFI_UNSUPPORTED is returned.
  20. @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
  21. EFI_COMPONENT_NAME_PROTOCOL instance.
  22. @param Language[in] A pointer to a Null-terminated ASCII string
  23. array indicating the language. This is the
  24. language of the driver name that the caller is
  25. requesting, and it must match one of the
  26. languages specified in SupportedLanguages. The
  27. number of languages supported by a driver is up
  28. to the driver writer. Language is specified
  29. in RFC 4646 or ISO 639-2 language code format.
  30. @param DriverName[out] A pointer to the Unicode string to return.
  31. This Unicode string is the name of the
  32. driver specified by This in the language
  33. specified by Language.
  34. @retval EFI_SUCCESS The Unicode string for the Driver specified by
  35. This and the language specified by Language was
  36. returned in DriverName.
  37. @retval EFI_INVALID_PARAMETER Language is NULL.
  38. @retval EFI_INVALID_PARAMETER DriverName is NULL.
  39. @retval EFI_UNSUPPORTED The driver specified by This does not support
  40. the language specified by Language.
  41. **/
  42. EFI_STATUS
  43. EFIAPI
  44. EmuBlockIoComponentNameGetDriverName (
  45. IN EFI_COMPONENT_NAME_PROTOCOL *This,
  46. IN CHAR8 *Language,
  47. OUT CHAR16 **DriverName
  48. );
  49. /**
  50. Retrieves a Unicode string that is the user readable name of the controller
  51. that is being managed by a driver.
  52. This function retrieves the user readable name of the controller specified by
  53. ControllerHandle and ChildHandle in the form of a Unicode string. If the
  54. driver specified by This has a user readable name in the language specified by
  55. Language, then a pointer to the controller name is returned in ControllerName,
  56. and EFI_SUCCESS is returned. If the driver specified by This is not currently
  57. managing the controller specified by ControllerHandle and ChildHandle,
  58. then EFI_UNSUPPORTED is returned. If the driver specified by This does not
  59. support the language specified by Language, then EFI_UNSUPPORTED is returned.
  60. @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
  61. EFI_COMPONENT_NAME_PROTOCOL instance.
  62. @param ControllerHandle[in] The handle of a controller that the driver
  63. specified by This is managing. This handle
  64. specifies the controller whose name is to be
  65. returned.
  66. @param ChildHandle[in] The handle of the child controller to retrieve
  67. the name of. This is an optional parameter that
  68. may be NULL. It will be NULL for device
  69. drivers. It will also be NULL for a bus drivers
  70. that wish to retrieve the name of the bus
  71. controller. It will not be NULL for a bus
  72. driver that wishes to retrieve the name of a
  73. child controller.
  74. @param Language[in] A pointer to a Null-terminated ASCII string
  75. array indicating the language. This is the
  76. language of the driver name that the caller is
  77. requesting, and it must match one of the
  78. languages specified in SupportedLanguages. The
  79. number of languages supported by a driver is up
  80. to the driver writer. Language is specified in
  81. RFC 4646 or ISO 639-2 language code format.
  82. @param ControllerName[out] A pointer to the Unicode string to return.
  83. This Unicode string is the name of the
  84. controller specified by ControllerHandle and
  85. ChildHandle in the language specified by
  86. Language from the point of view of the driver
  87. specified by This.
  88. @retval EFI_SUCCESS The Unicode string for the user readable name in
  89. the language specified by Language for the
  90. driver specified by This was returned in
  91. DriverName.
  92. @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
  93. @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
  94. EFI_HANDLE.
  95. @retval EFI_INVALID_PARAMETER Language is NULL.
  96. @retval EFI_INVALID_PARAMETER ControllerName is NULL.
  97. @retval EFI_UNSUPPORTED The driver specified by This is not currently
  98. managing the controller specified by
  99. ControllerHandle and ChildHandle.
  100. @retval EFI_UNSUPPORTED The driver specified by This does not support
  101. the language specified by Language.
  102. **/
  103. EFI_STATUS
  104. EFIAPI
  105. EmuBlockIoComponentNameGetControllerName (
  106. IN EFI_COMPONENT_NAME_PROTOCOL *This,
  107. IN EFI_HANDLE ControllerHandle,
  108. IN EFI_HANDLE ChildHandle OPTIONAL,
  109. IN CHAR8 *Language,
  110. OUT CHAR16 **ControllerName
  111. );
  112. //
  113. // EFI Component Name Protocol
  114. //
  115. GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gEmuBlockIoComponentName = {
  116. EmuBlockIoComponentNameGetDriverName,
  117. EmuBlockIoComponentNameGetControllerName,
  118. "eng"
  119. };
  120. //
  121. // EFI Component Name 2 Protocol
  122. //
  123. GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gEmuBlockIoComponentName2 = {
  124. (EFI_COMPONENT_NAME2_GET_DRIVER_NAME)EmuBlockIoComponentNameGetDriverName,
  125. (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME)EmuBlockIoComponentNameGetControllerName,
  126. "en"
  127. };
  128. EFI_UNICODE_STRING_TABLE mEmuBlockIoDriverNameTable[] = {
  129. { "eng;en", L"Emu Block I/O Driver" },
  130. { NULL, NULL }
  131. };
  132. /**
  133. Retrieves a Unicode string that is the user readable name of the driver.
  134. This function retrieves the user readable name of a driver in the form of a
  135. Unicode string. If the driver specified by This has a user readable name in
  136. the language specified by Language, then a pointer to the driver name is
  137. returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
  138. by This does not support the language specified by Language,
  139. then EFI_UNSUPPORTED is returned.
  140. @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
  141. EFI_COMPONENT_NAME_PROTOCOL instance.
  142. @param Language[in] A pointer to a Null-terminated ASCII string
  143. array indicating the language. This is the
  144. language of the driver name that the caller is
  145. requesting, and it must match one of the
  146. languages specified in SupportedLanguages. The
  147. number of languages supported by a driver is up
  148. to the driver writer. Language is specified
  149. in RFC 4646 or ISO 639-2 language code format.
  150. @param DriverName[out] A pointer to the Unicode string to return.
  151. This Unicode string is the name of the
  152. driver specified by This in the language
  153. specified by Language.
  154. @retval EFI_SUCCESS The Unicode string for the Driver specified by
  155. This and the language specified by Language was
  156. returned in DriverName.
  157. @retval EFI_INVALID_PARAMETER Language is NULL.
  158. @retval EFI_INVALID_PARAMETER DriverName is NULL.
  159. @retval EFI_UNSUPPORTED The driver specified by This does not support
  160. the language specified by Language.
  161. **/
  162. EFI_STATUS
  163. EFIAPI
  164. EmuBlockIoComponentNameGetDriverName (
  165. IN EFI_COMPONENT_NAME_PROTOCOL *This,
  166. IN CHAR8 *Language,
  167. OUT CHAR16 **DriverName
  168. )
  169. {
  170. return LookupUnicodeString2 (
  171. Language,
  172. This->SupportedLanguages,
  173. mEmuBlockIoDriverNameTable,
  174. DriverName,
  175. (BOOLEAN)(This == &gEmuBlockIoComponentName)
  176. );
  177. }
  178. /**
  179. Retrieves a Unicode string that is the user readable name of the controller
  180. that is being managed by a driver.
  181. This function retrieves the user readable name of the controller specified by
  182. ControllerHandle and ChildHandle in the form of a Unicode string. If the
  183. driver specified by This has a user readable name in the language specified by
  184. Language, then a pointer to the controller name is returned in ControllerName,
  185. and EFI_SUCCESS is returned. If the driver specified by This is not currently
  186. managing the controller specified by ControllerHandle and ChildHandle,
  187. then EFI_UNSUPPORTED is returned. If the driver specified by This does not
  188. support the language specified by Language, then EFI_UNSUPPORTED is returned.
  189. @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
  190. EFI_COMPONENT_NAME_PROTOCOL instance.
  191. @param ControllerHandle[in] The handle of a controller that the driver
  192. specified by This is managing. This handle
  193. specifies the controller whose name is to be
  194. returned.
  195. @param ChildHandle[in] The handle of the child controller to retrieve
  196. the name of. This is an optional parameter that
  197. may be NULL. It will be NULL for device
  198. drivers. It will also be NULL for a bus drivers
  199. that wish to retrieve the name of the bus
  200. controller. It will not be NULL for a bus
  201. driver that wishes to retrieve the name of a
  202. child controller.
  203. @param Language[in] A pointer to a Null-terminated ASCII string
  204. array indicating the language. This is the
  205. language of the driver name that the caller is
  206. requesting, and it must match one of the
  207. languages specified in SupportedLanguages. The
  208. number of languages supported by a driver is up
  209. to the driver writer. Language is specified in
  210. RFC 4646 or ISO 639-2 language code format.
  211. @param ControllerName[out] A pointer to the Unicode string to return.
  212. This Unicode string is the name of the
  213. controller specified by ControllerHandle and
  214. ChildHandle in the language specified by
  215. Language from the point of view of the driver
  216. specified by This.
  217. @retval EFI_SUCCESS The Unicode string for the user readable name in
  218. the language specified by Language for the
  219. driver specified by This was returned in
  220. DriverName.
  221. @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
  222. @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
  223. EFI_HANDLE.
  224. @retval EFI_INVALID_PARAMETER Language is NULL.
  225. @retval EFI_INVALID_PARAMETER ControllerName is NULL.
  226. @retval EFI_UNSUPPORTED The driver specified by This is not currently
  227. managing the controller specified by
  228. ControllerHandle and ChildHandle.
  229. @retval EFI_UNSUPPORTED The driver specified by This does not support
  230. the language specified by Language.
  231. **/
  232. EFI_STATUS
  233. EFIAPI
  234. EmuBlockIoComponentNameGetControllerName (
  235. IN EFI_COMPONENT_NAME_PROTOCOL *This,
  236. IN EFI_HANDLE ControllerHandle,
  237. IN EFI_HANDLE ChildHandle OPTIONAL,
  238. IN CHAR8 *Language,
  239. OUT CHAR16 **ControllerName
  240. )
  241. {
  242. EFI_STATUS Status;
  243. EFI_BLOCK_IO_PROTOCOL *BlockIo;
  244. EMU_BLOCK_IO_PRIVATE *Private;
  245. //
  246. // This is a device driver, so ChildHandle must be NULL.
  247. //
  248. if (ChildHandle != NULL) {
  249. return EFI_UNSUPPORTED;
  250. }
  251. //
  252. // Make sure this driver is currently managing ControllerHandle
  253. //
  254. Status = EfiTestManagedDevice (
  255. ControllerHandle,
  256. gEmuBlockIoDriverBinding.DriverBindingHandle,
  257. &gEmuIoThunkProtocolGuid
  258. );
  259. if (EFI_ERROR (Status)) {
  260. return EFI_UNSUPPORTED;
  261. }
  262. //
  263. // Get our context back
  264. //
  265. Status = gBS->OpenProtocol (
  266. ControllerHandle,
  267. &gEfiBlockIoProtocolGuid,
  268. (VOID **)&BlockIo,
  269. gEmuBlockIoDriverBinding.DriverBindingHandle,
  270. ControllerHandle,
  271. EFI_OPEN_PROTOCOL_GET_PROTOCOL
  272. );
  273. if (EFI_ERROR (Status)) {
  274. return EFI_UNSUPPORTED;
  275. }
  276. Private = EMU_BLOCK_IO_PRIVATE_DATA_FROM_THIS (BlockIo);
  277. return LookupUnicodeString2 (
  278. Language,
  279. This->SupportedLanguages,
  280. Private->ControllerNameTable,
  281. ControllerName,
  282. (BOOLEAN)(This == &gEmuBlockIoComponentName)
  283. );
  284. }