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>
38 // Driver Private Data
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')
44 typedef struct _KEYBOARD_CONSOLE_IN_EX_NOTIFY
{
46 EFI_HANDLE NotifyHandle
;
48 EFI_KEY_NOTIFY_FUNCTION KeyNotificationFn
;
49 LIST_ENTRY NotifyEntry
;
50 } KEYBOARD_CONSOLE_IN_EX_NOTIFY
;
57 EFI_SIMPLE_TEXT_INPUT_PROTOCOL ConIn
;
58 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL ConInEx
;
59 EFI_ISA_IO_PROTOCOL
*IsaIo
;
63 UINT32 DataRegisterAddress
;
64 UINT32 StatusRegisterAddress
;
65 UINT32 CommandRegisterAddress
;
68 EFI_KEY_STATE KeyState
;
85 // Buffer storing key scancodes
87 UINT8 ScancodeBuf
[KEYBOARD_BUFFER_MAX_COUNT
];
88 UINT32 ScancodeBufStartPos
;
89 UINT32 ScancodeBufEndPos
;
90 UINT32 ScancodeBufCount
;
93 // Indicators of the key pressing state, used in detecting Alt+Ctrl+Del
103 EFI_UNICODE_STRING_TABLE
*ControllerNameTable
;
105 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
107 // Notification Function List
109 LIST_ENTRY NotifyList
;
110 } KEYBOARD_CONSOLE_IN_DEV
;
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) \
115 KEYBOARD_CONSOLE_IN_DEV, \
117 KEYBOARD_CONSOLE_IN_DEV_SIGNATURE \
120 #define TABLE_END 0x0
125 extern EFI_DRIVER_BINDING_PROTOCOL gKeyboardControllerDriver
;
126 extern EFI_COMPONENT_NAME_PROTOCOL gPs2KeyboardComponentName
;
127 extern EFI_COMPONENT_NAME2_PROTOCOL gPs2KeyboardComponentName2
;
129 extern EFI_GUID gSimpleTextInExNotifyGuid
;
132 // Driver entry point
136 InstallPs2KeyboardDriver (
137 IN EFI_HANDLE ImageHandle
,
138 IN EFI_SYSTEM_TABLE
*SystemTable
144 GC_TODO: Add function description
148 ImageHandle - GC_TODO: add argument description
149 SystemTable - GC_TODO: add argument description
153 GC_TODO: add return values
158 #define KEYBOARD_8042_DATA_REGISTER 0x60
159 #define KEYBOARD_8042_STATUS_REGISTER 0x64
160 #define KEYBOARD_8042_COMMAND_REGISTER 0x64
162 #define KEYBOARD_KBEN 0xF4
163 #define KEYBOARD_CMDECHO_ACK 0xFA
165 #define KEYBOARD_TIMEOUT 65536 // 0.07s
166 #define KEYBOARD_WAITFORVALUE_TIMEOUT 1000000 // 1s
167 #define KEYBOARD_BAT_TIMEOUT 4000000 // 4s
168 #define KEYBOARD_TIMER_INTERVAL 200000 // 0.02s
169 #define SCANCODE_EXTENDED 0xE0
170 #define SCANCODE_EXTENDED1 0xE1
171 #define SCANCODE_CTRL_MAKE 0x1D
172 #define SCANCODE_CTRL_BREAK 0x9D
173 #define SCANCODE_ALT_MAKE 0x38
174 #define SCANCODE_ALT_BREAK 0xB8
175 #define SCANCODE_LEFT_SHIFT_MAKE 0x2A
176 #define SCANCODE_LEFT_SHIFT_BREAK 0xAA
177 #define SCANCODE_RIGHT_SHIFT_MAKE 0x36
178 #define SCANCODE_RIGHT_SHIFT_BREAK 0xB6
179 #define SCANCODE_CAPS_LOCK_MAKE 0x3A
180 #define SCANCODE_NUM_LOCK_MAKE 0x45
181 #define SCANCODE_SCROLL_LOCK_MAKE 0x46
182 #define SCANCODE_LEFT_LOGO_MAKE 0x5B //GUI key defined in Keyboard scan code
183 #define SCANCODE_LEFT_LOGO_BREAK 0xDB
184 #define SCANCODE_RIGHT_LOGO_MAKE 0x5C
185 #define SCANCODE_RIGHT_LOGO_BREAK 0xDC
186 #define SCANCODE_MENU_MAKE 0x5D //APPS key defined in Keyboard scan code
187 #define SCANCODE_MENU_BREAK 0xDD
188 #define SCANCODE_SYS_REQ_MAKE 0x37
189 #define SCANCODE_MAX_MAKE 0x60
192 // Other functions that are used among .c files
197 IN KEYBOARD_CONSOLE_IN_DEV
*ConsoleIn
203 Show keyboard status light for ScrollLock, NumLock and CapsLock
204 according to indicators in ConsoleIn.
208 ConsoleIn - driver private structure
212 EFI_SUCCESS - Show the status light successfully.
213 EFI_TIMEOUT - Timeout when operating read/write on registers.
220 IN KEYBOARD_CONSOLE_IN_DEV
*ConsoleIn
,
227 GC_TODO: Add function description
231 ConsoleIn - GC_TODO: add argument description
232 Data - GC_TODO: add argument description
236 GC_TODO: add return values
243 IN OUT KEYBOARD_CONSOLE_IN_DEV
*ConsoleIn
249 GC_TODO: Add function description
253 ConsoleIn - GC_TODO: add argument description
257 GC_TODO: add return values
264 IN OUT KEYBOARD_CONSOLE_IN_DEV
*ConsoleIn
,
265 IN BOOLEAN ExtendedVerification
271 GC_TODO: Add function description
275 ConsoleIn - GC_TODO: add argument description
276 ExtendedVerification - GC_TODO: add argument description
280 GC_TODO: add return values
287 IN KEYBOARD_CONSOLE_IN_DEV
*ConsoleIn
293 GC_TODO: Add function description
297 ConsoleIn - GC_TODO: add argument description
301 GC_TODO: add return values
308 KeyboardTimerHandler (
316 GC_TODO: Add function description
320 Event - GC_TODO: add argument description
321 Context - GC_TODO: add argument description
325 GC_TODO: add return values
333 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
334 IN BOOLEAN ExtendedVerification
340 GC_TODO: Add function description
344 This - GC_TODO: add argument description
345 ExtendedVerification - GC_TODO: add argument description
349 GC_TODO: add return values
356 KeyboardReadKeyStroke (
357 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
358 OUT EFI_INPUT_KEY
*Key
364 GC_TODO: Add function description
368 This - GC_TODO: add argument description
369 Key - GC_TODO: add argument description
373 GC_TODO: add return values
388 GC_TODO: Add function description
392 Event - GC_TODO: add argument description
393 Context - GC_TODO: add argument description
397 GC_TODO: add return values
403 KeyReadStatusRegister (
404 IN KEYBOARD_CONSOLE_IN_DEV
*ConsoleIn
410 GC_TODO: Add function description
414 ConsoleIn - GC_TODO: add argument description
418 GC_TODO: add return values
424 Check whether there is Ps/2 Keyboard device in system by 0xF4 Keyboard Command
425 If Keyboard receives 0xF4, it will respond with 'ACK'. If it doesn't respond, the device
426 should not be in system.
428 @param[in] BiosKeyboardPrivate Keyboard Private Data Structure
430 @retval TRUE Keyboard in System.
431 @retval FALSE Keyboard not in System.
435 CheckKeyboardConnect (
436 IN KEYBOARD_CONSOLE_IN_DEV
*ConsoleIn
442 KeyboardWaitForKeyEx (
450 Event notification function for SIMPLE_TEXT_INPUT_EX_PROTOCOL.WaitForKeyEx event
451 Signal the event if there is key available
461 // Simple Text Input Ex protocol function prototypes
467 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
468 IN BOOLEAN ExtendedVerification
473 Reset the input device and optionaly run diagnostics
476 This - Protocol instance pointer.
477 ExtendedVerification - Driver may perform diagnostics on reset.
480 EFI_SUCCESS - The device was reset.
481 EFI_DEVICE_ERROR - The device is not functioning properly and could
489 KeyboardReadKeyStrokeEx (
490 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
491 OUT EFI_KEY_DATA
*KeyData
496 Reads the next keystroke from the input device. The WaitForKey Event can
497 be used to test for existance of a keystroke via WaitForEvent () call.
500 This - Protocol instance pointer.
501 KeyData - A pointer to a buffer that is filled in with the keystroke
502 state data for the key that was pressed.
505 EFI_SUCCESS - The keystroke information was returned.
506 EFI_NOT_READY - There was no keystroke data availiable.
507 EFI_DEVICE_ERROR - The keystroke information was not returned due to
509 EFI_INVALID_PARAMETER - KeyData is NULL.
517 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
518 IN EFI_KEY_TOGGLE_STATE
*KeyToggleState
523 Set certain state for the input device.
526 This - Protocol instance pointer.
527 KeyToggleState - A pointer to the EFI_KEY_TOGGLE_STATE to set the
528 state for the input device.
531 EFI_SUCCESS - The device state was set successfully.
532 EFI_DEVICE_ERROR - The device is not functioning correctly and could
533 not have the setting adjusted.
534 EFI_UNSUPPORTED - The device does not have the ability to set its state.
535 EFI_INVALID_PARAMETER - KeyToggleState is NULL.
542 KeyboardRegisterKeyNotify (
543 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
544 IN EFI_KEY_DATA
*KeyData
,
545 IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction
,
546 OUT EFI_HANDLE
*NotifyHandle
551 Register a notification function for a particular keystroke for the input device.
554 This - Protocol instance pointer.
555 KeyData - A pointer to a buffer that is filled in with the keystroke
556 information data for the key that was pressed.
557 KeyNotificationFunction - Points to the function to be called when the key
558 sequence is typed specified by KeyData.
559 NotifyHandle - Points to the unique handle assigned to the registered notification.
562 EFI_SUCCESS - The notification function was registered successfully.
563 EFI_OUT_OF_RESOURCES - Unable to allocate resources for necesssary data structures.
564 EFI_INVALID_PARAMETER - KeyData or NotifyHandle is NULL.
571 KeyboardUnregisterKeyNotify (
572 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
573 IN EFI_HANDLE NotificationHandle
578 Remove a registered notification function from a particular keystroke.
581 This - Protocol instance pointer.
582 NotificationHandle - The handle of the notification function being unregistered.
585 EFI_SUCCESS - The notification function was unregistered successfully.
586 EFI_INVALID_PARAMETER - The NotificationHandle is invalid.
587 EFI_NOT_FOUND - Can not find the matching entry in database.