]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkModulePkg/Bus/Isa/Ps2KeyboardDxe/Ps2Keyboard.h
Update comments.
[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
9f6531d1 37//\r
38// Global Variables\r
39//\r
40extern EFI_DRIVER_BINDING_PROTOCOL gKeyboardControllerDriver;\r
41extern EFI_COMPONENT_NAME_PROTOCOL gPs2KeyboardComponentName;\r
42extern EFI_COMPONENT_NAME2_PROTOCOL gPs2KeyboardComponentName2;\r
43\r
05fbd06d 44//\r
45// Driver Private Data\r
46//\r
47#define KEYBOARD_BUFFER_MAX_COUNT 32\r
f02bd376 48#define KEYBOARD_CONSOLE_IN_DEV_SIGNATURE SIGNATURE_32 ('k', 'k', 'e', 'y')\r
49#define KEYBOARD_CONSOLE_IN_EX_NOTIFY_SIGNATURE SIGNATURE_32 ('k', 'c', 'e', 'n')\r
f3d1e940 50\r
51typedef struct _KEYBOARD_CONSOLE_IN_EX_NOTIFY {\r
52 UINTN Signature;\r
53 EFI_HANDLE NotifyHandle;\r
54 EFI_KEY_DATA KeyData;\r
55 EFI_KEY_NOTIFY_FUNCTION KeyNotificationFn;\r
56 LIST_ENTRY NotifyEntry;\r
57} KEYBOARD_CONSOLE_IN_EX_NOTIFY;\r
58\r
05fbd06d 59\r
60typedef struct {\r
61 UINTN Signature;\r
62\r
63 EFI_HANDLE Handle;\r
64 EFI_SIMPLE_TEXT_INPUT_PROTOCOL ConIn;\r
f3d1e940 65 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL ConInEx;\r
05fbd06d 66 EFI_ISA_IO_PROTOCOL *IsaIo;\r
67\r
68 EFI_EVENT TimerEvent;\r
69\r
70 UINT32 DataRegisterAddress;\r
71 UINT32 StatusRegisterAddress;\r
72 UINT32 CommandRegisterAddress;\r
73\r
74 EFI_INPUT_KEY Key;\r
f3d1e940 75 EFI_KEY_STATE KeyState;\r
76\r
77 BOOLEAN LeftShift;\r
78 BOOLEAN RightShift; \r
79 BOOLEAN LeftLogo;\r
80 BOOLEAN RightLogo;\r
81 BOOLEAN Menu;\r
82 BOOLEAN SysReq;\r
05fbd06d 83\r
84 BOOLEAN Ctrl;\r
85 BOOLEAN Alt;\r
86 BOOLEAN Shift;\r
87 BOOLEAN CapsLock;\r
88 BOOLEAN NumLock;\r
89 BOOLEAN ScrollLock;\r
90\r
91 //\r
92 // Buffer storing key scancodes\r
93 //\r
94 UINT8 ScancodeBuf[KEYBOARD_BUFFER_MAX_COUNT];\r
95 UINT32 ScancodeBufStartPos;\r
96 UINT32 ScancodeBufEndPos;\r
97 UINT32 ScancodeBufCount;\r
98\r
99 //\r
100 // Indicators of the key pressing state, used in detecting Alt+Ctrl+Del\r
101 //\r
102 BOOLEAN Ctrled;\r
103 BOOLEAN Alted;\r
104\r
105 //\r
106 // Error state\r
107 //\r
108 BOOLEAN KeyboardErr;\r
109\r
110 EFI_UNICODE_STRING_TABLE *ControllerNameTable;\r
111\r
112 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
f3d1e940 113 //\r
114 // Notification Function List\r
115 //\r
116 LIST_ENTRY NotifyList;\r
05fbd06d 117} KEYBOARD_CONSOLE_IN_DEV;\r
118\r
119#define KEYBOARD_CONSOLE_IN_DEV_FROM_THIS(a) CR (a, KEYBOARD_CONSOLE_IN_DEV, ConIn, KEYBOARD_CONSOLE_IN_DEV_SIGNATURE)\r
f3d1e940 120#define TEXT_INPUT_EX_KEYBOARD_CONSOLE_IN_DEV_FROM_THIS(a) \\r
121 CR (a, \\r
122 KEYBOARD_CONSOLE_IN_DEV, \\r
123 ConInEx, \\r
124 KEYBOARD_CONSOLE_IN_DEV_SIGNATURE \\r
125 )\r
05fbd06d 126\r
127#define TABLE_END 0x0\r
128\r
05fbd06d 129//\r
130// Driver entry point\r
131//\r
bcd70414 132/**\r
133 The user Entry Point for module Ps2Keyboard. The user code starts with this function.\r
134\r
135 @param[in] ImageHandle The firmware allocated handle for the EFI image. \r
136 @param[in] SystemTable A pointer to the EFI System Table.\r
137 \r
138 @retval EFI_SUCCESS The entry point is executed successfully.\r
139 @retval other Some error occurs when executing this entry point.\r
140\r
141**/\r
05fbd06d 142EFI_STATUS\r
f3d1e940 143EFIAPI\r
05fbd06d 144InstallPs2KeyboardDriver (\r
145 IN EFI_HANDLE ImageHandle,\r
146 IN EFI_SYSTEM_TABLE *SystemTable\r
ed66e1bc 147 );\r
05fbd06d 148\r
149#define KEYBOARD_8042_DATA_REGISTER 0x60\r
150#define KEYBOARD_8042_STATUS_REGISTER 0x64\r
151#define KEYBOARD_8042_COMMAND_REGISTER 0x64\r
152\r
153#define KEYBOARD_KBEN 0xF4\r
154#define KEYBOARD_CMDECHO_ACK 0xFA\r
155\r
05f89b17 156#define KEYBOARD_MAX_TRY 256 // 256\r
05fbd06d 157#define KEYBOARD_TIMEOUT 65536 // 0.07s\r
158#define KEYBOARD_WAITFORVALUE_TIMEOUT 1000000 // 1s\r
159#define KEYBOARD_BAT_TIMEOUT 4000000 // 4s\r
160#define KEYBOARD_TIMER_INTERVAL 200000 // 0.02s\r
161#define SCANCODE_EXTENDED 0xE0\r
162#define SCANCODE_EXTENDED1 0xE1\r
163#define SCANCODE_CTRL_MAKE 0x1D\r
164#define SCANCODE_CTRL_BREAK 0x9D\r
165#define SCANCODE_ALT_MAKE 0x38\r
166#define SCANCODE_ALT_BREAK 0xB8\r
167#define SCANCODE_LEFT_SHIFT_MAKE 0x2A\r
168#define SCANCODE_LEFT_SHIFT_BREAK 0xAA\r
169#define SCANCODE_RIGHT_SHIFT_MAKE 0x36\r
170#define SCANCODE_RIGHT_SHIFT_BREAK 0xB6\r
171#define SCANCODE_CAPS_LOCK_MAKE 0x3A\r
172#define SCANCODE_NUM_LOCK_MAKE 0x45\r
173#define SCANCODE_SCROLL_LOCK_MAKE 0x46\r
f3d1e940 174#define SCANCODE_LEFT_LOGO_MAKE 0x5B //GUI key defined in Keyboard scan code\r
175#define SCANCODE_LEFT_LOGO_BREAK 0xDB\r
176#define SCANCODE_RIGHT_LOGO_MAKE 0x5C\r
177#define SCANCODE_RIGHT_LOGO_BREAK 0xDC\r
178#define SCANCODE_MENU_MAKE 0x5D //APPS key defined in Keyboard scan code \r
179#define SCANCODE_MENU_BREAK 0xDD\r
180#define SCANCODE_SYS_REQ_MAKE 0x37\r
181#define SCANCODE_MAX_MAKE 0x60\r
05fbd06d 182\r
007c18f5 183//\r
184// Keyboard Controller Status\r
185//\r
186#define KBC_PARE 0x80 // Parity Error\r
187#define KBC_TIM 0x40 // General Time Out\r
188\r
05fbd06d 189//\r
190// Other functions that are used among .c files\r
191//\r
bcd70414 192/**\r
193 Show keyboard status lights according to\r
194 indicators in ConsoleIn.\r
195\r
196 @param ConsoleIn Pointer to instance of KEYBOARD_CONSOLE_IN_DEV\r
197 \r
198 @return status\r
f3d1e940 199\r
bcd70414 200**/\r
f3d1e940 201EFI_STATUS\r
202UpdateStatusLights (\r
203 IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn\r
ed66e1bc 204 );\r
f3d1e940 205\r
bcd70414 206/**\r
207 write key to keyboard\r
f3d1e940 208\r
bcd70414 209 @param ConsoleIn Pointer to instance of KEYBOARD_CONSOLE_IN_DEV\r
210 @param Data value wanted to be written\r
f3d1e940 211\r
bcd70414 212 @retval EFI_TIMEOUT - GC_TODO: Add description for return value\r
213 @retval EFI_SUCCESS - GC_TODO: Add description for return value\r
f3d1e940 214\r
bcd70414 215**/\r
05fbd06d 216EFI_STATUS\r
217KeyboardRead (\r
218 IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn,\r
219 OUT UINT8 *Data\r
ed66e1bc 220 );\r
05fbd06d 221\r
bcd70414 222/**\r
223 Get scancode from scancode buffer\r
224 and translate into EFI-scancode and unicode defined by EFI spec\r
225 The function is always called in TPL_NOTIFY\r
05fbd06d 226\r
bcd70414 227 @param ConsoleIn KEYBOARD_CONSOLE_IN_DEV instance pointer\r
05fbd06d 228\r
bcd70414 229 @retval EFI_NOT_READY - Input from console not ready yet.\r
230 @retval EFI_SUCCESS - Function executed successfully.\r
05fbd06d 231\r
bcd70414 232**/\r
05fbd06d 233EFI_STATUS\r
234KeyGetchar (\r
235 IN OUT KEYBOARD_CONSOLE_IN_DEV *ConsoleIn\r
ed66e1bc 236 );\r
05fbd06d 237\r
bcd70414 238/**\r
239 Perform 8042 controller and keyboard Initialization\r
240 If ExtendedVerification is TRUE, do additional test for\r
241 the keyboard interface\r
05fbd06d 242\r
bcd70414 243 @param ConsoleIn - KEYBOARD_CONSOLE_IN_DEV instance pointer\r
244 @param ExtendedVerification - indicates a thorough initialization\r
05fbd06d 245\r
bcd70414 246 @retval EFI_DEVICE_ERROR Fail to init keyboard\r
247 @retval EFI_SUCCESS Success to init keyboard\r
248**/\r
05fbd06d 249EFI_STATUS\r
250InitKeyboard (\r
251 IN OUT KEYBOARD_CONSOLE_IN_DEV *ConsoleIn,\r
252 IN BOOLEAN ExtendedVerification\r
ed66e1bc 253 );\r
05fbd06d 254\r
bcd70414 255/**\r
256 Disable the keyboard interface of the 8042 controller\r
05fbd06d 257\r
bcd70414 258 @param ConsoleIn - the device instance\r
05fbd06d 259\r
bcd70414 260 @return status of issuing disable command\r
05fbd06d 261\r
bcd70414 262**/\r
05fbd06d 263EFI_STATUS\r
264DisableKeyboard (\r
265 IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn\r
ed66e1bc 266 );\r
05fbd06d 267\r
bcd70414 268/**\r
269 Timer event handler: read a series of scancodes from 8042\r
270 and put them into memory scancode buffer.\r
271 it read as much scancodes to either fill\r
272 the memory buffer or empty the keyboard buffer.\r
273 It is registered as running under TPL_NOTIFY\r
05fbd06d 274\r
bcd70414 275 @param Event - The timer event\r
276 @param Context - A KEYBOARD_CONSOLE_IN_DEV pointer\r
05fbd06d 277\r
bcd70414 278**/\r
05fbd06d 279VOID\r
280EFIAPI\r
281KeyboardTimerHandler (\r
282 IN EFI_EVENT Event,\r
283 IN VOID *Context\r
ed66e1bc 284 );\r
05fbd06d 285\r
bcd70414 286/**\r
287 logic reset keyboard\r
288 Implement SIMPLE_TEXT_IN.Reset()\r
289 Perform 8042 controller and keyboard initialization\r
05fbd06d 290\r
bcd70414 291 @param This Pointer to instance of EFI_SIMPLE_TEXT_INPUT_PROTOCOL\r
292 @param ExtendedVerification Indicate that the driver may perform a more \r
293 exhaustive verification operation of the device during \r
294 reset, now this par is ignored in this driver \r
05fbd06d 295\r
bcd70414 296**/\r
05fbd06d 297EFI_STATUS\r
298EFIAPI\r
299KeyboardEfiReset (\r
300 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,\r
301 IN BOOLEAN ExtendedVerification\r
ed66e1bc 302 );\r
05fbd06d 303\r
bcd70414 304/**\r
305 Implement SIMPLE_TEXT_IN.ReadKeyStroke().\r
306 Retrieve key values for driver user.\r
05fbd06d 307\r
bcd70414 308 @param This Pointer to instance of EFI_SIMPLE_TEXT_INPUT_PROTOCOL\r
309 @param Key The output buffer for key value \r
05fbd06d 310\r
bcd70414 311 @retval EFI_SUCCESS success to read key stroke\r
312**/\r
05fbd06d 313EFI_STATUS\r
314EFIAPI\r
315KeyboardReadKeyStroke (\r
316 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,\r
317 OUT EFI_INPUT_KEY *Key\r
ed66e1bc 318 );\r
05fbd06d 319\r
bcd70414 320/**\r
321 Event notification function for SIMPLE_TEXT_IN.WaitForKey event\r
322 Signal the event if there is key available\r
05fbd06d 323\r
bcd70414 324 @param Event the event object\r
325 @param Context waitting context\r
05fbd06d 326\r
bcd70414 327**/\r
05fbd06d 328VOID\r
329EFIAPI\r
330KeyboardWaitForKey (\r
331 IN EFI_EVENT Event,\r
332 IN VOID *Context\r
ed66e1bc 333 );\r
05fbd06d 334\r
bcd70414 335/**\r
336 Read status register\r
05fbd06d 337\r
bcd70414 338 @param ConsoleIn Pointer to instance of KEYBOARD_CONSOLE_IN_DEV\r
05fbd06d 339\r
bcd70414 340 @return value in status register\r
05fbd06d 341\r
bcd70414 342**/\r
05fbd06d 343UINT8\r
344KeyReadStatusRegister (\r
345 IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn\r
ed66e1bc 346 );\r
05fbd06d 347\r
348/**\r
349 Check whether there is Ps/2 Keyboard device in system by 0xF4 Keyboard Command\r
350 If Keyboard receives 0xF4, it will respond with 'ACK'. If it doesn't respond, the device\r
351 should not be in system.\r
352\r
353 @param[in] BiosKeyboardPrivate Keyboard Private Data Structure\r
354\r
f3d1e940 355 @retval TRUE Keyboard in System.\r
356 @retval FALSE Keyboard not in System.\r
05fbd06d 357**/\r
358BOOLEAN\r
359EFIAPI\r
360CheckKeyboardConnect (\r
361 IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn\r
ed66e1bc 362 );\r
f3d1e940 363\r
bcd70414 364/**\r
365 Event notification function for SIMPLE_TEXT_INPUT_EX_PROTOCOL.WaitForKeyEx event\r
366 Signal the event if there is key available\r
367\r
368 @param Event event object\r
369 @param Context waiting context\r
370\r
371**/\r
f3d1e940 372VOID\r
373EFIAPI\r
374KeyboardWaitForKeyEx (\r
375 IN EFI_EVENT Event,\r
376 IN VOID *Context\r
ed66e1bc 377 ); \r
f3d1e940 378\r
379//\r
380// Simple Text Input Ex protocol function prototypes\r
381//\r
382\r
bcd70414 383/**\r
384 Reset the input device and optionaly run diagnostics\r
385\r
386 @param This - Protocol instance pointer.\r
387 @param ExtendedVerification - Driver may perform diagnostics on reset.\r
388\r
389 @retval EFI_SUCCESS - The device was reset.\r
390 @retval EFI_DEVICE_ERROR - The device is not functioning properly and could \r
391 not be reset.\r
392\r
393**/\r
f3d1e940 394EFI_STATUS\r
395EFIAPI\r
396KeyboardEfiResetEx (\r
397 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,\r
398 IN BOOLEAN ExtendedVerification\r
ed66e1bc 399 );\r
f3d1e940 400\r
bcd70414 401/**\r
402 Reads the next keystroke from the input device. The WaitForKey Event can \r
403 be used to test for existance of a keystroke via WaitForEvent () call.\r
f3d1e940 404\r
f3d1e940 405\r
bcd70414 406 @param This - Protocol instance pointer.\r
407 @param KeyData - A pointer to a buffer that is filled in with the keystroke \r
408 state data for the key that was pressed.\r
f3d1e940 409\r
bcd70414 410 @retval EFI_SUCCESS - The keystroke information was returned.\r
411 @retval EFI_NOT_READY - There was no keystroke data availiable.\r
412 @retval EFI_DEVICE_ERROR - The keystroke information was not returned due to \r
413 hardware errors.\r
414 @retval EFI_INVALID_PARAMETER - KeyData is NULL. \r
f3d1e940 415\r
bcd70414 416**/\r
f3d1e940 417EFI_STATUS\r
418EFIAPI\r
419KeyboardReadKeyStrokeEx (\r
420 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,\r
421 OUT EFI_KEY_DATA *KeyData\r
ed66e1bc 422 );\r
f3d1e940 423\r
bcd70414 424/**\r
425 Set certain state for the input device.\r
f3d1e940 426\r
bcd70414 427 @param This - Protocol instance pointer.\r
428 @param KeyToggleState - A pointer to the EFI_KEY_TOGGLE_STATE to set the \r
429 state for the input device.\r
f3d1e940 430\r
bcd70414 431 @retval EFI_SUCCESS - The device state was set successfully.\r
432 @retval EFI_DEVICE_ERROR - The device is not functioning correctly and could \r
433 not have the setting adjusted.\r
434 @retval EFI_UNSUPPORTED - The device does not have the ability to set its state.\r
435 @retval EFI_INVALID_PARAMETER - KeyToggleState is NULL. \r
f3d1e940 436\r
bcd70414 437**/\r
f3d1e940 438EFI_STATUS\r
439EFIAPI\r
440KeyboardSetState (\r
441 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,\r
442 IN EFI_KEY_TOGGLE_STATE *KeyToggleState\r
ed66e1bc 443 );\r
f3d1e940 444\r
bcd70414 445/**\r
446 Register a notification function for a particular keystroke for the input device.\r
447\r
448 @param This - Protocol instance pointer.\r
449 @param KeyData - A pointer to a buffer that is filled in with the keystroke \r
450 information data for the key that was pressed.\r
451 @param KeyNotificationFunction - Points to the function to be called when the key \r
452 sequence is typed specified by KeyData. \r
453 @param NotifyHandle - Points to the unique handle assigned to the registered notification. \r
454\r
455 @retval EFI_SUCCESS - The notification function was registered successfully.\r
456 @retval EFI_OUT_OF_RESOURCES - Unable to allocate resources for necesssary data structures.\r
457 @retval EFI_INVALID_PARAMETER - KeyData or NotifyHandle is NULL. \r
458 \r
459**/ \r
f3d1e940 460EFI_STATUS\r
461EFIAPI\r
462KeyboardRegisterKeyNotify (\r
463 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,\r
464 IN EFI_KEY_DATA *KeyData,\r
465 IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction,\r
466 OUT EFI_HANDLE *NotifyHandle\r
ed66e1bc 467 );\r
f3d1e940 468\r
bcd70414 469/**\r
470 Remove a registered notification function from a particular keystroke.\r
f3d1e940 471\r
bcd70414 472 @param This - Protocol instance pointer. \r
473 @param NotificationHandle - The handle of the notification function being unregistered.\r
f3d1e940 474\r
bcd70414 475 \r
476 @retval EFI_SUCCESS - The notification function was unregistered successfully.\r
477 @retval EFI_INVALID_PARAMETER - The NotificationHandle is invalid.\r
478 @retval EFI_NOT_FOUND - Can not find the matching entry in database. \r
f3d1e940 479 \r
bcd70414 480**/ \r
f3d1e940 481EFI_STATUS\r
482EFIAPI\r
483KeyboardUnregisterKeyNotify (\r
484 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,\r
485 IN EFI_HANDLE NotificationHandle\r
ed66e1bc 486 );\r
f3d1e940 487\r
05fbd06d 488#endif\r