]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Bus/Isa/Ps2KeyboardDxe/Ps2KbdTextIn.c
IntelFrameworkModule/Ps2Kb: ReadKeyStrokeEx always return key state
[mirror_edk2.git] / IntelFrameworkModulePkg / 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
542 are 0, then any incomplete keystroke will trigger a notification of
543 the KeyNotificationFunction.
544 @param KeyNotificationFunction Points to the function to be called when the key
545 sequence is typed specified by KeyData. This notification function
546 should be called at <=TPL_CALLBACK.
547 @param NotifyHandle Points to the unique handle assigned to the registered notification.
548
549 @retval EFI_SUCCESS The notification function was registered successfully.
550 @retval EFI_OUT_OF_RESOURCES Unable to allocate resources for necesssary data structures.
551 @retval EFI_INVALID_PARAMETER KeyData or NotifyHandle or KeyNotificationFunction is NULL.
552
553 **/
554 EFI_STATUS
555 EFIAPI
556 KeyboardRegisterKeyNotify (
557 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
558 IN EFI_KEY_DATA *KeyData,
559 IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction,
560 OUT VOID **NotifyHandle
561 )
562 {
563 EFI_STATUS Status;
564 KEYBOARD_CONSOLE_IN_DEV *ConsoleInDev;
565 EFI_TPL OldTpl;
566 LIST_ENTRY *Link;
567 KEYBOARD_CONSOLE_IN_EX_NOTIFY *CurrentNotify;
568 KEYBOARD_CONSOLE_IN_EX_NOTIFY *NewNotify;
569
570 if (KeyData == NULL || NotifyHandle == NULL || KeyNotificationFunction == NULL) {
571 return EFI_INVALID_PARAMETER;
572 }
573
574 ConsoleInDev = TEXT_INPUT_EX_KEYBOARD_CONSOLE_IN_DEV_FROM_THIS (This);
575
576 //
577 // Enter critical section
578 //
579 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
580
581 //
582 // Return EFI_SUCCESS if the (KeyData, NotificationFunction) is already registered.
583 //
584 for (Link = ConsoleInDev->NotifyList.ForwardLink; Link != &ConsoleInDev->NotifyList; Link = Link->ForwardLink) {
585 CurrentNotify = CR (
586 Link,
587 KEYBOARD_CONSOLE_IN_EX_NOTIFY,
588 NotifyEntry,
589 KEYBOARD_CONSOLE_IN_EX_NOTIFY_SIGNATURE
590 );
591 if (IsKeyRegistered (&CurrentNotify->KeyData, KeyData)) {
592 if (CurrentNotify->KeyNotificationFn == KeyNotificationFunction) {
593 *NotifyHandle = CurrentNotify;
594 Status = EFI_SUCCESS;
595 goto Exit;
596 }
597 }
598 }
599
600 //
601 // Allocate resource to save the notification function
602 //
603 NewNotify = (KEYBOARD_CONSOLE_IN_EX_NOTIFY *) AllocateZeroPool (sizeof (KEYBOARD_CONSOLE_IN_EX_NOTIFY));
604 if (NewNotify == NULL) {
605 Status = EFI_OUT_OF_RESOURCES;
606 goto Exit;
607 }
608
609 NewNotify->Signature = KEYBOARD_CONSOLE_IN_EX_NOTIFY_SIGNATURE;
610 NewNotify->KeyNotificationFn = KeyNotificationFunction;
611 CopyMem (&NewNotify->KeyData, KeyData, sizeof (EFI_KEY_DATA));
612 InsertTailList (&ConsoleInDev->NotifyList, &NewNotify->NotifyEntry);
613
614 *NotifyHandle = NewNotify;
615 Status = EFI_SUCCESS;
616
617 Exit:
618 //
619 // Leave critical section and return
620 //
621 gBS->RestoreTPL (OldTpl);
622 return Status;
623
624 }
625
626 /**
627 Remove a registered notification function from a particular keystroke.
628
629 @param This Protocol instance pointer.
630 @param NotificationHandle The handle of the notification function being unregistered.
631
632
633 @retval EFI_SUCCESS The notification function was unregistered successfully.
634 @retval EFI_INVALID_PARAMETER The NotificationHandle is invalid.
635
636 **/
637 EFI_STATUS
638 EFIAPI
639 KeyboardUnregisterKeyNotify (
640 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
641 IN VOID *NotificationHandle
642 )
643 {
644 EFI_STATUS Status;
645 KEYBOARD_CONSOLE_IN_DEV *ConsoleInDev;
646 EFI_TPL OldTpl;
647 LIST_ENTRY *Link;
648 KEYBOARD_CONSOLE_IN_EX_NOTIFY *CurrentNotify;
649
650 if (NotificationHandle == NULL) {
651 return EFI_INVALID_PARAMETER;
652 }
653
654 ConsoleInDev = TEXT_INPUT_EX_KEYBOARD_CONSOLE_IN_DEV_FROM_THIS (This);
655
656 //
657 // Enter critical section
658 //
659 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
660
661 for (Link = ConsoleInDev->NotifyList.ForwardLink; Link != &ConsoleInDev->NotifyList; Link = Link->ForwardLink) {
662 CurrentNotify = CR (
663 Link,
664 KEYBOARD_CONSOLE_IN_EX_NOTIFY,
665 NotifyEntry,
666 KEYBOARD_CONSOLE_IN_EX_NOTIFY_SIGNATURE
667 );
668 if (CurrentNotify == NotificationHandle) {
669 //
670 // Remove the notification function from NotifyList and free resources
671 //
672 RemoveEntryList (&CurrentNotify->NotifyEntry);
673
674 gBS->FreePool (CurrentNotify);
675 Status = EFI_SUCCESS;
676 goto Exit;
677 }
678 }
679
680 //
681 // Can not find the specified Notification Handle
682 //
683 Status = EFI_INVALID_PARAMETER;
684 Exit:
685 //
686 // Leave critical section and return
687 //
688 gBS->RestoreTPL (OldTpl);
689 return Status;
690 }
691
692 /**
693 Process key notify.
694
695 @param Event Indicates the event that invoke this function.
696 @param Context Indicates the calling context.
697 **/
698 VOID
699 EFIAPI
700 KeyNotifyProcessHandler (
701 IN EFI_EVENT Event,
702 IN VOID *Context
703 )
704 {
705 EFI_STATUS Status;
706 KEYBOARD_CONSOLE_IN_DEV *ConsoleIn;
707 EFI_KEY_DATA KeyData;
708 LIST_ENTRY *Link;
709 LIST_ENTRY *NotifyList;
710 KEYBOARD_CONSOLE_IN_EX_NOTIFY *CurrentNotify;
711 EFI_TPL OldTpl;
712
713 ConsoleIn = (KEYBOARD_CONSOLE_IN_DEV *) Context;
714
715 //
716 // Invoke notification functions.
717 //
718 NotifyList = &ConsoleIn->NotifyList;
719 while (TRUE) {
720 //
721 // Enter critical section
722 //
723 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
724 Status = PopEfikeyBufHead (&ConsoleIn->EfiKeyQueueForNotify, &KeyData);
725 //
726 // Leave critical section
727 //
728 gBS->RestoreTPL (OldTpl);
729 if (EFI_ERROR (Status)) {
730 break;
731 }
732 for (Link = GetFirstNode (NotifyList); !IsNull (NotifyList, Link); Link = GetNextNode (NotifyList, Link)) {
733 CurrentNotify = CR (Link, KEYBOARD_CONSOLE_IN_EX_NOTIFY, NotifyEntry, KEYBOARD_CONSOLE_IN_EX_NOTIFY_SIGNATURE);
734 if (IsKeyRegistered (&CurrentNotify->KeyData, &KeyData)) {
735 CurrentNotify->KeyNotificationFn (&KeyData);
736 }
737 }
738 }
739 }
740