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
17class PhysicalMemoryAllocator {
18public:
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
41private:
42		bool						_Lock();
43		void						_Unlock();
44
45		char						*fName;
46
47		size_t						fOverhead;
48		size_t						fManagedMemory;
49		status_t					fStatus;
50
51		mutex						fLock;
52		area_id						fArea;
53		void						*fLogicalBase;
54		phys_addr_t					fPhysicalBase;
55
56		int32						fArrayCount;
57		size_t						*fBlockSize;
58		size_t						*fArrayLength;
59		size_t						*fArrayOffset;
60		uint8						**fArray;
61
62		ConditionVariable			fNoMemoryCondition;
63		uint32						fMemoryWaitersCount;
64
65		uint32						fDebugBase;
66		uint32						fDebugChunkSize;
67		uint64						fDebugUseMap;
68};
69
70#endif // !_PHYSICAL_MEMORY_ALLOCATOR_H_
71