2 USB Mouse Driver that manages USB mouse and produces Absolute Pointer Protocol.
4 Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #include "UsbMouseAbsolutePointer.h"
11 EFI_DRIVER_BINDING_PROTOCOL gUsbMouseAbsolutePointerDriverBinding
= {
12 USBMouseAbsolutePointerDriverBindingSupported
,
13 USBMouseAbsolutePointerDriverBindingStart
,
14 USBMouseAbsolutePointerDriverBindingStop
,
21 Entrypoint of USB Mouse Absolute Pointer Driver.
23 This function is the entrypoint of USB Mouse Driver. It installs Driver Binding
24 Protocols together with Component Name Protocols.
26 @param ImageHandle The firmware allocated handle for the EFI image.
27 @param SystemTable A pointer to the EFI System Table.
29 @retval EFI_SUCCESS The entry point is executed successfully.
34 USBMouseAbsolutePointerDriverBindingEntryPoint (
35 IN EFI_HANDLE ImageHandle
,
36 IN EFI_SYSTEM_TABLE
*SystemTable
41 Status
= EfiLibInstallDriverBindingComponentName2 (
44 &gUsbMouseAbsolutePointerDriverBinding
,
46 &gUsbMouseAbsolutePointerComponentName
,
47 &gUsbMouseAbsolutePointerComponentName2
49 ASSERT_EFI_ERROR (Status
);
56 Check whether USB Mouse Absolute Pointer Driver supports this device.
58 @param This The driver binding protocol.
59 @param Controller The controller handle to check.
60 @param RemainingDevicePath The remaining device path.
62 @retval EFI_SUCCESS The driver supports this controller.
63 @retval other This device isn't supported.
68 USBMouseAbsolutePointerDriverBindingSupported (
69 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
70 IN EFI_HANDLE Controller
,
71 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
75 EFI_USB_IO_PROTOCOL
*UsbIo
;
77 Status
= gBS
->OpenProtocol (
79 &gEfiUsbIoProtocolGuid
,
81 This
->DriverBindingHandle
,
83 EFI_OPEN_PROTOCOL_BY_DRIVER
85 if (EFI_ERROR (Status
)) {
90 // Use the USB I/O Protocol interface to check whether Controller is
91 // a mouse device that can be managed by this driver.
94 if (!IsUsbMouse (UsbIo
)) {
95 Status
= EFI_UNSUPPORTED
;
100 &gEfiUsbIoProtocolGuid
,
101 This
->DriverBindingHandle
,
110 Starts the mouse device with this driver.
112 This function consumes USB I/O Protocol, initializes USB mouse device,
113 installs Absolute Pointer Protocol, and submits Asynchronous Interrupt
114 Transfer to manage the USB mouse device.
116 @param This The driver binding instance.
117 @param Controller Handle of device to bind driver to.
118 @param RemainingDevicePath Optional parameter use to pick a specific child
121 @retval EFI_SUCCESS This driver supports this device.
122 @retval EFI_UNSUPPORTED This driver does not support this device.
123 @retval EFI_DEVICE_ERROR This driver cannot be started due to device Error.
124 @retval EFI_OUT_OF_RESOURCES Can't allocate memory resources.
125 @retval EFI_ALREADY_STARTED This driver has been started.
130 USBMouseAbsolutePointerDriverBindingStart (
131 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
132 IN EFI_HANDLE Controller
,
133 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
137 EFI_USB_IO_PROTOCOL
*UsbIo
;
138 USB_MOUSE_ABSOLUTE_POINTER_DEV
*UsbMouseAbsolutePointerDevice
;
139 UINT8 EndpointNumber
;
140 EFI_USB_ENDPOINT_DESCRIPTOR EndpointDescriptor
;
143 UINT8 PollingInterval
;
148 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
150 // Open USB I/O Protocol
152 Status
= gBS
->OpenProtocol (
154 &gEfiUsbIoProtocolGuid
,
156 This
->DriverBindingHandle
,
158 EFI_OPEN_PROTOCOL_BY_DRIVER
160 if (EFI_ERROR (Status
)) {
164 UsbMouseAbsolutePointerDevice
= AllocateZeroPool (sizeof (USB_MOUSE_ABSOLUTE_POINTER_DEV
));
165 ASSERT (UsbMouseAbsolutePointerDevice
!= NULL
);
167 UsbMouseAbsolutePointerDevice
->UsbIo
= UsbIo
;
168 UsbMouseAbsolutePointerDevice
->Signature
= USB_MOUSE_ABSOLUTE_POINTER_DEV_SIGNATURE
;
171 // Get the Device Path Protocol on Controller's handle
173 Status
= gBS
->OpenProtocol (
175 &gEfiDevicePathProtocolGuid
,
176 (VOID
**) &UsbMouseAbsolutePointerDevice
->DevicePath
,
177 This
->DriverBindingHandle
,
179 EFI_OPEN_PROTOCOL_GET_PROTOCOL
182 if (EFI_ERROR (Status
)) {
187 // Report Status Code here since USB mouse will be detected next.
189 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
191 (EFI_PERIPHERAL_MOUSE
| EFI_P_PC_PRESENCE_DETECT
),
192 UsbMouseAbsolutePointerDevice
->DevicePath
196 // Get interface & endpoint descriptor
198 UsbIo
->UsbGetInterfaceDescriptor (
200 &UsbMouseAbsolutePointerDevice
->InterfaceDescriptor
203 EndpointNumber
= UsbMouseAbsolutePointerDevice
->InterfaceDescriptor
.NumEndpoints
;
206 // Traverse endpoints to find interrupt endpoint IN
209 for (Index
= 0; Index
< EndpointNumber
; Index
++) {
210 UsbIo
->UsbGetEndpointDescriptor (
216 if (((EndpointDescriptor
.Attributes
& (BIT0
| BIT1
)) == USB_ENDPOINT_INTERRUPT
) &&
217 ((EndpointDescriptor
.EndpointAddress
& USB_ENDPOINT_DIR_IN
) != 0)) {
219 // We only care interrupt endpoint here
221 CopyMem (&UsbMouseAbsolutePointerDevice
->IntEndpointDescriptor
, &EndpointDescriptor
, sizeof(EndpointDescriptor
));
229 // Report Status Code to indicate that there is no USB mouse
232 EFI_ERROR_CODE
| EFI_ERROR_MINOR
,
233 (EFI_PERIPHERAL_MOUSE
| EFI_P_EC_NOT_DETECTED
)
236 // No interrupt endpoint found, then return unsupported.
238 Status
= EFI_UNSUPPORTED
;
243 // Report Status Code here since USB mouse has be detected.
245 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
247 (EFI_PERIPHERAL_MOUSE
| EFI_P_PC_DETECTED
),
248 UsbMouseAbsolutePointerDevice
->DevicePath
251 Status
= InitializeUsbMouseDevice (UsbMouseAbsolutePointerDevice
);
252 if (EFI_ERROR (Status
)) {
254 // Fail to initialize USB mouse device.
256 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
257 EFI_ERROR_CODE
| EFI_ERROR_MINOR
,
258 (EFI_PERIPHERAL_MOUSE
| EFI_P_EC_INTERFACE_ERROR
),
259 UsbMouseAbsolutePointerDevice
->DevicePath
266 // Initialize and install EFI Absolute Pointer Protocol.
268 UsbMouseAbsolutePointerDevice
->AbsolutePointerProtocol
.GetState
= GetMouseAbsolutePointerState
;
269 UsbMouseAbsolutePointerDevice
->AbsolutePointerProtocol
.Reset
= UsbMouseAbsolutePointerReset
;
270 UsbMouseAbsolutePointerDevice
->AbsolutePointerProtocol
.Mode
= &UsbMouseAbsolutePointerDevice
->Mode
;
272 Status
= gBS
->CreateEvent (
275 UsbMouseAbsolutePointerWaitForInput
,
276 UsbMouseAbsolutePointerDevice
,
277 &((UsbMouseAbsolutePointerDevice
->AbsolutePointerProtocol
).WaitForInput
)
279 if (EFI_ERROR (Status
)) {
283 Status
= gBS
->InstallProtocolInterface (
285 &gEfiAbsolutePointerProtocolGuid
,
286 EFI_NATIVE_INTERFACE
,
287 &UsbMouseAbsolutePointerDevice
->AbsolutePointerProtocol
290 if (EFI_ERROR (Status
)) {
295 // The next step would be submitting Asynchronous Interrupt Transfer on this mouse device.
296 // After that we will be able to get key data from it. Thus this is deemed as
297 // the enable action of the mouse, so report status code accordingly.
299 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
301 (EFI_PERIPHERAL_MOUSE
| EFI_P_PC_ENABLE
),
302 UsbMouseAbsolutePointerDevice
->DevicePath
306 // Submit Asynchronous Interrupt Transfer to manage this device.
308 EndpointAddr
= UsbMouseAbsolutePointerDevice
->IntEndpointDescriptor
.EndpointAddress
;
309 PollingInterval
= UsbMouseAbsolutePointerDevice
->IntEndpointDescriptor
.Interval
;
310 PacketSize
= (UINT8
) (UsbMouseAbsolutePointerDevice
->IntEndpointDescriptor
.MaxPacketSize
);
312 Status
= UsbIo
->UsbAsyncInterruptTransfer (
318 OnMouseInterruptComplete
,
319 UsbMouseAbsolutePointerDevice
322 if (EFI_ERROR (Status
)) {
324 // If submit error, uninstall that interface
326 gBS
->UninstallProtocolInterface (
328 &gEfiAbsolutePointerProtocolGuid
,
329 &UsbMouseAbsolutePointerDevice
->AbsolutePointerProtocol
334 UsbMouseAbsolutePointerDevice
->ControllerNameTable
= NULL
;
337 gUsbMouseAbsolutePointerComponentName
.SupportedLanguages
,
338 &UsbMouseAbsolutePointerDevice
->ControllerNameTable
,
339 L
"Generic Usb Mouse Absolute Pointer",
344 gUsbMouseAbsolutePointerComponentName2
.SupportedLanguages
,
345 &UsbMouseAbsolutePointerDevice
->ControllerNameTable
,
346 L
"Generic Usb Mouse Absolute Pointer",
350 gBS
->RestoreTPL (OldTpl
);
357 if (EFI_ERROR (Status
)) {
360 &gEfiUsbIoProtocolGuid
,
361 This
->DriverBindingHandle
,
365 if (UsbMouseAbsolutePointerDevice
!= NULL
) {
366 if ((UsbMouseAbsolutePointerDevice
->AbsolutePointerProtocol
).WaitForInput
!= NULL
) {
367 gBS
->CloseEvent ((UsbMouseAbsolutePointerDevice
->AbsolutePointerProtocol
).WaitForInput
);
370 FreePool (UsbMouseAbsolutePointerDevice
);
371 UsbMouseAbsolutePointerDevice
= NULL
;
376 gBS
->RestoreTPL (OldTpl
);
383 Stop the USB mouse device handled by this driver.
385 @param This The driver binding protocol.
386 @param Controller The controller to release.
387 @param NumberOfChildren The number of handles in ChildHandleBuffer.
388 @param ChildHandleBuffer The array of child handle.
390 @retval EFI_SUCCESS The device was stopped.
391 @retval EFI_UNSUPPORTED Absolute Pointer Protocol is not installed on Controller.
392 @retval Others Fail to uninstall protocols attached on the device.
397 USBMouseAbsolutePointerDriverBindingStop (
398 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
399 IN EFI_HANDLE Controller
,
400 IN UINTN NumberOfChildren
,
401 IN EFI_HANDLE
*ChildHandleBuffer
405 USB_MOUSE_ABSOLUTE_POINTER_DEV
*UsbMouseAbsolutePointerDevice
;
406 EFI_ABSOLUTE_POINTER_PROTOCOL
*AbsolutePointerProtocol
;
407 EFI_USB_IO_PROTOCOL
*UsbIo
;
409 Status
= gBS
->OpenProtocol (
411 &gEfiAbsolutePointerProtocolGuid
,
412 (VOID
**) &AbsolutePointerProtocol
,
413 This
->DriverBindingHandle
,
415 EFI_OPEN_PROTOCOL_GET_PROTOCOL
418 if (EFI_ERROR (Status
)) {
419 return EFI_UNSUPPORTED
;
422 UsbMouseAbsolutePointerDevice
= USB_MOUSE_ABSOLUTE_POINTER_DEV_FROM_MOUSE_PROTOCOL (AbsolutePointerProtocol
);
424 UsbIo
= UsbMouseAbsolutePointerDevice
->UsbIo
;
427 // The key data input from this device will be disabled.
429 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
431 (EFI_PERIPHERAL_MOUSE
| EFI_P_PC_DISABLE
),
432 UsbMouseAbsolutePointerDevice
->DevicePath
436 // Delete the Asynchronous Interrupt Transfer from this device
438 UsbIo
->UsbAsyncInterruptTransfer (
440 UsbMouseAbsolutePointerDevice
->IntEndpointDescriptor
.EndpointAddress
,
442 UsbMouseAbsolutePointerDevice
->IntEndpointDescriptor
.Interval
,
448 Status
= gBS
->UninstallProtocolInterface (
450 &gEfiAbsolutePointerProtocolGuid
,
451 &UsbMouseAbsolutePointerDevice
->AbsolutePointerProtocol
453 if (EFI_ERROR (Status
)) {
459 &gEfiUsbIoProtocolGuid
,
460 This
->DriverBindingHandle
,
465 // Free all resources.
467 gBS
->CloseEvent (UsbMouseAbsolutePointerDevice
->AbsolutePointerProtocol
.WaitForInput
);
469 if (UsbMouseAbsolutePointerDevice
->DelayedRecoveryEvent
!= NULL
) {
470 gBS
->CloseEvent (UsbMouseAbsolutePointerDevice
->DelayedRecoveryEvent
);
471 UsbMouseAbsolutePointerDevice
->DelayedRecoveryEvent
= NULL
;
474 if (UsbMouseAbsolutePointerDevice
->ControllerNameTable
!= NULL
) {
475 FreeUnicodeStringTable (UsbMouseAbsolutePointerDevice
->ControllerNameTable
);
478 FreePool (UsbMouseAbsolutePointerDevice
);
486 Uses USB I/O to check whether the device is a USB mouse device.
488 @param UsbIo Pointer to a USB I/O protocol instance.
490 @retval TRUE Device is a USB mouse device.
491 @retval FALSE Device is a not USB mouse device.
496 IN EFI_USB_IO_PROTOCOL
*UsbIo
500 EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor
;
503 // Get the default interface descriptor
505 Status
= UsbIo
->UsbGetInterfaceDescriptor (
510 if (EFI_ERROR (Status
)) {
514 if ((InterfaceDescriptor
.InterfaceClass
== CLASS_HID
) &&
515 (InterfaceDescriptor
.InterfaceSubClass
== SUBCLASS_BOOT
) &&
516 (InterfaceDescriptor
.InterfaceProtocol
== PROTOCOL_MOUSE
)
526 Initialize the USB mouse device.
528 This function retrieves and parses HID report descriptor, and
529 initializes state of USB_MOUSE_ABSOLUTE_POINTER_DEV. Then it sets indefinite idle
530 rate for the device. Finally it creates event for delayed recovery,
531 which deals with device error.
533 @param UsbMouseAbsolutePointerDev Device instance to be initialized.
535 @retval EFI_SUCCESS USB mouse device successfully initialized.
536 @retval EFI_UNSUPPORTED HID descriptor type is not report descriptor.
537 @retval Other USB mouse device was not initialized successfully.
541 InitializeUsbMouseDevice (
542 IN USB_MOUSE_ABSOLUTE_POINTER_DEV
*UsbMouseAbsolutePointerDev
545 EFI_USB_IO_PROTOCOL
*UsbIo
;
548 EFI_USB_HID_DESCRIPTOR
*MouseHidDesc
;
550 EFI_USB_CONFIG_DESCRIPTOR ConfigDesc
;
552 UINT32 TransferResult
;
557 UsbIo
= UsbMouseAbsolutePointerDev
->UsbIo
;
560 // Get the current configuration descriptor. Note that it doesn't include other descriptors.
562 Status
= UsbIo
->UsbGetConfigDescriptor (
566 if (EFI_ERROR (Status
)) {
571 // By issuing Get_Descriptor(Configuration) request with total length, we get the Configuration descriptor,
572 // all Interface descriptors, all Endpoint descriptors, and the HID descriptor for each interface.
574 Buf
= AllocateZeroPool (ConfigDesc
.TotalLength
);
576 return EFI_OUT_OF_RESOURCES
;
579 Status
= UsbGetDescriptor (
581 (UINT16
)((USB_DESC_TYPE_CONFIG
<< 8) | (ConfigDesc
.ConfigurationValue
- 1)),
583 ConfigDesc
.TotalLength
,
587 if (EFI_ERROR (Status
)) {
594 Head
= (USB_DESC_HEAD
*)Buf
;
598 // Get HID descriptor from the receipt of Get_Descriptor(Configuration) request.
599 // This algorithm is based on the fact that the HID descriptor shall be interleaved
600 // between the interface and endpoint descriptors for HID interfaces.
602 while (Total
< ConfigDesc
.TotalLength
) {
603 if (Head
->Type
== USB_DESC_TYPE_INTERFACE
) {
604 if ((((USB_INTERFACE_DESCRIPTOR
*)Head
)->InterfaceNumber
== UsbMouseAbsolutePointerDev
->InterfaceDescriptor
.InterfaceNumber
) &&
605 (((USB_INTERFACE_DESCRIPTOR
*)Head
)->AlternateSetting
== UsbMouseAbsolutePointerDev
->InterfaceDescriptor
.AlternateSetting
)) {
609 if (Start
&& (Head
->Type
== USB_DESC_TYPE_ENDPOINT
)) {
612 if (Start
&& (Head
->Type
== USB_DESC_TYPE_HID
)) {
613 MouseHidDesc
= (EFI_USB_HID_DESCRIPTOR
*)Head
;
616 Total
= Total
+ (UINT16
)Head
->Len
;
617 Head
= (USB_DESC_HEAD
*)((UINT8
*)Buf
+ Total
);
620 if (MouseHidDesc
== NULL
) {
622 return EFI_UNSUPPORTED
;
626 // Get report descriptor
628 if (MouseHidDesc
->HidClassDesc
[0].DescriptorType
!= USB_DESC_TYPE_REPORT
) {
630 return EFI_UNSUPPORTED
;
633 ReportDesc
= AllocateZeroPool (MouseHidDesc
->HidClassDesc
[0].DescriptorLength
);
634 ASSERT (ReportDesc
!= NULL
);
636 Status
= UsbGetReportDescriptor (
638 UsbMouseAbsolutePointerDev
->InterfaceDescriptor
.InterfaceNumber
,
639 MouseHidDesc
->HidClassDesc
[0].DescriptorLength
,
643 if (EFI_ERROR (Status
)) {
645 FreePool (ReportDesc
);
650 // Parse report descriptor
652 Status
= ParseMouseReportDescriptor (
653 UsbMouseAbsolutePointerDev
,
655 MouseHidDesc
->HidClassDesc
[0].DescriptorLength
658 if (EFI_ERROR (Status
)) {
660 FreePool (ReportDesc
);
664 UsbMouseAbsolutePointerDev
->Mode
.AbsoluteMaxX
= 1024;
665 UsbMouseAbsolutePointerDev
->Mode
.AbsoluteMaxY
= 1024;
666 UsbMouseAbsolutePointerDev
->Mode
.AbsoluteMaxZ
= 0;
667 UsbMouseAbsolutePointerDev
->Mode
.AbsoluteMinX
= 0;
668 UsbMouseAbsolutePointerDev
->Mode
.AbsoluteMinY
= 0;
669 UsbMouseAbsolutePointerDev
->Mode
.AbsoluteMinZ
= 0;
670 UsbMouseAbsolutePointerDev
->Mode
.Attributes
= 0x3;
673 // Let the cursor's starting position is in the center of the screen.
675 UsbMouseAbsolutePointerDev
->State
.CurrentX
=
676 DivU64x32 (UsbMouseAbsolutePointerDev
->Mode
.AbsoluteMaxX
+ UsbMouseAbsolutePointerDev
->Mode
.AbsoluteMinX
, 2);
677 UsbMouseAbsolutePointerDev
->State
.CurrentY
=
678 DivU64x32 (UsbMouseAbsolutePointerDev
->Mode
.AbsoluteMaxY
+ UsbMouseAbsolutePointerDev
->Mode
.AbsoluteMinY
, 2);
681 // Set boot protocol for the USB mouse.
682 // This driver only supports boot protocol.
684 UsbGetProtocolRequest (
686 UsbMouseAbsolutePointerDev
->InterfaceDescriptor
.InterfaceNumber
,
689 if (Protocol
!= BOOT_PROTOCOL
) {
690 Status
= UsbSetProtocolRequest (
692 UsbMouseAbsolutePointerDev
->InterfaceDescriptor
.InterfaceNumber
,
696 if (EFI_ERROR (Status
)) {
698 FreePool (ReportDesc
);
704 FreePool (ReportDesc
);
707 // Create event for delayed recovery, which deals with device error.
709 if (UsbMouseAbsolutePointerDev
->DelayedRecoveryEvent
!= NULL
) {
710 gBS
->CloseEvent (UsbMouseAbsolutePointerDev
->DelayedRecoveryEvent
);
711 UsbMouseAbsolutePointerDev
->DelayedRecoveryEvent
= 0;
715 EVT_TIMER
| EVT_NOTIFY_SIGNAL
,
717 USBMouseRecoveryHandler
,
718 UsbMouseAbsolutePointerDev
,
719 &UsbMouseAbsolutePointerDev
->DelayedRecoveryEvent
727 Handler function for USB mouse's asynchronous interrupt transfer.
729 This function is the handler function for USB mouse's asynchronous interrupt transfer
730 to manage the mouse. It parses data returned from asynchronous interrupt transfer, and
731 get button and movement state.
733 @param Data A pointer to a buffer that is filled with key data which is
734 retrieved via asynchronous interrupt transfer.
735 @param DataLength Indicates the size of the data buffer.
736 @param Context Pointing to USB_KB_DEV instance.
737 @param Result Indicates the result of the asynchronous interrupt transfer.
739 @retval EFI_SUCCESS Asynchronous interrupt transfer is handled successfully.
740 @retval EFI_DEVICE_ERROR Hardware error occurs.
745 OnMouseInterruptComplete (
752 USB_MOUSE_ABSOLUTE_POINTER_DEV
*UsbMouseAbsolutePointerDevice
;
753 EFI_USB_IO_PROTOCOL
*UsbIo
;
757 UsbMouseAbsolutePointerDevice
= (USB_MOUSE_ABSOLUTE_POINTER_DEV
*) Context
;
758 UsbIo
= UsbMouseAbsolutePointerDevice
->UsbIo
;
760 if (Result
!= EFI_USB_NOERROR
) {
762 // Some errors happen during the process
764 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
765 EFI_ERROR_CODE
| EFI_ERROR_MINOR
,
766 (EFI_PERIPHERAL_MOUSE
| EFI_P_EC_INPUT_ERROR
),
767 UsbMouseAbsolutePointerDevice
->DevicePath
770 if ((Result
& EFI_USB_ERR_STALL
) == EFI_USB_ERR_STALL
) {
771 EndpointAddr
= UsbMouseAbsolutePointerDevice
->IntEndpointDescriptor
.EndpointAddress
;
773 UsbClearEndpointHalt (
781 // Delete & Submit this interrupt again
782 // Handler of DelayedRecoveryEvent triggered by timer will re-submit the interrupt.
784 UsbIo
->UsbAsyncInterruptTransfer (
786 UsbMouseAbsolutePointerDevice
->IntEndpointDescriptor
.EndpointAddress
,
794 // EFI_USB_INTERRUPT_DELAY is defined in USB standard for error handling.
797 UsbMouseAbsolutePointerDevice
->DelayedRecoveryEvent
,
799 EFI_USB_INTERRUPT_DELAY
801 return EFI_DEVICE_ERROR
;
805 // If no error and no data, just return EFI_SUCCESS.
807 if (DataLength
== 0 || Data
== NULL
) {
813 // USB HID Specification specifies following data format:
814 // Byte Bits Description
818 // 4 to 7 Device-specific
819 // 1 0 to 7 X displacement
820 // 2 0 to 7 Y displacement
821 // 3 to n 0 to 7 Device specific (optional)
823 if (DataLength
< 3) {
824 return EFI_DEVICE_ERROR
;
827 UsbMouseAbsolutePointerDevice
->StateChanged
= TRUE
;
829 UsbMouseAbsolutePointerDevice
->State
.ActiveButtons
= *(UINT8
*) Data
& (BIT0
| BIT1
| BIT2
);
831 UsbMouseAbsolutePointerDevice
->State
.CurrentX
=
833 MAX ((INT64
) UsbMouseAbsolutePointerDevice
->State
.CurrentX
+ *((INT8
*) Data
+ 1),
834 (INT64
) UsbMouseAbsolutePointerDevice
->Mode
.AbsoluteMinX
),
835 (INT64
) UsbMouseAbsolutePointerDevice
->Mode
.AbsoluteMaxX
837 UsbMouseAbsolutePointerDevice
->State
.CurrentY
=
839 MAX ((INT64
) UsbMouseAbsolutePointerDevice
->State
.CurrentY
+ *((INT8
*) Data
+ 2),
840 (INT64
) UsbMouseAbsolutePointerDevice
->Mode
.AbsoluteMinY
),
841 (INT64
) UsbMouseAbsolutePointerDevice
->Mode
.AbsoluteMaxY
843 if (DataLength
> 3) {
844 UsbMouseAbsolutePointerDevice
->State
.CurrentZ
=
846 MAX ((INT64
) UsbMouseAbsolutePointerDevice
->State
.CurrentZ
+ *((INT8
*) Data
+ 1),
847 (INT64
) UsbMouseAbsolutePointerDevice
->Mode
.AbsoluteMinZ
),
848 (INT64
) UsbMouseAbsolutePointerDevice
->Mode
.AbsoluteMaxZ
856 Retrieves the current state of a pointer device.
858 @param This A pointer to the EFI_ABSOLUTE_POINTER_PROTOCOL instance.
859 @param MouseState A pointer to the state information on the pointer device.
861 @retval EFI_SUCCESS The state of the pointer device was returned in State.
862 @retval EFI_NOT_READY The state of the pointer device has not changed since the last call to
864 @retval EFI_DEVICE_ERROR A device error occurred while attempting to retrieve the pointer device's
866 @retval EFI_INVALID_PARAMETER State is NULL.
871 GetMouseAbsolutePointerState (
872 IN EFI_ABSOLUTE_POINTER_PROTOCOL
*This
,
873 OUT EFI_ABSOLUTE_POINTER_STATE
*State
876 USB_MOUSE_ABSOLUTE_POINTER_DEV
*MouseAbsolutePointerDev
;
879 return EFI_INVALID_PARAMETER
;
882 MouseAbsolutePointerDev
= USB_MOUSE_ABSOLUTE_POINTER_DEV_FROM_MOUSE_PROTOCOL (This
);
884 if (!MouseAbsolutePointerDev
->StateChanged
) {
885 return EFI_NOT_READY
;
889 // Retrieve mouse state from USB_MOUSE_ABSOLUTE_POINTER_DEV,
890 // which was filled by OnMouseInterruptComplete()
894 &MouseAbsolutePointerDev
->State
,
895 sizeof (EFI_ABSOLUTE_POINTER_STATE
)
898 MouseAbsolutePointerDev
->StateChanged
= FALSE
;
905 Resets the pointer device hardware.
907 @param This A pointer to the EFI_ABSOLUTE_POINTER_PROTOCOL instance.
908 @param ExtendedVerification Indicates that the driver may perform a more exhaustive
909 verification operation of the device during reset.
911 @retval EFI_SUCCESS The device was reset.
912 @retval EFI_DEVICE_ERROR The device is not functioning correctly and could not be reset.
917 UsbMouseAbsolutePointerReset (
918 IN EFI_ABSOLUTE_POINTER_PROTOCOL
*This
,
919 IN BOOLEAN ExtendedVerification
922 USB_MOUSE_ABSOLUTE_POINTER_DEV
*UsbMouseAbsolutePointerDevice
;
924 UsbMouseAbsolutePointerDevice
= USB_MOUSE_ABSOLUTE_POINTER_DEV_FROM_MOUSE_PROTOCOL (This
);
926 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
928 (EFI_PERIPHERAL_MOUSE
| EFI_P_PC_RESET
),
929 UsbMouseAbsolutePointerDevice
->DevicePath
933 // Clear mouse state.
936 &UsbMouseAbsolutePointerDevice
->State
,
937 sizeof (EFI_ABSOLUTE_POINTER_STATE
)
941 // Let the cursor's starting position is in the center of the screen.
943 UsbMouseAbsolutePointerDevice
->State
.CurrentX
=
944 DivU64x32 (UsbMouseAbsolutePointerDevice
->Mode
.AbsoluteMaxX
+ UsbMouseAbsolutePointerDevice
->Mode
.AbsoluteMinX
, 2);
945 UsbMouseAbsolutePointerDevice
->State
.CurrentY
=
946 DivU64x32 (UsbMouseAbsolutePointerDevice
->Mode
.AbsoluteMaxY
+ UsbMouseAbsolutePointerDevice
->Mode
.AbsoluteMinY
, 2);
948 UsbMouseAbsolutePointerDevice
->StateChanged
= FALSE
;
954 Event notification function for EFI_ABSOLUTE_POINTER_PROTOCOL.WaitForInput event.
956 @param Event Event to be signaled when there's input from mouse.
957 @param Context Points to USB_MOUSE_ABSOLUTE_POINTER_DEV instance.
962 UsbMouseAbsolutePointerWaitForInput (
967 USB_MOUSE_ABSOLUTE_POINTER_DEV
*UsbMouseAbsolutePointerDev
;
969 UsbMouseAbsolutePointerDev
= (USB_MOUSE_ABSOLUTE_POINTER_DEV
*) Context
;
972 // If there's input from mouse, signal the event.
974 if (UsbMouseAbsolutePointerDev
->StateChanged
) {
975 gBS
->SignalEvent (Event
);
980 Handler for Delayed Recovery event.
982 This function is the handler for Delayed Recovery event triggered
984 After a device error occurs, the event would be triggered
985 with interval of EFI_USB_INTERRUPT_DELAY. EFI_USB_INTERRUPT_DELAY
986 is defined in USB standard for error handling.
988 @param Event The Delayed Recovery event.
989 @param Context Points to the USB_MOUSE_ABSOLUTE_POINTER_DEV instance.
994 USBMouseRecoveryHandler (
999 USB_MOUSE_ABSOLUTE_POINTER_DEV
*UsbMouseAbsolutePointerDev
;
1000 EFI_USB_IO_PROTOCOL
*UsbIo
;
1002 UsbMouseAbsolutePointerDev
= (USB_MOUSE_ABSOLUTE_POINTER_DEV
*) Context
;
1004 UsbIo
= UsbMouseAbsolutePointerDev
->UsbIo
;
1007 // Re-submit Asynchronous Interrupt Transfer for recovery.
1009 UsbIo
->UsbAsyncInterruptTransfer (
1011 UsbMouseAbsolutePointerDev
->IntEndpointDescriptor
.EndpointAddress
,
1013 UsbMouseAbsolutePointerDev
->IntEndpointDescriptor
.Interval
,
1014 UsbMouseAbsolutePointerDev
->IntEndpointDescriptor
.MaxPacketSize
,
1015 OnMouseInterruptComplete
,
1016 UsbMouseAbsolutePointerDev