]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Console/TerminalDxe/TerminalConIn.c
Retired gSimpleTextInExNotifyGuid, used local structure address to be notify handle.
[mirror_edk2.git] / MdeModulePkg / Universal / Console / TerminalDxe / TerminalConIn.c
index 4bb2e77d01504efafd8e2b49885e20d6e5ed7cd2..ae4ea818deb95e63610fe26e5d57ac707c65ee82 100644 (file)
@@ -120,11 +120,11 @@ TerminalConInReset (
   Status = TerminalDevice->SerialIo->Reset (TerminalDevice->SerialIo);\r
 \r
   //\r
-  // clear all the internal buffer for keys\r
+  // Make all the internal buffer empty for keys\r
   //\r
-  InitializeRawFiFo (TerminalDevice);\r
-  InitializeUnicodeFiFo (TerminalDevice);\r
-  InitializeEfiKeyFiFo (TerminalDevice);\r
+  TerminalDevice->RawFiFo->Head     = TerminalDevice->RawFiFo->Tail;\r
+  TerminalDevice->UnicodeFiFo->Head = TerminalDevice->UnicodeFiFo->Tail;\r
+  TerminalDevice->EfiKeyFiFo->Head  = TerminalDevice->EfiKeyFiFo->Tail;\r
 \r
   if (EFI_ERROR (Status)) {\r
     REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
@@ -179,7 +179,7 @@ TerminalConInReadKeyStroke (
 \r
 /**\r
   Check if the key already has been registered.\r
-  \r
+\r
   If both RegsiteredData and InputData is NULL, then ASSERT().\r
 \r
   @param  RegsiteredData           A pointer to a buffer that is filled in with the\r
@@ -365,7 +365,6 @@ TerminalConInRegisterKeyNotify (
   OUT EFI_HANDLE                        *NotifyHandle\r
   )\r
 {\r
-  EFI_STATUS                      Status;\r
   TERMINAL_DEV                    *TerminalDevice;\r
   TERMINAL_CONSOLE_IN_EX_NOTIFY   *NewNotify;\r
   LIST_ENTRY                      *Link;\r
@@ -407,18 +406,10 @@ TerminalConInRegisterKeyNotify (
 \r
   NewNotify->Signature         = TERMINAL_CONSOLE_IN_EX_NOTIFY_SIGNATURE;\r
   NewNotify->KeyNotificationFn = KeyNotificationFunction;\r
+  NewNotify->NotifyHandle      = (EFI_HANDLE) NewNotify;\r
   CopyMem (&NewNotify->KeyData, KeyData, sizeof (KeyData));\r
   InsertTailList (&TerminalDevice->NotifyList, &NewNotify->NotifyEntry);\r
-  //\r
-  // Use gSimpleTextInExNotifyGuid to get a valid EFI_HANDLE\r
-  //\r
-  Status = gBS->InstallMultipleProtocolInterfaces (\r
-                  &NewNotify->NotifyHandle,\r
-                  &gSimpleTextInExNotifyGuid,\r
-                  NULL,\r
-                  NULL\r
-                  );\r
-  ASSERT_EFI_ERROR (Status);\r
+\r
   *NotifyHandle                = NewNotify->NotifyHandle;\r
 \r
   return EFI_SUCCESS;\r
@@ -445,25 +436,12 @@ TerminalConInUnregisterKeyNotify (
   IN EFI_HANDLE                         NotificationHandle\r
   )\r
 {\r
-  EFI_STATUS                      Status;\r
   TERMINAL_DEV                    *TerminalDevice;\r
   LIST_ENTRY                      *Link;\r
   TERMINAL_CONSOLE_IN_EX_NOTIFY   *CurrentNotify;\r
   LIST_ENTRY                      *NotifyList;\r
-  \r
-  if (NotificationHandle == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
 \r
-  Status = gBS->OpenProtocol (\r
-                  NotificationHandle,\r
-                  &gSimpleTextInExNotifyGuid,\r
-                  NULL,\r
-                  NULL,\r
-                  NULL,\r
-                  EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
-                  );\r
-  if (EFI_ERROR (Status)) {\r
+  if (NotificationHandle == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -482,13 +460,7 @@ TerminalConInUnregisterKeyNotify (
       // Remove the notification function from NotifyList and free resources\r
       //\r
       RemoveEntryList (&CurrentNotify->NotifyEntry);\r
-      Status = gBS->UninstallMultipleProtocolInterfaces (\r
-                      CurrentNotify->NotifyHandle,\r
-                      &gSimpleTextInExNotifyGuid,\r
-                      NULL,\r
-                      NULL\r
-                      );\r
-      ASSERT_EFI_ERROR (Status);\r
+\r
       gBS->FreePool (CurrentNotify);\r
       return EFI_SUCCESS;\r
     }\r
@@ -498,8 +470,8 @@ TerminalConInUnregisterKeyNotify (
 }\r
 \r
 /**\r
-  Translate raw data into Unicode (according to different encode), and \r
-  translate Unicode into key information. (according to different standard). \r
+  Translate raw data into Unicode (according to different encode), and\r
+  translate Unicode into key information. (according to different standard).\r
 \r
   @param  TerminalDevice       Terminal driver private structure.\r
 \r
@@ -746,7 +718,7 @@ RawFiFoInsertOneKey (
 {\r
   UINT8 Tail;\r
 \r
-  Tail = TerminalDevice->RawFiFo.Tail;\r
+  Tail = TerminalDevice->RawFiFo->Tail;\r
 \r
   if (IsRawFiFoFull (TerminalDevice)) {\r
     //\r
@@ -755,9 +727,9 @@ RawFiFoInsertOneKey (
     return FALSE;\r
   }\r
 \r
-  TerminalDevice->RawFiFo.Data[Tail]  = Input;\r
+  TerminalDevice->RawFiFo->Data[Tail]  = Input;\r
 \r
-  TerminalDevice->RawFiFo.Tail        = (UINT8) ((Tail + 1) % (RAW_FIFO_MAX_NUMBER + 1));\r
+  TerminalDevice->RawFiFo->Tail        = (UINT8) ((Tail + 1) % (RAW_FIFO_MAX_NUMBER + 1));\r
 \r
   return TRUE;\r
 }\r
@@ -780,7 +752,7 @@ RawFiFoRemoveOneKey (
 {\r
   UINT8 Head;\r
 \r
-  Head = TerminalDevice->RawFiFo.Head;\r
+  Head = TerminalDevice->RawFiFo->Head;\r
 \r
   if (IsRawFiFoEmpty (TerminalDevice)) {\r
     //\r
@@ -790,9 +762,9 @@ RawFiFoRemoveOneKey (
     return FALSE;\r
   }\r
 \r
-  *Output                       = TerminalDevice->RawFiFo.Data[Head];\r
+  *Output                       = TerminalDevice->RawFiFo->Data[Head];\r
 \r
-  TerminalDevice->RawFiFo.Head  = (UINT8) ((Head + 1) % (RAW_FIFO_MAX_NUMBER + 1));\r
+  TerminalDevice->RawFiFo->Head  = (UINT8) ((Head + 1) % (RAW_FIFO_MAX_NUMBER + 1));\r
 \r
   return TRUE;\r
 }\r
@@ -811,7 +783,7 @@ IsRawFiFoEmpty (
   TERMINAL_DEV  *TerminalDevice\r
   )\r
 {\r
-  if (TerminalDevice->RawFiFo.Head == TerminalDevice->RawFiFo.Tail) {\r
+  if (TerminalDevice->RawFiFo->Head == TerminalDevice->RawFiFo->Tail) {\r
     return TRUE;\r
   } else {\r
     return FALSE;\r
@@ -835,8 +807,8 @@ IsRawFiFoFull (
   UINT8 Tail;\r
   UINT8 Head;\r
 \r
-  Tail  = TerminalDevice->RawFiFo.Tail;\r
-  Head  = TerminalDevice->RawFiFo.Head;\r
+  Tail  = TerminalDevice->RawFiFo->Tail;\r
+  Head  = TerminalDevice->RawFiFo->Head;\r
 \r
   if (((Tail + 1) % (RAW_FIFO_MAX_NUMBER + 1)) == Head) {\r
 \r
@@ -865,7 +837,8 @@ EfiKeyFiFoInsertOneKey (
 {\r
   UINT8 Tail;\r
 \r
-  Tail = TerminalDevice->EfiKeyFiFo.Tail;\r
+  Tail = TerminalDevice->EfiKeyFiFo->Tail;\r
+  ASSERT (Tail < FIFO_MAX_NUMBER + 1);\r
 \r
   if (IsEfiKeyFiFoFull (TerminalDevice)) {\r
     //\r
@@ -874,9 +847,9 @@ EfiKeyFiFoInsertOneKey (
     return FALSE;\r
   }\r
 \r
-  TerminalDevice->EfiKeyFiFo.Data[Tail] = Key;\r
+  TerminalDevice->EfiKeyFiFo->Data[Tail] = Key;\r
 \r
-  TerminalDevice->EfiKeyFiFo.Tail       = (UINT8) ((Tail + 1) % (FIFO_MAX_NUMBER + 1));\r
+  TerminalDevice->EfiKeyFiFo->Tail       = (UINT8) ((Tail + 1) % (FIFO_MAX_NUMBER + 1));\r
 \r
   return TRUE;\r
 }\r
@@ -899,7 +872,8 @@ EfiKeyFiFoRemoveOneKey (
 {\r
   UINT8 Head;\r
 \r
-  Head = TerminalDevice->EfiKeyFiFo.Head;\r
+  Head = TerminalDevice->EfiKeyFiFo->Head;\r
+  ASSERT (Head < FIFO_MAX_NUMBER + 1);\r
 \r
   if (IsEfiKeyFiFoEmpty (TerminalDevice)) {\r
     //\r
@@ -910,9 +884,9 @@ EfiKeyFiFoRemoveOneKey (
     return FALSE;\r
   }\r
 \r
-  *Output                         = TerminalDevice->EfiKeyFiFo.Data[Head];\r
+  *Output                         = TerminalDevice->EfiKeyFiFo->Data[Head];\r
 \r
-  TerminalDevice->EfiKeyFiFo.Head = (UINT8) ((Head + 1) % (FIFO_MAX_NUMBER + 1));\r
+  TerminalDevice->EfiKeyFiFo->Head = (UINT8) ((Head + 1) % (FIFO_MAX_NUMBER + 1));\r
 \r
   return TRUE;\r
 }\r
@@ -931,7 +905,7 @@ IsEfiKeyFiFoEmpty (
   TERMINAL_DEV  *TerminalDevice\r
   )\r
 {\r
-  if (TerminalDevice->EfiKeyFiFo.Head == TerminalDevice->EfiKeyFiFo.Tail) {\r
+  if (TerminalDevice->EfiKeyFiFo->Head == TerminalDevice->EfiKeyFiFo->Tail) {\r
     return TRUE;\r
   } else {\r
     return FALSE;\r
@@ -955,8 +929,8 @@ IsEfiKeyFiFoFull (
   UINT8 Tail;\r
   UINT8 Head;\r
 \r
-  Tail  = TerminalDevice->EfiKeyFiFo.Tail;\r
-  Head  = TerminalDevice->EfiKeyFiFo.Head;\r
+  Tail  = TerminalDevice->EfiKeyFiFo->Tail;\r
+  Head  = TerminalDevice->EfiKeyFiFo->Head;\r
 \r
   if (((Tail + 1) % (FIFO_MAX_NUMBER + 1)) == Head) {\r
 \r
@@ -985,7 +959,9 @@ UnicodeFiFoInsertOneKey (
 {\r
   UINT8 Tail;\r
 \r
-  Tail = TerminalDevice->UnicodeFiFo.Tail;\r
+  Tail = TerminalDevice->UnicodeFiFo->Tail;\r
+  ASSERT (Tail < FIFO_MAX_NUMBER + 1);\r
+\r
 \r
   if (IsUnicodeFiFoFull (TerminalDevice)) {\r
     //\r
@@ -994,9 +970,9 @@ UnicodeFiFoInsertOneKey (
     return FALSE;\r
   }\r
 \r
-  TerminalDevice->UnicodeFiFo.Data[Tail]  = Input;\r
+  TerminalDevice->UnicodeFiFo->Data[Tail]  = Input;\r
 \r
-  TerminalDevice->UnicodeFiFo.Tail        = (UINT8) ((Tail + 1) % (FIFO_MAX_NUMBER + 1));\r
+  TerminalDevice->UnicodeFiFo->Tail        = (UINT8) ((Tail + 1) % (FIFO_MAX_NUMBER + 1));\r
 \r
   return TRUE;\r
 }\r
@@ -1019,7 +995,8 @@ UnicodeFiFoRemoveOneKey (
 {\r
   UINT8 Head;\r
 \r
-  Head = TerminalDevice->UnicodeFiFo.Head;\r
+  Head = TerminalDevice->UnicodeFiFo->Head;\r
+  ASSERT (Head < FIFO_MAX_NUMBER + 1);\r
 \r
   if (IsUnicodeFiFoEmpty (TerminalDevice)) {\r
     //\r
@@ -1029,9 +1006,9 @@ UnicodeFiFoRemoveOneKey (
     return FALSE;\r
   }\r
 \r
-  *Output = TerminalDevice->UnicodeFiFo.Data[Head];\r
+  *Output = TerminalDevice->UnicodeFiFo->Data[Head];\r
 \r
-  TerminalDevice->UnicodeFiFo.Head = (UINT8) ((Head + 1) % (FIFO_MAX_NUMBER + 1));\r
+  TerminalDevice->UnicodeFiFo->Head = (UINT8) ((Head + 1) % (FIFO_MAX_NUMBER + 1));\r
 \r
   return TRUE;\r
 }\r
@@ -1050,7 +1027,7 @@ IsUnicodeFiFoEmpty (
   TERMINAL_DEV  *TerminalDevice\r
   )\r
 {\r
-  if (TerminalDevice->UnicodeFiFo.Head == TerminalDevice->UnicodeFiFo.Tail) {\r
+  if (TerminalDevice->UnicodeFiFo->Head == TerminalDevice->UnicodeFiFo->Tail) {\r
     return TRUE;\r
   } else {\r
     return FALSE;\r
@@ -1074,8 +1051,8 @@ IsUnicodeFiFoFull (
   UINT8 Tail;\r
   UINT8 Head;\r
 \r
-  Tail  = TerminalDevice->UnicodeFiFo.Tail;\r
-  Head  = TerminalDevice->UnicodeFiFo.Head;\r
+  Tail  = TerminalDevice->UnicodeFiFo->Tail;\r
+  Head  = TerminalDevice->UnicodeFiFo->Head;\r
 \r
   if (((Tail + 1) % (FIFO_MAX_NUMBER + 1)) == Head) {\r
 \r
@@ -1101,8 +1078,8 @@ UnicodeFiFoGetKeyCount (
   UINT8 Tail;\r
   UINT8 Head;\r
 \r
-  Tail  = TerminalDevice->UnicodeFiFo.Tail;\r
-  Head  = TerminalDevice->UnicodeFiFo.Head;\r
+  Tail  = TerminalDevice->UnicodeFiFo->Tail;\r
+  Head  = TerminalDevice->UnicodeFiFo->Head;\r
 \r
   if (Tail >= Head) {\r
     return (UINT8) (Tail - Head);\r
@@ -1113,7 +1090,7 @@ UnicodeFiFoGetKeyCount (
 \r
 /**\r
   Update the Unicode characters from a terminal input device into EFI Keys FIFO.\r
-  \r
+\r
   @param TerminalDevice   The terminal device to use to translate raw input into EFI Keys\r
 \r
 **/\r
@@ -1124,9 +1101,9 @@ UnicodeToEfiKeyFlushState (
 {\r
   EFI_INPUT_KEY Key;\r
   UINT32        InputState;\r
-  \r
+\r
   InputState = TerminalDevice->InputState;\r
-  \r
+\r
   if ((InputState & INPUT_STATE_ESC) != 0) {\r
     Key.ScanCode    = SCAN_ESC;\r
     Key.UnicodeChar = 0;\r
@@ -1172,8 +1149,8 @@ UnicodeToEfiKeyFlushState (
 \r
 /**\r
   Converts a stream of Unicode characters from a terminal input device into EFI Keys that\r
-  can be read through the Simple Input Protocol. \r
-  \r
+  can be read through the Simple Input Protocol.\r
+\r
   The table below shows the keyboard input mappings that this function supports.\r
   If the ESC sequence listed in one of the columns is presented, then it is translated\r
   into the corresponding EFI Scan Code.  If a matching sequence is not found, then the raw\r
@@ -1255,7 +1232,7 @@ UnicodeToEfiKey (
 \r
     if (TerminalDevice->InputState != INPUT_STATE_DEFAULT) {\r
       //\r
-      // Check to see if the 2 second timer has expired\r
+      // Check to see if the 2 seconds timer has expired\r
       //\r
       TimerStatus = gBS->CheckEvent (TerminalDevice->TwoSecondTimeOut);\r
       if (!EFI_ERROR (TimerStatus)) {\r