/** @file\r
Multi-Processor support functions implementation.\r
\r
- Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.<BR>\r
+ Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>\r
This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
which accompanies this distribution. The full text of the license may be found at\r
\r
#include "DebugAgent.h"\r
\r
-DEBUG_MP_CONTEXT volatile mDebugMpContext = {0,0,0,0,0,0,0,0,FALSE,FALSE};\r
+GLOBAL_REMOVE_IF_UNREFERENCED DEBUG_MP_CONTEXT volatile mDebugMpContext = {0,0,0,{0},{0},0,0,0,0,FALSE,FALSE};\r
\r
-DEBUG_CPU_DATA volatile mDebugCpuData = {0};\r
+GLOBAL_REMOVE_IF_UNREFERENCED DEBUG_CPU_DATA volatile mDebugCpuData = {0};\r
\r
/**\r
- Acquire access control on debug port.\r
+ Acquire a spin lock when Multi-processor supported.\r
\r
It will block in the function if cannot get the access control.\r
+ If Multi-processor is not supported, return directly.\r
+\r
+ @param[in, out] MpSpinLock A pointer to the spin lock.\r
\r
**/\r
VOID\r
-AcquireDebugPortControl (\r
- VOID\r
+AcquireMpSpinLock (\r
+ IN OUT SPIN_LOCK *MpSpinLock\r
)\r
{\r
- if (!MultiProcessorDebugSupport) {\r
+ if (!MultiProcessorDebugSupport()) {\r
return;\r
}\r
\r
while (TRUE) {\r
- if (AcquireSpinLockOrFail (&mDebugMpContext.DebugPortSpinLock)) {\r
+ if (AcquireSpinLockOrFail (MpSpinLock)) {\r
break;\r
}\r
CpuPause ();\r
}\r
\r
/**\r
- Release access control on debug port.\r
-\r
-**/\r
-VOID\r
-ReleaseDebugPortControl (\r
- VOID\r
- )\r
-{\r
- if (!MultiProcessorDebugSupport) {\r
- return;\r
- }\r
-\r
- ReleaseSpinLock (&mDebugMpContext.DebugPortSpinLock);\r
-}\r
-\r
-/**\r
- Acquire access control on MP context.\r
+ Release a spin lock when Multi-processor supported.\r
\r
- It will block in the function if cannot get the access control.\r
+ @param[in, out] MpSpinLock A pointer to the spin lock.\r
\r
**/\r
VOID\r
-AcquireMpContextControl (\r
- VOID\r
+ReleaseMpSpinLock (\r
+ IN OUT SPIN_LOCK *MpSpinLock\r
)\r
{\r
- while (TRUE) {\r
- if (AcquireSpinLockOrFail (&mDebugMpContext.MpContextSpinLock)) {\r
- break;\r
- }\r
- CpuPause ();\r
- continue;\r
+ if (!MultiProcessorDebugSupport()) {\r
+ return;\r
}\r
-}\r
-\r
-/**\r
- Release access control on MP context.\r
\r
-**/\r
-VOID\r
-ReleaseMpContextControl (\r
- VOID\r
- )\r
-{\r
- ReleaseSpinLock (&mDebugMpContext.MpContextSpinLock);\r
+ ReleaseSpinLock (MpSpinLock);\r
}\r
\r
/**\r
// Send fixed IPI to other processors.\r
//\r
SendFixedIpiAllExcludingSelf (DEBUG_TIMER_VECTOR);\r
- \r
+\r
}\r
\r
/**\r
\r
LocalApicID = (UINT16) GetApicId ();\r
\r
- AcquireMpContextControl ();\r
+ AcquireMpSpinLock (&mDebugMpContext.MpContextSpinLock);\r
\r
for (Index = 0; Index < mDebugCpuData.CpuCount; Index ++) {\r
if (mDebugCpuData.ApicID[Index] == LocalApicID) {\r
mDebugCpuData.CpuCount ++ ;\r
}\r
\r
- ReleaseMpContextControl ();\r
+ ReleaseMpSpinLock (&mDebugMpContext.MpContextSpinLock);\r
\r
return Index;\r
}\r
{\r
if (AsmMsrBitFieldRead64 (MSR_IA32_APIC_BASE_ADDRESS, 8, 8) == 1) {\r
if (mDebugMpContext.BspIndex != ProcessorIndex) {\r
- AcquireMpContextControl ();\r
+ AcquireMpSpinLock (&mDebugMpContext.MpContextSpinLock);\r
mDebugMpContext.BspIndex = ProcessorIndex;\r
- ReleaseMpContextControl ();\r
+ ReleaseMpSpinLock (&mDebugMpContext.MpContextSpinLock);\r
}\r
return TRUE;\r
} else {\r
UINT8 Value;\r
UINTN Index;\r
\r
- AcquireMpContextControl ();\r
+ AcquireMpSpinLock (&mDebugMpContext.MpContextSpinLock);\r
\r
Value = mDebugMpContext.CpuStopStatusMask[ProcessorIndex / 8];\r
Index = ProcessorIndex % 8;\r
}\r
mDebugMpContext.CpuStopStatusMask[ProcessorIndex / 8] = Value;\r
\r
- ReleaseMpContextControl ();\r
+ ReleaseMpSpinLock (&mDebugMpContext.MpContextSpinLock);\r
}\r
\r
/**\r
UINT8 Value;\r
UINTN Index;\r
\r
- AcquireMpContextControl ();\r
+ AcquireMpSpinLock (&mDebugMpContext.MpContextSpinLock);\r
\r
Value = mDebugMpContext.CpuBreakMask[ProcessorIndex / 8];\r
Index = ProcessorIndex % 8;\r
}\r
mDebugMpContext.CpuBreakMask[ProcessorIndex / 8] = Value;\r
\r
- ReleaseMpContextControl ();\r
+ ReleaseMpSpinLock (&mDebugMpContext.MpContextSpinLock);\r
}\r
\r
/**\r
IN BOOLEAN RunningFlag\r
)\r
{\r
- AcquireMpContextControl ();\r
-\r
+ AcquireMpSpinLock (&mDebugMpContext.MpContextSpinLock);\r
mDebugMpContext.RunCommandSet = RunningFlag;\r
-\r
- ReleaseMpContextControl ();\r
+ ReleaseMpSpinLock (&mDebugMpContext.MpContextSpinLock);\r
}\r
\r
/**\r
IN UINT32 ProcessorIndex\r
)\r
{\r
- AcquireMpContextControl ();\r
-\r
+ AcquireMpSpinLock (&mDebugMpContext.MpContextSpinLock);\r
mDebugMpContext.ViewPointIndex = ProcessorIndex;\r
-\r
- ReleaseMpContextControl ();\r
+ ReleaseMpSpinLock (&mDebugMpContext.MpContextSpinLock);\r
}\r
\r
/**\r
IN BOOLEAN IpiSentByApFlag\r
)\r
{\r
- AcquireMpContextControl ();\r
-\r
+ AcquireMpSpinLock (&mDebugMpContext.MpContextSpinLock);\r
mDebugMpContext.IpiSentByAp = IpiSentByApFlag;\r
-\r
- ReleaseMpContextControl ();\r
+ ReleaseMpSpinLock (&mDebugMpContext.MpContextSpinLock);\r
}\r
\r
/**\r
)\r
{\r
UINT32 Index;\r
- \r
+\r
for (Index = 0; Index < DEBUG_CPU_MAX_COUNT / 8; Index ++) {\r
if (mDebugMpContext.CpuBreakMask[Index] != 0) {\r
return (UINT32) LowBitSet32 (mDebugMpContext.CpuBreakMask[Index]) + Index * 8;\r
}\r
return (UINT32)-1;\r
}\r
- \r
+\r
/**\r
Check if all processors are in running status.\r
\r
)\r
{\r
UINTN Index;\r
- \r
+\r
for (Index = 0; Index < DEBUG_CPU_MAX_COUNT / 8; Index ++) {\r
if (mDebugMpContext.CpuStopStatusMask[Index] != 0) {\r
return FALSE;\r
/**\r
Check if the current processor is the first breaking processor.\r
\r
- If yes, halt other processors. \r
- \r
+ If yes, halt other processors.\r
+\r
@param[in] ProcessorIndex Processor index value.\r
- \r
+\r
@return TRUE This processor is the first breaking processor.\r
@return FALSE This processor is not the first breaking processor.\r
- \r
+\r
**/\r
BOOLEAN\r
IsFirstBreakProcessor (\r
IN UINT32 ProcessorIndex\r
)\r
{\r
- if (MultiProcessorDebugSupport) {\r
+ if (MultiProcessorDebugSupport()) {\r
if (mDebugMpContext.BreakAtCpuIndex != (UINT32) -1) {\r
//\r
// The current processor is not the first breaking one.\r
}\r
}\r
return TRUE;\r
-} \r
+}\r
\r