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