From nobody Mon Sep 16 18:50:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+101311+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1679035828474202.93484621918583; Thu, 16 Mar 2023 23:50:28 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id RI0zYY1788612x3BpBqvojkY; Thu, 16 Mar 2023 23:50:28 -0700 X-Received: from NAM04-DM6-obe.outbound.protection.outlook.com (NAM04-DM6-obe.outbound.protection.outlook.com [40.107.102.84]) by mx.groups.io with SMTP id smtpd.web11.13512.1679035827039270176 for ; Thu, 16 Mar 2023 23:50:27 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SeybqWVd4SIbQJ/CJrBqCTuQ5TgkDhAgFcNz8iqM0Nc5yS44otamAymwQ5e2N/EAAayX2pMXRnic+DYrV/gh6EclVSGFoHoQzyidETwKuPLCiInHD1Z1klv1N7EduGkWZNAKn2VBsQzFj9dPpzGiPaNZgKvzMJVheIvd8e7uob949BMExErrUjDOP6zuJ0hRLQ/V03Blq32taxvI8mxAjtEjD0qrGb3CKaHxj/HGmiPLRgLQFvLjzHZ5nV+FQsAfHS/UIaWzNsQC7DNK56xtPY9jN7WuDwQrHdTECGNFN76oBTG0mrqG5hU2+LcytN6cXsRXafDI55JwffShjLFQoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=7kOPACWySzJwCxjwiix8wG99gJycLOilDU7ZdE/KRW4=; b=oMSDTiSmNstfoRVO/GuYG2AlJ53vvNx2/88Z45/lhPAVLOlLmUTUyAhIMX3tZwICnKhVB3Eb4j5UZxOJd/h6/FEyUWIxofzZh3JhbYYGPPYvUTRctdW4gxKXKYwiojFqArY+1Hjxv/9j+tg1yZgfDSvRPl6olK+ThFWZO5BsvoD+iRF32M7Zh2eMaJcWtQO+NNuYurt6oa2rnj/b9+g7Y4jU4dERO2LS7OlClyoRy9K5qqFa8H6qUuQftfXVvEWL1CdUxDutwGyp3j9mBIAhQa65zh5tLTX2FVj5o3r0V5AIZ0gkIddH6N+E7Dj+g5f0y1iGIuzJcu+Kt7Vw1x5ooA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none X-Received: from DS7PR05CA0086.namprd05.prod.outlook.com (2603:10b6:8:56::7) by SJ2PR12MB9007.namprd12.prod.outlook.com (2603:10b6:a03:541::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.31; Fri, 17 Mar 2023 06:50:24 +0000 X-Received: from DM6NAM11FT029.eop-nam11.prod.protection.outlook.com (2603:10b6:8:56:cafe::30) by DS7PR05CA0086.outlook.office365.com (2603:10b6:8:56::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6222.8 via Frontend Transport; Fri, 17 Mar 2023 06:50:24 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+101311+1787277+3901457@groups.io; helo=mail02.groups.io; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C X-Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT029.mail.protection.outlook.com (10.13.173.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6199.20 via Frontend Transport; Fri, 17 Mar 2023 06:50:24 +0000 X-Received: from SATLEXMB06.amd.com (10.181.40.147) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Fri, 17 Mar 2023 01:50:24 -0500 X-Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB06.amd.com (10.181.40.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Fri, 17 Mar 2023 01:50:23 -0500 X-Received: from BLR-LAB-SFW01.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Fri, 17 Mar 2023 01:50:21 -0500 From: "Abdul Lateef Attar via groups.io" To: CC: Abdul Lateef Attar , Ard Biesheuvel , Leif Lindholm , Abner Chang , Michael D Kinney Subject: [edk2-devel] [PATCH v2 RESEND 3/4] Platform/AMD/BoarkPkg: Adds SetCacheMtrrLib library Date: Fri, 17 Mar 2023 12:20:06 +0530 Message-ID: <60ddb8be3b32bc6ff9745a51eef1f857c428a0f4.1679035605.git.abdattar@amd.com> In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT029:EE_|SJ2PR12MB9007:EE_ X-MS-Office365-Filtering-Correlation-Id: 9acf3261-d316-458a-5523-08db26b3e2b2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: xHLQon1YnmxocGm/qdq3hTX1xDczVUlhggP6xyQOnbBRgnCE8ihqJIhDPLgmvbrc+V5SweOL67L/g5RQc8MPyrOFQ9wggqErwNGF9piHo0FEQhVFx0ticBnfW4d6uTLB8ylk8Tn8cVZtQ0ysi9RCC7/xdEmW1fHUHiWgsAOLZ5ijUJ/BfLxYfwLVDqVp3FyY65+30p0pgSAA/HxOr+Off2121n00k6MVdyGPWCz6quOvpPV7+FxL1L2hIepvM8onJBvQ0pw2SD0GVfRSwEO2m8lDfyjTedem5dKXdqJH4BpgQ9IAEV1EpY9BpiutrAJsl0F/7RWHaIKTJW3WiG4Y1Ji9nbWB1se11rF5f9NvF6IdLxlKemZtW5xMhu3pHTjAMRFcTIFMJ3xp91qNE2G5zj0uRsOhvn2Gv/lkWIsmjJmuaLW+mSsnBcQ1Z//dglRHDNI0VdT4fLPQcCDrLo2ip2lYKZlsyp5RfBRoOM0HcN/MO2ckSxWtg/PWNa+5k2PsttWb69cK8w7Z6/E9ap9OoExCxQN09EebZacMQV6KW2Fk4ePsugQSIJ/M2qMZ9zez4GnJpoj2U4uJKjJkrGj66OzQE1jvCYmR4TegxNsDkhwamlP2JCxb1oO2tsSdYUKwtQGf2TEi2iyT2iBFRACJNVnsALWHGh+BQnwV+p4Bp5V55uqRXYo6zd7bfua2hP3ftSOXwRm+A1drXMnFm0fZJchBjjbzyReGiDxKIUfiIVk= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Mar 2023 06:50:24.6615 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9acf3261-d316-458a-5523-08db26b3e2b2 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT029.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB9007 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,abdattar@amd.com X-Gm-Message-State: aOPXwXtYG4YnLXhMSE3I9Zi4x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1679035828; bh=jAQzeO38/fu6mnYmOHfyWYwg4lDLDvcg0L/W6CLW+cw=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=Uk7tzSzJOJdg0tMFh46IzH9H1Q5Y2jhVbGeweVs4nLvCflByL78CL5zgt0O/fXn0Xn1 nc+SY55YsHOZhp1C+iCt7fVU9GAZPUUXTzKADYcqWBIcLhhtZ6yb2fcFcsHWYiQ4Rijm4 VZiR939LBfiIS5EWhk8redqYlbTZLgyEpLA= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1679035830280100007 Content-Type: text/plain; charset="utf-8" Adds SetCacheMtrrLib library for AMD processor based boards. This library sets MTRR value or various memory ranges. Signed-off-by: Abdul Lateef Attar Cc: Ard Biesheuvel Cc: Leif Lindholm Cc: Abner Chang Cc: Michael D Kinney Reviewed-by: Abner Chang --- Platform/AMD/BoardPkg/BoardPkg.dsc | 10 ++ .../SetCacheMtrrLib/SetCacheMtrrLib.inf | 37 +++++ .../Library/SetCacheMtrrLib/SetCacheMtrrLib.c | 132 ++++++++++++++++++ 3 files changed, 179 insertions(+) create mode 100644 Platform/AMD/BoardPkg/Library/SetCacheMtrrLib/SetCacheM= trrLib.inf create mode 100644 Platform/AMD/BoardPkg/Library/SetCacheMtrrLib/SetCacheM= trrLib.c diff --git a/Platform/AMD/BoardPkg/BoardPkg.dsc b/Platform/AMD/BoardPkg/Boa= rdPkg.dsc index cb4065b86c60..aa0ee8287cd8 100644 --- a/Platform/AMD/BoardPkg/BoardPkg.dsc +++ b/Platform/AMD/BoardPkg/BoardPkg.dsc @@ -18,3 +18,13 @@ [Defines] =20 [Packages] BoardPkg/BoardPkg.dec + MinPlatformPkg/MinPlatformPkg.dec + MdePkg/MdePkg.dec + UefiCpuPkg/UefiCpuPkg.dec + +[LibraryClasses.common.PEIM] + SetCacheMtrrLib|BoardPkg/Library/SetCacheMtrrLib/SetCacheMtrrLib.inf + +[Components.IA32] + BoardPkg/Library/SetCacheMtrrLib/SetCacheMtrrLib.inf + diff --git a/Platform/AMD/BoardPkg/Library/SetCacheMtrrLib/SetCacheMtrrLib.= inf b/Platform/AMD/BoardPkg/Library/SetCacheMtrrLib/SetCacheMtrrLib.inf new file mode 100644 index 000000000000..c66661d3f8dc --- /dev/null +++ b/Platform/AMD/BoardPkg/Library/SetCacheMtrrLib/SetCacheMtrrLib.inf @@ -0,0 +1,37 @@ +## @file +# Component information file for Platform SetCacheMtrr Library. +# This library implementation is for AMD processor based platforms. +# +# Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 1.29 + BASE_NAME =3D PeiSetCacheMtrrLib + FILE_GUID =3D 1E8468E0-5EB4-4088-9B52-BFDC6E4DAE87 + MODULE_TYPE =3D PEIM + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D SetCacheMtrrLib + +[LibraryClasses] + BaseLib + DebugLib + MtrrLib + +[Packages] + MinPlatformPkg/MinPlatformPkg.dec + MdePkg/MdePkg.dec + UefiCpuPkg/UefiCpuPkg.dec + +[Sources] + SetCacheMtrrLib.c + +[Guids] + +[Pcd] + gMinPlatformPkgTokenSpaceGuid.PcdFlashAreaBaseAddress + gMinPlatformPkgTokenSpaceGuid.PcdFlashAreaSize + diff --git a/Platform/AMD/BoardPkg/Library/SetCacheMtrrLib/SetCacheMtrrLib.= c b/Platform/AMD/BoardPkg/Library/SetCacheMtrrLib/SetCacheMtrrLib.c new file mode 100644 index 000000000000..18404405d9fa --- /dev/null +++ b/Platform/AMD/BoardPkg/Library/SetCacheMtrrLib/SetCacheMtrrLib.c @@ -0,0 +1,132 @@ +/** @file + +SetCacheMtrr library functions. +This library implementation is for AMD processor based platforms. + +Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
+ +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include + +/** + This function sets the cache MTRR values for PEI phase. +**/ +VOID +EFIAPI +SetCacheMtrr ( + VOID + ) +{ + EFI_STATUS Status; + + Status =3D MtrrSetMemoryAttribute ( + 0, + 0xA0000, + CacheWriteBack + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "Error(%r) in setting CacheWriteBack for 0-0x9FFFF\n", + Status + )); + } + + Status =3D MtrrSetMemoryAttribute ( + 0xA0000, + 0x20000, + CacheUncacheable + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "Error(%r) in setting CacheUncacheable for 0xA0000-0xBFFFF\n", + Status + )); + } + + Status =3D MtrrSetMemoryAttribute ( + 0xC0000, + 0x40000, + CacheWriteProtected + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "Error(%r) in setting CacheWriteProtected for 0xC0000-0xFFFFF\n", + Status + )); + } + + Status =3D MtrrSetMemoryAttribute ( + 0x100000, + 0xAFF00000, + CacheWriteBack + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "Error(%r) in setting CacheWriteBack for 0x100000-0xAFFFFFFF\n", + Status + )); + } + + Status =3D MtrrSetMemoryAttribute ( + PcdGet32 (PcdFlashAreaBaseAddress), + PcdGet32 (PcdFlashAreaSize), + CacheWriteProtected + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "Error(%r) in setting CacheWriteProtected for 0x%X-0x%X\n", + Status, + PcdGet32 (PcdFlashAreaBaseAddress), + PcdGet32 (PcdFlashAreaBaseAddress) + PcdGet32 (PcdFlashAreaSize) + )); + } + + MtrrDebugPrintAllMtrrs (); + return; +} + +/** + Update MTRR setting in EndOfPei phase. + This function will set the MTRR value as CacheUncacheable + for Flash address. + + @retval EFI_SUCCESS The function completes successfully. + @retval Others Some error occurs. +**/ +EFI_STATUS +EFIAPI +SetCacheMtrrAfterEndOfPei ( + VOID + ) +{ + EFI_STATUS Status; + + Status =3D MtrrSetMemoryAttribute ( + PcdGet32 (PcdFlashAreaBaseAddress), + PcdGet32 (PcdFlashAreaSize), + CacheUncacheable + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "Error(%r) in setting CacheUncacheable for 0x%X-0x%X\n", + Status, + PcdGet32 (PcdFlashAreaBaseAddress), + PcdGet32 (PcdFlashAreaBaseAddress) + PcdGet32 (PcdFlashAreaSize) + )); + } + + MtrrDebugPrintAllMtrrs (); + return EFI_SUCCESS; +} --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#101311): https://edk2.groups.io/g/devel/message/101311 Mute This Topic: https://groups.io/mt/97667945/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-