]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - IntelFrameworkModulePkg/Bus/Isa/Ps2KeyboardDxe/Ps2Keyboard.h
Update comments.
[mirror_edk2.git] / IntelFrameworkModulePkg / Bus / Isa / Ps2KeyboardDxe / Ps2Keyboard.h
... / ...
CommitLineData
1/**@file\r
2 PS/2 keyboard driver header file\r
3\r
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
12\r
13**/\r
14\r
15#ifndef _PS2KEYBOARD_H\r
16#define _PS2KEYBOARD_H\r
17\r
18#include <PiDxe.h>\r
19#include <Framework/StatusCode.h>\r
20\r
21#include <Protocol/SimpleTextIn.h>\r
22#include <Protocol/SimpleTextInEx.h>\r
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
34#include <Library/BaseLib.h>\r
35#include <Library/BaseMemoryLib.h>\r
36\r
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
44//\r
45// Driver Private Data\r
46//\r
47#define KEYBOARD_BUFFER_MAX_COUNT 32\r
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
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
59\r
60typedef struct {\r
61 UINTN Signature;\r
62\r
63 EFI_HANDLE Handle;\r
64 EFI_SIMPLE_TEXT_INPUT_PROTOCOL ConIn;\r
65 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL ConInEx;\r
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
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
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
113 //\r
114 // Notification Function List\r
115 //\r
116 LIST_ENTRY NotifyList;\r
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
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
126\r
127#define TABLE_END 0x0\r
128\r
129//\r
130// Driver entry point\r
131//\r
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
142EFI_STATUS\r
143EFIAPI\r
144InstallPs2KeyboardDriver (\r
145 IN EFI_HANDLE ImageHandle,\r
146 IN EFI_SYSTEM_TABLE *SystemTable\r
147 );\r
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
156#define KEYBOARD_MAX_TRY 256 // 256\r
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
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
182\r
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
189//\r
190// Other functions that are used among .c files\r
191//\r
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
199\r
200**/\r
201EFI_STATUS\r
202UpdateStatusLights (\r
203 IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn\r
204 );\r
205\r
206/**\r
207 write key to keyboard\r
208\r
209 @param ConsoleIn Pointer to instance of KEYBOARD_CONSOLE_IN_DEV\r
210 @param Data value wanted to be written\r
211\r
212 @retval EFI_TIMEOUT - GC_TODO: Add description for return value\r
213 @retval EFI_SUCCESS - GC_TODO: Add description for return value\r
214\r
215**/\r
216EFI_STATUS\r
217KeyboardRead (\r
218 IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn,\r
219 OUT UINT8 *Data\r
220 );\r
221\r
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
226\r
227 @param ConsoleIn KEYBOARD_CONSOLE_IN_DEV instance pointer\r
228\r
229 @retval EFI_NOT_READY - Input from console not ready yet.\r
230 @retval EFI_SUCCESS - Function executed successfully.\r
231\r
232**/\r
233EFI_STATUS\r
234KeyGetchar (\r
235 IN OUT KEYBOARD_CONSOLE_IN_DEV *ConsoleIn\r
236 );\r
237\r
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
242\r
243 @param ConsoleIn - KEYBOARD_CONSOLE_IN_DEV instance pointer\r
244 @param ExtendedVerification - indicates a thorough initialization\r
245\r
246 @retval EFI_DEVICE_ERROR Fail to init keyboard\r
247 @retval EFI_SUCCESS Success to init keyboard\r
248**/\r
249EFI_STATUS\r
250InitKeyboard (\r
251 IN OUT KEYBOARD_CONSOLE_IN_DEV *ConsoleIn,\r
252 IN BOOLEAN ExtendedVerification\r
253 );\r
254\r
255/**\r
256 Disable the keyboard interface of the 8042 controller\r
257\r
258 @param ConsoleIn - the device instance\r
259\r
260 @return status of issuing disable command\r
261\r
262**/\r
263EFI_STATUS\r
264DisableKeyboard (\r
265 IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn\r
266 );\r
267\r
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
274\r
275 @param Event - The timer event\r
276 @param Context - A KEYBOARD_CONSOLE_IN_DEV pointer\r
277\r
278**/\r
279VOID\r
280EFIAPI\r
281KeyboardTimerHandler (\r
282 IN EFI_EVENT Event,\r
283 IN VOID *Context\r
284 );\r
285\r
286/**\r
287 logic reset keyboard\r
288 Implement SIMPLE_TEXT_IN.Reset()\r
289 Perform 8042 controller and keyboard initialization\r
290\r
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
295\r
296**/\r
297EFI_STATUS\r
298EFIAPI\r
299KeyboardEfiReset (\r
300 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,\r
301 IN BOOLEAN ExtendedVerification\r
302 );\r
303\r
304/**\r
305 Implement SIMPLE_TEXT_IN.ReadKeyStroke().\r
306 Retrieve key values for driver user.\r
307\r
308 @param This Pointer to instance of EFI_SIMPLE_TEXT_INPUT_PROTOCOL\r
309 @param Key The output buffer for key value \r
310\r
311 @retval EFI_SUCCESS success to read key stroke\r
312**/\r
313EFI_STATUS\r
314EFIAPI\r
315KeyboardReadKeyStroke (\r
316 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,\r
317 OUT EFI_INPUT_KEY *Key\r
318 );\r
319\r
320/**\r
321 Event notification function for SIMPLE_TEXT_IN.WaitForKey event\r
322 Signal the event if there is key available\r
323\r
324 @param Event the event object\r
325 @param Context waitting context\r
326\r
327**/\r
328VOID\r
329EFIAPI\r
330KeyboardWaitForKey (\r
331 IN EFI_EVENT Event,\r
332 IN VOID *Context\r
333 );\r
334\r
335/**\r
336 Read status register\r
337\r
338 @param ConsoleIn Pointer to instance of KEYBOARD_CONSOLE_IN_DEV\r
339\r
340 @return value in status register\r
341\r
342**/\r
343UINT8\r
344KeyReadStatusRegister (\r
345 IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn\r
346 );\r
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
355 @retval TRUE Keyboard in System.\r
356 @retval FALSE Keyboard not in System.\r
357**/\r
358BOOLEAN\r
359EFIAPI\r
360CheckKeyboardConnect (\r
361 IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn\r
362 );\r
363\r
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
372VOID\r
373EFIAPI\r
374KeyboardWaitForKeyEx (\r
375 IN EFI_EVENT Event,\r
376 IN VOID *Context\r
377 ); \r
378\r
379//\r
380// Simple Text Input Ex protocol function prototypes\r
381//\r
382\r
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
394EFI_STATUS\r
395EFIAPI\r
396KeyboardEfiResetEx (\r
397 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,\r
398 IN BOOLEAN ExtendedVerification\r
399 );\r
400\r
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
404\r
405\r
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
409\r
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
415\r
416**/\r
417EFI_STATUS\r
418EFIAPI\r
419KeyboardReadKeyStrokeEx (\r
420 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,\r
421 OUT EFI_KEY_DATA *KeyData\r
422 );\r
423\r
424/**\r
425 Set certain state for the input device.\r
426\r
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
430\r
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
436\r
437**/\r
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
443 );\r
444\r
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
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
467 );\r
468\r
469/**\r
470 Remove a registered notification function from a particular keystroke.\r
471\r
472 @param This - Protocol instance pointer. \r
473 @param NotificationHandle - The handle of the notification function being unregistered.\r
474\r
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
479 \r
480**/ \r
481EFI_STATUS\r
482EFIAPI\r
483KeyboardUnregisterKeyNotify (\r
484 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,\r
485 IN EFI_HANDLE NotificationHandle\r
486 );\r
487\r
488#endif\r