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