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