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