1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/smr/d_smr.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,448 @@
1.4 +// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// Bootstrap Shadow Memory Region Test Driver
1.18 +//
1.19 +
1.20 +
1.21 +// -- INCLUDES ----------------------------------------------------------------
1.22 +
1.23 +#include "d_trace.h"
1.24 +
1.25 +#include <memmodel\epoc\platform.h>
1.26 +#include <bootdefs.h>
1.27 +#include <kernel/kernboot.h>
1.28 +#include <kernel/kern_priv.h>
1.29 +#include <platform.h>
1.30 +#include <u32hal.h>
1.31 +#include "d_smr.h"
1.32 +
1.33 +
1.34 +// -- CLASSES -----------------------------------------------------------------
1.35 +
1.36 +
1.37 +class DSMRTestFactory : public DLogicalDevice
1.38 + {
1.39 +public:
1.40 + virtual TInt Install();
1.41 + virtual void GetCaps(TDes8& aDes) const;
1.42 + virtual TInt Create(DLogicalChannelBase*& aChannel);
1.43 + };
1.44 +
1.45 +
1.46 +class DSMRTestChannel : public DLogicalChannelBase
1.47 + {
1.48 +public:
1.49 + DSMRTestChannel();
1.50 + virtual ~DSMRTestChannel();
1.51 +
1.52 + // Inherited from DObject
1.53 + virtual TInt RequestUserHandle(DThread* aThread, TOwnerType aType);
1.54 +
1.55 + // Inherited from DLogicalChannelBase
1.56 + virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
1.57 + virtual TInt Request(TInt aReqNo, TAny* a1, TAny* a2);
1.58 +
1.59 +public:
1.60 + static void TestTrace(DSMRTestChannel* aSelf);
1.61 +
1.62 +private:
1.63 + DThread* iClient;
1.64 +
1.65 + };
1.66 +
1.67 +TInt OpenDumpCloseChunk(TUint32 aBase, TUint32 aSize);
1.68 +
1.69 +
1.70 +// -- GLOBALS -----------------------------------------------------------------
1.71 +//
1.72 +
1.73 +
1.74 +
1.75 +// -- METHODS -----------------------------------------------------------------
1.76 +//
1.77 +// TEST FUNCTIONS
1.78 +//
1.79 +
1.80 +static TInt ECtrlCheckSMRIBPtr()
1.81 + {
1.82 + SMR_FUNC("DSMRTestChannel::Request::ECtrlCheckSMRIBPtr");
1.83 +
1.84 + TSuperPage& superPage = Kern::SuperPage();
1.85 + TLinAddr smrib = superPage.iSmrData;
1.86 +
1.87 + SMR_TRACE1("SMRIB - Virtual address %x", smrib);
1.88 +
1.89 + return smrib;
1.90 + }
1.91 +
1.92 +static TInt ECtrlPrintSMRIB()
1.93 + {
1.94 + SMR_FUNC("DSMRTestChannel::Request::ECtrlPrintSMRIB");
1.95 +
1.96 + TSuperPage& superPage = Kern::SuperPage();
1.97 + TLinAddr smrib = superPage.iSmrData;
1.98 +
1.99 + SMR_TRACE1("SMRIB - Virtual address %x", smrib);
1.100 +
1.101 + if (smrib == KSuperPageAddressFieldUndefined)
1.102 + SMR_LOGMSG_RETURN ("SMRIB Does not exist!", KErrBadHandle);
1.103 +
1.104 + SSmrBank* smrPtr = (SSmrBank*)(smrib);
1.105 + int x=0;
1.106 + while (smrPtr->iBase != 0)
1.107 + {
1.108 + SMR_TRACE6("SMRIB entry %d (0x%x): %x, %x, %x, %x", x, smrPtr, smrPtr->iBase, smrPtr->iSize, smrPtr->iPayloadUID, smrPtr->iPayloadFlags);
1.109 + x++;
1.110 + smrPtr++;
1.111 + }
1.112 + if (x==0)
1.113 + SMR_TRACE0("SMRIB Zero, no valid entries");
1.114 + else
1.115 + SMR_TRACE1("SMRIB Contained %d entries", x);
1.116 +
1.117 + return x;
1.118 + }
1.119 +
1.120 +
1.121 +static TInt ECtrlAccessAllSMRs()
1.122 + {
1.123 + SMR_FUNC("DSMRTestChannel::Request::ECtrlAccessAllSMRs");
1.124 +
1.125 + TInt err=0;
1.126 + TSuperPage& superPage = Kern::SuperPage();
1.127 + TLinAddr smrib = superPage.iSmrData;
1.128 +
1.129 + if (smrib == KSuperPageAddressFieldUndefined)
1.130 + return KErrBadHandle;
1.131 +
1.132 + SSmrBank* smrPtr = (SSmrBank*)(smrib);
1.133 + int x=0;
1.134 + while (smrPtr->iBase != 0)
1.135 + {
1.136 + SMR_TRACE6("SMRIB item %d (0x%x): %x, %x, %x, %x", x, smrPtr, smrPtr->iBase, smrPtr->iSize, smrPtr->iPayloadUID, smrPtr->iPayloadFlags);
1.137 +
1.138 + err = OpenDumpCloseChunk(smrPtr->iBase, smrPtr->iSize);
1.139 + if (err != KErrNone)
1.140 + return err;
1.141 +
1.142 + x++;
1.143 + smrPtr++;
1.144 + }
1.145 + if (x==0)
1.146 + SMR_TRACE0("SMRIB Zero, no valid entries");
1.147 + else
1.148 + SMR_TRACE1("SMRIB Contained %d entries", x);
1.149 +
1.150 + return x;
1.151 + }
1.152 +
1.153 +
1.154 +static TInt ECtrlFreeHalfSMR1PhysicalRam()
1.155 + {
1.156 + SMR_FUNC("DSMRTestChannel::Request::ECtrlFreeHalfSMR1PhysicalRam");
1.157 +
1.158 + TInt err=0;
1.159 + TSuperPage& superPage = Kern::SuperPage();
1.160 + TLinAddr smrib = superPage.iSmrData;
1.161 +
1.162 +
1.163 + if (smrib == KSuperPageAddressFieldUndefined)
1.164 + return KErrBadHandle;
1.165 +
1.166 + SSmrBank* smrPtr = (SSmrBank*)(smrib);
1.167 + int x=0;
1.168 +
1.169 + if ((smrPtr->iBase == 0) || (smrPtr->iSize == 0))
1.170 + SMR_LOGMSG_RETURN("SMRIB Does not contain one entry!", 0);
1.171 +
1.172 + SMR_TRACE6("SMRIB item before %d (0x%x): %x, %x, %x, %x", x, smrPtr, smrPtr->iBase, smrPtr->iSize, smrPtr->iPayloadUID, smrPtr->iPayloadFlags);
1.173 +
1.174 + TInt halfSize = smrPtr->iSize >> 1;
1.175 +
1.176 + NKern::ThreadEnterCS();
1.177 + err = Epoc::FreePhysicalRam(smrPtr->iBase+halfSize, halfSize);
1.178 + NKern::ThreadLeaveCS();
1.179 + if (err != KErrNone)
1.180 + SMR_LOGMSG_RETURN("Epoc::FreePhysicalRam() gave error", err)
1.181 + else
1.182 + SMR_TRACE0("Success - half of physical ram freed for SMR 1");
1.183 +
1.184 + smrPtr->iSize = halfSize;
1.185 +
1.186 + SMR_TRACE6("SMRIB item after %d (0x%x): %x, %x, %x, %x", x, smrPtr, smrPtr->iBase, smrPtr->iSize, smrPtr->iPayloadUID, smrPtr->iPayloadFlags);
1.187 +
1.188 + err = OpenDumpCloseChunk(smrPtr->iBase, smrPtr->iSize);
1.189 + if (err != KErrNone)
1.190 + return err;
1.191 +
1.192 + return halfSize;
1.193 + }
1.194 +
1.195 +
1.196 +static TInt ECtrlFreeAllSMR2PhysicalRam()
1.197 + {
1.198 + SMR_FUNC("DSMRTestChannel::Request::ECtrlFreeAllSMR2PhysicalRam");
1.199 +
1.200 + TInt err=0;
1.201 + TSuperPage& superPage = Kern::SuperPage();
1.202 + TLinAddr smrib = superPage.iSmrData;
1.203 +
1.204 + if (smrib == KSuperPageAddressFieldUndefined)
1.205 + return KErrBadHandle;
1.206 +
1.207 + SSmrBank* smrPtr = (SSmrBank*)(smrib);
1.208 + int x=0;
1.209 +
1.210 + if ((smrPtr->iBase == 0) || (smrPtr->iSize == 0))
1.211 + SMR_LOGMSG_RETURN("SMRIB Does not contain first entry!", 0);
1.212 +
1.213 + smrPtr++; x++;
1.214 + if ((smrPtr->iBase == 0) || (smrPtr->iSize == 0))
1.215 + SMR_LOGMSG_RETURN("SMRIB Does not contain two entries!", 0);
1.216 +
1.217 + smrPtr++; x++;
1.218 + if ((smrPtr->iBase == 0) || (smrPtr->iSize == 0))
1.219 + SMR_LOGMSG_RETURN("SMRIB Does not contain three entries!", 0);
1.220 +
1.221 + SMR_TRACE6("SMRIB item before %d (0x%x): %x, %x, %x, %x", x, smrPtr, smrPtr->iBase, smrPtr->iSize, smrPtr->iPayloadUID, smrPtr->iPayloadFlags);
1.222 + TInt sizeToFree = smrPtr->iSize;
1.223 +
1.224 + NKern::ThreadEnterCS();
1.225 + err = Epoc::FreePhysicalRam(smrPtr->iBase, sizeToFree);
1.226 + NKern::ThreadLeaveCS();
1.227 + if (err != KErrNone)
1.228 + SMR_LOGMSG_RETURN("Epoc::FreePhysicalRam() gave error", err)
1.229 + else
1.230 + SMR_TRACE0("Success - all physical ram freed for SMR 2");
1.231 +
1.232 +
1.233 + smrPtr->iBase = 0;
1.234 + smrPtr->iSize = 0;
1.235 + smrPtr->iPayloadUID = 0;
1.236 + smrPtr->iPayloadFlags = 0;
1.237 +
1.238 + SMR_TRACE6("SMRIB item after %d (0x%x): %x, %x, %x, %x", x, smrPtr, smrPtr->iBase, smrPtr->iSize, smrPtr->iPayloadUID, smrPtr->iPayloadFlags);
1.239 + return sizeToFree;
1.240 + }
1.241 +
1.242 +
1.243 +TInt OpenDumpCloseChunk(TUint32 aBase, TUint32 aSize)
1.244 + {
1.245 + TInt err;
1.246 + TChunkCreateInfo cci;
1.247 + DChunk *chunkPtr;
1.248 + TLinAddr kernAddr = 0;
1.249 + TUint32 mapAttr = 0;
1.250 +
1.251 + cci.iType = TChunkCreateInfo::ESharedKernelSingle;
1.252 + cci.iMaxSize = 0x800000;
1.253 + cci.iMapAttr = EMapAttrCachedMax | EMapAttrSupRw;
1.254 + cci.iOwnsMemory = EFalse;
1.255 + cci.iDestroyedDfc = 0;
1.256 +
1.257 + NKern::ThreadEnterCS();
1.258 + err = Kern::ChunkCreate(cci, chunkPtr, kernAddr, mapAttr);
1.259 + NKern::ThreadLeaveCS();
1.260 + if (err != KErrNone)
1.261 + SMR_LOGMSG_RETURN("Kern::ChunkCreate() gave error", err);
1.262 +
1.263 + NKern::ThreadEnterCS();
1.264 + err = Kern::ChunkCommitPhysical(chunkPtr, 0, aSize, aBase);
1.265 + NKern::ThreadLeaveCS();
1.266 + if (err != KErrNone)
1.267 + SMR_LOGMSG_RETURN("Kern::ChunkCommitPhysical() gave error", err);
1.268 +
1.269 + TUint32* setting = (TUint32*)(kernAddr);
1.270 + SMR_TRACE1("SMR Image Memory Dump First Kb @ %08x", setting);
1.271 +
1.272 + for (TInt y=0; y < 0x80; y+=16)
1.273 + {
1.274 + SMR_TRACE5(" %08x: %08x %08x %08x %08x", setting, setting[0], setting[1], setting[2], setting[3]);
1.275 + setting+=4;
1.276 + }
1.277 +
1.278 + setting = (TUint32*)(kernAddr+aSize-0x80);
1.279 + SMR_TRACE1("SMR Image Memory Dump Last Kb @ %08x", setting);
1.280 +
1.281 + for (TInt y=0; y < 0x80; y+=16)
1.282 + {
1.283 + SMR_TRACE5(" %08x: %08x %08x %08x %08x", setting, setting[0], setting[1], setting[2], setting[3]);
1.284 + setting+=4;
1.285 + }
1.286 +
1.287 + NKern::ThreadEnterCS();
1.288 + TBool chunkRefCntZero = Kern::ChunkClose(chunkPtr);
1.289 + NKern::ThreadLeaveCS();
1.290 + if (chunkRefCntZero == 0)
1.291 + SMR_LOGMSG_RETURN("Kern::ChunkClose gave false result", KErrGeneral);
1.292 +
1.293 + return KErrNone;
1.294 + }
1.295 +
1.296 +// -- METHODS -----------------------------------------------------------------
1.297 +//
1.298 +// DSMRTestFactory
1.299 +//
1.300 +
1.301 +TInt DSMRTestFactory::Install()
1.302 + {
1.303 + SMR_FUNC("DSMRTestFactory::Install");
1.304 + return SetName(&RSMRTest::Name());
1.305 + }
1.306 +
1.307 +void DSMRTestFactory::GetCaps(TDes8& aDes) const
1.308 + {
1.309 + SMR_FUNC("DSMRTestFactory::GetCaps");
1.310 + Kern::InfoCopy(aDes,0,0);
1.311 + }
1.312 +
1.313 +TInt DSMRTestFactory::Create(DLogicalChannelBase*& aChannel)
1.314 + {
1.315 + SMR_FUNC("DSMRTestFactory::Create");
1.316 +
1.317 + aChannel=new DSMRTestChannel();
1.318 + if(!aChannel)
1.319 + return KErrNoMemory;
1.320 + return KErrNone;
1.321 + }
1.322 +
1.323 +
1.324 +// -- METHODS -----------------------------------------------------------------
1.325 +//
1.326 +// DSMRTestChannel
1.327 +//
1.328 +
1.329 +DSMRTestChannel::DSMRTestChannel()
1.330 + {
1.331 + SMR_FUNC("DSMRTestChannel");
1.332 + }
1.333 +
1.334 +DSMRTestChannel::~DSMRTestChannel()
1.335 + {
1.336 + SMR_FUNC("~DSMRTestChannel");
1.337 + }
1.338 +
1.339 +TInt DSMRTestChannel::DoCreate(TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& /*aVer*/)
1.340 + {
1.341 + SMR_FUNC("DSMRTestChannel::DoCreate");
1.342 +
1.343 + iClient = &Kern::CurrentThread();
1.344 + return KErrNone;
1.345 + }
1.346 +
1.347 +TInt DSMRTestChannel::RequestUserHandle(DThread* aThread, TOwnerType aType)
1.348 + {
1.349 + SMR_FUNC("DSMRTestChannel::RequestUserHandle");
1.350 +
1.351 + if (aType!=EOwnerThread || aThread!=iClient)
1.352 + return KErrAccessDenied;
1.353 + return KErrNone;
1.354 + }
1.355 +
1.356 +TInt DSMRTestChannel::Request(TInt aReqNo, TAny* a1, TAny*)
1.357 + {
1.358 + SMR_FUNC("DSMRTestChannel::Request");
1.359 + TBool aEnforce = (TBool) a1;
1.360 +
1.361 + switch(aReqNo)
1.362 + {
1.363 +
1.364 + case RSMRTest::ECtrlCheckSMRIBPtr:
1.365 + {
1.366 + TInt rc = ECtrlCheckSMRIBPtr();
1.367 + if (rc < 0)
1.368 + return rc;
1.369 + if (aEnforce && rc == 0)
1.370 + return KErrBadHandle;
1.371 +
1.372 + break; // fall through, return KErrNone
1.373 + }
1.374 +
1.375 + case RSMRTest::ECtrlPrintSMRIB:
1.376 + {
1.377 + TInt rc = ECtrlPrintSMRIB();
1.378 + if (rc < 0)
1.379 + return rc;
1.380 + if (aEnforce && rc == 0)
1.381 + return KErrNotFound;
1.382 +
1.383 + break; // fall through, return KErrNone
1.384 + }
1.385 +
1.386 + case RSMRTest::ECtrlAccessAllSMRs:
1.387 + {
1.388 + TInt rc = ECtrlAccessAllSMRs();
1.389 + if (rc < 0)
1.390 + return rc;
1.391 + if (aEnforce && rc == 0)
1.392 + return KErrNotFound;
1.393 +
1.394 + break; // fall through, return KErrNone
1.395 + }
1.396 +
1.397 + case RSMRTest::ECtrlFreeHalfSMR1PhysicalRam:
1.398 + {
1.399 + TInt rc = ECtrlFreeHalfSMR1PhysicalRam();
1.400 + if (rc < 0)
1.401 + return rc;
1.402 + if (aEnforce && rc == 0)
1.403 + return KErrNotFound;
1.404 +
1.405 + break; // fall through, return KErrNone
1.406 + }
1.407 +
1.408 + case RSMRTest::ECtrlFreeAllSMR2PhysicalRam:
1.409 + {
1.410 +
1.411 + TInt rc = ECtrlFreeAllSMR2PhysicalRam();
1.412 + if (rc < 0)
1.413 + return rc;
1.414 + if (aEnforce && rc == 0)
1.415 + return KErrNotFound;
1.416 +
1.417 + break; // fall through, return KErrNone
1.418 + }
1.419 +
1.420 + default:
1.421 + return KErrNotSupported;
1.422 + }
1.423 +
1.424 + return KErrNone;
1.425 + }
1.426 +
1.427 +
1.428 +// -- GLOBALS -----------------------------------------------------------------
1.429 +
1.430 +
1.431 +DECLARE_STANDARD_LDD()
1.432 + {
1.433 + SMR_FUNC("D_SMR_DECLARE_STANDARD_LDD");
1.434 +
1.435 + const TRomHeader& romHdr = Epoc::RomHeader();
1.436 +
1.437 + TInt RHsize = sizeof(TRomHeader);
1.438 + SMR_TRACE2("RomHeader - addr %0x; size %d", &romHdr, RHsize);
1.439 +
1.440 + TSuperPage& superPage = Kern::SuperPage();
1.441 + TInt SPsize = sizeof(SSuperPageBase);
1.442 +
1.443 + TInt startupReason = superPage.iHwStartupReason;
1.444 + TLinAddr rootDirList = superPage.iRootDirList;
1.445 +
1.446 + SMR_TRACE2("SuperPage - addr %0x; size %d", &superPage, SPsize);
1.447 + SMR_TRACE2("SuperPage - StartupReason: %0x; rootDirList %0x", startupReason, rootDirList);
1.448 +
1.449 + return new DSMRTestFactory;
1.450 + }
1.451 +