FreeNOS
|
Allocator which separates kernel mapped memory at virtual and physical addresses. More...
#include <SplitAllocator.h>
Public Member Functions | |
SplitAllocator (const Range physRange, const Range virtRange, const Size pageSize) | |
Class constructor. More... | |
virtual Size | available () const |
Get memory available. More... | |
virtual Result | allocate (Range &args) |
Allocate physical memory. More... | |
Result | allocateSparse (const Range &range, CallbackFunction *function) |
Allocate sparse (non-contiguous) physical memory. More... | |
Result | allocate (Range &phys, Range &virt) |
Allocate physical/virtual memory. More... | |
Result | allocate (const Address addr) |
Allocate one physical memory page. More... | |
virtual Result | release (const Address addr) |
Release memory page. More... | |
Address | toVirtual (const Address phys) const |
Convert Address to virtual pointer. More... | |
Address | toPhysical (const Address virt) const |
Convert Address to physical pointer. More... | |
bool | isAllocated (const Address page) const |
Check if a physical page is allocated. More... | |
Public Member Functions inherited from Allocator | |
Allocator () | |
Default class constructor. More... | |
Allocator (const Range range) | |
Class constructor with Range input. More... | |
virtual | ~Allocator () |
Class destructor. More... | |
void | setParent (Allocator *parent) |
Set parent allocator. More... | |
Allocator * | parent () |
Get parent Allocator. More... | |
Address | base () const |
Get memory base address for allocations. More... | |
Size | alignment () const |
Get memory alignment in bytes for allocations. More... | |
virtual Size | size () const |
Get memory size. More... | |
Private Attributes | |
BitAllocator | m_alloc |
Physical memory allocator. More... | |
const Range | m_virtRange |
Virtual memory range to manage. More... | |
const Size | m_pageSize |
Size of a memory page. More... | |
Additional Inherited Members | |
Public Types inherited from Allocator | |
enum | Result { Success = 0, InvalidAddress, InvalidSize, InvalidAlignment, OutOfMemory } |
Allocation results. More... | |
typedef struct Allocator::Range | Range |
Describes a range of memory. More... | |
Static Public Member Functions inherited from Allocator | |
static void | setDefault (Allocator *alloc) |
Makes the given Allocator the default. More... | |
static Allocator * | getDefault () |
Retrieve the currently default Allocator. More... | |
Protected Member Functions inherited from Allocator | |
Address | aligned (const Address addr, const Size boundary) const |
Align memory address. More... | |
Allocator which separates kernel mapped memory at virtual and physical addresses.
Definition at line 37 of file SplitAllocator.h.
SplitAllocator::SplitAllocator | ( | const Range | physRange, |
const Range | virtRange, | ||
const Size | pageSize | ||
) |
Class constructor.
physRange | Block of physical continguous memory to be managed. |
virtRange | Same block of memory in the virtual address space. |
pageSize | Size of a single memory page. |
Definition at line 20 of file SplitAllocator.cpp.
Allocator::Result SplitAllocator::allocate | ( | const Address | addr | ) |
Allocate one physical memory page.
addr | Physical memory page address |
Definition at line 84 of file SplitAllocator.cpp.
References BitAllocator::allocateAt(), and m_alloc.
|
virtual |
Allocate physical memory.
args | Contains the requested size and alignment on input. The alignment value must be a multiple of the pageSize. On output, contains the actual allocated address. |
Reimplemented from Allocator.
Definition at line 35 of file SplitAllocator.cpp.
References BitAllocator::allocate(), and m_alloc.
Referenced by allocateSparse(), ARMKernel::ARMKernel(), ARMPaging::initialize(), IntelPaging::initialize(), IntelKernel::IntelKernel(), Kernel::Kernel(), Kernel::loadBootProgram(), ARMFirstTable::map(), IntelPageDirectory::map(), MemoryContext::mapRangeContiguous(), SunxiKernel::SunxiKernel(), and VMCtlHandler().
Allocator::Result SplitAllocator::allocate | ( | Allocator::Range & | phys, |
Allocator::Range & | virt | ||
) |
Allocate physical/virtual memory.
phys | Contains the requested size and alignment on input. The alignment value must be a multiple of the pageSize. On output, contains the actual allocated physical address. |
virt | Contains the allocated memory translated for virtual addressing. |
Definition at line 69 of file SplitAllocator.cpp.
References Allocator::Range::address, Allocator::Range::alignment, BitAllocator::allocate(), m_alloc, Allocator::Range::size, Allocator::Success, and toVirtual().
Allocator::Result SplitAllocator::allocateSparse | ( | const Range & | range, |
CallbackFunction * | function | ||
) |
Allocate sparse (non-contiguous) physical memory.
range | Contains the requested size on input. The alignment and address values are unused. |
function | Called for each successful allocation of a page. |
Definition at line 40 of file SplitAllocator.cpp.
References Allocator::Range::address, Allocator::Range::alignment, allocate(), BitAllocator::available(), CallbackFunction::execute(), Allocator::InvalidSize, m_alloc, m_pageSize, Allocator::OutOfMemory, Allocator::Range::size, Allocator::Success, and ZERO.
Referenced by MemoryContext::mapRangeSparse().
|
virtual |
Get memory available.
Reimplemented from Allocator.
Definition at line 30 of file SplitAllocator.cpp.
References BitAllocator::available(), and m_alloc.
Referenced by SystemInfoHandler().
bool SplitAllocator::isAllocated | ( | const Address | page | ) | const |
Check if a physical page is allocated.
Definition at line 106 of file SplitAllocator.cpp.
References BitAllocator::isAllocated(), and m_alloc.
Referenced by IntelPageDirectory::releasePhysical(), ARMFirstTable::releasePhysical(), and VMCtlHandler().
|
virtual |
Release memory page.
addr | Physical memory address of page to release. |
Reimplemented from Allocator.
Definition at line 89 of file SplitAllocator.cpp.
References m_alloc, and BitAllocator::release().
Referenced by MemoryContext::release(), IntelPageDirectory::releasePhysical(), ARMFirstTable::releasePhysical(), IntelPageDirectory::releaseSection(), ARMFirstTable::releaseSection(), ARMPaging::~ARMPaging(), IntelPaging::~IntelPaging(), and IntelProcess::~IntelProcess().
Convert Address to physical pointer.
virt | Virtual address |
Definition at line 100 of file SplitAllocator.cpp.
References Allocator::Range::address, Allocator::base(), and m_virtRange.
Referenced by Kernel::Kernel(), and IntelProcess::~IntelProcess().
Convert Address to virtual pointer.
phys | Physical address |
Definition at line 94 of file SplitAllocator.cpp.
References Allocator::Range::address, Allocator::base(), and m_virtRange.
Referenced by allocate(), IntelPageDirectory::getPageTable(), ARMFirstTable::getSecondTable(), IntelPaging::initialize(), Kernel::loadBootImage(), and Kernel::loadBootProgram().
|
private |
Physical memory allocator.
Definition at line 141 of file SplitAllocator.h.
Referenced by allocate(), allocateSparse(), available(), isAllocated(), and release().
|
private |
Size of a memory page.
Definition at line 147 of file SplitAllocator.h.
Referenced by allocateSparse().
|
private |
Virtual memory range to manage.
Definition at line 144 of file SplitAllocator.h.
Referenced by toPhysical(), and toVirtual().