20 #include "PhysicalMemoryManager.h"    21 #include "VirtualAddressSpace.h"    22 #include "pedigree/kernel/LockGuard.h"    23 #include "pedigree/kernel/Log.h"    24 #include "pedigree/kernel/processor/MemoryRegion.h"    25 #include "pedigree/kernel/processor/Processor.h"    39     physical_uintptr_t ptr = m_PageStack.allocate(0);
    46     m_PageStack.free(page);
    50     if (!m_Lock.acquired())
    51         FATAL(
"ArmV7PhysicalMemoryManager::freePageUnlocked called without an "    54     m_PageStack.free(page);
    57     MemoryRegion &Region, 
size_t cPages, 
size_t pageConstraints, 
size_t Flags,
    58     physical_uintptr_t start)
    63     if (start != static_cast<physical_uintptr_t>(-1))
    65         if ((pageConstraints & 
continuous) != continuous)
    66             panic(
"PhysicalMemoryManager::allocateRegion(): function misused");
    69 #ifdef ARM_BEAGLE  // Beagleboard RAM locations    70         if ((start < 0x80000000) || (start >= 0x90000000))
    72             if (!m_NonRAMRanges.allocateSpecific(start, cPages * 
getPageSize()))
    81             if (!m_PhysicalRanges.allocateSpecific(
    89         if (m_VirtualMemoryRegions.allocate(cPages * 
getPageSize(), vAddress) ==
    92             WARNING(
"AllocateRegion: MemoryRegion allocation failed.");
    98         if (vAddress > 0x40000000)  
   101             virtualAddressSpace =
   103         for (
size_t i = 0; i < cPages; i++)
   104             if (virtualAddressSpace->
map(
   106                     reinterpret_cast<void *>(
   110                 m_VirtualMemoryRegions.free(
   112                 WARNING(
"AllocateRegion: VirtualAddressSpace::map failed.");
   128         bool bContinuous = 
false;
   129         physical_uintptr_t physAddr = 0;
   133             if (!m_PhysicalRanges.allocate(cPages * 
getPageSize(), physAddr))
   139         if (m_VirtualMemoryRegions.allocate(
   143             WARNING(
"AllocateRegion: MemoryRegion allocation failed.");
   149         if (vAddress > 0x40000000)  
   152             virtualAddressSpace =
   157             for (
size_t i = 0; i < cPages; i++)
   159                 physical_uintptr_t page = 0;
   164                     page = m_PageStack.allocate(pageConstraints);
   165                 if (virtualAddressSpace->
map(
   167                         reinterpret_cast<void *>(
   172                     WARNING(
"AllocateRegion: VirtualAddressSpace::map failed.");
   196 extern char __start, __end;
   201     physical_uintptr_t addr = 0;
   202     for (addr = reinterpret_cast<physical_uintptr_t>(&__end); addr < 0x87000000;
   205         m_PageStack.free(addr);
   207     for (addr = 0x88000000; addr < 0x8F000000; addr += 0x1000)
   209         m_PageStack.free(addr);
   212     size_t kernelSize = 
reinterpret_cast<physical_uintptr_t
>(&__end) -
   213                         reinterpret_cast<physical_uintptr_t>(&__start);
   214     if (kernelSize % 4096)
   216         kernelSize += 0x1000;
   217         kernelSize &= ~0xFFF;
   220     m_PhysicalRanges.free(0x80000000 + kernelSize, 0xF000000);
   221     m_PhysicalRanges.allocateSpecific(
   222         0x80000000, reinterpret_cast<physical_uintptr_t>(&__end) - 0x80000000);
   223     m_PhysicalRanges.allocateSpecific(0x87000000, 0x1000000);
   225     m_NonRAMRanges.free(0, 0x80000000);
   226     m_NonRAMRanges.free(0x90000000, 0x60000000);
   230     m_VirtualMemoryRegions.free(
   231         reinterpret_cast<uintptr_t>(KERNEL_VIRTUAL_MEMORYREGION_ADDRESS),
   232         KERNEL_VIRTUAL_MEMORYREGION_SIZE);
   236     : m_PageStack(), m_PhysicalRanges(), m_VirtualMemoryRegions(),
   237       m_Lock(false, true), m_RegionLock(false, true)
   248     physical_uintptr_t ret = 0;
   249     if ((m_StackMax != m_StackSize) && m_StackSize)
   251         m_StackSize -= 
sizeof(physical_uintptr_t);
   253             *(
reinterpret_cast<uint32_t *
>(m_Stack) +
   254               m_StackSize / 
sizeof(physical_uintptr_t));
   264     if (physicalAddress < 0x80000000)
   266     else if (physicalAddress >= 0x90000000)
   275     if (m_StackMax == m_StackSize)
   280         if (!AddressSpace.
map(
   281                 physicalAddress, adjust_pointer(m_Stack, m_StackMax),
   288     *(
reinterpret_cast<physical_uintptr_t *
>(m_Stack) +
   290     m_StackSize += 
sizeof(physical_uintptr_t);
   297     m_Stack = KERNEL_VIRTUAL_PAGESTACK_4GB;
 ArmV7PhysicalMemoryManager()
 
Bootstrap structure passed to the kernel entry point. 
 
void pushBack(const T &value)
 
static size_t getPageSize() PURE
 
static PhysicalMemoryManager & instance()
 
static const size_t continuous
 
PageStack() INITIALISATION_ONLY
 
static const size_t force
 
void free(physical_uintptr_t physicalAddress)
 
static ArmV7PhysicalMemoryManager m_Instance
 
virtual bool map(physical_uintptr_t physicalAddress, void *virtualAddress, size_t flags)=0
 
physical_uintptr_t m_PhysicalAddress
 
static EXPORTED_PUBLIC VirtualAddressSpace & getKernelAddressSpace()
 
static ProcessorInformation & information()
 
virtual ~ArmV7PhysicalMemoryManager()
 
virtual physical_uintptr_t allocatePage()
 
static const size_t Write
 
virtual bool allocateRegion(MemoryRegion &Region, size_t cPages, size_t pageConstraints, size_t Flags, physical_uintptr_t start=-1)
 
uintptr_t physicalAddress(physical_uintptr_t address) PURE
 
static const size_t KernelMode
 
Special memory entity in the kernel's virtual address space. 
 
virtual bool map(physical_uintptr_t physicalAddress, void *virtualAddress, size_t flags)
 
virtual void freePage(physical_uintptr_t page)
 
Implementation of the PhysicalMemoryManager for common arm. 
 
virtual void unmapRegion(MemoryRegion *pRegion)
 
virtual void freePageUnlocked(physical_uintptr_t page)
 
static ArmV7PhysicalMemoryManager & instance()
 
physical_uintptr_t allocate(size_t constraints)
 
void EXPORTED_PUBLIC panic(const char *msg) NORETURN
 
Vector< MemoryRegion * > m_MemoryRegions