MdeModulePkg Ps2KbDxe: Execute key notify func at TPL_CALLBACK

Current implementation executes key notify function in TimerHandler
at TPL_NOTIFY. The code change is to make key notify function
executed at TPL_CALLBACK to reduce the time occupied at TPL_NOTIFY.

The code will signal KeyNotify process event if the key pressed
matches any key registered and insert the KeyData to the EFI Key
queue for notify, then the KeyNotify process handler will invoke
key notify functions at TPL_CALLBACK.

Cc: Ruiyu Ni <Ruiyu.ni@intel.com>
Cc: Michael Kinney <michael.d.kinney@intel.com>
Cc: Feng Tian <feng.tian@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Ruiyu Ni <Ruiyu.ni@intel.com>
This commit is contained in:
Star Zeng 2016-12-16 18:08:18 +08:00
parent 47b612db90
commit 35dadd7c54
4 changed files with 94 additions and 2 deletions

View File

@ -1420,7 +1420,7 @@ KeyGetchar (
} }
// //
// Invoke notification functions if exist // Signal KeyNotify process event if this key pressed matches any key registered.
// //
for (Link = GetFirstNode (&ConsoleIn->NotifyList); !IsNull (&ConsoleIn->NotifyList, Link); Link = GetNextNode (&ConsoleIn->NotifyList, Link)) { for (Link = GetFirstNode (&ConsoleIn->NotifyList); !IsNull (&ConsoleIn->NotifyList, Link); Link = GetNextNode (&ConsoleIn->NotifyList, Link)) {
CurrentNotify = CR ( CurrentNotify = CR (
@ -1430,7 +1430,13 @@ KeyGetchar (
KEYBOARD_CONSOLE_IN_EX_NOTIFY_SIGNATURE KEYBOARD_CONSOLE_IN_EX_NOTIFY_SIGNATURE
); );
if (IsKeyRegistered (&CurrentNotify->KeyData, &KeyData)) { if (IsKeyRegistered (&CurrentNotify->KeyData, &KeyData)) {
CurrentNotify->KeyNotificationFn (&KeyData); //
// The key notification function needs to run at TPL_CALLBACK
// while current TPL is TPL_NOTIFY. It will be invoked in
// KeyNotifyProcessHandler() which runs at TPL_CALLBACK.
//
PushEfikeyBufTail (&ConsoleIn->EfiKeyQueueForNotify, &KeyData);
gBS->SignalEvent (ConsoleIn->KeyNotifyProcessEvent);
} }
} }
@ -1629,6 +1635,8 @@ InitKeyboard (
ConsoleIn->ScancodeQueue.Tail = 0; ConsoleIn->ScancodeQueue.Tail = 0;
ConsoleIn->EfiKeyQueue.Head = 0; ConsoleIn->EfiKeyQueue.Head = 0;
ConsoleIn->EfiKeyQueue.Tail = 0; ConsoleIn->EfiKeyQueue.Tail = 0;
ConsoleIn->EfiKeyQueueForNotify.Head = 0;
ConsoleIn->EfiKeyQueueForNotify.Tail = 0;
// //
// Reset the status indicators // Reset the status indicators

View File

@ -681,3 +681,52 @@ Exit:
return Status; return Status;
} }
/**
Process key notify.
@param Event Indicates the event that invoke this function.
@param Context Indicates the calling context.
**/
VOID
EFIAPI
KeyNotifyProcessHandler (
IN EFI_EVENT Event,
IN VOID *Context
)
{
EFI_STATUS Status;
KEYBOARD_CONSOLE_IN_DEV *ConsoleIn;
EFI_KEY_DATA KeyData;
LIST_ENTRY *Link;
LIST_ENTRY *NotifyList;
KEYBOARD_CONSOLE_IN_EX_NOTIFY *CurrentNotify;
EFI_TPL OldTpl;
ConsoleIn = (KEYBOARD_CONSOLE_IN_DEV *) Context;
//
// Invoke notification functions.
//
NotifyList = &ConsoleIn->NotifyList;
while (TRUE) {
//
// Enter critical section
//
OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
Status = PopEfikeyBufHead (&ConsoleIn->EfiKeyQueueForNotify, &KeyData);
//
// Leave critical section
//
gBS->RestoreTPL (OldTpl);
if (EFI_ERROR (Status)) {
break;
}
for (Link = GetFirstNode (NotifyList); !IsNull (NotifyList, Link); Link = GetNextNode (NotifyList, Link)) {
CurrentNotify = CR (Link, KEYBOARD_CONSOLE_IN_EX_NOTIFY, NotifyEntry, KEYBOARD_CONSOLE_IN_EX_NOTIFY_SIGNATURE);
if (IsKeyRegistered (&CurrentNotify->KeyData, &KeyData)) {
CurrentNotify->KeyNotificationFn (&KeyData);
}
}
}
}

View File

