kernel/eka/memmodel/epoc/flexible/mmu/mmu.cpp
branchRCL_3
changeset 110 c734af59ce98
parent 97 41f0cfe18c80
child 117 5b5d147c7838
equal deleted inserted replaced
97:41f0cfe18c80 110:c734af59ce98
   620 TInt Mmu::ZoneAllocPhysicalRam(TUint* aZoneIdList, TUint aZoneIdCount, TInt aBytes, TPhysAddr& aPhysAddr, TInt aAlign)
   620 TInt Mmu::ZoneAllocPhysicalRam(TUint* aZoneIdList, TUint aZoneIdCount, TInt aBytes, TPhysAddr& aPhysAddr, TInt aAlign)
   621 	{
   621 	{
   622 	__KTRACE_OPT(KMMU,Kern::Printf("Mmu::ZoneAllocPhysicalRam(?,%d,%d,?,%d)", aZoneIdCount, aBytes, aPhysAddr, aAlign));
   622 	__KTRACE_OPT(KMMU,Kern::Printf("Mmu::ZoneAllocPhysicalRam(?,%d,%d,?,%d)", aZoneIdCount, aBytes, aPhysAddr, aAlign));
   623 	__NK_ASSERT_DEBUG(RamAllocLock::IsHeld());
   623 	__NK_ASSERT_DEBUG(RamAllocLock::IsHeld());
   624 
   624 
   625 	TInt r = iRamPageAllocator->ZoneAllocContiguousRam(aZoneIdList, aZoneIdCount, aBytes, aPhysAddr, EPageFixed, aAlign);
   625 	TInt r = iRamPageAllocator->ZoneAllocContiguousRam(aZoneIdList, aZoneIdCount, aBytes, aPhysAddr, aAlign);
   626 	if(r!=KErrNone)
   626 	if(r!=KErrNone)
   627 		iRamAllocFailed = ETrue;
   627 		iRamAllocFailed = ETrue;
   628 	else
   628 	else
   629 		{
   629 		{
   630 		TUint pages = MM::RoundToPageCount(aBytes);
   630 		TUint pages = MM::RoundToPageCount(aBytes);
   866 		iRamAllocFailed = ETrue;
   866 		iRamAllocFailed = ETrue;
   867 	else
   867 	else
   868 		PagesAllocated(aPages,aCount,aFlags);
   868 		PagesAllocated(aPages,aCount,aFlags);
   869 	__KTRACE_OPT(KMMU,Kern::Printf("Mmu::AllocRam returns %d",r));
   869 	__KTRACE_OPT(KMMU,Kern::Printf("Mmu::AllocRam returns %d",r));
   870 	return r;
   870 	return r;
       
   871 	}
       
   872 
       
   873 
       
   874 /**
       
   875 Mark a page as being allocated to a particular page type.
       
   876 
       
   877 NOTE - This page should not be used until PagesAllocated() has been invoked on it.
       
   878 
       
   879 @param aPhysAddr		The physical address of the page to mark as allocated.
       
   880 @param aZonePageType	The type of the page to mark as allocated.
       
   881 */
       
   882 void Mmu::MarkPageAllocated(TPhysAddr aPhysAddr, TZonePageType aZonePageType)
       
   883 	{
       
   884 	__KTRACE_OPT(KMMU,Kern::Printf("Mmu::MarkPageAllocated(0x%x, %d)", aPhysAddr, aZonePageType));
       
   885 	__NK_ASSERT_DEBUG(RamAllocLock::IsHeld());
       
   886 	iRamPageAllocator->MarkPageAllocated(aPhysAddr, aZonePageType);
   871 	}
   887 	}
   872 
   888 
   873 
   889 
   874 void Mmu::FreeRam(TPhysAddr* aPages, TUint aCount, TZonePageType aZonePageType)
   890 void Mmu::FreeRam(TPhysAddr* aPages, TUint aCount, TZonePageType aZonePageType)
   875 	{
   891 	{
   934 		return KErrNoMemory;
   950 		return KErrNoMemory;
   935 		}
   951 		}
   936 	// Only the pager sets EAllocNoPagerReclaim and it shouldn't allocate contiguous ram.
   952 	// Only the pager sets EAllocNoPagerReclaim and it shouldn't allocate contiguous ram.
   937 	__NK_ASSERT_DEBUG(!(aFlags&EAllocNoPagerReclaim));
   953 	__NK_ASSERT_DEBUG(!(aFlags&EAllocNoPagerReclaim));
   938 #endif
   954 #endif
   939 	TInt r = iRamPageAllocator->AllocContiguousRam(aCount, aPhysAddr, EPageFixed, aAlign+KPageShift);
   955 	TInt r = iRamPageAllocator->AllocContiguousRam(aCount, aPhysAddr, aAlign+KPageShift);
   940 	if(r==KErrNoMemory && aCount > KMaxFreeableContiguousPages)
       
   941 		{
       
   942 		// flush paging cache and retry...
       
   943 		RamAllocLock::Unlock();
       
   944 		ThePager.FlushAll();
       
   945 		RamAllocLock::Lock();
       
   946 		r = iRamPageAllocator->AllocContiguousRam(aCount, aPhysAddr, EPageFixed, aAlign+KPageShift);
       
   947 		}
       
   948 	if(r!=KErrNone)
   956 	if(r!=KErrNone)
   949 		iRamAllocFailed = ETrue;
   957 		iRamAllocFailed = ETrue;
   950 	else
   958 	else
   951 		PagesAllocated((TPhysAddr*)(aPhysAddr|1), aCount, aFlags);
   959 		PagesAllocated((TPhysAddr*)(aPhysAddr|1), aCount, aFlags);
   952 	__KTRACE_OPT(KMMU,Kern::Printf("AllocContiguousRam returns %d and aPhysAddr=0x%08x",r,aPhysAddr));
   960 	__KTRACE_OPT(KMMU,Kern::Printf("AllocContiguousRam returns %d and aPhysAddr=0x%08x",r,aPhysAddr));