kerneltest/e32test/mmu/d_memorytest.cpp
changeset 47 46fffbe7b5a7
parent 43 96e5fb8b040d
child 109 b3a1d9898418
equal deleted inserted replaced
46:0bf4040442f9 47:46fffbe7b5a7
    52 	TVirtualPinObject* iVirtualPinObject;
    52 	TVirtualPinObject* iVirtualPinObject;
    53 	
    53 	
    54 	struct{
    54 	struct{
    55 		TPhysicalPinObject* iObject;
    55 		TPhysicalPinObject* iObject;
    56 		TPhysAddr iPhysAddr;
    56 		TPhysAddr iPhysAddr;
    57 		TPhysAddr iPhysPageList[UCPageCount];
    57 		TPhysAddr iPhysPageList[KUCPageCount];
    58 		TUint 	iColour;
    58 		TUint 	iColour;
    59 		TUint32 iActualMapAttr;
    59 		TUint32 iActualMapAttr;
    60 		}iPhysicalPinning;
    60 		}iPhysicalPinning;
       
    61 
       
    62 	struct{
       
    63 		TKernelMapObject* iObject;
       
    64 		TPhysAddr iPhysPageList[KUCPageCount];
       
    65 		TLinAddr iLinAddr;
       
    66 		}iKernelMapping;
       
    67 
    61 	TUint32 iPageSize;
    68 	TUint32 iPageSize;
    62 	};
    69 	};
    63 
    70 
    64 //
    71 //
    65 // DMemoryTestFactory
    72 // DMemoryTestFactory
   247 		{
   254 		{
   248 #ifdef __WINS__
   255 #ifdef __WINS__
   249 		return KErrNotSupported;
   256 		return KErrNotSupported;
   250 #else
   257 #else
   251 		TInt i;
   258 		TInt i;
   252 		for (i=0;i<UCPageCount; i++)
   259 		for (i=0;i<KUCPageCount; i++)
   253 			{
   260 			{
   254 			TPhysAddr addr = Epoc::LinearToPhysical((TLinAddr)a1 + i*iPageSize);
   261 			TPhysAddr addr = Epoc::LinearToPhysical((TLinAddr)a1 + i*iPageSize);
   255 			if (addr==KPhysAddrInvalid) 				 return KErrGeneral;
   262 			if (addr==KPhysAddrInvalid) 				 return KErrGeneral;
   256 			if (addr!=iPhysicalPinning.iPhysPageList[i]) return KErrNotFound;
   263 			if (addr!=iPhysicalPinning.iPhysPageList[i]) return KErrNotFound;
   257 			}
   264 			}
   311 		Kern::UnpinPhysicalMemory(pinObject);
   318 		Kern::UnpinPhysicalMemory(pinObject);
   312 		Kern::DestroyPhysicalPinObject(pinObject);
   319 		Kern::DestroyPhysicalPinObject(pinObject);
   313 		NKern::ThreadLeaveCS();
   320 		NKern::ThreadLeaveCS();
   314 		return r;
   321 		return r;
   315 		}
   322 		}
       
   323 
       
   324 	case RMemoryTestLdd::ECreateKernelMapObject:
       
   325 		{
       
   326 		NKern::ThreadEnterCS();
       
   327 		r=Kern::CreateKernelMapObject(iKernelMapping.iObject, (TUint)a1);
       
   328 		NKern::ThreadLeaveCS();
       
   329 		return r;
       
   330 		}
       
   331 
       
   332 	case RMemoryTestLdd::EKernelMapMemory:
       
   333 		return Kern::MapAndPinMemory(	iKernelMapping.iObject, NULL, (TLinAddr)a1, (TUint)a2, 0,
       
   334 										iKernelMapping.iLinAddr, iKernelMapping.iPhysPageList);
       
   335 
       
   336 	case RMemoryTestLdd::EKernelMapMemoryRO:
       
   337 		return Kern::MapAndPinMemory(	iKernelMapping.iObject, NULL, (TLinAddr)a1, (TUint)a2, Kern::EKernelMap_ReadOnly,
       
   338 										iKernelMapping.iLinAddr, iKernelMapping.iPhysPageList);
       
   339 
       
   340 	case RMemoryTestLdd::EKernelMapMemoryInvalid:
       
   341 		return Kern::MapAndPinMemory(	iKernelMapping.iObject, NULL, (TLinAddr)a1, (TUint)a2, (TUint)~Kern::EKernelMap_ReadOnly,
       
   342 										iKernelMapping.iLinAddr, iKernelMapping.iPhysPageList);
       
   343 
       
   344 	case RMemoryTestLdd::EKernelMapCheckPageList:
       
   345 		{
       
   346 #ifdef __WINS__
       
   347 		return KErrNotSupported;
       
   348 #else
       
   349 		TUint i = 0;
       
   350 		for (; i < (TUint)KUCPageCount; i++)
       
   351 			{
       
   352 			// Compare the user side address to physical addresses
       
   353 			TPhysAddr addr = Epoc::LinearToPhysical((TLinAddr)a1 + i*iPageSize);
       
   354 			if (addr == KPhysAddrInvalid) 				 
       
   355 				return KErrGeneral;
       
   356 			if (addr != iKernelMapping.iPhysPageList[i]) 
       
   357 				return KErrNotFound;
       
   358 			// Compare the kernel side address to physical addresses
       
   359 			addr = Epoc::LinearToPhysical(iKernelMapping.iLinAddr + i*iPageSize);
       
   360 			if (addr == KPhysAddrInvalid) 				 
       
   361 				return KErrGeneral;
       
   362 			if (addr != iKernelMapping.iPhysPageList[i])
       
   363 				return KErrNotFound;
       
   364 			}
       
   365 		return KErrNone;
       
   366 #endif		
       
   367 		}
       
   368 
       
   369 	case RMemoryTestLdd::EKernelMapSyncMemory:
       
   370 		Cache::SyncMemoryBeforeDmaWrite(iKernelMapping.iLinAddr, KUCPageCount*iPageSize);
       
   371 		return KErrNone;
       
   372 
       
   373 	case RMemoryTestLdd::EKernelMapInvalidateMemory:
       
   374 		{
       
   375 		Cache::SyncMemoryBeforeDmaRead(iKernelMapping.iLinAddr, KUCPageCount*iPageSize);
       
   376 		Cache::SyncMemoryAfterDmaRead(iKernelMapping.iLinAddr, KUCPageCount*iPageSize);
       
   377 		return KErrNone;
       
   378 		}
       
   379 
       
   380 	case RMemoryTestLdd::EKernelMapMoveMemory:
       
   381 		{
       
   382 #ifdef __WINS__
       
   383 		return KErrNotSupported;
       
   384 #else
       
   385 		TPhysAddr newPage;
       
   386 		NKern::ThreadEnterCS();
       
   387 		r = Epoc::MovePhysicalPage(iKernelMapping.iPhysPageList[(TUint)a1], newPage);		
       
   388 		NKern::ThreadLeaveCS();
       
   389 		return r;
       
   390 #endif
       
   391 		}
       
   392 
       
   393 	case RMemoryTestLdd::EKernelMapReadModifyMemory:
       
   394 		{
       
   395 		TUint8* p = (TUint8*)iKernelMapping.iLinAddr;
       
   396 		// Verify the contents of the data when accessed via the kernel mapping.
       
   397 		TUint i = 0;
       
   398 		for (i = 0; i < KUCPageCount*iPageSize; i++)
       
   399 			{
       
   400 			if (*p++ != (TUint8)i)
       
   401 				return KErrCorrupt;
       
   402 			}
       
   403 		// Modify the data via the kernel mapping.
       
   404 		p = (TUint8*)iKernelMapping.iLinAddr;
       
   405 		for (i = 0; i < KUCPageCount*iPageSize; i++)
       
   406 			{
       
   407 			*p++ = (TUint8)(i + 1);
       
   408 			}
       
   409 		return KErrNone;
       
   410 		}
       
   411 		
       
   412 	case RMemoryTestLdd::EKernelUnmapMemory:
       
   413 		Kern::UnmapAndUnpinMemory(iKernelMapping.iObject);
       
   414 		return KErrNone;
       
   415 
       
   416 	case RMemoryTestLdd::EDestroyKernelMapObject:
       
   417 		{
       
   418 		NKern::ThreadEnterCS();
       
   419 		Kern::DestroyKernelMapObject(iKernelMapping.iObject);
       
   420 		NKern::ThreadLeaveCS();
       
   421 		return KErrNone;
       
   422 		}
       
   423 		
   316 	default:
   424 	default:
   317 		return KErrNotSupported;
   425 		return KErrNotSupported;
   318 		}
   426 		}
   319 	}
   427 	}
   320 
   428