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