From nobody Fri Dec 27 02:42:39 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1502679637430968.332773020895; Sun, 13 Aug 2017 20:00:37 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 375BC21D0A265; Sun, 13 Aug 2017 19:58:12 -0700 (PDT) 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 A744021D0A244 for ; Sun, 13 Aug 2017 19:58:10 -0700 (PDT) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga105.jf.intel.com with ESMTP; 13 Aug 2017 20:00:33 -0700 Received: from shwdeopenpsi068.ccr.corp.intel.com ([10.239.9.12]) by fmsmga004.fm.intel.com with ESMTP; 13 Aug 2017 20:00:32 -0700 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.41,372,1498546800"; d="scan'208";a="299712105" From: Star Zeng To: edk2-devel@lists.01.org Date: Mon, 14 Aug 2017 11:00:30 +0800 Message-Id: <1502679630-119332-1-git-send-email-star.zeng@intel.com> X-Mailer: git-send-email 2.7.0.windows.1 Subject: [edk2] [PATCH] UefiCpuPkg MpInitLib: Save/restore original WakeupBuffer for DxeMpLib X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ruiyu Ni , Jeff Fan , Liming Gao , Star Zeng , Eric Dong MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Current code always allocates/frees < 1MB WakeupBuffer for DxeMpLib until ExitBootService, but the allocation may be failed at late phase of the boot. This patch is to always save/restore original WakeupBuffer for DxeMpLib, it is aligned with the solution for PeiMpLib at 9293d6e42e677e4a38e055258c0993ad8a9df14e, then AllocateResetVector() and FreeResetVector() will be common and moved to MpLib.c. Only difference is GetWakeupBuffer() that will be in PeiMpLib or DxeMpLib respectively. Cc: Liming Gao Cc: Ruiyu Ni Cc: Eric Dong Cc: Jeff Fan Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Star Zeng Reviewed-by: Liming Gao --- UefiCpuPkg/Library/MpInitLib/DxeMpLib.c | 84 ++++++++--------------- UefiCpuPkg/Library/MpInitLib/MpLib.c | 114 +++++++++++++++++++++-------= ---- UefiCpuPkg/Library/MpInitLib/MpLib.h | 43 +++--------- UefiCpuPkg/Library/MpInitLib/PeiMpLib.c | 36 ---------- 4 files changed, 109 insertions(+), 168 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c b/UefiCpuPkg/Library/M= pInitLib/DxeMpLib.c index b393244e0582..479f8189f655 100644 --- a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c @@ -75,72 +75,41 @@ SaveCpuMpData ( } =20 /** - Allocate reset vector buffer. + Get available system memory below 1MB by specified size. =20 - @param[in, out] CpuMpData The pointer to CPU MP Data structure. -**/ -VOID -AllocateResetVector ( - IN OUT CPU_MP_DATA *CpuMpData - ) -{ - EFI_STATUS Status; - UINTN ApResetVectorSize; - EFI_PHYSICAL_ADDRESS StartAddress; + @param[in] WakeupBufferSize Wakeup buffer size required =20 - if (CpuMpData->SaveRestoreFlag) { - BackupAndPrepareWakeupBuffer (CpuMpData); - } else { - ApResetVectorSize =3D CpuMpData->AddressMap.RendezvousFunnelSize + - sizeof (MP_CPU_EXCHANGE_INFO); - - StartAddress =3D BASE_1MB; - Status =3D gBS->AllocatePages ( - AllocateMaxAddress, - EfiACPIMemoryNVS, - EFI_SIZE_TO_PAGES (ApResetVectorSize), - &StartAddress - ); - ASSERT_EFI_ERROR (Status); - - CpuMpData->WakeupBuffer =3D (UINTN) StartAddress; - CpuMpData->MpCpuExchangeInfo =3D (MP_CPU_EXCHANGE_INFO *) (UINTN) - (CpuMpData->WakeupBuffer + CpuMpData->AddressMap.Rendezv= ousFunnelSize); - // - // copy AP reset code in it - // - CopyMem ( - (VOID *) CpuMpData->WakeupBuffer, - (VOID *) CpuMpData->AddressMap.RendezvousFunnelAddress, - CpuMpData->AddressMap.RendezvousFunnelSize - ); - } -} - -/** - Free AP reset vector buffer. - - @param[in] CpuMpData The pointer to CPU MP Data structure. + @retval other Return wakeup buffer address below 1MB. + @retval -1 Cannot find free memory below 1MB. **/ -VOID -FreeResetVector ( - IN CPU_MP_DATA *CpuMpData +UINTN +GetWakeupBuffer ( + IN UINTN WakeupBufferSize ) { - EFI_STATUS Status; - UINTN ApResetVectorSize; - - if (CpuMpData->SaveRestoreFlag) { - RestoreWakeupBuffer (CpuMpData); - } else { - ApResetVectorSize =3D CpuMpData->AddressMap.RendezvousFunnelSize + - sizeof (MP_CPU_EXCHANGE_INFO); + EFI_STATUS Status; + EFI_PHYSICAL_ADDRESS StartAddress; + + StartAddress =3D BASE_1MB; + Status =3D gBS->AllocatePages ( + AllocateMaxAddress, + EfiBootServicesData, + EFI_SIZE_TO_PAGES (WakeupBufferSize), + &StartAddress + ); + ASSERT_EFI_ERROR (Status); + if (!EFI_ERROR (Status)) { Status =3D gBS->FreePages( - (EFI_PHYSICAL_ADDRESS)CpuMpData->WakeupBuffer, - EFI_SIZE_TO_PAGES (ApResetVectorSize) + StartAddress, + EFI_SIZE_TO_PAGES (WakeupBufferSize) ); ASSERT_EFI_ERROR (Status); + DEBUG ((DEBUG_INFO, "WakeupBufferStart =3D %x, WakeupBufferSize =3D %x= \n", + (UINTN) StartAddress, WakeupBufferSize)); + } else { + StartAddress =3D (EFI_PHYSICAL_ADDRESS) -1; } + return (UINTN) StartAddress; } =20 /** @@ -299,7 +268,6 @@ MpInitChangeApLoopCallback ( CPU_MP_DATA *CpuMpData; =20 CpuMpData =3D GetCpuMpData (); - CpuMpData->SaveRestoreFlag =3D TRUE; CpuMpData->PmCodeSegment =3D GetProtectedModeCS (); CpuMpData->ApLoopMode =3D PcdGet8 (PcdCpuApLoopMode); mNumberToFinish =3D CpuMpData->CpuCount - 1; diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index a3eea29d6148..ed1f55e955c2 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -796,6 +796,81 @@ TimedWaitForApFinish ( ); =20 /** + Get available system memory below 1MB by specified size. + + @param[in] CpuMpData The pointer to CPU MP Data structure. +**/ +VOID +BackupAndPrepareWakeupBuffer( + IN CPU_MP_DATA *CpuMpData + ) +{ + CopyMem ( + (VOID *) CpuMpData->BackupBuffer, + (VOID *) CpuMpData->WakeupBuffer, + CpuMpData->BackupBufferSize + ); + CopyMem ( + (VOID *) CpuMpData->WakeupBuffer, + (VOID *) CpuMpData->AddressMap.RendezvousFunnelAddress, + CpuMpData->AddressMap.RendezvousFunnelSize + ); +} + +/** + Restore wakeup buffer data. + + @param[in] CpuMpData The pointer to CPU MP Data structure. +**/ +VOID +RestoreWakeupBuffer( + IN CPU_MP_DATA *CpuMpData + ) +{ + CopyMem ( + (VOID *) CpuMpData->WakeupBuffer, + (VOID *) CpuMpData->BackupBuffer, + CpuMpData->BackupBufferSize + ); +} + +/** + Allocate reset vector buffer. + + @param[in, out] CpuMpData The pointer to CPU MP Data structure. +**/ +VOID +AllocateResetVector ( + IN OUT CPU_MP_DATA *CpuMpData + ) +{ + UINTN ApResetVectorSize; + + if (CpuMpData->WakeupBuffer =3D=3D (UINTN) -1) { + ApResetVectorSize =3D CpuMpData->AddressMap.RendezvousFunnelSize + + sizeof (MP_CPU_EXCHANGE_INFO); + + CpuMpData->WakeupBuffer =3D GetWakeupBuffer (ApResetVectorSize); + CpuMpData->MpCpuExchangeInfo =3D (MP_CPU_EXCHANGE_INFO *) (UINTN) + (CpuMpData->WakeupBuffer + CpuMpData->AddressMap.Rende= zvousFunnelSize); + } + BackupAndPrepareWakeupBuffer (CpuMpData); +} + +/** + Free AP reset vector buffer. + + @param[in] CpuMpData The pointer to CPU MP Data structure. +**/ +VOID +FreeResetVector ( + IN CPU_MP_DATA *CpuMpData + ) +{ + RestoreWakeupBuffer (CpuMpData); +} + +/** This function will be called by BSP to wakeup AP. =20 @param[in] CpuMpData Pointer to CPU MP Data @@ -1353,7 +1428,6 @@ MpInitLibInitialize ( CpuMpData->CpuApStackSize =3D ApStackSize; CpuMpData->BackupBuffer =3D BackupBufferAddr; CpuMpData->BackupBufferSize =3D ApResetVectorSize; - CpuMpData->SaveRestoreFlag =3D FALSE; CpuMpData->WakeupBuffer =3D (UINTN) -1; CpuMpData->CpuCount =3D 1; CpuMpData->BspNumber =3D 0; @@ -2120,41 +2194,3 @@ GetCpuMpDataFromGuidedHob ( return CpuMpData; } =20 -/** - Get available system memory below 1MB by specified size. - - @param[in] CpuMpData The pointer to CPU MP Data structure. -**/ -VOID -BackupAndPrepareWakeupBuffer( - IN CPU_MP_DATA *CpuMpData - ) -{ - CopyMem ( - (VOID *) CpuMpData->BackupBuffer, - (VOID *) CpuMpData->WakeupBuffer, - CpuMpData->BackupBufferSize - ); - CopyMem ( - (VOID *) CpuMpData->WakeupBuffer, - (VOID *) CpuMpData->AddressMap.RendezvousFunnelAddress, - CpuMpData->AddressMap.RendezvousFunnelSize - ); -} - -/** - Restore wakeup buffer data. - - @param[in] CpuMpData The pointer to CPU MP Data structure. -**/ -VOID -RestoreWakeupBuffer( - IN CPU_MP_DATA *CpuMpData - ) -{ - CopyMem ( - (VOID *) CpuMpData->WakeupBuffer, - (VOID *) CpuMpData->BackupBuffer, - CpuMpData->BackupBufferSize - ); -} diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpIn= itLib/MpLib.h index ea56412cbce0..19defdaf4ba4 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h @@ -201,7 +201,6 @@ struct _CPU_MP_DATA { UINTN WakeupBuffer; UINTN BackupBuffer; UINTN BackupBufferSize; - BOOLEAN SaveRestoreFlag; =20 volatile UINT32 StartCount; volatile UINT32 FinishedCount; @@ -310,24 +309,18 @@ SaveCpuMpData ( IN CPU_MP_DATA *CpuMpData ); =20 -/** - Allocate reset vector buffer. - - @param[in, out] CpuMpData The pointer to CPU MP Data structure. -**/ -VOID -AllocateResetVector ( - IN OUT CPU_MP_DATA *CpuMpData - ); =20 /** - Free AP reset vector buffer. + Get available system memory below 1MB by specified size. =20 - @param[in] CpuMpData The pointer to CPU MP Data structure. + @param[in] WakeupBufferSize Wakeup buffer size required + + @retval other Return wakeup buffer address below 1MB. + @retval -1 Cannot find free memory below 1MB. **/ -VOID -FreeResetVector ( - IN CPU_MP_DATA *CpuMpData +UINTN +GetWakeupBuffer ( + IN UINTN WakeupBufferSize ); =20 /** @@ -543,26 +536,6 @@ IsMwaitSupport ( ); =20 /** - Get available system memory below 1MB by specified size. - - @param[in] CpuMpData The pointer to CPU MP Data structure. -**/ -VOID -BackupAndPrepareWakeupBuffer( - IN CPU_MP_DATA *CpuMpData - ); - -/** - Restore wakeup buffer data. - - @param[in] CpuMpData The pointer to CPU MP Data structure. -**/ -VOID -RestoreWakeupBuffer( - IN CPU_MP_DATA *CpuMpData - ); - -/** Enable Debug Agent to support source debugging on AP function. =20 **/ diff --git a/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c b/UefiCpuPkg/Library/M= pInitLib/PeiMpLib.c index 9ee5aca57b2b..70c2bc7323f6 100644 --- a/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c @@ -188,42 +188,6 @@ GetWakeupBuffer ( } =20 /** - Allocate reset vector buffer. - - @param[in, out] CpuMpData The pointer to CPU MP Data structure. -**/ -VOID -AllocateResetVector ( - IN OUT CPU_MP_DATA *CpuMpData - ) -{ - UINTN ApResetVectorSize; - - if (CpuMpData->WakeupBuffer =3D=3D (UINTN) -1) { - ApResetVectorSize =3D CpuMpData->AddressMap.RendezvousFunnelSize + - sizeof (MP_CPU_EXCHANGE_INFO); - - CpuMpData->WakeupBuffer =3D GetWakeupBuffer (ApResetVectorSize); - CpuMpData->MpCpuExchangeInfo =3D (MP_CPU_EXCHANGE_INFO *) (UINTN) - (CpuMpData->WakeupBuffer + CpuMpData->AddressMap.Rende= zvousFunnelSize); - } - BackupAndPrepareWakeupBuffer (CpuMpData); -} - -/** - Free AP reset vector buffer. - - @param[in] CpuMpData The pointer to CPU MP Data structure. -**/ -VOID -FreeResetVector ( - IN CPU_MP_DATA *CpuMpData - ) -{ - RestoreWakeupBuffer (CpuMpData); -} - -/** Checks APs status and updates APs status if needed. =20 **/ --=20 2.7.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel