TianoCore EDK2 master
Loading...
Searching...
No Matches
Ps2Keyboard.h
Go to the documentation of this file.
1
9#ifndef _PS2KEYBOARD_H_
10#define _PS2KEYBOARD_H_
11
12#include <Uefi.h>
13
14#include <Protocol/SuperIo.h>
17#include <Protocol/DevicePath.h>
18#include <Protocol/Ps2Policy.h>
19
20#include <Library/IoLib.h>
23#include <Library/UefiLib.h>
26#include <Library/DebugLib.h>
29#include <Library/BaseLib.h>
31#include <Library/TimerLib.h>
32#include <Library/PcdLib.h>
33
34//
35// Global Variables
36//
37extern EFI_DRIVER_BINDING_PROTOCOL gKeyboardControllerDriver;
38extern EFI_COMPONENT_NAME_PROTOCOL gPs2KeyboardComponentName;
39extern EFI_COMPONENT_NAME2_PROTOCOL gPs2KeyboardComponentName2;
40
41//
42// Driver Private Data
43//
44#define KEYBOARD_CONSOLE_IN_DEV_SIGNATURE SIGNATURE_32 ('k', 'k', 'e', 'y')
45#define KEYBOARD_CONSOLE_IN_EX_NOTIFY_SIGNATURE SIGNATURE_32 ('k', 'c', 'e', 'n')
46
48 UINTN Signature;
49 EFI_KEY_DATA KeyData;
50 EFI_KEY_NOTIFY_FUNCTION KeyNotificationFn;
51 LIST_ENTRY NotifyEntry;
53
54#define KEYBOARD_SCAN_CODE_MAX_COUNT 32
55typedef struct {
56 UINT8 Buffer[KEYBOARD_SCAN_CODE_MAX_COUNT];
57 UINTN Head;
58 UINTN Tail;
60
61#define KEYBOARD_EFI_KEY_MAX_COUNT 256
62typedef struct {
63 EFI_KEY_DATA Buffer[KEYBOARD_EFI_KEY_MAX_COUNT];
64 UINTN Head;
65 UINTN Tail;
67
68typedef struct {
69 UINTN Signature;
70
71 EFI_HANDLE Handle;
74
75 EFI_EVENT TimerEvent;
76
77 UINT32 DataRegisterAddress;
78 UINT32 StatusRegisterAddress;
79 UINT32 CommandRegisterAddress;
80
81 BOOLEAN LeftCtrl;
82 BOOLEAN RightCtrl;
83 BOOLEAN LeftAlt;
84 BOOLEAN RightAlt;
85 BOOLEAN LeftShift;
86 BOOLEAN RightShift;
87 BOOLEAN LeftLogo;
88 BOOLEAN RightLogo;
89 BOOLEAN Menu;
90 BOOLEAN SysReq;
91
92 BOOLEAN CapsLock;
93 BOOLEAN NumLock;
94 BOOLEAN ScrollLock;
95
96 BOOLEAN IsSupportPartialKey;
97 //
98 // Queue storing key scancodes
99 //
100 SCAN_CODE_QUEUE ScancodeQueue;
101 EFI_KEY_QUEUE EfiKeyQueue;
102 EFI_KEY_QUEUE EfiKeyQueueForNotify;
103
104 //
105 // Error state
106 //
107 BOOLEAN KeyboardErr;
108
109 EFI_UNICODE_STRING_TABLE *ControllerNameTable;
110
111 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
112 //
113 // Notification Function List
114 //
115 LIST_ENTRY NotifyList;
116 EFI_EVENT KeyNotifyProcessEvent;
118
119#define KEYBOARD_CONSOLE_IN_DEV_FROM_THIS(a) CR (a, KEYBOARD_CONSOLE_IN_DEV, ConIn, KEYBOARD_CONSOLE_IN_DEV_SIGNATURE)
120#define TEXT_INPUT_EX_KEYBOARD_CONSOLE_IN_DEV_FROM_THIS(a) \
121 CR (a, \
122 KEYBOARD_CONSOLE_IN_DEV, \
123 ConInEx, \
124 KEYBOARD_CONSOLE_IN_DEV_SIGNATURE \
125 )
126
127#define TABLE_END 0x0
128
129//
130// Driver entry point
131//
132
144EFIAPI
146 IN EFI_HANDLE ImageHandle,
147 IN EFI_SYSTEM_TABLE *SystemTable
148 );
149
150#define KEYBOARD_8042_DATA_REGISTER 0x60
151#define KEYBOARD_8042_STATUS_REGISTER 0x64
152#define KEYBOARD_8042_COMMAND_REGISTER 0x64
153
154#define KEYBOARD_KBEN 0xF4
155#define KEYBOARD_CMDECHO_ACK 0xFA
156
157#define KEYBOARD_MAX_TRY 256 // 256
158#define KEYBOARD_TIMEOUT 65536 // 0.07s
159#define KEYBOARD_WAITFORVALUE_TIMEOUT 1000000 // 1s
160#define KEYBOARD_BAT_TIMEOUT 4000000 // 4s
161#define KEYBOARD_TIMER_INTERVAL 200000 // 0.02s
162#define SCANCODE_EXTENDED0 0xE0
163#define SCANCODE_EXTENDED1 0xE1
164#define SCANCODE_CTRL_MAKE 0x1D
165#define SCANCODE_CTRL_BREAK 0x9D
166#define SCANCODE_ALT_MAKE 0x38
167#define SCANCODE_ALT_BREAK 0xB8
168#define SCANCODE_LEFT_SHIFT_MAKE 0x2A
169#define SCANCODE_LEFT_SHIFT_BREAK 0xAA
170#define SCANCODE_RIGHT_SHIFT_MAKE 0x36
171#define SCANCODE_RIGHT_SHIFT_BREAK 0xB6
172#define SCANCODE_CAPS_LOCK_MAKE 0x3A
173#define SCANCODE_NUM_LOCK_MAKE 0x45
174#define SCANCODE_SCROLL_LOCK_MAKE 0x46
175#define SCANCODE_DELETE_MAKE 0x53
176#define SCANCODE_LEFT_LOGO_MAKE 0x5B// GUI key defined in Keyboard scan code
177#define SCANCODE_LEFT_LOGO_BREAK 0xDB
178#define SCANCODE_RIGHT_LOGO_MAKE 0x5C
179#define SCANCODE_RIGHT_LOGO_BREAK 0xDC
180#define SCANCODE_MENU_MAKE 0x5D// APPS key defined in Keyboard scan code
181#define SCANCODE_MENU_BREAK 0xDD
182#define SCANCODE_SYS_REQ_MAKE 0x37
183#define SCANCODE_SYS_REQ_BREAK 0xB7
184#define SCANCODE_SYS_REQ_MAKE_WITH_ALT 0x54
185#define SCANCODE_SYS_REQ_BREAK_WITH_ALT 0xD4
186
187#define SCANCODE_MAX_MAKE 0x60
188
189#define KEYBOARD_STATUS_REGISTER_HAS_OUTPUT_DATA BIT0
190#define KEYBOARD_STATUS_REGISTER_HAS_INPUT_DATA BIT1
191#define KEYBOARD_STATUS_REGISTER_SYSTEM_FLAG BIT2
192#define KEYBOARD_STATUS_REGISTER_INPUT_DATA_TYPE BIT3
193#define KEYBOARD_STATUS_REGISTER_ENABLE_FLAG BIT4
194#define KEYBOARD_STATUS_REGISTER_TRANSMIT_TIMEOUT BIT5
195#define KEYBOARD_STATUS_REGISTER_RECEIVE_TIMEOUT BIT6
196#define KEYBOARD_STATUS_REGISTER_PARITY BIT7
197
198#define KEYBOARD_8042_COMMAND_READ 0x20
199#define KEYBOARD_8042_COMMAND_WRITE 0x60
200#define KEYBOARD_8042_COMMAND_DISABLE_MOUSE_INTERFACE 0xA7
201#define KEYBOARD_8042_COMMAND_ENABLE_MOUSE_INTERFACE 0xA8
202#define KEYBOARD_8042_COMMAND_CONTROLLER_SELF_TEST 0xAA
203#define KEYBOARD_8042_COMMAND_KEYBOARD_INTERFACE_SELF_TEST 0xAB
204#define KEYBOARD_8042_COMMAND_DISABLE_KEYBOARD_INTERFACE 0xAD
205
206#define KEYBOARD_8048_COMMAND_CLEAR_OUTPUT_DATA 0xF4
207#define KEYBOARD_8048_COMMAND_RESET 0xFF
208#define KEYBOARD_8048_COMMAND_SELECT_SCAN_CODE_SET 0xF0
209
210#define KEYBOARD_8048_RETURN_8042_BAT_SUCCESS 0xAA
211#define KEYBOARD_8048_RETURN_8042_BAT_ERROR 0xFC
212#define KEYBOARD_8048_RETURN_8042_ACK 0xFA
213
214//
215// Keyboard Controller Status
216//
217#define KBC_PARE 0x80 // Parity Error
218#define KBC_TIM 0x40 // General Time Out
219
220//
221// Other functions that are used among .c files
222//
223
235 IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn
236 );
237
250 IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn,
251 OUT UINT8 *Data
252 );
253
262VOID
265 );
266
273VOID
274EFIAPI
276 IN EFI_EVENT Event,
277 IN VOID *Context
278 );
279
293 IN OUT KEYBOARD_CONSOLE_IN_DEV *ConsoleIn,
294 IN BOOLEAN ExtendedVerification
295 );
296
308VOID
309EFIAPI
311 IN EFI_EVENT Event,
312 IN VOID *Context
313 );
314
327EFIAPI
330 IN BOOLEAN ExtendedVerification
331 );
332
344EFIAPI
347 OUT EFI_INPUT_KEY *Key
348 );
349
358VOID
359EFIAPI
361 IN EFI_EVENT Event,
362 IN VOID *Context
363 );
364
373UINT8
375 IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn
376 );
377
388BOOLEAN
389EFIAPI
391 IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn
392 );
393
402VOID
403EFIAPI
405 IN EFI_EVENT Event,
406 IN VOID *Context
407 );
408
409//
410// Simple Text Input Ex protocol function prototypes
411//
412
425EFIAPI
428 IN BOOLEAN ExtendedVerification
429 );
430
450EFIAPI
453 OUT EFI_KEY_DATA *KeyData
454 );
455
471EFIAPI
474 IN EFI_KEY_TOGGLE_STATE *KeyToggleState
475 );
476
496EFIAPI
499 IN EFI_KEY_DATA *KeyData,
500 IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction,
501 OUT VOID **NotifyHandle
502 );
503
517EFIAPI
520 IN VOID *NotificationHandle
521 );
522
529VOID
531 IN EFI_KEY_QUEUE *Queue,
532 IN EFI_KEY_DATA *KeyData
533 );
534
547BOOLEAN
549 IN EFI_KEY_DATA *RegsiteredData,
550 IN EFI_KEY_DATA *InputData
551 );
552
559VOID
561 IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn,
562 OUT EFI_KEY_STATE *KeyState
563 );
564
565#endif
UINT64 UINTN
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
EFI_STATUS EFIAPI KeyboardReadKeyStrokeEx(IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This, OUT EFI_KEY_DATA *KeyData)
Definition: Ps2KbdTextIn.c:442
VOID EFIAPI KeyNotifyProcessHandler(IN EFI_EVENT Event, IN VOID *Context)
BOOLEAN EFIAPI CheckKeyboardConnect(IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn)
VOID InitializeKeyState(IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn, OUT EFI_KEY_STATE *KeyState)
UINT8 KeyReadStatusRegister(IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn)
VOID EFIAPI KeyboardTimerHandler(IN EFI_EVENT Event, IN VOID *Context)
EFI_STATUS EFIAPI KeyboardEfiResetEx(IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This, IN BOOLEAN ExtendedVerification)
Definition: Ps2KbdTextIn.c:407
EFI_STATUS KeyboardRead(IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn, OUT UINT8 *Data)
EFI_STATUS EFIAPI KeyboardSetState(IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This, IN EFI_KEY_TOGGLE_STATE *KeyToggleState)
Definition: Ps2KbdTextIn.c:474
EFI_STATUS EFIAPI KeyboardEfiReset(IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This, IN BOOLEAN ExtendedVerification)
Definition: Ps2KbdTextIn.c:188
EFI_STATUS UpdateStatusLights(IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn)
EFI_STATUS EFIAPI KeyboardReadKeyStroke(IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This, OUT EFI_INPUT_KEY *Key)
Definition: Ps2KbdTextIn.c:266
VOID PushEfikeyBufTail(IN EFI_KEY_QUEUE *Queue, IN EFI_KEY_DATA *KeyData)
Definition: Ps2KbdTextIn.c:65
EFI_STATUS EFIAPI InstallPs2KeyboardDriver(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
EFI_STATUS InitKeyboard(IN OUT KEYBOARD_CONSOLE_IN_DEV *ConsoleIn, IN BOOLEAN ExtendedVerification)
VOID EFIAPI KeyboardWaitForKeyEx(IN EFI_EVENT Event, IN VOID *Context)
Definition: Ps2KbdTextIn.c:385
EFI_STATUS EFIAPI KeyboardUnregisterKeyNotify(IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This, IN VOID *NotificationHandle)
Definition: Ps2KbdTextIn.c:645
VOID KeyGetchar(IN OUT KEYBOARD_CONSOLE_IN_DEV *ConsoleIn)
EFI_STATUS EFIAPI KeyboardRegisterKeyNotify(IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This, IN EFI_KEY_DATA *KeyData, IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction, OUT VOID **NotifyHandle)
Definition: Ps2KbdTextIn.c:563
BOOLEAN IsKeyRegistered(IN EFI_KEY_DATA *RegsiteredData, IN EFI_KEY_DATA *InputData)
VOID EFIAPI KeyboardWaitForKey(IN EFI_EVENT Event, IN VOID *Context)
Definition: Ps2KbdTextIn.c:325
UINT8 EFI_KEY_TOGGLE_STATE
EFI_STATUS(EFIAPI * EFI_KEY_NOTIFY_FUNCTION)(IN EFI_KEY_DATA *KeyData)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_EVENT
Definition: UefiBaseType.h:37
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33