TianoCore EDK2 master
Loading...
Searching...
No Matches
BaseRiscVMmuLib.c File Reference

Go to the source code of this file.

Macros

#define RISCV_PG_V   BIT0
 
#define RISCV_PG_R   BIT1
 
#define RISCV_PG_W   BIT2
 
#define RISCV_PG_X   BIT3
 
#define RISCV_PG_G   BIT5
 
#define RISCV_PG_A   BIT6
 
#define RISCV_PG_D   BIT7
 
#define PTE_ATTRIBUTES_MASK   0xE
 
#define PTE_PPN_MASK   0x3FFFFFFFFFFC00ULL
 
#define PTE_PPN_SHIFT   10
 
#define RISCV_MMU_PAGE_SHIFT   12
 
#define RISCV_CPU_FEATURE_PBMT_BITMASK   BIT2
 
#define PTE_PBMT_NC   BIT61
 
#define PTE_PBMT_IO   BIT62
 
#define PTE_PBMT_MASK   (PTE_PBMT_NC | PTE_PBMT_IO)
 

Functions

STATIC BOOLEAN RiscVMmuEnabled (VOID)
 
STATIC UINT64 RiscVGetRootTranslateTable (VOID)
 
STATIC BOOLEAN IsValidPte (IN UINT64 Entry)
 
STATIC UINT64 SetValidPte (IN UINT64 Entry)
 
STATIC BOOLEAN IsBlockEntry (IN UINT64 Entry)
 
STATIC BOOLEAN IsTableEntry (IN UINT64 Entry)
 
STATIC UINT64 SetTableEntry (IN UINT64 Entry)
 
STATIC VOID ReplaceTableEntry (IN UINT64 *Entry, IN UINT64 Value, IN UINT64 RegionStart, IN BOOLEAN IsLiveBlockMapping)
 
STATIC UINT64 GetPpnfromPte (IN UINT64 Entry)
 
STATIC UINT64 SetPpnToPte (UINT64 Entry, UINT64 Address)
 
STATIC VOID FreePageTablesRecursive (IN UINT64 *TranslationTable, IN UINTN Level)
 
STATIC EFI_STATUS UpdateRegionMappingRecursive (IN UINT64 RegionStart, IN UINT64 RegionEnd, IN UINT64 AttributeSetMask, IN UINT64 AttributeClearMask, IN UINT64 *PageTable, IN UINTN Level, IN BOOLEAN TableIsLive)
 
STATIC EFI_STATUS UpdateRegionMapping (IN UINT64 RegionStart, IN UINT64 RegionLength, IN UINT64 AttributeSetMask, IN UINT64 AttributeClearMask, IN UINT64 *RootTable, IN BOOLEAN TableIsLive)
 
STATIC EFI_STATUS GcdAttributeToPageAttribute (IN UINT64 GcdAttributes, OUT UINT64 *RiscVAttributes)
 
EFI_STATUS EFIAPI RiscVSetMemoryAttributes (IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, IN UINT64 Attributes)
 
STATIC EFI_STATUS RiscVMmuSetSatpMode (UINTN SatpMode)
 
EFI_STATUS EFIAPI RiscVConfigureMmu (VOID)
 

Variables

STATIC UINTN mModeSupport [] = { SATP_MODE_SV57, SATP_MODE_SV48, SATP_MODE_SV39, SATP_MODE_OFF }
 
STATIC UINTN mMaxRootTableLevel
 
STATIC UINTN mBitPerLevel
 
STATIC UINTN mTableEntryCount
 

Detailed Description

MMU library for RISC-V.

Copyright (c) 2011-2020, ARM Limited. All rights reserved. Copyright (c) 2016, Linaro Limited. All rights reserved. Copyright (c) 2017, Intel Corporation. All rights reserved.
Copyright (c) 2023, Ventana Micro Systems Inc. All Rights Reserved.

SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file BaseRiscVMmuLib.c.

Macro Definition Documentation

◆ PTE_ATTRIBUTES_MASK

#define PTE_ATTRIBUTES_MASK   0xE

Definition at line 33 of file BaseRiscVMmuLib.c.

◆ PTE_PBMT_IO

#define PTE_PBMT_IO   BIT62

Definition at line 41 of file BaseRiscVMmuLib.c.

◆ PTE_PBMT_MASK

#define PTE_PBMT_MASK   (PTE_PBMT_NC | PTE_PBMT_IO)

Definition at line 42 of file BaseRiscVMmuLib.c.

◆ PTE_PBMT_NC

#define PTE_PBMT_NC   BIT61

Definition at line 40 of file BaseRiscVMmuLib.c.

◆ PTE_PPN_MASK

#define PTE_PPN_MASK   0x3FFFFFFFFFFC00ULL

Definition at line 35 of file BaseRiscVMmuLib.c.

◆ PTE_PPN_SHIFT

#define PTE_PPN_SHIFT   10

