]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Bus/Isa/Ps2KeyboardDxe/Ps2Keyboard.h
Coding style modification.
[mirror_edk2.git] / IntelFrameworkModulePkg / Bus / Isa / Ps2KeyboardDxe / Ps2Keyboard.h
1 /**@file
2 PS/2 keyboard driver header file
3
4 Copyright (c) 2006 - 2007, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #ifndef _PS2KEYBOARD_H
16 #define _PS2KEYBOARD_H
17
18 #include <PiDxe.h>
19 #include <Framework/StatusCode.h>
20
21 #include <Protocol/SimpleTextIn.h>
22 #include <Protocol/SimpleTextInEx.h>
23 #include <Protocol/IsaIo.h>
24 #include <Protocol/DevicePath.h>
25 #include <Protocol/Ps2Policy.h>
26
27 #include <Library/UefiDriverEntryPoint.h>
28 #include <Library/UefiLib.h>
29 #include <Library/UefiBootServicesTableLib.h>
30 #include <Library/ReportStatusCodeLib.h>
31 #include <Library/DebugLib.h>
32 #include <Library/UefiRuntimeServicesTableLib.h>
33 #include <Library/MemoryAllocationLib.h>
34 #include <Library/BaseLib.h>
35 #include <Library/BaseMemoryLib.h>
36
37 //
38 // Driver Private Data
39 //
40 #define KEYBOARD_BUFFER_MAX_COUNT 32
41 #define KEYBOARD_CONSOLE_IN_DEV_SIGNATURE EFI_SIGNATURE_32 ('k', 'k', 'e', 'y')
42 #define KEYBOARD_CONSOLE_IN_EX_NOTIFY_SIGNATURE EFI_SIGNATURE_32 ('k', 'c', 'e', 'n')
43
44 typedef struct _KEYBOARD_CONSOLE_IN_EX_NOTIFY {
45 UINTN Signature;
46 EFI_HANDLE NotifyHandle;
47 EFI_KEY_DATA KeyData;
48 EFI_KEY_NOTIFY_FUNCTION KeyNotificationFn;
49 LIST_ENTRY NotifyEntry;
50 } KEYBOARD_CONSOLE_IN_EX_NOTIFY;
51
52
53 typedef struct {
54 UINTN Signature;
55
56 EFI_HANDLE Handle;
57 EFI_SIMPLE_TEXT_INPUT_PROTOCOL ConIn;
58 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL ConInEx;
59 EFI_ISA_IO_PROTOCOL *IsaIo;
60
61 EFI_EVENT TimerEvent;
62
63 UINT32 DataRegisterAddress;
64 UINT32 StatusRegisterAddress;
65 UINT32 CommandRegisterAddress;
66
67 EFI_INPUT_KEY Key;
68 EFI_KEY_STATE KeyState;
69
70 BOOLEAN LeftShift;
71 BOOLEAN RightShift;
72 BOOLEAN LeftLogo;
73 BOOLEAN RightLogo;
74 BOOLEAN Menu;
75 BOOLEAN SysReq;
76
77 BOOLEAN Ctrl;
78 BOOLEAN Alt;
79 BOOLEAN Shift;
80 BOOLEAN CapsLock;
81 BOOLEAN NumLock;
82 BOOLEAN ScrollLock;
83
84 //
85 // Buffer storing key scancodes
86 //
87 UINT8 ScancodeBuf[KEYBOARD_BUFFER_MAX_COUNT];
88 UINT32 ScancodeBufStartPos;
89 UINT32 ScancodeBufEndPos;
90 UINT32 ScancodeBufCount;
91
92 //
93 // Indicators of the key pressing state, used in detecting Alt+Ctrl+Del
94 //
95 BOOLEAN Ctrled;
96 BOOLEAN Alted;
97
98 //
99 // Error state
100 //
101 BOOLEAN KeyboardErr;
102
103 EFI_UNICODE_STRING_TABLE *ControllerNameTable;
104
105 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
106 //
107 // Notification Function List
108 //
109 LIST_ENTRY NotifyList;
110 } KEYBOARD_CONSOLE_IN_DEV;
111
112 #define KEYBOARD_CONSOLE_IN_DEV_FROM_THIS(a) CR (a, KEYBOARD_CONSOLE_IN_DEV, ConIn, KEYBOARD_CONSOLE_IN_DEV_SIGNATURE)
113 #define TEXT_INPUT_EX_KEYBOARD_CONSOLE_IN_DEV_FROM_THIS(a) \
114 CR (a, \
115 KEYBOARD_CONSOLE_IN_DEV, \
116 ConInEx, \
117 KEYBOARD_CONSOLE_IN_DEV_SIGNATURE \
118 )
119
120 #define TABLE_END 0x0
121
122 //
123 // Global Variables
124 //
125 extern EFI_DRIVER_BINDING_PROTOCOL gKeyboardControllerDriver;
126 extern EFI_COMPONENT_NAME_PROTOCOL gPs2KeyboardComponentName;
127 extern EFI_COMPONENT_NAME2_PROTOCOL gPs2KeyboardComponentName2;
128
129 extern EFI_GUID gSimpleTextInExNotifyGuid;
130
131 //
132 // Driver entry point
133 //
134 /**
135 The user Entry Point for module Ps2Keyboard. The user code starts with this function.
136
137 @param[in] ImageHandle The firmware allocated handle for the EFI image.
138 @param[in] SystemTable A pointer to the EFI System Table.
139
140 @retval EFI_SUCCESS The entry point is executed successfully.
141 @retval other Some error occurs when executing this entry point.
142
143 **/
144 EFI_STATUS
145 EFIAPI
146 InstallPs2KeyboardDriver (
147 IN EFI_HANDLE ImageHandle,
148 IN EFI_SYSTEM_TABLE *SystemTable
149 )
150 ;
151
152 #define KEYBOARD_8042_DATA_REGISTER 0x60
153 #define KEYBOARD_8042_STATUS_REGISTER 0x64
154 #define KEYBOARD_8042_COMMAND_REGISTER 0x64
155
156 #define KEYBOARD_KBEN 0xF4
157 #define KEYBOARD_CMDECHO_ACK 0xFA
158
159 #define KEYBOARD_TIMEOUT 65536 // 0.07s
160 #define KEYBOARD_WAITFORVALUE_TIMEOUT 1000000 // 1s
161 #define KEYBOARD_BAT_TIMEOUT 4000000 // 4s
162 #define KEYBOARD_TIMER_INTERVAL 200000 // 0.02s
163 #define SCANCODE_EXTENDED 0xE0
164 #define SCANCODE_EXTENDED1 0xE1
165 #define SCANCODE_CTRL_MAKE 0x1D
166 #define SCANCODE_CTRL_BREAK 0x9D
167 #define SCANCODE_ALT_MAKE 0x38
168 #define SCANCODE_ALT_BREAK 0xB8
169 #define SCANCODE_LEFT_SHIFT_MAKE 0x2A
170 #define SCANCODE_LEFT_SHIFT_BREAK 0xAA
171 #define SCANCODE_RIGHT_SHIFT_MAKE 0x36
172 #define SCANCODE_RIGHT_SHIFT_BREAK 0xB6
173 #define SCANCODE_CAPS_LOCK_MAKE 0x3A
174 #define SCANCODE_NUM_LOCK_MAKE 0x45
175 #define SCANCODE_SCROLL_LOCK_MAKE 0x46
176 #define SCANCODE_LEFT_LOGO_MAKE 0x5B //GUI key defined in Keyboard scan code
177 #define SCANCODE_LEFT_LOGO_BREAK 0xDB
178 #define SCANCODE_RIGHT_LOGO_MAKE 0x5C
179 #define SCANCODE_RIGHT_LOGO_BREAK 0xDC
180 #define SCANCODE_MENU_MAKE 0x5D //APPS key defined in Keyboard scan code
181 #define SCANCODE_MENU_BREAK 0xDD
182 #define SCANCODE_SYS_REQ_MAKE 0x37
183 #define SCANCODE_MAX_MAKE 0x60
184
185 //
186 // Other functions that are used among .c files
187 //
188 /**
189 Show keyboard status lights according to
190 indicators in ConsoleIn.
191
192 @param ConsoleIn Pointer to instance of KEYBOARD_CONSOLE_IN_DEV
193
194 @return status
195
196 **/
197 EFI_STATUS
198 UpdateStatusLights (
199 IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn
200 )
201 ;
202
203 /**
204 write key to keyboard
205
206 @param ConsoleIn Pointer to instance of KEYBOARD_CONSOLE_IN_DEV
207 @param Data value wanted to be written
208
209 @retval EFI_TIMEOUT - GC_TODO: Add description for return value
210 @retval EFI_SUCCESS - GC_TODO: Add description for return value
211
212 **/
213 EFI_STATUS
214 KeyboardRead (
215 IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn,
216 OUT UINT8 *Data
217 )
218 ;
219
220 /**
221 Get scancode from scancode buffer
222 and translate into EFI-scancode and unicode defined by EFI spec
223 The function is always called in TPL_NOTIFY
224
225 @param ConsoleIn KEYBOARD_CONSOLE_IN_DEV instance pointer
226
227 @retval EFI_NOT_READY - Input from console not ready yet.
228 @retval EFI_SUCCESS - Function executed successfully.
229
230 **/
231 EFI_STATUS
232 KeyGetchar (
233 IN OUT KEYBOARD_CONSOLE_IN_DEV *ConsoleIn
234 )
235 ;
236
237 /**
238 Perform 8042 controller and keyboard Initialization
239 If ExtendedVerification is TRUE, do additional test for
240 the keyboard interface
241
242 @param ConsoleIn - KEYBOARD_CONSOLE_IN_DEV instance pointer
243 @param ExtendedVerification - indicates a thorough initialization
244
245 @retval EFI_DEVICE_ERROR Fail to init keyboard
246 @retval EFI_SUCCESS Success to init keyboard
247 **/
248 EFI_STATUS
249 InitKeyboard (
250 IN OUT KEYBOARD_CONSOLE_IN_DEV *ConsoleIn,
251 IN BOOLEAN ExtendedVerification
252 )
253 ;
254
255 /**
256 Disable the keyboard interface of the 8042 controller
257
258 @param ConsoleIn - the device instance
259
260 @return status of issuing disable command
261
262 **/
263 EFI_STATUS
264 DisableKeyboard (
265 IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn
266 )
267 ;
268
269 /**
270 Timer event handler: read a series of scancodes from 8042
271 and put them into memory scancode buffer.
272 it read as much scancodes to either fill
273 the memory buffer or empty the keyboard buffer.
274 It is registered as running under TPL_NOTIFY
275
276 @param Event - The timer event
277 @param Context - A KEYBOARD_CONSOLE_IN_DEV pointer
278
279 **/
280 VOID
281 EFIAPI
282 KeyboardTimerHandler (
283 IN EFI_EVENT Event,
284 IN VOID *Context
285 )
286 ;
287
288 /**
289 logic reset keyboard
290 Implement SIMPLE_TEXT_IN.Reset()
291 Perform 8042 controller and keyboard initialization
292
293 @param This Pointer to instance of EFI_SIMPLE_TEXT_INPUT_PROTOCOL
294 @param ExtendedVerification Indicate that the driver may perform a more
295 exhaustive verification operation of the device during
296 reset, now this par is ignored in this driver
297
298 **/
299 EFI_STATUS
300 EFIAPI
301 KeyboardEfiReset (
302 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,
303 IN BOOLEAN ExtendedVerification
304 )
305 ;
306
307 /**
308 Implement SIMPLE_TEXT_IN.ReadKeyStroke().
309 Retrieve key values for driver user.
310
311 @param This Pointer to instance of EFI_SIMPLE_TEXT_INPUT_PROTOCOL
312 @param Key The output buffer for key value
313
314 @retval EFI_SUCCESS success to read key stroke
315 **/
316 EFI_STATUS
317 EFIAPI
318 KeyboardReadKeyStroke (
319 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,
320 OUT EFI_INPUT_KEY *Key
321 )
322 ;
323
324 /**
325 Event notification function for SIMPLE_TEXT_IN.WaitForKey event
326 Signal the event if there is key available
327
328 @param Event the event object
329 @param Context waitting context
330
331 **/
332 VOID
333 EFIAPI
334 KeyboardWaitForKey (
335 IN EFI_EVENT Event,
336 IN VOID *Context
337 )
338 ;
339
340 /**
341 Read status register
342
343 @param ConsoleIn Pointer to instance of KEYBOARD_CONSOLE_IN_DEV
344
345 @return value in status register
346
347 **/
348 UINT8
349 KeyReadStatusRegister (
350 IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn
351 )
352 ;
353
354 /**
355 Check whether there is Ps/2 Keyboard device in system by 0xF4 Keyboard Command
356 If Keyboard receives 0xF4, it will respond with 'ACK'. If it doesn't respond, the device
357 should not be in system.
358
359 @param[in] BiosKeyboardPrivate Keyboard Private Data Structure
360
361 @retval TRUE Keyboard in System.
362 @retval FALSE Keyboard not in System.
363 **/
364 BOOLEAN
365 EFIAPI
366 CheckKeyboardConnect (
367 IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn
368 )
369 ;
370
371 /**
372 Event notification function for SIMPLE_TEXT_INPUT_EX_PROTOCOL.WaitForKeyEx event
373 Signal the event if there is key available
374
375 @param Event event object
376 @param Context waiting context
377
378 **/
379 VOID
380 EFIAPI
381 KeyboardWaitForKeyEx (
382 IN EFI_EVENT Event,
383 IN VOID *Context
384 )
385 ;
386
387 //
388 // Simple Text Input Ex protocol function prototypes
389 //
390
391 /**
392 Reset the input device and optionaly run diagnostics
393
394 @param This - Protocol instance pointer.
395 @param ExtendedVerification - Driver may perform diagnostics on reset.
396
397 @retval EFI_SUCCESS - The device was reset.
398 @retval EFI_DEVICE_ERROR - The device is not functioning properly and could
399 not be reset.
400
401 **/
402 EFI_STATUS
403 EFIAPI
404 KeyboardEfiResetEx (
405 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
406 IN BOOLEAN ExtendedVerification
407 )
408 ;
409
410 /**
411 Reads the next keystroke from the input device. The WaitForKey Event can
412 be used to test for existance of a keystroke via WaitForEvent () call.
413
414
415 @param This - Protocol instance pointer.
416 @param KeyData - A pointer to a buffer that is filled in with the keystroke
417 state data for the key that was pressed.
418
419 @retval EFI_SUCCESS - The keystroke information was returned.
420 @retval EFI_NOT_READY - There was no keystroke data availiable.
421 @retval EFI_DEVICE_ERROR - The keystroke information was not returned due to
422 hardware errors.
423 @retval EFI_INVALID_PARAMETER - KeyData is NULL.
424
425 **/
426 EFI_STATUS
427 EFIAPI
428 KeyboardReadKeyStrokeEx (
429 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
430 OUT EFI_KEY_DATA *KeyData
431 )
432 ;
433
434 /**
435 Set certain state for the input device.
436
437 @param This - Protocol instance pointer.
438 @param KeyToggleState - A pointer to the EFI_KEY_TOGGLE_STATE to set the
439 state for the input device.
440
441 @retval EFI_SUCCESS - The device state was set successfully.
442 @retval EFI_DEVICE_ERROR - The device is not functioning correctly and could
443 not have the setting adjusted.
444 @retval EFI_UNSUPPORTED - The device does not have the ability to set its state.
445 @retval EFI_INVALID_PARAMETER - KeyToggleState is NULL.
446
447 **/
448 EFI_STATUS
449 EFIAPI
450 KeyboardSetState (
451 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
452 IN EFI_KEY_TOGGLE_STATE *KeyToggleState
453 )
454 ;
455
456 /**
457 Register a notification function for a particular keystroke for the input device.
458
459 @param This - Protocol instance pointer.
460 @param KeyData - A pointer to a buffer that is filled in with the keystroke
461 information data for the key that was pressed.
462 @param KeyNotificationFunction - Points to the function to be called when the key
463 sequence is typed specified by KeyData.
464 @param NotifyHandle - Points to the unique handle assigned to the registered notification.
465
466 @retval EFI_SUCCESS - The notification function was registered successfully.
467 @retval EFI_OUT_OF_RESOURCES - Unable to allocate resources for necesssary data structures.
468 @retval EFI_INVALID_PARAMETER - KeyData or NotifyHandle is NULL.
469
470 **/
471 EFI_STATUS
472 EFIAPI
473 KeyboardRegisterKeyNotify (
474 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
475 IN EFI_KEY_DATA *KeyData,
476 IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction,
477 OUT EFI_HANDLE *NotifyHandle
478 )
479 ;
480
481 /**
482 Remove a registered notification function from a particular keystroke.
483
484 @param This - Protocol instance pointer.
485 @param NotificationHandle - The handle of the notification function being unregistered.
486
487
488 @retval EFI_SUCCESS - The notification function was unregistered successfully.
489 @retval EFI_INVALID_PARAMETER - The NotificationHandle is invalid.
490 @retval EFI_NOT_FOUND - Can not find the matching entry in database.
491
492 **/
493 EFI_STATUS
494 EFIAPI
495 KeyboardUnregisterKeyNotify (
496 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
497 IN EFI_HANDLE NotificationHandle
498 )
499 ;
500
501 #endif