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 Portocol, intializes 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
209 for (Index
= 0; Index
< EndpointNumber
; Index
++) {
210 UsbIo
->UsbGetEndpointDescriptor (
216 if ((EndpointDescriptor
.Attributes
& (BIT0
| BIT1
)) == USB_ENDPOINT_INTERRUPT
) {
218 // We only care interrupt endpoint here
220 CopyMem (&UsbMouseAbsolutePointerDevice
->IntEndpointDescriptor
, &EndpointDescriptor
, sizeof(EndpointDescriptor
));
228 // Report Status Code to indicate that there is no USB mouse
231 EFI_ERROR_CODE
| EFI_ERROR_MINOR
,
232 (EFI_PERIPHERAL_MOUSE
| EFI_P_EC_NOT_DETECTED
)
235 // No interrupt endpoint found, then return unsupported.
237 Status
= EFI_UNSUPPORTED
;
242 // Report Status Code here since USB mouse has be detected.
244 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
246 (EFI_PERIPHERAL_MOUSE
| EFI_P_PC_DETECTED
),
247 UsbMouseAbsolutePointerDevice
->DevicePath
250 Status
= InitializeUsbMouseDevice (UsbMouseAbsolutePointerDevice
);
251 if (EFI_ERROR (Status
)) {
253 // Fail to initialize USB mouse device.
255 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
256 EFI_ERROR_CODE
| EFI_ERROR_MINOR
,
257 (EFI_PERIPHERAL_MOUSE
| EFI_P_EC_INTERFACE_ERROR
),
258 UsbMouseAbsolutePointerDevice
->DevicePath
265 // Initialize and install EFI Absolute Pointer Protocol.
267 UsbMouseAbsolutePointerDevice
->AbsolutePointerProtocol
.GetState
= GetMouseAbsolutePointerState
;
268 UsbMouseAbsolutePointerDevice
->AbsolutePointerProtocol
.Reset
= UsbMouseAbsolutePointerReset
;
269 UsbMouseAbsolutePointerDevice
->AbsolutePointerProtocol
.Mode
= &UsbMouseAbsolutePointerDevice
->Mode
;
271 Status
= gBS
->CreateEvent (
274 UsbMouseAbsolutePointerWaitForInput
,
275 UsbMouseAbsolutePointerDevice
,
276 &((UsbMouseAbsolutePointerDevice
->AbsolutePointerProtocol
).WaitForInput
)
278 if (EFI_ERROR (Status
)) {
282 Status
= gBS
->InstallProtocolInterface (
284 &gEfiAbsolutePointerProtocolGuid
,
285 EFI_NATIVE_INTERFACE
,
286 &UsbMouseAbsolutePointerDevice
->AbsolutePointerProtocol
289 if (EFI_ERROR (Status
)) {
294 // The next step would be submitting Asynchronous Interrupt Transfer on this mouse device.
295 // After that we will be able to get key data from it. Thus this is deemed as
296 // the enable action of the mouse, so report status code accordingly.
298 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
300 (EFI_PERIPHERAL_MOUSE
| EFI_P_PC_ENABLE
),
301 UsbMouseAbsolutePointerDevice
->DevicePath
305 // Submit Asynchronous Interrupt Transfer to manage this device.
307 EndpointAddr
= UsbMouseAbsolutePointerDevice
->IntEndpointDescriptor
.EndpointAddress
;
308 PollingInterval
= UsbMouseAbsolutePointerDevice
->IntEndpointDescriptor
.Interval
;
309 PacketSize
= (UINT8
) (UsbMouseAbsolutePointerDevice
->IntEndpointDescriptor
.MaxPacketSize
);
311 Status
= UsbIo
->UsbAsyncInterruptTransfer (
317 OnMouseInterruptComplete
,
318 UsbMouseAbsolutePointerDevice
321 if (EFI_ERROR (Status
)) {
323 // If submit error, uninstall that interface
325 gBS
->UninstallProtocolInterface (
327 &gEfiAbsolutePointerProtocolGuid
,
328 &UsbMouseAbsolutePointerDevice
->AbsolutePointerProtocol
333 UsbMouseAbsolutePointerDevice
->ControllerNameTable
= NULL
;
336 gUsbMouseAbsolutePointerComponentName
.SupportedLanguages
,
337 &UsbMouseAbsolutePointerDevice
->ControllerNameTable
,
338 L
"Generic Usb Mouse Absolute Pointer",
343 gUsbMouseAbsolutePointerComponentName2
.SupportedLanguages
,
344 &UsbMouseAbsolutePointerDevice
->ControllerNameTable
,
345 L
"Generic Usb Mouse Absolute Pointer",
349 gBS
->RestoreTPL (OldTpl
);
356 if (EFI_ERROR (Status
)) {
359 &gEfiUsbIoProtocolGuid
,
360 This
->DriverBindingHandle
,
364 if (UsbMouseAbsolutePointerDevice
!= NULL
) {
365 if ((UsbMouseAbsolutePointerDevice
->AbsolutePointerProtocol
).WaitForInput
!= NULL
) {
366 gBS
->CloseEvent ((UsbMouseAbsolutePointerDevice
->AbsolutePointerProtocol
).WaitForInput
);
369 FreePool (UsbMouseAbsolutePointerDevice
);
370 UsbMouseAbsolutePointerDevice
= NULL
;
375 gBS
->RestoreTPL (OldTpl
);
382 Stop the USB mouse device handled by this driver.
384 @param This The driver binding protocol.
385 @param Controller The controller to release.
386 @param NumberOfChildren The number of handles in ChildHandleBuffer.
387 @param ChildHandleBuffer The array of child handle.
389 @retval EFI_SUCCESS The device was stopped.
390 @retval EFI_UNSUPPORTED Absolute Pointer Protocol is not installed on Controller.
391 @retval Others Fail to uninstall protocols attached on the device.
396 USBMouseAbsolutePointerDriverBindingStop (
397 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
398 IN EFI_HANDLE Controller
,
399 IN UINTN NumberOfChildren
,
400 IN EFI_HANDLE
*ChildHandleBuffer
404 USB_MOUSE_ABSOLUTE_POINTER_DEV
*UsbMouseAbsolutePointerDevice
;
405 EFI_ABSOLUTE_POINTER_PROTOCOL
*AbsolutePointerProtocol
;
406 EFI_USB_IO_PROTOCOL
*UsbIo
;
408 Status
= gBS
->OpenProtocol (
410 &gEfiAbsolutePointerProtocolGuid
,
411 (VOID
**) &AbsolutePointerProtocol
,
412 This
->DriverBindingHandle
,
414 EFI_OPEN_PROTOCOL_GET_PROTOCOL
417 if (EFI_ERROR (Status
)) {
418 return EFI_UNSUPPORTED
;
421 UsbMouseAbsolutePointerDevice
= USB_MOUSE_ABSOLUTE_POINTER_DEV_FROM_MOUSE_PROTOCOL (AbsolutePointerProtocol
);
423 UsbIo
= UsbMouseAbsolutePointerDevice
->UsbIo
;
426 // The key data input from this device will be disabled.
428 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
430 (EFI_PERIPHERAL_MOUSE
| EFI_P_PC_DISABLE
),
431 UsbMouseAbsolutePointerDevice
->DevicePath
435 // Delete the Asynchronous Interrupt Transfer from this device
437 UsbIo
->UsbAsyncInterruptTransfer (
439 UsbMouseAbsolutePointerDevice
->IntEndpointDescriptor
.EndpointAddress
,
441 UsbMouseAbsolutePointerDevice
->IntEndpointDescriptor
.Interval
,
447 Status
= gBS
->UninstallProtocolInterface (
449 &gEfiAbsolutePointerProtocolGuid
,
450 &UsbMouseAbsolutePointerDevice
->AbsolutePointerProtocol
452 if (EFI_ERROR (Status
)) {
458 &gEfiUsbIoProtocolGuid
,
459 This
->DriverBindingHandle
,
464 // Free all resources.
466 gBS
->CloseEvent (UsbMouseAbsolutePointerDevice
->AbsolutePointerProtocol
.WaitForInput
);
468 if (UsbMouseAbsolutePointerDevice
->DelayedRecoveryEvent
!= NULL
) {
469 gBS
->CloseEvent (UsbMouseAbsolutePointerDevice
->DelayedRecoveryEvent
);
470 UsbMouseAbsolutePointerDevice
->DelayedRecoveryEvent
= NULL
;
473 if (UsbMouseAbsolutePointerDevice
->ControllerNameTable
!= NULL
) {
474 FreeUnicodeStringTable (UsbMouseAbsolutePointerDevice
->ControllerNameTable
);
477 FreePool (UsbMouseAbsolutePointerDevice
);
485 Uses USB I/O to check whether the device is a USB mouse device.
487 @param UsbIo Pointer to a USB I/O protocol instance.
489 @retval TRUE Device is a USB mouse device.
490 @retval FALSE Device is a not USB mouse device.
495 IN EFI_USB_IO_PROTOCOL
*UsbIo
499 EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor
;
502 // Get the default interface descriptor
504 Status
= UsbIo
->UsbGetInterfaceDescriptor (
509 if (EFI_ERROR (Status
)) {
513 if ((InterfaceDescriptor
.InterfaceClass
== CLASS_HID
) &&
514 (InterfaceDescriptor
.InterfaceSubClass
== SUBCLASS_BOOT
) &&
515 (InterfaceDescriptor
.InterfaceProtocol
== PROTOCOL_MOUSE
)
525 Initialize the USB mouse device.
527 This function retrieves and parses HID report descriptor, and
528 initializes state of USB_MOUSE_ABSOLUTE_POINTER_DEV. Then it sets indefinite idle
529 rate for the device. Finally it creates event for delayed recovery,
530 which deals with device error.
532 @param UsbMouseAbsolutePointerDev Device instance to be initialized.
534 @retval EFI_SUCCESS USB mouse device successfully initialized.
535 @retval EFI_UNSUPPORTED HID descriptor type is not report descriptor.
536 @retval Other USB mouse device was not initialized successfully.
540 InitializeUsbMouseDevice (
541 IN USB_MOUSE_ABSOLUTE_POINTER_DEV
*UsbMouseAbsolutePointerDev
544 EFI_USB_IO_PROTOCOL
*UsbIo
;
547 EFI_USB_HID_DESCRIPTOR
*MouseHidDesc
;
549 EFI_USB_CONFIG_DESCRIPTOR ConfigDesc
;
551 UINT32 TransferResult
;
556 UsbIo
= UsbMouseAbsolutePointerDev
->UsbIo
;
559 // Get the current configuration descriptor. Note that it doesn't include other descriptors.
561 Status
= UsbIo
->UsbGetConfigDescriptor (
565 if (EFI_ERROR (Status
)) {
570 // By issuing Get_Descriptor(Configuration) request with total length, we get the Configuration descriptor,
571 // all Interface descriptors, all Endpoint descriptors, and the HID descriptor for each interface.
573 Buf
= AllocateZeroPool (ConfigDesc
.TotalLength
);
575 return EFI_OUT_OF_RESOURCES
;
578 Status
= UsbGetDescriptor (
580 (UINT16
)((USB_DESC_TYPE_CONFIG
<< 8) | (ConfigDesc
.ConfigurationValue
- 1)),
582 ConfigDesc
.TotalLength
,
586 if (EFI_ERROR (Status
)) {
593 Head
= (USB_DESC_HEAD
*)Buf
;
597 // Get HID descriptor from the receipt of Get_Descriptor(Configuration) request.
598 // This algorithm is based on the fact that the HID descriptor shall be interleaved
599 // between the interface and endpoint descriptors for HID interfaces.
601 while (Total
< ConfigDesc
.TotalLength
) {
602 if (Head
->Type
== USB_DESC_TYPE_INTERFACE
) {
603 if ((((USB_INTERFACE_DESCRIPTOR
*)Head
)->InterfaceNumber
== UsbMouseAbsolutePointerDev
->InterfaceDescriptor
.InterfaceNumber
) &&
604 (((USB_INTERFACE_DESCRIPTOR
*)Head
)->AlternateSetting
== UsbMouseAbsolutePointerDev
->InterfaceDescriptor
.AlternateSetting
)) {
608 if (Start
&& (Head
->Type
== USB_DESC_TYPE_ENDPOINT
)) {
611 if (Start
&& (Head
->Type
== USB_DESC_TYPE_HID
)) {
612 MouseHidDesc
= (EFI_USB_HID_DESCRIPTOR
*)Head
;
615 Total
= Total
+ (UINT16
)Head
->Len
;
616 Head
= (USB_DESC_HEAD
*)((UINT8
*)Buf
+ Total
);
619 if (MouseHidDesc
== NULL
) {
621 return EFI_UNSUPPORTED
;
625 // Get report descriptor
627 if (MouseHidDesc
->HidClassDesc
[0].DescriptorType
!= USB_DESC_TYPE_REPORT
) {
629 return EFI_UNSUPPORTED
;
632 ReportDesc
= AllocateZeroPool (MouseHidDesc
->HidClassDesc
[0].DescriptorLength
);
633 ASSERT (ReportDesc
!= NULL
);
635 Status
= UsbGetReportDescriptor (
637 UsbMouseAbsolutePointerDev
->InterfaceDescriptor
.InterfaceNumber
,
638 MouseHidDesc
->HidClassDesc
[0].DescriptorLength
,
642 if (EFI_ERROR (Status
)) {
644 FreePool (ReportDesc
);
649 // Parse report descriptor
651 Status
= ParseMouseReportDescriptor (
652 UsbMouseAbsolutePointerDev
,
654 MouseHidDesc
->HidClassDesc
[0].DescriptorLength
657 if (EFI_ERROR (Status
)) {
659 FreePool (ReportDesc
);
663 UsbMouseAbsolutePointerDev
->Mode
.AbsoluteMaxX
= 1024;
664 UsbMouseAbsolutePointerDev
->Mode
.AbsoluteMaxY
= 1024;
665 UsbMouseAbsolutePointerDev
->Mode
.AbsoluteMaxZ
= 0;
666 UsbMouseAbsolutePointerDev
->Mode
.AbsoluteMinX
= 0;
667 UsbMouseAbsolutePointerDev
->Mode
.AbsoluteMinY
= 0;
668 UsbMouseAbsolutePointerDev
->Mode
.AbsoluteMinZ
= 0;
669 UsbMouseAbsolutePointerDev
->Mode
.Attributes
= 0x3;
672 // Let the cursor's starting position is in the center of the screen.
674 UsbMouseAbsolutePointerDev
->State
.CurrentX
=
675 DivU64x32 (UsbMouseAbsolutePointerDev
->Mode
.AbsoluteMaxX
+ UsbMouseAbsolutePointerDev
->Mode
.AbsoluteMinX
, 2);
676 UsbMouseAbsolutePointerDev
->State
.CurrentY
=
677 DivU64x32 (UsbMouseAbsolutePointerDev
->Mode
.AbsoluteMaxY
+ UsbMouseAbsolutePointerDev
->Mode
.AbsoluteMinY
, 2);
680 // Set boot protocol for the USB mouse.
681 // This driver only supports boot protocol.
683 UsbGetProtocolRequest (
685 UsbMouseAbsolutePointerDev
->InterfaceDescriptor
.InterfaceNumber
,
688 if (Protocol
!= BOOT_PROTOCOL
) {
689 Status
= UsbSetProtocolRequest (
691 UsbMouseAbsolutePointerDev
->InterfaceDescriptor
.InterfaceNumber
,
695 if (EFI_ERROR (Status
)) {
697 FreePool (ReportDesc
);
703 FreePool (ReportDesc
);
706 // Create event for delayed recovery, which deals with device error.
708 if (UsbMouseAbsolutePointerDev
->DelayedRecoveryEvent
!= NULL
) {
709 gBS
->CloseEvent (UsbMouseAbsolutePointerDev
->DelayedRecoveryEvent
);
710 UsbMouseAbsolutePointerDev
->DelayedRecoveryEvent
= 0;
714 EVT_TIMER
| EVT_NOTIFY_SIGNAL
,
716 USBMouseRecoveryHandler
,
717 UsbMouseAbsolutePointerDev
,
718 &UsbMouseAbsolutePointerDev
->DelayedRecoveryEvent
726 Handler function for USB mouse's asynchronous interrupt transfer.
728 This function is the handler function for USB mouse's asynchronous interrupt transfer
729 to manage the mouse. It parses data returned from asynchronous interrupt transfer, and
730 get button and movement state.
732 @param Data A pointer to a buffer that is filled with key data which is
733 retrieved via asynchronous interrupt transfer.
734 @param DataLength Indicates the size of the data buffer.
735 @param Context Pointing to USB_KB_DEV instance.
736 @param Result Indicates the result of the asynchronous interrupt transfer.
738 @retval EFI_SUCCESS Asynchronous interrupt transfer is handled successfully.
739 @retval EFI_DEVICE_ERROR Hardware error occurs.
744 OnMouseInterruptComplete (
751 USB_MOUSE_ABSOLUTE_POINTER_DEV
*UsbMouseAbsolutePointerDevice
;
752 EFI_USB_IO_PROTOCOL
*UsbIo
;
756 UsbMouseAbsolutePointerDevice
= (USB_MOUSE_ABSOLUTE_POINTER_DEV
*) Context
;
757 UsbIo
= UsbMouseAbsolutePointerDevice
->UsbIo
;
759 if (Result
!= EFI_USB_NOERROR
) {
761 // Some errors happen during the process
763 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
764 EFI_ERROR_CODE
| EFI_ERROR_MINOR
,
765 (EFI_PERIPHERAL_MOUSE
| EFI_P_EC_INPUT_ERROR
),
766 UsbMouseAbsolutePointerDevice
->DevicePath
769 if ((Result
& EFI_USB_ERR_STALL
) == EFI_USB_ERR_STALL
) {
770 EndpointAddr
= UsbMouseAbsolutePointerDevice
->IntEndpointDescriptor
.EndpointAddress
;
772 UsbClearEndpointHalt (
780 // Delete & Submit this interrupt again
781 // Handler of DelayedRecoveryEvent triggered by timer will re-submit the interrupt.
783 UsbIo
->UsbAsyncInterruptTransfer (
785 UsbMouseAbsolutePointerDevice
->IntEndpointDescriptor
.EndpointAddress
,
793 // EFI_USB_INTERRUPT_DELAY is defined in USB standard for error handling.
796 UsbMouseAbsolutePointerDevice
->DelayedRecoveryEvent
,
798 EFI_USB_INTERRUPT_DELAY
800 return EFI_DEVICE_ERROR
;
804 // If no error and no data, just return EFI_SUCCESS.
806 if (DataLength
== 0 || Data
== NULL
) {
812 // USB HID Specification specifies following data format:
813 // Byte Bits Description
817 // 4 to 7 Device-specific
818 // 1 0 to 7 X displacement
819 // 2 0 to 7 Y displacement
820 // 3 to n 0 to 7 Device specific (optional)
822 if (DataLength
< 3) {
823 return EFI_DEVICE_ERROR
;
826 UsbMouseAbsolutePointerDevice
->StateChanged
= TRUE
;
828 UsbMouseAbsolutePointerDevice
->State
.ActiveButtons
= *(UINT8
*) Data
& (BIT0
| BIT1
| BIT2
);
830 UsbMouseAbsolutePointerDevice
->State
.CurrentX
=
832 MAX ((INT64
) UsbMouseAbsolutePointerDevice
->State
.CurrentX
+ *((INT8
*) Data
+ 1),
833 (INT64
) UsbMouseAbsolutePointerDevice
->Mode
.AbsoluteMinX
),
834 (INT64
) UsbMouseAbsolutePointerDevice
->Mode
.AbsoluteMaxX
836 UsbMouseAbsolutePointerDevice
->State
.CurrentY
=
838 MAX ((INT64
) UsbMouseAbsolutePointerDevice
->State
.CurrentY
+ *((INT8
*) Data
+ 2),
839 (INT64
) UsbMouseAbsolutePointerDevice
->Mode
.AbsoluteMinY
),
840 (INT64
) UsbMouseAbsolutePointerDevice
->Mode
.AbsoluteMaxY
842 if (DataLength
> 3) {
843 UsbMouseAbsolutePointerDevice
->State
.CurrentZ
=
845 MAX ((INT64
) UsbMouseAbsolutePointerDevice
->State
.CurrentZ
+ *((INT8
*) Data
+ 1),
846 (INT64
) UsbMouseAbsolutePointerDevice
->Mode
.AbsoluteMinZ
),
847 (INT64
) UsbMouseAbsolutePointerDevice
->Mode
.AbsoluteMaxZ
855 Retrieves the current state of a pointer device.
857 @param This A pointer to the EFI_ABSOLUTE_POINTER_PROTOCOL instance.
858 @param MouseState A pointer to the state information on the pointer device.
860 @retval EFI_SUCCESS The state of the pointer device was returned in State.
861 @retval EFI_NOT_READY The state of the pointer device has not changed since the last call to
863 @retval EFI_DEVICE_ERROR A device error occurred while attempting to retrieve the pointer device's
865 @retval EFI_INVALID_PARAMETER State is NULL.
870 GetMouseAbsolutePointerState (
871 IN EFI_ABSOLUTE_POINTER_PROTOCOL
*This
,
872 OUT EFI_ABSOLUTE_POINTER_STATE
*State
875 USB_MOUSE_ABSOLUTE_POINTER_DEV
*MouseAbsolutePointerDev
;
878 return EFI_INVALID_PARAMETER
;
881 MouseAbsolutePointerDev
= USB_MOUSE_ABSOLUTE_POINTER_DEV_FROM_MOUSE_PROTOCOL (This
);
883 if (!MouseAbsolutePointerDev
->StateChanged
) {
884 return EFI_NOT_READY
;
888 // Retrieve mouse state from USB_MOUSE_ABSOLUTE_POINTER_DEV,
889 // which was filled by OnMouseInterruptComplete()
893 &MouseAbsolutePointerDev
->State
,
894 sizeof (EFI_ABSOLUTE_POINTER_STATE
)
897 MouseAbsolutePointerDev
->StateChanged
= FALSE
;
904 Resets the pointer device hardware.
906 @param This A pointer to the EFI_ABSOLUTE_POINTER_PROTOCOL instance.
907 @param ExtendedVerification Indicates that the driver may perform a more exhaustive
908 verification operation of the device during reset.
910 @retval EFI_SUCCESS The device was reset.
911 @retval EFI_DEVICE_ERROR The device is not functioning correctly and could not be reset.
916 UsbMouseAbsolutePointerReset (
917 IN EFI_ABSOLUTE_POINTER_PROTOCOL
*This
,
918 IN BOOLEAN ExtendedVerification
921 USB_MOUSE_ABSOLUTE_POINTER_DEV
*UsbMouseAbsolutePointerDevice
;
923 UsbMouseAbsolutePointerDevice
= USB_MOUSE_ABSOLUTE_POINTER_DEV_FROM_MOUSE_PROTOCOL (This
);
925 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
927 (EFI_PERIPHERAL_MOUSE
| EFI_P_PC_RESET
),
928 UsbMouseAbsolutePointerDevice
->DevicePath
932 // Clear mouse state.
935 &UsbMouseAbsolutePointerDevice
->State
,
936 sizeof (EFI_ABSOLUTE_POINTER_STATE
)
940 // Let the cursor's starting position is in the center of the screen.
942 UsbMouseAbsolutePointerDevice
->State
.CurrentX
=
943 DivU64x32 (UsbMouseAbsolutePointerDevice
->Mode
.AbsoluteMaxX
+ UsbMouseAbsolutePointerDevice
->Mode
.AbsoluteMinX
, 2);
944 UsbMouseAbsolutePointerDevice
->State
.CurrentY
=
945 DivU64x32 (UsbMouseAbsolutePointerDevice
->Mode
.AbsoluteMaxY
+ UsbMouseAbsolutePointerDevice
->Mode
.AbsoluteMinY
, 2);
947 UsbMouseAbsolutePointerDevice
->StateChanged
= FALSE
;
953 Event notification function for EFI_ABSOLUTE_POINTER_PROTOCOL.WaitForInput event.
955 @param Event Event to be signaled when there's input from mouse.
956 @param Context Points to USB_MOUSE_ABSOLUTE_POINTER_DEV instance.
961 UsbMouseAbsolutePointerWaitForInput (
966 USB_MOUSE_ABSOLUTE_POINTER_DEV
*UsbMouseAbsolutePointerDev
;
968 UsbMouseAbsolutePointerDev
= (USB_MOUSE_ABSOLUTE_POINTER_DEV
*) Context
;
971 // If there's input from mouse, signal the event.
973 if (UsbMouseAbsolutePointerDev
->StateChanged
) {
974 gBS
->SignalEvent (Event
);
979 Handler for Delayed Recovery event.
981 This function is the handler for Delayed Recovery event triggered
983 After a device error occurs, the event would be triggered
984 with interval of EFI_USB_INTERRUPT_DELAY. EFI_USB_INTERRUPT_DELAY
985 is defined in USB standard for error handling.
987 @param Event The Delayed Recovery event.
988 @param Context Points to the USB_MOUSE_ABSOLUTE_POINTER_DEV instance.
993 USBMouseRecoveryHandler (
998 USB_MOUSE_ABSOLUTE_POINTER_DEV
*UsbMouseAbsolutePointerDev
;
999 EFI_USB_IO_PROTOCOL
*UsbIo
;
1001 UsbMouseAbsolutePointerDev
= (USB_MOUSE_ABSOLUTE_POINTER_DEV
*) Context
;
1003 UsbIo
= UsbMouseAbsolutePointerDev
->UsbIo
;
1006 // Re-submit Asynchronous Interrupt Transfer for recovery.
1008 UsbIo
->UsbAsyncInterruptTransfer (
1010 UsbMouseAbsolutePointerDev
->IntEndpointDescriptor
.EndpointAddress
,
1012 UsbMouseAbsolutePointerDev
->IntEndpointDescriptor
.Interval
,
1013 UsbMouseAbsolutePointerDev
->IntEndpointDescriptor
.MaxPacketSize
,
1014 OnMouseInterruptComplete
,
1015 UsbMouseAbsolutePointerDev