1 /* 2 * Copyright 2006, Haiku Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Michael Lotz <mmlr@mlotz.ch> 7 */ 8 9 #ifndef _PHYSICAL_MEMORY_ALLOCATOR_H_ 10 #define _PHYSICAL_MEMORY_ALLOCATOR_H_ 11 12 #include <SupportDefs.h> 13 #include <lock.h> 14 15 16 class PhysicalMemoryAllocator { 17 public: 18 PhysicalMemoryAllocator(const char *name, 19 size_t minSize, 20 size_t maxSize, 21 uint32 minCountPerBlock); 22 ~PhysicalMemoryAllocator(); 23 24 status_t InitCheck() { return fStatus; }; 25 26 status_t Allocate(size_t size, 27 void **logicalAddress, 28 void **physicalAddress); 29 30 // one of both addresses needs to be provided, the other may be NULL 31 status_t Deallocate(size_t size, 32 void *logicalAddress, 33 void *physicalAddress); 34 35 void PrintToStream(); 36 void DumpArrays(); 37 void DumpLastArray(); 38 void DumpFreeSlots(); 39 40 private: 41 bool _Lock(); 42 void _Unlock(); 43 44 char *fName; 45 46 size_t fOverhead; 47 size_t fManagedMemory; 48 status_t fStatus; 49 50 benaphore fLock; 51 area_id fArea; 52 void *fLogicalBase; 53 void *fPhysicalBase; 54 55 int32 fArrayCount; 56 size_t *fBlockSize; 57 size_t *fArrayLength; 58 size_t *fArrayOffset; 59 uint8 **fArray; 60 }; 61 62 #endif // !_PHYSICAL_MEMORY_ALLOCATOR_H_ 63