ComponentName.c 15 KB

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