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