diff options
author | vanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524> | 2013-01-25 02:36:18 +0000 |
---|---|---|
committer | vanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524> | 2013-01-25 02:36:18 +0000 |
commit | b422b62c01a490e7892864c04280d430a2566e3f (patch) | |
tree | 1256106c1730868c3040ba879e430cb2550e04be /SourceLevelDebugPkg/Library/DebugCommunicationLibSerialPort | |
parent | b7d269eae175a25d9d6df8e09feb55a3d23eeab0 (diff) | |
download | edk2-platforms-b422b62c01a490e7892864c04280d430a2566e3f.tar.xz |
This revision can only work with Intel(c) UDK Debugger Tool version 1.3 or greater. Detailed change log is as below:
1. Add DebugAgentPei driver to initialize Debug Agent in PEI phase.
Add DebugAgentDxe driver to initialize Debug Agent in DXE phase.
DebugAgentDxe driver could be loaded and unloaded in shell.
2. Update the SourceLevelDebugPkg so that the debug agent can be initialized in any phase: SEC, PEI or DXE.
3. Add an enhanced retry algorithm that provides a robust connection when data loss happens in the debug channel.
4. Clear DR7 register in exception handler.
5. Set the default serial port parameter to 0 instead of PCDs.
6. Build pointer of Mailbox in HOB instead of Mailbox itself, since HOB may be moved at DXE entry point function.
7. Raise TPL to prevent recursion from EFI timer interrupts in SerialIo.c.
8. Add one spin lock for accessing Mailbox when MP debugging supported.
9. Use more non-NULL library instances in SourceLevelDebugPkg DSC file, thus DebugAgentDxe.efi built from SourceLevelDebugPkg could work in shell.
10.Separate all operations about IDT table entry from SecDebugAgentLib.c into DebugAgent\DebugAgentCommon's arch sub-directory.
11.Enhance Debug Agent to avoid breaking by hardware SMI during DXE debugging phase.
12.Add supporting on mode switch code debugging.
13.Remove reset Host Controller operation in DebugCommunicationLibUsb.c to avoid impacting EDKII usb stack.
14.Fix debug timer interrupt missing issue after back from legacy code.
Signed-off-by: Jeff Fan <jeff.fan@intel.com>
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Signed-off-by: Feng Tian <feng.tian@intel.com>
Reviewed-by: Jeff Fan <jeff.fan@intel.com>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Feng Tian <feng.tian@intel.com>
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@14083 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'SourceLevelDebugPkg/Library/DebugCommunicationLibSerialPort')
2 files changed, 174 insertions, 20 deletions
diff --git a/SourceLevelDebugPkg/Library/DebugCommunicationLibSerialPort/DebugCommunicationLibSerialPort.c b/SourceLevelDebugPkg/Library/DebugCommunicationLibSerialPort/DebugCommunicationLibSerialPort.c index dd88e7d693..9523216591 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 - 2011, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2010 - 2013, 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
@@ -18,6 +18,80 @@ #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.
@@ -62,7 +136,42 @@ DebugPortInitialize ( IN DEBUG_PORT_CONTINUE Function
)
{
- RETURN_STATUS Status;
+ 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;
+ }
Status = SerialPortInitialize ();
if (RETURN_ERROR(Status)) {
@@ -70,10 +179,12 @@ DebugPortInitialize ( }
if (Function != NULL) {
- Function (Context, NULL);
+ Function (Context, SerialDebugPortHandle);
+ } else {
+ CopyMem(&mSerialDebugPortHandle, SerialDebugPortHandle, sizeof (SERIAL_DEBUG_PORT_HANDLE));
}
- return NULL;
+ return (DEBUG_PORT_HANDLE)(UINTN)&mSerialDebugPortHandle;
}
/**
@@ -102,25 +213,62 @@ DebugPortReadBuffer ( IN UINTN Timeout
)
{
- UINTN Index;
- INTN Elapsed;
-
- for (Index = 0; Index < NumberOfBytes; Index ++) {
- Elapsed = (INTN) Timeout;
- while (TRUE) {
- if (SerialPortPoll () || Timeout == 0) {
- SerialPortRead (Buffer + Index, 1);
- break;
- }
- MicroSecondDelay (1000);
- Elapsed -= 1000;
- if (Elapsed < 0) {
+ 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 --;
+ }
}
}
- return NumberOfBytes;
+ return Index;
}
/**
diff --git a/SourceLevelDebugPkg/Library/DebugCommunicationLibSerialPort/DebugCommunicationLibSerialPort.inf b/SourceLevelDebugPkg/Library/DebugCommunicationLibSerialPort/DebugCommunicationLibSerialPort.inf index 6d36cefd74..6ee5ddccee 100644 --- a/SourceLevelDebugPkg/Library/DebugCommunicationLibSerialPort/DebugCommunicationLibSerialPort.inf +++ b/SourceLevelDebugPkg/Library/DebugCommunicationLibSerialPort/DebugCommunicationLibSerialPort.inf @@ -1,7 +1,7 @@ ## @file
# Debug Communication Library instance based on serila port.
#
-# Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2010 - 2013, 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
@@ -36,4 +36,10 @@ 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
|