os/kernelhwsrv/kernel/eka/memmodel/epoc/flexible/mmu/mobject.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200 (2012-06-15)
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2007-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
//
sl@0
    15
sl@0
    16
/**
sl@0
    17
 @file
sl@0
    18
 @internalComponent
sl@0
    19
*/
sl@0
    20
sl@0
    21
#ifndef MOBJECT_H
sl@0
    22
#define MOBJECT_H
sl@0
    23
sl@0
    24
#include "mrefcntobj.h"
sl@0
    25
#include "mmappinglist.h"
sl@0
    26
#include "mpagearray.h"
sl@0
    27
sl@0
    28
class DMemoryManager;
sl@0
    29
class DCoarseMapping;
sl@0
    30
sl@0
    31
sl@0
    32
/**
sl@0
    33
Base class for memory objects.
sl@0
    34
sl@0
    35
A memory object is a sparse array of memory pages (#iPages) to which memory
sl@0
    36
mappings may be attached (#iMappings). All pages in the array are managed
sl@0
    37
in the same way (#iManager).
sl@0
    38
*/
sl@0
    39
class DMemoryObject : public DReferenceCountedObject
sl@0
    40
	{
sl@0
    41
public:
sl@0
    42
	virtual ~DMemoryObject();
sl@0
    43
sl@0
    44
	/**
sl@0
    45
	Claim ownership of memory originally allocated by the bootstrap.
sl@0
    46
sl@0
    47
	This is used during system boot to initialise this object's memory to contain
sl@0
    48
	the pages which are already mapped at a given region of virtual addresses.
sl@0
    49
sl@0
    50
	For coarse memory objects, this function also takes ownership of the page tables
sl@0
    51
	being used to map the memory.
sl@0
    52
sl@0
    53
	@param aBase				Starting virtual address of memory to claim.
sl@0
    54
sl@0
    55
	@param aSize				Size, in bytes, of memory region to claim.
sl@0
    56
sl@0
    57
	@param aPermissions			The access permissions which the memory region
sl@0
    58
								is mapped. As well as being required for correct object
sl@0
    59
								initialisation this also enables the function to check
sl@0
    60
								that the bootstrap code mapped the memory in manner
sl@0
    61
								consistent with the flexible memory model implementation.
sl@0
    62
sl@0
    63
	@param aAllowGaps			True if the memory region may have gaps (unmapped pages) in it.
sl@0
    64
								If false, the function faults if the region is not fully
sl@0
    65
								populated with mapped pages.
sl@0
    66
sl@0
    67
	@param aAllowNonRamPages	True if the memory region contains memory pages which are
sl@0
    68
								not RAM pages known to the kernel. I.e. are not
sl@0
    69
								contained in the list of RAM banks supplied by the bootstrap.
sl@0
    70
								Any such memory cannot be never be subsequently freed from the
sl@0
    71
								memory object because the kernel can't handle this memory.
sl@0
    72
sl@0
    73
	@return KErrNone if successful, otherwise one of the system wide error codes.
sl@0
    74
	*/
sl@0
    75
	virtual TInt ClaimInitialPages(TLinAddr aBase, TUint aSize, TMappingPermissions aPermissions, TBool aAllowGaps=false, TBool aAllowNonRamPages=false) = 0;
sl@0
    76
sl@0
    77
	/**
sl@0
    78
	Update the page table entries for all attached mappings to add entries for
sl@0
    79
	a specified set of memory pages.
sl@0
    80
sl@0
    81
	This method is called by this object's manager whenever new pages of memory are added.
sl@0
    82
sl@0
    83
	@param aPages				An RPageArray::TIter which refers to a range of pages
sl@0
    84
								in this memory object.
sl@0
    85
								Only array entries which have state RPageArray::ECommitted
sl@0
    86
								should be mapped into a mapping's page tables.
sl@0
    87
sl@0
    88
	@return KErrNone if successful, otherwise one of the system wide error codes.
sl@0
    89
	*/
sl@0
    90
	virtual TInt MapPages(RPageArray::TIter aPages);
sl@0
    91
sl@0
    92
	/**
sl@0
    93
	Update the page table entries for all attached mappings to add new entry for
sl@0
    94
	a specified memory page.
sl@0
    95
sl@0
    96
	This method is called by this object's manager whenever the page is moved.
sl@0
    97
sl@0
    98
	@param aPageArray			The page array entry of the page in this memory object.
sl@0
    99
								Only array entries which have state RPageArray::ECommitted
sl@0
   100
								should be mapped into a mapping's page tables.
sl@0
   101
sl@0
   102
	@param aIndex				The index of the page in this memory object.
sl@0
   103
sl@0
   104
	@param	aInvalidateTLB		Set to ETrue when the TLB entries associated with this page
sl@0
   105
								should be invalidated.  This must be done when there is 
sl@0
   106
								already a valid pte for this page, i.e. if the page is still 
sl@0
   107
								mapped.
sl@0
   108
sl@0
   109
	@return KErrNone if successful, otherwise one of the system wide error codes.
sl@0
   110
	*/
sl@0
   111
	virtual void RemapPage(TPhysAddr& aPageArray, TUint aIndex, TBool aInvalidateTLB);
sl@0
   112
sl@0
   113
	/**
sl@0
   114
	Update the page table entries for all attached mappings to remove entries for
sl@0
   115
	a specified set of memory pages.
sl@0
   116
sl@0
   117
	This method is called this object's manager whenever pages of memory are removed.
sl@0
   118
sl@0
   119
	@param aPages				An RPageArray::TIter which refers to a range of pages
sl@0
   120
								in this memory object.
sl@0
   121
								Only array entries which return true for
sl@0
   122
								RPageArray::TargetStateIsDecommitted should be unmapped
sl@0
   123
								from a mapping's page tables.
sl@0
   124
sl@0
   125
	@param aDecommitting		True if memory is being permanently decommitted from
sl@0
   126
								the memory object. False if the memory pages are only
sl@0
   127
								temporarily being unmapped due to a demand paging 'page out'
sl@0
   128
								operation.
sl@0
   129
	*/
sl@0
   130
	virtual void UnmapPages(RPageArray::TIter aPages, TBool aDecommitting);
sl@0
   131
sl@0
   132
	/**
sl@0
   133
	Update the page table entries for all attached mappings to apply access restrictions
sl@0
   134
	to a specified set of memory pages.
sl@0
   135
sl@0
   136
	This method is called by this object's manager whenever pages of memory are restricted.
sl@0
   137
sl@0
   138
	@param aPages				An RPageArray::TIter which refers to a range of pages
sl@0
   139
								in this memory object.
sl@0
   140
								Only array entries which return true for
sl@0
   141
								RPageArray::TargetStateIsDecommitted should be unmapped
sl@0
   142
								from a mapping's page tables.
sl@0
   143
sl@0
   144
	@param aRestriction			A value from enum #TRestrictPagesType indicating the
sl@0
   145
								kind of restriction to apply.
sl@0
   146
	*/
sl@0
   147
	virtual void RestrictPages(RPageArray::TIter aPages, TRestrictPagesType aRestriction);
sl@0
   148
sl@0
   149
	/**
sl@0
   150
	Add a memory mapping to this memory object.
sl@0
   151
sl@0
   152
	This is only intended for use by #DMemoryMappingBase::Attach.
sl@0
   153
sl@0
   154
	After verifying that the mapping is permitted (using #CheckNewMapping)
sl@0
   155
	the mapping is linked into this objects list of mappings #iMappings.
sl@0
   156
sl@0
   157
	@param aMapping The mapping to add.
sl@0
   158
sl@0
   159
	@return KErrNone if successful,
sl@0
   160
			otherwise KErrAccessDenied to indicate that the mapping is not allowed.
sl@0
   161
	*/
sl@0
   162
	virtual TInt AddMapping(DMemoryMappingBase* aMapping);
sl@0
   163
sl@0
   164
	/**
sl@0
   165
	Remove a memory mapping from this memory object.
sl@0
   166
sl@0
   167
	This is only intended for use by #DMemoryMappingBase::Detach.
sl@0
   168
sl@0
   169
	This unlinks the mapping from the list of mappings #iMappings.
sl@0
   170
sl@0
   171
	@param aMapping The mapping to remove.
sl@0
   172
	*/
sl@0
   173
	virtual void RemoveMapping(DMemoryMappingBase* aMapping);
sl@0
   174
sl@0
   175
	/**
sl@0
   176
	Attempt to set the memory object read only.  This will only succeed if
sl@0
   177
	there are no writable mappings to the memory object.
sl@0
   178
sl@0
   179
	NOTE - This can't be undone, page moving will break if a memory object 
sl@0
   180
	is made writable again.
sl@0
   181
sl@0
   182
	@return KErrNone on success, KErrInUse if writable mappings are found.
sl@0
   183
	*/
sl@0
   184
	virtual TInt SetReadOnly();
sl@0
   185
sl@0
   186
	/**
sl@0
   187
	Create a mapping object to map this memory.
sl@0
   188
sl@0
   189
	This is only intended for use by #MM::MappingNew.
sl@0
   190
	
sl@0
   191
	The base class creates a #DFineMapping object.  It is overridden by #DCoarseMemory to create a
sl@0
   192
	#DCoarseMapping in appropriate circumstances.
sl@0
   193
sl@0
   194
	@param aIndex 		The index of the start of the mapping into this memory object.
sl@0
   195
	@oaram aCount		The size in pages of the mapping.
sl@0
   196
	*/
sl@0
   197
	virtual DMemoryMapping* CreateMapping(TUint aIndex, TUint aCount);
sl@0
   198
sl@0
   199
	/**
sl@0
   200
	Get the physical address(es) for a region of pages in this memory object.
sl@0
   201
sl@0
   202
	Depending on how the memory is being managed the physical addresses returned
sl@0
   203
	may become invalid due to various reasons, e.g.
sl@0
   204
sl@0
   205
	- memory being decommitted from the memory object
sl@0
   206
	- ram defragmentation moving the memory contents to a different physical page
sl@0
   207
	- paging out of demand paged memory
sl@0
   208
sl@0
   209
	This function should therefore only be used where it is know that these
sl@0
   210
	possibilities can't occur, e.g. this is used safely by DPhysicalPinMapping::PhysAddr.
sl@0
   211
sl@0
   212
	@param aIndex			Page index, within the memory, for the start of the region.
sl@0
   213
	@param aCount			Number of pages in the region.
sl@0
   214
	@param aPhysicalAddress	On success, this value is set to one of two values.
sl@0
   215
							If the specified region is physically contiguous,
sl@0
   216
							the value is the physical address of the first page
sl@0
   217
							in the region. If the region is discontiguous, the
sl@0
   218
							value is set to KPhysAddrInvalid.
sl@0
   219
	@param aPhysicalPageList If not zero, this points to an array of TPhysAddr
sl@0
   220
							objects. On success, this array will be filled
sl@0
   221
							with the addresses of the physical pages which
sl@0
   222
							contain the specified region. If aPageList is
sl@0
   223
							zero, then the function will fail with
sl@0
   224
							KErrNotFound if the specified region is not
sl@0
   225
							physically contiguous.
sl@0
   226
sl@0
   227
	@return 0 if successful and the whole region is physically contiguous.
sl@0
   228
			1 if successful but the region isn't physically contiguous.
sl@0
   229
			KErrNotFound, if any page in the region is not present,
sl@0
   230
			otherwise one of the system wide error codes.
sl@0
   231
	*/
sl@0
   232
	TInt PhysAddr(TUint aIndex, TUint aCount, TPhysAddr& aPhysicalAddress, TPhysAddr* aPhysicalPageList);
sl@0
   233
sl@0
   234
	/**
sl@0
   235
	Check specified region lies entirely within this memory object, and that it
sl@0
   236
	is page aligned.
sl@0
   237
	*/
sl@0
   238
	TBool CheckRegion(TUint aIndex, TUint aCount);
sl@0
   239
sl@0
   240
	/**
sl@0
   241
	Clip the specified region to lie within the memory object,
sl@0
   242
	*/
sl@0
   243
	void ClipRegion(TUint& aIndex, TUint& aCount);
sl@0
   244
sl@0
   245
	/**
sl@0
   246
	Set the mutex used to lock operations on this memory object
sl@0
   247
	*/
sl@0
   248
	void SetLock(DMutex* aLock);
sl@0
   249
sl@0
   250
	/**
sl@0
   251
	Prevents any further mappings being added to this memory object.
sl@0
   252
	*/
sl@0
   253
	void DenyMappings();
sl@0
   254
sl@0
   255
	/**
sl@0
   256
	Return the memory attributes for this object's memory.
sl@0
   257
	*/
sl@0
   258
	FORCE_INLINE TMemoryAttributes Attributes()
sl@0
   259
		{
sl@0
   260
		return (TMemoryAttributes)iAttributes;
sl@0
   261
		}
sl@0
   262
sl@0
   263
	/**
sl@0
   264
	Value for initialising SPageInfo::iFlags when allocating pages.
sl@0
   265
	*/
sl@0
   266
	FORCE_INLINE TUint8 PageInfoFlags()
sl@0
   267
		{
sl@0
   268
		return iAttributes;
sl@0
   269
		}
sl@0
   270
sl@0
   271
	/**
sl@0
   272
	Value for #Mmu::TRamAllocFlags to use when allocating pages.
sl@0
   273
	*/
sl@0
   274
	FORCE_INLINE Mmu::TRamAllocFlags RamAllocFlags()
sl@0
   275
		{
sl@0
   276
		return (Mmu::TRamAllocFlags)iRamAllocFlags;
sl@0
   277
		}
sl@0
   278
sl@0
   279
	/**
sl@0
   280
	Return true if this object is an instance of #DCoarseMemory.
sl@0
   281
	*/
sl@0
   282
	FORCE_INLINE TBool IsCoarse()
sl@0
   283
		{
sl@0
   284
		return iFlags&ECoarseObject;
sl@0
   285
		}
sl@0
   286
sl@0
   287
	/**
sl@0
   288
	Return true if this object contains memory which is being demand paged.
sl@0
   289
	*/
sl@0
   290
	FORCE_INLINE TBool IsDemandPaged()
sl@0
   291
		{
sl@0
   292
		return iFlags&EDemandPaged;
sl@0
   293
		}
sl@0
   294
sl@0
   295
	/**
sl@0
   296
	Return true if writeable mappings of the memory are not allowed.
sl@0
   297
	*/
sl@0
   298
	FORCE_INLINE TBool IsReadOnly()
sl@0
   299
		{
sl@0
   300
		return iFlags&EDenyWriteMappings;
sl@0
   301
		}
sl@0
   302
sl@0
   303
	/**
sl@0
   304
	Return true if executable mappings allowed on this memory object.
sl@0
   305
	*/
sl@0
   306
	FORCE_INLINE TBool IsExecutable()
sl@0
   307
		{
sl@0
   308
		return !(iFlags&EDenyExecuteMappings);
sl@0
   309
		}
sl@0
   310
sl@0
   311
	/**
sl@0
   312
	Clear the flag that indicates that a mapping has been added.
sl@0
   313
	*/
sl@0
   314
	FORCE_INLINE void ClearMappingAddedFlag()
sl@0
   315
		{
sl@0
   316
		__NK_ASSERT_DEBUG(iMappings.LockIsHeld());
sl@0
   317
		__e32_atomic_and_ord8(&iFlags, (TUint8)~EMappingAdded);
sl@0
   318
		}
sl@0
   319
sl@0
   320
	/**
sl@0
   321
	Set the flag to indicate that a mapping has been added.
sl@0
   322
	*/
sl@0
   323
	FORCE_INLINE void SetMappingAddedFlag()
sl@0
   324
		{
sl@0
   325
		__NK_ASSERT_DEBUG(iMappings.LockIsHeld());
sl@0
   326
		__NK_ASSERT_DEBUG(MmuLock::IsHeld());
sl@0
   327
		__e32_atomic_ior_ord8(&iFlags, (TUint8)EMappingAdded);
sl@0
   328
		}
sl@0
   329
sl@0
   330
	/**
sl@0
   331
	Get the value of the mappings added flags
sl@0
   332
sl@0
   333
	@return ETrue if a mapping has been added, EFalse otherwise.
sl@0
   334
	*/
sl@0
   335
	FORCE_INLINE TBool MappingAddedFlag()
sl@0
   336
		{
sl@0
   337
		__NK_ASSERT_DEBUG(MmuLock::IsHeld());
sl@0
   338
		return iFlags & (TUint8)EMappingAdded;
sl@0
   339
		}
sl@0
   340
sl@0
   341
	enum
sl@0
   342
		{
sl@0
   343
		/**
sl@0
   344
		Maximum number of bits which can be stored in an array entry by SetPagingManagerData.
sl@0
   345
		*/
sl@0
   346
		KPagingManagerDataBits = RPageArray::KPagingManagerDataBits
sl@0
   347
		};
sl@0
   348
sl@0
   349
	enum
sl@0
   350
		{
sl@0
   351
		/**
sl@0
   352
		Maximum value which can be stored in an array entry by SetPagingManagerData.
sl@0
   353
		*/
sl@0
   354
		KMaxPagingManagerData = RPageArray::KMaxPagingManagerData
sl@0
   355
		};
sl@0
   356
sl@0
   357
	/**
sl@0
   358
	Write \a aValue to the paging manager data for page index \a aIndex.
sl@0
   359
	The value must not exceed KMaxPagingManagerData.
sl@0
   360
	This must only be used for demand paged memory objects.
sl@0
   361
	*/
sl@0
   362
	void SetPagingManagerData(TUint aIndex, TUint aValue);
sl@0
   363
sl@0
   364
	/**
sl@0
   365
	Return the paging manager data for page index \a aIndex.
sl@0
   366
	This must only be used for demand paged memory objects.
sl@0
   367
	@see SetPagingManagerData
sl@0
   368
	*/
sl@0
   369
	TUint PagingManagerData(TUint aIndex);
sl@0
   370
sl@0
   371
	/**
sl@0
   372
	Check that a given memory mapping is allowed to be attached to this memory object.
sl@0
   373
sl@0
   374
	@param aMapping	The mapping to check.
sl@0
   375
sl@0
   376
	@return KErrNone if successful,
sl@0
   377
			otherwise KErrAccessDenied to indicate that the mapping is not allowed.
sl@0
   378
	*/
sl@0
   379
	TInt CheckNewMapping(DMemoryMappingBase* aMapping);
sl@0
   380
sl@0
   381
	/**
sl@0
   382
	Emit BTrace traces identifying the initial attributes of this object.
sl@0
   383
	*/
sl@0
   384
	void BTraceCreate();
sl@0
   385
sl@0
   386
protected:
sl@0
   387
	/**
sl@0
   388
	@param aManager		The manager object for this memory.
sl@0
   389
	@param aFlags		Initial value for #iFlags.
sl@0
   390
	@param aSizeInPages	Size of the memory object, in number of pages.
sl@0
   391
	@param aAttributes	Bitmask of values from enum #TMemoryAttributes.
sl@0
   392
	@param aCreateFlags	Bitmask of option flags from enum #TMemoryCreateFlags.
sl@0
   393
	*/
sl@0
   394
	DMemoryObject(DMemoryManager* aManager, TUint aFlags, TUint aSizeInPages, TMemoryAttributes aAttributes, TMemoryCreateFlags aCreateFlags);
sl@0
   395
sl@0
   396
	/**
sl@0
   397
	Second phase constructor.
sl@0
   398
sl@0
   399
	@return KErrNone if successful, otherwise one of the system wide error codes.
sl@0
   400
	*/
sl@0
   401
	TInt Construct();
sl@0
   402
sl@0
   403
public:
sl@0
   404
	/**
sl@0
   405
	The manager of this memory object.
sl@0
   406
	*/
sl@0
   407
	DMemoryManager*	iManager;
sl@0
   408
sl@0
   409
	/**
sl@0
   410
	For use by this object's manager (iManager) to store any memory objects specific state
sl@0
   411
	it requires to keep track of.
sl@0
   412
	*/
sl@0
   413
	TAny*			iManagerData;
sl@0
   414
sl@0
   415
	/**
sl@0
   416
	For use by DMemoryManager::QueueCleanup to link objects which require a cleanup operation.
sl@0
   417
	Access to this is protected by #DMemoryManager::iCleanupLock.
sl@0
   418
	*/
sl@0
   419
	DMemoryObject*	iCleanupNext;
sl@0
   420
sl@0
   421
	/**
sl@0
   422
	For use by DMemoryManager::QueueCleanup to store flags representing each pending cleanup operation.
sl@0
   423
	Access to this is protected by #DMemoryManager::iCleanupLock.
sl@0
   424
	*/
sl@0
   425
	TUint32			iCleanupFlags;
sl@0
   426
sl@0
   427
	/**
sl@0
   428
	Bit flags stored in #iFlags giving various state and attributes of the object.
sl@0
   429
	*/
sl@0
   430
	enum TFlags
sl@0
   431
		{
sl@0
   432
		/**
sl@0
   433
		Flag set during object construction to indicate that this mapping is of
sl@0
   434
		class #DCoarseMemory.
sl@0
   435
		*/
sl@0
   436
		ECoarseObject			= 1<<0,
sl@0
   437
sl@0
   438
		/**
sl@0
   439
		Flag set during object construction to indicate that the memory for this object
sl@0
   440
		is being demand paged in some manner.
sl@0
   441
		*/
sl@0
   442
		EDemandPaged			= 1<<1,
sl@0
   443
sl@0
   444
		/**
sl@0
   445
		Flag set during object construction to indicate that all resources for this
sl@0
   446
		object are to be reserved during construction; excluding memory pages owned by
sl@0
   447
		object. Objects constructed in this way will not require additional memory
sl@0
   448
		allocation when committing memory to them (other than allocating the memory
sl@0
   449
		pages being committed.)
sl@0
   450
		*/
sl@0
   451
		EReserveResources		= 1<<2,
sl@0
   452
sl@0
   453
		/**
sl@0
   454
		Flag set during object construction to indicate that pinned memory mappings
sl@0
   455
		are not allowed to be attached to this object.
sl@0
   456
		*/
sl@0
   457
		EDenyPinning			= 1<<3,
sl@0
   458
sl@0
   459
		/**
sl@0
   460
		Flag set by DenyMappings to indicate that no additional memory mappings
sl@0
   461
		are allowed to be attached to this object.
sl@0
   462
		*/
sl@0
   463
		EDenyMappings			= 1<<4,
sl@0
   464
sl@0
   465
		/**
sl@0
   466
		Flag set during object construction, or by SetReadOnly, to indicate that
sl@0
   467
		the memory object is read-only and no writable mappings are allowed
sl@0
   468
		to be attached to this object.
sl@0
   469
		*/
sl@0
   470
		EDenyWriteMappings		= 1<<5,
sl@0
   471
sl@0
   472
		/**
sl@0
   473
		Flag set during object construction to indicate that executable memory mappings
sl@0
   474
		are not allowed to be attached to this object.
sl@0
   475
		This is mainly an optimisation to allow demand paging to avoid instruction cache
sl@0
   476
		maintenance operations during page fault handling.
sl@0
   477
		*/
sl@0
   478
		EDenyExecuteMappings	= 1<<6,
sl@0
   479
sl@0
   480
		/**
sl@0
   481
		Flag set whenever a new mapping is added to a memory object.
sl@0
   482
		The object's mappings lock and MmuLock protects this flag when it is set
sl@0
   483
		and the mappings lock protects when it is cleared.
sl@0
   484
		*/
sl@0
   485
		EMappingAdded			= 1<<7,
sl@0
   486
		};
sl@0
   487
sl@0
   488
	/**
sl@0
   489
	Bitmask of TFlags
sl@0
   490
	*/
sl@0
   491
	TUint8 iFlags;
sl@0
   492
sl@0
   493
	/**
sl@0
   494
	Value from TMemoryAttributes indicating type of memory in object.
sl@0
   495
	*/
sl@0
   496
	TUint8 iAttributes;
sl@0
   497
sl@0
   498
	/**
sl@0
   499
	#Mmu::TRamAllocFlags value to use when allocating RAM for this memory object.
sl@0
   500
	*/
sl@0
   501
	TUint16 iRamAllocFlags;
sl@0
   502
sl@0
   503
	/**
sl@0
   504
	List of mappings currently attached to this object.
sl@0
   505
	*/
sl@0
   506
	TMappingList iMappings;
sl@0
   507
sl@0
   508
	/**
sl@0
   509
	Size, in page units, of this memory object.
sl@0
   510
	*/
sl@0
   511
	TUint iSizeInPages;
sl@0
   512
sl@0
   513
	/**
sl@0
   514
	Lock currently being used to serialise explicit memory operations.
sl@0
   515
	This is assigned using #MemoryObjectLock.
sl@0
   516
	*/
sl@0
   517
	DMutex* iLock;
sl@0
   518
sl@0
   519
	/**
sl@0
   520
	The array of memory pages assigned to this memory object.
sl@0
   521
	*/
sl@0
   522
	RPageArray iPages;
sl@0
   523
	};
