kernel/eka/memmodel/epoc/flexible/mmu/mptalloc.cpp
branchRCL_3
changeset 28 5b5d147c7838
parent 26 c734af59ce98
child 41 0ffb4e86fcc9
equal deleted inserted replaced
26:c734af59ce98 28:5b5d147c7838
   116 		{ }
   116 		{ }
   117 
   117 
   118 
   118 
   119 	virtual TInt MovePage(	DMemoryObject* aMemory, SPageInfo* aOldPageInfo, 
   119 	virtual TInt MovePage(	DMemoryObject* aMemory, SPageInfo* aOldPageInfo, 
   120 							TPhysAddr& aNewPage, TUint aBlockZoneId, TBool aBlockRest);
   120 							TPhysAddr& aNewPage, TUint aBlockZoneId, TBool aBlockRest);
       
   121 
       
   122 	virtual TInt MoveAndAllocPage(DMemoryObject* aMemory, SPageInfo* aPageInfo, TZonePageType aType);
   121 public:
   123 public:
   122 	/**
   124 	/**
   123 	Allocate a page of RAM for storing page tables in.
   125 	Allocate a page of RAM for storing page tables in.
   124 
   126 
   125 	@param aMemory		A memory object associated with this manager.
   127 	@param aMemory		A memory object associated with this manager.
   180 			BTrace4(BTrace::EKernelMemory, BTrace::EKernelMemoryMiscAlloc, KPageSize);
   182 			BTrace4(BTrace::EKernelMemory, BTrace::EKernelMemoryMiscAlloc, KPageSize);
   181 			++Epoc::KernelMiscPages;
   183 			++Epoc::KernelMiscPages;
   182 			}
   184 			}
   183 #endif
   185 #endif
   184 		}
   186 		}
   185 	RamAllocLock::Unlock();
       
   186 
   187 
   187 	TUint usedNew = 0;
   188 	TUint usedNew = 0;
   188 	if(r==KErrNone)
   189 	if(r==KErrNone)
   189 		{
   190 		{
   190 		// add RAM to page array...
   191 		// add RAM to page array...
   195 		pi->SetManaged(aMemory,aIndex,aMemory->PageInfoFlags());
   196 		pi->SetManaged(aMemory,aIndex,aMemory->PageInfoFlags());
   196 		RPageArray::AddPage(p,pagePhys);
   197 		RPageArray::AddPage(p,pagePhys);
   197 		MmuLock::Unlock();
   198 		MmuLock::Unlock();
   198 		usedNew = 1;
   199 		usedNew = 1;
   199 
   200 
       
   201 		// Must hold the ram alloc lock until the page has been set as managed
       
   202 		// otherwise it will still be seen as free by the rest of the system.
       
   203 		RamAllocLock::Unlock();
       
   204 
   200 		// map page...
   205 		// map page...
   201 		r = aMemory->MapPages(pageList);
   206 		r = aMemory->MapPages(pageList);
   202 		}
   207 		}
       
   208 	else
       
   209 		RamAllocLock::Unlock();
   203 
   210 
   204 	// release page array entry...
   211 	// release page array entry...
   205 	aMemory->iPages.AddPageEnd(aIndex,usedNew);
   212 	aMemory->iPages.AddPageEnd(aIndex,usedNew);
   206 
   213 
   207 	// revert if error...
   214 	// revert if error...
   261 	// cleanup...
   268 	// cleanup...
   262 	aMemory->iPages.RemovePageEnd(aIndex,r);
   269 	aMemory->iPages.RemovePageEnd(aIndex,r);
   263 	return r;
   270 	return r;
   264 	}
   271 	}
   265 
   272 
       
   273 
   266 TInt DPageTableMemoryManager::MovePage(	DMemoryObject* aMemory, SPageInfo* aOldPageInfo, 
   274 TInt DPageTableMemoryManager::MovePage(	DMemoryObject* aMemory, SPageInfo* aOldPageInfo, 
   267 										TPhysAddr& aNewPage, TUint aBlockZoneId, TBool aBlockRest)
   275 										TPhysAddr& aNewPage, TUint aBlockZoneId, TBool aBlockRest)
   268 		{
   276 	{
   269 		// This could be a demand paged page table info which can be discarded 
   277 	// This could be a demand paged page table info which can be discarded 
   270 		// but let the PageTableAllocator handle that.
   278 	// but let the PageTableAllocator handle that.
   271 		return ::PageTables.MovePage(aMemory, aOldPageInfo, aBlockZoneId, aBlockRest);
   279 	return ::PageTables.MovePage(aMemory, aOldPageInfo, aBlockZoneId, aBlockRest);
   272 		}
   280 	}
       
   281 
       
   282 
       
   283 TInt DPageTableMemoryManager::MoveAndAllocPage(DMemoryObject* aMemory, SPageInfo* aPageInfo, TZonePageType aPageType)
       
   284 	{
       
   285 	// This could be a demand paged page table info which can be discarded 
       
   286 	// but let the PageTableAllocator handle that.
       
   287 	return ::PageTables.MoveAndAllocPage(aMemory, aPageInfo, aPageType);
       
   288 	}
   273 
   289 
   274 
   290 
   275 //
   291 //
   276 // PageTableAllocator
   292 // PageTableAllocator
   277 //
   293 //
  1204 		return KErrInUse;
  1220 		return KErrInUse;
  1205 		}
  1221 		}
  1206 	// Let the pager discard the page as it controls the size of the live list.
  1222 	// Let the pager discard the page as it controls the size of the live list.
  1207 	// If the size of the live list allows then eventually 
  1223 	// If the size of the live list allows then eventually 
  1208 	// PageTableAllocator::StealPage() will be invoked on this page.
  1224 	// PageTableAllocator::StealPage() will be invoked on this page.
  1209 	return ThePager.DiscardPage(aOldPageInfo, aBlockZoneId, aBlockRest);
  1225 	TUint moveDisFlags = (aBlockRest)? M::EMoveDisBlockRest : 0;
       
  1226 	return ThePager.DiscardPage(aOldPageInfo, aBlockZoneId, moveDisFlags);
       
  1227 	}
       
  1228 
       
  1229 
       
  1230 TInt PageTableAllocator::MoveAndAllocPage(DMemoryObject* aMemory, SPageInfo* aPageInfo, TZonePageType aPageType)
       
  1231 	{
       
  1232 	TInt r = MovePage(aMemory, aPageInfo, KRamZoneInvalidId, EFalse);
       
  1233 	if (r == KErrNone)
       
  1234 		{
       
  1235 		TheMmu.MarkPageAllocated(aPageInfo->PhysAddr(), aPageType);
       
  1236 		}
       
  1237 	return r;
  1210 	}
  1238 	}
  1211 
  1239 
  1212 
  1240 
  1213 TInt PageTableAllocator::PinPageTable(TPte* aPageTable, TPinArgs& aPinArgs)
  1241 TInt PageTableAllocator::PinPageTable(TPte* aPageTable, TPinArgs& aPinArgs)
  1214 	{
  1242 	{