From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.107.220.76]) by mx.groups.io with SMTP id smtpd.web10.67422.1680521004746494407 for ; Mon, 03 Apr 2023 04:23:24 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=2AcfN5Hb; 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.220.76, mailfrom: abdullateef.attar@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dgb4lzvATyhKJj6IONyA9wAinlylxQZmfE5L2XrFGkLggSTQvHaaZXbvVBt0GsmX2Klf7bgwHKUrvloOOuEW0pLykwE62pKYLRM9drh0KRIjMHmtciqjTnqS98BmAPelPBKn2yKN+ndDHeGsW0NKLZLe/uLoi+enFApbzlT24tHM4ZM3TvfH4k1Y7uIwDEbse68ZHJJj2nGHqR0oJFwNuxhhu4q/AQhhz2qOFXl3aduxidh01/tViNcEM+8xFlosV0uS3Fvcq981JcnLIozym4kdtrBK9PIAAZPxD0J0Hho81jOeFF4iA2I9EQLrwTbYw0L32qzqRnylAcpahEKklA== 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=fbCqfvYwycvf6ooEBxyy7sP4aeB/A8THhZdppz2BHb8=; b=ah9FZ/fSSsRLosYDYQHuGaS5Vti+do7h30wdoy0qC9hs0svRFLCL3E9rQOt/pKw9Wle3gdRnEaid5kSaI6O9our6hBUjb0crJpVcHDcQcKk4JfkLyxFqAv7LT/ejoizFFjPvIWuaLNjiTzMJk36ixvlz+7JrePGoHXMpdwQWkw0romjR7wJP71FrcgI8Jq+S1qy5WHeZ4lMq0yUXTEH7pbyL8uhQCkrCyJglVMfICvi+LrKvJAeqPOmu7OIjFjG7r/5U8TLg1wCt/z0K3aRsA0gaAwoy2ZMv3JpT7vHJYcvSAykaiz3Cy2zVy0lk9Uw8EyOcjYu5F0X2YZrpb6X7hg== 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=fbCqfvYwycvf6ooEBxyy7sP4aeB/A8THhZdppz2BHb8=; b=2AcfN5HbbL9R4XAYJWKnM46YdPStHEP5J+zEM7kcoTpJ/NlzURInEqt5h2S3eek8Bk/tQ8SU8ggd/Hcm1AqUD96VXKSgrMahObH/udeOFghXJ1ptATkb+vMnG7UFQxoi5ErJ6FK3itE3zDSxNX4sXmqy5b2Fv13vubgGRwTZ2xc= Received: from BN9PR03CA0546.namprd03.prod.outlook.com (2603:10b6:408:138::11) by CY5PR12MB6622.namprd12.prod.outlook.com (2603:10b6:930:42::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6254.33; Mon, 3 Apr 2023 11:23:22 +0000 Received: from BN8NAM11FT070.eop-nam11.prod.protection.outlook.com (2603:10b6:408:138:cafe::ef) by BN9PR03CA0546.outlook.office365.com (2603:10b6:408:138::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6254.22 via Frontend Transport; Mon, 3 Apr 2023 11:23:22 +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 BN8NAM11FT070.mail.protection.outlook.com (10.13.177.50) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6277.26 via Frontend Transport; Mon, 3 Apr 2023 11:23:22 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) 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; Mon, 3 Apr 2023 06:23:21 -0500 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; Mon, 3 Apr 2023 06:23:20 -0500 From: "Abdul Lateef Attar" To: CC: Abdul Lateef Attar , Ard Biesheuvel , Leif Lindholm , "Abner Chang" , Michael D Kinney Subject: [PATCH v4 2/3] Platform/AMD/MinBoardPkg: Adds SetCacheMtrrLib library Date: Mon, 3 Apr 2023 16:53:11 +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: BN8NAM11FT070:EE_|CY5PR12MB6622:EE_ X-MS-Office365-Filtering-Correlation-Id: 1583e415-eaea-4ab7-6583-08db3435d5a3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gq7Snzrmp9486dZfkRQlaOIhn5iAXnT/AU6c6l6KXUoHLEZ/CkdAtZ+N2XnSjPSDLvXJo8i4WZjOsxHSSFohNNkkzzJhKr5x2b7ePNEQCnVj5EFoFoszetTm29JmIXboc3daQbrtoVKgcCE63DX6c6i3YcnsWAxHytzLQZLRo6b6iLjaznPdgUGZHICK/ZR1IP/eGvfHrv1HdnAimSa4ZDxPtR0WD1vwwNla0UkuDlySG+TvdzpFP55nlE7PtjndReMnc5AbVWmc0vFkoIlg4fHj883MSh9obGJmVKDPQ/jmHvlvLwTlsTPyDvQwJGM13zIFyawh4j/i7vOPZsL2ZRNDFGKT4jrS+3f0CgGBTw60FHTUuvuU7Qb2ydyZxR1AQJYrL1sO2ZzVMr5rDemrcKfm46R25wzlpEKwb6IVHsDkIRZWMUGRj5KVpzRu6FXab6Xs6Jkmeknz+l7Ue12as/dsUAVLNAZdUsnk+iBQ3/brbMqNTr+D0q0z6nrYaSkD0WKaZqNs0vnCjSgu7g995zm+ZjEFLUIH9iFMG2QjreIn8QjX4No8PTJqRjS/Ck35PhAv4wCMIPn99ae0j95we2vrQHp2/wcL5aUhZ0fUMTSGxL7dnSRuTDyvwukcCt5A760Zf1LnAPAYS4sAvxpSGYPEmtLH1dlDorrX8qWaWp5wo172zIwA18WcZX1fseGGU69AzdZEna4ZaKvkKlwNTsnLiBL/afdZTjmiOnwsjwM= 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:(13230028)(4636009)(136003)(396003)(376002)(346002)(39860400002)(451199021)(36840700001)(40470700004)(46966006)(47076005)(478600001)(6666004)(186003)(26005)(7696005)(2616005)(40480700001)(36756003)(2906002)(40460700003)(83380400001)(81166007)(54906003)(426003)(336012)(70586007)(70206006)(5660300002)(8936002)(8676002)(36860700001)(41300700001)(356005)(82740400003)(4326008)(6916009)(316002)(82310400005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Apr 2023 11:23:22.4911 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1583e415-eaea-4ab7-6583-08db3435d5a3 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: BN8NAM11FT070.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6622 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain Adds SetCacheMtrrLib library for AmdMinBoardPkg, which sets MTRR values for PEI phase and also modifies the MTRR value at the end of PEI phase. Signed-off-by: Abdul Lateef Attar Cc: Ard Biesheuvel Cc: Leif Lindholm Cc: Abner Chang Cc: Michael D Kinney --- .../AMD/AmdMinBoardPkg/AmdMinBoardPkg.dsc | 9 ++ .../SetCacheMtrrLib/SetCacheMtrrLib.inf | 35 +++++ .../Library/SetCacheMtrrLib/SetCacheMtrrLib.c | 133 ++++++++++++++++++ 3 files changed, 177 insertions(+) create mode 100644 Platform/AMD/AmdMinBoardPkg/Library/SetCacheMtrrLib/Set= CacheMtrrLib.inf create mode 100644 Platform/AMD/AmdMinBoardPkg/Library/SetCacheMtrrLib/Set= CacheMtrrLib.c diff --git a/Platform/AMD/AmdMinBoardPkg/AmdMinBoardPkg.dsc b/Platform/AMD/= AmdMinBoardPkg/AmdMinBoardPkg.dsc index 74992a9a6b8c..2f17db5df5fb 100644 --- a/Platform/AMD/AmdMinBoardPkg/AmdMinBoardPkg.dsc +++ b/Platform/AMD/AmdMinBoardPkg/AmdMinBoardPkg.dsc @@ -18,4 +18,13 @@ [Defines] =20 [Packages] AmdMinBoardPkg/AmdMinBoardPkg.dec + MdePkg/MdePkg.dec + MinPlatformPkg/MinPlatformPkg.dec + UefiCpuPkg/UefiCpuPkg.dec + +[LibraryClasses.common.PEIM] + SetCacheMtrrLib|AmdMinBoardPkg/Library/SetCacheMtrrLib/SetCacheMtrrLib.i= nf + +[Components.IA32] + AmdMinBoardPkg/Library/SetCacheMtrrLib/SetCacheMtrrLib.inf =20 diff --git a/Platform/AMD/AmdMinBoardPkg/Library/SetCacheMtrrLib/SetCacheMt= rrLib.inf b/Platform/AMD/AmdMinBoardPkg/Library/SetCacheMtrrLib/SetCacheMtr= rLib.inf new file mode 100644 index 000000000000..b4c4b3e7de14 --- /dev/null +++ b/Platform/AMD/AmdMinBoardPkg/Library/SetCacheMtrrLib/SetCacheMtrrLib.i= nf @@ -0,0 +1,35 @@ +## @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] + MdePkg/MdePkg.dec + MinPlatformPkg/MinPlatformPkg.dec + UefiCpuPkg/UefiCpuPkg.dec + +[Sources] + SetCacheMtrrLib.c + +[Pcd] + gMinPlatformPkgTokenSpaceGuid.PcdFlashAreaBaseAddress + gMinPlatformPkgTokenSpaceGuid.PcdFlashAreaSize + diff --git a/Platform/AMD/AmdMinBoardPkg/Library/SetCacheMtrrLib/SetCacheMt= rrLib.c b/Platform/AMD/AmdMinBoardPkg/Library/SetCacheMtrrLib/SetCacheMtrrL= ib.c new file mode 100644 index 000000000000..33b774fedbd3 --- /dev/null +++ b/Platform/AMD/AmdMinBoardPkg/Library/SetCacheMtrrLib/SetCacheMtrrLib.c @@ -0,0 +1,133 @@ +/** @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