3 UEFI Component Name(2) protocol implementation for Usb Mouse driver.
5 Copyright (c) 2004 - 2008, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include <Library/DebugLib.h>
20 // EFI Component Name Functions
23 Retrieves a Unicode string that is the user readable name of the driver.
25 This function retrieves the user readable name of a driver in the form of a
26 Unicode string. If the driver specified by This has a user readable name in
27 the language specified by Language, then a pointer to the driver name is
28 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
29 by This does not support the language specified by Language,
30 then EFI_UNSUPPORTED is returned.
32 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
33 EFI_COMPONENT_NAME_PROTOCOL instance.
35 @param Language[in] A pointer to a Null-terminated ASCII string
36 array indicating the language. This is the
37 language of the driver name that the caller is
38 requesting, and it must match one of the
39 languages specified in SupportedLanguages. The
40 number of languages supported by a driver is up
41 to the driver writer. Language is specified
42 in RFC 3066 or ISO 639-2 language code format.
44 @param DriverName[out] A pointer to the Unicode string to return.
45 This Unicode string is the name of the
46 driver specified by This in the language
47 specified by Language.
49 @retval EFI_SUCCESS The Unicode string for the Driver specified by
50 This and the language specified by Language was
51 returned in DriverName.
53 @retval EFI_INVALID_PARAMETER Language is NULL.
55 @retval EFI_INVALID_PARAMETER DriverName is NULL.
57 @retval EFI_UNSUPPORTED The driver specified by This does not support
58 the language specified by Language.
63 UsbMouseComponentNameGetDriverName (
64 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
66 OUT CHAR16
**DriverName
71 Retrieves a Unicode string that is the user readable name of the controller
72 that is being managed by a driver.
74 This function retrieves the user readable name of the controller specified by
75 ControllerHandle and ChildHandle in the form of a Unicode string. If the
76 driver specified by This has a user readable name in the language specified by
77 Language, then a pointer to the controller name is returned in ControllerName,
78 and EFI_SUCCESS is returned. If the driver specified by This is not currently
79 managing the controller specified by ControllerHandle and ChildHandle,
80 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
81 support the language specified by Language, then EFI_UNSUPPORTED is returned.
83 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
84 EFI_COMPONENT_NAME_PROTOCOL instance.
86 @param ControllerHandle[in] The handle of a controller that the driver
87 specified by This is managing. This handle
88 specifies the controller whose name is to be
91 @param ChildHandle[in] The handle of the child controller to retrieve
92 the name of. This is an optional parameter that
93 may be NULL. It will be NULL for device
94 drivers. It will also be NULL for a bus drivers
95 that wish to retrieve the name of the bus
96 controller. It will not be NULL for a bus
97 driver that wishes to retrieve the name of a
100 @param Language[in] A pointer to a Null-terminated ASCII string
101 array indicating the language. This is the
102 language of the driver name that the caller is
103 requesting, and it must match one of the
104 languages specified in SupportedLanguages. The
105 number of languages supported by a driver is up
106 to the driver writer. Language is specified in
107 RFC 3066 or ISO 639-2 language code format.
109 @param ControllerName[out] A pointer to the Unicode string to return.
110 This Unicode string is the name of the
111 controller specified by ControllerHandle and
112 ChildHandle in the language specified by
113 Language from the point of view of the driver
116 @retval EFI_SUCCESS The Unicode string for the user readable name in
117 the language specified by Language for the
118 driver specified by This was returned in
121 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
123 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
126 @retval EFI_INVALID_PARAMETER Language is NULL.
128 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
130 @retval EFI_UNSUPPORTED The driver specified by This is not currently
131 managing the controller specified by
132 ControllerHandle and ChildHandle.
134 @retval EFI_UNSUPPORTED The driver specified by This does not support
135 the language specified by Language.
140 UsbMouseComponentNameGetControllerName (
141 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
142 IN EFI_HANDLE ControllerHandle
,
143 IN EFI_HANDLE ChildHandle OPTIONAL
,
145 OUT CHAR16
**ControllerName
150 // EFI Component Name Protocol
152 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gUsbMouseComponentName
= {
153 UsbMouseComponentNameGetDriverName
,
154 UsbMouseComponentNameGetControllerName
,
159 // EFI Component Name 2 Protocol
161 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gUsbMouseComponentName2
= {
162 (EFI_COMPONENT_NAME2_GET_DRIVER_NAME
) UsbMouseComponentNameGetDriverName
,
163 (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME
) UsbMouseComponentNameGetControllerName
,
169 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mUsbMouseDriverNameTable
[] = {
170 { "eng;en", L
"Usb Mouse Driver" },
176 Retrieves a Unicode string that is the user readable name of the driver.
178 This function retrieves the user readable name of a driver in the form of a
179 Unicode string. If the driver specified by This has a user readable name in
180 the language specified by Language, then a pointer to the driver name is
181 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
182 by This does not support the language specified by Language,
183 then EFI_UNSUPPORTED is returned.
185 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
186 EFI_COMPONENT_NAME_PROTOCOL instance.
188 @param Language[in] A pointer to a Null-terminated ASCII string
189 array indicating the language. This is the
190 language of the driver name that the caller is
191 requesting, and it must match one of the
192 languages specified in SupportedLanguages. The
193 number of languages supported by a driver is up
194 to the driver writer. Language is specified
195 in RFC 3066 or ISO 639-2 language code format.
197 @param DriverName[out] A pointer to the Unicode string to return.
198 This Unicode string is the name of the
199 driver specified by This in the language
200 specified by Language.
202 @retval EFI_SUCCESS The Unicode string for the Driver specified by
203 This and the language specified by Language was
204 returned in DriverName.
206 @retval EFI_INVALID_PARAMETER Language is NULL.
208 @retval EFI_INVALID_PARAMETER DriverName is NULL.
210 @retval EFI_UNSUPPORTED The driver specified by This does not support
211 the language specified by Language.
216 UsbMouseComponentNameGetDriverName (
217 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
219 OUT CHAR16
**DriverName
222 return LookupUnicodeString2 (
224 This
->SupportedLanguages
,
225 mUsbMouseDriverNameTable
,
227 (BOOLEAN
)(This
== &gUsbMouseComponentName
)
232 Retrieves a Unicode string that is the user readable name of the controller
233 that is being managed by a driver.
235 This function retrieves the user readable name of the controller specified by
236 ControllerHandle and ChildHandle in the form of a Unicode string. If the
237 driver specified by This has a user readable name in the language specified by
238 Language, then a pointer to the controller name is returned in ControllerName,
239 and EFI_SUCCESS is returned. If the driver specified by This is not currently
240 managing the controller specified by ControllerHandle and ChildHandle,
241 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
242 support the language specified by Language, then EFI_UNSUPPORTED is returned.
244 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
245 EFI_COMPONENT_NAME_PROTOCOL instance.
247 @param ControllerHandle[in] The handle of a controller that the driver
248 specified by This is managing. This handle
249 specifies the controller whose name is to be
252 @param ChildHandle[in] The handle of the child controller to retrieve
253 the name of. This is an optional parameter that
254 may be NULL. It will be NULL for device
255 drivers. It will also be NULL for a bus drivers
256 that wish to retrieve the name of the bus
257 controller. It will not be NULL for a bus
258 driver that wishes to retrieve the name of a
261 @param Language[in] A pointer to a Null-terminated ASCII string
262 array indicating the language. This is the
263 language of the driver name that the caller is
264 requesting, and it must match one of the
265 languages specified in SupportedLanguages. The
266 number of languages supported by a driver is up
267 to the driver writer. Language is specified in
268 RFC 3066 or ISO 639-2 language code format.
270 @param ControllerName[out] A pointer to the Unicode string to return.
271 This Unicode string is the name of the
272 controller specified by ControllerHandle and
273 ChildHandle in the language specified by
274 Language from the point of view of the driver
277 @retval EFI_SUCCESS The Unicode string for the user readable name in
278 the language specified by Language for the
279 driver specified by This was returned in
282 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
284 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
287 @retval EFI_INVALID_PARAMETER Language is NULL.
289 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
291 @retval EFI_UNSUPPORTED The driver specified by This is not currently
292 managing the controller specified by
293 ControllerHandle and ChildHandle.
295 @retval EFI_UNSUPPORTED The driver specified by This does not support
296 the language specified by Language.
301 UsbMouseComponentNameGetControllerName (
302 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
303 IN EFI_HANDLE ControllerHandle
,
304 IN EFI_HANDLE ChildHandle OPTIONAL
,
306 OUT CHAR16
**ControllerName
310 USB_MOUSE_DEV
*UsbMouseDev
;
311 EFI_SIMPLE_POINTER_PROTOCOL
*SimplePointerProtocol
;
312 EFI_USB_IO_PROTOCOL
*UsbIoProtocol
;
315 // This is a device driver, so ChildHandle must be NULL.
317 if (ChildHandle
!= NULL
) {
318 return EFI_UNSUPPORTED
;
322 // Check Controller's handle
324 Status
= gBS
->OpenProtocol (
326 &gEfiUsbIoProtocolGuid
,
327 (VOID
**) &UsbIoProtocol
,
328 gUsbMouseDriverBinding
.DriverBindingHandle
,
330 EFI_OPEN_PROTOCOL_BY_DRIVER
332 if (!EFI_ERROR (Status
)) {
335 &gEfiUsbIoProtocolGuid
,
336 gUsbMouseDriverBinding
.DriverBindingHandle
,
340 return EFI_UNSUPPORTED
;
343 if (Status
!= EFI_ALREADY_STARTED
) {
344 return EFI_UNSUPPORTED
;
347 // Get the device context
349 Status
= gBS
->OpenProtocol (
351 &gEfiSimplePointerProtocolGuid
,
352 (VOID
**) &SimplePointerProtocol
,
353 gUsbMouseDriverBinding
.DriverBindingHandle
,
355 EFI_OPEN_PROTOCOL_GET_PROTOCOL
358 if (EFI_ERROR (Status
)) {
362 UsbMouseDev
= USB_MOUSE_DEV_FROM_MOUSE_PROTOCOL (SimplePointerProtocol
);
364 return LookupUnicodeString2 (
366 This
->SupportedLanguages
,
367 UsbMouseDev
->ControllerNameTable
,
369 (BOOLEAN
)(This
== &gUsbMouseComponentName
)