Definition at line 36 of file BaseRiscVMmuLib.c.

◆ RISCV_CPU_FEATURE_PBMT_BITMASK

#define RISCV_CPU_FEATURE_PBMT_BITMASK   BIT2

Definition at line 39 of file BaseRiscVMmuLib.c.

◆ RISCV_MMU_PAGE_SHIFT

#define RISCV_MMU_PAGE_SHIFT   12

Definition at line 37 of file BaseRiscVMmuLib.c.

◆ RISCV_PG_A

#define RISCV_PG_A   BIT6

Definition at line 31 of file BaseRiscVMmuLib.c.

◆ RISCV_PG_D

#define RISCV_PG_D   BIT7

Definition at line 32 of file BaseRiscVMmuLib.c.

◆ RISCV_PG_G

#define RISCV_PG_G   BIT5

Definition at line 30 of file BaseRiscVMmuLib.c.

◆ RISCV_PG_R

#define RISCV_PG_R   BIT1

Definition at line 27 of file BaseRiscVMmuLib.c.

◆ RISCV_PG_V

#define RISCV_PG_V   BIT0

Definition at line 26 of file BaseRiscVMmuLib.c.

◆ RISCV_PG_W

#define RISCV_PG_W   BIT2

Definition at line 28 of file BaseRiscVMmuLib.c.

◆ RISCV_PG_X

#define RISCV_PG_X   BIT3

Definition at line 29 of file BaseRiscVMmuLib.c.

Function Documentation

◆ FreePageTablesRecursive()

STATIC VOID FreePageTablesRecursive ( IN UINT64 *  TranslationTable,
IN UINTN  Level 
)

Free resources of translation table recursively.

Parameters
TranslationTableThe pointer of table.
LevelThe current level.

Definition at line 257 of file BaseRiscVMmuLib.c.

◆ GcdAttributeToPageAttribute()

STATIC EFI_STATUS GcdAttributeToPageAttribute ( IN UINT64  GcdAttributes,
OUT UINT64 *  RiscVAttributes 
)

Convert GCD attribute to RISC-V page attribute.

Parameters
GcdAttributesThe GCD attribute.
RiscVAttributesThe pointer of RISC-V page attribute.
Return values
EFI_INVALID_PARAMETERThe RiscVAttributes is NULL or cache type mask not valid.
EFI_SUCCESSThe operation succesfully.

Definition at line 504 of file BaseRiscVMmuLib.c.

◆ GetPpnfromPte()

STATIC UINT64 GetPpnfromPte ( IN UINT64  Entry)

Get an ppn value from an entry.

Parameters
EntryThe entry value.
Returns
The ppn value.

Definition at line 217 of file BaseRiscVMmuLib.c.

◆ IsBlockEntry()

STATIC BOOLEAN IsBlockEntry ( IN UINT64  Entry)

Determine if an entry is a block pte.

Parameters
EntryThe entry value.
Return values
TRUEThe entry is a block pte.
FALSEThe entry is not a block pte.

Definition at line 135 of file BaseRiscVMmuLib.c.

◆ IsTableEntry()

STATIC BOOLEAN IsTableEntry ( IN UINT64  Entry)

Determine if an entry is a table pte.

Parameters
EntryThe entry value.
Return values
TRUEThe entry is a table pte.
FALSEThe entry is not a table pte.

Definition at line 154 of file BaseRiscVMmuLib.c.

◆ IsValidPte()

STATIC BOOLEAN IsValidPte ( IN UINT64  Entry)

Determine if an entry is valid pte.

Parameters
EntryThe entry value.
Return values
TRUEThe entry is a valid pte.
FALSEThe entry is not a valid pte.

Definition at line 93 of file BaseRiscVMmuLib.c.

◆ ReplaceTableEntry()

STATIC VOID ReplaceTableEntry ( IN UINT64 *  Entry,
IN UINT64  Value,
IN UINT64  RegionStart,
IN BOOLEAN  IsLiveBlockMapping 
)

Replace an existing entry with new value.

Parameters
EntryThe entry pointer.
ValueThe new entry value.
RegionStartThe start of region that new value affects.
IsLiveBlockMappingTRUE if this is live update, FALSE otherwise.

Definition at line 193 of file BaseRiscVMmuLib.c.

◆ RiscVConfigureMmu()

EFI_STATUS EFIAPI RiscVConfigureMmu ( VOID  )

The API to configure and enable RISC-V MMU with the highest mode supported.

Return values
EFI_OUT_OF_RESOURCESNot enough resource.
EFI_SUCCESSThe operation succesfully.

Definition at line 764 of file BaseRiscVMmuLib.c.

◆ RiscVGetRootTranslateTable()

STATIC UINT64 RiscVGetRootTranslateTable ( VOID  )

Retrieve the root translate table.

Returns
The root translate table.

Definition at line 74 of file BaseRiscVMmuLib.c.

◆ RiscVMmuEnabled()

