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.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of the License "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*/
sl@0
    12
//
sl@0
    13
// Contributors:
sl@0
    14
//
sl@0
    15
// Description:
sl@0
    16
// This file is part of the NE1_TB Variant Base Port
sl@0
    17
// Hardware Configuration Respoitory Platform Specific Layer (PSL) 
sl@0
    18
//
sl@0
    19
sl@0
    20
sl@0
    21
// -- INCLUDES ----------------------------------------------------------------
sl@0
    22
sl@0
    23
sl@0
    24
#include "hcr_debug.h"
sl@0
    25
sl@0
    26
#include "hcr_hai.h"
sl@0
    27
sl@0
    28
#include "hcr_uids.h"
sl@0
    29
sl@0
    30
#include <plat_priv.h>
sl@0
    31
#include <kernel/kernboot.h>
sl@0
    32
sl@0
    33
sl@0
    34
#ifdef __WINS__
sl@0
    35
// On WINS the EMapAttrSupRo and EMapAttrCachedMax doesn't exists
sl@0
    36
#define EMapAttrSupRo       0x01
sl@0
    37
#define EMapAttrCachedMax   0xF000
sl@0
    38
#endif
sl@0
    39
sl@0
    40
sl@0
    41
// -- GLOBALS -----------------------------------------------------------------
sl@0
    42
sl@0
    43
sl@0
    44
GLREF_C HCR::SRepositoryCompiled gRepository;
sl@0
    45
#define BUFFER_OFFSET_ZERO  0
sl@0
    46
sl@0
    47
// -- CLASSES- ----------------------------------------------------------------
sl@0
    48
sl@0
    49
sl@0
    50
class HCRVariant : public HCR::MVariant
sl@0
    51
    {    
sl@0
    52
    
sl@0
    53
public:
sl@0
    54
sl@0
    55
    HCRVariant();
sl@0
    56
    virtual ~HCRVariant();
sl@0
    57
    
sl@0
    58
public:    
sl@0
    59
    
sl@0
    60
    TInt Initialise();
sl@0
    61
    
sl@0
    62
    TBool IgnoreCoreImgRepository();
sl@0
    63
	TInt GetCompiledRepositoryAddress( TAny* & aAddr);
sl@0
    64
    TInt GetOverrideRepositoryAddress( TAny* & aAddr);
sl@0
    65
    
sl@0
    66
private:
sl@0
    67
    DChunk * iChunk;    
sl@0
    68
    };
sl@0
    69
    
sl@0
    70
    
sl@0
    71
sl@0
    72
sl@0
    73
// -- METHODS -----------------------------------------------------------------
sl@0
    74
sl@0
    75
sl@0
    76
HCRVariant::HCRVariant()
sl@0
    77
    : iChunk(0)
sl@0
    78
    {
sl@0
    79
    HCR_FUNC("HCRVariant");
sl@0
    80
    }
sl@0
    81
sl@0
    82
sl@0
    83
HCRVariant::~HCRVariant()
sl@0
    84
    {
sl@0
    85
    HCR_FUNC("~HCRVariant");
sl@0
    86
    if (iChunk != 0)
sl@0
    87
        {
sl@0
    88
        NKern::ThreadEnterCS();    
sl@0
    89
        TInt r = Kern::ChunkClose(iChunk);
sl@0
    90
        __NK_ASSERT_ALWAYS(r!=0);
sl@0
    91
        NKern::ThreadLeaveCS(); 
sl@0
    92
        }
sl@0
    93
    }
sl@0
    94
sl@0
    95
sl@0
    96
TInt HCRVariant::Initialise()
sl@0
    97
    {
sl@0
    98
    HCR_FUNC("HCRVariant::Initialise");
sl@0
    99
    
sl@0
   100
    HCR_TRACE_RETURN(KErrNone);
sl@0
   101
    }
sl@0
   102
    
sl@0
   103
    
sl@0
   104
