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