/**@file\r
- PS/2 Keyboard driver\r
Routines that access 8042 keyboard controller\r
\r
Copyright (c) 2006 - 2007, Intel Corporation\r
\r
BOOLEAN mEnableMouseInterface;\r
\r
-//\r
-// Function declarations\r
-//\r
-UINT8\r
-KeyReadDataRegister (\r
- IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn\r
- );\r
-\r
-VOID\r
-KeyWriteDataRegister (\r
- IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn,\r
- IN UINT8 Data\r
- );\r
-\r
-VOID\r
-KeyWriteCommandRegister (\r
- IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn,\r
- IN UINT8 Data\r
- );\r
-\r
-VOID\r
-KeyboardError (\r
- IN KEYBOARD_CONSOLE_IN_DEV*ConsoleIn,\r
- IN CHAR16 *ErrMsg // should be a unicode string\r
- );\r
-\r
-EFI_STATUS\r
-GetScancodeBufHead (\r
- KEYBOARD_CONSOLE_IN_DEV *ConsoleIn,\r
- IN UINT32 Count,\r
- OUT UINT8 *Buf\r
- );\r
-\r
-EFI_STATUS\r
-PopScancodeBufHead (\r
- KEYBOARD_CONSOLE_IN_DEV *ConsoleIn,\r
- IN UINT32 Count,\r
- OUT UINT8 *Buf\r
- );\r
-\r
-EFI_STATUS\r
-KeyboardWrite (\r
- IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn,\r
- IN UINT8 Data\r
- );\r
-\r
-EFI_STATUS\r
-KeyboardCommand (\r
- IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn,\r
- IN UINT8 Data\r
- );\r
-\r
-EFI_STATUS\r
-KeyboardWaitForValue (\r
- IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn,\r
- IN UINT8 Value\r
- );\r
-\r
/**\r
Read data register \r
\r
&Data\r
);\r
\r
- //\r
- // outp(ConsoleIn->DataRegisterAddress, Data);\r
- //\r
}\r
\r
/**\r
)\r
{\r
ConsoleIn->KeyboardErr = TRUE;\r
-\r
- //\r
- // gST -> ConOut -> OutputString (gST -> ConOut, L"Keyboard Driver: ");\r
- // gST -> ConOut -> OutputString (gST -> ConOut, ErrMsg);\r
- //\r
}\r
\r
/**\r
the memory buffer or empty the keyboard buffer.\r
It is registered as running under TPL_NOTIFY\r
\r
- @param Event - The timer event\r
- @param Context - A KEYBOARD_CONSOLE_IN_DEV pointer\r
+ @param Event The timer event\r
+ @param Context A KEYBOARD_CONSOLE_IN_DEV pointer\r
\r
**/\r
VOID\r
gBS->RestoreTPL (OldTpl);\r
return ;\r
}\r
+\r
//\r
// To let KB driver support Hot plug, here should skip the 'resend' command for the case that\r
// KB is not connected to system. If KB is not connected to system, driver will find there's something\r
//\r
// if there is no key present, just return\r
//\r
- if ((KeyReadStatusRegister (Context) & 0x21) != 0x1) {\r
+ if ((KeyReadStatusRegister (Context) & (KEYBOARD_STATUS_REGISTER_TRANSMIT_TIMEOUT|KEYBOARD_STATUS_REGISTER_HAS_OUTPUT_DATA)) != KEYBOARD_STATUS_REGISTER_HAS_OUTPUT_DATA) {\r
//\r
// Leave critical section and return\r
//\r
// wait till output buffer full then perform the read\r
//\r
for (TimeOut = 0; TimeOut < KEYBOARD_TIMEOUT; TimeOut += 30) {\r
- if (KeyReadStatusRegister (ConsoleIn) & 0x01) {\r
+ if (KeyReadStatusRegister (ConsoleIn) & KEYBOARD_STATUS_REGISTER_HAS_OUTPUT_DATA) {\r
RegFilled = 1;\r
*Data = KeyReadDataRegister (ConsoleIn);\r
break;\r
}\r
\r
- gBS->Stall (30);\r
+ MicroSecondDelay (30);\r
}\r
\r
if (!RegFilled) {\r
@param ConsoleIn Pointer to instance of KEYBOARD_CONSOLE_IN_DEV\r
@param Data value wanted to be written\r
\r
- @retval EFI_TIMEOUT - GC_TODO: Add description for return value\r
- @retval EFI_SUCCESS - GC_TODO: Add description for return value\r
+ @retval EFI_TIMEOUT The input buffer register is full for putting new value util timeout\r
+ @retval EFI_SUCCESS The new value is sucess put into input buffer register.\r
\r
**/\r
EFI_STATUS\r
break;\r
}\r
\r
- gBS->Stall (30);\r
+ MicroSecondDelay (30);\r
}\r
\r
if (!RegEmptied) {\r
break;\r
}\r
\r
- gBS->Stall (30);\r
+ MicroSecondDelay (30);\r
}\r
\r
if (!RegEmptied) {\r
break;\r
}\r
\r
- gBS->Stall (30);\r
+ MicroSecondDelay (30);\r
}\r
\r
if (!RegEmptied) {\r
break;\r
}\r
\r
- gBS->Stall (30);\r
+ MicroSecondDelay (30);\r
}\r
\r
SumTimeOut += TimeOut;\r
//\r
// Check results\r
//\r
- if (GotIt) {\r
+ if (GotIt == 1) {\r
return EFI_SUCCESS;\r
} else {\r
return EFI_TIMEOUT;\r
\r
@param ConsoleIn Pointer to instance of KEYBOARD_CONSOLE_IN_DEV\r
\r
- @return status\r
+ @return status of updating keyboard register\r
\r
**/\r
EFI_STATUS\r
\r
@param ConsoleIn KEYBOARD_CONSOLE_IN_DEV instance pointer\r
\r
- @retval EFI_NOT_READY - Input from console not ready yet.\r
- @retval EFI_SUCCESS - Function executed successfully.\r
+ @retval EFI_NOT_READY Input from console not ready yet.\r
+ @retval EFI_SUCCESS Function executed successfully.\r
\r
**/\r
EFI_STATUS\r
// Check if there are enough bytes of scancode representing a single key\r
// available in the buffer\r
//\r
- while (1) {\r
+ while (TRUE) {\r
\r
Status = GetScancodeBufHead (ConsoleIn, 1, ScancodeArr);\r
ScancodeArrPos = 0;\r
//\r
if (Extended && ScanCode == 0x35) {\r
ConsoleIn->Key.ScanCode = SCAN_NULL;\r
- ConsoleIn->Key.UnicodeChar = '/';\r
+ ConsoleIn->Key.UnicodeChar = L'/';\r
return EFI_SUCCESS;\r
}\r
//\r
// Need not return associated shift state if a class of printable characters that\r
// are normally adjusted by shift modifiers. e.g. Shift Key + 'f' key = 'F'\r
//\r
- if (ConsoleIn->Key.UnicodeChar >= 'A' && ConsoleIn->Key.UnicodeChar <= 'Z') {\r
+ if (ConsoleIn->Key.UnicodeChar >= L'A' && ConsoleIn->Key.UnicodeChar <= L'Z') {\r
ConsoleIn->LeftShift = FALSE;\r
ConsoleIn->RightShift = FALSE;\r
}\r
// alphabetic key is affected by CapsLock State\r
//\r
if (ConsoleIn->CapsLock) {\r
- if (ConsoleIn->Key.UnicodeChar >= 'a' && ConsoleIn->Key.UnicodeChar <= 'z') {\r
+ if (ConsoleIn->Key.UnicodeChar >= L'a' && ConsoleIn->Key.UnicodeChar <= L'z') {\r
ConsoleIn->Key.UnicodeChar = ConvertKeyboardScanCodeToEfiKey[Index].ShiftUnicodeChar;\r
- } else if (ConsoleIn->Key.UnicodeChar >= 'A' && ConsoleIn->Key.UnicodeChar <= 'Z') {\r
+ } else if (ConsoleIn->Key.UnicodeChar >= L'A' && ConsoleIn->Key.UnicodeChar <= L'Z') {\r
ConsoleIn->Key.UnicodeChar = ConvertKeyboardScanCodeToEfiKey[Index].UnicodeChar;\r
}\r
}\r
// Translate the CTRL-Alpha characters to their corresponding control value (ctrl-a = 0x0001 through ctrl-Z = 0x001A)\r
//\r
if (ConsoleIn->Ctrled) {\r
- if (ConsoleIn->Key.UnicodeChar >= 'a' && ConsoleIn->Key.UnicodeChar <= 'z') {\r
- ConsoleIn->Key.UnicodeChar = (UINT16) (ConsoleIn->Key.UnicodeChar - 'a' + 1);\r
- } else if (ConsoleIn->Key.UnicodeChar >= 'A' && ConsoleIn->Key.UnicodeChar <= 'Z') {\r
- ConsoleIn->Key.UnicodeChar = (UINT16) (ConsoleIn->Key.UnicodeChar - 'A' + 1);\r
+ if (ConsoleIn->Key.UnicodeChar >= L'a' && ConsoleIn->Key.UnicodeChar <= L'z') {\r
+ ConsoleIn->Key.UnicodeChar = (UINT16) (ConsoleIn->Key.UnicodeChar - L'a' + 1);\r
+ } else if (ConsoleIn->Key.UnicodeChar >= L'A' && ConsoleIn->Key.UnicodeChar <= L'Z') {\r
+ ConsoleIn->Key.UnicodeChar = (UINT16) (ConsoleIn->Key.UnicodeChar - L'A' + 1);\r
}\r
}\r
\r
if (ConsoleIn->NumLock && !ConsoleIn->Shift && !Extended) {\r
ConsoleIn->Key.ScanCode = SCAN_NULL;\r
} else if (ScanCode != 0x4a && ScanCode != 0x4e) {\r
- ConsoleIn->Key.UnicodeChar = 0x00;\r
+ ConsoleIn->Key.UnicodeChar = 0x0000;\r
}\r
}\r
//\r
// If the key can not be converted then just return.\r
//\r
- if (ConsoleIn->Key.ScanCode == SCAN_NULL && ConsoleIn->Key.UnicodeChar == 0x00) {\r
+ if (ConsoleIn->Key.ScanCode == SCAN_NULL && ConsoleIn->Key.UnicodeChar == 0x0000) {\r
return EFI_NOT_READY;\r
}\r
\r
// Test the system flag in to determine whether this is the first\r
// time initialization\r
//\r
- if ((KeyReadStatusRegister (ConsoleIn) & 0x04)) {\r
+ if ((KeyReadStatusRegister (ConsoleIn) & KEYBOARD_STATUS_REGISTER_SYSTEM_FLAG)) {\r
//\r
// 8042 controller is already setup (by myself or by mouse driver):\r
// See whether mouse interface is already enabled\r
//\r
// Read the command byte of 8042 controller\r
//\r
- Status = KeyboardCommand (ConsoleIn, 0x20);\r
+ Status = KeyboardCommand (ConsoleIn, KEYBOARD_8042_COMMAND_READ);\r
if (EFI_ERROR (Status)) {\r
KeyboardError (ConsoleIn, L"\n\r");\r
goto Done;\r
//\r
// Disable keyboard and mouse interfaces\r
//\r
- Status = KeyboardCommand (ConsoleIn, 0xad);\r
+ Status = KeyboardCommand (ConsoleIn, KEYBOARD_8042_COMMAND_DISABLE_KEYBOARD_INTERFACE);\r
if (EFI_ERROR (Status)) {\r
KeyboardError (ConsoleIn, L"\n\r");\r
goto Done;\r
}\r
\r
- Status = KeyboardCommand (ConsoleIn, 0xa7);\r
+ Status = KeyboardCommand (ConsoleIn, KEYBOARD_8042_COMMAND_DISABLE_MOUSE_INTERFACE);\r
if (EFI_ERROR (Status)) {\r
KeyboardError (ConsoleIn, L"\n\r");\r
goto Done;\r
//\r
// 8042 Controller Self Test\r
//\r
- Status = KeyboardCommand (ConsoleIn, 0xaa);\r
+ Status = KeyboardCommand (ConsoleIn, KEYBOARD_8042_COMMAND_CONTROLLER_SELF_TEST);\r
if (EFI_ERROR (Status)) {\r
KeyboardError (ConsoleIn, L"8042 controller command write error!\n\r");\r
goto Done;\r
// 1: Enable Auxiliary device interrupt\r
// 0: Enable Keyboard interrupt )\r
//\r
- Status = KeyboardCommand (ConsoleIn, 0x60);\r
+ Status = KeyboardCommand (ConsoleIn, KEYBOARD_8042_COMMAND_WRITE);\r
if (EFI_ERROR (Status)) {\r
KeyboardError (ConsoleIn, L"8042 controller command write error!\n\r");\r
goto Done;\r
//\r
// Keyboard Interface Test\r
//\r
- Status = KeyboardCommand (ConsoleIn, 0xab);\r
+ Status = KeyboardCommand (ConsoleIn, KEYBOARD_8042_COMMAND_KEYBOARD_INTERFACE_SELF_TEST);\r
if (EFI_ERROR (Status)) {\r
KeyboardError (ConsoleIn, L"8042 controller command write error!\n\r");\r
goto Done;\r
//\r
// Keyboard reset with a BAT(Basic Assurance Test)\r
//\r
- Status = KeyboardWrite (ConsoleIn, 0xff);\r
+ Status = KeyboardWrite (ConsoleIn, KEYBOARD_8048_COMMAND_RESET);\r
if (EFI_ERROR (Status)) {\r
KeyboardError (ConsoleIn, L"8042 controller data write error!\n\r");\r
goto Done;\r
}\r
\r
- Status = KeyboardWaitForValue (ConsoleIn, 0xfa);\r
+ Status = KeyboardWaitForValue (ConsoleIn, KEYBOARD_8048_RETURN_8042_ACK);\r
if (EFI_ERROR (Status)) {\r
KeyboardError (ConsoleIn, L"Some specific value not aquired from 8042 controller!\n\r");\r
goto Done;\r
//\r
mWaitForValueTimeOut = KEYBOARD_BAT_TIMEOUT;\r
\r
- Status = KeyboardWaitForValue (ConsoleIn, 0xaa);\r
+ Status = KeyboardWaitForValue (ConsoleIn, KEYBOARD_8048_RETURN_8042_BAT_SUCCESS);\r
if (EFI_ERROR (Status)) {\r
KeyboardError (ConsoleIn, L"Keyboard self test failed!\n\r");\r
goto Done;\r
//\r
// Set Keyboard to use Scan Code Set 2\r
//\r
- Status = KeyboardWrite (ConsoleIn, 0xf0);\r
+ Status = KeyboardWrite (ConsoleIn, KEYBOARD_8048_COMMAND_SELECT_SCAN_CODE_SET);\r
if (EFI_ERROR (Status)) {\r
KeyboardError (ConsoleIn, L"8042 controller data write error!\n\r");\r
goto Done;\r
}\r
\r
- Status = KeyboardWaitForValue (ConsoleIn, 0xfa);\r
+ Status = KeyboardWaitForValue (ConsoleIn, KEYBOARD_8048_RETURN_8042_ACK);\r
if (EFI_ERROR (Status)) {\r
KeyboardError (ConsoleIn, L"Some specific value not aquired from 8042 controller!\n\r");\r
goto Done;\r
goto Done;\r
}\r
\r
- Status = KeyboardWaitForValue (ConsoleIn, 0xfa);\r
+ Status = KeyboardWaitForValue (ConsoleIn, KEYBOARD_8048_RETURN_8042_ACK);\r
if (EFI_ERROR (Status)) {\r
KeyboardError (ConsoleIn, L"Some specific value not aquired from 8042 controller!\n\r");\r
goto Done;\r
//\r
// Clear Keyboard Scancode Buffer\r
//\r
- Status = KeyboardWrite (ConsoleIn, 0xf4);\r
+ Status = KeyboardWrite (ConsoleIn, KEYBOARD_8048_COMMAND_CLEAR_OUTPUT_DATA);\r
if (EFI_ERROR (Status)) {\r
KeyboardError (ConsoleIn, L"8042 controller data write error!\n\r");\r
goto Done;\r
}\r
\r
- Status = KeyboardWaitForValue (ConsoleIn, 0xfa);\r
+ Status = KeyboardWaitForValue (ConsoleIn, KEYBOARD_8048_RETURN_8042_ACK);\r
if (EFI_ERROR (Status)) {\r
KeyboardError (ConsoleIn, L"Some specific value not aquired from 8042 controller!\n\r");\r
goto Done;\r
//\r
// Enable mouse interface\r
//\r
- Status1 = KeyboardCommand (ConsoleIn, 0xa8);\r
+ Status1 = KeyboardCommand (ConsoleIn, KEYBOARD_8042_COMMAND_ENABLE_MOUSE_INTERFACE);\r
if (EFI_ERROR (Status1)) {\r
KeyboardError (ConsoleIn, L"8042 controller command write error!\n\r");\r
return EFI_DEVICE_ERROR;\r
//\r
// Disable keyboard interface\r
//\r
- Status = KeyboardCommand (ConsoleIn, 0xad);\r
+ Status = KeyboardCommand (ConsoleIn, KEYBOARD_8042_COMMAND_DISABLE_KEYBOARD_INTERFACE);\r
if (EFI_ERROR (Status)) {\r
KeyboardError (ConsoleIn, L"\n\r");\r
return EFI_DEVICE_ERROR;\r
/**@file\r
- PS/2 Keyboard driver\r
- Routines that support SIMPLE_TEXT_IN protocol\r
+ Routines implements SIMPLE_TEXT_IN protocol's interfaces based on 8042 interfaces\r
+ provided by Ps2KbdCtrller.c.\r
\r
Copyright (c) 2006 - 2007, Intel Corporation\r
All rights reserved. This program and the accompanying materials\r
\r
#include "Ps2Keyboard.h"\r
\r
-//\r
-// function declarations\r
-//\r
+/**\r
+ Check keyboard for given key value\r
+ \r
+ @param This Point to instance of EFI_SIMPLE_TEXT_INPUT_PROTOCOL\r
+ \r
+ @retval EFI_SUCCESS success check keyboard value\r
+ @retval !EFI_SUCCESS Fail to get char from keyboard\r
+**/\r
EFI_STATUS\r
-EFIAPI\r
-KeyboardEfiReset (\r
- IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,\r
- IN BOOLEAN ExtendedVerification\r
- );\r
+KeyboardCheckForKey (\r
+ IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This\r
+ )\r
+{\r
+ KEYBOARD_CONSOLE_IN_DEV *ConsoleIn;\r
\r
-EFI_STATUS\r
-EFIAPI\r
-KeyboardReadKeyStroke (\r
- IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,\r
- OUT EFI_INPUT_KEY *Key\r
- );\r
+ ConsoleIn = KEYBOARD_CONSOLE_IN_DEV_FROM_THIS (This);\r
\r
-VOID\r
-EFIAPI\r
-KeyboardWaitForKey (\r
- IN EFI_EVENT Event,\r
- IN VOID *Context\r
- );\r
+ //\r
+ // If ready to read next key, check it\r
+ //\r
+ if (ConsoleIn->Key.ScanCode == SCAN_NULL && ConsoleIn->Key.UnicodeChar == 0x00) {\r
+ return KeyGetchar (ConsoleIn);\r
+ }\r
\r
-EFI_STATUS\r
-KeyboardCheckForKey (\r
- IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This\r
- );\r
+ return EFI_SUCCESS;\r
+}\r
\r
/**\r
- @param RegsiteredData - A pointer to a buffer that is filled in with the keystroke \r
- state data for the key that was registered.\r
- @param InputData - A pointer to a buffer that is filled in with the keystroke \r
- state data for the key that was pressed.\r
+ Judge whether is a registed key\r
+\r
+ @param RegsiteredData A pointer to a buffer that is filled in with the keystroke \r
+ state data for the key that was registered.\r
+ @param InputData A pointer to a buffer that is filled in with the keystroke \r
+ state data for the key that was pressed.\r
\r
- @retval TRUE - Key be pressed matches a registered key.\r
- @retval FALSE - Match failed. \r
+ @retval TRUE Key be pressed matches a registered key.\r
+ @retval FLASE Match failed. \r
\r
**/\r
BOOLEAN\r
IsKeyRegistered (\r
IN EFI_KEY_DATA *RegsiteredData,\r
IN EFI_KEY_DATA *InputData\r
- );\r
+ )\r
+\r
+{\r
+ ASSERT (RegsiteredData != NULL && InputData != NULL);\r
+ \r
+ if ((RegsiteredData->Key.ScanCode != InputData->Key.ScanCode) ||\r
+ (RegsiteredData->Key.UnicodeChar != InputData->Key.UnicodeChar)) {\r
+ return FALSE; \r
+ } \r
+ \r
+ //\r
+ // Assume KeyShiftState/KeyToggleState = 0 in Registered key data means these state could be ignored.\r
+ //\r
+ if (RegsiteredData->KeyState.KeyShiftState != 0 &&\r
+ RegsiteredData->KeyState.KeyShiftState != InputData->KeyState.KeyShiftState) {\r
+ return FALSE; \r
+ } \r
+ if (RegsiteredData->KeyState.KeyToggleState != 0 &&\r
+ RegsiteredData->KeyState.KeyToggleState != InputData->KeyState.KeyToggleState) {\r
+ return FALSE; \r
+ } \r
+ \r
+ return TRUE;\r
+\r
+}\r
\r
/**\r
Reads the next keystroke from the input device. The WaitForKey Event can \r
be used to test for existance of a keystroke via WaitForEvent () call.\r
-\r
\r
- @param ConsoleInDev - Ps2 Keyboard private structure\r
- @param KeyData - A pointer to a buffer that is filled in with the keystroke \r
- state data for the key that was pressed.\r
+ @param ConsoleInDev Ps2 Keyboard private structure\r
+ @param KeyData A pointer to a buffer that is filled in with the keystroke \r
+ state data for the key that was pressed.\r
\r
\r
- @retval EFI_SUCCESS - The keystroke information was returned.\r
- @retval EFI_NOT_READY - There was no keystroke data availiable.\r
- @retval EFI_DEVICE_ERROR - The keystroke information was not returned due to \r
- hardware errors.\r
- @retval EFI_INVALID_PARAMETER - KeyData is NULL. \r
+ @retval EFI_SUCCESS The keystroke information was returned.\r
+ @retval EFI_NOT_READY There was no keystroke data availiable.\r
+ @retval EFI_DEVICE_ERROR The keystroke information was not returned due to \r
+ hardware errors.\r
+ @retval EFI_INVALID_PARAMETER KeyData is NULL. \r
\r
**/\r
EFI_STATUS\r
LIST_ENTRY *Link;\r
KEYBOARD_CONSOLE_IN_EX_NOTIFY *CurrentNotify;\r
EFI_KEY_DATA OriginalKeyData;\r
+ \r
if (KeyData == NULL) {\r
return EFI_INVALID_PARAMETER;\r
}\r
gBS->RestoreTPL (OldTpl);\r
return EFI_NOT_READY;\r
}\r
+ \r
CopyMem (&KeyData->Key, &ConsoleInDev->Key, sizeof (EFI_INPUT_KEY));\r
\r
ConsoleInDev->Key.ScanCode = SCAN_NULL; \r
if (ConsoleInDev->Ctrled) {\r
if (OriginalKeyData.Key.UnicodeChar >= 0x01 && OriginalKeyData.Key.UnicodeChar <= 0x1A) {\r
if (ConsoleInDev->CapsLock) {\r
- OriginalKeyData.Key.UnicodeChar = (CHAR16)(OriginalKeyData.Key.UnicodeChar + 'A' - 1);\r
+ OriginalKeyData.Key.UnicodeChar = (CHAR16)(OriginalKeyData.Key.UnicodeChar + L'A' - 1);\r
} else {\r
- OriginalKeyData.Key.UnicodeChar = (CHAR16)(OriginalKeyData.Key.UnicodeChar + 'a' - 1);\r
+ OriginalKeyData.Key.UnicodeChar = (CHAR16)(OriginalKeyData.Key.UnicodeChar + L'a' - 1);\r
} \r
}\r
}\r
}\r
\r
/**\r
- logic reset keyboard\r
- Implement SIMPLE_TEXT_IN.Reset()\r
- Perform 8042 controller and keyboard initialization\r
+ Perform 8042 controller and keyboard initialization which implement SIMPLE_TEXT_IN.Reset()\r
\r
- @param This Pointer to instance of EFI_SIMPLE_TEXT_INPUT_PROTOCOL\r
+ @param This Pointer to instance of EFI_SIMPLE_TEXT_INPUT_PROTOCOL\r
@param ExtendedVerification Indicate that the driver may perform a more \r
exhaustive verification operation of the device during \r
reset, now this par is ignored in this driver \r
}\r
\r
/**\r
- Implement SIMPLE_TEXT_IN.ReadKeyStroke().\r
- Retrieve key values for driver user.\r
+ Retrieve key values for driver user which implement SIMPLE_TEXT_IN.ReadKeyStroke().\r
\r
@param This Pointer to instance of EFI_SIMPLE_TEXT_INPUT_PROTOCOL\r
@param Key The output buffer for key value \r
return ;\r
}\r
\r
-/**\r
- Check keyboard for given key value\r
- \r
- @param This Point to instance of EFI_SIMPLE_TEXT_INPUT_PROTOCOL\r
- \r
- @retval EFI_SUCCESS success check keyboard value\r
-**/\r
-EFI_STATUS\r
-KeyboardCheckForKey (\r
- IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This\r
- )\r
-{\r
- KEYBOARD_CONSOLE_IN_DEV *ConsoleIn;\r
-\r
- ConsoleIn = KEYBOARD_CONSOLE_IN_DEV_FROM_THIS (This);\r
-\r
- //\r
- // If ready to read next key, check it\r
- //\r
- if (ConsoleIn->Key.ScanCode == SCAN_NULL && ConsoleIn->Key.UnicodeChar == 0x00) {\r
- return KeyGetchar (ConsoleIn);\r
- }\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
- Judge whether is a registed key\r
-\r
- @param RegsiteredData - A pointer to a buffer that is filled in with the keystroke \r
- state data for the key that was registered.\r
- @param InputData - A pointer to a buffer that is filled in with the keystroke \r
- state data for the key that was pressed.\r
-\r
- @retval TRUE - Key be pressed matches a registered key.\r
- @retval FLASE - Match failed. \r
- \r
-**/\r
-BOOLEAN\r
-IsKeyRegistered (\r
- IN EFI_KEY_DATA *RegsiteredData,\r
- IN EFI_KEY_DATA *InputData\r
- )\r
-\r
-{\r
- ASSERT (RegsiteredData != NULL && InputData != NULL);\r
- \r
- if ((RegsiteredData->Key.ScanCode != InputData->Key.ScanCode) ||\r
- (RegsiteredData->Key.UnicodeChar != InputData->Key.UnicodeChar)) {\r
- return FALSE; \r
- } \r
- \r
- //\r
- // Assume KeyShiftState/KeyToggleState = 0 in Registered key data means these state could be ignored.\r
- //\r
- if (RegsiteredData->KeyState.KeyShiftState != 0 &&\r
- RegsiteredData->KeyState.KeyShiftState != InputData->KeyState.KeyShiftState) {\r
- return FALSE; \r
- } \r
- if (RegsiteredData->KeyState.KeyToggleState != 0 &&\r
- RegsiteredData->KeyState.KeyToggleState != InputData->KeyState.KeyToggleState) {\r
- return FALSE; \r
- } \r
- \r
- return TRUE;\r
-\r
-}\r
-\r
/**\r
Event notification function for SIMPLE_TEXT_INPUT_EX_PROTOCOL.WaitForKeyEx event\r
Signal the event if there is key available\r
/**\r
Reset the input device and optionaly run diagnostics\r
\r
- @param This - Protocol instance pointer.\r
- @param ExtendedVerification - Driver may perform diagnostics on reset.\r
+ @param This Protocol instance pointer.\r
+ @param ExtendedVerification Driver may perform diagnostics on reset.\r
\r
- @retval EFI_SUCCESS - The device was reset.\r
- @retval EFI_DEVICE_ERROR - The device is not functioning properly and could \r
+ @retval EFI_SUCCESS The device was reset.\r
+ @retval EFI_DEVICE_ERROR The device is not functioning properly and could \r
not be reset.\r
\r
**/\r
be used to test for existance of a keystroke via WaitForEvent () call.\r
\r
\r
- @param This - Protocol instance pointer.\r
- @param KeyData - A pointer to a buffer that is filled in with the keystroke \r
- state data for the key that was pressed.\r
+ @param This Protocol instance pointer.\r
+ @param KeyData A pointer to a buffer that is filled in with the keystroke \r
+ state data for the key that was pressed.\r
\r
- @retval EFI_SUCCESS - The keystroke information was returned.\r
- @retval EFI_NOT_READY - There was no keystroke data availiable.\r
- @retval EFI_DEVICE_ERROR - The keystroke information was not returned due to \r
- hardware errors.\r
- @retval EFI_INVALID_PARAMETER - KeyData is NULL. \r
+ @retval EFI_SUCCESS The keystroke information was returned.\r
+ @retval EFI_NOT_READY There was no keystroke data availiable.\r
+ @retval EFI_DEVICE_ERROR The keystroke information was not returned due to \r
+ hardware errors.\r
+ @retval EFI_INVALID_PARAMETER KeyData is NULL. \r
\r
**/\r
EFI_STATUS\r
/**\r
Set certain state for the input device.\r
\r
- @param This - Protocol instance pointer.\r
- @param KeyToggleState - A pointer to the EFI_KEY_TOGGLE_STATE to set the \r
- state for the input device.\r
+ @param This Protocol instance pointer.\r
+ @param KeyToggleState A pointer to the EFI_KEY_TOGGLE_STATE to set the \r
+ state for the input device.\r
\r
- @retval EFI_SUCCESS - The device state was set successfully.\r
- @retval EFI_DEVICE_ERROR - The device is not functioning correctly and could \r
- not have the setting adjusted.\r
- @retval EFI_UNSUPPORTED - The device does not have the ability to set its state.\r
- @retval EFI_INVALID_PARAMETER - KeyToggleState is NULL. \r
+ @retval EFI_SUCCESS The device state was set successfully.\r
+ @retval EFI_DEVICE_ERROR The device is not functioning correctly and could \r
+ not have the setting adjusted.\r
+ @retval EFI_UNSUPPORTED The device does not have the ability to set its state.\r
+ @retval EFI_INVALID_PARAMETER KeyToggleState is NULL. \r
\r
**/ \r
EFI_STATUS\r
/**\r
Register a notification function for a particular keystroke for the input device.\r
\r
- @param This - Protocol instance pointer.\r
- @param KeyData - A pointer to a buffer that is filled in with the keystroke \r
- information data for the key that was pressed.\r
- @param KeyNotificationFunction - Points to the function to be called when the key \r
- sequence is typed specified by KeyData. \r
- @param NotifyHandle - Points to the unique handle assigned to the registered notification. \r
+ @param This Protocol instance pointer.\r
+ @param KeyData A pointer to a buffer that is filled in with the keystroke \r
+ information data for the key that was pressed.\r
+ @param KeyNotificationFunction Points to the function to be called when the key \r
+ sequence is typed specified by KeyData. \r
+ @param NotifyHandle Points to the unique handle assigned to the registered notification. \r
\r
- @retval EFI_SUCCESS - The notification function was registered successfully.\r
- @retval EFI_OUT_OF_RESOURCES - Unable to allocate resources for necesssary data structures.\r
- @retval EFI_INVALID_PARAMETER - KeyData or NotifyHandle is NULL. \r
+ @retval EFI_SUCCESS The notification function was registered successfully.\r
+ @retval EFI_OUT_OF_RESOURCES Unable to allocate resources for necesssary data structures.\r
+ @retval EFI_INVALID_PARAMETER KeyData or NotifyHandle or KeyNotificationFunction is NULL. \r
\r
**/ \r
EFI_STATUS\r
/**\r
Remove a registered notification function from a particular keystroke.\r
\r
- @param This - Protocol instance pointer. \r
- @param NotificationHandle - The handle of the notification function being unregistered.\r
+ @param This Protocol instance pointer. \r
+ @param NotificationHandle The handle of the notification function being unregistered.\r
\r
\r
- @retval EFI_SUCCESS - The notification function was unregistered successfully.\r
- @retval EFI_INVALID_PARAMETER - The NotificationHandle is invalid.\r
+ @retval EFI_SUCCESS The notification function was unregistered successfully.\r
+ @retval EFI_INVALID_PARAMETER The NotificationHandle is invalid.\r
\r
**/ \r
EFI_STATUS\r
}\r
\r
/**\r
- The user Entry Point for module Ps2Keyboard. The user code starts with this function.\r
+ The module Entry Point for module Ps2Keyboard. \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
#include <Library/MemoryAllocationLib.h>\r
#include <Library/BaseLib.h>\r
#include <Library/BaseMemoryLib.h>\r
+#include <Library/TimerLib.h>\r
\r
//\r
// Global Variables\r
#define SCANCODE_SYS_REQ_MAKE 0x37\r
#define SCANCODE_MAX_MAKE 0x60\r
\r
+#define KEYBOARD_STATUS_REGISTER_HAS_OUTPUT_DATA BIT0 ///< 0 - Output register has no data; 1 - Output register has data\r
+#define KEYBOARD_STATUS_REGISTER_HAS_INPUT_DATA BIT1 ///< 0 - Input register has no data; 1 - Input register has data\r
+#define KEYBOARD_STATUS_REGISTER_SYSTEM_FLAG BIT2 ///< Set to 0 after power on reset\r
+#define KEYBOARD_STATUS_REGISTER_INPUT_DATA_TYPE BIT3 ///< 0 - Data in input register is data; 1 - Data in input register is command\r
+#define KEYBOARD_STATUS_REGISTER_ENABLE_FLAG BIT4 ///< 0 - Keyboard is disable; 1 - Keyboard is enable\r
+#define KEYBOARD_STATUS_REGISTER_TRANSMIT_TIMEOUT BIT5 ///< 0 - Transmit is complete without timeout; 1 - Transmit is timeout without complete\r
+#define KEYBOARD_STATUS_REGISTER_RECEIVE_TIMEOUT BIT6 ///< 0 - Receive is complete without timeout; 1 - Receive is timeout without complete\r
+#define KEYBOARD_STATUS_REGISTER_PARITY BIT7 ///< 0 - Odd parity; 1 - Even parity\r
+\r
+#define KEYBOARD_8042_COMMAND_READ 0x20\r
+#define KEYBOARD_8042_COMMAND_WRITE 0x60\r
+#define KEYBOARD_8042_COMMAND_DISABLE_MOUSE_INTERFACE 0xA7\r
+#define KEYBOARD_8042_COMMAND_ENABLE_MOUSE_INTERFACE 0xA8\r
+#define KEYBOARD_8042_COMMAND_CONTROLLER_SELF_TEST 0xAA\r
+#define KEYBOARD_8042_COMMAND_KEYBOARD_INTERFACE_SELF_TEST 0xAB\r
+#define KEYBOARD_8042_COMMAND_DISABLE_KEYBOARD_INTERFACE 0xAD\r
+\r
+#define KEYBOARD_8048_COMMAND_CLEAR_OUTPUT_DATA 0xF4\r
+#define KEYBOARD_8048_COMMAND_RESET 0xFF\r
+#define KEYBOARD_8048_COMMAND_SELECT_SCAN_CODE_SET 0xF0\r
+\r
+#define KEYBOARD_8048_RETURN_8042_BAT_SUCCESS 0xAA\r
+#define KEYBOARD_8048_RETURN_8042_BAT_ERROR 0xFC\r
+#define KEYBOARD_8048_RETURN_8042_ACK 0xFA\r
+\r
+\r
//\r
// Keyboard Controller Status\r
//\r
UefiDriverEntryPoint\r
BaseLib\r
BaseMemoryLib\r
-\r
+ TimerLib\r
+ \r
[Protocols]\r
gEfiPs2PolicyProtocolGuid # PROTOCOL TO_START\r
gEfiIsaIoProtocolGuid # PROTOCOL TO_START\r