]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkModulePkg/Bus/Isa/Ps2KeyboardDxe/Ps2Keyboard.h
Adjust the code so that global variable placed at beginning of file.
[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
183//\r
184// Other functions that are used among .c files\r
185//\r
bcd70414 186/**\r
187 Show keyboard status lights according to\r
188 indicators in ConsoleIn.\r
189\r
190 @param ConsoleIn Pointer to instance of KEYBOARD_CONSOLE_IN_DEV\r
191 \r
192 @return status\r
f3d1e940 193\r
bcd70414 194**/\r
f3d1e940 195EFI_STATUS\r
196UpdateStatusLights (\r
197 IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn\r
ed66e1bc 198 );\r
f3d1e940 199\r
bcd70414 200/**\r
201 write key to keyboard\r
f3d1e940 202\r
bcd70414 203 @param ConsoleIn Pointer to instance of KEYBOARD_CONSOLE_IN_DEV\r
204 @param Data value wanted to be written\r
f3d1e940 205\r
bcd70414 206 @retval EFI_TIMEOUT - GC_TODO: Add description for return value\r
207 @retval EFI_SUCCESS - GC_TODO: Add description for return value\r
f3d1e940 208\r
bcd70414 209**/\r
05fbd06d 210EFI_STATUS\r
211KeyboardRead (\r
212 IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn,\r
213 OUT UINT8 *Data\r
ed66e1bc 214 );\r
05fbd06d 215\r
bcd70414 216/**\r
217 Get scancode from scancode buffer\r
218 and translate into EFI-scancode and unicode defined by EFI spec\r
219 The function is always called in TPL_NOTIFY\r
05fbd06d 220\r
bcd70414 221 @param ConsoleIn KEYBOARD_CONSOLE_IN_DEV instance pointer\r
05fbd06d 222\r
bcd70414 223 @retval EFI_NOT_READY - Input from console not ready yet.\r
224 @retval EFI_SUCCESS - Function executed successfully.\r
05fbd06d 225\r
bcd70414 226**/\r
05fbd06d 227EFI_STATUS\r
228KeyGetchar (\r
229 IN OUT KEYBOARD_CONSOLE_IN_DEV *ConsoleIn\r
ed66e1bc 230 );\r
05fbd06d 231\r
bcd70414 232/**\r
233 Perform 8042 controller and keyboard Initialization\r
234 If ExtendedVerification is TRUE, do additional test for\r
235 the keyboard interface\r
05fbd06d 236\r
bcd70414 237 @param ConsoleIn - KEYBOARD_CONSOLE_IN_DEV instance pointer\r
238 @param ExtendedVerification - indicates a thorough initialization\r
05fbd06d 239\r
bcd70414 240 @retval EFI_DEVICE_ERROR Fail to init keyboard\r
241 @retval EFI_SUCCESS Success to init keyboard\r
242**/\r
05fbd06d 243EFI_STATUS\r
244InitKeyboard (\r
245 IN OUT KEYBOARD_CONSOLE_IN_DEV *ConsoleIn,\r
246 IN BOOLEAN ExtendedVerification\r
ed66e1bc 247 );\r
05fbd06d 248\r
bcd70414 249/**\r
250 Disable the keyboard interface of the 8042 controller\r
05fbd06d 251\r
bcd70414 252 @param ConsoleIn - the device instance\r
05fbd06d 253\r
bcd70414 254 @return status of issuing disable command\r
05fbd06d 255\r
bcd70414 256**/\r
05fbd06d 257EFI_STATUS\r
258DisableKeyboard (\r
259 IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn\r
ed66e1bc 260 );\r
05fbd06d 261\r
bcd70414 262/**\r
263 Timer event handler: read a series of scancodes from 8042\r
264 and put them into memory scancode buffer.\r
265 it read as much scancodes to either fill\r
266 the memory buffer or empty the keyboard buffer.\r
267 It is registered as running under TPL_NOTIFY\r
05fbd06d 268\r
bcd70414 269 @param Event - The timer event\r
270 @param Context - A KEYBOARD_CONSOLE_IN_DEV pointer\r
05fbd06d 271\r
bcd70414 272**/\r
05fbd06d 273VOID\r
274EFIAPI\r
275KeyboardTimerHandler (\r
276 IN EFI_EVENT Event,\r
277 IN VOID *Context\r
ed66e1bc 278 );\r
05fbd06d 279\r
bcd70414 280/**\r
281 logic reset keyboard\r
282 Implement SIMPLE_TEXT_IN.Reset()\r
283 Perform 8042 controller and keyboard initialization\r
05fbd06d 284\r
bcd70414 285 @param This Pointer to instance of EFI_SIMPLE_TEXT_INPUT_PROTOCOL\r
286 @param ExtendedVerification Indicate that the driver may perform a more \r
287 exhaustive verification operation of the device during \r
288 reset, now this par is ignored in this driver \r
05fbd06d 289\r
bcd70414 290**/\r
05fbd06d 291EFI_STATUS\r
292EFIAPI\r
293KeyboardEfiReset (\r
294 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,\r
295 IN BOOLEAN ExtendedVerification\r
ed66e1bc 296 );\r
05fbd06d 297\r
bcd70414 298/**\r
299 Implement SIMPLE_TEXT_IN.ReadKeyStroke().\r
300 Retrieve key values for driver user.\r
05fbd06d 301\r
bcd70414 302 @param This Pointer to instance of EFI_SIMPLE_TEXT_INPUT_PROTOCOL\r
303 @param Key The output buffer for key value \r
05fbd06d 304\r
bcd70414 305 @retval EFI_SUCCESS success to read key stroke\r
306**/\r
05fbd06d 307EFI_STATUS\r
308EFIAPI\r
309KeyboardReadKeyStroke (\r
310 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,\r
311 OUT EFI_INPUT_KEY *Key\r
ed66e1bc 312 );\r
05fbd06d 313\r
bcd70414 314/**\r
315 Event notification function for SIMPLE_TEXT_IN.WaitForKey event\r
316 Signal the event if there is key available\r
05fbd06d 317\r
bcd70414 318 @param Event the event object\r
319 @param Context waitting context\r
05fbd06d 320\r
bcd70414 321**/\r
05fbd06d 322VOID\r
323EFIAPI\r
324KeyboardWaitForKey (\r
325 IN EFI_EVENT Event,\r
326 IN VOID *Context\r
ed66e1bc 327 );\r
05fbd06d 328\r
bcd70414 329/**\r
330 Read status register\r
05fbd06d 331\r
bcd70414 332 @param ConsoleIn Pointer to instance of KEYBOARD_CONSOLE_IN_DEV\r
05fbd06d 333\r
bcd70414 334 @return value in status register\r
05fbd06d 335\r
bcd70414 336**/\r
05fbd06d 337UINT8\r
338KeyReadStatusRegister (\r
339 IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn\r
ed66e1bc 340 );\r
05fbd06d 341\r
342/**\r
343 Check whether there is Ps/2 Keyboard device in system by 0xF4 Keyboard Command\r
344 If Keyboard receives 0xF4, it will respond with 'ACK'. If it doesn't respond, the device\r
345 should not be in system.\r
346\r
347 @param[in] BiosKeyboardPrivate Keyboard Private Data Structure\r
348\r
f3d1e940 349 @retval TRUE Keyboard in System.\r
350 @retval FALSE Keyboard not in System.\r
05fbd06d 351**/\r
352BOOLEAN\r
353EFIAPI\r
354CheckKeyboardConnect (\r
355 IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn\r
ed66e1bc 356 );\r
f3d1e940 357\r
bcd70414 358/**\r
359 Event notification function for SIMPLE_TEXT_INPUT_EX_PROTOCOL.WaitForKeyEx event\r
360 Signal the event if there is key available\r
361\r
362 @param Event event object\r
363 @param Context waiting context\r
364\r
365**/\r
f3d1e940 366VOID\r
367EFIAPI\r
368KeyboardWaitForKeyEx (\r
369 IN EFI_EVENT Event,\r
370 IN VOID *Context\r
ed66e1bc 371 ); \r
f3d1e940 372\r
373//\r
374// Simple Text Input Ex protocol function prototypes\r
375//\r
376\r
bcd70414 377/**\r
378 Reset the input device and optionaly run diagnostics\r
379\r
380 @param This - Protocol instance pointer.\r
381 @param ExtendedVerification - Driver may perform diagnostics on reset.\r
382\r
383 @retval EFI_SUCCESS - The device was reset.\r
384 @retval EFI_DEVICE_ERROR - The device is not functioning properly and could \r
385 not be reset.\r
386\r
387**/\r
f3d1e940 388EFI_STATUS\r
389EFIAPI\r
390KeyboardEfiResetEx (\r
391 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,\r
392 IN BOOLEAN ExtendedVerification\r
ed66e1bc 393 );\r
f3d1e940 394\r
bcd70414 395/**\r
396 Reads the next keystroke from the input device. The WaitForKey Event can \r
397 be used to test for existance of a keystroke via WaitForEvent () call.\r
f3d1e940 398\r
f3d1e940 399\r
bcd70414 400 @param This - Protocol instance pointer.\r
401 @param KeyData - A pointer to a buffer that is filled in with the keystroke \r
402 state data for the key that was pressed.\r
f3d1e940 403\r
bcd70414 404 @retval EFI_SUCCESS - The keystroke information was returned.\r
405 @retval EFI_NOT_READY - There was no keystroke data availiable.\r
406 @retval EFI_DEVICE_ERROR - The keystroke information was not returned due to \r
407 hardware errors.\r
408 @retval EFI_INVALID_PARAMETER - KeyData is NULL. \r
f3d1e940 409\r
bcd70414 410**/\r
f3d1e940 411EFI_STATUS\r
412EFIAPI\r
413KeyboardReadKeyStrokeEx (\r
414 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,\r
415 OUT EFI_KEY_DATA *KeyData\r
ed66e1bc 416 );\r
f3d1e940 417\r
bcd70414 418/**\r
419 Set certain state for the input device.\r
f3d1e940 420\r
bcd70414 421 @param This - Protocol instance pointer.\r
422 @param KeyToggleState - A pointer to the EFI_KEY_TOGGLE_STATE to set the \r
423 state for the input device.\r
f3d1e940 424\r
bcd70414 425 @retval EFI_SUCCESS - The device state was set successfully.\r
426 @retval EFI_DEVICE_ERROR - The device is not functioning correctly and could \r
427 not have the setting adjusted.\r
428 @retval EFI_UNSUPPORTED - The device does not have the ability to set its state.\r
429 @retval EFI_INVALID_PARAMETER - KeyToggleState is NULL. \r
f3d1e940 430\r
bcd70414 431**/\r
f3d1e940 432EFI_STATUS\r
433EFIAPI\r
434KeyboardSetState (\r
435 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,\r
436 IN EFI_KEY_TOGGLE_STATE *KeyToggleState\r
ed66e1bc 437 );\r
f3d1e940 438\r
bcd70414 439/**\r
440 Register a notification function for a particular keystroke for the input device.\r
441\r
442 @param This - Protocol instance pointer.\r
443 @param KeyData - A pointer to a buffer that is filled in with the keystroke \r
444 information data for the key that was pressed.\r
445 @param KeyNotificationFunction - Points to the function to be called when the key \r
446 sequence is typed specified by KeyData. \r
447 @param NotifyHandle - Points to the unique handle assigned to the registered notification. \r
448\r
449 @retval EFI_SUCCESS - The notification function was registered successfully.\r
450 @retval EFI_OUT_OF_RESOURCES - Unable to allocate resources for necesssary data structures.\r
451 @retval EFI_INVALID_PARAMETER - KeyData or NotifyHandle is NULL. \r
452 \r
453**/ \r
f3d1e940 454EFI_STATUS\r
455EFIAPI\r
456KeyboardRegisterKeyNotify (\r
457 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,\r
458 IN EFI_KEY_DATA *KeyData,\r
459 IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction,\r
460 OUT EFI_HANDLE *NotifyHandle\r
ed66e1bc 461 );\r
f3d1e940 462\r
bcd70414 463/**\r
464 Remove a registered notification function from a particular keystroke.\r
f3d1e940 465\r
bcd70414 466 @param This - Protocol instance pointer. \r
467 @param NotificationHandle - The handle of the notification function being unregistered.\r
f3d1e940 468\r
bcd70414 469 \r
470 @retval EFI_SUCCESS - The notification function was unregistered successfully.\r
471 @retval EFI_INVALID_PARAMETER - The NotificationHandle is invalid.\r
472 @retval EFI_NOT_FOUND - Can not find the matching entry in database. \r
f3d1e940 473 \r
bcd70414 474**/ \r
f3d1e940 475EFI_STATUS\r
476EFIAPI\r
477KeyboardUnregisterKeyNotify (\r
478 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,\r
479 IN EFI_HANDLE NotificationHandle\r
ed66e1bc 480 );\r
f3d1e940 481\r
05fbd06d 482#endif\r