os/kernelhwsrv/kernel/eka/include/memmodel/epoc/platform.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// e32\include\memmodel\epoc\platform.h
sl@0
    15
// Public header file for device drivers
sl@0
    16
// 
sl@0
    17
// WARNING: This file contains some APIs which are internal and are subject
sl@0
    18
//          to change without notice. Such APIs should therefore not be used
sl@0
    19
//          outside the Kernel and Hardware Services package.
sl@0
    20
//
sl@0
    21
sl@0
    22
#ifndef __M32STD_H__
sl@0
    23
#define __M32STD_H__
sl@0
    24
#include <kernel/kernel.h>
sl@0
    25
#include <kernel/kernboot.h>
sl@0
    26
#ifdef __EPOC32__
sl@0
    27
#include <e32rom.h>
sl@0
    28
#else
sl@0
    29
class TRomHeader;
sl@0
    30
class TRomImageHeader;
sl@0
    31
class TRomEntry;
sl@0
    32
#endif
sl@0
    33
//
sl@0
    34
sl@0
    35
/********************************************
sl@0
    36
 * Hardware chunk abstraction
sl@0
    37
 ********************************************/
sl@0
    38
sl@0
    39
/**
sl@0
    40
The list of memory types (aka cache attributes) in Kernel on ARMv6K, ARMv7 and later platforms.
sl@0
    41
Types 0-3 can be used on all platforms. Types 4-7 can be used only on the platforms with memory type remapping.
sl@0
    42
@see TMappingAttributes2
sl@0
    43
@publishedPartner
sl@0
    44
@released
sl@0
    45
*/
sl@0
    46
enum TMemoryType
sl@0
    47
	{
sl@0
    48
	EMemAttStronglyOrdered 	= 0, /**< Strongly Ordered memory.*/
sl@0
    49
	EMemAttDevice 			= 1, /**< Device memory.*/
sl@0
    50
	EMemAttNormalUncached 	= 2, /**< Uncached Normal memory. Writes may combine.*/
sl@0
    51
	EMemAttNormalCached 	= 3, /**< Fully cached (Write-Back, Read/Write Allocate, Normal memory).*/
sl@0
    52
	EMemAttKernelInternal4 	= 4, /**< @internalComponent. Not to be used by device drivers.*/
sl@0
    53
	EMemAttPlatformSpecific5= 5, /**< Defined by Baseport - H/W independent.*/
sl@0
    54
	EMemAttPlatformSpecific6= 6, /**< Defined by Baseport - H/W specific - see ARM core's document for the details.*/
sl@0
    55
	EMemAttPlatformSpecific7= 7	 /**< Defined by Baseport - H/W independent.*/
sl@0
    56
};
sl@0
    57
sl@0
    58
const TUint KMemoryTypeShift = 3; /**< @internalComponent. The number of bits in a TMemoryType value.*/
sl@0
    59
const TUint KMemoryTypeMask = (1<<KMemoryTypeShift)-1;  /**< @internalComponent. Mask value for extracting a TMemoryType value from a bitfield.*/
sl@0
    60
sl@0
    61
/**
sl@0
    62
Memory mapping permissions and attributes.
sl@0
    63
sl@0
    64
@see TChunkCreateInfo
sl@0
    65
@see Kern::ChunkCreate
sl@0
    66
@see DSharedIoBuffer::New
sl@0
    67
@see DPlatChunkHw::New
sl@0
    68
@see Kern::ChunkPhysicalAddress
sl@0
    69
@see Cache::SyncMemoryBeforeDmaWrite
sl@0
    70
@see Cache::SyncMemoryBeforeDmaRead
sl@0
    71
@see Cache::SyncMemoryBeforeDmaWrite
sl@0
    72
sl@0
    73
@publishedPartner
sl@0
    74
@released
sl@0
    75
*/
sl@0
    76
