author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 21 Jun 2010 17:12:14 +0300 | |
branch | RCL_3 |
changeset 39 | 2bb754abd467 |
parent 36 | bbf8bed59bcb |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 2008-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 |
// Bootstrap Shadow Memory Region Test Driver |
|
15 |
// |
|
16 |
||
17 |
||
18 |
// -- INCLUDES ---------------------------------------------------------------- |
|
19 |
||
20 |
#include "d_trace.h" |
|
21 |
||
36
bbf8bed59bcb
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
22 |
#include <memmodel/epoc/platform.h> |
0 | 23 |
#include <bootdefs.h> |
24 |
#include <kernel/kernboot.h> |
|
25 |
#include <kernel/kern_priv.h> |
|
26 |
#include <platform.h> |
|
27 |
#include <u32hal.h> |
|
28 |
#include "d_smr.h" |
|
29 |
||
30 |
||
31 |
// -- CLASSES ----------------------------------------------------------------- |
|
32 |
||
33 |
||
34 |
class DSMRTestFactory : public DLogicalDevice |
|
35 |
{ |
|
36 |
public: |
|
37 |
virtual TInt Install(); |
|
38 |
virtual void GetCaps(TDes8& aDes) const; |
|
39 |
virtual TInt Create(DLogicalChannelBase*& aChannel); |
|
40 |
}; |
|
41 |
||
42 |
||
43 |
class DSMRTestChannel : public DLogicalChannelBase |
|
44 |
{ |
|
45 |
public: |
|
46 |
DSMRTestChannel(); |
|
47 |
virtual ~DSMRTestChannel(); |
|
48 |
||
49 |
// Inherited from DObject |
|
50 |
virtual TInt RequestUserHandle(DThread* aThread, TOwnerType aType); |
|
51 |
||
52 |
// Inherited from DLogicalChannelBase |
|
53 |
virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer); |
|
54 |
virtual TInt Request(TInt aReqNo, TAny* a1, TAny* a2); |
|
55 |
||
56 |
public: |
|
57 |
static void TestTrace(DSMRTestChannel* aSelf); |
|
58 |
||
59 |
private: |
|
60 |
DThread* iClient; |
|
61 |
||
62 |
}; |
|
63 |
||
64 |
TInt OpenDumpCloseChunk(TUint32 aBase, TUint32 aSize); |
|
65 |
||
66 |
||
67 |
// -- GLOBALS ----------------------------------------------------------------- |
|
68 |
// |
|
69 |
||
70 |
||
71 |
||
72 |
// -- METHODS ----------------------------------------------------------------- |
|
73 |
// |
|
74 |
// TEST FUNCTIONS |
|
75 |
// |
|
76 |
||
77 |
static TInt ECtrlCheckSMRIBPtr() |
|
78 |
{ |
|
79 |
SMR_FUNC("DSMRTestChannel::Request::ECtrlCheckSMRIBPtr"); |
|
80 |
||
81 |
TSuperPage& superPage = Kern::SuperPage(); |
|
82 |
TLinAddr smrib = superPage.iSmrData; |
|
83 |
||
84 |
SMR_TRACE1("SMRIB - Virtual address %x", smrib); |
|
85 |
||
86 |
return smrib; |
|
87 |
} |
|
88 |
||
89 |
static TInt ECtrlPrintSMRIB() |
|
90 |
{ |
|
91 |
SMR_FUNC("DSMRTestChannel::Request::ECtrlPrintSMRIB"); |
|
92 |
||
93 |
TSuperPage& superPage = Kern::SuperPage(); |
|
94 |
TLinAddr smrib = superPage.iSmrData; |
|
95 |
||
96 |
SMR_TRACE1("SMRIB - Virtual address %x", smrib); |
|
97 |
||
98 |
if (smrib == KSuperPageAddressFieldUndefined) |
|
99 |
SMR_LOGMSG_RETURN ("SMRIB Does not exist!", KErrBadHandle); |
|
100 |
||
101 |
SSmrBank* smrPtr = (SSmrBank*)(smrib); |
|
102 |
int x=0; |
|
103 |
while (smrPtr->iBase != 0) |
|
104 |
{ |
|
105 |
SMR_TRACE6("SMRIB entry %d (0x%x): %x, %x, %x, %x", x, smrPtr, smrPtr->iBase, smrPtr->iSize, smrPtr->iPayloadUID, smrPtr->iPayloadFlags); |
|
106 |
x++; |
|
107 |
smrPtr++; |
|
108 |
} |
|
109 |
if (x==0) |
|
110 |
SMR_TRACE0("SMRIB Zero, no valid entries"); |
|
111 |
else |
|
112 |
SMR_TRACE1("SMRIB Contained %d entries", x); |
|
113 |
||
114 |
return x; |
|
115 |
} |
|
116 |
||
117 |
||
118 |
static TInt ECtrlAccessAllSMRs() |
|
119 |
{ |
|
120 |
SMR_FUNC("DSMRTestChannel::Request::ECtrlAccessAllSMRs"); |
|
121 |
||
122 |
TInt err=0; |
|
123 |
TSuperPage& superPage = Kern::SuperPage(); |
|
124 |
TLinAddr smrib = superPage.iSmrData; |
|
125 |
||
126 |
if (smrib == KSuperPageAddressFieldUndefined) |
|
127 |
return KErrBadHandle; |
|
128 |
||
129 |
SSmrBank* smrPtr = (SSmrBank*)(smrib); |
|
130 |
int x=0; |
|
131 |
while (smrPtr->iBase != 0) |
|
132 |
{ |
|
133 |
SMR_TRACE6("SMRIB item %d (0x%x): %x, %x, %x, %x", x, smrPtr, smrPtr->iBase, smrPtr->iSize, smrPtr->iPayloadUID, smrPtr->iPayloadFlags); |
|
134 |
||
135 |
err = OpenDumpCloseChunk(smrPtr->iBase, smrPtr->iSize); |
|
136 |
if (err != KErrNone) |
|
137 |
return err; |
|
138 |
||
139 |
x++; |
|
140 |
smrPtr++; |
|
141 |
} |
|
142 |
if (x==0) |
|
143 |
SMR_TRACE0("SMRIB Zero, no valid entries"); |
|
144 |
else |
|
145 |
SMR_TRACE1("SMRIB Contained %d entries", x); |
|
146 |
||
147 |
return x; |
|
148 |
} |
|
149 |
||
150 |
||
151 |
static TInt ECtrlFreeHalfSMR1PhysicalRam() |
|
152 |
{ |
|
153 |
SMR_FUNC("DSMRTestChannel::Request::ECtrlFreeHalfSMR1PhysicalRam"); |
|
154 |
||
155 |
TInt err=0; |
|
156 |
TSuperPage& superPage = Kern::SuperPage(); |
|
157 |
TLinAddr smrib = superPage.iSmrData; |
|
158 |
||
159 |
||
160 |
if (smrib == KSuperPageAddressFieldUndefined) |
|
161 |
return KErrBadHandle; |
|
162 |
||
163 |
SSmrBank* smrPtr = (SSmrBank*)(smrib); |
|
164 |
int x=0; |
|
165 |
||
166 |
if ((smrPtr->iBase == 0) || (smrPtr->iSize == 0)) |
|
167 |
SMR_LOGMSG_RETURN("SMRIB Does not contain one entry!", 0); |
|
168 |
||
169 |
SMR_TRACE6("SMRIB item before %d (0x%x): %x, %x, %x, %x", x, smrPtr, smrPtr->iBase, smrPtr->iSize, smrPtr->iPayloadUID, smrPtr->iPayloadFlags); |
|
170 |
||
171 |
TInt halfSize = smrPtr->iSize >> 1; |
|
172 |
||
173 |
NKern::ThreadEnterCS(); |
|
174 |
err = Epoc::FreePhysicalRam(smrPtr->iBase+halfSize, halfSize); |
|
175 |
NKern::ThreadLeaveCS(); |
|
176 |
if (err != KErrNone) |
|
177 |
SMR_LOGMSG_RETURN("Epoc::FreePhysicalRam() gave error", err) |
|
178 |
else |
|
179 |
SMR_TRACE0("Success - half of physical ram freed for SMR 1"); |
|
180 |
||
181 |
smrPtr->iSize = halfSize; |
|
182 |
||
183 |
SMR_TRACE6("SMRIB item after %d (0x%x): %x, %x, %x, %x", x, smrPtr, smrPtr->iBase, smrPtr->iSize, smrPtr->iPayloadUID, smrPtr->iPayloadFlags); |
|
184 |
||
185 |
err = OpenDumpCloseChunk(smrPtr->iBase, smrPtr->iSize); |
|
186 |
if (err != KErrNone) |
|
187 |
return err; |
|
188 |
||
189 |
return halfSize; |
|
190 |
} |
|
191 |
||
192 |
||
193 |
static TInt ECtrlFreeAllSMR2PhysicalRam() |
|
194 |
{ |
|
195 |
SMR_FUNC("DSMRTestChannel::Request::ECtrlFreeAllSMR2PhysicalRam"); |
|
196 |
||
197 |
TInt err=0; |
|
198 |
TSuperPage& superPage = Kern::SuperPage(); |
|
199 |
TLinAddr smrib = superPage.iSmrData; |
|
200 |
||
201 |
if (smrib == KSuperPageAddressFieldUndefined) |
|
202 |
return KErrBadHandle; |
|
203 |
||
204 |
SSmrBank* smrPtr = (SSmrBank*)(smrib); |
|
205 |
int x=0; |
|
206 |
||
207 |
if ((smrPtr->iBase == 0) || (smrPtr->iSize == 0)) |
|
208 |
SMR_LOGMSG_RETURN("SMRIB Does not contain first entry!", 0); |
|
209 |
||
210 |
smrPtr++; x++; |
|
211 |
if ((smrPtr->iBase == 0) || (smrPtr->iSize == 0)) |
|
212 |
SMR_LOGMSG_RETURN("SMRIB Does not contain two entries!", 0); |
|
213 |
||
214 |
smrPtr++; x++; |
|
215 |
if ((smrPtr->iBase == 0) || (smrPtr->iSize == 0)) |
|
216 |
SMR_LOGMSG_RETURN("SMRIB Does not contain three entries!", 0); |
|
217 |
||
218 |
SMR_TRACE6("SMRIB item before %d (0x%x): %x, %x, %x, %x", x, smrPtr, smrPtr->iBase, smrPtr->iSize, smrPtr->iPayloadUID, smrPtr->iPayloadFlags); |
|
219 |
TInt sizeToFree = smrPtr->iSize; |
|
220 |
||
221 |
NKern::ThreadEnterCS(); |
|
222 |
err = Epoc::FreePhysicalRam(smrPtr->iBase, sizeToFree); |
|
223 |
NKern::ThreadLeaveCS(); |
|
224 |
if (err != KErrNone) |
|
225 |
SMR_LOGMSG_RETURN("Epoc::FreePhysicalRam() gave error", err) |
|
226 |
else |
|
227 |
SMR_TRACE0("Success - all physical ram freed for SMR 2"); |
|
228 |
||
229 |
||
230 |
smrPtr->iBase = 0; |
|
231 |
smrPtr->iSize = 0; |
|
232 |
smrPtr->iPayloadUID = 0; |
|
233 |
smrPtr->iPayloadFlags = 0; |
|
234 |
||
235 |
SMR_TRACE6("SMRIB item after %d (0x%x): %x, %x, %x, %x", x, smrPtr, smrPtr->iBase, smrPtr->iSize, smrPtr->iPayloadUID, smrPtr->iPayloadFlags); |
|
236 |
return sizeToFree; |
|
237 |
} |
|
238 |
||
239 |
||
240 |
TInt OpenDumpCloseChunk(TUint32 aBase, TUint32 aSize) |
|
241 |
{ |
|
242 |
TInt err; |
|
243 |
TChunkCreateInfo cci; |
|
244 |
DChunk *chunkPtr; |
|
245 |
TLinAddr kernAddr = 0; |
|
246 |
TUint32 mapAttr = 0; |
|
247 |
||
248 |
cci.iType = TChunkCreateInfo::ESharedKernelSingle; |
|
249 |
cci.iMaxSize = 0x800000; |
|
250 |
cci.iMapAttr = EMapAttrCachedMax | EMapAttrSupRw; |
|
251 |
cci.iOwnsMemory = EFalse; |
|
252 |
cci.iDestroyedDfc = 0; |
|
253 |
||
254 |
NKern::ThreadEnterCS(); |
|
255 |
err = Kern::ChunkCreate(cci, chunkPtr, kernAddr, mapAttr); |
|
256 |
NKern::ThreadLeaveCS(); |
|
257 |
if (err != KErrNone) |
|
258 |
SMR_LOGMSG_RETURN("Kern::ChunkCreate() gave error", err); |
|
259 |
||
260 |
NKern::ThreadEnterCS(); |
|
261 |
err = Kern::ChunkCommitPhysical(chunkPtr, 0, aSize, aBase); |
|
262 |
NKern::ThreadLeaveCS(); |
|
263 |
if (err != KErrNone) |
|
264 |
SMR_LOGMSG_RETURN("Kern::ChunkCommitPhysical() gave error", err); |
|
265 |
||
266 |
TUint32* setting = (TUint32*)(kernAddr); |
|
267 |
SMR_TRACE1("SMR Image Memory Dump First Kb @ %08x", setting); |
|
268 |
||
269 |
for (TInt y=0; y < 0x80; y+=16) |
|
270 |
{ |
|
271 |
SMR_TRACE5(" %08x: %08x %08x %08x %08x", setting, setting[0], setting[1], setting[2], setting[3]); |
|
272 |
setting+=4; |
|
273 |
} |
|
274 |
||
275 |
setting = (TUint32*)(kernAddr+aSize-0x80); |
|
276 |
SMR_TRACE1("SMR Image Memory Dump Last Kb @ %08x", setting); |
|
277 |
||
278 |
for (TInt y=0; y < 0x80; y+=16) |
|
279 |
{ |
|
280 |
SMR_TRACE5(" %08x: %08x %08x %08x %08x", setting, setting[0], setting[1], setting[2], setting[3]); |
|
281 |
setting+=4; |
|
282 |
} |
|
283 |
||
284 |
NKern::ThreadEnterCS(); |
|
285 |
TBool chunkRefCntZero = Kern::ChunkClose(chunkPtr); |
|
286 |
NKern::ThreadLeaveCS(); |
|
287 |
if (chunkRefCntZero == 0) |
|
288 |
SMR_LOGMSG_RETURN("Kern::ChunkClose gave false result", KErrGeneral); |
|
289 |
||
290 |
return KErrNone; |
|
291 |
} |
|
292 |
||
293 |
// -- METHODS ----------------------------------------------------------------- |
|
294 |
// |
|
295 |
// DSMRTestFactory |
|
296 |
// |
|
297 |
||
298 |
TInt DSMRTestFactory::Install() |
|
299 |
{ |
|
300 |
SMR_FUNC("DSMRTestFactory::Install"); |
|
301 |
return SetName(&RSMRTest::Name()); |
|
302 |
} |
|
303 |
||
304 |
void DSMRTestFactory::GetCaps(TDes8& aDes) const |
|
305 |
{ |
|
306 |
SMR_FUNC("DSMRTestFactory::GetCaps"); |
|
307 |
Kern::InfoCopy(aDes,0,0); |
|
308 |
} |
|
309 |
||
310 |
TInt DSMRTestFactory::Create(DLogicalChannelBase*& aChannel) |
|
311 |
{ |
|
312 |
SMR_FUNC("DSMRTestFactory::Create"); |
|
313 |
||
314 |
aChannel=new DSMRTestChannel(); |
|
315 |
if(!aChannel) |
|
316 |
return KErrNoMemory; |
|
317 |
return KErrNone; |
|
318 |
} |
|
319 |
||
320 |
||
321 |
// -- METHODS ----------------------------------------------------------------- |
|
322 |
// |
|
323 |
// DSMRTestChannel |
|
324 |
// |
|
325 |
||
326 |
DSMRTestChannel::DSMRTestChannel() |
|
327 |
{ |
|
328 |
SMR_FUNC("DSMRTestChannel"); |
|
329 |
} |
|
330 |
||
331 |
DSMRTestChannel::~DSMRTestChannel() |
|
332 |
{ |
|
333 |
SMR_FUNC("~DSMRTestChannel"); |
|
334 |
} |
|
335 |
||
336 |
TInt DSMRTestChannel::DoCreate(TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& /*aVer*/) |
|
337 |
{ |
|
338 |
SMR_FUNC("DSMRTestChannel::DoCreate"); |
|
339 |
||
340 |
iClient = &Kern::CurrentThread(); |
|
341 |
return KErrNone; |
|
342 |
} |
|
343 |
||
344 |
TInt DSMRTestChannel::RequestUserHandle(DThread* aThread, TOwnerType aType) |
|
345 |
{ |
|
346 |
SMR_FUNC("DSMRTestChannel::RequestUserHandle"); |
|
347 |
||
348 |
if (aType!=EOwnerThread || aThread!=iClient) |
|
349 |
return KErrAccessDenied; |
|
350 |
return KErrNone; |
|
351 |
} |
|
352 |
||
353 |
TInt DSMRTestChannel::Request(TInt aReqNo, TAny* a1, TAny*) |
|
354 |
{ |
|
355 |
SMR_FUNC("DSMRTestChannel::Request"); |
|
356 |
TBool aEnforce = (TBool) a1; |
|
357 |
||
358 |
switch(aReqNo) |
|
359 |
{ |
|
360 |
||
361 |
case RSMRTest::ECtrlCheckSMRIBPtr: |
|
362 |
{ |
|
363 |
TInt rc = ECtrlCheckSMRIBPtr(); |
|
364 |
if (rc < 0) |
|
365 |
return rc; |
|
366 |
if (aEnforce && rc == 0) |
|
367 |
return KErrBadHandle; |
|
368 |
||
369 |
break; // fall through, return KErrNone |
|
370 |
} |
|
371 |
||
372 |
case RSMRTest::ECtrlPrintSMRIB: |
|
373 |
{ |
|
374 |
TInt rc = ECtrlPrintSMRIB(); |
|
375 |
if (rc < 0) |
|
376 |
return rc; |
|
377 |
if (aEnforce && rc == 0) |
|
378 |
return KErrNotFound; |
|
379 |
||
380 |
break; // fall through, return KErrNone |
|
381 |
} |
|
382 |
||
383 |
case RSMRTest::ECtrlAccessAllSMRs: |
|
384 |
{ |
|
385 |
TInt rc = ECtrlAccessAllSMRs(); |
|
386 |
if (rc < 0) |
|
387 |
return rc; |
|
388 |
if (aEnforce && rc == 0) |
|
389 |
return KErrNotFound; |
|
390 |
||
391 |
break; // fall through, return KErrNone |
|
392 |
} |
|
393 |
||
394 |
case RSMRTest::ECtrlFreeHalfSMR1PhysicalRam: |
|
395 |
{ |
|
396 |
TInt rc = ECtrlFreeHalfSMR1PhysicalRam(); |
|
397 |
if (rc < 0) |
|
398 |
return rc; |
|
399 |
if (aEnforce && rc == 0) |
|
400 |
return KErrNotFound; |
|
401 |
||
402 |
break; // fall through, return KErrNone |
|
403 |
} |
|
404 |
||
405 |
case RSMRTest::ECtrlFreeAllSMR2PhysicalRam: |
|
406 |
{ |
|
407 |
||
408 |
TInt rc = ECtrlFreeAllSMR2PhysicalRam(); |
|
409 |
if (rc < 0) |
|
410 |
return rc; |
|
411 |
if (aEnforce && rc == 0) |
|
412 |
return KErrNotFound; |
|
413 |
||
414 |
break; // fall through, return KErrNone |
|
415 |
} |
|
416 |
||
417 |
default: |
|
418 |
return KErrNotSupported; |
|
419 |
} |
|
420 |
||
421 |
return KErrNone; |
|
422 |
} |
|
423 |
||
424 |
||
425 |
// -- GLOBALS ----------------------------------------------------------------- |
|
426 |
||
427 |
||
428 |
DECLARE_STANDARD_LDD() |
|
429 |
{ |
|
430 |
SMR_FUNC("D_SMR_DECLARE_STANDARD_LDD"); |
|
431 |
||
432 |
const TRomHeader& romHdr = Epoc::RomHeader(); |
|
433 |
||
434 |
TInt RHsize = sizeof(TRomHeader); |
|
435 |
SMR_TRACE2("RomHeader - addr %0x; size %d", &romHdr, RHsize); |
|
436 |
||
437 |
TSuperPage& superPage = Kern::SuperPage(); |
|
438 |
TInt SPsize = sizeof(SSuperPageBase); |
|
439 |
||
440 |
TInt startupReason = superPage.iHwStartupReason; |
|
441 |
TLinAddr rootDirList = superPage.iRootDirList; |
|
442 |
||
443 |
SMR_TRACE2("SuperPage - addr %0x; size %d", &superPage, SPsize); |
|
444 |
SMR_TRACE2("SuperPage - StartupReason: %0x; rootDirList %0x", startupReason, rootDirList); |
|
445 |
||
446 |
return new DSMRTestFactory; |
|
447 |
} |
|
448 |