sl@0
   524
sl@0
   525
sl@0
   526
sl@0
   527
/**
sl@0
   528
A memory object which has a size that is an exact multiple
sl@0
   529
multiple of the region covered by a whole MMU page table;
sl@0
   530
that is a 'chunk' size (#KChunkSize) bytes.
sl@0
   531
sl@0
   532
When used in conjunction with DCoarseMapping this object
sl@0
   533
allows RAM to be saved by sharing MMU page tables between multiple
sl@0
   534
different mappings of the memory.
sl@0
   535
sl@0
   536
Fine memory mappings (DFineMapping) may also be attached
sl@0
   537
to this memory object but these won't benefit from page table
sl@0
   538
sharing.
sl@0
   539
*/
sl@0
   540
class DCoarseMemory : public DMemoryObject
sl@0
   541
	{
sl@0
   542
public:
sl@0
   543
	// from DMemoryObject...
sl@0
   544
	virtual ~DCoarseMemory();
sl@0
   545
	virtual TInt ClaimInitialPages(TLinAddr aBase, TUint aSize, TMappingPermissions aPermissions, TBool aAllowGaps=false, TBool aAllowNonRamPages=false);
sl@0
   546
	virtual TInt MapPages(RPageArray::TIter aPages);
sl@0
   547
	virtual void RemapPage(TPhysAddr& aPageArray, TUint aIndex, TBool aInvalidateTLB);
sl@0
   548
	virtual void UnmapPages(RPageArray::TIter aPages, TBool aDecommitting);
sl@0
   549
	virtual void RestrictPages(RPageArray::TIter aPages, TRestrictPagesType aRestriction);
sl@0
   550
	virtual TInt AddMapping(DMemoryMappingBase* aMapping);
sl@0
   551
	virtual void RemoveMapping(DMemoryMappingBase* aMapping);
sl@0
   552
	virtual TInt SetReadOnly();
sl@0
   553
	virtual DMemoryMapping* CreateMapping(TUint aIndex, TUint aCount);
sl@0
   554
public:
sl@0
   555
	/**
sl@0
   556
	Create a new DCoarseMemory object.
sl@0
   557
sl@0
   558
	@param aManager		The manager object for this memory.
sl@0
   559
	@param aSizeInPages	Size of the memory object, in number of pages.
sl@0
   560
						(Must represent an exact 'chunk' size.)
sl@0
   561
	@param aAttributes	Bitmask of values from enum #TMemoryAttributes.
sl@0
   562
	@param aCreateFlags	Bitmask of option flags from enum #TMemoryCreateFlags.
sl@0
   563
sl@0
   564
	@return The newly created DCoarseMemory or the null pointer if there was
sl@0
   565
			insufficient memory.
sl@0
   566
	*/
sl@0
   567
	static DCoarseMemory* New(DMemoryManager* aManager, TUint aSizeInPages, TMemoryAttributes aAttributes, TMemoryCreateFlags aCreateFlags);
sl@0
   568
sl@0
   569
	/**
sl@0
   570
	Remove an mmu page table from this memory object's ownership.
sl@0
   571
	This is called when a RAM page containing the page table is paged out.
sl@0
   572
	This function delegates its action to DPageTables::StealPageTable.
sl@0
   573
sl@0
   574
	@param aChunkIndex	The index of the page table, i.e. the offset, in 'chunks',
sl@0
   575
						into the object's memory that the page table is being used to map.
sl@0
   576
						(The index into DPageTables::iTables.)
sl@0
   577
	@param aPteType		The #TPteType the page table is being used for.
sl@0
   578
						(The index into #iPageTables.)
sl@0
   579
sl@0
   580
	@pre #MmuLock is held.
sl@0
   581
	@pre #PageTablesLockIsHeld
sl@0
   582
	*/
sl@0
   583
	void StealPageTable(TUint aChunkIndex, TUint aPteType);
sl@0
   584
sl@0
   585
public:
sl@0
   586
	// Interface for DCoarseMapping
sl@0
   587
	
sl@0
   588
	/**
sl@0
   589
	Get the page table to use for mapping a specified chunk if it exists.
sl@0
   590
sl@0
   591
	@param aPteType		The #TPteType the page tables will be used for.
sl@0
   592
	@param aChunkIndex	The index of the chunk.
sl@0
   593
sl@0
   594
	@return The virtual address of the page table, or NULL.
sl@0
   595
sl@0
   596
	@pre #MmuLock is held.
sl@0
   597
	*/
sl@0
   598
	TPte* GetPageTable(TUint aPteType , TUint aChunkIndex);
sl@0
   599
sl@0
   600
	/**
sl@0
   601
	Update the page tables to add entries for a specified set of demand paged memory
sl@0
   602
	pages following a 'page in' or memory pinning operation.
sl@0
   603
sl@0
   604
	@param aMapping				The mapping the pages are being paged into.
sl@0
   605
	
sl@0
   606
	@param aPages				An RPageArray::TIter which refers to a range of pages
sl@0
   607
								in the memory object #iMemory.
sl@0
   608
								Only array entries which have state RPageArray::ECommitted
sl@0
   609
								should be mapped into the page tables.
sl@0
   610
sl@0
   611
	@param aPinArgs				The resources required to pin any page tables.
sl@0
   612
								Page table must be pinned if \a aPinArgs.iPinnedPageTables is
sl@0
   613
								not the null pointer, in which case this the virtual address
sl@0
   614
								of the pinned must be stored in the array this points to.
sl@0
   615
								\a aPinArgs.iReadOnly is true if write access permissions
sl@0
   616
								are not needed.
sl@0
   617
sl@0
   618
	@return KErrNone if successful, otherwise one of the system wide error codes.
sl@0
   619
sl@0
   620
	@pre #MmuLock is held.
sl@0
   621
	@post #MmuLock has been released.
sl@0
   622
	*/
sl@0
   623
	TInt PageIn(DCoarseMapping* aMapping, RPageArray::TIter aPages, TPinArgs& aPinArgs, TUint aMapInstanceCount);
sl@0
   624
sl@0
   625
	/**
sl@0
   626
	Update the page table entries to renable access to a specified memory page.
sl@0
   627
sl@0
   628
	This method is called by #DCoarseMapping::MovingPageIn
sl@0
   629
sl@0
   630
	@param aMapping				The mapping which maps the page.
sl@0
   631
	@param aPageArrayPtr		The page array entry of the page to map.
sl@0
   632
								Only array entries which have state RPageArray::ECommitted
sl@0
   633
								should be mapped into a mapping's page tables.
sl@0
   634
sl@0
   635
	@param aIndex				The index of the memory page.
sl@0
   636
	*/
sl@0
   637
	TBool MovingPageIn(DCoarseMapping* aMapping, TPhysAddr& aPageArrayPtr, TUint aIndex);
sl@0
   638
sl@0
   639
	/**
sl@0
   640
	Function to return a page table pointer for the specified linear address and
sl@0
   641
	index to this mapping.
sl@0
   642
sl@0
   643
	This method is called by #DCoarseMapping::FindPageTable.
sl@0
   644
	
sl@0
   645
	@param aLinAddr		The linear address to find the page table entry for.
sl@0
   646
	@param aMemoryIndex	The memory object index of the page to find the page 
sl@0
   647
						table entry for.
sl@0
   648
	
sl@0
   649
	@return A pointer to the page table entry, if the page table entry couldn't 
sl@0
   650
			be found this will be NULL
sl@0
   651
	*/
sl@0
   652
	TPte* FindPageTable(DCoarseMapping* aMapping, TLinAddr aLinAddr, TUint aMemoryIndex);
sl@0
   653
	
sl@0
   654
protected:
sl@0
   655
	/**
sl@0
   656
	For arguments, see #New.
sl@0
   657
	*/
sl@0
   658
	DCoarseMemory(DMemoryManager* aManager, TUint aSizeInPages, TMemoryAttributes aAttributes, TMemoryCreateFlags aCreateFlags);
sl@0
   659
	
sl@0
   660
public:
sl@0
   661
	/**
sl@0
   662
	The object which manages the page tables owned by a #DCoarseMemory object
sl@0
   663
	and used by #DCoarseMapping objects. Each DPageTables is used for mappings
sl@0
   664
	with a specific #TPteType e.g. set of memory access permissions, and all these
sl@0
   665
	#DCoarseMapping objects are linked into this object whenever they are
sl@0
   666
	attached to a DCoarseMemory.
sl@0
   667
	*/
sl@0
   668
	class DPageTables : public DReferenceCountedObject
sl@0
   669
		{
sl@0
   670
	public:
sl@0
   671
		/**
sl@0
   672
		Create a new DPageTables.
sl@0
   673
sl@0
   674
		This object is added to DCoarseMemory::iPageTables and all of
sl@0
   675
		the mmu page tables will be initialised to map the memory currently
sl@0
   676
		owned by the memory object (unless memory is demand paged).
sl@0
   677
sl@0
   678
sl@0
   679
		@param aMemory		The DCoarseMemory the new object is associated with.
sl@0
   680
		@param aNumPages	Size of the memory object, in number of pages.
sl@0
   681
							(Must represent an exact 'chunk' size.)
sl@0
   682
		@param aPteType		The #TPteType the page tables will be used for.
sl@0
   683
sl@0
   684
		@return The newly created DPageTables or the null pointer if there was
sl@0
   685
				insufficient memory.
sl@0
   686
sl@0
   687
		@pre The #MemoryObjectLock for the memory must be held by the current thread.
sl@0
   688
		*/
sl@0
   689
		static DPageTables* New(DCoarseMemory* aMemory, TUint aNumPages, TUint aPteType);
sl@0
   690
sl@0
   691
		virtual ~DPageTables();
sl@0
   692
sl@0
   693
		/**
sl@0
   694
		Update the page tables to add entries for a specified set of memory pages.
sl@0
   695
sl@0
   696
		This method is called by #DCoarseMemory::MapPages.
sl@0
   697
sl@0
   698
		@param aPages				An RPageArray::TIter which refers to a range of pages
sl@0
   699
									in the memory object #iMemory.
sl@0
   700
									Only array entries which have state RPageArray::ECommitted
sl@0
   701
									should be mapped into the page tables.
sl@0
   702
sl@0
   703
		@return KErrNone if successful, otherwise one of the system wide error codes.
sl@0
   704
		*/
sl@0
   705
		virtual TInt MapPages(RPageArray::TIter aPages);
sl@0
   706
sl@0
   707
		/**
sl@0
   708
		Update the page table entries for a specified memory page.
sl@0
   709
sl@0
   710
		This method is called by #DCoarseMemory::RemapPage
sl@0
   711
sl@0
   712
		@param aPageArray			The page array entry of the page in this memory object.
sl@0
   713
									Only array entries which have state RPageArray::ECommitted
sl@0
   714
									should be mapped into a mapping's page tables.
sl@0
   715
sl@0
   716
		@param aIndex				The index of the page in this memory object.
sl@0
   717
sl@0
   718
		@param	aInvalidateTLB		Set to ETrue when the TLB entries associated with this page
sl@0
   719
									should be invalidated.  This must be done when there is 
sl@0
   720
									already a valid pte for this page, i.e. if the page is still 
sl@0
   721
									mapped.
sl@0
   722
		*/
sl@0
   723
		virtual void RemapPage(TPhysAddr& aPageArray, TUint aIndex, TBool aInvalidateTLB);
sl@0
   724
sl@0
   725
		/**
sl@0
   726
		Update the page table entries to renable access to a specified memory page.
sl@0
   727
sl@0
   728
		This method is called by #DCoarseMemory::MovingPageIn
sl@0
   729
sl@0
   730
		@param aPageArrayPtr		The page array entry of the page to map.
sl@0
   731
									Only array entries which have state RPageArray::ECommitted
sl@0
   732
									should be mapped into a mapping's page tables.
sl@0
   733
sl@0
   734
		@param aIndex				The index of the memory page.
sl@0
   735
		*/
sl@0
   736
		virtual TBool MovingPageIn(TPhysAddr& aPageArrayPtr, TUint aIndex);
sl@0
   737
sl@0
   738
sl@0
   739
		/**
sl@0
   740
		Update the page tables to remove entries for a specified set of memory pages.
sl@0
   741
sl@0
   742
		This method is called by #DCoarseMemory::UnmapPages.
sl@0
   743
sl@0
   744
		@param aPages				An RPageArray::TIter which refers to a range of pages
sl@0
   745
									in the memory object #iMemory.
sl@0
   746
									Only array entries which return true for
sl@0
   747
									RPageArray::TargetStateIsDecommitted should be unmapped
sl@0
   748
									from the page tables.
sl@0
   749
sl@0
   750
		@param aDecommitting		True if memory is being permanently decommitted from
sl@0
   751
									the memory object. False if the memory pages are only
sl@0
   752
									temporarily being unmapped due to a demand paging 'page out'
sl@0
   753
									operation.
sl@0
   754
		*/
sl@0
   755
		virtual void UnmapPages(RPageArray::TIter aPages, TBool aDecommitting);
sl@0
   756
sl@0
   757
		/**
sl@0
   758
		Update the page tables to apply access restrictions to a specified set of memory pages.
sl@0
   759
sl@0
   760
		This method is called by #DCoarseMemory::RestrictPagesNA.
sl@0
   761
sl@0
   762
		@param aPages				An RPageArray::TIter which refers to a range of pages
sl@0
   763
									in the memory object #iMemory.
sl@0
   764
									Only array entries which return true for
sl@0
   765
									RPageArray::TargetStateIsDecommitted should be unmapped
sl@0
   766
									from the page tables.
sl@0
   767
		*/
sl@0
   768
		virtual void RestrictPagesNA(RPageArray::TIter aPages);
sl@0
   769
sl@0
   770
		/**
sl@0
   771
		Update the page tables to add entries for a specified set of demand paged memory
sl@0
   772
		pages following a 'page in' or memory pinning operation.
sl@0
   773
sl@0
   774
		@param aPages				An RPageArray::TIter which refers to a range of pages
sl@0
   775
									in the memory object #iMemory.
sl@0
   776
									Only array entries which have state RPageArray::ECommitted
sl@0
   777
									should be mapped into the page tables.
sl@0
   778
sl@0
   779
		@param aPinArgs				The resources required to pin any page tables.
sl@0
   780
									Page table must be pinned if \a aPinArgs.iPinnedPageTables is
sl@0
   781
									not the null pointer, in which case this the virtual address
sl@0
   782
									of the pinned must be stored in the array this points to.
sl@0
   783
									\a aPinArgs.iReadOnly is true if write access permissions
sl@0
   784
									are not needed.
sl@0
   785
sl@0
   786
		@param aMapping				The mapping that took the page fault or is being pinned.
sl@0
   787
sl@0
   788
		@param aMapInstanceCount	The instance count of the mapping.
sl@0
   789
sl@0
   790
		@return KErrNone if successful, otherwise one of the system wide error codes.
sl@0
   791
		*/
sl@0
   792
		virtual TInt PageIn(RPageArray::TIter aPages, TPinArgs& aPinArgs,
sl@0
   793
							DMemoryMappingBase* aMapping, TUint aMapInstanceCount);
sl@0
   794
sl@0
   795
		/**
sl@0
   796
		Flush the MMUs TLB entries associated with all attached memory mappings
sl@0
   797
		for a specified region of memory pages.
sl@0
   798
sl@0
   799
		This is used by UnmapPages and RestrictPages.
sl@0
   800
sl@0
   801
		@param aStartIndex	Page index, within the memory, for start of the region.
sl@0
   802
		@param aEndIndex	Page index, within the memory, for the first page after
sl@0
   803
							the end of the region.
sl@0
   804
		*/
sl@0
   805
		void FlushTLB(TUint aStartIndex, TUint aEndIndex);
sl@0
   806
sl@0
   807
sl@0
   808
		/**
sl@0
   809
		Get the page table being used for a specified chunk index if it exists.
sl@0
   810
sl@0
   811
		@param aChunkIndex	The index into #iTables of the page table.
sl@0
   812
sl@0
   813
		@return The virtual address of the page table,
sl@0
   814
				or the null pointer if one wasn't found.
sl@0
   815
		*/
sl@0
   816
		inline TPte* GetPageTable(TUint aChunkIndex)
sl@0
   817
			{
sl@0
   818
			__NK_ASSERT_DEBUG(MmuLock::IsHeld());
sl@0
   819
			return iTables[aChunkIndex];
sl@0
   820
			}
sl@0
   821
sl@0
   822
		/**
sl@0
   823
		Get the page table being used for a specified chunk index; allocating
sl@0
   824
		a new one if it didn't previously exist.
sl@0
   825
sl@0
   826
		@param aChunkIndex	The index into #iTables of the page table.
sl@0
   827
sl@0
   828
		@return The virtual address of the page table,
sl@0
   829
				or the null pointer if one wasn't found and couldn't be allocated.
sl@0
   830
		*/
sl@0
   831
		TPte* GetOrAllocatePageTable(TUint aChunkIndex);
sl@0
   832
sl@0
   833
		/**
sl@0
   834
		Get and pin the page table being for a specified chunk index; allocating
sl@0
   835
		a new one if it didn't previously exist.
sl@0
   836
sl@0
   837
		@param aChunkIndex	The index into #iTables of the page table.
sl@0
   838
		@param aPinArgs		The resources required to pin the page table.
sl@0
   839
							On success, the page table will have been appended to
sl@0
   840
							\a aPinArgs.iPinnedPageTables.
sl@0
   841
sl@0
   842
		@return The virtual address of the page table,
sl@0
   843
				or the null pointer if one wasn't found and couldn't be allocated.
sl@0
   844
		*/
sl@0
   845
		TPte* GetOrAllocatePageTable(TUint aChunkIndex, TPinArgs& aPinArgs);
sl@0
   846
sl@0
   847
		/**
sl@0
   848
		Allocate a single page table.
sl@0
   849
sl@0
   850
		@param aChunkIndex	The index into #iTables of the page table.
sl@0
   851
		@param aDemandPaged True if the page table is for mapping demand paged memory.  Most of the
sl@0
   852
		                    time this will be determined by the #EDemandPaged bit in #iFlags.
sl@0
   853
		@param aPermanent	True, if the page table's permanence count is to be incremented.
sl@0
   854
sl@0
   855
		@return The virtual address of the page table,
sl@0
   856
				or the null pointer if one wasn't found and couldn't be allocated.
sl@0
   857
		*/
sl@0
   858
		TPte* AllocatePageTable(TUint aChunkIndex, TBool aDemandPaged, TBool aPermanent=false);
sl@0
   859
sl@0
   860
		/**
sl@0
   861
		Free a single page table if it is unused.
sl@0
   862
sl@0
   863
		@param aChunkIndex	The index into #iTables of the page table.
sl@0
   864
		*/
sl@0
   865
		void FreePageTable(TUint aChunkIndex);
sl@0
   866
sl@0
   867
		/**
sl@0
   868
		Allocate all the mmu page tables for this object (iTables) and ensure that
sl@0
   869
		they are not freed even when they no longer map any pages.
sl@0
   870
sl@0
   871
		This method increments iPermanenceCount.
sl@0
   872
sl@0
   873
		This is called by DCoarseMemory::AddMapping when a memory mapping is
sl@0
   874
		added with the #DMemoryMappingBase::EPermanentPageTables attribute is set.
sl@0
   875
		This will also be true if the memory object has the #EReserveResources
sl@0
   876
		attribute.
sl@0
   877
sl@0
   878
		@pre The #MemoryObjectLock for the memory must be held by the current thread.
sl@0
   879
sl@0
   880
		@return KErrNone if successful, otherwise one of the system wide error codes.
sl@0
   881
		*/
sl@0
   882
		TInt AllocatePermanentPageTables();
sl@0
   883
sl@0
   884
		/**
sl@0
   885
		Reverses the action of #AllocatePermanentPageTables.
sl@0
   886
sl@0
   887
		This method decrements iPermanenceCount and if this reaches zero,
sl@0
   888
		the mmu page tables for this object are freed if the are no longer in use.
sl@0
   889
		*/
sl@0
   890
		void FreePermanentPageTables();
sl@0
   891
sl@0
   892
		/**
sl@0
   893
		This is called by DCoarseMemory::AddMapping when a coarse memory mapping is
sl@0
   894
		added.
sl@0
   895
sl@0
   896
		@param aMapping	The coarse memory mapping to add.
sl@0
   897
sl@0
   898
		@return KErrNone if successful, otherwise one of the system wide error codes.
sl@0
   899
		*/
sl@0
   900
		TInt AddMapping(DCoarseMapping* aMapping);
sl@0
   901
sl@0
   902
		/**
sl@0
   903
		This is called by DCoarseMemory::RemoveMapping when a coarse memory mapping is
sl@0
   904
		removed.
sl@0
   905
sl@0
   906
		@param aMapping	The coarse memory mapping to remove.
sl@0
   907
		*/
sl@0
   908
		void RemoveMapping(DCoarseMapping* aMapping);
sl@0
   909
sl@0
   910
		/**
sl@0
   911
		Overriding DReferenceCountedObject::Close.
sl@0
   912
		This removes the linkage with #iMemory if this object is deleted.
sl@0
   913
		*/
sl@0
   914
		void Close();
sl@0
   915
sl@0
   916
		/**
sl@0
   917
		Overriding DReferenceCountedObject::AsyncClose.
sl@0
   918
		This removes the linkage with #iMemory if this object is deleted.
sl@0
   919
		*/
sl@0
   920
		void AsyncClose();
sl@0
   921
sl@0
   922
		/**
sl@0
   923
		Remove an mmu page table from this object's ownership.
sl@0
   924
		This is called from DCoarseMemory::StealPageTable when a RAM page containing
sl@0
   925
		the page table is paged out.
sl@0
   926
sl@0
   927
		@param aChunkIndex	The index into #iTables of the page table.
sl@0
   928
sl@0
   929
		@pre #MmuLock is held.
sl@0
   930
		@pre #PageTablesLockIsHeld
sl@0
   931
		*/
sl@0
   932
		void StealPageTable(TUint aChunkIndex);
sl@0
   933
		
sl@0
   934
	protected:
sl@0
   935
		/**
sl@0
   936
		For arguments, see #New.
sl@0
   937
		*/
sl@0
   938
		DPageTables(DCoarseMemory* aMemory, TInt aNumPts, TUint aPteType);
sl@0
   939
sl@0
   940
		/**
sl@0
   941
		Second phase constructor.
sl@0
   942
sl@0
   943
		This initialises all of the mmu page tables to map the memory currently owned
sl@0
   944
		by the memory object (#iMemory).
sl@0
   945
sl@0
   946
		@return KErrNone if successful, otherwise one of the system wide error codes.
sl@0
   947
		*/
sl@0
   948
		TInt Construct();
sl@0
   949
sl@0
   950
	private:
sl@0
   951
		/**
sl@0
   952
		Reverses the action of #AllocatePermanentPageTables for a range of page tables.
sl@0
   953
sl@0
   954
		This is an implementation factor for #FreePermanentPageTables().
sl@0
   955
sl@0
   956
		@param aChunkIndex	The index into #iTables of the first page table.
sl@0
   957
		@param aChunkCount	The number of page tables.
sl@0
   958
		*/
sl@0
   959
		void FreePermanentPageTables(TUint aChunkIndex, TUint aChunkCount);
sl@0
   960
sl@0
   961
		/**
sl@0
   962
		Assign a newly allocated page table to this object.
sl@0
   963
sl@0
   964
		This adds the page table to the page directory entries associated with
sl@0
   965
		all mappings attached to this object.
sl@0
   966
sl@0
   967
		@param aChunkIndex	The index into #iTables of the page table.
sl@0
   968
		@param aPageTable	The page table.
sl@0
   969
sl@0
   970
		@pre #PageTablesLockIsHeld.
sl@0
   971
		*/
sl@0
   972
		void AssignPageTable(TUint aChunkIndex, TPte* aPageTable);
sl@0
   973
sl@0
   974
		/**
sl@0
   975
		Unassign a page table to this object.
sl@0
   976
sl@0
   977
		This removes the page table from the page directory entries associated with
sl@0
   978
		all mappings attached to this object.
sl@0
   979
sl@0
   980
		This is called by FreePageTable and StealPageTable.
sl@0
   981
sl@0
   982
		@param aChunkIndex	The index into #iTables of the page table.
sl@0
   983
sl@0
   984
		@pre #PageTablesLockIsHeld.
sl@0
   985
		*/
sl@0
   986
		void UnassignPageTable(TUint aChunkIndex);
sl@0
   987
sl@0
   988
	public:
sl@0
   989
		/**
sl@0
   990
		The coarse memory object which owns us.
sl@0
   991
		*/
sl@0
   992
		DCoarseMemory* iMemory;
sl@0
   993
sl@0
   994
		/**
sl@0
   995
		The #TPteType the page tables are being used for.
sl@0
   996
		(This object's index in #iMemory->iPageTables.)
sl@0
   997
		*/
sl@0
   998
		TUint iPteType;
sl@0
   999
sl@0
  1000
		/**
sl@0
  1001
		The list of coarse mappings attached to this object.
sl@0
  1002
		These mappings use the mmu page tables owned by us.
sl@0
  1003
		*/
sl@0
  1004
		TMappingList iMappings;
sl@0
  1005
sl@0
  1006
		/**
sl@0
  1007
		The page table entry (PTE) value for use when mapping pages into the page tables.
sl@0
  1008
		This value has the physical address component being zero, so a page's physical
sl@0
  1009
		address can be simply ORed in.
sl@0
  1010
		*/
sl@0
  1011
		TPte iBlankPte;
sl@0
  1012
sl@0
  1013
		/**
sl@0
  1014
		Reference count for the number of times #AllocatePermanentPageTables
sl@0
  1015
		has been called without #FreePermanentPageTables.
sl@0
  1016
		*/
sl@0
  1017
		TUint iPermanenceCount;
sl@0
  1018
sl@0
  1019
		/**
sl@0
  1020
		Number of entries in #iTables.
sl@0
  1021
		*/
sl@0
  1022
		TUint iNumPageTables;
sl@0
  1023
sl@0
  1024
		/**
sl@0
  1025
		Array of page tables owned by this object. This may extend into memory
sl@0
  1026
		beyond the end of this object and contains #iNumPageTables entries.
sl@0
  1027
sl@0
  1028
		Each entry in the array corresponds to a #KChunkSize sized region of #iMemory.
sl@0
  1029
		The null pointer indicating that no page table exists for the corresponding
sl@0
  1030
		region.
sl@0
  1031
sl@0
  1032
		The contents of the array are protected by the PageTableAllocator lock AND #MmuLock
sl@0
  1033
		*/
sl@0
  1034
		TPte* iTables[1];
sl@0
  1035
		};
sl@0
  1036
sl@0
  1037
private:
sl@0
  1038
	/**
sl@0
  1039
	Get or allocate the page tables container for a given PTE type
sl@0
  1040
sl@0
  1041
	@pre #MemoryObjectLock for this object must be held.
sl@0
  1042
	*/
sl@0
  1043
	DPageTables* GetOrAllocatePageTables(TUint aPteType);
sl@0
  1044
sl@0
  1045
protected:
sl@0
  1046
	/**
sl@0
  1047
	Array of #DPageTables objects owned by this memory object.
sl@0
  1048
	Updates to this array require the #MmuLock.
sl@0
  1049
	*/
sl@0
  1050
	DPageTables* iPageTables[ENumPteTypes];
sl@0
  1051
sl@0
  1052
	friend class DCoarseMemory::DPageTables;  // for DPageTables::Close() / AsyncClose()
sl@0
  1053
	};