enum TMappingAttributes
sl@0
    77
	{
sl@0
    78
	// access permissions for read
sl@0
    79
	EMapAttrReadNoone=0x0,		/**< Sets the memory as not readable in any mode */
sl@0
    80
	EMapAttrReadSup=0x1,		/**< Sets the memory as readable only from Kernel (Supervisor) mode */
sl@0
    81
	EMapAttrReadUser=0x4,		/**< Sets the memory as readable for user, hence it can be read in both user and supervisor mode*/
sl@0
    82
	EMapAttrReadMask=0xF,		/**< Used for masking read attributes*/
sl@0
    83
sl@0
    84
	// access permissions for write
sl@0
    85
	EMapAttrWriteNoone=0x00,	/**< Sets the memory as not writable in any mode */
sl@0
    86
	EMapAttrWriteSup=0x10,		/**< Sets the memory as writable only from Kernel (Supervisor) mode */
sl@0
    87
	EMapAttrWriteUser=0x40,		/**< Sets the memory as writable for user, hence it can be written in both user and supervisor mode*/
sl@0
    88
	EMapAttrWriteMask=0xF0,		/**< Used for masking write attributes*/
sl@0
    89
sl@0
    90
	// access permissions for execute
sl@0
    91
	EMapAttrExecNoone=0x000,	/**< Sets the memory as not executable in any mode */
sl@0
    92
	EMapAttrExecSup=0x100,		/**< Sets the memory as executable only from Kernel (Supervisor) mode */
sl@0
    93
	EMapAttrExecUser=0x400,		/**< Sets the memory as executable for user, hence it can be executed in both user and supervisor mode*/
sl@0
    94
	EMapAttrExecMask=0xF00,		/**< Used for masking execute attributes*/
sl@0
    95
sl@0
    96
	// access permissions - popular combinations
sl@0
    97
	EMapAttrSupRo=0x01,			/**< Supervisor has read only and user has no access permissions*/
sl@0
    98
	EMapAttrSupRw=0x11,			/**< Supervisor has read/write and user has no access permissions*/
sl@0
    99
	EMapAttrSupRwx=0x111,		/**< Supervisor has read/write/execute and user has no access permissions*/
sl@0
   100
	EMapAttrUserRo=0x14,		/**< Supervisor has read/write and user has read only permissions*/
sl@0
   101
	EMapAttrUserRw=0x44,		/**< Supervisor and user both have read/write permissions*/
sl@0
   102
	EMapAttrUserRwx=0x444,		/**< Supervisor and user both have read/write/execute permissions*/
sl@0
   103
	EMapAttrAccessMask=0xFFF,	/**< Used for masking access permissions attribute for popular combination */
sl@0
   104
sl@0
   105
	// Level 1 cache/buffer attributes
sl@0
   106
	EMapAttrFullyBlocking=0x0000,	/**< Level 1 cache/buffer attributes sets the memory as uncached, unbuffered (may not be L2 cached)*/
sl@0
   107
	EMapAttrBufferedNC=0x1000,		/**< Level 1 cache/buffer attributes sets the memory as uncached, buffered, writes do not coalesce (may not be L2 cached)*/
sl@0
   108
	EMapAttrBufferedC=0x2000,		/**< Level 1 cache/buffer attributes sets the memory as uncached, buffered, writes may coalesce (may not be L2 cached)*/
sl@0
   109
	EMapAttrL1Uncached=0x3000,		/**< Level 1 cache/buffer attributes sets the memory as uncached, buffered, writes may coalesce (may be L2 cached)*/
sl@0
   110
	EMapAttrCachedWTRA=0x4000,		/**< Level 1 cache/buffer attributes sets the memory as write-through cached, read allocate*/
sl@0
   111
	EMapAttrCachedWTWA=0x5000,		/**< Level 1 cache/buffer attributes sets the memory as write-through cached, read/write allocate*/
sl@0
   112
	EMapAttrCachedWBRA=0x6000,		/**< Level 1 cache/buffer attributes sets the memory as write-back cached, read allocate*/
sl@0
   113
	EMapAttrCachedWBWA=0x7000,		/**< Level 1 cache/buffer attributes sets memory as write-back cached, read/write allocate*/
sl@0
   114
	EMapAttrAltCacheWTRA=0x8000,	/**< Level 1 cache/buffer attributes sets memory as write-through cached, read allocate, use alternate cache*/
sl@0
   115
	EMapAttrAltCacheWTWA=0x9000,	/**< Level 1 cache/buffer attributes sets memory as write-through cached, read/write allocate, use alternate cache*/
sl@0
   116
	EMapAttrAltCacheWBRA=0xA000,	/**< Level 1 cache/buffer attributes sets memory as write-back cached, read allocate, use alternate cache*/
sl@0
   117
	EMapAttrAltCacheWBWA=0xB000,	/**< Level 1 cache/buffer attributes write-back cached, read/write allocate, use alternate cache*/
sl@0
   118
	EMapAttrL1CachedMax=0xF000,		/**< Used to make memory maximally cached in L1 cache*/
sl@0
   119
	EMapAttrL1CacheMask=0xF000,		/**< Used for masking L1 cache attributes*/
sl@0
   120
sl@0
   121
	// Level 2 cache attributes
sl@0
   122
	EMapAttrL2Uncached=0x00000,		/**< Level 2 cache attributes used to set memory as uncached at level 2 */
sl@0
   123
	EMapAttrL2CachedWTRA=0x40000,	/**< Level 2 cache attributes sets memory as write-through cached, read allocate*/
sl@0
   124
	EMapAttrL2CachedWTWA=0x50000,	/**< Level 2 cache attributes sets memory as write-through cached, read/write allocate*/
sl@0
   125
	EMapAttrL2CachedWBRA=0x60000,	/**< Level 2 cache attributes sets memory as write-back cached, read allocate*/
sl@0
   126
	EMapAttrL2CachedWBWA=0x70000,	/**< Level 2 cache attributes sets memory as write-back cached, read/write allocate*/
sl@0
   127
	EMapAttrL2CachedMax=0xF0000,	/**< Used to make memory maximally cached in L2 cache*/
sl@0
   128
	EMapAttrL2CacheMask=0xF0000,	/**< Used for masking L2 cache attributes*/
sl@0
   129
sl@0
   130
	// Others
sl@0
   131
	EMapAttrCachedMax=0xFF000,		/**< Used to set memory as maximally cached for system (fully cached in L1&L2 cache)*/
sl@0
   132
	EMapAttrShared=0x100000,		/**< Used to set the memory as shared with other processors*/
sl@0
   133
	EMapAttrUseECC=0x200000,		/**< Used for error correcting code*/
sl@0
   134
	};
