From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 9FC741A1E4B for ; Wed, 24 Aug 2016 07:45:35 -0700 (PDT) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga105.jf.intel.com with ESMTP; 24 Aug 2016 07:45:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.28,570,1464678000"; d="scan'208";a="160352252" Received: from jfan12-desk.ccr.corp.intel.com ([10.239.9.5]) by fmsmga004.fm.intel.com with ESMTP; 24 Aug 2016 07:45:34 -0700 From: Jeff Fan To: edk2-devel@lists.01.org Cc: Michael Kinney , Feng Tian Date: Wed, 24 Aug 2016 22:45:24 +0800 Message-Id: <1472049924-8228-7-git-send-email-jeff.fan@intel.com> X-Mailer: git-send-email 2.7.4.windows.1 In-Reply-To: <1472049924-8228-1-git-send-email-jeff.fan@intel.com> References: <1472049924-8228-1-git-send-email-jeff.fan@intel.com> Subject: [Patch 6/6] UefiCpuPkg/MpInitLib: Don't allocate reset vector in Exit Boot Service 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: Wed, 24 Aug 2016 14:45:35 -0000 In Exit Boot Services callback function, we cannot use allocate memory services because it may change the memory map that has been gotten by OS. This fix is not to allocate reset vector buffer after SaveRestoreFlag is set to TRUE in MpInitExitBootServicesCallback(). Instead AllocateResetVector() will use the previous allocated buffer address and save the contents before copying reset vector code. At the same time, FreeResetVector() will restore original contents after if SaveRestoreFlag is TRUE. Cc: Michael Kinney Cc: Feng Tian Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jeff Fan --- UefiCpuPkg/Library/MpInitLib/DxeMpLib.c | 68 +++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 29 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c index e459ebc..50b5b27 100644 --- a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c @@ -66,29 +66,33 @@ AllocateResetVector ( UINTN ApResetVectorSize; EFI_PHYSICAL_ADDRESS StartAddress; - ApResetVectorSize = CpuMpData->AddressMap.RendezvousFunnelSize + - sizeof (MP_CPU_EXCHANGE_INFO); - - StartAddress = BASE_1MB; - Status = gBS->AllocatePages ( - AllocateMaxAddress, - EfiACPIMemoryNVS, - EFI_SIZE_TO_PAGES (ApResetVectorSize), - &StartAddress - ); - ASSERT_EFI_ERROR (Status); - - CpuMpData->WakeupBuffer = (UINTN) StartAddress; - CpuMpData->MpCpuExchangeInfo = (MP_CPU_EXCHANGE_INFO *) (UINTN) + if (CpuMpData->SaveRestoreFlag) { + BackupAndPrepareWakeupBuffer (CpuMpData); + } else { + ApResetVectorSize = CpuMpData->AddressMap.RendezvousFunnelSize + + sizeof (MP_CPU_EXCHANGE_INFO); + + StartAddress = BASE_1MB; + Status = gBS->AllocatePages ( + AllocateMaxAddress, + EfiACPIMemoryNVS, + EFI_SIZE_TO_PAGES (ApResetVectorSize), + &StartAddress + ); + ASSERT_EFI_ERROR (Status); + + CpuMpData->WakeupBuffer = (UINTN) StartAddress; + CpuMpData->MpCpuExchangeInfo = (MP_CPU_EXCHANGE_INFO *) (UINTN) (CpuMpData->WakeupBuffer + CpuMpData->AddressMap.RendezvousFunnelSize); - // - // copy AP reset code in it - // - CopyMem ( - (VOID *) CpuMpData->WakeupBuffer, - (VOID *) CpuMpData->AddressMap.RendezvousFunnelAddress, - CpuMpData->AddressMap.RendezvousFunnelSize - ); + // + // copy AP reset code in it + // + CopyMem ( + (VOID *) CpuMpData->WakeupBuffer, + (VOID *) CpuMpData->AddressMap.RendezvousFunnelAddress, + CpuMpData->AddressMap.RendezvousFunnelSize + ); + } } /** @@ -103,13 +107,18 @@ FreeResetVector ( { EFI_STATUS Status; UINTN ApResetVectorSize; - ApResetVectorSize = CpuMpData->AddressMap.RendezvousFunnelSize + - sizeof (MP_CPU_EXCHANGE_INFO); - Status = gBS->FreePages( - (EFI_PHYSICAL_ADDRESS)CpuMpData->WakeupBuffer, - EFI_SIZE_TO_PAGES (ApResetVectorSize) - ); - ASSERT_EFI_ERROR (Status); + + if (CpuMpData->SaveRestoreFlag) { + RestoreWakeupBuffer (CpuMpData); + } else { + ApResetVectorSize = CpuMpData->AddressMap.RendezvousFunnelSize + + sizeof (MP_CPU_EXCHANGE_INFO); + Status = gBS->FreePages( + (EFI_PHYSICAL_ADDRESS)CpuMpData->WakeupBuffer, + EFI_SIZE_TO_PAGES (ApResetVectorSize) + ); + ASSERT_EFI_ERROR (Status); + } } /** @@ -260,6 +269,7 @@ MpInitExitBootServicesCallback ( CPU_MP_DATA *CpuMpData; CpuMpData = GetCpuMpData (); + CpuMpData->SaveRestoreFlag = TRUE; CpuMpData->PmCodeSegment = GetProtectedModeCS (); CpuMpData->ApLoopMode = PcdGet8 (PcdCpuApLoopMode); WakeUpAP (CpuMpData, TRUE, 0, RelocateApLoop, mReservedApLoopFunc); -- 2.7.4.windows.1