3 Copyright (c) 2006 - 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 Routines that support SIMPLE_TEXT_IN protocol
26 // Include common header file for this module.
28 #include "CommonHeader.h"
30 #include "Ps2Keyboard.h"
33 // function declarations
38 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
39 IN BOOLEAN ExtendedVerification
44 KeyboardReadKeyStroke (
45 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
46 OUT EFI_INPUT_KEY
*Key
58 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
64 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
65 IN BOOLEAN ExtendedVerification
71 Implement SIMPLE_TEXT_IN.Reset()
72 Perform 8042 controller and keyboard initialization
79 // GC_TODO: This - add argument and description to function comment
80 // GC_TODO: ExtendedVerification - add argument and description to function comment
81 // GC_TODO: EFI_DEVICE_ERROR - add return value to function comment
82 // GC_TODO: EFI_DEVICE_ERROR - add return value to function comment
83 // GC_TODO: EFI_SUCCESS - add return value to function comment
86 KEYBOARD_CONSOLE_IN_DEV
*ConsoleIn
;
89 ConsoleIn
= KEYBOARD_CONSOLE_IN_DEV_FROM_THIS (This
);
90 if (ConsoleIn
->KeyboardErr
) {
91 return EFI_DEVICE_ERROR
;
94 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
96 EFI_PERIPHERAL_KEYBOARD
| EFI_P_PC_RESET
,
101 // Enter critical section
103 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
106 // Call InitKeyboard to initialize the keyboard
108 Status
= InitKeyboard (ConsoleIn
, ExtendedVerification
);
109 if (EFI_ERROR (Status
)) {
111 // Leave critical section and return
113 gBS
->RestoreTPL (OldTpl
);
114 return EFI_DEVICE_ERROR
;
117 // Clear the status of ConsoleIn.Key
119 ConsoleIn
->Key
.ScanCode
= SCAN_NULL
;
120 ConsoleIn
->Key
.UnicodeChar
= 0x0000;
123 // Leave critical section and return
125 gBS
->RestoreTPL (OldTpl
);
128 // Report the status If a stuck key was detected
130 if (KeyReadStatusRegister (ConsoleIn
) & 0x01) {
131 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
132 EFI_ERROR_CODE
| EFI_ERROR_MINOR
,
133 EFI_PERIPHERAL_KEYBOARD
| EFI_P_KEYBOARD_EC_STUCK_KEY
,
134 ConsoleIn
->DevicePath
138 // Report the status If keyboard is locked
140 if (!(KeyReadStatusRegister (ConsoleIn
) & 0x10)) {
141 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
142 EFI_ERROR_CODE
| EFI_ERROR_MINOR
,
143 EFI_PERIPHERAL_KEYBOARD
| EFI_P_KEYBOARD_EC_LOCKED
,
144 ConsoleIn
->DevicePath
153 KeyboardReadKeyStroke (
154 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
155 OUT EFI_INPUT_KEY
*Key
161 Implement SIMPLE_TEXT_IN.ReadKeyStroke().
162 Retrieve key values for driver user.
169 // GC_TODO: This - add argument and description to function comment
170 // GC_TODO: Key - add argument and description to function comment
171 // GC_TODO: EFI_DEVICE_ERROR - add return value to function comment
172 // GC_TODO: EFI_NOT_READY - add return value to function comment
173 // GC_TODO: EFI_SUCCESS - add return value to function comment
176 KEYBOARD_CONSOLE_IN_DEV
*ConsoleIn
;
179 ConsoleIn
= KEYBOARD_CONSOLE_IN_DEV_FROM_THIS (This
);
182 // Enter critical section
184 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
186 if (ConsoleIn
->KeyboardErr
) {
188 // Leave critical section and return
190 gBS
->RestoreTPL (OldTpl
);
192 return EFI_DEVICE_ERROR
;
195 // If there's no key, just return
197 Status
= KeyboardCheckForKey (This
);
198 if (EFI_ERROR (Status
)) {
200 // Leave critical section and return
202 gBS
->RestoreTPL (OldTpl
);
203 return EFI_NOT_READY
;
206 Key
->ScanCode
= ConsoleIn
->Key
.ScanCode
;
207 Key
->UnicodeChar
= ConsoleIn
->Key
.UnicodeChar
;
209 ConsoleIn
->Key
.ScanCode
= SCAN_NULL
;
210 ConsoleIn
->Key
.UnicodeChar
= 0x0000;
213 // Leave critical section and return
215 gBS
->RestoreTPL (OldTpl
);
230 Event notification function for SIMPLE_TEXT_IN.WaitForKey event
231 Signal the event if there is key available
238 // GC_TODO: Event - add argument and description to function comment
239 // GC_TODO: Context - add argument and description to function comment
242 KEYBOARD_CONSOLE_IN_DEV
*ConsoleIn
;
244 ConsoleIn
= KEYBOARD_CONSOLE_IN_DEV_FROM_THIS (Context
);
247 // Enter critical section
249 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
251 if (ConsoleIn
->KeyboardErr
) {
253 // Leave critical section and return
255 gBS
->RestoreTPL (OldTpl
);
259 // Someone is waiting on the keyboard event, if there's
260 // a key pending, signal the event
262 if (!EFI_ERROR (KeyboardCheckForKey (Context
))) {
263 gBS
->SignalEvent (Event
);
266 // Leave critical section and return
268 gBS
->RestoreTPL (OldTpl
);
274 KeyboardCheckForKey (
275 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
281 GC_TODO: Add function description
285 This - GC_TODO: add argument description
289 EFI_SUCCESS - GC_TODO: Add description for return value
293 KEYBOARD_CONSOLE_IN_DEV
*ConsoleIn
;
295 ConsoleIn
= KEYBOARD_CONSOLE_IN_DEV_FROM_THIS (This
);
298 // If ready to read next key, check it
300 if (ConsoleIn
->Key
.ScanCode
== SCAN_NULL
&& ConsoleIn
->Key
.UnicodeChar
== 0x00) {
301 return KeyGetchar (ConsoleIn
);