]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Nt32Pkg/WinNtGopDxe/WinNtGopInput.c
Add WinNtGop driver into Nt32Pkg
[mirror_edk2.git] / Nt32Pkg / WinNtGopDxe / WinNtGopInput.c
diff --git a/Nt32Pkg/WinNtGopDxe/WinNtGopInput.c b/Nt32Pkg/WinNtGopDxe/WinNtGopInput.c
new file mode 100644 (file)
index 0000000..a604dad
--- /dev/null
@@ -0,0 +1,377 @@
+/** @file\r
+\r
+Copyright (c) 2006, Intel Corporation\r
+All rights reserved. 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
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+Module Name:\r
+\r
+  WinNtGopInput.c\r
+\r
+Abstract:\r
+\r
+  This file produces the Simple Text In for an Gop window.\r
+\r
+  This stuff is linked at the hip to the Window, since the window\r
+  processing is done in a thread kicked off in WinNtGopImplementation.c\r
+\r
+  Since the window information is processed in an other thread we need\r
+  a keyboard Queue to pass data about. The Simple Text In code just\r
+  takes data off the Queue. The WinProc message loop takes keyboard input\r
+  and places it in the Queue.\r
+\r
+\r
+**/\r
+\r
+//\r
+// The package level header files this module uses\r
+//\r
+#include <Uefi.h>\r
+#include <WinNtDxe.h>\r
+//\r
+// The protocols, PPI and GUID defintions for this module\r
+//\r
+#include <Guid/EventGroup.h>\r
+#include <Protocol/WinNtIo.h>\r
+#include <Protocol/ComponentName.h>\r
+#include <Protocol/SimpleTextIn.h>\r
+#include <Protocol/DriverBinding.h>\r
+#include <Protocol/GraphicsOutput.h>\r
+//\r
+// The Library classes this module consumes\r
+//\r
+#include <Library/DebugLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+\r
+#include "WinNtGop.h"\r
+\r
+\r
+/**\r
+  TODO: Add function description\r
+\r
+  @param  Private               TODO: add argument description\r
+\r
+  @retval EFI_SUCCESS           TODO: Add description for return value\r
+\r
+**/\r
+EFI_STATUS\r
+GopPrivateCreateQ (\r
+  IN  GOP_PRIVATE_DATA    *Private\r
+  )\r
+{\r
+  Private->WinNtThunk->InitializeCriticalSection (&Private->QCriticalSection);\r
+\r
+  Private->Queue.Front  = 0;\r
+  Private->Queue.Rear   = MAX_Q - 1;\r
+  Private->Queue.Count  = 0;\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+  TODO: Add function description\r
+\r
+  @param  Private               TODO: add argument description\r
+\r
+  @retval EFI_SUCCESS           TODO: Add description for return value\r
+\r
+**/\r
+EFI_STATUS\r
+GopPrivateDestroyQ (\r
+  IN  GOP_PRIVATE_DATA    *Private\r
+  )\r
+{\r
+  Private->Queue.Count = 0;\r
+  Private->WinNtThunk->DeleteCriticalSection (&Private->QCriticalSection);\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+  TODO: Add function description\r
+\r
+  @param  Private               TODO: add argument description\r
+  @param  Key                   TODO: add argument description\r
+\r
+  @retval EFI_NOT_READY         TODO: Add description for return value\r
+  @retval EFI_SUCCESS           TODO: Add description for return value\r
+\r
+**/\r
+EFI_STATUS\r
+GopPrivateAddQ (\r
+  IN  GOP_PRIVATE_DATA    *Private,\r
+  IN  EFI_INPUT_KEY       Key\r
+  )\r
+{\r
+  Private->WinNtThunk->EnterCriticalSection (&Private->QCriticalSection);\r
+\r
+  if (Private->Queue.Count == MAX_Q) {\r
+    Private->WinNtThunk->LeaveCriticalSection (&Private->QCriticalSection);\r
+    return EFI_NOT_READY;\r
+  }\r
+\r
+  Private->Queue.Rear                   = (Private->Queue.Rear + 1) % MAX_Q;\r
+  Private->Queue.Q[Private->Queue.Rear] = Key;\r
+  Private->Queue.Count++;\r
+\r
+  Private->WinNtThunk->LeaveCriticalSection (&Private->QCriticalSection);\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+  TODO: Add function description\r
+\r
+  @param  Private               TODO: add argument description\r
+  @param  Key                   TODO: add argument description\r
+\r
+  @retval EFI_NOT_READY         TODO: Add description for return value\r
+  @retval EFI_SUCCESS           TODO: Add description for return value\r
+\r
+**/\r
+EFI_STATUS\r
+GopPrivateDeleteQ (\r
+  IN  GOP_PRIVATE_DATA    *Private,\r
+  OUT EFI_INPUT_KEY       *Key\r
+  )\r
+{\r
+  Private->WinNtThunk->EnterCriticalSection (&Private->QCriticalSection);\r
+\r
+  if (Private->Queue.Count == 0) {\r
+    Private->WinNtThunk->LeaveCriticalSection (&Private->QCriticalSection);\r
+    return EFI_NOT_READY;\r
+  }\r
+\r
+  *Key                  = Private->Queue.Q[Private->Queue.Front];\r
+  Private->Queue.Front  = (Private->Queue.Front + 1) % MAX_Q;\r
+  Private->Queue.Count--;\r
+\r
+  Private->WinNtThunk->LeaveCriticalSection (&Private->QCriticalSection);\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+  TODO: Add function description\r
+\r
+  @param  Private               TODO: add argument description\r
+\r
+  @retval EFI_NOT_READY         TODO: Add description for return value\r
+  @retval EFI_SUCCESS           TODO: Add description for return value\r
+\r
+**/\r
+EFI_STATUS\r
+GopPrivateCheckQ (\r
+  IN  GOP_PRIVATE_DATA    *Private\r
+  )\r
+{\r
+  if (Private->Queue.Count == 0) {\r
+    return EFI_NOT_READY;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+//\r
+// Simple Text In implementation.\r
+//\r
+\r
+\r
+/**\r
+  TODO: Add function description\r
+\r
+  @param  This                  TODO: add argument description\r
+  @param  ExtendedVerification  TODO: add argument description\r
+\r
+  @retval EFI_SUCCESS           TODO: Add description for return value\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtGopSimpleTextInReset (\r
+  IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL          *This,\r
+  IN BOOLEAN                              ExtendedVerification\r
+  )\r
+{\r
+  GOP_PRIVATE_DATA  *Private;\r
+  EFI_INPUT_KEY     Key;\r
+  EFI_TPL           OldTpl;\r
+\r
+  Private = GOP_PRIVATE_DATA_FROM_TEXT_IN_THIS (This);\r
+\r
+  //\r
+  // Enter critical section\r
+  //\r
+  OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
+\r
+  //\r
+  // A reset is draining the Queue\r
+  //\r
+  while (GopPrivateDeleteQ (Private, &Key) == EFI_SUCCESS)\r
+    ;\r
+\r
+  //\r
+  // Leave critical section and return\r
+  //\r
+  gBS->RestoreTPL (OldTpl);\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+  TODO: Add function description\r
+\r
+  @param  This                  TODO: add argument description\r
+  @param  Key                   TODO: add argument description\r
+\r
+  @return TODO: add return values\r
+\r
+**/\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+WinNtGopSimpleTextInReadKeyStroke (\r
+  IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL          *This,\r
+  OUT EFI_INPUT_KEY                       *Key\r
+  )\r
+{\r
+  GOP_PRIVATE_DATA  *Private;\r
+  EFI_STATUS        Status;\r
+  EFI_TPL           OldTpl;\r
+\r
+  Private = GOP_PRIVATE_DATA_FROM_TEXT_IN_THIS (This);\r
+\r
+  //\r
+  // Enter critical section\r
+  //\r
+  OldTpl  = gBS->RaiseTPL (TPL_NOTIFY);\r
+\r
+  Status  = GopPrivateCheckQ (Private);\r
+  if (!EFI_ERROR (Status)) {\r
+    //\r
+    // If a Key press exists try and read it.\r
+    //\r
+    Status = GopPrivateDeleteQ (Private, Key);\r
+  }\r
+\r
+  //\r
+  // Leave critical section and return\r
+  //\r
+  gBS->RestoreTPL (OldTpl);\r
+\r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+  TODO: Add function description\r
+\r
+  @param  Event                 TODO: add argument description\r
+  @param  Context               TODO: add argument description\r
+\r
+  @return TODO: add return values\r
+\r
+**/\r
+STATIC\r
+VOID\r
+EFIAPI\r
+WinNtGopSimpleTextInWaitForKey (\r
+  IN EFI_EVENT          Event,\r
+  IN VOID               *Context\r
+  )\r
+{\r
+  GOP_PRIVATE_DATA  *Private;\r
+  EFI_STATUS        Status;\r
+  EFI_TPL           OldTpl;\r
+\r
+  Private = (GOP_PRIVATE_DATA *) Context;\r
+\r
+  //\r
+  // Enter critical section\r
+  //\r
+  OldTpl  = gBS->RaiseTPL (TPL_NOTIFY);\r
+\r
+  Status  = GopPrivateCheckQ (Private);\r
+  if (!EFI_ERROR (Status)) {\r
+    //\r
+    // If a there is a key in the queue signal our event.\r
+    //\r
+    gBS->SignalEvent (Event);\r
+  } else {\r
+    //\r
+    // We need to sleep or NT will schedule this thread with such high\r
+    // priority that WinProc thread will never run and we will not see\r
+    // keyboard input. This Sleep makes the syste run 10x faster, so don't\r
+    // remove it.\r
+    //\r
+    Private->WinNtThunk->Sleep (1);\r
+  }\r
+\r
+  //\r
+  // Leave critical section and return\r
+  //\r
+  gBS->RestoreTPL (OldTpl);\r
+}\r
+\r
+\r
+/**\r
+  TODO: Add function description\r
+\r
+  @param  Private               TODO: add argument description\r
+\r
+  @return TODO: add return values\r
+\r
+**/\r
+EFI_STATUS\r
+WinNtGopInitializeSimpleTextInForWindow (\r
+  IN  GOP_PRIVATE_DATA    *Private\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  GopPrivateCreateQ (Private);\r
+\r
+  //\r
+  // Initialize Simple Text In protoocol\r
+  //\r
+  Private->SimpleTextIn.Reset         = WinNtGopSimpleTextInReset;\r
+  Private->SimpleTextIn.ReadKeyStroke = WinNtGopSimpleTextInReadKeyStroke;\r
+\r
+  Status = gBS->CreateEvent (\r
+                  EVT_NOTIFY_WAIT,\r
+                  TPL_NOTIFY,\r
+                  WinNtGopSimpleTextInWaitForKey,\r
+                  Private,\r
+                  &Private->SimpleTextIn.WaitForKey\r
+                  );\r
+\r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+  TODO: Add function description\r
+\r
+  @param  Private               TODO: add argument description\r
+\r
+  @retval EFI_SUCCESS           TODO: Add description for return value\r
+\r
+**/\r
+EFI_STATUS\r
+WinNtGopDestroySimpleTextInForWindow (\r
+  IN  GOP_PRIVATE_DATA    *Private\r
+  )\r
+{\r
+  GopPrivateDestroyQ (Private);\r
+  return EFI_SUCCESS;\r
+}\r