From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.43]) by mx.groups.io with SMTP id smtpd.web10.2152.1678864310556934038 for ; Wed, 15 Mar 2023 00:11:50 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=MaGj/AjO; spf=permerror, err=parse error for token &{10 18 %{i}._ip.%{h}._ehlo.%{d}._spf.vali.email}: invalid domain name (domain: amd.com, ip: 40.107.92.43, mailfrom: abdullateef.attar@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VaDhyzi3wpmsjE2h5KYCjRD7+p390HH3LFwDDgk2uKIoMm8c98TumjQrYPoy1AdKZDLmctLEUsQ4xS4TtbP9zaUycco2q5CGpUwhS3QVKY47V8gENkW+pILbJs5cblH8rNbC7vD0liyRjkRpxfz/ruXOTzheJVSzrpvoAeL4BQS0Fcts84t0u6La1tBowFouoN50Uc1fRFIye6VO0q32X8DuP4w4XH+kbQi/TaiWLm/gMzIJ9YiC5HQ70ZWmGB1whUBOCF8DvCd9rk81bU0NvvrqnMC+9vXIkUkljM44EwgsIe+rjBG4g0IpA6hFG0cLA4kf72ulgp7XzZV0UMZ9qA== 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=lzlZyb6cN2GFcFEYstItN9YetZXswM9G2A+72YXCfS8=; b=bfkPfZ7WVTkigBmSHdHSkXOSp6BQOUabuxDXyIzV9e1BOavmBQ+Yp3hUWwqF+RnhxMAx/O7LwYHrXPXTKeP5gqAx+vUmD4M4r+7TDeLPK3F/11bae02hXJrPjkVDKmv/XJkm90WuyIg41vPndWrU8ANwn4tFwGP2MghhdrWQg09WuvJqagUGSnFnmkaJZQOrlbSeHONsS5OmUKAGLmALJ0EP5GVZde3iz0hgCYY/RT2griU5zBEeP+p2CWLnwmEpNTQMYpnrRgFN4AJpYPLtWj7wWa6l8kUR/svp6KfGAwqTs5BYvDqL+QtjlRpkCYJ2+bY17i2DKs8JmWTbttQRgA== 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lzlZyb6cN2GFcFEYstItN9YetZXswM9G2A+72YXCfS8=; b=MaGj/AjOzloBGZCqebYkdAT5OatOjX3nBjXnaaoP89tHua9t7RPP8zOp/4OmBrmy1h40P/gRmyVRSFh1wzHc+QlPrxN45PZTWcGgExDQ1glreRegi/ltW3UF6IFacZNwRAHuYy6p1fqqosCMZVHeZyvivtjs0M4kTAiDX2n4WaI= Received: from MN2PR01CA0012.prod.exchangelabs.com (2603:10b6:208:10c::25) by DM6PR12MB4044.namprd12.prod.outlook.com (2603:10b6:5:21d::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.26; Wed, 15 Mar 2023 07:11:46 +0000 Received: from BL02EPF000100D2.namprd05.prod.outlook.com (2603:10b6:208:10c:cafe::19) by MN2PR01CA0012.outlook.office365.com (2603:10b6:208:10c::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.29 via Frontend Transport; Wed, 15 Mar 2023 07:11:46 +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 (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 Received: from SATLEXMB04.amd.com (165.204.84.17) by BL02EPF000100D2.mail.protection.outlook.com (10.167.241.206) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6178.17 via Frontend Transport; Wed, 15 Mar 2023 07:11:46 +0000 Received: from SATLEXMB07.amd.com (10.181.41.45) 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; Wed, 15 Mar 2023 02:11:40 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB07.amd.com (10.181.41.45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Wed, 15 Mar 2023 00:11:39 -0700 Received: from BLR-LAB-SFW01.amd.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Wed, 15 Mar 2023 02:11:38 -0500 From: "Abdul Lateef Attar" To: CC: Abdul Lateef Attar , Ard Biesheuvel , Leif Lindholm Subject: [PATCH v1 3/4] Platform/AMD/BoarkPkg: Adds SetCacheMtrrLib library Date: Wed, 15 Mar 2023 12:41:14 +0530 Message-ID: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Return-Path: AbdulLateef.Attar@amd.com X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF000100D2:EE_|DM6PR12MB4044:EE_ X-MS-Office365-Filtering-Correlation-Id: 4e98a1f6-0b3b-4741-b285-08db252489fe X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kQH+rDpPe18TGzBkBwtIh1eU/wu/D5EocCWPuw/7yrzY/kunItMvnHdzqWP7wpM6SY4LPtebiCNfpFN9+mcTez9yg0NG3pEovOSmhPRimTlwDt8blMkgXhRGngj0iufAEV13cXsR1iUglqTaFXRrLnsY+rquxzpUmMy1g5/vJKNiNKkc+fsYyb3iK+R9VfEArMjRxKoZNyJOFDiaevKBYZQS5AQUNDqZvGBzUvUb5/PSN4vYssmrU9lt8PXu9GJKzObThSQZhQSt4w4q9El/qxuLfI9Ld8dItuVihfsleHi23L2CQozIi6hEMB+/ll/9xxYKTtK60tASEzVN3749rcHV0EiKUAa92dW4RcUNPaNEPdYm3sQbKoGKYM1W5VL4PpVgxwXtew/ekd3LsI6BxJb9uxCeHVwhQkjrr5GuSLPSHiotATZtMfltCUvb+o+OKkR0YsdduuytkjJuBUbC6p+ursmNbnTlLm+YUKbTTl5ImoatCR+1KIWh0GlRsSGoG/9cX+oYxaotqIsyqjSyUC1Ta5C6GG9hH28Uk2o2TqdAIJVV3f4csfYUUUOl45jjYac6SxUttYk0Ae9BurDMtOz5KslMnwolBUfAnSdBJWK/4O1fEh+QhFGGQMjJ0UXs8OPYUQ2Z0mbqA8L+K+IdK2GoSlSD85jSG3qhWFIJqzTfqYZiHu8lP0mMLM01WTHN/YO7WZUNtn5W/+7Nko6Qlst3nG/sY+4Xb5wdcdSSz0Q= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230025)(4636009)(376002)(346002)(136003)(39860400002)(396003)(451199018)(36840700001)(40470700004)(46966006)(36756003)(40460700003)(478600001)(356005)(54906003)(316002)(8936002)(5660300002)(7696005)(8676002)(2906002)(6916009)(4326008)(70586007)(70206006)(41300700001)(82740400003)(81166007)(40480700001)(36860700001)(26005)(186003)(2616005)(82310400005)(83380400001)(336012)(6666004)(47076005)(426003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Mar 2023 07:11:46.6809 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4e98a1f6-0b3b-4741-b285-08db252489fe 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: BL02EPF000100D2.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4044 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain Adds SetCacheMtrrLib library for AMD processor based boards. This library sets MTRR value or various memory ranges. Cc: Ard Biesheuvel Cc: Leif Lindholm Cc: 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