]> git.proxmox.com Git - mirror_edk2.git/commitdiff
SourceLevelDebugPkg: Use CPU Local APIC timer to handle timeout.
authorJeff Fan <jeff.fan@intel.com>
Wed, 1 Apr 2015 07:51:15 +0000 (07:51 +0000)
committervanjeff <vanjeff@Edk2>
Wed, 1 Apr 2015 07:51:15 +0000 (07:51 +0000)
Use CPU Local APIC timer to handle timeout when read data from debug port, instead of the TimerLib in Debug Communication lib instances.
It could remove much duplicated code in Debug Communication Lib instances.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan <jeff.fan@intel.com>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@17089 6f19259b-4bc3-4df7-8a09-765794883524

17 files changed:
SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugAgent.c
SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugAgent.h
SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugTimer.c
SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugTimer.h
SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgent/DxeDebugAgentLib.c
SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgent/SerialIo.c
SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgent/SecPeiDebugAgentLib.c
SourceLevelDebugPkg/Library/DebugAgent/SmmDebugAgent/SmmDebugAgentLib.c
SourceLevelDebugPkg/Library/DebugCommunicationLibSerialPort/DebugCommunicationLibSerialPort.c
SourceLevelDebugPkg/Library/DebugCommunicationLibSerialPort/DebugCommunicationLibSerialPort.inf
SourceLevelDebugPkg/Library/DebugCommunicationLibUsb/DebugCommunicationLibUsb.c
SourceLevelDebugPkg/Library/DebugCommunicationLibUsb/DebugCommunicationLibUsb.inf
SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Common.c
SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Dxe.inf
SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Internal.h
SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Pei.inf
SourceLevelDebugPkg/Library/DebugCommunicationLibUsb3/DebugCommunicationLibUsb3Transfer.c

index 3bb9921cc36e4c6969188512434ece64d438c462..fc40112b54e9285fe7e381f918ed24d2a4073023 100644 (file)
@@ -380,10 +380,92 @@ UpdateMailboxContent (
                                               - CalculateSum8 ((UINT8 *)&Value, sizeof(UINT8));\r
     Mailbox->HostSequenceNo = (UINT8) Value;\r
     break;\r
+  case DEBUG_MAILBOX_DEBUG_TIMER_FREQUENCY:\r
+    Mailbox->ToBeCheckSum = Mailbox->CheckSum + CalculateSum8 ((UINT8 *)&Mailbox->HostSequenceNo, sizeof(UINT32))\r
+                                              - CalculateSum8 ((UINT8 *)&Value, sizeof(UINT32));\r
+    Mailbox->DebugTimerFrequency = (UINT32) Value;\r
+    break;\r
   }\r
   UpdateMailboxChecksum (Mailbox);\r
   ReleaseMpSpinLock (&mDebugMpContext.MailboxSpinLock);\r
 }\r
+\r
+/**\r
+  Read data from debug device and save the data in buffer.\r
+\r
+  Reads NumberOfBytes data bytes from a debug device into the buffer\r
+  specified by Buffer. The number of bytes actually read is returned.\r
+  If the return value is less than NumberOfBytes, then the rest operation failed.\r
+  If NumberOfBytes is zero, then return 0.\r
+\r
+  @param  Handle           Debug port handle.\r
+  @param  Buffer           Pointer to the data buffer to store the data read from the debug device.\r
+  @param  NumberOfBytes    Number of bytes which will be read.\r
+  @param  Timeout          Timeout value for reading from debug device. It unit is Microsecond.\r
+\r
+  @retval 0                Read data failed, no data is to be read.\r
+  @retval >0               Actual number of bytes read from debug device.\r
+\r
+**/\r
+UINTN\r
+DebugAgentReadBuffer (\r
+  IN DEBUG_PORT_HANDLE     Handle,\r
+  IN UINT8                 *Buffer,\r
+  IN UINTN                 NumberOfBytes,\r
+  IN UINTN                 Timeout\r
+  )\r
+{\r
+  UINTN                    Index;\r
+  UINT32                   Begin;\r
+  UINT32                   TimeoutTicker;\r
+  UINT32                   TimerRound;\r
+  UINT32                   TimerFrequency;\r
+  UINT32                   TimerCycle;\r
+  \r
+  Begin         = 0;\r
+  TimeoutTicker = 0;  \r
+  TimerRound    = 0;\r
+  TimerFrequency = GetMailboxPointer()->DebugTimerFrequency;\r
+  TimerCycle = GetApicTimerInitCount ();\r
+\r
+  if (Timeout != 0) {\r
+    Begin = GetApicTimerCurrentCount ();\r
+    TimeoutTicker = (UINT32) DivU64x32 (\r
+                      MultU64x64 (\r
+                        TimerFrequency,\r
+                        Timeout\r
+                        ),\r
+                      1000000u\r
+                      );\r
+    TimerRound = (UINT32) DivU64x32Remainder (TimeoutTicker,  TimerCycle / 2, &TimeoutTicker);\r
+  }\r
+  Index = 0;\r
+  while (Index < NumberOfBytes) {\r
+    if (DebugPortPollBuffer (Handle)) {\r
+      DebugPortReadBuffer (Handle, Buffer + Index, 1, 0);\r
+      Index ++; \r
+      continue;\r
+    }\r
+    if (Timeout != 0) {\r
+      if (TimerRound == 0) {\r
+        if (IsDebugTimerTimeout (TimerCycle, Begin, TimeoutTicker)) {\r
+          //\r
+          // If time out occurs.\r
+          //\r
+          return 0;\r
+        }\r
+      } else {\r
+        if (IsDebugTimerTimeout (TimerCycle, Begin, TimerCycle / 2)) {\r
+          TimerRound --;\r
+          Begin = GetApicTimerCurrentCount ();\r
+        }\r
+      }\r
+    }\r
+  }\r
+\r
+  return Index;\r
+}\r
+\r
 /**\r
   Set debug flag in mailbox.\r
 \r
@@ -589,7 +671,7 @@ ReadRemainingBreakPacket (
   //\r
   // Has received start symbol, try to read the rest part\r
   //\r
-  if (DebugPortReadBuffer (Handle, (UINT8 *)DebugHeader + OFFSET_OF (DEBUG_PACKET_HEADER, Command), sizeof (DEBUG_PACKET_HEADER) - OFFSET_OF (DEBUG_PACKET_HEADER, Command), READ_PACKET_TIMEOUT) == 0) {\r
+  if (DebugAgentReadBuffer (Handle, (UINT8 *)DebugHeader + OFFSET_OF (DEBUG_PACKET_HEADER, Command), sizeof (DEBUG_PACKET_HEADER) - OFFSET_OF (DEBUG_PACKET_HEADER, Command), READ_PACKET_TIMEOUT) == 0) {\r
     //\r
     // Timeout occur, exit\r
     //\r
@@ -1046,9 +1128,9 @@ ReceivePacket (
     //\r
     // Find the valid start symbol\r
     //\r
-    Received = DebugPortReadBuffer (Handle, &DebugHeader->StartSymbol, sizeof (DebugHeader->StartSymbol), TimeoutForStartSymbol);\r
+    Received = DebugAgentReadBuffer (Handle, &DebugHeader->StartSymbol, sizeof (DebugHeader->StartSymbol), TimeoutForStartSymbol);\r
     if (Received < sizeof (DebugHeader->StartSymbol)) {\r
-      DebugAgentMsgPrint (DEBUG_AGENT_WARNING, "DebugPortReadBuffer(StartSymbol) timeout\n");\r
+      DebugAgentMsgPrint (DEBUG_AGENT_WARNING, "DebugAgentReadBuffer(StartSymbol) timeout\n");\r
       return RETURN_TIMEOUT;\r
     }\r
 \r
@@ -1060,14 +1142,14 @@ ReceivePacket (
     //\r
     // Read Package header till field Length\r
     //\r
-    Received = DebugPortReadBuffer (\r
+    Received = DebugAgentReadBuffer (\r
                  Handle,\r
                  (UINT8 *) DebugHeader + OFFSET_OF (DEBUG_PACKET_HEADER, Command),\r
                  OFFSET_OF (DEBUG_PACKET_HEADER, Length) + sizeof (DebugHeader->Length) - sizeof (DebugHeader->StartSymbol),\r
                  Timeout\r
                  );\r
     if (Received == 0) {\r
-      DebugAgentMsgPrint (DEBUG_AGENT_ERROR, "DebugPortReadBuffer(Command) timeout\n");\r
+      DebugAgentMsgPrint (DEBUG_AGENT_ERROR, "DebugAgentReadBuffer(Command) timeout\n");\r
       return RETURN_TIMEOUT;\r
     }\r
     if (DebugHeader->Length < sizeof (DEBUG_PACKET_HEADER)) {\r
@@ -1086,9 +1168,9 @@ ReceivePacket (
       //\r
       // Read the payload data include the CRC field\r
       //\r
-      Received = DebugPortReadBuffer (Handle, &DebugHeader->SequenceNo, (UINT8) (DebugHeader->Length - OFFSET_OF (DEBUG_PACKET_HEADER, SequenceNo)), Timeout);\r
+      Received = DebugAgentReadBuffer (Handle, &DebugHeader->SequenceNo, (UINT8) (DebugHeader->Length - OFFSET_OF (DEBUG_PACKET_HEADER, SequenceNo)), Timeout);\r
       if (Received == 0) {\r
-        DebugAgentMsgPrint (DEBUG_AGENT_ERROR, "DebugPortReadBuffer(SequenceNo) timeout\n");\r
+        DebugAgentMsgPrint (DEBUG_AGENT_ERROR, "DebugAgentReadBuffer(SequenceNo) timeout\n");\r
         return RETURN_TIMEOUT;\r
       }\r
       //\r
@@ -1681,7 +1763,7 @@ SendBreakPacketToHost (
     // Poll Attach symbols from HOST and ack OK\r
     //\r
     do {\r
-      DebugPortReadBuffer (Handle, &InputCharacter, 1, 0);\r
+      DebugAgentReadBuffer (Handle, &InputCharacter, 1, 0);\r
     } while (InputCharacter != DEBUG_STARTING_SYMBOL_ATTACH);\r
     SendAckPacket (DEBUG_COMMAND_OK);\r
 \r
@@ -2408,7 +2490,7 @@ InterruptProcess (
         //\r
         CurrentDebugTimerInitCount = GetApicTimerInitCount ();\r
         if (mDebugMpContext.DebugTimerInitCount != CurrentDebugTimerInitCount) {\r
-          InitializeDebugTimer ();\r
+          InitializeDebugTimer (NULL);\r
         }\r
       }\r
 \r
index c92204136f452d61bfab9ea6447771690f9fa13f..6a9e316f45fa5b49966512e585878bd9114bbb21 100644 (file)
@@ -60,6 +60,7 @@
 //  Timeout value for reading packet (unit is microsecond)\r
 //\r
 #define READ_PACKET_TIMEOUT     (500 * 1000)\r
+#define DEBUG_TIMER_INTERVAL    (100 * 1000)\r
 \r
 #define SOFT_INTERRUPT_SIGNATURE    SIGNATURE_32('S','O','F','T')\r
 #define SYSTEM_RESET_SIGNATURE      SIGNATURE_32('S','Y','S','R')\r
@@ -102,6 +103,7 @@ typedef struct {
 #define DEBUG_MAILBOX_LAST_ACK                        4\r
 #define DEBUG_MAILBOX_SEQUENCE_NO_INDEX               5\r
 #define DEBUG_MAILBOX_HOST_SEQUENCE_NO_INDEX          6\r
+#define DEBUG_MAILBOX_DEBUG_TIMER_FREQUENCY           7\r
 \r
 #pragma pack(1)\r
 typedef union {\r
@@ -137,6 +139,7 @@ typedef struct {
   UINT8                      LastAck;      // The last ack packet type\r
   UINT8                      SequenceNo;\r
   UINT8                      HostSequenceNo;\r
+  UINT32                     DebugTimerFrequency;\r
   UINT8                      CheckSum;     // Mailbox checksum\r
   UINT8                      ToBeCheckSum; // To be Mailbox checksum at the next\r
 } DEBUG_AGENT_MAILBOX;\r
@@ -469,5 +472,30 @@ ReadRemainingBreakPacket (
   IN OUT DEBUG_PACKET_HEADER    *DebugHeader\r
   );\r
 \r
+/**\r
+  Read data from debug channel and save the data in buffer.\r
+\r
+  Reads NumberOfBytes data bytes from a debug device into the buffer\r
+  specified by Buffer. The number of bytes actually read is returned.\r
+  If the return value is less than NumberOfBytes, then the rest operation failed.\r
+  If NumberOfBytes is zero, then return 0.\r
+\r
+  @param  Handle           Debug port handle.\r
+  @param  Buffer           Pointer to the data buffer to store the data read from the debug device.\r
+  @param  NumberOfBytes    Number of bytes which will be read.\r
+  @param  Timeout          Timeout value for reading from debug device. It unit is Microsecond.\r
+\r
+  @retval 0                Read data failed, no data is to be read.\r
+  @retval >0               Actual number of bytes read from debug device.\r
+\r
+**/\r
+UINTN\r
+DebugAgentReadBuffer (\r
+  IN     DEBUG_PORT_HANDLE     Handle,\r
+  IN OUT UINT8                 *Buffer,\r
+  IN     UINTN                 NumberOfBytes,\r
+  IN     UINTN                 Timeout\r
+  );\r
+\r
 #endif\r
 \r
