20 #include "PhysicalMemoryManager.h" 21 #include "../ppc32/VirtualAddressSpace.h" 22 #include "pedigree/kernel/Log.h" 23 #include "pedigree/kernel/panic.h" 24 #include "pedigree/kernel/processor/MemoryRegion.h" 25 #include "pedigree/kernel/processor/VirtualAddressSpace.h" 34 physical_uintptr_t PpcCommonPhysicalMemoryManager::allocatePage()
39 return (m_NextPage += 0x1000);
41 return m_PageStack.allocate();
47 panic(
"freePage called in initial mode!");
48 m_PageStack.free(page);
51 MemoryRegion &Region,
size_t cPages,
size_t pageConstraints,
size_t Flags,
52 physical_uintptr_t start)
55 if (start != static_cast<physical_uintptr_t>(-1))
57 if ((pageConstraints &
continuous) != continuous)
58 panic(
"PhysicalMemoryManager::allocateRegion(): function misused");
63 if (m_PhysicalRanges.allocateSpecific(
75 WARNING(
"AllocateRegion: MemoryRegion allocation failed.");
82 for (
size_t i = 0; i < cPages; i++)
83 if (virtualAddressSpace.
map(
85 reinterpret_cast<void *>(
91 WARNING(
"AllocateRegion: VirtualAddressSpace::map failed.");
112 WARNING(
"AllocateRegion: MemoryRegion allocation failed.");
120 for (
size_t i = 0; i < cPages; i++)
122 physical_uintptr_t page = m_PageStack.allocate();
124 if (virtualAddressSpace.
map(
126 reinterpret_cast<void *>(
130 WARNING(
"AllocateRegion: VirtualAddressSpace::map failed.");
148 : m_PageStack(), m_InitialMode(true), m_NextPage(PMM_INITIAL_START),
156 void PpcCommonPhysicalMemoryManager::initialise(
160 for (uintptr_t i = 0; i < ramMax; i +=
getPageSize())
162 bool claimed =
false;
166 if ((i >= t.phys) && (i < t.phys + t.size))
172 if ((i >= PMM_INITIAL_START) && (i <
m_NextPage))
189 if (t.phys >= ramMax)
191 static_cast<uint64_t>(t.phys), t.size);
196 KERNEL_VIRTUAL_MEMORYREGION_ADDRESS, KERNEL_VIRTUAL_MEMORYREGION_SIZE);
216 for (
size_t i = 0; i < cPages; i++)
217 virtualAddressSpace.
unmap(reinterpret_cast<void *>(
227 : m_Stack(0), m_StackMax(0), m_StackSize(0)
234 panic(
"No more physical pages left to allocate!");
244 physical_uintptr_t *oldStack =
m_Stack;
248 reinterpret_cast<uint8_t *>(
m_Stack),
249 reinterpret_cast<uint8_t *>(oldStack),
m_StackSize);
physical_uintptr_t * m_Stack
void pushBack(const T &value)
virtual void unmap(void *virtualAddress)=0
static size_t getPageSize() PURE
static PhysicalMemoryManager & instance()
static const size_t continuous
A vector / dynamic array.
static const size_t force
static PpcCommonPhysicalMemoryManager & instance()
virtual bool map(physical_uintptr_t physicalAddress, void *virtualAddress, size_t flags)=0
physical_uintptr_t m_PhysicalAddress
static EXPORTED_PUBLIC VirtualAddressSpace & getKernelAddressSpace()
void free(T address, T length, bool merge=true)
physical_uintptr_t m_NextPage
PpcCommonPhysicalMemoryManager()
RangeList< uintptr_t > m_MemoryRegions
RangeList< uint64_t > m_PhysicalRanges
uintptr_t physicalAddress(physical_uintptr_t address) PURE
Special memory entity in the kernel's virtual address space.
void unmapRegion(MemoryRegion *pRegion)
bool allocateSpecific(T address, T length)
physical_uintptr_t allocate()
void free(uintptr_t physicalAddress)
Implementation of the PhysicalMemoryManager for common ppc.
Translation getTranslation(size_t n)
void * virtualAddress() const
static const size_t nonRamMemory
virtual void freePage(physical_uintptr_t page)
void EXPORTED_PUBLIC panic(const char *msg) NORETURN
virtual bool allocateRegion(MemoryRegion &Region, size_t cPages, size_t pageConstraints, size_t Flags, physical_uintptr_t start=-1)
Vector< MemoryRegion * > m_MemoryRegions
static PpcCommonPhysicalMemoryManager m_Instance
virtual ~PpcCommonPhysicalMemoryManager()
size_t getNumTranslations()
PageStack() INITIALISATION_ONLY