kernel/eka/memmodel/epoc/mmubase/mmubase.cpp
changeset 102 ef2a444a7410
parent 90 947f0dc9f7a8
child 109 b3a1d9898418
equal deleted inserted replaced
90:947f0dc9f7a8 102:ef2a444a7410
   646 		
   646 		
   647 		// Free the page
   647 		// Free the page
   648 		r = iRamPageAllocator->FreePhysicalRam(*page, KPageSize);
   648 		r = iRamPageAllocator->FreePhysicalRam(*page, KPageSize);
   649 		}
   649 		}
   650 	return r;
   650 	return r;
       
   651 	}
       
   652 
       
   653 
       
   654 TInt MmuBase::FreeRamZone(TUint aZoneId, TPhysAddr& aZoneBase, TUint& aZoneBytes)
       
   655 	{
       
   656 	TUint zonePages;
       
   657 	TInt r = iRamPageAllocator->GetZoneAddress(aZoneId, aZoneBase, zonePages);
       
   658 	if (r != KErrNone)
       
   659 		return r;
       
   660 	aZoneBytes = zonePages << KPageShift;
       
   661 	return MmuBase::FreePhysicalRam(aZoneBase, aZoneBytes);
   651 	}
   662 	}
   652 
   663 
   653 
   664 
   654 TInt MmuBase::ClaimPhysicalRam(TPhysAddr aPhysAddr, TInt aSize)
   665 TInt MmuBase::ClaimPhysicalRam(TPhysAddr aPhysAddr, TInt aSize)
   655 	{
   666 	{
  1261 		NKern::ThreadLeaveCS();
  1272 		NKern::ThreadLeaveCS();
  1262 		}
  1273 		}
  1263 #endif
  1274 #endif
  1264 
  1275 
  1265 #ifdef BTRACE_RAM_ALLOCATOR
  1276 #ifdef BTRACE_RAM_ALLOCATOR
  1266 	// Must check for -1 as that is the default value of aCategroy for
  1277 	// Must check for -1 as that is the default value of aCategory for
  1267 	// BTrace::Prime() which is intended to prime all categories that are 
  1278 	// BTrace::Prime() which is intended to prime all categories that are 
  1268 	// currently enabled via a single invocation of BTrace::Prime().
  1279 	// currently enabled via a single invocation of BTrace::Prime().
  1269 	if(aCategory==BTrace::ERamAllocator || (TInt)aCategory == -1)
  1280 	if(aCategory==BTrace::ERamAllocator || (TInt)aCategory == -1)
  1270 		{
  1281 		{
  1271 		NKern::ThreadEnterCS();
  1282 		NKern::ThreadEnterCS();
  1272 		Mmu::Wait();
  1283 		Mmu::Wait();
  1273 		Mmu::Get().iRamPageAllocator->SendInitialBtraceLogs();
  1284 		Mmu::Get().iRamPageAllocator->DoBTracePrime();
  1274 		Mmu::Signal();
  1285 		Mmu::Signal();
  1275 		NKern::ThreadLeaveCS();
  1286 		NKern::ThreadLeaveCS();
  1276 		}
  1287 		}
  1277 #endif
  1288 #endif
  1278 	}
  1289 	}
  2041 		TUint32 pa=aPhysAddr;
  2052 		TUint32 pa=aPhysAddr;
  2042 		TUint32 size=aSize;
  2053 		TUint32 size=aSize;
  2043 		m.RoundUpRangeToPageSize(pa,size);
  2054 		m.RoundUpRangeToPageSize(pa,size);
  2044 		BTrace8(BTrace::EKernelMemory, BTrace::EKernelMemoryDrvPhysAlloc, size, pa);
  2055 		BTrace8(BTrace::EKernelMemory, BTrace::EKernelMemoryDrvPhysAlloc, size, pa);
  2045 		Epoc::DriverAllocdPhysRam += size;
  2056 		Epoc::DriverAllocdPhysRam += size;
       
  2057 		}
       
  2058 #endif
       
  2059 	MmuBase::Signal();
       
  2060 	return r;
       
  2061 	}
       
  2062 
       
  2063 
       
  2064 /**
       
  2065 Free a RAM zone which was previously allocated by one of these methods:
       
  2066 Epoc::AllocPhysicalRam(), Epoc::ZoneAllocPhysicalRam() or 
       
  2067 TRamDefragRequest::ClaimRamZone().
       
  2068 
       
  2069 All of the pages in the RAM zone must be allocated and only via one of the methods 
       
  2070 listed above, otherwise a system panic will occur.
       
  2071 
       
  2072 @param	aZoneId			The ID of the RAM zone to free.
       
  2073 @return	KErrNone 		If the operation was successful.
       
  2074 		KErrArgument 	If a RAM zone with ID aZoneId was not found.
       
  2075 
       
  2076 @pre Calling thread must be in a critical section.
       
  2077 @pre Interrupts must be enabled.
       
  2078 @pre Kernel must be unlocked.
       
  2079 @pre No fast mutex can be held.
       
  2080 @pre Call in a thread context.
       
  2081 @pre Can be used in a device driver.
       
  2082 */
       
  2083 EXPORT_C TInt Epoc::FreeRamZone(TUint aZoneId)
       
  2084 	{
       
  2085 	CHECK_PRECONDITIONS(MASK_THREAD_CRITICAL,"Epoc::FreeRamZone");
       
  2086 	MmuBase& m = *MmuBase::TheMmu;
       
  2087 	MmuBase::Wait();
       
  2088 	TPhysAddr zoneBase;
       
  2089 	TUint zoneBytes;
       
  2090 	TInt r = m.FreeRamZone(aZoneId, zoneBase, zoneBytes);
       
  2091 #ifdef BTRACE_KERNEL_MEMORY
       
  2092 	if (r == KErrNone)
       
  2093 		{
       
  2094 		BTrace8(BTrace::EKernelMemory, BTrace::EKernelMemoryDrvPhysFree, zoneBytes, zoneBase);
       
  2095 		Epoc::DriverAllocdPhysRam -= zoneBytes;
  2046 		}
  2096 		}
  2047 #endif
  2097 #endif
  2048 	MmuBase::Signal();
  2098 	MmuBase::Signal();
  2049 	return r;
  2099 	return r;
  2050 	}
  2100 	}