]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkModulePkg/Bus/Isa/Ps2KeyboardDxe/Ps2Keyboard.h
Coding style modification.
[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
bcd70414 134/**\r
135 The user Entry Point for module Ps2Keyboard. The user code starts with this function.\r
136\r
137 @param[in] ImageHandle The firmware allocated handle for the EFI image. \r
138 @param[in] SystemTable A pointer to the EFI System Table.\r
139 \r
140 @retval EFI_SUCCESS The entry point is executed successfully.\r
141 @retval other Some error occurs when executing this entry point.\r
142\r
143**/\r
05fbd06d 144EFI_STATUS\r
f3d1e940 145EFIAPI\r
05fbd06d 146InstallPs2KeyboardDriver (\r
147 IN EFI_HANDLE ImageHandle,\r
148 IN EFI_SYSTEM_TABLE *SystemTable\r
149 )\r
05fbd06d 150;\r
151\r
152#define KEYBOARD_8042_DATA_REGISTER 0x60\r
153#define KEYBOARD_8042_STATUS_REGISTER 0x64\r
154#define KEYBOARD_8042_COMMAND_REGISTER 0x64\r
155\r
156#define KEYBOARD_KBEN 0xF4\r
157#define KEYBOARD_CMDECHO_ACK 0xFA\r
158\r
159#define KEYBOARD_TIMEOUT 65536 // 0.07s\r
160#define KEYBOARD_WAITFORVALUE_TIMEOUT 1000000 // 1s\r
161#define KEYBOARD_BAT_TIMEOUT 4000000 // 4s\r
162#define KEYBOARD_TIMER_INTERVAL 200000 // 0.02s\r
163#define SCANCODE_EXTENDED 0xE0\r
164#define SCANCODE_EXTENDED1 0xE1\r
165#define SCANCODE_CTRL_MAKE 0x1D\r
166#define SCANCODE_CTRL_BREAK 0x9D\r
167#define SCANCODE_ALT_MAKE 0x38\r
168#define SCANCODE_ALT_BREAK 0xB8\r
169#define SCANCODE_LEFT_SHIFT_MAKE 0x2A\r
170#define SCANCODE_LEFT_SHIFT_BREAK 0xAA\r
171#define SCANCODE_RIGHT_SHIFT_MAKE 0x36\r
172#define SCANCODE_RIGHT_SHIFT_BREAK 0xB6\r
173#define SCANCODE_CAPS_LOCK_MAKE 0x3A\r
174#define SCANCODE_NUM_LOCK_MAKE 0x45\r
175#define SCANCODE_SCROLL_LOCK_MAKE 0x46\r
f3d1e940 176#define SCANCODE_LEFT_LOGO_MAKE 0x5B //GUI key defined in Keyboard scan code\r
177#define SCANCODE_LEFT_LOGO_BREAK 0xDB\r
178#define SCANCODE_RIGHT_LOGO_MAKE 0x5C\r
179#define SCANCODE_RIGHT_LOGO_BREAK 0xDC\r
180#define SCANCODE_MENU_MAKE 0x5D //APPS key defined in Keyboard scan code \r
181#define SCANCODE_MENU_BREAK 0xDD\r
182#define SCANCODE_SYS_REQ_MAKE 0x37\r
183#define SCANCODE_MAX_MAKE 0x60\r
05fbd06d 184\r
185//\r
186// Other functions that are used among .c files\r
187//\r
bcd70414 188/**\r
189 Show keyboard status lights according to\r
190 indicators in ConsoleIn.\r
191\r
192 @param ConsoleIn Pointer to instance of KEYBOARD_CONSOLE_IN_DEV\r
193 \r
194 @return status\r
f3d1e940 195\r
bcd70414 196**/\r
f3d1e940 197EFI_STATUS\r
198UpdateStatusLights (\r
199 IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn\r
200 )\r
bcd70414 201;\r
f3d1e940 202\r
bcd70414 203/**\r
204 write key to keyboard\r
f3d1e940 205\r
bcd70414 206 @param ConsoleIn Pointer to instance of KEYBOARD_CONSOLE_IN_DEV\r
207 @param Data value wanted to be written\r
f3d1e940 208\r
bcd70414 209 @retval EFI_TIMEOUT - GC_TODO: Add description for return value\r
210 @retval EFI_SUCCESS - GC_TODO: Add description for return value\r
f3d1e940 211\r
bcd70414 212**/\r
05fbd06d 213EFI_STATUS\r
214KeyboardRead (\r
215 IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn,\r
216 OUT UINT8 *Data\r
217 )\r
bcd70414 218;\r
05fbd06d 219\r
bcd70414 220/**\r
221 Get scancode from scancode buffer\r
222 and translate into EFI-scancode and unicode defined by EFI spec\r
223 The function is always called in TPL_NOTIFY\r
05fbd06d 224\r
bcd70414 225 @param ConsoleIn KEYBOARD_CONSOLE_IN_DEV instance pointer\r
05fbd06d 226\r
bcd70414 227 @retval EFI_NOT_READY - Input from console not ready yet.\r
228 @retval EFI_SUCCESS - Function executed successfully.\r
05fbd06d 229\r
bcd70414 230**/\r
05fbd06d 231EFI_STATUS\r
232KeyGetchar (\r
233 IN OUT KEYBOARD_CONSOLE_IN_DEV *ConsoleIn\r
234 )\r
bcd70414 235;\r
05fbd06d 236\r
bcd70414 237/**\r
238 Perform 8042 controller and keyboard Initialization\r
239 If ExtendedVerification is TRUE, do additional test for\r
240 the keyboard interface\r
05fbd06d 241\r
bcd70414 242 @param ConsoleIn - KEYBOARD_CONSOLE_IN_DEV instance pointer\r
243 @param ExtendedVerification - indicates a thorough initialization\r
05fbd06d 244\r
bcd70414 245 @retval EFI_DEVICE_ERROR Fail to init keyboard\r
246 @retval EFI_SUCCESS Success to init keyboard\r
247**/\r
05fbd06d 248EFI_STATUS\r
249InitKeyboard (\r
250 IN OUT KEYBOARD_CONSOLE_IN_DEV *ConsoleIn,\r
251 IN BOOLEAN ExtendedVerification\r
252 )\r
bcd70414 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
266 )\r
bcd70414 267;\r
05fbd06d 268\r
bcd70414 269/**\r
270 Timer event handler: read a series of scancodes from 8042\r
271 and put them into memory scancode buffer.\r
272 it read as much scancodes to either fill\r
273 the memory buffer or empty the keyboard buffer.\r
274 It is registered as running under TPL_NOTIFY\r
05fbd06d 275\r
bcd70414 276 @param Event - The timer event\r
277 @param Context - A KEYBOARD_CONSOLE_IN_DEV pointer\r
05fbd06d 278\r
bcd70414 279**/\r
05fbd06d 280VOID\r
281EFIAPI\r
282KeyboardTimerHandler (\r
283 IN EFI_EVENT Event,\r
284 IN VOID *Context\r
285 )\r
bcd70414 286;\r
05fbd06d 287\r
bcd70414 288/**\r
289 logic reset keyboard\r
290 Implement SIMPLE_TEXT_IN.Reset()\r
291 Perform 8042 controller and keyboard initialization\r
05fbd06d 292\r
bcd70414 293 @param This Pointer to instance of EFI_SIMPLE_TEXT_INPUT_PROTOCOL\r
294 @param ExtendedVerification Indicate that the driver may perform a more \r
295 exhaustive verification operation of the device during \r
296 reset, now this par is ignored in this driver \r
05fbd06d 297\r
bcd70414 298**/\r
05fbd06d 299EFI_STATUS\r
300EFIAPI\r
301KeyboardEfiReset (\r
302 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,\r
303 IN BOOLEAN ExtendedVerification\r
304 )\r
bcd70414 305;\r
05fbd06d 306\r
bcd70414 307/**\r
308 Implement SIMPLE_TEXT_IN.ReadKeyStroke().\r
309 Retrieve key values for driver user.\r
05fbd06d 310\r
bcd70414 311 @param This Pointer to instance of EFI_SIMPLE_TEXT_INPUT_PROTOCOL\r
312 @param Key The output buffer for key value \r
05fbd06d 313\r
bcd70414 314 @retval EFI_SUCCESS success to read key stroke\r
315**/\r
05fbd06d 316EFI_STATUS\r
317EFIAPI\r
318KeyboardReadKeyStroke (\r
319 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,\r
320 OUT EFI_INPUT_KEY *Key\r
321 )\r
bcd70414 322;\r
05fbd06d 323\r
bcd70414 324/**\r
325 Event notification function for SIMPLE_TEXT_IN.WaitForKey event\r
326 Signal the event if there is key available\r
05fbd06d 327\r
bcd70414 328 @param Event the event object\r
329 @param Context waitting context\r
05fbd06d 330\r
bcd70414 331**/\r
05fbd06d 332VOID\r
333EFIAPI\r
334KeyboardWaitForKey (\r
335 IN EFI_EVENT Event,\r
336 IN VOID *Context\r
337 )\r
bcd70414 338;\r
05fbd06d 339\r
bcd70414 340/**\r
341 Read status register\r
05fbd06d 342\r
bcd70414 343 @param ConsoleIn Pointer to instance of KEYBOARD_CONSOLE_IN_DEV\r
05fbd06d 344\r
bcd70414 345 @return value in status register\r
05fbd06d 346\r
bcd70414 347**/\r
05fbd06d 348UINT8\r
349KeyReadStatusRegister (\r
350 IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn\r
351 )\r
05fbd06d 352;\r
353\r
354/**\r
355 Check whether there is Ps/2 Keyboard device in system by 0xF4 Keyboard Command\r
356 If Keyboard receives 0xF4, it will respond with 'ACK'. If it doesn't respond, the device\r
357 should not be in system.\r
358\r
359 @param[in] BiosKeyboardPrivate Keyboard Private Data Structure\r
360\r
f3d1e940 361 @retval TRUE Keyboard in System.\r
362 @retval FALSE Keyboard not in System.\r
05fbd06d 363**/\r
364BOOLEAN\r
365EFIAPI\r
366CheckKeyboardConnect (\r
367 IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn\r
368 )\r
369;\r
f3d1e940 370\r
bcd70414 371/**\r
372 Event notification function for SIMPLE_TEXT_INPUT_EX_PROTOCOL.WaitForKeyEx event\r
373 Signal the event if there is key available\r
374\r
375 @param Event event object\r
376 @param Context waiting context\r
377\r
378**/\r
f3d1e940 379VOID\r
380EFIAPI\r
381KeyboardWaitForKeyEx (\r
382 IN EFI_EVENT Event,\r
383 IN VOID *Context\r
384 )\r
f3d1e940 385; \r
386\r
387//\r
388// Simple Text Input Ex protocol function prototypes\r
389//\r
390\r
bcd70414 391/**\r
392 Reset the input device and optionaly run diagnostics\r
393\r
394 @param This - Protocol instance pointer.\r
395 @param ExtendedVerification - Driver may perform diagnostics on reset.\r
396\r
397 @retval EFI_SUCCESS - The device was reset.\r
398 @retval EFI_DEVICE_ERROR - The device is not functioning properly and could \r
399 not be reset.\r
400\r
401**/\r
f3d1e940 402EFI_STATUS\r
403EFIAPI\r
404KeyboardEfiResetEx (\r
405 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,\r
406 IN BOOLEAN ExtendedVerification\r
407 )\r
bcd70414 408;\r
f3d1e940 409\r
bcd70414 410/**\r
411 Reads the next keystroke from the input device. The WaitForKey Event can \r
412 be used to test for existance of a keystroke via WaitForEvent () call.\r
f3d1e940 413\r
f3d1e940 414\r
bcd70414 415 @param This - Protocol instance pointer.\r
416 @param KeyData - A pointer to a buffer that is filled in with the keystroke \r
417 state data for the key that was pressed.\r
f3d1e940 418\r
bcd70414 419 @retval EFI_SUCCESS - The keystroke information was returned.\r
420 @retval EFI_NOT_READY - There was no keystroke data availiable.\r
421 @retval EFI_DEVICE_ERROR - The keystroke information was not returned due to \r
422 hardware errors.\r
423 @retval EFI_INVALID_PARAMETER - KeyData is NULL. \r
f3d1e940 424\r
bcd70414 425**/\r
f3d1e940 426EFI_STATUS\r
427EFIAPI\r
428KeyboardReadKeyStrokeEx (\r
429 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,\r
430 OUT EFI_KEY_DATA *KeyData\r
431 )\r
bcd70414 432;\r
f3d1e940 433\r
bcd70414 434/**\r
435 Set certain state for the input device.\r
f3d1e940 436\r
bcd70414 437 @param This - Protocol instance pointer.\r
438 @param KeyToggleState - A pointer to the EFI_KEY_TOGGLE_STATE to set the \r
439 state for the input device.\r
f3d1e940 440\r
bcd70414 441 @retval EFI_SUCCESS - The device state was set successfully.\r
442 @retval EFI_DEVICE_ERROR - The device is not functioning correctly and could \r
443 not have the setting adjusted.\r
444 @retval EFI_UNSUPPORTED - The device does not have the ability to set its state.\r
445 @retval EFI_INVALID_PARAMETER - KeyToggleState is NULL. \r
f3d1e940 446\r
bcd70414 447**/\r
f3d1e940 448EFI_STATUS\r
449EFIAPI\r
450KeyboardSetState (\r
451 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,\r
452 IN EFI_KEY_TOGGLE_STATE *KeyToggleState\r
453 )\r
f3d1e940 454;\r
455\r
bcd70414 456/**\r
457 Register a notification function for a particular keystroke for the input device.\r
458\r
459 @param This - Protocol instance pointer.\r
460 @param KeyData - A pointer to a buffer that is filled in with the keystroke \r
461 information data for the key that was pressed.\r
462 @param KeyNotificationFunction - Points to the function to be called when the key \r
463 sequence is typed specified by KeyData. \r
464 @param NotifyHandle - Points to the unique handle assigned to the registered notification. \r
465\r
466 @retval EFI_SUCCESS - The notification function was registered successfully.\r
467 @retval EFI_OUT_OF_RESOURCES - Unable to allocate resources for necesssary data structures.\r
468 @retval EFI_INVALID_PARAMETER - KeyData or NotifyHandle is NULL. \r
469 \r
470**/ \r
f3d1e940 471EFI_STATUS\r
472EFIAPI\r
473KeyboardRegisterKeyNotify (\r
474 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,\r
475 IN EFI_KEY_DATA *KeyData,\r
476 IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction,\r
477 OUT EFI_HANDLE *NotifyHandle\r
478 )\r
bcd70414 479;\r
f3d1e940 480\r
bcd70414 481/**\r
482 Remove a registered notification function from a particular keystroke.\r
f3d1e940 483\r
bcd70414 484 @param This - Protocol instance pointer. \r
485 @param NotificationHandle - The handle of the notification function being unregistered.\r
f3d1e940 486\r
bcd70414 487 \r
488 @retval EFI_SUCCESS - The notification function was unregistered successfully.\r
489 @retval EFI_INVALID_PARAMETER - The NotificationHandle is invalid.\r
490 @retval EFI_NOT_FOUND - Can not find the matching entry in database. \r
f3d1e940 491 \r
bcd70414 492**/ \r
f3d1e940 493EFI_STATUS\r
494EFIAPI\r
495KeyboardUnregisterKeyNotify (\r
496 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,\r
497 IN EFI_HANDLE NotificationHandle\r
498 )\r
f3d1e940 499;\r
500\r
05fbd06d 501#endif\r