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 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 #include "UsbMouseAbsolutePointer.h"
17 EFI_DRIVER_BINDING_PROTOCOL gUsbMouseAbsolutePointerDriverBinding
= {
18 USBMouseAbsolutePointerDriverBindingSupported
,
19 USBMouseAbsolutePointerDriverBindingStart
,
20 USBMouseAbsolutePointerDriverBindingStop
,
27 Entrypoint of USB Mouse Absolute Pointer Driver.
29 This function is the entrypoint of USB Mouse Driver. It installs Driver Binding
30 Protocols together with Component Name Protocols.
32 @param ImageHandle The firmware allocated handle for the EFI image.
33 @param SystemTable A pointer to the EFI System Table.
35 @retval EFI_SUCCESS The entry point is executed successfully.
40 USBMouseAbsolutePointerDriverBindingEntryPoint (
41 IN EFI_HANDLE ImageHandle
,
42 IN EFI_SYSTEM_TABLE
*SystemTable
47 Status
= EfiLibInstallDriverBindingComponentName2 (
50 &gUsbMouseAbsolutePointerDriverBinding
,
52 &gUsbMouseAbsolutePointerComponentName
,
53 &gUsbMouseAbsolutePointerComponentName2
55 ASSERT_EFI_ERROR (Status
);
62 Check whether USB Mouse Absolute Pointer Driver supports this device.
64 @param This The driver binding protocol.
65 @param Controller The controller handle to check.
66 @param RemainingDevicePath The remaining device path.
68 @retval EFI_SUCCESS The driver supports this controller.
69 @retval other This device isn't supported.
74 USBMouseAbsolutePointerDriverBindingSupported (
75 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
76 IN EFI_HANDLE Controller
,
77 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
81 EFI_USB_IO_PROTOCOL
*UsbIo
;
83 Status
= gBS
->OpenProtocol (
85 &gEfiUsbIoProtocolGuid
,
87 This
->DriverBindingHandle
,
89 EFI_OPEN_PROTOCOL_BY_DRIVER
91 if (EFI_ERROR (Status
)) {
96 // Use the USB I/O Protocol interface to check whether Controller is
97 // a mouse device that can be managed by this driver.
100 if (!IsUsbMouse (UsbIo
)) {
101 Status
= EFI_UNSUPPORTED
;
106 &gEfiUsbIoProtocolGuid
,
107 This
->DriverBindingHandle
,
116 Starts the mouse device with this driver.
118 This function consumes USB I/O Portocol, intializes USB mouse device,
119 installs Absolute Pointer Protocol, and submits Asynchronous Interrupt
120 Transfer to manage the USB mouse device.
122 @param This The driver binding instance.
123 @param Controller Handle of device to bind driver to.
124 @param RemainingDevicePath Optional parameter use to pick a specific child
127 @retval EFI_SUCCESS This driver supports this device.
128 @retval EFI_UNSUPPORTED This driver does not support this device.
129 @retval EFI_DEVICE_ERROR This driver cannot be started due to device Error.
130 @retval EFI_OUT_OF_RESOURCES Can't allocate memory resources.
131 @retval EFI_ALREADY_STARTED This driver has been started.
136 USBMouseAbsolutePointerDriverBindingStart (
137 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
138 IN EFI_HANDLE Controller
,
139 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
143 EFI_USB_IO_PROTOCOL
*UsbIo
;
144 USB_MOUSE_ABSOLUTE_POINTER_DEV
*UsbMouseAbsolutePointerDevice
;
145 UINT8 EndpointNumber
;
146 EFI_USB_ENDPOINT_DESCRIPTOR EndpointDescriptor
;
149 UINT8 PollingInterval
;
154 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
156 // Open USB I/O Protocol
158 Status
= gBS
->OpenProtocol (
160 &gEfiUsbIoProtocolGuid
,
162 This
->DriverBindingHandle
,
164 EFI_OPEN_PROTOCOL_BY_DRIVER
166 if (EFI_ERROR (Status
)) {
170 UsbMouseAbsolutePointerDevice
= AllocateZeroPool (sizeof (USB_MOUSE_ABSOLUTE_POINTER_DEV
));
171 ASSERT (UsbMouseAbsolutePointerDevice
!= NULL
);
173 UsbMouseAbsolutePointerDevice
->UsbIo
= UsbIo
;
174 UsbMouseAbsolutePointerDevice
->Signature
= USB_MOUSE_ABSOLUTE_POINTER_DEV_SIGNATURE
;
177 // Get the Device Path Protocol on Controller's handle
179 Status
= gBS
->OpenProtocol (
181 &gEfiDevicePathProtocolGuid
,
182 (VOID
**) &UsbMouseAbsolutePointerDevice
->DevicePath
,
183 This
->DriverBindingHandle
,
185 EFI_OPEN_PROTOCOL_GET_PROTOCOL
188 if (EFI_ERROR (Status
)) {
193 // Report Status Code here since USB mouse will be detected next.
195 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
197 (EFI_PERIPHERAL_MOUSE
| EFI_P_PC_PRESENCE_DETECT
),
198 UsbMouseAbsolutePointerDevice
->DevicePath
202 // Get interface & endpoint descriptor
204 UsbIo
->UsbGetInterfaceDescriptor (
206 &UsbMouseAbsolutePointerDevice
->InterfaceDescriptor
209 EndpointNumber
= UsbMouseAbsolutePointerDevice
->InterfaceDescriptor
.NumEndpoints
;
212 // Traverse endpoints to find interrupt endpoint
215 for (Index
= 0; Index
< EndpointNumber
; Index
++) {
216 UsbIo
->UsbGetEndpointDescriptor (
222 if ((EndpointDescriptor
.Attributes
& (BIT0
| BIT1
)) == USB_ENDPOINT_INTERRUPT
) {
224 // We only care interrupt endpoint here
226 CopyMem (&UsbMouseAbsolutePointerDevice
->IntEndpointDescriptor
, &EndpointDescriptor
, sizeof(EndpointDescriptor
));
234 // Report Status Code to indicate that there is no USB mouse
237 EFI_ERROR_CODE
| EFI_ERROR_MINOR
,
238 (EFI_PERIPHERAL_MOUSE
| EFI_P_EC_NOT_DETECTED
)
241 // No interrupt endpoint found, then return unsupported.
243 Status
= EFI_UNSUPPORTED
;
248 // Report Status Code here since USB mouse has be detected.
250 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
252 (EFI_PERIPHERAL_MOUSE
| EFI_P_PC_DETECTED
),
253 UsbMouseAbsolutePointerDevice
->DevicePath
256 Status
= InitializeUsbMouseDevice (UsbMouseAbsolutePointerDevice
);
257 if (EFI_ERROR (Status
)) {
259 // Fail to initialize USB mouse device.
261 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
262 EFI_ERROR_CODE
| EFI_ERROR_MINOR
,
263 (EFI_PERIPHERAL_MOUSE
| EFI_P_EC_INTERFACE_ERROR
),
264 UsbMouseAbsolutePointerDevice
->DevicePath
271 // Initialize and install EFI Absolute Pointer Protocol.
273 UsbMouseAbsolutePointerDevice
->AbsolutePointerProtocol
.GetState
= GetMouseAbsolutePointerState
;
274 UsbMouseAbsolutePointerDevice
->AbsolutePointerProtocol
.Reset
= UsbMouseAbsolutePointerReset
;
275 UsbMouseAbsolutePointerDevice
->AbsolutePointerProtocol
.Mode
= &UsbMouseAbsolutePointerDevice
->Mode
;
277 Status
= gBS
->CreateEvent (
280 UsbMouseAbsolutePointerWaitForInput
,
281 UsbMouseAbsolutePointerDevice
,
282 &((UsbMouseAbsolutePointerDevice
->AbsolutePointerProtocol
).WaitForInput
)
284 if (EFI_ERROR (Status
)) {
288 Status
= gBS
->InstallProtocolInterface (
290 &gEfiAbsolutePointerProtocolGuid
,
291 EFI_NATIVE_INTERFACE
,
292 &UsbMouseAbsolutePointerDevice
->AbsolutePointerProtocol
295 if (EFI_ERROR (Status
)) {
300 // The next step would be submitting Asynchronous Interrupt Transfer on this mouse device.
301 // After that we will be able to get key data from it. Thus this is deemed as
302 // the enable action of the mouse, so report status code accordingly.
304 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
306 (EFI_PERIPHERAL_MOUSE
| EFI_P_PC_ENABLE
),
307 UsbMouseAbsolutePointerDevice
->DevicePath
311 // Submit Asynchronous Interrupt Transfer to manage this device.
313 EndpointAddr
= UsbMouseAbsolutePointerDevice
->IntEndpointDescriptor
.EndpointAddress
;
314 PollingInterval
= UsbMouseAbsolutePointerDevice
->IntEndpointDescriptor
.Interval
;
315 PacketSize
= (UINT8
) (UsbMouseAbsolutePointerDevice
->IntEndpointDescriptor
.MaxPacketSize
);
317 Status
= UsbIo
->UsbAsyncInterruptTransfer (
323 OnMouseInterruptComplete
,
324 UsbMouseAbsolutePointerDevice
327 if (EFI_ERROR (Status
)) {
329 // If submit error, uninstall that interface
331 gBS
->UninstallProtocolInterface (
333 &gEfiAbsolutePointerProtocolGuid
,
334 &UsbMouseAbsolutePointerDevice
->AbsolutePointerProtocol
339 UsbMouseAbsolutePointerDevice
->ControllerNameTable
= NULL
;
342 gUsbMouseAbsolutePointerComponentName
.SupportedLanguages
,
343 &UsbMouseAbsolutePointerDevice
->ControllerNameTable
,
344 L
"Generic Usb Mouse Absolute Pointer",
349 gUsbMouseAbsolutePointerComponentName2
.SupportedLanguages
,
350 &UsbMouseAbsolutePointerDevice
->ControllerNameTable
,
351 L
"Generic Usb Mouse Absolute Pointer",
355 gBS
->RestoreTPL (OldTpl
);
362 if (EFI_ERROR (Status
)) {
365 &gEfiUsbIoProtocolGuid
,
366 This
->DriverBindingHandle
,
370 if (UsbMouseAbsolutePointerDevice
!= NULL
) {
371 if ((UsbMouseAbsolutePointerDevice
->AbsolutePointerProtocol
).WaitForInput
!= NULL
) {
372 gBS
->CloseEvent ((UsbMouseAbsolutePointerDevice
->AbsolutePointerProtocol
).WaitForInput
);
375 FreePool (UsbMouseAbsolutePointerDevice
);
376 UsbMouseAbsolutePointerDevice
= NULL
;
381 gBS
->RestoreTPL (OldTpl
);
388 Stop the USB mouse device handled by this driver.
390 @param This The driver binding protocol.
391 @param Controller The controller to release.
392 @param NumberOfChildren The number of handles in ChildHandleBuffer.
393 @param ChildHandleBuffer The array of child handle.
395 @retval EFI_SUCCESS The device was stopped.
396 @retval EFI_UNSUPPORTED Absolute Pointer Protocol is not installed on Controller.
397 @retval Others Fail to uninstall protocols attached on the device.
402 USBMouseAbsolutePointerDriverBindingStop (
403 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
404 IN EFI_HANDLE Controller
,
405 IN UINTN NumberOfChildren
,
406 IN EFI_HANDLE
*ChildHandleBuffer
410 USB_MOUSE_ABSOLUTE_POINTER_DEV
*UsbMouseAbsolutePointerDevice
;
411 EFI_ABSOLUTE_POINTER_PROTOCOL
*AbsolutePointerProtocol
;
412 EFI_USB_IO_PROTOCOL
*UsbIo
;
414 Status
= gBS
->OpenProtocol (
416 &gEfiAbsolutePointerProtocolGuid
,
417 (VOID
**) &AbsolutePointerProtocol
,
418 This
->DriverBindingHandle
,
420 EFI_OPEN_PROTOCOL_GET_PROTOCOL
423 if (EFI_ERROR (Status
)) {
424 return EFI_UNSUPPORTED
;
427 UsbMouseAbsolutePointerDevice
= USB_MOUSE_ABSOLUTE_POINTER_DEV_FROM_MOUSE_PROTOCOL (AbsolutePointerProtocol
);
429 UsbIo
= UsbMouseAbsolutePointerDevice
->UsbIo
;
432 // The key data input from this device will be disabled.
434 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
436 (EFI_PERIPHERAL_MOUSE
| EFI_P_PC_DISABLE
),
437 UsbMouseAbsolutePointerDevice
->DevicePath
441 // Delete the Asynchronous Interrupt Transfer from this device
443 UsbIo
->UsbAsyncInterruptTransfer (
445 UsbMouseAbsolutePointerDevice
->IntEndpointDescriptor
.EndpointAddress
,
447 UsbMouseAbsolutePointerDevice
->IntEndpointDescriptor
.Interval
,
453 Status
= gBS
->UninstallProtocolInterface (
455 &gEfiAbsolutePointerProtocolGuid
,
456 &UsbMouseAbsolutePointerDevice
->AbsolutePointerProtocol
458 if (EFI_ERROR (Status
)) {
464 &gEfiUsbIoProtocolGuid
,
465 This
->DriverBindingHandle
,
470 // Free all resources.
472 gBS
->CloseEvent (UsbMouseAbsolutePointerDevice
->AbsolutePointerProtocol
.WaitForInput
);
474 if (UsbMouseAbsolutePointerDevice
->DelayedRecoveryEvent
!= NULL
) {
475 gBS
->CloseEvent (UsbMouseAbsolutePointerDevice
->DelayedRecoveryEvent
);
476 UsbMouseAbsolutePointerDevice
->DelayedRecoveryEvent
= NULL
;
479 if (UsbMouseAbsolutePointerDevice
->ControllerNameTable
!= NULL
) {
480 FreeUnicodeStringTable (UsbMouseAbsolutePointerDevice
->ControllerNameTable
);
483 FreePool (UsbMouseAbsolutePointerDevice
);
491 Uses USB I/O to check whether the device is a USB mouse device.
493 @param UsbIo Pointer to a USB I/O protocol instance.
495 @retval TRUE Device is a USB mouse device.
496 @retval FALSE Device is a not USB mouse device.
501 IN EFI_USB_IO_PROTOCOL
*UsbIo
505 EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor
;
508 // Get the default interface descriptor
510 Status
= UsbIo
->UsbGetInterfaceDescriptor (
515 if (EFI_ERROR (Status
)) {
519 if ((InterfaceDescriptor
.InterfaceClass
== CLASS_HID
) &&
520 (InterfaceDescriptor
.InterfaceSubClass
== SUBCLASS_BOOT
) &&
521 (InterfaceDescriptor
.InterfaceProtocol
== PROTOCOL_MOUSE
)
531 Initialize the USB mouse device.
533 This function retrieves and parses HID report descriptor, and
534 initializes state of USB_MOUSE_ABSOLUTE_POINTER_DEV. Then it sets indefinite idle
535 rate for the device. Finally it creates event for delayed recovery,
536 which deals with device error.
538 @param UsbMouseAbsolutePointerDev Device instance to be initialized.
540 @retval EFI_SUCCESS USB mouse device successfully initialized.
541 @retval EFI_UNSUPPORTED HID descriptor type is not report descriptor.
542 @retval Other USB mouse device was not initialized successfully.
546 InitializeUsbMouseDevice (
547 IN USB_MOUSE_ABSOLUTE_POINTER_DEV
*UsbMouseAbsolutePointerDev
550 EFI_USB_IO_PROTOCOL
*UsbIo
;
553 EFI_USB_HID_DESCRIPTOR
*MouseHidDesc
;
555 EFI_USB_CONFIG_DESCRIPTOR ConfigDesc
;
557 UINT32 TransferResult
;
562 UsbIo
= UsbMouseAbsolutePointerDev
->UsbIo
;
565 // Get the current configuration descriptor. Note that it doesn't include other descriptors.
567 Status
= UsbIo
->UsbGetConfigDescriptor (
571 if (EFI_ERROR (Status
)) {
576 // By issuing Get_Descriptor(Configuration) request with total length, we get the Configuration descriptor,
577 // all Interface descriptors, all Endpoint descriptors, and the HID descriptor for each interface.
579 Buf
= AllocateZeroPool (ConfigDesc
.TotalLength
);
581 return EFI_OUT_OF_RESOURCES
;
584 Status
= UsbGetDescriptor (
586 (UINT16
)((USB_DESC_TYPE_CONFIG
<< 8) | (ConfigDesc
.ConfigurationValue
- 1)),
588 ConfigDesc
.TotalLength
,
592 if (EFI_ERROR (Status
)) {
599 Head
= (USB_DESC_HEAD
*)Buf
;
603 // Get HID descriptor from the receipt of Get_Descriptor(Configuration) request.
604 // This algorithm is based on the fact that the HID descriptor shall be interleaved
605 // between the interface and endpoint descriptors for HID interfaces.
607 while (Total
< ConfigDesc
.TotalLength
) {
608 if (Head
->Type
== USB_DESC_TYPE_INTERFACE
) {
609 if ((((USB_INTERFACE_DESCRIPTOR
*)Head
)->InterfaceNumber
== UsbMouseAbsolutePointerDev
->InterfaceDescriptor
.InterfaceNumber
) &&
610 (((USB_INTERFACE_DESCRIPTOR
*)Head
)->AlternateSetting
== UsbMouseAbsolutePointerDev
->InterfaceDescriptor
.AlternateSetting
)) {
614 if (Start
&& (Head
->Type
== USB_DESC_TYPE_ENDPOINT
)) {
617 if (Start
&& (Head
->Type
== USB_DESC_TYPE_HID
)) {
618 MouseHidDesc
= (EFI_USB_HID_DESCRIPTOR
*)Head
;
621 Total
= Total
+ (UINT16
)Head
->Len
;
622 Head
= (USB_DESC_HEAD
*)((UINT8
*)Buf
+ Total
);
625 if (MouseHidDesc
== NULL
) {
627 return EFI_UNSUPPORTED
;
631 // Get report descriptor
633 if (MouseHidDesc
->HidClassDesc
[0].DescriptorType
!= USB_DESC_TYPE_REPORT
) {
635 return EFI_UNSUPPORTED
;
638 ReportDesc
= AllocateZeroPool (MouseHidDesc
->HidClassDesc
[0].DescriptorLength
);
639 ASSERT (ReportDesc
!= NULL
);
641 Status
= UsbGetReportDescriptor (
643 UsbMouseAbsolutePointerDev
->InterfaceDescriptor
.InterfaceNumber
,
644 MouseHidDesc
->HidClassDesc
[0].DescriptorLength
,
648 if (EFI_ERROR (Status
)) {
650 FreePool (ReportDesc
);
655 // Parse report descriptor
657 Status
= ParseMouseReportDescriptor (
658 UsbMouseAbsolutePointerDev
,
660 MouseHidDesc
->HidClassDesc
[0].DescriptorLength
663 if (EFI_ERROR (Status
)) {
665 FreePool (ReportDesc
);
669 UsbMouseAbsolutePointerDev
->Mode
.AbsoluteMaxX
= 1024;
670 UsbMouseAbsolutePointerDev
->Mode
.AbsoluteMaxY
= 1024;
671 UsbMouseAbsolutePointerDev
->Mode
.AbsoluteMaxZ
= 0;
672 UsbMouseAbsolutePointerDev
->Mode
.AbsoluteMinX
= 0;
673 UsbMouseAbsolutePointerDev
->Mode
.AbsoluteMinY
= 0;
674 UsbMouseAbsolutePointerDev
->Mode
.AbsoluteMinZ
= 0;
675 UsbMouseAbsolutePointerDev
->Mode
.Attributes
= 0x3;
678 // Let the cursor's starting position is in the center of the screen.
680 UsbMouseAbsolutePointerDev
->State
.CurrentX
=
681 DivU64x32 (UsbMouseAbsolutePointerDev
->Mode
.AbsoluteMaxX
+ UsbMouseAbsolutePointerDev
->Mode
.AbsoluteMinX
, 2);
682 UsbMouseAbsolutePointerDev
->State
.CurrentY
=
683 DivU64x32 (UsbMouseAbsolutePointerDev
->Mode
.AbsoluteMaxY
+ UsbMouseAbsolutePointerDev
->Mode
.AbsoluteMinY
, 2);
686 // Set boot protocol for the USB mouse.
687 // This driver only supports boot protocol.
689 UsbGetProtocolRequest (
691 UsbMouseAbsolutePointerDev
->InterfaceDescriptor
.InterfaceNumber
,
694 if (Protocol
!= BOOT_PROTOCOL
) {
695 Status
= UsbSetProtocolRequest (
697 UsbMouseAbsolutePointerDev
->InterfaceDescriptor
.InterfaceNumber
,
701 if (EFI_ERROR (Status
)) {
703 FreePool (ReportDesc
);
709 FreePool (ReportDesc
);
712 // Create event for delayed recovery, which deals with device error.
714 if (UsbMouseAbsolutePointerDev
->DelayedRecoveryEvent
!= NULL
) {
715 gBS
->CloseEvent (UsbMouseAbsolutePointerDev
->DelayedRecoveryEvent
);
716 UsbMouseAbsolutePointerDev
->DelayedRecoveryEvent
= 0;
720 EVT_TIMER
| EVT_NOTIFY_SIGNAL
,
722 USBMouseRecoveryHandler
,
723 UsbMouseAbsolutePointerDev
,
724 &UsbMouseAbsolutePointerDev
->DelayedRecoveryEvent
732 Handler function for USB mouse's asynchronous interrupt transfer.
734 This function is the handler function for USB mouse's asynchronous interrupt transfer
735 to manage the mouse. It parses data returned from asynchronous interrupt transfer, and
736 get button and movement state.
738 @param Data A pointer to a buffer that is filled with key data which is
739 retrieved via asynchronous interrupt transfer.
740 @param DataLength Indicates the size of the data buffer.
741 @param Context Pointing to USB_KB_DEV instance.
742 @param Result Indicates the result of the asynchronous interrupt transfer.
744 @retval EFI_SUCCESS Asynchronous interrupt transfer is handled successfully.
745 @retval EFI_DEVICE_ERROR Hardware error occurs.
750 OnMouseInterruptComplete (
757 USB_MOUSE_ABSOLUTE_POINTER_DEV
*UsbMouseAbsolutePointerDevice
;
758 EFI_USB_IO_PROTOCOL
*UsbIo
;
762 UsbMouseAbsolutePointerDevice
= (USB_MOUSE_ABSOLUTE_POINTER_DEV
*) Context
;
763 UsbIo
= UsbMouseAbsolutePointerDevice
->UsbIo
;
765 if (Result
!= EFI_USB_NOERROR
) {
767 // Some errors happen during the process
769 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
770 EFI_ERROR_CODE
| EFI_ERROR_MINOR
,
771 (EFI_PERIPHERAL_MOUSE
| EFI_P_EC_INPUT_ERROR
),
772 UsbMouseAbsolutePointerDevice
->DevicePath
775 if ((Result
& EFI_USB_ERR_STALL
) == EFI_USB_ERR_STALL
) {
776 EndpointAddr
= UsbMouseAbsolutePointerDevice
->IntEndpointDescriptor
.EndpointAddress
;
778 UsbClearEndpointHalt (
786 // Delete & Submit this interrupt again
787 // Handler of DelayedRecoveryEvent triggered by timer will re-submit the interrupt.
789 UsbIo
->UsbAsyncInterruptTransfer (
791 UsbMouseAbsolutePointerDevice
->IntEndpointDescriptor
.EndpointAddress
,
799 // EFI_USB_INTERRUPT_DELAY is defined in USB standard for error handling.
802 UsbMouseAbsolutePointerDevice
->DelayedRecoveryEvent
,
804 EFI_USB_INTERRUPT_DELAY
806 return EFI_DEVICE_ERROR
;
810 // If no error and no data, just return EFI_SUCCESS.
812 if (DataLength
== 0 || Data
== NULL
) {
818 // USB HID Specification specifies following data format:
819 // Byte Bits Description
823 // 4 to 7 Device-specific
824 // 1 0 to 7 X displacement
825 // 2 0 to 7 Y displacement
826 // 3 to n 0 to 7 Device specific (optional)
828 if (DataLength
< 3) {
829 return EFI_DEVICE_ERROR
;
832 UsbMouseAbsolutePointerDevice
->StateChanged
= TRUE
;
834 UsbMouseAbsolutePointerDevice
->State
.ActiveButtons
= *(UINT8
*) Data
& (BIT0
| BIT1
| BIT2
);
836 UsbMouseAbsolutePointerDevice
->State
.CurrentX
=
838 MAX ((INT64
) UsbMouseAbsolutePointerDevice
->State
.CurrentX
+ *((INT8
*) Data
+ 1),
839 (INT64
) UsbMouseAbsolutePointerDevice
->Mode
.AbsoluteMinX
),
840 (INT64
) UsbMouseAbsolutePointerDevice
->Mode
.AbsoluteMaxX
842 UsbMouseAbsolutePointerDevice
->State
.CurrentY
=
844 MAX ((INT64
) UsbMouseAbsolutePointerDevice
->State
.CurrentY
+ *((INT8
*) Data
+ 2),
845 (INT64
) UsbMouseAbsolutePointerDevice
->Mode
.AbsoluteMinY
),
846 (INT64
) UsbMouseAbsolutePointerDevice
->Mode
.AbsoluteMaxY
848 if (DataLength
> 3) {
849 UsbMouseAbsolutePointerDevice
->State
.CurrentZ
=
851 MAX ((INT64
) UsbMouseAbsolutePointerDevice
->State
.CurrentZ
+ *((INT8
*) Data
+ 1),
852 (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
;
910 Resets the pointer device hardware.
912 @param This A pointer to the EFI_ABSOLUTE_POINTER_PROTOCOL instance.
913 @param ExtendedVerification Indicates that the driver may perform a more exhaustive
914 verification operation of the device during reset.
916 @retval EFI_SUCCESS The device was reset.
917 @retval EFI_DEVICE_ERROR The device is not functioning correctly and could not be reset.
922 UsbMouseAbsolutePointerReset (
923 IN EFI_ABSOLUTE_POINTER_PROTOCOL
*This
,
924 IN BOOLEAN ExtendedVerification
927 USB_MOUSE_ABSOLUTE_POINTER_DEV
*UsbMouseAbsolutePointerDevice
;
929 UsbMouseAbsolutePointerDevice
= USB_MOUSE_ABSOLUTE_POINTER_DEV_FROM_MOUSE_PROTOCOL (This
);
931 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
933 (EFI_PERIPHERAL_MOUSE
| EFI_P_PC_RESET
),
934 UsbMouseAbsolutePointerDevice
->DevicePath
938 // Clear mouse state.
941 &UsbMouseAbsolutePointerDevice
->State
,
942 sizeof (EFI_ABSOLUTE_POINTER_STATE
)
946 // Let the cursor's starting position is in the center of the screen.
948 UsbMouseAbsolutePointerDevice
->State
.CurrentX
=
949 DivU64x32 (UsbMouseAbsolutePointerDevice
->Mode
.AbsoluteMaxX
+ UsbMouseAbsolutePointerDevice
->Mode
.AbsoluteMinX
, 2);
950 UsbMouseAbsolutePointerDevice
->State
.CurrentY
=
951 DivU64x32 (UsbMouseAbsolutePointerDevice
->Mode
.AbsoluteMaxY
+ UsbMouseAbsolutePointerDevice
->Mode
.AbsoluteMinY
, 2);
953 UsbMouseAbsolutePointerDevice
->StateChanged
= FALSE
;
959 Event notification function for EFI_ABSOLUTE_POINTER_PROTOCOL.WaitForInput event.
961 @param Event Event to be signaled when there's input from mouse.
962 @param Context Points to USB_MOUSE_ABSOLUTE_POINTER_DEV instance.
967 UsbMouseAbsolutePointerWaitForInput (
972 USB_MOUSE_ABSOLUTE_POINTER_DEV
*UsbMouseAbsolutePointerDev
;
974 UsbMouseAbsolutePointerDev
= (USB_MOUSE_ABSOLUTE_POINTER_DEV
*) Context
;
977 // If there's input from mouse, signal the event.
979 if (UsbMouseAbsolutePointerDev
->StateChanged
) {
980 gBS
->SignalEvent (Event
);
985 Handler for Delayed Recovery event.
987 This function is the handler for Delayed Recovery event triggered
989 After a device error occurs, the event would be triggered
990 with interval of EFI_USB_INTERRUPT_DELAY. EFI_USB_INTERRUPT_DELAY
991 is defined in USB standard for error handling.
993 @param Event The Delayed Recovery event.
994 @param Context Points to the USB_MOUSE_ABSOLUTE_POINTER_DEV instance.
999 USBMouseRecoveryHandler (
1004 USB_MOUSE_ABSOLUTE_POINTER_DEV
*UsbMouseAbsolutePointerDev
;
1005 EFI_USB_IO_PROTOCOL
*UsbIo
;
1007 UsbMouseAbsolutePointerDev
= (USB_MOUSE_ABSOLUTE_POINTER_DEV
*) Context
;
1009 UsbIo
= UsbMouseAbsolutePointerDev
->UsbIo
;
1012 // Re-submit Asynchronous Interrupt Transfer for recovery.
1014 UsbIo
->UsbAsyncInterruptTransfer (
1016 UsbMouseAbsolutePointerDev
->IntEndpointDescriptor
.EndpointAddress
,
1018 UsbMouseAbsolutePointerDev
->IntEndpointDescriptor
.Interval
,
1019 UsbMouseAbsolutePointerDev
->IntEndpointDescriptor
.MaxPacketSize
,
1020 OnMouseInterruptComplete
,
1021 UsbMouseAbsolutePointerDev