+++ /dev/null
-/** @file\r
- PS2 Mouse Communication Interface.\r
-\r
-Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
-SPDX-License-Identifier: BSD-2-Clause-Patent\r
-\r
-**/\r
-\r
-#include "Ps2MouseAbsolutePointer.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
- @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\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
- IN EFI_ISA_IO_PROTOCOL *IsaIo\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
-/**\r
- Issue command to enable 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
-KbcEnableAux (\r
- IN EFI_ISA_IO_PROTOCOL *IsaIo\r
- )\r
-{\r
- //\r
- // Send 8042 enable mouse command\r
- //\r
- return Out8042Command (IsaIo, 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
- IN EFI_ISA_IO_PROTOCOL *IsaIo\r
- )\r
-{\r
- //\r
- // Send 8042 disable mouse command\r
- //\r
- return Out8042Command (IsaIo, 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
- IN EFI_ISA_IO_PROTOCOL *IsaIo\r
- )\r
-{\r
- //\r
- // Send 8042 enable keyboard command\r
- //\r
- return Out8042Command (IsaIo, ENABLE_KB);\r
-}\r
-\r
-/**\r
- Issue command to disable 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
-KbcDisableKb (\r
- IN EFI_ISA_IO_PROTOCOL *IsaIo\r
- )\r
-{\r
- //\r
- // Send 8042 disable keyboard command\r
- //\r
- return Out8042Command (IsaIo, DISABLE_KB);\r
-}\r
-\r
-/**\r
- Issue command to check keyboard status.\r
-\r
- @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r
- @param KeyboardEnable return whether keyboard is enable.\r
-\r
- @return Status of command issuing.\r
-**/\r
-EFI_STATUS\r
-CheckKbStatus (\r
- IN EFI_ISA_IO_PROTOCOL *IsaIo,\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 (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
-/**\r
- Issue command to reset 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
-PS2MouseReset (\r
- IN EFI_ISA_IO_PROTOCOL *IsaIo\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
-/**\r
- Issue command to set mouse's sample rate\r
-\r
- @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r
- @param SampleRate value of sample rate\r
-\r
- @return Status of command issuing.\r
-**/\r
-EFI_STATUS\r
-PS2MouseSetSampleRate (\r
- IN EFI_ISA_IO_PROTOCOL *IsaIo,\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 (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
-/**\r
- Issue command to set mouse's resolution.\r
-\r
- @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r
- @param Resolution value of resolution\r
-\r
- @return Status of command issuing.\r
-**/\r
-EFI_STATUS\r
-PS2MouseSetResolution (\r
- IN EFI_ISA_IO_PROTOCOL *IsaIo,\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 (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
-/**\r
- Issue command to set mouse's scaling.\r
-\r
- @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r
- @param Scaling value of scaling\r
-\r
- @return Status of command issuing.\r
-**/\r
-EFI_STATUS\r
-PS2MouseSetScaling (\r
- IN EFI_ISA_IO_PROTOCOL *IsaIo,\r
- IN MOUSE_SF Scaling\r
- )\r
-{\r
- UINT8 Command;\r
-\r
- Command = (UINT8) (Scaling == Scaling1 ? 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
-/**\r
- Issue command to enable Ps2 mouse.\r
-\r
- @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r
-\r
- @return Status of command issuing.\r
-**/\r
-EFI_STATUS\r
-PS2MouseEnable (\r
- IN EFI_ISA_IO_PROTOCOL *IsaIo\r
- )\r
-{\r
- //\r
- // Send auxiliary command to enable mouse\r
- //\r
- return Out8042AuxCommand (IsaIo, ENABLE_CMD, FALSE);\r
-}\r
-\r
-/**\r
- Get mouse packet . Only care first 3 bytes\r
-\r
- @param MouseAbsolutePointerDev Pointer to PS2 Absolute Pointer Simulation Device 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_ABSOLUTE_POINTER_DEV *MouseAbsolutePointerDev\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 (MouseAbsolutePointerDev->IsaIo);\r
- Status = PS2MouseRead (MouseAbsolutePointerDev->IsaIo, &Data, &Count, State);\r
- if (EFI_ERROR (Status)) {\r
- KbcEnableAux (MouseAbsolutePointerDev->IsaIo);\r
- return EFI_NOT_READY;\r
- }\r
-\r
- if (Count != 1) {\r
- KbcEnableAux (MouseAbsolutePointerDev->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 (MouseAbsolutePointerDev->IsaIo, &KeyboardEnable);\r
- KbcDisableKb (MouseAbsolutePointerDev->IsaIo);\r
- KbcEnableAux (MouseAbsolutePointerDev->IsaIo);\r
- }\r
- break;\r
-\r
- case PS2_READ_DATA_BYTE:\r
- Count = 2;\r
- Status = PS2MouseRead (MouseAbsolutePointerDev->IsaIo, (Packet + 1), &Count, State);\r
- if (EFI_ERROR (Status)) {\r
- if (KeyboardEnable) {\r
- KbcEnableKb (MouseAbsolutePointerDev->IsaIo);\r
- }\r
-\r
- return EFI_NOT_READY;\r
- }\r
-\r
- if (Count != 2) {\r
- if (KeyboardEnable) {\r
- KbcEnableKb (MouseAbsolutePointerDev->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 (MouseAbsolutePointerDev->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
- MouseAbsolutePointerDev->State.CurrentX += RelativeMovementX;\r
- MouseAbsolutePointerDev->State.CurrentY -= RelativeMovementY;\r
- MouseAbsolutePointerDev->State.CurrentZ = 0;\r
- MouseAbsolutePointerDev->State.ActiveButtons = (UINT8) (LButton || RButton) & 0x3;\r
- MouseAbsolutePointerDev->StateChanged = TRUE;\r
-\r
- return EFI_SUCCESS;\r
- }\r
- }\r
-}\r
-\r
-/**\r
- Read data via IsaIo protocol with given number.\r
-\r
- @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\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
- IN EFI_ISA_IO_PROTOCOL *IsaIo,\r
- OUT VOID *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
- 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
-//\r
-// 8042 I/O function\r
-//\r
-/**\r
- I/O work flow of outing 8042 command.\r
-\r
- @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r
- @param Command I/O command.\r
-\r
- @retval EFI_SUCCESS Success to execute I/O work flow\r
- @retval EFI_TIMEOUT Keyboard controller time out.\r
-**/\r
-EFI_STATUS\r
-Out8042Command (\r
- IN EFI_ISA_IO_PROTOCOL *IsaIo,\r
- IN UINT8 Command\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
-/**\r
- I/O work flow of outing 8042 data.\r
-\r
- @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r
- @param Data Data value\r
-\r
- @retval EFI_SUCCESS Success to execute I/O work flow\r
- @retval EFI_TIMEOUT Keyboard controller time out.\r
-**/\r
-EFI_STATUS\r
-Out8042Data (\r
- IN EFI_ISA_IO_PROTOCOL *IsaIo,\r
- IN UINT8 Data\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
-/**\r
- I/O work flow of in 8042 data.\r
-\r
- @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r
- @param Data Data value\r
-\r
- @retval EFI_SUCCESS Success to execute I/O work flow\r
- @retval EFI_TIMEOUT Keyboard controller time out.\r
-**/\r
-EFI_STATUS\r
-In8042Data (\r
- IN EFI_ISA_IO_PROTOCOL *IsaIo,\r
- IN OUT UINT8 *Data\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 != 0);\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
-/**\r
- I/O work flow of outing 8042 Aux command.\r
-\r
- @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r
- @param Command Aux I/O command\r
- @param Resend Whether need resend the Aux command.\r
-\r
- @retval EFI_SUCCESS Success to execute I/O work flow\r
- @retval EFI_TIMEOUT Keyboard controller time out.\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 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
-/**\r
- I/O work flow of outing 8042 Aux data.\r
-\r
- @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r
- @param Data Buffer holding return value\r
-\r
- @retval EFI_SUCCESS Success to execute I/O work flow.\r
- @retval EFI_TIMEOUT Keyboard controller time out.\r
-**/\r
-EFI_STATUS\r
-Out8042AuxData (\r
- IN EFI_ISA_IO_PROTOCOL *IsaIo,\r
- IN UINT8 Data\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
-/**\r
- I/O work flow of in 8042 Aux data.\r
-\r
- @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r
- @param Data Buffer holding return value.\r
-\r
- @retval EFI_SUCCESS Success to execute I/O work flow\r
- @retval EFI_TIMEOUT Keyboard controller time out.\r
-**/\r
-EFI_STATUS\r
-In8042AuxData (\r
- IN EFI_ISA_IO_PROTOCOL *IsaIo,\r
- IN OUT UINT8 *Data\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
-\r
-/**\r
- Check keyboard controller status, if it is output buffer full and for auxiliary device.\r
-\r
- @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\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
- IN EFI_ISA_IO_PROTOCOL *IsaIo\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
-/**\r
- I/O work flow to wait input buffer empty in given time.\r
-\r
- @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\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 EFI_ISA_IO_PROTOCOL *IsaIo,\r
- IN UINTN Timeout\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 != 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 IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\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 EFI_ISA_IO_PROTOCOL *IsaIo,\r
- IN UINTN Timeout\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 != 0);\r
-\r
- if (Delay == 0) {\r
- return EFI_TIMEOUT;\r
- }\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r