Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Bootstrap Shadow Memory Region Test Driver
18 // -- INCLUDES ----------------------------------------------------------------
22 #include <memmodel\epoc\platform.h>
24 #include <kernel/kernboot.h>
25 #include <kernel/kern_priv.h>
31 // -- CLASSES -----------------------------------------------------------------
34 class DSMRTestFactory : public DLogicalDevice
37 virtual TInt Install();
38 virtual void GetCaps(TDes8& aDes) const;
39 virtual TInt Create(DLogicalChannelBase*& aChannel);
43 class DSMRTestChannel : public DLogicalChannelBase
47 virtual ~DSMRTestChannel();
49 // Inherited from DObject
50 virtual TInt RequestUserHandle(DThread* aThread, TOwnerType aType);
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);
57 static void TestTrace(DSMRTestChannel* aSelf);
64 TInt OpenDumpCloseChunk(TUint32 aBase, TUint32 aSize);
67 // -- GLOBALS -----------------------------------------------------------------
72 // -- METHODS -----------------------------------------------------------------
77 static TInt ECtrlCheckSMRIBPtr()
79 SMR_FUNC("DSMRTestChannel::Request::ECtrlCheckSMRIBPtr");
81 TSuperPage& superPage = Kern::SuperPage();
82 TLinAddr smrib = superPage.iSmrData;
84 SMR_TRACE1("SMRIB - Virtual address %x", smrib);
89 static TInt ECtrlPrintSMRIB()
91 SMR_FUNC("DSMRTestChannel::Request::ECtrlPrintSMRIB");
93 TSuperPage& superPage = Kern::SuperPage();
94 TLinAddr smrib = superPage.iSmrData;
96 SMR_TRACE1("SMRIB - Virtual address %x", smrib);
98 if (smrib == KSuperPageAddressFieldUndefined)
99 SMR_LOGMSG_RETURN ("SMRIB Does not exist!", KErrBadHandle);
101 SSmrBank* smrPtr = (SSmrBank*)(smrib);
103 while (smrPtr->iBase != 0)
105 SMR_TRACE6("SMRIB entry %d (0x%x): %x, %x, %x, %x", x, smrPtr, smrPtr->iBase, smrPtr->iSize, smrPtr->iPayloadUID, smrPtr->iPayloadFlags);
110 SMR_TRACE0("SMRIB Zero, no valid entries");
112 SMR_TRACE1("SMRIB Contained %d entries", x);
118 static TInt ECtrlAccessAllSMRs()
120 SMR_FUNC("DSMRTestChannel::Request::ECtrlAccessAllSMRs");
123 TSuperPage& superPage = Kern::SuperPage();
124 TLinAddr smrib = superPage.iSmrData;
126 if (smrib == KSuperPageAddressFieldUndefined)
127 return KErrBadHandle;
129 SSmrBank* smrPtr = (SSmrBank*)(smrib);
131 while (smrPtr->iBase != 0)
133 SMR_TRACE6("SMRIB item %d (0x%x): %x, %x, %x, %x", x, smrPtr, smrPtr->iBase, smrPtr->iSize, smrPtr->iPayloadUID, smrPtr->iPayloadFlags);
135 err = OpenDumpCloseChunk(smrPtr->iBase, smrPtr->iSize);
143 SMR_TRACE0("SMRIB Zero, no valid entries");
145 SMR_TRACE1("SMRIB Contained %d entries", x);
151 static TInt ECtrlFreeHalfSMR1PhysicalRam()
153 SMR_FUNC("DSMRTestChannel::Request::ECtrlFreeHalfSMR1PhysicalRam");
156 TSuperPage& superPage = Kern::SuperPage();
157 TLinAddr smrib = superPage.iSmrData;
160 if (smrib == KSuperPageAddressFieldUndefined)
161 return KErrBadHandle;
163 SSmrBank* smrPtr = (SSmrBank*)(smrib);
166 if ((smrPtr->iBase == 0) || (smrPtr->iSize == 0))
167 SMR_LOGMSG_RETURN("SMRIB Does not contain one entry!", 0);
169 SMR_TRACE6("SMRIB item before %d (0x%x): %x, %x, %x, %x", x, smrPtr, smrPtr->iBase, smrPtr->iSize, smrPtr->iPayloadUID, smrPtr->iPayloadFlags);
171 TInt halfSize = smrPtr->iSize >> 1;
173 NKern::ThreadEnterCS();
174 err = Epoc::FreePhysicalRam(smrPtr->iBase+halfSize, halfSize);
175 NKern::ThreadLeaveCS();
177 SMR_LOGMSG_RETURN("Epoc::FreePhysicalRam() gave error", err)
179 SMR_TRACE0("Success - half of physical ram freed for SMR 1");
181 smrPtr->iSize = halfSize;
183 SMR_TRACE6("SMRIB item after %d (0x%x): %x, %x, %x, %x", x, smrPtr, smrPtr->iBase, smrPtr->iSize, smrPtr->iPayloadUID, smrPtr->iPayloadFlags);
185 err = OpenDumpCloseChunk(smrPtr->iBase, smrPtr->iSize);
193 static TInt ECtrlFreeAllSMR2PhysicalRam()
195 SMR_FUNC("DSMRTestChannel::Request::ECtrlFreeAllSMR2PhysicalRam");
198 TSuperPage& superPage = Kern::SuperPage();
199 TLinAddr smrib = superPage.iSmrData;
201 if (smrib == KSuperPageAddressFieldUndefined)
202 return KErrBadHandle;
204 SSmrBank* smrPtr = (SSmrBank*)(smrib);
207 if ((smrPtr->iBase == 0) || (smrPtr->iSize == 0))
208 SMR_LOGMSG_RETURN("SMRIB Does not contain first entry!", 0);
211 if ((smrPtr->iBase == 0) || (smrPtr->iSize == 0))
212 SMR_LOGMSG_RETURN("SMRIB Does not contain two entries!", 0);
215 if ((smrPtr->iBase == 0) || (smrPtr->iSize == 0))
216 SMR_LOGMSG_RETURN("SMRIB Does not contain three entries!", 0);
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;
221 NKern::ThreadEnterCS();
222 err = Epoc::FreePhysicalRam(smrPtr->iBase, sizeToFree);
223 NKern::ThreadLeaveCS();
225 SMR_LOGMSG_RETURN("Epoc::FreePhysicalRam() gave error", err)
227 SMR_TRACE0("Success - all physical ram freed for SMR 2");
232 smrPtr->iPayloadUID = 0;
233 smrPtr->iPayloadFlags = 0;
235 SMR_TRACE6("SMRIB item after %d (0x%x): %x, %x, %x, %x", x, smrPtr, smrPtr->iBase, smrPtr->iSize, smrPtr->iPayloadUID, smrPtr->iPayloadFlags);
240 TInt OpenDumpCloseChunk(TUint32 aBase, TUint32 aSize)
243 TChunkCreateInfo cci;
245 TLinAddr kernAddr = 0;
248 cci.iType = TChunkCreateInfo::ESharedKernelSingle;
249 cci.iMaxSize = 0x800000;
250 cci.iMapAttr = EMapAttrCachedMax | EMapAttrSupRw;
251 cci.iOwnsMemory = EFalse;
252 cci.iDestroyedDfc = 0;
254 NKern::ThreadEnterCS();
255 err = Kern::ChunkCreate(cci, chunkPtr, kernAddr, mapAttr);
256 NKern::ThreadLeaveCS();
258 SMR_LOGMSG_RETURN("Kern::ChunkCreate() gave error", err);
260 NKern::ThreadEnterCS();
261 err = Kern::ChunkCommitPhysical(chunkPtr, 0, aSize, aBase);
262 NKern::ThreadLeaveCS();
264 SMR_LOGMSG_RETURN("Kern::ChunkCommitPhysical() gave error", err);
266 TUint32* setting = (TUint32*)(kernAddr);
267 SMR_TRACE1("SMR Image Memory Dump First Kb @ %08x", setting);
269 for (TInt y=0; y < 0x80; y+=16)
271 SMR_TRACE5(" %08x: %08x %08x %08x %08x", setting, setting[0], setting[1], setting[2], setting[3]);
275 setting = (TUint32*)(kernAddr+aSize-0x80);
276 SMR_TRACE1("SMR Image Memory Dump Last Kb @ %08x", setting);
278 for (TInt y=0; y < 0x80; y+=16)
280 SMR_TRACE5(" %08x: %08x %08x %08x %08x", setting, setting[0], setting[1], setting[2], setting[3]);
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);
293 // -- METHODS -----------------------------------------------------------------
298 TInt DSMRTestFactory::Install()
300 SMR_FUNC("DSMRTestFactory::Install");
301 return SetName(&RSMRTest::Name());
304 void DSMRTestFactory::GetCaps(TDes8& aDes) const
306 SMR_FUNC("DSMRTestFactory::GetCaps");
307 Kern::InfoCopy(aDes,0,0);
310 TInt DSMRTestFactory::Create(DLogicalChannelBase*& aChannel)
312 SMR_FUNC("DSMRTestFactory::Create");
314 aChannel=new DSMRTestChannel();
321 // -- METHODS -----------------------------------------------------------------
326 DSMRTestChannel::DSMRTestChannel()
328 SMR_FUNC("DSMRTestChannel");
331 DSMRTestChannel::~DSMRTestChannel()
333 SMR_FUNC("~DSMRTestChannel");
336 TInt DSMRTestChannel::DoCreate(TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& /*aVer*/)
338 SMR_FUNC("DSMRTestChannel::DoCreate");
340 iClient = &Kern::CurrentThread();
344 TInt DSMRTestChannel::RequestUserHandle(DThread* aThread, TOwnerType aType)
346 SMR_FUNC("DSMRTestChannel::RequestUserHandle");
348 if (aType!=EOwnerThread || aThread!=iClient)
349 return KErrAccessDenied;
353 TInt DSMRTestChannel::Request(TInt aReqNo, TAny* a1, TAny*)
355 SMR_FUNC("DSMRTestChannel::Request");
356 TBool aEnforce = (TBool) a1;
361 case RSMRTest::ECtrlCheckSMRIBPtr:
363 TInt rc = ECtrlCheckSMRIBPtr();
366 if (aEnforce && rc == 0)
367 return KErrBadHandle;
369 break; // fall through, return KErrNone
372 case RSMRTest::ECtrlPrintSMRIB:
374 TInt rc = ECtrlPrintSMRIB();
377 if (aEnforce && rc == 0)
380 break; // fall through, return KErrNone
383 case RSMRTest::ECtrlAccessAllSMRs:
385 TInt rc = ECtrlAccessAllSMRs();
388 if (aEnforce && rc == 0)
391 break; // fall through, return KErrNone
394 case RSMRTest::ECtrlFreeHalfSMR1PhysicalRam:
396 TInt rc = ECtrlFreeHalfSMR1PhysicalRam();
399 if (aEnforce && rc == 0)
402 break; // fall through, return KErrNone
405 case RSMRTest::ECtrlFreeAllSMR2PhysicalRam:
408 TInt rc = ECtrlFreeAllSMR2PhysicalRam();
411 if (aEnforce && rc == 0)
414 break; // fall through, return KErrNone
418 return KErrNotSupported;
425 // -- GLOBALS -----------------------------------------------------------------
428 DECLARE_STANDARD_LDD()
430 SMR_FUNC("D_SMR_DECLARE_STANDARD_LDD");
432 const TRomHeader& romHdr = Epoc::RomHeader();
434 TInt RHsize = sizeof(TRomHeader);
435 SMR_TRACE2("RomHeader - addr %0x; size %d", &romHdr, RHsize);
437 TSuperPage& superPage = Kern::SuperPage();
438 TInt SPsize = sizeof(SSuperPageBase);
440 TInt startupReason = superPage.iHwStartupReason;
441 TLinAddr rootDirList = superPage.iRootDirList;
443 SMR_TRACE2("SuperPage - addr %0x; size %d", &superPage, SPsize);
444 SMR_TRACE2("SuperPage - StartupReason: %0x; rootDirList %0x", startupReason, rootDirList);
446 return new DSMRTestFactory;