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