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 9B0CDD8060D for ; Wed, 31 Jan 2024 01:04:54 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=O8osR/w17H3kc5mYaFczOqGby7DzwnO5vIy2BNevE7g=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id: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=1706663093; v=1; b=fASIyez4dk9cz4obNkfhw5uLHh4tvfyudOm9voQlZqEHgClb+X+oy9fAzSb+SwoEGOMVADoL hRFUF/ZoXjKC0ADALnGtLWYEeT0KSIt9ECpZjEF80ZG1ct014Or+hxL/kTbIS/Z1Lw4ASMXIdRo 2e4uhjvprTa2rW2CibdNmIqI= X-Received: by 127.0.0.2 with SMTP id wAWKYY7687511xdMxB37dQLh; Tue, 30 Jan 2024 17:04:53 -0800 X-Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) by mx.groups.io with SMTP id smtpd.web10.4049.1706663092414800850 for ; Tue, 30 Jan 2024 17:04:52 -0800 X-Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-6ddcfda697cso3437501b3a.2 for ; Tue, 30 Jan 2024 17:04:52 -0800 (PST) X-Gm-Message-State: LXYs7PG71AAjlmjmObWzjW6vx7686176AA= X-Google-Smtp-Source: AGHT+IHu7pz8VyuSoK7oHV/4UPOjji8NZT+m6XIAVKCdRK87ncsMGVhRUezD+qjJwN26OqEzaybwyw== X-Received: by 2002:a05:6a00:1c96:b0:6d9:bbac:a34b with SMTP id y22-20020a056a001c9600b006d9bbaca34bmr367259pfw.14.1706663091555; Tue, 30 Jan 2024 17:04:51 -0800 (PST) X-Received: from localhost.localdomain (115.sub-174-249-150.myvzw.com. [174.249.150.115]) by smtp.gmail.com with ESMTPSA id x185-20020a6263c2000000b006de11aaa7ffsm7155323pfb.8.2024.01.30.17.04.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 17:04:51 -0800 (PST) From: "Tuan Phan" To: devel@edk2.groups.io Cc: michael.d.kinney@intel.com, gaoliming@byosoft.com.cn, zhiguang.liu@intel.com, sunilvl@ventanamicro.com, git@danielschaefer.me, andrei.warkentin@intel.com, eric.dong@intel.com, kraxel@redhat.com, rahul1.kumar@intel.com, ray.ni@intel.com, Tuan Phan Subject: [edk2-devel] [PATCH] UefiCpuPkg: RISC-V: MMU: Support Svpbmt extension Date: Tue, 30 Jan 2024 17:04:43 -0800 Message-Id: <20240131010443.28552-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=fASIyez4; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io; dmarc=none The GCD EFI_MEMORY_UC and EFI_MEMORY_WC memory attributes will be supported when Svpbmt extension be available. Signed-off-by: Tuan Phan --- MdePkg/MdePkg.dec | 2 ++ OvmfPkg/RiscVVirt/RiscVVirt.dsc.inc | 2 +- .../Library/BaseRiscVMmuLib/BaseRiscVMmuLib.c | 25 ++++++++++++++++++- .../BaseRiscVMmuLib/BaseRiscVMmuLib.inf | 1 + 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec index 0459418906f8..6850acb96b92 100644 --- a/MdePkg/MdePkg.dec +++ b/MdePkg/MdePkg.dec @@ -2407,6 +2407,8 @@ # previous stage has feature enabled and user wants to disable it.=0D # BIT 1 =3D Supervisor Time Compare (Sstc). This bit is relevant only if= =0D # previous stage has feature enabled and user wants to disable it.=0D + # BIT 2 =3D Page-Based Memory Types (Pbmt). This bit is relevant only if= =0D + # previous stage has feature enabled and user wants to disable it.=0D #=0D gEfiMdePkgTokenSpaceGuid.PcdRiscVFeatureOverride|0xFFFFFFFFFFFFFFFF|UINT= 64|0x69=0D =0D diff --git a/OvmfPkg/RiscVVirt/RiscVVirt.dsc.inc b/OvmfPkg/RiscVVirt/RiscVV= irt.dsc.inc index 6bc7c90f31dc..b8338d2eb5f5 100644 --- a/OvmfPkg/RiscVVirt/RiscVVirt.dsc.inc +++ b/OvmfPkg/RiscVVirt/RiscVVirt.dsc.inc @@ -203,7 +203,7 @@ gEfiMdeModulePkgTokenSpaceGuid.PcdInstallAcpiSdtProtocol|TRUE=0D =0D [PcdsFixedAtBuild.common]=0D - gEfiMdePkgTokenSpaceGuid.PcdRiscVFeatureOverride|0xFFFFFFFFFFFFFFFC=0D + gEfiMdePkgTokenSpaceGuid.PcdRiscVFeatureOverride|0xFFFFFFFFFFFFFFF8=0D gEfiMdePkgTokenSpaceGuid.PcdMaximumUnicodeStringLength|1000000=0D gEfiMdePkgTokenSpaceGuid.PcdMaximumAsciiStringLength|1000000=0D gEfiMdePkgTokenSpaceGuid.PcdMaximumLinkedListLength|0=0D diff --git a/UefiCpuPkg/Library/BaseRiscVMmuLib/BaseRiscVMmuLib.c b/UefiCpu= Pkg/Library/BaseRiscVMmuLib/BaseRiscVMmuLib.c index 826a1d32a1d4..c50a28e97e4b 100644 --- a/UefiCpuPkg/Library/BaseRiscVMmuLib/BaseRiscVMmuLib.c +++ b/UefiCpuPkg/Library/BaseRiscVMmuLib/BaseRiscVMmuLib.c @@ -36,6 +36,15 @@ #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 +#define EFI_MEMORY_CACHETYPE_MASK (EFI_MEMORY_UC | EFI_MEMORY_WC | \=0D + EFI_MEMORY_WT | EFI_MEMORY_WB | \=0D + EFI_MEMORY_UCE)=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 @@ -514,6 +523,20 @@ GcdAttributeToPageAttribute ( RiscVAttributes &=3D ~RISCV_PG_X;=0D }=0D =0D + if ((PcdGet64 (PcdRiscVFeatureOverride) & RISCV_CPU_FEATURE_PBMT_BITMASK= ) !=3D 0) {=0D + switch (GcdAttributes & EFI_MEMORY_CACHETYPE_MASK) {=0D + case EFI_MEMORY_UC:=0D + RiscVAttributes |=3D PTE_PBMT_IO;=0D + break;=0D + case EFI_MEMORY_WC:=0D + RiscVAttributes |=3D PTE_PBMT_NC;=0D + break;=0D + default:=0D + // Default PMA mode=0D + break;=0D + }=0D + }=0D +=0D return RiscVAttributes;=0D }=0D =0D @@ -559,7 +582,7 @@ RiscVSetMemoryAttributes ( BaseAddress,=0D Length,=0D PageAttributesSet,=0D - PTE_ATTRIBUTES_MASK,=0D + PTE_ATTRIBUTES_MASK | PTE_PBMT_MASK,=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 (#114839): https://edk2.groups.io/g/devel/message/114839 Mute This Topic: https://groups.io/mt/104066781/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-