TInt HCRVariant::GetCompiledRepositoryAddress( TAny* & aAddr)
sl@0
   105
    {
sl@0
   106
    HCR_FUNC("HCRVariant::GetCompiledRepositoryAddress");
sl@0
   107
        
sl@0
   108
    aAddr = static_cast<TAny*>(&gRepository);
sl@0
   109
    HCR_TRACE_RETURN(KErrNone);
sl@0
   110
    }
sl@0
   111
sl@0
   112
TBool HCRVariant::IgnoreCoreImgRepository()
sl@0
   113
    {
sl@0
   114
    HCR_FUNC("HCRVariant::IgnoreCoreImgRepository");
sl@0
   115
        
sl@0
   116
    HCR_TRACE_RETURN(EFalse);
sl@0
   117
    }
sl@0
   118
sl@0
   119
TInt HCRVariant::GetOverrideRepositoryAddress( TAny* & aAddr)
sl@0
   120
    {
sl@0
   121
    HCR_FUNC("HCRVariant::GetRAMRepositoryAddress");
sl@0
   122
    aAddr = 0;
sl@0
   123
sl@0
   124
	// Note: the SMR feature by which we obtain the address of the override
sl@0
   125
	// repository is only supported in the ARM bootstrap, not X86 or WINS so 
sl@0
   126
	// this test code needs conditional compilation.
sl@0
   127
#if !defined(__WINS__) && !defined(__X86__)
sl@0
   128
    
sl@0
   129
    // Note to future implementor:
sl@0
   130
	// #include <kernel\kernboot.h>
sl@0
   131
	// First check to see if SMRIB was created during boot time. 
sl@0
   132
    // If SSuperPageBase::iSmrData == KSuperPageAddressFieldUndefined (i.e. -1) 
sl@0
   133
	// it does not exist, return KErrNotSupported, SMR not support by base port
sl@0
   134
    // or it is not available due to boot scenario, i.e. boot from MMC
sl@0
   135
    //
sl@0
   136
    // If it does exist (i.e. boot from NAND) then read and process the 
sl@0
   137
	// SMR entries listed in the SMRIB looking for KHCRUID_SMRPayloadUID.
sl@0
   138
	// Next using the internal sizes from the HCR dat file within the SMR image
sl@0
   139
	// determine if the RAM holding the SMR image can be shrunk to return 
sl@0
   140
	// unused RAM pages at the end of the image.
sl@0
   141
	// 
sl@0
   142
	// Finally allocate the reserved RAM identified in the SMR entry to a 
sl@0
   143
	// DChunk and return the virtual address of the HCR data file payload
sl@0
   144
	// within the SMR image, i.e. iBase+(sizeof(SSmrRomHeader)>>2).
sl@0
   145
    // Locate SMRIB 
sl@0
   146
    const TSuperPage& superpage = Kern::SuperPage();
sl@0
   147
   	TUint32* smrIB;
sl@0
   148
   	smrIB = (TUint32 *) superpage.iSmrData;
sl@0
   149
   	
sl@0
   150
   	HCR_TRACE2("--- Superpage: 0x%08x, SMRIB: 0x%08x", &superpage, smrIB);
sl@0
   151
    
sl@0
   152
   	if( (smrIB == NULL) || (smrIB == (TUint32*)KSuperPageAddressFieldUndefined))
sl@0
   153
   	    {
sl@0
   154
        HCR_TRACE_RETURN(KErrNotSupported);   	        
sl@0
   155
   	    }
sl@0
   156
   	    
sl@0
   157
   	HCR_HEX_DUMP_ABS((TUint8 *)smrIB, 8*sizeof(SSmrBank) );
sl@0
   158
    SSmrBank * smrBank = (SSmrBank *) smrIB;
sl@0
   159
    
sl@0
   160
    // T_HCRUT designed to work ith the second HCR SMR image as the first 
sl@0
   161
	// is used by the t_hcr test suite.
sl@0
   162
    int smrInst = 2;
sl@0
   163
    
sl@0
   164
    while( smrBank->iBase != 0 ) 
sl@0
   165
        {
sl@0
   166
        HCR_TRACE2("--- smrBank: 0x%08x, smrBank->iPayloadUID: 0x%08x", smrBank, smrBank->iPayloadUID);
sl@0
   167
        
sl@0
   168
        if (smrBank->iPayloadUID == KHCRUID_SMRPayloadUID)
sl@0
   169
            {
sl@0
   170
            smrInst--;
sl@0
   171
			if (smrInst == 0) // PSL to use only the 2nd HCR SMR image
sl@0
   172
			    {
sl@0
   173
				
sl@0
   174
	            HCR_TRACE2("--- smrPhysAddr: 0x%08x, size:0x%08x", smrBank->iBase, smrBank->iSize);
sl@0
   175
	            NKern::ThreadEnterCS();
sl@0
   176
	    
sl@0
   177
	            TChunkCreateInfo info;
sl@0
   178
	            info.iType = TChunkCreateInfo::ESharedKernelSingle;
sl@0
   179
	            info.iMaxSize = smrBank->iSize;
sl@0
   180
	
sl@0
   181
	            // Enable to give supervisor read only access and maximum caching at both L1 and L2.
sl@0
   182
	            info.iMapAttr = EMapAttrSupRo|EMapAttrCachedMax;  
sl@0
   183
	
sl@0
   184
	            info.iOwnsMemory = EFalse; 
sl@0
   185
	            info.iDestroyedDfc = NULL;
sl@0
   186
	            TUint32 mapAttr;
sl@0
   187
	            TLinAddr chunkKernAddr;
sl@0
   188
	            TInt r = Kern::ChunkCreate(info, iChunk, chunkKernAddr, mapAttr);
sl@0
   189
	            if( r != KErrNone )
sl@0
   190
	                {
sl@0
   191
	                HCR_TRACE1("--- Kern::ChunkCreate failed: 0x%08x", r);
sl@0
   192
	                NKern::ThreadLeaveCS();
sl@0
   193
	                HCR_TRACE_RETURN(r);
sl@0
   194
	                }
sl@0
   195
	                
sl@0
   196
	            r = Kern::ChunkCommitPhysical(iChunk, BUFFER_OFFSET_ZERO, smrBank->iSize, smrBank->iBase);
sl@0
   197
	            if( r != KErrNone)
sl@0
   198
	                {
sl@0
   199
	                HCR_TRACE1("--- Kern::ChunkCommitPhysical failed: 0x%08x", r);
sl@0
   200
	                TInt r2 = Kern::ChunkClose(iChunk);
sl@0
   201
	                __NK_ASSERT_ALWAYS(r2!=0);
sl@0
   202
	                NKern::ThreadLeaveCS();
sl@0
   203
	                HCR_TRACE_RETURN(r);    
sl@0
   204
	                }   
sl@0
   205
	            NKern::ThreadLeaveCS();
sl@0
   206
	                
sl@0
   207
	            HCR_TRACE1("--- iChunkKernAddr: 0x%08x", chunkKernAddr);    
sl@0
   208
	            // It should contains SMR and HCR image headers and some settings
sl@0
   209
	            HCR_HEX_DUMP_ABS((TUint8 *)chunkKernAddr, 1024 );  
sl@0
   210
	            
sl@0
   211
	            // Skip the SMR header, so we return the address of the first byte in the Repository
sl@0
   212
	            aAddr = (TAny *) (chunkKernAddr + sizeof(SSmrRomHeader));  
sl@0
   213
	            
sl@0
   214
	            HCR_TRACE_RETURN(KErrNone);
sl@0
   215
	            }
sl@0
   216
	        }
sl@0
   217
         
sl@0
   218
        ++smrBank;    
sl@0
   219
        }
sl@0
   220
#endif // !__WINS__ && !__X86__
sl@0
   221
       	
sl@0
   222
    HCR_TRACE_RETURN(KErrNotSupported);
sl@0
   223
    }
sl@0
   224
sl@0
   225
 
sl@0
   226
// -- ENTRY POINTS ------------------------------------------------------------
sl@0
   227
sl@0
   228
sl@0
   229
GLDEF_C HCR::MVariant* CreateHCRVariant()
sl@0
   230
    {
sl@0
   231
    HCR_FUNC("CreateHCRVariant");
sl@0
   232
sl@0
   233
    return new HCRVariant;
sl@0
   234
    }