sl@0
   135
sl@0
   136
/**
sl@0
   137
Container class for memory region's attributes.
sl@0
   138
It is intended for ARM platforms with memory type and access permission remapping
sl@0
   139
(arm11mpcore, arm1176, cortex_a8 and later), but could be used on any previous platform as well.
sl@0
   140
sl@0
   141
The object of this type can replace TMappingAttributes bit mask whereever it is in use. For example:
sl@0
   142
@code
sl@0
   143
	TChunkCreateInfo chunkInfo;
sl@0
   144
	...
sl@0
   145
	new (&chunkInfo.iMapAttr) TMappingAttributes2(EMemAttStronglyOrdered,EFalse,ETrue);
sl@0
   146
	r = Kern::ChunkCreate(chunkInfo, ...);
sl@0
   147
@endcode
sl@0
   148
sl@0
   149
@see TMemoryType
sl@0
   150
@see TMappingAttributes
sl@0
   151
@see TChunkCreateInfo
sl@0
   152
@see Kern::ChunkCreate
sl@0
   153
@see DSharedIoBuffer::New
sl@0
   154
@see DPlatChunkHw::New
sl@0
   155
@see Kern::ChunkPhysicalAddress
sl@0
   156
@see Cache::SyncMemoryBeforeDmaWrite
sl@0
   157
@see Cache::SyncMemoryBeforeDmaRead
sl@0
   158
@see Cache::SyncMemoryBeforeDmaWrite
sl@0
   159
sl@0
   160
@publishedPartner
sl@0
   161
@released
sl@0
   162
*/
sl@0
   163
class TMappingAttributes2
sl@0
   164
	{
sl@0
   165
public:
sl@0
   166
/**
sl@0
   167
Constructor.
sl@0
   168
Memory is always readable by Kernel. Other attributes are defined by input parameters, as follows:
sl@0
   169
@param aType 		Type (aka cache attributes) of the memory.
sl@0
   170
@param aUserAccess 	True if memory is also accessed from user code, false if it is only accessible from kernel.
sl@0
   171
@param aWritable 	True if memory is writable, false if this is read only memory.
sl@0
   172
@param aExecutable 	True if memory contains code or data, false if it only contains data.
sl@0
   173
					Default argument value is false.
sl@0
   174
@param aShared 		Shared attribute of the mapping:
sl@0
   175
					<0	Default value for the platform, e.g. Shareable for SMP, Unshareable for uni-processor.
sl@0
   176
					==0	Unshareable memory
sl@0
   177
					>0	Shareable memory
sl@0
   178
					To ensure future compatibility, use the value <0 except when absolutely neccessary.
sl@0
   179
					Default argument value is -1.
sl@0
   180
@param aParity 		Parity error attribute of the mapping:
sl@0
   181
					<0	Default value for the platform (which is off on all platforms so far).
sl@0
   182
					==0	Parity error doesn't generate external abort.
sl@0
   183
					>0	Parity error generates external abort.
sl@0
   184
					To ensure future compatibility, use the value <0 except when absolutely neccessary.
sl@0
   185
					Default argument value is -1.
sl@0
   186
sl@0
   187
@see TMemoryType
sl@0
   188
*/
sl@0
   189
	IMPORT_C TMappingAttributes2(TMemoryType 	aType       ,
sl@0
   190
								TBool 			aUserAccess ,
sl@0
   191
								TBool 			aWritable   ,
sl@0
   192
								TBool 			aExecutable = EFalse,
sl@0
   193
								TInt 			aShared     = -1,
sl@0
   194
								TInt 			aParity     = -1);
sl@0
   195
	
sl@0
   196
	TMappingAttributes2(TUint aMapAttr);/**< @internalComponent*/
sl@0
   197
	TMemoryType Type();	/**< @internalComponent @return Type of the memory (aka cache attributes).*/
sl@0
   198
	TBool UserAccess();	/**< @internalComponent @return True if memory can be accessed from user code.*/
sl@0
   199
	TBool Writable();	/**< @internalComponent @return True if memory can be written into, false if this is reaad only memory.*/
sl@0
   200
	TBool Executable();	/**< @internalComponent @return True if memory can contain code and data, false if it can only contain data.*/
sl@0
   201
	TBool Shared();	   	/**< @internalComponent @return True if memory is shared, false if not.*/
sl@0
   202
	TBool Parity();		/**< @internalComponent @return True if parity error generates external abort, false if not.*/
sl@0
   203
	TBool ObjectType2();/**< @internalComponent @return True if the object is TMappingAttributes2, false if it is TMappingAttributes bitmask.*/
sl@0
   204
private:
sl@0
   205
	static void Panic(TInt aPanic); /**< @internalComponent*/
sl@0
   206
private:
sl@0
   207
	TUint32 iAttributes; /**< @internalComponent*/
sl@0
   208
	};
