ComponentName.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /** @file
  2. Component Name code for the virtio-net driver.
  3. Copyright (C) 2013, Red Hat, Inc.
  4. Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
  5. SPDX-License-Identifier: BSD-2-Clause-Patent
  6. **/
  7. #include <Library/UefiLib.h>
  8. #include "VirtioNet.h"
  9. STATIC
  10. EFI_UNICODE_STRING_TABLE mVirtioNetDriverNameTable[] = {
  11. { "eng;en", L"Virtio Network Driver" },
  12. { NULL, NULL }
  13. };
  14. STATIC
  15. EFI_UNICODE_STRING_TABLE mVirtioNetControllerNameTable[] = {
  16. { "eng;en", L"Virtio Network Device" },
  17. { NULL, NULL }
  18. };
  19. /**
  20. Retrieves a Unicode string that is the user-readable name of the EFI Driver.
  21. @param This A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
  22. @param Language A pointer to a three-character ISO 639-2 language
  23. identifier. This is the language of the driver name that
  24. that the caller is requesting, and it must match one of
  25. the languages specified in SupportedLanguages. The number
  26. of languages supported by a driver is up to the driver
  27. writer.
  28. @param DriverName A pointer to the Unicode string to return. This Unicode
  29. string is the name of the driver specified by This in the
  30. language specified by Language.
  31. @retval EFI_SUCCESS The Unicode string for the Driver specified by
  32. This and the language specified by Language was
  33. returned in DriverName.
  34. @retval EFI_INVALID_PARAMETER Language is NULL.
  35. @retval EFI_INVALID_PARAMETER DriverName is NULL.
  36. @retval EFI_UNSUPPORTED The driver specified by This does not support
  37. the language specified by Language.
  38. **/
  39. STATIC
  40. EFI_STATUS
  41. EFIAPI
  42. VirtioNetGetDriverName (
  43. IN EFI_COMPONENT_NAME_PROTOCOL *This,
  44. IN CHAR8 *Language,
  45. OUT CHAR16 **DriverName
  46. )
  47. {
  48. return (Language == NULL || DriverName == NULL) ?
  49. EFI_INVALID_PARAMETER :
  50. LookupUnicodeString2 (
  51. Language,
  52. This->SupportedLanguages,
  53. mVirtioNetDriverNameTable,
  54. DriverName,
  55. (BOOLEAN)(This == &gVirtioNetComponentName) // Iso639Language
  56. );
  57. }
  58. /**
  59. Retrieves a Unicode string that is the user readable name of the controller
  60. that is being managed by an EFI Driver.
  61. @param This A pointer to the EFI_COMPONENT_NAME_PROTOCOL
  62. instance.
  63. @param ControllerHandle The handle of a controller that the driver specified
  64. by This is managing. This handle specifies the
  65. controller whose name is to be returned.
  66. @param ChildHandle The handle of the child controller to retrieve the
  67. name of. This is an optional parameter that may be
  68. NULL. It will be NULL for device drivers. It will
  69. also be NULL for a bus drivers that wish to retrieve
  70. the name of the bus controller. It will not be NULL
  71. for a bus driver that wishes to retrieve the name of
  72. a child controller.
  73. @param Language A pointer to a three character ISO 639-2 language
  74. identifier. This is the language of the controller
  75. name that the caller is requesting, and it must
  76. match one of the languages specified in
  77. SupportedLanguages. The number of languages
  78. supported by a driver is up to the driver writer.
  79. @param ControllerName A pointer to the Unicode string to return. This
  80. Unicode string is the name of the controller
  81. specified by ControllerHandle and ChildHandle in the
  82. language specified by Language, from the point of
  83. view of the driver specified by This.
  84. @retval EFI_SUCCESS The Unicode string for the user-readable name
  85. in the language specified by Language for the
  86. driver specified by This was returned in
  87. DriverName.
  88. @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
  89. @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
  90. EFI_HANDLE.
  91. @retval EFI_INVALID_PARAMETER Language is NULL.
  92. @retval EFI_INVALID_PARAMETER ControllerName is NULL.
  93. @retval EFI_UNSUPPORTED The driver specified by This is not currently
  94. managing the controller specified by
  95. ControllerHandle and ChildHandle.
  96. @retval EFI_UNSUPPORTED The driver specified by This does not support
  97. the language specified by Language.
  98. **/
  99. STATIC
  100. EFI_STATUS
  101. EFIAPI
  102. VirtioNetGetControllerName (
  103. IN EFI_COMPONENT_NAME_PROTOCOL *This,
  104. IN EFI_HANDLE ControllerHandle,
  105. IN EFI_HANDLE ChildHandle,
  106. IN CHAR8 *Language,
  107. OUT CHAR16 **ControllerName
  108. )
  109. {
  110. EFI_STATUS Status;
  111. if ((ControllerHandle == NULL) || (Language == NULL) || (ControllerName == NULL)) {
  112. return EFI_INVALID_PARAMETER;
  113. }
  114. //
  115. // This is a device driver, so ChildHandle must be NULL.
  116. //
  117. if (ChildHandle != NULL) {
  118. return EFI_UNSUPPORTED;
  119. }
  120. //
  121. // confirm that the device is managed by this driver, using the VirtIo
  122. // Protocol
  123. //
  124. Status = EfiTestManagedDevice (
  125. ControllerHandle,
  126. gVirtioNetDriverBinding.DriverBindingHandle,
  127. &gVirtioDeviceProtocolGuid
  128. );
  129. if (EFI_ERROR (Status)) {
  130. return Status;
  131. }
  132. //
  133. // we don't give different names to the bus (= parent) handle and the
  134. // child (= MAC) handle
  135. //
  136. return LookupUnicodeString2 (
  137. Language,
  138. This->SupportedLanguages,
  139. mVirtioNetControllerNameTable,
  140. ControllerName,
  141. (BOOLEAN)(This == &gVirtioNetComponentName) // Iso639Language
  142. );
  143. }
  144. EFI_COMPONENT_NAME_PROTOCOL gVirtioNetComponentName = {
  145. &VirtioNetGetDriverName,
  146. &VirtioNetGetControllerName,
  147. "eng" // SupportedLanguages, ISO 639-2 language codes
  148. };
  149. EFI_COMPONENT_NAME2_PROTOCOL gVirtioNetComponentName2 = {
  150. (EFI_COMPONENT_NAME2_GET_DRIVER_NAME)&VirtioNetGetDriverName,
  151. (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME)&VirtioNetGetControllerName,
  152. "en" // SupportedLanguages, RFC 4646 language codes
  153. };