USB Keyboard Driver that manages USB keyboard and produces Simple Text Input\r
Protocol and Simple Text Input Ex Protocol.\r
\r
-Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>\r
This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
which accompanies this distribution. The full text of the license may be found at\r
goto ErrorExit;\r
}\r
\r
+ Status = gBS->CreateEvent (\r
+ EVT_NOTIFY_SIGNAL,\r
+ TPL_CALLBACK,\r
+ KeyNotifyProcessHandler,\r
+ UsbKeyboardDevice,\r
+ &UsbKeyboardDevice->KeyNotifyProcessEvent\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ goto ErrorExit;\r
+ }\r
+\r
//\r
// Install Simple Text Input Protocol and Simple Text Input Ex Protocol\r
// for the USB keyboard device.\r
if (UsbKeyboardDevice->SimpleInputEx.WaitForKeyEx != NULL) {\r
gBS->CloseEvent (UsbKeyboardDevice->SimpleInputEx.WaitForKeyEx);\r
}\r
+ if (UsbKeyboardDevice->KeyNotifyProcessEvent != NULL) {\r
+ gBS->CloseEvent (UsbKeyboardDevice->KeyNotifyProcessEvent);\r
+ }\r
if (UsbKeyboardDevice->KeyboardLayoutEvent != NULL) {\r
ReleaseKeyboardLayoutResources (UsbKeyboardDevice);\r
gBS->CloseEvent (UsbKeyboardDevice->KeyboardLayoutEvent);\r
gBS->CloseEvent (UsbKeyboardDevice->DelayedRecoveryEvent);\r
gBS->CloseEvent (UsbKeyboardDevice->SimpleInput.WaitForKey);\r
gBS->CloseEvent (UsbKeyboardDevice->SimpleInputEx.WaitForKeyEx);\r
+ gBS->CloseEvent (UsbKeyboardDevice->KeyNotifyProcessEvent);\r
KbdFreeNotifyList (&UsbKeyboardDevice->NotifyList);\r
\r
ReleaseKeyboardLayoutResources (UsbKeyboardDevice);\r
\r
DestroyQueue (&UsbKeyboardDevice->UsbKeyQueue);\r
DestroyQueue (&UsbKeyboardDevice->EfiKeyQueue);\r
+ DestroyQueue (&UsbKeyboardDevice->EfiKeyQueueForNotify);\r
\r
FreePool (UsbKeyboardDevice);\r
\r
//\r
InitQueue (&UsbKeyboardDevice->UsbKeyQueue, sizeof (USB_KEY));\r
InitQueue (&UsbKeyboardDevice->EfiKeyQueue, sizeof (EFI_KEY_DATA));\r
+ InitQueue (&UsbKeyboardDevice->EfiKeyQueueForNotify, sizeof (EFI_KEY_DATA));\r
\r
return EFI_SUCCESS;\r
}\r
return EFI_INVALID_PARAMETER;\r
}\r
\r
+/**\r
+ Process key notify.\r
+\r
+ @param Event Indicates the event that invoke this function.\r
+ @param Context Indicates the calling context.\r
+**/\r
+VOID\r
+EFIAPI\r
+KeyNotifyProcessHandler (\r
+ IN EFI_EVENT Event,\r
+ IN VOID *Context\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ USB_KB_DEV *UsbKeyboardDevice;\r
+ EFI_KEY_DATA KeyData;\r
+ LIST_ENTRY *Link;\r
+ LIST_ENTRY *NotifyList;\r
+ KEYBOARD_CONSOLE_IN_EX_NOTIFY *CurrentNotify;\r
+ EFI_TPL OldTpl;\r
+\r
+ UsbKeyboardDevice = (USB_KB_DEV *) Context;\r
+\r
+ //\r
+ // Invoke notification functions.\r
+ //\r
+ NotifyList = &UsbKeyboardDevice->NotifyList;\r
+ while (TRUE) {\r
+ //\r
+ // Enter critical section\r
+ // \r
+ OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
+ Status = Dequeue (&UsbKeyboardDevice->EfiKeyQueueForNotify, &KeyData, sizeof (KeyData));\r
+ //\r
+ // Leave critical section\r
+ //\r
+ gBS->RestoreTPL (OldTpl);\r
+ if (EFI_ERROR (Status)) {\r
+ break;\r
+ }\r
+ for (Link = GetFirstNode (NotifyList); !IsNull (NotifyList, Link); Link = GetNextNode (NotifyList, Link)) {\r
+ CurrentNotify = CR (Link, KEYBOARD_CONSOLE_IN_EX_NOTIFY, NotifyEntry, USB_KB_CONSOLE_IN_EX_NOTIFY_SIGNATURE);\r
+ if (IsKeyRegistered (&CurrentNotify->KeyData, &KeyData)) {\r
+ CurrentNotify->KeyNotificationFn (&KeyData);\r
+ }\r
+ }\r
+ }\r
+}\r
+\r
/** @file\r
Header file for USB Keyboard Driver's Data Structures.\r
\r
-Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>\r
This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
which accompanies this distribution. The full text of the license may be found at\r
\r
USB_SIMPLE_QUEUE UsbKeyQueue;\r
USB_SIMPLE_QUEUE EfiKeyQueue;\r
+ USB_SIMPLE_QUEUE EfiKeyQueueForNotify;\r
BOOLEAN CtrlOn;\r
BOOLEAN AltOn;\r
BOOLEAN ShiftOn;\r
// Notification function list\r
//\r
LIST_ENTRY NotifyList;\r
+ EFI_EVENT KeyNotifyProcessEvent;\r
\r
//\r
// Non-spacing key list\r
IN VOID *Context\r
);\r
\r
+/**\r
+ Process key notify.\r
+\r
+ @param Event Indicates the event that invoke this function.\r
+ @param Context Indicates the calling context.\r
+**/\r
+VOID\r
+EFIAPI\r
+KeyNotifyProcessHandler (\r
+ IN EFI_EVENT Event,\r
+ IN VOID *Context\r
+ );\r
+\r
#endif\r
\r
\r
InitQueue (&UsbKeyboardDevice->UsbKeyQueue, sizeof (USB_KEY));\r
InitQueue (&UsbKeyboardDevice->EfiKeyQueue, sizeof (EFI_KEY_DATA));\r
+ InitQueue (&UsbKeyboardDevice->EfiKeyQueueForNotify, sizeof (EFI_KEY_DATA));\r
\r
//\r
// Use the config out of the descriptor\r
KeyData->KeyState.KeyToggleState |= EFI_KEY_STATE_EXPOSED;\r
}\r
//\r
- // Invoke notification functions if the key is registered.\r
+ // Signal KeyNotify process event if this key pressed matches any key registered.\r
//\r
NotifyList = &UsbKeyboardDevice->NotifyList;\r
for (Link = GetFirstNode (NotifyList); !IsNull (NotifyList, Link); Link = GetNextNode (NotifyList, Link)) {\r
CurrentNotify = CR (Link, KEYBOARD_CONSOLE_IN_EX_NOTIFY, NotifyEntry, USB_KB_CONSOLE_IN_EX_NOTIFY_SIGNATURE);\r
if (IsKeyRegistered (&CurrentNotify->KeyData, KeyData)) {\r
- CurrentNotify->KeyNotificationFn (KeyData);\r
+ //\r
+ // The key notification function needs to run at TPL_CALLBACK\r
+ // while current TPL is TPL_NOTIFY. It will be invoked in\r
+ // KeyNotifyProcessHandler() which runs at TPL_CALLBACK.\r
+ //\r
+ Enqueue (&UsbKeyboardDevice->EfiKeyQueueForNotify, KeyData, sizeof (*KeyData));\r
+ gBS->SignalEvent (UsbKeyboardDevice->KeyNotifyProcessEvent);\r
}\r
}\r
\r
return EFI_SUCCESS;\r
}\r
\r
-\r
/**\r
Create the queue.\r
\r