The Pedigree Project 0.1
Classes | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Private Member Functions | Friends | List of all members
PhysicalMemoryManager Class Referenceabstract

#include <PhysicalMemoryManager.h>

+ Inheritance diagram for PhysicalMemoryManager:
+ Collaboration diagram for PhysicalMemoryManager:

Classes

struct  MemoryRegionInfo
 
struct  MemorySnapshot
 

Public Member Functions

virtual physical_uintptr_t allocatePage (size_t pageConstraints=0)=0
 
virtual physical_uintptr_t tryAllocatePage ()
 
virtual bool copyPhysicalPageToBuffer (physical_uintptr_t page, void *buffer)
 
virtual bool copyPhysicalPageFromBuffer (physical_uintptr_t page, const void *buffer)
 
virtual MemorySnapshot memorySnapshot () const
 
virtual void freePage (physical_uintptr_t page)=0
 
virtual void pin (physical_uintptr_t page)=0
 
virtual bool allocateRegion (MemoryRegion &Region, size_t cPages, size_t pageConstraints, size_t Flags, physical_uintptr_t start=-1)=0
 
void allocateMemoryRegionList (Vector< MemoryRegionInfo * > &MemoryRegions)
 
void freeMemoryRegionList (Vector< MemoryRegionInfo * > &MemoryRegions)
 
virtual size_t freePageCount () const
 

Static Public Member Functions

static PhysicalMemoryManager & instance ()
 
static constexpr size_t getPageSize () PURE
 

Static Public Attributes

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 Member Functions

 PhysicalMemoryManager ()
 
virtual ~PhysicalMemoryManager ()
 

Protected Attributes

Vector< MemoryRegion * > m_MemoryRegions
 

Private Member Functions

 PhysicalMemoryManager (const PhysicalMemoryManager &)
 
PhysicalMemoryManager & operator= (const PhysicalMemoryManager &)
 
virtual void freePageUnlocked (physical_uintptr_t page)=0
 
virtual void unmapRegion (MemoryRegion *pRegion)=0
 

Friends

class CacheManager
 
class Cache
 
class MemoryRegion
 

Detailed Description

The PhysicalMemoryManager manages the physical address space. That means it provides functions to allocate and free pages.

Definition at line 35 of file include/pedigree/kernel/processor/PhysicalMemoryManager.h.

Constructor & Destructor Documentation

◆ PhysicalMemoryManager() [1/2]

PhysicalMemoryManager::PhysicalMemoryManager ( )
protected

The constructor

Definition at line 24 of file PhysicalMemoryManager.cc.

◆ ~PhysicalMemoryManager()

PhysicalMemoryManager::~PhysicalMemoryManager ( )
protectedvirtual

The destructor

Definition at line 26 of file PhysicalMemoryManager.cc.

◆ PhysicalMemoryManager() [2/2]

PhysicalMemoryManager::PhysicalMemoryManager ( const PhysicalMemoryManager &  )
private

The copy-constructor

Note
Not implemented (singleton)

Member Function Documentation

◆ allocateMemoryRegionList()

void PhysicalMemoryManager::allocateMemoryRegionList ( Vector< MemoryRegionInfo * > &  MemoryRegions)

Copy the memory region list

Parameters
[in,out]MemoryRegionscontainer for the copy of the memory regions

Definition at line 32 of file PhysicalMemoryManager.cc.

References Vector< T >::count(), m_MemoryRegions, physicalAddress(), and Vector< T >::pushBack().

Referenced by IoCommand::execute().

+ Here is the caller graph for this function:

◆ allocatePage()

virtual physical_uintptr_t PhysicalMemoryManager::allocatePage ( size_t  pageConstraints = 0)
pure virtual

◆ allocateRegion()

virtual bool PhysicalMemoryManager::allocateRegion ( MemoryRegion &  Region,
size_t  cPages,
size_t  pageConstraints,
size_t  Flags,
physical_uintptr_t  start = -1 
)
pure virtual

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

Implemented in HostedPhysicalMemoryManager, X86CommonPhysicalMemoryManager, Arm64PhysicalMemoryManager, and Armv7PhysicalMemoryManager.

Referenced by KernelElf::initialise(), MemoryPool::initialise(), Device::Address::map(), Nic3C90x::Nic3C90x(), and Framebuffer::swCreateBuffer().