index 6b056150a3268477a037799fbb9e5d0420e204eb..bf06072b0153549b11e3ffa4f74eece44678a1e0 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Code for debug timer to support debug agent library implementation.\r
 \r
-  Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2010 - 2015, 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
   Initialize CPU local APIC timer.\r
 \r
+  @param[out]   Local APIC timer frequency returned.\r
\r
   @return   32-bit Local APIC timer init count.\r
 **/\r
 UINT32\r
 InitializeDebugTimer (\r
-  VOID\r
+  OUT UINT32     *TimerFrequency\r
   )\r
 {\r
   UINTN       ApicTimerDivisor;\r
   UINT32      InitialCount;\r
+  UINT32      ApicTimerFrequency;\r
 \r
   GetApicTimerState (&ApicTimerDivisor, NULL, NULL);\r
-\r
+  ApicTimerFrequency = PcdGet32(PcdFSBClock) / (UINT32)ApicTimerDivisor;\r
   //\r
   // Cpu Local Apic timer interrupt frequency, it is set to 0.1s\r
   //\r
   InitialCount = (UINT32)DivU64x32 (\r
                    MultU64x64 (\r
-                     PcdGet32(PcdFSBClock) / (UINT32)ApicTimerDivisor,\r
-                     100\r
+                     ApicTimerFrequency,\r
+                     DEBUG_TIMER_INTERVAL\r
                      ),\r
-                   1000\r
+                   1000000u\r
                    );\r
 \r
   InitializeApicTimer (ApicTimerDivisor, InitialCount, TRUE, DEBUG_TIMER_VECTOR);\r
 \r
+  DEBUG ((EFI_D_INFO, "Debug Timer: FSB Clock    = %d\n", PcdGet32(PcdFSBClock))); \r
+  DEBUG ((EFI_D_INFO, "Debug Timer: Divisor      = %d\n", ApicTimerDivisor)); \r
+  DEBUG ((EFI_D_INFO, "Debug Timer: Frequency    = %d\n", ApicTimerFrequency)); \r
+  DEBUG ((EFI_D_INFO, "Debug Timer: InitialCount = %d\n", InitialCount)); \r
+\r
+  if (TimerFrequency != NULL) {\r
+    *TimerFrequency = ApicTimerFrequency;\r
+  }\r
   return InitialCount;\r
 }\r
 \r
@@ -87,3 +98,41 @@ SaveAndSetDebugTimerInterrupt (
   return OldDebugTimerInterruptState;\r
 }\r
 \r
