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