STATIC BOOLEAN RiscVMmuEnabled ( VOID  )

Determine if the MMU enabled or not.

Return values
TRUEThe MMU already enabled.
FALSEThe MMU not enabled.

Definition at line 58 of file BaseRiscVMmuLib.c.

◆ RiscVMmuSetSatpMode()

STATIC EFI_STATUS RiscVMmuSetSatpMode ( UINTN  SatpMode)

Set SATP mode.

Parameters
SatpModeThe SATP mode to be set.
Return values
EFI_INVALID_PARAMETERThe SATP mode was not valid.
EFI_OUT_OF_RESOURCESNot enough resource.
EFI_DEVICE_ERRORThe SATP mode not supported by HW.
EFI_SUCCESSThe operation succesfully.

Definition at line 643 of file BaseRiscVMmuLib.c.

◆ RiscVSetMemoryAttributes()

EFI_STATUS EFIAPI RiscVSetMemoryAttributes ( IN EFI_PHYSICAL_ADDRESS  BaseAddress,
IN UINT64  Length,
IN UINT64  Attributes 
)

The API to set a GCD attribute on an memory region.

Parameters
BaseAddressThe base address of the region.
LengthThe length of the region.
AttributesThe GCD attributes.
Return values
EFI_INVALID_PARAMETERThe BaseAddress or Length was not valid.
EFI_OUT_OF_RESOURCESNot enough resource.
EFI_SUCCESSThe operation succesfully.

Definition at line 587 of file BaseRiscVMmuLib.c.

◆ SetPpnToPte()

STATIC UINT64 SetPpnToPte ( UINT64  Entry,
UINT64  Address 
)

Set an ppn value to a entry.

Parameters
EntryThe entry value.
AddressThe address.
Returns
The new entry value.

Definition at line 235 of file BaseRiscVMmuLib.c.

◆ SetTableEntry()

STATIC UINT64 SetTableEntry ( IN UINT64  Entry)

Set an entry to be a table pte.

Parameters
EntryThe entry value.
Returns
The entry value.

Definition at line 172 of file BaseRiscVMmuLib.c.

◆ SetValidPte()

STATIC UINT64 SetValidPte ( IN UINT64  Entry)

Set an entry to be a valid pte.

Parameters
EntryThe entry value.
Returns
The entry value.

Definition at line 116 of file BaseRiscVMmuLib.c.

◆ UpdateRegionMapping()

STATIC EFI_STATUS UpdateRegionMapping ( IN UINT64  RegionStart,
IN UINT64  RegionLength,
IN UINT64  AttributeSetMask,
IN UINT64  AttributeClearMask,
IN UINT64 *  RootTable,
IN BOOLEAN  TableIsLive 
)

Update region mapping at root table.

Parameters
RegionStartThe start address of the region.
RegionLengthThe length of the region.
AttributeSetMaskThe attribute mask to be set.
AttributeClearMaskThe attribute mask to be clear.
RootTableThe pointer of root table.
TableIsLiveTRUE if this is live update, FALSE otherwise.
Return values
EFI_INVALID_PARAMETERThe RegionStart or RegionLength was not valid.
EFI_OUT_OF_RESOURCESNot enough resource.
EFI_SUCCESSThe operation succesfully.

Definition at line 468 of file BaseRiscVMmuLib.c.

◆ UpdateRegionMappingRecursive()

STATIC EFI_STATUS UpdateRegionMappingRecursive ( IN UINT64  RegionStart,
IN UINT64  RegionEnd,
IN UINT64  AttributeSetMask,
IN UINT64  AttributeClearMask,
IN UINT64 *  PageTable,
IN UINTN  Level,
IN BOOLEAN  TableIsLive 
)

Update region mapping recursively.

Parameters
RegionStartThe start address of the region.
RegionEndThe end address of the region.
AttributeSetMaskThe attribute mask to be set.
AttributeClearMaskThe attribute mask to be clear.
PageTableThe pointer of current page table.
LevelThe current level.
TableIsLiveTRUE if this is live update, FALSE otherwise.
Return values
EFI_OUT_OF_RESOURCESNot enough resource.
EFI_SUCCESSThe operation succesfully.

Definition at line 296 of file BaseRiscVMmuLib.c.

Variable Documentation

◆ mBitPerLevel

STATIC UINTN mBitPerLevel

Definition at line 46 of file BaseRiscVMmuLib.c.

◆ mMaxRootTableLevel

STATIC UINTN mMaxRootTableLevel

Definition at line 45 of file BaseRiscVMmuLib.c.

◆ mModeSupport

STATIC UINTN mModeSupport[] = { SATP_MODE_SV57, SATP_MODE_SV48, SATP_MODE_SV39, SATP_MODE_OFF }

Definition at line 44 of file BaseRiscVMmuLib.c.

◆ mTableEntryCount

STATIC UINTN mTableEntryCount

Definition at line 47 of file BaseRiscVMmuLib.c.