|
The Pedigree Project 0.1
|
#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 |
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.
|
protected |
The constructor
Definition at line 24 of file PhysicalMemoryManager.cc.
|
protectedvirtual |
The destructor
Definition at line 26 of file PhysicalMemoryManager.cc.
|
private |
The copy-constructor
| void PhysicalMemoryManager::allocateMemoryRegionList | ( | Vector< MemoryRegionInfo * > & | MemoryRegions | ) |
Copy the memory region list
| [in,out] | MemoryRegions | container 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:
|
pure virtual |
Allocate a single page with optional constraints.
Implemented in Arm64PhysicalMemoryManager, Armv7PhysicalMemoryManager, HostedPhysicalMemoryManager, and X86CommonPhysicalMemoryManager.
Referenced by Elf::allocate(), PerProcessorScheduler::checkEventState(), X64VirtualAddressSpace::conditionalTableEntryAllocation(), HostedVirtualAddressSpace::doAllocateStack(), X64VirtualAddressSpace::doAllocateStack(), Thread::getTlsBase(), HostedVirtualAddressSpace::handleCopyOnWriteFault(), X64VirtualAddressSpace::handleCopyOnWriteFault(), DynamicLinker::initPlt(), Elf::loadModule(), Cache::map(), KernelElf::prepareRuntimeModules(), MemoryMappedFile::trap(), and X64VirtualAddressSpace::X64VirtualAddressSpace().
Here is the caller graph for this function:
|
pure virtual |
Allocate a memory-region with specific constraints the pages need to fullfill.
| [in] | Region | reference to the MemoryRegion object |
| [in] | cPages | the number of pages to allocate for the MemoryRegion object |
| [in] | pageConstraints | the constraints the pages have to fullfill |
| [in] | Flags | flags from the VirtualAddressSpace class namespace |
| [in] | start | the physical address of the beginning of the region (optional) |
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:
|
inlinevirtual |
Definition at line 89 of file include/pedigree/kernel/processor/PhysicalMemoryManager.h.
|
inlinevirtual |
Definition at line 86 of file include/pedigree/kernel/processor/PhysicalMemoryManager.h.
| void PhysicalMemoryManager::freeMemoryRegionList | ( | Vector< MemoryRegionInfo * > & | MemoryRegions | ) |
Free the memory region list created with allocateMemoryRegionList.
| [in,out] | MemoryRegions | container of the copy of the memory regions |
Definition at line 44 of file PhysicalMemoryManager.cc.
References Vector< T >::count(), and Vector< T >::popBack().
|
pure virtual |
Free a page allocated with the allocatePage() function
| [in] | page | physical address of the page |
Implemented in Arm64PhysicalMemoryManager, Armv7PhysicalMemoryManager, HostedPhysicalMemoryManager, and X86CommonPhysicalMemoryManager.
Referenced by VirtualAddressSpace::expandHeap(), Cache::finishRetirement(), HostedVirtualAddressSpace::freeStack(), X64VirtualAddressSpace::freeStack(), HostedVirtualAddressSpace::handleCopyOnWriteFault(), X64VirtualAddressSpace::handleCopyOnWriteFault(), X64VirtualAddressSpace::mapHuge(), KernelElf::prepareRuntimeModules(), MemoryMappedFile::remove(), HostedVirtualAddressSpace::revertToKernelAddressSpace(), X64VirtualAddressSpace::revertToKernelAddressSpace(), VirtualAddressSpace::rollbackHeapExpansion(), MemoryMappedFile::trap(), Thread::~Thread(), and X64VirtualAddressSpace::~X64VirtualAddressSpace().
Here is the caller graph for this function:
|
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:
|
privatepure virtual |
Same as freePage, but without the lock. Will panic if the lock is unlocked.
Implemented in Arm64PhysicalMemoryManager, Armv7PhysicalMemoryManager, HostedPhysicalMemoryManager, and X86CommonPhysicalMemoryManager.
|
inlinestaticconstexpr |
Get the size of one page
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().
|
static |
Get the PhysicalMemoryManager instance
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:
|
inlinevirtual |
Definition at line 97 of file include/pedigree/kernel/processor/PhysicalMemoryManager.h.
|
private |
The copy-constructor
|
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:
|
inlinevirtual |
Definition at line 82 of file include/pedigree/kernel/processor/PhysicalMemoryManager.h.
|
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:
|
friend |
Definition at line 37 of file include/pedigree/kernel/processor/PhysicalMemoryManager.h.
|
friend |
Definition at line 36 of file include/pedigree/kernel/processor/PhysicalMemoryManager.h.
|
friend |
MemoryRegion can access our unmapRegion function.
Definition at line 41 of file include/pedigree/kernel/processor/PhysicalMemoryManager.h.
|
static |
All address size constraints
Definition at line 64 of file include/pedigree/kernel/processor/PhysicalMemoryManager.h.
Referenced by HostedPhysicalMemoryManager::allocateRegion(), and X86CommonPhysicalMemoryManager::allocateRegion().
|
static |
Don't expose the memory region in diagnostic region listings.
Definition at line 67 of file include/pedigree/kernel/processor/PhysicalMemoryManager.h.
Referenced by HostedPhysicalMemoryManager::allocateRegion(), X86CommonPhysicalMemoryManager::allocateRegion(), Arm64PhysicalMemoryManager::allocateRegion(), Armv7PhysicalMemoryManager::allocateRegion(), and HostedPhysicalMemoryManager::initialisationDone().
|
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().
|
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().
|
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().
|
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().
|
static |
If this flag is set the pages are physically continuous
Definition at line 44 of file include/pedigree/kernel/processor/PhysicalMemoryManager.h.
Referenced by HostedPhysicalMemoryManager::allocateRegion(), X86CommonPhysicalMemoryManager::allocateRegion(), Arm64PhysicalMemoryManager::allocateRegion(), Armv7PhysicalMemoryManager::allocateRegion(), Archive::Archive(), KernelElf::initialise(), BusMasterIde::initialise(), and Device::Address::map().
|
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().
|
protected |
List of memory-regions
Definition at line 176 of file include/pedigree/kernel/processor/PhysicalMemoryManager.h.
Referenced by allocateMemoryRegionList(), HostedPhysicalMemoryManager::allocateRegion(), X86CommonPhysicalMemoryManager::allocateRegion(), Arm64PhysicalMemoryManager::allocateRegion(), Armv7PhysicalMemoryManager::allocateRegion(), HostedPhysicalMemoryManager::initialisationDone(), X86CommonPhysicalMemoryManager::shutdown(), HostedPhysicalMemoryManager::unmapRegion(), X86CommonPhysicalMemoryManager::unmapRegion(), Arm64PhysicalMemoryManager::unmapRegion(), Armv7PhysicalMemoryManager::unmapRegion(), and HostedPhysicalMemoryManager::~HostedPhysicalMemoryManager().
|
static |
If this flag is set we allocate pages that are not in RAM
Definition at line 46 of file include/pedigree/kernel/processor/PhysicalMemoryManager.h.
Referenced by HostedPhysicalMemoryManager::allocateRegion(), X86CommonPhysicalMemoryManager::allocateRegion(), Arm64PhysicalMemoryManager::allocateRegion(), Armv7PhysicalMemoryManager::allocateRegion(), and Device::Address::map().
|
static |
Only allocate virtual address space for the region.
Definition at line 52 of file include/pedigree/kernel/processor/PhysicalMemoryManager.h.
Referenced by HostedPhysicalMemoryManager::allocateRegion(), X86CommonPhysicalMemoryManager::allocateRegion(), Arm64PhysicalMemoryManager::allocateRegion(), Armv7PhysicalMemoryManager::allocateRegion(), and MemoryPool::initialise().