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 #ifndef _PHYSICAL_MEMORY_ALLOCATOR_H_ 9 #define _PHYSICAL_MEMORY_ALLOCATOR_H_ 10 11 12 #include <condition_variable.h> 13 #include <SupportDefs.h> 14 #include <lock.h> 15 16 17 class PhysicalMemoryAllocator { 18 public: 19 PhysicalMemoryAllocator(const char *name, 20 size_t minSize, 21 size_t maxSize, 22 uint32 minCountPerBlock); 23 ~PhysicalMemoryAllocator(); 24 25 status_t InitCheck() { return fStatus; } 26 27 status_t Allocate(size_t size, 28 void **logicalAddress, 29 phys_addr_t *physicalAddress); 30 31 // one of both addresses needs to be provided, the other may be NULL 32 status_t Deallocate(size_t size, 33 void *logicalAddress, 34 phys_addr_t physicalAddress); 35 36 void PrintToStream(); 37 void DumpArrays(); 38 void DumpLastArray(); 39 void DumpFreeSlots(); 40 41 private: 42 char *fName; 43 44 size_t fOverhead; 45 size_t fManagedMemory; 46 status_t fStatus; 47 48 mutex fLock; 49 area_id fArea; 50 void *fLogicalBase; 51 phys_addr_t fPhysicalBase; 52 53 int32 fArrayCount; 54 size_t *fBlockSize; 55 size_t *fArrayLength; 56 size_t *fArrayOffset; 57 uint8 **fArray; 58 59 ConditionVariable fNoMemoryCondition; 60 uint32 fMemoryWaitersCount; 61 62 uint32 fDebugBase; 63 uint32 fDebugChunkSize; 64 uint64 fDebugUseMap; 65 }; 66 67 #endif // !_PHYSICAL_MEMORY_ALLOCATOR_H_ 68