]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Add in Ps2keyboard.inf and Ps2Mouse.inf to IntelFrameworkModuelPkg
authorqwang12 <qwang12@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 6 Jul 2007 09:09:42 +0000 (09:09 +0000)
committerqwang12 <qwang12@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 6 Jul 2007 09:09:42 +0000 (09:09 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@3112 6f19259b-4bc3-4df7-8a09-765794883524

18 files changed:
IntelFrameworkModulePkg/Bus/Isa/Ps2KeyboardDxe/CommonHeader.h [new file with mode: 0644]
IntelFrameworkModulePkg/Bus/Isa/Ps2KeyboardDxe/ComponentName.c [new file with mode: 0644]
IntelFrameworkModulePkg/Bus/Isa/Ps2KeyboardDxe/EntryPoint.c [new file with mode: 0644]
IntelFrameworkModulePkg/Bus/Isa/Ps2KeyboardDxe/Ps2KbdCtrller.c [new file with mode: 0644]
IntelFrameworkModulePkg/Bus/Isa/Ps2KeyboardDxe/Ps2KbdTextIn.c [new file with mode: 0644]
IntelFrameworkModulePkg/Bus/Isa/Ps2KeyboardDxe/Ps2Keyboard.c [new file with mode: 0644]
IntelFrameworkModulePkg/Bus/Isa/Ps2KeyboardDxe/Ps2Keyboard.h [new file with mode: 0644]
IntelFrameworkModulePkg/Bus/Isa/Ps2KeyboardDxe/Ps2keyboard.inf [new file with mode: 0644]
IntelFrameworkModulePkg/Bus/Isa/Ps2KeyboardDxe/Ps2keyboard.msa [new file with mode: 0644]
IntelFrameworkModulePkg/Bus/Isa/Ps2MouseDxe/CommPs2.c [new file with mode: 0644]
IntelFrameworkModulePkg/Bus/Isa/Ps2MouseDxe/CommPs2.h [new file with mode: 0644]
IntelFrameworkModulePkg/Bus/Isa/Ps2MouseDxe/CommonHeader.h [new file with mode: 0644]
IntelFrameworkModulePkg/Bus/Isa/Ps2MouseDxe/ComponentName.c [new file with mode: 0644]
IntelFrameworkModulePkg/Bus/Isa/Ps2MouseDxe/EntryPoint.c [new file with mode: 0644]
IntelFrameworkModulePkg/Bus/Isa/Ps2MouseDxe/Ps2Mouse.c [new file with mode: 0644]
IntelFrameworkModulePkg/Bus/Isa/Ps2MouseDxe/Ps2Mouse.h [new file with mode: 0644]
IntelFrameworkModulePkg/Bus/Isa/Ps2MouseDxe/Ps2Mouse.inf [new file with mode: 0644]
IntelFrameworkModulePkg/Bus/Isa/Ps2MouseDxe/Ps2Mouse.msa [new file with mode: 0644]

diff --git a/IntelFrameworkModulePkg/Bus/Isa/Ps2KeyboardDxe/CommonHeader.h b/IntelFrameworkModulePkg/Bus/Isa/Ps2KeyboardDxe/CommonHeader.h
new file mode 100644 (file)
index 0000000..fd84c93
--- /dev/null
@@ -0,0 +1,51 @@
+/**@file\r
+  Common header file shared by all source files.\r
+\r
+  This file includes package header files, library classes and protocol, PPI & GUID definitions.\r
+\r
+  Copyright (c) 2006 - 2007, Intel Corporation.\r
+  All rights reserved.\r
+   This software and associated documentation (if any) is furnished\r
+   under a license and may only be used or copied in accordance\r
+   with the terms of the license. Except as permitted by such\r
+   license, no part of this software or documentation may be\r
+   reproduced, stored in a retrieval system, or transmitted in any\r
+   form or by any means without the express written consent of\r
+   Intel Corporation.\r
+**/\r
+\r
+#ifndef __COMMON_HEADER_H_\r
+#define __COMMON_HEADER_H_\r
+\r
+\r
+//\r
+// The package level header files this module uses\r
+//\r
+#include <PiDxe.h>\r
+#include <Framework/StatusCode.h>\r
+\r
+//\r
+// The protocols, PPI and GUID defintions for this module\r
+//\r
+#include <Protocol/SimpleTextIn.h>\r
+#include <Protocol/IsaIo.h>\r
+#include <Protocol/DevicePath.h>\r
+#include <Protocol/Ps2Policy.h>\r
+\r
+//\r
+// The Library classes this module consumes\r
+//\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/ReportStatusCodeLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/UefiRuntimeServicesTableLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+//\r
+// Driver Binding Externs\r
+//\r
+extern EFI_DRIVER_BINDING_PROTOCOL gKeyboardControllerDriver;\r
+extern EFI_COMPONENT_NAME_PROTOCOL gPs2KeyboardComponentName;\r
+\r
+#endif\r
diff --git a/IntelFrameworkModulePkg/Bus/Isa/Ps2KeyboardDxe/ComponentName.c b/IntelFrameworkModulePkg/Bus/Isa/Ps2KeyboardDxe/ComponentName.c
new file mode 100644 (file)
index 0000000..75598b0
--- /dev/null
@@ -0,0 +1,230 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved. <BR>\r
+This software and associated documentation (if any) is furnished\r
+under a license and may only be used or copied in accordance\r
+with the terms of the license. Except as permitted by such\r
+license, no part of this software or documentation may be\r
+reproduced, stored in a retrieval system, or transmitted in any\r
+form or by any means without the express written consent of\r
+Intel Corporation.\r
+\r
+\r
+Module Name:\r
+\r
+  ComponentName.c\r
+\r
+Abstract:\r
+\r
+--*/\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+#include "Ps2Keyboard.h"\r
+\r
+//\r
+// EFI Component Name Functions\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+Ps2KeyboardComponentNameGetDriverName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+Ps2KeyboardComponentNameGetControllerName (\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     gPs2KeyboardComponentName = {\r
+  Ps2KeyboardComponentNameGetDriverName,\r
+  Ps2KeyboardComponentNameGetControllerName,\r
+  "eng"\r
+};\r
+\r
+static EFI_UNICODE_STRING_TABLE mPs2KeyboardDriverNameTable[] = {\r
+  {\r
+    "eng",\r
+    L"PS/2 Keyboard Driver"\r
+  },\r
+  {\r
+    NULL,\r
+    NULL\r
+  }\r
+};\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+Ps2KeyboardComponentNameGetDriverName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+\r
+    Retrieves a Unicode string that is the user readable name of the EFI Driver.\r
+\r
+  Arguments:\r
+\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
+\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
+           gPs2KeyboardComponentName.SupportedLanguages,\r
+           mPs2KeyboardDriverNameTable,\r
+           DriverName\r
+           );\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+Ps2KeyboardComponentNameGetControllerName (\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
+\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
+\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
+\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
+  EFI_SIMPLE_TEXT_INPUT_PROTOCOL              *ConIn;\r
+  KEYBOARD_CONSOLE_IN_DEV                     *ConsoleIn;\r
+  EFI_ISA_IO_PROTOCOL                         *IsaIoProtocol;\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
+  // Check Controller's handle\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiIsaIoProtocolGuid,\r
+                  (VOID **) &IsaIoProtocol,\r
+                  gKeyboardControllerDriver.DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (!EFI_ERROR (Status)) {\r
+    gBS->CloseProtocol (\r
+           ControllerHandle,\r
+           &gEfiIsaIoProtocolGuid,\r
+           gKeyboardControllerDriver.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 **) &ConIn,\r
+                  gKeyboardControllerDriver.DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  ConsoleIn = KEYBOARD_CONSOLE_IN_DEV_FROM_THIS (ConIn);\r
+\r
+  return LookupUnicodeString (\r
+           Language,\r
+           gPs2KeyboardComponentName.SupportedLanguages,\r
+           ConsoleIn->ControllerNameTable,\r
+           ControllerName\r
+           );\r
+}\r
diff --git a/IntelFrameworkModulePkg/Bus/Isa/Ps2KeyboardDxe/EntryPoint.c b/IntelFrameworkModulePkg/Bus/Isa/Ps2KeyboardDxe/EntryPoint.c
new file mode 100644 (file)
index 0000000..c1d3e61
--- /dev/null
@@ -0,0 +1,58 @@
+/**@file\r
+  Entry Point Source file.\r
+\r
+  This file contains the user entry point \r
+\r
+  Copyright (c) 2006 - 2007, Intel Corporation.\r
+  All rights reserved.\r
+   This software and associated documentation (if any) is furnished\r
+   under a license and may only be used or copied in accordance\r
+   with the terms of the license. Except as permitted by such\r
+   license, no part of this software or documentation may be\r
+   reproduced, stored in a retrieval system, or transmitted in any\r
+   form or by any means without the express written consent of\r
+   Intel Corporation.\r
+**/\r
+\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+/**\r
+  The user Entry Point for module Ps2Keyboard. The user code starts with this function.\r
+\r
+  @param[in] ImageHandle    The firmware allocated handle for the EFI image.  \r
+  @param[in] SystemTable    A pointer to the EFI System Table.\r
+  \r
+  @retval EFI_SUCCESS       The entry point is executed successfully.\r
+  @retval other             Some error occurs when executing this entry point.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InitializePs2Keyboard(\r
+  IN EFI_HANDLE           ImageHandle,\r
+  IN EFI_SYSTEM_TABLE     *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+\r
+  //\r
+  // Install driver model protocol(s).\r
+  //\r
+  Status = EfiLibInstallAllDriverProtocols (\r
+             ImageHandle,\r
+             SystemTable,\r
+             &gKeyboardControllerDriver,\r
+             ImageHandle,\r
+             &gPs2KeyboardComponentName,\r
+             NULL,\r
+             NULL\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+\r
+  return Status;\r
+}\r
diff --git a/IntelFrameworkModulePkg/Bus/Isa/Ps2KeyboardDxe/Ps2KbdCtrller.c b/IntelFrameworkModulePkg/Bus/Isa/Ps2KeyboardDxe/Ps2KbdCtrller.c
new file mode 100644 (file)
index 0000000..5980556
--- /dev/null
@@ -0,0 +1,2076 @@
+/**@file\r
+  PS/2 Keyboard driver\r
+  Routines that access 8042 keyboard controller\r
+\r
+Copyright (c) 2006 - 2007 Intel Corporation. All rights reserved. <BR>\r
+This software and associated documentation (if any) is furnished\r
+under a license and may only be used or copied in accordance\r
+with the terms of the license. Except as permitted by such\r
+license, no part of this software or documentation may be\r
+reproduced, stored in a retrieval system, or transmitted in any\r
+form or by any means without the express written consent of\r
+Intel Corporation.\r
+\r
+**/\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+#include "Ps2Keyboard.h"\r
+\r
+//\r
+// Function declarations\r
+//\r
+STATIC\r
+UINT8\r
+KeyReadDataRegister (\r
+  IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn\r
+  );\r
+\r
+STATIC\r
+VOID\r
+KeyWriteDataRegister (\r
+  IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn,\r
+  IN UINT8                   Data\r
+  );\r
+\r
+STATIC\r
+VOID\r
+KeyWriteCommandRegister (\r
+  IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn,\r
+  IN UINT8                   Data\r
+  );\r
+\r
+STATIC\r
+VOID\r
+KeyboardError (\r
+  IN KEYBOARD_CONSOLE_IN_DEV*ConsoleIn,\r
+  IN CHAR16                 *ErrMsg // should be a unicode string\r
+  );\r
+\r
+STATIC\r
+EFI_STATUS\r
+GetScancodeBufHead (\r
+  KEYBOARD_CONSOLE_IN_DEV  *ConsoleIn,\r
+  IN UINT32                Count,\r
+  OUT UINT8                *Buf\r
+  );\r
+\r
+STATIC\r
+EFI_STATUS\r
+PopScancodeBufHead (\r
+  KEYBOARD_CONSOLE_IN_DEV  *ConsoleIn,\r
+  IN UINT32                Count,\r
+  OUT UINT8                *Buf\r
+  );\r
+\r
+STATIC\r
+EFI_STATUS\r
+KeyboardWrite (\r
+  IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn,\r
+  IN UINT8                   Data\r
+  );\r
+\r
+STATIC\r
+EFI_STATUS\r
+KeyboardCommand (\r
+  IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn,\r
+  IN UINT8                   Data\r
+  );\r
+\r
+STATIC\r
+EFI_STATUS\r
+KeyboardWaitForValue (\r
+  IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn,\r
+  IN UINT8                   Value\r
+  );\r
+\r
+STATIC\r
+EFI_STATUS\r
+UpdateStatusLights (\r
+  IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn\r
+  );\r
+\r
+//\r
+// Global variables\r
+//\r
+\r
+STATIC struct {\r
+  UINT8  ScanCode;\r
+  UINT16  EfiScanCode;\r
+  CHAR16  UnicodeChar;\r
+  CHAR16  ShiftUnicodeChar;\r
+}\r
+ConvertKeyboardScanCodeToEfiKey[] = {\r
+\r
+  {\r
+    0x01,  //   Escape\r
+    SCAN_ESC,\r
+    0x00,\r
+    0x00\r
+  },\r
+  {\r
+    0x02,\r
+    SCAN_NULL,\r
+    '1',\r
+    '!'\r
+  },\r
+  {\r
+    0x03,\r
+    SCAN_NULL,\r
+    '2',\r
+    '@'\r
+  },\r
+  {\r
+    0x04,\r
+    SCAN_NULL,\r
+    '3',\r
+    '#'\r
+  },\r
+  {\r
+    0x05,\r
+    SCAN_NULL,\r
+    '4',\r
+    '$'\r
+  },\r
+  {\r
+    0x06,\r
+    SCAN_NULL,\r
+    '5',\r
+    '%'\r
+  },\r
+  {\r
+    0x07,\r
+    SCAN_NULL,\r
+    '6',\r
+    '^'\r
+  },\r
+  {\r
+    0x08,\r
+    SCAN_NULL,\r
+    '7',\r
+    '&'\r
+  },\r
+  {\r
+    0x09,\r
+    SCAN_NULL,\r
+    '8',\r
+    '*'\r
+  },\r
+  {\r
+    0x0A,\r
+    SCAN_NULL,\r
+    '9',\r
+    '('\r
+  },\r
+  {\r
+    0x0B,\r
+    SCAN_NULL,\r
+    '0',\r
+    ')'\r
+  },\r
+  {\r
+    0x0C,\r
+    SCAN_NULL,\r
+    '-',\r
+    '_'\r
+  },\r
+  {\r
+    0x0D,\r
+    SCAN_NULL,\r
+    '=',\r
+    '+'\r
+  },\r
+  {\r
+    0x0E, //  BackSpace\r
+    SCAN_NULL,\r
+    0x08,\r
+    0x08\r
+  },\r
+  {\r
+    0x0F, //  Tab\r
+    SCAN_NULL,\r
+    0x09,\r
+    0x09\r
+  },\r
+  {\r
+    0x10,\r
+    SCAN_NULL,\r
+    'q',\r
+    'Q'\r
+  },\r
+  {\r
+    0x11,\r
+    SCAN_NULL,\r
+    'w',\r
+    'W'\r
+  },\r
+  {\r
+    0x12,\r
+    SCAN_NULL,\r
+    'e',\r
+    'E'\r
+  },\r
+  {\r
+    0x13,\r
+    SCAN_NULL,\r
+    'r',\r
+    'R'\r
+  },\r
+  {\r
+    0x14,\r
+    SCAN_NULL,\r
+    't',\r
+    'T'\r
+  },\r
+  {\r
+    0x15,\r
+    SCAN_NULL,\r
+    'y',\r
+    'Y'\r
+  },\r
+  {\r
+    0x16,\r
+    SCAN_NULL,\r
+    'u',\r
+    'U'\r
+  },\r
+  {\r
+    0x17,\r
+    SCAN_NULL,\r
+    'i',\r
+    'I'\r
+  },\r
+  {\r
+    0x18,\r
+    SCAN_NULL,\r
+    'o',\r
+    'O'\r
+  },\r
+  {\r
+    0x19,\r
+    SCAN_NULL,\r
+    'p',\r
+    'P'\r
+  },\r
+  {\r
+    0x1a,\r
+    SCAN_NULL,\r
+    '[',\r
+    '{'\r
+  },\r
+  {\r
+    0x1b,\r
+    SCAN_NULL,\r
+    ']',\r
+    '}'\r
+  },\r
+  {\r
+    0x1c, //   Enter\r
+    SCAN_NULL,\r
+    0x0d,\r
+    0x0d\r
+  },\r
+  {\r
+    0x1d,\r
+    SCAN_NULL,\r
+    0x00,\r
+    0x00\r
+  },\r
+  {\r
+    0x1e,\r
+    SCAN_NULL,\r
+    'a',\r
+    'A'\r
+  },\r
+  {\r
+    0x1f,\r
+    SCAN_NULL,\r
+    's',\r
+    'S'\r
+  },\r
+  {\r
+    0x20,\r
+    SCAN_NULL,\r
+    'd',\r
+    'D'\r
+  },\r
+  {\r
+    0x21,\r
+    SCAN_NULL,\r
+    'f',\r
+    'F'\r
+  },\r
+  {\r
+    0x22,\r
+    SCAN_NULL,\r
+    'g',\r
+    'G'\r
+  },\r
+  {\r
+    0x23,\r
+    SCAN_NULL,\r
+    'h',\r
+    'H'\r
+  },\r
+  {\r
+    0x24,\r
+    SCAN_NULL,\r
+    'j',\r
+    'J'\r
+  },\r
+  {\r
+    0x25,\r
+    SCAN_NULL,\r
+    'k',\r
+    'K'\r
+  },\r
+  {\r
+    0x26,\r
+    SCAN_NULL,\r
+    'l',\r
+    'L'\r
+  },\r
+  {\r
+    0x27,\r
+    SCAN_NULL,\r
+    ';',\r
+    ':'\r
+  },\r
+  {\r
+    0x28,\r
+    SCAN_NULL,\r
+    '\'',\r
+    '"'\r
+  },\r
+  {\r
+    0x29,\r
+    SCAN_NULL,\r
+    '`',\r
+    '~'\r
+  },\r
+  {\r
+    0x2a, //   Left Shift\r
+    SCAN_NULL,\r
+    0x00,\r
+    0x00\r
+  },\r
+  {\r
+    0x2b,\r
+    SCAN_NULL,\r
+    '\\',\r
+    '|'\r
+  },\r
+  {\r
+    0x2c,\r
+    SCAN_NULL,\r
+    'z',\r
+    'Z'\r
+  },\r
+  {\r
+    0x2d,\r
+    SCAN_NULL,\r
+    'x',\r
+    'X'\r
+  },\r
+  {\r
+    0x2e,\r
+    SCAN_NULL,\r
+    'c',\r
+    'C'\r
+  },\r
+  {\r
+    0x2f,\r
+    SCAN_NULL,\r
+    'v',\r
+    'V'\r
+  },\r
+  {\r
+    0x30,\r
+    SCAN_NULL,\r
+    'b',\r
+    'B'\r
+  },\r
+  {\r
+    0x31,\r
+    SCAN_NULL,\r
+    'n',\r
+    'N'\r
+  },\r
+  {\r
+    0x32,\r
+    SCAN_NULL,\r
+    'm',\r
+    'M'\r
+  },\r
+  {\r
+    0x33,\r
+    SCAN_NULL,\r
+    ',',\r
+    '<'\r
+  },\r
+  {\r
+    0x34,\r
+    SCAN_NULL,\r
+    '.',\r
+    '>'\r
+  },\r
+  {\r
+    0x35,\r
+    SCAN_NULL,\r
+    '/',\r
+    '?'\r
+  },\r
+  {\r
+    0x36, //Right Shift\r
+    SCAN_NULL,\r
+    0x00,\r
+    0x00\r
+  },\r
+  {\r
+    0x37, // Numeric Keypad *\r
+    SCAN_NULL,\r
+    '*',\r
+    '*'\r
+  },\r
+  {\r
+    0x38,  //Left Alt/Extended Right Alt\r
+    SCAN_NULL,\r
+    0x00,\r
+    0x00\r
+  },\r
+  {\r
+    0x39,\r
+    SCAN_NULL,\r
+    ' ',\r
+    ' '\r
+  },\r
+  {\r
+    0x3A, //CapsLock\r
+    SCAN_NULL,\r
+    0x00,\r
+    0x00\r
+  },\r
+  {\r
+    0x3B,\r
+    SCAN_F1,\r
+    0x00,\r
+    0x00\r
+  },\r
+  {\r
+    0x3C,\r
+    SCAN_F2,\r
+    0x00,\r
+    0x00\r
+  },\r
+  {\r
+    0x3D,\r
+    SCAN_F3,\r
+    0x00,\r
+    0x00\r
+  },\r
+  {\r
+    0x3E,\r
+    SCAN_F4,\r
+    0x00,\r
+    0x00\r
+  },\r
+  {\r
+    0x3F,\r
+    SCAN_F5,\r
+    0x00,\r
+    0x00\r
+  },\r
+  {\r
+    0x40,\r
+    SCAN_F6,\r
+    0x00,\r
+    0x00\r
+  },\r
+  {\r
+    0x41,\r
+    SCAN_F7,\r
+    0x00,\r
+    0x00\r
+  },\r
+  {\r
+    0x42,\r
+    SCAN_F8,\r
+    0x00,\r
+    0x00\r
+  },\r
+  {\r
+    0x43,\r
+    SCAN_F9,\r
+    0x00,\r
+    0x00\r
+  },\r
+  {\r
+    0x44,\r
+    SCAN_F10,\r
+    0x00,\r
+    0x00\r
+  },\r
+  {\r
+    0x45, // NumLock\r
+    SCAN_NULL,\r
+    0x00,\r
+    0x00\r
+  },\r
+  {\r
+    0x46, //  ScrollLock\r
+    SCAN_NULL,\r
+    0x00,\r
+    0x00\r
+  },\r
+  {\r
+    0x47,\r
+    SCAN_HOME,\r
+    '7',\r
+    '7'\r
+  },\r
+  {\r
+    0x48,\r
+    SCAN_UP,\r
+    '8',\r
+    '8'\r
+  },\r
+  {\r
+    0x49,\r
+    SCAN_PAGE_UP,\r
+    '9',\r
+    '9'\r
+  },\r
+  {\r
+    0x4a,\r
+    SCAN_NULL,\r
+    '-',\r
+    '-'\r
+  },\r
+  {\r
+    0x4b,\r
+    SCAN_LEFT,\r
+    '4',\r
+    '4'\r
+  },\r
+  {\r
+    0x4c, //  Numeric Keypad 5\r
+    SCAN_NULL,\r
+    '5',\r
+    '5'\r
+  },\r
+  {\r
+    0x4d,\r
+    SCAN_RIGHT,\r
+    '6',\r
+    '6'\r
+  },\r
+  {\r
+    0x4e,\r
+    SCAN_NULL,\r
+    '+',\r
+    '+'\r
+  },\r
+  {\r
+    0x4f,\r
+    SCAN_END,\r
+    '1',\r
+    '1'\r
+  },\r
+  {\r
+    0x50,\r
+    SCAN_DOWN,\r
+    '2',\r
+    '2'\r
+  },\r
+  {\r
+    0x51,\r
+    SCAN_PAGE_DOWN,\r
+    '3',\r
+    '3'\r
+  },\r
+  {\r
+    0x52,\r
+    SCAN_INSERT,\r
+    '0',\r
+    '0'\r
+  },\r
+  {\r
+    0x53,\r
+    SCAN_DELETE,\r
+    '.',\r
+    '.'\r
+  },\r
+  {\r
+    0x57,\r
+    SCAN_F11,\r
+    0x00,\r
+    0x00\r
+  },\r
+  {\r
+    0x58,\r
+    SCAN_F12,\r
+    0x00,\r
+    0x00\r
+  },\r
+  {\r
+    TABLE_END,\r
+    TABLE_END,\r
+    SCAN_NULL,\r
+    SCAN_NULL\r
+  },\r
+};\r
+\r
+\r
+//\r
+// The WaitForValue time out\r
+//\r
+STATIC UINTN  mWaitForValueTimeOut = KEYBOARD_WAITFORVALUE_TIMEOUT;\r
+\r
+STATIC\r
+UINT8\r
+KeyReadDataRegister (\r
+  IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  ConsoleIn - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+  GC_TODO: add return values\r
+\r
+--*/\r
+{\r
+  EFI_ISA_IO_PROTOCOL                 *IsaIo;\r
+  UINT8                               Data;\r
+\r
+  //\r
+  // Use IsaIo protocol to perform IO operations\r
+  //\r
+  IsaIo = ConsoleIn->IsaIo;\r
+\r
+  IsaIo->Io.Read (\r
+              IsaIo,\r
+              EfiIsaIoWidthUint8,\r
+              ConsoleIn->DataRegisterAddress,\r
+              1,\r
+              &Data\r
+              );\r
+\r
+  return Data;\r
+}\r
+\r
+STATIC\r
+VOID\r
+KeyWriteDataRegister (\r
+  IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn,\r
+  IN UINT8                   Data\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  ConsoleIn - GC_TODO: add argument description\r
+  Data      - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+  GC_TODO: add return values\r
+\r
+--*/\r
+{\r
+  EFI_ISA_IO_PROTOCOL                 *IsaIo;\r
+\r
+  //\r
+  // Use IsaIo protocol to perform IO operations\r
+  //\r
+  IsaIo = ConsoleIn->IsaIo;\r
+\r
+  IsaIo->Io.Write (\r
+              IsaIo,\r
+              EfiIsaIoWidthUint8,\r
+              ConsoleIn->DataRegisterAddress,\r
+              1,\r
+              &Data\r
+              );\r
+\r
+  //\r
+  // outp(ConsoleIn->DataRegisterAddress, Data);\r
+  //\r
+}\r
+\r
+UINT8\r
+KeyReadStatusRegister (\r
+  IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  ConsoleIn - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+  GC_TODO: add return values\r
+\r
+--*/\r
+{\r
+  EFI_ISA_IO_PROTOCOL                 *IsaIo;\r
+  UINT8                               Data;\r
+\r
+  //\r
+  // Use IsaIo protocol to perform IO operations\r
+  //\r
+  IsaIo = ConsoleIn->IsaIo;\r
+\r
+  IsaIo->Io.Read (\r
+              IsaIo,\r
+              EfiIsaIoWidthUint8,\r
+              ConsoleIn->StatusRegisterAddress,\r
+              1,\r
+              &Data\r
+              );\r
+\r
+  return Data;\r
+\r
+}\r
+\r
+STATIC\r
+VOID\r
+KeyWriteCommandRegister (\r
+  IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn,\r
+  IN UINT8                   Data\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  ConsoleIn - GC_TODO: add argument description\r
+  Data      - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+  GC_TODO: add return values\r
+\r
+--*/\r
+{\r
+  EFI_ISA_IO_PROTOCOL                 *IsaIo;\r
+\r
+  //\r
+  // Use IsaIo protocol to perform IO operations\r
+  //\r
+  IsaIo = ConsoleIn->IsaIo;\r
+\r
+  IsaIo->Io.Write (\r
+              IsaIo,\r
+              EfiIsaIoWidthUint8,\r
+              ConsoleIn->CommandRegisterAddress,\r
+              1,\r
+              &Data\r
+              );\r
+\r
+}\r
+\r
+STATIC\r
+VOID\r
+KeyboardError (\r
+  IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn,\r
+  IN CHAR16                  *ErrMsg\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Display error message\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+--*/\r
+// GC_TODO:    ConsoleIn - add argument and description to function comment\r
+// GC_TODO:    ErrMsg - add argument and description to function comment\r
+{\r
+  ConsoleIn->KeyboardErr = TRUE;\r
+\r
+  //\r
+  // gST -> ConOut -> OutputString (gST -> ConOut, L"Keyboard Driver: ");\r
+  // gST -> ConOut -> OutputString (gST -> ConOut, ErrMsg);\r
+  //\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+KeyboardTimerHandler (\r
+  IN EFI_EVENT    Event,\r
+  IN VOID         *Context\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Timer event handler: read a series of scancodes from 8042\r
+  and put them into memory scancode buffer.\r
+  it read as much scancodes to either fill\r
+  the memory buffer or empty the keyboard buffer.\r
+  It is registered as running under TPL_NOTIFY\r
+\r
+Arguments:\r
+\r
+  Event - The timer event\r
+  Context - A KEYBOARD_CONSOLE_IN_DEV pointer\r
+\r
+Returns:\r
+\r
+--*/\r
+{\r
+  UINT8                   Data;\r
+  EFI_TPL                 OldTpl;\r
+  KEYBOARD_CONSOLE_IN_DEV *ConsoleIn;\r
+\r
+  ConsoleIn = Context;\r
+\r
+  //\r
+  // Enter critical section\r
+  //\r
+  OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
+\r
+  if (((KEYBOARD_CONSOLE_IN_DEV *) Context)->KeyboardErr) {\r
+    //\r
+    // Leave critical section and return\r
+    //\r
+    gBS->RestoreTPL (OldTpl);\r
+    return ;\r
+  }\r
+  //\r
+  // To let KB driver support Hot plug, here should skip the 'resend' command  for the case that\r
+  // KB is not connected to system. If KB is not connected to system, driver will find there's  something\r
+  // error in the following code and wait for the input buffer empty, this waiting time shoulb be  short enough since\r
+  // this is a NOTIFY TPL period function, or the system performance will degrade hardly when KB is not connected.\r
+  // Just skip the 'resend' process simply.\r
+  //\r
+\r
+  Data = 0;\r
+\r
+  //\r
+  // if there is no key present, just return\r
+  //\r
+  if ((KeyReadStatusRegister (Context) & 0x21) != 0x1) {\r
+    //\r
+    // Leave critical section and return\r
+    //\r
+    gBS->RestoreTPL (OldTpl);\r
+\r
+    return ;\r
+  }\r
+  //\r
+  // Read one byte of the scan code and store it into the memory buffer\r
+  //\r
+  if (ConsoleIn->ScancodeBufCount < KEYBOARD_BUFFER_MAX_COUNT) {\r
+\r
+    Data = KeyReadDataRegister (Context);\r
+    //\r
+    // put the scancode into the memory scancode buffer\r
+    //\r
+    ConsoleIn->ScancodeBufCount++;\r
+    ConsoleIn->ScancodeBufEndPos++;\r
+    if (ConsoleIn->ScancodeBufEndPos >= KEYBOARD_BUFFER_MAX_COUNT) {\r
+      ConsoleIn->ScancodeBufEndPos = 0;\r
+    }\r
+\r
+    ConsoleIn->ScancodeBuf[ConsoleIn->ScancodeBufEndPos] = Data;\r
+\r
+    //\r
+    // Handle Alt+Ctrl+Del Key combination\r
+    //\r
+    switch (Data) {\r
+    case SCANCODE_CTRL_MAKE:\r
+      ConsoleIn->Ctrled = TRUE;\r
+      break;\r
+\r
+    case SCANCODE_CTRL_BREAK:\r
+      ConsoleIn->Ctrled = FALSE;\r
+      break;\r
+\r
+    case SCANCODE_ALT_MAKE:\r
+      ConsoleIn->Alted = TRUE;\r
+      break;\r
+\r
+    case SCANCODE_ALT_BREAK:\r
+      ConsoleIn->Alted = FALSE;\r
+      break;\r
+    }\r
+    //\r
+    // if Alt+Ctrl+Del, Reboot the System\r
+    //\r
+    if (ConsoleIn->Ctrled && ConsoleIn->Alted && Data == 0x53) {\r
+      gRT->ResetSystem (EfiResetWarm, EFI_SUCCESS, 0, NULL);\r
+    }\r
+  }\r
+  //\r
+  // Leave critical section and return\r
+  //\r
+  gBS->RestoreTPL (OldTpl);\r
+\r
+  return ;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+GetScancodeBufHead (\r
+  KEYBOARD_CONSOLE_IN_DEV    *ConsoleIn,\r
+  IN UINT32                  Count,\r
+  OUT UINT8                  *Buf\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Read several bytes from the scancode buffer without removing them.\r
+  This function is called to see if there are enough bytes of scancode\r
+  representing a single key.\r
+\r
+Arguments:\r
+\r
+  Count - Number of bytes to be read\r
+  Buf - Store the results\r
+\r
+Returns:\r
+\r
+  EFI_STATUS\r
+\r
+--*/\r
+// GC_TODO:    ConsoleIn - add argument and description to function comment\r
+// GC_TODO:    EFI_NOT_READY - add return value to function comment\r
+// GC_TODO:    EFI_SUCCESS - add return value to function comment\r
+{\r
+  UINT32  Index;\r
+  UINT32  Pos;\r
+\r
+  Index = 0;\r
+  Pos   = 0;\r
+\r
+  //\r
+  // check the valid range of parameter 'Count'\r
+  //\r
+  if (Count <= 0 || ConsoleIn->ScancodeBufCount < Count) {\r
+    return EFI_NOT_READY;\r
+  }\r
+  //\r
+  // retrieve the values\r
+  //\r
+  for (Index = 0; Index < Count; Index++) {\r
+\r
+    if (Index == 0) {\r
+\r
+      Pos = ConsoleIn->ScancodeBufStartPos;\r
+    } else {\r
+\r
+      Pos = Pos + 1;\r
+      if (Pos >= KEYBOARD_BUFFER_MAX_COUNT) {\r
+        Pos = 0;\r
+      }\r
+    }\r
+\r
+    Buf[Index] = ConsoleIn->ScancodeBuf[Pos];\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+PopScancodeBufHead (\r
+  KEYBOARD_CONSOLE_IN_DEV   *ConsoleIn,\r
+  IN UINT32                 Count,\r
+  OUT UINT8                 *Buf\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Read & remove several bytes from the scancode buffer.\r
+  This function is usually called after GetScancodeBufHead()\r
+\r
+Arguments:\r
+\r
+  Count - Number of bytes to be read\r
+  Buf - Store the results\r
+\r
+Returns:\r
+\r
+  EFI_STATUS\r
+\r
+--*/\r
+// GC_TODO:    ConsoleIn - add argument and description to function comment\r
+// GC_TODO:    EFI_NOT_READY - add return value to function comment\r
+// GC_TODO:    EFI_SUCCESS - add return value to function comment\r
+{\r
+  UINT32  Index;\r
+\r
+  Index = 0;\r
+\r
+  //\r
+  // Check the valid range of parameter 'Count'\r
+  //\r
+  if (Count <= 0 || ConsoleIn->ScancodeBufCount < Count) {\r
+    return EFI_NOT_READY;\r
+  }\r
+  //\r
+  // Retrieve and remove the values\r
+  //\r
+  for (Index = 0; Index < Count; Index++) {\r
+\r
+    if (Index != 0) {\r
+\r
+      ConsoleIn->ScancodeBufStartPos++;\r
+      if (ConsoleIn->ScancodeBufStartPos >= KEYBOARD_BUFFER_MAX_COUNT) {\r
+        ConsoleIn->ScancodeBufStartPos = 0;\r
+      }\r
+    }\r
+\r
+    Buf[Index] = ConsoleIn->ScancodeBuf[ConsoleIn->ScancodeBufStartPos];\r
+    ConsoleIn->ScancodeBufCount--;\r
+  }\r
+\r
+  ConsoleIn->ScancodeBufStartPos++;\r
+  if (ConsoleIn->ScancodeBufStartPos >= KEYBOARD_BUFFER_MAX_COUNT) {\r
+    ConsoleIn->ScancodeBufStartPos = 0;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+KeyboardRead (\r
+  IN KEYBOARD_CONSOLE_IN_DEV  *ConsoleIn,\r
+  OUT UINT8                   *Data\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  ConsoleIn - GC_TODO: add argument description\r
+  Data      - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+  EFI_TIMEOUT - GC_TODO: Add description for return value\r
+  EFI_SUCCESS - GC_TODO: Add description for return value\r
+\r
+--*/\r
+{\r
+  UINT32  TimeOut;\r
+  UINT32  RegFilled;\r
+\r
+  TimeOut   = 0;\r
+  RegFilled = 0;\r
+\r
+  //\r
+  // wait till output buffer full then perform the read\r
+  //\r
+  for (TimeOut = 0; TimeOut < KEYBOARD_TIMEOUT; TimeOut += 30) {\r
+    if (KeyReadStatusRegister (ConsoleIn) & 0x01) {\r
+      RegFilled = 1;\r
+      *Data     = KeyReadDataRegister (ConsoleIn);\r
+      break;\r
+    }\r
+\r
+    gBS->Stall (30);\r
+  }\r
+\r
+  if (!RegFilled) {\r
+    return EFI_TIMEOUT;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+KeyboardWrite (\r
+  IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn,\r
+  IN UINT8                   Data\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  ConsoleIn - GC_TODO: add argument description\r
+  Data      - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+  EFI_TIMEOUT - GC_TODO: Add description for return value\r
+  EFI_SUCCESS - GC_TODO: Add description for return value\r
+\r
+--*/\r
+{\r
+  UINT32  TimeOut;\r
+  UINT32  RegEmptied;\r
+\r
+  TimeOut     = 0;\r
+  RegEmptied  = 0;\r
+\r
+  //\r
+  // wait for input buffer empty\r
+  //\r
+  for (TimeOut = 0; TimeOut < KEYBOARD_TIMEOUT; TimeOut += 30) {\r
+    if (!(KeyReadStatusRegister (ConsoleIn) & 0x02)) {\r
+      RegEmptied = 1;\r
+      break;\r
+    }\r
+\r
+    gBS->Stall (30);\r
+  }\r
+\r
+  if (!RegEmptied) {\r
+    return EFI_TIMEOUT;\r
+  }\r
+  //\r
+  // Write it\r
+  //\r
+  KeyWriteDataRegister (ConsoleIn, Data);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+KeyboardCommand (\r
+  IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn,\r
+  IN UINT8                   Data\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  ConsoleIn - GC_TODO: add argument description\r
+  Data      - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+  EFI_TIMEOUT - GC_TODO: Add description for return value\r
+  EFI_TIMEOUT - GC_TODO: Add description for return value\r
+  EFI_SUCCESS - GC_TODO: Add description for return value\r
+\r
+--*/\r
+{\r
+  UINT32  TimeOut;\r
+  UINT32  RegEmptied;\r
+\r
+  TimeOut     = 0;\r
+  RegEmptied  = 0;\r
+\r
+  //\r
+  // Wait For Input Buffer Empty\r
+  //\r
+  for (TimeOut = 0; TimeOut < KEYBOARD_TIMEOUT; TimeOut += 30) {\r
+    if (!(KeyReadStatusRegister (ConsoleIn) & 0x02)) {\r
+      RegEmptied = 1;\r
+      break;\r
+    }\r
+\r
+    gBS->Stall (30);\r
+  }\r
+\r
+  if (!RegEmptied) {\r
+    return EFI_TIMEOUT;\r
+  }\r
+  //\r
+  // issue the command\r
+  //\r
+  KeyWriteCommandRegister (ConsoleIn, Data);\r
+\r
+  //\r
+  // Wait For Input Buffer Empty again\r
+  //\r
+  RegEmptied = 0;\r
+  for (TimeOut = 0; TimeOut < KEYBOARD_TIMEOUT; TimeOut += 30) {\r
+    if (!(KeyReadStatusRegister (ConsoleIn) & 0x02)) {\r
+      RegEmptied = 1;\r
+      break;\r
+    }\r
+\r
+    gBS->Stall (30);\r
+  }\r
+\r
+  if (!RegEmptied) {\r
+    return EFI_TIMEOUT;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+KeyboardWaitForValue (\r
+  IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn,\r
+  IN UINT8                   Value\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  wait for a specific value to be presented on\r
+  8042 Data register by keyboard and then read it,\r
+  used in keyboard commands ack\r
+\r
+Arguments:\r
+\r
+  ConsoleIn - The KEYBOARD_CONSOLE_IN_DEV instance pointer\r
+  Value - The value to be waited for\r
+\r
+Returns:\r
+\r
+  EFI_STATUS\r
+\r
+--*/\r
+// GC_TODO:    EFI_SUCCESS - add return value to function comment\r
+// GC_TODO:    EFI_TIMEOUT - add return value to function comment\r
+{\r
+  UINT8   Data;\r
+  UINT32  TimeOut;\r
+  UINT32  SumTimeOut;\r
+  UINT32  GotIt;\r
+\r
+  GotIt       = 0;\r
+  TimeOut     = 0;\r
+  SumTimeOut  = 0;\r
+\r
+  //\r
+  // Make sure the initial value of 'Data' is different from 'Value'\r
+  //\r
+  Data = 0;\r
+  if (Data == Value) {\r
+    Data = 1;\r
+  }\r
+  //\r
+  // Read from 8042 (multiple times if needed)\r
+  // until the expected value appears\r
+  // use SumTimeOut to control the iteration\r
+  //\r
+  while (1) {\r
+    //\r
+    // Perform a read\r
+    //\r
+    for (TimeOut = 0; TimeOut < KEYBOARD_TIMEOUT; TimeOut += 30) {\r
+      if (KeyReadStatusRegister (ConsoleIn) & 0x01) {\r
+        Data = KeyReadDataRegister (ConsoleIn);\r
+        break;\r
+      }\r
+\r
+      gBS->Stall (30);\r
+    }\r
+\r
+    SumTimeOut += TimeOut;\r
+\r
+    if (Data == Value) {\r
+      GotIt = 1;\r
+      break;\r
+    }\r
+\r
+    if (SumTimeOut >= mWaitForValueTimeOut) {\r
+      break;\r
+    }\r
+  }\r
+  //\r
+  // Check results\r
+  //\r
+  if (GotIt) {\r
+    return EFI_SUCCESS;\r
+  } else {\r
+    return EFI_TIMEOUT;\r
+  }\r
+\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+UpdateStatusLights (\r
+  IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Show keyboard status lights according to\r
+  indicators in ConsoleIn.\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+--*/\r
+// GC_TODO:    ConsoleIn - add argument and description to function comment\r
+{\r
+  EFI_STATUS  Status;\r
+  UINT8       Command;\r
+\r
+  //\r
+  // Send keyboard command\r
+  //\r
+  Status = KeyboardWrite (ConsoleIn, 0xed);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  KeyboardWaitForValue (ConsoleIn, 0xfa);\r
+\r
+  //\r
+  // Light configuration\r
+  //\r
+  Command = 0;\r
+  if (ConsoleIn->CapsLock) {\r
+    Command |= 4;\r
+  }\r
+\r
+  if (ConsoleIn->NumLock) {\r
+    Command |= 2;\r
+  }\r
+\r
+  if (ConsoleIn->ScrollLock) {\r
+    Command |= 1;\r
+  }\r
+\r
+  Status = KeyboardWrite (ConsoleIn, Command);\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  KeyboardWaitForValue (ConsoleIn, 0xfa);\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+KeyGetchar (\r
+  IN OUT KEYBOARD_CONSOLE_IN_DEV *ConsoleIn\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Get scancode from scancode buffer\r
+  and translate into EFI-scancode and unicode defined by EFI spec\r
+  The function is always called in TPL_NOTIFY\r
+\r
+Arguments:\r
+\r
+  ConsoleIn - KEYBOARD_CONSOLE_IN_DEV instance pointer\r
+\r
+Returns:\r
+\r
+  EFI_NOT_READY - Input from console not ready yet.\r
+  EFI_SUCCESS   - Function executed successfully.\r
+\r
+--*/\r
+{\r
+  EFI_STATUS  Status;\r
+  UINT8       ScanCode;\r
+  UINT8       Readed;\r
+  BOOLEAN     Extended;\r
+  UINT8       ScancodeArr[4];\r
+  UINTN       Index;\r
+  //\r
+  // 4 bytes most\r
+  //\r
+  UINT32      ScancodeArrPos;\r
+  //\r
+  // point to the current position in ScancodeArr\r
+  //\r
+\r
+  Readed          = 0;\r
+  Extended        = FALSE;\r
+  ScancodeArrPos  = 0;\r
+\r
+  //\r
+  // Read one byte of the scan code and store it into the memory buffer\r
+  // This block of code is added to insert an action that is equivalent to\r
+  // the timer event handling function, so as to increase the frequency of\r
+  // detecting the availability of keys. Timer event has a max frequency of\r
+  // 18Hz which is insufficient\r
+  //\r
+  //\r
+  // To let KB driver support Hot plug, here should skip the 'resend' command  for the case that\r
+  // KB is not connected to system. If KB is not connected to system, driver will find there's  something\r
+  // error in the following code and wait for the input buffer empty, this waiting time shoulb be  short enough since\r
+  // this is a NOTIFY TPL period function, or the system performance will degrade hardly when KB is not connected.\r
+  // Just skip the 'resend' process simply.\r
+  //\r
+\r
+\r
+  if (((KeyReadStatusRegister (ConsoleIn) & 0x21) == 0x1) && (ConsoleIn->ScancodeBufCount < KEYBOARD_BUFFER_MAX_COUNT)) {\r
+\r
+    Readed = KeyReadDataRegister (ConsoleIn);\r
+    //\r
+    // put the scancode into the memory scancode buffer\r
+    //\r
+    ConsoleIn->ScancodeBufCount++;\r
+    ConsoleIn->ScancodeBufEndPos++;\r
+    if (ConsoleIn->ScancodeBufEndPos >= KEYBOARD_BUFFER_MAX_COUNT) {\r
+      ConsoleIn->ScancodeBufEndPos = 0;\r
+    }\r
+\r
+    ConsoleIn->ScancodeBuf[ConsoleIn->ScancodeBufEndPos] = Readed;\r
+\r
+    //\r
+    // Handle Alt+Ctrl+Del Key combination\r
+    //\r
+    switch (Readed) {\r
+\r
+    case SCANCODE_CTRL_MAKE:\r
+      ConsoleIn->Ctrled = TRUE;\r
+      break;\r
+\r
+    case SCANCODE_CTRL_BREAK:\r
+      ConsoleIn->Ctrled = FALSE;\r
+      break;\r
+\r
+    case SCANCODE_ALT_MAKE:\r
+      ConsoleIn->Alted = TRUE;\r
+      break;\r
+\r
+    case SCANCODE_ALT_BREAK:\r
+      ConsoleIn->Alted = FALSE;\r
+      break;\r
+    }\r
+    //\r
+    // if Alt+Ctrl+Del, Reboot the System\r
+    //\r
+    if (ConsoleIn->Ctrled && ConsoleIn->Alted && Readed == 0x53) {\r
+      gRT->ResetSystem (EfiResetWarm, EFI_SUCCESS, 0, NULL);\r
+    }\r
+  }\r
+  //\r
+  // Check if there are enough bytes of scancode representing a single key\r
+  // available in the buffer\r
+  //\r
+  while (1) {\r
+\r
+    Status          = GetScancodeBufHead (ConsoleIn, 1, ScancodeArr);\r
+    ScancodeArrPos  = 0;\r
+    if (EFI_ERROR (Status)) {\r
+      return EFI_NOT_READY;\r
+    }\r
+\r
+    if (ScancodeArr[ScancodeArrPos] == SCANCODE_EXTENDED) {\r
+      Extended        = TRUE;\r
+      Status          = GetScancodeBufHead (ConsoleIn, 2, ScancodeArr);\r
+      ScancodeArrPos  = 1;\r
+      if (EFI_ERROR (Status)) {\r
+        return EFI_NOT_READY;\r
+      }\r
+    }\r
+    //\r
+    // Checks for key scancode for PAUSE:E1-1D/45-E1/9D-C5\r
+    // if present, ignore them\r
+    //\r
+    if (ScancodeArr[ScancodeArrPos] == SCANCODE_EXTENDED1) {\r
+\r
+      Status          = GetScancodeBufHead (ConsoleIn, 2, ScancodeArr);\r
+      ScancodeArrPos  = 1;\r
+\r
+      if (EFI_ERROR (Status)) {\r
+        return EFI_NOT_READY;\r
+      }\r
+\r
+      Status          = GetScancodeBufHead (ConsoleIn, 3, ScancodeArr);\r
+      ScancodeArrPos  = 2;\r
+\r
+      if (EFI_ERROR (Status)) {\r
+        return EFI_NOT_READY;\r
+      }\r
+\r
+      PopScancodeBufHead (ConsoleIn, 3, ScancodeArr);\r
+      return EFI_NOT_READY;\r
+    }\r
+    //\r
+    // if we reach this position, scancodes for a key is in buffer now,pop them\r
+    //\r
+    Status = PopScancodeBufHead (ConsoleIn, ScancodeArrPos + 1, ScancodeArr);\r
+    if (EFI_ERROR (Status)) {\r
+      return EFI_NOT_READY;\r
+    }\r
+    //\r
+    // store the last available byte, this byte of scancode will be checked\r
+    //\r
+    ScanCode = ScancodeArr[ScancodeArrPos];\r
+\r
+    //\r
+    // Check for special keys and update the driver state.\r
+    //\r
+    switch (ScanCode) {\r
+\r
+    case SCANCODE_CTRL_MAKE:\r
+      ConsoleIn->Ctrl = TRUE;\r
+      break;\r
+\r
+    case SCANCODE_CTRL_BREAK:\r
+      ConsoleIn->Ctrl = FALSE;\r
+      break;\r
+\r
+    case SCANCODE_ALT_MAKE:\r
+      ConsoleIn->Alt = TRUE;\r
+      break;\r
+\r
+    case SCANCODE_ALT_BREAK:\r
+      ConsoleIn->Alt = FALSE;\r
+      break;\r
+\r
+    case SCANCODE_LEFT_SHIFT_MAKE:\r
+    case SCANCODE_RIGHT_SHIFT_MAKE:\r
+      if (!Extended) {\r
+        ConsoleIn->Shift = TRUE;\r
+      }\r
+      break;\r
+\r
+    case SCANCODE_LEFT_SHIFT_BREAK:\r
+    case SCANCODE_RIGHT_SHIFT_BREAK:\r
+      if (!Extended) {\r
+        ConsoleIn->Shift = FALSE;\r
+      }\r
+      break;\r
+\r
+    case SCANCODE_CAPS_LOCK_MAKE:\r
+      ConsoleIn->CapsLock = (BOOLEAN)!ConsoleIn->CapsLock;\r
+      UpdateStatusLights (ConsoleIn);\r
+      break;\r
+\r
+    case SCANCODE_NUM_LOCK_MAKE:\r
+      ConsoleIn->NumLock = (BOOLEAN)!ConsoleIn->NumLock;\r
+      UpdateStatusLights (ConsoleIn);\r
+      break;\r
+\r
+    case SCANCODE_SCROLL_LOCK_MAKE:\r
+      ConsoleIn->ScrollLock = (BOOLEAN)!ConsoleIn->ScrollLock;\r
+      UpdateStatusLights (ConsoleIn);\r
+      break;\r
+    }\r
+    //\r
+    // If this is a BREAK Key or above the valid range, ignore it\r
+    //\r
+    if (ScanCode >= SCANCODE_MAX_MAKE) {\r
+      continue;\r
+    } else {\r
+      break;\r
+    }\r
+  }\r
+  //\r
+  // If this is the SysRq, ignore it\r
+  //\r
+  if (Extended && ScanCode == 0x37) {\r
+    return EFI_NOT_READY;\r
+  }\r
+  //\r
+  // Treat Numeric Key Pad "/" specially\r
+  //\r
+  if (Extended && ScanCode == 0x35) {\r
+    ConsoleIn->Key.ScanCode     = SCAN_NULL;\r
+    ConsoleIn->Key.UnicodeChar  = '/';\r
+    return EFI_SUCCESS;\r
+  }\r
+  //\r
+  // Convert Keyboard ScanCode into an EFI Key\r
+  //\r
+  for (Index = 0; ConvertKeyboardScanCodeToEfiKey[Index].ScanCode != TABLE_END; Index += 1) {\r
+    if (ScanCode == ConvertKeyboardScanCodeToEfiKey[Index].ScanCode) {\r
+      ConsoleIn->Key.ScanCode = ConvertKeyboardScanCodeToEfiKey[Index].EfiScanCode;\r
+      if (ConsoleIn->Shift) {\r
+        ConsoleIn->Key.UnicodeChar = ConvertKeyboardScanCodeToEfiKey[Index].ShiftUnicodeChar;\r
+      } else {\r
+        ConsoleIn->Key.UnicodeChar = ConvertKeyboardScanCodeToEfiKey[Index].UnicodeChar;\r
+      }\r
+      //\r
+      // alphabetic key is affected by CapsLock State\r
+      //\r
+      if (ConsoleIn->CapsLock) {\r
+        if (ConsoleIn->Key.UnicodeChar >= 'a' && ConsoleIn->Key.UnicodeChar <= 'z') {\r
+          ConsoleIn->Key.UnicodeChar = ConvertKeyboardScanCodeToEfiKey[Index].ShiftUnicodeChar;\r
+        } else if (ConsoleIn->Key.UnicodeChar >= 'A' && ConsoleIn->Key.UnicodeChar <= 'Z') {\r
+          ConsoleIn->Key.UnicodeChar = ConvertKeyboardScanCodeToEfiKey[Index].UnicodeChar;\r
+        }\r
+      }\r
+\r
+      break;\r
+    }\r
+  }\r
+\r
+  //\r
+  // distinguish numeric key pad keys' 'up symbol' and 'down symbol'\r
+  //\r
+  if (ScanCode >= 0x47 && ScanCode <= 0x53) {\r
+\r
+    if (ConsoleIn->NumLock && !ConsoleIn->Shift && !Extended) {\r
+      ConsoleIn->Key.ScanCode = SCAN_NULL;\r
+    } else if (ScanCode != 0x4a && ScanCode != 0x4e) {\r
+      ConsoleIn->Key.UnicodeChar = 0x00;\r
+    }\r
+  }\r
+  //\r
+  // If the key can not be converted then just return.\r
+  //\r
+  if (ConsoleIn->Key.ScanCode == SCAN_NULL && ConsoleIn->Key.UnicodeChar == 0x00) {\r
+    return EFI_NOT_READY;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+InitKeyboard (\r
+  IN OUT KEYBOARD_CONSOLE_IN_DEV *ConsoleIn,\r
+  IN BOOLEAN                     ExtendedVerification\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Perform 8042 controller and keyboard Initialization\r
+  If ExtendedVerification is TRUE, do additional test for\r
+  the keyboard interface\r
+\r
+Arguments:\r
+\r
+  ConsoleIn - KEYBOARD_CONSOLE_IN_DEV instance pointer\r
+  ExtendedVerification - indicates a thorough initialization\r
+\r
+Returns:\r
+\r
+  EFI_STATUS\r
+\r
+--*/\r
+// GC_TODO:    EFI_DEVICE_ERROR - add return value to function comment\r
+// GC_TODO:    EFI_SUCCESS - add return value to function comment\r
+// GC_TODO:    EFI_DEVICE_ERROR - add return value to function comment\r
+{\r
+  EFI_STATUS              Status;\r
+  EFI_STATUS              Status1;\r
+  UINT8                   CommandByte;\r
+  STATIC BOOLEAN          EnableMouseInterface;\r
+  EFI_PS2_POLICY_PROTOCOL *Ps2Policy;\r
+\r
+  Status                = EFI_SUCCESS;\r
+  EnableMouseInterface  = TRUE;\r
+\r
+  //\r
+  // Get Ps2 policy to set this\r
+  //\r
+  Status = gBS->LocateProtocol (\r
+                  &gEfiPs2PolicyProtocolGuid,\r
+                  NULL,\r
+                  (VOID **) &Ps2Policy\r
+                  );\r
+\r
+  REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
+    EFI_PROGRESS_CODE,\r
+    EFI_PERIPHERAL_KEYBOARD | EFI_P_KEYBOARD_PC_CLEAR_BUFFER,\r
+    ConsoleIn->DevicePath\r
+    );\r
+\r
+  //\r
+  // Perform a read to cleanup the Status Register's\r
+  // output buffer full bits\r
+  //\r
+  while (!EFI_ERROR (Status)) {\r
+    Status = KeyboardRead (ConsoleIn, &CommandByte);\r
+  }\r
+  //\r
+  // We should disable mouse interface during the initialization process\r
+  // since mouse device output could block keyboard device output in the\r
+  // 60H port of 8042 controller.\r
+  //\r
+  // So if we are not initializing 8042 controller for the\r
+  // first time, we have to remember the previous mouse interface\r
+  // enabling state\r
+  //\r
+  // Test the system flag in to determine whether this is the first\r
+  // time initialization\r
+  //\r
+  if ((KeyReadStatusRegister (ConsoleIn) & 0x04)) {\r
+    //\r
+    // 8042 controller is already setup (by myself or by mouse driver):\r
+    //   See whether mouse interface is already enabled\r
+    //   which determines whether we should enable it later\r
+    //\r
+    //\r
+    // Read the command byte of 8042 controller\r
+    //\r
+    Status = KeyboardCommand (ConsoleIn, 0x20);\r
+    if (EFI_ERROR (Status)) {\r
+      KeyboardError (ConsoleIn, L"\n\r");\r
+      goto Done;\r
+    }\r
+\r
+    Status = KeyboardRead (ConsoleIn, &CommandByte);\r
+    if (EFI_ERROR (Status)) {\r
+      KeyboardError (ConsoleIn, L"\n\r");\r
+      goto Done;\r
+    }\r
+    //\r
+    // Test the mouse enabling bit\r
+    //\r
+    if (CommandByte & 0x20) {\r
+      EnableMouseInterface = FALSE;\r
+    } else {\r
+      EnableMouseInterface = TRUE;\r
+    }\r
+\r
+  } else {\r
+    //\r
+    // 8042 controller is not setup yet:\r
+    //   8042 controller selftest;\r
+    //   Don't enable mouse interface later.\r
+    //\r
+    //\r
+    // Disable keyboard and mouse interfaces\r
+    //\r
+    Status = KeyboardCommand (ConsoleIn, 0xad);\r
+    if (EFI_ERROR (Status)) {\r
+      KeyboardError (ConsoleIn, L"\n\r");\r
+      goto Done;\r
+    }\r
+\r
+    Status = KeyboardCommand (ConsoleIn, 0xa7);\r
+    if (EFI_ERROR (Status)) {\r
+      KeyboardError (ConsoleIn, L"\n\r");\r
+      goto Done;\r
+    }\r
+\r
+    REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
+      EFI_PROGRESS_CODE,\r
+      EFI_PERIPHERAL_KEYBOARD | EFI_P_KEYBOARD_PC_SELF_TEST,\r
+      ConsoleIn->DevicePath\r
+      );\r
+    //\r
+    // 8042 Controller Self Test\r
+    //\r
+    Status = KeyboardCommand (ConsoleIn, 0xaa);\r
+    if (EFI_ERROR (Status)) {\r
+      KeyboardError (ConsoleIn, L"8042 controller command write error!\n\r");\r
+      goto Done;\r
+    }\r
+\r
+    Status = KeyboardWaitForValue (ConsoleIn, 0x55);\r
+    if (EFI_ERROR (Status)) {\r
+      KeyboardError (ConsoleIn, L"8042 controller self test failed!\n\r");\r
+      goto Done;\r
+    }\r
+    //\r
+    // Don't enable mouse interface later\r
+    //\r
+    EnableMouseInterface = FALSE;\r
+\r
+  }\r
+\r
+  if (Ps2Policy != NULL) {\r
+    Ps2Policy->Ps2InitHardware (ConsoleIn->Handle);\r
+  }\r
+  //\r
+  // Write 8042 Command Byte, set System Flag\r
+  // While at the same time:\r
+  //  1. disable mouse interface,\r
+  //  2. enable kbd interface,\r
+  //  3. enable PC/XT kbd translation mode\r
+  //  4. enable mouse and kbd interrupts\r
+  //\r
+  //  ( Command Byte bits:\r
+  //  7: Reserved\r
+  //  6: PC/XT translation mode\r
+  //  5: Disable Auxiliary device interface\r
+  //  4: Disable keyboard interface\r
+  //  3: Reserved\r
+  //  2: System Flag\r
+  //  1: Enable Auxiliary device interrupt\r
+  //  0: Enable Keyboard interrupt )\r
+  //\r
+  Status = KeyboardCommand (ConsoleIn, 0x60);\r
+  if (EFI_ERROR (Status)) {\r
+    KeyboardError (ConsoleIn, L"8042 controller command write error!\n\r");\r
+    goto Done;\r
+  }\r
+\r
+  Status = KeyboardWrite (ConsoleIn, 0x67);\r
+  if (EFI_ERROR (Status)) {\r
+    KeyboardError (ConsoleIn, L"8042 controller data write error!\n\r");\r
+    goto Done;\r
+  }\r
+\r
+  //\r
+  // Clear Memory Scancode Buffer\r
+  //\r
+  ConsoleIn->ScancodeBufStartPos  = 0;\r
+  ConsoleIn->ScancodeBufEndPos    = KEYBOARD_BUFFER_MAX_COUNT - 1;\r
+  ConsoleIn->ScancodeBufCount     = 0;\r
+  ConsoleIn->Ctrled               = FALSE;\r
+  ConsoleIn->Alted                = FALSE;\r
+\r
+  //\r
+  // Reset the status indicators\r
+  //\r
+  ConsoleIn->Ctrl       = FALSE;\r
+  ConsoleIn->Alt        = FALSE;\r
+  ConsoleIn->Shift      = FALSE;\r
+  ConsoleIn->CapsLock   = FALSE;\r
+  ConsoleIn->NumLock    = FALSE;\r
+  ConsoleIn->ScrollLock = FALSE;\r
+\r
+  //\r
+  // For reseting keyboard is not mandatory before booting OS and sometimes keyboard responses very slow,\r
+  // and to support KB hot plug, we need to let the InitKB succeed no matter whether there is a KB device connected\r
+  // to system. So we only do the real reseting for keyboard when user asks and there is a real KB connected t system,\r
+  // and normally during booting an OS, it's skipped.\r
+  //\r
+  if (ExtendedVerification && CheckKeyboardConnect (ConsoleIn)) {\r
+    //\r
+    // Additional verifications for keyboard interface\r
+    //\r
+    //\r
+    // Keyboard Interface Test\r
+    //\r
+    Status = KeyboardCommand (ConsoleIn, 0xab);\r
+    if (EFI_ERROR (Status)) {\r
+      KeyboardError (ConsoleIn, L"8042 controller command write error!\n\r");\r
+      goto Done;\r
+    }\r
+\r
+    Status = KeyboardWaitForValue (ConsoleIn, 0x00);\r
+    if (EFI_ERROR (Status)) {\r
+      KeyboardError (\r
+        ConsoleIn,\r
+        L"Some specific value not aquired from 8042 controller!\n\r"\r
+        );\r
+      goto Done;\r
+    }\r
+    //\r
+    // Keyboard reset with a BAT(Basic Assurance Test)\r
+    //\r
+    Status = KeyboardWrite (ConsoleIn, 0xff);\r
+    if (EFI_ERROR (Status)) {\r
+      KeyboardError (ConsoleIn, L"8042 controller data write error!\n\r");\r
+      goto Done;\r
+    }\r
+\r
+    Status = KeyboardWaitForValue (ConsoleIn, 0xfa);\r
+    if (EFI_ERROR (Status)) {\r
+      KeyboardError (ConsoleIn, L"Some specific value not aquired from 8042 controller!\n\r");\r
+      goto Done;\r
+    }\r
+    //\r
+    // wait for BAT completion code\r
+    //\r
+    mWaitForValueTimeOut  = KEYBOARD_BAT_TIMEOUT;\r
+\r
+    Status                = KeyboardWaitForValue (ConsoleIn, 0xaa);\r
+    if (EFI_ERROR (Status)) {\r
+      KeyboardError (ConsoleIn, L"Keyboard self test failed!\n\r");\r
+      goto Done;\r
+    }\r
+\r
+    mWaitForValueTimeOut = KEYBOARD_WAITFORVALUE_TIMEOUT;\r
+\r
+    //\r
+    // Set Keyboard to use Scan Code Set 2\r
+    //\r
+    Status = KeyboardWrite (ConsoleIn, 0xf0);\r
+    if (EFI_ERROR (Status)) {\r
+      KeyboardError (ConsoleIn, L"8042 controller data write error!\n\r");\r
+      goto Done;\r
+    }\r
+\r
+    Status = KeyboardWaitForValue (ConsoleIn, 0xfa);\r
+    if (EFI_ERROR (Status)) {\r
+      KeyboardError (ConsoleIn, L"Some specific value not aquired from 8042 controller!\n\r");\r
+      goto Done;\r
+    }\r
+\r
+    Status = KeyboardWrite (ConsoleIn, 0x02);\r
+    if (EFI_ERROR (Status)) {\r
+      KeyboardError (ConsoleIn, L"8042 controller data write error!!\n\r");\r
+      goto Done;\r
+    }\r
+\r
+    Status = KeyboardWaitForValue (ConsoleIn, 0xfa);\r
+    if (EFI_ERROR (Status)) {\r
+      KeyboardError (ConsoleIn, L"Some specific value not aquired from 8042 controller!\n\r");\r
+      goto Done;\r
+    }\r
+\r
+  //\r
+  // Clear Keyboard Scancode Buffer\r
+  //\r
+  Status = KeyboardWrite (ConsoleIn, 0xf4);\r
+  if (EFI_ERROR (Status)) {\r
+    KeyboardError (ConsoleIn, L"8042 controller data write error!\n\r");\r
+    goto Done;\r
+  }\r
+\r
+  Status = KeyboardWaitForValue (ConsoleIn, 0xfa);\r
+  if (EFI_ERROR (Status)) {\r
+    KeyboardError (ConsoleIn, L"Some specific value not aquired from 8042 controller!\n\r");\r
+    goto Done;\r
+  }\r
+  //\r
+  if (Ps2Policy != NULL) {\r
+    if ((Ps2Policy->KeyboardLight & EFI_KEYBOARD_CAPSLOCK) == EFI_KEYBOARD_CAPSLOCK) {\r
+      ConsoleIn->CapsLock = TRUE;\r
+    }\r
+\r
+    if ((Ps2Policy->KeyboardLight & EFI_KEYBOARD_NUMLOCK) == EFI_KEYBOARD_NUMLOCK) {\r
+      ConsoleIn->NumLock = TRUE;\r
+    }\r
+\r
+    if ((Ps2Policy->KeyboardLight & EFI_KEYBOARD_SCROLLLOCK) == EFI_KEYBOARD_SCROLLLOCK) {\r
+      ConsoleIn->ScrollLock = TRUE;\r
+    }\r
+  }\r
+  //\r
+  // Update Keyboard Lights\r
+  //\r
+  Status = UpdateStatusLights (ConsoleIn);\r
+  if (EFI_ERROR (Status)) {\r
+    KeyboardError (ConsoleIn, L"Update keyboard status lights error!\n\r");\r
+    goto Done;\r
+    }\r
+  }\r
+  //\r
+  // At last, we can now enable the mouse interface if appropriate\r
+  //\r
+Done:\r
+\r
+  if (EnableMouseInterface) {\r
+    //\r
+    // Enable mouse interface\r
+    //\r
+    Status1 = KeyboardCommand (ConsoleIn, 0xa8);\r
+    if (EFI_ERROR (Status1)) {\r
+      KeyboardError (ConsoleIn, L"8042 controller command write error!\n\r");\r
+      return EFI_DEVICE_ERROR;\r
+    }\r
+  }\r
+\r
+  if (!EFI_ERROR (Status)) {\r
+    return EFI_SUCCESS;\r
+  } else {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+}\r
+\r
+EFI_STATUS\r
+DisableKeyboard (\r
+  IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Disable the keyboard interface of the 8042 controller\r
+\r
+Arguments:\r
+\r
+  ConsoleIn   - the device instance\r
+\r
+Returns:\r
+\r
+  EFI_STATUS\r
+\r
+--*/\r
+// GC_TODO:    EFI_DEVICE_ERROR - add return value to function comment\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  //\r
+  // Disable keyboard interface\r
+  //\r
+  Status = KeyboardCommand (ConsoleIn, 0xad);\r
+  if (EFI_ERROR (Status)) {\r
+    KeyboardError (ConsoleIn, L"\n\r");\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Check whether there is Ps/2 Keyboard device in system by 0xF4 Keyboard Command\r
+  If Keyboard receives 0xF4, it will respond with 'ACK'. If it doesn't respond, the device\r
+  should not be in system.\r
+\r
+  @param[in]  BiosKeyboardPrivate   Keyboard Private Data Structure\r
+\r
+  @retval              TRUE                                                            Keyboard in System.\r
+  @retval              FALSE                                                           Keyboard not in System.\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+CheckKeyboardConnect (\r
+  IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn\r
+  )\r
+{\r
+  EFI_STATUS     Status;\r
+  UINTN          WaitForValueTimeOutBcakup;\r
+\r
+  Status = EFI_SUCCESS;\r
+  //\r
+  // enable keyboard itself and wait for its ack\r
+  // If can't receive ack, Keyboard should not be connected.\r
+  //\r
+  Status = KeyboardWrite (\r
+             ConsoleIn,\r
+             KEYBOARD_KBEN\r
+             );\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return FALSE;\r
+  }\r
+  //\r
+  // wait for 1s\r
+  //\r
+  WaitForValueTimeOutBcakup = mWaitForValueTimeOut;\r
+  mWaitForValueTimeOut = KEYBOARD_WAITFORVALUE_TIMEOUT;\r
+  Status = KeyboardWaitForValue (\r
+             ConsoleIn,\r
+             KEYBOARD_CMDECHO_ACK\r
+             );\r
+  mWaitForValueTimeOut = WaitForValueTimeOutBcakup;\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return FALSE;\r
+  }\r
+\r
+  return TRUE;\r
+}\r
diff --git a/IntelFrameworkModulePkg/Bus/Isa/Ps2KeyboardDxe/Ps2KbdTextIn.c b/IntelFrameworkModulePkg/Bus/Isa/Ps2KeyboardDxe/Ps2KbdTextIn.c
new file mode 100644 (file)
index 0000000..18ac83f
--- /dev/null
@@ -0,0 +1,306 @@
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation. All rights reserved. <BR>\r
+This software and associated documentation (if any) is furnished\r
+under a license and may only be used or copied in accordance\r
+with the terms of the license. Except as permitted by such\r
+license, no part of this software or documentation may be\r
+reproduced, stored in a retrieval system, or transmitted in any\r
+form or by any means without the express written consent of\r
+Intel Corporation.\r
+\r
+\r
+Module Name:\r
+\r
+  Ps2KbdTextIn.c\r
+\r
+Abstract:\r
+\r
+  PS/2 Keyboard  driver\r
+  Routines that support SIMPLE_TEXT_IN protocol\r
+\r
+Revision History\r
+\r
+--*/\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+#include "Ps2Keyboard.h"\r
+\r
+//\r
+// function declarations\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+KeyboardEfiReset (\r
+  IN  EFI_SIMPLE_TEXT_INPUT_PROTOCOL  *This,\r
+  IN  BOOLEAN                         ExtendedVerification\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+KeyboardReadKeyStroke (\r
+  IN  EFI_SIMPLE_TEXT_INPUT_PROTOCOL  *This,\r
+  OUT EFI_INPUT_KEY                   *Key\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+KeyboardWaitForKey (\r
+  IN  EFI_EVENT               Event,\r
+  IN  VOID                    *Context\r
+  );\r
+\r
+EFI_STATUS\r
+KeyboardCheckForKey (\r
+  IN  EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+KeyboardEfiReset (\r
+  IN  EFI_SIMPLE_TEXT_INPUT_PROTOCOL  *This,\r
+  IN  BOOLEAN                         ExtendedVerification\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Implement SIMPLE_TEXT_IN.Reset()\r
+  Perform 8042 controller and keyboard initialization\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+--*/\r
+// GC_TODO:    This - add argument and description to function comment\r
+// GC_TODO:    ExtendedVerification - add argument and description to function comment\r
+// GC_TODO:    EFI_DEVICE_ERROR - add return value to function comment\r
+// GC_TODO:    EFI_DEVICE_ERROR - add return value to function comment\r
+// GC_TODO:    EFI_SUCCESS - add return value to function comment\r
+{\r
+  EFI_STATUS              Status;\r
+  KEYBOARD_CONSOLE_IN_DEV *ConsoleIn;\r
+  EFI_TPL                 OldTpl;\r
+\r
+  ConsoleIn = KEYBOARD_CONSOLE_IN_DEV_FROM_THIS (This);\r
+  if (ConsoleIn->KeyboardErr) {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
+    EFI_PROGRESS_CODE,\r
+    EFI_PERIPHERAL_KEYBOARD | EFI_P_PC_RESET,\r
+    ConsoleIn->DevicePath\r
+    );\r
+\r
+  //\r
+  // Enter critical section\r
+  //\r
+  OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
+\r
+  //\r
+  // Call InitKeyboard to initialize the keyboard\r
+  //\r
+  Status = InitKeyboard (ConsoleIn, ExtendedVerification);\r
+  if (EFI_ERROR (Status)) {\r
+    //\r
+    // Leave critical section and return\r
+    //\r
+    gBS->RestoreTPL (OldTpl);\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+  //\r
+  // Clear the status of ConsoleIn.Key\r
+  //\r
+  ConsoleIn->Key.ScanCode     = SCAN_NULL;\r
+  ConsoleIn->Key.UnicodeChar  = 0x0000;\r
+\r
+  //\r
+  // Leave critical section and return\r
+  //\r
+  gBS->RestoreTPL (OldTpl);\r
+\r
+  //\r
+  // Report the status If a stuck key was detected\r
+  //\r
+  if (KeyReadStatusRegister (ConsoleIn) & 0x01) {\r
+    REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
+      EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
+      EFI_PERIPHERAL_KEYBOARD | EFI_P_KEYBOARD_EC_STUCK_KEY,\r
+      ConsoleIn->DevicePath\r
+      );\r
+  }\r
+  //\r
+  // Report the status If keyboard is locked\r
+  //\r
+  if (!(KeyReadStatusRegister (ConsoleIn) & 0x10)) {\r
+    REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
+      EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
+      EFI_PERIPHERAL_KEYBOARD | EFI_P_KEYBOARD_EC_LOCKED,\r
+      ConsoleIn->DevicePath\r
+      );\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+KeyboardReadKeyStroke (\r
+  IN  EFI_SIMPLE_TEXT_INPUT_PROTOCOL  *This,\r
+  OUT EFI_INPUT_KEY                   *Key\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Implement SIMPLE_TEXT_IN.ReadKeyStroke().\r
+  Retrieve key values for driver user.\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+--*/\r
+// GC_TODO:    This - add argument and description to function comment\r
+// GC_TODO:    Key - add argument and description to function comment\r
+// GC_TODO:    EFI_DEVICE_ERROR - add return value to function comment\r
+// GC_TODO:    EFI_NOT_READY - add return value to function comment\r
+// GC_TODO:    EFI_SUCCESS - add return value to function comment\r
+{\r
+  EFI_STATUS              Status;\r
+  KEYBOARD_CONSOLE_IN_DEV *ConsoleIn;\r
+  EFI_TPL                 OldTpl;\r
+\r
+  ConsoleIn = KEYBOARD_CONSOLE_IN_DEV_FROM_THIS (This);\r
+\r
+  //\r
+  // Enter critical section\r
+  //\r
+  OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
+\r
+  if (ConsoleIn->KeyboardErr) {\r
+    //\r
+    // Leave critical section and return\r
+    //\r
+    gBS->RestoreTPL (OldTpl);\r
+\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+  //\r
+  // If there's no key, just return\r
+  //\r
+  Status = KeyboardCheckForKey (This);\r
+  if (EFI_ERROR (Status)) {\r
+    //\r
+    // Leave critical section and return\r
+    //\r
+    gBS->RestoreTPL (OldTpl);\r
+    return EFI_NOT_READY;\r
+  }\r
+\r
+  Key->ScanCode               = ConsoleIn->Key.ScanCode;\r
+  Key->UnicodeChar            = ConsoleIn->Key.UnicodeChar;\r
+\r
+  ConsoleIn->Key.ScanCode     = SCAN_NULL;\r
+  ConsoleIn->Key.UnicodeChar  = 0x0000;\r
+\r
+  //\r
+  // Leave critical section and return\r
+  //\r
+  gBS->RestoreTPL (OldTpl);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+KeyboardWaitForKey (\r
+  IN  EFI_EVENT               Event,\r
+  IN  VOID                    *Context\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Event notification function for SIMPLE_TEXT_IN.WaitForKey event\r
+  Signal the event if there is key available\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+--*/\r
+// GC_TODO:    Event - add argument and description to function comment\r
+// GC_TODO:    Context - add argument and description to function comment\r
+{\r
+  EFI_TPL                 OldTpl;\r
+  KEYBOARD_CONSOLE_IN_DEV *ConsoleIn;\r
+\r
+  ConsoleIn = KEYBOARD_CONSOLE_IN_DEV_FROM_THIS (Context);\r
+\r
+  //\r
+  // Enter critical section\r
+  //\r
+  OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
+\r
+  if (ConsoleIn->KeyboardErr) {\r
+    //\r
+    // Leave critical section and return\r
+    //\r
+    gBS->RestoreTPL (OldTpl);\r
+    return ;\r
+  }\r
+  //\r
+  // Someone is waiting on the keyboard event, if there's\r
+  // a key pending, signal the event\r
+  //\r
+  if (!EFI_ERROR (KeyboardCheckForKey (Context))) {\r
+    gBS->SignalEvent (Event);\r
+  }\r
+  //\r
+  // Leave critical section and return\r
+  //\r
+  gBS->RestoreTPL (OldTpl);\r
+\r
+  return ;\r
+}\r
+\r
+EFI_STATUS\r
+KeyboardCheckForKey (\r
+  IN  EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This  - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS - GC_TODO: Add description for return value\r
+\r
+--*/\r
+{\r
+  KEYBOARD_CONSOLE_IN_DEV *ConsoleIn;\r
+\r
+  ConsoleIn = KEYBOARD_CONSOLE_IN_DEV_FROM_THIS (This);\r
+\r
+  //\r
+  // If ready to read next key, check it\r
+  //\r
+  if (ConsoleIn->Key.ScanCode == SCAN_NULL && ConsoleIn->Key.UnicodeChar == 0x00) {\r
+    return KeyGetchar (ConsoleIn);\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
diff --git a/IntelFrameworkModulePkg/Bus/Isa/Ps2KeyboardDxe/Ps2Keyboard.c b/IntelFrameworkModulePkg/Bus/Isa/Ps2KeyboardDxe/Ps2Keyboard.c
new file mode 100644 (file)
index 0000000..ef2e4a2
--- /dev/null
@@ -0,0 +1,474 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved. <BR>\r
+This software and associated documentation (if any) is furnished\r
+under a license and may only be used or copied in accordance\r
+with the terms of the license. Except as permitted by such\r
+license, no part of this software or documentation may be\r
+reproduced, stored in a retrieval system, or transmitted in any\r
+form or by any means without the express written consent of\r
+Intel Corporation.\r
+\r
+\r
+Module Name:\r
+\r
+  Ps2Keyboard.c\r
+\r
+Abstract:\r
+\r
+  PS/2 Keyboard driver. Routines that interacts with callers,\r
+  conforming to EFI driver model\r
+\r
+--*/\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+#include "Ps2Keyboard.h"\r
+\r
+//\r
+// Function prototypes\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+KbdControllerDriverSupported (\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
+KbdControllerDriverStart (\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
+KbdControllerDriverStop (\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
+// Global variables\r
+//\r
+//\r
+// DriverBinding Protocol Instance\r
+//\r
+EFI_DRIVER_BINDING_PROTOCOL gKeyboardControllerDriver = {\r
+  KbdControllerDriverSupported,\r
+  KbdControllerDriverStart,\r
+  KbdControllerDriverStop,\r
+  0xa,\r
+  NULL,\r
+  NULL\r
+};\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+KbdControllerDriverSupported (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL    *This,\r
+  IN EFI_HANDLE                     Controller,\r
+  IN EFI_DEVICE_PATH_PROTOCOL       *RemainingDevicePath\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  ControllerDriver Protocol Method\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+--*/\r
+// GC_TODO:    This - add argument and description to function comment\r
+// GC_TODO:    Controller - add argument and description to function comment\r
+// GC_TODO:    RemainingDevicePath - add argument and description to function comment\r
+{\r
+  EFI_STATUS                          Status;\r
+  EFI_ISA_IO_PROTOCOL                 *IsaIo;\r
+\r
+  //\r
+  // Open the IO Abstraction(s) needed to perform the supported test\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  Controller,\r
+                  &gEfiIsaIoProtocolGuid,\r
+                  (VOID **) &IsaIo,\r
+                  This->DriverBindingHandle,\r
+                  Controller,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  //\r
+  // Use the ISA I/O Protocol to see if Controller is the Keyboard controller\r
+  //\r
+  if (IsaIo->ResourceList->Device.HID != EISA_PNP_ID (0x303) || IsaIo->ResourceList->Device.UID != 0) {\r
+    Status = EFI_UNSUPPORTED;\r
+  }\r
+  //\r
+  // Close the I/O Abstraction(s) used to perform the supported test\r
+  //\r
+  gBS->CloseProtocol (\r
+         Controller,\r
+         &gEfiIsaIoProtocolGuid,\r
+         This->DriverBindingHandle,\r
+         Controller\r
+         );\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+KbdControllerDriverStart (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL    *This,\r
+  IN EFI_HANDLE                     Controller,\r
+  IN EFI_DEVICE_PATH_PROTOCOL       *RemainingDevicePath\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+--*/\r
+// GC_TODO:    This - add argument and description to function comment\r
+// GC_TODO:    Controller - add argument and description to function comment\r
+// GC_TODO:    RemainingDevicePath - add argument and description to function comment\r
+// GC_TODO:    EFI_INVALID_PARAMETER - add return value to function comment\r
+{\r
+  EFI_STATUS                                Status;\r
+  EFI_STATUS                                Status1;\r
+  EFI_ISA_IO_PROTOCOL                       *IsaIo;\r
+  KEYBOARD_CONSOLE_IN_DEV                   *ConsoleIn;\r
+  UINT8                                     Data;\r
+  EFI_STATUS_CODE_VALUE                     StatusCode;\r
+  EFI_DEVICE_PATH_PROTOCOL                  *ParentDevicePath;\r
+\r
+  StatusCode = 0;\r
+\r
+  Status = gBS->OpenProtocol (\r
+                  Controller,\r
+                  &gEfiDevicePathProtocolGuid,\r
+                  (VOID **) &ParentDevicePath,\r
+                  This->DriverBindingHandle,\r
+                  Controller,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  //\r
+  // Report that the keyboard is being enabled\r
+  //\r
+  REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
+    EFI_PROGRESS_CODE,\r
+    EFI_PERIPHERAL_KEYBOARD | EFI_P_PC_ENABLE,\r
+    ParentDevicePath\r
+    );\r
+\r
+  //\r
+  // Get the ISA I/O Protocol on Controller's handle\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  Controller,\r
+                  &gEfiIsaIoProtocolGuid,\r
+                  (VOID **) &IsaIo,\r
+                  This->DriverBindingHandle,\r
+                  Controller,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    gBS->CloseProtocol (\r
+           Controller,\r
+           &gEfiDevicePathProtocolGuid,\r
+           This->DriverBindingHandle,\r
+           Controller\r
+           );\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  //\r
+  // Allocate private data\r
+  //\r
+  ConsoleIn = AllocateZeroPool (sizeof (KEYBOARD_CONSOLE_IN_DEV));\r
+  if (ConsoleIn == NULL) {\r
+    Status      = EFI_OUT_OF_RESOURCES;\r
+    StatusCode  = EFI_PERIPHERAL_KEYBOARD | EFI_P_EC_CONTROLLER_ERROR;\r
+    goto ErrorExit;\r
+  }\r
+  //\r
+  // Setup the device instance\r
+  //\r
+  ConsoleIn->Signature              = KEYBOARD_CONSOLE_IN_DEV_SIGNATURE;\r
+  ConsoleIn->Handle                 = Controller;\r
+  (ConsoleIn->ConIn).Reset          = KeyboardEfiReset;\r
+  (ConsoleIn->ConIn).ReadKeyStroke  = KeyboardReadKeyStroke;\r
+  ConsoleIn->DataRegisterAddress    = KEYBOARD_8042_DATA_REGISTER;\r
+  ConsoleIn->StatusRegisterAddress  = KEYBOARD_8042_STATUS_REGISTER;\r
+  ConsoleIn->CommandRegisterAddress = KEYBOARD_8042_COMMAND_REGISTER;\r
+  ConsoleIn->IsaIo                  = IsaIo;\r
+  ConsoleIn->ScancodeBufStartPos    = 0;\r
+  ConsoleIn->ScancodeBufEndPos      = KEYBOARD_BUFFER_MAX_COUNT - 1;\r
+  ConsoleIn->ScancodeBufCount       = 0;\r
+  ConsoleIn->Ctrled                 = FALSE;\r
+  ConsoleIn->Alted                  = FALSE;\r
+  ConsoleIn->DevicePath             = ParentDevicePath;\r
+\r
+  //\r
+  // Setup the WaitForKey event\r
+  //\r
+  Status = gBS->CreateEvent (\r
+                  EVT_NOTIFY_WAIT,\r
+                  TPL_NOTIFY,\r
+                  KeyboardWaitForKey,\r
+                  &(ConsoleIn->ConIn),\r
+                  &((ConsoleIn->ConIn).WaitForKey)\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    Status      = EFI_OUT_OF_RESOURCES;\r
+    StatusCode  = EFI_PERIPHERAL_KEYBOARD | EFI_P_EC_CONTROLLER_ERROR;\r
+    goto ErrorExit;\r
+  }\r
+  //\r
+  // Setup a periodic timer, used for reading keystrokes at a fixed interval\r
+  //\r
+  Status = gBS->CreateEvent (\r
+                  EVT_TIMER | EVT_NOTIFY_SIGNAL,\r
+                  TPL_NOTIFY,\r
+                  KeyboardTimerHandler,\r
+                  ConsoleIn,\r
+                  &ConsoleIn->TimerEvent\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    Status      = EFI_OUT_OF_RESOURCES;\r
+    StatusCode  = EFI_PERIPHERAL_KEYBOARD | EFI_P_EC_CONTROLLER_ERROR;\r
+    goto ErrorExit;\r
+  }\r
+\r
+  Status = gBS->SetTimer (\r
+                  ConsoleIn->TimerEvent,\r
+                  TimerPeriodic,\r
+                  KEYBOARD_TIMER_INTERVAL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    Status      = EFI_OUT_OF_RESOURCES;\r
+    StatusCode  = EFI_PERIPHERAL_KEYBOARD | EFI_P_EC_CONTROLLER_ERROR;\r
+    goto ErrorExit;\r
+  }\r
+\r
+  REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
+    EFI_PROGRESS_CODE,\r
+    EFI_PERIPHERAL_KEYBOARD | EFI_P_PC_PRESENCE_DETECT,\r
+    ParentDevicePath\r
+    );\r
+\r
+  //\r
+  // Reset the keyboard device\r
+  //\r
+  Status = ConsoleIn->ConIn.Reset (&ConsoleIn->ConIn, TRUE);\r
+  if (EFI_ERROR (Status)) {\r
+    Status      = EFI_DEVICE_ERROR;\r
+    StatusCode  = EFI_PERIPHERAL_KEYBOARD | EFI_P_EC_NOT_DETECTED;\r
+    goto ErrorExit;\r
+  }\r
+\r
+  ConsoleIn->ControllerNameTable = NULL;\r
+  AddUnicodeString (\r
+    "eng",\r
+    gPs2KeyboardComponentName.SupportedLanguages,\r
+    &ConsoleIn->ControllerNameTable,\r
+    L"PS/2 Keyboard Device"\r
+    );\r
+\r
+  //\r
+  // Install protocol interfaces for the keyboard device.\r
+  //\r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &Controller,\r
+                  &gEfiSimpleTextInProtocolGuid,\r
+                  &ConsoleIn->ConIn,\r
+                  NULL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    StatusCode = EFI_PERIPHERAL_KEYBOARD | EFI_P_EC_CONTROLLER_ERROR;\r
+    goto ErrorExit;\r
+  }\r
+\r
+  return Status;\r
+\r
+ErrorExit:\r
+  //\r
+  // Report error code\r
+  //\r
+  if (StatusCode != 0) {\r
+    REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
+      EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
+      StatusCode,\r
+      ParentDevicePath\r
+      );\r
+  }\r
+\r
+  if ((ConsoleIn != NULL) && (ConsoleIn->ConIn.WaitForKey != NULL)) {\r
+    gBS->CloseEvent (ConsoleIn->ConIn.WaitForKey);\r
+  }\r
+\r
+  if ((ConsoleIn != NULL) && (ConsoleIn->TimerEvent != NULL)) {\r
+    gBS->CloseEvent (ConsoleIn->TimerEvent);\r
+  }\r
+\r
+  if ((ConsoleIn != NULL) && (ConsoleIn->ControllerNameTable != NULL)) {\r
+    FreeUnicodeStringTable (ConsoleIn->ControllerNameTable);\r
+  }\r
+  //\r
+  // Since there will be no timer handler for keyboard input any more,\r
+  // exhaust input data just in case there is still keyboard data left\r
+  //\r
+  Status1 = EFI_SUCCESS;\r
+  while (!EFI_ERROR (Status1)) {\r
+    Status1 = KeyboardRead (ConsoleIn, &Data);;\r
+  }\r
+\r
+  if (ConsoleIn != NULL) {\r
+    gBS->FreePool (ConsoleIn);\r
+  }\r
+\r
+  gBS->CloseProtocol (\r
+         Controller,\r
+         &gEfiDevicePathProtocolGuid,\r
+         This->DriverBindingHandle,\r
+         Controller\r
+         );\r
+\r
+  gBS->CloseProtocol (\r
+         Controller,\r
+         &gEfiIsaIoProtocolGuid,\r
+         This->DriverBindingHandle,\r
+         Controller\r
+         );\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+KbdControllerDriverStop (\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
+  Routine Description:\r
+\r
+  Arguments:\r
+\r
+  Returns:\r
+\r
+--*/\r
+// GC_TODO:    This - add argument and description to function comment\r
+// GC_TODO:    Controller - add argument and description to function comment\r
+// GC_TODO:    NumberOfChildren - add argument and description to function comment\r
+// GC_TODO:    ChildHandleBuffer - add argument and description to function comment\r
+// GC_TODO:    EFI_SUCCESS - add return value to function comment\r
+{\r
+  EFI_STATUS                     Status;\r
+  EFI_SIMPLE_TEXT_INPUT_PROTOCOL *ConIn;\r
+  KEYBOARD_CONSOLE_IN_DEV        *ConsoleIn;\r
+  UINT8                          Data;\r
+\r
+  //\r
+  // Disable Keyboard\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  Controller,\r
+                  &gEfiSimpleTextInProtocolGuid,\r
+                  (VOID **) &ConIn,\r
+                  This->DriverBindingHandle,\r
+                  Controller,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  ConsoleIn = KEYBOARD_CONSOLE_IN_DEV_FROM_THIS (ConIn);\r
+\r
+  //\r
+  // Report that the keyboard is being disabled\r
+  //\r
+  REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
+    EFI_PROGRESS_CODE,\r
+    EFI_PERIPHERAL_KEYBOARD | EFI_P_PC_DISABLE,\r
+    ConsoleIn->DevicePath\r
+    );\r
+\r
+  if (ConsoleIn->TimerEvent) {\r
+    gBS->CloseEvent (ConsoleIn->TimerEvent);\r
+    ConsoleIn->TimerEvent = NULL;\r
+  }\r
+  //\r
+  // Disable the keyboard interface\r
+  //\r
+  Status = DisableKeyboard (ConsoleIn);\r
+\r
+  //\r
+  // Since there will be no timer handler for keyboard input any more,\r
+  // exhaust input data just in case there is still keyboard data left\r
+  //\r
+  Status = EFI_SUCCESS;\r
+  while (!EFI_ERROR (Status)) {\r
+    Status = KeyboardRead (ConsoleIn, &Data);;\r
+  }\r
+  //\r
+  // Uninstall the Simple TextIn Protocol\r
+  //\r
+  Status = gBS->UninstallProtocolInterface (\r
+                  Controller,\r
+                  &gEfiSimpleTextInProtocolGuid,\r
+                  &ConsoleIn->ConIn\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  gBS->CloseProtocol (\r
+         Controller,\r
+         &gEfiDevicePathProtocolGuid,\r
+         This->DriverBindingHandle,\r
+         Controller\r
+         );\r
+\r
+  gBS->CloseProtocol (\r
+         Controller,\r
+         &gEfiIsaIoProtocolGuid,\r
+         This->DriverBindingHandle,\r
+         Controller\r
+         );\r
+\r
+  //\r
+  // Free other resources\r
+  //\r
+  if ((ConsoleIn->ConIn).WaitForKey) {\r
+    gBS->CloseEvent ((ConsoleIn->ConIn).WaitForKey);\r
+    (ConsoleIn->ConIn).WaitForKey = NULL;\r
+  }\r
+\r
+  FreeUnicodeStringTable (ConsoleIn->ControllerNameTable);\r
+  gBS->FreePool (ConsoleIn);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
diff --git a/IntelFrameworkModulePkg/Bus/Isa/Ps2KeyboardDxe/Ps2Keyboard.h b/IntelFrameworkModulePkg/Bus/Isa/Ps2KeyboardDxe/Ps2Keyboard.h
new file mode 100644 (file)
index 0000000..58af5ff
--- /dev/null
@@ -0,0 +1,361 @@
+/**@file\r
+       PS/2 keyboard driver header file\r
+\r
+Copyright (c) 2006 - 2007 Intel Corporation. All rights reserved. <BR>\r
+This software and associated documentation (if any) is furnished\r
+under a license and may only be used or copied in accordance\r
+with the terms of the license. Except as permitted by such\r
+license, no part of this software or documentation may be\r
+reproduced, stored in a retrieval system, or transmitted in any\r
+form or by any means without the express written consent of\r
+Intel Corporation.\r
+\r
+**/\r
+\r
+#ifndef _PS2KEYBOARD_H\r
+#define _PS2KEYBOARD_H\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+//\r
+// Driver Private Data\r
+//\r
+#define KEYBOARD_BUFFER_MAX_COUNT         32\r
+#define KEYBOARD_CONSOLE_IN_DEV_SIGNATURE EFI_SIGNATURE_32 ('k', 'k', 'e', 'y')\r
+\r
+typedef struct {\r
+  UINTN                               Signature;\r
+\r
+  EFI_HANDLE                          Handle;\r
+  EFI_SIMPLE_TEXT_INPUT_PROTOCOL      ConIn;\r
+  EFI_ISA_IO_PROTOCOL                 *IsaIo;\r
+\r
+  EFI_EVENT                           TimerEvent;\r
+\r
+  UINT32                              DataRegisterAddress;\r
+  UINT32                              StatusRegisterAddress;\r
+  UINT32                              CommandRegisterAddress;\r
+\r
+  EFI_INPUT_KEY                       Key;\r
+\r
+  BOOLEAN                             Ctrl;\r
+  BOOLEAN                             Alt;\r
+  BOOLEAN                             Shift;\r
+  BOOLEAN                             CapsLock;\r
+  BOOLEAN                             NumLock;\r
+  BOOLEAN                             ScrollLock;\r
+\r
+  //\r
+  // Buffer storing key scancodes\r
+  //\r
+  UINT8                               ScancodeBuf[KEYBOARD_BUFFER_MAX_COUNT];\r
+  UINT32                              ScancodeBufStartPos;\r
+  UINT32                              ScancodeBufEndPos;\r
+  UINT32                              ScancodeBufCount;\r
+\r
+  //\r
+  // Indicators of the key pressing state, used in detecting Alt+Ctrl+Del\r
+  //\r
+  BOOLEAN                             Ctrled;\r
+  BOOLEAN                             Alted;\r
+\r
+  //\r
+  // Error state\r
+  //\r
+  BOOLEAN                             KeyboardErr;\r
+\r
+  EFI_UNICODE_STRING_TABLE            *ControllerNameTable;\r
+\r
+  EFI_DEVICE_PATH_PROTOCOL            *DevicePath;\r
+} KEYBOARD_CONSOLE_IN_DEV;\r
+\r
+#define KEYBOARD_CONSOLE_IN_DEV_FROM_THIS(a)  CR (a, KEYBOARD_CONSOLE_IN_DEV, ConIn, KEYBOARD_CONSOLE_IN_DEV_SIGNATURE)\r
+\r
+#define TABLE_END 0x0\r
+\r
+//\r
+// Global Variables\r
+//\r
+extern EFI_DRIVER_BINDING_PROTOCOL  gKeyboardControllerDriver;\r
+extern EFI_COMPONENT_NAME_PROTOCOL  gPs2KeyboardComponentName;\r
+\r
+//\r
+// Driver entry point\r
+//\r
+EFI_STATUS\r
+InstallPs2KeyboardDriver (\r
+  IN EFI_HANDLE           ImageHandle,\r
+  IN EFI_SYSTEM_TABLE     *SystemTable\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  ImageHandle - GC_TODO: add argument description\r
+  SystemTable - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+  GC_TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+#define KEYBOARD_8042_DATA_REGISTER     0x60\r
+#define KEYBOARD_8042_STATUS_REGISTER   0x64\r
+#define KEYBOARD_8042_COMMAND_REGISTER  0x64\r
+\r
+#define KEYBOARD_KBEN                   0xF4\r
+#define KEYBOARD_CMDECHO_ACK            0xFA\r
+\r
+#define KEYBOARD_TIMEOUT                65536   // 0.07s\r
+#define KEYBOARD_WAITFORVALUE_TIMEOUT   1000000 // 1s\r
+#define KEYBOARD_BAT_TIMEOUT            4000000 // 4s\r
+#define KEYBOARD_TIMER_INTERVAL         200000  // 0.02s\r
+#define SCANCODE_EXTENDED               0xE0\r
+#define SCANCODE_EXTENDED1              0xE1\r
+#define SCANCODE_CTRL_MAKE              0x1D\r
+#define SCANCODE_CTRL_BREAK             0x9D\r
+#define SCANCODE_ALT_MAKE               0x38\r
+#define SCANCODE_ALT_BREAK              0xB8\r
+#define SCANCODE_LEFT_SHIFT_MAKE        0x2A\r
+#define SCANCODE_LEFT_SHIFT_BREAK       0xAA\r
+#define SCANCODE_RIGHT_SHIFT_MAKE       0x36\r
+#define SCANCODE_RIGHT_SHIFT_BREAK      0xB6\r
+#define SCANCODE_CAPS_LOCK_MAKE         0x3A\r
+#define SCANCODE_NUM_LOCK_MAKE          0x45\r
+#define SCANCODE_SCROLL_LOCK_MAKE       0x46\r
+#define SCANCODE_MAX_MAKE               0x59\r
+\r
+//\r
+// Other functions that are used among .c files\r
+//\r
+EFI_STATUS\r
+KeyboardRead (\r
+  IN KEYBOARD_CONSOLE_IN_DEV  *ConsoleIn,\r
+  OUT UINT8                   *Data\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  ConsoleIn - GC_TODO: add argument description\r
+  Data      - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+  GC_TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+KeyGetchar (\r
+  IN OUT KEYBOARD_CONSOLE_IN_DEV *ConsoleIn\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  ConsoleIn - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+  GC_TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+InitKeyboard (\r
+  IN OUT KEYBOARD_CONSOLE_IN_DEV *ConsoleIn,\r
+  IN BOOLEAN                     ExtendedVerification\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  ConsoleIn             - GC_TODO: add argument description\r
+  ExtendedVerification  - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+  GC_TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+DisableKeyboard (\r
+  IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  ConsoleIn - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+  GC_TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+VOID\r
+EFIAPI\r
+KeyboardTimerHandler (\r
+  IN EFI_EVENT    Event,\r
+  IN VOID         *Context\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  Event   - GC_TODO: add argument description\r
+  Context - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+  GC_TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+KeyboardEfiReset (\r
+  IN  EFI_SIMPLE_TEXT_INPUT_PROTOCOL  *This,\r
+  IN  BOOLEAN                         ExtendedVerification\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This                  - GC_TODO: add argument description\r
+  ExtendedVerification  - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+  GC_TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+KeyboardReadKeyStroke (\r
+  IN  EFI_SIMPLE_TEXT_INPUT_PROTOCOL  *This,\r
+  OUT EFI_INPUT_KEY                   *Key\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This  - GC_TODO: add argument description\r
+  Key   - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+  GC_TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+VOID\r
+EFIAPI\r
+KeyboardWaitForKey (\r
+  IN  EFI_EVENT               Event,\r
+  IN  VOID                    *Context\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  Event   - GC_TODO: add argument description\r
+  Context - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+  GC_TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+UINT8\r
+KeyReadStatusRegister (\r
+  IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  ConsoleIn - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+  GC_TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+/**\r
+  Check whether there is Ps/2 Keyboard device in system by 0xF4 Keyboard Command\r
+  If Keyboard receives 0xF4, it will respond with 'ACK'. If it doesn't respond, the device\r
+  should not be in system.\r
+\r
+  @param[in]  BiosKeyboardPrivate   Keyboard Private Data Structure\r
+\r
+  @retval              TRUE                                                            Keyboard in System.\r
+  @retval              FALSE                                                           Keyboard not in System.\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+CheckKeyboardConnect (\r
+  IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn\r
+  )\r
+;\r
+#endif\r
diff --git a/IntelFrameworkModulePkg/Bus/Isa/Ps2KeyboardDxe/Ps2keyboard.inf b/IntelFrameworkModulePkg/Bus/Isa/Ps2KeyboardDxe/Ps2keyboard.inf
new file mode 100644 (file)
index 0000000..c669890
--- /dev/null
@@ -0,0 +1,108 @@
+#/** @file\r
+# Ps2 Keyboard Driver\r
+#\r
+# This dirver directly uses IsaIo protocol service to support KeyBoard work.\r
+# Copyright (c) 2006 - 2007, Intel Corporation.\r
+#\r
+#  All rights reserved.\r
+#  This software and associated documentation (if any) is furnished\r
+#  under a license and may only be used or copied in accordance\r
+#  with the terms of the license. Except as permitted by such\r
+#  license, no part of this software or documentation may be\r
+#  reproduced, stored in a retrieval system, or transmitted in any\r
+#  form or by any means without the express written consent of\r
+#  Intel Corporation.\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                      = Ps2Keyboard\r
+  FILE_GUID                      = 3DC82376-637B-40a6-A8FC-A565417F2C38\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  ENTRY_POINT                    = InitializePs2Keyboard\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
+#  DRIVER_BINDING                =  gKeyboardControllerDriver\r
+#  COMPONENT_NAME                =  gPs2KeyboardComponentName\r
+#  Create Event Guid C Name:  Event Type: EVENT_TYPE_RELATIVE_TIMER\r
+#  Create Event Guid C Name:  Event Type: EVENT_TYPE_PERIODIC_TIMER\r
+#\r
+#  Signal Event Guid C Name:  Event Type: EVENT_TYPE_PERIODIC_TIMER\r
+#\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
+  ComponentName.c\r
+  Ps2Keyboard.h\r
+  Ps2KbdCtrller.c\r
+  Ps2KbdTextIn.c\r
+  Ps2Keyboard.c\r
+  CommonHeader.h\r
+  EntryPoint.c\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
+  IntelFrameworkPkg/IntelFrameworkPkg.dec\r
+  IntelFrameworkModulePkg/IntelFrameworkModulePkg.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
+  UefiRuntimeServicesTableLib\r
+  DebugLib\r
+  ReportStatusCodeLib\r
+  UefiBootServicesTableLib\r
+  UefiLib\r
+  UefiDriverEntryPoint\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
+  gEfiPs2PolicyProtocolGuid                     # PROTOCOL TO_START\r
+  gEfiIsaIoProtocolGuid                         # PROTOCOL TO_START\r
+  gEfiSimpleTextInProtocolGuid                  # PROTOCOL BY_START\r
+  gEfiDevicePathProtocolGuid                    # PROTOCOL TO_START\r
+\r
diff --git a/IntelFrameworkModulePkg/Bus/Isa/Ps2KeyboardDxe/Ps2keyboard.msa b/IntelFrameworkModulePkg/Bus/Isa/Ps2KeyboardDxe/Ps2keyboard.msa
new file mode 100644 (file)
index 0000000..ddf62a4
--- /dev/null
@@ -0,0 +1,104 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xsi:schemaLocation="http://www.TianoCore.org/2006/Edk2.0  http://www.TianoCore.org/2006/Edk2.0/SurfaceArea.xsd" xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\r
+  <MsaHeader>\r
+    <ModuleName>Ps2Keyboard</ModuleName>\r
+    <ModuleType>DXE_DRIVER</ModuleType>\r
+    <GuidValue>3DC82376-637B-40a6-A8FC-A565417F2C38</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Ps2 Keyboard Driver</Abstract>\r
+    <Description>This dirver directly uses IsaIo protocol service to support KeyBoard work.</Description>\r
+    <Copyright>Copyright (c) 2006 - 2007, Intel Corporation.</Copyright>\r
+    <License>All rights reserved.
+      This software and associated documentation (if any) is furnished
+      under a license and may only be used or copied in accordance
+      with the terms of the license. Except as permitted by such
+      license, no part of this software or documentation may be
+      reproduced, stored in a retrieval system, or transmitted in any
+      form or by any means without the express written consent of
+      Intel Corporation.</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>Ps2Keyboard</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiDriverModelLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiDriverEntryPoint</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiBootServicesTableLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>ReportStatusCodeLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiRuntimeServicesTableLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>MemoryAllocationLib</Keyword>\r
+    </LibraryClass>    \r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>Ps2Keyboard.c</Filename>\r
+    <Filename>Ps2KbdTextIn.c</Filename>\r
+    <Filename>Ps2KbdCtrller.c</Filename>\r
+    <Filename>Ps2Keyboard.h</Filename>\r
+    <Filename>ComponentName.c</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+    <Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/>\r
+    <Package PackageGuid="bea835f9-fd62-464a-81ff-f3a806360c6b"/>\r
+  </PackageDependencies>\r
+  <Protocols>\r
+    <Protocol Usage="TO_START">\r
+      <ProtocolCName>gEfiDevicePathProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="BY_START">\r
+      <ProtocolCName>gEfiSimpleTextInProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="TO_START">\r
+      <ProtocolCName>gEfiIsaIoProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="TO_START">\r
+      <ProtocolCName>gEfiPs2PolicyProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+  </Protocols>\r
+  <Events>\r
+    <CreateEvents>\r
+      <EventTypes Usage="ALWAYS_PRODUCED">\r
+        <EventType>EVENT_TYPE_RELATIVE_TIMER</EventType>\r
+        <HelpText>Set up  event in order to wait for key stroke</HelpText>\r
+      </EventTypes>\r
+      <EventTypes Usage="ALWAYS_PRODUCED">\r
+        <EventType>EVENT_TYPE_PERIODIC_TIMER</EventType>\r
+        <HelpText>Set up a periodic timer to read key strokes at a fixed interval</HelpText>\r
+      </EventTypes>\r
+    </CreateEvents>\r
+    <SignalEvents>\r
+      <EventTypes Usage="SOMETIMES_PRODUCED">\r
+        <EventType>EVENT_TYPE_PERIODIC_TIMER</EventType>\r
+        <HelpText>Signal an event wheneven there is a key pending</HelpText>\r
+      </EventTypes>\r
+    </SignalEvents>\r
+  </Events>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+    <Extern>\r
+      <DriverBinding>gKeyboardControllerDriver</DriverBinding>\r
+      <ComponentName>gPs2KeyboardComponentName</ComponentName>\r
+    </Extern>\r
+  </Externs>\r
+</ModuleSurfaceArea>
\ No newline at end of file
diff --git a/IntelFrameworkModulePkg/Bus/Isa/Ps2MouseDxe/CommPs2.c b/IntelFrameworkModulePkg/Bus/Isa/Ps2MouseDxe/CommPs2.c
new file mode 100644 (file)
index 0000000..5216504
--- /dev/null
@@ -0,0 +1,1110 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved. <BR> \r
+This software and associated documentation (if any) is furnished\r
+under a license and may only be used or copied in accordance\r
+with the terms of the license. Except as permitted by such\r
+license, no part of this software or documentation may be\r
+reproduced, stored in a retrieval system, or transmitted in any\r
+form or by any means without the express written consent of\r
+Intel Corporation.\r
+\r
+\r
+Module Name:\r
+\r
+  CommPs2.c\r
+    \r
+Abstract:   \r
+\r
+  PS2 Mouse Communication Interface \r
+\r
+\r
+Revision History\r
+\r
+--*/\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+#include "Ps2Mouse.h"\r
+#include "CommPs2.h"\r
+\r
+UINT8 SampleRateTbl[MAX_SR]   = { 0xa, 0x14, 0x28, 0x3c, 0x50, 0x64, 0xc8 };\r
+\r
+UINT8 ResolutionTbl[MAX_CMR]  = { 0, 1, 2, 3 };\r
+\r
+EFI_STATUS\r
+KbcSelfTest (\r
+  IN EFI_ISA_IO_PROTOCOL                  *IsaIo\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  IsaIo - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+  EFI_DEVICE_ERROR - GC_TODO: Add description for return value\r
+  EFI_SUCCESS - GC_TODO: Add description for return value\r
+\r
+--*/\r
+{\r
+  EFI_STATUS  Status;\r
+  UINT8       Data;\r
+\r
+  //\r
+  // Keyboard controller self test\r
+  //\r
+  Status = Out8042Command (IsaIo, SELF_TEST);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  //\r
+  // Read return code\r
+  //\r
+  Status = In8042Data (IsaIo, &Data);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  if (Data != 0x55) {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+  //\r
+  // Set system flag\r
+  //\r
+  Status = Out8042Command (IsaIo, READ_CMD_BYTE);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  Status = In8042Data (IsaIo, &Data);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  Status = Out8042Command (IsaIo, WRITE_CMD_BYTE);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  Data |= CMD_SYS_FLAG;\r
+  Status = Out8042Data (IsaIo, Data);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+KbcEnableAux (\r
+  IN EFI_ISA_IO_PROTOCOL                  *IsaIo\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  IsaIo - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+  GC_TODO: add return values\r
+\r
+--*/\r
+{\r
+  //\r
+  // Send 8042 enable mouse command\r
+  //\r
+  return Out8042Command (IsaIo, ENABLE_AUX);\r
+}\r
+\r
+EFI_STATUS\r
+KbcDisableAux (\r
+  IN EFI_ISA_IO_PROTOCOL                  *IsaIo\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  IsaIo - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+  GC_TODO: add return values\r
+\r
+--*/\r
+{\r
+  //\r
+  // Send 8042 disable mouse command\r
+  //\r
+  return Out8042Command (IsaIo, DISABLE_AUX);\r
+}\r
+\r
+EFI_STATUS\r
+KbcEnableKb (\r
+  IN EFI_ISA_IO_PROTOCOL                  *IsaIo\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  IsaIo - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+  GC_TODO: add return values\r
+\r
+--*/\r
+{\r
+  //\r
+  // Send 8042 enable keyboard command\r
+  //\r
+  return Out8042Command (IsaIo, ENABLE_KB);\r
+}\r
+\r
+EFI_STATUS\r
+KbcDisableKb (\r
+  IN EFI_ISA_IO_PROTOCOL                  *IsaIo\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  IsaIo - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+  GC_TODO: add return values\r
+\r
+--*/\r
+{\r
+  //\r
+  // Send 8042 disable keyboard command\r
+  //\r
+  return Out8042Command (IsaIo, DISABLE_KB);\r
+}\r
+\r
+EFI_STATUS\r
+CheckKbStatus (\r
+  IN EFI_ISA_IO_PROTOCOL                  *IsaIo,\r
+  OUT BOOLEAN                             *KeyboardEnable\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  IsaIo           - GC_TODO: add argument description\r
+  KeyboardEnable  - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS - GC_TODO: Add description for return value\r
+\r
+--*/\r
+{\r
+  EFI_STATUS  Status;\r
+  UINT8       Data;\r
+\r
+  //\r
+  // Send command to read KBC command byte\r
+  //\r
+  Status = Out8042Command (IsaIo, READ_CMD_BYTE);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  Status = In8042Data (IsaIo, &Data);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  //\r
+  // Check keyboard enable or not\r
+  //\r
+  if ((Data & CMD_KB_STS) == CMD_KB_DIS) {\r
+    *KeyboardEnable = FALSE;\r
+  } else {\r
+    *KeyboardEnable = TRUE;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+PS2MouseReset (\r
+  IN EFI_ISA_IO_PROTOCOL                  *IsaIo\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  IsaIo - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+  EFI_DEVICE_ERROR - GC_TODO: Add description for return value\r
+  EFI_DEVICE_ERROR - GC_TODO: Add description for return value\r
+  EFI_SUCCESS - GC_TODO: Add description for return value\r
+\r
+--*/\r
+{\r
+  EFI_STATUS  Status;\r
+  UINT8       Data;\r
+\r
+  Status = Out8042AuxCommand (IsaIo, RESET_CMD, FALSE);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  Status = In8042AuxData (IsaIo, &Data);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  //\r
+  // Check BAT Complete Code\r
+  //\r
+  if (Data != PS2MOUSE_BAT1) {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  Status = In8042AuxData (IsaIo, &Data);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  //\r
+  // Check BAT Complete Code\r
+  //\r
+  if (Data != PS2MOUSE_BAT2) {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+PS2MouseSetSampleRate (\r
+  IN EFI_ISA_IO_PROTOCOL                  *IsaIo,\r
+  IN MOUSE_SR                             SampleRate\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  IsaIo       - GC_TODO: add argument description\r
+  SampleRate  - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+  GC_TODO: add return values\r
+\r
+--*/\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  //\r
+  // Send auxiliary command to set mouse sample rate\r
+  //\r
+  Status = Out8042AuxCommand (IsaIo, SETSR_CMD, FALSE);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  Status = Out8042AuxData (IsaIo, SampleRateTbl[SampleRate]);\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+PS2MouseSetResolution (\r
+  IN EFI_ISA_IO_PROTOCOL                  *IsaIo,\r
+  IN MOUSE_RE                             Resolution\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  IsaIo       - GC_TODO: add argument description\r
+  Resolution  - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+  GC_TODO: add return values\r
+\r
+--*/\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  //\r
+  // Send auxiliary command to set mouse resolution\r
+  //\r
+  Status = Out8042AuxCommand (IsaIo, SETRE_CMD, FALSE);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  Status = Out8042AuxData (IsaIo, ResolutionTbl[Resolution]);\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+PS2MouseSetScaling (\r
+  IN EFI_ISA_IO_PROTOCOL                  *IsaIo,\r
+  IN MOUSE_SF                             Scaling\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  IsaIo   - GC_TODO: add argument description\r
+  Scaling - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+  GC_TODO: add return values\r
+\r
+--*/\r
+{\r
+  UINT8 Command;\r
+\r
+  Command = (UINT8) (Scaling == SF1 ? SETSF1_CMD : SETSF2_CMD);\r
+\r
+  //\r
+  // Send auxiliary command to set mouse scaling data\r
+  //\r
+  return Out8042AuxCommand (IsaIo, Command, FALSE);\r
+}\r
+\r
+EFI_STATUS\r
+PS2MouseEnable (\r
+  IN EFI_ISA_IO_PROTOCOL                  *IsaIo\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  IsaIo - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+  GC_TODO: add return values\r
+\r
+--*/\r
+{\r
+  //\r
+  // Send auxiliary command to enable mouse\r
+  //\r
+  return Out8042AuxCommand (IsaIo, ENABLE_CMD, FALSE);\r
+}\r
+\r
+EFI_STATUS\r
+PS2MouseGetPacket (\r
+  PS2_MOUSE_DEV     *MouseDev\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Get mouse packet . Only care first 3 bytes\r
+\r
+Arguments:\r
+\r
+  MouseDev  - Pointer of PS2 Mouse Private Data Structure \r
+\r
+Returns:\r
+\r
+  EFI_NOT_READY -  Mouse Device not ready to input data packet, or some error happened during getting the packet\r
+  EFI_SUCCESS - The data packet is gotten successfully.\r
+\r
+--*/\r
+{\r
+  EFI_STATUS  Status;\r
+  BOOLEAN     KeyboardEnable;\r
+  UINT8       Packet[PS2_PACKET_LENGTH];\r
+  UINT8       Data;\r
+  UINTN       Count;\r
+  UINTN       State;\r
+  INT16       RelativeMovementX;\r
+  INT16       RelativeMovementY;\r
+  BOOLEAN     LButton;\r
+  BOOLEAN     RButton;\r
+\r
+  KeyboardEnable  = FALSE;\r
+  Count           = 1;\r
+  State           = PS2_READ_BYTE_ONE;\r
+\r
+  //\r
+  // State machine to get mouse packet\r
+  //\r
+  while (1) {\r
+\r
+    switch (State) {\r
+    case PS2_READ_BYTE_ONE:\r
+      //\r
+      // Read mouse first byte data, if failed, immediately return\r
+      //\r
+      KbcDisableAux (MouseDev->IsaIo);\r
+      Status = PS2MouseRead (MouseDev->IsaIo, &Data, &Count, State);\r
+      if (EFI_ERROR (Status)) {\r
+        KbcEnableAux (MouseDev->IsaIo);\r
+        return EFI_NOT_READY;\r
+      }\r
+\r
+      if (Count != 1) {\r
+        KbcEnableAux (MouseDev->IsaIo);\r
+        return EFI_NOT_READY;\r
+      }\r
+\r
+      if (IS_PS2_SYNC_BYTE (Data)) {\r
+        Packet[0] = Data;\r
+        State     = PS2_READ_DATA_BYTE;\r
+\r
+        CheckKbStatus (MouseDev->IsaIo, &KeyboardEnable);\r
+        KbcDisableKb (MouseDev->IsaIo);\r
+        KbcEnableAux (MouseDev->IsaIo);\r
+      }\r
+      break;\r
+\r
+    case PS2_READ_DATA_BYTE:\r
+      Count   = 2;\r
+      Status  = PS2MouseRead (MouseDev->IsaIo, (Packet + 1), &Count, State);\r
+      if (EFI_ERROR (Status)) {\r
+        if (KeyboardEnable) {\r
+          KbcEnableKb (MouseDev->IsaIo);\r
+        }\r
+\r
+        return EFI_NOT_READY;\r
+      }\r
+\r
+      if (Count != 2) {\r
+        if (KeyboardEnable) {\r
+          KbcEnableKb (MouseDev->IsaIo);\r
+        }\r
+\r
+        return EFI_NOT_READY;\r
+      }\r
+\r
+      State = PS2_PROCESS_PACKET;\r
+      break;\r
+\r
+    case PS2_PROCESS_PACKET:\r
+      if (KeyboardEnable) {\r
+        KbcEnableKb (MouseDev->IsaIo);\r
+      }\r
+      //\r
+      // Decode the packet\r
+      //\r
+      RelativeMovementX = Packet[1];\r
+      RelativeMovementY = Packet[2];\r
+      //\r
+      //               Bit 7   |    Bit 6   |    Bit 5   |   Bit 4    |   Bit 3  |   Bit 2    |   Bit 1   |   Bit 0 \r
+      //  Byte 0  | Y overflow | X overflow | Y sign bit | X sign bit | Always 1 | Middle Btn | Right Btn | Left Btn \r
+      //  Byte 1  |                                           8 bit X Movement \r
+      //  Byte 2  |                                           8 bit Y Movement \r
+      // \r
+      // X sign bit + 8 bit X Movement : 9-bit signed twos complement integer that presents the relative displacement of the device in the X direction since the last data transmission.\r
+      // Y sign bit + 8 bit Y Movement : Same as X sign bit + 8 bit X Movement.\r
+      //\r
+      //\r
+      // First, Clear X and Y high 8 bits\r
+      //\r
+      RelativeMovementX = (INT16) (RelativeMovementX & 0xFF); \r
+      RelativeMovementY = (INT16) (RelativeMovementY & 0xFF); \r
+      //\r
+      // Second, if the 9-bit signed twos complement integer is negative, set the high 8 bit 0xff\r
+      //\r
+      if ((Packet[0] & 0x10) != 0) {\r
+        RelativeMovementX = (INT16) (RelativeMovementX | 0xFF00);\r
+      }\r
+      if ((Packet[0] & 0x20) != 0) {\r
+        RelativeMovementY = (INT16) (RelativeMovementY | 0xFF00);\r
+      }\r
+\r
+      \r
+      RButton           = (UINT8) (Packet[0] & 0x2);\r
+      LButton           = (UINT8) (Packet[0] & 0x1);\r
+\r
+      //\r
+      // Update mouse state\r
+      //\r
+      MouseDev->State.RelativeMovementX += RelativeMovementX;\r
+      MouseDev->State.RelativeMovementY -= RelativeMovementY;\r
+      MouseDev->State.RightButton = (UINT8) (RButton ? TRUE : FALSE);\r
+      MouseDev->State.LeftButton  = (UINT8) (LButton ? TRUE : FALSE);\r
+      MouseDev->StateChanged      = TRUE;\r
+\r
+      return EFI_SUCCESS;\r
+    }\r
+  }\r
+}\r
+\r
+EFI_STATUS\r
+PS2MouseRead (\r
+  IN EFI_ISA_IO_PROTOCOL                  *IsaIo,\r
+  OUT VOID                                *Buffer,\r
+  IN OUT UINTN                            *BufSize,\r
+  IN  UINTN                               State\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  IsaIo   - GC_TODO: add argument description\r
+  Buffer  - GC_TODO: add argument description\r
+  BufSize - GC_TODO: add argument description\r
+  State   - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+  GC_TODO: add return values\r
+\r
+--*/\r
+{\r
+  EFI_STATUS  Status;\r
+  UINTN       BytesRead;\r
+\r
+  Status    = EFI_SUCCESS;\r
+  BytesRead = 0;\r
+\r
+  if (State == PS2_READ_BYTE_ONE) {\r
+    //\r
+    // Check input for mouse\r
+    //\r
+    Status = CheckForInput (IsaIo);\r
+\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+  }\r
+\r
+  while (BytesRead < *BufSize) {\r
+\r
+    Status = WaitOutputFull (IsaIo, TIMEOUT);\r
+    if (EFI_ERROR (Status)) {\r
+      break;\r
+    }\r
+\r
+    IsaIo->Io.Read (IsaIo, EfiIsaIoWidthUint8, KBC_DATA_PORT, 1, Buffer);\r
+\r
+    BytesRead++;\r
+    Buffer = (UINT8 *) Buffer + 1;\r
+  }\r
+  //\r
+  // Verify the correct number of bytes read\r
+  //\r
+  if (BytesRead == 0 || BytesRead != *BufSize) {\r
+    Status = EFI_NOT_FOUND;\r
+  }\r
+\r
+  *BufSize = BytesRead;\r
+  return Status;\r
+}\r
+//\r
+// 8042 I/O function\r
+//\r
+EFI_STATUS\r
+Out8042Command (\r
+  IN EFI_ISA_IO_PROTOCOL                  *IsaIo,\r
+  IN UINT8                                Command\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  IsaIo   - GC_TODO: add argument description\r
+  Command - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS - GC_TODO: Add description for return value\r
+\r
+--*/\r
+{\r
+  EFI_STATUS  Status;\r
+  UINT8       Data;\r
+\r
+  //\r
+  // Wait keyboard controller input buffer empty\r
+  //\r
+  Status = WaitInputEmpty (IsaIo, TIMEOUT);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  //\r
+  // Send command\r
+  //\r
+  Data = Command;\r
+  IsaIo->Io.Write (IsaIo, EfiIsaIoWidthUint8, KBC_CMD_STS_PORT, 1, &Data);\r
+\r
+  Status = WaitInputEmpty (IsaIo, TIMEOUT);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+Out8042Data (\r
+  IN EFI_ISA_IO_PROTOCOL                  *IsaIo,\r
+  IN UINT8                                Data\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  IsaIo - GC_TODO: add argument description\r
+  Data  - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS - GC_TODO: Add description for return value\r
+\r
+--*/\r
+{\r
+  EFI_STATUS  Status;\r
+  UINT8       temp;\r
+  //\r
+  // Wait keyboard controller input buffer empty\r
+  //\r
+  Status = WaitInputEmpty (IsaIo, TIMEOUT);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  temp = Data;\r
+  IsaIo->Io.Write (IsaIo, EfiIsaIoWidthUint8, KBC_DATA_PORT, 1, &temp);\r
+\r
+  Status = WaitInputEmpty (IsaIo, TIMEOUT);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+In8042Data (\r
+  IN EFI_ISA_IO_PROTOCOL                  *IsaIo,\r
+  IN OUT UINT8                            *Data\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  IsaIo - GC_TODO: add argument description\r
+  Data  - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+  EFI_TIMEOUT - GC_TODO: Add description for return value\r
+  EFI_SUCCESS - GC_TODO: Add description for return value\r
+\r
+--*/\r
+{\r
+  UINTN Delay;\r
+  UINT8 temp;\r
+\r
+  Delay = TIMEOUT / 50;\r
+\r
+  do {\r
+    IsaIo->Io.Read (IsaIo, EfiIsaIoWidthUint8, KBC_CMD_STS_PORT, 1, &temp);\r
+\r
+    //\r
+    // Check keyboard controller status bit 0(output buffer status)\r
+    //\r
+    if ((temp & KBC_OUTB) == KBC_OUTB) {\r
+      break;\r
+    }\r
+\r
+    gBS->Stall (50);\r
+    Delay--;\r
+  } while (Delay);\r
+\r
+  if (Delay == 0) {\r
+    return EFI_TIMEOUT;\r
+  }\r
+\r
+  IsaIo->Io.Read (IsaIo, EfiIsaIoWidthUint8, KBC_DATA_PORT, 1, Data);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+Out8042AuxCommand (\r
+  IN EFI_ISA_IO_PROTOCOL                  *IsaIo,\r
+  IN UINT8                                Command,\r
+  IN BOOLEAN                              Resend\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  IsaIo   - GC_TODO: add argument description\r
+  Command - GC_TODO: add argument description\r
+  Resend  - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS - GC_TODO: Add description for return value\r
+  EFI_DEVICE_ERROR - GC_TODO: Add description for return value\r
+  EFI_DEVICE_ERROR - GC_TODO: Add description for return value\r
+  EFI_SUCCESS - GC_TODO: Add description for return value\r
+\r
+--*/\r
+{\r
+  EFI_STATUS  Status;\r
+  UINT8       Data;\r
+\r
+  //\r
+  // Wait keyboard controller input buffer empty\r
+  //\r
+  Status = WaitInputEmpty (IsaIo, TIMEOUT);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  //\r
+  // Send write to auxiliary device command\r
+  //\r
+  Data = WRITE_AUX_DEV;\r
+  IsaIo->Io.Write (IsaIo, EfiIsaIoWidthUint8, KBC_CMD_STS_PORT, 1, &Data);\r
+\r
+  Status = WaitInputEmpty (IsaIo, TIMEOUT);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  //\r
+  // Send auxiliary device command\r
+  //\r
+  IsaIo->Io.Write (IsaIo, EfiIsaIoWidthUint8, KBC_DATA_PORT, 1, &Command);\r
+\r
+  //\r
+  // Read return code\r
+  //\r
+  Status = In8042AuxData (IsaIo, &Data);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  if (Data == PS2_ACK) {\r
+    //\r
+    // Receive mouse acknowledge, command send success\r
+    //\r
+    return EFI_SUCCESS;\r
+\r
+  } else if (Resend) {\r
+    //\r
+    // Resend fail\r
+    //\r
+    return EFI_DEVICE_ERROR;\r
+\r
+  } else if (Data == PS2_RESEND) {\r
+    //\r
+    // Resend command\r
+    //\r
+    Status = Out8042AuxCommand (IsaIo, Command, TRUE);\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+\r
+  } else {\r
+    //\r
+    // Invalid return code\r
+    //\r
+    return EFI_DEVICE_ERROR;\r
+\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+Out8042AuxData (\r
+  IN EFI_ISA_IO_PROTOCOL                  *IsaIo,\r
+  IN UINT8                                Data\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  IsaIo - GC_TODO: add argument description\r
+  Data  - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS - GC_TODO: Add description for return value\r
+\r
+--*/\r
+{\r
+  EFI_STATUS  Status;\r
+  UINT8       Temp;\r
+  //\r
+  // Wait keyboard controller input buffer empty\r
+  //\r
+  Status = WaitInputEmpty (IsaIo, TIMEOUT);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  //\r
+  // Send write to auxiliary device command\r
+  //\r
+  Temp = WRITE_AUX_DEV;\r
+  IsaIo->Io.Write (IsaIo, EfiIsaIoWidthUint8, KBC_CMD_STS_PORT, 1, &Temp);\r
+\r
+  Status = WaitInputEmpty (IsaIo, TIMEOUT);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  Temp = Data;\r
+  IsaIo->Io.Write (IsaIo, EfiIsaIoWidthUint8, KBC_DATA_PORT, 1, &Temp);\r
+\r
+  Status = WaitInputEmpty (IsaIo, TIMEOUT);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+In8042AuxData (\r
+  IN EFI_ISA_IO_PROTOCOL                  *IsaIo,\r
+  IN OUT UINT8                            *Data\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  IsaIo - GC_TODO: add argument description\r
+  Data  - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS - GC_TODO: Add description for return value\r
+\r
+--*/\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  //\r
+  // wait for output data\r
+  //\r
+  Status = WaitOutputFull (IsaIo, BAT_TIMEOUT);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  IsaIo->Io.Read (IsaIo, EfiIsaIoWidthUint8, KBC_DATA_PORT, 1, Data);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+CheckForInput (\r
+  IN EFI_ISA_IO_PROTOCOL                  *IsaIo\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  IsaIo - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+  EFI_NOT_READY - GC_TODO: Add description for return value\r
+  EFI_SUCCESS - GC_TODO: Add description for return value\r
+\r
+--*/\r
+{\r
+  UINT8 Data;\r
+\r
+  IsaIo->Io.Read (IsaIo, EfiIsaIoWidthUint8, KBC_CMD_STS_PORT, 1, &Data);\r
+\r
+  //\r
+  // Check keyboard controller status, if it is output buffer full and for auxiliary device\r
+  //\r
+  if ((Data & (KBC_OUTB | KBC_AUXB)) != (KBC_OUTB | KBC_AUXB)) {\r
+    return EFI_NOT_READY;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+WaitInputEmpty (\r
+  IN EFI_ISA_IO_PROTOCOL                  *IsaIo,\r
+  IN UINTN                                Timeout\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  IsaIo   - GC_TODO: add argument description\r
+  Timeout - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+  EFI_TIMEOUT - GC_TODO: Add description for return value\r
+  EFI_SUCCESS - GC_TODO: Add description for return value\r
+\r
+--*/\r
+{\r
+  UINTN Delay;\r
+  UINT8 Data;\r
+\r
+  Delay = Timeout / 50;\r
+\r
+  do {\r
+    IsaIo->Io.Read (IsaIo, EfiIsaIoWidthUint8, KBC_CMD_STS_PORT, 1, &Data);\r
+\r
+    //\r
+    // Check keyboard controller status bit 1(input buffer status)\r
+    //\r
+    if ((Data & KBC_INPB) == 0) {\r
+      break;\r
+    }\r
+\r
+    gBS->Stall (50);\r
+    Delay--;\r
+  } while (Delay);\r
+\r
+  if (Delay == 0) {\r
+    return EFI_TIMEOUT;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+WaitOutputFull (\r
+  IN EFI_ISA_IO_PROTOCOL                  *IsaIo,\r
+  IN UINTN                                Timeout\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  IsaIo   - GC_TODO: add argument description\r
+  Timeout - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+  EFI_TIMEOUT - GC_TODO: Add description for return value\r
+  EFI_SUCCESS - GC_TODO: Add description for return value\r
+\r
+--*/\r
+{\r
+  UINTN Delay;\r
+  UINT8 Data;\r
+\r
+  Delay = Timeout / 50;\r
+\r
+  do {\r
+    IsaIo->Io.Read (IsaIo, EfiIsaIoWidthUint8, KBC_CMD_STS_PORT, 1, &Data);\r
+\r
+    //\r
+    // Check keyboard controller status bit 0(output buffer status)\r
+    //  & bit5(output buffer for auxiliary device)\r
+    //\r
+    if ((Data & (KBC_OUTB | KBC_AUXB)) == (KBC_OUTB | KBC_AUXB)) {\r
+      break;\r
+    }\r
+\r
+    gBS->Stall (50);\r
+    Delay--;\r
+  } while (Delay);\r
+\r
+  if (Delay == 0) {\r
+    return EFI_TIMEOUT;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
diff --git a/IntelFrameworkModulePkg/Bus/Isa/Ps2MouseDxe/CommPs2.h b/IntelFrameworkModulePkg/Bus/Isa/Ps2MouseDxe/CommPs2.h
new file mode 100644 (file)
index 0000000..a997ce6
--- /dev/null
@@ -0,0 +1,445 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved. \r
+This software and associated documentation (if any) is furnished\r
+under a license and may only be used or copied in accordance\r
+with the terms of the license. Except as permitted by such\r
+license, no part of this software or documentation may be\r
+reproduced, stored in a retrieval system, or transmitted in any\r
+form or by any means without the express written consent of\r
+Intel Corporation.\r
+\r
+\r
+Module Name:\r
+\r
+  CommPs2.h\r
+    \r
+Abstract:   \r
+\r
+  PS2 Mouse Communication Interface \r
+\r
+\r
+Revision History\r
+\r
+--*/\r
+\r
+#ifndef _COMMPS2_H_\r
+#define _COMMPS2_H_\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+#define PS2_PACKET_LENGTH       3\r
+#define PS2_SYNC_MASK           0xc\r
+#define PS2_SYNC_BYTE           0x8\r
+\r
+#define IS_PS2_SYNC_BYTE(byte)  ((byte & PS2_SYNC_MASK) == PS2_SYNC_BYTE)\r
+\r
+#define PS2_READ_BYTE_ONE       0\r
+#define PS2_READ_DATA_BYTE      1\r
+#define PS2_PROCESS_PACKET      2\r
+\r
+#define TIMEOUT                 50000\r
+#define BAT_TIMEOUT             500000\r
+\r
+//\r
+// 8042 I/O Port\r
+//\r
+#define KBC_DATA_PORT     0x60\r
+#define KBC_CMD_STS_PORT  0x64\r
+\r
+//\r
+// 8042 Command\r
+//\r
+#define READ_CMD_BYTE   0x20\r
+#define WRITE_CMD_BYTE  0x60\r
+#define DISABLE_AUX     0xa7\r
+#define ENABLE_AUX      0xa8\r
+#define SELF_TEST       0xaa\r
+#define DISABLE_KB      0xad\r
+#define ENABLE_KB       0xae\r
+#define WRITE_AUX_DEV   0xd4\r
+\r
+#define CMD_SYS_FLAG    0x04\r
+#define CMD_KB_STS      0x10\r
+#define CMD_KB_DIS      0x10\r
+#define CMD_KB_EN       0x0\r
+\r
+//\r
+// 8042 Auxiliary Device Command\r
+//\r
+#define SETSF1_CMD  0xe6\r
+#define SETSF2_CMD  0xe7\r
+#define SETRE_CMD   0xe8\r
+#define READ_CMD    0xeb\r
+#define SETRM_CMD   0xf0\r
+#define SETSR_CMD   0xf3\r
+#define ENABLE_CMD  0xf4\r
+#define DISABLE_CMD 0xf5\r
+#define RESET_CMD   0xff\r
+\r
+//\r
+// return code\r
+//\r
+#define PS2_ACK       0xfa\r
+#define PS2_RESEND    0xfe\r
+#define PS2MOUSE_BAT1 0xaa\r
+#define PS2MOUSE_BAT2 0x0\r
+\r
+//\r
+// Keyboard Controller Status\r
+//\r
+#define KBC_PARE  0x80  // Parity Error\r
+#define KBC_TIM   0x40  // General Time Out\r
+#define KBC_AUXB  0x20  // Output buffer for auxiliary device (PS/2):\r
+//    0 - Holds keyboard data\r
+//    1 - Holds data for auxiliary device\r
+//\r
+#define KBC_KEYL  0x10  // Keyboard lock status:\r
+//    0 - keyboard locked\r
+//    1 - keyboard free\r
+//\r
+#define KBC_CD  0x08  // Command/Data:\r
+//    0 - data byte written via port 60h\r
+//    1 - command byte written via port 64h\r
+//\r
+#define KBC_SYSF  0x04  // System Flag:\r
+//    0 - power-on reset\r
+//    1 - self-test successful\r
+//\r
+#define KBC_INPB  0x02  // Input Buffer Status :\r
+//    0 - input buffer empty\r
+//    1 - CPU data in input buffer\r
+//\r
+#define KBC_OUTB  0x01  // Output Buffer Status :\r
+//    0 - output buffer empty\r
+//    1 - keyboard controller data in output buffer\r
+//\r
+EFI_STATUS\r
+KbcSelfTest (\r
+  IN EFI_ISA_IO_PROTOCOL                  *IsaIo\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  IsaIo - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+  GC_TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+KbcEnableAux (\r
+  IN EFI_ISA_IO_PROTOCOL                  *IsaIo\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  IsaIo - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+  GC_TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+KbcDisableAux (\r
+  IN EFI_ISA_IO_PROTOCOL                  *IsaIo\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  IsaIo - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+  GC_TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+KbcEnableKb (\r
+  IN EFI_ISA_IO_PROTOCOL                  *IsaIo\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  IsaIo - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+  GC_TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+KbcDisableKb (\r
+  IN EFI_ISA_IO_PROTOCOL                  *IsaIo\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  IsaIo - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+  GC_TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+CheckKbStatus (\r
+  IN EFI_ISA_IO_PROTOCOL                  *IsaIo,\r
+  OUT BOOLEAN                             *KeyboardEnable\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  IsaIo           - GC_TODO: add argument description\r
+  KeyboardEnable  - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+  GC_TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+PS2MouseReset (\r
+  IN EFI_ISA_IO_PROTOCOL                  *IsaIo\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  IsaIo - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+  GC_TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+PS2MouseSetSampleRate (\r
+  IN EFI_ISA_IO_PROTOCOL                  *IsaIo,\r
+  IN MOUSE_SR                             SampleRate\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  IsaIo       - GC_TODO: add argument description\r
+  SampleRate  - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+  GC_TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+PS2MouseSetResolution (\r
+  IN EFI_ISA_IO_PROTOCOL                  *IsaIo,\r
+  IN MOUSE_RE                             Resolution\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  IsaIo       - GC_TODO: add argument description\r
+  Resolution  - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+  GC_TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+PS2MouseSetScaling (\r
+  IN EFI_ISA_IO_PROTOCOL                  *IsaIo,\r
+  IN MOUSE_SF                             Scaling\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  IsaIo   - GC_TODO: add argument description\r
+  Scaling - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+  GC_TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+PS2MouseEnable (\r
+  IN EFI_ISA_IO_PROTOCOL                  *IsaIo\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  IsaIo - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+  GC_TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+PS2MouseGetPacket (\r
+  PS2_MOUSE_DEV     *MouseDev\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  MouseDev  - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+  GC_TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+PS2MouseRead (\r
+  IN EFI_ISA_IO_PROTOCOL                  *IsaIo,\r
+  OUT VOID                                *Buffer,\r
+  IN OUT UINTN                            *BufSize,\r
+  IN  UINTN                               State\r
+  );\r
+\r
+//\r
+// 8042 I/O function\r
+//\r
+EFI_STATUS\r
+Out8042Command (\r
+  IN EFI_ISA_IO_PROTOCOL                  *IsaIo,\r
+  IN UINT8                                Command\r
+  );\r
+\r
+EFI_STATUS\r
+In8042Data (\r
+  IN EFI_ISA_IO_PROTOCOL                  *IsaIo,\r
+  IN OUT UINT8                            *Data\r
+  );\r
+\r
+EFI_STATUS\r
+Out8042Data (\r
+  IN EFI_ISA_IO_PROTOCOL                  *IsaIo,\r
+  IN UINT8                                Data\r
+  );\r
+\r
+EFI_STATUS\r
+Out8042AuxCommand (\r
+  IN EFI_ISA_IO_PROTOCOL                  *IsaIo,\r
+  IN UINT8                                Command,\r
+  IN BOOLEAN                              Resend\r
+  );\r
+\r
+EFI_STATUS\r
+In8042AuxData (\r
+  IN EFI_ISA_IO_PROTOCOL                  *IsaIo,\r
+  IN OUT UINT8                            *Data\r
+  );\r
+\r
+EFI_STATUS\r
+Out8042AuxData (\r
+  IN EFI_ISA_IO_PROTOCOL                  *IsaIo,\r
+  IN UINT8                                Data\r
+  );\r
+\r
+EFI_STATUS\r
+CheckForInput (\r
+  IN EFI_ISA_IO_PROTOCOL                  *IsaIo\r
+  );\r
+\r
+EFI_STATUS\r
+WaitInputEmpty (\r
+  IN EFI_ISA_IO_PROTOCOL                  *IsaIo,\r
+  IN UINTN                                Timeout\r
+  );\r
+\r
+EFI_STATUS\r
+WaitOutputFull (\r
+  IN EFI_ISA_IO_PROTOCOL                  *IsaIo,\r
+  IN UINTN                                Timeout\r
+  );\r
+\r
+#endif // _COMMPS2_H_\r
diff --git a/IntelFrameworkModulePkg/Bus/Isa/Ps2MouseDxe/CommonHeader.h b/IntelFrameworkModulePkg/Bus/Isa/Ps2MouseDxe/CommonHeader.h
new file mode 100644 (file)
index 0000000..7130d86
--- /dev/null
@@ -0,0 +1,48 @@
+/**@file\r
+  Common header file shared by all source files.\r
+\r
+  This file includes package header files, library classes and protocol, PPI & GUID definitions.\r
+\r
+  Copyright (c) 2006 - 2007, Intel Corporation.\r
+  All rights reserved.\r
+   This software and associated documentation (if any) is furnished\r
+   under a license and may only be used or copied in accordance\r
+   with the terms of the license. Except as permitted by such\r
+   license, no part of this software or documentation may be\r
+   reproduced, stored in a retrieval system, or transmitted in any\r
+   form or by any means without the express written consent of\r
+   Intel Corporation.\r
+**/\r
+\r
+#ifndef __COMMON_HEADER_H_\r
+#define __COMMON_HEADER_H_\r
+\r
+\r
+//\r
+// The package level header files this module uses\r
+//\r
+#include <PiDxe.h>\r
+#include <Framework/StatusCode.h>\r
+//\r
+// The protocols, PPI and GUID defintions for this module\r
+//\r
+#include <Protocol/SimplePointer.h>\r
+#include <Protocol/IsaIo.h>\r
+#include <Protocol/DevicePath.h>\r
+//\r
+// The Library classes this module consumes\r
+//\r
+#include <Library/DebugLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/ReportStatusCodeLib.h>\r
+//\r
+// Driver Binding Externs\r
+//\r
+extern EFI_DRIVER_BINDING_PROTOCOL gPS2MouseDriver;\r
+extern EFI_COMPONENT_NAME_PROTOCOL gPs2MouseComponentName;\r
+\r
+#endif\r
diff --git a/IntelFrameworkModulePkg/Bus/Isa/Ps2MouseDxe/ComponentName.c b/IntelFrameworkModulePkg/Bus/Isa/Ps2MouseDxe/ComponentName.c
new file mode 100644 (file)
index 0000000..bfe500f
--- /dev/null
@@ -0,0 +1,209 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved. <BR> \r
+This software and associated documentation (if any) is furnished\r
+under a license and may only be used or copied in accordance\r
+with the terms of the license. Except as permitted by such\r
+license, no part of this software or documentation may be\r
+reproduced, stored in a retrieval system, or transmitted in any\r
+form or by any means without the express written consent of\r
+Intel Corporation.\r
+\r
+\r
+Module Name:\r
+\r
+  ComponentName.c\r
+\r
+Abstract:\r
+\r
+--*/\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+#include "Ps2Mouse.h"\r
+\r
+//\r
+// EFI Component Name Protocol\r
+//\r
+EFI_COMPONENT_NAME_PROTOCOL     gPs2MouseComponentName = {\r
+  Ps2MouseComponentNameGetDriverName,\r
+  Ps2MouseComponentNameGetControllerName,\r
+  "eng"\r
+};\r
+\r
+static EFI_UNICODE_STRING_TABLE mPs2MouseDriverNameTable[] = {\r
+  {\r
+    "eng",\r
+    L"PS/2 Mouse Driver"\r
+  },\r
+  {\r
+    NULL,\r
+    NULL\r
+  }\r
+};\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+Ps2MouseComponentNameGetDriverName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+  \r
+    Retrieves a Unicode string that is the user readable name of the EFI Driver.\r
+\r
+  Arguments:\r
+  \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
+  \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
+           gPs2MouseComponentName.SupportedLanguages,\r
+           mPs2MouseDriverNameTable,\r
+           DriverName\r
+           );\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+Ps2MouseComponentNameGetControllerName (\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
+  \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
+  \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
+  \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
+  EFI_SIMPLE_POINTER_PROTOCOL                 *SimplePointerProtocol;\r
+  PS2_MOUSE_DEV                               *MouseDev;\r
+  EFI_ISA_IO_PROTOCOL                         *IsaIoProtocol;\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
+  // Check Controller's handle\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiIsaIoProtocolGuid,\r
+                  (VOID **) &IsaIoProtocol,\r
+                  gPS2MouseDriver.DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (!EFI_ERROR (Status)) {\r
+    gBS->CloseProtocol (\r
+           ControllerHandle,\r
+           &gEfiIsaIoProtocolGuid,\r
+           gPS2MouseDriver.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
+                  gPS2MouseDriver.DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  MouseDev = PS2_MOUSE_DEV_FROM_THIS (SimplePointerProtocol);\r
+\r
+  return LookupUnicodeString (\r
+           Language,\r
+           gPs2MouseComponentName.SupportedLanguages,\r
+           MouseDev->ControllerNameTable,\r
+           ControllerName\r
+           );\r
+}\r
diff --git a/IntelFrameworkModulePkg/Bus/Isa/Ps2MouseDxe/EntryPoint.c b/IntelFrameworkModulePkg/Bus/Isa/Ps2MouseDxe/EntryPoint.c
new file mode 100644 (file)
index 0000000..bdac890
--- /dev/null
@@ -0,0 +1,58 @@
+/**@file\r
+  Entry Point Source file.\r
+\r
+  This file contains the user entry point \r
+\r
+  Copyright (c) 2006 - 2007, Intel Corporation.\r
+  All rights reserved.\r
+   This software and associated documentation (if any) is furnished\r
+   under a license and may only be used or copied in accordance\r
+   with the terms of the license. Except as permitted by such\r
+   license, no part of this software or documentation may be\r
+   reproduced, stored in a retrieval system, or transmitted in any\r
+   form or by any means without the express written consent of\r
+   Intel Corporation.\r
+**/\r
+\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+/**\r
+  The user Entry Point for module Ps2Mouse. The user code starts with this function.\r
+\r
+  @param[in] ImageHandle    The firmware allocated handle for the EFI image.  \r
+  @param[in] SystemTable    A pointer to the EFI System Table.\r
+  \r
+  @retval EFI_SUCCESS       The entry point is executed successfully.\r
+  @retval other             Some error occurs when executing this entry point.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InitializePs2Mouse(\r
+  IN EFI_HANDLE           ImageHandle,\r
+  IN EFI_SYSTEM_TABLE     *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+\r
+  //\r
+  // Install driver model protocol(s).\r
+  //\r
+  Status = EfiLibInstallAllDriverProtocols (\r
+             ImageHandle,\r
+             SystemTable,\r
+             &gPS2MouseDriver,\r
+             ImageHandle,\r
+             &gPs2MouseComponentName,\r
+             NULL,\r
+             NULL\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+\r
+  return Status;\r
+}\r
diff --git a/IntelFrameworkModulePkg/Bus/Isa/Ps2MouseDxe/Ps2Mouse.c b/IntelFrameworkModulePkg/Bus/Isa/Ps2MouseDxe/Ps2Mouse.c
new file mode 100644 (file)
index 0000000..45d7a33
--- /dev/null
@@ -0,0 +1,763 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved. <BR>\r
+This software and associated documentation (if any) is furnished\r
+under a license and may only be used or copied in accordance\r
+with the terms of the license. Except as permitted by such\r
+license, no part of this software or documentation may be\r
+reproduced, stored in a retrieval system, or transmitted in any\r
+form or by any means without the express written consent of\r
+Intel Corporation.\r
+\r
+\r
+Module Name:\r
+\r
+  Ps2Mouse.c\r
+\r
+Abstract:\r
+\r
+  PS/2 Mouse driver. Routines that interacts with callers,\r
+  conforming to EFI driver model\r
+\r
+--*/\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+#include "Ps2Mouse.h"\r
+#include "CommPs2.h"\r
+\r
+//\r
+// DriverBinding Protocol Instance\r
+//\r
+EFI_DRIVER_BINDING_PROTOCOL gPS2MouseDriver = {\r
+  PS2MouseDriverSupported,\r
+  PS2MouseDriverStart,\r
+  PS2MouseDriverStop,\r
+  0xa,\r
+  NULL,\r
+  NULL\r
+};\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+PS2MouseDriverSupported (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL    *This,\r
+  IN EFI_HANDLE                     Controller,\r
+  IN EFI_DEVICE_PATH_PROTOCOL       *RemainingDevicePath\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  ControllerDriver Protocol Method\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+--*/\r
+// GC_TODO:    This - add argument and description to function comment\r
+// GC_TODO:    Controller - add argument and description to function comment\r
+// GC_TODO:    RemainingDevicePath - add argument and description to function comment\r
+{\r
+  EFI_STATUS                          Status;\r
+  EFI_ISA_IO_PROTOCOL                 *IsaIo;\r
+\r
+  Status = EFI_SUCCESS;\r
+\r
+  //\r
+  // Open the IO Abstraction(s) needed to perform the supported test\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  Controller,\r
+                  &gEfiIsaIoProtocolGuid,\r
+                  (VOID **) &IsaIo,\r
+                  This->DriverBindingHandle,\r
+                  Controller,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  //\r
+  // Use the ISA I/O Protocol to see if Controller is the Keyboard controller\r
+  //\r
+  switch (IsaIo->ResourceList->Device.HID) {\r
+  case EISA_PNP_ID (0xF03):\r
+  //\r
+  // Microsoft PS/2 style mouse\r
+  //\r
+  case EISA_PNP_ID (0xF13):\r
+    //\r
+    // PS/2 Port for PS/2-style Mice\r
+    //\r
+    break;\r
+\r
+  case EISA_PNP_ID (0x303):\r
+    //\r
+    // IBM Enhanced (101/102-key, PS/2 mouse support)\r
+    //\r
+    if (IsaIo->ResourceList->Device.UID == 1) {\r
+      break;\r
+    }\r
+\r
+  default:\r
+    Status = EFI_UNSUPPORTED;\r
+    break;\r
+  }\r
+  //\r
+  // Close the I/O Abstraction(s) used to perform the supported test\r
+  //\r
+  gBS->CloseProtocol (\r
+         Controller,\r
+         &gEfiIsaIoProtocolGuid,\r
+         This->DriverBindingHandle,\r
+         Controller\r
+         );\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+PS2MouseDriverStart (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL    *This,\r
+  IN EFI_HANDLE                     Controller,\r
+  IN EFI_DEVICE_PATH_PROTOCOL       *RemainingDevicePath\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+    Start protocol interfaces for the mouse device handles.\r
+\r
+Arguments:\r
+    This                               - Protocol instance pointer.\r
+    Controller                      - Handle of device to bind driver to.\r
+    RemainingDevicePath  - Not used.\r
+\r
+Returns:\r
+    EFI_SUCCESS             - This driver is added to DeviceHandle.\r
+    other                               - Errors occurred.\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                          Status;\r
+  EFI_STATUS                          EmptyStatus;\r
+  EFI_ISA_IO_PROTOCOL                 *IsaIo;\r
+  PS2_MOUSE_DEV                       *MouseDev;\r
+  UINT8                               Data;\r
+  EFI_TPL                             OldTpl;\r
+  EFI_STATUS_CODE_VALUE               StatusCode;\r
+  EFI_DEVICE_PATH_PROTOCOL            *ParentDevicePath;\r
+\r
+  StatusCode  = 0;\r
+  MouseDev    = NULL;\r
+  IsaIo       = NULL;\r
+\r
+  //\r
+  // Open the device path protocol\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  Controller,\r
+                  &gEfiDevicePathProtocolGuid,\r
+                  (VOID **) &ParentDevicePath,\r
+                  This->DriverBindingHandle,\r
+                  Controller,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  //\r
+  // Report that the keyboard is being enabled\r
+  //\r
+  REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
+    EFI_PROGRESS_CODE,\r
+    EFI_PERIPHERAL_MOUSE | EFI_P_PC_ENABLE,\r
+    ParentDevicePath\r
+    );\r
+\r
+  //\r
+  // Get the ISA I/O Protocol on Controller's handle\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  Controller,\r
+                  &gEfiIsaIoProtocolGuid,\r
+                  (VOID **) &IsaIo,\r
+                  This->DriverBindingHandle,\r
+                  Controller,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    gBS->CloseProtocol (\r
+           Controller,\r
+           &gEfiDevicePathProtocolGuid,\r
+           This->DriverBindingHandle,\r
+           Controller\r
+           );\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  //\r
+  // Raise TPL to avoid keyboard operation impact\r
+  //\r
+  OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
+\r
+  //\r
+  // Allocate private data\r
+  //\r
+  MouseDev = AllocateZeroPool (sizeof (PS2_MOUSE_DEV));\r
+  if (MouseDev == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    goto ErrorExit;\r
+  }\r
+  //\r
+  // Setup the device instance\r
+  //\r
+  MouseDev->Signature       = PS2_MOUSE_DEV_SIGNATURE;\r
+  MouseDev->Handle          = Controller;\r
+  MouseDev->SampleRate      = SSR_20;\r
+  MouseDev->Resolution      = CMR4;\r
+  MouseDev->Scaling         = SF1;\r
+  MouseDev->DataPackageSize = 3;\r
+  MouseDev->IsaIo           = IsaIo;\r
+  MouseDev->DevicePath      = ParentDevicePath;\r
+\r
+  //\r
+  // Resolution = 4 counts/mm\r
+  //\r
+  MouseDev->Mode.ResolutionX                = 4;\r
+  MouseDev->Mode.ResolutionY                = 4;\r
+  MouseDev->Mode.LeftButton                 = TRUE;\r
+  MouseDev->Mode.RightButton                = TRUE;\r
+\r
+  MouseDev->SimplePointerProtocol.Reset     = MouseReset;\r
+  MouseDev->SimplePointerProtocol.GetState  = MouseGetState;\r
+  MouseDev->SimplePointerProtocol.Mode      = &(MouseDev->Mode);\r
+\r
+  //\r
+  // Initialize keyboard controller if necessary\r
+  //\r
+  IsaIo->Io.Read (IsaIo, EfiIsaIoWidthUint8, KBC_CMD_STS_PORT, 1, &Data);\r
+  if ((Data & KBC_SYSF) != KBC_SYSF) {\r
+    Status = KbcSelfTest (IsaIo);\r
+    if (EFI_ERROR (Status)) {\r
+      StatusCode = EFI_PERIPHERAL_MOUSE | EFI_P_EC_CONTROLLER_ERROR;\r
+      goto ErrorExit;\r
+    }\r
+  }\r
+\r
+  KbcEnableAux (IsaIo);\r
+\r
+  REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
+    EFI_PROGRESS_CODE,\r
+    EFI_PERIPHERAL_MOUSE | EFI_P_PC_PRESENCE_DETECT,\r
+    ParentDevicePath\r
+    );\r
+\r
+  //\r
+  // Reset the mouse\r
+  //\r
+  Status = MouseDev->SimplePointerProtocol.Reset (&MouseDev->SimplePointerProtocol, TRUE);\r
+  if (EFI_ERROR (Status)) {\r
+    //\r
+    // mouse not connected\r
+    //\r
+    Status      = EFI_SUCCESS;\r
+    StatusCode  = EFI_PERIPHERAL_MOUSE | EFI_P_EC_NOT_DETECTED;\r
+    goto ErrorExit;\r
+  }\r
+  //\r
+  // Setup the WaitForKey event\r
+  //\r
+  Status = gBS->CreateEvent (\r
+                  EVT_NOTIFY_WAIT,\r
+                  TPL_NOTIFY,\r
+                  MouseWaitForInput,\r
+                  MouseDev,\r
+                  &((MouseDev->SimplePointerProtocol).WaitForInput)\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    goto ErrorExit;\r
+  }\r
+  //\r
+  // Setup a periodic timer, used to poll mouse state\r
+  //\r
+  Status = gBS->CreateEvent (\r
+                  EVT_TIMER | EVT_NOTIFY_SIGNAL,\r
+                  TPL_NOTIFY,\r
+                  PollMouse,\r
+                  MouseDev,\r
+                  &MouseDev->TimerEvent\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    goto ErrorExit;\r
+  }\r
+  //\r
+  // Start timer to poll mouse (100 samples per second)\r
+  //\r
+  Status = gBS->SetTimer (MouseDev->TimerEvent, TimerPeriodic, 100000);\r
+  if (EFI_ERROR (Status)) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    goto ErrorExit;\r
+  }\r
+\r
+  MouseDev->ControllerNameTable = NULL;\r
+  AddUnicodeString (\r
+    "eng",\r
+    gPs2MouseComponentName.SupportedLanguages,\r
+    &MouseDev->ControllerNameTable,\r
+    L"PS/2 Mouse Device"\r
+    );\r
+\r
+  //\r
+  // Install protocol interfaces for the mouse device.\r
+  //\r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &Controller,\r
+                  &gEfiSimplePointerProtocolGuid,\r
+                  &MouseDev->SimplePointerProtocol,\r
+                  NULL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    goto ErrorExit;\r
+  }\r
+\r
+  gBS->RestoreTPL (OldTpl);\r
+\r
+  return Status;\r
+\r
+ErrorExit:\r
+\r
+  KbcDisableAux (IsaIo);\r
+\r
+  if (StatusCode != 0) {\r
+    REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
+      EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
+      StatusCode,\r
+      ParentDevicePath\r
+      );\r
+  }\r
+\r
+  if ((MouseDev != NULL) && (MouseDev->SimplePointerProtocol.WaitForInput != NULL)) {\r
+    gBS->CloseEvent (MouseDev->SimplePointerProtocol.WaitForInput);\r
+  }\r
+\r
+  if ((MouseDev != NULL) && (MouseDev->TimerEvent != NULL)) {\r
+    gBS->CloseEvent (MouseDev->TimerEvent);\r
+  }\r
+\r
+  if ((MouseDev != NULL) && (MouseDev->ControllerNameTable != NULL)) {\r
+    FreeUnicodeStringTable (MouseDev->ControllerNameTable);\r
+  }\r
+  //\r
+  // Since there will be no timer handler for mouse input any more,\r
+  // exhaust input data just in case there is still mouse data left\r
+  //\r
+  EmptyStatus = EFI_SUCCESS;\r
+  while (!EFI_ERROR (EmptyStatus)) {\r
+    EmptyStatus = In8042Data (IsaIo, &Data);\r
+  }\r
+\r
+  if (MouseDev != NULL) {\r
+    gBS->FreePool (MouseDev);\r
+  }\r
+\r
+  gBS->CloseProtocol (\r
+         Controller,\r
+         &gEfiDevicePathProtocolGuid,\r
+         This->DriverBindingHandle,\r
+         Controller\r
+         );\r
+\r
+  gBS->CloseProtocol (\r
+         Controller,\r
+         &gEfiIsaIoProtocolGuid,\r
+         This->DriverBindingHandle,\r
+         Controller\r
+         );\r
+\r
+  gBS->RestoreTPL (OldTpl);\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+PS2MouseDriverStop (\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
+  Routine Description:\r
+\r
+  Arguments:\r
+\r
+  Returns:\r
+\r
+--*/\r
+// GC_TODO:    This - add argument and description to function comment\r
+// GC_TODO:    Controller - add argument and description to function comment\r
+// GC_TODO:    NumberOfChildren - add argument and description to function comment\r
+// GC_TODO:    ChildHandleBuffer - add argument and description to function comment\r
+// GC_TODO:    EFI_SUCCESS - add return value to function comment\r
+// GC_TODO:    EFI_SUCCESS - add return value to function comment\r
+{\r
+  EFI_STATUS                  Status;\r
+  EFI_SIMPLE_POINTER_PROTOCOL *SimplePointerProtocol;\r
+  PS2_MOUSE_DEV               *MouseDev;\r
+  UINT8                       Data;\r
+\r
+  Status = gBS->OpenProtocol (\r
+                  Controller,\r
+                  &gEfiSimplePointerProtocolGuid,\r
+                  (VOID **) &SimplePointerProtocol,\r
+                  This->DriverBindingHandle,\r
+                  Controller,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  MouseDev = PS2_MOUSE_DEV_FROM_THIS (SimplePointerProtocol);\r
+\r
+  //\r
+  // Report that the keyboard is being disabled\r
+  //\r
+  REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
+    EFI_PROGRESS_CODE,\r
+    EFI_PERIPHERAL_MOUSE | EFI_P_PC_DISABLE,\r
+    MouseDev->DevicePath\r
+    );\r
+\r
+  Status = gBS->UninstallProtocolInterface (\r
+                  Controller,\r
+                  &gEfiSimplePointerProtocolGuid,\r
+                  &MouseDev->SimplePointerProtocol\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  //\r
+  // Disable mouse on keyboard controller\r
+  //\r
+  KbcDisableAux (MouseDev->IsaIo);\r
+\r
+  //\r
+  // Cancel mouse data polling timer, close timer event\r
+  //\r
+  gBS->SetTimer (MouseDev->TimerEvent, TimerCancel, 0);\r
+  gBS->CloseEvent (MouseDev->TimerEvent);\r
+\r
+  //\r
+  // Since there will be no timer handler for mouse input any more,\r
+  // exhaust input data just in case there is still mouse data left\r
+  //\r
+  Status = EFI_SUCCESS;\r
+  while (!EFI_ERROR (Status)) {\r
+    Status = In8042Data (MouseDev->IsaIo, &Data);\r
+  }\r
+\r
+  gBS->CloseEvent (MouseDev->SimplePointerProtocol.WaitForInput);\r
+  FreeUnicodeStringTable (MouseDev->ControllerNameTable);\r
+  gBS->FreePool (MouseDev);\r
+\r
+  gBS->CloseProtocol (\r
+         Controller,\r
+         &gEfiDevicePathProtocolGuid,\r
+         This->DriverBindingHandle,\r
+         Controller\r
+         );\r
+\r
+  gBS->CloseProtocol (\r
+         Controller,\r
+         &gEfiIsaIoProtocolGuid,\r
+         This->DriverBindingHandle,\r
+         Controller\r
+         );\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+MouseReset (\r
+  IN EFI_SIMPLE_POINTER_PROTOCOL    *This,\r
+  IN BOOLEAN                        ExtendedVerification\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Reset the Mouse and do BAT test for it, if ExtendedVerification isTRUE and there is a mouse device connectted to system\r
+\r
+Arguments:\r
+\r
+  This                 - Pointer of simple pointer Protocol.\r
+  ExtendedVerification - Whether configure mouse parameters. True: do; FALSE: skip.\r
+\r
+Returns:\r
+\r
+ EFI_SUCCESS         - The command byte is written successfully.\r
+ EFI_DEVICE_ERROR    - Errors occurred during reseting keyboard.\r
+\r
+--*/\r
+{\r
+  EFI_STATUS    Status;\r
+  PS2_MOUSE_DEV *MouseDev;\r
+  EFI_TPL       OldTpl;\r
+  BOOLEAN       KeyboardEnable;\r
+  UINT8         Data;\r
+\r
+  MouseDev = PS2_MOUSE_DEV_FROM_THIS (This);\r
+\r
+  //\r
+  // Report reset progress code\r
+  //\r
+  REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
+    EFI_PROGRESS_CODE,\r
+    EFI_PERIPHERAL_MOUSE | EFI_P_PC_RESET,\r
+    MouseDev->DevicePath\r
+    );\r
+\r
+  KeyboardEnable = FALSE;\r
+\r
+  //\r
+  // Raise TPL to avoid keyboard operation impact\r
+  //\r
+  OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
+\r
+  ZeroMem (&MouseDev->State, sizeof (EFI_SIMPLE_POINTER_STATE));\r
+  MouseDev->StateChanged = FALSE;\r
+\r
+  //\r
+  // Exhaust input data\r
+  //\r
+  Status = EFI_SUCCESS;\r
+  while (!EFI_ERROR (Status)) {\r
+    Status = In8042Data (MouseDev->IsaIo, &Data);\r
+  }\r
+\r
+  CheckKbStatus (MouseDev->IsaIo, &KeyboardEnable);\r
+\r
+  KbcDisableKb (MouseDev->IsaIo);\r
+\r
+  MouseDev->IsaIo->Io.Read (MouseDev->IsaIo, EfiIsaIoWidthUint8, KBC_CMD_STS_PORT, 1, &Data);\r
+\r
+  //\r
+  // if there's data block on KBC data port, read it out\r
+  //\r
+  if ((Data & KBC_OUTB) == KBC_OUTB) {\r
+    MouseDev->IsaIo->Io.Read (MouseDev->IsaIo, EfiIsaIoWidthUint8, KBC_DATA_PORT, 1, &Data);\r
+  }\r
+\r
+  Status = EFI_SUCCESS;\r
+  //\r
+  // The PS2 mouse driver reset behavior is always successfully return no matter wheater or not there is mouse connected to system.\r
+  // This behavior is needed by performance speed. The following mouse command only succeessfully finish when mouse device is\r
+  // connected to system, so if PS2 mouse device not connect to system or user not ask for, we skip the mouse configuration and enabling\r
+  //\r
+  if (ExtendedVerification && CheckMouseConnect (MouseDev)) {\r
+    //\r
+    // Send mouse reset command and set mouse default configure\r
+    //\r
+    Status = PS2MouseReset (MouseDev->IsaIo);\r
+    if (EFI_ERROR (Status)) {\r
+      Status = EFI_DEVICE_ERROR;\r
+      goto Exit;\r
+    }\r
+\r
+    Status = PS2MouseSetSampleRate (MouseDev->IsaIo, MouseDev->SampleRate);\r
+    if (EFI_ERROR (Status)) {\r
+      Status = EFI_DEVICE_ERROR;\r
+      goto Exit;\r
+    }\r
+\r
+    Status = PS2MouseSetResolution (MouseDev->IsaIo, MouseDev->Resolution);\r
+    if (EFI_ERROR (Status)) {\r
+      Status = EFI_DEVICE_ERROR;\r
+      goto Exit;\r
+    }\r
+\r
+    Status = PS2MouseSetScaling (MouseDev->IsaIo, MouseDev->Scaling);\r
+    if (EFI_ERROR (Status)) {\r
+      Status = EFI_DEVICE_ERROR;\r
+      goto Exit;\r
+    }\r
+\r
+    Status = PS2MouseEnable (MouseDev->IsaIo);\r
+    if (EFI_ERROR (Status)) {\r
+      Status = EFI_DEVICE_ERROR;\r
+      goto Exit;\r
+    }\r
+  }\r
+Exit:\r
+  gBS->RestoreTPL (OldTpl);\r
+\r
+  if (KeyboardEnable) {\r
+    KbcEnableKb (MouseDev->IsaIo);\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+BOOLEAN\r
+CheckMouseConnect (\r
+  IN  PS2_MOUSE_DEV     *MouseDev\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Check whether there is Ps/2 mouse device in system\r
+\r
+Arguments:\r
+\r
+  PS2_MOUSE_DEV - Mouse Private Data Structure\r
+\r
+Returns:\r
+\r
+  TRUE                - Keyboard in System.\r
+  FALSE               - Keyboard not in System.\r
+\r
+--*/\r
+{\r
+  EFI_STATUS     Status;\r
+\r
+  Status = PS2MouseEnable (MouseDev->IsaIo);\r
+  if (!EFI_ERROR (Status)) {\r
+    return TRUE;\r
+  }\r
+\r
+  return FALSE;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+MouseGetState (\r
+  IN EFI_SIMPLE_POINTER_PROTOCOL    *This,\r
+  IN OUT EFI_SIMPLE_POINTER_STATE   *State\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This  - GC_TODO: add argument description\r
+  State - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+  EFI_INVALID_PARAMETER - GC_TODO: Add description for return value\r
+  EFI_NOT_READY - GC_TODO: Add description for return value\r
+  EFI_SUCCESS - GC_TODO: Add description for return value\r
+\r
+--*/\r
+{\r
+  PS2_MOUSE_DEV *MouseDev;\r
+  EFI_TPL       OldTpl;\r
+\r
+  MouseDev = PS2_MOUSE_DEV_FROM_THIS (This);\r
+\r
+  if (State == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (!MouseDev->StateChanged) {\r
+    return EFI_NOT_READY;\r
+  }\r
+\r
+  OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
+  CopyMem (State, &(MouseDev->State), sizeof (EFI_SIMPLE_POINTER_STATE));\r
+\r
+  //\r
+  // clear mouse state\r
+  //\r
+  MouseDev->State.RelativeMovementX = 0;\r
+  MouseDev->State.RelativeMovementY = 0;\r
+  MouseDev->State.RelativeMovementZ = 0;\r
+  MouseDev->StateChanged            = FALSE;\r
+  gBS->RestoreTPL (OldTpl);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+MouseWaitForInput (\r
+  IN  EFI_EVENT               Event,\r
+  IN  VOID                    *Context\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Event notification function for SIMPLE_POINTER.WaitForInput event\r
+  Signal the event if there is input from mouse\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+--*/\r
+// GC_TODO:    Event - add argument and description to function comment\r
+// GC_TODO:    Context - add argument and description to function comment\r
+{\r
+  PS2_MOUSE_DEV *MouseDev;\r
+\r
+  MouseDev = (PS2_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 (MouseDev->StateChanged) {\r
+    gBS->SignalEvent (Event);\r
+  }\r
+\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+PollMouse (\r
+  IN EFI_EVENT  Event,\r
+  IN VOID       *Context\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Event notification function for TimerEvent event\r
+  If mouse device is connected to system, try to get the mouse packet data\r
+\r
+Arguments:\r
+\r
+  Event      -  TimerEvent in PS2_MOUSE_DEV\r
+  Context  -  Pointer to PS2_MOUSE_DEV structure\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+{\r
+  PS2_MOUSE_DEV *MouseDev;\r
+\r
+  MouseDev = (PS2_MOUSE_DEV *) Context;\r
+\r
+  //\r
+  // Polling mouse packet data\r
+  //\r
+  PS2MouseGetPacket (MouseDev);\r
+}\r
diff --git a/IntelFrameworkModulePkg/Bus/Isa/Ps2MouseDxe/Ps2Mouse.h b/IntelFrameworkModulePkg/Bus/Isa/Ps2MouseDxe/Ps2Mouse.h
new file mode 100644 (file)
index 0000000..bda92e5
--- /dev/null
@@ -0,0 +1,191 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved. \r
+This software and associated documentation (if any) is furnished\r
+under a license and may only be used or copied in accordance\r
+with the terms of the license. Except as permitted by such\r
+license, no part of this software or documentation may be\r
+reproduced, stored in a retrieval system, or transmitted in any\r
+form or by any means without the express written consent of\r
+Intel Corporation.\r
+\r
+\r
+Module Name:\r
+\r
+  Ps2Mouse.h\r
+\r
+Abstract:\r
+\r
+  PS/2 Mouse driver header file\r
+\r
+Revision History\r
+\r
+--*/\r
+\r
+#ifndef _PS2MOUSE_H\r
+#define _PS2MOUSE_H\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+//\r
+// PS/2 mouse sample rate\r
+//\r
+typedef enum {\r
+  SSR_10,\r
+  SSR_20,\r
+  SSR_40,\r
+  SSR_60,\r
+  SSR_80,\r
+  SSR_100,\r
+  SSR_200,\r
+  MAX_SR\r
+} MOUSE_SR;\r
+\r
+//\r
+// PS/2 mouse resolution\r
+//\r
+typedef enum {\r
+  CMR1,\r
+  CMR2,\r
+  CMR4,\r
+  CMR8,\r
+  MAX_CMR\r
+} MOUSE_RE;\r
+\r
+//\r
+// PS/2 mouse scaling\r
+//\r
+typedef enum {\r
+  SF1,\r
+  SF2\r
+} MOUSE_SF;\r
+\r
+//\r
+// Driver Private Data\r
+//\r
+#define PS2_MOUSE_DEV_SIGNATURE EFI_SIGNATURE_32 ('p', 's', '2', 'm')\r
+\r
+typedef struct {\r
+  UINTN                               Signature;\r
+\r
+  EFI_HANDLE                          Handle;\r
+  EFI_SIMPLE_POINTER_PROTOCOL         SimplePointerProtocol;\r
+  EFI_SIMPLE_POINTER_STATE            State;\r
+  EFI_SIMPLE_POINTER_MODE             Mode;\r
+  BOOLEAN                             StateChanged;\r
+\r
+  //\r
+  // PS2 Mouse device specific information\r
+  //\r
+  MOUSE_SR                            SampleRate;\r
+  MOUSE_RE                            Resolution;\r
+  MOUSE_SF                            Scaling;\r
+  UINT8                               DataPackageSize;\r
+\r
+  EFI_ISA_IO_PROTOCOL                 *IsaIo;\r
+\r
+  EFI_EVENT                           TimerEvent;\r
+\r
+  EFI_UNICODE_STRING_TABLE            *ControllerNameTable;\r
+  EFI_DEVICE_PATH_PROTOCOL            *DevicePath;\r
+} PS2_MOUSE_DEV;\r
+\r
+#define PS2_MOUSE_DEV_FROM_THIS(a)  CR (a, PS2_MOUSE_DEV, SimplePointerProtocol, PS2_MOUSE_DEV_SIGNATURE)\r
+\r
+//\r
+// Global Variables\r
+//\r
+extern EFI_DRIVER_BINDING_PROTOCOL  gPS2MouseDriver;\r
+extern EFI_COMPONENT_NAME_PROTOCOL  gPs2MouseComponentName;\r
+\r
+//\r
+// Function prototypes\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+PS2MouseDriverSupported (\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
+PS2MouseDriverStart (\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
+PS2MouseDriverStop (\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
+// EFI Component Name Functions\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+Ps2MouseComponentNameGetDriverName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+Ps2MouseComponentNameGetControllerName (\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
+EFI_STATUS\r
+EFIAPI\r
+MouseReset (\r
+  IN EFI_SIMPLE_POINTER_PROTOCOL    *This,\r
+  IN BOOLEAN                        ExtendedVerification\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+MouseGetState (\r
+  IN EFI_SIMPLE_POINTER_PROTOCOL    *This,\r
+  IN OUT EFI_SIMPLE_POINTER_STATE   *State\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+MouseWaitForInput (\r
+  IN  EFI_EVENT               Event,\r
+  IN  VOID                    *Context\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+PollMouse (\r
+  IN EFI_EVENT  Event,\r
+  IN VOID       *Context\r
+  );\r
+\r
+EFI_STATUS\r
+In8042Data (\r
+  IN EFI_ISA_IO_PROTOCOL                  *IsaIo,\r
+  IN OUT UINT8                            *Data\r
+  );\r
+BOOLEAN\r
+CheckMouseConnect (\r
+  IN  PS2_MOUSE_DEV     *MouseDev\r
+  );\r
+\r
+#endif\r
diff --git a/IntelFrameworkModulePkg/Bus/Isa/Ps2MouseDxe/Ps2Mouse.inf b/IntelFrameworkModulePkg/Bus/Isa/Ps2MouseDxe/Ps2Mouse.inf
new file mode 100644 (file)
index 0000000..575e91b
--- /dev/null
@@ -0,0 +1,107 @@
+#/** @file\r
+# Ps2 Mouse Driver\r
+#\r
+# This dirver directly uses IsaIo protocol service to support Ps2 mouse work.\r
+# Copyright (c) 2006 - 2007, Intel Corporation.\r
+#\r
+#  All rights reserved.\r
+#  This software and associated documentation (if any) is furnished\r
+#  under a license and may only be used or copied in accordance\r
+#  with the terms of the license. Except as permitted by such\r
+#  license, no part of this software or documentation may be\r
+#  reproduced, stored in a retrieval system, or transmitted in any\r
+#  form or by any means without the express written consent of\r
+#  Intel Corporation.\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                      = Ps2Mouse\r
+  FILE_GUID                      = 202A2B0E-9A31-4812-B291-8747DF152439\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  ENTRY_POINT                    = InitializePs2Mouse\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
+#  DRIVER_BINDING                =  gPS2MouseDriver\r
+#  COMPONENT_NAME                =  gPs2MouseComponentName\r
+#  Create Event Guid C Name:  Event Type: EVENT_TYPE_RELATIVE_TIMER\r
+#  Create Event Guid C Name:  Event Type: EVENT_TYPE_PERIODIC_TIMER\r
+#\r
+#  Signal Event Guid C Name:  Event Type: EVENT_TYPE_RELATIVE_TIMER\r
+#\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
+  ComponentName.c\r
+  CommPs2.h\r
+  CommPs2.c\r
+  Ps2Mouse.h\r
+  Ps2Mouse.c\r
+  CommonHeader.h\r
+  EntryPoint.c\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
+  IntelFrameworkPkg/IntelFrameworkPkg.dec\r
+  IntelFrameworkModulePkg/IntelFrameworkModulePkg.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
+  ReportStatusCodeLib\r
+  UefiBootServicesTableLib\r
+  MemoryAllocationLib\r
+  BaseMemoryLib\r
+  UefiLib\r
+  UefiDriverEntryPoint\r
+  DebugLib\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
+  gEfiIsaIoProtocolGuid                         # PROTOCOL TO_START\r
+  gEfiSimplePointerProtocolGuid                 # PROTOCOL BY_START\r
+  gEfiDevicePathProtocolGuid                    # PROTOCOL TO_START\r
+\r
diff --git a/IntelFrameworkModulePkg/Bus/Isa/Ps2MouseDxe/Ps2Mouse.msa b/IntelFrameworkModulePkg/Bus/Isa/Ps2MouseDxe/Ps2Mouse.msa
new file mode 100644 (file)
index 0000000..e79128d
--- /dev/null
@@ -0,0 +1,100 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xsi:schemaLocation="http://www.TianoCore.org/2006/Edk2.0  http://www.TianoCore.org/2006/Edk2.0/SurfaceArea.xsd" xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\r
+  <MsaHeader>\r
+    <ModuleName>Ps2Mouse</ModuleName>\r
+    <ModuleType>DXE_DRIVER</ModuleType>\r
+    <GuidValue>202A2B0E-9A31-4812-B291-8747DF152439</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Ps2 Mouse Driver</Abstract>\r
+    <Description>This dirver directly uses IsaIo protocol service to support Ps2 mouse work.</Description>\r
+    <Copyright>Copyright (c) 2006 - 2007, Intel Corporation.</Copyright>\r
+    <License>All rights reserved.
+      This software and associated documentation (if any) is furnished
+      under a license and may only be used or copied in accordance
+      with the terms of the license. Except as permitted by such
+      license, no part of this software or documentation may be
+      reproduced, stored in a retrieval system, or transmitted in any
+      form or by any means without the express written consent of
+      Intel Corporation.</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>Ps2Mouse</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiDriverModelLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiDriverEntryPoint</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseMemoryLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>MemoryAllocationLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiBootServicesTableLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>ReportStatusCodeLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>Ps2Mouse.c</Filename>\r
+    <Filename>Ps2Mouse.h</Filename>\r
+    <Filename>CommPs2.c</Filename>\r
+    <Filename>CommPs2.h</Filename>\r
+    <Filename>ComponentName.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="TO_START">\r
+      <ProtocolCName>gEfiDevicePathProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="BY_START">\r
+      <ProtocolCName>gEfiSimplePointerProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="TO_START">\r
+      <ProtocolCName>gEfiIsaIoProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+  </Protocols>\r
+  <Events>\r
+    <CreateEvents>\r
+      <EventTypes Usage="ALWAYS_PRODUCED">\r
+        <EventType>EVENT_TYPE_RELATIVE_TIMER</EventType>\r
+        <HelpText>Set up a time event to wait for the mouse input</HelpText>\r
+      </EventTypes>\r
+      <EventTypes Usage="ALWAYS_PRODUCED">\r
+        <EventType>EVENT_TYPE_PERIODIC_TIMER</EventType>\r
+        <HelpText>Set up a periodic timer to poll mouse state at a fixed interval</HelpText>\r
+      </EventTypes>\r
+    </CreateEvents>\r
+    <SignalEvents>\r
+      <EventTypes Usage="SOMETIMES_PRODUCED">\r
+        <EventType>EVENT_TYPE_RELATIVE_TIMER</EventType>\r
+        <HelpText>Signal an event whenever these is a pending event from mouse input</HelpText>\r
+      </EventTypes>\r
+    </SignalEvents>\r
+  </Events>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+    <Extern>\r
+      <DriverBinding>gPS2MouseDriver</DriverBinding>\r
+      <ComponentName>gPs2MouseComponentName</ComponentName>\r
+    </Extern>\r
+  </Externs>\r
+</ModuleSurfaceArea>
\ No newline at end of file