2 Helper routine and corresponding data struct used by USB Mouse Driver.
4 Copyright (c) 2004 - 2010, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #ifndef _EFI_USB_MOUSE_H_
16 #define _EFI_USB_MOUSE_H_
21 #include <Protocol/SimplePointer.h>
22 #include <Protocol/UsbIo.h>
23 #include <Protocol/DevicePath.h>
25 #include <Library/ReportStatusCodeLib.h>
26 #include <Library/BaseMemoryLib.h>
27 #include <Library/UefiDriverEntryPoint.h>
28 #include <Library/UefiBootServicesTableLib.h>
29 #include <Library/UefiLib.h>
30 #include <Library/MemoryAllocationLib.h>
31 #include <Library/PcdLib.h>
32 #include <Library/UefiUsbLib.h>
33 #include <Library/DebugLib.h>
35 #include <IndustryStandard/Usb.h>
38 #define SUBCLASS_BOOT 1
39 #define PROTOCOL_MOUSE 2
41 #define BOOT_PROTOCOL 0
42 #define REPORT_PROTOCOL 1
44 #define USB_MOUSE_DEV_SIGNATURE SIGNATURE_32 ('u', 'm', 'o', 'u')
47 /// Button range and status
50 BOOLEAN ButtonDetected
;
54 } USB_MOUSE_BUTTON_DATA
;
57 /// Device instance of USB mouse.
61 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
62 EFI_EVENT DelayedRecoveryEvent
;
63 EFI_USB_IO_PROTOCOL
*UsbIo
;
64 EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor
;
65 EFI_USB_ENDPOINT_DESCRIPTOR IntEndpointDescriptor
;
66 UINT8 NumberOfButtons
;
71 EFI_SIMPLE_POINTER_PROTOCOL SimplePointerProtocol
;
72 EFI_SIMPLE_POINTER_STATE State
;
73 EFI_SIMPLE_POINTER_MODE Mode
;
75 USB_MOUSE_BUTTON_DATA PrivateData
;
76 EFI_UNICODE_STRING_TABLE
*ControllerNameTable
;
80 /// General HID Item structure
101 #define USB_MOUSE_DEV_FROM_MOUSE_PROTOCOL(a) \
102 CR(a, USB_MOUSE_DEV, SimplePointerProtocol, USB_MOUSE_DEV_SIGNATURE)
107 extern EFI_DRIVER_BINDING_PROTOCOL gUsbMouseDriverBinding
;
108 extern EFI_COMPONENT_NAME_PROTOCOL gUsbMouseComponentName
;
109 extern EFI_COMPONENT_NAME2_PROTOCOL gUsbMouseComponentName2
;
112 // Functions of Driver Binding Protocol
116 Check whether USB mouse driver supports this device.
118 @param This The USB mouse driver binding protocol.
119 @param Controller The controller handle to check.
120 @param RemainingDevicePath The remaining device path.
122 @retval EFI_SUCCESS The driver supports this controller.
123 @retval other This device isn't supported.
128 USBMouseDriverBindingSupported (
129 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
130 IN EFI_HANDLE Controller
,
131 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
135 Starts the mouse device with this driver.
137 This function consumes USB I/O Portocol, intializes USB mouse device,
138 installs Simple Pointer Protocol, and submits Asynchronous Interrupt
139 Transfer to manage the USB mouse device.
141 @param This The USB mouse driver binding instance.
142 @param Controller Handle of device to bind driver to.
143 @param RemainingDevicePath Optional parameter use to pick a specific child
146 @retval EFI_SUCCESS This driver supports this device.
147 @retval EFI_UNSUPPORTED This driver does not support this device.
148 @retval EFI_DEVICE_ERROR This driver cannot be started due to device Error.
149 @retval EFI_OUT_OF_RESOURCES Can't allocate memory resources.
150 @retval EFI_ALREADY_STARTED This driver has been started.
155 USBMouseDriverBindingStart (
156 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
157 IN EFI_HANDLE Controller
,
158 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
162 Stop the USB mouse device handled by this driver.
164 @param This The USB mouse driver binding protocol.
165 @param Controller The controller to release.
166 @param NumberOfChildren The number of handles in ChildHandleBuffer.
167 @param ChildHandleBuffer The array of child handle.
169 @retval EFI_SUCCESS The device was stopped.
170 @retval EFI_UNSUPPORTED Simple Pointer Protocol is not installed on Controller.
171 @retval Others Fail to uninstall protocols attached on the device.
176 USBMouseDriverBindingStop (
177 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
178 IN EFI_HANDLE Controller
,
179 IN UINTN NumberOfChildren
,
180 IN EFI_HANDLE
*ChildHandleBuffer
184 // EFI Component Name Functions
188 Retrieves a Unicode string that is the user readable name of the driver.
190 This function retrieves the user readable name of a driver in the form of a
191 Unicode string. If the driver specified by This has a user readable name in
192 the language specified by Language, then a pointer to the driver name is
193 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
194 by This does not support the language specified by Language,
195 then EFI_UNSUPPORTED is returned.
197 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
198 EFI_COMPONENT_NAME_PROTOCOL instance.
199 @param Language A pointer to a Null-terminated ASCII string
200 array indicating the language. This is the
201 language of the driver name that the caller is
202 requesting, and it must match one of the
203 languages specified in SupportedLanguages. The
204 number of languages supported by a driver is up
205 to the driver writer. Language is specified
206 in RFC 4646 or ISO 639-2 language code format.
207 @param DriverName A pointer to the Unicode string to return.
208 This Unicode string is the name of the
209 driver specified by This in the language
210 specified by Language.
212 @retval EFI_SUCCESS The Unicode string for the Driver specified by
213 This and the language specified by Language was
214 returned in DriverName.
215 @retval EFI_INVALID_PARAMETER Language is NULL.
216 @retval EFI_INVALID_PARAMETER DriverName is NULL.
217 @retval EFI_UNSUPPORTED The driver specified by This does not support
218 the language specified by Language.
223 UsbMouseComponentNameGetDriverName (
224 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
226 OUT CHAR16
**DriverName
230 Retrieves a Unicode string that is the user readable name of the controller
231 that is being managed by a driver.
233 This function retrieves the user readable name of the controller specified by
234 ControllerHandle and ChildHandle in the form of a Unicode string. If the
235 driver specified by This has a user readable name in the language specified by
236 Language, then a pointer to the controller name is returned in ControllerName,
237 and EFI_SUCCESS is returned. If the driver specified by This is not currently
238 managing the controller specified by ControllerHandle and ChildHandle,
239 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
240 support the language specified by Language, then EFI_UNSUPPORTED is returned.
242 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
243 EFI_COMPONENT_NAME_PROTOCOL instance.
244 @param ControllerHandle The handle of a controller that the driver
245 specified by This is managing. This handle
246 specifies the controller whose name is to be
248 @param ChildHandle The handle of the child controller to retrieve
249 the name of. This is an optional parameter that
250 may be NULL. It will be NULL for device
251 drivers. It will also be NULL for a bus drivers
252 that wish to retrieve the name of the bus
253 controller. It will not be NULL for a bus
254 driver that wishes to retrieve the name of a
256 @param Language A pointer to a Null-terminated ASCII string
257 array indicating the language. This is the
258 language of the driver name that the caller is
259 requesting, and it must match one of the
260 languages specified in SupportedLanguages. The
261 number of languages supported by a driver is up
262 to the driver writer. Language is specified in
263 RFC 4646 or ISO 639-2 language code format.
264 @param ControllerName A pointer to the Unicode string to return.
265 This Unicode string is the name of the
266 controller specified by ControllerHandle and
267 ChildHandle in the language specified by
268 Language from the point of view of the driver
271 @retval EFI_SUCCESS The Unicode string for the user readable name in
272 the language specified by Language for the
273 driver specified by This was returned in
275 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
276 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
278 @retval EFI_INVALID_PARAMETER Language is NULL.
279 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
280 @retval EFI_UNSUPPORTED The driver specified by This is not currently
281 managing the controller specified by
282 ControllerHandle and ChildHandle.
283 @retval EFI_UNSUPPORTED The driver specified by This does not support
284 the language specified by Language.
289 UsbMouseComponentNameGetControllerName (
290 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
291 IN EFI_HANDLE ControllerHandle
,
292 IN EFI_HANDLE ChildHandle OPTIONAL
,
294 OUT CHAR16
**ControllerName
298 // Functions of EFI_SIMPLE_POINTER_PROTOCOL
302 Retrieves the current state of a pointer device.
304 @param This A pointer to the EFI_SIMPLE_POINTER_PROTOCOL instance.
305 @param MouseState A pointer to the state information on the pointer device.
307 @retval EFI_SUCCESS The state of the pointer device was returned in State.
308 @retval EFI_NOT_READY The state of the pointer device has not changed since the last call to
310 @retval EFI_DEVICE_ERROR A device error occurred while attempting to retrieve the pointer device's
312 @retval EFI_INVALID_PARAMETER MouseState is NULL.
318 IN EFI_SIMPLE_POINTER_PROTOCOL
*This
,
319 OUT EFI_SIMPLE_POINTER_STATE
*MouseState
323 Resets the pointer device hardware.
325 @param This A pointer to the EFI_SIMPLE_POINTER_PROTOCOL instance.
326 @param ExtendedVerification Indicates that the driver may perform a more exhaustive
327 verification operation of the device during reset.
329 @retval EFI_SUCCESS The device was reset.
330 @retval EFI_DEVICE_ERROR The device is not functioning correctly and could not be reset.
336 IN EFI_SIMPLE_POINTER_PROTOCOL
*This
,
337 IN BOOLEAN ExtendedVerification
341 Event notification function for SIMPLE_POINTER.WaitForInput event.
343 @param Event Event to be signaled when there's input from mouse.
344 @param Context Points to USB_MOUSE_DEV instance.
349 UsbMouseWaitForInput (
355 // Internal worker functions
359 Uses USB I/O to check whether the device is a USB mouse device.
361 @param UsbIo Pointer to a USB I/O protocol instance.
363 @retval TRUE Device is a USB mouse device.
364 @retval FALSE Device is a not USB mouse device.
369 IN EFI_USB_IO_PROTOCOL
*UsbIo
373 Initialize the USB mouse device.
375 This function retrieves and parses HID report descriptor, and
376 initializes state of USB_MOUSE_DEV. Then it sets indefinite idle
377 rate for the device. Finally it creates event for delayed recovery,
378 which deals with device error.
380 @param UsbMouseDev Device instance to be initialized.
382 @retval EFI_SUCCESS USB mouse device successfully initialized..
383 @retval EFI_UNSUPPORTED HID descriptor type is not report descriptor.
384 @retval Other USB mouse device was not initialized successfully.
388 InitializeUsbMouseDevice (
389 IN OUT USB_MOUSE_DEV
*UsbMouseDev
393 Handler function for USB mouse's asynchronous interrupt transfer.
395 This function is the handler function for USB mouse's asynchronous interrupt transfer
396 to manage the mouse. It parses data returned from asynchronous interrupt transfer, and
397 get button and movement state.
399 @param Data A pointer to a buffer that is filled with key data which is
400 retrieved via asynchronous interrupt transfer.
401 @param DataLength Indicates the size of the data buffer.
402 @param Context Pointing to USB_KB_DEV instance.
403 @param Result Indicates the result of the asynchronous interrupt transfer.
405 @retval EFI_SUCCESS Asynchronous interrupt transfer is handled successfully.
406 @retval EFI_DEVICE_ERROR Hardware error occurs.
411 OnMouseInterruptComplete (
419 Handler for Delayed Recovery event.
421 This function is the handler for Delayed Recovery event triggered
423 After a device error occurs, the event would be triggered
424 with interval of EFI_USB_INTERRUPT_DELAY. EFI_USB_INTERRUPT_DELAY
425 is defined in USB standard for error handling.
427 @param Event The Delayed Recovery event.
428 @param Context Points to the USB_MOUSE_DEV instance.
433 USBMouseRecoveryHandler (
439 Parse Mouse Report Descriptor.
441 According to USB HID Specification, report descriptors are
442 composed of pieces of information. Each piece of information
443 is called an Item. This function retrieves each item from
444 the report descriptor and updates USB_MOUSE_DEV.
446 @param UsbMouse The instance of USB_MOUSE_DEV
447 @param ReportDescriptor Report descriptor to parse
448 @param ReportSize Report descriptor size
450 @retval EFI_SUCCESS Report descriptor successfully parsed.
451 @retval EFI_UNSUPPORTED Report descriptor contains long item.
455 ParseMouseReportDescriptor (
456 OUT USB_MOUSE_DEV
*UsbMouse
,
457 IN UINT8
*ReportDescriptor
,