1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/hcr/d_hcrut_psl.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,234 @@
1.4 +/*
1.5 +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*/
1.15 +//
1.16 +// Contributors:
1.17 +//
1.18 +// Description:
1.19 +// This file is part of the NE1_TB Variant Base Port
1.20 +// Hardware Configuration Respoitory Platform Specific Layer (PSL)
1.21 +//
1.22 +
1.23 +
1.24 +// -- INCLUDES ----------------------------------------------------------------
1.25 +
1.26 +
1.27 +#include "hcr_debug.h"
1.28 +
1.29 +#include "hcr_hai.h"
1.30 +
1.31 +#include "hcr_uids.h"
1.32 +
1.33 +#include <plat_priv.h>
1.34 +#include <kernel/kernboot.h>
1.35 +
1.36 +
1.37 +#ifdef __WINS__
1.38 +// On WINS the EMapAttrSupRo and EMapAttrCachedMax doesn't exists
1.39 +#define EMapAttrSupRo 0x01
1.40 +#define EMapAttrCachedMax 0xF000
1.41 +#endif
1.42 +
1.43 +
1.44 +// -- GLOBALS -----------------------------------------------------------------
1.45 +
1.46 +
1.47 +GLREF_C HCR::SRepositoryCompiled gRepository;
1.48 +#define BUFFER_OFFSET_ZERO 0
1.49 +
1.50 +// -- CLASSES- ----------------------------------------------------------------
1.51 +
1.52 +
1.53 +class HCRVariant : public HCR::MVariant
1.54 + {
1.55 +
1.56 +public:
1.57 +
1.58 + HCRVariant();
1.59 + virtual ~HCRVariant();
1.60 +
1.61 +public:
1.62 +
1.63 + TInt Initialise();
1.64 +
1.65 + TBool IgnoreCoreImgRepository();
1.66 + TInt GetCompiledRepositoryAddress( TAny* & aAddr);
1.67 + TInt GetOverrideRepositoryAddress( TAny* & aAddr);
1.68 +
1.69 +private:
1.70 + DChunk * iChunk;
1.71 + };
1.72 +
1.73 +
1.74 +
1.75 +
1.76 +// -- METHODS -----------------------------------------------------------------
1.77 +
1.78 +
1.79 +HCRVariant::HCRVariant()
1.80 + : iChunk(0)
1.81 + {
1.82 + HCR_FUNC("HCRVariant");
1.83 + }
1.84 +
1.85 +
1.86 +HCRVariant::~HCRVariant()
1.87 + {
1.88 + HCR_FUNC("~HCRVariant");
1.89 + if (iChunk != 0)
1.90 + {
1.91 + NKern::ThreadEnterCS();
1.92 + TInt r = Kern::ChunkClose(iChunk);
1.93 + __NK_ASSERT_ALWAYS(r!=0);
1.94 + NKern::ThreadLeaveCS();
1.95 + }
1.96 + }
1.97 +
1.98 +
1.99 +TInt HCRVariant::Initialise()
1.100 + {
1.101 + HCR_FUNC("HCRVariant::Initialise");
1.102 +
1.103 + HCR_TRACE_RETURN(KErrNone);
1.104 + }
1.105 +
1.106 +
1.107 +TInt HCRVariant::GetCompiledRepositoryAddress( TAny* & aAddr)
1.108 + {
1.109 + HCR_FUNC("HCRVariant::GetCompiledRepositoryAddress");
1.110 +
1.111 + aAddr = static_cast<TAny*>(&gRepository);
1.112 + HCR_TRACE_RETURN(KErrNone);
1.113 + }
1.114 +
1.115 +TBool HCRVariant::IgnoreCoreImgRepository()
1.116 + {
1.117 + HCR_FUNC("HCRVariant::IgnoreCoreImgRepository");
1.118 +
1.119 + HCR_TRACE_RETURN(EFalse);
1.120 + }
1.121 +
1.122 +TInt HCRVariant::GetOverrideRepositoryAddress( TAny* & aAddr)
1.123 + {
1.124 + HCR_FUNC("HCRVariant::GetRAMRepositoryAddress");
1.125 + aAddr = 0;
1.126 +
1.127 + // Note: the SMR feature by which we obtain the address of the override
1.128 + // repository is only supported in the ARM bootstrap, not X86 or WINS so
1.129 + // this test code needs conditional compilation.
1.130 +#if !defined(__WINS__) && !defined(__X86__)
1.131 +
1.132 + // Note to future implementor:
1.133 + // #include <kernel\kernboot.h>
1.134 + // First check to see if SMRIB was created during boot time.
1.135 + // If SSuperPageBase::iSmrData == KSuperPageAddressFieldUndefined (i.e. -1)
1.136 + // it does not exist, return KErrNotSupported, SMR not support by base port
1.137 + // or it is not available due to boot scenario, i.e. boot from MMC
1.138 + //
1.139 + // If it does exist (i.e. boot from NAND) then read and process the
1.140 + // SMR entries listed in the SMRIB looking for KHCRUID_SMRPayloadUID.
1.141 + // Next using the internal sizes from the HCR dat file within the SMR image
1.142 + // determine if the RAM holding the SMR image can be shrunk to return
1.143 + // unused RAM pages at the end of the image.
1.144 + //
1.145 + // Finally allocate the reserved RAM identified in the SMR entry to a
1.146 + // DChunk and return the virtual address of the HCR data file payload
1.147 + // within the SMR image, i.e. iBase+(sizeof(SSmrRomHeader)>>2).
1.148 + // Locate SMRIB
1.149 + const TSuperPage& superpage = Kern::SuperPage();
1.150 + TUint32* smrIB;
1.151 + smrIB = (TUint32 *) superpage.iSmrData;
1.152 +
1.153 + HCR_TRACE2("--- Superpage: 0x%08x, SMRIB: 0x%08x", &superpage, smrIB);
1.154 +
1.155 + if( (smrIB == NULL) || (smrIB == (TUint32*)KSuperPageAddressFieldUndefined))
1.156 + {
1.157 + HCR_TRACE_RETURN(KErrNotSupported);
1.158 + }
1.159 +
1.160 + HCR_HEX_DUMP_ABS((TUint8 *)smrIB, 8*sizeof(SSmrBank) );
1.161 + SSmrBank * smrBank = (SSmrBank *) smrIB;
1.162 +
1.163 + // T_HCRUT designed to work ith the second HCR SMR image as the first
1.164 + // is used by the t_hcr test suite.
1.165 + int smrInst = 2;
1.166 +
1.167 + while( smrBank->iBase != 0 )
1.168 + {
1.169 + HCR_TRACE2("--- smrBank: 0x%08x, smrBank->iPayloadUID: 0x%08x", smrBank, smrBank->iPayloadUID);
1.170 +
1.171 + if (smrBank->iPayloadUID == KHCRUID_SMRPayloadUID)
1.172 + {
1.173 + smrInst--;
1.174 + if (smrInst == 0) // PSL to use only the 2nd HCR SMR image
1.175 + {
1.176 +
1.177 + HCR_TRACE2("--- smrPhysAddr: 0x%08x, size:0x%08x", smrBank->iBase, smrBank->iSize);
1.178 + NKern::ThreadEnterCS();
1.179 +
1.180 + TChunkCreateInfo info;
1.181 + info.iType = TChunkCreateInfo::ESharedKernelSingle;
1.182 + info.iMaxSize = smrBank->iSize;
1.183 +
1.184 + // Enable to give supervisor read only access and maximum caching at both L1 and L2.
1.185 + info.iMapAttr = EMapAttrSupRo|EMapAttrCachedMax;
1.186 +
1.187 + info.iOwnsMemory = EFalse;
1.188 + info.iDestroyedDfc = NULL;
1.189 + TUint32 mapAttr;
1.190 + TLinAddr chunkKernAddr;
1.191 + TInt r = Kern::ChunkCreate(info, iChunk, chunkKernAddr, mapAttr);
1.192 + if( r != KErrNone )
1.193 + {
1.194 + HCR_TRACE1("--- Kern::ChunkCreate failed: 0x%08x", r);
1.195 + NKern::ThreadLeaveCS();
1.196 + HCR_TRACE_RETURN(r);
1.197 + }
1.198 +
1.199 + r = Kern::ChunkCommitPhysical(iChunk, BUFFER_OFFSET_ZERO, smrBank->iSize, smrBank->iBase);
1.200 + if( r != KErrNone)
1.201 + {
1.202 + HCR_TRACE1("--- Kern::ChunkCommitPhysical failed: 0x%08x", r);
1.203 + TInt r2 = Kern::ChunkClose(iChunk);
1.204 + __NK_ASSERT_ALWAYS(r2!=0);
1.205 + NKern::ThreadLeaveCS();
1.206 + HCR_TRACE_RETURN(r);
1.207 + }
1.208 + NKern::ThreadLeaveCS();
1.209 +
1.210 + HCR_TRACE1("--- iChunkKernAddr: 0x%08x", chunkKernAddr);
1.211 + // It should contains SMR and HCR image headers and some settings
1.212 + HCR_HEX_DUMP_ABS((TUint8 *)chunkKernAddr, 1024 );
1.213 +
1.214 + // Skip the SMR header, so we return the address of the first byte in the Repository
1.215 + aAddr = (TAny *) (chunkKernAddr + sizeof(SSmrRomHeader));
1.216 +
1.217 + HCR_TRACE_RETURN(KErrNone);
1.218 + }
1.219 + }
1.220 +
1.221 + ++smrBank;
1.222 + }
1.223 +#endif // !__WINS__ && !__X86__
1.224 +
1.225 + HCR_TRACE_RETURN(KErrNotSupported);
1.226 + }
1.227 +
1.228 +
1.229 +// -- ENTRY POINTS ------------------------------------------------------------
1.230 +
1.231 +
1.232 +GLDEF_C HCR::MVariant* CreateHCRVariant()
1.233 + {
1.234 + HCR_FUNC("CreateHCRVariant");
1.235 +
1.236 + return new HCRVariant;
1.237 + }