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