Update contrib.
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of the License "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
16 // This file is part of the NE1_TB Variant Base Port
17 // Hardware Configuration Respoitory Platform Specific Layer (PSL)
21 // -- INCLUDES ----------------------------------------------------------------
24 #include "hcr_debug.h"
30 #include <plat_priv.h>
31 #include <kernel/kernboot.h>
35 // On WINS the EMapAttrSupRo and EMapAttrCachedMax doesn't exists
36 #define EMapAttrSupRo 0x01
37 #define EMapAttrCachedMax 0xF000
41 // -- GLOBALS -----------------------------------------------------------------
44 GLREF_C HCR::SRepositoryCompiled gRepository;
45 #define BUFFER_OFFSET_ZERO 0
47 // -- CLASSES- ----------------------------------------------------------------
50 class HCRVariant : public HCR::MVariant
56 virtual ~HCRVariant();
62 TBool IgnoreCoreImgRepository();
63 TInt GetCompiledRepositoryAddress( TAny* & aAddr);
64 TInt GetOverrideRepositoryAddress( TAny* & aAddr);
73 // -- METHODS -----------------------------------------------------------------
76 HCRVariant::HCRVariant()
79 HCR_FUNC("HCRVariant");
83 HCRVariant::~HCRVariant()
85 HCR_FUNC("~HCRVariant");
88 NKern::ThreadEnterCS();
89 TInt r = Kern::ChunkClose(iChunk);
90 __NK_ASSERT_ALWAYS(r!=0);
91 NKern::ThreadLeaveCS();
96 TInt HCRVariant::Initialise()
98 HCR_FUNC("HCRVariant::Initialise");
100 HCR_TRACE_RETURN(KErrNone);
104 TInt HCRVariant::GetCompiledRepositoryAddress( TAny* & aAddr)
106 HCR_FUNC("HCRVariant::GetCompiledRepositoryAddress");
108 aAddr = static_cast<TAny*>(&gRepository);
109 HCR_TRACE_RETURN(KErrNone);
112 TBool HCRVariant::IgnoreCoreImgRepository()
114 HCR_FUNC("HCRVariant::IgnoreCoreImgRepository");
116 HCR_TRACE_RETURN(EFalse);
119 TInt HCRVariant::GetOverrideRepositoryAddress( TAny* & aAddr)
121 HCR_FUNC("HCRVariant::GetRAMRepositoryAddress");
124 // Note: the SMR feature by which we obtain the address of the override
125 // repository is only supported in the ARM bootstrap, not X86 or WINS so
126 // this test code needs conditional compilation.
127 #if !defined(__WINS__) && !defined(__X86__)
129 // Note to future implementor:
130 // #include <kernel\kernboot.h>
131 // First check to see if SMRIB was created during boot time.
132 // If SSuperPageBase::iSmrData == KSuperPageAddressFieldUndefined (i.e. -1)
133 // it does not exist, return KErrNotSupported, SMR not support by base port
134 // or it is not available due to boot scenario, i.e. boot from MMC
136 // If it does exist (i.e. boot from NAND) then read and process the
137 // SMR entries listed in the SMRIB looking for KHCRUID_SMRPayloadUID.
138 // Next using the internal sizes from the HCR dat file within the SMR image
139 // determine if the RAM holding the SMR image can be shrunk to return
140 // unused RAM pages at the end of the image.
142 // Finally allocate the reserved RAM identified in the SMR entry to a
143 // DChunk and return the virtual address of the HCR data file payload
144 // within the SMR image, i.e. iBase+(sizeof(SSmrRomHeader)>>2).
146 const TSuperPage& superpage = Kern::SuperPage();
148 smrIB = (TUint32 *) superpage.iSmrData;
150 HCR_TRACE2("--- Superpage: 0x%08x, SMRIB: 0x%08x", &superpage, smrIB);
152 if( (smrIB == NULL) || (smrIB == (TUint32*)KSuperPageAddressFieldUndefined))
154 HCR_TRACE_RETURN(KErrNotSupported);
157 HCR_HEX_DUMP_ABS((TUint8 *)smrIB, 8*sizeof(SSmrBank) );
158 SSmrBank * smrBank = (SSmrBank *) smrIB;
160 // T_HCRUT designed to work ith the second HCR SMR image as the first
161 // is used by the t_hcr test suite.
164 while( smrBank->iBase != 0 )
166 HCR_TRACE2("--- smrBank: 0x%08x, smrBank->iPayloadUID: 0x%08x", smrBank, smrBank->iPayloadUID);
168 if (smrBank->iPayloadUID == KHCRUID_SMRPayloadUID)
171 if (smrInst == 0) // PSL to use only the 2nd HCR SMR image
174 HCR_TRACE2("--- smrPhysAddr: 0x%08x, size:0x%08x", smrBank->iBase, smrBank->iSize);
175 NKern::ThreadEnterCS();
177 TChunkCreateInfo info;
178 info.iType = TChunkCreateInfo::ESharedKernelSingle;
179 info.iMaxSize = smrBank->iSize;
181 // Enable to give supervisor read only access and maximum caching at both L1 and L2.
182 info.iMapAttr = EMapAttrSupRo|EMapAttrCachedMax;
184 info.iOwnsMemory = EFalse;
185 info.iDestroyedDfc = NULL;
187 TLinAddr chunkKernAddr;
188 TInt r = Kern::ChunkCreate(info, iChunk, chunkKernAddr, mapAttr);
191 HCR_TRACE1("--- Kern::ChunkCreate failed: 0x%08x", r);
192 NKern::ThreadLeaveCS();
196 r = Kern::ChunkCommitPhysical(iChunk, BUFFER_OFFSET_ZERO, smrBank->iSize, smrBank->iBase);
199 HCR_TRACE1("--- Kern::ChunkCommitPhysical failed: 0x%08x", r);
200 TInt r2 = Kern::ChunkClose(iChunk);
201 __NK_ASSERT_ALWAYS(r2!=0);
202 NKern::ThreadLeaveCS();
205 NKern::ThreadLeaveCS();
207 HCR_TRACE1("--- iChunkKernAddr: 0x%08x", chunkKernAddr);
208 // It should contains SMR and HCR image headers and some settings
209 HCR_HEX_DUMP_ABS((TUint8 *)chunkKernAddr, 1024 );
211 // Skip the SMR header, so we return the address of the first byte in the Repository
212 aAddr = (TAny *) (chunkKernAddr + sizeof(SSmrRomHeader));
214 HCR_TRACE_RETURN(KErrNone);
220 #endif // !__WINS__ && !__X86__
222 HCR_TRACE_RETURN(KErrNotSupported);
226 // -- ENTRY POINTS ------------------------------------------------------------
229 GLDEF_C HCR::MVariant* CreateHCRVariant()
231 HCR_FUNC("CreateHCRVariant");
233 return new HCRVariant;