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