author | Mike Kinghan <mikek@symbian.org> |
Thu, 25 Nov 2010 14:35:45 +0000 | |
branch | GCC_SURGE |
changeset 305 | 1ba12ef4ef89 |
parent 201 | 43365a9b78a3 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
2 |
// All rights reserved. |
|
3 |
// This component and the accompanying materials are made available |
|
4 |
// under the terms of the License "Eclipse Public License v1.0" |
|
5 |
// which accompanies this distribution, and is available |
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 |
// |
|
8 |
// Initial Contributors: |
|
9 |
// Nokia Corporation - initial contribution. |
|
10 |
// |
|
11 |
// Contributors: |
|
12 |
// |
|
13 |
// Description: |
|
14 |
// |
|
15 |
||
16 |
#ifndef MPAGEARRAY_H |
|
17 |
#define MPAGEARRAY_H |
|
18 |
||
19 |
#include "mmu.h" |
|
20 |
||
21 |
const TUint KPageArraySegmentShift = 4; |
|
22 |
||
23 |
/** |
|
24 |
Number of entries in each segment RPageArray::TSegment. |
|
25 |
*/ |
|
26 |
const TUint KPageArraySegmentSize = (1<<KPageArraySegmentShift); |
|
27 |
||
28 |
const TUint KPageArraySegmentMask = KPageArraySegmentSize-1; |
|
29 |
||
30 |
/** |
|
31 |
Bit position in RPageArray::TSegment::iCount for the least significant bit |
|
32 |
of the 'AllocCount'. I.e. the number of entries which are not empty. |
|
33 |
*/ |
|
34 |
const TUint KPageArraySegmentAllocCountShift = 31-KPageArraySegmentShift; |
|
35 |
||
36 |
const TUint KPageArraySegmentLockCountMask = (1<<KPageArraySegmentAllocCountShift)-1; |
|
37 |
||
38 |
/** |
|
39 |
Array which contains the physical addresses of all the pages contained in a DMemoryObject. |
|
40 |
This is a sparse array, therefore memory storage may not exist for unallocated pages entries. |
|
41 |
Where storage does exists for unallocated entries, a state value of ENotPresent indicates this. |
|
42 |
For allocated entries, the redundant least significant bits of each entry contain flags and state |
|
43 |
from from enum TFlags and TState. |
|
44 |
||
45 |
To add pages to the array: |
|
46 |
||
47 |
@code |
|
48 |
RPageArray::TIter iter; |
|
49 |
array.AddStart(index,count,iter); |
|
50 |
RPageArray::TIter pageList; |
|
51 |
while(n = iter.AddFind(pageList)) |
|
52 |
{ |
|
53 |
pageList.Add(n,pages); |
|
54 |
// or pageList.AddContiguous |
|
55 |
} |
|
56 |
array.AddEnd(index,count); |
|
57 |
@endcode |
|
58 |
||
59 |
||
60 |
To remove pages from the array: |
|
61 |
||
62 |
@code |
|
63 |
RPageArray::TIter iter; |
|
64 |
array.FindStart(index,count,iter); |
|
65 |
RPageArray::TIter pageList; |
|
66 |
while(n = iter.RemoveFind(pageList)) |
|
67 |
{ |
|
68 |
pageList.Remove(n,pages); |
|
69 |
iter.FindRelease(n); |
|
70 |
} |
|
71 |
array.FindEnd(index,count); |
|
72 |
@endcode |
|
73 |
||
74 |
Mutual exclusion must be used to ensure that only a single Add or Remove operation is in |
|
75 |
progress at any time. |
|
76 |
||
77 |
||
78 |
To query the contents of the array: |
|
79 |
||
80 |
@code |
|
81 |
RPageArray::TIter iter; |
|
82 |
array.FindStart(index,count,iter); |
|
83 |
RPageArray::TIter pageList; |
|
84 |
while(n=iter.Find(pageList)); |
|
85 |
{ |
|
86 |
TPhysAddr* pages; |
|
87 |
while(n = pageList.Pages(pages,max)) |
|
88 |
{ |
|
89 |
// do something with pages |
|
90 |
pageList.Skip(n); |
|
91 |
} |
|
92 |
iter.FindRelease(n); |
|
93 |
} |
|
94 |
array.FindEnd(index,count); |
|
95 |
@endcode |
|
96 |
||
97 |
*/ |
|
98 |
class RPageArray |
|
99 |
{ |
|
100 |
public: |
|
101 |
class TSegment; |
|
102 |
class TIter; |
|
103 |
||
104 |
/** |
|
105 |
States for pages stored in the array. These are stored in least significant part of each entry. |
|
106 |
*/ |
|
107 |
enum TState |
|
108 |
{ |
|
109 |
ENotPresent = 0x000, ///< No page present. |
|
110 |
EDecommitted = 0x001, ///< Paged Decommitted, but is pinned |
|
111 |
EDecommitting = 0x002, ///< Page is in the process of being decommitted |
|
112 |
EStealing = 0x003, ///< Page is in the process of being stolen |
|
113 |
ERestrictingNA = 0x004, ///< Page is in the process of having no-access restrictions applied |
|
114 |
EMoving = 0x005, ///< Page is in the process of being moved to another physical page |
|
115 |
ECommitted = 0x006, ///< Page is committed |
|
116 |
||
117 |
EStateShift = 3, ///< Number of bits needed to store state values. |
|
118 |
EStateMask = (1<<EStateShift)-1, ///< Mask for state values |
|
119 |
||
120 |
EEmptyEntry = ENotPresent ///< Value of an empty array entry |
|
121 |
}; |
|
122 |
||
123 |
/** |
|
124 |
Flags stored in array entries in addition to the state. |
|
125 |
*/ |
|
126 |
enum TFlags |
|
127 |
{ |
|
128 |
EUnmapVetoed = 1<<EStateShift, ///< A Steal or Decommit operation on the page has been vetoed |
|
129 |
||
130 |
EFlagsShift = 1, ///< Number of bits needed to store flags. |
|
131 |
EFlagsMask = ((1<<EFlagsShift)-1)<<EStateShift ///< Mask for flags values |
|
132 |
}; |
|
133 |
||
134 |
/** |
|
135 |
Return true if the array entry \a aPage is currently being decommitted. |
|
136 |
*/ |
|
137 |
static FORCE_INLINE TBool TargetStateIsDecommitted(TPhysAddr aPage) |
|
138 |
{ |
|
139 |
return State(aPage)<=EStealing; |
|
140 |
} |
|
141 |
||
142 |
/** |
|
143 |
Return true if the array entry \a aPage is currently committed and may be being moved. |
|
144 |
*/ |
|
145 |
static FORCE_INLINE TBool TargetStateIsCommitted(TPhysAddr aPage) |
|
146 |
{ |
|
147 |
__ASSERT_COMPILE(RPageArray::EMoving == RPageArray::ECommitted - 1); |
|
148 |
return State(aPage)>=EMoving; |
|
149 |
} |
|
150 |
||
151 |
/** |
|
152 |
Return true if the array entry \a aPage is not present. |
|
153 |
*/ |
|
154 |
static FORCE_INLINE TBool IsPresent(TPhysAddr aPage) |
|
155 |
{ |
|
156 |
return State(aPage)!=ENotPresent; |
|
157 |
} |
|
158 |
||
159 |
/** |
|
160 |
Return the TState value in the array entry \a aPage. |
|
161 |
*/ |
|
162 |
static FORCE_INLINE TState State(TPhysAddr aPage) |
|
163 |
{ |
|
164 |
return (TState)(aPage&EStateMask); |
|
165 |
} |
|
166 |
||
167 |
/** |
|
168 |
Update the physical address in the array entry \a aEntry. |
|
169 |
@param aEntry A reference to the entry to update. |
|
170 |
@param aPhysAddr The new physical address. |
|
171 |
*/ |
|
172 |
static FORCE_INLINE void PageMoveNewAddr(TPhysAddr& aEntry, TPhysAddr aPhysAddr) |
|
173 |
{ |
|
174 |
__NK_ASSERT_DEBUG(!(aPhysAddr & EStateMask)); |
|
175 |
__NK_ASSERT_DEBUG(State(aEntry) == EMoving); |
|
176 |
aEntry = (aEntry & EStateMask) | aPhysAddr; |
|
177 |
} |
|
178 |
||
179 |
static void Init2A(); |
|
180 |
static void Init2B(DMutex* aLock); |
|
181 |
||
182 |
RPageArray(); |
|
183 |
~RPageArray(); |
|
184 |
||
185 |
/** |
|
186 |
Second stage constructor for the array. |
|
187 |
||
188 |
@param aMaxPages The maximum number of entries to be stored in the array. |
|
189 |
@param aPreallocateMemory If true, then all the memory required to store the array |
|
190 |
entries is allocated immediately - rather than on demand |
|
191 |
as entries are added. |
|
192 |
*/ |
|
193 |
TInt Construct(TUint aMaxPages, TBool aPreallocateMemory=EFalse); |
|
194 |
||
195 |
/** |
|
196 |
Allocate all memory required to store array entries. |
|
197 |
This is only for use during system boot. |
|
198 |
*/ |
|
199 |
TInt PreallocateMemory(); |
|
200 |
||
201 |
/** |
|
202 |
Ensures the memory to store a region of array entries is allocated and locked. |
|
203 |
||
204 |
@param aIndex Start index of region. |
|
205 |
@param aCount Number of pages in region. |
|
206 |
||
207 |
@see RPageArray::Free() |
|
208 |
*/ |
|
209 |
TInt Alloc(TUint aIndex, TUint aCount); |
|
210 |
||
211 |
/** |
|
212 |
Revert the action of #Alloc by unlocking the memory used for a region of array entries. |
|
213 |
Note, calling #Free for any entry more times than #Alloc was used will have |
|
214 |
unpredictable results. |
|
215 |
||
216 |
@param aIndex Start index of region. |
|
217 |
@param aCount Number of pages in region. |
|
218 |
*/ |
|
219 |
void Free(TUint aIndex, TUint aCount); |
|
220 |
||
221 |
/** |
|
222 |
Prepare to add (commit) pages to a region in this array. |
|
223 |
This ensures the memory to store the entries is allocated and locked. It also, |
|
224 |
optionally and by default, check that these entries are empty. |
|
225 |
||
226 |
@param aIndex Start index of region. |
|
227 |
@param aCount Number of pages in region. |
|
228 |
@param[out] aIter An iterator which covers the specified region. |
|
229 |
@param aAllowExisting True if the region may contain non-empty entries. |
|
230 |
False to assert entries are empty. |
|
231 |
||
232 |
@see RPageArray::AddEnd() |
|
233 |
*/ |
|
234 |
TInt AddStart(TUint aIndex, TUint aCount, TIter& aIter, TBool aAllowExisting=EFalse); |
|
235 |
||
236 |
/** |
|
237 |
End an 'add' operation started with #AddStart. |
|
238 |
This must be called to unlock any page array memory which #AddStart locked. |
|
239 |
||
240 |
@param aIndex Start index of region. Must be same value as corresponding call to #AddStart. |
|
241 |
@param aCount Number of pages in region. Must be same value as corresponding call to #AddStart. |
|
242 |
*/ |
|
243 |
void AddEnd(TUint aIndex, TUint aCount); |
|
244 |
||
245 |
/** |
|
246 |
Prepare to search a region in this array. |
|
247 |
||
248 |
@param aIndex Start index of region. |
|
249 |
@param aCount Number of pages in region. |
|
250 |
@param[out] aIter An iterator which covers the specified region. |
|
251 |
||
252 |
@see RPageArray::AddEnd() |
|
253 |
*/ |
|
254 |
void FindStart(TUint aIndex, TUint aCount, TIter& aIter); |
|
255 |
||
256 |
/** |
|
257 |
End a find operation started with #FindStart. |
|
258 |
||
259 |
@param aIndex Start index of region. Must be same value as corresponding call to #FindStart. |
|
260 |
@param aCount Number of pages in region. Must be same value as corresponding call to #FindStart. |
|
261 |
*/ |
|
262 |
void FindEnd(TUint aIndex, TUint aCount); |
|
263 |
||
264 |
/** |
|
265 |
Prepare to add (commit) a single page to this array. |
|
266 |
This ensures the memory to store the entry is allocated and locked. |
|
267 |
||
268 |
@param aIndex Index of entry. |
|
269 |
@param[out] aPageList An iterator represents the single array entry. |
|
270 |
||
271 |
@return Pointer to the array entry, |
|
272 |
or the null pointer if memory allocation failed. |
|
273 |
||
274 |
@see RPageArray::AddPage() |
|
275 |
@see RPageArray::AddPageEnd() |
|
276 |
*/ |
|
277 |
TPhysAddr* AddPageStart(TUint aIndex, TIter& aPageList); |
|
278 |
||
279 |
/** |
|
280 |
Add (commit) a single page to the array. |
|
281 |
||
282 |
@param aPageEntry The address of the array entry as returned by AddPageStart. |
|
283 |
@param aPage The physical address of the page being added. |
|
284 |
*/ |
|
285 |
static void AddPage(TPhysAddr* aPageEntry, TPhysAddr aPage); |
|
286 |
||
287 |
/** |
|
288 |
End an 'add' operation started with #AddPageStart. |
|
289 |
This must be called to unlock any page array memory which #AddPageStart locked. |
|
290 |
||
291 |
@param aIndex Index of entry. Must be same value as corresponding call to #AddPageStart. |
|
292 |
@param aDelta 1 (one), if the array entry was changed from ENotPresent state (e.g. AddPage called), |
|
293 |
zero otherwise. |
|
294 |
*/ |
|
295 |
void AddPageEnd(TUint aIndex, TInt aDelta); |
|
296 |
||
297 |
/** |
|
298 |
Prepare to remove (decommit) a single page from this array. |
|
299 |
||
300 |
This function is similar to TIter::RemoveFind and updates the array entry and |
|
301 |
memory locking in the same way. |
|
302 |
||
303 |
@param aIndex Index of entry. |
|
304 |
@param[out] aPageList An iterator representing the single array entry. |
|
305 |
Not set if this method returns the null pointer. |
|
306 |
||
307 |
@return Pointer to the array entry, |
|
308 |
or the null pointer if entry does not need decommitting. |
|
309 |
||
310 |
@see RPageArray::RemovePage() |
|
311 |
@see RPageArray::RemovePageEnd() |
|
312 |
*/ |
|
313 |
TPhysAddr* RemovePageStart(TUint aIndex, TIter& aPageList); |
|
314 |
||
315 |
/** |
|
316 |
Remove a single page from the array. |
|
317 |
||
318 |
This function is similar to TIter::Remove and updates the array entry in the same way. |
|
319 |
||
320 |
@param aPageEntry The address of the array entry as returned by RemovePageStart. |
|
321 |
||
322 |
@return The physical address of the page which was removed, |
|
323 |
or KPhysAddrInvalid if no page was removed. |
|
324 |
*/ |
|
325 |
static TPhysAddr RemovePage(TPhysAddr* aPageEntry); |
|
326 |
||
327 |
/** |
|
328 |
End an 'remove' operation started with #RemovePageStart. |
|
329 |
This must be called to unlock any page array memory which #RemovePageStart locked. |
|
330 |
||
331 |
@param aIndex Index of entry. Must be same value as corresponding call to #RemovePageStart. |
|
332 |
@param aDelta 1 (one), if the array entry was set ENotPresent state (RemovePage succeeded), |
|
333 |
zero otherwise. |
|
334 |
*/ |
|
335 |
void RemovePageEnd(TUint aIndex, TInt aDelta); |
|
336 |
||
337 |
/** |
|
338 |
Prepare to restrict access to a single page in this array. |
|
339 |
||
340 |
If the page entry state indicates that the page is already more restricted |
|
341 |
than being requested, then the function returns the null pointer and does nothing. |
|
342 |
||
343 |
If the page does need its access restricting then its entry in the array is set to |
|
344 |
ERestrictingNA and the memory for the entry is locked. |
|
345 |
||
346 |
@param aIndex Index of entry. |
|
347 |
@param[out] aPageList An iterator representing the single array entry. |
|
348 |
Not set if this method returns the null pointer. |
|
349 |
||
350 |
@return Pointer to the array entry, |
|
351 |
or the null pointer if entry does not need it's access restricting further. |
|
352 |
||
353 |
@see RPageArray::RestrictPageNAEnd() |
|
354 |
*/ |
|
355 |
TPhysAddr* RestrictPageNAStart(TUint aIndex, TIter& aPageList); |
|
356 |
||
357 |
/** |
|
358 |
End an 'restrict' operation started with #RestrictPageStart. |
|
359 |
This must be called to unlock any page array memory which #RestrictPageStart locked. |
|
360 |
||
361 |
@param aIndex Index of entry. Must be same value as corresponding call to #RestrictPageStart. |
|
362 |
*/ |
|
363 |
void RestrictPageNAEnd(TUint aIndex); |
|
364 |
||
365 |
/** |
|
366 |
Prepare to steal a single page from this array. |
|
367 |
||
368 |
The memory for the entry is locked and if the page entry is is in one of the committed |
|
369 |
states then it is changed to state EStealing. |
|
370 |
||
371 |
@param aIndex Index of entry. |
|
372 |
@param[out] aPageList An iterator representing the single array entry. |
|
373 |
Not set if this method returns the null pointer. |
|
374 |
||
375 |
@return Pointer to the array entry. |
|
376 |
||
377 |
@see RPageArray::StealPageEnd() |
|
378 |
*/ |
|
379 |
TPhysAddr* StealPageStart(TUint aIndex, TIter& aPageList); |
|
380 |
||
381 |
/** |
|
382 |
End an 'steal' operation started with #StealPageStart. |
|
383 |
This must be called to unlock any page array memory which #StealPageStart locked. |
|
384 |
||
385 |
@param aIndex Index of entry. Must be same value as corresponding call to #StealPageStart. |
|
386 |
@param aDelta 1 (one), if the array entry was set ENotPresent state (the page was stolen), |
|
387 |
zero otherwise. |
|
388 |
*/ |
|
389 |
void StealPageEnd(TUint aIndex, TInt aDelta); |
|
390 |
||
391 |
/** |
|
392 |
Prepare to move a page in this array by changing its state to EMoving. |
|
393 |
||
394 |
Note - the memory entry isn't locked as the RamAllocLock mutex must be held |
|
395 |
through out the page moving process and therefore the page cannot be removed. |
|
396 |
||
397 |
@param aIndex The index of the entry to be moved. |
|
398 |
@param[out] aPageList An iterator representing the single array entry. |
|
399 |
Not set if this method returns the null pointer. |
|
400 |
||
401 |
@return Pointer to the array entry, NULL if the page cannot be moved. |
|
402 |
||
403 |
@see RPageArray::MovePageEnd() |
|
404 |
*/ |
|
405 |
TPhysAddr* MovePageStart(TUint aIndex, TIter& aPageList); |
|
406 |
||
201
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
102
diff
changeset
|
407 |
|
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
102
diff
changeset
|
408 |
/** |
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
102
diff
changeset
|
409 |
Page moving has ended so set the page back to committed if no other |
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
102
diff
changeset
|
410 |
operation has occurred/is occurring. |
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
102
diff
changeset
|
411 |
|
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
102
diff
changeset
|
412 |
@param aEntry A reference to the entry to update. |
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
102
diff
changeset
|
413 |
@param aIndex The index of the page that was moved. |
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
102
diff
changeset
|
414 |
*/ |
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
102
diff
changeset
|
415 |
void MovePageEnd(TPhysAddr& aEntry, TUint aIndex); |
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
102
diff
changeset
|
416 |
|
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
102
diff
changeset
|
417 |
|
0 | 418 |
/** |
419 |
Return the array entry for index \a aIndex. |
|
420 |
*/ |
|
421 |
TPhysAddr Page(TUint aIndex); |
|
422 |
||
423 |
||
424 |
/** |
|
425 |
Return a pointer to the array entry for index \a aIndex. |
|
426 |
||
427 |
@return Pointer to the array entry, NULL if the page cannot found. |
|
428 |
*/ |
|
429 |
TPhysAddr* PageEntry(TUint aIndex); |
|
430 |
||
431 |
/** |
|
432 |
Return the physical address of the page at index \a aIndex, or KPhysAddrInvalid if none present. |
|
433 |
*/ |
|
434 |
TPhysAddr PhysAddr(TUint aIndex); |
|
435 |
||
436 |
/** |
|
437 |
Get the physical address for the pages stored in the specified region in the array. |
|
438 |
||
439 |
@param aIndex Start index of region. |
|
440 |
@param aCount Number of pages in region. |
|
441 |
@param[out] aPhysicalAddress If all pages are physically contiguous this is set to the start address, |
|
442 |
otherwise this is set to KPhysAddrInvalid. |
|
443 |
@param[out] aPhysicalPageList Pointer to array of \a aCount physical addresses which |
|
444 |
will be filled with the physical addressed of each page in the region. |
|
445 |
||
446 |
@return 0 (zero) if all pages in region are physically contiguous; |
|
447 |
1 (one) if pages are not physically contiguous; |
|
448 |
KErrNotFound, if any page in the region is not present. |
|
449 |
*/ |
|
450 |
TInt PhysAddr(TUint aIndex, TUint aCount, TPhysAddr& aPhysicalAddress, TPhysAddr* aPhysicalPageList); |
|
451 |
||
452 |
enum |
|
453 |
{ |
|
454 |
/** |
|
455 |
Maximum number of bits which can be stored in an array entry by SetPagingManagerData. |
|
456 |
*/ |
|
457 |
KPagingManagerDataBits = 32-(EFlagsShift+EStateShift), |
|
458 |
}; |
|
459 |
||
460 |
enum |
|
461 |
{ |
|
462 |
/** |
|
463 |
Maximum value which can be stored in an array entry by SetPagingManagerData. |
|
464 |
*/ |
|
465 |
KMaxPagingManagerData = (1u<<KPagingManagerDataBits)-1u |
|
466 |
}; |
|
467 |
||
468 |
/** |
|
469 |
Write \a aValue to the paging manager data for index \a aIndex. |
|
470 |
The value must not exceed KMaxPagingManagerData. |
|
471 |
||
472 |
This value is stored in the page array entry, if it's state is ENotPresent; |
|
473 |
otherwise it is stored in the SPageInfo object for the page in the array entry. |
|
474 |
*/ |
|
475 |
void SetPagingManagerData(TUint aIndex, TUint aValue); |
|
476 |
||
477 |
/** |
|
478 |
Return the paging manager data for index \a aIndex. |
|
479 |
@see RPageArray::SetPagingManagerData() |
|
480 |
*/ |
|
481 |
TUint PagingManagerData(TUint aIndex); |
|
482 |
||
483 |
||
484 |
private: |
|
485 |
/** |
|
486 |
Unlock the memory used for a region of array entries. |
|
487 |
||
488 |
@param aSegments Copy of RPageArray::iSegments from the array. |
|
489 |
@param aIndex Start index of region. |
|
490 |
@param aCount Number of pages in region. |
|
491 |
*/ |
|
492 |
static void Release(TSegment** aSegments, TUint aIndex, TUint aCount); |
|
493 |
||
494 |
/** |
|
495 |
Unlocking the memory used for a single array entry. |
|
496 |
This also updates |
|
497 |
||
498 |
@param aIndex The index of the array entry. |
|
499 |
@param aDelta The change in the 'present' state for the entry. This is |
|
500 |
1 if the entry was added (state changed from ENotPresent), |
|
501 |
-1 if the entry was removed (state changed to ENotPresent), |
|
502 |
0 otherwise. |
|
503 |
*/ |
|
504 |
void ReleasePage(TUint aIndex, TInt aDelta); |
|
505 |
||
506 |
/** |
|
507 |
Return the array segment in at \a aSegmentEntry, allocating a new one to this if |
|
508 |
none previously existed. Return the null pointer in no segment could be allocated |
|
509 |
(out of memory). |
|
510 |
||
511 |
The returned segment is locked (TSegment::Lock) \a aLockCount times; this normally |
|
512 |
represents the number of entries in the segment which are to be accesses. |
|
513 |
*/ |
|
514 |
TSegment* GetOrAllocateSegment(TSegment** aSegmentEntry, TUint aLockCount); |
|
515 |
private: |
|
516 |
TUint8 iPreallocatedMemory; ///< Set true, if this array was constructed with pre-allocated memory. See #Construct. |
|
517 |
TUint iNumSegments; ///< The number of segments in array iSegments. |
|
518 |
TSegment** iSegments; ///< Array of TSegment objects allocated for this array. May contain null pointers. |
|
519 |
||
520 |
public: |
|
521 |
/** |
|
522 |
Class for iterating through and manipulating a section of entries in an RPageArray. |
|
523 |
*/ |
|
524 |
class TIter |
|
525 |
{ |
|
526 |
public: |
|
527 |
/** |
|
528 |
Find the next region of empty entries. |
|
529 |
||
530 |
@param[out] aPageList The found region. |
|
531 |
The #Add or #AddContiguous method is normally subsequently used on this. |
|
532 |
||
533 |
@return The number of pages in the found region. Zero indicating no more empty entries were found. |
|
534 |
||
535 |
@post This iterator is updated start immediately after the found region returned in \a aPageList. |
|
536 |
*/ |
|
537 |
TUint AddFind(TIter& aPageList); |
|
538 |
||
539 |
/** |
|
540 |
Add pages to the array, setting each entry state as ECommitted. |
|
541 |
||
542 |
@param aCount The number of pages to add. |
|
543 |
@param aPages Pointer to list of \a aCount physical page addresses to add. |
|
544 |
*/ |
|
102
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
545 |
void Add(TUint aCount, const TPhysAddr* aPages); |
0 | 546 |
|
547 |
/** |
|
548 |
Add contiguous pages to the array, setting each entry state as ECommitted. |
|
549 |
||
550 |
@param aCount The number of pages to add. |
|
551 |
@param aPhysAddr The physical address of the first page to add. |
|
552 |
*/ |
|
553 |
void AddContiguous(TUint aCount, TPhysAddr aPhysAddr); |
|
554 |
||
555 |
/** |
|
556 |
Update iterator and array state as if pages had been added with #Add. |
|
557 |
This is used after array entries have been directly manipulated rather |
|
558 |
than being updated through #Add. |
|
559 |
||
560 |
@param aCount The number of pages to move this iterator on by. |
|
561 |
@param aChanged The number of new entries which have been added to the array. |
|
562 |
*/ |
|
563 |
void Added(TUint aCount, TUint aChanged); |
|
564 |
||
565 |
/** |
|
566 |
Find the next region of non-empty entries and lock the memory used to store these. |
|
567 |
||
568 |
@param[out] aPageList The found region. |
|
569 |
The #Pages method is normally subsequently used on this. |
|
570 |
||
571 |
@return The number of pages in the found region. Zero indicating no more empty entries were found. |
|
572 |
||
573 |
@post This iterator is updated to start at the first found entry. |
|
574 |
||
575 |
@see RPageArray::FindRelease() |
|
576 |
*/ |
|
577 |
TUint Find(TIter& aPageList); |
|
578 |
||
579 |
/** |
|
580 |
Unlock the page array memory locked by #Find or #RemoveFind and move this iterator |
|
581 |
past this region in preparation for a subsequent find operation. |
|
582 |
||
583 |
@param aCount The number of pages returned by the corresponding find function. |
|
584 |
||
585 |
@post This iterator is updated to start immediately after the region |
|
586 |
returned by the corresponding find function. |
|
587 |
*/ |
|
588 |
void FindRelease(TUint aCount); |
|
589 |
||
590 |
/** |
|
591 |
Find the next region of entries to be removed (decommitted). |
|
592 |
The entries found are those which are neither empty nor in state EDecommitted. |
|
593 |
They are updated to state EDecommitting and the memory used to store these entries |
|
594 |
is locked. To unlock the memory and continue searching FindRelease |
|
595 |
||
596 |
@param[out] aPageList The found region. |
|
597 |
The #Remove method is normally subsequently used on this. |
|
598 |
||
599 |
@return The number of pages in the found region. Zero indicating no more empty entries were found. |
|
600 |
||
601 |
@post This iterator is updated to start at the first found entry. |
|
602 |
||
603 |
@see RPageArray::FindRelease() |
|
604 |
@see RPageArray::Remove() |
|
605 |
*/ |
|
606 |
TUint RemoveFind(TIter& aPageList); |
|
607 |
||
608 |
/** |
|
609 |
Remove pages from the array. |
|
610 |
||
611 |
For each entry found to be in the EDecommitting state (as set by #RemoveFind) |
|
612 |
the page address in the entry is appended to the supplied array (\a aPages) and |
|
613 |
the entry set to EEmptyEntry. However, if the array entry has the EUnmapVetoed flag set |
|
614 |
then instead the entry state is set to EDecommitted and the page address is not appended |
|
615 |
to \a aPages. |
|
616 |
||
617 |
@param aMaxCount The maximum number of pages to remove. |
|
618 |
@param[out] aPages Pointer to array of \a aMaxCount physical addresses which |
|
619 |
will be set to the physical addresses of the pages removed. |
|
620 |
||
621 |
@return The number of pages removed from the array and stored at \a aPages. |
|
622 |
||
623 |
@post This iterator is updated start immediately after the last removed entry. |
|
624 |
*/ |
|
625 |
TUint Remove(TUint aMaxCount, TPhysAddr* aPages); |
|
626 |
||
627 |
/** |
|
628 |
Return a pointer to the array entries represented by this iterator. |
|
629 |
||
630 |
As array entries may not be stored contiguously in memory this method returns the |
|
631 |
number of valid entries. |
|
632 |
||
633 |
This method should only be used for array entries which have had their |
|
634 |
memory locked or for which there are other guarantees that the memory is present. |
|
635 |
||
636 |
@param[out] aStart Set to the address of the first array entry. |
|
637 |
@param aMaxCount The maximum count this function should return. |
|
638 |
||
639 |
@return The number of array entries starting at \a aStart which are valid. |
|
640 |
*/ |
|
641 |
TUint Pages(TPhysAddr*& aStart, TUint aMaxCount=~0u); |
|
642 |
||
643 |
/** |
|
644 |
Move this iterator on by \a aCount pages. |
|
645 |
*/ |
|
646 |
void Skip(TUint aCount); |
|
647 |
||
648 |
/** |
|
649 |
Prevent pages in the region covered by this iterator from having their |
|
650 |
access restricted. This is achieved by returning any entries currently |
|
651 |
in the specified 'being restricted' state to be fully committed again (state ECommitted). |
|
652 |
||
653 |
@param aPageMoving ETrue to veto pages being restricted for page moving (EMoving). Set to EFalse otherwise. |
|
654 |
*/ |
|
655 |
void VetoRestrict(TBool aPageMoving); |
|
656 |
||
657 |
/** |
|
658 |
Prevent pages in the region covered by this iterator from being removed from the array. |
|
659 |
This is achieved by setting the EUnmapVetoed flag for all entries with a current state |
|
660 |
indicating they are being decommitted, c.f. TargetStateIsDecommitted. |
|
661 |
*/ |
|
662 |
void VetoUnmap(); |
|
663 |
||
664 |
/** |
|
665 |
Default constructor which does not initialise members. |
|
666 |
*/ |
|
667 |
TIter(); |
|
668 |
||
669 |
/** |
|
670 |
Return a new iterator which represents the array region [aIndex..aEndIndex). |
|
671 |
The new region is asserted to be within that specified by this iterator. |
|
672 |
*/ |
|
673 |
TIter Slice(TUint aIndex, TUint aEndIndex); |
|
674 |
||
675 |
/** |
|
676 |
Return a new iterator which represents the first \a aCount pages of this one. |
|
677 |
*/ |
|
678 |
TIter Left(TUint aCount); |
|
679 |
||
680 |
/** |
|
681 |
Return the start index of the region being represented by this iterator. |
|
682 |
*/ |
|
683 |
FORCE_INLINE TUint Index() const |
|
684 |
{ return iIndex; } |
|
685 |
||
686 |
/** |
|
687 |
Return the index immediately after the being represented by this iterator. |
|
688 |
*/ |
|
689 |
FORCE_INLINE TUint IndexEnd() const |
|
690 |
{ return iEndIndex; } |
|
691 |
||
692 |
/** |
|
693 |
Return the number of entries in the region represented by this iterator. |
|
694 |
*/ |
|
695 |
FORCE_INLINE TUint Count() const |
|
696 |
{ return iEndIndex-iIndex; } |
|
697 |
||
698 |
private: |
|
699 |
TIter(TSegment** aSegments, TUint aIndex, TUint aEndIndex); |
|
700 |
void Set(TSegment** aSegments, TUint aIndex, TUint aEndIndex); |
|
701 |
private: |
|
702 |
TSegment** iSegments; ///< Copy of RPageArray::iSegments of the array being represented by this iterator. |
|
703 |
TUint iIndex; ///< Start index of the array region being represented by this iterator. |
|
704 |
TUint iEndIndex; ///< The index immediately after the array region being represented by this iterator. |
|
705 |
||
706 |
friend class RPageArray; |
|
707 |
}; |
|
708 |
||
709 |
/** |
|
710 |
Class representing the memory storage for a 'segment' of entries in an RPageArray. |
|
711 |
Each segment contains storage for #KPageArraySegmentSize entries and the number |
|
712 |
of these which are not #EEmptyEntry are counted by the 'alloc count'. |
|
713 |
Each segment also has a 'lock count' which acts as a reference count preventing |
|
714 |
the segment from being deleted whilst it is being manipulated. |
|
715 |
Both of these counts are combined in #iCounts. |
|
716 |
*/ |
|
717 |
class TSegment |
|
718 |
{ |
|
719 |
private: |
|
720 |
/** |
|
721 |
Return a newly allocated segment or the null pointer if out-ot-memory. |
|
722 |
*/ |
|
723 |
static TSegment* New(); |
|
724 |
||
725 |
/** |
|
726 |
Delete \a aSegment and return the null pointer. |
|
727 |
*/ |
|
728 |
static TSegment* Delete(TSegment* aSegment); |
|
729 |
||
730 |
/** |
|
731 |
Lock this segment \a aCount times. This prevents the segment being deleted. |
|
732 |
*/ |
|
733 |
void Lock(TUint aCount=1); |
|
734 |
||
735 |
/** |
|
736 |
Unlock \a aSegment \a aCount times. |
|
737 |
If the lock count reaches zero and the segment has no allocated entries |
|
738 |
then it is deleted and \a aSegment set to the null pointer. |
|
739 |
*/ |
|
740 |
static TBool Unlock(TSegment*& aSegment, TUint aCount=1); |
|
741 |
||
742 |
/** |
|
743 |
Adjust the allocation count for this segment by \a aDelta. |
|
744 |
The allocation count keeps count of the number of entries which are not #EEmptyEntry. |
|
745 |
*/ |
|
746 |
void AdjustAllocCount(TInt aDelta); |
|
747 |
||
748 |
/** |
|
749 |
Debug function which outputs the contents of this segment to the kernel debug port. |
|
750 |
*/ |
|
751 |
void Dump(); |
|
752 |
private: |
|
753 |
/** |
|
754 |
Storage for each array entry. |
|
755 |
*/ |
|
756 |
TPhysAddr iPages[KPageArraySegmentSize]; |
|
757 |
||
758 |
/** |
|
759 |
Two count values are stored in this member. |
|
760 |
Bits 0..KPageArraySegmentAllocCountShift-1 is the 'lock count' modified by the |
|
761 |
Lock and Unlock methods. |
|
762 |
Bits KPageArraySegmentAllocCountShift..31 is the 'alloc count' modified by the |
|
763 |
AdjustAllocCount method. |
|
764 |
When both counts are zero, this segment is empty and not being used, |
|
765 |
and can therefore be deleted. |
|
766 |
Note, the alloc count is only valid when the lock count is zero, i.e. |
|
767 |
after all users have finished updating this segment. |
|
768 |
*/ |
|
769 |
TUint iCounts; |
|
770 |
||
771 |
friend class RPageArray; |
|
772 |
friend class TIter; |
|
773 |
}; |
|
774 |
||
775 |
friend class RPageArray::TSegment; |
|
776 |
friend class RPageArray::TIter; |
|
777 |
}; |
|
778 |
||
779 |
||
780 |
||
781 |
// |
|
782 |
// RPageArray::TIter |
|
783 |
// |
|
784 |
||
785 |
FORCE_INLINE RPageArray::TIter::TIter() |
|
786 |
{ |
|
787 |
#ifdef _DEBUG |
|
788 |
iSegments = 0; |
|
789 |
iIndex = 0; |
|
790 |
iEndIndex = ~0u; |
|
791 |
#endif |
|
792 |
} |
|
793 |
||
794 |
FORCE_INLINE RPageArray::TIter::TIter(RPageArray::TSegment** aSegments, TUint aIndex, TUint aEndIndex) |
|
795 |
: iSegments(aSegments), iIndex(aIndex), iEndIndex(aEndIndex) |
|
796 |
{ |
|
797 |
__NK_ASSERT_DEBUG(iEndIndex>=aIndex); |
|
798 |
} |
|
799 |
||
800 |
FORCE_INLINE RPageArray::TIter RPageArray::TIter::Slice(TUint aIndex, TUint aEndIndex) |
|
801 |
{ |
|
802 |
__NK_ASSERT_DEBUG(aEndIndex>=aIndex); |
|
803 |
__NK_ASSERT_DEBUG(aIndex>=iIndex); |
|
804 |
__NK_ASSERT_DEBUG(aEndIndex<=iEndIndex); |
|
805 |
return TIter(iSegments,aIndex,aEndIndex); |
|
806 |
} |
|
807 |
||
808 |
FORCE_INLINE RPageArray::TIter RPageArray::TIter::Left(TUint aCount) |
|
809 |
{ |
|
810 |
__NK_ASSERT_DEBUG(aCount<=Count()); |
|
811 |
return TIter(iSegments,iIndex,iIndex+aCount); |
|
812 |
} |
|
813 |
||
814 |
FORCE_INLINE void RPageArray::TIter::Skip(TUint aCount) |
|
815 |
{ |
|
816 |
__NK_ASSERT_DEBUG(iIndex+aCount>=iIndex); |
|
817 |
__NK_ASSERT_DEBUG(iIndex+aCount<=iEndIndex); |
|
818 |
iIndex += aCount; |
|
819 |
} |
|
820 |
||
821 |
||
822 |
// |
|
823 |
// RPageArray |
|
824 |
// |
|
825 |
||
826 |
FORCE_INLINE void RPageArray::FindEnd(TUint /*aIndex*/, TUint /*aCount*/) |
|
827 |
{ |
|
828 |
// nothing to do |
|
829 |
} |
|
830 |
||
831 |
FORCE_INLINE void RPageArray::AddPageEnd(TUint aIndex, TInt aDelta) |
|
832 |
{ |
|
833 |
MmuLock::Lock(); |
|
834 |
ReleasePage(aIndex,aDelta); |
|
835 |
MmuLock::Unlock(); |
|
836 |
} |
|
837 |
||
838 |
FORCE_INLINE void RPageArray::AddPage(TPhysAddr* aPageEntry, TPhysAddr aPage) |
|
839 |
{ |
|
840 |
__NK_ASSERT_DEBUG(MmuLock::IsHeld()); |
|
841 |
__NK_ASSERT_DEBUG((aPage&KPageMask)==0); |
|
842 |
__NK_ASSERT_DEBUG(!RPageArray::IsPresent(*aPageEntry)); |
|
843 |
*aPageEntry = aPage|RPageArray::ECommitted; |
|
844 |
} |
|
845 |
||
846 |
FORCE_INLINE void RPageArray::RestrictPageNAEnd(TUint aIndex) |
|
847 |
{ |
|
848 |
ReleasePage(aIndex,0); |
|
849 |
} |
|
850 |
||
851 |
FORCE_INLINE void RPageArray::StealPageEnd(TUint aIndex, TInt aDelta) |
|
852 |
{ |
|
853 |
ReleasePage(aIndex,-aDelta); |
|
854 |
} |
|
855 |
||
856 |
FORCE_INLINE void RPageArray::RemovePageEnd(TUint aIndex, TInt aDelta) |
|
857 |
{ |
|
858 |
MmuLock::Lock(); |
|
859 |
ReleasePage(aIndex,-aDelta); |
|
860 |
MmuLock::Unlock(); |
|
861 |
} |
|
862 |
||
201
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
102
diff
changeset
|
863 |
FORCE_INLINE void RPageArray::MovePageEnd(TPhysAddr& aEntry, TUint aIndex) |
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
102
diff
changeset
|
864 |
{ |
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
102
diff
changeset
|
865 |
__NK_ASSERT_DEBUG(PageEntry(aIndex) == &aEntry); |
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
102
diff
changeset
|
866 |
if (State(aEntry) == EMoving) |
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
102
diff
changeset
|
867 |
aEntry = (aEntry & ~EStateMask) | ECommitted; |
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
102
diff
changeset
|
868 |
ReleasePage(aIndex, 0); |
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
102
diff
changeset
|
869 |
} |
43365a9b78a3
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
102
diff
changeset
|
870 |
|
0 | 871 |
#endif |