sl@0
   209
sl@0
   210
/**
sl@0
   211
@internalComponent
sl@0
   212
*/
sl@0
   213
inline TBool ComparePermissions(TInt aActual, TInt aRequired)
sl@0
   214
	{
sl@0
   215
	return	((aActual&EMapAttrReadMask)>=(aRequired&EMapAttrReadMask)) &&
sl@0
   216
			((aActual&EMapAttrWriteMask)>=(aRequired&EMapAttrWriteMask)) &&
sl@0
   217
			((aActual&EMapAttrExecMask)>=(aRequired&EMapAttrExecMask));
sl@0
   218
	}
sl@0
   219
sl@0
   220
sl@0
   221
/** Hardware Chunk class
sl@0
   222
	Class representing a global mapping of I/O or global memory buffers
sl@0
   223
sl@0
   224
@publishedPartner
sl@0
   225
@released
sl@0
   226
*/
sl@0
   227
class DPlatChunkHw : public DObject
sl@0
   228
	{
sl@0
   229
public:
sl@0
   230
	IMPORT_C static TInt New(DPlatChunkHw*& aChunk, TPhysAddr anAddr, TInt aSize, TUint aAttribs);
sl@0
   231
	inline TLinAddr LinearAddress() {return iLinAddr;}
sl@0
   232
	inline TPhysAddr PhysicalAddress() {return iPhysAddr;}
sl@0
   233
public:
sl@0
   234
	/** @internalComponent */
sl@0
   235
	static TInt DoNew(DPlatChunkHw*& aChunk, TPhysAddr anAddr, TInt aSize, TUint aAttribs);
sl@0
   236
public:
sl@0
   237
	TPhysAddr iPhysAddr;			/**< @internalComponent */
sl@0
   238
	TLinAddr iLinAddr;				/**< @internalComponent */
sl@0
   239
	TInt iSize;						/**< @internalComponent */
sl@0
   240
	TUint iAttribs;					/**< @internalComponent */	// mapping attributes
sl@0
   241
	};
sl@0
   242
sl@0
   243
/********************************************
sl@0
   244
 * Exports from layer 2 or below of the kernel
sl@0
   245
 * which are not available to layer 1
sl@0
   246
 ********************************************/
sl@0
   247
sl@0
   248
/**
sl@0
   249
Specifies the operation performed by the TRamZoneCallback function.
sl@0
   250
@see TRamZoneCallback
sl@0
   251
@publishedPartner
sl@0
   252
@released 
sl@0
   253
*/
sl@0
   254
enum TRamZoneOp
sl@0
   255
	{
sl@0
   256
	/** Informs the variant that a specified RAM zone is not currently 
sl@0
   257
	being used and therefore it may be possible to save power by not refreshing 
sl@0
   258
	this zone or, if the rest of the its RAM IC's zones are also empty, powering 
sl@0
   259
	down the RAM IC.
sl@0
   260
sl@0
   261
	The TRamZoneCallback parameter aParam1 is the ID of the zone.
sl@0
   262
	The TRamZoneCallback parameter aParam2 is a pointer to const array of TUints
sl@0
   263
	that are the bit masks of the zones' power status.
sl@0
   264
	*/
sl@0
   265
	ERamZoneOp_PowerDown=0, 
sl@0
   266
sl@0
   267
	/** Informs the variant that a specified RAM zone is now required for use
sl@0
   268
	and therefore it must be ready.
sl@0
   269
	The variant should ensure the zone is refreshed, if required, and that the 
sl@0
   270
	RAM IC is powered and fully initialised.
sl@0
   271
sl@0
   272
	The TRamZoneCallback parameter aParam1 is the ID of the zone.
sl@0
   273
	The TRamZoneCallback parameter aParam2 is a pointer to const array of TUints
sl@0
   274
	that are the bit masks of the zones' power status.
sl@0
   275
	*/
sl@0
   276
	ERamZoneOp_PowerUp=1,
sl@0
   277
sl@0
   278
	/** Operation that informs the variant of the RAM zones that have been used
sl@0
   279
	during the initial stages of the boot process.  Any RAM zones that are not
sl@0
   280
	in use may be powered down or not refreshed to save power.
sl@0
   281
	This will be the first operation requested of the variant and it is only
sl@0
   282
	issued once.
sl@0
   283
sl@0
   284
	The TRamZoneCallback parameter aParam1 is unused by this operation.
sl@0
   285
	The TRamZoneCallback parameter aParam2 is a pointer to const array of TUints
sl@0
   286
	that are the bit masks of the zones' power status.
sl@0
   287
	*/
sl@0
   288
	ERamZoneOp_Init=2,
sl@0
   289
	};
