]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Usb/UsbMouseDxe/UsbMouse.c
MdeModulePkg/UsbMouse: Fix few typos
[mirror_edk2.git] / MdeModulePkg / Bus / Usb / UsbMouseDxe / UsbMouse.c
index 378bbec7ed4d4940ab0db62da32233e41874c55c..9861c32d4971a9c38471337948b571aa731801cd 100644 (file)
@@ -1,72 +1,13 @@
 /** @file\r
+  USB Mouse Driver that manages USB mouse and produces Simple Pointer Protocol.\r
 \r
-Copyright (c) 2004 - 2007, Intel Corporation\r
-All rights reserved. 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
-\r
-  Module Name:\r
-\r
-    UsbMouse.c\r
-\r
-  Abstract:\r
-\r
+Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
 #include "UsbMouse.h"\r
 \r
-#include <Library/DebugLib.h>\r
-#include <IndustryStandard/Usb.h>\r
-\r
-\r
-#include "UsbMouse.h"\r
-#include "MouseHid.h"\r
-\r
-//\r
-// Prototypes\r
-// Driver model protocol interface\r
-//\r
-EFI_STATUS\r
-EFIAPI\r
-USBMouseDriverBindingEntryPoint (\r
-  IN EFI_HANDLE           ImageHandle,\r
-  IN EFI_SYSTEM_TABLE     *SystemTable\r
-  );\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-USBMouseDriverBindingSupported (\r
-  IN EFI_DRIVER_BINDING_PROTOCOL    *This,\r
-  IN EFI_HANDLE                     Controller,\r
-  IN EFI_DEVICE_PATH_PROTOCOL       *RemainingDevicePath\r
-  );\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-USBMouseDriverBindingStart (\r
-  IN EFI_DRIVER_BINDING_PROTOCOL    *This,\r
-  IN EFI_HANDLE                     Controller,\r
-  IN EFI_DEVICE_PATH_PROTOCOL       *RemainingDevicePath\r
-  );\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-USBMouseDriverBindingStop (\r
-  IN  EFI_DRIVER_BINDING_PROTOCOL   *This,\r
-  IN  EFI_HANDLE                    Controller,\r
-  IN  UINTN                         NumberOfChildren,\r
-  IN  EFI_HANDLE                    *ChildHandleBuffer\r
-  );\r
-\r
-EFI_GUID  gEfiUsbMouseDriverGuid = {\r
-  0x290156b5, 0x6a05, 0x4ac0, {0xb8, 0x0, 0x51, 0x27, 0x55, 0xad, 0x14, 0x29}\r
-};\r
-\r
 EFI_DRIVER_BINDING_PROTOCOL gUsbMouseDriverBinding = {\r
   USBMouseDriverBindingSupported,\r
   USBMouseDriverBindingStart,\r
@@ -76,105 +17,50 @@ EFI_DRIVER_BINDING_PROTOCOL gUsbMouseDriverBinding = {
   NULL\r
 };\r
 \r
-//\r
-// helper functions\r
-//\r
-STATIC\r
-BOOLEAN\r
-IsUsbMouse (\r
-  IN  EFI_USB_IO_PROTOCOL     *UsbIo\r
-  );\r
+/**\r
+  Entrypoint of USB Mouse Driver.\r
 \r
-STATIC\r
-EFI_STATUS\r
-InitializeUsbMouseDevice (\r
-  IN  USB_MOUSE_DEV           *UsbMouseDev\r
-  );\r
+  This function is the entrypoint of USB Mouse Driver. It installs Driver Binding\r
+  Protocols together with Component Name Protocols.\r
 \r
-STATIC\r
-VOID\r
-EFIAPI\r
-UsbMouseWaitForInput (\r
-  IN  EFI_EVENT               Event,\r
-  IN  VOID                    *Context\r
-  );\r
+  @param  ImageHandle       The firmware allocated handle for the EFI image.\r
+  @param  SystemTable       A pointer to the EFI System Table.\r
 \r
-//\r
-// Mouse interrupt handler\r
-//\r
-STATIC\r
-EFI_STATUS\r
-EFIAPI\r
-OnMouseInterruptComplete (\r
-  IN  VOID        *Data,\r
-  IN  UINTN       DataLength,\r
-  IN  VOID        *Context,\r
-  IN  UINT32      Result\r
-  );\r
-\r
-//\r
-// Mouse Protocol\r
-//\r
-STATIC\r
-EFI_STATUS\r
-EFIAPI\r
-GetMouseState (\r
-  IN   EFI_SIMPLE_POINTER_PROTOCOL  *This,\r
-  OUT  EFI_SIMPLE_POINTER_STATE     *MouseState\r
-  );\r
+  @retval EFI_SUCCESS       The entry point is executed successfully.\r
 \r
-STATIC\r
-EFI_STATUS\r
-EFIAPI\r
-UsbMouseReset (\r
-  IN EFI_SIMPLE_POINTER_PROTOCOL    *This,\r
-  IN BOOLEAN                        ExtendedVerification\r
-  );\r
-\r
-//\r
-// Driver start here\r
-//\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 USBMouseDriverBindingEntryPoint (\r
   IN EFI_HANDLE           ImageHandle,\r
   IN EFI_SYSTEM_TABLE     *SystemTable\r
   )\r
-/*++\r
-\r
-  Routine Description:\r
-    Entry point for EFI drivers.\r
+{\r
+  EFI_STATUS              Status;\r
 \r
-  Arguments:\r
-   ImageHandle - EFI_HANDLE\r
-   SystemTable - EFI_SYSTEM_TABLE\r
-  Returns:\r
-    EFI_SUCCESS\r
-    others\r
+  Status = EfiLibInstallDriverBindingComponentName2 (\r
+             ImageHandle,\r
+             SystemTable,\r
+             &gUsbMouseDriverBinding,\r
+             ImageHandle,\r
+             &gUsbMouseComponentName,\r
+             &gUsbMouseComponentName2\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
 \r
---*/\r
-{\r
-  return EfiLibInstallDriverBindingComponentName2 (\r
-           ImageHandle,\r
-           SystemTable,\r
-           &gUsbMouseDriverBinding,\r
-           ImageHandle,\r
-           &gUsbMouseComponentName,\r
-           &gUsbMouseComponentName2\r
-           );\r
+  return EFI_SUCCESS;\r
 }\r
 \r
 \r
 /**\r
-  Test to see if this driver supports ControllerHandle. Any ControllerHandle\r
-  that has UsbHcProtocol installed will be supported.\r
+  Check whether USB mouse driver supports this device.\r
 \r
-  @param  This                  Protocol instance pointer.\r
-  @param  Controller            Handle of device to test\r
-  @param  RemainingDevicePath   Not used\r
+  @param  This                   The USB mouse driver binding protocol.\r
+  @param  Controller             The controller handle to check.\r
+  @param  RemainingDevicePath    The remaining device path.\r
 \r
-  @retval EFI_SUCCESS           This driver supports this device.\r
-  @retval EFI_UNSUPPORTED       This driver does not support this device.\r
+  @retval EFI_SUCCESS            The driver supports this controller.\r
+  @retval other                  This device isn't supported.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -185,29 +71,24 @@ USBMouseDriverBindingSupported (
   IN EFI_DEVICE_PATH_PROTOCOL       *RemainingDevicePath\r
   )\r
 {\r
-  EFI_STATUS          OpenStatus;\r
-  EFI_USB_IO_PROTOCOL *UsbIo;\r
   EFI_STATUS          Status;\r
+  EFI_USB_IO_PROTOCOL *UsbIo;\r
 \r
-  OpenStatus = gBS->OpenProtocol (\r
-                      Controller,\r
-                      &gEfiUsbIoProtocolGuid,\r
-                      (VOID **) &UsbIo,\r
-                      This->DriverBindingHandle,\r
-                      Controller,\r
-                      EFI_OPEN_PROTOCOL_BY_DRIVER\r
-                      );\r
-  if (EFI_ERROR (OpenStatus) && (OpenStatus != EFI_ALREADY_STARTED)) {\r
-    return EFI_UNSUPPORTED;\r
-  }\r
-\r
-  if (OpenStatus == EFI_ALREADY_STARTED) {\r
-    return EFI_ALREADY_STARTED;\r
+  Status = gBS->OpenProtocol (\r
+                  Controller,\r
+                  &gEfiUsbIoProtocolGuid,\r
+                  (VOID **) &UsbIo,\r
+                  This->DriverBindingHandle,\r
+                  Controller,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
   }\r
 \r
   //\r
-  // Use the USB I/O protocol interface to see the Controller is\r
-  // the Mouse controller that can be managed by this driver.\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
   //\r
   Status = EFI_SUCCESS;\r
   if (!IsUsbMouse (UsbIo)) {\r
@@ -220,23 +101,28 @@ USBMouseDriverBindingSupported (
         This->DriverBindingHandle,\r
         Controller\r
         );\r
+\r
   return Status;\r
 }\r
 \r
 \r
 /**\r
-  Starting the Usb Bus Driver\r
+  Starts the mouse device with this driver.\r
 \r
-  @param  This                  Protocol instance pointer.\r
-  @param  Controller            Handle of device to test\r
-  @param  RemainingDevicePath   Not used\r
+  This function consumes USB I/O Protocol, initializes USB mouse device,\r
+  installs Simple Pointer Protocol, and submits Asynchronous Interrupt\r
+  Transfer to manage the USB mouse device.\r
+\r
+  @param  This                  The USB mouse driver binding instance.\r
+  @param  Controller            Handle of device to bind driver to.\r
+  @param  RemainingDevicePath   Optional parameter use to pick a specific child\r
+                                device to start.\r
 \r
   @retval EFI_SUCCESS           This driver supports this device.\r
   @retval EFI_UNSUPPORTED       This driver does not support this device.\r
-  @retval EFI_DEVICE_ERROR      This driver cannot be started due to device Error\r
-                                EFI_OUT_OF_RESOURCES- Can't allocate memory\r
-                                resources\r
-  @retval EFI_ALREADY_STARTED   Thios driver has been started\r
+  @retval EFI_DEVICE_ERROR      This driver cannot be started due to device Error.\r
+  @retval EFI_OUT_OF_RESOURCES  Can't allocate memory resources.\r
+  @retval EFI_ALREADY_STARTED   This driver has been started.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -249,17 +135,20 @@ USBMouseDriverBindingStart (
 {\r
   EFI_STATUS                  Status;\r
   EFI_USB_IO_PROTOCOL         *UsbIo;\r
-  EFI_USB_ENDPOINT_DESCRIPTOR *EndpointDesc;\r
   USB_MOUSE_DEV               *UsbMouseDevice;\r
   UINT8                       EndpointNumber;\r
+  EFI_USB_ENDPOINT_DESCRIPTOR EndpointDescriptor;\r
   UINT8                       Index;\r
   UINT8                       EndpointAddr;\r
   UINT8                       PollingInterval;\r
   UINT8                       PacketSize;\r
+  BOOLEAN                     Found;\r
+  EFI_TPL                     OldTpl;\r
 \r
-  UsbMouseDevice  = NULL;\r
-  Status          = EFI_SUCCESS;\r
-\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+  //\r
+  // Open USB I/O Protocol\r
+  //\r
   Status = gBS->OpenProtocol (\r
                   Controller,\r
                   &gEfiUsbIoProtocolGuid,\r
@@ -269,30 +158,15 @@ USBMouseDriverBindingStart (
                   EFI_OPEN_PROTOCOL_BY_DRIVER\r
                   );\r
   if (EFI_ERROR (Status)) {\r
-    goto ErrorExit;\r
+    goto ErrorExit1;\r
   }\r
 \r
   UsbMouseDevice = AllocateZeroPool (sizeof (USB_MOUSE_DEV));\r
-  if (UsbMouseDevice == NULL) {\r
-    Status = EFI_OUT_OF_RESOURCES;\r
-    goto ErrorExit;\r
-  }\r
+  ASSERT (UsbMouseDevice != NULL);\r
 \r
-  UsbMouseDevice->UsbIo               = UsbIo;\r
-\r
-  UsbMouseDevice->Signature           = USB_MOUSE_DEV_SIGNATURE;\r
-\r
-  UsbMouseDevice->InterfaceDescriptor = AllocatePool (sizeof (EFI_USB_INTERFACE_DESCRIPTOR));\r
-  if (UsbMouseDevice->InterfaceDescriptor == NULL) {\r
-    Status = EFI_OUT_OF_RESOURCES;\r
-    goto ErrorExit;\r
-  }\r
+  UsbMouseDevice->UsbIo     = UsbIo;\r
+  UsbMouseDevice->Signature = USB_MOUSE_DEV_SIGNATURE;\r
 \r
-  EndpointDesc = AllocatePool (sizeof (EFI_USB_ENDPOINT_DESCRIPTOR));\r
-  if (EndpointDesc == NULL) {\r
-    Status = EFI_OUT_OF_RESOURCES;\r
-    goto ErrorExit;\r
-  }\r
   //\r
   // Get the Device Path Protocol on Controller's handle\r
   //\r
@@ -308,51 +182,89 @@ USBMouseDriverBindingStart (
   if (EFI_ERROR (Status)) {\r
     goto ErrorExit;\r
   }\r
+\r
+  //\r
+  // Report Status Code here since USB mouse will be detected next.\r
+  //\r
+  REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
+    EFI_PROGRESS_CODE,\r
+    (EFI_PERIPHERAL_MOUSE | EFI_P_PC_PRESENCE_DETECT),\r
+    UsbMouseDevice->DevicePath\r
+    );\r
+\r
   //\r
   // Get interface & endpoint descriptor\r
   //\r
   UsbIo->UsbGetInterfaceDescriptor (\r
-          UsbIo,\r
-          UsbMouseDevice->InterfaceDescriptor\r
-          );\r
+           UsbIo,\r
+           &UsbMouseDevice->InterfaceDescriptor\r
+           );\r
 \r
-  EndpointNumber = UsbMouseDevice->InterfaceDescriptor->NumEndpoints;\r
+  EndpointNumber = UsbMouseDevice->InterfaceDescriptor.NumEndpoints;\r
 \r
+  //\r
+  // Traverse endpoints to find interrupt endpoint IN\r
+  //\r
+  Found = FALSE;\r
   for (Index = 0; Index < EndpointNumber; Index++) {\r
     UsbIo->UsbGetEndpointDescriptor (\r
-            UsbIo,\r
-            Index,\r
-            EndpointDesc\r
-            );\r
-\r
-    if ((EndpointDesc->Attributes & 0x03) == 0x03) {\r
+             UsbIo,\r
+             Index,\r
+             &EndpointDescriptor\r
+             );\r
 \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
-      UsbMouseDevice->IntEndpointDescriptor = EndpointDesc;\r
+      CopyMem(&UsbMouseDevice->IntEndpointDescriptor, &EndpointDescriptor, sizeof(EndpointDescriptor));\r
+      Found = TRUE;\r
+      break;\r
     }\r
   }\r
 \r
-  if (UsbMouseDevice->IntEndpointDescriptor == NULL) {\r
+  if (!Found) {\r
+    //\r
+    // Report Status Code to indicate that there is no USB mouse\r
+    //\r
+    REPORT_STATUS_CODE (\r
+      EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
+      (EFI_PERIPHERAL_MOUSE | EFI_P_EC_NOT_DETECTED)\r
+      );\r
     //\r
-    // No interrupt endpoint, then error\r
+    // No interrupt endpoint found, then return unsupported.\r
     //\r
     Status = EFI_UNSUPPORTED;\r
     goto ErrorExit;\r
   }\r
 \r
+  //\r
+  // Report Status Code here since USB mouse has be detected.\r
+  //\r
+  REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
+    EFI_PROGRESS_CODE,\r
+    (EFI_PERIPHERAL_MOUSE | EFI_P_PC_DETECTED),\r
+    UsbMouseDevice->DevicePath\r
+    );\r
+\r
   Status = InitializeUsbMouseDevice (UsbMouseDevice);\r
   if (EFI_ERROR (Status)) {\r
-    MouseReportStatusCode (\r
-      UsbMouseDevice->DevicePath,\r
+    //\r
+    // Fail to initialize USB mouse device.\r
+    //\r
+    REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
       EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
-      PcdGet32 (PcdStatusCodeValueMouseInterfaceError)\r
+      (EFI_PERIPHERAL_MOUSE | EFI_P_EC_INTERFACE_ERROR),\r
+      UsbMouseDevice->DevicePath\r
       );\r
 \r
     goto ErrorExit;\r
   }\r
 \r
+  //\r
+  // Initialize and install EFI Simple Pointer Protocol.\r
+  //\r
   UsbMouseDevice->SimplePointerProtocol.GetState  = GetMouseState;\r
   UsbMouseDevice->SimplePointerProtocol.Reset     = UsbMouseReset;\r
   UsbMouseDevice->SimplePointerProtocol.Mode      = &UsbMouseDevice->Mode;\r
@@ -376,28 +288,26 @@ USBMouseDriverBindingStart (
                   );\r
 \r
   if (EFI_ERROR (Status)) {\r
-    Status = EFI_DEVICE_ERROR;\r
     goto ErrorExit;\r
   }\r
 \r
   //\r
-  // After Enabling Async Interrupt Transfer on this mouse Device\r
-  // we will be able to get key data from it. Thus this is deemed as\r
-  // the enable action of the mouse\r
+  // The next step would be submitting Asynchronous Interrupt Transfer on this mouse device.\r
+  // After that we will be able to get key data from it. Thus this is deemed as\r
+  // the enable action of the mouse, so report status code accordingly.\r
   //\r
-\r
-  MouseReportStatusCode (\r
-    UsbMouseDevice->DevicePath,\r
+  REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
     EFI_PROGRESS_CODE,\r
-    PcdGet32 (PcdStatusCodeValueMouseEnable)\r
+    (EFI_PERIPHERAL_MOUSE | EFI_P_PC_ENABLE),\r
+    UsbMouseDevice->DevicePath\r
     );\r
 \r
   //\r
-  // submit async interrupt transfer\r
+  // Submit Asynchronous Interrupt Transfer to manage this device.\r
   //\r
-  EndpointAddr    = UsbMouseDevice->IntEndpointDescriptor->EndpointAddress;\r
-  PollingInterval = UsbMouseDevice->IntEndpointDescriptor->Interval;\r
-  PacketSize      = (UINT8) (UsbMouseDevice->IntEndpointDescriptor->MaxPacketSize);\r
+  EndpointAddr    = UsbMouseDevice->IntEndpointDescriptor.EndpointAddress;\r
+  PollingInterval = UsbMouseDevice->IntEndpointDescriptor.Interval;\r
+  PacketSize      = (UINT8) (UsbMouseDevice->IntEndpointDescriptor.MaxPacketSize);\r
 \r
   Status = UsbIo->UsbAsyncInterruptTransfer (\r
                     UsbIo,\r
@@ -409,38 +319,41 @@ USBMouseDriverBindingStart (
                     UsbMouseDevice\r
                     );\r
 \r
-  if (!EFI_ERROR (Status)) {\r
-\r
-    UsbMouseDevice->ControllerNameTable = NULL;\r
-    AddUnicodeString2 (\r
-      "eng",\r
-      gUsbMouseComponentName.SupportedLanguages,\r
-      &UsbMouseDevice->ControllerNameTable,\r
-      L"Generic Usb Mouse",\r
-      TRUE\r
-      );\r
-    AddUnicodeString2 (\r
-      "en",\r
-      gUsbMouseComponentName2.SupportedLanguages,\r
-      &UsbMouseDevice->ControllerNameTable,\r
-      L"Generic Usb Mouse",\r
-      FALSE\r
-      );\r
+  if (EFI_ERROR (Status)) {\r
+    //\r
+    // If submit error, uninstall that interface\r
+    //\r
+    gBS->UninstallProtocolInterface (\r
+           Controller,\r
+           &gEfiSimplePointerProtocolGuid,\r
+           &UsbMouseDevice->SimplePointerProtocol\r
+           );\r
+    goto ErrorExit;\r
+  }\r
 \r
+  UsbMouseDevice->ControllerNameTable = NULL;\r
+  AddUnicodeString2 (\r
+    "eng",\r
+    gUsbMouseComponentName.SupportedLanguages,\r
+    &UsbMouseDevice->ControllerNameTable,\r
+    L"Generic Usb Mouse",\r
+    TRUE\r
+    );\r
+  AddUnicodeString2 (\r
+    "en",\r
+    gUsbMouseComponentName2.SupportedLanguages,\r
+    &UsbMouseDevice->ControllerNameTable,\r
+    L"Generic Usb Mouse",\r
+    FALSE\r
+    );\r
 \r
-    return EFI_SUCCESS;\r
-  }\r
+  gBS->RestoreTPL (OldTpl);\r
 \r
-  //\r
-  // If submit error, uninstall that interface\r
-  //\r
-  Status = EFI_DEVICE_ERROR;\r
-  gBS->UninstallProtocolInterface (\r
-        Controller,\r
-        &gEfiSimplePointerProtocolGuid,\r
-        &UsbMouseDevice->SimplePointerProtocol\r
-        );\r
+  return EFI_SUCCESS;\r
 \r
+//\r
+// Error handler\r
+//\r
 ErrorExit:\r
   if (EFI_ERROR (Status)) {\r
     gBS->CloseProtocol (\r
@@ -451,39 +364,32 @@ ErrorExit:
           );\r
 \r
     if (UsbMouseDevice != NULL) {\r
-      if (UsbMouseDevice->InterfaceDescriptor != NULL) {\r
-        gBS->FreePool (UsbMouseDevice->InterfaceDescriptor);\r
-      }\r
-\r
-      if (UsbMouseDevice->IntEndpointDescriptor != NULL) {\r
-        gBS->FreePool (UsbMouseDevice->IntEndpointDescriptor);\r
-      }\r
-\r
       if ((UsbMouseDevice->SimplePointerProtocol).WaitForInput != NULL) {\r
         gBS->CloseEvent ((UsbMouseDevice->SimplePointerProtocol).WaitForInput);\r
       }\r
 \r
-      gBS->FreePool (UsbMouseDevice);\r
+      FreePool (UsbMouseDevice);\r
       UsbMouseDevice = NULL;\r
     }\r
   }\r
 \r
+ErrorExit1:\r
+  gBS->RestoreTPL (OldTpl);\r
   return Status;\r
 }\r
 \r
 \r
 /**\r
-  Stop this driver on ControllerHandle. Support stoping any child handles\r
-  created by this driver.\r
+  Stop the USB mouse device handled by this driver.\r
 \r
-  @param  This                  Protocol instance pointer.\r
-  @param  Controller            Handle of device to stop driver on\r
-  @param  NumberOfChildren      Number of Children in the ChildHandleBuffer\r
-  @param  ChildHandleBuffer     List of handles for the children we need to stop.\r
+  @param  This                   The USB mouse driver binding protocol.\r
+  @param  Controller             The controller to release.\r
+  @param  NumberOfChildren       The number of handles in ChildHandleBuffer.\r
+  @param  ChildHandleBuffer      The array of child handle.\r
 \r
-  @return EFI_SUCCESS\r
-  @return EFI_DEVICE_ERROR\r
-  @return others\r
+  @retval EFI_SUCCESS            The device was stopped.\r
+  @retval EFI_UNSUPPORTED        Simple Pointer Protocol is not installed on Controller.\r
+  @retval Others                 Fail to uninstall protocols attached on the device.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -500,9 +406,6 @@ USBMouseDriverBindingStop (
   EFI_SIMPLE_POINTER_PROTOCOL *SimplePointerProtocol;\r
   EFI_USB_IO_PROTOCOL         *UsbIo;\r
 \r
-  //\r
-  // Get our context back.\r
-  //\r
   Status = gBS->OpenProtocol (\r
                   Controller,\r
                   &gEfiSimplePointerProtocolGuid,\r
@@ -518,44 +421,29 @@ USBMouseDriverBindingStop (
 \r
   UsbMouseDevice = USB_MOUSE_DEV_FROM_MOUSE_PROTOCOL (SimplePointerProtocol);\r
 \r
-  gBS->CloseProtocol (\r
-        Controller,\r
-        &gEfiSimplePointerProtocolGuid,\r
-        This->DriverBindingHandle,\r
-        Controller\r
-        );\r
-\r
   UsbIo = UsbMouseDevice->UsbIo;\r
 \r
   //\r
-  // Uninstall the Asyn Interrupt Transfer from this device\r
-  // will disable the mouse data input from this device\r
+  // The key data input from this device will be disabled.\r
   //\r
-  MouseReportStatusCode (\r
-    UsbMouseDevice->DevicePath,\r
+  REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
     EFI_PROGRESS_CODE,\r
-    PcdGet32 (PcdStatusCodeValueMouseDisable)\r
+    (EFI_PERIPHERAL_MOUSE | EFI_P_PC_DISABLE),\r
+    UsbMouseDevice->DevicePath\r
     );\r
 \r
   //\r
-  // Delete Mouse Async Interrupt Transfer\r
+  // Delete the Asynchronous Interrupt Transfer from this device\r
   //\r
   UsbIo->UsbAsyncInterruptTransfer (\r
-          UsbIo,\r
-          UsbMouseDevice->IntEndpointDescriptor->EndpointAddress,\r
-          FALSE,\r
-          UsbMouseDevice->IntEndpointDescriptor->Interval,\r
-          0,\r
-          NULL,\r
-          NULL\r
-          );\r
-\r
-  gBS->CloseEvent (UsbMouseDevice->SimplePointerProtocol.WaitForInput);\r
-\r
-  if (UsbMouseDevice->DelayedRecoveryEvent) {\r
-    gBS->CloseEvent (UsbMouseDevice->DelayedRecoveryEvent);\r
-    UsbMouseDevice->DelayedRecoveryEvent = 0;\r
-  }\r
+           UsbIo,\r
+           UsbMouseDevice->IntEndpointDescriptor.EndpointAddress,\r
+           FALSE,\r
+           UsbMouseDevice->IntEndpointDescriptor.Interval,\r
+           0,\r
+           NULL,\r
+           NULL\r
+           );\r
 \r
   Status = gBS->UninstallProtocolInterface (\r
                   Controller,\r
@@ -567,20 +455,27 @@ USBMouseDriverBindingStop (
   }\r
 \r
   gBS->CloseProtocol (\r
-        Controller,\r
-        &gEfiUsbIoProtocolGuid,\r
-        This->DriverBindingHandle,\r
-        Controller\r
-        );\r
+         Controller,\r
+         &gEfiUsbIoProtocolGuid,\r
+         This->DriverBindingHandle,\r
+         Controller\r
+         );\r
 \r
-  gBS->FreePool (UsbMouseDevice->InterfaceDescriptor);\r
-  gBS->FreePool (UsbMouseDevice->IntEndpointDescriptor);\r
+  //\r
+  // Free all resources.\r
+  //\r
+  gBS->CloseEvent (UsbMouseDevice->SimplePointerProtocol.WaitForInput);\r
 \r
-  if (UsbMouseDevice->ControllerNameTable) {\r
+  if (UsbMouseDevice->DelayedRecoveryEvent != NULL) {\r
+    gBS->CloseEvent (UsbMouseDevice->DelayedRecoveryEvent);\r
+    UsbMouseDevice->DelayedRecoveryEvent = NULL;\r
+  }\r
+\r
+  if (UsbMouseDevice->ControllerNameTable != NULL) {\r
     FreeUnicodeStringTable (UsbMouseDevice->ControllerNameTable);\r
   }\r
 \r
-  gBS->FreePool (UsbMouseDevice);\r
+  FreePool (UsbMouseDevice);\r
 \r
   return EFI_SUCCESS;\r
 \r
@@ -588,12 +483,12 @@ USBMouseDriverBindingStop (
 \r
 \r
 /**\r
-  Tell if a Usb Controller is a mouse\r
+  Uses USB I/O to check whether the device is a USB mouse device.\r
 \r
-  @param  UsbIo                 Protocol instance pointer.\r
+  @param  UsbIo    Pointer to a USB I/O protocol instance.\r
 \r
-  @retval TRUE                  It is a mouse\r
-  @retval FALSE                 It is not a mouse\r
+  @retval TRUE     Device is a USB mouse device.\r
+  @retval FALSE    Device is a not USB mouse device.\r
 \r
 **/\r
 BOOLEAN\r
