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

Go to the source code of this file.

Functions

STATIC BOOLEAN MmuIsInit (VOID)
 
STATIC BOOLEAN MmuIsEnabled (VOID)
 
STATIC BOOLEAN IsValidPte (IN UINTN Entry)
 
STATIC BOOLEAN IsValidHugePage (IN UINTN Entry)
 
STATIC UINTN SetValidPte (IN UINTN Entry)
 
STATIC UINTN ParseMaxPageTableLevel (IN UINT64 PageWalkCfg)
 
STATIC UINTN ParsePageTableBitWidth (IN UINT64 PageWalkCfg)
 
STATIC BOOLEAN IsBlockEntry (IN UINTN Entry, IN UINTN Level, IN UINT64 PageWalkCfg)
 
STATIC BOOLEAN IsTableEntry (IN UINTN Entry, IN UINTN Level, IN UINT64 PageWalkCfg)
 
STATIC VOID ReplaceTableEntry (IN UINTN *Entry, IN UINTN Value, IN UINTN RegionStart, IN BOOLEAN IsLiveBlockMapping)
 
STATIC UINTN GetPpnfromPte (IN UINTN Entry)
 
STATIC UINTN SetPpnToPte (UINTN Entry, UINTN Address)
 
STATIC VOID FreePageTablesRecursive (IN UINTN *TranslationTable, IN UINT64 PageWalkCfg, IN UINTN Level)
 
STATIC EFI_STATUS UpdateRegionMappingRecursive (IN UINTN RegionStart, IN UINTN RegionEnd, IN UINTN AttributeSetMask, IN UINTN AttributeClearMask, IN UINTN *PageTable, IN UINTN Level, IN UINT64 PageWalkCfg, IN BOOLEAN TableIsLive)
 
EFI_STATUS UpdateRegionMapping (IN UINTN RegionStart, IN UINTN RegionLength, IN UINT64 PageWalkCfg, IN UINTN AttributeSetMask, IN UINTN AttributeClearMask, IN UINTN *RootTable, IN BOOLEAN TableIsLive)
 
UINT64 EFIAPI EfiAttributeConverse (IN UINT64 EfiAttributes)
 
EFI_STATUS TlbRefillHandlerConfigure (VOID)
 
EFI_STATUS EFIAPI MemoryRegionMap (IN OUT UINTN *PageTable OPTIONAL, IN UINT64 PageWalkCfg, IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, IN UINT64 Attributes, IN UINT64 AttributeMask)
 

Detailed Description

CPU Memory Map Unit Handler Library common functions.

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.
Copyright (c) 2024 Loongson Technology Corporation Limited. All rights reserved.

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

Definition in file CpuMmu.c.

Function Documentation

◆ EfiAttributeConverse()

UINT64 EFIAPI EfiAttributeConverse ( IN UINT64  EfiAttributes)

Convert EFI Attributes to Loongarch Attributes.

Parameters
[in]EfiAttributesEfi Attributes.
Return values
Correspondingarchitecture attributes.

Definition at line 575 of file CpuMmu.c.

◆ FreePageTablesRecursive()

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

Free resources of translation table recursively.

Parameters
TranslationTableThe pointer of table.
PageWalkCfgPage table configure value.
LevelThe current level.

Definition at line 320 of file CpuMmu.c.

◆ GetPpnfromPte()

STATIC UINTN GetPpnfromPte ( IN UINTN  Entry)

Get an ppn value from an entry.

Parameters
EntryThe entry value.
Returns
The ppn value.

Definition at line 279 of file CpuMmu.c.

◆ IsBlockEntry()

STATIC BOOLEAN IsBlockEntry ( IN UINTN  Entry,
IN UINTN  Level,
IN UINT64  PageWalkCfg 
)

Determine if an entry is a HUGE PTE or 4K PTE.

Parameters
EntryThe entry value.
LevelThe current page table level.
PageWalkCfgPage table configure value.
Return values
TRUEThe entry is a block pte.
FALSEThe entry is not a block pte.

Definition at line 199 of file CpuMmu.c.

◆ IsTableEntry()

STATIC BOOLEAN IsTableEntry ( IN UINTN  Entry,
IN UINTN  Level,
IN UINT64  PageWalkCfg 
)

Determine if an entry is a table pte.

Parameters
EntryThe entry value.
LevelThe current page table level.
PageWalkCfgPage table configure value.
Return values
TRUEThe entry is a table pte.
FALSEThe entry is not a table pte.

Definition at line 225 of file CpuMmu.c.

◆ IsValidHugePage()

STATIC BOOLEAN IsValidHugePage ( IN UINTN  Entry)

Determine if an entry is huge page.

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

Definition at line 102 of file CpuMmu.c.

◆ IsValidPte()