sl@0
   290
sl@0
   291
sl@0
   292
/**
sl@0
   293
Call back function that is invoked by the kernel when its RAM allocator determines 
sl@0
   294
that an operation can be performed on a particular RAM zone.
sl@0
   295
sl@0
   296
@publishedPartner
sl@0
   297
@released
sl@0
   298
sl@0
   299
@param aOp Type of operation to perform; a value of TRamZoneOp
sl@0
   300
@param aParam1 A value whose use is defined by the TRamZoneOp to be performed
sl@0
   301
@param aParam2 A value whose use is defined by the TRamZoneOp to be performed 
sl@0
   302
The data pointed to by aParam2 is const and therefore should not be modified
sl@0
   303
sl@0
   304
@return KErrNone if successful, otherwise one of the system wide error codes
sl@0
   305
sl@0
   306
@see TRamZoneOp
sl@0
   307
*/
sl@0
   308
typedef TInt (*TRamZoneCallback) (TRamZoneOp aOp, TAny* aParam1, const TAny* aParam2);
sl@0
   309
sl@0
   310
/**
sl@0
   311
Holds the number of each page type within a RAM zone.
sl@0
   312
sl@0
   313
@see Epoc::GetRamZonePageCount()
sl@0
   314
sl@0
   315
@publishedPartner
sl@0
   316
@released
sl@0
   317
*/
sl@0
   318
struct SRamZonePageCount
sl@0
   319
	{
sl@0
   320
	TUint iFreePages;		/**< The number of free pages in the RAM zone*/
sl@0
   321
	TUint iUnknownPages;	/**< The number of unknown pages in the RAM zone*/
sl@0
   322
	TUint iFixedPages;		/**< The number of fixed pages in the RAM zone*/
sl@0
   323
	TUint iMovablePages;	/**< The number of movable pages in the RAM zone*/
sl@0
   324
	TUint iDiscardablePages;/**< The number of discardable pages in the RAM zone*/
sl@0
   325
	TUint iReserved[4];		/**<@internalComponent reserved for internal use only*/
sl@0
   326
	};
sl@0
   327
sl@0
   328
/**
sl@0
   329
@publishedPartner
sl@0
   330
@released
sl@0
   331
*/
sl@0
   332
