From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by ml01.01.org (Postfix) with ESMTP id 562A91A1E3D for ; Fri, 29 Jul 2016 11:15:34 -0700 (PDT) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga103.jf.intel.com with ESMTP; 29 Jul 2016 11:15:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.28,440,1464678000"; d="scan'208";a="1016339087" Received: from jfan12-desk.ccr.corp.intel.com ([10.239.9.5]) by fmsmga001.fm.intel.com with ESMTP; 29 Jul 2016 11:15:33 -0700 From: Jeff Fan To: edk2-devel@ml01.01.org Cc: Michael Kinney , Feng Tian , Giri P Mudusuru , Laszlo Ersek Date: Sat, 30 Jul 2016 02:14:39 +0800 Message-Id: <1469816112-8200-14-git-send-email-jeff.fan@intel.com> X-Mailer: git-send-email 2.7.4.windows.1 In-Reply-To: <1469816112-8200-1-git-send-email-jeff.fan@intel.com> References: <1469816112-8200-1-git-send-email-jeff.fan@intel.com> Subject: [Patch v4 13/46] UefiCpuPkg/MpInitLib: Initialize CPU_AP_DATA for CPU APs X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Jul 2016 18:15:34 -0000 Initialize CPU_AP_DATA for CPU APs and add GetApState()/SetApState() helper functions to get/set AP state. Cc: Michael Kinney Cc: Feng Tian Cc: Giri P Mudusuru Cc: Laszlo Ersek Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jeff Fan --- UefiCpuPkg/Library/MpInitLib/MpLib.c | 76 ++++++++++++++++++++++++++++++++++++ UefiCpuPkg/Library/MpInitLib/MpLib.h | 12 ++++++ 2 files changed, 88 insertions(+) diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpInitLib/MpLib.c index f05db7c..70e5eb1 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -14,6 +14,37 @@ #include "MpLib.h" +/** + Get the Application Processors state. + + @param[in] CpuData The pointer to CPU_AP_DATA of specified AP + + @return The AP status +**/ +CPU_STATE +GetApState ( + IN CPU_AP_DATA *CpuData + ) +{ + return CpuData->State; +} + +/** + Set the Application Processors state. + + @param[in] CpuData The pointer to CPU_AP_DATA of specified AP + @param[in] State The AP status +**/ +VOID +SetApState ( + IN CPU_AP_DATA *CpuData, + IN CPU_STATE State + ) +{ + AcquireSpinLock (&CpuData->ApLock); + CpuData->State = State; + ReleaseSpinLock (&CpuData->ApLock); +} /** Detect whether Mwait-monitor feature is supported. @@ -74,6 +105,40 @@ GetApLoopMode ( return ApLoopMode; } +/* + Initialize CPU AP Data when AP is wakeup at the first time. + + @param[in, out] CpuMpData Pointer to PEI CPU MP Data + @param[in] ProcessorNumber The handle number of processor + @param[in] BistData Processor BIST data + +**/ +VOID +InitializeApData ( + IN OUT CPU_MP_DATA *CpuMpData, + IN UINTN ProcessorNumber, + IN UINT32 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) { + // + // Set x2APIC mode if there are any logical processor reporting + // an Initial APIC ID of 255 or greater. + // + AcquireSpinLock(&CpuMpData->MpLock); + CpuMpData->X2ApicEnable = TRUE; + ReleaseSpinLock(&CpuMpData->MpLock); + } + + InitializeSpinLock(&CpuMpData->CpuData[ProcessorNumber].ApLock); + SetApState (&CpuMpData->CpuData[ProcessorNumber], CpuStateIdle); +} + /** MP Initialize Library initialization. @@ -103,6 +168,7 @@ MpInitLibInitialize ( CPU_MP_DATA *CpuMpData; UINT8 ApLoopMode; UINT8 *MonitorBuffer; + UINTN Index; UINTN ApResetVectorSize; UINTN BackupBufferAddr; MaxLogicalProcessorNumber = PcdGet32(PcdCpuMaxLogicalProcessorNumber); @@ -138,6 +204,10 @@ MpInitLibInitialize ( CpuMpData->CpuInfoInHob = (UINT64) (UINTN) (CpuMpData->CpuData + MaxLogicalProcessorNumber); InitializeSpinLock(&CpuMpData->MpLock); // + // Set BSP basic information + // + InitializeApData (CpuMpData, 0, 0); + // // Save assembly code information // CopyMem (&CpuMpData->AddressMap, &AddressMap, sizeof (MP_ASSEMBLY_ADDRESS_MAP)); @@ -147,6 +217,12 @@ MpInitLibInitialize ( CpuMpData->ApLoopMode = ApLoopMode; DEBUG ((DEBUG_INFO, "AP Loop Mode is %d\n", CpuMpData->ApLoopMode)); // + // Set up APs wakeup signal buffer + // + for (Index = 0; Index < MaxLogicalProcessorNumber; Index++) { + CpuMpData->CpuData[Index].StartupApSignal = + (UINT32 *)(MonitorBuffer + MonitorFilterSize * Index); + } // Store BSP's MTRR setting // MtrrGetAllMtrrs (&CpuMpData->MtrrTable); diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpInitLib/MpLib.h index 955de96..3f936c2 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h @@ -47,6 +47,17 @@ typedef enum { ApInitDone = 3 } AP_INIT_STATE; +// +// AP state +// +typedef enum { + CpuStateIdle, + CpuStateReady, + CpuStateBusy, + CpuStateFinished, + CpuStateDisabled +} CPU_STATE; + typedef struct { SPIN_LOCK ApLock; volatile UINT32 *StartupApSignal; @@ -56,6 +67,7 @@ typedef struct { UINT32 ApicId; UINT32 Health; BOOLEAN CpuHealthy; + volatile CPU_STATE State; BOOLEAN Waiting; BOOLEAN *Finished; UINT64 ExpectedTime; -- 2.7.4.windows.1