ComponentName.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /** @file
  2. Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
  3. SPDX-License-Identifier: BSD-2-Clause-Patent
  4. **/
  5. #include "EmuBusDriverDxe.h"
  6. //
  7. // EFI Component Name Functions
  8. //
  9. EFI_STATUS
  10. EFIAPI
  11. EmuBusDriverComponentNameGetDriverName (
  12. IN EFI_COMPONENT_NAME_PROTOCOL *This,
  13. IN CHAR8 *Language,
  14. OUT CHAR16 **DriverName
  15. );
  16. EFI_STATUS
  17. EFIAPI
  18. EmuBusDriverComponentNameGetControllerName (
  19. IN EFI_COMPONENT_NAME_PROTOCOL *This,
  20. IN EFI_HANDLE ControllerHandle,
  21. IN EFI_HANDLE ChildHandle OPTIONAL,
  22. IN CHAR8 *Language,
  23. OUT CHAR16 **ControllerName
  24. );
  25. //
  26. // EFI Component Name Protocol
  27. //
  28. GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gEmuBusDriverComponentName = {
  29. EmuBusDriverComponentNameGetDriverName,
  30. EmuBusDriverComponentNameGetControllerName,
  31. "eng"
  32. };
  33. //
  34. // EFI Component Name 2 Protocol
  35. //
  36. GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gEmuBusDriverComponentName2 = {
  37. (EFI_COMPONENT_NAME2_GET_DRIVER_NAME)EmuBusDriverComponentNameGetDriverName,
  38. (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME)EmuBusDriverComponentNameGetControllerName,
  39. "en"
  40. };
  41. GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mEmuBusDriverNameTable[] = {
  42. { "eng", L"Emu Bus Driver" },
  43. { NULL, NULL }
  44. };
  45. /**
  46. Retrieves a Unicode string that is the user readable name of the driver.
  47. This function retrieves the user readable name of a driver in the form of a
  48. Unicode string. If the driver specified by This has a user readable name in
  49. the language specified by Language, then a pointer to the driver name is
  50. returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
  51. by This does not support the language specified by Language,
  52. then EFI_UNSUPPORTED is returned.
  53. @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
  54. EFI_COMPONENT_NAME_PROTOCOL instance.
  55. @param Language[in] A pointer to a Null-terminated ASCII string
  56. array indicating the language. This is the
  57. language of the driver name that the caller is
  58. requesting, and it must match one of the
  59. languages specified in SupportedLanguages. The
  60. number of languages supported by a driver is up
  61. to the driver writer. Language is specified
  62. in RFC 4646 or ISO 639-2 language code format.
  63. @param DriverName[out] A pointer to the Unicode string to return.
  64. This Unicode string is the name of the
  65. driver specified by This in the language
  66. specified by Language.
  67. @retval EFI_SUCCESS The Unicode string for the Driver specified by
  68. This and the language specified by Language was
  69. returned in DriverName.
  70. @retval EFI_INVALID_PARAMETER Language is NULL.
  71. @retval EFI_INVALID_PARAMETER DriverName is NULL.
  72. @retval EFI_UNSUPPORTED The driver specified by This does not support
  73. the language specified by Language.
  74. **/
  75. EFI_STATUS
  76. EFIAPI
  77. EmuBusDriverComponentNameGetDriverName (
  78. IN EFI_COMPONENT_NAME_PROTOCOL *This,
  79. IN CHAR8 *Language,
  80. OUT CHAR16 **DriverName
  81. )
  82. {
  83. return LookupUnicodeString2 (
  84. Language,
  85. This->SupportedLanguages,
  86. mEmuBusDriverNameTable,
  87. DriverName,
  88. (BOOLEAN)(This == &gEmuBusDriverComponentName)
  89. );
  90. }
  91. /**
  92. Retrieves a Unicode string that is the user readable name of the controller
  93. that is being managed by a driver.
  94. This function retrieves the user readable name of the controller specified by
  95. ControllerHandle and ChildHandle in the form of a Unicode string. If the
  96. driver specified by This has a user readable name in the language specified by
  97. Language, then a pointer to the controller name is returned in ControllerName,
  98. and EFI_SUCCESS is returned. If the driver specified by This is not currently
  99. managing the controller specified by ControllerHandle and ChildHandle,
  100. then EFI_UNSUPPORTED is returned. If the driver specified by This does not
  101. support the language specified by Language, then EFI_UNSUPPORTED is returned.
  102. @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
  103. EFI_COMPONENT_NAME_PROTOCOL instance.
  104. @param ControllerHandle[in] The handle of a controller that the driver
  105. specified by This is managing. This handle
  106. specifies the controller whose name is to be
  107. returned.
  108. @param ChildHandle[in] The handle of the child controller to retrieve
  109. the name of. This is an optional parameter that
  110. may be NULL. It will be NULL for device
  111. drivers. It will also be NULL for a bus drivers
  112. that wish to retrieve the name of the bus
  113. controller. It will not be NULL for a bus
  114. driver that wishes to retrieve the name of a
  115. child controller.
  116. @param Language[in] A pointer to a Null-terminated ASCII string
  117. array indicating the language. This is the
  118. language of the driver name that the caller is
  119. requesting, and it must match one of the
  120. languages specified in SupportedLanguages. The
  121. number of languages supported by a driver is up
  122. to the driver writer. Language is specified in
  123. RFC 4646 or ISO 639-2 language code format.
  124. @param ControllerName[out] A pointer to the Unicode string to return.
  125. This Unicode string is the name of the
  126. controller specified by ControllerHandle and
  127. ChildHandle in the language specified by
  128. Language from the point of view of the driver
  129. specified by This.
  130. @retval EFI_SUCCESS The Unicode string for the user readable name in
  131. the language specified by Language for the
  132. driver specified by This was returned in
  133. DriverName.
  134. @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
  135. @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
  136. EFI_HANDLE.
  137. @retval EFI_INVALID_PARAMETER Language is NULL.
  138. @retval EFI_INVALID_PARAMETER ControllerName is NULL.
  139. @retval EFI_UNSUPPORTED The driver specified by This is not currently
  140. managing the controller specified by
  141. ControllerHandle and ChildHandle.
  142. @retval EFI_UNSUPPORTED The driver specified by This does not support
  143. the language specified by Language.
  144. **/
  145. EFI_STATUS
  146. EFIAPI
  147. EmuBusDriverComponentNameGetControllerName (
  148. IN EFI_COMPONENT_NAME_PROTOCOL *This,
  149. IN EFI_HANDLE ControllerHandle,
  150. IN EFI_HANDLE ChildHandle OPTIONAL,
  151. IN CHAR8 *Language,
  152. OUT CHAR16 **ControllerName
  153. )
  154. {
  155. EFI_STATUS Status;
  156. EMU_IO_THUNK_PROTOCOL *EmuIo;
  157. EMU_IO_DEVICE *Private;
  158. //
  159. // Make sure this driver is currently managing ControllHandle
  160. //
  161. Status = EfiTestManagedDevice (
  162. ControllerHandle,
  163. gEmuBusDriverBinding.DriverBindingHandle,
  164. &gEmuThunkProtocolGuid
  165. );
  166. if (EFI_ERROR (Status)) {
  167. return Status;
  168. }
  169. //
  170. // This is a bus driver, so ChildHandle can not be NULL.
  171. //
  172. if (ChildHandle == NULL) {
  173. return EFI_UNSUPPORTED;
  174. }
  175. Status = EfiTestChildHandle (
  176. ControllerHandle,
  177. ChildHandle,
  178. &gEmuThunkProtocolGuid
  179. );
  180. if (EFI_ERROR (Status)) {
  181. return Status;
  182. }
  183. //
  184. // Get our context back
  185. //
  186. Status = gBS->OpenProtocol (
  187. ChildHandle,
  188. &gEmuIoThunkProtocolGuid,
  189. (VOID **)&EmuIo,
  190. gEmuBusDriverBinding.DriverBindingHandle,
  191. ChildHandle,
  192. EFI_OPEN_PROTOCOL_GET_PROTOCOL
  193. );
  194. if (EFI_ERROR (Status)) {
  195. return EFI_UNSUPPORTED;
  196. }
  197. Private = EMU_IO_DEVICE_FROM_THIS (EmuIo);
  198. return LookupUnicodeString2 (
  199. Language,
  200. This->SupportedLanguages,
  201. Private->ControllerNameTable,
  202. ControllerName,
  203. (BOOLEAN)(This == &gEmuBusDriverComponentName)
  204. );
  205. }