The Pedigree Project 0.1
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
HostedPhysicalMemoryManager Class Reference

Implementation of the PhysicalMemoryManager for common x86. More...

#include <PhysicalMemoryManager.h>

+ Inheritance diagram for HostedPhysicalMemoryManager:
+ Collaboration diagram for HostedPhysicalMemoryManager:

Classes

struct  page
 
class  PageHashable
 

Public Member Functions

virtual physical_uintptr_t allocatePage (size_t pageConstraints=0) override
 
physical_uintptr_t tryAllocatePage () override
 
bool copyPhysicalPageToBuffer (physical_uintptr_t page, void *buffer) override
 
bool copyPhysicalPageFromBuffer (physical_uintptr_t page, const void *buffer) override
 
MemorySnapshot memorySnapshot () const override
 
virtual void freePage (physical_uintptr_t page) override
 
virtual bool allocateRegion (MemoryRegion &Region, size_t cPages, size_t pageConstraints, size_t Flags, physical_uintptr_t start=-1) override
 
virtual void pin (physical_uintptr_t page) override
 
void initialise (const BootstrapStruct_t &Info) INITIALISATION_ONLY
 
void initialisationDone ()
 
const RangeList< uint64_t > & getAcpiRanges () const
 
- Public Member Functions inherited from PhysicalMemoryManager
void allocateMemoryRegionList (Vector< MemoryRegionInfo * > &MemoryRegions)
 
void freeMemoryRegionList (Vector< MemoryRegionInfo * > &MemoryRegions)
 
virtual size_t freePageCount () const
 

Static Public Member Functions

static HostedPhysicalMemoryManager & instance ()
 
- Static Public Member Functions inherited from PhysicalMemoryManager
static PhysicalMemoryManager & instance ()
 
static constexpr size_t getPageSize () PURE
 

Protected Member Functions

 HostedPhysicalMemoryManager () INITIALISATION_ONLY
 
virtual ~HostedPhysicalMemoryManager () override
 
- Protected Member Functions inherited from PhysicalMemoryManager
 PhysicalMemoryManager ()
 
virtual ~PhysicalMemoryManager ()
 

Private Types

using PageStack = X86CommonPhysicalMemoryManager::PageStack
 
typedef HashTable< PageHashable, struct page > MetadataTable
 

Private Member Functions

 HostedPhysicalMemoryManager (const HostedPhysicalMemoryManager &)
 
HostedPhysicalMemoryManager & operator= (const HostedPhysicalMemoryManager &)
 
int getBackingFile () const
 
void unmapRegion (MemoryRegion *pRegion) override
 
virtual void freePageUnlocked (physical_uintptr_t page) override
 

Private Attributes

PageStack m_PageStack
 
RangeList< uint64_t > m_PhysicalRanges
 
RangeList< uintptr_t > m_MemoryRegions
 
RangeList< uint64_t > m_AcpiRanges
 
Spinlock m_Lock
 
Spinlock m_RegionLock
 
HashTable< PageHashable, struct page > m_PageMetadata
 
int m_BackingFile
 

Static Private Attributes

static HostedPhysicalMemoryManager * m_Instance = nullptr
 

Friends

class CacheManager
 
class Cache
 
class PhysicalMemoryManager
 
class HostedVirtualAddressSpace
 

Additional Inherited Members

- Static Public Attributes inherited from PhysicalMemoryManager
static const size_t continuous = 1 << 0
 
static const size_t nonRamMemory = 1 << 1
 
static const size_t force = 1 << 2
 
static const size_t virtualOnly = 1 << 3
 
static const size_t below1MB = 1 << 4
 
static const size_t below16MB = 1 << 5
 
static const size_t below4GB = 1 << 6
 
static const size_t below64GB = 1 << 7
 
static const size_t addressConstraints = below1MB | below16MB | below4GB | below64GB
 
static const size_t anonymous = 1 << 8
 
- Protected Attributes inherited from PhysicalMemoryManager
Vector< MemoryRegion * > m_MemoryRegions
 

Detailed Description

Implementation of the PhysicalMemoryManager for common x86.

The common x86 implementation of the PhysicalMemoryManager

Definition at line 40 of file kernel/core/processor/hosted/PhysicalMemoryManager.h.

Member Typedef Documentation

◆ MetadataTable

◆ PageStack

Constructor & Destructor Documentation

◆ HostedPhysicalMemoryManager() [1/2]

HostedPhysicalMemoryManager::HostedPhysicalMemoryManager ( )
protected

The constructor

Definition at line 465 of file hosted/PhysicalMemoryManager.cc.

References m_BackingFile.

Referenced by instance().

+ Here is the caller graph for this function:

◆ ~HostedPhysicalMemoryManager()

HostedPhysicalMemoryManager::~HostedPhysicalMemoryManager ( )
overrideprotectedvirtual

