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 30E81740035 for ; Thu, 14 Mar 2024 20:19:34 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=aY+r9izR6ws9oC9aSwtk4i0uYlhetf/D/RsH3zesv8I=; 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:Resent-Date:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20240206; t=1710447572; v=1; b=BojA9J1XVHbvQSjzhPteNe8yScaGXVY9j6FFY90f9j3vOKO542fRq4XfMBNarMcmrG9U/O9M 18iMLTzcldj5omCrDytNmvYNqBYcaLdWIn654FcbTsRmForUa61XP4TSIW4KkszngRHM5Aok8/D U/xSyPK6PQKlRAIP8Iwjstbb6sbzqrehFXeNuU9/zieUlSbysXP5BojCoHiVPvbzu6IxYKUhuSC EYQsGUJMg2i2YDRY+ptlh21ho8Ehg+nYMuQS9ZlRRZakSzCSjue3gBGcMVOsyD+WDyoHfugB4F8 RLc0/47e69iQ5BluiTA44xKavVuz+7BSTU9wjupVcOQ8Q== X-Received: by 127.0.0.2 with SMTP id 2gcnYY7687511xgKcIgKbdAm; Thu, 14 Mar 2024 13:19:32 -0700 X-Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) by mx.groups.io with SMTP id smtpd.web11.3110.1710447567434997902 for ; Thu, 14 Mar 2024 13:19:27 -0700 X-Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-6e622b46f45so1173362b3a.1 for ; Thu, 14 Mar 2024 13:19:27 -0700 (PDT) X-Gm-Message-State: fj56wKZistSUE7UdTsBqZVWFx7686176AA= X-Google-Smtp-Source: AGHT+IEZG3E8ZnU6h5CL3s6unNIwEJoIQ5Ni29XrQUXm8NtqEAA7wUz/3H0Qahup3oSTe5/7YvUgQw== X-Received: by 2002:a05:6a21:318c:b0:1a1:67d6:9bc5 with SMTP id za12-20020a056a21318c00b001a167d69bc5mr1154376pzb.49.1710447566517; Thu, 14 Mar 2024 13:19:26 -0700 (PDT) X-Received: from localhost.localdomain (c-73-223-207-212.hsd1.ca.comcast.net. [73.223.207.212]) by smtp.gmail.com with ESMTPSA id y20-20020a63b514000000b005d34cf68664sm1135859pge.25.2024.03.14.13.19.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Mar 2024 13:19:26 -0700 (PDT) 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 v4 2/4] UefiCpuPkg: RISC-V: MMU: Explictly use UINT64 instead of UINTN Date: Thu, 14 Mar 2024 13:19:15 -0700 Message-Id: <20240314201917.1756-3-tphan@ventanamicro.com> In-Reply-To: <20240314201917.1756-1-tphan@ventanamicro.com> References: <20240314201917.1756-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 Resent-Date: Thu, 14 Mar 2024 13:19:32 -0700 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=20240206 header.b=BojA9J1X; 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 While UINTN defined for RISC-V 64 bits is UINT64, explictly using UINT64 for those variables that clearly are UINT64. Cc: Gerd Hoffmann Cc: Laszlo Ersek Cc: Rahul Kumar Cc: Ray Ni Signed-off-by: Tuan Phan --- .../Library/BaseRiscVMmuLib/BaseRiscVMmuLib.c | 158 +++++++++--------- 1 file changed, 76 insertions(+), 82 deletions(-) diff --git a/UefiCpuPkg/Library/BaseRiscVMmuLib/BaseRiscVMmuLib.c b/UefiCpu= Pkg/Library/BaseRiscVMmuLib/BaseRiscVMmuLib.c index 826a1d32a1d4..46ba4b4709b1 100644 --- a/UefiCpuPkg/Library/BaseRiscVMmuLib/BaseRiscVMmuLib.c +++ b/UefiCpuPkg/Library/BaseRiscVMmuLib/BaseRiscVMmuLib.c @@ -65,7 +65,7 @@ RiscVMmuEnabled ( =0D **/=0D STATIC=0D -UINTN=0D +UINT64=0D RiscVGetRootTranslateTable (=0D VOID=0D )=0D @@ -86,7 +86,7 @@ RiscVGetRootTranslateTable ( STATIC=0D BOOLEAN=0D IsValidPte (=0D - IN UINTN Entry=0D + IN UINT64 Entry=0D )=0D {=0D if (((Entry & RISCV_PG_V) =3D=3D 0) ||=0D @@ -107,9 +107,9 @@ IsValidPte ( =0D **/=0D STATIC=0D -UINTN=0D +UINT64=0D SetValidPte (=0D - IN UINTN Entry=0D + IN UINT64 Entry=0D )=0D {=0D /* Set Valid and Global mapping bits */=0D @@ -128,7 +128,7 @@ SetValidPte ( STATIC=0D BOOLEAN=0D IsBlockEntry (=0D - IN UINTN Entry=0D + IN UINT64 Entry=0D )=0D {=0D return IsValidPte (Entry) &&=0D @@ -147,7 +147,7 @@ IsBlockEntry ( STATIC=0D BOOLEAN=0D IsTableEntry (=0D - IN UINTN Entry=0D + IN UINT64 Entry=0D )=0D {=0D return IsValidPte (Entry) &&=0D @@ -163,13 +163,13 @@ IsTableEntry ( =0D **/=0D STATIC=0D -UINTN=0D +UINT64=0D SetTableEntry (=0D - IN UINTN Entry=0D + IN UINT64 Entry=0D )=0D {=0D Entry =3D SetValidPte (Entry);=0D - Entry &=3D ~(RISCV_PG_X | RISCV_PG_W | RISCV_PG_R);=0D + Entry &=3D ~(UINT64)(RISCV_PG_X | RISCV_PG_W | RISCV_PG_R);=0D =0D return Entry;=0D }=0D @@ -186,9 +186,9 @@ SetTableEntry ( STATIC=0D VOID=0D ReplaceTableEntry (=0D - IN UINTN *Entry,=0D - IN UINTN Value,=0D - IN UINTN RegionStart,=0D + IN UINT64 *Entry,=0D + IN UINT64 Value,=0D + IN UINT64 RegionStart,=0D IN BOOLEAN IsLiveBlockMapping=0D )=0D {=0D @@ -208,9 +208,9 @@ ReplaceTableEntry ( =0D **/=0D STATIC=0D -UINTN=0D +UINT64=0D GetPpnfromPte (=0D - IN UINTN Entry=0D + IN UINT64 Entry=0D )=0D {=0D return ((Entry & PTE_PPN_MASK) >> PTE_PPN_SHIFT);=0D @@ -226,13 +226,13 @@ GetPpnfromPte ( =0D **/=0D STATIC=0D -UINTN=0D +UINT64=0D SetPpnToPte (=0D - UINTN Entry,=0D - UINTN Address=0D + UINT64 Entry,=0D + UINT64 Address=0D )=0D {=0D - UINTN Ppn;=0D + UINT64 Ppn;=0D =0D Ppn =3D ((Address >> RISCV_MMU_PAGE_SHIFT) << PTE_PPN_SHIFT);=0D ASSERT (~(Ppn & ~PTE_PPN_MASK));=0D @@ -250,8 +250,8 @@ SetPpnToPte ( STATIC=0D VOID=0D FreePageTablesRecursive (=0D - IN UINTN *TranslationTable,=0D - IN UINTN Level=0D + IN UINT64 *TranslationTable,=0D + IN UINTN Level=0D )=0D {=0D UINTN Index;=0D @@ -260,8 +260,8 @@ FreePageTablesRecursive ( for (Index =3D 0; Index < mTableEntryCount; Index++) {=0D if (IsTableEntry (TranslationTable[Index])) {=0D FreePageTablesRecursive (=0D - (UINTN *)(GetPpnfromPte ((TranslationTable[Index])) <<=0D - RISCV_MMU_PAGE_SHIFT),=0D + (UINT64 *)(GetPpnfromPte ((TranslationTable[Index])) <<=0D + RISCV_MMU_PAGE_SHIFT),=0D Level + 1=0D );=0D }=0D @@ -289,22 +289,22 @@ FreePageTablesRecursive ( STATIC=0D EFI_STATUS=0D UpdateRegionMappingRecursive (=0D - IN UINTN RegionStart,=0D - IN UINTN RegionEnd,=0D - IN UINTN AttributeSetMask,=0D - IN UINTN AttributeClearMask,=0D - IN UINTN *PageTable,=0D + IN UINT64 RegionStart,=0D + IN UINT64 RegionEnd,=0D + IN UINT64 AttributeSetMask,=0D + IN UINT64 AttributeClearMask,=0D + IN UINT64 *PageTable,=0D IN UINTN Level,=0D IN BOOLEAN TableIsLive=0D )=0D {=0D EFI_STATUS Status;=0D - UINTN BlockShift;=0D - UINTN BlockMask;=0D - UINTN BlockEnd;=0D - UINTN *Entry;=0D - UINTN EntryValue;=0D - UINTN *TranslationTable;=0D + UINT64 BlockShift;=0D + UINT64 BlockMask;=0D + UINT64 BlockEnd;=0D + UINT64 *Entry;=0D + UINT64 EntryValue;=0D + UINT64 *TranslationTable;=0D BOOLEAN NextTableIsLive;=0D =0D ASSERT (Level < mMaxRootTableLevel);=0D @@ -313,18 +313,16 @@ UpdateRegionMappingRecursive ( BlockShift =3D (mMaxRootTableLevel - Level - 1) * mBitPerLevel + RISCV_M= MU_PAGE_SHIFT;=0D BlockMask =3D MAX_ADDRESS >> (64 - BlockShift);=0D =0D - DEBUG (=0D - (=0D - DEBUG_VERBOSE,=0D - "%a(%d): %llx - %llx set %lx clr %lx\n",=0D - __func__,=0D - Level,=0D - RegionStart,=0D - RegionEnd,=0D - AttributeSetMask,=0D - AttributeClearMask=0D - )=0D - );=0D + DEBUG ((=0D + DEBUG_VERBOSE,=0D + "%a(%d): %LX - %LX set %LX clr %LX\n",=0D + __func__,=0D + Level,=0D + RegionStart,=0D + RegionEnd,=0D + AttributeSetMask,=0D + AttributeClearMask=0D + ));=0D =0D for ( ; RegionStart < RegionEnd; RegionStart =3D BlockEnd) {=0D BlockEnd =3D MIN (RegionEnd, (RegionStart | BlockMask) + 1);=0D @@ -380,7 +378,7 @@ UpdateRegionMappingRecursive ( =0D NextTableIsLive =3D FALSE;=0D } else {=0D - TranslationTable =3D (UINTN *)(GetPpnfromPte (*Entry) << RISCV_MMU= _PAGE_SHIFT);=0D + TranslationTable =3D (UINT64 *)(GetPpnfromPte (*Entry) << RISCV_MM= U_PAGE_SHIFT);=0D NextTableIsLive =3D TableIsLive;=0D }=0D =0D @@ -412,7 +410,7 @@ UpdateRegionMappingRecursive ( }=0D =0D if (!IsTableEntry (*Entry)) {=0D - EntryValue =3D SetPpnToPte (0, (UINTN)TranslationTable);=0D + EntryValue =3D SetPpnToPte (0, (UINT64)TranslationTable);=0D EntryValue =3D SetTableEntry (EntryValue);=0D ReplaceTableEntry (=0D Entry,=0D @@ -463,11 +461,11 @@ UpdateRegionMappingRecursive ( STATIC=0D EFI_STATUS=0D UpdateRegionMapping (=0D - IN UINTN RegionStart,=0D - IN UINTN RegionLength,=0D - IN UINTN AttributeSetMask,=0D - IN UINTN AttributeClearMask,=0D - IN UINTN *RootTable,=0D + IN UINT64 RegionStart,=0D + IN UINT64 RegionLength,=0D + IN UINT64 AttributeSetMask,=0D + IN UINT64 AttributeClearMask,=0D + IN UINT64 *RootTable,=0D IN BOOLEAN TableIsLive=0D )=0D {=0D @@ -495,23 +493,23 @@ UpdateRegionMapping ( =0D **/=0D STATIC=0D -UINTN=0D +UINT64=0D GcdAttributeToPageAttribute (=0D - IN UINTN GcdAttributes=0D + IN UINT64 GcdAttributes=0D )=0D {=0D - UINTN RiscVAttributes;=0D + UINT64 RiscVAttributes;=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 ~(UINT64)(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 ~(UINT64)RISCV_PG_X;=0D }=0D =0D return RiscVAttributes;=0D @@ -533,11 +531,11 @@ EFI_STATUS EFIAPI=0D RiscVSetMemoryAttributes (=0D IN EFI_PHYSICAL_ADDRESS BaseAddress,=0D - IN UINTN Length,=0D - IN UINTN Attributes=0D + IN UINT64 Length,=0D + IN UINT64 Attributes=0D )=0D {=0D - UINTN PageAttributesSet;=0D + UINT64 PageAttributesSet;=0D =0D PageAttributesSet =3D GcdAttributeToPageAttribute (Attributes);=0D =0D @@ -560,7 +558,7 @@ RiscVSetMemoryAttributes ( Length,=0D PageAttributesSet,=0D PTE_ATTRIBUTES_MASK,=0D - (UINTN *)RiscVGetRootTranslateTable (),=0D + (UINT64 *)RiscVGetRootTranslateTable (),=0D TRUE=0D );=0D }=0D @@ -583,8 +581,8 @@ RiscVMmuSetSatpMode ( )=0D {=0D VOID *TranslationTable;=0D - UINTN SatpReg;=0D - UINTN Ppn;=0D + UINT64 SatpReg;=0D + UINT64 Ppn;=0D EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemoryMap;=0D UINTN NumberOfDescriptors;=0D UINTN Index;=0D @@ -622,7 +620,7 @@ RiscVMmuSetSatpMode ( return EFI_OUT_OF_RESOURCES;=0D }=0D =0D - ZeroMem (TranslationTable, mTableEntryCount * sizeof (UINTN));=0D + ZeroMem (TranslationTable, mTableEntryCount * sizeof (UINT64));=0D =0D NumberOfDescriptors =3D 0;=0D MemoryMap =3D NULL;=0D @@ -662,7 +660,7 @@ RiscVMmuSetSatpMode ( DisableInterrupts ();=0D }=0D =0D - Ppn =3D (UINTN)TranslationTable >> RISCV_MMU_PAGE_SHIFT;=0D + Ppn =3D (UINT64)TranslationTable >> RISCV_MMU_PAGE_SHIFT;=0D ASSERT (!(Ppn & ~(SATP64_PPN)));=0D =0D SatpReg =3D Ppn;=0D @@ -671,14 +669,12 @@ RiscVMmuSetSatpMode ( RiscVSetSupervisorAddressTranslationRegister (SatpReg);=0D /* Check if HW support the setup satp mode */=0D if (SatpReg !=3D RiscVGetSupervisorAddressTranslationRegister ()) {=0D - DEBUG (=0D - (=0D - DEBUG_VERBOSE,=0D - "%a: HW does not support SATP mode:%d\n",=0D - __func__,=0D - SatpMode=0D - )=0D - );=0D + DEBUG ((=0D + DEBUG_VERBOSE,=0D + "%a: HW does not support SATP mode:%d\n",=0D + __func__,=0D + SatpMode=0D + ));=0D FreePageTablesRecursive (TranslationTable, 0);=0D return EFI_DEVICE_ERROR;=0D }=0D @@ -706,7 +702,7 @@ RiscVConfigureMmu ( )=0D {=0D EFI_STATUS Status;=0D - INTN Idx;=0D + UINTN Idx;=0D =0D Status =3D EFI_SUCCESS;=0D =0D @@ -719,14 +715,12 @@ RiscVConfigureMmu ( return Status;=0D }=0D =0D - DEBUG (=0D - (=0D - DEBUG_INFO,=0D - "%a: SATP mode %d successfully configured\n",=0D - __func__,=0D - mModeSupport[Idx]=0D - )=0D - );=0D + DEBUG ((=0D + DEBUG_INFO,=0D + "%a: SATP mode %d successfully configured\n",=0D + __func__,=0D + mModeSupport[Idx]=0D + ));=0D break;=0D }=0D =0D --=20 2.25.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#116777): https://edk2.groups.io/g/devel/message/116777 Mute This Topic: https://groups.io/mt/104934688/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-