Update to support to produce Component Name and & Component Name 2 protocol based...
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / UhciDxe / ComponentName.c
1 /** @file
2
3 Copyright (c) 2004 - 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13
14 ComponentName.c
15
16 Abstract:
17
18
19 **/
20
21 #include "uhci.h"
22
23 //
24 // EFI Component Name Functions
25 //
26 /**
27 Retrieves a Unicode string that is the user readable name of the driver.
28
29 This function retrieves the user readable name of a driver in the form of a
30 Unicode string. If the driver specified by This has a user readable name in
31 the language specified by Language, then a pointer to the driver name is
32 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
33 by This does not support the language specified by Language,
34 then EFI_UNSUPPORTED is returned.
35
36 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
37 EFI_COMPONENT_NAME_PROTOCOL instance.
38
39 @param Language[in] A pointer to a Null-terminated ASCII string
40 array indicating the language. This is the
41 language of the driver name that the caller is
42 requesting, and it must match one of the
43 languages specified in SupportedLanguages. The
44 number of languages supported by a driver is up
45 to the driver writer. Language is specified
46 in RFC 3066 or ISO 639-2 language code format.
47
48 @param DriverName[out] A pointer to the Unicode string to return.
49 This Unicode string is the name of the
50 driver specified by This in the language
51 specified by Language.
52
53 @retval EFI_SUCCESS The Unicode string for the Driver specified by
54 This and the language specified by Language was
55 returned in DriverName.
56
57 @retval EFI_INVALID_PARAMETER Language is NULL.
58
59 @retval EFI_INVALID_PARAMETER DriverName is NULL.
60
61 @retval EFI_UNSUPPORTED The driver specified by This does not support
62 the language specified by Language.
63
64 **/
65 EFI_STATUS
66 EFIAPI
67 UhciComponentNameGetDriverName (
68 IN EFI_COMPONENT_NAME_PROTOCOL *This,
69 IN CHAR8 *Language,
70 OUT CHAR16 **DriverName
71 );
72
73
74 /**
75 Retrieves a Unicode string that is the user readable name of the controller
76 that is being managed by a driver.
77
78 This function retrieves the user readable name of the controller specified by
79 ControllerHandle and ChildHandle in the form of a Unicode string. If the
80 driver specified by This has a user readable name in the language specified by
81 Language, then a pointer to the controller name is returned in ControllerName,
82 and EFI_SUCCESS is returned. If the driver specified by This is not currently
83 managing the controller specified by ControllerHandle and ChildHandle,
84 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
85 support the language specified by Language, then EFI_UNSUPPORTED is returned.
86
87 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
88 EFI_COMPONENT_NAME_PROTOCOL instance.
89
90 @param ControllerHandle[in] The handle of a controller that the driver
91 specified by This is managing. This handle
92 specifies the controller whose name is to be
93 returned.
94
95 @param ChildHandle[in] The handle of the child controller to retrieve
96 the name of. This is an optional parameter that
97 may be NULL. It will be NULL for device
98 drivers. It will also be NULL for a bus drivers
99 that wish to retrieve the name of the bus
100 controller. It will not be NULL for a bus
101 driver that wishes to retrieve the name of a
102 child controller.
103
104 @param Language[in] A pointer to a Null-terminated ASCII string
105 array indicating the language. This is the
106 language of the driver name that the caller is
107 requesting, and it must match one of the
108 languages specified in SupportedLanguages. The
109 number of languages supported by a driver is up
110 to the driver writer. Language is specified in
111 RFC 3066 or ISO 639-2 language code format.
112
113 @param ControllerName[out] A pointer to the Unicode string to return.
114 This Unicode string is the name of the
115 controller specified by ControllerHandle and
116 ChildHandle in the language specified by
117 Language from the point of view of the driver
118 specified by This.
119
120 @retval EFI_SUCCESS The Unicode string for the user readable name in
121 the language specified by Language for the
122 driver specified by This was returned in
123 DriverName.
124
125 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
126
127 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
128 EFI_HANDLE.
129
130 @retval EFI_INVALID_PARAMETER Language is NULL.
131
132 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
133
134 @retval EFI_UNSUPPORTED The driver specified by This is not currently
135 managing the controller specified by
136 ControllerHandle and ChildHandle.
137
138 @retval EFI_UNSUPPORTED The driver specified by This does not support
139 the language specified by Language.
140
141 **/
142 EFI_STATUS
143 EFIAPI
144 UhciComponentNameGetControllerName (
145 IN EFI_COMPONENT_NAME_PROTOCOL *This,
146 IN EFI_HANDLE ControllerHandle,
147 IN EFI_HANDLE ChildHandle OPTIONAL,
148 IN CHAR8 *Language,
149 OUT CHAR16 **ControllerName
150 );
151
152
153 //
154 // EFI Component Name Protocol
155 //
156 EFI_COMPONENT_NAME_PROTOCOL gUhciComponentName = {
157 UhciComponentNameGetDriverName,
158 UhciComponentNameGetControllerName,
159 "eng"
160 };
161
162 //
163 // EFI Component Name 2 Protocol
164 //
165 EFI_COMPONENT_NAME2_PROTOCOL gUhciComponentName2 = {
166 (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) UhciComponentNameGetDriverName,
167 (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) UhciComponentNameGetControllerName,
168 "en"
169 };
170
171
172 static EFI_UNICODE_STRING_TABLE mUhciDriverNameTable[] = {
173 { "eng;en", L"Usb Uhci Driver" },
174 { NULL, NULL }
175 };
176
177 /**
178 Retrieves a Unicode string that is the user readable name of the driver.
179
180 This function retrieves the user readable name of a driver in the form of a
181 Unicode string. If the driver specified by This has a user readable name in
182 the language specified by Language, then a pointer to the driver name is
183 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
184 by This does not support the language specified by Language,
185 then EFI_UNSUPPORTED is returned.
186
187 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
188 EFI_COMPONENT_NAME_PROTOCOL instance.
189
190 @param Language[in] A pointer to a Null-terminated ASCII string
191 array indicating the language. This is the
192 language of the driver name that the caller is
193 requesting, and it must match one of the
194 languages specified in SupportedLanguages. The
195 number of languages supported by a driver is up
196 to the driver writer. Language is specified
197 in RFC 3066 or ISO 639-2 language code format.
198
199 @param DriverName[out] A pointer to the Unicode string to return.
200 This Unicode string is the name of the
201 driver specified by This in the language
202 specified by Language.
203
204 @retval EFI_SUCCESS The Unicode string for the Driver specified by
205 This and the language specified by Language was
206 returned in DriverName.
207
208 @retval EFI_INVALID_PARAMETER Language is NULL.
209
210 @retval EFI_INVALID_PARAMETER DriverName is NULL.
211
212 @retval EFI_UNSUPPORTED The driver specified by This does not support
213 the language specified by Language.
214
215 **/
216 EFI_STATUS
217 EFIAPI
218 UhciComponentNameGetDriverName (
219 IN EFI_COMPONENT_NAME_PROTOCOL *This,
220 IN CHAR8 *Language,
221 OUT CHAR16 **DriverName
222 )
223 {
224 return LookupUnicodeString2 (
225 Language,
226 This->SupportedLanguages,
227 mUhciDriverNameTable,
228 DriverName,
229 (BOOLEAN)(This == &gUhciComponentName)
230 );
231 }
232
233 /**
234 Retrieves a Unicode string that is the user readable name of the controller
235 that is being managed by a driver.
236
237 This function retrieves the user readable name of the controller specified by
238 ControllerHandle and ChildHandle in the form of a Unicode string. If the
239 driver specified by This has a user readable name in the language specified by
240 Language, then a pointer to the controller name is returned in ControllerName,
241 and EFI_SUCCESS is returned. If the driver specified by This is not currently
242 managing the controller specified by ControllerHandle and ChildHandle,
243 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
244 support the language specified by Language, then EFI_UNSUPPORTED is returned.
245
246 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
247 EFI_COMPONENT_NAME_PROTOCOL instance.
248
249 @param ControllerHandle[in] The handle of a controller that the driver
250 specified by This is managing. This handle
251 specifies the controller whose name is to be
252 returned.
253
254 @param ChildHandle[in] The handle of the child controller to retrieve
255 the name of. This is an optional parameter that
256 may be NULL. It will be NULL for device
257 drivers. It will also be NULL for a bus drivers
258 that wish to retrieve the name of the bus
259 controller. It will not be NULL for a bus
260 driver that wishes to retrieve the name of a
261 child controller.
262
263 @param Language[in] A pointer to a Null-terminated ASCII string
264 array indicating the language. This is the
265 language of the driver name that the caller is
266 requesting, and it must match one of the
267 languages specified in SupportedLanguages. The
268 number of languages supported by a driver is up
269 to the driver writer. Language is specified in
270 RFC 3066 or ISO 639-2 language code format.
271
272 @param ControllerName[out] A pointer to the Unicode string to return.
273 This Unicode string is the name of the
274 controller specified by ControllerHandle and
275 ChildHandle in the language specified by
276 Language from the point of view of the driver
277 specified by This.
278
279 @retval EFI_SUCCESS The Unicode string for the user readable name in
280 the language specified by Language for the
281 driver specified by This was returned in
282 DriverName.
283
284 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
285
286 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
287 EFI_HANDLE.
288
289 @retval EFI_INVALID_PARAMETER Language is NULL.
290
291 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
292
293 @retval EFI_UNSUPPORTED The driver specified by This is not currently
294 managing the controller specified by
295 ControllerHandle and ChildHandle.
296
297 @retval EFI_UNSUPPORTED The driver specified by This does not support
298 the language specified by Language.
299
300 **/
301 EFI_STATUS
302 EFIAPI
303 UhciComponentNameGetControllerName (
304 IN EFI_COMPONENT_NAME_PROTOCOL *This,
305 IN EFI_HANDLE ControllerHandle,
306 IN EFI_HANDLE ChildHandle OPTIONAL,
307 IN CHAR8 *Language,
308 OUT CHAR16 **ControllerName
309 )
310 {
311 EFI_STATUS Status;
312 USB_HC_DEV *UhciDev;
313 EFI_USB_HC_PROTOCOL *UsbHc;
314
315 //
316 // This is a device driver, so ChildHandle must be NULL.
317 //
318 if (ChildHandle != NULL) {
319 return EFI_UNSUPPORTED;
320 }
321
322 //
323 // Make sure this driver is currently managing ControllerHandle
324 //
325 Status = EfiTestManagedDevice (
326 ControllerHandle,
327 gUhciDriverBinding.DriverBindingHandle,
328 &gEfiPciIoProtocolGuid
329 );
330 if (EFI_ERROR (Status)) {
331 return Status;
332 }
333
334 //
335 // Get the device context
336 //
337 Status = gBS->OpenProtocol (
338 ControllerHandle,
339 &gEfiUsbHcProtocolGuid,
340 (VOID **) &UsbHc,
341 gUhciDriverBinding.DriverBindingHandle,
342 ControllerHandle,
343 EFI_OPEN_PROTOCOL_GET_PROTOCOL
344 );
345
346 if (EFI_ERROR (Status)) {
347 return Status;
348 }
349
350 UhciDev = UHC_FROM_USB_HC_PROTO (UsbHc);
351
352 return LookupUnicodeString2 (
353 Language,
354 This->SupportedLanguages,
355 UhciDev->CtrlNameTable,
356 ControllerName,
357 (BOOLEAN)(This == &gUhciComponentName)
358 );
359
360 }