]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg: Add Ps2MouseDxe driver
authorRuiyu Ni <ruiyu.ni@intel.com>
Fri, 17 Jul 2015 09:40:15 +0000 (17:40 +0800)
committerRuiyu Ni <ruiyu.ni@intel.com>
Fri, 8 Apr 2016 09:45:59 +0000 (17:45 +0800)
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Feng Tian <feng.tian@intel.com>
MdeModulePkg/Bus/Isa/Ps2MouseDxe/CommPs2.c [new file with mode: 0644]
MdeModulePkg/Bus/Isa/Ps2MouseDxe/CommPs2.h [new file with mode: 0644]
MdeModulePkg/Bus/Isa/Ps2MouseDxe/ComponentName.c [new file with mode: 0644]
MdeModulePkg/Bus/Isa/Ps2MouseDxe/Ps2Mouse.c [new file with mode: 0644]
MdeModulePkg/Bus/Isa/Ps2MouseDxe/Ps2Mouse.h [new file with mode: 0644]
MdeModulePkg/Bus/Isa/Ps2MouseDxe/Ps2MouseDxe.inf [new file with mode: 0644]
MdeModulePkg/Bus/Isa/Ps2MouseDxe/Ps2MouseDxe.uni [new file with mode: 0644]
MdeModulePkg/Bus/Isa/Ps2MouseDxe/Ps2MouseDxeExtra.uni [new file with mode: 0644]
MdeModulePkg/MdeModulePkg.dec
MdeModulePkg/MdeModulePkg.dsc

