1. Import UsbKbDxe and UsbMouseDxe into MdeModulePkg
authorvanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 12 Jul 2007 17:31:28 +0000 (17:31 +0000)
committervanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 12 Jul 2007 17:31:28 +0000 (17:31 +0000)
2. Updated UefiUsbLib

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@3216 6f19259b-4bc3-4df7-8a09-765794883524

21 files changed:
MdeModulePkg/Bus/Usb/UsbKbDxe/ComponentName.c [new file with mode: 0644]
MdeModulePkg/Bus/Usb/UsbKbDxe/UsbKbDxe.inf [new file with mode: 0644]
MdeModulePkg/Bus/Usb/UsbKbDxe/UsbKbDxe.msa [new file with mode: 0644]
MdeModulePkg/Bus/Usb/UsbKbDxe/efikey.c [new file with mode: 0644]
MdeModulePkg/Bus/Usb/UsbKbDxe/efikey.h [new file with mode: 0644]
MdeModulePkg/Bus/Usb/UsbKbDxe/keyboard.c [new file with mode: 0644]
MdeModulePkg/Bus/Usb/UsbKbDxe/keyboard.h [new file with mode: 0644]
MdeModulePkg/Bus/Usb/UsbMouseDxe/ComponentName.c [new file with mode: 0644]
MdeModulePkg/Bus/Usb/UsbMouseDxe/UsbMouseDxe.inf [new file with mode: 0644]
MdeModulePkg/Bus/Usb/UsbMouseDxe/UsbMouseDxe.msa [new file with mode: 0644]
MdeModulePkg/Bus/Usb/UsbMouseDxe/mousehid.c [new file with mode: 0644]
MdeModulePkg/Bus/Usb/UsbMouseDxe/mousehid.h [new file with mode: 0644]
MdeModulePkg/Bus/Usb/UsbMouseDxe/usbmouse.c [new file with mode: 0644]
MdeModulePkg/Bus/Usb/UsbMouseDxe/usbmouse.h [new file with mode: 0644]
MdeModulePkg/MdeModulePkg.dec
MdeModulePkg/MdeModulePkg.dsc
MdePkg/Include/Library/UsbLib.h
MdePkg/Library/UefiUsbLib/UefiUsbLib.inf
MdePkg/Library/UefiUsbLib/UefiUsbLib.msa
MdePkg/Library/UefiUsbLib/UsbDxeLib.c
MdePkg/Library/UefiUsbLib/hid.c

