TianoCore EDK2 master
|
#include <PiDxe.h>
#include <Uefi.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/BaseRiscVMmuLib.h>
#include <Library/CacheMaintenanceLib.h>
#include <Library/DebugLib.h>
#include <Library/DxeServicesTableLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/PcdLib.h>
#include <Register/RiscV64/RiscVEncoding.h>
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 |
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.
#define PTE_ATTRIBUTES_MASK 0xE |
Definition at line 33 of file BaseRiscVMmuLib.c.
#define PTE_PBMT_IO BIT62 |
Definition at line 41 of file BaseRiscVMmuLib.c.
#define PTE_PBMT_MASK (PTE_PBMT_NC | PTE_PBMT_IO) |
Definition at line 42 of file BaseRiscVMmuLib.c.
#define PTE_PBMT_NC BIT61 |
Definition at line 40 of file BaseRiscVMmuLib.c.
#define PTE_PPN_MASK 0x3FFFFFFFFFFC00ULL |
Definition at line 35 of file BaseRiscVMmuLib.c.
#define PTE_PPN_SHIFT 10 |
Definition at line 36 of file BaseRiscVMmuLib.c.
#define RISCV_CPU_FEATURE_PBMT_BITMASK BIT2 |
Definition at line 39 of file BaseRiscVMmuLib.c.
#define RISCV_MMU_PAGE_SHIFT 12 |
Definition at line 37 of file BaseRiscVMmuLib.c.
#define RISCV_PG_A BIT6 |
Definition at line 31 of file BaseRiscVMmuLib.c.
#define RISCV_PG_D BIT7 |
Definition at line 32 of file BaseRiscVMmuLib.c.
#define RISCV_PG_G BIT5 |
Definition at line 30 of file BaseRiscVMmuLib.c.
#define RISCV_PG_R BIT1 |
Definition at line 27 of file BaseRiscVMmuLib.c.
#define RISCV_PG_V BIT0 |
Definition at line 26 of file BaseRiscVMmuLib.c.
#define RISCV_PG_W BIT2 |
Definition at line 28 of file BaseRiscVMmuLib.c.
#define RISCV_PG_X BIT3 |
Definition at line 29 of file BaseRiscVMmuLib.c.
Free resources of translation table recursively.
TranslationTable | The pointer of table. |
Level | The current level. |
Definition at line 257 of file BaseRiscVMmuLib.c.
STATIC EFI_STATUS GcdAttributeToPageAttribute | ( | IN UINT64 | GcdAttributes, |
OUT UINT64 * | RiscVAttributes | ||
) |
Convert GCD attribute to RISC-V page attribute.
GcdAttributes | The GCD attribute. |
RiscVAttributes | The pointer of RISC-V page attribute. |
EFI_INVALID_PARAMETER | The RiscVAttributes is NULL or cache type mask not valid. |
EFI_SUCCESS | The operation succesfully. |
Definition at line 504 of file BaseRiscVMmuLib.c.
Get an ppn value from an entry.
Entry | The entry value. |
Definition at line 217 of file BaseRiscVMmuLib.c.
Determine if an entry is a block pte.
Entry | The entry value. |
TRUE | The entry is a block pte. |
FALSE | The entry is not a block pte. |
Definition at line 135 of file BaseRiscVMmuLib.c.
Determine if an entry is a table pte.
Entry | The entry value. |
TRUE | The entry is a table pte. |
FALSE | The entry is not a table pte. |
Definition at line 154 of file BaseRiscVMmuLib.c.
Determine if an entry is valid pte.
Entry | The entry value. |
TRUE | The entry is a valid pte. |
FALSE | The entry is not a valid pte. |
Definition at line 93 of file BaseRiscVMmuLib.c.
STATIC VOID ReplaceTableEntry | ( | IN UINT64 * | Entry, |
IN UINT64 | Value, | ||
IN UINT64 | RegionStart, | ||
IN BOOLEAN | IsLiveBlockMapping | ||
) |
Replace an existing entry with new value.
Entry | The entry pointer. |
Value | The new entry value. |
RegionStart | The start of region that new value affects. |
IsLiveBlockMapping | TRUE if this is live update, FALSE otherwise. |
Definition at line 193 of file BaseRiscVMmuLib.c.
EFI_STATUS EFIAPI RiscVConfigureMmu | ( | VOID | ) |
The API to configure and enable RISC-V MMU with the highest mode supported.
EFI_OUT_OF_RESOURCES | Not enough resource. |
EFI_SUCCESS | The operation succesfully. |
Definition at line 764 of file BaseRiscVMmuLib.c.
STATIC UINT64 RiscVGetRootTranslateTable | ( | VOID | ) |
Retrieve the root translate table.
Definition at line 74 of file BaseRiscVMmuLib.c.
STATIC BOOLEAN RiscVMmuEnabled | ( | VOID | ) |
Determine if the MMU enabled or not.
TRUE | The MMU already enabled. |
FALSE | The MMU not enabled. |
Definition at line 58 of file BaseRiscVMmuLib.c.
STATIC EFI_STATUS RiscVMmuSetSatpMode | ( | UINTN | SatpMode | ) |
Set SATP mode.
SatpMode | The SATP mode to be set. |
EFI_INVALID_PARAMETER | The SATP mode was not valid. |
EFI_OUT_OF_RESOURCES | Not enough resource. |
EFI_DEVICE_ERROR | The SATP mode not supported by HW. |
EFI_SUCCESS | The operation succesfully. |
Definition at line 643 of file BaseRiscVMmuLib.c.
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.
BaseAddress | The base address of the region. |
Length | The length of the region. |
Attributes | The GCD attributes. |
EFI_INVALID_PARAMETER | The BaseAddress or Length was not valid. |
EFI_OUT_OF_RESOURCES | Not enough resource. |
EFI_SUCCESS | The operation succesfully. |
Definition at line 587 of file BaseRiscVMmuLib.c.
STATIC UINT64 SetPpnToPte | ( | UINT64 | Entry, |
UINT64 | Address | ||
) |
Set an ppn value to a entry.
Entry | The entry value. |
Address | The address. |
Definition at line 235 of file BaseRiscVMmuLib.c.
Set an entry to be a table pte.
Entry | The entry value. |
Definition at line 172 of file BaseRiscVMmuLib.c.
Set an entry to be a valid pte.
Entry | The entry value. |
Definition at line 116 of file BaseRiscVMmuLib.c.
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.
RegionStart | The start address of the region. |
RegionLength | The length of the region. |
AttributeSetMask | The attribute mask to be set. |
AttributeClearMask | The attribute mask to be clear. |
RootTable | The pointer of root table. |
TableIsLive | TRUE if this is live update, FALSE otherwise. |
EFI_INVALID_PARAMETER | The RegionStart or RegionLength was not valid. |
EFI_OUT_OF_RESOURCES | Not enough resource. |
EFI_SUCCESS | The operation succesfully. |
Definition at line 468 of file BaseRiscVMmuLib.c.
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.
RegionStart | The start address of the region. |
RegionEnd | The end address of the region. |
AttributeSetMask | The attribute mask to be set. |
AttributeClearMask | The attribute mask to be clear. |
PageTable | The pointer of current page table. |
Level | The current level. |
TableIsLive | TRUE if this is live update, FALSE otherwise. |
EFI_OUT_OF_RESOURCES | Not enough resource. |
EFI_SUCCESS | The operation succesfully. |
Definition at line 296 of file BaseRiscVMmuLib.c.
Definition at line 46 of file BaseRiscVMmuLib.c.
Definition at line 45 of file BaseRiscVMmuLib.c.
Definition at line 44 of file BaseRiscVMmuLib.c.
Definition at line 47 of file BaseRiscVMmuLib.c.