kernel/eka/memmodel/epoc/flexible/mmu/mmu.h
branchRCL_3
changeset 87 2f92ad2dc5db
parent 0 a41df078684a
child 110 c734af59ce98
equal deleted inserted replaced
81:e7d2d738d3c2 87:2f92ad2dc5db
    84 
    84 
    85 		/**
    85 		/**
    86 		Page is in an indeterminate state.
    86 		Page is in an indeterminate state.
    87 
    87 
    88 		A page is placed into this state by Mmu::PagesAllocated when it is
    88 		A page is placed into this state by Mmu::PagesAllocated when it is
    89 		allocated (ceases to be #EUnused). Once the page
    89 		allocated (ceases to be #EUnused). Once the page has been assigned to 
       
    90 		its new use its type will be updated.
    90 		*/
    91 		*/
    91 		EUnknown,
    92 		EUnknown,
    92 
    93 
    93 		/**
    94 		/**
    94 		Page was allocated with Mmu::AllocPhysicalRam, Mmu::ClaimPhysicalRam
    95 		Page was allocated with Mmu::AllocPhysicalRam, Mmu::ClaimPhysicalRam
   220 
   221 
   221 	union
   222 	union
   222 		{
   223 		{
   223 		/**
   224 		/**
   224 		The memory object which owns this page.
   225 		The memory object which owns this page.
   225 		Used for always set for #EManaged pages and can be set for #PhysAlloc pages.
   226 		Always set for #EManaged pages and can be set for #PhysAlloc pages.
   226 		*/
   227 		*/
   227 		DMemoryObject* iOwner;
   228 		DMemoryObject* iOwner;
   228 
   229 
   229 		/**
   230 		/**
   230 		A pointer to the SPageInfo of the page that is being shadowed.
   231 		A pointer to the SPageInfo of the page that is being shadowed.
   299 	/**
   300 	/**
   300 	Return a SPageInfo by conversion from the address of its embedded link member #iLink.
   301 	Return a SPageInfo by conversion from the address of its embedded link member #iLink.
   301 	*/
   302 	*/
   302 	FORCE_INLINE static SPageInfo* FromLink(SDblQueLink* aLink)
   303 	FORCE_INLINE static SPageInfo* FromLink(SDblQueLink* aLink)
   303 		{
   304 		{
   304 		return (SPageInfo*)((TInt)aLink-_FOFF(SPageInfo,iLink));
   305 		return _LOFF(aLink, SPageInfo, iLink);
   305 		}
   306 		}
   306 
   307 
   307 	//
   308 	//
   308 	// Getters...
   309 	// Getters...
   309 	//
   310 	//
   485 		__NK_ASSERT_DEBUG(!iOriginalPageInfo);
   486 		__NK_ASSERT_DEBUG(!iOriginalPageInfo);
   486 		iOriginalPageInfo = aOrigPageInfo;
   487 		iOriginalPageInfo = aOrigPageInfo;
   487 		}
   488 		}
   488 
   489 
   489 	/**
   490 	/**
   490 	Reutrns a pointer to the SPageInfo of the page that this page is shadowing.
   491 	Returns a pointer to the SPageInfo of the page that this page is shadowing.
   491 
   492 
   492 	@return	A pointer to the SPageInfo that this page is shadowing
   493 	@return	A pointer to the SPageInfo that this page is shadowing
   493 
   494 
   494 	@pre #MmuLock held.
   495 	@pre #MmuLock held.
   495 	*/
   496 	*/
   572 		iPagedState = aPagedState;
   573 		iPagedState = aPagedState;
   573 		iModifier = 0;
   574 		iModifier = 0;
   574 		}
   575 		}
   575 
   576 
   576 	/**
   577 	/**
   577 	The the pages #iModifier value.
   578 	Set the page's #iModifier value.
   578 
   579 
   579 	#iModifier is cleared to zero whenever the usage or paging state of the page
   580 	#iModifier is cleared to zero whenever the usage or paging state of the page
   580 	changes. So if a thread sets this to a suitable unique value (e.g. the address
   581 	changes. So if a thread sets this to a suitable unique value (e.g. the address
   581 	of a local variable) then it may perform a long running operation on the page
   582 	of a local variable) then it may perform a long running operation on the page
   582 	and later check with #CheckModified that no other thread has changed the page
   583 	and later check with #CheckModified that no other thread has changed the page
  1433 	Return a pointer to a SPageTableInfo by conversion from the address
  1434 	Return a pointer to a SPageTableInfo by conversion from the address
  1434 	of its embedded link as returned by #FreeLink.
  1435 	of its embedded link as returned by #FreeLink.
  1435 	*/
  1436 	*/
  1436 	FORCE_INLINE static SPageTableInfo* FromFreeLink(SDblQueLink* aLink)
  1437 	FORCE_INLINE static SPageTableInfo* FromFreeLink(SDblQueLink* aLink)
  1437 		{
  1438 		{
  1438 		return (SPageTableInfo*)((TInt)aLink-_FOFF(SPageTableInfo,iUnused));
  1439 		return _LOFF(aLink, SPageTableInfo, iUnused);
  1439 		}
  1440 		}
  1440 
  1441 
  1441 	/**
  1442 	/**
  1442 	Return the SPageTableInfo for the first page table in the same
  1443 	Return the SPageTableInfo for the first page table in the same
  1443 	physical ram page as the page table for this SPageTableInfo.
  1444 	physical ram page as the page table for this SPageTableInfo.
  1710 	__UNLOCK_GUARD_END(MmuLock); // fault if MmuLock released by SomeCode or SomeMoreCode
  1711 	__UNLOCK_GUARD_END(MmuLock); // fault if MmuLock released by SomeCode or SomeMoreCode
  1711 	@endcode
  1712 	@endcode
  1712 	*/
  1713 	*/
  1713 	static FORCE_INLINE void UnlockGuardStart()
  1714 	static FORCE_INLINE void UnlockGuardStart()
  1714 		{
  1715 		{
  1715 		#ifdef _DEBUG
  1716 #ifdef _DEBUG
  1716 			++UnlockGuardNest;
  1717 		++UnlockGuardNest;
  1717 		#endif
  1718 #endif
  1718 		}
  1719 		}
  1719 
  1720 
  1720 	/**
  1721 	/**
  1721 	End a debug check testing that the MmuLock is not unlocked unexpectedly.
  1722 	End a debug check testing that the MmuLock is not unlocked unexpectedly.
  1722 	This is usually used via the #__UNLOCK_GUARD_END which faults if true is returned.
  1723 	This is usually used via the #__UNLOCK_GUARD_END which faults if true is returned.
  1723 
  1724 
  1724 	@see UnlockGuardStart
  1725 	@see UnlockGuardStart
  1725 
  1726 
  1726 	@return True if the MmuLock was released between a previous #UnlockGuardStart
  1727 	@return EFalse if the MmuLock was released between a previous #UnlockGuardStart
  1727 			and the call this function.
  1728 			and the call this function.
  1728 	*/
  1729 	*/
  1729 	static FORCE_INLINE TBool UnlockGuardEnd()
  1730 	static FORCE_INLINE TBool UnlockGuardEnd()
  1730 		{
  1731 		{
  1731 		#ifdef _DEBUG
  1732 #ifdef _DEBUG
  1732 			__NK_ASSERT_DEBUG(UnlockGuardNest);
  1733 		__NK_ASSERT_DEBUG(UnlockGuardNest);
  1733 			--UnlockGuardNest;
  1734 		--UnlockGuardNest;
  1734 			return UnlockGuardFail==0;
  1735 		return UnlockGuardFail==0;
  1735 		#else
  1736 #else
  1736 			return true;
  1737 		return ETrue;
  1737 		#endif
  1738 #endif
  1738 		}
  1739 		}
  1739 
  1740 
  1740 private:
  1741 private:
  1741 	/**
  1742 	/**
  1742 	Exectued whenever the lock is released to check that
  1743 	Exectued whenever the lock is released to check that
  1743 	#UnlockGuardStart and #UnlockGuardEnd are balanced.
  1744 	#UnlockGuardStart and #UnlockGuardEnd are balanced.
  1744 	*/
  1745 	*/
  1745 	static FORCE_INLINE void UnlockGuardCheck()
  1746 	static FORCE_INLINE void UnlockGuardCheck()
  1746 		{
  1747 		{
  1747 		#ifdef _DEBUG
  1748 #ifdef _DEBUG
  1748 			if(UnlockGuardNest)
  1749 		if(UnlockGuardNest)
  1749 				UnlockGuardFail = true;
  1750 			UnlockGuardFail = ETrue;
  1750 		#endif
  1751 #endif
  1751 		}
  1752 		}
  1752 
  1753 
  1753 private:
  1754 private:
  1754 	/** The lock */
  1755 	/** The lock */
  1755 	static NFastMutex iLock;
  1756 	static NFastMutex iLock;
  1949 	void Init2Common();
  1950 	void Init2Common();
  1950 	void Init2Final();
  1951 	void Init2Final();
  1951 	void Init2FinalCommon();
  1952 	void Init2FinalCommon();
  1952 	void Init3();
  1953 	void Init3();
  1953 
  1954 
       
  1955 	void BTracePrime(TUint aCategory);
       
  1956 
  1954 	static void Panic(TPanic aPanic);
  1957 	static void Panic(TPanic aPanic);
  1955 
  1958 
  1956 	static TInt HandlePageFault(TLinAddr aPc, TLinAddr aFaultAddress, TUint aAccessPermissions, TAny* aExceptionInfo);
  1959 	static TInt HandlePageFault(TLinAddr aPc, TLinAddr aFaultAddress, TUint aAccessPermissions, TAny* aExceptionInfo);
  1957 
  1960 
  1958 	TUint FreeRamInPages();
  1961 	TUint FreeRamInPages();
  1977 	void FreePhysicalRam(TPhysAddr* aPages, TUint aCount);
  1980 	void FreePhysicalRam(TPhysAddr* aPages, TUint aCount);
  1978 	TInt AllocPhysicalRam(TPhysAddr& aPhysAddr, TUint aCount, TUint aAlign, TRamAllocFlags aFlags);
  1981 	TInt AllocPhysicalRam(TPhysAddr& aPhysAddr, TUint aCount, TUint aAlign, TRamAllocFlags aFlags);
  1979 	void FreePhysicalRam(TPhysAddr aPhysAddr, TUint aCount);
  1982 	void FreePhysicalRam(TPhysAddr aPhysAddr, TUint aCount);
  1980 	TInt ClaimPhysicalRam(TPhysAddr aPhysAddr, TUint aCount, TRamAllocFlags aFlags);
  1983 	TInt ClaimPhysicalRam(TPhysAddr aPhysAddr, TUint aCount, TRamAllocFlags aFlags);
  1981 	void AllocatedPhysicalRam(TPhysAddr aPhysAddr, TUint aCount, TRamAllocFlags aFlags);
  1984 	void AllocatedPhysicalRam(TPhysAddr aPhysAddr, TUint aCount, TRamAllocFlags aFlags);
  1982 
  1985 private:
       
  1986 	void SetAllocPhysRam(TPhysAddr aPhysAddr, TUint aCount);
       
  1987 	void SetAllocPhysRam(TPhysAddr* aPageList, TUint aNumPages);
       
  1988 
       
  1989 public:
  1983 	TLinAddr MapTemp(TPhysAddr aPage, TUint aColour, TUint aSlot=0);
  1990 	TLinAddr MapTemp(TPhysAddr aPage, TUint aColour, TUint aSlot=0);
  1984 	void UnmapTemp(TUint aSlot=0);
  1991 	void UnmapTemp(TUint aSlot=0);
  1985 	void RemoveAliasesForPageTable(TPhysAddr aPageTable);
  1992 	void RemoveAliasesForPageTable(TPhysAddr aPageTable);
  1986 
  1993 
  1987 	static TBool MapPages(TPte* const aPtePtr, const TUint aCount, TPhysAddr* aPages, TPte aBlankPte);
  1994 	static TBool MapPages(TPte* const aPtePtr, const TUint aCount, TPhysAddr* aPages, TPte aBlankPte);
  2130 	of memory level change notifications.
  2137 	of memory level change notifications.
  2131 	*/
  2138 	*/
  2132 	TUint iRamAllocInitialFreePages;
  2139 	TUint iRamAllocInitialFreePages;
  2133 
  2140 
  2134 	friend class RamAllocLock;
  2141 	friend class RamAllocLock;
       
  2142 
       
  2143 #ifdef FMM_VERIFY_RAM
  2135 private:
  2144 private:
  2136 	void VerifyRam();
  2145 	void VerifyRam();
       
  2146 #endif
  2137 	};
  2147 	};
  2138 
  2148 
  2139 /**
  2149 /**
  2140 The single instance of class #Mmu.
  2150 The single instance of class #Mmu.
  2141 */
  2151 */