navienginebsp/ne1_tb/hcr/hcr_psl.cpp
changeset 0 5de814552237
equal deleted inserted replaced
-1:000000000000 0:5de814552237
       
     1 /*
       
     2 * Copyright (c) 2008-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 "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 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 * This file is part of the NE1_TB Variant Base Port
       
    16 * Hardware Configuration Respoitory Platform Specific Layer (PSL) 
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 
       
    22 #include "hcr_debug.h"
       
    23 
       
    24 #include "hcr_hai.h"
       
    25 
       
    26 #include "hcr_uids.h"
       
    27 
       
    28 #include <plat_priv.h>
       
    29 #include <kernel/kernboot.h>
       
    30 
       
    31 // -- GLOBALS -----------------------------------------------------------------
       
    32 
       
    33 
       
    34 GLREF_C HCR::SRepositoryCompiled gRepository;
       
    35 #define BUFFER_OFFSET_ZERO  0
       
    36 
       
    37 // -- CLASSES- ----------------------------------------------------------------
       
    38 
       
    39 
       
    40 class HCRVariant : public HCR::MVariant
       
    41     {    
       
    42     
       
    43 public:
       
    44 
       
    45     HCRVariant();
       
    46     virtual ~HCRVariant();
       
    47     
       
    48 public:    
       
    49     
       
    50     TInt Initialise();
       
    51     
       
    52     TBool IgnoreCoreImgRepository();
       
    53 	TInt GetCompiledRepositoryAddress( TAny* & aAddr);
       
    54     TInt GetOverrideRepositoryAddress( TAny* & aAddr);
       
    55     
       
    56 private:
       
    57     DChunk * iChunk;    
       
    58     };
       
    59     
       
    60     
       
    61 
       
    62 
       
    63 // -- METHODS -----------------------------------------------------------------
       
    64 
       
    65 
       
    66 HCRVariant::HCRVariant()
       
    67     : iChunk(0)
       
    68     {
       
    69     HCR_FUNC("HCRVariant");
       
    70     }
       
    71 
       
    72 
       
    73 HCRVariant::~HCRVariant()
       
    74     {
       
    75     HCR_FUNC("~HCRVariant");
       
    76     if (iChunk != 0)
       
    77         {
       
    78         NKern::ThreadEnterCS();    
       
    79         TInt r = Kern::ChunkClose(iChunk);
       
    80         __NK_ASSERT_ALWAYS(r!=0);
       
    81         NKern::ThreadLeaveCS(); 
       
    82         }
       
    83     }
       
    84 
       
    85 
       
    86 TInt HCRVariant::Initialise()
       
    87     {
       
    88     HCR_FUNC("HCRVariant::Initialise");
       
    89     
       
    90     HCR_TRACE_RETURN(KErrNone);
       
    91     }
       
    92     
       
    93     
       
    94 TInt HCRVariant::GetCompiledRepositoryAddress( TAny* & aAddr)
       
    95     {
       
    96     HCR_FUNC("HCRVariant::GetCompiledRepositoryAddress");
       
    97         
       
    98     aAddr = static_cast<TAny*>(&gRepository);
       
    99     HCR_TRACE_RETURN(KErrNone);
       
   100     }
       
   101 
       
   102 TBool HCRVariant::IgnoreCoreImgRepository()
       
   103     {
       
   104     HCR_FUNC("HCRVariant::IgnoreCoreImgRepository");
       
   105         
       
   106     HCR_TRACE_RETURN(EFalse);
       
   107     }
       
   108 
       
   109 TInt HCRVariant::GetOverrideRepositoryAddress( TAny* & aAddr)
       
   110     {
       
   111     HCR_FUNC("HCRVariant::GetRAMRepositoryAddress");
       
   112     
       
   113     // Note to future implementor:
       
   114 	// #include <kernel\kernboot.h>
       
   115 	// First check to see if SMRIB was created during boot time. 
       
   116     // If SSuperPageBase::iSmrData == KSuperPageAddressFieldUndefined (i.e. -1) 
       
   117 	// it does not exist, return KErrNotSupported, SMR not support by base port
       
   118     // or it is not available due to boot scenario, i.e. boot from MMC
       
   119     //
       
   120     // If it does exist (i.e. boot from NAND) then read and process the 
       
   121 	// SMR entries listed in the SMRIB looking for KHCRUID_SMRPayloadUID.
       
   122 	// Next using the internal sizes from the HCR dat file within the SMR image
       
   123 	// determine if the RAM holding the SMR image can be shrunk to return 
       
   124 	// unused RAM pages at the end of the image.
       
   125 	// 
       
   126 	// Finally allocate the reserved RAM identified in the SMR entry to a 
       
   127 	// DChunk and return the virtual address of the HCR data file payload
       
   128 	// within the SMR image, i.e. iBase+(sizeof(SSmrRomHeader)>>2).
       
   129     // Locate SMRIB 
       
   130     const TSuperPage& superpage = Kern::SuperPage();
       
   131    	TUint32* smrIB;
       
   132    	smrIB = (TUint32 *) superpage.iSmrData;
       
   133    	
       
   134    	HCR_TRACE2("--- Superpage: 0x%08x, SMRIB: 0x%08x", &superpage, smrIB);
       
   135     
       
   136    	if( (smrIB == NULL) || (smrIB == (TUint32*)KSuperPageAddressFieldUndefined))
       
   137    	    {
       
   138         HCR_TRACE_RETURN(KErrNotSupported);   	        
       
   139    	    }
       
   140    	    
       
   141    	HCR_HEX_DUMP_ABS((TUint8 *)smrIB, 8*sizeof(SSmrBank) );
       
   142     SSmrBank * smrBank = (SSmrBank *) smrIB;
       
   143     
       
   144     while( smrBank->iBase != 0 )
       
   145         {
       
   146         HCR_TRACE2("--- smrBank: 0x%08x, smrBank->iPayloadUID: 0x%08x", smrBank, smrBank->iPayloadUID);
       
   147         if( smrBank->iPayloadUID == KHCRUID_SMRPayloadUID)
       
   148             {
       
   149             HCR_TRACE2("--- smrPhysAddr: 0x%08x, size:0x%08x", smrBank->iBase, smrBank->iSize);
       
   150             NKern::ThreadEnterCS();
       
   151     
       
   152             TChunkCreateInfo info;
       
   153             info.iType = TChunkCreateInfo::ESharedKernelSingle;
       
   154             info.iMaxSize = smrBank->iSize;
       
   155             // Enable to give supervisor read only access and maximum caching at both L1 and L2.
       
   156             info.iMapAttr = EMapAttrSupRo|EMapAttrCachedMax;  
       
   157             info.iOwnsMemory = EFalse; 
       
   158             info.iDestroyedDfc = NULL;
       
   159             TUint32 mapAttr;
       
   160             TLinAddr chunkKernAddr;
       
   161             TInt r = Kern::ChunkCreate(info, iChunk, chunkKernAddr, mapAttr);
       
   162             if( r != KErrNone )
       
   163                 {
       
   164                 HCR_TRACE1("--- Kern::ChunkCreate failed: 0x%08x", r);
       
   165                 NKern::ThreadLeaveCS();
       
   166                 HCR_TRACE_RETURN(r);
       
   167                 }
       
   168                 
       
   169             r = Kern::ChunkCommitPhysical(iChunk, BUFFER_OFFSET_ZERO, smrBank->iSize, smrBank->iBase);
       
   170             if( r != KErrNone)
       
   171                 {
       
   172                 HCR_TRACE1("--- Kern::ChunkCommitPhysical failed: 0x%08x", r);
       
   173                 TInt r2 = Kern::ChunkClose(iChunk);
       
   174                 __NK_ASSERT_ALWAYS(r2!=0);
       
   175                 NKern::ThreadLeaveCS();
       
   176                 HCR_TRACE_RETURN(r);    
       
   177                 }   
       
   178             NKern::ThreadLeaveCS();
       
   179                 
       
   180             HCR_TRACE1("--- iChunkKernAddr: 0x%08x", chunkKernAddr);    
       
   181             // It should contains SMR and HCR image headers and some settings
       
   182             HCR_HEX_DUMP_ABS((TUint8 *)chunkKernAddr, 1024 );  
       
   183             
       
   184             // Skip the SMR header, so we return the address of the first byte in the Repository
       
   185             aAddr = (TAny *) (chunkKernAddr + sizeof(SSmrRomHeader));  
       
   186             
       
   187             HCR_TRACE_RETURN(KErrNone);
       
   188             }
       
   189          
       
   190         ++smrBank;    
       
   191         }
       
   192        	
       
   193     HCR_TRACE_RETURN(KErrNotSupported);
       
   194     }
       
   195 
       
   196  
       
   197 // -- ENTRY POINTS ------------------------------------------------------------
       
   198 
       
   199 
       
   200 GLDEF_C HCR::MVariant* CreateHCRVariant()
       
   201     {
       
   202     HCR_FUNC("CreateHCRVariant");
       
   203 
       
   204     return new HCRVariant;
       
   205     }