author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Thu, 19 Aug 2010 11:14:22 +0300 | |
branch | RCL_3 |
changeset 42 | a179b74831c9 |
parent 41 | 0ffb4e86fcc9 |
child 43 | c1f20ce4abcf |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 1998-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 |
#include "memmodel.h" |
|
17 |
#include "kernel/cache_maintenance.inl" |
|
18 |
#include <kernel/cache.h> |
|
19 |
#include <ramalloc.h> |
|
20 |
#include <defrag.h> |
|
21 |
#include "mm.h" |
|
22 |
#include "mmu.h" |
|
23 |
#include "mpager.h" |
|
24 |
#include "mmapping.h" |
|
25 |
#include "mobject.h" |
|
26 |
#include "mmanager.h" |
|
27 |
#include "mpagearray.h" |
|
28 |
||
29 |
||
30 |
// |
|
31 |
// SPageInfo |
|
32 |
// |
|
33 |
||
34 |
// check enough space for page infos... |
|
35 |
__ASSERT_COMPILE((KPageInfoLinearEnd-KPageInfoLinearBase)/sizeof(SPageInfo)==(1<<(32-KPageShift))); |
|
36 |
||
37 |
// check KPageInfoShift... |
|
38 |
__ASSERT_COMPILE(sizeof(SPageInfo)==(1<<KPageInfoShift)); |
|
39 |
||
40 |
||
41 |
SPageInfo* SPageInfo::SafeFromPhysAddr(TPhysAddr aAddress) |
|
42 |
{ |
|
43 |
__NK_ASSERT_DEBUG((aAddress&KPageMask)==0); |
|
44 |
TUint index = aAddress>>(KPageShift+KPageShift-KPageInfoShift); |
|
45 |
TUint flags = ((TUint8*)KPageInfoMap)[index>>3]; |
|
46 |
TUint mask = 1<<(index&7); |
|
47 |
if(!(flags&mask)) |
|
48 |
return 0; // no SPageInfo for aAddress |
|
49 |
SPageInfo* info = FromPhysAddr(aAddress); |
|
50 |
if(info->iType==SPageInfo::EInvalid) |
|
51 |
return 0; |
|
52 |
return info; |
|
53 |
} |
|
54 |
||
55 |
||
56 |
#ifdef _DEBUG |
|
57 |
||
58 |
void SPageInfo::CheckAccess(const char* aMessage, TUint aFlags) |
|
59 |
{ |
|
60 |
if(K::Initialising || NKern::Crashed()) |
|
61 |
return; |
|
62 |
||
63 |
if((aFlags&ECheckNotAllocated) && (iType!=EUnknown)) |
|
64 |
{ |
|
65 |
Kern::Printf("SPageInfo[0x%08x]::CheckAccess failed, PhysAddr()=0x%08x, iType==%d : %s",this,PhysAddr(),iType,aMessage); |
|
66 |
__NK_ASSERT_DEBUG(0); |
|
67 |
goto fail; |
|
68 |
} |
|
69 |
||
70 |
if((aFlags&ECheckNotUnused) && (iType==EUnused)) |
|
71 |
{ |
|
72 |
Kern::Printf("SPageInfo[0x%08x]::CheckAccess failed, PhysAddr()=0x%08x, iType==%d : %s",this,PhysAddr(),iType,aMessage); |
|
73 |
__NK_ASSERT_DEBUG(0); |
|
74 |
goto fail; |
|
75 |
} |
|
76 |
||
77 |
if((aFlags&ECheckUnused) && (iType!=EUnused)) |
|
78 |
{ |
|
79 |
Kern::Printf("SPageInfo[0x%08x]::CheckAccess failed, PhysAddr()=0x%08x, iType==%d : %s",this,PhysAddr(),iType,aMessage); |
|
80 |
__NK_ASSERT_DEBUG(0); |
|
81 |
goto fail; |
|
82 |
} |
|
83 |
||
84 |
if((aFlags&ECheckNotPaged) && (iPagedState!=EUnpaged)) |
|
85 |
{ |
|
86 |
Kern::Printf("SPageInfo[0x%08x]::CheckAccess failed, PhysAddr()=0x%08x, iPagedState=%d : %s",this,PhysAddr(),iPagedState,aMessage); |
|
87 |
__NK_ASSERT_DEBUG(0); |
|
88 |
goto fail; |
|
89 |
} |
|
90 |
||
91 |
if((aFlags&ECheckRamAllocLock) && !RamAllocLock::IsHeld()) |
|
92 |
{ |
|
93 |
Kern::Printf("SPageInfo[0x%08x]::CheckAccess failed, PhysAddr()=0x%08x, iType==%d : %s",this,PhysAddr(),iType,aMessage); |
|
94 |
__NK_ASSERT_DEBUG(0); |
|
95 |
goto fail; |
|
96 |
} |
|
97 |
||
98 |
if((aFlags&ENoCheckMmuLock) || MmuLock::IsHeld()) |
|
99 |
return; |
|
100 |
fail: |
|
101 |
Kern::Printf("SPageInfo[0x%08x]::CheckAccess failed, PhysAddr()=0x%08x : %s",this,PhysAddr(),aMessage); |
|
102 |
Mmu::Panic(Mmu::EUnsafePageInfoAccess); |
|
103 |
} |
|
104 |
||
105 |
||
106 |
void SPageInfo::Dump() |
|
107 |
{ |
|
108 |
Kern::Printf("SPageInfo for page %x = %d,%d,%02x,0x%08x,0x%x,%d",PhysAddr(),iType,iPagedState,iFlags,iOwner,iIndex,iPinCount); |
|
109 |
} |
|
110 |
||
111 |
#endif |
|
112 |
||
113 |
||
114 |
||
115 |
// |
|
116 |
// SPageTableInfo |
|
117 |
// |
|
118 |
||
119 |
// check enough space for page table infos... |
|
120 |
__ASSERT_COMPILE((KPageTableInfoEnd-KPageTableInfoBase)/sizeof(SPageTableInfo) |
|
121 |
>=(KPageTableEnd-KPageTableBase)/KPageTableSize); |
|
122 |
||
123 |
// check KPtBlockShift... |
|
124 |
__ASSERT_COMPILE((sizeof(SPageTableInfo)<<KPtBlockShift)==KPageSize); |
|
125 |
||
126 |
||
127 |
#ifdef _DEBUG |
|
128 |
||
129 |
TBool SPageTableInfo::CheckPageCount() |
|
130 |
{ |
|
131 |
__NK_ASSERT_DEBUG(MmuLock::IsHeld()); |
|
132 |
TPte* pt = PageTable(); |
|
133 |
TUint realCount = 0; |
|
134 |
do if(*pt++) ++realCount; |
|
135 |
while(TLinAddr(pt)&(KPageTableMask/sizeof(TPte)*sizeof(TPte))); |
|
136 |
if(iPageCount==realCount) |
|
137 |
return true; |
|
138 |
Kern::Printf("CheckPageCount Failed: pt=0x%08x count=%d realCount=%d",TLinAddr(pt)-KPageTableSize,iPageCount,realCount); |
|
139 |
return false; |
|
140 |
} |
|
141 |
||
142 |
||
143 |
void SPageTableInfo::CheckChangeUse(const char* aName) |
|
144 |
{ |
|
145 |
if(K::Initialising) |
|
146 |
return; |
|
147 |
if(PageTablesLockIsHeld() && MmuLock::IsHeld()) |
|
148 |
return; |
|
149 |
Kern::Printf("SPageTableInfo::CheckChangeUse failed : %s",aName); |
|
150 |
Mmu::Panic(Mmu::EUnsafePageTableInfoAccess); |
|
151 |
} |
|
152 |
||
153 |
||
154 |
void SPageTableInfo::CheckCheckUse(const char* aName) |
|
155 |
{ |
|
156 |
if(K::Initialising) |
|
157 |
return; |
|
158 |
if(PageTablesLockIsHeld() || MmuLock::IsHeld()) |
|
159 |
return; |
|
160 |
Kern::Printf("SPageTableInfo::CheckCheckUse failed : %s",aName); |
|
161 |
Mmu::Panic(Mmu::EUnsafePageTableInfoAccess); |
|
162 |
} |
|
163 |
||
164 |
||
165 |
void SPageTableInfo::CheckAccess(const char* aName) |
|
166 |
{ |
|
167 |
if(K::Initialising) |
|
168 |
return; |
|
169 |
if(MmuLock::IsHeld()) |
|
170 |
return; |
|
171 |
Kern::Printf("SPageTableInfo::CheckAccess failed : %s",aName); |
|
172 |
Mmu::Panic(Mmu::EUnsafePageTableInfoAccess); |
|
173 |
} |
|
174 |
||
175 |
||
176 |
void SPageTableInfo::CheckInit(const char* aName) |
|
177 |
{ |
|
178 |
if(K::Initialising) |
|
179 |
return; |
|
180 |
if(PageTablesLockIsHeld() && iType==EUnused) |
|
181 |
return; |
|
182 |
Kern::Printf("SPageTableInfo::CheckInit failed : %s",aName); |
|
183 |
Mmu::Panic(Mmu::EUnsafePageTableInfoAccess); |
|
184 |
} |
|
185 |
||
186 |
#endif |
|
187 |
||
188 |
||
189 |
||
190 |
// |
|
191 |
// RamAllocLock |
|
192 |
// |
|
193 |
||
194 |
_LIT(KLitRamAlloc,"RamAlloc"); |
|
195 |
_LIT(KLitPhysMemSync,"PhysMemSync"); |
|
196 |
||
197 |
void RamAllocLock::Lock() |
|
198 |
{ |
|
199 |
Mmu& m = TheMmu; |
|
200 |
Kern::MutexWait(*m.iRamAllocatorMutex); |
|
201 |
if(!m.iRamAllocLockCount++) |
|
202 |
{ |
|
203 |
// first lock, so setup memory fail data... |
|
204 |
m.iRamAllocFailed = EFalse; |
|
205 |
__NK_ASSERT_DEBUG(m.iRamAllocInitialFreePages==m.FreeRamInPages()); // free RAM shouldn't have changed whilst lock was held |
|
206 |
} |
|
207 |
} |
|
208 |
||
209 |
||
210 |
void RamAllocLock::Unlock() |
|
211 |
{ |
|
212 |
Mmu& m = TheMmu; |
|
213 |
if(--m.iRamAllocLockCount) |
|
214 |
{ |
|
215 |
Kern::MutexSignal(*m.iRamAllocatorMutex); |
|
216 |
return; |
|
217 |
} |
|
218 |
TBool failed = m.iRamAllocFailed; |
|
219 |
TUint initial = m.iRamAllocInitialFreePages; |
|
220 |
TUint final = m.FreeRamInPages(); |
|
221 |
m.iRamAllocInitialFreePages = final; // new baseline value |
|
222 |
TUint changes = K::CheckFreeMemoryLevel(initial*KPageSize,final*KPageSize,failed); |
|
223 |
if(changes) |
|
224 |
{ |
|
225 |
__KTRACE_OPT(KMMU,Kern::Printf("RamAllocLock::Unlock() changes=%x",changes)); |
|
226 |
} |
|
227 |
Kern::MutexSignal(*m.iRamAllocatorMutex); |
|
228 |
} |
|
229 |
||
230 |
||
231 |
TBool RamAllocLock::Flash() |
|
232 |
{ |
|
233 |
Unlock(); |
|
234 |
Lock(); |
|
235 |
return true; // lock was released |
|
236 |
} |
|
237 |
||
238 |
||
239 |
TBool RamAllocLock::IsHeld() |
|
240 |
{ |
|
241 |
Mmu& m = TheMmu; |
|
242 |
return m.iRamAllocatorMutex->iCleanup.iThread == &Kern::CurrentThread() && m.iRamAllocLockCount; |
|
243 |
} |
|
244 |
||
245 |
||
246 |
||
247 |
// |
|
248 |
// MmuLock |
|
249 |
// |
|
250 |
||
251 |
#ifdef _DEBUG |
|
252 |
TUint MmuLock::UnlockGuardNest =0; |
|
253 |
TUint MmuLock::UnlockGuardFail =0; |
|
254 |
#endif |
|
255 |
||
256 |
NFastMutex MmuLock::iLock; |
|
257 |
||
258 |
void MmuLock::Lock() |
|
259 |
{ |
|
260 |
NKern::FMWait(&iLock); |
|
261 |
} |
|
262 |
||
263 |
void MmuLock::Unlock() |
|
264 |
{ |
|
265 |
UnlockGuardCheck(); |
|
266 |
NKern::FMSignal(&iLock); |
|
267 |
} |
|
268 |
||
269 |
TBool MmuLock::Flash() |
|
270 |
{ |
|
271 |
UnlockGuardCheck(); |
|
272 |
return NKern::FMFlash(&iLock); |
|
273 |
} |
|
274 |
||
275 |
TBool MmuLock::IsHeld() |
|
276 |
{ |
|
277 |
NFastMutex& m = iLock; |
|
278 |
return m.HeldByCurrentThread(); |
|
279 |
} |
|
280 |
||
281 |
||
282 |
||
283 |
// |
|
284 |
// Initialisation |
|
285 |
// |
|
286 |
||
287 |
Mmu TheMmu; |
|
288 |
||
289 |
void Mmu::Init1Common() |
|
290 |
{ |
|
291 |
__KTRACE_OPT2(KBOOT,KMMU,Kern::Printf("Mmu::Init1Common")); |
|
292 |
||
293 |
// Mmu data |
|
294 |
TUint pteType = PteType(ESupervisorReadWrite,true); |
|
295 |
iTempPteCached = BlankPte((TMemoryAttributes)(EMemoryAttributeNormalCached|EMemoryAttributeDefaultShareable),pteType); |
|
296 |
iTempPteUncached = BlankPte((TMemoryAttributes)(EMemoryAttributeNormalUncached|EMemoryAttributeDefaultShareable),pteType); |
|
297 |
iTempPteCacheMaintenance = BlankPte((TMemoryAttributes)(CacheMaintenance::TemporaryMapping()|EMemoryAttributeDefaultShareable),pteType); |
|
298 |
||
299 |
// other |
|
300 |
PP::MaxUserThreadStack=0x14000; // 80K - STDLIB asks for 64K for PosixServer!!!! |
|
301 |
PP::UserThreadStackGuard=0x2000; // 8K |
|
302 |
PP::MaxStackSpacePerProcess=0x200000; // 2Mb |
|
303 |
K::SupervisorThreadStackSize=0x1000; // 4K |
|
304 |
PP::SupervisorThreadStackGuard=0x1000; // 4K |
|
305 |
K::MachineConfig=(TMachineConfig*)KMachineConfigLinAddr; |
|
306 |
PP::RamDriveStartAddress=0; |
|
307 |
PP::RamDriveRange=0; |
|
308 |
PP::RamDriveMaxSize=0x20000000; // 512MB, probably will be reduced later |
|
309 |
K::MemModelAttributes=EMemModelTypeFlexible|EMemModelAttrNonExProt|EMemModelAttrKernProt|EMemModelAttrWriteProt| |
|
310 |
EMemModelAttrVA|EMemModelAttrProcessProt|EMemModelAttrSameVA|EMemModelAttrSvKernProt| |
|
311 |
EMemModelAttrIPCKernProt|EMemModelAttrRamCodeProt; |
|
312 |
} |
|
313 |
||
314 |
||
22
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
315 |
#ifdef FMM_VERIFY_RAM |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
316 |
// Attempt to write to each unused RAM page and verify the contents. |
0 | 317 |
void Mmu::VerifyRam() |
318 |
{ |
|
319 |
Kern::Printf("Mmu::VerifyRam() pass 1"); |
|
320 |
RamAllocLock::Lock(); |
|
321 |
||
322 |
TPhysAddr p = 0; |
|
323 |
do |
|
324 |
{ |
|
325 |
SPageInfo* pi = SPageInfo::SafeFromPhysAddr(p); |
|
326 |
if(pi) |
|
327 |
{ |
|
328 |
Kern::Printf("%08x %d",p,pi->Type()); |
|
329 |
if(pi->Type()==SPageInfo::EUnused) |
|
330 |
{ |
|
331 |
volatile TPhysAddr* b = (volatile TPhysAddr*)MapTemp(p,0); |
|
332 |
b[0] = p; |
|
333 |
b[1] = ~p; |
|
334 |
__NK_ASSERT_DEBUG(b[0]==p); |
|
335 |
__NK_ASSERT_DEBUG(b[1]==~p); |
|
336 |
UnmapTemp(); |
|
337 |
} |
|
338 |
} |
|
339 |
p += KPageSize; |
|
340 |
} |
|
341 |
while(p); |
|
342 |
||
343 |
TBool fail = false; |
|
344 |
Kern::Printf("Mmu::VerifyRam() pass 2"); |
|
345 |
do |
|
346 |
{ |
|
347 |
SPageInfo* pi = SPageInfo::SafeFromPhysAddr(p); |
|
348 |
if(pi) |
|
349 |
{ |
|
350 |
if(pi->Type()==SPageInfo::EUnused) |
|
351 |
{ |
|
352 |
volatile TPhysAddr* b = (volatile TPhysAddr*)MapTemp(p,0); |
|
353 |
if(b[0]!=p || b[1]!=~p) |
|
354 |
{ |
|
355 |
fail = true; |
|
356 |
Kern::Printf("%08x FAILED %x %x",b[0],b[1]); |
|
357 |
} |
|
358 |
UnmapTemp(); |
|
359 |
} |
|
360 |
} |
|
361 |
p += KPageSize; |
|
362 |
} |
|
363 |
while(p); |
|
364 |
||
365 |
__NK_ASSERT_DEBUG(!fail); |
|
366 |
RamAllocLock::Unlock(); |
|
367 |
} |
|
368 |
#endif |
|
369 |
||
370 |
||
371 |
void Mmu::Init2Common() |
|
372 |
{ |
|
373 |
__KTRACE_OPT2(KBOOT,KMMU,Kern::Printf("Mmu::Init2Common")); |
|
374 |
||
375 |
// create allocator... |
|
376 |
const SRamInfo& info = *(const SRamInfo*)TheSuperPage().iRamBootData; |
|
377 |
iRamPageAllocator = DRamAllocator::New(info, iRamZones, iRamZoneCallback); |
|
378 |
||
379 |
// initialise all pages in banks as unused... |
|
380 |
const SRamBank* bank = info.iBanks; |
|
381 |
while(bank->iSize) |
|
382 |
{ |
|
383 |
TUint32 base = bank->iBase; |
|
384 |
TUint32 size = bank->iSize; |
|
385 |
__KTRACE_OPT2(KBOOT,KMMU,Kern::Printf("Found RAM bank 0x%08x size %d",base,size)); |
|
386 |
if(base+size<=base || ((base|size)&KPageMask)) |
|
387 |
Panic(EInvalidRamBankAtBoot); |
|
388 |
||
389 |
SPageInfo* pi = SPageInfo::FromPhysAddr(base); |
|
390 |
SPageInfo* piEnd = pi+(size>>KPageShift); |
|
391 |
while(pi<piEnd) |
|
392 |
(pi++)->SetUnused(); |
|
393 |
++bank; |
|
394 |
} |
|
395 |
// step over the last bank to get to the reserved banks. |
|
396 |
++bank; |
|
397 |
// mark any reserved regions as allocated... |
|
398 |
while(bank->iSize) |
|
399 |
{ |
|
400 |
TUint32 base = bank->iBase; |
|
401 |
TUint32 size = bank->iSize; |
|
402 |
__KTRACE_OPT2(KBOOT,KMMU,Kern::Printf("Found reserved bank 0x%08x size %d",base,size)); |
|
403 |
if(base+size<=base || ((base|size)&KPageMask)) |
|
404 |
Panic(EInvalidReservedBankAtBoot); |
|
405 |
||
406 |
SPageInfo* pi = SPageInfo::FromPhysAddr(base); |
|
407 |
SPageInfo* piEnd = pi+(size>>KPageShift); |
|
408 |
while(pi<piEnd) |
|
409 |
(pi++)->SetPhysAlloc(); |
|
410 |
++bank; |
|
411 |
} |
|
412 |
||
413 |
// Clear the inital (and only so far) page table info page so all unused |
|
414 |
// page tables infos will be marked as unused. |
|
415 |
__ASSERT_COMPILE(SPageTableInfo::EUnused == 0); |
|
416 |
memclr((TAny*)KPageTableInfoBase, KPageSize); |
|
417 |
||
418 |
// look for page tables - assume first page table maps page tables |
|
419 |
TPte* pPte = (TPte*)KPageTableBase; |
|
420 |
TInt i; |
|
421 |
for(i=0; i<KChunkSize/KPageSize; ++i) |
|
422 |
{ |
|
423 |
TPte pte = *pPte++; |
|
424 |
if(pte==KPteUnallocatedEntry) // after boot, page tables are contiguous |
|
425 |
break; |
|
426 |
TPhysAddr ptpgPhys = Mmu::PtePhysAddr(pte,i); |
|
427 |
__KTRACE_OPT(KBOOT,Kern::Printf("Page Table Group %08x -> Phys %08x", KPageTableBase+i*KPageSize, ptpgPhys)); |
|
428 |
SPageInfo* pi = SPageInfo::SafeFromPhysAddr(ptpgPhys); |
|
429 |
__ASSERT_ALWAYS(pi, Panic(EInvalidPageTableAtBoot)); |
|
430 |
pi->SetFixed(i); // this also sets the SPageInfo::iOffset so that linear-to-physical works |
|
431 |
} |
|
432 |
||
433 |
// look for mapped pages |
|
434 |
TPde* pd = Mmu::PageDirectory(KKernelOsAsid); |
|
435 |
for(i=0; i<(1<<(32-KChunkShift)); ++i) |
|
436 |
{ |
|
437 |
TPde pde = pd[i]; |
|
438 |
if(pde==KPdeUnallocatedEntry) |
|
439 |
continue; |
|
440 |
TPhysAddr pdePhys = Mmu::PdePhysAddr(pde); |
|
441 |
TPte* pt = 0; |
|
442 |
if(pdePhys!=KPhysAddrInvalid) |
|
443 |
{ |
|
444 |
__KTRACE_OPT(KBOOT,Kern::Printf("Addr %08x -> Whole PDE Phys %08x", i<<KChunkShift, pdePhys)); |
|
445 |
} |
|
446 |
else |
|
447 |
{ |
|
448 |
pt = Mmu::PageTableFromPde(pde); |
|
449 |
__KTRACE_OPT(KBOOT,Kern::Printf("Addr %08x -> page table %08x", i<<KChunkShift, pt)); |
|
450 |
__ASSERT_ALWAYS(pt,Panic(EInvalidPdeAtBoot)); // bad PDE |
|
451 |
} |
|
452 |
||
453 |
TInt j; |
|
454 |
TInt np = 0; |
|
455 |
for(j=0; j<KChunkSize/KPageSize; ++j) |
|
456 |
{ |
|
457 |
TBool present = ETrue; // all pages present if whole PDE mapping |
|
458 |
TPte pte = 0; |
|
459 |
if(pt) |
|
460 |
{ |
|
461 |
pte = pt[j]; |
|
462 |
present = pte!=KPteUnallocatedEntry; |
|
463 |
} |
|
464 |
if(present) |
|
465 |
{ |
|
466 |
++np; |
|
467 |
TPhysAddr pa = pt ? Mmu::PtePhysAddr(pte,j) : (pdePhys + (j<<KPageShift)); |
|
468 |
SPageInfo* pi = SPageInfo::SafeFromPhysAddr(pa); |
|
469 |
__KTRACE_OPT(KBOOT,Kern::Printf("Addr: %08x PA=%08x", |
|
470 |
(i<<KChunkShift)+(j<<KPageShift), pa)); |
|
471 |
if(pi) // ignore non-RAM mappings |
|
472 |
{ |
|
473 |
TInt r = iRamPageAllocator->MarkPageAllocated(pa, EPageFixed); |
|
474 |
// allow KErrAlreadyExists since it's possible that a page is doubly mapped |
|
475 |
__ASSERT_ALWAYS(r==KErrNone || r==KErrAlreadyExists, Panic(EBadMappedPageAfterBoot)); |
|
476 |
if(pi->Type()==SPageInfo::EUnused) |
|
477 |
pi->SetFixed(); |
|
22
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
478 |
#ifdef BTRACE_KERNEL_MEMORY |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
479 |
if(r == KErrNone) |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
480 |
++Epoc::KernelMiscPages; |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
481 |
#endif |
0 | 482 |
} |
483 |
} |
|
484 |
} |
|
485 |
__KTRACE_OPT(KBOOT,Kern::Printf("Addr: %08x #PTEs=%d",(i<<KChunkShift),np)); |
|
486 |
if(pt) |
|
487 |
{ |
|
488 |
SPageTableInfo* pti = SPageTableInfo::FromPtPtr(pt); |
|
489 |
pti->Boot(np); |
|
490 |
} |
|
491 |
} |
|
492 |
||
493 |
TInt r = K::MutexCreate(iRamAllocatorMutex, KLitRamAlloc, NULL, EFalse, KMutexOrdRamAlloc); |
|
494 |
if(r!=KErrNone) |
|
495 |
Panic(ERamAllocMutexCreateFailed); |
|
496 |
iRamAllocLockCount = 0; |
|
497 |
iRamAllocInitialFreePages = FreeRamInPages(); |
|
498 |
||
499 |
__KTRACE_OPT2(KBOOT,KMMU,Kern::Printf("Mmu::DoInit2")); |
|
500 |
||
501 |
for(i=0; i<KNumTempMappingSlots; ++i) |
|
502 |
iTempMap[i].Alloc(1); |
|
503 |
||
504 |
iPhysMemSyncTemp.Alloc(1); |
|
505 |
r = K::MutexCreate(iPhysMemSyncMutex, KLitPhysMemSync, NULL, EFalse, KMutexOrdSyncPhysMem); |
|
506 |
if(r!=KErrNone) |
|
507 |
Panic(EPhysMemSyncMutexCreateFailed); |
|
22
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
508 |
|
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
509 |
#ifdef FMM_VERIFY_RAM |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
510 |
VerifyRam(); |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
511 |
#endif |
0 | 512 |
} |
513 |
||
514 |
||
515 |
void Mmu::Init2FinalCommon() |
|
516 |
{ |
|
517 |
__KTRACE_OPT2(KBOOT,KMMU,Kern::Printf("Mmu::Init2FinalCommon")); |
|
22
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
518 |
// Reduce free memory to <2GB... |
0 | 519 |
while(FreeRamInPages()>=0x80000000/KPageSize) |
520 |
{ |
|
521 |
TPhysAddr dummyPage; |
|
522 |
TInt r = iRamPageAllocator->AllocRamPages(&dummyPage,1, EPageFixed); |
|
523 |
__NK_ASSERT_ALWAYS(r==KErrNone); |
|
524 |
} |
|
22
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
525 |
// Reduce total RAM to <2GB... |
0 | 526 |
if(TheSuperPage().iTotalRamSize<0) |
527 |
TheSuperPage().iTotalRamSize = 0x80000000-KPageSize; |
|
528 |
||
529 |
// Save current free RAM size - there can never be more free RAM than this |
|
530 |
TUint maxFreePages = FreeRamInPages(); |
|
531 |
K::MaxFreeRam = maxFreePages*KPageSize; |
|
532 |
if(maxFreePages < (TUint(PP::RamDriveMaxSize)>>KPageShift)) |
|
533 |
PP::RamDriveMaxSize = maxFreePages*KPageSize; |
|
534 |
||
535 |
// update this to stop assert triggering in RamAllocLock::Lock() |
|
536 |
iRamAllocInitialFreePages = maxFreePages; |
|
20
597aaf25e343
Revision: 201008
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
14
diff
changeset
|
537 |
|
597aaf25e343
Revision: 201008
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
14
diff
changeset
|
538 |
// Get the allocator to signal to the variant which RAM zones are in use so far |
597aaf25e343
Revision: 201008
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
14
diff
changeset
|
539 |
iRamPageAllocator->InitialCallback(); |
0 | 540 |
} |
541 |
||
542 |
||
543 |
void Mmu::Init3() |
|
544 |
{ |
|
545 |
iDefrag = new Defrag; |
|
546 |
if (!iDefrag) |
|
547 |
Panic(EDefragAllocFailed); |
|
548 |
iDefrag->Init3(TheMmu.iRamPageAllocator); |
|
549 |
} |
|
550 |
||
22
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
551 |
|
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
552 |
void Mmu::BTracePrime(TUint aCategory) |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
553 |
{ |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
554 |
(void)aCategory; |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
555 |
|
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
556 |
#ifdef BTRACE_RAM_ALLOCATOR |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
557 |
// Must check for -1 as that is the default value of aCategory for |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
558 |
// BTrace::Prime() which is intended to prime all categories that are |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
559 |
// currently enabled via a single invocation of BTrace::Prime(). |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
560 |
if(aCategory==BTrace::ERamAllocator || (TInt)aCategory == -1) |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
561 |
{ |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
562 |
NKern::ThreadEnterCS(); |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
563 |
RamAllocLock::Lock(); |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
564 |
iRamPageAllocator->DoBTracePrime(); |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
565 |
RamAllocLock::Unlock(); |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
566 |
NKern::ThreadLeaveCS(); |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
567 |
} |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
568 |
#endif |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
569 |
} |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
570 |
|
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
571 |
|
0 | 572 |
// |
573 |
// Utils |
|
574 |
// |
|
575 |
||
576 |
void Mmu::Panic(TPanic aPanic) |
|
577 |
{ |
|
578 |
Kern::Fault("MMU",aPanic); |
|
579 |
} |
|
580 |
||
581 |
||
582 |
TUint Mmu::FreeRamInPages() |
|
583 |
{ |
|
584 |
return iRamPageAllocator->FreeRamInPages()+ThePager.NumberOfFreePages(); |
|
585 |
} |
|
586 |
||
587 |
||
588 |
TUint Mmu::TotalPhysicalRamPages() |
|
589 |
{ |
|
590 |
return iRamPageAllocator->TotalPhysicalRamPages(); |
|
591 |
} |
|
592 |
||
593 |
||
594 |
const SRamZone* Mmu::RamZoneConfig(TRamZoneCallback& aCallback) const |
|
595 |
{ |
|
596 |
aCallback = iRamZoneCallback; |
|
597 |
return iRamZones; |
|
598 |
} |
|
599 |
||
600 |
||
601 |
void Mmu::SetRamZoneConfig(const SRamZone* aZones, TRamZoneCallback aCallback) |
|
602 |
{ |
|
603 |
iRamZones = aZones; |
|
604 |
iRamZoneCallback = aCallback; |
|
605 |
} |
|
606 |
||
607 |
||
608 |
TInt Mmu::ModifyRamZoneFlags(TUint aId, TUint aClearMask, TUint aSetMask) |
|
609 |
{ |
|
610 |
return iRamPageAllocator->ModifyZoneFlags(aId, aClearMask, aSetMask); |
|
611 |
} |
|
612 |
||
613 |
||
614 |
TInt Mmu::GetRamZonePageCount(TUint aId, SRamZonePageCount& aPageData) |
|
615 |
{ |
|
616 |
return iRamPageAllocator->GetZonePageCount(aId, aPageData); |
|
617 |
} |
|
618 |
||
619 |
||
620 |
TInt Mmu::ZoneAllocPhysicalRam(TUint* aZoneIdList, TUint aZoneIdCount, TInt aBytes, TPhysAddr& aPhysAddr, TInt aAlign) |
|
621 |
{ |
|
622 |
__KTRACE_OPT(KMMU,Kern::Printf("Mmu::ZoneAllocPhysicalRam(?,%d,%d,?,%d)", aZoneIdCount, aBytes, aPhysAddr, aAlign)); |
|
623 |
__NK_ASSERT_DEBUG(RamAllocLock::IsHeld()); |
|
624 |
||
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
625 |
TInt r = iRamPageAllocator->ZoneAllocContiguousRam(aZoneIdList, aZoneIdCount, aBytes, aPhysAddr, aAlign); |
0 | 626 |
if(r!=KErrNone) |
627 |
iRamAllocFailed = ETrue; |
|
628 |
else |
|
629 |
{ |
|
630 |
TUint pages = MM::RoundToPageCount(aBytes); |
|
631 |
AllocatedPhysicalRam(aPhysAddr, pages, (Mmu::TRamAllocFlags)EMemAttStronglyOrdered); |
|
632 |
} |
|
633 |
__KTRACE_OPT(KMMU,Kern::Printf("Mmu::ZoneAllocPhysicalRam returns %d and aPhysAddr=0x%08x",r,aPhysAddr)); |
|
634 |
return r; |
|
635 |
} |
|
636 |
||
637 |
||
638 |
TInt Mmu::ZoneAllocPhysicalRam(TUint* aZoneIdList, TUint aZoneIdCount, TInt aNumPages, TPhysAddr* aPageList) |
|
639 |
{ |
|
640 |
__KTRACE_OPT(KMMU,Kern::Printf("Mmu::ZoneAllocPhysicalRam(?,%d,%d,?)", aZoneIdCount, aNumPages)); |
|
641 |
__NK_ASSERT_DEBUG(RamAllocLock::IsHeld()); |
|
642 |
||
643 |
TInt r = iRamPageAllocator->ZoneAllocRamPages(aZoneIdList, aZoneIdCount, aPageList, aNumPages, EPageFixed); |
|
644 |
if(r!=KErrNone) |
|
645 |
iRamAllocFailed = ETrue; |
|
646 |
else |
|
647 |
{ |
|
648 |
PagesAllocated(aPageList, aNumPages, (Mmu::TRamAllocFlags)EMemAttStronglyOrdered); |
|
649 |
||
650 |
// update page infos... |
|
22
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
651 |
SetAllocPhysRam(aPageList, aNumPages); |
0 | 652 |
} |
653 |
__KTRACE_OPT(KMMU,Kern::Printf("Mmu::ZoneAllocPhysicalRam returns %d",r)); |
|
654 |
return r; |
|
655 |
} |
|
656 |
||
657 |
||
658 |
TInt Mmu::RamHalFunction(TInt aFunction, TAny* a1, TAny* a2) |
|
659 |
{ |
|
660 |
// This function should only be registered with hal and therefore can only |
|
661 |
// be invoked after the ram allocator has been created. |
|
662 |
__NK_ASSERT_DEBUG(iRamPageAllocator); |
|
663 |
return iRamPageAllocator->HalFunction(aFunction, a1, a2); |
|
664 |
} |
|
665 |
||
666 |
||
667 |
void Mmu::ChangePageType(SPageInfo* aPageInfo, TZonePageType aOldPageType, TZonePageType aNewPageType) |
|
668 |
{ |
|
669 |
iRamPageAllocator->ChangePageType(aPageInfo, aOldPageType, aNewPageType); |
|
670 |
} |
|
671 |
||
672 |
TInt Mmu::HandlePageFault(TLinAddr aPc, TLinAddr aFaultAddress, TUint aAccessPermissions, TAny* aExceptionInfo) |
|
673 |
{ |
|
674 |
TRACE(("Mmu::HandlePageFault(0x%08x,0x%08x,%d)",aPc,aFaultAddress,aAccessPermissions)); |
|
675 |
||
676 |
DMemModelThread* thread = (DMemModelThread*)TheCurrentThread; |
|
677 |
// Get the os asid of the process taking the fault, no need to open a reference |
|
678 |
// as it is the current thread's process so can't be freed. |
|
679 |
TUint faultOsAsid = ((DMemModelProcess*)thread->iNThread.iAddressSpace)->OsAsid(); |
|
680 |
||
681 |
// check if any fast mutexes held... |
|
682 |
NFastMutex* fm = NKern::HeldFastMutex(); |
|
683 |
TPagingExcTrap* trap = thread->iPagingExcTrap; |
|
684 |
if(fm) |
|
685 |
{ |
|
686 |
// check there is an XTRAP_PAGING in effect... |
|
687 |
if(!trap) |
|
688 |
{ |
|
689 |
// oops, kill system... |
|
690 |
__KTRACE_OPT2(KPAGING,KPANIC,Kern::Printf("Fault with FM Held! addr=0x%08x (%O pc=%x)",aFaultAddress,thread,aPc)); |
|
691 |
Exc::Fault(aExceptionInfo); |
|
692 |
} |
|
693 |
||
694 |
// release the fast mutex... |
|
695 |
NKern::FMSignal(fm); |
|
696 |
} |
|
697 |
||
698 |
NKern::ThreadEnterCS(); |
|
699 |
||
700 |
// work out address space for aFaultAddress... |
|
701 |
TUint osAsid = faultOsAsid; |
|
702 |
TLinAddr addr = aFaultAddress; |
|
703 |
if(thread->iAliasLinAddr && TUint(addr - thread->iAliasLinAddr) < TUint(KPageSize)) |
|
704 |
{ |
|
705 |
// Address in aliased memory... |
|
706 |
addr = (addr - thread->iAliasLinAddr) + thread->iAliasTarget; |
|
707 |
// Get the os asid of the process thread is aliasing, no need to open |
|
708 |
// a reference on it as one was already opened when the alias was created. |
|
709 |
osAsid = thread->iAliasProcess->OsAsid(); |
|
710 |
} |
|
711 |
else if(addr>=KGlobalMemoryBase) |
|
712 |
{ |
|
713 |
// Address in global region, so look it up in kernel's address space... |
|
714 |
osAsid = KKernelOsAsid; |
|
715 |
} |
|
716 |
||
717 |
// NOTE, osAsid will remain valid for duration of this function because it is either |
|
718 |
// - The current thread's address space, which can't go away whilst the thread |
|
719 |
// is running. |
|
720 |
// - The address space of another thread which we are aliasing memory from, |
|
721 |
// and we would only do this if we have a reference on this other thread, |
|
722 |
// which has a reference on it's process, which should own the address space! |
|
723 |
||
724 |
#ifdef __BROADCAST_CACHE_MAINTENANCE__ |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
725 |
TInt aliasAsid = -1; |
0 | 726 |
if (thread->iAliasLinAddr) |
727 |
{ |
|
728 |
// If an alias is in effect, the the thread will be locked to the current CPU, |
|
729 |
// but we need to be able to migrate between CPUs for cache maintainance. This |
|
730 |
// must be dealt with by removing the alias and restoring it with a paging trap |
|
731 |
// handler. |
|
732 |
if(!trap) |
|
733 |
{ |
|
734 |
// oops, kill system... |
|
735 |
__KTRACE_OPT2(KPAGING,KPANIC,Kern::Printf("Fault with thread locked to current CPU! addr=0x%08x (%O pc=%x)",aFaultAddress,thread,aPc)); |
|
736 |
Exc::Fault(aExceptionInfo); |
|
737 |
} |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
738 |
// Open a reference on the aliased process's os asid before removing the alias |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
739 |
// so that the address space can't be freed while we try to access its members. |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
740 |
aliasAsid = thread->iAliasProcess->TryOpenOsAsid(); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
741 |
// This should never fail as until we remove the alias there will |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
742 |
// always be at least one reference on the os asid. |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
743 |
__NK_ASSERT_DEBUG(aliasAsid >= 0); |
0 | 744 |
thread->RemoveAlias(); |
745 |
} |
|
746 |
#endif |
|
747 |
||
748 |
// find mapping... |
|
749 |
TUint offsetInMapping; |
|
750 |
TUint mapInstanceCount; |
|
751 |
DMemoryMapping* mapping = MM::FindMappingInAddressSpace(osAsid, addr, 1, offsetInMapping, mapInstanceCount); |
|
752 |
// TRACE(("%O mapping=0x%08x",TheCurrentThread,mapping)); |
|
753 |
TInt r = KErrNotFound; |
|
754 |
||
755 |
if(mapping) |
|
756 |
{ |
|
757 |
MmuLock::Lock(); |
|
758 |
||
759 |
// check if we need to process page fault... |
|
760 |
if(!Mmu::CheckPteTypePermissions(mapping->PteType(),aAccessPermissions) || |
|
761 |
mapInstanceCount != mapping->MapInstanceCount()) |
|
762 |
{ |
|
763 |
// Invalid access to the page. |
|
764 |
MmuLock::Unlock(); |
|
765 |
r = KErrAbort; |
|
766 |
} |
|
767 |
else |
|
768 |
{ |
|
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
769 |
// Should not be able to take a fault on a pinned mapping if accessing it |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
770 |
// with the correct permissions. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
771 |
__NK_ASSERT_DEBUG(!mapping->IsPinned()); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
772 |
|
0 | 773 |
// we do need to handle fault so is this a demand paging or page moving fault |
774 |
DMemoryObject* memory = mapping->Memory(); |
|
775 |
if(!memory) |
|
776 |
MmuLock::Unlock(); |
|
777 |
else |
|
778 |
{ |
|
779 |
TUint faultIndex = (offsetInMapping >> KPageShift) + mapping->iStartIndex; |
|
780 |
memory->Open(); |
|
781 |
||
782 |
// This is safe as we have the instance count so can detect the mapping |
|
783 |
// being reused and we have a reference to the memory object so it can't |
|
784 |
// be deleted. |
|
785 |
MmuLock::Unlock(); |
|
786 |
||
787 |
if(memory->IsDemandPaged()) |
|
788 |
{ |
|
789 |
// Let the pager handle the fault... |
|
790 |
r = ThePager.HandlePageFault( aPc, aFaultAddress, faultOsAsid, faultIndex, |
|
791 |
aAccessPermissions, memory, mapping, mapInstanceCount, |
|
792 |
thread, aExceptionInfo); |
|
793 |
} |
|
794 |
else |
|
795 |
{// The page could be being moved so verify that with its manager. |
|
796 |
DMemoryManager* manager = memory->iManager; |
|
797 |
r = manager->HandleFault(memory, faultIndex, mapping, mapInstanceCount, aAccessPermissions); |
|
798 |
} |
|
799 |
if (r == KErrNone) |
|
800 |
{// alias PDE needs updating because page tables have changed... |
|
801 |
thread->RefreshAlias(); |
|
802 |
} |
|
803 |
memory->Close(); |
|
804 |
} |
|
805 |
} |
|
806 |
mapping->Close(); |
|
807 |
} |
|
808 |
||
809 |
if (trap) |
|
810 |
{ |
|
811 |
// restore address space (because the trap will bypass any code |
|
812 |
// which would have done this.)... |
|
813 |
DMemModelThread::RestoreAddressSpace(); |
|
814 |
} |
|
815 |
||
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
816 |
#ifdef __BROADCAST_CACHE_MAINTENANCE__ |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
817 |
// Close any reference on the aliased process's os asid before we leave the |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
818 |
// critical section. |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
819 |
if (aliasAsid >= 0) |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
820 |
{ |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
821 |
thread->iAliasProcess->CloseOsAsid(); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
822 |
} |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
823 |
#endif |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
824 |
|
0 | 825 |
NKern::ThreadLeaveCS(); // thread will die now if CheckRealtimeThreadFault caused a panic |
826 |
||
827 |
// deal with XTRAP_PAGING... |
|
828 |
if(trap) |
|
829 |
{ |
|
830 |
// re-acquire any fast mutex which was held before the page fault... |
|
831 |
if(fm) |
|
832 |
NKern::FMWait(fm); |
|
833 |
if (r == KErrNone) |
|
834 |
{ |
|
835 |
trap->Exception(1); // return from exception trap with result '1' (value>0) |
|
836 |
// code doesn't continue beyond this point. |
|
837 |
__NK_ASSERT_DEBUG(0); |
|
838 |
} |
|
839 |
} |
|
840 |
||
841 |
return r; |
|
842 |
} |
|
843 |
||
844 |
||
845 |
// |
|
846 |
// Memory allocation |
|
847 |
// |
|
848 |
||
849 |
TInt Mmu::AllocRam( TPhysAddr* aPages, TUint aCount, TRamAllocFlags aFlags, TZonePageType aZonePageType, |
|
850 |
TUint aBlockZoneId, TBool aBlockRest) |
|
851 |
{ |
|
852 |
__KTRACE_OPT(KMMU,Kern::Printf("Mmu::AllocRam(?,%d,%x)",aCount,aFlags)); |
|
853 |
__NK_ASSERT_DEBUG(RamAllocLock::IsHeld()); |
|
854 |
#ifdef _DEBUG |
|
855 |
if(K::CheckForSimulatedAllocFail()) |
|
856 |
{ |
|
857 |
__KTRACE_OPT(KMMU,Kern::Printf("Mmu::AllocRam returns simulated OOM %d",KErrNoMemory)); |
|
858 |
return KErrNoMemory; |
|
859 |
} |
|
860 |
#endif |
|
861 |
TInt missing = iRamPageAllocator->AllocRamPages(aPages, aCount, aZonePageType, aBlockZoneId, aBlockRest); |
|
28
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
862 |
if(missing && !(aFlags&EAllocNoPagerReclaim)) |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
863 |
{ |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
864 |
// taking the page cleaning lock here prevents the pager releasing the ram alloc lock |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
865 |
PageCleaningLock::Lock(); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
866 |
if (ThePager.GetFreePages(missing)) |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
867 |
missing = iRamPageAllocator->AllocRamPages(aPages, aCount, aZonePageType, aBlockZoneId, aBlockRest); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
868 |
PageCleaningLock::Unlock(); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
26
diff
changeset
|
869 |
} |
0 | 870 |
TInt r = missing ? KErrNoMemory : KErrNone; |
871 |
if(r!=KErrNone) |
|
872 |
iRamAllocFailed = ETrue; |
|
873 |
else |
|
874 |
PagesAllocated(aPages,aCount,aFlags); |
|
875 |
__KTRACE_OPT(KMMU,Kern::Printf("Mmu::AllocRam returns %d",r)); |
|
876 |
return r; |
|
877 |
} |
|
878 |
||
879 |
||
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
880 |
/** |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
881 |
Mark a page as being allocated to a particular page type. |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
882 |
|
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
883 |
NOTE - This page should not be used until PagesAllocated() has been invoked on it. |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
884 |
|
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
885 |
@param aPhysAddr The physical address of the page to mark as allocated. |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
886 |
@param aZonePageType The type of the page to mark as allocated. |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
887 |
*/ |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
888 |
void Mmu::MarkPageAllocated(TPhysAddr aPhysAddr, TZonePageType aZonePageType) |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
889 |
{ |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
890 |
__KTRACE_OPT(KMMU,Kern::Printf("Mmu::MarkPageAllocated(0x%x, %d)", aPhysAddr, aZonePageType)); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
891 |
__NK_ASSERT_DEBUG(RamAllocLock::IsHeld()); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
892 |
iRamPageAllocator->MarkPageAllocated(aPhysAddr, aZonePageType); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
893 |
} |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
894 |
|
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
895 |
|
0 | 896 |
void Mmu::FreeRam(TPhysAddr* aPages, TUint aCount, TZonePageType aZonePageType) |
897 |
{ |
|
898 |
__KTRACE_OPT(KMMU,Kern::Printf("Mmu::FreeRam(?,%d)",aCount)); |
|
899 |
__NK_ASSERT_DEBUG(RamAllocLock::IsHeld()); |
|
900 |
||
901 |
// update page infos... |
|
902 |
TPhysAddr* pages = aPages; |
|
903 |
TPhysAddr* pagesEnd = pages+aCount; |
|
904 |
TPhysAddr* pagesOut = aPages; |
|
905 |
MmuLock::Lock(); |
|
906 |
TUint flash = 0; |
|
907 |
while(pages<pagesEnd) |
|
908 |
{ |
|
909 |
MmuLock::Flash(flash,KMaxPageInfoUpdatesInOneGo/2); |
|
910 |
TPhysAddr pagePhys = *pages++; |
|
911 |
__NK_ASSERT_DEBUG(pagePhys!=KPhysAddrInvalid); |
|
912 |
SPageInfo* pi = SPageInfo::FromPhysAddr(pagePhys); |
|
913 |
PageFreed(pi); |
|
914 |
||
24
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
915 |
switch (ThePager.PageFreed(pi)) |
0 | 916 |
{ |
24
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
917 |
case KErrNone: |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
918 |
--aCount; // pager has dealt with this page, so one less for us |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
919 |
break; |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
920 |
case KErrCompletion: |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
921 |
// This was a pager controlled page but it is no longer required. |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
922 |
__NK_ASSERT_DEBUG(aZonePageType == EPageMovable || aZonePageType == EPageDiscard); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
923 |
__NK_ASSERT_DEBUG(pi->PagedState() == SPageInfo::EUnpaged); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
924 |
if (aZonePageType == EPageMovable) |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
925 |
{// This page was donated to the pager so have to free it here |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
926 |
// as aZonePageType is incorrect for this page but aPages may |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
927 |
// contain a mixture of movable and discardable pages. |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
928 |
MmuLock::Unlock(); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
929 |
iRamPageAllocator->FreeRamPages(&pagePhys, 1, EPageDiscard); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
930 |
aCount--; // We've freed this page here so one less to free later |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
931 |
flash = 0; // reset flash count as we released the mmulock. |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
932 |
MmuLock::Lock(); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
933 |
break; |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
934 |
} |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
935 |
// fall through.. |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
936 |
default: |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
937 |
// Free this page.. |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
938 |
__NK_ASSERT_DEBUG(pi->PagedState() == SPageInfo::EUnpaged); |
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
939 |
*pagesOut++ = pagePhys; // store page address for freeing later |
0 | 940 |
} |
941 |
} |
|
942 |
MmuLock::Unlock(); |
|
943 |
||
944 |
iRamPageAllocator->FreeRamPages(aPages, aCount, aZonePageType); |
|
945 |
} |
|
946 |
||
947 |
||
948 |
TInt Mmu::AllocContiguousRam(TPhysAddr& aPhysAddr, TUint aCount, TUint aAlign, TRamAllocFlags aFlags) |
|
949 |
{ |
|
950 |
__KTRACE_OPT(KMMU,Kern::Printf("Mmu::AllocContiguousRam(?,0x%x,%d,%x)",aCount,aAlign,aFlags)); |
|
951 |
__NK_ASSERT_DEBUG(RamAllocLock::IsHeld()); |
|
952 |
#ifdef _DEBUG |
|
953 |
if(K::CheckForSimulatedAllocFail()) |
|
954 |
{ |
|
955 |
__KTRACE_OPT(KMMU,Kern::Printf("Mmu::AllocContiguousRam returns simulated OOM %d",KErrNoMemory)); |
|
956 |
return KErrNoMemory; |
|
957 |
} |
|
24
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
958 |
// Only the pager sets EAllocNoPagerReclaim and it shouldn't allocate contiguous ram. |
0 | 959 |
__NK_ASSERT_DEBUG(!(aFlags&EAllocNoPagerReclaim)); |
960 |
#endif |
|
26
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
24
diff
changeset
|
961 |
TInt r = iRamPageAllocator->AllocContiguousRam(aCount, aPhysAddr, aAlign+KPageShift); |
0 | 962 |
if(r!=KErrNone) |
963 |
iRamAllocFailed = ETrue; |
|
964 |
else |
|
965 |
PagesAllocated((TPhysAddr*)(aPhysAddr|1), aCount, aFlags); |
|
24
41f0cfe18c80
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
22
diff
changeset
|
966 |
__KTRACE_OPT(KMMU,Kern::Printf("AllocContiguousRam returns %d and aPhysAddr=0x%08x",r,aPhysAddr)); |
0 | 967 |
return r; |
968 |
} |
|
969 |
||
970 |
||
971 |
void Mmu::FreeContiguousRam(TPhysAddr aPhysAddr, TUint aCount) |
|
972 |
{ |
|
973 |
__KTRACE_OPT(KMMU,Kern::Printf("Mmu::FreeContiguousRam(0x%08x,0x%x)",aPhysAddr,aCount)); |
|
974 |
__NK_ASSERT_DEBUG(RamAllocLock::IsHeld()); |
|
975 |
__NK_ASSERT_DEBUG((aPhysAddr&KPageMask)==0); |
|
976 |
||
977 |
TUint pageCount = aCount; |
|
978 |
||
979 |
// update page infos... |
|
980 |
SPageInfo* pi = SPageInfo::FromPhysAddr(aPhysAddr); |
|
981 |
SPageInfo* piEnd = pi+pageCount; |
|
982 |
TUint flash = 0; |
|
983 |
MmuLock::Lock(); |
|
984 |
while(pi<piEnd) |
|
985 |
{ |
|
986 |
MmuLock::Flash(flash,KMaxPageInfoUpdatesInOneGo); |
|
987 |
PageFreed(pi++); |
|
988 |
} |
|
989 |
MmuLock::Unlock(); |
|
990 |
||
991 |
// free pages... |
|
992 |
while(pageCount) |
|
993 |
{ |
|
994 |
iRamPageAllocator->FreeRamPage(aPhysAddr, EPageFixed); |
|
995 |
aPhysAddr += KPageSize; |
|
996 |
--pageCount; |
|
997 |
} |
|
998 |
} |
|
999 |
||
1000 |
||
1001 |
TInt Mmu::AllocPhysicalRam(TPhysAddr* aPages, TUint aCount, TRamAllocFlags aFlags) |
|
1002 |
{ |
|
1003 |
__KTRACE_OPT(KMMU,Kern::Printf("Mmu::AllocPhysicalRam(?,%d,%x)",aCount,aFlags)); |
|
1004 |
__NK_ASSERT_DEBUG(RamAllocLock::IsHeld()); |
|
1005 |
// Allocate fixed pages as physically allocated pages aren't movable or discardable. |
|
1006 |
TInt r = AllocRam(aPages, aCount, aFlags, EPageFixed); |
|
1007 |
if (r!=KErrNone) |
|
1008 |
return r; |
|
1009 |
||
1010 |
// update page infos... |
|
22
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1011 |
SetAllocPhysRam(aPages, aCount); |
0 | 1012 |
|
1013 |
return KErrNone; |
|
1014 |
} |
|
1015 |
||
1016 |
||
1017 |
void Mmu::FreePhysicalRam(TPhysAddr* aPages, TUint aCount) |
|
1018 |
{ |
|
1019 |
__KTRACE_OPT(KMMU,Kern::Printf("Mmu::FreePhysicalRam(?,%d)",aCount)); |
|
1020 |
__NK_ASSERT_DEBUG(RamAllocLock::IsHeld()); |
|
1021 |
||
1022 |
// update page infos... |
|
1023 |
TPhysAddr* pages = aPages; |
|
1024 |
TPhysAddr* pagesEnd = pages+aCount; |
|
1025 |
MmuLock::Lock(); |
|
1026 |
TUint flash = 0; |
|
1027 |
while(pages<pagesEnd) |
|
1028 |
{ |
|
1029 |
MmuLock::Flash(flash,KMaxPageInfoUpdatesInOneGo/2); |
|
1030 |
TPhysAddr pagePhys = *pages++; |
|
1031 |
__NK_ASSERT_DEBUG(pagePhys!=KPhysAddrInvalid); |
|
1032 |
SPageInfo* pi = SPageInfo::FromPhysAddr(pagePhys); |
|
1033 |
__ASSERT_ALWAYS(pi->Type()==SPageInfo::EPhysAlloc, Panic(EBadFreePhysicalRam)); |
|
1034 |
__ASSERT_ALWAYS(!pi->UseCount(), Panic(EBadFreePhysicalRam)); |
|
1035 |
pi->SetUnused(); |
|
1036 |
} |
|
1037 |
MmuLock::Unlock(); |
|
1038 |
||
1039 |
iRamPageAllocator->FreeRamPages(aPages,aCount, EPageFixed); |
|
22
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1040 |
|
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1041 |
#ifdef BTRACE_KERNEL_MEMORY |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1042 |
if (BTrace::CheckFilter(BTrace::EKernelMemory)) |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1043 |
{// Only loop round each page if EKernelMemory tracing is enabled |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1044 |
pages = aPages; |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1045 |
pagesEnd = aPages + aCount; |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1046 |
while (pages < pagesEnd) |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1047 |
{ |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1048 |
BTrace8(BTrace::EKernelMemory, BTrace::EKernelMemoryDrvPhysFree, KPageSize, *pages++); |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1049 |
Epoc::DriverAllocdPhysRam -= KPageSize; |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1050 |
} |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1051 |
} |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1052 |
#endif |
0 | 1053 |
} |
1054 |
||
1055 |
||
1056 |
TInt Mmu::AllocPhysicalRam(TPhysAddr& aPhysAddr, TUint aCount, TUint aAlign, TRamAllocFlags aFlags) |
|
1057 |
{ |
|
1058 |
__KTRACE_OPT(KMMU,Kern::Printf("Mmu::AllocPhysicalRam(?,0x%x,d,%x)",aCount,aAlign,aFlags)); |
|
1059 |
TInt r = AllocContiguousRam(aPhysAddr,aCount,aAlign,aFlags); |
|
1060 |
if (r!=KErrNone) |
|
1061 |
return r; |
|
1062 |
||
1063 |
// update page infos... |
|
22
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1064 |
SetAllocPhysRam(aPhysAddr, aCount); |
0 | 1065 |
|
1066 |
return KErrNone; |
|
1067 |
} |
|
1068 |
||
1069 |
||
1070 |
void Mmu::FreePhysicalRam(TPhysAddr aPhysAddr, TUint aCount) |
|
1071 |
{ |
|
1072 |
__KTRACE_OPT(KMMU,Kern::Printf("Mmu::FreePhysicalRam(0x%08x,0x%x)",aPhysAddr,aCount)); |
|
1073 |
||
1074 |
// update page infos... |
|
1075 |
SPageInfo* pi = SPageInfo::FromPhysAddr(aPhysAddr); |
|
1076 |
SPageInfo* piEnd = pi+aCount; |
|
1077 |
TUint flash = 0; |
|
1078 |
MmuLock::Lock(); |
|
1079 |
while(pi<piEnd) |
|
1080 |
{ |
|
1081 |
MmuLock::Flash(flash,KMaxPageInfoUpdatesInOneGo); |
|
1082 |
__ASSERT_ALWAYS(pi->Type()==SPageInfo::EPhysAlloc, Panic(EBadFreePhysicalRam)); |
|
1083 |
__ASSERT_ALWAYS(!pi->UseCount(), Panic(EBadFreePhysicalRam)); |
|
1084 |
pi->SetUnused(); |
|
1085 |
++pi; |
|
1086 |
} |
|
1087 |
MmuLock::Unlock(); |
|
1088 |
||
22
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1089 |
TUint bytes = aCount << KPageShift; |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1090 |
iRamPageAllocator->FreePhysicalRam(aPhysAddr, bytes); |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1091 |
|
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1092 |
#ifdef BTRACE_KERNEL_MEMORY |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1093 |
BTrace8(BTrace::EKernelMemory, BTrace::EKernelMemoryDrvPhysFree, bytes, aPhysAddr); |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1094 |
Epoc::DriverAllocdPhysRam -= bytes; |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1095 |
#endif |
0 | 1096 |
} |
1097 |
||
1098 |
||
1099 |
TInt Mmu::ClaimPhysicalRam(TPhysAddr aPhysAddr, TUint aCount, TRamAllocFlags aFlags) |
|
1100 |
{ |
|
1101 |
__KTRACE_OPT(KMMU,Kern::Printf("Mmu::ClaimPhysicalRam(0x%08x,0x%x,0x%08x)",aPhysAddr,aCount,aFlags)); |
|
1102 |
aPhysAddr &= ~KPageMask; |
|
22
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1103 |
TInt r = iRamPageAllocator->ClaimPhysicalRam(aPhysAddr, aCount << KPageShift); |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1104 |
if(r != KErrNone) |
0 | 1105 |
return r; |
1106 |
||
22
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1107 |
AllocatedPhysicalRam(aPhysAddr, aCount, aFlags); |
0 | 1108 |
return KErrNone; |
1109 |
} |
|
1110 |
||
1111 |
||
1112 |
void Mmu::AllocatedPhysicalRam(TPhysAddr aPhysAddr, TUint aCount, TRamAllocFlags aFlags) |
|
1113 |
{ |
|
1114 |
__KTRACE_OPT(KMMU,Kern::Printf("Mmu::AllocatedPhysicalRam(0x%08x,0x%x,d,%x)",aPhysAddr,aCount,aFlags)); |
|
1115 |
||
1116 |
PagesAllocated((TPhysAddr*)(aPhysAddr|1), aCount, aFlags); |
|
1117 |
||
1118 |
// update page infos... |
|
22
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1119 |
SetAllocPhysRam(aPhysAddr, aCount); |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1120 |
} |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1121 |
|
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1122 |
|
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1123 |
void Mmu::SetAllocPhysRam(TPhysAddr aPhysAddr, TUint aCount) |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1124 |
{ |
0 | 1125 |
SPageInfo* pi = SPageInfo::FromPhysAddr(aPhysAddr); |
1126 |
SPageInfo* piEnd = pi+aCount; |
|
1127 |
TUint flash = 0; |
|
1128 |
MmuLock::Lock(); |
|
1129 |
while(pi<piEnd) |
|
1130 |
{ |
|
22
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1131 |
MmuLock::Flash(flash, KMaxPageInfoUpdatesInOneGo); |
0 | 1132 |
pi->SetPhysAlloc(); |
1133 |
++pi; |
|
1134 |
} |
|
1135 |
MmuLock::Unlock(); |
|
22
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1136 |
|
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1137 |
#ifdef BTRACE_KERNEL_MEMORY |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1138 |
TUint bytes = aCount << KPageShift; |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1139 |
BTrace8(BTrace::EKernelMemory, BTrace::EKernelMemoryDrvPhysAlloc, bytes, aPhysAddr); |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1140 |
Epoc::DriverAllocdPhysRam += bytes; |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1141 |
#endif |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1142 |
} |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1143 |
|
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1144 |
|
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1145 |
void Mmu::SetAllocPhysRam(TPhysAddr* aPageList, TUint aNumPages) |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1146 |
{ |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1147 |
TPhysAddr* page = aPageList; |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1148 |
TPhysAddr* pageEnd = aPageList + aNumPages; |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1149 |
TUint flash = 0; |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1150 |
MmuLock::Lock(); |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1151 |
while (page < pageEnd) |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1152 |
{ |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1153 |
MmuLock::Flash(flash, KMaxPageInfoUpdatesInOneGo / 2); |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1154 |
TPhysAddr pagePhys = *page++; |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1155 |
__NK_ASSERT_DEBUG(pagePhys != KPhysAddrInvalid); |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1156 |
SPageInfo::FromPhysAddr(pagePhys)->SetPhysAlloc(); |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1157 |
} |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1158 |
MmuLock::Unlock(); |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1159 |
|
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1160 |
#ifdef BTRACE_KERNEL_MEMORY |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1161 |
if (BTrace::CheckFilter(BTrace::EKernelMemory)) |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1162 |
{// Only loop round each page if EKernelMemory tracing is enabled |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1163 |
TPhysAddr* pAddr = aPageList; |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1164 |
TPhysAddr* pAddrEnd = aPageList + aNumPages; |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1165 |
while (pAddr < pAddrEnd) |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1166 |
{ |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1167 |
BTrace8(BTrace::EKernelMemory, BTrace::EKernelMemoryDrvPhysAlloc, KPageSize, *pAddr++); |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1168 |
Epoc::DriverAllocdPhysRam += KPageSize; |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1169 |
} |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1170 |
} |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1171 |
#endif |
0 | 1172 |
} |
1173 |
||
1174 |
||
1175 |
// |
|
1176 |
// Misc |
|
1177 |
// |
|
1178 |
||
1179 |
#ifdef _DEBUG |
|
1180 |
/** |
|
1181 |
Perform a page table walk to return the physical address of |
|
1182 |
the memory mapped at virtual address \a aLinAddr in the |
|
1183 |
address space \a aOsAsid. |
|
1184 |
||
1185 |
If the page table used was not one allocated by the kernel |
|
1186 |
then the results are unpredictable and may cause a system fault. |
|
1187 |
||
1188 |
@pre #MmuLock held. |
|
1189 |
*/ |
|
1190 |
TPhysAddr Mmu::LinearToPhysical(TLinAddr aLinAddr, TInt aOsAsid) |
|
1191 |
{ |
|
1192 |
__NK_ASSERT_DEBUG(MmuLock::IsHeld() || K::Initialising); |
|
1193 |
return UncheckedLinearToPhysical(aLinAddr,aOsAsid); |
|
1194 |
} |
|
1195 |
#endif |
|
1196 |
||
1197 |
||
1198 |
/** |
|
1199 |
Next virtual address available for allocation by TTempMapping. |
|
1200 |
This is initialised to #KTempAddr and addresses may be allocated |
|
1201 |
until they reach #KTempAddrEnd. |
|
1202 |
*/ |
|
1203 |
TLinAddr Mmu::TTempMapping::iNextLinAddr = KTempAddr; |
|
1204 |
||
1205 |
||
1206 |
/** |
|
1207 |
Allocate virtual address space required to map a given number of memory pages. |
|
1208 |
||
1209 |
The actual size of allocated virtual allocated needs to accommodate \a aNumPages |
|
1210 |
number of pages of any colour. For example: if \a aNumPages == 4 and #KPageColourCount == 4, |
|
1211 |
then at least 7 pages are required. |
|
1212 |
||
1213 |
@param aNumPages Maximum number of pages that can be mapped into this temporary mapping. |
|
1214 |
||
1215 |
@pre Called in single threaded content (boot) only. |
|
1216 |
||
1217 |
@pre #iNextLinAddr points to virtual page with zero colour. |
|
1218 |
@post #iNextLinAddr points to virtual page with zero colour. |
|
1219 |
*/ |
|
1220 |
void Mmu::TTempMapping::Alloc(TUint aNumPages) |
|
1221 |
{ |
|
1222 |
__NK_ASSERT_DEBUG(aNumPages<=(KTempAddrEnd-KTempAddr)/KPageSize); |
|
1223 |
||
1224 |
// This runs during the boot only (single threaded context) so the access to iNextLinAddr is not guarded by any mutex. |
|
1225 |
TLinAddr tempAddr = iNextLinAddr; |
|
1226 |
TUint numPages = (KPageColourMask+aNumPages+KPageColourMask)&~KPageColourMask; |
|
1227 |
iNextLinAddr = tempAddr+numPages*KPageSize; |
|
1228 |
||
1229 |
__NK_ASSERT_ALWAYS(iNextLinAddr<=KTempAddrEnd); |
|
1230 |
||
1231 |
__NK_ASSERT_DEBUG(iSize==0); |
|
1232 |
iLinAddr = tempAddr; |
|
1233 |
MmuLock::Lock(); |
|
1234 |
iPtePtr = Mmu::PtePtrFromLinAddr(tempAddr,KKernelOsAsid); |
|
1235 |
__NK_ASSERT_DEBUG(iPtePtr); |
|
1236 |
MmuLock::Unlock(); |
|
1237 |
iBlankPte = TheMmu.iTempPteCached; |
|
1238 |
iSize = aNumPages; |
|
1239 |
iCount = 0; |
|
1240 |
||
1241 |
TRACEB(("Mmu::TTempMapping::Alloc(%d) iLinAddr=0x%08x, iPtePtr=0x%08x",aNumPages,iLinAddr,iPtePtr)); |
|
1242 |
} |
|
1243 |
||
1244 |
||
1245 |
/** |
|
1246 |
Map a single physical page into this temporary mapping. |
|
1247 |
||
1248 |
Supervisor read/write access and EMemoryAttributeStandard memory attributes apply. |
|
1249 |
||
1250 |
@param aPage The physical page to map. |
|
1251 |
@param aColour The required colour for the mapping. |
|
1252 |
||
1253 |
@return The linear address at which the page is mapped. |
|
1254 |
*/ |
|
1255 |
TLinAddr Mmu::TTempMapping::Map(TPhysAddr aPage, TUint aColour) |
|
1256 |
{ |
|
1257 |
__NK_ASSERT_DEBUG(iSize>=1); |
|
1258 |
__NK_ASSERT_DEBUG(iCount==0); |
|
1259 |
||
22
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1260 |
return Map(aPage, aColour, iBlankPte); |
0 | 1261 |
} |
1262 |
||
22
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1263 |
|
0 | 1264 |
/** |
1265 |
Map a single physical page into this temporary mapping using the given page table entry (PTE) value. |
|
1266 |
||
1267 |
@param aPage The physical page to map. |
|
1268 |
@param aColour The required colour for the mapping. |
|
1269 |
@param aBlankPte The PTE value to use for mapping the page, |
|
1270 |
with the physical address component equal to zero. |
|
1271 |
||
1272 |
@return The linear address at which the page is mapped. |
|
1273 |
*/ |
|
1274 |
TLinAddr Mmu::TTempMapping::Map(TPhysAddr aPage, TUint aColour, TPte aBlankPte) |
|
1275 |
{ |
|
1276 |
__NK_ASSERT_DEBUG(iSize>=1); |
|
1277 |
__NK_ASSERT_DEBUG(iCount==0); |
|
22
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1278 |
__NK_ASSERT_DEBUG(!(aBlankPte & ~KPageMask)); |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1279 |
|
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1280 |
TUint colour = aColour & KPageColourMask; |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1281 |
TLinAddr addr = iLinAddr + (colour << KPageShift); |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1282 |
TPte* pPte = iPtePtr + colour; |
0 | 1283 |
iColour = colour; |
1284 |
||
22
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1285 |
__ASSERT_DEBUG(*pPte == KPteUnallocatedEntry, MM::Panic(MM::ETempMappingAlreadyInUse)); |
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1286 |
*pPte = (aPage & ~KPageMask) | aBlankPte; |
0 | 1287 |
CacheMaintenance::SinglePteUpdated((TLinAddr)pPte); |
22
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1288 |
InvalidateTLBForPage(addr | KKernelOsAsid); |
0 | 1289 |
|
1290 |
iCount = 1; |
|
1291 |
return addr; |
|
1292 |
} |
|
1293 |
||
1294 |
||
1295 |
/** |
|
1296 |
Map a number of physical pages into this temporary mapping. |
|
1297 |
||
1298 |
Supervisor read/write access and EMemoryAttributeStandard memory attributes apply. |
|
1299 |
||
1300 |
@param aPages The array of physical pages to map. |
|
1301 |
@param aCount The number of pages to map. |
|
1302 |
@param aColour The required colour for the first page. |
|
1303 |
Consecutive pages will be coloured accordingly. |
|
1304 |
||
1305 |
@return The linear address at which the first page is mapped. |
|
1306 |
*/ |
|
1307 |
TLinAddr Mmu::TTempMapping::Map(TPhysAddr* aPages, TUint aCount, TUint aColour) |
|
1308 |
{ |
|
1309 |
__NK_ASSERT_DEBUG(iSize>=aCount); |
|
1310 |
__NK_ASSERT_DEBUG(iCount==0); |
|
1311 |
||
1312 |
TUint colour = aColour&KPageColourMask; |
|
1313 |
TLinAddr addr = iLinAddr+(colour<<KPageShift); |
|
1314 |
TPte* pPte = iPtePtr+colour; |
|
1315 |
iColour = colour; |
|
1316 |
||
1317 |
for(TUint i=0; i<aCount; ++i) |
|
1318 |
{ |
|
1319 |
__ASSERT_DEBUG(pPte[i]==KPteUnallocatedEntry,MM::Panic(MM::ETempMappingAlreadyInUse)); |
|
1320 |
pPte[i] = (aPages[i]&~KPageMask) | iBlankPte; |
|
1321 |
CacheMaintenance::SinglePteUpdated((TLinAddr)&pPte[i]); |
|
1322 |
InvalidateTLBForPage((addr+i*KPageSize)|KKernelOsAsid); |
|
1323 |
} |
|
1324 |
||
1325 |
iCount = aCount; |
|
1326 |
return addr; |
|
1327 |
} |
|
1328 |
||
1329 |
||
1330 |
/** |
|
1331 |
Unmap all pages from this temporary mapping. |
|
1332 |
||
1333 |
@param aIMBRequired True if IMB barrier is required prior unmapping. |
|
1334 |
*/ |
|
1335 |
void Mmu::TTempMapping::Unmap(TBool aIMBRequired) |
|
1336 |
{ |
|
1337 |
__NK_ASSERT_DEBUG(iSize>=1); |
|
1338 |
if(aIMBRequired) |
|
1339 |
CacheMaintenance::CodeChanged(iLinAddr+iColour*KPageSize,iCount*KPageSize); |
|
1340 |
Unmap(); |
|
1341 |
} |
|
1342 |
||
1343 |
||
1344 |
/** |
|
1345 |
Unmap all pages from this temporary mapping. |
|
1346 |
*/ |
|
1347 |
void Mmu::TTempMapping::Unmap() |
|
1348 |
{ |
|
1349 |
__NK_ASSERT_DEBUG(iSize>=1); |
|
1350 |
||
1351 |
TUint colour = iColour; |
|
1352 |
TLinAddr addr = iLinAddr+(colour<<KPageShift); |
|
1353 |
TPte* pPte = iPtePtr+colour; |
|
22
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1354 |
|
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1355 |
while(iCount) |
0 | 1356 |
{ |
1357 |
*pPte = KPteUnallocatedEntry; |
|
1358 |
CacheMaintenance::SinglePteUpdated((TLinAddr)pPte); |
|
1359 |
InvalidateTLBForPage(addr|KKernelOsAsid); |
|
1360 |
addr += KPageSize; |
|
1361 |
++pPte; |
|
22
2f92ad2dc5db
Revision: 201013
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
1362 |
--iCount; |
0 | 1363 |
} |
1364 |
} |
|
1365 |
||
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1366 |
#ifdef __SMP__ |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1367 |
/** |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1368 |
Dummy IPI to be invoked when a thread's alias pde members are updated remotely |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1369 |
by another thread. |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1370 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1371 |
@internalComponent |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1372 |
*/ |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1373 |
class TAliasIPI : public TGenericIPI |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1374 |
{ |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1375 |
public: |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1376 |
static void RefreshIsr(TGenericIPI*); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1377 |
void RefreshAlias(); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1378 |
}; |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1379 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1380 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1381 |
/** |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1382 |
Dummy isr method. |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1383 |
*/ |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1384 |
void TAliasIPI::RefreshIsr(TGenericIPI*) |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1385 |
{ |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1386 |
TRACE2(("TAliasIPI")); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1387 |
} |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1388 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1389 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1390 |
/** |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1391 |
Queue the dummy IPI on all other processors. This ensures that DoProcessSwitch will |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1392 |
have completed updating iAliasPdePtr once this method returns. |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1393 |
*/ |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1394 |
void TAliasIPI::RefreshAlias() |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1395 |
{ |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1396 |
NKern::Lock(); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1397 |
QueueAllOther(&RefreshIsr); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1398 |
NKern::Unlock(); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1399 |
WaitCompletion(); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1400 |
} |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1401 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1402 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1403 |
/** |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1404 |
Perform a dummy ipi on all the other processors to ensure if any of them are |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1405 |
executing DoProcessSwitch they will see the new value of iAliasPde before they |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1406 |
update iAliasPdePtr or will finish updating iAliasPdePtr before we continue. |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1407 |
This works as DoProcessSwitch() has interrupts disabled while reading iAliasPde |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1408 |
and updating iAliasPdePtr. |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1409 |
*/ |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1410 |
void BroadcastAliasRefresh() |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1411 |
{ |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1412 |
TAliasIPI ipi; |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1413 |
ipi.RefreshAlias(); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1414 |
} |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1415 |
#endif //__SMP__ |
0 | 1416 |
|
1417 |
/** |
|
1418 |
Remove any thread IPC aliases which use the specified page table. |
|
1419 |
This is used by the page table allocator when a page table is freed. |
|
1420 |
||
1421 |
@pre #PageTablesLockIsHeld |
|
1422 |
*/ |
|
1423 |
void Mmu::RemoveAliasesForPageTable(TPhysAddr aPageTable) |
|
1424 |
{ |
|
1425 |
__NK_ASSERT_DEBUG(PageTablesLockIsHeld()); |
|
1426 |
||
1427 |
MmuLock::Lock(); |
|
1428 |
||
1429 |
SDblQue checkedList; |
|
1430 |
||
1431 |
TUint ptId = aPageTable>>KPageTableShift; |
|
1432 |
while(!iAliasList.IsEmpty()) |
|
1433 |
{ |
|
1434 |
SDblQueLink* next = iAliasList.First()->Deque(); |
|
1435 |
checkedList.Add(next); |
|
1436 |
DMemModelThread* thread = (DMemModelThread*)((TInt)next-_FOFF(DMemModelThread,iAliasLink)); |
|
1437 |
if((thread->iAliasPde>>KPageTableShift)==ptId) |
|
1438 |
{ |
|
1439 |
// the page table is being aliased by the thread, so remove it... |
|
1440 |
TRACE2(("Thread %O RemoveAliasesForPageTable", this)); |
|
1441 |
thread->iAliasPde = KPdeUnallocatedEntry; |
|
1442 |
#ifdef __SMP__ // we need to also unmap the page table in case thread is running on another core... |
|
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1443 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1444 |
// Ensure other processors see the update to iAliasPde. |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1445 |
BroadcastAliasRefresh(); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1446 |
|
0 | 1447 |
*thread->iAliasPdePtr = KPdeUnallocatedEntry; |
8
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1448 |
|
0 | 1449 |
SinglePdeUpdated(thread->iAliasPdePtr); |
1450 |
__NK_ASSERT_DEBUG((thread->iAliasLinAddr&KPageMask)==0); |
|
1451 |
// Invalidate the tlb for the page using os asid of the process that created the alias |
|
1452 |
// this is safe as the os asid will be valid as thread must be running otherwise the alias |
|
1453 |
// would have been removed. |
|
1454 |
InvalidateTLBForPage(thread->iAliasLinAddr | ((DMemModelProcess*)thread->iOwningProcess)->OsAsid()); |
|
1455 |
// note, race condition with 'thread' updating its iAliasLinAddr is |
|
1456 |
// not a problem because 'thread' will not the be accessing the aliased |
|
1457 |
// region and will take care of invalidating the TLB. |
|
1458 |
#endif |
|
1459 |
} |
|
1460 |
MmuLock::Flash(); |
|
1461 |
} |
|
1462 |
||
1463 |
// copy checkedList back to iAliasList |
|
1464 |
iAliasList.MoveFrom(&checkedList); |
|
1465 |
||
1466 |
MmuLock::Unlock(); |
|
1467 |
} |
|
1468 |
||
1469 |
||
1470 |
void DMemModelThread::RefreshAlias() |
|
1471 |
{ |
|
1472 |
if(iAliasLinAddr) |
|
1473 |
{ |
|
1474 |
TRACE2(("Thread %O RefreshAlias", this)); |
|
1475 |
// Get the os asid, this is the current thread so no need to open a reference. |
|
1476 |
TUint thisAsid = ((DMemModelProcess*)iOwningProcess)->OsAsid(); |
|
1477 |
MmuLock::Lock(); |
|
1478 |
TInt osAsid = iAliasProcess->OsAsid(); |
|
1479 |
TPde pde = *Mmu::PageDirectoryEntry(osAsid,iAliasTarget); |
|
1480 |
iAliasPde = pde; |
|
1481 |
*iAliasPdePtr = pde; |
|
1482 |
SinglePdeUpdated(iAliasPdePtr); |
|
1483 |
InvalidateTLBForPage(iAliasLinAddr|thisAsid); |
|
1484 |
MmuLock::Unlock(); |
|
1485 |
} |
|
1486 |
} |
|
1487 |
||
1488 |
||
1489 |
||
1490 |
// |
|
1491 |
// Mapping/unmapping functions |
|
1492 |
// |
|
1493 |
||
1494 |
||
1495 |
/** |
|
1496 |
Modify page table entries (PTEs) so they map the given memory pages. |
|
1497 |
Entries are only updated if the current state of the corresponding page |
|
1498 |
is RPageArray::ECommitted. |
|
1499 |
||
1500 |
@param aPtePtr Pointer into a page table for the PTE of the first page. |
|
1501 |
@param aCount The number of pages to modify. |
|
1502 |
@param aPages Pointer to the entry for the first page in a memory object's #RPageArray. |
|
1503 |
Each entry contains the physical address of a page together with its |
|
1504 |
current state (RPageArray::TState). |
|
1505 |
@param aBlankPte The value to use for each PTE, with the physical address component equal |
|
1506 |
to zero. |
|
1507 |
||
1508 |
@return False, if the page table no longer maps any entries and may be freed. |
|
1509 |
True otherwise, to indicate that the page table is still needed. |
|
1510 |
||
1511 |
@pre #MmuLock held. |
|
1512 |
@post #MmuLock held and has not been released by this function. |
|
1513 |
*/ |
|
1514 |
TBool Mmu::MapPages(TPte* const aPtePtr, const TUint aCount, TPhysAddr* aPages, TPte aBlankPte) |
|
1515 |
{ |
|
1516 |
__NK_ASSERT_DEBUG(MmuLock::IsHeld()); |
|
1517 |
__NK_ASSERT_DEBUG(aCount); |
|
1518 |
__NK_ASSERT_DEBUG(aBlankPte!=KPteUnallocatedEntry); |
|
1519 |
||
1520 |
TUint count = 0; |
|
1521 |
if(aCount==1) |
|
1522 |
{ |
|
1523 |
// get page to map... |
|
1524 |
TPhysAddr pagePhys = *aPages; |
|
1525 |
TPte pte = *aPtePtr; |
|
1526 |
if(!RPageArray::TargetStateIsCommitted(pagePhys)) |
|
1527 |
goto done; // page no longer needs mapping |
|
1528 |
||
1529 |
// clear type flags... |
|
1530 |
pagePhys &= ~KPageMask; |
|
1531 |
||
1532 |
// check nobody has already mapped the page... |
|
1533 |
if(pte!=KPteUnallocatedEntry) |
|
1534 |
{ |
|
1535 |
// already mapped... |
|
1536 |
#ifdef _DEBUG |
|
1537 |
if((pte^pagePhys)>=TPte(KPageSize)) |
|
1538 |
{ |
|
1539 |
// but different! |
|
1540 |
Kern::Printf("Mmu::MapPages already mapped %x->%x",pagePhys,pte); |
|
1541 |
__NK_ASSERT_DEBUG(0); |
|
1542 |
} |
|
1543 |
#endif |
|
1544 |
return true; // return true to keep page table (it already had at least page mapped) |
|
1545 |
} |
|
1546 |
||
1547 |
// map page... |
|
1548 |
pte = pagePhys|aBlankPte; |
|
1549 |
TRACE2(("!PTE %x=%x",aPtePtr,pte)); |
|
1550 |
*aPtePtr = pte; |
|
1551 |
count = 1; |
|
1552 |
||
1553 |
// clean cache... |
|
1554 |
CacheMaintenance::SinglePteUpdated((TLinAddr)aPtePtr); |
|
1555 |
} |
|
1556 |
else |
|
1557 |
{ |
|
1558 |
// check we are only updating a single page table... |
|
1559 |
__NK_ASSERT_DEBUG(((TLinAddr(aPtePtr)^TLinAddr(aPtePtr+aCount-1))>>KPageTableShift)==0); |
|
1560 |
||
1561 |
// map pages... |
|
1562 |
TPte* pPte = aPtePtr; |
|
1563 |
TPte* pPteEnd = aPtePtr+aCount; |
|
1564 |
do |
|
1565 |
{ |
|
1566 |
// map page... |
|
1567 |
TPhysAddr pagePhys = *aPages++; |
|
1568 |
TPte pte = *pPte++; |
|
1569 |
if(RPageArray::TargetStateIsCommitted(pagePhys)) |
|
1570 |
{ |
|
1571 |
// clear type flags... |
|
1572 |
pagePhys &= ~KPageMask; |
|
1573 |
||
1574 |
// page not being freed, so try and map it... |
|
1575 |
if(pte!=KPteUnallocatedEntry) |
|
1576 |
{ |
|
1577 |
// already mapped... |
|
1578 |
#ifdef _DEBUG |
|
1579 |
if((pte^pagePhys)>=TPte(KPageSize)) |
|
1580 |
{ |
|
1581 |
// but different! |
|
1582 |
Kern::Printf("Mmu::MapPages already mapped %x->%x",pagePhys,pte); |
|
1583 |
__NK_ASSERT_DEBUG(0); |
|
1584 |
} |
|
1585 |
#endif |
|
1586 |
} |
|
1587 |
else |
|
1588 |
{ |
|
1589 |
// map page... |
|
1590 |
pte = pagePhys|aBlankPte; |
|
1591 |
TRACE2(("!PTE %x=%x",pPte-1,pte)); |
|
1592 |
pPte[-1] = pte; |
|
1593 |
++count; |
|
1594 |
} |
|
1595 |
} |
|
1596 |
} |
|
1597 |
while(pPte!=pPteEnd); |
|
1598 |
||
1599 |
// clean cache... |
|
1600 |
CacheMaintenance::MultiplePtesUpdated((TLinAddr)aPtePtr,(TLinAddr)pPte-(TLinAddr)aPtePtr); |
|
1601 |
} |
|
1602 |
||
1603 |
done: |
|
1604 |
// update page counts... |
|
1605 |
SPageTableInfo* pti = SPageTableInfo::FromPtPtr(aPtePtr); |
|
1606 |
count = pti->IncPageCount(count); |
|
1607 |
TRACE2(("pt %x page count=%d",TLinAddr(aPtePtr)&~KPageTableMask,pti->PageCount())); |
|
1608 |
__NK_ASSERT_DEBUG(pti->CheckPageCount()); |
|
1609 |
||
1610 |
// see if page table needs freeing... |
|
1611 |
TUint keepPt = count | pti->PermanenceCount(); |
|
1612 |
||
1613 |
__NK_ASSERT_DEBUG(!pti->IsDemandPaged()); // check not demand paged page table |
|
1614 |
||
1615 |
return keepPt; |
|
1616 |
} |
|
1617 |
||
1618 |
||
1619 |
/** |
|
1620 |
Modify page table entries (PTEs) so they map a new page. |
|
1621 |
Entries are only updated if the current state of the corresponding page |
|
1622 |
is RPageArray::ECommitted or RPageArray::EMoving. |
|
1623 |
||
1624 |
@param aPtePtr Pointer into a page table for the PTE of the page. |
|
1625 |
@param aPage Pointer to the entry for the page in a memory object's #RPageArray. |
|
1626 |
The entry contains the physical address of a page together with its |
|
1627 |
current state (RPageArray::TState). |
|
1628 |
@param aBlankPte The value to use for each PTE, with the physical address component equal |
|
1629 |
to zero. |
|
1630 |
||
1631 |
@pre #MmuLock held. |
|
1632 |
@post #MmuLock held and has not been released by this function. |
|
1633 |
*/ |
|
1634 |
void Mmu::RemapPage(TPte* const aPtePtr, TPhysAddr& aPage, TPte aBlankPte) |
|
1635 |
{ |
|
1636 |
__NK_ASSERT_DEBUG(MmuLock::IsHeld()); |
|
1637 |
__NK_ASSERT_DEBUG(aBlankPte!=KPteUnallocatedEntry); |
|
1638 |
||
1639 |
// get page to remap... |
|
1640 |
TPhysAddr pagePhys = aPage; |
|
41
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1641 |
|
0 | 1642 |
// Only remap the page if it is committed or it is being moved and |
1643 |
// no other operation has been performed on the page. |
|
1644 |
if(!RPageArray::TargetStateIsCommitted(pagePhys)) |
|
1645 |
return; // page no longer needs mapping |
|
41
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1646 |
|
0 | 1647 |
// Only remap the page if it is currently mapped, i.e. doesn't have an unallocated pte. |
1648 |
// This will only be true if a new mapping is being added but it hasn't yet updated |
|
1649 |
// all the ptes for the pages that it maps. |
|
1650 |
TPte pte = *aPtePtr; |
|
1651 |
if (pte == KPteUnallocatedEntry) |
|
1652 |
return; |
|
41
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1653 |
|
0 | 1654 |
// clear type flags... |
1655 |
pagePhys &= ~KPageMask; |
|
1656 |
||
41
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1657 |
// Get the SPageInfo of the page to map. Allow pages without SPageInfos to |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1658 |
// be mapped as when freeing a shadow page may need to remap an unpaged ROM |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1659 |
// page which won't have an SPageInfo. |
0 | 1660 |
SPageInfo* pi = SPageInfo::SafeFromPhysAddr(pagePhys); |
1661 |
if (pi) |
|
1662 |
{ |
|
1663 |
SPageInfo::TPagedState pagedState = pi->PagedState(); |
|
1664 |
if (pagedState != SPageInfo::EUnpaged) |
|
1665 |
{ |
|
41
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1666 |
// For paged pages only update the pte if the pte points to the wrong physical |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1667 |
// address or the page is pinned. |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1668 |
if (pagedState != SPageInfo::EPagedPinned) |
0 | 1669 |
{ |
41
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1670 |
if ((pte^pagePhys) < TPte(KPageSize)) |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1671 |
return; |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1672 |
if (Mmu::IsPteInaccessible(pte)) |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1673 |
{ |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1674 |
// Updating this pte shouldn't be necessary but it stops random data |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1675 |
// corruption in stressed cases??? |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1676 |
Mmu::MakePteInaccessible(aBlankPte, EFalse); |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1677 |
} |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1678 |
else if (!pi->IsDirty()) |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1679 |
{ |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1680 |
// Ensure that the page is mapped as read only to prevent pages being writable |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1681 |
// without having been marked dirty. |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1682 |
Mmu::MakePteInaccessible(aBlankPte, ETrue); |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1683 |
} |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1684 |
} |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1685 |
else if (!pi->IsDirty()) |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1686 |
{ |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1687 |
// Ensure that the page is mapped as read only to prevent pages being writable |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1688 |
// without having been marked dirty. |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1689 |
Mmu::MakePteInaccessible(aBlankPte, ETrue); |
0 | 1690 |
} |
1691 |
} |
|
1692 |
} |
|
41
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1693 |
|
0 | 1694 |
// Map the page in the page array entry as this is always the physical |
1695 |
// page that the memory object's page should be mapped to. |
|
1696 |
pte = pagePhys|aBlankPte; |
|
1697 |
TRACE2(("!PTE %x=%x",aPtePtr,pte)); |
|
1698 |
*aPtePtr = pte; |
|
41
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1699 |
|
0 | 1700 |
// clean cache... |
1701 |
CacheMaintenance::SinglePteUpdated((TLinAddr)aPtePtr); |
|
1702 |
} |
|
1703 |
||
1704 |
||
1705 |
/** |
|
1706 |
Modify page table entries (PTEs) so they no longer map any memory pages. |
|
1707 |
||
1708 |
@param aPtePtr Pointer into a page table for the PTE of the first page. |
|
1709 |
@param aCount The number of pages to modify. |
|
1710 |
||
1711 |
@return False, if the page table no longer maps any entries and may be freed. |
|
1712 |
True otherwise, to indicate that the page table is still needed. |
|
1713 |
||
1714 |
@pre #MmuLock held. |
|
1715 |
@post #MmuLock held and has not been released by this function. |
|
1716 |
*/ |
|
1717 |
TBool Mmu::UnmapPages(TPte* const aPtePtr, TUint aCount) |
|
1718 |
{ |
|
1719 |
__NK_ASSERT_DEBUG(MmuLock::IsHeld()); |
|
1720 |
__NK_ASSERT_DEBUG(aCount); |
|
1721 |
||
1722 |
TUint count = 0; |
|
1723 |
if(aCount==1) |
|
1724 |
{ |
|
1725 |
if(*aPtePtr==KPteUnallocatedEntry) |
|
1726 |
return true; // page already unmapped |
|
1727 |
||
1728 |
// unmap page... |
|
1729 |
++count; |
|
1730 |
TPte pte = KPteUnallocatedEntry; |
|
1731 |
TRACE2(("!PTE %x=%x",aPtePtr,pte)); |
|
1732 |
*aPtePtr = pte; |
|
1733 |
||
1734 |
// clean cache... |
|
1735 |
CacheMaintenance::SinglePteUpdated((TLinAddr)aPtePtr); |
|
1736 |
} |
|
1737 |
else |
|
1738 |
{ |
|
1739 |
// check we are only updating a single page table... |
|
1740 |
__NK_ASSERT_DEBUG(((TLinAddr(aPtePtr)^TLinAddr(aPtePtr+aCount-1))>>KPageTableShift)==0); |
|
1741 |
||
1742 |
// unmap pages... |
|
1743 |
TPte* pPte = aPtePtr; |
|
1744 |
TPte* pPteEnd = aPtePtr+aCount; |
|
1745 |
do |
|
1746 |
{ |
|
1747 |
if(*pPte!=KPteUnallocatedEntry) |
|
1748 |
{ |
|
1749 |
// unmap page... |
|
1750 |
++count; |
|
1751 |
TPte pte = KPteUnallocatedEntry; |
|
1752 |
TRACE2(("!PTE %x=%x",pPte,pte)); |
|
1753 |
*pPte = pte; |
|
1754 |
} |
|
1755 |
} |
|
1756 |
while(++pPte<pPteEnd); |
|
1757 |
||
1758 |
if(!count) |
|
1759 |
return true; // no PTEs changed, so nothing more to do |
|
1760 |
||
1761 |
// clean cache... |
|
1762 |
CacheMaintenance::MultiplePtesUpdated((TLinAddr)aPtePtr,(TLinAddr)pPte-(TLinAddr)aPtePtr); |
|
1763 |
} |
|
1764 |
||
1765 |
// update page table info... |
|
1766 |
SPageTableInfo* pti = SPageTableInfo::FromPtPtr(aPtePtr); |
|
1767 |
count = pti->DecPageCount(count); |
|
1768 |
TRACE2(("pt %x page count=%d",TLinAddr(aPtePtr)&~KPageTableMask,count)); |
|
1769 |
__NK_ASSERT_DEBUG(pti->CheckPageCount()); |
|
1770 |
||
1771 |
// see if page table needs freeing... |
|
1772 |
TUint keepPt = count | pti->PermanenceCount(); |
|
1773 |
||
1774 |
return keepPt; |
|
1775 |
} |
|
1776 |
||
1777 |
||
1778 |
/** |
|
1779 |
Modify page table entries (PTEs) so they no longer map the given memory pages. |
|
1780 |
Entries are only updated if the current state of the corresponding page |
|
1781 |
is 'decommitted' i.e. RPageArray::TargetStateIsDecommitted returns true. |
|
1782 |
||
1783 |
@param aPtePtr Pointer into a page table for the PTE of the first page. |
|
1784 |
@param aCount The number of pages to modify. |
|
1785 |
@param aPages Pointer to the entry for the first page in a memory object's #RPageArray. |
|
1786 |
Each entry contains the physical address of a page together with its |
|
1787 |
current state (RPageArray::TState). |
|
1788 |
||
1789 |
@return False, if the page table no longer maps any entries and may be freed. |
|
1790 |
True otherwise, to indicate that the page table is still needed. |
|
1791 |
||
1792 |
@pre #MmuLock held. |
|
1793 |
@post #MmuLock held and has not been released by this function. |
|
1794 |
*/ |
|
1795 |
TBool Mmu::UnmapPages(TPte* const aPtePtr, TUint aCount, TPhysAddr* aPages) |
|
1796 |
{ |
|
1797 |
__NK_ASSERT_DEBUG(MmuLock::IsHeld()); |
|
1798 |
__NK_ASSERT_DEBUG(aCount); |
|
1799 |
||
1800 |
TUint count = 0; |
|
1801 |
if(aCount==1) |
|
1802 |
{ |
|
1803 |
if(*aPtePtr==KPteUnallocatedEntry) |
|
1804 |
return true; // page already unmapped |
|
1805 |
||
1806 |
if(!RPageArray::TargetStateIsDecommitted(*aPages)) |
|
1807 |
return true; // page has been reallocated |
|
1808 |
||
1809 |
// unmap page... |
|
1810 |
++count; |
|
1811 |
TPte pte = KPteUnallocatedEntry; |
|
1812 |
TRACE2(("!PTE %x=%x",aPtePtr,pte)); |
|
1813 |
*aPtePtr = pte; |
|
1814 |
||
1815 |
// clean cache... |
|
1816 |
CacheMaintenance::SinglePteUpdated((TLinAddr)aPtePtr); |
|
1817 |
} |
|
1818 |
else |
|
1819 |
{ |
|
1820 |
// check we are only updating a single page table... |
|
1821 |
__NK_ASSERT_DEBUG(((TLinAddr(aPtePtr)^TLinAddr(aPtePtr+aCount-1))>>KPageTableShift)==0); |
|
1822 |
||
1823 |
// unmap pages... |
|
1824 |
TPte* pPte = aPtePtr; |
|
1825 |
TPte* pPteEnd = aPtePtr+aCount; |
|
1826 |
do |
|
1827 |
{ |
|
1828 |
if(RPageArray::TargetStateIsDecommitted(*aPages++) && *pPte!=KPteUnallocatedEntry) |
|
1829 |
{ |
|
1830 |
// unmap page... |
|
1831 |
++count; |
|
1832 |
TPte pte = KPteUnallocatedEntry; |
|
1833 |
TRACE2(("!PTE %x=%x",pPte,pte)); |
|
1834 |
*pPte = pte; |
|
1835 |
} |
|
1836 |
} |
|
1837 |
while(++pPte<pPteEnd); |
|
1838 |
||
1839 |
if(!count) |
|
1840 |
return true; // no PTEs changed, so nothing more to do |
|
1841 |
||
1842 |
// clean cache... |
|
1843 |
CacheMaintenance::MultiplePtesUpdated((TLinAddr)aPtePtr,(TLinAddr)pPte-(TLinAddr)aPtePtr); |
|
1844 |
} |
|
1845 |
||
1846 |
// update page table info... |
|
1847 |
SPageTableInfo* pti = SPageTableInfo::FromPtPtr(aPtePtr); |
|
1848 |
count = pti->DecPageCount(count); |
|
1849 |
TRACE2(("pt %x page count=%d",TLinAddr(aPtePtr)&~KPageTableMask,count)); |
|
1850 |
__NK_ASSERT_DEBUG(pti->CheckPageCount()); |
|
1851 |
||
1852 |
// see if page table needs freeing... |
|
1853 |
TUint keepPt = count | pti->PermanenceCount(); |
|
1854 |
||
1855 |
return keepPt; |
|
1856 |
} |
|
1857 |
||
1858 |
||
1859 |
/** |
|
1860 |
Modify page table entries (PTEs) so the given memory pages are not accessible. |
|
1861 |
Entries are only updated if the current state of the corresponding page |
|
1862 |
is RPageArray::ERestrictingNA. |
|
1863 |
||
1864 |
@param aPtePtr Pointer into a page table for the PTE of the first page. |
|
1865 |
@param aCount The number of pages to modify. |
|
1866 |
@param aPages Pointer to the entry for the first page in a memory object's #RPageArray. |
|
1867 |
Each entry contains the physical address of a page together with its |
|
1868 |
current state (RPageArray::TState). |
|
1869 |
||
1870 |
@pre #MmuLock held. |
|
1871 |
@post #MmuLock held and has not been released by this function. |
|
1872 |
*/ |
|
1873 |
void Mmu::RestrictPagesNA(TPte* const aPtePtr, TUint aCount, TPhysAddr* aPages) |
|
1874 |
{ |
|
1875 |
__NK_ASSERT_DEBUG(MmuLock::IsHeld()); |
|
1876 |
__NK_ASSERT_DEBUG(aCount); |
|
1877 |
||
1878 |
if(aCount==1) |
|
1879 |
{ |
|
1880 |
TPhysAddr page = *aPages; |
|
1881 |
TPte pte = *aPtePtr; |
|
1882 |
RPageArray::TState state = RPageArray::State(page); |
|
1883 |
if(state != RPageArray::ERestrictingNA && state != RPageArray::EMoving) |
|
1884 |
return; // page no longer needs restricting |
|
1885 |
||
1886 |
if(pte==KPteUnallocatedEntry) |
|
1887 |
return; // page gone |
|
1888 |
||
1889 |
// restrict page... |
|
1890 |
pte = Mmu::MakePteInaccessible(pte,false); |
|
1891 |
TRACE2(("!PTE %x=%x",aPtePtr,pte)); |
|
1892 |
*aPtePtr = pte; |
|
1893 |
||
1894 |
// clean cache... |
|
1895 |
CacheMaintenance::SinglePteUpdated((TLinAddr)aPtePtr); |
|
1896 |
} |
|
1897 |
else |
|
1898 |
{ |
|
1899 |
// check we are only updating a single page table... |
|
1900 |
__NK_ASSERT_DEBUG(((TLinAddr(aPtePtr)^TLinAddr(aPtePtr+aCount-1))>>KPageTableShift)==0); |
|
1901 |
||
1902 |
// restrict pages... |
|
1903 |
TPte* pPte = aPtePtr; |
|
1904 |
TPte* pPteEnd = aPtePtr+aCount; |
|
1905 |
do |
|
1906 |
{ |
|
1907 |
TPhysAddr page = *aPages++; |
|
1908 |
TPte pte = *pPte++; |
|
1909 |
if(RPageArray::State(page)==RPageArray::ERestrictingNA && pte!=KPteUnallocatedEntry) |
|
1910 |
{ |
|
1911 |
pte = Mmu::MakePteInaccessible(pte,false); |
|
1912 |
TRACE2(("!PTE %x=%x",pPte-1,pte)); |
|
1913 |
pPte[-1] = pte; |
|
1914 |
} |
|
1915 |
} |
|
1916 |
while(pPte<pPteEnd); |
|
1917 |
||
1918 |
// clean cache... |
|
1919 |
CacheMaintenance::MultiplePtesUpdated((TLinAddr)aPtePtr,(TLinAddr)pPte-(TLinAddr)aPtePtr); |
|
1920 |
} |
|
1921 |
} |
|
1922 |
||
1923 |
||
1924 |
/** |
|
1925 |
Modify page table entries (PTEs) so they map the given demand paged memory pages. |
|
1926 |
||
1927 |
Entries are only updated if the current state of the corresponding page |
|
1928 |
is RPageArray::ECommitted. |
|
1929 |
||
1930 |
This function is used for demand paged memory when handling a page fault or |
|
1931 |
memory pinning operation. It will widen the access permission of existing entries |
|
1932 |
if required to match \a aBlankPte and will 'rejuvenate' the page table. |
|
1933 |
||
1934 |
@param aPtePtr Pointer into a page table for the PTE of the first page. |
|
1935 |
@param aCount The number of pages to modify. |
|
1936 |
@param aPages Pointer to the entry for the first page in a memory object's #RPageArray. |
|
1937 |
Each entry contains the physical address of a page together with its |
|
1938 |
current state (RPageArray::TState). |
|
1939 |
@param aBlankPte The value to use for each PTE, with the physical address component equal |
|
1940 |
to zero. |
|
1941 |
||
1942 |
@return False, if the page table no longer maps any entries and may be freed. |
|
1943 |
True otherwise, to indicate that the page table is still needed. |
|
1944 |
||
1945 |
@pre #MmuLock held. |
|
1946 |
@post MmuLock held (but may have been released by this function) |
|
1947 |
*/ |
|
1948 |
TBool Mmu::PageInPages(TPte* const aPtePtr, const TUint aCount, TPhysAddr* aPages, TPte aBlankPte) |
|
1949 |
{ |
|
1950 |
__NK_ASSERT_DEBUG(MmuLock::IsHeld()); |
|
1951 |
__NK_ASSERT_DEBUG(aCount); |
|
1952 |
__NK_ASSERT_DEBUG(aBlankPte!=KPteUnallocatedEntry); |
|
1953 |
||
1954 |
TUint count = 0; |
|
1955 |
||
1956 |
if(aCount==1) |
|
1957 |
{ |
|
1958 |
// get page to map... |
|
1959 |
TPhysAddr page = *aPages; |
|
1960 |
TPte pte = *aPtePtr; |
|
1961 |
if(!RPageArray::TargetStateIsCommitted(page)) |
|
1962 |
goto done; // page no longer needs mapping |
|
1963 |
||
1964 |
#ifdef _DEBUG |
|
1965 |
if(pte!=KPteUnallocatedEntry) |
|
1966 |
{ |
|
1967 |
if ((pte^page)>=TPte(KPageSize) && !Mmu::IsPteInaccessible(pte) && |
|
1968 |
!Mmu::IsPteReadOnly(pte)) |
|
1969 |
{ |
|
1970 |
// Page has been mapped before but the physical address is different |
|
1971 |
// and the page hasn't been moved as it is not inaccessible. |
|
1972 |
Kern::Printf("Mmu::PageInPages already mapped %x->%x",page,pte); |
|
1973 |
__NK_ASSERT_DEBUG(0); |
|
1974 |
} |
|
1975 |
} |
|
1976 |
#endif |
|
1977 |
if(!Mmu::IsPteMoreAccessible(aBlankPte,pte)) |
|
41
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1978 |
{ |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1979 |
__NK_ASSERT_DEBUG((pte^page) < (TUint)KPageSize); // Must be the same physical addr. |
0 | 1980 |
return true; // return true to keep page table (it already had at least page mapped) |
41
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
1981 |
} |
0 | 1982 |
|
1983 |
// remap page with new increased permissions... |
|
1984 |
if(pte==KPteUnallocatedEntry) |
|
1985 |
count = 1; // we'll be adding a new pte entry, count it |
|
1986 |
if(!Mmu::IsPteReadOnly(aBlankPte)) |
|
1987 |
ThePager.SetWritable(*SPageInfo::FromPhysAddr(page)); |
|
1988 |
pte = (page&~KPageMask)|aBlankPte; |
|
1989 |
TRACE2(("!PTE %x=%x",aPtePtr,pte)); |
|
1990 |
*aPtePtr = pte; |
|
1991 |
||
1992 |
// clean cache... |
|
1993 |
CacheMaintenance::SinglePteUpdated((TLinAddr)aPtePtr); |
|
1994 |
} |
|
1995 |
else |
|
1996 |
{ |
|
1997 |
// check we are only updating a single page table... |
|
1998 |
__NK_ASSERT_DEBUG(((TLinAddr(aPtePtr)^TLinAddr(aPtePtr+aCount-1))>>KPageTableShift)==0); |
|
1999 |
||
2000 |
// map pages... |
|
2001 |
TPte* pPte = aPtePtr; |
|
2002 |
TPte* pPteEnd = aPtePtr+aCount; |
|
2003 |
do |
|
2004 |
{ |
|
2005 |
// map page... |
|
2006 |
TPhysAddr page = *aPages++; |
|
2007 |
TPte pte = *pPte++; |
|
2008 |
if(RPageArray::TargetStateIsCommitted(page)) |
|
2009 |
{ |
|
2010 |
#ifdef _DEBUG |
|
2011 |
if(pte!=KPteUnallocatedEntry) |
|
2012 |
{ |
|
2013 |
if ((pte^page)>=TPte(KPageSize) && !Mmu::IsPteInaccessible(pte) && |
|
2014 |
!Mmu::IsPteReadOnly(pte)) |
|
2015 |
{ |
|
2016 |
// Page has been mapped before but the physical address is different |
|
2017 |
// and the page hasn't been moved as it is not inaccessible. |
|
2018 |
Kern::Printf("Mmu::PageInPages already mapped %x->%x",page,pte); |
|
2019 |
__NK_ASSERT_DEBUG(0); |
|
2020 |
} |
|
2021 |
} |
|
2022 |
#endif |
|
2023 |
if(Mmu::IsPteMoreAccessible(aBlankPte,pte)) |
|
2024 |
{ |
|
2025 |
// remap page with new increased permissions... |
|
2026 |
if(pte==KPteUnallocatedEntry) |
|
2027 |
++count; // we'll be adding a new pte entry, count it |
|
2028 |
if(!Mmu::IsPteReadOnly(aBlankPte)) |
|
2029 |
ThePager.SetWritable(*SPageInfo::FromPhysAddr(page)); |
|
2030 |
pte = (page&~KPageMask)|aBlankPte; |
|
2031 |
TRACE2(("!PTE %x=%x",pPte-1,pte)); |
|
2032 |
pPte[-1] = pte; |
|
2033 |
} |
|
41
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
2034 |
else |
0ffb4e86fcc9
Revision: 201027
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
28
diff
changeset
|
2035 |
__NK_ASSERT_DEBUG((pte^page) < (TUint)KPageSize); // Must be the same physical addr. |
0 | 2036 |
} |
2037 |
} |
|
2038 |
while(pPte!=pPteEnd); |
|
2039 |
||
2040 |
// clean cache... |
|
2041 |
CacheMaintenance::MultiplePtesUpdated((TLinAddr)aPtePtr,(TLinAddr)pPte-(TLinAddr)aPtePtr); |
|
2042 |
} |
|
2043 |
||
2044 |
done: |
|
2045 |
// update page counts... |
|
2046 |
SPageTableInfo* pti = SPageTableInfo::FromPtPtr(aPtePtr); |
|
2047 |
count = pti->IncPageCount(count); |
|
2048 |
TRACE2(("pt %x page count=%d",TLinAddr(aPtePtr)&~KPageTableMask,pti->PageCount())); |
|
2049 |
__NK_ASSERT_DEBUG(pti->CheckPageCount()); |
|
2050 |
||
2051 |
// see if page table needs freeing... |
|
2052 |
TUint keepPt = count | pti->PermanenceCount(); |
|
2053 |
||
2054 |
// rejuvenate demand paged page tables... |
|
2055 |
ThePager.RejuvenatePageTable(aPtePtr); |
|
2056 |
||
2057 |
return keepPt; |
|
2058 |
} |
|
2059 |
||
2060 |
||
2061 |
// |
|
2062 |
// CodeModifier |
|
2063 |
// |
|
2064 |
||
2065 |
#ifdef __DEBUGGER_SUPPORT__ |
|
2066 |
||
2067 |
void DoWriteCode(TUint32* aAddress, TUint32 aValue); |
|
2068 |
||
2069 |
#ifdef __SMP__ |
|
2070 |
||
2071 |
extern "C" void __e32_instruction_barrier(); |
|
2072 |
||
2073 |
class TCodeModifierBroadcast : public TGenericIPI |
|
2074 |
{ |
|
2075 |
public: |
|
2076 |
TCodeModifierBroadcast(TUint32* aAddress, TUint32 aValue); |
|
2077 |
static void Isr(TGenericIPI*); |
|
2078 |
void Go(); |
|
2079 |
public: |
|
2080 |
TUint32* iAddress; |
|
2081 |
TUint32 iValue; |
|
2082 |
volatile TInt iFlag; |
|
2083 |
}; |
|
2084 |
||
2085 |
TCodeModifierBroadcast::TCodeModifierBroadcast(TUint32* aAddress, TUint32 aValue) |
|
2086 |
: iAddress(aAddress), iValue(aValue), iFlag(0) |
|
2087 |
{ |
|
2088 |
} |
|
2089 |
||
2090 |
void TCodeModifierBroadcast::Isr(TGenericIPI* aPtr) |
|
2091 |
{ |
|
2092 |
TCodeModifierBroadcast& a = *(TCodeModifierBroadcast*)aPtr; |
|
2093 |
while (!__e32_atomic_load_acq32(&a.iFlag)) |
|
2094 |
__chill(); |
|
2095 |
#ifdef __BROADCAST_CACHE_MAINTENANCE__ |
|
2096 |
CacheMaintenance::CodeChanged((TLinAddr)a.iAddress, sizeof (TInt), CacheMaintenance::ECodeModifier); // need to do separate Clean-D, Purge-I on each core |
|
2097 |
#else |
|
2098 |
__e32_instruction_barrier(); // synchronize instruction execution |
|
2099 |
#endif |
|
2100 |
} |
|
2101 |
||
2102 |
void TCodeModifierBroadcast::Go() |
|
2103 |
{ |
|
2104 |
NKern::Lock(); |
|
2105 |
QueueAllOther(&Isr); |
|
2106 |
WaitEntry(); // wait for other cores to stop |
|
2107 |
DoWriteCode(iAddress, iValue); |
|
2108 |
iFlag = 1; |
|
2109 |
__e32_instruction_barrier(); // synchronize instruction execution |
|
2110 |
WaitCompletion(); // wait for other cores to resume |
|
2111 |
NKern::Unlock(); |
|
2112 |
} |
|
2113 |
#endif |
|
2114 |
||
2115 |
/** |
|
2116 |
@pre Calling thread must be in critical section |
|
2117 |
@pre CodeSeg mutex held |
|
2118 |
*/ |
|
2119 |
TInt CodeModifier::SafeWriteCode(DProcess* aProcess, TLinAddr aAddress, TInt aSize, TUint aValue, void* aOldValue) |
|
2120 |
{ |
|
2121 |
__ASSERT_CRITICAL; |
|
2122 |
Mmu& m=TheMmu; |
|
2123 |
RamAllocLock::Lock(); |
|
2124 |
MmuLock::Lock(); |
|
2125 |
__UNLOCK_GUARD_START(MmuLock); |
|
2126 |
||
2127 |
// Check aProcess is still alive by opening a reference on its os asid. |
|
2128 |
TInt osAsid = ((DMemModelProcess*)aProcess)->TryOpenOsAsid(); |
|
2129 |
if (osAsid < 0) |
|
2130 |
{ |
|
2131 |
__KTRACE_OPT(KDEBUGGER,Kern::Printf("CodeModifier::SafeWriteCode - zombie process")); |
|
2132 |
__UNLOCK_GUARD_END(MmuLock); |
|
2133 |
MmuLock::Unlock(); |
|
2134 |
RamAllocLock::Unlock(); |
|
2135 |
return KErrBadDescriptor; |
|
2136 |
} |
|
2137 |
||
2138 |
// Find physical address of the page, the breakpoint belongs to |
|
2139 |
TPhysAddr physAddr = Mmu::LinearToPhysical(aAddress, osAsid); |
|
2140 |
__KTRACE_OPT(KDEBUGGER,Kern::Printf("CodeModifier::SafeWriteCode - PA:%x", physAddr)); |
|
2141 |
||
2142 |
||
2143 |
if (physAddr==KPhysAddrInvalid) |
|
2144 |
{ |
|
2145 |
__KTRACE_OPT(KDEBUGGER,Kern::Printf("CodeModifier::SafeWriteCode - invalid VA")); |
|
2146 |
__UNLOCK_GUARD_END(MmuLock); |
|
2147 |
MmuLock::Unlock(); |
|
2148 |
RamAllocLock::Unlock(); |
|
2149 |
// The os asid is no longer required. |
|
2150 |
((DMemModelProcess*)aProcess)->CloseOsAsid(); |
|
2151 |
return KErrBadDescriptor; |
|
2152 |
} |
|
2153 |
||
2154 |
// Temporary map physical page |
|
2155 |
TLinAddr tempAddr = m.MapTemp(physAddr&~KPageMask, aAddress>>KPageShift); |
|
2156 |
tempAddr |= aAddress & KPageMask; |
|
2157 |
__KTRACE_OPT(KDEBUGGER,Kern::Printf("CodeModifier::SafeWriteCode - tempAddr:%x",tempAddr)); |
|
2158 |
||
2159 |
TInt r = KErrBadDescriptor; |
|
2160 |
TUint32* ptr = (TUint32*)(tempAddr&~3); |
|
2161 |
TUint32 oldWord; |
|
2162 |
||
2163 |
if(Kern::SafeRead(ptr,&oldWord,sizeof(oldWord))==0 // safely read the original value... |
|
2164 |
&& Kern::SafeWrite(ptr,&oldWord,sizeof(oldWord))==0 ) // and write it back |
|
2165 |
{ |
|
2166 |
// We have successfully probed the memory by reading and writing to it |
|
2167 |
// so we assume it is now safe to access without generating exceptions. |
|
2168 |
// If this is wrong it will kill the system horribly. |
|
2169 |
||
2170 |
TUint32 newWord; |
|
2171 |
TUint badAlign; |
|
2172 |
TUint shift = (aAddress&3)*8; |
|
2173 |
||
2174 |
switch(aSize) |
|
2175 |
{ |
|
2176 |
case 1: // 1 byte value |
|
2177 |
badAlign = 0; |
|
2178 |
*(TUint8*)aOldValue = oldWord>>shift; |
|
2179 |
newWord = (oldWord&~(0xff<<shift)) | ((aValue&0xff)<<shift); |
|
2180 |
break; |
|
2181 |
||
2182 |
case 2: // 2 byte value |
|
2183 |
badAlign = tempAddr&1; |
|
2184 |
if(!badAlign) |
|
2185 |
*(TUint16*)aOldValue = oldWord>>shift; |
|
2186 |
newWord = (oldWord&~(0xffff<<shift)) | ((aValue&0xffff)<<shift); |
|
2187 |
break; |
|
2188 |
||
2189 |
default: // 4 byte value |
|
2190 |
badAlign = tempAddr&3; |
|
2191 |
if(!badAlign) |
|
2192 |
*(TUint32*)aOldValue = oldWord; |
|
2193 |
newWord = aValue; |
|
2194 |
break; |
|
2195 |
} |
|
2196 |
||
2197 |
if(!badAlign) |
|
2198 |
{ |
|
2199 |
// write the new value... |
|
2200 |
#ifdef __SMP__ |
|
2201 |
TCodeModifierBroadcast b(ptr, newWord); |
|
2202 |
b.Go(); |
|
2203 |
#else |
|
2204 |
DoWriteCode(ptr, newWord); |
|
2205 |
#endif |
|
2206 |
r = KErrNone; |
|
2207 |
} |
|
2208 |
} |
|
2209 |
||
2210 |
__UNLOCK_GUARD_END(MmuLock); |
|
2211 |
m.UnmapTemp(); |
|
2212 |
MmuLock::Unlock(); |
|
2213 |
RamAllocLock::Unlock(); |
|
2214 |
// The os asid is no longer required. |
|
2215 |
((DMemModelProcess*)aProcess)->CloseOsAsid(); |
|
2216 |
return r; |
|
2217 |
} |
|
2218 |
||
2219 |
/** |
|
2220 |
@pre Calling thread must be in critical section |
|
2221 |
@pre CodeSeg mutex held |
|
2222 |
*/ |
|
2223 |
void DoWriteCode(TUint32* aAddress, TUint32 aValue) |
|
2224 |
{ |
|
2225 |
// We do not want to be interrupted by e.g. ISR that will run altered code before IMB-Range. |
|
2226 |
// Therefore, copy data and clean/invalidate caches with interrupts disabled. |
|
2227 |
TInt irq = NKern::DisableAllInterrupts(); |
|
2228 |
*aAddress = aValue; |
|
2229 |
CacheMaintenance::CodeChanged((TLinAddr)aAddress, sizeof(TUint32), CacheMaintenance::ECodeModifier); |
|
2230 |
NKern::RestoreInterrupts(irq); |
|
2231 |
} |
|
2232 |
||
2233 |
#endif //__DEBUGGER_SUPPORT__ |
|
2234 |
||
2235 |
||
2236 |
||
2237 |
// |
|
2238 |
// Virtual pinning |
|
2239 |
// |
|
2240 |
||
2241 |
TInt M::CreateVirtualPinObject(TVirtualPinObject*& aPinObject) |
|
2242 |
{ |
|
2243 |
aPinObject = (TVirtualPinObject*)new DVirtualPinMapping; |
|
2244 |
return aPinObject != NULL ? KErrNone : KErrNoMemory; |
|
2245 |
} |
|
2246 |
||
2247 |
TInt M::PinVirtualMemory(TVirtualPinObject* aPinObject, TLinAddr aStart, TUint aSize, DThread* aThread) |
|
2248 |
{ |
|
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2249 |
__ASSERT_CRITICAL; |
0 | 2250 |
TUint offsetInMapping; |
2251 |
TUint mapInstanceCount; |
|
2252 |
DMemoryMapping* mapping = MM::FindMappingInThread( (DMemModelThread*)aThread, |
|
2253 |
aStart, |
|
2254 |
aSize, |
|
2255 |
offsetInMapping, |
|
2256 |
mapInstanceCount); |
|
2257 |
TInt r = KErrBadDescriptor; |
|
2258 |
if (mapping) |
|
2259 |
{ |
|
2260 |
TInt count = ((aStart & KPageMask) + aSize + KPageMask) >> KPageShift; |
|
2261 |
if(mapping->IsPinned()) |
|
2262 |
{ |
|
2263 |
// Mapping for specified virtual address is pinned so we don't need to |
|
2264 |
// do anything. Also, we can't safely pin the memory in this case |
|
2265 |
// anyway, as pinned mappings may move between memory objects |
|
2266 |
r = KErrNone; |
|
2267 |
} |
|
2268 |
else |
|
2269 |
{ |
|
2270 |
MmuLock::Lock(); |
|
2271 |
DMemoryObject* memory = mapping->Memory(); |
|
2272 |
if (mapInstanceCount != mapping->MapInstanceCount() || |
|
2273 |
!memory || !memory->IsDemandPaged()) |
|
2274 |
{ |
|
2275 |
// mapping has been reused, no memory, or it's not paged, so no need to pin... |
|
2276 |
MmuLock::Unlock(); |
|
2277 |
r = KErrNone; |
|
2278 |
} |
|
2279 |
else |
|
2280 |
{ |
|
2281 |
// paged memory needs pinning... |
|
2282 |
// Open a reference on the memory so it doesn't get deleted. |
|
2283 |
memory->Open(); |
|
2284 |
MmuLock::Unlock(); |
|
2285 |
||
2286 |
TUint startInMemory = (offsetInMapping >> KPageShift) + mapping->iStartIndex; |
|
2287 |
r = ((DVirtualPinMapping*)aPinObject)->Pin( memory, startInMemory, count, mapping->Permissions(), |
|
2288 |
mapping, mapInstanceCount); |
|
2289 |
memory->Close(); |
|
2290 |
} |
|
2291 |
} |
|
2292 |
mapping->Close(); |
|
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2293 |
} |
0 | 2294 |
return r; |
2295 |
} |
|
2296 |
||
2297 |
TInt M::CreateAndPinVirtualMemory(TVirtualPinObject*& aPinObject, TLinAddr aStart, TUint aSize) |
|
2298 |
{ |
|
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2299 |
__ASSERT_CRITICAL; |
0 | 2300 |
aPinObject = 0; |
2301 |
TUint offsetInMapping; |
|
2302 |
TUint mapInstanceCount; |
|
2303 |
DMemoryMapping* mapping = MM::FindMappingInThread( (DMemModelThread*)&Kern::CurrentThread(), |
|
2304 |
aStart, |
|
2305 |
aSize, |
|
2306 |
offsetInMapping, |
|
2307 |
mapInstanceCount); |
|
2308 |
TInt r = KErrBadDescriptor; |
|
2309 |
if (mapping) |
|
2310 |
{ |
|
2311 |
TInt count = ((aStart & KPageMask) + aSize + KPageMask) >> KPageShift; |
|
2312 |
if(mapping->IsPinned()) |
|
2313 |
{ |
|
2314 |
// Mapping for specified virtual address is pinned so we don't need to |
|
2315 |
// do anything. Also, we can't safely pin the memory in this case |
|
2316 |
// anyway, as pinned mappings may move between memory objects |
|
2317 |
r = KErrNone; |
|
2318 |
} |
|
2319 |
else |
|
2320 |
{ |
|
2321 |
MmuLock::Lock(); |
|
2322 |
DMemoryObject* memory = mapping->Memory(); |
|
2323 |
if (mapInstanceCount != mapping->MapInstanceCount() || |
|
2324 |
!memory || !memory->IsDemandPaged()) |
|
2325 |
{ |
|
2326 |
// mapping has been reused, no memory, or it's not paged, so no need to pin... |
|
2327 |
MmuLock::Unlock(); |
|
2328 |
r = KErrNone; |
|
2329 |
} |
|
2330 |
else |
|
2331 |
{// The memory is demand paged so create a pin object and pin it. |
|
2332 |
// Open a reference on the memory so it doesn't get deleted. |
|
2333 |
memory->Open(); |
|
2334 |
MmuLock::Unlock(); |
|
2335 |
r = CreateVirtualPinObject(aPinObject); |
|
2336 |
if (r == KErrNone) |
|
2337 |
{ |
|
2338 |
TUint startInMemory = (offsetInMapping >> KPageShift) + mapping->iStartIndex; |
|
2339 |
r = ((DVirtualPinMapping*)aPinObject)->Pin( memory, startInMemory, count, mapping->Permissions(), |
|
2340 |
mapping, mapInstanceCount); |
|
2341 |
if (r != KErrNone) |
|
2342 |
{// Failed to pin the memory so pin object is not required. |
|
2343 |
DestroyVirtualPinObject(aPinObject); |
|
2344 |
} |
|
2345 |
} |
|
2346 |
memory->Close(); |
|
2347 |
} |
|
2348 |
} |
|
2349 |
mapping->Close(); |
|
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2350 |
} |
0 | 2351 |
return r; |
2352 |
} |
|
2353 |
||
2354 |
void M::UnpinVirtualMemory(TVirtualPinObject* aPinObject) |
|
2355 |
{ |
|
2356 |
DVirtualPinMapping* mapping = (DVirtualPinMapping*)aPinObject; |
|
2357 |
if (mapping->IsAttached()) |
|
2358 |
mapping->Unpin(); |
|
2359 |
} |
|
2360 |
||
2361 |
void M::DestroyVirtualPinObject(TVirtualPinObject*& aPinObject) |
|
2362 |
{ |
|
2363 |
DVirtualPinMapping* mapping = (DVirtualPinMapping*)__e32_atomic_swp_ord_ptr(&aPinObject, 0); |
|
2364 |
if (mapping) |
|
2365 |
{ |
|
2366 |
if (mapping->IsAttached()) |
|
2367 |
mapping->Unpin(); |
|
2368 |
mapping->AsyncClose(); |
|
2369 |
} |
|
2370 |
} |
|
2371 |
||
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2372 |
// |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2373 |
// Physical pinning |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2374 |
// |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2375 |
|
0 | 2376 |
TInt M::CreatePhysicalPinObject(TPhysicalPinObject*& aPinObject) |
2377 |
{ |
|
2378 |
aPinObject = (TPhysicalPinObject*)new DPhysicalPinMapping; |
|
2379 |
return aPinObject != NULL ? KErrNone : KErrNoMemory; |
|
2380 |
} |
|
2381 |
||
2382 |
TInt M::PinPhysicalMemory(TPhysicalPinObject* aPinObject, TLinAddr aStart, TUint aSize, TBool aReadOnly, |
|
2383 |
TPhysAddr& aAddress, TPhysAddr* aPages, TUint32& aMapAttr, TUint& aColour, DThread* aThread) |
|
2384 |
{ |
|
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2385 |
__ASSERT_CRITICAL; |
0 | 2386 |
TUint offsetInMapping; |
2387 |
TUint mapInstanceCount; |
|
2388 |
DMemoryMapping* mapping = MM::FindMappingInThread( (DMemModelThread*)aThread, |
|
2389 |
aStart, |
|
2390 |
aSize, |
|
2391 |
offsetInMapping, |
|
2392 |
mapInstanceCount); |
|
2393 |
TInt r = KErrBadDescriptor; |
|
2394 |
if (mapping) |
|
2395 |
{ |
|
2396 |
TInt count = ((aStart & KPageMask) + aSize + KPageMask) >> KPageShift; |
|
2397 |
||
2398 |
MmuLock::Lock(); |
|
2399 |
DMemoryObject* memory = mapping->Memory(); |
|
2400 |
if (mapInstanceCount == mapping->MapInstanceCount() && memory) |
|
2401 |
{ |
|
2402 |
memory->Open(); |
|
2403 |
MmuLock::Unlock(); |
|
2404 |
||
2405 |
TUint startInMemory = (offsetInMapping >> KPageShift) + mapping->iStartIndex; |
|
2406 |
TMappingPermissions permissions = aReadOnly ? ESupervisorReadOnly : ESupervisorReadWrite; |
|
2407 |
r = ((DPhysicalPinMapping*)aPinObject)->Pin(memory, startInMemory, count, permissions); |
|
2408 |
if (r == KErrNone) |
|
2409 |
{ |
|
2410 |
r = ((DPhysicalPinMapping*)aPinObject)->PhysAddr(0, count, aAddress, aPages); |
|
2411 |
if (r>=KErrNone) |
|
2412 |
{ |
|
2413 |
r = KErrNone; //Do not report discontiguous memory in return value. |
|
2414 |
const TMappingAttributes2& mapAttr2 = |
|
2415 |
MM::LegacyMappingAttributes(memory->Attributes(), mapping->Permissions()); |
|
2416 |
*(TMappingAttributes2*)&aMapAttr = mapAttr2; |
|
2417 |
} |
|
2418 |
else |
|
2419 |
UnpinPhysicalMemory(aPinObject); |
|
2420 |
} |
|
2421 |
memory->Close(); |
|
2422 |
} |
|
2423 |
else // mapping has been reused or no memory... |
|
2424 |
{ |
|
2425 |
MmuLock::Unlock(); |
|
2426 |
} |
|
2427 |
mapping->Close(); |
|
2428 |
} |
|
2429 |
aColour = (aStart >>KPageShift) & KPageColourMask; |
|
2430 |
return r; |
|
2431 |
} |
|
2432 |
||
2433 |
void M::UnpinPhysicalMemory(TPhysicalPinObject* aPinObject) |
|
2434 |
{ |
|
2435 |
DPhysicalPinMapping* mapping = (DPhysicalPinMapping*)aPinObject; |
|
2436 |
if (mapping->IsAttached()) |
|
2437 |
mapping->Unpin(); |
|
2438 |
} |
|
2439 |
||
2440 |
void M::DestroyPhysicalPinObject(TPhysicalPinObject*& aPinObject) |
|
2441 |
{ |
|
2442 |
DPhysicalPinMapping* mapping = (DPhysicalPinMapping*)__e32_atomic_swp_ord_ptr(&aPinObject, 0); |
|
2443 |
if (mapping) |
|
2444 |
{ |
|
2445 |
if (mapping->IsAttached()) |
|
2446 |
mapping->Unpin(); |
|
2447 |
mapping->AsyncClose(); |
|
2448 |
} |
|
2449 |
} |
|
2450 |
||
2451 |
||
14
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2452 |
// |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2453 |
// Kernel map and pin. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2454 |
// |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2455 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2456 |
TInt M::CreateKernelMapObject(TKernelMapObject*& aMapObject, TUint aMaxReserveSize) |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2457 |
{ |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2458 |
DKernelPinMapping* pinObject = new DKernelPinMapping(); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2459 |
aMapObject = (TKernelMapObject*) pinObject; |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2460 |
if (pinObject == NULL) |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2461 |
{ |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2462 |
return KErrNoMemory; |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2463 |
} |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2464 |
// Ensure we reserve enough bytes for all possible alignments of the start and |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2465 |
// end of the region to map. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2466 |
TUint reserveBytes = aMaxReserveSize? ((aMaxReserveSize + KPageMask) & ~KPageMask) + KPageSize : 0; |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2467 |
TInt r = pinObject->Construct(reserveBytes); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2468 |
if (r != KErrNone) |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2469 |
{// Failed so delete the kernel mapping object. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2470 |
pinObject->Close(); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2471 |
aMapObject = NULL; |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2472 |
} |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2473 |
return r; |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2474 |
} |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2475 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2476 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2477 |
TInt M::MapAndPinMemory(TKernelMapObject* aMapObject, DThread* aThread, TLinAddr aStart, |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2478 |
TUint aSize, TUint aMapAttributes, TLinAddr& aKernelAddr, TPhysAddr* aPages) |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2479 |
{ |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2480 |
__ASSERT_CRITICAL; |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2481 |
TUint offsetInMapping; |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2482 |
TUint mapInstanceCount; |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2483 |
DMemoryMapping* mapping = MM::FindMappingInThread( (DMemModelThread*)aThread, |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2484 |
aStart, |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2485 |
aSize, |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2486 |
offsetInMapping, |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2487 |
mapInstanceCount); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2488 |
TInt r = KErrBadDescriptor; |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2489 |
if (mapping) |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2490 |
{ |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2491 |
DKernelPinMapping* kernelMap = (DKernelPinMapping*)aMapObject; |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2492 |
TInt count = (((aStart + aSize + KPageMask) & ~KPageMask) - (aStart & ~KPageMask)) >> KPageShift; |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2493 |
if (kernelMap->iReservePages && kernelMap->iReservePages < count) |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2494 |
{ |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2495 |
mapping->Close(); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2496 |
return KErrArgument; |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2497 |
} |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2498 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2499 |
MmuLock::Lock(); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2500 |
DMemoryObject* memory = mapping->Memory(); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2501 |
if (mapInstanceCount == mapping->MapInstanceCount() && memory) |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2502 |
{ |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2503 |
memory->Open(); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2504 |
MmuLock::Unlock(); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2505 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2506 |
TUint startInMemory = (offsetInMapping >> KPageShift) + mapping->iStartIndex; |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2507 |
TBool readOnly = aMapAttributes & Kern::EKernelMap_ReadOnly; |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2508 |
TMappingPermissions permissions = readOnly ? ESupervisorReadOnly : ESupervisorReadWrite; |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2509 |
r = kernelMap->MapAndPin(memory, startInMemory, count, permissions); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2510 |
if (r == KErrNone) |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2511 |
{ |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2512 |
__NK_ASSERT_DEBUG(!kernelMap->IsUserMapping()); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2513 |
aKernelAddr = kernelMap->Base(); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2514 |
TPhysAddr contigAddr; // Ignore this value as aPages will be populated |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2515 |
// whether the memory is contiguous or not. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2516 |
r = kernelMap->PhysAddr(0, count, contigAddr, aPages); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2517 |
if (r>=KErrNone) |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2518 |
{ |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2519 |
r = KErrNone; //Do not report discontiguous memory in return value. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2520 |
} |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2521 |
else |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2522 |
{ |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2523 |
UnmapAndUnpinMemory((TKernelMapObject*)kernelMap); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2524 |
} |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2525 |
} |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2526 |
memory->Close(); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2527 |
} |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2528 |
else // mapping has been reused or no memory... |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2529 |
{ |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2530 |
MmuLock::Unlock(); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2531 |
} |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2532 |
mapping->Close(); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2533 |
} |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2534 |
return r; |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2535 |
} |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2536 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2537 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2538 |
void M::UnmapAndUnpinMemory(TKernelMapObject* aMapObject) |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2539 |
{ |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2540 |
DKernelPinMapping* mapping = (DKernelPinMapping*)aMapObject; |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2541 |
if (mapping->IsAttached()) |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2542 |
mapping->UnmapAndUnpin(); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2543 |
} |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2544 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2545 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2546 |
void M::DestroyKernelMapObject(TKernelMapObject*& aMapObject) |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2547 |
{ |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2548 |
DKernelPinMapping* mapping = (DKernelPinMapping*)__e32_atomic_swp_ord_ptr(&aMapObject, 0); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2549 |
if (mapping) |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2550 |
{ |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2551 |
if (mapping->IsAttached()) |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2552 |
mapping->UnmapAndUnpin(); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2553 |
mapping->AsyncClose(); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2554 |
} |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2555 |
} |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
8
diff
changeset
|
2556 |
|
0 | 2557 |
|
2558 |
// |
|
2559 |
// Cache sync operations |
|
2560 |
// |
|
2561 |
||
2562 |
//@pre As for MASK_THREAD_STANDARD |
|
2563 |
void Mmu::SyncPhysicalMemoryBeforeDmaWrite(TPhysAddr* aPages, TUint aColour, TUint aOffset, TUint aSize, TUint32 aMapAttr) |
|
2564 |
{ |
|
2565 |
//Jump over the pages we do not have to sync |
|
2566 |
aPages += aOffset>>KPageShift; |
|
2567 |
aOffset &=KPageMask; |
|
2568 |
aColour = (aColour + (aOffset>>KPageShift)) & KPageColourMask; |
|
2569 |
||
2570 |
//Calculate page table entry for the temporary mapping. |
|
2571 |
TUint pteType = PteType(ESupervisorReadWrite,true); |
|
2572 |
TMappingAttributes2 mapAttr2(aMapAttr); |
|
2573 |
TPte pte = Mmu::BlankPte((TMemoryAttributes)mapAttr2.Type(), pteType); |
|
2574 |
||
2575 |
while (aSize) //A single pass of loop operates within page boundaries. |
|
2576 |
{ |
|
2577 |
TUint sizeInLoopPass = Min (KPageSize, aOffset+aSize) - aOffset; //The size of the region in this pass. |
|
2578 |
||
2579 |
NKern::ThreadEnterCS(); |
|
2580 |
Kern::MutexWait(*iPhysMemSyncMutex); |
|
2581 |
||
2582 |
TLinAddr linAddr = iPhysMemSyncTemp.Map(*aPages, aColour, pte); |
|
2583 |
CacheMaintenance::MakeCPUChangesVisible(linAddr+aOffset, sizeInLoopPass, aMapAttr, *aPages+aOffset); |
|
2584 |
iPhysMemSyncTemp.Unmap(); |
|
2585 |
||
2586 |
Kern::MutexSignal(*iPhysMemSyncMutex); |
|
2587 |
NKern::ThreadLeaveCS(); |
|
2588 |
||
2589 |
aSize-=sizeInLoopPass; // Remaining bytes to sync |
|
2590 |
aOffset=0; // In all the pages after the first, sync will always start with zero offset. |
|
2591 |
aPages++; // Point to the next page |
|
2592 |
aColour = (aColour+1) & KPageColourMask; |
|
2593 |
} |
|
2594 |
} |
|
2595 |
||
2596 |
//@pre As for MASK_THREAD_STANDARD |
|
2597 |
void Mmu::SyncPhysicalMemoryBeforeDmaRead(TPhysAddr* aPages, TUint aColour, TUint aOffset, TUint aSize, TUint32 aMapAttr) |
|
2598 |
{ |
|
2599 |
//Jump over the pages we do not have to sync |
|
2600 |
aPages += aOffset>>KPageShift; |
|
2601 |
aOffset &=KPageMask; |
|
2602 |
aColour = (aColour + (aOffset>>KPageShift)) & KPageColourMask; |
|
2603 |
||
2604 |
//Calculate page table entry for the temporary mapping. |
|
2605 |
TUint pteType = PteType(ESupervisorReadWrite,true); |
|
2606 |
TMappingAttributes2 mapAttr2(aMapAttr); |
|
2607 |
TPte pte = Mmu::BlankPte((TMemoryAttributes)mapAttr2.Type(), pteType); |
|
2608 |
||
2609 |
while (aSize) //A single pass of loop operates within page boundaries. |
|
2610 |
{ |
|
2611 |
TUint sizeInLoopPass = Min (KPageSize, aOffset+aSize) - aOffset; //The size of the region in this pass. |
|
2612 |
||
2613 |
NKern::ThreadEnterCS(); |
|
2614 |
Kern::MutexWait(*iPhysMemSyncMutex); |
|
2615 |
||
2616 |
TLinAddr linAddr = iPhysMemSyncTemp.Map(*aPages, aColour, pte); |
|
2617 |
CacheMaintenance::PrepareMemoryForExternalWrites(linAddr+aOffset, sizeInLoopPass, aMapAttr, *aPages+aOffset); |
|
2618 |
iPhysMemSyncTemp.Unmap(); |
|
2619 |
||
2620 |
Kern::MutexSignal(*iPhysMemSyncMutex); |
|
2621 |
NKern::ThreadLeaveCS(); |
|
2622 |
||
2623 |
aSize-=sizeInLoopPass; // Remaining bytes to sync |
|
2624 |
aOffset=0; // In all the pages after the first, sync will always start with zero offset. |
|
2625 |
aPages++; // Point to the next page |
|
2626 |
aColour = (aColour+1) & KPageColourMask; |
|
2627 |
} |
|
2628 |
} |
|
2629 |
||
2630 |
//@pre As for MASK_THREAD_STANDARD |
|
2631 |
void Mmu::SyncPhysicalMemoryAfterDmaRead(TPhysAddr* aPages, TUint aColour, TUint aOffset, TUint aSize, TUint32 aMapAttr) |
|
2632 |
{ |
|
2633 |
//Jump over the pages we do not have to sync |
|
2634 |
aPages += aOffset>>KPageShift; |
|
2635 |
aOffset &=KPageMask; |
|
2636 |
aColour = (aColour + (aOffset>>KPageShift)) & KPageColourMask; |
|
2637 |
||
2638 |
//Calculate page table entry for the temporary mapping. |
|
2639 |
TUint pteType = PteType(ESupervisorReadWrite,true); |
|
2640 |
TMappingAttributes2 mapAttr2(aMapAttr); |
|
2641 |
TPte pte = Mmu::BlankPte((TMemoryAttributes)mapAttr2.Type(), pteType); |
|
2642 |
||
2643 |
while (aSize) //A single pass of loop operates within page boundaries. |
|
2644 |
{ |
|
2645 |
TUint sizeInLoopPass = Min (KPageSize, aOffset+aSize) - aOffset; //The size of the region in this pass. |
|
2646 |
||
2647 |
NKern::ThreadEnterCS(); |
|
2648 |
Kern::MutexWait(*iPhysMemSyncMutex); |
|
2649 |
||
2650 |
TLinAddr linAddr = iPhysMemSyncTemp.Map(*aPages, aColour, pte); |
|
2651 |
CacheMaintenance::MakeExternalChangesVisible(linAddr+aOffset, sizeInLoopPass, aMapAttr, *aPages+aOffset); |
|
2652 |
iPhysMemSyncTemp.Unmap(); |
|
2653 |
||
2654 |
Kern::MutexSignal(*iPhysMemSyncMutex); |
|
2655 |
NKern::ThreadLeaveCS(); |
|
2656 |
||
2657 |
aSize-=sizeInLoopPass; // Remaining bytes to sync |
|
2658 |
aOffset=0; // In all the pages after the first, sync will always start with zero offset. |
|
2659 |
aPages++; // Point to the next page |
|
2660 |
aColour = (aColour+1) & KPageColourMask; |
|
2661 |
} |
|
2662 |
} |
|
2663 |
||
2664 |
EXPORT_C TInt Cache::SyncPhysicalMemoryBeforeDmaWrite(TPhysAddr* aPages, TUint aColour, TUint aOffset, TUint aSize, TUint32 aMapAttr) |
|
2665 |
{ |
|
2666 |
CHECK_PRECONDITIONS(MASK_THREAD_STANDARD,"Cache::SyncPhysicalMemoryBeforeDmaWrite"); |
|
2667 |
TheMmu.SyncPhysicalMemoryBeforeDmaWrite(aPages, aColour, aOffset, aSize, aMapAttr); |
|
2668 |
return KErrNone; |
|
2669 |
} |
|
2670 |
||
2671 |
EXPORT_C TInt Cache::SyncPhysicalMemoryBeforeDmaRead(TPhysAddr* aPages, TUint aColour, TUint aOffset, TUint aSize, TUint32 aMapAttr) |
|
2672 |
{ |
|
2673 |
CHECK_PRECONDITIONS(MASK_THREAD_STANDARD,"Cache::SyncPhysicalMemoryBeforeDmaRead"); |
|
2674 |
TheMmu.SyncPhysicalMemoryBeforeDmaRead(aPages, aColour, aOffset, aSize, aMapAttr); |
|
2675 |
return KErrNone; |
|
2676 |
} |
|
2677 |
||
2678 |
EXPORT_C TInt Cache::SyncPhysicalMemoryAfterDmaRead(TPhysAddr* aPages, TUint aColour, TUint aOffset, TUint aSize, TUint32 aMapAttr) |
|
2679 |
{ |
|
2680 |
CHECK_PRECONDITIONS(MASK_THREAD_STANDARD,"Cache::SyncPhysicalMemoryAfterDmaRead"); |
|
2681 |
TheMmu.SyncPhysicalMemoryAfterDmaRead(aPages, aColour, aOffset, aSize, aMapAttr); |
|
2682 |
return KErrNone; |
|
2683 |
} |