/edk2/Clover/BiosKeyboard/ComponentName.c

https://gitlab.com/envieidoc/Clover · C · 243 lines · 94 code · 13 blank · 136 comment · 8 complexity · 1341641bb61c390f563923014b848a33 MD5 · raw file

  1. /** @file
  2. Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
  3. This program and the accompanying materials
  4. are licensed and made available under the terms and conditions
  5. of the BSD License which accompanies this distribution. The
  6. full text of the license may be found at
  7. http://opensource.org/licenses/bsd-license.php
  8. THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
  10. **/
  11. #include "BiosKeyboard.h"
  12. //
  13. // EFI Component Name Protocol
  14. //
  15. GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gBiosKeyboardComponentName = {
  16. BiosKeyboardComponentNameGetDriverName,
  17. BiosKeyboardComponentNameGetControllerName,
  18. "eng"
  19. };
  20. //
  21. // EFI Component Name 2 Protocol
  22. //
  23. GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gBiosKeyboardComponentName2 = {
  24. (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) BiosKeyboardComponentNameGetDriverName,
  25. (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) BiosKeyboardComponentNameGetControllerName,
  26. "en"
  27. };
  28. GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mBiosKeyboardDriverNameTable[] = {
  29. {
  30. "eng;en",
  31. L"BIOS[INT16] Keyboard Driver"
  32. },
  33. {
  34. NULL,
  35. NULL
  36. }
  37. };
  38. /**
  39. Retrieves a Unicode string that is the user readable name of the driver.
  40. This function retrieves the user readable name of a driver in the form of a
  41. Unicode string. If the driver specified by This has a user readable name in
  42. the language specified by Language, then a pointer to the driver name is
  43. returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
  44. by This does not support the language specified by Language,
  45. then EFI_UNSUPPORTED is returned.
  46. @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
  47. EFI_COMPONENT_NAME_PROTOCOL instance.
  48. @param Language[in] A pointer to a Null-terminated ASCII string
  49. array indicating the language. This is the
  50. language of the driver name that the caller is
  51. requesting, and it must match one of the
  52. languages specified in SupportedLanguages. The
  53. number of languages supported by a driver is up
  54. to the driver writer. Language is specified
  55. in RFC 4646 or ISO 639-2 language code format.
  56. @param DriverName[out] A pointer to the Unicode string to return.
  57. This Unicode string is the name of the
  58. driver specified by This in the language
  59. specified by Language.
  60. @retval EFI_SUCCESS The Unicode string for the Driver specified by
  61. This and the language specified by Language was
  62. returned in DriverName.
  63. @retval EFI_INVALID_PARAMETER Language is NULL.
  64. @retval EFI_INVALID_PARAMETER DriverName is NULL.
  65. @retval EFI_UNSUPPORTED The driver specified by This does not support
  66. the language specified by Language.
  67. **/
  68. EFI_STATUS
  69. EFIAPI
  70. BiosKeyboardComponentNameGetDriverName (
  71. IN EFI_COMPONENT_NAME_PROTOCOL *This,
  72. IN CHAR8 *Language,
  73. OUT CHAR16 **DriverName
  74. )
  75. {
  76. return LookupUnicodeString2 (
  77. Language,
  78. This->SupportedLanguages,
  79. mBiosKeyboardDriverNameTable,
  80. DriverName,
  81. (BOOLEAN)(This == &gBiosKeyboardComponentName)
  82. );
  83. }
  84. /**
  85. Retrieves a Unicode string that is the user readable name of the controller
  86. that is being managed by a driver.
  87. This function retrieves the user readable name of the controller specified by
  88. ControllerHandle and ChildHandle in the form of a Unicode string. If the
  89. driver specified by This has a user readable name in the language specified by
  90. Language, then a pointer to the controller name is returned in ControllerName,
  91. and EFI_SUCCESS is returned. If the driver specified by This is not currently
  92. managing the controller specified by ControllerHandle and ChildHandle,
  93. then EFI_UNSUPPORTED is returned. If the driver specified by This does not
  94. support the language specified by Language, then EFI_UNSUPPORTED is returned.
  95. @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
  96. EFI_COMPONENT_NAME_PROTOCOL instance.
  97. @param ControllerHandle[in] The handle of a controller that the driver
  98. specified by This is managing. This handle
  99. specifies the controller whose name is to be
  100. returned.
  101. @param ChildHandle[in] The handle of the child controller to retrieve
  102. the name of. This is an optional parameter that
  103. may be NULL. It will be NULL for device
  104. drivers. It will also be NULL for a bus drivers
  105. that wish to retrieve the name of the bus
  106. controller. It will not be NULL for a bus
  107. driver that wishes to retrieve the name of a
  108. child controller.
  109. @param Language[in] A pointer to a Null-terminated ASCII string
  110. array indicating the language. This is the
  111. language of the driver name that the caller is
  112. requesting, and it must match one of the
  113. languages specified in SupportedLanguages. The
  114. number of languages supported by a driver is up
  115. to the driver writer. Language is specified in
  116. RFC 4646 or ISO 639-2 language code format.
  117. @param ControllerName[out] A pointer to the Unicode string to return.
  118. This Unicode string is the name of the
  119. controller specified by ControllerHandle and
  120. ChildHandle in the language specified by
  121. Language from the point of view of the driver
  122. specified by This.
  123. @retval EFI_SUCCESS The Unicode string for the user readable name in
  124. the language specified by Language for the
  125. driver specified by This was returned in
  126. DriverName.
  127. @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
  128. @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
  129. EFI_HANDLE.
  130. @retval EFI_INVALID_PARAMETER Language is NULL.
  131. @retval EFI_INVALID_PARAMETER ControllerName is NULL.
  132. @retval EFI_UNSUPPORTED The driver specified by This is not currently
  133. managing the controller specified by
  134. ControllerHandle and ChildHandle.
  135. @retval EFI_UNSUPPORTED The driver specified by This does not support
  136. the language specified by Language.
  137. **/
  138. EFI_STATUS
  139. EFIAPI
  140. BiosKeyboardComponentNameGetControllerName (
  141. IN EFI_COMPONENT_NAME_PROTOCOL *This,
  142. IN EFI_HANDLE ControllerHandle,
  143. IN EFI_HANDLE ChildHandle OPTIONAL,
  144. IN CHAR8 *Language,
  145. OUT CHAR16 **ControllerName
  146. )
  147. {
  148. EFI_STATUS Status;
  149. EFI_SIMPLE_TEXT_INPUT_PROTOCOL *ConIn;
  150. BIOS_KEYBOARD_DEV *ConsoleIn;
  151. EFI_ISA_IO_PROTOCOL *IsaIoProtocol;
  152. //
  153. // This is a device driver, so ChildHandle must be NULL.
  154. //
  155. if (ChildHandle != NULL) {
  156. return EFI_UNSUPPORTED;
  157. }
  158. //
  159. // Check Controller's handle
  160. //
  161. Status = gBS->OpenProtocol (
  162. ControllerHandle,
  163. &gEfiIsaIoProtocolGuid,
  164. (VOID **) &IsaIoProtocol,
  165. gBiosKeyboardDriverBinding.DriverBindingHandle,
  166. ControllerHandle,
  167. EFI_OPEN_PROTOCOL_BY_DRIVER
  168. );
  169. if (!EFI_ERROR (Status)) {
  170. gBS->CloseProtocol (
  171. ControllerHandle,
  172. &gEfiIsaIoProtocolGuid,
  173. gBiosKeyboardDriverBinding.DriverBindingHandle,
  174. ControllerHandle
  175. );
  176. return EFI_UNSUPPORTED;
  177. }
  178. if (Status != EFI_ALREADY_STARTED) {
  179. return EFI_UNSUPPORTED;
  180. }
  181. //
  182. // Get the device context
  183. //
  184. Status = gBS->OpenProtocol (
  185. ControllerHandle,
  186. &gEfiSimpleTextInProtocolGuid,
  187. (VOID **) &ConIn,
  188. gBiosKeyboardDriverBinding.DriverBindingHandle,
  189. ControllerHandle,
  190. EFI_OPEN_PROTOCOL_GET_PROTOCOL
  191. );
  192. if (EFI_ERROR (Status)) {
  193. return Status;
  194. }
  195. ConsoleIn = BIOS_KEYBOARD_DEV_FROM_THIS (ConIn);
  196. return LookupUnicodeString2 (
  197. Language,
  198. This->SupportedLanguages,
  199. ConsoleIn->ControllerNameTable,
  200. ControllerName,
  201. (BOOLEAN)(This == &gBiosKeyboardComponentName)
  202. );
  203. }