@ -351,6 +351,19 @@ KbdControllerDriverStart (
goto ErrorExit; goto ErrorExit;
} }
Status = gBS->CreateEvent (
EVT_NOTIFY_SIGNAL,
TPL_CALLBACK,
KeyNotifyProcessHandler,
ConsoleIn,
&ConsoleIn->KeyNotifyProcessEvent
);
if (EFI_ERROR (Status)) {
Status = EFI_OUT_OF_RESOURCES;
StatusCode = EFI_PERIPHERAL_KEYBOARD | EFI_P_EC_CONTROLLER_ERROR;
goto ErrorExit;
}
REPORT_STATUS_CODE_WITH_DEVICE_PATH ( REPORT_STATUS_CODE_WITH_DEVICE_PATH (
EFI_PROGRESS_CODE, EFI_PROGRESS_CODE,
EFI_PERIPHERAL_KEYBOARD | EFI_P_PC_PRESENCE_DETECT, EFI_PERIPHERAL_KEYBOARD | EFI_P_PC_PRESENCE_DETECT,
@ -430,6 +443,9 @@ ErrorExit:
if ((ConsoleIn != NULL) && (ConsoleIn->ConInEx.WaitForKeyEx != NULL)) { if ((ConsoleIn != NULL) && (ConsoleIn->ConInEx.WaitForKeyEx != NULL)) {
gBS->CloseEvent (ConsoleIn->ConInEx.WaitForKeyEx); gBS->CloseEvent (ConsoleIn->ConInEx.WaitForKeyEx);
} }
if ((ConsoleIn != NULL) && (ConsoleIn->KeyNotifyProcessEvent != NULL)) {
gBS->CloseEvent (ConsoleIn->KeyNotifyProcessEvent);
}
KbdFreeNotifyList (&ConsoleIn->NotifyList); KbdFreeNotifyList (&ConsoleIn->NotifyList);
if ((ConsoleIn != NULL) && (ConsoleIn->ControllerNameTable != NULL)) { if ((ConsoleIn != NULL) && (ConsoleIn->ControllerNameTable != NULL)) {
FreeUnicodeStringTable (ConsoleIn->ControllerNameTable); FreeUnicodeStringTable (ConsoleIn->ControllerNameTable);
@ -570,6 +586,10 @@ KbdControllerDriverStop (
gBS->CloseEvent (ConsoleIn->ConInEx.WaitForKeyEx); gBS->CloseEvent (ConsoleIn->ConInEx.WaitForKeyEx);
ConsoleIn->ConInEx.WaitForKeyEx = NULL; ConsoleIn->ConInEx.WaitForKeyEx = NULL;
} }
if (ConsoleIn->KeyNotifyProcessEvent != NULL) {
gBS->CloseEvent (ConsoleIn->KeyNotifyProcessEvent);
ConsoleIn->KeyNotifyProcessEvent = NULL;
}
KbdFreeNotifyList (&ConsoleIn->NotifyList); KbdFreeNotifyList (&ConsoleIn->NotifyList);
FreeUnicodeStringTable (ConsoleIn->ControllerNameTable); FreeUnicodeStringTable (ConsoleIn->ControllerNameTable);
gBS->FreePool (ConsoleIn); gBS->FreePool (ConsoleIn);

View File

@ -105,6 +105,7 @@ typedef struct {
// //
SCAN_CODE_QUEUE ScancodeQueue; SCAN_CODE_QUEUE ScancodeQueue;
EFI_KEY_QUEUE EfiKeyQueue; EFI_KEY_QUEUE EfiKeyQueue;
EFI_KEY_QUEUE EfiKeyQueueForNotify;
// //
// Error state // Error state
@ -118,6 +119,7 @@ typedef struct {
// Notification Function List // Notification Function List
// //
LIST_ENTRY NotifyList; LIST_ENTRY NotifyList;
EFI_EVENT KeyNotifyProcessEvent;
} KEYBOARD_CONSOLE_IN_DEV; } KEYBOARD_CONSOLE_IN_DEV;
#define KEYBOARD_CONSOLE_IN_DEV_FROM_THIS(a) CR (a, KEYBOARD_CONSOLE_IN_DEV, ConIn, KEYBOARD_CONSOLE_IN_DEV_SIGNATURE) #define KEYBOARD_CONSOLE_IN_DEV_FROM_THIS(a) CR (a, KEYBOARD_CONSOLE_IN_DEV, ConIn, KEYBOARD_CONSOLE_IN_DEV_SIGNATURE)
@ -268,6 +270,19 @@ KeyGetchar (
IN OUT KEYBOARD_CONSOLE_IN_DEV *ConsoleIn IN OUT KEYBOARD_CONSOLE_IN_DEV *ConsoleIn
); );
/**
Process key notify.
@param Event Indicates the event that invoke this function.
@param Context Indicates the calling context.
**/
VOID
EFIAPI
KeyNotifyProcessHandler (
IN EFI_EVENT Event,
IN VOID *Context
);
/** /**
Perform 8042 controller and keyboard Initialization. Perform 8042 controller and keyboard Initialization.
If ExtendedVerification is TRUE, do additional test for If ExtendedVerification is TRUE, do additional test for