diff --git a/MdeModulePkg/Bus/Isa/Ps2MouseDxe/CommPs2.c b/MdeModulePkg/Bus/Isa/Ps2MouseDxe/CommPs2.c
new file mode 100644 (file)
index 0000000..7539c32
--- /dev/null
@@ -0,0 +1,858 @@
+/** @file\r
+  PS2 Mouse Communication Interface.\r
+\r
+Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "Ps2Mouse.h"\r
+#include "CommPs2.h"\r
+\r
+UINT8 SampleRateTbl[MaxSampleRate]  = { 0xa, 0x14, 0x28, 0x3c, 0x50, 0x64, 0xc8 };\r
+\r
+UINT8 ResolutionTbl[MaxResolution]  = { 0, 1, 2, 3 };\r
+\r
+/**\r
+  Issue self test command via IsaIo interface.\r
+\r
+  @return EFI_SUCCESS  Success to do keyboard self testing.\r
+  @return others       Fail to do keyboard self testing.\r
+**/\r
+EFI_STATUS\r
+KbcSelfTest (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+  UINT8       Data;\r
+\r
+  //\r
+  // Keyboard controller self test\r
+  //\r
+  Status = Out8042Command (SELF_TEST);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  //\r
+  // Read return code\r
+  //\r
+  Status = In8042Data (&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 (READ_CMD_BYTE);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  Status = In8042Data (&Data);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  Status = Out8042Command (WRITE_CMD_BYTE);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  Data |= CMD_SYS_FLAG;\r
+  Status = Out8042Data (Data);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Issue command to enable keyboard AUX functionality.\r
+\r
+  @return Status of command issuing.\r
+**/\r
+EFI_STATUS\r
+KbcEnableAux (\r
+  VOID\r
+  )\r
+{\r
+  //\r
+  // Send 8042 enable mouse command\r
+  //\r
+  return Out8042Command (ENABLE_AUX);\r
+}\r
+\r
+/**\r
+  Issue command to disable keyboard AUX functionality.\r
+\r
+  @param IsaIo  Pointer to instance of EFI_ISA_IO_PROTOCOL\r
+\r
+  @return Status of command issuing.\r
+**/\r
+EFI_STATUS\r
+KbcDisableAux (\r
+  VOID\r
+  )\r
+{\r
+  //\r
+  // Send 8042 disable mouse command\r
+  //\r
+  return Out8042Command (DISABLE_AUX);\r
+}\r
+\r
+/**\r
+  Issue command to enable keyboard.\r
+\r
+  @param IsaIo  Pointer to instance of EFI_ISA_IO_PROTOCOL\r
+\r
+  @return Status of command issuing.\r
+**/\r
+EFI_STATUS\r
+KbcEnableKb (\r
+  VOID\r
+  )\r
+{\r
+  //\r
+  // Send 8042 enable keyboard command\r
+  //\r
+  return Out8042Command (ENABLE_KB);\r
+}\r
+\r
+/**\r
+  Issue command to disable keyboard.\r
+\r
+  @return Status of command issuing.\r
+**/\r
+EFI_STATUS\r
+KbcDisableKb (\r
+  VOID\r
+  )\r
+{\r
+  //\r
+  // Send 8042 disable keyboard command\r
+  //\r
+  return Out8042Command (DISABLE_KB);\r
+}\r
+\r
+/**\r
+  Issue command to check keyboard status.\r
+\r
+  @param KeyboardEnable return whether keyboard is enable.\r
+\r
+  @return Status of command issuing.\r
+**/\r
+EFI_STATUS\r
+CheckKbStatus (\r
+  OUT BOOLEAN                             *KeyboardEnable\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+  UINT8       Data;\r
+\r
+  //\r
+  // Send command to read KBC command byte\r
+  //\r
+  Status = Out8042Command (READ_CMD_BYTE);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  Status = In8042Data (&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
+/**\r
+  Issue command to reset keyboard.\r
+\r
+  @return Status of command issuing.\r
+**/\r
+EFI_STATUS\r
+PS2MouseReset (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+  UINT8       Data;\r
+\r
+  Status = Out8042AuxCommand (RESET_CMD, FALSE);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  Status = In8042AuxData (&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 (&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
+/**\r
+  Issue command to set mouse's sample rate\r
+\r
+  @param SampleRate value of sample rate\r
+\r
+  @return Status of command issuing.\r
+**/\r
+EFI_STATUS\r
+PS2MouseSetSampleRate (\r
+  IN MOUSE_SR                             SampleRate\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  //\r
+  // Send auxiliary command to set mouse sample rate\r
+  //\r
+  Status = Out8042AuxCommand (SETSR_CMD, FALSE);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  Status = Out8042AuxData (SampleRateTbl[SampleRate]);\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Issue command to set mouse's resolution.\r
+\r
+  @param Resolution value of resolution\r
+\r
+  @return Status of command issuing.\r
+**/\r
+EFI_STATUS\r
+PS2MouseSetResolution (\r
+  IN MOUSE_RE                             Resolution\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  //\r
+  // Send auxiliary command to set mouse resolution\r
+  //\r
+  Status = Out8042AuxCommand (SETRE_CMD, FALSE);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  Status = Out8042AuxData (ResolutionTbl[Resolution]);\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Issue command to set mouse's scaling.\r
+\r
+  @param Scaling value of scaling\r
+\r
+  @return Status of command issuing.\r
+**/\r
+EFI_STATUS\r
+PS2MouseSetScaling (\r
+  IN MOUSE_SF                             Scaling\r
+  )\r
+{\r
+  //\r
+  // Send auxiliary command to set mouse scaling data\r
+  //\r
+  return Out8042AuxCommand (Scaling == Scaling1 ? SETSF1_CMD : SETSF2_CMD, FALSE);\r
+}\r
+\r
+/**\r
+  Issue command to enable Ps2 mouse.\r
+\r
+  @return Status of command issuing.\r
+**/\r
+EFI_STATUS\r
+PS2MouseEnable (\r
+  VOID\r
+  )\r
+{\r
+  //\r
+  // Send auxiliary command to enable mouse\r
+  //\r
+  return Out8042AuxCommand (ENABLE_CMD, FALSE);\r
+}\r
+\r
+/**\r
+  Get mouse packet . Only care first 3 bytes\r
+\r
+  @param MouseDev  Pointer of PS2 Mouse Private Data Structure\r
+\r
+  @retval EFI_NOT_READY  Mouse Device not ready to input data packet, or some error happened during getting the packet\r
+  @retval EFI_SUCCESS    The data packet is gotten successfully.\r
+\r
+**/\r
+EFI_STATUS\r
+PS2MouseGetPacket (\r
+  PS2_MOUSE_DEV     *MouseDev\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 ();\r
+      Status = PS2MouseRead (&Data, &Count, State);\r
+      if (EFI_ERROR (Status)) {\r
+        KbcEnableAux ();\r
+        return EFI_NOT_READY;\r
+      }\r
+\r
+      if (Count != 1) {\r
+        KbcEnableAux ();\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 (&KeyboardEnable);\r
+        KbcDisableKb ();\r
+        KbcEnableAux ();\r
+      }\r
+      break;\r
+\r
+    case PS2_READ_DATA_BYTE:\r
+      Count   = 2;\r
+      Status  = PS2MouseRead ((Packet + 1), &Count, State);\r
+      if (EFI_ERROR (Status)) {\r
+        if (KeyboardEnable) {\r
+          KbcEnableKb ();\r
+        }\r
+\r
+        return EFI_NOT_READY;\r
+      }\r
+\r
+      if (Count != 2) {\r
+        if (KeyboardEnable) {\r
+          KbcEnableKb ();\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 ();\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
+/**\r
+  Read data via IsaIo protocol with given number.\r
+\r
+  @param Buffer  Buffer receive data of mouse\r
+  @param BufSize The size of buffer\r
+  @param State   Check input or read data\r
+\r
+  @return status of reading mouse data.\r
+**/\r
+EFI_STATUS\r
+PS2MouseRead (\r
+  OUT UINT8                               *Buffer,\r
+  IN OUT UINTN                            *BufSize,\r
+  IN  UINTN                               State\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+  UINTN       BytesRead;\r
+\r
+  Status    = EFI_SUCCESS;\r
+\r
+  if (State == PS2_READ_BYTE_ONE) {\r
+    //\r
+    // Check input for mouse\r
+    //\r
+    Status = CheckForInput ();\r
+\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+  }\r
+\r
+  for (BytesRead = 0; BytesRead < *BufSize; BytesRead++) {\r
+\r
+    Status = WaitOutputFull (TIMEOUT);\r
+    if (EFI_ERROR (Status)) {\r
+      break;\r
+    }\r
+    Buffer[BytesRead] = IoRead8 (KBC_DATA_PORT);\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
+//\r
+// 8042 I/O function\r
+//\r
+/**\r
+  I/O work flow of outing 8042 command.\r
+\r
+  @param Command I/O command.\r
+\r
+  @retval EFI_SUCCESS Success to excute I/O work flow\r
+  @retval EFI_TIMEOUT Keyboard controller time out.\r
+**/\r
+EFI_STATUS\r
+Out8042Command (\r
+  IN UINT8                                Command\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  //\r
+  // Wait keyboard controller input buffer empty\r
+  //\r
+  Status = WaitInputEmpty (TIMEOUT);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  //\r
+  // Send command\r
+  //\r
+  IoWrite8 (KBC_CMD_STS_PORT, Command);\r
+\r
+  Status = WaitInputEmpty (TIMEOUT);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  I/O work flow of outing 8042 data.\r
+\r
+  @param Data    Data value\r
+\r
+  @retval EFI_SUCCESS Success to excute I/O work flow\r
+  @retval EFI_TIMEOUT Keyboard controller time out.\r
+**/\r
+EFI_STATUS\r
+Out8042Data (\r
+  IN UINT8                                Data\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+  //\r
+  // Wait keyboard controller input buffer empty\r
+  //\r
+  Status = WaitInputEmpty (TIMEOUT);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  IoWrite8 (KBC_DATA_PORT, Data);\r
+  return WaitInputEmpty (TIMEOUT);\r
+}\r
+\r
+/**\r
+  I/O work flow of in 8042 data.\r
+\r
+  @param Data    Data value\r
+\r
+  @retval EFI_SUCCESS Success to excute I/O work flow\r
+  @retval EFI_TIMEOUT Keyboard controller time out.\r
+**/\r
+EFI_STATUS\r
+In8042Data (\r
+  IN OUT UINT8                            *Data\r
+  )\r
+{\r
+  UINTN Delay;\r
+\r
+  Delay = TIMEOUT / 50;\r
+\r
+  do {\r
+    //\r
+    // Check keyboard controller status bit 0(output buffer status)\r
+    //\r
+    if ((IoRead8 (KBC_CMD_STS_PORT) & KBC_OUTB) == KBC_OUTB) {\r
+      break;\r
+    }\r
+\r
+    gBS->Stall (50);\r
+    Delay--;\r
+  } while (Delay != 0);\r
+\r
+  if (Delay == 0) {\r
+    return EFI_TIMEOUT;\r
+  }\r
+\r
+  *Data = IoRead8 (KBC_DATA_PORT);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  I/O work flow of outing 8042 Aux command.\r
+\r
+  @param Command Aux I/O command\r
+  @param Resend  Whether need resend the Aux command.\r
+\r
+  @retval EFI_SUCCESS Success to excute I/O work flow\r
+  @retval EFI_TIMEOUT Keyboard controller time out.\r
+**/\r
+EFI_STATUS\r
+Out8042AuxCommand (\r
+  IN UINT8                                Command,\r
+  IN BOOLEAN                              Resend\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+  UINT8       Data;\r
+\r
+  //\r
+  // Wait keyboard controller input buffer empty\r
+  //\r
+  Status = WaitInputEmpty (TIMEOUT);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  //\r
+  // Send write to auxiliary device command\r
+  //\r
+  IoWrite8 (KBC_CMD_STS_PORT, WRITE_AUX_DEV);\r
+\r
+  Status = WaitInputEmpty (TIMEOUT);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  //\r
+  // Send auxiliary device command\r
+  //\r
+  IoWrite8 (KBC_DATA_PORT, Command);\r
+\r
+  //\r
+  // Read return code\r
+  //\r
+  Status = In8042AuxData (&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 (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
+/**\r
+  I/O work flow of outing 8042 Aux data.\r
+\r
+  @param Data    Buffer holding return value\r
+\r
+  @retval EFI_SUCCESS Success to excute I/O work flow.\r
+  @retval EFI_TIMEOUT Keyboard controller time out.\r
+**/\r
+EFI_STATUS\r
+Out8042AuxData (\r
+  IN UINT8                                Data\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+  //\r
+  // Wait keyboard controller input buffer empty\r
+  //\r
+  Status = WaitInputEmpty (TIMEOUT);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  //\r
+  // Send write to auxiliary device command\r
+  //\r
+  IoWrite8 (KBC_CMD_STS_PORT, WRITE_AUX_DEV);\r
+\r
+  Status = WaitInputEmpty (TIMEOUT);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  IoWrite8 (KBC_DATA_PORT, Data);\r
+\r
+  Status = WaitInputEmpty (TIMEOUT);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  I/O work flow of in 8042 Aux data.\r
+\r
+  @param Data    Buffer holding return value.\r
+\r
+  @retval EFI_SUCCESS Success to excute I/O work flow\r
+  @retval EFI_TIMEOUT Keyboard controller time out.\r
+**/\r
+EFI_STATUS\r
+In8042AuxData (\r
+  IN OUT UINT8                            *Data\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  //\r
+  // wait for output data\r
+  //\r
+  Status = WaitOutputFull (BAT_TIMEOUT);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  *Data = IoRead8 (KBC_DATA_PORT);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+  Check keyboard controller status, if it is output buffer full and for auxiliary device.\r
+\r
+  @retval EFI_SUCCESS   Keyboard controller is ready\r
+  @retval EFI_NOT_READY Keyboard controller is not ready\r
+**/\r
+EFI_STATUS\r
+CheckForInput (\r
+  VOID\r
+  )\r
+{\r
+  UINT8 Data;\r
+\r
+  Data = IoRead8 (KBC_CMD_STS_PORT);\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
+/**\r
+  I/O work flow to wait input buffer empty in given time.\r
+\r
+  @param Timeout Wating time.\r
+\r
+  @retval EFI_TIMEOUT if input is still not empty in given time.\r
+  @retval EFI_SUCCESS input is empty.\r
+**/\r
+EFI_STATUS\r
+WaitInputEmpty (\r
+  IN UINTN                                Timeout\r
+  )\r
+{\r
+  UINTN Delay;\r
+  UINT8 Data;\r
+\r
+  Delay = Timeout / 50;\r
+\r
+  do {\r
+    Data = IoRead8 (KBC_CMD_STS_PORT);\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 != 0);\r
+\r
+  if (Delay == 0) {\r
+    return EFI_TIMEOUT;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  I/O work flow to wait output buffer full in given time.\r
+\r
+  @param Timeout given time\r
+\r
+  @retval EFI_TIMEOUT  output is not full in given time\r
+  @retval EFI_SUCCESS  output is full in given time.\r
+**/\r
+EFI_STATUS\r
+WaitOutputFull (\r
+  IN UINTN                                Timeout\r
+  )\r
+{\r
+  UINTN Delay;\r
+  UINT8 Data;\r
+\r
+  Delay = Timeout / 50;\r
+\r
+  do {\r
+    Data = IoRead8 (KBC_CMD_STS_PORT);\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 != 0);\r
+\r
+  if (Delay == 0) {\r
+    return EFI_TIMEOUT;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
diff --git a/MdeModulePkg/Bus/Isa/Ps2MouseDxe/CommPs2.h b/MdeModulePkg/Bus/Isa/Ps2MouseDxe/CommPs2.h
new file mode 100644 (file)
index 0000000..6cf814e
--- /dev/null
@@ -0,0 +1,395 @@
+/** @file\r
+  PS2 Mouse Communication Interface\r
+\r
+Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef _COMMPS2_H_\r
+#define _COMMPS2_H_\r
+\r
+#include "Ps2Mouse.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
+///\r
+/// Parity Error\r
+///\r
+#define KBC_PARE  0x80\r
+///\r
+/// General Time Out\r
+///\r
+#define KBC_TIM   0x40\r
+///\r
+/// Output buffer for auxiliary device (PS/2):\r
+///    0 - Holds keyboard data\r
+///    1 - Holds data for auxiliary device\r
+///\r
+#define KBC_AUXB  0x20\r
+///\r
+/// Keyboard lock status:\r
+///    0 - keyboard locked\r
+///    1 - keyboard free\r
+///\r
+#define KBC_KEYL  0x10\r
+///\r
+/// Command/Data:\r
+///    0 - data byte written via port 60h\r
+///    1 - command byte written via port 64h\r
+///\r
+#define KBC_CD  0x08\r
+///\r
+/// System Flag:\r
+///    0 - power-on reset\r
+///    1 - self-test successful\r
+///\r
+#define KBC_SYSF  0x04\r
+///\r
+/// Input Buffer Status :\r
+///    0 - input buffer empty\r
+///    1 - CPU data in input buffer\r
+///\r
+#define KBC_INPB  0x02\r
+///\r
+/// Output Buffer Status :\r
+///    0 - output buffer empty\r
+///    1 - keyboard controller data in output buffer\r
+///\r
+#define KBC_OUTB  0x01\r
+\r
+/**\r
+  Issue self test command via IsaIo interface.\r
+\r
+  @return EFI_SUCCESS  Success to do keyboard self testing.\r
+  @return others       Fail to do keyboard self testing.\r
+**/\r
+EFI_STATUS\r
+KbcSelfTest (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  Issue command to enable keyboard AUX functionality.\r
+\r
+  @return Status of command issuing.\r
+**/\r
+EFI_STATUS\r
+KbcEnableAux (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  Issue command to disable keyboard AUX functionality.\r
+\r
+  @return Status of command issuing.\r
+**/\r
+EFI_STATUS\r
+KbcDisableAux (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  Issue command to enable keyboard.\r
+\r
+  @return Status of command issuing.\r
+**/\r
+EFI_STATUS\r
+KbcEnableKb (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  Issue command to disable keyboard.\r
+\r
+  @return Status of command issuing.\r
+**/\r
+EFI_STATUS\r
+KbcDisableKb (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  Issue command to check keyboard status.\r
+\r
+  @param KeyboardEnable return whether keyboard is enable.\r
+\r
+  @return Status of command issuing.\r
+**/\r
+EFI_STATUS\r
+CheckKbStatus (\r
+  OUT BOOLEAN                             *KeyboardEnable\r
+  );\r
+\r
+/**\r
+  Issue command to reset keyboard.\r
+\r
+  @return Status of command issuing.\r
+**/\r
+EFI_STATUS\r
+PS2MouseReset (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  Issue command to set mouse's sample rate\r
+\r
+  @param SampleRate value of sample rate\r
+\r
+  @return Status of command issuing.\r
+**/\r
+EFI_STATUS\r
+PS2MouseSetSampleRate (\r
+  IN MOUSE_SR                             SampleRate\r
+  );\r
+\r
+/**\r
+  Issue command to set mouse's resolution.\r
+\r
+  @param Resolution value of resolution\r
+\r
+  @return Status of command issuing.\r
+**/\r
+EFI_STATUS\r
+PS2MouseSetResolution (\r
+  IN MOUSE_RE                             Resolution\r
+  );\r
+\r
+/**\r
+  Issue command to set mouse's scaling.\r
+\r
+  @param Scaling value of scaling\r
+\r
+  @return Status of command issuing.\r
+**/\r
+EFI_STATUS\r
+PS2MouseSetScaling (\r
+  IN MOUSE_SF                             Scaling\r
+  );\r
+\r
+/**\r
+  Issue command to enable Ps2 mouse.\r
+\r
+  @return Status of command issuing.\r
+**/\r
+EFI_STATUS\r
+PS2MouseEnable (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  Get mouse packet . Only care first 3 bytes\r
+\r
+  @param MouseDev  Pointer of PS2 Mouse Private Data Structure\r
+\r
+  @retval EFI_NOT_READY  Mouse Device not ready to input data packet, or some error happened during getting the packet\r
+  @retval EFI_SUCCESS    The data packet is gotten successfully.\r
+\r
+**/\r
+EFI_STATUS\r
+PS2MouseGetPacket (\r
+  PS2_MOUSE_DEV     *MouseDev\r
+  );\r
+\r
+/**\r
+  Read data via IsaIo protocol with given number.\r
+\r
+  @param Buffer  Buffer receive data of mouse\r
+  @param BufSize The size of buffer\r
+  @param State   Check input or read data\r
+\r
+  @return status of reading mouse data.\r
+**/\r
+EFI_STATUS\r
+PS2MouseRead (\r
+  OUT VOID                                *Buffer,\r
+  IN OUT UINTN                            *BufSize,\r
+  IN  UINTN                               State\r
+  );\r
+\r
+//\r
+// 8042 I/O function\r
+//\r
+/**\r
+  I/O work flow of outing 8042 command.\r
+\r
+  @param Command I/O command.\r
+\r
+  @retval EFI_SUCCESS Success to excute I/O work flow\r
+  @retval EFI_TIMEOUT Keyboard controller time out.\r
+**/\r
+EFI_STATUS\r
+Out8042Command (\r
+  IN UINT8                                Command\r
+  );\r
+\r
+/**\r
+  I/O work flow of in 8042 data.\r
+\r
+  @param Data    Data value\r
+\r
+  @retval EFI_SUCCESS Success to excute I/O work flow\r
+  @retval EFI_TIMEOUT Keyboard controller time out.\r
+**/\r
+EFI_STATUS\r
+In8042Data (\r
+  IN OUT UINT8                            *Data\r
+  );\r
+\r
+/**\r
+  I/O work flow of outing 8042 data.\r
+\r
+  @param Data    Data value\r
+\r
+  @retval EFI_SUCCESS Success to excute I/O work flow\r
+  @retval EFI_TIMEOUT Keyboard controller time out.\r
+**/\r
+EFI_STATUS\r
+Out8042Data (\r
+  IN UINT8                                Data\r
+  );\r
+\r
+/**\r
+  I/O work flow of outing 8042 Aux command.\r
+\r
+  @param Command Aux I/O command\r
+  @param Resend  Whether need resend the Aux command.\r
+\r
+  @retval EFI_SUCCESS Success to excute I/O work flow\r
+  @retval EFI_TIMEOUT Keyboard controller time out.\r
+**/\r
+EFI_STATUS\r
+Out8042AuxCommand (\r
+  IN UINT8                                Command,\r
+  IN BOOLEAN                              Resend\r
+  );\r
+\r
+/**\r
+  I/O work flow of in 8042 Aux data.\r
+\r
+  @param Data    Buffer holding return value.\r
+\r
+  @retval EFI_SUCCESS Success to excute I/O work flow\r
+  @retval EFI_TIMEOUT Keyboard controller time out.\r
+**/\r
+EFI_STATUS\r
+In8042AuxData (\r
+  IN OUT UINT8                            *Data\r
+  );\r
+\r
+/**\r
+  I/O work flow of outing 8042 Aux data.\r
+\r
+  @param Data    Buffer holding return value\r
+\r
+  @retval EFI_SUCCESS Success to excute I/O work flow\r
+  @retval EFI_TIMEOUT Keyboard controller time out.\r
+**/\r
+EFI_STATUS\r
+Out8042AuxData (\r
+  IN UINT8                                Data\r
+  );\r
+\r
+/**\r
+  Check keyboard controller status, if it is output buffer full and for auxiliary device.\r
+\r
+  @retval EFI_SUCCESS   Keyboard controller is ready\r
+  @retval EFI_NOT_READY Keyboard controller is not ready\r
+**/\r
+EFI_STATUS\r
+CheckForInput (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  I/O work flow to wait input buffer empty in given time.\r
+\r
+  @param Timeout Wating time.\r
+\r
+  @retval EFI_TIMEOUT if input is still not empty in given time.\r
+  @retval EFI_SUCCESS input is empty.\r
+**/\r
+EFI_STATUS\r
+WaitInputEmpty (\r
+  IN UINTN                                Timeout\r
+  );\r
+\r
+/**\r
+  I/O work flow to wait output buffer full in given time.\r
+\r
+  @param Timeout given time\r
+\r
+  @retval EFI_TIMEOUT  output is not full in given time\r
+  @retval EFI_SUCCESS  output is full in given time.\r
+**/\r
+EFI_STATUS\r
+WaitOutputFull (\r
+  IN UINTN                                Timeout\r
+  );\r
+\r
+#endif\r
+\r
diff --git a/MdeModulePkg/Bus/Isa/Ps2MouseDxe/ComponentName.c b/MdeModulePkg/Bus/Isa/Ps2MouseDxe/ComponentName.c
new file mode 100644 (file)
index 0000000..9624802
--- /dev/null
@@ -0,0 +1,223 @@
+/** @file\r
+  UEFI Component Name(2) protocol implementation for Ps2MouseDxe driver.\r
+\r
+Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "Ps2Mouse.h"\r
+\r
+//\r
+// EFI Component Name Protocol\r
+//\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL  gPs2MouseComponentName = {\r
+  Ps2MouseComponentNameGetDriverName,\r
+  Ps2MouseComponentNameGetControllerName,\r
+  "eng"\r
+};\r
+\r
+//\r
+// EFI Component Name 2 Protocol\r
+//\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gPs2MouseComponentName2 = {\r
+  (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) Ps2MouseComponentNameGetDriverName,\r
+  (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) Ps2MouseComponentNameGetControllerName,\r
+  "en"\r
+};\r
+\r
+\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mPs2MouseDriverNameTable[] = {\r
+  {\r
+    "eng;en",\r
+    L"PS/2 Mouse Driver"\r
+  },\r
+  {\r
+    NULL,\r
+    NULL\r
+  }\r
+};\r
+\r
+/**\r
+  Retrieves a Unicode string that is the user readable name of the driver.\r
+\r
+  This function retrieves the user readable name of a driver in the form of a\r
+  Unicode string. If the driver specified by This has a user readable name in\r
+  the language specified by Language, then a pointer to the driver name is\r
+  returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r
+  by This does not support the language specified by Language,\r
+  then EFI_UNSUPPORTED is returned.\r
+\r
+  @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
+                                EFI_COMPONENT_NAME_PROTOCOL instance.\r
+\r
+  @param  Language[in]          A pointer to a Null-terminated ASCII string\r
+                                array indicating the language. This is the\r
+                                language of the driver name that the caller is\r
+                                requesting, and it must match one of the\r
+                                languages specified in SupportedLanguages. The\r
+                                number of languages supported by a driver is up\r
+                                to the driver writer. Language is specified\r
+                                in RFC 4646 or ISO 639-2 language code format.\r
+\r
+  @param  DriverName[out]       A pointer to the Unicode string to return.\r
+                                This Unicode string is the name of the\r
+                                driver specified by This in the language\r
+                                specified by Language.\r
+\r
+  @retval EFI_SUCCESS           The Unicode string for the Driver specified by\r
+                                This and the language specified by Language was\r
+                                returned in DriverName.\r
+\r
+  @retval EFI_INVALID_PARAMETER Language is NULL.\r
+\r
+  @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
+\r
+  @retval EFI_UNSUPPORTED       The driver specified by This does not support\r
+                                the language specified by Language.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+Ps2MouseComponentNameGetDriverName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  )\r
+{\r
+  return LookupUnicodeString2 (\r
+           Language,\r
+           This->SupportedLanguages,\r
+           mPs2MouseDriverNameTable,\r
+           DriverName,\r
+           (BOOLEAN)(This == &gPs2MouseComponentName)\r
+           );\r
+}\r
+\r
+/**\r
+  Retrieves a Unicode string that is the user readable name of the controller\r
+  that is being managed by a driver.\r
+\r
+  This function retrieves the user readable name of the controller specified by\r
+  ControllerHandle and ChildHandle in the form of a Unicode string. If the\r
+  driver specified by This has a user readable name in the language specified by\r
+  Language, then a pointer to the controller name is returned in ControllerName,\r
+  and EFI_SUCCESS is returned.  If the driver specified by This is not currently\r
+  managing the controller specified by ControllerHandle and ChildHandle,\r
+  then EFI_UNSUPPORTED is returned.  If the driver specified by This does not\r
+  support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
+\r
+  @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
+                                EFI_COMPONENT_NAME_PROTOCOL instance.\r
+\r
+  @param  ControllerHandle[in]  The handle of a controller that the driver\r
+                                specified by This is managing.  This handle\r
+                                specifies the controller whose name is to be\r
+                                returned.\r
+\r
+  @param  ChildHandle[in]       The handle of the child controller to retrieve\r
+                                the name of.  This is an optional parameter that\r
+                                may be NULL.  It will be NULL for device\r
+                                drivers.  It will also be NULL for a bus drivers\r
+                                that wish to retrieve the name of the bus\r
+                                controller.  It will not be NULL for a bus\r
+                                driver that wishes to retrieve the name of a\r
+                                child controller.\r
+\r
+  @param  Language[in]          A pointer to a Null-terminated ASCII string\r
+                                array indicating the language.  This is the\r
+                                language of the driver name that the caller is\r
+                                requesting, and it must match one of the\r
+                                languages specified in SupportedLanguages. The\r
+                                number of languages supported by a driver is up\r
+                                to the driver writer. Language is specified in\r
+                                RFC 4646 or ISO 639-2 language code format.\r
+\r
+  @param  ControllerName[out]   A pointer to the Unicode string to return.\r
+                                This Unicode string is the name of the\r
+                                controller specified by ControllerHandle and\r
+                                ChildHandle in the language specified by\r
+                                Language from the point of view of the driver\r
+                                specified by This.\r
+\r
+  @retval EFI_SUCCESS           The Unicode string for the user readable name in\r
+                                the language specified by Language for the\r
+                                driver specified by This was returned in\r
+                                DriverName.\r
+\r
+  @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r
+\r
+  @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r
+                                EFI_HANDLE.\r
+\r
+  @retval EFI_INVALID_PARAMETER Language is NULL.\r
+\r
+  @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
+\r
+  @retval EFI_UNSUPPORTED       The driver specified by This is not currently\r
+                                managing the controller specified by\r
+                                ControllerHandle and ChildHandle.\r
+\r
+  @retval EFI_UNSUPPORTED       The driver specified by This does not support\r
+                                the language specified by Language.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+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                                  Status;\r
+  EFI_SIMPLE_POINTER_PROTOCOL                 *SimplePointerProtocol;\r
+  PS2_MOUSE_DEV                               *MouseDev;\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 = EfiTestManagedDevice (ControllerHandle, gPS2MouseDriver.DriverBindingHandle, &gEfiSioProtocolGuid);\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\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 LookupUnicodeString2 (\r
+           Language,\r
+           This->SupportedLanguages,\r
+           MouseDev->ControllerNameTable,\r
+           ControllerName,\r
+           (BOOLEAN)(This == &gPs2MouseComponentName)\r
+           );\r
+}\r
diff --git a/MdeModulePkg/Bus/Isa/Ps2MouseDxe/Ps2Mouse.c b/MdeModulePkg/Bus/Isa/Ps2MouseDxe/Ps2Mouse.c
new file mode 100644 (file)
index 0000000..91fac55
--- /dev/null
@@ -0,0 +1,805 @@
+/** @file\r
+  PS/2 Mouse driver. Routines that interacts with callers,\r
+  conforming to EFI driver model.\r
+\r
+Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\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
+/**\r
+  Test to see if this driver supports ControllerHandle. Any ControllerHandle\r
+  than contains a IsaIo protocol can be supported.\r
+\r
+  @param  This                Protocol instance pointer.\r
+  @param  ControllerHandle    Handle of device to test\r
+  @param  RemainingDevicePath Optional parameter use to pick a specific child\r
+                              device to start.\r
+\r
+  @retval EFI_SUCCESS         This driver supports this device\r
+  @retval EFI_ALREADY_STARTED This driver is already running on this device\r
+  @retval other               This driver does not support this device\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
+  EFI_STATUS                        Status;\r
+  EFI_SIO_PROTOCOL                  *Sio;\r
+  EFI_DEVICE_PATH_PROTOCOL          *DevicePath;\r
+  ACPI_HID_DEVICE_PATH              *Acpi;\r
+\r
+  //\r
+  // Check whether the controller is keyboard.\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  Controller,\r
+                  &gEfiDevicePathProtocolGuid,\r
+                  (VOID **) &DevicePath,\r
+                  This->DriverBindingHandle,\r
+                  Controller,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  do {\r
+    Acpi = (ACPI_HID_DEVICE_PATH *) DevicePath;\r
+    DevicePath = NextDevicePathNode (DevicePath);\r
+  } while (!IsDevicePathEnd (DevicePath));\r
+\r
+  if (DevicePathType (Acpi) != ACPI_DEVICE_PATH ||\r
+      (DevicePathSubType (Acpi) != ACPI_DP && DevicePathSubType (Acpi) != ACPI_EXTENDED_DP)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  switch (Acpi->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 (Acpi->UID == 1) {\r
+      break;\r
+    }\r
+\r
+  default:\r
+    return EFI_UNSUPPORTED;\r
+    break;\r
+  }\r
+\r
+  //\r
+  // Open the IO Abstraction(s) needed to perform the supported test\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  Controller,\r
+                  &gEfiSioProtocolGuid,\r
+                  (VOID **) &Sio,\r
+                  This->DriverBindingHandle,\r
+                  Controller,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Close the I/O Abstraction(s) used to perform the supported test\r
+  //\r
+  gBS->CloseProtocol (\r
+         Controller,\r
+         &gEfiSioProtocolGuid,\r
+         This->DriverBindingHandle,\r
+         Controller\r
+         );\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Start this driver on ControllerHandle by opening a Sio protocol, creating\r
+  PS2_MOUSE_DEV device and install gEfiSimplePointerProtocolGuid finally.\r
+\r
+  @param  This                 Protocol instance pointer.\r
+  @param  ControllerHandle     Handle of device to bind driver to\r
+  @param  RemainingDevicePath  Optional parameter use to pick a specific child\r
+                               device to start.\r
+\r
+  @retval EFI_SUCCESS          This driver is added to ControllerHandle\r
+  @retval EFI_ALREADY_STARTED  This driver is already running on ControllerHandle\r
+  @retval other                This driver does not support this device\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                          Status;\r
+  EFI_STATUS                          EmptyStatus;\r
+  EFI_SIO_PROTOCOL                    *Sio;\r
+  PS2_MOUSE_DEV                       *MouseDev;\r
+  UINT8                               Data;\r
+  EFI_TPL                             OldTpl;\r
+  EFI_STATUS_CODE_VALUE               StatusCode;\r
+  EFI_DEVICE_PATH_PROTOCOL            *DevicePath;\r
+\r
+  StatusCode  = 0;\r
+\r
+  //\r
+  // Open the device path protocol\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  Controller,\r
+                  &gEfiDevicePathProtocolGuid,\r
+                  (VOID **) &DevicePath,\r
+                  This->DriverBindingHandle,\r
+                  Controller,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\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
+    DevicePath\r
+    );\r
+\r
+  //\r
+  // Get the ISA I/O Protocol on Controller's handle\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  Controller,\r
+                  &gEfiSioProtocolGuid,\r
+                  (VOID **) &Sio,\r
+                  This->DriverBindingHandle,\r
+                  Controller,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\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      = SampleRate20;\r
+  MouseDev->Resolution      = MouseResolution4;\r
+  MouseDev->Scaling         = Scaling1;\r
+  MouseDev->DataPackageSize = 3;\r
+  MouseDev->DevicePath      = DevicePath;\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
+  REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
+    EFI_PROGRESS_CODE,\r
+    EFI_PERIPHERAL_MOUSE | EFI_P_MOUSE_PC_SELF_TEST,\r
+    DevicePath\r
+    );\r
+\r
+  Data = IoRead8 (KBC_CMD_STS_PORT);\r
+  //\r
+  // Fix for random hangs in System waiting for the Key if no KBC is present in BIOS.\r
+  //\r
+  if ((Data & (KBC_PARE | KBC_TIM)) == (KBC_PARE | KBC_TIM)) {\r
+    //\r
+    // If nobody decodes KBC I/O port, it will read back as 0xFF.\r
+    // Check the Time-Out and Parity bit to see if it has an active KBC in system\r
+    //\r
+    Status     = EFI_DEVICE_ERROR;\r
+    StatusCode = EFI_PERIPHERAL_MOUSE | EFI_P_EC_NOT_DETECTED;\r
+    goto ErrorExit;\r
+  }\r
+\r
+  if ((Data & KBC_SYSF) != KBC_SYSF) {\r
+    Status = KbcSelfTest ();\r
+    if (EFI_ERROR (Status)) {\r
+      StatusCode = EFI_PERIPHERAL_MOUSE | EFI_P_EC_CONTROLLER_ERROR;\r
+      goto ErrorExit;\r
+    }\r
+  }\r
+\r
+  KbcEnableAux ();\r
+\r
+  REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
+    EFI_PROGRESS_CODE,\r
+    EFI_PERIPHERAL_MOUSE | EFI_P_PC_PRESENCE_DETECT,\r
+    DevicePath\r
+    );\r
+\r
+  //\r
+  // Reset the mouse\r
+  //\r
+  Status = MouseDev->SimplePointerProtocol.Reset (\r
+                     &MouseDev->SimplePointerProtocol,\r
+                     FeaturePcdGet (PcdPs2MouseExtendedVerification)\r
+                     );\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
+  REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
+    EFI_PROGRESS_CODE,\r
+    EFI_PERIPHERAL_MOUSE | EFI_P_PC_DETECTED,\r
+    DevicePath\r
+    );\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
+  AddUnicodeString2 (\r
+    "eng",\r
+    gPs2MouseComponentName.SupportedLanguages,\r
+    &MouseDev->ControllerNameTable,\r
+    L"PS/2 Mouse Device",\r
+    TRUE\r
+    );\r
+  AddUnicodeString2 (\r
+    "en",\r
+    gPs2MouseComponentName2.SupportedLanguages,\r
+    &MouseDev->ControllerNameTable,\r
+    L"PS/2 Mouse Device",\r
+    FALSE\r
+    );\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
+  if (Status != EFI_DEVICE_ERROR) {\r
+    KbcDisableAux ();\r
+  }\r
+\r
+  if (StatusCode != 0) {\r
+    REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
+      EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
+      StatusCode,\r
+      DevicePath\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
+  if (Status != EFI_DEVICE_ERROR) {\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 (&Data);\r
+    }\r
+  }\r
+\r
+  if (MouseDev != NULL) {\r
+    FreePool (MouseDev);\r
+  }\r
+\r
+  gBS->CloseProtocol (\r
+         Controller,\r
+         &gEfiDevicePathProtocolGuid,\r
+         This->DriverBindingHandle,\r
+         Controller\r
+         );\r
+\r
+  gBS->CloseProtocol (\r
+         Controller,\r
+         &gEfiSioProtocolGuid,\r
+         This->DriverBindingHandle,\r
+         Controller\r
+         );\r
+\r
+  gBS->RestoreTPL (OldTpl);\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Stop this driver on ControllerHandle. Support stoping any child handles\r
+  created by this driver.\r
+\r
+  @param  This              Protocol instance pointer.\r
+  @param  ControllerHandle  Handle of device to stop driver on\r
+  @param  NumberOfChildren  Number of Handles in ChildHandleBuffer. If number of\r
+                            children is zero stop the entire bus driver.\r
+  @param  ChildHandleBuffer List of Child Handles to Stop.\r
+\r
+  @retval EFI_SUCCESS       This driver is removed ControllerHandle\r
+  @retval other             This driver was not removed from this device\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
+  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
+  //\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 (&Data);\r
+  }\r
+\r
+  gBS->CloseEvent (MouseDev->SimplePointerProtocol.WaitForInput);\r
+  FreeUnicodeStringTable (MouseDev->ControllerNameTable);\r
+  FreePool (MouseDev);\r
+\r
+  gBS->CloseProtocol (\r
+         Controller,\r
+         &gEfiDevicePathProtocolGuid,\r
+         This->DriverBindingHandle,\r
+         Controller\r
+         );\r
+\r
+  gBS->CloseProtocol (\r
+         Controller,\r
+         &gEfiSioProtocolGuid,\r
+         This->DriverBindingHandle,\r
+         Controller\r
+         );\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Reset the Mouse and do BAT test for it, if ExtendedVerification is TRUE and\r
+  there is a mouse device connectted to system.\r
+\r
+  @param This                 - Pointer of simple pointer Protocol.\r
+  @param ExtendedVerification - Whether configure mouse parameters. True: do; FALSE: skip.\r
+\r
+\r
+  @retval EFI_SUCCESS         - The command byte is written successfully.\r
+  @retval EFI_DEVICE_ERROR    - Errors occurred during reseting keyboard.\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    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 (&Data);\r
+  }\r
+\r
+  CheckKbStatus (&KeyboardEnable);\r
+\r
+  KbcDisableKb ();\r
+\r
+  //\r
+  // if there's data block on KBC data port, read it out\r
+  //\r
+  if ((IoRead8 (KBC_CMD_STS_PORT) & KBC_OUTB) == KBC_OUTB) {\r
+    IoRead8 (KBC_DATA_PORT);\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 ();\r
+    if (EFI_ERROR (Status)) {\r
+      Status = EFI_DEVICE_ERROR;\r
+      goto Exit;\r
+    }\r
+\r
+    Status = PS2MouseSetSampleRate (MouseDev->SampleRate);\r
+    if (EFI_ERROR (Status)) {\r
+      Status = EFI_DEVICE_ERROR;\r
+      goto Exit;\r
+    }\r
+\r
+    Status = PS2MouseSetResolution (MouseDev->Resolution);\r
+    if (EFI_ERROR (Status)) {\r
+      Status = EFI_DEVICE_ERROR;\r
+      goto Exit;\r
+    }\r
+\r
+    Status = PS2MouseSetScaling (MouseDev->Scaling);\r
+    if (EFI_ERROR (Status)) {\r
+      Status = EFI_DEVICE_ERROR;\r
+      goto Exit;\r
+    }\r
+\r
+    Status = PS2MouseEnable ();\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 ();\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Check whether there is Ps/2 mouse device in system\r
+\r
+  @param MouseDev   - Mouse Private Data Structure\r
+\r
+  @retval TRUE      - Keyboard in System.\r
+  @retval FALSE     - Keyboard not in System.\r
+\r
+**/\r
+BOOLEAN\r
+CheckMouseConnect (\r
+  IN  PS2_MOUSE_DEV     *MouseDev\r
+  )\r
+\r
+{\r
+  EFI_STATUS     Status;\r
+\r
+  Status = PS2MouseEnable ();\r
+  if (!EFI_ERROR (Status)) {\r
+    return TRUE;\r
+  }\r
+\r
+  return FALSE;\r
+}\r
+\r
+/**\r
+  Get and Clear mouse status.\r
+\r
+  @param This                 - Pointer of simple pointer Protocol.\r
+  @param State                - Output buffer holding status.\r
+\r
+  @retval EFI_INVALID_PARAMETER Output buffer is invalid.\r
+  @retval EFI_NOT_READY         Mouse is not changed status yet.\r
+  @retval EFI_SUCCESS           Mouse status is changed and get successful.\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
+  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
+/**\r
+\r
+  Event notification function for SIMPLE_POINTER.WaitForInput event.\r
+  Signal the event if there is input from mouse.\r
+\r
+  @param Event    event object\r
+  @param Context  event context\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+MouseWaitForInput (\r
+  IN  EFI_EVENT               Event,\r
+  IN  VOID                    *Context\r
+  )\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
+/**\r
+  Event notification function for TimerEvent event.\r
+  If mouse device is connected to system, try to get the mouse packet data.\r
+\r
+  @param Event      -  TimerEvent in PS2_MOUSE_DEV\r
+  @param Context    -  Pointer to PS2_MOUSE_DEV structure\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+PollMouse (\r
+  IN EFI_EVENT  Event,\r
+  IN VOID       *Context\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
+\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 = EfiLibInstallDriverBindingComponentName2 (\r
+             ImageHandle,\r
+             SystemTable,\r
+             &gPS2MouseDriver,\r
+             ImageHandle,\r
+             &gPs2MouseComponentName,\r
+             &gPs2MouseComponentName2\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+\r
+  return Status;\r
+}\r
+\r
diff --git a/MdeModulePkg/Bus/Isa/Ps2MouseDxe/Ps2Mouse.h b/MdeModulePkg/Bus/Isa/Ps2MouseDxe/Ps2Mouse.h
new file mode 100644 (file)
index 0000000..6419b89
--- /dev/null
@@ -0,0 +1,399 @@
+/** @file\r
+  PS/2 Mouse driver header file.\r
+\r
+Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef _PS2MOUSE_H_\r
+#define _PS2MOUSE_H_\r
+\r
+#include <Uefi.h>\r
+\r
+#include <Protocol/SimplePointer.h>\r
+#include <Protocol/SuperIo.h>\r
+#include <Protocol/DevicePath.h>\r
+\r
+#include <Library/DevicePathLib.h>\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
+#include <Library/PcdLib.h>\r
+#include <Library/IoLib.h>\r
+\r
+//\r
+// Global Variables\r
+//\r
+extern EFI_DRIVER_BINDING_PROTOCOL   gPS2MouseDriver;\r
+extern EFI_COMPONENT_NAME_PROTOCOL   gPs2MouseComponentName;\r
+extern EFI_COMPONENT_NAME2_PROTOCOL  gPs2MouseComponentName2;\r
+\r
+//\r
+// PS/2 mouse sample rate\r
+//\r
+typedef enum {\r
+  SampleRate10,\r
+  SampleRate20,\r
+  SampleRate40,\r
+  SampleRate60,\r
+  SampleRate80,\r
+  SampleRate100,\r
+  SampleRate200,\r
+  MaxSampleRate\r
+} MOUSE_SR;\r
+\r
+//\r
+// PS/2 mouse resolution\r
+//\r
+typedef enum {\r
+  MouseResolution1,\r
+  MouseResolution2,\r
+  MouseResolution4,\r
+  MouseResolution8,\r
+  MaxResolution\r
+} MOUSE_RE;\r
+\r
+//\r
+// PS/2 mouse scaling\r
+//\r
+typedef enum {\r
+  Scaling1,\r
+  Scaling2\r
+} MOUSE_SF;\r
+\r
+//\r
+// Driver Private Data\r
+//\r
+#define PS2_MOUSE_DEV_SIGNATURE 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_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
+// Function prototypes\r
+//\r
+/**\r
+  Test to see if this driver supports ControllerHandle. Any ControllerHandle\r
+  than contains a IsaIo protocol can be supported.\r
+\r
+  @param  This                Protocol instance pointer.\r
+  @param  ControllerHandle    Handle of device to test\r
+  @param  RemainingDevicePath Optional parameter use to pick a specific child\r
+                              device to start.\r
+\r
+  @retval EFI_SUCCESS         This driver supports this device\r
+  @retval EFI_ALREADY_STARTED This driver is already running on this device\r
+  @retval other               This driver does not support this device\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
+  Start this driver on ControllerHandle by opening a IsaIo\r
+  protocol, creating PS2_MOUSE_ABSOLUTE_POINTER_DEV device and install gEfiAbsolutePointerProtocolGuid\r
+  finnally.\r
+\r
+  @param  This                 Protocol instance pointer.\r
+  @param  ControllerHandle     Handle of device to bind driver to\r
+  @param  RemainingDevicePath  Optional parameter use to pick a specific child\r
+                               device to start.\r
+\r
+  @retval EFI_SUCCESS          This driver is added to ControllerHandle\r
+  @retval EFI_ALREADY_STARTED  This driver is already running on ControllerHandle\r
+  @retval other                This driver does not support this device\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
+  Stop this driver on ControllerHandle. Support stoping any child handles\r
+  created by this driver.\r
+\r
+  @param  This              Protocol instance pointer.\r
+  @param  ControllerHandle  Handle of device to stop driver on\r
+  @param  NumberOfChildren  Number of Handles in ChildHandleBuffer. If number of\r
+                            children is zero stop the entire bus driver.\r
+  @param  ChildHandleBuffer List of Child Handles to Stop.\r
+\r
+  @retval EFI_SUCCESS       This driver is removed ControllerHandle\r
+  @retval other             This driver was not removed from this device\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
+/**\r
+  Retrieves a Unicode string that is the user readable name of the driver.\r
+\r
+  This function retrieves the user readable name of a driver in the form of a\r
+  Unicode string. If the driver specified by This has a user readable name in\r
+  the language specified by Language, then a pointer to the driver name is\r
+  returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r
+  by This does not support the language specified by Language,\r
+  then EFI_UNSUPPORTED is returned.\r
+\r
+  @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
+                                EFI_COMPONENT_NAME_PROTOCOL instance.\r
+\r
+  @param  Language[in]          A pointer to a Null-terminated ASCII string\r
+                                array indicating the language. This is the\r
+                                language of the driver name that the caller is\r
+                                requesting, and it must match one of the\r
+                                languages specified in SupportedLanguages. The\r
+                                number of languages supported by a driver is up\r
+                                to the driver writer. Language is specified\r
+                                in RFC 4646 or ISO 639-2 language code format.\r
+\r
+  @param  DriverName[out]       A pointer to the Unicode string to return.\r
+                                This Unicode string is the name of the\r
+                                driver specified by This in the language\r
+                                specified by Language.\r
+\r
+  @retval EFI_SUCCESS           The Unicode string for the Driver specified by\r
+                                This and the language specified by Language was\r
+                                returned in DriverName.\r
+\r
+  @retval EFI_INVALID_PARAMETER Language is NULL.\r
+\r
+  @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
+\r
+  @retval EFI_UNSUPPORTED       The driver specified by This does not support\r
+                                the language specified by Language.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+Ps2MouseComponentNameGetDriverName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  );\r
+\r
+\r
+/**\r
+  Retrieves a Unicode string that is the user readable name of the controller\r
+  that is being managed by a driver.\r
+\r
+  This function retrieves the user readable name of the controller specified by\r
+  ControllerHandle and ChildHandle in the form of a Unicode string. If the\r
+  driver specified by This has a user readable name in the language specified by\r
+  Language, then a pointer to the controller name is returned in ControllerName,\r
+  and EFI_SUCCESS is returned.  If the driver specified by This is not currently\r
+  managing the controller specified by ControllerHandle and ChildHandle,\r
+  then EFI_UNSUPPORTED is returned.  If the driver specified by This does not\r
+  support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
+\r
+  @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
+                                EFI_COMPONENT_NAME_PROTOCOL instance.\r
+\r
+  @param  ControllerHandle[in]  The handle of a controller that the driver\r
+                                specified by This is managing.  This handle\r
+                                specifies the controller whose name is to be\r
+                                returned.\r
+\r
+  @param  ChildHandle[in]       The handle of the child controller to retrieve\r
+                                the name of.  This is an optional parameter that\r
+                                may be NULL.  It will be NULL for device\r
+                                drivers.  It will also be NULL for a bus drivers\r
+                                that wish to retrieve the name of the bus\r
+                                controller.  It will not be NULL for a bus\r
+                                driver that wishes to retrieve the name of a\r
+                                child controller.\r
+\r
+  @param  Language[in]          A pointer to a Null-terminated ASCII string\r
+                                array indicating the language.  This is the\r
+                                language of the driver name that the caller is\r
+                                requesting, and it must match one of the\r
+                                languages specified in SupportedLanguages. The\r
+                                number of languages supported by a driver is up\r
+                                to the driver writer. Language is specified in\r
+                                RFC 4646 or ISO 639-2 language code format.\r
+\r
+  @param  ControllerName[out]   A pointer to the Unicode string to return.\r
+                                This Unicode string is the name of the\r
+                                controller specified by ControllerHandle and\r
+                                ChildHandle in the language specified by\r
+                                Language from the point of view of the driver\r
+                                specified by This.\r
+\r
+  @retval EFI_SUCCESS           The Unicode string for the user readable name in\r
+                                the language specified by Language for the\r
+                                driver specified by This was returned in\r
+                                DriverName.\r
+\r
+  @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r
+\r
+  @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r
+                                EFI_HANDLE.\r
+\r
+  @retval EFI_INVALID_PARAMETER Language is NULL.\r
+\r
+  @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
+\r
+  @retval EFI_UNSUPPORTED       The driver specified by This is not currently\r
+                                managing the controller specified by\r
+                                ControllerHandle and ChildHandle.\r
+\r
+  @retval EFI_UNSUPPORTED       The driver specified by This does not support\r
+                                the language specified by Language.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+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
+  Reset the Mouse and do BAT test for it, if ExtendedVerification is TRUE and\r
+  there is a mouse device connectted to system.\r
+\r
+  @param This                 - Pointer of simple pointer Protocol.\r
+  @param ExtendedVerification - Whether configure mouse parameters. True: do; FALSE: skip.\r
+\r
+\r
+  @retval EFI_SUCCESS         - The command byte is written successfully.\r
+  @retval EFI_DEVICE_ERROR    - Errors occurred during reseting keyboard.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+MouseReset (\r
+  IN EFI_SIMPLE_POINTER_PROTOCOL    *This,\r
+  IN BOOLEAN                        ExtendedVerification\r
+  );\r
+\r
+/**\r
+  Get and Clear mouse status.\r
+\r
+  @param This                 - Pointer of simple pointer Protocol.\r
+  @param State                - Output buffer holding status.\r
+\r
+  @retval EFI_INVALID_PARAMETER Output buffer is invalid.\r
+  @retval EFI_NOT_READY         Mouse is not changed status yet.\r
+  @retval EFI_SUCCESS           Mouse status is changed and get successful.\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
+\r
+  Event notification function for SIMPLE_POINTER.WaitForInput event.\r
+  Signal the event if there is input from mouse.\r
+\r
+  @param Event    event object\r
+  @param Context  event context\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+MouseWaitForInput (\r
+  IN  EFI_EVENT               Event,\r
+  IN  VOID                    *Context\r
+  );\r
+\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
+  @param Event      -  TimerEvent in PS2_MOUSE_DEV\r
+  @param Context    -  Pointer to PS2_MOUSE_DEV structure\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+PollMouse (\r
+  IN EFI_EVENT  Event,\r
+  IN VOID       *Context\r
+  );\r
+\r
+/**\r
+  I/O work flow of in 8042 data.\r
+\r
+  @param Data    Data value\r
+\r
+  @retval EFI_SUCCESS Success to excute I/O work flow\r
+  @retval EFI_TIMEOUT Keyboard controller time out.\r
+**/\r
+EFI_STATUS\r
+In8042Data (\r
+  IN OUT UINT8                            *Data\r
+  );\r
+\r
+/**\r
+  Check whether there is Ps/2 mouse device in system\r
+\r
+  @param MouseDev   - Mouse Private Data Structure\r
+\r
+  @retval TRUE      - Keyboard in System.\r
+  @retval FALSE     - Keyboard not in System.\r
+\r
+**/\r
+BOOLEAN\r
+CheckMouseConnect (\r
+  IN  PS2_MOUSE_DEV     *MouseDev\r
+  );\r
+\r
+#endif\r
diff --git a/MdeModulePkg/Bus/Isa/Ps2MouseDxe/Ps2MouseDxe.inf b/MdeModulePkg/Bus/Isa/Ps2MouseDxe/Ps2MouseDxe.inf
new file mode 100644 (file)
index 0000000..1d257f5
--- /dev/null
@@ -0,0 +1,76 @@
+## @file\r
+# PS2 Mouse Driver.\r
+#\r
+# This dirver provides support for PS2 based mice.\r
+#\r
+# Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
+#\r
+# This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution.  The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+##\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = Ps2MouseDxe\r
+  MODULE_UNI_FILE                = Ps2MouseDxe.uni\r
+  FILE_GUID                      = 202A2B0E-9A31-4812-B291-8747DF152439\r
+  MODULE_TYPE                    = UEFI_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  ENTRY_POINT                    = InitializePs2Mouse\r
+\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#  DRIVER_BINDING                = gPS2MouseDriver;\r
+#  COMPONENT_NAME                = gPs2MouseComponentName;\r
+#  COMPONENT_NAME2               = gPs2MouseComponentName2;\r
+#\r
+\r
+[Sources]\r
+  ComponentName.c\r
+  CommPs2.h\r
+  CommPs2.c\r
+  Ps2Mouse.h\r
+  Ps2Mouse.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+\r
+[LibraryClasses]\r
+  ReportStatusCodeLib\r
+  UefiBootServicesTableLib\r
+  MemoryAllocationLib\r
+  BaseMemoryLib\r
+  UefiLib\r
+  UefiDriverEntryPoint\r
+  DebugLib\r
+  PcdLib\r
+  IoLib\r
+  DevicePathLib\r
+\r
+[Protocols]\r
+  gEfiSioProtocolGuid                           ## TO_START\r
+  gEfiSimplePointerProtocolGuid                 ## BY_START\r
+  gEfiDevicePathProtocolGuid                    ## TO_START\r
+\r
+[FeaturePcd]\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdPs2MouseExtendedVerification   ## CONSUMES\r
+\r
+#\r
+# [Event]\r
+#\r
+#   ##\r
+#   # Timer event used to check the mouse state at a regular interval.\r
+#   #\r
+#   EVENT_TYPE_PERIODIC_TIMER   ## CONSUMES\r
+#\r
+\r
+[UserExtensions.TianoCore."ExtraFiles"]\r
+  Ps2MouseDxeExtra.uni\r
diff --git a/MdeModulePkg/Bus/Isa/Ps2MouseDxe/Ps2MouseDxe.uni b/MdeModulePkg/Bus/Isa/Ps2MouseDxe/Ps2MouseDxe.uni
new file mode 100644 (file)
index 0000000..4174744
--- /dev/null
@@ -0,0 +1,22 @@
+// /** @file\r
+// PS2 Mouse Driver.\r
+//\r
+// This dirver provides support for PS2 based mice.\r
+//\r
+// Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
+//\r
+// This program and the accompanying materials\r
+// are licensed and made available under the terms and conditions of the BSD License\r
+// which accompanies this distribution.  The full text of the license may be found at\r
+// http://opensource.org/licenses/bsd-license.php\r
+//\r
+// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+//\r
+// **/\r
+\r
+\r
+#string STR_MODULE_ABSTRACT             #language en-US "PS2 Mouse Driver"\r
+\r
+#string STR_MODULE_DESCRIPTION          #language en-US "This driver provides support for PS2-based mice."\r
+\r
diff --git a/MdeModulePkg/Bus/Isa/Ps2MouseDxe/Ps2MouseDxeExtra.uni b/MdeModulePkg/Bus/Isa/Ps2MouseDxe/Ps2MouseDxeExtra.uni
new file mode 100644 (file)
index 0000000..fee64d8
--- /dev/null
@@ -0,0 +1,20 @@
+// /** @file\r
+// Ps2MouseDxe Localized Strings and Content\r
+//\r
+// Copyright (c) 2013 - 2016, Intel Corporation. All rights reserved.<BR>\r
+//\r
+// This program and the accompanying materials\r
+// are licensed and made available under the terms and conditions of the BSD License\r
+// which accompanies this distribution.  The full text of the license may be found at\r
+// http://opensource.org/licenses/bsd-license.php\r
+//\r
+// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+//\r
+// **/\r
+\r
+#string STR_PROPERTIES_MODULE_NAME\r
+#language en-US\r
+"PS2 Mouse DXE Driver"\r
+\r
+\r
index e74b0d92ac907d9792d5ba871afc17625c98662c..49bd105db77b35a2b4ae663b5186ede1498ddd49 100644 (file)
   # @Prompt Enable export HII data and configuration to be used in OS runtime.\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdHiiOsRuntimeSupport|TRUE|BOOLEAN|0x00010074\r
 \r
+  ## Indicates if PS2 mouse does a extended verification during start.\r
+  #  Extended verification will take some performance. It can be set to FALSE for boot performance.<BR><BR>\r
+  #   TRUE  - Turn on PS2 mouse extended verification. <BR>\r
+  #   FALSE - Turn off PS2 mouse extended verification. <BR>\r
+  # @Prompt Turn on PS2 Mouse Extended Verification\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdPs2MouseExtendedVerification|TRUE|BOOLEAN|0x00010075\r
+\r
 [PcdsFeatureFlag.IA32, PcdsFeatureFlag.X64]\r
   ## Indicates if DxeIpl should switch to long mode to enter DXE phase.\r
   #  It is assumed that 64-bit DxeCore is built in firmware if it is true; otherwise 32-bit DxeCore\r
index f1d7a1470a34d2f9fd0e30d1b1a4fa7549708100..c2f51714511bad979a0a11c6b3df8f9e7288d013 100644 (file)
   MdeModulePkg/Bus/I2c/I2cDxe/I2cDxe.inf\r
   MdeModulePkg/Bus/Isa/IsaBusDxe/IsaBusDxe.inf\r
   MdeModulePkg/Bus/Isa/Ps2KeyboardDxe/Ps2KeyboardDxe.inf\r
+  MdeModulePkg/Bus/Isa/Ps2MouseDxe/Ps2MouseDxe.inf\r
 \r
   MdeModulePkg/Core/Dxe/DxeMain.inf {\r
     <LibraryClasses>\r