2 PS/2 keyboard driver header file
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
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.
15 #ifndef _PS2KEYBOARD_H
16 #define _PS2KEYBOARD_H
19 #include <Framework/StatusCode.h>
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>
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>
40 extern EFI_DRIVER_BINDING_PROTOCOL gKeyboardControllerDriver
;
41 extern EFI_COMPONENT_NAME_PROTOCOL gPs2KeyboardComponentName
;
42 extern EFI_COMPONENT_NAME2_PROTOCOL gPs2KeyboardComponentName2
;
45 // Driver Private Data
47 #define KEYBOARD_BUFFER_MAX_COUNT 32
48 #define KEYBOARD_CONSOLE_IN_DEV_SIGNATURE SIGNATURE_32 ('k', 'k', 'e', 'y')
49 #define KEYBOARD_CONSOLE_IN_EX_NOTIFY_SIGNATURE SIGNATURE_32 ('k', 'c', 'e', 'n')
51 typedef struct _KEYBOARD_CONSOLE_IN_EX_NOTIFY
{
53 EFI_HANDLE NotifyHandle
;
55 EFI_KEY_NOTIFY_FUNCTION KeyNotificationFn
;
56 LIST_ENTRY NotifyEntry
;
57 } KEYBOARD_CONSOLE_IN_EX_NOTIFY
;
64 EFI_SIMPLE_TEXT_INPUT_PROTOCOL ConIn
;
65 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL ConInEx
;
66 EFI_ISA_IO_PROTOCOL
*IsaIo
;
70 UINT32 DataRegisterAddress
;
71 UINT32 StatusRegisterAddress
;
72 UINT32 CommandRegisterAddress
;
75 EFI_KEY_STATE KeyState
;
92 // Buffer storing key scancodes
94 UINT8 ScancodeBuf
[KEYBOARD_BUFFER_MAX_COUNT
];
95 UINT32 ScancodeBufStartPos
;
96 UINT32 ScancodeBufEndPos
;
97 UINT32 ScancodeBufCount
;
100 // Indicators of the key pressing state, used in detecting Alt+Ctrl+Del
110 EFI_UNICODE_STRING_TABLE
*ControllerNameTable
;
112 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
114 // Notification Function List
116 LIST_ENTRY NotifyList
;
117 } KEYBOARD_CONSOLE_IN_DEV
;
119 #define KEYBOARD_CONSOLE_IN_DEV_FROM_THIS(a) CR (a, KEYBOARD_CONSOLE_IN_DEV, ConIn, KEYBOARD_CONSOLE_IN_DEV_SIGNATURE)
120 #define TEXT_INPUT_EX_KEYBOARD_CONSOLE_IN_DEV_FROM_THIS(a) \
122 KEYBOARD_CONSOLE_IN_DEV, \
124 KEYBOARD_CONSOLE_IN_DEV_SIGNATURE \
127 #define TABLE_END 0x0
130 // Driver entry point
133 The user Entry Point for module Ps2Keyboard. The user code starts with this function.
135 @param[in] ImageHandle The firmware allocated handle for the EFI image.
136 @param[in] SystemTable A pointer to the EFI System Table.
138 @retval EFI_SUCCESS The entry point is executed successfully.
139 @retval other Some error occurs when executing this entry point.
144 InstallPs2KeyboardDriver (
145 IN EFI_HANDLE ImageHandle
,
146 IN EFI_SYSTEM_TABLE
*SystemTable
149 #define KEYBOARD_8042_DATA_REGISTER 0x60
150 #define KEYBOARD_8042_STATUS_REGISTER 0x64
151 #define KEYBOARD_8042_COMMAND_REGISTER 0x64
153 #define KEYBOARD_KBEN 0xF4
154 #define KEYBOARD_CMDECHO_ACK 0xFA
156 #define KEYBOARD_MAX_TRY 256 // 256
157 #define KEYBOARD_TIMEOUT 65536 // 0.07s
158 #define KEYBOARD_WAITFORVALUE_TIMEOUT 1000000 // 1s
159 #define KEYBOARD_BAT_TIMEOUT 4000000 // 4s
160 #define KEYBOARD_TIMER_INTERVAL 200000 // 0.02s
161 #define SCANCODE_EXTENDED 0xE0
162 #define SCANCODE_EXTENDED1 0xE1
163 #define SCANCODE_CTRL_MAKE 0x1D
164 #define SCANCODE_CTRL_BREAK 0x9D
165 #define SCANCODE_ALT_MAKE 0x38
166 #define SCANCODE_ALT_BREAK 0xB8
167 #define SCANCODE_LEFT_SHIFT_MAKE 0x2A
168 #define SCANCODE_LEFT_SHIFT_BREAK 0xAA
169 #define SCANCODE_RIGHT_SHIFT_MAKE 0x36
170 #define SCANCODE_RIGHT_SHIFT_BREAK 0xB6
171 #define SCANCODE_CAPS_LOCK_MAKE 0x3A
172 #define SCANCODE_NUM_LOCK_MAKE 0x45
173 #define SCANCODE_SCROLL_LOCK_MAKE 0x46
174 #define SCANCODE_LEFT_LOGO_MAKE 0x5B //GUI key defined in Keyboard scan code
175 #define SCANCODE_LEFT_LOGO_BREAK 0xDB
176 #define SCANCODE_RIGHT_LOGO_MAKE 0x5C
177 #define SCANCODE_RIGHT_LOGO_BREAK 0xDC
178 #define SCANCODE_MENU_MAKE 0x5D //APPS key defined in Keyboard scan code
179 #define SCANCODE_MENU_BREAK 0xDD
180 #define SCANCODE_SYS_REQ_MAKE 0x37
181 #define SCANCODE_MAX_MAKE 0x60
184 // Keyboard Controller Status
186 #define KBC_PARE 0x80 // Parity Error
187 #define KBC_TIM 0x40 // General Time Out
190 // Other functions that are used among .c files
193 Show keyboard status lights according to
194 indicators in ConsoleIn.
196 @param ConsoleIn Pointer to instance of KEYBOARD_CONSOLE_IN_DEV
203 IN KEYBOARD_CONSOLE_IN_DEV
*ConsoleIn
207 write key to keyboard
209 @param ConsoleIn Pointer to instance of KEYBOARD_CONSOLE_IN_DEV
210 @param Data value wanted to be written
212 @retval EFI_TIMEOUT - GC_TODO: Add description for return value
213 @retval EFI_SUCCESS - GC_TODO: Add description for return value
218 IN KEYBOARD_CONSOLE_IN_DEV
*ConsoleIn
,
223 Get scancode from scancode buffer
224 and translate into EFI-scancode and unicode defined by EFI spec
225 The function is always called in TPL_NOTIFY
227 @param ConsoleIn KEYBOARD_CONSOLE_IN_DEV instance pointer
229 @retval EFI_NOT_READY - Input from console not ready yet.
230 @retval EFI_SUCCESS - Function executed successfully.
235 IN OUT KEYBOARD_CONSOLE_IN_DEV
*ConsoleIn
239 Perform 8042 controller and keyboard Initialization
240 If ExtendedVerification is TRUE, do additional test for
241 the keyboard interface
243 @param ConsoleIn - KEYBOARD_CONSOLE_IN_DEV instance pointer
244 @param ExtendedVerification - indicates a thorough initialization
246 @retval EFI_DEVICE_ERROR Fail to init keyboard
247 @retval EFI_SUCCESS Success to init keyboard
251 IN OUT KEYBOARD_CONSOLE_IN_DEV
*ConsoleIn
,
252 IN BOOLEAN ExtendedVerification
256 Disable the keyboard interface of the 8042 controller
258 @param ConsoleIn - the device instance
260 @return status of issuing disable command
265 IN KEYBOARD_CONSOLE_IN_DEV
*ConsoleIn
269 Timer event handler: read a series of scancodes from 8042
270 and put them into memory scancode buffer.
271 it read as much scancodes to either fill
272 the memory buffer or empty the keyboard buffer.
273 It is registered as running under TPL_NOTIFY
275 @param Event - The timer event
276 @param Context - A KEYBOARD_CONSOLE_IN_DEV pointer
281 KeyboardTimerHandler (
288 Implement SIMPLE_TEXT_IN.Reset()
289 Perform 8042 controller and keyboard initialization
291 @param This Pointer to instance of EFI_SIMPLE_TEXT_INPUT_PROTOCOL
292 @param ExtendedVerification Indicate that the driver may perform a more
293 exhaustive verification operation of the device during
294 reset, now this par is ignored in this driver
300 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
301 IN BOOLEAN ExtendedVerification
305 Implement SIMPLE_TEXT_IN.ReadKeyStroke().
306 Retrieve key values for driver user.
308 @param This Pointer to instance of EFI_SIMPLE_TEXT_INPUT_PROTOCOL
309 @param Key The output buffer for key value
311 @retval EFI_SUCCESS success to read key stroke
315 KeyboardReadKeyStroke (
316 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
317 OUT EFI_INPUT_KEY
*Key
321 Event notification function for SIMPLE_TEXT_IN.WaitForKey event
322 Signal the event if there is key available
324 @param Event the event object
325 @param Context waitting context
338 @param ConsoleIn Pointer to instance of KEYBOARD_CONSOLE_IN_DEV
340 @return value in status register
344 KeyReadStatusRegister (
345 IN KEYBOARD_CONSOLE_IN_DEV
*ConsoleIn
349 Check whether there is Ps/2 Keyboard device in system by 0xF4 Keyboard Command
350 If Keyboard receives 0xF4, it will respond with 'ACK'. If it doesn't respond, the device
351 should not be in system.
353 @param[in] BiosKeyboardPrivate Keyboard Private Data Structure
355 @retval TRUE Keyboard in System.
356 @retval FALSE Keyboard not in System.
360 CheckKeyboardConnect (
361 IN KEYBOARD_CONSOLE_IN_DEV
*ConsoleIn
365 Event notification function for SIMPLE_TEXT_INPUT_EX_PROTOCOL.WaitForKeyEx event
366 Signal the event if there is key available
368 @param Event event object
369 @param Context waiting context
374 KeyboardWaitForKeyEx (
380 // Simple Text Input Ex protocol function prototypes
384 Reset the input device and optionaly run diagnostics
386 @param This - Protocol instance pointer.
387 @param ExtendedVerification - Driver may perform diagnostics on reset.
389 @retval EFI_SUCCESS - The device was reset.
390 @retval EFI_DEVICE_ERROR - The device is not functioning properly and could
397 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
398 IN BOOLEAN ExtendedVerification
402 Reads the next keystroke from the input device. The WaitForKey Event can
403 be used to test for existance of a keystroke via WaitForEvent () call.
406 @param This - Protocol instance pointer.
407 @param KeyData - A pointer to a buffer that is filled in with the keystroke
408 state data for the key that was pressed.
410 @retval EFI_SUCCESS - The keystroke information was returned.
411 @retval EFI_NOT_READY - There was no keystroke data availiable.
412 @retval EFI_DEVICE_ERROR - The keystroke information was not returned due to
414 @retval EFI_INVALID_PARAMETER - KeyData is NULL.
419 KeyboardReadKeyStrokeEx (
420 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
421 OUT EFI_KEY_DATA
*KeyData
425 Set certain state for the input device.
427 @param This - Protocol instance pointer.
428 @param KeyToggleState - A pointer to the EFI_KEY_TOGGLE_STATE to set the
429 state for the input device.
431 @retval EFI_SUCCESS - The device state was set successfully.
432 @retval EFI_DEVICE_ERROR - The device is not functioning correctly and could
433 not have the setting adjusted.
434 @retval EFI_UNSUPPORTED - The device does not have the ability to set its state.
435 @retval EFI_INVALID_PARAMETER - KeyToggleState is NULL.
441 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
442 IN EFI_KEY_TOGGLE_STATE
*KeyToggleState
446 Register a notification function for a particular keystroke for the input device.
448 @param This - Protocol instance pointer.
449 @param KeyData - A pointer to a buffer that is filled in with the keystroke
450 information data for the key that was pressed.
451 @param KeyNotificationFunction - Points to the function to be called when the key
452 sequence is typed specified by KeyData.
453 @param NotifyHandle - Points to the unique handle assigned to the registered notification.
455 @retval EFI_SUCCESS - The notification function was registered successfully.
456 @retval EFI_OUT_OF_RESOURCES - Unable to allocate resources for necesssary data structures.
457 @retval EFI_INVALID_PARAMETER - KeyData or NotifyHandle is NULL.
462 KeyboardRegisterKeyNotify (
463 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
464 IN EFI_KEY_DATA
*KeyData
,
465 IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction
,
466 OUT EFI_HANDLE
*NotifyHandle
470 Remove a registered notification function from a particular keystroke.
472 @param This - Protocol instance pointer.
473 @param NotificationHandle - The handle of the notification function being unregistered.
476 @retval EFI_SUCCESS - The notification function was unregistered successfully.
477 @retval EFI_INVALID_PARAMETER - The NotificationHandle is invalid.
478 @retval EFI_NOT_FOUND - Can not find the matching entry in database.
483 KeyboardUnregisterKeyNotify (
484 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
485 IN EFI_HANDLE NotificationHandle