]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Console/TerminalDxe/TerminalConIn.c
Remove reference to PCDs of status code value. Use macros introduced in PI1.2 instead.
[mirror_edk2.git] / MdeModulePkg / Universal / Console / TerminalDxe / TerminalConIn.c
index 4bb2e77d01504efafd8e2b49885e20d6e5ed7cd2..c6d4ecd0818dd683bb28426597ff27c50686b1f1 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Implementation for EFI_SIMPLE_TEXT_INPUT_PROTOCOL protocol.\r
 \r
-Copyright (c) 2006 - 2008, Intel Corporation. <BR>\r
+Copyright (c) 2006 - 2010, Intel Corporation. <BR>\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
@@ -113,23 +113,23 @@ TerminalConInReset (
   //\r
   REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
     EFI_PROGRESS_CODE,\r
-    PcdGet32 (PcdStatusCodeValueRemoteConsoleReset),\r
+    (EFI_PERIPHERAL_REMOTE_CONSOLE | EFI_P_PC_RESET),\r
     TerminalDevice->DevicePath\r
     );\r
 \r
   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
       EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
-      PcdGet32 (PcdStatusCodeValueRemoteConsoleError),\r
+      (EFI_PERIPHERAL_REMOTE_CONSOLE | EFI_P_EC_CONTROLLER_ERROR),\r
       TerminalDevice->DevicePath\r
       );\r
   }\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
@@ -435,7 +426,6 @@ TerminalConInRegisterKeyNotify (
   @retval EFI_SUCCESS              The notification function was unregistered\r
                                    successfully.\r
   @retval EFI_INVALID_PARAMETER    The NotificationHandle is invalid.\r
-  @retval EFI_NOT_FOUND            Can not find the matching entry in database.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -445,28 +435,19 @@ 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
+\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 (((TERMINAL_CONSOLE_IN_EX_NOTIFY *) NotificationHandle)->Signature != TERMINAL_CONSOLE_IN_EX_NOTIFY_SIGNATURE) {\r
     return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
+  } \r
+  \r
   TerminalDevice = TERMINAL_CON_IN_EX_DEV_FROM_THIS (This);\r
 \r
   NotifyList = &TerminalDevice->NotifyList;\r
@@ -482,24 +463,21 @@ 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
   }\r
 \r
-  return EFI_NOT_FOUND;\r
+  //\r
+  // Can not find the matching entry in database.\r
+  //\r
+  return EFI_INVALID_PARAMETER;\r
 }\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
@@ -658,7 +636,7 @@ TerminalConInCheckForKey (
       if (Status == EFI_DEVICE_ERROR) {\r
         REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
           EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
-          PcdGet32 (PcdStatusCodeValueRemoteConsoleInputError),\r
+          (EFI_PERIPHERAL_REMOTE_CONSOLE | EFI_P_EC_INPUT_ERROR),\r
           TerminalDevice->DevicePath\r
           );\r
       }\r
@@ -746,7 +724,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 +733,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 +758,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 +768,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 +789,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 +813,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 +843,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 +853,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 +878,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 +890,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 +911,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 +935,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 +965,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 +976,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 +1001,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 +1012,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 +1033,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 +1057,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 +1084,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 +1096,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 +1107,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 +1155,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
@@ -1185,6 +1168,10 @@ UnicodeToEfiKeyFlushState (
   There is one special input sequence that will force the system to reset.\r
   This is ESC R ESC r ESC R.\r
 \r
+  Note: current implementation support terminal types include: PC ANSI, VT100+/VTUTF8, VT100. \r
+        The table below is not same with UEFI Spec 2.3 Appendix B Table 201(not support ANSI X3.64 /\r
+        DEC VT200-500 and extra support PC ANSI, VT100)since UEFI Table 201 is just an example.\r
+        \r
   Symbols used in table below\r
   ===========================\r
     ESC = 0x1B\r
@@ -1255,7 +1242,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
@@ -1359,14 +1346,14 @@ UnicodeToEfiKey (
         if (TerminalDevice->ResetState == RESET_STATE_DEFAULT) {\r
           TerminalDevice->ResetState = RESET_STATE_ESC_R;\r
           SetDefaultResetState = FALSE;\r
-        } else if (TerminalDevice->ResetState == RESET_STATE_ESC_R_ESC_r) {\r
+        } else if (TerminalDevice->ResetState == RESET_STATE_ESC_R_ESC_R) {\r
           gRT->ResetSystem (EfiResetWarm, EFI_SUCCESS, 0, NULL);\r
         }\r
         Key.ScanCode = SCAN_NULL;\r
         break;\r
       case 'r':\r
         if (TerminalDevice->ResetState == RESET_STATE_ESC_R) {\r
-          TerminalDevice->ResetState = RESET_STATE_ESC_R_ESC_r;\r
+          TerminalDevice->ResetState = RESET_STATE_ESC_R_ESC_R;\r
           SetDefaultResetState = FALSE;\r
         }\r
         Key.ScanCode = SCAN_NULL;\r