class Epoc
sl@0
   333
	{
sl@0
   334
public:
sl@0
   335
	/**
sl@0
   336
	The types of RAM defragmentation operations.
sl@0
   337
	@internalComponent
sl@0
   338
	*/
sl@0
   339
	enum TRamDefragOp
sl@0
   340
		{
sl@0
   341
		ERamDefrag_DefragRam,
sl@0
   342
		ERamDefrag_EmptyRamZone,
sl@0
   343
		ERamDefrag_ClaimRamZone,
sl@0
   344
		};
sl@0
   345
sl@0
   346
	/**
sl@0
   347
	The type of page to move with Epoc::MovePhysicalPage().
sl@0
   348
	@internalComponent
sl@0
   349
	*/
sl@0
   350
	enum TRamDefragPageToMove
sl@0
   351
		{
sl@0
   352
		/** 
sl@0
   353
		Move the physical page aOld.
sl@0
   354
		*/
sl@0
   355
		ERamDefragPage_Physical,
sl@0
   356
		/** 
sl@0
   357
		Move the page table page that maps the linear address in the 
sl@0
   358
		current thread at aOld.
sl@0
   359
		*/
sl@0
   360
		ERamDefragPage_PageTable,
sl@0
   361
		/** 
sl@0
   362
		Move the page table info page of the page table that maps the linear 
sl@0
   363
		address in the current thread at aOld.
sl@0
   364
		*/
sl@0
   365
		ERamDefragPage_PageTableInfo,
sl@0
   366
		};
sl@0
   367
sl@0
   368
sl@0
   369
	IMPORT_C static void SetMonitorEntryPoint(TDfcFn aFunction);			/**< @internalComponent */
sl@0
   370
	IMPORT_C static void SetMonitorExceptionHandler(TLinAddr aHandler);		/**< @internalComponent */
sl@0
   371
	IMPORT_C static TAny* ExceptionInfo();									/**< @internalComponent */
sl@0
   372
	IMPORT_C static const TRomHeader& RomHeader();
sl@0
   373
	IMPORT_C static TInt AllocShadowPage(TLinAddr aRomAddr);
sl@0
   374
	IMPORT_C static TInt CopyToShadowMemory(TLinAddr aDest, TLinAddr aSrc, TUint32 aLength);
sl@0
   375
	IMPORT_C static TInt FreeShadowPage(TLinAddr aRomAddr);
sl@0
   376
	IMPORT_C static TInt FreezeShadowPage(TLinAddr aRomAddr);
sl@0
   377
	IMPORT_C static TInt AllocPhysicalRam(TInt aSize, TPhysAddr& aPhysAddr, TInt aAlign=0);
sl@0
   378
	IMPORT_C static TInt ZoneAllocPhysicalRam(TUint aZoneId, TInt aSize, TPhysAddr& aPhysAddr, TInt aAlign=0);
sl@0
   379
	IMPORT_C static TInt ZoneAllocPhysicalRam(TUint* aZoneIdList, TUint aZoneIdCount, TInt aSize, TPhysAddr& aPhysAddr, TInt aAlign=0);
sl@0
   380
	IMPORT_C static TInt AllocPhysicalRam(TInt aNumPages, TPhysAddr* aPageList);
sl@0
   381
	IMPORT_C static TInt ZoneAllocPhysicalRam(TUint aZoneId, TInt aNumPages, TPhysAddr* aPageList);
sl@0
   382
	IMPORT_C static TInt ZoneAllocPhysicalRam(TUint* aZoneIdList, TUint aZoneIdCount, TInt aNumPages, TPhysAddr* aPageList);
sl@0
   383
	IMPORT_C static TInt FreePhysicalRam(TPhysAddr aPhysAddr, TInt aSize);
sl@0
   384
	IMPORT_C static TInt FreePhysicalRam(TInt aNumPages, TPhysAddr* aPageList);
sl@0
   385
	IMPORT_C static TInt ClaimPhysicalRam(TPhysAddr aPhysAddr, TInt aSize);
sl@0
   386
	IMPORT_C static TPhysAddr LinearToPhysical(TLinAddr aLinAddr);
sl@0
   387
	IMPORT_C static void RomProcessInfo(TProcessCreateInfo& aInfo, const TRomImageHeader& aRomImageHeader);	/**< @internalComponent */
sl@0
   388
#ifdef BTRACE_KERNEL_MEMORY
sl@0
   389
	static TInt DriverAllocdPhysRam; // the number of bytes allocated by Epoc::AllocPhysicalRam and Epoc::FreePhysicalRam
sl@0
   390
	static TInt KernelMiscPages; // the number of bytes of 'miscelaneous' kernel memory allocated
sl@0
   391
#endif
sl@0
   392
	IMPORT_C static TInt MovePhysicalPage(TPhysAddr aOld, TPhysAddr& aNew, TRamDefragPageToMove aPageToMove=ERamDefragPage_Physical);	/**< @internalComponent */
sl@0
   393
	IMPORT_C static TInt SetRamZoneConfig(const SRamZone* aZones, TRamZoneCallback aCallback);
sl@0
   394
	IMPORT_C static TInt GetRamZonePageCount(TUint aId, SRamZonePageCount& aPageData);
sl@0
   395
	IMPORT_C static TInt ModifyRamZoneFlags(TUint aId, TUint aClearMask, TUint aSetMask);
sl@0
   396
	};
sl@0
   397
sl@0
   398
/**
sl@0
   399
@publishedPartner
sl@0
   400
@released
sl@0
   401
*/
sl@0
   402
class DebugSupport
sl@0
   403
	{
sl@0
   404
public:
sl@0
   405
sl@0
   406
	/** Bitmask values representing different breakpoint types. */
sl@0
   407
	enum TType
sl@0
   408
		{
sl@0
   409
		EBreakpointGlobal = 1<<0, /**< Breakpoint appears in all processes */
sl@0
   410
		EBreakpointLocal  = 1<<1, /**< Breakpoint appears in the specified process only. */
sl@0
   411
		};
sl@0
   412
sl@0
   413
	IMPORT_C static TInt InitialiseCodeModifier(TUint& aCapabilities, TInt aMinBreakpoints);
sl@0
   414
	IMPORT_C static void CloseCodeModifier();
sl@0
   415
	IMPORT_C static TInt ModifyCode(DThread* aThread, TLinAddr aAddress, TInt aSize, TUint aValue, TUint aType);
sl@0
   416
	IMPORT_C static TInt RestoreCode(DThread* aThread, TLinAddr aAddress);
sl@0
   417
sl@0
   418
/**
sl@0
   419
@internalTechnology
sl@0
   420
@prototype
sl@0
   421
*/
sl@0
   422
	IMPORT_C static void TerminateProcess(DProcess* aProcess, const TInt aReason);
sl@0
   423
sl@0
   424
	};
