0
|
1 |
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
//
|
|
15 |
|
|
16 |
#include <plat_priv.h>
|
|
17 |
#include "mm.h"
|
|
18 |
#include "mmu.h"
|
|
19 |
|
|
20 |
#include "mmappinglist.h"
|
|
21 |
#include "mmapping.h"
|
|
22 |
|
|
23 |
|
|
24 |
TSpinLock TMappingListBase::iSpinLock(TSpinLock::EOrderGenericIrqHigh3);
|
|
25 |
|
|
26 |
|
|
27 |
//
|
|
28 |
// TMappingList
|
|
29 |
//
|
|
30 |
|
|
31 |
void TMappingList::Add(DMemoryMappingBase* aMapping)
|
|
32 |
{
|
|
33 |
__NK_ASSERT_DEBUG(LockIsHeld());
|
|
34 |
aMapping->iLink.InsertBefore(this);
|
|
35 |
}
|
|
36 |
|
|
37 |
|
|
38 |
void TMappingList::Remove(DMemoryMappingBase* aMapping)
|
|
39 |
{
|
|
40 |
__NK_ASSERT_DEBUG(LockIsHeld());
|
|
41 |
aMapping->iLink.Remove();
|
|
42 |
}
|
|
43 |
|
|
44 |
|
|
45 |
// Utility methods
|
|
46 |
|
|
47 |
void TMappingList::RemapPage(TPhysAddr& aPageArray, TUint aIndex, TBool aInvalidateTLB)
|
|
48 |
{
|
|
49 |
Lock();
|
|
50 |
TMappingListIter iter;
|
|
51 |
DMemoryMappingBase* mapping = iter.Start(*this);
|
|
52 |
while(mapping)
|
|
53 |
{
|
|
54 |
TUint start = aIndex-mapping->iStartIndex;
|
|
55 |
if(start < mapping->iSizeInPages && !mapping->IsPinned())
|
|
56 |
{
|
|
57 |
// remap the page in the mapping...
|
|
58 |
mapping->Open();
|
|
59 |
TUint mapInstanceCount = mapping->MapInstanceCount();
|
|
60 |
Unlock();
|
|
61 |
mapping->RemapPage(aPageArray, aIndex, mapInstanceCount, aInvalidateTLB);
|
|
62 |
mapping->AsyncClose();
|
|
63 |
}
|
|
64 |
else
|
|
65 |
{
|
|
66 |
// the mapping doesn't contain the page or is a pinned mapping and therefore doesn't own
|
|
67 |
// any page tables...
|
|
68 |
Unlock();
|
|
69 |
}
|
|
70 |
Lock();
|
|
71 |
mapping = iter.Next();
|
|
72 |
}
|
|
73 |
iter.Finish();
|
|
74 |
Unlock();
|
|
75 |
}
|
|
76 |
|
|
77 |
|
|
78 |
//
|
|
79 |
// TMappingListIter
|
|
80 |
//
|
|
81 |
|
|
82 |
DMemoryMappingBase* TMappingListIter::Start(TMappingList& aList)
|
|
83 |
{
|
|
84 |
TRACE2(("TMappingListIter::Start"));
|
|
85 |
__NK_ASSERT_DEBUG(LockIsHeld());
|
|
86 |
return Next(&aList);
|
|
87 |
}
|
|
88 |
|
|
89 |
|
|
90 |
void TMappingListIter::Finish()
|
|
91 |
{
|
|
92 |
TRACE2(("TMappingListIter::Finish"));
|
|
93 |
__NK_ASSERT_DEBUG(LockIsHeld());
|
|
94 |
Remove();
|
|
95 |
}
|
|
96 |
|
|
97 |
|
|
98 |
DMemoryMappingBase* TMappingListIter::Next(TMappingListBase* aPrev)
|
|
99 |
{
|
|
100 |
// avoid live-lock by only flashing iSpinLock after a number of attempts greater
|
|
101 |
// than the number of CPU cores, that way each core is guaranteed to make some headway...
|
|
102 |
const TUint KFlashPeriod = KMaxCpus+1;
|
|
103 |
__ASSERT_COMPILE(KFlashPeriod<10); // make sure limit is sensible, if not, will need more complex live-lock avoidance
|
|
104 |
TUint flash = 0;
|
|
105 |
|
|
106 |
TMappingListBase* prev = aPrev;
|
|
107 |
TMappingListBase* next = prev->iNext;
|
|
108 |
for(;;)
|
|
109 |
{
|
|
110 |
TUint type = next->iType;
|
|
111 |
|
|
112 |
// at end of list?
|
|
113 |
if(type==EHead)
|
|
114 |
{
|
|
115 |
// yes, so put iterator back at end...
|
|
116 |
prev->iNext = this;
|
|
117 |
next->iPrev = this;
|
|
118 |
iNext = next;
|
|
119 |
iPrev = prev;
|
|
120 |
// return NULL...
|
|
121 |
TRACE2(("TMappingListIter::Next returns 0"));
|
|
122 |
return 0;
|
|
123 |
}
|
|
124 |
|
|
125 |
// move past next...
|
|
126 |
prev = next;
|
|
127 |
next = next->iNext;
|
|
128 |
|
|
129 |
// have we found a mapping?
|
|
130 |
if(type==ELink)
|
|
131 |
{
|
|
132 |
// yes, so insert iterator after it...
|
|
133 |
prev->iNext = this;
|
|
134 |
next->iPrev = this;
|
|
135 |
iNext = next;
|
|
136 |
iPrev = prev;
|
|
137 |
// return mapping...
|
|
138 |
DMemoryMappingBase* mapping = (DMemoryMappingBase*)((TLinAddr)prev-_FOFF(DMemoryMappingBase,iLink));
|
|
139 |
TRACE2(("TMappingListIter::Next returns 0x%08x",mapping));
|
|
140 |
return mapping;
|
|
141 |
}
|
|
142 |
|
|
143 |
// move on to next...
|
|
144 |
TRACE2(("TMappingListIter::Next skip %d",next->iType));
|
|
145 |
|
|
146 |
// but first see if we need to flash lock...
|
|
147 |
if(++flash>=KFlashPeriod)
|
|
148 |
{
|
|
149 |
// we need to flash the lock, but first put iterator back in list so we don't loose our place...
|
|
150 |
prev->iNext = this;
|
|
151 |
next->iPrev = this;
|
|
152 |
iNext = next;
|
|
153 |
iPrev = prev;
|
|
154 |
// flash lock...
|
|
155 |
__SPIN_FLASH_IRQ(iSpinLock);
|
|
156 |
// remove iterator again...
|
|
157 |
next = iNext;
|
|
158 |
prev = iPrev;
|
|
159 |
prev->iNext = next;
|
|
160 |
next->iPrev = prev;
|
|
161 |
}
|
|
162 |
|
|
163 |
// loop back and try next
|
|
164 |
}
|
|
165 |
}
|
|
166 |
|
|
167 |
|
|
168 |
DMemoryMappingBase* TMappingListIter::Next()
|
|
169 |
{
|
|
170 |
__NK_ASSERT_DEBUG(LockIsHeld());
|
|
171 |
|
|
172 |
TMappingListBase* next = iNext;
|
|
173 |
TMappingListBase* prev = iPrev;
|
|
174 |
TUint type = next->iType;
|
|
175 |
|
|
176 |
// at end of list?
|
|
177 |
if(type==EHead)
|
|
178 |
{
|
|
179 |
// yes, return NULL...
|
|
180 |
TRACE2(("TMappingListIter::Next returns 0"));
|
|
181 |
return 0;
|
|
182 |
}
|
|
183 |
|
|
184 |
// unlink iterator...
|
|
185 |
prev->iNext = next;
|
|
186 |
next->iPrev = prev;
|
|
187 |
|
|
188 |
// have we found a mapping?
|
|
189 |
if(type==ELink)
|
|
190 |
{
|
|
191 |
// yes, so insert iterator after it...
|
|
192 |
prev = next;
|
|
193 |
next = next->iNext;
|
|
194 |
prev->iNext = this;
|
|
195 |
next->iPrev = this;
|
|
196 |
iNext = next;
|
|
197 |
iPrev = prev;
|
|
198 |
// return mapping...
|
|
199 |
DMemoryMappingBase* mapping = (DMemoryMappingBase*)((TLinAddr)prev-_FOFF(DMemoryMappingBase,iLink));
|
|
200 |
TRACE2(("TMappingListIter::Next returns 0x%08x",mapping));
|
|
201 |
return mapping;
|
|
202 |
}
|
|
203 |
|
|
204 |
// handle more complicated situations...
|
|
205 |
return Next(next);
|
|
206 |
}
|
|
207 |
|
|
208 |
|
|
209 |
|