sl@0
|
1 |
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
/**
|
sl@0
|
17 |
@file
|
sl@0
|
18 |
@internalComponent
|
sl@0
|
19 |
*/
|
sl@0
|
20 |
|
sl@0
|
21 |
#ifndef MVALLOC_H
|
sl@0
|
22 |
#define MVALLOC_H
|
sl@0
|
23 |
|
sl@0
|
24 |
|
sl@0
|
25 |
class RVirtualAllocSlabSet;
|
sl@0
|
26 |
|
sl@0
|
27 |
/**
|
sl@0
|
28 |
Allocator for virtual addresses.
|
sl@0
|
29 |
|
sl@0
|
30 |
The allocator has the concept of addresses having a 'slab type' (#TVirtualSlabType).
|
sl@0
|
31 |
It ensures that addresses of different slab types will not overlap in the same 'chunk'
|
sl@0
|
32 |
(the region covered by a single MMU page table).
|
sl@0
|
33 |
|
sl@0
|
34 |
Addresses will be allocated from lower address regions first, subject to slab type
|
sl@0
|
35 |
and allocation algorithm constraints. See #RBackwardsVirtualAllocator.
|
sl@0
|
36 |
*/
|
sl@0
|
37 |
class RVirtualAllocator
|
sl@0
|
38 |
{
|
sl@0
|
39 |
public:
|
sl@0
|
40 |
RVirtualAllocator();
|
sl@0
|
41 |
~RVirtualAllocator();
|
sl@0
|
42 |
|
sl@0
|
43 |
/**
|
sl@0
|
44 |
Second phase constructor.
|
sl@0
|
45 |
|
sl@0
|
46 |
@param aStart The starting virtual address of the region to be covered
|
sl@0
|
47 |
by this allocator.
|
sl@0
|
48 |
Must be an integer multiple of #KVirtualAllocSlabSize.
|
sl@0
|
49 |
@param aEnd The end virtual address (last valid address plus one) of the region
|
sl@0
|
50 |
to be covered by this allocator.
|
sl@0
|
51 |
Must be an integer multiple of #KVirtualAllocSlabSize.
|
sl@0
|
52 |
@param aNumSlabTypes The number of different 'slab types' to be allocated.
|
sl@0
|
53 |
This will normally be #ENumVirtualAllocTypes.
|
sl@0
|
54 |
@param aWriteLock Reference to the mutex which is being used to protect allocations
|
sl@0
|
55 |
with this object. This is only used for debug checks and may be
|
sl@0
|
56 |
a mutex assigned by #DMutexPool. In practice, this will usually be an
|
sl@0
|
57 |
address space lock DAddressSpace::iLock.
|
sl@0
|
58 |
|
sl@0
|
59 |
@return KErrNone if successful, otherwise one of the system wide error codes.
|
sl@0
|
60 |
*/
|
sl@0
|
61 |
TInt Construct(TLinAddr aStart, TLinAddr aEnd, TUint aNumSlabTypes, DMutex*& aWriteLock);
|
sl@0
|
62 |
|
sl@0
|
63 |
/**
|
sl@0
|
64 |
Allocate a region of virtual addresses.
|
sl@0
|
65 |
|
sl@0
|
66 |
The returned region may have a start address and/or size which is different to
|
sl@0
|
67 |
those requested due to various alignment requirements in the implementation.
|
sl@0
|
68 |
However the returned region will always include all addresses requested.
|
sl@0
|
69 |
|
sl@0
|
70 |
@param[out] aAddr Returns the start address of the region which was allocated.
|
sl@0
|
71 |
@param[out] aSize Returns the size, in bytes, of the region which was allocated.
|
sl@0
|
72 |
This will always be aligned to a multiple of the page colouring
|
sl@0
|
73 |
size: #KPageColourCount*#KPageSize.
|
sl@0
|
74 |
@param aRequestedAddr The requested start address of the region to allocate,
|
sl@0
|
75 |
or zero if no specific address is required.
|
sl@0
|
76 |
@param aRequestedSize The requested size, in bytes, of the region to allocate.
|
sl@0
|
77 |
@param aSlabType The 'slab type' of the address to be allocated.
|
sl@0
|
78 |
Addresses of different slab types will not overlap in the
|
sl@0
|
79 |
same 'chunk' (region covered by a single MMU page table).
|
sl@0
|
80 |
This value must be less than the \a aNumSlabTypes argument
|
sl@0
|
81 |
used in #Construct.
|
sl@0
|
82 |
|
sl@0
|
83 |
@return KErrNone if successful.
|
sl@0
|
84 |
KErrAlreadyExists if a specific address was supplied and this was already
|
sl@0
|
85 |
allocated, or exists in a slab already used for a different slab type.
|
sl@0
|
86 |
Otherwise, one of the system wide error codes.
|
sl@0
|
87 |
|
sl@0
|
88 |
@pre The write lock must be held. (See \a aWriteLock argument for #Construct.)
|
sl@0
|
89 |
*/
|
sl@0
|
90 |
TInt Alloc(TLinAddr& aAddr, TUint& aSize, TLinAddr aRequestedAddr, TUint aRequestedSize, TUint aSlabType);
|
sl@0
|
91 |
|
sl@0
|
92 |
/**
|
sl@0
|
93 |
Free a virtual addresses region which was allocated with #Alloc.
|
sl@0
|
94 |
The region supplied to this function must either be one supplied to a
|
sl@0
|
95 |
previous call to #Alloc or be one returned by that function.
|
sl@0
|
96 |
|
sl@0
|
97 |
@param aAddr Start address of the region to be freed.
|
sl@0
|
98 |
@param aSize Size, in bytes, of the region to be freed.
|
sl@0
|
99 |
|
sl@0
|
100 |
@pre The write lock must be held. (See \a aWriteLock argument for #Construct.)
|
sl@0
|
101 |
*/
|
sl@0
|
102 |
void Free(TLinAddr aAddr, TUint aSize);
|
sl@0
|
103 |
|
sl@0
|
104 |
/**
|
sl@0
|
105 |
Return true if the the address region specified by \a aAddr and \a aSize is
|
sl@0
|
106 |
entirely within the region of addresses covered by this allocator.
|
sl@0
|
107 |
*/
|
sl@0
|
108 |
TBool InRange(TLinAddr aAddr, TUint aSize);
|
sl@0
|
109 |
|
sl@0
|
110 |
/**
|
sl@0
|
111 |
Return true if the the address region specified by \a aAddr and \a aSize was
|
sl@0
|
112 |
allocated by this allocator using the specified \a aSlabType.
|
sl@0
|
113 |
|
sl@0
|
114 |
@pre The write lock must be held. (See \a aWriteLock argument for #Construct.)
|
sl@0
|
115 |
*/
|
sl@0
|
116 |
TBool CheckSlabType(TLinAddr aAddr, TUint aSize, TUint aSlabType);
|
sl@0
|
117 |
|
sl@0
|
118 |
private:
|
sl@0
|
119 |
/**
|
sl@0
|
120 |
If required, expand the region specified by \a aAddr and \a aSize
|
sl@0
|
121 |
to meet size and alignment requirements of the allocator.
|
sl@0
|
122 |
This also returns log2 of the address alignment required.
|
sl@0
|
123 |
*/
|
sl@0
|
124 |
static TUint AdjustRegion(TLinAddr& aAddr, TUint& aSize);
|
sl@0
|
125 |
|
sl@0
|
126 |
protected:
|
sl@0
|
127 |
/**
|
sl@0
|
128 |
The starting virtual address of the region covered by this allocator.
|
sl@0
|
129 |
*/
|
sl@0
|
130 |
TLinAddr iBase;
|
sl@0
|
131 |
|
sl@0
|
132 |
/**
|
sl@0
|
133 |
The size, in bytes, of the virtual address of the region covered by this allocator.
|
sl@0
|
134 |
*/
|
sl@0
|
135 |
TUint iSize;
|
sl@0
|
136 |
|
sl@0
|
137 |
private:
|
sl@0
|
138 |
/**
|
sl@0
|
139 |
Bitmap of used virtual address regions, each a 'slab' size (#KVirtualAllocSlabSize).
|
sl@0
|
140 |
*/
|
sl@0
|
141 |
TBitMapAllocator* iAllocator;
|
sl@0
|
142 |
|
sl@0
|
143 |
/**
|
sl@0
|
144 |
Pointer to allocator object used for sizes less than #KVirtualAllocSlabSize.
|
sl@0
|
145 |
*/
|
sl@0
|
146 |
RVirtualAllocSlabSet* iSlabSet;
|
sl@0
|
147 |
};
|
sl@0
|
148 |
|
sl@0
|
149 |
|
sl@0
|
150 |
inline TBool RVirtualAllocator::InRange(TLinAddr aAddr, TUint aSize)
|
sl@0
|
151 |
{
|
sl@0
|
152 |
aAddr -= iBase;
|
sl@0
|
153 |
return aAddr<iSize && aAddr+aSize>=aAddr && aAddr+aSize<=iSize;
|
sl@0
|
154 |
}
|
sl@0
|
155 |
|
sl@0
|
156 |
|
sl@0
|
157 |
|
sl@0
|
158 |
/**
|
sl@0
|
159 |
Allocator for virtual addresses which is identical to #RVirtualAllocator
|
sl@0
|
160 |
except that addresses will be allocated from higher address regions first.
|
sl@0
|
161 |
(Subject to 'slab type' and allocation algorithm constraints).
|
sl@0
|
162 |
*/
|
sl@0
|
163 |
class RBackwardsVirtualAllocator : public RVirtualAllocator
|
sl@0
|
164 |
{
|
sl@0
|
165 |
public:
|
sl@0
|
166 |
// overriding RVirtualAllocator...
|
sl@0
|
167 |
TInt Alloc(TLinAddr& aAddr, TUint& aSize, TLinAddr aRequestedAddr, TUint aRequestedSize, TUint aSlabType);
|
sl@0
|
168 |
void Free(TLinAddr aAddr, TUint aSize);
|
sl@0
|
169 |
};
|
sl@0
|
170 |
|
sl@0
|
171 |
|
sl@0
|
172 |
/**
|
sl@0
|
173 |
Enumeration of the different virtual address allocation types which may not
|
sl@0
|
174 |
overlap in the same 'chunk' (region covered by a single MMU page table).
|
sl@0
|
175 |
|
sl@0
|
176 |
This includes all #TPdeType values, plus addition address types.
|
sl@0
|
177 |
*/
|
sl@0
|
178 |
enum TVirtualSlabType
|
sl@0
|
179 |
{
|
sl@0
|
180 |
/**
|
sl@0
|
181 |
Bit flag used to distinguish common virtual addresses allocated with
|
sl@0
|
182 |
DAddressSpace::AllocateUserCommonVirtualMemory.
|
sl@0
|
183 |
|
sl@0
|
184 |
It is important that these addresses reside in their own slab type,
|
sl@0
|
185 |
otherwise normal local address allocation would tend to get allocated
|
sl@0
|
186 |
adjacent to them; clogging up the 'common' address region.
|
sl@0
|
187 |
*/
|
sl@0
|
188 |
EVirtualSlabTypeCommonVirtual = ENumPdeTypes<<0,
|
sl@0
|
189 |
|
sl@0
|
190 |
/**
|
sl@0
|
191 |
Bit flag used to distinguish virtual addresses allocated for use in
|
sl@0
|
192 |
mapping demand paged memory.
|
sl@0
|
193 |
|
sl@0
|
194 |
This ensures that page tables used for demand paged memory are not
|
sl@0
|
195 |
used for other memory types and means they may be freed once the
|
sl@0
|
196 |
memory is paged out.
|
sl@0
|
197 |
*/
|
sl@0
|
198 |
EVirtualSlabTypeDemandPaged = ENumPdeTypes<<1,
|
sl@0
|
199 |
|
sl@0
|
200 |
/**
|
sl@0
|
201 |
Total number of different 'kinds' of virtual address which may need to be allocated.
|
sl@0
|
202 |
*/
|
sl@0
|
203 |
ENumVirtualAllocTypes = ENumPdeTypes<<2
|
sl@0
|
204 |
};
|
sl@0
|
205 |
|
sl@0
|
206 |
|
sl@0
|
207 |
#endif
|