From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by ml01.01.org (Postfix) with ESMTP id 30F3A1A1E0F for ; Tue, 2 Aug 2016 02:00:21 -0700 (PDT) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga101.fm.intel.com with ESMTP; 02 Aug 2016 02:00:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.28,459,1464678000"; d="scan'208";a="743019232" Received: from jfan12-desk.ccr.corp.intel.com ([10.239.9.5]) by FMSMGA003.fm.intel.com with ESMTP; 02 Aug 2016 02:00:20 -0700 From: Jeff Fan To: edk2-devel@lists.01.org Cc: Michael Kinney , Feng Tian , Giri P Mudusuru , Laszlo Ersek Date: Tue, 2 Aug 2016 16:59:21 +0800 Message-Id: <1470128388-17960-22-git-send-email-jeff.fan@intel.com> X-Mailer: git-send-email 2.7.4.windows.1 In-Reply-To: <1470128388-17960-1-git-send-email-jeff.fan@intel.com> References: <1470128388-17960-1-git-send-email-jeff.fan@intel.com> Subject: [Patch v5 21/48] UefiCpuPkg/MpInitLib: Fill MP_CPU_EXCHANGE_INFO fields 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: Tue, 02 Aug 2016 09:00:21 -0000 FillExchangeInfoData() is used to fill MP_CPU_EXCHANGE_INFO date exchanged between C code and assembly code of AP reset vector. v5: 1. Reference ApWakeupFunction instead of ApCFunction. 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 | 79 ++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpInitLib/MpLib.c index a4a2c44..d081111 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -17,6 +17,47 @@ EFI_GUID mCpuInitMpLibHobGuid = CPU_INIT_MP_LIB_HOB_GUID; /** + The function will check if BSP Execute Disable is enabled. + DxeIpl may have enabled Execute Disable for BSP, + APs need to get the status and sync up the settings. + + @retval TRUE BSP Execute Disable is enabled. + @retval FALSE BSP Execute Disable is not enabled. +**/ +BOOLEAN +IsBspExecuteDisableEnabled ( + VOID + ) +{ + UINT32 Eax; + CPUID_EXTENDED_CPU_SIG_EDX Edx; + MSR_IA32_EFER_REGISTER EferMsr; + BOOLEAN Enabled; + + Enabled = FALSE; + AsmCpuid (CPUID_EXTENDED_FUNCTION, &Eax, NULL, NULL, NULL); + if (Eax >= CPUID_EXTENDED_CPU_SIG) { + AsmCpuid (CPUID_EXTENDED_CPU_SIG, NULL, NULL, NULL, &Edx.Uint32); + // + // CPUID 0x80000001 + // Bit 20: Execute Disable Bit available. + // + if (Edx.Bits.NX != 0) { + EferMsr.Uint64 = AsmReadMsr64 (MSR_IA32_EFER); + // + // MSR 0xC0000080 + // Bit 11: Execute Disable Bit enable. + // + if (EferMsr.Bits.NXE != 0) { + Enabled = TRUE; + } + } + } + + return Enabled; +} + +/** Get the Application Processors state. @param[in] CpuData The pointer to CPU_AP_DATA of specified AP @@ -407,6 +448,44 @@ ApWakeupFunction ( } /** + This function will fill the exchange info structure. + + @param[in] CpuMpData Pointer to CPU MP Data + +**/ +VOID +FillExchangeInfoData ( + IN CPU_MP_DATA *CpuMpData + ) +{ + volatile MP_CPU_EXCHANGE_INFO *ExchangeInfo; + + ExchangeInfo = CpuMpData->MpCpuExchangeInfo; + ExchangeInfo->Lock = 0; + ExchangeInfo->StackStart = CpuMpData->Buffer; + ExchangeInfo->StackSize = CpuMpData->CpuApStackSize; + ExchangeInfo->BufferStart = CpuMpData->WakeupBuffer; + ExchangeInfo->ModeOffset = CpuMpData->AddressMap.ModeEntryOffset; + + ExchangeInfo->CodeSegment = AsmReadCs (); + ExchangeInfo->DataSegment = AsmReadDs (); + + ExchangeInfo->Cr3 = AsmReadCr3 (); + + ExchangeInfo->CFunction = (UINTN) ApWakeupFunction; + ExchangeInfo->NumApsExecuting = 0; + ExchangeInfo->CpuMpData = CpuMpData; + + ExchangeInfo->EnableExecuteDisable = IsBspExecuteDisableEnabled (); + + // + // Get the BSP's data of GDT and IDT + // + AsmReadGdtr ((IA32_DESCRIPTOR *) &ExchangeInfo->GdtrProfile); + AsmReadIdtr ((IA32_DESCRIPTOR *) &ExchangeInfo->IdtrProfile); +} + +/** MP Initialize Library initialization. This service will allocate AP reset vector and wakeup all APs to do APs -- 2.7.4.windows.1