sl@0
   425
sl@0
   426
#ifdef __DEBUGGER_SUPPORT__
sl@0
   427
/**
sl@0
   428
@internalComponent
sl@0
   429
*/
sl@0
   430
class CodeModifier : public DBase
sl@0
   431
	{
sl@0
   432
public:
sl@0
   433
sl@0
   434
	/** Values for panic values in category 'CodeModifier'. */
sl@0
   435
	enum TPanic
sl@0
   436
		{
sl@0
   437
		EPanicNotInitialised = 0,
sl@0
   438
		EPanicInvalidSizeOrAlignment = 1,
sl@0
   439
		};
sl@0
   440
sl@0
   441
	/** Defines the type/size of the breakpoint - see TBreakpoint::iSize*/
sl@0
   442
	enum TBrkType
sl@0
   443
		{
sl@0
   444
		EEmpty =0,		//The slot is unused
sl@0
   445
		EByte =1,		//Jazelle breakpoint
sl@0
   446
		EHalfword =2,	//Thumb breakpoint
sl@0
   447
		EWord =4		//ARM breakpoint
sl@0
   448
		};
sl@0
   449
sl@0
   450
	TInt static CreateAndInitialise(TInt aMinBreakpoints);
sl@0
   451
	~CodeModifier();
sl@0
   452
	void Close();
sl@0
   453
	TInt Modify(DThread* aThread, TLinAddr aAddress, TInt aSize, TUint aValue);
sl@0
   454
	TInt Restore(DThread* aThread, TLinAddr aAddress);
sl@0
   455
	static void CodeSegRemoved(DCodeSeg* aCodeSeg, DProcess* aProcess);
sl@0
   456
	static DMutex& Mutex() {return *Kern::CodeSegLock();}
sl@0
   457
	static void Fault(TPanic aPanic);
sl@0
   458
sl@0
   459
private:
sl@0
   460
	
sl@0
   461
	/**Desribes a breakpoint slot in the pool*/
sl@0
   462
	struct TBreakpoint
sl@0
   463
		{
sl@0
   464
		TUint   iProcessId;	//Id of the process associated to this breakpoint.
sl@0
   465
		TUint   iAddress;	//The virtual address of the breakpoint
sl@0
   466
		TUint32 iOldValue;	//Will hold the original content of iAddress
sl@0
   467
		TInt16  iSize; 		//Could be one of TBrkType. 0 means empty/unused, otherwise it indicates the size of the breakpoint in bytes.
sl@0
   468
		TInt16  iPageIndex;	//If iSize!=0 identifies corresponding shadowed page, or -1 if it is non-XIP page.
sl@0
   469
		};
sl@0
   470
	
sl@0
   471
	/** Desribes a page slot in the pool. Used for pages that are shadowed or need to be locked (for demand paging). */
sl@0
   472
	struct TPageInfo
sl@0
   473
		{
sl@0
   474
		TLinAddr iAddress;		//Base address of the page.
sl@0
   475
		TInt32 	 iCounter;	  	//The number of breakpoints associated with this page. 0 indicates empty slot.
sl@0
   476
		TBool 	 iWasShadowed;	//True if the page had been already shadowed before the first breakpoint was applied,
sl@0
   477
								//false otherwise. If true, it won't be un-shadowed after all breakpoints are removed.
sl@0
   478
#ifdef __DEMAND_PAGING__
sl@0
   479
		/// If set, points to the deamnd paging lock object used to lock this page.  Only applies to
sl@0
   480
		/// RAM-loaded code.
sl@0
   481
		DDemandPagingLock* iPagingLock;
sl@0
   482
#endif
sl@0
   483
		};
sl@0
   484
private:
sl@0
   485
	TBreakpoint* FindBreakpoint(DThread* aThread, TLinAddr aAddress, TInt aSize, TBool& aOverlap);
sl@0
   486
	TBreakpoint* FindEmptyBrk();
sl@0
   487
	TInt FindEmptyPageInfo();
sl@0
   488
	TInt FindPageInfo(TLinAddr aAddress);
sl@0
   489
	TInt IsRom(TLinAddr aAddress);
sl@0
   490
	TInt WriteCode(TLinAddr aAddress, TInt aSize, TUint aValue, void* aOldValue);
sl@0
   491
	DProcess* Process(TUint aProcessId);
sl@0
   492
	TInt SafeWriteCode(DProcess* aProcess, TLinAddr aAddress, TInt aSize, TUint aValue, void* aOldValue);
sl@0
   493
	void RestorePage(TInt aPageIndex);
sl@0
   494
	void DoCodeSegRemoved(DCodeSeg* aCodeSeg, DProcess* aProcess);
sl@0
   495
sl@0
   496
private:
sl@0
   497
	TInt iPoolSize;
sl@0
   498
	TBreakpoint* iBreakpoints;	//Breakpoint pool with iPoolSize slots
sl@0
   499
	TPageInfo* iPages;			//The pool of the shadowed/locked pages with iPoolSize slots
sl@0
   500
	TUint iPageSize;
sl@0
   501
	TUint iPageMask;
sl@0
   502
	};