+ Here is the caller graph for this function:

◆ copyPhysicalPageFromBuffer()

virtual bool PhysicalMemoryManager::copyPhysicalPageFromBuffer ( physical_uintptr_t  page,
const void *  buffer 
)
inlinevirtual

◆ copyPhysicalPageToBuffer()

virtual bool PhysicalMemoryManager::copyPhysicalPageToBuffer ( physical_uintptr_t  page,
void *  buffer 
)
inlinevirtual

◆ freeMemoryRegionList()

void PhysicalMemoryManager::freeMemoryRegionList ( Vector< MemoryRegionInfo * > &  MemoryRegions)

Free the memory region list created with allocateMemoryRegionList.

Parameters
[in,out]MemoryRegionscontainer of the copy of the memory regions

Definition at line 44 of file PhysicalMemoryManager.cc.

References Vector< T >::count(), and Vector< T >::popBack().

◆ freePage()

virtual void PhysicalMemoryManager::freePage ( physical_uintptr_t  page)
pure virtual

◆ freePageCount()

size_t PhysicalMemoryManager::freePageCount ( ) const
virtual

Specifies the number of pages that remain free on the system.

Reimplemented in Arm64PhysicalMemoryManager, Armv7PhysicalMemoryManager, and X86CommonPhysicalMemoryManager.

Definition at line 28 of file PhysicalMemoryManager.cc.

Referenced by CacheManager::timer().

+ Here is the caller graph for this function:

◆ freePageUnlocked()

virtual void PhysicalMemoryManager::freePageUnlocked ( physical_uintptr_t  page)
privatepure virtual

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

Note
Use in the wrong place and you die.

Implemented in Arm64PhysicalMemoryManager, Armv7PhysicalMemoryManager, HostedPhysicalMemoryManager, and X86CommonPhysicalMemoryManager.

◆ getPageSize()

static constexpr size_t PhysicalMemoryManager::getPageSize ( )
inlinestaticconstexpr

Get the size of one page

Returns
size of one page in bytes

Definition at line 75 of file include/pedigree/kernel/processor/PhysicalMemoryManager.h.

References TargetInfo::getPageSize().

Referenced by Device::Address::Address(), Elf::allocate(), MemoryPool::allocateDoer(), HostedPhysicalMemoryManager::allocatePage(), File::allocateRange(), HostedPhysicalMemoryManager::allocateRegion(), X86CommonPhysicalMemoryManager::allocateRegion(), MemoryMapManager::allows(), Archive::Archive(), PosixSubsystem::checkAddress(), PerProcessorScheduler::checkEventState(), HostedVirtualAddressSpace::clone(), MemoryMappedFile::compact(), X64VirtualAddressSpace::conditionalTableEntryAllocation(), X64VirtualAddressSpace::conditionalTableEntryMapping(), MemoryMapManager::contains(), X64VirtualAddressSpace::copyResidentUserPage(), PosixSubsystem::copyUserString(), HostedVirtualAddressSpace::detachMapping(), HostedVirtualAddressSpace::doAllocateStack(), X64VirtualAddressSpace::doAllocateStack(), MappingCommand::execute(), VirtualAddressSpace::expandHeap(), Elf::finaliseModule(), X86CommonPhysicalMemoryManager::PageStack::free(), HostedPhysicalMemoryManager::freePageUnlocked(), X86CommonPhysicalMemoryManager::freePageUnlocked(), HostedVirtualAddressSpace::freeStack(), X64VirtualAddressSpace::freeStack(), RawFsFile::getBlockSize(), File::getBlockSize(), Event::getHandlerBuffer(), Event::getHandlerBufferSize(), HostedVirtualAddressSpace::getMapping(), FramebufferFile::getPhysicalPage(), MemFile::getPhysicalPage(), File::getPhysicalPage(), VirtioGpu::GpuFramebuffer::getPhysicalPage(), HostedVirtualAddressSpace::handleCopyOnWriteFault(), X64VirtualAddressSpace::handleCopyOnWriteFault(), X86CommonPhysicalMemoryManager::initialisationDone(), HostedPhysicalMemoryManager::initialise(), X86CommonPhysicalMemoryManager::initialise(), KernelElf::initialise(), MemoryPool::initialise(), X86CommonPhysicalMemoryManager::initialise64(), DynamicLinker::initPlt(), PosixSubsystem::invoke(), HostedVirtualAddressSpace::isMapped(), PosixSubsystem::loadElf(), Elf::loadModule(), HostedVirtualAddressSpace::map(), Device::Address::map(), VirtualAddressSpace::mapHuge(), X64VirtualAddressSpace::mapHuge(), File::markPageExternallyWritable(), X86CommonPhysicalMemoryManager::PageStack::maybeMap(), RawFsFile::pinBlock(), File::populateRange(), KernelElf::prepareRuntimeModules(), DiskImage::read(), File::read(), RawFsFile::readBlock(), File::readIntoCache(), File::readPage(), Ext2File::readPage(), Ext2File::readPages(), File::releaseReadReference(), AnonymousMemoryMap::remove(), MemoryMappedFile::remove(), MemoryMapManager::removeAndRelease(), MemoryMapManager::removeAttachment(), File::resize(), File::returnPhysicalPage(), HostedVirtualAddressSpace::revertToKernelAddressSpace(), VirtualAddressSpace::rollbackHeapExpansion(), HostedVirtualAddressSpace::setFlags(), MemoryMappedFile::split(), Framebuffer::swCreateBuffer(), HostedVirtualAddressSpace::switchAddressSpace(), RawFsFile::sync(), MemoryMapManager::sync(), File::syncFillCache(), Ext2File::syncPages(), File::syncRange(), MemoryMappedObject::syncRange(), MemoryMappedFile::syncRange(), AnonymousMemoryMap::trap(), MemoryMappedFile::trap(), MemoryPool::trim(), HostedVirtualAddressSpace::trySetFlags(), HostedVirtualAddressSpace::tryWriteUser32(), X64VirtualAddressSpace::tryWriteUser32(), MemoryMapManager::unmap(), HostedVirtualAddressSpace::unmap(), MemoryMapManager::unmapAllUnlocked(), HostedPhysicalMemoryManager::unmapRegion(), X86CommonPhysicalMemoryManager::unmapRegion(), RawFsFile::unpinBlock(), File::useFillCache(), RawFsFile::writeBlock(), Ext2File::writeBlocks(), File::writeCallback(), and File::writeUnlocked().

◆ instance()

PhysicalMemoryManager & PhysicalMemoryManager::instance ( )
static

Get the PhysicalMemoryManager instance

Returns
instance of the PhysicalMemoryManager

Definition at line 34 of file arm64/PhysicalMemoryManager.cc.

Referenced by Elf::allocate(), Archive::Archive(), PerProcessorScheduler::checkEventState(), HostedVirtualAddressSpace::clone(), X64VirtualAddressSpace::clone(), X64VirtualAddressSpace::conditionalTableEntryAllocation(), HostedVirtualAddressSpace::doAllocateStack(), X64VirtualAddressSpace::doAllocateStack(), IoCommand::execute(), VirtualAddressSpace::expandHeap(), Cache::finishRetirement(), HostedVirtualAddressSpace::freeStack(), X64VirtualAddressSpace::freeStack(), Thread::getTlsBase(), HostedVirtualAddressSpace::handleCopyOnWriteFault(), X64VirtualAddressSpace::handleCopyOnWriteFault(), KernelElf::initialise(), BusMasterIde::initialise(), MemoryPool::initialise(), DynamicLinker::initPlt(), Elf::loadModule(), Cache::lruEvict(), Device::Address::map(), Cache::map(), X64VirtualAddressSpace::mapHuge(), Nic3C90x::Nic3C90x(), KernelElf::prepareRuntimeModules(), MemoryMappedFile::remove(), HostedVirtualAddressSpace::revertToKernelAddressSpace(), X64VirtualAddressSpace::revertToKernelAddressSpace(), VirtualAddressSpace::rollbackHeapExpansion(), Framebuffer::swCreateBuffer(), CacheManager::timer(), AnonymousMemoryMap::trap(), MemoryMappedFile::trap(), X64VirtualAddressSpace::X64VirtualAddressSpace(), MemoryRegion::~MemoryRegion(), Thread::~Thread(), and X64VirtualAddressSpace::~X64VirtualAddressSpace().

+ Here is the caller graph for this function:

◆ memorySnapshot()

virtual MemorySnapshot PhysicalMemoryManager::memorySnapshot ( ) const
inlinevirtual

◆ operator=()

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

The copy-constructor

Note
Not implemented (singleton)

◆ pin()

virtual void PhysicalMemoryManager::pin ( physical_uintptr_t  page)
pure virtual

"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.

Implemented in Arm64PhysicalMemoryManager, Armv7PhysicalMemoryManager, HostedPhysicalMemoryManager, and X86CommonPhysicalMemoryManager.

Referenced by HostedVirtualAddressSpace::clone(), X64VirtualAddressSpace::clone(), HostedVirtualAddressSpace::doAllocateStack(), X64VirtualAddressSpace::doAllocateStack(), and VirtualAddressSpace::expandHeap().

+ Here is the caller graph for this function:

◆ tryAllocatePage()

virtual physical_uintptr_t PhysicalMemoryManager::tryAllocatePage ( )
inlinevirtual

◆ unmapRegion()

virtual void PhysicalMemoryManager::unmapRegion ( MemoryRegion *  pRegion)
privatepure virtual

Unmaps a memory region - called ONLY from MemoryRegion's destructor.

Implemented in HostedPhysicalMemoryManager, X86CommonPhysicalMemoryManager, Arm64PhysicalMemoryManager, and Armv7PhysicalMemoryManager.

Referenced by MemoryRegion::~MemoryRegion().

+ Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ Cache

friend class Cache
friend

◆ CacheManager

friend class CacheManager
friend

◆ MemoryRegion

friend class MemoryRegion
friend

MemoryRegion can access our unmapRegion function.

Definition at line 41 of file include/pedigree/kernel/processor/PhysicalMemoryManager.h.

Member Data Documentation

◆ addressConstraints

const size_t PhysicalMemoryManager::addressConstraints = below1MB | below16MB | below4GB | below64GB
static

◆ anonymous

const size_t PhysicalMemoryManager::anonymous = 1 << 8
static

◆ below16MB

const size_t PhysicalMemoryManager::below16MB = 1 << 5
static

The allocated pages should be below the 16MB mark

Definition at line 57 of file include/pedigree/kernel/processor/PhysicalMemoryManager.h.

Referenced by X86CommonPhysicalMemoryManager::allocateRegion().

◆ below1MB

const size_t PhysicalMemoryManager::below1MB = 1 << 4
static

The allocated pages should be below the 1MB mark

Definition at line 55 of file include/pedigree/kernel/processor/PhysicalMemoryManager.h.

Referenced by X86CommonPhysicalMemoryManager::allocateRegion().

◆ below4GB

const size_t PhysicalMemoryManager::below4GB = 1 << 6
static

The allocated pages should be below the 4GB mark

Definition at line 59 of file include/pedigree/kernel/processor/PhysicalMemoryManager.h.

Referenced by X86CommonPhysicalMemoryManager::PageStack::allocate().

◆ below64GB

const size_t PhysicalMemoryManager::below64GB = 1 << 7
static

The allocated pages should be below the 64GB mark

Definition at line 61 of file include/pedigree/kernel/processor/PhysicalMemoryManager.h.

Referenced by X86CommonPhysicalMemoryManager::PageStack::allocate().

◆ continuous

const size_t PhysicalMemoryManager::continuous = 1 << 0
static

◆ force

const size_t PhysicalMemoryManager::force = 1 << 2
static

If this flag is set we try to remove the range from the PhysicalMemoryManager, but if that fails, we still map the physical memory region

Definition at line 50 of file include/pedigree/kernel/processor/PhysicalMemoryManager.h.

Referenced by HostedPhysicalMemoryManager::allocateRegion(), X86CommonPhysicalMemoryManager::allocateRegion(), and Device::Address::map().

◆ m_MemoryRegions

Vector<MemoryRegion*> PhysicalMemoryManager::m_MemoryRegions
protected

◆ nonRamMemory

const size_t PhysicalMemoryManager::nonRamMemory = 1 << 1
static

◆ virtualOnly

const size_t PhysicalMemoryManager::virtualOnly = 1 << 3
static

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