]>
Commit | Line | Data |
---|---|---|
4aa68cbc RN |
1 | /** @file\r |
2 | Routines implements SIMPLE_TEXT_IN protocol's interfaces based on 8042 interfaces\r | |
3 | provided by Ps2KbdCtrller.c.\r | |
4 | \r | |
c9e6803c | 5 | Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r |
9d510e61 | 6 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
4aa68cbc RN |
7 | \r |
8 | **/\r | |
9 | \r | |
10 | \r | |
11 | #include "Ps2Keyboard.h"\r | |
12 | \r | |
13 | /**\r | |
14 | Check whether the EFI key buffer is empty.\r | |
15 | \r | |
16 | @param Queue Pointer to instance of EFI_KEY_QUEUE.\r | |
17 | \r | |
18 | @retval TRUE The EFI key buffer is empty.\r | |
19 | @retval FALSE The EFI key buffer isn't empty.\r | |
20 | **/\r | |
21 | BOOLEAN\r | |
22 | IsEfikeyBufEmpty (\r | |
23 | IN EFI_KEY_QUEUE *Queue\r | |
24 | )\r | |
25 | {\r | |
26 | return (BOOLEAN) (Queue->Head == Queue->Tail);\r | |
27 | }\r | |
28 | \r | |
29 | /**\r | |
30 | Read & remove one key data from the EFI key buffer.\r | |
31 | \r | |
32 | @param Queue Pointer to instance of EFI_KEY_QUEUE.\r | |
33 | @param KeyData Receive the key data.\r | |
34 | \r | |
35 | @retval EFI_SUCCESS The key data is popped successfully.\r | |
36 | @retval EFI_NOT_READY There is no key data available.\r | |
37 | **/\r | |
38 | EFI_STATUS\r | |
39 | PopEfikeyBufHead (\r | |
40 | IN EFI_KEY_QUEUE *Queue,\r | |
41 | OUT EFI_KEY_DATA *KeyData OPTIONAL\r | |
42 | )\r | |
43 | {\r | |
44 | if (IsEfikeyBufEmpty (Queue)) {\r | |
45 | return EFI_NOT_READY;\r | |
46 | }\r | |
47 | //\r | |
48 | // Retrieve and remove the values\r | |
49 | //\r | |
50 | if (KeyData != NULL) {\r | |
51 | CopyMem (KeyData, &Queue->Buffer[Queue->Head], sizeof (EFI_KEY_DATA));\r | |
52 | }\r | |
53 | Queue->Head = (Queue->Head + 1) % KEYBOARD_EFI_KEY_MAX_COUNT;\r | |
54 | return EFI_SUCCESS;\r | |
55 | }\r | |
56 | \r | |
57 | /**\r | |
58 | Push one key data to the EFI key buffer.\r | |
59 | \r | |
60 | @param Queue Pointer to instance of EFI_KEY_QUEUE.\r | |
61 | @param KeyData The key data to push.\r | |
62 | **/\r | |
63 | VOID\r | |
64 | PushEfikeyBufTail (\r | |
65 | IN EFI_KEY_QUEUE *Queue,\r | |
66 | IN EFI_KEY_DATA *KeyData\r | |
67 | )\r | |
68 | {\r | |
69 | if ((Queue->Tail + 1) % KEYBOARD_EFI_KEY_MAX_COUNT == Queue->Head) {\r | |
70 | //\r | |
71 | // If Queue is full, pop the one from head.\r | |
72 | //\r | |
73 | PopEfikeyBufHead (Queue, NULL);\r | |
74 | }\r | |
75 | CopyMem (&Queue->Buffer[Queue->Tail], KeyData, sizeof (EFI_KEY_DATA));\r | |
76 | Queue->Tail = (Queue->Tail + 1) % KEYBOARD_EFI_KEY_MAX_COUNT;\r | |
77 | }\r | |
78 | \r | |
79 | /**\r | |
80 | Judge whether is a registed key\r | |
81 | \r | |
82 | @param RegsiteredData A pointer to a buffer that is filled in with the keystroke\r | |
83 | state data for the key that was registered.\r | |
84 | @param InputData A pointer to a buffer that is filled in with the keystroke\r | |
85 | state data for the key that was pressed.\r | |
86 | \r | |
87 | @retval TRUE Key be pressed matches a registered key.\r | |
88 | @retval FLASE Match failed.\r | |
89 | \r | |
90 | **/\r | |
91 | BOOLEAN\r | |
92 | IsKeyRegistered (\r | |
93 | IN EFI_KEY_DATA *RegsiteredData,\r | |
94 | IN EFI_KEY_DATA *InputData\r | |
95 | )\r | |
96 | \r | |
97 | {\r | |
98 | ASSERT (RegsiteredData != NULL && InputData != NULL);\r | |
99 | \r | |
100 | if ((RegsiteredData->Key.ScanCode != InputData->Key.ScanCode) ||\r | |
101 | (RegsiteredData->Key.UnicodeChar != InputData->Key.UnicodeChar)) {\r | |
102 | return FALSE;\r | |
103 | }\r | |
104 | \r | |
105 | //\r | |
106 | // Assume KeyShiftState/KeyToggleState = 0 in Registered key data means these state could be ignored.\r | |
107 | //\r | |
108 | if (RegsiteredData->KeyState.KeyShiftState != 0 &&\r | |
109 | RegsiteredData->KeyState.KeyShiftState != InputData->KeyState.KeyShiftState) {\r | |
110 | return FALSE;\r | |
111 | }\r | |
112 | if (RegsiteredData->KeyState.KeyToggleState != 0 &&\r | |
113 | RegsiteredData->KeyState.KeyToggleState != InputData->KeyState.KeyToggleState) {\r | |
114 | return FALSE;\r | |
115 | }\r | |
116 | \r | |
117 | return TRUE;\r | |
118 | \r | |
119 | }\r | |
120 | \r | |
121 | /**\r | |
122 | Reads the next keystroke from the input device. The WaitForKey Event can\r | |
123 | be used to test for existance of a keystroke via WaitForEvent () call.\r | |
124 | \r | |
125 | @param ConsoleInDev Ps2 Keyboard private structure\r | |
126 | @param KeyData A pointer to a buffer that is filled in with the keystroke\r | |
127 | state data for the key that was pressed.\r | |
128 | \r | |
129 | \r | |
130 | @retval EFI_SUCCESS The keystroke information was returned.\r | |
131 | @retval EFI_NOT_READY There was no keystroke data availiable.\r | |
132 | @retval EFI_DEVICE_ERROR The keystroke information was not returned due to\r | |
133 | hardware errors.\r | |
134 | @retval EFI_INVALID_PARAMETER KeyData is NULL.\r | |
135 | \r | |
136 | **/\r | |
137 | EFI_STATUS\r | |
138 | KeyboardReadKeyStrokeWorker (\r | |
139 | IN KEYBOARD_CONSOLE_IN_DEV *ConsoleInDev,\r | |
140 | OUT EFI_KEY_DATA *KeyData\r | |
141 | )\r | |
142 | \r | |
143 | {\r | |
144 | EFI_STATUS Status;\r | |
145 | EFI_TPL OldTpl;\r | |
146 | \r | |
147 | if (KeyData == NULL) {\r | |
148 | return EFI_INVALID_PARAMETER;\r | |
149 | }\r | |
150 | \r | |
151 | //\r | |
152 | // Enter critical section\r | |
153 | //\r | |
154 | OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r | |
155 | \r | |
156 | KeyboardTimerHandler (NULL, ConsoleInDev);\r | |
157 | \r | |
158 | if (ConsoleInDev->KeyboardErr) {\r | |
159 | Status = EFI_DEVICE_ERROR;\r | |
160 | } else {\r | |
161 | Status = PopEfikeyBufHead (&ConsoleInDev->EfiKeyQueue, KeyData);\r | |
c9e6803c RN |
162 | if (Status == EFI_NOT_READY) {\r |
163 | ZeroMem (&KeyData->Key, sizeof (KeyData->Key));\r | |
164 | InitializeKeyState (ConsoleInDev, &KeyData->KeyState);\r | |
165 | }\r | |
4aa68cbc RN |
166 | }\r |
167 | \r | |
168 | gBS->RestoreTPL (OldTpl);\r | |
169 | return Status;\r | |
170 | }\r | |
171 | \r | |
172 | /**\r | |
173 | Perform 8042 controller and keyboard initialization which implement SIMPLE_TEXT_IN.Reset()\r | |
174 | \r | |
175 | @param This Pointer to instance of EFI_SIMPLE_TEXT_INPUT_PROTOCOL\r | |
176 | @param ExtendedVerification Indicate that the driver may perform a more\r | |
177 | exhaustive verification operation of the device during\r | |
178 | reset, now this par is ignored in this driver\r | |
179 | \r | |
180 | **/\r | |
181 | EFI_STATUS\r | |
182 | EFIAPI\r | |
183 | KeyboardEfiReset (\r | |
184 | IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,\r | |
185 | IN BOOLEAN ExtendedVerification\r | |
186 | )\r | |
187 | {\r | |
188 | EFI_STATUS Status;\r | |
189 | KEYBOARD_CONSOLE_IN_DEV *ConsoleIn;\r | |
190 | EFI_TPL OldTpl;\r | |
191 | \r | |
192 | ConsoleIn = KEYBOARD_CONSOLE_IN_DEV_FROM_THIS (This);\r | |
193 | if (ConsoleIn->KeyboardErr) {\r | |
194 | return EFI_DEVICE_ERROR;\r | |
195 | }\r | |
196 | \r | |
197 | REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r | |
198 | EFI_PROGRESS_CODE,\r | |
199 | EFI_PERIPHERAL_KEYBOARD | EFI_P_PC_RESET,\r | |
200 | ConsoleIn->DevicePath\r | |
201 | );\r | |
202 | \r | |
203 | //\r | |
204 | // Enter critical section\r | |
205 | //\r | |
206 | OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r | |
207 | \r | |
208 | //\r | |
209 | // Call InitKeyboard to initialize the keyboard\r | |
210 | //\r | |
211 | Status = InitKeyboard (ConsoleIn, ExtendedVerification);\r | |
212 | if (EFI_ERROR (Status)) {\r | |
213 | //\r | |
214 | // Leave critical section and return\r | |
215 | //\r | |
216 | gBS->RestoreTPL (OldTpl);\r | |
217 | return EFI_DEVICE_ERROR;\r | |
218 | }\r | |
219 | \r | |
220 | //\r | |
221 | // Leave critical section and return\r | |
222 | //\r | |
223 | gBS->RestoreTPL (OldTpl);\r | |
224 | \r | |
225 | //\r | |
226 | // Report the status If a stuck key was detected\r | |
227 | //\r | |
228 | if (KeyReadStatusRegister (ConsoleIn) & 0x01) {\r | |
229 | REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r | |
230 | EFI_ERROR_CODE | EFI_ERROR_MINOR,\r | |
231 | EFI_PERIPHERAL_KEYBOARD | EFI_P_KEYBOARD_EC_STUCK_KEY,\r | |
232 | ConsoleIn->DevicePath\r | |
233 | );\r | |
234 | }\r | |
235 | //\r | |
236 | // Report the status If keyboard is locked\r | |
237 | //\r | |
238 | if ((KeyReadStatusRegister (ConsoleIn) & 0x10) == 0) {\r | |
239 | REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r | |
240 | EFI_ERROR_CODE | EFI_ERROR_MINOR,\r | |
241 | EFI_PERIPHERAL_KEYBOARD | EFI_P_KEYBOARD_EC_LOCKED,\r | |
242 | ConsoleIn->DevicePath\r | |
243 | );\r | |
244 | }\r | |
245 | \r | |
246 | return EFI_SUCCESS;\r | |
247 | }\r | |
248 | \r | |
249 | /**\r | |
250 | Retrieve key values for driver user which implement SIMPLE_TEXT_IN.ReadKeyStroke().\r | |
251 | \r | |
252 | @param This Pointer to instance of EFI_SIMPLE_TEXT_INPUT_PROTOCOL\r | |
253 | @param Key The output buffer for key value\r | |
254 | \r | |
255 | @retval EFI_SUCCESS success to read key stroke\r | |
256 | **/\r | |
257 | EFI_STATUS\r | |
258 | EFIAPI\r | |
259 | KeyboardReadKeyStroke (\r | |
260 | IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,\r | |
261 | OUT EFI_INPUT_KEY *Key\r | |
262 | )\r | |
263 | {\r | |
264 | EFI_STATUS Status;\r | |
265 | KEYBOARD_CONSOLE_IN_DEV *ConsoleIn;\r | |
266 | EFI_KEY_DATA KeyData;\r | |
267 | \r | |
268 | ConsoleIn = KEYBOARD_CONSOLE_IN_DEV_FROM_THIS (This);\r | |
269 | \r | |
270 | //\r | |
271 | // Considering if the partial keystroke is enabled, there maybe a partial\r | |
272 | // keystroke in the queue, so here skip the partial keystroke and get the\r | |
273 | // next key from the queue\r | |
274 | //\r | |
275 | while (1) {\r | |
276 | //\r | |
277 | // If there is no pending key, then return.\r | |
278 | //\r | |
279 | Status = KeyboardReadKeyStrokeWorker (ConsoleIn, &KeyData);\r | |
280 | if (EFI_ERROR (Status)) {\r | |
281 | return Status;\r | |
282 | }\r | |
283 | //\r | |
284 | // If it is partial keystroke, skip it.\r | |
285 | //\r | |
286 | if (KeyData.Key.ScanCode == SCAN_NULL && KeyData.Key.UnicodeChar == CHAR_NULL) {\r | |
287 | continue;\r | |
288 | }\r | |
289 | //\r | |
290 | // Translate the CTRL-Alpha characters to their corresponding control value\r | |
291 | // (ctrl-a = 0x0001 through ctrl-Z = 0x001A)\r | |
292 | //\r | |
293 | if ((KeyData.KeyState.KeyShiftState & (EFI_LEFT_CONTROL_PRESSED | EFI_RIGHT_CONTROL_PRESSED)) != 0) {\r | |
294 | if (KeyData.Key.UnicodeChar >= L'a' && KeyData.Key.UnicodeChar <= L'z') {\r | |
295 | KeyData.Key.UnicodeChar = (CHAR16) (KeyData.Key.UnicodeChar - L'a' + 1);\r | |
296 | } else if (KeyData.Key.UnicodeChar >= L'A' && KeyData.Key.UnicodeChar <= L'Z') {\r | |
297 | KeyData.Key.UnicodeChar = (CHAR16) (KeyData.Key.UnicodeChar - L'A' + 1);\r | |
298 | }\r | |
299 | }\r | |
300 | \r | |
301 | CopyMem (Key, &KeyData.Key, sizeof (EFI_INPUT_KEY));\r | |
302 | return EFI_SUCCESS;\r | |
303 | }\r | |
304 | }\r | |
305 | \r | |
306 | /**\r | |
307 | Event notification function for SIMPLE_TEXT_IN.WaitForKey event\r | |
308 | Signal the event if there is key available\r | |
309 | \r | |
310 | @param Event the event object\r | |
311 | @param Context waitting context\r | |
312 | \r | |
313 | **/\r | |
314 | VOID\r | |
315 | EFIAPI\r | |
316 | KeyboardWaitForKey (\r | |
317 | IN EFI_EVENT Event,\r | |
318 | IN VOID *Context\r | |
319 | )\r | |
320 | {\r | |
321 | EFI_TPL OldTpl;\r | |
322 | KEYBOARD_CONSOLE_IN_DEV *ConsoleIn;\r | |
323 | EFI_KEY_DATA KeyData;\r | |
324 | \r | |
325 | ConsoleIn = (KEYBOARD_CONSOLE_IN_DEV *) Context;\r | |
326 | \r | |
327 | //\r | |
328 | // Enter critical section\r | |
329 | //\r | |
330 | OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r | |
331 | \r | |
332 | KeyboardTimerHandler (NULL, ConsoleIn);\r | |
333 | \r | |
334 | if (!ConsoleIn->KeyboardErr) {\r | |
335 | //\r | |
336 | // WaitforKey doesn't suppor the partial key.\r | |
337 | // Considering if the partial keystroke is enabled, there maybe a partial\r | |
338 | // keystroke in the queue, so here skip the partial keystroke and get the\r | |
339 | // next key from the queue\r | |
340 | //\r | |
341 | while (!IsEfikeyBufEmpty (&ConsoleIn->EfiKeyQueue)) {\r | |
342 | CopyMem (\r | |
343 | &KeyData,\r | |
344 | &(ConsoleIn->EfiKeyQueue.Buffer[ConsoleIn->EfiKeyQueue.Head]),\r | |
345 | sizeof (EFI_KEY_DATA)\r | |
346 | );\r | |
347 | if (KeyData.Key.ScanCode == SCAN_NULL && KeyData.Key.UnicodeChar == CHAR_NULL) {\r | |
348 | PopEfikeyBufHead (&ConsoleIn->EfiKeyQueue, &KeyData);\r | |
349 | continue;\r | |
350 | }\r | |
351 | //\r | |
352 | // if there is pending value key, signal the event.\r | |
353 | //\r | |
354 | gBS->SignalEvent (Event);\r | |
355 | break;\r | |
356 | }\r | |
357 | }\r | |
358 | //\r | |
359 | // Leave critical section and return\r | |
360 | //\r | |
361 | gBS->RestoreTPL (OldTpl);\r | |
362 | }\r | |
363 | \r | |
364 | /**\r | |
365 | Event notification function for SIMPLE_TEXT_INPUT_EX_PROTOCOL.WaitForKeyEx event\r | |
366 | Signal the event if there is key available\r | |
367 | \r | |
368 | @param Event event object\r | |
369 | @param Context waiting context\r | |
370 | \r | |
371 | **/\r | |
372 | VOID\r | |
373 | EFIAPI\r | |
374 | KeyboardWaitForKeyEx (\r | |
375 | IN EFI_EVENT Event,\r | |
376 | IN VOID *Context\r | |
377 | )\r | |
378 | \r | |
379 | {\r | |
380 | KeyboardWaitForKey (Event, Context);\r | |
381 | }\r | |
382 | \r | |
383 | /**\r | |
384 | Reset the input device and optionaly run diagnostics\r | |
385 | \r | |
386 | @param This Protocol instance pointer.\r | |
387 | @param ExtendedVerification Driver may perform diagnostics on reset.\r | |
388 | \r | |
389 | @retval EFI_SUCCESS The device was reset.\r | |
390 | @retval EFI_DEVICE_ERROR The device is not functioning properly and could\r | |
391 | not be reset.\r | |
392 | \r | |
393 | **/\r | |
394 | EFI_STATUS\r | |
395 | EFIAPI\r | |
396 | KeyboardEfiResetEx (\r | |
397 | IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,\r | |
398 | IN BOOLEAN ExtendedVerification\r | |
399 | )\r | |
400 | \r | |
401 | {\r | |
402 | KEYBOARD_CONSOLE_IN_DEV *ConsoleInDev;\r | |
403 | \r | |
404 | ConsoleInDev = TEXT_INPUT_EX_KEYBOARD_CONSOLE_IN_DEV_FROM_THIS (This);\r | |
405 | \r | |
406 | return ConsoleInDev->ConIn.Reset (\r | |
407 | &ConsoleInDev->ConIn,\r | |
408 | ExtendedVerification\r | |
409 | );\r | |
410 | }\r | |
411 | \r | |
412 | /**\r | |
413 | Reads the next keystroke from the input device. The WaitForKey Event can\r | |
414 | be used to test for existance of a keystroke via WaitForEvent () call.\r | |
415 | \r | |
416 | \r | |
417 | @param This Protocol instance pointer.\r | |
418 | @param KeyData A pointer to a buffer that is filled in with the keystroke\r | |
419 | state data for the key that was pressed.\r | |
420 | \r | |
421 | @retval EFI_SUCCESS The keystroke information was returned.\r | |
422 | @retval EFI_NOT_READY There was no keystroke data availiable.\r | |
423 | @retval EFI_DEVICE_ERROR The keystroke information was not returned due to\r | |
424 | hardware errors.\r | |
425 | @retval EFI_INVALID_PARAMETER KeyData is NULL.\r | |
426 | \r | |
427 | **/\r | |
428 | EFI_STATUS\r | |
429 | EFIAPI\r | |
430 | KeyboardReadKeyStrokeEx (\r | |
431 | IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,\r | |
432 | OUT EFI_KEY_DATA *KeyData\r | |
433 | )\r | |
434 | \r | |
435 | {\r | |
436 | KEYBOARD_CONSOLE_IN_DEV *ConsoleInDev;\r | |
437 | \r | |
438 | if (KeyData == NULL) {\r | |
439 | return EFI_INVALID_PARAMETER;\r | |
440 | }\r | |
441 | \r | |
442 | ConsoleInDev = TEXT_INPUT_EX_KEYBOARD_CONSOLE_IN_DEV_FROM_THIS (This);\r | |
443 | return KeyboardReadKeyStrokeWorker (ConsoleInDev, KeyData);\r | |
444 | }\r | |
445 | \r | |
446 | /**\r | |
447 | Set certain state for the input device.\r | |
448 | \r | |
449 | @param This Protocol instance pointer.\r | |
450 | @param KeyToggleState A pointer to the EFI_KEY_TOGGLE_STATE to set the\r | |
451 | state for the input device.\r | |
452 | \r | |
453 | @retval EFI_SUCCESS The device state was set successfully.\r | |
454 | @retval EFI_DEVICE_ERROR The device is not functioning correctly and could\r | |
455 | not have the setting adjusted.\r | |
456 | @retval EFI_UNSUPPORTED The device does not have the ability to set its state.\r | |
457 | @retval EFI_INVALID_PARAMETER KeyToggleState is NULL.\r | |
458 | \r | |
459 | **/\r | |
460 | EFI_STATUS\r | |
461 | EFIAPI\r | |
462 | KeyboardSetState (\r | |
463 | IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,\r | |
464 | IN EFI_KEY_TOGGLE_STATE *KeyToggleState\r | |
465 | )\r | |
466 | \r | |
467 | {\r | |
468 | EFI_STATUS Status;\r | |
469 | KEYBOARD_CONSOLE_IN_DEV *ConsoleInDev;\r | |
470 | EFI_TPL OldTpl;\r | |
471 | \r | |
472 | if (KeyToggleState == NULL) {\r | |
473 | return EFI_INVALID_PARAMETER;\r | |
474 | }\r | |
475 | \r | |
476 | ConsoleInDev = TEXT_INPUT_EX_KEYBOARD_CONSOLE_IN_DEV_FROM_THIS (This);\r | |
477 | \r | |
478 | //\r | |
479 | // Enter critical section\r | |
480 | //\r | |
481 | OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r | |
482 | \r | |
483 | if (ConsoleInDev->KeyboardErr) {\r | |
484 | Status = EFI_DEVICE_ERROR;\r | |
485 | goto Exit;\r | |
486 | }\r | |
487 | \r | |
488 | if ((*KeyToggleState & EFI_TOGGLE_STATE_VALID) != EFI_TOGGLE_STATE_VALID) {\r | |
489 | Status = EFI_UNSUPPORTED;\r | |
490 | goto Exit;\r | |
491 | }\r | |
492 | \r | |
493 | //\r | |
494 | // Update the status light\r | |
495 | //\r | |
496 | ConsoleInDev->ScrollLock = FALSE;\r | |
497 | ConsoleInDev->NumLock = FALSE;\r | |
498 | ConsoleInDev->CapsLock = FALSE;\r | |
499 | ConsoleInDev->IsSupportPartialKey = FALSE;\r | |
500 | \r | |
501 | if ((*KeyToggleState & EFI_SCROLL_LOCK_ACTIVE) == EFI_SCROLL_LOCK_ACTIVE) {\r | |
502 | ConsoleInDev->ScrollLock = TRUE;\r | |
503 | }\r | |
504 | if ((*KeyToggleState & EFI_NUM_LOCK_ACTIVE) == EFI_NUM_LOCK_ACTIVE) {\r | |
505 | ConsoleInDev->NumLock = TRUE;\r | |
506 | }\r | |
507 | if ((*KeyToggleState & EFI_CAPS_LOCK_ACTIVE) == EFI_CAPS_LOCK_ACTIVE) {\r | |
508 | ConsoleInDev->CapsLock = TRUE;\r | |
509 | }\r | |
510 | if ((*KeyToggleState & EFI_KEY_STATE_EXPOSED) == EFI_KEY_STATE_EXPOSED) {\r | |
511 | ConsoleInDev->IsSupportPartialKey = TRUE;\r | |
512 | }\r | |
513 | \r | |
514 | Status = UpdateStatusLights (ConsoleInDev);\r | |
515 | if (EFI_ERROR (Status)) {\r | |
516 | Status = EFI_DEVICE_ERROR;\r | |
517 | }\r | |
518 | \r | |
519 | Exit:\r | |
520 | //\r | |
521 | // Leave critical section and return\r | |
522 | //\r | |
523 | gBS->RestoreTPL (OldTpl);\r | |
524 | \r | |
525 | return Status;\r | |
526 | \r | |
527 | }\r | |
528 | \r | |
529 | /**\r | |
530 | Register a notification function for a particular keystroke for the input device.\r | |
531 | \r | |
532 | @param This Protocol instance pointer.\r | |
533 | @param KeyData A pointer to a buffer that is filled in with the keystroke\r | |
3652f990 DB |
534 | information data for the key that was pressed. If KeyData.Key,\r |
535 | KeyData.KeyState.KeyToggleState and KeyData.KeyState.KeyShiftState are 0,\r | |
536 | then any incomplete keystroke will trigger a notification of the KeyNotificationFunction.\r | |
4aa68cbc | 537 | @param KeyNotificationFunction Points to the function to be called when the key\r |
3652f990 DB |
538 | sequence is typed specified by KeyData. This notification function\r |
539 | should be called at <=TPL_CALLBACK.\r | |
4aa68cbc RN |
540 | @param NotifyHandle Points to the unique handle assigned to the registered notification.\r |
541 | \r | |
542 | @retval EFI_SUCCESS The notification function was registered successfully.\r | |
543 | @retval EFI_OUT_OF_RESOURCES Unable to allocate resources for necesssary data structures.\r | |
544 | @retval EFI_INVALID_PARAMETER KeyData or NotifyHandle or KeyNotificationFunction is NULL.\r | |
545 | \r | |
546 | **/\r | |
547 | EFI_STATUS\r | |
548 | EFIAPI\r | |
549 | KeyboardRegisterKeyNotify (\r | |
550 | IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,\r | |
551 | IN EFI_KEY_DATA *KeyData,\r | |
552 | IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction,\r | |
553 | OUT VOID **NotifyHandle\r | |
554 | )\r | |
555 | {\r | |
556 | EFI_STATUS Status;\r | |
557 | KEYBOARD_CONSOLE_IN_DEV *ConsoleInDev;\r | |
558 | EFI_TPL OldTpl;\r | |
559 | LIST_ENTRY *Link;\r | |
560 | KEYBOARD_CONSOLE_IN_EX_NOTIFY *CurrentNotify;\r | |
561 | KEYBOARD_CONSOLE_IN_EX_NOTIFY *NewNotify;\r | |
562 | \r | |
563 | if (KeyData == NULL || NotifyHandle == NULL || KeyNotificationFunction == NULL) {\r | |
564 | return EFI_INVALID_PARAMETER;\r | |
565 | }\r | |
566 | \r | |
567 | ConsoleInDev = TEXT_INPUT_EX_KEYBOARD_CONSOLE_IN_DEV_FROM_THIS (This);\r | |
568 | \r | |
569 | //\r | |
570 | // Enter critical section\r | |
571 | //\r | |
572 | OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r | |
573 | \r | |
574 | //\r | |
575 | // Return EFI_SUCCESS if the (KeyData, NotificationFunction) is already registered.\r | |
576 | //\r | |
577 | for (Link = ConsoleInDev->NotifyList.ForwardLink; Link != &ConsoleInDev->NotifyList; Link = Link->ForwardLink) {\r | |
578 | CurrentNotify = CR (\r | |
579 | Link,\r | |
580 | KEYBOARD_CONSOLE_IN_EX_NOTIFY,\r | |
581 | NotifyEntry,\r | |
582 | KEYBOARD_CONSOLE_IN_EX_NOTIFY_SIGNATURE\r | |
583 | );\r | |
584 | if (IsKeyRegistered (&CurrentNotify->KeyData, KeyData)) {\r | |
585 | if (CurrentNotify->KeyNotificationFn == KeyNotificationFunction) {\r | |
586 | *NotifyHandle = CurrentNotify;\r | |
587 | Status = EFI_SUCCESS;\r | |
588 | goto Exit;\r | |
589 | }\r | |
590 | }\r | |
591 | }\r | |
592 | \r | |
593 | //\r | |
594 | // Allocate resource to save the notification function\r | |
595 | //\r | |
596 | NewNotify = (KEYBOARD_CONSOLE_IN_EX_NOTIFY *) AllocateZeroPool (sizeof (KEYBOARD_CONSOLE_IN_EX_NOTIFY));\r | |
597 | if (NewNotify == NULL) {\r | |
598 | Status = EFI_OUT_OF_RESOURCES;\r | |
599 | goto Exit;\r | |
600 | }\r | |
601 | \r | |
602 | NewNotify->Signature = KEYBOARD_CONSOLE_IN_EX_NOTIFY_SIGNATURE;\r | |
603 | NewNotify->KeyNotificationFn = KeyNotificationFunction;\r | |
604 | CopyMem (&NewNotify->KeyData, KeyData, sizeof (EFI_KEY_DATA));\r | |
605 | InsertTailList (&ConsoleInDev->NotifyList, &NewNotify->NotifyEntry);\r | |
606 | \r | |
607 | *NotifyHandle = NewNotify;\r | |
608 | Status = EFI_SUCCESS;\r | |
609 | \r | |
610 | Exit:\r | |
611 | //\r | |
612 | // Leave critical section and return\r | |
613 | //\r | |
614 | gBS->RestoreTPL (OldTpl);\r | |
615 | return Status;\r | |
616 | \r | |
617 | }\r | |
618 | \r | |
619 | /**\r | |
620 | Remove a registered notification function from a particular keystroke.\r | |
621 | \r | |
622 | @param This Protocol instance pointer.\r | |
623 | @param NotificationHandle The handle of the notification function being unregistered.\r | |
624 | \r | |
625 | \r | |
626 | @retval EFI_SUCCESS The notification function was unregistered successfully.\r | |
627 | @retval EFI_INVALID_PARAMETER The NotificationHandle is invalid.\r | |
628 | \r | |
629 | **/\r | |
630 | EFI_STATUS\r | |
631 | EFIAPI\r | |
632 | KeyboardUnregisterKeyNotify (\r | |
633 | IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,\r | |
634 | IN VOID *NotificationHandle\r | |
635 | )\r | |
636 | {\r | |
637 | EFI_STATUS Status;\r | |
638 | KEYBOARD_CONSOLE_IN_DEV *ConsoleInDev;\r | |
639 | EFI_TPL OldTpl;\r | |
640 | LIST_ENTRY *Link;\r | |
641 | KEYBOARD_CONSOLE_IN_EX_NOTIFY *CurrentNotify;\r | |
642 | \r | |
643 | if (NotificationHandle == NULL) {\r | |
644 | return EFI_INVALID_PARAMETER;\r | |
645 | }\r | |
646 | \r | |
647 | ConsoleInDev = TEXT_INPUT_EX_KEYBOARD_CONSOLE_IN_DEV_FROM_THIS (This);\r | |
648 | \r | |
649 | //\r | |
650 | // Enter critical section\r | |
651 | //\r | |
652 | OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r | |
653 | \r | |
654 | for (Link = ConsoleInDev->NotifyList.ForwardLink; Link != &ConsoleInDev->NotifyList; Link = Link->ForwardLink) {\r | |
655 | CurrentNotify = CR (\r | |
656 | Link,\r | |
657 | KEYBOARD_CONSOLE_IN_EX_NOTIFY,\r | |
658 | NotifyEntry,\r | |
659 | KEYBOARD_CONSOLE_IN_EX_NOTIFY_SIGNATURE\r | |
660 | );\r | |
661 | if (CurrentNotify == NotificationHandle) {\r | |
662 | //\r | |
663 | // Remove the notification function from NotifyList and free resources\r | |
664 | //\r | |
665 | RemoveEntryList (&CurrentNotify->NotifyEntry);\r | |
666 | \r | |
667 | gBS->FreePool (CurrentNotify);\r | |
668 | Status = EFI_SUCCESS;\r | |
669 | goto Exit;\r | |
670 | }\r | |
671 | }\r | |
672 | \r | |
673 | //\r | |
674 | // Can not find the specified Notification Handle\r | |
675 | //\r | |
676 | Status = EFI_INVALID_PARAMETER;\r | |
677 | Exit:\r | |
678 | //\r | |
679 | // Leave critical section and return\r | |
680 | //\r | |
681 | gBS->RestoreTPL (OldTpl);\r | |
682 | return Status;\r | |
683 | }\r | |
684 | \r | |
35dadd7c SZ |
685 | /**\r |
686 | Process key notify.\r | |
687 | \r | |
688 | @param Event Indicates the event that invoke this function.\r | |
689 | @param Context Indicates the calling context.\r | |
690 | **/\r | |
691 | VOID\r | |
692 | EFIAPI\r | |
693 | KeyNotifyProcessHandler (\r | |
694 | IN EFI_EVENT Event,\r | |
695 | IN VOID *Context\r | |
696 | )\r | |
697 | {\r | |
698 | EFI_STATUS Status;\r | |
699 | KEYBOARD_CONSOLE_IN_DEV *ConsoleIn;\r | |
700 | EFI_KEY_DATA KeyData;\r | |
701 | LIST_ENTRY *Link;\r | |
702 | LIST_ENTRY *NotifyList;\r | |
703 | KEYBOARD_CONSOLE_IN_EX_NOTIFY *CurrentNotify;\r | |
704 | EFI_TPL OldTpl;\r | |
705 | \r | |
706 | ConsoleIn = (KEYBOARD_CONSOLE_IN_DEV *) Context;\r | |
707 | \r | |
708 | //\r | |
709 | // Invoke notification functions.\r | |
710 | //\r | |
711 | NotifyList = &ConsoleIn->NotifyList;\r | |
712 | while (TRUE) {\r | |
713 | //\r | |
714 | // Enter critical section\r | |
d1102dba | 715 | //\r |
35dadd7c SZ |
716 | OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r |
717 | Status = PopEfikeyBufHead (&ConsoleIn->EfiKeyQueueForNotify, &KeyData);\r | |
718 | //\r | |
719 | // Leave critical section\r | |
720 | //\r | |
721 | gBS->RestoreTPL (OldTpl);\r | |
722 | if (EFI_ERROR (Status)) {\r | |
723 | break;\r | |
724 | }\r | |
725 | for (Link = GetFirstNode (NotifyList); !IsNull (NotifyList, Link); Link = GetNextNode (NotifyList, Link)) {\r | |
726 | CurrentNotify = CR (Link, KEYBOARD_CONSOLE_IN_EX_NOTIFY, NotifyEntry, KEYBOARD_CONSOLE_IN_EX_NOTIFY_SIGNATURE);\r | |
727 | if (IsKeyRegistered (&CurrentNotify->KeyData, &KeyData)) {\r | |
728 | CurrentNotify->KeyNotificationFn (&KeyData);\r | |
729 | }\r | |
730 | }\r | |
731 | }\r | |
732 | }\r | |
733 | \r |