@@ -605,8 +500,7 @@ IsUsbMouse (
   EFI_USB_INTERFACE_DESCRIPTOR  InterfaceDescriptor;\r
 \r
   //\r
-  // Get the Default interface descriptor, now we only\r
-  // suppose it is interface 1\r
+  // Get the default interface descriptor\r
   //\r
   Status = UsbIo->UsbGetInterfaceDescriptor (\r
                     UsbIo,\r
@@ -629,63 +523,126 @@ IsUsbMouse (
 \r
 \r
 /**\r
-  Initialize the Usb Mouse Device.\r
+  Initialize the USB mouse device.\r
+\r
+  This function retrieves and parses HID report descriptor, and\r
+  initializes state of USB_MOUSE_DEV. Then it sets indefinite idle\r
+  rate for the device. Finally it creates event for delayed recovery,\r
+  which deals with device error.\r
 \r
-  @param  UsbMouseDev           Device instance to be initialized\r
+  @param  UsbMouseDev           Device instance to be initialized.\r
 \r
-  @retval EFI_SUCCESS           Success\r
-  @retval EFI_DEVICE_ERROR      Init error. EFI_OUT_OF_RESOURCES- Can't allocate\r
-                                memory\r
+  @retval EFI_SUCCESS           USB mouse device successfully initialized..\r
+  @retval EFI_UNSUPPORTED       HID descriptor type is not report descriptor.\r
+  @retval Other                 USB mouse device was not initialized successfully.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 InitializeUsbMouseDevice (\r
-  IN  USB_MOUSE_DEV           *UsbMouseDev\r
+  IN OUT USB_MOUSE_DEV           *UsbMouseDev\r
   )\r
 {\r
-  EFI_USB_IO_PROTOCOL     *UsbIo;\r
-  UINT8                   Protocol;\r
-  EFI_STATUS              Status;\r
-  EFI_USB_HID_DESCRIPTOR  MouseHidDesc;\r
-  UINT8                   *ReportDesc;\r
+  EFI_USB_IO_PROTOCOL       *UsbIo;\r
+  UINT8                     Protocol;\r
+  EFI_STATUS                Status;\r
+  EFI_USB_HID_DESCRIPTOR    *MouseHidDesc;\r
+  UINT8                     *ReportDesc;\r
+  EFI_USB_CONFIG_DESCRIPTOR ConfigDesc;\r
+  VOID                      *Buf;\r
+  UINT32                    TransferResult;\r
+  UINT16                    Total;\r
+  USB_DESC_HEAD             *Head;\r
+  BOOLEAN                   Start;\r
 \r
   UsbIo = UsbMouseDev->UsbIo;\r
 \r
   //\r
-  // Get HID descriptor\r
+  // Get the current configuration descriptor. Note that it doesn't include other descriptors.\r
   //\r
-  Status = UsbGetHidDescriptor (\r
-            UsbIo,\r
-            UsbMouseDev->InterfaceDescriptor->InterfaceNumber,\r
-            &MouseHidDesc\r
-            );\r
+  Status = UsbIo->UsbGetConfigDescriptor (\r
+                    UsbIo,\r
+                    &ConfigDesc\r
+                    );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
 \r
+  //\r
+  // By issuing Get_Descriptor(Configuration) request with total length, we get the Configuration descriptor,\r
+  // all Interface descriptors, all Endpoint descriptors, and the HID descriptor for each interface.\r
+  //\r
+  Buf = AllocateZeroPool (ConfigDesc.TotalLength);\r
+  if (Buf == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  Status = UsbGetDescriptor (\r
+             UsbIo,\r
+             (UINT16)((USB_DESC_TYPE_CONFIG << 8) | (ConfigDesc.ConfigurationValue - 1)),\r
+             0,\r
+             ConfigDesc.TotalLength,\r
+             Buf,\r
+             &TransferResult\r
+             );\r
   if (EFI_ERROR (Status)) {\r
+    FreePool (Buf);\r
     return Status;\r
   }\r
 \r
+  Total = 0;\r
+  Start = FALSE;\r
+  Head  = (USB_DESC_HEAD *)Buf;\r
+  MouseHidDesc = NULL;\r
+\r
   //\r
-  // Get Report descriptor\r
+  // Get HID descriptor from the receipt of Get_Descriptor(Configuration) request.\r
+  // This algorithm is based on the fact that the HID descriptor shall be interleaved\r
+  // between the interface and endpoint descriptors for HID interfaces.\r
   //\r
-  if (MouseHidDesc.HidClassDesc[0].DescriptorType != 0x22) {\r
+  while (Total < ConfigDesc.TotalLength) {\r
+    if (Head->Type == USB_DESC_TYPE_INTERFACE) {\r
+      if ((((USB_INTERFACE_DESCRIPTOR *)Head)->InterfaceNumber == UsbMouseDev->InterfaceDescriptor.InterfaceNumber) &&\r
+        (((USB_INTERFACE_DESCRIPTOR *)Head)->AlternateSetting == UsbMouseDev->InterfaceDescriptor.AlternateSetting)) {\r
+        Start = TRUE;\r
+      }\r
+    }\r
+    if (Start && (Head->Type == USB_DESC_TYPE_ENDPOINT)) {\r
+      break;\r
+    }\r
+    if (Start && (Head->Type == USB_DESC_TYPE_HID)) {\r
+      MouseHidDesc = (EFI_USB_HID_DESCRIPTOR *)Head;\r
+      break;\r
+    }\r
+    Total = Total + (UINT16)Head->Len;\r
+    Head  = (USB_DESC_HEAD*)((UINT8 *)Buf + Total);\r
+  }\r
+\r
+  if (MouseHidDesc == NULL) {\r
+    FreePool (Buf);\r
     return EFI_UNSUPPORTED;\r
   }\r
 \r
-  ReportDesc = AllocateZeroPool (MouseHidDesc.HidClassDesc[0].DescriptorLength);\r
-  if (ReportDesc == NULL) {\r
-    return EFI_OUT_OF_RESOURCES;\r
+  //\r
+  // Get report descriptor\r
+  //\r
+  if (MouseHidDesc->HidClassDesc[0].DescriptorType != USB_DESC_TYPE_REPORT) {\r
+    FreePool (Buf);\r
+    return EFI_UNSUPPORTED;\r
   }\r
 \r
+  ReportDesc = AllocateZeroPool (MouseHidDesc->HidClassDesc[0].DescriptorLength);\r
+  ASSERT (ReportDesc != NULL);\r
+\r
   Status = UsbGetReportDescriptor (\r
-            UsbIo,\r
-            UsbMouseDev->InterfaceDescriptor->InterfaceNumber,\r
-            MouseHidDesc.HidClassDesc[0].DescriptorLength,\r
-            ReportDesc\r
-            );\r
+             UsbIo,\r
+             UsbMouseDev->InterfaceDescriptor.InterfaceNumber,\r
+             MouseHidDesc->HidClassDesc[0].DescriptorLength,\r
+             ReportDesc\r
+             );\r
 \r
   if (EFI_ERROR (Status)) {\r
-    gBS->FreePool (ReportDesc);\r
+    FreePool (Buf);\r
+    FreePool (ReportDesc);\r
     return Status;\r
   }\r
 \r
@@ -693,92 +650,94 @@ InitializeUsbMouseDevice (
   // Parse report descriptor\r
   //\r
   Status = ParseMouseReportDescriptor (\r
-            UsbMouseDev,\r
-            ReportDesc,\r
-            MouseHidDesc.HidClassDesc[0].DescriptorLength\r
-            );\r
+             UsbMouseDev,\r
+             ReportDesc,\r
+             MouseHidDesc->HidClassDesc[0].DescriptorLength\r
+             );\r
 \r
   if (EFI_ERROR (Status)) {\r
-    gBS->FreePool (ReportDesc);\r
+    FreePool (Buf);\r
+    FreePool (ReportDesc);\r
     return Status;\r
   }\r
 \r
+  //\r
+  // Check the presence of left and right buttons,\r
+  // and initialize fields of EFI_SIMPLE_POINTER_MODE.\r
+  //\r
   if (UsbMouseDev->NumberOfButtons >= 1) {\r
     UsbMouseDev->Mode.LeftButton = TRUE;\r
   }\r
-\r
   if (UsbMouseDev->NumberOfButtons > 1) {\r
     UsbMouseDev->Mode.RightButton = TRUE;\r
   }\r
-\r
   UsbMouseDev->Mode.ResolutionX = 8;\r
   UsbMouseDev->Mode.ResolutionY = 8;\r
   UsbMouseDev->Mode.ResolutionZ = 0;\r
+\r
   //\r
-  // Here we just assume interface 0 is the mouse interface\r
+  // Set boot protocol for the USB mouse.\r
+  // This driver only supports boot protocol.\r
   //\r
   UsbGetProtocolRequest (\r
     UsbIo,\r
-    0,\r
+    UsbMouseDev->InterfaceDescriptor.InterfaceNumber,\r
     &Protocol\r
     );\r
-\r
   if (Protocol != BOOT_PROTOCOL) {\r
     Status = UsbSetProtocolRequest (\r
-              UsbIo,\r
-              0,\r
-              BOOT_PROTOCOL\r
-              );\r
+               UsbIo,\r
+               UsbMouseDev->InterfaceDescriptor.InterfaceNumber,\r
+               BOOT_PROTOCOL\r
+               );\r
 \r
     if (EFI_ERROR (Status)) {\r
-      gBS->FreePool (ReportDesc);\r
-      return EFI_DEVICE_ERROR;\r
+      FreePool (Buf);\r
+      FreePool (ReportDesc);\r
+      return Status;\r
     }\r
   }\r
 \r
+  FreePool (Buf);\r
+  FreePool (ReportDesc);\r
+\r
   //\r
-  // Set indefinite Idle rate for USB Mouse\r
+  // Create event for delayed recovery, which deals with device error.\r
   //\r
-  UsbSetIdleRequest (\r
-    UsbIo,\r
-    0,\r
-    0,\r
-    0\r
-    );\r
-\r
-  gBS->FreePool (ReportDesc);\r
-\r
-  if (UsbMouseDev->DelayedRecoveryEvent) {\r
+  if (UsbMouseDev->DelayedRecoveryEvent != NULL) {\r
     gBS->CloseEvent (UsbMouseDev->DelayedRecoveryEvent);\r
     UsbMouseDev->DelayedRecoveryEvent = 0;\r
   }\r
 \r
-  Status = gBS->CreateEvent (\r
-                  EVT_TIMER | EVT_NOTIFY_SIGNAL,\r
-                  TPL_NOTIFY,\r
-                  USBMouseRecoveryHandler,\r
-                  UsbMouseDev,\r
-                  &UsbMouseDev->DelayedRecoveryEvent\r
-                  );\r
+  gBS->CreateEvent (\r
+         EVT_TIMER | EVT_NOTIFY_SIGNAL,\r
+         TPL_NOTIFY,\r
+         USBMouseRecoveryHandler,\r
+         UsbMouseDev,\r
+         &UsbMouseDev->DelayedRecoveryEvent\r
+         );\r
 \r
   return EFI_SUCCESS;\r
 }\r
 \r
 \r
 /**\r
-  It is called whenever there is data received from async interrupt\r
-  transfer.\r
+  Handler function for USB mouse's asynchronous interrupt transfer.\r
+\r
+  This function is the handler function for USB mouse's asynchronous interrupt transfer\r
+  to manage the mouse. It parses data returned from asynchronous interrupt transfer, and\r
+  get button and movement state.\r
 \r
-  @param  Data                  Data received.\r
-  @param  DataLength            Length of Data\r
-  @param  Context               Passed in context\r
-  @param  Result                Async Interrupt Transfer result\r
+  @param  Data             A pointer to a buffer that is filled with key data which is\r
+                           retrieved via asynchronous interrupt transfer.\r
+  @param  DataLength       Indicates the size of the data buffer.\r
+  @param  Context          Pointing to USB_KB_DEV instance.\r
+  @param  Result           Indicates the result of the asynchronous interrupt transfer.\r
 \r
-  @return EFI_SUCCESS\r
-  @return EFI_DEVICE_ERROR\r
+  @retval EFI_SUCCESS      Asynchronous interrupt transfer is handled successfully.\r
+  @retval EFI_DEVICE_ERROR Hardware error occurs.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 EFIAPI\r
 OnMouseInterruptComplete (\r
@@ -800,14 +759,14 @@ OnMouseInterruptComplete (
     //\r
     // Some errors happen during the process\r
     //\r
-    MouseReportStatusCode (\r
-      UsbMouseDevice->DevicePath,\r
+    REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
       EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
-      PcdGet32 (PcdStatusCodeValueMouseInputError)\r
+      (EFI_PERIPHERAL_MOUSE | EFI_P_EC_INPUT_ERROR),\r
+      UsbMouseDevice->DevicePath\r
       );\r
 \r
     if ((Result & EFI_USB_ERR_STALL) == EFI_USB_ERR_STALL) {\r
-      EndpointAddr = UsbMouseDevice->IntEndpointDescriptor->EndpointAddress;\r
+      EndpointAddr = UsbMouseDevice->IntEndpointDescriptor.EndpointAddress;\r
 \r
       UsbClearEndpointHalt (\r
         UsbIo,\r
@@ -816,35 +775,57 @@ OnMouseInterruptComplete (
         );\r
     }\r
 \r
+    //\r
+    // Delete & Submit this interrupt again\r
+    // Handler of DelayedRecoveryEvent triggered by timer will re-submit the interrupt.\r
+    //\r
     UsbIo->UsbAsyncInterruptTransfer (\r
-            UsbIo,\r
-            UsbMouseDevice->IntEndpointDescriptor->EndpointAddress,\r
-            FALSE,\r
-            0,\r
-            0,\r
-            NULL,\r
-            NULL\r
-            );\r
-\r
+             UsbIo,\r
+             UsbMouseDevice->IntEndpointDescriptor.EndpointAddress,\r
+             FALSE,\r
+             0,\r
+             0,\r
+             NULL,\r
+             NULL\r
+             );\r
+    //\r
+    // EFI_USB_INTERRUPT_DELAY is defined in USB standard for error handling.\r
+    //\r
     gBS->SetTimer (\r
-          UsbMouseDevice->DelayedRecoveryEvent,\r
-          TimerRelative,\r
-          EFI_USB_INTERRUPT_DELAY\r
-          );\r
+           UsbMouseDevice->DelayedRecoveryEvent,\r
+           TimerRelative,\r
+           EFI_USB_INTERRUPT_DELAY\r
+           );\r
     return EFI_DEVICE_ERROR;\r
   }\r
 \r
+  //\r
+  // If no error and no data, just return EFI_SUCCESS.\r
+  //\r
   if (DataLength == 0 || Data == NULL) {\r
     return EFI_SUCCESS;\r
   }\r
 \r
-  UsbMouseDevice->StateChanged = TRUE;\r
-\r
   //\r
   // Check mouse Data\r
-  //\r
-  UsbMouseDevice->State.LeftButton  = (BOOLEAN) (*(UINT8 *) Data & 0x01);\r
-  UsbMouseDevice->State.RightButton = (BOOLEAN) (*(UINT8 *) Data & 0x02);\r
+  // USB HID Specification specifies following data format:\r
+  // Byte    Bits    Description\r
+  // 0       0       Button 1\r
+  //         1       Button 2\r
+  //         2       Button 3\r
+  //         4 to 7  Device-specific\r
+  // 1       0 to 7  X displacement\r
+  // 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
+  UsbMouseDevice->StateChanged = TRUE;\r
+\r
+  UsbMouseDevice->State.LeftButton  = (BOOLEAN) ((*(UINT8 *) Data & BIT0) != 0);\r
+  UsbMouseDevice->State.RightButton = (BOOLEAN) ((*(UINT8 *) Data & BIT1) != 0);\r
   UsbMouseDevice->State.RelativeMovementX += *((INT8 *) Data + 1);\r
   UsbMouseDevice->State.RelativeMovementY += *((INT8 *) Data + 2);\r
 \r
@@ -855,32 +836,20 @@ OnMouseInterruptComplete (
   return EFI_SUCCESS;\r
 }\r
 \r
-/*\r
-STATIC VOID\r
-PrintMouseState(\r
-    IN  EFI_MOUSE_STATE *MouseState\r
-    )\r
-{\r
-    Aprint("(%x: %x, %x)\n",\r
-        MouseState->ButtonStates,\r
-        MouseState->dx,\r
-        MouseState->dy\r
-        );\r
-}\r
-*/\r
-\r
 /**\r
-  Get the mouse state, see SIMPLE POINTER PROTOCOL.\r
+  Retrieves the current state of a pointer device.\r
 \r
-  @param  This                  Protocol instance pointer.\r
-  @param  MouseState            Current mouse state\r
+  @param  This                  A pointer to the EFI_SIMPLE_POINTER_PROTOCOL instance.\r
+  @param  MouseState            A pointer to the state information on the pointer device.\r
 \r
-  @return EFI_SUCCESS\r
-  @return EFI_DEVICE_ERROR\r
-  @return EFI_NOT_READY\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
+  @retval EFI_DEVICE_ERROR      A device error occurred while attempting to retrieve the pointer device's\r
+                                current state.\r
+  @retval EFI_INVALID_PARAMETER MouseState is NULL.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 EFIAPI\r
 GetMouseState (\r
@@ -891,7 +860,7 @@ GetMouseState (
   USB_MOUSE_DEV *MouseDev;\r
 \r
   if (MouseState == NULL) {\r
-    return EFI_DEVICE_ERROR;\r
+    return EFI_INVALID_PARAMETER;\r
   }\r
 \r
   MouseDev = USB_MOUSE_DEV_FROM_MOUSE_PROTOCOL (This);\r
@@ -900,6 +869,9 @@ GetMouseState (
     return EFI_NOT_READY;\r
   }\r
 \r
+  //\r
+  // Retrieve mouse state from USB_MOUSE_DEV, which was filled by OnMouseInterruptComplete()\r
+  //\r
   CopyMem (\r
     MouseState,\r
     &MouseDev->State,\r
@@ -920,15 +892,16 @@ GetMouseState (
 \r
 \r
 /**\r
-  Reset the mouse device, see SIMPLE POINTER PROTOCOL.\r
+  Resets the pointer device hardware.\r
 \r
-  @param  This                  Protocol instance pointer.\r
-  @param  ExtendedVerification  Ignored here/\r
+  @param  This                  A pointer to the EFI_SIMPLE_POINTER_PROTOCOL instance.\r
+  @param  ExtendedVerification  Indicates that the driver may perform a more exhaustive\r
+                                verification operation of the device during reset.\r
 \r
-  @return EFI_SUCCESS\r
+  @retval EFI_SUCCESS           The device was reset.\r
+  @retval EFI_DEVICE_ERROR      The device is not functioning correctly and could not be reset.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 EFIAPI\r
 UsbMouseReset (\r
@@ -940,13 +913,15 @@ UsbMouseReset (
 \r
   UsbMouseDevice  = USB_MOUSE_DEV_FROM_MOUSE_PROTOCOL (This);\r
 \r
-  MouseReportStatusCode (\r
-    UsbMouseDevice->DevicePath,\r
+  REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
     EFI_PROGRESS_CODE,\r
-    PcdGet32 (PcdStatusCodeValueMouseReset)\r
-\r
+    (EFI_PERIPHERAL_MOUSE | EFI_P_PC_RESET),\r
+    UsbMouseDevice->DevicePath\r
     );\r
 \r
+  //\r
+  // Clear mouse state.\r
+  //\r
   ZeroMem (\r
     &UsbMouseDevice->State,\r
     sizeof (EFI_SIMPLE_POINTER_STATE)\r
@@ -956,17 +931,13 @@ UsbMouseReset (
   return EFI_SUCCESS;\r
 }\r
 \r
-\r
 /**\r
-  Event notification function for SIMPLE_POINTER.WaitForInput event\r
-  Signal the event if there is input from mouse\r
+  Event notification function for EFI_SIMPLE_POINTER_PROTOCOL.WaitForInput event.\r
 \r
-  @param  Event                 Wait Event\r
-  @param  Context               Passed parameter to event handler\r
- VOID\r
+  @param  Event        Event to be signaled when there's input from mouse.\r
+  @param  Context      Points to USB_MOUSE_DEV instance.\r
 \r
 **/\r
-STATIC\r
 VOID\r
 EFIAPI\r
 UsbMouseWaitForInput (\r
@@ -979,21 +950,24 @@ UsbMouseWaitForInput (
   UsbMouseDev = (USB_MOUSE_DEV *) Context;\r
 \r
   //\r
-  // Someone is waiting on the mouse event, if there's\r
-  // input from mouse, signal the event\r
+  // If there's input from mouse, signal the event.\r
   //\r
   if (UsbMouseDev->StateChanged) {\r
     gBS->SignalEvent (Event);\r
   }\r
 }\r
 \r
-\r
 /**\r
-  Timer handler for Delayed Recovery timer.\r
+  Handler for Delayed Recovery event.\r
 \r
-  @param  Event                 The Delayed Recovery event.\r
-  @param  Context               Points to the USB_KB_DEV instance.\r
+  This function is the handler for Delayed Recovery event triggered\r
+  by timer.\r
+  After a device error occurs, the event would be triggered\r
+  with interval of EFI_USB_INTERRUPT_DELAY. EFI_USB_INTERRUPT_DELAY\r
+  is defined in USB standard for error handling.\r
 \r
+  @param  Event              The Delayed Recovery event.\r
+  @param  Context            Points to the USB_MOUSE_DEV instance.\r
 \r
 **/\r
 VOID\r
@@ -1010,38 +984,16 @@ USBMouseRecoveryHandler (
 \r
   UsbIo       = UsbMouseDev->UsbIo;\r
 \r
+  //\r
+  // Re-submit Asynchronous Interrupt Transfer for recovery.\r
+  //\r
   UsbIo->UsbAsyncInterruptTransfer (\r
-          UsbIo,\r
-          UsbMouseDev->IntEndpointDescriptor->EndpointAddress,\r
-          TRUE,\r
-          UsbMouseDev->IntEndpointDescriptor->Interval,\r
-          UsbMouseDev->IntEndpointDescriptor->MaxPacketSize,\r
-          OnMouseInterruptComplete,\r
-          UsbMouseDev\r
-          );\r
-}\r
-\r
-\r
-/**\r
-  Report Status Code in Usb Bot Driver\r
-\r
-  @param  DevicePath            Use this to get Device Path\r
-  @param  CodeType              Status Code Type\r
-  @param  CodeValue             Status Code Value\r
-\r
-  @return None\r
-\r
-**/\r
-VOID\r
-MouseReportStatusCode (\r
-  IN EFI_DEVICE_PATH_PROTOCOL  *DevicePath,\r
-  IN EFI_STATUS_CODE_TYPE      CodeType,\r
-  IN EFI_STATUS_CODE_VALUE     Value\r
-  )\r
-{\r
-  REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
-    CodeType,\r
-    Value,\r
-    DevicePath\r
-    );\r
+           UsbIo,\r
+           UsbMouseDev->IntEndpointDescriptor.EndpointAddress,\r
+           TRUE,\r
+           UsbMouseDev->IntEndpointDescriptor.Interval,\r
+           UsbMouseDev->IntEndpointDescriptor.MaxPacketSize,\r
+           OnMouseInterruptComplete,\r
+           UsbMouseDev\r
+           );\r
 }\r