STATIC BOOLEAN IsValidPte ( IN UINTN  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 80 of file CpuMmu.c.

◆ MemoryRegionMap()

EFI_STATUS EFIAPI MemoryRegionMap ( IN OUT UINTN *PageTable  OPTIONAL,
IN UINT64  PageWalkCfg,
IN EFI_PHYSICAL_ADDRESS  BaseAddress,
IN UINT64  Length,
IN UINT64  Attributes,
IN UINT64  AttributeMask 
)

Maps the memory region in the page table to the specified attributes.

Parameters
[in,out]PageTableThe pointer to the page table to update, or pointer to NULL if a new page table is to be created.
[in]PageWalkCfgThe page walk controller configure.
[in]BaseAddressThe base address of the memory region to set the Attributes.
[in]LengthThe length of the memory region to set the Attributes.
[in]AttributesThe bitmask of attributes to set, which refer to UEFI SPEC 7.2.3(EFI_BOOT_SERVICES.GetMemoryMap()).
[in]AttributeMaskMask of memory attributes to take into account.
Return values
EFI_SUCCESSThe Attributes was set successfully or Length is 0.
EFI_INVALID_PARAMETERPageTable is NULL, PageWalkCfg is invalid.
EFI_UNSUPPORTED*PageTable is NULL.

Definition at line 694 of file CpuMmu.c.

◆ MmuIsEnabled()

STATIC BOOLEAN MmuIsEnabled ( VOID  )

Check to see if mmu is enabled.

Parameters
VOID.
Return values
TRUEMMU has been enabled. FALSE MMU did not enabled.

Definition at line 58 of file CpuMmu.c.

◆ MmuIsInit()

STATIC BOOLEAN MmuIsInit ( VOID  )

Check to see if mmu successfully initializes.

Parameters
VOID.
Return values
TRUEInitialization has been completed. FALSE Initialization did not complete.

Definition at line 37 of file CpuMmu.c.

◆ ParseMaxPageTableLevel()

STATIC UINTN ParseMaxPageTableLevel ( IN UINT64  PageWalkCfg)

Parse max page table level.

Parameters
[in]PageWalkCfgPage table configure value.
Returns
5 MAX page level is 5 4 MAX page level is 4 3 MAX page level is 3 0 Invalid

Definition at line 143 of file CpuMmu.c.

◆ ParsePageTableBitWidth()

STATIC UINTN ParsePageTableBitWidth ( IN UINT64  PageWalkCfg)

Parse page table bit width.

Assume that the bit width of the page table that each level is the same to PTwidth.

Parameters
[in]PageWalkCfgPage table configure value.
Returns
page table bit width

Definition at line 176 of file CpuMmu.c.

◆ ReplaceTableEntry()

STATIC VOID ReplaceTableEntry ( IN UINTN Entry,
IN UINTN  Value,
IN UINTN  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 255 of file CpuMmu.c.

◆ SetPpnToPte()

STATIC UINTN SetPpnToPte ( UINTN  Entry,
UINTN  Address 
)

Set an ppn value to a entry.

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

Definition at line 297 of file CpuMmu.c.

◆ SetValidPte()

STATIC UINTN SetValidPte ( IN UINTN  Entry)

Set an entry to be a valid pte.

Parameters
EntryThe entry value.
Returns
The entry value.

Definition at line 123 of file CpuMmu.c.

◆ TlbRefillHandlerConfigure()

EFI_STATUS TlbRefillHandlerConfigure ( VOID  )

TLB refill handler configure.

Parameters
VOID.
Return values
EFI_SUCCESSTLB refill handler configure successfully. EFI_UNSUPPORTED Size not aligned.

TLB Re-entry address at the end of exception vector, a vector is up to 512 bytes, so the starting address is: total exception vector size + total interrupt vector size + base. The total size of TLB handler and exception vector size and interrupt vector size should not be lager than 64KB.

Definition at line 628 of file CpuMmu.c.

◆ UpdateRegionMapping()

EFI_STATUS UpdateRegionMapping ( IN UINTN  RegionStart,
IN UINTN  RegionLength,
IN UINT64  PageWalkCfg,
IN UINTN  AttributeSetMask,
IN UINTN  AttributeClearMask,
IN UINTN RootTable,
IN BOOLEAN  TableIsLive 
)

Update region mapping at root table.

Parameters
RegionStartThe start address of the region.
RegionLengthThe length of the region.
PageWalkCfgPage table configure value.
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 540 of file CpuMmu.c.

◆ UpdateRegionMappingRecursive()

STATIC EFI_STATUS UpdateRegionMappingRecursive ( IN UINTN  RegionStart,
IN UINTN  RegionEnd,
IN UINTN  AttributeSetMask,
IN UINTN  AttributeClearMask,
IN UINTN PageTable,
IN UINTN  Level,
IN UINT64  PageWalkCfg,
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.
PageWalkCfgPage table configure value.
TableIsLiveTRUE if this is live update, FALSE otherwise.
Return values
EFI_OUT_OF_RESOURCESNot enough resource.
EFI_SUCCESSThe operation succesfully.

Definition at line 365 of file CpuMmu.c.