2 Helper routine and corresponding data struct used by USB Mouse Absolute Pointer Driver.
4 Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>
5 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 _USB_MOUSE_ABSOLUTE_POINTER_H_
16 #define _USB_MOUSE_ABSOLUTE_POINTER_H_
21 #include <Protocol/AbsolutePointer.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/UefiUsbLib.h>
32 #include <Library/DebugLib.h>
34 #include <IndustryStandard/Usb.h>
37 #define SUBCLASS_BOOT 1
38 #define PROTOCOL_MOUSE 2
40 #define BOOT_PROTOCOL 0
41 #define REPORT_PROTOCOL 1
43 #define USB_MOUSE_ABSOLUTE_POINTER_DEV_SIGNATURE SIGNATURE_32 ('u', 'm', 's', 't')
46 /// Button range and status
49 BOOLEAN ButtonDetected
;
53 } USB_MOUSE_BUTTON_DATA
;
56 /// Device instance of USB mouse.
60 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
61 EFI_EVENT DelayedRecoveryEvent
;
62 EFI_USB_IO_PROTOCOL
*UsbIo
;
63 EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor
;
64 EFI_USB_ENDPOINT_DESCRIPTOR IntEndpointDescriptor
;
65 UINT8 NumberOfButtons
;
70 EFI_ABSOLUTE_POINTER_PROTOCOL AbsolutePointerProtocol
;
71 EFI_ABSOLUTE_POINTER_STATE State
;
72 EFI_ABSOLUTE_POINTER_MODE Mode
;
74 USB_MOUSE_BUTTON_DATA PrivateData
;
75 EFI_UNICODE_STRING_TABLE
*ControllerNameTable
;
76 } USB_MOUSE_ABSOLUTE_POINTER_DEV
;
79 /// General HID Item structure
100 #define USB_MOUSE_ABSOLUTE_POINTER_DEV_FROM_MOUSE_PROTOCOL(a) \
101 CR(a, USB_MOUSE_ABSOLUTE_POINTER_DEV, AbsolutePointerProtocol, USB_MOUSE_ABSOLUTE_POINTER_DEV_SIGNATURE)
106 extern EFI_DRIVER_BINDING_PROTOCOL gUsbMouseAbsolutePointerDriverBinding
;
107 extern EFI_COMPONENT_NAME_PROTOCOL gUsbMouseAbsolutePointerComponentName
;
108 extern EFI_COMPONENT_NAME2_PROTOCOL gUsbMouseAbsolutePointerComponentName2
;
111 // Functions of Driver Binding Protocol
115 Check whether USB Mouse Absolute Pointer Driver supports this device.
117 @param This The driver binding protocol.
118 @param Controller The controller handle to check.
119 @param RemainingDevicePath The remaining device path.
121 @retval EFI_SUCCESS The driver supports this controller.
122 @retval other This device isn't supported.
127 USBMouseAbsolutePointerDriverBindingSupported (
128 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
129 IN EFI_HANDLE Controller
,
130 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
134 Starts the mouse device with this driver.
136 This function consumes USB I/O Portocol, intializes USB mouse device,
137 installs Absolute Pointer Protocol, and submits Asynchronous Interrupt
138 Transfer to manage the USB mouse device.
140 @param This The driver binding instance.
141 @param Controller Handle of device to bind driver to.
142 @param RemainingDevicePath Optional parameter use to pick a specific child
145 @retval EFI_SUCCESS This driver supports this device.
146 @retval EFI_UNSUPPORTED This driver does not support this device.
147 @retval EFI_DEVICE_ERROR This driver cannot be started due to device Error.
148 @retval EFI_OUT_OF_RESOURCES Can't allocate memory resources.
149 @retval EFI_ALREADY_STARTED This driver has been started.
154 USBMouseAbsolutePointerDriverBindingStart (
155 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
156 IN EFI_HANDLE Controller
,
157 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
161 Stop the USB mouse device handled by this driver.
163 @param This The driver binding protocol.
164 @param Controller The controller to release.
165 @param NumberOfChildren The number of handles in ChildHandleBuffer.
166 @param ChildHandleBuffer The array of child handle.
168 @retval EFI_SUCCESS The device was stopped.
169 @retval EFI_UNSUPPORTED Absolute Pointer Protocol is not installed on Controller.
170 @retval Others Fail to uninstall protocols attached on the device.
175 USBMouseAbsolutePointerDriverBindingStop (
176 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
177 IN EFI_HANDLE Controller
,
178 IN UINTN NumberOfChildren
,
179 IN EFI_HANDLE
*ChildHandleBuffer
183 // EFI Component Name Functions
187 Retrieves a Unicode string that is the user readable name of the driver.
189 This function retrieves the user readable name of a driver in the form of a
190 Unicode string. If the driver specified by This has a user readable name in
191 the language specified by Language, then a pointer to the driver name is
192 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
193 by This does not support the language specified by Language,
194 then EFI_UNSUPPORTED is returned.
196 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
197 EFI_COMPONENT_NAME_PROTOCOL instance.
198 @param Language A pointer to a Null-terminated ASCII string
199 array indicating the language. This is the
200 language of the driver name that the caller is
201 requesting, and it must match one of the
202 languages specified in SupportedLanguages. The
203 number of languages supported by a driver is up
204 to the driver writer. Language is specified
205 in RFC 4646 or ISO 639-2 language code format.
206 @param DriverName A pointer to the Unicode string to return.
207 This Unicode string is the name of the
208 driver specified by This in the language
209 specified by Language.
211 @retval EFI_SUCCESS The Unicode string for the Driver specified by
212 This and the language specified by Language was
213 returned in DriverName.
214 @retval EFI_INVALID_PARAMETER Language is NULL.
215 @retval EFI_INVALID_PARAMETER DriverName is NULL.
216 @retval EFI_UNSUPPORTED The driver specified by This does not support
217 the language specified by Language.
222 UsbMouseAbsolutePointerComponentNameGetDriverName (
223 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
225 OUT CHAR16
**DriverName
229 Retrieves a Unicode string that is the user readable name of the controller
230 that is being managed by a driver.
232 This function retrieves the user readable name of the controller specified by
233 ControllerHandle and ChildHandle in the form of a Unicode string. If the
234 driver specified by This has a user readable name in the language specified by
235 Language, then a pointer to the controller name is returned in ControllerName,
236 and EFI_SUCCESS is returned. If the driver specified by This is not currently
237 managing the controller specified by ControllerHandle and ChildHandle,
238 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
239 support the language specified by Language, then EFI_UNSUPPORTED is returned.
241 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
242 EFI_COMPONENT_NAME_PROTOCOL instance.
243 @param ControllerHandle The handle of a controller that the driver
244 specified by This is managing. This handle
245 specifies the controller whose name is to be
247 @param ChildHandle The handle of the child controller to retrieve
248 the name of. This is an optional parameter that
249 may be NULL. It will be NULL for device
250 drivers. It will also be NULL for a bus drivers
251 that wish to retrieve the name of the bus
252 controller. It will not be NULL for a bus
253 driver that wishes to retrieve the name of a
255 @param Language A pointer to a Null-terminated ASCII string
256 array indicating the language. This is the
257 language of the driver name that the caller is
258 requesting, and it must match one of the
259 languages specified in SupportedLanguages. The
260 number of languages supported by a driver is up
261 to the driver writer. Language is specified in
262 RFC 4646 or ISO 639-2 language code format.
263 @param ControllerName A pointer to the Unicode string to return.
264 This Unicode string is the name of the
265 controller specified by ControllerHandle and
266 ChildHandle in the language specified by
267 Language from the point of view of the driver
270 @retval EFI_SUCCESS The Unicode string for the user readable name in
271 the language specified by Language for the
272 driver specified by This was returned in
274 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
275 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
277 @retval EFI_INVALID_PARAMETER Language is NULL.
278 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
279 @retval EFI_UNSUPPORTED The driver specified by This is not currently
280 managing the controller specified by
281 ControllerHandle and ChildHandle.
282 @retval EFI_UNSUPPORTED The driver specified by This does not support
283 the language specified by Language.
288 UsbMouseAbsolutePointerComponentNameGetControllerName (
289 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
290 IN EFI_HANDLE ControllerHandle
,
291 IN EFI_HANDLE ChildHandle OPTIONAL
,
293 OUT CHAR16
**ControllerName
297 // Functions of EFI_ABSOLUTE_POINTER_PROTOCOL
301 Retrieves the current state of a pointer device.
303 @param This A pointer to the EFI_ABSOLUTE_POINTER_PROTOCOL instance.
304 @param MouseState A pointer to the state information on the pointer device.
306 @retval EFI_SUCCESS The state of the pointer device was returned in State.
307 @retval EFI_NOT_READY The state of the pointer device has not changed since the last call to
309 @retval EFI_DEVICE_ERROR A device error occurred while attempting to retrieve the pointer device's
311 @retval EFI_INVALID_PARAMETER State is NULL.
316 GetMouseAbsolutePointerState (
317 IN EFI_ABSOLUTE_POINTER_PROTOCOL
*This
,
318 OUT EFI_ABSOLUTE_POINTER_STATE
*State
322 Resets the pointer device hardware.
324 @param This A pointer to the EFI_ABSOLUTE_POINTER_PROTOCOL instance.
325 @param ExtendedVerification Indicates that the driver may perform a more exhaustive
326 verification operation of the device during reset.
328 @retval EFI_SUCCESS The device was reset.
329 @retval EFI_DEVICE_ERROR The device is not functioning correctly and could not be reset.
334 UsbMouseAbsolutePointerReset (
335 IN EFI_ABSOLUTE_POINTER_PROTOCOL
*This
,
336 IN BOOLEAN ExtendedVerification
340 Event notification function for EFI_ABSOLUTE_POINTER_PROTOCOL.WaitForInput event.
342 @param Event Event to be signaled when there's input from mouse.
343 @param Context Points to USB_MOUSE_ABSOLUTE_POINTER_DEV instance.
348 UsbMouseAbsolutePointerWaitForInput (
354 // Internal worker functions
358 Uses USB I/O to check whether the device is a USB mouse device.
360 @param UsbIo Pointer to a USB I/O protocol instance.
362 @retval TRUE Device is a USB mouse device.
363 @retval FALSE Device is a not USB mouse device.
368 IN EFI_USB_IO_PROTOCOL
*UsbIo
372 Initialize the USB mouse device.
374 This function retrieves and parses HID report descriptor, and
375 initializes state of USB_MOUSE_ABSOLUTE_POINTER_DEV. Then it sets indefinite idle
376 rate for the device. Finally it creates event for delayed recovery,
377 which deals with device error.
379 @param UsbMouseAbsolutePointerDev Device instance to be initialized.
381 @retval EFI_SUCCESS USB mouse device successfully initialized.
382 @retval EFI_UNSUPPORTED HID descriptor type is not report descriptor.
383 @retval Other USB mouse device was not initialized successfully.
387 InitializeUsbMouseDevice (
388 IN USB_MOUSE_ABSOLUTE_POINTER_DEV
*UsbMouseAbsolutePointerDev
392 Handler function for USB mouse's asynchronous interrupt transfer.
394 This function is the handler function for USB mouse's asynchronous interrupt transfer
395 to manage the mouse. It parses data returned from asynchronous interrupt transfer, and
396 get button and movement state.
398 @param Data A pointer to a buffer that is filled with key data which is
399 retrieved via asynchronous interrupt transfer.
400 @param DataLength Indicates the size of the data buffer.
401 @param Context Pointing to USB_KB_DEV instance.
402 @param Result Indicates the result of the asynchronous interrupt transfer.
404 @retval EFI_SUCCESS Asynchronous interrupt transfer is handled successfully.
405 @retval EFI_DEVICE_ERROR Hardware error occurs.
410 OnMouseInterruptComplete (
418 Handler for Delayed Recovery event.
420 This function is the handler for Delayed Recovery event triggered
422 After a device error occurs, the event would be triggered
423 with interval of EFI_USB_INTERRUPT_DELAY. EFI_USB_INTERRUPT_DELAY
424 is defined in USB standard for error handling.
426 @param Event The Delayed Recovery event.
427 @param Context Points to the USB_MOUSE_ABSOLUTE_POINTER_DEV instance.
432 USBMouseRecoveryHandler (
438 Parse Mouse Report Descriptor.
440 According to USB HID Specification, report descriptors are
441 composed of pieces of information. Each piece of information
442 is called an Item. This function retrieves each item from
443 the report descriptor and updates USB_MOUSE_ABSOLUTE_POINTER_DEV.
445 @param UsbMouseAbsolutePointer The instance of USB_MOUSE_ABSOLUTE_POINTER_DEV
446 @param ReportDescriptor Report descriptor to parse
447 @param ReportSize Report descriptor size
449 @retval EFI_SUCCESS Report descriptor successfully parsed.
450 @retval EFI_UNSUPPORTED Report descriptor contains long item.
454 ParseMouseReportDescriptor (
455 OUT USB_MOUSE_ABSOLUTE_POINTER_DEV
*UsbMouseAbsolutePointer
,
456 IN UINT8
*ReportDescriptor
,