kernel/eka/drivers/hcr/hcr_hai.h
changeset 43 96e5fb8b040d
child 45 329ab0095843
equal deleted inserted replaced
-1:000000000000 43:96e5fb8b040d
       
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of the License "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Hardware Configuration Respoitory Platform Independent Layer (PIL)
       
    15 //
       
    16 
       
    17 /** 
       
    18 @file hcr_hai.h
       
    19 Kernel side definitions for the HCR Symbian Hardware Abstraction 
       
    20 Interface (SHAI) for variants to implement when creating a HCR.dll binary.
       
    21 
       
    22 @publishedPartner
       
    23 @prototype
       
    24 */
       
    25 
       
    26 #ifndef HCR_HAI_H
       
    27 #define HCR_HAI_H
       
    28 
       
    29 
       
    30 // -- INCLUDES ----------------------------------------------------------------
       
    31 
       
    32 
       
    33 #include <e32def.h>
       
    34 #include <e32err.h> 
       
    35 
       
    36 #include <drivers/hcr.h>
       
    37 
       
    38 
       
    39 // -- CLASSES -----------------------------------------------------------------
       
    40 
       
    41 
       
    42 /**
       
    43 The HCR namespace contains all the types and classes that make up the
       
    44 Kernel side Hardware Configuration Repository (HCR).
       
    45 */
       
    46 namespace HCR
       
    47     {
       
    48 	/** Constant defined for the first HCR repository format. Used for both 
       
    49 	compiled and file repositories. 	
       
    50 	@see SRepositoryBase::iFormatVersion	
       
    51 	*/	    
       
    52     static const TInt KRepositoryFirstVersion = 0x0001;
       
    53     
       
    54     /** Interface class defining the methods variants must implement to provide
       
    55     a complete HCR component for the targeted variant.  
       
    56     The HCR supports three repositories and it is recommended that as few of 
       
    57     these are employed for a variant to minimise lookup overheads as setting 
       
    58     override flexibility is provided at the expense of lookup performance.       
       
    59     */
       
    60     class MVariant
       
    61         {
       
    62     public:
       
    63     
       
    64         /** 
       
    65         Perform platform specific initialisation of variant HCR object. Invoked 
       
    66         during HCR kernel extension module initialisation. 
       
    67         Note: an error code from this method will prevent device startup.
       
    68 
       
    69     	@return	KErrNone if successful, or any other system wide error code.
       
    70         */    
       
    71         virtual TInt Initialise() = 0;
       
    72         
       
    73         
       
    74     	/**
       
    75         This method returns the address of the compile time setting repository 
       
    76         built into the variant HCR.dll project/binary. This repository is 
       
    77         optional and may be absent in which case 0 should be returned in aAddr. 
       
    78          
       
    79         @param aAddr out: a pointer to a HCR::SRepositoryCompiled 
       
    80     	@return	KErrNone if successful, output parameters valid,
       
    81     	        KErrNotSupported if a compile time repository is not supported,
       
    82     	        Any other system wide error code.
       
    83         @see HCR::SRepositoryCompiled
       
    84        	*/
       
    85         virtual TInt GetCompiledRepositoryAddress(TAny* & aAddr) = 0;
       
    86         
       
    87    	    /**
       
    88         This method is called at kernel initialisation and allows the PSL to 
       
    89 		disable the initial lookup of the built-in Core Image file repository. 
       
    90 		The PSL should return ETrue if the device/BSP is not going to support 
       
    91 		this repository. 	
       
    92          
       
    93     	@return	ETrue if the PIL should not find the repository in the ROM
       
    94     	        EFalse if the core image repository is to be used/supported
       
    95        	*/
       
    96         virtual TBool IgnoreCoreImgRepository () = 0;
       
    97         
       
    98     	/**
       
    99         This method returns the address of the override repository that 
       
   100         provides override values for the variant. Typically this repository
       
   101         is held in NAND flash and shadowed in RAM by the OS loader. It is
       
   102         a read-only settings repository. This repository is optional and may 
       
   103         be absent in which case 0 should be returned in aAddr.
       
   104          
       
   105         @param aAddr out: a pointer to a HCR::SRepositoryFile
       
   106     	@return	KErrNone if successful, output parameters valid,
       
   107     	        KErrNotSupported if a compile time repository is not supported,
       
   108     	        Any other system wide error code.
       
   109         @see HCR::SRepositoryFile
       
   110        	*/
       
   111         virtual TInt GetOverrideRepositoryAddress(TAny* & aAddr) = 0;
       
   112         
       
   113         };       
       
   114         
       
   115         
       
   116     /** Union that holds one of the supported word-sized setting values 
       
   117     */
       
   118     union UValueWord
       
   119         {
       
   120         TInt32      iInt32;
       
   121         TInt16      iInt16;
       
   122         TInt8       iInt8;
       
   123         TBool       iBool;
       
   124         TUint32     iUInt32;
       
   125         TUint16     iUInt16;
       
   126         TUint8      iUInt8;
       
   127         TLinAddr    iAddress;
       
   128         };
       
   129 
       
   130     /** Union that holds a pointer to one of the supported large value types 
       
   131     */
       
   132     union UValueLarge
       
   133         {
       
   134         TUint8*     iData;          //!< Array of TUint8 values
       
   135         TText8*     iString8;       //!< Array of TText8 values
       
   136 		TInt32*		iArrayInt32;	//!< Array of TInt32 values
       
   137 		TUint32*	iArrayUInt32;	//!< Array of TUInt32 values
       
   138         TInt64*     iInt64;         //!< Single TInt64 value
       
   139         TUint64*    iUInt64;        //!< Single TUint64 value
       
   140         };
       
   141     
       
   142     /** Type used to hold the offset to a large setting value */
       
   143     typedef TInt TValueLargeOffset;
       
   144       
       
   145     /** Union type used to hold either the literal value or a C++ pointer to 
       
   146     the value. Used in compile time settings.   
       
   147     */
       
   148     union USettingValueC
       
   149         {
       
   150         UValueWord  iLit;
       
   151         UValueLarge iPtr;
       
   152         };
       
   153 
       
   154     /** Union type used to hold either the literal value or an offset from the 
       
   155     start if the setting repository to the setting value. Used in file and RAM
       
   156     mapped settings.   
       
   157     */
       
   158     union USettingValueF
       
   159         {
       
   160         UValueWord          iLit;
       
   161         TValueLargeOffset   iOffset;
       
   162         };
       
   163            
       
   164     /** Metadata flags to describe properties of the settings.
       
   165     */
       
   166     enum TSettingProperties
       
   167         {
       
   168         EPropUndefined     = 0x0000,   //!< Unknown/not set
       
   169    
       
   170         // Following properties are not yet supported:
       
   171         EPropUnintiailised = 0x0001,   //!< Setting has no initial value
       
   172         EPropModifiable    = 0x0002,   //!< Setting is set/writable
       
   173         EPropPersistent    = 0x0004,   //!< Setting is non-volatile
       
   174         
       
   175         // Following properties are not yet supported but are envisaged to be
       
   176 		// implemented to support setting breaks/migration where settings 
       
   177 		// evolve and/or replace each other.
       
   178         EPropDeprecated	   = 0x1000,   //!< Setting supported but deprecate, accessed logged
       
   179 		EPropReplaced      = 0x2000,   //!< HCR redirected to retrieve value from replacement setting, access logged
       
   180 		EPropWithdrawn	   = 0x4000    //!< Setting withdrawn, log & panic if accessed 
       
   181         };        
       
   182         
       
   183     /** Provides base class for setting records. All setting structures start
       
   184     with this structure providing common setting attributes such as the
       
   185     identifier, type etc.    
       
   186     */
       
   187     struct SSettingBase
       
   188         {
       
   189         SSettingId  iId;        // Always the first member!
       
   190         TInt32      iType;      //!< @see TSettingType
       
   191         TUint16     iFlags;     //!< @See TSettingProperties
       
   192         TUint16     iLen;       //!< Only valid if setting is a large type
       
   193         };
       
   194             
       
   195     /** This structure holds a setting defined at compile time within a compile
       
   196     time defined repository.     
       
   197     @see SRepositoryCompiled
       
   198     */
       
   199     struct SSettingC            // : public SSettingBase
       
   200         {
       
   201         SSettingBase    iName;  // Always the first member!
       
   202         USettingValueC  iValue;
       
   203         };
       
   204 
       
   205     /** This structure holds a setting define in a file or memory within a file
       
   206     based repository.     
       
   207     @see SRepositoryFile
       
   208     */
       
   209     struct SSettingF             // : public SSettingBase
       
   210         {
       
   211         SSettingBase    iName;   // Always the first member!
       
   212         USettingValueF  iValue;
       
   213         };
       
   214 
       
   215 
       
   216     /** Metadata flags to describe the repository type/layout.
       
   217     */
       
   218     enum TRepositoryType
       
   219         {
       
   220         EReposUndefined = 0x00,   //!< Unknown
       
   221         
       
   222         EReposCompiled  = 'c',   //!< Repository is in Compiled layout
       
   223         EReposFile      = 'f'    //!< Repository is in File layout
       
   224         };        
       
   225 
       
   226     /** Metadata flags to describe repository properties.
       
   227     */
       
   228     enum TRepositoryProperties
       
   229         {
       
   230         EReposClear       = 0x0000,   //!< Unknown
       
   231         EReposReadOnly    = 0x0001,   //!< Repository is read-only
       
   232         EReposNonVolatile = 0x0002    //!< Repository is writable, saved to flash
       
   233         };        
       
   234 
       
   235     /** Provides base class for setting repositories. All repository structures 
       
   236     start with this structure providing common repository attributes such as the
       
   237     type , size etc.   
       
   238     */
       
   239     struct SRepositoryBase
       
   240         {
       
   241         TUint8      iFingerPrint[3];    //!< Fixed value {'H', 'C', 'R'}
       
   242         TUint8      iType;              //!< @See TRepositoryType
       
   243         TInt16      iFormatVersion;     //!< Format/layout version number
       
   244         TUint16     iFlags;             //!< @see TRepositoryProperties
       
   245         TInt32      iNumSettings;       //!< Number of settings in repository
       
   246         };    
       
   247  
       
   248  
       
   249     /** This class is the root object for a compile time defined settings 
       
   250     repository and is used in the PSL HCR variant object to hold read-only
       
   251     compile time settings. This type of repository makes use of pointers to 
       
   252     structures and arrays as it is compiled.
       
   253     */
       
   254     struct SRepositoryCompiled
       
   255         {
       
   256         SRepositoryBase*    iHdr;        // Always the first member!
       
   257         SSettingC*          iOrderedSettingList;
       
   258         };    
       
   259  
       
   260  
       
   261     /** Byte type for large setting value data 
       
   262     */
       
   263     typedef TUint8 TSettingData;
       
   264  
       
   265     /** This class is the root object for a file or memory based settings 
       
   266     repository. It assumes the repository has a flat contiguous layout and
       
   267     employees offsets to data rather then C++ pointers as in compiled 
       
   268     setting repositories.                 
       
   269     All offsets are relative to the address of &iHdr member.
       
   270     The last two members are expected to be present in the file/memory as shown
       
   271     although there is no way at type definition time to know the size of these
       
   272     members, hence they are commented out and will be accessed in the code
       
   273     using memory/file address arithmetic.
       
   274     */
       
   275     struct SRepositoryFile 
       
   276         {
       
   277         SRepositoryBase     iHdr;        // Always the first member!
       
   278         TUint32             iLSDfirstByteOffset;
       
   279 		TUint32             iLSDataSize;
       
   280 		TUint32				iReserved[3];
       
   281      // SSettingF           iOrderedSettingList[iNumSettings];
       
   282      // TSettingData        iLargeSettingsData[iLSDataSize];
       
   283         };    
       
   284   
       
   285     }
       
   286 
       
   287 
       
   288 // -- GLOBALS -----------------------------------------------------------------
       
   289 
       
   290 
       
   291 /**
       
   292 Global entry point used by PIL to create the variant HCR object in the PSL
       
   293 code.
       
   294 
       
   295 @return Pointer to variant is successfully, 0 otherwise.
       
   296 @see HCR::MVariant
       
   297 */
       
   298 GLREF_C HCR::MVariant* CreateHCRVariant(); 
       
   299 
       
   300 
       
   301 
       
   302 // -- MACROS ------------------------------------------------------------------
       
   303 
       
   304 
       
   305 /** 
       
   306 Global macro for use in defining the finger print field of a 
       
   307 SRepositoryCompiled.iHdr instance in the PSL compiled repository static data.
       
   308 
       
   309 Macro used in PSL source as the value for the finger print field in a
       
   310 compiled repository.
       
   311 @see SRepositoryBase::iFingerPrint
       
   312 */
       
   313 #define HCR_FINGER_PRINT {'H', 'C', 'R'}
       
   314 
       
   315 /** 
       
   316 Global macro for use in defining the finger print field of a 
       
   317 SRepositoryCompiled.iHdr instance in the PSL compiled repository static data.
       
   318 
       
   319 Macro used in PSL source as the value for the finger print field in a
       
   320 compiled repository.
       
   321 @see SRepositoryBase::iFingerPrint
       
   322 */
       
   323 #define HCR_SETTING_COUNT(a) (sizeof(a)/sizeof(SSettingC))
       
   324 
       
   325 /**
       
   326 Global macro for use in setting the flags attribute of a SSettingC 
       
   327 instance in the PSL compiled repository static data.
       
   328 
       
   329 @see HCR::MVariant
       
   330 @see HCR::SRepositoryCompiled
       
   331 */
       
   332 #define HCR_FLAGS_NONE		HCR::EPropUndefined
       
   333 
       
   334 /**
       
   335 Global macro for use in setting the length attribute of a SSettingC 
       
   336 instance in the PSL compiled repository static data.
       
   337 
       
   338 @see HCR::MVariant
       
   339 @see HCR::SRepositoryCompiled
       
   340 */
       
   341 #define HCR_LEN_NA			0x0000
       
   342 
       
   343 /**
       
   344 Global macro for use in defining the actual integer (word) value of a SettingC 
       
   345 instance in the PSL compiled repository static data. This can be used to 
       
   346 simplify the setting table for settings with the type flag
       
   347 set to one of 0x0000FFFF.
       
   348 
       
   349 @see HCR::MVariant
       
   350 @see HCR::SRepositoryCompiled
       
   351 */
       
   352 #define HCR_WVALUE(a)	static_cast<TInt32>(a)
       
   353 
       
   354 /**
       
   355 Global macro for use in assigning the address of a large setting value to an 
       
   356 instance of a SettingC in the PSL compiled repository static data. This can be 
       
   357 used to simplify the setting table for settings with the type flag
       
   358 set to one of 0xFFFF0000.
       
   359 
       
   360 @see HCR::MVariant
       
   361 @see HCR::SRepositoryCompiled
       
   362 */
       
   363 #define HCR_LVALUE(a)	reinterpret_cast<TInt32>(a)
       
   364 
       
   365 /**
       
   366 Global macro used as last entry in a PSL compiled repository static data. 
       
   367 The main use of this is to avoid the "last entry needs no following comma" issue
       
   368 and to aid HCR initial thead testing. 
       
   369 The Setting (0xffffffff, 0xffffffff) was choosen as it should never appear in
       
   370 a real variant as this category UID can not be allocated offically. Testers
       
   371 should also be aware of the special use of this setting so as not to use it in
       
   372 a file repository.
       
   373 
       
   374 @see HCR::MVariant
       
   375 @see HCR::SRepositoryCompiled
       
   376 */
       
   377 #define HCR_LAST_SETTING { { { 0xFFFFFFFF, 0xFFFFFFFF}, ETypeUInt32, HCR_FLAGS_NONE, HCR_LEN_NA }, { { 0x4C415354 }}}
       
   378 
       
   379 
       
   380 #endif // HCR_HAI_H