+/**\r
+  Check if the timer is time out.\r
+  \r
+  @param[in] TimerCycle             Timer total count.\r
+  @param[in] Timer                  The start timer from the begin.\r
+  @param[in] TimeoutTicker          Ticker number need time out.\r
+\r
+  @return TRUE  Timer time out occurs.\r
+  @retval FALSE Timer does not time out.\r
+\r
+**/\r
+BOOLEAN\r
+IsDebugTimerTimeout (\r
+  IN UINT32                     TimerCycle,\r
+  IN UINT32                     Timer,\r
+  IN UINT32                     TimeoutTicker\r
+  )\r
+{\r
+  UINT64  CurrentTimer;\r
+  UINT64  Delta;\r
+\r
+  CurrentTimer = GetApicTimerCurrentCount ();\r
+\r
+  //\r
+  // This timer counter counts down.  Check for roll over condition.\r
+  //\r
+  if (CurrentTimer < Timer) {\r
+    Delta = Timer - CurrentTimer;\r
+  } else {\r
+    //\r
+    // Handle one roll-over. \r
+    //\r
+    Delta = TimerCycle - (CurrentTimer - Timer);\r
+  }\r
\r
+  return (BOOLEAN) (Delta >= TimeoutTicker);\r
+}\r
+\r
index 76716d46b20e631107e8fa399ded22ddf1f3a3a8..7ff0661d461474db4d0bda083d6312ad37658319 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Header file for debug timer to support debug agent library implementation.\r
 \r
-  Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2010 - 2015, 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
   Initialize CPU local APIC timer.\r
 \r
+  @param[out]   Local APIC timer frequency returned.\r
\r
   @return   32-bit Local APIC timer init count.\r
 **/\r
 UINT32\r
 InitializeDebugTimer (\r
-  VOID\r
+  OUT UINT32     *TimerFrequency\r
+  );\r
+\r
+/**\r
+  Check if the timer is time out.\r
+  \r
+  @param[in] TimerCycle             Timer total count.\r
+  @param[in] Timer                  The start timer from the begin.\r
+  @param[in] TimeoutTicker          Ticker number need time out.\r
+\r
+  @return TRUE  Timer time out occurs.\r
+  @retval FALSE Timer does not time out.\r
+\r
+**/\r
+BOOLEAN\r
+IsDebugTimerTimeout (\r
+  IN UINT32                     TimerCycle,\r
+  IN UINT32                     Timer,\r
+  IN UINT32                     TimeoutTicker\r
   );\r
 \r
 #endif\r
index b7bade4fcabcf488a6ba34f168f9983338164891..601c5e8bedea0703cc0b6b032d4397dfe6d5d7c9 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Debug Agent library implementition for Dxe Core and Dxr modules.\r
 \r