diff --git a/MdeModulePkg/Bus/Usb/UsbKbDxe/ComponentName.c b/MdeModulePkg/Bus/Usb/UsbKbDxe/ComponentName.c
new file mode 100644 (file)
index 0000000..db8fe6b
--- /dev/null
@@ -0,0 +1,217 @@
+/** @file\r
+\r
+Copyright (c) 2004 - 2007, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+Module Name:\r
+\r
+  ComponentName.c\r
+\r
+Abstract:\r
+\r
+\r
+**/\r
+\r
+\r
+#include "keyboard.h"\r
+\r
+//\r
+// EFI Component Name Functions\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+UsbKeyboardComponentNameGetDriverName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UsbKeyboardComponentNameGetControllerName (\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
+// EFI Component Name Protocol\r
+//\r
+EFI_COMPONENT_NAME_PROTOCOL     gUsbKeyboardComponentName = {\r
+  UsbKeyboardComponentNameGetDriverName,\r
+  UsbKeyboardComponentNameGetControllerName,\r
+  "eng"\r
+};\r
+\r
+STATIC EFI_UNICODE_STRING_TABLE mUsbKeyboardDriverNameTable[] = {\r
+  { "eng", L"Usb Keyboard Driver" },\r
+  { NULL , NULL }\r
+};\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UsbKeyboardComponentNameGetDriverName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Retrieves a Unicode string that is the user readable name of the EFI Driver.\r
+\r
+  Arguments:\r
+    This       - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.\r
+    Language   - A pointer to a three character ISO 639-2 language identifier.\r
+                 This is the language of the driver name that that the caller\r
+                 is requesting, and it must match one of the languages specified\r
+                 in SupportedLanguages.  The number of languages supported by a\r
+                 driver is up to the driver writer.\r
+    DriverName - A pointer to the Unicode string to return.  This Unicode string\r
+                 is the name of the driver specified by This in the language\r
+                 specified by Language.\r
+\r
+  Returns:\r
+    EFI_SUCCESS           - The Unicode string for the Driver specified by This\r
+                            and the language specified by Language was returned\r
+                            in DriverName.\r
+    EFI_INVALID_PARAMETER - Language is NULL.\r
+    EFI_INVALID_PARAMETER - DriverName is NULL.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support the\r
+                            language specified by Language.\r
+\r
+--*/\r
+{\r
+  return LookupUnicodeString (\r
+          Language,\r
+          gUsbKeyboardComponentName.SupportedLanguages,\r
+          mUsbKeyboardDriverNameTable,\r
+          DriverName\r
+          );\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UsbKeyboardComponentNameGetControllerName (\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
+  Routine Description:\r
+    Retrieves a Unicode string that is the user readable name of the controller\r
+    that is being managed by an EFI Driver.\r
+\r
+  Arguments:\r
+    This             - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.\r
+    ControllerHandle - The handle of a controller that the driver specified by\r
+                       This is managing.  This handle specifies the controller\r
+                       whose name is to be returned.\r
+    ChildHandle      - The handle of the child controller to retrieve the name\r
+                       of.  This is an optional parameter that may be NULL.  It\r
+                       will be NULL for device drivers.  It will also be NULL\r
+                       for a bus drivers that wish to retrieve the name of the\r
+                       bus controller.  It will not be NULL for a bus driver\r
+                       that wishes to retrieve the name of a child controller.\r
+    Language         - A pointer to a three character ISO 639-2 language\r
+                       identifier.  This is the language of the controller name\r
+                       that that the caller is requesting, and it must match one\r
+                       of the languages specified in SupportedLanguages.  The\r
+                       number of languages supported by a driver is up to the\r
+                       driver writer.\r
+    ControllerName   - A pointer to the Unicode string to return.  This Unicode\r
+                       string is the name of the controller specified by\r
+                       ControllerHandle and ChildHandle in the language specified\r
+                       by Language from the point of view of the driver specified\r
+                       by This.\r
+\r
+  Returns:\r
+    EFI_SUCCESS           - The Unicode string for the user readable name in the\r
+                            language specified by Language for the driver\r
+                            specified by This was returned in DriverName.\r
+    EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - Language is NULL.\r
+    EFI_INVALID_PARAMETER - ControllerName is NULL.\r
+    EFI_UNSUPPORTED       - The driver specified by This is not currently managing\r
+                            the controller specified by ControllerHandle and\r
+                            ChildHandle.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support the\r
+                            language specified by Language.\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                  Status;\r
+  USB_KB_DEV                  *UsbKbDev;\r
+  EFI_SIMPLE_TEXT_INPUT_PROTOCOL *SimpleTxtIn;\r
+  EFI_USB_IO_PROTOCOL         *UsbIoProtocol;\r
+  //\r
+  // This is a device driver, so ChildHandle must be NULL.\r
+  //\r
+  if (ChildHandle != NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  //\r
+  // Check Controller's handle\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiUsbIoProtocolGuid,\r
+                  (VOID **) &UsbIoProtocol,\r
+                  gUsbKeyboardDriverBinding.DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (!EFI_ERROR (Status)) {\r
+    gBS->CloseProtocol (\r
+          ControllerHandle,\r
+          &gEfiUsbIoProtocolGuid,\r
+          gUsbKeyboardDriverBinding.DriverBindingHandle,\r
+          ControllerHandle\r
+          );\r
+\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  if (Status != EFI_ALREADY_STARTED) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+  //\r
+  // Get the device context\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiSimpleTextInProtocolGuid,\r
+                  (VOID **) &SimpleTxtIn,\r
+                  gUsbKeyboardDriverBinding.DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  UsbKbDev = USB_KB_DEV_FROM_THIS (SimpleTxtIn);\r
+\r
+  return LookupUnicodeString (\r
+          Language,\r
+          gUsbKeyboardComponentName.SupportedLanguages,\r
+          UsbKbDev->ControllerNameTable,\r
+          ControllerName\r
+          );\r
+\r
+}\r
diff --git a/MdeModulePkg/Bus/Usb/UsbKbDxe/UsbKbDxe.inf b/MdeModulePkg/Bus/Usb/UsbKbDxe/UsbKbDxe.inf
new file mode 100644 (file)
index 0000000..dfe7a2c
--- /dev/null
@@ -0,0 +1,121 @@
+#/** @file\r
+# Component name for module UsbKb\r
+#\r
+# FIX ME!\r
+# Copyright (c) 2006, Intel Corporation. All right reserved.\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
+#  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
+#\r
+#**/\r
+\r
+################################################################################\r
+#\r
+# Defines Section - statements that will be processed to create a Makefile.\r
+#\r
+################################################################################\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = UsbKbDxe\r
+  FILE_GUID                      = 2D2E62CF-9ECF-43b7-8219-94E7FC713DFE\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  ENTRY_POINT                    = USBKeyboardDriverBindingEntryPoint\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+################################################################################\r
+#\r
+# Sources Section - list of files that are required for the build to succeed.\r
+#\r
+################################################################################\r
+\r
+[Sources.common]\r
+  efikey.c\r
+  efikey.h\r
+  keyboard.c\r
+  ComponentName.c\r
+  keyboard.h\r
+\r
+################################################################################\r
+#\r
+# Package Dependency Section - list of Package files that are required for\r
+#                              this module.\r
+#\r
+################################################################################\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+\r
+\r
+################################################################################\r
+#\r
+# Library Class Section - list of Library Classes that are required for\r
+#                         this module.\r
+#\r
+################################################################################\r
+\r
+[LibraryClasses]\r
+  MemoryAllocationLib\r
+  UefiLib\r
+  UefiBootServicesTableLib\r
+  UefiDriverEntryPoint\r
+  UefiRuntimeServicesTableLib\r
+  BaseMemoryLib\r
+  ReportStatusCodeLib\r
+  DebugLib\r
+  PcdLib\r
+  UsbLib\r
+\r
+\r
+################################################################################\r
+#\r
+# Guid C Name Section - list of Guids that this module uses or produces.\r
+#\r
+################################################################################\r
+\r
+[Guids]\r
+  gEfiHotPlugDeviceGuid                         # ALWAYS_CONSUMED\r
+\r
+\r
+################################################################################\r
+#\r
+# Protocol C Name Section - list of Protocol and Protocol Notify C Names\r
+#                           that this module uses or produces.\r
+#\r
+################################################################################\r
+\r
+[Protocols]\r
+  gEfiUsbIoProtocolGuid                         # PROTOCOL ALWAYS_CONSUMED\r
+  gEfiDevicePathProtocolGuid                    # PROTOCOL ALWAYS_CONSUMED\r
+  gEfiSimpleTextInProtocolGuid                  # PROTOCOL ALWAYS_CONSUMED\r
+\r
+################################################################################\r
+#\r
+# Pcd FIXED_AT_BUILD - list of PCDs that this module is coded for.\r
+#\r
+################################################################################\r
+\r
+[PcdsFixedAtBuild]\r
+  PcdStatusCodeValueKeyboardEnable|gEfiMdePkgTokenSpaceGuid\r
+  PcdStatusCodeValueKeyboardPresenceDetect|gEfiMdePkgTokenSpaceGuid\r
+  PcdStatusCodeValueKeyboardDisable|gEfiMdePkgTokenSpaceGuid\r
+  PcdStatusCodeValueKeyboardReset|gEfiMdePkgTokenSpaceGuid\r
+  PcdStatusCodeValueKeyboardClearBuffer|gEfiMdePkgTokenSpaceGuid\r
+  PcdStatusCodeValueKeyboardSelfTest|gEfiMdePkgTokenSpaceGuid\r
+  PcdStatusCodeValueKeyboardInterfaceError|gEfiMdePkgTokenSpaceGuid\r
+  PcdStatusCodeValueKeyboardInputError|gEfiMdePkgTokenSpaceGuid
\ No newline at end of file
diff --git a/MdeModulePkg/Bus/Usb/UsbKbDxe/UsbKbDxe.msa b/MdeModulePkg/Bus/Usb/UsbKbDxe/UsbKbDxe.msa
new file mode 100644 (file)
index 0000000..b476aef
--- /dev/null
@@ -0,0 +1,84 @@
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\r
+  <MsaHeader>\r
+    <ModuleName>UsbKbDxe</ModuleName>\r
+    <ModuleType>DXE_DRIVER</ModuleType>\r
+    <GuidValue>2D2E62CF-9ECF-43b7-8219-94E7FC713DFE</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Component name for module UsbKb</Abstract>\r
+    <Description>FIX ME!</Description>\r
+    <Copyright>Copyright (c) 2006, Intel Corporation. All right reserved.</Copyright>\r
+    <License>All rights reserved. This program and the accompanying materials
+      are licensed and made available under the terms and conditions of the BSD License
+      which accompanies this distribution.  The full text of the license may be found at
+      http://opensource.org/licenses/bsd-license.php
+
+      THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+      WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>UsbKbDxe</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>ReportStatusCodeLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseMemoryLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiRuntimeServicesTableLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiDriverEntryPoint</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiBootServicesTableLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>MemoryAllocationLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>keyboard.h</Filename>\r
+    <Filename>ComponentName.c</Filename>\r
+    <Filename>keyboard.c</Filename>\r
+    <Filename>efikey.h</Filename>\r
+    <Filename>efikey.c</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+    <Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/>\r
+  </PackageDependencies>\r
+  <Protocols>\r
+    <Protocol Usage="ALWAYS_CONSUMED">\r
+      <ProtocolCName>gEfiSimpleTextInProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="ALWAYS_CONSUMED">\r
+      <ProtocolCName>gEfiDevicePathProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="ALWAYS_CONSUMED">\r
+      <ProtocolCName>gEfiUsbIoProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+  </Protocols>\r
+  <Guids>\r
+    <GuidCNames Usage="ALWAYS_CONSUMED">\r
+      <GuidCName>gEfiHotPlugDeviceGuid</GuidCName>\r
+    </GuidCNames>\r
+  </Guids>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+    <Extern>\r
+      <ModuleEntryPoint>USBKeyboardDriverBindingEntryPoint</ModuleEntryPoint>\r
+    </Extern>\r
+  </Externs>\r
+</ModuleSurfaceArea>
\ No newline at end of file
diff --git a/MdeModulePkg/Bus/Usb/UsbKbDxe/efikey.c b/MdeModulePkg/Bus/Usb/UsbKbDxe/efikey.c
new file mode 100644 (file)
index 0000000..3ea788c
--- /dev/null
@@ -0,0 +1,793 @@
+/** @file\r
+\r
+Copyright (c) 2004 - 2007, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+Module Name:\r
+\r
+  EfiKey.c\r
+\r
+Abstract:\r
+\r
+  USB Keyboard Driver\r
+\r
+Revision History\r
+\r
+\r
+**/\r
+\r
+#include "efikey.h"\r
+#include "keyboard.h"\r
+\r
+//\r
+// Prototypes\r
+// Driver model protocol interface\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+USBKeyboardDriverBindingEntryPoint (\r
+  IN EFI_HANDLE           ImageHandle,\r
+  IN EFI_SYSTEM_TABLE     *SystemTable\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+USBKeyboardDriverBindingSupported (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL    *This,\r
+  IN EFI_HANDLE                     Controller,\r
+  IN EFI_DEVICE_PATH_PROTOCOL       *RemainingDevicePath\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+USBKeyboardDriverBindingStart (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL    *This,\r
+  IN EFI_HANDLE                     Controller,\r
+  IN EFI_DEVICE_PATH_PROTOCOL       *RemainingDevicePath\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+USBKeyboardDriverBindingStop (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL    *This,\r
+  IN  EFI_HANDLE                     Controller,\r
+  IN  UINTN                          NumberOfChildren,\r
+  IN  EFI_HANDLE                     *ChildHandleBuffer\r
+  );\r
+\r
+//\r
+// Simple Text In Protocol Interface\r
+//\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+USBKeyboardReset (\r
+  IN  EFI_SIMPLE_TEXT_INPUT_PROTOCOL  *This,\r
+  IN  BOOLEAN                      ExtendedVerification\r
+  );\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+USBKeyboardReadKeyStroke (\r
+  IN  EFI_SIMPLE_TEXT_INPUT_PROTOCOL   *This,\r
+  OUT EFI_INPUT_KEY                 *Key\r
+  );\r
+\r
+STATIC\r
+VOID\r
+EFIAPI\r
+USBKeyboardWaitForKey (\r
+  IN  EFI_EVENT               Event,\r
+  IN  VOID                    *Context\r
+  );\r
+\r
+//\r
+//  Helper functions\r
+//\r
+STATIC\r
+EFI_STATUS\r
+USBKeyboardCheckForKey (\r
+  IN  USB_KB_DEV      *UsbKeyboardDevice\r
+  );\r
+\r
+EFI_GUID  gEfiUsbKeyboardDriverGuid = {\r
+  0xa05f5f78, 0xfb3, 0x4d10, 0x90, 0x90, 0xac, 0x4, 0x6e, 0xeb, 0x7c, 0x3c\r
+};\r
+\r
+//\r
+// USB Keyboard Driver Global Variables\r
+//\r
+EFI_DRIVER_BINDING_PROTOCOL gUsbKeyboardDriverBinding = {\r
+  USBKeyboardDriverBindingSupported,\r
+  USBKeyboardDriverBindingStart,\r
+  USBKeyboardDriverBindingStop,\r
+  0xa,\r
+  NULL,\r
+  NULL\r
+};\r
+\r
+//@MT: EFI_DRIVER_ENTRY_POINT (USBKeyboardDriverBindingEntryPoint)\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+USBKeyboardDriverBindingEntryPoint (\r
+  IN EFI_HANDLE           ImageHandle,\r
+  IN EFI_SYSTEM_TABLE     *SystemTable\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Driver Entry Point.\r
+\r
+  Arguments:\r
+    ImageHandle - EFI_HANDLE\r
+    SystemTable - EFI_SYSTEM_TABLE\r
+  Returns:\r
+    EFI_STATUS\r
+\r
+--*/\r
+{\r
+  return EfiLibInstallAllDriverProtocols (\r
+          ImageHandle,\r
+          SystemTable,\r
+          &gUsbKeyboardDriverBinding,\r
+          ImageHandle,\r
+          &gUsbKeyboardComponentName,\r
+          NULL,\r
+          NULL\r
+          );\r
+}\r
+\r
+\r
+\r
+/**\r
+  Supported.\r
+\r
+  @param  This                  EFI_DRIVER_BINDING_PROTOCOL\r
+  @param  Controller            Controller handle\r
+  @param  RemainingDevicePath   EFI_DEVICE_PATH_PROTOCOL\r
+ EFI_STATUS\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+USBKeyboardDriverBindingSupported (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL    *This,\r
+  IN EFI_HANDLE                     Controller,\r
+  IN EFI_DEVICE_PATH_PROTOCOL       *RemainingDevicePath\r
+  )\r
+{\r
+  EFI_STATUS          OpenStatus;\r
+  EFI_USB_IO_PROTOCOL *UsbIo;\r
+  EFI_STATUS          Status;\r
+\r
+  //\r
+  // Check if USB_IO protocol is attached on the controller handle.\r
+  //\r
+  OpenStatus = gBS->OpenProtocol (\r
+                      Controller,\r
+                      &gEfiUsbIoProtocolGuid,\r
+                      &UsbIo,\r
+                      This->DriverBindingHandle,\r
+                      Controller,\r
+                      EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                      );\r
+  if (EFI_ERROR (OpenStatus)) {\r
+    return OpenStatus;\r
+  }\r
+\r
+  //\r
+  // Use the USB I/O protocol interface to check whether the Controller is\r
+  // the Keyboard controller that can be managed by this driver.\r
+  //\r
+  Status = EFI_SUCCESS;\r
+\r
+  if (!IsUSBKeyboard (UsbIo)) {\r
+    Status = EFI_UNSUPPORTED;\r
+  }\r
+\r
+  gBS->CloseProtocol (\r
+        Controller,\r
+        &gEfiUsbIoProtocolGuid,\r
+        This->DriverBindingHandle,\r
+        Controller\r
+        );\r
+\r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+  Start.\r
+\r
+  @param  This                  EFI_DRIVER_BINDING_PROTOCOL\r
+  @param  Controller            Controller handle\r
+  @param  RemainingDevicePath   EFI_DEVICE_PATH_PROTOCOL\r
+\r
+  @retval EFI_SUCCESS           Success\r
+  @retval EFI_OUT_OF_RESOURCES  Can't allocate memory\r
+  @retval EFI_UNSUPPORTED       The Start routine fail\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+USBKeyboardDriverBindingStart (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL    *This,\r
+  IN EFI_HANDLE                     Controller,\r
+  IN EFI_DEVICE_PATH_PROTOCOL       *RemainingDevicePath\r
+  )\r
+{\r
+  EFI_STATUS                    Status;\r
+  EFI_USB_IO_PROTOCOL           *UsbIo;\r
+  USB_KB_DEV                    *UsbKeyboardDevice;\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
+  UsbKeyboardDevice = NULL;\r
+  Found             = FALSE;\r
+\r
+  //\r
+  // Open USB_IO Protocol\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  Controller,\r
+                  &gEfiUsbIoProtocolGuid,\r
+                  &UsbIo,\r
+                  This->DriverBindingHandle,\r
+                  Controller,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  UsbKeyboardDevice = AllocateZeroPool (sizeof (USB_KB_DEV));\r
+  if (UsbKeyboardDevice == NULL) {\r
+    gBS->CloseProtocol (\r
+          Controller,\r
+          &gEfiUsbIoProtocolGuid,\r
+          This->DriverBindingHandle,\r
+          Controller\r
+          );\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+  //\r
+  // Get the Device Path Protocol on Controller's handle\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  Controller,\r
+                  &gEfiDevicePathProtocolGuid,\r
+                  (VOID **) &UsbKeyboardDevice->DevicePath,\r
+                  This->DriverBindingHandle,\r
+                  Controller,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    gBS->FreePool (UsbKeyboardDevice);\r
+    gBS->CloseProtocol (\r
+          Controller,\r
+          &gEfiUsbIoProtocolGuid,\r
+          This->DriverBindingHandle,\r
+          Controller\r
+          );\r
+    return Status;\r
+  }\r
+  //\r
+  // Report that the usb keyboard is being enabled\r
+  //\r
+  KbdReportStatusCode (\r
+    UsbKeyboardDevice->DevicePath,\r
+    EFI_PROGRESS_CODE,\r
+    PcdGet32 (PcdStatusCodeValueKeyboardEnable)\r
+    );\r
+\r
+  //\r
+  // This is pretty close to keyboard detection, so log progress\r
+  //\r
+  KbdReportStatusCode (\r
+    UsbKeyboardDevice->DevicePath,\r
+    EFI_PROGRESS_CODE,\r
+    PcdGet32 (PcdStatusCodeValueKeyboardPresenceDetect)\r
+    );\r
+\r
+  //\r
+  // Initialize UsbKeyboardDevice\r
+  //\r
+  UsbKeyboardDevice->UsbIo = UsbIo;\r
+\r
+  //\r
+  // Get interface & endpoint descriptor\r
+  //\r
+  UsbIo->UsbGetInterfaceDescriptor (\r
+          UsbIo,\r
+          &UsbKeyboardDevice->InterfaceDescriptor\r
+          );\r
+\r
+  EndpointNumber = UsbKeyboardDevice->InterfaceDescriptor.NumEndpoints;\r
+\r
+  for (Index = 0; Index < EndpointNumber; Index++) {\r
+\r
+    UsbIo->UsbGetEndpointDescriptor (\r
+            UsbIo,\r
+            Index,\r
+            &EndpointDescriptor\r
+            );\r
+\r
+    if ((EndpointDescriptor.Attributes & 0x03) == 0x03) {\r
+      //\r
+      // We only care interrupt endpoint here\r
+      //\r
+      UsbKeyboardDevice->IntEndpointDescriptor  = EndpointDescriptor;\r
+      Found = TRUE;\r
+    }\r
+  }\r
+\r
+  if (!Found) {\r
+    //\r
+    // No interrupt endpoint found, then return unsupported.\r
+    //\r
+    gBS->FreePool (UsbKeyboardDevice);\r
+    gBS->CloseProtocol (\r
+          Controller,\r
+          &gEfiUsbIoProtocolGuid,\r
+          This->DriverBindingHandle,\r
+          Controller\r
+          );\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  UsbKeyboardDevice->Signature                  = USB_KB_DEV_SIGNATURE;\r
+  UsbKeyboardDevice->SimpleInput.Reset          = USBKeyboardReset;\r
+  UsbKeyboardDevice->SimpleInput.ReadKeyStroke  = USBKeyboardReadKeyStroke;\r
+  Status = gBS->CreateEvent (\r
+                  EVT_NOTIFY_WAIT,\r
+                  TPL_NOTIFY,\r
+                  USBKeyboardWaitForKey,\r
+                  UsbKeyboardDevice,\r
+                  &(UsbKeyboardDevice->SimpleInput.WaitForKey)\r
+                  );\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    gBS->FreePool (UsbKeyboardDevice);\r
+    gBS->CloseProtocol (\r
+          Controller,\r
+          &gEfiUsbIoProtocolGuid,\r
+          This->DriverBindingHandle,\r
+          Controller\r
+          );\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Install simple txt in protocol interface\r
+  // for the usb keyboard device.\r
+  // Usb keyboard is a hot plug device, and expected to work immediately\r
+  // when plugging into system, so a HotPlugDeviceGuid is installed onto\r
+  // the usb keyboard device handle, to distinguish it from other conventional\r
+  // console devices.\r
+  //\r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &Controller,\r
+                  &gEfiSimpleTextInProtocolGuid,\r
+                  &UsbKeyboardDevice->SimpleInput,\r
+                  &gEfiHotPlugDeviceGuid,\r
+                  NULL,\r
+                  NULL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    gBS->CloseEvent (UsbKeyboardDevice->SimpleInput.WaitForKey);\r
+    gBS->FreePool (UsbKeyboardDevice);\r
+    gBS->CloseProtocol (\r
+          Controller,\r
+          &gEfiUsbIoProtocolGuid,\r
+          This->DriverBindingHandle,\r
+          Controller\r
+          );\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Reset USB Keyboard Device\r
+  //\r
+  Status = UsbKeyboardDevice->SimpleInput.Reset (\r
+                                            &UsbKeyboardDevice->SimpleInput,\r
+                                            TRUE\r
+                                            );\r
+  if (EFI_ERROR (Status)) {\r
+    gBS->UninstallMultipleProtocolInterfaces (\r
+          Controller,\r
+          &gEfiSimpleTextInProtocolGuid,\r
+          &UsbKeyboardDevice->SimpleInput,\r
+          &gEfiHotPlugDeviceGuid,\r
+          NULL,\r
+          NULL\r
+          );\r
+    gBS->CloseEvent (UsbKeyboardDevice->SimpleInput.WaitForKey);\r
+    gBS->FreePool (UsbKeyboardDevice);\r
+    gBS->CloseProtocol (\r
+          Controller,\r
+          &gEfiUsbIoProtocolGuid,\r
+          This->DriverBindingHandle,\r
+          Controller\r
+          );\r
+    return Status;\r
+  }\r
+  //\r
+  // submit async interrupt transfer\r
+  //\r
+  EndpointAddr    = UsbKeyboardDevice->IntEndpointDescriptor.EndpointAddress;\r
+  PollingInterval = UsbKeyboardDevice->IntEndpointDescriptor.Interval;\r
+  PacketSize      = (UINT8) (UsbKeyboardDevice->IntEndpointDescriptor.MaxPacketSize);\r
+\r
+  Status = UsbIo->UsbAsyncInterruptTransfer (\r
+                    UsbIo,\r
+                    EndpointAddr,\r
+                    TRUE,\r
+                    PollingInterval,\r
+                    PacketSize,\r
+                    KeyboardHandler,\r
+                    UsbKeyboardDevice\r
+                    );\r
+\r
+  if (EFI_ERROR (Status)) {\r
+\r
+    gBS->UninstallMultipleProtocolInterfaces (\r
+          Controller,\r
+          &gEfiSimpleTextInProtocolGuid,\r
+          &UsbKeyboardDevice->SimpleInput,\r
+          &gEfiHotPlugDeviceGuid,\r
+          NULL,\r
+          NULL\r
+          );\r
+    gBS->CloseEvent (UsbKeyboardDevice->SimpleInput.WaitForKey);\r
+    gBS->FreePool (UsbKeyboardDevice);\r
+    gBS->CloseProtocol (\r
+          Controller,\r
+          &gEfiUsbIoProtocolGuid,\r
+          This->DriverBindingHandle,\r
+          Controller\r
+          );\r
+    return Status;\r
+  }\r
+\r
+  UsbKeyboardDevice->ControllerNameTable = NULL;\r
+  AddUnicodeString (\r
+    "eng",\r
+    gUsbKeyboardComponentName.SupportedLanguages,\r
+    &UsbKeyboardDevice->ControllerNameTable,\r
+    L"Generic Usb Keyboard"\r
+    );\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+\r
+/**\r
+  Stop.\r
+\r
+  @param  This                  EFI_DRIVER_BINDING_PROTOCOL\r
+  @param  Controller            Controller handle\r
+  @param  NumberOfChildren      Child handle number\r
+  @param  ChildHandleBuffer     Child handle buffer\r
+\r
+  @retval EFI_SUCCESS           Success\r
+  @retval EFI_UNSUPPORTED       Can't support\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+USBKeyboardDriverBindingStop (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL    *This,\r
+  IN  EFI_HANDLE                     Controller,\r
+  IN  UINTN                          NumberOfChildren,\r
+  IN  EFI_HANDLE                     *ChildHandleBuffer\r
+  )\r
+{\r
+  EFI_STATUS                  Status;\r
+  EFI_SIMPLE_TEXT_INPUT_PROTOCOL *SimpleInput;\r
+  USB_KB_DEV                  *UsbKeyboardDevice;\r
+  EFI_USB_IO_PROTOCOL         *UsbIo;\r
+\r
+  Status = gBS->OpenProtocol (\r
+                  Controller,\r
+                  &gEfiSimpleTextInProtocolGuid,\r
+                  &SimpleInput,\r
+                  This->DriverBindingHandle,\r
+                  Controller,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  //\r
+  // Get USB_KB_DEV instance.\r
+  //\r
+  UsbKeyboardDevice = USB_KB_DEV_FROM_THIS (SimpleInput);\r
+\r
+  gBS->CloseProtocol (\r
+        Controller,\r
+        &gEfiSimpleTextInProtocolGuid,\r
+        This->DriverBindingHandle,\r
+        Controller\r
+        );\r
+\r
+  UsbIo = UsbKeyboardDevice->UsbIo;\r
+  //\r
+  // Uninstall the Asyn Interrupt Transfer from this device\r
+  // will disable the key data input from this device\r
+  //\r
+  KbdReportStatusCode (\r
+    UsbKeyboardDevice->DevicePath,\r
+    EFI_PROGRESS_CODE,\r
+    PcdGet32 (PcdStatusCodeValueKeyboardDisable)\r
+    );\r
+\r
+  //\r
+  // Destroy asynchronous interrupt transfer\r
+  //\r
+  UsbKeyboardDevice->UsbIo->UsbAsyncInterruptTransfer (\r
+                              UsbKeyboardDevice->UsbIo,\r
+                              UsbKeyboardDevice->IntEndpointDescriptor.EndpointAddress,\r
+                              FALSE,\r
+                              UsbKeyboardDevice->IntEndpointDescriptor.Interval,\r
+                              0,\r
+                              NULL,\r
+                              NULL\r
+                              );\r
+\r
+  gBS->CloseProtocol (\r
+        Controller,\r
+        &gEfiUsbIoProtocolGuid,\r
+        This->DriverBindingHandle,\r
+        Controller\r
+        );\r
+\r
+  Status = gBS->UninstallMultipleProtocolInterfaces (\r
+                  Controller,\r
+                  &gEfiSimpleTextInProtocolGuid,\r
+                  &UsbKeyboardDevice->SimpleInput,\r
+                  &gEfiHotPlugDeviceGuid,\r
+                  NULL,\r
+                  NULL\r
+                  );\r
+  //\r
+  // free all the resources.\r
+  //\r
+  gBS->CloseEvent (UsbKeyboardDevice->RepeatTimer);\r
+  gBS->CloseEvent (UsbKeyboardDevice->DelayedRecoveryEvent);\r
+  gBS->CloseEvent ((UsbKeyboardDevice->SimpleInput).WaitForKey);\r
+\r
+  if (UsbKeyboardDevice->ControllerNameTable != NULL) {\r
+    FreeUnicodeStringTable (UsbKeyboardDevice->ControllerNameTable);\r
+  }\r
+\r
+  gBS->FreePool (UsbKeyboardDevice);\r
+\r
+  return Status;\r
+\r
+}\r
+\r
+\r
+\r
+/**\r
+  Implements EFI_SIMPLE_TEXT_INPUT_PROTOCOL.Reset() function.\r
+\r
+  This      The EFI_SIMPLE_TEXT_INPUT_PROTOCOL instance.\r
+  ExtendedVerification\r
+  Indicates that the driver may perform a more exhaustive\r
+  verification operation of the device during reset.\r
+\r
+  @retval EFI_SUCCESS           Success\r
+  @retval EFI_DEVICE_ERROR      Hardware Error\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+USBKeyboardReset (\r
+  IN  EFI_SIMPLE_TEXT_INPUT_PROTOCOL   *This,\r
+  IN  BOOLEAN                       ExtendedVerification\r
+  )\r
+{\r
+  EFI_STATUS          Status;\r
+  USB_KB_DEV          *UsbKeyboardDevice;\r
+  EFI_USB_IO_PROTOCOL *UsbIo;\r
+\r
+  UsbKeyboardDevice = USB_KB_DEV_FROM_THIS (This);\r
+\r
+  UsbIo             = UsbKeyboardDevice->UsbIo;\r
+\r
+  KbdReportStatusCode (\r
+    UsbKeyboardDevice->DevicePath,\r
+    EFI_PROGRESS_CODE,\r
+        PcdGet32 (PcdStatusCodeValueKeyboardReset)\r
+    );\r
+\r
+  //\r
+  // Non Exhaustive reset:\r
+  // only reset private data structures.\r
+  //\r
+  if (!ExtendedVerification) {\r
+    //\r
+    // Clear the key buffer of this Usb keyboard\r
+    //\r
+    KbdReportStatusCode (\r
+      UsbKeyboardDevice->DevicePath,\r
+      EFI_PROGRESS_CODE,\r
+      PcdGet32 (PcdStatusCodeValueKeyboardClearBuffer)\r
+      );\r
+\r
+    InitUSBKeyBuffer (&(UsbKeyboardDevice->KeyboardBuffer));\r
+    UsbKeyboardDevice->CurKeyChar = 0;\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  //\r
+  // Exhaustive reset\r
+  //\r
+  Status                        = InitUSBKeyboard (UsbKeyboardDevice);\r
+  UsbKeyboardDevice->CurKeyChar = 0;\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+  Implements EFI_SIMPLE_TEXT_INPUT_PROTOCOL.ReadKeyStroke() function.\r
+\r
+  This     The EFI_SIMPLE_TEXT_INPUT_PROTOCOL instance.\r
+  Key      A pointer to a buffer that is filled in with the keystroke\r
+  information for the key that was pressed.\r
+\r
+  @retval EFI_SUCCESS           Success\r
+\r
+**/\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+USBKeyboardReadKeyStroke (\r
+  IN  EFI_SIMPLE_TEXT_INPUT_PROTOCOL   *This,\r
+  OUT EFI_INPUT_KEY                 *Key\r
+  )\r
+{\r
+  USB_KB_DEV  *UsbKeyboardDevice;\r
+  EFI_STATUS  Status;\r
+  UINT8       KeyChar;\r
+\r
+  UsbKeyboardDevice = USB_KB_DEV_FROM_THIS (This);\r
+\r
+  //\r
+  // if there is no saved ASCII byte, fetch it\r
+  // by calling USBKeyboardCheckForKey().\r
+  //\r
+  if (UsbKeyboardDevice->CurKeyChar == 0) {\r
+    Status = USBKeyboardCheckForKey (UsbKeyboardDevice);\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+  }\r
+\r
+  Key->UnicodeChar              = 0;\r
+  Key->ScanCode                 = SCAN_NULL;\r
+\r
+  KeyChar                       = UsbKeyboardDevice->CurKeyChar;\r
+\r
+  UsbKeyboardDevice->CurKeyChar = 0;\r
+\r
+  //\r
+  // Translate saved ASCII byte into EFI_INPUT_KEY\r
+  //\r
+  Status = USBKeyCodeToEFIScanCode (UsbKeyboardDevice, KeyChar, Key);\r
+\r
+  return Status;\r
+\r
+}\r
+\r
+\r
+/**\r
+  Handler function for WaitForKey event.\r
+\r
+  Event        Event to be signaled when a key is pressed.\r
+  Context      Points to USB_KB_DEV instance.\r
+\r
+  @return VOID\r
+\r
+**/\r
+STATIC\r
+VOID\r
+EFIAPI\r
+USBKeyboardWaitForKey (\r
+  IN  EFI_EVENT               Event,\r
+  IN  VOID                    *Context\r
+  )\r
+{\r
+  USB_KB_DEV  *UsbKeyboardDevice;\r
+\r
+  UsbKeyboardDevice = (USB_KB_DEV *) Context;\r
+\r
+  if (UsbKeyboardDevice->CurKeyChar == 0) {\r
+\r
+    if (EFI_ERROR (USBKeyboardCheckForKey (UsbKeyboardDevice))) {\r
+      return ;\r
+    }\r
+  }\r
+  //\r
+  // If has key pending, signal the event.\r
+  //\r
+  gBS->SignalEvent (Event);\r
+}\r
+\r
+\r
+\r
+/**\r
+  Check whether there is key pending.\r
+\r
+  UsbKeyboardDevice    The USB_KB_DEV instance.\r
+\r
+  @retval EFI_SUCCESS           Success\r
+\r
+**/\r
+STATIC\r
+EFI_STATUS\r
+USBKeyboardCheckForKey (\r
+  IN  USB_KB_DEV    *UsbKeyboardDevice\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+  UINT8       KeyChar;\r
+\r
+  //\r
+  // Fetch raw data from the USB keyboard input,\r
+  // and translate it into ASCII data.\r
+  //\r
+  Status = USBParseKey (UsbKeyboardDevice, &KeyChar);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  UsbKeyboardDevice->CurKeyChar = KeyChar;\r
+  return EFI_SUCCESS;\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
+KbdReportStatusCode (\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
+  REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
+    CodeType,\r
+    Value,\r
+    DevicePath\r
+    );\r
+}\r
diff --git a/MdeModulePkg/Bus/Usb/UsbKbDxe/efikey.h b/MdeModulePkg/Bus/Usb/UsbKbDxe/efikey.h
new file mode 100644 (file)
index 0000000..e93a866
--- /dev/null
@@ -0,0 +1,146 @@
+/** @file\r
+Copyright (c) 2004 - 2007, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+Module Name:\r
+\r
+    EfiKey.h\r
+\r
+Abstract:\r
+\r
+    Header file for USB Keyboard Driver's Data Structures\r
+\r
+Revision History\r
+\r
+**/\r
+#ifndef _USB_KB_H\r
+#define _USB_KB_H\r
+\r
+//\r
+// The package level header files this module uses\r
+//\r
+#include <PiDxe.h>\r
+//\r
+// The protocols, PPI and GUID defintions for this module\r
+//\r
+#include <Protocol/SimpleTextIn.h>\r
+#include <Guid/HotPlugDevice.h>\r
+#include <Protocol/UsbIo.h>\r
+#include <Protocol/DevicePath.h>\r
+//\r
+// The Library classes this module consumes\r
+//\r
+#include <Library/DebugLib.h>\r
+#include <Library/ReportStatusCodeLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/UefiRuntimeServicesTableLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/UsbLib.h>\r
+\r
+\r
+#include <IndustryStandard/Usb.h>\r
+\r
+#define MAX_KEY_ALLOWED     32\r
+\r
+#define HZ                  1000 * 1000 * 10\r
+#define USBKBD_REPEAT_DELAY ((HZ) / 2)\r
+#define USBKBD_REPEAT_RATE  ((HZ) / 50)\r
+\r
+#define CLASS_HID           3\r
+#define SUBCLASS_BOOT       1\r
+#define PROTOCOL_KEYBOARD   1\r
+\r
+#define BOOT_PROTOCOL       0\r
+#define REPORT_PROTOCOL     1\r
+\r
+typedef struct {\r
+  UINT8 Down;\r
+  UINT8 KeyCode;\r
+} USB_KEY;\r
+\r
+typedef struct {\r
+  USB_KEY buffer[MAX_KEY_ALLOWED + 1];\r
+  UINT8   bHead;\r
+  UINT8   bTail;\r
+} USB_KB_BUFFER;\r
+\r
+#define USB_KB_DEV_SIGNATURE  EFI_SIGNATURE_32 ('u', 'k', 'b', 'd')\r
+typedef struct {\r
+  UINTN                          Signature;\r
+  EFI_DEVICE_PATH_PROTOCOL       *DevicePath;\r
+  EFI_EVENT                      DelayedRecoveryEvent;\r
+  EFI_SIMPLE_TEXT_INPUT_PROTOCOL SimpleInput;\r
+  EFI_USB_IO_PROTOCOL            *UsbIo;\r
+\r
+  EFI_USB_INTERFACE_DESCRIPTOR  InterfaceDescriptor;\r
+  EFI_USB_ENDPOINT_DESCRIPTOR   IntEndpointDescriptor;\r
+\r
+  USB_KB_BUFFER                 KeyboardBuffer;\r
+  UINT8                         CtrlOn;\r
+  UINT8                         AltOn;\r
+  UINT8                         ShiftOn;\r
+  UINT8                         NumLockOn;\r
+  UINT8                         CapsOn;\r
+  UINT8                         ScrollOn;\r
+  UINT8                         LastKeyCodeArray[8];\r
+  UINT8                         CurKeyChar;\r
+\r
+  UINT8                         RepeatKey;\r
+  EFI_EVENT                     RepeatTimer;\r
+\r
+  EFI_UNICODE_STRING_TABLE      *ControllerNameTable;\r
+\r
+} USB_KB_DEV;\r
+\r
+//\r
+// Global Variables\r
+//\r
+extern EFI_DRIVER_BINDING_PROTOCOL  gUsbKeyboardDriverBinding;\r
+extern EFI_COMPONENT_NAME_PROTOCOL  gUsbKeyboardComponentName;\r
+extern EFI_GUID                     gEfiUsbKeyboardDriverGuid;\r
+\r
+VOID\r
+KbdReportStatusCode (\r
+  IN EFI_DEVICE_PATH_PROTOCOL  *DevicePath,\r
+  IN EFI_STATUS_CODE_TYPE      CodeType,\r
+  IN EFI_STATUS_CODE_VALUE     Value\r
+  );\r
+\r
+#define USB_KB_DEV_FROM_THIS(a) \\r
+    CR(a, USB_KB_DEV, SimpleInput, USB_KB_DEV_SIGNATURE)\r
+\r
+#define MOD_CONTROL_L           0x01\r
+#define MOD_CONTROL_R           0x10\r
+#define MOD_SHIFT_L             0x02\r
+#define MOD_SHIFT_R             0x20\r
+#define MOD_ALT_L               0x04\r
+#define MOD_ALT_R               0x40\r
+#define MOD_WIN_L               0x08\r
+#define MOD_WIN_R               0x80\r
+\r
+typedef struct {\r
+  UINT8 Mask;\r
+  UINT8 Key;\r
+} KB_MODIFIER;\r
+\r
+#define USB_KEYCODE_MAX_MAKE      0x64\r
+\r
+#define USBKBD_VALID_KEYCODE(key) ((UINT8) (key) > 3)\r
+\r
+typedef struct {\r
+  UINT8 NumLock : 1;\r
+  UINT8 CapsLock : 1;\r
+  UINT8 ScrollLock : 1;\r
+  UINT8 Resrvd : 5;\r
+} LED_MAP;\r
+#endif\r
diff --git a/MdeModulePkg/Bus/Usb/UsbKbDxe/keyboard.c b/MdeModulePkg/Bus/Usb/UsbKbDxe/keyboard.c
new file mode 100644 (file)
index 0000000..41286d6
--- /dev/null
@@ -0,0 +1,1140 @@
+/** @file\r
+\r
+Copyright (c) 2004 - 2005, 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
+  Keyboard.c\r
+\r
+Abstract:\r
+\r
+  Helper functions for USB Keyboard Driver\r
+\r
+Revision History\r
+\r
+\r
+**/\r
+\r
+#include "keyboard.h"\r
+#include <Library/UsbLib.h>\r
+//\r
+// USB Key Code to Efi key mapping table\r
+// Format:<efi scan code>, <unicode without shift>, <unicode with shift>\r
+//\r
+STATIC\r
+UINT8 KeyConvertionTable[USB_KEYCODE_MAX_MAKE][3] = {\r
+  { SCAN_NULL,      'a',      'A' },      // 0x04\r
+  { SCAN_NULL,      'b',      'B' },      // 0x05\r
+  { SCAN_NULL,      'c',      'C' },      // 0x06\r
+  { SCAN_NULL,      'd',      'D' },      // 0x07\r
+  { SCAN_NULL,      'e',      'E' },      // 0x08\r
+  { SCAN_NULL,      'f',      'F' },      // 0x09\r
+  { SCAN_NULL,      'g',      'G' },      // 0x0A\r
+  { SCAN_NULL,      'h',      'H' },      // 0x0B\r
+  { SCAN_NULL,      'i',      'I' },      // 0x0C\r
+  { SCAN_NULL,      'j',      'J' },      // 0x0D\r
+  { SCAN_NULL,      'k',      'K' },      // 0x0E\r
+  { SCAN_NULL,      'l',      'L' },      // 0x0F\r
+  { SCAN_NULL,      'm',      'M' },      // 0x10\r
+  { SCAN_NULL,      'n',      'N' },      // 0x11\r
+  { SCAN_NULL,      'o',      'O' },      // 0x12\r
+  { SCAN_NULL,      'p',      'P' },      // 0x13\r
+  { SCAN_NULL,      'q',      'Q' },      // 0x14\r
+  { SCAN_NULL,      'r',      'R' },      // 0x15\r
+  { SCAN_NULL,      's',      'S' },      // 0x16\r
+  { SCAN_NULL,      't',      'T' },      // 0x17\r
+  { SCAN_NULL,      'u',      'U' },      // 0x18\r
+  { SCAN_NULL,      'v',      'V' },      // 0x19\r
+  { SCAN_NULL,      'w',      'W' },      // 0x1A\r
+  { SCAN_NULL,      'x',      'X' },      // 0x1B\r
+  { SCAN_NULL,      'y',      'Y' },      // 0x1C\r
+  { SCAN_NULL,      'z',      'Z' },      // 0x1D\r
+  { SCAN_NULL,      '1',      '!' },      // 0x1E\r
+  { SCAN_NULL,      '2',      '@' },      // 0x1F\r
+  { SCAN_NULL,      '3',      '#' },      // 0x20\r
+  { SCAN_NULL,      '4',      '$' },      // 0x21\r
+  { SCAN_NULL,      '5',      '%' },      // 0x22\r
+  { SCAN_NULL,      '6',      '^' },      // 0x23\r
+  { SCAN_NULL,      '7',      '&' },      // 0x24\r
+  { SCAN_NULL,      '8',      '*' },      // 0x25\r
+  { SCAN_NULL,      '9',      '(' },      // 0x26\r
+  { SCAN_NULL,      '0',      ')' },      // 0x27\r
+  { SCAN_NULL,      0x0d,     0x0d },     // 0x28   Enter\r
+  { SCAN_ESC,       0x00,     0x00 },     // 0x29   Esc\r
+  { SCAN_NULL,      0x08,     0x08 },     // 0x2A   Backspace\r
+  { SCAN_NULL,      0x09,     0x09 },     // 0x2B   Tab\r
+  { SCAN_NULL,      ' ',      ' ' },      // 0x2C   Spacebar\r
+  { SCAN_NULL,      '-',      '_' },      // 0x2D\r
+  { SCAN_NULL,      '=',      '+' },      // 0x2E\r
+  { SCAN_NULL,      '[',      '{' },      // 0x2F\r
+  { SCAN_NULL,      ']',      '}' },      // 0x30\r
+  { SCAN_NULL,      '\\',     '|' },      // 0x31\r
+  { SCAN_NULL,      '\\',     '|' },      // 0x32  Keyboard US \ and |\r
+  { SCAN_NULL,      ';',      ':' },      // 0x33\r
+  { SCAN_NULL,      '\'',     '"' },      // 0x34\r
+  { SCAN_NULL,      '`',      '~' },      // 0x35  Keyboard Grave Accent and Tlide\r
+  { SCAN_NULL,      ',',      '<' },      // 0x36\r
+  { SCAN_NULL,      '.',      '>' },      // 0x37\r
+  { SCAN_NULL,      '/',      '?' },      // 0x38\r
+  { SCAN_NULL,      0x00,     0x00 },     // 0x39   CapsLock\r
+  { SCAN_F1,        0x00,     0x00 },     // 0x3A\r
+  { SCAN_F2,        0x00,     0x00 },     // 0x3B\r
+  { SCAN_F3,        0x00,     0x00 },     // 0x3C\r
+  { SCAN_F4,        0x00,     0x00 },     // 0x3D\r
+  { SCAN_F5,        0x00,     0x00 },     // 0x3E\r
+  { SCAN_F6,        0x00,     0x00 },     // 0x3F\r
+  { SCAN_F7,        0x00,     0x00 },     // 0x40\r
+  { SCAN_F8,        0x00,     0x00 },     // 0x41\r
+  { SCAN_F9,        0x00,     0x00 },     // 0x42\r
+  { SCAN_F10,       0x00,     0x00 },     // 0x43\r
+  { SCAN_F11,      0x00,     0x00 },     // 0x44   F11\r
+  { SCAN_F12,      0x00,     0x00 },     // 0x45   F12\r
+  { SCAN_NULL,      0x00,     0x00 },     // 0x46   PrintScreen\r
+  { SCAN_NULL,      0x00,     0x00 },     // 0x47   Scroll Lock\r
+  { SCAN_NULL,      0x00,     0x00 },     // 0x48   Pause\r
+  { SCAN_INSERT,    0x00,     0x00 },     // 0x49\r
+  { SCAN_HOME,      0x00,     0x00 },     // 0x4A\r
+  { SCAN_PAGE_UP,   0x00,     0x00 },     // 0x4B\r
+  { SCAN_DELETE,    0x00,     0x00 },     // 0x4C\r
+  { SCAN_END,       0x00,     0x00 },     // 0x4D\r
+  { SCAN_PAGE_DOWN, 0x00,     0x00 },     // 0x4E\r
+  { SCAN_RIGHT,     0x00,     0x00 },     // 0x4F\r
+  { SCAN_LEFT,      0x00,     0x00 },     // 0x50\r
+  { SCAN_DOWN,      0x00,     0x00 },     // 0x51\r
+  { SCAN_UP,        0x00,     0x00 },     // 0x52\r
+  { SCAN_NULL,      0x00,     0x00 },     // 0x53   NumLock\r
+  { SCAN_NULL,      '/',      '/' },      // 0x54\r
+  { SCAN_NULL,      '*',      '*' },      // 0x55\r
+  { SCAN_NULL,      '-',      '-' },      // 0x56\r
+  { SCAN_NULL,      '+',      '+' },      // 0x57\r
+  { SCAN_NULL,      0x0d,     0x0d },     // 0x58\r
+  { SCAN_END,       '1',      '1' },      // 0x59\r
+  { SCAN_DOWN,      '2',      '2' },      // 0x5A\r
+  { SCAN_PAGE_DOWN, '3',      '3' },      // 0x5B\r
+  { SCAN_LEFT,      '4',      '4' },      // 0x5C\r
+  { SCAN_NULL,      '5',      '5' },      // 0x5D\r
+  { SCAN_RIGHT,     '6',      '6' },      // 0x5E\r
+  { SCAN_HOME,      '7',      '7' },      // 0x5F\r
+  { SCAN_UP,        '8',      '8' },      // 0x60\r
+  { SCAN_PAGE_UP,   '9',      '9' },      // 0x61\r
+  { SCAN_INSERT,    '0',      '0' },      // 0x62\r
+  { SCAN_DELETE,    '.',      '.' },      // 0x63\r
+  { SCAN_NULL,      '\\',     '|' },      // 0x64 Keyboard Non-US \ and |\r
+  { SCAN_NULL,      0x00,     0x00 },     // 0x65 Keyboard Application\r
+  { SCAN_NULL,      0x00,     0x00 },     // 0x66 Keyboard Power\r
+  { SCAN_NULL,      '=' ,     '='  }      // 0x67 Keypad =\r
+};\r
+\r
+STATIC KB_MODIFIER  KB_Mod[8] = {\r
+  { MOD_CONTROL_L,  0xe0 }, // 11100000\r
+  { MOD_CONTROL_R,  0xe4 }, // 11100100\r
+  { MOD_SHIFT_L,    0xe1 }, // 11100001\r
+  { MOD_SHIFT_R,    0xe5 }, // 11100101\r
+  { MOD_ALT_L,      0xe2 }, // 11100010\r
+  { MOD_ALT_R,      0xe6 }, // 11100110\r
+  { MOD_WIN_L,      0xe3 }, // 11100011\r
+  { MOD_WIN_R,      0xe7 }  // 11100111\r
+};\r
+\r
+\r
+\r
+/**\r
+  Uses USB I/O to check whether the device is a USB Keyboard device.\r
+\r
+  UsbIo:    Points to a USB I/O protocol instance.\r
+\r
+\r
+**/\r
+BOOLEAN\r
+IsUSBKeyboard (\r
+  IN  EFI_USB_IO_PROTOCOL       *UsbIo\r
+  )\r
+{\r
+  EFI_STATUS                    Status;\r
+  EFI_USB_INTERFACE_DESCRIPTOR  InterfaceDescriptor;\r
+\r
+  //\r
+  // Get the Default interface descriptor, currently we\r
+  // assume it is interface 1\r
+  //\r
+  Status = UsbIo->UsbGetInterfaceDescriptor (\r
+                    UsbIo,\r
+                    &InterfaceDescriptor\r
+                    );\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return FALSE;\r
+  }\r
+\r
+  if (InterfaceDescriptor.InterfaceClass == CLASS_HID &&\r
+      InterfaceDescriptor.InterfaceSubClass == SUBCLASS_BOOT &&\r
+      InterfaceDescriptor.InterfaceProtocol == PROTOCOL_KEYBOARD\r
+      ) {\r
+\r
+    return TRUE;\r
+  }\r
+\r
+  return FALSE;\r
+}\r
+\r
+\r
+\r
+/**\r
+  Initialize USB Keyboard device and all private data structures.\r
+\r
+  UsbKeyboardDevice    The USB_KB_DEV instance.\r
+\r
+  @retval EFI_SUCCESS        Success\r
+  @retval EFI_DEVICE_ERROR   Hardware Error\r
+\r
+**/\r
+EFI_STATUS\r
+InitUSBKeyboard (\r
+  IN USB_KB_DEV   *UsbKeyboardDevice\r
+  )\r
+{\r
+  UINT8               ConfigValue;\r
+  UINT8               Protocol;\r
+  UINT8               ReportId;\r
+  UINT8               Duration;\r
+  EFI_STATUS          Status;\r
+  UINT32              TransferResult;\r
+  EFI_USB_IO_PROTOCOL *UsbIo;\r
+\r
+  UsbIo = UsbKeyboardDevice->UsbIo;\r
+\r
+  KbdReportStatusCode (\r
+    UsbKeyboardDevice->DevicePath,\r
+    EFI_PROGRESS_CODE,\r
+    PcdGet32 (PcdStatusCodeValueKeyboardSelfTest)\r
+    );\r
+\r
+  InitUSBKeyBuffer (&(UsbKeyboardDevice->KeyboardBuffer));\r
+\r
+  //\r
+  // default configurations\r
+  //\r
+  ConfigValue = 0x01;\r
+\r
+  //\r
+  // Uses default configuration to configure the USB Keyboard device.\r
+  //\r
+  Status = UsbSetConfiguration (\r
+            UsbKeyboardDevice->UsbIo,\r
+            (UINT16) ConfigValue,\r
+            &TransferResult\r
+            );\r
+  if (EFI_ERROR (Status)) {\r
+    //\r
+    // If configuration could not be set here, it means\r
+    // the keyboard interface has some errors and could\r
+    // not be initialized\r
+    //\r
+    KbdReportStatusCode (\r
+      UsbKeyboardDevice->DevicePath,\r
+      EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
+      PcdGet32 (PcdStatusCodeValueKeyboardInterfaceError)\r
+      );\r
+\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  UsbGetProtocolRequest (\r
+    UsbKeyboardDevice->UsbIo,\r
+    UsbKeyboardDevice->InterfaceDescriptor.InterfaceNumber,\r
+    &Protocol\r
+    );\r
+  //\r
+  // Sets boot protocol for the USB Keyboard.\r
+  // This driver only supports boot protocol.\r
+  // !!BugBug: How about the device that does not support boot protocol?\r
+  //\r
+  if (Protocol != BOOT_PROTOCOL) {\r
+    UsbSetProtocolRequest (\r
+      UsbKeyboardDevice->UsbIo,\r
+      UsbKeyboardDevice->InterfaceDescriptor.InterfaceNumber,\r
+      BOOT_PROTOCOL\r
+      );\r
+  }\r
+  //\r
+  // the duration is indefinite, so the endpoint will inhibit reporting forever,\r
+  // and only reporting when a change is detected in the report data.\r
+  //\r
+\r
+  //\r
+  // idle value for all report ID\r
+  //\r
+  ReportId = 0;\r
+  //\r
+  // idle forever until there is a key pressed and released.\r
+  //\r
+  Duration = 0;\r
+  UsbSetIdleRequest (\r
+    UsbKeyboardDevice->UsbIo,\r
+    UsbKeyboardDevice->InterfaceDescriptor.InterfaceNumber,\r
+    ReportId,\r
+    Duration\r
+    );\r
+\r
+  UsbKeyboardDevice->CtrlOn     = 0;\r
+  UsbKeyboardDevice->AltOn      = 0;\r
+  UsbKeyboardDevice->ShiftOn    = 0;\r
+  UsbKeyboardDevice->NumLockOn  = 0;\r
+  UsbKeyboardDevice->CapsOn     = 0;\r
+  UsbKeyboardDevice->ScrollOn   = 0;\r
+\r
+  //\r
+  // Sync the initial state of lights\r
+  //\r
+  SetKeyLED (UsbKeyboardDevice);\r
+\r
+  ZeroMem (UsbKeyboardDevice->LastKeyCodeArray, sizeof (UINT8) * 8);\r
+\r
+  //\r
+  // Set a timer for repeat keys' generation.\r
+  //\r
+  if (UsbKeyboardDevice->RepeatTimer) {\r
+    gBS->CloseEvent (UsbKeyboardDevice->RepeatTimer);\r
+    UsbKeyboardDevice->RepeatTimer = 0;\r
+  }\r
+\r
+  Status = gBS->CreateEvent (\r
+                  EVT_TIMER | EVT_NOTIFY_SIGNAL,\r
+                  TPL_NOTIFY,\r
+                  USBKeyboardRepeatHandler,\r
+                  UsbKeyboardDevice,\r
+                  &UsbKeyboardDevice->RepeatTimer\r
+                  );\r
+\r
+  if (UsbKeyboardDevice->DelayedRecoveryEvent) {\r
+    gBS->CloseEvent (UsbKeyboardDevice->DelayedRecoveryEvent);\r
+    UsbKeyboardDevice->DelayedRecoveryEvent = 0;\r
+  }\r
+\r
+  Status = gBS->CreateEvent (\r
+                  EVT_TIMER | EVT_NOTIFY_SIGNAL,\r
+                  TPL_NOTIFY,\r
+                  USBKeyboardRecoveryHandler,\r
+                  UsbKeyboardDevice,\r
+                  &UsbKeyboardDevice->DelayedRecoveryEvent\r
+                  );\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+  Handler function for USB Keyboard's asynchronous interrupt transfer.\r
+\r
+  Data       A pointer to a buffer that is filled with key data which is\r
+  retrieved via asynchronous interrupt transfer.\r
+  DataLength Indicates the size of the data buffer.\r
+  Context    Pointing to USB_KB_DEV instance.\r
+  Result     Indicates the result of the asynchronous interrupt transfer.\r
+\r
+  @retval EFI_SUCCESS        Success\r
+  @retval EFI_DEVICE_ERROR   Hardware Error\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+KeyboardHandler (\r
+  IN  VOID          *Data,\r
+  IN  UINTN         DataLength,\r
+  IN  VOID          *Context,\r
+  IN  UINT32        Result\r
+  )\r
+{\r
+  USB_KB_DEV          *UsbKeyboardDevice;\r
+  EFI_USB_IO_PROTOCOL *UsbIo;\r
+  UINT8               *CurKeyCodeBuffer;\r
+  UINT8               *OldKeyCodeBuffer;\r
+  UINT8               CurModifierMap;\r
+  UINT8               OldModifierMap;\r
+  UINT8               Index;\r
+  UINT8               Index2;\r
+  BOOLEAN             Down;\r
+  EFI_STATUS          Status;\r
+  BOOLEAN             KeyRelease;\r
+  BOOLEAN             KeyPress;\r
+  UINT8               SavedTail;\r
+  USB_KEY             UsbKey;\r
+  UINT8               NewRepeatKey;\r
+  UINT32              UsbStatus;\r
+  UINT8               *DataPtr;\r
+\r
+  ASSERT (Context);\r
+\r
+  NewRepeatKey      = 0;\r
+  DataPtr           = (UINT8 *) Data;\r
+  UsbKeyboardDevice = (USB_KB_DEV *) Context;\r
+  UsbIo             = UsbKeyboardDevice->UsbIo;\r
+\r
+  //\r
+  // Analyzes the Result and performs corresponding action.\r
+  //\r
+  if (Result != EFI_USB_NOERROR) {\r
+    //\r
+    // Some errors happen during the process\r
+    //\r
+    KbdReportStatusCode (\r
+      UsbKeyboardDevice->DevicePath,\r
+      EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
+      PcdGet32 (PcdStatusCodeValueKeyboardInputError)\r
+      );\r
+\r
+    //\r
+    // stop the repeat key generation if any\r
+    //\r
+    UsbKeyboardDevice->RepeatKey = 0;\r
+\r
+    gBS->SetTimer (\r
+          UsbKeyboardDevice->RepeatTimer,\r
+          TimerCancel,\r
+          USBKBD_REPEAT_RATE\r
+          );\r
+\r
+    if ((Result & EFI_USB_ERR_STALL) == EFI_USB_ERR_STALL) {\r
+      UsbClearEndpointHalt (\r
+        UsbIo,\r
+        UsbKeyboardDevice->IntEndpointDescriptor.EndpointAddress,\r
+        &UsbStatus\r
+        );\r
+    }\r
+\r
+    //\r
+    // Delete & Submit this interrupt again\r
+    //\r
+\r
+    Status = UsbIo->UsbAsyncInterruptTransfer (\r
+                      UsbIo,\r
+                      UsbKeyboardDevice->IntEndpointDescriptor.EndpointAddress,\r
+                      FALSE,\r
+                      0,\r
+                      0,\r
+                      NULL,\r
+                      NULL\r
+                      );\r
+\r
+    gBS->SetTimer (\r
+          UsbKeyboardDevice->DelayedRecoveryEvent,\r
+          TimerRelative,\r
+          EFI_USB_INTERRUPT_DELAY\r
+          );\r
+\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  if (DataLength == 0 || Data == NULL) {\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  CurKeyCodeBuffer  = (UINT8 *) Data;\r
+  OldKeyCodeBuffer  = UsbKeyboardDevice->LastKeyCodeArray;\r
+\r
+  //\r
+  // checks for new key stroke.\r
+  // if no new key got, return immediately.\r
+  //\r
+  for (Index = 0; Index < 8; Index++) {\r
+    if (OldKeyCodeBuffer[Index] != CurKeyCodeBuffer[Index]) {\r
+      break;\r
+    }\r
+  }\r
+\r
+  if (Index == 8) {\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  //\r
+  // Parse the modifier key\r
+  //\r
+  CurModifierMap  = CurKeyCodeBuffer[0];\r
+  OldModifierMap  = OldKeyCodeBuffer[0];\r
+\r
+  //\r
+  // handle modifier key's pressing or releasing situation.\r
+  //\r
+  for (Index = 0; Index < 8; Index++) {\r
+\r
+    if ((CurModifierMap & KB_Mod[Index].Mask) != (OldModifierMap & KB_Mod[Index].Mask)) {\r
+      //\r
+      // if current modifier key is up, then\r
+      // CurModifierMap & KB_Mod[Index].Mask = 0;\r
+      // otherwize it is a non-zero value.\r
+      // Inserts the pressed modifier key into key buffer.\r
+      //\r
+      Down = (UINT8) (CurModifierMap & KB_Mod[Index].Mask);\r
+      InsertKeyCode (&(UsbKeyboardDevice->KeyboardBuffer), KB_Mod[Index].Key, Down);\r
+    }\r
+  }\r
+\r
+  //\r
+  // handle normal key's releasing situation\r
+  //\r
+  KeyRelease = FALSE;\r
+  for (Index = 2; Index < 8; Index++) {\r
+\r
+    if (!USBKBD_VALID_KEYCODE (OldKeyCodeBuffer[Index])) {\r
+      continue;\r
+    }\r
+\r
+    KeyRelease = TRUE;\r
+    for (Index2 = 2; Index2 < 8; Index2++) {\r
+\r
+      if (!USBKBD_VALID_KEYCODE (CurKeyCodeBuffer[Index2])) {\r
+        continue;\r
+      }\r
+\r
+      if (OldKeyCodeBuffer[Index] == CurKeyCodeBuffer[Index2]) {\r
+        KeyRelease = FALSE;\r
+        break;\r
+      }\r
+    }\r
+\r
+    if (KeyRelease) {\r
+      InsertKeyCode (\r
+        &(UsbKeyboardDevice->KeyboardBuffer),\r
+        OldKeyCodeBuffer[Index],\r
+        0\r
+        );\r
+      //\r
+      // the original reapeat key is released.\r
+      //\r
+      if (OldKeyCodeBuffer[Index] == UsbKeyboardDevice->RepeatKey) {\r
+        UsbKeyboardDevice->RepeatKey = 0;\r
+      }\r
+    }\r
+  }\r
+\r
+  //\r
+  // original repeat key is released, cancel the repeat timer\r
+  //\r
+  if (UsbKeyboardDevice->RepeatKey == 0) {\r
+    gBS->SetTimer (\r
+          UsbKeyboardDevice->RepeatTimer,\r
+          TimerCancel,\r
+          USBKBD_REPEAT_RATE\r
+          );\r
+  }\r
+\r
+  //\r
+  // handle normal key's pressing situation\r
+  //\r
+  KeyPress = FALSE;\r
+  for (Index = 2; Index < 8; Index++) {\r
+\r
+    if (!USBKBD_VALID_KEYCODE (CurKeyCodeBuffer[Index])) {\r
+      continue;\r
+    }\r
+\r
+    KeyPress = TRUE;\r
+    for (Index2 = 2; Index2 < 8; Index2++) {\r
+\r
+      if (!USBKBD_VALID_KEYCODE (OldKeyCodeBuffer[Index2])) {\r
+        continue;\r
+      }\r
+\r
+      if (CurKeyCodeBuffer[Index] == OldKeyCodeBuffer[Index2]) {\r
+        KeyPress = FALSE;\r
+        break;\r
+      }\r
+    }\r
+\r
+    if (KeyPress) {\r
+      InsertKeyCode (&(UsbKeyboardDevice->KeyboardBuffer), CurKeyCodeBuffer[Index], 1);\r
+      //\r
+      // NumLock pressed or CapsLock pressed\r
+      //\r
+      if (CurKeyCodeBuffer[Index] == 0x53 || CurKeyCodeBuffer[Index] == 0x39) {\r
+        UsbKeyboardDevice->RepeatKey = 0;\r
+      } else {\r
+        NewRepeatKey = CurKeyCodeBuffer[Index];\r
+        //\r
+        // do not repeat the original repeated key\r
+        //\r
+        UsbKeyboardDevice->RepeatKey = 0;\r
+      }\r
+    }\r
+  }\r
+\r
+  //\r
+  // Update LastKeycodeArray[] buffer in the\r
+  // Usb Keyboard Device data structure.\r
+  //\r
+  for (Index = 0; Index < 8; Index++) {\r
+    UsbKeyboardDevice->LastKeyCodeArray[Index] = CurKeyCodeBuffer[Index];\r
+  }\r
+\r
+  //\r
+  // pre-process KeyboardBuffer, pop out the ctrl,alt,del key in sequence\r
+  // and judge whether it will invoke reset event.\r
+  //\r
+  SavedTail = UsbKeyboardDevice->KeyboardBuffer.bTail;\r
+  Index     = UsbKeyboardDevice->KeyboardBuffer.bHead;\r
+  while (Index != SavedTail) {\r
+    RemoveKeyCode (&(UsbKeyboardDevice->KeyboardBuffer), &UsbKey);\r
+\r
+    switch (UsbKey.KeyCode) {\r
+\r
+    case 0xe0:\r
+    case 0xe4:\r
+      if (UsbKey.Down) {\r
+        UsbKeyboardDevice->CtrlOn = 1;\r
+      } else {\r
+        UsbKeyboardDevice->CtrlOn = 0;\r
+      }\r
+      break;\r
+\r
+    case 0xe2:\r
+    case 0xe6:\r
+      if (UsbKey.Down) {\r
+        UsbKeyboardDevice->AltOn = 1;\r
+      } else {\r
+        UsbKeyboardDevice->AltOn = 0;\r
+      }\r
+      break;\r
+\r
+    //\r
+    // Del Key Code\r
+    //\r
+    case 0x4c:\r
+    case 0x63:\r
+      if (UsbKey.Down) {\r
+        if (UsbKeyboardDevice->CtrlOn && UsbKeyboardDevice->AltOn) {\r
+          gRT->ResetSystem (EfiResetWarm, EFI_SUCCESS, 0, NULL);\r
+        }\r
+      }\r
+      break;\r
+\r
+    default:\r
+      break;\r
+    }\r
+\r
+    //\r
+    // insert the key back to the buffer.\r
+    // so the key sequence will not be destroyed.\r
+    //\r
+    InsertKeyCode (\r
+      &(UsbKeyboardDevice->KeyboardBuffer),\r
+      UsbKey.KeyCode,\r
+      UsbKey.Down\r
+      );\r
+    Index = UsbKeyboardDevice->KeyboardBuffer.bHead;\r
+\r
+  }\r
+  //\r
+  // If have new key pressed, update the RepeatKey value, and set the\r
+  // timer to repeate delay timer\r
+  //\r
+  if (NewRepeatKey != 0) {\r
+    //\r
+    // sets trigger time to "Repeat Delay Time",\r
+    // to trigger the repeat timer when the key is hold long\r
+    // enough time.\r
+    //\r
+    gBS->SetTimer (\r
+          UsbKeyboardDevice->RepeatTimer,\r
+          TimerRelative,\r
+          USBKBD_REPEAT_DELAY\r
+          );\r
+    UsbKeyboardDevice->RepeatKey = NewRepeatKey;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+  Retrieves a key character after parsing the raw data in keyboard buffer.\r
+\r
+  UsbKeyboardDevice    The USB_KB_DEV instance.\r
+  KeyChar              Points to the Key character after key parsing.\r
+\r
+  @retval EFI_SUCCESS        Success\r
+  @retval EFI_NOT_READY      Device is not ready\r
+\r
+**/\r
+EFI_STATUS\r
+USBParseKey (\r
+  IN OUT  USB_KB_DEV  *UsbKeyboardDevice,\r
+  OUT     UINT8       *KeyChar\r
+  )\r
+{\r
+  USB_KEY UsbKey;\r
+\r
+  *KeyChar = 0;\r
+\r
+  while (!IsUSBKeyboardBufferEmpty (&UsbKeyboardDevice->KeyboardBuffer)) {\r
+    //\r
+    // pops one raw data off.\r
+    //\r
+    RemoveKeyCode (&(UsbKeyboardDevice->KeyboardBuffer), &UsbKey);\r
+\r
+    if (!UsbKey.Down) {\r
+      switch (UsbKey.KeyCode) {\r
+\r
+      case 0xe0:\r
+      case 0xe4:\r
+        UsbKeyboardDevice->CtrlOn = 0;\r
+        break;\r
+\r
+      case 0xe1:\r
+      case 0xe5:\r
+        UsbKeyboardDevice->ShiftOn = 0;\r
+        break;\r
+\r
+      case 0xe2:\r
+      case 0xe6:\r
+        UsbKeyboardDevice->AltOn = 0;\r
+        break;\r
+\r
+      default:\r
+        break;\r
+      }\r
+\r
+      continue;\r
+    }\r
+\r
+    //\r
+    // Analyzes key pressing situation\r
+    //\r
+    switch (UsbKey.KeyCode) {\r
+\r
+    case 0xe0:\r
+    case 0xe4:\r
+      UsbKeyboardDevice->CtrlOn = 1;\r
+      continue;\r
+      break;\r
+\r
+    case 0xe1:\r
+    case 0xe5:\r
+      UsbKeyboardDevice->ShiftOn = 1;\r
+      continue;\r
+      break;\r
+\r
+    case 0xe2:\r
+    case 0xe6:\r
+      UsbKeyboardDevice->AltOn = 1;\r
+      continue;\r
+      break;\r
+\r
+    case 0xe3:\r
+    case 0xe7:\r
+      continue;\r
+      break;\r
+\r
+    case 0x53:\r
+      UsbKeyboardDevice->NumLockOn ^= 1;\r
+    //\r
+    // Turn on the NumLock light on KB\r
+    //\r
+      SetKeyLED (UsbKeyboardDevice);\r
+      continue;\r
+      break;\r
+\r
+    case 0x39:\r
+      UsbKeyboardDevice->CapsOn ^= 1;\r
+    //\r
+    // Turn on the CapsLock light on KB\r
+    //\r
+      SetKeyLED (UsbKeyboardDevice);\r
+      continue;\r
+      break;\r
+\r
+    case 0x47:\r
+      UsbKeyboardDevice->ScrollOn ^= 1;\r
+    //\r
+    // Turn on the ScrollLock light on KB\r
+    //\r
+      SetKeyLED (UsbKeyboardDevice);\r
+      continue;\r
+      break;\r
+\r
+    //\r
+    // PrintScreen,Pause,Application,Power\r
+    // keys are not valid EFI key\r
+    //\r
+\r
+    case 0x46:\r
+    //\r
+    // fall through\r
+    //\r
+    case 0x48:\r
+    //\r
+    // fall through\r
+    //\r
+    case 0x65:\r
+    //\r
+    // fall through\r
+    //\r
+    case 0x66:\r
+    //\r
+    // fall through\r
+    //\r
+      continue;\r
+      break;\r
+\r
+    default:\r
+      break;\r
+    }\r
+\r
+    //\r
+    // When encountered Del Key...\r
+    //\r
+    if (UsbKey.KeyCode == 0x4c || UsbKey.KeyCode == 0x63) {\r
+      if (UsbKeyboardDevice->CtrlOn && UsbKeyboardDevice->AltOn) {\r
+        gRT->ResetSystem (EfiResetWarm, EFI_SUCCESS, 0, NULL);\r
+      }\r
+    }\r
+\r
+    *KeyChar = UsbKey.KeyCode;\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  return EFI_NOT_READY;\r
+\r
+}\r
+\r
+\r
+\r
+/**\r
+  Converts USB Keyboard code to EFI Scan Code.\r
+\r
+  UsbKeyboardDevice    The USB_KB_DEV instance.\r
+  KeyChar              Indicates the key code that will be interpreted.\r
+  Key                  A pointer to a buffer that is filled in with\r
+  the keystroke information for the key that\r
+  was pressed.\r
+\r
+  @retval EFI_NOT_READY      Device is not ready\r
+  @retval EFI_SUCCESS        Success\r
+\r
+**/\r
+EFI_STATUS\r
+USBKeyCodeToEFIScanCode (\r
+  IN  USB_KB_DEV      *UsbKeyboardDevice,\r
+  IN  UINT8           KeyChar,\r
+  OUT EFI_INPUT_KEY   *Key\r
+  )\r
+{\r
+  UINT8 Index;\r
+\r
+  if (!USBKBD_VALID_KEYCODE (KeyChar)) {\r
+    return EFI_NOT_READY;\r
+  }\r
+\r
+  //\r
+  // valid USB Key Code starts from 4\r
+  //\r
+  Index = (UINT8) (KeyChar - 4);\r
+\r
+  if (Index >= USB_KEYCODE_MAX_MAKE) {\r
+    return EFI_NOT_READY;\r
+  }\r
+\r
+  Key->ScanCode = KeyConvertionTable[Index][0];\r
+\r
+  if (UsbKeyboardDevice->ShiftOn) {\r
+\r
+    Key->UnicodeChar = KeyConvertionTable[Index][2];\r
+\r
+  } else {\r
+\r
+    Key->UnicodeChar = KeyConvertionTable[Index][1];\r
+  }\r
+\r
+  if (UsbKeyboardDevice->CapsOn) {\r
+\r
+    if (Key->UnicodeChar >= 'a' && Key->UnicodeChar <= 'z') {\r
+\r
+      Key->UnicodeChar = KeyConvertionTable[Index][2];\r
+\r
+    } else if (Key->UnicodeChar >= 'A' && Key->UnicodeChar <= 'Z') {\r
+\r
+      Key->UnicodeChar = KeyConvertionTable[Index][1];\r
+\r
+    }\r
+  }\r
+\r
+  if (KeyChar >= 0x59 && KeyChar <= 0x63) {\r
+\r
+    if (UsbKeyboardDevice->NumLockOn && !UsbKeyboardDevice->ShiftOn) {\r
+\r
+      Key->ScanCode = SCAN_NULL;\r
+\r
+    } else {\r
+\r
+      Key->UnicodeChar = 0x00;\r
+    }\r
+  }\r
+\r
+  if (Key->UnicodeChar == 0 && Key->ScanCode == SCAN_NULL) {\r
+    return EFI_NOT_READY;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+\r
+}\r
+\r
+\r
+\r
+/**\r
+  Resets USB Keyboard Buffer.\r
+\r
+  @param  KeyboardBuffer     Points to the USB Keyboard Buffer.\r
+\r
+  @retval EFI_SUCCESS        Success\r
+\r
+**/\r
+EFI_STATUS\r
+InitUSBKeyBuffer (\r
+  IN OUT  USB_KB_BUFFER   *KeyboardBuffer\r
+  )\r
+{\r
+  ZeroMem (KeyboardBuffer, sizeof (USB_KB_BUFFER));\r
+\r
+  KeyboardBuffer->bHead = KeyboardBuffer->bTail;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+  Check whether USB Keyboard buffer is empty.\r
+\r
+  @param  KeyboardBuffer     USB Keyboard Buffer.\r
+\r
+\r
+**/\r
+BOOLEAN\r
+IsUSBKeyboardBufferEmpty (\r
+  IN  USB_KB_BUFFER   *KeyboardBuffer\r
+  )\r
+{\r
+  //\r
+  // meet FIFO empty condition\r
+  //\r
+  return (BOOLEAN) (KeyboardBuffer->bHead == KeyboardBuffer->bTail);\r
+}\r
+\r
+\r
+\r
+/**\r
+  Check whether USB Keyboard buffer is full.\r
+\r
+  @param  KeyboardBuffer     USB Keyboard Buffer.\r
+\r
+\r
+**/\r
+BOOLEAN\r
+IsUSBKeyboardBufferFull (\r
+  IN  USB_KB_BUFFER   *KeyboardBuffer\r
+  )\r
+{\r
+  return (BOOLEAN)(((KeyboardBuffer->bTail + 1) % (MAX_KEY_ALLOWED + 1)) ==\r
+                                                        KeyboardBuffer->bHead);\r
+}\r
+\r
+\r
+\r
+/**\r
+  Inserts a key code into keyboard buffer.\r
+\r
+  @param  KeyboardBuffer     Points to the USB Keyboard Buffer.\r
+  @param  Key                Key code\r
+  @param  Down               Special key\r
+\r
+  @retval EFI_SUCCESS        Success\r
+\r
+**/\r
+EFI_STATUS\r
+InsertKeyCode (\r
+  IN OUT  USB_KB_BUFFER *KeyboardBuffer,\r
+  IN      UINT8         Key,\r
+  IN      UINT8         Down\r
+  )\r
+{\r
+  USB_KEY UsbKey;\r
+\r
+  //\r
+  // if keyboard buffer is full, throw the\r
+  // first key out of the keyboard buffer.\r
+  //\r
+  if (IsUSBKeyboardBufferFull (KeyboardBuffer)) {\r
+    RemoveKeyCode (KeyboardBuffer, &UsbKey);\r
+  }\r
+\r
+  KeyboardBuffer->buffer[KeyboardBuffer->bTail].KeyCode = Key;\r
+  KeyboardBuffer->buffer[KeyboardBuffer->bTail].Down    = Down;\r
+\r
+  //\r
+  // adjust the tail pointer of the FIFO keyboard buffer.\r
+  //\r
+  KeyboardBuffer->bTail = (UINT8) ((KeyboardBuffer->bTail + 1) % (MAX_KEY_ALLOWED + 1));\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+  Pops a key code off from keyboard buffer.\r
+\r
+  @param  KeyboardBuffer     Points to the USB Keyboard Buffer.\r
+  @param  UsbKey             Points to the buffer that contains a usb key code.\r
+\r
+  @retval EFI_SUCCESS        Success\r
+  @retval EFI_DEVICE_ERROR   Hardware Error\r
+\r
+**/\r
+EFI_STATUS\r
+RemoveKeyCode (\r
+  IN OUT  USB_KB_BUFFER *KeyboardBuffer,\r
+  OUT     USB_KEY       *UsbKey\r
+  )\r
+{\r
+  if (IsUSBKeyboardBufferEmpty (KeyboardBuffer)) {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  UsbKey->KeyCode = KeyboardBuffer->buffer[KeyboardBuffer->bHead].KeyCode;\r
+  UsbKey->Down    = KeyboardBuffer->buffer[KeyboardBuffer->bHead].Down;\r
+\r
+  //\r
+  // adjust the head pointer of the FIFO keyboard buffer.\r
+  //\r
+  KeyboardBuffer->bHead = (UINT8) ((KeyboardBuffer->bHead + 1) % (MAX_KEY_ALLOWED + 1));\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+  Sets USB Keyboard LED state.\r
+\r
+  @param  UsbKeyboardDevice  The USB_KB_DEV instance.\r
+\r
+  @retval EFI_SUCCESS        Success\r
+\r
+**/\r
+EFI_STATUS\r
+SetKeyLED (\r
+  IN  USB_KB_DEV    *UsbKeyboardDevice\r
+  )\r
+{\r
+  LED_MAP Led;\r
+  UINT8   ReportId;\r
+\r
+  //\r
+  // Set each field in Led map.\r
+  //\r
+  Led.NumLock    = (UINT8) UsbKeyboardDevice->NumLockOn;\r
+  Led.CapsLock   = (UINT8) UsbKeyboardDevice->CapsOn;\r
+  Led.ScrollLock = (UINT8) UsbKeyboardDevice->ScrollOn;\r
+  Led.Resrvd     = 0;\r
+\r
+  ReportId       = 0;\r
+  //\r
+  // call Set Report Request to lighten the LED.\r
+  //\r
+  UsbSetReportRequest (\r
+    UsbKeyboardDevice->UsbIo,\r
+    UsbKeyboardDevice->InterfaceDescriptor.InterfaceNumber,\r
+    ReportId,\r
+    HID_OUTPUT_REPORT,\r
+    1,\r
+    (UINT8 *) &Led\r
+    );\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+  Timer handler for Repeat Key timer.\r
+\r
+  @param  Event              The Repeat Key event.\r
+  @param  Context            Points to the USB_KB_DEV instance.\r
+\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+USBKeyboardRepeatHandler (\r
+  IN    EFI_EVENT    Event,\r
+  IN    VOID         *Context\r
+  )\r
+{\r
+  USB_KB_DEV  *UsbKeyboardDevice;\r
+\r
+  UsbKeyboardDevice = (USB_KB_DEV *) Context;\r
+\r
+  //\r
+  // Do nothing when there is no repeat key.\r
+  //\r
+  if (UsbKeyboardDevice->RepeatKey != 0) {\r
+    //\r
+    // Inserts one Repeat key into keyboard buffer,\r
+    //\r
+    InsertKeyCode (\r
+      &(UsbKeyboardDevice->KeyboardBuffer),\r
+      UsbKeyboardDevice->RepeatKey,\r
+      1\r
+      );\r
+\r
+    //\r
+    // set repeate rate for repeat key generation.\r
+    //\r
+    gBS->SetTimer (\r
+          UsbKeyboardDevice->RepeatTimer,\r
+          TimerRelative,\r
+          USBKBD_REPEAT_RATE\r
+          );\r
+\r
+  }\r
+}\r
+\r
+\r
+/**\r
+  Timer handler for Delayed Recovery timer.\r
+\r
+  @param  Event              The Delayed Recovery event.\r
+  @param  Context            Points to the USB_KB_DEV instance.\r
+\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+USBKeyboardRecoveryHandler (\r
+  IN    EFI_EVENT    Event,\r
+  IN    VOID         *Context\r
+  )\r
+{\r
+\r
+  USB_KB_DEV          *UsbKeyboardDevice;\r
+  EFI_USB_IO_PROTOCOL *UsbIo;\r
+  UINT8               PacketSize;\r
+\r
+  UsbKeyboardDevice = (USB_KB_DEV *) Context;\r
+\r
+  UsbIo             = UsbKeyboardDevice->UsbIo;\r
+\r
+  PacketSize        = (UINT8) (UsbKeyboardDevice->IntEndpointDescriptor.MaxPacketSize);\r
+\r
+  UsbIo->UsbAsyncInterruptTransfer (\r
+          UsbIo,\r
+          UsbKeyboardDevice->IntEndpointDescriptor.EndpointAddress,\r
+          TRUE,\r
+          UsbKeyboardDevice->IntEndpointDescriptor.Interval,\r
+          PacketSize,\r
+          KeyboardHandler,\r
+          UsbKeyboardDevice\r
+          );\r
+}\r
diff --git a/MdeModulePkg/Bus/Usb/UsbKbDxe/keyboard.h b/MdeModulePkg/Bus/Usb/UsbKbDxe/keyboard.h
new file mode 100644 (file)
index 0000000..9a8cb0f
--- /dev/null
@@ -0,0 +1,108 @@
+/** @file\r
+Copyright (c) 2004 - 2005, 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
+    Keyboard.h\r
+\r
+Abstract:\r
+\r
+    Function prototype for USB Keyboard Driver\r
+\r
+Revision History\r
+\r
+**/\r
+\r
+#ifndef _KEYBOARD_H\r
+#define _KEYBOARD_H\r
+\r
+\r
+#include "efikey.h"\r
+\r
+BOOLEAN\r
+IsUSBKeyboard (\r
+  IN  EFI_USB_IO_PROTOCOL       *UsbIo\r
+  );\r
+\r
+EFI_STATUS\r
+InitUSBKeyboard (\r
+  IN USB_KB_DEV   *UsbKeyboardDevice\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+KeyboardHandler (\r
+  IN  VOID          *Data,\r
+  IN  UINTN         DataLength,\r
+  IN  VOID          *Context,\r
+  IN  UINT32        Result\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+USBKeyboardRecoveryHandler (\r
+  IN    EFI_EVENT    Event,\r
+  IN    VOID         *Context\r
+  );\r
+\r
+EFI_STATUS\r
+USBParseKey (\r
+  IN OUT  USB_KB_DEV  *UsbKeyboardDevice,\r
+  OUT     UINT8       *KeyChar\r
+  );\r
+\r
+EFI_STATUS\r
+USBKeyCodeToEFIScanCode (\r
+  IN  USB_KB_DEV      *UsbKeyboardDevice,\r
+  IN  UINT8           KeyChar,\r
+  OUT EFI_INPUT_KEY   *Key\r
+  );\r
+\r
+EFI_STATUS\r
+InitUSBKeyBuffer (\r
+  IN OUT  USB_KB_BUFFER   *KeyboardBuffer\r
+  );\r
+\r
+BOOLEAN\r
+IsUSBKeyboardBufferEmpty (\r
+  IN  USB_KB_BUFFER   *KeyboardBuffer\r
+  );\r
+\r
+BOOLEAN\r
+IsUSBKeyboardBufferFull (\r
+  IN  USB_KB_BUFFER   *KeyboardBuffer\r
+  );\r
+\r
+EFI_STATUS\r
+InsertKeyCode (\r
+  IN OUT  USB_KB_BUFFER *KeyboardBuffer,\r
+  IN      UINT8         Key,\r
+  IN      UINT8         Down\r
+  );\r
+\r
+EFI_STATUS\r
+RemoveKeyCode (\r
+  IN OUT  USB_KB_BUFFER *KeyboardBuffer,\r
+  OUT     USB_KEY       *UsbKey\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+USBKeyboardRepeatHandler (\r
+  IN    EFI_EVENT    Event,\r
+  IN    VOID         *Context\r
+  );\r
+\r
+EFI_STATUS\r
+SetKeyLED (\r
+  IN  USB_KB_DEV    *UsbKeyboardDevice\r
+  );\r
+\r
+#endif\r
diff --git a/MdeModulePkg/Bus/Usb/UsbMouseDxe/ComponentName.c b/MdeModulePkg/Bus/Usb/UsbMouseDxe/ComponentName.c
new file mode 100644 (file)
index 0000000..29ea943
--- /dev/null
@@ -0,0 +1,219 @@
+/** @file\r
+\r
+Copyright (c) 2004 - 2007, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+Module Name:\r
+\r
+  ComponentName.c\r
+\r
+Abstract:\r
+\r
+\r
+**/\r
+\r
+#include "usbmouse.h"\r
+#include <Library/DebugLib.h>\r
+\r
+//\r
+// EFI Component Name Functions\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+UsbMouseComponentNameGetDriverName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UsbMouseComponentNameGetControllerName (\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
+// EFI Component Name Protocol\r
+//\r
+EFI_COMPONENT_NAME_PROTOCOL     gUsbMouseComponentName = {\r
+  UsbMouseComponentNameGetDriverName,\r
+  UsbMouseComponentNameGetControllerName,\r
+  "eng"\r
+};\r
+\r
+\r
+STATIC EFI_UNICODE_STRING_TABLE mUsbMouseDriverNameTable[] = {\r
+  { "eng", L"Usb Mouse Driver" },\r
+  { NULL , NULL }\r
+};\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UsbMouseComponentNameGetDriverName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Retrieves a Unicode string that is the user readable name of the EFI Driver.\r
+\r
+  Arguments:\r
+    This       - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.\r
+    Language   - A pointer to a three character ISO 639-2 language identifier.\r
+                 This is the language of the driver name that that the caller\r
+                 is requesting, and it must match one of the languages specified\r
+                 in SupportedLanguages.  The number of languages supported by a\r
+                 driver is up to the driver writer.\r
+    DriverName - A pointer to the Unicode string to return.  This Unicode string\r
+                 is the name of the driver specified by This in the language\r
+                 specified by Language.\r
+\r
+  Returns:\r
+    EFI_SUCCESS           - The Unicode string for the Driver specified by This\r
+                            and the language specified by Language was returned\r
+                            in DriverName.\r
+    EFI_INVALID_PARAMETER - Language is NULL.\r
+    EFI_INVALID_PARAMETER - DriverName is NULL.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support the\r
+                            language specified by Language.\r
+\r
+--*/\r
+{\r
+  return LookupUnicodeString (\r
+          Language,\r
+          gUsbMouseComponentName.SupportedLanguages,\r
+          mUsbMouseDriverNameTable,\r
+          DriverName\r
+          );\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UsbMouseComponentNameGetControllerName (\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
+  Routine Description:\r
+    Retrieves a Unicode string that is the user readable name of the controller\r
+    that is being managed by an EFI Driver.\r
+\r
+  Arguments:\r
+    This             - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.\r
+    ControllerHandle - The handle of a controller that the driver specified by\r
+                       This is managing.  This handle specifies the controller\r
+                       whose name is to be returned.\r
+    ChildHandle      - The handle of the child controller to retrieve the name\r
+                       of.  This is an optional parameter that may be NULL.  It\r
+                       will be NULL for device drivers.  It will also be NULL\r
+                       for a bus drivers that wish to retrieve the name of the\r
+                       bus controller.  It will not be NULL for a bus driver\r
+                       that wishes to retrieve the name of a child controller.\r
+    Language         - A pointer to a three character ISO 639-2 language\r
+                       identifier.  This is the language of the controller name\r
+                       that that the caller is requesting, and it must match one\r
+                       of the languages specified in SupportedLanguages.  The\r
+                       number of languages supported by a driver is up to the\r
+                       driver writer.\r
+    ControllerName   - A pointer to the Unicode string to return.  This Unicode\r
+                       string is the name of the controller specified by\r
+                       ControllerHandle and ChildHandle in the language specified\r
+                       by Language from the point of view of the driver specified\r
+                       by This.\r
+\r
+  Returns:\r
+    EFI_SUCCESS           - The Unicode string for the user readable name in the\r
+                            language specified by Language for the driver\r
+                            specified by This was returned in DriverName.\r
+    EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - Language is NULL.\r
+    EFI_INVALID_PARAMETER - ControllerName is NULL.\r
+    EFI_UNSUPPORTED       - The driver specified by This is not currently managing\r
+                            the controller specified by ControllerHandle and\r
+                            ChildHandle.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support the\r
+                            language specified by Language.\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                  Status;\r
+  USB_MOUSE_DEV               *UsbMouseDev;\r
+  EFI_SIMPLE_POINTER_PROTOCOL *SimplePointerProtocol;\r
+  EFI_USB_IO_PROTOCOL         *UsbIoProtocol;\r
+\r
+  //\r
+  // This is a device driver, so ChildHandle must be NULL.\r
+  //\r
+  if (ChildHandle != NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  //\r
+  // Check Controller's handle\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiUsbIoProtocolGuid,\r
+                  (VOID **) &UsbIoProtocol,\r
+                  gUsbMouseDriverBinding.DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (!EFI_ERROR (Status)) {\r
+    gBS->CloseProtocol (\r
+          ControllerHandle,\r
+          &gEfiUsbIoProtocolGuid,\r
+          gUsbMouseDriverBinding.DriverBindingHandle,\r
+          ControllerHandle\r
+          );\r
+\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  if (Status != EFI_ALREADY_STARTED) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+  //\r
+  // Get the device context\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                 &gEfiSimplePointerProtocolGuid,\r
+                  (VOID **) &SimplePointerProtocol,\r
+                  gUsbMouseDriverBinding.DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  UsbMouseDev = USB_MOUSE_DEV_FROM_MOUSE_PROTOCOL (SimplePointerProtocol);\r
+\r
+  return LookupUnicodeString (\r
+          Language,\r
+          gUsbMouseComponentName.SupportedLanguages,\r
+          UsbMouseDev->ControllerNameTable,\r
+          ControllerName\r
+          );\r
+\r
+}\r
diff --git a/MdeModulePkg/Bus/Usb/UsbMouseDxe/UsbMouseDxe.inf b/MdeModulePkg/Bus/Usb/UsbMouseDxe/UsbMouseDxe.inf
new file mode 100644 (file)
index 0000000..01af215
--- /dev/null
@@ -0,0 +1,110 @@
+#/** @file\r
+# Component name for module UsbMouse\r
+#\r
+# FIX ME!\r
+# Copyright (c) 2006, Intel Corporation. All right reserved.\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
+#  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
+#\r
+#**/\r
+\r
+################################################################################\r
+#\r
+# Defines Section - statements that will be processed to create a Makefile.\r
+#\r
+################################################################################\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = UsbMouseDxe\r
+  FILE_GUID                      = 2D2E62AA-9ECF-43b7-8219-94E7FC713DFE\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  ENTRY_POINT                    = USBMouseDriverBindingEntryPoint\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+################################################################################\r
+#\r
+# Sources Section - list of files that are required for the build to succeed.\r
+#\r
+################################################################################\r
+\r
+[Sources.common]\r
+  mousehid.h\r
+  ComponentName.c\r
+  usbmouse.c\r
+  mousehid.c\r
+  usbmouse.h\r
+  CommonHeader.h\r
+\r
+\r
+################################################################################\r
+#\r
+# Package Dependency Section - list of Package files that are required for\r
+#                              this module.\r
+#\r
+################################################################################\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+\r
+\r
+################################################################################\r
+#\r
+# Library Class Section - list of Library Classes that are required for\r
+#                         this module.\r
+#\r
+################################################################################\r
+\r
+[LibraryClasses]\r
+  MemoryAllocationLib\r
+  UefiLib\r
+  UefiBootServicesTableLib\r
+  UefiDriverEntryPoint\r
+  BaseMemoryLib\r
+  ReportStatusCodeLib\r
+  PcdLib\r
+  UsbLib\r
+\r
+\r
+################################################################################\r
+#\r
+# Protocol C Name Section - list of Protocol and Protocol Notify C Names\r
+#                           that this module uses or produces.\r
+#\r
+################################################################################\r
+\r
+[Protocols]\r
+  gEfiUsbIoProtocolGuid                         # PROTOCOL ALWAYS_CONSUMED\r
+  gEfiDevicePathProtocolGuid                    # PROTOCOL ALWAYS_CONSUMED\r
+  gEfiSimplePointerProtocolGuid                 # PROTOCOL ALWAYS_CONSUMED\r
+\r
+################################################################################\r
+#\r
+# Pcd FIXED_AT_BUILD - list of PCDs that this module is coded for.\r
+#\r
+################################################################################\r
+\r
+[PcdsFixedAtBuild]\r
+  PcdStatusCodeValueMouseInterfaceError|gEfiMdePkgTokenSpaceGuid\r
+  PcdStatusCodeValueMouseEnable|gEfiMdePkgTokenSpaceGuid\r
+  PcdStatusCodeValueMouseDisable|gEfiMdePkgTokenSpaceGuid\r
+  PcdStatusCodeValueMouseInputError|gEfiMdePkgTokenSpaceGuid\r
+  PcdStatusCodeValueMouseReset|gEfiMdePkgTokenSpaceGuid\r
+\r
+\r
diff --git a/MdeModulePkg/Bus/Usb/UsbMouseDxe/UsbMouseDxe.msa b/MdeModulePkg/Bus/Usb/UsbMouseDxe/UsbMouseDxe.msa
new file mode 100644 (file)
index 0000000..cb267d5
--- /dev/null
@@ -0,0 +1,73 @@
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\r
+  <MsaHeader>\r
+    <ModuleName>UsbMouseDxe</ModuleName>\r
+    <ModuleType>DXE_DRIVER</ModuleType>\r
+    <GuidValue>2D2E62AA-9ECF-43b7-8219-94E7FC713DFE</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Component name for module UsbMouse</Abstract>\r
+    <Description>FIX ME!</Description>\r
+    <Copyright>Copyright (c) 2006, Intel Corporation. All right reserved.</Copyright>\r
+    <License>All rights reserved. This program and the accompanying materials
+      are licensed and made available under the terms and conditions of the BSD License
+      which accompanies this distribution.  The full text of the license may be found at
+      http://opensource.org/licenses/bsd-license.php
+
+      THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+      WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>UsbMouseDxe</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>ReportStatusCodeLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseMemoryLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiDriverEntryPoint</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiBootServicesTableLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>MemoryAllocationLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>usbmouse.h</Filename>\r
+    <Filename>mousehid.c</Filename>\r
+    <Filename>usbmouse.c</Filename>\r
+    <Filename>ComponentName.c</Filename>\r
+    <Filename>mousehid.h</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+    <Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/>\r
+  </PackageDependencies>\r
+  <Protocols>\r
+    <Protocol Usage="ALWAYS_CONSUMED">\r
+      <ProtocolCName>gEfiSimplePointerProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="ALWAYS_CONSUMED">\r
+      <ProtocolCName>gEfiDevicePathProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="ALWAYS_CONSUMED">\r
+      <ProtocolCName>gEfiUsbIoProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+  </Protocols>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+    <Extern>\r
+      <ModuleEntryPoint>USBMouseDriverBindingEntryPoint</ModuleEntryPoint>\r
+    </Extern>\r
+  </Externs>\r
+</ModuleSurfaceArea>
\ No newline at end of file
diff --git a/MdeModulePkg/Bus/Usb/UsbMouseDxe/mousehid.c b/MdeModulePkg/Bus/Usb/UsbMouseDxe/mousehid.c
new file mode 100644 (file)
index 0000000..6490b09
--- /dev/null
@@ -0,0 +1,362 @@
+/** @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.c\r
+\r
+Abstract:\r
+  Parse mouse hid descriptor\r
+\r
+\r
+**/\r
+\r
+#include "mousehid.h"\r
+\r
+\r
+//\r
+// Get an item from report descriptor\r
+//\r
+\r
+/**\r
+  Get Next Item\r
+\r
+  @param  StartPos          Start Position\r
+  @param  EndPos            End Position\r
+  @param  HidItem           HidItem to return\r
+\r
+  @return Position\r
+\r
+**/\r
+STATIC\r
+UINT8 *\r
+GetNextItem (\r
+  IN  UINT8    *StartPos,\r
+  IN  UINT8    *EndPos,\r
+  OUT HID_ITEM *HidItem\r
+  )\r
+{\r
+  UINT8 Temp;\r
+\r
+  if ((EndPos - StartPos) <= 0) {\r
+    return NULL;\r
+  }\r
+\r
+  Temp = *StartPos;\r
+  StartPos++;\r
+  //\r
+  // bit 2,3\r
+  //\r
+  HidItem->Type = (UINT8) ((Temp >> 2) & 0x03);\r
+  //\r
+  // bit 4-7\r
+  //\r
+  HidItem->Tag = (UINT8) ((Temp >> 4) & 0x0F);\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
+    //\r
+    HidItem->Format = HID_ITEM_FORMAT_LONG;\r
+\r
+    if ((EndPos - StartPos) >= 2) {\r
+      HidItem->Size = *StartPos++;\r
+      HidItem->Tag  = *StartPos++;\r
+\r
+      if ((EndPos - StartPos) >= HidItem->Size) {\r
+        HidItem->Data.LongData = StartPos;\r
+        StartPos += HidItem->Size;\r
+        return StartPos;\r
+      }\r
+    }\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
+\r
+    case 0:\r
+      //\r
+      // No data\r
+      //\r
+      return StartPos;\r
+\r
+    case 1:\r
+      //\r
+      // One byte data\r
+      //\r
+      if ((EndPos - StartPos) >= 1) {\r
+        HidItem->Data.U8 = *StartPos++;\r
+        return StartPos;\r
+      }\r
+\r
+    case 2:\r
+      //\r
+      // Two byte data\r
+      //\r
+      if ((EndPos - StartPos) >= 2) {\r
+        CopyMem (&HidItem->Data.U16, StartPos, sizeof (UINT16));\r
+        StartPos += 2;\r
+        return StartPos;\r
+      }\r
+\r
+    case 3:\r
+      //\r
+      // 4 byte data, adjust size\r
+      //\r
+      HidItem->Size++;\r
+      if ((EndPos - StartPos) >= 4) {\r
+        CopyMem (&HidItem->Data.U32, StartPos, sizeof (UINT32));\r
+        StartPos += 4;\r
+        return StartPos;\r
+      }\r
+    }\r
+  }\r
+\r
+  return NULL;\r
+}\r
+\r
+\r
+/**\r
+  Get Item Data\r
+\r
+  @param  HidItem           HID_ITEM\r
+\r
+  @return HidItem Data\r
+\r
+**/\r
+STATIC\r
+UINT32\r
+GetItemData (\r
+  IN  HID_ITEM *HidItem\r
+  )\r
+{\r
+  //\r
+  // Get Data from HID_ITEM structure\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
+\r
+  @param  UsbMouse          USB_MOUSE_DEV\r
+  @param  LocalItem         Local Item\r
+\r
+\r
+**/\r
+STATIC\r
+VOID\r
+ParseLocalItem (\r
+  IN  USB_MOUSE_DEV   *UsbMouse,\r
+  IN  HID_ITEM        *LocalItem\r
+  )\r
+{\r
+  UINT32  Data;\r
+\r
+  if (LocalItem->Size == 0) {\r
+    //\r
+    // No expected data for local item\r
+    //\r
+    return ;\r
+  }\r
+\r
+  Data = GetItemData (LocalItem);\r
+\r
+  switch (LocalItem->Tag) {\r
+\r
+  case HID_LOCAL_ITEM_TAG_DELIMITER:\r
+    //\r
+    // we don't support delimiter here\r
+    //\r
+    return ;\r
+\r
+  case HID_LOCAL_ITEM_TAG_USAGE:\r
+    return ;\r
+\r
+  case HID_LOCAL_ITEM_TAG_USAGE_MINIMUM:\r
+    if (UsbMouse->PrivateData.ButtonDetected) {\r
+      UsbMouse->PrivateData.ButtonMinIndex = (UINT8) Data;\r
+    }\r
+\r
+    return ;\r
+\r
+  case HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM:\r
+    {\r
+      if (UsbMouse->PrivateData.ButtonDetected) {\r
+        UsbMouse->PrivateData.ButtonMaxIndex = (UINT8) Data;\r
+      }\r
+\r
+      return ;\r
+    }\r
+  }\r
+}\r
+\r
+STATIC\r
+VOID\r
+ParseGlobalItem (\r
+  IN  USB_MOUSE_DEV   *UsbMouse,\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
+        UsbMouse->PrivateData.ButtonDetected = TRUE;\r
+        return ;\r
+      }\r
+      break;\r
+    }\r
+\r
+  }\r
+}\r
+\r
+\r
+\r
+/**\r
+  Parse Main Item\r
+\r
+  @param  UsbMouse          TODO: add argument description\r
+  @param  MainItem          HID_ITEM to parse\r
+\r
+  @return VOID\r
+\r
+**/\r
+STATIC\r
+VOID\r
+ParseMainItem (\r
+  IN  USB_MOUSE_DEV   *UsbMouse,\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  UsbMouse          USB_MOUSE_DEV\r
+  @param  HidItem           HidItem to parse\r
+\r
+  @return VOID\r
+\r
+**/\r
+STATIC\r
+VOID\r
+ParseHidItem (\r
+  IN  USB_MOUSE_DEV   *UsbMouse,\r
+  IN  HID_ITEM        *HidItem\r
+  )\r
+{\r
+  switch (HidItem->Type) {\r
+\r
+  case HID_ITEM_TYPE_MAIN:\r
+    //\r
+    // For Main Item, parse main item\r
+    //\r
+    ParseMainItem (UsbMouse, HidItem);\r
+    break;\r
+\r
+  case HID_ITEM_TYPE_GLOBAL:\r
+    //\r
+    // For global Item, parse global item\r
+    //\r
+    ParseGlobalItem (UsbMouse, HidItem);\r
+    break;\r
+\r
+  case HID_ITEM_TYPE_LOCAL:\r
+    //\r
+    // For Local Item, parse local item\r
+    //\r
+    ParseLocalItem (UsbMouse, 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
+\r
+**/\r
+EFI_STATUS\r
+ParseMouseReportDescriptor (\r
+  IN  USB_MOUSE_DEV   *UsbMouse,\r
+  IN  UINT8           *ReportDescriptor,\r
+  IN  UINTN           ReportSize\r
+  )\r
+{\r
+  UINT8     *DescriptorEnd;\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
+    if (HidItem.Format != HID_ITEM_FORMAT_SHORT) {\r
+      //\r
+      // Long Format Item is not supported at current HID revision\r
+      //\r
+      return EFI_DEVICE_ERROR;\r
+    }\r
+\r
+    ParseHidItem (UsbMouse, &HidItem);\r
+\r
+    ptr = GetNextItem (ptr, DescriptorEnd, &HidItem);\r
+  }\r
+\r
+  UsbMouse->NumberOfButtons                 = (UINT8) (UsbMouse->PrivateData.ButtonMaxIndex - UsbMouse->PrivateData.ButtonMinIndex + 1);\r
+  UsbMouse->XLogicMax                       = UsbMouse->YLogicMax = 127;\r
+  UsbMouse->XLogicMin                       = UsbMouse->YLogicMin = -127;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
diff --git a/MdeModulePkg/Bus/Usb/UsbMouseDxe/mousehid.h b/MdeModulePkg/Bus/Usb/UsbMouseDxe/mousehid.h
new file mode 100644 (file)
index 0000000..13afc55
--- /dev/null
@@ -0,0 +1,85 @@
+/** @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 "usbmouse.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_DEV   *UsbMouse,\r
+  IN  UINT8           *ReportDescriptor,\r
+  IN  UINTN           ReportSize\r
+  );\r
+\r
+#endif\r
diff --git a/MdeModulePkg/Bus/Usb/UsbMouseDxe/usbmouse.c b/MdeModulePkg/Bus/Usb/UsbMouseDxe/usbmouse.c
new file mode 100644 (file)
index 0000000..a4c9e77
--- /dev/null
@@ -0,0 +1,1057 @@
+/** @file\r
+\r
+Copyright (c) 2004 - 2007, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+  Module Name:\r
+\r
+    UsbMouse.c\r
+\r
+  Abstract:\r
+\r
+\r
+**/\r
+\r
+#include "UsbMouse.h"\r
+\r
+#include <Library/DebugLib.h>\r
+#include <IndustryStandard/Usb.h>\r
+\r
+\r
+//\r
+// Driver Consumed Protocol Prototypes\r
+//\r
+//@MT:#include EFI_PROTOCOL_DEFINITION (DriverBinding)\r
+//@MT:#include EFI_PROTOCOL_DEFINITION (UsbIo)\r
+\r
+//\r
+// Driver Produced Protocol Prototypes\r
+//\r
+//@MT:#include EFI_PROTOCOL_DEFINITION (SimplePointer)\r
+\r
+//@MT:#include "UsbDxeLib.h"\r
+//@MT:#include "hid.h"\r
+#include "usbmouse.h"\r
+#include "mousehid.h"\r
+\r
+//\r
+// Prototypes\r
+// Driver model protocol interface\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+USBMouseDriverBindingEntryPoint (\r
+  IN EFI_HANDLE           ImageHandle,\r
+  IN EFI_SYSTEM_TABLE     *SystemTable\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+USBMouseDriverBindingSupported (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL    *This,\r
+  IN EFI_HANDLE                     Controller,\r
+  IN EFI_DEVICE_PATH_PROTOCOL       *RemainingDevicePath\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+USBMouseDriverBindingStart (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL    *This,\r
+  IN EFI_HANDLE                     Controller,\r
+  IN EFI_DEVICE_PATH_PROTOCOL       *RemainingDevicePath\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+USBMouseDriverBindingStop (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL   *This,\r
+  IN  EFI_HANDLE                    Controller,\r
+  IN  UINTN                         NumberOfChildren,\r
+  IN  EFI_HANDLE                    *ChildHandleBuffer\r
+  );\r
+\r
+EFI_GUID  gEfiUsbMouseDriverGuid = {\r
+  0x290156b5, 0x6a05, 0x4ac0, 0xb8, 0x0, 0x51, 0x27, 0x55, 0xad, 0x14, 0x29\r
+};\r
+\r
+EFI_DRIVER_BINDING_PROTOCOL gUsbMouseDriverBinding = {\r
+  USBMouseDriverBindingSupported,\r
+  USBMouseDriverBindingStart,\r
+  USBMouseDriverBindingStop,\r
+  0xa,\r
+  NULL,\r
+  NULL\r
+};\r
+\r
+//\r
+// helper functions\r
+//\r
+STATIC\r
+BOOLEAN\r
+IsUsbMouse (\r
+  IN  EFI_USB_IO_PROTOCOL     *UsbIo\r
+  );\r
+\r
+STATIC\r
+EFI_STATUS\r
+InitializeUsbMouseDevice (\r
+  IN  USB_MOUSE_DEV           *UsbMouseDev\r
+  );\r
+\r
+STATIC\r
+VOID\r
+EFIAPI\r
+UsbMouseWaitForInput (\r
+  IN  EFI_EVENT               Event,\r
+  IN  VOID                    *Context\r
+  );\r
+\r
+//\r
+// Mouse interrupt handler\r
+//\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+OnMouseInterruptComplete (\r
+  IN  VOID        *Data,\r
+  IN  UINTN       DataLength,\r
+  IN  VOID        *Context,\r
+  IN  UINT32      Result\r
+  );\r
+\r
+//\r
+// Mouse Protocol\r
+//\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+GetMouseState (\r
+  IN   EFI_SIMPLE_POINTER_PROTOCOL  *This,\r
+  OUT  EFI_SIMPLE_POINTER_STATE     *MouseState\r
+  );\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+UsbMouseReset (\r
+  IN EFI_SIMPLE_POINTER_PROTOCOL    *This,\r
+  IN BOOLEAN                        ExtendedVerification\r
+  );\r
+\r
+//\r
+// Driver start here\r
+//\r
+//@MT: EFI_DRIVER_ENTRY_POINT (USBMouseDriverBindingEntryPoint)\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+USBMouseDriverBindingEntryPoint (\r
+  IN EFI_HANDLE           ImageHandle,\r
+  IN EFI_SYSTEM_TABLE     *SystemTable\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Entry point for EFI drivers.\r
+\r
+  Arguments:\r
+   ImageHandle - EFI_HANDLE\r
+   SystemTable - EFI_SYSTEM_TABLE\r
+  Returns:\r
+    EFI_SUCCESS\r
+    others\r
+\r
+--*/\r
+{\r
+  return EfiLibInstallAllDriverProtocols (\r
+          ImageHandle,\r
+          SystemTable,\r
+          &gUsbMouseDriverBinding,\r
+          ImageHandle,\r
+          &gUsbMouseComponentName,\r
+          NULL,\r
+          NULL\r
+          );\r
+}\r
+\r
+\r
+/**\r
+  Test to see if this driver supports ControllerHandle. Any ControllerHandle\r
+  that has UsbHcProtocol installed will be supported.\r
+\r
+  @param  This                  Protocol instance pointer.\r
+  @param  Controller            Handle of device to test\r
+  @param  RemainingDevicePath   Not used\r
+\r
+  @retval EFI_SUCCESS           This driver supports this device.\r
+  @retval EFI_UNSUPPORTED       This driver does not support this device.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+USBMouseDriverBindingSupported (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL    *This,\r
+  IN EFI_HANDLE                     Controller,\r
+  IN EFI_DEVICE_PATH_PROTOCOL       *RemainingDevicePath\r
+  )\r
+{\r
+  EFI_STATUS          OpenStatus;\r
+  EFI_USB_IO_PROTOCOL *UsbIo;\r
+  EFI_STATUS          Status;\r
+\r
+  OpenStatus = gBS->OpenProtocol (\r
+                      Controller,\r
+                      &gEfiUsbIoProtocolGuid,\r
+                      &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
+  }\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
+  //\r
+  Status = EFI_SUCCESS;\r
+  if (!IsUsbMouse (UsbIo)) {\r
+    Status = EFI_UNSUPPORTED;\r
+  }\r
+\r
+  gBS->CloseProtocol (\r
+        Controller,\r
+        &gEfiUsbIoProtocolGuid,\r
+        This->DriverBindingHandle,\r
+        Controller\r
+        );\r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+  Starting the Usb Bus Driver\r
+\r
+  @param  This                  Protocol instance pointer.\r
+  @param  Controller            Handle of device to test\r
+  @param  RemainingDevicePath   Not used\r
+\r
+  @retval EFI_SUCCESS           This driver supports this device.\r
+  @retval EFI_UNSUPPORTED       This driver does not support this device.\r
+  @retval EFI_DEVICE_ERROR      This driver cannot be started due to device Error\r
+                                EFI_OUT_OF_RESOURCES- Can't allocate memory\r
+                                resources\r
+  @retval EFI_ALREADY_STARTED   Thios driver has been started\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+USBMouseDriverBindingStart (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL    *This,\r
+  IN EFI_HANDLE                     Controller,\r
+  IN EFI_DEVICE_PATH_PROTOCOL       *RemainingDevicePath\r
+  )\r
+{\r
+  EFI_STATUS                  Status;\r
+  EFI_USB_IO_PROTOCOL         *UsbIo;\r
+  EFI_USB_ENDPOINT_DESCRIPTOR *EndpointDesc;\r
+  USB_MOUSE_DEV               *UsbMouseDevice;\r
+  UINT8                       EndpointNumber;\r
+  UINT8                       Index;\r
+  UINT8                       EndpointAddr;\r
+  UINT8                       PollingInterval;\r
+  UINT8                       PacketSize;\r
+\r
+  UsbMouseDevice  = NULL;\r
+  Status          = EFI_SUCCESS;\r
+\r
+  Status = gBS->OpenProtocol (\r
+                  Controller,\r
+                  &gEfiUsbIoProtocolGuid,\r
+                  &UsbIo,\r
+                  This->DriverBindingHandle,\r
+                  Controller,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    goto ErrorExit;\r
+  }\r
+\r
+  UsbMouseDevice = AllocateZeroPool (sizeof (USB_MOUSE_DEV));\r
+  if (UsbMouseDevice == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    goto ErrorExit;\r
+  }\r
+\r
+  UsbMouseDevice->UsbIo               = UsbIo;\r
+\r
+  UsbMouseDevice->Signature           = USB_MOUSE_DEV_SIGNATURE;\r
+\r
+  UsbMouseDevice->InterfaceDescriptor = AllocatePool (sizeof (EFI_USB_INTERFACE_DESCRIPTOR));\r
+  if (UsbMouseDevice->InterfaceDescriptor == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    goto ErrorExit;\r
+  }\r
+\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
+  Status = gBS->OpenProtocol (\r
+                  Controller,\r
+                  &gEfiDevicePathProtocolGuid,\r
+                  (VOID **) &UsbMouseDevice->DevicePath,\r
+                  This->DriverBindingHandle,\r
+                  Controller,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    goto ErrorExit;\r
+  }\r
+  //\r
+  // Get interface & endpoint descriptor\r
+  //\r
+  UsbIo->UsbGetInterfaceDescriptor (\r
+          UsbIo,\r
+          UsbMouseDevice->InterfaceDescriptor\r
+          );\r
+\r
+  EndpointNumber = UsbMouseDevice->InterfaceDescriptor->NumEndpoints;\r
+\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
+\r
+      //\r
+      // We only care interrupt endpoint here\r
+      //\r
+      UsbMouseDevice->IntEndpointDescriptor = EndpointDesc;\r
+    }\r
+  }\r
+\r
+  if (UsbMouseDevice->IntEndpointDescriptor == NULL) {\r
+    //\r
+    // No interrupt endpoint, then error\r
+    //\r
+    Status = EFI_UNSUPPORTED;\r
+    goto ErrorExit;\r
+  }\r
+\r
+  Status = InitializeUsbMouseDevice (UsbMouseDevice);\r
+  if (EFI_ERROR (Status)) {\r
+    MouseReportStatusCode (\r
+      UsbMouseDevice->DevicePath,\r
+      EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
+      PcdGet32 (PcdStatusCodeValueMouseInterfaceError)\r
+      );\r
+\r
+    goto ErrorExit;\r
+  }\r
+\r
+  UsbMouseDevice->SimplePointerProtocol.GetState  = GetMouseState;\r
+  UsbMouseDevice->SimplePointerProtocol.Reset     = UsbMouseReset;\r
+  UsbMouseDevice->SimplePointerProtocol.Mode      = &UsbMouseDevice->Mode;\r
+\r
+  Status = gBS->CreateEvent (\r
+                  EVT_NOTIFY_WAIT,\r
+                  TPL_NOTIFY,\r
+                  UsbMouseWaitForInput,\r
+                  UsbMouseDevice,\r
+                  &((UsbMouseDevice->SimplePointerProtocol).WaitForInput)\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    goto ErrorExit;\r
+  }\r
+\r
+  Status = gBS->InstallProtocolInterface (\r
+                  &Controller,\r
+                  &gEfiSimplePointerProtocolGuid,\r
+                  EFI_NATIVE_INTERFACE,\r
+                  &UsbMouseDevice->SimplePointerProtocol\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
+  //\r
+\r
+  MouseReportStatusCode (\r
+    UsbMouseDevice->DevicePath,\r
+    EFI_PROGRESS_CODE,\r
+    PcdGet32 (PcdStatusCodeValueMouseEnable)\r
+    );\r
+\r
+  //\r
+  // submit async interrupt transfer\r
+  //\r
+  EndpointAddr    = UsbMouseDevice->IntEndpointDescriptor->EndpointAddress;\r
+  PollingInterval = UsbMouseDevice->IntEndpointDescriptor->Interval;\r
+  PacketSize      = (UINT8) (UsbMouseDevice->IntEndpointDescriptor->MaxPacketSize);\r
+\r
+  Status = UsbIo->UsbAsyncInterruptTransfer (\r
+                    UsbIo,\r
+                    EndpointAddr,\r
+                    TRUE,\r
+                    PollingInterval,\r
+                    PacketSize,\r
+                    OnMouseInterruptComplete,\r
+                    UsbMouseDevice\r
+                    );\r
+\r
+  if (!EFI_ERROR (Status)) {\r
+\r
+    UsbMouseDevice->ControllerNameTable = NULL;\r
+    AddUnicodeString (\r
+      "eng",\r
+      gUsbMouseComponentName.SupportedLanguages,\r
+      &UsbMouseDevice->ControllerNameTable,\r
+      L"Generic Usb Mouse"\r
+      );\r
+\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  //\r
+  // If submit error, uninstall that interface\r
+  //\r
+  Status = EFI_DEVICE_ERROR;\r
+  gBS->UninstallProtocolInterface (\r
+        Controller,\r
+        &gEfiSimplePointerProtocolGuid,\r
+        &UsbMouseDevice->SimplePointerProtocol\r
+        );\r
+\r
+ErrorExit:\r
+  if (EFI_ERROR (Status)) {\r
+    gBS->CloseProtocol (\r
+          Controller,\r
+          &gEfiUsbIoProtocolGuid,\r
+          This->DriverBindingHandle,\r
+          Controller\r
+          );\r
+\r
+    if (UsbMouseDevice != NULL) {\r
+      if (UsbMouseDevice->InterfaceDescriptor != NULL) {\r
+        gBS->FreePool (UsbMouseDevice->InterfaceDescriptor);\r
+      }\r
+\r
+      if (UsbMouseDevice->IntEndpointDescriptor != NULL) {\r
+        gBS->FreePool (UsbMouseDevice->IntEndpointDescriptor);\r
+      }\r
+\r
+      if ((UsbMouseDevice->SimplePointerProtocol).WaitForInput != NULL) {\r
+        gBS->CloseEvent ((UsbMouseDevice->SimplePointerProtocol).WaitForInput);\r
+      }\r
+\r
+      gBS->FreePool (UsbMouseDevice);\r
+      UsbMouseDevice = NULL;\r
+    }\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+  Stop this driver on ControllerHandle. Support stoping any child handles\r
+  created 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
+\r
+  @return EFI_SUCCESS\r
+  @return EFI_DEVICE_ERROR\r
+  @return others\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+USBMouseDriverBindingStop (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL   *This,\r
+  IN  EFI_HANDLE                    Controller,\r
+  IN  UINTN                         NumberOfChildren,\r
+  IN  EFI_HANDLE                    *ChildHandleBuffer\r
+  )\r
+{\r
+  EFI_STATUS                  Status;\r
+  USB_MOUSE_DEV               *UsbMouseDevice;\r
+  EFI_SIMPLE_POINTER_PROTOCOL *SimplePointerProtocol;\r
+  EFI_USB_IO_PROTOCOL         *UsbIo;\r
+\r
+  //\r
+  // Get our context back.\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  Controller,\r
+                  &gEfiSimplePointerProtocolGuid,\r
+                  &SimplePointerProtocol,\r
+                  This->DriverBindingHandle,\r
+                  Controller,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  UsbMouseDevice = USB_MOUSE_DEV_FROM_MOUSE_PROTOCOL (SimplePointerProtocol);\r
+\r
+  gBS->CloseProtocol (\r
+        Controller,\r
+        &gEfiSimplePointerProtocolGuid,\r
+        This->DriverBindingHandle,\r
+        Controller\r
+        );\r
+\r
+  UsbIo = UsbMouseDevice->UsbIo;\r
+\r
+  //\r
+  // Uninstall the Asyn Interrupt Transfer from this device\r
+  // will disable the mouse data input from this device\r
+  //\r
+  MouseReportStatusCode (\r
+    UsbMouseDevice->DevicePath,\r
+    EFI_PROGRESS_CODE,\r
+    PcdGet32 (PcdStatusCodeValueMouseDisable)\r
+    );\r
+\r
+  //\r
+  // Delete Mouse Async Interrupt Transfer\r
+  //\r
+  UsbIo->UsbAsyncInterruptTransfer (\r
+          UsbIo,\r
+          UsbMouseDevice->IntEndpointDescriptor->EndpointAddress,\r
+          FALSE,\r
+          UsbMouseDevice->IntEndpointDescriptor->Interval,\r
+          0,\r
+          NULL,\r
+          NULL\r
+          );\r
+\r
+  gBS->CloseEvent (UsbMouseDevice->SimplePointerProtocol.WaitForInput);\r
+\r
+  if (UsbMouseDevice->DelayedRecoveryEvent) {\r
+    gBS->CloseEvent (UsbMouseDevice->DelayedRecoveryEvent);\r
+    UsbMouseDevice->DelayedRecoveryEvent = 0;\r
+  }\r
+\r
+  Status = gBS->UninstallProtocolInterface (\r
+                  Controller,\r
+                  &gEfiSimplePointerProtocolGuid,\r
+                  &UsbMouseDevice->SimplePointerProtocol\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  gBS->CloseProtocol (\r
+        Controller,\r
+        &gEfiUsbIoProtocolGuid,\r
+        This->DriverBindingHandle,\r
+        Controller\r
+        );\r
+\r
+  gBS->FreePool (UsbMouseDevice->InterfaceDescriptor);\r
+  gBS->FreePool (UsbMouseDevice->IntEndpointDescriptor);\r
+\r
+  if (UsbMouseDevice->ControllerNameTable) {\r
+    FreeUnicodeStringTable (UsbMouseDevice->ControllerNameTable);\r
+  }\r
+\r
+  gBS->FreePool (UsbMouseDevice);\r
+\r
+  return EFI_SUCCESS;\r
+\r
+}\r
+\r
+\r
+/**\r
+  Tell if a Usb Controller is a mouse\r
+\r
+  @param  UsbIo                 Protocol instance pointer.\r
+\r
+  @retval TRUE                  It is a mouse\r
+  @retval FALSE                 It is not a mouse\r
+\r
+**/\r
+BOOLEAN\r
+IsUsbMouse (\r
+  IN  EFI_USB_IO_PROTOCOL     *UsbIo\r
+  )\r
+{\r
+  EFI_STATUS                    Status;\r
+  EFI_USB_INTERFACE_DESCRIPTOR  InterfaceDescriptor;\r
+\r
+  //\r
+  // Get the Default interface descriptor, now we only\r
+  // suppose it is interface 1\r
+  //\r
+  Status = UsbIo->UsbGetInterfaceDescriptor (\r
+                    UsbIo,\r
+                    &InterfaceDescriptor\r
+                    );\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return FALSE;\r
+  }\r
+\r
+  if ((InterfaceDescriptor.InterfaceClass == CLASS_HID) &&\r
+      (InterfaceDescriptor.InterfaceSubClass == SUBCLASS_BOOT) &&\r
+      (InterfaceDescriptor.InterfaceProtocol == PROTOCOL_MOUSE)\r
+      ) {\r
+    return TRUE;\r
+  }\r
+\r
+  return FALSE;\r
+}\r
+\r
+\r
+/**\r
+  Initialize the Usb Mouse Device.\r
+\r
+  @param  UsbMouseDev           Device instance to be initialized\r
+\r
+  @retval EFI_SUCCESS           Success\r
+  @retval EFI_DEVICE_ERROR      Init error. EFI_OUT_OF_RESOURCES- Can't allocate\r
+                                memory\r
+\r
+**/\r
+STATIC\r
+EFI_STATUS\r
+InitializeUsbMouseDevice (\r
+  IN  USB_MOUSE_DEV           *UsbMouseDev\r
+  )\r
+{\r
+  EFI_USB_IO_PROTOCOL     *UsbIo;\r
+  UINT8                   Protocol;\r
+  EFI_STATUS              Status;\r
+  EFI_USB_HID_DESCRIPTOR  MouseHidDesc;\r
+  UINT8                   *ReportDesc;\r
+\r
+  UsbIo = UsbMouseDev->UsbIo;\r
+\r
+  //\r
+  // Get HID descriptor\r
+  //\r
+  Status = UsbGetHidDescriptor (\r
+            UsbIo,\r
+            UsbMouseDev->InterfaceDescriptor->InterfaceNumber,\r
+            &MouseHidDesc\r
+            );\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Get Report descriptor\r
+  //\r
+  if (MouseHidDesc.HidClassDesc[0].DescriptorType != 0x22) {\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
+\r
+  Status = UsbGetReportDescriptor (\r
+            UsbIo,\r
+            UsbMouseDev->InterfaceDescriptor->InterfaceNumber,\r
+            MouseHidDesc.HidClassDesc[0].DescriptorLength,\r
+            ReportDesc\r
+            );\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    gBS->FreePool (ReportDesc);\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Parse report descriptor\r
+  //\r
+  Status = ParseMouseReportDescriptor (\r
+            UsbMouseDev,\r
+            ReportDesc,\r
+            MouseHidDesc.HidClassDesc[0].DescriptorLength\r
+            );\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    gBS->FreePool (ReportDesc);\r
+    return Status;\r
+  }\r
+\r
+  if (UsbMouseDev->NumberOfButtons >= 1) {\r
+    UsbMouseDev->Mode.LeftButton = TRUE;\r
+  }\r
+\r
+  if (UsbMouseDev->NumberOfButtons > 1) {\r
+    UsbMouseDev->Mode.RightButton = TRUE;\r
+  }\r
+\r
+  UsbMouseDev->Mode.ResolutionX = 8;\r
+  UsbMouseDev->Mode.ResolutionY = 8;\r
+  UsbMouseDev->Mode.ResolutionZ = 0;\r
+  //\r
+  // Here we just assume interface 0 is the mouse interface\r
+  //\r
+  UsbGetProtocolRequest (\r
+    UsbIo,\r
+    0,\r
+    &Protocol\r
+    );\r
+\r
+  if (Protocol != BOOT_PROTOCOL) {\r
+    Status = UsbSetProtocolRequest (\r
+              UsbIo,\r
+              0,\r
+              BOOT_PROTOCOL\r
+              );\r
+\r
+    if (EFI_ERROR (Status)) {\r
+      gBS->FreePool (ReportDesc);\r
+      return EFI_DEVICE_ERROR;\r
+    }\r
+  }\r
+\r
+  //\r
+  // Set indefinite Idle rate for USB Mouse\r
+  //\r
+  UsbSetIdleRequest (\r
+    UsbIo,\r
+    0,\r
+    0,\r
+    0\r
+    );\r
+\r
+  gBS->FreePool (ReportDesc);\r
+\r
+  if (UsbMouseDev->DelayedRecoveryEvent) {\r
+    gBS->CloseEvent (UsbMouseDev->DelayedRecoveryEvent);\r
+    UsbMouseDev->DelayedRecoveryEvent = 0;\r
+  }\r
+\r
+  Status = gBS->CreateEvent (\r
+                  EVT_TIMER | EVT_NOTIFY_SIGNAL,\r
+                  TPL_NOTIFY,\r
+                  USBMouseRecoveryHandler,\r
+                  UsbMouseDev,\r
+                  &UsbMouseDev->DelayedRecoveryEvent\r
+                  );\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+  It is called whenever there is data received from async interrupt\r
+  transfer.\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
+\r
+  @return EFI_SUCCESS\r
+  @return EFI_DEVICE_ERROR\r
+\r
+**/\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+OnMouseInterruptComplete (\r
+  IN  VOID        *Data,\r
+  IN  UINTN       DataLength,\r
+  IN  VOID        *Context,\r
+  IN  UINT32      Result\r
+  )\r
+{\r
+  USB_MOUSE_DEV       *UsbMouseDevice;\r
+  EFI_USB_IO_PROTOCOL *UsbIo;\r
+  UINT8               EndpointAddr;\r
+  UINT32              UsbResult;\r
+\r
+  UsbMouseDevice  = (USB_MOUSE_DEV *) Context;\r
+  UsbIo           = UsbMouseDevice->UsbIo;\r
+\r
+  if (Result != EFI_USB_NOERROR) {\r
+    //\r
+    // Some errors happen during the process\r
+    //\r
+    MouseReportStatusCode (\r
+      UsbMouseDevice->DevicePath,\r
+      EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
+      PcdGet32 (PcdStatusCodeValueMouseInputError)\r
+      );\r
+\r
+    if ((Result & EFI_USB_ERR_STALL) == EFI_USB_ERR_STALL) {\r
+      EndpointAddr = UsbMouseDevice->IntEndpointDescriptor->EndpointAddress;\r
+\r
+      UsbClearEndpointHalt (\r
+        UsbIo,\r
+        EndpointAddr,\r
+        &UsbResult\r
+        );\r
+    }\r
+\r
+    UsbIo->UsbAsyncInterruptTransfer (\r
+            UsbIo,\r
+            UsbMouseDevice->IntEndpointDescriptor->EndpointAddress,\r
+            FALSE,\r
+            0,\r
+            0,\r
+            NULL,\r
+            NULL\r
+            );\r
+\r
+    gBS->SetTimer (\r
+          UsbMouseDevice->DelayedRecoveryEvent,\r
+          TimerRelative,\r
+          EFI_USB_INTERRUPT_DELAY\r
+          );\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  if (DataLength == 0 || Data == NULL) {\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  UsbMouseDevice->StateChanged = TRUE;\r
+\r
+  //\r
+  // Check mouse Data\r
+  //\r
+  UsbMouseDevice->State.LeftButton  = (BOOLEAN) (*(UINT8 *) Data & 0x01);\r
+  UsbMouseDevice->State.RightButton = (BOOLEAN) (*(UINT8 *) Data & 0x02);\r
+  UsbMouseDevice->State.RelativeMovementX += *((INT8 *) Data + 1);\r
+  UsbMouseDevice->State.RelativeMovementY += *((INT8 *) Data + 2);\r
+\r
+  if (DataLength > 3) {\r
+    UsbMouseDevice->State.RelativeMovementZ += *((INT8 *) Data + 3);\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/*\r
+STATIC VOID\r
+PrintMouseState(\r
+    IN  EFI_MOUSE_STATE *MouseState\r
+    )\r
+{\r
+    Aprint("(%x: %x, %x)\n",\r
+        MouseState->ButtonStates,\r
+        MouseState->dx,\r
+        MouseState->dy\r
+        );\r
+}\r
+*/\r
+\r
+/**\r
+  Get the mouse state, see SIMPLE POINTER PROTOCOL.\r
+\r
+  @param  This                  Protocol instance pointer.\r
+  @param  MouseState            Current mouse state\r
+\r
+  @return EFI_SUCCESS\r
+  @return EFI_DEVICE_ERROR\r
+  @return EFI_NOT_READY\r
+\r
+**/\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+GetMouseState (\r
+  IN   EFI_SIMPLE_POINTER_PROTOCOL  *This,\r
+  OUT  EFI_SIMPLE_POINTER_STATE     *MouseState\r
+  )\r
+{\r
+  USB_MOUSE_DEV *MouseDev;\r
+\r
+  if (MouseState == NULL) {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  MouseDev = USB_MOUSE_DEV_FROM_MOUSE_PROTOCOL (This);\r
+\r
+  if (!MouseDev->StateChanged) {\r
+    return EFI_NOT_READY;\r
+  }\r
+\r
+  CopyMem (\r
+    MouseState,\r
+    &MouseDev->State,\r
+    sizeof (EFI_SIMPLE_POINTER_STATE)\r
+    );\r
+\r
+  //\r
+  // Clear previous move state\r
+  //\r
+  MouseDev->State.RelativeMovementX = 0;\r
+  MouseDev->State.RelativeMovementY = 0;\r
+  MouseDev->State.RelativeMovementZ = 0;\r
+\r
+  MouseDev->StateChanged            = FALSE;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+  Reset the mouse device, see SIMPLE POINTER PROTOCOL.\r
+\r
+  @param  This                  Protocol instance pointer.\r
+  @param  ExtendedVerification  Ignored here/\r
+\r
+  @return EFI_SUCCESS\r
+\r
+**/\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+UsbMouseReset (\r
+  IN EFI_SIMPLE_POINTER_PROTOCOL    *This,\r
+  IN BOOLEAN                        ExtendedVerification\r
+  )\r
+{\r
+  USB_MOUSE_DEV       *UsbMouseDevice;\r
+  EFI_USB_IO_PROTOCOL *UsbIo;\r
+\r
+  UsbMouseDevice  = USB_MOUSE_DEV_FROM_MOUSE_PROTOCOL (This);\r
+\r
+  UsbIo           = UsbMouseDevice->UsbIo;\r
+\r
+  MouseReportStatusCode (\r
+    UsbMouseDevice->DevicePath,\r
+    EFI_PROGRESS_CODE,\r
+    PcdGet32 (PcdStatusCodeValueMouseReset)\r
+\r
+    );\r
+\r
+  ZeroMem (\r
+    &UsbMouseDevice->State,\r
+    sizeof (EFI_SIMPLE_POINTER_STATE)\r
+    );\r
+  UsbMouseDevice->StateChanged = FALSE;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+  Event notification function for SIMPLE_POINTER.WaitForInput event\r
+  Signal the event if there is input from mouse\r
+\r
+  @param  Event                 Wait Event\r
+  @param  Context               Passed parameter to event handler\r
+ VOID\r
+\r
+**/\r
+STATIC\r
+VOID\r
+EFIAPI\r
+UsbMouseWaitForInput (\r
+  IN  EFI_EVENT               Event,\r
+  IN  VOID                    *Context\r
+  )\r
+{\r
+  USB_MOUSE_DEV *UsbMouseDev;\r
+\r
+  UsbMouseDev = (USB_MOUSE_DEV *) Context;\r
+\r
+  //\r
+  // Someone is waiting on the mouse event, if there's\r
+  // input from mouse, signal the event\r
+  //\r
+  if (UsbMouseDev->StateChanged) {\r
+    gBS->SignalEvent (Event);\r
+  }\r
+}\r
+\r
+\r
+/**\r
+  Timer handler for Delayed Recovery timer.\r
+\r
+  @param  Event                 The Delayed Recovery event.\r
+  @param  Context               Points to the USB_KB_DEV instance.\r
+\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+USBMouseRecoveryHandler (\r
+  IN    EFI_EVENT    Event,\r
+  IN    VOID         *Context\r
+  )\r
+{\r
+  USB_MOUSE_DEV       *UsbMouseDev;\r
+  EFI_USB_IO_PROTOCOL *UsbIo;\r
+\r
+  UsbMouseDev = (USB_MOUSE_DEV *) Context;\r
+\r
+  UsbIo       = UsbMouseDev->UsbIo;\r
+\r
+  UsbIo->UsbAsyncInterruptTransfer (\r
+          UsbIo,\r
+          UsbMouseDev->IntEndpointDescriptor->EndpointAddress,\r
+          TRUE,\r
+          UsbMouseDev->IntEndpointDescriptor->Interval,\r
+          UsbMouseDev->IntEndpointDescriptor->MaxPacketSize,\r
+          OnMouseInterruptComplete,\r
+          UsbMouseDev\r
+          );\r
+}\r
+\r
+\r
+/**\r
+  Report Status Code in Usb Bot Driver\r
+\r
+  @param  DevicePath            Use this to get Device Path\r
+  @param  CodeType              Status Code Type\r
+  @param  CodeValue             Status Code Value\r
+\r
+  @return None\r
+\r
+**/\r
+VOID\r
+MouseReportStatusCode (\r
+  IN EFI_DEVICE_PATH_PROTOCOL  *DevicePath,\r
+  IN EFI_STATUS_CODE_TYPE      CodeType,\r
+  IN EFI_STATUS_CODE_VALUE     Value\r
+  )\r
+{\r
+  REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
+    CodeType,\r
+    Value,\r
+    DevicePath\r
+    );\r
+}\r
diff --git a/MdeModulePkg/Bus/Usb/UsbMouseDxe/usbmouse.h b/MdeModulePkg/Bus/Usb/UsbMouseDxe/usbmouse.h
new file mode 100644 (file)
index 0000000..73cccb0
--- /dev/null
@@ -0,0 +1,108 @@
+/** @file\r
+\r
+Copyright (c) 2004 - 2007, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+  Module Name:\r
+\r
+    UsbMouse.h\r
+\r
+  Abstract:\r
+\r
+\r
+**/\r
+\r
+#ifndef _USB_MOUSE_H\r
+#define _USB_MOUSE_H\r
+\r
+//\r
+// The package level header files this module uses\r
+//\r
+#include <PiDxe.h>\r
+//\r
+// The protocols, PPI and GUID defintions for this module\r
+//\r
+#include <Protocol/SimplePointer.h>\r
+#include <Protocol/UsbIo.h>\r
+#include <Protocol/DevicePath.h>\r
+//\r
+// The Library classes this module consumes\r
+//\r
+#include <Library/ReportStatusCodeLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/UsbLib.h>\r
+\r
+#include <IndustryStandard/Usb.h>\r
+\r
+#define CLASS_HID               3\r
+#define SUBCLASS_BOOT           1\r
+#define PROTOCOL_MOUSE          2\r
+\r
+#define BOOT_PROTOCOL           0\r
+#define REPORT_PROTOCOL         1\r
+\r
+#define USB_MOUSE_DEV_SIGNATURE EFI_SIGNATURE_32 ('u', 'm', 'o', 'u')\r
+\r
+typedef struct {\r
+  BOOLEAN ButtonDetected;\r
+  UINT8   ButtonMinIndex;\r
+  UINT8   ButtonMaxIndex;\r
+  UINT8   Reserved;\r
+} PRIVATE_DATA;\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
+  UINT8                         NumberOfButtons;\r
+  INT32                         XLogicMax;\r
+  INT32                         XLogicMin;\r
+  INT32                         YLogicMax;\r
+  INT32                         YLogicMin;\r
+  EFI_SIMPLE_POINTER_PROTOCOL   SimplePointerProtocol;\r
+  EFI_SIMPLE_POINTER_STATE      State;\r
+  EFI_SIMPLE_POINTER_MODE       Mode;\r
+  BOOLEAN                       StateChanged;\r
+  PRIVATE_DATA                  PrivateData;\r
+  EFI_UNICODE_STRING_TABLE      *ControllerNameTable;\r
+} USB_MOUSE_DEV;\r
+\r
+#define USB_MOUSE_DEV_FROM_MOUSE_PROTOCOL(a) \\r
+    CR(a, USB_MOUSE_DEV, SimplePointerProtocol, USB_MOUSE_DEV_SIGNATURE)\r
+\r
+VOID\r
+EFIAPI\r
+USBMouseRecoveryHandler (\r
+  IN    EFI_EVENT    Event,\r
+  IN    VOID         *Context\r
+  );\r
+\r
+//\r
+// Global Variables\r
+//\r
+extern EFI_DRIVER_BINDING_PROTOCOL  gUsbMouseDriverBinding;\r
+extern EFI_COMPONENT_NAME_PROTOCOL  gUsbMouseComponentName;\r
+extern EFI_GUID                     gEfiUsbMouseDriverGuid;\r
+\r
+VOID\r
+MouseReportStatusCode (\r
+  IN EFI_DEVICE_PATH_PROTOCOL  *DevicePath,\r
+  IN EFI_STATUS_CODE_TYPE      CodeType,\r
+  IN EFI_STATUS_CODE_VALUE     Value\r
+  );\r
+\r
+#endif\r
index 9a53b46..92242c5 100644 (file)
@@ -9,7 +9,7 @@
 #    the terms and conditions of the BSD License which accompanies this distribution.\r
 #    The full text of the license may be found at\r
 #    http://opensource.org/licenses/bsd-license.php\r
-# \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
@@ -29,7 +29,7 @@
   PACKAGE_VERSION                = 0.1\r
 \r
 [Includes.common]\r
-  Include                        \r
+  Include\r
 \r
 ################################################################################\r
 #\r
@@ -68,7 +68,7 @@
   gEfiPeiPeCoffLoaderGuid        = { 0xd8117cff, 0x94a6, 0x11d4, {0x9a, 0x3a, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d } }\r
   gEfiPeiCorePrivateGuid         = { 0xd641a0f5, 0xcb7c, 0x4846, { 0xa3, 0x80, 0x1d, 0x01, 0xb4, 0xd9, 0xe3, 0xb9 }}\r
   gEfiExtendedSalVariableServicesProtocolGuid = {0x4ecb6c53, 0xc641, 0x4370, {0x8c, 0xb2, 0x3b, 0x0e, 0x49, 0x6e, 0x83, 0x78 }}\r
-  \r
+\r
 ################################################################################\r
 #\r
 # Global Protocols Definition section - list of Global Protocols C Name Data\r
@@ -92,7 +92,7 @@
   gEfiCustomizedDecompressProtocolGuid = { 0x9A44198E, 0xA4A2, 0x44E6, { 0x8A, 0x1F, 0x39, 0xBE, 0xFD, 0xAC, 0x89, 0x6F }}\r
   gEfiCapsuleArchProtocolGuid    = { 0x5053697E, 0x2EBC, 0x4819, { 0x90, 0xD9, 0x05, 0x80, 0xDE, 0xEE, 0x57, 0x54 }}\r
   gEfiCrc32GuidedSectionExtractionProtocolGuid = { 0xFC1BCDB0, 0x7D31, 0x49aa, {0x93, 0x6A, 0xA4, 0x60, 0x0D, 0x9D, 0xD0, 0x83 } }\r
\r
+\r
 \r
 \r
 \r
 ################################################################################\r
 [Ppis.common]\r
   gPeiBaseMemoryTestPpiGuid      = { 0xB6EC423C, 0x21D2, 0x490D, { 0x85, 0xC6, 0xDD, 0x58, 0x64, 0xEA, 0xA6, 0x74 }}\r
-  gEfiPeiFvFileLoaderPpiGuid     = { 0x7e1f0d85, 0x04ff, 0x4bb2, { 0x86, 0x6a, 0x31, 0xa2, 0x99, 0x6a, 0x48, 0xa8 }} \r
+  gEfiPeiFvFileLoaderPpiGuid     = { 0x7e1f0d85, 0x04ff, 0x4bb2, { 0x86, 0x6a, 0x31, 0xa2, 0x99, 0x6a, 0x48, 0xa8 }}\r
   ##gPeiFlashMapPpiGuid will be removed in future\r
   gPeiFlashMapPpiGuid            = { 0xf34c2fa0, 0xde88, 0x4270, {0x84, 0x14, 0x96, 0x12, 0x22, 0xf4, 0x52, 0x1c } }\r
 \r
   PcdFlashNvStorageFtwSpareSize|0x30000014|gEfiMdeModulePkgTokenSpaceGuid|UINT32|0x0\r
   PcdFlashNvStorageFtwWorkingBase|0x30000010|gEfiMdeModulePkgTokenSpaceGuid|UINT32|0x0\r
   PcdFlashNvStorageFtwWorkingSize|0x30000011|gEfiMdeModulePkgTokenSpaceGuid|UINT32|0x0\r
+  PcdStatusCodeValueMouseInterfaceError|0x30001000|gEfiMdePkgTokenSpaceGuid|UINT32|0x01020005\r
+  PcdStatusCodeValueMouseEnable|0x30001001|gEfiMdePkgTokenSpaceGuid|UINT32|0x01020004\r
+  PcdStatusCodeValueMouseDisable|0x3001002|gEfiMdePkgTokenSpaceGuid|UINT32|0x01020002\r
+  PcdStatusCodeValueKeyboardEnable|0x3001003|gEfiMdePkgTokenSpaceGuid|UINT32|0x01010004\r
+  PcdStatusCodeValueKeyboardDisable|0x3001004|gEfiMdePkgTokenSpaceGuid|UINT32|0x01010002\r
+  PcdStatusCodeValueKeyboardPresenceDetect|0x30001005|gEfiMdePkgTokenSpaceGuid|UINT32|0x01010003\r
+  PcdStatusCodeValueKeyboardReset|0x30001006|gEfiMdePkgTokenSpaceGuid|UINT32|0x01010001\r
+  PcdStatusCodeValueKeyboardClearBuffer|0x30001007|gEfiMdePkgTokenSpaceGuid|UINT32|0x01011000\r
+  PcdStatusCodeValueKeyboardSelfTest|0x30001008|gEfiMdePkgTokenSpaceGuid|UINT32|0x01011001\r
+  PcdStatusCodeValueKeyboardInterfaceError|0x30001009|gEfiMdePkgTokenSpaceGuid|UINT32|0x01010005\r
+  PcdStatusCodeValueKeyboardInputError|0x3000100a|gEfiMdePkgTokenSpaceGuid|UINT32|0x01010007\r
+  PcdStatusCodeValueMouseInputError|0x30001000b|gEfiMdePkgTokenSpaceGuid|UINT32|0x01020007\r
+  PcdStatusCodeValueMouseReset|0x30001000c|gEfiMdePkgTokenSpaceGuid|UINT32|0x01020001\r
 \r
 [PcdsDynamic.common]\r
   PcdFlashNvStorageVariableBase|0x30000001|gEfiMdeModulePkgTokenSpaceGuid|UINT32|0x0\r
index ee44ee1..e8ec07c 100644 (file)
   ReportStatusCodeLib|$(WORKSPACE)/IntelFrameworkPkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf\r
   ScsiLib|$(WORKSPACE)/MdePkg/Library/UefiScsiLib/UefiScsiLib.inf\r
   FrameworkHiiLib|$(WORKSPACE)/IntelFrameworkPkg/Library/FrameworkHiiLib/HiiLib.inf\r
+  UsbLib|$(WORKSPACE)/MdePkg/Library/UefiUsbLib/UefiUsbLib.inf\r
 \r
 [LibraryClasses.common.DXE_RUNTIME_DRIVER]\r
   HobLib|$(WORKSPACE)/MdePkg/Library/DxeHobLib/DxeHobLib.inf\r
   PcdStatusCodeValueRemoteConsoleInputError|gEfiMdePkgTokenSpaceGuid|0x01040007   # EFI_PERIPHERAL_REMOTE_CONSOLE | EFI_P_EC_INPUT_ERROR\r
   PcdStatusCodeValueRemoteConsoleOutputError|gEfiMdePkgTokenSpaceGuid|0x01040008  # EFI_PERIPHERAL_REMOTE_CONSOLE | EFI_P_EC_OUTPUT_ERROR\r
 \r
+  PcdStatusCodeValueMouseInterfaceError|gEfiMdePkgTokenSpaceGuid|0x01020005       # EFI_PERIPHERAL_MOUSE | EFI_P_EC_INTERFACE_ERROR\r
+  PcdStatusCodeValueMouseEnable|gEfiMdePkgTokenSpaceGuid|0x01020004               # EFI_PERIPHERAL_MOUSE | EFI_P_PC_ENABLE\r
+  PcdStatusCodeValueMouseDisable|gEfiMdePkgTokenSpaceGuid|0x01020002              # EFI_PERIPHERAL_MOUSE | EFI_P_PC_DISABLE\r
+  PcdStatusCodeValueKeyboardEnable|gEfiMdePkgTokenSpaceGuid|0x01010004            # EFI_PERIPHERAL_KEYBOARD | EFI_P_PC_ENABLE\r
+  PcdStatusCodeValueKeyboardPresenceDetect|gEfiMdePkgTokenSpaceGuid|0x01010003    # EFI_PERIPHERAL_KEYBOARD | EFI_P_PC_PRESENCE_DETECT\r
+  PcdStatusCodeValueKeyboardDisable|gEfiMdePkgTokenSpaceGuid|0x01010002           # EFI_PERIPHERAL_KEYBOARD | EFI_P_PC_DISABLE\r
+  PcdStatusCodeValueKeyboardReset|gEfiMdePkgTokenSpaceGuid|0x01010001             # EFI_PERIPHERAL_KEYBOARD | EFI_P_PC_RESET\r
+  PcdStatusCodeValueKeyboardClearBuffer|gEfiMdePkgTokenSpaceGuid|0x01011000       # EFI_PERIPHERAL_KEYBOARD | EFI_P_KEYBOARD_PC_CLEAR_BUFFER
+  PcdStatusCodeValueKeyboardSelfTest|gEfiMdePkgTokenSpaceGuid|0x01011001          # EFI_PERIPHERAL_KEYBOARD | EFI_P_KEYBOARD_PC_SELF_TEST\r
+  PcdStatusCodeValueKeyboardInterfaceError|gEfiMdePkgTokenSpaceGuid|0x01010005    # EFI_PERIPHERAL_KEYBOARD | EFI_P_EC_INTERFACE_ERROR\r
+  PcdStatusCodeValueKeyboardInputError|gEfiMdePkgTokenSpaceGuid|0x01010007        # EFI_PERIPHERAL_KEYBOARD | EFI_P_EC_INPUT_ERROR\r
+  PcdStatusCodeValueMouseInputError|gEfiMdePkgTokenSpaceGuid|0x01020007           # EFI_PERIPHERAL_MOUSE | EFI_P_EC_INPUT_ERROR\r
+  PcdStatusCodeValueMouseReset|gEfiMdePkgTokenSpaceGuid|0x01020001                # EFI_PERIPHERAL_MOUSE | EFI_P_PC_RESET\r
+\r
 [PcdsFixedAtBuild.IPF]\r
   PcdIoBlockBaseAddressForIpf|gEfiMdePkgTokenSpaceGuid|0x0ffffc000000\r
-  \r
+\r
 [PcdsPatchableInModule.common]\r
   PcdDebugPrintErrorLevel|gEfiMdePkgTokenSpaceGuid|0x80000000\r
   PcdPciExpressBaseAddress|gEfiMdePkgTokenSpaceGuid|0xE0000000\r
   $(WORKSPACE)/MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitter.inf\r
   $(WORKSPACE)/MdeModulePkg/Universal/DevicePathDxe/DevicePath.inf\r
   $(WORKSPACE)/MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsole.inf\r
-  $(WORKSPACE)/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.inf  \r
+  $(WORKSPACE)/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.inf\r
   $(WORKSPACE)/MdeModulePkg/Application/HelloWorld/HelloWorld.inf\r
   $(WORKSPACE)/MdeModulePkg/Bus/Pci/EhciDxe/EhciDxe.inf\r
   $(WORKSPACE)/MdeModulePkg/Bus/Pci/UhciDxe/UhciDxe.inf\r
   $(WORKSPACE)/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBusDxe.inf\r
-  $(WORKSPACE)/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassStorageDxe.inf  \r
+  $(WORKSPACE)/MdeModulePkg/Bus/Usb/UsbKbDxe/UsbKbDxe.inf\r
+  $(WORKSPACE)/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassStorageDxe.inf\r
+  $(WORKSPACE)/MdeModulePkg/Bus/Usb/UsbMouseDxe/UsbMouseDxe.inf\r
 \r
 [Components.Ia32]\r
-  $(WORKSPACE)/MdeModulePkg/Universal/Capsule/RuntimeDxe/CapsuleRuntime.inf  \r
+  $(WORKSPACE)/MdeModulePkg/Universal/Capsule/RuntimeDxe/CapsuleRuntime.inf\r
   $(WORKSPACE)/MdeModulePkg/Universal/VariableRuntimeDxe/Variable.inf\r
   $(WORKSPACE)/MdeModulePkg/Universal/EmuVariableRuntimeDxe/EmuVariable.inf\r
   $(WORKSPACE)/MdeModulePkg/Universal/MonotonicCounterDxe/MonotonicCounter.inf\r
 \r
 [Components.X64]\r
-  $(WORKSPACE)/MdeModulePkg/Universal/Capsule/RuntimeDxe/CapsuleRuntime.inf  \r
+  $(WORKSPACE)/MdeModulePkg/Universal/Capsule/RuntimeDxe/CapsuleRuntime.inf\r
   $(WORKSPACE)/MdeModulePkg/Universal/VariableRuntimeDxe/Variable.inf\r
   $(WORKSPACE)/MdeModulePkg/Universal/EmuVariableRuntimeDxe/EmuVariable.inf\r
-  $(WORKSPACE)/MdeModulePkg/Universal/MonotonicCounterDxe/MonotonicCounter.inf  \r
+  $(WORKSPACE)/MdeModulePkg/Universal/MonotonicCounterDxe/MonotonicCounter.inf\r
 \r
 [Components.IPF]\r
 \r
index 291eccb..1438328 100644 (file)
@@ -1,6 +1,5 @@
 /** @file\r
-   Common Dxe Libarary  for USB\r
-   Add Constants & structure definitions for Usb HID\r
+  Common Dxe Libarary  for USB\r
 \r
   Copyright (c) 2006, Intel Corporation<BR>\r
   All rights reserved. This program and the accompanying materials\r
 #define __USB_DXE_LIB_H__\r
 \r
 #include <Protocol/UsbIo.h>\r
+\r
+//\r
+// Standard device request and request type\r
+// By [Spec-USB20/Chapter-9.4]\r
+//\r
+#define USB_DEV_GET_STATUS                  0x00\r
+#define USB_DEV_GET_STATUS_REQ_TYPE_D       0x80 // Receiver : Device\r
+#define USB_DEV_GET_STATUS_REQ_TYPE_I       0x81 // Receiver : Interface\r
+#define USB_DEV_GET_STATUS_REQ_TYPE_E       0x82 // Receiver : Endpoint\r
+\r
+#define USB_DEV_CLEAR_FEATURE               0x01\r
+#define USB_DEV_CLEAR_FEATURE_REQ_TYPE_D    0x00 // Receiver : Device\r
+#define USB_DEV_CLEAR_FEATURE_REQ_TYPE_I    0x01 // Receiver : Interface\r
+#define USB_DEV_CLEAR_FEATURE_REQ_TYPE_E    0x02 // Receiver : Endpoint\r
+\r
+#define USB_DEV_SET_FEATURE                 0x03\r
+#define USB_DEV_SET_FEATURE_REQ_TYPE_D      0x00 // Receiver : Device\r
+#define USB_DEV_SET_FEATURE_REQ_TYPE_I      0x01 // Receiver : Interface\r
+#define USB_DEV_SET_FEATURE_REQ_TYPE_E      0x02 // Receiver : Endpoint\r
+\r
+#define USB_DEV_SET_ADDRESS                 0x05\r
+#define USB_DEV_SET_ADDRESS_REQ_TYPE        0x00\r
+\r
+#define USB_DEV_GET_DESCRIPTOR              0x06\r
+#define USB_DEV_GET_DESCRIPTOR_REQ_TYPE     0x80\r
+\r
+#define USB_DEV_SET_DESCRIPTOR              0x07\r
+#define USB_DEV_SET_DESCRIPTOR_REQ_TYPE     0x00\r
+\r
+#define USB_DEV_GET_CONFIGURATION           0x08\r
+#define USB_DEV_GET_CONFIGURATION_REQ_TYPE  0x80\r
+\r
+#define USB_DEV_SET_CONFIGURATION           0x09\r
+#define USB_DEV_SET_CONFIGURATION_REQ_TYPE  0x00\r
+\r
+#define USB_DEV_GET_INTERFACE               0x0A\r
+#define USB_DEV_GET_INTERFACE_REQ_TYPE      0x81\r
+\r
+#define USB_DEV_SET_INTERFACE               0x0B\r
+#define USB_DEV_SET_INTERFACE_REQ_TYPE      0x01\r
+\r
+#define USB_DEV_SYNCH_FRAME                 0x0C\r
+#define USB_DEV_SYNCH_FRAME_REQ_TYPE        0x82\r
+\r
 //\r
 // define the timeout time as 3ms\r
 //\r
@@ -233,9 +276,11 @@ UsbGetReportRequest (
   IN UINT8                   *Report\r
   );\r
 \r
-//\r
-// Get Device Descriptor\r
-//\r
+typedef enum {\r
+  EfiUsbEndpointHalt,\r
+  EfiUsbDeviceRemoteWakeup\r
+} EFI_USB_STANDARD_FEATURE_SELECTOR;\r
+\r
 EFI_STATUS\r
 UsbGetDescriptor (\r
   IN  EFI_USB_IO_PROTOCOL     *UsbIo,\r
@@ -246,9 +291,6 @@ UsbGetDescriptor (
   OUT UINT32                  *Status\r
   );\r
 \r
-//\r
-// Set Device Descriptor\r
-//\r
 EFI_STATUS\r
 UsbSetDescriptor (\r
   IN  EFI_USB_IO_PROTOCOL     *UsbIo,\r
@@ -259,97 +301,70 @@ UsbSetDescriptor (
   OUT UINT32                  *Status\r
   );\r
 \r
-//\r
-// Get device Interface\r
-//\r
 EFI_STATUS\r
-UsbGetDeviceInterface (\r
+UsbGetInterface (\r
   IN  EFI_USB_IO_PROTOCOL     *UsbIo,\r
   IN  UINT16                  Index,\r
   OUT UINT8                   *AltSetting,\r
   OUT UINT32                  *Status\r
   );\r
 \r
-//\r
-// Set device interface\r
-//\r
 EFI_STATUS\r
-UsbSetDeviceInterface (\r
+UsbSetInterface (\r
   IN  EFI_USB_IO_PROTOCOL     *UsbIo,\r
   IN  UINT16                  InterfaceNo,\r
   IN  UINT16                  AltSetting,\r
   OUT UINT32                  *Status\r
   );\r
 \r
-//\r
-// Get device configuration\r
-//\r
 EFI_STATUS\r
-UsbGetDeviceConfiguration (\r
+UsbGetConfiguration (\r
   IN  EFI_USB_IO_PROTOCOL     *UsbIo,\r
   OUT UINT8                   *ConfigValue,\r
   OUT UINT32                  *Status\r
   );\r
 \r
-//\r
-// Set device configuration\r
-//\r
 EFI_STATUS\r
-UsbSetDeviceConfiguration (\r
+UsbSetConfiguration (\r
   IN  EFI_USB_IO_PROTOCOL     *UsbIo,\r
   IN  UINT16                  Value,\r
   OUT UINT32                  *Status\r
   );\r
 \r
-//\r
-//  Set Device Feature\r
-//\r
 EFI_STATUS\r
-UsbSetDeviceFeature (\r
+UsbSetFeature (\r
   IN  EFI_USB_IO_PROTOCOL     *UsbIo,\r
-  IN  EFI_USB_RECIPIENT       Recipient,\r
+  IN  UINTN                   Recipient,\r
   IN  UINT16                  Value,\r
   IN  UINT16                  Target,\r
   OUT UINT32                  *Status\r
   );\r
 \r
-//\r
-// Clear Device Feature\r
-//\r
 EFI_STATUS\r
-UsbClearDeviceFeature (\r
+UsbClearFeature (\r
   IN  EFI_USB_IO_PROTOCOL     *UsbIo,\r
-  IN  EFI_USB_RECIPIENT       Recipient,\r
+  IN  UINTN                   Recipient,\r
   IN  UINT16                  Value,\r
   IN  UINT16                  Target,\r
   OUT UINT32                  *Status\r
   );\r
 \r
-//\r
-//  Get Device Status\r
-//\r
 EFI_STATUS\r
-UsbGetDeviceStatus (\r
+UsbGetStatus (\r
   IN  EFI_USB_IO_PROTOCOL     *UsbIo,\r
-  IN  EFI_USB_RECIPIENT       Recipient,\r
+  IN  UINTN                   Recipient,\r
   IN  UINT16                  Target,\r
   OUT UINT16                  *DevStatus,\r
   OUT UINT32                  *Status\r
   );\r
 \r
-//\r
-// The following APIs are not basic library, but they are common used.\r
-//\r
-//\r
-// Usb Get String\r
-//\r
 EFI_STATUS\r
-UsbGetString (\r
+UsbGetHubDescriptor (\r
   IN  EFI_USB_IO_PROTOCOL     *UsbIo,\r
-  IN  UINT16                  LangID,\r
-  IN  UINT                  Index,\r
-  IN  VOID                    *Buf,\r
-  IN  UINTN                   BufSize,\r
+  IN  UINT16                  Value,\r
+  IN  UINT16                  Index,\r
+  IN  UINT16                  DescriptorLength,\r
+  OUT VOID                    *Descriptor,\r
   OUT UINT32                  *Status\r
   );\r
 \r
index e0c46ae..adf2757 100644 (file)
@@ -25,7 +25,7 @@
   FILE_GUID                      = 87eb5df9-722a-4241-ad7f-370d0b3a56d7\r
   MODULE_TYPE                    = UEFI_DRIVER\r
   VERSION_STRING                 = 1.0\r
-  LIBRARY_CLASS                  = UsbLib|DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER \r
+  LIBRARY_CLASS                  = UsbLib|DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER\r
   EDK_RELEASE_VERSION            = 0x00020000\r
   EFI_SPECIFICATION_VERSION      = 0x00020000\r
 \r
@@ -45,8 +45,6 @@
 [Sources.common]\r
   hid.c\r
   UsbDxeLib.c\r
-  CommonHeader.h\r
-\r
 \r
 ################################################################################\r
 #\r
index d552426..1226226 100644 (file)
@@ -30,6 +30,7 @@
     </LibraryClass>\r
   </LibraryClassDefinitions>\r
   <SourceFiles>\r
+    <Filename>hid.h</Filename>\r
     <Filename>UsbDxeLib.c</Filename>\r
     <Filename>hid.c</Filename>\r
   </SourceFiles>\r
index 626fa22..cb88853 100644 (file)
@@ -1,13 +1,13 @@
-/*++\r
+/** @file\r
 \r
-Copyright (c) 2006, 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
+Copyright (c) 2004 - 2007, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
  Module Name:\r
 \r
@@ -19,13 +19,34 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
  Revision History\r
 \r
---*/\r
 \r
-#include "UefiUsbLibInternal.h"\r
+**/\r
 \r
 //\r
-// Get Device Descriptor\r
+// The package level header files this module uses\r
+//\r
+#include <PiDxe.h>\r
+//\r
+// The Library classes this module consumes\r
 //\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/UsbLib.h>\r
+\r
+/**\r
+  Usb Get Descriptor\r
+\r
+  @param  UsbIo                  EFI_USB_IO_PROTOCOL\r
+  @param  Value                  Device Request Value\r
+  @param  Index                  Device Request Index\r
+  @param  DescriptorLength       Descriptor Length\r
+  @param  Descriptor             Descriptor buffer to contain result\r
+  @param  Status                 Transfer Status\r
+\r
+  @retval EFI_INVALID_PARAMETER  Parameter is error\r
+  @retval EFI_SUCCESS            Success\r
+  @retval EFI_TIMEOUT            Device has no response\r
+\r
+**/\r
 EFI_STATUS\r
 UsbGetDescriptor (\r
   IN  EFI_USB_IO_PROTOCOL     *UsbIo,\r
@@ -35,26 +56,6 @@ UsbGetDescriptor (
   OUT VOID                    *Descriptor,\r
   OUT UINT32                  *Status\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Usb Get Descriptor\r
-\r
-Arguments:\r
-\r
-  UsbIo             - EFI_USB_IO_PROTOCOL\r
-  Value             - Device Request Value\r
-  Index             - Device Request Index \r
-  DescriptorLength  - Descriptor Length\r
-  Descriptor        - Descriptor buffer to contain result\r
-  Status            - Transfer Status\r
-Returns:\r
-  EFI_INVALID_PARAMETER - Parameter is error\r
-  EFI_SUCCESS           - Success\r
-  EFI_TIMEOUT           - Device has no response \r
-\r
---*/\r
 {\r
   EFI_USB_DEVICE_REQUEST  DevReq;\r
 \r
@@ -65,7 +66,7 @@ Returns:
   ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r
 \r
   DevReq.RequestType  = USB_DEV_GET_DESCRIPTOR_REQ_TYPE;\r
-  DevReq.Request      = USB_DEV_GET_DESCRIPTOR;\r
+  DevReq.Request      = USB_REQ_GET_DESCRIPTOR;\r
   DevReq.Value        = Value;\r
   DevReq.Index        = Index;\r
   DevReq.Length       = DescriptorLength;\r
@@ -80,9 +81,23 @@ Returns:
                   Status\r
                   );\r
 }\r
-//\r
-// Set Device Descriptor\r
-//\r
+\r
+\r
+/**\r
+  Usb Set Descriptor\r
+\r
+  @param  UsbIo                  EFI_USB_IO_PROTOCOL\r
+  @param  Value                  Device Request Value\r
+  @param  Index                  Device Request Index\r
+  @param  DescriptorLength       Descriptor Length\r
+  @param  Descriptor             Descriptor buffer to set\r
+  @param  Status                 Transfer Status\r
+\r
+  @retval EFI_INVALID_PARAMETER  Parameter is error\r
+  @retval EFI_SUCCESS            Success\r
+  @retval EFI_TIMEOUT            Device has no response\r
+\r
+**/\r
 EFI_STATUS\r
 UsbSetDescriptor (\r
   IN  EFI_USB_IO_PROTOCOL     *UsbIo,\r
@@ -92,26 +107,6 @@ UsbSetDescriptor (
   IN  VOID                    *Descriptor,\r
   OUT UINT32                  *Status\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Usb Set Descriptor\r
-\r
-Arguments:\r
-\r
-  UsbIo             - EFI_USB_IO_PROTOCOL\r
-  Value             - Device Request Value\r
-  Index             - Device Request Index \r
-  DescriptorLength  - Descriptor Length\r
-  Descriptor        - Descriptor buffer to set\r
-  Status            - Transfer Status\r
-Returns:\r
-  EFI_INVALID_PARAMETER - Parameter is error\r
-  EFI_SUCCESS           - Success\r
-  EFI_TIMEOUT           - Device has no response \r
-\r
---*/\r
 {\r
   EFI_USB_DEVICE_REQUEST  DevReq;\r
 \r
@@ -122,7 +117,7 @@ Returns:
   ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r
 \r
   DevReq.RequestType  = USB_DEV_SET_DESCRIPTOR_REQ_TYPE;\r
-  DevReq.Request      = USB_DEV_SET_DESCRIPTOR;\r
+  DevReq.Request      = USB_REQ_SET_DESCRIPTOR;\r
   DevReq.Value        = Value;\r
   DevReq.Index        = Index;\r
   DevReq.Length       = DescriptorLength;\r
@@ -138,37 +133,27 @@ Returns:
                   );\r
 }\r
 \r
-//\r
-// Get device Interface\r
-//\r
+\r
+/**\r
+  Usb Get Device Interface\r
+\r
+  @param  UsbIo                  EFI_USB_IO_PROTOCOL\r
+  @param  Index                  Interface index value\r
+  @param  AltSetting             Alternate setting\r
+  @param  Status                 Trasnsfer status\r
+\r
+  @retval EFI_INVALID_PARAMETER  Parameter is error\r
+  @retval EFI_SUCCESS            Success\r
+  @retval EFI_TIMEOUT            Device has no response\r
+\r
+**/\r
 EFI_STATUS\r
-UsbGetDeviceInterface (\r
+UsbGetInterface (\r
   IN  EFI_USB_IO_PROTOCOL     *UsbIo,\r
   IN  UINT16                  Index,\r
   OUT UINT8                   *AltSetting,\r
   OUT UINT32                  *Status\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Usb Get Device Interface\r
-\r
-Arguments:\r
-\r
-  UsbIo       - EFI_USB_IO_PROTOCOL\r
-  Index       - Interface index value\r
-  AltSetting  - Alternate setting\r
-  Status      - Trasnsfer status\r
-\r
-Returns:\r
-\r
-  EFI_INVALID_PARAMETER - Parameter is error\r
-  EFI_SUCCESS           - Success\r
-  EFI_TIMEOUT           - Device has no response \r
-\r
-\r
---*/\r
 {\r
   EFI_USB_DEVICE_REQUEST  DevReq;\r
 \r
@@ -179,7 +164,7 @@ Returns:
   ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r
 \r
   DevReq.RequestType  = USB_DEV_GET_INTERFACE_REQ_TYPE;\r
-  DevReq.Request      = USB_DEV_GET_INTERFACE;\r
+  DevReq.Request      = USB_REQ_GET_INTERFACE;\r
   DevReq.Index        = Index;\r
   DevReq.Length       = 1;\r
 \r
@@ -193,36 +178,28 @@ Returns:
                   Status\r
                   );\r
 }\r
-//\r
-// Set device interface\r
-//\r
-EFI_STATUS\r
-UsbSetDeviceInterface (\r
-  IN  EFI_USB_IO_PROTOCOL     *UsbIo,\r
-  IN  UINT16                  InterfaceNo,\r
-  IN  UINT16                  AltSetting,\r
-  OUT UINT32                  *Status\r
-  )\r
-/*++\r
 \r
-Routine Description:\r
 \r
+/**\r
   Usb Set Device Interface\r
 \r
-Arguments:\r
-\r
-  UsbIo       - EFI_USB_IO_PROTOCOL\r
-  InterfaceNo - Interface Number\r
-  AltSetting  - Alternate setting\r
-  Status      - Trasnsfer status\r
+  @param  UsbIo                  EFI_USB_IO_PROTOCOL\r
+  @param  InterfaceNo            Interface Number\r
+  @param  AltSetting             Alternate setting\r
+  @param  Status                 Trasnsfer status\r
 \r
-Returns:\r
+  @retval EFI_INVALID_PARAMETER  Parameter is error\r
+  @retval EFI_SUCCESS            Success\r
+  @retval EFI_TIMEOUT            Device has no response\r
 \r
-  EFI_INVALID_PARAMETER - Parameter is error\r
-  EFI_SUCCESS           - Success\r
-  EFI_TIMEOUT           - Device has no response \r
-\r
---*/\r
+**/\r
+EFI_STATUS\r
+UsbSetInterface (\r
+  IN  EFI_USB_IO_PROTOCOL     *UsbIo,\r
+  IN  UINT16                  InterfaceNo,\r
+  IN  UINT16                  AltSetting,\r
+  OUT UINT32                  *Status\r
+  )\r
 {\r
   EFI_USB_DEVICE_REQUEST  DevReq;\r
 \r
@@ -233,10 +210,10 @@ Returns:
   ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r
 \r
   DevReq.RequestType  = USB_DEV_SET_INTERFACE_REQ_TYPE;\r
-  DevReq.Request      = USB_DEV_SET_INTERFACE;\r
+  DevReq.Request      = USB_REQ_SET_INTERFACE;\r
   DevReq.Value        = AltSetting;\r
   DevReq.Index        = InterfaceNo;\r
\r
+\r
 \r
   return UsbIo->UsbControlTransfer (\r
                   UsbIo,\r
@@ -248,34 +225,26 @@ Returns:
                   Status\r
                   );\r
 }\r
-//\r
-// Get device configuration\r
-//\r
-EFI_STATUS\r
-UsbGetDeviceConfiguration (\r
-  IN  EFI_USB_IO_PROTOCOL     *UsbIo,\r
-  OUT UINT8                   *ConfigValue,\r
-  OUT UINT32                  *Status\r
-  )\r
-/*++\r
 \r
-Routine Description:\r
 \r
+/**\r
   Usb Get Device Configuration\r
 \r
-Arguments:\r
-\r
-  UsbIo       - EFI_USB_IO_PROTOCOL\r
-  ConfigValue - Config Value\r
-  Status      - Transfer Status\r
-\r
-Returns:\r
+  @param  UsbIo                  EFI_USB_IO_PROTOCOL\r
+  @param  ConfigValue            Config Value\r
+  @param  Status                 Transfer Status\r
 \r
-  EFI_INVALID_PARAMETER - Parameter is error\r
-  EFI_SUCCESS           - Success\r
-  EFI_TIMEOUT           - Device has no response \r
+  @retval EFI_INVALID_PARAMETER  Parameter is error\r
+  @retval EFI_SUCCESS            Success\r
+  @retval EFI_TIMEOUT            Device has no response\r
 \r
---*/\r
+**/\r
+EFI_STATUS\r
+UsbGetConfiguration (\r
+  IN  EFI_USB_IO_PROTOCOL     *UsbIo,\r
+  OUT UINT8                   *ConfigValue,\r
+  OUT UINT32                  *Status\r
+  )\r
 {\r
   EFI_USB_DEVICE_REQUEST  DevReq;\r
 \r
@@ -286,7 +255,7 @@ Returns:
   ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r
 \r
   DevReq.RequestType  = USB_DEV_GET_CONFIGURATION_REQ_TYPE;\r
-  DevReq.Request      = USB_DEV_GET_CONFIGURATION;\r
+  DevReq.Request      = USB_REQ_GET_CONFIG;\r
   DevReq.Length       = 1;\r
 \r
   return UsbIo->UsbControlTransfer (\r
@@ -299,34 +268,26 @@ Returns:
                   Status\r
                   );\r
 }\r
-//\r
-// Set device configuration\r
-//\r
-EFI_STATUS\r
-UsbSetDeviceConfiguration (\r
-  IN  EFI_USB_IO_PROTOCOL     *UsbIo,\r
-  IN  UINT16                  Value,\r
-  OUT UINT32                  *Status\r
-  )\r
-/*++\r
 \r
-Routine Description:\r
 \r
+/**\r
   Usb Set Device Configuration\r
 \r
-Arguments:\r
-\r
-  UsbIo   - EFI_USB_IO_PROTOCOL\r
-  Value   - Configuration Value to set\r
-  Status  - Transfer status\r
+  @param  UsbIo                  EFI_USB_IO_PROTOCOL\r
+  @param  Value                  Configuration Value to set\r
+  @param  Status                 Transfer status\r
 \r
-Returns:\r
+  @retval EFI_INVALID_PARAMETER  Parameter is error\r
+  @retval EFI_SUCCESS            Success\r
+  @retval EFI_TIMEOUT            Device has no response\r
 \r
-  EFI_INVALID_PARAMETER - Parameter is error\r
-  EFI_SUCCESS           - Success\r
-  EFI_TIMEOUT           - Device has no response \r
-\r
---*/\r
+**/\r
+EFI_STATUS\r
+UsbSetConfiguration (\r
+  IN  EFI_USB_IO_PROTOCOL     *UsbIo,\r
+  IN  UINT16                  Value,\r
+  OUT UINT32                  *Status\r
+  )\r
 {\r
   EFI_USB_DEVICE_REQUEST  DevReq;\r
 \r
@@ -337,9 +298,9 @@ Returns:
   ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));\r
 \r
   DevReq.RequestType  = USB_DEV_SET_CONFIGURATION_REQ_TYPE;\r
-  DevReq.Request      = USB_DEV_SET_CONFIGURATION;\r
+  DevReq.Request      = USB_REQ_SET_CONFIG;\r
   DevReq.Value        = Value;\r
\r
+\r
   return UsbIo->UsbControlTransfer (\r
                   UsbIo,\r
                   &DevReq,\r
@@ -350,38 +311,30 @@ Returns:
                   Status\r
                   );\r
 }\r
-//\r
-//  Set Device Feature\r
-//\r
-EFI_STATUS\r
-UsbSetDeviceFeature (\r
-  IN  EFI_USB_IO_PROTOCOL     *UsbIo,\r
-  IN  EFI_USB_RECIPIENT       Recipient,\r
-  IN  UINT16                  Value,\r
-  IN  UINT16                  Target,\r
-  OUT UINT32                  *Status\r
-  )\r
-/*++\r
 \r
-Routine Description:\r
 \r
+/**\r
   Usb Set Device Feature\r
 \r
-Arguments:\r
+  @param  UsbIo                  EFI_USB_IO_PROTOCOL\r
+  @param  Recipient              Interface/Device/Endpoint\r
+  @param  Value                  Request value\r
+  @param  Target                 Request Index\r
+  @param  Status                 Transfer status\r
 \r
-  UsbIo     - EFI_USB_IO_PROTOCOL\r
-  Recipient - Interface/Device/Endpoint\r
-  Value     - Request value\r
-  Target    - Request Index\r
-  Status    - Transfer status\r
+  @retval EFI_INVALID_PARAMETER  Parameter is error\r
+  @retval EFI_SUCCESS            Success\r
+  @retval EFI_TIMEOUT            Device has no response\r
 \r
-Returns:\r
-  \r
-  EFI_INVALID_PARAMETER - Parameter is error\r
-  EFI_SUCCESS           - Success\r
-  EFI_TIMEOUT           - Device has no response \r
-\r
---*/\r
+**/\r
+EFI_STATUS\r
+UsbSetFeature (\r
+  IN  EFI_USB_IO_PROTOCOL     *UsbIo,\r
+  IN  UINTN       Recipient,\r
+  IN  UINT16                  Value,\r
+  IN  UINT16                  Target,\r
+  OUT UINT32                  *Status\r
+  )\r
 {\r
   EFI_USB_DEVICE_REQUEST  DevReq;\r
 \r
@@ -393,22 +346,22 @@ Returns:
 \r
   switch (Recipient) {\r
 \r
-  case EfiUsbDevice:\r
-    DevReq.RequestType = 0x00;\r
+  case USB_TARGET_DEVICE:\r
+    DevReq.RequestType = USB_DEV_SET_FEATURE_REQ_TYPE_D;\r
     break;\r
 \r
-  case EfiUsbInterface:\r
-    DevReq.RequestType = 0x01;\r
+  case USB_TARGET_INTERFACE:\r
+    DevReq.RequestType = USB_DEV_SET_FEATURE_REQ_TYPE_I;\r
     break;\r
 \r
-  case EfiUsbEndpoint:\r
-    DevReq.RequestType = 0x02;\r
+  case USB_TARGET_ENDPOINT:\r
+    DevReq.RequestType = USB_DEV_SET_FEATURE_REQ_TYPE_E;\r
     break;\r
   }\r
   //\r
   // Fill device request, see USB1.1 spec\r
   //\r
-  DevReq.Request  = USB_DEV_SET_FEATURE;\r
+  DevReq.Request  = USB_REQ_SET_FEATURE;\r
   DevReq.Value    = Value;\r
   DevReq.Index    = Target;\r
 \r
@@ -423,38 +376,30 @@ Returns:
                   Status\r
                   );\r
 }\r
-//\r
-// Clear Device Feature\r
-//\r
-EFI_STATUS\r
-UsbClearDeviceFeature (\r
-  IN  EFI_USB_IO_PROTOCOL     *UsbIo,\r
-  IN  EFI_USB_RECIPIENT       Recipient,\r
-  IN  UINT16                  Value,\r
-  IN  UINT16                  Target,\r
-  OUT UINT32                  *Status\r
-  )\r
-/*++\r
 \r
-Routine Description:\r
 \r
+/**\r
   Usb Clear Device Feature\r
 \r
-Arguments:\r
+  @param  UsbIo                  EFI_USB_IO_PROTOCOL\r
+  @param  Recipient              Interface/Device/Endpoint\r
+  @param  Value                  Request value\r
+  @param  Target                 Request Index\r
+  @param  Status                 Transfer status\r
 \r
-  UsbIo     - EFI_USB_IO_PROTOCOL\r
-  Recipient - Interface/Device/Endpoint\r
-  Value     - Request value\r
-  Target    - Request Index\r
-  Status    - Transfer status\r
+  @retval EFI_INVALID_PARAMETER  Parameter is error\r
+  @retval EFI_SUCCESS            Success\r
+  @retval EFI_TIMEOUT            Device has no response\r
 \r
-Returns:\r
-  \r
-  EFI_INVALID_PARAMETER - Parameter is error\r
-  EFI_SUCCESS           - Success\r
-  EFI_TIMEOUT           - Device has no response \r
-\r
---*/\r
+**/\r
+EFI_STATUS\r
+UsbClearFeature (\r
+  IN  EFI_USB_IO_PROTOCOL     *UsbIo,\r
+  IN  UINTN       Recipient,\r
+  IN  UINT16                  Value,\r
+  IN  UINT16                  Target,\r
+  OUT UINT32                  *Status\r
+  )\r
 {\r
   EFI_USB_DEVICE_REQUEST  DevReq;\r
 \r
@@ -466,22 +411,22 @@ Returns:
 \r
   switch (Recipient) {\r
 \r
-  case EfiUsbDevice:\r
-    DevReq.RequestType = 0x00;\r
+  case USB_TARGET_DEVICE:\r
+    DevReq.RequestType = USB_DEV_CLEAR_FEATURE_REQ_TYPE_D;\r
     break;\r
 \r
-  case EfiUsbInterface:\r
-    DevReq.RequestType = 0x01;\r
+  case USB_TARGET_INTERFACE:\r
+    DevReq.RequestType = USB_DEV_CLEAR_FEATURE_REQ_TYPE_I;\r
     break;\r
 \r
-  case EfiUsbEndpoint:\r
-    DevReq.RequestType = 0x02;\r
+  case USB_TARGET_ENDPOINT:\r
+    DevReq.RequestType = USB_DEV_CLEAR_FEATURE_REQ_TYPE_E;\r
     break;\r
   }\r
   //\r
   // Fill device request, see USB1.1 spec\r
   //\r
-  DevReq.Request  = USB_DEV_CLEAR_FEATURE;\r
+  DevReq.Request  = USB_REQ_CLEAR_FEATURE;\r
   DevReq.Value    = Value;\r
   DevReq.Index    = Target;\r
 \r
@@ -496,38 +441,30 @@ Returns:
                   Status\r
                   );\r
 }\r
-//\r
-//  Get Device Status\r
-//\r
-EFI_STATUS\r
-UsbGetDeviceStatus (\r
-  IN  EFI_USB_IO_PROTOCOL     *UsbIo,\r
-  IN  EFI_USB_RECIPIENT       Recipient,\r
-  IN  UINT16                  Target,\r
-  OUT UINT16                  *DevStatus,\r
-  OUT UINT32                  *Status\r
-  )\r
-/*++\r
 \r
-Routine Description:\r
 \r
+/**\r
   Usb Get Device Status\r
 \r
-Arguments:\r
+  @param  UsbIo                  EFI_USB_IO_PROTOCOL\r
+  @param  Recipient              Interface/Device/Endpoint\r
+  @param  Target                 Request index\r
+  @param  DevStatus              Device status\r
+  @param  Status                 Transfer status\r
 \r
-  UsbIo     - EFI_USB_IO_PROTOCOL\r
-  Recipient - Interface/Device/Endpoint\r
-  Target    - Request index\r
-  DevStatus - Device status\r
-  Status    - Transfer status\r
+  @retval EFI_INVALID_PARAMETER  Parameter is error\r
+  @retval EFI_SUCCESS            Success\r
+  @retval EFI_TIMEOUT            Device has no response\r
 \r
-Returns:\r
-  \r
-  EFI_INVALID_PARAMETER - Parameter is error\r
-  EFI_SUCCESS           - Success\r
-  EFI_TIMEOUT           - Device has no response \r
-\r
---*/\r
+**/\r
+EFI_STATUS\r
+UsbGetStatus (\r
+  IN  EFI_USB_IO_PROTOCOL     *UsbIo,\r
+  IN  UINTN       Recipient,\r
+  IN  UINT16                  Target,\r
+  OUT UINT16                  *DevStatus,\r
+  OUT UINT32                  *Status\r
+  )\r
 {\r
   EFI_USB_DEVICE_REQUEST  DevReq;\r
 \r
@@ -539,22 +476,22 @@ Returns:
 \r
   switch (Recipient) {\r
 \r
-  case EfiUsbDevice:\r
-    DevReq.RequestType = 0x80;\r
+  case USB_TARGET_DEVICE:\r
+    DevReq.RequestType = USB_DEV_GET_STATUS_REQ_TYPE_D;\r
     break;\r
 \r
-  case EfiUsbInterface:\r
-    DevReq.RequestType = 0x81;\r
+  case USB_TARGET_INTERFACE:\r
+    DevReq.RequestType = USB_DEV_GET_STATUS_REQ_TYPE_I;\r
     break;\r
 \r
-  case EfiUsbEndpoint:\r
-    DevReq.RequestType = 0x82;\r
+  case USB_TARGET_ENDPOINT:\r
+    DevReq.RequestType = USB_DEV_GET_STATUS_REQ_TYPE_E;\r
     break;\r
   }\r
   //\r
   // Fill device request, see USB1.1 spec\r
   //\r
-  DevReq.Request  = USB_DEV_GET_STATUS;\r
+  DevReq.Request  = USB_REQ_GET_STATUS;\r
   DevReq.Value    = 0;\r
   DevReq.Index    = Target;\r
   DevReq.Length   = 2;\r
@@ -569,86 +506,27 @@ Returns:
                   Status\r
                   );\r
 }\r
-//\r
-// Usb Get String\r
-//\r
-EFI_STATUS\r
-UsbGetString (\r
-  IN  EFI_USB_IO_PROTOCOL     *UsbIo,\r
-  IN  UINT16                  LangID,\r
-  IN  UINT8                   Index,\r
-  IN  VOID                    *Buf,\r
-  IN  UINTN                   BufSize,\r
-  OUT UINT32                  *Status\r
-  )\r
-/*++\r
 \r
-Routine Description:\r
 \r
-  Usb Get String\r
 \r
-Arguments:\r
+/**\r
+  Clear endpoint stall\r
 \r
-  UsbIo     - EFI_USB_IO_PROTOCOL\r
-  LangID    - Language ID\r
-  Index     - Request index\r
-  Buf       - Buffer to store string\r
-  BufSize   - Buffer size\r
-  Status    - Transfer status\r
+  @param  UsbIo                  EFI_USB_IO_PROTOCOL\r
+  @param  EndpointNo             Endpoint Number\r
+  @param  Status                 Transfer Status\r
 \r
-Returns:\r
-  \r
-  EFI_INVALID_PARAMETER - Parameter is error\r
-  EFI_SUCCESS           - Success\r
-  EFI_TIMEOUT           - Device has no response \r
-\r
---*/\r
-{\r
-  UINT16  Value;\r
-\r
-  if (UsbIo == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-  //\r
-  // Fill value, see USB1.1 spec\r
-  //\r
-  Value = (UINT16) ((USB_DT_STRING << 8) | Index);\r
-\r
-  return UsbGetDescriptor (\r
-          UsbIo,\r
-          Value,\r
-          LangID,\r
-          (UINT16) BufSize,\r
-          Buf,\r
-          Status\r
-          );\r
-}\r
+  @retval EFI_NOT_FOUND          Can't find the Endpoint\r
+  @retval EFI_DEVICE_ERROR       Hardware error\r
+  @retval EFI_SUCCESS            Success\r
 \r
+**/\r
 EFI_STATUS\r
 UsbClearEndpointHalt (\r
   IN  EFI_USB_IO_PROTOCOL     *UsbIo,\r
   IN  UINT8                   EndpointNo,\r
   OUT UINT32                  *Status\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Clear endpoint stall\r
-\r
-Arguments:\r
-\r
-  UsbIo       - EFI_USB_IO_PROTOCOL\r
-  EndpointNo  - Endpoint Number\r
-  Status      - Transfer Status\r
-\r
-Returns:\r
-\r
-  EFI_NOT_FOUND    - Can't find the Endpoint\r
-  EFI_DEVICE_ERROR - Hardware error\r
-  EFI_SUCCESS      - Success\r
-\r
---*/\r
 {\r
   EFI_STATUS                    Result;\r
   EFI_USB_ENDPOINT_DESCRIPTOR   EndpointDescriptor;\r
@@ -689,9 +567,9 @@ Returns:
     return EFI_NOT_FOUND;\r
   }\r
 \r
-  Result = UsbClearDeviceFeature (\r
+  Result = UsbClearFeature (\r
             UsbIo,\r
-            EfiUsbEndpoint,\r
+            USB_TARGET_ENDPOINT,\r
             EfiUsbEndpointHalt,\r
             EndpointDescriptor.EndpointAddress,\r
             Status\r
index a1019a0..3156f63 100644 (file)
@@ -1,13 +1,13 @@
-/*++\r
+/** @file\r
 \r
-Copyright (c) 2006, 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
+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
@@ -19,36 +19,34 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
   Revision History\r
 \r
---*/\r
 \r
-#include "UefiUsbLibInternal.h"\r
+**/\r
+#include <PiDxe.h>\r
+#include <Library/UsbLib.h>\r
 \r
 //\r
 // Function to get HID descriptor\r
 //\r
+\r
+/**\r
+  Get Hid Descriptor\r
+\r
+  @param  UsbIo             EFI_USB_IO_PROTOCOL\r
+  @param  InterfaceNum      Hid interface number\r
+  @param  HidDescriptor     Caller allocated buffer to store Usb hid descriptor if\r
+                            successfully returned.\r
+\r
+  @return EFI_SUCCESS\r
+  @return EFI_DEVICE_ERROR\r
+  @return EFI_TIMEOUT\r
+\r
+**/\r
 EFI_STATUS\r
 UsbGetHidDescriptor (\r
   IN  EFI_USB_IO_PROTOCOL        *UsbIo,\r
   IN  UINT8                      InterfaceNum,\r
   OUT EFI_USB_HID_DESCRIPTOR     *HidDescriptor\r
   )\r
-/*++\r
-\r
-  Routine Description:\r
-    Get Hid Descriptor\r
-\r
-  Arguments:\r
-    UsbIo             -   EFI_USB_IO_PROTOCOL\r
-    InterfaceNum      -   Hid interface number\r
-    HidDescriptor     -   Caller allocated buffer to store Usb hid descriptor\r
-                          if successfully returned.\r
-\r
-  Returns:\r
-    EFI_SUCCESS\r
-    EFI_DEVICE_ERROR\r
-    EFI_TIMEOUT\r
-\r
---*/\r
 {\r
   UINT32                  Status;\r
   EFI_STATUS              Result;\r
@@ -76,6 +74,21 @@ UsbGetHidDescriptor (
 //\r
 // Function to get Report Class descriptor\r
 //\r
+\r
+/**\r
+  get Report Class descriptor\r
+\r
+  @param  UsbIo             EFI_USB_IO_PROTOCOL.\r
+  @param  InterfaceNum      Report interface number.\r
+  @param  DescriptorSize    Length of DescriptorBuffer.\r
+  @param  DescriptorBuffer  Caller allocated buffer to store Usb report descriptor\r
+                            if successfully returned.\r
+\r
+  @return EFI_SUCCESS\r
+  @return EFI_DEVICE_ERROR\r
+  @return EFI_TIMEOUT\r
+\r
+**/\r
 EFI_STATUS\r
 UsbGetReportDescriptor (\r
   IN  EFI_USB_IO_PROTOCOL     *UsbIo,\r
@@ -83,24 +96,6 @@ UsbGetReportDescriptor (
   IN  UINT16                  DescriptorSize,\r
   OUT UINT8                   *DescriptorBuffer\r
   )\r
-/*++\r
-\r
-  Routine Description:\r
-    get Report Class descriptor\r
-\r
-  Arguments:\r
-    UsbIo             -   EFI_USB_IO_PROTOCOL.\r
-    InterfaceNum      -   Report interface number.\r
-    DescriptorSize    -   Length of DescriptorBuffer.\r
-    DescriptorBuffer  -   Caller allocated buffer to store Usb report descriptor\r
-                          if successfully returned.\r
-\r
-  Returns:\r
-    EFI_SUCCESS\r
-    EFI_DEVICE_ERROR\r
-    EFI_TIMEOUT\r
-\r
---*/\r
 {\r
   UINT32                  Status;\r
   EFI_STATUS              Result;\r
@@ -131,28 +126,25 @@ UsbGetReportDescriptor (
 //\r
 // Following are HID class request\r
 //\r
+\r
+/**\r
+  Get Hid Protocol Request\r
+\r
+  @param  UsbIo             EFI_USB_IO_PROTOCOL\r
+  @param  Interface         Which interface the caller wants to get protocol\r
+  @param  Protocol          Protocol value returned.\r
+\r
+  @return EFI_SUCCESS\r
+  @return EFI_DEVICE_ERROR\r
+  @return EFI_TIMEOUT\r
+\r
+**/\r
 EFI_STATUS\r
 UsbGetProtocolRequest (\r
   IN EFI_USB_IO_PROTOCOL     *UsbIo,\r
   IN UINT8                   Interface,\r
   IN UINT8                   *Protocol\r
   )\r
-/*++\r
-\r
-  Routine Description:\r
-    Get Hid Protocol Request\r
-\r
-  Arguments:\r
-    UsbIo             -   EFI_USB_IO_PROTOCOL\r
-    Interface         -   Which interface the caller wants to get protocol\r
-    Protocol          -   Protocol value returned.\r
-\r
-  Returns:\r
-    EFI_SUCCESS\r
-    EFI_DEVICE_ERROR\r
-    EFI_TIMEOUT\r
-\r
---*/\r
 {\r
   UINT32                  Status;\r
   EFI_STATUS              Result;\r
@@ -184,28 +176,25 @@ UsbGetProtocolRequest (
 }\r
 \r
 \r
+\r
+/**\r
+  Set Hid Protocol Request\r
+\r
+  @param  UsbIo             EFI_USB_IO_PROTOCOL\r
+  @param  Interface         Which interface the caller wants to set protocol\r
+  @param  Protocol          Protocol value the caller wants to set.\r
+\r
+  @return EFI_SUCCESS\r
+  @return EFI_DEVICE_ERROR\r
+  @return EFI_TIMEOUT\r
+\r
+**/\r
 EFI_STATUS\r
 UsbSetProtocolRequest (\r
   IN EFI_USB_IO_PROTOCOL     *UsbIo,\r
   IN UINT8                   Interface,\r
   IN UINT8                   Protocol\r
   )\r
-/*++\r
-\r
-  Routine Description:\r
-    Set Hid Protocol Request\r
-\r
-  Arguments:\r
-    UsbIo             -   EFI_USB_IO_PROTOCOL\r
-    Interface         -   Which interface the caller wants to set protocol\r
-    Protocol          -   Protocol value the caller wants to set.\r
-\r
-  Returns:\r
-    EFI_SUCCESS\r
-    EFI_DEVICE_ERROR\r
-    EFI_TIMEOUT\r
-\r
---*/\r
 {\r
   UINT32                  Status;\r
   EFI_STATUS              Result;\r
@@ -236,6 +225,20 @@ UsbSetProtocolRequest (
 }\r
 \r
 \r
+\r
+/**\r
+  Set Idel request.\r
+\r
+  @param  UsbIo             EFI_USB_IO_PROTOCOL\r
+  @param  Interface         Which interface the caller wants to set.\r
+  @param  ReportId          Which report the caller wants to set.\r
+  @param  Duration          Idle rate the caller wants to set.\r
+\r
+  @return EFI_SUCCESS\r
+  @return EFI_DEVICE_ERROR\r
+  @return EFI_TIMEOUT\r
+\r
+**/\r
 EFI_STATUS\r
 UsbSetIdleRequest (\r
   IN EFI_USB_IO_PROTOCOL     *UsbIo,\r
@@ -243,23 +246,6 @@ UsbSetIdleRequest (
   IN UINT8                   ReportId,\r
   IN UINT8                   Duration\r
   )\r
-/*++\r
-\r
-  Routine Description:\r
-    Set Idel request.\r
-\r
-  Arguments:\r
-    UsbIo             -   EFI_USB_IO_PROTOCOL\r
-    Interface         -   Which interface the caller wants to set.\r
-    ReportId          -   Which report the caller wants to set.\r
-    Duration          -   Idle rate the caller wants to set.\r
-\r
-  Returns:\r
-    EFI_SUCCESS\r
-    EFI_DEVICE_ERROR\r
-    EFI_TIMEOUT\r
-\r
---*/\r
 {\r
   UINT32                  Status;\r
   EFI_STATUS              Result;\r
@@ -289,6 +275,20 @@ UsbSetIdleRequest (
   return Result;\r
 }\r
 \r
+\r
+/**\r
+  Get Idel request.\r
+\r
+  @param  UsbIo             EFI_USB_IO_PROTOCOL\r
+  @param  Interface         Which interface the caller wants to get.\r
+  @param  ReportId          Which report the caller wants to get.\r
+  @param  Duration          Idle rate the caller wants to get.\r
+\r
+  @return EFI_SUCCESS\r
+  @return EFI_DEVICE_ERROR\r
+  @return EFI_TIMEOUT\r
+\r
+**/\r
 EFI_STATUS\r
 UsbGetIdleRequest (\r
   IN  EFI_USB_IO_PROTOCOL     *UsbIo,\r
@@ -296,23 +296,6 @@ UsbGetIdleRequest (
   IN  UINT8                   ReportId,\r
   OUT UINT8                   *Duration\r
   )\r
-/*++\r
-\r
-  Routine Description:\r
-    Get Idel request.\r
-\r
-  Arguments:\r
-    UsbIo             -   EFI_USB_IO_PROTOCOL\r
-    Interface         -   Which interface the caller wants to get.\r
-    ReportId          -   Which report the caller wants to get.\r
-    Duration          -   Idle rate the caller wants to get.\r
-\r
-  Returns:\r
-    EFI_SUCCESS\r
-    EFI_DEVICE_ERROR\r
-    EFI_TIMEOUT\r
-\r
---*/\r
 {\r
   UINT32                  Status;\r
   EFI_STATUS              Result;\r
@@ -344,6 +327,22 @@ UsbGetIdleRequest (
 }\r
 \r
 \r
+\r
+/**\r
+  Hid Set Report request.\r
+\r
+  @param  UsbIo             EFI_USB_IO_PROTOCOL\r
+  @param  Interface         Which interface the caller wants to set.\r
+  @param  ReportId          Which report the caller wants to set.\r
+  @param  ReportType        Type of report.\r
+  @param  ReportLen         Length of report descriptor.\r
+  @param  Report            Report Descriptor buffer.\r
+\r
+  @return EFI_SUCCESS\r
+  @return EFI_DEVICE_ERROR\r
+  @return EFI_TIMEOUT\r
+\r
+**/\r
 EFI_STATUS\r
 UsbSetReportRequest (\r
   IN EFI_USB_IO_PROTOCOL     *UsbIo,\r
@@ -353,25 +352,6 @@ UsbSetReportRequest (
   IN UINT16                  ReportLen,\r
   IN UINT8                   *Report\r
   )\r
-/*++\r
-\r
-  Routine Description:\r
-    Hid Set Report request.\r
-\r
-  Arguments:\r
-    UsbIo             -   EFI_USB_IO_PROTOCOL\r
-    Interface         -   Which interface the caller wants to set.\r
-    ReportId          -   Which report the caller wants to set.\r
-    ReportType        -   Type of report.\r
-    ReportLen         -   Length of report descriptor.\r
-    Report            -   Report Descriptor buffer.\r
-\r
-  Returns:\r
-    EFI_SUCCESS\r
-    EFI_DEVICE_ERROR\r
-    EFI_TIMEOUT\r
-\r
---*/\r
 {\r
   UINT32                  Status;\r
   EFI_STATUS              Result;\r
@@ -402,6 +382,22 @@ UsbSetReportRequest (
   return Result;\r
 }\r
 \r
+\r
+/**\r
+  Hid Set Report request.\r
+\r
+  @param  UsbIo             EFI_USB_IO_PROTOCOL\r
+  @param  Interface         Which interface the caller wants to set.\r
+  @param  ReportId          Which report the caller wants to set.\r
+  @param  ReportType        Type of report.\r
+  @param  ReportLen         Length of report descriptor.\r
+  @param  Report            Caller allocated buffer to store Report Descriptor.\r
+\r
+  @return EFI_SUCCESS\r
+  @return EFI_DEVICE_ERROR\r
+  @return EFI_TIMEOUT\r
+\r
+**/\r
 EFI_STATUS\r
 UsbGetReportRequest (\r
   IN EFI_USB_IO_PROTOCOL     *UsbIo,\r
@@ -411,25 +407,6 @@ UsbGetReportRequest (
   IN UINT16                  ReportLen,\r
   IN UINT8                   *Report\r
   )\r
-/*++\r
-\r
-  Routine Description:\r
-    Hid Set Report request.\r
-\r
-  Arguments:\r
-    UsbIo             -   EFI_USB_IO_PROTOCOL\r
-    Interface         -   Which interface the caller wants to set.\r
-    ReportId          -   Which report the caller wants to set.\r
-    ReportType        -   Type of report.\r
-    ReportLen         -   Length of report descriptor.\r
-    Report            -   Caller allocated buffer to store Report Descriptor.\r
-\r
-  Returns:\r
-    EFI_SUCCESS\r
-    EFI_DEVICE_ERROR\r
-    EFI_TIMEOUT\r
-\r
---*/\r
 {\r
   UINT32                  Status;\r
   EFI_STATUS              Result;\r