sl@0
   503
sl@0
   504
GLREF_D CodeModifier* TheCodeModifier;
sl@0
   505
#endif //__DEBUGGER_SUPPORT__
sl@0
   506
sl@0
   507
sl@0
   508
/**
sl@0
   509
@internalComponent
sl@0
   510
*/
sl@0
   511
inline const TRomEntry &RomEntry(TLinAddr anAddr)
sl@0
   512
	{return(*((const TRomEntry *)anAddr));}
sl@0
   513
sl@0
   514
/**
sl@0
   515
@internalComponent
sl@0
   516
*/
sl@0
   517
inline const TRomImageHeader& RomImageHeader(TLinAddr anAddr)
sl@0
   518
	{return(*((const TRomImageHeader*)anAddr));}
sl@0
   519
sl@0
   520
/**
sl@0
   521
TRamDefragRequest is intended to be used by device drivers to request that RAM defragmentation
sl@0
   522
operations are performed.
sl@0
   523
sl@0
   524
All RAM defragmentation operations can be invoked synchronously or asynchronously.
sl@0
   525
The asynchronous RAM defragmentation operations can use either a TDfc or a NFastSemaphore
sl@0
   526
to signal to the caller that the operation has completed.
sl@0
   527
sl@0
   528
@see TDfc
sl@0
   529
@see NFastSemaphore
sl@0
   530
@publishedPartner
sl@0
   531
@released
sl@0
   532
*/
sl@0
   533
class TRamDefragRequest : protected TAsyncRequest
sl@0
   534
	{
sl@0
   535
public:
sl@0
   536
	IMPORT_C TRamDefragRequest();
sl@0
   537
	IMPORT_C TInt DefragRam(TInt aPriority, TInt aMaxPages=0);
sl@0
   538
	IMPORT_C TInt DefragRam(NFastSemaphore* aSem, TInt aPriority, TInt aMaxPages=0);
sl@0
   539
	IMPORT_C TInt DefragRam(TDfc* aDfc, TInt aPriority, TInt aMaxPages=0);
sl@0
   540
	IMPORT_C TInt EmptyRamZone(TUint aId, TInt aPriority);
sl@0
   541
	IMPORT_C TInt EmptyRamZone(TUint aId, NFastSemaphore* aSem, TInt aPriority);
sl@0
   542
	IMPORT_C TInt EmptyRamZone(TUint aId, TDfc* aDfc, TInt aPriority);
sl@0
   543
	IMPORT_C TInt ClaimRamZone(TUint aId, TPhysAddr& aPhysAddr, TInt aPriority);
sl@0
   544
	IMPORT_C TInt ClaimRamZone(TUint aId, TPhysAddr& aPhysAddr, NFastSemaphore* aSem, TInt aPriority);
sl@0
   545
	IMPORT_C TInt ClaimRamZone(TUint aId, TPhysAddr& aPhysAddr, TDfc* aDfc, TInt aPriority);
sl@0
   546
	IMPORT_C TInt Result();
sl@0
   547
	IMPORT_C void Cancel();
sl@0
   548
sl@0
   549
	/** 
sl@0
   550
	Values that can be specified to control which thread priority 
sl@0
   551
	the RAM defragmentation operations are run with.
sl@0
   552
	*/
sl@0
   553
	enum TPrioritySpecial
sl@0
   554
		{
sl@0
   555
		/** 
sl@0
   556
		The RAM defragmentation operation will use the same thread priority as 
sl@0
   557
		that of the caller.
sl@0
   558
		*/
sl@0
   559
		KInheritPriority = -1,	
sl@0
   560
		};
sl@0
   561
sl@0
   562
private:
sl@0
   563
	void SetupPriority(TInt aPriority);
sl@0
   564
sl@0
   565
private:
sl@0
   566
	Epoc::TRamDefragOp iOp;
sl@0
   567
	TUint iId;
sl@0
   568
	TUint iMaxPages;
sl@0
   569
	TInt iThreadPriority;
sl@0
   570
	TPhysAddr* iPhysAddr;
sl@0
   571
	TInt iSpare[6];
sl@0
   572
sl@0
   573
public:
sl@0
   574
	friend class Defrag;
sl@0
   575
	};
sl@0
   576
sl@0
   577
sl@0
   578
#endif
sl@0
   579