|
The Pedigree Project 0.1
|
Implementation of the PhysicalMemoryManager for common x86. More...
#include <PhysicalMemoryManager.h>
Inheritance diagram for X86CommonPhysicalMemoryManager:
Collaboration diagram for X86CommonPhysicalMemoryManager:Classes | |
| struct | page |
| class | PageHashable |
| class | PageStack |
| The Stack of pages (below4GB, below64GB, no constraint). More... | |
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 | initialise64 (const BootstrapStruct_t &Info) INITIALISATION_ONLY |
| void | initialisationDone () |
| void | shutdown () |
| const RangeList< uint64_t > & | getAcpiRanges () const |
| virtual size_t | freePageCount () const override |
Public Member Functions inherited from PhysicalMemoryManager | |
| void | allocateMemoryRegionList (Vector< MemoryRegionInfo * > &MemoryRegions) |
| void | freeMemoryRegionList (Vector< MemoryRegionInfo * > &MemoryRegions) |
Static Public Member Functions | |
| static X86CommonPhysicalMemoryManager & | instance () |
Static Public Member Functions inherited from PhysicalMemoryManager | |
| static PhysicalMemoryManager & | instance () |
| static constexpr size_t | getPageSize () PURE |
Protected Member Functions | |
| X86CommonPhysicalMemoryManager () INITIALISATION_ONLY | |
| virtual | ~X86CommonPhysicalMemoryManager () override |
Protected Member Functions inherited from PhysicalMemoryManager | |
| PhysicalMemoryManager () | |
| virtual | ~PhysicalMemoryManager () |
Private Types | |
| typedef HashTable< PageHashable, struct page > | MetadataTable |
Private Member Functions | |
| X86CommonPhysicalMemoryManager (const X86CommonPhysicalMemoryManager &) | |
| X86CommonPhysicalMemoryManager & | operator= (const X86CommonPhysicalMemoryManager &) |
| void | unmapRegion (MemoryRegion *pRegion) override |
| virtual void | freePageUnlocked (physical_uintptr_t page) override |
Private Attributes | |
| PageStack | m_PageStack |
| RangeList< uint32_t > | m_RangeBelow1MB |
| RangeList< uint32_t > | m_RangeBelow16MB |
| RangeList< uint64_t > | m_PhysicalRanges |
| RangeList< uint64_t > | m_AcpiRanges |
| RangeList< uintptr_t > | m_MemoryRegions |
| Spinlock | m_Lock |
| Spinlock | m_RegionLock |
| HashTable< PageHashable, struct page > | m_PageMetadata |
| bool | m_PageMetadataReady |
| physical_uintptr_t | m_BootstrapPinnedPage |
| size_t | m_BootstrapPinnedPageRefcount |
Static Private Attributes | |
| static X86CommonPhysicalMemoryManager | m_Instance |
Friends | |
| class | CacheManager |
| class | Cache |
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 |
Implementation of the PhysicalMemoryManager for common x86.
The common x86 implementation of the PhysicalMemoryManager
Definition at line 44 of file kernel/core/processor/x86_common/PhysicalMemoryManager.h.
|
private |
Definition at line 255 of file kernel/core/processor/x86_common/PhysicalMemoryManager.h.
|
protected |
The constructor
Definition at line 824 of file x86_common/PhysicalMemoryManager.cc.
|
overrideprotectedvirtual |
The destructor
Definition at line 837 of file x86_common/PhysicalMemoryManager.cc.
|
private |
The copy-constructor
|
overridevirtual |
Allocate a single page with optional constraints.
Implements PhysicalMemoryManager.
Definition at line 66 of file x86_common/PhysicalMemoryManager.cc.
References Spinlock::acquire(), X86CommonPhysicalMemoryManager::PageStack::allocate(), MemoryPressureManager::compact(), MemoryPressureManager::compactingForCurrentExecution(), EMIT_IF, ProcessorBase::m_Initialised, m_Lock, m_PageStack, panic(), and Spinlock::release().
Referenced by allocateRegion().
Here is the caller graph for this function:
|
overridevirtual |
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) |
Implements PhysicalMemoryManager.
Definition at line 264 of file x86_common/PhysicalMemoryManager.cc.
References PhysicalMemoryManager::addressConstraints, RangeList< T, Reversed >::allocate(), allocatePage(), RangeList< T, Reversed >::allocateSpecific(), PhysicalMemoryManager::anonymous, PhysicalMemoryManager::below16MB, PhysicalMemoryManager::below1MB, PhysicalMemoryManager::continuous, PhysicalMemoryManager::force, RangeList< T, Reversed >::free(), freePage(), VirtualAddressSpace::getMapping(), PhysicalMemoryManager::getPageSize(), Hex, ProcessorBase::information(), PhysicalMemoryManager::m_MemoryRegions, m_MemoryRegions, MemoryRegion::m_PhysicalAddress, m_PhysicalRanges, m_RangeBelow16MB, m_RangeBelow1MB, MemoryRegion::m_Size, MemoryRegion::m_VirtualAddress, VirtualAddressSpace::map(), PhysicalMemoryManager::nonRamMemory, panic(), Vector< T >::pushBack(), VirtualAddressSpace::unmap(), and PhysicalMemoryManager::virtualOnly.
|
overridevirtual |
Reimplemented from PhysicalMemoryManager.
Definition at line 177 of file x86_common/PhysicalMemoryManager.cc.
|
overridevirtual |
Reimplemented from PhysicalMemoryManager.
Definition at line 166 of file x86_common/PhysicalMemoryManager.cc.
|
overridevirtual |
Free a page allocated with the allocatePage() function
| [in] | page | physical address of the page |
Implements PhysicalMemoryManager.
Definition at line 189 of file x86_common/PhysicalMemoryManager.cc.
References freePageUnlocked(), and m_Lock.
Referenced by allocateRegion(), and unmapRegion().
Here is the caller graph for this function:
|
overridevirtual |
Specifies the number of pages that remain free on the system.
Reimplemented from PhysicalMemoryManager.
Definition at line 62 of file x86_common/PhysicalMemoryManager.cc.
References m_PageStack.
|
overrideprivatevirtual |
Same as freePage, but without the lock. Will panic if the lock is unlocked.
Implements PhysicalMemoryManager.
Definition at line 194 of file x86_common/PhysicalMemoryManager.cc.
References X86CommonPhysicalMemoryManager::PageStack::free(), PhysicalMemoryManager::getPageSize(), ProcessorBase::m_Initialised, m_Lock, m_PageMetadata, m_PageMetadataReady, and m_PageStack.
Referenced by freePage().
Here is the caller graph for this function:
|
inline |
Definition at line 88 of file kernel/core/processor/x86_common/PhysicalMemoryManager.h.
| void X86CommonPhysicalMemoryManager::initialisationDone | ( | ) |
Unmap & free the .init section
Definition at line 788 of file x86_common/PhysicalMemoryManager.cc.
References Dec, EMIT_IF, RangeList< T, Reversed >::free(), VirtualAddressSpace::getKernelAddressSpace(), VirtualAddressSpace::getMapping(), PhysicalMemoryManager::getPageSize(), Hex, m_RangeBelow16MB, and VirtualAddressSpace::unmap().
| void X86CommonPhysicalMemoryManager::initialise | ( | const BootstrapStruct_t & | Info | ) |
Initialise the page stack
| [in] | Info | reference to the multiboot information structure |
Definition at line 448 of file x86_common/PhysicalMemoryManager.cc.
References RangeList< T, Reversed >::Range::address, RangeList< T, Reversed >::allocateSpecific(), EMIT_IF, RangeList< T, Reversed >::free(), X86CommonPhysicalMemoryManager::PageStack::free(), PhysicalMemoryManager::getPageSize(), RangeList< T, Reversed >::getRange(), Hex, RangeList< T, Reversed >::Range::length, m_AcpiRanges, m_Lock, m_MemoryRegions, m_PageMetadata, m_PageMetadataReady, m_PageStack, m_PhysicalRanges, m_RangeBelow16MB, m_RangeBelow1MB, X86CommonPhysicalMemoryManager::PageStack::markBelow4GReady(), panic(), and RangeList< T, Reversed >::size().
Referenced by X86CommonPhysicalMemoryManager::PageStack::free().
Here is the caller graph for this function:| void X86CommonPhysicalMemoryManager::initialise64 | ( | const BootstrapStruct_t & | Info | ) |
Initialise the page stack, with ranges above 4 GB. Requires ranges below 4 GB to be available (call initialise first).
| [in] | Info | reference to the multiboot information structure |
Definition at line 633 of file x86_common/PhysicalMemoryManager.cc.
References RangeList< T, Reversed >::Range::address, RangeList< T, Reversed >::allocateSpecific(), EMIT_IF, RangeList< T, Reversed >::free(), X86CommonPhysicalMemoryManager::PageStack::free(), VirtualAddressSpace::getKernelAddressSpace(), PhysicalMemoryManager::getPageSize(), RangeList< T, Reversed >::getRange(), Hex, VirtualAddressSpace::KernelMode, RangeList< T, Reversed >::Range::length, m_AcpiRanges, m_PageStack, m_PhysicalRanges, VirtualAddressSpace::mapHuge(), X86CommonPhysicalMemoryManager::PageStack::markAbove4GReady(), panic(), RangeList< T, Reversed >::size(), and VirtualAddressSpace::Write.
|
inlinestatic |
Get the X86CommonPhysicalMemoryManager instance
Definition at line 55 of file kernel/core/processor/x86_common/PhysicalMemoryManager.h.
References m_Instance.
|
overridevirtual |
Reimplemented from PhysicalMemoryManager.
Definition at line 160 of file x86_common/PhysicalMemoryManager.cc.
|
private |
The copy-constructor
|
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 235 of file x86_common/PhysicalMemoryManager.cc.
References m_Lock, m_PageMetadata, and m_PageMetadataReady.
| void X86CommonPhysicalMemoryManager::shutdown | ( | ) |
Clean up tracking structures.
Definition at line 442 of file x86_common/PhysicalMemoryManager.cc.
References Vector< T >::clear(), PhysicalMemoryManager::m_MemoryRegions, and m_PageMetadata.
|
overridevirtual |
Reimplemented from PhysicalMemoryManager.
Definition at line 126 of file x86_common/PhysicalMemoryManager.cc.
|
overrideprivatevirtual |
Unmaps a memory region - called ONLY from MemoryRegion's destructor.
Implements PhysicalMemoryManager.
Definition at line 839 of file x86_common/PhysicalMemoryManager.cc.
References Vector< T >::end(), Vector< T >::erase(), RangeList< T, Reversed >::free(), freePage(), VirtualAddressSpace::getKernelAddressSpace(), VirtualAddressSpace::getMapping(), PhysicalMemoryManager::getPageSize(), VirtualAddressSpace::isMapped(), PhysicalMemoryManager::m_MemoryRegions, m_MemoryRegions, m_PhysicalRanges, m_RangeBelow16MB, m_RangeBelow1MB, MemoryRegion::physicalAddress(), MemoryRegion::size(), VirtualAddressSpace::unmap(), and MemoryRegion::virtualAddress().
|
friend |
Definition at line 46 of file kernel/core/processor/x86_common/PhysicalMemoryManager.h.
|
friend |
Definition at line 45 of file kernel/core/processor/x86_common/PhysicalMemoryManager.h.
|
private |
RangeList of ACPI memory
Definition at line 209 of file kernel/core/processor/x86_common/PhysicalMemoryManager.h.
Referenced by initialise(), and initialise64().
|
private |
Definition at line 266 of file kernel/core/processor/x86_common/PhysicalMemoryManager.h.
|
private |
Definition at line 267 of file kernel/core/processor/x86_common/PhysicalMemoryManager.h.
|
staticprivate |
The X86CommonPhysicalMemoryManager class instance
Definition at line 217 of file kernel/core/processor/x86_common/PhysicalMemoryManager.h.
Referenced by instance().
|
private |
To guard against multiprocessor reentrancy.
Definition at line 220 of file kernel/core/processor/x86_common/PhysicalMemoryManager.h.
Referenced by allocatePage(), freePage(), freePageUnlocked(), initialise(), and pin().
|
private |
Virtual-memory available for MemoryRegions
Definition at line 214 of file kernel/core/processor/x86_common/PhysicalMemoryManager.h.
Referenced by allocateRegion(), initialise(), and unmapRegion().
|
private |
Page metadata table
Definition at line 258 of file kernel/core/processor/x86_common/PhysicalMemoryManager.h.
Referenced by freePageUnlocked(), initialise(), pin(), and shutdown().
|
private |
A shared SLAM zero page is pinned while this table is itself being allocated through SLAM. Keep that one bootstrap reference allocation-free until the table can own it.
Definition at line 265 of file kernel/core/processor/x86_common/PhysicalMemoryManager.h.
Referenced by freePageUnlocked(), initialise(), and pin().
|
private |
The page stack
Definition at line 198 of file kernel/core/processor/x86_common/PhysicalMemoryManager.h.
Referenced by allocatePage(), freePageCount(), freePageUnlocked(), initialise(), and initialise64().
|
private |
RangeList of free physical memory
Definition at line 206 of file kernel/core/processor/x86_common/PhysicalMemoryManager.h.
Referenced by allocateRegion(), initialise(), initialise64(), and unmapRegion().
|
private |
RangeList for the usable memory below 16MB
Definition at line 203 of file kernel/core/processor/x86_common/PhysicalMemoryManager.h.
Referenced by allocateRegion(), initialisationDone(), initialise(), and unmapRegion().
|
private |
RangeList for the usable memory below 1MB
Definition at line 201 of file kernel/core/processor/x86_common/PhysicalMemoryManager.h.
Referenced by allocateRegion(), initialise(), and unmapRegion().
|
private |
Definition at line 220 of file kernel/core/processor/x86_common/PhysicalMemoryManager.h.