public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Jeff Fan <jeff.fan@intel.com>
To: edk2-devel@lists.01.org
Cc: Feng Tian <feng.tian@intel.com>,
	Michael D Kinney <michael.d.kinney@intel.com>
Subject: [PATCH 3/6] UefiCpuPkg/MpInitLib: Remove CPU information from CPU_AP_DATA
Date: Mon, 14 Nov 2016 11:46:58 +0800	[thread overview]
Message-ID: <20161114034701.5996-4-jeff.fan@intel.com> (raw)
In-Reply-To: <20161114034701.5996-1-jeff.fan@intel.com>

Some CPU information (InitialApicId/ApicId/Health) are duplicated in CPU_AP_DATA
and CPU_INFO_IN_HOB.

This update is to remove the ones from CPU_AP_DATA and update MpInitLib to
consume the ones from CPU_INFO_IN_HOB.

Cc: Feng Tian <feng.tian@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan <jeff.fan@intel.com>
---
 UefiCpuPkg/Library/MpInitLib/MpLib.c | 73 +++++++++++++++++++-----------------
 UefiCpuPkg/Library/MpInitLib/MpLib.h |  3 --
 2 files changed, 39 insertions(+), 37 deletions(-)

diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpInitLib/MpLib.c
index 9641e5e..dc4216c 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
@@ -253,7 +253,7 @@ SortApicId (
   UINTN             Index2;
   UINTN             Index3;
   UINT32            ApicId;
-  CPU_AP_DATA       CpuData;
+  CPU_INFO_IN_HOB   CpuInfo;
   UINT32            ApCount;
   CPU_INFO_IN_HOB   *CpuInfoInHob;
 
@@ -265,21 +265,22 @@ SortApicId (
       //
       // Sort key is the hardware default APIC ID
       //
-      ApicId = CpuMpData->CpuData[Index1].ApicId;
+      CpuInfoInHob = (CPU_INFO_IN_HOB *) (UINTN) CpuMpData->CpuInfoInHob;
+      ApicId = CpuInfoInHob[Index1].ApicId;
       for (Index2 = Index1 + 1; Index2 <= ApCount; Index2++) {
-        if (ApicId > CpuMpData->CpuData[Index2].ApicId) {
+        if (ApicId > CpuInfoInHob[Index2].ApicId) {
           Index3 = Index2;
-          ApicId = CpuMpData->CpuData[Index2].ApicId;
+          ApicId = CpuInfoInHob[Index2].ApicId;
         }
       }
       if (Index3 != Index1) {
-        CopyMem (&CpuData, &CpuMpData->CpuData[Index3], sizeof (CPU_AP_DATA));
+        CopyMem (&CpuInfo, &CpuInfoInHob[Index3], sizeof (CPU_INFO_IN_HOB));
         CopyMem (
-          &CpuMpData->CpuData[Index3],
-          &CpuMpData->CpuData[Index1],
-          sizeof (CPU_AP_DATA)
+          &CpuInfoInHob[Index3],
+          &CpuInfoInHob[Index1],
+          sizeof (CPU_INFO_IN_HOB)
           );
-        CopyMem (&CpuMpData->CpuData[Index1], &CpuData, sizeof (CPU_AP_DATA));
+        CopyMem (&CpuInfoInHob[Index1], &CpuInfo, sizeof (CPU_INFO_IN_HOB));
       }
     }
 
@@ -288,18 +289,11 @@ SortApicId (
     //
     ApicId = GetInitialApicId ();
     for (Index1 = 0; Index1 < CpuMpData->CpuCount; Index1++) {
-      if (CpuMpData->CpuData[Index1].ApicId == ApicId) {
+      if (CpuInfoInHob[Index1].ApicId == ApicId) {
         CpuMpData->BspNumber = (UINT32) Index1;
         break;
       }
     }
-
-    CpuInfoInHob = (CPU_INFO_IN_HOB *) (UINTN) CpuMpData->CpuInfoInHob;
-    for (Index1 = 0; Index1 < CpuMpData->CpuCount; Index1++) {
-      CpuInfoInHob[Index1].InitialApicId = CpuMpData->CpuData[Index1].InitialApicId;
-      CpuInfoInHob[Index1].ApicId        = CpuMpData->CpuData[Index1].ApicId;
-      CpuInfoInHob[Index1].Health        = CpuMpData->CpuData[Index1].Health;
-    }
   }
 }
 
@@ -358,10 +352,13 @@ GetProcessorNumber (
 {
   UINTN                   TotalProcessorNumber;
   UINTN                   Index;
+  CPU_INFO_IN_HOB         *CpuInfoInHob;
+
+  CpuInfoInHob = (CPU_INFO_IN_HOB *) (UINTN) CpuMpData->CpuInfoInHob;
 
   TotalProcessorNumber = CpuMpData->CpuCount;
   for (Index = 0; Index < TotalProcessorNumber; Index ++) {
-    if (CpuMpData->CpuData[Index].ApicId == GetApicId ()) {
+    if (CpuInfoInHob[Index].ApicId == GetApicId ()) {
       *ProcessorNumber = Index;
       return EFI_SUCCESS;
     }
@@ -439,12 +436,16 @@ InitializeApData (
   IN     UINT32           BistData
   )
 {
+  CPU_INFO_IN_HOB          *CpuInfoInHob;
+
+  CpuInfoInHob = (CPU_INFO_IN_HOB *) (UINTN) CpuMpData->CpuInfoInHob;
+  CpuInfoInHob[ProcessorNumber].InitialApicId = GetInitialApicId ();
+  CpuInfoInHob[ProcessorNumber].ApicId        = GetApicId ();
+  CpuInfoInHob[ProcessorNumber].Health        = BistData;
+
   CpuMpData->CpuData[ProcessorNumber].Waiting    = FALSE;
-  CpuMpData->CpuData[ProcessorNumber].Health     = BistData;
   CpuMpData->CpuData[ProcessorNumber].CpuHealthy = (BistData == 0) ? TRUE : FALSE;
-  CpuMpData->CpuData[ProcessorNumber].ApicId     = GetApicId ();
-  CpuMpData->CpuData[ProcessorNumber].InitialApicId = GetInitialApicId ();
-  if (CpuMpData->CpuData[ProcessorNumber].InitialApicId >= 0xFF) {
+  if (CpuInfoInHob[ProcessorNumber].InitialApicId >= 0xFF) {
     //
     // Set x2APIC mode if there are any logical processor reporting
     // an Initial APIC ID of 255 or greater.
@@ -477,6 +478,7 @@ ApWakeupFunction (
   VOID                       *Parameter;
   UINT32                     BistData;
   volatile UINT32            *ApStartupSignalBuffer;
+  CPU_INFO_IN_HOB            *CpuInfoInHob;
 
   //
   // AP finished assembly code and begin to execute C code
@@ -547,8 +549,9 @@ ApWakeupFunction (
             //
             // Re-get the CPU APICID and Initial APICID
             //
-            CpuMpData->CpuData[ProcessorNumber].ApicId        = GetApicId ();
-            CpuMpData->CpuData[ProcessorNumber].InitialApicId = GetInitialApicId ();
+            CpuInfoInHob = (CPU_INFO_IN_HOB *) (UINTN) CpuMpData->CpuInfoInHob;
+            CpuInfoInHob[ProcessorNumber].ApicId        = GetApicId ();
+            CpuInfoInHob[ProcessorNumber].InitialApicId = GetInitialApicId ();
           }
         }
         SetApState (&CpuMpData->CpuData[ProcessorNumber], CpuStateFinished);
@@ -696,6 +699,7 @@ WakeUpAP (
   UINTN                            Index;
   CPU_AP_DATA                      *CpuData;
   BOOLEAN                          ResetVectorRequired;
+  CPU_INFO_IN_HOB                  *CpuInfoInHob;
 
   CpuMpData->FinishedCount = 0;
   ResetVectorRequired = FALSE;
@@ -760,8 +764,9 @@ WakeUpAP (
     ASSERT (CpuMpData->InitFlag != ApInitConfig);
     *(UINT32 *) CpuData->StartupApSignal = WAKEUP_AP_SIGNAL;
     if (ResetVectorRequired) {
+      CpuInfoInHob = (CPU_INFO_IN_HOB *) (UINTN) CpuMpData->CpuInfoInHob;
       SendInitSipiSipi (
-        CpuData->ApicId,
+        CpuInfoInHob[ProcessorNumber].ApicId,
         (UINT32) ExchangeInfo->BufferStart
         );
     }
@@ -1229,16 +1234,14 @@ MpInitLibInitialize (
     CpuMpData->CpuCount  = OldCpuMpData->CpuCount;
     CpuMpData->BspNumber = OldCpuMpData->BspNumber;
     CpuMpData->InitFlag  = ApInitReconfig;
-    CpuInfoInHob = (CPU_INFO_IN_HOB *) (UINTN) OldCpuMpData->CpuInfoInHob;
+    CpuMpData->CpuInfoInHob = OldCpuMpData->CpuInfoInHob;
+    CpuInfoInHob = (CPU_INFO_IN_HOB *) (UINTN) CpuMpData->CpuInfoInHob;
     for (Index = 0; Index < CpuMpData->CpuCount; Index++) {
       InitializeSpinLock(&CpuMpData->CpuData[Index].ApLock);
-      CpuMpData->CpuData[Index].ApicId        = CpuInfoInHob[Index].ApicId;
-      CpuMpData->CpuData[Index].InitialApicId = CpuInfoInHob[Index].InitialApicId;
-      if (CpuMpData->CpuData[Index].InitialApicId >= 255) {
+      if (CpuInfoInHob[Index].InitialApicId >= 255) {
         CpuMpData->X2ApicEnable = TRUE;
       }
-      CpuMpData->CpuData[Index].Health     = CpuInfoInHob[Index].Health;
-      CpuMpData->CpuData[Index].CpuHealthy = (CpuMpData->CpuData[Index].Health == 0)? TRUE:FALSE;
+      CpuMpData->CpuData[Index].CpuHealthy = (CpuInfoInHob[Index].Health == 0)? TRUE:FALSE;
       CpuMpData->CpuData[Index].ApFunction = 0;
       CopyMem (
         &CpuMpData->CpuData[Index].VolatileRegisters,
@@ -1299,8 +1302,10 @@ MpInitLibGetProcessorInfo (
 {
   CPU_MP_DATA            *CpuMpData;
   UINTN                  CallerNumber;
+  CPU_INFO_IN_HOB        *CpuInfoInHob;
 
   CpuMpData = GetCpuMpData ();
+  CpuInfoInHob = (CPU_INFO_IN_HOB *) (UINTN) CpuMpData->CpuInfoInHob;
 
   //
   // Check whether caller processor is BSP
@@ -1318,7 +1323,7 @@ MpInitLibGetProcessorInfo (
     return EFI_NOT_FOUND;
   }
 
-  ProcessorInfoBuffer->ProcessorId = (UINT64) CpuMpData->CpuData[ProcessorNumber].ApicId;
+  ProcessorInfoBuffer->ProcessorId = (UINT64) CpuInfoInHob[ProcessorNumber].ApicId;
   ProcessorInfoBuffer->StatusFlag  = 0;
   if (ProcessorNumber == CpuMpData->BspNumber) {
     ProcessorInfoBuffer->StatusFlag |= PROCESSOR_AS_BSP_BIT;
@@ -1336,14 +1341,14 @@ MpInitLibGetProcessorInfo (
   // Get processor location information
   //
   GetProcessorLocationByApicId (
-    CpuMpData->CpuData[ProcessorNumber].ApicId,
+    CpuInfoInHob[ProcessorNumber].ApicId,
     &ProcessorInfoBuffer->Location.Package,
     &ProcessorInfoBuffer->Location.Core,
     &ProcessorInfoBuffer->Location.Thread
     );
 
   if (HealthData != NULL) {
-    HealthData->Uint32 = CpuMpData->CpuData[ProcessorNumber].Health;
+    HealthData->Uint32 = CpuInfoInHob[ProcessorNumber].Health;
   }
 
   return EFI_SUCCESS;
diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpInitLib/MpLib.h
index ae78c59..f107b6d 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.h
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h
@@ -112,9 +112,6 @@ typedef struct {
   volatile UINT32                *StartupApSignal;
   volatile UINTN                 ApFunction;
   volatile UINTN                 ApFunctionArgument;
-  UINT32                         InitialApicId;
-  UINT32                         ApicId;
-  UINT32                         Health;
   BOOLEAN                        CpuHealthy;
   volatile CPU_STATE             State;
   CPU_VOLATILE_REGISTERS         VolatileRegisters;
-- 
2.9.3.windows.2



  parent reply	other threads:[~2016-11-14  3:47 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-14  3:46 [PATCH 0/6] UefiCpuPkg/MpInitLib: Program AP stack in fixed address Jeff Fan
2016-11-14  3:46 ` [PATCH 1/6] UefiCpuPkg/MpInitLib: Fixed offset error on Cr3Location Jeff Fan
2016-11-14  3:46 ` [PATCH 2/6] UefiCpuPkg/MpInitLib: Force sending INIT-SIPI-SIPI to reset APs Jeff Fan
2016-11-14  3:46 ` Jeff Fan [this message]
2016-11-14  3:46 ` [PATCH 4/6] UefiCpuPkg/MpInitLib: Add InitFlag and CpuInfo in MP_CPU_EXCHANGE_INFO Jeff Fan
2016-11-14  3:47 ` [PATCH 5/6] UefiCpuPkg/MpInitLib: Program AP stack in fixed address Jeff Fan
2016-11-14  3:47 ` [PATCH 6/6] UefiCpuPkg/MpInitLib: Update AP information when BSP switched Jeff Fan
2016-11-16  8:00 ` [PATCH 0/6] UefiCpuPkg/MpInitLib: Program AP stack in fixed address Tian, Feng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161114034701.5996-4-jeff.fan@intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox