Home | History | Annotate | Download | only in KeyboardDxe
      1 /** @file
      2 
      3 Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
      4 
      5 This program and the accompanying materials
      6 are licensed and made available under the terms and conditions
      7 of the BSD License which accompanies this distribution.  The
      8 full text of the license may be found at
      9 http://opensource.org/licenses/bsd-license.php
     10 
     11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
     12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     13 
     14 **/
     15 
     16 #ifndef _BIOS_KEYBOARD_H_
     17 #define _BIOS_KEYBOARD_H_
     18 
     19 
     20 #include <FrameworkDxe.h>
     21 
     22 #include <Guid/StatusCodeDataTypeId.h>
     23 #include <Protocol/SimpleTextIn.h>
     24 #include <Protocol/SimpleTextInEx.h>
     25 #include <Protocol/LegacyBios.h>
     26 #include <Protocol/IsaIo.h>
     27 #include <Protocol/DevicePath.h>
     28 #include <Protocol/Ps2Policy.h>
     29 
     30 #include <Library/DebugLib.h>
     31 #include <Library/UefiLib.h>
     32 #include <Library/BaseMemoryLib.h>
     33 #include <Library/ReportStatusCodeLib.h>
     34 #include <Library/UefiDriverEntryPoint.h>
     35 #include <Library/UefiBootServicesTableLib.h>
     36 #include <Library/MemoryAllocationLib.h>
     37 #include <Library/BaseLib.h>
     38 #include <Library/PcdLib.h>
     39 
     40 //
     41 // Driver Binding Externs
     42 //
     43 extern EFI_DRIVER_BINDING_PROTOCOL  gBiosKeyboardDriverBinding;
     44 extern EFI_COMPONENT_NAME_PROTOCOL  gBiosKeyboardComponentName;
     45 extern EFI_COMPONENT_NAME2_PROTOCOL gBiosKeyboardComponentName2;
     46 
     47 
     48 #include <IndustryStandard/Pci.h>
     49 
     50 //
     51 // BISO Keyboard Defines
     52 //
     53 #define CHAR_SCANCODE                   0xe0
     54 #define CHAR_ESC                        0x1b
     55 
     56 #define KEYBOARD_8042_DATA_REGISTER     0x60
     57 #define KEYBOARD_8042_STATUS_REGISTER   0x64
     58 #define KEYBOARD_8042_COMMAND_REGISTER  0x64
     59 
     60 #define KEYBOARD_TIMEOUT                65536   // 0.07s
     61 #define KEYBOARD_WAITFORVALUE_TIMEOUT   1000000 // 1s
     62 #define KEYBOARD_BAT_TIMEOUT            4000000 // 4s
     63 #define KEYBOARD_TIMER_INTERVAL         200000  // 0.02s
     64 //  KEYBOARD COMMAND BYTE -- read by writing command KBC_CMDREG_VIA64_CMDBYTE_R to 64H, then read from 60H
     65 //                           write by wrting command KBC_CMDREG_VIA64_CMDBYTE_W to 64H, then write to  60H
     66 //  7: Reserved
     67 //  6: PC/XT translation mode convert
     68 //  5: Disable Auxiliary device interface
     69 //  4: Disable keyboard interface
     70 //  3: Reserved
     71 //  2: System Flag: selftest successful
     72 //  1: Enable Auxiliary device interrupt
     73 //  0: Enable Keyboard interrupt )
     74 //
     75 #define KB_CMMBYTE_KSCAN2UNI_COV  (0x1 << 6)
     76 #define KB_CMMBYTE_DISABLE_AUX    (0x1 << 5)
     77 #define KB_CMMBYTE_DISABLE_KB     (0x1 << 4)
     78 #define KB_CMMBYTE_SLFTEST_SUCC   (0x1 << 2)
     79 #define KB_CMMBYTE_ENABLE_AUXINT  (0x1 << 1)
     80 #define KB_CMMBYTE_ENABLE_KBINT   (0x1 << 0)
     81 
     82 //
     83 //  KEYBOARD CONTROLLER STATUS REGISTER - read from 64h
     84 //  7: Parity error
     85 //  6: General time out
     86 //  5: Output buffer holds data for AUX
     87 //  4: Keyboard is not locked
     88 //  3: Command written via 64h  / Data written via 60h
     89 //  2: KBC self-test successful / Power-on reset
     90 //  1: Input buffer holds CPU data / empty
     91 //  0: Output buffer holds keyboard data / empty
     92 //
     93 #define KBC_STSREG_VIA64_PARE (0x1 << 7)
     94 #define KBC_STSREG_VIA64_TIM  (0x1 << 6)
     95 #define KBC_STSREG_VIA64_AUXB (0x1 << 5)
     96 #define KBC_STSREG_VIA64_KEYL (0x1 << 4)
     97 #define KBC_STSREG_VIA64_C_D  (0x1 << 3)
     98 #define KBC_STSREG_VIA64_SYSF (0x1 << 2)
     99 #define KBC_STSREG_VIA64_INPB (0x1 << 1)
    100 #define KBC_STSREG_VIA64_OUTB (0x1 << 0)
    101 
    102 //
    103 //  COMMANDs of KEYBOARD CONTROLLER COMMAND REGISTER - write to 64h
    104 //
    105 #define KBC_CMDREG_VIA64_CMDBYTE_R    0x20
    106 #define KBC_CMDREG_VIA64_CMDBYTE_W    0x60
    107 #define KBC_CMDREG_VIA64_AUX_DISABLE  0xA7
    108 #define KBC_CMDREG_VIA64_AUX_ENABLE   0xA8
    109 #define KBC_CMDREG_VIA64_KBC_SLFTEST  0xAA
    110 #define KBC_CMDREG_VIA64_KB_CKECK     0xAB
    111 #define KBC_CMDREG_VIA64_KB_DISABLE   0xAD
    112 #define KBC_CMDREG_VIA64_KB_ENABLE    0xAE
    113 #define KBC_CMDREG_VIA64_INTP_LOW_R   0xC0
    114 #define KBC_CMDREG_VIA64_INTP_HIGH_R  0xC2
    115 #define KBC_CMDREG_VIA64_OUTP_R       0xD0
    116 #define KBC_CMDREG_VIA64_OUTP_W       0xD1
    117 #define KBC_CMDREG_VIA64_OUTB_KB_W    0xD2
    118 #define KBC_CMDREG_VIA64_OUTB_AUX_W   0xD3
    119 #define KBC_CMDREG_VIA64_AUX_W        0xD4
    120 
    121 //
    122 //  echos of KEYBOARD CONTROLLER COMMAND - read from 60h
    123 //
    124 #define KBC_CMDECHO_KBCSLFTEST_OK 0x55
    125 #define KBC_CMDECHO_KBCHECK_OK    0x00
    126 #define KBC_CMDECHO_ACK           0xFA
    127 #define KBC_CMDECHO_BATTEST_OK    0xAA
    128 #define KBC_CMDECHO_BATTEST_FAILE 0xFC
    129 
    130 //
    131 // OUTPUT PORT COMMANDs - write port by writing KBC_CMDREG_VIA64_OUTP_W via 64H, then write the command to 60H
    132 // drive data and clock of KB to high for at least 500us for BAT needs
    133 //
    134 #define KBC_OUTPORT_DCHIGH_BAT  0xC0
    135 //
    136 // scan code set type
    137 //
    138 #define KBC_INPBUF_VIA60_SCODESET1  0x01
    139 #define KBC_INPBUF_VIA60_SCODESET2  0x02
    140 #define KBC_INPBUF_VIA60_SCODESET3  0x03
    141 
    142 //
    143 //  COMMANDs written to INPUT BUFFER - write to 60h
    144 //
    145 #define KBC_INPBUF_VIA60_KBECHO   0xEE
    146 #define KBC_INPBUF_VIA60_KBSCODE  0xF0
    147 #define KBC_INPBUF_VIA60_KBTYPE   0xF2
    148 #define KBC_INPBUF_VIA60_KBDELAY  0xF3
    149 #define KBC_INPBUF_VIA60_KBEN     0xF4
    150 #define KBC_INPBUF_VIA60_KBSTDDIS 0xF5
    151 #define KBC_INPBUF_VIA60_KBSTDEN  0xF6
    152 #define KBC_INPBUF_VIA60_KBRESEND 0xFE
    153 #define KBC_INPBUF_VIA60_KBRESET  0xFF
    154 
    155 //
    156 // 0040h:0017h - KEYBOARD - STATUS FLAGS 1
    157 //   7 INSert active
    158 //   6 Caps Lock active
    159 //   5 Num Lock active
    160 //   4 Scroll Lock active
    161 //   3 either Alt pressed
    162 //   2 either Ctrl pressed
    163 //   1 Left Shift pressed
    164 //   0 Right Shift pressed
    165 //
    166 // 0040h:0018h - KEYBOARD - STATUS FLAGS 2
    167 //   7: insert key is depressed
    168 //   6: caps-lock key is depressed (does not work well)
    169 //   5: num-lock key is depressed (does not work well)
    170 //   4: scroll lock key is depressed (does not work well)
    171 //   3: suspend key has been toggled (does not work well)
    172 //   2: system key is pressed and held (does not work well)
    173 //   1: left ALT key is pressed
    174 //   0: left CTRL key is pressed
    175 //
    176 #define KB_INSERT_BIT             (0x1 << 7)
    177 #define KB_CAPS_LOCK_BIT          (0x1 << 6)
    178 #define KB_NUM_LOCK_BIT           (0x1 << 5)
    179 #define KB_SCROLL_LOCK_BIT        (0x1 << 4)
    180 #define KB_ALT_PRESSED            (0x1 << 3)
    181 #define KB_CTRL_PRESSED           (0x1 << 2)
    182 #define KB_LEFT_SHIFT_PRESSED     (0x1 << 1)
    183 #define KB_RIGHT_SHIFT_PRESSED    (0x1 << 0)
    184 
    185 #define KB_SUSPEND_PRESSED        (0x1 << 3)
    186 #define KB_SYSREQ_PRESSED         (0x1 << 2)
    187 #define KB_LEFT_ALT_PRESSED       (0x1 << 1)
    188 #define KB_LEFT_CTRL_PRESSED      (0x1 << 0)
    189 
    190 //
    191 // BIOS Keyboard Device Structure
    192 //
    193 #define BIOS_KEYBOARD_DEV_SIGNATURE SIGNATURE_32 ('B', 'K', 'B', 'D')
    194 #define BIOS_KEYBOARD_CONSOLE_IN_EX_NOTIFY_SIGNATURE SIGNATURE_32 ('c', 'b', 'k', 'h')
    195 
    196 typedef struct _BIOS_KEYBOARD_CONSOLE_IN_EX_NOTIFY {
    197   UINTN                                      Signature;
    198   EFI_KEY_DATA                               KeyData;
    199   EFI_KEY_NOTIFY_FUNCTION                    KeyNotificationFn;
    200   LIST_ENTRY                                 NotifyEntry;
    201 } BIOS_KEYBOARD_CONSOLE_IN_EX_NOTIFY;
    202 
    203 #define QUEUE_MAX_COUNT         32
    204 typedef struct {
    205   UINTN             Front;
    206   UINTN             Rear;
    207   EFI_KEY_DATA      Buffer[QUEUE_MAX_COUNT];
    208 } SIMPLE_QUEUE;
    209 
    210 typedef struct {
    211   UINTN                                       Signature;
    212   EFI_HANDLE                                  Handle;
    213   EFI_LEGACY_BIOS_PROTOCOL                    *LegacyBios;
    214   EFI_ISA_IO_PROTOCOL                         *IsaIo;
    215   EFI_SIMPLE_TEXT_INPUT_PROTOCOL              SimpleTextIn;
    216   EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL           SimpleTextInputEx;
    217   UINT16                                      DataRegisterAddress;
    218   UINT16                                      StatusRegisterAddress;
    219   UINT16                                      CommandRegisterAddress;
    220   BOOLEAN                                     ExtendedKeyboard;
    221 
    222   //
    223   // Buffer storing EFI_KEY_DATA
    224   //
    225   SIMPLE_QUEUE                                Queue;
    226   SIMPLE_QUEUE                                QueueForNotify;
    227 
    228   //
    229   // Notification Function List
    230   //
    231   LIST_ENTRY                                  NotifyList;
    232   EFI_EVENT                                   KeyNotifyProcessEvent;
    233   EFI_EVENT                                   TimerEvent;
    234 
    235 } BIOS_KEYBOARD_DEV;
    236 
    237 #define BIOS_KEYBOARD_DEV_FROM_THIS(a)  CR (a, BIOS_KEYBOARD_DEV, SimpleTextIn, BIOS_KEYBOARD_DEV_SIGNATURE)
    238 #define TEXT_INPUT_EX_BIOS_KEYBOARD_DEV_FROM_THIS(a) \
    239   CR (a, \
    240       BIOS_KEYBOARD_DEV, \
    241       SimpleTextInputEx, \
    242       BIOS_KEYBOARD_DEV_SIGNATURE \
    243       )
    244 
    245 //
    246 // Global Variables
    247 //
    248 extern EFI_DRIVER_BINDING_PROTOCOL   gBiosKeyboardDriverBinding;
    249 
    250 //
    251 // Driver Binding Protocol functions
    252 //
    253 
    254 /**
    255   Check whether the driver supports this device.
    256 
    257   @param  This                   The Udriver binding protocol.
    258   @param  Controller             The controller handle to check.
    259   @param  RemainingDevicePath    The remaining device path.
    260 
    261   @retval EFI_SUCCESS            The driver supports this controller.
    262   @retval other                  This device isn't supported.
    263 
    264 **/
    265 EFI_STATUS
    266 EFIAPI
    267 BiosKeyboardDriverBindingSupported (
    268   IN EFI_DRIVER_BINDING_PROTOCOL  *This,
    269   IN EFI_HANDLE                   Controller,
    270   IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath
    271   );
    272 
    273 /**
    274   Starts the device with this driver.
    275 
    276   @param  This                   The driver binding instance.
    277   @param  Controller             Handle of device to bind driver to.
    278   @param  RemainingDevicePath    Optional parameter use to pick a specific child
    279                                  device to start.
    280 
    281   @retval EFI_SUCCESS            The controller is controlled by the driver.
    282   @retval Other                  This controller cannot be started.
    283 
    284 **/
    285 EFI_STATUS
    286 EFIAPI
    287 BiosKeyboardDriverBindingStart (
    288   IN EFI_DRIVER_BINDING_PROTOCOL  *This,
    289   IN EFI_HANDLE                   Controller,
    290   IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath
    291   );
    292 
    293 /**
    294   Stop the device handled by this driver.
    295 
    296   @param  This                   The driver binding protocol.
    297   @param  Controller             The controller to release.
    298   @param  NumberOfChildren       The number of handles in ChildHandleBuffer.
    299   @param  ChildHandleBuffer      The array of child handle.
    300 
    301   @retval EFI_SUCCESS            The device was stopped.
    302   @retval EFI_DEVICE_ERROR       The device could not be stopped due to a device error.
    303   @retval Others                 Fail to uninstall protocols attached on the device.
    304 
    305 **/
    306 EFI_STATUS
    307 EFIAPI
    308 BiosKeyboardDriverBindingStop (
    309   IN  EFI_DRIVER_BINDING_PROTOCOL  *This,
    310   IN  EFI_HANDLE                   Controller,
    311   IN  UINTN                        NumberOfChildren,
    312   IN  EFI_HANDLE                   *ChildHandleBuffer
    313   );
    314 
    315 /**
    316   Retrieves a Unicode string that is the user readable name of the driver.
    317 
    318   This function retrieves the user readable name of a driver in the form of a
    319   Unicode string. If the driver specified by This has a user readable name in
    320   the language specified by Language, then a pointer to the driver name is
    321   returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
    322   by This does not support the language specified by Language,
    323   then EFI_UNSUPPORTED is returned.
    324 
    325   @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
    326                                 EFI_COMPONENT_NAME_PROTOCOL instance.
    327 
    328   @param  Language[in]          A pointer to a Null-terminated ASCII string
    329                                 array indicating the language. This is the
    330                                 language of the driver name that the caller is
    331                                 requesting, and it must match one of the
    332                                 languages specified in SupportedLanguages. The
    333                                 number of languages supported by a driver is up
    334                                 to the driver writer. Language is specified
    335                                 in RFC 4646 or ISO 639-2 language code format.
    336 
    337   @param  DriverName[out]       A pointer to the Unicode string to return.
    338                                 This Unicode string is the name of the
    339                                 driver specified by This in the language
    340                                 specified by Language.
    341 
    342   @retval EFI_SUCCESS           The Unicode string for the Driver specified by
    343                                 This and the language specified by Language was
    344                                 returned in DriverName.
    345 
    346   @retval EFI_INVALID_PARAMETER Language is NULL.
    347 
    348   @retval EFI_INVALID_PARAMETER DriverName is NULL.
    349 
    350   @retval EFI_UNSUPPORTED       The driver specified by This does not support
    351                                 the language specified by Language.
    352 
    353 **/
    354 EFI_STATUS
    355 EFIAPI
    356 BiosKeyboardComponentNameGetDriverName (
    357   IN  EFI_COMPONENT_NAME_PROTOCOL  *This,
    358   IN  CHAR8                        *Language,
    359   OUT CHAR16                       **DriverName
    360   );
    361 
    362 
    363 /**
    364   Retrieves a Unicode string that is the user readable name of the controller
    365   that is being managed by a driver.
    366 
    367   This function retrieves the user readable name of the controller specified by
    368   ControllerHandle and ChildHandle in the form of a Unicode string. If the
    369   driver specified by This has a user readable name in the language specified by
    370   Language, then a pointer to the controller name is returned in ControllerName,
    371   and EFI_SUCCESS is returned.  If the driver specified by This is not currently
    372   managing the controller specified by ControllerHandle and ChildHandle,
    373   then EFI_UNSUPPORTED is returned.  If the driver specified by This does not
    374   support the language specified by Language, then EFI_UNSUPPORTED is returned.
    375 
    376   @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
    377                                 EFI_COMPONENT_NAME_PROTOCOL instance.
    378 
    379   @param  ControllerHandle[in]  The handle of a controller that the driver
    380                                 specified by This is managing.  This handle
    381                                 specifies the controller whose name is to be
    382                                 returned.
    383 
    384   @param  ChildHandle[in]       The handle of the child controller to retrieve
    385                                 the name of.  This is an optional parameter that
    386                                 may be NULL.  It will be NULL for device
    387                                 drivers.  It will also be NULL for a bus drivers
    388                                 that wish to retrieve the name of the bus
    389                                 controller.  It will not be NULL for a bus
    390                                 driver that wishes to retrieve the name of a
    391                                 child controller.
    392 
    393   @param  Language[in]          A pointer to a Null-terminated ASCII string
    394                                 array indicating the language.  This is the
    395                                 language of the driver name that the caller is
    396                                 requesting, and it must match one of the
    397                                 languages specified in SupportedLanguages. The
    398                                 number of languages supported by a driver is up
    399                                 to the driver writer. Language is specified in
    400                                 RFC 4646 or ISO 639-2 language code format.
    401 
    402   @param  ControllerName[out]   A pointer to the Unicode string to return.
    403                                 This Unicode string is the name of the
    404                                 controller specified by ControllerHandle and
    405                                 ChildHandle in the language specified by
    406                                 Language from the point of view of the driver
    407                                 specified by This.
    408 
    409   @retval EFI_SUCCESS           The Unicode string for the user readable name in
    410                                 the language specified by Language for the
    411                                 driver specified by This was returned in
    412                                 DriverName.
    413 
    414   @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
    415 
    416   @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
    417                                 EFI_HANDLE.
    418 
    419   @retval EFI_INVALID_PARAMETER Language is NULL.
    420 
    421   @retval EFI_INVALID_PARAMETER ControllerName is NULL.
    422 
    423   @retval EFI_UNSUPPORTED       The driver specified by This is not currently
    424                                 managing the controller specified by
    425                                 ControllerHandle and ChildHandle.
    426 
    427   @retval EFI_UNSUPPORTED       The driver specified by This does not support
    428                                 the language specified by Language.
    429 
    430 **/
    431 EFI_STATUS
    432 EFIAPI
    433 BiosKeyboardComponentNameGetControllerName (
    434   IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,
    435   IN  EFI_HANDLE                                      ControllerHandle,
    436   IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,
    437   IN  CHAR8                                           *Language,
    438   OUT CHAR16                                          **ControllerName
    439   );
    440 
    441 
    442 //
    443 // Simple Text Input Protocol functions
    444 //
    445 /**
    446   Reset the Keyboard and do BAT test for it, if (ExtendedVerification == TRUE) then do some extra keyboard validations.
    447 
    448   @param  This                  Pointer of simple text Protocol.
    449   @param  ExtendedVerification  Whether perform the extra validation of keyboard. True: perform; FALSE: skip.
    450 
    451   @retval EFI_SUCCESS           The command byte is written successfully.
    452   @retval EFI_DEVICE_ERROR      Errors occurred during resetting keyboard.
    453 
    454 **/
    455 EFI_STATUS
    456 EFIAPI
    457 BiosKeyboardReset (
    458   IN  EFI_SIMPLE_TEXT_INPUT_PROTOCOL  *This,
    459   IN  BOOLEAN                         ExtendedVerification
    460   );
    461 
    462 /**
    463   Read out the scan code of the key that has just been stroked.
    464 
    465   @param  This        Pointer of simple text Protocol.
    466   @param  Key         Pointer for store the key that read out.
    467 
    468   @retval EFI_SUCCESS The key is read out successfully.
    469   @retval other       The key reading failed.
    470 
    471 **/
    472 EFI_STATUS
    473 EFIAPI
    474 BiosKeyboardReadKeyStroke (
    475   IN  EFI_SIMPLE_TEXT_INPUT_PROTOCOL  *This,
    476   OUT EFI_INPUT_KEY                   *Key
    477   );
    478 
    479 //
    480 // Private worker functions
    481 //
    482 /**
    483   Waiting on the keyboard event, if there's any key pressed by the user, signal the event
    484 
    485   @param  Event       The event that be siganlled when any key has been stroked.
    486   @param  Context     Pointer of the protocol EFI_SIMPLE_TEXT_INPUT_PROTOCOL.
    487 
    488 **/
    489 VOID
    490 EFIAPI
    491 BiosKeyboardWaitForKey (
    492   IN  EFI_EVENT  Event,
    493   IN  VOID       *Context
    494   );
    495 
    496 /**
    497   Check key buffer to get the key stroke status.
    498 
    499   @param  This         Pointer of the protocol EFI_SIMPLE_TEXT_IN_PROTOCOL.
    500 
    501   @retval EFI_SUCCESS  A key is being pressed now.
    502   @retval Other        No key is now pressed.
    503 
    504 **/
    505 EFI_STATUS
    506 EFIAPI
    507 BiosKeyboardCheckForKey (
    508   IN  EFI_SIMPLE_TEXT_INPUT_PROTOCOL  *This
    509   );
    510 
    511 /**
    512   Convert unicode combined with scan code of key to the counterpart of EFIScancode of it.
    513 
    514   @param  KeyChar      Unicode of key.
    515   @param  ScanCode     Scan code of key.
    516 
    517   @return The value of EFI Scancode for the key.
    518   @retval SCAN_NULL   No corresponding value in the EFI convert table is found for the key.
    519 
    520 **/
    521 UINT16
    522 ConvertToEFIScanCode (
    523   IN  CHAR16  KeyChar,
    524   IN  UINT16  ScanCode
    525   );
    526 
    527 /**
    528   Check whether there is Ps/2 Keyboard device in system by 0xF4 Keyboard Command
    529   If Keyboard receives 0xF4, it will respond with 'ACK'. If it doesn't respond, the device
    530   should not be in system.
    531 
    532   @param  BiosKeyboardPrivate  Keyboard Private Data Struture
    533 
    534   @retval TRUE  Keyboard in System.
    535   @retval FALSE Keyboard not in System.
    536 
    537 **/
    538 BOOLEAN
    539 CheckKeyboardConnect (
    540   IN  BIOS_KEYBOARD_DEV     *BiosKeyboardPrivate
    541   );
    542 
    543 /**
    544   Timer event handler: read a series of key stroke from 8042
    545   and put them into memory key buffer.
    546   It is registered as running under TPL_NOTIFY
    547 
    548   @param  Event   The timer event
    549   @param  Context A BIOS_KEYBOARD_DEV pointer
    550 
    551 **/
    552 VOID
    553 EFIAPI
    554 BiosKeyboardTimerHandler (
    555   IN EFI_EVENT    Event,
    556   IN VOID         *Context
    557   );
    558 
    559 /**
    560   Process key notify.
    561 
    562   @param  Event                 Indicates the event that invoke this function.
    563   @param  Context               Indicates the calling context.
    564 **/
    565 VOID
    566 EFIAPI
    567 KeyNotifyProcessHandler (
    568   IN  EFI_EVENT                 Event,
    569   IN  VOID                      *Context
    570   );
    571 
    572 /**
    573   Reset the input device and optionaly run diagnostics
    574 
    575   @param  This                  Protocol instance pointer.
    576   @param  ExtendedVerification  Driver may perform diagnostics on reset.
    577 
    578   @retval EFI_SUCCESS           The device was reset.
    579   @retval EFI_DEVICE_ERROR      The device is not functioning properly and could
    580                                 not be reset.
    581 
    582 **/
    583 EFI_STATUS
    584 EFIAPI
    585 BiosKeyboardResetEx (
    586   IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL  *This,
    587   IN BOOLEAN                            ExtendedVerification
    588   );
    589 
    590 /**
    591   Reads the next keystroke from the input device. The WaitForKey Event can
    592   be used to test for existance of a keystroke via WaitForEvent () call.
    593 
    594   @param  This         Protocol instance pointer.
    595   @param  KeyData      A pointer to a buffer that is filled in with the keystroke
    596                        state data for the key that was pressed.
    597 
    598   @retval  EFI_SUCCESS           The keystroke information was returned.
    599   @retval  EFI_NOT_READY         There was no keystroke data availiable.
    600   @retval  EFI_DEVICE_ERROR      The keystroke information was not returned due to
    601                                  hardware errors.
    602   @retval  EFI_INVALID_PARAMETER KeyData is NULL.
    603 
    604 **/
    605 EFI_STATUS
    606 EFIAPI
    607 BiosKeyboardReadKeyStrokeEx (
    608   IN  EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
    609   OUT EFI_KEY_DATA                      *KeyData
    610   );
    611 
    612 /**
    613   Set certain state for the input device.
    614 
    615   @param  This              Protocol instance pointer.
    616   @param  KeyToggleState    A pointer to the EFI_KEY_TOGGLE_STATE to set the
    617                             state for the input device.
    618 
    619   @retval EFI_SUCCESS           The device state was set successfully.
    620   @retval EFI_DEVICE_ERROR      The device is not functioning correctly and could
    621                                 not have the setting adjusted.
    622   @retval EFI_UNSUPPORTED       The device does not have the ability to set its state.
    623   @retval EFI_INVALID_PARAMETER KeyToggleState is NULL.
    624 
    625 **/
    626 EFI_STATUS
    627 EFIAPI
    628 BiosKeyboardSetState (
    629   IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL  *This,
    630   IN EFI_KEY_TOGGLE_STATE               *KeyToggleState
    631   );
    632 
    633 /**
    634   Register a notification function for a particular keystroke for the input device.
    635 
    636   @param  This                    Protocol instance pointer.
    637   @param  KeyData                 A pointer to a buffer that is filled in with the keystroke
    638                                   information data for the key that was pressed.
    639   @param  KeyNotificationFunction Points to the function to be called when the key
    640                                   sequence is typed specified by KeyData.
    641   @param  NotifyHandle            Points to the unique handle assigned to the registered notification.
    642 
    643 
    644   @retval EFI_SUCCESS             The notification function was registered successfully.
    645   @retval EFI_OUT_OF_RESOURCES    Unable to allocate resources for necesssary data structures.
    646   @retval EFI_INVALID_PARAMETER   KeyData or NotifyHandle is NULL.
    647 
    648 **/
    649 EFI_STATUS
    650 EFIAPI
    651 BiosKeyboardRegisterKeyNotify (
    652   IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL  *This,
    653   IN EFI_KEY_DATA                       *KeyData,
    654   IN EFI_KEY_NOTIFY_FUNCTION            KeyNotificationFunction,
    655   OUT VOID                              **NotifyHandle
    656   );
    657 
    658 /**
    659   Remove a registered notification function from a particular keystroke.
    660 
    661   @param  This                 Protocol instance pointer.
    662   @param  NotificationHandle   The handle of the notification function being unregistered.
    663 
    664   @retval EFI_SUCCESS             The notification function was unregistered successfully.
    665   @retval EFI_INVALID_PARAMETER   The NotificationHandle is invalid.
    666 
    667 **/
    668 EFI_STATUS
    669 EFIAPI
    670 BiosKeyboardUnregisterKeyNotify (
    671   IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL  *This,
    672   IN VOID                               *NotificationHandle
    673   );
    674 
    675 /**
    676   Wait for a specific value to be presented in
    677   Data register of Keyboard Controller by keyboard and then read it,
    678   used in keyboard commands ack
    679 
    680   @param   BiosKeyboardPrivate  Keyboard instance pointer.
    681   @param   Value                The value to be waited for
    682   @param   WaitForValueTimeOut  The limit of microseconds for timeout
    683 
    684   @retval  EFI_SUCCESS          The command byte is written successfully.
    685   @retval  EFI_TIMEOUT          Timeout occurred during writing.
    686 
    687 **/
    688 EFI_STATUS
    689 KeyboardWaitForValue (
    690   IN BIOS_KEYBOARD_DEV  *BiosKeyboardPrivate,
    691   IN UINT8              Value,
    692   IN UINTN              WaitForValueTimeOut
    693   );
    694 
    695 /**
    696   Write data byte to input buffer or input/output ports of Keyboard Controller with delay and waiting for buffer-empty state.
    697 
    698   @param   BiosKeyboardPrivate  Keyboard instance pointer.
    699   @param   Data                 Data byte to write.
    700 
    701   @retval  EFI_SUCCESS          The data byte is written successfully.
    702   @retval  EFI_TIMEOUT          Timeout occurred during writing.
    703 
    704 **/
    705 EFI_STATUS
    706 KeyboardWrite (
    707   IN BIOS_KEYBOARD_DEV  *BiosKeyboardPrivate,
    708   IN UINT8              Data
    709   );
    710 
    711 /**
    712   Free keyboard notify list.
    713 
    714   @param  ListHead   The list head
    715 
    716   @retval EFI_SUCCESS           Free the notify list successfully
    717   @retval EFI_INVALID_PARAMETER ListHead is invalid.
    718 
    719 **/
    720 EFI_STATUS
    721 BiosKeyboardFreeNotifyList (
    722   IN OUT LIST_ENTRY           *ListHead
    723   );
    724 
    725 /**
    726   Check if key is registered.
    727 
    728   @param  RegsiteredData    A pointer to a buffer that is filled in with the keystroke
    729                             state data for the key that was registered.
    730   @param  InputData         A pointer to a buffer that is filled in with the keystroke
    731                             state data for the key that was pressed.
    732 
    733   @retval TRUE              Key be pressed matches a registered key.
    734   @retval FLASE             Match failed.
    735 
    736 **/
    737 BOOLEAN
    738 IsKeyRegistered (
    739   IN EFI_KEY_DATA  *RegsiteredData,
    740   IN EFI_KEY_DATA  *InputData
    741   );
    742 
    743 /**
    744   Waiting on the keyboard event, if there's any key pressed by the user, signal the event
    745 
    746   @param  Event    The event that be siganlled when any key has been stroked.
    747   @param  Context  Pointer of the protocol EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL.
    748 
    749 **/
    750 VOID
    751 EFIAPI
    752 BiosKeyboardWaitForKeyEx (
    753   IN  EFI_EVENT  Event,
    754   IN  VOID       *Context
    755   );
    756 
    757 #endif
    758 
    759