]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Bus/Isa/Ps2KeyboardDxe/Ps2Keyboard.h
Update to support EFI_SIMPLE_INPUT_EX protocol
[mirror_edk2.git] / IntelFrameworkModulePkg / Bus / Isa / Ps2KeyboardDxe / Ps2Keyboard.h
1 /**@file
2 PS/2 keyboard driver header file
3
4 Copyright (c) 2006 - 2007, Intel Corporation
5 All rights reserved. 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 <PiDxe.h>
19 #include <Framework/StatusCode.h>
20
21 #include <Protocol/SimpleTextIn.h>
22 #include <Protocol/SimpleTextInEx.h>
23 #include <Protocol/IsaIo.h>
24 #include <Protocol/DevicePath.h>
25 #include <Protocol/Ps2Policy.h>
26
27 #include <Library/UefiDriverEntryPoint.h>
28 #include <Library/UefiLib.h>
29 #include <Library/UefiBootServicesTableLib.h>
30 #include <Library/ReportStatusCodeLib.h>
31 #include <Library/DebugLib.h>
32 #include <Library/UefiRuntimeServicesTableLib.h>
33 #include <Library/MemoryAllocationLib.h>
34 #include <Library/BaseLib.h>
35 #include <Library/BaseMemoryLib.h>
36
37 //
38 // Driver Private Data
39 //
40 #define KEYBOARD_BUFFER_MAX_COUNT 32
41 #define KEYBOARD_CONSOLE_IN_DEV_SIGNATURE EFI_SIGNATURE_32 ('k', 'k', 'e', 'y')
42 #define KEYBOARD_CONSOLE_IN_EX_NOTIFY_SIGNATURE EFI_SIGNATURE_32 ('k', 'c', 'e', 'n')
43
44 typedef struct _KEYBOARD_CONSOLE_IN_EX_NOTIFY {
45 UINTN Signature;
46 EFI_HANDLE NotifyHandle;
47 EFI_KEY_DATA KeyData;
48 EFI_KEY_NOTIFY_FUNCTION KeyNotificationFn;
49 LIST_ENTRY NotifyEntry;
50 } KEYBOARD_CONSOLE_IN_EX_NOTIFY;
51
52
53 typedef struct {
54 UINTN Signature;
55
56 EFI_HANDLE Handle;
57 EFI_SIMPLE_TEXT_INPUT_PROTOCOL ConIn;
58 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL ConInEx;
59 EFI_ISA_IO_PROTOCOL *IsaIo;
60
61 EFI_EVENT TimerEvent;
62
63 UINT32 DataRegisterAddress;
64 UINT32 StatusRegisterAddress;
65 UINT32 CommandRegisterAddress;
66
67 EFI_INPUT_KEY Key;
68 EFI_KEY_STATE KeyState;
69
70 BOOLEAN LeftShift;
71 BOOLEAN RightShift;
72 BOOLEAN LeftLogo;
73 BOOLEAN RightLogo;
74 BOOLEAN Menu;
75 BOOLEAN SysReq;
76
77 BOOLEAN Ctrl;
78 BOOLEAN Alt;
79 BOOLEAN Shift;
80 BOOLEAN CapsLock;
81 BOOLEAN NumLock;
82 BOOLEAN ScrollLock;
83
84 //
85 // Buffer storing key scancodes
86 //
87 UINT8 ScancodeBuf[KEYBOARD_BUFFER_MAX_COUNT];
88 UINT32 ScancodeBufStartPos;
89 UINT32 ScancodeBufEndPos;
90 UINT32 ScancodeBufCount;
91
92 //
93 // Indicators of the key pressing state, used in detecting Alt+Ctrl+Del
94 //
95 BOOLEAN Ctrled;
96 BOOLEAN Alted;
97
98 //
99 // Error state
100 //
101 BOOLEAN KeyboardErr;
102
103 EFI_UNICODE_STRING_TABLE *ControllerNameTable;
104
105 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
106 //
107 // Notification Function List
108 //
109 LIST_ENTRY NotifyList;
110 } KEYBOARD_CONSOLE_IN_DEV;
111
112 #define KEYBOARD_CONSOLE_IN_DEV_FROM_THIS(a) CR (a, KEYBOARD_CONSOLE_IN_DEV, ConIn, KEYBOARD_CONSOLE_IN_DEV_SIGNATURE)
113 #define TEXT_INPUT_EX_KEYBOARD_CONSOLE_IN_DEV_FROM_THIS(a) \
114 CR (a, \
115 KEYBOARD_CONSOLE_IN_DEV, \
116 ConInEx, \
117 KEYBOARD_CONSOLE_IN_DEV_SIGNATURE \
118 )
119
120 #define TABLE_END 0x0
121
122 //
123 // Global Variables
124 //
125 extern EFI_DRIVER_BINDING_PROTOCOL gKeyboardControllerDriver;
126 extern EFI_COMPONENT_NAME_PROTOCOL gPs2KeyboardComponentName;
127 extern EFI_COMPONENT_NAME2_PROTOCOL gPs2KeyboardComponentName2;
128
129 extern EFI_GUID gSimpleTextInExNotifyGuid;
130
131 //
132 // Driver entry point
133 //
134 EFI_STATUS
135 EFIAPI
136 InstallPs2KeyboardDriver (
137 IN EFI_HANDLE ImageHandle,
138 IN EFI_SYSTEM_TABLE *SystemTable
139 )
140 /*++
141
142 Routine Description:
143
144 GC_TODO: Add function description
145
146 Arguments:
147
148 ImageHandle - GC_TODO: add argument description
149 SystemTable - GC_TODO: add argument description
150
151 Returns:
152
153 GC_TODO: add return values
154
155 --*/
156 ;
157
158 #define KEYBOARD_8042_DATA_REGISTER 0x60
159 #define KEYBOARD_8042_STATUS_REGISTER 0x64
160 #define KEYBOARD_8042_COMMAND_REGISTER 0x64
161
162 #define KEYBOARD_KBEN 0xF4
163 #define KEYBOARD_CMDECHO_ACK 0xFA
164
165 #define KEYBOARD_TIMEOUT 65536 // 0.07s
166 #define KEYBOARD_WAITFORVALUE_TIMEOUT 1000000 // 1s
167 #define KEYBOARD_BAT_TIMEOUT 4000000 // 4s
168 #define KEYBOARD_TIMER_INTERVAL 200000 // 0.02s
169 #define SCANCODE_EXTENDED 0xE0
170 #define SCANCODE_EXTENDED1 0xE1
171 #define SCANCODE_CTRL_MAKE 0x1D
172 #define SCANCODE_CTRL_BREAK 0x9D
173 #define SCANCODE_ALT_MAKE 0x38
174 #define SCANCODE_ALT_BREAK 0xB8
175 #define SCANCODE_LEFT_SHIFT_MAKE 0x2A
176 #define SCANCODE_LEFT_SHIFT_BREAK 0xAA
177 #define SCANCODE_RIGHT_SHIFT_MAKE 0x36
178 #define SCANCODE_RIGHT_SHIFT_BREAK 0xB6
179 #define SCANCODE_CAPS_LOCK_MAKE 0x3A
180 #define SCANCODE_NUM_LOCK_MAKE 0x45
181 #define SCANCODE_SCROLL_LOCK_MAKE 0x46
182 #define SCANCODE_LEFT_LOGO_MAKE 0x5B //GUI key defined in Keyboard scan code
183 #define SCANCODE_LEFT_LOGO_BREAK 0xDB
184 #define SCANCODE_RIGHT_LOGO_MAKE 0x5C
185 #define SCANCODE_RIGHT_LOGO_BREAK 0xDC
186 #define SCANCODE_MENU_MAKE 0x5D //APPS key defined in Keyboard scan code
187 #define SCANCODE_MENU_BREAK 0xDD
188 #define SCANCODE_SYS_REQ_MAKE 0x37
189 #define SCANCODE_MAX_MAKE 0x60
190
191 //
192 // Other functions that are used among .c files
193 //
194
195 EFI_STATUS
196 UpdateStatusLights (
197 IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn
198 )
199 /*++
200
201 Routine Description:
202
203 Show keyboard status light for ScrollLock, NumLock and CapsLock
204 according to indicators in ConsoleIn.
205
206 Arguments:
207
208 ConsoleIn - driver private structure
209
210 Returns:
211
212 EFI_SUCCESS - Show the status light successfully.
213 EFI_TIMEOUT - Timeout when operating read/write on registers.
214
215 --*/
216 ;
217
218 EFI_STATUS
219 KeyboardRead (
220 IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn,
221 OUT UINT8 *Data
222 )
223 /*++
224
225 Routine Description:
226
227 GC_TODO: Add function description
228
229 Arguments:
230
231 ConsoleIn - GC_TODO: add argument description
232 Data - GC_TODO: add argument description
233
234 Returns:
235
236 GC_TODO: add return values
237
238 --*/
239 ;
240
241 EFI_STATUS
242 KeyGetchar (
243 IN OUT KEYBOARD_CONSOLE_IN_DEV *ConsoleIn
244 )
245 /*++
246
247 Routine Description:
248
249 GC_TODO: Add function description
250
251 Arguments:
252
253 ConsoleIn - GC_TODO: add argument description
254
255 Returns:
256
257 GC_TODO: add return values
258
259 --*/
260 ;
261
262 EFI_STATUS
263 InitKeyboard (
264 IN OUT KEYBOARD_CONSOLE_IN_DEV *ConsoleIn,
265 IN BOOLEAN ExtendedVerification
266 )
267 /*++
268
269 Routine Description:
270
271 GC_TODO: Add function description
272
273 Arguments:
274
275 ConsoleIn - GC_TODO: add argument description
276 ExtendedVerification - GC_TODO: add argument description
277
278 Returns:
279
280 GC_TODO: add return values
281
282 --*/
283 ;
284
285 EFI_STATUS
286 DisableKeyboard (
287 IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn
288 )
289 /*++
290
291 Routine Description:
292
293 GC_TODO: Add function description
294
295 Arguments:
296
297 ConsoleIn - GC_TODO: add argument description
298
299 Returns:
300
301 GC_TODO: add return values
302
303 --*/
304 ;
305
306 VOID
307 EFIAPI
308 KeyboardTimerHandler (
309 IN EFI_EVENT Event,
310 IN VOID *Context
311 )
312 /*++
313
314 Routine Description:
315
316 GC_TODO: Add function description
317
318 Arguments:
319
320 Event - GC_TODO: add argument description
321 Context - GC_TODO: add argument description
322
323 Returns:
324
325 GC_TODO: add return values
326
327 --*/
328 ;
329
330 EFI_STATUS
331 EFIAPI
332 KeyboardEfiReset (
333 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,
334 IN BOOLEAN ExtendedVerification
335 )
336 /*++
337
338 Routine Description:
339
340 GC_TODO: Add function description
341
342 Arguments:
343
344 This - GC_TODO: add argument description
345 ExtendedVerification - GC_TODO: add argument description
346
347 Returns:
348
349 GC_TODO: add return values
350
351 --*/
352 ;
353
354 EFI_STATUS
355 EFIAPI
356 KeyboardReadKeyStroke (
357 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,
358 OUT EFI_INPUT_KEY *Key
359 )
360 /*++
361
362 Routine Description:
363
364 GC_TODO: Add function description
365
366 Arguments:
367
368 This - GC_TODO: add argument description
369 Key - GC_TODO: add argument description
370
371 Returns:
372
373 GC_TODO: add return values
374
375 --*/
376 ;
377
378 VOID
379 EFIAPI
380 KeyboardWaitForKey (
381 IN EFI_EVENT Event,
382 IN VOID *Context
383 )
384 /*++
385
386 Routine Description:
387
388 GC_TODO: Add function description
389
390 Arguments:
391
392 Event - GC_TODO: add argument description
393 Context - GC_TODO: add argument description
394
395 Returns:
396
397 GC_TODO: add return values
398
399 --*/
400 ;
401
402 UINT8
403 KeyReadStatusRegister (
404 IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn
405 )
406 /*++
407
408 Routine Description:
409
410 GC_TODO: Add function description
411
412 Arguments:
413
414 ConsoleIn - GC_TODO: add argument description
415
416 Returns:
417
418 GC_TODO: add return values
419
420 --*/
421 ;
422
423 /**
424 Check whether there is Ps/2 Keyboard device in system by 0xF4 Keyboard Command
425 If Keyboard receives 0xF4, it will respond with 'ACK'. If it doesn't respond, the device
426 should not be in system.
427
428 @param[in] BiosKeyboardPrivate Keyboard Private Data Structure
429
430 @retval TRUE Keyboard in System.
431 @retval FALSE Keyboard not in System.
432 **/
433 BOOLEAN
434 EFIAPI
435 CheckKeyboardConnect (
436 IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn
437 )
438 ;
439
440 VOID
441 EFIAPI
442 KeyboardWaitForKeyEx (
443 IN EFI_EVENT Event,
444 IN VOID *Context
445 )
446 /*++
447
448 Routine Description:
449
450 Event notification function for SIMPLE_TEXT_INPUT_EX_PROTOCOL.WaitForKeyEx event
451 Signal the event if there is key available
452
453 Arguments:
454
455 Returns:
456
457 --*/
458 ;
459
460 //
461 // Simple Text Input Ex protocol function prototypes
462 //
463
464 EFI_STATUS
465 EFIAPI
466 KeyboardEfiResetEx (
467 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
468 IN BOOLEAN ExtendedVerification
469 )
470 /*++
471
472 Routine Description:
473 Reset the input device and optionaly run diagnostics
474
475 Arguments:
476 This - Protocol instance pointer.
477 ExtendedVerification - Driver may perform diagnostics on reset.
478
479 Returns:
480 EFI_SUCCESS - The device was reset.
481 EFI_DEVICE_ERROR - The device is not functioning properly and could
482 not be reset.
483
484 --*/
485 ;
486
487 EFI_STATUS
488 EFIAPI
489 KeyboardReadKeyStrokeEx (
490 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
491 OUT EFI_KEY_DATA *KeyData
492 )
493 /*++
494
495 Routine Description:
496 Reads the next keystroke from the input device. The WaitForKey Event can
497 be used to test for existance of a keystroke via WaitForEvent () call.
498
499 Arguments:
500 This - Protocol instance pointer.
501 KeyData - A pointer to a buffer that is filled in with the keystroke
502 state data for the key that was pressed.
503
504 Returns:
505 EFI_SUCCESS - The keystroke information was returned.
506 EFI_NOT_READY - There was no keystroke data availiable.
507 EFI_DEVICE_ERROR - The keystroke information was not returned due to
508 hardware errors.
509 EFI_INVALID_PARAMETER - KeyData is NULL.
510
511 --*/
512 ;
513
514 EFI_STATUS
515 EFIAPI
516 KeyboardSetState (
517 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
518 IN EFI_KEY_TOGGLE_STATE *KeyToggleState
519 )
520 /*++
521
522 Routine Description:
523 Set certain state for the input device.
524
525 Arguments:
526 This - Protocol instance pointer.
527 KeyToggleState - A pointer to the EFI_KEY_TOGGLE_STATE to set the
528 state for the input device.
529
530 Returns:
531 EFI_SUCCESS - The device state was set successfully.
532 EFI_DEVICE_ERROR - The device is not functioning correctly and could
533 not have the setting adjusted.
534 EFI_UNSUPPORTED - The device does not have the ability to set its state.
535 EFI_INVALID_PARAMETER - KeyToggleState is NULL.
536
537 --*/
538 ;
539
540 EFI_STATUS
541 EFIAPI
542 KeyboardRegisterKeyNotify (
543 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
544 IN EFI_KEY_DATA *KeyData,
545 IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction,
546 OUT EFI_HANDLE *NotifyHandle
547 )
548 /*++
549
550 Routine Description:
551 Register a notification function for a particular keystroke for the input device.
552
553 Arguments:
554 This - Protocol instance pointer.
555 KeyData - A pointer to a buffer that is filled in with the keystroke
556 information data for the key that was pressed.
557 KeyNotificationFunction - Points to the function to be called when the key
558 sequence is typed specified by KeyData.
559 NotifyHandle - Points to the unique handle assigned to the registered notification.
560
561 Returns:
562 EFI_SUCCESS - The notification function was registered successfully.
563 EFI_OUT_OF_RESOURCES - Unable to allocate resources for necesssary data structures.
564 EFI_INVALID_PARAMETER - KeyData or NotifyHandle is NULL.
565
566 --*/
567 ;
568
569 EFI_STATUS
570 EFIAPI
571 KeyboardUnregisterKeyNotify (
572 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
573 IN EFI_HANDLE NotificationHandle
574 )
575 /*++
576
577 Routine Description:
578 Remove a registered notification function from a particular keystroke.
579
580 Arguments:
581 This - Protocol instance pointer.
582 NotificationHandle - The handle of the notification function being unregistered.
583
584 Returns:
585 EFI_SUCCESS - The notification function was unregistered successfully.
586 EFI_INVALID_PARAMETER - The NotificationHandle is invalid.
587 EFI_NOT_FOUND - Can not find the matching entry in database.
588
589 --*/
590 ;
591
592 #endif