From nobody Mon Dec 23 09:53:24 2024 Delivered-To: importer@patchew.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 1518323467657254.81607512814867; Sat, 10 Feb 2018 20:31:07 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id D87C2222DE158; Sat, 10 Feb 2018 20:25:17 -0800 (PST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) (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 B8060223DB79A for ; Sat, 10 Feb 2018 20:25:15 -0800 (PST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Feb 2018 20:31:02 -0800 Received: from fmsmsx105.amr.corp.intel.com ([10.18.124.203]) by fmsmga002.fm.intel.com with ESMTP; 10 Feb 2018 20:31:02 -0800 Received: from fmsmsx111.amr.corp.intel.com (10.18.116.5) by FMSMSX105.amr.corp.intel.com (10.18.124.203) with Microsoft SMTP Server (TLS) id 14.3.319.2; Sat, 10 Feb 2018 20:31:02 -0800 Received: from shsmsx101.ccr.corp.intel.com (10.239.4.153) by fmsmsx111.amr.corp.intel.com (10.18.116.5) with Microsoft SMTP Server (TLS) id 14.3.319.2; Sat, 10 Feb 2018 20:31:01 -0800 Received: from shsmsx103.ccr.corp.intel.com ([169.254.4.116]) by SHSMSX101.ccr.corp.intel.com ([169.254.1.253]) with mapi id 14.03.0319.002; Sun, 11 Feb 2018 12:31:00 +0800 X-Original-To: edk2-devel@lists.01.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; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.65; helo=mga03.intel.com; envelope-from=mang.guo@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,493,1511856000"; d="dat'59?scan'59,208,59";a="18997137" From: "Guo, Mang" To: "edk2-devel@lists.01.org" Thread-Topic: [Patch][edk2-platforms/devel-MinnowBoard3-UDK2017] UefiCpuPkg MpInitLib: Save/restore original WakeupBuffer for DxeMpLib Thread-Index: AdOi8R3JU7+XyPQOTkqEy06pomaC2w== Date: Sun, 11 Feb 2018 04:30:59 +0000 Message-ID: <22D2C85ED001C54AA20BFE3B0E4751D1525B4801@SHSMSX103.ccr.corp.intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: <22D2C85ED001C54AA20BFE3B0E4751D1525B4801@SHSMSX103.ccr.corp.intel.com> x-originating-ip: [10.239.127.40] MIME-Version: 1.0 X-Content-Filtered-By: Mailman/MimeDel 2.1.23 Subject: [edk2] [Patch][edk2-platforms/devel-MinnowBoard3-UDK2017] UefiCpuPkg MpInitLib: Save/restore original WakeupBuffer for DxeMpLib X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Wei, David" 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. Sync from edk2 master: a6b3d753f98118ee547ae935b347f4f00fa67e7c Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Guo Mang --- Core/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c | 86 +++++++------------- Core/UefiCpuPkg/Library/MpInitLib/MpLib.c | 114 +++++++++++++++++------= ---- Core/UefiCpuPkg/Library/MpInitLib/MpLib.h | 45 +++-------- Core/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c | 38 +-------- 4 files changed, 111 insertions(+), 172 deletions(-) diff --git a/Core/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c b/Core/UefiCpuPkg= /Library/MpInitLib/DxeMpLib.c index b393244..8099ee6 100644 --- a/Core/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c +++ b/Core/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c @@ -1,7 +1,7 @@ /** @file MP initialize support functions for DXE phase. =20 - Copyright (c) 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License which accompanies this distribution. The full text of the license may b= e found at @@ -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/Core/UefiCpuPkg/Library/MpInitLib/MpLib.c b/Core/UefiCpuPkg/Li= brary/MpInitLib/MpLib.c index df19b43..2913844 100644 --- a/Core/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/Core/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -1,7 +1,7 @@ /** @file CPU MP Initialize Library common functions. =20 - Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.
+ Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License which accompanies this distribution. The full text of the license may b= e found at @@ -794,7 +794,80 @@ TimedWaitForApFinish ( IN UINT32 FinishedApLimit, IN UINT32 TimeLimit ); +/** + 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. =20 + @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 @@ -1353,7 +1426,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 +2192,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/Core/UefiCpuPkg/Library/MpInitLib/MpLib.h b/Core/UefiCpuPkg/Li= brary/MpInitLib/MpLib.h index ea56412..ff04796 100644 --- a/Core/UefiCpuPkg/Library/MpInitLib/MpLib.h +++ b/Core/UefiCpuPkg/Library/MpInitLib/MpLib.h @@ -1,7 +1,7 @@ /** @file Common header file for MP Initialize Library. =20 - Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.
+ Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License which accompanies this distribution. The full text of the license may b= e found at @@ -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/Core/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c b/Core/UefiCpuPkg= /Library/MpInitLib/PeiMpLib.c index 9ee5aca..7ce5f72 100644 --- a/Core/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c +++ b/Core/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c @@ -1,7 +1,7 @@ /** @file MP initialize support functions for PEI phase. =20 - Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.
+ Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License which accompanies this distribution. The full text of the license may b= e found at @@ -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.10.1.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel