SourceLevelDebugPkg: Apply uncrustify changes

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3737

Apply uncrustify changes to .c/.h files in the SourceLevelDebugPkg package

Cc: Andrew Fish <afish@apple.com>
Cc: Leif Lindholm <leif@nuviainc.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
This commit is contained in:
Michael Kubacki
2021-12-05 14:54:15 -08:00
committed by mergify[bot]
parent b878648967
commit c1e126b119
35 changed files with 3547 additions and 3381 deletions

View File

@ -46,7 +46,7 @@ DisableDebugTimerExitBootService (
**/ **/
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
DebugAgentDxeInitialize( DebugAgentDxeInitialize (
IN EFI_HANDLE ImageHandle, IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable IN EFI_SYSTEM_TABLE *SystemTable
) )
@ -81,14 +81,17 @@ DebugAgentDxeInitialize(
Print (L"3: Shell> disconnect EA\r\n"); Print (L"3: Shell> disconnect EA\r\n");
Print (L"4: Shell> load -nc DebugAgentDxe.efi\r\n\r\n"); Print (L"4: Shell> load -nc DebugAgentDxe.efi\r\n\r\n");
} }
Status = EFI_UNSUPPORTED; Status = EFI_UNSUPPORTED;
InitializeDebugAgent (DEBUG_AGENT_INIT_DXE_LOAD, &Status, NULL); InitializeDebugAgent (DEBUG_AGENT_INIT_DXE_LOAD, &Status, NULL);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
if (gST->ConOut != NULL) { if (gST->ConOut != NULL) {
Print (L"Debug Agent: Initialized successfully!\r\n\r\n"); Print (L"Debug Agent: Initialized successfully!\r\n\r\n");
} }
// //
// Create event to disable Debug Timer interrupt when exit boot service. // Create event to disable Debug Timer interrupt when exit boot service.
// //

View File

@ -301,4 +301,3 @@ typedef struct {
#pragma pack() #pragma pack()
#endif #endif

View File

@ -19,4 +19,3 @@
#define DEBUG_AGENT_IMAGE_CONTINUE 0x01 #define DEBUG_AGENT_IMAGE_CONTINUE 0x01
#endif #endif

View File

@ -9,7 +9,7 @@
#ifndef __DEBUG_COMMUNICATION_LIB_H__ #ifndef __DEBUG_COMMUNICATION_LIB_H__
#define __DEBUG_COMMUNICATION_LIB_H__ #define __DEBUG_COMMUNICATION_LIB_H__
typedef VOID * DEBUG_PORT_HANDLE; typedef VOID *DEBUG_PORT_HANDLE;
/** /**
Caller provided function to be invoked at the end of DebugPortInitialize(). Caller provided function to be invoked at the end of DebugPortInitialize().
@ -22,7 +22,7 @@ typedef VOID * DEBUG_PORT_HANDLE;
**/ **/
typedef typedef
VOID VOID
(EFIAPI * DEBUG_PORT_CONTINUE)( (EFIAPI *DEBUG_PORT_CONTINUE)(
IN VOID *Context, IN VOID *Context,
IN DEBUG_PORT_HANDLE DebugPortHandle IN DEBUG_PORT_HANDLE DebugPortHandle
); );
@ -70,7 +70,6 @@ DebugPortInitialize (
IN DEBUG_PORT_CONTINUE Function IN DEBUG_PORT_CONTINUE Function
); );
/** /**
Read data from debug device and save the datas in buffer. Read data from debug device and save the datas in buffer.
@ -97,7 +96,6 @@ DebugPortReadBuffer (
IN UINTN Timeout IN UINTN Timeout
); );
/** /**
Write data from buffer to debug device. Write data from buffer to debug device.
@ -143,4 +141,3 @@ DebugPortPollBuffer (
); );
#endif #endif

View File

@ -167,10 +167,10 @@ typedef struct {
#define DEBUG_DATA_BREAK_CPU_ARCH_X64 2 #define DEBUG_DATA_BREAK_CPU_ARCH_X64 2
typedef struct { typedef struct {
UINT8 Length:2; // Refer to below DEBUG_DATA_BREAKPOINT_LENGTH_XX macros UINT8 Length : 2; // Refer to below DEBUG_DATA_BREAKPOINT_LENGTH_XX macros
UINT8 Access:2; // Refer to below DEBUG_DATA_BREAKPOINT_ACCESS_XX macros UINT8 Access : 2; // Refer to below DEBUG_DATA_BREAKPOINT_ACCESS_XX macros
UINT8 Index:2; // Index of debug register UINT8 Index : 2; // Index of debug register
UINT8 Reserved:2; UINT8 Reserved : 2;
} DEBUG_DATA_BREAKPOINT_TYPE; } DEBUG_DATA_BREAKPOINT_TYPE;
#define DEBUG_DATA_BREAKPOINT_MEMORY_ACCESS (0x3) #define DEBUG_DATA_BREAKPOINT_MEMORY_ACCESS (0x3)
#define DEBUG_DATA_BREAKPOINT_IO_ACCESS (0x2) #define DEBUG_DATA_BREAKPOINT_IO_ACCESS (0x2)
@ -367,4 +367,3 @@ typedef struct {
#pragma pack() #pragma pack()
#endif #endif

View File

@ -147,16 +147,15 @@ typedef struct {
/// ///
typedef union { typedef union {
struct { struct {
UINT32 OffsetLow:16; ///< Offset bits 15..0. UINT32 OffsetLow : 16; ///< Offset bits 15..0.
UINT32 Selector:16; ///< Selector. UINT32 Selector : 16; ///< Selector.
UINT32 Reserved_0:8; ///< Reserved. UINT32 Reserved_0 : 8; ///< Reserved.
UINT32 GateType:8; ///< Gate Type. See #defines above. UINT32 GateType : 8; ///< Gate Type. See #defines above.
UINT32 OffsetHigh:16; ///< Offset bits 31..16. UINT32 OffsetHigh : 16; ///< Offset bits 31..16.
} Bits; } Bits;
UINT64 Uint64; UINT64 Uint64;
} IA32_IDT_ENTRY; } IA32_IDT_ENTRY;
typedef union { typedef union {
struct { struct {
UINT32 LimitLow : 16; UINT32 LimitLow : 16;
@ -495,4 +494,3 @@ DebugAgentReadBuffer (
); );
#endif #endif

View File

@ -8,9 +8,9 @@
#include "DebugAgent.h" #include "DebugAgent.h"
GLOBAL_REMOVE_IF_UNREFERENCED DEBUG_MP_CONTEXT volatile mDebugMpContext = {0,0,0,{0},{0},0,0,0,0,FALSE,FALSE}; GLOBAL_REMOVE_IF_UNREFERENCED DEBUG_MP_CONTEXT volatile mDebugMpContext = { 0, 0, 0, { 0 }, { 0 }, 0, 0, 0, 0, FALSE, FALSE };
GLOBAL_REMOVE_IF_UNREFERENCED DEBUG_CPU_DATA volatile mDebugCpuData = {0}; GLOBAL_REMOVE_IF_UNREFERENCED DEBUG_CPU_DATA volatile mDebugCpuData = { 0 };
/** /**
Acquire a spin lock when Multi-processor supported. Acquire a spin lock when Multi-processor supported.
@ -26,7 +26,7 @@ AcquireMpSpinLock (
IN OUT SPIN_LOCK *MpSpinLock IN OUT SPIN_LOCK *MpSpinLock
) )
{ {
if (!MultiProcessorDebugSupport()) { if (!MultiProcessorDebugSupport ()) {
return; return;
} }
@ -34,6 +34,7 @@ AcquireMpSpinLock (
if (AcquireSpinLockOrFail (MpSpinLock)) { if (AcquireSpinLockOrFail (MpSpinLock)) {
break; break;
} }
CpuPause (); CpuPause ();
continue; continue;
} }
@ -50,7 +51,7 @@ ReleaseMpSpinLock (
IN OUT SPIN_LOCK *MpSpinLock IN OUT SPIN_LOCK *MpSpinLock
) )
{ {
if (!MultiProcessorDebugSupport()) { if (!MultiProcessorDebugSupport ()) {
return; return;
} }
@ -70,7 +71,7 @@ HaltOtherProcessors (
{ {
DebugAgentMsgPrint (DEBUG_AGENT_INFO, "processor[%x]:Try to halt other processors.\n", CurrentProcessorIndex); DebugAgentMsgPrint (DEBUG_AGENT_INFO, "processor[%x]:Try to halt other processors.\n", CurrentProcessorIndex);
if (!DebugAgentIsBsp (CurrentProcessorIndex)) { if (!DebugAgentIsBsp (CurrentProcessorIndex)) {
SetIpiSentByApFlag (TRUE);; SetIpiSentByApFlag (TRUE);
} }
mDebugMpContext.BreakAtCpuIndex = CurrentProcessorIndex; mDebugMpContext.BreakAtCpuIndex = CurrentProcessorIndex;
@ -84,7 +85,6 @@ HaltOtherProcessors (
// Send fixed IPI to other processors. // Send fixed IPI to other processors.
// //
SendFixedIpiAllExcludingSelf (DEBUG_TIMER_VECTOR); SendFixedIpiAllExcludingSelf (DEBUG_TIMER_VECTOR);
} }
/** /**
@ -101,11 +101,11 @@ GetProcessorIndex (
UINT32 Index; UINT32 Index;
UINT16 LocalApicID; UINT16 LocalApicID;
LocalApicID = (UINT16) GetApicId (); LocalApicID = (UINT16)GetApicId ();
AcquireMpSpinLock (&mDebugMpContext.MpContextSpinLock); AcquireMpSpinLock (&mDebugMpContext.MpContextSpinLock);
for (Index = 0; Index < mDebugCpuData.CpuCount; Index ++) { for (Index = 0; Index < mDebugCpuData.CpuCount; Index++) {
if (mDebugCpuData.ApicID[Index] == LocalApicID) { if (mDebugCpuData.ApicID[Index] == LocalApicID) {
break; break;
} }
@ -113,7 +113,7 @@ GetProcessorIndex (
if (Index == mDebugCpuData.CpuCount) { if (Index == mDebugCpuData.CpuCount) {
mDebugCpuData.ApicID[Index] = LocalApicID; mDebugCpuData.ApicID[Index] = LocalApicID;
mDebugCpuData.CpuCount ++ ; mDebugCpuData.CpuCount++;
} }
ReleaseMpSpinLock (&mDebugMpContext.MpContextSpinLock); ReleaseMpSpinLock (&mDebugMpContext.MpContextSpinLock);
@ -153,6 +153,7 @@ DebugAgentIsBsp (
mDebugMpContext.BspIndex = ProcessorIndex; mDebugMpContext.BspIndex = ProcessorIndex;
ReleaseMpSpinLock (&mDebugMpContext.MpContextSpinLock); ReleaseMpSpinLock (&mDebugMpContext.MpContextSpinLock);
} }
return TRUE; return TRUE;
} else { } else {
return FALSE; return FALSE;
@ -185,6 +186,7 @@ SetCpuStopFlagByIndex (
} else { } else {
Value = BitFieldWrite8 (Value, Index, Index, 0); Value = BitFieldWrite8 (Value, Index, Index, 0);
} }
mDebugMpContext.CpuStopStatusMask[ProcessorIndex / 8] = Value; mDebugMpContext.CpuStopStatusMask[ProcessorIndex / 8] = Value;
ReleaseMpSpinLock (&mDebugMpContext.MpContextSpinLock); ReleaseMpSpinLock (&mDebugMpContext.MpContextSpinLock);
@ -216,6 +218,7 @@ SetCpuBreakFlagByIndex (
} else { } else {
Value = BitFieldWrite8 (Value, Index, Index, 0); Value = BitFieldWrite8 (Value, Index, Index, 0);
} }
mDebugMpContext.CpuBreakMask[ProcessorIndex / 8] = Value; mDebugMpContext.CpuBreakMask[ProcessorIndex / 8] = Value;
ReleaseMpSpinLock (&mDebugMpContext.MpContextSpinLock); ReleaseMpSpinLock (&mDebugMpContext.MpContextSpinLock);
@ -237,7 +240,7 @@ IsCpuStopped (
{ {
UINT8 CpuMask; UINT8 CpuMask;
CpuMask = (UINT8) (1 << (ProcessorIndex % 8)); CpuMask = (UINT8)(1 << (ProcessorIndex % 8));
if ((mDebugMpContext.CpuStopStatusMask[ProcessorIndex / 8] & CpuMask) != 0) { if ((mDebugMpContext.CpuStopStatusMask[ProcessorIndex / 8] & CpuMask) != 0) {
return TRUE; return TRUE;
@ -311,11 +314,12 @@ FindNextPendingBreakCpu (
{ {
UINT32 Index; UINT32 Index;
for (Index = 0; Index < DEBUG_CPU_MAX_COUNT / 8; Index ++) { for (Index = 0; Index < DEBUG_CPU_MAX_COUNT / 8; Index++) {
if (mDebugMpContext.CpuBreakMask[Index] != 0) { if (mDebugMpContext.CpuBreakMask[Index] != 0) {
return (UINT32) LowBitSet32 (mDebugMpContext.CpuBreakMask[Index]) + Index * 8; return (UINT32)LowBitSet32 (mDebugMpContext.CpuBreakMask[Index]) + Index * 8;
} }
} }
return (UINT32)-1; return (UINT32)-1;
} }
@ -333,11 +337,12 @@ IsAllCpuRunning (
{ {
UINTN Index; UINTN Index;
for (Index = 0; Index < DEBUG_CPU_MAX_COUNT / 8; Index ++) { for (Index = 0; Index < DEBUG_CPU_MAX_COUNT / 8; Index++) {
if (mDebugMpContext.CpuStopStatusMask[Index] != 0) { if (mDebugMpContext.CpuStopStatusMask[Index] != 0) {
return FALSE; return FALSE;
} }
} }
return TRUE; return TRUE;
} }
@ -357,8 +362,8 @@ IsFirstBreakProcessor (
IN UINT32 ProcessorIndex IN UINT32 ProcessorIndex
) )
{ {
if (MultiProcessorDebugSupport()) { if (MultiProcessorDebugSupport ()) {
if (mDebugMpContext.BreakAtCpuIndex != (UINT32) -1) { if (mDebugMpContext.BreakAtCpuIndex != (UINT32)-1) {
// //
// The current processor is not the first breaking one. // The current processor is not the first breaking one.
// //
@ -372,6 +377,6 @@ IsFirstBreakProcessor (
return TRUE; return TRUE;
} }
} }
return TRUE; return TRUE;
} }

View File

@ -213,4 +213,3 @@ IsFirstBreakProcessor (
); );
#endif #endif

View File

@ -28,7 +28,7 @@ InitializeDebugTimer (
InitializeLocalApicSoftwareEnable (TRUE); InitializeLocalApicSoftwareEnable (TRUE);
GetApicTimerState (&ApicTimerDivisor, NULL, NULL); GetApicTimerState (&ApicTimerDivisor, NULL, NULL);
ApicTimerFrequency = PcdGet32(PcdFSBClock) / (UINT32)ApicTimerDivisor; ApicTimerFrequency = PcdGet32 (PcdFSBClock) / (UINT32)ApicTimerDivisor;
// //
// Cpu Local Apic timer interrupt frequency, it is set to 0.1s // Cpu Local Apic timer interrupt frequency, it is set to 0.1s
// //
@ -48,14 +48,16 @@ InitializeDebugTimer (
DisableApicTimerInterrupt (); DisableApicTimerInterrupt ();
if (DumpFlag) { if (DumpFlag) {
DEBUG ((DEBUG_INFO, "Debug Timer: FSB Clock = %d\n", PcdGet32(PcdFSBClock))); DEBUG ((DEBUG_INFO, "Debug Timer: FSB Clock = %d\n", PcdGet32 (PcdFSBClock)));
DEBUG ((DEBUG_INFO, "Debug Timer: Divisor = %d\n", ApicTimerDivisor)); DEBUG ((DEBUG_INFO, "Debug Timer: Divisor = %d\n", ApicTimerDivisor));
DEBUG ((DEBUG_INFO, "Debug Timer: Frequency = %d\n", ApicTimerFrequency)); DEBUG ((DEBUG_INFO, "Debug Timer: Frequency = %d\n", ApicTimerFrequency));
DEBUG ((DEBUG_INFO, "Debug Timer: InitialCount = %d\n", InitialCount)); DEBUG ((DEBUG_INFO, "Debug Timer: InitialCount = %d\n", InitialCount));
} }
if (TimerFrequency != NULL) { if (TimerFrequency != NULL) {
*TimerFrequency = ApicTimerFrequency; *TimerFrequency = ApicTimerFrequency;
} }
return InitialCount; return InitialCount;
} }
@ -88,6 +90,7 @@ SaveAndSetDebugTimerInterrupt (
} else { } else {
DisableApicTimerInterrupt (); DisableApicTimerInterrupt ();
} }
// //
// Validate the Debug Timer interrupt state // Validate the Debug Timer interrupt state
// This will make additional delay after Local Apic Timer interrupt state is changed. // This will make additional delay after Local Apic Timer interrupt state is changed.
@ -138,5 +141,5 @@ IsDebugTimerTimeout (
Delta = TimerCycle - (CurrentTimer - Timer) + 1; Delta = TimerCycle - (CurrentTimer - Timer) + 1;
} }
return (BOOLEAN) (Delta >= TimeoutTicker); return (BOOLEAN)(Delta >= TimeoutTicker);
} }

View File

@ -42,4 +42,3 @@ IsDebugTimerTimeout (
); );
#endif #endif

View File

@ -31,15 +31,16 @@ InitializeDebugIdt (
// //
CodeSegment = AsmReadCs (); CodeSegment = AsmReadCs ();
IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *) IdtDescriptor.Base; IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *)IdtDescriptor.Base;
for (Index = 0; Index < 20; Index ++) { for (Index = 0; Index < 20; Index++) {
if (((PcdGet32 (PcdExceptionsIgnoredByDebugger) & ~(BIT1 | BIT3)) & (1 << Index)) != 0) { if (((PcdGet32 (PcdExceptionsIgnoredByDebugger) & ~(BIT1 | BIT3)) & (1 << Index)) != 0) {
// //
// If the exception is masked to be reserved except for INT1 and INT3, skip it // If the exception is masked to be reserved except for INT1 and INT3, skip it
// //
continue; continue;
} }
InterruptHandler = (UINTN)&Exception0Handle + Index * ExceptionStubHeaderSize; InterruptHandler = (UINTN)&Exception0Handle + Index * ExceptionStubHeaderSize;
IdtEntry[Index].Bits.OffsetLow = (UINT16)(UINTN)InterruptHandler; IdtEntry[Index].Bits.OffsetLow = (UINT16)(UINTN)InterruptHandler;
IdtEntry[Index].Bits.OffsetHigh = (UINT16)((UINTN)InterruptHandler >> 16); IdtEntry[Index].Bits.OffsetHigh = (UINT16)((UINTN)InterruptHandler >> 16);
@ -47,7 +48,7 @@ InitializeDebugIdt (
IdtEntry[Index].Bits.GateType = IA32_IDT_GATE_TYPE_INTERRUPT_32; IdtEntry[Index].Bits.GateType = IA32_IDT_GATE_TYPE_INTERRUPT_32;
} }
InterruptHandler = (UINTN) &TimerInterruptHandle; InterruptHandler = (UINTN)&TimerInterruptHandle;
IdtEntry[DEBUG_TIMER_VECTOR].Bits.OffsetLow = (UINT16)(UINTN)InterruptHandler; IdtEntry[DEBUG_TIMER_VECTOR].Bits.OffsetLow = (UINT16)(UINTN)InterruptHandler;
IdtEntry[DEBUG_TIMER_VECTOR].Bits.OffsetHigh = (UINT16)((UINTN)InterruptHandler >> 16); IdtEntry[DEBUG_TIMER_VECTOR].Bits.OffsetHigh = (UINT16)((UINTN)InterruptHandler >> 16);
IdtEntry[DEBUG_TIMER_VECTOR].Bits.Selector = CodeSegment; IdtEntry[DEBUG_TIMER_VECTOR].Bits.Selector = CodeSegment;
@ -80,9 +81,9 @@ GetExceptionHandlerInIdtEntry (
IA32_DESCRIPTOR IdtDescriptor; IA32_DESCRIPTOR IdtDescriptor;
AsmReadIdtr (&IdtDescriptor); AsmReadIdtr (&IdtDescriptor);
IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *) IdtDescriptor.Base; IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *)IdtDescriptor.Base;
return (VOID *) (((UINTN)IdtEntry[ExceptionNum].Bits.OffsetLow) | return (VOID *)(((UINTN)IdtEntry[ExceptionNum].Bits.OffsetLow) |
(((UINTN)IdtEntry[ExceptionNum].Bits.OffsetHigh) << 16)); (((UINTN)IdtEntry[ExceptionNum].Bits.OffsetHigh) << 16));
} }
@ -103,7 +104,7 @@ SetExceptionHandlerInIdtEntry (
IA32_DESCRIPTOR IdtDescriptor; IA32_DESCRIPTOR IdtDescriptor;
AsmReadIdtr (&IdtDescriptor); AsmReadIdtr (&IdtDescriptor);
IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *) IdtDescriptor.Base; IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *)IdtDescriptor.Base;
IdtEntry[ExceptionNum].Bits.OffsetLow = (UINT16)(UINTN)ExceptionHandler; IdtEntry[ExceptionNum].Bits.OffsetLow = (UINT16)(UINTN)ExceptionHandler;
IdtEntry[ExceptionNum].Bits.OffsetHigh = (UINT16)((UINTN)ExceptionHandler >> 16); IdtEntry[ExceptionNum].Bits.OffsetHigh = (UINT16)((UINTN)ExceptionHandler >> 16);

View File

@ -31,15 +31,16 @@ InitializeDebugIdt (
// //
CodeSegment = AsmReadCs (); CodeSegment = AsmReadCs ();
IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *) IdtDescriptor.Base; IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *)IdtDescriptor.Base;
for (Index = 0; Index < 20; Index ++) { for (Index = 0; Index < 20; Index++) {
if (((PcdGet32 (PcdExceptionsIgnoredByDebugger) & ~(BIT1 | BIT3)) & (1 << Index)) != 0) { if (((PcdGet32 (PcdExceptionsIgnoredByDebugger) & ~(BIT1 | BIT3)) & (1 << Index)) != 0) {
// //
// If the exception is masked to be reserved except for INT1 and INT3, skip it // If the exception is masked to be reserved except for INT1 and INT3, skip it
// //
continue; continue;
} }
InterruptHandler = (UINTN)&Exception0Handle + Index * ExceptionStubHeaderSize; InterruptHandler = (UINTN)&Exception0Handle + Index * ExceptionStubHeaderSize;
IdtEntry[Index].Bits.OffsetLow = (UINT16)(UINTN)InterruptHandler; IdtEntry[Index].Bits.OffsetLow = (UINT16)(UINTN)InterruptHandler;
IdtEntry[Index].Bits.OffsetHigh = (UINT16)((UINTN)InterruptHandler >> 16); IdtEntry[Index].Bits.OffsetHigh = (UINT16)((UINTN)InterruptHandler >> 16);
@ -48,7 +49,7 @@ InitializeDebugIdt (
IdtEntry[Index].Bits.GateType = IA32_IDT_GATE_TYPE_INTERRUPT_32; IdtEntry[Index].Bits.GateType = IA32_IDT_GATE_TYPE_INTERRUPT_32;
} }
InterruptHandler = (UINTN) &TimerInterruptHandle; InterruptHandler = (UINTN)&TimerInterruptHandle;
IdtEntry[DEBUG_TIMER_VECTOR].Bits.OffsetLow = (UINT16)(UINTN)InterruptHandler; IdtEntry[DEBUG_TIMER_VECTOR].Bits.OffsetLow = (UINT16)(UINTN)InterruptHandler;
IdtEntry[DEBUG_TIMER_VECTOR].Bits.OffsetHigh = (UINT16)((UINTN)InterruptHandler >> 16); IdtEntry[DEBUG_TIMER_VECTOR].Bits.OffsetHigh = (UINT16)((UINTN)InterruptHandler >> 16);
IdtEntry[DEBUG_TIMER_VECTOR].Bits.OffsetUpper = (UINT32)((UINTN)InterruptHandler >> 32); IdtEntry[DEBUG_TIMER_VECTOR].Bits.OffsetUpper = (UINT32)((UINTN)InterruptHandler >> 32);
@ -82,9 +83,9 @@ GetExceptionHandlerInIdtEntry (
IA32_DESCRIPTOR IdtDescriptor; IA32_DESCRIPTOR IdtDescriptor;
AsmReadIdtr (&IdtDescriptor); AsmReadIdtr (&IdtDescriptor);
IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *) IdtDescriptor.Base; IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *)IdtDescriptor.Base;
return (VOID *) (IdtEntry[ExceptionNum].Bits.OffsetLow | return (VOID *)(IdtEntry[ExceptionNum].Bits.OffsetLow |
(((UINTN)IdtEntry[ExceptionNum].Bits.OffsetHigh) << 16) | (((UINTN)IdtEntry[ExceptionNum].Bits.OffsetHigh) << 16) |
(((UINTN)IdtEntry[ExceptionNum].Bits.OffsetUpper) << 32)); (((UINTN)IdtEntry[ExceptionNum].Bits.OffsetUpper) << 32));
} }
@ -106,7 +107,7 @@ SetExceptionHandlerInIdtEntry (
IA32_DESCRIPTOR IdtDescriptor; IA32_DESCRIPTOR IdtDescriptor;
AsmReadIdtr (&IdtDescriptor); AsmReadIdtr (&IdtDescriptor);
IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *) IdtDescriptor.Base; IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *)IdtDescriptor.Base;
IdtEntry[ExceptionNum].Bits.OffsetLow = (UINT16)(UINTN)ExceptionHandler; IdtEntry[ExceptionNum].Bits.OffsetLow = (UINT16)(UINTN)ExceptionHandler;
IdtEntry[ExceptionNum].Bits.OffsetHigh = (UINT16)((UINTN)ExceptionHandler >> 16); IdtEntry[ExceptionNum].Bits.OffsetHigh = (UINT16)((UINTN)ExceptionHandler >> 16);

View File

@ -59,19 +59,20 @@ InternalConstructorWorker (
// //
Status = EFI_SUCCESS; Status = EFI_SUCCESS;
GuidHob = GetFirstGuidHob (&gEfiVectorHandoffInfoPpiGuid); GuidHob = GetFirstGuidHob (&gEfiVectorHandoffInfoPpiGuid);
if (GuidHob != NULL && !mDxeCoreFlag) { if ((GuidHob != NULL) && !mDxeCoreFlag) {
// //
// Check if configuration table is installed or not if GUIDed HOB existed, // Check if configuration table is installed or not if GUIDed HOB existed,
// only when Debug Agent is not linked by DXE Core // only when Debug Agent is not linked by DXE Core
// //
Status = EfiGetSystemConfigurationTable (&gEfiVectorHandoffTableGuid, (VOID **) &VectorHandoffInfo); Status = EfiGetSystemConfigurationTable (&gEfiVectorHandoffTableGuid, (VOID **)&VectorHandoffInfo);
} }
if (GuidHob == NULL || Status != EFI_SUCCESS) {
if ((GuidHob == NULL) || (Status != EFI_SUCCESS)) {
// //
// Install configuration table for persisted vector handoff info if GUIDed HOB cannot be found or // Install configuration table for persisted vector handoff info if GUIDed HOB cannot be found or
// configuration table does not exist // configuration table does not exist
// //
Status = gBS->InstallConfigurationTable (&gEfiVectorHandoffTableGuid, (VOID *) &mVectorHandoffInfoDebugAgent[0]); Status = gBS->InstallConfigurationTable (&gEfiVectorHandoffTableGuid, (VOID *)&mVectorHandoffInfoDebugAgent[0]);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "DebugAgent: Cannot install configuration table for persisted vector handoff info!\n")); DEBUG ((DEBUG_ERROR, "DebugAgent: Cannot install configuration table for persisted vector handoff info!\n"));
CpuDeadLoop (); CpuDeadLoop ();
@ -87,7 +88,7 @@ InternalConstructorWorker (
Status = gBS->AllocatePages ( Status = gBS->AllocatePages (
AllocateAnyPages, AllocateAnyPages,
EfiACPIMemoryNVS, EfiACPIMemoryNVS,
EFI_SIZE_TO_PAGES (sizeof(DEBUG_AGENT_MAILBOX) + PcdGet16(PcdDebugPortHandleBufferSize)), EFI_SIZE_TO_PAGES (sizeof (DEBUG_AGENT_MAILBOX) + PcdGet16 (PcdDebugPortHandleBufferSize)),
&Address &Address
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
@ -97,14 +98,14 @@ InternalConstructorWorker (
DebugTimerInterruptState = SaveAndSetDebugTimerInterrupt (FALSE); DebugTimerInterruptState = SaveAndSetDebugTimerInterrupt (FALSE);
NewMailbox = (DEBUG_AGENT_MAILBOX *) (UINTN) Address; NewMailbox = (DEBUG_AGENT_MAILBOX *)(UINTN)Address;
// //
// Copy Mailbox and Debug Port Handle buffer to new location in ACPI NVS memory, because original Mailbox // Copy Mailbox and Debug Port Handle buffer to new location in ACPI NVS memory, because original Mailbox
// and Debug Port Handle buffer may be free at runtime, SMM debug agent needs to access them // and Debug Port Handle buffer may be free at runtime, SMM debug agent needs to access them
// //
Mailbox = GetMailboxPointer (); Mailbox = GetMailboxPointer ();
CopyMem (NewMailbox, Mailbox, sizeof (DEBUG_AGENT_MAILBOX)); CopyMem (NewMailbox, Mailbox, sizeof (DEBUG_AGENT_MAILBOX));
CopyMem (NewMailbox + 1, (VOID *)(UINTN)Mailbox->DebugPortHandle, PcdGet16(PcdDebugPortHandleBufferSize)); CopyMem (NewMailbox + 1, (VOID *)(UINTN)Mailbox->DebugPortHandle, PcdGet16 (PcdDebugPortHandleBufferSize));
// //
// Update Debug Port Handle in new Mailbox // Update Debug Port Handle in new Mailbox
// //
@ -113,7 +114,7 @@ InternalConstructorWorker (
DebugTimerInterruptState = SaveAndSetDebugTimerInterrupt (DebugTimerInterruptState); DebugTimerInterruptState = SaveAndSetDebugTimerInterrupt (DebugTimerInterruptState);
Status = gBS->InstallConfigurationTable (&gEfiDebugAgentGuid, (VOID *) mMailboxPointer); Status = gBS->InstallConfigurationTable (&gEfiDebugAgentGuid, (VOID *)mMailboxPointer);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "DebugAgent: Failed to install configuration for mailbox!\n")); DEBUG ((DEBUG_ERROR, "DebugAgent: Failed to install configuration for mailbox!\n"));
CpuDeadLoop (); CpuDeadLoop ();
@ -160,8 +161,8 @@ GetMailboxFromConfigurationTable (
EFI_STATUS Status; EFI_STATUS Status;
DEBUG_AGENT_MAILBOX *Mailbox; DEBUG_AGENT_MAILBOX *Mailbox;
Status = EfiGetSystemConfigurationTable (&gEfiDebugAgentGuid, (VOID **) &Mailbox); Status = EfiGetSystemConfigurationTable (&gEfiDebugAgentGuid, (VOID **)&Mailbox);
if (Status == EFI_SUCCESS && Mailbox != NULL) { if ((Status == EFI_SUCCESS) && (Mailbox != NULL)) {
VerifyMailboxChecksum (Mailbox); VerifyMailboxChecksum (Mailbox);
return Mailbox; return Mailbox;
} else { } else {
@ -190,7 +191,8 @@ GetMailboxFromHob (
if (GuidHob == NULL) { if (GuidHob == NULL) {
return NULL; return NULL;
} }
MailboxLocation = (UINT64 *) (GET_GUID_HOB_DATA(GuidHob));
MailboxLocation = (UINT64 *)(GET_GUID_HOB_DATA (GuidHob));
Mailbox = (DEBUG_AGENT_MAILBOX *)(UINTN)(*MailboxLocation); Mailbox = (DEBUG_AGENT_MAILBOX *)(UINTN)(*MailboxLocation);
VerifyMailboxChecksum (Mailbox); VerifyMailboxChecksum (Mailbox);
@ -225,7 +227,7 @@ GetDebugPortHandle (
VOID VOID
) )
{ {
return (DEBUG_PORT_HANDLE) (UINTN)(GetMailboxPointer ()->DebugPortHandle); return (DEBUG_PORT_HANDLE)(UINTN)(GetMailboxPointer ()->DebugPortHandle);
} }
/** /**
@ -255,26 +257,26 @@ SetupDebugAgentEnvironment (
// //
// Clear Break CPU index value // Clear Break CPU index value
// //
mDebugMpContext.BreakAtCpuIndex = (UINT32) -1; mDebugMpContext.BreakAtCpuIndex = (UINT32)-1;
} }
// //
// Get original IDT address and size. // Get original IDT address and size.
// //
AsmReadIdtr ((IA32_DESCRIPTOR *) &Idtr); AsmReadIdtr ((IA32_DESCRIPTOR *)&Idtr);
IdtEntryCount = (UINT16) ((Idtr.Limit + 1) / sizeof (IA32_IDT_GATE_DESCRIPTOR)); IdtEntryCount = (UINT16)((Idtr.Limit + 1) / sizeof (IA32_IDT_GATE_DESCRIPTOR));
if (IdtEntryCount < 33) { if (IdtEntryCount < 33) {
ZeroMem (&mIdtEntryTable, sizeof (IA32_IDT_GATE_DESCRIPTOR) * 33); ZeroMem (&mIdtEntryTable, sizeof (IA32_IDT_GATE_DESCRIPTOR) * 33);
// //
// Copy original IDT table into new one // Copy original IDT table into new one
// //
CopyMem (&mIdtEntryTable, (VOID *) Idtr.Base, Idtr.Limit + 1); CopyMem (&mIdtEntryTable, (VOID *)Idtr.Base, Idtr.Limit + 1);
// //
// Load new IDT table // Load new IDT table
// //
Idtr.Limit = (UINT16) (sizeof (IA32_IDT_GATE_DESCRIPTOR) * 33 - 1); Idtr.Limit = (UINT16)(sizeof (IA32_IDT_GATE_DESCRIPTOR) * 33 - 1);
Idtr.Base = (UINTN) &mIdtEntryTable; Idtr.Base = (UINTN)&mIdtEntryTable;
AsmWriteIdtr ((IA32_DESCRIPTOR *) &Idtr); AsmWriteIdtr ((IA32_DESCRIPTOR *)&Idtr);
} }
// //
@ -294,6 +296,7 @@ SetupDebugAgentEnvironment (
} else { } else {
ZeroMem (&mMailbox, sizeof (DEBUG_AGENT_MAILBOX)); ZeroMem (&mMailbox, sizeof (DEBUG_AGENT_MAILBOX));
} }
mMailboxPointer = &mMailbox; mMailboxPointer = &mMailbox;
} }
@ -305,7 +308,7 @@ SetupDebugAgentEnvironment (
// //
// Initialize debug communication port // Initialize debug communication port
// //
DebugPortHandle = (UINT64) (UINTN)DebugPortInitialize ((VOID *)(UINTN)mMailboxPointer->DebugPortHandle, NULL); DebugPortHandle = (UINT64)(UINTN)DebugPortInitialize ((VOID *)(UINTN)mMailboxPointer->DebugPortHandle, NULL);
UpdateMailboxContent (mMailboxPointer, DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX, DebugPortHandle); UpdateMailboxContent (mMailboxPointer, DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX, DebugPortHandle);
if (Mailbox == NULL) { if (Mailbox == NULL) {
@ -326,7 +329,6 @@ SetupDebugAgentEnvironment (
} }
} }
/** /**
Initialize debug agent. Initialize debug agent.
@ -369,14 +371,15 @@ InitializeDebugAgent (
InitializeLocalApicSoftwareEnable (TRUE); InitializeLocalApicSoftwareEnable (TRUE);
GetApicTimerState (NULL, &PeriodicMode, NULL); GetApicTimerState (NULL, &PeriodicMode, NULL);
TimerCycle = GetApicTimerInitCount (); TimerCycle = GetApicTimerInitCount ();
if (!PeriodicMode || TimerCycle == 0) { if (!PeriodicMode || (TimerCycle == 0)) {
InitializeDebugTimer (NULL, FALSE); InitializeDebugTimer (NULL, FALSE);
} }
// //
// Invoked by AP, enable interrupt to let AP could receive IPI from other processors // Invoked by AP, enable interrupt to let AP could receive IPI from other processors
// //
EnableInterrupts (); EnableInterrupts ();
return ; return;
} }
// //
@ -396,7 +399,6 @@ InitializeDebugAgent (
MailboxLocation = NULL; MailboxLocation = NULL;
switch (InitFlag) { switch (InitFlag) {
case DEBUG_AGENT_INIT_DXE_LOAD: case DEBUG_AGENT_INIT_DXE_LOAD:
// //
// Check if Debug Agent has been initialized before // Check if Debug Agent has been initialized before
@ -411,7 +413,7 @@ InitializeDebugAgent (
// //
AsmReadIdtr (&IdtDescriptor); AsmReadIdtr (&IdtDescriptor);
mSaveIdtTableSize = IdtDescriptor.Limit + 1; mSaveIdtTableSize = IdtDescriptor.Limit + 1;
mSavedIdtTable = AllocateCopyPool (mSaveIdtTableSize, (VOID *) IdtDescriptor.Base); mSavedIdtTable = AllocateCopyPool (mSaveIdtTableSize, (VOID *)IdtDescriptor.Base);
// //
// Check if Debug Agent initialized in DXE phase // Check if Debug Agent initialized in DXE phase
// //
@ -423,6 +425,7 @@ InitializeDebugAgent (
HobList = GetHobList (); HobList = GetHobList ();
Mailbox = GetMailboxFromHob (HobList); Mailbox = GetMailboxFromHob (HobList);
} }
// //
// Set up Debug Agent Environment and try to connect HOST if required // Set up Debug Agent Environment and try to connect HOST if required
// //
@ -461,8 +464,8 @@ InitializeDebugAgent (
// Restore original IDT table // Restore original IDT table
// //
AsmReadIdtr (&IdtDescriptor); AsmReadIdtr (&IdtDescriptor);
IdtDescriptor.Limit = (UINT16) (mSaveIdtTableSize - 1); IdtDescriptor.Limit = (UINT16)(mSaveIdtTableSize - 1);
CopyMem ((VOID *) IdtDescriptor.Base, mSavedIdtTable, mSaveIdtTableSize); CopyMem ((VOID *)IdtDescriptor.Base, mSavedIdtTable, mSaveIdtTableSize);
AsmWriteIdtr (&IdtDescriptor); AsmWriteIdtr (&IdtDescriptor);
FreePool (mSavedIdtTable); FreePool (mSavedIdtTable);
mDebugAgentInitialized = FALSE; mDebugAgentInitialized = FALSE;
@ -504,13 +507,14 @@ InitializeDebugAgent (
case DEBUG_AGENT_INIT_S3: case DEBUG_AGENT_INIT_S3:
if (Context != NULL) { if (Context != NULL) {
Ia32Idtr = (IA32_DESCRIPTOR *) Context; Ia32Idtr = (IA32_DESCRIPTOR *)Context;
Ia32IdtEntry = (IA32_IDT_ENTRY *)(Ia32Idtr->Base); Ia32IdtEntry = (IA32_IDT_ENTRY *)(Ia32Idtr->Base);
MailboxLocation = (UINT64 *) ((UINTN) Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetLow + MailboxLocation = (UINT64 *)((UINTN)Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetLow +
((UINTN) Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetHigh << 16)); ((UINTN)Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetHigh << 16));
Mailbox = (DEBUG_AGENT_MAILBOX *)(UINTN)(*MailboxLocation); Mailbox = (DEBUG_AGENT_MAILBOX *)(UINTN)(*MailboxLocation);
VerifyMailboxChecksum (Mailbox); VerifyMailboxChecksum (Mailbox);
} }
// //
// Save Mailbox pointer in global variable // Save Mailbox pointer in global variable
// //
@ -530,6 +534,7 @@ InitializeDebugAgent (
// //
CpuBreakpoint (); CpuBreakpoint ();
} }
break; break;
default: default:

View File

@ -182,8 +182,8 @@ SERIAL_IO_DEVICE_PATH mSerialIoDevicePath = {
HARDWARE_DEVICE_PATH, HARDWARE_DEVICE_PATH,
HW_VENDOR_DP, HW_VENDOR_DP,
{ {
(UINT8) (sizeof (VENDOR_DEVICE_PATH)), (UINT8)(sizeof (VENDOR_DEVICE_PATH)),
(UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8) (UINT8)((sizeof (VENDOR_DEVICE_PATH)) >> 8)
} }
}, },
EFI_DEBUG_AGENT_GUID, EFI_DEBUG_AGENT_GUID,
@ -193,8 +193,8 @@ SERIAL_IO_DEVICE_PATH mSerialIoDevicePath = {
MESSAGING_DEVICE_PATH, MESSAGING_DEVICE_PATH,
MSG_UART_DP, MSG_UART_DP,
{ {
(UINT8) (sizeof (UART_DEVICE_PATH)), (UINT8)(sizeof (UART_DEVICE_PATH)),
(UINT8) ((sizeof (UART_DEVICE_PATH)) >> 8) (UINT8)((sizeof (UART_DEVICE_PATH)) >> 8)
} }
}, },
0, 0,
@ -235,8 +235,12 @@ typedef struct {
// //
EFI_HANDLE mSerialIoHandle = NULL; EFI_HANDLE mSerialIoHandle = NULL;
UINTN mLoopbackBuffer = 0; UINTN mLoopbackBuffer = 0;
DEBUG_SERIAL_FIFO mSerialFifoForTerminal = {0, 0, DEBGU_SERIAL_IO_FIFO_DEPTH, { 0 }}; DEBUG_SERIAL_FIFO mSerialFifoForTerminal = {
DEBUG_SERIAL_FIFO mSerialFifoForDebug = {0, 0, DEBGU_SERIAL_IO_FIFO_DEPTH, { 0 }}; 0, 0, DEBGU_SERIAL_IO_FIFO_DEPTH, { 0 }
};
DEBUG_SERIAL_FIFO mSerialFifoForDebug = {
0, 0, DEBGU_SERIAL_IO_FIFO_DEPTH, { 0 }
};
/** /**
Detect whether specific FIFO is empty or not. Detect whether specific FIFO is empty or not.
@ -302,6 +306,7 @@ DebugTerminalFifoAdd (
if (IsDebugTerminalFifoFull (Fifo)) { if (IsDebugTerminalFifoFull (Fifo)) {
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
// //
// FIFO is not full can add data // FIFO is not full can add data
// //
@ -337,6 +342,7 @@ DebugTerminalFifoRemove (
if (IsDebugTermianlFifoEmpty (Fifo)) { if (IsDebugTermianlFifoEmpty (Fifo)) {
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
// //
// FIFO is not empty, can remove data // FIFO is not empty, can remove data
// //
@ -363,8 +369,10 @@ InstallSerialIo (
Status = gBS->InstallMultipleProtocolInterfaces ( Status = gBS->InstallMultipleProtocolInterfaces (
&mSerialIoHandle, &mSerialIoHandle,
&gEfiDevicePathProtocolGuid, &mSerialIoDevicePath, &gEfiDevicePathProtocolGuid,
&gEfiSerialIoProtocolGuid, &mSerialIo, &mSerialIoDevicePath,
&gEfiSerialIoProtocolGuid,
&mSerialIo,
NULL NULL
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
@ -445,7 +453,7 @@ SerialSetAttributes (
// SERIAL_PORT_DEFAULT_RECEIVE_FIFO_DEPTH. The Debug Communication Library may actually be // SERIAL_PORT_DEFAULT_RECEIVE_FIFO_DEPTH. The Debug Communication Library may actually be
// using a larger FIFO, but there is no way to tell. // using a larger FIFO, but there is no way to tell.
// //
if (ReceiveFifoDepth == 0 || ReceiveFifoDepth >= SERIAL_PORT_DEFAULT_RECEIVE_FIFO_DEPTH) { if ((ReceiveFifoDepth == 0) || (ReceiveFifoDepth >= SERIAL_PORT_DEFAULT_RECEIVE_FIFO_DEPTH)) {
mSerialIoMode.ReceiveFifoDepth = SERIAL_PORT_DEFAULT_RECEIVE_FIFO_DEPTH; mSerialIoMode.ReceiveFifoDepth = SERIAL_PORT_DEFAULT_RECEIVE_FIFO_DEPTH;
} else { } else {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
@ -478,6 +486,7 @@ SerialSetControl (
if ((Control & (~EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE)) != 0) { if ((Control & (~EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE)) != 0) {
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
mSerialIoMode.ControlMask = Control; mSerialIoMode.ControlMask = Control;
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -580,10 +589,12 @@ SerialWrite (
if (*BufferSize == 0) { if (*BufferSize == 0) {
return EFI_SUCCESS; return EFI_SUCCESS;
} }
if ((mLoopbackBuffer & SERIAL_PORT_LOOPBACK_BUFFER_FULL) != 0) { if ((mLoopbackBuffer & SERIAL_PORT_LOOPBACK_BUFFER_FULL) != 0) {
*BufferSize = 0; *BufferSize = 0;
return EFI_TIMEOUT; return EFI_TIMEOUT;
} }
mLoopbackBuffer = SERIAL_PORT_LOOPBACK_BUFFER_FULL | *(UINT8 *)Buffer; mLoopbackBuffer = SERIAL_PORT_LOOPBACK_BUFFER_FULL | *(UINT8 *)Buffer;
*BufferSize = 1; *BufferSize = 1;
} else { } else {
@ -644,12 +655,13 @@ SerialRead (
DebugTimerInterruptState = SaveAndSetDebugTimerInterrupt (FALSE); DebugTimerInterruptState = SaveAndSetDebugTimerInterrupt (FALSE);
Handle = GetDebugPortHandle (); Handle = GetDebugPortHandle ();
Data8 = (UINT8 *) &DebugHeader; Data8 = (UINT8 *)&DebugHeader;
Uint8Buffer = (UINT8 *)Buffer; Uint8Buffer = (UINT8 *)Buffer;
if ((mSerialIoMode.ControlMask & EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE) != 0) { if ((mSerialIoMode.ControlMask & EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE) != 0) {
if ((mLoopbackBuffer & SERIAL_PORT_LOOPBACK_BUFFER_FULL) == 0) { if ((mLoopbackBuffer & SERIAL_PORT_LOOPBACK_BUFFER_FULL) == 0) {
return EFI_TIMEOUT; return EFI_TIMEOUT;
} }
*Uint8Buffer = (UINT8)(mLoopbackBuffer & 0xff); *Uint8Buffer = (UINT8)(mLoopbackBuffer & 0xff);
mLoopbackBuffer = 0; mLoopbackBuffer = 0;
*BufferSize = 1; *BufferSize = 1;
@ -661,15 +673,17 @@ SerialRead (
Status = DebugTerminalFifoRemove (&mSerialFifoForTerminal, Data8); Status = DebugTerminalFifoRemove (&mSerialFifoForTerminal, Data8);
if (Status == EFI_SUCCESS) { if (Status == EFI_SUCCESS) {
*Uint8Buffer = *Data8; *Uint8Buffer = *Data8;
Uint8Buffer ++; Uint8Buffer++;
continue; continue;
} }
// //
// Read the input character from Debug Port // Read the input character from Debug Port
// //
if (!DebugPortPollBuffer (Handle)) { if (!DebugPortPollBuffer (Handle)) {
break; break;
} }
DebugAgentReadBuffer (Handle, Data8, 1, 0); DebugAgentReadBuffer (Handle, Data8, 1, 0);
if (*Data8 == DEBUG_STARTING_SYMBOL_ATTACH) { if (*Data8 == DEBUG_STARTING_SYMBOL_ATTACH) {
@ -684,14 +698,16 @@ SerialRead (
DebugAgentMsgPrint (DEBUG_AGENT_INFO, "Terminal Timer break symbol received %x", DebugHeader.Command); DebugAgentMsgPrint (DEBUG_AGENT_INFO, "Terminal Timer break symbol received %x", DebugHeader.Command);
DebugTerminalFifoAdd (&mSerialFifoForDebug, DebugHeader.Command); DebugTerminalFifoAdd (&mSerialFifoForDebug, DebugHeader.Command);
} }
if (Status == EFI_TIMEOUT) { if (Status == EFI_TIMEOUT) {
continue; continue;
} }
} else { } else {
*Uint8Buffer = *Data8; *Uint8Buffer = *Data8;
Uint8Buffer ++; Uint8Buffer++;
} }
} }
*BufferSize = (UINTN)Uint8Buffer - (UINTN)Buffer; *BufferSize = (UINTN)Uint8Buffer - (UINTN)Buffer;
} }
@ -732,7 +748,7 @@ DebugReadBreakFromDebugPort (
// //
// If Debug Port buffer has data, read it till it was break symbol or Debug Port buffer empty. // If Debug Port buffer has data, read it till it was break symbol or Debug Port buffer empty.
// //
Data8 = (UINT8 *) &DebugHeader; Data8 = (UINT8 *)&DebugHeader;
while (TRUE) { while (TRUE) {
// //
// If start symbol is not received // If start symbol is not received
@ -743,6 +759,7 @@ DebugReadBreakFromDebugPort (
// //
break; break;
} }
// //
// Try to read the start symbol // Try to read the start symbol
// //
@ -752,6 +769,7 @@ DebugReadBreakFromDebugPort (
*BreakSymbol = *Data8; *BreakSymbol = *Data8;
return EFI_SUCCESS; return EFI_SUCCESS;
} }
if (*Data8 == DEBUG_STARTING_SYMBOL_NORMAL) { if (*Data8 == DEBUG_STARTING_SYMBOL_NORMAL) {
Status = ReadRemainingBreakPacket (Handle, &DebugHeader); Status = ReadRemainingBreakPacket (Handle, &DebugHeader);
if (Status == EFI_SUCCESS) { if (Status == EFI_SUCCESS) {
@ -759,6 +777,7 @@ DebugReadBreakFromDebugPort (
*BreakSymbol = DebugHeader.Command; *BreakSymbol = DebugHeader.Command;
return EFI_SUCCESS; return EFI_SUCCESS;
} }
if (Status == EFI_TIMEOUT) { if (Status == EFI_TIMEOUT) {
break; break;
} }

View File

@ -10,7 +10,6 @@
GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN mSkipBreakpoint = FALSE; GLOBAL_REMOVE_IF_UNREFERENCED BOOLEAN mSkipBreakpoint = FALSE;
GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_VECTOR_HANDOFF_INFO_PPI mVectorHandoffInfoPpi = { GLOBAL_REMOVE_IF_UNREFERENCED EFI_PEI_VECTOR_HANDOFF_INFO_PPI mVectorHandoffInfoPpi = {
&mVectorHandoffInfoDebugAgent[0] &mVectorHandoffInfoDebugAgent[0]
}; };
@ -73,7 +72,7 @@ DebugReadBreakSymbol (
// //
// If Debug Port buffer has data, read it till it was break symbol or Debug Port buffer empty. // If Debug Port buffer has data, read it till it was break symbol or Debug Port buffer empty.
// //
Data8 = (UINT8 *) &DebugHeader; Data8 = (UINT8 *)&DebugHeader;
while (TRUE) { while (TRUE) {
// //
// If start symbol is not received // If start symbol is not received
@ -84,6 +83,7 @@ DebugReadBreakSymbol (
// //
break; break;
} }
// //
// Try to read the start symbol // Try to read the start symbol
// //
@ -93,6 +93,7 @@ DebugReadBreakSymbol (
DebugAgentMsgPrint (DEBUG_AGENT_INFO, "Debug Timer attach symbol received %x", *BreakSymbol); DebugAgentMsgPrint (DEBUG_AGENT_INFO, "Debug Timer attach symbol received %x", *BreakSymbol);
return EFI_SUCCESS; return EFI_SUCCESS;
} }
if (*Data8 == DEBUG_STARTING_SYMBOL_NORMAL) { if (*Data8 == DEBUG_STARTING_SYMBOL_NORMAL) {
Status = ReadRemainingBreakPacket (Handle, &DebugHeader); Status = ReadRemainingBreakPacket (Handle, &DebugHeader);
if (Status == EFI_SUCCESS) { if (Status == EFI_SUCCESS) {
@ -100,6 +101,7 @@ DebugReadBreakSymbol (
DebugAgentMsgPrint (DEBUG_AGENT_INFO, "Debug Timer break symbol received %x", *BreakSymbol); DebugAgentMsgPrint (DEBUG_AGENT_INFO, "Debug Timer break symbol received %x", *BreakSymbol);
return EFI_SUCCESS; return EFI_SUCCESS;
} }
if (Status == EFI_TIMEOUT) { if (Status == EFI_TIMEOUT) {
break; break;
} }
@ -120,11 +122,11 @@ GetLocationSavedMailboxPointerInIdtEntry (
{ {
UINTN *MailboxLocation; UINTN *MailboxLocation;
MailboxLocation = (UINTN *) GetExceptionHandlerInIdtEntry (DEBUG_MAILBOX_VECTOR); MailboxLocation = (UINTN *)GetExceptionHandlerInIdtEntry (DEBUG_MAILBOX_VECTOR);
// //
// *MailboxLocation is the pointer to Mailbox // *MailboxLocation is the pointer to Mailbox
// //
VerifyMailboxChecksum ((DEBUG_AGENT_MAILBOX *) (*MailboxLocation)); VerifyMailboxChecksum ((DEBUG_AGENT_MAILBOX *)(*MailboxLocation));
return MailboxLocation; return MailboxLocation;
} }
@ -159,7 +161,8 @@ GetMailboxLocationFromHob (
if (GuidHob == NULL) { if (GuidHob == NULL) {
return NULL; return NULL;
} }
return (UINT64 *) (GET_GUID_HOB_DATA(GuidHob));
return (UINT64 *)(GET_GUID_HOB_DATA (GuidHob));
} }
/** /**
@ -186,8 +189,9 @@ GetMailboxPointer (
// //
// Cannot used GetDebugFlag() to get Debug Flag to avoid GetMailboxPointer() nested // Cannot used GetDebugFlag() to get Debug Flag to avoid GetMailboxPointer() nested
// //
if (Mailbox->DebugFlag.Bits.CheckMailboxInHob != 1 || if ((Mailbox->DebugFlag.Bits.CheckMailboxInHob != 1) ||
Mailbox->DebugFlag.Bits.InitArch != DEBUG_ARCH_SYMBOL) { (Mailbox->DebugFlag.Bits.InitArch != DEBUG_ARCH_SYMBOL))
{
// //
// If mailbox was setup in SEC or the current CPU arch is different from the init arch // If mailbox was setup in SEC or the current CPU arch is different from the init arch
// Debug Agent initialized, return the mailbox from IDT entry directly. // Debug Agent initialized, return the mailbox from IDT entry directly.
@ -201,7 +205,7 @@ GetMailboxPointer (
// Compare mailbox in IDT entry with mailbox in HOB, // Compare mailbox in IDT entry with mailbox in HOB,
// need to fix mailbox location if HOB moved by PEI CORE // need to fix mailbox location if HOB moved by PEI CORE
// //
if (MailboxLocationInHob != MailboxLocationInIdt && MailboxLocationInHob != NULL) { if ((MailboxLocationInHob != MailboxLocationInIdt) && (MailboxLocationInHob != NULL)) {
Mailbox = (DEBUG_AGENT_MAILBOX *)(UINTN)(*MailboxLocationInHob); Mailbox = (DEBUG_AGENT_MAILBOX *)(UINTN)(*MailboxLocationInHob);
// //
// Fix up Debug Port handler and save new mailbox in IDT entry // Fix up Debug Port handler and save new mailbox in IDT entry
@ -236,7 +240,7 @@ GetDebugPortHandle (
DebugAgentMailbox = GetMailboxPointer (); DebugAgentMailbox = GetMailboxPointer ();
return (DEBUG_PORT_HANDLE) (UINTN)(DebugAgentMailbox->DebugPortHandle); return (DEBUG_PORT_HANDLE)(UINTN)(DebugAgentMailbox->DebugPortHandle);
} }
/** /**
@ -274,11 +278,11 @@ DebugAgentCallbackMemoryDiscoveredPpi (
// //
Status = PeiServicesAllocatePages ( Status = PeiServicesAllocatePages (
EfiACPIMemoryNVS, EfiACPIMemoryNVS,
EFI_SIZE_TO_PAGES (sizeof(DEBUG_AGENT_MAILBOX) + PcdGet16(PcdDebugPortHandleBufferSize)), EFI_SIZE_TO_PAGES (sizeof (DEBUG_AGENT_MAILBOX) + PcdGet16 (PcdDebugPortHandleBufferSize)),
&Address &Address
); );
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
NewMailbox = (DEBUG_AGENT_MAILBOX *) (UINTN) Address; NewMailbox = (DEBUG_AGENT_MAILBOX *)(UINTN)Address;
// //
// Copy Mailbox and Debug Port Handle buffer to new location in ACPI NVS memory, because original Mailbox // Copy Mailbox and Debug Port Handle buffer to new location in ACPI NVS memory, because original Mailbox
// and Debug Port Handle buffer in the allocated pool that may be marked as free by DXE Core after DXE Core // and Debug Port Handle buffer in the allocated pool that may be marked as free by DXE Core after DXE Core
@ -286,7 +290,7 @@ DebugAgentCallbackMemoryDiscoveredPpi (
// //
Mailbox = GetMailboxPointer (); Mailbox = GetMailboxPointer ();
CopyMem (NewMailbox, Mailbox, sizeof (DEBUG_AGENT_MAILBOX)); CopyMem (NewMailbox, Mailbox, sizeof (DEBUG_AGENT_MAILBOX));
CopyMem (NewMailbox + 1, (VOID *)(UINTN)Mailbox->DebugPortHandle, PcdGet16(PcdDebugPortHandleBufferSize)); CopyMem (NewMailbox + 1, (VOID *)(UINTN)Mailbox->DebugPortHandle, PcdGet16 (PcdDebugPortHandleBufferSize));
// //
// Update Mailbox Location pointer in GUIDed HOB and IDT entry with new one // Update Mailbox Location pointer in GUIDed HOB and IDT entry with new one
// //
@ -375,17 +379,16 @@ InitializeDebugAgent (
// //
// Disable interrupts and save current interrupt state // Disable interrupts and save current interrupt state
// //
CpuInterruptState = SaveAndDisableInterrupts(); CpuInterruptState = SaveAndDisableInterrupts ();
switch (InitFlag) { switch (InitFlag) {
case DEBUG_AGENT_INIT_PREMEM_SEC: case DEBUG_AGENT_INIT_PREMEM_SEC:
InitializeDebugIdt (); InitializeDebugIdt ();
MailboxLocation = (UINT64)(UINTN)&MailboxInStack; MailboxLocation = (UINT64)(UINTN)&MailboxInStack;
Mailbox = &MailboxInStack; Mailbox = &MailboxInStack;
ZeroMem ((VOID *) Mailbox, sizeof (DEBUG_AGENT_MAILBOX)); ZeroMem ((VOID *)Mailbox, sizeof (DEBUG_AGENT_MAILBOX));
// //
// Get and save debug port handle and set the length of memory block. // Get and save debug port handle and set the length of memory block.
// //
@ -407,7 +410,7 @@ InitializeDebugAgent (
Phase2Context.InitFlag = InitFlag; Phase2Context.InitFlag = InitFlag;
Phase2Context.Context = Context; Phase2Context.Context = Context;
Phase2Context.Function = Function; Phase2Context.Function = Function;
DebugPortInitialize ((VOID *) &Phase2Context, InitializeDebugAgentPhase2); DebugPortInitialize ((VOID *)&Phase2Context, InitializeDebugAgentPhase2);
// //
// If reaches here, it means Debug Port initialization failed. // If reaches here, it means Debug Port initialization failed.
// //
@ -427,6 +430,7 @@ InitializeDebugAgent (
// //
TriggerSoftInterrupt (MEMORY_READY_SIGNATURE); TriggerSoftInterrupt (MEMORY_READY_SIGNATURE);
} }
// //
// Install Vector Handoff Info PPI to persist vectors used by Debug Agent // Install Vector Handoff Info PPI to persist vectors used by Debug Agent
// //
@ -435,14 +439,15 @@ InitializeDebugAgent (
DEBUG ((DEBUG_ERROR, "DebugAgent: Failed to install Vector Handoff Info PPI!\n")); DEBUG ((DEBUG_ERROR, "DebugAgent: Failed to install Vector Handoff Info PPI!\n"));
CpuDeadLoop (); CpuDeadLoop ();
} }
// //
// Fix up Debug Port handle address and mailbox address // Fix up Debug Port handle address and mailbox address
// //
DebugAgentContext = (DEBUG_AGENT_CONTEXT_POSTMEM_SEC *) Context; DebugAgentContext = (DEBUG_AGENT_CONTEXT_POSTMEM_SEC *)Context;
if (DebugAgentContext != NULL) { if (DebugAgentContext != NULL) {
DebugPortHandle = (UINT64)(UINT32)(Mailbox->DebugPortHandle + DebugAgentContext->StackMigrateOffset); DebugPortHandle = (UINT64)(UINT32)(Mailbox->DebugPortHandle + DebugAgentContext->StackMigrateOffset);
UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX, DebugPortHandle); UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX, DebugPortHandle);
Mailbox = (DEBUG_AGENT_MAILBOX *) ((UINTN) Mailbox + DebugAgentContext->StackMigrateOffset); Mailbox = (DEBUG_AGENT_MAILBOX *)((UINTN)Mailbox + DebugAgentContext->StackMigrateOffset);
MailboxLocation = (UINT64)(UINTN)Mailbox; MailboxLocation = (UINT64)(UINTN)Mailbox;
// //
// Build mailbox location in HOB and fix-up its address // Build mailbox location in HOB and fix-up its address
@ -452,7 +457,7 @@ InitializeDebugAgent (
&MailboxLocation, &MailboxLocation,
sizeof (UINT64) sizeof (UINT64)
); );
MailboxLocationPointer = (UINT64 *) ((UINTN) MailboxLocationPointer + DebugAgentContext->HeapMigrateOffset); MailboxLocationPointer = (UINT64 *)((UINTN)MailboxLocationPointer + DebugAgentContext->HeapMigrateOffset);
} else { } else {
// //
// DebugAgentContext is NULL. Then, Mailbox can directly be copied into memory. // DebugAgentContext is NULL. Then, Mailbox can directly be copied into memory.
@ -460,21 +465,22 @@ InitializeDebugAgent (
// //
Status = PeiServicesAllocatePages ( Status = PeiServicesAllocatePages (
EfiACPIMemoryNVS, EfiACPIMemoryNVS,
EFI_SIZE_TO_PAGES (sizeof(DEBUG_AGENT_MAILBOX) + PcdGet16(PcdDebugPortHandleBufferSize)), EFI_SIZE_TO_PAGES (sizeof (DEBUG_AGENT_MAILBOX) + PcdGet16 (PcdDebugPortHandleBufferSize)),
&Address &Address
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "DebugAgent: Failed to allocate pages!\n")); DEBUG ((DEBUG_ERROR, "DebugAgent: Failed to allocate pages!\n"));
CpuDeadLoop (); CpuDeadLoop ();
} }
NewMailbox = (DEBUG_AGENT_MAILBOX *) (UINTN) Address;
NewMailbox = (DEBUG_AGENT_MAILBOX *)(UINTN)Address;
// //
// Copy Mailbox and Debug Port Handle buffer to new location in ACPI NVS memory, because original Mailbox // Copy Mailbox and Debug Port Handle buffer to new location in ACPI NVS memory, because original Mailbox
// and Debug Port Handle buffer in the allocated pool that may be marked as free by DXE Core after DXE Core // and Debug Port Handle buffer in the allocated pool that may be marked as free by DXE Core after DXE Core
// reallocates the HOB. // reallocates the HOB.
// //
CopyMem (NewMailbox, Mailbox, sizeof (DEBUG_AGENT_MAILBOX)); CopyMem (NewMailbox, Mailbox, sizeof (DEBUG_AGENT_MAILBOX));
CopyMem (NewMailbox + 1, (VOID *)(UINTN)Mailbox->DebugPortHandle, PcdGet16(PcdDebugPortHandleBufferSize)); CopyMem (NewMailbox + 1, (VOID *)(UINTN)Mailbox->DebugPortHandle, PcdGet16 (PcdDebugPortHandleBufferSize));
UpdateMailboxContent (NewMailbox, DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX, (UINT64)(UINTN)(NewMailbox + 1)); UpdateMailboxContent (NewMailbox, DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX, (UINT64)(UINTN)(NewMailbox + 1));
MailboxLocation = (UINT64)(UINTN)NewMailbox; MailboxLocation = (UINT64)(UINTN)NewMailbox;
// //
@ -486,6 +492,7 @@ InitializeDebugAgent (
sizeof (UINT64) sizeof (UINT64)
); );
} }
// //
// Update IDT entry to save the location saved mailbox pointer // Update IDT entry to save the location saved mailbox pointer
// //
@ -497,13 +504,15 @@ InitializeDebugAgent (
DEBUG ((DEBUG_ERROR, "DebugAgent: Input parameter Context cannot be NULL!\n")); DEBUG ((DEBUG_ERROR, "DebugAgent: Input parameter Context cannot be NULL!\n"));
CpuDeadLoop (); CpuDeadLoop ();
} }
// //
// Check if Debug Agent has initialized before // Check if Debug Agent has initialized before
// //
if (IsDebugAgentInitialzed()) { if (IsDebugAgentInitialzed ()) {
DEBUG ((DEBUG_WARN, "Debug Agent: It has already initialized in SEC Core!\n")); DEBUG ((DEBUG_WARN, "Debug Agent: It has already initialized in SEC Core!\n"));
break; break;
} }
// //
// Install Vector Handoff Info PPI to persist vectors used by Debug Agent // Install Vector Handoff Info PPI to persist vectors used by Debug Agent
// //
@ -512,6 +521,7 @@ InitializeDebugAgent (
DEBUG ((DEBUG_ERROR, "DebugAgent: Failed to install Vector Handoff Info PPI!\n")); DEBUG ((DEBUG_ERROR, "DebugAgent: Failed to install Vector Handoff Info PPI!\n"));
CpuDeadLoop (); CpuDeadLoop ();
} }
// //
// Set up IDT entries // Set up IDT entries
// //
@ -540,6 +550,7 @@ InitializeDebugAgent (
// //
SetLocationSavedMailboxPointerInIdtEntry (MailboxLocationPointer); SetLocationSavedMailboxPointerInIdtEntry (MailboxLocationPointer);
} }
// //
// Save init arch type when debug agent initialized // Save init arch type when debug agent initialized
// //
@ -553,6 +564,7 @@ InitializeDebugAgent (
DEBUG ((DEBUG_ERROR, "DebugAgent: Failed to register memory discovered callback function!\n")); DEBUG ((DEBUG_ERROR, "DebugAgent: Failed to register memory discovered callback function!\n"));
CpuDeadLoop (); CpuDeadLoop ();
} }
// //
// Set HOB check flag if memory has not been ready yet // Set HOB check flag if memory has not been ready yet
// //
@ -563,7 +575,7 @@ InitializeDebugAgent (
Phase2Context.InitFlag = InitFlag; Phase2Context.InitFlag = InitFlag;
Phase2Context.Context = Context; Phase2Context.Context = Context;
Phase2Context.Function = Function; Phase2Context.Function = Function;
DebugPortInitialize ((VOID *) &Phase2Context, InitializeDebugAgentPhase2); DebugPortInitialize ((VOID *)&Phase2Context, InitializeDebugAgentPhase2);
FindAndReportModuleImageInfo (4); FindAndReportModuleImageInfo (4);
@ -574,17 +586,17 @@ InitializeDebugAgent (
DEBUG ((DEBUG_ERROR, "DebugAgent: Input parameter Context cannot be NULL!\n")); DEBUG ((DEBUG_ERROR, "DebugAgent: Input parameter Context cannot be NULL!\n"));
CpuDeadLoop (); CpuDeadLoop ();
} else { } else {
Ia32Idtr = (IA32_DESCRIPTOR *) Context; Ia32Idtr = (IA32_DESCRIPTOR *)Context;
Ia32IdtEntry = (IA32_IDT_ENTRY *)(Ia32Idtr->Base); Ia32IdtEntry = (IA32_IDT_ENTRY *)(Ia32Idtr->Base);
MailboxLocationPointer = (UINT64 *) ((UINTN) Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetLow + MailboxLocationPointer = (UINT64 *)((UINTN)Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetLow +
((UINTN) Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetHigh << 16)); ((UINTN)Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetHigh << 16));
Mailbox = (DEBUG_AGENT_MAILBOX *) (UINTN)(*MailboxLocationPointer); Mailbox = (DEBUG_AGENT_MAILBOX *)(UINTN)(*MailboxLocationPointer);
// //
// Mailbox should valid and setup before executing thunk code // Mailbox should valid and setup before executing thunk code
// //
VerifyMailboxChecksum (Mailbox); VerifyMailboxChecksum (Mailbox);
DebugPortHandle = (UINT64) (UINTN)DebugPortInitialize ((VOID *)(UINTN)Mailbox->DebugPortHandle, NULL); DebugPortHandle = (UINT64)(UINTN)DebugPortInitialize ((VOID *)(UINTN)Mailbox->DebugPortHandle, NULL);
UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX, DebugPortHandle); UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX, DebugPortHandle);
// //
// Set up IDT entries // Set up IDT entries
@ -597,6 +609,7 @@ InitializeDebugAgent (
FindAndReportModuleImageInfo (4); FindAndReportModuleImageInfo (4);
} }
break; break;
default: default:
@ -625,16 +638,18 @@ InitializeDebugAgent (
// //
EnableInterrupts (); EnableInterrupts ();
} }
// //
// If Function is not NULL, invoke it always whatever debug agent was initialized successfully or not. // If Function is not NULL, invoke it always whatever debug agent was initialized successfully or not.
// //
if (Function != NULL) { if (Function != NULL) {
Function (Context); Function (Context);
} }
// //
// Set return status for DEBUG_AGENT_INIT_PEI // Set return status for DEBUG_AGENT_INIT_PEI
// //
if (InitFlag == DEBUG_AGENT_INIT_PEI && Context != NULL) { if ((InitFlag == DEBUG_AGENT_INIT_PEI) && (Context != NULL)) {
*(EFI_STATUS *)Context = EFI_SUCCESS; *(EFI_STATUS *)Context = EFI_SUCCESS;
} }
} }
@ -662,15 +677,16 @@ InitializeDebugAgentPhase2 (
UINT16 BufferSize; UINT16 BufferSize;
UINT64 NewDebugPortHandle; UINT64 NewDebugPortHandle;
Phase2Context = (DEBUG_AGENT_PHASE2_CONTEXT *) Context; Phase2Context = (DEBUG_AGENT_PHASE2_CONTEXT *)Context;
MailboxLocation = GetLocationSavedMailboxPointerInIdtEntry (); MailboxLocation = GetLocationSavedMailboxPointerInIdtEntry ();
Mailbox = (DEBUG_AGENT_MAILBOX *)(UINTN)(*MailboxLocation); Mailbox = (DEBUG_AGENT_MAILBOX *)(UINTN)(*MailboxLocation);
BufferSize = PcdGet16(PcdDebugPortHandleBufferSize); BufferSize = PcdGet16 (PcdDebugPortHandleBufferSize);
if (Phase2Context->InitFlag == DEBUG_AGENT_INIT_PEI && BufferSize != 0) { if ((Phase2Context->InitFlag == DEBUG_AGENT_INIT_PEI) && (BufferSize != 0)) {
NewDebugPortHandle = (UINT64)(UINTN)AllocateCopyPool (BufferSize, DebugPortHandle); NewDebugPortHandle = (UINT64)(UINTN)AllocateCopyPool (BufferSize, DebugPortHandle);
} else { } else {
NewDebugPortHandle = (UINT64)(UINTN)DebugPortHandle; NewDebugPortHandle = (UINT64)(UINTN)DebugPortHandle;
} }
UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX, NewDebugPortHandle); UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX, NewDebugPortHandle);
// //
@ -684,10 +700,11 @@ InitializeDebugAgentPhase2 (
// host to disable low memory filtering. // host to disable low memory filtering.
// //
SecCoreData = (EFI_SEC_PEI_HAND_OFF *)Phase2Context->Context; SecCoreData = (EFI_SEC_PEI_HAND_OFF *)Phase2Context->Context;
if ((UINTN)SecCoreData->TemporaryRamBase < BASE_128MB && IsHostAttached ()) { if (((UINTN)SecCoreData->TemporaryRamBase < BASE_128MB) && IsHostAttached ()) {
SetDebugFlag (DEBUG_AGENT_FLAG_MEMORY_READY, 1); SetDebugFlag (DEBUG_AGENT_FLAG_MEMORY_READY, 1);
TriggerSoftInterrupt (MEMORY_READY_SIGNATURE); TriggerSoftInterrupt (MEMORY_READY_SIGNATURE);
} }
// //
// Enable Debug Timer interrupt // Enable Debug Timer interrupt
// //

View File

@ -56,4 +56,3 @@ DebugAgentCallbackMemoryDiscoveredPpi (
); );
#endif #endif

View File

@ -78,7 +78,8 @@ GetMailboxFromHob (
if (GuidHob == NULL) { if (GuidHob == NULL) {
return NULL; return NULL;
} }
MailboxLocation = (UINT64 *) (GET_GUID_HOB_DATA(GuidHob));
MailboxLocation = (UINT64 *)(GET_GUID_HOB_DATA (GuidHob));
Mailbox = (DEBUG_AGENT_MAILBOX *)(UINTN)(*MailboxLocation); Mailbox = (DEBUG_AGENT_MAILBOX *)(UINTN)(*MailboxLocation);
VerifyMailboxChecksum (Mailbox); VerifyMailboxChecksum (Mailbox);
@ -111,7 +112,7 @@ GetDebugPortHandle (
VOID VOID
) )
{ {
return (DEBUG_PORT_HANDLE) (UINTN)(GetMailboxPointer()->DebugPortHandle); return (DEBUG_PORT_HANDLE)(UINTN)(GetMailboxPointer ()->DebugPortHandle);
} }
/** /**
@ -199,22 +200,24 @@ InitializeDebugAgent (
Status = gSmst->SmmInstallConfigurationTable ( Status = gSmst->SmmInstallConfigurationTable (
gSmst, gSmst,
&gEfiVectorHandoffTableGuid, &gEfiVectorHandoffTableGuid,
(VOID *) &mVectorHandoffInfoDebugAgent[0], (VOID *)&mVectorHandoffInfoDebugAgent[0],
sizeof (EFI_VECTOR_HANDOFF_INFO) * mVectorHandoffInfoCount sizeof (EFI_VECTOR_HANDOFF_INFO) * mVectorHandoffInfoCount
); );
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "DebugAgent: Cannot install configuration table for persisted vector handoff info!\n")); DEBUG ((DEBUG_ERROR, "DebugAgent: Cannot install configuration table for persisted vector handoff info!\n"));
CpuDeadLoop (); CpuDeadLoop ();
} }
// //
// Check if Debug Agent initialized in DXE phase // Check if Debug Agent initialized in DXE phase
// //
Status = EfiGetSystemConfigurationTable (&gEfiDebugAgentGuid, (VOID **) &Mailbox); Status = EfiGetSystemConfigurationTable (&gEfiDebugAgentGuid, (VOID **)&Mailbox);
if (Status == EFI_SUCCESS && Mailbox != NULL) { if ((Status == EFI_SUCCESS) && (Mailbox != NULL)) {
VerifyMailboxChecksum (Mailbox); VerifyMailboxChecksum (Mailbox);
mMailboxPointer = Mailbox; mMailboxPointer = Mailbox;
break; break;
} }
// //
// Check if Debug Agent initialized in SEC/PEI phase // Check if Debug Agent initialized in SEC/PEI phase
// //
@ -223,6 +226,7 @@ InitializeDebugAgent (
mMailboxPointer = Mailbox; mMailboxPointer = Mailbox;
break; break;
} }
// //
// Debug Agent was not initialized before, use the local mailbox. // Debug Agent was not initialized before, use the local mailbox.
// //
@ -232,7 +236,7 @@ InitializeDebugAgent (
// Save original IDT entries // Save original IDT entries
// //
AsmReadIdtr (&IdtDescriptor); AsmReadIdtr (&IdtDescriptor);
CopyMem (&IdtEntry, (VOID *)IdtDescriptor.Base, 33 * sizeof(IA32_IDT_GATE_DESCRIPTOR)); CopyMem (&IdtEntry, (VOID *)IdtDescriptor.Base, 33 * sizeof (IA32_IDT_GATE_DESCRIPTOR));
// //
// Initialized Debug Agent // Initialized Debug Agent
// //
@ -243,7 +247,7 @@ InitializeDebugAgent (
InitializeDebugTimer (&DebugTimerFrequency, TRUE); InitializeDebugTimer (&DebugTimerFrequency, TRUE);
UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_DEBUG_TIMER_FREQUENCY, DebugTimerFrequency); UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_DEBUG_TIMER_FREQUENCY, DebugTimerFrequency);
DebugPortHandle = (UINT64) (UINTN)DebugPortInitialize ((DEBUG_PORT_HANDLE) (UINTN)Mailbox->DebugPortHandle, NULL); DebugPortHandle = (UINT64)(UINTN)DebugPortInitialize ((DEBUG_PORT_HANDLE)(UINTN)Mailbox->DebugPortHandle, NULL);
UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX, DebugPortHandle); UpdateMailboxContent (Mailbox, DEBUG_MAILBOX_DEBUG_PORT_HANDLE_INDEX, DebugPortHandle);
mMailboxPointer = Mailbox; mMailboxPointer = Mailbox;
// //
@ -261,6 +265,7 @@ InitializeDebugAgent (
// //
TriggerSoftInterrupt (MEMORY_READY_SIGNATURE); TriggerSoftInterrupt (MEMORY_READY_SIGNATURE);
} }
// //
// Find and report PE/COFF image info to HOST // Find and report PE/COFF image info to HOST
// //
@ -268,7 +273,7 @@ InitializeDebugAgent (
// //
// Restore saved IDT entries // Restore saved IDT entries
// //
CopyMem ((VOID *)IdtDescriptor.Base, &IdtEntry, 33 * sizeof(IA32_IDT_GATE_DESCRIPTOR)); CopyMem ((VOID *)IdtDescriptor.Base, &IdtEntry, 33 * sizeof (IA32_IDT_GATE_DESCRIPTOR));
break; break;
@ -282,16 +287,18 @@ InitializeDebugAgent (
InitializeDebugIdt (); InitializeDebugIdt ();
mSmmDebugIdtInitFlag = TRUE; mSmmDebugIdtInitFlag = TRUE;
} }
// //
// Check if CPU APIC Timer is working, otherwise initialize it. // Check if CPU APIC Timer is working, otherwise initialize it.
// //
InitializeLocalApicSoftwareEnable (TRUE); InitializeLocalApicSoftwareEnable (TRUE);
GetApicTimerState (&mApicTimerDivisor, &mPeriodicMode, &mVector); GetApicTimerState (&mApicTimerDivisor, &mPeriodicMode, &mVector);
mTimerCycle = GetApicTimerInitCount (); mTimerCycle = GetApicTimerInitCount ();
if (!mPeriodicMode || mTimerCycle == 0) { if (!mPeriodicMode || (mTimerCycle == 0)) {
mApicTimerRestore = TRUE; mApicTimerRestore = TRUE;
InitializeDebugTimer (NULL, FALSE); InitializeDebugTimer (NULL, FALSE);
} }
Mailbox = GetMailboxPointer (); Mailbox = GetMailboxPointer ();
if (GetDebugFlag (DEBUG_AGENT_FLAG_AGENT_IN_PROGRESS) == 1) { if (GetDebugFlag (DEBUG_AGENT_FLAG_AGENT_IN_PROGRESS) == 1) {
// //
@ -300,12 +307,14 @@ InitializeDebugAgent (
// //
mSkipBreakpoint = TRUE; mSkipBreakpoint = TRUE;
} }
if (GetDebugFlag (DEBUG_AGENT_FLAG_BREAK_ON_NEXT_SMI) == 1) { if (GetDebugFlag (DEBUG_AGENT_FLAG_BREAK_ON_NEXT_SMI) == 1) {
if (mSkipBreakpoint) { if (mSkipBreakpoint) {
// //
// Print warning message if ignore smm entry break // Print warning message if ignore smm entry break
// //
DebugPortWriteBuffer ((DEBUG_PORT_HANDLE) (UINTN)Mailbox->DebugPortHandle, DebugPortWriteBuffer (
(DEBUG_PORT_HANDLE)(UINTN)Mailbox->DebugPortHandle,
(UINT8 *)mWarningMsgIgnoreSmmEntryBreak, (UINT8 *)mWarningMsgIgnoreSmmEntryBreak,
AsciiStrLen (mWarningMsgIgnoreSmmEntryBreak) AsciiStrLen (mWarningMsgIgnoreSmmEntryBreak)
); );
@ -316,6 +325,7 @@ InitializeDebugAgent (
CpuBreakpoint (); CpuBreakpoint ();
} }
} }
break; break;
case DEBUG_AGENT_INIT_EXIT_SMI: case DEBUG_AGENT_INIT_EXIT_SMI:
@ -332,6 +342,7 @@ InitializeDebugAgent (
InitializeApicTimer (mApicTimerDivisor, mTimerCycle, mPeriodicMode, mVector); InitializeApicTimer (mApicTimerDivisor, mTimerCycle, mPeriodicMode, mVector);
mApicTimerRestore = FALSE; mApicTimerRestore = FALSE;
} }
break; break;
case DEBUG_AGENT_INIT_THUNK_PEI_IA32TOX64: case DEBUG_AGENT_INIT_THUNK_PEI_IA32TOX64:
@ -339,22 +350,22 @@ InitializeDebugAgent (
DEBUG ((DEBUG_ERROR, "DebugAgent: Input parameter Context cannot be NULL!\n")); DEBUG ((DEBUG_ERROR, "DebugAgent: Input parameter Context cannot be NULL!\n"));
CpuDeadLoop (); CpuDeadLoop ();
} else { } else {
Ia32Idtr = (IA32_DESCRIPTOR *) Context; Ia32Idtr = (IA32_DESCRIPTOR *)Context;
Ia32IdtEntry = (IA32_IDT_ENTRY *)(Ia32Idtr->Base); Ia32IdtEntry = (IA32_IDT_ENTRY *)(Ia32Idtr->Base);
MailboxLocation = (UINT64 *) ((UINTN) Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetLow + MailboxLocation = (UINT64 *)((UINTN)Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetLow +
((UINTN) Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetHigh << 16)); ((UINTN)Ia32IdtEntry[DEBUG_MAILBOX_VECTOR].Bits.OffsetHigh << 16));
mMailboxPointer = (DEBUG_AGENT_MAILBOX *)(UINTN)(*MailboxLocation); mMailboxPointer = (DEBUG_AGENT_MAILBOX *)(UINTN)(*MailboxLocation);
VerifyMailboxChecksum (mMailboxPointer); VerifyMailboxChecksum (mMailboxPointer);
// //
// Get original IDT address and size. // Get original IDT address and size.
// //
AsmReadIdtr ((IA32_DESCRIPTOR *) &Idtr); AsmReadIdtr ((IA32_DESCRIPTOR *)&Idtr);
IdtEntryCount = (UINT16) ((Idtr.Limit + 1) / sizeof (IA32_IDT_GATE_DESCRIPTOR)); IdtEntryCount = (UINT16)((Idtr.Limit + 1) / sizeof (IA32_IDT_GATE_DESCRIPTOR));
if (IdtEntryCount < 33) { if (IdtEntryCount < 33) {
Idtr.Limit = (UINT16) (sizeof (IA32_IDT_GATE_DESCRIPTOR) * 33 - 1); Idtr.Limit = (UINT16)(sizeof (IA32_IDT_GATE_DESCRIPTOR) * 33 - 1);
Idtr.Base = (UINTN) &mIdtEntryTable; Idtr.Base = (UINTN)&mIdtEntryTable;
ZeroMem (&mIdtEntryTable, Idtr.Limit + 1); ZeroMem (&mIdtEntryTable, Idtr.Limit + 1);
AsmWriteIdtr ((IA32_DESCRIPTOR *) &Idtr); AsmWriteIdtr ((IA32_DESCRIPTOR *)&Idtr);
} }
InitializeDebugIdt (); InitializeDebugIdt ();
@ -371,6 +382,7 @@ InitializeDebugAgent (
FindAndReportModuleImageInfo (SIZE_4KB); FindAndReportModuleImageInfo (SIZE_4KB);
} }
break; break;
default: default:

View File

@ -58,7 +58,7 @@ DebugPortInitialize (
RETURN_STATUS Status; RETURN_STATUS Status;
Status = SerialPortInitialize (); Status = SerialPortInitialize ();
if (RETURN_ERROR(Status)) { if (RETURN_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "Debug Serial Port: Initialization failed!\n")); DEBUG ((DEBUG_ERROR, "Debug Serial Port: Initialization failed!\n"));
} }
@ -95,7 +95,7 @@ DebugPortReadBuffer (
IN UINTN Timeout IN UINTN Timeout
) )
{ {
if (NumberOfBytes != 1 || Buffer == NULL || Timeout != 0) { if ((NumberOfBytes != 1) || (Buffer == NULL) || (Timeout != 0)) {
return 0; return 0;
} }

View File

@ -50,15 +50,15 @@ typedef struct _USB_DEBUG_PORT_DESCRIPTOR {
UINT8 DescriptorType; UINT8 DescriptorType;
UINT8 DebugInEndpoint; UINT8 DebugInEndpoint;
UINT8 DebugOutEndpoint; UINT8 DebugOutEndpoint;
}USB_DEBUG_PORT_DESCRIPTOR; } USB_DEBUG_PORT_DESCRIPTOR;
USB_DEVICE_REQUEST mDebugCommunicationLibUsbGetDebugDescriptor = { USB_DEVICE_REQUEST mDebugCommunicationLibUsbGetDebugDescriptor = {
0x80, 0x80,
USB_REQ_GET_DESCRIPTOR, USB_REQ_GET_DESCRIPTOR,
(UINT16)(0x0A << 8), (UINT16)(0x0A << 8),
0x0000, 0x0000,
sizeof(USB_DEBUG_PORT_DESCRIPTOR) sizeof (USB_DEBUG_PORT_DESCRIPTOR)
}; };
USB_DEVICE_REQUEST mDebugCommunicationLibUsbSetDebugFeature = { USB_DEVICE_REQUEST mDebugCommunicationLibUsbSetDebugFeature = {
0x0, 0x0,
@ -66,7 +66,7 @@ USB_DEVICE_REQUEST mDebugCommunicationLibUsbSetDebugFeature = {
(UINT16)(0x06), (UINT16)(0x06),
0x0000, 0x0000,
0x0 0x0
}; };
USB_DEVICE_REQUEST mDebugCommunicationLibUsbSetDebugAddress = { USB_DEVICE_REQUEST mDebugCommunicationLibUsbSetDebugAddress = {
0x0, 0x0,
@ -74,7 +74,7 @@ USB_DEVICE_REQUEST mDebugCommunicationLibUsbSetDebugAddress = {
(UINT16)(0x7F), (UINT16)(0x7F),
0x0000, 0x0000,
0x0 0x0
}; };
// //
// Usb debug port register file, which is defined at // Usb debug port register file, which is defined at
@ -91,7 +91,7 @@ typedef struct _USB_DEBUG_PORT_REGISTER {
UINT8 UsbAddress; UINT8 UsbAddress;
UINT8 Reserved2; UINT8 Reserved2;
UINT8 Reserved3; UINT8 Reserved3;
}USB_DEBUG_PORT_REGISTER; } USB_DEBUG_PORT_REGISTER;
// //
// The state machine of usb debug port // The state machine of usb debug port
@ -107,7 +107,7 @@ typedef struct _USB_DEBUG_PORT_REGISTER {
// The internal data structure of DEBUG_PORT_HANDLE, which stores some // The internal data structure of DEBUG_PORT_HANDLE, which stores some
// important datum which are used across various phases. // important datum which are used across various phases.
// //
typedef struct _USB_DEBUG_PORT_HANDLE{ typedef struct _USB_DEBUG_PORT_HANDLE {
// //
// The usb debug port memory BAR number in EHCI configuration space. // The usb debug port memory BAR number in EHCI configuration space.
// //
@ -183,16 +183,16 @@ CalculateUsbDebugPortBar (
UINT8 CapabilityPtr; UINT8 CapabilityPtr;
UINT8 CapabilityId; UINT8 CapabilityId;
VendorId = PciRead16 (PcdGet32(PcdUsbEhciPciAddress) + PCI_VENDOR_ID_OFFSET); VendorId = PciRead16 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_VENDOR_ID_OFFSET);
DeviceId = PciRead16 (PcdGet32(PcdUsbEhciPciAddress) + PCI_DEVICE_ID_OFFSET); DeviceId = PciRead16 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_DEVICE_ID_OFFSET);
if ((VendorId == 0xFFFF) || (DeviceId == 0xFFFF)) { if ((VendorId == 0xFFFF) || (DeviceId == 0xFFFF)) {
return RETURN_UNSUPPORTED; return RETURN_UNSUPPORTED;
} }
ProgInterface = PciRead8 (PcdGet32(PcdUsbEhciPciAddress) + PCI_CLASSCODE_OFFSET); ProgInterface = PciRead8 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_CLASSCODE_OFFSET);
SubClassCode = PciRead8 (PcdGet32(PcdUsbEhciPciAddress) + PCI_CLASSCODE_OFFSET + 1); SubClassCode = PciRead8 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_CLASSCODE_OFFSET + 1);
BaseCode = PciRead8 (PcdGet32(PcdUsbEhciPciAddress) + PCI_CLASSCODE_OFFSET + 2); BaseCode = PciRead8 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_CLASSCODE_OFFSET + 2);
if ((ProgInterface != PCI_IF_EHCI) || (SubClassCode != PCI_CLASS_SERIAL_USB) || (BaseCode != PCI_CLASS_SERIAL)) { if ((ProgInterface != PCI_IF_EHCI) || (SubClassCode != PCI_CLASS_SERIAL_USB) || (BaseCode != PCI_CLASS_SERIAL)) {
return RETURN_UNSUPPORTED; return RETURN_UNSUPPORTED;
@ -201,7 +201,7 @@ CalculateUsbDebugPortBar (
// //
// Enable Ehci Host Controller MMIO Space. // Enable Ehci Host Controller MMIO Space.
// //
PciStatus = PciRead16 (PcdGet32(PcdUsbEhciPciAddress) + PCI_PRIMARY_STATUS_OFFSET); PciStatus = PciRead16 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_PRIMARY_STATUS_OFFSET);
if ((PciStatus & EFI_PCI_STATUS_CAPABILITY) == 0) { if ((PciStatus & EFI_PCI_STATUS_CAPABILITY) == 0) {
// //
@ -213,17 +213,18 @@ CalculateUsbDebugPortBar (
// //
// Get Pointer To Capability List // Get Pointer To Capability List
// //
CapabilityPtr = PciRead8(PcdGet32(PcdUsbEhciPciAddress) + PCI_CAPBILITY_POINTER_OFFSET); CapabilityPtr = PciRead8 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_CAPBILITY_POINTER_OFFSET);
// //
// Find Capability ID 0xA, Which Is For Debug Port // Find Capability ID 0xA, Which Is For Debug Port
// //
while (CapabilityPtr != 0) { while (CapabilityPtr != 0) {
CapabilityId = PciRead8(PcdGet32(PcdUsbEhciPciAddress) + CapabilityPtr); CapabilityId = PciRead8 (PcdGet32 (PcdUsbEhciPciAddress) + CapabilityPtr);
if (CapabilityId == PCI_CAPABILITY_ID_DEBUG_PORT) { if (CapabilityId == PCI_CAPABILITY_ID_DEBUG_PORT) {
break; break;
} }
CapabilityPtr = PciRead8(PcdGet32(PcdUsbEhciPciAddress) + CapabilityPtr + 1);
CapabilityPtr = PciRead8 (PcdGet32 (PcdUsbEhciPciAddress) + CapabilityPtr + 1);
} }
// //
@ -236,8 +237,8 @@ CalculateUsbDebugPortBar (
// //
// Get The Base Address Of Debug Port Register In Debug Port Capability Register // Get The Base Address Of Debug Port Register In Debug Port Capability Register
// //
*DebugPortOffset = (UINT16)(PciRead16(PcdGet32(PcdUsbEhciPciAddress) + CapabilityPtr + 2) & 0x1FFF); *DebugPortOffset = (UINT16)(PciRead16 (PcdGet32 (PcdUsbEhciPciAddress) + CapabilityPtr + 2) & 0x1FFF);
*DebugPortBarNumbar = (UINT8)((PciRead16(PcdGet32(PcdUsbEhciPciAddress) + CapabilityPtr + 2) >> 13) - 1); *DebugPortBarNumbar = (UINT8)((PciRead16 (PcdGet32 (PcdUsbEhciPciAddress) + CapabilityPtr + 2) >> 13) - 1);
return RETURN_SUCCESS; return RETURN_SUCCESS;
} }
@ -275,6 +276,7 @@ UsbDebugPortIn (
if (Length == NULL) { if (Length == NULL) {
return RETURN_INVALID_PARAMETER; return RETURN_INVALID_PARAMETER;
} }
*Length = 0; *Length = 0;
DebugPortRegister->TokenPid = Token; DebugPortRegister->TokenPid = Token;
@ -290,19 +292,20 @@ UsbDebugPortIn (
// //
// Clearing W/R bit to indicate it's a READ operation // Clearing W/R bit to indicate it's a READ operation
// //
MmioAnd32((UINTN)&DebugPortRegister->ControlStatus, (UINT32)~BIT4); MmioAnd32 ((UINTN)&DebugPortRegister->ControlStatus, (UINT32) ~BIT4);
// //
// Setting GO bit as well as clearing DONE bit // Setting GO bit as well as clearing DONE bit
// //
MmioOr32((UINTN)&DebugPortRegister->ControlStatus, (UINT32)BIT5); MmioOr32 ((UINTN)&DebugPortRegister->ControlStatus, (UINT32)BIT5);
// //
// Wait for completing the request // Wait for completing the request
// //
while ((MmioRead32((UINTN)&DebugPortRegister->ControlStatus) & (UINT32)BIT16) == 0) { while ((MmioRead32 ((UINTN)&DebugPortRegister->ControlStatus) & (UINT32)BIT16) == 0) {
if ((MmioRead32((UINTN)&DebugPortRegister->ControlStatus) & (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_IN_USE | USB_DEBUG_PORT_ENABLE)) if ((MmioRead32 ((UINTN)&DebugPortRegister->ControlStatus) & (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_IN_USE | USB_DEBUG_PORT_ENABLE))
!= (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_IN_USE | USB_DEBUG_PORT_ENABLE)) { != (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_IN_USE | USB_DEBUG_PORT_ENABLE))
{
return RETURN_DEVICE_ERROR; return RETURN_DEVICE_ERROR;
} }
} }
@ -310,23 +313,23 @@ UsbDebugPortIn (
// //
// Clearing DONE bit by writing 1 // Clearing DONE bit by writing 1
// //
MmioOr32((UINTN)&DebugPortRegister->ControlStatus, BIT16); MmioOr32 ((UINTN)&DebugPortRegister->ControlStatus, BIT16);
// //
// Check if the request is executed successfully or not. // Check if the request is executed successfully or not.
// //
if ((MmioRead32((UINTN)&DebugPortRegister->ControlStatus)) & BIT6) { if ((MmioRead32 ((UINTN)&DebugPortRegister->ControlStatus)) & BIT6) {
return RETURN_DEVICE_ERROR; return RETURN_DEVICE_ERROR;
} }
// //
// Make sure the received data are not beyond the allowable maximum length - 8 byte // Make sure the received data are not beyond the allowable maximum length - 8 byte
// //
if (((MmioRead32((UINTN)&DebugPortRegister->ControlStatus)) & 0xF) > USB_DEBUG_PORT_MAX_PACKET_SIZE) { if (((MmioRead32 ((UINTN)&DebugPortRegister->ControlStatus)) & 0xF) > USB_DEBUG_PORT_MAX_PACKET_SIZE) {
return RETURN_DEVICE_ERROR; return RETURN_DEVICE_ERROR;
} }
*Length = (UINT8)(MmioRead32((UINTN)&DebugPortRegister->ControlStatus) & 0xF); *Length = (UINT8)(MmioRead32 ((UINTN)&DebugPortRegister->ControlStatus) & 0xF);
if (*Length > 8) { if (*Length > 8) {
return RETURN_DEVICE_ERROR; return RETURN_DEVICE_ERROR;
} }
@ -334,6 +337,7 @@ UsbDebugPortIn (
for (Index = 0; Index < *Length; Index++) { for (Index = 0; Index < *Length; Index++) {
Buffer[Index] = DebugPortRegister->DataBuffer[Index]; Buffer[Index] = DebugPortRegister->DataBuffer[Index];
} }
return RETURN_SUCCESS; return RETURN_SUCCESS;
} }
@ -377,14 +381,15 @@ UsbDebugPortOut (
} else { } else {
DebugPortRegister->SendPid = DATA0_PID; DebugPortRegister->SendPid = DATA0_PID;
} }
DebugPortRegister->UsbAddress = (UINT8)(Addr & 0x7F); DebugPortRegister->UsbAddress = (UINT8)(Addr & 0x7F);
DebugPortRegister->UsbEndPoint = (UINT8)(Ep & 0xF); DebugPortRegister->UsbEndPoint = (UINT8)(Ep & 0xF);
// //
// Fill in the data length and corresponding data. // Fill in the data length and corresponding data.
// //
MmioAnd32((UINTN)&DebugPortRegister->ControlStatus, (UINT32)~0xF); MmioAnd32 ((UINTN)&DebugPortRegister->ControlStatus, (UINT32) ~0xF);
MmioOr32((UINTN)&DebugPortRegister->ControlStatus, Length & 0xF); MmioOr32 ((UINTN)&DebugPortRegister->ControlStatus, Length & 0xF);
for (Index = 0; Index < Length; Index++) { for (Index = 0; Index < Length; Index++) {
DebugPortRegister->DataBuffer[Index] = Buffer[Index]; DebugPortRegister->DataBuffer[Index] = Buffer[Index];
} }
@ -392,18 +397,19 @@ UsbDebugPortOut (
// //
// Setting W/R bit to indicate it's a WRITE operation // Setting W/R bit to indicate it's a WRITE operation
// //
MmioOr32((UINTN)&DebugPortRegister->ControlStatus, BIT4); MmioOr32 ((UINTN)&DebugPortRegister->ControlStatus, BIT4);
// //
// Setting GO bit as well as clearing DONE bit // Setting GO bit as well as clearing DONE bit
// //
MmioOr32((UINTN)&DebugPortRegister->ControlStatus, BIT5); MmioOr32 ((UINTN)&DebugPortRegister->ControlStatus, BIT5);
// //
// Wait for completing the request // Wait for completing the request
// //
while ((MmioRead32((UINTN)&DebugPortRegister->ControlStatus) & BIT16) == 0) { while ((MmioRead32 ((UINTN)&DebugPortRegister->ControlStatus) & BIT16) == 0) {
if ((MmioRead32((UINTN)&DebugPortRegister->ControlStatus) & (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_IN_USE | USB_DEBUG_PORT_ENABLE)) if ((MmioRead32 ((UINTN)&DebugPortRegister->ControlStatus) & (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_IN_USE | USB_DEBUG_PORT_ENABLE))
!= (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_IN_USE | USB_DEBUG_PORT_ENABLE)) { != (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_IN_USE | USB_DEBUG_PORT_ENABLE))
{
return RETURN_DEVICE_ERROR; return RETURN_DEVICE_ERROR;
} }
} }
@ -411,19 +417,19 @@ UsbDebugPortOut (
// //
// Clearing DONE bit by writing 1 // Clearing DONE bit by writing 1
// //
MmioOr32((UINTN)&DebugPortRegister->ControlStatus, BIT16); MmioOr32 ((UINTN)&DebugPortRegister->ControlStatus, BIT16);
// //
// Check if the request is executed successfully or not. // Check if the request is executed successfully or not.
// //
if ((MmioRead32((UINTN)&DebugPortRegister->ControlStatus)) & BIT6) { if ((MmioRead32 ((UINTN)&DebugPortRegister->ControlStatus)) & BIT6) {
return RETURN_DEVICE_ERROR; return RETURN_DEVICE_ERROR;
} }
// //
// Make sure the sent data are not beyond the allowable maximum length - 8 byte // Make sure the sent data are not beyond the allowable maximum length - 8 byte
// //
if (((MmioRead32((UINTN)&DebugPortRegister->ControlStatus)) & 0xF) > USB_DEBUG_PORT_MAX_PACKET_SIZE) { if (((MmioRead32 ((UINTN)&DebugPortRegister->ControlStatus)) & 0xF) > USB_DEBUG_PORT_MAX_PACKET_SIZE) {
return RETURN_DEVICE_ERROR; return RETURN_DEVICE_ERROR;
} }
@ -463,8 +469,8 @@ UsbDebugPortControlTransfer (
// //
// Setup Phase // Setup Phase
// //
Status = UsbDebugPortOut(DebugPortRegister, (UINT8 *)SetupPacket, (UINT8)sizeof(USB_DEVICE_REQUEST), SETUP_PID, Addr, Ep, 0); Status = UsbDebugPortOut (DebugPortRegister, (UINT8 *)SetupPacket, (UINT8)sizeof (USB_DEVICE_REQUEST), SETUP_PID, Addr, Ep, 0);
if (RETURN_ERROR(Status)) { if (RETURN_ERROR (Status)) {
return Status; return Status;
} }
@ -476,16 +482,16 @@ UsbDebugPortControlTransfer (
// //
// Get Data From Device // Get Data From Device
// //
Status = UsbDebugPortIn(DebugPortRegister, Data, DataLength, INPUT_PID, Addr, Ep, 1); Status = UsbDebugPortIn (DebugPortRegister, Data, DataLength, INPUT_PID, Addr, Ep, 1);
if (RETURN_ERROR(Status)) { if (RETURN_ERROR (Status)) {
return Status; return Status;
} }
} else { } else {
// //
// Send Data To Device // Send Data To Device
// //
Status = UsbDebugPortOut(DebugPortRegister, Data, *DataLength, OUTPUT_PID, Addr, Ep, 1); Status = UsbDebugPortOut (DebugPortRegister, Data, *DataLength, OUTPUT_PID, Addr, Ep, 1);
if (RETURN_ERROR(Status)) { if (RETURN_ERROR (Status)) {
return Status; return Status;
} }
} }
@ -498,12 +504,12 @@ UsbDebugPortControlTransfer (
// //
// For READ operation, Data Toggle in Status Phase Should be 1. // For READ operation, Data Toggle in Status Phase Should be 1.
// //
Status = UsbDebugPortOut(DebugPortRegister, NULL, 0, OUTPUT_PID, Addr, Ep, 1); Status = UsbDebugPortOut (DebugPortRegister, NULL, 0, OUTPUT_PID, Addr, Ep, 1);
} else { } else {
// //
// For WRITE operation, Data Toggle in Status Phase Should be 1. // For WRITE operation, Data Toggle in Status Phase Should be 1.
// //
Status = UsbDebugPortIn(DebugPortRegister, ReturnStatus, &Temp, INPUT_PID, Addr, Ep, 1); Status = UsbDebugPortIn (DebugPortRegister, ReturnStatus, &Temp, INPUT_PID, Addr, Ep, 1);
} }
return Status; return Status;
@ -524,7 +530,7 @@ UsbDebugPortControlTransfer (
**/ **/
BOOLEAN BOOLEAN
EFIAPI EFIAPI
NeedReinitializeHardware( NeedReinitializeHardware (
IN USB_DEBUG_PORT_HANDLE *Handle IN USB_DEBUG_PORT_HANDLE *Handle
) )
{ {
@ -536,13 +542,13 @@ NeedReinitializeHardware(
Status = FALSE; Status = FALSE;
EhciMemoryBase = 0xFFFFFC00 & PciRead32(PcdGet32(PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET); EhciMemoryBase = 0xFFFFFC00 & PciRead32 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET);
if (EhciMemoryBase != Handle->EhciMemoryBase) { if (EhciMemoryBase != Handle->EhciMemoryBase) {
Handle->EhciMemoryBase = EhciMemoryBase; Handle->EhciMemoryBase = EhciMemoryBase;
Status = TRUE; Status = TRUE;
} }
UsbDebugPortMemoryBase = 0xFFFFFC00 & PciRead32(PcdGet32(PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET + Handle->DebugPortBarNumber * 4); UsbDebugPortMemoryBase = 0xFFFFFC00 & PciRead32 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET + Handle->DebugPortBarNumber * 4);
if (UsbDebugPortMemoryBase != Handle->UsbDebugPortMemoryBase) { if (UsbDebugPortMemoryBase != Handle->UsbDebugPortMemoryBase) {
Handle->UsbDebugPortMemoryBase = UsbDebugPortMemoryBase; Handle->UsbDebugPortMemoryBase = UsbDebugPortMemoryBase;
Status = TRUE; Status = TRUE;
@ -551,10 +557,10 @@ NeedReinitializeHardware(
// //
// Enable Ehci Memory Space Access // Enable Ehci Memory Space Access
// //
PciCmd = PciRead16 (PcdGet32(PcdUsbEhciPciAddress) + PCI_COMMAND_OFFSET); PciCmd = PciRead16 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_COMMAND_OFFSET);
if (((PciCmd & EFI_PCI_COMMAND_MEMORY_SPACE) == 0) || ((PciCmd & EFI_PCI_COMMAND_BUS_MASTER) == 0)) { if (((PciCmd & EFI_PCI_COMMAND_MEMORY_SPACE) == 0) || ((PciCmd & EFI_PCI_COMMAND_BUS_MASTER) == 0)) {
PciCmd |= EFI_PCI_COMMAND_MEMORY_SPACE | EFI_PCI_COMMAND_BUS_MASTER; PciCmd |= EFI_PCI_COMMAND_MEMORY_SPACE | EFI_PCI_COMMAND_BUS_MASTER;
PciWrite16(PcdGet32(PcdUsbEhciPciAddress) + PCI_COMMAND_OFFSET, PciCmd); PciWrite16 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_COMMAND_OFFSET, PciCmd);
Status = TRUE; Status = TRUE;
} }
@ -562,8 +568,9 @@ NeedReinitializeHardware(
// If the owner and in_use bit is not set, it means system is doing cold/warm boot or EHCI host controller is reset by system software. // If the owner and in_use bit is not set, it means system is doing cold/warm boot or EHCI host controller is reset by system software.
// //
UsbDebugPortRegister = (USB_DEBUG_PORT_REGISTER *)((UINTN)Handle->UsbDebugPortMemoryBase + Handle->DebugPortOffset); UsbDebugPortRegister = (USB_DEBUG_PORT_REGISTER *)((UINTN)Handle->UsbDebugPortMemoryBase + Handle->DebugPortOffset);
if ((MmioRead32((UINTN)&UsbDebugPortRegister->ControlStatus) & (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_ENABLE | USB_DEBUG_PORT_IN_USE)) if ((MmioRead32 ((UINTN)&UsbDebugPortRegister->ControlStatus) & (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_ENABLE | USB_DEBUG_PORT_IN_USE))
!= (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_ENABLE | USB_DEBUG_PORT_IN_USE)) { != (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_ENABLE | USB_DEBUG_PORT_IN_USE))
{
Status = TRUE; Status = TRUE;
} }
@ -572,6 +579,7 @@ NeedReinitializeHardware(
} else if (Handle->Initialized != USBDBG_INIT_DONE) { } else if (Handle->Initialized != USBDBG_INIT_DONE) {
Status = TRUE; Status = TRUE;
} }
return Status; return Status;
} }
@ -594,7 +602,7 @@ RETURN_STATUS
EFIAPI EFIAPI
InitializeUsbDebugHardware ( InitializeUsbDebugHardware (
IN USB_DEBUG_PORT_HANDLE *Handle IN USB_DEBUG_PORT_HANDLE *Handle
) )
{ {
RETURN_STATUS Status; RETURN_STATUS Status;
USB_DEBUG_PORT_REGISTER *UsbDebugPortRegister; USB_DEBUG_PORT_REGISTER *UsbDebugPortRegister;
@ -614,67 +622,73 @@ InitializeUsbDebugHardware (
// //
// Check if the debug port is enabled and owned by myself. // Check if the debug port is enabled and owned by myself.
// //
if (((MmioRead32((UINTN)&UsbDebugPortRegister->ControlStatus) & (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_IN_USE)) if (((MmioRead32 ((UINTN)&UsbDebugPortRegister->ControlStatus) & (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_IN_USE))
!= (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_IN_USE)) || (Handle->Initialized == USBDBG_RESET)) { != (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_IN_USE)) || (Handle->Initialized == USBDBG_RESET))
{
DEBUG (( DEBUG ((
DEBUG_INFO, DEBUG_INFO,
"UsbDbg: Need to reset the host controller. ControlStatus = %08x\n", "UsbDbg: Need to reset the host controller. ControlStatus = %08x\n",
MmioRead32((UINTN)&UsbDebugPortRegister->ControlStatus) MmioRead32 ((UINTN)&UsbDebugPortRegister->ControlStatus)
)); ));
// //
// If the host controller is halted, then reset and restart it. // If the host controller is halted, then reset and restart it.
// //
if ((MmioRead32((UINTN)UsbStatus) & BIT12) != 0) { if ((MmioRead32 ((UINTN)UsbStatus) & BIT12) != 0) {
DEBUG ((DEBUG_INFO, "UsbDbg: Reset the host controller.\n")); DEBUG ((DEBUG_INFO, "UsbDbg: Reset the host controller.\n"));
// //
// reset the host controller. // reset the host controller.
// //
MmioOr32((UINTN)UsbCmd, BIT1); MmioOr32 ((UINTN)UsbCmd, BIT1);
// //
// ensure that the host controller is reset. // ensure that the host controller is reset.
// //
while ((MmioRead32((UINTN)UsbCmd) & BIT1) != 0); while ((MmioRead32 ((UINTN)UsbCmd) & BIT1) != 0) {
}
MmioOr32((UINTN)UsbCmd, BIT0); MmioOr32 ((UINTN)UsbCmd, BIT0);
// ensure that the host controller is started (HALTED bit must be cleared) // ensure that the host controller is started (HALTED bit must be cleared)
while ((MmioRead32((UINTN)UsbStatus) & BIT12) != 0); while ((MmioRead32 ((UINTN)UsbStatus) & BIT12) != 0) {
}
} }
// //
// First get the ownership of port 0. // First get the ownership of port 0.
// //
MmioOr32((UINTN)&UsbDebugPortRegister->ControlStatus, USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_IN_USE); MmioOr32 ((UINTN)&UsbDebugPortRegister->ControlStatus, USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_IN_USE);
MicroSecondDelay (200000); MicroSecondDelay (200000);
} }
// //
// Find out which port is used as debug port. // Find out which port is used as debug port.
// //
DebugPortNumber = (UINT8)((MmioRead32((UINTN)UsbHCSParam) & 0x00F00000) >> 20); DebugPortNumber = (UINT8)((MmioRead32 ((UINTN)UsbHCSParam) & 0x00F00000) >> 20);
// //
// Should find a device is connected at debug port // Should find a device is connected at debug port
// //
PortStatus = (UINT32 *)((UINTN)Handle->EhciMemoryBase + 0x64 + (DebugPortNumber - 1) * 4); PortStatus = (UINT32 *)((UINTN)Handle->EhciMemoryBase + 0x64 + (DebugPortNumber - 1) * 4);
if (!(MmioRead32((UINTN)PortStatus) & BIT0)) { if (!(MmioRead32 ((UINTN)PortStatus) & BIT0)) {
Handle->Initialized = USBDBG_NO_DEV; Handle->Initialized = USBDBG_NO_DEV;
return RETURN_NOT_FOUND; return RETURN_NOT_FOUND;
} }
if (Handle->Initialized != USBDBG_INIT_DONE || if ((Handle->Initialized != USBDBG_INIT_DONE) ||
(MmioRead32 ((UINTN) &UsbDebugPortRegister->ControlStatus) & USB_DEBUG_PORT_ENABLE) == 0) { ((MmioRead32 ((UINTN)&UsbDebugPortRegister->ControlStatus) & USB_DEBUG_PORT_ENABLE) == 0))
{
DEBUG ((DEBUG_INFO, "UsbDbg: Reset the debug port.\n")); DEBUG ((DEBUG_INFO, "UsbDbg: Reset the debug port.\n"));
// //
// Reset the debug port // Reset the debug port
// //
MmioOr32((UINTN)PortStatus, BIT8); MmioOr32 ((UINTN)PortStatus, BIT8);
MicroSecondDelay (500000); MicroSecondDelay (500000);
MmioAnd32((UINTN)PortStatus, (UINT32)~BIT8); MmioAnd32 ((UINTN)PortStatus, (UINT32) ~BIT8);
while (MmioRead32((UINTN)PortStatus) & BIT8); while (MmioRead32 ((UINTN)PortStatus) & BIT8) {
}
// //
// The port enabled bit should be set by HW. // The port enabled bit should be set by HW.
// //
if ((MmioRead32((UINTN)PortStatus) & BIT2) == 0) { if ((MmioRead32 ((UINTN)PortStatus) & BIT2) == 0) {
Handle->Initialized = USBDBG_NO_DBG_CAB; Handle->Initialized = USBDBG_NO_DBG_CAB;
return RETURN_DEVICE_ERROR; return RETURN_DEVICE_ERROR;
} }
@ -682,7 +696,7 @@ InitializeUsbDebugHardware (
// //
// Enable Usb Debug Port Capability // Enable Usb Debug Port Capability
// //
MmioOr32((UINTN)&UsbDebugPortRegister->ControlStatus, USB_DEBUG_PORT_ENABLE); MmioOr32 ((UINTN)&UsbDebugPortRegister->ControlStatus, USB_DEBUG_PORT_ENABLE);
// //
// initialize the data toggle used by bulk in/out endpoint. // initialize the data toggle used by bulk in/out endpoint.
@ -694,7 +708,7 @@ InitializeUsbDebugHardware (
// set usb debug device address as 0x7F. // set usb debug device address as 0x7F.
// //
Status = UsbDebugPortControlTransfer (UsbDebugPortRegister, &mDebugCommunicationLibUsbSetDebugAddress, 0x0, 0x0, NULL, NULL); Status = UsbDebugPortControlTransfer (UsbDebugPortRegister, &mDebugCommunicationLibUsbSetDebugAddress, 0x0, 0x0, NULL, NULL);
if (RETURN_ERROR(Status)) { if (RETURN_ERROR (Status)) {
// //
// The device can not work well. // The device can not work well.
// //
@ -710,8 +724,8 @@ InitializeUsbDebugHardware (
// //
// Get debug descriptor. // Get debug descriptor.
// //
Status = UsbDebugPortControlTransfer (UsbDebugPortRegister, &mDebugCommunicationLibUsbGetDebugDescriptor, 0x7F, 0x0, (UINT8*)&UsbDebugPortDescriptor, &Length); Status = UsbDebugPortControlTransfer (UsbDebugPortRegister, &mDebugCommunicationLibUsbGetDebugDescriptor, 0x7F, 0x0, (UINT8 *)&UsbDebugPortDescriptor, &Length);
if (RETURN_ERROR(Status)) { if (RETURN_ERROR (Status)) {
// //
// The device is not a usb debug device. // The device is not a usb debug device.
// //
@ -719,7 +733,7 @@ InitializeUsbDebugHardware (
return Status; return Status;
} }
if (Length != sizeof(USB_DEBUG_PORT_DESCRIPTOR)) { if (Length != sizeof (USB_DEBUG_PORT_DESCRIPTOR)) {
Handle->Initialized = USBDBG_NO_DBG_CAB; Handle->Initialized = USBDBG_NO_DBG_CAB;
return RETURN_DEVICE_ERROR; return RETURN_DEVICE_ERROR;
} }
@ -734,7 +748,7 @@ InitializeUsbDebugHardware (
// enable the usb debug feature. // enable the usb debug feature.
// //
Status = UsbDebugPortControlTransfer (UsbDebugPortRegister, &mDebugCommunicationLibUsbSetDebugFeature, 0x7F, 0x0, NULL, NULL); Status = UsbDebugPortControlTransfer (UsbDebugPortRegister, &mDebugCommunicationLibUsbSetDebugFeature, 0x7F, 0x0, NULL, NULL);
if (RETURN_ERROR(Status)) { if (RETURN_ERROR (Status)) {
// //
// The device can not work well. // The device can not work well.
// //
@ -783,7 +797,7 @@ DebugPortReadBuffer (
RETURN_STATUS Status; RETURN_STATUS Status;
UINT8 Index; UINT8 Index;
if (NumberOfBytes != 1 || Buffer == NULL || Timeout != 0) { if ((NumberOfBytes != 1) || (Buffer == NULL) || (Timeout != 0)) {
return 0; return 0;
} }
@ -797,9 +811,9 @@ DebugPortReadBuffer (
UsbDebugPortHandle = (USB_DEBUG_PORT_HANDLE *)Handle; UsbDebugPortHandle = (USB_DEBUG_PORT_HANDLE *)Handle;
} }
if (NeedReinitializeHardware(UsbDebugPortHandle)) { if (NeedReinitializeHardware (UsbDebugPortHandle)) {
Status = InitializeUsbDebugHardware (UsbDebugPortHandle); Status = InitializeUsbDebugHardware (UsbDebugPortHandle);
if (RETURN_ERROR(Status)) { if (RETURN_ERROR (Status)) {
return 0; return 0;
} }
} }
@ -815,8 +829,10 @@ DebugPortReadBuffer (
if ((Index + 1) >= USB_DEBUG_PORT_MAX_PACKET_SIZE) { if ((Index + 1) >= USB_DEBUG_PORT_MAX_PACKET_SIZE) {
return 0; return 0;
} }
UsbDebugPortHandle->Data[Index] = UsbDebugPortHandle->Data[Index + 1]; UsbDebugPortHandle->Data[Index] = UsbDebugPortHandle->Data[Index + 1];
} }
UsbDebugPortHandle->DataCount = (UINT8)(UsbDebugPortHandle->DataCount - 1); UsbDebugPortHandle->DataCount = (UINT8)(UsbDebugPortHandle->DataCount - 1);
return 1; return 1;
} }
@ -854,7 +870,7 @@ DebugPortWriteBuffer (
UINTN Total; UINTN Total;
UINT8 ReceivedPid; UINT8 ReceivedPid;
if (NumberOfBytes == 0 || Buffer == NULL) { if ((NumberOfBytes == 0) || (Buffer == NULL)) {
return 0; return 0;
} }
@ -871,9 +887,9 @@ DebugPortWriteBuffer (
UsbDebugPortHandle = (USB_DEBUG_PORT_HANDLE *)Handle; UsbDebugPortHandle = (USB_DEBUG_PORT_HANDLE *)Handle;
} }
if (NeedReinitializeHardware(UsbDebugPortHandle)) { if (NeedReinitializeHardware (UsbDebugPortHandle)) {
Status = InitializeUsbDebugHardware (UsbDebugPortHandle); Status = InitializeUsbDebugHardware (UsbDebugPortHandle);
if (RETURN_ERROR(Status)) { if (RETURN_ERROR (Status)) {
return 0; return 0;
} }
} }
@ -887,13 +903,13 @@ DebugPortWriteBuffer (
Sent = (UINT8)(NumberOfBytes - Total); Sent = (UINT8)(NumberOfBytes - Total);
} }
Status = UsbDebugPortOut(UsbDebugPortRegister, Buffer + Total, Sent, OUTPUT_PID, 0x7F, UsbDebugPortHandle->OutEndpoint, UsbDebugPortHandle->BulkOutToggle); Status = UsbDebugPortOut (UsbDebugPortRegister, Buffer + Total, Sent, OUTPUT_PID, 0x7F, UsbDebugPortHandle->OutEndpoint, UsbDebugPortHandle->BulkOutToggle);
if (RETURN_ERROR(Status)) { if (RETURN_ERROR (Status)) {
return Total; return Total;
} }
ReceivedPid = (MmioRead8((UINTN)&UsbDebugPortRegister->ReceivedPid)); ReceivedPid = (MmioRead8 ((UINTN)&UsbDebugPortRegister->ReceivedPid));
// //
// If received a NAK_PID on write transaction, it means the usb debug device is busy and can not handle this transaction. // If received a NAK_PID on write transaction, it means the usb debug device is busy and can not handle this transaction.
// should send the packet again. // should send the packet again.
@ -903,8 +919,10 @@ DebugPortWriteBuffer (
} else { } else {
UsbDebugPortHandle->BulkOutToggle ^= 1; UsbDebugPortHandle->BulkOutToggle ^= 1;
} }
Total += Sent; Total += Sent;
} }
return Total; return Total;
} }
@ -943,9 +961,9 @@ DebugPortPollBuffer (
UsbDebugPortHandle = (USB_DEBUG_PORT_HANDLE *)Handle; UsbDebugPortHandle = (USB_DEBUG_PORT_HANDLE *)Handle;
} }
if (NeedReinitializeHardware(UsbDebugPortHandle)) { if (NeedReinitializeHardware (UsbDebugPortHandle)) {
Status = InitializeUsbDebugHardware(UsbDebugPortHandle); Status = InitializeUsbDebugHardware (UsbDebugPortHandle);
if (RETURN_ERROR(Status)) { if (RETURN_ERROR (Status)) {
return FALSE; return FALSE;
} }
} }
@ -966,33 +984,35 @@ DebugPortPollBuffer (
} else { } else {
UsbDebugPortRegister->SendPid = DATA1_PID; UsbDebugPortRegister->SendPid = DATA1_PID;
} }
UsbDebugPortRegister->UsbAddress = 0x7F; UsbDebugPortRegister->UsbAddress = 0x7F;
UsbDebugPortRegister->UsbEndPoint = UsbDebugPortHandle->InEndpoint & 0x0F; UsbDebugPortRegister->UsbEndPoint = UsbDebugPortHandle->InEndpoint & 0x0F;
// //
// Clearing W/R bit to indicate it's a READ operation // Clearing W/R bit to indicate it's a READ operation
// //
MmioAnd32((UINTN)&UsbDebugPortRegister->ControlStatus, (UINT32)~BIT4); MmioAnd32 ((UINTN)&UsbDebugPortRegister->ControlStatus, (UINT32) ~BIT4);
// //
// Setting GO bit as well as clearing DONE bit // Setting GO bit as well as clearing DONE bit
// //
MmioOr32((UINTN)&UsbDebugPortRegister->ControlStatus, (UINT32)BIT5); MmioOr32 ((UINTN)&UsbDebugPortRegister->ControlStatus, (UINT32)BIT5);
// //
// Wait for completing the request // Wait for completing the request
// //
while ((MmioRead32((UINTN)&UsbDebugPortRegister->ControlStatus) & (UINT32)BIT16) == 0) { while ((MmioRead32 ((UINTN)&UsbDebugPortRegister->ControlStatus) & (UINT32)BIT16) == 0) {
if ((MmioRead32((UINTN)&UsbDebugPortRegister->ControlStatus) & (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_IN_USE | USB_DEBUG_PORT_ENABLE)) if ((MmioRead32 ((UINTN)&UsbDebugPortRegister->ControlStatus) & (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_IN_USE | USB_DEBUG_PORT_ENABLE))
!= (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_IN_USE | USB_DEBUG_PORT_ENABLE)) { != (USB_DEBUG_PORT_OWNER | USB_DEBUG_PORT_IN_USE | USB_DEBUG_PORT_ENABLE))
{
return FALSE; return FALSE;
} }
} }
if ((MmioRead32((UINTN)&UsbDebugPortRegister->ControlStatus)) & BIT6) { if ((MmioRead32 ((UINTN)&UsbDebugPortRegister->ControlStatus)) & BIT6) {
return FALSE; return FALSE;
} }
Length = (UINT8)(MmioRead32((UINTN)&UsbDebugPortRegister->ControlStatus) & 0xF); Length = (UINT8)(MmioRead32 ((UINTN)&UsbDebugPortRegister->ControlStatus) & 0xF);
if (Length > 8) { if (Length > 8) {
return FALSE; return FALSE;
@ -1007,6 +1027,7 @@ DebugPortPollBuffer (
for (Index = 0; Index < Length; Index++) { for (Index = 0; Index < Length; Index++) {
UsbDebugPortHandle->Data[Index] = UsbDebugPortRegister->DataBuffer[Index]; UsbDebugPortHandle->Data[Index] = UsbDebugPortRegister->DataBuffer[Index];
} }
UsbDebugPortHandle->DataCount = Length; UsbDebugPortHandle->DataCount = Length;
return TRUE; return TRUE;
@ -1051,43 +1072,44 @@ DebugPortInitialize (
// //
ASSERT (PcdGet16 (PcdDebugPortHandleBufferSize) == sizeof (USB_DEBUG_PORT_HANDLE)); ASSERT (PcdGet16 (PcdDebugPortHandleBufferSize) == sizeof (USB_DEBUG_PORT_HANDLE));
if (Function == NULL && Context != NULL) { if ((Function == NULL) && (Context != NULL)) {
return (DEBUG_PORT_HANDLE *) Context; return (DEBUG_PORT_HANDLE *)Context;
} }
ZeroMem(&Handle, sizeof (USB_DEBUG_PORT_HANDLE));
Status = CalculateUsbDebugPortBar(&Handle.DebugPortOffset, &Handle.DebugPortBarNumber); ZeroMem (&Handle, sizeof (USB_DEBUG_PORT_HANDLE));
Status = CalculateUsbDebugPortBar (&Handle.DebugPortOffset, &Handle.DebugPortBarNumber);
if (RETURN_ERROR (Status)) { if (RETURN_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "UsbDbg: the pci device pointed by PcdUsbEhciPciAddress is not EHCI host controller or does not support debug port capability!\n")); DEBUG ((DEBUG_ERROR, "UsbDbg: the pci device pointed by PcdUsbEhciPciAddress is not EHCI host controller or does not support debug port capability!\n"));
goto Exit; goto Exit;
} }
Handle.EhciMemoryBase = 0xFFFFFC00 & PciRead32(PcdGet32(PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET); Handle.EhciMemoryBase = 0xFFFFFC00 & PciRead32 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET);
if (Handle.EhciMemoryBase == 0) { if (Handle.EhciMemoryBase == 0) {
// //
// Usb Debug Port MMIO Space Is Not Enabled. Assumption here that DebugPortBase is zero // Usb Debug Port MMIO Space Is Not Enabled. Assumption here that DebugPortBase is zero
// //
PciWrite32(PcdGet32(PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET, PcdGet32(PcdUsbEhciMemorySpaceBase)); PciWrite32 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET, PcdGet32 (PcdUsbEhciMemorySpaceBase));
Handle.EhciMemoryBase = 0xFFFFFC00 & PciRead32(PcdGet32(PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET); Handle.EhciMemoryBase = 0xFFFFFC00 & PciRead32 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET);
} }
Handle.UsbDebugPortMemoryBase = 0xFFFFFC00 & PciRead32(PcdGet32(PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET + Handle.DebugPortBarNumber * 4); Handle.UsbDebugPortMemoryBase = 0xFFFFFC00 & PciRead32 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET + Handle.DebugPortBarNumber * 4);
if (Handle.UsbDebugPortMemoryBase == 0) { if (Handle.UsbDebugPortMemoryBase == 0) {
// //
// Usb Debug Port MMIO Space Is Not Enabled. Assumption here that DebugPortBase is zero // Usb Debug Port MMIO Space Is Not Enabled. Assumption here that DebugPortBase is zero
// //
PciWrite32(PcdGet32(PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET + Handle.DebugPortBarNumber * 4, PcdGet32(PcdUsbDebugPortMemorySpaceBase)); PciWrite32 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET + Handle.DebugPortBarNumber * 4, PcdGet32 (PcdUsbDebugPortMemorySpaceBase));
Handle.UsbDebugPortMemoryBase = 0xFFFFFC00 & PciRead32(PcdGet32(PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET + Handle.DebugPortBarNumber * 4); Handle.UsbDebugPortMemoryBase = 0xFFFFFC00 & PciRead32 (PcdGet32 (PcdUsbEhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET + Handle.DebugPortBarNumber * 4);
} }
Handle.Initialized = USBDBG_RESET; Handle.Initialized = USBDBG_RESET;
if (NeedReinitializeHardware(&Handle)) { if (NeedReinitializeHardware (&Handle)) {
DEBUG ((DEBUG_ERROR, "UsbDbg: Start EHCI debug port initialization!\n")); DEBUG ((DEBUG_ERROR, "UsbDbg: Start EHCI debug port initialization!\n"));
Status = InitializeUsbDebugHardware (&Handle); Status = InitializeUsbDebugHardware (&Handle);
if (RETURN_ERROR(Status)) { if (RETURN_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "UsbDbg: Failed, please check if USB debug cable is plugged into EHCI debug port correctly!\n")); DEBUG ((DEBUG_ERROR, "UsbDbg: Failed, please check if USB debug cable is plugged into EHCI debug port correctly!\n"));
goto Exit; goto Exit;
} }
@ -1098,7 +1120,7 @@ Exit:
if (Function != NULL) { if (Function != NULL) {
Function (Context, &Handle); Function (Context, &Handle);
} else { } else {
CopyMem(&mDebugCommunicationLibUsbDebugPortHandle, &Handle, sizeof (USB_DEBUG_PORT_HANDLE)); CopyMem (&mDebugCommunicationLibUsbDebugPortHandle, &Handle, sizeof (USB_DEBUG_PORT_HANDLE));
} }
return (DEBUG_PORT_HANDLE)(UINTN)&mDebugCommunicationLibUsbDebugPortHandle; return (DEBUG_PORT_HANDLE)(UINTN)&mDebugCommunicationLibUsbDebugPortHandle;

View File

@ -10,25 +10,25 @@
UINT16 mString0Desc[] = { UINT16 mString0Desc[] = {
// String Descriptor Type + Length // String Descriptor Type + Length
( USB_DESC_TYPE_STRING << 8 ) + STRING0_DESC_LEN, (USB_DESC_TYPE_STRING << 8) + STRING0_DESC_LEN,
0x0409 0x0409
}; };
UINT16 mManufacturerStrDesc[] = { UINT16 mManufacturerStrDesc[] = {
// String Descriptor Type + Length // String Descriptor Type + Length
( USB_DESC_TYPE_STRING << 8 ) + MANU_DESC_LEN, (USB_DESC_TYPE_STRING << 8) + MANU_DESC_LEN,
'I', 'n', 't', 'e', 'l' 'I', 'n','t', 'e', 'l'
}; };
UINT16 mProductStrDesc[] = { UINT16 mProductStrDesc[] = {
// String Descriptor Type + Length // String Descriptor Type + Length
( USB_DESC_TYPE_STRING << 8 ) + PRODUCT_DESC_LEN, (USB_DESC_TYPE_STRING << 8) + PRODUCT_DESC_LEN,
'U', 'S', 'B', ' ', '3', '.', '0', ' ', 'D', 'e', 'b', 'u', 'g', ' ', 'C', 'a', 'b', 'l', 'e' 'U', 'S','B', ' ', '3', '.', '0', ' ', 'D', 'e', 'b', 'u', 'g', ' ', 'C', 'a', 'b', 'l', 'e'
}; };
UINT16 mSerialNumberStrDesc[] = { UINT16 mSerialNumberStrDesc[] = {
// String Descriptor Type + Length // String Descriptor Type + Length
( USB_DESC_TYPE_STRING << 8 ) + SERIAL_DESC_LEN, (USB_DESC_TYPE_STRING << 8) + SERIAL_DESC_LEN,
'1' '1'
}; };
@ -39,7 +39,7 @@ UINT16 mSerialNumberStrDesc[] = {
@param[in] BitMask 32-bit mask @param[in] BitMask 32-bit mask
**/ **/
VOID VOID
XhcSetR32Bit( XhcSetR32Bit (
IN OUT UINTN Register, IN OUT UINTN Register,
IN UINT32 BitMask IN UINT32 BitMask
) )
@ -58,7 +58,7 @@ XhcSetR32Bit(
@param[in] BitMask 32-bit mask @param[in] BitMask 32-bit mask
**/ **/
VOID VOID
XhcClearR32Bit( XhcClearR32Bit (
IN OUT UINTN Register, IN OUT UINTN Register,
IN UINT32 BitMask IN UINT32 BitMask
) )
@ -177,21 +177,21 @@ ProgramXhciBaseAddress (
UINT32 High; UINT32 High;
EFI_PHYSICAL_ADDRESS XhciMmioBase; EFI_PHYSICAL_ADDRESS XhciMmioBase;
Low = PciRead32 (PcdGet32(PcdUsbXhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET); Low = PciRead32 (PcdGet32 (PcdUsbXhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET);
High = PciRead32 (PcdGet32(PcdUsbXhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET + 4); High = PciRead32 (PcdGet32 (PcdUsbXhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET + 4);
XhciMmioBase = (EFI_PHYSICAL_ADDRESS) (LShiftU64 ((UINT64) High, 32) | Low); XhciMmioBase = (EFI_PHYSICAL_ADDRESS)(LShiftU64 ((UINT64)High, 32) | Low);
XhciMmioBase &= XHCI_BASE_ADDRESS_64_BIT_MASK; XhciMmioBase &= XHCI_BASE_ADDRESS_64_BIT_MASK;
if ((XhciMmioBase == 0) || (XhciMmioBase == XHCI_BASE_ADDRESS_64_BIT_MASK)) { if ((XhciMmioBase == 0) || (XhciMmioBase == XHCI_BASE_ADDRESS_64_BIT_MASK)) {
XhciMmioBase = PcdGet64(PcdUsbXhciMemorySpaceBase); XhciMmioBase = PcdGet64 (PcdUsbXhciMemorySpaceBase);
PciWrite32(PcdGet32(PcdUsbXhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET, XhciMmioBase & 0xFFFFFFFF); PciWrite32 (PcdGet32 (PcdUsbXhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET, XhciMmioBase & 0xFFFFFFFF);
PciWrite32(PcdGet32(PcdUsbXhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET + 4, (RShiftU64 (XhciMmioBase, 32) & 0xFFFFFFFF)); PciWrite32 (PcdGet32 (PcdUsbXhciPciAddress) + PCI_BASE_ADDRESSREG_OFFSET + 4, (RShiftU64 (XhciMmioBase, 32) & 0xFFFFFFFF));
} }
PciCmd = PciRead16 (PcdGet32(PcdUsbXhciPciAddress) + PCI_COMMAND_OFFSET); PciCmd = PciRead16 (PcdGet32 (PcdUsbXhciPciAddress) + PCI_COMMAND_OFFSET);
if (((PciCmd & EFI_PCI_COMMAND_MEMORY_SPACE) == 0) || ((PciCmd & EFI_PCI_COMMAND_BUS_MASTER) == 0)) { if (((PciCmd & EFI_PCI_COMMAND_MEMORY_SPACE) == 0) || ((PciCmd & EFI_PCI_COMMAND_BUS_MASTER) == 0)) {
PciCmd |= EFI_PCI_COMMAND_MEMORY_SPACE | EFI_PCI_COMMAND_BUS_MASTER; PciCmd |= EFI_PCI_COMMAND_MEMORY_SPACE | EFI_PCI_COMMAND_BUS_MASTER;
PciWrite16(PcdGet32(PcdUsbXhciPciAddress) + PCI_COMMAND_OFFSET, PciCmd); PciWrite16 (PcdGet32 (PcdUsbXhciPciAddress) + PCI_COMMAND_OFFSET, PciCmd);
} }
return XhciMmioBase; return XhciMmioBase;
@ -255,22 +255,22 @@ CalculateUsbDebugPortMmioBase (
} }
} }
VendorId = PciRead16 (PcdGet32(PcdUsbXhciPciAddress) + PCI_VENDOR_ID_OFFSET); VendorId = PciRead16 (PcdGet32 (PcdUsbXhciPciAddress) + PCI_VENDOR_ID_OFFSET);
DeviceId = PciRead16 (PcdGet32(PcdUsbXhciPciAddress) + PCI_DEVICE_ID_OFFSET); DeviceId = PciRead16 (PcdGet32 (PcdUsbXhciPciAddress) + PCI_DEVICE_ID_OFFSET);
if ((VendorId == 0xFFFF) || (DeviceId == 0xFFFF)) { if ((VendorId == 0xFFFF) || (DeviceId == 0xFFFF)) {
goto Done; goto Done;
} }
ProgInterface = PciRead8 (PcdGet32(PcdUsbXhciPciAddress) + PCI_CLASSCODE_OFFSET); ProgInterface = PciRead8 (PcdGet32 (PcdUsbXhciPciAddress) + PCI_CLASSCODE_OFFSET);
SubClassCode = PciRead8 (PcdGet32(PcdUsbXhciPciAddress) + PCI_CLASSCODE_OFFSET + 1); SubClassCode = PciRead8 (PcdGet32 (PcdUsbXhciPciAddress) + PCI_CLASSCODE_OFFSET + 1);
BaseCode = PciRead8 (PcdGet32(PcdUsbXhciPciAddress) + PCI_CLASSCODE_OFFSET + 2); BaseCode = PciRead8 (PcdGet32 (PcdUsbXhciPciAddress) + PCI_CLASSCODE_OFFSET + 2);
if ((ProgInterface != PCI_IF_XHCI) || (SubClassCode != PCI_CLASS_SERIAL_USB) || (BaseCode != PCI_CLASS_SERIAL)) { if ((ProgInterface != PCI_IF_XHCI) || (SubClassCode != PCI_CLASS_SERIAL_USB) || (BaseCode != PCI_CLASS_SERIAL)) {
goto Done; goto Done;
} }
CapLength = MmioRead8 ((UINTN) Handle->XhciMmioBase); CapLength = MmioRead8 ((UINTN)Handle->XhciMmioBase);
// //
// Get capability pointer from HCCPARAMS at offset 0x10 // Get capability pointer from HCCPARAMS at offset 0x10
@ -287,12 +287,14 @@ CalculateUsbDebugPortMmioBase (
Flag = TRUE; Flag = TRUE;
break; break;
} }
if ((((Capability & XHC_NEXT_CAPABILITY_MASK) >> 8) & XHC_CAPABILITY_ID_MASK) == 0) { if ((((Capability & XHC_NEXT_CAPABILITY_MASK) >> 8) & XHC_CAPABILITY_ID_MASK) == 0) {
// //
// Reach the end of capability list, quit // Reach the end of capability list, quit
// //
break; break;
} }
CapabilityPointer += ((Capability & XHC_NEXT_CAPABILITY_MASK) >> 8) * 4; CapabilityPointer += ((Capability & XHC_NEXT_CAPABILITY_MASK) >> 8) * 4;
Capability = MmioRead32 ((UINTN)CapabilityPointer); Capability = MmioRead32 ((UINTN)CapabilityPointer);
} }
@ -331,7 +333,7 @@ Done:
**/ **/
BOOLEAN BOOLEAN
EFIAPI EFIAPI
NeedReinitializeHardware( NeedReinitializeHardware (
IN USB3_DEBUG_PORT_HANDLE *Handle IN USB3_DEBUG_PORT_HANDLE *Handle
) )
{ {
@ -377,13 +379,13 @@ CreateEventRing (
// //
Buf = AllocateAlignBuffer (sizeof (TRB_TEMPLATE) * EVENT_RING_TRB_NUMBER); Buf = AllocateAlignBuffer (sizeof (TRB_TEMPLATE) * EVENT_RING_TRB_NUMBER);
ASSERT (Buf != NULL); ASSERT (Buf != NULL);
ASSERT (((UINTN) Buf & 0x3F) == 0); ASSERT (((UINTN)Buf & 0x3F) == 0);
ZeroMem (Buf, sizeof (TRB_TEMPLATE) * EVENT_RING_TRB_NUMBER); ZeroMem (Buf, sizeof (TRB_TEMPLATE) * EVENT_RING_TRB_NUMBER);
EventRing->EventRingSeg0 = (EFI_PHYSICAL_ADDRESS)(UINTN) Buf; EventRing->EventRingSeg0 = (EFI_PHYSICAL_ADDRESS)(UINTN)Buf;
EventRing->TrbNumber = EVENT_RING_TRB_NUMBER; EventRing->TrbNumber = EVENT_RING_TRB_NUMBER;
EventRing->EventRingDequeue = (EFI_PHYSICAL_ADDRESS)(UINTN) EventRing->EventRingSeg0; EventRing->EventRingDequeue = (EFI_PHYSICAL_ADDRESS)(UINTN)EventRing->EventRingSeg0;
EventRing->EventRingEnqueue = (EFI_PHYSICAL_ADDRESS)(UINTN) EventRing->EventRingSeg0; EventRing->EventRingEnqueue = (EFI_PHYSICAL_ADDRESS)(UINTN)EventRing->EventRingSeg0;
// //
// Software maintains an Event Ring Consumer Cycle State (CCS) bit, initializing it to '1' // Software maintains an Event Ring Consumer Cycle State (CCS) bit, initializing it to '1'
@ -396,11 +398,11 @@ CreateEventRing (
// //
Buf = AllocateAlignBuffer (sizeof (EVENT_RING_SEG_TABLE_ENTRY) * ERST_NUMBER); Buf = AllocateAlignBuffer (sizeof (EVENT_RING_SEG_TABLE_ENTRY) * ERST_NUMBER);
ASSERT (Buf != NULL); ASSERT (Buf != NULL);
ASSERT (((UINTN) Buf & 0x3F) == 0); ASSERT (((UINTN)Buf & 0x3F) == 0);
ZeroMem (Buf, sizeof (EVENT_RING_SEG_TABLE_ENTRY) * ERST_NUMBER); ZeroMem (Buf, sizeof (EVENT_RING_SEG_TABLE_ENTRY) * ERST_NUMBER);
ERSTBase = (EVENT_RING_SEG_TABLE_ENTRY *) Buf; ERSTBase = (EVENT_RING_SEG_TABLE_ENTRY *)Buf;
EventRing->ERSTBase = (EFI_PHYSICAL_ADDRESS)(UINTN) ERSTBase; EventRing->ERSTBase = (EFI_PHYSICAL_ADDRESS)(UINTN)ERSTBase;
// //
// Fill Event Segment address // Fill Event Segment address
@ -415,13 +417,13 @@ CreateEventRing (
XhcWriteDebugReg ( XhcWriteDebugReg (
Handle, Handle,
XHC_DC_DCERDP, XHC_DC_DCERDP,
XHC_LOW_32BIT((UINT64)(UINTN)EventRing->EventRingDequeue) XHC_LOW_32BIT ((UINT64)(UINTN)EventRing->EventRingDequeue)
); );
XhcWriteDebugReg ( XhcWriteDebugReg (
Handle, Handle,
XHC_DC_DCERDP + 4, XHC_DC_DCERDP + 4,
XHC_HIGH_32BIT((UINT64)(UINTN)EventRing->EventRingDequeue) XHC_HIGH_32BIT ((UINT64)(UINTN)EventRing->EventRingDequeue)
); );
// //
@ -430,13 +432,13 @@ CreateEventRing (
XhcWriteDebugReg ( XhcWriteDebugReg (
Handle, Handle,
XHC_DC_DCERSTBA, XHC_DC_DCERSTBA,
XHC_LOW_32BIT((UINT64)(UINTN)ERSTBase) XHC_LOW_32BIT ((UINT64)(UINTN)ERSTBase)
); );
XhcWriteDebugReg ( XhcWriteDebugReg (
Handle, Handle,
XHC_DC_DCERSTBA + 4, XHC_DC_DCERSTBA + 4,
XHC_HIGH_32BIT((UINT64)(UINTN)ERSTBase) XHC_HIGH_32BIT ((UINT64)(UINTN)ERSTBase)
); );
// //
@ -470,10 +472,10 @@ CreateTransferRing (
Buf = AllocateAlignBuffer (sizeof (TRB_TEMPLATE) * TrbNum); Buf = AllocateAlignBuffer (sizeof (TRB_TEMPLATE) * TrbNum);
ASSERT (Buf != NULL); ASSERT (Buf != NULL);
ASSERT (((UINTN) Buf & 0xF) == 0); ASSERT (((UINTN)Buf & 0xF) == 0);
ZeroMem (Buf, sizeof (TRB_TEMPLATE) * TrbNum); ZeroMem (Buf, sizeof (TRB_TEMPLATE) * TrbNum);
TransferRing->RingSeg0 = (EFI_PHYSICAL_ADDRESS)(UINTN) Buf; TransferRing->RingSeg0 = (EFI_PHYSICAL_ADDRESS)(UINTN)Buf;
TransferRing->TrbNumber = TrbNum; TransferRing->TrbNumber = TrbNum;
TransferRing->RingEnqueue = TransferRing->RingSeg0; TransferRing->RingEnqueue = TransferRing->RingSeg0;
TransferRing->RingDequeue = TransferRing->RingSeg0; TransferRing->RingDequeue = TransferRing->RingSeg0;
@ -483,7 +485,7 @@ CreateTransferRing (
// To form a ring (or circular queue) a Link TRB may be inserted at the end of a ring to // To form a ring (or circular queue) a Link TRB may be inserted at the end of a ring to
// point to the first TRB in the ring. // point to the first TRB in the ring.
// //
EndTrb = (LINK_TRB *) ((UINTN)Buf + sizeof (TRB_TEMPLATE) * (TrbNum - 1)); EndTrb = (LINK_TRB *)((UINTN)Buf + sizeof (TRB_TEMPLATE) * (TrbNum - 1));
EndTrb->Type = TRB_TYPE_LINK; EndTrb->Type = TRB_TYPE_LINK;
EndTrb->PtrLo = XHC_LOW_32BIT (Buf); EndTrb->PtrLo = XHC_LOW_32BIT (Buf);
EndTrb->PtrHi = XHC_HIGH_32BIT (Buf); EndTrb->PtrHi = XHC_HIGH_32BIT (Buf);
@ -523,11 +525,11 @@ CreateDebugCapabilityContext (
// //
Buf = AllocateAlignBuffer (sizeof (XHC_DC_CONTEXT)); Buf = AllocateAlignBuffer (sizeof (XHC_DC_CONTEXT));
ASSERT (Buf != NULL); ASSERT (Buf != NULL);
ASSERT (((UINTN) Buf & 0xF) == 0); ASSERT (((UINTN)Buf & 0xF) == 0);
ZeroMem (Buf, sizeof (XHC_DC_CONTEXT)); ZeroMem (Buf, sizeof (XHC_DC_CONTEXT));
DebugCapabilityContext = (XHC_DC_CONTEXT *)(UINTN) Buf; DebugCapabilityContext = (XHC_DC_CONTEXT *)(UINTN)Buf;
Handle->DebugCapabilityContext = (EFI_PHYSICAL_ADDRESS)(UINTN) DebugCapabilityContext; Handle->DebugCapabilityContext = (EFI_PHYSICAL_ADDRESS)(UINTN)DebugCapabilityContext;
// //
// Initialize DbcInfoContext. // Initialize DbcInfoContext.
@ -556,7 +558,7 @@ CreateDebugCapabilityContext (
// //
// Update string descriptor address // Update string descriptor address
// //
String0Desc = (UINT8 *) AllocateAlignBuffer (STRING0_DESC_LEN + MANU_DESC_LEN + PRODUCT_DESC_LEN + SERIAL_DESC_LEN); String0Desc = (UINT8 *)AllocateAlignBuffer (STRING0_DESC_LEN + MANU_DESC_LEN + PRODUCT_DESC_LEN + SERIAL_DESC_LEN);
ASSERT (String0Desc != NULL); ASSERT (String0Desc != NULL);
ZeroMem (String0Desc, STRING0_DESC_LEN + MANU_DESC_LEN + PRODUCT_DESC_LEN + SERIAL_DESC_LEN); ZeroMem (String0Desc, STRING0_DESC_LEN + MANU_DESC_LEN + PRODUCT_DESC_LEN + SERIAL_DESC_LEN);
CopyMem (String0Desc, mString0Desc, STRING0_DESC_LEN); CopyMem (String0Desc, mString0Desc, STRING0_DESC_LEN);
@ -596,12 +598,12 @@ CreateDebugCapabilityContext (
XhcWriteDebugReg ( XhcWriteDebugReg (
Handle, Handle,
XHC_DC_DCCP, XHC_DC_DCCP,
XHC_LOW_32BIT((UINT64)(UINTN)DebugCapabilityContext) XHC_LOW_32BIT ((UINT64)(UINTN)DebugCapabilityContext)
); );
XhcWriteDebugReg ( XhcWriteDebugReg (
Handle, Handle,
XHC_DC_DCCP + 4, XHC_DC_DCCP + 4,
XHC_HIGH_32BIT((UINT64)(UINTN)DebugCapabilityContext) XHC_HIGH_32BIT ((UINT64)(UINTN)DebugCapabilityContext)
); );
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -642,6 +644,7 @@ XhcDetectDebugCapabilityReady (
Handle->Ready = TRUE; Handle->Ready = TRUE;
break; break;
} }
MicroSecondDelay (XHC_POLL_DELAY); MicroSecondDelay (XHC_POLL_DELAY);
TimeOut--; TimeOut--;
} while (TimeOut != 0); } while (TimeOut != 0);
@ -670,16 +673,17 @@ InitializeUsbDebugHardware (
UINT32 Dcddi1; UINT32 Dcddi1;
XhciOpRegister = Handle->XhciOpRegister; XhciOpRegister = Handle->XhciOpRegister;
TotalUsb3Port = MmioRead32 (((UINTN) Handle->XhciMmioBase + XHC_HCSPARAMS1_OFFSET)) >> 24; TotalUsb3Port = MmioRead32 (((UINTN)Handle->XhciMmioBase + XHC_HCSPARAMS1_OFFSET)) >> 24;
if (Handle->Initialized == USB3DBG_NOT_ENABLED) { if (Handle->Initialized == USB3DBG_NOT_ENABLED) {
Dcddi1 = XhcReadDebugReg (Handle,XHC_DC_DCDDI1); Dcddi1 = XhcReadDebugReg (Handle, XHC_DC_DCDDI1);
if (Dcddi1 != (UINT32)((XHCI_DEBUG_DEVICE_VENDOR_ID << 16) | XHCI_DEBUG_DEVICE_PROTOCOL)) { if (Dcddi1 != (UINT32)((XHCI_DEBUG_DEVICE_VENDOR_ID << 16) | XHCI_DEBUG_DEVICE_PROTOCOL)) {
// //
// The debug capability has been reset by other code, return device error. // The debug capability has been reset by other code, return device error.
// //
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
// //
// If XHCI supports debug capability, hardware resource has been allocated, // If XHCI supports debug capability, hardware resource has been allocated,
// but it has not been enabled, try to enable again. // but it has not been enabled, try to enable again.
@ -718,8 +722,8 @@ InitializeUsbDebugHardware (
// //
// Construct the buffer for read, poll and write. // Construct the buffer for read, poll and write.
// //
Handle->UrbIn.Data = (EFI_PHYSICAL_ADDRESS)(UINTN) Buffer; Handle->UrbIn.Data = (EFI_PHYSICAL_ADDRESS)(UINTN)Buffer;
Handle->Data = (EFI_PHYSICAL_ADDRESS)(UINTN) Buffer + XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE; Handle->Data = (EFI_PHYSICAL_ADDRESS)(UINTN)Buffer + XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE;
Handle->UrbOut.Data = Handle->UrbIn.Data + XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE * 2; Handle->UrbOut.Data = Handle->UrbIn.Data + XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE * 2;
// //
@ -827,7 +831,7 @@ SetUsb3DebugPortInstance (
AddrPtr = GetUsb3DebugPortInstanceAddrPtr (); AddrPtr = GetUsb3DebugPortInstanceAddrPtr ();
ASSERT (AddrPtr != NULL); ASSERT (AddrPtr != NULL);
*AddrPtr = (EFI_PHYSICAL_ADDRESS) (UINTN) Instance; *AddrPtr = (EFI_PHYSICAL_ADDRESS)(UINTN)Instance;
} }
/** /**
@ -845,7 +849,7 @@ GetUsb3DebugPortInstance (
AddrPtr = GetUsb3DebugPortInstanceAddrPtr (); AddrPtr = GetUsb3DebugPortInstanceAddrPtr ();
ASSERT (AddrPtr != NULL); ASSERT (AddrPtr != NULL);
Instance = (USB3_DEBUG_PORT_HANDLE *) (UINTN) *AddrPtr; Instance = (USB3_DEBUG_PORT_HANDLE *)(UINTN)*AddrPtr;
return Instance; return Instance;
} }
@ -880,7 +884,7 @@ DebugPortReadBuffer (
UINT8 Index; UINT8 Index;
UINT8 *Data; UINT8 *Data;
if (NumberOfBytes != 1 || Buffer == NULL || Timeout != 0) { if ((NumberOfBytes != 1) || (Buffer == NULL) || (Timeout != 0)) {
return 0; return 0;
} }
@ -889,11 +893,12 @@ DebugPortReadBuffer (
// If Handle is not NULL, use it and set the instance. // If Handle is not NULL, use it and set the instance.
// //
if (Handle != NULL) { if (Handle != NULL) {
UsbDebugPortHandle = (USB3_DEBUG_PORT_HANDLE *) Handle; UsbDebugPortHandle = (USB3_DEBUG_PORT_HANDLE *)Handle;
SetUsb3DebugPortInstance (UsbDebugPortHandle); SetUsb3DebugPortInstance (UsbDebugPortHandle);
} else { } else {
UsbDebugPortHandle = GetUsb3DebugPortInstance (); UsbDebugPortHandle = GetUsb3DebugPortInstance ();
} }
if (UsbDebugPortHandle == NULL) { if (UsbDebugPortHandle == NULL) {
return 0; return 0;
} }
@ -922,8 +927,10 @@ DebugPortReadBuffer (
if ((Index + 1) >= XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE) { if ((Index + 1) >= XHCI_DEBUG_DEVICE_MAX_PACKET_SIZE) {
return 0; return 0;
} }
Data[Index] = Data[Index + 1]; Data[Index] = Data[Index + 1];
} }
UsbDebugPortHandle->DataCount = (UINT8)(UsbDebugPortHandle->DataCount - 1); UsbDebugPortHandle->DataCount = (UINT8)(UsbDebugPortHandle->DataCount - 1);
return 1; return 1;
} }
@ -958,7 +965,7 @@ DebugPortWriteBuffer (
UINTN Sent; UINTN Sent;
UINTN Total; UINTN Total;
if (NumberOfBytes == 0 || Buffer == NULL) { if ((NumberOfBytes == 0) || (Buffer == NULL)) {
return 0; return 0;
} }
@ -970,11 +977,12 @@ DebugPortWriteBuffer (
// If Handle is not NULL, use it and set the instance. // If Handle is not NULL, use it and set the instance.
// //
if (Handle != NULL) { if (Handle != NULL) {
UsbDebugPortHandle = (USB3_DEBUG_PORT_HANDLE *) Handle; UsbDebugPortHandle = (USB3_DEBUG_PORT_HANDLE *)Handle;
SetUsb3DebugPortInstance (UsbDebugPortHandle); SetUsb3DebugPortInstance (UsbDebugPortHandle);
} else { } else {
UsbDebugPortHandle = GetUsb3DebugPortInstance (); UsbDebugPortHandle = GetUsb3DebugPortInstance ();
} }
if (UsbDebugPortHandle == NULL) { if (UsbDebugPortHandle == NULL) {
return 0; return 0;
} }
@ -1001,6 +1009,7 @@ DebugPortWriteBuffer (
} else { } else {
Sent = (UINT8)(NumberOfBytes - Total); Sent = (UINT8)(NumberOfBytes - Total);
} }
XhcDataTransfer (UsbDebugPortHandle, EfiUsbDataOut, Buffer + Total, &Sent, DATA_TRANSFER_WRITE_TIMEOUT); XhcDataTransfer (UsbDebugPortHandle, EfiUsbDataOut, Buffer + Total, &Sent, DATA_TRANSFER_WRITE_TIMEOUT);
Total += Sent; Total += Sent;
} }
@ -1035,11 +1044,12 @@ DebugPortPollBuffer (
// If Handle is not NULL, use it and set the instance. // If Handle is not NULL, use it and set the instance.
// //
if (Handle != NULL) { if (Handle != NULL) {
UsbDebugPortHandle = (USB3_DEBUG_PORT_HANDLE *) Handle; UsbDebugPortHandle = (USB3_DEBUG_PORT_HANDLE *)Handle;
SetUsb3DebugPortInstance (UsbDebugPortHandle); SetUsb3DebugPortInstance (UsbDebugPortHandle);
} else { } else {
UsbDebugPortHandle = GetUsb3DebugPortInstance (); UsbDebugPortHandle = GetUsb3DebugPortInstance ();
} }
if (UsbDebugPortHandle == NULL) { if (UsbDebugPortHandle == NULL) {
return FALSE; return FALSE;
} }
@ -1079,7 +1089,7 @@ DebugPortPollBuffer (
// //
// Store data into internal buffer for use later // Store data into internal buffer for use later
// //
UsbDebugPortHandle->DataCount = (UINT8) Length; UsbDebugPortHandle->DataCount = (UINT8)Length;
return TRUE; return TRUE;
} }
@ -1121,10 +1131,11 @@ DebugPortInitialize (
// //
ASSERT (PcdGet16 (PcdDebugPortHandleBufferSize) == sizeof (USB3_DEBUG_PORT_HANDLE)); ASSERT (PcdGet16 (PcdDebugPortHandleBufferSize) == sizeof (USB3_DEBUG_PORT_HANDLE));
if (Function == NULL && Context != NULL) { if ((Function == NULL) && (Context != NULL)) {
SetUsb3DebugPortInstance ((USB3_DEBUG_PORT_HANDLE *) Context); SetUsb3DebugPortInstance ((USB3_DEBUG_PORT_HANDLE *)Context);
return (DEBUG_PORT_HANDLE) Context; return (DEBUG_PORT_HANDLE)Context;
} }
UsbDebugPortHandle = GetUsb3DebugPortInstance (); UsbDebugPortHandle = GetUsb3DebugPortInstance ();
if (UsbDebugPortHandle == NULL) { if (UsbDebugPortHandle == NULL) {
return NULL; return NULL;
@ -1133,8 +1144,8 @@ DebugPortInitialize (
DiscoverInitializeUsbDebugPort (UsbDebugPortHandle); DiscoverInitializeUsbDebugPort (UsbDebugPortHandle);
if (Function != NULL) { if (Function != NULL) {
Function (Context, (DEBUG_PORT_HANDLE) UsbDebugPortHandle); Function (Context, (DEBUG_PORT_HANDLE)UsbDebugPortHandle);
} }
return (DEBUG_PORT_HANDLE) UsbDebugPortHandle; return (DEBUG_PORT_HANDLE)UsbDebugPortHandle;
} }

View File

@ -17,7 +17,7 @@
GUID gUsb3DbgGuid = USB3_DBG_GUID; GUID gUsb3DbgGuid = USB3_DBG_GUID;
USB3_DEBUG_PORT_HANDLE mUsb3Instance = {USB3DBG_UNINITIALIZED}; USB3_DEBUG_PORT_HANDLE mUsb3Instance = { USB3DBG_UNINITIALIZED };
EFI_PHYSICAL_ADDRESS mUsb3InstanceAddr = 0; EFI_PHYSICAL_ADDRESS mUsb3InstanceAddr = 0;
EFI_PHYSICAL_ADDRESS *mUsb3InstanceAddrPtr = NULL; EFI_PHYSICAL_ADDRESS *mUsb3InstanceAddrPtr = NULL;
EFI_PCI_IO_PROTOCOL *mUsb3PciIo = NULL; EFI_PCI_IO_PROTOCOL *mUsb3PciIo = NULL;
@ -71,7 +71,7 @@ Usb3NamedEventListen (
// Register for an installation of protocol interface // Register for an installation of protocol interface
// //
Status = gBS->RegisterProtocolNotify ( Status = gBS->RegisterProtocolNotify (
(EFI_GUID *) Name, (EFI_GUID *)Name,
*Event, *Event,
&RegistrationLocal &RegistrationLocal
); );
@ -100,7 +100,7 @@ Usb3MapOneDmaBuffer (
EFI_PHYSICAL_ADDRESS DeviceAddress; EFI_PHYSICAL_ADDRESS DeviceAddress;
VOID *Mapping; VOID *Mapping;
HostAddress = (VOID *) (UINTN) Address; HostAddress = (VOID *)(UINTN)Address;
Status = PciIo->Map ( Status = PciIo->Map (
PciIo, PciIo,
EfiPciIoOperationBusMasterCommonBuffer, EfiPciIoOperationBusMasterCommonBuffer,
@ -110,7 +110,7 @@ Usb3MapOneDmaBuffer (
&Mapping &Mapping
); );
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
ASSERT (DeviceAddress == ((EFI_PHYSICAL_ADDRESS) (UINTN) HostAddress)); ASSERT (DeviceAddress == ((EFI_PHYSICAL_ADDRESS)(UINTN)HostAddress));
} }
/** /**
@ -164,7 +164,7 @@ Usb3MapDmaBuffers (
Usb3MapOneDmaBuffer ( Usb3MapOneDmaBuffer (
PciIo, PciIo,
((XHC_DC_CONTEXT *) (UINTN) Instance->DebugCapabilityContext)->DbcInfoContext.String0DescAddress, ((XHC_DC_CONTEXT *)(UINTN)Instance->DebugCapabilityContext)->DbcInfoContext.String0DescAddress,
STRING0_DESC_LEN + MANU_DESC_LEN + PRODUCT_DESC_LEN + SERIAL_DESC_LEN STRING0_DESC_LEN + MANU_DESC_LEN + PRODUCT_DESC_LEN + SERIAL_DESC_LEN
); );
} }
@ -228,7 +228,7 @@ Usb3GetIoMmu (
Status = gBS->LocateProtocol ( Status = gBS->LocateProtocol (
&gEdkiiIoMmuProtocolGuid, &gEdkiiIoMmuProtocolGuid,
NULL, NULL,
(VOID **) &IoMmu (VOID **)&IoMmu
); );
if (!EFI_ERROR (Status) && (IoMmu != NULL)) { if (!EFI_ERROR (Status) && (IoMmu != NULL)) {
return IoMmu; return IoMmu;
@ -274,18 +274,19 @@ Usb3PciIoNotify (
); );
if (!EFI_ERROR (Status) && if (!EFI_ERROR (Status) &&
(PciIoHandleBuffer != NULL) && (PciIoHandleBuffer != NULL) &&
(PciIoHandleCount != 0)) { (PciIoHandleCount != 0))
{
for (Index = 0; Index < PciIoHandleCount; Index++) { for (Index = 0; Index < PciIoHandleCount; Index++) {
Status = gBS->HandleProtocol ( Status = gBS->HandleProtocol (
PciIoHandleBuffer[Index], PciIoHandleBuffer[Index],
&gEfiPciIoProtocolGuid, &gEfiPciIoProtocolGuid,
(VOID **) &PciIo (VOID **)&PciIo
); );
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
Status = PciIo->GetLocation (PciIo, &PciSegment, &PciBusNumber, &PciDeviceNumber, &PciFunctionNumber); Status = PciIo->GetLocation (PciIo, &PciSegment, &PciBusNumber, &PciDeviceNumber, &PciFunctionNumber);
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
PciAddress = (UINT32) ((PciBusNumber << 20) | (PciDeviceNumber << 15) | (PciFunctionNumber << 12)); PciAddress = (UINT32)((PciBusNumber << 20) | (PciDeviceNumber << 15) | (PciFunctionNumber << 12));
if (PciAddress == PcdGet32(PcdUsbXhciPciAddress)) { if (PciAddress == PcdGet32 (PcdUsbXhciPciAddress)) {
// //
// Found the PciIo for USB3 debug port. // Found the PciIo for USB3 debug port.
// //
@ -309,6 +310,7 @@ Usb3PciIoNotify (
} }
} }
} }
gBS->CloseEvent (Event); gBS->CloseEvent (Event);
break; break;
} }
@ -331,9 +333,10 @@ GetUsb3DebugPortInstanceAddrPtr (
// //
// Use the local variables temporarily. // Use the local variables temporarily.
// //
mUsb3InstanceAddr = (EFI_PHYSICAL_ADDRESS) (UINTN) &mUsb3Instance; mUsb3InstanceAddr = (EFI_PHYSICAL_ADDRESS)(UINTN)&mUsb3Instance;
mUsb3InstanceAddrPtr = &mUsb3InstanceAddr; mUsb3InstanceAddrPtr = &mUsb3InstanceAddr;
} }
return mUsb3InstanceAddrPtr; return mUsb3InstanceAddrPtr;
} }
@ -374,10 +377,11 @@ Usb3AllocateDmaBuffer (
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
Usb3MapOneDmaBuffer ( Usb3MapOneDmaBuffer (
PciIo, PciIo,
(EFI_PHYSICAL_ADDRESS) (UINTN) *Address, (EFI_PHYSICAL_ADDRESS)(UINTN)*Address,
EFI_PAGES_TO_SIZE (Pages) EFI_PAGES_TO_SIZE (Pages)
); );
} }
return Status; return Status;
} }
@ -389,7 +393,7 @@ Usb3AllocateDmaBuffer (
@return A pointer to the allocated buffer or NULL if allocation fails. @return A pointer to the allocated buffer or NULL if allocation fails.
**/ **/
VOID* VOID *
AllocateAlignBuffer ( AllocateAlignBuffer (
IN UINTN BufferSize IN UINTN BufferSize
) )
@ -416,7 +420,7 @@ AllocateAlignBuffer (
&TmpAddr &TmpAddr
); );
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
Buf = (VOID *) (UINTN) TmpAddr; Buf = (VOID *)(UINTN)TmpAddr;
} }
} }
} }
@ -446,7 +450,7 @@ DebugCommunicationUsb3DxeConstructor (
EFI_STATUS Status; EFI_STATUS Status;
EFI_EVENT Event; EFI_EVENT Event;
Status = EfiGetSystemConfigurationTable (&gUsb3DbgGuid, (VOID **) &AddrPtr); Status = EfiGetSystemConfigurationTable (&gUsb3DbgGuid, (VOID **)&AddrPtr);
if (EFI_ERROR (Status) || (AddrPtr == NULL)) { if (EFI_ERROR (Status) || (AddrPtr == NULL)) {
// //
// Instead of using local variables, install system configuration table for // Instead of using local variables, install system configuration table for
@ -463,11 +467,11 @@ DebugCommunicationUsb3DxeConstructor (
return Status; return Status;
} }
AddrPtr = (EFI_PHYSICAL_ADDRESS *) (UINTN) Address; AddrPtr = (EFI_PHYSICAL_ADDRESS *)(UINTN)Address;
ZeroMem (AddrPtr, sizeof (EFI_PHYSICAL_ADDRESS) + sizeof (USB3_DEBUG_PORT_HANDLE)); ZeroMem (AddrPtr, sizeof (EFI_PHYSICAL_ADDRESS) + sizeof (USB3_DEBUG_PORT_HANDLE));
Instance = (USB3_DEBUG_PORT_HANDLE *) (AddrPtr + 1); Instance = (USB3_DEBUG_PORT_HANDLE *)(AddrPtr + 1);
CopyMem (Instance, &mUsb3Instance, sizeof (USB3_DEBUG_PORT_HANDLE)); CopyMem (Instance, &mUsb3Instance, sizeof (USB3_DEBUG_PORT_HANDLE));
*AddrPtr = (EFI_PHYSICAL_ADDRESS) (UINTN) Instance; *AddrPtr = (EFI_PHYSICAL_ADDRESS)(UINTN)Instance;
Status = gBS->InstallConfigurationTable (&gUsb3DbgGuid, AddrPtr); Status = gBS->InstallConfigurationTable (&gUsb3DbgGuid, AddrPtr);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
@ -478,6 +482,7 @@ DebugCommunicationUsb3DxeConstructor (
if (mUsb3InstanceAddrPtr != NULL) { if (mUsb3InstanceAddrPtr != NULL) {
*AddrPtr = *mUsb3InstanceAddrPtr; *AddrPtr = *mUsb3InstanceAddrPtr;
} }
mUsb3InstanceAddrPtr = AddrPtr; mUsb3InstanceAddrPtr = AddrPtr;
Instance = GetUsb3DebugPortInstance (); Instance = GetUsb3DebugPortInstance ();
@ -491,7 +496,7 @@ DebugCommunicationUsb3DxeConstructor (
&Event &Event
); );
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
Instance->PciIoEvent = (EFI_PHYSICAL_ADDRESS) (UINTN) Event; Instance->PciIoEvent = (EFI_PHYSICAL_ADDRESS)(UINTN)Event;
} }
} }
@ -523,9 +528,9 @@ DebugCommunicationUsb3DxeDestructor (
// //
// Close the event created. // Close the event created.
// //
gBS->CloseEvent ((EFI_EVENT) (UINTN) Instance->PciIoEvent); gBS->CloseEvent ((EFI_EVENT)(UINTN)Instance->PciIoEvent);
Instance->PciIoEvent = 0; Instance->PciIoEvent = 0;
} }
return EFI_SUCCESS; return EFI_SUCCESS;
} }

View File

@ -216,28 +216,28 @@
// 7.6.9.2 When used by the DbC it is always a 64 byte data structure // 7.6.9.2 When used by the DbC it is always a 64 byte data structure
// //
typedef struct _ENDPOINT_CONTEXT_64 { typedef struct _ENDPOINT_CONTEXT_64 {
UINT32 EPState:3; UINT32 EPState : 3;
UINT32 RsvdZ1:5; UINT32 RsvdZ1 : 5;
UINT32 Mult:2; // set to 0 UINT32 Mult : 2; // set to 0
UINT32 MaxPStreams:5; // set to 0 UINT32 MaxPStreams : 5; // set to 0
UINT32 LSA:1; // set to 0 UINT32 LSA : 1; // set to 0
UINT32 Interval:8; // set to 0 UINT32 Interval : 8; // set to 0
UINT32 RsvdZ2:8; UINT32 RsvdZ2 : 8;
UINT32 RsvdZ3:1; UINT32 RsvdZ3 : 1;
UINT32 CErr:2; UINT32 CErr : 2;
UINT32 EPType:3; UINT32 EPType : 3;
UINT32 RsvdZ4:1; UINT32 RsvdZ4 : 1;
UINT32 HID:1; // set to 0 UINT32 HID : 1; // set to 0
UINT32 MaxBurstSize:8; UINT32 MaxBurstSize : 8;
UINT32 MaxPacketSize:16; UINT32 MaxPacketSize : 16;
UINT32 PtrLo; UINT32 PtrLo;
UINT32 PtrHi; UINT32 PtrHi;
UINT32 AverageTRBLength:16; UINT32 AverageTRBLength : 16;
UINT32 MaxESITPayload:16; // set to 0 UINT32 MaxESITPayload : 16; // set to 0
UINT32 RsvdZ5; // Reserved UINT32 RsvdZ5; // Reserved
UINT32 RsvdZ6; UINT32 RsvdZ6;
@ -265,21 +265,21 @@ typedef struct _TRANSFER_TRB_NORMAL {
UINT32 TRBPtrHi; UINT32 TRBPtrHi;
UINT32 Length:17; UINT32 Length : 17;
UINT32 TDSize:5; UINT32 TDSize : 5;
UINT32 IntTarget:10; UINT32 IntTarget : 10;
UINT32 CycleBit:1; UINT32 CycleBit : 1;
UINT32 ENT:1; UINT32 ENT : 1;
UINT32 ISP:1; UINT32 ISP : 1;
UINT32 NS:1; UINT32 NS : 1;
UINT32 CH:1; UINT32 CH : 1;
UINT32 IOC:1; UINT32 IOC : 1;
UINT32 IDT:1; UINT32 IDT : 1;
UINT32 RsvdZ1:2; UINT32 RsvdZ1 : 2;
UINT32 BEI:1; UINT32 BEI : 1;
UINT32 Type:6; UINT32 Type : 6;
UINT32 RsvdZ2:16; UINT32 RsvdZ2 : 16;
} TRANSFER_TRB_NORMAL; } TRANSFER_TRB_NORMAL;
// //
@ -292,17 +292,17 @@ typedef struct _EVT_TRB_TRANSFER {
UINT32 TRBPtrHi; UINT32 TRBPtrHi;
UINT32 Length:24; UINT32 Length : 24;
UINT32 Completecode:8; UINT32 Completecode : 8;
UINT32 CycleBit:1; UINT32 CycleBit : 1;
UINT32 RsvdZ1:1; UINT32 RsvdZ1 : 1;
UINT32 ED:1; UINT32 ED : 1;
UINT32 RsvdZ2:7; UINT32 RsvdZ2 : 7;
UINT32 Type:6; UINT32 Type : 6;
UINT32 EndpointId:5; UINT32 EndpointId : 5;
UINT32 RsvdZ3:3; UINT32 RsvdZ3 : 3;
UINT32 SlotId:8; UINT32 SlotId : 8;
} EVT_TRB_TRANSFER; } EVT_TRB_TRANSFER;
// //
@ -314,17 +314,17 @@ typedef struct _LINK_TRB {
UINT32 PtrHi; UINT32 PtrHi;
UINT32 RsvdZ1:22; UINT32 RsvdZ1 : 22;
UINT32 InterTarget:10; UINT32 InterTarget : 10;
UINT32 CycleBit:1; UINT32 CycleBit : 1;
UINT32 TC:1; UINT32 TC : 1;
UINT32 RsvdZ2:2; UINT32 RsvdZ2 : 2;
UINT32 CH:1; UINT32 CH : 1;
UINT32 IOC:1; UINT32 IOC : 1;
UINT32 RsvdZ3:4; UINT32 RsvdZ3 : 4;
UINT32 Type:6; UINT32 Type : 6;
UINT32 RsvdZ4:16; UINT32 RsvdZ4 : 16;
} LINK_TRB; } LINK_TRB;
// //
@ -337,10 +337,10 @@ typedef struct _TRB_TEMPLATE {
UINT32 Status; UINT32 Status;
UINT32 CycleBit:1; UINT32 CycleBit : 1;
UINT32 RsvdZ1:9; UINT32 RsvdZ1 : 9;
UINT32 Type:6; UINT32 Type : 6;
UINT32 Control:16; UINT32 Control : 16;
} TRB_TEMPLATE; } TRB_TEMPLATE;
// //
@ -349,8 +349,8 @@ typedef struct _TRB_TEMPLATE {
typedef struct _EVENT_RING_SEG_TABLE_ENTRY { typedef struct _EVENT_RING_SEG_TABLE_ENTRY {
UINT32 PtrLo; UINT32 PtrLo;
UINT32 PtrHi; UINT32 PtrHi;
UINT32 RingTrbSize:16; UINT32 RingTrbSize : 16;
UINT32 RsvdZ1:16; UINT32 RsvdZ1 : 16;
UINT32 RsvdZ2; UINT32 RsvdZ2;
} EVENT_RING_SEG_TABLE_ENTRY; } EVENT_RING_SEG_TABLE_ENTRY;
@ -383,11 +383,11 @@ typedef struct _DBC_INFO_CONTEXT {
UINT64 ManufacturerStrDescAddress; UINT64 ManufacturerStrDescAddress;
UINT64 ProductStrDescAddress; UINT64 ProductStrDescAddress;
UINT64 SerialNumberStrDescAddress; UINT64 SerialNumberStrDescAddress;
UINT64 String0Length:8; UINT64 String0Length : 8;
UINT64 ManufacturerStrLength:8; UINT64 ManufacturerStrLength : 8;
UINT64 ProductStrLength:8; UINT64 ProductStrLength : 8;
UINT64 SerialNumberStrLength:8; UINT64 SerialNumberStrLength : 8;
UINT64 RsvdZ1:32; UINT64 RsvdZ1 : 32;
UINT64 RsvdZ2; UINT64 RsvdZ2;
UINT64 RsvdZ3; UINT64 RsvdZ3;
UINT64 RsvdZ4; UINT64 RsvdZ4;
@ -594,7 +594,7 @@ XhcWriteDebugReg (
is not enabled. is not enabled.
**/ **/
BOOLEAN BOOLEAN
XhcIsBitSet( XhcIsBitSet (
UINTN Register, UINTN Register,
UINT32 BitMask UINT32 BitMask
); );
@ -606,7 +606,7 @@ XhcIsBitSet(
@param[in] BitMask 32-bit mask @param[in] BitMask 32-bit mask
**/ **/
VOID VOID
XhcSetR32Bit( XhcSetR32Bit (
UINTN Register, UINTN Register,
UINT32 BitMask UINT32 BitMask
); );
@ -618,7 +618,7 @@ XhcSetR32Bit(
@param[in] BitMask 32-bit mask @param[in] BitMask 32-bit mask
**/ **/
VOID VOID
XhcClearR32Bit( XhcClearR32Bit (
IN OUT UINTN Register, IN OUT UINTN Register,
IN UINT32 BitMask IN UINT32 BitMask
); );
@ -654,7 +654,7 @@ GetXhciPciCommand (
@return A pointer to the allocated buffer or NULL if allocation fails. @return A pointer to the allocated buffer or NULL if allocation fails.
**/ **/
VOID* VOID *
AllocateAlignBuffer ( AllocateAlignBuffer (
IN UINTN BufferSize IN UINTN BufferSize
); );

View File

@ -126,6 +126,7 @@ IoMmuAllocateBuffer (
*HostAddress = NULL; *HostAddress = NULL;
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
Status = IoMmu->SetAttribute ( Status = IoMmu->SetAttribute (
IoMmu, IoMmu,
*Mapping, *Mapping,
@ -161,7 +162,7 @@ Usb3GetIoMmu (
&gEdkiiIoMmuPpiGuid, &gEdkiiIoMmuPpiGuid,
0, 0,
NULL, NULL,
(VOID **) &IoMmu (VOID **)&IoMmu
); );
if (!EFI_ERROR (Status) && (IoMmu != NULL)) { if (!EFI_ERROR (Status) && (IoMmu != NULL)) {
return IoMmu; return IoMmu;
@ -196,8 +197,8 @@ GetUsb3DebugPortInstanceAddrPtr (
); );
ASSERT (AddrPtr != NULL); ASSERT (AddrPtr != NULL);
ZeroMem (AddrPtr, sizeof (EFI_PHYSICAL_ADDRESS) + sizeof (USB3_DEBUG_PORT_HANDLE)); ZeroMem (AddrPtr, sizeof (EFI_PHYSICAL_ADDRESS) + sizeof (USB3_DEBUG_PORT_HANDLE));
Instance = (USB3_DEBUG_PORT_HANDLE *) (AddrPtr + 1); Instance = (USB3_DEBUG_PORT_HANDLE *)(AddrPtr + 1);
*AddrPtr = (EFI_PHYSICAL_ADDRESS) (UINTN) Instance; *AddrPtr = (EFI_PHYSICAL_ADDRESS)(UINTN)Instance;
Instance->FromHob = TRUE; Instance->FromHob = TRUE;
Instance->Initialized = USB3DBG_UNINITIALIZED; Instance->Initialized = USB3DBG_UNINITIALIZED;
if (Usb3GetIoMmu () == NULL) { if (Usb3GetIoMmu () == NULL) {
@ -219,7 +220,7 @@ GetUsb3DebugPortInstanceAddrPtr (
@return A pointer to the allocated buffer or NULL if allocation fails. @return A pointer to the allocated buffer or NULL if allocation fails.
**/ **/
VOID* VOID *
AllocateAlignBuffer ( AllocateAlignBuffer (
IN UINTN BufferSize IN UINTN BufferSize
) )
@ -241,7 +242,7 @@ AllocateAlignBuffer (
&gEfiPeiMemoryDiscoveredPpiGuid, &gEfiPeiMemoryDiscoveredPpiGuid,
0, 0,
NULL, NULL,
(VOID **) &MemoryDiscoveredPpi (VOID **)&MemoryDiscoveredPpi
); );
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
IoMmu = Usb3GetIoMmu (); IoMmu = Usb3GetIoMmu ();
@ -254,8 +255,8 @@ AllocateAlignBuffer (
&Mapping &Mapping
); );
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
ASSERT (Address == ((EFI_PHYSICAL_ADDRESS) (UINTN) HostAddress)); ASSERT (Address == ((EFI_PHYSICAL_ADDRESS)(UINTN)HostAddress));
Buf = (VOID *)(UINTN) Address; Buf = (VOID *)(UINTN)Address;
} }
} else { } else {
Status = PeiServicesAllocatePages ( Status = PeiServicesAllocatePages (
@ -264,10 +265,10 @@ AllocateAlignBuffer (
&Address &Address
); );
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
Buf = (VOID *)(UINTN) Address; Buf = (VOID *)(UINTN)Address;
} }
} }
} }
return Buf; return Buf;
} }

View File

@ -32,7 +32,7 @@ XhcSyncTrsRing (
// //
// Calculate the latest RingEnqueue and RingPCS // Calculate the latest RingEnqueue and RingPCS
// //
TrsTrb = (TRB_TEMPLATE *)(UINTN) TrsRing->RingEnqueue; TrsTrb = (TRB_TEMPLATE *)(UINTN)TrsRing->RingEnqueue;
ASSERT (TrsTrb != NULL); ASSERT (TrsTrb != NULL);
@ -40,13 +40,14 @@ XhcSyncTrsRing (
if (TrsTrb->CycleBit != (TrsRing->RingPCS & BIT0)) { if (TrsTrb->CycleBit != (TrsRing->RingPCS & BIT0)) {
break; break;
} }
TrsTrb++; TrsTrb++;
if ((UINT8) TrsTrb->Type == TRB_TYPE_LINK) { if ((UINT8)TrsTrb->Type == TRB_TYPE_LINK) {
ASSERT (((LINK_TRB*)TrsTrb)->TC != 0); ASSERT (((LINK_TRB *)TrsTrb)->TC != 0);
// //
// set cycle bit in Link TRB as normal // set cycle bit in Link TRB as normal
// //
((LINK_TRB*)TrsTrb)->CycleBit = TrsRing->RingPCS & BIT0; ((LINK_TRB *)TrsTrb)->CycleBit = TrsRing->RingPCS & BIT0;
// //
// Toggle PCS maintained by software // Toggle PCS maintained by software
// //
@ -54,10 +55,11 @@ XhcSyncTrsRing (
TrsTrb = (TRB_TEMPLATE *)(UINTN)((TrsTrb->Parameter1 | LShiftU64 ((UINT64)TrsTrb->Parameter2, 32)) & ~0x0F); TrsTrb = (TRB_TEMPLATE *)(UINTN)((TrsTrb->Parameter1 | LShiftU64 ((UINT64)TrsTrb->Parameter2, 32)) & ~0x0F);
} }
} }
ASSERT (Index != TrsRing->TrbNumber); ASSERT (Index != TrsRing->TrbNumber);
if ((EFI_PHYSICAL_ADDRESS)(UINTN) TrsTrb != TrsRing->RingEnqueue) { if ((EFI_PHYSICAL_ADDRESS)(UINTN)TrsTrb != TrsRing->RingEnqueue) {
TrsRing->RingEnqueue = (EFI_PHYSICAL_ADDRESS)(UINTN) TrsTrb; TrsRing->RingEnqueue = (EFI_PHYSICAL_ADDRESS)(UINTN)TrsTrb;
} }
// //
@ -95,7 +97,7 @@ XhcSyncEventRing (
// Calculate the EventRingEnqueue and EventRingCCS. // Calculate the EventRingEnqueue and EventRingCCS.
// Note: only support single Segment // Note: only support single Segment
// //
EvtTrb1 = (TRB_TEMPLATE *)(UINTN) EvtRing->EventRingDequeue; EvtTrb1 = (TRB_TEMPLATE *)(UINTN)EvtRing->EventRingDequeue;
for (Index = 0; Index < EvtRing->TrbNumber; Index++) { for (Index = 0; Index < EvtRing->TrbNumber; Index++) {
if (EvtTrb1->CycleBit != EvtRing->EventRingCCS) { if (EvtTrb1->CycleBit != EvtRing->EventRingCCS) {
@ -104,8 +106,8 @@ XhcSyncEventRing (
EvtTrb1++; EvtTrb1++;
if ((UINTN)EvtTrb1 >= ((UINTN) EvtRing->EventRingSeg0 + sizeof (TRB_TEMPLATE) * EvtRing->TrbNumber)) { if ((UINTN)EvtTrb1 >= ((UINTN)EvtRing->EventRingSeg0 + sizeof (TRB_TEMPLATE) * EvtRing->TrbNumber)) {
EvtTrb1 = (TRB_TEMPLATE *)(UINTN) EvtRing->EventRingSeg0; EvtTrb1 = (TRB_TEMPLATE *)(UINTN)EvtRing->EventRingSeg0;
EvtRing->EventRingCCS = (EvtRing->EventRingCCS) ? 0 : 1; EvtRing->EventRingCCS = (EvtRing->EventRingCCS) ? 0 : 1;
} }
} }
@ -142,7 +144,7 @@ XhcCheckNewEvent (
ASSERT (EvtRing != NULL); ASSERT (EvtRing != NULL);
*NewEvtTrb = (TRB_TEMPLATE *)(UINTN) EvtRing->EventRingDequeue; *NewEvtTrb = (TRB_TEMPLATE *)(UINTN)EvtRing->EventRingDequeue;
if (EvtRing->EventRingDequeue == EvtRing->EventRingEnqueue) { if (EvtRing->EventRingDequeue == EvtRing->EventRingEnqueue) {
return EFI_NOT_READY; return EFI_NOT_READY;
@ -154,7 +156,7 @@ XhcCheckNewEvent (
// //
// If the dequeue pointer is beyond the ring, then roll-back it to the beginning of the ring. // If the dequeue pointer is beyond the ring, then roll-back it to the beginning of the ring.
// //
if ((UINTN)EvtRing->EventRingDequeue >= ((UINTN) EvtRing->EventRingSeg0 + sizeof (TRB_TEMPLATE) * EvtRing->TrbNumber)) { if ((UINTN)EvtRing->EventRingDequeue >= ((UINTN)EvtRing->EventRingSeg0 + sizeof (TRB_TEMPLATE) * EvtRing->TrbNumber)) {
EvtRing->EventRingDequeue = EvtRing->EventRingSeg0; EvtRing->EventRingDequeue = EvtRing->EventRingSeg0;
} }
@ -180,7 +182,7 @@ IsTrbInTrsRing (
TRB_TEMPLATE *CheckedTrb; TRB_TEMPLATE *CheckedTrb;
UINTN Index; UINTN Index;
CheckedTrb = (TRB_TEMPLATE *)(UINTN) Ring->RingSeg0; CheckedTrb = (TRB_TEMPLATE *)(UINTN)Ring->RingSeg0;
ASSERT (Ring->TrbNumber == TR_RING_TRB_NUMBER); ASSERT (Ring->TrbNumber == TR_RING_TRB_NUMBER);
@ -188,6 +190,7 @@ IsTrbInTrsRing (
if (Trb == CheckedTrb) { if (Trb == CheckedTrb) {
return TRUE; return TRUE;
} }
CheckedTrb++; CheckedTrb++;
} }
@ -231,7 +234,6 @@ XhcCheckUrbResult (
XhcSyncEventRing (Handle, &Handle->EventRing); XhcSyncEventRing (Handle, &Handle->EventRing);
for (Index = 0; Index < Handle->EventRing.TrbNumber; Index++) { for (Index = 0; Index < Handle->EventRing.TrbNumber; Index++) {
Status = XhcCheckNewEvent (Handle, &Handle->EventRing, ((TRB_TEMPLATE **)&EvtTrb)); Status = XhcCheckNewEvent (Handle, &Handle->EventRing, ((TRB_TEMPLATE **)&EvtTrb));
if (Status == EFI_NOT_READY) { if (Status == EFI_NOT_READY) {
// //
@ -244,7 +246,7 @@ XhcCheckUrbResult (
continue; continue;
} }
TRBPtr = (TRB_TEMPLATE *)(UINTN)(EvtTrb->TRBPtrLo | LShiftU64 ((UINT64) EvtTrb->TRBPtrHi, 32)); TRBPtr = (TRB_TEMPLATE *)(UINTN)(EvtTrb->TRBPtrLo | LShiftU64 ((UINT64)EvtTrb->TRBPtrHi, 32));
if (IsTrbInTrsRing ((TRANSFER_RING *)(UINTN)(Urb->Ring), TRBPtr)) { if (IsTrbInTrsRing ((TRANSFER_RING *)(UINTN)(Urb->Ring), TRBPtr)) {
CheckedUrb = Urb; CheckedUrb = Urb;
@ -253,7 +255,7 @@ XhcCheckUrbResult (
// If it is read event and it should be generated by poll, and current operation is write, we need save data into internal buffer. // If it is read event and it should be generated by poll, and current operation is write, we need save data into internal buffer.
// Internal buffer is used by next read. // Internal buffer is used by next read.
// //
Handle->DataCount = (UINT8) (Handle->UrbIn.DataLen - EvtTrb->Length); Handle->DataCount = (UINT8)(Handle->UrbIn.DataLen - EvtTrb->Length);
CopyMem ((VOID *)(UINTN)Handle->Data, (VOID *)(UINTN)Handle->UrbIn.Data, Handle->DataCount); CopyMem ((VOID *)(UINTN)Handle->Data, (VOID *)(UINTN)Handle->UrbIn.Data, Handle->DataCount);
// //
// Fill this TRB complete with CycleBit, otherwise next read will fail with old TRB. // Fill this TRB complete with CycleBit, otherwise next read will fail with old TRB.
@ -265,14 +267,16 @@ XhcCheckUrbResult (
} }
if ((EvtTrb->Completecode == TRB_COMPLETION_SHORT_PACKET) || if ((EvtTrb->Completecode == TRB_COMPLETION_SHORT_PACKET) ||
(EvtTrb->Completecode == TRB_COMPLETION_SUCCESS)) { (EvtTrb->Completecode == TRB_COMPLETION_SUCCESS))
{
// //
// The length of data which were transferred. // The length of data which were transferred.
// //
CheckedUrb->Completed += (((TRANSFER_TRB_NORMAL*)TRBPtr)->Length - EvtTrb->Length); CheckedUrb->Completed += (((TRANSFER_TRB_NORMAL *)TRBPtr)->Length - EvtTrb->Length);
} else { } else {
CheckedUrb->Result |= EFI_USB_ERR_TIMEOUT; CheckedUrb->Result |= EFI_USB_ERR_TIMEOUT;
} }
// //
// This Urb has been processed // This Urb has been processed
// //
@ -288,7 +292,7 @@ EXIT:
// //
Low = XhcReadDebugReg (Handle, XHC_DC_DCERDP); Low = XhcReadDebugReg (Handle, XHC_DC_DCERDP);
High = XhcReadDebugReg (Handle, XHC_DC_DCERDP + 4); High = XhcReadDebugReg (Handle, XHC_DC_DCERDP + 4);
XhcDequeue = (UINT64)(LShiftU64((UINT64)High, 32) | Low); XhcDequeue = (UINT64)(LShiftU64 ((UINT64)High, 32) | Low);
if ((XhcDequeue & (~0x0F)) != ((UINT64)(UINTN)Handle->EventRing.EventRingDequeue & (~0x0F))) { if ((XhcDequeue & (~0x0F)) != ((UINT64)(UINTN)Handle->EventRing.EventRingDequeue & (~0x0F))) {
// //
@ -356,6 +360,7 @@ XhcExecTransfer (
if (Timeout == 0) { if (Timeout == 0) {
Loop = 0xFFFFFFFF; Loop = 0xFFFFFFFF;
} }
XhcRingDoorBell (Handle, Urb); XhcRingDoorBell (Handle, Urb);
// //
// Event Ring Not Empty bit can only be set to 1 by XHC after ringing door bell with some delay. // Event Ring Not Empty bit can only be set to 1 by XHC after ringing door bell with some delay.
@ -365,19 +370,22 @@ XhcExecTransfer (
if (Urb->Finished) { if (Urb->Finished) {
break; break;
} }
MicroSecondDelay (XHC_DEBUG_PORT_1_MILLISECOND); MicroSecondDelay (XHC_DEBUG_PORT_1_MILLISECOND);
} }
if (Index == Loop) { if (Index == Loop) {
// //
// If time out occurs. // If time out occurs.
// //
Urb->Result |= EFI_USB_ERR_TIMEOUT; Urb->Result |= EFI_USB_ERR_TIMEOUT;
} }
// //
// If URB transfer is error, restore transfer ring to original value before URB transfer // If URB transfer is error, restore transfer ring to original value before URB transfer
// This will make the current transfer TRB is always at the latest unused one in transfer ring. // This will make the current transfer TRB is always at the latest unused one in transfer ring.
// //
Ring = (TRANSFER_RING *)(UINTN) Urb->Ring; Ring = (TRANSFER_RING *)(UINTN)Urb->Ring;
if ((Urb->Result != EFI_USB_NOERROR) && (Urb->Direction == EfiUsbDataIn)) { if ((Urb->Result != EFI_USB_NOERROR) && (Urb->Direction == EfiUsbDataIn)) {
// //
// Adjust Enqueue pointer // Adjust Enqueue pointer
@ -386,7 +394,7 @@ XhcExecTransfer (
// //
// Clear CCS flag for next use // Clear CCS flag for next use
// //
Trb = (TRB_TEMPLATE *)(UINTN) Urb->Trb; Trb = (TRB_TEMPLATE *)(UINTN)Urb->Trb;
Trb->CycleBit = ((~Ring->RingPCS) & BIT0); Trb->CycleBit = ((~Ring->RingPCS) & BIT0);
} else { } else {
// //
@ -420,7 +428,7 @@ XhcCreateTransferTrb (
EPRing = &Handle->TransferRingOut; EPRing = &Handle->TransferRingOut;
} }
Urb->Ring = (EFI_PHYSICAL_ADDRESS)(UINTN) EPRing; Urb->Ring = (EFI_PHYSICAL_ADDRESS)(UINTN)EPRing;
XhcSyncTrsRing (Handle, EPRing); XhcSyncTrsRing (Handle, EPRing);
Urb->Trb = EPRing->RingEnqueue; Urb->Trb = EPRing->RingEnqueue;
@ -453,7 +461,7 @@ XhcCreateTransferTrb (
@return Created URB or NULL @return Created URB or NULL
**/ **/
URB* URB *
XhcCreateUrb ( XhcCreateUrb (
IN USB3_DEBUG_PORT_HANDLE *Handle, IN USB3_DEBUG_PORT_HANDLE *Handle,
IN EFI_USB_DATA_DIRECTION Direction, IN EFI_USB_DATA_DIRECTION Direction,
@ -487,14 +495,14 @@ XhcCreateUrb (
// //
// Do not break URB data in buffer as it may contain the data which were just put in via DMA by XHC // Do not break URB data in buffer as it may contain the data which were just put in via DMA by XHC
// //
Urb->DataLen = (UINT32) DataLen; Urb->DataLen = (UINT32)DataLen;
} else { } else {
// //
// Put data into URB data out buffer which will create TRBs // Put data into URB data out buffer which will create TRBs
// //
ZeroMem ((VOID*)(UINTN) Urb->Data, DataLen); ZeroMem ((VOID *)(UINTN)Urb->Data, DataLen);
CopyMem ((VOID*)(UINTN) Urb->Data, Data, DataLen); CopyMem ((VOID *)(UINTN)Urb->Data, Data, DataLen);
Urb->DataLen = (UINT32) DataLen; Urb->DataLen = (UINT32)DataLen;
} }
Status = XhcCreateTransferTrb (Handle, Urb); Status = XhcCreateTransferTrb (Handle, Urb);
@ -574,4 +582,3 @@ XhcDataTransfer (
return Status; return Status;
} }

View File

@ -27,14 +27,14 @@ CheckDebugAgentHandler (
IA32_IDT_GATE_DESCRIPTOR *IdtEntry; IA32_IDT_GATE_DESCRIPTOR *IdtEntry;
UINTN InterruptHandler; UINTN InterruptHandler;
IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *) IdtDescriptor->Base; IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *)IdtDescriptor->Base;
if (IdtEntry == NULL) { if (IdtEntry == NULL) {
return FALSE; return FALSE;
} }
InterruptHandler = IdtEntry[InterruptType].Bits.OffsetLow + InterruptHandler = IdtEntry[InterruptType].Bits.OffsetLow +
(IdtEntry[InterruptType].Bits.OffsetHigh << 16); (IdtEntry[InterruptType].Bits.OffsetHigh << 16);
if (InterruptHandler >= sizeof (UINT32) && *(UINT32 *)(InterruptHandler - sizeof (UINT32)) == AGENT_HANDLER_SIGNATURE) { if ((InterruptHandler >= sizeof (UINT32)) && (*(UINT32 *)(InterruptHandler - sizeof (UINT32)) == AGENT_HANDLER_SIGNATURE)) {
return TRUE; return TRUE;
} else { } else {
return FALSE; return FALSE;
@ -58,7 +58,7 @@ SaveAndUpdateIdtEntry1 (
UINT16 CodeSegment; UINT16 CodeSegment;
UINTN InterruptHandler; UINTN InterruptHandler;
IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *) IdtDescriptor->Base; IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *)IdtDescriptor->Base;
CopyMem (SavedIdtEntry, &IdtEntry[1], sizeof (IA32_IDT_GATE_DESCRIPTOR)); CopyMem (SavedIdtEntry, &IdtEntry[1], sizeof (IA32_IDT_GATE_DESCRIPTOR));
// //
@ -66,7 +66,7 @@ SaveAndUpdateIdtEntry1 (
// //
CodeSegment = AsmReadCs (); CodeSegment = AsmReadCs ();
InterruptHandler = (UINTN) &AsmInterruptHandle; InterruptHandler = (UINTN)&AsmInterruptHandle;
IdtEntry[1].Bits.OffsetLow = (UINT16)(UINTN)InterruptHandler; IdtEntry[1].Bits.OffsetLow = (UINT16)(UINTN)InterruptHandler;
IdtEntry[1].Bits.OffsetHigh = (UINT16)((UINTN)InterruptHandler >> 16); IdtEntry[1].Bits.OffsetHigh = (UINT16)((UINTN)InterruptHandler >> 16);
IdtEntry[1].Bits.Selector = CodeSegment; IdtEntry[1].Bits.Selector = CodeSegment;
@ -88,6 +88,6 @@ RestoreIdtEntry1 (
{ {
IA32_IDT_GATE_DESCRIPTOR *IdtEntry; IA32_IDT_GATE_DESCRIPTOR *IdtEntry;
IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *) IdtDescriptor->Base; IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *)IdtDescriptor->Base;
CopyMem (&IdtEntry[1], RestoredIdtEntry, sizeof (IA32_IDT_GATE_DESCRIPTOR)); CopyMem (&IdtEntry[1], RestoredIdtEntry, sizeof (IA32_IDT_GATE_DESCRIPTOR));
} }

View File

@ -27,7 +27,7 @@ IsDrxEnabled (
IN UINTN Dr7 IN UINTN Dr7
) )
{ {
return (BOOLEAN) (((Dr7 >> (RegisterIndex * 2)) & (BIT0 | BIT1)) == (BIT0 | BIT1)); return (BOOLEAN)(((Dr7 >> (RegisterIndex * 2)) & (BIT0 | BIT1)) == (BIT0 | BIT1));
} }
/** /**
@ -64,7 +64,7 @@ PeCoffLoaderExtraActionCommon (
ASSERT (ImageContext != NULL); ASSERT (ImageContext != NULL);
if (ImageContext->PdbPointer != NULL) { if (ImageContext->PdbPointer != NULL) {
DEBUG((DEBUG_ERROR, " PDB = %a\n", ImageContext->PdbPointer)); DEBUG ((DEBUG_ERROR, " PDB = %a\n", ImageContext->PdbPointer));
} }
// //
@ -84,6 +84,7 @@ PeCoffLoaderExtraActionCommon (
LoadImageMethod = DEBUG_LOAD_IMAGE_METHOD_SOFT_INT3; LoadImageMethod = DEBUG_LOAD_IMAGE_METHOD_SOFT_INT3;
} }
} }
AsmReadIdtr (&IdtDescriptor); AsmReadIdtr (&IdtDescriptor);
if (LoadImageMethod == DEBUG_LOAD_IMAGE_METHOD_SOFT_INT3) { if (LoadImageMethod == DEBUG_LOAD_IMAGE_METHOD_SOFT_INT3) {
if (!CheckDebugAgentHandler (&IdtDescriptor, SOFT_INT_VECTOR_NUM)) { if (!CheckDebugAgentHandler (&IdtDescriptor, SOFT_INT_VECTOR_NUM)) {
@ -122,8 +123,8 @@ PeCoffLoaderExtraActionCommon (
// //
AsmWriteDr7 (BIT10); AsmWriteDr7 (BIT10);
AsmWriteDr0 (Signature); AsmWriteDr0 (Signature);
AsmWriteDr1 ((UINTN) ImageContext->PdbPointer); AsmWriteDr1 ((UINTN)ImageContext->PdbPointer);
AsmWriteDr2 ((UINTN) ImageContext); AsmWriteDr2 ((UINTN)ImageContext);
AsmWriteDr3 (IO_PORT_BREAKPOINT_ADDRESS); AsmWriteDr3 (IO_PORT_BREAKPOINT_ADDRESS);
if (LoadImageMethod == DEBUG_LOAD_IMAGE_METHOD_IO_HW_BREAKPOINT) { if (LoadImageMethod == DEBUG_LOAD_IMAGE_METHOD_IO_HW_BREAKPOINT) {
@ -136,7 +137,6 @@ PeCoffLoaderExtraActionCommon (
do { do {
DebugAgentStatus = IoRead8 (IO_PORT_BREAKPOINT_ADDRESS); DebugAgentStatus = IoRead8 (IO_PORT_BREAKPOINT_ADDRESS);
} while (DebugAgentStatus == DEBUG_AGENT_IMAGE_WAIT); } while (DebugAgentStatus == DEBUG_AGENT_IMAGE_WAIT);
} else if (LoadImageMethod == DEBUG_LOAD_IMAGE_METHOD_SOFT_INT3) { } else if (LoadImageMethod == DEBUG_LOAD_IMAGE_METHOD_SOFT_INT3) {
// //
// Generate a software break point. // Generate a software break point.
@ -150,26 +150,31 @@ PeCoffLoaderExtraActionCommon (
// in the above exception handler // in the above exception handler
// //
NewDr7 = AsmReadDr7 () | BIT10; // H/w sets bit 10, some simulators don't NewDr7 = AsmReadDr7 () | BIT10; // H/w sets bit 10, some simulators don't
if (!IsDrxEnabled (0, NewDr7) && (AsmReadDr0 () == 0 || AsmReadDr0 () == Signature)) { if (!IsDrxEnabled (0, NewDr7) && ((AsmReadDr0 () == 0) || (AsmReadDr0 () == Signature))) {
// //
// If user changed Dr3 (by setting HW bp in the above exception handler, // If user changed Dr3 (by setting HW bp in the above exception handler,
// we will not set Dr0 to 0 in GO/STEP handler because the break cause is not IMAGE_LOAD/_UNLOAD. // we will not set Dr0 to 0 in GO/STEP handler because the break cause is not IMAGE_LOAD/_UNLOAD.
// //
AsmWriteDr0 (Dr0); AsmWriteDr0 (Dr0);
} }
if (!IsDrxEnabled (1, NewDr7) && (AsmReadDr1 () == (UINTN) ImageContext->PdbPointer)) {
if (!IsDrxEnabled (1, NewDr7) && (AsmReadDr1 () == (UINTN)ImageContext->PdbPointer)) {
AsmWriteDr1 (Dr1); AsmWriteDr1 (Dr1);
} }
if (!IsDrxEnabled (2, NewDr7) && (AsmReadDr2 () == (UINTN) ImageContext)) {
if (!IsDrxEnabled (2, NewDr7) && (AsmReadDr2 () == (UINTN)ImageContext)) {
AsmWriteDr2 (Dr2); AsmWriteDr2 (Dr2);
} }
if (!IsDrxEnabled (3, NewDr7) && (AsmReadDr3 () == IO_PORT_BREAKPOINT_ADDRESS)) { if (!IsDrxEnabled (3, NewDr7) && (AsmReadDr3 () == IO_PORT_BREAKPOINT_ADDRESS)) {
AsmWriteDr3 (Dr3); AsmWriteDr3 (Dr3);
} }
if (LoadImageMethod == DEBUG_LOAD_IMAGE_METHOD_IO_HW_BREAKPOINT) { if (LoadImageMethod == DEBUG_LOAD_IMAGE_METHOD_IO_HW_BREAKPOINT) {
if (AsmReadCr4 () == (Cr4 | BIT3)) { if (AsmReadCr4 () == (Cr4 | BIT3)) {
AsmWriteCr4 (Cr4); AsmWriteCr4 (Cr4);
} }
if (NewDr7 == 0x20000480) { if (NewDr7 == 0x20000480) {
AsmWriteDr7 (Dr7); AsmWriteDr7 (Dr7);
} }
@ -178,12 +183,14 @@ PeCoffLoaderExtraActionCommon (
AsmWriteDr7 (Dr7); AsmWriteDr7 (Dr7);
} }
} }
// //
// Restore original IDT entry for INT1 if it was hooked. // Restore original IDT entry for INT1 if it was hooked.
// //
if (IdtEntryHooked) { if (IdtEntryHooked) {
RestoreIdtEntry1 (&IdtDescriptor, &OriginalIdtEntry); RestoreIdtEntry1 (&IdtDescriptor, &OriginalIdtEntry);
} }
// //
// Restore the interrupt state // Restore the interrupt state
// //

View File

@ -70,4 +70,3 @@ RestoreIdtEntry1 (
); );
#endif #endif

View File

@ -27,7 +27,7 @@ CheckDebugAgentHandler (
IA32_IDT_GATE_DESCRIPTOR *IdtEntry; IA32_IDT_GATE_DESCRIPTOR *IdtEntry;
UINTN InterruptHandler; UINTN InterruptHandler;
IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *) IdtDescriptor->Base; IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *)IdtDescriptor->Base;
if (IdtEntry == NULL) { if (IdtEntry == NULL) {
return FALSE; return FALSE;
} }
@ -35,7 +35,7 @@ CheckDebugAgentHandler (
InterruptHandler = IdtEntry[InterruptType].Bits.OffsetLow + InterruptHandler = IdtEntry[InterruptType].Bits.OffsetLow +
(((UINTN)IdtEntry[InterruptType].Bits.OffsetHigh) << 16) + (((UINTN)IdtEntry[InterruptType].Bits.OffsetHigh) << 16) +
(((UINTN)IdtEntry[InterruptType].Bits.OffsetUpper) << 32); (((UINTN)IdtEntry[InterruptType].Bits.OffsetUpper) << 32);
if (InterruptHandler >= sizeof (UINT32) && *(UINT32 *)(InterruptHandler - sizeof (UINT32)) == AGENT_HANDLER_SIGNATURE) { if ((InterruptHandler >= sizeof (UINT32)) && (*(UINT32 *)(InterruptHandler - sizeof (UINT32)) == AGENT_HANDLER_SIGNATURE)) {
return TRUE; return TRUE;
} else { } else {
return FALSE; return FALSE;
@ -59,7 +59,7 @@ SaveAndUpdateIdtEntry1 (
UINT16 CodeSegment; UINT16 CodeSegment;
UINTN InterruptHandler; UINTN InterruptHandler;
IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *) IdtDescriptor->Base; IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *)IdtDescriptor->Base;
CopyMem (SavedIdtEntry, &IdtEntry[1], sizeof (IA32_IDT_GATE_DESCRIPTOR)); CopyMem (SavedIdtEntry, &IdtEntry[1], sizeof (IA32_IDT_GATE_DESCRIPTOR));
// //
@ -67,7 +67,7 @@ SaveAndUpdateIdtEntry1 (
// //
CodeSegment = AsmReadCs (); CodeSegment = AsmReadCs ();
InterruptHandler = (UINTN) &AsmInterruptHandle; InterruptHandler = (UINTN)&AsmInterruptHandle;
IdtEntry[1].Bits.OffsetLow = (UINT16)(UINTN)InterruptHandler; IdtEntry[1].Bits.OffsetLow = (UINT16)(UINTN)InterruptHandler;
IdtEntry[1].Bits.OffsetHigh = (UINT16)((UINTN)InterruptHandler >> 16); IdtEntry[1].Bits.OffsetHigh = (UINT16)((UINTN)InterruptHandler >> 16);
IdtEntry[1].Bits.OffsetUpper = (UINT32)((UINTN)InterruptHandler >> 32); IdtEntry[1].Bits.OffsetUpper = (UINT32)((UINTN)InterruptHandler >> 32);
@ -90,6 +90,6 @@ RestoreIdtEntry1 (
{ {
IA32_IDT_GATE_DESCRIPTOR *IdtEntry; IA32_IDT_GATE_DESCRIPTOR *IdtEntry;
IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *) IdtDescriptor->Base; IdtEntry = (IA32_IDT_GATE_DESCRIPTOR *)IdtDescriptor->Base;
CopyMem (&IdtEntry[1], RestoredIdtEntry, sizeof (IA32_IDT_GATE_DESCRIPTOR)); CopyMem (&IdtEntry[1], RestoredIdtEntry, sizeof (IA32_IDT_GATE_DESCRIPTOR));
} }