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