]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Usb/UsbMouseAbsolutePointerDxe/UsbMouseAbsolutePointer.c
MdeModulePkg/UsbMouse: Fix few typos
[mirror_edk2.git] / MdeModulePkg / Bus / Usb / UsbMouseAbsolutePointerDxe / UsbMouseAbsolutePointer.c
index bf3d853807e1ad6f05b57584d2159925356c0b2a..926e03f9cb920617637c9f874e0427052b13ba00 100644 (file)
@@ -1,14 +1,8 @@
 /** @file\r
   USB Mouse Driver that manages USB mouse and produces Absolute Pointer Protocol.\r
 \r
-Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution.  The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -91,7 +85,7 @@ USBMouseAbsolutePointerDriverBindingSupported (
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
-  \r
+\r
   //\r
   // Use the USB I/O Protocol interface to check whether Controller is\r
   // a mouse device that can be managed by this driver.\r
@@ -100,14 +94,14 @@ USBMouseAbsolutePointerDriverBindingSupported (
   if (!IsUsbMouse (UsbIo)) {\r
     Status = EFI_UNSUPPORTED;\r
   }\r
-  \r
+\r
   gBS->CloseProtocol (\r
         Controller,\r
         &gEfiUsbIoProtocolGuid,\r
         This->DriverBindingHandle,\r
         Controller\r
         );\r
-        \r
+\r
   return Status;\r
 }\r
 \r
@@ -115,7 +109,7 @@ USBMouseAbsolutePointerDriverBindingSupported (
 /**\r
   Starts the mouse device with this driver.\r
 \r
-  This function consumes USB I/O Portocol, intializes USB mouse device,\r
+  This function consumes USB I/O Protocol, initializes USB mouse device,\r
   installs Absolute Pointer Protocol, and submits Asynchronous Interrupt\r
   Transfer to manage the USB mouse device.\r
 \r
@@ -161,12 +155,12 @@ USBMouseAbsolutePointerDriverBindingStart (
                   (VOID **) &UsbIo,\r
                   This->DriverBindingHandle,\r
                   Controller,\r
-                  EFI_OPEN_PROTOCOL_BY_DRIVER                  \r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
                   );\r
   if (EFI_ERROR (Status)) {\r
     goto ErrorExit1;\r
   }\r
-  \r
+\r
   UsbMouseAbsolutePointerDevice = AllocateZeroPool (sizeof (USB_MOUSE_ABSOLUTE_POINTER_DEV));\r
   ASSERT (UsbMouseAbsolutePointerDevice != NULL);\r
 \r
@@ -209,7 +203,7 @@ USBMouseAbsolutePointerDriverBindingStart (
   EndpointNumber = UsbMouseAbsolutePointerDevice->InterfaceDescriptor.NumEndpoints;\r
 \r
   //\r
-  // Traverse endpoints to find interrupt endpoint\r
+  // Traverse endpoints to find interrupt endpoint IN\r
   //\r
   Found = FALSE;\r
   for (Index = 0; Index < EndpointNumber; Index++) {\r
@@ -219,7 +213,8 @@ USBMouseAbsolutePointerDriverBindingStart (
              &EndpointDescriptor\r
              );\r
 \r
-    if ((EndpointDescriptor.Attributes & (BIT0 | BIT1)) == USB_ENDPOINT_INTERRUPT) {\r
+    if (((EndpointDescriptor.Attributes & (BIT0 | BIT1)) == USB_ENDPOINT_INTERRUPT) &&\r
+        ((EndpointDescriptor.EndpointAddress & USB_ENDPOINT_DIR_IN) != 0)) {\r
       //\r
       // We only care interrupt endpoint here\r
       //\r
@@ -271,8 +266,8 @@ USBMouseAbsolutePointerDriverBindingStart (
   // Initialize and install EFI Absolute Pointer Protocol.\r
   //\r
   UsbMouseAbsolutePointerDevice->AbsolutePointerProtocol.GetState = GetMouseAbsolutePointerState;\r
-  UsbMouseAbsolutePointerDevice->AbsolutePointerProtocol.Reset   = UsbMouseAbsolutePointerReset;\r
-  UsbMouseAbsolutePointerDevice->AbsolutePointerProtocol.Mode    = &UsbMouseAbsolutePointerDevice->Mode;\r
+  UsbMouseAbsolutePointerDevice->AbsolutePointerProtocol.Reset    = UsbMouseAbsolutePointerReset;\r
+  UsbMouseAbsolutePointerDevice->AbsolutePointerProtocol.Mode    = &UsbMouseAbsolutePointerDevice->Mode;\r
 \r
   Status = gBS->CreateEvent (\r
                   EVT_NOTIFY_WAIT,\r
@@ -470,7 +465,7 @@ USBMouseAbsolutePointerDriverBindingStop (
   // Free all resources.\r
   //\r
   gBS->CloseEvent (UsbMouseAbsolutePointerDevice->AbsolutePointerProtocol.WaitForInput);\r
-  \r
+\r
   if (UsbMouseAbsolutePointerDevice->DelayedRecoveryEvent != NULL) {\r
     gBS->CloseEvent (UsbMouseAbsolutePointerDevice->DelayedRecoveryEvent);\r
     UsbMouseAbsolutePointerDevice->DelayedRecoveryEvent = NULL;\r
@@ -596,7 +591,7 @@ InitializeUsbMouseDevice (
 \r
   Total = 0;\r
   Start = FALSE;\r
-  Head  = (USB_DESC_HEAD *)Buf;  \r
+  Head  = (USB_DESC_HEAD *)Buf;\r
   MouseHidDesc = NULL;\r
 \r
   //\r
@@ -678,9 +673,9 @@ InitializeUsbMouseDevice (
   // Let the cursor's starting position is in the center of the screen.\r
   //\r
   UsbMouseAbsolutePointerDev->State.CurrentX =\r
-    (UsbMouseAbsolutePointerDev->Mode.AbsoluteMaxX + UsbMouseAbsolutePointerDev->Mode.AbsoluteMinX) / 2;\r
+    DivU64x32 (UsbMouseAbsolutePointerDev->Mode.AbsoluteMaxX + UsbMouseAbsolutePointerDev->Mode.AbsoluteMinX, 2);\r
   UsbMouseAbsolutePointerDev->State.CurrentY =\r
-    (UsbMouseAbsolutePointerDev->Mode.AbsoluteMaxY + UsbMouseAbsolutePointerDev->Mode.AbsoluteMinY) / 2;\r
+    DivU64x32 (UsbMouseAbsolutePointerDev->Mode.AbsoluteMaxY + UsbMouseAbsolutePointerDev->Mode.AbsoluteMinY, 2);\r
 \r
   //\r
   // Set boot protocol for the USB mouse.\r
@@ -784,7 +779,7 @@ OnMouseInterruptComplete (
 \r
     //\r
     // Delete & Submit this interrupt again\r
-    // Handler of DelayedRecoveryEvent triggered by timer will re-submit the interrupt. \r
+    // Handler of DelayedRecoveryEvent triggered by timer will re-submit the interrupt.\r
     //\r
     UsbIo->UsbAsyncInterruptTransfer (\r
              UsbIo,\r
@@ -813,8 +808,6 @@ OnMouseInterruptComplete (
     return EFI_SUCCESS;\r
   }\r
 \r
-  UsbMouseAbsolutePointerDevice->StateChanged = TRUE;\r
-\r
   //\r
   // Check mouse Data\r
   // USB HID Specification specifies following data format:\r
@@ -827,6 +820,12 @@ OnMouseInterruptComplete (
   // 2       0 to 7  Y displacement\r
   // 3 to n  0 to 7  Device specific (optional)\r
   //\r
+  if (DataLength < 3) {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  UsbMouseAbsolutePointerDevice->StateChanged = TRUE;\r
+\r
   UsbMouseAbsolutePointerDevice->State.ActiveButtons = *(UINT8 *) Data & (BIT0 | BIT1 | BIT2);\r
 \r
   UsbMouseAbsolutePointerDevice->State.CurrentX =\r
@@ -856,15 +855,15 @@ OnMouseInterruptComplete (
 /**\r
   Retrieves the current state of a pointer device.\r
 \r
-  @param  This                  A pointer to the EFI_ABSOLUTE_POINTER_PROTOCOL instance.                                   \r
+  @param  This                  A pointer to the EFI_ABSOLUTE_POINTER_PROTOCOL instance.\r
   @param  MouseState            A pointer to the state information on the pointer device.\r
 \r
   @retval EFI_SUCCESS           The state of the pointer device was returned in State.\r
   @retval EFI_NOT_READY         The state of the pointer device has not changed since the last call to\r
-                                GetState().                                                           \r
+                                GetState().\r
   @retval EFI_DEVICE_ERROR      A device error occurred while attempting to retrieve the pointer device's\r
-                                current state.                                                           \r
-  @retval EFI_INVALID_PARAMETER State is NULL.                                                           \r
+                                current state.\r
+  @retval EFI_INVALID_PARAMETER State is NULL.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -942,9 +941,9 @@ UsbMouseAbsolutePointerReset (
   // Let the cursor's starting position is in the center of the screen.\r
   //\r
   UsbMouseAbsolutePointerDevice->State.CurrentX =\r
-    (UsbMouseAbsolutePointerDevice->Mode.AbsoluteMaxX + UsbMouseAbsolutePointerDevice->Mode.AbsoluteMinX) / 2;\r
+    DivU64x32 (UsbMouseAbsolutePointerDevice->Mode.AbsoluteMaxX + UsbMouseAbsolutePointerDevice->Mode.AbsoluteMinX, 2);\r
   UsbMouseAbsolutePointerDevice->State.CurrentY =\r
-    (UsbMouseAbsolutePointerDevice->Mode.AbsoluteMaxY + UsbMouseAbsolutePointerDevice->Mode.AbsoluteMinY) / 2;\r
+    DivU64x32 (UsbMouseAbsolutePointerDevice->Mode.AbsoluteMaxY + UsbMouseAbsolutePointerDevice->Mode.AbsoluteMinY, 2);\r
 \r
   UsbMouseAbsolutePointerDevice->StateChanged = FALSE;\r
 \r