-  Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2010 - 2015, 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
@@ -355,6 +355,7 @@ InitializeDebugAgent (
   IA32_DESCRIPTOR              IdtDescriptor;\r
   IA32_DESCRIPTOR              *Ia32Idtr;\r
   IA32_IDT_ENTRY               *Ia32IdtEntry;\r
+  UINT32                       DebugTimerFrequency;\r
 \r
   if (InitFlag == DEBUG_AGENT_INIT_DXE_AP) {\r
     //\r
@@ -398,10 +399,6 @@ InitializeDebugAgent (
     mSaveIdtTableSize = IdtDescriptor.Limit + 1;\r
     mSavedIdtTable    = AllocateCopyPool (mSaveIdtTableSize, (VOID *) IdtDescriptor.Base);\r
     //\r
-    // Initialize Debug Timer hardware and save its initial count\r
-    //\r
-    mDebugMpContext.DebugTimerInitCount = InitializeDebugTimer ();\r
-    //\r
     // Check if Debug Agent initialized in DXE phase\r
     //\r
     Mailbox = GetMailboxFromConfigurationTable ();\r
@@ -417,6 +414,11 @@ InitializeDebugAgent (
     //\r
     SetupDebugAgentEnviroment (Mailbox);\r
     //\r
+    // Initialize Debug Timer hardware and save its initial count and frequency\r
+    //\r
+    mDebugMpContext.DebugTimerInitCount = InitializeDebugTimer (&DebugTimerFrequency);\r
+    UpdateMailboxContent (mMailboxPointer, DEBUG_MAILBOX_DEBUG_TIMER_FREQUENCY, DebugTimerFrequency);\r
+    //\r
     // For DEBUG_AGENT_INIT_S3, needn't to install configuration table and EFI Serial IO protocol\r
     // For DEBUG_AGENT_INIT_DXE_CORE, InternalConstructorWorker() will invoked in Constructor()\r
     //\r
@@ -496,10 +498,6 @@ InitializeDebugAgent (
     mDxeCoreFlag                = TRUE;\r
     mMultiProcessorDebugSupport = TRUE;\r
     //\r
-    // Initialize Debug Timer hardware and its initial count\r
-    //\r
-    mDebugMpContext.DebugTimerInitCount = InitializeDebugTimer ();\r
-    //\r
     // Try to get mailbox from GUIDed HOB build in PEI\r
     //\r
     HobList = Context;\r
@@ -509,6 +507,11 @@ InitializeDebugAgent (
     //\r
     SetupDebugAgentEnviroment (Mailbox);\r
     //\r
+    // Initialize Debug Timer hardware and save its initial count and frequency\r
+    //\r
+    mDebugMpContext.DebugTimerInitCount = InitializeDebugTimer (&DebugTimerFrequency);\r
+    UpdateMailboxContent (mMailboxPointer, DEBUG_MAILBOX_DEBUG_TIMER_FREQUENCY, DebugTimerFrequency);\r
+    //\r
     // Enable interrupt to receive Debug Timer interrupt\r
     //\r
     EnableInterrupts ();\r
index 9b181e3ac7fa82cc798c974b6393f8e0f42789be..cb3b623038b90e0f72c4a3f367a83935984ac761 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Install Serial IO Protocol that layers on top of a Debug Communication Library instance.\r
 \r
-  Copyright (c) 2012 - 2013, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2012 - 2015, 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
@@ -676,7 +676,7 @@ SerialRead (
       if (!DebugPortPollBuffer (Handle)) {\r
         break;\r
       }\r
-      DebugPortReadBuffer (Handle, Data8, 1, 0);\r
+      DebugAgentReadBuffer (Handle, Data8, 1, 0);\r
 \r
       if (*Data8 == DEBUG_STARTING_SYMBOL_ATTACH) {\r
         //\r
@@ -752,7 +752,7 @@ DebugReadBreakFromDebugPort (
     //\r
     // Try to read the start symbol\r
     //\r
-    DebugPortReadBuffer (Handle, Data8, 1, 0);\r
+    DebugAgentReadBuffer (Handle, Data8, 1, 0);\r
     if (*Data8 == DEBUG_STARTING_SYMBOL_ATTACH) {\r
       DebugAgentMsgPrint (DEBUG_AGENT_INFO, "Debug Timer attach symbol received %x", *Data8);\r
       *BreakSymbol = *Data8;\r
index 6e7ff8e22eda2d3268519568ff9498b3847426c6..b718e82e2094c748e8f60c8c11892b31d3d68d69 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   SEC Core Debug Agent Library instance implementition.\r
 \r
-  Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2010 - 2015, 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
@@ -93,7 +93,7 @@ DebugReadBreakSymbol (
     //\r
     // Try to read the start symbol\r
     //\r
-    DebugPortReadBuffer (Handle, Data8, 1, 0);\r
+    DebugAgentReadBuffer (Handle, Data8, 1, 0);\r
     if (*Data8 == DEBUG_STARTING_SYMBOL_ATTACH) {\r
       *BreakSymbol = *Data8;\r
       DebugAgentMsgPrint (DEBUG_AGENT_INFO, "Debug Timer attach symbol received %x", *BreakSymbol);\r
@@ -375,6 +375,7 @@ InitializeDebugAgent (
   UINT64                           MailboxLocation;\r
   UINT64                           *MailboxLocationPointer;\r
   EFI_PHYSICAL_ADDRESS             Address;\r
+  UINT32                           DebugTimerFrequency;\r
 \r
   DisableInterrupts ();\r
 \r
@@ -399,8 +400,11 @@ InitializeDebugAgent (
     // Save init arch type when debug agent initialized\r
     //\r
     SetDebugFlag (DEBUG_AGENT_FLAG_INIT_ARCH, DEBUG_ARCH_SYMBOL);\r
-\r
-    InitializeDebugTimer ();\r
+    //\r
+    // Initialize Debug Timer hardware and save its frequency\r
+    //\r
+    InitializeDebugTimer (&DebugTimerFrequency);\r
+    UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_DEBUG_TIMER_FREQUENCY, DebugTimerFrequency);\r
 \r
     Phase2Context.InitFlag = InitFlag;\r
     Phase2Context.Context  = Context;\r
@@ -524,8 +528,11 @@ InitializeDebugAgent (
                                &MailboxLocation,\r
                                sizeof (UINT64)\r
                                );\r
-\r
-    InitializeDebugTimer ();\r
+    //\r
+    // Initialize Debug Timer hardware and save its frequency\r
+    //\r
+    InitializeDebugTimer (&DebugTimerFrequency);\r
+    UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_DEBUG_TIMER_FREQUENCY, DebugTimerFrequency);\r
     //\r
     // Update IDT entry to save the location pointer saved mailbox pointer\r
     //\r
index 651737e5e7b2195b745851b247402f930898dc44..ac96a00240319e6245182a64174bbad3df34f92a 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Debug Agent library implementition.\r
 \r
-  Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2010 - 2015, 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
@@ -189,6 +189,7 @@ InitializeDebugAgent (
   UINT16                        IdtEntryCount;\r
   DEBUG_AGENT_MAILBOX           *Mailbox;\r
   UINT64                        *MailboxLocation;\r
+  UINT32                        DebugTimerFrequency;\r
 \r
   switch (InitFlag) {\r
   case DEBUG_AGENT_INIT_SMM:\r
@@ -236,6 +237,12 @@ InitializeDebugAgent (
     // Initialized Debug Agent\r
     //\r
     InitializeDebugIdt ();\r
+    //\r
+    // Initialize Debug Timer hardware and save its frequency\r
+    //\r
+    InitializeDebugTimer (&DebugTimerFrequency);\r
+    UpdateMailboxContent (mMailboxPointer, DEBUG_MAILBOX_DEBUG_TIMER_FREQUENCY, DebugTimerFrequency);\r
+\r
     DebugPortHandle = (UINT64) (UINTN)DebugPortInitialize ((DEBUG_PORT_HANDLE) (UINTN)Mailbox->DebugPortHandle, NULL);\r
     UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX, DebugPortHandle);\r
     mMailboxPointer = Mailbox;\r
@@ -329,9 +336,10 @@ InitializeDebugAgent (
 \r
       InitializeDebugIdt ();\r
       //\r
-      // Initialize Debug Timer hardware and enable interrupt.\r
+      // Initialize Debug Timer hardware and save its frequency\r
       //\r
-      InitializeDebugTimer ();\r
+      InitializeDebugTimer (&DebugTimerFrequency);\r
+      UpdateMailboxContent (mMailboxPointer, DEBUG_MAILBOX_DEBUG_TIMER_FREQUENCY, DebugTimerFrequency);\r
       EnableInterrupts ();\r
 \r
       FindAndReportModuleImageInfo (SIZE_4KB);\r
index 3a5f1969b22abef84390b3920a401a32a3df855d..388286b406c4a235b5b6bb52486e0ca3d2ade9cd 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Debug Port Library implementation based on serial port.\r
 \r
-  Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2010 - 2015, 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
 #include <Library/DebugCommunicationLib.h>\r
 #include <Library/SerialPortLib.h>\r
-#include <Library/TimerLib.h>\r
 #include <Library/DebugLib.h>\r
-#include <Library/BaseLib.h>\r
-#include <Library/BaseMemoryLib.h>\r
-\r
-#pragma pack(1)\r
-//\r
-// The internal data structure of DEBUG_PORT_HANDLE, which stores some\r
-// important datum which are used across various phases.\r
-//\r
-typedef struct _SERIAL_DEBUG_PORT_HANDLE{\r
-  //\r
-  // Timter settings\r
-  //\r
-  UINT64       TimerFrequency;\r
-  UINT64       TimerCycle;\r
-  BOOLEAN      TimerCountDown;\r
-} SERIAL_DEBUG_PORT_HANDLE;\r
-#pragma pack()\r
-\r
-//\r
-// The global variable which can be used after memory is ready.\r
-//\r
-SERIAL_DEBUG_PORT_HANDLE     mSerialDebugPortHandle;\r
-\r
-/**\r
-  Check if the timer is timeout.\r
-  \r
-  @param[in] SerialDebugPortHandle  Pointer to Serial Debug port handle\r
-  @param[in] Timer                  The start timer from the begin.\r
-  @param[in] TimeoutTicker          Ticker number need time out.\r
-\r
-  @return TRUE  Timer time out occurs.\r
-  @retval FALSE Timer does not time out.\r
-\r
-**/\r
-BOOLEAN\r
-IsTimerTimeout (\r
-  IN SERIAL_DEBUG_PORT_HANDLE   *SerialDebugPortHandle,\r
-  IN UINT64                     Timer,\r
-  IN UINT64                     TimeoutTicker\r
-  )\r
-{\r
-  UINT64  CurrentTimer;\r
-  UINT64  Delta;\r
-\r
-  CurrentTimer = GetPerformanceCounter ();\r
-\r
-  if (SerialDebugPortHandle->TimerCountDown) {\r
-    //\r
-    // The timer counter counts down.  Check for roll over condition.\r
-    //\r
-    if (CurrentTimer < Timer) {\r
-      Delta = Timer - CurrentTimer;\r
-    } else {\r
-      //\r
-      // Handle one roll-over. \r
-      //\r
-      Delta = SerialDebugPortHandle->TimerCycle - (CurrentTimer - Timer);\r
-    }\r
-  } else {\r
-    //\r
-    // The timer counter counts up.  Check for roll over condition.\r
-    //\r
-    if (CurrentTimer > Timer) {\r
-      Delta = CurrentTimer - Timer;\r
-    } else {\r
-      //\r
-      // Handle one roll-over. \r
-      //\r
-      Delta = SerialDebugPortHandle->TimerCycle - (Timer - CurrentTimer);\r
-    }\r
-  }\r
\r
-  return (BOOLEAN) (Delta >= TimeoutTicker);\r
-}\r
 \r
 /**\r
   Initialize the debug port.\r
@@ -136,42 +61,7 @@ DebugPortInitialize (
   IN DEBUG_PORT_CONTINUE  Function\r
   )\r
 {\r
-  RETURN_STATUS              Status;\r
-  SERIAL_DEBUG_PORT_HANDLE   Handle;\r
-  SERIAL_DEBUG_PORT_HANDLE   *SerialDebugPortHandle;\r
-  UINT64                     TimerStartValue;\r
-  UINT64                     TimerEndValue;\r
-\r
-  //\r
-  // Validate the PCD PcdDebugPortHandleBufferSize value \r
-  //\r
-  ASSERT (PcdGet16 (PcdDebugPortHandleBufferSize) == sizeof (SERIAL_DEBUG_PORT_HANDLE));\r
-\r
-  if (Context != NULL && Function == NULL) {\r
-    SerialDebugPortHandle = (SERIAL_DEBUG_PORT_HANDLE *)Context;\r
-  } else {\r
-    ZeroMem (&Handle, sizeof (SERIAL_DEBUG_PORT_HANDLE));\r
-    SerialDebugPortHandle = &Handle;\r
-  }\r
-  SerialDebugPortHandle->TimerFrequency = GetPerformanceCounterProperties (\r
-                                            &TimerStartValue,\r
-                                            &TimerEndValue\r
-                                            );\r
-  DEBUG ((EFI_D_INFO, "Serial Debug Port: TimerFrequency  = 0x%lx\n", SerialDebugPortHandle->TimerFrequency)); \r
-  DEBUG ((EFI_D_INFO, "Serial Debug Port: TimerStartValue = 0x%lx\n", TimerStartValue)); \r
-  DEBUG ((EFI_D_INFO, "Serial Debug Port: TimerEndValue   = 0x%lx\n", TimerEndValue)); \r
-\r
-  if (TimerEndValue < TimerStartValue) {\r
-    SerialDebugPortHandle->TimerCountDown = TRUE;\r
-    SerialDebugPortHandle->TimerCycle     = TimerStartValue - TimerEndValue;\r
-  } else {\r
-    SerialDebugPortHandle->TimerCountDown = FALSE;\r
-    SerialDebugPortHandle->TimerCycle     = TimerEndValue - TimerStartValue;\r
-  }  \r
-\r
-  if (Function == NULL && Context != NULL) {\r
-    return (DEBUG_PORT_HANDLE *) Context;\r
-  }\r
+  RETURN_STATUS      Status;\r
 \r
   Status = SerialPortInitialize ();\r
   if (RETURN_ERROR(Status)) {\r
@@ -179,12 +69,10 @@ DebugPortInitialize (
   }\r
 \r
   if (Function != NULL) {\r
-    Function (Context, SerialDebugPortHandle);\r
-  } else {\r
-    CopyMem(&mSerialDebugPortHandle, SerialDebugPortHandle, sizeof (SERIAL_DEBUG_PORT_HANDLE));\r
+    Function (Context, NULL);\r
   }\r
 \r
-  return (DEBUG_PORT_HANDLE)(UINTN)&mSerialDebugPortHandle;\r
+  return NULL;\r
 }\r
 \r
 /**\r
@@ -213,62 +101,11 @@ DebugPortReadBuffer (
   IN UINTN                 Timeout\r
   )\r
 {\r
-  SERIAL_DEBUG_PORT_HANDLE *SerialDebugPortHandle;\r
-  UINTN                    Index;\r
-  UINT64                   Begin;\r
-  UINT64                   TimeoutTicker;\r
-  UINT64                   TimerRound;\r
-  \r
-  //\r
-  // If Handle is NULL, it means memory is ready for use.\r
-  // Use global variable to store handle value.\r
-  //\r
-  if (Handle == NULL) {\r
-    SerialDebugPortHandle = &mSerialDebugPortHandle;\r
-  } else {\r
-    SerialDebugPortHandle = (SERIAL_DEBUG_PORT_HANDLE *)Handle;\r
-  }\r
-\r
-  Begin         = 0;\r
-  TimeoutTicker = 0;  \r
-  TimerRound    = 0;\r
-  if (Timeout != 0) {\r
-    Begin = GetPerformanceCounter ();\r
-    TimeoutTicker = DivU64x32 (\r
-                      MultU64x64 (\r
-                        SerialDebugPortHandle->TimerFrequency,\r
-                        Timeout\r
-                        ),\r
-                      1000000u\r
-                      );\r
-    TimerRound = DivU64x64Remainder (\r
-                   TimeoutTicker,\r
-                   DivU64x32 (SerialDebugPortHandle->TimerCycle, 2),\r
-                   &TimeoutTicker\r
-                   );\r
-  }\r
-  Index = 0;\r
-  while (Index < NumberOfBytes) {\r
-    if (SerialPortPoll () || Timeout == 0) {\r
-      SerialPortRead (Buffer + Index, 1);\r
-      Index ++; \r
-      continue;\r
-    }\r
-    if (TimerRound == 0) {\r
-      if (IsTimerTimeout (SerialDebugPortHandle, Begin, TimeoutTicker)) {\r
-        //\r
-        // If time out occurs.\r
-        //\r
-        return 0;\r
-      }\r
-    } else {\r
-      if (IsTimerTimeout (SerialDebugPortHandle, Begin, DivU64x32 (SerialDebugPortHandle->TimerCycle, 2))) {\r
-        TimerRound --;\r
-      }\r
-    }\r
+  if (NumberOfBytes != 1 || Buffer == NULL || Timeout != 0) {\r
+    return 0;\r
   }\r
 \r
-  return Index;\r
+  return SerialPortRead (Buffer, 1);\r
 }\r
 \r
 /**\r
index 640d0833a5d1b45dec6b864c6bb2a4a648f85762..50b24c21d138e37f5ee61341241dd018fe6b8238 100644 (file)
 \r
 [LibraryClasses]\r
   SerialPortLib\r
-  TimerLib\r
   DebugLib\r
-  BaseMemoryLib\r
-  BaseLib\r
-\r
-[PCD]\r
-  # The value of data buffer size used for Serial debug port handle.\r
-  # It should be equal to sizeof (SERIAL_DEBUG_PORT_HANDLE).\r
-  gEfiSourceLevelDebugPkgTokenSpaceGuid.PcdDebugPortHandleBufferSize|17   ## SOMETIMES_CONSUMES\r
-\r
index 59c04af34987c84af7ac93b99c6d57878646aad8..b65c56dc13bd2b42c0ad27eb5aabe90f6eb7dffa 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Debug Port Library implementation based on usb debug port.\r
 \r
-  Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2010 - 2015, 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
@@ -147,12 +147,6 @@ typedef struct _USB_DEBUG_PORT_HANDLE{
   // The data buffer. Maximum length is 8 bytes.\r
   //\r
   UINT8        Data[8];\r
-  //\r
-  // Timter settings\r
-  //\r
-  UINT64       TimerFrequency;\r
-  UINT64       TimerCycle;\r
-  BOOLEAN      TimerCountDown;\r
 } USB_DEBUG_PORT_HANDLE;\r
 #pragma pack()\r
 \r
@@ -161,58 +155,6 @@ typedef struct _USB_DEBUG_PORT_HANDLE{
 //\r
 USB_DEBUG_PORT_HANDLE     mDebugCommunicationLibUsbDebugPortHandle;\r
 \r
-/**\r
-  Check if the timer is timeout.\r
-  \r
-  @param[in] UsbDebugPortHandle  Pointer to USB Debug port handle\r
-  @param[in] Timer               The start timer from the begin.\r
-  @param[in] TimeoutTicker       Ticker number need time out.\r
-\r
-  @return TRUE  Timer time out occurs.\r
-  @retval FALSE Timer does not time out.\r
-\r
-**/\r
-BOOLEAN\r
-IsTimerTimeout (\r
-  IN USB_DEBUG_PORT_HANDLE   *UsbDebugPortHandle,\r
-  IN UINT64                  Timer,\r
-  IN UINT64                  TimeoutTicker\r
-  )\r
-{\r
-  UINT64  CurrentTimer;\r
-  UINT64  Delta;\r
-\r
-  CurrentTimer = GetPerformanceCounter ();\r
-\r
-  if (UsbDebugPortHandle->TimerCountDown) {\r
-    //\r
-    // The timer counter counts down.  Check for roll over condition.\r
-    //\r
-    if (CurrentTimer < Timer) {\r
-      Delta = Timer - CurrentTimer;\r
-    } else {\r
-      //\r
-      // Handle one roll-over. \r
-      //\r
-      Delta = UsbDebugPortHandle->TimerCycle - (CurrentTimer - Timer);\r
-    }\r
-  } else {\r
-    //\r
-    // The timer counter counts up.  Check for roll over condition.\r
-    //\r
-    if (CurrentTimer > Timer) {\r
-      Delta = CurrentTimer - Timer;\r
-    } else {\r
-      //\r
-      // Handle one roll-over. \r
-      //\r
-      Delta = UsbDebugPortHandle->TimerCycle - (Timer - CurrentTimer);\r
-    }\r
-  }\r
\r
-  return (BOOLEAN) (Delta >= TimeoutTicker);\r
-}\r
-\r
 /**\r
   Calculate the usb debug port bar address.\r
 \r
@@ -834,23 +776,12 @@ DebugPortReadBuffer (
   USB_DEBUG_PORT_HANDLE     *UsbDebugPortHandle;\r
   USB_DEBUG_PORT_REGISTER   *UsbDebugPortRegister;\r
   RETURN_STATUS             Status;\r
-  UINT8                     Received;\r
-  UINTN                     Total;\r
-  UINTN                     Remaining;\r
   UINT8                     Index;\r
-  UINT8                     Length;\r
-  UINT64                    Begin;\r
-  UINT64                    TimeoutTicker;\r
-  UINT64                    TimerRound;\r
 \r
-  if (NumberOfBytes == 0 || Buffer == NULL) {\r
+  if (NumberOfBytes != 1 || Buffer == NULL || Timeout != 0) {\r
     return 0;\r
   }\r
 \r
-  Received  = 0;\r
-  Total     = 0;\r
-  Remaining = 0;\r
-\r
   //\r
   // If Handle is NULL, it means memory is ready for use.\r
   // Use global variable to store handle value.\r
@@ -871,117 +802,21 @@ DebugPortReadBuffer (
   UsbDebugPortRegister = (USB_DEBUG_PORT_REGISTER *)(UINTN)(UsbDebugPortHandle->UsbDebugPortMemoryBase + UsbDebugPortHandle->DebugPortOffset);\r
 \r
   //\r
-  // First read data from buffer, then read debug port hw to get received data.\r
+  // Read data from buffer\r
   //\r
-  if (UsbDebugPortHandle->DataCount > 0) {\r
-    if (NumberOfBytes <= UsbDebugPortHandle->DataCount) {\r
-      Total = NumberOfBytes;\r
-    } else {\r
-      Total = UsbDebugPortHandle->DataCount;\r
-    }\r
-\r
-    for (Index = 0; Index < Total; Index++) {\r
-      Buffer[Index] = UsbDebugPortHandle->Data[Index];\r
-    }\r
-\r
-    for (Index = 0; Index < UsbDebugPortHandle->DataCount - Total; Index++) {\r
-      if (Total + Index >= 8) {\r
+  if (UsbDebugPortHandle->DataCount < 1) {\r
+    return 0;\r
+  } else {\r
+    *Buffer = UsbDebugPortHandle->Data[0];\r
+    for (Index = 0; Index < UsbDebugPortHandle->DataCount - 1; Index++) {\r
+      if ((Index + 1) >= USB_DEBUG_PORT_MAX_PACKET_SIZE) {\r
         return 0;\r
       }\r
-      UsbDebugPortHandle->Data[Index] = UsbDebugPortHandle->Data[Total + Index];\r
-    }\r
-    UsbDebugPortHandle->DataCount = (UINT8)(UsbDebugPortHandle->DataCount - (UINT8)Total);\r
-  }\r
-\r
-  //\r
-  // If Timeout is equal to 0, then it means it should always wait until all datum required are received.\r
-  //\r
-  Begin         = 0;\r
-  TimeoutTicker = 0;  \r
-  TimerRound    = 0;\r
-  if (Timeout != 0) {\r
-    Begin = GetPerformanceCounter ();\r
-    TimeoutTicker = DivU64x32 (\r
-                      MultU64x64 (\r
-                        UsbDebugPortHandle->TimerFrequency,\r
-                        Timeout\r
-                        ),\r
-                      1000000u\r
-                      );\r
-    TimerRound = DivU64x64Remainder (\r
-                   TimeoutTicker,\r
-                   DivU64x32 (UsbDebugPortHandle->TimerCycle, 2),\r
-                   &TimeoutTicker\r
-                   );\r
-  }\r
-\r
-  //\r
-  // Read remaining data by executing one or more usb debug transfer transactions at usb debug port hw.\r
-  //\r
-  while (Total < NumberOfBytes) {\r
-    if (Timeout != 0) {\r
-      if (TimerRound == 0) {\r
-        if (IsTimerTimeout (UsbDebugPortHandle, Begin, TimeoutTicker)) {\r
-          //\r
-          // If time out occurs.\r
-          //\r
-          return 0;\r
-        }\r
-      } else {\r
-        if (IsTimerTimeout (UsbDebugPortHandle, Begin, DivU64x32 (UsbDebugPortHandle->TimerCycle, 2))) {\r
-          TimerRound --;\r
-        }\r
-      }\r
-    }\r
-    Remaining = NumberOfBytes - Total;\r
-    if (Remaining >= USB_DEBUG_PORT_MAX_PACKET_SIZE) {\r
-      Status = UsbDebugPortIn(UsbDebugPortRegister, Buffer + Total, &Received, INPUT_PID, 0x7f, 0x82, UsbDebugPortHandle->BulkInToggle);\r
-\r
-      if (RETURN_ERROR(Status)) {\r
-        return Total;\r
-      }\r
-    } else {\r
-      Status = UsbDebugPortIn(UsbDebugPortRegister, &UsbDebugPortHandle->Data[0], &Received, INPUT_PID, 0x7f, 0x82, UsbDebugPortHandle->BulkInToggle);\r
-\r
-      if (RETURN_ERROR(Status)) {\r
-        return Total;\r
-      }\r
-\r
-      UsbDebugPortHandle->DataCount = Received;\r
-\r
-      if (Remaining <= Received) {\r
-        Length = (UINT8)Remaining;\r
-      } else {\r
-        Length = (UINT8)Received;\r
-      }\r
-\r
-      //\r
-      // Copy required data from the data buffer to user buffer.\r
-      //\r
-      for (Index = 0; Index < Length; Index++) {\r
-        (Buffer + Total)[Index] = UsbDebugPortHandle->Data[Index];\r
-        UsbDebugPortHandle->DataCount--;\r
-      }\r
-\r
-      //\r
-      // reorder the data buffer to make available data arranged from the beginning of the data buffer.\r
-      //\r
-      for (Index = 0; Index < Received - Length; Index++) {\r
-        if (Length + Index >= 8) {\r
-          return 0;\r
-        }\r
-        UsbDebugPortHandle->Data[Index] = UsbDebugPortHandle->Data[Length + Index];\r
-      }\r
-      //\r
-      // fixup the real received length in Buffer.\r
-      //\r
-      Received = Length;\r
+      UsbDebugPortHandle->Data[Index] = UsbDebugPortHandle->Data[Index + 1];\r
     }\r
-    UsbDebugPortHandle->BulkInToggle ^= 1;\r
-    Total += Received;\r
+    UsbDebugPortHandle->DataCount = (UINT8)(UsbDebugPortHandle->DataCount - 1);\r
+    return 1;\r
   }\r
-\r
-  return Total;\r
 }\r
 \r
 /**\r
@@ -1208,8 +1043,6 @@ DebugPortInitialize (
   RETURN_STATUS             Status;\r
   USB_DEBUG_PORT_HANDLE     Handle;\r
   USB_DEBUG_PORT_HANDLE     *UsbDebugPortHandle;\r
-  UINT64                    TimerStartValue;\r
-  UINT64                    TimerEndValue;\r
 \r
   //\r
   // Validate the PCD PcdDebugPortHandleBufferSize value \r
@@ -1223,22 +1056,6 @@ DebugPortInitialize (
     UsbDebugPortHandle = &Handle;\r
   }\r
 \r
-  UsbDebugPortHandle->TimerFrequency = GetPerformanceCounterProperties (\r
-                                         &TimerStartValue,\r
-                                         &TimerEndValue\r
-                                         );\r
-  DEBUG ((EFI_D_INFO, "USB Debug Port: TimerFrequency  = 0x%lx\n", UsbDebugPortHandle->TimerFrequency)); \r
-  DEBUG ((EFI_D_INFO, "USB Debug Port: TimerStartValue = 0x%lx\n", TimerStartValue)); \r
-  DEBUG ((EFI_D_INFO, "USB Debug Port: TimerEndValue   = 0x%lx\n", TimerEndValue)); \r
-\r
-  if (TimerEndValue < TimerStartValue) {\r
-    UsbDebugPortHandle->TimerCountDown = TRUE;\r
-    UsbDebugPortHandle->TimerCycle     = TimerStartValue - TimerEndValue;\r
-  } else {\r
-    UsbDebugPortHandle->TimerCountDown = FALSE;\r
-    UsbDebugPortHandle->TimerCycle     = TimerEndValue - TimerStartValue;\r
-  }   \r
-\r
   if (Function == NULL && Context != NULL) {\r
     return (DEBUG_PORT_HANDLE *) Context;\r
   }\r
index b9f4889166c173882b35c8584c76ffd268535649..028b04afbf00e7fdb78af66b01d00c1e67e46385 100644 (file)
@@ -45,7 +45,7 @@
   gEfiSourceLevelDebugPkgTokenSpaceGuid.PcdUsbEhciPciAddress              ## CONSUMES\r
   # The value of data buffer size used for USB debug port handle.\r
   # It should be equal to sizeof (USB_DEBUG_PORT_HANDLE).\r
-  gEfiSourceLevelDebugPkgTokenSpaceGuid.PcdDebugPortHandleBufferSize|40   ## SOMETIMES_CONSUMES\r
+  gEfiSourceLevelDebugPkgTokenSpaceGuid.PcdDebugPortHandleBufferSize|23   ## SOMETIMES_CONSUMES\r
 \r
 [LibraryClasses]\r
   TimerLib\r
index 320998b32a12f68ec385f61f7363da854870acdc..7c62bdadfbf255dca50f313f6da623de8355ca4d 100644 (file)
@@ -186,58 +186,6 @@ ProgramXhciBaseAddress (
   return XhciMmioBase;\r
 }\r
 \r
-/**\r
-  Check if the timer is timeout.\r
-  \r
-  @param[in] UsbDebugPortHandle  Pointer to USB Debug port handle\r
-  @param[in] Timer               The start timer from the begin.\r
-  @param[in] TimeoutTicker       Ticker number need time out.\r
-\r
-  @return TRUE  Timer time out occurs.\r
-  @retval FALSE Timer does not time out.\r
-\r
-**/\r
-BOOLEAN\r
-IsTimerTimeout (\r
-  IN USB3_DEBUG_PORT_HANDLE  *UsbDebugPortHandle,\r
-  IN UINT64                  Timer,\r
-  IN UINT64                  TimeoutTicker\r
-  )\r
-{\r
-  UINT64  CurrentTimer;\r
-  UINT64  Delta;\r
-\r
-  CurrentTimer = GetPerformanceCounter ();\r
-\r
-  if (UsbDebugPortHandle->TimerCountDown) {\r
-    //\r
-    // The timer counter counts down.  Check for roll over condition.\r
-    //\r
-    if (CurrentTimer < Timer) {\r
-      Delta = Timer - CurrentTimer;\r
-    } else {\r
-      //\r
-      // Handle one roll-over. \r
-      //\r
-      Delta = UsbDebugPortHandle->TimerCycle - (CurrentTimer - Timer);\r
-    }\r
-  } else {\r
-    //\r
-    // The timer counter counts up.  Check for roll over condition.\r
-    //\r
-    if (CurrentTimer > Timer) {\r
-      Delta = CurrentTimer - Timer;\r
-    } else {\r
-      //\r
-      // Handle one roll-over. \r
-      //\r
-      Delta = UsbDebugPortHandle->TimerCycle - (Timer - CurrentTimer);\r
-    }\r
-  }\r
\r
-  return (BOOLEAN) (Delta >= TimeoutTicker);\r
-}\r
-\r
 /**\r
   Update XHC MMIO base address when MMIO base address is changed.\r
 \r
@@ -825,25 +773,13 @@ DebugPortReadBuffer (
 {\r
   USB3_DEBUG_PORT_HANDLE    *UsbDebugPortHandle;\r
   RETURN_STATUS             Status;\r
-  UINTN                     Received;\r
-  UINTN                     Total;\r
-  UINTN                     Remaining;\r
   UINT8                     Index;\r
-  UINTN                     Length;\r
-  UINT64                    Begin;\r
-  UINT64                    TimeoutTicker;\r
-  UINT64                    TimerRound;\r
-  EFI_PHYSICAL_ADDRESS      XhciMmioBase;\r
   UINT8                     *Data;\r
 \r
-  if (NumberOfBytes == 0 || Buffer == NULL) {\r
+  if (NumberOfBytes != 1 || Buffer == NULL || Timeout != 0) {\r
     return 0;\r
   }\r
 \r
-  Received  = 0;\r
-  Total     = 0;\r
-  Remaining = 0;\r
-\r
   //\r
   // If Handle is NULL, it means memory is ready for use.\r
   // Use global variable to store handle value.\r
@@ -858,9 +794,6 @@ DebugPortReadBuffer (
     return 0;\r
   }\r
   \r
-  XhciMmioBase = ProgramXhciBaseAddress ();\r
-  UpdateXhcResource (UsbDebugPortHandle, XhciMmioBase);\r
-  \r
   if (NeedReinitializeHardware(UsbDebugPortHandle)) {\r
     Status = InitializeUsbDebugHardware (UsbDebugPortHandle);\r
     if (RETURN_ERROR(Status)) {\r
@@ -871,114 +804,22 @@ DebugPortReadBuffer (
   Data = (UINT8 *)(UINTN)UsbDebugPortHandle->Data;\r
 \r
   //\r
-  // First read data from buffer, then read debug port hw to get received data.\r
+  // Read data from buffer\r
   //\r
-  if (UsbDebugPortHandle->DataCount > 0) {\r
-    if (NumberOfBytes <= UsbDebugPortHandle->DataCount) {\r
-      Total = NumberOfBytes;\r
-    } else {\r
-      Total = UsbDebugPortHandle->DataCount;\r
-    }\r
-\r
-    for (Index = 0; Index < Total; Index++) {\r
-      Buffer[Index] = Data[Index];\r
-    }\r
+  if (UsbDebugPortHandle->DataCount < 1) {\r
+    return 0;\r
+  } else {\r
+    *Buffer = Data[0];\r
 \r
-    for (Index = 0; Index < UsbDebugPortHandle->DataCount - Total; Index++) {\r
-      if (Total + Index >= XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE) {\r
+    for (Index = 0; Index < UsbDebugPortHandle->DataCount - 1; Index++) {\r
+      if ((Index + 1) >= XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE) {\r
         return 0;\r
       }\r
-      Data[Index] = Data[Total + Index];\r
+      Data[Index] = Data[Index + 1];\r
     }\r
-    UsbDebugPortHandle->DataCount = (UINT8)(UsbDebugPortHandle->DataCount - (UINT8)Total);\r
+    UsbDebugPortHandle->DataCount = (UINT8)(UsbDebugPortHandle->DataCount - 1);\r
+    return 1;\r
   }\r
-\r
-  //\r
-  // If Timeout is equal to 0, then it means it should always wait until all data required are received.\r
-  //\r
-  Begin         = 0;\r
-  TimeoutTicker = 0;  \r
-  TimerRound    = 0;\r
-  if (Timeout != 0) {\r
-    Begin = GetPerformanceCounter ();\r
-    TimeoutTicker = DivU64x32 (\r
-                      MultU64x64 (\r
-                        UsbDebugPortHandle->TimerFrequency,\r
-                        Timeout\r
-                        ),\r
-                      1000000u\r
-                      );\r
-    TimerRound = DivU64x64Remainder (\r
-                   TimeoutTicker,\r
-                   DivU64x32 (UsbDebugPortHandle->TimerCycle, 2),\r
-                   &TimeoutTicker\r
-                   );\r
-  }\r
-\r
-  //\r
-  // Read remaining data by executing one or more usb debug transfer transactions at usb debug port hw.\r
-  //\r
-  while (Total < NumberOfBytes) {\r
-    if (Timeout != 0) {\r
-      if (TimerRound == 0) {\r
-        if (IsTimerTimeout (UsbDebugPortHandle, Begin, TimeoutTicker)) {\r
-          //\r
-          // If time out occurs.\r
-          //\r
-          return 0;\r
-        }\r
-      } else {\r
-        if (IsTimerTimeout (UsbDebugPortHandle, Begin, DivU64x32 (UsbDebugPortHandle->TimerCycle, 2))) {\r
-          TimerRound --;\r
-        }\r
-      }\r
-    }\r
-    Remaining = NumberOfBytes - Total;\r
-    if (Remaining >= XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE) {\r
-      Received = XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE;\r
-      Status = XhcDataTransfer (UsbDebugPortHandle, EfiUsbDataIn, Buffer + Total, &Received, DATA_TRANSFER_READ_TIMEOUT);\r
-    } else {\r
-      Received = XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE;\r
-      Status = XhcDataTransfer (UsbDebugPortHandle, EfiUsbDataIn, (VOID *)Data, &Received, DATA_TRANSFER_READ_TIMEOUT);\r
-      UsbDebugPortHandle->DataCount = (UINT8) Received;\r
-\r
-      if (Remaining <= Received) {\r
-        //\r
-        // The data received are more than required\r
-        //\r
-        Length = (UINT8)Remaining;\r
-      } else {\r
-        //\r
-        // The data received are less than the remaining bytes\r
-        //\r
-        Length = (UINT8)Received;\r
-      }\r
-\r
-      //\r
-      // Copy required data from the data buffer to user buffer.\r
-      //\r
-      for (Index = 0; Index < Length; Index++) {\r
-        (Buffer + Total)[Index] = Data[Index];\r
-        UsbDebugPortHandle->DataCount--;\r
-      }\r
-\r
-      //\r
-      // reorder the data buffer to make available data arranged from the beginning of the data buffer.\r
-      //\r
-      for (Index = 0; Index < Received - Length; Index++) {\r
-        if (Length + Index >= XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE) {\r
-          return 0;\r
-        }\r
-        Data[Index] = Data[Length + Index];\r
-      }\r
-      //\r
-      // fixup the real required length of data.\r
-      //\r
-      Received = Length;\r
-    }\r
-    Total += Received;\r
-  }\r
-  return Total;\r
 }\r
 \r
 /**\r
@@ -1179,8 +1020,6 @@ DebugPortInitialize (
   RETURN_STATUS             Status;\r
   USB3_DEBUG_PORT_HANDLE    Handle;\r
   USB3_DEBUG_PORT_HANDLE    *UsbDebugPortHandle;\r
-  UINT64                    TimerStartValue;\r
-  UINT64                    TimerEndValue;\r
 \r
   //\r
   // Validate the PCD PcdDebugPortHandleBufferSize value \r
@@ -1194,19 +1033,6 @@ DebugPortInitialize (
     UsbDebugPortHandle = &Handle;\r
   }\r
 \r
-  UsbDebugPortHandle->TimerFrequency = GetPerformanceCounterProperties (\r
-                                         &TimerStartValue,\r
-                                         &TimerEndValue\r
-                                         );\r
-\r
-  if (TimerEndValue < TimerStartValue) {\r
-    UsbDebugPortHandle->TimerCountDown = TRUE;\r
-    UsbDebugPortHandle->TimerCycle     = TimerStartValue - TimerEndValue;\r
-  } else {\r
-    UsbDebugPortHandle->TimerCountDown = FALSE;\r
-    UsbDebugPortHandle->TimerCycle     = TimerEndValue - TimerStartValue;\r
-  }   \r
-\r
   if (Function == NULL && Context != NULL) {\r
     return (DEBUG_PORT_HANDLE *) Context;\r
   }\r
index 88c3723b09b84870110acf9f3700a357bb7e9050..c029219aef2776c3d3238900253f64265c1cc4d8 100644 (file)
@@ -55,7 +55,7 @@
 \r
   # The value of data buffer size used for USB debug port handle.\r
   # It should be equal to sizeof (USB3_DEBUG_PORT_HANDLE).\r
-  gEfiSourceLevelDebugPkgTokenSpaceGuid.PcdDebugPortHandleBufferSize|256   ## SOMETIMES_CONSUMES\r
+  gEfiSourceLevelDebugPkgTokenSpaceGuid.PcdDebugPortHandleBufferSize|239   ## SOMETIMES_CONSUMES\r
 \r
 [LibraryClasses]\r
   BaseLib\r
index 9190853c568282c91f78d52cb9d55b7eb58f1277..356485c5f6973fa0150406a7b56115d9ab8a19ab 100644 (file)
@@ -83,7 +83,7 @@
 #define DATA_TRANSFER_WRITE_TIMEOUT      0\r
 #define DATA_TRANSFER_READ_TIMEOUT       50000\r
 #define DATA_TRANSFER_POLL_TIMEOUT       1000\r
-\r
+#define XHC_DEBUG_PORT_1_MILLISECOND     1000\r
 //\r
 // XHCI port power off/on delay\r
 //\r
@@ -524,13 +524,6 @@ typedef struct _USB3_DEBUG_PORT_INSTANCE {
   // The data buffer address for data read and poll.\r
   //\r
   EFI_PHYSICAL_ADDRESS                    Data;\r
-  //\r
-  // Timter settings\r
-  //\r
-  UINT64                                  TimerFrequency;\r
-  UINT64                                  TimerCycle;\r
-  BOOLEAN                                 TimerCountDown;\r
-\r
 } USB3_DEBUG_PORT_HANDLE;\r
 \r
 #pragma pack()\r
@@ -735,22 +728,4 @@ XhcDataTransfer (
   IN     UINTN                               Timeout\r
   );\r
 \r
-/**\r
-  Check if the timer is timeout.\r
-  \r
-  @param[in] UsbDebugPortHandle  Pointer to USB Debug port handle\r
-  @param[in] Timer               The start timer from the begin.\r
-  @param[in] TimeoutTicker       Ticker number need time out.\r
-\r
-  @return TRUE  Timer time out occurs.\r
-  @retval FALSE Timer does not time out.\r
-\r
-**/\r
-BOOLEAN\r
-IsTimerTimeout (\r
-  IN USB3_DEBUG_PORT_HANDLE  *UsbDebugPortHandle,\r
-  IN UINT64                  Timer,\r
-  IN UINT64                  TimeoutTicker\r
-  );\r
-\r
 #endif //__SERIAL_PORT_LIB_USB__\r
index fbc04f3aa433032c43f0843ddd853c4431c798e5..74dcdd124b4780ce48d0c22c00f52448a61be3fb 100644 (file)
@@ -55,7 +55,7 @@
 \r
   # The value of data buffer size used for USB debug port handle.\r
   # It should be equal to sizeof (USB3_DEBUG_PORT_HANDLE).\r
-  gEfiSourceLevelDebugPkgTokenSpaceGuid.PcdDebugPortHandleBufferSize|256   ## SOMETIMES_CONSUMES\r
+  gEfiSourceLevelDebugPkgTokenSpaceGuid.PcdDebugPortHandleBufferSize|239   ## SOMETIMES_CONSUMES\r
 \r
 [LibraryClasses]\r
   BaseLib\r
index deb802e4adf4d9cd35a3fe6445de77190e6d6d28..773a7bd9c57ef8b61cdd90d11fad38cabea1f34e 100644 (file)
@@ -356,58 +356,31 @@ XhcExecTransfer (
   )\r
 {\r
   TRANSFER_RING           *Ring;\r
-  UINT64                  Begin;\r
-  UINT64                  TimeoutTicker;\r
-  UINT64                  TimerRound;\r
   TRB_TEMPLATE            *Trb;\r
+  UINTN                   Loop;\r
+  UINTN                   Index;\r
 \r
-  Begin         = 0;\r
-  TimeoutTicker = 0;  \r
-  TimerRound    = 0;\r
-\r
-  XhcRingDoorBell (Handle, Urb);\r
-\r
-  if (Timeout != 0) {\r
-    Begin = GetPerformanceCounter ();\r
-    TimeoutTicker = DivU64x32 (\r
-                      MultU64x64 (\r
-                        Handle->TimerFrequency,\r
-                        Timeout\r
-                        ),\r
-                      1000000u\r
-                      );\r
-    TimerRound = DivU64x64Remainder (\r
-                   TimeoutTicker,\r
-                   DivU64x32 (Handle->TimerCycle, 2),\r
-                   &TimeoutTicker\r
-                   );\r
+  Loop = Timeout / XHC_DEBUG_PORT_1_MILLISECOND;\r
+  if (Timeout == 0) {\r
+    Loop = 0xFFFFFFFF;\r
   }\r
-\r
+  XhcRingDoorBell (Handle, Urb);\r
   //\r
   // Event Ring Not Empty bit can only be set to 1 by XHC after ringing door bell with some delay.\r
   //\r
-  while (TRUE) {\r
-    if (Timeout != 0) {\r
-      if (TimerRound == 0) {\r
-        if (IsTimerTimeout (Handle, Begin, TimeoutTicker)) {\r
-          //\r
-          // If time out occurs.\r
-          //\r
-          Urb->Result |= EFI_USB_ERR_TIMEOUT;\r
-          break;\r
-        }\r
-      } else {\r
-        if (IsTimerTimeout (Handle, Begin, DivU64x32 (Handle->TimerCycle, 2))) {\r
-          TimerRound --;\r
-        }\r
-      }\r
-    }\r
+  for (Index = 0; Index < Loop; Index++) {\r
     XhcCheckUrbResult (Handle, Urb);\r
     if (Urb->Finished) {\r
       break;\r
     }\r
+    MicroSecondDelay (XHC_DEBUG_PORT_1_MILLISECOND);\r
   }\r
-  \r
+  if (Index == Loop) {\r
+    //\r
+    // If time out occurs.\r
+    //\r
+    Urb->Result |= EFI_USB_ERR_TIMEOUT;\r
+  } \r
   //\r
   // If URB transfer is error, restore transfer ring to original value before URB transfer\r
   // This will make the current transfer TRB is always at the latest unused one in transfer ring.\r