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
);
55 Check whether USB Mouse Absolute Pointer Driver supports this device.
57 @param This The driver binding protocol.
58 @param Controller The controller handle to check.
59 @param RemainingDevicePath The remaining device path.
61 @retval EFI_SUCCESS The driver supports this controller.
62 @retval other This device isn't supported.
67 USBMouseAbsolutePointerDriverBindingSupported (
68 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
69 IN EFI_HANDLE Controller
,
70 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
74 EFI_USB_IO_PROTOCOL
*UsbIo
;
76 Status
= gBS
->OpenProtocol (
78 &gEfiUsbIoProtocolGuid
,
80 This
->DriverBindingHandle
,
82 EFI_OPEN_PROTOCOL_BY_DRIVER
84 if (EFI_ERROR (Status
)) {
89 // Use the USB I/O Protocol interface to check whether Controller is
90 // a mouse device that can be managed by this driver.
93 if (!IsUsbMouse (UsbIo
)) {
94 Status
= EFI_UNSUPPORTED
;
99 &gEfiUsbIoProtocolGuid
,
100 This
->DriverBindingHandle
,
108 Starts the mouse device with this driver.
110 This function consumes USB I/O Protocol, initializes USB mouse device,
111 installs Absolute Pointer Protocol, and submits Asynchronous Interrupt
112 Transfer to manage the USB mouse device.
114 @param This The driver binding instance.
115 @param Controller Handle of device to bind driver to.
116 @param RemainingDevicePath Optional parameter use to pick a specific child
119 @retval EFI_SUCCESS This driver supports this device.
120 @retval EFI_UNSUPPORTED This driver does not support this device.
121 @retval EFI_DEVICE_ERROR This driver cannot be started due to device Error.
122 @retval EFI_OUT_OF_RESOURCES Can't allocate memory resources.
123 @retval EFI_ALREADY_STARTED This driver has been started.
128 USBMouseAbsolutePointerDriverBindingStart (
129 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
130 IN EFI_HANDLE Controller
,
131 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
135 EFI_USB_IO_PROTOCOL
*UsbIo
;
136 USB_MOUSE_ABSOLUTE_POINTER_DEV
*UsbMouseAbsolutePointerDevice
;
137 UINT8 EndpointNumber
;
138 EFI_USB_ENDPOINT_DESCRIPTOR EndpointDescriptor
;
141 UINT8 PollingInterval
;
146 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
148 // Open USB I/O Protocol
150 Status
= gBS
->OpenProtocol (
152 &gEfiUsbIoProtocolGuid
,
154 This
->DriverBindingHandle
,
156 EFI_OPEN_PROTOCOL_BY_DRIVER
158 if (EFI_ERROR (Status
)) {
162 UsbMouseAbsolutePointerDevice
= AllocateZeroPool (sizeof (USB_MOUSE_ABSOLUTE_POINTER_DEV
));
163 ASSERT (UsbMouseAbsolutePointerDevice
!= NULL
);
165 UsbMouseAbsolutePointerDevice
->UsbIo
= UsbIo
;
166 UsbMouseAbsolutePointerDevice
->Signature
= USB_MOUSE_ABSOLUTE_POINTER_DEV_SIGNATURE
;
169 // Get the Device Path Protocol on Controller's handle
171 Status
= gBS
->OpenProtocol (
173 &gEfiDevicePathProtocolGuid
,
174 (VOID
**)&UsbMouseAbsolutePointerDevice
->DevicePath
,
175 This
->DriverBindingHandle
,
177 EFI_OPEN_PROTOCOL_GET_PROTOCOL
180 if (EFI_ERROR (Status
)) {
185 // Report Status Code here since USB mouse will be detected next.
187 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
189 (EFI_PERIPHERAL_MOUSE
| EFI_P_PC_PRESENCE_DETECT
),
190 UsbMouseAbsolutePointerDevice
->DevicePath
194 // Get interface & endpoint descriptor
196 UsbIo
->UsbGetInterfaceDescriptor (
198 &UsbMouseAbsolutePointerDevice
->InterfaceDescriptor
201 EndpointNumber
= UsbMouseAbsolutePointerDevice
->InterfaceDescriptor
.NumEndpoints
;
204 // Traverse endpoints to find interrupt endpoint IN
207 for (Index
= 0; Index
< EndpointNumber
; Index
++) {
208 UsbIo
->UsbGetEndpointDescriptor (
214 if (((EndpointDescriptor
.Attributes
& (BIT0
| BIT1
)) == USB_ENDPOINT_INTERRUPT
) &&
215 ((EndpointDescriptor
.EndpointAddress
& USB_ENDPOINT_DIR_IN
) != 0))
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
);
381 Stop the USB mouse device handled by this driver.
383 @param This The driver binding protocol.
384 @param Controller The controller to release.
385 @param NumberOfChildren The number of handles in ChildHandleBuffer.
386 @param ChildHandleBuffer The array of child handle.
388 @retval EFI_SUCCESS The device was stopped.
389 @retval EFI_UNSUPPORTED Absolute Pointer Protocol is not installed on Controller.
390 @retval Others Fail to uninstall protocols attached on the device.
395 USBMouseAbsolutePointerDriverBindingStop (
396 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
397 IN EFI_HANDLE Controller
,
398 IN UINTN NumberOfChildren
,
399 IN EFI_HANDLE
*ChildHandleBuffer
403 USB_MOUSE_ABSOLUTE_POINTER_DEV
*UsbMouseAbsolutePointerDevice
;
404 EFI_ABSOLUTE_POINTER_PROTOCOL
*AbsolutePointerProtocol
;
405 EFI_USB_IO_PROTOCOL
*UsbIo
;
407 Status
= gBS
->OpenProtocol (
409 &gEfiAbsolutePointerProtocolGuid
,
410 (VOID
**)&AbsolutePointerProtocol
,
411 This
->DriverBindingHandle
,
413 EFI_OPEN_PROTOCOL_GET_PROTOCOL
416 if (EFI_ERROR (Status
)) {
417 return EFI_UNSUPPORTED
;
420 UsbMouseAbsolutePointerDevice
= USB_MOUSE_ABSOLUTE_POINTER_DEV_FROM_MOUSE_PROTOCOL (AbsolutePointerProtocol
);
422 UsbIo
= UsbMouseAbsolutePointerDevice
->UsbIo
;
425 // The key data input from this device will be disabled.
427 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
429 (EFI_PERIPHERAL_MOUSE
| EFI_P_PC_DISABLE
),
430 UsbMouseAbsolutePointerDevice
->DevicePath
434 // Delete the Asynchronous Interrupt Transfer from this device
436 UsbIo
->UsbAsyncInterruptTransfer (
438 UsbMouseAbsolutePointerDevice
->IntEndpointDescriptor
.EndpointAddress
,
440 UsbMouseAbsolutePointerDevice
->IntEndpointDescriptor
.Interval
,
446 Status
= gBS
->UninstallProtocolInterface (
448 &gEfiAbsolutePointerProtocolGuid
,
449 &UsbMouseAbsolutePointerDevice
->AbsolutePointerProtocol
451 if (EFI_ERROR (Status
)) {
457 &gEfiUsbIoProtocolGuid
,
458 This
->DriverBindingHandle
,
463 // Free all resources.
465 gBS
->CloseEvent (UsbMouseAbsolutePointerDevice
->AbsolutePointerProtocol
.WaitForInput
);
467 if (UsbMouseAbsolutePointerDevice
->DelayedRecoveryEvent
!= NULL
) {
468 gBS
->CloseEvent (UsbMouseAbsolutePointerDevice
->DelayedRecoveryEvent
);
469 UsbMouseAbsolutePointerDevice
->DelayedRecoveryEvent
= NULL
;
472 if (UsbMouseAbsolutePointerDevice
->ControllerNameTable
!= NULL
) {
473 FreeUnicodeStringTable (UsbMouseAbsolutePointerDevice
->ControllerNameTable
);
476 FreePool (UsbMouseAbsolutePointerDevice
);
482 Uses USB I/O to check whether the device is a USB mouse device.
484 @param UsbIo Pointer to a USB I/O protocol instance.
486 @retval TRUE Device is a USB mouse device.
487 @retval FALSE Device is a not USB mouse device.
492 IN EFI_USB_IO_PROTOCOL
*UsbIo
496 EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor
;
499 // Get the default interface descriptor
501 Status
= UsbIo
->UsbGetInterfaceDescriptor (
506 if (EFI_ERROR (Status
)) {
510 if ((InterfaceDescriptor
.InterfaceClass
== CLASS_HID
) &&
511 (InterfaceDescriptor
.InterfaceSubClass
== SUBCLASS_BOOT
) &&
512 (InterfaceDescriptor
.InterfaceProtocol
== PROTOCOL_MOUSE
)
522 Initialize the USB mouse device.
524 This function retrieves and parses HID report descriptor, and
525 initializes state of USB_MOUSE_ABSOLUTE_POINTER_DEV. Then it sets indefinite idle
526 rate for the device. Finally it creates event for delayed recovery,
527 which deals with device error.
529 @param UsbMouseAbsolutePointerDev Device instance to be initialized.
531 @retval EFI_SUCCESS USB mouse device successfully initialized.
532 @retval EFI_UNSUPPORTED HID descriptor type is not report descriptor.
533 @retval Other USB mouse device was not initialized successfully.
537 InitializeUsbMouseDevice (
538 IN USB_MOUSE_ABSOLUTE_POINTER_DEV
*UsbMouseAbsolutePointerDev
541 EFI_USB_IO_PROTOCOL
*UsbIo
;
544 EFI_USB_HID_DESCRIPTOR
*MouseHidDesc
;
546 EFI_USB_CONFIG_DESCRIPTOR ConfigDesc
;
548 UINT32 TransferResult
;
553 UsbIo
= UsbMouseAbsolutePointerDev
->UsbIo
;
556 // Get the current configuration descriptor. Note that it doesn't include other descriptors.
558 Status
= UsbIo
->UsbGetConfigDescriptor (
562 if (EFI_ERROR (Status
)) {
567 // By issuing Get_Descriptor(Configuration) request with total length, we get the Configuration descriptor,
568 // all Interface descriptors, all Endpoint descriptors, and the HID descriptor for each interface.
570 Buf
= AllocateZeroPool (ConfigDesc
.TotalLength
);
572 return EFI_OUT_OF_RESOURCES
;
575 Status
= UsbGetDescriptor (
577 (UINT16
)((USB_DESC_TYPE_CONFIG
<< 8) | (ConfigDesc
.ConfigurationValue
- 1)),
579 ConfigDesc
.TotalLength
,
583 if (EFI_ERROR (Status
)) {
590 Head
= (USB_DESC_HEAD
*)Buf
;
594 // Get HID descriptor from the receipt of Get_Descriptor(Configuration) request.
595 // This algorithm is based on the fact that the HID descriptor shall be interleaved
596 // between the interface and endpoint descriptors for HID interfaces.
598 while (Total
< ConfigDesc
.TotalLength
) {
599 if (Head
->Type
== USB_DESC_TYPE_INTERFACE
) {
600 if ((((USB_INTERFACE_DESCRIPTOR
*)Head
)->InterfaceNumber
== UsbMouseAbsolutePointerDev
->InterfaceDescriptor
.InterfaceNumber
) &&
601 (((USB_INTERFACE_DESCRIPTOR
*)Head
)->AlternateSetting
== UsbMouseAbsolutePointerDev
->InterfaceDescriptor
.AlternateSetting
))
607 if (Start
&& (Head
->Type
== USB_DESC_TYPE_ENDPOINT
)) {
611 if (Start
&& (Head
->Type
== USB_DESC_TYPE_HID
)) {
612 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
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
=
833 (INT64
)UsbMouseAbsolutePointerDevice
->State
.CurrentX
+ *((INT8
*)Data
+ 1),
834 (INT64
)UsbMouseAbsolutePointerDevice
->Mode
.AbsoluteMinX
836 (INT64
)UsbMouseAbsolutePointerDevice
->Mode
.AbsoluteMaxX
838 UsbMouseAbsolutePointerDevice
->State
.CurrentY
=
841 (INT64
)UsbMouseAbsolutePointerDevice
->State
.CurrentY
+ *((INT8
*)Data
+ 2),
842 (INT64
)UsbMouseAbsolutePointerDevice
->Mode
.AbsoluteMinY
844 (INT64
)UsbMouseAbsolutePointerDevice
->Mode
.AbsoluteMaxY
846 if (DataLength
> 3) {
847 UsbMouseAbsolutePointerDevice
->State
.CurrentZ
=
850 (INT64
)UsbMouseAbsolutePointerDevice
->State
.CurrentZ
+ *((INT8
*)Data
+ 1),
851 (INT64
)UsbMouseAbsolutePointerDevice
->Mode
.AbsoluteMinZ
853 (INT64
)UsbMouseAbsolutePointerDevice
->Mode
.AbsoluteMaxZ
861 Retrieves the current state of a pointer device.
863 @param This A pointer to the EFI_ABSOLUTE_POINTER_PROTOCOL instance.
864 @param MouseState A pointer to the state information on the pointer device.
866 @retval EFI_SUCCESS The state of the pointer device was returned in State.
867 @retval EFI_NOT_READY The state of the pointer device has not changed since the last call to
869 @retval EFI_DEVICE_ERROR A device error occurred while attempting to retrieve the pointer device's
871 @retval EFI_INVALID_PARAMETER State is NULL.
876 GetMouseAbsolutePointerState (
877 IN EFI_ABSOLUTE_POINTER_PROTOCOL
*This
,
878 OUT EFI_ABSOLUTE_POINTER_STATE
*State
881 USB_MOUSE_ABSOLUTE_POINTER_DEV
*MouseAbsolutePointerDev
;
884 return EFI_INVALID_PARAMETER
;
887 MouseAbsolutePointerDev
= USB_MOUSE_ABSOLUTE_POINTER_DEV_FROM_MOUSE_PROTOCOL (This
);
889 if (!MouseAbsolutePointerDev
->StateChanged
) {
890 return EFI_NOT_READY
;
894 // Retrieve mouse state from USB_MOUSE_ABSOLUTE_POINTER_DEV,
895 // which was filled by OnMouseInterruptComplete()
899 &MouseAbsolutePointerDev
->State
,
900 sizeof (EFI_ABSOLUTE_POINTER_STATE
)
903 MouseAbsolutePointerDev
->StateChanged
= FALSE
;
909 Resets the pointer device hardware.
911 @param This A pointer to the EFI_ABSOLUTE_POINTER_PROTOCOL instance.
912 @param ExtendedVerification Indicates that the driver may perform a more exhaustive
913 verification operation of the device during reset.
915 @retval EFI_SUCCESS The device was reset.
916 @retval EFI_DEVICE_ERROR The device is not functioning correctly and could not be reset.
921 UsbMouseAbsolutePointerReset (
922 IN EFI_ABSOLUTE_POINTER_PROTOCOL
*This
,
923 IN BOOLEAN ExtendedVerification
926 USB_MOUSE_ABSOLUTE_POINTER_DEV
*UsbMouseAbsolutePointerDevice
;
928 UsbMouseAbsolutePointerDevice
= USB_MOUSE_ABSOLUTE_POINTER_DEV_FROM_MOUSE_PROTOCOL (This
);
930 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
932 (EFI_PERIPHERAL_MOUSE
| EFI_P_PC_RESET
),
933 UsbMouseAbsolutePointerDevice
->DevicePath
937 // Clear mouse state.
940 &UsbMouseAbsolutePointerDevice
->State
,
941 sizeof (EFI_ABSOLUTE_POINTER_STATE
)
945 // Let the cursor's starting position is in the center of the screen.
947 UsbMouseAbsolutePointerDevice
->State
.CurrentX
=
948 DivU64x32 (UsbMouseAbsolutePointerDevice
->Mode
.AbsoluteMaxX
+ UsbMouseAbsolutePointerDevice
->Mode
.AbsoluteMinX
, 2);
949 UsbMouseAbsolutePointerDevice
->State
.CurrentY
=
950 DivU64x32 (UsbMouseAbsolutePointerDevice
->Mode
.AbsoluteMaxY
+ UsbMouseAbsolutePointerDevice
->Mode
.AbsoluteMinY
, 2);
952 UsbMouseAbsolutePointerDevice
->StateChanged
= FALSE
;
958 Event notification function for EFI_ABSOLUTE_POINTER_PROTOCOL.WaitForInput event.
960 @param Event Event to be signaled when there's input from mouse.
961 @param Context Points to USB_MOUSE_ABSOLUTE_POINTER_DEV instance.
966 UsbMouseAbsolutePointerWaitForInput (
971 USB_MOUSE_ABSOLUTE_POINTER_DEV
*UsbMouseAbsolutePointerDev
;
973 UsbMouseAbsolutePointerDev
= (USB_MOUSE_ABSOLUTE_POINTER_DEV
*)Context
;
976 // If there's input from mouse, signal the event.
978 if (UsbMouseAbsolutePointerDev
->StateChanged
) {
979 gBS
->SignalEvent (Event
);
984 Handler for Delayed Recovery event.
986 This function is the handler for Delayed Recovery event triggered
988 After a device error occurs, the event would be triggered
989 with interval of EFI_USB_INTERRUPT_DELAY. EFI_USB_INTERRUPT_DELAY
990 is defined in USB standard for error handling.
992 @param Event The Delayed Recovery event.
993 @param Context Points to the USB_MOUSE_ABSOLUTE_POINTER_DEV instance.
998 USBMouseRecoveryHandler (
1003 USB_MOUSE_ABSOLUTE_POINTER_DEV
*UsbMouseAbsolutePointerDev
;
1004 EFI_USB_IO_PROTOCOL
*UsbIo
;
1006 UsbMouseAbsolutePointerDev
= (USB_MOUSE_ABSOLUTE_POINTER_DEV
*)Context
;
1008 UsbIo
= UsbMouseAbsolutePointerDev
->UsbIo
;
1011 // Re-submit Asynchronous Interrupt Transfer for recovery.
1013 UsbIo
->UsbAsyncInterruptTransfer (
1015 UsbMouseAbsolutePointerDev
->IntEndpointDescriptor
.EndpointAddress
,
1017 UsbMouseAbsolutePointerDev
->IntEndpointDescriptor
.Interval
,
1018 UsbMouseAbsolutePointerDev
->IntEndpointDescriptor
.MaxPacketSize
,
1019 OnMouseInterruptComplete
,
1020 UsbMouseAbsolutePointerDev