ComponentName.c 15 KB

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