]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/DebugMp.c
This revision can only work with Intel(c) UDK Debugger Tool version 1.3 or greater...
[mirror_edk2.git] / SourceLevelDebugPkg / Library / DebugAgent / DebugAgentCommon / DebugMp.c
index d7df6ad20ddd4271b7ad0120ee7f2762c6fd1392..6c729986cd47672f5e0ecffa2533a21e60016e7a 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Multi-Processor support functions implementation.\r
 \r
-  Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2010 - 2013, 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
+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
 \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
@@ -43,51 +46,21 @@ AcquireDebugPortControl (
 }\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
@@ -136,7 +109,7 @@ GetProcessorIndex (
 \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
@@ -149,7 +122,7 @@ GetProcessorIndex (
     mDebugCpuData.CpuCount ++ ;\r
   }\r
 \r
-  ReleaseMpContextControl ();\r
+  ReleaseMpSpinLock (&mDebugMpContext.MpContextSpinLock);\r
 \r
   return Index;\r
 }\r
@@ -170,9 +143,9 @@ IsBsp (
 {\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
@@ -197,7 +170,7 @@ SetCpuStopFlagByIndex (
   UINT8                 Value;\r
   UINTN                 Index;\r
 \r
-  AcquireMpContextControl ();\r
+  AcquireMpSpinLock (&mDebugMpContext.MpContextSpinLock);\r
 \r
   Value = mDebugMpContext.CpuStopStatusMask[ProcessorIndex / 8];\r
   Index = ProcessorIndex % 8;\r
@@ -208,7 +181,7 @@ SetCpuStopFlagByIndex (
   }\r
   mDebugMpContext.CpuStopStatusMask[ProcessorIndex / 8] = Value;\r
 \r
-  ReleaseMpContextControl ();\r
+  ReleaseMpSpinLock (&mDebugMpContext.MpContextSpinLock);\r
 }\r
 \r
 /**\r
@@ -228,7 +201,7 @@ SetCpuBreakFlagByIndex (
   UINT8                 Value;\r
   UINTN                 Index;\r
 \r
-  AcquireMpContextControl ();\r
+  AcquireMpSpinLock (&mDebugMpContext.MpContextSpinLock);\r
 \r
   Value = mDebugMpContext.CpuBreakMask[ProcessorIndex / 8];\r
   Index = ProcessorIndex % 8;\r
@@ -239,7 +212,7 @@ SetCpuBreakFlagByIndex (
   }\r
   mDebugMpContext.CpuBreakMask[ProcessorIndex / 8] = Value;\r
 \r
-  ReleaseMpContextControl ();\r
+  ReleaseMpSpinLock (&mDebugMpContext.MpContextSpinLock);\r
 }\r
 \r
 /**\r
@@ -279,11 +252,9 @@ SetCpuRunningFlag (
   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
@@ -297,11 +268,9 @@ SetDebugViewPoint (
   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
@@ -316,11 +285,9 @@ SetIpiSentByApFlag (
   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
@@ -384,7 +351,7 @@ IsFirstBreakProcessor (
   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