os/kernelhwsrv/kerneltest/e32test/hcr/d_hcrut_psl.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     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".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 */
    12 //
    13 // Contributors:
    14 //
    15 // Description:
    16 // This file is part of the NE1_TB Variant Base Port
    17 // Hardware Configuration Respoitory Platform Specific Layer (PSL) 
    18 //
    19 
    20 
    21 // -- INCLUDES ----------------------------------------------------------------
    22 
    23 
    24 #include "hcr_debug.h"
    25 
    26 #include "hcr_hai.h"
    27 
    28 #include "hcr_uids.h"
    29 
    30 #include <plat_priv.h>
    31 #include <kernel/kernboot.h>
    32 
    33 
    34 #ifdef __WINS__
    35 // On WINS the EMapAttrSupRo and EMapAttrCachedMax doesn't exists
    36 #define EMapAttrSupRo       0x01
    37 #define EMapAttrCachedMax   0xF000
    38 #endif
    39 
    40 
    41 // -- GLOBALS -----------------------------------------------------------------
    42 
    43 
    44 GLREF_C HCR::SRepositoryCompiled gRepository;
    45 #define BUFFER_OFFSET_ZERO  0
    46 
    47 // -- CLASSES- ----------------------------------------------------------------
    48 
    49 
    50 class HCRVariant : public HCR::MVariant
    51     {    
    52     
    53 public:
    54 
    55     HCRVariant();
    56     virtual ~HCRVariant();
    57     
    58 public:    
    59     
    60     TInt Initialise();
    61     
    62     TBool IgnoreCoreImgRepository();
    63 	TInt GetCompiledRepositoryAddress( TAny* & aAddr);
    64     TInt GetOverrideRepositoryAddress( TAny* & aAddr);
    65     
    66 private:
    67     DChunk * iChunk;    
    68     };
    69     
    70     
    71 
    72 
    73 // -- METHODS -----------------------------------------------------------------
    74 
    75 
    76 HCRVariant::HCRVariant()
    77     : iChunk(0)
    78     {
    79     HCR_FUNC("HCRVariant");
    80     }
    81 
    82 
    83 HCRVariant::~HCRVariant()
    84     {
    85     HCR_FUNC("~HCRVariant");
    86     if (iChunk != 0)
    87         {
    88         NKern::ThreadEnterCS();    
    89         TInt r = Kern::ChunkClose(iChunk);
    90         __NK_ASSERT_ALWAYS(r!=0);
    91         NKern::ThreadLeaveCS(); 
    92         }
    93     }
    94 
    95 
    96 TInt HCRVariant::Initialise()
    97     {
    98     HCR_FUNC("HCRVariant::Initialise");
    99     
   100     HCR_TRACE_RETURN(KErrNone);
   101     }
   102     
   103     
   104 TInt HCRVariant::GetCompiledRepositoryAddress( TAny* & aAddr)
   105     {
   106     HCR_FUNC("HCRVariant::GetCompiledRepositoryAddress");
   107         
   108     aAddr = static_cast<TAny*>(&gRepository);
   109     HCR_TRACE_RETURN(KErrNone);
   110     }
   111 
   112 TBool HCRVariant::IgnoreCoreImgRepository()
   113     {
   114     HCR_FUNC("HCRVariant::IgnoreCoreImgRepository");
   115         
   116     HCR_TRACE_RETURN(EFalse);
   117     }
   118 
   119 TInt HCRVariant::GetOverrideRepositoryAddress( TAny* & aAddr)
   120     {
   121     HCR_FUNC("HCRVariant::GetRAMRepositoryAddress");
   122     aAddr = 0;
   123 
   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__)
   128     
   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
   135     //
   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.
   141 	// 
   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).
   145     // Locate SMRIB 
   146     const TSuperPage& superpage = Kern::SuperPage();
   147    	TUint32* smrIB;
   148    	smrIB = (TUint32 *) superpage.iSmrData;
   149    	
   150    	HCR_TRACE2("--- Superpage: 0x%08x, SMRIB: 0x%08x", &superpage, smrIB);
   151     
   152    	if( (smrIB == NULL) || (smrIB == (TUint32*)KSuperPageAddressFieldUndefined))
   153    	    {
   154         HCR_TRACE_RETURN(KErrNotSupported);   	        
   155    	    }
   156    	    
   157    	HCR_HEX_DUMP_ABS((TUint8 *)smrIB, 8*sizeof(SSmrBank) );
   158     SSmrBank * smrBank = (SSmrBank *) smrIB;
   159     
   160     // T_HCRUT designed to work ith the second HCR SMR image as the first 
   161 	// is used by the t_hcr test suite.
   162     int smrInst = 2;
   163     
   164     while( smrBank->iBase != 0 ) 
   165         {
   166         HCR_TRACE2("--- smrBank: 0x%08x, smrBank->iPayloadUID: 0x%08x", smrBank, smrBank->iPayloadUID);
   167         
   168         if (smrBank->iPayloadUID == KHCRUID_SMRPayloadUID)
   169             {
   170             smrInst--;
   171 			if (smrInst == 0) // PSL to use only the 2nd HCR SMR image
   172 			    {
   173 				
   174 	            HCR_TRACE2("--- smrPhysAddr: 0x%08x, size:0x%08x", smrBank->iBase, smrBank->iSize);
   175 	            NKern::ThreadEnterCS();
   176 	    
   177 	            TChunkCreateInfo info;
   178 	            info.iType = TChunkCreateInfo::ESharedKernelSingle;
   179 	            info.iMaxSize = smrBank->iSize;
   180 	
   181 	            // Enable to give supervisor read only access and maximum caching at both L1 and L2.
   182 	            info.iMapAttr = EMapAttrSupRo|EMapAttrCachedMax;  
   183 	
   184 	            info.iOwnsMemory = EFalse; 
   185 	            info.iDestroyedDfc = NULL;
   186 	            TUint32 mapAttr;
   187 	            TLinAddr chunkKernAddr;
   188 	            TInt r = Kern::ChunkCreate(info, iChunk, chunkKernAddr, mapAttr);
   189 	            if( r != KErrNone )
   190 	                {
   191 	                HCR_TRACE1("--- Kern::ChunkCreate failed: 0x%08x", r);
   192 	                NKern::ThreadLeaveCS();
   193 	                HCR_TRACE_RETURN(r);
   194 	                }
   195 	                
   196 	            r = Kern::ChunkCommitPhysical(iChunk, BUFFER_OFFSET_ZERO, smrBank->iSize, smrBank->iBase);
   197 	            if( r != KErrNone)
   198 	                {
   199 	                HCR_TRACE1("--- Kern::ChunkCommitPhysical failed: 0x%08x", r);
   200 	                TInt r2 = Kern::ChunkClose(iChunk);
   201 	                __NK_ASSERT_ALWAYS(r2!=0);
   202 	                NKern::ThreadLeaveCS();
   203 	                HCR_TRACE_RETURN(r);    
   204 	                }   
   205 	            NKern::ThreadLeaveCS();
   206 	                
   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 );  
   210 	            
   211 	            // Skip the SMR header, so we return the address of the first byte in the Repository
   212 	            aAddr = (TAny *) (chunkKernAddr + sizeof(SSmrRomHeader));  
   213 	            
   214 	            HCR_TRACE_RETURN(KErrNone);
   215 	            }
   216 	        }
   217          
   218         ++smrBank;    
   219         }
   220 #endif // !__WINS__ && !__X86__
   221        	
   222     HCR_TRACE_RETURN(KErrNotSupported);
   223     }
   224 
   225  
   226 // -- ENTRY POINTS ------------------------------------------------------------
   227 
   228 
   229 GLDEF_C HCR::MVariant* CreateHCRVariant()
   230     {
   231     HCR_FUNC("CreateHCRVariant");
   232 
   233     return new HCRVariant;
   234     }