]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Bus/Isa/Ps2KeyboardDxe/Ps2Keyboard.h
Fixed issue that addition LEFT CTRL key was detected when press PAUSE key. PS2 keybo...
[mirror_edk2.git] / IntelFrameworkModulePkg / Bus / Isa / Ps2KeyboardDxe / Ps2Keyboard.h
1 /** @file
2 PS/2 keyboard driver header file
3
4 Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #ifndef _PS2KEYBOARD_H_
16 #define _PS2KEYBOARD_H_
17
18 #include <FrameworkDxe.h>
19
20 #include <Protocol/SimpleTextIn.h>
21 #include <Protocol/SimpleTextInEx.h>
22 #include <Protocol/IsaIo.h>
23 #include <Protocol/DevicePath.h>
24 #include <Protocol/Ps2Policy.h>
25
26 #include <Library/UefiDriverEntryPoint.h>
27 #include <Library/UefiLib.h>
28 #include <Library/UefiBootServicesTableLib.h>
29 #include <Library/ReportStatusCodeLib.h>
30 #include <Library/DebugLib.h>
31 #include <Library/UefiRuntimeServicesTableLib.h>
32 #include <Library/MemoryAllocationLib.h>
33 #include <Library/BaseLib.h>
34 #include <Library/BaseMemoryLib.h>
35 #include <Library/TimerLib.h>
36 #include <Library/PcdLib.h>
37
38 //
39 // Global Variables
40 //
41 extern EFI_DRIVER_BINDING_PROTOCOL gKeyboardControllerDriver;
42 extern EFI_COMPONENT_NAME_PROTOCOL gPs2KeyboardComponentName;
43 extern EFI_COMPONENT_NAME2_PROTOCOL gPs2KeyboardComponentName2;
44
45 //
46 // Driver Private Data
47 //
48 #define KEYBOARD_CONSOLE_IN_DEV_SIGNATURE SIGNATURE_32 ('k', 'k', 'e', 'y')
49 #define KEYBOARD_CONSOLE_IN_EX_NOTIFY_SIGNATURE SIGNATURE_32 ('k', 'c', 'e', 'n')
50
51 typedef struct _KEYBOARD_CONSOLE_IN_EX_NOTIFY {
52 UINTN Signature;
53 EFI_HANDLE NotifyHandle;
54 EFI_KEY_DATA KeyData;
55 EFI_KEY_NOTIFY_FUNCTION KeyNotificationFn;
56 LIST_ENTRY NotifyEntry;
57 } KEYBOARD_CONSOLE_IN_EX_NOTIFY;
58
59 #define KEYBOARD_SCAN_CODE_MAX_COUNT 32
60 typedef struct {
61 UINT8 Buffer[KEYBOARD_SCAN_CODE_MAX_COUNT];
62 UINTN Head;
63 UINTN Tail;
64 } SCAN_CODE_QUEUE;
65
66 #define KEYBOARD_EFI_KEY_MAX_COUNT 256
67 typedef struct {
68 EFI_KEY_DATA Buffer[KEYBOARD_EFI_KEY_MAX_COUNT];
69 UINTN Head;
70 UINTN Tail;
71 } EFI_KEY_QUEUE;
72
73 typedef struct {
74 UINTN Signature;
75
76 EFI_HANDLE Handle;
77 EFI_SIMPLE_TEXT_INPUT_PROTOCOL ConIn;
78 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL ConInEx;
79 EFI_ISA_IO_PROTOCOL *IsaIo;
80
81 EFI_EVENT TimerEvent;
82
83 UINT32 DataRegisterAddress;
84 UINT32 StatusRegisterAddress;
85 UINT32 CommandRegisterAddress;
86
87 BOOLEAN LeftShift;
88 BOOLEAN RightShift;
89 BOOLEAN LeftLogo;
90 BOOLEAN RightLogo;
91 BOOLEAN Menu;
92 BOOLEAN SysReq;
93
94 BOOLEAN Ctrl;
95 BOOLEAN Alt;
96 BOOLEAN Shift;
97 BOOLEAN CapsLock;
98 BOOLEAN NumLock;
99 BOOLEAN ScrollLock;
100
101 //
102 // Queue storing key scancodes
103 //
104 SCAN_CODE_QUEUE ScancodeQueue;
105 EFI_KEY_QUEUE EfiKeyQueue;
106
107 //
108 // Error state
109 //
110 BOOLEAN KeyboardErr;
111
112 EFI_UNICODE_STRING_TABLE *ControllerNameTable;
113
114 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
115 //
116 // Notification Function List
117 //
118 LIST_ENTRY NotifyList;
119 } KEYBOARD_CONSOLE_IN_DEV;
120
121 #define KEYBOARD_CONSOLE_IN_DEV_FROM_THIS(a) CR (a, KEYBOARD_CONSOLE_IN_DEV, ConIn, KEYBOARD_CONSOLE_IN_DEV_SIGNATURE)
122 #define TEXT_INPUT_EX_KEYBOARD_CONSOLE_IN_DEV_FROM_THIS(a) \
123 CR (a, \
124 KEYBOARD_CONSOLE_IN_DEV, \
125 ConInEx, \
126 KEYBOARD_CONSOLE_IN_DEV_SIGNATURE \
127 )
128
129 #define TABLE_END 0x0
130
131 //
132 // Driver entry point
133 //
134 /**
135 The user Entry Point for module Ps2Keyboard. The user code starts with this function.
136
137 @param[in] ImageHandle The firmware allocated handle for the EFI image.
138 @param[in] SystemTable A pointer to the EFI System Table.
139
140 @retval EFI_SUCCESS The entry point is executed successfully.
141 @retval other Some error occurs when executing this entry point.
142
143 **/
144 EFI_STATUS
145 EFIAPI
146 InstallPs2KeyboardDriver (
147 IN EFI_HANDLE ImageHandle,
148 IN EFI_SYSTEM_TABLE *SystemTable
149 );
150
151 #define KEYBOARD_8042_DATA_REGISTER 0x60
152 #define KEYBOARD_8042_STATUS_REGISTER 0x64
153 #define KEYBOARD_8042_COMMAND_REGISTER 0x64
154
155 #define KEYBOARD_KBEN 0xF4
156 #define KEYBOARD_CMDECHO_ACK 0xFA
157
158 #define KEYBOARD_MAX_TRY 256 // 256
159 #define KEYBOARD_TIMEOUT 65536 // 0.07s
160 #define KEYBOARD_WAITFORVALUE_TIMEOUT 1000000 // 1s
161 #define KEYBOARD_BAT_TIMEOUT 4000000 // 4s
162 #define KEYBOARD_TIMER_INTERVAL 200000 // 0.02s
163 #define SCANCODE_EXTENDED 0xE0
164 #define SCANCODE_EXTENDED1 0xE1
165 #define SCANCODE_CTRL_MAKE 0x1D
166 #define SCANCODE_CTRL_BREAK 0x9D
167 #define SCANCODE_ALT_MAKE 0x38
168 #define SCANCODE_ALT_BREAK 0xB8
169 #define SCANCODE_LEFT_SHIFT_MAKE 0x2A
170 #define SCANCODE_LEFT_SHIFT_BREAK 0xAA
171 #define SCANCODE_RIGHT_SHIFT_MAKE 0x36
172 #define SCANCODE_RIGHT_SHIFT_BREAK 0xB6
173 #define SCANCODE_CAPS_LOCK_MAKE 0x3A
174 #define SCANCODE_NUM_LOCK_MAKE 0x45
175 #define SCANCODE_SCROLL_LOCK_MAKE 0x46
176 #define SCANCODE_DELETE_MAKE 0x53
177 #define SCANCODE_LEFT_LOGO_MAKE 0x5B //GUI key defined in Keyboard scan code
178 #define SCANCODE_LEFT_LOGO_BREAK 0xDB
179 #define SCANCODE_RIGHT_LOGO_MAKE 0x5C
180 #define SCANCODE_RIGHT_LOGO_BREAK 0xDC
181 #define SCANCODE_MENU_MAKE 0x5D //APPS key defined in Keyboard scan code
182 #define SCANCODE_MENU_BREAK 0xDD
183 #define SCANCODE_SYS_REQ_MAKE 0x37
184 #define SCANCODE_MAX_MAKE 0x60
185
186 #define SCANCODE_PAUSE_MAKE 0x9DC5 // The last two bytes of scancode for PAUSE key
187
188 #define KEYBOARD_STATUS_REGISTER_HAS_OUTPUT_DATA BIT0 ///< 0 - Output register has no data; 1 - Output register has data
189 #define KEYBOARD_STATUS_REGISTER_HAS_INPUT_DATA BIT1 ///< 0 - Input register has no data; 1 - Input register has data
190 #define KEYBOARD_STATUS_REGISTER_SYSTEM_FLAG BIT2 ///< Set to 0 after power on reset
191 #define KEYBOARD_STATUS_REGISTER_INPUT_DATA_TYPE BIT3 ///< 0 - Data in input register is data; 1 - Data in input register is command
192 #define KEYBOARD_STATUS_REGISTER_ENABLE_FLAG BIT4 ///< 0 - Keyboard is disable; 1 - Keyboard is enable
193 #define KEYBOARD_STATUS_REGISTER_TRANSMIT_TIMEOUT BIT5 ///< 0 - Transmit is complete without timeout; 1 - Transmit is timeout without complete
194 #define KEYBOARD_STATUS_REGISTER_RECEIVE_TIMEOUT BIT6 ///< 0 - Receive is complete without timeout; 1 - Receive is timeout without complete
195 #define KEYBOARD_STATUS_REGISTER_PARITY BIT7 ///< 0 - Odd parity; 1 - Even parity
196
197 #define KEYBOARD_8042_COMMAND_READ 0x20
198 #define KEYBOARD_8042_COMMAND_WRITE 0x60
199 #define KEYBOARD_8042_COMMAND_DISABLE_MOUSE_INTERFACE 0xA7
200 #define KEYBOARD_8042_COMMAND_ENABLE_MOUSE_INTERFACE 0xA8
201 #define KEYBOARD_8042_COMMAND_CONTROLLER_SELF_TEST 0xAA
202 #define KEYBOARD_8042_COMMAND_KEYBOARD_INTERFACE_SELF_TEST 0xAB
203 #define KEYBOARD_8042_COMMAND_DISABLE_KEYBOARD_INTERFACE 0xAD
204
205 #define KEYBOARD_8048_COMMAND_CLEAR_OUTPUT_DATA 0xF4
206 #define KEYBOARD_8048_COMMAND_RESET 0xFF
207 #define KEYBOARD_8048_COMMAND_SELECT_SCAN_CODE_SET 0xF0
208
209 #define KEYBOARD_8048_RETURN_8042_BAT_SUCCESS 0xAA
210 #define KEYBOARD_8048_RETURN_8042_BAT_ERROR 0xFC
211 #define KEYBOARD_8048_RETURN_8042_ACK 0xFA
212
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 /**
224 Show keyboard status lights according to
225 indicators in ConsoleIn.
226
227 @param ConsoleIn Pointer to instance of KEYBOARD_CONSOLE_IN_DEV
228
229 @return status
230
231 **/
232 EFI_STATUS
233 UpdateStatusLights (
234 IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn
235 );
236
237 /**
238 write key to keyboard.
239
240 @param ConsoleIn Pointer to instance of KEYBOARD_CONSOLE_IN_DEV
241 @param Data value wanted to be written
242
243 @retval EFI_TIMEOUT - GC_TODO: Add description for return value
244 @retval EFI_SUCCESS - GC_TODO: Add description for return value
245
246 **/
247 EFI_STATUS
248 KeyboardRead (
249 IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn,
250 OUT UINT8 *Data
251 );
252
253 /**
254 Get scancode from scancode buffer and translate into EFI-scancode and unicode defined by EFI spec.
255
256 The function is always called in TPL_NOTIFY.
257
258 @param ConsoleIn KEYBOARD_CONSOLE_IN_DEV instance pointer
259
260 **/
261 VOID
262 KeyGetchar (
263 IN OUT KEYBOARD_CONSOLE_IN_DEV *ConsoleIn
264 );
265
266 /**
267 Perform 8042 controller and keyboard Initialization.
268 If ExtendedVerification is TRUE, do additional test for
269 the keyboard interface
270
271 @param ConsoleIn - KEYBOARD_CONSOLE_IN_DEV instance pointer
272 @param ExtendedVerification - indicates a thorough initialization
273
274 @retval EFI_DEVICE_ERROR Fail to init keyboard
275 @retval EFI_SUCCESS Success to init keyboard
276 **/
277 EFI_STATUS
278 InitKeyboard (
279 IN OUT KEYBOARD_CONSOLE_IN_DEV *ConsoleIn,
280 IN BOOLEAN ExtendedVerification
281 );
282
283 /**
284 Disable the keyboard interface of the 8042 controller.
285
286 @param ConsoleIn - the device instance
287
288 @return status of issuing disable command
289
290 **/
291 EFI_STATUS
292 DisableKeyboard (
293 IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn
294 );
295
296 /**
297 Timer event handler: read a series of scancodes from 8042
298 and put them into memory scancode buffer.
299 it read as much scancodes to either fill
300 the memory buffer or empty the keyboard buffer.
301 It is registered as running under TPL_NOTIFY
302
303 @param Event - The timer event
304 @param Context - A KEYBOARD_CONSOLE_IN_DEV pointer
305
306 **/
307 VOID
308 EFIAPI
309 KeyboardTimerHandler (
310 IN EFI_EVENT Event,
311 IN VOID *Context
312 );
313
314 /**
315 logic reset keyboard
316 Implement SIMPLE_TEXT_IN.Reset()
317 Perform 8042 controller and keyboard initialization
318
319 @param This Pointer to instance of EFI_SIMPLE_TEXT_INPUT_PROTOCOL
320 @param ExtendedVerification Indicate that the driver may perform a more
321 exhaustive verification operation of the device during
322 reset, now this par is ignored in this driver
323
324 **/
325 EFI_STATUS
326 EFIAPI
327 KeyboardEfiReset (
328 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,
329 IN BOOLEAN ExtendedVerification
330 );
331
332 /**
333 Implement SIMPLE_TEXT_IN.ReadKeyStroke().
334 Retrieve key values for driver user.
335
336 @param This Pointer to instance of EFI_SIMPLE_TEXT_INPUT_PROTOCOL
337 @param Key The output buffer for key value
338
339 @retval EFI_SUCCESS success to read key stroke
340 **/
341 EFI_STATUS
342 EFIAPI
343 KeyboardReadKeyStroke (
344 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,
345 OUT EFI_INPUT_KEY *Key
346 );
347
348 /**
349 Event notification function for SIMPLE_TEXT_IN.WaitForKey event
350 Signal the event if there is key available
351
352 @param Event the event object
353 @param Context waitting context
354
355 **/
356 VOID
357 EFIAPI
358 KeyboardWaitForKey (
359 IN EFI_EVENT Event,
360 IN VOID *Context
361 );
362
363 /**
364 Read status register.
365
366 @param ConsoleIn Pointer to instance of KEYBOARD_CONSOLE_IN_DEV
367
368 @return value in status register
369
370 **/
371 UINT8
372 KeyReadStatusRegister (
373 IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn
374 );
375
376 /**
377 Check whether there is Ps/2 Keyboard device in system by 0xF4 Keyboard Command
378 If Keyboard receives 0xF4, it will respond with 'ACK'. If it doesn't respond, the device
379 should not be in system.
380
381 @param[in] ConsoleIn Pointer to instance of KEYBOARD_CONSOLE_IN_DEV
382
383 @retval TRUE Keyboard in System.
384 @retval FALSE Keyboard not in System.
385 **/
386 BOOLEAN
387 EFIAPI
388 CheckKeyboardConnect (
389 IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn
390 );
391
392 /**
393 Event notification function for SIMPLE_TEXT_INPUT_EX_PROTOCOL.WaitForKeyEx event
394 Signal the event if there is key available
395
396 @param Event event object
397 @param Context waiting context
398
399 **/
400 VOID
401 EFIAPI
402 KeyboardWaitForKeyEx (
403 IN EFI_EVENT Event,
404 IN VOID *Context
405 );
406
407 //
408 // Simple Text Input Ex protocol function prototypes
409 //
410
411 /**
412 Reset the input device and optionaly run diagnostics
413
414 @param This - Protocol instance pointer.
415 @param ExtendedVerification - Driver may perform diagnostics on reset.
416
417 @retval EFI_SUCCESS - The device was reset.
418 @retval EFI_DEVICE_ERROR - The device is not functioning properly and could
419 not be reset.
420
421 **/
422 EFI_STATUS
423 EFIAPI
424 KeyboardEfiResetEx (
425 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
426 IN BOOLEAN ExtendedVerification
427 );
428
429 /**
430 Reads the next keystroke from the input device. The WaitForKey Event can
431 be used to test for existance of a keystroke via WaitForEvent () call.
432
433
434 @param This - Protocol instance pointer.
435 @param KeyData - A pointer to a buffer that is filled in with the keystroke
436 state data for the key that was pressed.
437
438 @retval EFI_SUCCESS - The keystroke information was returned.
439 @retval EFI_NOT_READY - There was no keystroke data availiable.
440 @retval EFI_DEVICE_ERROR - The keystroke information was not returned due to
441 hardware errors.
442 @retval EFI_INVALID_PARAMETER - KeyData is NULL.
443
444 **/
445 EFI_STATUS
446 EFIAPI
447 KeyboardReadKeyStrokeEx (
448 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
449 OUT EFI_KEY_DATA *KeyData
450 );
451
452 /**
453 Set certain state for the input device.
454
455 @param This - Protocol instance pointer.
456 @param KeyToggleState - A pointer to the EFI_KEY_TOGGLE_STATE to set the
457 state for the input device.
458
459 @retval EFI_SUCCESS - The device state was set successfully.
460 @retval EFI_DEVICE_ERROR - The device is not functioning correctly and could
461 not have the setting adjusted.
462 @retval EFI_UNSUPPORTED - The device does not have the ability to set its state.
463 @retval EFI_INVALID_PARAMETER - KeyToggleState is NULL.
464
465 **/
466 EFI_STATUS
467 EFIAPI
468 KeyboardSetState (
469 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
470 IN EFI_KEY_TOGGLE_STATE *KeyToggleState
471 );
472
473 /**
474 Register a notification function for a particular keystroke for the input device.
475
476 @param This - Protocol instance pointer.
477 @param KeyData - A pointer to a buffer that is filled in with the keystroke
478 information data for the key that was pressed.
479 @param KeyNotificationFunction - Points to the function to be called when the key
480 sequence is typed specified by KeyData.
481 @param NotifyHandle - Points to the unique handle assigned to the registered notification.
482
483 @retval EFI_SUCCESS - The notification function was registered successfully.
484 @retval EFI_OUT_OF_RESOURCES - Unable to allocate resources for necesssary data structures.
485 @retval EFI_INVALID_PARAMETER - KeyData or NotifyHandle is NULL.
486
487 **/
488 EFI_STATUS
489 EFIAPI
490 KeyboardRegisterKeyNotify (
491 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
492 IN EFI_KEY_DATA *KeyData,
493 IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction,
494 OUT EFI_HANDLE *NotifyHandle
495 );
496
497 /**
498 Remove a registered notification function from a particular keystroke.
499
500 @param This - Protocol instance pointer.
501 @param NotificationHandle - The handle of the notification function being unregistered.
502
503
504 @retval EFI_SUCCESS - The notification function was unregistered successfully.
505 @retval EFI_INVALID_PARAMETER - The NotificationHandle is invalid.
506 @retval EFI_NOT_FOUND - Can not find the matching entry in database.
507
508 **/
509 EFI_STATUS
510 EFIAPI
511 KeyboardUnregisterKeyNotify (
512 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
513 IN EFI_HANDLE NotificationHandle
514 );
515
516 /**
517 Push one key data to the EFI key buffer.
518
519 @param Queue Pointer to instance of EFI_KEY_QUEUE.
520 @param KeyData The key data to push.
521 **/
522 VOID
523 PushEfikeyBufTail (
524 IN EFI_KEY_QUEUE *Queue,
525 IN EFI_KEY_DATA *KeyData
526 );
527
528 /**
529 Judge whether is a registed key
530
531 @param RegsiteredData A pointer to a buffer that is filled in with the keystroke
532 state data for the key that was registered.
533 @param InputData A pointer to a buffer that is filled in with the keystroke
534 state data for the key that was pressed.
535
536 @retval TRUE Key be pressed matches a registered key.
537 @retval FLASE Match failed.
538
539 **/
540 BOOLEAN
541 IsKeyRegistered (
542 IN EFI_KEY_DATA *RegsiteredData,
543 IN EFI_KEY_DATA *InputData
544 );
545 #endif