From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 57BF378003C for ; Fri, 1 Mar 2024 01:29:36 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=hUIYRpTaAUZn10tEOVSb4LGU3CV2AM2inllv98AZZ08=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1709256575; v=1; b=YsxTqQvmqrO0NcG0/Ng6wbwQioMrJPiLfRN66dGr2dOicLr51OHF9Z6xYFWvr8QYNH6c0CrG F8/6/9HuWDw1psZ+XYxQ6Q3qJm1+FYoHZrFUvkZN16ELT/U52deuD861nydnIKUVYM+F/PRIfJv sORg4/pWDGUnmWRFjdvYOlgc= X-Received: by 127.0.0.2 with SMTP id SOwJYY7687511xXpBidvsodG; Thu, 29 Feb 2024 17:29:35 -0800 X-Received: from mail-oa1-f43.google.com (mail-oa1-f43.google.com [209.85.160.43]) by mx.groups.io with SMTP id smtpd.web10.12516.1709256575002417981 for ; Thu, 29 Feb 2024 17:29:35 -0800 X-Received: by mail-oa1-f43.google.com with SMTP id 586e51a60fabf-21fa6e04835so528982fac.1 for ; Thu, 29 Feb 2024 17:29:34 -0800 (PST) X-Gm-Message-State: 47Bkfjc60Lq6hjTNCT67Gegkx7686176AA= X-Google-Smtp-Source: AGHT+IHb1gyZ8IvlCyxRsjBfJ0EE8xfhrBQVmoFvVSp9THq3nfLqmZJyffgYsS+XJvIhMuN13/4f0w== X-Received: by 2002:a05:6871:288c:b0:21e:f15e:836b with SMTP id bq12-20020a056871288c00b0021ef15e836bmr245765oac.20.1709256574130; Thu, 29 Feb 2024 17:29:34 -0800 (PST) X-Received: from localhost.localdomain (c-98-210-194-104.hsd1.ca.comcast.net. [98.210.194.104]) by smtp.gmail.com with ESMTPSA id xa20-20020a0568707f1400b0021e7c192093sm755267oab.27.2024.02.29.17.29.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 17:29:33 -0800 (PST) From: "Tuan Phan" To: devel@edk2.groups.io Cc: michael.d.kinney@intel.com, gaoliming@byosoft.com.cn, zhiguang.liu@intel.com, kraxel@redhat.com, lersek@redhat.com, rahul1.kumar@intel.com, ray.ni@intel.com, sunilvl@ventanamicro.com, jiewen.yao@intel.com, andrei.warkentin@intel.com, ardb+tianocore@kernel.org, Tuan Phan Subject: [edk2-devel] [PATCH v3 2/3] UefiCpuPkg: RISC-V: MMU: Support Svpbmt extension Date: Thu, 29 Feb 2024 17:29:23 -0800 Message-Id: <20240301012924.16232-3-tphan@ventanamicro.com> In-Reply-To: <20240301012924.16232-1-tphan@ventanamicro.com> References: <20240301012924.16232-1-tphan@ventanamicro.com> MIME-Version: 1.0 Precedence: Bulk 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,tphan@ventanamicro.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=YsxTqQvm; dmarc=none; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io The GCD EFI_MEMORY_UC and EFI_MEMORY_WC memory attributes will be supported when Svpbmt extension available. Cc: Gerd Hoffmann Cc: Laszlo Ersek Cc: Rahul Kumar Cc: Ray Ni Signed-off-by: Tuan Phan --- .../Library/BaseRiscVMmuLib/BaseRiscVMmuLib.c | 101 +++++++++++++++--- .../BaseRiscVMmuLib/BaseRiscVMmuLib.inf | 1 + 2 files changed, 88 insertions(+), 14 deletions(-) diff --git a/UefiCpuPkg/Library/BaseRiscVMmuLib/BaseRiscVMmuLib.c b/UefiCpu= Pkg/Library/BaseRiscVMmuLib/BaseRiscVMmuLib.c index 826a1d32a1d4..f4419bb8f380 100644 --- a/UefiCpuPkg/Library/BaseRiscVMmuLib/BaseRiscVMmuLib.c +++ b/UefiCpuPkg/Library/BaseRiscVMmuLib/BaseRiscVMmuLib.c @@ -36,6 +36,11 @@ #define PTE_PPN_SHIFT 10=0D #define RISCV_MMU_PAGE_SHIFT 12=0D =0D +#define RISCV_CPU_FEATURE_PBMT_BITMASK BIT2=0D +#define PTE_PBMT_NC BIT61=0D +#define PTE_PBMT_IO BIT62=0D +#define PTE_PBMT_MASK (PTE_PBMT_NC | PTE_PBMT_IO)=0D +=0D STATIC UINTN mModeSupport[] =3D { SATP_MODE_SV57, SATP_MODE_SV48, SATP_MO= DE_SV39, SATP_MODE_OFF };=0D STATIC UINTN mMaxRootTableLevel;=0D STATIC UINTN mBitPerLevel;=0D @@ -489,32 +494,89 @@ UpdateRegionMapping ( /**=0D Convert GCD attribute to RISC-V page attribute.=0D =0D - @param GcdAttributes The GCD attribute.=0D + @param GcdAttributes The GCD attribute.=0D + @param RiscVAttribtues The pointer of RISC-V page attribute.=0D =0D - @return The RISC-V page attribute.=0D + @retval EFI_INVALID_PARAMETER The RiscVAttribtues is NULL or cache typ= e mask not valid.=0D + @retval EFI_SUCCESS The operation succesfully.=0D =0D **/=0D STATIC=0D -UINTN=0D +EFI_STATUS=0D GcdAttributeToPageAttribute (=0D - IN UINTN GcdAttributes=0D + IN UINTN GcdAttributes,=0D + OUT UINTN *RiscVAttributes=0D )=0D {=0D - UINTN RiscVAttributes;=0D + UINT64 CacheTypeMask;=0D + BOOLEAN PmbtExtEnabled =3D (PcdGet64 (PcdRiscVFeatureOverride) & RISCV_= CPU_FEATURE_PBMT_BITMASK) ? TRUE : FALSE;=0D =0D - RiscVAttributes =3D RISCV_PG_R | RISCV_PG_W | RISCV_PG_X;=0D + if (!RiscVAttributes) {=0D + return EFI_INVALID_PARAMETER;=0D + }=0D +=0D + *RiscVAttributes =3D RISCV_PG_R | RISCV_PG_W | RISCV_PG_X;=0D =0D // Determine protection attributes=0D if ((GcdAttributes & EFI_MEMORY_RO) !=3D 0) {=0D - RiscVAttributes &=3D ~(RISCV_PG_W);=0D + *RiscVAttributes &=3D ~(RISCV_PG_W);=0D }=0D =0D // Process eXecute Never attribute=0D if ((GcdAttributes & EFI_MEMORY_XP) !=3D 0) {=0D - RiscVAttributes &=3D ~RISCV_PG_X;=0D + *RiscVAttributes &=3D ~RISCV_PG_X;=0D + }=0D +=0D + CacheTypeMask =3D GcdAttributes & EFI_CACHE_ATTRIBUTE_MASK;=0D + if ((CacheTypeMask !=3D 0) &&=0D + (((CacheTypeMask - 1) & CacheTypeMask) !=3D 0))=0D + {=0D + DEBUG (=0D + (=0D + DEBUG_ERROR,=0D + "%a: The cache type mask (0x%llX) should contain exactly one bit se= t\n",=0D + __func__,=0D + CacheTypeMask=0D + )=0D + );=0D + return EFI_INVALID_PARAMETER;=0D }=0D =0D - return RiscVAttributes;=0D + switch (CacheTypeMask) {=0D + case EFI_MEMORY_UC:=0D + if (PmbtExtEnabled) {=0D + *RiscVAttributes |=3D PTE_PBMT_IO;=0D + } else {=0D + DEBUG (=0D + (=0D + DEBUG_VERBOSE,=0D + "%a: EFI_MEMORY_UC set but Pmbt extension not available\n",=0D + __func__=0D + )=0D + );=0D + }=0D +=0D + break;=0D + case EFI_MEMORY_WC:=0D + if (PmbtExtEnabled) {=0D + *RiscVAttributes |=3D PTE_PBMT_NC;=0D + } else {=0D + DEBUG (=0D + (=0D + DEBUG_VERBOSE,=0D + "%a: EFI_MEMORY_WC set but Pmbt extension not available\n",=0D + __func__=0D + )=0D + );=0D + }=0D +=0D + break;=0D + default:=0D + // Default PMA mode=0D + break;=0D + }=0D +=0D + return EFI_SUCCESS;=0D }=0D =0D /**=0D @@ -537,21 +599,32 @@ RiscVSetMemoryAttributes ( IN UINTN Attributes=0D )=0D {=0D - UINTN PageAttributesSet;=0D + UINTN PageAttributesSet;=0D + UINTN PageAttributesClear;=0D + EFI_STATUS Status;=0D =0D - PageAttributesSet =3D GcdAttributeToPageAttribute (Attributes);=0D + Status =3D GcdAttributeToPageAttribute (Attributes, &PageAttributesSet);= =0D + if (EFI_ERROR (Status)) {=0D + return Status;=0D + }=0D =0D if (!RiscVMmuEnabled ()) {=0D return EFI_SUCCESS;=0D }=0D =0D + PageAttributesClear =3D PTE_ATTRIBUTES_MASK;=0D + if ((PcdGet64 (PcdRiscVFeatureOverride) & RISCV_CPU_FEATURE_PBMT_BITMASK= ) !=3D 0) {=0D + PageAttributesClear |=3D PTE_PBMT_MASK;=0D + }=0D +=0D DEBUG (=0D (=0D DEBUG_VERBOSE,=0D - "%a: Set %llX page attribute 0x%X\n",=0D + "%a: %llX: set attributes 0x%X, clear attributes 0x%X\n",=0D __func__,=0D BaseAddress,=0D - PageAttributesSet=0D + PageAttributesSet,=0D + PageAttributesClear=0D )=0D );=0D =0D @@ -559,7 +632,7 @@ RiscVSetMemoryAttributes ( BaseAddress,=0D Length,=0D PageAttributesSet,=0D - PTE_ATTRIBUTES_MASK,=0D + PageAttributesClear,=0D (UINTN *)RiscVGetRootTranslateTable (),=0D TRUE=0D );=0D diff --git a/UefiCpuPkg/Library/BaseRiscVMmuLib/BaseRiscVMmuLib.inf b/UefiC= puPkg/Library/BaseRiscVMmuLib/BaseRiscVMmuLib.inf index 51ebe1750e97..1dbaa81f3608 100644 --- a/UefiCpuPkg/Library/BaseRiscVMmuLib/BaseRiscVMmuLib.inf +++ b/UefiCpuPkg/Library/BaseRiscVMmuLib/BaseRiscVMmuLib.inf @@ -28,3 +28,4 @@ =0D [Pcd]=0D gUefiCpuPkgTokenSpaceGuid.PcdCpuRiscVMmuMaxSatpMode ## CONSUMES=0D + gEfiMdePkgTokenSpaceGuid.PcdRiscVFeatureOverride ## CONSUMES=0D --=20 2.25.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#116198): https://edk2.groups.io/g/devel/message/116198 Mute This Topic: https://groups.io/mt/104656466/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-