summaryrefslogtreecommitdiff
path: root/SourceLevelDebugPkg/Library/DebugCommunicationLibSerialPort
diff options
context:
space:
mode:
authorJeff Fan <jeff.fan@intel.com>2015-04-01 07:51:15 +0000
committervanjeff <vanjeff@Edk2>2015-04-01 07:51:15 +0000
commit08021523f8a581437b07986d2c1876a7b6f0d282 (patch)
tree5a6684e3bcb26373da7ef36a7a2a818e67de0e0c /SourceLevelDebugPkg/Library/DebugCommunicationLibSerialPort
parent206f412113e8be0da9bd6fd16f89c045ce0d8366 (diff)
downloadedk2-platforms-08021523f8a581437b07986d2c1876a7b6f0d282.tar.xz
SourceLevelDebugPkg: Use CPU Local APIC timer to handle timeout.
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
Diffstat (limited to 'SourceLevelDebugPkg/Library/DebugCommunicationLibSerialPort')
-rw-r--r--SourceLevelDebugPkg/Library/DebugCommunicationLibSerialPort/DebugCommunicationLibSerialPort.c177
-rw-r--r--SourceLevelDebugPkg/Library/DebugCommunicationLibSerialPort/DebugCommunicationLibSerialPort.inf9
2 files changed, 7 insertions, 179 deletions
diff --git a/SourceLevelDebugPkg/Library/DebugCommunicationLibSerialPort/DebugCommunicationLibSerialPort.c b/SourceLevelDebugPkg/Library/DebugCommunicationLibSerialPort/DebugCommunicationLibSerialPort.c
index 3a5f1969b2..388286b406 100644
--- a/SourceLevelDebugPkg/Library/DebugCommunicationLibSerialPort/DebugCommunicationLibSerialPort.c
+++ b/SourceLevelDebugPkg/Library/DebugCommunicationLibSerialPort/DebugCommunicationLibSerialPort.c
@@ -1,7 +1,7 @@
/** @file
Debug Port Library implementation based on serial port.
- Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -16,82 +16,7 @@
#include <Library/DebugCommunicationLib.h>
#include <Library/SerialPortLib.h>
-#include <Library/TimerLib.h>
#include <Library/DebugLib.h>
-#include <Library/BaseLib.h>
-#include <Library/BaseMemoryLib.h>
-
-#pragma pack(1)
-//
-// The internal data structure of DEBUG_PORT_HANDLE, which stores some
-// important datum which are used across various phases.
-//
-typedef struct _SERIAL_DEBUG_PORT_HANDLE{
- //
- // Timter settings
- //
- UINT64 TimerFrequency;
- UINT64 TimerCycle;
- BOOLEAN TimerCountDown;
-} SERIAL_DEBUG_PORT_HANDLE;
-#pragma pack()
-
-//
-// The global variable which can be used after memory is ready.
-//
-SERIAL_DEBUG_PORT_HANDLE mSerialDebugPortHandle;
-
-/**
- Check if the timer is timeout.
-
- @param[in] SerialDebugPortHandle Pointer to Serial Debug port handle
- @param[in] Timer The start timer from the begin.
- @param[in] TimeoutTicker Ticker number need time out.
-
- @return TRUE Timer time out occurs.
- @retval FALSE Timer does not time out.
-
-**/
-BOOLEAN
-IsTimerTimeout (
- IN SERIAL_DEBUG_PORT_HANDLE *SerialDebugPortHandle,
- IN UINT64 Timer,
- IN UINT64 TimeoutTicker
- )
-{
- UINT64 CurrentTimer;
- UINT64 Delta;
-
- CurrentTimer = GetPerformanceCounter ();
-
- if (SerialDebugPortHandle->TimerCountDown) {
- //
- // The timer counter counts down. Check for roll over condition.
- //
- if (CurrentTimer < Timer) {
- Delta = Timer - CurrentTimer;
- } else {
- //
- // Handle one roll-over.
- //
- Delta = SerialDebugPortHandle->TimerCycle - (CurrentTimer - Timer);
- }
- } else {
- //
- // The timer counter counts up. Check for roll over condition.
- //
- if (CurrentTimer > Timer) {
- Delta = CurrentTimer - Timer;
- } else {
- //
- // Handle one roll-over.
- //
- Delta = SerialDebugPortHandle->TimerCycle - (Timer - CurrentTimer);
- }
- }
-
- return (BOOLEAN) (Delta >= TimeoutTicker);
-}
/**
Initialize the debug port.
@@ -136,42 +61,7 @@ DebugPortInitialize (
IN DEBUG_PORT_CONTINUE Function
)
{
- RETURN_STATUS Status;
- SERIAL_DEBUG_PORT_HANDLE Handle;
- SERIAL_DEBUG_PORT_HANDLE *SerialDebugPortHandle;
- UINT64 TimerStartValue;
- UINT64 TimerEndValue;
-
- //
- // Validate the PCD PcdDebugPortHandleBufferSize value
- //
- ASSERT (PcdGet16 (PcdDebugPortHandleBufferSize) == sizeof (SERIAL_DEBUG_PORT_HANDLE));
-
- if (Context != NULL && Function == NULL) {
- SerialDebugPortHandle = (SERIAL_DEBUG_PORT_HANDLE *)Context;
- } else {
- ZeroMem (&Handle, sizeof (SERIAL_DEBUG_PORT_HANDLE));
- SerialDebugPortHandle = &Handle;
- }
- SerialDebugPortHandle->TimerFrequency = GetPerformanceCounterProperties (
- &TimerStartValue,
- &TimerEndValue
- );
- DEBUG ((EFI_D_INFO, "Serial Debug Port: TimerFrequency = 0x%lx\n", SerialDebugPortHandle->TimerFrequency));
- DEBUG ((EFI_D_INFO, "Serial Debug Port: TimerStartValue = 0x%lx\n", TimerStartValue));
- DEBUG ((EFI_D_INFO, "Serial Debug Port: TimerEndValue = 0x%lx\n", TimerEndValue));
-
- if (TimerEndValue < TimerStartValue) {
- SerialDebugPortHandle->TimerCountDown = TRUE;
- SerialDebugPortHandle->TimerCycle = TimerStartValue - TimerEndValue;
- } else {
- SerialDebugPortHandle->TimerCountDown = FALSE;
- SerialDebugPortHandle->TimerCycle = TimerEndValue - TimerStartValue;
- }
-
- if (Function == NULL && Context != NULL) {
- return (DEBUG_PORT_HANDLE *) Context;
- }
+ RETURN_STATUS Status;
Status = SerialPortInitialize ();
if (RETURN_ERROR(Status)) {
@@ -179,12 +69,10 @@ DebugPortInitialize (
}
if (Function != NULL) {
- Function (Context, SerialDebugPortHandle);
- } else {
- CopyMem(&mSerialDebugPortHandle, SerialDebugPortHandle, sizeof (SERIAL_DEBUG_PORT_HANDLE));
+ Function (Context, NULL);
}
- return (DEBUG_PORT_HANDLE)(UINTN)&mSerialDebugPortHandle;
+ return NULL;
}
/**
@@ -213,62 +101,11 @@ DebugPortReadBuffer (
IN UINTN Timeout
)
{
- SERIAL_DEBUG_PORT_HANDLE *SerialDebugPortHandle;
- UINTN Index;
- UINT64 Begin;
- UINT64 TimeoutTicker;
- UINT64 TimerRound;
-
- //
- // If Handle is NULL, it means memory is ready for use.
- // Use global variable to store handle value.
- //
- if (Handle == NULL) {
- SerialDebugPortHandle = &mSerialDebugPortHandle;
- } else {
- SerialDebugPortHandle = (SERIAL_DEBUG_PORT_HANDLE *)Handle;
- }
-
- Begin = 0;
- TimeoutTicker = 0;
- TimerRound = 0;
- if (Timeout != 0) {
- Begin = GetPerformanceCounter ();
- TimeoutTicker = DivU64x32 (
- MultU64x64 (
- SerialDebugPortHandle->TimerFrequency,
- Timeout
- ),
- 1000000u
- );
- TimerRound = DivU64x64Remainder (
- TimeoutTicker,
- DivU64x32 (SerialDebugPortHandle->TimerCycle, 2),
- &TimeoutTicker
- );
- }
- Index = 0;
- while (Index < NumberOfBytes) {
- if (SerialPortPoll () || Timeout == 0) {
- SerialPortRead (Buffer + Index, 1);
- Index ++;
- continue;
- }
- if (TimerRound == 0) {
- if (IsTimerTimeout (SerialDebugPortHandle, Begin, TimeoutTicker)) {
- //
- // If time out occurs.
- //
- return 0;
- }
- } else {
- if (IsTimerTimeout (SerialDebugPortHandle, Begin, DivU64x32 (SerialDebugPortHandle->TimerCycle, 2))) {
- TimerRound --;
- }
- }
+ if (NumberOfBytes != 1 || Buffer == NULL || Timeout != 0) {
+ return 0;
}
- return Index;
+ return SerialPortRead (Buffer, 1);
}
/**
diff --git a/SourceLevelDebugPkg/Library/DebugCommunicationLibSerialPort/DebugCommunicationLibSerialPort.inf b/SourceLevelDebugPkg/Library/DebugCommunicationLibSerialPort/DebugCommunicationLibSerialPort.inf
index 640d0833a5..50b24c21d1 100644
--- a/SourceLevelDebugPkg/Library/DebugCommunicationLibSerialPort/DebugCommunicationLibSerialPort.inf
+++ b/SourceLevelDebugPkg/Library/DebugCommunicationLibSerialPort/DebugCommunicationLibSerialPort.inf
@@ -35,13 +35,4 @@
[LibraryClasses]
SerialPortLib
- TimerLib
DebugLib
- BaseMemoryLib
- BaseLib
-
-[PCD]
- # The value of data buffer size used for Serial debug port handle.
- # It should be equal to sizeof (SERIAL_DEBUG_PORT_HANDLE).
- gEfiSourceLevelDebugPkgTokenSpaceGuid.PcdDebugPortHandleBufferSize|17 ## SOMETIMES_CONSUMES
-