From nobody Fri Apr 26 21:30:48 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+101305+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 1679034543784423.3261998015314; Thu, 16 Mar 2023 23:29:03 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 8zBXYY1788612x4SG3rSApdI; Thu, 16 Mar 2023 23:29:03 -0700 X-Received: from NAM11-BN8-obe.outbound.protection.outlook.com (NAM11-BN8-obe.outbound.protection.outlook.com [40.107.236.41]) by mx.groups.io with SMTP id smtpd.web11.13342.1679034542552373694 for ; Thu, 16 Mar 2023 23:29:02 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GNHmx6gQlvw5o2IjIaXjG7SXlvYDGJFuzeczbp1vCJdF+tzzMr3rLTevPXxHDhFIbHAu0x9oNhddKg1LdbOcFaTtJFbAfIMI9lJ5ChQ92qohARF5QbiANZJJ4XGM7AMLFmbeuof0q57vdSn84ZmbsQ2o4WpBbl5lKd8jin9NZIyJshSuG/uuO+q4AcUJ7u68bb2sBW/sZASZLcAEetWm/wvB/BAC8LrUZmqrrJQugFR2U4RGOsoIxdgywPpu+a0klMg7ONZYdiO2l7pfpWAn7hc/Y6ePpxbE6VrHGMs8XZt3xCwhhCltO3rAaSHPfDIa5l9vy6wjYq9c7oC71wv33A== 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=IO9AIugg52yy5/dMCjZ6fQKt3oiYgHfaNCctRcr6Cfc=; b=YN7LzYVBKFHs8yPcppV2zb1kLW+OVJ8AjpPBzSJ5n80kswgB9sq7WR2rAAwXdpuUkJuErL0DeQ8TpYd1lyCzWr4xgl6Hj3ouFIvlMD1d6E2VCUvMc2Lz/hecjwbEM7FsY18pljdCPdPpOKrUwzUo7Ndh307qyCQvVIThMTkmSb4Uqo0EG7w93iLnl9hTg7wEwHD5hxDahuGWJtsd4q7rkM4gXzQ3JYNsRcUabbLXsJEww9XYmtvNpy7pzf4vUv4VLpG9uQd222UWFU8f8P354PAqsIm6LQzQKVP3Ey50YArves468myNOzVNr8jKYGfdv+vQIxIDvc4GuKYhYJo6tg== 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 DM6PR11CA0053.namprd11.prod.outlook.com (2603:10b6:5:14c::30) by SA1PR12MB6871.namprd12.prod.outlook.com (2603:10b6:806:25f::22) 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:29:00 +0000 X-Received: from DS1PEPF0000E642.namprd02.prod.outlook.com (2603:10b6:5:14c:cafe::73) by DM6PR11CA0053.outlook.office365.com (2603:10b6:5:14c::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.35 via Frontend Transport; Fri, 17 Mar 2023 06:29:00 +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+101305+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=SATLEXMB03.amd.com; pr=C X-Received: from SATLEXMB03.amd.com (165.204.84.17) by DS1PEPF0000E642.mail.protection.outlook.com (10.167.17.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6178.13 via Frontend Transport; Fri, 17 Mar 2023 06:29:00 +0000 X-Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB03.amd.com (10.181.40.144) 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:28:59 -0500 X-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; Fri, 17 Mar 2023 01:28:58 -0500 From: "Abdul Lateef Attar via groups.io" To: CC: Abdul Lateef Attar , Ard Biesheuvel , Leif Lindholm , Michael D Kinney Subject: [edk2-devel] [PATCH v2 3/4] Platform/AMD/BoarkPkg: Adds SetCacheMtrrLib library Date: Fri, 17 Mar 2023 11:58:47 +0530 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF0000E642:EE_|SA1PR12MB6871:EE_ X-MS-Office365-Filtering-Correlation-Id: 4e539316-985a-4ba0-9399-08db26b0e529 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: /UVXmLuyGSTEJtsr54oCmc00bzYIZr7CmpqjUM7zGfNu7oswGByGWRVz05sO0eVOW/gDv+ADHNAKgBlbkoNxpc3/SqVoCmt2xMxUw/u6HLpGavLXlPCv57ngY5VXOTM7NpzxtzUwGEVNRjzrv3db7HScNAzhXXvpr0fPcim/voSClKd3V+o2u6E5G1mY4shOJSGfCsN3CMwc9Uv2vDP76ggQQW/plOcL0xhkABE7FxkOdz1W9eIUVM425axwknRLi8qU3CMwWAba2pL3TRkgdz5I1G0IcLWts1Et0uBluM+956K4TdOjMIt2vzquXAnXW8iuMqKZiQ27Z7ylI2c4QHa4gp+d6BvgGOof3pgd1jto9EKt0QCcnQqkd0y3H9E903ikPtO+EaA280xISkU/CTzn6L3WhBV/hyFeYXzd7XLUTqoJCIbR468YqIpw/q9ph22s+bCHjWcfuQkWr1+ckv9igORWpPGds49jV81rviW3FZi/rkhN7tQuOACQGN45C5f1DJBvB82GfY0SY7s4OSxt+VlxUebg7xKbd5Ouyzc7I1Nf3vyVTpGs8W46n73JNAs8yZtwpp6g5xUxT2scQVpz5bS7G8AcM3j2hFU4wNzUH3maH8HnH/qyimxKruGAShXKYmwOMTGwzwGeToyEkol26Nz/Y01MW5OAufTj6DBctuxhdyHsGUhdvAtVk60J79sbx3w+5irN7EJVs4W9/8XlMWEnATfi+fi3oqh4Qss= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Mar 2023 06:29:00.3082 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4e539316-985a-4ba0-9399-08db26b0e529 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=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS1PEPF0000E642.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB6871 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: LIKYp7gYP82WfCjpMmdr7y09x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1679034543; bh=3oDSM4ARkprAS+AQKmIiHLH6LIJu5T4lV4YjbU/mb14=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=nVCvRw9ZZPgjbMbN2NL7S/s7W8xnOEK8U2t22g80Jw4zTPLrq1QBzVbFo34CxDz9oAg 18r85tuceP8BHqGa10AC0l9+1sVKZL1jmg3dsIJk5iAp6IzEGapU6705Qrce1cf7jocM0 cMqIGpXYtY5VqKXwszY/YcFY5iwgkn1451E= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1679034544088100009 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 --- 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 (#101305): https://edk2.groups.io/g/devel/message/101305 Mute This Topic: https://groups.io/mt/97667844/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-