]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Code Scrub for USB Mouse Absolute Pointer Driver.
authorxli24 <xli24@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 31 Dec 2008 07:32:33 +0000 (07:32 +0000)
committerxli24 <xli24@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 31 Dec 2008 07:32:33 +0000 (07:32 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@7163 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Bus/Usb/UsbMouseAbsolutePointerDxe/ComponentName.c
MdeModulePkg/Bus/Usb/UsbMouseAbsolutePointerDxe/UsbMouseAbsolutePointer.c
MdeModulePkg/Bus/Usb/UsbMouseAbsolutePointerDxe/UsbMouseAbsolutePointer.h
MdeModulePkg/Bus/Usb/UsbMouseAbsolutePointerDxe/UsbMouseAbsolutePointerDxe.inf
MdeModulePkg/Bus/Usb/UsbMouseAbsolutePointerDxe/mousehid.c
MdeModulePkg/Bus/Usb/UsbMouseAbsolutePointerDxe/mousehid.h [deleted file]

index 3e71f4e748b8ece8271b0df9d0b9475b60cb3da4..507ae8e62599882389b4e2758dfff7d0eb5639a5 100644 (file)
@@ -1,6 +1,7 @@
 /** @file\r
+  UEFI Component Name(2) protocol implementation for USB Mouse Absolute Pointer Driver.\r
 \r
-Copyright (c) 2004 - 2007, Intel Corporation\r
+Copyright (c) 2004 - 2008, 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
@@ -9,147 +10,10 @@ http://opensource.org/licenses/bsd-license.php
 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
-  UsbMouseAbsolutePointerComponentName.c\r
-\r
-Abstract:\r
-\r
-\r
 **/\r
 \r
-#include "UsbMouseAbsolutePointer.h"\r
-#include <Library/DebugLib.h>\r
-\r
-//\r
-// EFI Component Name Functions\r
-//\r
-/**\r
-  Retrieves a Unicode string that is the user readable name of the driver.\r
-\r
-  This function retrieves the user readable name of a driver in the form of a\r
-  Unicode string. If the driver specified by This has a user readable name in\r
-  the language specified by Language, then a pointer to the driver name is\r
-  returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r
-  by This does not support the language specified by Language,\r
-  then EFI_UNSUPPORTED is returned.\r
-\r
-  @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
-                                EFI_COMPONENT_NAME_PROTOCOL instance.\r
-\r
-  @param  Language[in]          A pointer to a Null-terminated ASCII string\r
-                                array indicating the language. This is the\r
-                                language of the driver name that the caller is\r
-                                requesting, and it must match one of the\r
-                                languages specified in SupportedLanguages. The\r
-                                number of languages supported by a driver is up\r
-                                to the driver writer. Language is specified\r
-                                in RFC 3066 or ISO 639-2 language code format.\r
-\r
-  @param  DriverName[out]       A pointer to the Unicode string to return.\r
-                                This Unicode string is the name of the\r
-                                driver specified by This in the language\r
-                                specified by Language.\r
-\r
-  @retval EFI_SUCCESS           The Unicode string for the Driver specified by\r
-                                This and the language specified by Language was\r
-                                returned in DriverName.\r
-\r
-  @retval EFI_INVALID_PARAMETER Language is NULL.\r
-\r
-  @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
-\r
-  @retval EFI_UNSUPPORTED       The driver specified by This does not support\r
-                                the language specified by Language.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-UsbMouseAbsolutePointerComponentNameGetDriverName (\r
-  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
-  IN  CHAR8                        *Language,\r
-  OUT CHAR16                       **DriverName\r
-  );\r
-\r
-\r
-/**\r
-  Retrieves a Unicode string that is the user readable name of the controller\r
-  that is being managed by a driver.\r
-\r
-  This function retrieves the user readable name of the controller specified by\r
-  ControllerHandle and ChildHandle in the form of a Unicode string. If the\r
-  driver specified by This has a user readable name in the language specified by\r
-  Language, then a pointer to the controller name is returned in ControllerName,\r
-  and EFI_SUCCESS is returned.  If the driver specified by This is not currently\r
-  managing the controller specified by ControllerHandle and ChildHandle,\r
-  then EFI_UNSUPPORTED is returned.  If the driver specified by This does not\r
-  support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
-\r
-  @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
-                                EFI_COMPONENT_NAME_PROTOCOL instance.\r
-\r
-  @param  ControllerHandle[in]  The handle of a controller that the driver\r
-                                specified by This is managing.  This handle\r
-                                specifies the controller whose name is to be\r
-                                returned.\r
-\r
-  @param  ChildHandle[in]       The handle of the child controller to retrieve\r
-                                the name of.  This is an optional parameter that\r
-                                may be NULL.  It will be NULL for device\r
-                                drivers.  It will also be NULL for a bus drivers\r
-                                that wish to retrieve the name of the bus\r
-                                controller.  It will not be NULL for a bus\r
-                                driver that wishes to retrieve the name of a\r
-                                child controller.\r
-\r
-  @param  Language[in]          A pointer to a Null-terminated ASCII string\r
-                                array indicating the language.  This is the\r
-                                language of the driver name that the caller is\r
-                                requesting, and it must match one of the\r
-                                languages specified in SupportedLanguages. The\r
-                                number of languages supported by a driver is up\r
-                                to the driver writer. Language is specified in\r
-                                RFC 3066 or ISO 639-2 language code format.\r
-\r
-  @param  ControllerName[out]   A pointer to the Unicode string to return.\r
-                                This Unicode string is the name of the\r
-                                controller specified by ControllerHandle and\r
-                                ChildHandle in the language specified by\r
-                                Language from the point of view of the driver\r
-                                specified by This.\r
-\r
-  @retval EFI_SUCCESS           The Unicode string for the user readable name in\r
-                                the language specified by Language for the\r
-                                driver specified by This was returned in\r
-                                DriverName.\r
-\r
-  @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.\r
-\r
-  @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r
-                                EFI_HANDLE.\r
-\r
-  @retval EFI_INVALID_PARAMETER Language is NULL.\r
-\r
-  @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
-\r
-  @retval EFI_UNSUPPORTED       The driver specified by This is not currently\r
-                                managing the controller specified by\r
-                                ControllerHandle and ChildHandle.\r
-\r
-  @retval EFI_UNSUPPORTED       The driver specified by This does not support\r
-                                the language specified by Language.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-UsbMouseAbsolutePointerComponentNameGetControllerName (\r
-  IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,\r
-  IN  EFI_HANDLE                                      ControllerHandle,\r
-  IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,\r
-  IN  CHAR8                                           *Language,\r
-  OUT CHAR16                                          **ControllerName\r
-  );\r
 \r
+#include "UsbMouseAbsolutePointer.h"\r
 \r
 //\r
 // EFI Component Name Protocol\r
@@ -170,13 +34,11 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gUsbMouseAbsolutePoin
 };\r
 \r
 \r
-\r
 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mUsbMouseAbsolutePointerDriverNameTable[] = {\r
-  { "eng;en", L"Usb Mouse Simulate TouchPad Driver" },\r
+  { "eng;en", L"Usb Mouse Absolute Pointer Driver" },\r
   { NULL , NULL }\r
 };\r
 \r
-\r
 /**\r
   Retrieves a Unicode string that is the user readable name of the driver.\r
 \r
@@ -187,10 +49,9 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mUsbMouseAbsolutePointerD
   by This does not support the language specified by Language,\r
   then EFI_UNSUPPORTED is returned.\r
 \r
-  @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
+  @param  This                  A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
                                 EFI_COMPONENT_NAME_PROTOCOL instance.\r
-\r
-  @param  Language[in]          A pointer to a Null-terminated ASCII string\r
+  @param  Language              A pointer to a Null-terminated ASCII string\r
                                 array indicating the language. This is the\r
                                 language of the driver name that the caller is\r
                                 requesting, and it must match one of the\r
@@ -198,8 +59,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mUsbMouseAbsolutePointerD
                                 number of languages supported by a driver is up\r
                                 to the driver writer. Language is specified\r
                                 in RFC 3066 or ISO 639-2 language code format.\r
-\r
-  @param  DriverName[out]       A pointer to the Unicode string to return.\r
+  @param  DriverName            A pointer to the Unicode string to return.\r
                                 This Unicode string is the name of the\r
                                 driver specified by This in the language\r
                                 specified by Language.\r
@@ -207,11 +67,8 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mUsbMouseAbsolutePointerD
   @retval EFI_SUCCESS           The Unicode string for the Driver specified by\r
                                 This and the language specified by Language was\r
                                 returned in DriverName.\r
-\r
   @retval EFI_INVALID_PARAMETER Language is NULL.\r
-\r
   @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
-\r
   @retval EFI_UNSUPPORTED       The driver specified by This does not support\r
                                 the language specified by Language.\r
 \r
@@ -246,15 +103,13 @@ UsbMouseAbsolutePointerComponentNameGetDriverName (
   then EFI_UNSUPPORTED is returned.  If the driver specified by This does not\r
   support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
 \r
-  @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
+  @param  This                  A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
                                 EFI_COMPONENT_NAME_PROTOCOL instance.\r
-\r
-  @param  ControllerHandle[in]  The handle of a controller that the driver\r
+  @param  ControllerHandle      The handle of a controller that the driver\r
                                 specified by This is managing.  This handle\r
                                 specifies the controller whose name is to be\r
                                 returned.\r
-\r
-  @param  ChildHandle[in]       The handle of the child controller to retrieve\r
+  @param  ChildHandle           The handle of the child controller to retrieve\r
                                 the name of.  This is an optional parameter that\r
                                 may be NULL.  It will be NULL for device\r
                                 drivers.  It will also be NULL for a bus drivers\r
@@ -262,8 +117,7 @@ UsbMouseAbsolutePointerComponentNameGetDriverName (
                                 controller.  It will not be NULL for a bus\r
                                 driver that wishes to retrieve the name of a\r
                                 child controller.\r
-\r
-  @param  Language[in]          A pointer to a Null-terminated ASCII string\r
+  @param  Language              A pointer to a Null-terminated ASCII string\r
                                 array indicating the language.  This is the\r
                                 language of the driver name that the caller is\r
                                 requesting, and it must match one of the\r
@@ -271,8 +125,7 @@ UsbMouseAbsolutePointerComponentNameGetDriverName (
                                 number of languages supported by a driver is up\r
                                 to the driver writer. Language is specified in\r
                                 RFC 3066 or ISO 639-2 language code format.\r
-\r
-  @param  ControllerName[out]   A pointer to the Unicode string to return.\r
+  @param  ControllerName        A pointer to the Unicode string to return.\r
                                 This Unicode string is the name of the\r
                                 controller specified by ControllerHandle and\r
                                 ChildHandle in the language specified by\r
@@ -283,20 +136,14 @@ UsbMouseAbsolutePointerComponentNameGetDriverName (
                                 the language specified by Language for the\r
                                 driver specified by This was returned in\r
                                 DriverName.\r
-\r
   @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.\r
-\r
   @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r
                                 EFI_HANDLE.\r
-\r
   @retval EFI_INVALID_PARAMETER Language is NULL.\r
-\r
   @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
-\r
   @retval EFI_UNSUPPORTED       The driver specified by This is not currently\r
                                 managing the controller specified by\r
                                 ControllerHandle and ChildHandle.\r
-\r
   @retval EFI_UNSUPPORTED       The driver specified by This does not support\r
                                 the language specified by Language.\r
 \r
@@ -311,10 +158,10 @@ UsbMouseAbsolutePointerComponentNameGetControllerName (
   OUT CHAR16                                          **ControllerName\r
   )\r
 {\r
-  EFI_STATUS                  Status;\r
-  USB_MOUSE_ABSOLUTE_POINTER_DEV               *UsbMouseAbsolutePointerDev;\r
-  EFI_ABSOLUTE_POINTER_PROTOCOL *AbsolutePointerProtocol;\r
-  EFI_USB_IO_PROTOCOL         *UsbIoProtocol;\r
+  EFI_STATUS                       Status;\r
+  USB_MOUSE_ABSOLUTE_POINTER_DEV   *UsbMouseAbsolutePointerDev;\r
+  EFI_ABSOLUTE_POINTER_PROTOCOL    *AbsolutePointerProtocol;\r
+  EFI_USB_IO_PROTOCOL              *UsbIoProtocol;\r
 \r
   //\r
   // This is a device driver, so ChildHandle must be NULL.\r
@@ -336,11 +183,11 @@ UsbMouseAbsolutePointerComponentNameGetControllerName (
                   );\r
   if (!EFI_ERROR (Status)) {\r
     gBS->CloseProtocol (\r
-          ControllerHandle,\r
-          &gEfiUsbIoProtocolGuid,\r
-          gUsbMouseAbsolutePointerDriverBinding.DriverBindingHandle,\r
-          ControllerHandle\r
-          );\r
+           ControllerHandle,\r
+           &gEfiUsbIoProtocolGuid,\r
+           gUsbMouseAbsolutePointerDriverBinding.DriverBindingHandle,\r
+           ControllerHandle\r
+           );\r
 \r
     return EFI_UNSUPPORTED;\r
   }\r
index faafd2e52c32c06f24fcd0280366e026a0c836f3..2e22cfcda2433f2964525c57049ee4ca5c6a8bcc 100644 (file)
@@ -1,6 +1,7 @@
 /** @file\r
+  USB Mouse Driver that manages USB mouse and produces Absolute Pointer Protocol.\r
 \r
-Copyright (c) 2004 - 2007, Intel Corporation\r
+Copyright (c) 2004 - 2008, 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
@@ -9,27 +10,10 @@ http://opensource.org/licenses/bsd-license.php
 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
-    UsbMouseAbsolutePointer.c\r
-\r
-  Abstract:\r
-\r
-\r
 **/\r
 \r
 #include "UsbMouseAbsolutePointer.h"\r
 \r
-#include <Library/DebugLib.h>\r
-#include <IndustryStandard/Usb.h>\r
-\r
-#include "mousehid.h"\r
-\r
-\r
-EFI_GUID  gEfiUsbMouseAbsolutePointerDriverGuid = {\r
-  0xa579f729, 0xa71d, 0x4b45, { 0xbe, 0xd7, 0xd, 0xb0, 0xa8, 0x7c, 0x3e, 0x8d }\r
-};\r
-\r
 EFI_DRIVER_BINDING_PROTOCOL gUsbMouseAbsolutePointerDriverBinding = {\r
   USBMouseAbsolutePointerDriverBindingSupported,\r
   USBMouseAbsolutePointerDriverBindingStart,\r
@@ -39,99 +23,50 @@ EFI_DRIVER_BINDING_PROTOCOL gUsbMouseAbsolutePointerDriverBinding = {
   NULL\r
 };\r
 \r
-//\r
-// helper functions\r
-//\r
-BOOLEAN\r
-IsUsbMouseAbsolutePointer (\r
-  IN  EFI_USB_IO_PROTOCOL     *UsbIo\r
-  );\r
-\r
-EFI_STATUS\r
-InitializeUsbMouseAbsolutePointerDevice (\r
-  IN  USB_MOUSE_ABSOLUTE_POINTER_DEV           *UsbMouseAbsolutePointerDev\r
-  );\r
-\r
-VOID\r
-EFIAPI\r
-UsbMouseAbsolutePointerWaitForInput (\r
-  IN  EFI_EVENT               Event,\r
-  IN  VOID                    *Context\r
-  );\r
+/**\r
+  Entrypoint of USB Mouse Absolute Pointer Driver.\r
 \r
-//\r
-// Mouse interrupt handler\r
-//\r
-EFI_STATUS\r
-EFIAPI\r
-OnMouseAbsolutePointerInterruptComplete (\r
-  IN  VOID        *Data,\r
-  IN  UINTN       DataLength,\r
-  IN  VOID        *Context,\r
-  IN  UINT32      Result\r
-  );\r
+  This function is the entrypoint of USB Mouse Driver. It installs Driver Binding\r
+  Protocols together with Component Name Protocols.\r
 \r
-//\r
-// Mouse simulate TouchPad, Using AbsolutePointer Protocol\r
-//\r
-EFI_STATUS\r
-EFIAPI\r
-GetMouseAbsolutePointerState (\r
-  IN   EFI_ABSOLUTE_POINTER_PROTOCOL  *This,\r
-  OUT  EFI_ABSOLUTE_POINTER_STATE     *MouseAbsolutePointerState\r
-  );\r
+  @param  ImageHandle       The firmware allocated handle for the EFI image.\r
+  @param  SystemTable       A pointer to the EFI System Table.\r
 \r
-EFI_STATUS\r
-EFIAPI\r
-UsbMouseAbsolutePointerReset (\r
-  IN EFI_ABSOLUTE_POINTER_PROTOCOL    *This,\r
-  IN BOOLEAN                        ExtendedVerification\r
-  );\r
+  @retval EFI_SUCCESS       The entry point is executed successfully.\r
 \r
-//\r
-// Driver start here\r
-//\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 USBMouseAbsolutePointerDriverBindingEntryPoint (\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
+             &gUsbMouseAbsolutePointerDriverBinding,\r
+             ImageHandle,\r
+             &gUsbMouseAbsolutePointerComponentName,\r
+             &gUsbMouseAbsolutePointerComponentName2\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
 \r
---*/\r
-{\r
-       return EfiLibInstallDriverBindingComponentName2 (\r
-           ImageHandle,\r
-           SystemTable,\r
-           &gUsbMouseAbsolutePointerDriverBinding,\r
-           ImageHandle,\r
-           &gUsbMouseAbsolutePointerComponentName,\r
-           &gUsbMouseAbsolutePointerComponentName2\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 Absolute Pointer 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 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
@@ -142,32 +77,27 @@ USBMouseAbsolutePointerDriverBindingSupported (
   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 (!IsUsbMouseAbsolutePointer (UsbIo)) {\r
+  if (!IsUsbMouse (UsbIo)) {\r
     Status = EFI_UNSUPPORTED;\r
   }\r
   \r
@@ -183,18 +113,22 @@ USBMouseAbsolutePointerDriverBindingSupported (
 \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 Portocol, intializes USB mouse device,\r
+  installs Absolute Pointer Protocol, and submits Asynchronous Interrupt\r
+  Transfer to manage the USB mouse device.\r
+\r
+  @param  This                  The 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   This 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
@@ -205,19 +139,20 @@ USBMouseAbsolutePointerDriverBindingStart (
   IN EFI_DEVICE_PATH_PROTOCOL       *RemainingDevicePath\r
   )\r
 {\r
-  EFI_STATUS                  Status;\r
-  EFI_USB_IO_PROTOCOL         *UsbIo;\r
-  EFI_USB_ENDPOINT_DESCRIPTOR *EndpointDesc;\r
-  USB_MOUSE_ABSOLUTE_POINTER_DEV               *UsbMouseAbsolutePointerDevice;\r
-  UINT8                       EndpointNumber;\r
-  UINT8                       Index;\r
-  UINT8                       EndpointAddr;\r
-  UINT8                       PollingInterval;\r
-  UINT8                       PacketSize;\r
-\r
-  UsbMouseAbsolutePointerDevice  = NULL;\r
-  Status          = EFI_SUCCESS;\r
+  EFI_STATUS                     Status;\r
+  EFI_USB_IO_PROTOCOL            *UsbIo;\r
+  USB_MOUSE_ABSOLUTE_POINTER_DEV *UsbMouseAbsolutePointerDevice;\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
 \r
+  //\r
+  // Open USB I/O Protocol\r
+  //\r
   Status = gBS->OpenProtocol (\r
                   Controller,\r
                   &gEfiUsbIoProtocolGuid,\r
@@ -227,31 +162,15 @@ USBMouseAbsolutePointerDriverBindingStart (
                   EFI_OPEN_PROTOCOL_BY_DRIVER                  \r
                   );\r
   if (EFI_ERROR (Status)) {\r
-    goto ErrorExit;\r
+    return Status;\r
   }\r
   \r
   UsbMouseAbsolutePointerDevice = AllocateZeroPool (sizeof (USB_MOUSE_ABSOLUTE_POINTER_DEV));\r
-  if (UsbMouseAbsolutePointerDevice == NULL) {\r
-    Status = EFI_OUT_OF_RESOURCES;\r
-    goto ErrorExit;\r
-  }\r
+  ASSERT (UsbMouseAbsolutePointerDevice != NULL);\r
 \r
-  UsbMouseAbsolutePointerDevice->UsbIo               = UsbIo;\r
+  UsbMouseAbsolutePointerDevice->UsbIo     = UsbIo;\r
+  UsbMouseAbsolutePointerDevice->Signature = USB_MOUSE_ABSOLUTE_POINTER_DEV_SIGNATURE;\r
 \r
-  UsbMouseAbsolutePointerDevice->Signature           = USB_MOUSE_ABSOLUTE_POINTER_DEV_SIGNATURE;\r
-\r
-  UsbMouseAbsolutePointerDevice->InterfaceDescriptor = AllocatePool (sizeof (EFI_USB_INTERFACE_DESCRIPTOR));\r
-\r
-  if (UsbMouseAbsolutePointerDevice->InterfaceDescriptor == NULL) {\r
-    Status = EFI_OUT_OF_RESOURCES;\r
-    goto ErrorExit;\r
-  }\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
@@ -271,92 +190,101 @@ USBMouseAbsolutePointerDriverBindingStart (
   // Get interface & endpoint descriptor\r
   //\r
   UsbIo->UsbGetInterfaceDescriptor (\r
-          UsbIo,\r
-          UsbMouseAbsolutePointerDevice->InterfaceDescriptor\r
-          );\r
+           UsbIo,\r
+           &UsbMouseAbsolutePointerDevice->InterfaceDescriptor\r
+           );\r
 \r
-  EndpointNumber = UsbMouseAbsolutePointerDevice->InterfaceDescriptor->NumEndpoints;\r
+  EndpointNumber = UsbMouseAbsolutePointerDevice->InterfaceDescriptor.NumEndpoints;\r
 \r
+  //\r
+  // Traverse endpoints to find interrupt endpoint\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
       //\r
       // We only care interrupt endpoint here\r
       //\r
-      UsbMouseAbsolutePointerDevice->IntEndpointDescriptor = EndpointDesc;\r
+      CopyMem (&UsbMouseAbsolutePointerDevice->IntEndpointDescriptor, &EndpointDescriptor, sizeof(EndpointDescriptor));\r
+      Found = TRUE;\r
+      break;\r
     }\r
   }\r
 \r
-  if (UsbMouseAbsolutePointerDevice->IntEndpointDescriptor == NULL) {\r
+  if (!Found) {\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
-  Status = InitializeUsbMouseAbsolutePointerDevice (UsbMouseAbsolutePointerDevice);\r
+  Status = InitializeUsbMouseDevice (UsbMouseAbsolutePointerDevice);\r
   if (EFI_ERROR (Status)) {\r
-    MouseAbsolutePointerReportStatusCode (\r
-      UsbMouseAbsolutePointerDevice->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
+      PcdGet32 (PcdStatusCodeValueMouseInterfaceError),\r
+      UsbMouseAbsolutePointerDevice->DevicePath\r
       );\r
 \r
     goto ErrorExit;\r
   }\r
 \r
+  //\r
+  // Initialize and install EFI Absolute Pointer Protocol.\r
+  //\r
   UsbMouseAbsolutePointerDevice->AbsolutePointerProtocol.GetState = GetMouseAbsolutePointerState;\r
-  UsbMouseAbsolutePointerDevice->AbsolutePointerProtocol.Reset    = UsbMouseAbsolutePointerReset;\r
-  UsbMouseAbsolutePointerDevice->AbsolutePointerProtocol.Mode     = &UsbMouseAbsolutePointerDevice->AbsolutePointerMode;\r
+  UsbMouseAbsolutePointerDevice->AbsolutePointerProtocol.Reset   = UsbMouseAbsolutePointerReset;\r
+  UsbMouseAbsolutePointerDevice->AbsolutePointerProtocol.Mode    = &UsbMouseAbsolutePointerDevice->Mode;\r
 \r
   Status = gBS->CreateEvent (\r
-          EVT_NOTIFY_WAIT,\r
-          TPL_NOTIFY,\r
-          UsbMouseAbsolutePointerWaitForInput,\r
-          UsbMouseAbsolutePointerDevice,\r
-          &((UsbMouseAbsolutePointerDevice->AbsolutePointerProtocol).WaitForInput)\r
-          );\r
+                  EVT_NOTIFY_WAIT,\r
+                  TPL_NOTIFY,\r
+                  UsbMouseAbsolutePointerWaitForInput,\r
+                  UsbMouseAbsolutePointerDevice,\r
+                  &((UsbMouseAbsolutePointerDevice->AbsolutePointerProtocol).WaitForInput)\r
+                  );\r
   if (EFI_ERROR (Status)) {\r
     goto ErrorExit;\r
   }\r
 \r
   Status = gBS->InstallProtocolInterface (\r
-          &Controller,\r
-          &gEfiAbsolutePointerProtocolGuid,\r
-          EFI_NATIVE_INTERFACE,\r
-          &UsbMouseAbsolutePointerDevice->AbsolutePointerProtocol\r
-          );\r
+                  &Controller,\r
+                  &gEfiAbsolutePointerProtocolGuid,\r
+                  EFI_NATIVE_INTERFACE,\r
+                  &UsbMouseAbsolutePointerDevice->AbsolutePointerProtocol\r
+                  );\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
-  MouseAbsolutePointerReportStatusCode (\r
-    UsbMouseAbsolutePointerDevice->DevicePath,\r
+  REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
     EFI_PROGRESS_CODE,\r
-    PcdGet32 (PcdStatusCodeValueMouseEnable)\r
+    PcdGet32 (PcdStatusCodeValueMouseEnable),\r
+    UsbMouseAbsolutePointerDevice->DevicePath\r
     );\r
 \r
   //\r
-  // submit async interrupt transfer\r
+  // Submit Asynchronous Interrupt Transfer to manage this device.\r
   //\r
-  EndpointAddr    = UsbMouseAbsolutePointerDevice->IntEndpointDescriptor->EndpointAddress;\r
-  PollingInterval = UsbMouseAbsolutePointerDevice->IntEndpointDescriptor->Interval;\r
-  PacketSize      = (UINT8) (UsbMouseAbsolutePointerDevice->IntEndpointDescriptor->MaxPacketSize);\r
+  EndpointAddr    = UsbMouseAbsolutePointerDevice->IntEndpointDescriptor.EndpointAddress;\r
+  PollingInterval = UsbMouseAbsolutePointerDevice->IntEndpointDescriptor.Interval;\r
+  PacketSize      = (UINT8) (UsbMouseAbsolutePointerDevice->IntEndpointDescriptor.MaxPacketSize);\r
 \r
   Status = UsbIo->UsbAsyncInterruptTransfer (\r
                     UsbIo,\r
@@ -364,42 +292,43 @@ USBMouseAbsolutePointerDriverBindingStart (
                     TRUE,\r
                     PollingInterval,\r
                     PacketSize,\r
-                    OnMouseAbsolutePointerInterruptComplete,\r
+                    OnMouseInterruptComplete,\r
                     UsbMouseAbsolutePointerDevice\r
                     );\r
 \r
-  if (!EFI_ERROR (Status)) {\r
+  if (EFI_ERROR (Status)) {\r
+    //\r
+    // If submit error, uninstall that interface\r
+    //\r
+    gBS->UninstallProtocolInterface (\r
+           Controller,\r
+           &gEfiAbsolutePointerProtocolGuid,\r
+           &UsbMouseAbsolutePointerDevice->AbsolutePointerProtocol\r
+           );\r
+    goto ErrorExit;\r
+  }\r
 \r
-    UsbMouseAbsolutePointerDevice->ControllerNameTable = NULL;\r
-    AddUnicodeString2 (\r
-      "eng",\r
-      gUsbMouseAbsolutePointerComponentName.SupportedLanguages,\r
-      &UsbMouseAbsolutePointerDevice->ControllerNameTable,\r
-      L"Generic Usb Mouse Simulate TouchPad",\r
+  UsbMouseAbsolutePointerDevice->ControllerNameTable = NULL;\r
+  AddUnicodeString2 (\r
+    "eng",\r
+    gUsbMouseAbsolutePointerComponentName.SupportedLanguages,\r
+    &UsbMouseAbsolutePointerDevice->ControllerNameTable,\r
+    L"Generic Usb Mouse Absolute Pointer",\r
       TRUE\r
       );\r
-    AddUnicodeString2 (\r
-      "en",\r
-      gUsbMouseAbsolutePointerComponentName2.SupportedLanguages,\r
-      &UsbMouseAbsolutePointerDevice->ControllerNameTable,\r
-      L"Generic Usb Mouse Simulate TouchPad2",\r
-      FALSE\r
-      );\r
-\r
-    return EFI_SUCCESS;\r
-  }\r
-\r
-  //\r
-  // If submit error, uninstall that interface\r
-  //\r
-  Status = EFI_DEVICE_ERROR;\r
+  AddUnicodeString2 (\r
+    "en",\r
+    gUsbMouseAbsolutePointerComponentName2.SupportedLanguages,\r
+    &UsbMouseAbsolutePointerDevice->ControllerNameTable,\r
+    L"Generic Usb Mouse Absolute Pointer",\r
+    FALSE\r
+    );\r
 \r
-  gBS->UninstallProtocolInterface (\r
-        Controller,\r
-        &gEfiAbsolutePointerProtocolGuid,\r
-        &UsbMouseAbsolutePointerDevice->AbsolutePointerProtocol\r
-  );\r
+  return EFI_SUCCESS;\r
 \r
+//\r
+// Error handler\r
+//\r
 ErrorExit:\r
   if (EFI_ERROR (Status)) {\r
     gBS->CloseProtocol (\r
@@ -410,19 +339,11 @@ ErrorExit:
           );\r
 \r
     if (UsbMouseAbsolutePointerDevice != NULL) {\r
-      if (UsbMouseAbsolutePointerDevice->InterfaceDescriptor != NULL) {\r
-        gBS->FreePool (UsbMouseAbsolutePointerDevice->InterfaceDescriptor);\r
-      }\r
-\r
-      if (UsbMouseAbsolutePointerDevice->IntEndpointDescriptor != NULL) {\r
-        gBS->FreePool (UsbMouseAbsolutePointerDevice->IntEndpointDescriptor);\r
-      }\r
-  \r
       if ((UsbMouseAbsolutePointerDevice->AbsolutePointerProtocol).WaitForInput != NULL) {\r
         gBS->CloseEvent ((UsbMouseAbsolutePointerDevice->AbsolutePointerProtocol).WaitForInput);\r
       }\r
 \r
-      gBS->FreePool (UsbMouseAbsolutePointerDevice);\r
+      FreePool (UsbMouseAbsolutePointerDevice);\r
       UsbMouseAbsolutePointerDevice = NULL;\r
     }\r
   }\r
@@ -432,17 +353,16 @@ ErrorExit:
 \r
 \r
 /**\r
-  Stop this driver on ControllerHandle. Support stopping 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 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        Absolute Pointer Protocol is not installed on Controller.\r
+  @retval Others                 Fail to uninstall protocols attached on the device.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -454,66 +374,49 @@ USBMouseAbsolutePointerDriverBindingStop (
   IN  EFI_HANDLE                    *ChildHandleBuffer\r
   )\r
 {\r
-  EFI_STATUS                  Status;\r
-  USB_MOUSE_ABSOLUTE_POINTER_DEV               *UsbMouseAbsolutePointerDevice;\r
-  EFI_ABSOLUTE_POINTER_PROTOCOL *AbsolutePointerProtocol;\r
-  EFI_USB_IO_PROTOCOL         *UsbIo;\r
+  EFI_STATUS                      Status;\r
+  USB_MOUSE_ABSOLUTE_POINTER_DEV  *UsbMouseAbsolutePointerDevice;\r
+  EFI_ABSOLUTE_POINTER_PROTOCOL   *AbsolutePointerProtocol;\r
+  EFI_USB_IO_PROTOCOL             *UsbIo;\r
 \r
-  //\r
-  // Get our context back.\r
-  //\r
   Status = gBS->OpenProtocol (\r
-      Controller,\r
-      &gEfiAbsolutePointerProtocolGuid,\r
-      (VOID **) &AbsolutePointerProtocol,\r
-      This->DriverBindingHandle,\r
-      Controller,\r
-      EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
-  );\r
+                  Controller,\r
+                  &gEfiAbsolutePointerProtocolGuid,\r
+                  (VOID **) &AbsolutePointerProtocol,\r
+                  This->DriverBindingHandle,\r
+                  Controller,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
 \r
   if (EFI_ERROR (Status)) {\r
-      return EFI_UNSUPPORTED;\r
+    return EFI_UNSUPPORTED;\r
   }\r
-  UsbMouseAbsolutePointerDevice = USB_MOUSE_ABSOLUTE_POINTER_DEV_FROM_MOUSE_PROTOCOL (AbsolutePointerProtocol);\r
 \r
-  gBS->CloseProtocol (\r
-        Controller,\r
-        &gEfiAbsolutePointerProtocolGuid,\r
-        This->DriverBindingHandle,\r
-        Controller\r
-        );\r
+  UsbMouseAbsolutePointerDevice = USB_MOUSE_ABSOLUTE_POINTER_DEV_FROM_MOUSE_PROTOCOL (AbsolutePointerProtocol);\r
 \r
   UsbIo = UsbMouseAbsolutePointerDevice->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
-  MouseAbsolutePointerReportStatusCode (\r
-    UsbMouseAbsolutePointerDevice->DevicePath,\r
+  REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
     EFI_PROGRESS_CODE,\r
-    PcdGet32 (PcdStatusCodeValueMouseDisable)\r
+    PcdGet32 (PcdStatusCodeValueMouseDisable),\r
+    UsbMouseAbsolutePointerDevice->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
-          UsbMouseAbsolutePointerDevice->IntEndpointDescriptor->EndpointAddress,\r
-          FALSE,\r
-          UsbMouseAbsolutePointerDevice->IntEndpointDescriptor->Interval,\r
-          0,\r
-          NULL,\r
-          NULL\r
-          );\r
-\r
-  gBS->CloseEvent (UsbMouseAbsolutePointerDevice->AbsolutePointerProtocol.WaitForInput);\r
-  \r
-  if (UsbMouseAbsolutePointerDevice->DelayedRecoveryEvent) {\r
-    gBS->CloseEvent (UsbMouseAbsolutePointerDevice->DelayedRecoveryEvent);\r
-    UsbMouseAbsolutePointerDevice->DelayedRecoveryEvent = 0;\r
-  }\r
+           UsbIo,\r
+           UsbMouseAbsolutePointerDevice->IntEndpointDescriptor.EndpointAddress,\r
+           FALSE,\r
+           UsbMouseAbsolutePointerDevice->IntEndpointDescriptor.Interval,\r
+           0,\r
+           NULL,\r
+           NULL\r
+           );\r
 \r
   Status = gBS->UninstallProtocolInterface (\r
                   Controller,\r
@@ -525,20 +428,27 @@ USBMouseAbsolutePointerDriverBindingStop (
   }\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 (UsbMouseAbsolutePointerDevice->InterfaceDescriptor);\r
-  gBS->FreePool (UsbMouseAbsolutePointerDevice->IntEndpointDescriptor);\r
+  //\r
+  // Free all resources.\r
+  //\r
+  gBS->CloseEvent (UsbMouseAbsolutePointerDevice->AbsolutePointerProtocol.WaitForInput);\r
+  \r
+  if (UsbMouseAbsolutePointerDevice->DelayedRecoveryEvent != NULL) {\r
+    gBS->CloseEvent (UsbMouseAbsolutePointerDevice->DelayedRecoveryEvent);\r
+    UsbMouseAbsolutePointerDevice->DelayedRecoveryEvent = NULL;\r
+  }\r
 \r
-  if (UsbMouseAbsolutePointerDevice->ControllerNameTable) {\r
+  if (UsbMouseAbsolutePointerDevice->ControllerNameTable != NULL) {\r
     FreeUnicodeStringTable (UsbMouseAbsolutePointerDevice->ControllerNameTable);\r
   }\r
 \r
-  gBS->FreePool (UsbMouseAbsolutePointerDevice);\r
+  FreePool (UsbMouseAbsolutePointerDevice);\r
 \r
   return EFI_SUCCESS;\r
 \r
@@ -546,16 +456,16 @@ USBMouseAbsolutePointerDriverBindingStop (
 \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
-IsUsbMouseAbsolutePointer (\r
+IsUsbMouse (\r
   IN  EFI_USB_IO_PROTOCOL     *UsbIo\r
   )\r
 {\r
@@ -563,8 +473,7 @@ IsUsbMouseAbsolutePointer (
   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
@@ -579,7 +488,6 @@ IsUsbMouseAbsolutePointer (
       (InterfaceDescriptor.InterfaceSubClass == SUBCLASS_BOOT) &&\r
       (InterfaceDescriptor.InterfaceProtocol == PROTOCOL_MOUSE)\r
       ) {\r
-       \r
     return TRUE;\r
   }\r
 \r
@@ -588,17 +496,22 @@ IsUsbMouseAbsolutePointer (
 \r
 \r
 /**\r
-  Initialize the Usb Mouse Simulate TouchPad Device.\r
+  Initialize the USB mouse device.\r
 \r
-  @param  UsbMouseAbsolutePointerDev           Device instance to be initialized\r
+  This function retrieves and parses HID report descriptor, and\r
+  initializes state of USB_MOUSE_ABSOLUTE_POINTER_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
-  @retval EFI_SUCCESS           Success\r
-  @retval EFI_DEVICE_ERROR      Init error. EFI_OUT_OF_RESOURCES- Can't allocate\r
-                                memory\r
+  @param  UsbMouseAbsolutePointerDev   Device instance to be initialized.\r
+\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
 EFI_STATUS\r
-InitializeUsbMouseAbsolutePointerDevice (\r
+InitializeUsbMouseDevice (\r
   IN  USB_MOUSE_ABSOLUTE_POINTER_DEV           *UsbMouseAbsolutePointerDev\r
   )\r
 {\r
@@ -607,6 +520,8 @@ InitializeUsbMouseAbsolutePointerDevice (
   EFI_STATUS              Status;\r
   EFI_USB_HID_DESCRIPTOR  MouseHidDesc;\r
   UINT8                   *ReportDesc;\r
+  UINT8                   ReportId;\r
+  UINT8                   Duration;\r
 \r
   UsbIo = UsbMouseAbsolutePointerDev->UsbIo;\r
 \r
@@ -614,36 +529,33 @@ InitializeUsbMouseAbsolutePointerDevice (
   // Get HID descriptor\r
   //\r
   Status = UsbGetHidDescriptor (\r
-            UsbIo,\r
-            UsbMouseAbsolutePointerDev->InterfaceDescriptor->InterfaceNumber,\r
-            &MouseHidDesc\r
-            );\r
-\r
+             UsbIo,\r
+             UsbMouseAbsolutePointerDev->InterfaceDescriptor.InterfaceNumber,\r
+             &MouseHidDesc\r
+             );\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
 \r
   //\r
-  // Get Report descriptor\r
+  // Get report descriptor\r
   //\r
-  if (MouseHidDesc.HidClassDesc[0].DescriptorType != 0x22) {\r
+  if (MouseHidDesc.HidClassDesc[0].DescriptorType != USB_DESC_TYPE_REPORT) {\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
+  ASSERT (ReportDesc != NULL);\r
 \r
   Status = UsbGetReportDescriptor (\r
-            UsbIo,\r
-            UsbMouseAbsolutePointerDev->InterfaceDescriptor->InterfaceNumber,\r
-            MouseHidDesc.HidClassDesc[0].DescriptorLength,\r
-            ReportDesc\r
-            );\r
+             UsbIo,\r
+             UsbMouseAbsolutePointerDev->InterfaceDescriptor.InterfaceNumber,\r
+             MouseHidDesc.HidClassDesc[0].DescriptorLength,\r
+             ReportDesc\r
+             );\r
 \r
   if (EFI_ERROR (Status)) {\r
-    gBS->FreePool (ReportDesc);\r
+    FreePool (ReportDesc);\r
     return Status;\r
   }\r
 \r
@@ -651,117 +563,131 @@ InitializeUsbMouseAbsolutePointerDevice (
   // Parse report descriptor\r
   //\r
   Status = ParseMouseReportDescriptor (\r
-            UsbMouseAbsolutePointerDev,\r
-            ReportDesc,\r
-            MouseHidDesc.HidClassDesc[0].DescriptorLength\r
-            );\r
+             UsbMouseAbsolutePointerDev,\r
+             ReportDesc,\r
+             MouseHidDesc.HidClassDesc[0].DescriptorLength\r
+             );\r
 \r
   if (EFI_ERROR (Status)) {\r
-    gBS->FreePool (ReportDesc);\r
+    FreePool (ReportDesc);\r
     return Status;\r
   }\r
 \r
-  UsbMouseAbsolutePointerDev->AbsolutePointerMode.AbsoluteMaxX = 1024;\r
-  UsbMouseAbsolutePointerDev->AbsolutePointerMode.AbsoluteMaxY = 1024;\r
-  UsbMouseAbsolutePointerDev->AbsolutePointerMode.AbsoluteMaxZ = 0;\r
-  UsbMouseAbsolutePointerDev->AbsolutePointerMode.AbsoluteMinX = 0;\r
-  UsbMouseAbsolutePointerDev->AbsolutePointerMode.AbsoluteMinY = 0;\r
-  UsbMouseAbsolutePointerDev->AbsolutePointerMode.AbsoluteMinZ = 0;\r
-  UsbMouseAbsolutePointerDev->AbsolutePointerMode.Attributes   = 0x3;\r
+  UsbMouseAbsolutePointerDev->Mode.AbsoluteMaxX = 1024;\r
+  UsbMouseAbsolutePointerDev->Mode.AbsoluteMaxY = 1024;\r
+  UsbMouseAbsolutePointerDev->Mode.AbsoluteMaxZ = 0;\r
+  UsbMouseAbsolutePointerDev->Mode.AbsoluteMinX = 0;\r
+  UsbMouseAbsolutePointerDev->Mode.AbsoluteMinY = 0;\r
+  UsbMouseAbsolutePointerDev->Mode.AbsoluteMinZ = 0;\r
+  UsbMouseAbsolutePointerDev->Mode.Attributes   = 0x3;\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
+    UsbMouseAbsolutePointerDev->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
+               0,\r
+               BOOT_PROTOCOL\r
+               );\r
 \r
     if (EFI_ERROR (Status)) {\r
-      gBS->FreePool (ReportDesc);\r
-      return EFI_DEVICE_ERROR;\r
+      FreePool (ReportDesc);\r
+      return Status;\r
     }\r
   }\r
 \r
   //\r
-  // Set indefinite Idle rate for USB Mouse\r
+  // ReportId is zero, which means the idle rate applies to all input reports.\r
   //\r
+  ReportId = 0;\r
+  //\r
+  // Duration is zero, which means the duration is infinite.\r
+  // so the endpoint will inhibit reporting forever,\r
+  // and only reporting when a change is detected in the report data.\r
+  //\r
+  Duration = 0;\r
   UsbSetIdleRequest (\r
     UsbIo,\r
-    0,\r
-    0,\r
-    0\r
+    UsbMouseAbsolutePointerDev->InterfaceDescriptor.InterfaceNumber,\r
+    ReportId,\r
+    Duration\r
     );\r
 \r
-  gBS->FreePool (ReportDesc);\r
+  FreePool (ReportDesc);\r
 \r
-  if (UsbMouseAbsolutePointerDev->DelayedRecoveryEvent) {\r
+  //\r
+  // Create event for delayed recovery, which deals with device error.\r
+  //\r
+  if (UsbMouseAbsolutePointerDev->DelayedRecoveryEvent != NULL) {\r
     gBS->CloseEvent (UsbMouseAbsolutePointerDev->DelayedRecoveryEvent);\r
     UsbMouseAbsolutePointerDev->DelayedRecoveryEvent = 0;\r
   }\r
 \r
-  Status = gBS->CreateEvent (\r
-                  EVT_TIMER | EVT_NOTIFY_SIGNAL,\r
-                  TPL_NOTIFY,\r
-                  USBMouseAbsolutePointerRecoveryHandler,\r
-                  UsbMouseAbsolutePointerDev,\r
-                  &UsbMouseAbsolutePointerDev->DelayedRecoveryEvent\r
-                  );\r
+  gBS->CreateEvent (\r
+         EVT_TIMER | EVT_NOTIFY_SIGNAL,\r
+         TPL_NOTIFY,\r
+         USBMouseRecoveryHandler,\r
+         UsbMouseAbsolutePointerDev,\r
+         &UsbMouseAbsolutePointerDev->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
 EFI_STATUS\r
 EFIAPI\r
-OnMouseAbsolutePointerInterruptComplete (\r
+OnMouseInterruptComplete (\r
   IN  VOID        *Data,\r
   IN  UINTN       DataLength,\r
   IN  VOID        *Context,\r
   IN  UINT32      Result\r
   )\r
 {\r
-  USB_MOUSE_ABSOLUTE_POINTER_DEV       *UsbMouseAbsolutePointerDevice;\r
-  EFI_USB_IO_PROTOCOL *UsbIo;\r
-  UINT8               EndpointAddr;\r
-  UINT32              UsbResult;\r
+  USB_MOUSE_ABSOLUTE_POINTER_DEV   *UsbMouseAbsolutePointerDevice;\r
+  EFI_USB_IO_PROTOCOL              *UsbIo;\r
+  UINT8                            EndpointAddr;\r
+  UINT32                           UsbResult;\r
 \r
   UsbMouseAbsolutePointerDevice  = (USB_MOUSE_ABSOLUTE_POINTER_DEV *) Context;\r
-  UsbIo           = UsbMouseAbsolutePointerDevice->UsbIo;\r
+  UsbIo                          = UsbMouseAbsolutePointerDevice->UsbIo;\r
 \r
   if (Result != EFI_USB_NOERROR) {\r
     //\r
     // Some errors happen during the process\r
     //\r
-    MouseAbsolutePointerReportStatusCode (\r
-      UsbMouseAbsolutePointerDevice->DevicePath,\r
+    REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
       EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
-      PcdGet32 (PcdStatusCodeValueMouseInputError)\r
+      PcdGet32 (PcdStatusCodeValueMouseInputError),\r
+      UsbMouseAbsolutePointerDevice->DevicePath\r
       );\r
 \r
     if ((Result & EFI_USB_ERR_STALL) == EFI_USB_ERR_STALL) {\r
-      EndpointAddr = UsbMouseAbsolutePointerDevice->IntEndpointDescriptor->EndpointAddress;\r
+      EndpointAddr = UsbMouseAbsolutePointerDevice->IntEndpointDescriptor.EndpointAddress;\r
 \r
       UsbClearEndpointHalt (\r
         UsbIo,\r
@@ -770,105 +696,134 @@ OnMouseAbsolutePointerInterruptComplete (
         );\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
-            UsbMouseAbsolutePointerDevice->IntEndpointDescriptor->EndpointAddress,\r
-            FALSE,\r
-            0,\r
-            0,\r
-            NULL,\r
-            NULL\r
-            );\r
-\r
+             UsbIo,\r
+             UsbMouseAbsolutePointerDevice->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
-          UsbMouseAbsolutePointerDevice->DelayedRecoveryEvent,\r
-          TimerRelative,\r
-          EFI_USB_INTERRUPT_DELAY\r
-          );\r
+           UsbMouseAbsolutePointerDevice->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
+  UsbMouseAbsolutePointerDevice->StateChanged = TRUE;\r
+\r
   //\r
-  //Check mouse Data\r
+  // Check mouse Data\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
-  UsbMouseAbsolutePointerDevice->AbsolutePointerStateChanged = TRUE;\r
-  UsbMouseAbsolutePointerDevice->AbsolutePointerState.CurrentX += *((INT8 *) Data + 1);\r
-  UsbMouseAbsolutePointerDevice->AbsolutePointerState.CurrentY += *((INT8 *) Data + 2);\r
+  UsbMouseAbsolutePointerDevice->State.CurrentX += *((INT8 *) Data + 1);\r
+  UsbMouseAbsolutePointerDevice->State.CurrentY += *((INT8 *) Data + 2);\r
+  \r
   if (DataLength > 3) {\r
-    UsbMouseAbsolutePointerDevice->AbsolutePointerState.CurrentZ += *((INT8 *) Data + 3);\r
+    UsbMouseAbsolutePointerDevice->State.CurrentZ += *((INT8 *) Data + 3);\r
   }\r
-  UsbMouseAbsolutePointerDevice->AbsolutePointerState.ActiveButtons = *(UINT8 *)Data & 0x3;\r
+  UsbMouseAbsolutePointerDevice->State.ActiveButtons = *(UINT8 *) Data & (BIT0 | BIT1);\r
 \r
   return EFI_SUCCESS;\r
 }\r
 \r
 /**\r
-  Get the mouse state, see ABSOLUTE 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_ABSOLUTE_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 State is NULL.                                                           \r
 \r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 GetMouseAbsolutePointerState (\r
   IN   EFI_ABSOLUTE_POINTER_PROTOCOL  *This,\r
-  OUT  EFI_ABSOLUTE_POINTER_STATE     *MouseAbsolutePointerState\r
+  OUT  EFI_ABSOLUTE_POINTER_STATE     *State\r
   )\r
 {\r
   USB_MOUSE_ABSOLUTE_POINTER_DEV *MouseAbsolutePointerDev;\r
 \r
-  if (MouseAbsolutePointerState == NULL) {\r
-    return EFI_DEVICE_ERROR;\r
+  if (State == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
   }\r
 \r
   MouseAbsolutePointerDev = USB_MOUSE_ABSOLUTE_POINTER_DEV_FROM_MOUSE_PROTOCOL (This);\r
 \r
-  if (!MouseAbsolutePointerDev->AbsolutePointerStateChanged) {\r
+  if (!MouseAbsolutePointerDev->StateChanged) {\r
     return EFI_NOT_READY;\r
   }\r
 \r
+  //\r
+  // Retrieve mouse state from USB_MOUSE_ABSOLUTE_POINTER_DEV,\r
+  // which was filled by OnMouseInterruptComplete()\r
+  //\r
   CopyMem (\r
-    MouseAbsolutePointerState,\r
-    &MouseAbsolutePointerDev->AbsolutePointerState,\r
+    State,\r
+    &MouseAbsolutePointerDev->State,\r
     sizeof (EFI_ABSOLUTE_POINTER_STATE)\r
     );\r
 \r
   //\r
   // Clear previous move state\r
   //\r
-  MouseAbsolutePointerDev->AbsolutePointerState.CurrentX = 0;\r
-  MouseAbsolutePointerDev->AbsolutePointerState.CurrentY = 0;\r
-  MouseAbsolutePointerDev->AbsolutePointerState.CurrentZ = 0;\r
-  MouseAbsolutePointerDev->AbsolutePointerState.ActiveButtons = 0;\r
+  MouseAbsolutePointerDev->State.CurrentX      = 0;\r
+  MouseAbsolutePointerDev->State.CurrentY      = 0;\r
+  MouseAbsolutePointerDev->State.CurrentZ      = 0;\r
+  MouseAbsolutePointerDev->State.ActiveButtons = 0;\r
 \r
-  MouseAbsolutePointerDev->AbsolutePointerStateChanged            = FALSE;\r
+  MouseAbsolutePointerDev->StateChanged = FALSE;\r
 \r
   return EFI_SUCCESS;\r
 }\r
 \r
 \r
 /**\r
-  Reset the mouse device, see ABSOLUTE 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_ABSOLUTE_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
 EFI_STATUS\r
 EFIAPI\r
 UsbMouseAbsolutePointerReset (\r
-  IN EFI_ABSOLUTE_POINTER_PROTOCOL    *This,\r
+  IN EFI_ABSOLUTE_POINTER_PROTOCOL  *This,\r
   IN BOOLEAN                        ExtendedVerification\r
   )\r
 {\r
@@ -876,28 +831,29 @@ UsbMouseAbsolutePointerReset (
 \r
   UsbMouseAbsolutePointerDevice  = USB_MOUSE_ABSOLUTE_POINTER_DEV_FROM_MOUSE_PROTOCOL (This);\r
 \r
-  MouseAbsolutePointerReportStatusCode (\r
-    UsbMouseAbsolutePointerDevice->DevicePath,\r
+  REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
     EFI_PROGRESS_CODE,\r
-    PcdGet32 (PcdStatusCodeValueMouseReset)\r
+    PcdGet32 (PcdStatusCodeValueMouseReset),\r
+    UsbMouseAbsolutePointerDevice->DevicePath\r
     );\r
 \r
+  //\r
+  // Clear mouse state.\r
+  //\r
   ZeroMem (\r
-    &UsbMouseAbsolutePointerDevice->AbsolutePointerState,\r
+    &UsbMouseAbsolutePointerDevice->State,\r
     sizeof (EFI_ABSOLUTE_POINTER_STATE)\r
     );\r
-  UsbMouseAbsolutePointerDevice->AbsolutePointerStateChanged = FALSE;\r
+  UsbMouseAbsolutePointerDevice->StateChanged = FALSE;\r
 \r
   return EFI_SUCCESS;\r
 }\r
 \r
 /**\r
-  Event notification function for ABSOLUTE_POINTER.WaitForInput event\r
-  Signal the event if there is input from mouse\r
+  Event notification function for EFI_ABSOLUTE_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_ABSOLUTE_POINTER_DEV instance.\r
 \r
 **/\r
 VOID\r
@@ -912,68 +868,50 @@ UsbMouseAbsolutePointerWaitForInput (
   UsbMouseAbsolutePointerDev = (USB_MOUSE_ABSOLUTE_POINTER_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 (UsbMouseAbsolutePointerDev->AbsolutePointerStateChanged) {\r
+  if (UsbMouseAbsolutePointerDev->StateChanged) {\r
     gBS->SignalEvent (Event);\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_ABSOLUTE_POINTER_DEV instance.\r
 \r
 **/\r
 VOID\r
 EFIAPI\r
-USBMouseAbsolutePointerRecoveryHandler (\r
+USBMouseRecoveryHandler (\r
   IN    EFI_EVENT    Event,\r
   IN    VOID         *Context\r
   )\r
 {\r
   USB_MOUSE_ABSOLUTE_POINTER_DEV       *UsbMouseAbsolutePointerDev;\r
-  EFI_USB_IO_PROTOCOL *UsbIo;\r
+  EFI_USB_IO_PROTOCOL                  *UsbIo;\r
 \r
   UsbMouseAbsolutePointerDev = (USB_MOUSE_ABSOLUTE_POINTER_DEV *) Context;\r
 \r
   UsbIo       = UsbMouseAbsolutePointerDev->UsbIo;\r
 \r
+  //\r
+  // Re-submit Asynchronous Interrupt Transfer for recovery.\r
+  //\r
   UsbIo->UsbAsyncInterruptTransfer (\r
-          UsbIo,\r
-          UsbMouseAbsolutePointerDev->IntEndpointDescriptor->EndpointAddress,\r
-          TRUE,\r
-          UsbMouseAbsolutePointerDev->IntEndpointDescriptor->Interval,\r
-          UsbMouseAbsolutePointerDev->IntEndpointDescriptor->MaxPacketSize,\r
-          OnMouseAbsolutePointerInterruptComplete,\r
-          UsbMouseAbsolutePointerDev\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
-MouseAbsolutePointerReportStatusCode (\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
+           UsbMouseAbsolutePointerDev->IntEndpointDescriptor.EndpointAddress,\r
+           TRUE,\r
+           UsbMouseAbsolutePointerDev->IntEndpointDescriptor.Interval,\r
+           UsbMouseAbsolutePointerDev->IntEndpointDescriptor.MaxPacketSize,\r
+           OnMouseInterruptComplete,\r
+           UsbMouseAbsolutePointerDev\r
+           );\r
 }\r
index eea4ad5a58c3250f1b702c713e014c8d92c3967b..976dd54c46920e904a42b3211390a083642f947f 100644 (file)
@@ -1,6 +1,7 @@
 /** @file\r
+  Helper routine and corresponding data struct used by USB Mouse Absolute Pointer Driver.\r
 \r
-Copyright (c) 2004 - 2007, Intel Corporation\r
+Copyright (c) 2004 - 2008, 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
@@ -9,17 +10,10 @@ http://opensource.org/licenses/bsd-license.php
 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
-    UsbMouseAbsolutePointer.h\r
-\r
-  Abstract:\r
-\r
-\r
 **/\r
 \r
-#ifndef _USB_MOUSE_ABSOLUTE_POINTER_H\r
-#define _USB_MOUSE_ABSOLUTE_POINTER_H\r
+#ifndef _USB_MOUSE_ABSOLUTE_POINTER_H_\r
+#define _USB_MOUSE_ABSOLUTE_POINTER_H_\r
 \r
 \r
 #include <Uefi.h>\r
@@ -33,10 +27,10 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Library/UefiDriverEntryPoint.h>\r
 #include <Library/UefiBootServicesTableLib.h>\r
 #include <Library/UefiLib.h>\r
-#include <Library/BaseLib.h>\r
 #include <Library/MemoryAllocationLib.h>\r
 #include <Library/PcdLib.h>\r
 #include <Library/UefiUsbLib.h>\r
+#include <Library/DebugLib.h>\r
 \r
 #include <IndustryStandard/Usb.h>\r
 \r
@@ -49,71 +43,83 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #define USB_MOUSE_ABSOLUTE_POINTER_DEV_SIGNATURE SIGNATURE_32 ('u', 'm', 's', 't')\r
 \r
+///\r
+/// Button range and status\r
+///\r
 typedef struct {\r
   BOOLEAN ButtonDetected;\r
   UINT8   ButtonMinIndex;\r
   UINT8   ButtonMaxIndex;\r
   UINT8   Reserved;\r
-} PRIVATE_DATA;\r
+} USB_MOUSE_BUTTON_DATA;\r
 \r
+///\r
+/// Device instance of USB mouse.\r
+///\r
 typedef struct {\r
   UINTN                         Signature;\r
   EFI_DEVICE_PATH_PROTOCOL      *DevicePath;\r
   EFI_EVENT                     DelayedRecoveryEvent;\r
   EFI_USB_IO_PROTOCOL           *UsbIo;\r
-  EFI_USB_INTERFACE_DESCRIPTOR  *InterfaceDescriptor;\r
-  EFI_USB_ENDPOINT_DESCRIPTOR   *IntEndpointDescriptor;\r
+  EFI_USB_INTERFACE_DESCRIPTOR  InterfaceDescriptor;\r
+  EFI_USB_ENDPOINT_DESCRIPTOR   IntEndpointDescriptor;\r
   UINT8                         NumberOfButtons;\r
   INT32                         XLogicMax;\r
   INT32                         XLogicMin;\r
   INT32                         YLogicMax;\r
   INT32                         YLogicMin;\r
-\r
   EFI_ABSOLUTE_POINTER_PROTOCOL AbsolutePointerProtocol;\r
-  EFI_ABSOLUTE_POINTER_STATE   AbsolutePointerState;\r
-  EFI_ABSOLUTE_POINTER_MODE            AbsolutePointerMode;\r
-  BOOLEAN                                              AbsolutePointerStateChanged;\r
-\r
-  PRIVATE_DATA                  PrivateData;\r
+  EFI_ABSOLUTE_POINTER_STATE    State;\r
+  EFI_ABSOLUTE_POINTER_MODE     Mode;\r
+  BOOLEAN                       StateChanged;\r
+  USB_MOUSE_BUTTON_DATA         PrivateData;\r
   EFI_UNICODE_STRING_TABLE      *ControllerNameTable;\r
 } USB_MOUSE_ABSOLUTE_POINTER_DEV;\r
 \r
+///\r
+/// General HID Item structure\r
+///\r
+typedef struct {\r
+  UINT16  Format;\r
+  UINT8   Size;\r
+  UINT8   Type;\r
+  UINT8   Tag;\r
+  union {\r
+    UINT8   U8;\r
+    UINT16  U16;\r
+    UINT32  U32;\r
+    INT8    I8;\r
+    INT16   I16;\r
+    INT32   I32;\r
+    UINT8   *LongData;\r
+  } Data;\r
+} HID_ITEM;\r
+\r
 #define USB_MOUSE_ABSOLUTE_POINTER_DEV_FROM_MOUSE_PROTOCOL(a) \\r
     CR(a, USB_MOUSE_ABSOLUTE_POINTER_DEV, AbsolutePointerProtocol, USB_MOUSE_ABSOLUTE_POINTER_DEV_SIGNATURE)\r
 \r
-VOID\r
-EFIAPI\r
-USBMouseAbsolutePointerRecoveryHandler (\r
-  IN    EFI_EVENT    Event,\r
-  IN    VOID         *Context\r
-  );\r
-\r
 //\r
 // Global Variables\r
 //\r
 extern EFI_DRIVER_BINDING_PROTOCOL   gUsbMouseAbsolutePointerDriverBinding;\r
 extern EFI_COMPONENT_NAME_PROTOCOL   gUsbMouseAbsolutePointerComponentName;\r
 extern EFI_COMPONENT_NAME2_PROTOCOL  gUsbMouseAbsolutePointerComponentName2;\r
-extern EFI_GUID                      gEfiUsbMouseAbsolutePointerDriverGuid;\r
-\r
-VOID\r
-MouseAbsolutePointerReportStatusCode (\r
-  IN EFI_DEVICE_PATH_PROTOCOL  *DevicePath,\r
-  IN EFI_STATUS_CODE_TYPE      CodeType,\r
-  IN EFI_STATUS_CODE_VALUE     Value\r
-  );\r
 \r
 //\r
-// Prototypes\r
-// Driver model protocol interface\r
+// Functions of Driver Binding Protocol\r
 //\r
-EFI_STATUS\r
-EFIAPI\r
-USBMouseAbsolutePointerDriverBindingEntryPoint (\r
-  IN EFI_HANDLE           ImageHandle,\r
-  IN EFI_SYSTEM_TABLE     *SystemTable\r
-  );\r
 \r
+/**\r
+  Check whether USB Mouse Absolute Pointer Driver supports this device.\r
+\r
+  @param  This                   The driver binding protocol.\r
+  @param  Controller             The controller handle to check.\r
+  @param  RemainingDevicePath    The remaining device path.\r
+\r
+  @retval EFI_SUCCESS            The driver supports this controller.\r
+  @retval other                  This device isn't supported.\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 USBMouseAbsolutePointerDriverBindingSupported (\r
@@ -122,6 +128,25 @@ USBMouseAbsolutePointerDriverBindingSupported (
   IN EFI_DEVICE_PATH_PROTOCOL       *RemainingDevicePath\r
   );\r
 \r
+/**\r
+  Starts the mouse device with this driver.\r
+\r
+  This function consumes USB I/O Portocol, intializes USB mouse device,\r
+  installs Absolute Pointer Protocol, and submits Asynchronous Interrupt\r
+  Transfer to manage the USB mouse device.\r
+\r
+  @param  This                  The 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
+  @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
 EFIAPI\r
 USBMouseAbsolutePointerDriverBindingStart (\r
@@ -130,6 +155,19 @@ USBMouseAbsolutePointerDriverBindingStart (
   IN EFI_DEVICE_PATH_PROTOCOL       *RemainingDevicePath\r
   );\r
 \r
+/**\r
+  Stop the USB mouse device handled by this driver.\r
+\r
+  @param  This                   The 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
+  @retval EFI_SUCCESS            The device was stopped.\r
+  @retval EFI_UNSUPPORTED        Absolute Pointer Protocol is not installed on Controller.\r
+  @retval Others                 Fail to uninstall protocols attached on the device.\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 USBMouseAbsolutePointerDriverBindingStop (\r
@@ -139,5 +177,282 @@ USBMouseAbsolutePointerDriverBindingStop (
   IN  EFI_HANDLE                    *ChildHandleBuffer\r
   );\r
 \r
+//\r
+// EFI Component Name Functions\r
+//\r
+\r
+/**\r
+  Retrieves a Unicode string that is the user readable name of the driver.\r
+\r
+  This function retrieves the user readable name of a driver in the form of a\r
+  Unicode string. If the driver specified by This has a user readable name in\r
+  the language specified by Language, then a pointer to the driver name is\r
+  returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r
+  by This does not support the language specified by Language,\r
+  then EFI_UNSUPPORTED is returned.\r
+\r
+  @param  This                  A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
+                                EFI_COMPONENT_NAME_PROTOCOL instance.\r
+  @param  Language              A pointer to a Null-terminated ASCII string\r
+                                array indicating the language. This is the\r
+                                language of the driver name that the caller is\r
+                                requesting, and it must match one of the\r
+                                languages specified in SupportedLanguages. The\r
+                                number of languages supported by a driver is up\r
+                                to the driver writer. Language is specified\r
+                                in RFC 3066 or ISO 639-2 language code format.\r
+  @param  DriverName            A pointer to the Unicode string to return.\r
+                                This Unicode string is the name of the\r
+                                driver specified by This in the language\r
+                                specified by Language.\r
+\r
+  @retval EFI_SUCCESS           The Unicode string for the Driver specified by\r
+                                This and the language specified by Language was\r
+                                returned in DriverName.\r
+  @retval EFI_INVALID_PARAMETER Language is NULL.\r
+  @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
+  @retval EFI_UNSUPPORTED       The driver specified by This does not support\r
+                                the language specified by Language.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+UsbMouseAbsolutePointerComponentNameGetDriverName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  );\r
+\r
+/**\r
+  Retrieves a Unicode string that is the user readable name of the controller\r
+  that is being managed by a driver.\r
+\r
+  This function retrieves the user readable name of the controller specified by\r
+  ControllerHandle and ChildHandle in the form of a Unicode string. If the\r
+  driver specified by This has a user readable name in the language specified by\r
+  Language, then a pointer to the controller name is returned in ControllerName,\r
+  and EFI_SUCCESS is returned.  If the driver specified by This is not currently\r
+  managing the controller specified by ControllerHandle and ChildHandle,\r
+  then EFI_UNSUPPORTED is returned.  If the driver specified by This does not\r
+  support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
+\r
+  @param  This                  A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
+                                EFI_COMPONENT_NAME_PROTOCOL instance.\r
+  @param  ControllerHandle      The handle of a controller that the driver\r
+                                specified by This is managing.  This handle\r
+                                specifies the controller whose name is to be\r
+                                returned.\r
+  @param  ChildHandle           The handle of the child controller to retrieve\r
+                                the name of.  This is an optional parameter that\r
+                                may be NULL.  It will be NULL for device\r
+                                drivers.  It will also be NULL for a bus drivers\r
+                                that wish to retrieve the name of the bus\r
+                                controller.  It will not be NULL for a bus\r
+                                driver that wishes to retrieve the name of a\r
+                                child controller.\r
+  @param  Language              A pointer to a Null-terminated ASCII string\r
+                                array indicating the language.  This is the\r
+                                language of the driver name that the caller is\r
+                                requesting, and it must match one of the\r
+                                languages specified in SupportedLanguages. The\r
+                                number of languages supported by a driver is up\r
+                                to the driver writer. Language is specified in\r
+                                RFC 3066 or ISO 639-2 language code format.\r
+  @param  ControllerName        A pointer to the Unicode string to return.\r
+                                This Unicode string is the name of the\r
+                                controller specified by ControllerHandle and\r
+                                ChildHandle in the language specified by\r
+                                Language from the point of view of the driver\r
+                                specified by This.\r
+\r
+  @retval EFI_SUCCESS           The Unicode string for the user readable name in\r
+                                the language specified by Language for the\r
+                                driver specified by This was returned in\r
+                                DriverName.\r
+  @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.\r
+  @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r
+                                EFI_HANDLE.\r
+  @retval EFI_INVALID_PARAMETER Language is NULL.\r
+  @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
+  @retval EFI_UNSUPPORTED       The driver specified by This is not currently\r
+                                managing the controller specified by\r
+                                ControllerHandle and ChildHandle.\r
+  @retval EFI_UNSUPPORTED       The driver specified by This does not support\r
+                                the language specified by Language.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+UsbMouseAbsolutePointerComponentNameGetControllerName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,\r
+  IN  EFI_HANDLE                                      ControllerHandle,\r
+  IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,\r
+  IN  CHAR8                                           *Language,\r
+  OUT CHAR16                                          **ControllerName\r
+  );\r
+\r
+//\r
+// Functions of EFI_ABSOLUTE_POINTER_PROTOCOL\r
+//\r
+\r
+/**\r
+  Retrieves the current state of a pointer device.\r
+\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
+  @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
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+GetMouseAbsolutePointerState (\r
+  IN   EFI_ABSOLUTE_POINTER_PROTOCOL  *This,\r
+  OUT  EFI_ABSOLUTE_POINTER_STATE     *State\r
+  );\r
+\r
+/**\r
+  Resets the pointer device hardware.\r
+\r
+  @param  This                  A pointer to the EFI_ABSOLUTE_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
+  @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
+EFI_STATUS\r
+EFIAPI\r
+UsbMouseAbsolutePointerReset (\r
+  IN EFI_ABSOLUTE_POINTER_PROTOCOL  *This,\r
+  IN BOOLEAN                        ExtendedVerification\r
+  );\r
+\r
+/**\r
+  Event notification function for EFI_ABSOLUTE_POINTER_PROTOCOL.WaitForInput event.\r
+\r
+  @param  Event        Event to be signaled when there's input from mouse.\r
+  @param  Context      Points to USB_MOUSE_ABSOLUTE_POINTER_DEV instance.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+UsbMouseAbsolutePointerWaitForInput (\r
+  IN  EFI_EVENT               Event,\r
+  IN  VOID                    *Context\r
+  );\r
+\r
+//\r
+// Internal worker functions\r
+//\r
+\r
+/**\r
+  Uses USB I/O to check whether the device is a USB mouse device.\r
+\r
+  @param  UsbIo    Pointer to a USB I/O protocol instance.\r
+\r
+  @retval TRUE     Device is a USB mouse device.\r
+  @retval FALSE    Device is a not USB mouse device.\r
+\r
+**/\r
+BOOLEAN\r
+IsUsbMouse (\r
+  IN  EFI_USB_IO_PROTOCOL     *UsbIo\r
+  );\r
+\r
+/**\r
+  Initialize the USB mouse device.\r
+\r
+  This function retrieves and parses HID report descriptor, and\r
+  initializes state of USB_MOUSE_ABSOLUTE_POINTER_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  UsbMouseAbsolutePointerDev   Device instance to be initialized.\r
+\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
+EFI_STATUS\r
+InitializeUsbMouseDevice (\r
+  IN  USB_MOUSE_ABSOLUTE_POINTER_DEV           *UsbMouseAbsolutePointerDev\r
+  );\r
+\r
+/**\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             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
+  @retval EFI_SUCCESS      Asynchronous interrupt transfer is handled successfully.\r
+  @retval EFI_DEVICE_ERROR Hardware error occurs.\r
+\r
+**/\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
+  Handler for Delayed Recovery event.\r
+\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_ABSOLUTE_POINTER_DEV instance.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+USBMouseRecoveryHandler (\r
+  IN    EFI_EVENT    Event,\r
+  IN    VOID         *Context\r
+  );\r
+\r
+/**\r
+  Parse Mouse Report Descriptor.\r
+\r
+  According to USB HID Specification, report descriptors are\r
+  composed of pieces of information. Each piece of information\r
+  is called an Item. This function retrieves each item from\r
+  the report descriptor and updates USB_MOUSE_ABSOLUTE_POINTER_DEV.\r
+\r
+  @param  UsbMouseAbsolutePointer  The instance of USB_MOUSE_ABSOLUTE_POINTER_DEV\r
+  @param  ReportDescriptor         Report descriptor to parse\r
+  @param  ReportSize               Report descriptor size\r
+\r
+  @retval EFI_SUCCESS              Report descriptor successfully parsed.\r
+  @retval EFI_UNSUPPORTED          Report descriptor contains long item.\r
+\r
+**/\r
+EFI_STATUS\r
+ParseMouseReportDescriptor (\r
+  OUT USB_MOUSE_ABSOLUTE_POINTER_DEV   *UsbMouseAbsolutePointer,\r
+  IN  UINT8                            *ReportDescriptor,\r
+  IN  UINTN                            ReportSize\r
+  );\r
 \r
 #endif\r
index 7b85bf0dea609bc6a44e302a7bd26458bb80e872..f574b03c161cde0bb33ee0632b78ff1954686096 100644 (file)
@@ -1,8 +1,7 @@
 #/** @file\r
-# Component name for module UsbMouseAbsolutePointerDxe\r
+# USB Mouse Driver that manages USB mouse and produces Absolute Pointer Protocol.\r
 #\r
-# FIX ME!\r
-# Copyright (c) 2006, Intel Corporation. \r
+# Copyright (c) 2006 - 2008, Intel Corporation. \r
 #\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
 #  COMPONENT_NAME                =  gUsbMouseAbsolutePointerComponentName\r
 #  COMPONENT_NAME2               =  gUsbMouseAbsolutePointerComponentName2\r
 #\r
+\r
 [Sources.common]\r
-  mousehid.h\r
   ComponentName.c\r
+  MouseHid.c\r
   UsbMouseAbsolutePointer.c\r
-  mousehid.c\r
   UsbMouseAbsolutePointer.h\r
 \r
 [Packages]\r
@@ -54,9 +53,9 @@
   UefiUsbLib\r
 \r
 [Protocols]\r
-  gEfiUsbIoProtocolGuid                         # PROTOCOL ALWAYS_CONSUMED\r
-  gEfiDevicePathProtocolGuid                    # PROTOCOL ALWAYS_CONSUMED\r
-  gEfiAbsolutePointerProtocolGuid               # PROTOCOL ALWAYS_CONSUMED\r
+  gEfiUsbIoProtocolGuid                         # PROTOCOL TO_START\r
+  gEfiDevicePathProtocolGuid                    # PROTOCOL TO_START\r
+  gEfiAbsolutePointerProtocolGuid               # PROTOCOL BY_START\r
 \r
 [FixedPcd]\r
   gEfiMdePkgTokenSpaceGuid.PcdStatusCodeValueMouseInterfaceError\r
index 21b8d05aa8fdceb8834773ab92497f92f79a2c74..e0112dd427f6bba62bdd88651f6ccb27eb1a9c4c 100644 (file)
@@ -1,6 +1,7 @@
 /** @file\r
+  Helper functions to parse HID report descriptor and items.\r
 \r
-Copyright (c) 2004, Intel Corporation\r
+Copyright (c) 2004 - 2008, 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
@@ -9,35 +10,33 @@ http://opensource.org/licenses/bsd-license.php
 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
-  Mousehid.c\r
-\r
-Abstract:\r
-  Parse mouse hid descriptor\r
-\r
-\r
 **/\r
 \r
-#include "mousehid.h"\r
-\r
+#include "UsbMouseAbsolutePointer.h"\r
 \r
-//\r
-// Get an item from report descriptor\r
-//\r
 \r
 /**\r
-  Get Next Item\r
+  Get next HID item from report descriptor.\r
+\r
+  This function retrieves next HID item from report descriptor, according to\r
+  the start position.\r
+  According to USB HID Specification, An item is piece of information\r
+  about the device. All items have a one-byte prefix that contains\r
+  the item tag, item type, and item size.\r
+  There are two basic types of items: short items and long items.\r
+  If the item is a short item, its optional data size may be 0, 1, 2, or 4 bytes.\r
+  Only short item is supported here.\r
 \r
-  @param  StartPos          Start Position\r
-  @param  EndPos            End Position\r
-  @param  HidItem           HidItem to return\r
+  @param  StartPos          Start position of the HID item to get.\r
+  @param  EndPos            End position of the range to get the the next HID item.\r
+  @param  HidItem           Buffer for the HID Item to return.\r
 \r
-  @return Position\r
+  @return Pointer to end of the HID item returned.\r
+          NULL if no HID item retrieved.\r
 \r
 **/\r
 UINT8 *\r
-GetNextItem (\r
+GetNextHidItem (\r
   IN  UINT8    *StartPos,\r
   IN  UINT8    *EndPos,\r
   OUT HID_ITEM *HidItem\r
@@ -45,25 +44,25 @@ GetNextItem (
 {\r
   UINT8 Temp;\r
 \r
-  if ((EndPos - StartPos) <= 0) {\r
+  if (EndPos <= StartPos) {\r
     return NULL;\r
   }\r
 \r
   Temp = *StartPos;\r
   StartPos++;\r
+\r
   //\r
-  // bit 2,3\r
-  //\r
-  HidItem->Type = (UINT8) ((Temp >> 2) & 0x03);\r
-  //\r
-  // bit 4-7\r
+  // Bit format of prefix byte:\r
+  // Bits 0-1: Size\r
+  // Bits 2-3: Type\r
+  // Bits 4-7: Tag\r
   //\r
-  HidItem->Tag = (UINT8) ((Temp >> 4) & 0x0F);\r
+  HidItem->Type = BitFieldRead8 (Temp, 2, 3);\r
+  HidItem->Tag  = BitFieldRead8 (Temp, 4, 7);\r
 \r
   if (HidItem->Tag == HID_ITEM_TAG_LONG) {\r
     //\r
-    // Long Items are not supported by HID rev1.0,\r
-    // although we try to parse it.\r
+    // Long Items are not supported, although we try to parse it.\r
     //\r
     HidItem->Format = HID_ITEM_FORMAT_LONG;\r
 \r
@@ -79,12 +78,9 @@ GetNextItem (
     }\r
   } else {\r
     HidItem->Format = HID_ITEM_FORMAT_SHORT;\r
-    //\r
-    // bit 0, 1\r
-    //\r
-    HidItem->Size   = (UINT8) (Temp & 0x03);\r
-    switch (HidItem->Size) {\r
+    HidItem->Size   = BitFieldRead8 (Temp, 0, 1);\r
 \r
+    switch (HidItem->Size) {\r
     case 0:\r
       //\r
       // No data\r
@@ -93,7 +89,7 @@ GetNextItem (
 \r
     case 1:\r
       //\r
-      // One byte data\r
+      // 1-byte data\r
       //\r
       if ((EndPos - StartPos) >= 1) {\r
         HidItem->Data.U8 = *StartPos++;\r
@@ -102,7 +98,7 @@ GetNextItem (
 \r
     case 2:\r
       //\r
-      // Two byte data\r
+      // 2-byte data\r
       //\r
       if ((EndPos - StartPos) >= 2) {\r
         CopyMem (&HidItem->Data.U16, StartPos, sizeof (UINT16));\r
@@ -112,9 +108,9 @@ GetNextItem (
 \r
     case 3:\r
       //\r
-      // 4 byte data, adjust size\r
+      // 4-byte data, adjust size\r
       //\r
-      HidItem->Size++;\r
+      HidItem->Size = 4;\r
       if ((EndPos - StartPos) >= 4) {\r
         CopyMem (&HidItem->Data.U32, StartPos, sizeof (UINT32));\r
         StartPos += 4;\r
@@ -128,11 +124,15 @@ GetNextItem (
 \r
 \r
 /**\r
-  Get Item Data\r
+  Get data from HID item.\r
+\r
+  This function retrieves data from HID item.\r
+  It only supports short items, which has 4 types of data:\r
+  0, 1, 2, or 4 bytes.\r
 \r
-  @param  HidItem           HID_ITEM\r
+  @param  HidItem       Pointer to the HID item.\r
 \r
-  @return HidItem Data\r
+  @return The data of HID item.\r
 \r
 **/\r
 UINT32\r
@@ -141,216 +141,141 @@ GetItemData (
   )\r
 {\r
   //\r
-  // Get Data from HID_ITEM structure\r
+  // Get data from HID item.\r
   //\r
   switch (HidItem->Size) {\r
-\r
   case 1:\r
     return HidItem->Data.U8;\r
-\r
   case 2:\r
     return HidItem->Data.U16;\r
-\r
   case 4:\r
     return HidItem->Data.U32;\r
   }\r
-\r
   return 0;\r
 }\r
 \r
-\r
 /**\r
-  Parse Local Item\r
+  Parse HID item from report descriptor.\r
 \r
-  @param  UsbMouseAbsolutePointer          USB_MOUSE_ABSOLUTE_POINTER_DEV\r
-  @param  LocalItem         Local Item\r
+  There are three item types: Main, Global, and Local.\r
+  This function parses these types of HID items according\r
+  to tag info.\r
 \r
+  @param  UsbMouse          The instance of USB_MOUSE_ABSOLUTE_POINTER_DEV\r
+  @param  HidItem           The HID item to parse\r
 \r
 **/\r
 VOID\r
-ParseLocalItem (\r
-  IN  USB_MOUSE_ABSOLUTE_POINTER_DEV   *UsbMouseAbsolutePointer,\r
-  IN  HID_ITEM        *LocalItem\r
+ParseHidItem (\r
+  IN  USB_MOUSE_ABSOLUTE_POINTER_DEV   *UsbMouse,\r
+  IN  HID_ITEM                         *HidItem\r
   )\r
 {\r
-  UINT32  Data;\r
+  UINT8  Data;\r
 \r
-  if (LocalItem->Size == 0) {\r
+  switch (HidItem->Type) {\r
+\r
+  case HID_ITEM_TYPE_MAIN:\r
     //\r
-    // No expected data for local item\r
+    // we don't care any main items, just skip\r
     //\r
     return ;\r
-  }\r
-\r
-  Data = GetItemData (LocalItem);\r
 \r
-  switch (LocalItem->Tag) {\r
+  case HID_ITEM_TYPE_GLOBAL:\r
+    //\r
+    // For global items, we only care Usage Page tag for Button Page here\r
+    //\r
+    if (HidItem->Tag == HID_GLOBAL_ITEM_TAG_USAGE_PAGE) {\r
+      Data = (UINT8) GetItemData (HidItem);\r
+      if (Data == 0x09) {\r
+        //\r
+        // Button Page\r
+        //\r
+        UsbMouse->PrivateData.ButtonDetected = TRUE;\r
+      }\r
+  }\r
+    return;\r
 \r
-  case HID_LOCAL_ITEM_TAG_DELIMITER:\r
+  case HID_ITEM_TYPE_LOCAL:\r
+    if (HidItem->Size == 0) {\r
     //\r
-    // we don't support delimiter here\r
+      // No expected data for local item\r
     //\r
     return ;\r
+    }\r
 \r
-  case HID_LOCAL_ITEM_TAG_USAGE:\r
-    return ;\r
+    Data = (UINT8) GetItemData (HidItem);\r
 \r
-  case HID_LOCAL_ITEM_TAG_USAGE_MINIMUM:\r
-    if (UsbMouseAbsolutePointer->PrivateData.ButtonDetected) {\r
-      UsbMouseAbsolutePointer->PrivateData.ButtonMinIndex = (UINT8) Data;\r
+    switch (HidItem->Tag) {\r
+    case HID_LOCAL_ITEM_TAG_USAGE_MINIMUM:\r
+      if (UsbMouse->PrivateData.ButtonDetected) {\r
+        UsbMouse->PrivateData.ButtonMinIndex = Data;\r
     }\r
-\r
     return ;\r
 \r
-  case HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM:\r
+    case HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM:\r
     {\r
-      if (UsbMouseAbsolutePointer->PrivateData.ButtonDetected) {\r
-        UsbMouseAbsolutePointer->PrivateData.ButtonMaxIndex = (UINT8) Data;\r
+      if (UsbMouse->PrivateData.ButtonDetected) {\r
+        UsbMouse->PrivateData.ButtonMaxIndex = Data;\r
       }\r
-\r
       return ;\r
     }\r
-  }\r
-}\r
-\r
-VOID\r
-ParseGlobalItem (\r
-  IN  USB_MOUSE_ABSOLUTE_POINTER_DEV   *UsbMouseAbsolutePointer,\r
-  IN  HID_ITEM        *GlobalItem\r
-  )\r
-{\r
-  UINT8 UsagePage;\r
-\r
-  switch (GlobalItem->Tag) {\r
-  case HID_GLOBAL_ITEM_TAG_USAGE_PAGE:\r
-    {\r
-      UsagePage = (UINT8) GetItemData (GlobalItem);\r
 \r
-      //\r
-      // We only care Button Page here\r
-      //\r
-      if (UsagePage == 0x09) {\r
-        //\r
-        // Button Page\r
-        //\r
-        UsbMouseAbsolutePointer->PrivateData.ButtonDetected = TRUE;\r
+    default:\r
         return ;\r
       }\r
-      break;\r
-    }\r
-\r
   }\r
 }\r
 \r
 \r
-\r
 /**\r
-  Parse Main Item\r
-\r
-  @param  UsbMouseAbsolutePointer   USB_MOUSE_ABSOLUTE_POINTER_DEV\r
-  @param  MainItem          HID_ITEM to parse\r
-\r
-  @return VOID\r
-\r
-**/\r
-VOID\r
-ParseMainItem (\r
-  IN  USB_MOUSE_ABSOLUTE_POINTER_DEV   *UsbMouseAbsolutePointer,\r
-  IN  HID_ITEM        *MainItem\r
-  )\r
-{\r
-  //\r
-  // we don't care any main items, just skip\r
-  //\r
-  return ;\r
-}\r
-\r
-\r
-/**\r
-  Parse Hid Item\r
-\r
-  @param  UsbMouseAbsolutePointer          USB_MOUSE_ABSOLUTE_POINTER_DEV\r
-  @param  HidItem           HidItem to parse\r
-\r
-  @return VOID\r
+  Parse Mouse Report Descriptor.\r
 \r
-**/\r
-VOID\r
-ParseHidItem (\r
-  IN  USB_MOUSE_ABSOLUTE_POINTER_DEV   *UsbMouseAbsolutePointer,\r
-  IN  HID_ITEM        *HidItem\r
-  )\r
-{\r
-  switch (HidItem->Type) {\r
+  According to USB HID Specification, report descriptors are\r
+  composed of pieces of information. Each piece of information\r
+  is called an Item. This function retrieves each item from\r
+  the report descriptor and updates USB_MOUSE_ABSOLUTE_POINTER_DEV.\r
 \r
-  case HID_ITEM_TYPE_MAIN:\r
-    //\r
-    // For Main Item, parse main item\r
-    //\r
-    ParseMainItem (UsbMouseAbsolutePointer, HidItem);\r
-    break;\r
+  @param  UsbMouseAbsolutePointer  The instance of USB_MOUSE_ABSOLUTE_POINTER_DEV\r
+  @param  ReportDescriptor         Report descriptor to parse\r
+  @param  ReportSize               Report descriptor size\r
 \r
-  case HID_ITEM_TYPE_GLOBAL:\r
-    //\r
-    // For global Item, parse global item\r
-    //\r
-    ParseGlobalItem (UsbMouseAbsolutePointer, HidItem);\r
-    break;\r
-\r
-  case HID_ITEM_TYPE_LOCAL:\r
-    //\r
-    // For Local Item, parse local item\r
-    //\r
-    ParseLocalItem (UsbMouseAbsolutePointer, HidItem);\r
-    break;\r
-  }\r
-}\r
-//\r
-// A simple parse just read some field we are interested in\r
-//\r
-\r
-/**\r
-  Parse Mouse Report Descriptor\r
-\r
-  @param  UsbMouse          USB_MOUSE_DEV\r
-  @param  ReportDescriptor  Report descriptor to parse\r
-  @param  ReportSize        Report descriptor size\r
-\r
-  @retval EFI_DEVICE_ERROR  Report descriptor error\r
-  @retval EFI_SUCCESS       Success\r
+  @retval EFI_SUCCESS              Report descriptor successfully parsed.\r
+  @retval EFI_UNSUPPORTED          Report descriptor contains long item.\r
 \r
 **/\r
 EFI_STATUS\r
 ParseMouseReportDescriptor (\r
-  IN  USB_MOUSE_ABSOLUTE_POINTER_DEV   *UsbMouseAbsolutePointer,\r
-  IN  UINT8           *ReportDescriptor,\r
-  IN  UINTN           ReportSize\r
+  OUT USB_MOUSE_ABSOLUTE_POINTER_DEV   *UsbMouseAbsolutePointer,\r
+  IN  UINT8                            *ReportDescriptor,\r
+  IN  UINTN                            ReportSize\r
   )\r
 {\r
   UINT8     *DescriptorEnd;\r
-  UINT8     *ptr;\r
+  UINT8     *Ptr;\r
   HID_ITEM  HidItem;\r
 \r
   DescriptorEnd = ReportDescriptor + ReportSize;\r
 \r
-  ptr           = GetNextItem (ReportDescriptor, DescriptorEnd, &HidItem);\r
-\r
-  while (ptr != NULL) {\r
+  Ptr = GetNextHidItem (ReportDescriptor, DescriptorEnd, &HidItem);\r
+  while (Ptr != NULL) {\r
     if (HidItem.Format != HID_ITEM_FORMAT_SHORT) {\r
       //\r
-      // Long Format Item is not supported at current HID revision\r
+      // Long Item is not supported at current HID revision\r
       //\r
-      return EFI_DEVICE_ERROR;\r
+      return EFI_UNSUPPORTED;\r
     }\r
 \r
     ParseHidItem (UsbMouseAbsolutePointer, &HidItem);\r
 \r
-    ptr = GetNextItem (ptr, DescriptorEnd, &HidItem);\r
+    Ptr = GetNextHidItem (Ptr, DescriptorEnd, &HidItem);\r
   }\r
 \r
-  UsbMouseAbsolutePointer->NumberOfButtons                 = (UINT8) (UsbMouseAbsolutePointer->PrivateData.ButtonMaxIndex - UsbMouseAbsolutePointer->PrivateData.ButtonMinIndex + 1);\r
-  UsbMouseAbsolutePointer->XLogicMax                       = UsbMouseAbsolutePointer->YLogicMax = 1023;\r
-  UsbMouseAbsolutePointer->XLogicMin                       = UsbMouseAbsolutePointer->YLogicMin = -1023;\r
+  UsbMouseAbsolutePointer->NumberOfButtons = (UINT8) (UsbMouseAbsolutePointer->PrivateData.ButtonMaxIndex - UsbMouseAbsolutePointer->PrivateData.ButtonMinIndex + 1);\r
+  UsbMouseAbsolutePointer->XLogicMax = 1023;\r
+  UsbMouseAbsolutePointer->YLogicMax = 1023;\r
+  UsbMouseAbsolutePointer->XLogicMin = -1023;\r
+  UsbMouseAbsolutePointer->YLogicMin = -1023;\r
 \r
   return EFI_SUCCESS;\r
 }\r
diff --git a/MdeModulePkg/Bus/Usb/UsbMouseAbsolutePointerDxe/mousehid.h b/MdeModulePkg/Bus/Usb/UsbMouseAbsolutePointerDxe/mousehid.h
deleted file mode 100644 (file)
index 4c4a233..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-/** @file\r
-\r
-Copyright (c) 2004, 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
-  MouseHid.h\r
-\r
-Abstract:\r
-\r
-\r
-**/\r
-\r
-#ifndef __MOUSE_HID_H\r
-#define __MOUSE_HID_H\r
-\r
-#include "UsbMouseAbsolutePointer.h"\r
-\r
-//\r
-// HID Item general structure\r
-//\r
-typedef struct _hid_item {\r
-  UINT16  Format;\r
-  UINT8   Size;\r
-  UINT8   Type;\r
-  UINT8   Tag;\r
-  union {\r
-    UINT8   U8;\r
-    UINT16  U16;\r
-    UINT32  U32;\r
-    INT8    I8;\r
-    INT16   I16;\r
-    INT32   I32;\r
-    UINT8   *LongData;\r
-  } Data;\r
-} HID_ITEM;\r
-\r
-typedef struct {\r
-  UINT16  UsagePage;\r
-  INT32   LogicMin;\r
-  INT32   LogicMax;\r
-  INT32   PhysicalMin;\r
-  INT32   PhysicalMax;\r
-  UINT16  UnitExp;\r
-  UINT16 UINT;\r
-  UINT16 ReportId;\r
-  UINT16 ReportSize;\r
-  UINT16 ReportCount;\r
-} HID_GLOBAL;\r
-\r
-typedef struct {\r
-  UINT16  Usage[16];  /* usage array */\r
-  UINT16  UsageIndex;\r
-  UINT16  UsageMin;\r
-} HID_LOCAL;\r
-\r
-typedef struct {\r
-  UINT16  Type;\r
-  UINT16  Usage;\r
-} HID_COLLECTION;\r
-\r
-typedef struct {\r
-  HID_GLOBAL      Global;\r
-  HID_GLOBAL      GlobalStack[8];\r
-  UINT32          GlobalStackPtr;\r
-  HID_LOCAL       Local;\r
-  HID_COLLECTION  CollectionStack[8];\r
-  UINT32          CollectionStackPtr;\r
-} HID_PARSER;\r
-\r
-EFI_STATUS\r
-ParseMouseReportDescriptor (\r
-  IN  USB_MOUSE_ABSOLUTE_POINTER_DEV   *UsbMouseAbsolutePointer,\r
-  IN  UINT8           *ReportDescriptor,\r
-  IN  UINTN           ReportSize\r
-  );\r
-\r
-#endif\r