18ac83fb43f01e26cb59b311a486118cac4d4a2e
[mirror_edk2.git] / IntelFrameworkModulePkg / Bus / Isa / Ps2KeyboardDxe / Ps2KbdTextIn.c
1 /*++
2
3 Copyright (c) 2006, Intel Corporation. All rights reserved. <BR>
4 This software and associated documentation (if any) is furnished
5 under a license and may only be used or copied in accordance
6 with the terms of the license. Except as permitted by such
7 license, no part of this software or documentation may be
8 reproduced, stored in a retrieval system, or transmitted in any
9 form or by any means without the express written consent of
10 Intel Corporation.
11
12
13 Module Name:
14
15 Ps2KbdTextIn.c
16
17 Abstract:
18
19 PS/2 Keyboard driver
20 Routines that support SIMPLE_TEXT_IN protocol
21
22 Revision History
23
24 --*/
25
26 //
27 // Include common header file for this module.
28 //
29 #include "CommonHeader.h"
30
31 #include "Ps2Keyboard.h"
32
33 //
34 // function declarations
35 //
36 EFI_STATUS
37 EFIAPI
38 KeyboardEfiReset (
39 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,
40 IN BOOLEAN ExtendedVerification
41 );
42
43 EFI_STATUS
44 EFIAPI
45 KeyboardReadKeyStroke (
46 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,
47 OUT EFI_INPUT_KEY *Key
48 );
49
50 VOID
51 EFIAPI
52 KeyboardWaitForKey (
53 IN EFI_EVENT Event,
54 IN VOID *Context
55 );
56
57 EFI_STATUS
58 KeyboardCheckForKey (
59 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This
60 );
61
62 EFI_STATUS
63 EFIAPI
64 KeyboardEfiReset (
65 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,
66 IN BOOLEAN ExtendedVerification
67 )
68 /*++
69
70 Routine Description:
71
72 Implement SIMPLE_TEXT_IN.Reset()
73 Perform 8042 controller and keyboard initialization
74
75 Arguments:
76
77 Returns:
78
79 --*/
80 // GC_TODO: This - add argument and description to function comment
81 // GC_TODO: ExtendedVerification - add argument and description to function comment
82 // GC_TODO: EFI_DEVICE_ERROR - add return value to function comment
83 // GC_TODO: EFI_DEVICE_ERROR - add return value to function comment
84 // GC_TODO: EFI_SUCCESS - add return value to function comment
85 {
86 EFI_STATUS Status;
87 KEYBOARD_CONSOLE_IN_DEV *ConsoleIn;
88 EFI_TPL OldTpl;
89
90 ConsoleIn = KEYBOARD_CONSOLE_IN_DEV_FROM_THIS (This);
91 if (ConsoleIn->KeyboardErr) {
92 return EFI_DEVICE_ERROR;
93 }
94
95 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
96 EFI_PROGRESS_CODE,
97 EFI_PERIPHERAL_KEYBOARD | EFI_P_PC_RESET,
98 ConsoleIn->DevicePath
99 );
100
101 //
102 // Enter critical section
103 //
104 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
105
106 //
107 // Call InitKeyboard to initialize the keyboard
108 //
109 Status = InitKeyboard (ConsoleIn, ExtendedVerification);
110 if (EFI_ERROR (Status)) {
111 //
112 // Leave critical section and return
113 //
114 gBS->RestoreTPL (OldTpl);
115 return EFI_DEVICE_ERROR;
116 }
117 //
118 // Clear the status of ConsoleIn.Key
119 //
120 ConsoleIn->Key.ScanCode = SCAN_NULL;
121 ConsoleIn->Key.UnicodeChar = 0x0000;
122
123 //
124 // Leave critical section and return
125 //
126 gBS->RestoreTPL (OldTpl);
127
128 //
129 // Report the status If a stuck key was detected
130 //
131 if (KeyReadStatusRegister (ConsoleIn) & 0x01) {
132 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
133 EFI_ERROR_CODE | EFI_ERROR_MINOR,
134 EFI_PERIPHERAL_KEYBOARD | EFI_P_KEYBOARD_EC_STUCK_KEY,
135 ConsoleIn->DevicePath
136 );
137 }
138 //
139 // Report the status If keyboard is locked
140 //
141 if (!(KeyReadStatusRegister (ConsoleIn) & 0x10)) {
142 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
143 EFI_ERROR_CODE | EFI_ERROR_MINOR,
144 EFI_PERIPHERAL_KEYBOARD | EFI_P_KEYBOARD_EC_LOCKED,
145 ConsoleIn->DevicePath
146 );
147 }
148
149 return EFI_SUCCESS;
150 }
151
152 EFI_STATUS
153 EFIAPI
154 KeyboardReadKeyStroke (
155 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,
156 OUT EFI_INPUT_KEY *Key
157 )
158 /*++
159
160 Routine Description:
161
162 Implement SIMPLE_TEXT_IN.ReadKeyStroke().
163 Retrieve key values for driver user.
164
165 Arguments:
166
167 Returns:
168
169 --*/
170 // GC_TODO: This - add argument and description to function comment
171 // GC_TODO: Key - add argument and description to function comment
172 // GC_TODO: EFI_DEVICE_ERROR - add return value to function comment
173 // GC_TODO: EFI_NOT_READY - add return value to function comment
174 // GC_TODO: EFI_SUCCESS - add return value to function comment
175 {
176 EFI_STATUS Status;
177 KEYBOARD_CONSOLE_IN_DEV *ConsoleIn;
178 EFI_TPL OldTpl;
179
180 ConsoleIn = KEYBOARD_CONSOLE_IN_DEV_FROM_THIS (This);
181
182 //
183 // Enter critical section
184 //
185 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
186
187 if (ConsoleIn->KeyboardErr) {
188 //
189 // Leave critical section and return
190 //
191 gBS->RestoreTPL (OldTpl);
192
193 return EFI_DEVICE_ERROR;
194 }
195 //
196 // If there's no key, just return
197 //
198 Status = KeyboardCheckForKey (This);
199 if (EFI_ERROR (Status)) {
200 //
201 // Leave critical section and return
202 //
203 gBS->RestoreTPL (OldTpl);
204 return EFI_NOT_READY;
205 }
206
207 Key->ScanCode = ConsoleIn->Key.ScanCode;
208 Key->UnicodeChar = ConsoleIn->Key.UnicodeChar;
209
210 ConsoleIn->Key.ScanCode = SCAN_NULL;
211 ConsoleIn->Key.UnicodeChar = 0x0000;
212
213 //
214 // Leave critical section and return
215 //
216 gBS->RestoreTPL (OldTpl);
217
218 return EFI_SUCCESS;
219 }
220
221 VOID
222 EFIAPI
223 KeyboardWaitForKey (
224 IN EFI_EVENT Event,
225 IN VOID *Context
226 )
227 /*++
228
229 Routine Description:
230
231 Event notification function for SIMPLE_TEXT_IN.WaitForKey event
232 Signal the event if there is key available
233
234 Arguments:
235
236 Returns:
237
238 --*/
239 // GC_TODO: Event - add argument and description to function comment
240 // GC_TODO: Context - add argument and description to function comment
241 {
242 EFI_TPL OldTpl;
243 KEYBOARD_CONSOLE_IN_DEV *ConsoleIn;
244
245 ConsoleIn = KEYBOARD_CONSOLE_IN_DEV_FROM_THIS (Context);
246
247 //
248 // Enter critical section
249 //
250 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
251
252 if (ConsoleIn->KeyboardErr) {
253 //
254 // Leave critical section and return
255 //
256 gBS->RestoreTPL (OldTpl);
257 return ;
258 }
259 //
260 // Someone is waiting on the keyboard event, if there's
261 // a key pending, signal the event
262 //
263 if (!EFI_ERROR (KeyboardCheckForKey (Context))) {
264 gBS->SignalEvent (Event);
265 }
266 //
267 // Leave critical section and return
268 //
269 gBS->RestoreTPL (OldTpl);
270
271 return ;
272 }
273
274 EFI_STATUS
275 KeyboardCheckForKey (
276 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This
277 )
278 /*++
279
280 Routine Description:
281
282 GC_TODO: Add function description
283
284 Arguments:
285
286 This - GC_TODO: add argument description
287
288 Returns:
289
290 EFI_SUCCESS - GC_TODO: Add description for return value
291
292 --*/
293 {
294 KEYBOARD_CONSOLE_IN_DEV *ConsoleIn;
295
296 ConsoleIn = KEYBOARD_CONSOLE_IN_DEV_FROM_THIS (This);
297
298 //
299 // If ready to read next key, check it
300 //
301 if (ConsoleIn->Key.ScanCode == SCAN_NULL && ConsoleIn->Key.UnicodeChar == 0x00) {
302 return KeyGetchar (ConsoleIn);
303 }
304
305 return EFI_SUCCESS;
306 }