From nobody Fri Dec 27 19:35:49 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 1501752737703871.9414041616142; Thu, 3 Aug 2017 02:32:17 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 84B032095DB8D; Thu, 3 Aug 2017 02:30:00 -0700 (PDT) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (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 9B10F21AEB0AE for ; Thu, 3 Aug 2017 02:29:59 -0700 (PDT) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 Aug 2017 02:32:10 -0700 Received: from ydong10-win10.ccr.corp.intel.com ([10.239.158.51]) by orsmga002.jf.intel.com with ESMTP; 03 Aug 2017 02:32:09 -0700 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.41,315,1498546800"; d="scan'208";a="119098236" From: Eric Dong To: edk2-devel@lists.01.org Date: Thu, 3 Aug 2017 17:32:01 +0800 Message-Id: <1501752726-14072-3-git-send-email-eric.dong@intel.com> X-Mailer: git-send-email 2.7.0.windows.1 In-Reply-To: <1501752726-14072-1-git-send-email-eric.dong@intel.com> References: <1501752726-14072-1-git-send-email-eric.dong@intel.com> Subject: [edk2] [Patch 2/7] Vlv2TbltDevicePkg: Enhance get mtrr mask logic. 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 , David Wei 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" In order to not use the deprecated macro, refine get mtrr mask value logic. Cc: Jeff Fan Cc: Ruiyu Ni Cc: David Wei Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Eric Dong Reviewed-by: Ruiyu Ni --- Vlv2TbltDevicePkg/PlatformInitPei/MemoryPeim.c | 45 ++++++++++++++++++++++= ---- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/Vlv2TbltDevicePkg/PlatformInitPei/MemoryPeim.c b/Vlv2TbltDevic= ePkg/PlatformInitPei/MemoryPeim.c index 99bdeb1..5a18a3f 100644 --- a/Vlv2TbltDevicePkg/PlatformInitPei/MemoryPeim.c +++ b/Vlv2TbltDevicePkg/PlatformInitPei/MemoryPeim.c @@ -70,6 +70,34 @@ GetMemorySize ( ); =20 =20 +/** + Initializes the valid address mask for MTRRs. + + This function initializes the valid bits mask and valid address mask for= MTRRs. + +**/ +UINT64 +InitializeAddressMtrrMask ( + VOID + ) +{ + UINT32 RegEax; + UINT8 PhysicalAddressBits;=20 + UINT64 ValidMtrrBitsMask; + + AsmCpuid (0x80000000, &RegEax, NULL, NULL, NULL); + + if (RegEax >=3D 0x80000008) { + AsmCpuid (0x80000008, &RegEax, NULL, NULL, NULL); + + PhysicalAddressBits =3D (UINT8) RegEax; + } else { + PhysicalAddressBits =3D 36; + } + + ValidMtrrBitsMask =3D LShiftU64 (1, PhysicalAddressBits) - 1; + return (ValidMtrrBitsMask & 0xfffffffffffff000ULL); +} =20 EFI_STATUS EFIAPI @@ -89,6 +117,7 @@ SetPeiCacheMode ( UINT64 HighMemoryLength; UINT8 Index; MTRR_SETTINGS MtrrSetting; + UINT64 ValidMtrrAddressMask; =20 // // Load Cache PPI @@ -124,6 +153,8 @@ SetPeiCacheMode ( &BootMode ); =20 + ValidMtrrAddressMask =3D InitializeAddressMtrrMask (); + // // Determine memory usage // @@ -166,15 +197,15 @@ SetPeiCacheMode ( // Index =3D 0; MtrrSetting.Variables.Mtrr[0].Base =3D (FixedPcdGet32 (PcdFlashAreaBaseA= ddress) | CacheWriteProtected); - MtrrSetting.Variables.Mtrr[0].Mask =3D ((~((UINT64)(FixedPcdGet32 (PcdFl= ashAreaSize) - 1))) & MTRR_LIB_CACHE_VALID_ADDRESS) | MTRR_LIB_CACHE_MTRR_E= NABLED; + MtrrSetting.Variables.Mtrr[0].Mask =3D ((~((UINT64)(FixedPcdGet32 (PcdFl= ashAreaSize) - 1))) & ValidMtrrAddressMask) | MTRR_LIB_CACHE_MTRR_ENABLED; Index ++; =20 MemOverflow =3D0; while (MaxMemoryLength > MemOverflow){ - MtrrSetting.Variables.Mtrr[Index].Base =3D (MemOverflow & MTRR_LIB_CAC= HE_VALID_ADDRESS) | CacheWriteBack; + MtrrSetting.Variables.Mtrr[Index].Base =3D (MemOverflow & ValidMtrrAdd= ressMask) | CacheWriteBack; MemoryLength =3D MaxMemoryLength - MemOverflow; MemoryLength =3D GetPowerOfTwo64 (MemoryLength); - MtrrSetting.Variables.Mtrr[Index].Mask =3D ((~(MemoryLength - 1)) & MT= RR_LIB_CACHE_VALID_ADDRESS) | MTRR_LIB_CACHE_MTRR_ENABLED; + MtrrSetting.Variables.Mtrr[Index].Mask =3D ((~(MemoryLength - 1)) & Va= lidMtrrAddressMask) | MTRR_LIB_CACHE_MTRR_ENABLED; =20 MemOverflow +=3D MemoryLength; Index++; @@ -185,15 +216,15 @@ SetPeiCacheMode ( while (MaxMemoryLength !=3D MemoryLength) { MemoryLengthUc =3D GetPowerOfTwo64 (MaxMemoryLength - MemoryLength); =20 - MtrrSetting.Variables.Mtrr[Index].Base =3D ((MaxMemoryLength - MemoryL= engthUc) & MTRR_LIB_CACHE_VALID_ADDRESS) | CacheUncacheable; - MtrrSetting.Variables.Mtrr[Index].Mask=3D ((~(MemoryLengthUc - 1)) &= MTRR_LIB_CACHE_VALID_ADDRESS) | MTRR_LIB_CACHE_MTRR_ENABLED; + MtrrSetting.Variables.Mtrr[Index].Base =3D ((MaxMemoryLength - MemoryL= engthUc) & ValidMtrrAddressMask) | CacheUncacheable; + MtrrSetting.Variables.Mtrr[Index].Mask=3D ((~(MemoryLengthUc - 1)) &= ValidMtrrAddressMask) | MTRR_LIB_CACHE_MTRR_ENABLED; MaxMemoryLength -=3D MemoryLengthUc; Index++; } =20 MemOverflow =3D0x100000000; while (HighMemoryLength > 0) { - MtrrSetting.Variables.Mtrr[Index].Base =3D (MemOverflow & MTRR_LIB_CAC= HE_VALID_ADDRESS) | CacheWriteBack; + MtrrSetting.Variables.Mtrr[Index].Base =3D (MemOverflow & ValidMtrrAdd= ressMask) | CacheWriteBack; MemoryLength =3D HighMemoryLength; MemoryLength =3D GetPowerOfTwo64 (MemoryLength); =20 @@ -201,7 +232,7 @@ SetPeiCacheMode ( MemoryLength =3D MemOverflow; } =20 - MtrrSetting.Variables.Mtrr[Index].Mask =3D ((~(MemoryLength - 1)) & MT= RR_LIB_CACHE_VALID_ADDRESS) | MTRR_LIB_CACHE_MTRR_ENABLED; + MtrrSetting.Variables.Mtrr[Index].Mask =3D ((~(MemoryLength - 1)) & Va= lidMtrrAddressMask) | MTRR_LIB_CACHE_MTRR_ENABLED; =20 MemOverflow +=3D MemoryLength; HighMemoryLength -=3D MemoryLength; --=20 2.7.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel