FreeNOS
Public Member Functions | Private Member Functions | Private Attributes
ARMPaging Class Reference

ARM virtual memory implementation. More...

#include <ARMPaging.h>

Inheritance diagram for ARMPaging:
MemoryContext

Public Member Functions

 ARMPaging (MemoryMap *map, SplitAllocator *alloc)
 Constructor. More...
 
 ARMPaging (MemoryMap *map, Address firstTableAddress, Address kernelBaseAddress)
 Secondary constructor with pre-allocated 1st page table. More...
 
virtual ~ARMPaging ()
 Destructor. More...
 
virtual Result initialize ()
 Initialize the MemoryContext. More...
 
virtual Result activate (bool initializeMMU=false)
 Activate the MemoryContext. More...
 
virtual Result map (Address virt, Address phys, Memory::Access access)
 Map a physical page to a virtual address. More...
 
virtual Result unmap (Address virt)
 Unmap a virtual address. More...
 
virtual Result lookup (Address virt, Address *phys) const
 Translate virtual address to physical address. More...
 
virtual Result access (Address virt, Memory::Access *access) const
 Get Access flags for a virtual address. More...
 
virtual Result releaseSection (const Memory::Range &range, const bool tablesOnly=false)
 Release memory sections. More...
 
virtual Result releaseRange (Memory::Range *range)
 Release range of memory. More...
 
- Public Member Functions inherited from MemoryContext
 MemoryContext (MemoryMap *map, SplitAllocator *alloc)
 Constructor. More...
 
virtual ~MemoryContext ()
 Destructor. More...
 
virtual Result mapRangeContiguous (Memory::Range *range)
 Map a range of contiguous physical pages to virtual addresses. More...
 
virtual Result mapRangeSparse (Memory::Range *range)
 Map and allocate a range of sparse (non-contiguous) physical pages to virtual addresses. More...
 
virtual Result unmapRange (Memory::Range *range)
 Unmaps a range of virtual memory. More...
 
virtual Result release (Address virt)
 Release a memory page mapping. More...
 
virtual Result findFree (Size size, MemoryMap::Region region, Address *virt) const
 Find unused memory. More...
 
virtual void mapRangeSparseCallback (Address *phys)
 Callback to provide intermediate Range object during mapRangeSparse() More...
 

Private Member Functions

void setupFirstTable (MemoryMap *map, Address firstTableAddress, Address kernelBaseAddress)
 Installs default mappings on 1st level page table. More...
 
Result enableMMU ()
 Enable the MMU. More...
 

Private Attributes

ARMFirstTablem_firstTable
 Pointer to the first level page table. More...
 
Address m_firstTableAddr
 Physical address of the first level page table. More...
 
Address m_kernelBaseAddr
 Kernel base address. More...
 
Arch::Cache m_cache
 Caching implementation. More...
 

Additional Inherited Members

- Public Types inherited from MemoryContext
enum  Result {
  Success, InvalidAddress, InvalidSize, AlreadyExists,
  OutOfMemory
}
 Result codes. More...
 
typedef enum MemoryContext::Result Result
 Result codes. More...
 
- Static Public Member Functions inherited from MemoryContext
static MemoryContextgetCurrent ()
 Get currently active MemoryContext. More...
 
- Protected Attributes inherited from MemoryContext
SplitAllocatorm_alloc
 Physical memory allocator. More...
 
MemoryMapm_map
 Virtual memory layout. More...
 
Callback< MemoryContext, Addressm_mapRangeSparseCallback
 Callback object for mapRangeSparseCallback function. More...
 
Memory::Rangem_savedRange
 Saved range input for use in the mapRangeSparse Callback. More...
 
Size m_numSparsePages
 Number of pages allocated via mapRangeSparse Callback. More...
 
- Static Protected Attributes inherited from MemoryContext
static MemoryContextm_current = 0
 The currently active MemoryContext. More...
 

Detailed Description

ARM virtual memory implementation.

Definition at line 43 of file ARMPaging.h.

Constructor & Destructor Documentation

◆ ARMPaging() [1/2]

ARMPaging::ARMPaging ( MemoryMap map,
SplitAllocator alloc 
)

Constructor.

Parameters
mapVirtual memory map.
allocAllocator pointer of the physical memory page allocations.

Definition at line 28 of file ARMPaging.cpp.

◆ ARMPaging() [2/2]

ARMPaging::ARMPaging ( MemoryMap map,
Address  firstTableAddress,
Address  kernelBaseAddress 
)

Secondary constructor with pre-allocated 1st page table.

Parameters
mapVirtual memory map
firstTableAddressPhysical address of 1st page table
kernelBaseAddressPhysical base address of the kernel

Definition at line 45 of file ARMPaging.cpp.

◆ ~ARMPaging()

ARMPaging::~ARMPaging ( )
virtual

Destructor.

Definition at line 36 of file ARMPaging.cpp.

References MemoryContext::m_alloc, m_firstTableAddr, PAGESIZE, and SplitAllocator::release().

Member Function Documentation

◆ access()