◆ HostedPhysicalMemoryManager() [2/2]

HostedPhysicalMemoryManager::HostedPhysicalMemoryManager ( const HostedPhysicalMemoryManager &  )
private

The copy-constructor

Note
Not implemented (singleton)

Member Function Documentation

◆ allocatePage()

physical_uintptr_t HostedPhysicalMemoryManager::allocatePage ( size_t  pageConstraints = 0)
overridevirtual

Allocate a single page with optional constraints.

Returns
physical address of the page or 0 if no page available.

Implements PhysicalMemoryManager.

Definition at line 65 of file hosted/PhysicalMemoryManager.cc.

References Spinlock::acquire(), X86CommonPhysicalMemoryManager::PageStack::allocate(), MemoryPressureManager::compact(), MemoryPressureManager::compactingForCurrentExecution(), PhysicalMemoryManager::getPageSize(), ProcessorBase::m_Initialised, m_Lock, m_PageStack, panic(), and Spinlock::release().

Referenced by allocateRegion().

+ Here is the caller graph for this function:

◆ allocateRegion()

bool HostedPhysicalMemoryManager::allocateRegion ( MemoryRegion &  Region,
size_t  cPages,
size_t  pageConstraints,
size_t  Flags,
physical_uintptr_t  start = -1 
)
overridevirtual

Allocate a memory-region with specific constraints the pages need to fullfill.

Parameters
[in]Regionreference to the MemoryRegion object
[in]cPagesthe number of pages to allocate for the MemoryRegion object
[in]pageConstraintsthe constraints the pages have to fullfill
[in]Flagsflags from the VirtualAddressSpace class namespace
[in]startthe physical address of the beginning of the region (optional)
Returns
true, if a valid MemoryRegion object is created, false otherwise

Implements PhysicalMemoryManager.

Definition at line 286 of file hosted/PhysicalMemoryManager.cc.

References PhysicalMemoryManager::addressConstraints, RangeList< T, Reversed >::allocate(), allocatePage(), RangeList< T, Reversed >::allocateSpecific(), PhysicalMemoryManager::anonymous, PhysicalMemoryManager::continuous, PhysicalMemoryManager::force, RangeList< T, Reversed >::free(), freePage(), VirtualAddressSpace::getMapping(), PhysicalMemoryManager::getPageSize(), ProcessorBase::information(), PhysicalMemoryManager::m_MemoryRegions, m_MemoryRegions, MemoryRegion::m_PhysicalAddress, m_PhysicalRanges, MemoryRegion::m_Size, MemoryRegion::m_VirtualAddress, VirtualAddressSpace::map(), PhysicalMemoryManager::nonRamMemory, panic(), Vector< T >::pushBack(), VirtualAddressSpace::unmap(), and PhysicalMemoryManager::virtualOnly.

Referenced by initialisationDone().

+ Here is the caller graph for this function:

◆ copyPhysicalPageFromBuffer()

bool HostedPhysicalMemoryManager::copyPhysicalPageFromBuffer ( physical_uintptr_t  page,
const void *  buffer 
)
overridevirtual

Reimplemented from PhysicalMemoryManager.

Definition at line 192 of file hosted/PhysicalMemoryManager.cc.

◆ copyPhysicalPageToBuffer()

bool HostedPhysicalMemoryManager::copyPhysicalPageToBuffer ( physical_uintptr_t  page,
void *  buffer 
)
overridevirtual

Reimplemented from PhysicalMemoryManager.

Definition at line 188 of file hosted/PhysicalMemoryManager.cc.

◆ freePage()

void HostedPhysicalMemoryManager::freePage ( physical_uintptr_t  page)
overridevirtual

Free a page allocated with the allocatePage() function

Parameters
[in]pagephysical address of the page

Implements PhysicalMemoryManager.

Definition at line 198 of file hosted/PhysicalMemoryManager.cc.

References freePageUnlocked(), and m_Lock.

Referenced by allocateRegion(), and unmapRegion().

+ Here is the caller graph for this function:

◆ freePageUnlocked()

void HostedPhysicalMemoryManager::freePageUnlocked ( physical_uintptr_t  page)
overrideprivatevirtual

Same as freePage, but without the lock. Will panic if the lock is unlocked.

Note
Use in the wrong place and you die.

Implements PhysicalMemoryManager.

Definition at line 203 of file hosted/PhysicalMemoryManager.cc.

References X86CommonPhysicalMemoryManager::PageStack::free(), PhysicalMemoryManager::getPageSize(), ProcessorBase::m_Initialised, m_Lock, m_PageMetadata, m_PageStack, and Spinlock::release().

Referenced by freePage().

+ Here is the caller graph for this function:

◆ getAcpiRanges()

const RangeList< uint64_t > & HostedPhysicalMemoryManager::getAcpiRanges ( ) const
inline