sl@0
  1054
sl@0
  1055
sl@0
  1056
sl@0
  1057
/**
sl@0
  1058
A memory object without the special case optimisations of DCoarseMemory.
sl@0
  1059
*/
sl@0
  1060
class DFineMemory : public DMemoryObject
sl@0
  1061
	{
sl@0
  1062
public:
sl@0
  1063
	// from DMemoryObject...
sl@0
  1064
	virtual ~DFineMemory();
sl@0
  1065
	virtual TInt ClaimInitialPages(TLinAddr aBase, TUint aSize, TMappingPermissions aPermissions, TBool aAllowGaps=false, TBool aAllowNonRamPages=false);
sl@0
  1066
sl@0
  1067
public:
sl@0
  1068
	/**
sl@0
  1069
	Create a new DFineMemory object.
sl@0
  1070
sl@0
  1071
	@param aManager		The manager object for this memory.
sl@0
  1072
	@param aSizeInPages	Size of the memory object, in number of pages.
sl@0
  1073
	@param aAttributes	Bitmask of values from enum #TMemoryAttributes.
sl@0
  1074
	@param aCreateFlags	Bitmask of option flags from enum #TMemoryCreateFlags.
sl@0
  1075
sl@0
  1076
	@return The newly created DFineMemory or the null pointer if there was
sl@0
  1077
			insufficient memory.
sl@0
  1078
	*/
sl@0
  1079
	static DFineMemory* New(DMemoryManager* aManager, TUint aSizeInPages, TMemoryAttributes aAttributes, TMemoryCreateFlags aCreateFlags);
sl@0
  1080
sl@0
  1081
private:
sl@0
  1082
	/**
sl@0
  1083
	For arguments, see #New.
sl@0
  1084
	*/
sl@0
  1085
	DFineMemory(DMemoryManager* aManager, TUint aSizeInPages, TMemoryAttributes aAttributes, TMemoryCreateFlags aCreateFlags);
sl@0
  1086
	};
sl@0
  1087
sl@0
  1088
sl@0
  1089
#endif