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