◆ getBackingFile()

int HostedPhysicalMemoryManager::getBackingFile ( ) const
inlineprivate

◆ initialisationDone()

void HostedPhysicalMemoryManager::initialisationDone ( )

◆ initialise()

void HostedPhysicalMemoryManager::initialise ( const BootstrapStruct_t &  Info)

◆ instance()

HostedPhysicalMemoryManager & HostedPhysicalMemoryManager::instance ( )
static

◆ memorySnapshot()

PhysicalMemoryManager::MemorySnapshot HostedPhysicalMemoryManager::memorySnapshot ( ) const
overridevirtual

Reimplemented from PhysicalMemoryManager.

Definition at line 182 of file hosted/PhysicalMemoryManager.cc.

◆ operator=()

HostedPhysicalMemoryManager & HostedPhysicalMemoryManager::operator= ( const HostedPhysicalMemoryManager &  )
private

The copy-constructor

Note
Not implemented (singleton)

References m_BackingFile.

◆ pin()

void HostedPhysicalMemoryManager::pin ( physical_uintptr_t  page)
overridevirtual

"Pin" a page, increasing its refcount.

Every time a pinned page is passed to freePage, its refcount is decreased, and the page is only freed once the refcount hits zero.

Note that an unpin function is not provided, as freePage offers the right semantics.

Implements PhysicalMemoryManager.

Definition at line 243 of file hosted/PhysicalMemoryManager.cc.

References m_Lock, and m_PageMetadata.

◆ tryAllocatePage()

physical_uintptr_t HostedPhysicalMemoryManager::tryAllocatePage ( )
overridevirtual

Reimplemented from PhysicalMemoryManager.

Definition at line 135 of file hosted/PhysicalMemoryManager.cc.

◆ unmapRegion()

void HostedPhysicalMemoryManager::unmapRegion ( MemoryRegion *  pRegion)
overrideprivatevirtual

Friends And Related Symbol Documentation

◆ Cache

friend class Cache
friend

◆ CacheManager

friend class CacheManager
friend

◆ HostedVirtualAddressSpace

friend class HostedVirtualAddressSpace
friend

For getBackingFile()

Definition at line 45 of file kernel/core/processor/hosted/PhysicalMemoryManager.h.

◆ PhysicalMemoryManager

friend class PhysicalMemoryManager
friend

Member Data Documentation

◆ m_AcpiRanges

RangeList<uint64_t> HostedPhysicalMemoryManager::m_AcpiRanges
private

◆ m_BackingFile

int HostedPhysicalMemoryManager::m_BackingFile
private

Hosted: backing file for physical memory.

Definition at line 162 of file kernel/core/processor/hosted/PhysicalMemoryManager.h.

Referenced by HostedPhysicalMemoryManager(), operator=(), and ~HostedPhysicalMemoryManager().

◆ m_Instance

HostedPhysicalMemoryManager * HostedPhysicalMemoryManager::m_Instance = nullptr
staticprivate

Static instance.

Definition at line 165 of file kernel/core/processor/hosted/PhysicalMemoryManager.h.

Referenced by instance().

◆ m_Lock

Spinlock HostedPhysicalMemoryManager::m_Lock
private

To guard against multiprocessor reentrancy.

Definition at line 121 of file kernel/core/processor/hosted/PhysicalMemoryManager.h.

Referenced by allocatePage(), freePage(), freePageUnlocked(), and pin().

◆ m_MemoryRegions

RangeList<uintptr_t> HostedPhysicalMemoryManager::m_MemoryRegions
private

Virtual-memory available for MemoryRegions

Todo:
rename this member (conflicts with PhysicalMemoryManager::m_MemoryRegions)

Definition at line 116 of file kernel/core/processor/hosted/PhysicalMemoryManager.h.

Referenced by allocateRegion(), initialise(), and unmapRegion().

◆ m_PageMetadata

HashTable<PageHashable, struct page> HostedPhysicalMemoryManager::m_PageMetadata
private

Page metadata table

Definition at line 159 of file kernel/core/processor/hosted/PhysicalMemoryManager.h.

Referenced by freePageUnlocked(), initialise(), and pin().

◆ m_PageStack

PageStack HostedPhysicalMemoryManager::m_PageStack
private

The page stack

Definition at line 108 of file kernel/core/processor/hosted/PhysicalMemoryManager.h.

Referenced by allocatePage(), freePageUnlocked(), and initialise().

◆ m_PhysicalRanges

RangeList<uint64_t> HostedPhysicalMemoryManager::m_PhysicalRanges
private

RangeList of free physical memory

Definition at line 111 of file kernel/core/processor/hosted/PhysicalMemoryManager.h.

Referenced by allocateRegion(), initialise(), and unmapRegion().

◆ m_RegionLock

Spinlock HostedPhysicalMemoryManager::m_RegionLock
private

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