]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Usb/UsbMouseDxe/ComponentName.c
Add compiler hint of "GLOBAL_REMOVE_IF_UNREFERENCED" to prevent static unicode string...
[mirror_edk2.git] / MdeModulePkg / Bus / Usb / UsbMouseDxe / 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 "usbmouse.h"
22 #include <Library/DebugLib.h>
23
24 //
25 // EFI Component Name Functions
26 //
27 /**
28 Retrieves a Unicode string that is the user readable name of the driver.
29
30 This function retrieves the user readable name of a driver in the form of a
31 Unicode string. If the driver specified by This has a user readable name in
32 the language specified by Language, then a pointer to the driver name is
33 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
34 by This does not support the language specified by Language,
35 then EFI_UNSUPPORTED is returned.
36
37 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
38 EFI_COMPONENT_NAME_PROTOCOL instance.
39
40 @param Language[in] A pointer to a Null-terminated ASCII string
41 array indicating the language. This is the
42 language of the driver name that the caller is
43 requesting, and it must match one of the
44 languages specified in SupportedLanguages. The
45 number of languages supported by a driver is up
46 to the driver writer. Language is specified
47 in RFC 3066 or ISO 639-2 language code format.
48
49 @param DriverName[out] A pointer to the Unicode string to return.
50 This Unicode string is the name of the
51 driver specified by This in the language
52 specified by Language.
53
54 @retval EFI_SUCCESS The Unicode string for the Driver specified by
55 This and the language specified by Language was
56 returned in DriverName.
57
58 @retval EFI_INVALID_PARAMETER Language is NULL.
59
60 @retval EFI_INVALID_PARAMETER DriverName is NULL.
61
62 @retval EFI_UNSUPPORTED The driver specified by This does not support
63 the language specified by Language.
64
65 **/
66 EFI_STATUS
67 EFIAPI
68 UsbMouseComponentNameGetDriverName (
69 IN EFI_COMPONENT_NAME_PROTOCOL *This,
70 IN CHAR8 *Language,
71 OUT CHAR16 **DriverName
72 );
73
74
75 /**
76 Retrieves a Unicode string that is the user readable name of the controller
77 that is being managed by a driver.
78
79 This function retrieves the user readable name of the controller specified by
80 ControllerHandle and ChildHandle in the form of a Unicode string. If the
81 driver specified by This has a user readable name in the language specified by
82 Language, then a pointer to the controller name is returned in ControllerName,
83 and EFI_SUCCESS is returned. If the driver specified by This is not currently
84 managing the controller specified by ControllerHandle and ChildHandle,
85 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
86 support the language specified by Language, then EFI_UNSUPPORTED is returned.
87
88 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
89 EFI_COMPONENT_NAME_PROTOCOL instance.
90
91 @param ControllerHandle[in] The handle of a controller that the driver
92 specified by This is managing. This handle
93 specifies the controller whose name is to be
94 returned.
95
96 @param ChildHandle[in] The handle of the child controller to retrieve
97 the name of. This is an optional parameter that
98 may be NULL. It will be NULL for device
99 drivers. It will also be NULL for a bus drivers
100 that wish to retrieve the name of the bus
101 controller. It will not be NULL for a bus
102 driver that wishes to retrieve the name of a
103 child controller.
104
105 @param Language[in] A pointer to a Null-terminated ASCII string
106 array indicating the language. This is the
107 language of the driver name that the caller is
108 requesting, and it must match one of the
109 languages specified in SupportedLanguages. The
110 number of languages supported by a driver is up
111 to the driver writer. Language is specified in
112 RFC 3066 or ISO 639-2 language code format.
113
114 @param ControllerName[out] A pointer to the Unicode string to return.
115 This Unicode string is the name of the
116 controller specified by ControllerHandle and
117 ChildHandle in the language specified by
118 Language from the point of view of the driver
119 specified by This.
120
121 @retval EFI_SUCCESS The Unicode string for the user readable name in
122 the language specified by Language for the
123 driver specified by This was returned in
124 DriverName.
125
126 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
127
128 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
129 EFI_HANDLE.
130
131 @retval EFI_INVALID_PARAMETER Language is NULL.
132
133 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
134
135 @retval EFI_UNSUPPORTED The driver specified by This is not currently
136 managing the controller specified by
137 ControllerHandle and ChildHandle.
138
139 @retval EFI_UNSUPPORTED The driver specified by This does not support
140 the language specified by Language.
141
142 **/
143 EFI_STATUS
144 EFIAPI
145 UsbMouseComponentNameGetControllerName (
146 IN EFI_COMPONENT_NAME_PROTOCOL *This,
147 IN EFI_HANDLE ControllerHandle,
148 IN EFI_HANDLE ChildHandle OPTIONAL,
149 IN CHAR8 *Language,
150 OUT CHAR16 **ControllerName
151 );
152
153
154 //
155 // EFI Component Name Protocol
156 //
157 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gUsbMouseComponentName = {
158 UsbMouseComponentNameGetDriverName,
159 UsbMouseComponentNameGetControllerName,
160 "eng"
161 };
162
163 //
164 // EFI Component Name 2 Protocol
165 //
166 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gUsbMouseComponentName2 = {
167 (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) UsbMouseComponentNameGetDriverName,
168 (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) UsbMouseComponentNameGetControllerName,
169 "en"
170 };
171
172
173
174 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mUsbMouseDriverNameTable[] = {
175 { "eng;en", L"Usb Mouse Driver" },
176 { NULL , NULL }
177 };
178
179
180 /**
181 Retrieves a Unicode string that is the user readable name of the driver.
182
183 This function retrieves the user readable name of a driver in the form of a
184 Unicode string. If the driver specified by This has a user readable name in
185 the language specified by Language, then a pointer to the driver name is
186 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
187 by This does not support the language specified by Language,
188 then EFI_UNSUPPORTED is returned.
189
190 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
191 EFI_COMPONENT_NAME_PROTOCOL instance.
192
193 @param Language[in] A pointer to a Null-terminated ASCII string
194 array indicating the language. This is the
195 language of the driver name that the caller is
196 requesting, and it must match one of the
197 languages specified in SupportedLanguages. The
198 number of languages supported by a driver is up
199 to the driver writer. Language is specified
200 in RFC 3066 or ISO 639-2 language code format.
201
202 @param DriverName[out] A pointer to the Unicode string to return.
203 This Unicode string is the name of the
204 driver specified by This in the language
205 specified by Language.
206
207 @retval EFI_SUCCESS The Unicode string for the Driver specified by
208 This and the language specified by Language was
209 returned in DriverName.
210
211 @retval EFI_INVALID_PARAMETER Language is NULL.
212
213 @retval EFI_INVALID_PARAMETER DriverName is NULL.
214
215 @retval EFI_UNSUPPORTED The driver specified by This does not support
216 the language specified by Language.
217
218 **/
219 EFI_STATUS
220 EFIAPI
221 UsbMouseComponentNameGetDriverName (
222 IN EFI_COMPONENT_NAME_PROTOCOL *This,
223 IN CHAR8 *Language,
224 OUT CHAR16 **DriverName
225 )
226 {
227 return LookupUnicodeString2 (
228 Language,
229 This->SupportedLanguages,
230 mUsbMouseDriverNameTable,
231 DriverName,
232 (BOOLEAN)(This == &gUsbMouseComponentName)
233 );
234 }
235
236 /**
237 Retrieves a Unicode string that is the user readable name of the controller
238 that is being managed by a driver.
239
240 This function retrieves the user readable name of the controller specified by
241 ControllerHandle and ChildHandle in the form of a Unicode string. If the
242 driver specified by This has a user readable name in the language specified by
243 Language, then a pointer to the controller name is returned in ControllerName,
244 and EFI_SUCCESS is returned. If the driver specified by This is not currently
245 managing the controller specified by ControllerHandle and ChildHandle,
246 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
247 support the language specified by Language, then EFI_UNSUPPORTED is returned.
248
249 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
250 EFI_COMPONENT_NAME_PROTOCOL instance.
251
252 @param ControllerHandle[in] The handle of a controller that the driver
253 specified by This is managing. This handle
254 specifies the controller whose name is to be
255 returned.
256
257 @param ChildHandle[in] The handle of the child controller to retrieve
258 the name of. This is an optional parameter that
259 may be NULL. It will be NULL for device
260 drivers. It will also be NULL for a bus drivers
261 that wish to retrieve the name of the bus
262 controller. It will not be NULL for a bus
263 driver that wishes to retrieve the name of a
264 child controller.
265
266 @param Language[in] A pointer to a Null-terminated ASCII string
267 array indicating the language. This is the
268 language of the driver name that the caller is
269 requesting, and it must match one of the
270 languages specified in SupportedLanguages. The
271 number of languages supported by a driver is up
272 to the driver writer. Language is specified in
273 RFC 3066 or ISO 639-2 language code format.
274
275 @param ControllerName[out] A pointer to the Unicode string to return.
276 This Unicode string is the name of the
277 controller specified by ControllerHandle and
278 ChildHandle in the language specified by
279 Language from the point of view of the driver
280 specified by This.
281
282 @retval EFI_SUCCESS The Unicode string for the user readable name in
283 the language specified by Language for the
284 driver specified by This was returned in
285 DriverName.
286
287 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
288
289 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
290 EFI_HANDLE.
291
292 @retval EFI_INVALID_PARAMETER Language is NULL.
293
294 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
295
296 @retval EFI_UNSUPPORTED The driver specified by This is not currently
297 managing the controller specified by
298 ControllerHandle and ChildHandle.
299
300 @retval EFI_UNSUPPORTED The driver specified by This does not support
301 the language specified by Language.
302
303 **/
304 EFI_STATUS
305 EFIAPI
306 UsbMouseComponentNameGetControllerName (
307 IN EFI_COMPONENT_NAME_PROTOCOL *This,
308 IN EFI_HANDLE ControllerHandle,
309 IN EFI_HANDLE ChildHandle OPTIONAL,
310 IN CHAR8 *Language,
311 OUT CHAR16 **ControllerName
312 )
313 {
314 EFI_STATUS Status;
315 USB_MOUSE_DEV *UsbMouseDev;
316 EFI_SIMPLE_POINTER_PROTOCOL *SimplePointerProtocol;
317 EFI_USB_IO_PROTOCOL *UsbIoProtocol;
318
319 //
320 // This is a device driver, so ChildHandle must be NULL.
321 //
322 if (ChildHandle != NULL) {
323 return EFI_UNSUPPORTED;
324 }
325
326 //
327 // Check Controller's handle
328 //
329 Status = gBS->OpenProtocol (
330 ControllerHandle,
331 &gEfiUsbIoProtocolGuid,
332 (VOID **) &UsbIoProtocol,
333 gUsbMouseDriverBinding.DriverBindingHandle,
334 ControllerHandle,
335 EFI_OPEN_PROTOCOL_BY_DRIVER
336 );
337 if (!EFI_ERROR (Status)) {
338 gBS->CloseProtocol (
339 ControllerHandle,
340 &gEfiUsbIoProtocolGuid,
341 gUsbMouseDriverBinding.DriverBindingHandle,
342 ControllerHandle
343 );
344
345 return EFI_UNSUPPORTED;
346 }
347
348 if (Status != EFI_ALREADY_STARTED) {
349 return EFI_UNSUPPORTED;
350 }
351 //
352 // Get the device context
353 //
354 Status = gBS->OpenProtocol (
355 ControllerHandle,
356 &gEfiSimplePointerProtocolGuid,
357 (VOID **) &SimplePointerProtocol,
358 gUsbMouseDriverBinding.DriverBindingHandle,
359 ControllerHandle,
360 EFI_OPEN_PROTOCOL_GET_PROTOCOL
361 );
362
363 if (EFI_ERROR (Status)) {
364 return Status;
365 }
366
367 UsbMouseDev = USB_MOUSE_DEV_FROM_MOUSE_PROTOCOL (SimplePointerProtocol);
368
369 return LookupUnicodeString2 (
370 Language,
371 This->SupportedLanguages,
372 UsbMouseDev->ControllerNameTable,
373 ControllerName,
374 (BOOLEAN)(This == &gUsbMouseComponentName)
375 );
376
377 }