mirror of
https://github.com/acidanthera/audk.git
synced 2025-07-24 06:04:52 +02:00
UefiCpuPkg: RISC-V: MMU: Explictly use UINT64 instead of UINTN
While UINTN defined for RISC-V 64 bits is UINT64, explictly using UINT64 for those variables that clearly are UINT64. Cc: Gerd Hoffmann <kraxel@redhat.com> Cc: Laszlo Ersek <lersek@redhat.com> Cc: Rahul Kumar <rahul1.kumar@intel.com> Cc: Ray Ni <ray.ni@intel.com> Signed-off-by: Tuan Phan <tphan@ventanamicro.com> Reviewed-by: Sunil V L <sunilvl@ventanamicro.com>
This commit is contained in:
parent
f1203a4099
commit
6ddfbeb0d6
@ -65,7 +65,7 @@ RiscVMmuEnabled (
|
|||||||
|
|
||||||
**/
|
**/
|
||||||
STATIC
|
STATIC
|
||||||
UINTN
|
UINT64
|
||||||
RiscVGetRootTranslateTable (
|
RiscVGetRootTranslateTable (
|
||||||
VOID
|
VOID
|
||||||
)
|
)
|
||||||
@ -86,7 +86,7 @@ RiscVGetRootTranslateTable (
|
|||||||
STATIC
|
STATIC
|
||||||
BOOLEAN
|
BOOLEAN
|
||||||
IsValidPte (
|
IsValidPte (
|
||||||
IN UINTN Entry
|
IN UINT64 Entry
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (((Entry & RISCV_PG_V) == 0) ||
|
if (((Entry & RISCV_PG_V) == 0) ||
|
||||||
@ -107,9 +107,9 @@ IsValidPte (
|
|||||||
|
|
||||||
**/
|
**/
|
||||||
STATIC
|
STATIC
|
||||||
UINTN
|
UINT64
|
||||||
SetValidPte (
|
SetValidPte (
|
||||||
IN UINTN Entry
|
IN UINT64 Entry
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
/* Set Valid and Global mapping bits */
|
/* Set Valid and Global mapping bits */
|
||||||
@ -128,7 +128,7 @@ SetValidPte (
|
|||||||
STATIC
|
STATIC
|
||||||
BOOLEAN
|
BOOLEAN
|
||||||
IsBlockEntry (
|
IsBlockEntry (
|
||||||
IN UINTN Entry
|
IN UINT64 Entry
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return IsValidPte (Entry) &&
|
return IsValidPte (Entry) &&
|
||||||
@ -147,7 +147,7 @@ IsBlockEntry (
|
|||||||
STATIC
|
STATIC
|
||||||
BOOLEAN
|
BOOLEAN
|
||||||
IsTableEntry (
|
IsTableEntry (
|
||||||
IN UINTN Entry
|
IN UINT64 Entry
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return IsValidPte (Entry) &&
|
return IsValidPte (Entry) &&
|
||||||
@ -163,13 +163,13 @@ IsTableEntry (
|
|||||||
|
|
||||||
**/
|
**/
|
||||||
STATIC
|
STATIC
|
||||||
UINTN
|
UINT64
|
||||||
SetTableEntry (
|
SetTableEntry (
|
||||||
IN UINTN Entry
|
IN UINT64 Entry
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
Entry = SetValidPte (Entry);
|
Entry = SetValidPte (Entry);
|
||||||
Entry &= ~(RISCV_PG_X | RISCV_PG_W | RISCV_PG_R);
|
Entry &= ~(UINT64)(RISCV_PG_X | RISCV_PG_W | RISCV_PG_R);
|
||||||
|
|
||||||
return Entry;
|
return Entry;
|
||||||
}
|
}
|
||||||
@ -186,9 +186,9 @@ SetTableEntry (
|
|||||||
STATIC
|
STATIC
|
||||||
VOID
|
VOID
|
||||||
ReplaceTableEntry (
|
ReplaceTableEntry (
|
||||||
IN UINTN *Entry,
|
IN UINT64 *Entry,
|
||||||
IN UINTN Value,
|
IN UINT64 Value,
|
||||||
IN UINTN RegionStart,
|
IN UINT64 RegionStart,
|
||||||
IN BOOLEAN IsLiveBlockMapping
|
IN BOOLEAN IsLiveBlockMapping
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@ -208,9 +208,9 @@ ReplaceTableEntry (
|
|||||||
|
|
||||||
**/
|
**/
|
||||||
STATIC
|
STATIC
|
||||||
UINTN
|
UINT64
|
||||||
GetPpnfromPte (
|
GetPpnfromPte (
|
||||||
IN UINTN Entry
|
IN UINT64 Entry
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return ((Entry & PTE_PPN_MASK) >> PTE_PPN_SHIFT);
|
return ((Entry & PTE_PPN_MASK) >> PTE_PPN_SHIFT);
|
||||||
@ -226,13 +226,13 @@ GetPpnfromPte (
|
|||||||
|
|
||||||
**/
|
**/
|
||||||
STATIC
|
STATIC
|
||||||
UINTN
|
UINT64
|
||||||
SetPpnToPte (
|
SetPpnToPte (
|
||||||
UINTN Entry,
|
UINT64 Entry,
|
||||||
UINTN Address
|
UINT64 Address
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
UINTN Ppn;
|
UINT64 Ppn;
|
||||||
|
|
||||||
Ppn = ((Address >> RISCV_MMU_PAGE_SHIFT) << PTE_PPN_SHIFT);
|
Ppn = ((Address >> RISCV_MMU_PAGE_SHIFT) << PTE_PPN_SHIFT);
|
||||||
ASSERT (~(Ppn & ~PTE_PPN_MASK));
|
ASSERT (~(Ppn & ~PTE_PPN_MASK));
|
||||||
@ -250,8 +250,8 @@ SetPpnToPte (
|
|||||||
STATIC
|
STATIC
|
||||||
VOID
|
VOID
|
||||||
FreePageTablesRecursive (
|
FreePageTablesRecursive (
|
||||||
IN UINTN *TranslationTable,
|
IN UINT64 *TranslationTable,
|
||||||
IN UINTN Level
|
IN UINTN Level
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
UINTN Index;
|
UINTN Index;
|
||||||
@ -260,8 +260,8 @@ FreePageTablesRecursive (
|
|||||||
for (Index = 0; Index < mTableEntryCount; Index++) {
|
for (Index = 0; Index < mTableEntryCount; Index++) {
|
||||||
if (IsTableEntry (TranslationTable[Index])) {
|
if (IsTableEntry (TranslationTable[Index])) {
|
||||||
FreePageTablesRecursive (
|
FreePageTablesRecursive (
|
||||||
(UINTN *)(GetPpnfromPte ((TranslationTable[Index])) <<
|
(UINT64 *)(GetPpnfromPte ((TranslationTable[Index])) <<
|
||||||
RISCV_MMU_PAGE_SHIFT),
|
RISCV_MMU_PAGE_SHIFT),
|
||||||
Level + 1
|
Level + 1
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -289,22 +289,22 @@ FreePageTablesRecursive (
|
|||||||
STATIC
|
STATIC
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
UpdateRegionMappingRecursive (
|
UpdateRegionMappingRecursive (
|
||||||
IN UINTN RegionStart,
|
IN UINT64 RegionStart,
|
||||||
IN UINTN RegionEnd,
|
IN UINT64 RegionEnd,
|
||||||
IN UINTN AttributeSetMask,
|
IN UINT64 AttributeSetMask,
|
||||||
IN UINTN AttributeClearMask,
|
IN UINT64 AttributeClearMask,
|
||||||
IN UINTN *PageTable,
|
IN UINT64 *PageTable,
|
||||||
IN UINTN Level,
|
IN UINTN Level,
|
||||||
IN BOOLEAN TableIsLive
|
IN BOOLEAN TableIsLive
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
UINTN BlockShift;
|
UINT64 BlockShift;
|
||||||
UINTN BlockMask;
|
UINT64 BlockMask;
|
||||||
UINTN BlockEnd;
|
UINT64 BlockEnd;
|
||||||
UINTN *Entry;
|
UINT64 *Entry;
|
||||||
UINTN EntryValue;
|
UINT64 EntryValue;
|
||||||
UINTN *TranslationTable;
|
UINT64 *TranslationTable;
|
||||||
BOOLEAN NextTableIsLive;
|
BOOLEAN NextTableIsLive;
|
||||||
|
|
||||||
ASSERT (Level < mMaxRootTableLevel);
|
ASSERT (Level < mMaxRootTableLevel);
|
||||||
@ -313,18 +313,16 @@ UpdateRegionMappingRecursive (
|
|||||||
BlockShift = (mMaxRootTableLevel - Level - 1) * mBitPerLevel + RISCV_MMU_PAGE_SHIFT;
|
BlockShift = (mMaxRootTableLevel - Level - 1) * mBitPerLevel + RISCV_MMU_PAGE_SHIFT;
|
||||||
BlockMask = MAX_ADDRESS >> (64 - BlockShift);
|
BlockMask = MAX_ADDRESS >> (64 - BlockShift);
|
||||||
|
|
||||||
DEBUG (
|
DEBUG ((
|
||||||
(
|
DEBUG_VERBOSE,
|
||||||
DEBUG_VERBOSE,
|
"%a(%d): %LX - %LX set %LX clr %LX\n",
|
||||||
"%a(%d): %llx - %llx set %lx clr %lx\n",
|
__func__,
|
||||||
__func__,
|
Level,
|
||||||
Level,
|
RegionStart,
|
||||||
RegionStart,
|
RegionEnd,
|
||||||
RegionEnd,
|
AttributeSetMask,
|
||||||
AttributeSetMask,
|
AttributeClearMask
|
||||||
AttributeClearMask
|
));
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
for ( ; RegionStart < RegionEnd; RegionStart = BlockEnd) {
|
for ( ; RegionStart < RegionEnd; RegionStart = BlockEnd) {
|
||||||
BlockEnd = MIN (RegionEnd, (RegionStart | BlockMask) + 1);
|
BlockEnd = MIN (RegionEnd, (RegionStart | BlockMask) + 1);
|
||||||
@ -380,7 +378,7 @@ UpdateRegionMappingRecursive (
|
|||||||
|
|
||||||
NextTableIsLive = FALSE;
|
NextTableIsLive = FALSE;
|
||||||
} else {
|
} else {
|
||||||
TranslationTable = (UINTN *)(GetPpnfromPte (*Entry) << RISCV_MMU_PAGE_SHIFT);
|
TranslationTable = (UINT64 *)(GetPpnfromPte (*Entry) << RISCV_MMU_PAGE_SHIFT);
|
||||||
NextTableIsLive = TableIsLive;
|
NextTableIsLive = TableIsLive;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -412,7 +410,7 @@ UpdateRegionMappingRecursive (
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!IsTableEntry (*Entry)) {
|
if (!IsTableEntry (*Entry)) {
|
||||||
EntryValue = SetPpnToPte (0, (UINTN)TranslationTable);
|
EntryValue = SetPpnToPte (0, (UINT64)TranslationTable);
|
||||||
EntryValue = SetTableEntry (EntryValue);
|
EntryValue = SetTableEntry (EntryValue);
|
||||||
ReplaceTableEntry (
|
ReplaceTableEntry (
|
||||||
Entry,
|
Entry,
|
||||||
@ -463,11 +461,11 @@ UpdateRegionMappingRecursive (
|
|||||||
STATIC
|
STATIC
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
UpdateRegionMapping (
|
UpdateRegionMapping (
|
||||||
IN UINTN RegionStart,
|
IN UINT64 RegionStart,
|
||||||
IN UINTN RegionLength,
|
IN UINT64 RegionLength,
|
||||||
IN UINTN AttributeSetMask,
|
IN UINT64 AttributeSetMask,
|
||||||
IN UINTN AttributeClearMask,
|
IN UINT64 AttributeClearMask,
|
||||||
IN UINTN *RootTable,
|
IN UINT64 *RootTable,
|
||||||
IN BOOLEAN TableIsLive
|
IN BOOLEAN TableIsLive
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@ -495,23 +493,23 @@ UpdateRegionMapping (
|
|||||||
|
|
||||||
**/
|
**/
|
||||||
STATIC
|
STATIC
|
||||||
UINTN
|
UINT64
|
||||||
GcdAttributeToPageAttribute (
|
GcdAttributeToPageAttribute (
|
||||||
IN UINTN GcdAttributes
|
IN UINT64 GcdAttributes
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
UINTN RiscVAttributes;
|
UINT64 RiscVAttributes;
|
||||||
|
|
||||||
RiscVAttributes = RISCV_PG_R | RISCV_PG_W | RISCV_PG_X;
|
RiscVAttributes = RISCV_PG_R | RISCV_PG_W | RISCV_PG_X;
|
||||||
|
|
||||||
// Determine protection attributes
|
// Determine protection attributes
|
||||||
if ((GcdAttributes & EFI_MEMORY_RO) != 0) {
|
if ((GcdAttributes & EFI_MEMORY_RO) != 0) {
|
||||||
RiscVAttributes &= ~(RISCV_PG_W);
|
RiscVAttributes &= ~(UINT64)(RISCV_PG_W);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process eXecute Never attribute
|
// Process eXecute Never attribute
|
||||||
if ((GcdAttributes & EFI_MEMORY_XP) != 0) {
|
if ((GcdAttributes & EFI_MEMORY_XP) != 0) {
|
||||||
RiscVAttributes &= ~RISCV_PG_X;
|
RiscVAttributes &= ~(UINT64)RISCV_PG_X;
|
||||||
}
|
}
|
||||||
|
|
||||||
return RiscVAttributes;
|
return RiscVAttributes;
|
||||||
@ -533,11 +531,11 @@ EFI_STATUS
|
|||||||
EFIAPI
|
EFIAPI
|
||||||
RiscVSetMemoryAttributes (
|
RiscVSetMemoryAttributes (
|
||||||
IN EFI_PHYSICAL_ADDRESS BaseAddress,
|
IN EFI_PHYSICAL_ADDRESS BaseAddress,
|
||||||
IN UINTN Length,
|
IN UINT64 Length,
|
||||||
IN UINTN Attributes
|
IN UINT64 Attributes
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
UINTN PageAttributesSet;
|
UINT64 PageAttributesSet;
|
||||||
|
|
||||||
PageAttributesSet = GcdAttributeToPageAttribute (Attributes);
|
PageAttributesSet = GcdAttributeToPageAttribute (Attributes);
|
||||||
|
|
||||||
@ -560,7 +558,7 @@ RiscVSetMemoryAttributes (
|
|||||||
Length,
|
Length,
|
||||||
PageAttributesSet,
|
PageAttributesSet,
|
||||||
PTE_ATTRIBUTES_MASK,
|
PTE_ATTRIBUTES_MASK,
|
||||||
(UINTN *)RiscVGetRootTranslateTable (),
|
(UINT64 *)RiscVGetRootTranslateTable (),
|
||||||
TRUE
|
TRUE
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -583,8 +581,8 @@ RiscVMmuSetSatpMode (
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
VOID *TranslationTable;
|
VOID *TranslationTable;
|
||||||
UINTN SatpReg;
|
UINT64 SatpReg;
|
||||||
UINTN Ppn;
|
UINT64 Ppn;
|
||||||
EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemoryMap;
|
EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemoryMap;
|
||||||
UINTN NumberOfDescriptors;
|
UINTN NumberOfDescriptors;
|
||||||
UINTN Index;
|
UINTN Index;
|
||||||
@ -622,7 +620,7 @@ RiscVMmuSetSatpMode (
|
|||||||
return EFI_OUT_OF_RESOURCES;
|
return EFI_OUT_OF_RESOURCES;
|
||||||
}
|
}
|
||||||
|
|
||||||
ZeroMem (TranslationTable, mTableEntryCount * sizeof (UINTN));
|
ZeroMem (TranslationTable, mTableEntryCount * sizeof (UINT64));
|
||||||
|
|
||||||
NumberOfDescriptors = 0;
|
NumberOfDescriptors = 0;
|
||||||
MemoryMap = NULL;
|
MemoryMap = NULL;
|
||||||
@ -662,7 +660,7 @@ RiscVMmuSetSatpMode (
|
|||||||
DisableInterrupts ();
|
DisableInterrupts ();
|
||||||
}
|
}
|
||||||
|
|
||||||
Ppn = (UINTN)TranslationTable >> RISCV_MMU_PAGE_SHIFT;
|
Ppn = (UINT64)TranslationTable >> RISCV_MMU_PAGE_SHIFT;
|
||||||
ASSERT (!(Ppn & ~(SATP64_PPN)));
|
ASSERT (!(Ppn & ~(SATP64_PPN)));
|
||||||
|
|
||||||
SatpReg = Ppn;
|
SatpReg = Ppn;
|
||||||
@ -671,14 +669,12 @@ RiscVMmuSetSatpMode (
|
|||||||
RiscVSetSupervisorAddressTranslationRegister (SatpReg);
|
RiscVSetSupervisorAddressTranslationRegister (SatpReg);
|
||||||
/* Check if HW support the setup satp mode */
|
/* Check if HW support the setup satp mode */
|
||||||
if (SatpReg != RiscVGetSupervisorAddressTranslationRegister ()) {
|
if (SatpReg != RiscVGetSupervisorAddressTranslationRegister ()) {
|
||||||
DEBUG (
|
DEBUG ((
|
||||||
(
|
DEBUG_VERBOSE,
|
||||||
DEBUG_VERBOSE,
|
"%a: HW does not support SATP mode:%d\n",
|
||||||
"%a: HW does not support SATP mode:%d\n",
|
__func__,
|
||||||
__func__,
|
SatpMode
|
||||||
SatpMode
|
));
|
||||||
)
|
|
||||||
);
|
|
||||||
FreePageTablesRecursive (TranslationTable, 0);
|
FreePageTablesRecursive (TranslationTable, 0);
|
||||||
return EFI_DEVICE_ERROR;
|
return EFI_DEVICE_ERROR;
|
||||||
}
|
}
|
||||||
@ -706,7 +702,7 @@ RiscVConfigureMmu (
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
INTN Idx;
|
UINTN Idx;
|
||||||
|
|
||||||
Status = EFI_SUCCESS;
|
Status = EFI_SUCCESS;
|
||||||
|
|
||||||
@ -719,14 +715,12 @@ RiscVConfigureMmu (
|
|||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
DEBUG (
|
DEBUG ((
|
||||||
(
|
DEBUG_INFO,
|
||||||
DEBUG_INFO,
|
"%a: SATP mode %d successfully configured\n",
|
||||||
"%a: SATP mode %d successfully configured\n",
|
__func__,
|
||||||
__func__,
|
mModeSupport[Idx]
|
||||||
mModeSupport[Idx]
|
));
|
||||||
)
|
|
||||||
);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user