MemoryContext::Result ARMPaging::access ( Address  virt,
Memory::Access access 
) const
virtual

Get Access flags for a virtual address.

Parameters
virtVirtual address to get Access flags for.
accessMemoryAccess object pointer.
Returns
Result code.

Implements MemoryContext.

Definition at line 274 of file ARMPaging.cpp.

References ARMFirstTable::access(), MemoryContext::m_alloc, and m_firstTable.

◆ activate()

MemoryContext::Result ARMPaging::activate ( bool  initializeMMU = false)
virtual

Activate the MemoryContext.

This function applies this MemoryContext on the hardware MMU.

Parameters
initializeMMUIf true perform (re)initialization of the MMU
Returns
Result code.

Implements MemoryContext.

Definition at line 198 of file ARMPaging.cpp.

References ARMCacheV6::cleanInvalidate(), enableMMU(), isb(), m_cache, MemoryContext::m_current, m_firstTableAddr, mcr, MemoryContext::Success, tlb_flush_all(), ARMControl::TranslationTable0, Cache::Unified, and ARMControl::write().

Referenced by kernel_main().

◆ enableMMU()

Result ARMPaging::enableMMU ( )
private

Enable the MMU.

Returns
Result code

Referenced by activate().

◆ initialize()

MemoryContext::Result ARMPaging::initialize ( )
virtual

◆ lookup()

MemoryContext::Result ARMPaging::lookup ( Address  virt,
Address phys 
) const
virtual

Translate virtual address to physical address.

Parameters
virtVirtual address to lookup on input
physContains the physical address on output.
Returns
Result code

Implements MemoryContext.

Definition at line 269 of file ARMPaging.cpp.

References MemoryContext::m_alloc, m_firstTable, and ARMFirstTable::translate().

◆ map()

MemoryContext::Result ARMPaging::map ( Address  virt,
Address  phys,
Memory::Access  access 
)
virtual

Map a physical page to a virtual address.

Parameters
virtVirtual address.
physPhysical address.
accessMemory access flags.
Returns
Result code

Implements MemoryContext.

Definition at line 237 of file ARMPaging.cpp.

References isb(), MemoryContext::m_alloc, MemoryContext::m_current, m_firstTable, ARMFirstTable::map(), and tlb_invalidate.

◆ releaseRange()

MemoryContext::Result ARMPaging::releaseRange ( Memory::Range range)
virtual

Release range of memory.

Parameters
rangeMemory range input
Returns
Result code.

Implements MemoryContext.

Definition at line 285 of file ARMPaging.cpp.

References MemoryContext::m_alloc, m_firstTable, and ARMFirstTable::releaseRange().

◆ releaseSection()

MemoryContext::Result ARMPaging::releaseSection ( const Memory::Range range,
const bool  tablesOnly = false 
)
virtual

Release memory sections.

Deallocate all associated physical memory which resides in the given memory section range.

Parameters
rangeRange of memory sections to release
tablesOnlyTrue to only release associated page tables and do not release the actual mapped pages
Returns
Result code

Implements MemoryContext.

Definition at line 279 of file ARMPaging.cpp.

References MemoryContext::m_alloc, m_firstTable, and ARMFirstTable::releaseSection().

◆ setupFirstTable()

void ARMPaging::setupFirstTable ( MemoryMap map,
Address  firstTableAddress,
Address  kernelBaseAddress 
)
private

Installs default mappings on 1st level page table.

Parameters
mapVirtual memory map
firstTableAddressPhysical address of 1st level page table
kernelBaseAddressPhysical address of the kernel base

◆ unmap()

MemoryContext::Result ARMPaging::unmap ( Address  virt)
virtual

Unmap a virtual address.

This function removes a virtual to physical memory mapping without deallocating any physical memory.

Parameters
virtVirtual address to unmap.
Returns
Result code

Implements MemoryContext.

Definition at line 251 of file ARMPaging.cpp.

References ARMCacheV6::cleanInvalidateAddress(), Cache::Data, isb(), MemoryContext::m_alloc, m_cache, MemoryContext::m_current, m_firstTable, tlb_invalidate, and ARMFirstTable::unmap().

Field Documentation

◆ m_cache

Arch::Cache ARMPaging::m_cache
private

Caching implementation.

Definition at line 184 of file ARMPaging.h.

Referenced by activate(), and unmap().

◆ m_firstTable

ARMFirstTable* ARMPaging::m_firstTable
private

Pointer to the first level page table.

Definition at line 175 of file ARMPaging.h.

Referenced by access(), initialize(), lookup(), map(), releaseRange(), releaseSection(), and unmap().

◆ m_firstTableAddr

Address ARMPaging::m_firstTableAddr
private

Physical address of the first level page table.

Definition at line 178 of file ARMPaging.h.

Referenced by activate(), initialize(), and ~ARMPaging().

◆ m_kernelBaseAddr

Address ARMPaging::m_kernelBaseAddr
private

Kernel base address.

Definition at line 181 of file ARMPaging.h.

Referenced by initialize().


The documentation for this class was generated from the following files: