20#ifndef KERNEL_PROCESSOR_PHYSICALMEMORYMANAGER_H
21#define KERNEL_PROCESSOR_PHYSICALMEMORYMANAGER_H
23#include "pedigree/kernel/TargetInfo.h"
24#include "pedigree/kernel/compiler.h"
25#include "pedigree/kernel/processor/types.h"
26#include "pedigree/kernel/utilities/Vector.h"
44 static const size_t continuous = 1 << 0;
46 static const size_t nonRamMemory = 1 << 1;
50 static const size_t force = 1 << 2;
52 static const size_t virtualOnly = 1 << 3;
55 static const size_t below1MB = 1 << 4;
57 static const size_t below16MB = 1 << 5;
59 static const size_t below4GB = 1 << 6;
61 static const size_t below64GB = 1 << 7;
64 static const size_t addressConstraints = below1MB | below16MB | below4GB | below64GB;
67 static const size_t anonymous = 1 << 8;
80 virtual physical_uintptr_t
allocatePage(
size_t pageConstraints = 0) = 0;
82 virtual physical_uintptr_t tryAllocatePage() {
86 virtual bool copyPhysicalPageToBuffer(physical_uintptr_t page,
void* buffer) {
89 virtual bool copyPhysicalPageFromBuffer(physical_uintptr_t page,
const void* buffer) {
93 uint64_t totalPages = 0;
94 uint64_t freePages = 0;
95 bool available =
false;
102 virtual void freePage(physical_uintptr_t page) = 0;
113 virtual void pin(physical_uintptr_t page) = 0;
115#if HOSTED && PEDIGREE_HOSTED_SMOKE_TESTS
116 static EXPORTED_PUBLIC
void setTryAllocationFailureForTest(ssize_t after);
118 static EXPORTED_PUBLIC
size_t pageReferenceCountForTest(physical_uintptr_t page);
130 size_t Flags, physical_uintptr_t start = -1) = 0;
140 inline MemoryRegionInfo(
void* VirtualAddress, physical_uintptr_t PhysicalAddress,
size_t size,
142 : pVirtualAddress(VirtualAddress),
144 sVirtualAddress(size),
167 virtual size_t freePageCount()
const;
Special memory entity in the kernel's virtual address space.
virtual physical_uintptr_t allocatePage(size_t pageConstraints=0)=0
static constexpr size_t getPageSize() PURE
PhysicalMemoryManager(const PhysicalMemoryManager &)
virtual void freePageUnlocked(physical_uintptr_t page)=0
Vector< MemoryRegion * > m_MemoryRegions
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
PhysicalMemoryManager & operator=(const PhysicalMemoryManager &)
virtual void unmapRegion(MemoryRegion *pRegion)=0
static constexpr size_t getPageSize() noexcept
A vector / dynamic array.
uintptr_t physicalAddress(physical_uintptr_t address) PURE
MemoryRegionInfo(void *VirtualAddress, physical_uintptr_t PhysicalAddress, size_t size, const char *name)
physical_uintptr_t physicalAddress