Revision: 201021 RCL_3
authorDremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Tue, 25 May 2010 14:09:55 +0300
branchRCL_3
changeset 28 5b5d147c7838
parent 26 c734af59ce98
child 29 743008598095
child 36 bbf8bed59bcb
Revision: 201021 Kit: 2010121
bsptemplate/asspandvariant/template_assp/dma.mmp
bsptemplate/asspandvariant/template_assp/dmapsl.cpp
halservices/hal/bld.inf
halservices/hal/inc/hal.h
halservices/hal/inc/hal_data.h
halservices/hal/rom/haltests.auto.bat
halservices/hal/rom/haltests.iby
halservices/hal/rom/tshell_haltests.oby
halservices/hal/src/hal_main.cpp
halservices/hal/tsrc/t_haldefect.cpp
halservices/hal/tsrc/t_haldefect.mmp
halservices/hal/tsrc/t_newhal.cpp
kernel/eka/bld.inf
kernel/eka/bmarm/dma2u.def
kernel/eka/drivers/bsp/bld.inf
kernel/eka/drivers/dma/dma2_lib.mmp
kernel/eka/drivers/dma/dma2_pil.cpp
kernel/eka/drivers/dma/dma2_shared.cpp
kernel/eka/drivers/locmedia/dmasupport.cpp
kernel/eka/drivers/locmedia/locmedia.cpp
kernel/eka/drivers/medmmc/medmmc.cpp
kernel/eka/drivers/pbus/mmc/mmccd_init.cpp
kernel/eka/eabi/dma2u.def
kernel/eka/include/drivers/dma.h
kernel/eka/include/drivers/dma.inl
kernel/eka/include/drivers/dma_compat.inl
kernel/eka/include/drivers/dma_hai.h
kernel/eka/include/drivers/dma_hai.inl
kernel/eka/include/drivers/dma_v1.h
kernel/eka/include/drivers/dma_v1.inl
kernel/eka/include/drivers/dma_v2.h
kernel/eka/include/drivers/dma_v2.inl
kernel/eka/include/drivers/dmadefs.h
kernel/eka/include/drivers/locmedia.h
kernel/eka/include/e32math.h
kernel/eka/include/e32ver.h
kernel/eka/include/kernel/kern_priv.h
kernel/eka/include/kernel/kernel.h
kernel/eka/include/memmodel/epoc/mmubase/mmubase.inl
kernel/eka/include/memmodel/epoc/mmubase/ramalloc.h
kernel/eka/include/u32hal.h
kernel/eka/klib/arm/cbma.cia
kernel/eka/klib/bma.cpp
kernel/eka/memmodel/epoc/flexible/mmu/mcodepaging.cpp
kernel/eka/memmodel/epoc/flexible/mmu/mdatapaging.cpp
kernel/eka/memmodel/epoc/flexible/mmu/mdefrag.cpp
kernel/eka/memmodel/epoc/flexible/mmu/mdefrag.inl
kernel/eka/memmodel/epoc/flexible/mmu/mm.h
kernel/eka/memmodel/epoc/flexible/mmu/mmanager.cpp
kernel/eka/memmodel/epoc/flexible/mmu/mmapping.h
kernel/eka/memmodel/epoc/flexible/mmu/mmu.cpp
kernel/eka/memmodel/epoc/flexible/mmu/mmu.h
kernel/eka/memmodel/epoc/flexible/mmu/mpager.cpp
kernel/eka/memmodel/epoc/flexible/mmu/mpager.h
kernel/eka/memmodel/epoc/flexible/mmu/mptalloc.cpp
kernel/eka/memmodel/epoc/flexible/mmu/mptalloc.h
kernel/eka/memmodel/epoc/flexible/mmu/mrom.cpp
kernel/eka/memmodel/epoc/flexible/mmu/mswap.h
kernel/eka/memmodel/epoc/mmubase/defragbase.cpp
kernel/eka/memmodel/epoc/mmubase/mmubase.cpp
kernel/eka/memmodel/epoc/mmubase/ramalloc.cpp
kernel/eka/release.txt
kernel/eka/rombuild/mmctest_load.oby
kerneltest/e32test/defrag/t_ramdefrag.cpp
kerneltest/e32test/demandpaging/t_thrash.cpp
kerneltest/e32test/device/t_usbapi.cpp
kerneltest/e32test/dma/d_dma.cpp
kerneltest/e32test/dmav2/cap_reqs.h
kerneltest/e32test/dmav2/d_dma2.cpp
kerneltest/e32test/dmav2/d_dma2.h
kerneltest/e32test/dmav2/d_dma2_cmn.cpp
kerneltest/e32test/dmav2/dma_api_tests.cpp
kerneltest/e32test/dmav2/self_test.cpp
kerneltest/e32test/dmav2/t_dma2.cpp
kerneltest/e32test/dmav2/t_dma2.h
kerneltest/e32test/dmav2/test_cases.cpp
kerneltest/e32test/dmav2/test_thread.cpp
kerneltest/e32test/dmav2/test_thread.h
kerneltest/e32test/group/bld.inf
kerneltest/e32test/group/d_dma2.mmp
kerneltest/e32test/group/d_dma2_compat.mmp
kerneltest/e32test/group/d_dma_compat.mmp
kerneltest/e32test/group/t_dma2.mmp
kerneltest/e32test/group/t_ramall.mmp
kerneltest/e32test/mmu/t_demandpaging.cpp
kerneltest/e32test/mmu/t_ramall.cpp
kerneltest/e32test/prime/t_semutx.cpp
kerneltest/e32test/prime/t_semutx2.cpp
kerneltest/e32test/system/t_condvar.cpp
kerneltest/f32test/server/t_falsespace.cpp
userlibandfileserver/fileserver/etshell/ts_com.cpp
userlibandfileserver/fileserver/group/release.txt
userlibandfileserver/fileserver/inc/f32file.h
userlibandfileserver/fileserver/inc/f32ver.h
userlibandfileserver/fileserver/sfat32/sl_mnt32.cpp
userlibandfileserver/fileserver/sfile/sf_file.cpp
userlibandfileserver/fileserver/sfile/sf_nbs.cpp
userlibandfileserver/fileserver/sfile/sf_std.h
userlibandfileserver/fileserver/sfile/sf_svr.cpp
userlibandfileserver/fileserver/sfile/sf_utl.cpp
userlibandfileserver/fileserver/sfsrv/cl_fman.cpp
userlibandfileserver/fileserver/shostmassstorage/client/hostmsclient.mmp
userlibandfileserver/fileserver/shostmassstorage/server/hostmsserver.mmp
--- a/bsptemplate/asspandvariant/template_assp/dma.mmp	Tue May 11 17:28:22 2010 +0300
+++ b/bsptemplate/asspandvariant/template_assp/dma.mmp	Tue May 25 14:09:55 2010 +0300
@@ -1,4 +1,4 @@
-// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
+// Copyright (c) 2004-2010 Nokia Corporation and/or its subsidiary(-ies).
 // All rights reserved.
 // This component and the accompanying materials are made available
 // under the terms of the License "Eclipse Public License v1.0"
@@ -27,19 +27,17 @@
 noexportlibrary
 
 sourcepath		../../../kernel/eka/drivers/dma
-source			dma2_pil.cpp dma2_shared.cpp
+source			dmapil.cpp
 
 sourcepath		.
 source			dmapsl.cpp
 
 library			VariantTarget(katemplate,lib)
 
-deffile			../../../kernel/eka/~/dma2.def
+deffile			../../../kernel/eka/~/dma.def
 
 epocallowdlldata
 
 capability		all
 
 VENDORID 0x70000001
-
-MACRO DMA_APIV2
--- a/bsptemplate/asspandvariant/template_assp/dmapsl.cpp	Tue May 11 17:28:22 2010 +0300
+++ b/bsptemplate/asspandvariant/template_assp/dmapsl.cpp	Tue May 25 14:09:55 2010 +0300
@@ -1,4 +1,4 @@
-// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
+// Copyright (c) 2004-2010 Nokia Corporation and/or its subsidiary(-ies).
 // All rights reserved.
 // This component and the accompanying materials are made available
 // under the terms of the License "Eclipse Public License v1.0"
@@ -21,16 +21,15 @@
 #include <template_assp.h>									// /assp/template_assp/
 
 #include <drivers/dma.h>
-#include <drivers/dma_hai.h>
 
 
 // Debug support
 static const char KDmaPanicCat[] = "DMA PSL - " __FILE__;
 
-static const TInt KMaxTransferLen = 0x1FE0;	// max transfer length for this DMAC
-static const TInt KMemAlignMask = 7; // memory addresses passed to DMAC must be multiple of 8
-static const TInt KChannelCount = 16;			// we got 16 channels
-static const TInt KDesCount = 160;				// Initial DMA descriptor count
+static const TInt KMaxTransferLen = 0x1FE0;					// max transfer length for this DMAC
+static const TInt KMemAlignMask = 7;				  // memory addresses passed to DMAC must be multiple of 8
+static const TInt KChannelCount = 16;						// we got 16 channels
+static const TInt KDesCount = 1024;							// DMA descriptor count
 
 
 class TDmaDesc
@@ -77,26 +76,6 @@
 	return TestInfo;
 	}
 
-/**
-TO DO: Fill in to provide information to the V2 test harness (t_dma2.exe)
-*/
-TDmaV2TestInfo TestInfov2 =
-	{
-	0,
-	0,
-	0,
-	0,
-	{0},
-	0,
-	{0},
-	0,
-	{0}
-	};
-
-EXPORT_C const TDmaV2TestInfo& DmaTestInfoV2()
-	{
-	return TestInfov2;
-	}
 
 //////////////////////////////////////////////////////////////////////////////
 // Helper Functions
@@ -111,14 +90,14 @@
 	}
 
 
-static TUint32 DmaCmdReg(TUint aCount, TUint aFlags, TUint32 aSrcPslInfo, TUint32 aDstPslInfo)
+static TUint32 DcmdReg(TInt aCount, TUint aFlags, TUint32 aPslInfo)
 //
 // Returns value to set in DMA command register or in descriptor command field.
 //
 	{
 	// TO DO: Construct CMD word from input values.
 	// The return value should reflect the actual control word.
-	return (aCount | aFlags | aSrcPslInfo | aDstPslInfo);
+	return (aCount | aFlags | aPslInfo);
 	}
 
 
@@ -145,15 +124,14 @@
 	TInt Create();
 private:
 	// from TDmac (PIL pure virtual)
+	virtual void Transfer(const TDmaChannel& aChannel, const SDmaDesHdr& aHdr);
 	virtual void StopTransfer(const TDmaChannel& aChannel);
 	virtual TBool IsIdle(const TDmaChannel& aChannel);
-	virtual TUint MaxTransferLength(TDmaChannel& aChannel, TUint aSrcFlags,
-									TUint aDstFlags, TUint32 aPslInfo);
-	virtual TUint AddressAlignMask(TDmaChannel& aChannel, TUint aSrcFlags,
-								   TUint aDstFlags, TUint32 aPslInfo);
+	virtual TInt MaxTransferSize(TDmaChannel& aChannel, TUint aFlags, TUint32 aPslInfo);
+	virtual TUint MemAlignMask(TDmaChannel& aChannel, TUint aFlags, TUint32 aPslInfo);
 	// from TDmac (PIL virtual)
-	virtual void Transfer(const TDmaChannel& aChannel, const SDmaDesHdr& aHdr);
-	virtual TInt InitHwDes(const SDmaDesHdr& aHdr, const TDmaTransferArgs& aTransferArgs);
+	virtual void InitHwDes(const SDmaDesHdr& aHdr, TUint32 aSrc, TUint32 aDest, TInt aCount,
+ 						   TUint aFlags, TUint32 aPslInfo, TUint32 aCookie);
 	virtual void ChainHwDes(const SDmaDesHdr& aHdr, const SDmaDesHdr& aNextHdr);
 	virtual void AppendHwDes(const TDmaChannel& aChannel, const SDmaDesHdr& aLastHdr,
 							 const SDmaDesHdr& aNewHdr);
@@ -173,10 +151,11 @@
 
 const TDmac::SCreateInfo TTemplateDmac::KInfo =
 	{
-	ETrue,													// iCapsHwDes
-	KDesCount,												// iDesCount
-	sizeof(TDmaDesc),										// iDesSize
-	EMapAttrSupRw | EMapAttrFullyBlocking					// iDesChunkAttribs
+	KChannelCount,
+	KDesCount,
+	TDmac::KCapsBitHwDes,
+	sizeof(TDmaDesc),
+	EMapAttrSupRw | EMapAttrFullyBlocking
 	};
 
 
@@ -201,7 +180,7 @@
 			{
 			TDmaDesc* pD = HdrToHwDes(*iFreeHdr);
 			iChannels[i].iTmpDes = pD;
-			iChannels[i].iTmpDesPhysAddr = HwDesLinToPhys(pD);
+			iChannels[i].iTmpDesPhysAddr = DesLinToPhys(pD);
 			iFreeHdr = iFreeHdr->iNext;
 			}
 		r = Interrupt::Bind(EAsspIntIdDma, Isr, this);
@@ -265,10 +244,9 @@
 	}
 
 
-TUint TTemplateDmac::MaxTransferLength(TDmaChannel& /*aChannel*/, TUint /*aSrcFlags*/,
-									   TUint /*aDstFlags*/, TUint32 /*aPslInfo*/)
+TInt TTemplateDmac::MaxTransferSize(TDmaChannel& /*aChannel*/, TUint /*aFlags*/, TUint32 /*aPslInfo*/)
 //
-// Returns the maximum transfer length in bytes for a given transfer.
+// Returns the maximum transfer size for a given transfer.
 //
 	{
 	// TO DO: Determine the proper return value, based on the arguments.
@@ -278,8 +256,7 @@
 	}
 
 
-TUint TTemplateDmac::AddressAlignMask(TDmaChannel& aChannel, TUint /*aSrcFlags*/,
-									  TUint /*aDstFlags*/, TUint32 /*aPslInfo*/)
+TUint TTemplateDmac::MemAlignMask(TDmaChannel& /*aChannel*/, TUint /*aFlags*/, TUint32 /*aPslInfo*/)
 //
 // Returns the memory buffer alignment restrictions mask for a given transfer.
 //
@@ -291,7 +268,8 @@
 	}
 
 
-TInt TTemplateDmac::InitHwDes(const SDmaDesHdr& aHdr, const TDmaTransferArgs& aTransferArgs)
+void TTemplateDmac::InitHwDes(const SDmaDesHdr& aHdr, TUint32 aSrc, TUint32 aDest, TInt aCount,
+							  TUint aFlags, TUint32 aPslInfo, TUint32 /*aCookie*/)
 //
 // Sets up (from a passed in request) the descriptor with that fragment's
 // source and destination address, the fragment size, and the (driver/DMA
@@ -306,15 +284,12 @@
 	// Unaligned descriptor? Bug in generic layer!
 	__DMA_ASSERTD(IsHwDesAligned(pD));
 
-	const TDmaTransferConfig& src = aTransferArgs.iSrcConfig;
-	const TDmaTransferConfig& dst = aTransferArgs.iDstConfig;
-	pD->iSrcAddr  = (src.iFlags & KDmaPhysAddr) ? src.iAddr : Epoc::LinearToPhysical(src.iAddr);
-	pD->iDestAddr = (dst.iFlags & KDmaPhysAddr) ? dst.iAddr : Epoc::LinearToPhysical(dst.iAddr);
-	pD->iCmd = DmaCmdReg(aTransferArgs.iTransferCount, aTransferArgs.iFlags,
-					   src.iPslTargetInfo, dst.iPslTargetInfo);
+	pD->iSrcAddr = (aFlags & KDmaPhysAddrSrc) ? aSrc : Epoc::LinearToPhysical(aSrc);
+	__DMA_ASSERTD(pD->iSrcAddr != KPhysAddrInvalid);
+	pD->iDestAddr = (aFlags & KDmaPhysAddrDest) ? aDest : Epoc::LinearToPhysical(aDest);
+	__DMA_ASSERTD(pD->iDestAddr != KPhysAddrInvalid);
+	pD->iCmd = DcmdReg(aCount, aFlags, aPslInfo);
 	pD->iDescAddr = TDmaDesc::KStopBitMask;
-
-	return KErrNone;
 	}
 
 
@@ -334,7 +309,7 @@
 
 	// TO DO: Modify pD->iCmd so that no end-of-transfer interrupt gets raised any longer.
 
-	pD->iDescAddr = HwDesLinToPhys(pN);
+	pD->iDescAddr = DesLinToPhys(pN);
 	}
 
 
@@ -354,7 +329,7 @@
 	// Unaligned descriptor? Bug in generic layer!
 	__DMA_ASSERTD(IsHwDesAligned(pL) && IsHwDesAligned(pN));
 
-	TPhysAddr newPhys = HwDesLinToPhys(pN);
+	TPhysAddr newPhys = DesLinToPhys(pN);
 
 	const TInt irq = NKern::DisableAllInterrupts();
 	StopTransfer(aChannel);
@@ -398,7 +373,7 @@
 
 	// TO DO: Implement the behaviour described above, call HandleIsr().
 
-	HandleIsr(me.iChannels[5], EDmaCallbackRequestCompletion, ETrue); // Example
+	HandleIsr(me.iChannels[5], 0);							// Example
 
 	}
 
@@ -416,7 +391,7 @@
 // Channel Opening/Closing (Channel Allocator)
 //////////////////////////////////////////////////////////////////////////////
 
-TDmaChannel* DmaChannelMgr::Open(TUint32 aOpenId, TBool /*aDynChannel*/, TUint /*aPriority*/)
+TDmaChannel* DmaChannelMgr::Open(TUint32 aOpenId)
 //
 //
 //
@@ -469,10 +444,5 @@
 	{
 	__KTRACE_OPT2(KBOOT, KDMA, Kern::Printf("Starting DMA Extension"));
 
-	const TInt r = DmaChannelMgr::Initialise();
-	if (r != KErrNone)
-		{
-		return r;
-		}
 	return Controller.Create();
 	}
--- a/halservices/hal/bld.inf	Tue May 11 17:28:22 2010 +0300
+++ b/halservices/hal/bld.inf	Tue May 25 14:09:55 2010 +0300
@@ -1,4 +1,4 @@
-// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
+// Copyright (c) 1998-2010 Nokia Corporation and/or its subsidiary(-ies).
 // All rights reserved.
 // This component and the accompanying materials are made available
 // under the terms of the License "Eclipse Public License v1.0"
@@ -25,16 +25,30 @@
 
 BASEUSERDEFAULT
 
+
 PRJ_EXPORTS
-inc/hal_int.h						SYMBIAN_OS_LAYER_PLATFORM_EXPORT_PATH(kernel/)
-inc/hal_data.h						SYMBIAN_OS_LAYER_PLATFORM_EXPORT_PATH(hal_data.h)
-inc/hal.h							SYMBIAN_OS_LAYER_PLATFORM_EXPORT_PATH(hal.h)
-rom/hal.iby		/epoc32/rom/hal/	//
-rom/hal.hby		/epoc32/rom/hal/	//
+
+inc/hal_int.h			SYMBIAN_OS_LAYER_PLATFORM_EXPORT_PATH(kernel/)
+inc/hal_data.h			SYMBIAN_OS_LAYER_PLATFORM_EXPORT_PATH(hal_data.h)
+inc/hal.h				SYMBIAN_OS_LAYER_PLATFORM_EXPORT_PATH(hal.h)
+
+rom/hal.iby				/epoc32/rom/hal/	//
+rom/hal.hby				/epoc32/rom/hal/	//
+
+
+PRJ_TESTEXPORTS
+
+rom/haltests.iby		/epoc32/rom/include/haltests.iby
+rom/haltests.auto.bat	/epoc32/rom/include/haltests.auto.bat
+
+rom/tshell_haltests.oby	 ../../kernel/eka/rombuild/tshell_haltests.oby
+
+
 
 PRJ_MMPFILES
 src/hal_lib
 
 PRJ_TESTMMPFILES
-tsrc/t_newhal
-tsrc/savehal
+tsrc/t_newhal		manual
+tsrc/savehal		manual
+tsrc/t_haldefect
--- a/halservices/hal/inc/hal.h	Tue May 11 17:28:22 2010 +0300
+++ b/halservices/hal/inc/hal.h	Tue May 25 14:09:55 2010 +0300
@@ -1,4 +1,4 @@
-// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
+// Copyright (c) 1995-2010 Nokia Corporation and/or its subsidiary(-ies).
 // All rights reserved.
 // This component and the accompanying materials are made available
 // under the terms of the License "Eclipse Public License v1.0"
@@ -124,14 +124,17 @@
     Gets all HAL attributes, and their properties.
 
     For attributes that are not meaningful on this device (ie. those which have
-	not been defined in the config.hcf file),
-	the attribute value and its associated property value are set to zero in
-	the returned array.
+	not been defined in the config.hcf file), the attribute value and its 
+	associated property value are set to zero in the returned array.
 
 	Attributes for which multiple values can be retrieved
 	ie. EDisplayIsPalettized, EDisplayBitsPerPixel, EDisplayOffsetToFirstPixel,
 	EDisplayOffsetBetweenLines, and EDisplayPaletteEntry will also be zero in
 	the returned array.
+	
+	Attributes that allocate resources and open handles are also not returned 
+	by this API. Their value and property values will be set to zero in the
+	returned array. Use HAL::Get() for these attributes.
 
     @param aNumEntries On successful return, contains the total number
                        of HAL attributes.
--- a/halservices/hal/inc/hal_data.h	Tue May 11 17:28:22 2010 +0300
+++ b/halservices/hal/inc/hal_data.h	Tue May 25 14:09:55 2010 +0300
@@ -1,4 +1,4 @@
-// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
+// Copyright (c) 1995-2010 Nokia Corporation and/or its subsidiary(-ies).
 // All rights reserved.
 // This component and the accompanying materials are made available
 // under the terms of the License "Eclipse Public License v1.0"
@@ -35,6 +35,11 @@
     
     They are also used by the HAL accessor functions.
     
+    Note: It is not recommended to use HAL attributes to pass handles from the  
+	kernel to user-side clients due to resource overhead's that will affect 
+	existing clients of HAL. HAL is designed to allow simply hardware parameters
+	to be shared with user-side clients without resource allocation overheads.
+    
     @see HAL::Get()
     @see HAL::Set()
     */
@@ -1080,6 +1085,9 @@
 		
 		/**
 		A Handle to the display memory.
+		This attribute opens a chunk, the client is responsible for closing it.
+		Using HAL attribtues to open handles is not recommended and this 
+		attribute may be removed in the future. 
 
 		@prototype 9.5
 		*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/halservices/hal/rom/haltests.auto.bat	Tue May 25 14:09:55 2010 +0300
@@ -0,0 +1,17 @@
+rem
+rem Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+rem All rights reserved.
+rem This component and the accompanying materials are made available
+rem under the terms of the License "Eclipse Public License v1.0"
+rem which accompanies this distribution, and is available
+rem at the URL "http://www.eclipse.org/legal/epl-v10.html".
+rem
+rem Initial Contributors:
+rem Nokia Corporation - initial contribution.
+rem
+rem Contributors:
+rem
+rem Description:
+rem
+
+t_haldefect
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/halservices/hal/rom/haltests.iby	Tue May 25 14:09:55 2010 +0300
@@ -0,0 +1,28 @@
+// Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+// All rights reserved.
+// This component and the accompanying materials are made available
+// under the terms of the License "Eclipse Public License v1.0"
+// which accompanies this distribution, and is available
+// at the URL "http://www.eclipse.org/legal/epl-v10.html".
+//
+// Initial Contributors:
+// Nokia Corporation - initial contribution.
+//
+// Contributors:
+//
+// Description:
+// HAL Test Applications
+//
+
+#ifndef __HALTESTS_IBY__
+#define __HALTESTS_IBY__
+
+
+file=\Epoc32\Release\##MAIN##\##BUILD##\t_haldefect.exe 	\sys\bin\t_haldefect.exe
+file=\Epoc32\Release\##MAIN##\##BUILD##\t_newhal.exe 		\sys\bin\t_newhal.exe
+file=\Epoc32\Release\##MAIN##\##BUILD##\savehal.exe 		\sys\bin\savehal.exe
+
+data=\epoc32\rom\include\haltests.auto.bat					\haltests.auot.bat
+
+
+#endif // __HALTESTS_IBY__
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/halservices/hal/rom/tshell_haltests.oby	Tue May 25 14:09:55 2010 +0300
@@ -0,0 +1,29 @@
+/*
+* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of the License "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+*/
+
+#define BASE_ROM
+#include <rom\##VARIANT##\header.iby>
+
+
+files=
+
+#include <rom\##VARIANT##\kernel.iby>
+#include "user.iby"
+#include <rom\hal\hal.iby>
+#include <rom\f32\f32.iby>
+
+#include <rom\include\haltests.iby>
--- a/halservices/hal/src/hal_main.cpp	Tue May 11 17:28:22 2010 +0300
+++ b/halservices/hal/src/hal_main.cpp	Tue May 25 14:09:55 2010 +0300
@@ -1,4 +1,4 @@
-// Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies).
+// Copyright (c) 1999-2010 Nokia Corporation and/or its subsidiary(-ies).
 // All rights reserved.
 // This component and the accompanying materials are made available
 // under the terms of the License "Eclipse Public License v1.0"
@@ -119,7 +119,14 @@
 			{
 			TInt offset = device*(TInt)ENumHalAttributes + i;
 			TInt properties=HalInternal::Properties[i];
-			if (properties & HAL::EValid)
+			// Exclusion of the EDisplayMemoryHandle attribute is a work around
+			// to avoid the handle and resources related to it from being 
+			// allocated. Callers of this API (halsettings - to save modifiable 
+			// atrributes) need to avoid this resource overhead. Clients of 
+			// this attribute need to use HAL::Get() directly.
+			// HAL should not be used for handle opening and this
+			// attribute should be replaced with a better API.
+			if ((properties & HAL::EValid) && (i != EDisplayMemoryHandle))
 				{
 				THalImplementation f=HalInternal::Implementation[i];
 				if (f)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/halservices/hal/tsrc/t_haldefect.cpp	Tue May 25 14:09:55 2010 +0300
@@ -0,0 +1,109 @@
+// Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+// All rights reserved.
+// This component and the accompanying materials are made available
+// under the terms of the License "Eclipse Public License v1.0"
+// which accompanies this distribution, and is available
+// at the URL "http://www.eclipse.org/legal/epl-v10.html".
+//
+// Initial Contributors:
+// Nokia Corporation - initial contribution.
+//
+// Contributors:
+//
+// Description:
+//
+
+#define __E32TEST_EXTENSION__
+#include <e32test.h>
+#include <e32svr.h>
+#include <e32cmn.h>
+#include <e32cmn_private.h>
+#include <hal.h>
+
+LOCAL_D RTest test(_L("T_HalDefect Testcases"));
+
+
+	
+void DoTestRC_361803()
+	{
+	__UHEAP_MARK;
+	test.Start(_L("DoTestRC_361803 tests"));
+
+	TInt origValue = 0;
+	TInt r = HAL::Get(HALData::EDisplayMemoryHandle, origValue);
+	// Standard base emulator PSL without "-1 check", HAL::Get, r==KErrArgument
+	// Standard base emulator PSL, no mods, HAL::GetAll, r==KErrNone, origValue==0
+	// NaviEngine PSL, no mods, r==KErrNotSupported
+	// Platforms that support it: r==KErrNone, origValue==+ve 
+	if ((r == KErrNotSupported) || (r == KErrArgument) || 
+	    (origValue == 0))						 // Skip test if not supported
+		{
+		test.Printf(_L("Platform doesn't support EDigitiserOrientation, skipping, (%d, %d)\n"), r, origValue);
+		test.End();
+		__UHEAP_MARKEND;
+		return;
+		}
+	// Attribute supported
+	test_KErrNone(r);
+	RHandleBase handle;
+	handle.SetHandle(origValue);
+	handle.Close();
+	test.Printf(_L("Platform DOES support EDigitiserOrientation, handle closed\n"));
+			
+	HAL::SEntry* pE = 0;
+	TInt pC = 0;
+	r = HAL::GetAll(pC, pE);
+	test_KErrNone(r);
+	
+	const HAL::SEntry* pS=pE;
+	const HAL::SEntry* pEnd=pS + pC;
+	TBool displayMemHandleFound = EFalse;
+		
+    test.Printf(_L("ENumHalAttributes == %d, nEntries == %d\n"), HALData::ENumHalAttributes, pC);
+	for (TInt s = 0; pS<pEnd; ++pS, ++s)
+		{
+		// Following line only needed for development and debug of test case.
+		// test.Printf(_L("Attr: %d; Prop: %x; Value: %x\n"), s, pS->iProperties, pS->iValue );
+ 
+		if ((pS->iProperties & HAL::EEntryValid ) &&
+		    ((s%HAL::ENumHalAttributes) == HALData::EDisplayMemoryHandle))
+		    {		    
+		    // Note, GetAll on Emulator PSL will set r==KErrNone and value to 0
+		    // So check value to ensure a handle has been allocated.
+		    if( pS->iValue >= 0 )
+		        {
+		        displayMemHandleFound++;
+		        RHandleBase handle;
+		        handle.SetHandle(pS->iValue);
+		        handle.Close();
+				break;
+		        }
+		    }	
+		}
+	
+	test.Printf(_L("HAL::GetAll() DisplayMemHandle should not have been found (0), result == (%d)\n"), displayMemHandleFound );
+	test_Equal(displayMemHandleFound, 0);
+		
+	test.Printf(_L("DoTestRC_361803 - complete\n"));
+	test.End();
+	__UHEAP_MARKEND;
+	}
+
+
+GLDEF_C TInt E32Main()
+    {
+	__UHEAP_MARK;
+	
+ 	test.Title();
+	test.Start(_L("User-side HAL Defect Test Cases"));
+	
+	DoTestRC_361803();	// ox1cimx1#361803
+	
+	test.Printf(_L("\n"));
+	test.End();
+	test.Close();
+
+	__UHEAP_MARKEND;
+    return KErrNone;
+    }
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/halservices/hal/tsrc/t_haldefect.mmp	Tue May 25 14:09:55 2010 +0300
@@ -0,0 +1,34 @@
+/*
+* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of the License "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+*/
+
+TARGET		t_haldefect.exe
+TARGETTYPE	EXE
+
+CAPABILITY	WriteDeviceData
+VENDORID	0x70000001
+SMPSAFE
+
+OS_LAYER_SYSTEMINCLUDE_SYMBIAN
+
+SOURCEPATH	.
+SOURCE		t_haldefect.cpp
+
+LIBRARY		euser.lib
+LIBRARY		hal.lib
+
+
+
--- a/halservices/hal/tsrc/t_newhal.cpp	Tue May 11 17:28:22 2010 +0300
+++ b/halservices/hal/tsrc/t_newhal.cpp	Tue May 25 14:09:55 2010 +0300
@@ -1,4 +1,4 @@
-// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
+// Copyright (c) 1998-2010 Nokia Corporation and/or its subsidiary(-ies).
 // All rights reserved.
 // This component and the accompanying materials are made available
 // under the terms of the License "Eclipse Public License v1.0"
@@ -236,8 +236,11 @@
 			}
 		else
 			{
-			test.Printf(_L("Attribute %S not supported on this platform or requires parameter\n"),&att_name,r);
-			test(r==KErrNotSupported || r==KErrArgument);
+			test.Printf(_L("Attribute %S not supported on this platform or requires parameter: r==%d\n"),&att_name,r);
+			// For some reason the following attribtues come back "KErrNone" on 
+			// emulator...so guard added
+			if (i != HALData::EDisplayMemoryHandle)
+				test(r==KErrNotSupported || r==KErrArgument);
 			}
 		}
 	User::Free(pE);
--- a/kernel/eka/bld.inf	Tue May 11 17:28:22 2010 +0300
+++ b/kernel/eka/bld.inf	Tue May 25 14:09:55 2010 +0300
@@ -1,4 +1,4 @@
-// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
+// Copyright (c) 1998-2010 Nokia Corporation and/or its subsidiary(-ies).
 // All rights reserved.
 // This component and the accompanying materials are made available
 // under the terms of the License "Eclipse Public License v1.0"
@@ -201,14 +201,7 @@
 include/drivers/ethernet.h						SYMBIAN_OS_LAYER_PLATFORM_EXPORT_PATH(drivers/)
 include/drivers/ethernet.inl					SYMBIAN_OS_LAYER_PLATFORM_EXPORT_PATH(drivers/)
 include/drivers/dma.h							SYMBIAN_OS_LAYER_PLATFORM_EXPORT_PATH(drivers/)
-include/drivers/dma_v1.h						SYMBIAN_OS_LAYER_PLATFORM_EXPORT_PATH(drivers/)
-include/drivers/dma_v1.inl						SYMBIAN_OS_LAYER_PLATFORM_EXPORT_PATH(drivers/)
-include/drivers/dma_v2.h						SYMBIAN_OS_LAYER_PLATFORM_EXPORT_PATH(drivers/)
-include/drivers/dma_v2.inl						SYMBIAN_OS_LAYER_PLATFORM_EXPORT_PATH(drivers/)
-include/drivers/dmadefs.h						SYMBIAN_OS_LAYER_PLATFORM_EXPORT_PATH(drivers/)
-include/drivers/dma_compat.inl					SYMBIAN_OS_LAYER_PLATFORM_EXPORT_PATH(drivers/)
-include/drivers/dma_hai.h						SYMBIAN_OS_LAYER_PLATFORM_EXPORT_PATH(drivers/)
-include/drivers/dma_hai.inl						SYMBIAN_OS_LAYER_PLATFORM_EXPORT_PATH(drivers/)
+include/drivers/dma.inl							SYMBIAN_OS_LAYER_PLATFORM_EXPORT_PATH(drivers/)
 include/drivers/iic.h							SYMBIAN_OS_LAYER_PLATFORM_EXPORT_PATH(drivers/)
 include/drivers/iic.inl							SYMBIAN_OS_LAYER_PLATFORM_EXPORT_PATH(drivers/)
 include/drivers/iic_channel.h					SYMBIAN_OS_LAYER_PLATFORM_EXPORT_PATH(drivers/)
--- a/kernel/eka/bmarm/dma2u.def	Tue May 11 17:28:22 2010 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,45 +0,0 @@
-EXPORTS
-	__18TDmaTransferConfigUlUiUiUiiiUiUi13TDmaBurstSizeUiUii @ 1 NONAME ; TDmaTransferConfig::TDmaTransferConfig(unsigned long, unsigned int, unsigned int, unsigned int, int, int, unsigned int, unsigned int, TDmaBurstSize, unsigned int, unsigned int, int)
-	CancelAll__11TDmaChannel @ 2 NONAME R3UNUSED ; TDmaChannel::CancelAll(void)
-	Close__11TDmaChannel @ 3 NONAME R3UNUSED ; TDmaChannel::Close(void)
-	DisableDstElementCounting__11DDmaRequest @ 4 NONAME R3UNUSED ; DDmaRequest::DisableDstElementCounting(void)
-	DisableSrcElementCounting__11DDmaRequest @ 5 NONAME R3UNUSED ; DDmaRequest::DisableSrcElementCounting(void)
-	DmaTestInfoV2__Fv @ 6 NONAME R3UNUSED ; DmaTestInfoV2(void)
-	DmaTestInfo__Fv @ 7 NONAME R3UNUSED ; DmaTestInfo(void)
-	DmacCaps__11TDmaChannel @ 8 NONAME R3UNUSED ; TDmaChannel::DmacCaps(void)
-	DstFragmentCount__11DDmaRequest @ 9 NONAME R3UNUSED ; DDmaRequest::DstFragmentCount(void)
-	EnableDstElementCounting__11DDmaRequesti @ 10 NONAME R3UNUSED ; DDmaRequest::EnableDstElementCounting(int)
-	EnableSrcElementCounting__11DDmaRequesti @ 11 NONAME R3UNUSED ; DDmaRequest::EnableSrcElementCounting(int)
-	ExpandDesList__11DDmaRequesti @ 12 NONAME R3UNUSED ; DDmaRequest::ExpandDesList(int)
-	ExpandDstDesList__11DDmaRequesti @ 13 NONAME R3UNUSED ; DDmaRequest::ExpandDstDesList(int)
-	ExpandSrcDesList__11DDmaRequesti @ 14 NONAME R3UNUSED ; DDmaRequest::ExpandSrcDesList(int)
-	Extension__11TDmaChanneliPv @ 15 NONAME R3UNUSED ; TDmaChannel::Extension(int, void *)
-	FailNext__11TDmaChanneli @ 16 NONAME R3UNUSED ; TDmaChannel::FailNext(int)
-	FragmentCount__11DDmaRequest @ 17 NONAME R3UNUSED ; DDmaRequest::FragmentCount(void)
-	Fragment__11DDmaRequestRC16TDmaTransferArgs @ 18 NONAME R3UNUSED ; DDmaRequest::Fragment(TDmaTransferArgs const &)
-	Fragment__11DDmaRequestUlUliUiUl @ 19 NONAME ; DDmaRequest::Fragment(unsigned long, unsigned long, int, unsigned int, unsigned long)
-	FreeDesList__11DDmaRequest @ 20 NONAME R3UNUSED ; DDmaRequest::FreeDesList(void)
-	FreeDstDesList__11DDmaRequest @ 21 NONAME R3UNUSED ; DDmaRequest::FreeDstDesList(void)
-	FreeSrcDesList__11DDmaRequest @ 22 NONAME R3UNUSED ; DDmaRequest::FreeSrcDesList(void)
-	IsrRedoRequest__11TDmaChannelUlUlUiUli @ 23 NONAME ; TDmaChannel::IsrRedoRequest(unsigned long, unsigned long, unsigned int, unsigned long, int)
-	LinkToChannel__11TDmaChannelP11TDmaChannel @ 24 NONAME R3UNUSED ; TDmaChannel::LinkToChannel(TDmaChannel *)
-	MaxTransferLength__11TDmaChannelUiUiUl @ 25 NONAME ; TDmaChannel::MaxTransferLength(unsigned int, unsigned int, unsigned long)
-	MissNextInterrupts__11TDmaChanneli @ 26 NONAME R3UNUSED ; TDmaChannel::MissNextInterrupts(int)
-	Open__11TDmaChannelRCQ211TDmaChannel11SCreateInfoRP11TDmaChannel @ 27 NONAME R3UNUSED ; TDmaChannel::Open(TDmaChannel::SCreateInfo const &, TDmaChannel *&)
-	Pause__11TDmaChannel @ 28 NONAME R3UNUSED ; TDmaChannel::Pause(void)
-	Queue__11DDmaRequest @ 29 NONAME R3UNUSED ; DDmaRequest::Queue(void)
-	Resume__11TDmaChannel @ 30 NONAME R3UNUSED ; TDmaChannel::Resume(void)
-	SrcFragmentCount__11DDmaRequest @ 31 NONAME R3UNUSED ; DDmaRequest::SrcFragmentCount(void)
-	StaticExtension__11TDmaChanneliPv @ 32 NONAME R3UNUSED ; TDmaChannel::StaticExtension(int, void *)
-	TotalNumDstElementsTransferred__11DDmaRequest @ 33 NONAME R3UNUSED ; DDmaRequest::TotalNumDstElementsTransferred(void)
-	TotalNumSrcElementsTransferred__11DDmaRequest @ 34 NONAME R3UNUSED ; DDmaRequest::TotalNumSrcElementsTransferred(void)
-	"_._11DDmaRequest" @ 35 NONAME R3UNUSED ; DDmaRequest::~DDmaRequest(void)
-	__11DDmaRequestR11TDmaChannelPFQ211DDmaRequest7TResultPv_vPvi @ 36 NONAME ; DDmaRequest::DDmaRequest(TDmaChannel &, void (*)(DDmaRequest::TResult, void *), void *, int)
-	__11DDmaRequestR11TDmaChannelPFUi10TDmaResultPvP10SDmaDesHdr_vPvUi @ 37 NONAME ; DDmaRequest::DDmaRequest(TDmaChannel &, void (*)(unsigned int, TDmaResult, void *, SDmaDesHdr *), void *, unsigned int)
-	__16TDmaTransferArgs @ 38 NONAME R3UNUSED ; TDmaTransferArgs::TDmaTransferArgs(void)
-	__16TDmaTransferArgsRC18TDmaTransferConfigT1UlUiUi15TDmaGraphicsOpsUl @ 39 NONAME ; TDmaTransferArgs::TDmaTransferArgs(TDmaTransferConfig const &, TDmaTransferConfig const &, unsigned long, unsigned int, unsigned int, TDmaGraphicsOps, unsigned long)
-	__16TDmaTransferArgsUiUiUiUiUiUi12TDmaAddrModeUiUi13TDmaBurstSizeUi15TDmaGraphicsOpsUl @ 40 NONAME ; TDmaTransferArgs::TDmaTransferArgs(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, TDmaAddrMode, unsigned int, unsigned int, TDmaBurstSize, unsigned int, TDmaGraphicsOps, unsigned long)
-	__18TDmaTransferConfig @ 41 NONAME R3UNUSED ; TDmaTransferConfig::TDmaTransferConfig(void)
-	__18TDmaTransferConfigUlUi12TDmaAddrModeUi13TDmaBurstSizeUiUiUii @ 42 NONAME ; TDmaTransferConfig::TDmaTransferConfig(unsigned long, unsigned int, TDmaAddrMode, unsigned int, TDmaBurstSize, unsigned int, unsigned int, unsigned int, int)
-	AddressAlignMask__11TDmaChannelUiUiUl @ 43 NONAME ; TDmaChannel::AddressAlignMask(unsigned int, unsigned int, unsigned long)
-
--- a/kernel/eka/drivers/bsp/bld.inf	Tue May 11 17:28:22 2010 +0300
+++ b/kernel/eka/drivers/bsp/bld.inf	Tue May 25 14:09:55 2010 +0300
@@ -1,4 +1,4 @@
-// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
+// Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
 // All rights reserved.
 // This component and the accompanying materials are made available
 // under the terms of the License "Eclipse Public License v1.0"
@@ -37,7 +37,6 @@
 #if !defined(WINS) 
 #if !defined(X86)
 ../dma/dma_lib
-../dma/dma2_lib
 #endif
 #endif
 
--- a/kernel/eka/drivers/dma/dma2_lib.mmp	Tue May 11 17:28:22 2010 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,30 +0,0 @@
-// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
-// All rights reserved.
-// This component and the accompanying materials are made available
-// under the terms of "Eclipse Public License v1.0"
-// which accompanies this distribution, and is available
-// at the URL "http://www.eclipse.org/legal/epl-v10.html".
-//
-// Initial Contributors:
-// Nokia Corporation - initial contribution.
-//
-// Contributors:
-//
-// Description:
-// e32\drivers\dma\dma2_lib.mmp
-// 
-//
-
-target			dma2.lib
-targettype		implib
-linkas			dma.dll
-
-#if defined(EABI)
-deffile				../../eabi/dma2.def 
-#elif defined(GCC32)
-deffile				../../bmarm/dma2.def 
-#endif
-
-VENDORID 0x70000001
-
-SMPSAFE
--- a/kernel/eka/drivers/dma/dma2_pil.cpp	Tue May 11 17:28:22 2010 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,2237 +0,0 @@
-// Copyright (c) 2002-2010 Nokia Corporation and/or its subsidiary(-ies).
-// All rights reserved.
-// This component and the accompanying materials are made available
-// under the terms of "Eclipse Public License v1.0"
-// which accompanies this distribution, and is available
-// at the URL "http://www.eclipse.org/legal/epl-v10.html".
-//
-// Initial Contributors:
-// Nokia Corporation - initial contribution.
-//
-// Contributors:
-//
-// Description:
-// e32/drivers/dma2_pil.cpp
-// DMA Platform Independent Layer (PIL)
-//
-//
-
-#include <drivers/dma.h>
-#include <drivers/dma_hai.h>
-
-#include <kernel/kern_priv.h>
-
-
-// Symbian Min() & Max() are broken, so we have to define them ourselves
-inline TUint Min(TUint aLeft, TUint aRight)
-	{return(aLeft < aRight ? aLeft : aRight);}
-inline TUint Max(TUint aLeft, TUint aRight)
-	{return(aLeft > aRight ? aLeft : aRight);}
-
-
-// Uncomment the following #define only when freezing the DMA2 export library.
-//#define __FREEZE_DMA2_LIB
-#ifdef __FREEZE_DMA2_LIB
-TInt DmaChannelMgr::StaticExtension(TInt, TAny*) {return 0;}
-TDmaChannel* DmaChannelMgr::Open(TUint32, TBool, TUint) {return 0;}
-void DmaChannelMgr::Close(TDmaChannel*) {}
-EXPORT_C const TDmaTestInfo& DmaTestInfo() {static TDmaTestInfo a; return a;}
-EXPORT_C const TDmaV2TestInfo& DmaTestInfoV2() {static TDmaV2TestInfo a; return a;}
-#endif	// #ifdef __FREEZE_DMA2_LIB
-
-
-static const char KDmaPanicCat[] = "DMA " __FILE__;
-
-//////////////////////////////////////////////////////////////////////
-// DmaChannelMgr
-//
-// Wait, Signal, and Initialise are defined here in the PIL.
-// Open, Close and Extension must be defined in the PSL.
-
-NFastMutex DmaChannelMgr::Lock;
-
-
-void DmaChannelMgr::Wait()
-	{
-	NKern::FMWait(&Lock);
-	}
-
-
-void DmaChannelMgr::Signal()
-	{
-	NKern::FMSignal(&Lock);
-	}
-
-
-TInt DmaChannelMgr::Initialise()
-	{
-	return KErrNone;
-	}
-
-
-class TDmaCancelInfo : public SDblQueLink
-	{
-public:
-	TDmaCancelInfo();
-	void Signal();
-public:
-	NFastSemaphore iSem;
-	};
-
-
-TDmaCancelInfo::TDmaCancelInfo()
-	: iSem(0)
-	{
-	iNext = this;
-	iPrev = this;
-	}
-
-
-void TDmaCancelInfo::Signal()
-	{
-	TDmaCancelInfo* p = this;
-	FOREVER
-		{
-		TDmaCancelInfo* next = (TDmaCancelInfo*)p->iNext;
-		if (p!=next)
-			p->Deque();
-		NKern::FSSignal(&p->iSem);	// Don't dereference p after this
-		if (p==next)
-			break;
-		p = next;
-		}
-	}
-
-
-//////////////////////////////////////////////////////////////////////////////
-
-#ifdef __DMASIM__
-#ifdef __WINS__
-typedef TLinAddr TPhysAddr;
-#endif
-static inline TPhysAddr LinToPhys(TLinAddr aLin) {return aLin;}
-#else
-static inline TPhysAddr LinToPhys(TLinAddr aLin) {return Epoc::LinearToPhysical(aLin);}
-#endif
-
-//
-// Return minimum of aMaxSize and size of largest physically contiguous block
-// starting at aLinAddr.
-//
-static TInt MaxPhysSize(TLinAddr aLinAddr, const TInt aMaxSize)
-	{
-	const TPhysAddr physBase = LinToPhys(aLinAddr);
-	TLinAddr lin = aLinAddr;
-	TInt size = 0;
-	for (;;)
-		{
-		// Round up the linear address to the next MMU page boundary
-		const TLinAddr linBoundary = Kern::RoundToPageSize(lin + 1);
-		size += linBoundary - lin;
-		if (size >= aMaxSize)
-			return aMaxSize;
-		if ((physBase + size) != LinToPhys(linBoundary))
-			return size;
-		lin = linBoundary;
-		}
-	}
-
-
-//////////////////////////////////////////////////////////////////////////////
-// TDmac
-
-TDmac::TDmac(const SCreateInfo& aInfo)
-	: iMaxDesCount(aInfo.iDesCount),
-	  iAvailDesCount(aInfo.iDesCount),
-	  iHdrPool(NULL),
-#ifndef __WINS__
-	  iHwDesChunk(NULL),
-#endif
-	  iDesPool(NULL),
-	  iDesSize(aInfo.iDesSize),
-	  iCapsHwDes(aInfo.iCapsHwDes),
-	  iFreeHdr(NULL)
-	{
-	__DMA_ASSERTD(iMaxDesCount > 0);
-	__DMA_ASSERTD(iDesSize > 0);
-	}
-
-
-//
-// Second-phase c'tor
-//
-TInt TDmac::Create(const SCreateInfo& aInfo)
-	{
-	iHdrPool = new SDmaDesHdr[iMaxDesCount];
-	if (iHdrPool == NULL)
-		{
-		return KErrNoMemory;
-		}
-
-	TInt r = AllocDesPool(aInfo.iDesChunkAttribs);
-	if (r != KErrNone)
-		{
-		return KErrNoMemory;
-		}
-
-	// Link all descriptor headers together on the free list
-	iFreeHdr = iHdrPool;
-	for (TInt i = 0; i < iMaxDesCount - 1; i++)
-		iHdrPool[i].iNext = iHdrPool + i + 1;
-	iHdrPool[iMaxDesCount-1].iNext = NULL;
-
-	__DMA_INVARIANT();
-	return KErrNone;
-	}
-
-
-TDmac::~TDmac()
-	{
-	__DMA_INVARIANT();
-
-	FreeDesPool();
-	delete[] iHdrPool;
-	}
-
-
-void TDmac::Transfer(const TDmaChannel& /*aChannel*/, const SDmaDesHdr& /*aHdr*/)
-	{
-	// TDmac needs to override this function if it has reported the channel
-	// type for which the PIL calls it.
-	__DMA_CANT_HAPPEN();
-	}
-
-
-void TDmac::Transfer(const TDmaChannel& /*aChannel*/, const SDmaDesHdr& /*aSrcHdr*/,
-					 const SDmaDesHdr& /*aDstHdr*/)
-	{
-	// TDmac needs to override this function if it has reported the channel
-	// type for which the PIL calls it.
-	__DMA_CANT_HAPPEN();
-	}
-
-
-TInt TDmac::PauseTransfer(const TDmaChannel& /*aChannel*/)
-	{
-	// TDmac needs to override this function if it has reported support for
-	// channel pausing/resuming.
-	return KErrNotSupported;
-	}
-
-
-TInt TDmac::ResumeTransfer(const TDmaChannel& /*aChannel*/)
-	{
-	// TDmac needs to override this function if it has reported support for
-	// channel pausing/resuming.
-	return KErrNotSupported;
-	}
-
-
-TInt TDmac::AllocDesPool(TUint aAttribs)
-	{
-	// Calling thread must be in CS
-	__ASSERT_CRITICAL;
-	TInt r;
-	if (iCapsHwDes)
-		{
-		const TInt size = iMaxDesCount * iDesSize;
-#ifdef __WINS__
-		(void)aAttribs;
-		iDesPool = new TUint8[size];
-		r = iDesPool ? KErrNone : KErrNoMemory;
-#else
-		// Chunk not mapped as supervisor r/w user none? incorrect mask passed by PSL
-		__DMA_ASSERTD((aAttribs & EMapAttrAccessMask) == EMapAttrSupRw);
-		TPhysAddr phys;
-		r = Epoc::AllocPhysicalRam(size, phys);
-		if (r == KErrNone)
-			{
-			r = DPlatChunkHw::New(iHwDesChunk, phys, size, aAttribs);
-			if (r == KErrNone)
-				{
-				iDesPool = (TAny*)iHwDesChunk->LinearAddress();
-				__KTRACE_OPT(KDMA, Kern::Printf("descriptor hw chunk created lin=0x%08X phys=0x%08X, size=0x%X",
-												iHwDesChunk->iLinAddr, iHwDesChunk->iPhysAddr, size));
-				}
-			else
-				Epoc::FreePhysicalRam(phys, size);
-			}
-#endif
-		}
-	else
-		{
-		iDesPool = new TDmaTransferArgs[iMaxDesCount];
-		r = iDesPool ? KErrNone : KErrNoMemory;
-		}
-	return r;
-	}
-
-
-void TDmac::FreeDesPool()
-	{
-	// Calling thread must be in CS
-	__ASSERT_CRITICAL;
-	if (iCapsHwDes)
-		{
-#ifdef __WINS__
-		delete[] iDesPool;
-#else
-		if (iHwDesChunk)
-			{
-			const TPhysAddr phys = iHwDesChunk->PhysicalAddress();
-			const TInt size = iHwDesChunk->iSize;
-			iHwDesChunk->Close(NULL);
-			Epoc::FreePhysicalRam(phys, size);
-			}
-#endif
-		}
-	else
-		{
-		Kern::Free(iDesPool);
-		}
-	}
-
-
-//
-// Prealloc the given number of descriptors.
-//
-TInt TDmac::ReserveSetOfDes(TInt aCount)
-	{
-	__KTRACE_OPT(KDMA, Kern::Printf("TDmac::ReserveSetOfDes count=%d", aCount));
-	__DMA_ASSERTD(aCount > 0);
-	TInt r = KErrTooBig;
-	Wait();
-	if (iAvailDesCount - aCount >= 0)
-		{
-		iAvailDesCount -= aCount;
-		r = KErrNone;
-		}
-	Signal();
-	__DMA_INVARIANT();
-	return r;
-	}
-
-
-//
-// Return the given number of preallocated descriptors to the free pool.
-//
-void TDmac::ReleaseSetOfDes(TInt aCount)
-	{
-	__DMA_ASSERTD(aCount >= 0);
-	Wait();
-	iAvailDesCount += aCount;
-	Signal();
-	__DMA_INVARIANT();
-	}
-
-
-//
-// Queue DFC and update word used to communicate with channel DFC.
-//
-// Called in interrupt context by PSL.
-//
-void TDmac::HandleIsr(TDmaChannel& aChannel, TUint aEventMask, TBool aIsComplete)
-	{
-	__KTRACE_OPT(KDMA, Kern::Printf("TDmac::HandleIsr"));
-
-	// Function needs to be called by PSL in ISR context
-	__DMA_ASSERTD(NKern::CurrentContext() == NKern::EInterrupt);
-
-	// First the ISR callback stuff
-
-	// Is this a transfer completion notification?
-	if (aEventMask & EDmaCallbackRequestCompletion)
-		{
-		// If so, has the client requested an ISR callback?
-		if (__e32_atomic_load_acq32(&aChannel.iIsrCbRequest))
-			{
-			__KTRACE_OPT(KDMA, Kern::Printf("ISR callback"));
-
-			// Since iIsrCbRequest was set no threads will be
-			// modifying the request queue.
-			const DDmaRequest* const req = _LOFF(aChannel.iReqQ.First(), DDmaRequest, iLink);
-
-			// We expect the request to have requested
-			// ISR callback
-			__NK_ASSERT_DEBUG(req->iIsrCb);
-
-			TDmaCallback const cb = req->iDmaCb;
-			TAny* const arg = req->iDmaCbArg;
-			// Execute the client callback
-			(*cb)(EDmaCallbackRequestCompletion,
-				  (aIsComplete ? EDmaResultOK : EDmaResultError),
-				  arg,
-				  NULL);
-			// Now let's see if the callback rescheduled the transfer request
-			// (see TDmaChannel::IsrRedoRequest()).
-			const TBool redo = aChannel.iRedoRequest;
-			aChannel.iRedoRequest = EFalse;
-			const TBool stop = __e32_atomic_load_acq32(&aChannel.iIsrDfc) &
-				(TUint32)TDmaChannel::KCancelFlagMask;
-			// There won't be another ISR callback if this callback didn't
-			// reschedule the request, or the client cancelled all requests, or
-			// this callback rescheduled the request with a DFC callback.
-			if (!redo || stop || !req->iIsrCb)
-				{
-				__e32_atomic_store_rel32(&aChannel.iIsrCbRequest, EFalse);
-				}
-			if (redo && !stop)
-				{
-				// We won't queue the channel DFC in this case and just return.
-				__KTRACE_OPT(KDMA, Kern::Printf("CB rescheduled xfer -> no DFC"));
-				return;
-				}
-			// Not redoing or being cancelled means we've been calling the
-			// request's ISR callback for the last time. We're going to
-			// complete the request via the DFC in the usual way.
-			}
-		}
-
-	// Now queue a DFC if necessary. The possible scenarios are:
-	// a) DFC not queued (orig == 0)              -> update iIsrDfc + queue DFC
-	// b) DFC queued, not running yet (orig != 0) -> just update iIsrDfc
-	// c) DFC running / iIsrDfc not reset yet (orig != 0) -> just update iIsrDfc
-	// d) DFC running / iIsrDfc already reset (orig == 0) -> update iIsrDfc + requeue DFC
-
-	// Set error flag if necessary.
-	const TUint32 inc = aIsComplete ? 1u : TUint32(TDmaChannel::KErrorFlagMask) | 1u;
-
-	// Add 'inc' (interrupt count increment + poss. error flag) to 'iIsrDfc' if
-	// cancel flag is not set, do nothing otherwise. Assign original value of
-	// 'iIsrDfc' to 'orig' in any case.
-	const TUint32 orig = __e32_atomic_tau_ord32(&aChannel.iIsrDfc,
-												TUint32(TDmaChannel::KCancelFlagMask),
-												0,
-												inc);
-
-	// As transfer should be suspended when an error occurs, we
-	// should never get there with the error flag already set.
-	__DMA_ASSERTD((orig & inc & (TUint32)TDmaChannel::KErrorFlagMask) == 0);
-
-	if (orig == 0)
-		{
-		aChannel.iDfc.Add();
-		}
-	}
-
-
-TInt TDmac::InitDes(const SDmaDesHdr& aHdr, const TDmaTransferArgs& aTransferArgs)
-	{
-	__KTRACE_OPT(KDMA, Kern::Printf("TDmac::InitDes"));
-	TInt r;
-	if (iCapsHwDes)
-		{
-		__KTRACE_OPT(KDMA, Kern::Printf("iCaps.iHwDescriptors"));
-		r = InitHwDes(aHdr, aTransferArgs);
-		}
-	else
-		{
-		TDmaTransferArgs& args = HdrToDes(aHdr);
-		args = aTransferArgs;
-		r = KErrNone;
-		}
-	return r;
-	}
-
-
-TInt TDmac::InitHwDes(const SDmaDesHdr& /*aHdr*/, const TDmaTransferArgs& /*aTransferArgs*/)
-	{
-	// concrete controller must override if SDmacCaps::iHwDescriptors set
-	__DMA_CANT_HAPPEN();
-	return KErrGeneral;
-	}
-
-
-TInt TDmac::InitSrcHwDes(const SDmaDesHdr& /*aHdr*/, const TDmaTransferArgs& /*aTransferArgs*/)
-	{
-	// concrete controller must override if SDmacCaps::iAsymHwDescriptors set
-	__DMA_CANT_HAPPEN();
-	return KErrGeneral;
-	}
-
-
-TInt TDmac::InitDstHwDes(const SDmaDesHdr& /*aHdr*/, const TDmaTransferArgs& /*aTransferArgs*/)
-	{
-	// concrete controller must override if SDmacCaps::iAsymHwDescriptors set
-	__DMA_CANT_HAPPEN();
-	return KErrGeneral;
-	}
-
-
-TInt TDmac::UpdateDes(const SDmaDesHdr& aHdr, TUint32 aSrcAddr, TUint32 aDstAddr,
-					  TUint aTransferCount, TUint32 aPslRequestInfo)
-	{
-	__KTRACE_OPT(KDMA, Kern::Printf("TDmac::UpdateDes"));
-	TInt r;
-	if (iCapsHwDes)
-		{
-		__KTRACE_OPT(KDMA, Kern::Printf("iCaps.iHwDescriptors"));
-		r = UpdateHwDes(aHdr, aSrcAddr, aDstAddr, aTransferCount, aPslRequestInfo);
-		}
-	else
-		{
-		TDmaTransferArgs& args = HdrToDes(aHdr);
-		if (aSrcAddr != KPhysAddrInvalid)
-			args.iSrcConfig.iAddr = aSrcAddr;
-		if (aDstAddr != KPhysAddrInvalid)
-			args.iDstConfig.iAddr = aDstAddr;
-		if (aTransferCount)
-			args.iTransferCount = aTransferCount;
-		if (aPslRequestInfo)
-			args.iPslRequestInfo = aPslRequestInfo;
-		r = KErrNone;
-		}
-	return r;
-	}
-
-
-TInt TDmac::UpdateHwDes(const SDmaDesHdr& /*aHdr*/, TUint32 /*aSrcAddr*/, TUint32 /*aDstAddr*/,
-						TUint /*aTransferCount*/, TUint32 /*aPslRequestInfo*/)
-	{
-	// concrete controller must override if SDmacCaps::iHwDescriptors set
-	__DMA_CANT_HAPPEN();
-	return KErrGeneral;
-	}
-
-
-TInt TDmac::UpdateSrcHwDes(const SDmaDesHdr& /*aHdr*/, TUint32 /*aSrcAddr*/,
-						   TUint /*aTransferCount*/, TUint32 /*aPslRequestInfo*/)
-	{
-	// concrete controller must override if SDmacCaps::iAsymHwDescriptors set
-	__DMA_CANT_HAPPEN();
-	return KErrGeneral;
-	}
-
-
-TInt TDmac::UpdateDstHwDes(const SDmaDesHdr& /*aHdr*/, TUint32 /*aDstAddr*/,
-						   TUint /*aTransferCount*/, TUint32 /*aPslRequestInfo*/)
-	{
-	// concrete controller must override if SDmacCaps::iAsymHwDescriptors set
-	__DMA_CANT_HAPPEN();
-	return KErrGeneral;
-	}
-
-
-void TDmac::ChainHwDes(const SDmaDesHdr& /*aHdr*/, const SDmaDesHdr& /*aNextHdr*/)
-	{
-	// concrete controller must override if SDmacCaps::iHwDescriptors set
-	__DMA_CANT_HAPPEN();
-	}
-
-
-void TDmac::AppendHwDes(const TDmaChannel& /*aChannel*/, const SDmaDesHdr& /*aLastHdr*/,
-						const SDmaDesHdr& /*aNewHdr*/)
-	{
- 	// concrete controller must override if SDmacCaps::iHwDescriptors set
-	__DMA_CANT_HAPPEN();
-	}
-
-
-void TDmac::AppendHwDes(const TDmaChannel& /*aChannel*/,
-						const SDmaDesHdr& /*aSrcLastHdr*/, const SDmaDesHdr& /*aSrcNewHdr*/,
-						const SDmaDesHdr& /*aDstLastHdr*/, const SDmaDesHdr& /*aDstNewHdr*/)
-	{
-	// concrete controller must override if SDmacCaps::iAsymHwDescriptors set
-	__DMA_CANT_HAPPEN();
-	}
-
-
-void TDmac::UnlinkHwDes(const TDmaChannel& /*aChannel*/, SDmaDesHdr& /*aHdr*/)
-	{
- 	// concrete controller must override if SDmacCaps::iHwDescriptors set
-	__DMA_CANT_HAPPEN();
-	}
-
-
-void TDmac::ClearHwDes(const SDmaDesHdr& /*aHdr*/)
-	{
-	// default implementation - NOP; concrete controller may override
-	return;
-	}
-
-
-TInt TDmac::LinkChannels(TDmaChannel& /*a1stChannel*/, TDmaChannel& /*a2ndChannel*/)
-	{
-	// default implementation - NOP; concrete controller may override
-	return KErrNotSupported;
-	}
-
-
-TInt TDmac::UnlinkChannel(TDmaChannel& /*aChannel*/)
-	{
-	// default implementation - NOP; concrete controller may override
-	return KErrNotSupported;
-	}
-
-
-TInt TDmac::FailNext(const TDmaChannel& /*aChannel*/)
-	{
-	// default implementation - NOP; concrete controller may override
-	return KErrNotSupported;
-	}
-
-
-TInt TDmac::MissNextInterrupts(const TDmaChannel& /*aChannel*/, TInt /*aInterruptCount*/)
-	{
-	// default implementation - NOP; concrete controller may override
-	return KErrNotSupported;
-	}
-
-
-TInt TDmac::Extension(TDmaChannel& /*aChannel*/, TInt /*aCmd*/, TAny* /*aArg*/)
-	{
-	// default implementation - NOP; concrete controller may override
-	return KErrNotSupported;
-	}
-
-
-TUint32 TDmac::HwDesNumDstElementsTransferred(const SDmaDesHdr& /*aHdr*/)
-	{
- 	// Concrete controller must override if SDmacCaps::iHwDescriptors set.
-	__DMA_CANT_HAPPEN();
-	return 0;
-	}
-
-
-TUint32 TDmac::HwDesNumSrcElementsTransferred(const SDmaDesHdr& /*aHdr*/)
-	{
- 	// Concrete controller must override if SDmacCaps::iHwDescriptors set.
-	__DMA_CANT_HAPPEN();
-	return 0;
-	}
-
-
-#ifdef _DEBUG
-
-void TDmac::Invariant()
-	{
-	Wait();
-	__DMA_ASSERTD(0 <= iAvailDesCount && iAvailDesCount <= iMaxDesCount);
-	__DMA_ASSERTD(! iFreeHdr || IsValidHdr(iFreeHdr));
-	for (TInt i = 0; i < iMaxDesCount; i++)
-		__DMA_ASSERTD(iHdrPool[i].iNext == NULL || IsValidHdr(iHdrPool[i].iNext));
-	Signal();
-	}
-
-
-TBool TDmac::IsValidHdr(const SDmaDesHdr* aHdr)
-	{
-	return (iHdrPool <= aHdr) && (aHdr < iHdrPool + iMaxDesCount);
-	}
-
-#endif
-
-
-
-
-//
-// Internal compat version, used by legacy Fragment()
-//
-TDmaTransferConfig::TDmaTransferConfig(TUint32 aAddr, TUint aFlags, TBool aAddrInc)
-	: iAddr(aAddr),
-	  iAddrMode(aAddrInc ? KDmaAddrModePostIncrement : KDmaAddrModeConstant),
-	  iElementSize(0),
-	  iElementsPerFrame(0),
-	  iElementsPerPacket(0),
-	  iFramesPerTransfer(0),
-	  iElementSkip(0),
-	  iFrameSkip(0),
-	  iBurstSize(KDmaBurstSizeAny),
-	  iFlags(aFlags),
-	  iSyncFlags(KDmaSyncAuto),
-	  iPslTargetInfo(0),
-	  iRepeatCount(0),
-	  iDelta(~0u),
-	  iReserved(0)
-	{
-	}
-
-
-
-//
-// Internal compat version, used by legacy Fragment()
-//
-TDmaTransferArgs::TDmaTransferArgs(TUint32 aSrc, TUint32 aDest, TInt aCount,
-								   TUint aFlags, TUint32 aPslInfo)
-	: iSrcConfig(aSrc, RequestFlags2SrcConfigFlags(aFlags), (aFlags & KDmaIncSrc)),
-	  iDstConfig(aDest, RequestFlags2DstConfigFlags(aFlags), (aFlags & KDmaIncDest)),
-	  iTransferCount(aCount),
-	  iGraphicsOps(KDmaGraphicsOpNone),
-	  iColour(0),
-	  iFlags(0),
-	  iChannelPriority(KDmaPriorityNone),
-	  iPslRequestInfo(aPslInfo),
-	  iDelta(~0u),
-	  iReserved1(0),
-	  iChannelCookie(0),
-	  iReserved2(0)
-	{
-	}
-
-
-//
-// As DDmaRequest is derived from DBase, the initializations with zero aren't
-// strictly necessary here, but this way it's nicer.
-//
-EXPORT_C DDmaRequest::DDmaRequest(TDmaChannel& aChannel, TCallback aCb,
-								  TAny* aCbArg, TInt aMaxTransferSize)
-	: iChannel(aChannel),
-	  iCb(aCb),
-	  iCbArg(aCbArg),
-	  iDmaCb(NULL),
-	  iDmaCbArg(NULL),
-	  iIsrCb(EFalse),
-	  iDesCount(0),
-	  iFirstHdr(NULL),
-	  iLastHdr(NULL),
-	  iSrcDesCount(0),
-	  iSrcFirstHdr(NULL),
-	  iSrcLastHdr(NULL),
-	  iDstDesCount(0),
-	  iDstFirstHdr(NULL),
-	  iDstLastHdr(NULL),
-	  iQueued(EFalse),
-	  iMaxTransferSize(aMaxTransferSize),
-	  iTotalNumSrcElementsTransferred(0),
-	  iTotalNumDstElementsTransferred(0)
-	{
-	iChannel.iReqCount++;
-	__DMA_ASSERTD(0 <= aMaxTransferSize);
-	__DMA_INVARIANT();
-	}
-
-
-//
-// As DDmaRequest is derived from DBase, the initializations with zero aren't
-// strictly necessary here, but this way it's nicer.
-//
-EXPORT_C DDmaRequest::DDmaRequest(TDmaChannel& aChannel, TDmaCallback aDmaCb,
-								  TAny* aCbArg, TUint aMaxTransferSize)
-	: iChannel(aChannel),
-	  iCb(NULL),
-	  iCbArg(NULL),
-	  iDmaCb(aDmaCb),
-	  iDmaCbArg(aCbArg),
-	  iIsrCb(EFalse),
-	  iDesCount(0),
-	  iFirstHdr(NULL),
-	  iLastHdr(NULL),
-	  iSrcDesCount(0),
-	  iSrcFirstHdr(NULL),
-	  iSrcLastHdr(NULL),
-	  iDstDesCount(0),
-	  iDstFirstHdr(NULL),
-	  iDstLastHdr(NULL),
-	  iQueued(EFalse),
-	  iMaxTransferSize(aMaxTransferSize),
-	  iTotalNumSrcElementsTransferred(0),
-	  iTotalNumDstElementsTransferred(0)
-	{
-	__e32_atomic_add_ord32(&iChannel.iReqCount, 1);
-	__DMA_INVARIANT();
-	}
-
-
-EXPORT_C DDmaRequest::~DDmaRequest()
-	{
-	__DMA_ASSERTD(!iQueued);
-	__DMA_INVARIANT();
-	FreeDesList();
-	__e32_atomic_add_ord32(&iChannel.iReqCount, TUint32(-1));
-	}
-
-
-EXPORT_C TInt DDmaRequest::Fragment(TUint32 aSrc, TUint32 aDest, TInt aCount,
-									TUint aFlags, TUint32 aPslInfo)
-	{
-	__KTRACE_OPT(KDMA, Kern::Printf("DDmaRequest::Fragment thread %O "
-									"src=0x%08X dest=0x%08X count=%d flags=0x%X psl=0x%08X",
-									&Kern::CurrentThread(), aSrc, aDest, aCount, aFlags, aPslInfo));
-	__DMA_ASSERTD(aCount > 0);
-
-	TDmaTransferArgs args(aSrc, aDest, aCount, aFlags, aPslInfo);
-
-	return Frag(args);
-	}
-
-
-EXPORT_C TInt DDmaRequest::Fragment(const TDmaTransferArgs& aTransferArgs)
-	{
-	__KTRACE_OPT(KDMA, Kern::Printf("DDmaRequest::Fragment thread %O", &Kern::CurrentThread()));
-
-	// Writable temporary working copy of the transfer arguments.
-	// We need this because we may have to modify some fields before passing it
-	// to the PSL (for example iChannelCookie, iTransferCount,
-	// iDstConfig::iAddr, and iSrcConfig::iAddr).
-	TDmaTransferArgs args(aTransferArgs);
-
-	return Frag(args);
-	}
-
-
-TUint DDmaRequest::GetTransferCount(const TDmaTransferArgs& aTransferArgs)
-	{
-	const TDmaTransferConfig& src = aTransferArgs.iSrcConfig;
-	const TDmaTransferConfig& dst = aTransferArgs.iDstConfig;
-
-	TUint count = aTransferArgs.iTransferCount;
-	if (count == 0)
-		{
-		__KTRACE_OPT(KDMA, Kern::Printf("iTransferCount == 0"));
-		count = src.iElementSize * src.iElementsPerFrame *
-			src.iFramesPerTransfer;
-		const TUint dst_cnt = dst.iElementSize * dst.iElementsPerFrame *
-			dst.iFramesPerTransfer;
-		if (count != dst_cnt)
-			{
-			__KTRACE_OPT(KPANIC, Kern::Printf("Error: (count != dst_cnt)"));
-			return 0;
-			}
-		}
-	else
-		{
-		__KTRACE_OPT(KDMA, Kern::Printf("iTransferCount == %d", count));
-		// Client shouldn't specify contradictory or incomplete things
-		if (src.iElementSize != 0)
-			{
-			if ((count % src.iElementSize) != 0)
-				{
-				__KTRACE_OPT(KPANIC,
-							 Kern::Printf("Error: ((count %% src.iElementSize) != 0)"));
-				return 0;
-				}
-			if (src.iElementsPerFrame != 0)
-				{
-				if ((src.iElementSize * src.iElementsPerFrame * src.iFramesPerTransfer) != count)
-					{
-					__KTRACE_OPT(KPANIC,
-								 Kern::Printf("Error: ((src.iElementSize * "
-											  "src.iElementsPerFrame * "
-											  "src.iFramesPerTransfer) != count)"));
-					return 0;
-					}
-				}
-			}
-		else
-			{
-			if (src.iElementsPerFrame != 0)
-				{
-				__KTRACE_OPT(KPANIC,
-							 Kern::Printf("Error: (src.iElementsPerFrame != 0)"));
-				return 0;
-				}
-			if (src.iFramesPerTransfer != 0)
-				{
-				__KTRACE_OPT(KPANIC,
-							 Kern::Printf("Error: (src.iFramesPerTransfer != 0)"));
-				return 0;
-				}
-			if (src.iElementsPerPacket != 0)
-				{
-				__KTRACE_OPT(KPANIC,
-							 Kern::Printf("Error: (src.iElementsPerPacket != 0)"));
-				return 0;
-				}
-			}
-		if (dst.iElementSize != 0)
-			{
-			if ((count % dst.iElementSize) != 0)
-				{
-				__KTRACE_OPT(KPANIC,
-							 Kern::Printf("Error: ((count %% dst.iElementSize) != 0)"));
-				return 0;
-				}
-			if (dst.iElementsPerFrame != 0)
-				{
-				if ((dst.iElementSize * dst.iElementsPerFrame * dst.iFramesPerTransfer) != count)
-					{
-					__KTRACE_OPT(KPANIC,
-								 Kern::Printf("Error: ((dst.iElementSize * "
-											  "dst.iElementsPerFrame * "
-											  "dst.iFramesPerTransfer) != count)"));
-					return 0;
-					}
-				}
-			}
-		else
-			{
-			if (dst.iElementsPerFrame != 0)
-				{
-				__KTRACE_OPT(KPANIC,
-							 Kern::Printf("Error: (dst.iElementsPerFrame != 0)"));
-				return 0;
-				}
-			if (dst.iFramesPerTransfer != 0)
-				{
-				__KTRACE_OPT(KPANIC,
-							 Kern::Printf("Error: (dst.iFramesPerTransfer != 0)"));
-				return 0;
-				}
-			if (dst.iElementsPerPacket != 0)
-				{
-				__KTRACE_OPT(KPANIC,
-							 Kern::Printf("Error: (dst.iElementsPerPacket != 0)"));
-				return 0;
-				}
-			}
-		}
-	return count;
-	}
-
-
-TInt DDmaRequest::Frag(TDmaTransferArgs& aTransferArgs)
-	{
-	__DMA_ASSERTD(!iQueued);
-
-	// Transfer count checks
-	const TUint count = GetTransferCount(aTransferArgs);
-	if (count == 0)
-		{
-		return KErrArgument;
-		}
-
-	const TDmaTransferConfig& src = aTransferArgs.iSrcConfig;
-	const TDmaTransferConfig& dst = aTransferArgs.iDstConfig;
-
-	// Ask the PSL what the maximum length possible for this transfer is
-	TUint max_xfer_len = iChannel.MaxTransferLength(src.iFlags, dst.iFlags,
-													aTransferArgs.iPslRequestInfo);
-	if (iMaxTransferSize)
-		{
-		// User has set a size cap
-		__KTRACE_OPT(KDMA, Kern::Printf("iMaxTransferSize != 0"));
-		__DMA_ASSERTA((iMaxTransferSize <= max_xfer_len) || (max_xfer_len == 0));
-		max_xfer_len = iMaxTransferSize;
-		}
-	else
-		{
-		// User doesn't care about max size
-		if (max_xfer_len == 0)
-			{
-			// No maximum imposed by controller
-			max_xfer_len = count;
-			}
-		}
-
-	// ISR callback requested?
-	const TBool isr_cb = (aTransferArgs.iFlags & KDmaRequestCallbackFromIsr);
-	if (isr_cb)
-		{
-		// Requesting an ISR callback w/o supplying one?
-		if (!iDmaCb)
-			{
-			return KErrArgument;
-			}
-		}
-
-	// Set the channel cookie for the PSL
-	aTransferArgs.iChannelCookie = iChannel.PslId();
-
-	// Now the actual fragmentation
-	TInt r;
-	if (iChannel.iDmacCaps->iAsymHwDescriptors)
-		{
-		r = FragAsym(aTransferArgs, count, max_xfer_len);
-		}
-	else
-		{
-		r = FragSym(aTransferArgs, count, max_xfer_len);
-		}
-
-	if (r == KErrNone)
-		{
-		iIsrCb = isr_cb;
-		}
-
-	__DMA_INVARIANT();
-	return r;
-	};
-
-
-TInt DDmaRequest::FragSym(TDmaTransferArgs& aTransferArgs, TUint aCount,
-						  TUint aMaxTransferLen)
-	{
-	TDmaTransferConfig& src = aTransferArgs.iSrcConfig;
-	TDmaTransferConfig& dst = aTransferArgs.iDstConfig;
-
-	const TBool mem_src = (src.iFlags & KDmaMemAddr);
-	const TBool mem_dst = (dst.iFlags & KDmaMemAddr);
-
-	const TUint align_mask_src = iChannel.AddressAlignMask(src.iFlags,
-														   src.iElementSize,
-														   aTransferArgs.iPslRequestInfo);
-	const TUint align_mask_dst = iChannel.AddressAlignMask(dst.iFlags,
-														   dst.iElementSize,
-														   aTransferArgs.iPslRequestInfo);
-	// Memory buffers must satisfy alignment constraint
-	__DMA_ASSERTD(!mem_src || ((src.iAddr & align_mask_src) == 0));
-	__DMA_ASSERTD(!mem_dst || ((dst.iAddr & align_mask_dst) == 0));
-
-	const TUint max_aligned_len = (aMaxTransferLen &
-								   ~(Max(align_mask_src, align_mask_dst)));
-	// Client and PSL sane?
-	__DMA_ASSERTD(max_aligned_len > 0);
-
-	FreeDesList();			   // revert any previous fragmentation attempt
-	TInt r;
-	do
-		{
-		// Allocate fragment
-		r = ExpandDesList(/*1*/);
-		if (r != KErrNone)
-			{
-			FreeDesList();
-			break;
-			}
-		// Compute fragment size
-		TUint c = Min(aMaxTransferLen, aCount);
-		if (mem_src && !(src.iFlags & KDmaPhysAddr))
-			{
-			__KTRACE_OPT(KDMA, Kern::Printf("mem_src && !(src.iFlags & KDmaPhysAddr)"));
-			// @@@ Should also take into account (src.iFlags & KDmaMemIsContiguous)!
-			c = MaxPhysSize(src.iAddr, c);
-			}
-		if (mem_dst && !(dst.iFlags & KDmaPhysAddr))
-			{
-			__KTRACE_OPT(KDMA, Kern::Printf("mem_dst && !(dst.iFlags & KDmaPhysAddr)"));
-			// @@@ Should also take into account (dst.iFlags & KDmaMemIsContiguous)!
-			c = MaxPhysSize(dst.iAddr, c);
-			}
-		if ((mem_src || mem_dst) && (c < aCount) && (c > max_aligned_len))
-			{
-			// This is not the last fragment of a transfer to/from memory.
-			// We must round down the fragment size so the next one is
-			// correctly aligned.
-			__KTRACE_OPT(KDMA, Kern::Printf("(mem_src || mem_dst) && (c < aCount) && (c > max_aligned_len)"));
-			c = max_aligned_len;
-			}
-
-		// TODO: Make sure an element or frame on neither src or dst side
-		// (which can be of different sizes) never straddles a DMA subtransfer.
-		// (This would be a fragmentation error by the PIL.)
-
-		// Set transfer count for the PSL
-		aTransferArgs.iTransferCount = c;
-		__KTRACE_OPT(KDMA, Kern::Printf("this fragm.: %d (0x%x) total remain.: %d (0x%x)",
-										c, c, aCount, aCount));
-		// Initialise fragment
-		r = iChannel.iController->InitDes(*iLastHdr, aTransferArgs);
-		if (r != KErrNone)
-			{
-			FreeDesList();
-			break;
-			}
-		// Update for next iteration
-		aCount -= c;
-		if (mem_src)
-			src.iAddr += c;
-		if (mem_dst)
-			dst.iAddr += c;
-		}
-	while (aCount > 0);
-
-	return r;
-	}
-
-
-TInt DDmaRequest::FragAsym(TDmaTransferArgs& aTransferArgs, TUint aCount,
-						   TUint aMaxTransferLen)
-	{
-	TInt r = FragAsymSrc(aTransferArgs, aCount, aMaxTransferLen);
-	if (r != KErrNone)
-		{
-		FreeSrcDesList();
-		return r;
-		}
-	r = FragAsymDst(aTransferArgs, aCount, aMaxTransferLen);
-	if (r != KErrNone)
-		{
-		FreeSrcDesList();
-		FreeDstDesList();
-		}
-	return r;
-	}
-
-
-TInt DDmaRequest::FragAsymSrc(TDmaTransferArgs& aTransferArgs, TUint aCount,
-							  TUint aMaxTransferLen)
-	{
-	TDmaTransferConfig& src = aTransferArgs.iSrcConfig;
-
-	const TBool mem_src = (src.iFlags & KDmaMemAddr);
-
-	const TUint align_mask = iChannel.AddressAlignMask(src.iFlags,
-													   src.iElementSize,
-													   aTransferArgs.iPslRequestInfo);
-	// Memory buffers must satisfy alignment constraint
-	__DMA_ASSERTD(!mem_src || ((src.iAddr & align_mask) == 0));
-
-	const TUint max_aligned_len = (aMaxTransferLen & ~align_mask);
-	__DMA_ASSERTD(max_aligned_len > 0);				  // bug in PSL if not true
-
-	FreeSrcDesList();
-	TInt r;
-	do
-		{
-		// Allocate fragment
-		r = ExpandSrcDesList(/*1*/);
-		if (r != KErrNone)
-			{
-			break;
-			}
-		// Compute fragment size
-		TUint c = Min(aMaxTransferLen, aCount);
-		if (mem_src && !(src.iFlags & KDmaPhysAddr))
-			{
-			__KTRACE_OPT(KDMA, Kern::Printf("mem_src && !(src.iFlags & KDmaPhysAddr)"));
-			c = MaxPhysSize(src.iAddr, c);
-			}
-		if (mem_src && (c < aCount) && (c > max_aligned_len))
-			{
-			// This is not the last fragment of a transfer from memory.
-			// We must round down the fragment size so the next one is
-			// correctly aligned.
-			__KTRACE_OPT(KDMA, Kern::Printf("mem_src && (c < aCount) && (c > max_aligned_len)"));
-			c = max_aligned_len;
-			}
-		// Set transfer count for the PSL
-		aTransferArgs.iTransferCount = c;
-		__KTRACE_OPT(KDMA, Kern::Printf("this fragm.: %d (0x%x) total remain.: %d (0x%x)",
-										c, c, aCount, aCount));
-		// Initialise fragment
-		r = iChannel.iController->InitSrcHwDes(*iSrcLastHdr, aTransferArgs);
-		if (r != KErrNone)
-			{
-			break;
-			}
-		// Update for next iteration
-		aCount -= c;
-		if (mem_src)
-			src.iAddr += c;
-		}
-	while (aCount > 0);
-
-	return r;
-	}
-
-
-TInt DDmaRequest::FragAsymDst(TDmaTransferArgs& aTransferArgs, TUint aCount,
-							  TUint aMaxTransferLen)
-	{
-	TDmaTransferConfig& dst = aTransferArgs.iDstConfig;
-
-	const TBool mem_dst = (dst.iFlags & KDmaMemAddr);
-
-	const TUint align_mask = iChannel.AddressAlignMask(dst.iFlags,
-													   dst.iElementSize,
-													   aTransferArgs.iPslRequestInfo);
-	// Memory buffers must satisfy alignment constraint
-	__DMA_ASSERTD(!mem_dst || ((dst.iAddr & align_mask) == 0));
-
-	const TUint max_aligned_len = (aMaxTransferLen & ~align_mask);
-	__DMA_ASSERTD(max_aligned_len > 0);				  // bug in PSL if not true
-
-	FreeDstDesList();
-	TInt r;
-	do
-		{
-		// Allocate fragment
-		r = ExpandDstDesList(/*1*/);
-		if (r != KErrNone)
-			{
-			break;
-			}
-		// Compute fragment size
-		TUint c = Min(aMaxTransferLen, aCount);
-		if (mem_dst && !(dst.iFlags & KDmaPhysAddr))
-			{
-			__KTRACE_OPT(KDMA, Kern::Printf("mem_dst && !(dst.iFlags & KDmaPhysAddr)"));
-			c = MaxPhysSize(dst.iAddr, c);
-			}
-		if (mem_dst && (c < aCount) && (c > max_aligned_len))
-			{
-			// This is not the last fragment of a transfer to memory.
-			// We must round down the fragment size so the next one is
-			// correctly aligned.
-			__KTRACE_OPT(KDMA, Kern::Printf("mem_dst && (c < aCount) && (c > max_aligned_len)"));
-			c = max_aligned_len;
-			}
-		// Set transfer count for the PSL
-		aTransferArgs.iTransferCount = c;
-		__KTRACE_OPT(KDMA, Kern::Printf("this fragm.: %d (0x%x) total remain.: %d (0x%x)",
-										c, c, aCount, aCount));
-		// Initialise fragment
-		r = iChannel.iController->InitDstHwDes(*iDstLastHdr, aTransferArgs);
-		if (r != KErrNone)
-			{
-			break;
-			}
-		// Update for next iteration
-		aCount -= c;
-		if (mem_dst)
-			dst.iAddr += c;
-		}
-	while (aCount > 0);
-
-	return r;
-	}
-
-
-EXPORT_C TInt DDmaRequest::Queue()
-	{
-	__KTRACE_OPT(KDMA, Kern::Printf("DDmaRequest::Queue thread %O", &Kern::CurrentThread()));
-	__DMA_ASSERTD(iDesCount > 0);	// Not configured? Call Fragment() first!
-	__DMA_ASSERTD(!iQueued);
-
-	// Append request to queue and link new descriptor list to existing one.
-	iChannel.Wait();
-
-	TInt r = KErrGeneral;
-	const TBool ch_isr_cb = __e32_atomic_load_acq32(&iChannel.iIsrCbRequest);
-	if (ch_isr_cb)
-		{
-		// Client mustn't try to queue any new request while one with an ISR
-		// callback is already queued on this channel. This is to make sure
-		// that the channel's Transfer() function is not called by both the ISR
-		// and the client thread at the same time.
-		__KTRACE_OPT(KPANIC, Kern::Printf("An ISR cb request exists - not queueing"));
-		}
-	else if (iIsrCb && !iChannel.IsQueueEmpty())
-		{
-		// Client mustn't try to queue an ISR callback request whilst any
-		// others are still queued on this channel. This is to make sure that
-		// the ISR callback doesn't get executed together with the DFC(s) of
-		// any previous request(s).
-		__KTRACE_OPT(KPANIC, Kern::Printf("Request queue not empty - not queueing"));
-		}
-	else if (iChannel.iIsrDfc & (TUint32)TDmaChannel::KCancelFlagMask)
-		{
-		__KTRACE_OPT(KPANIC, Kern::Printf("Channel requests cancelled - not queueing"));
-		}
-	else
-		{
-		iQueued = ETrue;
-		iChannel.iReqQ.Add(&iLink);
-		// iChannel.iNullPtr points to iChannel.iCurHdr for an empty queue
-		*iChannel.iNullPtr = iFirstHdr;
-		iChannel.iNullPtr = &(iLastHdr->iNext);
-		if (iIsrCb)
-			{
-			// Since we've made sure that there is no other request in the
-			// queue before this, the only thing of relevance is the channel
-			// DFC which might yet have to complete for the previous request,
-			// and this function might indeed have been called from there via
-			// the client callback. This should be all right though as once
-			// we've set the following flag no further Queue()'s will be
-			// possible.
-			__e32_atomic_store_rel32(&iChannel.iIsrCbRequest, ETrue);
-			}
-		iChannel.DoQueue(const_cast<const DDmaRequest&>(*this));
-		r = KErrNone;
-		}
-	iChannel.Signal();
-
-	__DMA_INVARIANT();
-	return r;
-	}
-
-
-EXPORT_C TInt DDmaRequest::ExpandDesList(TInt aCount)
-	{
-	return ExpandDesList(aCount, iDesCount, iFirstHdr, iLastHdr);
-	}
-
-
-EXPORT_C TInt DDmaRequest::ExpandSrcDesList(TInt aCount)
-	{
-	return ExpandDesList(aCount, iSrcDesCount, iSrcFirstHdr, iSrcLastHdr);
-	}
-
-
-EXPORT_C TInt DDmaRequest::ExpandDstDesList(TInt aCount)
-	{
-	return ExpandDesList(aCount, iDstDesCount, iDstFirstHdr, iDstLastHdr);
-	}
-
-
-TInt DDmaRequest::ExpandDesList(TInt aCount, TInt& aDesCount,
-								SDmaDesHdr*& aFirstHdr,
-								SDmaDesHdr*& aLastHdr)
-	{
-	__DMA_ASSERTD(!iQueued);
-	__DMA_ASSERTD(aCount > 0);
-
-	if (aCount > iChannel.iAvailDesCount)
-		{
-		return KErrTooBig;
-		}
-
-	iChannel.iAvailDesCount -= aCount;
-	aDesCount += aCount;
-
-	TDmac& c = *(iChannel.iController);
-	c.Wait();
-
-	if (aFirstHdr == NULL)
-		{
-		// Handle an empty list specially to simplify the following loop
-		aFirstHdr = aLastHdr = c.iFreeHdr;
-		c.iFreeHdr = c.iFreeHdr->iNext;
-		--aCount;
-		}
-	else
-		{
-		aLastHdr->iNext = c.iFreeHdr;
-		}
-
-	// Remove as many descriptors and headers from the free pool as necessary
-	// and ensure hardware descriptors are chained together.
-	while (aCount-- > 0)
-		{
-		__DMA_ASSERTD(c.iFreeHdr != NULL);
-		if (c.iCapsHwDes)
-			{
-			c.ChainHwDes(*aLastHdr, *(c.iFreeHdr));
-			}
-		aLastHdr = c.iFreeHdr;
-		c.iFreeHdr = c.iFreeHdr->iNext;
-		}
-
-	c.Signal();
-
-	aLastHdr->iNext = NULL;
-
-	__DMA_INVARIANT();
-	return KErrNone;
-	}
-
-
-EXPORT_C void DDmaRequest::FreeDesList()
-	{
-	FreeDesList(iDesCount, iFirstHdr, iLastHdr);
-	}
-
-
-EXPORT_C void DDmaRequest::FreeSrcDesList()
-	{
-	FreeDesList(iSrcDesCount, iSrcFirstHdr, iSrcLastHdr);
-	}
-
-
-EXPORT_C void DDmaRequest::FreeDstDesList()
-	{
-	FreeDesList(iDstDesCount, iDstFirstHdr, iDstLastHdr);
-	}
-
-
-void DDmaRequest::FreeDesList(TInt& aDesCount, SDmaDesHdr*& aFirstHdr, SDmaDesHdr*& aLastHdr)
-	{
-	__DMA_ASSERTD(!iQueued);
-
-	if (aDesCount > 0)
-		{
-		iChannel.iAvailDesCount += aDesCount;
-		TDmac& c = *(iChannel.iController);
-		const SDmaDesHdr* hdr = aFirstHdr;
-		while (hdr)
-			{
-			c.ClearHwDes(*hdr);
-			hdr = hdr->iNext;
-			};
-		c.Wait();
-		aLastHdr->iNext = c.iFreeHdr;
-		c.iFreeHdr = aFirstHdr;
-		c.Signal();
-		aFirstHdr = aLastHdr = NULL;
-		aDesCount = 0;
-		}
-	}
-
-
-EXPORT_C void DDmaRequest::EnableSrcElementCounting(TBool /*aResetElementCount*/)
-	{
-	// Not yet implemented.
-	return;
-	}
-
-
-EXPORT_C void DDmaRequest::EnableDstElementCounting(TBool /*aResetElementCount*/)
-	{
-	// Not yet implemented.
-	return;
-	}
-
-
-EXPORT_C void DDmaRequest::DisableSrcElementCounting()
-	{
-	// Not yet implemented.
-	return;
-	}
-
-
-EXPORT_C void DDmaRequest::DisableDstElementCounting()
-	{
-	// Not yet implemented.
-	return;
-	}
-
-
-EXPORT_C TUint32 DDmaRequest::TotalNumSrcElementsTransferred()
-	{
-	// Not yet implemented.
-
-	// So far largely bogus code (just to touch some symbols)...
-	iTotalNumSrcElementsTransferred = 0;
-	TDmac& c = *(iChannel.iController);
-	if (c.iCapsHwDes)
-		{
-		for (const SDmaDesHdr* pH = iFirstHdr; pH != NULL; pH = pH->iNext)
-			{
-			iTotalNumSrcElementsTransferred += c.HwDesNumDstElementsTransferred(*pH);
-			}
-		}
-	else
-		{
-		// Do something different for pseudo descriptors...
-		}
-	return iTotalNumSrcElementsTransferred;
-	}
-
-
-EXPORT_C TUint32 DDmaRequest::TotalNumDstElementsTransferred()
-	{
-	// Not yet implemented.
-	return iTotalNumDstElementsTransferred;
-	}
-
-
-EXPORT_C TInt DDmaRequest::FragmentCount()
-	{
-	return FragmentCount(iFirstHdr);
-	}
-
-
-EXPORT_C TInt DDmaRequest::SrcFragmentCount()
-	{
-	return FragmentCount(iSrcFirstHdr);
-	}
-
-
-EXPORT_C TInt DDmaRequest::DstFragmentCount()
-	{
-	return FragmentCount(iDstFirstHdr);
-	}
-
-
-TInt DDmaRequest::FragmentCount(const SDmaDesHdr* aHdr)
-	{
-	TInt count = 0;
-	for (const SDmaDesHdr* pH = aHdr; pH != NULL; pH = pH->iNext)
-		{
-		count++;
-		}
-	return count;
-	}
-
-
-//
-// Called when request is removed from request queue in channel
-//
-inline void DDmaRequest::OnDeque()
-	{
-	iQueued = EFalse;
-	iLastHdr->iNext = NULL;
-	iChannel.DoUnlink(*iLastHdr);
-	}
-
-
-#ifdef _DEBUG
-void DDmaRequest::Invariant()
-	{
-	iChannel.Wait();
-	__DMA_ASSERTD(LOGICAL_XOR(iCb, iDmaCb));
-	if (iChannel.iDmacCaps->iAsymHwDescriptors)
-		{
-		__DMA_ASSERTD((0 <= iSrcDesCount) && (iSrcDesCount <= iChannel.iMaxDesCount) &&
-					  (0 <= iDstDesCount) && (iDstDesCount <= iChannel.iMaxDesCount));
-		if (iSrcDesCount == 0)
-			{
-			__DMA_ASSERTD(iDstDesCount == 0);
-			__DMA_ASSERTD(!iQueued);
-			__DMA_ASSERTD(!iSrcFirstHdr && !iSrcLastHdr &&
-						  !iDstFirstHdr && !iDstLastHdr);
-			}
-		else
-			{
-			__DMA_ASSERTD(iChannel.iController->IsValidHdr(iSrcFirstHdr));
-			__DMA_ASSERTD(iChannel.iController->IsValidHdr(iSrcLastHdr));
-			__DMA_ASSERTD(iChannel.iController->IsValidHdr(iDstFirstHdr));
-			__DMA_ASSERTD(iChannel.iController->IsValidHdr(iDstLastHdr));
-			}
-		}
-	else
-		{
-		__DMA_ASSERTD((0 <= iDesCount) && (iDesCount <= iChannel.iMaxDesCount));
-		if (iDesCount == 0)
-			{
-			__DMA_ASSERTD(!iQueued);
-			__DMA_ASSERTD(!iFirstHdr && !iLastHdr);
-			}
-		else
-			{
-			__DMA_ASSERTD(iChannel.iController->IsValidHdr(iFirstHdr));
-			__DMA_ASSERTD(iChannel.iController->IsValidHdr(iLastHdr));
-			}
-		}
-	iChannel.Signal();
-	}
-#endif
-
-
-//////////////////////////////////////////////////////////////////////////////
-// TDmaChannel
-
-_LIT(KDmaChannelMutex, "DMA-Channel");
-
-TDmaChannel::TDmaChannel()
-	: iController(NULL),
-	  iDmacCaps(NULL),
-	  iPslId(0),
-	  iDynChannel(EFalse),
-	  iPriority(KDmaPriorityNone),
-	  iCurHdr(NULL),
-	  iNullPtr(&iCurHdr),
-	  iDfc(Dfc, NULL, 0),
-	  iMaxDesCount(0),
-	  iAvailDesCount(0),
-	  iIsrDfc(0),
-	  iReqQ(),
-	  iReqCount(0),
-	  iCancelInfo(NULL),
-	  iRedoRequest(EFalse),
-	  iIsrCbRequest(EFalse)
-	{
-	const TInt r = Kern::MutexCreate(iMutex, KDmaChannelMutex, KMutexOrdDmaChannel);
-	__DMA_ASSERTA(r == KErrNone);
-
-#ifndef __WINS__
-	// On the emulator this code is called from within the codeseg mutex.
-	// The invariant tries to hold the dma channel mutex, but this is not allowed
-	__DMA_INVARIANT();
-#endif
-	}
-
-
-TDmaChannel::~TDmaChannel()
-	{
-	Kern::SafeClose((DObject*&)iMutex, NULL);
-	}
-
-
-//
-// static member function
-//
-EXPORT_C TInt TDmaChannel::Open(const SCreateInfo& aInfo, TDmaChannel*& aChannel)
-	{
-	__KTRACE_OPT(KDMA, Kern::Printf("TDmaChannel::Open thread %O", &Kern::CurrentThread()));
-
-	__DMA_ASSERTD(aInfo.iDesCount >= 1);
-	__DMA_ASSERTD(aInfo.iPriority <= KDmaPriority8);
-	__DMA_ASSERTD(aInfo.iDfcQ != NULL);
-	__DMA_ASSERTD(aInfo.iDfcPriority < KNumDfcPriorities);
-
-	aChannel = NULL;
-
-	DmaChannelMgr::Wait();
-	TDmaChannel* pC = DmaChannelMgr::Open(aInfo.iCookie, aInfo.iDynChannel, aInfo.iPriority);
-	DmaChannelMgr::Signal();
-	if (!pC)
-		{
-		return KErrInUse;
-		}
-	__DMA_ASSERTD(pC->iController != NULL);
-	__DMA_ASSERTD(pC->iDmacCaps != NULL);
-	__DMA_ASSERTD(pC->iController->iCapsHwDes == pC->DmacCaps().iHwDescriptors);
-	// PSL needs to set iDynChannel if and only if dynamic channel was requested
-	__DMA_ASSERTD(!LOGICAL_XOR(aInfo.iDynChannel, pC->iDynChannel));
-
-	const TInt r = pC->iController->ReserveSetOfDes(aInfo.iDesCount);
-	if (r != KErrNone)
-		{
-		pC->Close();
-		return r;
-		}
-	pC->iAvailDesCount = pC->iMaxDesCount = aInfo.iDesCount;
-
-	new (&pC->iDfc) TDfc(&Dfc, pC, aInfo.iDfcQ, aInfo.iDfcPriority);
-
-	aChannel = pC;
-
-#ifdef _DEBUG
-	pC->Invariant();
-#endif
-	__KTRACE_OPT(KDMA, Kern::Printf("opened channel %d", pC->iPslId));
-	return KErrNone;
-	}
-
-
-EXPORT_C void TDmaChannel::Close()
-	{
-	__KTRACE_OPT(KDMA, Kern::Printf("TDmaChannel::Close %d iReqCount=%d", iPslId, iReqCount));
-	__DMA_ASSERTD(IsQueueEmpty());
-	__DMA_ASSERTD(iReqCount == 0);
-
-	// Descriptor leak? -> bug in request code
-	__DMA_ASSERTD(iAvailDesCount == iMaxDesCount);
-
-	__DMA_ASSERTD(!iRedoRequest);
-	__DMA_ASSERTD(!iIsrCbRequest);
-
-	iController->ReleaseSetOfDes(iMaxDesCount);
-	iAvailDesCount = iMaxDesCount = 0;
-
-	DmaChannelMgr::Wait();
-	DmaChannelMgr::Close(this);
-	// The following assignment will be removed once IsOpened() has been
-	// removed. That's because 'this' shouldn't be touched any more once
-	// Close() has returned from the PSL.
-	iController = NULL;
-	DmaChannelMgr::Signal();
-	}
-
-
-EXPORT_C TInt TDmaChannel::LinkToChannel(TDmaChannel* aChannel)
-	{
-	__KTRACE_OPT(KDMA, Kern::Printf("TDmaChannel::LinkToChannel thread %O",
-									&Kern::CurrentThread()));
-	if (aChannel)
-		{
-		return iController->LinkChannels(*this, *aChannel);
-		}
-	else
-		{
-		return iController->UnlinkChannel(*this);
-		}
-	}
-
-
-EXPORT_C TInt TDmaChannel::Pause()
-	{
-	__KTRACE_OPT(KDMA, Kern::Printf("TDmaChannel::Pause thread %O",
-									&Kern::CurrentThread()));
-	return iController->PauseTransfer(*this);
-	}
-
-
-EXPORT_C TInt TDmaChannel::Resume()
-	{
-	__KTRACE_OPT(KDMA, Kern::Printf("TDmaChannel::Resume thread %O",
-									&Kern::CurrentThread()));
-	return iController->ResumeTransfer(*this);
-	}
-
-
-EXPORT_C void TDmaChannel::CancelAll()
-	{
-	__KTRACE_OPT(KDMA, Kern::Printf("TDmaChannel::CancelAll thread %O channel - %d",
-									&Kern::CurrentThread(), iPslId));
-	NThread* const nt = NKern::CurrentThread();
-	TBool wait = EFalse;
-	TDmaCancelInfo cancelinfo;
-	TDmaCancelInfo* waiters = NULL;
-
-	NKern::ThreadEnterCS();
-	Wait();
-
-	NThreadBase* const dfc_nt = iDfc.Thread();
-	// Shouldn't be NULL (i.e. an IDFC)
-	__DMA_ASSERTD(dfc_nt);
-
-	__e32_atomic_store_ord32(&iIsrDfc, (TUint32)KCancelFlagMask);
-	// ISRs after this point will not post a DFC, however a DFC may already be
-	// queued or running or both.
-	if (!IsQueueEmpty())
-		{
-		// There is a transfer in progress. It may complete before the DMAC
-		// has stopped, but the resulting ISR will not post a DFC.
-		// ISR should not happen after this function returns.
-		iController->StopTransfer(*this);
-
-		ResetStateMachine();
-
-		// Clean-up the request queue.
-		SDblQueLink* pL;
-		while ((pL = iReqQ.GetFirst()) != NULL)
-			{
-			DDmaRequest* pR = _LOFF(pL, DDmaRequest, iLink);
-			pR->OnDeque();
-			}
-		}
-	if (dfc_nt == nt)
-		{
-		// DFC runs in this thread, so just cancel it and we're finished
-		iDfc.Cancel();
-
-		// If other calls to CancelAll() are waiting for the DFC, release them here
-		waiters = iCancelInfo;
-		iCancelInfo = NULL;
-
-		// Reset the ISR count
-		__e32_atomic_store_rel32(&iIsrDfc, 0);
-		}
-	else
-		{
-		// DFC runs in another thread. Make sure it's queued and then wait for it to run.
-		if (iCancelInfo)
-			{
-			// Insert cancelinfo into the list so that it precedes iCancelInfo
-			cancelinfo.InsertBefore(iCancelInfo);
-			}
-		else
-			{
-			iCancelInfo = &cancelinfo;
-			}
-		wait = ETrue;
-		iDfc.Enque();
-		}
-
-	Signal();
-
-	if (waiters)
-		{
-		waiters->Signal();
-		}
-	else if (wait)
-		{
-		NKern::FSWait(&cancelinfo.iSem);
-		}
-
- 	NKern::ThreadLeaveCS();
-	__DMA_INVARIANT();
-	}
-
-
-EXPORT_C TInt TDmaChannel::IsrRedoRequest(TUint32 aSrcAddr, TUint32 aDstAddr,
-										  TUint aTransferCount,
-										  TUint32 aPslRequestInfo,
-										  TBool aIsrCb)
-	{
-	__KTRACE_OPT(KDMA,
-				 Kern::Printf("TDmaChannel::IsrRedoRequest src=0x%08x, "
-							  "dst=0x%08x, count=%d, pslInfo=0x%08x, isrCb=%d",
-							  aSrcAddr, aDstAddr, aTransferCount, aPslRequestInfo,
-							  aIsrCb));
-	// Function needs to be called in ISR context.
-	__DMA_ASSERTD(NKern::CurrentContext() == NKern::EInterrupt);
-
-	__DMA_ASSERTD(!iReqQ.IsEmpty());
-	__DMA_ASSERTD(iIsrCbRequest);
-
-#ifdef _DEBUG
-	if ((aSrcAddr != KPhysAddrInvalid) && (aSrcAddr == aDstAddr))
-		{
-		__KTRACE_OPT(KPANIC,
-					 Kern::Printf("Error: Updating src & dst to same address: 0x%08x",
-								  aSrcAddr));
-		return KErrArgument;
-		}
-#endif
-
-	// We assume here that the just completed request is the first one in the
-	// queue, i.e. that even if there is more than one request in the queue,
-	// their respective last and first (hw) descriptors are *not* linked.
-	// (Although that's what apparently happens in TDmaSgChannel::DoQueue() /
-	// TDmac::AppendHwDes() @@@).
-	DDmaRequest* const pCurReq = _LOFF(iReqQ.First(), DDmaRequest, iLink);
-	TInt r;
-
-	if (iDmacCaps->iAsymHwDescriptors)
-		{
-		// We don't allow multiple-descriptor chains to be updated here
-		__DMA_ASSERTD((pCurReq->iSrcDesCount == 1) && (pCurReq->iDstDesCount == 1));
-		// Adjust parameters if necessary (asymmetrical s/g variety)
-		const SDmaDesHdr* const pSrcFirstHdr = pCurReq->iSrcFirstHdr;
-		if ((aSrcAddr != KPhysAddrInvalid) || aTransferCount || aPslRequestInfo)
-			{
-			r = iController->UpdateSrcHwDes(*pSrcFirstHdr, aSrcAddr,
-											aTransferCount, aPslRequestInfo);
-			if (r != KErrNone)
-				{
-				__KTRACE_OPT(KPANIC, Kern::Printf("Src descriptor updating failed in PSL"));
-				return r;
-				}
-			}
-		const SDmaDesHdr* const pDstFirstHdr = pCurReq->iDstFirstHdr;
-		if ((aDstAddr != KPhysAddrInvalid) || aTransferCount || aPslRequestInfo)
-			{
-			r = iController->UpdateDstHwDes(*pDstFirstHdr, aSrcAddr,
-											aTransferCount, aPslRequestInfo);
-			if (r != KErrNone)
-				{
-				__KTRACE_OPT(KPANIC, Kern::Printf("Dst descriptor updating failed in PSL"));
-				return r;
-				}
-			}
-		// Reschedule the request
-		iController->Transfer(*this, *pSrcFirstHdr, *pDstFirstHdr);
-		}
-	else
-		{
-		// We don't allow multiple-descriptor chains to be updated here
-		__DMA_ASSERTD(pCurReq->iDesCount == 1);
-		// Adjust parameters if necessary (symmetrical s/g and non-s/g variety)
-		const SDmaDesHdr* const pFirstHdr = pCurReq->iFirstHdr;
-		if ((aSrcAddr != KPhysAddrInvalid) || (aDstAddr != KPhysAddrInvalid) ||
-			aTransferCount || aPslRequestInfo)
-			{
-			r = iController->UpdateDes(*pFirstHdr, aSrcAddr, aDstAddr,
-									   aTransferCount, aPslRequestInfo);
-			if (r != KErrNone)
-				{
-				__KTRACE_OPT(KPANIC, Kern::Printf("Descriptor updating failed"));
-				return r;
-				}
-			}
-		// Reschedule the request
-		iController->Transfer(*this, *pFirstHdr);
-		}
-
-	if (!aIsrCb)
-		{
-		// Not another ISR callback please
-		pCurReq->iIsrCb = aIsrCb;
-		}
-	iRedoRequest = ETrue;
-
-	return KErrNone;
-	}
-
-
-EXPORT_C TInt TDmaChannel::FailNext(TInt /*aFragmentCount*/)
-	{
-	return iController->FailNext(*this);
-	}
-
-
-EXPORT_C TInt TDmaChannel::MissNextInterrupts(TInt aInterruptCount)
-	{
-	return iController->MissNextInterrupts(*this, aInterruptCount);
-	}
-
-
-EXPORT_C TInt TDmaChannel::Extension(TInt aCmd, TAny* aArg)
-	{
-	return iController->Extension(*this, aCmd, aArg);
-	}
-
-
-//
-// static member function
-//
-EXPORT_C TInt TDmaChannel::StaticExtension(TInt aCmd, TAny* aArg)
-	{
-	return DmaChannelMgr::StaticExtension(aCmd, aArg);
-	}
-
-
-EXPORT_C TUint TDmaChannel::MaxTransferLength(TUint aSrcFlags, TUint aDstFlags,
-											  TUint32 aPslInfo)
-	{
-	return iController->MaxTransferLength(*this, aSrcFlags, aDstFlags, aPslInfo);
-	}
-
-
-EXPORT_C TUint TDmaChannel::AddressAlignMask(TUint aTargetFlags, TUint aElementSize,
-											 TUint32 aPslInfo)
-	{
-	return iController->AddressAlignMask(*this, aTargetFlags, aElementSize, aPslInfo);
-	}
-
-
-EXPORT_C const SDmacCaps& TDmaChannel::DmacCaps()
-	{
-	return *iDmacCaps;
-	}
-
-
-//
-// DFC callback function (static member).
-//
-void TDmaChannel::Dfc(TAny* aArg)
-	{
-	static_cast<TDmaChannel*>(aArg)->DoDfc();
-	}
-
-
-//
-// This is quite a long function, but what can you do...
-//
-void TDmaChannel::DoDfc()
-	{
-	__KTRACE_OPT(KDMA, Kern::Printf("TDmaChannel::DoDfc thread %O channel - %d",
-									&Kern::CurrentThread(), iPslId));
-	Wait();
-
-	// Atomically fetch and reset the number of DFCs queued by the ISR and the
-	// error flag. Leave the cancel flag alone for now.
-	const TUint32 w = __e32_atomic_and_ord32(&iIsrDfc, (TUint32)KCancelFlagMask);
-	TUint32 count = w & KDfcCountMask;
-	const TBool error = w & (TUint32)KErrorFlagMask;
-	TBool stop = w & (TUint32)KCancelFlagMask;
-	__DMA_ASSERTD((count > 0) || stop);
-
-	__DMA_ASSERTD(!iRedoRequest); // We shouldn't be here if this is true
-
-	while (count && !stop)
-		{
-		--count;
-
-		__DMA_ASSERTD(!iReqQ.IsEmpty());
-
-		// If an error occurred it must have been reported on the last
-		// interrupt since transfers are suspended after an error.
-		DDmaRequest::TResult const res = (count == 0 && error) ?
-			DDmaRequest::EError : DDmaRequest::EOk;
-		DDmaRequest* pCompletedReq = NULL;
-		DDmaRequest* const pCurReq = _LOFF(iReqQ.First(), DDmaRequest, iLink);
-
-		if (res == DDmaRequest::EOk)
-			{
-			// Update state machine, current fragment, completed fragment and
-			// tell the DMAC to transfer the next fragment if necessary.
-			SDmaDesHdr* pCompletedHdr = NULL;
-			DoDfc(const_cast<const DDmaRequest&>(*pCurReq), pCompletedHdr);
-
-			// If just completed last fragment from current request, switch to
-			// next request (if any).
-			if (pCompletedHdr == pCurReq->iLastHdr)
-				{
-				pCompletedReq = pCurReq;
-				pCurReq->iLink.Deque();
-				if (iReqQ.IsEmpty())
-					iNullPtr = &iCurHdr;
-				pCompletedReq->OnDeque();
-				}
-			}
-		else
-			{
-			pCompletedReq = pCurReq;
-			}
-
-		if (pCompletedReq && !pCompletedReq->iIsrCb)
-			{
-			// Don't execute ISR callbacks here (they have already been called)
-			DDmaRequest::TCallback const cb = pCompletedReq->iCb;
-			if (cb)
-				{
-				// Old style callback
-				TAny* const arg = pCompletedReq->iCbArg;
-				Signal();
-				__KTRACE_OPT(KDMA, Kern::Printf("Client CB res=%d", res));
-				(*cb)(res, arg);
-				Wait();
-				}
-			else
-				{
-				// New style callback
-				TDmaCallback const ncb = pCompletedReq->iDmaCb;
-				if (ncb)
-					{
-					TAny* const arg = pCompletedReq->iDmaCbArg;
-					TDmaResult const result = (res == DDmaRequest::EOk) ?
-						EDmaResultOK : EDmaResultError;
-					Signal();
-					__KTRACE_OPT(KDMA, Kern::Printf("Client CB result=%d", result));
-					(*ncb)(EDmaCallbackRequestCompletion, result, arg, NULL);
-					Wait();
-					}
-				}
-			}
-		else
-			{
-			// Allow another thread in, in case they are trying to cancel
-			Flash();
-			}
-		stop = __e32_atomic_load_acq32(&iIsrDfc) & (TUint32)KCancelFlagMask;
-		}
-
-	if (stop)
-		{
-		// If another thread set the cancel flag, it should have
-		// cleaned up the request queue
-		__DMA_ASSERTD(IsQueueEmpty());
-
-		TDmaCancelInfo* const waiters = iCancelInfo;
-		iCancelInfo = NULL;
-
-		// make sure DFC doesn't run again until a new request completes
-		iDfc.Cancel();
-
-		// reset the ISR count - new requests can now be processed
-		__e32_atomic_store_rel32(&iIsrDfc, 0);
-
-		Signal();
-
-		// release threads doing CancelAll()
-		waiters->Signal();
-		}
-	else
-		Signal();
-
-	__DMA_INVARIANT();
-	}
-
-
-//
-// Reset state machine only, request queue is unchanged */
-//
-void TDmaChannel::ResetStateMachine()
-	{
-	DoCancelAll();
-	iCurHdr = NULL;
-	iNullPtr = &iCurHdr;
-	}
-
-
-void TDmaChannel::DoQueue(const DDmaRequest& /*aReq*/)
-	{
-	// Must be overridden
-	__DMA_CANT_HAPPEN();
-	}
-
-
-//
-// Unlink the last item of a LLI chain from the next chain.
-// Default implementation does nothing. This is overridden by scatter-gather
-// channels.
-//
-void TDmaChannel::DoUnlink(SDmaDesHdr& /*aHdr*/)
-	{
-	}
-
-
-void TDmaChannel::DoDfc(const DDmaRequest& /*aCurReq*/, SDmaDesHdr*& /*aCompletedHdr*/)
-	{
-	// To make sure this version of the function isn't called for channels for
-	// which it isn't appropriate (and which therefore don't override it) we
-	// put this check in here.
-	__DMA_CANT_HAPPEN();
-	}
-
-
-void TDmaChannel::DoDfc(const DDmaRequest& /*aCurReq*/, SDmaDesHdr*& /*aSrcCompletedHdr*/,
-						SDmaDesHdr*& /*aDstCompletedHdr*/)
-	{
-	// To make sure this version of the function isn't called for channels for
-	// which it isn't appropriate (and which therefore don't override it) we
-	// put this check in here.
-	__DMA_CANT_HAPPEN();
-	}
-
-
-#ifdef _DEBUG
-void TDmaChannel::Invariant()
-	{
-	Wait();
-
-	__DMA_ASSERTD(iReqCount >= 0);
-
-	__DMA_ASSERTD(iCurHdr == NULL || iController->IsValidHdr(iCurHdr));
-
-	// should always point to NULL pointer ending fragment queue
-	__DMA_ASSERTD(*iNullPtr == NULL);
-
-	__DMA_ASSERTD((0 <= iAvailDesCount) && (iAvailDesCount <= iMaxDesCount));
-
-	__DMA_ASSERTD(LOGICAL_XOR(iCurHdr, IsQueueEmpty()));
-	if (iCurHdr == NULL)
-		{
-		__DMA_ASSERTD(iNullPtr == &iCurHdr);
-		}
-
-	Signal();
-	}
-#endif
-
-
-//////////////////////////////////////////////////////////////////////////////
-// TDmaSbChannel
-
-void TDmaSbChannel::DoQueue(const DDmaRequest& /*aReq*/)
-	{
-	if (iState != ETransferring)
-		{
-		iController->Transfer(*this, *iCurHdr);
-		iState = ETransferring;
-		}
-	}
-
-
-void TDmaSbChannel::DoCancelAll()
-	{
-	__DMA_ASSERTD(iState == ETransferring);
-	iState = EIdle;
-	}
-
-
-void TDmaSbChannel::DoDfc(const DDmaRequest& /*aCurReq*/, SDmaDesHdr*& aCompletedHdr)
-	{
-	__DMA_ASSERTD(iState == ETransferring);
-	aCompletedHdr = iCurHdr;
-	iCurHdr = iCurHdr->iNext;
-	if (iCurHdr != NULL)
-		{
-		iController->Transfer(*this, *iCurHdr);
-		}
-	else
-		{
-		iState = EIdle;
-		}
-	}
-
-
-//////////////////////////////////////////////////////////////////////////////
-// TDmaDbChannel
-
-void TDmaDbChannel::DoQueue(const DDmaRequest& aReq)
-	{
-	switch (iState)
-		{
-	case EIdle:
-		iController->Transfer(*this, *iCurHdr);
-		if (iCurHdr->iNext)
-			{
-			iController->Transfer(*this, *(iCurHdr->iNext));
-			iState = ETransferring;
-			}
-		else
-			iState = ETransferringLast;
-		break;
-	case ETransferring:
-		// nothing to do
-		break;
-	case ETransferringLast:
-		iController->Transfer(*this, *(aReq.iFirstHdr));
-		iState = ETransferring;
-		break;
-	default:
-		__DMA_CANT_HAPPEN();
-		}
-	}
-
-
-void TDmaDbChannel::DoCancelAll()
-	{
-	iState = EIdle;
-	}
-
-
-void TDmaDbChannel::DoDfc(const DDmaRequest& /*aCurReq*/, SDmaDesHdr*& aCompletedHdr)
-	{
-	aCompletedHdr = iCurHdr;
-	iCurHdr = iCurHdr->iNext;
-	switch (iState)
-		{
-	case ETransferringLast:
-		iState = EIdle;
-		break;
-	case ETransferring:
-		if (iCurHdr->iNext == NULL)
-			iState = ETransferringLast;
-		else
-			iController->Transfer(*this, *(iCurHdr->iNext));
-		break;
-	default:
-		__DMA_CANT_HAPPEN();
-		}
-	}
-
-
-//////////////////////////////////////////////////////////////////////////////
-// TDmaSgChannel
-
-void TDmaSgChannel::DoQueue(const DDmaRequest& aReq)
-	{
-	if (iState == ETransferring)
-		{
-		__DMA_ASSERTD(!aReq.iLink.Alone());
-		DDmaRequest* pReqPrev = _LOFF(aReq.iLink.iPrev, DDmaRequest, iLink);
-		iController->AppendHwDes(*this, *(pReqPrev->iLastHdr), *(aReq.iFirstHdr));
-		}
-	else
-		{
-		iController->Transfer(*this, *(aReq.iFirstHdr));
-		iState = ETransferring;
-		}
-	}
-
-
-void TDmaSgChannel::DoCancelAll()
-	{
-	__DMA_ASSERTD(iState == ETransferring);
-	iState = EIdle;
-	}
-
-
-void TDmaSgChannel::DoUnlink(SDmaDesHdr& aHdr)
-	{
-	iController->UnlinkHwDes(*this, aHdr);
-	}
-
-
-void TDmaSgChannel::DoDfc(const DDmaRequest& aCurReq, SDmaDesHdr*& aCompletedHdr)
-	{
-	__DMA_ASSERTD(iState == ETransferring);
-	aCompletedHdr = aCurReq.iLastHdr;
-	iCurHdr = aCompletedHdr->iNext;
-	iState = (iCurHdr != NULL) ? ETransferring : EIdle;
-	}
-
-
-//////////////////////////////////////////////////////////////////////////////
-// TDmaAsymSgChannel
-
-void TDmaAsymSgChannel::DoQueue(const DDmaRequest& aReq)
-	{
-	if (iState == ETransferring)
-		{
-		__DMA_ASSERTD(!aReq.iLink.Alone());
-		DDmaRequest* pReqPrev = _LOFF(aReq.iLink.iPrev, DDmaRequest, iLink);
-		iController->AppendHwDes(*this,
-								 *(pReqPrev->iSrcLastHdr), *(aReq.iSrcFirstHdr),
-								 *(pReqPrev->iDstLastHdr), *(aReq.iDstFirstHdr));
-		}
-	else
-		{
-		iController->Transfer(*this, *(aReq.iSrcFirstHdr), *(aReq.iDstFirstHdr));
-		iState = ETransferring;
-		}
-	}
-
-
-void TDmaAsymSgChannel::DoCancelAll()
-	{
-	__DMA_ASSERTD(iState == ETransferring);
-	iState = EIdle;
-	}
-
-
-void TDmaAsymSgChannel::DoUnlink(SDmaDesHdr& aHdr)
-	{
-	iController->UnlinkHwDes(*this, aHdr);
-	}
-
-
-void TDmaAsymSgChannel::DoDfc(const DDmaRequest& aCurReq, SDmaDesHdr*& aSrcCompletedHdr,
-							  SDmaDesHdr*& aDstCompletedHdr)
-	{
-	__DMA_ASSERTD(iState == ETransferring);
-	aSrcCompletedHdr = aCurReq.iSrcLastHdr;
-	iSrcCurHdr = aSrcCompletedHdr->iNext;
-	aDstCompletedHdr = aCurReq.iDstLastHdr;
-	iDstCurHdr = aDstCompletedHdr->iNext;
-	// Must be either both NULL or none of them.
-	__DMA_ASSERTD(!LOGICAL_XOR(iSrcCurHdr, iDstCurHdr));
-	iState = (iSrcCurHdr != NULL) ? ETransferring : EIdle;
-	}
-
--- a/kernel/eka/drivers/dma/dma2_shared.cpp	Tue May 11 17:28:22 2010 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,210 +0,0 @@
-// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
-// All rights reserved.
-// This component and the accompanying materials are made available
-// under the terms of "Eclipse Public License v1.0"
-// which accompanies this distribution, and is available
-// at the URL "http://www.eclipse.org/legal/epl-v10.html".
-//
-// Initial Contributors:
-// Nokia Corporation - initial contribution.
-//
-// Contributors:
-//
-// Description:
-// e32/drivers/dma2_shared.cpp
-// DMA Platform Independent Layer (PIL)
-//
-//
-
-#include <drivers/dmadefs.h>
-
-
-//
-// Exported default constructor.
-//
-#ifdef DMA_APIV2
-KEXPORT_C
-#endif
-TDmaTransferConfig::TDmaTransferConfig()
-	: iAddr(0),
-	  iAddrMode(KDmaAddrModeConstant),
-	  iElementSize(0),
-	  iElementsPerFrame(0),
-	  iElementsPerPacket(0),
-	  iFramesPerTransfer(0),
-	  iElementSkip(0),
-	  iFrameSkip(0),
-	  iBurstSize(KDmaBurstSizeAny),
-	  iFlags(0),
-	  iSyncFlags(KDmaSyncAuto),
-	  iPslTargetInfo(0),
-	  iRepeatCount(0),
-	  iDelta(~0u),
-	  iReserved(0)
-	{
-	}
-
-
-//
-// General use version.
-//
-#ifdef DMA_APIV2
-KEXPORT_C
-#endif
-TDmaTransferConfig::TDmaTransferConfig(
-	TUint32 aAddr,
-	TUint aTransferFlags,
-	TDmaAddrMode aAddrMode,
-	TUint aSyncFlags,
-	TDmaBurstSize aBurstSize,
-	TUint aElementSize,
-	TUint aElementsPerPacket,
-	TUint aPslTargetInfo,
-	TInt aRepeatCount
-	)
-	:
-	iAddr(aAddr),
-	iAddrMode(aAddrMode),
-	iElementSize(aElementSize),
-	iElementsPerFrame(0),
-	iElementsPerPacket(aElementsPerPacket),
-	iFramesPerTransfer(0),
-	iElementSkip(0),
-	iFrameSkip(0),
-	iBurstSize(aBurstSize),
-	iFlags(aTransferFlags),
-	iSyncFlags(aSyncFlags),
-	iPslTargetInfo(aPslTargetInfo),
-	iRepeatCount(aRepeatCount),
-	iDelta(~0u),
-	iReserved(0)
-	{
-	}
-
-
-//
-// 1D/2D version.
-//
-#ifdef DMA_APIV2
-KEXPORT_C
-#endif
-TDmaTransferConfig::TDmaTransferConfig(
-	TUint32 aAddr,
-	TUint aElementSize,
-	TUint aElementsPerFrame,
-	TUint aFramesPerTransfer,
-	TInt aElementSkip,
-	TInt aFrameSkip,
-	TUint aTransferFlags,
-	TUint aSyncFlags,
-	TDmaBurstSize aBurstSize,
-	TUint aElementsPerPacket,
-	TUint aPslTargetInfo,
-	TInt aRepeatCount
-	)
-	:
-	iAddr(aAddr),
-	iAddrMode( // deduce transfer mode from skips
-		(aFrameSkip != 0) ? KDmaAddrMode2DIndex :
-		(aElementSkip != 0)? KDmaAddrMode1DIndex :
-		KDmaAddrModePostIncrement),
-	iElementSize(aElementSize),
-	iElementsPerFrame(aElementsPerFrame),
-	iElementsPerPacket(aElementsPerPacket),
-	iFramesPerTransfer(aFramesPerTransfer),
-	iElementSkip(aElementSkip),
-	iFrameSkip(aFrameSkip),
-	iBurstSize(aBurstSize),
-	iFlags(aTransferFlags),
-	iSyncFlags(aSyncFlags),
-	iPslTargetInfo(aPslTargetInfo),
-	iRepeatCount(aRepeatCount),
-	iDelta(~0u),
-	iReserved(0)
-	{
-	}
-
-
-//
-// Exported default constructor.
-//
-#ifdef DMA_APIV2
-KEXPORT_C
-#endif
-TDmaTransferArgs::TDmaTransferArgs()
-	: iTransferCount(0),
-	  iGraphicsOps(KDmaGraphicsOpNone),
-	  iFlags(0),
-	  iChannelPriority(KDmaPriorityNone),
-	  iPslRequestInfo(0),
-	  iDelta(~0u),
-	  iReserved1(0),
-	  iChannelCookie(0),
-	  iReserved2(0)
-	{
-	}
-
-
-//
-// .
-//
-#ifdef DMA_APIV2
-KEXPORT_C
-#endif
-TDmaTransferArgs::TDmaTransferArgs (
-	TUint aSrcAddr,
-	TUint aDstAddr,
-	TUint aCount,
-	TUint aDmaTransferFlags,
-	TUint aDmaSyncFlags,
-	TUint aDmaPILFlags,
-	TDmaAddrMode aMode,
-	TUint aElementSize,
-	TUint aChannelPriority,
-	TDmaBurstSize aBurstSize,
-	TUint aPslRequestInfo,
-	TDmaGraphicsOps aGraphicOp,
-	TUint32 aColour
-	)
-	:
-	iSrcConfig(aSrcAddr, aDmaTransferFlags, aMode, aDmaSyncFlags, aBurstSize, aElementSize),
-	iDstConfig(aDstAddr, aDmaTransferFlags, aMode, aDmaSyncFlags, aBurstSize, aElementSize),
-	iTransferCount(aCount),
-	iGraphicsOps(aGraphicOp),
-	iColour(aColour),
-	iFlags(aDmaPILFlags),
-	iChannelPriority(aChannelPriority),
-	iPslRequestInfo(aPslRequestInfo)
-	{
-	}
-
-
-//
-// .
-//
-#ifdef DMA_APIV2
-KEXPORT_C
-#endif
-TDmaTransferArgs::TDmaTransferArgs(
-	const TDmaTransferConfig& aSrc,
-	const TDmaTransferConfig& aDst,
-	TUint32 aFlags,
-	TUint aChannelPriority,
-	TUint aPslRequestInfo,
-	TDmaGraphicsOps aGraphicOp,
-	TUint32 aColour
-	)
-	: iSrcConfig(aSrc),
-	  iDstConfig(aDst),
-	  iTransferCount(0),
-	  iGraphicsOps(aGraphicOp),
-	  iColour(aColour),
-	  iFlags(aFlags),
-	  iChannelPriority(aChannelPriority),
-	  iPslRequestInfo(aPslRequestInfo),
-	  iDelta(~0u),
-	  iReserved1(0),
-	  iChannelCookie(0),
-	  iReserved2(0)
-	{
-	}
--- a/kernel/eka/drivers/locmedia/dmasupport.cpp	Tue May 11 17:28:22 2010 +0300
+++ b/kernel/eka/drivers/locmedia/dmasupport.cpp	Tue May 25 14:09:55 2010 +0300
@@ -743,43 +743,79 @@
 	{
 	OstTraceFunctionEntry0( DDMAHELPER_GETPHYSICALADDRESS_ENTRY );
 	__ASSERT_DEBUG( (aReq.Flags() & TLocDrvRequest::ETClientBuffer) == 0,  PHYSADDR_FAULT());
-	TLinAddr linAddr = (TLinAddr) aReq.RemoteDes();
-	TInt& offset = aReq.RemoteDesOffset();
-	TLinAddr currLinAddr = linAddr + offset;
-	TInt reqLen = I64LOW(aReq.Length());
-	__ASSERT_DEBUG(I64HIGH(aReq.Length()) == 0,  PHYSADDR_FAULT());
-
-	aAddr = Epoc::LinearToPhysical(currLinAddr);
 
-	// Set the initial length to be the length remaining in this page or the request length (whichever is shorter).
-	// If there are subsequent pages, we then need to determine whether they are contiguous
-	aLen = Min( (TInt) (PageAlign(currLinAddr+iPageSize) - currLinAddr), reqLen - offset);
+	TInt reqLen = I64LOW(aReq.Length());
+    __ASSERT_DEBUG(I64HIGH(aReq.Length()) == 0,  PHYSADDR_FAULT());
+    
+    TInt& offset = aReq.RemoteDesOffset();    
+	if (aReq.Flags() & TLocDrvRequest::EPhysAddrOnly)
+        {        
+        __KTRACE_DMA(Kern::Printf("-Physical Address Only"));
+        __ASSERT_DEBUG(IsPageAligned((TLinAddr)reqLen), PHYSADDR_FAULT());
+        
+        TPhysAddr* physArray = (TPhysAddr*)aReq.RemoteDes();        
+        
+        // Adjust start to the next element to be issued                 
+        TUint pageNo = offset>>iPageSizeLog2;
+        TPhysAddr currPhysPageAddr = aAddr = physArray[pageNo];
+        __ASSERT_DEBUG(IsPageAligned((TLinAddr)currPhysPageAddr), PHYSADDR_FAULT());
+        offset+=iPageSize; 
+        aLen=iPageSize;
 
-	__ASSERT_DEBUG(aLen > 0,  PHYSADDR_FAULT());
-	
-	TPhysAddr currPhysPageAddr = PageAlign((TLinAddr) aAddr);
-
-	offset+= aLen;
-
+        //Determine how many pages are contiguous
+        TPhysAddr nextPhysPageAddr;        
+        while (offset < reqLen)
+            {
+            pageNo++;
+            nextPhysPageAddr = physArray[pageNo];            
+            __ASSERT_DEBUG(PageOffset((TLinAddr) nextPhysPageAddr) == 0,  PHYSADDR_FAULT());
 
-	while (offset < reqLen)
-		{
-		TPhysAddr nextPhysPageAddr = Epoc::LinearToPhysical(linAddr + offset);
-		__ASSERT_DEBUG(PageOffset((TLinAddr) nextPhysPageAddr) == 0,  PHYSADDR_FAULT());
+            if (nextPhysPageAddr != currPhysPageAddr + iPageSize)
+                break;
+            
+            currPhysPageAddr = nextPhysPageAddr;            
+            offset+= iPageSize;
+            aLen+= iPageSize;
+            }
+        
+        __KTRACE_DMA(Kern::Printf(">PHYSADDR:DP:GetPhysS(PhysAddrOnly), physAddr %08X, len %x reqLen %x", aAddr, aLen, reqLen));
+        }
+	else
+	    {	
+        TLinAddr linAddr = (TLinAddr) aReq.RemoteDes();
+        TLinAddr currLinAddr = linAddr + offset;	
+    
+        aAddr = Epoc::LinearToPhysical(currLinAddr);
+    
+        // Set the initial length to be the length remaining in this page or the request length (whichever is shorter).
+        // If there are subsequent pages, we then need to determine whether they are contiguous
+        aLen = Min( (TInt) (PageAlign(currLinAddr+iPageSize) - currLinAddr), reqLen - offset);
+    
+        __ASSERT_DEBUG(aLen > 0,  PHYSADDR_FAULT());
+        
+        TPhysAddr currPhysPageAddr = PageAlign((TLinAddr) aAddr);
+    
+        offset+= aLen;
+    
+        while (offset < reqLen)
+            {
+            TPhysAddr nextPhysPageAddr = Epoc::LinearToPhysical(linAddr + offset);
+            __ASSERT_DEBUG(PageOffset((TLinAddr) nextPhysPageAddr) == 0,  PHYSADDR_FAULT());
+    
+            if (nextPhysPageAddr != currPhysPageAddr + iPageSize)
+                break;
+            
+            currPhysPageAddr = nextPhysPageAddr;
+    
+            TInt len = Min(iPageSize, reqLen - offset);
+            offset+= len;
+            aLen+= len;
+            }
 
-		if (nextPhysPageAddr != currPhysPageAddr + iPageSize)
-			break;
-		
-		currPhysPageAddr = nextPhysPageAddr;
-
-		TInt len = Min(iPageSize, reqLen - offset);
-		offset+= len;
-		aLen+= len;
-		}
-
-
-	__KTRACE_DMA(Kern::Printf(">PHYSADDR:DP:GetPhysS(), linAddr %08X, physAddr %08X, len %x reqLen %x", linAddr + offset, aAddr, aLen, reqLen));
-	OstTraceExt4(TRACE_DEMANDPAGING, DDMAHELPER_GETPHYSICALADDRESS_DP, "linAddr=0x%x; physAddr=0x%x; length=0x%x; reqLen=0x%x", linAddr + offset, aAddr, aLen, reqLen);
+        __KTRACE_DMA(Kern::Printf(">PHYSADDR:DP:GetPhysS(), linAddr %08X, physAddr %08X, len %x reqLen %x", linAddr + offset, aAddr, aLen, reqLen));
+        OstTraceExt4(TRACE_DEMANDPAGING, DDMAHELPER_GETPHYSICALADDRESS_DP, "linAddr=0x%x; physAddr=0x%x; length=0x%x; reqLen=0x%x", linAddr + offset, aAddr, aLen, reqLen);
+	    }
+	
 	OstTraceFunctionExit0( DDMAHELPER_GETPHYSICALADDRESS_EXIT );
 	return KErrNone;
 	}
--- a/kernel/eka/drivers/locmedia/locmedia.cpp	Tue May 11 17:28:22 2010 +0300
+++ b/kernel/eka/drivers/locmedia/locmedia.cpp	Tue May 25 14:09:55 2010 +0300
@@ -76,6 +76,7 @@
 #ifdef __DEMAND_PAGING__
 	DMediaPagingDevice* iPagingDevice;
 	TInt iPageSizeMsk;			// Mask of page size (e.g. 4096-1 -> 4095)
+	TInt iPageSizeLog2;        // LOG2 of page size (i.e. 4096 -> 12)
 	TInt iMediaChanges;
 #endif
 	};
@@ -259,7 +260,6 @@
 
 #endif	// __DEMAND_PAGING__
 
-
 /********************************************
  * Local drive device base class
  ********************************************/
@@ -1377,6 +1377,10 @@
 	RemoteDes()=(TAny*)d.iPtr;
 	RemoteDesOffset()=d.iOffset;
 	DriverFlags()=d.iFlags;
+	
+	// EPhysAddrOnly should not be set for client requests
+	Flags() &= ~TLocDrvRequest::EPhysAddrOnly;
+	
 	if (Pos()<0 || Length()<0)
 	    {
 		OstTraceFunctionExitExt( TLOCDRVREQUEST_PROCESSMESSAGEDATA_EXIT2, this, KErrArgument );
@@ -1640,6 +1644,7 @@
 #ifdef __DEMAND_PAGING__
 	TInt pageSize = Kern::RoundToPageSize(1);
 	iBody->iPageSizeMsk = pageSize-1;
+	iBody->iPageSizeLog2 = __e32_find_ms1_32(pageSize);
 #endif
 
 	iLastMediaId=aLastMediaId;
@@ -3615,19 +3620,15 @@
 void DPrimaryMediaBase::RequestCountInc()
 	{
 	__ASSERT_DEBUG(iBody, LOCM_FAULT());
-	if (iBody->iPagingDevice)
+	TInt oldVal = (TInt) __e32_atomic_add_ord32(&iBody->iRequestCount, (TUint) 1);
+//Kern::Printf("RCINC: this %x cnt %d, old %d", this, iBody->iRequestCount, oldVal);
+	
+	OstTraceDefExt2( OST_TRACE_CATEGORY_RND, TRACE_DEMANDPAGING, DPRIMARYMEDIABASE_REQUESTCOUNTINC, "new count=%d; old count=%d", iBody->iRequestCount, oldVal );
+	
+	if (oldVal == 0 && iBody->iPagingDevice)
 		{
-		NFastMutex* lock = iBody->iPagingDevice->NotificationLock();
-		NKern::FMWait(lock);
-		TInt oldVal = iBody->iRequestCount++;
-		//Kern::Printf("RCINC: this %x cnt %d, old %d", this, iBody->iRequestCount, oldVal);
-		OstTraceDefExt2( OST_TRACE_CATEGORY_RND, TRACE_DEMANDPAGING, DPRIMARYMEDIABASE_REQUESTCOUNTINC, "new count=%d; old count=%d", iBody->iRequestCount, oldVal );
-		if (oldVal == 0)
-			{
-			//Kern::Printf("RCINC: NotifyBusy()");
-			iBody->iPagingDevice->NotifyBusy();
-			}
-		NKern::FMSignal(lock);
+//Kern::Printf("RCINC: NotifyBusy()");
+		iBody->iPagingDevice->NotifyBusy();
 		}
 	}
 
@@ -3639,21 +3640,17 @@
 void DPrimaryMediaBase::RequestCountDec()
 	{
 	__ASSERT_DEBUG(iBody, LOCM_FAULT());
-	if (iBody->iPagingDevice)
+	TInt oldVal = (TInt) __e32_atomic_add_ord32(&iBody->iRequestCount, (TUint) -1);
+//Kern::Printf("RCDEC: this %x cnt %d, old %d", this, iBody->iRequestCount, oldVal);
+	
+	OstTraceDefExt2( OST_TRACE_CATEGORY_RND, TRACE_DEMANDPAGING, DPRIMARYMEDIABASE_REQUESTCOUNTDEC, "new count=%d; old count=%d", iBody->iRequestCount, oldVal );
+	
+	if (oldVal == 1 && iBody->iPagingDevice)
 		{
-		NFastMutex* lock = iBody->iPagingDevice->NotificationLock();
-		NKern::FMWait(lock);
-		TInt oldVal = iBody->iRequestCount--;
-		//Kern::Printf("RCDEC: this %x cnt %d, old %d", this, iBody->iRequestCount, oldVal);
-		OstTraceDefExt2( OST_TRACE_CATEGORY_RND, TRACE_DEMANDPAGING, DPRIMARYMEDIABASE_REQUESTCOUNTDEC, "new count=%d; old count=%d", iBody->iRequestCount, oldVal );
-		if (oldVal == 1)
-			{
-			//Kern::Printf("RCDEC: NotifyIdle()");
-			iBody->iPagingDevice->NotifyIdle();
-			}		
-		NKern::FMSignal(lock);
-		__ASSERT_DEBUG(iBody->iRequestCount >= 0, LOCM_FAULT());
+//Kern::Printf("RCDEC: NotifyIdle()");
+		iBody->iPagingDevice->NotifyIdle();
 		}
+	__ASSERT_DEBUG(iBody->iRequestCount >= 0, LOCM_FAULT());
 	}
 #endif	// __DEMAND_PAGING__
 
@@ -3776,19 +3773,23 @@
 	TInt len = I64LOW(m.Length());
 
 	TBool needSyncAfterRead = EFalse;
-	if (m.Drive()->iDmaHelper)
-		{
-		m.Flags() |= TLocDrvRequest::EPhysAddr;
-		if (m.Id() == DLocalDrive::EWrite)
-			{
-			Cache::SyncMemoryBeforeDmaWrite(addr, len);
-			}
-		else
-			{
-			Cache::SyncMemoryBeforeDmaRead(addr, len);
-			needSyncAfterRead = ETrue;
-			}
-		}
+    if (m.Drive()->iDmaHelper)
+        {        
+        m.Flags() |= TLocDrvRequest::EPhysAddr;
+        // don't cache sync for zero mapping...
+        if (!(m.Flags() & TLocDrvRequest::EPhysAddrOnly))
+            {
+            if (m.Id() == DLocalDrive::EWrite)
+                {
+                Cache::SyncMemoryBeforeDmaWrite(addr, len);
+                }
+            else
+                {
+                Cache::SyncMemoryBeforeDmaRead(addr, len);
+                needSyncAfterRead = ETrue;
+                }
+            }
+	    }
 
 	// Count the number of outstanding requests if this is the data-paging media, so that
 	// we can call DPagingDevice::NotifyBusy() / DPagingDevice::NotifyIdle()
@@ -3845,6 +3846,17 @@
 	}
 
 TInt DMediaPagingDevice::Read(TThreadMessage* aReq,TLinAddr aBuffer,TUint aOffset,TUint aSize,TInt aDrvNumber)
+    {
+    return BaseRead(aReq,(TUint32)aBuffer,aOffset,aSize,aDrvNumber,EFalse);
+    }
+
+TInt DMediaPagingDevice::ReadPhysical(TThreadMessage* aReq, TPhysAddr* aPageArray, TUint aPageCount, TUint aOffset, TInt aDrvNumber)
+    {    
+    TUint adjSize = (aPageCount << iPrimaryMedia->iBody->iPageSizeLog2) >> iReadUnitShift; // translate to Read Units
+    return BaseRead(aReq,(TUint32)aPageArray,aOffset,adjSize,aDrvNumber,ETrue);
+    }
+
+TInt DMediaPagingDevice::BaseRead(TThreadMessage* aReq,TUint32 aBuffer,TUint aOffset,TUint aSize,TInt aDrvNumber, TBool aPhysAddr)
 	{
 	OstTraceFunctionEntry1( DMEDIAPAGINGDEVICE_READ_ENTRY, this );
 	__ASSERT_ALWAYS(NKern::CurrentThread()!=iPrimaryMedia->iDfcQ->iThread,LOCM_FAULT());	// that would lock up the system, thus better die now
@@ -3993,7 +4005,10 @@
 		m.Length()=Int64(size);
 		m.RemoteDes()=(TAny*)aBuffer;
 		m.RemoteDesOffset()=0;		// pre-aligned
-		m.DriverFlags()=0;
+		m.DriverFlags() = 0;
+		if (aPhysAddr)
+		    m.Flags() |= TLocDrvRequest::EPhysAddrOnly;
+
 		__KTRACE_OPT2(KLOCDRV,KLOCDPAGING,Kern::Printf("ReqId=%d, Pos=0x%lx, Len=0x%lx, remote Des 0x%x",m.Id(),m.Pos(),m.Length(),m.RemoteDes()));
 		OstTraceDefExt4(OST_TRACE_CATEGORY_RND, TRACE_DEMANDPAGING, DMEDIAPAGINGDEVICE_READ2, "reqId=%d; position=0x%lx; length=0x%x; remote Des=0x%x", (TInt) m.Id(), (TUint) m.Pos(), (TUint) m.Length(), (TUint) m.RemoteDes());
 		
@@ -4041,7 +4056,18 @@
 	}
 
 TInt DMediaPagingDevice::Write(TThreadMessage* aReq,TLinAddr aBuffer,TUint aOffset,TUint aSize,TBool aBackground)
+    {
+    return BaseWrite(aReq,(TUint32)aBuffer,aOffset,aSize,aBackground,EFalse);
+    }
+
+TInt DMediaPagingDevice::WritePhysical(TThreadMessage* aReq, TPhysAddr* aPageArray, TUint aPageCount, TUint aOffset, TBool aBackground)
 	{
+    TUint adjSize = (aPageCount << iPrimaryMedia->iBody->iPageSizeLog2) >> iReadUnitShift; // translate to Read Units
+    return BaseWrite(aReq,(TUint32)aPageArray,aOffset,adjSize,aBackground,ETrue);
+	}
+
+TInt DMediaPagingDevice::BaseWrite(TThreadMessage* aReq,TUint32 aBuffer,TUint aOffset,TUint aSize,TBool aBackground, TBool aPhysAddr)
+    {
 	OstTraceFunctionEntry1( DMEDIAPAGINGDEVICE_WRITE_ENTRY, this );
 	__ASSERT_ALWAYS(NKern::CurrentThread()!=iPrimaryMedia->iDfcQ->iThread,LOCM_FAULT());	// that would lock up the system, thus better die now
 	__ASSERT_ALWAYS(aReq,LOCM_FAULT());
@@ -4101,7 +4127,10 @@
 	TInt retVal = KErrGeneral;
 	for (TInt i=0; retVal != KErrNone && i < KPageOutRetries; i++)
 		{
-		m.Flags() = TLocDrvRequest::EPaging | TLocDrvRequest::EDataPaging | (aBackground ? TLocDrvRequest::EBackgroundPaging : 0);
+		m.Flags() = TLocDrvRequest::EPaging | 
+                    TLocDrvRequest::EDataPaging | 
+                    (aBackground ? TLocDrvRequest::EBackgroundPaging : 0) |
+                    (aPhysAddr ? TLocDrvRequest::EPhysAddrOnly : 0);
 
 		m.Id() = DLocalDrive::EWrite;
 		m.Drive() = TheDrives[iDataPagingDriveNumber];
@@ -4111,7 +4140,8 @@
 		m.Length()=Int64(size);
 		m.RemoteDes()=(TAny*)aBuffer;
 		m.RemoteDesOffset()=0;		// pre-aligned
-		m.DriverFlags()=0;
+		m.DriverFlags() = 0;        
+
 		__KTRACE_OPT2(KLOCDRV,KLOCDPAGING,Kern::Printf("ReqId=%d, Pos=0x%lx, Len=0x%lx, remote Des 0x%x",m.Id(),m.Pos(),m.Length(),m.RemoteDes()));
 		OstTraceDefExt4(OST_TRACE_CATEGORY_RND, TRACE_DEMANDPAGING, DMEDIAPAGINGDEVICE_WRITE2, "reqId=%d; position=0x%lx; length=0x%lx; remote Des=0x%x", (TInt) m.Id(), (TUint) m.Pos(), (TUint) m.Length(), (TUint) m.RemoteDes());
 		
@@ -4820,8 +4850,6 @@
 		return KErrArgument;
 		}
 
-
-
 	for(i=0; i<KMaxLocalDrives; i++)
 		{
 		if (ThePagingDevices[i] == NULL)
@@ -4899,6 +4927,8 @@
 
 	TInt dataPagingDriveNumber = KErrNotFound;
 	TInt swapSize = 0;
+	TInt blockSize = 0;
+	TUint16 flags = 0;
 
 	// find the local drive assocated with the primary media
 	for (i=0; i<KMaxLocalDrives; ++i)
@@ -4929,9 +4959,10 @@
 
 
 		TLocDrvRequest m;
+        TBuf8<KMaxLocalDriveCapsLength> capsBuf;
+        
 		memclr(&m, sizeof(m));
 		
-
 		// Get the Caps from the device. NB for MMC/SD we may need to retry as some PSLs start up
 		// in "door open" or "media not present" state which can result in the cancellation of requests
 		TInt i;
@@ -4939,7 +4970,6 @@
 		TInt r = KErrNotReady;
 		for (i=0; r == KErrNotReady && i < KRetries; i++)
 			{
-			TBuf8<KMaxLocalDriveCapsLength> capsBuf;
 			capsBuf.SetMax();
 			capsBuf.FillZ();
 			m.Drive() = TheDrives[firstLocalDriveNumber];
@@ -4961,6 +4991,9 @@
 			return KErrNotSupported;
 		    }
 
+		TLocalDriveCapsV6& caps = *(TLocalDriveCapsV6*)capsBuf.Ptr();
+		blockSize = caps.iBlockSize;
+		
 		TLocDrv* drive;
 		for (i=0; i<KMaxLocalDrives; ++i)
 			{
@@ -4982,6 +5015,10 @@
 					OstTraceDefExt2( OST_TRACE_CATEGORY_RND, TRACE_DEMANDPAGING, LOCDRV_REGISTERPAGINGDEVICE6, "Found SWAP partition on local drive=%d; size=0x%x", (TInt) i, (TUint) I64LOW(drive->iPartitionLen) );			
 					dataPagingDriveNumber = i;
 					swapSize = drive->iPartitionLen >> aReadShift;
+					
+			        // Mark Paging Device capable of utilising physical addresss only accesses
+			        if (drive->iDmaHelper)
+			            flags |= DPagingDevice::ESupportsPhysicalAccess;  
 					}
 				}
 			}
@@ -5006,6 +5043,7 @@
 		}
 
 	pagingDevice->iType = aPagingType;
+	pagingDevice->iFlags = flags;
 	pagingDevice->iReadUnitShift = aReadShift;
 
 	pagingDevice->iFirstLocalDriveNumber = firstLocalDriveNumber;
@@ -5013,15 +5051,19 @@
 
 	pagingDevice->iDataPagingDriveNumber = dataPagingDriveNumber;
 	pagingDevice->iSwapSize = swapSize;
+		
+	pagingDevice->iPreferredWriteShift = (blockSize) ? __e32_find_ms1_32(blockSize) : 0;
 
 #ifdef __DEBUG_DEMAND_PAGING__
 	Kern::Printf("PagingDevice :");
 	Kern::Printf("iType 0x%x\n", pagingDevice->iType);
+	Kern::Printf("iFlags 0x%x\n", pagingDevice->iFlags);
 	Kern::Printf("iReadUnitShift 0x%x\n", pagingDevice->iReadUnitShift);
 	Kern::Printf("iFirstLocalDriveNumber 0x%x\n", pagingDevice->iFirstLocalDriveNumber);
 	Kern::Printf("iRomPagingDriveNumber 0x%x\n", pagingDevice->iRomPagingDriveNumber);
 	Kern::Printf("iDataPagingDriveNumber 0x%x\n", pagingDevice->iDataPagingDriveNumber);
 	Kern::Printf("iSwapSize 0x%x\n", pagingDevice->iSwapSize);
+	Kern::Printf("iPreferredWriteShift 0x%x\n", pagingDevice->iPreferredWriteShift);
 #endif
 
 
--- a/kernel/eka/drivers/medmmc/medmmc.cpp	Tue May 11 17:28:22 2010 +0300
+++ b/kernel/eka/drivers/medmmc/medmmc.cpp	Tue May 25 14:09:55 2010 +0300
@@ -1494,7 +1494,8 @@
 					}
 				}
 			}
-	
+
+#ifdef _ENABLE_EMMC_RELIABLE_WRITE_		
 			//Reliable Write only supported by v4.3+ MMC media
 			if (iCard->ExtendedCSD().ExtendedCSDRev() >= 3)
 				{
@@ -1506,6 +1507,7 @@
 					iSession->Command().iFlags|= KMMCCmdFlagReliableWrite;
 					}
 				}
+#endif //_ENABLE_EMMC_RELIABLE_WRITE_			
 		
 			// Engage the data transfer session...
 			r = EngageAndSetWriteRequest(aMedReq);
--- a/kernel/eka/drivers/pbus/mmc/mmccd_init.cpp	Tue May 11 17:28:22 2010 +0300
+++ b/kernel/eka/drivers/pbus/mmc/mmccd_init.cpp	Tue May 25 14:09:55 2010 +0300
@@ -278,6 +278,16 @@
 			break;
 
 #if !defined(__WINS__)
+        if ((mi.iFlags & TMMCMachineInfo::ESupportsDMA) == TMMCMachineInfo::ESupportsDMA)
+            {
+            err = LocDrv::RegisterDmaDevice(pMedia,
+                                            KMMCardHighCapBlockSize, 
+                                            pS->MaxDataTransferLength(), 
+                                            pS->DmaAlignment());
+            if (err != KErrNone)
+                break;
+            }		
+		
 		if (demandPagingSupported && demandPagingInfo.iSlotNumber == i)
 			{
 			err = LocDrv::RegisterPagingDevice(
@@ -295,16 +305,6 @@
 			if (err != KErrNone)
 				break;
 			}
-
-		if ((mi.iFlags & TMMCMachineInfo::ESupportsDMA) == TMMCMachineInfo::ESupportsDMA)
-			{
-			err = LocDrv::RegisterDmaDevice(pMedia,
-											KMMCardHighCapBlockSize, 
-											pS->MaxDataTransferLength(), 
-											pS->DmaAlignment());
-			if (err != KErrNone)
-				break;
-			}
 #endif // __WINS__
 
 		driveListIndex+= drivesPerSlot;
--- a/kernel/eka/eabi/dma2u.def	Tue May 11 17:28:22 2010 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,69 +0,0 @@
-EXPORTS
-	_Z11DmaTestInfov @ 1 NONAME
-	_Z13DmaTestInfoV2v @ 2 NONAME
-	_ZN11DDmaRequest11FreeDesListEv @ 3 NONAME
-	_ZN11DDmaRequest13ExpandDesListEi @ 4 NONAME
-	_ZN11DDmaRequest13FragmentCountEv @ 5 NONAME
-	_ZN11DDmaRequest14FreeDstDesListEv @ 6 NONAME
-	_ZN11DDmaRequest14FreeSrcDesListEv @ 7 NONAME
-	_ZN11DDmaRequest16DstFragmentCountEv @ 8 NONAME
-	_ZN11DDmaRequest16ExpandDstDesListEi @ 9 NONAME
-	_ZN11DDmaRequest16ExpandSrcDesListEi @ 10 NONAME
-	_ZN11DDmaRequest16SrcFragmentCountEv @ 11 NONAME
-	_ZN11DDmaRequest24EnableDstElementCountingEi @ 12 NONAME
-	_ZN11DDmaRequest24EnableSrcElementCountingEi @ 13 NONAME
-	_ZN11DDmaRequest25DisableDstElementCountingEv @ 14 NONAME
-	_ZN11DDmaRequest25DisableSrcElementCountingEv @ 15 NONAME
-	_ZN11DDmaRequest30TotalNumDstElementsTransferredEv @ 16 NONAME
-	_ZN11DDmaRequest30TotalNumSrcElementsTransferredEv @ 17 NONAME
-	_ZN11DDmaRequest5QueueEv @ 18 NONAME
-	_ZN11DDmaRequest8FragmentERK16TDmaTransferArgs @ 19 NONAME
-	_ZN11DDmaRequest8FragmentEmmijm @ 20 NONAME
-	_ZN11DDmaRequestC1ER11TDmaChannelPFvNS_7TResultEPvES3_i @ 21 NONAME
-	_ZN11DDmaRequestC1ER11TDmaChannelPFvj10TDmaResultPvP10SDmaDesHdrES3_j @ 22 NONAME
-	_ZN11DDmaRequestC2ER11TDmaChannelPFvNS_7TResultEPvES3_i @ 23 NONAME
-	_ZN11DDmaRequestC2ER11TDmaChannelPFvj10TDmaResultPvP10SDmaDesHdrES3_j @ 24 NONAME
-	_ZN11DDmaRequestD0Ev @ 25 NONAME
-	_ZN11DDmaRequestD1Ev @ 26 NONAME
-	_ZN11DDmaRequestD2Ev @ 27 NONAME
-	_ZN11TDmaChannel13LinkToChannelEPS_ @ 28 NONAME
-	_ZN11TDmaChannel14IsrRedoRequestEmmjmi @ 29 NONAME
-	_ZN11TDmaChannel15StaticExtensionEiPv @ 30 NONAME
-	_ZN11TDmaChannel16AddressAlignMaskEjjm @ 31 NONAME
-	_ZN11TDmaChannel17MaxTransferLengthEjjm @ 32 NONAME
-	_ZN11TDmaChannel18MissNextInterruptsEi @ 33 NONAME
-	_ZN11TDmaChannel4OpenERKNS_11SCreateInfoERPS_ @ 34 NONAME
-	_ZN11TDmaChannel5CloseEv @ 35 NONAME
-	_ZN11TDmaChannel5PauseEv @ 36 NONAME
-	_ZN11TDmaChannel6ResumeEv @ 37 NONAME
-	_ZN11TDmaChannel8DmacCapsEv @ 38 NONAME
-	_ZN11TDmaChannel8FailNextEi @ 39 NONAME
-	_ZN11TDmaChannel9CancelAllEv @ 40 NONAME
-	_ZN11TDmaChannel9ExtensionEiPv @ 41 NONAME
-	_ZN16TDmaTransferArgsC1ERK18TDmaTransferConfigS2_mjj15TDmaGraphicsOpsm @ 42 NONAME
-	_ZN16TDmaTransferArgsC1Ejjjjjj12TDmaAddrModejj13TDmaBurstSizej15TDmaGraphicsOpsm @ 43 NONAME
-	_ZN16TDmaTransferArgsC1Ev @ 44 NONAME
-	_ZN16TDmaTransferArgsC2ERK18TDmaTransferConfigS2_mjj15TDmaGraphicsOpsm @ 45 NONAME
-	_ZN16TDmaTransferArgsC2Ejjjjjj12TDmaAddrModejj13TDmaBurstSizej15TDmaGraphicsOpsm @ 46 NONAME
-	_ZN16TDmaTransferArgsC2Ev @ 47 NONAME
-	_ZN18TDmaTransferConfigC1Emj12TDmaAddrModej13TDmaBurstSizejjji @ 48 NONAME
-	_ZN18TDmaTransferConfigC1Emjjjiijj13TDmaBurstSizejji @ 49 NONAME
-	_ZN18TDmaTransferConfigC1Ev @ 50 NONAME
-	_ZN18TDmaTransferConfigC2Emj12TDmaAddrModej13TDmaBurstSizejjji @ 51 NONAME
-	_ZN18TDmaTransferConfigC2Emjjjiijj13TDmaBurstSizejji @ 52 NONAME
-	_ZN18TDmaTransferConfigC2Ev @ 53 NONAME
-	_ZTI11DDmaRequest @ 54 NONAME
-	_ZTI11TDmaChannel @ 55 NONAME
-	_ZTI13TDmaDbChannel @ 56 NONAME
-	_ZTI13TDmaSbChannel @ 57 NONAME
-	_ZTI13TDmaSgChannel @ 58 NONAME
-	_ZTI17TDmaAsymSgChannel @ 59 NONAME
-	_ZTI5TDmac @ 60 NONAME
-	_ZTV11DDmaRequest @ 61 NONAME
-	_ZTV11TDmaChannel @ 62 NONAME
-	_ZTV13TDmaDbChannel @ 63 NONAME
-	_ZTV13TDmaSbChannel @ 64 NONAME
-	_ZTV13TDmaSgChannel @ 65 NONAME
-	_ZTV17TDmaAsymSgChannel @ 66 NONAME
-	_ZTV5TDmac @ 67 NONAME
-
--- a/kernel/eka/include/drivers/dma.h	Tue May 11 17:28:22 2010 +0300
+++ b/kernel/eka/include/drivers/dma.h	Tue May 25 14:09:55 2010 +0300
@@ -1,7 +1,7 @@
-// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
+// Copyright (c) 2002-2010 Nokia Corporation and/or its subsidiary(-ies).
 // All rights reserved.
 // This component and the accompanying materials are made available
-// under the terms of the License "Eclipse Public License v1.0"
+// under the terms of "Eclipse Public License v1.0""
 // which accompanies this distribution, and is available
 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
 //
@@ -12,19 +12,842 @@
 //
 // Description:
 // include/drivers/dma.h
-// DMA Framework - Client API definition.
-//
+// DMA Framework API
 //
 
 #ifndef __DMA_H__
 #define __DMA_H__
 
+#include <kernel/kern_priv.h>
 
-#ifndef DMA_APIV2
-# include <drivers/dma_v1.h>
+
+//////////////////////////////////////////////////////////////////////////////
+// Debug Support - KDmaPanicCat is defined in each source file
+
+#define __DMA_ASSERTD(e) __ASSERT_DEBUG(e, Kern::Fault(KDmaPanicCat, __LINE__))
+#define __DMA_ASSERTA(e) __ASSERT_ALWAYS(e, Kern::Fault(KDmaPanicCat, __LINE__))
+#ifdef _DEBUG
+#define __DMA_CANT_HAPPEN() Kern::Fault(KDmaPanicCat, __LINE__)
+#define __DMA_DECLARE_INVARIANT public: void Invariant();
+#define __DMA_INVARIANT() Invariant()
 #else
-# include <drivers/dma_v2.h>
-#endif	// #ifndef DMA_APIV2
+#define __DMA_CANT_HAPPEN()
+#define __DMA_DECLARE_INVARIANT
+#define __DMA_INVARIANT()
+#endif
+
+
+//////////////////////////////////////////////////////////////////////////////
+// INTERFACE EXPOSED TO DEVICE-DRIVERS
+//////////////////////////////////////////////////////////////////////////////
+
+/**
+Bitmasks used for configuring a DMA request.
+
+In general, specify KDmaMemSrc|KDmaIncSrc (resp. KDmaMemDest|KDmaIncDest) if
+the source (resp. destination) is a memory buffer and clear
+KDmaMemSrc|KDmaIncSrc (resp. KDmaMemDest|KDmaIncDest) if the source
+(resp. destination) is a peripheral.
+
+If the location is given as a physical address (rather than a linear one)
+then also specify KDmaPhysAddrSrc and/or KDmaPhysAddrDest.
+
+The EKA1 "Fill Mode" can be implemented by omitting KDmaIncSrc.
+
+Some peripherals may require a post-increment address mode.
+
+@see DDmaRequest::Fragment
+@publishedPartner
+@released
+*/
+
+enum TDmaRequestFlags
+	{
+	/** Source is address of memory buffer */
+	KDmaMemSrc       = 0x01,
+	/** Destination is address of memory buffer */
+	KDmaMemDest      = 0x02,
+	/** Source address must be post-incremented during transfer */
+	KDmaIncSrc       = 0x04,
+	/** Destination address must be post-incremented during transfer */
+	KDmaIncDest      = 0x08,
+	/** Source address is a physical address (as opposed to a linear one) */
+	KDmaPhysAddrSrc  = 0x10,
+	/** Destination address is a physical address (as opposed to a linear one) */
+	KDmaPhysAddrDest = 0x20,
+	/** Request a different max transfer size (for instance for test purposes) */
+	KDmaAltTransferLen = 0x40
+	};
+
+
+//////////////////////////////////////////////////////////////////////////////
+
+class TDmaChannel;
+struct SDmaDesHdr;
+
+/** A DMA request is a list of fragments small enough to be transferred in one go
+	by the DMAC.
+
+	In general, fragmentation is done in the framework by calling Fragment() but
+	clients with special needs can allocate a blank descriptor list with
+	ExpandDesList() and customise it to fit their needs.
+
+	Clients should not set attributes directly, but should use the various functions
+	instead.
+
+	This class has not been designed to be called from several concurrent threads.
+	Multithreaded clients must implement their own locking scheme (via DMutex).
+
+	Fast mutexes are used internally to protect data structures accessed both
+	by the client thread and the DFC thread.  Therefore no fast mutex can be held
+	when calling a request function.
+
+	@publishedPartner
+	@released
+ */
+class DDmaRequest : public DBase
+	{
+	friend class TDmaChannel;
+public:
+	/** The outcome of the transfer */
+	enum TResult {EBadResult=0, EOk, EError};
+	/** The signature of the completion/failure callback function */
+	typedef void (*TCallback)(TResult, TAny*);
+public:
+   
+    /**
+    Create a new transfer request. 
+
+    @param aChannel The channel this request is bound to.
+    @param aCb      Callback function called on transfer completion or failure (in channel
+                    DFC context).  Can be NULL.
+    @param aCbArg   Argument passed to callback function.
+    @param aMaxTransferSize Maximum fragment size.  If not specified, defaults to the maximum size
+           supported by the DMA controller for the type of transfer that is later scheduled.
+    */
+	IMPORT_C DDmaRequest(TDmaChannel& aChannel, TCallback aCb=NULL, TAny* aCbArg=NULL, TInt aMaxTransferSize=0);
+	
+	
+	/**
+    Destructor.
+
+    Assume the request is not being transferred or pending.
+    */
+	IMPORT_C ~DDmaRequest();
+	
+	
+	/**
+    Split request into a list of fragments small enough to be fed to the DMAC.
+
+    The size of each fragment is smaller than or equal to the maximum transfer size
+    supported by the DMAC.  If the source and/or destination is memory, each
+    fragment points to memory which is physically contiguous.
+
+    The kind of transfer to perform is specified via a set of flags used by a PIL
+    and a magic cookie passed to the PSL.  If the source (resp. destination) is a
+    peripheral, aSrc (resp. aDest) is treated as a magic cookie by the PIL and
+    passed straight to the PSL.
+
+    The request can be uninitialised or may have been fragmented previously.  The
+    previous configuration if any is lost whether or not the function succeeds.
+
+    @param aSrc     Source memory buffer linear address or peripheral magic cookie.
+    @param aDest    Destination memory buffer linear address or peripheral magic cookie.
+    @param aCount   Number of bytes to transfer.
+    @param aFlags   Bitmask characterising the transfer.
+    @param aPslInfo Hardware-specific information passed to PSL.
+
+    @return KErrNone if success. KErrArgument if aFlags and/or aPslInfo are invalid when finding
+    the maximum transfer size. May also fail if running out of descriptors.
+
+    @pre The request is not being transferred or pending.
+    @pre The various parameters must be valid.  The PIL or PSL will fault the
+    kernel if not.
+
+    @see TDmaRequestFlags
+    */
+	IMPORT_C TInt Fragment(TUint32 aSrc, TUint32 aDest, TInt aCount, TUint aFlags, TUint32 aPslInfo);
+	
+	
+	/**
+    Transfer asynchronously this request.
+
+    If this request's channel is idle, the request is transferred immediately.
+    Otherwise, it is queued and transferred later.
+
+    The client is responsible for ensuring cache consistency before and/or after the
+    transfer if necessary.
+    */
+	IMPORT_C void Queue();
+	
+
+    /**
+    Append new descriptor(s) to existing list.
+
+    Clients needing to build a custom descriptor list should call this function to
+    allocate the list and access the resulting list through iFirstHdr and iLastHdr.
+
+    Clients should not change the value of iFirstHdr, iLastHdr and the iNext field
+    of the descriptor headers to ensure descriptors can be deallocated. Clients
+    are free to change hardware descriptors, including chaining, in whatever way
+    suit them.
+
+    Assume the request is not being transferred or pending.
+
+    @param aCount Number of descriptors to append.
+
+    @return KErrNone or KErrTooBig if not enough descriptors available.
+    */
+	IMPORT_C TInt ExpandDesList(TInt aCount=1);
+	
+	
+	/**
+    Free resources associated with this request.
+
+    Assume the request is not being transferred or pending.
+    */
+	IMPORT_C void FreeDesList();
+private:
+	inline void OnDeque();
+public:
+	// WARNING: The following attributes are accessed both in client and DFC
+	// context and so accesses must be protected with the channel lock.
+	TDmaChannel& iChannel;		/**< The channel this request is bound to */
+	volatile TCallback iCb;		/**< Called on completion/failure (can be NULL) */
+	TAny* volatile iCbArg;		/**< Callback argument */
+	TInt iDesCount;				/**< The number of fragments in list */
+	SDmaDesHdr* iFirstHdr;		/**< The first fragment in the list (or NULL) */
+	SDmaDesHdr* iLastHdr;		/**< The last fragment in the list (or NULL) */
+	SDblQueLink iLink;			/**< The link on channel queue of pending requests */
+	TBool iQueued;				/**< Indicates whether request is pending or being transferred */
+	TInt iMaxTransferSize;		/**< Defaults to DMA controller max. transfer size */
+	__DMA_DECLARE_INVARIANT
+	};
+
+
+//////////////////////////////////////////////////////////////////////////////
+
+class TDmac;
+class DmaChannelMgr;
+
+/** DMA channel base class.
+
+	This class has not been designed to be called from several concurrent
+	client threads.  Multithreaded clients must implement their own locking
+	scheme (via DMutex).
+
+	Fast mutexes are used internally to protect data structures accessed both
+	by the client thread and the DFC one.  Therefore no fast mutex can be held
+	when calling a channel function.
+
+	Must be allocated in BSS because it relies on being zeroed at
+	creation-time.  If the PSL really needs to allocate channels on the kernel
+	heap, it must manually zero-initialises the instances.  This can be
+	achieved either by allocating raw memory and using placement new, or by
+	wrapping channels into a DBase-derived wrapper.
+
+	@publishedPartner
+	@released
+ */
+class TDmaCancelInfo;
+class TDmaChannel
+	{
+	friend class DDmaRequest;
+	friend class TDmac;
+	friend class DmaChannelMgr;
+public:
+	/**  Information passed by client when opening channel */
+	struct SCreateInfo
+		{
+		/** Identifier used by PSL to select channel to open */
+		TUint32 iCookie;
+		/** Number of descriptors this channel can use */
+		TInt iDesCount;
+		/** DFC queue used to service DMA interrupts.  The DFC thread
+			priority must be higher than any client thread priority to
+			avoid a situation where a transfer completes while being
+			cancelled and another transfer is started before the DFC
+			thread gets a chance to run.  This would lead to a stray
+			DFC.
+		*/
+		TDfcQue* iDfcQ;
+		/** DFC priority */
+		TUint8 iDfcPriority;
+		};
+public:
+    /**
+ 	Opens the DMA channel.
+
+ 	Channel selection is done by the hardware-specific layer using a cookie passed in
+ 	via aInfo.
+
+ 	The client should not delete the returned pointer as the framework owns
+ 	channel objects.  However, the client should explicitly close the channel when
+ 	finished with it.
+
+	@param aInfo    Information passed by caller to select and configure channel.
+ 	@param aChannel Point to open channel on successful return.  NULL otherwise.
+
+ 	@return KErrNone or standard error code.
+ 	*/
+	IMPORT_C static TInt Open(const SCreateInfo& aInfo, TDmaChannel*& aChannel);
+	
+	
+	/**
+ 	Closes a previously opened DMA channel.
+
+ 	Assume the channel is idle and all requests have been deleted.
+ 	*/
+	IMPORT_C void Close();
+	
+	
+	/**
+ 	Cancels the current request and all the pending ones.
+ 	*/
+	IMPORT_C void CancelAll();
+	inline TBool IsOpened() const;
+	inline TBool IsQueueEmpty() const;
+	inline TUint32 PslId() const;
+	inline TInt FailNext(TInt aFragmentCount);
+	inline TInt MissNextInterrupts(TInt aInterruptCount);
+	inline TInt Extension(TInt aCmd, TAny* aArg);
+	
+	/**
+	This is a function that allows the Platform Specific Layer (PSL) to extend the DMA API
+	with new channel-independent operations.
+
+	@param aCmd Command identifier.  Negative values are reserved for Symbian use.
+	@param aArg PSL-specific.
+	
+	@return KErrNotSupported if aCmd is not supported; a  PSL specific value otherwise.
+ 	*/
+	IMPORT_C TInt StaticExtension(TInt aCmd, TAny* aArg);
+	inline const TDmac* Controller() const;
+	inline TInt MaxTransferSize(TUint aFlags, TUint32 aPslInfo);
+	inline TUint MemAlignMask(TUint aFlags, TUint32 aPslInfo);
+protected:
+	// Interface with state machines
+	TDmaChannel();
+	virtual void DoQueue(DDmaRequest& aReq) = 0;
+	virtual void DoCancelAll() = 0;
+	virtual void DoUnlink(SDmaDesHdr& aHdr);
+	virtual void DoDfc(DDmaRequest& aCurReq, SDmaDesHdr*& aCompletedHdr) = 0;
+	/**
+	   This function allows the Platform Specific Layer (PSL) to control the
+	   power management of the channel or its controller by overriding the
+	   PIL's default implementation (which does nothing) and making appropriate
+	   use of the Power Resource Manager (PRM).
+
+	   The function gets called by the PIL whenever the channel's queued
+	   requests count has changed in a significant way, either before the
+	   channel's Transfer() method is invoked for a request on a previously
+	   empty request queue, or immediately after the request count has become
+	   zero because of request cancellation or completion.
+
+	   Depending on the current value of iQueuedRequests, the PSL may power
+	   down or power up the channel. Note that iQueuedRequests gets accessed
+	   and changed by different threads, so the PSL needs to take the usual
+	   precautions when evaluating the variable's value.
+
+	   None of the internal DMA framework mutexes is being held by the PIL when
+	   calling this function.
+
+	   @see iQueuedRequests
+	 */
+	virtual void QueuedRequestCountChanged();
+#if defined(__CPU_ARM) && !defined(__EABI__)
+	inline virtual ~TDmaChannel() {}	// kill really annoying warning
+#endif
+private:
+	static void Dfc(TAny*);
+	void DoDfc();
+	inline void Wait();
+	inline void Signal();
+	inline TBool Flash();
+	void ResetStateMachine();
+protected:
+	TDmac* iController;										// DMAC this channel belongs to (NULL when closed)
+	TUint32 iPslId;											// unique identifier provided by PSL
+	NFastMutex iLock;										// for data accessed in both client & DFC context
+	SDmaDesHdr* iCurHdr;									// fragment being transferred or NULL
+	SDmaDesHdr** iNullPtr;									// Pointer to NULL pointer following last fragment
+	TDfc iDfc;												// transfer completion/failure DFC
+	TInt iMaxDesCount;										// maximum number of allocable descriptors
+	TInt iAvailDesCount;									// available number of descriptors
+	volatile TUint32 iIsrDfc;								// Interface between ISR and DFC:
+	enum { KErrorFlagMask = 0x80000000 };					// bit 31 - error flag
+	enum { KCancelFlagMask = 0x40000000 };					// bit 30 - cancel flag
+	enum { KDfcCountMask = 0x3FFFFFFF };					// bits 0-29 - number of queued DFCs
+	SDblQue iReqQ;											// being/about to be transferred request queue
+	TInt iReqCount;											// number of requests attached to this channel
+	TInt iQueuedRequests; 									// number of requests currently queued on this channel
+private:
+	TDmaCancelInfo* iCancelInfo;
+	__DMA_DECLARE_INVARIANT
+	};
+
+
+//////////////////////////////////////////////////////////////////////////////
+// PIL-PSL INTERFACE
+//////////////////////////////////////////////////////////////////////////////
+
+// Trace macros intended for use by the DMA PSL
+#define DMA_PRINTF(MSG) __KTRACE_OPT(KDMA, Kern::Printf((MSG)))
+#define DMA_PRINTF1(MSG, ARG1) __KTRACE_OPT(KDMA, Kern::Printf((MSG), (ARG1)))
+#define DMA_PRINTF2(MSG, ARG1, ARG2) __KTRACE_OPT(KDMA, Kern::Printf((MSG), (ARG1), (ARG2)))
+
+#define DMA_PSL_MESG "DMA PSL: "
+
+// General PSL tracing
+#define DMA_PSL_TRACE(MSG) DMA_PRINTF(DMA_PSL_MESG MSG)
+#define DMA_PSL_TRACE1(MSG, ARG1) DMA_PRINTF1(DMA_PSL_MESG MSG, (ARG1))
+#define DMA_PSL_TRACE2(MSG, ARG1, ARG2) DMA_PRINTF2(DMA_PSL_MESG MSG, (ARG1), (ARG2))
+
+
+#define DMA_PSL_CHAN_MESG DMA_PSL_MESG "ChanId %d: "
+#define DMA_PSL_CHAN_ARGS(CHAN) ((CHAN).PslId())
+
+// For channel specific tracing (where CHAN is a TDmaChannel)
+#define DMA_PSL_CHAN_TRACE_STATIC(CHAN, MSG) DMA_PRINTF1(DMA_PSL_CHAN_MESG MSG, DMA_PSL_CHAN_ARGS(CHAN))
+#define DMA_PSL_CHAN_TRACE_STATIC1(CHAN, MSG, ARG1) DMA_PRINTF2(DMA_PSL_CHAN_MESG MSG, DMA_PSL_CHAN_ARGS(CHAN), (ARG1))
+
+// For channel specific tracing, for use within methods of TDmaChannel derived
+// class
+#define DMA_PSL_CHAN_TRACE(MSG) DMA_PSL_CHAN_TRACE_STATIC(*this, MSG)
+#define DMA_PSL_CHAN_TRACE1(MSG, ARG1) DMA_PSL_CHAN_TRACE_STATIC1(*this, MSG, (ARG1))
 
 
-#endif	// #ifndef __DMA_H__
+/**
+Generic DMA descriptor used if the DMAC does not have support for hardware
+descriptor.
+@see DDmaRequest::Fragment
+@publishedPartner
+@released
+*/
+
+struct SDmaPseudoDes
+	{
+	/** Source linear address or peripheral cookie */
+	TUint32 iSrc;
+	/** Destination linear address or peripheral cookie */
+	TUint32 iDest;
+	/** Number of bytes to transfer */
+	TInt iCount;
+	/** @see TDmaRequestFlags */
+	TUint iFlags;
+	/** PSL-specific information provided by client */
+	TUint32 iPslInfo;
+	/** The same as TDmaChannel::SCreateInfo.iCookie */
+	TUint32 iCookie;
+	};
+
+
+/**
+Each hardware or pseudo descriptor is associated with a header.  Headers are
+needed because hardware descriptors can not easily be extended to store
+additional information.
+@publishedPartner
+@released
+*/
+
+struct SDmaDesHdr
+	{
+	SDmaDesHdr* iNext;
+	};
+
+
+/**
+Interface used by PIL to open and close DMA channels.
+
+Must be implemented by PSL.
+@publishedPartner
+@released
+*/
+
+class DmaChannelMgr
+	{
+public:
+	/** Opens a channel using a client-provided identifier.
+		This function must be implemented by the PSL.
+		@param	aOpenId Magic cookie passed by client
+				This may identify the channel (if a static channel
+				allocation scheme is used) or may indicate some
+				properties which the channel must possess (if a dynamic
+				channel allocation scheme is used). It may be set to
+				zero always if dynamic allocation is used and all
+				channels are equivalent.
+		@return	Pointer to channel if available, NULL otherwise.
+		@pre	The PIL calls this function with a global fast mutex held to
+				avoid race conditions.
+		@post	If a non-NULL pointer is returned, the object pointed to has its
+				iController and iPslId members set to valid states.
+				iController should point to the controller handling that channel.
+				iPslId should contain a value uniquely identifying the channel -
+				it is used only for debug tracing by PIL. It can be given any
+				convenient value by PSL	(channel index, I/O port address, ...).
+	*/
+	static TDmaChannel* Open(TUint32 aOpenId);
+
+	/** Performs platform-specific operations when a channel is closed.
+		This function must be implemented by the PSL but the implementation can be
+		a no-op.
+		@param aChannel The channel to close
+		@pre The PIL calls this function with a global fast mutex held to
+			avoid race conditions.
+	*/
+	static void Close(TDmaChannel* aChannel);
+
+	/** Function allowing PSL to extend DMA API with new channel-independent operations.
+		This function must be implemented by the PSL.
+		@param aCmd Command identifier.  Negative values are reserved for Symbian use.
+		@param aArg PSL-specific
+		@return KErrNotSupported if aCmd is not supported.  PSL-specific value otherwise.
+	 */
+	static TInt StaticExtension(TInt aCmd, TAny* aArg);
+
+	static inline void Wait();
+	static inline void Signal();
+private:
+	static NFastMutex Lock;
+	};
+
+
+//////////////////////////////////////////////////////////////////////////////
+
+/**
+ Abstract base class representing a DMA controller.
+
+ The class has two purposes.
+
+ First, it is a container for channels, descriptors and descriptor headers.
+
+ Second, it exposes a set of virtual functions implemented by
+ the PSL (platform-specific layer).
+ These functions are the main interfaces between
+ the PIL (platform-independent layer) and PSL.
+
+ Must be allocated in BSS because it relies on being zeroed at creation-time.
+
+ @publishedPartner
+ @released
+ */
+
+class TDmac
+	{
+	friend class DmaChannelMgr;
+// protected: VC++ complains when building PSL if following decl is protected
+public:
+	/** Data required for creating a new instance */
+	struct SCreateInfo
+		{
+		/** Number of channels in controller */
+		TInt iChannelCount;
+        /** Maximum number of descriptors (shared by all channels) */
+		TInt iDesCount;
+		/** Bitmask.  The only supported value is KCapsBitHwDes (hardware
+			descriptors used). */
+		TUint32 iCaps;
+		/** Size of individual descriptors.  Use sizeof(SDmaPseudoDes) for
+		 	single-buffer and double-buffer controllers. */
+		TInt iDesSize;
+		/** Bitmask used when creating the hardware chunk storing the descriptor
+			pool. Used only for hardware descriptors. The access part must be
+			EMapAttrSupRw.  If the chunk is cached and/or buffered, the PSL must
+			flush the data cache and/or drain the write buffer in InitHwDes()
+			and related functions.
+		 	@see TMappingAttributes
+		 */
+		TUint iDesChunkAttribs;
+		};
+public:
+	TInt Create(const SCreateInfo& aInfo);
+	virtual ~TDmac();
+	TInt ReserveSetOfDes(TInt aCount);
+	void ReleaseSetOfDes(TInt aCount);
+	void InitDes(const SDmaDesHdr& aHdr, TUint32 aSrc, TUint32 aDest, TInt aCount,
+				 TUint aFlags, TUint32 aPslInfo, TUint32 aCookie);
+	inline SDmaPseudoDes& HdrToDes(const SDmaDesHdr& aHdr) const;
+	inline TAny* HdrToHwDes(const SDmaDesHdr& aHdr) const;
+	inline TUint32 DesLinToPhys(TAny* aDes) const;
+	inline void Wait();
+	inline void Signal();
+protected:
+	TDmac(const SCreateInfo& aInfo);
+
+public:
+	/**
+	Called by PIL when one fragment (single-buffer and double-buffer DMACs) or
+	list of fragments (scatter/gather DMAC) is to be transferred.
+
+	Called when	initiating a new transfer and also, for double-buffer DMACs, for
+	configuring the next fragment to transfer while the current one is
+	ongoing. Must always be implemented by PSL.
+	@param aChannel The channel to use
+	@param aHdr Header associated with fragment to transfer
+	*/
+	virtual void Transfer(const TDmaChannel& aChannel, const SDmaDesHdr& aHdr) = 0;
+
+	/**
+    Called by PIL to suspend transfer on a given channel.
+
+    The suspension must occur synchronously as the PSL assumes the channel
+    is suspended after calling this function. Must always be implemented by PSL.
+	@param aChannel The channel to suspend
+	*/
+	virtual void StopTransfer(const TDmaChannel& aChannel) = 0;
+
+	/**
+	Called by PIL to check whether a DMA channel is idle.
+	@param aChannel The channel to test
+	@return ETrue if channel idle, EFalse if transferring.
+	 */
+	virtual TBool IsIdle(const TDmaChannel& aChannel) = 0;
+
+	/**
+	Called by PIL to retrieve from the PSL the maximum transfer size based on the
+	parameters passed.
+	@param aChannel Channel to be used for the transfer
+	@param aFlags Bitmask characterising transfer
+	@param aPslInfo Cookie passed by client and used by PSL
+	@return 0 if invalid argument(s), -1 if transfer size not limited, the maximum
+	transfer size otherwise.
+	*/
+	virtual TInt MaxTransferSize(TDmaChannel& aChannel, TUint aFlags, TUint32 aPslInfo) = 0;
+
+	/**
+	Called by PIL to retrieve from the PSL the memory alignment mask based on the
+	parameters passed. Some DMA controllers impose alignment constraints on the base
+	address of memory buffers. This mask is AND'ed against memory addresses computed
+	during fragmentation.
+	@param aChannel Channel to be used for the transfer
+	@param aFlags Bitmask characterising transfer
+	@param aPslInfo Cookie passed by client and used by PSL
+	@return A value representing the alignment mask (e.g. 3 if buffer must be 4-byte aligned)
+	*/
+	virtual TUint MemAlignMask(TDmaChannel& aChannel, TUint aFlags, TUint32 aPslInfo) = 0;
+
+	/**
+    Called by PIL during fragmentation to initialise a hardware descriptor.
+
+    The PSL must assume the descriptor is the last in the chain and so set the
+	interrupt bit and set the next descriptor field to an end of chain marker.
+	Must be implemented by PSL if and only if the DMAC supports hardware
+	descriptors.
+	@param aHdr Header associated with hardware descriptor to initialise
+	@param aSrc Transfer source
+	@param aDest Transfer destination
+	@param aCount Number of bytes to transfer (<= max. size supported by DMAC)
+	@param aFlags Bitmask characterising transfer
+	@param aPslInfo Cookie passed by client and used by PSL
+	@param aCookie the channel selection cookie
+	@see DDmaRequest::Fragment
+	*/
+	virtual void InitHwDes(const SDmaDesHdr& aHdr, TUint32 aSrc, TUint32 aDest, TInt aCount,
+						   TUint aFlags, TUint32 aPslInfo, TUint32 aCookie);
+
+	/**
+	Called by PIL, when fragmenting a request, to append a new hardware
+	descriptor to an existing descriptor chain.
+
+	Must clear the interrupt bit of	the descriptor associated with aHdr.
+	Must be implemented by PSL if and only if the DMAC supports hardware descriptors.
+	@param aHdr Header associated with last fragment in chain
+	@param aNextHdr Header associated with fragment to append
+	*/
+	virtual void ChainHwDes(const SDmaDesHdr& aHdr, const SDmaDesHdr& aNextHdr);
+
+	/**
+	Called by PIL when queuing a new request while the channel is running.
+
+	Must append the first hardware descriptor of the new request to the last
+	descriptor in the existing chain. Must be implemented by PSL if and only if
+	the DMAC supports hardware descriptors.
+	@param aChannel The channel where the transfer takes place
+	@param aLastHdr Header associated with last hardware descriptor in chain
+	@param aNewHdr Header associated with first hardware descriptor in new request
+	*/
+	virtual void AppendHwDes(const TDmaChannel& aChannel, const SDmaDesHdr& aLastHdr,
+							 const SDmaDesHdr& aNewHdr);
+
+	/**
+	Called by PIL when completing or cancelling a request to cause the PSL to unlink
+	the last item in the h/w descriptor chain from a subsequent chain that it was
+	possibly linked to. Must be implemented by the PSL if and only if the DMAC supports
+	hardware descriptors.
+
+	@param aChannel The channel where the request (and thus the descriptor) was queued
+	@param aHdr Header associated with last h/w descriptor in completed/cancelled chain
+	*/
+	virtual void UnlinkHwDes(const TDmaChannel& aChannel, SDmaDesHdr& aHdr);
+
+	/**
+	Called by test harness to force an error when the next fragment is
+	transferred.
+
+	Must be implemented by the PSL only if possible.
+	@param aChannel The channel where the error is to occur.
+	@return KErrNone if implemented.  The default PIL implementation returns
+	KErrNotSupported and the test harness knows how to deal with that.
+	*/
+	virtual TInt FailNext(const TDmaChannel& aChannel);
+
+	/**
+	Called by test harness to force the DMA controller to miss one or
+	more interrupts.
+
+	Must be implemented by the PSL only if possible.
+	@param aChannel The channel where the error is to occur
+	@param aInterruptCount The number of interrupt to miss.
+	@return KErrNone if implemented.  The default PIL implementation returns
+	KErrNotSupported and the test harness knows how to deal with that.
+	*/
+	virtual TInt MissNextInterrupts(const TDmaChannel& aChannel, TInt aInterruptCount);
+
+	/** Function allowing platform-specific layer to extend channel API with
+		new channel-specific operations.
+		@param aChannel Channel to operate on
+		@param aCmd Command identifier.  Negative values are reserved for Symbian use.
+		@param aArg PSL-specific
+		@return KErrNotSupported if aCmd is not supported.  PSL-specific value otherwise.
+		@see TDmaChannel::Extension
+	*/
+	virtual TInt Extension(TDmaChannel& aChannel, TInt aCmd, TAny* aArg);
+
+protected:
+	static void HandleIsr(TDmaChannel& aChannel, TBool aIsComplete);
+private:
+	TInt AllocDesPool(TUint aAttribs);
+	void FreeDesPool();
+private:
+	NFastMutex iLock;			 // protect descriptor reservation and allocation
+	const TInt iMaxDesCount;	 // initial number of descriptors and headers
+	TInt iAvailDesCount;		 // current available number of descriptors and headers
+	SDmaDesHdr* iHdrPool;		 // descriptor header dynamic array
+#ifndef __WINS__
+	DPlatChunkHw* iHwDesChunk;	 // chunk for hardware descriptor pool
+#endif
+	TAny* iDesPool;				 // hardware or pseudo descriptor dynamic array
+	const TInt iDesSize;		 // descriptor size in bytes
+public:
+	const TUint iCaps;  		 /*< what is supported by DMA controller */
+	enum {KCapsBitHwDes = 1};	 /*< hardware descriptors supported */
+	SDmaDesHdr* iFreeHdr;		 /*< head of unallocated descriptors linked list */
+#ifdef _DEBUG
+	TBool IsValidHdr(const SDmaDesHdr* aHdr);
+#endif
+	__DMA_DECLARE_INVARIANT
+	};
+
+
+//////////////////////////////////////////////////////////////////////////////
+
+/**
+Single-buffer DMA channel.
+
+Can be instantiated or further derived by PSL.  Not
+intended to be instantiated by client device drivers.
+@publishedPartner
+@released
+*/
+
+class TDmaSbChannel : public TDmaChannel
+	{
+private:
+	virtual void DoQueue(DDmaRequest& aReq);
+	virtual void DoCancelAll();
+	virtual void DoDfc(DDmaRequest& aCurReq, SDmaDesHdr*& aCompletedHdr);
+private:
+	TBool iTransferring;
+	};
+
+
+/**
+Double-buffer DMA channel.
+
+Can be instantiated or further derived by PSL.  Not
+intended to be instantiated by client device drivers.
+@publishedPartner
+@released
+*/
+
+class TDmaDbChannel : public TDmaChannel
+	{
+private:
+	virtual void DoQueue(DDmaRequest& aReq);
+	virtual void DoCancelAll();
+	virtual void DoDfc(DDmaRequest& aCurReq, SDmaDesHdr*& aCompletedHdr);
+private:
+	enum { EIdle = 0, ETransferring, ETransferringLast } iState;
+	};
+
+
+/**
+Scatter-gather DMA channel.
+
+Can be instantiated or further derived by PSL.
+Not intended to be instantiated by client device drivers.
+@publishedPartner
+@released
+*/
+
+class TDmaSgChannel : public TDmaChannel
+	{
+private:
+	virtual void DoQueue(DDmaRequest& aReq);
+	virtual void DoCancelAll();
+	virtual void DoUnlink(SDmaDesHdr& aHdr);
+	virtual void DoDfc(DDmaRequest& aCurReq, SDmaDesHdr*& aCompletedHdr);
+private:
+	TBool iTransferring;
+	};
+
+
+//////////////////////////////////////////////////////////////////////////////
+// INTERFACE WITH TEST HARNESS
+//////////////////////////////////////////////////////////////////////////////
+
+/**
+Set of information used by test harness.
+@publishedPartner
+@released
+*/
+
+struct TDmaTestInfo
+	{
+	/** Maximum transfer size in bytes for all channels (ie. the minimum of all channels' maximum size)*/
+	TInt iMaxTransferSize;
+	/** 3->Memory buffers must be 4-byte aligned, 7->8-byte aligned, ... */
+	TUint iMemAlignMask;
+	/** Cookie to pass to DDmaRequest::Fragment for memory-memory transfer*/
+	TUint32 iMemMemPslInfo;
+	/** Number of test single-buffer channels */
+	TInt iMaxSbChannels;
+	/** Pointer to array containing single-buffer test channel ids */
+	TUint32* iSbChannels;
+	/** Number of test double-buffer channels */
+	TInt iMaxDbChannels;
+	/** Pointer to array containing double-buffer test channel ids */
+	TUint32* iDbChannels;
+	/** Number of test scatter-gather channels */
+	TInt iMaxSgChannels;
+	/** Pointer to array containing scatter-gather test channel ids */
+	TUint32* iSgChannels;
+	};
+
+
+/**
+Provides access to test information structure stored in the PSL.
+
+Must be implemented by the PSL.
+@publishedPartner
+@released
+*/
+
+IMPORT_C const TDmaTestInfo& DmaTestInfo();
+
+
+//////////////////////////////////////////////////////////////////////////////
+
+#include <drivers/dma.inl>
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/kernel/eka/include/drivers/dma.inl	Tue May 25 14:09:55 2010 +0300
@@ -0,0 +1,148 @@
+// Copyright (c) 2002-2010 Nokia Corporation and/or its subsidiary(-ies).
+// All rights reserved.
+// This component and the accompanying materials are made available
+// under the terms of "Eclipse Public License v1.0""
+// which accompanies this distribution, and is available
+// at the URL "http://www.eclipse.org/legal/epl-v10.html".
+//
+// Initial Contributors:
+// Nokia Corporation - initial contribution.
+//
+// Contributors:
+//
+// Description:
+// include/drivers/dma.inl
+// DMA framework public inline functions
+// This file should not be modified when porting the DMA framework to
+// new hardware.
+//
+// WARNING: This file contains some APIs which are internal and are subject
+//          to change without noticed. Such APIs should therefore not be used
+//          outside the Kernel and Hardware Services package.
+//
+
+// TDmaChannel
+
+inline void TDmaChannel::Wait()
+	{
+	NKern::FMWait(&iLock);
+	}
+
+inline void TDmaChannel::Signal()
+	{
+	NKern::FMSignal(&iLock);
+	}
+
+inline TBool TDmaChannel::Flash()
+	{
+	return NKern::FMFlash(&iLock);
+	}
+
+inline TBool TDmaChannel::IsOpened() const
+	{
+	return iController != NULL;
+	}
+
+inline TBool TDmaChannel::IsQueueEmpty() const
+	{
+	return const_cast<TDmaChannel*>(this)->iReqQ.IsEmpty();
+	}
+
+inline TUint32 TDmaChannel::PslId() const
+	{
+	return iPslId;
+	}
+
+inline TInt TDmaChannel::FailNext(TInt /*aFragmentCount*/)
+	{
+	return iController->FailNext(*this);
+	}
+
+inline TInt TDmaChannel::MissNextInterrupts(TInt aInterruptCount)
+	{
+	return iController->MissNextInterrupts(*this, aInterruptCount);
+	}
+
+/** Function allowing platform-specific layer to extend API with new
+	channel-specific operations.
+ 	@param aCmd Command identifier.  Negative values are reserved for Symbian use.
+	@param aArg PSL-specific
+	@return KErrNotSupported if aCmd is not supported.  PSL-specific value otherwise.
+ */
+
+inline TInt TDmaChannel::Extension(TInt aCmd, TAny* aArg)
+	{
+	return iController->Extension(*this, aCmd, aArg);
+	}
+
+inline const TDmac* TDmaChannel::Controller() const
+	{
+	return iController;
+	}
+
+inline TInt TDmaChannel::MaxTransferSize(TUint aFlags, TUint32 aPslInfo)
+	{
+	return iController->MaxTransferSize(*this, aFlags, aPslInfo);
+	}
+
+inline TUint TDmaChannel::MemAlignMask(TUint aFlags, TUint32 aPslInfo)
+	{
+	return iController->MemAlignMask(*this, aFlags, aPslInfo);
+	}
+
+// DDmaRequest
+
+/** Called when request is removed from request queue in channel */
+
+inline void DDmaRequest::OnDeque()
+	{
+	iQueued = EFalse;
+	iLastHdr->iNext = NULL;
+	iChannel.DoUnlink(*iLastHdr);
+	}
+
+// TDmac
+
+inline void TDmac::Wait()
+	{
+	NKern::FMWait(&iLock);
+	}
+
+inline void TDmac::Signal()
+	{
+	NKern::FMSignal(&iLock);
+	}
+
+inline SDmaPseudoDes& TDmac::HdrToDes(const SDmaDesHdr& aHdr) const
+	{
+	return static_cast<SDmaPseudoDes*>(iDesPool)[&aHdr - iHdrPool];
+	}
+
+inline TAny* TDmac::HdrToHwDes(const SDmaDesHdr& aHdr) const
+	{
+	return static_cast<TUint8*>(iDesPool) + iDesSize*(&aHdr - iHdrPool);
+	}
+
+inline TUint32 TDmac::DesLinToPhys(TAny* aDes) const
+	{
+#ifdef __WINS__
+	(void)aDes;
+	return 0xDEADBEEF;
+#else
+	return iHwDesChunk->iPhysAddr + ((TLinAddr)aDes - iHwDesChunk->iLinAddr);
+#endif
+	}
+
+// DmaChannelMgr
+
+inline void DmaChannelMgr::Wait()
+	{
+	NKern::FMWait(&Lock);
+	}
+
+inline void DmaChannelMgr::Signal()
+	{
+	NKern::FMSignal(&Lock);
+	}
+
+//---
--- a/kernel/eka/include/drivers/dma_compat.inl	Tue May 11 17:28:22 2010 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,62 +0,0 @@
-// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
-// All rights reserved.
-// This component and the accompanying materials are made available
-// under the terms of "Eclipse Public License v1.0"
-// which accompanies this distribution, and is available
-// at the URL "http://www.eclipse.org/legal/epl-v10.html".
-//
-// Initial Contributors:
-// Nokia Corporation - initial contribution.
-//
-// Contributors:
-//
-// Description:
-// include/drivers/dma_compat.inl
-// DMA Framework - Client API definition.
-//
-// Inline implementations of functions which (originally) exposed DMA HAI
-// details that are now, after the header file split into dma_v2.h and
-// dma_hai.h, no longer meant to be visible to DMA clients. This file is only
-// included for DMA_APIV2 clients.
-//
-// This file is not meant to be a permanent one, and may eventually be removed
-// together with the deprecated functions it implements.
-//
-//
-
-
-inline const TDmac* TDmaChannel::Controller() const
-	{
-	return iController;
-	}
-
-static inline TUint32 RequestFlags2SrcConfigFlags(TUint aFlags)
-	{
-	TUint32 flags = (aFlags & KDmaMemSrc) ? KDmaMemAddr : 0;
-	flags |= (aFlags & KDmaPhysAddrSrc) ? KDmaPhysAddr : 0;
-	return flags;
-	}
-
-static inline TUint32 RequestFlags2DstConfigFlags(TUint aFlags)
-	{
-	TUint32 flags = (aFlags & KDmaMemDest) ? KDmaMemAddr : 0;
-	flags |= (aFlags & KDmaPhysAddrDest) ? KDmaPhysAddr : 0;
-	return flags;
-	}
-
-inline TInt TDmaChannel::MaxTransferSize(TUint aFlags, TUint32 aPslInfo)
-	{
-	TUint src_flags = RequestFlags2SrcConfigFlags(aFlags);
-	TUint dst_flags = RequestFlags2DstConfigFlags(aFlags);
-	return MaxTransferLength(src_flags, dst_flags, aPslInfo);
-	}
-
-inline TUint TDmaChannel::MemAlignMask(TUint aFlags, TUint32 aPslInfo)
-	{
-	TUint src_flags = RequestFlags2SrcConfigFlags(aFlags);
-	TUint dst_flags = RequestFlags2DstConfigFlags(aFlags);
-	return AddressAlignMask(src_flags, dst_flags, aPslInfo);
-	}
-
-
-// ---
--- a/kernel/eka/include/drivers/dma_hai.h	Tue May 11 17:28:22 2010 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,896 +0,0 @@
-// Copyright (c) 2002-2010 Nokia Corporation and/or its subsidiary(-ies).
-// All rights reserved.
-// This component and the accompanying materials are made available
-// under the terms of "Eclipse Public License v1.0"
-// which accompanies this distribution, and is available
-// at the URL "http://www.eclipse.org/legal/epl-v10.html".
-//
-// Initial Contributors:
-// Nokia Corporation - initial contribution.
-//
-// Contributors:
-//
-// Description:
-// include/drivers/dma_hai.h
-// DMA Framework - Symbian Hardware Abstraction Interface (SHAI).
-//
-//
-
-#ifndef __DMA_HAI_H__
-#define __DMA_HAI_H__
-
-
-#include <kernel/kern_priv.h>
-
-
-//////////////////////////////////////////////////////////////////////////////
-
-
-/** Interface used by PIL to open and close DMA channels.
-
-	Must be implemented by the PSL.
-
-	@publishedPartner
-	@released
-*/
-class DmaChannelMgr
-	{
-public:
-	/** Opens a channel using a client-provided identifier.
-
-		This function must be implemented by the PSL.
-
-		@param aOpenId PSL-specific magic cookie passed by client. This could
-		identify the channel exactly (by being just the channel number), or at
-		least sufficiently (for example for use with a certain peripheral), or
-		it may indicate some properties which the channel must possess. It may
-		be set to zero always if all channels are equivalent.
-
-		@param aDynChannel ETrue if the Open call is for a dynamic channel. A
-		dynamic channel is not exclusively reserved for just one client, and
-		further Open calls for more dynamic channels should succeed as long as
-		certain resources (but not including the number of available physical
-		channels) are not exceeded. Different transfer requests on this dynamic
-		channel may be serviced using different actual channels.
-
-		@param aPriority The desired channel priority as requested by the
-		client. This may be an actual hardware priority or a
-		platform-independent value. Not being able to satisfy the requested
-		value is not a reason for the PSL to return NULL. This parameter may be
-		ignored if aDynChannel is passed as ETrue. An overriding per-transfer
-		priority may be requested by a client later via
-		TDmaTransferArgs::iChannelPriority.
-		@see SDmacCaps::iChannelPriorities
-		@see TDmaPriority
-
-		@return Pointer to channel if available, NULL otherwise. It should not
-		be NULL if the Open call was for a dynamic channel unless a processing
-		error occurred.
-
-		@pre The PIL calls this function with a global fast mutex held to avoid
-		race conditions.
-
-		@post If a non-NULL pointer is returned, the object pointed to has its
-		iController, iDmacCaps, iPslId, iDynChannel and iPriority members set
-		to valid states.
-
-		iController should point to the controller handling the
-		channel.
-
-		iDmacCaps should point to a SDmacCaps structure containing values
-		relating to this particular channel.
-
-		iPslId should contain a value uniquely identifying the channel - the
-		PIL assigns this value later during request fragmentation to
-		TDmaTransferArgs::iChannelCookie. It can be given any convenient value
-		by the PSL (channel index, I/O port address, etc.).
-
-		iDynChannel should be set to ETrue by the PSL if a dynamic channel was
-		requested and has been opened.
-
-		If applicable, iPriority should contain the actual hardware priority
-		that has been configured or reserved. Otherwise it may be left at its
-		default value TDmaPriority::KDmaPriorityNone.
-	*/
-	static TDmaChannel* Open(TUint32 aOpenId, TBool aDynChannel, TUint aPriority);
-
-	/** Performs platform-specific operations when a channel is closed.
-
-		If aChannel was opened as a dynamic channel then this call is a sign
-		that there is a client which does not intend to queue any further
-		transfer requests via this channel.
-
-		This function must be implemented by the PSL but the implementation can
-		be a no-op.
-
-		@param aChannel The channel to close
-
-		@pre The PIL calls this function with a global fast mutex held to avoid
-		race conditions.
-	*/
-	static void Close(TDmaChannel* aChannel);
-
-	/** Function allowing PSL to extend DMA API with new channel-independent
-		operations.
-
-		This function must be implemented by the PSL.
-
-		@param aCmd Command identifier. Negative values are reserved for FW
-		internal use.
-
-		@param aArg PSL-specific
-
-		@return KErrNotSupported if aCmd is not supported. PSL-specific value
-		otherwise.
-	 */
-	static TInt StaticExtension(TInt aCmd, TAny* aArg);
-
-	/** Acquires the channel manager lock. Called by the PIL before opening and
-		closing a channel.
-	*/
-	static void Wait();
-
-	/** Releases the channel manager lock. Called by the PIL after opening and
-		closing a channel.
-	*/
-	static void Signal();
-
-private:
-	/** Declared, defined, and called by PSL's DECLARE_STANDARD_EXTENSION(). */
-	friend TInt InitExtension();
-
-	/** Must be called in the DMA DLL entry point. */
-	static TInt Initialise();
-
-	static NFastMutex Lock;
-	};
-
-
-//////////////////////////////////////////////////////////////////////////////
-
-
-/** Abstract base class representing a DMA controller.
-
-	The class has two purposes.
-
-	First, it is a container for channels, descriptors and descriptor headers.
-
-	Second, it exposes a set of virtual functions implemented by the PSL
-	(platform-specific layer).
-
-	These functions are the main interfaces between the PIL
-	(platform-independent layer) and PSL.
-
-	@publishedPartner
-	@released
-*/
-class TDmac
-	{
-	friend class DmaChannelMgr;
-
-protected:
-	/** Data required for creating a new instance */
-	struct SCreateInfo
-		{
-		/** True if DMAC uses hardware descriptors (i.e. supports
-			scatter/gather mode).
-		*/
-		TBool iCapsHwDes;
-		/** Initial maximum number of descriptors and headers (shared by all
-			channels) to be allocated by the PIL. If at run time more
-			descriptors are needed then they will be dynamically allocated and
-			added to the available pool.
-
-			The PSL may consider a number of factors when providing this
-			initial value, such as the number of channels on this controller,
-			the maximum transfer size per descriptor and also likely usage
-			scenarios for the platform or device (number of drivers using DMA,
-			their traffic patterns, simultaneity of operations, etc.).
-		*/
-		TInt iDesCount;
-		/** Size of individual descriptors. Use sizeof(TDmaTransferArgs) for
-		 	single-buffer and double-buffer (i.e. non-s/g) controllers.
-		*/
-		TInt iDesSize;
-		/** Bitmask used when creating the memory chunk storing the descriptor
-			pool. Used only for hardware descriptors.
-
-			The access part must be EMapAttrSupRw. If the chunk is cached
-			and/or buffered, the PSL must flush the data cache and/or drain the
-			write buffer in InitHwDes() and related functions.
-
-			The physical start address of the chunk will always be MMU page
-		 	size aligned.
-
-		 	@see TMappingAttributes
-		 */
-		TUint iDesChunkAttribs;
-		};
-
-	/** Base class constructor. */
-	TDmac(const SCreateInfo& aInfo);
-
-	/** Base class 2nd-phase constructor. */
-	TInt Create(const SCreateInfo& aInfo);
-
-public:
-	/** Base class virtual destructor. */
-	virtual ~TDmac();
-
-	/** Allocates a number of headers (and hence also descriptors) from the
-		header/descriptor pools. Called by the PIL but may also be used by the
-		PSL.
-	*/
-	TInt ReserveSetOfDes(TInt aCount);
-
-	/** Returns previously allocated headers (and hence also descriptors) to
-		the header/descriptor pools. Called by the PIL but may also be used by
-		the PSL.
-	*/
-	void ReleaseSetOfDes(TInt aCount);
-
-	/** Called by the PIL during request fragmentation to fill a descriptor or
-		pseudo descriptor with transfer arguments.
-	*/
-	TInt InitDes(const SDmaDesHdr& aHdr, const TDmaTransferArgs& aTransferArgs);
-
-	/** Called by the PIL in TDmaChannel::IsrRedoRequest() if any of the
-		latter's arguments is non-zero.
-	*/
-	TInt UpdateDes(const SDmaDesHdr& aHdr, TUint32 aSrcAddr, TUint32 aDstAddr,
-				   TUint aTransferCount, TUint32 aPslRequestInfo);
-
-	/** Returns a reference to the associated pseudo descriptor for a given
-		descriptor header. For use by PIL and PSL.
-	*/
-	inline TDmaTransferArgs& HdrToDes(const SDmaDesHdr& aHdr) const;
-
-	/** Returns a reference to the associated hardware descriptor for a given
-		descriptor header. For use by PIL and PSL.
-	*/
-	inline TAny* HdrToHwDes(const SDmaDesHdr& aHdr) const;
-
-	/** Returns the physical address of the hardware descriptor
-		pointed to by aDes. For use by PIL and PSL.
-	*/
-	inline TUint32 HwDesLinToPhys(TAny* aDes) const;
-
-	/** Called by the PIL to acquire the controller lock which protects the
-		header and descriptor pools.
-	*/
-	inline void Wait();
-
-	/** Called by the PIL to release the controller lock which protects the
-		header and descriptor pools.
-	*/
-	inline void Signal();
-
-public:
-	/** Called by PIL when one fragment (single-buffer and double-buffer DMACs)
-		or list of fragments (scatter/gather DMAC) is to be transferred.
-
-		Called when initiating a new transfer and also, for double-buffer
-		DMACs, for configuring the next fragment to transfer while the current
-		one is ongoing.
-
-		The function must be implemented by the PSL if
-		SCreateInfo::iCaps::iAsymHwDescriptors is reported as false.
-
-		@note This function may be called in thread or ISR context by the PIL
-
-		@param aChannel The channel to use.
-		@param aHdr Header associated with fragment to transfer.
-	*/
-	virtual void Transfer(const TDmaChannel& aChannel, const SDmaDesHdr& aHdr);
-
-	/** Called by PIL when two lists of fragments (scatter/gather DMAC with
-		asymmetrical linked-list capability) are to be transferred.
-
-		Called when initiating a new transfer.
-
-		The function must be implemented by the PSL if
-		SDmaCaps::iAsymHwDescriptors is reported as true.
-
-		@note This function may be called in thread or ISR context by the PIL
-
-		@param aChannel The channel to use.
-		@param aSrcHdr Header associated with descriptor to transfer on the
-		source side.
-		@param aDstHdr Header associated with descriptor to transfer on the
-		destination side.
-	*/
-	virtual void Transfer(const TDmaChannel& aChannel, const SDmaDesHdr& aSrcHdr,
-						  const SDmaDesHdr& aDstHdr);
-
-	/** Called by PIL to stop a transfer on a given channel.
-
-		The stopping must occur synchronously as the PIL assumes the channel
-		is halted after calling this function. A channel stopped via this
-		function is not intended to be resumed. Function must always be
-		implemented by the PSL.
-
-		@param aChannel The channel to stop
-		@post The channel will be idle
-		@post No interrupt will occur from this channel until a new
-		request is queued.
-	*/
-	virtual void StopTransfer(const TDmaChannel& aChannel) = 0;
-
-	/** Called by PIL to pause (suspend) a transfer on a given channel.
-
-		A paused channel transfer must be able to be resumed by calling
-		ResumeTransfer().
-
-		The function must be implemented by the PSL if
-		SDmacCaps::iChannelPauseAndResume is reported as true.
-
-		@return KErrNone if the transfer has been paused successfully,
-		KErrCompletion if the transfer was already paused, KErrGeneral
-		if a general error occurred preventing a successful outcome.
-
-		@post No interrupt will occur from this channel until it is
-		resumed.
-	 */
-	virtual TInt PauseTransfer(const TDmaChannel& aChannel);
-
-	/** Called by PIL to resume a paused (suspended) transfer on a given
-		channel.
-
-		Resume() can be called when the transfer is paused as a result of a
-		previous call to PauseTransfer() or because the DMAC has encountered a
-		Pause bit in a H/W descriptor.
-
-		The function must be implemented by the PSL if
-		SDmacCaps::iChannelPauseAndResume is reported as true.
-
-		@return KErrNone if the transfer has been resumed successfully,
-		KErrCompletion if there was no paused transfer, KErrGeneral
-		if a general error occurred preventing a successful outcome.
-	 */
-	virtual TInt ResumeTransfer(const TDmaChannel& aChannel);
-
-	/** Called by PIL to check whether a DMA channel is idle.
-
-		'Idle' here means that the channel is ultimately stopped, for example
-		because the transfer has finished, or an error was encountered, or it
-		was manually stopped, but not because it was manually suspended (aka
-		'paused'), or it is waiting for a request line assertion to start the
-		transfer.
-
-		@param aChannel The channel to test
-
-		@return ETrue if channel idle, EFalse if transferring.
-	*/
-	virtual TBool IsIdle(const TDmaChannel& aChannel) = 0;
-
-	/** Called by PIL to retrieve from the PSL the maximum transfer length
-		based on the parameters passed.
-
-		@param aChannel Channel to be used for the transfer
-		@param aSrcFlags Bitmask characterising transfer source
-		@see TDmaTransferArgs::iSrcConfig::iFlags
-		@param aDstFlags Bitmask characterising transfer destination
-		@see TDmaTransferArgs::iDstConfig::iFlags
-		@param aPslInfo Cookie passed by client and used by the PSL
-		@see TDmaTransferArgs::iPslRequestInfo
-
-		@return 0 if transfer length is not limited, the maximum transfer
-		length in bytes otherwise.
-	*/
-	virtual TUint MaxTransferLength(TDmaChannel& aChannel, TUint aSrcFlags,
-									TUint aDstFlags, TUint32 aPslInfo) = 0;
-
-	/** Called by PIL to retrieve from the PSL the memory alignment mask based
-		on the parameters passed. Some DMA controllers impose alignment
-		constraints on the base address of memory buffers. This mask is AND'ed
-		against memory addresses computed during fragmentation.
-
-		The PIL will call this function separately for source and destination.
-
-		An assumption is that the PSL doesn't need to know if a call to this
-		function is for the source or the destination side, i.e. both ports
-		are, as far as the alignment is concerned, equivalent. All that matters
-		are the values of the relevant configuration parameters.
-
-		Another assumption is that the alignment requirement for a port on a
-		DMAC with potentially different values for source and destination does
-		not depend on the configuration of the respective other port.
-
-		@param aChannel Channel used for the transfer
-		@param aTargetFlags Bitmask characterising transfer source or
-		destination
-		@see TDmaTransferArgs::iSrcConfig::iFlags
-		@see TDmaTransferArgs::iDstConfig::iFlags
-		@param aElementSize Element size used for the transfer. May be zero if
-		not known or 'don't care'.
-		@param aPslInfo Cookie passed by client and used by the PSL
-		@see TDmaTransferArgs::iPslRequestInfo
-
-		@return A value representing the alignment mask (e.g. 3 if buffer must
-		be 4-byte aligned)
-	*/
-	virtual TUint AddressAlignMask(TDmaChannel& aChannel, TUint aTargetFlags,
-								   TUint aElementSize, TUint32 aPslInfo) = 0;
-
-	/** Called by PIL during fragmentation to initialise a hardware descriptor.
-
-		The PSL must assume the descriptor is the last in the chain and so set
-		the interrupt bit and set the next descriptor field to an end of chain
-		marker.
-
-		The function must be implemented by the PSL if and only if the DMAC
-		supports hardware descriptors and SDmaCaps::iAsymHwDescriptors is
-		reported as false.
-
-		@param aHdr Header associated with the hardware descriptor to
-		initialise
-		@param aTransferArgs The transfer parameters for this descriptor
-
-		@return KErrNone if the descriptor was successfully initialized,
-		KErrArgument if any of the transfer arguments were detected to be
-		invalid, KErrGeneral if a general error occurred preventing a
-		successful outcome.
-	*/
-	virtual TInt InitHwDes(const SDmaDesHdr& aHdr, const TDmaTransferArgs& aTransferArgs);
-
-	/** Called by PIL during fragmentation to initialise a hardware descriptor
-		on the source side of an asymmetric linked list.
-
-		The function must be implemented by the PSL if
-		SDmaCaps::iAsymHwDescriptors is reported as true.
-
-		@param aHdr Header associated with the hardware descriptor to
-		initialise
-		@param aTransferArgs The transfer parameters for this descriptor. Only
-		the elements relating to the source side should be relevant to the
-		implementation.
-
-		@return KErrNone if the descriptor was successfully initialized,
-		KErrArgument if any of the transfer arguments were detected to be
-		invalid, KErrGeneral if a general error occurred preventing a
-		successful outcome.
-	*/
-	virtual TInt InitSrcHwDes(const SDmaDesHdr& aHdr, const TDmaTransferArgs& aTransferArgs);
-
-	/** Called by PIL during fragmentation to initialise a hardware descriptor
-		on the destination side of an asymmetric linked list.
-
-		The function must be implemented by the PSL if
-		SDmaCaps::iAsymHwDescriptors is reported as true.
-
-		@param aHdr Header associated with the hardware descriptor to
-		initialise
-		@param aTransferArgs The transfer parameters for this descriptor. Only
-		the elements relating to the destination side should be relevant to the
-		implementation.
-
-		@return KErrNone if the descriptor was successfully initialized,
-		KErrArgument if any of the transfer arguments were detected to be
-		invalid, KErrGeneral if a general error occurred preventing a
-		successful outcome.
-	*/
-	virtual TInt InitDstHwDes(const SDmaDesHdr& aHdr, const TDmaTransferArgs& aTransferArgs);
-
-	/** Called by the PIL in ISR context to change specific fields in a
-		hardware descriptor.
-
-		The function must be implemented by the PSL if and only if the DMAC
-		supports hardware descriptors and SDmaCaps::iAsymHwDescriptors is
-		reported as false.
-
-		@param aHdr Header associated with the hardware descriptor to be
-		updated
-		@param aSrcAddr @see TDmaTransferArgs::iSrcConfig::iAddr
-		@param aDstAddr @see TDmaTransferArgs::iDstConfig::iAddr
-		@param aTransferCount @see TDmaTransferArgs::iTransferCount
-		@param aPslRequestInfo @see TDmaTransferArgs::iPslRequestInfo
-
-		Since Epoc::LinearToPhysical() cannot be called in ISR context the
-		addresses passed into this function are always physical ones, i.e.
-		TDmaTransferFlags::KDmaPhysAddr is implied.
-
-		@return KErrNone if the descriptor was successfully modified,
-		KErrArgument if any of the transfer arguments were detected to be
-		invalid, KErrGeneral if a general error occurred preventing a
-		successful outcome.
-	*/
-	virtual TInt UpdateHwDes(const SDmaDesHdr& aHdr, TUint32 aSrcAddr, TUint32 aDstAddr,
-							 TUint aTransferCount, TUint32 aPslRequestInfo);
-
-	/** Called by the PIL in ISR context to change specific fields in a
-		hardware descriptor.
-
-		The function must be implemented by the PSL if
-		SDmaCaps::iAsymHwDescriptors is reported as true.
-
-		@param aHdr Header associated with the hardware descriptor to be
-		updated
-		@param aSrcAddr @see TDmaTransferArgs::iSrcConfig::iAddr
-		@param aTransferCount @see TDmaTransferArgs::iTransferCount
-		@param aPslRequestInfo @see TDmaTransferArgs::iPslRequestInfo
-
-		Since Epoc::LinearToPhysical() cannot be called in ISR context the
-		address passed into this function is always a physical ones, i.e.
-		TDmaTransferFlags::KDmaPhysAddr is implied.
-
-		@return KErrNone if the descriptor was successfully modified,
-		KErrArgument if any of the transfer arguments were detected to be
-		invalid, KErrGeneral if a general error occurred preventing a
-		successful outcome.
-	*/
-	virtual TInt UpdateSrcHwDes(const SDmaDesHdr& aHdr, TUint32 aSrcAddr,
-								TUint aTransferCount, TUint32 aPslRequestInfo);
-
-	/** Called by the PIL in ISR context to change specific fields in a
-		hardware descriptor.
-
-		The function must be implemented by the PSL if
-		SDmaCaps::iAsymHwDescriptors is reported as true.
-
-		@param aHdr Header associated with the hardware descriptor to be
-		updated
-		@param aDstAddr @see TDmaTransferArgs::iDstConfig::iAddr
-		@param aTransferCount @see TDmaTransferArgs::iTransferCount
-		@param aPslRequestInfo @see TDmaTransferArgs::iPslRequestInfo
-
-		Since Epoc::LinearToPhysical() cannot be called in ISR context the
-		address passed into this function is always a physical ones, i.e.
-		TDmaTransferFlags::KDmaPhysAddr is implied.
-
-		@return KErrNone if the descriptor was successfully modified,
-		KErrArgument if any of the transfer arguments were detected to be
-		invalid, KErrGeneral if a general error occurred preventing a
-		successful outcome.
-	*/
-	virtual TInt UpdateDstHwDes(const SDmaDesHdr& aHdr, TUint32 aDstAddr,
-								TUint aTransferCount, TUint32 aPslRequestInfo);
-
-	/** Called by PIL, when fragmenting a request, to append a new hardware
-		descriptor to an existing descriptor chain. May also be called by
-		clients who wish to create their own descriptor chains.
-
-		Must clear the interrupt bit of the descriptor associated with aHdr.
-
-		The function must be implemented by the PSL if and only if the DMAC
-		supports hardware descriptors.
-
-		@param aHdr Header associated with last fragment in chain
-		@param aNextHdr Header associated with fragment to append
-	*/
-	virtual void ChainHwDes(const SDmaDesHdr& aHdr, const SDmaDesHdr& aNextHdr);
-
-	/** Called by PIL when queuing a new request while the channel is running.
-
-		Must append the first hardware descriptor of the new request to the
-		last descriptor in the existing chain.
-
-		The function must be implemented by the PSL if and only if the DMAC
-		supports hardware descriptors.
-
-		@param aChannel The channel where the transfer takes place
-		@param aLastHdr Header associated with last hardware descriptor in
-		chain
-		@param aNewHdr Header associated with first hardware descriptor in new
-		request
-	*/
-	virtual void AppendHwDes(const TDmaChannel& aChannel, const SDmaDesHdr& aLastHdr,
-							 const SDmaDesHdr& aNewHdr);
-
-	/** Called by PIL when queuing a new request while the channel is running.
-
-		Must append the first hardware descriptor of the new request to the
-		last descriptor in the existing chain.
-
-		The function must be implemented by the PSL if
-		SDmaCaps::iAsymHwDescriptors is reported as true.
-
-		@param aChannel The channel where the transfer takes place
-		@param aSrcLastHdr Header associated with the last descriptor in the
-		source side chain
-		@param aSrcNewHdr Header associated with the first source side
-		descriptor of the new request
-		@param aDstLastHdr Header associated with the last descriptor in the
-		destination side chain
-		@param aDstNewHdr Header associated with the first destination side
-		descriptor of the new request
-	*/
-	virtual void AppendHwDes(const TDmaChannel& aChannel,
-							 const SDmaDesHdr& aSrcLastHdr, const SDmaDesHdr& aSrcNewHdr,
-							 const SDmaDesHdr& aDstLastHdr, const SDmaDesHdr& aDstNewHdr);
-
-	/** Called by PIL when completing or cancelling a request to cause the PSL
-		to unlink the last item in the h/w descriptor chain from a subsequent
-		chain that it was possibly linked to.
-
-		The function must be implemented by the PSL if and only if the DMAC
-		supports hardware descriptors.
-
-		@param aChannel The channel where the request (and thus the descriptor)
-		was queued
-		@param aHdr Header associated with last h/w descriptor in
-		completed / cancelled chain
-	*/
-	virtual void UnlinkHwDes(const TDmaChannel& aChannel, SDmaDesHdr& aHdr);
-
-	/** Called by PIL when freeing descriptors back to the shared pool in
-		FreeDesList(). The PSL inside ClearHwDes() can clear the contents of
-		the h/w descriptor.
-
-		This may be necessary if the PSL implementation uses the h/w descriptor
-		as another header which in turn points to the actual DMA h/w descriptor
-		(aka LLI).
-
-		The function may be implemented by the PSL if the DMAC supports
-		hardware descriptors.
-
-		@param aHdr Header associated with the h/w descriptor being freed.
-	 */
-	virtual void ClearHwDes(const SDmaDesHdr& aHdr);
-
-	/** Called by PIL to logically link two physical channels.
-
-		The function must be implemented by the PSL if the DMAC supports
-		logical channel linking.
-
-		@see SDmacCaps::iChannelLinking
-
-		@param a1stChannel The channel which is to be linked to another channel
-		@param a2ndChannel The channel the first one is to be linked to
-
-		@return KErrNone if the two channels have been linked successfully,
-		KErrCompletion if a1stChannel was already linked to a2ndChannel,
-		KErrArgument if a1stChannel was already linked to a different channel,
-		KErrGeneral if a general error occurred preventing a successful
-		outcome. The default PIL implementation returns KErrNotSupported.
-	 */
-	virtual TInt LinkChannels(TDmaChannel& a1stChannel, TDmaChannel& a2ndChannel);
-
-	/** Called by PIL to logically unlink a physical channel from its linked-to
-		successor.
-
-		The function must be implemented by the PSL if the DMAC supports
-		logical channel linking.
-
-		@see SDmacCaps::iChannelLinking
-
-		@param aChannel The channel which is to be unlinked from its successor
-
-		@return KErrNone if the channel has been unlinked successfully,
-		KErrCompletion if the channel was not linked to another channel,
-		KErrGeneral if a general error occurred preventing a successful
-		outcome. The default PIL implementation returns KErrNotSupported.
-	 */
-	virtual TInt UnlinkChannel(TDmaChannel& aChannel);
-
-	/** Called by a test harness to force an error when the next fragment is
-		transferred.
-
-		Must be implemented by the PSL only if possible.
-
-		@param aChannel The channel where the error is to occur.
-
-		@return KErrNone if implemented. The default PIL implementation
-		returns KErrNotSupported.
-	*/
-	virtual TInt FailNext(const TDmaChannel& aChannel);
-
-	/** Called by a test harness to force the DMA controller to miss one or
-		more interrupts.
-
-		The function must be implemented by the PSL only if possible.
-
-		@param aChannel The channel where the error is to occur
-		@param aInterruptCount The number of interrupt to miss.
-
-		@return KErrNone if implemented. The default PIL implementation
-		returns KErrNotSupported.
-	*/
-	virtual TInt MissNextInterrupts(const TDmaChannel& aChannel, TInt aInterruptCount);
-
-	/** Function allowing platform-specific layer to extend channel API with
-		new channel-specific operations.
-
-		@see TDmaChannel::ChannelExtension
-
-		@param aChannel Channel to operate on
-		@param aCmd Command identifier. Negative values are reserved for use by
-		Nokia.
-		@param aArg PSL-specific argument
-
-		@return KErrNotSupported if aCmd is not supported. PSL-specific value
-		otherwise.
-	*/
-	virtual TInt Extension(TDmaChannel& aChannel, TInt aCmd, TAny* aArg);
-
-	/** Called by the PIL to query the number of elements that have so far been
-		transferred by the hardware descriptor associated with aHdr at the
-		source port.
-
-		If SDmacCaps::iAsymHwDescriptors is true then the PIL will call this
-		function only for source-side descriptors, and the PSL should fault the
-		kernel if this is not the case.
-
-		The function must be implemented (i.e. overridden) by the PSL if and
-		only if the DMAC supports hardware descriptors.
-
-		@param aHdr Descriptor header associated with the hardware descriptor
-		to be queried
-
-		@return The number of elements that have been transferred by the
-		hardware descriptor associated with aHdr at the source port
-	*/
-	virtual TUint32 HwDesNumSrcElementsTransferred(const SDmaDesHdr& aHdr);
-
-	/** Called by the PIL to query the number of elements that have so far been
-		transferred by the hardware descriptor associated with aHdr at the
-		destination port.
-
-		If SDmacCaps::iAsymHwDescriptors is true then the PIL will call this
-		function only for destination-side descriptors, and the PSL should
-		panic if this is not the case.
-
-		The function must be implemented (i.e. overridden) by the PSL if and
-		only if the DMAC supports hardware descriptors.
-
-		@param aHdr Descriptor header associated with the hardware descriptor
-		to be queried
-
-		@return The number of elements that have been transferred by the
-		hardware descriptor associated with aHdr at the destination port
-	*/
-	virtual TUint32 HwDesNumDstElementsTransferred(const SDmaDesHdr& aHdr);
-
-protected:
-	/** Called by the PSL in interrupt context upon a channel interrupt event.
-
-		@param aChannel The channel the ISR relates to
-		@param aEventMask Bitmask of one or more TDmaCallbackType values
-		@param aIsComplete Set to ETrue if no error was encountered
-	 */
-	static void HandleIsr(TDmaChannel& aChannel, TUint aEventMask, TBool aIsComplete);
-
-private:
-	/** Called in Create() */
-	TInt AllocDesPool(TUint aAttribs);
-
-	/** Called in ~TDmac() */
-	void FreeDesPool();
-
-private:
-	NFastMutex iLock;			 // protect descriptor reservation and allocation
-	const TInt iMaxDesCount;	 // initial number of descriptors and headers
-	TInt iAvailDesCount;		 // current available number of descriptors and headers
-	SDmaDesHdr* iHdrPool;		 // descriptor header dynamic array
-#ifndef __WINS__
-	DPlatChunkHw* iHwDesChunk;	 // chunk for hardware descriptor pool
-#endif
-	TAny* iDesPool;				 // hardware or pseudo descriptor dynamic array
-	const TInt iDesSize;		 // descriptor size in bytes
-
-public:
-	const TBool iCapsHwDes;		 /*< True if DMAC uses h/w descriptors */
-	SDmaDesHdr* iFreeHdr;		 /*< head of unallocated descriptors linked list */
-
-#ifdef _DEBUG
-	/** Tests whether aHdr points into the descriptor header array. */
-	TBool IsValidHdr(const SDmaDesHdr* aHdr);
-#endif
-	__DMA_DECLARE_INVARIANT
-	};
-
-
-//////////////////////////////////////////////////////////////////////////////
-
-
-/** Single-buffer DMA channel.
-
-	Can be instantiated or further derived by the PSL.
-
-	@publishedPartner
-	@released
-*/
-class TDmaSbChannel : public TDmaChannel
-	{
-private:
-	virtual void DoQueue(const DDmaRequest& aReq);
-	virtual void DoCancelAll();
-	virtual void DoDfc(const DDmaRequest& aCurReq, SDmaDesHdr*& aCompletedHdr);
-private:
-	enum {EIdle = 0, ETransferring} iState;
-	};
-
-
-/** Double-buffer DMA channel.
-
-	Can be instantiated or further derived by the PSL.
-
-	@publishedPartner
-	@released
-*/
-class TDmaDbChannel : public TDmaChannel
-	{
-private:
-	virtual void DoQueue(const DDmaRequest& aReq);
-	virtual void DoCancelAll();
-	virtual void DoDfc(const DDmaRequest& aCurReq, SDmaDesHdr*& aCompletedHdr);
-private:
-	enum {EIdle = 0, ETransferring, ETransferringLast} iState;
-	};
-
-
-/** Scatter-gather DMA channel.
-
-	Can be instantiated or further derived by the PSL.
-
-	@publishedPartner
-	@released
-*/
-class TDmaSgChannel : public TDmaChannel
-	{
-private:
-	virtual void DoQueue(const DDmaRequest& aReq);
-	virtual void DoCancelAll();
-	virtual void DoUnlink(SDmaDesHdr& aHdr);
-	virtual void DoDfc(const DDmaRequest& aCurReq, SDmaDesHdr*& aCompletedHdr);
-private:
-	enum {EIdle = 0, ETransferring} iState;
-	};
-
-
-/** Scatter-gather DMA channel with asymmetric linked-lists.
-
-	Can be instantiated or further derived by the PSL.
-
-	@publishedPartner
-	@released
-*/
-class TDmaAsymSgChannel : public TDmaChannel
-	{
-private:
-	virtual void DoQueue(const DDmaRequest& aReq);
-	virtual void DoCancelAll();
-	virtual void DoUnlink(SDmaDesHdr& aHdr);
-	virtual void DoDfc(const DDmaRequest& aCurReq, SDmaDesHdr*& aSrcCompletedHdr,
-					   SDmaDesHdr*& aDstCompletedHdr);
-private:
-	SDmaDesHdr* iSrcCurHdr;		   // source fragment being transferred or NULL
-	SDmaDesHdr** iSrcNullPtr; // Pointer to NULL pointer following last source fragment
-	SDmaDesHdr* iDstCurHdr;	  // destination fragment being transferred or NULL
-	SDmaDesHdr** iDstNullPtr; // Pointer to NULL pointer following last destination fragment
-	enum {EIdle = 0, ETransferring} iState;
-	};
-
-
-//////////////////////////////////////////////////////////////////////////////
-
-// Trace macros intended for use by the DMA PSL
-#define DMA_PRINTF(MSG) __KTRACE_OPT(KDMA, Kern::Printf((MSG)))
-#define DMA_PRINTF1(MSG, ARG1) __KTRACE_OPT(KDMA, Kern::Printf((MSG), (ARG1)))
-#define DMA_PRINTF2(MSG, ARG1, ARG2) __KTRACE_OPT(KDMA, Kern::Printf((MSG), (ARG1), (ARG2)))
-
-#define DMA_PSL_MESG "DMA PSL: "
-
-// General PSL tracing
-#define DMA_PSL_TRACE(MSG) DMA_PRINTF(DMA_PSL_MESG MSG)
-#define DMA_PSL_TRACE1(MSG, ARG1) DMA_PRINTF1(DMA_PSL_MESG MSG, (ARG1))
-#define DMA_PSL_TRACE2(MSG, ARG1, ARG2) DMA_PRINTF2(DMA_PSL_MESG MSG, (ARG1), (ARG2))
-
-
-#define DMA_PSL_CHAN_MESG DMA_PSL_MESG "ChanId %d: "
-#define DMA_PSL_CHAN_ARGS(CHAN) ((CHAN).PslId())
-
-// For channel specific tracing (where CHAN is a TDmaChannel)
-#define DMA_PSL_CHAN_TRACE_STATIC(CHAN, MSG) DMA_PRINTF1(DMA_PSL_CHAN_MESG MSG, DMA_PSL_CHAN_ARGS(CHAN))
-#define DMA_PSL_CHAN_TRACE_STATIC1(CHAN, MSG, ARG1) DMA_PRINTF2(DMA_PSL_CHAN_MESG MSG, DMA_PSL_CHAN_ARGS(CHAN), (ARG1))
-
-// For channel specific tracing, for use within methods of TDmaChannel derived
-// class
-#define DMA_PSL_CHAN_TRACE(MSG) DMA_PSL_CHAN_TRACE_STATIC(*this, MSG)
-#define DMA_PSL_CHAN_TRACE1(MSG, ARG1) DMA_PSL_CHAN_TRACE_STATIC1(*this, MSG, (ARG1))
-
-
-
-#include <drivers/dma_hai.inl>
-
-
-#endif	// #ifndef __DMA_HAI_H__
--- a/kernel/eka/include/drivers/dma_hai.inl	Tue May 11 17:28:22 2010 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,54 +0,0 @@
-// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
-// All rights reserved.
-// This component and the accompanying materials are made available
-// under the terms of "Eclipse Public License v1.0"
-// which accompanies this distribution, and is available
-// at the URL "http://www.eclipse.org/legal/epl-v10.html".
-//
-// Initial Contributors:
-// Nokia Corporation - initial contribution.
-//
-// Contributors:
-//
-// Description:
-// include/drivers/dma_hai.inl
-// DMA Framework - Symbian Hardware Abstraction Interface (SHAI).
-//
-//
-
-
-// TDmac
-
-inline void TDmac::Wait()
-	{
-	NKern::FMWait(&iLock);
-	}
-
-inline void TDmac::Signal()
-	{
-	NKern::FMSignal(&iLock);
-	}
-
-inline TDmaTransferArgs& TDmac::HdrToDes(const SDmaDesHdr& aHdr) const
-	{
-	return static_cast<TDmaTransferArgs*>(iDesPool)[&aHdr - iHdrPool];
-	}
-
-inline TAny* TDmac::HdrToHwDes(const SDmaDesHdr& aHdr) const
-	{
-	return static_cast<TUint8*>(iDesPool) + iDesSize * (&aHdr - iHdrPool);
-	}
-
-inline TUint32 TDmac::HwDesLinToPhys(TAny* aDes) const
-	{
-#ifdef __WINS__
-	(void)aDes;
-	return 0xDEADBEEF;
-#else
-	return iHwDesChunk->iPhysAddr +
-		(reinterpret_cast<TLinAddr>(aDes) - iHwDesChunk->iLinAddr);
-#endif
-	}
-
-
-// ---
--- a/kernel/eka/include/drivers/dma_v1.h	Tue May 11 17:28:22 2010 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,860 +0,0 @@
-// Copyright (c) 2002-2010 Nokia Corporation and/or its subsidiary(-ies).
-// All rights reserved.
-// This component and the accompanying materials are made available
-// under the terms of "Eclipse Public License v1.0""
-// which accompanies this distribution, and is available
-// at the URL "http://www.eclipse.org/legal/epl-v10.html".
-//
-// Initial Contributors:
-// Nokia Corporation - initial contribution.
-//
-// Contributors:
-//
-// Description:
-// include/drivers/dma_v1.h
-// DMA Framework API v1
-//
-// NB: DMA clients should never include this file directly, but only ever the
-// generic header file <drivers/dma.h>.
-//
-
-#ifndef __DMA_H__
-#error "dma_v1.h must'n be included directly - use <drivers/dma.h> instead"
-#endif	// #ifndef __DMA_H__
-
-#ifndef __DMA_V1_H__
-#define __DMA_V1_H__
-
-#include <kernel/kern_priv.h>
-
-
-//////////////////////////////////////////////////////////////////////////////
-// Debug Support - KDmaPanicCat is defined in each source file
-
-#define __DMA_ASSERTD(e) __ASSERT_DEBUG(e, Kern::Fault(KDmaPanicCat, __LINE__))
-#define __DMA_ASSERTA(e) __ASSERT_ALWAYS(e, Kern::Fault(KDmaPanicCat, __LINE__))
-#ifdef _DEBUG
-#define __DMA_CANT_HAPPEN() Kern::Fault(KDmaPanicCat, __LINE__)
-#define __DMA_DECLARE_INVARIANT public: void Invariant();
-#define __DMA_INVARIANT() Invariant()
-#else
-#define __DMA_CANT_HAPPEN()
-#define __DMA_DECLARE_INVARIANT
-#define __DMA_INVARIANT()
-#endif
-
-
-//////////////////////////////////////////////////////////////////////////////
-// INTERFACE EXPOSED TO DEVICE-DRIVERS
-//////////////////////////////////////////////////////////////////////////////
-
-/**
-Bitmasks used for configuring a DMA request.
-
-In general, specify KDmaMemSrc|KDmaIncSrc (resp. KDmaMemDest|KDmaIncDest) if
-the source (resp. destination) is a memory buffer and clear
-KDmaMemSrc|KDmaIncSrc (resp. KDmaMemDest|KDmaIncDest) if the source
-(resp. destination) is a peripheral.
-
-If the location is given as a physical address (rather than a linear one)
-then also specify KDmaPhysAddrSrc and/or KDmaPhysAddrDest.
-
-The EKA1 "Fill Mode" can be implemented by omitting KDmaIncSrc.
-
-Some peripherals may require a post-increment address mode.
-
-@see DDmaRequest::Fragment
-@publishedPartner
-@released
-*/
-
-enum TDmaRequestFlags
-	{
-	/** Source is address of memory buffer */
-	KDmaMemSrc       = 0x01,
-	/** Destination is address of memory buffer */
-	KDmaMemDest      = 0x02,
-	/** Source address must be post-incremented during transfer */
-	KDmaIncSrc       = 0x04,
-	/** Destination address must be post-incremented during transfer */
-	KDmaIncDest      = 0x08,
-	/** Source address is a physical address (as opposed to a linear one) */
-	KDmaPhysAddrSrc  = 0x10,
-	/** Destination address is a physical address (as opposed to a linear one) */
-	KDmaPhysAddrDest = 0x20,
-	/** Request a different max transfer size (for instance for test purposes) */
-	KDmaAltTransferLen = 0x40
-	};
-
-
-//////////////////////////////////////////////////////////////////////////////
-
-class TDmaChannel;
-struct SDmaDesHdr;
-
-/** A DMA request is a list of fragments small enough to be transferred in one go
-	by the DMAC.
-
-	In general, fragmentation is done in the framework by calling Fragment() but
-	clients with special needs can allocate a blank descriptor list with
-	ExpandDesList() and customise it to fit their needs.
-
-	Clients should not set attributes directly, but should use the various functions
-	instead.
-
-	This class has not been designed to be called from several concurrent threads.
-	Multithreaded clients must implement their own locking scheme (via DMutex).
-
-	Fast mutexes are used internally to protect data structures accessed both
-	by the client thread and the DFC thread.  Therefore no fast mutex can be held
-	when calling a request function.
-
-	@publishedPartner
-	@released
- */
-class DDmaRequest : public DBase
-	{
-	friend class TDmaChannel;
-public:
-	/** The outcome of the transfer */
-	enum TResult {EBadResult=0, EOk, EError};
-	/** The signature of the completion/failure callback function */
-	typedef void (*TCallback)(TResult, TAny*);
-public:
-   
-    /**
-    Create a new transfer request. 
-
-    @param aChannel The channel this request is bound to.
-    @param aCb      Callback function called on transfer completion or failure (in channel
-                    DFC context).  Can be NULL.
-    @param aCbArg   Argument passed to callback function.
-    @param aMaxTransferSize Maximum fragment size.  If not specified, defaults to the maximum size
-           supported by the DMA controller for the type of transfer that is later scheduled.
-    */
-	IMPORT_C DDmaRequest(TDmaChannel& aChannel, TCallback aCb=NULL, TAny* aCbArg=NULL, TInt aMaxTransferSize=0);
-	
-	
-	/**
-    Destructor.
-
-    Assume the request is not being transferred or pending.
-    */
-	IMPORT_C ~DDmaRequest();
-	
-	
-	/**
-    Split request into a list of fragments small enough to be fed to the DMAC.
-
-    The size of each fragment is smaller than or equal to the maximum transfer size
-    supported by the DMAC.  If the source and/or destination is memory, each
-    fragment points to memory which is physically contiguous.
-
-    The kind of transfer to perform is specified via a set of flags used by a PIL
-    and a magic cookie passed to the PSL.  If the source (resp. destination) is a
-    peripheral, aSrc (resp. aDest) is treated as a magic cookie by the PIL and
-    passed straight to the PSL.
-
-    The request can be uninitialised or may have been fragmented previously.  The
-    previous configuration if any is lost whether or not the function succeeds.
-
-    @param aSrc     Source memory buffer linear address or peripheral magic cookie.
-    @param aDest    Destination memory buffer linear address or peripheral magic cookie.
-    @param aCount   Number of bytes to transfer.
-    @param aFlags   Bitmask characterising the transfer.
-    @param aPslInfo Hardware-specific information passed to PSL.
-
-    @return KErrNone if success. KErrArgument if aFlags and/or aPslInfo are invalid when finding
-    the maximum transfer size. May also fail if running out of descriptors.
-
-    @pre The request is not being transferred or pending.
-    @pre The various parameters must be valid.  The PIL or PSL will fault the
-    kernel if not.
-
-    @see TDmaRequestFlags
-    */
-	IMPORT_C TInt Fragment(TUint32 aSrc, TUint32 aDest, TInt aCount, TUint aFlags, TUint32 aPslInfo);
-	
-	
-	/**
-    Transfer asynchronously this request.
-
-    If this request's channel is idle, the request is transferred immediately.
-    Otherwise, it is queued and transferred later.
-
-    The client is responsible for ensuring cache consistency before and/or after the
-    transfer if necessary.
-    */
-	IMPORT_C void Queue();
-	
-
-    /**
-    Append new descriptor(s) to existing list.
-
-    Clients needing to build a custom descriptor list should call this function to
-    allocate the list and access the resulting list through iFirstHdr and iLastHdr.
-
-    Clients should not change the value of iFirstHdr, iLastHdr and the iNext field
-    of the descriptor headers to ensure descriptors can be deallocated. Clients
-    are free to change hardware descriptors, including chaining, in whatever way
-    suit them.
-
-    Assume the request is not being transferred or pending.
-
-    @param aCount Number of descriptors to append.
-
-    @return KErrNone or KErrTooBig if not enough descriptors available.
-    */
-	IMPORT_C TInt ExpandDesList(TInt aCount=1);
-	
-	
-	/**
-    Free resources associated with this request.
-
-    Assume the request is not being transferred or pending.
-    */
-	IMPORT_C void FreeDesList();
-private:
-	inline void OnDeque();
-public:
-	// WARNING: The following attributes are accessed both in client and DFC
-	// context and so accesses must be protected with the channel lock.
-	TDmaChannel& iChannel;		/**< The channel this request is bound to */
-	volatile TCallback iCb;		/**< Called on completion/failure (can be NULL) */
-	TAny* volatile iCbArg;		/**< Callback argument */
-	TInt iDesCount;				/**< The number of fragments in list */
-	SDmaDesHdr* iFirstHdr;		/**< The first fragment in the list (or NULL) */
-	SDmaDesHdr* iLastHdr;		/**< The last fragment in the list (or NULL) */
-	SDblQueLink iLink;			/**< The link on channel queue of pending requests */
-	TBool iQueued;				/**< Indicates whether request is pending or being transferred */
-	TInt iMaxTransferSize;		/**< Defaults to DMA controller max. transfer size */
-	__DMA_DECLARE_INVARIANT
-	};
-
-
-//////////////////////////////////////////////////////////////////////////////
-
-class TDmac;
-class DmaChannelMgr;
-
-/** DMA channel base class.
-
-	This class has not been designed to be called from several concurrent
-	client threads.  Multithreaded clients must implement their own locking
-	scheme (via DMutex).
-
-	Fast mutexes are used internally to protect data structures accessed both
-	by the client thread and the DFC one.  Therefore no fast mutex can be held
-	when calling a channel function.
-
-	Must be allocated in BSS because it relies on being zeroed at
-	creation-time.  If the PSL really needs to allocate channels on the kernel
-	heap, it must manually zero-initialises the instances.  This can be
-	achieved either by allocating raw memory and using placement new, or by
-	wrapping channels into a DBase-derived wrapper.
-
-	@publishedPartner
-	@released
- */
-class TDmaCancelInfo;
-class TDmaChannel
-	{
-	friend class DDmaRequest;
-	friend class TDmac;
-	friend class DmaChannelMgr;
-public:
-	/**  Information passed by client when opening channel */
-	struct SCreateInfo
-		{
-		/** Identifier used by PSL to select channel to open */
-		TUint32 iCookie;
-		/** Number of descriptors this channel can use */
-		TInt iDesCount;
-		/** DFC queue used to service DMA interrupts.  The DFC thread
-			priority must be higher than any client thread priority to
-			avoid a situation where a transfer completes while being
-			cancelled and another transfer is started before the DFC
-			thread gets a chance to run.  This would lead to a stray
-			DFC.
-		*/
-		TDfcQue* iDfcQ;
-		/** DFC priority */
-		TUint8 iDfcPriority;
-		};
-public:
-    /**
- 	Opens the DMA channel.
-
- 	Channel selection is done by the hardware-specific layer using a cookie passed in
- 	via aInfo.
-
- 	The client should not delete the returned pointer as the framework owns
- 	channel objects.  However, the client should explicitly close the channel when
- 	finished with it.
-
-	@param aInfo    Information passed by caller to select and configure channel.
- 	@param aChannel Point to open channel on successful return.  NULL otherwise.
-
- 	@return KErrNone or standard error code.
- 	*/
-	IMPORT_C static TInt Open(const SCreateInfo& aInfo, TDmaChannel*& aChannel);
-	
-	
-	/**
- 	Closes a previously opened DMA channel.
-
- 	Assume the channel is idle and all requests have been deleted.
- 	*/
-	IMPORT_C void Close();
-	
-	
-	/**
- 	Cancels the current request and all the pending ones.
- 	*/
-	IMPORT_C void CancelAll();
-	inline TBool IsOpened() const;
-	inline TBool IsQueueEmpty() const;
-	inline TUint32 PslId() const;
-	inline TInt FailNext(TInt aFragmentCount);
-	inline TInt MissNextInterrupts(TInt aInterruptCount);
-	inline TInt Extension(TInt aCmd, TAny* aArg);
-	
-	/**
-	This is a function that allows the Platform Specific Layer (PSL) to extend the DMA API
-	with new channel-independent operations.
-
-	@param aCmd Command identifier.  Negative values are reserved for Symbian use.
-	@param aArg PSL-specific.
-	
-	@return KErrNotSupported if aCmd is not supported; a  PSL specific value otherwise.
- 	*/
-	IMPORT_C TInt StaticExtension(TInt aCmd, TAny* aArg);
-	inline const TDmac* Controller() const;
-	inline TInt MaxTransferSize(TUint aFlags, TUint32 aPslInfo);
-	inline TUint MemAlignMask(TUint aFlags, TUint32 aPslInfo);
-protected:
-	// Interface with state machines
-	TDmaChannel();
-	virtual void DoQueue(DDmaRequest& aReq) = 0;
-	virtual void DoCancelAll() = 0;
-	virtual void DoUnlink(SDmaDesHdr& aHdr);
-	virtual void DoDfc(DDmaRequest& aCurReq, SDmaDesHdr*& aCompletedHdr) = 0;
-	/**
-	   This function allows the Platform Specific Layer (PSL) to control the
-	   power management of the channel or its controller by overriding the
-	   PIL's default implementation (which does nothing) and making appropriate
-	   use of the Power Resource Manager (PRM).
-
-	   The function gets called by the PIL whenever the channel's queued
-	   requests count has changed in a significant way, either before the
-	   channel's Transfer() method is invoked for a request on a previously
-	   empty request queue, or immediately after the request count has become
-	   zero because of request cancellation or completion.
-
-	   Depending on the current value of iQueuedRequests, the PSL may power
-	   down or power up the channel. Note that iQueuedRequests gets accessed
-	   and changed by different threads, so the PSL needs to take the usual
-	   precautions when evaluating the variable's value.
-
-	   None of the internal DMA framework mutexes is being held by the PIL when
-	   calling this function.
-
-	   @see iQueuedRequests
-	 */
-	virtual void QueuedRequestCountChanged();
-#if defined(__CPU_ARM) && !defined(__EABI__)
-	inline virtual ~TDmaChannel() {}	// kill really annoying warning
-#endif
-private:
-	static void Dfc(TAny*);
-	void DoDfc();
-	inline void Wait();
-	inline void Signal();
-	inline TBool Flash();
-	void ResetStateMachine();
-protected:
-	TDmac* iController;										// DMAC this channel belongs to (NULL when closed)
-	TUint32 iPslId;											// unique identifier provided by PSL
-	NFastMutex iLock;										// for data accessed in both client & DFC context
-	SDmaDesHdr* iCurHdr;									// fragment being transferred or NULL
-	SDmaDesHdr** iNullPtr;									// Pointer to NULL pointer following last fragment
-	TDfc iDfc;												// transfer completion/failure DFC
-	TInt iMaxDesCount;										// maximum number of allocable descriptors
-	TInt iAvailDesCount;									// available number of descriptors
-	volatile TUint32 iIsrDfc;								// Interface between ISR and DFC:
-	enum { KErrorFlagMask = 0x80000000 };					// bit 31 - error flag
-	enum { KCancelFlagMask = 0x40000000 };					// bit 30 - cancel flag
-	enum { KDfcCountMask = 0x3FFFFFFF };					// bits 0-29 - number of queued DFCs
-	SDblQue iReqQ;											// being/about to be transferred request queue
-	TInt iReqCount;											// number of requests attached to this channel
-	TInt iQueuedRequests; 									// number of requests currently queued on this channel
-private:
-	TDmaCancelInfo* iCancelInfo;
-	__DMA_DECLARE_INVARIANT
-	};
-
-
-//////////////////////////////////////////////////////////////////////////////
-// PIL-PSL INTERFACE
-//////////////////////////////////////////////////////////////////////////////
-
-// Trace macros intended for use by the DMA PSL
-#define DMA_PRINTF(MSG) __KTRACE_OPT(KDMA, Kern::Printf((MSG)))
-#define DMA_PRINTF1(MSG, ARG1) __KTRACE_OPT(KDMA, Kern::Printf((MSG), (ARG1)))
-#define DMA_PRINTF2(MSG, ARG1, ARG2) __KTRACE_OPT(KDMA, Kern::Printf((MSG), (ARG1), (ARG2)))
-
-#define DMA_PSL_MESG "DMA PSL: "
-
-// General PSL tracing
-#define DMA_PSL_TRACE(MSG) DMA_PRINTF(DMA_PSL_MESG MSG)
-#define DMA_PSL_TRACE1(MSG, ARG1) DMA_PRINTF1(DMA_PSL_MESG MSG, (ARG1))
-#define DMA_PSL_TRACE2(MSG, ARG1, ARG2) DMA_PRINTF2(DMA_PSL_MESG MSG, (ARG1), (ARG2))
-
-
-#define DMA_PSL_CHAN_MESG DMA_PSL_MESG "ChanId %d: "
-#define DMA_PSL_CHAN_ARGS(CHAN) ((CHAN).PslId())
-
-// For channel specific tracing (where CHAN is a TDmaChannel)
-#define DMA_PSL_CHAN_TRACE_STATIC(CHAN, MSG) DMA_PRINTF1(DMA_PSL_CHAN_MESG MSG, DMA_PSL_CHAN_ARGS(CHAN))
-#define DMA_PSL_CHAN_TRACE_STATIC1(CHAN, MSG, ARG1) DMA_PRINTF2(DMA_PSL_CHAN_MESG MSG, DMA_PSL_CHAN_ARGS(CHAN), (ARG1))
-
-// For channel specific tracing, for use within methods of TDmaChannel derived
-// class
-#define DMA_PSL_CHAN_TRACE(MSG) DMA_PSL_CHAN_TRACE_STATIC(*this, MSG)
-#define DMA_PSL_CHAN_TRACE1(MSG, ARG1) DMA_PSL_CHAN_TRACE_STATIC1(*this, MSG, (ARG1))
-
-
-/**
-Generic DMA descriptor used if the DMAC does not have support for hardware
-descriptor.
-@see DDmaRequest::Fragment
-@publishedPartner
-@released
-*/
-
-struct SDmaPseudoDes
-	{
-	/** Source linear address or peripheral cookie */
-	TUint32 iSrc;
-	/** Destination linear address or peripheral cookie */
-	TUint32 iDest;
-	/** Number of bytes to transfer */
-	TInt iCount;
-	/** @see TDmaRequestFlags */
-	TUint iFlags;
-	/** PSL-specific information provided by client */
-	TUint32 iPslInfo;
-	/** The same as TDmaChannel::SCreateInfo.iCookie */
-	TUint32 iCookie;
-	};
-
-
-/**
-Each hardware or pseudo descriptor is associated with a header.  Headers are
-needed because hardware descriptors can not easily be extended to store
-additional information.
-@publishedPartner
-@released
-*/
-
-struct SDmaDesHdr
-	{
-	SDmaDesHdr* iNext;
-	};
-
-
-/**
-Interface used by PIL to open and close DMA channels.
-
-Must be implemented by PSL.
-@publishedPartner
-@released
-*/
-
-class DmaChannelMgr
-	{
-public:
-	/** Opens a channel using a client-provided identifier.
-		This function must be implemented by the PSL.
-		@param	aOpenId Magic cookie passed by client
-				This may identify the channel (if a static channel
-				allocation scheme is used) or may indicate some
-				properties which the channel must possess (if a dynamic
-				channel allocation scheme is used). It may be set to
-				zero always if dynamic allocation is used and all
-				channels are equivalent.
-		@return	Pointer to channel if available, NULL otherwise.
-		@pre	The PIL calls this function with a global fast mutex held to
-				avoid race conditions.
-		@post	If a non-NULL pointer is returned, the object pointed to has its
-				iController and iPslId members set to valid states.
-				iController should point to the controller handling that channel.
-				iPslId should contain a value uniquely identifying the channel -
-				it is used only for debug tracing by PIL. It can be given any
-				convenient value by PSL	(channel index, I/O port address, ...).
-	*/
-	static TDmaChannel* Open(TUint32 aOpenId);
-
-	/** Performs platform-specific operations when a channel is closed.
-		This function must be implemented by the PSL but the implementation can be
-		a no-op.
-		@param aChannel The channel to close
-		@pre The PIL calls this function with a global fast mutex held to
-			avoid race conditions.
-	*/
-	static void Close(TDmaChannel* aChannel);
-
-	/** Function allowing PSL to extend DMA API with new channel-independent operations.
-		This function must be implemented by the PSL.
-		@param aCmd Command identifier.  Negative values are reserved for Symbian use.
-		@param aArg PSL-specific
-		@return KErrNotSupported if aCmd is not supported.  PSL-specific value otherwise.
-	 */
-	static TInt StaticExtension(TInt aCmd, TAny* aArg);
-
-	static inline void Wait();
-	static inline void Signal();
-private:
-	static NFastMutex Lock;
-	};
-
-
-//////////////////////////////////////////////////////////////////////////////
-
-/**
- Abstract base class representing a DMA controller.
-
- The class has two purposes.
-
- First, it is a container for channels, descriptors and descriptor headers.
-
- Second, it exposes a set of virtual functions implemented by
- the PSL (platform-specific layer).
- These functions are the main interfaces between
- the PIL (platform-independent layer) and PSL.
-
- Must be allocated in BSS because it relies on being zeroed at creation-time.
-
- @publishedPartner
- @released
- */
-
-class TDmac
-	{
-	friend class DmaChannelMgr;
-// protected: VC++ complains when building PSL if following decl is protected
-public:
-	/** Data required for creating a new instance */
-	struct SCreateInfo
-		{
-		/** Number of channels in controller */
-		TInt iChannelCount;
-        /** Maximum number of descriptors (shared by all channels) */
-		TInt iDesCount;
-		/** Bitmask.  The only supported value is KCapsBitHwDes (hardware
-			descriptors used). */
-		TUint32 iCaps;
-		/** Size of individual descriptors.  Use sizeof(SDmaPseudoDes) for
-		 	single-buffer and double-buffer controllers. */
-		TInt iDesSize;
-		/** Bitmask used when creating the hardware chunk storing the descriptor
-			pool. Used only for hardware descriptors. The access part must be
-			EMapAttrSupRw.  If the chunk is cached and/or buffered, the PSL must
-			flush the data cache and/or drain the write buffer in InitHwDes()
-			and related functions.
-		 	@see TMappingAttributes
-		 */
-		TUint iDesChunkAttribs;
-		};
-public:
-	TInt Create(const SCreateInfo& aInfo);
-	virtual ~TDmac();
-	TInt ReserveSetOfDes(TInt aCount);
-	void ReleaseSetOfDes(TInt aCount);
-	void InitDes(const SDmaDesHdr& aHdr, TUint32 aSrc, TUint32 aDest, TInt aCount,
-				 TUint aFlags, TUint32 aPslInfo, TUint32 aCookie);
-	inline SDmaPseudoDes& HdrToDes(const SDmaDesHdr& aHdr) const;
-	inline TAny* HdrToHwDes(const SDmaDesHdr& aHdr) const;
-	inline TUint32 DesLinToPhys(TAny* aDes) const;
-	inline void Wait();
-	inline void Signal();
-protected:
-	TDmac(const SCreateInfo& aInfo);
-
-public:
-	/**
-	Called by PIL when one fragment (single-buffer and double-buffer DMACs) or
-	list of fragments (scatter/gather DMAC) is to be transferred.
-
-	Called when	initiating a new transfer and also, for double-buffer DMACs, for
-	configuring the next fragment to transfer while the current one is
-	ongoing. Must always be implemented by PSL.
-	@param aChannel The channel to use
-	@param aHdr Header associated with fragment to transfer
-	*/
-	virtual void Transfer(const TDmaChannel& aChannel, const SDmaDesHdr& aHdr) = 0;
-
-	/**
-    Called by PIL to suspend transfer on a given channel.
-
-    The suspension must occur synchronously as the PSL assumes the channel
-    is suspended after calling this function. Must always be implemented by PSL.
-	@param aChannel The channel to suspend
-	*/
-	virtual void StopTransfer(const TDmaChannel& aChannel) = 0;
-
-	/**
-	Called by PIL to check whether a DMA channel is idle.
-	@param aChannel The channel to test
-	@return ETrue if channel idle, EFalse if transferring.
-	 */
-	virtual TBool IsIdle(const TDmaChannel& aChannel) = 0;
-
-	/**
-	Called by PIL to retrieve from the PSL the maximum transfer size based on the
-	parameters passed.
-	@param aChannel Channel to be used for the transfer
-	@param aFlags Bitmask characterising transfer
-	@param aPslInfo Cookie passed by client and used by PSL
-	@return 0 if invalid argument(s), -1 if transfer size not limited, the maximum
-	transfer size otherwise.
-	*/
-	virtual TInt MaxTransferSize(TDmaChannel& aChannel, TUint aFlags, TUint32 aPslInfo) = 0;
-
-	/**
-	Called by PIL to retrieve from the PSL the memory alignment mask based on the
-	parameters passed. Some DMA controllers impose alignment constraints on the base
-	address of memory buffers. This mask is AND'ed against memory addresses computed
-	during fragmentation.
-	@param aChannel Channel to be used for the transfer
-	@param aFlags Bitmask characterising transfer
-	@param aPslInfo Cookie passed by client and used by PSL
-	@return A value representing the alignment mask (e.g. 3 if buffer must be 4-byte aligned)
-	*/
-	virtual TUint MemAlignMask(TDmaChannel& aChannel, TUint aFlags, TUint32 aPslInfo) = 0;
-
-	/**
-    Called by PIL during fragmentation to initialise a hardware descriptor.
-
-    The PSL must assume the descriptor is the last in the chain and so set the
-	interrupt bit and set the next descriptor field to an end of chain marker.
-	Must be implemented by PSL if and only if the DMAC supports hardware
-	descriptors.
-	@param aHdr Header associated with hardware descriptor to initialise
-	@param aSrc Transfer source
-	@param aDest Transfer destination
-	@param aCount Number of bytes to transfer (<= max. size supported by DMAC)
-	@param aFlags Bitmask characterising transfer
-	@param aPslInfo Cookie passed by client and used by PSL
-	@param aCookie the channel selection cookie
-	@see DDmaRequest::Fragment
-	*/
-	virtual void InitHwDes(const SDmaDesHdr& aHdr, TUint32 aSrc, TUint32 aDest, TInt aCount,
-						   TUint aFlags, TUint32 aPslInfo, TUint32 aCookie);
-
-	/**
-	Called by PIL, when fragmenting a request, to append a new hardware
-	descriptor to an existing descriptor chain.
-
-	Must clear the interrupt bit of	the descriptor associated with aHdr.
-	Must be implemented by PSL if and only if the DMAC supports hardware descriptors.
-	@param aHdr Header associated with last fragment in chain
-	@param aNextHdr Header associated with fragment to append
-	*/
-	virtual void ChainHwDes(const SDmaDesHdr& aHdr, const SDmaDesHdr& aNextHdr);
-
-	/**
-	Called by PIL when queuing a new request while the channel is running.
-
-	Must append the first hardware descriptor of the new request to the last
-	descriptor in the existing chain. Must be implemented by PSL if and only if
-	the DMAC supports hardware descriptors.
-	@param aChannel The channel where the transfer takes place
-	@param aLastHdr Header associated with last hardware descriptor in chain
-	@param aNewHdr Header associated with first hardware descriptor in new request
-	*/
-	virtual void AppendHwDes(const TDmaChannel& aChannel, const SDmaDesHdr& aLastHdr,
-							 const SDmaDesHdr& aNewHdr);
-
-	/**
-	Called by PIL when completing or cancelling a request to cause the PSL to unlink
-	the last item in the h/w descriptor chain from a subsequent chain that it was
-	possibly linked to. Must be implemented by the PSL if and only if the DMAC supports
-	hardware descriptors.
-
-	@param aChannel The channel where the request (and thus the descriptor) was queued
-	@param aHdr Header associated with last h/w descriptor in completed/cancelled chain
-	*/
-	virtual void UnlinkHwDes(const TDmaChannel& aChannel, SDmaDesHdr& aHdr);
-
-	/**
-	Called by test harness to force an error when the next fragment is
-	transferred.
-
-	Must be implemented by the PSL only if possible.
-	@param aChannel The channel where the error is to occur.
-	@return KErrNone if implemented.  The default PIL implementation returns
-	KErrNotSupported and the test harness knows how to deal with that.
-	*/
-	virtual TInt FailNext(const TDmaChannel& aChannel);
-
-	/**
-	Called by test harness to force the DMA controller to miss one or
-	more interrupts.
-
-	Must be implemented by the PSL only if possible.
-	@param aChannel The channel where the error is to occur
-	@param aInterruptCount The number of interrupt to miss.
-	@return KErrNone if implemented.  The default PIL implementation returns
-	KErrNotSupported and the test harness knows how to deal with that.
-	*/
-	virtual TInt MissNextInterrupts(const TDmaChannel& aChannel, TInt aInterruptCount);
-
-	/** Function allowing platform-specific layer to extend channel API with
-		new channel-specific operations.
-		@param aChannel Channel to operate on
-		@param aCmd Command identifier.  Negative values are reserved for Symbian use.
-		@param aArg PSL-specific
-		@return KErrNotSupported if aCmd is not supported.  PSL-specific value otherwise.
-		@see TDmaChannel::Extension
-	*/
-	virtual TInt Extension(TDmaChannel& aChannel, TInt aCmd, TAny* aArg);
-
-protected:
-	static void HandleIsr(TDmaChannel& aChannel, TBool aIsComplete);
-private:
-	TInt AllocDesPool(TUint aAttribs);
-	void FreeDesPool();
-private:
-	NFastMutex iLock;			 // protect descriptor reservation and allocation
-	const TInt iMaxDesCount;	 // initial number of descriptors and headers
-	TInt iAvailDesCount;		 // current available number of descriptors and headers
-	SDmaDesHdr* iHdrPool;		 // descriptor header dynamic array
-#ifndef __WINS__
-	DPlatChunkHw* iHwDesChunk;	 // chunk for hardware descriptor pool
-#endif
-	TAny* iDesPool;				 // hardware or pseudo descriptor dynamic array
-	const TInt iDesSize;		 // descriptor size in bytes
-public:
-	const TUint iCaps;  		 /*< what is supported by DMA controller */
-	enum {KCapsBitHwDes = 1};	 /*< hardware descriptors supported */
-	SDmaDesHdr* iFreeHdr;		 /*< head of unallocated descriptors linked list */
-#ifdef _DEBUG
-	TBool IsValidHdr(const SDmaDesHdr* aHdr);
-#endif
-	__DMA_DECLARE_INVARIANT
-	};
-
-
-//////////////////////////////////////////////////////////////////////////////
-
-/**
-Single-buffer DMA channel.
-
-Can be instantiated or further derived by PSL.  Not
-intended to be instantiated by client device drivers.
-@publishedPartner
-@released
-*/
-
-class TDmaSbChannel : public TDmaChannel
-	{
-private:
-	virtual void DoQueue(DDmaRequest& aReq);
-	virtual void DoCancelAll();
-	virtual void DoDfc(DDmaRequest& aCurReq, SDmaDesHdr*& aCompletedHdr);
-private:
-	TBool iTransferring;
-	};
-
-
-/**
-Double-buffer DMA channel.
-
-Can be instantiated or further derived by PSL.  Not
-intended to be instantiated by client device drivers.
-@publishedPartner
-@released
-*/
-
-class TDmaDbChannel : public TDmaChannel
-	{
-private:
-	virtual void DoQueue(DDmaRequest& aReq);
-	virtual void DoCancelAll();
-	virtual void DoDfc(DDmaRequest& aCurReq, SDmaDesHdr*& aCompletedHdr);
-private:
-	enum { EIdle = 0, ETransferring, ETransferringLast } iState;
-	};
-
-
-/**
-Scatter-gather DMA channel.
-
-Can be instantiated or further derived by PSL.
-Not intended to be instantiated by client device drivers.
-@publishedPartner
-@released
-*/
-
-class TDmaSgChannel : public TDmaChannel
-	{
-private:
-	virtual void DoQueue(DDmaRequest& aReq);
-	virtual void DoCancelAll();
-	virtual void DoUnlink(SDmaDesHdr& aHdr);
-	virtual void DoDfc(DDmaRequest& aCurReq, SDmaDesHdr*& aCompletedHdr);
-private:
-	TBool iTransferring;
-	};
-
-
-//////////////////////////////////////////////////////////////////////////////
-// INTERFACE WITH TEST HARNESS
-//////////////////////////////////////////////////////////////////////////////
-
-/**
-Set of information used by test harness.
-@publishedPartner
-@released
-*/
-
-struct TDmaTestInfo
-	{
-	/** Maximum transfer size in bytes for all channels (ie. the minimum of all channels' maximum size)*/
-	TInt iMaxTransferSize;
-	/** 3->Memory buffers must be 4-byte aligned, 7->8-byte aligned, ... */
-	TUint iMemAlignMask;
-	/** Cookie to pass to DDmaRequest::Fragment for memory-memory transfer*/
-	TUint32 iMemMemPslInfo;
-	/** Number of test single-buffer channels */
-	TInt iMaxSbChannels;
-	/** Pointer to array containing single-buffer test channel ids */
-	TUint32* iSbChannels;
-	/** Number of test double-buffer channels */
-	TInt iMaxDbChannels;
-	/** Pointer to array containing double-buffer test channel ids */
-	TUint32* iDbChannels;
-	/** Number of test scatter-gather channels */
-	TInt iMaxSgChannels;
-	/** Pointer to array containing scatter-gather test channel ids */
-	TUint32* iSgChannels;
-	};
-
-
-/**
-Provides access to test information structure stored in the PSL.
-
-Must be implemented by the PSL.
-@publishedPartner
-@released
-*/
-
-IMPORT_C const TDmaTestInfo& DmaTestInfo();
-
-
-//////////////////////////////////////////////////////////////////////////////
-
-#include <drivers/dma_v1.inl>
-
-#endif
--- a/kernel/eka/include/drivers/dma_v1.inl	Tue May 11 17:28:22 2010 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,147 +0,0 @@
-// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
-// All rights reserved.
-// This component and the accompanying materials are made available
-// under the terms of "Eclipse Public License v1.0""
-// which accompanies this distribution, and is available
-// at the URL "http://www.eclipse.org/legal/epl-v10.html".
-//
-// Initial Contributors:
-// Nokia Corporation - initial contribution.
-//
-// Contributors:
-//
-// Description:
-// include/drivers/dma_v1.inl
-// DMA framework public inline functions
-// This file should not be modified when porting the DMA framework to
-// new hardware.
-// TDmaChannel
-// 
-// WARNING: This file contains some APIs which are internal and are subject
-//          to change without noticed. Such APIs should therefore not be used
-//          outside the Kernel and Hardware Services package.
-//
-
-inline void TDmaChannel::Wait()
-	{
-	NKern::FMWait(&iLock);
-	}
-
-inline void TDmaChannel::Signal()
-	{
-	NKern::FMSignal(&iLock);
-	}
-
-inline TBool TDmaChannel::Flash()
-	{
-	return NKern::FMFlash(&iLock);
-	}
-
-inline TBool TDmaChannel::IsOpened() const
-	{
-	return iController != NULL;
-	}
-
-inline TBool TDmaChannel::IsQueueEmpty() const
-	{
-	return const_cast<TDmaChannel*>(this)->iReqQ.IsEmpty();
-	}
-
-inline TUint32 TDmaChannel::PslId() const
-	{
-	return iPslId;
-	}
-
-inline TInt TDmaChannel::FailNext(TInt /*aFragmentCount*/)
-	{
-	return iController->FailNext(*this);
-	}
-
-inline TInt TDmaChannel::MissNextInterrupts(TInt aInterruptCount)
-	{
-	return iController->MissNextInterrupts(*this, aInterruptCount);
-	}
-
-/** Function allowing platform-specific layer to extend API with new
-	channel-specific operations.
- 	@param aCmd Command identifier.  Negative values are reserved for Symbian use.
-	@param aArg PSL-specific
-	@return KErrNotSupported if aCmd is not supported.  PSL-specific value otherwise.
- */
-
-inline TInt TDmaChannel::Extension(TInt aCmd, TAny* aArg)
-	{
-	return iController->Extension(*this, aCmd, aArg);
-	}
-
-inline const TDmac* TDmaChannel::Controller() const
-	{
-	return iController;
-	}
-
-inline TInt TDmaChannel::MaxTransferSize(TUint aFlags, TUint32 aPslInfo)
-	{
-	return iController->MaxTransferSize(*this, aFlags, aPslInfo);
-	}
-
-inline TUint TDmaChannel::MemAlignMask(TUint aFlags, TUint32 aPslInfo)
-	{
-	return iController->MemAlignMask(*this, aFlags, aPslInfo);
-	}
-
-// DDmaRequest
-
-/** Called when request is removed from request queue in channel */
-
-inline void DDmaRequest::OnDeque()
-	{
-	iQueued = EFalse;
-	iLastHdr->iNext = NULL;
-	iChannel.DoUnlink(*iLastHdr);
-	}
-
-// TDmac
-
-inline void TDmac::Wait()
-	{
-	NKern::FMWait(&iLock);
-	}
-
-inline void TDmac::Signal()
-	{
-	NKern::FMSignal(&iLock);
-	}
-
-inline SDmaPseudoDes& TDmac::HdrToDes(const SDmaDesHdr& aHdr) const
-	{
-	return static_cast<SDmaPseudoDes*>(iDesPool)[&aHdr - iHdrPool];
-	}
-
-inline TAny* TDmac::HdrToHwDes(const SDmaDesHdr& aHdr) const
-	{
-	return static_cast<TUint8*>(iDesPool) + iDesSize*(&aHdr - iHdrPool);
-	}
-
-inline TUint32 TDmac::DesLinToPhys(TAny* aDes) const
-	{
-#ifdef __WINS__
-	(void)aDes;
-	return 0xDEADBEEF;
-#else
-	return iHwDesChunk->iPhysAddr + ((TLinAddr)aDes - iHwDesChunk->iLinAddr);
-#endif
-	}
-
-// DmaChannelMgr
-
-inline void DmaChannelMgr::Wait()
-	{
-	NKern::FMWait(&Lock);
-	}
-
-inline void DmaChannelMgr::Signal()
-	{
-	NKern::FMSignal(&Lock);
-	}
-
-//---
--- a/kernel/eka/include/drivers/dma_v2.h	Tue May 11 17:28:22 2010 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1135 +0,0 @@
-// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
-// All rights reserved.
-// This component and the accompanying materials are made available
-// under the terms of "Eclipse Public License v1.0""
-// which accompanies this distribution, and is available
-// at the URL "http://www.eclipse.org/legal/epl-v10.html".
-//
-// Initial Contributors:
-// Nokia Corporation - initial contribution.
-//
-// Contributors:
-//
-// Description:
-// include/drivers/dma_v2.h
-// DMA Framework - Client API v2 definition.
-//
-// NB: DMA clients should never include this file directly, but only ever the
-// generic header file <drivers/dma.h>.
-//
-
-#ifndef __DMA_H__
-#error "dma_v2.h must'n be included directly - use <drivers/dma.h> instead"
-#endif	// #ifndef __DMA_H__
-
-#ifndef __DMA_V2_H__
-#define __DMA_V2_H__
-
-
-#include <kernel/kernel.h>
-#include <drivers/dmadefs.h>
-
-
-//////////////////////////////////////////////////////////////////////////////
-// Debug Support - KDmaPanicCat is defined in each source file
-
-#define __DMA_ASSERTD(e) __ASSERT_DEBUG(e, Kern::Fault(KDmaPanicCat, __LINE__))
-#define __DMA_ASSERTA(e) __ASSERT_ALWAYS(e, Kern::Fault(KDmaPanicCat, __LINE__))
-#ifdef _DEBUG
-#define __DMA_CANT_HAPPEN() Kern::Fault(KDmaPanicCat, __LINE__)
-#define __DMA_DECLARE_INVARIANT public: void Invariant();
-#define __DMA_INVARIANT() Invariant()
-#else
-#define __DMA_CANT_HAPPEN()
-#define __DMA_DECLARE_INVARIANT
-#define __DMA_INVARIANT()
-#endif
-
-
-//////////////////////////////////////////////////////////////////////////////
-// INTERFACE EXPOSED TO DEVICE-DRIVERS
-//////////////////////////////////////////////////////////////////////////////
-
-//////////////////////////////////////////////////////////////////////////////
-
-/** Bitmasks used for configuring a DMA request.
-
-	In general, specify KDmaMemSrc|KDmaIncSrc (resp. KDmaMemDest|KDmaIncDest)
-	if the source (resp. destination) is a memory buffer and clear
-	KDmaMemSrc|KDmaIncSrc (resp. KDmaMemDest|KDmaIncDest) if the source
-	(resp. destination) is a peripheral.
-
-	If the location is given as a physical address (rather than a linear one)
-	then also specify KDmaPhysAddrSrc and/or KDmaPhysAddrDest.
-
-	The EKA1 "Fill Mode" can be implemented by omitting KDmaIncSrc.
-
-	Some peripherals may require a post-increment address mode.
-
-	@see DDmaRequest::Fragment
-	@publishedPartner
-	@released
-*/
-enum TDmaRequestFlags
-	{
-	// Note: This enum is only required for backwards compatibility with the
-	// old DMA framework, it can be removed once this is no longer needed.
-
-	/** Source is address of memory buffer */
-	KDmaMemSrc       = 0x01,
-	/** Destination is address of memory buffer */
-	KDmaMemDest      = 0x02,
-	/** Source address must be post-incremented during transfer */
-	KDmaIncSrc       = 0x04,
-	/** Destination address must be post-incremented during transfer */
-	KDmaIncDest      = 0x08,
-	/** Source address is a physical address (as opposed to a linear one) */
-	KDmaPhysAddrSrc  = 0x10,
-	/** Destination address is a physical address (as opposed to a linear one) */
-	KDmaPhysAddrDest = 0x20,
-	/** Request a different max transfer size (for instance for test purposes) */
-	KDmaAltTransferLen = 0x40
-	};
-
-
-/** Each hardware or pseudo descriptor is associated with a header.  Headers
-	are needed because hardware descriptors can not easily be extended to store
-	additional information.
-
-	@publishedPartner
-	@released
-*/
-struct SDmaDesHdr
-	{
-	SDmaDesHdr* iNext;
-	};
-
-/** Pointer to signature of the new extended callback function.
-
-	TUint - bitmask of one or more TDmaCallbackType values
-	TDmaResult - just that
-	TAny* - was provided by client in DDmaRequest constructor
-	SDmaDesHdr* - points to header (and thus descriptor) which caused a
-	'descriptor completed' or 'descriptor paused' event.
- */
-typedef void (*TDmaCallback)(TUint, TDmaResult, TAny*, SDmaDesHdr*);
-
-class TDmaChannel;
-
-/** A DMA request is a list of fragments small enough to be transferred in one go
-	by the DMAC.
-
-	In general, fragmentation is done in the framework by calling Fragment() but
-	clients with special needs can allocate a blank descriptor list with
-	ExpandDesList() and customise it to fit their needs.
-
-	Clients should not set attributes directly, but should use the various functions
-	instead.
-
-	This class has not been designed to be called from several concurrent threads.
-	Multithreaded clients must implement their own locking scheme (via DMutex).
-
-	Mutexes are used internally to protect data structures accessed both by the
-	client thread and the DFC thread. Therefore no fast mutex can be held when
-	calling a request function.
-
-	@publishedPartner
-	@released
- */
-class DDmaRequest : public DBase
-	{
-	friend class TDmaChannel;
-
-public:
-	/** The outcome of the transfer
-
-		@deprecated
-		@see TDmaResult
-	*/
-	enum TResult {EBadResult=0, EOk, EError};
-	/** The signature of the completion/failure callback function
-
-		@deprecated
-		@see TDmaCallback
-	*/
-	typedef void (*TCallback)(TResult, TAny*);
-
-public:
-    /** Constructor.
-
-		Create a new transfer request.
-
-		@param aChannel The channel this request is bound to.
-		@param aCb Callback function called on transfer completion or failure
-		(in channel DFC context).  Can be NULL.
-		@param aCbArg   Argument passed to callback function.
-		@param aMaxTransferSize Maximum fragment size.  If not specified, defaults to the maximum size
-		supported by the DMA controller for the type of transfer that is later scheduled.
-
-		@deprecated
-    */
-	IMPORT_C DDmaRequest(TDmaChannel& aChannel, TCallback aCb=NULL, TAny* aCbArg=NULL,
-						 TInt aMaxTransferSize=0);
-
-
-	/** Constructor.
-
-		Create a new transfer request.
-
-		@param aChannel The channel this request is bound to.
-		@param aDmaCb Callback function called on transfer completion or
-		failure (in channel DFC or ISR context). Can be NULL.
-		@param aCbArg Argument passed to callback function.
-		@param aMaxTransferSize Maximum fragment size. If not specified,
-		defaults to the maximum size supported by the DMA controller for the
-		type of transfer that is later scheduled.
-	*/
-	IMPORT_C DDmaRequest(TDmaChannel& aChannel, TDmaCallback aDmaCb, TAny* aCbArg=NULL,
-						 TUint aMaxTransferSize=0);
-
-
-	/** Destructor.
-
-		Assume the request is not being transferred or pending.
-    */
-	IMPORT_C ~DDmaRequest();
-
-
-	/** Split request into a list of fragments small enough to be fed to the
-		DMAC.
-
-		The size of each fragment is smaller than or equal to the maximum
-		transfer size supported by the DMAC. If the source and/or destination
-		is memory, each fragment points to memory which is physically
-		contiguous.
-
-		The kind of transfer to perform is specified via a set of flags used by
-		a PIL and a magic cookie passed to the PSL. If the source
-		(resp. destination) is a peripheral, aSrc (resp. aDest) is treated as a
-		magic cookie by the PIL and passed straight to the PSL.
-
-		The request can be uninitialised or may have been fragmented
-		previously. The previous configuration if any is lost whether or not
-		the function succeeds.
-
-		@param aSrc Source memory buffer linear address or peripheral magic
-		cookie.
-		@param aDest Destination memory buffer linear address or peripheral
-		magic cookie.
-		@param aCount Number of bytes to transfer.
-		@param aFlags Bitmask characterising the transfer.
-		@param aPslInfo Hardware-specific information passed to PSL.
-
-		@return KErrNone if success. KErrArgument if aFlags and/or aPslInfo are
-		invalid when finding the maximum transfer size. May also fail if
-		running out of descriptors.
-
-		@pre The request is not being transferred or pending.
-		@pre The various parameters must be valid. The PIL or PSL will fault the
-		kernel if not.
-
-		@see TDmaRequestFlags
-
-		@deprecated
-    */
-	IMPORT_C TInt Fragment(TUint32 aSrc, TUint32 aDest, TInt aCount, TUint aFlags, TUint32 aPslInfo);
-
-
-	/** New version of the DMA request fragment function, to be used with the
-		TDmaTransferArgs structure.
-	*/
-	IMPORT_C TInt Fragment(const TDmaTransferArgs& aTransferArgs);
-
-
-	/** Transfer asynchronously this request.
-
-		If this request's channel is idle, the request is transferred
-		immediately. Otherwise, it is queued and transferred later.
-
-		The client is responsible for ensuring cache consistency before and/or
-		after the transfer if necessary.
-
-		@return KErrNone if success, KErrGeneral otherwise.
-    */
-	IMPORT_C TInt Queue();
-
-
-    /** Append new descriptor(s) to existing list.
-
-		Clients needing to build a custom descriptor list should call this
-		function to allocate the list and access the resulting list through
-		iFirstHdr and iLastHdr.
-
-		Clients should not change the value of iFirstHdr, iLastHdr and the
-		iNext field of the descriptor headers to ensure descriptors can be
-		deallocated. Clients are free to change hardware descriptors, including
-		chaining, in whatever way suit them.
-
-		Assume the request is not being transferred or pending.
-
-		@param aCount Number of descriptors to append.
-
-		@return KErrNone or standard error code.
-    */
-	IMPORT_C TInt ExpandDesList(TInt aCount=1);
-
-
-    /** Append new descriptor(s) to existing list. This function variant
-		operates on the source port descriptor chain.
-
-		Works like ExpandDesList except that it uses the iSrcFirstHdr and
-		iSrcLastHdr fields.
-
-		@see ExpandDesList
-
-		This function can only be used if SDmacCaps::iAsymHwDescriptors is
-		true, otherwise it will just return KErrGeneral.
-
-		@param aCount Number of descriptors to append.
-
-		@return KErrNone or standard error code.
-    */
-	IMPORT_C TInt ExpandSrcDesList(TInt aCount=1);
-
-
-    /** Append new descriptor(s) to existing list. This function variant
-		operates on the destination port descriptor chain.
-
-		Works like ExpandDesList except that it uses the iDstFirstHdr and
-		iDstLastHdr fields.
-
-		@see ExpandDesList
-
-		This function can only be used if SDmacCaps::iAsymHwDescriptors is
-		true, otherwise it will just return KErrGeneral.
-
-		@param aCount Number of descriptors to append.
-
-		@return KErrNone or standard error code.
-    */
-	IMPORT_C TInt ExpandDstDesList(TInt aCount=1);
-
-
-	/** Free resources associated with this request.
-
-		Assume the request is not being transferred or pending.
-    */
-	IMPORT_C void FreeDesList();
-
-
-	/** Free resources associated with this request. This function variant
-		operates on the source port descriptor chain.
-
-		@see FreeDesList
-
-		This function can only be used if SDmacCaps::iAsymHwDescriptors is
-		true, otherwise it will do nothing.
-    */
-	IMPORT_C void FreeSrcDesList();
-
-
-	/** Free resources associated with this request. This function variant
-		operates on the destination port descriptor chain.
-
-		@see FreeDesList
-
-		This function can only be used if SDmacCaps::iAsymHwDescriptors is
-		true, otherwise it will do nothing.
-    */
-	IMPORT_C void FreeDstDesList();
-
-
-	/** Enables the functionality for counting the transferred source
-		elements.
-
-		This function can be called at any time, but the enabled/disabled
-		status is checked by the framework only at two points in time.
-
-		The first one is after a request has been queued, and if it is enabled
-		then the counting will commence as soon as the transfer starts.
-
-		The second point is when Resume() is called for a paused transfer, and
-		in this case the following applies. If counting was enabled when the
-		transfer was paused and it is now disabled then the counting is stopped
-		at that point and the count value frozen. If counting was disabled when
-		the transfer was paused and it is now enabled then the counting will
-		commence when the transfer resumes. (The starting value will depend on
-		the argument of the enable function.) Otherwise nothing will change,
-		i.e. counting will either continue normally (enabled/enabled) or
-		neither stop nor continue (disabled/disabled).
-
-		Once a status has been set, it remains valid for the entire duration of
-		the transfer (and beyond, if it is not changed again).
-
-		@param aResetElementCount If ETrue (the default) then the count
-		variable will be reset to zero, otherwise it will retain its current
-		value.
-
-		@see Queue()
-		@see TotalNumSrcElementsTransferred()
-	*/
-	IMPORT_C void EnableSrcElementCounting(TBool aResetElementCount=ETrue);
-
-
-	/** Enables the functionality for counting the transferred destination
-		elements.
-
-		This function can be called at any time, but the enabled/disabled
-		status is checked by the framework only at two points in time.
-
-		The first one is after a request has been queued, and if it is enabled
-		then the counting will commence as soon as the transfer starts.
-
-		The second point is when Resume() is called for a paused transfer, and
-		in this case the following applies. If counting was enabled when the
-		transfer was paused and it is now disabled then the counting is stopped
-		at that point and the count value frozen. If counting was disabled when
-		the transfer was paused and it is now enabled then the counting will
-		commence when the transfer resumes. (The starting value will depend on
-		the argument of the enable function.) Otherwise nothing will change,
-		i.e. counting will either continue normally (enabled/enabled) or
-		neither stop nor continue (disabled/disabled).
-
-		Once a status has been set, it remains valid for the entire duration of
-		the transfer (and beyond, if it is not changed again).
-
-		@param aResetElementCount If ETrue (the default) then the count
-		variable will be reset to zero, otherwise it will retain its current
-		value.
-
-		@see Queue()
-		@see TotalNumDstElementsTransferred()
-	*/
-	IMPORT_C void EnableDstElementCounting(TBool aResetElementCount=ETrue);
-
-
-	/** Disables the functionality for counting the transferred source
-		elements.
-
-		This function can be called at any time, but the enabled/disabled
-		status is checked by the framework only at two points in time.
-
-		The first one is after a request has been queued, and if it is enabled
-		then the counting will commence as soon as the transfer starts.
-
-		The second point is when Resume() is called for a paused transfer, and
-		in this case the following applies. If counting was enabled when the
-		transfer was paused and it is now disabled then the counting is stopped
-		at that point and the count value frozen. If counting was disabled when
-		the transfer was paused and it is now enabled then the counting will
-		commence when the transfer resumes. (The starting value will depend on
-		the argument of the enable function.) Otherwise nothing will change,
-		i.e. counting will either continue normally (enabled/enabled) or
-		neither stop nor continue (disabled/disabled).
-
-		Once a status has been set, it remains valid for the entire duration of
-		the transfer (and beyond, if it is not changed again).
-
-		@see Queue()
-		@see TotalNumSrcElementsTransferred()
-	*/
-	IMPORT_C void DisableSrcElementCounting();
-
-
-	/** Disables the functionality for counting the transferred destination
-		elements.
-
-		This function can be called at any time, but the enabled/disabled
-		status is checked by the framework only at two points in time.
-
-		The first one is after a request has been queued, and if it is enabled
-		then the counting will commence as soon as the transfer starts.
-
-		The second point is when Resume() is called for a paused transfer, and
-		in this case the following applies. If counting was enabled when the
-		transfer was paused and it is now disabled then the counting is stopped
-		at that point and the count value frozen. If counting was disabled when
-		the transfer was paused and it is now enabled then the counting will
-		commence when the transfer resumes. (The starting value will depend on
-		the argument of the enable function.) Otherwise nothing will change,
-		i.e. counting will either continue normally (enabled/enabled) or
-		neither stop nor continue (disabled/disabled).
-
-		Once a status has been set, it remains valid for the entire duration of
-		the transfer (and beyond, if it is not changed again).
-
-		@see Queue()
-		@see TotalNumDstElementsTransferred()
-	*/
-	IMPORT_C void DisableDstElementCounting();
-
-
-	/** Returns the number of elements that have been transferred by this
-		transfer request at the source port.
-
-		To use this method, the counting functionality has to be explicitly
-		enabled, either before the transfer request is queued or while it is
-		paused.
-
-		@see EnableSrcElementCounting()
-		@see DisableSrcElementCounting()
-
-		This function should only be called after the transfer has finished
-		(completed with or without error, or because it was cancelled) or while
-		it is paused. Otherwise it may just return 0.
-
-		@return The number of elements that have been transferred by this
-		transfer request at the source port.
-	*/
-	IMPORT_C TUint32 TotalNumSrcElementsTransferred();
-
-
-	/** Returns the number of elements that have been transferred by this
-		transfer request at the destination port.
-
-		To use this method, the counting functionality has to be explicitly
-		enabled, either before the transfer request is queued or while it is
-		paused.
-
-		@see EnableDstElementCounting()
-		@see DisableDstElementCounting()
-
-		This function should only be called after the transfer has finished
-		(completed with or without error, or because it was cancelled) or while
-		it is paused. Otherwise it may just return 0.
-
-		@return The number of elements that have been transferred by this
-		transfer request at the destination port.
-	*/
-	IMPORT_C TUint32 TotalNumDstElementsTransferred();
-
-
-	/** Returns the number of fragments that this transfer request has been
-		split into.
-
-		This number will only be different from 0 once Fragment() has been
-		called or after descriptors have been manually allocated by the client
-		using ExpandDesList().
-
-		If SDmacCaps::iAsymHwDescriptors is true then this function will always
-		return 0, and SrcFragmentCount() / DstFragmentCount() should be used
-		instead.
-
-		@return The number of fragments (descriptors / pseudo descriptors) that
-		this transfer request has been split into.
-	 */
-	IMPORT_C TInt FragmentCount();
-
-	/** Returns the number of source port fragments that this transfer request
-		has been split into.
-
-		This number will only be different from 0 once Fragment() has been
-		called or after descriptors have been manually allocated by the client
-		using ExpandSrcDesList().
-
-		This function can only be used if SDmacCaps::iAsymHwDescriptors is
-		true, otherwise it will always return 0.
-
-		@return The number of source port fragments (descriptors) that this
-		transfer request has been split into.
-	 */
-	IMPORT_C TInt SrcFragmentCount();
-
-
-	/** Returns the number of destination port fragments that this transfer
-		request has been split into.
-
-		This number will only be different from 0 once Fragment() has been
-		called or after descriptors have been manually allocated by the client
-		using ExpandDstDesList().
-
-		This function can only be used if SDmacCaps::iAsymHwDescriptors is
-		true, otherwise it will always return 0.
-
-		@return The number of destination port fragments (descriptors) that
-		this transfer request has been split into.
-	 */
-	IMPORT_C TInt DstFragmentCount();
-
-private:
-	inline void OnDeque();
-	TUint GetTransferCount(const TDmaTransferArgs& aTransferArgs);
-	TInt Frag(TDmaTransferArgs& aTransferArgs);
-	TInt FragSym(TDmaTransferArgs& aTransferArgs, TUint aCount, TUint aMaxTransferLen);
-	TInt FragAsym(TDmaTransferArgs& aTransferArgs, TUint aCount, TUint aMaxTransferLen);
-	TInt FragAsymSrc(TDmaTransferArgs& aTransferArgs, TUint aCount, TUint aMaxTransferLen);
-	TInt FragAsymDst(TDmaTransferArgs& aTransferArgs, TUint aCount, TUint aMaxTransferLen);
-	TInt ExpandDesList(TInt aCount, TInt& aDesCount, SDmaDesHdr*& aFirstHdr,
-					   SDmaDesHdr*& aLastHdr);
-	void FreeDesList(TInt& aDesCount, SDmaDesHdr*& aFirstHdr, SDmaDesHdr*& aLastHdr);
-	TInt FragmentCount(const SDmaDesHdr* aHdr);
-
-public:
-	// WARNING: The following attributes are accessed both in client and DFC
-	// context and so accesses must be protected with the channel lock.
-	TDmaChannel& iChannel;		/**< The channel this request is bound to */
-	TCallback iCb;			 /**< Called on completion/failure (can be NULL) */
-	TAny* iCbArg;			 /**< Callback argument */
-	TDmaCallback iDmaCb;		// the new-style callback function
-	TAny* iDmaCbArg;			// the new-style callback arg
-	TBool iIsrCb;				// client wants callback in ISR context
-	TInt iDesCount;			   /**< The number of fragments in list */
-	SDmaDesHdr* iFirstHdr;	   /**< The first fragment in the list (or NULL) */
-	SDmaDesHdr* iLastHdr;	   /**< The last fragment in the list (or NULL) */
-	TInt iSrcDesCount;		   /**< The number of fragments in list */
-	SDmaDesHdr* iSrcFirstHdr;  /**< The first fragment in the list (or NULL) */
-	SDmaDesHdr* iSrcLastHdr;   /**< The last fragment in the list (or NULL) */
-	TInt iDstDesCount;		   /**< The number of fragments in list */
-	SDmaDesHdr* iDstFirstHdr;  /**< The first fragment in the list (or NULL) */
-	SDmaDesHdr* iDstLastHdr;   /**< The last fragment in the list (or NULL) */
-	SDblQueLink iLink;			/**< The link on channel queue of pending requests */
-	TBool iQueued;				/**< Indicates whether request is pending or being transferred */
-	TUint iMaxTransferSize;		/**< Defaults to DMA controller max. transfer size */
-
-	TUint32 iTotalNumSrcElementsTransferred;
-	TUint32 iTotalNumDstElementsTransferred;
-
-	__DMA_DECLARE_INVARIANT
-	};
-
-
-//////////////////////////////////////////////////////////////////////////////
-
-class TDmac;
-class DmaChannelMgr;
-class TDmaCancelInfo;
-
-/** DMA channel base class.
-
-	Standard derived classes are provided for this channel (see
-	TDmaSbChannel, TDmaDbChannel, TDmaSgChannel, and TDmaAsymSgChannel).
-	The base-port implementor will only need to write their own derived
-	class if one of the standard classes is unsuitable.
-
-	This class has not been designed to be called from several concurrent
-	client threads. Multithreaded clients must implement their own locking
-	scheme (via DMutex).
-
-	Mutexes are used internally to protect data structures accessed both by the
-	client thread and the DFC one. Therefore no fast mutex can be held when
-	calling a channel function.
-
-	@publishedPartner
-	@released
- */
-class TDmaChannel
-	{
-	friend class DDmaRequest;
-	friend class TDmac;
-	friend class DmaChannelMgr;
-public:
-
-	/** Information passed by client when opening a channel */
-	struct SCreateInfo
-		{
-		/** Default constructor. Initializes all fields with meaningful default
-			values.
-
-			Must be inline (for now) because exporting it would break existing
-			custom DMA libs as their clients would need the export which would
-			be missing from the custom .def files.
-		*/
-		SCreateInfo() : iPriority(KDmaPriorityNone), iDynChannel(EFalse) {};
-
-		/** Identifier used by PSL to select channel to open */
-		TUint32 iCookie;
-		/** Number of descriptors this channel can use.
-
-			This number is not used in the upgraded version of the DMA
-			framework and is kept there only for source compatibility. If the
-			client is certain that it will only ever use that version, then the
-			value passed here doesn't matter - the framework will ignore it.
-
-			@deprecated
-		 */
-		TInt iDesCount;
-		/** DFC queue used to service DMA interrupts.
-
-			The DFC thread priority must be higher than any client thread
-			priority to avoid a situation where a transfer completes while
-			being cancelled and another transfer is started before the DFC
-			thread gets a chance to run. This would lead to a stray DFC.
-		*/
-		TDfcQue* iDfcQ;
-		/** DFC priority */
-		TUint8 iDfcPriority;
-		/** Used by PSL to configure a channel priority (if possible).
-
-			The default is KDmaPriorityNone (the don't care value).
-
-		    @see TDmaPriority
-		*/
-		TUint iPriority;
-		/** Request a dynamic DMA channel.
-
-			If this is set to ETrue then the Open call is for a 'dynamic' as
-			opposed to a static and solely owned DMA channel. A number of
-			properties of the opened TDmaChannel object will be different in
-			that case.
-
-			The default value is EFalse.
-		 */
-		TBool iDynChannel;
-		};
-
-public:
-    /** Opens the DMA channel.
-
-		Channel selection is done by the hardware-specific layer using a cookie
-		passed in via aInfo.
-
-		The client should not delete the returned pointer as the framework owns
-		channel objects. However, the client should explicitly close the
-		channel when finished with it.
-
-		@param aInfo Information passed by caller to select and configure
-		channel.
-
-		@param aChannel Points to open channel on successful return. NULL
-		otherwise.
-
-		@return KErrNone or standard error code.
- 	*/
-	IMPORT_C static TInt Open(const SCreateInfo& aInfo, TDmaChannel*& aChannel);
-
-
-	/** Closes a previously opened DMA channel.
-
-		Assumes the channel is idle and all requests have been deleted.
-
-		The call will cause the resources associated with this channel to be
-		released, and the pointer/reference to it mustn't therefore be accessed
-		any longer after the function has returned. The channel pointer should
-		be set to NULL by the client.
- 	*/
-	IMPORT_C void Close();
-
-
-	/** Logically links this channel to the one specified as an argument, or,
-		if the argument is NULL, unlinks this channel.
-
-		The effect of channel linking is that once a transfer on this channel
-		has finished, instead of causing the associated client callback to be
-		called, 'aChannel' will be enabled by hardware and a preconfigured
-		transfer on that channel will start.
-
-		Note that conceptually 'linking' here always refers to the end of a
-		channel transfer, not the beginning, i.e. a channel can only be linked
-		once and always to a successor, never twice or to a predecessor. (This
-		does not preclude the possibility that two channels are linked in a
-		circular fashion.)
-
-		This function can only be used if the DMAC supports logical channel
-		linking.
-
-		@see SDmacCaps::iChannelLinking
-
-		@param aChannel Points to the channel this one should be linked to, or
-		NULL if this channel is to be unlinked from any other one.
-
-		@return KErrNone if the channel has been linked or unlinked
-		successfully, KErrCompletion if this channel was already linked to
-		aChannel or already unlinked, KErrNotSupported if the DMAC doesn't
-		support channel linking, KErrArgument if this channel was already
-		linked to a different channel, KErrGeneral if a general error occurred
-		preventing a successful outcome.
-	 */
-	IMPORT_C TInt LinkToChannel(TDmaChannel* aChannel);
-
-	/** Pauses an active transfer on this channel.
-
-		A paused channel transfer can be resumed by calling Resume() or it can
-		be stopped altogether by calling CancelAll().
-
-		@see TDmaChannel::Resume()
-
-		Function can only be used if the DMAC supports this functionality.
-
-		@see SDmacCaps::iChannelPauseAndResume
-
-		@return KErrNone if a transfer has been paused successfully,
-		KErrCompletion if a transfer was already paused, KErrNotSupported if
-		the DMAC doesn't support channel transfer pausing/resuming, KErrGeneral
-		if a general error occurred preventing a successful outcome.
-	 */
-	IMPORT_C TInt Pause();
-
-
-	/** Resumes a transfer on this channel that is paused.
-
-		Resume() can be called to resume channel operation when the transfer is
-		paused as a result of a previous call to Pause() or because the DMAC
-		has encountered a Pause bit in a H/W descriptor.
-
-		@see TDmaChannel::Pause()
-		@see TDmaCallbackType::EDmaCallbackLinkedListPaused
-
-		Function can only be used if the DMAC supports this functionality.
-
-		@see SDmacCaps::iChannelPauseAndResume
-
-		@return KErrNone if a paused transfer has been resumed successfully,
-		KErrCompletion if there was no paused transfer, KErrNotSupported if the
-		DMAC doesn't support channel transfer pausing/resuming, KErrGeneral if
-		a general error occurred preventing a successful outcome.
-	 */
-	IMPORT_C TInt Resume();
-
-
-	/** Cancels the current request and all the pending ones.
-	 */
-	IMPORT_C void CancelAll();
-
-
-	/** Returns the channel's maximum transfer length based on the passed
-		arguments.
-
-		@param aSrcFlags Bitmask characterising transfer source
-		@see TDmaTransferArgs::iSrcConfig::iFlags
-
-		@param aDstFlags Bitmask characterising transfer destination
-		@see TDmaTransferArgs::iDstConfig::iFlags
-
-		@param aPslInfo Cookie passed to the PSL
-		@see TDmaTransferArgs::iPslRequestInfo
-
-		@return 0 if transfer length is not limited, the maximum transfer
-		length in bytes otherwise.
- 	*/
-	IMPORT_C TUint MaxTransferLength(TUint aSrcFlags, TUint aDstFlags, TUint32 aPslInfo);
-
-
-	/** Retrieves from the PSL the address / memory alignment mask based on the
-		parameters passed. Some DMA controllers impose alignment constraints on
-		the base address of memory buffers. This mask is AND'ed against memory
-		addresses computed during fragmentation.
-
-		This function needs to be called separately for source and destination.
-
-		@param aTargetFlags Bitmask characterising transfer source or
-		destination
-		@see TDmaTransferArgs::iSrcConfig::iFlags
-		@see TDmaTransferArgs::iDstConfig::iFlags
-
-		@param aElementSize Element size used for the transfer. Can be zero if
-		not known or 'don't care'.
-
-		@param aPslInfo Cookie passed to the PSL
-		@see TDmaTransferArgs::iPslRequestInfo
-
-		@return A value representing the alignment mask (e.g. 3 if buffer must
-		be 4-byte aligned)
-	 */
-	IMPORT_C TUint AddressAlignMask(TUint aTargetFlags, TUint aElementSize,
-									TUint32 aPslInfo);
-
-
-	/** Returns a reference to a structure containing the capabilities and
-		features of the DMA controller associated with this channel.
-
-		@return A reference to a structure containing the capabilities and
-		features of the DMA controller associated with this channel.
-	 */
-	IMPORT_C const SDmacCaps& DmacCaps();
-
-
-	/** Sets up once more the transfer request that has just completed, after
-		optionally having adjusted the transfer parameters as specified.
-
-		This function is meant to be called exclusively from a client-supplied
-		callback that is executed in ISR context, and only in response to a
-		transfer completion notification.
-
-		If this call returns to the caller with KErrNone then the framework's
-		ISR handler will subsequently not queue the channel DFC for this
-		completed request.
-
-		The parameters specify which changes the framework should apply to the
-		descriptors of the transfer request before rescheduling it. Arguments
-		for which no change is required should be passed as their default
-		values. The parameters correspond to those in the TDmaTransferArgs
-		struct as follows.
-
-		@param aSrcAddr @see TDmaTransferArgs::iSrcConfig::iAddr
-		@param aDstAddr @see TDmaTransferArgs::iDstConfig::iAddr
-		@param aTransferCount @see TDmaTransferArgs::iTransferCount
-		@param aPslRequestInfo @see TDmaTransferArgs::iPslRequestInfo
-		@param aIsrCb If set to ETrue (the default) then the callback of the
-		rescheduled request will again be called in ISR context
-
-		Since Epoc::LinearToPhysical() cannot be called in ISR context the
-		addresses passed into this function must be physical ones, i.e.
-		TDmaTransferFlags::KDmaPhysAddr is implied.
-
-		If an address refers to a memory target then
-		TDmaTransferFlags::KDmaMemIsContiguous is implied as well as no
-		fragmentation is possible at this point.
-
-		@pre Must only be called from a 'transfer complete' client callback in
-		ISR context.
-
-		@post Framework won't queue the channel DFC for the completed request
-		in success case.
-
-		@see DDmaRequest::DDmaRequest(TDmaChannel&, TDmaCallback, TAny*, TUint)
-		@see TDmaCallbackType::EDmaCallbackRequestCompletion
-		@see TDmaPILFlags::KDmaRequestCallbackFromIsr
-
-		@return KErrGeneral if there was an error, KErrNone otherwise.
-	 */
-	IMPORT_C TInt IsrRedoRequest(TUint32 aSrcAddr=KPhysAddrInvalid,
-								 TUint32 aDstAddr=KPhysAddrInvalid,
-								 TUint aTransferCount=0,
-								 TUint32 aPslRequestInfo=0,
-								 TBool aIsrCb=ETrue);
-
-
-	/** Tests whether the channel is currently opened.
-
-		@return ETrue if channel is currently opened, EFalse otherwise.
-
-		NB: This API should not be used any longer.
-
-		After calling TDmaChannel::Open() successfully the channel is
-		guaranteed to be open. Therefore there seems no good reason for this
-		API to exist.
-
-		@deprecated
-	 */
-	inline TBool IsOpened() const;
-
-
-	/** Tests whether the channel's request queue is currently empty.
-
-		@return ETrue if request queue is currently empty, EFalse otherwise.
-	 */
-	inline TBool IsQueueEmpty() const;
-
-
-	/** Returns a PSL-specific value which uniquely identifies this channel -
-		it is used for debug tracing by the PIL.
-
-		@return PSL-specific value which uniquely identifies this channel.
-	 */
-	inline TUint32 PslId() const;
-
-
-	/** Called by a test harness to force an error when the next fragment is
-		transferred.
-
-		@param aFragmentCount The number of consecutive fragments to fail
-	 */
-	IMPORT_C TInt FailNext(TInt aFragmentCount);
-
-
-	/** Called by a test harness to force the DMA controller to miss one or
-		more interrupts.
-
-		@param aInterruptCount The number of consecutive interrupts to miss
-	 */
-	IMPORT_C TInt MissNextInterrupts(TInt aInterruptCount);
-
-
-	/** Function allowing platform-specific layer to extend channel API with
-		new channel-specific operations.
-
-		@param aCmd Command identifier. Negative values are reserved for use by
-		Nokia.
-		@param aArg PSL-specific argument
-
-		@return KErrNotSupported if aCmd is not supported. PSL-specific value
-		otherwise.
-	 */
-	IMPORT_C TInt Extension(TInt aCmd, TAny* aArg);
-
-
-	/** This is a function that allows the Platform Specific Layer (PSL) to
-		extend the DMA API with new channel-independent operations.
-
-		@param aCmd Command identifier. Negative values are reserved for
-		Symbian use.
-		@param aArg PSL-specific.
-
-		@return KErrNotSupported if aCmd is not supported; a PSL specific value
-		otherwise.
- 	*/
-	IMPORT_C TInt StaticExtension(TInt aCmd, TAny* aArg);
-
-
-	/** @deprecated
-		@see DmacCaps()
-	 */
-	inline const TDmac* Controller() const;
-
-	/** @deprecated
-		@see MaxTransferLength()
-	 */
-	inline TInt MaxTransferSize(TUint aFlags, TUint32 aPslInfo);
-
-	/** @deprecated
-		@see AddressAlignMask()
-	 */
-	inline TUint MemAlignMask(TUint aFlags, TUint32 aPslInfo);
-
-protected:
-	// Interface with state machines
-	TDmaChannel();
-
-	/** Called by the PIL when adding a new request to the channel's queue.
-		The implementation should update the channel's state as appropriate
-		and begin transfer of aReq if possible.
-
-		@param aReq The request which has been added to the queue
-	*/
-	virtual void DoQueue(const DDmaRequest& aReq);
-
-	/** Called by the PIL in response to a CancelAll call. It should update
-		the channel state appropriately.
-	*/
-	virtual void DoCancelAll() = 0;
-
-	/** This is called by the PIL when a DDmaRequest is removed from the
-		channel's queue. In general the implementation simply needs to unlink
-		the hardware descriptor corresponding to aHdr from the next.
-
-		Since the PIL links the hardware descriptor chains of adjacent queued
-		requests (for speed) it is necessary to break the chain when a request
-		is completed so that the request may be requeued by the client without
-		having called DDmaRequest::Fragment again.
-
-		@param aHdr The header for a descriptor, which must be unlinked
-		from its next descriptor (if there is one)
-	*/
-	virtual void DoUnlink(SDmaDesHdr& aHdr);
-
-	/** Called by the PIL whenever a transfer associated with aCurReq is
-		done. The implementation must advance the channel's state and
-		may transfer the next header if necessary (the provided
-		scatter-gather channel does not do this). It must also report
-		back which header was associated with the last transfer to
-		complete.
-
-		@param aCurReq The current request.
-		@param aCompletedHdr Must be set by the implementation to the header
-		of the last transfer to complete.
-	*/
-	virtual void DoDfc(const DDmaRequest& aCurReq, SDmaDesHdr*& aCompletedHdr);
-
-	/** Called by the PIL whenever a transfer associated with aCurReq is
-		done. The implementation must advance the channel's state and
-		may start the transfer for the next headers if necessary (the
-		provided scatter-gather channels do not do this). If one
-		header has a successor but the other is the last in the chain it
-		is an error.
-
-		@note Must be implemented by PSL if channel uses asymmetric hardware
-		descriptors and is not derived from TDmaAsymSgChannel.
-
-		@param aCurReq The current request.
-
-		@param aSrcCompletedHdr Must be set by the implementation to
-		the header of the last source descriptor to complete.
-
-		@param aDstCompletedHdr Must be set by the implementation to
-		the header of the last destination descriptor to complete.
-	*/
-	virtual void DoDfc(const DDmaRequest& aCurReq, SDmaDesHdr*& aSrcCompletedHdr,
-					   SDmaDesHdr*& aDstCompletedHdr);
-
-	virtual ~TDmaChannel();
-
-private:
-	static void Dfc(TAny*);
-	void DoDfc();
-	inline void Wait();
-	inline void Signal();
-	inline void Flash();
-	void ResetStateMachine();
-
-protected:
-	TDmac* iController;		 // DMAC this channel belongs to (NULL when closed)
-	const SDmacCaps* iDmacCaps;	// what is supported by DMAC on this channel
-	TUint32 iPslId;			 // unique identifier provided by PSL
-	TBool iDynChannel;		 // this is a dynamically allocated channel
-	TUint iPriority;		 // hardware priority of this channel
-	DMutex* iMutex;			 // for data accessed in both client & DFC context
-	SDmaDesHdr* iCurHdr;	 // fragment being transferred or NULL
-	SDmaDesHdr** iNullPtr;	 // Pointer to NULL pointer following last fragment
-	TDfc iDfc;				  // transfer completion/failure DFC
-	TInt iMaxDesCount;		  // maximum number of allocable descriptors
-	TInt iAvailDesCount;	  // available number of descriptors
-	volatile TUint32 iIsrDfc; // Interface between ISR and DFC:
-	enum {KErrorFlagMask = 0x80000000};	   // bit 31 - error flag
-	enum {KCancelFlagMask = 0x40000000};   // bit 30 - cancel flag
-	enum {KDfcCountMask = 0x3FFFFFFF};	   // bits 0-29 - number of queued DFCs
-	SDblQue iReqQ;				 // being/about to be transferred request queue
-	TInt iReqCount;				 // number of requests attached to this channel
-private:
-	TDmaCancelInfo* iCancelInfo; // ...
-	TBool iRedoRequest;			 // client ISR callback wants a redo of request
-	TBool iIsrCbRequest;		 // request on queue using ISR callback
-
-	__DMA_DECLARE_INVARIANT
-	};
-
-
-//////////////////////////////////////////////////////////////////////////////
-// INTERFACE WITH TEST HARNESS
-//////////////////////////////////////////////////////////////////////////////
-
-/** Set of information used by test harness.
-
-	@publishedPartner
-	@released
-*/
-struct TDmaTestInfo
-	{
-	/** Maximum transfer size in bytes for all channels (ie. the minimum of all channels' maximum size)*/
-	TUint iMaxTransferSize;
-	/** 3->Memory buffers must be 4-byte aligned, 7->8-byte aligned, ... */
-	TUint iMemAlignMask;
-	/** Cookie to pass to DDmaRequest::Fragment for memory-memory transfer*/
-	TUint32 iMemMemPslInfo;
-	/** Number of test single-buffer channels */
-	TInt iMaxSbChannels;
-	/** Pointer to array containing single-buffer test channel ids */
-	TUint32* iSbChannels;
-	/** Number of test double-buffer channels */
-	TInt iMaxDbChannels;
-	/** Pointer to array containing double-buffer test channel ids */
-	TUint32* iDbChannels;
-	/** Number of test scatter-gather channels */
-	TInt iMaxSgChannels;
-	/** Pointer to array containing scatter-gather test channel ids */
-	TUint32* iSgChannels;
-	};
-
-
-/** Provides access to test information structure stored in the PSL.
-
-	Must be implemented by the PSL.
-
-	@publishedPartner
-	@released
-*/
-IMPORT_C const TDmaTestInfo& DmaTestInfo();
-
-/** Provides access to test information structure stored in the PSL.
-
-	Must be implemented by the PSL.
-
-	@publishedPartner
-	@released
-*/
-IMPORT_C const TDmaV2TestInfo& DmaTestInfoV2();
-
-
-
-//////////////////////////////////////////////////////////////////////////////
-
-
-#include <drivers/dma_compat.inl>
-#include <drivers/dma_v2.inl>
-
-
-#endif	// #ifndef __DMA_V2_H__
--- a/kernel/eka/include/drivers/dma_v2.inl	Tue May 11 17:28:22 2010 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,62 +0,0 @@
-// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
-// All rights reserved.
-// This component and the accompanying materials are made available
-// under the terms of "Eclipse Public License v1.0""
-// which accompanies this distribution, and is available
-// at the URL "http://www.eclipse.org/legal/epl-v10.html".
-//
-// Initial Contributors:
-// Nokia Corporation - initial contribution.
-//
-// Contributors:
-//
-// Description:
-// include/drivers/dma_v2.inl
-// DMA Framework - Client API v2 definition.
-//
-//
-// WARNING: This file contains some APIs which are internal and are subject
-//          to change without noticed. Such APIs should therefore not be used
-//          outside the Kernel and Hardware Services package.
-
-
-//
-// TDmaChannel
-//
-
-inline void TDmaChannel::Wait()
-	{
-	NKern::ThreadEnterCS();
-	Kern::MutexWait(*iMutex);
-	}
-
-inline void TDmaChannel::Signal()
-	{
-	Kern::MutexSignal(*iMutex);
-	NKern::ThreadLeaveCS();
-	}
-
-inline void TDmaChannel::Flash()
-	{
-	Kern::MutexSignal(*iMutex);
-	Kern::MutexWait(*iMutex);
-	}
-
-inline TBool TDmaChannel::IsOpened() const
-	{
-	__KTRACE_OPT(KDMA, Kern::Printf("Warning: TDmaChannel::IsOpened() is deprecated"));
-	return iController != NULL;
-	}
-
-inline TBool TDmaChannel::IsQueueEmpty() const
-	{
-	return const_cast<TDmaChannel*>(this)->iReqQ.IsEmpty();
-	}
-
-inline TUint32 TDmaChannel::PslId() const
-	{
-	return iPslId;
-	}
-
-
-// ---
--- a/kernel/eka/include/drivers/dmadefs.h	Tue May 11 17:28:22 2010 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,739 +0,0 @@
-// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
-// All rights reserved.
-// This component and the accompanying materials are made available
-// under the terms of "Eclipse Public License v1.0"
-// which accompanies this distribution, and is available
-// at the URL "http://www.eclipse.org/legal/epl-v10.html".
-//
-// Initial Contributors:
-// Nokia Corporation - initial contribution.
-//
-// Contributors:
-//
-// Description:
-// include/drivers/dmadefs.h
-// DMA Framework - General class, enum, constant and type definitions.
-//
-//
-
-#ifndef __DMADEFS_H__
-#define __DMADEFS_H__
-
-
-#include <e32def.h>
-
-
-/** The client request callback type */
-enum TDmaCallbackType
-	{
-	/** Transfer request completion callback */
-	EDmaCallbackRequestCompletion        = 0x01,
-	/** Transfer request completion callback - source side */
-	EDmaCallbackRequestCompletion_Src    = 0x02,
-	/** Transfer request completion callback - destination side */
-	EDmaCallbackRequestCompletion_Dst    = 0x04,
-
-	/** Descriptor completion callback */
-	EDmaCallbackDescriptorCompletion     = 0x08,
-	/** Descriptor completion callback - source side */
-	EDmaCallbackDescriptorCompletion_Src = 0x10,
-	/** Descriptor completion callback - destination side */
-	EDmaCallbackDescriptorCompletion_Dst = 0x20,
-
-	/** Frame completion callback */
-	EDmaCallbackFrameCompletion          = 0x40,
-	/** Frame completion callback - source side */
-	EDmaCallbackFrameCompletion_Src      = 0x80,
-	/** Frame completion callback - destination side */
-	EDmaCallbackFrameCompletion_Dst      = 0x100,
-
-	/** H/W descriptor pause event callback */
-	EDmaCallbackLinkedListPaused        = 0x200,
-	/** H/W descriptor pause event callback - source side */
-	EDmaCallbackLinkedListPaused_Src    = 0x400,
-	/** H/W descriptor pause event callback - destination side */
-	EDmaCallbackLinkedListPaused_Dst    = 0x800
-	};
-
-
-/** The outcome of the transfer request */
-enum TDmaResult
-	{
-	/** Completed without error */
-	EDmaResultOK = 0,
-	/** There was an error */
-	EDmaResultError
-	};
-
-
-
-/** To be used with address mode field of the DMA transfer config struct.
-
-	@see TDmaTransferConfig::iAddrMode
-*/
-enum TDmaAddrMode
-	{
-	/** Constant addressing. The address remains the same for consecutive
-		accesses.
-	*/
-	KDmaAddrModeConstant,
-	/** Post-increment addressing. The address increases by the element size
-		after each access.
-	*/
-	KDmaAddrModePostIncrement,
-	/** Post-decrement addressing. The address decreases by the element size
-		after each access.
-	*/
-	KDmaAddrModePostDecrement,
-	/** 1D-index addressing. The address always increases by the element size
-		plus the element skip value after each access.
-	*/
-	KDmaAddrMode1DIndex,
-	/** 2D-index addressing. The address increases by the element size plus the
-		element skip value - but only within a frame. Once a full frame has been
-		transferred, the address increases by the element size plus the element
-		skip value plus the frame skip value.
-	*/
-	KDmaAddrMode2DIndex
-	};
-
-
-/** To be used with the burst size field of the DMA transfer config struct.
-
-	@see SDmacCaps::iBurstTransactions
-	@see TDmaTransferConfig::iBurstSize
-*/
-enum TDmaBurstSize
-	{
-	/** Don't use burst transactions */
-	KDmaNoBursts     = -1,
-	/** Don't care (the default) */
-	KDmaBurstSizeAny = 0x00,
-	/** 4 bytes */
-	KDmaBurstSize4   = 0x04,
-	/** 8 bytes */
-	KDmaBurstSize8   = 0x08,
-	/** 16 bytes */
-	KDmaBurstSize16  = 0x10,
-	/** 32 bytes */
-	KDmaBurstSize32  = 0x20,
-	/** 64 bytes */
-	KDmaBurstSize64  = 0x40,
-	/** 128 bytes */
-	KDmaBurstSize128 = 0x80
-	};
-
-
-/** To be used with the flags field of the DMA transfer config struct.
-
-	@see TDmaTransferConfig::iFlags
-*/
-enum TDmaTransferFlags
-	{
-	/** Location is address of a memory buffer (as opposed to a peripheral or a
-		register).
-	*/
-	KDmaMemAddr                      = 0x01,
-	/** Address is a physical address (as opposed to a linear one).
-		If it is a memory address then KDmaMemIsContiguous will need to be set
-		as well.
-	 */
-	KDmaPhysAddr                     = 0x02,
-	/** Target memory is known to be physically contiguous, hence there is
-		no need for the framework to check for memory fragmentation.
-	*/
-	KDmaMemIsContiguous              = 0x04,
-	/** Don't use packed access (if possible) */
-	KDmaDontUsePacked                = 0x08,
-	/** Location is big endian (little endian if not set).
-
-		To have any effect, this flag requires the DMAC to support endianness
-		conversion.
-
-		@see SDmacCaps::iEndiannessConversion
-	*/
-	KDmaBigEndian                    = 0x10,
-	/** Don't do endianness conversion even if applicable.
-
-		To have any effect, this flag requires the DMAC to support endianness
-		conversion.
-
-		@see SDmacCaps::iEndiannessConversion
-	*/
-	KDmaLockEndian                   = 0x20,
-	/** Execute client request callback after each subtransfer (streaming /
-		loop case).
-
-		This option is only taken into account if the respective
-		TDmaTransferConfig::iRepeatCount is non-zero.
-
-		The callback will complete with a TDmaCallbackType of
-		EDmaCallbackRequestCompletion (even if the repeat counts for source and
-		destination are different), unless the flag
-		TDmaPILFlags::KDmaAsymCompletionCallback is set too, in which case what
-		is described there applies.
-	*/
-	KDmaCallbackAfterEveryTransfer   = 0x40,
-	/** Execute client request callback after each completed hardware
-		descriptor.
-
-		Requires the DMAC to support this feature. Unless the DMAC supports
-		asymmetric descriptor interrupts as well, this flag should not be set
-		on only one (source or destination) side.
-
-		@see SDmacCaps::iDescriptorInterrupt
-		@see SDmacCaps::iAsymDescriptorInterrupt
-	*/
-	KDmaCallbackAfterEveryDescriptor = 0x80,
-	/** Execute client request callback after each completed frame.
-
-		Requires the DMAC to support this feature. Unless the DMAC supports
-		asymmetric frame interrupts as well, this flag should not be set on
-		only one (source or destination) side.
-
-		@see SDmacCaps::iFrameInterrupt
-		@see SDmacCaps::iAsymFrameInterrupt
-	*/
-	KDmaCallbackAfterEveryFrame      = 0x100
-	};
-
-
-/** To be used with the synchronization flags field of a DMA transfer
-	config struct.
-
-	@see SDmacCaps::iSynchronizationTypes
-	@see TDmaTransferConfig::iSyncFlags
-*/
-enum TDmaTransferSyncFlags
-	{
-	/** Leave the decision on whether the transfer is hardware synchronized at
-		this end (either source or destination) to the Framework. This is the
-		default.
-	*/
-	KDmaSyncAuto        = 0x00,
-	/** Transfer is not hardware synchronized at this end (either source or
-		destination).
-	*/
-	KDmaSyncNone        = 0x01,
-	/** Transfer is hardware synchronized at this end (either source or
-		destination). This option can also be used on its own, without any
-		of the following sync sizes.
-	*/
-	KDmaSyncHere        = 0x02,
-	/** H/W synchronized at this end: transfer one ELEMENT (a number of
-		bytes, depending on the configured element size) per sync event.
-	*/
-	KDmaSyncSizeElement = 0x04,
-	/** H/W synchronized at this end: transfer one FRAME (a number of
-		elements, depending on the configured frame size) per sync event.
-	*/
-	KDmaSyncSizeFrame   = 0x08,
-	/** H/W synchronized at this end: transfer one BLOCK (a number of
-		frames, depending on the configured transfer size) per sync
-		event. This is the most common use case.
-	*/
-	KDmaSyncSizeBlock   = 0x10,
-	/** H/W synchronized at this end: transfer one PACKET (a number of
-		elements, depending on the configured packet size) per sync event.
-		In cases where the transfer block size is not a multiple of the
-		packet size the last packet will consist of the remaining elements.
-	*/
-	KDmaSyncSizePacket  = 0x20
-	};
-
-
-/** To be used with the Graphics operation field of a DMA transfer request.
-
-	@see TDmaTransferArgs::iGraphicsOps
-*/
-enum TDmaGraphicsOps
-	{
-	/** Don't use any graphics acceleration feature (the default) */
-	KDmaGraphicsOpNone            = 0x00,
-	/** Enable graphics acceleration feature 'Constant Fill' */
-	KDmaGraphicsOpConstantFill    = 0x01,
-	/** Enable graphics acceleration feature 'TransparentCopy' */
-	KDmaGraphicsOpTransparentCopy = 0x02
-	};
-
-
-/** To be used with the PIL flags field of a DMA transfer request.
-
-	@see TDmaTransferArgs::iFlags
-*/
-enum TDmaPILFlags
-	{
-	/** Request a different max transfer size (for instance for test
-		purposes).
-	*/
-	KDmaAltTransferLength         = 0x01,
-	/** Execute client request callback in ISR context instead of from a
-		DFC.
-	*/
-	KDmaRequestCallbackFromIsr    = 0x02,
-	/** Execute descriptor completion callback in ISR context instead of
-		from a DFC. This option is to be used in conjunction with the
-		TDmaTransferFlags::KDmaCallbackAfterEveryDescriptor flag.
-	*/
-	KDmaDescriptorCallbackFromIsr = 0x04,
-	/** Execute frame completion callback in ISR context instead of
-		from a DFC. This option is to be used in conjunction with the
-		TDmaTransferFlags::KDmaCallbackAfterEveryFrame flag.
-	*/
-	KDmaFrameCallbackFromIsr      = 0x08,
-	/** Execute the client request callback separately for source and
-		destination subtransfers.
-
-		This flag also determines the TDmaCallbackType value returned. If set,
-		the callback will complete with EDmaCallbackRequestCompletion_Src or
-		EDmaCallbackRequestCompletion_Dst, respectively, instead of with
-		EDmaCallbackRequestCompletion.
-
-		Requires the DMAC to support this feature.
-
-		@see SDmacCaps::iAsymCompletionInterrupt
-	*/
-	KDmaAsymCompletionCallback    = 0x10,
-	/** Execute the descriptor completion callback separately for source
-		and destination subtransfers.
-
-		This flag modifies the behaviour of the
-		TDmaTransferFlags::KDmaCallbackAfterEveryDescriptor flag and also
-		determines the TDmaCallbackType value returned. If set, the callback
-		will complete with EDmaCallbackDescriptorCompletion_Src or
-		EDmaCallbackDescriptorCompletion_Dst, respectively, instead of with
-		EDmaCallbackDescriptorCompletion.
-
-		Requires the DMAC to support this feature.
-
-		@see SDmacCaps::iAsymDescriptorInterrupt
-	*/
-	KDmaAsymDescriptorCallback    = 0x20,
-	/** Execute the frame completion callback separately for source and
-		destination subtransfers.
-
-		This flag modifies the behaviour of the
-		TDmaTransferFlags::KDmaCallbackAfterEveryFrame flag. If set, the
-		callback will complete with EDmaCallbackFrameCompletion_Src or
-		EDmaCallbackFrameCompletion_Dst, respectively, instead of with
-		EDmaCallbackFrameCompletion.
-
-		Requires the DMAC to support this feature.
-
-		@see SDmacCaps::iAsymFrameInterrupt
-	*/
-	KDmaAsymFrameCallback         = 0x40,
-	/** This transfer (only) should use the channel priority indicated by
-		TDmaTransferArgs::iChannelPriority.
-	*/
-	KDmaRequestChannelPriority    = 0x80
-	};
-
-
-/** Values which can be used with the priority field when opening a channel
-	and/or when fragmenting a transfer request.
-
-	@see TDmaChannel::SCreateInfo::iPriority
-	@see TDmaTransferArgs::iChannelPriority
-*/
-enum TDmaPriority
-	{
-	/** No transfer priority preference (don't care value) */
-	KDmaPriorityNone = 0x0,
-	/** Platform-independent transfer priority 1 (lowest) */
-	KDmaPriority1 = 0x80000001,
-	/** Platform-independent transfer priority 2 */
-	KDmaPriority2 = 0x80000002,
-	/** Platform-independent transfer priority 3 */
-	KDmaPriority3 = 0x80000003,
-	/** Platform-independent transfer priority 4 */
-	KDmaPriority4 = 0x80000004,
-	/** Platform-independent transfer priority 5 */
-	KDmaPriority5 = 0x80000005,
-	/** Platform-independent transfer priority 6 */
-	KDmaPriority6 = 0x80000006,
-	/** Platform-independent transfer priority 7 */
-	KDmaPriority7 = 0x80000007,
-	/** Platform-independent transfer priority 8 (highest) */
-	KDmaPriority8 = 0x80000008
-	};
-
-
-/** Contains the configuration values for either the source or the
-	destination side of a DMA transfer.
-
-	Note that some fields (notably iElementSize, iElementsPerFrame and
-	iFramesPerTransfer) may only differ between source and destination if
-	the underlying DMAC supports this.
-
-	@see SDmacCaps::iSrcDstAsymmetry
-	@see TDmaTransferArgs::iSrcConfig
-	@see TDmaTransferArgs::iDstConfig
-*/
-struct TDmaTransferConfig
-	{
-friend struct TDmaTransferArgs;
-
-	/** Default constructor. Initializes all fields with meaningful default
-		values.
-	*/
-#ifdef DMA_APIV2
-	KIMPORT_C
-#endif
-	TDmaTransferConfig();
-
-	/**	Intended for general use ie. not 2D or 1D transfers
-	 */
-#ifdef DMA_APIV2
-	KIMPORT_C
-#endif
-	TDmaTransferConfig (
-		TUint32 aAddr,
-		TUint aTransferFlags,
-		TDmaAddrMode aAddrMode = KDmaAddrModePostIncrement,
-		TUint aSyncFlags = KDmaSyncAuto,
-		TDmaBurstSize aBurstSize = KDmaBurstSizeAny,
-		TUint aElementSize = 0,
-		TUint aElementsPerPacket = 0,
-		TUint aPslTargetInfo = 0,
-		TInt aRepeatCount = 0
-		);
-
-	/**	Intended for 1D and 2D transfers
-	 */
-#ifdef DMA_APIV2
-	KIMPORT_C
-#endif
-	TDmaTransferConfig (
-		TUint32 aAddr,
-		TUint aElementSize,
-		TUint aElementsPerFrame,
-		TUint aFramesPerTransfer,
-		TInt aElementSkip,
-		TInt aFrameSkip,
-		TUint aTransferFlags,
-		TUint aSyncFlags = KDmaSyncAuto,
-		TDmaBurstSize aBurstSize = KDmaBurstSizeAny,
-		TUint aElementsPerPacket = 0,
-		TUint aPslTargetInfo = 0,
-		TInt aRepeatCount = 0
-		);
-
-	/** Transfer start address */
-	TUint32 iAddr;
-	/** Address mode */
-	TDmaAddrMode iAddrMode;
-	/** Element size in bytes (1/2/4/8) */
-	TUint iElementSize;
-	/** Number of elements per frame */
-	TUint iElementsPerFrame;
-	/** Number of elements per packet */
-	TUint iElementsPerPacket;
-	/** Number of frames to transfer (result is the transfer block) */
-	TUint iFramesPerTransfer;
-	/** Element skip in bytes (for addr modes E1DIndex or E2DIndex) */
-	TInt iElementSkip;
-	/** Frame skip in bytes (for addr mode E2DIndex) */
-	TInt iFrameSkip;
-	/** Use burst transactions of the specified size (in bytes)
-		@see TDmaBurstSize
-	*/
-	TInt iBurstSize;
-	/** PIL src/dst config flags.
-		@see TDmaTransferFlags
-	 */
-	TUint32 iFlags;
-	/** Transfer synchronization flags.
-		@see TDmaTransferSyncFlags
-	*/
-	TUint32 iSyncFlags;
-	/** Information passed to the PSL */
-	TUint iPslTargetInfo;
-	/** How often to repeat this (sub-)transfer:
-		0     no repeat (the default)
-		1..n  once / n times
-		-1     endlessly.
-	*/
-	TInt iRepeatCount;
-	/** Structure contents delta vector (usage tbd) */
-	TUint32 iDelta;
-	/** Reserved for future use */
-	TUint32 iReserved;
-
-private:
-	/** Private constructor. Initializes fields with the values passed in by
-		the legacy version of the DDmaRequest::Fragment() call.
-	*/
-	TDmaTransferConfig(TUint32 aAddr, TUint aFlags, TBool aAddrInc);
-	};
-
-
-/** To be used by the client to pass DMA transfer request details to the
-	framework.
-
-	Also used internally by the framework as a pseudo descriptor if the
-	controller doesn't support hardware descriptors (scatter/gather LLI).
-
-	@see DDmaRequest::Fragment
-*/
-struct TDmaTransferArgs
-	{
-	friend class DDmaRequest;
-	friend class TDmaChannel;
-	friend class TDmac;
-	friend class DmaChannelMgr;
-
-	/** Default constructor. Initializes all fields with meaningful default
-		values.
-	*/
-#ifdef DMA_APIV2
-	KIMPORT_C
-#endif
-	TDmaTransferArgs();
-
-	/**	For transfers where src and dst TDmaTransferConfig structs share some
-		of the same options ie. iDmaTransferFlags, iAddrMode, iSyncFlags,
-		iBurstSize, and iElementSize.
-
-		@param aSrcAddr
-		@param aDstAddr
-		@param aCount Number of bytes to transfer
-		@param aDmaTransferFlags Bitmask of TDmaTransferFlags for src and dst
-		@param aDmaSyncFlags Bitmask of TDmaTransferSyncFlags for src and dst
-		@param aMode Address mode for src and dst
-		@param aDmaPILFlags Bitmask of TDmaPILFlags
-		@param aElementSize In bytes (1/2/4/8) for src and dst
-		@param aChannelPriority
-		@param aBurstSize for src and dst
-		@param aPslRequestInfo Info word passed to the PSL
-		@param aGraphicOp Graphics operation to be executed
-		@param aColour Colour value for graphics operation
-	*/
-#ifdef DMA_APIV2
-	KIMPORT_C
-#endif
-	TDmaTransferArgs (
-		TUint aSrcAddr, TUint aDstAddr, TUint aCount,
-		TUint aDmaTransferFlags, TUint aDmaSyncFlags = KDmaSyncAuto,
-		TUint aDmaPILFlags = 0,
-		TDmaAddrMode aMode = KDmaAddrModePostIncrement, TUint aElementSize = 0,
-		TUint aChannelPriority = KDmaPriorityNone,
-		TDmaBurstSize aBurstSize = KDmaBurstSizeAny, TUint aPslRequestInfo = 0,
-		TDmaGraphicsOps aGraphicOp = KDmaGraphicsOpNone, TUint32 aColour = 0
-		);
-
-	/** For transfers needing specific options for source and destination
-		TDmaTransferConfig structs.
-
-		@param aSrc Configuration values for the source
-		@param aDst Configuration values for the destination
-		@param aFlags @see TDmaPILFlags
-		@param aChannelPriority Use for this request (only) the indicated
-		channel priority. Requires KDmaRequestChannelPriority to be set in
-		iFlags as well. @see TDmaPriority
-
-		@param aPslRequestInfo Info word passed to the PSL
-		@param aGraphicOp Graphics operation to be executed
-		@param aColour Colour value for graphics operation
-	*/
-#ifdef DMA_APIV2
-	KIMPORT_C
-#endif
-	TDmaTransferArgs (
-		const TDmaTransferConfig& aSrc,
-		const TDmaTransferConfig& aDst,
-		TUint32 aFlags = 0,
-		TUint aChannelPriority = KDmaPriorityNone,
-		TUint aPslRequestInfo = 0,
-		TDmaGraphicsOps aGraphicOp = KDmaGraphicsOpNone, TUint32 aColour = 0
-		);
-
-	/** Configuration values for the source */
-	TDmaTransferConfig iSrcConfig;
-	/** Configuration values for the destination */
-	TDmaTransferConfig iDstConfig;
-
-	/** Number of bytes to transfer (optional).
-
-		A non-zero value here must be consistent with iElementSize,
-		iElementsPerFrame and iFramesPerTransfer in iSrcConfig and iDstConfig
-		if the latter are specified as well (or instead, they may be left at
-		their default values of zero).
-
-		If zero, the PIL will fill in a value calculated from multiplying
-		iElementSize, iElementsPerFrame and iFramesPerTransfer in iSrcConfig,
-		so that the PSL can rely on it being always non-zero and valid.
-	 */
-	TUint iTransferCount;
-	/** Graphics operation to be executed */
-	TDmaGraphicsOps iGraphicsOps;
-	/** Colour value for graphics operations */
-	TUint32 iColour;
-	/** PIL common flags
-		@see TDmaPILFlags
-	*/
-	TUint32 iFlags;
-	/** Use for this request (only) the indicated channel priority.
-		Requires KDmaRequestChannelPriority to be set in iFlags as well.
-		@see TDmaPriority
-	*/
-	TUint iChannelPriority;
-	/** Info word passed to the PSL */
-	TUint iPslRequestInfo;
-
-	/** Structure contents delta vector (usage tbd) */
-	TUint32 iDelta;
-	/** Reserved for future use */
-	TUint32 iReserved1;
-
-private:
-	/** Private constructor. Initializes fields with the values passed in by
-		the legacy version of the DDmaRequest::Fragment() call.
-	*/
-	TDmaTransferArgs(TUint32 aSrcAddr, TUint32 aDstAddr, TInt aCount,
-					 TUint aFlags, TUint32 aPslInfo);
-	/** Stores the PSL cookie returned by TDmaChannel::PslId() at request
-		fragmentation time.
-		The value PslId() is often (but not necessarily) identical with the
-		client's TDmaChannel::SCreateInfo::iCookie, which gets passed by the
-		PIL into DmaChannelMgr::Open() as 'aOpenId'.
-	*/
-	TUint32 iChannelCookie;
-	/** Reserved for future use */
-	TUint32 iReserved2;
-	};
-
-
-/** DMAC capabilities info structure.
-
-	Instances are to be filled in by the PSL and then linked to via TDmaChannel
-	objects after they have been opened.
-
-	The contents may vary even between channels on the same DMAC (but will
-	remain constant for a given channel for the duration that it is open),
-	depending on static or dynamic factors which only the PSL knows about.
-
-	@see TDmaChannel::Open
-	@see TDmaChannel::DmacCaps
-*/
-struct SDmacCaps
-	{
-	/** DMAC supports n + 1 different channel priorities. */
-	TUint iChannelPriorities;
-	/** DMAC supports the pausing and resuming of channels. */
-	TBool iChannelPauseAndResume;
-	/** DMA addresses must be aligned on an element size boundary. */
-	TBool iAddrAlignedToElementSize;
-	/** DMAC supports 1D (element) index addressing in hardware. */
-	TBool i1DIndexAddressing;
-	/** DMAC supports 2D (frame) index addressing in hardware. */
-	TBool i2DIndexAddressing;
-	/** DMAC supports these transfer synchronization types (bitmap of values).
-
-		@see TDmaTransferSyncFlags
-	*/
-	TUint iSynchronizationTypes;
-	/** DMAC supports burst transactions with these sizes (bitmap of values).
-
-		@see TDmaBurstSize
-	*/
-	TUint iBurstTransactions;
-	/** DMAC supports a 'h/w descriptor complete' interrupt. */
-	TBool iDescriptorInterrupt;
-	/** DMAC supports a 'frame transfer complete' interrupt. */
-	TBool iFrameInterrupt;
-	/** DMAC supports a 'linked-list pause event' interrupt. */
-	TBool iLinkedListPausedInterrupt;
-	/** DMAC supports endianness conversion. */
-	TBool iEndiannessConversion;
-	/** DMAC supports these graphics operations (bitmap of values).
-
-		@see TDmaGraphicsOps
-	*/
-	TUint iGraphicsOps;
-	/** DMAC supports repeated transfers (loops). */
-	TBool iRepeatingTransfers;
-	/** DMAC supports logical channel linking (chaining). */
-	TBool iChannelLinking;
-	/** DMAC supports scatter/gather mode (linked list items). */
-	TBool iHwDescriptors;
-	/** DMAC supports asymmetric source and destination transfer
-		parameters (such as element size).
-	*/
-	TBool iSrcDstAsymmetry;
-	/** DMAC supports asymmetric h/w descriptor lists.
-
-		ETrue here requires ETrue for iHwDescriptors and iSrcDstAsymmetry as
-		well.
-	*/
-	TBool iAsymHwDescriptors;
-	/** DMAC with asymmetric descriptor support has the limitation that the
-		number of bytes transferred in source and destination must be equal in
-		every link segment (i.e. in each src/dst descriptor pair).
-
-		ETrue here requires ETrue for iAsymHwDescriptors as well.
-	*/
-	TBool iBalancedAsymSegments;
-	/** DMAC supports separate transfer completion notifications for source and
-		destination side subtransfers.
-
-		This capability is required for the asymmetric transfer completion
-		callback API feature.
-
-		@see TDmaPILFlags::KDmaAsymCompletionCallback
-	*/
-	TBool iAsymCompletionInterrupt;
-	/** DMAC supports separate descriptor completion notifications for source and
-		destination side.
-
-		This capability is required for the asymmetric descriptor completion
-		callback API feature.
-
-		ETrue here requires ETrue for both iDescriptorInterrupt and
-		iAsymHwDescriptors as well.
-
-		@see TDmaPILFlags::KDmaAsymDescriptorCallback
-	*/
-	TBool iAsymDescriptorInterrupt;
-	/** DMAC supports separate frame completion notifications for source and
-		destination side.
-
-		This capability is required for the asymmetric frame completion
-		callback API feature.
-
-		ETrue here requires ETrue for iFrameInterrupt as well.
-
-		@see TDmaPILFlags::KDmaAsymFrameCallback
-	*/
-	TBool iAsymFrameInterrupt;
-
-	/** Reserved for future use */
-	TUint32 iReserved[5];
-	};
-
-
-struct TDmaV2TestInfo
-	{
-	enum {KMaxChannels=32};
-	/** Maximum transfer size in bytes for all channels (ie. the minimum of all channels' maximum size)*/
-	TUint iMaxTransferSize;
-	/** 3->Memory buffers must be 4-byte aligned, 7->8-byte aligned, ... */
-	TUint iMemAlignMask;
-	/** Cookie to pass to DDmaRequest::Fragment for memory-memory transfer */
-	TUint32 iMemMemPslInfo;
-	/** Number of test single-buffer channels */
-	TInt iMaxSbChannels;
-	/** Pointer to array containing single-buffer test channel ids */
-	TUint32 iSbChannels[KMaxChannels];
-	/** Number of test double-buffer channels */
-	TInt iMaxDbChannels;
-	/** Pointer to array containing double-buffer test channel ids */
-	TUint32 iDbChannels[KMaxChannels];
-	/** Number of test scatter-gather channels */
-	TInt iMaxSgChannels;
-	/** Pointer to array containing scatter-gather test channel ids */
-	TUint32 iSgChannels[KMaxChannels];
-	};
-
-
-#endif	// #ifndef __DMADEFS_H__
--- a/kernel/eka/include/drivers/locmedia.h	Tue May 11 17:28:22 2010 +0300
+++ b/kernel/eka/include/drivers/locmedia.h	Tue May 25 14:09:55 2010 +0300
@@ -342,6 +342,7 @@
 		EDataPaging=0x40,			// a data paging request
 		ETClientBuffer=0x80,		// RemoteDes() points to a TClientBuffer
 		EKernelBuffer=0x100,		// RemoteDes() points to a kernel-side buffer
+		EPhysAddrOnly=0x200,        // No virtual address is available. Data Paging requests Only. 
 		};
 public:
     
@@ -977,6 +978,12 @@
 	inline static TBool PageInRequest(TLocDrvRequest& aReq);
 	inline static TBool PageOutRequest(TLocDrvRequest& aReq);
 	inline static TBool PagingRequest(TLocDrvRequest& aReq);
+		
+	virtual TInt WritePhysical(TThreadMessage* aReq, TPhysAddr* aPageArray, TUint aPageCount, TUint aOffset, TBool aBackground);
+	virtual TInt ReadPhysical(TThreadMessage* aReq, TPhysAddr* aPageArray, TUint aPageCount, TUint aOffset, TInt aDrvNumber);
+private:    
+    virtual TInt BaseRead(TThreadMessage* aReq,TUint32 aBuffer,TUint aOffset,TUint aSize,TInt aDrvNumber,TBool aPhysAddr);
+    virtual TInt BaseWrite(TThreadMessage* aReq,TUint32 aBuffer,TUint aOffset,TUint aSize, TBool aBackground,TBool aPhysAddr); 
 public:
 	TMessageQue iMainQ;
 	TMessageQue iDeferredQ;
--- a/kernel/eka/include/e32math.h	Tue May 11 17:28:22 2010 +0300
+++ b/kernel/eka/include/e32math.h	Tue May 25 14:09:55 2010 +0300
@@ -456,11 +456,6 @@
 	IMPORT_C static TInt ATan(TReal &aTrg,const TReal &aSrc);
 	IMPORT_C static TInt ATan(TReal &aTrg,const TReal &aSrcY,const TReal &aSrcX);
 	IMPORT_C static TInt Cos(TReal &aTrg,const TReal &aSrc);
-	
-	/**
-	This function is not implemented by Symbian OS.
-	*/
-	IMPORT_C static TInt DtoR(TReal &aTrg,const TDesC &aSrc,TInt &aPos,const TChar aPoint);
 	IMPORT_C static TInt Exp(TReal &aTrg,const TReal &aSrc);
 	IMPORT_C static TInt Frac(TReal &aTrg,const TReal &aSrc);
 	IMPORT_C static TInt Int(TReal &aTrg,const TReal &aSrc);
--- a/kernel/eka/include/e32ver.h	Tue May 11 17:28:22 2010 +0300
+++ b/kernel/eka/include/e32ver.h	Tue May 25 14:09:55 2010 +0300
@@ -28,7 +28,7 @@
 
 const TInt KE32MajorVersionNumber=2;
 const TInt KE32MinorVersionNumber=0;
-const TInt KE32BuildVersionNumber=2117;
+const TInt KE32BuildVersionNumber=2122;
 
 const TInt KMachineConfigurationMajorVersionNumber=1;
 const TInt KMachineConfigurationMinorVersionNumber=0;
--- a/kernel/eka/include/kernel/kern_priv.h	Tue May 11 17:28:22 2010 +0300
+++ b/kernel/eka/include/kernel/kern_priv.h	Tue May 25 14:09:55 2010 +0300
@@ -2757,6 +2757,22 @@
 class M
 	{
 public:
+	/**
+	Flags to control the moving or discarding of a page via the methods M::DiscardPage(),
+	M::MovePage()and M::MoveAndAllocPage().
+	*/
+	enum TMoveDiscardFlags
+		{
+		/** Set this flag so dirty discardable page are moved rather than 
+			written to swap.
+		*/
+		EMoveDisMoveDirty = 0x1,
+		/** Set this so the attempt to allocate the location to move the page to 
+			will fail if the blocked RAM zone is reached.
+		*/
+		EMoveDisBlockRest = 0x2,
+		};
+
 	static void Init1();
 	static void Init2();
 #ifdef __SMP__
@@ -2803,9 +2819,10 @@
 	static void RamAllocIsLocked();
 	static TUint NumberOfFreeDpPages();
 	static TUint NumberOfDirtyDpPages();
-	static TInt MovePage(TPhysAddr aOld, TPhysAddr& aNew, TUint aBlockZoneId, TBool aBlockRest);
+	static TInt MovePage(TPhysAddr aOld, TPhysAddr& aNew, TUint aBlockZoneId, TUint aMoveDisFlags);
 	static TInt MoveAndAllocPage(TPhysAddr aAddr, TZonePageType aPageType);
-	static TInt DiscardPage(TPhysAddr aAddr, TUint aBlockZoneId, TBool aBlockRest);
+	static TInt DiscardPage(TPhysAddr aAddr, TUint aBlockZoneId, TUint aMoveDisFlags);
+	static TBool GetFreePages(TUint aNumPages);
 	static void RamZoneClaimed(SZone* aZone);
 	static TInt RamDefragFault(TAny* aExceptionInfo);
 	};
--- a/kernel/eka/include/kernel/kernel.h	Tue May 11 17:28:22 2010 +0300
+++ b/kernel/eka/include/kernel/kernel.h	Tue May 25 14:09:55 2010 +0300
@@ -2793,6 +2793,12 @@
 		EDriveDataPaging = -2,	/**< Special drive number to indicate data paging. */
 		};
 
+	/** Additional flags. */
+	enum TFlags
+		{
+		ESupportsPhysicalAccess = 1<<0,  /**< Supports ReadPhysical and WritePhysical methods. */
+		};
+
 	/**
 	Called by the paging system to read data from the media represented by this
 	device.
@@ -2838,6 +2844,55 @@
 	inline virtual TInt DeleteNotify(TThreadMessage* aReq,TUint aOffset,TUint aSize);
 
 	/**
+	Called by the paging system to read data from the media represented by this device using
+	physical addresses, if the device supports it.
+	
+	This is intended to allow reading pages from swap without needing to map them first, and should
+	be implemented by media drivers that support DMA access.
+
+	If this method is implemented, the ESupportsPhysicalAccess flag in iFlags must be set as well.
+
+	The default implementation of this method just returns KErrNotSupported.
+
+	@param aPageArray   Pointer to array of physical address to write to.
+	@param aPageCount   Number of physical pages to read.
+	@param aOffset      The offset from the media start, in read units, from where data should be read.
+	
+	@param aDrvNumber The drive number for code paging or a member of TSpecialDrives for rom or data
+	paging.
+
+	@return KErrNone or standard error code.
+	*/
+	inline virtual TInt ReadPhysical(TThreadMessage* aReq, TPhysAddr* aPageArray, TUint aPageCount, TUint aOffset, TInt aDrvNumber);
+
+	/**
+	Called by the paging system to write data to the media represented by this device using physical
+	addresses, if the device supports it.
+
+	This is only used in the implementation of data paging to write to the swap partition.
+
+	This method takes a pointer to an array of physical addresses and the number of pages to write,
+	in contrast to #Write which takes a logical address and a number of read units.
+
+	This is intended to allow writing pages to swap without needing to map them first, and should be
+	implelemented by media drivers that support DMA access.
+
+	If this method is implemented, the ESupportsPhysicalAccess flag in iFlags must be set as well.
+
+	The default implementation of this method just returns KErrNotSupported.
+
+	@param aPageArray   Pointer to array of physical address to read from.
+	@param aPageCount   Number of physical pages to write.
+	@param aOffset      The offset from the media start, in read units, to where data should be
+		   			    written.
+	@param aBackground  If set, this indicates that the request should not count as making the 
+		   				device busy.
+
+	@return KErrNone or standard error code.
+	*/
+	inline virtual TInt WritePhysical(TThreadMessage* aReq, TPhysAddr* aPageArray, TUint aPageCount, TUint aOffset, TBool aBackground);
+	
+	/**
 	Return the lock that should be used to synchronise calculation of the idle/busy state and
 	subsequent calls to #NotifyIdle and #NotifyBusy.
 	*/
@@ -2867,7 +2922,10 @@
 	
 public:
 	/** The type of device this represents. */
-	TUint32 iType;
+	TUint16 iType;
+
+	/** Flags bitfield made up of members of TFlags. */
+	TUint16 iFlags;
 
 	/** The local drives supported for code paging.
 	    This is a bitmask containing one bit set for each local drive supported, where the bit set
@@ -2902,20 +2960,48 @@
 	*/
 	DPagingRequestPool* iRequestPool;
 
+	/** Log2 of the media's preferred write size in bytes.
+
+		E.g. if the preferred write size is 16KB, this should be set 14.
+		
+		Some media may exhibit poor performance unless writes happen in multiples of the superpage
+		size.  In this case the media driver would set this field to indicate the write size, and
+		the kernel will attempt to:
+		
+		 - write in multiples of the preferred size
+		 - align writes to multiples of the preferred size
+
+		Note that this value cannot be less the size of a page (eg 12) and there may be a maximum
+		limit to what the kernel will write as well.
+	*/
+	TUint32 iPreferredWriteShift;
+
 	/** Reserved for future use.
 	*/
-	TInt iSpare[4];
+	TInt iSpare[3];
 	};
 
-inline TInt DPagingDevice::Write(TThreadMessage*,TLinAddr,TUint,TUint,TBool)
+inline TInt DPagingDevice::Write(TThreadMessage*, TLinAddr, TUint, TUint, TBool)
+	{
+	// Default implementation, may be overriden by derived classes
+	return KErrNotSupported;
+	}
+
+inline TInt DPagingDevice::ReadPhysical(TThreadMessage*, TPhysAddr*, TUint, TUint, TInt)
 	{
-	// Default implementation, may be overriden by dervied classes
+	// Default implementation, may be overriden by derived classes
+	return KErrNotSupported;
+	}
+	
+inline TInt DPagingDevice::WritePhysical(TThreadMessage*, TPhysAddr*, TUint, TUint, TBool)
+	{
+	// Default implementation, may be overriden by derived classes
 	return KErrNotSupported;
 	}
 
 inline TInt DPagingDevice::DeleteNotify(TThreadMessage*,TUint,TUint)
 	{
-	// Default implementation, may be overriden by dervied classes
+	// Default implementation, may be overriden by derived classes
 	return KErrNotSupported;
 	}
 
--- a/kernel/eka/include/memmodel/epoc/mmubase/mmubase.inl	Tue May 11 17:28:22 2010 +0300
+++ b/kernel/eka/include/memmodel/epoc/mmubase/mmubase.inl	Tue May 25 14:09:55 2010 +0300
@@ -81,15 +81,17 @@
 	}
 
 
-inline TInt M::MovePage(TPhysAddr aOld, TPhysAddr& aNew, TUint aBlockZoneId, TBool aBlockRest)
+inline TInt M::MovePage(TPhysAddr aOld, TPhysAddr& aNew, TUint aBlockZoneId, TUint aMoveDisFlags)
 	{
-	return Mmu::Get().MovePage(aOld, aNew, aBlockZoneId, aBlockRest);
+	return Mmu::Get().MovePage(	aOld, aNew, aBlockZoneId, 
+								(aMoveDisFlags & M::EMoveDisBlockRest)!=0);
 	}
 
 
-inline TInt M::DiscardPage(TPhysAddr aAddr, TUint aBlockZoneId, TBool aBlockRest)
+inline TInt M::DiscardPage(TPhysAddr aAddr, TUint aBlockZoneId, TUint aMoveDisFlags)
 	{
-	return Mmu::Get().DiscardPage(aAddr, aBlockZoneId, aBlockRest);
+	return Mmu::Get().DiscardPage(	aAddr, aBlockZoneId, 
+									(aMoveDisFlags & M::EMoveDisBlockRest)!=0);
 	}
 #endif
 
--- a/kernel/eka/include/memmodel/epoc/mmubase/ramalloc.h	Tue May 11 17:28:22 2010 +0300
+++ b/kernel/eka/include/memmodel/epoc/mmubase/ramalloc.h	Tue May 25 14:09:55 2010 +0300
@@ -144,10 +144,11 @@
 	TInt ZoneAllocRamPages(TUint* aZoneIdList, TUint aZoneIdCount, TPhysAddr* aPageList, TInt aNumPages, TZonePageType aType);
 	TInt AllocContiguousRam(TUint aNumPages, TPhysAddr& aPhysAddr, TInt aAlign=0);
 #if !defined(__MEMMODEL_MULTIPLE__) && !defined(__MEMMODEL_MOVING__)
-	void BlockContiguousRegion(TPhysAddr aAddrBase, TUint aNumPages);
+	TUint BlockContiguousRegion(TPhysAddr aAddrBase, TUint aNumPages);
 	void UnblockSetAllocRuns(TUint& aOffset1, TUint& aOffset2, TUint aRunLength1, TUint aRunLength2, TUint& aAllocLength, TUint& aAllocStart);
 	void UnblockContiguousRegion(TPhysAddr aAddrBase, TUint aNumPages);
-	TBool ClearContiguousRegion(TPhysAddr aAddrBase, TPhysAddr aZoneBase, TUint aNumPages, TInt& aOffset);
+	TBool ClearContiguousRegion(TPhysAddr aAddrBase, TPhysAddr aZoneBase, TUint aNumPages, TInt& aOffsetm, TUint aUnreservedPages);
+	TUint CountPagesInRun(TPhysAddr aAddrBase, TPhysAddr aAddrEndPage, TZonePageType aType);
 #endif
 	TInt ZoneAllocContiguousRam(TUint* aZoneIdList, TUint aZoneIdCount, TInt aSize, TPhysAddr& aPhysAddr, TInt aAlign);
 #ifdef _DEBUG
--- a/kernel/eka/include/u32hal.h	Tue May 11 17:28:22 2010 +0300
+++ b/kernel/eka/include/u32hal.h	Tue May 25 14:09:55 2010 +0300
@@ -2748,6 +2748,59 @@
 	@see TChanges
 	*/ 
 	EVMHalSetThrashThresholds,
+
+	/**
+	Indicate whether the data paging media driver supports access by physical address.
+
+	@return 1 if it does, 0 if it does not and KErrNotSupported if data paging is not enabled.
+	*/
+	EVMHalGetPhysicalAccessSupported,
+
+	/**
+	Indicate whether the data paging media driver currently uses physical access for writing out
+	dirty data pages to swap.
+
+	@return 1 if it does, 0 if it does not and KErrNotSupported if data paging is not enabled.
+	*/
+	EVMHalGetUsePhysicalAccess,
+
+	/**
+	Set whether physical access is used for writing out dirty data pages to swap.
+
+	The first argument (a1) should contain zero or one to indicate whether to disable or enable
+	physical access respectively.
+	
+	@return KErrNone if successful, KErrNotSupported if data paging is not enabled.
+	*/
+	EVMHalSetUsePhysicalAccess,
+
+	/**
+	Get the data paging media driver's preferred write size.
+
+	@return Log2 of the preferred write size in pages, or KErrNotSupported if data paging is not
+	enabled.
+	*/
+	EVMHalGetPreferredDataWriteSize,
+
+	/**
+	Get the number of pages that the pager attempts to write at a time when paging out dirty pages
+	to swap.
+
+	@return Log2 of the current write size in pages, or KErrNotSupported if data paging is not
+	enabled.
+	*/
+	EVMHalGetDataWriteSize,
+
+	/**
+	Set the number of pages that the pager attempts to write at a time when paging out dirty pages
+	to swap.
+	
+	The first argument (a1) should contain log2 of the write size in pages.
+
+	@return KErrArgument if the value is out of range, or KErrNotSupported if data paging is not
+	enabled.
+	*/
+	EVMHalSetDataWriteSize,
 	};
 
 
--- a/kernel/eka/klib/arm/cbma.cia	Tue May 11 17:28:22 2010 +0300
+++ b/kernel/eka/klib/arm/cbma.cia	Tue May 25 14:09:55 2010 +0300
@@ -336,6 +336,81 @@
 	}
 
 
+/**	Allocates a specific range of bit positions.
+	
+	The specified range must lie within the total range for this allocator but it is
+	not necessary that all the positions are currently free.
+
+	@param	aStart	First position to allocate.
+	@param	aLength	Number of consecutive positions to allocate, must be >0.
+	@return The number of previously free positions that were allocated.
+ */
+EXPORT_C __NAKED__ TUint TBitMapAllocator::SelectiveAlloc(TInt /*aStart*/, TInt /*aLength*/)
+	{
+	asm("ldr r3, [r0, #%a0] " : : "i" _FOFF(TBitMapAllocator, iSize));	// r3->iSize
+	asm("stmfd sp!, {r4-r8,lr} ");
+	asm("adds r4, r1, r2 ");			// r4 = aStart + aLength
+	asm("bcs 0f ");						// if (aStart + aLength < aStart)
+	asm("cmp r4, r3 ");					// if (aStart + aLength > iSize)
+	asm("bhi 0f ");
+	asm("mov r7, r0 ");					// r7 = this
+	asm("mov r4, r1, lsr #5 ");			// r4 = wix = aStart >> 5
+	asm("and r1, r1, #0x1f ");			// r1 = sbit = aStart & 31
+	asm("ldr r6, [r7, #%a0] " : : "i" _FOFF(TBitMapAllocator, iAvail));	// r6 = iAvail
+	asm("add r4, r7, r4, lsl #2 ");	
+	asm("add r4, r4, #%a0 " : : "i" _FOFF(TBitMapAllocator, iMap));		// r4 = iMap + wix
+	asm("sub r6, r6, r2 ");				// r6 = iAvail -= aLength
+	asm("add r5, r2, r1 ");				// r5 = ebit =  sbit + aLength
+	asm("mvn r0, #0 ");
+	asm("mvn r0, r0, lsr r1 ");			// r0 = b = ~(0xffffffff >> sbit)
+	asm("cmp r5, #32 ");
+	asm("mov r8, r2");					// r8 = aLength
+	asm("bhi salloc_cross_bdry ");		// branch if (ebit >=32)
+
+	asm("mvn r5, #0 ");					// r5 = 0xffffffff
+	asm("mov r5, r5, lsr r8 ");			// r5 >> aLength
+	asm("mov r5, r5, lsr r1 ");			// r5 >> sbit
+	asm("orr r5, r5, r0 ");				// r5 = b = r0 | r5
+	asm("ldr r0, [r4] ");				// r0 = w = *pW
+	asm("and r1, r0, r5 ");				// r1 = w & b, clear the positions to be allocated
+	asm("str r1, [r4] ");				// *pW = r1, store new bit map word.
+	asm("mvn r0, r0");					// r0 = ~w
+	asm("mvn r5, r5");					// r5 = ~b
+	asm("and r0, r0, r5");				// r0 = ~w & ~b
+	asm("bl " CSM_CFUNC(__e32_bit_count_32));
+	asm("add r6, r6, r0 ");				// r6 = iAvail + allocated
+	asm("sub r0, r8, r0 ");				// return aLength - allocated
+	asm("str r6, [r7] ");				// iAvail += allocated, store free count
+	asm("ldmfd sp!, {r4-r8,pc} ");		// return
+	
+	asm("salloc_cross_bdry: ");			// r0 = b, r8 = aLength, r7 = this, r5 = ebit
+	asm("ldr r2, [r4] ");				// r2 = w = *pW
+	asm("and r1, r2, r0 ");				// r1 = w & b
+	asm("str r1, [r4], #4 ");			// *pW++ = r1, store new bit mask
+	asm("mvn r2, r2");					// r2 = ~w
+	asm("mvn r0, r0");					// r0 = ~b
+	asm("and r0, r0, r2");				// r0 = ~w & ~b
+	asm("bl " CSM_CFUNC(__e32_bit_count_32));
+	asm("add r6, r6, r0 ");				// r6 = iAvail += allocated
+	asm("sub r8, r8, r0 ");				// r8 = aLength -= allocated
+	asm("subs r5, r5, #32 ");			// r5 = ebit -= 32
+	asm("bls salloc_return ");			// ebit < 0 so return.
+	asm("cmp r5, #32 ");				// if (ebit < 32) {
+	asm("mvnlt r0, #0 ");
+	asm("movlt r0, r0, lsr r5 ");		// r0 = 0xffffffff >> ebit }
+	asm("movge r0, #0 ");				// if (ebit >= 32) r0 = b = 0
+	asm("b salloc_cross_bdry ");
+
+	asm("salloc_return: ");
+	asm("str r6, [r7] ");				// iAvail += allocated, store free count
+	asm("mov r0, r8 ");					// return aLength
+	asm("ldmfd sp!, {r4-r8,pc} ");		// return
+
+	asm("0: ");
+	ASM_FAULT();
+	}
+
+
 /**	Tests if a specific range of bit positions are all free
 	Specified range must lie within the total range for this allocator.
 
--- a/kernel/eka/klib/bma.cpp	Tue May 11 17:28:22 2010 +0300
+++ b/kernel/eka/klib/bma.cpp	Tue May 25 14:09:55 2010 +0300
@@ -433,6 +433,49 @@
 	}
 
 
+/**	Allocates a specific range of bit positions.
+	
+	The specified range must lie within the total range for this allocator but it is
+	not necessary that all the positions are currently free.
+
+	@param	aStart	First position to allocate.
+	@param	aLength	Number of consecutive positions to allocate, must be >0.
+	@return The number of previously free positions that were allocated.
+ */
+EXPORT_C TUint TBitMapAllocator::SelectiveAlloc(TInt aStart, TInt aLength)
+	{
+	__ASSERT_ALWAYS(TUint(aStart) < TUint(iSize), TBMA_FAULT());
+	__ASSERT_ALWAYS(TUint(aStart + aLength) >= TUint(aStart), TBMA_FAULT());
+	__ASSERT_ALWAYS(TUint(aStart + aLength) <= TUint(iSize), TBMA_FAULT());
+	TInt wix = aStart >> 5;
+	TInt sbit = aStart & 31;
+	TUint32* pW = iMap + wix;
+	iAvail -= aLength;	// update free count assuming no positions already allocated
+	TInt ebit = sbit + aLength;
+	if (ebit < 32)
+		{
+		TUint32 b = ((0xffffffffu >> aLength) >> sbit) | ~(0xffffffffu >> sbit);
+		TUint32 w = *pW;
+		*pW = w & b;	// mark all positions allocated
+		TUint allocated = __e32_bit_count_32(~w & ~b);
+		iAvail += allocated;	// increase free count by number of positions already allocated
+		return aLength - allocated;
+		}
+	TUint32 b = ~(0xffffffffu >> sbit);
+	while (ebit > 0)
+		{
+		TUint32 w = *pW;
+		*pW++ = w & b;		// mark all positions allocated
+		TUint allocated = __e32_bit_count_32(~w & ~b);
+		iAvail += allocated;	// increase free count by number of positions already allocated
+		aLength -= allocated;
+		ebit -= 32;
+		b = (ebit >= 32)? 0 : 0xffffffff >> ebit;
+		}
+	return aLength;
+	}
+
+
 /**	Tests whether a specific range of bit positions are all free.
 
 	The specified range must lie within the total range for this allocator.
@@ -762,49 +805,6 @@
 	}
 
 
-/**	Allocates a specific range of bit positions.
-	
-	The specified range must lie within the total range for this allocator but it is
-	not necessary that all the positions are currently free.
-
-	@param	aStart	First position to allocate.
-	@param	aLength	Number of consecutive positions to allocate, must be >0.
-	@return The number of previously free positions that were allocated.
- */
-EXPORT_C TUint TBitMapAllocator::SelectiveAlloc(TInt aStart, TInt aLength)
-	{
-	__ASSERT_ALWAYS(TUint(aStart) < TUint(iSize), TBMA_FAULT());
-	__ASSERT_ALWAYS(TUint(aStart + aLength) >= TUint(aStart), TBMA_FAULT());
-	__ASSERT_ALWAYS(TUint(aStart + aLength) <= TUint(iSize), TBMA_FAULT());
-	TInt wix = aStart >> 5;
-	TInt sbit = aStart & 31;
-	TUint32* pW = iMap + wix;
-	iAvail -= aLength;	// update free count assuming no positions already allocated
-	TInt ebit = sbit + aLength;
-	if (ebit < 32)
-		{
-		TUint32 b = ((0xffffffffu >> aLength) >> sbit) | ~(0xffffffffu >> sbit);
-		TUint32 w = *pW;
-		*pW = w & b;	// mark all positions allocated
-		TUint allocated = __e32_bit_count_32(~w & ~b);
-		iAvail += allocated;	// increase free count by number of positions already allocated
-		return aLength - allocated;
-		}
-	TUint32 b = ~(0xffffffffu >> sbit);
-	while (ebit > 0)
-		{
-		TUint32 w = *pW;
-		*pW++ = w & b;		// mark all positions allocated
-		TUint allocated = __e32_bit_count_32(~w & ~b);
-		iAvail += allocated;	// increase free count by number of positions already allocated
-		aLength -= allocated;
-		ebit -= 32;
-		b = (ebit >= 32)? 0 : 0xffffffff >> ebit;
-		}
-	return aLength;
-	}
-
-
 /** Copies a range from another allocator, mark remainder as occupied.
 
 	Values of bit positions from aFirst to aFirst+aLen-1 inclusive in allocator
--- a/kernel/eka/memmodel/epoc/flexible/mmu/mcodepaging.cpp	Tue May 11 17:28:22 2010 +0300
+++ b/kernel/eka/memmodel/epoc/flexible/mmu/mcodepaging.cpp	Tue May 25 14:09:55 2010 +0300
@@ -288,7 +288,7 @@
 			__KTRACE_OPT(KPAGING,Kern::Printf("  uncompressed, file offset == %x, size == %d", dataOffset, dataSize));
 			}
 
-		TInt bufferStart = info.iBlockMap.Read(aRequest->iBuffer,
+		TInt bufferStart = info.iBlockMap.Read(aRequest->Buffer(),
 												dataOffset,
 												dataSize,
 												device.iReadUnitShift,
@@ -303,7 +303,7 @@
 			break;
 			}
 
-		TLinAddr data = aRequest->iBuffer + bufferStart;
+		TLinAddr data = aRequest->Buffer() + bufferStart;
 		r = Decompress(info.iCompressionType, linAddr, decompressedSize, data, dataSize);
 		if(r>=0)
 			{
--- a/kernel/eka/memmodel/epoc/flexible/mmu/mdatapaging.cpp	Tue May 11 17:28:22 2010 +0300
+++ b/kernel/eka/memmodel/epoc/flexible/mmu/mdatapaging.cpp	Tue May 25 14:09:55 2010 +0300
@@ -14,6 +14,7 @@
 //
 
 #include <plat_priv.h>
+#include <kernel/cache.h>
 #include "mm.h"
 #include "mmu.h"
 
@@ -25,6 +26,34 @@
 
 
 /**
+Log2 of minimum number of pages to attempt to write at a time.
+
+The value of 2 gives a minimum write size of 16KB.
+*/
+const TUint KMinPreferredWriteShift = 2;
+
+/**
+Log2 of maximum number of pages to attempt to write at a time.
+
+The value of 4 gives a maximum write size of 64KB.
+*/
+const TUint KMaxPreferredWriteShift = 4;
+
+__ASSERT_COMPILE((1 << KMaxPreferredWriteShift) <= KMaxPagesToClean);
+
+
+/**
+Whether the CPU has the page colouring restriction, where pages must be mapped in sequential colour
+order.
+*/
+#ifdef __CPU_CACHE_HAS_COLOUR	
+const TBool KPageColouringRestriction = ETrue;
+#else
+const TBool KPageColouringRestriction = EFalse;
+#endif
+
+
+/**
 Manages the swap via the data paging device.
 */
 class DSwapManager
@@ -57,23 +86,24 @@
 	TInt UnreserveSwap(DMemoryObject* aMemory, TUint aStartIndex, TUint aPageCount);
 	TBool IsReserved(DMemoryObject* aMemory, TUint aStartIndex, TUint aPageCount);
 
-	TInt ReadSwapPages(DMemoryObject* aMemory, TUint aIndex, TUint aCount, TLinAddr aLinAddr, DPageReadRequest* aRequest, TPhysAddr* aPhysAddrs);
-	TInt WriteSwapPages(DMemoryObject** aMemory, TUint* aIndex, TUint aCount, TLinAddr aLinAddr, TBool aBackground);
+	TInt ReadSwapPages(DMemoryObject* aMemory, TUint aIndex, TUint aCount, TLinAddr aLinAddr, TPhysAddr* aPhysAddrs);
+	TInt WriteSwapPages(DMemoryObject** aMemory, TUint* aIndex, TUint aCount, TLinAddr aLinAddr, TPhysAddr* aPhysAddrs, TBool aBackground);
 
 	void GetSwapInfo(SVMSwapInfo& aInfoOut);
 	TInt SetSwapThresholds(const SVMSwapThresholds& aThresholds);
+	void SetSwapAlign(TUint aSwapAlign);
 
 private:
 	inline TSwapState SwapState(TUint aSwapData);
 	inline TInt SwapIndex(TUint aSwapData);
 	inline TUint SwapData(TSwapState aSwapState, TInt aSwapIndex);
 	
-	TInt AllocSwapIndex(TInt aCount);
+	TInt AllocSwapIndex(TUint aCount);
 	void FreeSwapIndex(TInt aSwapIndex);
 	void CheckSwapThresholdsAndUnlock(TUint aInitial);
 	
 	void DoDeleteNotify(TUint aSwapIndex);
-	TInt DoWriteSwapPages(DMemoryObject** aMemory, TUint* aIndex, TUint aCount, TLinAddr aLinAddr, TInt aSwapIndex, TBool aBackground);
+	TInt DoWriteSwapPages(DMemoryObject** aMemory, TUint* aIndex, TUint aCount, TLinAddr aLinAddr, TInt aPageIndex, TPhysAddr* aPhysAddrs, TInt aSwapIndex, TBool aBackground);
 	
 private:
 	DPagingDevice* iDevice;			///< Paging device used to read and write swap pages
@@ -81,6 +111,7 @@
 	NFastMutex iSwapLock;			///< Fast mutex protecting access to all members below
 	TUint iFreePageCount;			///< Number of swap pages that have not been reserved
 	TBitMapAllocator* iBitMap;		///< Bitmap of swap pages that have been allocated
+	TUint iSwapAlign;				///< Log2 number of pages to align swap writes to
 	TUint iAllocOffset;				///< Next offset to try when allocating a swap page
  	TUint iSwapThesholdLow;
  	TUint iSwapThesholdGood;
@@ -88,11 +119,11 @@
 
 
 /**
-Manager for demand paged memory objects which contain writeable data.
-The contents of the memory are written to a backing store whenever its
-pages are 'paged out'.
+   Manager for demand paged memory objects which contain writeable data.
+   The contents of the memory are written to a backing store whenever its
+   pages are 'paged out'.
 
-@see DSwapManager
+   @see DSwapManager
 */
 class DDataPagedMemoryManager : public DPagedMemoryManager
 	{
@@ -114,25 +145,38 @@
 public:
 	void GetSwapInfo(SVMSwapInfo& aInfoOut);
 	TInt SetSwapThresholds(const SVMSwapThresholds& aThresholds);
+	TBool PhysicalAccessSupported();
+	TBool UsePhysicalAccess();
+	void SetUsePhysicalAccess(TBool aUsePhysicalAccess);
+	TUint PreferredWriteSize();
+	TUint PreferredSwapAlignment();
+	TInt SetWriteSize(TUint aWriteShift);
 
 private:
 	TInt WritePages(DMemoryObject** aMemory, TUint* aIndex, TPhysAddr* aPages, TUint aCount, DPageWriteRequest *aRequest, TBool aAnyExecutable, TBool aBackground);
 
 private:
 	/**
-	The paging device used for accessing the backing store.
-	This is set by #InstallPagingDevice.
+	   The paging device used for accessing the backing store.
+	   This is set by #InstallPagingDevice.
 	*/
 	DPagingDevice* iDevice;
 
 	/**
-	The instance of #DSwapManager being used by this manager.
+	   The instance of #DSwapManager being used by this manager.
 	*/
 	DSwapManager* iSwapManager;
 
+	/**
+	   Whether to read and write pages by physical address without mapping them first.
+
+	   Set if the paging media driver supports it.
+	*/
+	TBool iUsePhysicalAccess;
+
 public:
 	/**
-	The single instance of this manager class.
+	   The single instance of this manager class.
 	*/
 	static DDataPagedMemoryManager TheManager;
 	};
@@ -143,9 +187,9 @@
 
 
 /**
-Create a swap manager.
+   Create a swap manager.
 
-@param	aDevice	The demand paging device for access to the swap.
+   @param	aDevice	The demand paging device for access to the swap.
 */
 TInt DSwapManager::Create(DPagingDevice* aDevice)
 	{
@@ -175,6 +219,15 @@
 	}
 
 
+void DSwapManager::SetSwapAlign(TUint aSwapAlign)
+	{
+	TRACE(("WDP: Set swap alignment to %d (%d KB)", aSwapAlign, 4 << aSwapAlign));
+	NKern::FMWait(&iSwapLock);
+	iSwapAlign = aSwapAlign;
+	NKern::FMSignal(&iSwapLock);
+	}
+
+
 inline DSwapManager::TSwapState DSwapManager::SwapState(TUint aSwapData)
 	{
 	TSwapState state = (TSwapState)(aSwapData & ESwapStateMask);
@@ -196,50 +249,73 @@
 
 
 /**
-Allocate one or more page's worth of space within the swap area.
+   Allocate one or more page's worth of space within the swap area.
 
-The location is represented by a page-based index into the swap area.
+   The location is represented by a page-based index into the swap area.
 
-@param aCount The number of page's worth of space to allocate.
+   @param aCount The number of page's worth of space to allocate.
 
-@return The swap index of the first location allocated.
+   @return The swap index of the first location allocated.
 */
-TInt DSwapManager::AllocSwapIndex(TInt aCount)
+TInt DSwapManager::AllocSwapIndex(TUint aCount)
 	{
-	__NK_ASSERT_DEBUG(aCount > 0 && aCount <= KMaxPagesToClean);
+	TRACE2(("DSwapManager::AllocSwapIndex %d", aCount));
+		
+	__NK_ASSERT_DEBUG(aCount <= KMaxPagesToClean);
 	NKern::FMWait(&iSwapLock);
 
-	// search for run of aCount from iAllocOffset to end
-	TInt carry = 0;
+	TInt carry;
 	TInt l = KMaxTInt;
-	TInt swapIndex = iBitMap->AllocAligned(aCount, 0, 0, EFalse, carry, l, iAllocOffset);
+	TInt swapIndex = -1;
 
-	// if search failed, retry from beginning
+	// if size suitable for alignment, search for aligned run of aCount from iAllocOffset to end,
+	// then from beginning
+	// 
+	// note that this aligns writes that at least as large as the alignment size - an alternative
+	// policy might be to align writes that are an exact multiple of the alignment size
+	if (iSwapAlign && aCount >= (1u << iSwapAlign))
+		{
+		carry = 0;
+		swapIndex = iBitMap->AllocAligned(aCount, iSwapAlign, 0, EFalse, carry, l, iAllocOffset);
+		if (swapIndex < 0)
+			{
+			carry = 0;
+			swapIndex = iBitMap->AllocAligned(aCount, iSwapAlign, 0, EFalse, carry, l, 0);
+			}
+		}
+	
+	// if not doing aligned search, or aligned search failed, retry without alignment
 	if (swapIndex < 0)
 		{
-		iAllocOffset = 0;
 		carry = 0;
 		swapIndex = iBitMap->AllocAligned(aCount, 0, 0, EFalse, carry, l, iAllocOffset);
+		if (swapIndex < 0)
+			{
+			carry = 0;
+			swapIndex = iBitMap->AllocAligned(aCount, 0, 0, EFalse, carry, l, 0);
+			}
 		}
 
 	// if we found one then mark it as allocated and update iAllocOffset
 	if (swapIndex >= 0)
 		{
-		__NK_ASSERT_DEBUG(swapIndex <= (iBitMap->iSize - aCount));
+		__NK_ASSERT_DEBUG(swapIndex <= (TInt)(iBitMap->iSize - aCount));
 		iBitMap->Alloc(swapIndex, aCount);
 		iAllocOffset = (swapIndex + aCount) % iBitMap->iSize;
 		}
 	
 	NKern::FMSignal(&iSwapLock);
 	__NK_ASSERT_DEBUG(swapIndex >= 0 || aCount > 1); // can't fail to allocate single page
+
+	TRACE2(("DSwapManager::AllocSwapIndex returns %d", swapIndex));	
 	return swapIndex;
 	}
 
 
 /**
-Free one page's worth of space within the swap area.
+   Free one page's worth of space within the swap area.
 
-The index must have been previously allocated with AllocSwapIndex().
+   The index must have been previously allocated with AllocSwapIndex().
 */
 void DSwapManager::FreeSwapIndex(TInt aSwapIndex)
 	{
@@ -252,15 +328,15 @@
 
 
 /**
-Reserve some swap pages for the requested region of the memory object
+   Reserve some swap pages for the requested region of the memory object
 
-@param aMemory		The memory object to reserve pages for.
-@param aStartIndex	The page index in the memory object of the start of the region.
-@param aPageCount	The number of pages to reserve.
+   @param aMemory		The memory object to reserve pages for.
+   @param aStartIndex	The page index in the memory object of the start of the region.
+   @param aPageCount	The number of pages to reserve.
 
-@return KErrNone on success, KErrNoMemory if not enough swap space available.
-@pre aMemory's lock is held.
-@post aMemory's lock is held.
+   @return KErrNone on success, KErrNoMemory if not enough swap space available.
+   @pre aMemory's lock is held.
+   @post aMemory's lock is held.
 */
 TInt DSwapManager::ReserveSwap(DMemoryObject* aMemory, TUint aStartIndex, TUint aPageCount)
 	{
@@ -293,15 +369,15 @@
 
 
 /**
-Unreserve swap pages for the requested region of the memory object.
+   Unreserve swap pages for the requested region of the memory object.
 
-@param aMemory		The memory object to unreserve pages for.
-@param aStartIndex	The page index in the memory object of the start of the region.
-@param aPageCount	The number of pages to unreserve.
+   @param aMemory		The memory object to unreserve pages for.
+   @param aStartIndex	The page index in the memory object of the start of the region.
+   @param aPageCount	The number of pages to unreserve.
 
-@return The number of pages freed.
-@pre aMemory's lock is held.
-@post aMemory's lock is held.
+   @return The number of pages freed.
+   @pre aMemory's lock is held.
+   @post aMemory's lock is held.
 */
 TInt DSwapManager::UnreserveSwap(DMemoryObject* aMemory, TUint aStartIndex, TUint aPageCount)
 	{
@@ -348,13 +424,13 @@
 
 
 /**
-Determine whether the specified pages in the memory object have swap reserved for them.
+   Determine whether the specified pages in the memory object have swap reserved for them.
 
-@param aMemory		The memory object that owns the pages.
-@param aStartIndex	The first index of the pages to check.
-@param aPageCount	The number of pages to check.
+   @param aMemory		The memory object that owns the pages.
+   @param aStartIndex	The first index of the pages to check.
+   @param aPageCount	The number of pages to check.
 
-@return ETrue if swap is reserved for all the pages, EFalse otherwise.
+   @return ETrue if swap is reserved for all the pages, EFalse otherwise.
 */
 TBool DSwapManager::IsReserved(DMemoryObject* aMemory, TUint aStartIndex, TUint aPageCount)
 	{// MmuLock required to protect manager data.
@@ -375,16 +451,16 @@
 
 
 /**
-Read from the swap the specified pages associated with the memory object.
+   Read from the swap the specified pages associated with the memory object.
 
-@param aMemory 	The memory object to read the pages for
-@param aIndex	The index of the first page within the memory object.
-@param aCount	The number of pages to read.
-@param aLinAddr	The address to copy the pages to.
-@param aRequest	The request to use for the read.
-@param aPhysAddrs	An array of the physical addresses for each page to read in.
+   @param aMemory 	The memory object to read the pages for
+   @param aIndex	The index of the first page within the memory object.
+   @param aCount	The number of pages to read.
+   @param aLinAddr	The address to copy the pages to.
+   @param aRequest	The request to use for the read.
+   @param aPhysAddrs	An array of the physical addresses for each page to read in.
 */
-TInt DSwapManager::ReadSwapPages(DMemoryObject* aMemory, TUint aIndex, TUint aCount, TLinAddr aLinAddr, DPageReadRequest* aRequest, TPhysAddr* aPhysAddrs)
+TInt DSwapManager::ReadSwapPages(DMemoryObject* aMemory, TUint aIndex, TUint aCount, TLinAddr aLinAddr, TPhysAddr* aPhysAddrs)
 	{
 	__ASSERT_CRITICAL;
 	
@@ -447,19 +523,21 @@
 
 
 /**
-Write the specified memory object's pages from the RAM into the swap.
+   Write the specified memory object's pages from the RAM into the swap.
 
-@param	aMemory		The memory object who owns the pages.
-@param	aIndex		The index within the memory object.
-@param 	aCount		The number of pages to write out.
-@param	aLinAddr	The location of the pages to write out.
-@param  aBackground Whether this is being called in the background by the page cleaning thread
-                    as opposed to on demand when a free page is required.
+   @param	aMemory		The memory object who owns the pages.
+   @param	aIndex		The index within the memory object.
+   @param 	aCount		The number of pages to write out.
+   @param	aLinAddr	The location of the pages to write out.
+   @param  aBackground Whether this is being called in the background by the page cleaning thread
+   as opposed to on demand when a free page is required.
 
-@pre Called with page cleaning lock held
+   @pre Called with page cleaning lock held
 */
-TInt DSwapManager::WriteSwapPages(DMemoryObject** aMemory, TUint* aIndex, TUint aCount, TLinAddr aLinAddr, TBool aBackground)
+TInt DSwapManager::WriteSwapPages(DMemoryObject** aMemory, TUint* aIndex, TUint aCount, TLinAddr aLinAddr, TPhysAddr* aPhysAddrs, TBool aBackground)
 	{
+	TRACE(("DSwapManager::WriteSwapPages %d pages", aCount));
+	
 	__ASSERT_CRITICAL;  // so we can pass the paging device a stack-allocated TThreadMessage
 	__NK_ASSERT_DEBUG(PageCleaningLock::IsHeld());
 
@@ -503,13 +581,13 @@
 			if (startIndex != -1)
 				{
 				// write pages from startIndex to i exclusive
-				TInt count = i - startIndex;
+				TUint count = i - startIndex;
 				__NK_ASSERT_DEBUG(count > 0 && count <= KMaxPagesToClean);
 
 				// Get a new swap location for these pages, writing them all together if possible
 				TInt swapIndex = AllocSwapIndex(count);
 				if (swapIndex >= 0)
-					r = DoWriteSwapPages(&aMemory[startIndex], &aIndex[startIndex], count, aLinAddr + (startIndex << KPageShift), swapIndex, aBackground);
+					r = DoWriteSwapPages(&aMemory[startIndex], &aIndex[startIndex], count, aLinAddr, startIndex, aPhysAddrs, swapIndex, aBackground);
 				else
 					{
 					// Otherwise, write them individually
@@ -517,7 +595,7 @@
 						{
 						swapIndex = AllocSwapIndex(1);
 						__NK_ASSERT_DEBUG(swapIndex >= 0);
-						r = DoWriteSwapPages(&aMemory[j], &aIndex[j], 1, aLinAddr + (j << KPageShift), swapIndex, aBackground);
+						r = DoWriteSwapPages(&aMemory[j], &aIndex[j], 1, aLinAddr, j, &aPhysAddrs[j], swapIndex, aBackground);
 						if (r != KErrNone)
 							break;
 						}
@@ -533,16 +611,22 @@
 	return r;
 	}
 
-TInt DSwapManager::DoWriteSwapPages(DMemoryObject** aMemory, TUint* aIndex, TUint aCount, TLinAddr aLinAddr, TInt aSwapIndex, TBool aBackground)
+TInt DSwapManager::DoWriteSwapPages(DMemoryObject** aMemory, TUint* aIndex, TUint aCount, TLinAddr aLinAddr, TInt aPageIndex, TPhysAddr* aPhysAddrs, TInt aSwapIndex, TBool aBackground)
 	{	
+	TRACE2(("DSwapManager::DoWriteSwapPages %d pages to %d", aCount, aSwapIndex));
 		
 	const TUint readUnitShift = iDevice->iReadUnitShift;
 	const TUint writeSize = aCount << (KPageShift - readUnitShift);
 	const TUint writeOffset = aSwapIndex << (KPageShift - readUnitShift);
-		
+
 	TThreadMessage msg;
 	START_PAGING_BENCHMARK;
-	TInt r = iDevice->Write(&msg, aLinAddr, writeOffset, writeSize, aBackground);
+	TInt r;
+	if (aLinAddr == 0)
+		r = iDevice->WritePhysical(&msg, aPhysAddrs, aCount, writeOffset, aBackground);
+	else
+		r = iDevice->Write(&msg, aLinAddr + (aPageIndex << KPageShift), writeOffset, writeSize, aBackground);
+		
 	if (r != KErrNone)
 		{
 		__KTRACE_OPT(KPANIC, Kern::Printf("DSwapManager::WriteSwapPages: error writing media from %08x to %08x + %x: %d", aLinAddr, writeOffset << readUnitShift, writeSize << readUnitShift, r));
@@ -643,6 +727,63 @@
 	}
 
 
+TBool DDataPagedMemoryManager::PhysicalAccessSupported()
+	{
+	return (iDevice->iFlags & DPagingDevice::ESupportsPhysicalAccess) != 0;
+	}
+
+
+TBool DDataPagedMemoryManager::UsePhysicalAccess()
+	{
+	return iUsePhysicalAccess;
+	}
+
+
+void DDataPagedMemoryManager::SetUsePhysicalAccess(TBool aUsePhysicalAccess)
+	{
+	TRACE(("WDP: Use physical access set to %d", aUsePhysicalAccess));
+	NKern::ThreadEnterCS();
+	PageCleaningLock::Lock();
+	iUsePhysicalAccess = aUsePhysicalAccess;
+	ThePager.SetCleanInSequence(!iUsePhysicalAccess && KPageColouringRestriction);
+	PageCleaningLock::Unlock();
+	NKern::ThreadLeaveCS();
+	}
+
+
+TUint DDataPagedMemoryManager::PreferredWriteSize()
+	{
+	return MaxU(iDevice->iPreferredWriteShift, KMinPreferredWriteShift + KPageShift) - KPageShift;
+	}
+
+
+TUint DDataPagedMemoryManager::PreferredSwapAlignment()
+	{
+	return MaxU(iDevice->iPreferredWriteShift, KPageShift) - KPageShift;
+	}
+
+
+TInt DDataPagedMemoryManager::SetWriteSize(TUint aWriteShift)
+	{
+	TRACE(("WDP: Set write size to %d (%d KB)", aWriteShift, 4 << aWriteShift));
+	// Check value is sensible
+	if (aWriteShift > 31)
+		return KErrArgument;
+	if (aWriteShift > KMaxPreferredWriteShift)
+		{
+		aWriteShift = KMaxPreferredWriteShift;
+		TRACE(("WDP: Reduced write size to %d (%d KB)",
+			   aWriteShift, 4 << aWriteShift));
+
+		}
+	NKern::ThreadEnterCS();
+	PageCleaningLock::Lock();
+	ThePager.SetPagesToClean(1 << aWriteShift);
+	PageCleaningLock::Unlock();
+	NKern::ThreadLeaveCS();
+	return KErrNone;
+	}
+
 
 TInt DDataPagedMemoryManager::InstallPagingDevice(DPagingDevice* aDevice)
 	{
@@ -664,9 +805,11 @@
 
 	// Now we can determine the size of the swap, create the swap manager.
 	iSwapManager = new DSwapManager;
-	__NK_ASSERT_ALWAYS(iSwapManager);
+	if (!iSwapManager)
+		return KErrNoMemory;
 
-	TInt r = iSwapManager->Create(iDevice);
+	// Create swap manager object
+	TInt r = iSwapManager->Create(aDevice);
 	if (r != KErrNone)
 		{// Couldn't create the swap manager.
 		delete iSwapManager;
@@ -674,6 +817,25 @@
 		NKern::SafeSwap(NULL, (TAny*&)iDevice);
 		return r;
 		}
+
+	// Enable physical access where supported
+	SetUsePhysicalAccess(PhysicalAccessSupported());
+	
+	// Determine swap alignment and number of pages to clean at once from device's preferred write
+	// size, if set
+	TRACE(("WDP: Preferred write shift is %d", iDevice->iPreferredWriteShift));
+	r = SetWriteSize(PreferredWriteSize());
+	if (r != KErrNone)
+		{
+		delete iSwapManager;
+		iSwapManager = NULL;
+		NKern::SafeSwap(NULL, (TAny*&)iDevice);
+		return r;
+		}
+
+	// Set swap alignment
+	iSwapManager->SetSwapAlign(PreferredSwapAlignment());
+	
  	NKern::LockedSetClear(K::MemModelAttributes, 0, EMemModelAttrDataPaging);
 
 	return r;
@@ -746,10 +908,15 @@
 	{
 	__NK_ASSERT_DEBUG(aRequest->CheckUseContiguous(aMemory,aIndex,aCount));
 
+	// todo: Possible to read using physical addresses here, but not sure it's worth it because it's
+	// not much saving and we may need to map the page anyway if it's blank to clear it
+	// 
+	// todo: Could move clearing pages up to here maybe?
+
 	// Map pages temporarily so that we can copy into them.
 	const TLinAddr linAddr = aRequest->MapPages(aIndex, aCount, aPages);
 
-	TInt r = iSwapManager->ReadSwapPages(aMemory, aIndex, aCount, linAddr, aRequest, aPages);
+	TInt r = iSwapManager->ReadSwapPages(aMemory, aIndex, aCount, linAddr, aPages);
 
 	// The memory object allows executable mappings then need IMB.
 	aRequest->UnmapPages(aMemory->IsExecutable());
@@ -760,13 +927,28 @@
 
 TInt DDataPagedMemoryManager::WritePages(DMemoryObject** aMemory, TUint* aIndex, TPhysAddr* aPages, TUint aCount, DPageWriteRequest* aRequest, TBool aAnyExecutable, TBool aBackground)
 	{
-	// Map pages temporarily so that we can copy into them.
-	const TLinAddr linAddr = aRequest->MapPages(aIndex[0], aCount, aPages);
+	// Note: this method used to do an IMB for executable pages (like ReadPages) but it was thought
+	// that this was uncessessary and so was removed
+
+	TLinAddr linAddr = 0;
 
-	TInt r = iSwapManager->WriteSwapPages(aMemory, aIndex, aCount, linAddr, aBackground);
+	if (iUsePhysicalAccess)
+		{
+		// must maps pages to perform cache maintenance but can map each page individually
+		for (TUint i = 0 ; i < aCount ; ++i)
+			{
+			TLinAddr addr = aRequest->MapPages(aIndex[i], 1, &aPages[i]);
+			Cache::SyncMemoryBeforeDmaWrite(addr, KPageSize);
+			aRequest->UnmapPages(EFalse);
+			}
+		}
+	else
+		linAddr = aRequest->MapPages(aIndex[0], aCount, aPages);
+	
+	TInt r = iSwapManager->WriteSwapPages(aMemory, aIndex, aCount, linAddr, aPages, aBackground);
 
-	// The memory object allows executable mappings then need IMB.
-	aRequest->UnmapPages(aAnyExecutable);
+	if (linAddr != 0)
+		aRequest->UnmapPages(EFalse);
 
 	return r;
 	}
@@ -774,6 +956,8 @@
 
 void DDataPagedMemoryManager::CleanPages(TUint aPageCount, SPageInfo** aPageInfos, TBool aBackground)
 	{
+	TRACE(("DDataPagedMemoryManager::CleanPages %d", aPageCount));
+	
 	__NK_ASSERT_DEBUG(PageCleaningLock::IsHeld());
 	__NK_ASSERT_DEBUG(MmuLock::IsHeld());
 	__NK_ASSERT_DEBUG(aPageCount <= (TUint)KMaxPagesToClean);
@@ -783,7 +967,7 @@
 	TUint index[KMaxPagesToClean];
 	TPhysAddr physAddr[KMaxPagesToClean];
 	TBool anyExecutable = EFalse;
-	
+
 	for (i = 0 ; i < aPageCount ; ++i)
 		{
 		SPageInfo* pi = aPageInfos[i];
@@ -819,7 +1003,8 @@
 		{
 		SPageInfo* pi = aPageInfos[i];
 		// check if page is clean...
-		if(pi->CheckModified(&memory[0]) || pi->IsWritable())
+		if(pi->CheckModified(&memory[0]) ||
+		   pi->IsWritable())
 			{
 			// someone else modified the page, or it became writable, so mark as not cleaned
 			aPageInfos[i] = NULL;
@@ -866,4 +1051,34 @@
 	{
 	return ((DDataPagedMemoryManager*)TheDataPagedMemoryManager)->SetSwapThresholds(aThresholds);
 	}
-  
+
+
+TBool GetPhysicalAccessSupported()
+	{
+	return ((DDataPagedMemoryManager*)TheDataPagedMemoryManager)->PhysicalAccessSupported();
+	}
+
+
+TBool GetUsePhysicalAccess()
+	{
+	return ((DDataPagedMemoryManager*)TheDataPagedMemoryManager)->UsePhysicalAccess();
+	}
+
+
+void SetUsePhysicalAccess(TBool aUsePhysicalAccess)
+	{
+	((DDataPagedMemoryManager*)TheDataPagedMemoryManager)->SetUsePhysicalAccess(aUsePhysicalAccess);
+	}
+
+
+TUint GetPreferredDataWriteSize()
+	{
+	return ((DDataPagedMemoryManager*)TheDataPagedMemoryManager)->PreferredWriteSize();
+	}
+
+
+TInt SetDataWriteSize(TUint aWriteShift)
+	{
+	return	((DDataPagedMemoryManager*)TheDataPagedMemoryManager)->SetWriteSize(aWriteShift);
+	}
+
--- a/kernel/eka/memmodel/epoc/flexible/mmu/mdefrag.cpp	Tue May 11 17:28:22 2010 +0300
+++ b/kernel/eka/memmodel/epoc/flexible/mmu/mdefrag.cpp	Tue May 25 14:09:55 2010 +0300
@@ -115,14 +115,14 @@
 	RamAllocLock::Lock();
 
 	// Move the page to any RAM zone.
-	r = M::MovePage(aOld, aNew, KRamZoneInvalidId, EFalse);
+	r = M::MovePage(aOld, aNew, KRamZoneInvalidId, 0);
 
 	RamAllocLock::Unlock();
 	return r;
 	}
 
 
-TInt M::MovePage(TPhysAddr aOld, TPhysAddr& aNew, TUint aBlockZoneId, TBool aBlockRest)
+TInt M::MovePage(TPhysAddr aOld, TPhysAddr& aNew, TUint aBlockZoneId, TUint aMoveDisFlags)
 	{
 	// Returns this when page is not paged or managed or free but is a real RAM page.
 	TInt r = KErrNotSupported;
@@ -130,12 +130,12 @@
 	// get memory object corresponding to the page...
 	DMemoryObject* memory = 0;
 	MmuLock::Lock();
-	SPageInfo* pi = SPageInfo::SafeFromPhysAddr(aOld&~KPageMask);
-	if(pi)
+	SPageInfo* pi = SPageInfo::SafeFromPhysAddr(aOld & ~KPageMask);
+	if (pi)
 		{
 		if (pi->PagedState() != SPageInfo::EUnpaged)
 			{// The page is paged so let the pager handle it.
-			return ThePager.DiscardPage(pi, aBlockZoneId, aBlockRest);
+			return ThePager.DiscardPage(pi, aBlockZoneId, aMoveDisFlags);
 			}
 		switch (pi->Type())
 			{
@@ -149,7 +149,8 @@
 				// i.e. we don't need to Open() the memory object.
 				MmuLock::Unlock();
 				// move page...
-				r = memory->iManager->MovePage(memory, pi, aNew, aBlockZoneId, aBlockRest);
+				r = memory->iManager->MovePage(	memory, pi, aNew, aBlockZoneId, 
+												(aMoveDisFlags & M::EMoveDisBlockRest)!=0);
 				break;
 			case SPageInfo::EUnused:
 				r = KErrNotFound;	// This page is free so nothing to do.
--- a/kernel/eka/memmodel/epoc/flexible/mmu/mdefrag.inl	Tue May 11 17:28:22 2010 +0300
+++ b/kernel/eka/memmodel/epoc/flexible/mmu/mdefrag.inl	Tue May 25 14:09:55 2010 +0300
@@ -50,10 +50,10 @@
 	}
 
 
-inline TInt M::DiscardPage(TPhysAddr aAddr, TUint aBlockZoneId, TBool aBlockRest)
+inline TInt M::DiscardPage(TPhysAddr aAddr, TUint aBlockZoneId, TUint aMoveDisFlags)
 	{
 	TPhysAddr newAddr;
-	return MovePage(aAddr, newAddr, aBlockZoneId, aBlockRest);
+	return MovePage(aAddr, newAddr, aBlockZoneId, aMoveDisFlags);
 	}
 
 
@@ -75,3 +75,9 @@
 								aZone->iPhysPages,
 								(Mmu::TRamAllocFlags)EMemAttStronglyOrdered);
 	}
+
+
+inline TBool M::GetFreePages(TUint aNumPages)
+	{
+	return ThePager.GetFreePages(aNumPages);
+	}
--- a/kernel/eka/memmodel/epoc/flexible/mmu/mm.h	Tue May 11 17:28:22 2010 +0300
+++ b/kernel/eka/memmodel/epoc/flexible/mmu/mm.h	Tue May 25 14:09:55 2010 +0300
@@ -1091,6 +1091,14 @@
 FORCE_INLINE void FlagClear(T& a,const T b,const T c,const T d)
 	{ a = (T)(a&~b&~c&~d); }
 
+/// Utility function to calculate the minimum of two unsigned integers
+FORCE_INLINE TUint MinU(TUint a, TUint b)
+	{ return a <= b ? a : b; }
+
+/// Utility function to calculate the maximum of two unsigned integers
+FORCE_INLINE TUint MaxU(TUint a, TUint b)
+	{ return a >= b ? a : b; }
+
 
 #include <memmodel/epoc/mmubase/kblockmap.h>
 
--- a/kernel/eka/memmodel/epoc/flexible/mmu/mmanager.cpp	Tue May 11 17:28:22 2010 +0300
+++ b/kernel/eka/memmodel/epoc/flexible/mmu/mmanager.cpp	Tue May 25 14:09:55 2010 +0300
@@ -137,6 +137,7 @@
 
 TInt DMemoryManager::MoveAndAllocPage(DMemoryObject*, SPageInfo*, TZonePageType)
 	{
+	__NK_ASSERT_DEBUG(0);	// This should only be invoked on managers that can move or discard pages.
 	return KErrNotSupported;
 	}
 
@@ -816,7 +817,8 @@
 	// If the page array entry (*movingPageArrayPtr) has been modified then a pinning 
 	// veto'd the preparation.
 	MmuLock::Lock();
-	if (aOldPageInfo->CheckModified(&pageIter) || oldPageEntry != *movingPageArrayPtr)
+	if (aOldPageInfo->CheckModified(&pageIter) ||
+		oldPageEntry != *movingPageArrayPtr)
 		{// Page is pinned or has been modified by another operation.
 		MmuLock::Unlock();
 		TheMmu.FreeRam(&newPage, 1, aMemory->iManager->PageType());
@@ -841,7 +843,8 @@
 #endif
 	
 	MmuLock::Lock();
-	if (!aOldPageInfo->CheckModified(&pageIter) && oldPageEntry == *movingPageArrayPtr &&
+	if (!aOldPageInfo->CheckModified(&pageIter) &&
+		oldPageEntry == *movingPageArrayPtr &&
 		!aMemory->MappingAddedFlag())
 		{
 		// The page has been copied without anyone modifying it so set the page 
@@ -1119,7 +1122,10 @@
 
 			// attempt to clean the page if it is dirty...
 			if (aPageInfo->IsDirty())
+				{
+				//Kern::Printf("WDP: Cleaning single page in StealPage");
 				aMemory->iManager->CleanPages(1, &aPageInfo, EFalse);
+				}
 
 			if(aPageInfo)
 				{
@@ -1535,10 +1541,7 @@
 
 	page = *p;
 	if(aPageInfo->CheckModified(&pageList) || page!=originalPage/*page state changed*/)
-		{
-		// page state was changed by someone else...
 		r = KErrInUse;
-		}
 	else
 		{
 		// nobody else has modified page state, so restrictions successfully applied...
@@ -1677,6 +1680,8 @@
 	TRACE(("DPagedMemoryManager::DoPin(0x%08x,0x%08x,0x%08x,0x%08x)",aMemory, aIndex, aCount, aMapping));
 	__ASSERT_CRITICAL;
 	__NK_ASSERT_DEBUG(aPinArgs.HaveSufficientPages(aCount));
+	__NK_ASSERT_DEBUG(aMapping->IsPinned());
+	__NK_ASSERT_DEBUG(!aMapping->PagesPinned());
 
 	// check and allocate page array entries...
 	RPageArray::TIter pageList;
--- a/kernel/eka/memmodel/epoc/flexible/mmu/mmapping.h	Tue May 11 17:28:22 2010 +0300
+++ b/kernel/eka/memmodel/epoc/flexible/mmu/mmapping.h	Tue May 25 14:09:55 2010 +0300
@@ -237,7 +237,7 @@
 	*/
 	FORCE_INLINE TBool IsPinned()
 		{ return Flags()&EPinned; }
-		
+
 	/**
 	Return true if this mapping physically pins the memory it maps.
 	*/
@@ -245,6 +245,12 @@
 		{ return Flags()&EPhysicalPinningMapping; }
 
 	/**
+	Return true if this mapping has beed successfully attached to a memory object, pinning its pages.
+	*/
+	FORCE_INLINE TBool PagesPinned()
+		{ return Flags()&EPagesPinned; }		
+		
+	/**
 	Return the access permissions which this mapping uses to maps memory.
 	*/
 	FORCE_INLINE TMappingPermissions Permissions()
--- a/kernel/eka/memmodel/epoc/flexible/mmu/mmu.cpp	Tue May 11 17:28:22 2010 +0300
+++ b/kernel/eka/memmodel/epoc/flexible/mmu/mmu.cpp	Tue May 25 14:09:55 2010 +0300
@@ -859,8 +859,14 @@
 		}
 #endif
 	TInt missing = iRamPageAllocator->AllocRamPages(aPages, aCount, aZonePageType, aBlockZoneId, aBlockRest);
-	if(missing && !(aFlags&EAllocNoPagerReclaim) && ThePager.GetFreePages(missing))
-		missing = iRamPageAllocator->AllocRamPages(aPages, aCount, aZonePageType, aBlockZoneId, aBlockRest);
+	if(missing && !(aFlags&EAllocNoPagerReclaim))
+		{
+		// taking the page cleaning lock here prevents the pager releasing the ram alloc lock
+		PageCleaningLock::Lock();  
+		if (ThePager.GetFreePages(missing))
+			missing = iRamPageAllocator->AllocRamPages(aPages, aCount, aZonePageType, aBlockZoneId, aBlockRest);
+		PageCleaningLock::Unlock();  
+		}
 	TInt r = missing ? KErrNoMemory : KErrNone;
 	if(r!=KErrNone)
 		iRamAllocFailed = ETrue;
--- a/kernel/eka/memmodel/epoc/flexible/mmu/mmu.h	Tue May 11 17:28:22 2010 +0300
+++ b/kernel/eka/memmodel/epoc/flexible/mmu/mmu.h	Tue May 25 14:09:55 2010 +0300
@@ -571,6 +571,23 @@
 		}
 
 	/**
+	Mark this page as an oldest old page.
+
+	This does not mark the object as modified as conceptually it's still an oldest page.  This means
+	that if a page goes from young -> old -> oldest the second transition will not interrupt the
+	page restriction that happens on the first.
+
+	@pre #MmuLock held.
+	*/
+	FORCE_INLINE void SetOldestPage(TPagedState aPagedState)
+		{
+		CheckAccess("SetPagedState");
+		__NK_ASSERT_DEBUG(iPagedState==EPagedOld);
+		__NK_ASSERT_DEBUG(aPagedState==EPagedOldestClean || aPagedState==EPagedOldestDirty);
+		iPagedState = aPagedState;
+		}
+
+	/**
 	Set the page's #iModifier value.
 
 	#iModifier is cleared to zero whenever the usage or paging state of the page
--- a/kernel/eka/memmodel/epoc/flexible/mmu/mpager.cpp	Tue May 11 17:28:22 2010 +0300
+++ b/kernel/eka/memmodel/epoc/flexible/mmu/mpager.cpp	Tue May 25 14:09:55 2010 +0300
@@ -43,21 +43,34 @@
 */
 const TUint	KAbsoluteMaxPageCount = (1u<<(32-KPageShift))-1u;
 
-/*
-Limit the maximum number of oldest pages to bound the time taken by SelectPagesToClean(), which is
-called with the MmuLock held.
+/**
+Default limit for the maximum number of oldest pages.
+
+If the data paging device sets iPreferredWriteShift, then this is increased if necessary to allow
+that many pages to be present.
+
+This limit exists to make our live list implementation a closer approximation to LRU, and to bound
+the time taken by SelectSequentialPagesToClean(), which is called with the MmuLock held.
 */
-const TUint KMaxOldestPages = 32;
+const TUint KDefaultMaxOldestPages = 32;
 
 static DMutex* ThePageCleaningLock = NULL;
 
 DPager ThePager;
 
 
-DPager::DPager()
-	: iMinimumPageCount(0), iMaximumPageCount(0), iYoungOldRatio(0),
-	  iYoungCount(0), iOldCount(0), iOldestCleanCount(0),
-	  iNumberOfFreePages(0), iReservePageCount(0), iMinimumPageLimit(0)
+DPager::DPager() :
+	iMinimumPageCount(0),
+	iMaximumPageCount(0),
+	iYoungOldRatio(0),
+	iYoungCount(0),
+	iOldCount(0),
+	iOldestCleanCount(0),
+	iMaxOldestPages(KDefaultMaxOldestPages),
+	iNumberOfFreePages(0),
+	iReservePageCount(0),
+	iMinimumPageLimit(0),
+	iPagesToClean(1)
 #ifdef __DEMAND_PAGING_BENCHMARKS__
 	, iBenchmarkLock(TSpinLock::EOrderGenericIrqHigh3)
 #endif	  
@@ -489,6 +502,10 @@
 	{
 	__NK_ASSERT_DEBUG(RamAllocLock::IsHeld());
 	__NK_ASSERT_DEBUG(MmuLock::IsHeld());
+	
+	// The PageCleaningLock may or may not be held.  This method will release the RamAllocLock if it
+	// has to wait for the PageCleaningLock
+	TBool pageCleaningLockAcquired = EFalse;
 
 	// find oldest page in list...
 	SDblQueLink* link;
@@ -500,6 +517,37 @@
 	else if (iOldestDirtyCount)
 		{
 		__NK_ASSERT_DEBUG(!iOldestDirtyList.IsEmpty());
+
+		// see if we can clean multiple dirty pages in one go...
+		if (iPagesToClean > 1 && iOldestDirtyCount > 1)
+			{
+			if (!PageCleaningLock::IsHeld())
+				{
+				// temporarily release ram alloc mutex and acquire page cleaning mutex
+				MmuLock::Unlock();
+				RamAllocLock::Unlock();
+				PageCleaningLock::Lock();
+				MmuLock::Lock();
+				pageCleaningLockAcquired = ETrue;
+				}
+
+			// there may be clean pages now if we've waited on the page cleaning mutex, if so don't
+			// bother cleaning but just restart
+			if (iOldestCleanCount == 0 && iOldestDirtyCount >= 1)
+				CleanSomePages(EFalse);
+
+			if (pageCleaningLockAcquired)
+				{
+				// release page cleaning mutex and re-aquire ram alloc mutex
+				MmuLock::Unlock();
+				PageCleaningLock::Unlock();			
+				RamAllocLock::Lock();
+				MmuLock::Lock();
+				}
+			
+			return 1;  // tell caller to restart their operation
+			}
+		
 		link = iOldestDirtyList.Last();
 		}
 	else if (iOldCount)
@@ -515,9 +563,14 @@
 		}
 	SPageInfo* pageInfo = SPageInfo::FromLink(link);
 
-	if (pageInfo->IsDirty() && !PageCleaningLock::IsHeld())
-		return 1;
-
+	if (pageInfo->IsDirty())
+		{		
+		MmuLock::Unlock();
+		PageCleaningLock::Lock();
+		MmuLock::Lock();
+		pageCleaningLockAcquired = ETrue;
+		}
+	
 	// try to steal it from owning object...
 	TInt r = StealPage(pageInfo);	
 	if (r == KErrNone)
@@ -525,73 +578,49 @@
 		BalanceAges();
 		aPageInfoOut = pageInfo;
 		}
+
+	if (pageCleaningLockAcquired)
+		{		
+		MmuLock::Unlock();
+		PageCleaningLock::Unlock();
+		MmuLock::Lock();
+		}
 	
 	return r;
 	}
 
 
-SPageInfo* DPager::StealOldestPage()
-	{
-	__NK_ASSERT_DEBUG(MmuLock::IsHeld());
-	TBool pageCleaningLockHeld = EFalse;
-	for(;;)
-		{
-		SPageInfo* pageInfo = NULL;
-		TInt r = TryStealOldestPage(pageInfo);
-		
-		if (r == KErrNone)
-			{
-			if (pageCleaningLockHeld)
-				{
-				MmuLock::Unlock();
-				PageCleaningLock::Unlock();
-				MmuLock::Lock();
-				}
-			return pageInfo;
-			}
-		else if (r == 1)
-			{
-			__NK_ASSERT_ALWAYS(!pageCleaningLockHeld);
-			MmuLock::Unlock();
-			PageCleaningLock::Lock();
-			MmuLock::Lock();
-			pageCleaningLockHeld = ETrue;
-			}
-		// else retry...
-		}
-	}
-
-#ifdef __CPU_CACHE_HAS_COLOUR
-
-template <class T, TInt maxObjects> class TSequentialColourSelector
+template <class T, TUint maxObjects> class TSequentialColourSelector
 	{
 public:
-	static const TInt KMaxLength = maxObjects;
-	static const TInt KArrayLength = _ALIGN_UP(KMaxLength, KPageColourCount);
+	static const TUint KMaxSearchLength = _ALIGN_UP(maxObjects, KPageColourCount);
 	
-	FORCE_INLINE TSequentialColourSelector()
+	FORCE_INLINE TSequentialColourSelector(TUint aTargetLength)
 		{
 		memclr(this, sizeof(*this));
+		__NK_ASSERT_DEBUG(aTargetLength <= maxObjects);
+		iTargetLength = aTargetLength;
+		iSearchLength = _ALIGN_UP(aTargetLength, KPageColourCount);
 		}
 
 	FORCE_INLINE TBool FoundLongestSequence()
 		{
-		return iLongestLength >= KMaxLength;
+		return iLongestLength >= iTargetLength;
 		}
 
-	FORCE_INLINE void AddCandidate(T* aObject, TInt aColour)
+	FORCE_INLINE void AddCandidate(T* aObject, TUint aColour)
 		{
 		// allocate objects to slots based on colour
-		for (TInt i = aColour ; i < KArrayLength ; i += KPageColourCount)
+		for (TUint i = aColour ; i < iSearchLength ; i += KPageColourCount)
 			{
 			if (!iSlot[i])
 				{
 				iSlot[i] = aObject;
 				iSeqLength[i] = i == 0 ? 1 : iSeqLength[i - 1] + 1;
-				TInt j = i + 1;
-				while(j < KArrayLength && iSeqLength[j])
+				TUint j = i + 1;
+				while(j < iSearchLength && iSeqLength[j])
 					iSeqLength[j++] += iSeqLength[i];
-				TInt currentLength = iSeqLength[j - 1];
+				TUint currentLength = iSeqLength[j - 1];
 				if (currentLength > iLongestLength)
 					{
 					iLongestLength = currentLength;
@@ -602,31 +631,31 @@
 			}
 		}
 
-	FORCE_INLINE TInt FindLongestRun(T** aObjectsOut)
+	FORCE_INLINE TUint FindLongestRun(T** aObjectsOut)
 		{
 		if (iLongestLength == 0)
 			return 0;
 
-		if (iLongestLength < KMaxLength && iSlot[0] && iSlot[KArrayLength - 1])
+		if (iLongestLength < iTargetLength && iSlot[0] && iSlot[iSearchLength - 1])
 			{
 			// check possibility of wrapping
 
 			TInt i = 1;
 			while (iSlot[i]) ++i;  // find first hole
-			TInt wrappedLength = iSeqLength[KArrayLength - 1] + iSeqLength[i - 1];
+			TUint wrappedLength = iSeqLength[iSearchLength - 1] + iSeqLength[i - 1];
 			if (wrappedLength > iLongestLength)
 				{
 				iLongestLength = wrappedLength;
-				iLongestStart = KArrayLength - iSeqLength[KArrayLength - 1];
+				iLongestStart = iSearchLength - iSeqLength[iSearchLength - 1];
 				}
 			}		
 
-		iLongestLength = Min(iLongestLength, KMaxLength);
-
-		__NK_ASSERT_DEBUG(iLongestStart >= 0 && iLongestStart < KArrayLength);
-		__NK_ASSERT_DEBUG(iLongestStart + iLongestLength < 2 * KArrayLength);
-
-		TInt len = Min(iLongestLength, KArrayLength - iLongestStart);
+		iLongestLength = MinU(iLongestLength, iTargetLength);
+
+		__NK_ASSERT_DEBUG(iLongestStart < iSearchLength);
+		__NK_ASSERT_DEBUG(iLongestStart + iLongestLength < 2 * iSearchLength);
+
+		TUint len = MinU(iLongestLength, iSearchLength - iLongestStart);
 		wordmove(aObjectsOut, &iSlot[iLongestStart], len * sizeof(T*));
 		wordmove(aObjectsOut + len, &iSlot[0], (iLongestLength - len) * sizeof(T*));
 		
@@ -634,19 +663,22 @@
 		}
 
 private:
-	T* iSlot[KArrayLength];
-	TInt8 iSeqLength[KArrayLength];
-	TInt iLongestStart;
-	TInt iLongestLength;
+	TUint iTargetLength;
+	TUint iSearchLength;
+	TUint iLongestStart;
+	TUint iLongestLength;
+	T* iSlot[KMaxSearchLength];
+	TUint8 iSeqLength[KMaxSearchLength];
 	};
 
-TInt DPager::SelectPagesToClean(SPageInfo** aPageInfosOut)
+
+TInt DPager::SelectSequentialPagesToClean(SPageInfo** aPageInfosOut)
 	{
-	// select up to KMaxPagesToClean oldest dirty pages with sequential page colours
+	// select up to iPagesToClean oldest dirty pages with sequential page colours
 	
 	__NK_ASSERT_DEBUG(MmuLock::IsHeld());
 
-	TSequentialColourSelector<SPageInfo, KMaxPagesToClean> selector;
+	TSequentialColourSelector<SPageInfo, KMaxPagesToClean> selector(iPagesToClean);
 
 	SDblQueLink* link = iOldestDirtyList.Last();
 	while (link != &iOldestDirtyList.iA)
@@ -668,15 +700,14 @@
 	return selector.FindLongestRun(aPageInfosOut);
 	}
 
-#else
-
-TInt DPager::SelectPagesToClean(SPageInfo** aPageInfosOut)
+
+TInt DPager::SelectOldestPagesToClean(SPageInfo** aPageInfosOut)
 	{
-	// no page colouring restrictions, so just take up to KMaxPagesToClean oldest dirty pages
+	// select up to iPagesToClean oldest dirty pages
 	__NK_ASSERT_DEBUG(MmuLock::IsHeld());
-	TInt pageCount = 0;
+	TUint pageCount = 0;
 	SDblQueLink* link = iOldestDirtyList.Last();
-	while (link != &iOldestDirtyList.iA && pageCount < KMaxPagesToClean)
+	while (link != &iOldestDirtyList.iA && pageCount < iPagesToClean)
 		{
 		SPageInfo* pi = SPageInfo::FromLink(link);
 		if (!pi->IsWritable())
@@ -691,20 +722,29 @@
 	return pageCount;
 	}
 
-#endif
-
 
 TInt DPager::CleanSomePages(TBool aBackground)
 	{
+	TRACE(("DPager::CleanSomePages"));
+	
 	__NK_ASSERT_DEBUG(MmuLock::IsHeld());
 	__NK_ASSERT_DEBUG(PageCleaningLock::IsHeld());
 	// ram alloc lock may or may not be held
 
 	SPageInfo* pageInfos[KMaxPagesToClean];
-	TInt pageCount = SelectPagesToClean(&pageInfos[0]);
+	TInt pageCount;
+	if (iCleanInSequence)
+		pageCount = SelectSequentialPagesToClean(&pageInfos[0]);
+	else
+		pageCount = SelectOldestPagesToClean(&pageInfos[0]);
 	
 	if (pageCount == 0)
+		{
+		TRACE2(("DPager::CleanSomePages no pages to clean", pageCount));
+		TRACE2(("  page counts %d, %d, %d, %d",
+				iYoungCount, iOldCount, iOldestCleanCount, iOldestDirtyCount));
 		return 0;
+		}
 	
 	TheDataPagedMemoryManager->CleanPages(pageCount, pageInfos, aBackground);
 
@@ -724,6 +764,8 @@
 			}
 		}
 
+	TRACE2(("DPager::CleanSomePages cleaned %d pages", pageCount));
+
 	return pageCount;
 	}
 
@@ -737,7 +779,6 @@
 
 TInt DPager::RestrictPage(SPageInfo* aPageInfo, TRestrictPagesType aRestriction)
 	{
-	TRACE(("DPager::RestrictPage(0x%08x,%d)",aPageInfo,aRestriction));
 	__NK_ASSERT_DEBUG(MmuLock::IsHeld());
 
 	TInt r;
@@ -763,7 +804,6 @@
 		MmuLock::Lock();
 		}
 
-	TRACE(("DPager::RestrictPage returns %d",r));
 	return r;
 	}
 
@@ -814,28 +854,25 @@
 
 TInt DPager::DiscardAndAllocPage(SPageInfo* aPageInfo, TZonePageType aPageType)
 	{
-	TInt r = DiscardPage(aPageInfo, KRamZoneInvalidId, EFalse);
+	TInt r = DiscardPage(aPageInfo, KRamZoneInvalidId, M::EMoveDisMoveDirty);
 	if (r == KErrNone)
 		{
 		TheMmu.MarkPageAllocated(aPageInfo->PhysAddr(), aPageType);
 		}
-	// Flash the ram alloc lock as we may have had to write a page out to swap.
-	RamAllocLock::Unlock();
-	RamAllocLock::Lock();
 	return r;
 	}
 
 
-static TBool DiscardCanStealPage(SPageInfo* aOldPageInfo, TBool aBlockRest)
+static TBool DiscardCanStealPage(SPageInfo* aOldPageInfo, TBool aMoveDirty)
 	{
  	// If the page is pinned or if the page is dirty and a general defrag is being performed then
 	// don't attempt to steal it
 	return aOldPageInfo->Type() == SPageInfo::EUnused ||
-		(aOldPageInfo->PagedState() != SPageInfo::EPagedPinned && (!aBlockRest || !aOldPageInfo->IsDirty()));	
+		(aOldPageInfo->PagedState() != SPageInfo::EPagedPinned && (!aMoveDirty || !aOldPageInfo->IsDirty()));	
 	}
 
 
-TInt DPager::DiscardPage(SPageInfo* aOldPageInfo, TUint aBlockZoneId, TBool aBlockRest)
+TInt DPager::DiscardPage(SPageInfo* aOldPageInfo, TUint aBlockZoneId, TUint aMoveDisFlags)
 	{
 	// todo: assert MmuLock not released
 	
@@ -843,8 +880,10 @@
 	
 	__NK_ASSERT_DEBUG(RamAllocLock::IsHeld());
 	__NK_ASSERT_DEBUG(MmuLock::IsHeld());
-
-	if (!DiscardCanStealPage(aOldPageInfo, aBlockRest))
+	TBool moveDirty = (aMoveDisFlags & M::EMoveDisMoveDirty) != 0;
+	TBool blockRest = (aMoveDisFlags & M::EMoveDisBlockRest) != 0;
+
+	if (!DiscardCanStealPage(aOldPageInfo, moveDirty))
 		{
 		// The page is pinned or is dirty and this is a general defrag so move the page.
 		DMemoryObject* memory = aOldPageInfo->Owner();
@@ -854,7 +893,7 @@
 		MmuLock::Unlock();
 		TPhysAddr newAddr;
 		TRACE2(("DPager::DiscardPage delegating pinned/dirty page to manager"));
-		TInt r = memory->iManager->MovePage(memory, aOldPageInfo, newAddr, aBlockZoneId, aBlockRest);
+		TInt r = memory->iManager->MovePage(memory, aOldPageInfo, newAddr, aBlockZoneId, blockRest);
 		TRACE(("< DPager::DiscardPage %d", r));
 		return r;
 		}
@@ -875,7 +914,7 @@
 			{
 			// Allocate a new page for the live list as it has reached its minimum size.
 			TUint flags = EMemAttNormalCached | Mmu::EAllocNoWipe;
-			newPageInfo = GetPageFromSystem((Mmu::TRamAllocFlags)flags, aBlockZoneId, aBlockRest);
+			newPageInfo = GetPageFromSystem((Mmu::TRamAllocFlags)flags, aBlockZoneId, blockRest);
 			if (!newPageInfo)
 				{
 				TRACE(("< DPager::DiscardPage KErrNoMemory"));
@@ -894,7 +933,7 @@
 
 		// Re-acquire the mmulock and re-check that the page is not pinned or dirty.
 		MmuLock::Lock();
-		if (!DiscardCanStealPage(aOldPageInfo, aBlockRest))
+		if (!DiscardCanStealPage(aOldPageInfo, moveDirty))
 			{
 			// Page is now pinned or dirty so give up as it is in use.
 			r = KErrInUse;
@@ -1005,12 +1044,26 @@
 	}
 
 
-void DPager::ReturnPageToSystem()
+TBool DPager::TryReturnOldestPageToSystem()
 	{
 	__NK_ASSERT_DEBUG(RamAllocLock::IsHeld());
 	__NK_ASSERT_DEBUG(MmuLock::IsHeld());
-
-	ReturnPageToSystem(*StealOldestPage());
+	__NK_ASSERT_DEBUG(iNumberOfFreePages>0);
+
+	SPageInfo* pageInfo = NULL;
+	if (TryStealOldestPage(pageInfo) == KErrNone)
+		{
+		// TryStealOldestPage may have released the MmuLock, so check there are still enough pages
+		// to remove one from the live list
+		if (iNumberOfFreePages>0)
+			{
+			ReturnPageToSystem(*pageInfo);
+			return ETrue;
+			}
+		else
+			AddAsFreePage(pageInfo);
+		}
+	return EFalse;
 	}
 
 
@@ -1039,7 +1092,6 @@
 
 SPageInfo* DPager::PageInAllocPage(Mmu::TRamAllocFlags aAllocFlags)
 	{
-	TBool pageCleaningLockHeld = EFalse;
 	SPageInfo* pageInfo;
 	TPhysAddr pagePhys;
 	TInt r = KErrGeneral;
@@ -1066,62 +1118,18 @@
 		MmuLock::Lock();
 		}
 
-	// try stealing a clean page...
-	if (iOldestCleanCount)
-		goto try_steal_oldest_page;
-
-	// see if we can clean multiple dirty pages in one go...
-	if (KMaxPagesToClean > 1 && iOldestDirtyCount > 1)
-		{
-		// if we don't hold the page cleaning mutex then temporarily release ram alloc mutex and
-		// acquire page cleaning mutex; if we hold it already just proceed
-		if (!pageCleaningLockHeld)
-			{
-			MmuLock::Unlock();
-			RamAllocLock::Unlock();
-			PageCleaningLock::Lock();			
-			MmuLock::Lock();
-			}
-		
-		// there may be clean pages now if we've waited on the page cleaning mutex, if so don't
-		// bother cleaning but just restart
-		if (iOldestCleanCount == 0)
-			CleanSomePages(EFalse);
-		
-		if (!pageCleaningLockHeld)
-			{
-			MmuLock::Unlock();
-			PageCleaningLock::Unlock();			
-			RamAllocLock::Lock();
-			MmuLock::Lock();
-			}
-		
-		if (iOldestCleanCount > 0)
-			goto find_a_page;
-		}
-
-	// as a last resort, steal a page from the live list...
-	
+	// otherwise steal a page from the live list...
 try_steal_oldest_page:
 	__NK_ASSERT_ALWAYS(iOldestCleanCount|iOldestDirtyCount|iOldCount|iYoungCount);
 	r = TryStealOldestPage(pageInfo);
-	// if this fails we restart whole process
-	if (r < KErrNone)
+	
+	// if this fails we restart whole process.
+	// failure can be either KErrInUse if the page was used while we were stealing, or 1 to indicate
+	// that some pages were cleaned and the operation should be restarted
+	if (r != KErrNone)
 		goto find_a_page;
 
-	// if we need to clean, acquire page cleaning mutex for life of this function
-	if (r == 1)
-		{
-		__NK_ASSERT_ALWAYS(!pageCleaningLockHeld);
-		MmuLock::Unlock();
-		PageCleaningLock::Lock();
-		MmuLock::Lock();
-		pageCleaningLockHeld = ETrue;
-		goto find_a_page;		
-		}
-
 	// otherwise we're done!
-	__NK_ASSERT_DEBUG(r == KErrNone);
 	MmuLock::Unlock();
 
 	// make page state same as a freshly allocated page...
@@ -1129,8 +1137,6 @@
 	TheMmu.PagesAllocated(&pagePhys,1,aAllocFlags);
 
 done:
-	if (pageCleaningLockHeld)
-		PageCleaningLock::Unlock();
 	RamAllocLock::Unlock();
 
 	return pageInfo;
@@ -1146,8 +1152,8 @@
 	MmuLock::Lock();
 	while(aNumPages>0 && (TInt)NumberOfFreePages()>=aNumPages)
 		{
-		ReturnPageToSystem();
-		--aNumPages;
+		if (TryReturnOldestPageToSystem())
+			--aNumPages;
 		}
 	MmuLock::Unlock();
 
@@ -1329,61 +1335,89 @@
 void DPager::BalanceAges()
 	{
 	__NK_ASSERT_DEBUG(MmuLock::IsHeld());
-	TBool restrictPage = EFalse;
-	SPageInfo* pageInfo = NULL;
-	TUint oldestCount = iOldestCleanCount + iOldestDirtyCount;
-	if((iOldCount + oldestCount) * iYoungOldRatio < iYoungCount)
+	TBool retry;
+	do
 		{
-		// Need more old pages so make one young page into an old page...
-		__NK_ASSERT_DEBUG(!iYoungList.IsEmpty());
-		__NK_ASSERT_DEBUG(iYoungCount);
-		SDblQueLink* link = iYoungList.Last()->Deque();
-		--iYoungCount;
-
-		pageInfo = SPageInfo::FromLink(link);
-		pageInfo->SetPagedState(SPageInfo::EPagedOld);
-
-		iOldList.AddHead(link);
-		++iOldCount;
-
-		Event(EEventPageAged,pageInfo);
-		// Delay restricting the page until it is safe to release the MmuLock.
-		restrictPage = ETrue;
-		}
-
-	// Check we have enough oldest pages.
-	if (oldestCount < KMaxOldestPages &&
-		oldestCount * iOldOldestRatio < iOldCount)
-		{
-		__NK_ASSERT_DEBUG(!iOldList.IsEmpty());
-		__NK_ASSERT_DEBUG(iOldCount);
-		SDblQueLink* link = iOldList.Last()->Deque();
-		--iOldCount;
-
-		SPageInfo* oldestPageInfo = SPageInfo::FromLink(link);
-		if (oldestPageInfo->IsDirty())
+		retry = EFalse;
+		TBool restrictPage = EFalse;
+		SPageInfo* pageInfo = NULL;
+		TUint oldestCount = iOldestCleanCount + iOldestDirtyCount;
+		if((iOldCount + oldestCount) * iYoungOldRatio < iYoungCount)
+			{
+			// Need more old pages so make one young page into an old page...
+			__NK_ASSERT_DEBUG(!iYoungList.IsEmpty());
+			__NK_ASSERT_DEBUG(iYoungCount);
+			SDblQueLink* link = iYoungList.Last()->Deque();
+			--iYoungCount;
+
+			pageInfo = SPageInfo::FromLink(link);
+			pageInfo->SetPagedState(SPageInfo::EPagedOld);
+
+			iOldList.AddHead(link);
+			++iOldCount;
+
+			Event(EEventPageAged,pageInfo);
+			// Delay restricting the page until it is safe to release the MmuLock.
+			restrictPage = ETrue;
+			}
+
+		// Check we have enough oldest pages.
+		if (oldestCount < iMaxOldestPages &&
+			oldestCount * iOldOldestRatio < iOldCount)
 			{
-			oldestPageInfo->SetPagedState(SPageInfo::EPagedOldestDirty);
-			iOldestDirtyList.AddHead(link);
-			++iOldestDirtyCount;
-			PageCleaner::NotifyPagesToClean();
-			Event(EEventPageAgedDirty,oldestPageInfo);
+			__NK_ASSERT_DEBUG(!iOldList.IsEmpty());
+			__NK_ASSERT_DEBUG(iOldCount);
+			SDblQueLink* link = iOldList.Last()->Deque();
+			--iOldCount;
+
+			SPageInfo* oldestPageInfo = SPageInfo::FromLink(link);
+			if (oldestPageInfo->IsDirty())
+				{
+				oldestPageInfo->SetOldestPage(SPageInfo::EPagedOldestDirty);
+				iOldestDirtyList.AddHead(link);
+				++iOldestDirtyCount;
+				PageCleaner::NotifyPagesToClean();
+				Event(EEventPageAgedDirty,oldestPageInfo);
+				}
+			else
+				{
+				oldestPageInfo->SetOldestPage(SPageInfo::EPagedOldestClean);
+				iOldestCleanList.AddHead(link);
+				++iOldestCleanCount;
+				Event(EEventPageAgedClean,oldestPageInfo);
+				}
 			}
-		else
+
+		if (restrictPage)
 			{
-			oldestPageInfo->SetPagedState(SPageInfo::EPagedOldestClean);
-			iOldestCleanList.AddHead(link);
-			++iOldestCleanCount;
-			Event(EEventPageAgedClean,oldestPageInfo);
+			// Make the recently aged old page inaccessible.  This is done last as it will release
+			// the MmuLock and therefore the page counts may otherwise change.
+			TInt r = RestrictPage(pageInfo,ERestrictPagesNoAccessForOldPage);
+
+			if (r == KErrInUse)
+				{
+				SPageInfo::TPagedState state = pageInfo->PagedState();
+				if (state == SPageInfo::EPagedOld ||
+					state == SPageInfo::EPagedOldestClean ||
+					state == SPageInfo::EPagedOldestDirty)
+					{
+					// The restrict operation failed, but the page was left in an old state.  This
+					// can happen when:
+					//  
+					//  - pages are in the process of being pinned - the mapping will veto the
+					//    restriction
+					//  - pages are rejuvenated and then become quickly become old again
+					//  
+					// In the second instance the page will be needlessly rejuvenated because we
+					// can't tell that it has actually been restricted by another thread
+					RemovePage(pageInfo);
+					AddAsYoungestPage(pageInfo);
+					retry = ETrue;
+					}
+				}
 			}
 		}
-
-	if (restrictPage)
-		{
-		// Make the recently aged old page inaccessible.  This is done last as it 
-		// will release the MmuLock and therefore the page counts may otherwise change.
-		RestrictPage(pageInfo,ERestrictPagesNoAccessForOldPage);
-		}
+	while (retry);
 	}
 
 
@@ -1392,7 +1426,7 @@
 	__NK_ASSERT_DEBUG(RamAllocLock::IsHeld());
 	__NK_ASSERT_DEBUG(MmuLock::IsHeld());
 	while(HaveTooManyPages())
-		ReturnPageToSystem();
+		TryReturnOldestPageToSystem();
 	}
 
 
@@ -1684,6 +1718,8 @@
 
 void DPager::Pin(SPageInfo* aPageInfo, TPinArgs& aPinArgs)
 	{
+	TRACE(("DPager::Pin %08x", aPageInfo->PhysAddr()));
+	
 	__ASSERT_CRITICAL;
 	__NK_ASSERT_DEBUG(MmuLock::IsHeld());
 	__NK_ASSERT_DEBUG(aPinArgs.HaveSufficientPages(1));
@@ -1989,7 +2025,10 @@
 
 TInt DPager::ResizeLiveList(TUint aMinimumPageCount, TUint aMaximumPageCount)
 	{
-	TRACE(("DPager::ResizeLiveList(%d,%d) current young=%d old=%d min=%d free=%d max=%d",aMinimumPageCount,aMaximumPageCount,iYoungCount,iOldCount,iMinimumPageCount,iNumberOfFreePages,iMaximumPageCount));
+	TRACE(("DPager::ResizeLiveList(%d,%d) current: %d %d %d %d, %d %d %d",
+		   aMinimumPageCount,aMaximumPageCount,
+		   iYoungCount,iOldCount,iOldestCleanCount,iOldestDirtyCount,
+		   iMinimumPageCount,iNumberOfFreePages,iMaximumPageCount));
 	__NK_ASSERT_DEBUG(CacheInitialised());
 
 	if(!aMaximumPageCount)
@@ -2003,10 +2042,15 @@
 	// Min must not be greater than max...
 	if(aMinimumPageCount>aMaximumPageCount)
 		return KErrArgument;
-
+	
 	NKern::ThreadEnterCS();
 	RamAllocLock::Lock();
 
+	// We must hold this otherwise TryStealOldestPage will release the RamAllocLock while waiting
+	// for it.  Note this method is not used in producton, so it's ok to hold both locks for longer
+	// than would otherwise happen.
+	PageCleaningLock::Lock();  
+
 	MmuLock::Lock();
 
 	__NK_ASSERT_ALWAYS(iYoungOldRatio);
@@ -2026,56 +2070,55 @@
 		iMaximumPageCount = aMaximumPageCount;
 
 	// Reduce iMinimumPageCount?
-	TInt spare = iMinimumPageCount-aMinimumPageCount;
-	if(spare>0)
+	if(aMinimumPageCount < iMinimumPageCount)
 		{
-		iMinimumPageCount -= spare;
-		iNumberOfFreePages += spare;
+		iNumberOfFreePages += iMinimumPageCount - aMinimumPageCount;
+		iMinimumPageCount = aMinimumPageCount;
 		}
 
 	// Increase iMinimumPageCount?
 	TInt r=KErrNone;
-	while(iMinimumPageCount<aMinimumPageCount)
+	while(aMinimumPageCount > iMinimumPageCount)
 		{
-		TUint newMin = aMinimumPageCount;
-		TUint maxMin = iMinimumPageCount+iNumberOfFreePages;
-		if(newMin>maxMin)
-			newMin = maxMin;
-
-		TUint delta = newMin-iMinimumPageCount;
-		if(delta)
+		TUint newMin = MinU(aMinimumPageCount, iMinimumPageCount + iNumberOfFreePages);
+		
+		if (newMin == iMinimumPageCount)
 			{
-			iMinimumPageCount = newMin;
-			iNumberOfFreePages -= delta;
-			continue;
+			// have to add pages before we can increase minimum page count
+			if(!TryGrowLiveList())
+				{
+				r=KErrNoMemory;
+				break;
+				}
 			}
-
-		if(!TryGrowLiveList())
+		else
 			{
-			r=KErrNoMemory;
-			break;
+			iNumberOfFreePages -= newMin - iMinimumPageCount;
+			iMinimumPageCount = newMin;
 			}
 		}
 
 	// Reduce iMaximumPageCount?
-	while(iMaximumPageCount>aMaximumPageCount)
+	while(aMaximumPageCount < iMaximumPageCount)
 		{
-		TUint newMax = aMaximumPageCount;
-		TUint minMax = iMinimumPageCount+iNumberOfFreePages;
-		if(newMax<minMax)
-			newMax = minMax;
-
-		TUint delta = iMaximumPageCount-newMax;
-		if(delta)
+		TUint newMax = MaxU(aMaximumPageCount, iMinimumPageCount + iNumberOfFreePages);
+
+		if (newMax == iMaximumPageCount)
+			{
+			// have to remove pages before we can reduce maximum page count
+			TryReturnOldestPageToSystem();
+			}
+		else
 			{
 			iMaximumPageCount = newMax;
-			continue;
 			}
-
-		ReturnPageToSystem();
 		}
-
-	TRACE(("DPager::ResizeLiveList end with young=%d old=%d min=%d free=%d max=%d",iYoungCount,iOldCount,iMinimumPageCount,iNumberOfFreePages,iMaximumPageCount));
+	
+	TRACE(("DPager::ResizeLiveList end: %d %d %d %d, %d %d %d",
+		   iYoungCount,iOldCount,iOldestCleanCount,iOldestDirtyCount,
+		   iMinimumPageCount,iNumberOfFreePages,iMaximumPageCount));
+	
+	__NK_ASSERT_DEBUG((iMinimumPageCount + iNumberOfFreePages) <= iMaximumPageCount);
 
 #ifdef BTRACE_KERNEL_MEMORY
 	BTrace4(BTrace::EKernelMemory,BTrace::EKernelMemoryDemandPagingCache,iMinimumPageCount << KPageShift);
@@ -2083,6 +2126,7 @@
 
 	MmuLock::Unlock();
 
+	PageCleaningLock::Unlock();
 	RamAllocLock::Unlock();
 	NKern::ThreadLeaveCS();
 
@@ -2090,6 +2134,43 @@
 	}
 
 
+TUint RequiredOldestPages(TUint aPagesToClean, TBool aCleanInSequence)
+	{
+	return aCleanInSequence ? aPagesToClean * 8 : aPagesToClean;
+	}
+
+
+void DPager::SetPagesToClean(TUint aPagesToClean)
+	{
+	TRACE(("WDP: Pager will attempt to clean %d pages", aPagesToClean));
+	__NK_ASSERT_ALWAYS(aPagesToClean > 0 && aPagesToClean <= KMaxPagesToClean);
+	MmuLock::Lock();
+	iPagesToClean = aPagesToClean;
+	iMaxOldestPages = MaxU(KDefaultMaxOldestPages,
+						   RequiredOldestPages(iPagesToClean, iCleanInSequence));
+	MmuLock::Unlock();
+	TRACE(("WDP: Maximum %d oldest pages", iMaxOldestPages));	
+	}
+
+
+TUint DPager::PagesToClean()
+	{
+	return iPagesToClean;
+	}
+
+
+void DPager::SetCleanInSequence(TBool aCleanInSequence)
+	{
+	TRACE(("WDP: Sequential page colour set to %d", aCleanInSequence));
+	MmuLock::Lock();
+	iCleanInSequence = aCleanInSequence;
+	iMaxOldestPages = MaxU(KDefaultMaxOldestPages,
+						   RequiredOldestPages(iPagesToClean, iCleanInSequence));
+	MmuLock::Unlock();	
+	TRACE(("WDP: Maximum %d oldest pages", iMaxOldestPages));
+	}
+
+
 // WARNING THIS METHOD MAY HOLD THE RAM ALLOC LOCK FOR EXCESSIVE PERIODS.  DON'T USE THIS IN ANY PRODUCTION CODE.
 void DPager::FlushAll()
 	{
@@ -2141,13 +2222,13 @@
 		}
 	while(piMap<piMapEnd);
 	MmuLock::Unlock();
+	PageCleaningLock::Unlock();
 
 	// reduce live page list to a minimum
 	while(GetFreePages(1)) {}; 
 
 	TRACE(("DPager::FlushAll() end with young=%d old=%d min=%d free=%d max=%d",iYoungCount,iOldCount,iMinimumPageCount,iNumberOfFreePages,iMaximumPageCount));
 
-	PageCleaningLock::Unlock();
 	RamAllocLock::Unlock();
 	NKern::ThreadLeaveCS();
 	}
@@ -2338,6 +2419,43 @@
 		return KErrNone;
 #endif
 
+	case EVMHalGetPhysicalAccessSupported:
+		if ((K::MemModelAttributes & EMemModelAttrDataPaging) == 0)
+			return KErrNotSupported;
+		return GetPhysicalAccessSupported();
+		
+	case EVMHalGetUsePhysicalAccess:
+		if ((K::MemModelAttributes & EMemModelAttrDataPaging) == 0)
+			return KErrNotSupported;
+		return GetUsePhysicalAccess();
+
+	case EVMHalSetUsePhysicalAccess:
+		if(!TheCurrentThread->HasCapability(ECapabilityWriteDeviceData,__PLATSEC_DIAGNOSTIC_STRING("Checked by VMHalFunction(EVMHalSetUsePhysicalAccess)")))
+			K::UnlockedPlatformSecurityPanic();
+		if ((K::MemModelAttributes & EMemModelAttrDataPaging) == 0)
+			return KErrNotSupported;
+		if ((TUint)a1 > 1)
+			return KErrArgument;
+		SetUsePhysicalAccess((TBool)a1);
+		return KErrNone;
+		
+	case EVMHalGetPreferredDataWriteSize:
+		if ((K::MemModelAttributes & EMemModelAttrDataPaging) == 0)
+			return KErrNotSupported;
+		return GetPreferredDataWriteSize();
+		
+	case EVMHalGetDataWriteSize:
+		if ((K::MemModelAttributes & EMemModelAttrDataPaging) == 0)
+			return KErrNotSupported;
+		return __e32_find_ms1_32(ThePager.PagesToClean());
+		
+	case EVMHalSetDataWriteSize:
+		if(!TheCurrentThread->HasCapability(ECapabilityWriteDeviceData,__PLATSEC_DIAGNOSTIC_STRING("Checked by VMHalFunction(EVMHalSetDataWriteSize)")))
+			K::UnlockedPlatformSecurityPanic();
+		if ((K::MemModelAttributes & EMemModelAttrDataPaging) == 0)
+			return KErrNotSupported;
+		return SetDataWriteSize((TUint)a1);
+	
 	default:
 		return KErrNotSupported;
 		}
@@ -2390,151 +2508,45 @@
 //
 
 //
-// DPagingRequest
+// DPagingRequestBase
 //
 
-DPagingRequest::DPagingRequest()
-	: iMutex(NULL), iUseRegionCount(0)
-	{
-	}
-
-
-void DPagingRequest::SetUseContiguous(DMemoryObject* aMemory, TUint aIndex, TUint aCount)
-	{
-	__ASSERT_SYSTEM_LOCK;
-	__NK_ASSERT_DEBUG(iUseRegionCount == 0);
-	__NK_ASSERT_DEBUG(aCount > 0 && aCount <= EMaxPages);
-	for (TUint i = 0 ; i < aCount ; ++i)
-		{
-		iUseRegionMemory[i] = aMemory;
-		iUseRegionIndex[i] = aIndex + i;		
-		}
-	iUseRegionCount = aCount;
-	}
-
-
-void DPagingRequest::SetUseDiscontiguous(DMemoryObject** aMemory, TUint* aIndex, TUint aCount)
-	{
-	__ASSERT_SYSTEM_LOCK;
-	__NK_ASSERT_DEBUG(iUseRegionCount == 0);
-	__NK_ASSERT_DEBUG(aCount > 0 && aCount <= EMaxPages);
-	for (TUint i = 0 ; i < aCount ; ++i)
-		{
-		iUseRegionMemory[i] = aMemory[i];
-		iUseRegionIndex[i] = aIndex[i];
-		}
-	iUseRegionCount = aCount;
-	}
-
-
-void DPagingRequest::ResetUse()
-	{
-	__ASSERT_SYSTEM_LOCK;
-	__NK_ASSERT_DEBUG(iUseRegionCount > 0);
-	iUseRegionCount = 0;
-	}
-
-
-TBool DPagingRequest::CheckUseContiguous(DMemoryObject* aMemory, TUint aIndex, TUint aCount)
-	{
-	if (iUseRegionCount != aCount)
-		return EFalse;
-	for (TUint i = 0 ; i < iUseRegionCount ; ++i)
-		{
-		if (iUseRegionMemory[i] != aMemory || iUseRegionIndex[i] != aIndex + i)
-			return EFalse;
-		}
-	return ETrue;
-	}
-
-
-TBool DPagingRequest::CheckUseDiscontiguous(DMemoryObject** aMemory, TUint* aIndex, TUint aCount)
-	{
-	if (iUseRegionCount != aCount)
-		return EFalse;
-	for (TUint i = 0 ; i < iUseRegionCount ; ++i)
-		{
-		if (iUseRegionMemory[i] != aMemory[i] || iUseRegionIndex[i] != aIndex[i])
-			return EFalse;
-		}
-	return ETrue;
-	}
-
-
- TBool DPagingRequest::IsCollisionContiguous(DMemoryObject* aMemory, TUint aIndex, TUint aCount)
-	{
-	// note this could be optimised as most of the time we will be checking read/read collusions,
-	// both of which will be contiguous
-	__ASSERT_SYSTEM_LOCK;
-	for (TUint i = 0 ; i < iUseRegionCount ; ++i)
-		{
-		if (iUseRegionMemory[i] == aMemory &&
-			TUint(iUseRegionIndex[i] - aIndex) < aCount)
-			return ETrue;
-		}
-	return EFalse;
-	}
-
-
-TLinAddr DPagingRequest::MapPages(TUint aColour, TUint aCount, TPhysAddr* aPages)
+
+TLinAddr DPagingRequestBase::MapPages(TUint aColour, TUint aCount, TPhysAddr* aPages)
 	{
 	__NK_ASSERT_DEBUG(iMutex->iCleanup.iThread == &Kern::CurrentThread());
 	return iTempMapping.Map(aPages,aCount,aColour);
 	}
 
 
-void DPagingRequest::UnmapPages(TBool aIMBRequired)
+void DPagingRequestBase::UnmapPages(TBool aIMBRequired)
 	{
 	__NK_ASSERT_DEBUG(iMutex->iCleanup.iThread == &Kern::CurrentThread());
 	iTempMapping.Unmap(aIMBRequired);
 	}
 
-//
-// DPoolPagingRequest
-//
-
-DPoolPagingRequest::DPoolPagingRequest(DPagingRequestPool::TGroup& aPoolGroup) :
-	iPoolGroup(aPoolGroup)
-	{
-	}
-
-
-void DPoolPagingRequest::Release()
-	{
-	NKern::LockSystem();
-	ResetUse();
-	Signal();
-	}
-
-
-void DPoolPagingRequest::Wait()
-	{
-	__ASSERT_SYSTEM_LOCK;
-	++iUsageCount;
-	TInt r = iMutex->Wait();
-	__NK_ASSERT_ALWAYS(r == KErrNone);
-	}
-
-
-void DPoolPagingRequest::Signal()
-	{
-	__ASSERT_SYSTEM_LOCK;
-	iPoolGroup.Signal(this);
-	}
 
 //
 // DPageReadRequest
 //
 
+
 TInt DPageReadRequest::iAllocNext = 0;
 
+
+TUint DPageReadRequest::ReservedPagesRequired()
+	{
+	return iAllocNext*EMaxPages;
+	}
+
+
 DPageReadRequest::DPageReadRequest(DPagingRequestPool::TGroup& aPoolGroup) :
-	DPoolPagingRequest(aPoolGroup)
+	iPoolGroup(aPoolGroup)
 	{
-	// allocate space for mapping pages whilst they're being loaded...
 	iTempMapping.Alloc(EMaxPages);
 	}
 
+
 TInt DPageReadRequest::Construct()
 	{
 	// allocate id and mutex...
@@ -2568,6 +2580,65 @@
 	}
 
 
+void DPageReadRequest::Release()
+	{
+	NKern::LockSystem();
+	ResetUse();
+	Signal();
+	}
+
+
+void DPageReadRequest::Wait()
+	{
+	__ASSERT_SYSTEM_LOCK;
+	++iUsageCount;
+	TInt r = iMutex->Wait();
+	__NK_ASSERT_ALWAYS(r == KErrNone);
+	}
+
+
+void DPageReadRequest::Signal()
+	{
+	__ASSERT_SYSTEM_LOCK;
+	__NK_ASSERT_DEBUG(iUsageCount > 0);
+	if (--iUsageCount == 0)
+		iPoolGroup.iFreeList.AddHead(&iLink);
+	iMutex->Signal();
+	}
+
+
+void DPageReadRequest::SetUseContiguous(DMemoryObject* aMemory, TUint aIndex, TUint aCount)
+	{
+	__ASSERT_SYSTEM_LOCK;
+	__NK_ASSERT_DEBUG(aMemory != NULL && aCount <= EMaxPages);
+	__NK_ASSERT_DEBUG(iMemory == NULL);
+	iMemory = aMemory;
+	iIndex = aIndex;
+	iCount = aCount;
+	}
+
+
+void DPageReadRequest::ResetUse()
+	{
+	__ASSERT_SYSTEM_LOCK;
+	__NK_ASSERT_DEBUG(iMemory != NULL);
+	iMemory = NULL;
+	}
+
+
+ TBool DPageReadRequest::IsCollisionContiguous(DMemoryObject* aMemory, TUint aIndex, TUint aCount)
+	{
+	__ASSERT_SYSTEM_LOCK;
+	return iMemory == aMemory && aIndex < iIndex + iCount && aIndex + aCount > iIndex;
+	}
+
+
+TBool DPageReadRequest::CheckUseContiguous(DMemoryObject* aMemory, TUint aIndex, TUint aCount)
+	{
+	return iMemory == aMemory && iIndex == aIndex && iCount == aCount;
+	}
+
+
 //
 // DPageWriteRequest
 //
@@ -2576,8 +2647,7 @@
 DPageWriteRequest::DPageWriteRequest()
 	{
 	iMutex = ThePageCleaningLock;
-	// allocate space for mapping pages whilst they're being loaded...
-	iTempMapping.Alloc(KMaxPagesToClean);
+	iTempMapping.Alloc(EMaxPages);
 	}
 
 
@@ -2589,6 +2659,55 @@
 	}
 
 
+void DPageWriteRequest::SetUseDiscontiguous(DMemoryObject** aMemory, TUint* aIndex, TUint aCount)
+	{
+	__ASSERT_SYSTEM_LOCK;
+	__NK_ASSERT_DEBUG(iUseRegionCount == 0);
+	__NK_ASSERT_DEBUG(aCount > 0 && aCount <= EMaxPages);
+	for (TUint i = 0 ; i < aCount ; ++i)
+		{
+		iUseRegionMemory[i] = aMemory[i];
+		iUseRegionIndex[i] = aIndex[i];
+		}
+	iUseRegionCount = aCount;
+	}
+
+
+void DPageWriteRequest::ResetUse()
+	{
+	__ASSERT_SYSTEM_LOCK;
+	__NK_ASSERT_DEBUG(iUseRegionCount > 0);
+	iUseRegionCount = 0;
+	}
+
+
+TBool DPageWriteRequest::CheckUseContiguous(DMemoryObject* aMemory, TUint aIndex, TUint aCount)
+	{
+	if (iUseRegionCount != aCount)
+		return EFalse;
+	for (TUint i = 0 ; i < iUseRegionCount ; ++i)
+		{
+		if (iUseRegionMemory[i] != aMemory || iUseRegionIndex[i] != aIndex + i)
+			return EFalse;
+		}
+	return ETrue;
+	}
+
+
+ TBool DPageWriteRequest::IsCollisionContiguous(DMemoryObject* aMemory, TUint aIndex, TUint aCount)
+	{
+	// note this could be optimised as most of the time we will be checking read/read collusions,
+	// both of which will be contiguous
+	__ASSERT_SYSTEM_LOCK;
+	for (TUint i = 0 ; i < iUseRegionCount ; ++i)
+		{
+		if (iUseRegionMemory[i] == aMemory &&
+			TUint(iUseRegionIndex[i] - aIndex) < aCount)
+			return ETrue;
+		}
+	return EFalse;
+	}
+
 //
 // DPagingRequestPool
 //
@@ -2604,7 +2723,7 @@
 		TInt r = req->Construct();
 		__NK_ASSERT_ALWAYS(r==KErrNone);
 		iPageReadRequests.iRequests[i] = req;
-		iPageReadRequests.iFreeList.Add(req);
+		iPageReadRequests.iFreeList.Add(&req->iLink);
 		}
 
 	if (aWriteRequest)
@@ -2625,7 +2744,7 @@
 	{
 	NKern::LockSystem();
 
-	DPoolPagingRequest* req;
+	DPageReadRequest* req;
 	
 	// check for collision with existing write
 	if(iPageWriteRequest && iPageWriteRequest->IsCollisionContiguous(aMemory,aIndex,aCount))
@@ -2686,19 +2805,19 @@
 DPagingRequestPool::TGroup::TGroup(TUint aNumRequests)
 	{
 	iNumRequests = aNumRequests;
-	iRequests = new DPoolPagingRequest*[aNumRequests];
+	iRequests = new DPageReadRequest*[aNumRequests];
 	__NK_ASSERT_ALWAYS(iRequests);
 	}
 
 
-DPoolPagingRequest* DPagingRequestPool::TGroup::FindCollisionContiguous(DMemoryObject* aMemory, TUint aIndex, TUint aCount)
+DPageReadRequest* DPagingRequestPool::TGroup::FindCollisionContiguous(DMemoryObject* aMemory, TUint aIndex, TUint aCount)
 	{
 	__ASSERT_SYSTEM_LOCK;
-	DPoolPagingRequest** ptr = iRequests;
-	DPoolPagingRequest** ptrEnd = ptr+iNumRequests;
+	DPageReadRequest** ptr = iRequests;
+	DPageReadRequest** ptrEnd = ptr+iNumRequests;
 	while(ptr<ptrEnd)
 		{
-		DPoolPagingRequest* req = *ptr++;
+		DPageReadRequest* req = *ptr++;
 		if(req->IsCollisionContiguous(aMemory,aIndex,aCount))
 			return req;
 		}
@@ -2708,20 +2827,21 @@
 
 static TUint32 RandomSeed = 33333;
 
-DPoolPagingRequest* DPagingRequestPool::TGroup::GetRequest(DMemoryObject* aMemory, TUint aIndex, TUint aCount)
+DPageReadRequest* DPagingRequestPool::TGroup::GetRequest(DMemoryObject* aMemory, TUint aIndex, TUint aCount)
 	{
 	__NK_ASSERT_DEBUG(iNumRequests > 0);
 
 	// try using an existing request which collides with this region...
-	DPoolPagingRequest* req  = FindCollisionContiguous(aMemory,aIndex,aCount);
+	DPageReadRequest* req  = FindCollisionContiguous(aMemory,aIndex,aCount);
 	if(!req)
 		{
 		// use a free request...
-		req = (DPoolPagingRequest*)iFreeList.GetFirst();
-		if(req)
+		SDblQueLink* first = iFreeList.GetFirst();
+		if(first)
 			{
 			// free requests aren't being used...
-			__NK_ASSERT_DEBUG(req->iUsageCount == 0);
+			req = _LOFF(first, DPageReadRequest, iLink);
+			__NK_ASSERT_DEBUG(req->ThreadsWaiting() == 0);
 			}
 		else
 			{
@@ -2729,7 +2849,7 @@
 			RandomSeed = RandomSeed*69069+1; // next 'random' number
 			TUint index = (TUint64(RandomSeed) * TUint64(iNumRequests)) >> 32;
 			req = iRequests[index];
-			__NK_ASSERT_DEBUG(req->iUsageCount > 0); // we only pick random when none are free
+			__NK_ASSERT_DEBUG(req->ThreadsWaiting() > 0); // we only pick random when none are free
 			}
 		}
 
@@ -2740,17 +2860,6 @@
 	}
 
 
-void DPagingRequestPool::TGroup::Signal(DPoolPagingRequest* aRequest)
-	{
-	// if there are no threads waiting on the mutex then return it to the free pool...
-	__NK_ASSERT_DEBUG(aRequest->iUsageCount > 0);
-	if (--aRequest->iUsageCount==0)
-		iFreeList.AddHead(aRequest);
-
-	aRequest->iMutex->Signal();
-	}
-
-
 /**
 Register the specified paging device with the kernel.
 
--- a/kernel/eka/memmodel/epoc/flexible/mmu/mpager.h	Tue May 11 17:28:22 2010 +0300
+++ b/kernel/eka/memmodel/epoc/flexible/mmu/mpager.h	Tue May 25 14:09:55 2010 +0300
@@ -26,8 +26,11 @@
 
 /**
 Maximum number of pages to attempt to clean in one go.
+
+If a paging device sets a preferred write size greater than this then it will fail to install with
+KErrArgument.
 */
-const TInt KMaxPagesToClean = 4;
+const TUint KMaxPagesToClean = 16;
 
 struct SVMCacheInfo;
 class DMemModelThread;
@@ -334,15 +337,17 @@
 	
 	@param aOldPageInfo	The page info of the page to discard.
 	@param aBlockZoneId	The ID of the RAM zone not to allocate any required new page into.
-	@param aBlockRest	Set to ETrue when we don't want the allocator to search for new pages if the RAM 
-						zone with ID==aBlockZoneId is encountered, i.e. a general RAM defrag operation.
+	@param aMoveDisFlags 	Flags that control the discarding of the page, should be a mask of 
+							values from M::TMoveDiscardFlags
 	*/
-	TInt DiscardPage(SPageInfo* aOldPageInfo, TUint aBlockZoneId, TBool aBlockRest);
+	TInt DiscardPage(SPageInfo* aOldPageInfo, TUint aBlockZoneId, TUint aMoveDisFlags);
 
 	/**
 	Attempt to discard the specified page and then allocate a page of type aPageType
 	in its place.
 	
+	Note - This will always attempt to move dirty pages rather than write them to swap.
+	
 	@param aPageInfo	The page info of the page to discard.
 	@param aPageType 	The new page type to allocate into aPageInfo's physical address.
 	*/
@@ -371,6 +376,34 @@
 	*/
 	void FreePinReplacementPages(TUint aNumPages);
 
+	//
+	// following public members for use by DDataPagedMemoryManager...
+	//
+	
+	/**
+	Called by the data paged memory manager to set the number of pages the pager should attempt to
+	clean at once.
+
+	This also adjusts the maximum size of the oldest list if it is too small to contain the
+	specified number of pages.
+
+	@param aPagesToClean     Number of pages the pager should attempt to clean in one go
+	*/
+	void SetPagesToClean(TUint aPagesToClean);
+
+	/**
+	Get the number of pages the pager attempts to clean at once.
+	*/
+	TUint PagesToClean();
+
+	/**
+	Called by the data paged memory manager to set whether pages cleaned must have sequential page
+	colour.
+
+	@param aCleanInSequence  Whether pages must have sequential page colour
+	*/
+	void SetCleanInSequence(TBool aCleanInSequence);
+
 private:
 	/**
 	Add a page to the head of the live page list. I.e. make it the 'youngest' page.
@@ -399,8 +432,18 @@
 	void RemovePage(SPageInfo* aPageInfo);
 
 	/**
-	Try to remove the oldest page from the live page list and perform #StealPage.
+	Attempt to steal the oldest page on the live list.
 
+	If the oldest page is an oldest dirty page, this attempts to clean multiple pages by calling
+	#CleanSomePages and then returns without stealing any page.  This allows the caller to restart
+	their operation after the lengthy cleaning process, which may no longer need to call this
+	function.
+
+	If the oldest page is on any other list (i.e. is an old or young page) this will steal it,
+	aquiring the page cleaning mutex first if it is dirty.
+
+	Called from #PageInAllocPage.
+	
 	@param aPageInfoOut Set to the SPageInfo pointer for the stolen page if any.
 	
 	@return KErrNone on success, KErrInUse if stealing failed or 1 to indicate the the oldest page
@@ -412,14 +455,6 @@
 	TInt TryStealOldestPage(SPageInfo*& aPageInfoOut);
 
 	/**
-	Remove the oldest page from the live page list and perform #StealPage.
-
-	@pre MmuLock held
-	@post MmuLock held (but may have been released by this function)
-	*/
-	SPageInfo* StealOldestPage();
-
-	/**
 	Steal a page from the memory object (if any) which is using the page.
 	If successful the returned page will be in the EUnknown state and the
 	cache state for the page is indeterminate. This is the same state as
@@ -465,7 +500,7 @@
 
 	@pre RamAllocLock held.
 	*/
-	void ReturnPageToSystem();
+	TBool TryReturnOldestPageToSystem();
 
 	/**
 	Put a specific page back on the system's free pool.
@@ -484,11 +519,11 @@
 	SPageInfo* PageInAllocPage(Mmu::TRamAllocFlags aAllocFlags);
 
 	/**
-	Called by CleanSomePages() to determine which pages should be cleaned.
+	Called by CleanSomePages() to select the pages be cleaned.
 
-	This deals with the complexity of page colouring, which means that pages can only be mapped at
-	certain locations.  When cleaning multiple pages at once we need to find a set of pages that we
-	can map in memory sequentially.
+	This function finds a set of pages that can be mapped sequentially in memory when page colouring
+	restrictions are in effect.  It is only called on systems with page colouring restrictions where
+	the paging media driver does not support writing by phyiscal address.
 
 	@pre MmuLock held
 	
@@ -497,7 +532,22 @@
 	
 	@return The numnber of pages to clean.
 	*/
-	TInt SelectPagesToClean(SPageInfo** aPageInfosOut);
+	TInt SelectSequentialPagesToClean(SPageInfo** aPageInfosOut);
+
+	/**
+	Called by CleanSomePages() to select the pages be cleaned.
+
+	This funciton selects the oldest dirty pages.  It is called on systems without page colouring
+	restrictions or where the paging media driver supports writing by phyiscal address.
+
+	@pre MmuLock held
+	
+	@param aPageInfosOut Pointer to an array of SPageInfo pointers, which must be at least
+	KMaxPagesToClean long.  This will be filled in to indicate the pages to clean.
+	
+	@return The numnber of pages to clean.
+	*/
+	TInt SelectOldestPagesToClean(SPageInfo** aPageInfosOut);
 
 	/**
 	If the number of young pages exceeds that specified by iYoungOldRatio then a
@@ -573,6 +623,7 @@
 	*/
 	TInt PteAndInfoFromLinAddr(	TInt aOsAsid, TLinAddr aAddress, DMemoryMappingBase* aMapping, 
 								TUint aMapInstanceCount, TPte*& aPte, SPageInfo*& aPageInfo);
+	
 #ifdef _DEBUG
 	/**
 	Check consistency of live list.
@@ -598,6 +649,7 @@
 	SDblQue iOldestDirtyList;	/**< Head of 'oldestDirty' page list. */
 	TUint iOldestDirtyCount;	/**< Number of 'oldestDirty' pages */
 	TUint16 iOldOldestRatio;	/**< Ratio of old pages to oldest to clean and dirty in the live page list*/
+	TUint iMaxOldestPages;      /**< Maximum number of oldest pages. */
 	TUint iNumberOfFreePages;
 	TUint iNumberOfDirtyPages;	/**< The total number of dirty pages in the paging cache. Protected by MmuLock */
 	TUint iInitMinimumPageCount;/**< Initial value for iMinimumPageCount */
@@ -605,6 +657,9 @@
 	TUint iReservePageCount;	/**< Number of pages reserved for locking */
 	TUint iMinimumPageLimit;	/**< Minimum size for iMinimumPageCount, not including locked pages.
 								     iMinimumPageCount >= iMinimumPageLimit + iReservePageCount */
+	TUint iPagesToClean;        /**< Preferred number of pages to attempt to clean in one go. */
+	TBool iCleanInSequence;     /**< Pages to be cleaned must have sequential page colour. */
+
 	SVMEventInfo iEventInfo;
 
 #ifdef __DEMAND_PAGING_BENCHMARKS__
@@ -772,7 +827,6 @@
 const TInt KPagingRequestsPerDevice = 2;
 
 
-class DPoolPagingRequest;
 class DPageReadRequest;
 class DPageWriteRequest;
 
@@ -792,110 +846,98 @@
 		{
 	public:
 		TGroup(TUint aNumRequests);
-		DPoolPagingRequest* FindCollisionContiguous(DMemoryObject* aMemory, TUint aIndex, TUint aCount);
-		DPoolPagingRequest* GetRequest(DMemoryObject* aMemory, TUint aIndex, TUint aCount);
-		void Signal(DPoolPagingRequest* aRequest);
+		DPageReadRequest* FindCollisionContiguous(DMemoryObject* aMemory, TUint aIndex, TUint aCount);
+		DPageReadRequest* GetRequest(DMemoryObject* aMemory, TUint aIndex, TUint aCount);
 	public:
 		TUint iNumRequests;
-		DPoolPagingRequest** iRequests;
+		DPageReadRequest** iRequests;
 		SDblQue iFreeList;
 		};
 	TGroup iPageReadRequests;
 	DPageWriteRequest* iPageWriteRequest;
 
-	friend class DPoolPagingRequest;
 	friend class DPageReadRequest;
-	friend class DPageWriteRequest;
 	};
 
 
 /**
-Resources needed to service a paging request.
+Common resources needed to service a paging request.
 */
-class DPagingRequest : public SDblQueLink
+class DPagingRequestBase : public DBase
 	{
 public:
+	TLinAddr MapPages(TUint aColour, TUint aCount, TPhysAddr* aPages);
+	void UnmapPages(TBool aIMBRequired);
+public:  // for DPagingRequestPool
+	DMutex*			iMutex;		/**< A mutex for synchronisation and priority inheritance. */
+protected:
+	Mmu::TTempMapping	iTempMapping;
+	};
+
+
+/**
+Resources needed to service a page in request.
+*/
+class DPageReadRequest : public DPagingRequestBase
+	{
+public:
+	static TUint ReservedPagesRequired();
+private:
+	static TInt iAllocNext;
+
+public:
 	enum
 		{
 		EMaxPages = 4
 		};
-	DPagingRequest();
-	TLinAddr MapPages(TUint aColour, TUint aCount, TPhysAddr* aPages);
-	void UnmapPages(TBool aIMBRequired);
-	void SetUseContiguous(DMemoryObject* aMemory, TUint aIndex, TUint aCount);
-	void SetUseDiscontiguous(DMemoryObject** aMemory, TUint* aIndex, TUint aCount);
-	void ResetUse();
-	TBool CheckUseContiguous(DMemoryObject* aMemory, TUint aIndex, TUint aCount);
-	TBool CheckUseDiscontiguous(DMemoryObject** aMemory, TUint* aIndex, TUint aCount);
-	TBool IsCollisionContiguous(DMemoryObject* aMemory, TUint aIndex, TUint aCount);
-public:
-	DMutex*			iMutex;		/**< A mutex for synchronisation and priority inheritance. */
-protected:
-	Mmu::TTempMapping	iTempMapping;
-private:
-	// used to identify memory request is used for...
-	TUint			iUseRegionCount;
-	DMemoryObject*	iUseRegionMemory[EMaxPages];
-	TUint			iUseRegionIndex[EMaxPages];
-	};
-
-
-__ASSERT_COMPILE(DPagingRequest::EMaxPages >= KMaxPagesToClean);
-
-
-/**
-A paging request that is part of a pool of similar request objects.
-*/
-class DPoolPagingRequest : public DPagingRequest
-	{
-public:
-	DPoolPagingRequest(DPagingRequestPool::TGroup& aPoolGroup);
+	DPageReadRequest(DPagingRequestPool::TGroup& aPoolGroup);
+	TInt Construct();
  	void Release();
 	void Wait();
 	void Signal();
-public:
-	TInt			iUsageCount;	/**< How many threads are using or waiting for this object. */	
+	void SetUseContiguous(DMemoryObject* aMemory, TUint aIndex, TUint aCount);
+	void ResetUse();
+	TBool CheckUseContiguous(DMemoryObject* aMemory, TUint aIndex, TUint aCount);
+	TBool IsCollisionContiguous(DMemoryObject* aMemory, TUint aIndex, TUint aCount);
+	TLinAddr Buffer() { return iBuffer; }
+	TUint ThreadsWaiting() { return iUsageCount; }
 private:
+	~DPageReadRequest() { }  // can't delete
+public:  // for DPagingRequestPool
+	SDblQueLink iLink;  /**< Link into list of free requests. */
+private:
+	TInt iUsageCount;	/**< How many threads are using or waiting for this object. */	
+	TLinAddr iBuffer;	/**< A buffer of size EMaxPages+1 pages to read compressed data into. */
 	DPagingRequestPool::TGroup& iPoolGroup;
+	DMemoryObject* iMemory;
+	TUint iIndex;
+	TUint iCount;
 	};
 
-	
-/**
-Resources needed to service a page in request.
-*/
-class DPageReadRequest : public DPoolPagingRequest
-	{
-public:
-	DPageReadRequest(DPagingRequestPool::TGroup& aPoolGroup);
-	TInt Construct();
-	static TUint ReservedPagesRequired();
-private:
-	~DPageReadRequest(); // can't delete
-public:
-	TLinAddr		iBuffer;	/**< A buffer to read compressed data into. Size is EMaxPages+1 pages.*/
-private:
-	DMemoryObject*	iMemory;
-private:
-	static TInt iAllocNext;
-	};
-
-
-FORCE_INLINE TUint DPageReadRequest::ReservedPagesRequired()
-	{
-	return iAllocNext*EMaxPages;
-	}
-
 
 /**
 Resources needed to service a page out request.
 */
-class DPageWriteRequest : public DPagingRequest
+class DPageWriteRequest : public DPagingRequestBase
 	{
 public:
+	enum
+		{
+		EMaxPages = KMaxPagesToClean
+		};
 	DPageWriteRequest();
  	void Release();
+	void SetUseDiscontiguous(DMemoryObject** aMemory, TUint* aIndex, TUint aCount);
+	void ResetUse();
+	TBool CheckUseContiguous(DMemoryObject* aMemory, TUint aIndex, TUint aCount);
+	TBool IsCollisionContiguous(DMemoryObject* aMemory, TUint aIndex, TUint aCount);
 private:
-	~DPageWriteRequest(); // can't delete
+	~DPageWriteRequest() { }  // can't delete	
+private:
+	// used to identify the memory the request is used for...
+	TUint			iUseRegionCount;
+	DMemoryObject*	iUseRegionMemory[EMaxPages];
+	TUint			iUseRegionIndex[EMaxPages];
 	};
 
 
--- a/kernel/eka/memmodel/epoc/flexible/mmu/mptalloc.cpp	Tue May 11 17:28:22 2010 +0300
+++ b/kernel/eka/memmodel/epoc/flexible/mmu/mptalloc.cpp	Tue May 25 14:09:55 2010 +0300
@@ -118,6 +118,8 @@
 
 	virtual TInt MovePage(	DMemoryObject* aMemory, SPageInfo* aOldPageInfo, 
 							TPhysAddr& aNewPage, TUint aBlockZoneId, TBool aBlockRest);
+
+	virtual TInt MoveAndAllocPage(DMemoryObject* aMemory, SPageInfo* aPageInfo, TZonePageType aType);
 public:
 	/**
 	Allocate a page of RAM for storing page tables in.
@@ -182,7 +184,6 @@
 			}
 #endif
 		}
-	RamAllocLock::Unlock();
 
 	TUint usedNew = 0;
 	if(r==KErrNone)
@@ -197,9 +198,15 @@
 		MmuLock::Unlock();
 		usedNew = 1;
 
+		// Must hold the ram alloc lock until the page has been set as managed
+		// otherwise it will still be seen as free by the rest of the system.
+		RamAllocLock::Unlock();
+
 		// map page...
 		r = aMemory->MapPages(pageList);
 		}
+	else
+		RamAllocLock::Unlock();
 
 	// release page array entry...
 	aMemory->iPages.AddPageEnd(aIndex,usedNew);
@@ -263,13 +270,22 @@
 	return r;
 	}
 
+
 TInt DPageTableMemoryManager::MovePage(	DMemoryObject* aMemory, SPageInfo* aOldPageInfo, 
 										TPhysAddr& aNewPage, TUint aBlockZoneId, TBool aBlockRest)
-		{
-		// This could be a demand paged page table info which can be discarded 
-		// but let the PageTableAllocator handle that.
-		return ::PageTables.MovePage(aMemory, aOldPageInfo, aBlockZoneId, aBlockRest);
-		}
+	{
+	// This could be a demand paged page table info which can be discarded 
+	// but let the PageTableAllocator handle that.
+	return ::PageTables.MovePage(aMemory, aOldPageInfo, aBlockZoneId, aBlockRest);
+	}
+
+
+TInt DPageTableMemoryManager::MoveAndAllocPage(DMemoryObject* aMemory, SPageInfo* aPageInfo, TZonePageType aPageType)
+	{
+	// This could be a demand paged page table info which can be discarded 
+	// but let the PageTableAllocator handle that.
+	return ::PageTables.MoveAndAllocPage(aMemory, aPageInfo, aPageType);
+	}
 
 
 //
@@ -1206,7 +1222,19 @@
 	// Let the pager discard the page as it controls the size of the live list.
 	// If the size of the live list allows then eventually 
 	// PageTableAllocator::StealPage() will be invoked on this page.
-	return ThePager.DiscardPage(aOldPageInfo, aBlockZoneId, aBlockRest);
+	TUint moveDisFlags = (aBlockRest)? M::EMoveDisBlockRest : 0;
+	return ThePager.DiscardPage(aOldPageInfo, aBlockZoneId, moveDisFlags);
+	}
+
+
+TInt PageTableAllocator::MoveAndAllocPage(DMemoryObject* aMemory, SPageInfo* aPageInfo, TZonePageType aPageType)
+	{
+	TInt r = MovePage(aMemory, aPageInfo, KRamZoneInvalidId, EFalse);
+	if (r == KErrNone)
+		{
+		TheMmu.MarkPageAllocated(aPageInfo->PhysAddr(), aPageType);
+		}
+	return r;
 	}
 
 
--- a/kernel/eka/memmodel/epoc/flexible/mmu/mptalloc.h	Tue May 11 17:28:22 2010 +0300
+++ b/kernel/eka/memmodel/epoc/flexible/mmu/mptalloc.h	Tue May 25 14:09:55 2010 +0300
@@ -137,6 +137,17 @@
 	TInt MovePage(	DMemoryObject* aMemory, SPageInfo* aOldPageInfo, 
 						TUint aBlockZoneId, TBool aBlockRest);
 
+	/**
+	Attempts to discard a page of page tables using #MovePage.  If the discard was 
+	succesful it then allocates the page with type aPageType.
+	
+	@param aMemory		This should always be the page table info memory object.
+	@param aPageInfo	The page info of the page to discard.
+
+	@return KErrNone if the page could be successfully discarded and its RAM page allocated.
+	*/
+	TInt MoveAndAllocPage(DMemoryObject* aMemory, SPageInfo* aPageInfo, TZonePageType aPageType);
+
 #ifdef _DEBUG
 	/**
 	Debug function for use by DPager::RemovePage() to allow it to remove
--- a/kernel/eka/memmodel/epoc/flexible/mmu/mrom.cpp	Tue May 11 17:28:22 2010 +0300
+++ b/kernel/eka/memmodel/epoc/flexible/mmu/mrom.cpp	Tue May 25 14:09:55 2010 +0300
@@ -574,7 +574,7 @@
 				__NK_ASSERT_ALWAYS(romPageInfo->iPagingAttributes & SRomPageInfo::EPageable);
 
 				// Read data for page...
-				const TLinAddr buffer = aRequest->iBuffer;
+				const TLinAddr buffer = aRequest->Buffer();
 				const TUint readStart = dataOffset >> readUnitShift;
 				const TUint readSize = ((dataOffset + dataSize - 1) >> readUnitShift) - readStart + 1;
 				__NK_ASSERT_DEBUG((readSize << readUnitShift) <= (DPageReadRequest::EMaxPages << KPageShift));
--- a/kernel/eka/memmodel/epoc/flexible/mmu/mswap.h	Tue May 11 17:28:22 2010 +0300
+++ b/kernel/eka/memmodel/epoc/flexible/mmu/mswap.h	Tue May 25 14:09:55 2010 +0300
@@ -23,5 +23,10 @@
 
 extern void GetSwapInfo(SVMSwapInfo& aInfoOut);
 extern TInt SetSwapThresholds(const SVMSwapThresholds& aThresholds);
+extern TBool GetPhysicalAccessSupported();
+extern TBool GetUsePhysicalAccess();
+extern void SetUsePhysicalAccess(TBool aUsePhysicalAccess);
+extern TUint GetPreferredDataWriteSize();
+extern TInt SetDataWriteSize(TUint aWriteShift);
 
 #endif
--- a/kernel/eka/memmodel/epoc/mmubase/defragbase.cpp	Tue May 11 17:28:22 2010 +0300
+++ b/kernel/eka/memmodel/epoc/mmubase/defragbase.cpp	Tue May 25 14:09:55 2010 +0300
@@ -78,6 +78,7 @@
 	TUint offset = 0;
 	TPhysAddr newAddr;
 	TBool zoneActive = EFalse;
+	const TUint moveDisFlags = (aBestEffort)? 0 : M::EMoveDisBlockRest | M::EMoveDisMoveDirty;
 	TInt ret = iRamAllocator->NextAllocatedPage(&aZone, offset, EPageMovable);
 
 	// if not best effort mode keep moving pages unless someone allocates into 
@@ -101,7 +102,7 @@
 			__KTRACE_OPT(KMMU, Kern::Printf("ClearMovableFromZone: memory too low or zone active addr %x", addr));
 			return KErrNoMemory;
 			}
-		TInt moved = M::MovePage(addr, newAddr, aZone.iId, !aBestEffort);
+		TInt moved = M::MovePage(addr, newAddr, aZone.iId, moveDisFlags);
 		if (moved != KErrNone)
 			{// Couldn't move the page so stop as we can't clear the zone
 			if (!aBestEffort)
@@ -144,6 +145,7 @@
 	TUint offset = 0;
 	TBool zoneActive = EFalse;
 	TInt ret = iRamAllocator->NextAllocatedPage(&aZone, offset, EPageDiscard);
+	const TUint moveDisFlags = (aBestEffort)? 0 : M::EMoveDisBlockRest | M::EMoveDisMoveDirty;
 
 
 	while (	aZone.iAllocPages[EPageDiscard] != 0 && ret == KErrNone && 
@@ -169,7 +171,7 @@
 			return KErrNoMemory;
 			}
 
-		TInt discardRet = M::DiscardPage(addr, aZone.iId, !aBestEffort);
+		TInt discardRet = M::DiscardPage(addr, aZone.iId, moveDisFlags);
 		if (discardRet == KErrNone)
 			{// Page was discarded successfully.
 			if (aMaxDiscard)
--- a/kernel/eka/memmodel/epoc/mmubase/mmubase.cpp	Tue May 11 17:28:22 2010 +0300
+++ b/kernel/eka/memmodel/epoc/mmubase/mmubase.cpp	Tue May 25 14:09:55 2010 +0300
@@ -5473,7 +5473,7 @@
 		}
 
 	MmuBase::Wait();
-	TInt r=M::MovePage(aOld,aNew,KRamZoneInvalidId,EFalse);
+	TInt r=M::MovePage(aOld,aNew,KRamZoneInvalidId,0);
 	if (r!=KErrNone)
 		aNew = KPhysAddrInvalid;
 	MmuBase::Signal();
--- a/kernel/eka/memmodel/epoc/mmubase/ramalloc.cpp	Tue May 11 17:28:22 2010 +0300
+++ b/kernel/eka/memmodel/epoc/mmubase/ramalloc.cpp	Tue May 25 14:09:55 2010 +0300
@@ -1330,26 +1330,37 @@
 		Kern::Printf("ZoneClearPages: ID 0x%x, req 0x%x", aZone.iId, aRequiredPages));
 	// Discard the required number of discardable pages.
 	TUint offset = 0;
-	TInt r = NextAllocatedPage(&aZone, offset, EPageDiscard);
-	while (r == KErrNone && aRequiredPages)
+	for (; aRequiredPages; offset++)
 		{
+		TInt r = NextAllocatedPage(&aZone, offset, EPageDiscard);
+		if (r != KErrNone)
+			break;
+		if (iContiguousReserved && aZone.iBma[EPageFixed]->NotFree(offset, 1))
+			{
+			offset++;
+			continue;
+			}
 		TPhysAddr physAddr = (offset << KPageShift) + aZone.iPhysBase;
-		TInt discarded = M::DiscardPage(physAddr, aZone.iId, EFalse);
+		TInt discarded = M::DiscardPage(physAddr, aZone.iId, M::EMoveDisMoveDirty);
 		if (discarded == KErrNone)
 			{// The page was successfully discarded.
 			aRequiredPages--;
 			}
-		offset++;
-		r = NextAllocatedPage(&aZone, offset, EPageDiscard);
 		}
 	// Move the required number of movable pages.
-	offset = 0;
-	r = NextAllocatedPage(&aZone, offset, EPageMovable);
-	while(r == KErrNone && aRequiredPages)
+	for (offset = 0; aRequiredPages; offset++)
 		{
+		TInt r = NextAllocatedPage(&aZone, offset, EPageMovable);
+		if (r != KErrNone)
+			break;
+		if (iContiguousReserved && aZone.iBma[EPageFixed]->NotFree(offset, 1))
+			{
+			offset++;
+			continue;
+			}
 		TPhysAddr physAddr = (offset << KPageShift) + aZone.iPhysBase;
 		TPhysAddr newAddr = KPhysAddrInvalid;
-		if (M::MovePage(physAddr, newAddr, aZone.iId, EFalse) == KErrNone)
+		if (M::MovePage(physAddr, newAddr, aZone.iId, 0) == KErrNone)
 			{// The page was successfully moved.
 #ifdef _DEBUG
 			TInt newOffset = 0;
@@ -1358,8 +1369,6 @@
 #endif
 			aRequiredPages--;
 			}
-		offset++;
-		r = NextAllocatedPage(&aZone, offset, EPageMovable);
 		}
 	}
 
@@ -1441,14 +1450,15 @@
 	TPhysAddr* pageListBase = aPageList;
 	TUint32 numMissing = aNumPages;
 
+	if ((TUint)aNumPages > iTotalFreeRamPages)
+		{// Not enough free pages to fulfill this request so return the amount required
+		return aNumPages - iTotalFreeRamPages;
+		}
+
 	if (aType == EPageFixed)
 		{// Currently only a general defrag operation should set this and it won't
 		// allocate fixed pages.
 		__NK_ASSERT_DEBUG(!aBlockRest);
-		if ((TUint)aNumPages > iTotalFreeRamPages + M::NumberOfFreeDpPages())
-			{// Not enough free space and not enough freeable pages.
-			goto exit;
-			}
 
 		// Search through each zone in preference order until all pages allocated or
 		// have reached the end of the preference list
@@ -1484,11 +1494,6 @@
 		}
 	else
 		{
-		if ((TUint)aNumPages > iTotalFreeRamPages)
-			{// Not enough free pages to fulfill this request so return amount required
-			return aNumPages - iTotalFreeRamPages;
-			}
-
 		// Determine if there are enough free pages in the RAM zones in use.
 		TUint totalFreeInUse = 0;
 		SDblQueLink* link = iZoneLeastMovDis;
@@ -1725,7 +1730,7 @@
 
 
 #if !defined(__MEMMODEL_MULTIPLE__) && !defined(__MEMMODEL_MOVING__)
-void DRamAllocator::BlockContiguousRegion(TPhysAddr aAddrBase, TUint aNumPages)
+TUint DRamAllocator::BlockContiguousRegion(TPhysAddr aAddrBase, TUint aNumPages)
 	{
 	// Shouldn't be asked to block zero pages, addrEndPage would be wrong if we did.
 	__NK_ASSERT_DEBUG(aNumPages);
@@ -1734,6 +1739,7 @@
 	TInt tmpOffset;
 	SZone* endZone = GetZoneAndOffset(addrEndPage, tmpOffset);
 	SZone* tmpZone;
+	TUint totalUnreserved = aNumPages;
 	do
 		{
 		tmpZone = GetZoneAndOffset(addr, tmpOffset);
@@ -1754,11 +1760,13 @@
 #endif
 			ZoneAllocPages(tmpZone, reserved, EPageFixed);
 			iTotalFreeRamPages -= reserved;
+			totalUnreserved -= reserved;
 			}
 		tmpZone->iBma[EPageFixed]->Alloc(tmpOffset, runLength);
 		addr = tmpZone->iPhysEnd + 1;
 		}
 	while (tmpZone != endZone);
+	return totalUnreserved;
 	}
 
 
@@ -1834,13 +1842,43 @@
 	}
 
 
-TBool DRamAllocator::ClearContiguousRegion(TPhysAddr aAddrBase, TPhysAddr aZoneBase, TUint aNumPages, TInt& aOffset)
+TUint DRamAllocator::CountPagesInRun(TPhysAddr aAddrBase, TPhysAddr aAddrEndPage, TZonePageType aType)
+	{
+	__NK_ASSERT_DEBUG(aAddrBase <= aAddrEndPage);
+	TUint totalAllocated = 0;
+	TPhysAddr addr = aAddrBase;
+	TUint tmpOffset;
+	SZone* endZone = GetZoneAndOffset(aAddrEndPage, (TInt&)tmpOffset);
+	SZone* tmpZone;
+	do
+		{
+		tmpZone = GetZoneAndOffset(addr, (TInt&)tmpOffset);
+		__NK_ASSERT_DEBUG(tmpZone != NULL);
+		TUint runLength = 	(aAddrEndPage < tmpZone->iPhysEnd)? 
+							((aAddrEndPage - addr) >> KPageShift) + 1: 
+							tmpZone->iPhysPages - tmpOffset;
+		TUint runEnd = tmpOffset + runLength - 1;
+		while (tmpOffset <= runEnd)
+			{
+			TUint run = NextAllocatedRun(tmpZone, tmpOffset, runEnd, aType);
+			totalAllocated += run;
+			tmpOffset += run;
+			}
+		addr = tmpZone->iPhysEnd + 1;
+		}
+	while (tmpZone != endZone);
+	return totalAllocated;
+	}
+
+
+TInt DRamAllocator::ClearContiguousRegion(TPhysAddr aAddrBase, TPhysAddr aZoneBase, TUint aNumPages, TInt& aOffset, TUint aUnreservedPages)
 	{
 	TPhysAddr addr = aAddrBase;
-	TPhysAddr addrEnd = aAddrBase + (aNumPages << KPageShift);
+	TPhysAddr addrEndPage = aAddrBase + ((aNumPages -1 )<< KPageShift);
 	TInt contigOffset = 0;
 	SZone* contigZone = GetZoneAndOffset(addr, contigOffset);
-	for (; addr != addrEnd; addr += KPageSize, contigOffset++)
+	TUint unreservedPages = aUnreservedPages;
+	for (; addr <= addrEndPage; addr += KPageSize, contigOffset++)
 		{
 		if (contigZone->iPhysEnd < addr)
 			{
@@ -1852,17 +1890,41 @@
 		__NK_ASSERT_DEBUG(contigZone->iBma[EPageFixed]->NotFree(contigOffset, 1));
 		__NK_ASSERT_DEBUG(SPageInfo::SafeFromPhysAddr(addr) != NULL);
 
-		// WARNING - This may flash the ram alloc mutex.
-		TInt exRet = M::MoveAndAllocPage(addr, EPageFixed);
-		if (exRet != KErrNone)
+		if (unreservedPages > iTotalFreeRamPages)
+			{// May need to discard some pages so there is free space for the 
+			// pages in the contiguous run to be moved to.
+			TUint requiredPages = unreservedPages - iTotalFreeRamPages;
+			if (requiredPages)
+				{// Ask the pager to get free some pages.
+				M::GetFreePages(requiredPages);
+
+				// The ram alloc lock may have been flashed so ensure that we still have
+				// enough free ram to complete the allocation.
+				TUint remainingPages = ((addrEndPage - addr) >> KPageShift) + 1;
+				unreservedPages = remainingPages - CountPagesInRun(addr, addrEndPage, EPageFixed);
+				if (unreservedPages > iTotalFreeRamPages + M::NumberOfFreeDpPages())
+					{// Not enough free space and not enough freeable pages.
+					return KErrNoMemory;
+					}
+				}
+			}
+
+		TInt r = M::MoveAndAllocPage(addr, EPageFixed);
+		if (r != KErrNone)
 			{// This page couldn't be moved or discarded so 
 			// restart the search the page after this one.
-			__KTRACE_OPT(KMMU2, Kern::Printf("ContigMov fail contigOffset 0x%x exRet %d", contigOffset, exRet));
+			__KTRACE_OPT(KMMU2, Kern::Printf("ContigMov fail contigOffset 0x%x r %d", contigOffset, r));
 			aOffset = (addr < aZoneBase)? 0 : contigOffset + 1;
-			break;
+			return r;
 			}
+		__NK_ASSERT_DEBUG(contigZone->iBma[EPageFixed]->NotFree(contigOffset, 1));
+		__NK_ASSERT_DEBUG(contigZone->iBma[KBmaAllPages]->NotFree(contigOffset, 1));
+		__NK_ASSERT_DEBUG(contigZone->iBma[EPageDiscard]->NotAllocated(contigOffset, 1));
+		__NK_ASSERT_DEBUG(contigZone->iBma[EPageMovable]->NotAllocated(contigOffset, 1));
 		}
-	return addr == addrEnd;
+
+	// Successfully cleared the contiguous run
+	return KErrNone;
 	}
 
 
@@ -1889,6 +1951,13 @@
 		{// Not enough free space and not enough freeable pages.
 		return KErrNoMemory;
 		}
+	if (aNumPages > iTotalFreeRamPages)
+		{// Need to discard some pages so there is free space for the pages in 
+		// the contiguous run to be moved to.
+		TUint requiredPages = aNumPages - iTotalFreeRamPages;
+		if (!M::GetFreePages(requiredPages))
+			return KErrNoMemory;
+		}
 
 	TInt alignWrtPage = Max(aAlign - KPageShift, 0);
 	TUint32 alignmask = (1u << alignWrtPage) - 1;
@@ -1950,8 +2019,9 @@
 				
 				// Block the contiguous region from being allocated.
 				iContiguousReserved++;
-				BlockContiguousRegion(addrBase, aNumPages);
-				if (ClearContiguousRegion(addrBase, zone->iPhysBase, aNumPages, offset))
+				TUint unreservedPages = BlockContiguousRegion(addrBase, aNumPages);
+				TInt clearRet = ClearContiguousRegion(addrBase, zone->iPhysBase, aNumPages, offset, unreservedPages);
+				if (clearRet == KErrNone)
 					{// Cleared all the required pages.
 					// Return address of physical page at the start of the region.
 					iContiguousReserved--;
@@ -1977,6 +2047,11 @@
 					carryImmov = 0;
 					carryAll = 0;
 					__KTRACE_OPT(KMMU2, Kern::Printf("<AllocContigfail run 0x%08x - 0x%08x 0x%x", addrBase, addrBase + (aNumPages << KPageShift), TheCurrentThread));
+					if (clearRet == KErrNoMemory)
+						{// There are no longer enough free or discardable pages to 
+						// be able to fulfill this allocation.
+						return KErrNoMemory;
+						}
 					}
 				}
 			}
@@ -2099,7 +2174,7 @@
 						__NK_ASSERT_DEBUG(SPageInfo::SafeFromPhysAddr(addr) != NULL);
 
 						TPhysAddr newAddr;
-						TInt moveRet = M::MovePage(addr, newAddr, contigZone->iId, EFalse);
+						TInt moveRet = M::MovePage(addr, newAddr, contigZone->iId, 0);
 						if (moveRet != KErrNone && moveRet != KErrNotFound)
 							{// This page couldn't be moved or discarded so 
 							// restart the search the page after this one.
@@ -2462,8 +2537,7 @@
 				page in the zone should be found, on return it will be the offset 
 				of the next allocated page.
 @param aEndOffset The last offset within this RAM zone to check for allocated runs.
-@return The length of any run found, KErrNotFound if no more pages in
-the zone after aOffset are allocated, KErrArgument if aOffset is outside the zone.
+@return The length of any run found.
 */
 TInt DRamAllocator::NextAllocatedRun(SZone* aZone, TUint& aOffset, TUint aEndOffset, TZonePageType aType) const
 	{
--- a/kernel/eka/release.txt	Tue May 11 17:28:22 2010 +0300
+++ b/kernel/eka/release.txt	Tue May 25 14:09:55 2010 +0300
@@ -1,3 +1,58 @@
+Version 2.00.2122
+=================
+(Made by vfebvre 11/05/2010)
+
+1.	martai
+	1.	ou1cimx1#378868 Contiguous memory allocations do not use multi-page write support
+
+2.	jimhofe
+	1.	ou1cimx1#367891: Changing MedSD3c PolicyId from 2 to 1461
+
+
+Version 2.00.2121
+=================
+(Made by vfebvre 10/05/2010)
+
+1.	necliffo
+	1.	ou1cimx1#375835: eMMC reliable Write can increase wear of eMMC devices
+
+
+Version 2.00.2120
+=================
+(Made by vfebvre 07/05/2010)
+
+1.	mipetzol
+	1.	ou1cimx1#374045 DMA V2 should be removed from TB9.2
+
+2.	jcoppear
+	1.	ou1cimx1#37212: WDP: Non aligned swap writes increase media wear
+
+
+Version 2.00.2119
+=================
+(Made by vfebvre 05/05/2010)
+
+1.	jimmzhou
+	1.	ou1cimx1#366904 [kernel92][[Internal]t_usbapi test is not ready to run on production phone environment Vasco/hw79
+
+2.	gcochran
+	1.	ou1cimx1#367933 TB9.2 - Undefined Symbol error with the header "e32math.h"
+
+3.	ricoles
+	1.	DEF139990 SMP known test failures 
+
+
+Version 2.00.2118
+=================
+(Made by vfebvre 30/04/2010)
+
+1.	stmansfi
+	1.	ou1cimx1#361784 HAL GetAll() returns handle based attributes leading to unnecessary resource allocation
+
+2.	jimhofe
+	1.	ou1cimx1#366068 Change unistore II policyId from 2 to 1455
+
+
 Version 2.00.2117
 =================
 (Made by vfebvre 28/04/2010)
--- a/kernel/eka/rombuild/mmctest_load.oby	Tue May 11 17:28:22 2010 +0300
+++ b/kernel/eka/rombuild/mmctest_load.oby	Tue May 25 14:09:55 2010 +0300
@@ -18,6 +18,7 @@
 // depends on the mmctest_test being built first (it includes it)
 
 #define BASE_ROM
+#define MMCLOADER_ROM
 #define REBOOT_DRIVER
 
 #include <rom\##VARIANT##\header.iby>
--- a/kerneltest/e32test/defrag/t_ramdefrag.cpp	Tue May 11 17:28:22 2010 +0300
+++ b/kerneltest/e32test/defrag/t_ramdefrag.cpp	Tue May 25 14:09:55 2010 +0300
@@ -1518,7 +1518,7 @@
 				}
 			else
 				{
-				if ((allocMov || allocDis) && prevZoneNotFull)
+				if (verifySpread && (allocMov || allocDis) && prevZoneNotFull)
 					{// The previous least preferable RAM zones were not full so shouldn't
 					// be any movable or discardable pages in the RAM zones of this preference.
 					test.Printf(_L("Movable or discardable pages in more preferable RAM zones unnecessarily\n"));
@@ -3053,8 +3053,9 @@
 				break;
 				}
 			totMov -= gZoneUtilArray[zoneIndexCand].iAllocMovable;
-			if (gZoneUtilArray[zoneIndexCand].iFreePages != gZoneUtilArray[zoneIndexCand].iPhysPages &&
-				gZoneUtilArray[zoneIndexCand].iFreePages != 0)
+			if (gZoneUtilArray[zoneIndexCand].iFreePages &&
+				(gZoneUtilArray[zoneIndexCand].iAllocMovable || 
+				gZoneUtilArray[zoneIndexCand].iAllocDiscardable))
 				{
 				zoneNotEmptyOrFull = ETrue;
 				}
--- a/kerneltest/e32test/demandpaging/t_thrash.cpp	Tue May 11 17:28:22 2010 +0300
+++ b/kerneltest/e32test/demandpaging/t_thrash.cpp	Tue May 25 14:09:55 2010 +0300
@@ -667,7 +667,7 @@
 	delete [] data;
 	}
 
-void BenchmarkReplacement()
+void TestDistributions()
 	{
  	test.Next(_L("Test uniform distribution"));
 	TUniformRandom rand1;
@@ -678,6 +678,49 @@
 	TNormalRandom rand2;
 	rand2.SetParams(100, 25);
 	TestDistribution(rand2, 10000);
+	}
+
+void BenchmarkReplacement()
+	{
+	// Report block write and physical access settings
+	test.Next(_L("Report media physical access and preferred write size settings"));
+	TInt physAccessSupported = UserSvr::HalFunction(EHalGroupVM, EVMHalGetPhysicalAccessSupported, 0, 0);
+	test(physAccessSupported == 0 || physAccessSupported == 1);
+	if (physAccessSupported)
+ 		test.Printf(_L("Physical access supported\n"));
+	else
+ 		test.Printf(_L("Physical access not supported\n"));
+
+	TInt preferredWriteSize = UserSvr::HalFunction(EHalGroupVM, EVMHalGetPreferredDataWriteSize, 0, 0);
+	test(preferredWriteSize >= 0);
+	test.Printf(_L("Preferred write size %d pages\n"), 1 << preferredWriteSize);
+
+	for (TInt physAccess = 0 ; physAccess <= physAccessSupported ; ++physAccess)
+		{
+		test_KErrNone(UserSvr::HalFunction(EHalGroupVM, EVMHalSetUsePhysicalAccess, (TAny*)physAccess, 0));
+		test_Equal(physAccess, UserSvr::HalFunction(EHalGroupVM, EVMHalGetUsePhysicalAccess, 0, 0));
+		TInt writeSize = 0;
+		for (;;)
+			{
+			test_KErrNone(UserSvr::HalFunction(EHalGroupVM, EVMHalSetDataWriteSize, (TAny*)writeSize, 0));
+			TInt writeSizeSet = UserSvr::HalFunction(EHalGroupVM, EVMHalGetDataWriteSize, 0, 0);
+			test (writeSizeSet >= 0);
+			if (writeSizeSet != writeSize)
+				break;  // stop loop when we reach limit of supported write size
+
+			TBuf<128> title;
+			title.AppendFormat(_L("Thrash test: single thread, normal random workload 2, phys access %d, write size %dKB"),
+							   physAccess, 1 << (writeSize - 2));
+			ThrashTest(title, 1, ETrue, EWorkloadNormalRandom2, (2 * gMaxCacheSize) / 3, 2 * gMaxCacheSize, 0);
+
+			++writeSize;
+			}
+		}
+
+	test_KErrNone(UserSvr::HalFunction(EHalGroupVM, EVMHalSetUsePhysicalAccess, (TAny*)physAccessSupported, 0));
+	test_Equal(physAccessSupported, UserSvr::HalFunction(EHalGroupVM, EVMHalGetUsePhysicalAccess, 0, 0));
+	test_KErrNone(UserSvr::HalFunction(EHalGroupVM, EVMHalSetDataWriteSize, (TAny*)preferredWriteSize, 0));
+	test_Equal(preferredWriteSize, UserSvr::HalFunction(EHalGroupVM, EVMHalGetDataWriteSize, 0, 0));
 
 	ThrashTest(_L("Thrash test: single thread, normal random workload 1"),
 			   1, ETrue, EWorkloadNormalRandom1, (2 * gMaxCacheSize) / 3, 2 * gMaxCacheSize, 0);
@@ -853,6 +896,7 @@
 	if (actions & EActionBenchmarks)
 		{	
 		test.Next(_L("Benchmarking page replacement"));
+		TestDistributions();
 		BenchmarkReplacement();
 		}
 
--- a/kerneltest/e32test/device/t_usbapi.cpp	Tue May 11 17:28:22 2010 +0300
+++ b/kerneltest/e32test/device/t_usbapi.cpp	Tue May 25 14:09:55 2010 +0300
@@ -1849,6 +1849,29 @@
 	{
 	test.Start(_L("Test Endpoint Stall Status"));
 
+#ifdef BSW_USB_DRC
+	// The MACRO comes from ncp adaptation to indicate that otg is built in.
+	// Newly added code for defect ou1cimx1#267421. When otg is built in and the device is not 
+	// in peripheral role, the ncp adaptation will return a dummy endpoint for the stall operation.
+	// The solution is to check if the device is in peripheral mode, if not, skip the stall
+	// operation. A problem is now we can't find a good solution to check the current role of the device.
+	// For the test environement, it's ok to use the USB state to confirm and from the test result,
+	// it works fine. Later when we find accurate method, we will change the confirmation logic.
+	TInt ret = KErrNone;
+
+	TUsbcDeviceState devstate = EUsbcDeviceStateUndefined;
+	ret = gPort.DeviceStatus(devstate);
+	test(ret == KErrNone);
+
+	if( EUsbcDeviceStateUndefined==devstate )
+		{
+		test.Printf( _L("Device not connected, state EUsbcDeviceStateUndefined.\n")  );
+		test.Printf( _L("Skipping endpoint stall status tests.\n") );
+		test.End();
+		return;
+		}
+#endif
+
 	if (!SupportsEndpointStall())
 		{
 		test.Printf(_L("*** Not supported - skipping endpoint stall status tests\n"));
--- a/kerneltest/e32test/dma/d_dma.cpp	Tue May 11 17:28:22 2010 +0300
+++ b/kerneltest/e32test/dma/d_dma.cpp	Tue May 25 14:09:55 2010 +0300
@@ -159,7 +159,6 @@
 #endif
 
 
-#ifndef DMA_APIV2
 static TInt FragmentCount(DDmaRequest* aRequest)
 	{
 	TInt count = 0;
@@ -167,7 +166,6 @@
 		count++;
 	return count;
 	}
-#endif
 
 
 //////////////////////////////////////////////////////////////////////////////
@@ -390,11 +388,7 @@
 		{
 		TInt reqIdx = (TInt)a1;
 		__ASSERT_DEBUG(0 <= reqIdx && reqIdx < KMaxRequests, Kern::PanicCurrentThread(KClientPanicCat, __LINE__));
-#ifdef DMA_APIV2
-		return iRequests[reqIdx]->FragmentCount();
-#else
 		return FragmentCount(iRequests[reqIdx]);
-#endif
 		}
 	case RTestDma::EMissInterrupts:
 		return iChannel->MissNextInterrupts((TInt)a1);
--- a/kerneltest/e32test/dmav2/cap_reqs.h	Tue May 11 17:28:22 2010 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,130 +0,0 @@
-/*
-* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
-* All rights reserved.
-* This component and the accompanying materials are made available
-* under the terms of "Eclipse Public License v1.0"
-* which accompanies this distribution, and is available
-* at the URL "http://www.eclipse.org/legal/epl-v10.html".
-*
-* Initial Contributors:
-* Nokia Corporation - initial contribution.
-*
-* Contributors:
-*
-* Description: Contains TDmaCapability and associated definitions.
-* These are used by the DMA tests in test_cases.cpp to express dependancies
-* on various DMA controller/channel capabilities
-*
-*/
-#ifndef __CAP_REQS_H__
-#define __CAP_REQS_H__
-
-#include <e32std.h>
-
-/**
-The various types of requirement on a
-value that can be specified by a TDmaCapability
-*/
-enum TCapsReqType
-		{
-		EEqual, EGTE /* >= */, ELTE /* <= */, EBitsSet, EBitsClear
-		};
-
-/**
-Enumerates all the various DMA channel capabilities
-*/
-enum TCapsReq
-		{
-		ENone,
-		EChannelPriorities,
-		EChannelPauseAndResume,
-		EAddrAlignedToElementSize,
-		E1DAddressing,
-		E2DAddressing,
-		ESynchronizationTypes,
-		EBurstTransactions,
-		EDescriptorInterrupt,
-		EFrameInterrupt,
-		ELinkedListPausedInterrupt,
-		EEndiannessConversion,
-		EGraphicsOps,
-		ERepeatingTransfers,
-		EChannelLinking,
-		EHwDescriptors,
-		ESrcDstAsymmetry,
-		EAsymHwDescriptors,
-		EBalancedAsymSegments,
-		EAsymCompletionInterrupt,
-		EAsymDescriptorInterrupt,
-		EAsymFrameInterrupt,
-		EPilVersion,
-		};
-
-enum TResult {ERun=0, ESkip=1, EFail=2}; //The ordering of these should not be changed
-
-struct SDmacCaps;
-struct TDmacTestCaps;
-
-/**
-Represents a requirement for some DMA capability
-to be either present or not present, less than, equal to, or
-greater than some value, or to have certain bits in a mask
-set or unset.
-*/
-struct TDmaCapability
-	{
-	TDmaCapability()
-		:iCapsReq(ENone), iCapsReqType(EEqual), iValue(ETrue), iFail(EFalse)
-		{}
-
-	TDmaCapability(TCapsReq aReq, TCapsReqType aReqType, TUint aValue, TBool aFail)
-		:iCapsReq(aReq), iCapsReqType(aReqType), iValue(aValue), iFail(aFail)
-		{}
-
-	static void SelfTest();
-
-	/**
-	Compares the requirements held in the struct
-	against those described in aChannelCaps and makes a decision
-	as to whether this test case should be run, skipped, or failed.
-	*/
-	TResult CompareToDmaCaps(const SDmacCaps& aChannelCaps) const;
-	TResult CompareToDmaCaps(const TDmacTestCaps& aChannelCaps) const;
-
-private:
-	TBool RequirementSatisfied(const SDmacCaps& aChannelCaps) const;
-	TBool RequirementSatisfied(const TDmacTestCaps& aChannelCaps) const;
-
-	TBool TestValue(TUint aValue) const;
-
-public:
-	TCapsReq		iCapsReq;
-	TCapsReqType	iCapsReqType;
-	TUint			iValue;
-	// if HW capability is not available:-
-	// 	ETrue - Fail the test
-	//	EFalse - Skip the test
-	TBool			iFail;
-	};
-
-//A set of DMA capability requirements
-const TDmaCapability none(ENone, EEqual, 0, ETrue);
-
-const TDmaCapability pauseRequired(EChannelPauseAndResume, EEqual, ETrue, ETrue);
-const TDmaCapability pauseRequired_skip(EChannelPauseAndResume, EEqual, ETrue, EFalse);
-const TDmaCapability pauseNotWanted(EChannelPauseAndResume, EEqual, EFalse, ETrue);
-
-const TDmaCapability hwDesNotWanted(EHwDescriptors, EEqual, EFalse, ETrue);
-const TDmaCapability hwDesNotWanted_skip(EHwDescriptors, EEqual, EFalse, EFalse);
-const TDmaCapability hwDesWanted(EHwDescriptors, EEqual, ETrue, ETrue);
-const TDmaCapability hwDesWanted_skip(EHwDescriptors, EEqual, ETrue, EFalse);
-
-const TDmaCapability cap_2DRequired(E2DAddressing, EEqual, ETrue, EFalse);
-
-const TDmaCapability capEqualV1(EPilVersion, EEqual, 1, EFalse);
-const TDmaCapability capEqualV2(EPilVersion, EEqual, 2, EFalse);
-const TDmaCapability capEqualV2Fatal(EPilVersion, EEqual, 2, ETrue);
-
-const TDmaCapability capAboveV1(EPilVersion, EGTE, 2, EFalse);
-const TDmaCapability capBelowV2(EPilVersion, ELTE, 1, EFalse);
-#endif // #ifdef __CAP_REQS_H__
--- a/kerneltest/e32test/dmav2/d_dma2.cpp	Tue May 11 17:28:22 2010 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1351 +0,0 @@
-// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
-// All rights reserved.
-// This component and the accompanying materials are made available
-// under the terms of "Eclipse Public License v1.0"
-// which accompanies this distribution, and is available
-// at the URL "http://www.eclipse.org/legal/epl-v10.html".
-//
-// Initial Contributors:
-// Nokia Corporation - initial contribution.
-//
-// Contributors:
-//
-// Description:
-// Test driver for DMA V2 framework
-//
-//
-
-#include <kernel/kern_priv.h>
-#include <drivers/dma.h>
-#include "d_dma2.h"
-
-_LIT(KClientPanicCat, "D_DMA2");
-_LIT(KDFCThreadName,"D_DMA_DFC_THREAD");
-_LIT(KIsrCbDfcThreadName,"D_DMA_IsrCb_thread");
-const TInt KDFCThreadPriority=26;
-
-class TStopwatch
-	{
-public:
-	TStopwatch()
-		:iStart(0), iStop(0)
-		{}
-
-	void Start()
-		{iStart = NKern::FastCounter();}
-
-	void Stop()
-		{
-		iStop = NKern::FastCounter();
-
-		__KTRACE_OPT(KDMA, Kern::Printf(">TStopwatch::Stop FastCounter ticks: iStart=0x%lx iStop=0x%lx", iStart, iStop));
-		}
-
-	TUint64 ReadMicroSecs() const
-		{
-#ifndef __SMP__
-		TUint64 diff = 0;
-		if(iStart > iStop)
-			{
-			diff = (KMaxTUint64 - iStart) + iStop;
-			}
-		else
-			{
-			diff = iStop - iStart;
-			}
-		return FastCountToMicroSecs(diff);
-#else
-		//TODO On SMP it is possible for the value returned from
-		//NKern::FastCounter to depend on the current CPU (ie.
-		//NaviEngine)
-		//
-		//One solution would be to tie DFC's and ISR's to the same
-		//core as the client, but this would reduce the usefulness of
-		//SMP testing.
-		return 0;
-#endif
-		}
-private:
-
-	TUint64 FastCountToMicroSecs(TUint64 aCount) const
-		{
-		const TUint64 countsPerS = NKern::FastCounterFrequency();
-
-		TUint64 timeuS = (aCount*1000000)/countsPerS;
-		__KTRACE_OPT(KDMA, Kern::Printf(">TStopwatch::FastCountToMicroSecs FastCounter ticks: aCount=0x%lx countsPerS=0x%lx time=0x%lx", aCount, countsPerS, timeuS));
-		return timeuS;
-		}
-
-	TUint64 iStart;
-	TUint64 iStop;
-	};
-
-//////////////////////////////////////////////////////////////////////////////
-
-class DClientDmaRequest;
-/**
-Driver channel. Only accessible by a single client thread
-*/
-class DDmaTestSession : public DLogicalChannelBase
-	{
-public:
-	DDmaTestSession();
-	virtual ~DDmaTestSession();
-protected:
-	// from DLogicalChannelBase
-	virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
-	virtual TInt Request(TInt aFunction, TAny* a1, TAny* a2);
-	virtual TInt RequestUserHandle(DThread* aThread, TOwnerType aType);
-private:
-	TInt DoGetInfo(TAny* aInfo);
-
-	TInt OpenDmaChannel(TUint aPslCookie, TUint& aDriverCookie);
-	TInt CloseDmaChannelByCookie(TUint aDriverCookie);
-	TInt PauseDmaChannelByCookie(TUint aDriverCookie);
-	TInt ResumeDmaChannelByCookie(TUint aDriverCookie);
-	TInt GetChannelCapsByCookie(TUint aDriverCookie, SDmacCaps& aChannelCaps);
-	TInt GetChannelCapsByCookie(TUint aDriverCookie, TDmacTestCaps& aChannelCaps);
-	TInt CancelAllByCookie(TUint aDriverCookie);
-	TInt IsrRedoRequestByCookie(TUint aDriverCookie,TUint32 aSrcAddr,TUint32 aDstAddr,TInt aTransferCount,TUint32 aPslRequestInfo,TBool aIsrCb);
-	TInt IsQueueEmptyByCookie(TUint aDriverCookie, TBool& aQueueEmpty);		
-	TInt ChannelIsOpenedByCookie(TUint aDriverCookie, TBool& aChannelOpen);		
-	void CloseDmaChannelByIndex(TInt aIndex);
-	void CancelAllByIndex(TInt aIndex);
-	TInt PauseDmaChannelByIndex(TInt aIndex);
-	TInt ResumeDmaChannelByIndex(TInt aIndex);		
-	TInt IsrRedoRequestByIndex(TInt aIndex,TUint32 aSrcAddr,TUint32 aDstAddr,TInt aTransferCount,TUint32 aPslRequestInfo,TBool aIsrCb);
-	TInt CreateSharedChunk();
-	TUint OpenSharedChunkHandle();
-
-	/**
-	Creates a new kernel-side DMA request object, associated with a previously
-	opened channel
-
-	@param aChannelCookie - A channel cookie as returned by OpenDmaChannel
-	@param aRequestCookie - On success will be a cookie by which the dma request can be referred to
-	@param aNewCallback - If true, then a new style DMA callback will be used
-	*/
-	TInt CreateDmaRequest(TUint aChannelCookie, TUint& aRequestCookie, TBool aNewCallback = EFalse, TInt aMaxFragmentSizeBytes=0);
-
-	//TODO what happens if a client closes a channel that
-	//it still has dma requests associated with?
-	
-	/**
-	Destroys a previously created dma request object
-	*/
-	TInt DestroyDmaRequestByCookie(TUint aRequestCookie);
-
-	void DestroyDmaRequestByIndex(TInt aIndex);
-
-
-	TInt CookieToChannelIndex(TUint aDriverCookie) const;
-	TInt CookieToRequestIndex(TUint aRequestCookie) const;
-
-	void FixupTransferArgs(TDmaTransferArgs& aTransferArgs) const;
-	TInt FragmentRequest(TUint aRequestCookie, const TDmaTransferArgs& aTransferArgs, TBool aLegacy=ETrue);
-
-	TInt QueueRequest(TUint aRequestCookie, TRequestStatus* aStatus, TCallbackRecord* aRecord, TUint64* aDurationMicroSecs);
-	DClientDmaRequest* RequestFromCookie(TUint aRequestCookie) const;
-	TInt RequestFragmentCount(TUint aRequestCookie);
-
-	TDmaV2TestInfo ConvertTestInfo(const TDmaTestInfo& aOldInfo) const;
-private:
-	DThread* iClient;
-	TDynamicDfcQue* iDfcQ;
-	TDynamicDfcQue* iIsrCallbackDfcQ; // Will be used by requests which complete with an ISR callback
-	static const TInt KMaxChunkSize = 8 * KMega;
-	TLinAddr iChunkBase;
-	DChunk* iChunk;
-
-	RPointerArray<TDmaChannel> iChannels;
-	RPointerArray<DClientDmaRequest> iClientDmaReqs;
-	};
-
-
-/**
-Allows a TClientRequest to be associated with a DDmaRequest
-*/
-class DClientDmaRequest : public DDmaRequest
-	{
-public:
-	static DClientDmaRequest* Construct(DThread* aClient, TDfcQue* const aDfcQ, TDmaChannel& aChannel, TBool aNewStyle=EFalse, TInt aMaxTransferSize=0);
-	~DClientDmaRequest();
-
-	TInt Queue(TRequestStatus* aRequestStatus, TCallbackRecord* aRecord, TUint64* aDurationMicroSecs);
-	void AddRequeArgs(const TIsrRequeArgsSet& aRequeArgSet);
-
-	TUint64 GetDuration()
-		{return iStopwatch.ReadMicroSecs();}
-
-protected:
-	TInt Create();
-	/** Construct with old style callback */
-	DClientDmaRequest(DThread* aClient, TDfcQue* const aDfcQ, TDmaChannel& aChannel, TInt aMaxTransferSize);
-
-	/** Construct with new style callback */
-	DClientDmaRequest(DThread* aClient, TDfcQue* const aDfcQ, TDmaChannel& aChannel, TBool aNewStyle, TInt aMaxTransferSize);
-
-private:
-	static void CallbackOldStyle(TResult aResult, TAny* aRequest);
-	static void Callback(TUint, TDmaResult, TAny*, SDmaDesHdr*);
-	static void CompleteCallback(TAny* aRequest);
-
-	void DoCallback(TUint, TDmaResult);
-	TBool RedoRequest();
-
-	//!< Used to return a TCallbackRecord and transfer time
-	TClientDataRequest2<TCallbackRecord, TUint64>* iClientDataRequest;
-
-	DThread* const iClient;
-	TDfcQue* const iDfcQ; //!< Use the DDmaTestSession's dfc queue
-	TDfc iDfc;
-
-	TStopwatch iStopwatch;
-	TIsrRequeArgsSet iIsrRequeArgSet;
-	};
-
-DClientDmaRequest* DClientDmaRequest::Construct(DThread* aClient, TDfcQue* const aDfcQ, TDmaChannel& aChannel, TBool aNewStyle, TInt aMaxTransferSize)
-	{
-	DClientDmaRequest* dmaRequest = NULL;
-	if(aNewStyle)
-		{
-#ifdef DMA_APIV2
-		dmaRequest = new DClientDmaRequest(aClient, aDfcQ, aChannel, aNewStyle, aMaxTransferSize);
-#else
-		TEST_FAULT; // if a new style dma request was requested it should have been caught earlier
-#endif
-		}
-	else
-		{
-		dmaRequest = new DClientDmaRequest(aClient, aDfcQ, aChannel, aMaxTransferSize);
-		}
-
-	if(dmaRequest == NULL)
-		{
-		return dmaRequest;
-		}
-
-	const TInt r = dmaRequest->Create();
-	if(r != KErrNone)
-		{
-		delete dmaRequest;
-		dmaRequest = NULL;
-		}
-	return dmaRequest;
-	}
-
-DClientDmaRequest::DClientDmaRequest(DThread* aClient, TDfcQue* const aDfcQ, TDmaChannel& aChannel, TInt aMaxFragmentSize)
-	:DDmaRequest(aChannel, &CallbackOldStyle, this, aMaxFragmentSize),
-	iClientDataRequest(NULL),
-	iClient(aClient),
-	iDfcQ(aDfcQ),
-	iDfc(CompleteCallback,NULL, iDfcQ, KMaxDfcPriority)
-	{
-	}
-#ifdef DMA_APIV2
-DClientDmaRequest::DClientDmaRequest(DThread* aClient, TDfcQue* const aDfcQ, TDmaChannel& aChannel, TBool /*aNewStyle*/, TInt aMaxFragmentSize)
-	:DDmaRequest(aChannel, &Callback, this, aMaxFragmentSize),
-	iClientDataRequest(NULL),
-	iClient(aClient),
-	iDfcQ(aDfcQ),
-	iDfc(CompleteCallback,NULL, iDfcQ, KMaxDfcPriority)
-	{
-	}
-#endif
-
-TInt DClientDmaRequest::Create()
-	{
-	return Kern::CreateClientDataRequest2(iClientDataRequest);
-	}
-
-DClientDmaRequest::~DClientDmaRequest()
-	{
-	__KTRACE_OPT(KDMA, Kern::Printf(">DClientDmaRequest::~DClientDmaRequest")); 
-	if(iClientDataRequest)
-		{
-		Kern::DestroyClientRequest(iClientDataRequest);
-		}
-	}
-
-/**
-Queue the DClientDmaRequest.
-
-@param aRequestStatus Pointer to the client's request status
-@param aRecord Pointer to the user's TCallbackRecord, may be null
-@return
-   -KErrInUse The client request is in use
-   -KErrNone success
-*/
-TInt DClientDmaRequest::Queue(TRequestStatus* aRequestStatus, TCallbackRecord* aRecord, TUint64* aDurationMicroSecs)
-	{
-	__NK_ASSERT_ALWAYS(aRecord);
-	__NK_ASSERT_ALWAYS(aDurationMicroSecs);
-
-	//erase results from last transfer
-	iClientDataRequest->Data1().Reset();
-	iClientDataRequest->SetDestPtr1(aRecord);
-
-	iClientDataRequest->SetDestPtr2(aDurationMicroSecs);
-
-
-	TInt r = iClientDataRequest->SetStatus(aRequestStatus);
-	if(r != KErrNone)
-		{
-		return r;
-		}
-
-	iStopwatch.Start();
-#ifdef DMA_APIV2
-	r = DDmaRequest::Queue();
-#else
-	// old version of queue did not return an error code
-	DDmaRequest::Queue();
-	r = KErrNone;
-#endif
-
-	return r;
-	}
-
-void DClientDmaRequest::AddRequeArgs(const TIsrRequeArgsSet& aRequeArgSet)
-	{
-	iIsrRequeArgSet = aRequeArgSet;
-	}
-
-/**
-If a transfer complete callback in ISR context s received this will be
-called to redo the request with the first entry in the array
-
-@return ETrue If the redo was successful - indicates that another callback is comming
-*/
-TBool DClientDmaRequest::RedoRequest()
-	{
-	TIsrRequeArgs args = iIsrRequeArgSet.GetArgs();
-	const TInt r = args.Call(iChannel);
-	TCallbackRecord& record = iClientDataRequest->Data1();
-	record.IsrRedoResult(r);
-	return (r == KErrNone);
-	}
-
-
-/**
-Calls TDmaChannel::IsrRedoRequest on aChannel
-with this object's parameters
-*/
-TInt TIsrRequeArgs::Call(TDmaChannel& aChannel)
-	{
-#ifdef DMA_APIV2
-	return aChannel.IsrRedoRequest(iSrcAddr, iDstAddr, iTransferCount, iPslRequestInfo, iIsrCb);
-#else
-	TEST_FAULT;
-	return KErrNotSupported;
-#endif
-	}
-
-/**
-Check that both source and destination of ISR reque args will
-lie within the range specified by aStart and aSize.
-
-@param aStart The linear base address of the region
-@param aSize The size of the region
-*/
-TBool TIsrRequeArgs::CheckRange(TLinAddr aStart, TUint aSize) const
-	{
-	TUint physStart = Epoc::LinearToPhysical(aStart);
-	TEST_ASSERT(physStart != KPhysAddrInvalid);
-
-	TAddrRange chunk(physStart, aSize);
-	TBool sourceOk = (iSrcAddr == KPhysAddrInvalid) ? ETrue : chunk.Contains(SourceRange());
-
-	TBool destOk = (iDstAddr == KPhysAddrInvalid) ? ETrue : chunk.Contains(DestRange());
-
-	return sourceOk && destOk;
-	}
-
-TBool TIsrRequeArgsSet::CheckRange(TLinAddr aAddr, TUint aSize) const
-	{
-	for(TInt i=0; i<iCount; i++)
-		{
-		if(!iRequeArgs[i].CheckRange(aAddr, aSize))
-			return EFalse;
-		}
-	return ETrue;
-	}
-
-/**
-Translate an old style dma callback to a new-style one
-*/
-void DClientDmaRequest::CallbackOldStyle(TResult aResult, TAny* aArg)
-	{
-	__KTRACE_OPT(KDMA, Kern::Printf(">DClientDmaRequest::CallBackOldStyle: TResult result=%d", aResult));
-	TEST_ASSERT(aResult != EBadResult);
-	//translate result code
-	const TDmaResult result = (aResult == EOk) ? EDmaResultOK : EDmaResultError;
-
-	//call the new-style callback
-	Callback(EDmaCallbackRequestCompletion, result, aArg, NULL);
-	}
-
-
-/**
-The new style callback called by the DMA framework
-may be called in either thread or ISR context
-*/
-void DClientDmaRequest::Callback(TUint aCallbackType, TDmaResult aResult, TAny* aArg, SDmaDesHdr* aHdr)
-	{
-	const TInt context = NKern::CurrentContext();
-	__KTRACE_OPT(KDMA, Kern::Printf(">DClientDmaRequest::CallBack: TDmaResult result = %d, NKern::TContext context = %d", aResult, context));
-	
-	DClientDmaRequest& self = *reinterpret_cast<DClientDmaRequest*>(aArg);
-	self.DoCallback(aCallbackType, aResult);
-
-	// decide if callback is complete
-	const TBool transferComplete = aCallbackType & EDmaCallbackRequestCompletion;
-	if(!transferComplete)
-		{
-		return;
-		}
-
-	// If there are reque args then redo this request
-	// another callback would then be expected.
-	// Requests can only be re-queued in ISR context, but we
-	// do not check that here as it is up to the client to get
-	// it right - also, we want to test that the PIL catches this
-	// error
-	if(!self.iIsrRequeArgSet.IsEmpty())
-		{
-		// If redo call was succesful, return and wait for next call back
-		if(self.RedoRequest())
-			return;
-		}
-
-	switch(context)
-		{
-	case NKern::EThread:
-		{
-		CompleteCallback(aArg);
-		break;
-		}
-	case NKern::EInterrupt:
-		{
-		self.iDfc.iPtr = aArg;
-		self.iDfc.Add();
-		break;
-		}
-	case NKern::EIDFC: //fall-through
-	case NKern::EEscaped:
-	default:
-		TEST_FAULT;
-		}
-	}
-
-/**
-Log results of callback. May be called in either thread or ISR context
-*/
-void DClientDmaRequest::DoCallback(TUint aCallbackType, TDmaResult aResult)
-	{
-	iStopwatch.Stop(); //sucessive calls will simply over write the stop time
-
-	// This will always be done whether the client requested a
-	// callback record or not
-	TCallbackRecord& record = iClientDataRequest->Data1();
-	record.ProcessCallback(aCallbackType, aResult);
-	}
-
-/**
-This function may either be called directly or queued as a DFC
-*/
-void DClientDmaRequest::CompleteCallback(TAny* aArg)
-	{
-	__KTRACE_OPT(KDMA, Kern::Printf(">DClientDmaRequest::CompleteCallBack thread %O", &Kern::CurrentThread()));
-	__ASSERT_NOT_ISR;
-
-	DClientDmaRequest& self = *reinterpret_cast<DClientDmaRequest*>(aArg);
-
-	self.iClientDataRequest->Data2() = self.iStopwatch.ReadMicroSecs();
-
-	//Assert that we called SetRequestStatus on this object before
-	//queueing
-	__NK_ASSERT_DEBUG(self.iClientDataRequest->IsReady());
-
-	// This is an inelegant, temporary, solution to the following problem:
-	//
-	// If a dma request completes with an ISR callback the test
-	// framework will queue this function as a DFC which
-	// will then signal the user-side client. As a consequence of
-	// this the user side client may then decide to destroy this
-	// request. However, untill the DMA framework's DFC has run
-	// and called OnDeque() on this request, it is still considered as
-	// queued. Since it is possible that this DFC could run
-	// before the DMA fw's DFC, this request could get destroyed while
-	// it is stil queued, triggering a PIL assertion.
-	//
-	// The real fix is likely be for the PIL to call the callback
-	// twice, but with different arguments, once to annonunce the
-	// ISR and again to announce the dequeue.
-	//
-	// Here we poll and wait for this request to be dequeued. Note,
-	// this DFC is currently run on a separate DFC queue, otherwise
-	// it could get deadlocked. An alternative to polling would be
-	// to use DCondVar, but that would require PIL modification
-
-	if(NKern::CurrentThread() == self.iDfcQ->iThread)
-		{
-		// Only need to poll if we aren't on the channel's DFC queue
-		for(;;)
-			{
-			// once the request has been unqueued it
-			// can only be queued again by the client
-			const TBool queued = __e32_atomic_load_acq32(&self.iQueued);
-			if(!queued)
-				break;
-			__KTRACE_OPT(KDMA, Kern::Printf("Waiting for requeuest to be dequeued"));
-			NKern::Sleep(10);
-			}
-		}
-	else
-		{
-		// If we are on the channel's DFCQ we should be dequeued
-		// already
-		__NK_ASSERT_DEBUG(!__e32_atomic_load_acq32(&self.iQueued));
-		}
-
-	// We can always complete with KErrNone, the actual DMA result is
-	// logged in the TCallbackRecord
-	Kern::QueueRequestComplete(self.iClient, self.iClientDataRequest, KErrNone);
-	}
-
-const TInt DDmaTestSession::KMaxChunkSize;
-
-TInt DDmaTestSession::RequestUserHandle(DThread* aThread, TOwnerType aType)
-	{
-	if (aType!=EOwnerThread || aThread!=iClient)
-		return KErrAccessDenied;
-	return KErrNone;
-	}
-
-DDmaTestSession::DDmaTestSession()
-	: iClient(NULL), iDfcQ(NULL), iIsrCallbackDfcQ(NULL), iChunkBase(0), iChunk(NULL)
-	{}
-
-// called in thread critical section
-TInt DDmaTestSession::DoCreate(TInt /*aUnit*/, const TDesC8* aInfo, const TVersion& /*aVer*/)
-	{
-	__NK_ASSERT_ALWAYS(iDfcQ == NULL);
-	__NK_ASSERT_ALWAYS(iIsrCallbackDfcQ == NULL);
-
-	TInt r = Kern::DynamicDfcQCreate(iDfcQ, KDFCThreadPriority, KDFCThreadName);
-	if (r != KErrNone)
-		return r;
-	NKern::ThreadSetCpuAffinity((NThread*)(iDfcQ->iThread), KCpuAffinityAny);
-
-	r = Kern::DynamicDfcQCreate(iIsrCallbackDfcQ, KDFCThreadPriority, KIsrCbDfcThreadName);
-	if (r != KErrNone)
-		return r;
-	NKern::ThreadSetCpuAffinity((NThread*)(iIsrCallbackDfcQ->iThread), KCpuAffinityAny);
-
-	iClient = &Kern::CurrentThread();
-
-	r = CreateSharedChunk();
-	return r;
-	}
-
-DDmaTestSession::~DDmaTestSession()
-	{
-	//Destroy requests before channels
-	//or we will trigger an assertion
-	while(iClientDmaReqs.Count())
-		{
-		DestroyDmaRequestByIndex(0);
-		}
-	iClientDmaReqs.Close();
-
-	while(iChannels.Count())
-		{
-		CloseDmaChannelByIndex(0);
-		}
-	iChannels.Close();
-
-
-	if (iDfcQ)
-		{
-		iDfcQ->Destroy();
-		}
-
-	if (iIsrCallbackDfcQ)
-		{
-		iIsrCallbackDfcQ->Destroy();
-		}
-
-	if(iChunk)
-		{
-		Kern::ChunkClose(iChunk);
-		iChunk = NULL;
-		}
-	}
-
-TInt DDmaTestSession::Request(TInt aFunction, TAny* a1, TAny* a2)
-	{
-	__NK_ASSERT_DEBUG(&Kern::CurrentThread() == iClient);
-
-	switch (aFunction)
-		{
-	case RDmaSession::EOpenChannel:
-			{
-			TUint pslCookie = (TUint)a1;
-			TUint driverCookie = 0;
-			TInt r = OpenDmaChannel(pslCookie, driverCookie);	
-			umemput32(a2, &driverCookie, sizeof(TAny*));
-			return r;
-			}
-	case RDmaSession::ECloseChannel:
-			{
-			TUint driverCookie = reinterpret_cast<TUint>(a1);
-			TInt r = CloseDmaChannelByCookie(driverCookie);
-			return r;
-			}
-	case RDmaSession::EChannelCaps:
-			{
-			TUint driverCookie = reinterpret_cast<TUint>(a1);
-			TPckgBuf<TDmacTestCaps> capsBuf;
-			TInt r = GetChannelCapsByCookie(driverCookie, capsBuf());
-			Kern::KUDesPut(*reinterpret_cast<TDes8*>(a2), capsBuf);
-			return r;
-			}
-	case RDmaSession::EPauseChannel:
-			{
-			TUint driverCookie = reinterpret_cast<TUint>(a1);
-			TInt r = PauseDmaChannelByCookie(driverCookie);
-			return r;
-			}
-	case RDmaSession::EResumeChannel:
-			{
-			TUint driverCookie = reinterpret_cast<TUint>(a1);
-			TInt r = ResumeDmaChannelByCookie(driverCookie);
-			return r;
-			}
-	case RDmaSession::EFragmentCount:
-			{
-			TUint requestCookie = reinterpret_cast<TUint>(a1);
-			TInt r = RequestFragmentCount(requestCookie);
-			return r;
-			}
-	case RDmaSession::ERequestOpen:
-			{
-			RDmaSession::TRequestCreateArgs createArgs(0, EFalse, 0);
-			TPckg<RDmaSession::TRequestCreateArgs> package(createArgs);
-			Kern::KUDesGet(package, *reinterpret_cast<TDes8*>(a1));
-
-			const TUint channelCookie = createArgs.iChannelCookie;
-			TUint requestCookie = 0;
-
-			TInt r = CreateDmaRequest(channelCookie, requestCookie, createArgs.iNewStyle, createArgs.iMaxFragmentSize);
-
-			umemput32(a2, &requestCookie, sizeof(TAny*));
-			return r;
-			}
-	case RDmaSession::ERequestClose:
-			{
-			const TUint requestCookie = reinterpret_cast<TUint>(a1);
-			return DestroyDmaRequestByCookie(requestCookie);
-			}
-	case RDmaSession::EFragmentLegacy:
-	case RDmaSession::EFragment:
-			{
-			TPckgBuf<RDmaSession::TFragmentArgs> argsBuff;
-			Kern::KUDesGet(argsBuff, *reinterpret_cast<TDes8*>(a1));
-			const TUint requestCookie = argsBuff().iRequestCookie;
-
-			//must remove constness as we actually need to
-			//convert the src and dst offsets to addresses
-			TDmaTransferArgs& transferArgs = const_cast<TDmaTransferArgs&>(argsBuff().iTransferArgs);
-
-			//convert address offsets in to kernel virtual addresses
-			FixupTransferArgs(transferArgs);
-
-			TEST_ASSERT((TAddressParms(transferArgs).CheckRange(iChunkBase, iChunk->Size())));
-
-			TInt r = KErrGeneral;
-
-			TStopwatch clock;
-			clock.Start();
-			switch (aFunction)
-				{
-			case RDmaSession::EFragmentLegacy:
-				r = FragmentRequest(requestCookie, transferArgs, ETrue); break;
-			case RDmaSession::EFragment:
-				r = FragmentRequest(requestCookie, transferArgs, EFalse); break;
-			default:
-				TEST_FAULT;
-				}
-			clock.Stop();
-
-			const TUint64 time = clock.ReadMicroSecs();
-
-			TUint64* const timePtr = argsBuff().iDurationMicroSecs;
-			if(timePtr)
-				{
-				umemput(timePtr, &time, sizeof(time));
-				}
-			return r;
-			}
-	case RDmaSession::EQueueRequest:
-			{
-			TPckgBuf<RDmaSession::TQueueArgs> argsBuff;
-			Kern::KUDesGet(argsBuff, *reinterpret_cast<TDes8*>(a1));
-
-			//this is an Asynchronous request
-			const TUint requestCookie = argsBuff().iRequestCookie;
-			TRequestStatus* requestStatus = argsBuff().iStatus;
-			TCallbackRecord* callbackRec = argsBuff().iCallbackRecord;
-			TUint64* duration = argsBuff().iDurationMicroSecs;
-
-			TInt r = QueueRequest(requestCookie, requestStatus, callbackRec, duration);
-			if(r != KErrNone)
-				{
-				Kern::RequestComplete(requestStatus, r);
-				}
-			return r;
-			}	
-	case RDmaSession::EQueueRequestWithReque:
-			{
-			//TODO can common code with EQueueRequest be extracted?
-			TPckgBuf<RDmaSession::TQueueArgsWithReque> argsBuff;
-			Kern::KUDesGet(argsBuff, *reinterpret_cast<TDes8*>(a1));
-
-			//this is an Asynchronous request
-			const TUint requestCookie = argsBuff().iRequestCookie;
-			TRequestStatus* requestStatus = argsBuff().iStatus;
-			TCallbackRecord* callbackRec = argsBuff().iCallbackRecord;
-			TUint64* duration = argsBuff().iDurationMicroSecs;
-
-			TInt r = KErrNotFound;
-
-			DClientDmaRequest* const request = RequestFromCookie(requestCookie);
-			if(request != NULL)
-				{
-				argsBuff().iRequeSet.Fixup(iChunkBase);
-				//TODO reque args must be substituted in order to
-				//check the range. The original transfer args are not
-				//available when queue is called, they could
-				//however be stored within DClientDmaRequest
-				//TEST_ASSERT((argsBuff().iRequeSet.CheckRange(iChunkBase, iChunk->Size())));
-				request->AddRequeArgs(argsBuff().iRequeSet);
-
-				r = QueueRequest(requestCookie, requestStatus, callbackRec, duration);
-				}
-
-			if(r != KErrNone)
-				{
-				Kern::RequestComplete(requestStatus, r);
-				}
-			return r;
-			}
-	case RDmaSession::EIsrRedoRequest:
-			{
-			TPckgBuf<RDmaSession::TIsrRedoReqArgs> argsBuff;
-			Kern::KUDesGet(argsBuff, *reinterpret_cast<TDes8*>(a1));
-
-			const TUint driverCookie = argsBuff().iDriverCookie;
-			const TUint32 srcAddr = argsBuff().iSrcAddr;
-			const TUint32 dstAddr = argsBuff().iDstAddr;
-			const TInt transferCount = argsBuff().iTransferCount;
-			const TUint32 pslRequestInfo = argsBuff().iPslRequestInfo;
-			const TBool isrCb = argsBuff().iIsrCb;
-
-			TInt r = IsrRedoRequestByCookie(driverCookie,srcAddr,dstAddr,transferCount,pslRequestInfo,isrCb);
-			return r;
-			}
-	case RDmaSession::EIsOpened:
-			{
-			TUint driverCookie = (TUint)a1;
-			TBool channelOpen = EFalse;;
-			TInt r = ChannelIsOpenedByCookie(driverCookie,channelOpen);	
-			umemput32(a2, &channelOpen, sizeof(TAny*));
-			return r;		
-			}
-	case RDmaSession::EIsQueueEmpty:
-			{
-			TUint driverCookie = (TUint)a1;
-			TBool queueEmpty = EFalse;;
-			TInt r = IsQueueEmptyByCookie(driverCookie,queueEmpty);	
-			umemput32(a2, &queueEmpty, sizeof(TAny*));
-			return r;
-			}
-	case RDmaSession::ECancelAllChannel:
-			{
-			TUint driverCookie = reinterpret_cast<TUint>(a1);
-			TInt r = CancelAllByCookie(driverCookie);
-			return r;
-			}
-	case RDmaSession::EOpenSharedChunk:
-			{
-			return OpenSharedChunkHandle();
-			}
-	case RDmaSession::EGetTestInfo:
-			{
-#ifdef DMA_APIV2
-			TPckgC<TDmaV2TestInfo> package(DmaTestInfoV2());
-#else
-			TPckgC<TDmaV2TestInfo> package(ConvertTestInfo(DmaTestInfo()));
-#endif
-			Kern::KUDesPut(*reinterpret_cast<TDes8*>(a1), package);
-			return KErrNone;
-			}
-	default:
-		Kern::PanicCurrentThread(KClientPanicCat, __LINE__);
-		return KErrGeneral;
-		}
-	}
-
-TInt DDmaTestSession::OpenDmaChannel(TUint aPslCookie, TUint& aDriverCookie )
-	{
-	TDmaChannel::SCreateInfo info;
-	info.iCookie = aPslCookie;
-	info.iDfcQ = iDfcQ;
-	info.iDfcPriority = 3;
-	info.iDesCount = 128;
-
-	TDmaChannel* channel = NULL;
-
-	//cs so thread can't be killed between
-	//opening channel and adding to array
-	NKern::ThreadEnterCS();
-	TInt r = TDmaChannel::Open(info, channel);
-	if(KErrNone == r)
-		{
-		__NK_ASSERT_ALWAYS(channel);
-		
-		__KTRACE_OPT(KDMA, Kern::Printf("OpenDmaChannel: channel@ 0x%08x", channel)); 
-
-
-		TInt err = iChannels.Append(channel);
-		if(KErrNone == err)
-			{
-			aDriverCookie = reinterpret_cast<TUint>(channel);
-			}
-		else
-			{
-			channel->Close();
-			r = KErrNoMemory;
-			}
-		}
-	NKern::ThreadLeaveCS();
-
-	return r;
-	}
-
-TInt DDmaTestSession::CookieToChannelIndex(TUint aDriverCookie) const
-	{
-	const TInt r = iChannels.Find(reinterpret_cast<TDmaChannel*>(aDriverCookie));
-
-	if(r < 0)
-		{
-		__KTRACE_OPT(KDMA, Kern::Printf("CookieToChannelIndex: cookie 0x%08x not found!", aDriverCookie)); 
-		}
-	return r;
-	}
-
-TInt DDmaTestSession::CookieToRequestIndex(TUint aRequestCookie) const
-	{
-	const TInt r = iClientDmaReqs.Find(reinterpret_cast<DClientDmaRequest*>(aRequestCookie));
-
-	if(r < 0)
-		{
-		__KTRACE_OPT(KDMA, Kern::Printf("CookieToRequestIndex: cookie 0x%08x not found!", aRequestCookie)); 
-		}
-	return r;
-	}
-
-void DDmaTestSession::CloseDmaChannelByIndex(TInt aIndex)
-	{
-	__KTRACE_OPT(KDMA, Kern::Printf("CloseDmaChannelByIndex: %d", aIndex)); 
-	__NK_ASSERT_DEBUG(aIndex < iChannels.Count()); 
-	// cs so client thread can't be killed between removing channel from
-	// array and closing it.
-	NKern::ThreadEnterCS();
-	TDmaChannel* channel = iChannels[aIndex];
-	iChannels.Remove(aIndex);
-	channel->Close();
-	NKern::ThreadLeaveCS();
-	}
-
-TInt DDmaTestSession::CloseDmaChannelByCookie(TUint aDriverCookie)
-	{
-	__KTRACE_OPT(KDMA, Kern::Printf("CloseDmaChannelByCookie: 0x%08x", aDriverCookie)); 
-	const TInt index = CookieToChannelIndex(aDriverCookie);
-	
-	if(index >= 0)
-		{
-		CloseDmaChannelByIndex(index);
-		return KErrNone;
-		}
-	else
-		{
-		return KErrNotFound;
-		}
-	}
-
-TInt DDmaTestSession::CancelAllByCookie(TUint aDriverCookie)
-	{
-	__KTRACE_OPT(KDMA, Kern::Printf("CancelAllByCookie: 0x%08x", aDriverCookie)); 
-	const TInt index = CookieToChannelIndex(aDriverCookie);
-	
-	if(index >= 0)
-		{
-		CancelAllByIndex(index);
-		return KErrNone;
-		}
-	else
-		{
-		return KErrNotFound;
-		}
-	}
-
-void DDmaTestSession::CancelAllByIndex(TInt aIndex)
-	{
-	__KTRACE_OPT(KDMA, Kern::Printf("CancelAllByIndex: %d", aIndex)); 
-	__NK_ASSERT_DEBUG(aIndex < iChannels.Count()); 
-	
-	TDmaChannel* channel = iChannels[aIndex];
-	iChannels.Remove(aIndex);
-	channel->CancelAll();
-	}
-
-TInt DDmaTestSession::PauseDmaChannelByIndex(TInt aIndex)
-	{
-	__KTRACE_OPT(KDMA, Kern::Printf("PauseDmaChannelByIndex: %d", aIndex)); 
-	__NK_ASSERT_DEBUG(aIndex < iChannels.Count()); 
-
-#ifdef DMA_APIV2
-	TDmaChannel* channel = iChannels[aIndex];
-	return channel->Pause();
-#else
-	return KErrNotSupported;
-#endif	
-	}
-
-TInt DDmaTestSession::PauseDmaChannelByCookie(TUint aDriverCookie)
-	{
-	__KTRACE_OPT(KDMA, Kern::Printf("PauseDmaChannelByCookie: 0x%08x", aDriverCookie)); 
-	const TInt index = CookieToChannelIndex(aDriverCookie);
-	
-	if(index >= 0)
-		{
-		TInt r = PauseDmaChannelByIndex(index);
-		return r;
-		}
-	else
-		{
-		return KErrNotFound;
-		}
-	}
-
-TInt DDmaTestSession::ResumeDmaChannelByIndex(TInt aIndex)
-	{
-	__KTRACE_OPT(KDMA, Kern::Printf("ResumeDmaChannelByIndex: %d", aIndex)); 
-	__NK_ASSERT_DEBUG(aIndex < iChannels.Count()); 
-
-#ifdef DMA_APIV2
-	TDmaChannel* channel = iChannels[aIndex];
-	return channel->Resume();
-#else
-	return KErrNotSupported;
-#endif
-	}
-
-TInt DDmaTestSession::ResumeDmaChannelByCookie(TUint aDriverCookie)
-	{
-	__KTRACE_OPT(KDMA, Kern::Printf("ResumeDmaChannelByCookie: 0x%08x", aDriverCookie)); 
-	const TInt index = CookieToChannelIndex(aDriverCookie);
-	
-	if(index >= 0)
-		{
-		TInt r = ResumeDmaChannelByIndex(index);
-		return r;
-		}
-	else
-		{
-		return KErrNotFound;
-		}
-	}
-
-TInt DDmaTestSession::IsrRedoRequestByCookie(TUint aDriverCookie,TUint32 aSrcAddr,TUint32 aDstAddr,TInt aTransferCount,TUint32 aPslRequestInfo,TBool aIsrCb)
-{
-	__KTRACE_OPT(KDMA, Kern::Printf("IsrRedoRequestByCookie: 0x%08x", aDriverCookie)); 
-	const TInt index = CookieToChannelIndex(aDriverCookie);
-	
-	if(index >= 0)
-		{
-		TInt r = IsrRedoRequestByIndex(index,aSrcAddr,aDstAddr,aTransferCount,aPslRequestInfo,aIsrCb);
-		return r;
-		}
-	else
-		{
-		return KErrNotFound;
-		}
-}
-
-TInt DDmaTestSession::IsrRedoRequestByIndex(TInt aIndex,TUint32 aSrcAddr,TUint32 aDstAddr,TInt aTransferCount,TUint32 aPslRequestInfo,TBool aIsrCb)
-	{
-	__KTRACE_OPT(KDMA, Kern::Printf("IsrRedoRequestByIndex: %d", aIndex)); 
-	__NK_ASSERT_DEBUG(aIndex < iChannels.Count()); 
-
-#ifdef DMA_APIV2
-	TDmaChannel* channel = iChannels[aIndex];
-	return channel->IsrRedoRequest(aSrcAddr,aDstAddr,aTransferCount,aPslRequestInfo,aIsrCb);
-#else
-	return KErrNotSupported;
-#endif
-	}
-
-/**
-aChannelCaps will be set to "NULL" values
-*/
-TInt DDmaTestSession::GetChannelCapsByCookie(TUint aDriverCookie, TDmacTestCaps& aChannelCaps)
-	{
-	SDmacCaps caps = {0,}; //initialise with NULL values
-	TInt r = GetChannelCapsByCookie(aDriverCookie, caps);
-
-	if(r == KErrNotSupported)
-		{
-		//If we can not query caps it means
-		//that we are using the v1 driver
-		//we construct a empty TDmacTestCaps
-		//but with an iPILVersion of 1
-		const TDmacTestCaps nullCapsV1(caps, 1);
-		aChannelCaps = nullCapsV1;
-		r = KErrNone;
-		}
-	else if(r == KErrNone)
-		{
-		const TDmacTestCaps capsV2(caps, 2);
-		aChannelCaps = capsV2;
-		}
-
-	return r;
-	}
-
-/**
-Will return the capabilities of the DMA channel.
-Querying SDmacCaps is not possible on V1 of the DMA framework.
-In that case an error of KErrNotSupported will be returned
-*/
-TInt DDmaTestSession::GetChannelCapsByCookie(TUint aDriverCookie, SDmacCaps& aChannelCaps)
-	{
-	__KTRACE_OPT(KDMA, Kern::Printf("GetChannelCapsByCookie: 0x%08x", aDriverCookie)); 
-	const TInt index = CookieToChannelIndex(aDriverCookie);
-	if(index >= 0)
-		{
-#ifdef DMA_APIV2
-		aChannelCaps = iChannels[index]->DmacCaps();
-		return KErrNone;
-#else
-		return KErrNotSupported;
-#endif
-		}
-	else
-		{
-		return KErrNotFound;
-		}
-	}
-
-TInt DDmaTestSession::IsQueueEmptyByCookie(TUint aDriverCookie, TBool& aQueueEmpty)
-	{
-	__KTRACE_OPT(KDMA, Kern::Printf("IsQueueEmptyByCookie: 0x%08x", aDriverCookie)); 
-	const TInt index = CookieToChannelIndex(aDriverCookie);
-	
-	if(index >= 0)
-		{
-		aQueueEmpty=iChannels[index]->IsQueueEmpty();
-		return KErrNone;
-		}
-	else
-		{
-		return KErrNotFound;
-		}
-	}
-
-TInt DDmaTestSession::ChannelIsOpenedByCookie(TUint aDriverCookie, TBool& aChannelOpen)
-	{
-	__KTRACE_OPT(KDMA, Kern::Printf("ChannelIsOpenedByCookie: 0x%08x", aDriverCookie)); 
-	const TInt index = CookieToChannelIndex(aDriverCookie);
-	
-	if(index >= 0)
-		{
-		aChannelOpen=iChannels[index]->IsOpened();
-		return KErrNone;
-		}
-	else
-		{
-		return KErrNotFound;
-		}
-	}
-
-TInt DDmaTestSession::CreateDmaRequest(TUint aChannelCookie, TUint& aRequestCookie, TBool aNewCallback, TInt aMaxFragmentSizeBytes)
-	{
-#ifndef DMA_APIV2
-	if(aNewCallback)
-		return KErrNotSupported;
-#endif
-
-	TInt channelIndex = CookieToChannelIndex(aChannelCookie);
-	if(channelIndex < 0)
-		return channelIndex;
-
-	NKern::ThreadEnterCS();
-	DClientDmaRequest* request = DClientDmaRequest::Construct(iClient, iIsrCallbackDfcQ, *iChannels[channelIndex], aNewCallback, aMaxFragmentSizeBytes);
-	if(request == NULL)
-		{
-		NKern::ThreadLeaveCS();
-		return KErrNoMemory;
-		}
-
-	TInt r = iClientDmaReqs.Append(request);
-	if(r == KErrNone)
-		{
-		aRequestCookie = reinterpret_cast<TUint>(request);
-		}
-	else
-		{
-		delete request;
-		}
-	NKern::ThreadLeaveCS();
-	
-	return r;
-	}
-
-TInt DDmaTestSession::DestroyDmaRequestByCookie(TUint aRequestCookie)
-	{
-	TInt requestIndex = CookieToRequestIndex(aRequestCookie);
-	if(requestIndex < 0)
-		return requestIndex;
-
-	DestroyDmaRequestByIndex(requestIndex);
-
-	return KErrNone;
-	}
-
-void DDmaTestSession::DestroyDmaRequestByIndex(TInt aIndex)
-	{
-	__KTRACE_OPT(KDMA, Kern::Printf("DestroyDmaRequestByIndex: %d", aIndex)); 
-	__NK_ASSERT_DEBUG(aIndex < iClientDmaReqs.Count()); 
-	NKern::ThreadEnterCS();
-
-	DClientDmaRequest* request = iClientDmaReqs[aIndex];
-	iClientDmaReqs.Remove(aIndex);
-	delete request;
-
-	NKern::ThreadLeaveCS();
-	}
-
-TInt DDmaTestSession::CreateSharedChunk()
-	{
-    // Enter critical section so we can't die and leak the objects we are creating
-    // I.e. the TChunkCleanup and DChunk (Shared Chunk)
-    NKern::ThreadEnterCS();
-
-    // Create the chunk
-    TChunkCreateInfo info;
-    info.iType         = TChunkCreateInfo::ESharedKernelSingle;
-    info.iMaxSize      = KMaxChunkSize;
-    info.iMapAttr      = EMapAttrFullyBlocking | EMapAttrUserRw;
-    info.iOwnsMemory   = ETrue;
-    info.iDestroyedDfc = NULL;
-
-    DChunk* chunk;
-	TUint32 mapAttr;
-    TInt r = Kern::ChunkCreate(info, chunk, iChunkBase, mapAttr);
-    if(r!=KErrNone)
-        {
-        NKern::ThreadLeaveCS();
-        return r;
-        }
-
-    // Map our device's memory into the chunk (at offset 0)
-	TUint32 physicalAddr;
-	r = Kern::ChunkCommitContiguous(chunk,0,KMaxChunkSize, physicalAddr);
-    if(r!=KErrNone)
-        {
-        // Commit failed so tidy-up...
-        Kern::ChunkClose(chunk);
-        }
-    else
-        {
-        iChunk = chunk;
-        }
-
-    // Can leave critical section now that we have saved pointers to created objects
-    NKern::ThreadLeaveCS();
-
-    return r;
-	}
-
-TUint DDmaTestSession::OpenSharedChunkHandle()
-	{
-	NKern::ThreadEnterCS();
-	const TInt r = Kern::MakeHandleAndOpen(NULL, iChunk);
-	NKern::ThreadLeaveCS();
-	return r;
-	}
-
-void DDmaTestSession::FixupTransferArgs(TDmaTransferArgs& aTransferArgs) const
-	{
-	aTransferArgs.iSrcConfig.iAddr += iChunkBase;
-	aTransferArgs.iDstConfig.iAddr += iChunkBase;
-	}
-
-#ifndef DMA_APIV2
-static TInt FragmentCount(DDmaRequest* aRequest)
-	{
-	TInt count = 0;
-	for (SDmaDesHdr* pH = aRequest->iFirstHdr; pH != NULL; pH = pH->iNext)
-		count++;
-	return count;
-	}
-#endif
-
-TInt DDmaTestSession::RequestFragmentCount(TUint aRequestCookie)
-	{
-	TInt requestIndex = CookieToRequestIndex(aRequestCookie);
-	if(requestIndex < 0)
-		return requestIndex;
-#ifdef DMA_APIV2
-	TInt r = iClientDmaReqs[requestIndex]->FragmentCount();
-#else
-	TInt r = FragmentCount(iClientDmaReqs[requestIndex]);
-#endif
-
-	return r;
-	}
-
-TInt DDmaTestSession::FragmentRequest(TUint aRequestCookie, const TDmaTransferArgs& aTransferArgs, TBool aLegacy)
-	{
-	__KTRACE_OPT(KDMA, Kern::Printf(">FragmentRequest: cookie=0x%08x, legacy=%d", aRequestCookie, aLegacy)); 
-	TInt requestIndex = CookieToRequestIndex(aRequestCookie);
-	if(requestIndex < 0)
-		return requestIndex;
-
-	TInt r = KErrNotSupported;
-	if(aLegacy)
-		{
-		// TODO we can extract the required info from the struct to
-		// set flags
-		TUint flags = KDmaMemSrc | KDmaIncSrc | KDmaMemDest | KDmaIncDest;
-
-		const TUint src = aTransferArgs.iSrcConfig.iAddr;
-		const TUint dst = aTransferArgs.iDstConfig.iAddr;
-		r = iClientDmaReqs[requestIndex]->Fragment(src, dst, aTransferArgs.iTransferCount, flags, NULL);
-		}
-	else
-		{
-#ifdef DMA_APIV2
-		r = iClientDmaReqs[requestIndex]->Fragment(aTransferArgs);
-#else
-		r = KErrNotSupported;
-#endif
-		}
-	return r;
-	}
-
-/**
-Queue the request refered to by aRequestCookie
-
-@param aRequestCookie Client identifier for the DDmaRequest
-@param aStatus Pointer to the client's TRequestStatus
-@param aRecord Pointer to the client's TCallbackRecord
-@return
-   - KErrNotFound - aRequestCookie was invalid
-   - KErrNone - Success
-*/
-TInt DDmaTestSession::QueueRequest(TUint aRequestCookie, TRequestStatus* aStatus, TCallbackRecord* aRecord, TUint64* aDurationMicroSecs)
-	{
-	__KTRACE_OPT(KDMA, Kern::Printf(">QueueRequest: 0x%08x", aRequestCookie)); 
-
-	DClientDmaRequest* request = RequestFromCookie(aRequestCookie);
-	if(request == NULL)
-		return KErrNotFound;
-
-	return request->Queue(aStatus, aRecord, aDurationMicroSecs);
-	}
-
-DClientDmaRequest* DDmaTestSession::RequestFromCookie(TUint aRequestCookie) const
-	{
-	TInt requestIndex = CookieToRequestIndex(aRequestCookie);
-	if(requestIndex < 0)
-		return NULL;
-
-	return (iClientDmaReqs[requestIndex]);
-	}
-
-TDmaV2TestInfo DDmaTestSession::ConvertTestInfo(const TDmaTestInfo& aOldInfo) const
-	{
-	TDmaV2TestInfo newInfo;
-	newInfo.iMaxTransferSize = aOldInfo.iMaxTransferSize;
-	newInfo.iMemAlignMask = aOldInfo.iMemAlignMask;
-	newInfo.iMemMemPslInfo = aOldInfo.iMemMemPslInfo;
-
-	newInfo.iMaxSbChannels = aOldInfo.iMaxSbChannels;
-	for(TInt i=0; i<aOldInfo.iMaxSbChannels; i++)
-		newInfo.iSbChannels[i] = aOldInfo.iSbChannels[i];
-
-	newInfo.iMaxDbChannels = aOldInfo.iMaxDbChannels;
-	for(TInt i=0; i<aOldInfo.iMaxDbChannels; i++)
-		newInfo.iDbChannels[i] = aOldInfo.iDbChannels[i];
-
-	newInfo.iMaxSgChannels = aOldInfo.iMaxSgChannels;
-	for(TInt i=0; i<aOldInfo.iMaxSgChannels; i++)
-		newInfo.iSgChannels[i] = aOldInfo.iSgChannels[i];
-
-	//TODO will want to add initialisation for Asym channels
-	//when these are available
-
-	return newInfo;
-	}
-//////////////////////////////////////////////////////////////////////////////
-
-class DDmaTestFactory : public DLogicalDevice
-	{
-public:
-	DDmaTestFactory();
-	// from DLogicalDevice
-	virtual ~DDmaTestFactory()
-		{
-		__KTRACE_OPT(KDMA, Kern::Printf(">DDmaTestFactory::~DDmaTestFactory"));
-		}
-	virtual TInt Install();
-	virtual void GetCaps(TDes8& aDes) const;
-	virtual TInt Create(DLogicalChannelBase*& aChannel);
-	};
-
-
-DDmaTestFactory::DDmaTestFactory()
-    {
-    iVersion = TestDmaLddVersion();
-    iParseMask = KDeviceAllowUnit;							// no info, no PDD
-    // iUnitsMask = 0;										// Only one thing
-    }
-
-
-TInt DDmaTestFactory::Create(DLogicalChannelBase*& aChannel)
-    {
-	aChannel=new DDmaTestSession;
-	return aChannel ? KErrNone : KErrNoMemory;
-    }
-
-
-TInt DDmaTestFactory::Install()
-    {
-    return SetName(&KTestDmaLddName);
-    }
-
-
-void DDmaTestFactory::GetCaps(TDes8& /*aDes*/) const
-    {
-    }
-
-//////////////////////////////////////////////////////////////////////////////
-
-DECLARE_STANDARD_LDD()
-	{
-    return new DDmaTestFactory;
-	}
--- a/kerneltest/e32test/dmav2/d_dma2.h	Tue May 11 17:28:22 2010 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,572 +0,0 @@
-// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
-// All rights reserved.
-// This component and the accompanying materials are made available
-// under the terms of "Eclipse Public License v1.0"
-// which accompanies this distribution, and is available
-// at the URL "http://www.eclipse.org/legal/epl-v10.html".
-//
-// Initial Contributors:
-// Nokia Corporation - initial contribution.
-//
-// Contributors:
-//
-// Description:
-// e32test\dmav2\d_dma2.h
-// User-side API for LDD used to test DMAv2 framework.
-// 
-//
-
-#ifndef __D_DMA2_H__
-#define __D_DMA2_H__
-
-#include <e32cmn.h>
-#include <drivers/dmadefs.h>
-
-
-#define ARRAY_LENGTH(ARRAY) sizeof(ARRAY)/sizeof(ARRAY[0])
-
-#ifdef __KERNEL_MODE__
-	#include <nkern.h>
-	#include <kernel.h>
-	#define TEST_FAULT FAULT();
-	#define PRINT(N) Kern::Printf("%s = 0x%08x (%d)", #N, (N), (N))
-#else
-	#include <e32std.h>
-	#include <e32debug.h>
-	#define TEST_FAULT RDebug::Printf("Assertion failure in %s, %d", __FILE__, __LINE__); User::Invariant()
-	#define PRINT(N) RDebug::Printf("%s = 0x%08x (%d)", #N, (N), (N))
-#endif
-
-#define TEST_ASSERT(C) if(!(C)) {TEST_FAULT;}
-
-const TUint KPhysAddrInvalidUser=0xFFFFFFFFu; // KPhysAddrInvalid is not defined on the user side
-#ifdef __KERNEL_MODE__
-//if this fails then KPhysAddrInvalidUser must be updated to match
-//KPhysAddrInvalid
-__ASSERT_COMPILE(KPhysAddrInvalidUser == KPhysAddrInvalid);
-#endif
-
-
-_LIT(KTestDmaLddName, "TestDmaV2");
-
-inline TVersion TestDmaLddVersion() { return TVersion(1, 0, 1); }
-
-TInt Log2(TInt aNum);
-
-/**
-Indicates the number of each type of call back received
-and their context
-
-TODO as yet, it does not indicate the context of each callback, only
-the final one
-*/
-const TInt KNumberOfCallbacks = 12;
-
-class TCallbackRecord
-	{
-public:
-	enum TCbContext
-		{ EInvalid, EThread, EIsr };
-
-	TCallbackRecord(
-			TCbContext aContext = EThread,
-			TInt aReq = 0,
-			TInt aReqSrc = 0,
-			TInt aReqDst = 0,
-
-			TInt aDes = 0,
-			TInt aDesSrc = 0,
-			TInt aDesDst = 0,
-
-			TInt aFrame = 0,
-			TInt aFrameSrc = 0,
-			TInt aFrameDst = 0,
-
-			TInt aPause = 0,
-			TInt aPauseSrc = 0,
-			TInt aPauseDst = 0,
-			TDmaResult aResult = EDmaResultOK
-		);
-
-	static TCallbackRecord Empty();
-
-	void Reset();
-
-	/**
-	Allows 2 callback records to be compared
-	*/
-	TBool operator == (const TCallbackRecord aOther) const;
-	void Print() const;
-
-	/**
-	Get the number of callbacks for callback aCbType
-	*/
-	TInt GetCount(TDmaCallbackType aCbType) const;
-
-	void SetCount(TDmaCallbackType aCbType, TInt aCount);
-
-	/**
-	Set the result (expected or actual) from
-	TDmaChannel::IsrRedoRequest
-	 */
-	inline TCallbackRecord& IsrRedoResult(TInt aResult) {iIsrRedoRequestResult = aResult; return *this;}
-
-	/**
-	Reports the context in which the callback occurred.
-	*/
-	inline TCbContext GetContext()
-		{return iContext;}
-
-	/**
-	Updates data based on callback mask aCallbackMask
-	@param aCallbackMask Bitmask of callback events @see TDmaCallbackType
-	@oaram aResult The result reported by the current callback
-	*/
-	void ProcessCallback(TUint aCallbackMask, TDmaResult aResultaContext);
-
-	static void SelfTest();
-
-	// The below methods are setters, which may be chained together
-	// ie. The Named Parameter Idiom
-	// @see http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.18
-	TCallbackRecord& Context(TCbContext aContext) {iContext = aContext; return *this;}
-
-private:
-	TInt BitToIndex(TDmaCallbackType aCbType) const;
-
-	TCbContext CurrentContext() const;
-
-	TInt iCallbackLog[KNumberOfCallbacks];
-
-	TDmaResult iResult;
-	TCbContext iContext;
-	/** Result of the most recent redo request call */
-	TInt iIsrRedoRequestResult;
-	};
-
-/**
-Extends SDmacCaps to contain the DMA PIL
-version being used
-*/
-struct TDmacTestCaps : public SDmacCaps
-	{
-	TDmacTestCaps();
-	TDmacTestCaps(const SDmacCaps& aDmacCaps, TInt aVersion = 2);
-
-	TInt iPILVersion;
-	};
-
-
-class TDmaChannel;
-
-struct TAddrRange
-	{
-	TAddrRange(TUint aStart, TUint aLength);
-	inline TUint End() const {return (iStart + iLength -1);}
-	inline TUint Start() const {return iStart;}
-
-	inline TBool Contains(TUint aValue) const {return Rng(iStart, aValue, End());}
-	TBool Contains(TAddrRange aRange) const;
-
-	TBool Overlaps(const TAddrRange& aRange) const;
-	static void SelfTest();
-
-private:
-	TUint iStart;
-	TUint iLength;
-	};
-
-
-struct TAddressParms
-	{
-	TAddressParms(TUint32 aSrcAddr=0, TUint32 aDstAddr=0, TUint aTransferCount=0)
-		:iSrcAddr(aSrcAddr), iDstAddr(aDstAddr), iTransferCount(aTransferCount)
-		{}
-
-	TAddressParms(const TDmaTransferArgs& aArgs)
-		:iSrcAddr(aArgs.iSrcConfig.iAddr),
-		iDstAddr(aArgs.iDstConfig.iAddr),
-		iTransferCount(aArgs.iTransferCount)
-		{}
-
-	/**
-	If any src, dst, or transfer count are zero, substitute the values from
-	aTransferArgs in their place
-	*/
-	void Substitute(const TDmaTransferArgs& aTransferArgs);
-
-	/**
-	When recieved by the test driver, src and dst
-	addresses will be offsets from the dma test session's
-	chunk base. They must be converted to absolute, *physical* addresses
-	*/
-	void Fixup(TLinAddr aChunkBase);
-
-	/**
-	Check that both the src and destination lie within the area
-	defined by aStart and aSize
-	*/
-	TBool CheckRange(TLinAddr aStart, TUint aSize);
-
-	TAddrRange SourceRange() const;
-	TAddrRange DestRange() const;
-
-	TBool Overlaps(const TAddrRange aRange) const;
-	TBool Overlaps(const TAddressParms aParm) const;
-
-	TBool operator==(const TAddressParms& aOther) const;
-
-	static void SelfTest();
-
-	TUint32 iSrcAddr;
-	TUint32 iDstAddr;
-	TUint iTransferCount;
-	};
-
-// These functions can be used for accessing TDmaTransferArgs in
-// terms of TAddressParms. (TAddressParms would be a natural base
-// class for TDmaTransferArgs but changing the production code
-// is undesirable)
-TAddressParms GetAddrParms(const TDmaTransferArgs&);
-void SetAddrParms(TDmaTransferArgs&, const TAddressParms&);
-
-/**
-This struct holds the arguments which can be used with TDmaChannel::IsrRedoRequest
-*/
-struct TIsrRequeArgs : public TAddressParms
-	{
-	TIsrRequeArgs(TUint32 aSrcAddr=KPhysAddrInvalidUser, TUint32 aDstAddr=KPhysAddrInvalidUser,
-			TUint aTransferCount=0, TUint32 aPslRequestInfo=0,
-			TBool aIsrCb=ETrue)
-		: TAddressParms(aSrcAddr, aDstAddr, aTransferCount), iPslRequestInfo(aPslRequestInfo), iIsrCb(aIsrCb)
-		{}
-
-
-	TInt Call(TDmaChannel& aChannel);
-
-	TBool CheckRange(TLinAddr aStart, TUint aSize) const;
-
-	TUint32 iPslRequestInfo;
-	TBool iIsrCb;
-	};
-class CISrRequeTest;
-/**
-A collection of TIsrRequeArgs
-*/
-struct TIsrRequeArgsSet
-	{
-
-	friend class CIsrRequeTest; //TODO see line 394 t_dma2.cpp
-	TIsrRequeArgsSet(TIsrRequeArgs* aRequeueArgs=NULL, TInt aCount =0)
-		:iCount(aCount), iIndex(0)
-		{
-		TEST_ASSERT(iCount <= MaxCount);
-		for(TInt i=0; i<iCount; i++)
-			{
-			iRequeArgs[i] = aRequeueArgs[i];
-			}
-
-		}
-
-	TBool IsEmpty() const
-		{return iCount == 0;}
-
-	TIsrRequeArgs GetArgs();
-
-	void Substitute(const TDmaTransferArgs& aTransferArgs);
-	void Fixup(TLinAddr aChunkBase);
-	TBool CheckRange(TLinAddr aAddr, TUint aSize) const;
-
-private:
-	enum {MaxCount=6};
-	TInt iCount;
-	TInt iIndex;
-	TIsrRequeArgs iRequeArgs[MaxCount];
-	};
-
-class DDmaTestSession;
-class RDmaSession : public RBusLogicalChannel
-	{
-	friend class DDmaTestSession;
-public:
-#ifndef __KERNEL_MODE__
-	TInt ChannelIsQueueEmpty(TUint aDriverCookie,TBool& aQueueEmpty)
-		{
-		return DoControl(EIsQueueEmpty, reinterpret_cast<TAny*>(aDriverCookie),	&aQueueEmpty);		
-		}
-
-	TInt ChannelIsOpened(TUint aDriverCookie,TBool &aChannelOpen)
-		{
-		return DoControl(EIsOpened, reinterpret_cast<TAny*>(aDriverCookie), &aChannelOpen);		
-		}
-
-	TInt ChannelIsrRedoRequest(TUint aDriverCookie,TUint32 aSrcAddr,TUint32 aDstAddr,TInt aTransferCount,TUint32 aPslRequestInfo,TBool aIsrCb)
-		{
-		TIsrRedoReqArgs args(aDriverCookie,aSrcAddr,aDstAddr,aTransferCount,aPslRequestInfo,aIsrCb);
-		TPckgC<TIsrRedoReqArgs> package(args);
-		return DoControl(EIsrRedoRequest,&package);
-		}
-
-	TInt ChannelCancelAll(TUint aDriverCookie)
-		{	
-		return DoControl(ECancelAllChannel, reinterpret_cast<TAny*>(aDriverCookie));
-		}
-
-	TInt ChannelOpen(TUint aPslCookie,  TUint& aDriverCookie)
-		{
-		return DoControl(EOpenChannel, reinterpret_cast<TAny*>(aPslCookie), &aDriverCookie);
-		}
-
-	TInt ChannelClose(TUint aDriverCookie)
-		{	
-		return DoControl(ECloseChannel, reinterpret_cast<TAny*>(aDriverCookie));
-		}
-
-	TInt ChannelPause(TUint aDriverCookie)
-		{	
-		return DoControl(EPauseChannel, reinterpret_cast<TAny*>(aDriverCookie));
-		}
-	
-	TInt ChannelResume(TUint aDriverCookie)
-		{	
-		return DoControl(EResumeChannel, reinterpret_cast<TAny*>(aDriverCookie));
-		}
-
-	TInt ChannelCaps(TUint aDriverCookie, SDmacCaps& aChannelCaps)
-		{
-		TDmacTestCaps caps;
-		TInt r = ChannelCaps(aDriverCookie, caps);
-		aChannelCaps = caps;
-		return r;
-		}
-
-	TInt ChannelCaps(TUint aDriverCookie, TDmacTestCaps& aChannelCaps)
-		{
-		TPckg<TDmacTestCaps> package(aChannelCaps);
-		return DoControl(EChannelCaps, reinterpret_cast<TAny*>(aDriverCookie), &package);
-		}
-	
-	TInt Open()
-		{// TO DO: Add Info , this  class is just to test the opening of channels
-		//TPckgBuf<TOpenInfo> infoBuf;
-		//infoBuf().iWhat = TOpenInfo::EOpen;
-		//infoBuf().U.iOpen.iId = aId;
-		//infoBuf().U.iOpen.iDesCount = aDesCount;
-		//infoBuf().U.iOpen.iMaxTransferSize = aMaxTransferSize;
-		return DoCreate(KTestDmaLddName,TestDmaLddVersion(), 0, NULL, NULL, EOwnerThread);
-		}
-
-	//TODO rename this (append "old")
-	TInt RequestCreate(TUint aChannelCookie, TUint& aRequestCookie, TUint aMaxTransferSize=0)
-		{	
-		return DoRequestCreate(aChannelCookie, EFalse, aMaxTransferSize, aRequestCookie);
-		}
-
-	//TODO rename this (get rid of "new"
-	TInt RequestCreateNew(TUint aChannelCookie, TUint& aRequestCookie, TUint aMaxTransferSize=0)
-		{
-		return DoRequestCreate(aChannelCookie, ETrue, aMaxTransferSize, aRequestCookie);
-		}
-
-	TInt RequestDestroy(TUint aRequestCookie)
-		{	
-		return DoControl(ERequestClose, reinterpret_cast<TAny*>(aRequestCookie));
-		}
-
-	TInt RequestFragmentCount(TUint aRequestCookie)
-		{	
-		return DoControl(EFragmentCount, reinterpret_cast<TAny*>(aRequestCookie));
-		}
-
-	/**
-	Will fragment a DMA request using the legacy API
-	*/
-	TInt FragmentRequestOld(TUint aRequestCookie, const TDmaTransferArgs& aTransferArgs, TUint64* aDurationMicroSecs=NULL)
-		{
-		const TFragmentArgs args(aRequestCookie, aTransferArgs, aDurationMicroSecs);
-		TPckgC<TFragmentArgs> package(args);
-		return DoControl(EFragmentLegacy, &package);
-		}
-
-	/**
-	Will fragment a DMA request using the new API
-	*/
-	TInt FragmentRequest(TUint aRequestCookie, const TDmaTransferArgs& aTransferArgs, TUint64* aDurationMicroSecs=NULL)
-		{
-		const TFragmentArgs args(aRequestCookie, aTransferArgs, aDurationMicroSecs);
-		TPckgC<TFragmentArgs> package(args);
-		return DoControl(EFragment, &package);
-		}
-
-	TInt QueueRequest(TUint aRequestCookie, TRequestStatus& aStatus, TCallbackRecord* aRecord = NULL, TUint64* aDurationMicroSecs=NULL)
-		{
-		//These dummy values can accept the writeback from the driver
-		//if the client does not want them.
-		//(TClientDataRequest can not be programmed with a NULL to
-		//indicate that an argument is unwanted)
-		TCallbackRecord dummyRec;
-		TUint64 dummyTime=0;
-
-		TQueueArgs args(aRequestCookie, &aStatus, aRecord ? aRecord : &dummyRec, aDurationMicroSecs ? aDurationMicroSecs : &dummyTime);
-		TPckgC<TQueueArgs> package(args);
-		return DoControl(EQueueRequest, &package);
-		}
-
-	/**
-	Synchronous version of QueueRequest
-	*/
-	TInt QueueRequest(TUint aRequestCookie, TCallbackRecord* aRecord = NULL, TUint64* aDurationMicroSecs=NULL)
-		{
-		TRequestStatus status;
-		TInt r = QueueRequest(aRequestCookie, status, aRecord, aDurationMicroSecs);
-		User::WaitForRequest(status);
-		return r;
-		}
-
-	/**
-	Queue a previously fragmented request.
-	Additional request parameters are included in iRequeueArgs, these will be
-	transferred from ISR context callback using the TDmaChannel::IsrRedoRequest function
-
-	@pre Isr callback for completion must have been requested at request fragmentation time
-	*/
-	TInt QueueRequestWithRequeue(TUint aRequestCookie, TIsrRequeArgs* aRequeueArgs, TInt aCount, TRequestStatus& aStatus, TCallbackRecord* aRecord = NULL, TUint64* aDurationMicroSecs=NULL)
-		{
-		//These dummy values can accept the writeback from the driver
-		//if the client does not want them.
-		//(TClientDataRequest can not be programmed with a NULL to
-		//indicate that an argument is unwanted)
-		TCallbackRecord dummyRec;
-		TUint64 dummyTime=0;
-
-		TQueueArgsWithReque args(aRequeueArgs, aCount, aRequestCookie, &aStatus, aRecord ? aRecord : &dummyRec, aDurationMicroSecs ? aDurationMicroSecs : &dummyTime);
-		TPckgC<TQueueArgsWithReque> package(args);
-		return DoControl(EQueueRequestWithReque, &package);
-		}
-
-	/**
-	Synchronous version of QueueRequestWithRequeue
-	*/
-	TInt QueueRequestWithRequeue(TUint aRequestCookie, TIsrRequeArgs* aRequeueArgs, TInt aCount, TCallbackRecord* aRecord = NULL, TUint64* aDurationMicroSecs=NULL)
-		{
-		TRequestStatus status;
-		TInt r = QueueRequestWithRequeue(aRequestCookie, aRequeueArgs, aCount, status, aRecord, aDurationMicroSecs);
-		User::WaitForRequest(status);
-		return r;
-		}
-
-	TInt OpenSharedChunk(RChunk& aChunk)
-		{
-		TUint chunkHandle = DoControl(EOpenSharedChunk);
-		return aChunk.SetReturnedHandle(chunkHandle);
-		}
-	
-	TInt GetTestInfo(TDmaV2TestInfo& aInfo)
-		{
-		TPckg<TDmaV2TestInfo> package(aInfo);
-		return DoControl(EGetTestInfo, &package);
-		}
-
-	static void SelfTest();
-	
-	static void ApiTest();
-#endif // __KERNEL_MODE__
-
-private:
-
-	TInt DoRequestCreate(TUint aChannelCookie, TBool aNewStyle, TUint aMaxTransferSize, TUint& aRequestCookie)
-		{
-		TRequestCreateArgs args(aChannelCookie, aNewStyle, aMaxTransferSize);
-		TPckgC<TRequestCreateArgs> package(args);
-		return DoControl(ERequestOpen, &package, &aRequestCookie);
-		}
-
-
-	struct TRequestCreateArgs
-		{
-		TRequestCreateArgs(TUint aChannelCookie, TBool aNewStyle, TUint aMaxFragmentSize)
-			:iChannelCookie(aChannelCookie), iNewStyle(aNewStyle), iMaxFragmentSize(aMaxFragmentSize)
-			{}
-
-		TUint iChannelCookie;
-		TBool iNewStyle;
-		TUint iMaxFragmentSize;
-		};
-
-	struct TFragmentArgs
-		{
-		TFragmentArgs()
-			:iRequestCookie(0), iTransferArgs(), iDurationMicroSecs(NULL)
-			{}
-		TFragmentArgs(TUint aRequestCookie, const TDmaTransferArgs& aTransferArgs, TUint64* aDurationMicroSecs = NULL)
-			:iRequestCookie(aRequestCookie), iTransferArgs(aTransferArgs), iDurationMicroSecs(aDurationMicroSecs)
-			{}
-
-		const TUint iRequestCookie;
-		const TDmaTransferArgs iTransferArgs;
-		TUint64* const iDurationMicroSecs;
-		};
-
-	struct TQueueArgs
-		{
-		TQueueArgs(TUint aRequestCookie=0, TRequestStatus* aStatus=NULL, TCallbackRecord* aCallbackRecord=NULL, TUint64* aDurationMicroSecs=NULL)
-			:iRequestCookie(aRequestCookie), iStatus(aStatus), iCallbackRecord(aCallbackRecord), iDurationMicroSecs(aDurationMicroSecs)
-			{}
-		TUint iRequestCookie;
-		TRequestStatus* iStatus;
-		TCallbackRecord* iCallbackRecord;
-		TUint64* iDurationMicroSecs;
-		};
-
-	struct TIsrRedoReqArgs 	
-		{
-		TIsrRedoReqArgs(TUint aDriverCookie=0,TUint32 aSrcAddr=0, TUint32 aDstAddr=0, TInt aTransferCount=0, TUint32 aPslRequestInfo=0,TBool aIsrCb=ETrue)
-			:iDriverCookie(aDriverCookie),iSrcAddr(aSrcAddr),iDstAddr(aDstAddr),iTransferCount(aTransferCount),iPslRequestInfo(aPslRequestInfo),iIsrCb(aIsrCb)
-			{}
-		TUint iDriverCookie;
-		TUint32 iSrcAddr;
-		TUint32 iDstAddr;
-		TInt iTransferCount;
-		TUint32 iPslRequestInfo;
-		TBool iIsrCb;
-		};
-
-	/**
-	This struct is used for queing and including a set of transfers
-	to be setup from ISR context callback
-	*/
-	struct TQueueArgsWithReque : public TQueueArgs
-		{
-		TQueueArgsWithReque(TIsrRequeArgs* aRequeueArgs=NULL, TInt aCount=0,
-				TUint aRequestCookie=0, TRequestStatus* aStatus=NULL, TCallbackRecord* aCallbackRecord=NULL, TUint64* aDurationMicroSecs=NULL)
-			:TQueueArgs(aRequestCookie, aStatus, aCallbackRecord, aDurationMicroSecs), iRequeSet(aRequeueArgs, aCount)
-			{
-			}
-
-		TIsrRequeArgsSet iRequeSet;
-		};
-
-
-	enum TControl
-		{
-		EOpenChannel,
-		ECloseChannel,
-		EPauseChannel,
-		EResumeChannel,
-		EChannelCaps,
-		ERequestOpen,
-		ERequestClose,
-		EOpenSharedChunk,
-		EFragmentLegacy,
-		EFragment,
-		EFragmentCount,
-		EQueueRequest,
-		EGetTestInfo,
-		EIsQueueEmpty,
-		EIsOpened,
-		EIsrRedoRequest,
-		ECancelAllChannel,
-		EQueueRequestWithReque
-		};
-	};
-#endif // __D_DMA2_H__
--- a/kerneltest/e32test/dmav2/d_dma2_cmn.cpp	Tue May 11 17:28:22 2010 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,328 +0,0 @@
-/*
-* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
-* All rights reserved.
-* This component and the accompanying materials are made available
-* under the terms of "Eclipse Public License v1.0"
-* which accompanies this distribution, and is available
-* at the URL "http://www.eclipse.org/legal/epl-v10.html".
-*
-* Initial Contributors:
-* Nokia Corporation - initial contribution.
-*
-* Contributors:
-*
-* Description: Implmentation of DMAv2 test code, common
-* to both user and kernel side
-*
-*/
-#ifdef __KERNEL_MODE__
-#include <platform.h>
-#endif
-
-#include "d_dma2.h"
-
-TInt Log2(TInt aNum)
-	{
-	TInt res = -1;
-	while(aNum)
-		{
-		res++;
-		aNum >>= 1;
-		}
-	return res;
-	}
-
-TCallbackRecord::TCallbackRecord(
-		TCbContext aContext,
-		TInt aReq,
-		TInt aReqSrc,
-		TInt aReqDst,
-		TInt aDes,
-		TInt aDesSrc,
-		TInt aDesDst,
-		TInt aFrame,
-		TInt aFrameSrc,
-		TInt aFrameDst,
-		TInt aPause,
-		TInt aPauseSrc,
-		TInt aPauseDst,
-		TDmaResult aResult
-	)
-	//Default iIsrRedoRequestResult is 1 as this is an invalid error code
-	:iResult(aResult), iContext(aContext), iIsrRedoRequestResult(1)
-	{
-	SetCount(EDmaCallbackRequestCompletion, aReq);
-	SetCount(EDmaCallbackRequestCompletion_Src, aReqSrc);
-	SetCount(EDmaCallbackRequestCompletion_Dst, aReqDst);
-	SetCount(EDmaCallbackDescriptorCompletion, aDes);
-	SetCount(EDmaCallbackDescriptorCompletion_Src, aDesSrc);
-	SetCount(EDmaCallbackDescriptorCompletion_Dst, aDesDst);
-	SetCount(EDmaCallbackFrameCompletion, aFrame);
-	SetCount(EDmaCallbackFrameCompletion_Src, aFrameSrc);
-	SetCount(EDmaCallbackFrameCompletion_Dst, aFrameDst);
-	SetCount(EDmaCallbackLinkedListPaused, aPause);
-	SetCount(EDmaCallbackLinkedListPaused_Src, aPauseSrc);
-	SetCount(EDmaCallbackLinkedListPaused_Dst, aPauseDst);
-	}
-
-TCallbackRecord TCallbackRecord::Empty()
-	{
-	return TCallbackRecord(EInvalid,0,0,0,0,0,0,0,0,0,0,0,0,EDmaResultError);
-	}
-
-void TCallbackRecord::Reset()
-	{
-	new (this) TCallbackRecord();
-	}
-
-TBool TCallbackRecord::operator == (const TCallbackRecord aOther) const
-	{
-	return (memcompare((TUint8*)this, sizeof(*this), (TUint8*)&aOther, sizeof(aOther)) == 0);
-	}
-
-TInt TCallbackRecord::GetCount(TDmaCallbackType aCbType) const
-	{
-	const TInt index = BitToIndex(aCbType);
-	return iCallbackLog[index];
-	}
-
-void TCallbackRecord::SetCount(TDmaCallbackType aCbType, TInt aCount)
-	{
-	const TInt index = BitToIndex(aCbType);
-	iCallbackLog[index] = aCount;
-	}
-
-TInt TCallbackRecord::BitToIndex(TDmaCallbackType aCbType) const
-	{
-	const TInt index = Log2(aCbType);
-	TEST_ASSERT(index >=0 && index < KNumberOfCallbacks);
-
-	return index;
-	}
-
-void TCallbackRecord::ProcessCallback(TUint aCallbackMask, TDmaResult aResult)
-	{
-	// This function may be called several
-	// times and will accumulate the number of each callback
-	// received. However, it will only ever remember the last
-	// result and context value,
-	iResult = aResult;
-	iContext = CurrentContext();
-	TEST_ASSERT(iContext != EInvalid);
-
-	for(TInt i=0; i < KNumberOfCallbacks; i++)
-		{
-		if(aCallbackMask & 1)
-			{
-			iCallbackLog[i]++;
-			}
-		aCallbackMask >>= 1;
-		}
-	// Assert that we have handled all bits
-	// if not then maybe KNumberOfCallbacks is too small
-	// or there is a spurious bit in aCallbackMask
-	TEST_ASSERT(aCallbackMask == 0);
-	}
-
-TCallbackRecord::TCbContext TCallbackRecord::CurrentContext() const
-	{
-#ifdef __KERNEL_MODE__
-	switch(NKern::CurrentContext())
-		{
-	case NKern::EThread:
-		return EThread;
-	case NKern::EInterrupt:
-		return EIsr;
-	case NKern::EIDFC: //fall-through
-	case NKern::EEscaped:
-	default:
-		return EInvalid;
-		}
-#else
-	//for the benefit of user-mode testing
-	return EThread;
-#endif
-	}
-
-void TCallbackRecord::Print() const
-	{
-	PRINT(GetCount(EDmaCallbackRequestCompletion));
-	PRINT(GetCount(EDmaCallbackRequestCompletion_Src));
-	PRINT(GetCount(EDmaCallbackRequestCompletion_Dst));
-	PRINT(GetCount(EDmaCallbackDescriptorCompletion));
-	PRINT(GetCount(EDmaCallbackDescriptorCompletion_Src));
-	PRINT(GetCount(EDmaCallbackDescriptorCompletion_Dst));
-	PRINT(GetCount(EDmaCallbackFrameCompletion));
-	PRINT(GetCount(EDmaCallbackFrameCompletion_Src));
-	PRINT(GetCount(EDmaCallbackFrameCompletion_Dst));
-	PRINT(GetCount(EDmaCallbackLinkedListPaused));
-	PRINT(GetCount(EDmaCallbackLinkedListPaused_Src));
-	PRINT(GetCount(EDmaCallbackLinkedListPaused_Dst));
-	PRINT(iResult);
-	PRINT(iContext);
-	PRINT(iIsrRedoRequestResult);
-	}
-
-TDmacTestCaps::TDmacTestCaps()
-	:iPILVersion(1)
-	{
-	}
-
-TDmacTestCaps::TDmacTestCaps(const SDmacCaps& aDmacCaps, TInt aVersion)
-	:SDmacCaps(aDmacCaps), iPILVersion(aVersion)
-	{}
-
-TAddrRange::TAddrRange(TUint aStart, TUint aLength)
-	:iStart(aStart), iLength(aLength)
-	{
-	TEST_ASSERT(iLength > 0);
-	}
-
-TBool TAddrRange::Contains(TAddrRange aRange) const
-	{
-	return Contains(aRange.Start()) && Contains(aRange.End());
-	}
-
-TBool TAddrRange::Overlaps(const TAddrRange& aRange) const
-	{
-	return (aRange.Contains(iStart) || aRange.Contains(End()) ||
-			Contains(aRange.Start()) || Contains(aRange.End()));
-	}
-/**
-If addresses have been left as KPhysAddrInvalid or the count as 0
-(ie. the default values used for IsrRedoRequest)
-then substitute the values from aTransferArgs.
-*/
-void TAddressParms::Substitute(const TDmaTransferArgs& aTransferArgs)
-	{
-	if(iSrcAddr == KPhysAddrInvalidUser)
-		iSrcAddr = aTransferArgs.iSrcConfig.iAddr;
-
-	if(iDstAddr == KPhysAddrInvalidUser)
-		iDstAddr = aTransferArgs.iDstConfig.iAddr;
-
-	if(iTransferCount == 0)
-		iTransferCount = aTransferArgs.iTransferCount;
-	}
-
-/**
-Addresses are converted into absolute,
-addresses (virtual in user mode, physical in kernel)
-unless they are KPhysAddrInvalid
-*/
-void TAddressParms::Fixup(TLinAddr aChunkBase)
-	{
-	if(iSrcAddr != KPhysAddrInvalidUser)
-		{
-		iSrcAddr += aChunkBase;
-
-#ifdef __KERNEL_MODE__
-		iSrcAddr = Epoc::LinearToPhysical(iSrcAddr);
-		TEST_ASSERT(iSrcAddr != KPhysAddrInvalid);
-#endif
-		}
-#ifndef __KERNEL_MODE__
-	else
-		{
-		// Substitute must be called before
-		// Fixup on user side
-		TEST_FAULT;
-		}
-#endif
-
-	if(iDstAddr != KPhysAddrInvalidUser)
-		{
-		iDstAddr += aChunkBase;
-
-#ifdef __KERNEL_MODE__
-		iDstAddr = Epoc::LinearToPhysical(iDstAddr);
-		TEST_ASSERT(iDstAddr != KPhysAddrInvalid);
-#endif
-		}
-#ifndef __KERNEL_MODE__
-	else
-		{
-		// Substitute must be called before
-		// Fixup on user side
-		TEST_FAULT;
-		}
-#endif
-	}
-
-TBool TAddressParms::CheckRange(TLinAddr aStart, TUint aSize)
-	{
-	TAddrRange chunk(aStart, aSize);
-	return chunk.Contains(SourceRange()) && chunk.Contains(DestRange());
-	}
-
-/**
-@return ETrue if the source or destination range of this object
-overlaps with aRange
-*/
-TBool TAddressParms::Overlaps(const TAddrRange aRange) const
-	{
-	return SourceRange().Overlaps(aRange) || DestRange().Overlaps(aRange);
-	}
-
-/**
-@return ETrue if either the source or dest range of this
-overlap with either of those of aParm
-*/
-TBool TAddressParms::Overlaps(const TAddressParms aParm) const
-	{
-	return Overlaps(aParm.SourceRange()) || Overlaps(aParm.DestRange());
-	}
-
-TBool TAddressParms::operator==(const TAddressParms& aOther) const
-	{
-	return iSrcAddr == aOther.iSrcAddr &&
-		iDstAddr == aOther.iDstAddr &&
-		iTransferCount == aOther.iTransferCount;
-	}
-
-TAddressParms GetAddrParms(const TDmaTransferArgs& aArgs)
-	{
-	return TAddressParms(aArgs);
-	}
-
-TAddrRange TAddressParms::SourceRange() const
-	{
-	return TAddrRange(iSrcAddr, iTransferCount);
-	}
-
-TAddrRange TAddressParms::DestRange() const
-	{
-	return TAddrRange(iDstAddr, iTransferCount);
-	}
-
-void SetAddrParms(TDmaTransferArgs& aTransferArgs, const TAddressParms& aAddrParams)
-	{
-	aTransferArgs.iSrcConfig.iAddr = aAddrParams.iSrcAddr;
-	aTransferArgs.iDstConfig.iAddr = aAddrParams.iDstAddr;
-	aTransferArgs.iTransferCount = aAddrParams.iTransferCount;
-	}
-
-TIsrRequeArgs TIsrRequeArgsSet::GetArgs()
-	{
-	TEST_ASSERT(!IsEmpty());
-	const TIsrRequeArgs args(iRequeArgs[iIndex]);
-	iIndex++;
-	iCount--;
-	return args;
-	}
-
-
-void TIsrRequeArgsSet::Substitute(const TDmaTransferArgs& aTransferArgs)
-	{
-	for(TInt i=0; i<iCount; i++)
-		{
-		iRequeArgs[i].Substitute(aTransferArgs);
-		}
-	}
-void TIsrRequeArgsSet::Fixup(TLinAddr aChunkBase)
-	{
-	for(TInt i=0; i<iCount; i++)
-		{
-		iRequeArgs[i].Fixup(aChunkBase);
-		}
-	}
--- a/kerneltest/e32test/dmav2/dma_api_tests.cpp	Tue May 11 17:28:22 2010 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,188 +0,0 @@
-// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
-// All rights reserved.
-// This component and the accompanying materials are made available
-// under the terms of "Eclipse Public License v1.0"
-// which accompanies this distribution, and is available
-// at the URL "http://www.eclipse.org/legal/epl-v10.html".
-//
-// Initial Contributors:
-// Nokia Corporation - initial contribution.
-//
-// Contributors:
-//
-// Description:
-// e32test\dma\dma_api_tests.cpp
-// 
-// Overview:
-//  This file contains API tests for the new DMA framework
-//
-
-#define __E32TEST_EXTENSION__
-#include "d_dma2.h"
-#include "u32std.h"
-#include "t_dma2.h"
-#include "cap_reqs.h"
-
-#include <e32test.h>
-#include <e32debug.h>
-#include <e32svr.h>
-
-static RTest test(_L("DMA Test Framework API"));
-//----------------------------------------------------------------------------------------------
-//! @SYMTestCaseID      KBASE-DMA-2564
-//! @SYMTestType        CIT
-//! @SYMPREQ            REQ
-//! @SYMTestCaseDesc    This test checks the correct behaviour of Open API in the new DMA framework
-//!
-//! @SYMTestActions     
-//!						1.  Open a DMA channel
-//!						2.	Verify that channel is really open.
-//!
-//! @SYMTestExpectedResults 
-//!						1.  DMA channel opens and KErrNone returned
-//!						2.  Call to ChannelIsOpened() return as ETrue.
-//!
-//! @SYMTestPriority        High
-//! @SYMTestStatus          Implemented
-//----------------------------------------------------------------------------------------------
-void test_open_api()
-{
-	//TO DO : Expose TInt Open(const SCreateInfo& aInfo, TDmaChannel*& aChannel)
-	//TO DO : Implement more test cases
-	test.Start(_L("*** Testing Open() API  ***"));
-
-	test.Next(_L("Open session"));
-	RDmaSession session;
-	TInt r = session.Open();
-	test_KErrNone(r);
-
-	TUint channelCookie_open_api=0;
-	
-	test.Next(_L("Open DMA Channel"));
-	channelCookie_open_api=0;
-	r = session.ChannelOpen(16, channelCookie_open_api);
-	test.Printf(_L("cookie recieved = 0x%08x\n"), channelCookie_open_api);
-	test_KErrNone(r);
-
-	//Check if channel is open
-	// test.Printf(_L("Verify that the specified DMA channel is opened\n"));	
-	// TBool channelOpened;
-	// TBool channelNotOpened = EFalse;
-	// r = session.ChannelIsOpened(channelCookie_open_api,  channelOpened);
-	// test_KErrNone(r);	
- 	// TEST_ASSERT(channelOpened != channelNotOpened)
-	
-	//close channel
-	test.Next(_L("Channel close"));
-	r = session.ChannelClose(channelCookie_open_api);
-	test_KErrNone(r);
-	
-	RTest::CloseHandleAndWaitForDestruction(session);
-	test.End();
-}
-
-//----------------------------------------------------------------------------------------------
-//! @SYMTestCaseID      KBASE-DMA-2568
-//! @SYMTestType        CIT
-//! @SYMPREQ            REQ
-//! @SYMTestCaseDesc    This test checks the correct behaviour of Close API in the new DMA framework
-//!
-//! @SYMTestActions     
-//!						1.  Open a DMA channel
-//!						2.	Open DMA Channel again
-//!						3	Close the DMA channel.
-//!						4	Open DMA channel to verify that the DMA channel closed.
-//!						5.	Open DMA channel again.
-//!						6.	Queue a request on the channel.
-//!						7.	Close DMA channel while request is still queued on it.
-//!
-//! @SYMTestExpectedResults 
-//!						1.  DMA channel opens and KErrNone returned.
-//!						2.	DMA Framework returns KErrInUse as channel is already open.					
-//!						3.	DMA channel closes and KErrNone returned.
-//!						4.	DMA channel opens and KErrNone returned.
-//!						5.	DMA Framework returns KErrInUse as channel is already open.
-//!						6.	DMA request queued and KErrNone returned.
-//!						7.	DMA channel closes and DMA framework flags an error.
-//!							
-//!
-//! @SYMTestPriority        High
-//! @SYMTestStatus          Implemented
-//----------------------------------------------------------------------------------------------
-void test_close_api()
-{
-	test.Start(_L("*** Testing Close() API  ***"));
-	
-	test.Next(_L("Open session"));
-	RDmaSession session;
-	TInt r = session.Open();
-	test_KErrNone(r);
-
-	const TInt size = 64 * KKilo;
-	TUint reqCookieNewStyle_close_api=0;	
-	TUint channelCookie_close_api=0;
-	
-	test.Next(_L("Open a single DMA channel"));
-	r = session.ChannelOpen(16, channelCookie_close_api);
-	test.Printf(_L("cookie recieved = 0x%08x\n"), channelCookie_close_api);
-	test_KErrNone(r);
-
-	// test.Next(_L("Open DMA channel again"));
-	// TUint channelCookie_close_api_1=0;
-	// r = session.ChannelOpen(16, channelCookie_close_api_1);
-	// test.Printf(_L("Verify that DMA channel is already opened\n"));
-	// test_Equal(KErrInUse,r); 
-
-	test.Next(_L("Close the DMA channel"));
-	r = session.ChannelClose(channelCookie_close_api);
-	test_KErrNone(r);
-
-	test.Next(_L("Open DMA channel again"));
-	r = session.ChannelOpen(16, channelCookie_close_api);
-	test.Printf(_L("Verify that DMA channel was closed\n"));
-	test_KErrNone(r); 
-
-	//Fails if a request is created and cancel
-	test.Next(_L("Queue a request on the channel"));
-  	r = session.RequestCreateNew(channelCookie_close_api, reqCookieNewStyle_close_api); //Create Dma request (with new-style callback)
-  	test.Printf(_L("cookie recieved for open channel = 0x%08x\n"), reqCookieNewStyle_close_api);
-  	test_KErrNone(r);
-  
-  	TDmaTransferArgs transferArgs_close_api;
-  	transferArgs_close_api.iSrcConfig.iAddr = 0;
-  	transferArgs_close_api.iDstConfig.iAddr = size;
-  	transferArgs_close_api.iSrcConfig.iFlags = KDmaMemAddr;
-  	transferArgs_close_api.iDstConfig.iFlags = KDmaMemAddr;
-  	transferArgs_close_api.iTransferCount = size;
-  	r = session.FragmentRequest(reqCookieNewStyle_close_api, transferArgs_close_api);
-  	test_KErrNone(r);
-  	
-  	test.Next(_L("Queue DMA Request"));
-  	TCallbackRecord record_close_api;
-  	r = session.QueueRequest(reqCookieNewStyle_close_api, &record_close_api);
-  	test_KErrNone(r);
-	
-	test.Next(_L("Destroy Dma request"));
-	r = session.RequestDestroy(reqCookieNewStyle_close_api);
-	test_KErrNone(r);
-
-	test.Next(_L("Close the DMA channel"));
-	r = session.ChannelClose(channelCookie_close_api);
-	test_KErrNone(r);
-
-	test.End();
-	RTest::CloseHandleAndWaitForDestruction(session);
-}
-
-void RDmaSession::ApiTest()
-	{
-    test_open_api();     // Verify that Open() opens a DMA channel
-    test_close_api();    // Verify that Close() closes a DMA channel
-	}
-
-void ApiTests()
-	{
-	test.Next(_L("Running framework API tests"));
-	RDmaSession::ApiTest();	
-	test.Close();
-	}
--- a/kerneltest/e32test/dmav2/self_test.cpp	Tue May 11 17:28:22 2010 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,665 +0,0 @@
-/*
-* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
-* All rights reserved.
-* This component and the accompanying materials are made available
-* under the terms of "Eclipse Public License v1.0"
-* which accompanies this distribution, and is available
-* at the URL "http://www.eclipse.org/legal/epl-v10.html".
-*
-* Initial Contributors:
-* Nokia Corporation - initial contribution.
-*
-* Contributors:
-*
-* Description:
-* This file contains unit tests for the test framework itself.
-* They should be run if changes have been made to
-* to the user side test framework code ie. anything in the dmav2
-* directory other than the d_* driver code, or test_cases.cpp
-*
-*/
-
-#include "d_dma2.h"
-#include "u32std.h"
-#include "t_dma2.h"
-#include "cap_reqs.h"
-
-#define __E32TEST_EXTENSION__
-#include <e32test.h>
-#include <e32debug.h>
-#include <e32svr.h>
-
-static RTest test(_L("t_dma2 test framework tests"));
-
-void RDmaSession::SelfTest()
-	{
-	test.Start(_L("Simple transfer test"));
-	test.Next(_L("Open session"));
-	RDmaSession session;
-	TInt r = session.Open();
-	test_KErrNone(r);
-
-	test.Next(_L("Get test info"));
-	TDmaV2TestInfo testInfo;
-	r = session.GetTestInfo(testInfo);
-	test_KErrNone(r);
-
-	if(gVerboseOutput)
-	{
-	Print(testInfo);
-	}
-
-	test.Next(_L("Channel open"));
-	TUint channelCookie=0;
-	r = session.ChannelOpen(16, channelCookie);
-	test.Printf(_L("cookie recived = 0x%08x\n"), channelCookie);
-	test_KErrNone(r);
-
-	test.Next(_L("Get Channel caps"));
-	SDmacCaps channelCaps;
-	r = session.ChannelCaps(channelCookie, channelCaps);
-	test_KErrNone(r);
-	if(gVerboseOutput)
-	{
-	PRINT(channelCaps.iChannelPriorities);
-	PRINT(channelCaps.iChannelPauseAndResume);
-	PRINT(channelCaps.iAddrAlignedToElementSize);
-	PRINT(channelCaps.i1DIndexAddressing);
-	PRINT(channelCaps.i2DIndexAddressing);
-	PRINT(channelCaps.iSynchronizationTypes);
-	PRINT(channelCaps.iBurstTransactions);
-	PRINT(channelCaps.iDescriptorInterrupt);
-	PRINT(channelCaps.iFrameInterrupt);
-	PRINT(channelCaps.iLinkedListPausedInterrupt);
-	PRINT(channelCaps.iEndiannessConversion);
-	PRINT(channelCaps.iGraphicsOps);
-	PRINT(channelCaps.iRepeatingTransfers);
-	PRINT(channelCaps.iChannelLinking);
-	PRINT(channelCaps.iHwDescriptors);
-	PRINT(channelCaps.iSrcDstAsymmetry);
-	PRINT(channelCaps.iAsymHwDescriptors);
-	PRINT(channelCaps.iBalancedAsymSegments);
-	PRINT(channelCaps.iAsymCompletionInterrupt);
-	PRINT(channelCaps.iAsymDescriptorInterrupt);
-	PRINT(channelCaps.iAsymFrameInterrupt);
-	PRINT(channelCaps.iReserved[0]);
-	PRINT(channelCaps.iReserved[1]);
-	PRINT(channelCaps.iReserved[2]);
-	PRINT(channelCaps.iReserved[3]);
-	PRINT(channelCaps.iReserved[4]);	
-	}
-
-	test.Next(_L("Get extended Channel caps (TDmacTestCaps)"));
-	TDmacTestCaps extChannelCaps;
-	r = session.ChannelCaps(channelCookie, extChannelCaps);
-	test_KErrNone(r);
-	test.Printf(_L("PIL version = %d\n"), extChannelCaps.iPILVersion);
-
-	const TBool newPil = (extChannelCaps.iPILVersion > 1);
-
-	test.Next(_L("Create Dma request - max fragment size 32K"));
-	TUint reqCookie=0;
-	r = session.RequestCreate(channelCookie, reqCookie, 32 * KKilo);
-	test.Printf(_L("cookie recived = 0x%08x\n"), reqCookie);
-	test_KErrNone(r);
-
-	if(newPil)
-		{
-		test.Next(_L("Create Dma request (with new-style callback)"));
-		TUint reqCookieNewStyle=0;
-		r = session.RequestCreateNew(channelCookie, reqCookieNewStyle);
-		test.Printf(_L("cookie recived = 0x%08x\n"), reqCookieNewStyle );
-		test_KErrNone(r);
-
-		test.Next(_L("Fragment for ISR callback"));
-		const TInt size = 128 * KKilo;
-		TDmaTransferArgs transferArgs(0, size, size, KDmaMemAddr, KDmaSyncAuto, KDmaRequestCallbackFromIsr);
-		r = session.FragmentRequest(reqCookieNewStyle, transferArgs);
-		test_KErrNone(r);
-
-		TIsrRequeArgs reque;
-		test.Next(_L("Queue ISR callback - with default re-queue"));
-		r = session.QueueRequestWithRequeue(reqCookieNewStyle, &reque, 1);
-		test_KErrNone(r);
-
-		test.Next(_L("Destroy new-style Dma request"));
-		r = session.RequestDestroy(reqCookieNewStyle);
-		test_KErrNone(r);
-
-		test.Next(_L("Attempt to destroy request again "));
-		r = session.RequestDestroy(reqCookieNewStyle);
-		test_Equal(KErrNotFound, r);
-		}
-
-	test.Next(_L("Open chunk handle"));
-	RChunk chunk;
-	r = session.OpenSharedChunk(chunk);
-	test_KErrNone(r);
-	if(gVerboseOutput)
-	{
-	test.Printf(_L("chunk base = 0x%08x\n"), chunk.Base());
-	test.Printf(_L("chunk size = %d\n"), chunk.Size());
-	}
-	test(chunk.IsWritable());
-	test(chunk.IsReadable());
-
-	test.Next(_L("Fragment(old style)"));
-	const TInt size = 128 * KKilo;
-	TInt i;
-	for(i = 0; i<10; i++)
-		{
-		TUint64 time = 0;
-		TDmaTransferArgs transferArgs(0, size, size, KDmaMemAddr);
-		r = session.FragmentRequestOld(reqCookie, transferArgs, &time);
-		test_KErrNone(r);
-		if(gVerboseOutput)
-			{
-			test.Printf(_L("%lu us\n"), time);
-			}
-	}
-
-	test.Next(_L("Queue"));
-	TRequestStatus status;
-
-	for(i = 0; i<10; i++)
-		{
-		TUint64 time = 0;
-		r = session.QueueRequest(reqCookie, status, 0, &time);
-		User::WaitForRequest(status);
-		test_KErrNone(r);
-		if(gVerboseOutput)
-			{
-			test.Printf(_L("%lu us\n"), time);
-			}
-		}
-
-	if(newPil)
-		{
-		test.Next(_L("Fragment(new style)"));
-		TDmaTransferArgs transferArgs;
-		transferArgs.iSrcConfig.iAddr = 0;
-		transferArgs.iDstConfig.iAddr = size;
-		transferArgs.iSrcConfig.iFlags = KDmaMemAddr;
-		transferArgs.iDstConfig.iFlags = KDmaMemAddr;
-		transferArgs.iTransferCount = size;
-
-		for(i = 0; i<10; i++)
-			{
-			TUint64 time = 0;
-			r = session.FragmentRequest(reqCookie, transferArgs, &time);
-			test_KErrNone(r);
-			if(gVerboseOutput)
-				{
-				test.Printf(_L("%lu us\n"), time);
-				}
-			}
-		}
-
-	test.Next(_L("Queue"));
-	TCallbackRecord record;
-	r = session.QueueRequest(reqCookie, &record);
-	test_KErrNone(r);
-
-	test.Next(_L("check TCallbackRecord record"));
-	if(gVerboseOutput)
-	{
-	record.Print();
-	}
-	const TCallbackRecord expected(TCallbackRecord::EThread, 1);
-	if(!(record == expected))
-		{
-		test.Printf(_L("TCallbackRecords did not match"));
-		if(gVerboseOutput)
-			{
-			test.Printf(_L("expected:"));
-			expected.Print();
-			}
-		TEST_FAULT;
-		}
-
-	test.Next(_L("Destroy Dma request"));
-	r = session.RequestDestroy(reqCookie);
-	test_KErrNone(r);
-
-	test.Next(_L("Close chunk handle"));
-	chunk.Close();
-
-	test.Next(_L("Channel close"));
-	r = session.ChannelClose(channelCookie);
-	test_KErrNone(r);
-
-	test.Next(_L("Channel close (same again)"));
-	r = session.ChannelClose(channelCookie);
-	test_Equal(KErrNotFound, r);
-
-	test.Next(_L("Close session"));
-	RTest::CloseHandleAndWaitForDestruction(session);
-
-	test.End();
-
-	}
-
-const SDmacCaps KTestCapSet =
-	{6,										// TInt iChannelPriorities;
-	 EFalse,								// TBool iChannelPauseAndResume;
-	 ETrue,									// TBool iAddrAlignedToElementSize;
-	 EFalse,								// TBool i1DIndexAddressing;
-	 EFalse,								// TBool i2DIndexAddressing;
-	 KDmaSyncSizeElement | KDmaSyncSizeFrame |
-	 KDmaSyncSizeBlock,					   // TUint iSynchronizationTypes;
-	 KDmaBurstSize4 | KDmaBurstSize8,	   // TUint iBurstTransactions;
-	 EFalse,							   // TBool iDescriptorInterrupt;
-	 EFalse,							   // TBool iFrameInterrupt;
-	 EFalse,							   // TBool iLinkedListPausedInterrupt;
-	 EFalse,							   // TBool iEndiannessConversion;
-	 0,									   // TUint iGraphicsOps;
-	 ETrue,								   // TBool iRepeatingTransfers;
-	 EFalse,							   // TBool iChannelLinking;
-	 ETrue,								   // TBool iHwDescriptors;
-	 EFalse,							   // TBool iSrcDstAsymmetry;
-	 EFalse,							   // TBool iAsymHwDescriptors;
-	 EFalse,							   // TBool iBalancedAsymSegments;
-	 EFalse,							   // TBool iAsymCompletionInterrupt;
-	 EFalse,							   // TBool iAsymDescriptorInterrupt;
-	 EFalse,							   // TBool iAsymFrameInterrupt;
-	 {0, 0, 0, 0, 0}					   // TUint32 iReserved[5];
-	};
-
-const TDmacTestCaps KDmacTestCapsV1(KTestCapSet, 1);
-const TDmacTestCaps KDmacTestCapsV2(KTestCapSet, 2);
-
-void TDmaCapability::SelfTest()
-	{
-	test.Start(_L("Unit test_Value of TDmaCapability::CompareToDmaCaps\n"));
-
-	{
-	test.Next(_L("ENone\n"));
-	TResult t = none.CompareToDmaCaps(KTestCapSet);
-	test_Value(t, t == ERun);
-	}
-
-	{
-	test.Next(_L("EChannelPauseAndResume - wanted\n"));
-	TResult t = pauseRequired.CompareToDmaCaps(KTestCapSet);
-	test_Value(t, t == EFail);
-	}
-	{
-	test.Next(_L("EChannelPauseAndResume - wanted - Allow skip\n"));
-	TResult t = pauseRequired_skip.CompareToDmaCaps(KTestCapSet);
-	test_Value(t, t == ESkip);
-	}
-	{
-	test.Next(_L("EChannelPauseAndResume - not wanted\n"));
-	TResult t = pauseNotWanted.CompareToDmaCaps(KTestCapSet);
-	test_Value(t, t == ERun);
-	}
-
-	{
-	test.Next(_L("EHwDescriptors - not wanted\n"));
-	TResult t = hwDesNotWanted.CompareToDmaCaps(KTestCapSet);
-	test_Value(t, t == EFail);
-	}
-
-	{
-	test.Next(_L("EHwDescriptors - not wanted - Allow skip\n"));
-	TResult t = hwDesNotWanted_skip.CompareToDmaCaps(KTestCapSet);
-	test_Value(t, t == ESkip);
-	}
-
-	{
-	test.Next(_L("EHwDescriptors - wanted\n"));
-	TResult t = hwDesWanted.CompareToDmaCaps(KTestCapSet);
-	test_Value(t, t == ERun);
-	}
-
-
-//TODO use this macro for the above tests
-
-// Note: The construction of the test description message
-// is horribly confusing. The _L macro will make the
-// *first* string token wide, but not the next two.
-// Therefore these must be made wide or compilier
-// will complain about concatination of narrow and wide string
-// literals
-#define CAP_TEST(CAP, CAPSET, EXPCT)\
-	{\
-	test.Next(_L(#CAP L" against " L ## #CAPSET));\
-	TResult t = (CAP).CompareToDmaCaps(CAPSET);\
-	test_Equal(EXPCT, t);\
-	}
-
-
-	CAP_TEST(capEqualV1, KDmacTestCapsV1, ERun);
-	CAP_TEST(capEqualV2, KDmacTestCapsV2, ERun);
-	CAP_TEST(capEqualV1, KDmacTestCapsV2, ESkip);
-	CAP_TEST(capEqualV2, KDmacTestCapsV1, ESkip);
-	CAP_TEST(capEqualV2Fatal, KDmacTestCapsV1, EFail);
-
-	CAP_TEST(capAboveV1, KDmacTestCapsV2, ERun);
-	CAP_TEST(capBelowV2, KDmacTestCapsV1, ERun);
-	CAP_TEST(capAboveV1, KDmacTestCapsV1, ESkip);
-	CAP_TEST(capBelowV2, KDmacTestCapsV2, ESkip);
-
-	test.End();
-	}
-
-void TTestCase::SelfTest()
-	{
-	//TODO should use macros for these tests
-	test.Start(_L("Unit test of TTestCase::TestCaseValid\n"));
-
-	TTestCase testCase(NULL, EFalse, pauseRequired, hwDesNotWanted);
-	test.Next(_L("pauseRequired, hwDesNotWanted\n"));
-	TResult t = testCase.TestCaseValid(KTestCapSet);
-	test_Value(t, t == EFail);
-
-	test.Next(_L("pauseRequired_skip, hwDesNotWanted\n"));
-	testCase.iChannelCaps[0] = pauseRequired_skip;
-	t = testCase.TestCaseValid(KTestCapSet);
-	test_Value(t, t == EFail);
-
-	test.Next(_L("pauseRequired_skip, hwDesNotWanted_skip\n"));
-	testCase.iChannelCaps[1] = hwDesNotWanted_skip;
-	t = testCase.TestCaseValid(KTestCapSet);
-	test_Value(t, t == ESkip);
-
-	test.Next(_L("pauseNotWanted, hwDesNotWanted_skip\n"));
-	testCase.iChannelCaps[0] = pauseNotWanted;
-	t = testCase.TestCaseValid(KTestCapSet);
-	test_Value(t, t == ESkip);
-
-	test.Next(_L("pauseNotWanted, hwDesWanted\n"));
-	testCase.iChannelCaps[1] = hwDesWanted;
-	t = testCase.TestCaseValid(KTestCapSet);
-	test_Value(t, t == ERun);
-
-	test.Next(_L("pauseNotWanted\n"));
-	testCase.iChannelCaps[1] = none;
-	t = testCase.TestCaseValid(KTestCapSet);
-	test_Value(t, t == ERun);
-
-	test.Next(_L("pauseNotWanted + V1 PIL required\n"));
-	testCase.iChannelCaps[1] = capAboveV1;
-	test.Next(_L("Against KDmacTestCapsV1"));
-	t = testCase.TestCaseValid(KDmacTestCapsV1);
-	test_Equal(ESkip, t);
-	test.Next(_L("Against KDmacTestCapsV2"));
-	t = testCase.TestCaseValid(KDmacTestCapsV2);
-	test_Equal(ERun, t);
-
-	test.Next(_L("pauseNotWanted + >V1 PIL required\n"));
-	testCase.iChannelCaps[1] = capBelowV2;
-	test.Next(_L("Against KDmacTestCapsV1"));
-	t = testCase.TestCaseValid(KDmacTestCapsV1);
-	test_Equal(ERun, t);
-	test.Next(_L("Against KDmacTestCapsV2"));
-	t = testCase.TestCaseValid(KDmacTestCapsV2);
-	test_Equal(ESkip, t);
-
-	test.End();
-	test.Close();
-	}
-
-
-void TTransferIter::SelfTest()
-	{
-	test.Start(_L("No skip"));
-
-	const TUint8 src[9] = {
-			1 ,2, 3,
-			4, 5, 6,
-			7, 8, 9
-	};
-
-	const TUint32 addr = (TUint32)src;
-	const TUint elementSize = 1;
-	const TUint elementSkip = 0;
-	const TUint elementsPerFrame = 3;
-	const TUint frameSkip = 0;
-	const TUint framesPerTransfer = 3;
-	TDmaTransferConfig cfg(addr, elementSize, elementsPerFrame, framesPerTransfer,
-			elementSkip, frameSkip, KDmaMemAddr
-			);
-
-	TTransferIter iter(cfg, 0);
-	TTransferIter end;
-	TInt i;
-	for(i = 0; i<9; i++, ++iter)
-		{
-		test_Equal(src[i],*iter);
-		};
-
-
-	test.Next(_L("90 degree rotation"));
-	// Now imagine that we wanted to perform a rotation
-	// as we write, so that we wrote out the following
-
-	const TUint8 expected[9] = {
-		7, 4, 1,
-		8, 5, 2,
-		9, 6, 3
-	};
-
-	TUint8 dst[9] = {0};
-	TDmaTransferConfig dst_cfg(cfg);
-	dst_cfg.iAddr = (TUint32)&dst[2];
-	dst_cfg.iElementSkip = 2;
-	dst_cfg.iFrameSkip = -8;
-
-	TTransferIter dst_iter(dst_cfg, 0);
-	for(i=0; dst_iter != end; i++, ++dst_iter)
-		{
-		TEST_ASSERT(i<9);
-		*dst_iter=src[i];
-		};
-
-	for(i=0; i<9; i++)
-		{
-		test_Equal(expected[i],dst[i]);
-		}
-	}
-
-void TCallbackRecord::SelfTest()
-	{
-	test.Start(_L("SeltTest of TCallbackRecord"));
-
-	test.Next(_L("create default TCallbackRecord record, record2"));
-	TCallbackRecord record;
-	const TCallbackRecord record2;
-	if(gVerboseOutput)
-	{
-	test.Next(_L("Print record"));
-	record.Print();
-	}
-
-	test.Next(_L("test (record == record2)"));
-	if(!(record == record2))
-		{
-		if(gVerboseOutput)
-			{
-			record2.Print();
-			}
-		TEST_FAULT;
-		}
-
-	//A series of callback masks
-	//Note these combinations do not necessarily represent
-	//possible callback combinations
-	TUint callbacks[]  =
-		{
-		EDmaCallbackDescriptorCompletion,
-		EDmaCallbackDescriptorCompletion,
-		EDmaCallbackDescriptorCompletion,
-		EDmaCallbackDescriptorCompletion,
-		EDmaCallbackFrameCompletion_Src,
-		EDmaCallbackFrameCompletion_Dst,
-		EDmaCallbackDescriptorCompletion_Src | EDmaCallbackDescriptorCompletion_Dst,
-		EDmaCallbackDescriptorCompletion_Src | EDmaCallbackFrameCompletion_Src | EDmaCallbackLinkedListPaused_Dst,
-		EDmaCallbackRequestCompletion | EDmaCallbackRequestCompletion_Src,
-		EDmaCallbackDescriptorCompletion_Dst
-		};
-	test.Next(_L("Feed a series of callback masks in to record"));
-	const TInt length = ARRAY_LENGTH(callbacks);
-	for(TInt i = 0; i < length; i++)
-		{
-		record.ProcessCallback(callbacks[i], EDmaResultOK);
-		}
-	
-	if(gVerboseOutput)
-	{
-	test.Next(_L("Print record"));
-	record.Print();
-	}
-
-	test.Next(_L("test GetCount"));
-	test_Equal(1, record.GetCount(EDmaCallbackRequestCompletion));
-	test_Equal(1, record.GetCount(EDmaCallbackRequestCompletion_Src));
-	test_Equal(0, record.GetCount(EDmaCallbackRequestCompletion_Dst));
-	test_Equal(4, record.GetCount(EDmaCallbackDescriptorCompletion));
-	test_Equal(2, record.GetCount(EDmaCallbackDescriptorCompletion_Src));
-	test_Equal(2, record.GetCount(EDmaCallbackDescriptorCompletion_Dst));
-	test_Equal(0, record.GetCount(EDmaCallbackFrameCompletion));
-	test_Equal(2, record.GetCount(EDmaCallbackFrameCompletion_Src));
-	test_Equal(1, record.GetCount(EDmaCallbackFrameCompletion_Dst));
-	test_Equal(0, record.GetCount(EDmaCallbackLinkedListPaused));
-	test_Equal(0, record.GetCount(EDmaCallbackLinkedListPaused_Src));
-	test_Equal(1, record.GetCount(EDmaCallbackLinkedListPaused_Dst));
-
-	test.Next(_L("test expected == record"));
-	const TCallbackRecord expected(TCallbackRecord::EThread, 1, 1, 0, 4, 2, 2, 0, 2, 1, 0, 0, 1);
-	if(!(expected == record))
-		{
-		if(gVerboseOutput)
-			{
-			expected.Print();
-			}
-		TEST_FAULT;
-		}
-
-	test.Next(_L("modify record: test expected != record"));
-	record.SetCount(EDmaCallbackFrameCompletion, 10);
-	if(expected == record)
-		{
-		if(gVerboseOutput)
-			{
-			expected.Print();
-			}
-		TEST_FAULT;
-		}
-
-	test.Next(_L("test Reset()"));
-	record.Reset();
-	test(record == record2);
-
-	test.End();
-	}
-
-void CDmaBenchmark::SelfTest()
-	{
-	test.Start(_L("SelfTest of CDmaBenchmark"));
-	test.Next(_L("MeanResult()"));
-
-	TUint64 results[] = {8, 12, 1, 19, 3, 17, 10};
-	const TInt count = ARRAY_LENGTH(results);
-
-	CDmaBmFragmentation fragTest(_L("SelfTest"), count, TDmaTransferArgs(), 0);
-
-	for(TInt i = 0; i < count; i++)
-		{
-		fragTest.iResultArray.Append(results[i]);
-		}
-	test_Equal(10, fragTest.MeanResult());
-
-	test.End();
-	}
-
-void TAddrRange::SelfTest()
-	{
-	test.Start(_L("SelfTest of TAddrRange"));
-	TAddrRange a(0, 8);
-	TAddrRange b(8, 8);
-
-	test_Equal(7, a.End());
-	test_Equal(15, b.End());
-
-	test(!a.Overlaps(b));
-	test(!b.Overlaps(a));
-	test(a.Overlaps(a));
-	test(b.Overlaps(b));
-
-	TAddrRange c(7, 2);
-	test_Equal(8, c.End());
-
-	test(a.Overlaps(c));
-	test(c.Overlaps(a));
-	test(b.Overlaps(c));
-	test(c.Overlaps(b));
-
-	TAddrRange d(0, 24);
-	test(a.Overlaps(d));
-	test(d.Overlaps(a));
-
-	test(b.Overlaps(d));
-	test(d.Overlaps(b));
-
-	test(d.Contains(d));
-
-	test(d.Contains(a));
-	test(!a.Contains(d));
-
-	test(d.Contains(b));
-	test(!b.Contains(d));
-
-	test(!a.Contains(b));
-	test(!b.Contains(a));
-	test.End();
-	}
-
-void TAddressParms::SelfTest()
-	{
-	test.Start(_L("SelfTest of TAddressParms"));
-	const TAddressParms pA(0, 32, 8);
-	test(pA == pA);
-	test(pA.Overlaps(pA));
-
-	const TAddrRange rA(4, 8);
-	const TAddrRange rB(16, 8);
-	const TAddrRange rC(28, 8);
-	const TAddrRange rD(4, 32);
-
-	test(pA.Overlaps(rA));
-	test(!pA.Overlaps(rB));
-	test(pA.Overlaps(rC));
-	test(pA.Overlaps(rD));
-
-	const TAddressParms pB(8, 16, 8);
-	test(!(pA == pB));
-	test(!(pB == pA));
-	test(!pA.Overlaps(pB));
-	test(!pB.Overlaps(pA));
-
-	const TAddressParms pC(8, 28, 8);
-	test(pC.Overlaps(pA));
-	test(pC.Overlaps(pB));
-
-	const TAddressParms pD(0, 128, 64);
-	test(pD.Overlaps(pA));
-	test(pD.Overlaps(pB));
-	test(pD.Overlaps(pC));
-	test.End();
-	}
-
-void SelfTests()
-	{
-	test.Next(_L("Running framework unit tests"));
-	RDmaSession::SelfTest();
-	TDmaCapability::SelfTest();
-	TTestCase::SelfTest();
-	TTransferIter::SelfTest();
-	TCallbackRecord::SelfTest();
-	CDmaBmFragmentation::SelfTest();
-	TAddrRange::SelfTest();
-	TAddressParms::SelfTest();
-	test.End();
-	test.Close();
-	}
--- a/kerneltest/e32test/dmav2/t_dma2.cpp	Tue May 11 17:28:22 2010 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1546 +0,0 @@
-// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
-// All rights reserved.
-// This component and the accompanying materials are made available
-// under the terms of "Eclipse Public License v1.0"
-// which accompanies this distribution, and is available
-// at the URL "http://www.eclipse.org/legal/epl-v10.html".
-//
-// Initial Contributors:
-// Nokia Corporation - initial contribution.
-//
-// Contributors:
-//
-// Description:
-// e32test\dma\t_dma.cpp
-
-#include "d_dma2.h"
-#include "u32std.h"
-#include "t_dma2.h"
-#include "cap_reqs.h"
-
-#define __E32TEST_EXTENSION__
-#include <e32test.h>
-#include <e32debug.h>
-#include <e32svr.h>
-#include <e32def_private.h>
-
-// DMA test framework command  parameter options
-
-// SelfTest Option
-_LIT(KArgSelfTest, "/SELFTEST");  
-_LIT(KArgSelfTest2, "/S");		  
-
-//Verbose Option
-_LIT(KArgVerboseOutput, "/VERBOSE"); 
-_LIT(KArgVerboseOutput2, "/V");	     
-  
-
-TBool gHelpRequested;   // print usage 
-TBool gVerboseOutput;   // enable verbose output 
-TBool gSelfTest;        // run SelfTest 
-
-/**
-This function prints out the PSL test Information
-*/
-void Print(const TDmaV2TestInfo& aInfo)
-	{
-	PRINT(aInfo.iMaxTransferSize);
-	PRINT(aInfo.iMemAlignMask);
-	PRINT(aInfo.iMemMemPslInfo);
-	PRINT(aInfo.iMaxSbChannels);
-	for(TInt i=0; i<aInfo.iMaxSbChannels; i++)
-		{
-		PRINT(aInfo.iSbChannels[i]);
-		}
-	PRINT(aInfo.iMaxDbChannels);
-	for(TInt j=0; j<aInfo.iMaxDbChannels; j++)
-		{
-		PRINT(aInfo.iDbChannels[j]);
-		}
-	PRINT(aInfo.iMaxSgChannels);
-	for(TInt k=0; k<aInfo.iMaxSgChannels; k++)
-		{
-		PRINT(aInfo.iSgChannels[k]);
-		}
-	}
-
-void CDmaTest::PrintTestInfo() const
-	{
-	TBuf<32> buf;
-	buf.AppendFormat(_L("DMA channel %d"), iChannelCookie);
-	RDebug::RawPrint(buf);
-	}
-
-//////////////////////////////////////////////////////////////////////
-// CDmaTest
-//////////////////////////////////////////////////////////////////////
-
-void CDmaTest::OpenDmaSession()
-	{
-	TInt r = iDmaSession.Open();
-	TEST_ASSERT(r == KErrNone);
-	r = iDmaSession.OpenSharedChunk(iChunk);
-	TEST_ASSERT(r == KErrNone);
-	}
-
-void CDmaTest::CloseDmaSession()
-	{
-	iChunk.Close();
-	iDmaSession.Close();
-	}
-
-//////////////////////////////////////////////////////////////////////
-// CSingleTransferTest
-//////////////////////////////////////////////////////////////////////
-void CSingleTransferTest::RunTest()
-	{
-	OpenDmaSession();
-	PreTransferSetup();
-
-	OpenChannel();
-	CreateDmaRequest();
-	Fragment();
-	Queue();
-	FreeRequest();
-	CloseChannel();
-	PostTransferCheck();
-
-	CloseDmaSession();
-	}
-
-void CSingleTransferTest::OpenChannel()
-	{
-	iActual.iChannelOpenResult =
-		iDmaSession.ChannelOpen(iChannelCookie, iChannelSessionCookie);
-	}
-
-void CSingleTransferTest::CreateDmaRequest()
-	{
-	if(iUseNewRequest)
-	{
-		if(gVerboseOutput)
-			{
-			RDebug::Printf("Calling New Request API\n");
-			}
-		iActual.iRequestResult.iCreate =
-			iDmaSession.RequestCreateNew(iChannelSessionCookie, iRequestSessionCookie, iMaxFragmentSize);
-		}
-	else
-		{
-		if(gVerboseOutput)
-			{
-			RDebug::Printf("Calling Old Request API\n");
-			}
-		iActual.iRequestResult.iCreate =
-			iDmaSession.RequestCreate(iChannelSessionCookie, iRequestSessionCookie, iMaxFragmentSize);
-		}
-	}
-
-void CSingleTransferTest::Fragment()
-	{
-	if(iActual.iRequestResult.iCreate != KErrNone)
-		return;
-
-	if(iUseNewFragment)
-		{
-		if(gVerboseOutput)
-			{
-			RDebug::Printf("Calling New Fragment API\n");
-			}
-		iActual.iRequestResult.iFragmentationResult =
-			iDmaSession.FragmentRequest(iRequestSessionCookie, iTransferArgs);
-		}
-	else
-		{
-		if(gVerboseOutput)
-			{
-			RDebug::Printf("Calling Old Fragment API\n");
-			}
-		iActual.iRequestResult.iFragmentationResult =
-			iDmaSession.FragmentRequestOld(iRequestSessionCookie, iTransferArgs);
-
-		}
-
-	const TInt fragmentCount = iDmaSession.RequestFragmentCount(iRequestSessionCookie);
-
-	// Record the fragment count if a non-zero value was expected,
-	// or if it was an error value
-	if(iExpected.iRequestResult.iFragmentCount != 0 || fragmentCount < 0)
-		iActual.iRequestResult.iFragmentCount = fragmentCount;
-	}
-
-void CSingleTransferTest::Queue()
-	{
-	if(iActual.iRequestResult.iFragmentationResult == KErrNone)
-		{
-		iActual.iRequestResult.iQueueResult = iDmaSession.QueueRequest(iRequestSessionCookie, &iActual.iCallbackRecord);
-		}
-	}
-
-void CSingleTransferTest::PostTransferCheck()
-	{
-	if(iPostTransferCheck)
-		iActual.iPostTransferCheck = DoPostTransferCheck();
-	}
-
-TInt CSingleTransferTest::DoPostTransferCheck()
-	{
-	return iPostTransferCheck->Check(*this);
-	}
-
-void CSingleTransferTest::FreeRequest()
-	{
-	if(iActual.iRequestResult.iCreate == KErrNone)
-		{
-		TInt r = iDmaSession.RequestDestroy(iRequestSessionCookie);
-		TEST_ASSERT(r == KErrNone);
-		}
-	}
-
-void CSingleTransferTest::CloseChannel()
-	{
-	if(iActual.iChannelOpenResult == KErrNone)
-		{
-		TInt r = iDmaSession.ChannelClose(iChannelSessionCookie);
-		TEST_ASSERT(r == KErrNone);
-		}
-	}
-
-void CSingleTransferTest::PrintTestType() const
-	{
-	RDebug::RawPrint(_L("Single transfer"));
-	}
-
-void CSingleTransferTest::PreTransferSetup()
-	{
-	if(iPreTransfer)
-		iPreTransfer->Setup(*this); //initialize test
-	}
-
-TBool CSingleTransferTest::Result()
-	{
-	const TBool result = iExpected == iActual;
-	if(!result)
-		{
-		RDebug::Printf("TResultSets do not match");
-		}
-	if(!result || gVerboseOutput)
-		{
-		RDebug::Printf("\nExpected error codes:");
-		iExpected.Print();
-		RDebug::Printf("Expected callback record:");
-		iExpected.iCallbackRecord.Print();
-
-		RDebug::Printf("\nActual error codes:");
-		iActual.Print();
-		RDebug::Printf("Actual callback record:");
-		iActual.iCallbackRecord.Print();
-		}
-	return result;
-	}
-
-
-
-//////////////////////////////////////////////////////////////////////
-// CDmaBenchmark
-//////////////////////////////////////////////////////////////////////
-
-CDmaBenchmark::CDmaBenchmark(const TDesC& aName, TInt aIterations, const TResultSet& aExpectedResults, const TDmaTransferArgs& aTransferArgs, TUint aMaxFragmentSize)
-	:CSingleTransferTest(aName, aIterations, aTransferArgs, aExpectedResults, aMaxFragmentSize, NULL, NULL)
-	{
-	UseNewDmaApi(EFalse);
-	}
-
-CDmaBenchmark::~CDmaBenchmark()
-	{
-	iResultArray.Close();
-	}
-
-TUint64 CDmaBenchmark::MeanResult()
-	{
-	if(gVerboseOutput)
-		RDebug::Printf("CDmaBenchmark::MeanResult\n");
-
-	const TInt count = iResultArray.Count();
-
-	TEST_ASSERT(count > 0);
-	TEST_ASSERT(count == iIterations);
-
-	TUint64 sum = 0;
-
-	for(TInt i = 0; i < count; i++)
-		{
-		const TUint64 value = iResultArray[i];
-		if(gVerboseOutput)
-			RDebug::Printf("iResultArray[%d]: %lu", i, value);
-
-		sum += value;
-		}
-
-	return sum / count;
-	}
-
-TBool CDmaBenchmark::Result()
-	{
-	const TBool result = CSingleTransferTest::Result();
-	if(result)
-		{
-		RDebug::Printf("  Mean time: %lu us", MeanResult());
-		}
-
-	//TODO this will be handled by the ctor later
-	iResultArray.Close();
-
-	return result;
-	}
-
-
-//////////////////////////////////////////////////////////////////////
-// CDmaBmFragmentation
-//////////////////////////////////////////////////////////////////////
-
-CDmaBmFragmentation::CDmaBmFragmentation(const TDesC& aName, TInt aIterations, const TDmaTransferArgs& aTransferArgs, TUint aMaxFragmentSize)
-	:CDmaBenchmark(aName, aIterations, ExpectedResults, aTransferArgs, aMaxFragmentSize)
-	{}
-
-const TResultSet CDmaBmFragmentation::ExpectedResults(KErrNone,
-		TRequestResults(KErrNone, 0, KErrNone, KErrUnknown),
-		KErrUnknown,
-		TCallbackRecord::Empty()
-		);
-
-void CDmaBmFragmentation::Fragment()
-	{
-	TUint64 time;
-	iActual.iRequestResult.iFragmentationResult =
-		iDmaSession.FragmentRequestOld(iRequestSessionCookie, iTransferArgs, &time);
-	iResultArray.Append(time);
-	}
-
-void CDmaBmFragmentation::PrintTestType() const
-	{
-	RDebug::RawPrint(_L("Fragmentation Benchmark"));
-	}
-
-void CDmaBmFragmentation::RunTest()
-	{
-	OpenDmaSession();
-
-	OpenChannel();
-	CreateDmaRequest();
-	Fragment();
-	FreeRequest();
-	CloseChannel();
-
-	CloseDmaSession();
-	}
-
-//////////////////////////////////////////////////////////////////////
-// CDmaBmTransfer
-//////////////////////////////////////////////////////////////////////
-
-CDmaBmTransfer::CDmaBmTransfer(const TDesC& aName, TInt aIterations, const TDmaTransferArgs& aTransferArgs, TUint aMaxFragmentSize)
-	:CDmaBenchmark(aName, aIterations,
-		TResultSet(KErrNone, TRequestResults(),	KErrUnknown, TCallbackRecord(TCallbackRecord::EThread,1)),
-		aTransferArgs, aMaxFragmentSize)
-	{}
-
-
-void CDmaBmTransfer::PrintTestType() const
-	{
-	RDebug::RawPrint(_L("Transfer Benchmark"));
-	}
-
-void CDmaBmTransfer::RunTest()
-	{
-	OpenDmaSession();
-
-	OpenChannel();
-	CreateDmaRequest();
-	Fragment();
-	Queue();
-	FreeRequest();
-	CloseChannel();
-
-	CloseDmaSession();
-	}
-
-void CDmaBmTransfer::Queue()
-	{
-	if(iActual.iRequestResult.iFragmentationResult == KErrNone)
-		{
-		TUint64 time;
-		iActual.iRequestResult.iQueueResult = iDmaSession.QueueRequest(iRequestSessionCookie, &iActual.iCallbackRecord, &time);
-		iResultArray.Append(time);
-		}
-	}
-
-
-//////////////////////////////////////////////////////////////////////
-// CMultiTransferTest
-//////////////////////////////////////////////////////////////////////
-
-//TODO
-// Add pre and post transfer for CMultiTransferTest
-CMultiTransferTest::CMultiTransferTest(const TDesC& aName, TInt aIterations, const TDmaTransferArgs* aTransferArgs,
-		const TResultSet* aResultSets, TInt aCount)
-	: CDmaTest(aName, aIterations, NULL, NULL), iTransferArgs(aTransferArgs), iTransferArgsCount(aCount), iNewDmaApi(ETrue),
-	iChannelSessionCookie(0), iExpectedArray(aResultSets), iPauseWhileQueuing(EFalse)
-	{}
-
-CMultiTransferTest::CMultiTransferTest(const CMultiTransferTest& aOther)
-	: CDmaTest(aOther), iTransferArgs(aOther.iTransferArgs), iTransferArgsCount(aOther.iTransferArgsCount),
-	iNewDmaApi(aOther.iNewDmaApi),
-	iExpectedArray(aOther.iExpectedArray), iPauseWhileQueuing(aOther.iPauseWhileQueuing)
-	//const cast is required because their isn't a ctor taking const
-	//array values
-	//TODO iRequestCookies(const_cast<TUint*>(&aOther.iRequestCookies[0]), aOther.iRequestCookies.Count())
-	{
-	}
-
-CMultiTransferTest::~CMultiTransferTest()
-	{
-	iRequestCookies.Close();
-	iActualResults.Close();
-	}
-
-TBool CMultiTransferTest::Result()
-	{
-	if(gVerboseOutput)
-		{
-		RDebug::Printf("Results for %d transfers:", iTransferArgsCount);
-		}
-
-	TBool result = EFalse;
-	for(TInt i=0; i<iTransferArgsCount; i++)
-		{
-		result = Result(i);
-		if(!result)
-			break;
-		}
-	return result;
-	}
-
-TBool CMultiTransferTest::Result(TInt aTransfer)
-	{
-	const TResultSet& expected = iExpectedArray[aTransfer];
-	const TResultSet& actual = iActualResults[aTransfer];
-	const TBool result = expected == actual;
-	if(!result || gVerboseOutput)
-		{
-		RDebug::Printf("Compairing results for transfer %d", aTransfer);
-		}
-
-	if(!result)
-		{
-		RDebug::Printf("TResultSets do not match");
-		}
-	if(!result || gVerboseOutput)
-		{
-		RDebug::Printf("\nExpected error codes:");
-		expected.Print();
-		RDebug::Printf("Expected callback record:");
-		expected.iCallbackRecord.Print();
-
-		RDebug::Printf("\nActual error codes:");
-		actual.Print();
-		RDebug::Printf("Actual callback record:");
-		actual.iCallbackRecord.Print();
-		}
-	return result;
-	}
-void CMultiTransferTest::RunTest()
-	{
-	OpenDmaSession();
-
-	PreTransferSetup();
-	OpenChannel();
-
-	CreateDmaRequests();
-	Fragment();
-
-	QueueRequests();
-
-	TInt r = DoPostTransferCheck();
-	TEST_ASSERT(r == KErrNone);
-
-	CloseDmaSession();
-	}
-
-void CMultiTransferTest::PrintTestType() const
-	{
-	RDebug::RawPrint(_L("Multi Transfer"));
-	}
-
-const TDmaTransferArgs& CMultiTransferTest::TransferArgs(TInt aIndex) const
-	{
-	TEST_ASSERT(Rng(0, aIndex, iTransferArgsCount-1));
-
-	return iTransferArgs[aIndex];
-	}
-
-void CMultiTransferTest::SetPostTransferResult(TInt aIndex, TInt aErrorCode)
-	{
-	TEST_ASSERT(Rng(0, aIndex, iTransferArgsCount-1));
-
-	iActualResults[aIndex].iPostTransferCheck = aErrorCode;
-	}
-
-void CMultiTransferTest::OpenChannel()
-	{
-	if(gVerboseOutput)
-		{
-		RDebug::Printf("CMultiTransferTest::OpenChannel()");
-		}
-	TInt r = iDmaSession.ChannelOpen(iChannelCookie, iChannelSessionCookie);
-
-	TEST_ASSERT(iActualResults.Count() == iTransferArgsCount);
-	for(TInt i=0; i<iTransferArgsCount; i++)
-		{
-		// Since all transfers will use the same channel,
-		// they all get the same result
-		// Arguably, iChannelOpenResult doesn't
-		// belong TResultSet
-		iActualResults[i].iChannelOpenResult = r;
-		}
-	}
-
-TInt CMultiTransferTest::CloseChannel()
-	{
-	return iDmaSession.ChannelClose(iChannelSessionCookie);
-	}
-
-void CMultiTransferTest::CreateDmaRequests()
-	{
-	if(gVerboseOutput)
-		{
-		RDebug::Printf("CMultiTransferTest::CreateDmaRequests() %d", iTransferArgsCount);
-		}
-	TEST_ASSERT(iActualResults.Count() == iTransferArgsCount);
-	//create a DMA request for each transfer arg struct
-	for(TInt i=0; i<iTransferArgsCount; i++)
-		{
-		if(iActualResults[i].iChannelOpenResult != KErrNone)
-			continue;
-
-		TUint cookie = 0;
-		TInt r = KErrGeneral;
-
-		if(iNewDmaApi)
-			{
-			r = iDmaSession.RequestCreateNew(iChannelSessionCookie, cookie);
-			}
-		else
-			{
-			r = iDmaSession.RequestCreate(iChannelSessionCookie, cookie);
-			}
-		iActualResults[i].iRequestResult.iCreate = r;
-
-		if(r == KErrNone)
-			{
-			r = iRequestCookies.Append(cookie);
-			TEST_ASSERT(r == KErrNone);
-			}
-		}
-	}
-
-void CMultiTransferTest::Fragment()
-	{
-	if(gVerboseOutput)
-		{
-		RDebug::Printf("CMultiTransferTest::Fragment() %d", iTransferArgsCount);
-		}
-	TEST_ASSERT(iActualResults.Count() == iTransferArgsCount);
-	// Fragment each dma request
-	for(TInt i=0; i<iTransferArgsCount; i++)
-		{
-		TRequestResults& result = iActualResults[i].iRequestResult;
-		if(result.iCreate != KErrNone)
-			continue;
-
-		TInt r = KErrGeneral;
-		if(iNewDmaApi)
-			r = iDmaSession.FragmentRequest(iRequestCookies[i], iTransferArgs[i]);
-		else
-			r = iDmaSession.FragmentRequestOld(iRequestCookies[i], iTransferArgs[i]);
-
-		result.iFragmentationResult = r;
-		}
-	}
-
-void CMultiTransferTest::QueueRequests()
-	{
-	if(iPauseWhileQueuing)
-		{
-		TInt r = iDmaSession.ChannelPause(iChannelSessionCookie);
-		TEST_ASSERT(r == KErrNone);
-		}
-
-	// Queue all the DMA requests asynchronously
-	TInt i;
-	RArray<TRequestStatus> requestStates;
-
-	TEST_ASSERT(iActualResults.Count() == iTransferArgsCount);
-	for(i=0; i<iTransferArgsCount; i++)
-		{
-		TResultSet& resultSet = iActualResults[i];
-		if(resultSet.iRequestResult.iFragmentationResult != KErrNone)
-			continue;
-
-		TInt r = requestStates.Append(TRequestStatus());
-		TEST_ASSERT(r == KErrNone);
-
-		r = iDmaSession.QueueRequest(iRequestCookies[i], requestStates[i], &resultSet.iCallbackRecord, NULL);
-		resultSet.iRequestResult.iQueueResult = r;
-		}
-
-	if(iPauseWhileQueuing)
-		{
-		TInt r = iDmaSession.ChannelResume(iChannelSessionCookie);
-		TEST_ASSERT(r == KErrNone);
-		}
-
-	// wait for all transfers to complete
-	const TInt count = requestStates.Count();
-
-	for(i=0; i<count; i++)
-		{
-		User::WaitForRequest(requestStates[i]);
-		}
-
-	requestStates.Close();
-	}
-
-//TODO support test setup for CMultiTransferTest
-void CMultiTransferTest::PreTransferSetup()
-	{
-	for(TInt i=0; i<iTransferArgsCount; i++)
-		{
-		//pre-fill actual results with error values
-		TInt r = iActualResults.Append(TResultSet(EFalse));
-		TEST_ASSERT(r == KErrNone);
-		}
-	if(iPreTransfer)
-		iPreTransfer->Setup(*this); //initialize test
-	}
-
-TInt CMultiTransferTest::DoPostTransferCheck()
-	{
-	if(iPostTransferCheck)
-		return iPostTransferCheck->Check(*this);
-	else
-		return KErrNone;
-	}
-//////////////////////////////////////////////////////////////////////
-// CIsrRequeTest
-//////////////////////////////////////////////////////////////////////
-
-
-CIsrRequeTest::CIsrRequeTest(const TDesC& aName, TInt aIterations, const TDmaTransferArgs& aArgs,
-			TIsrRequeArgs* aRequeueArgs, TInt aCount,
-			const TResultSet& aExpected,const MPreTransfer* aPreTfer,const MPostTransferCheck* aPostTferChk, TUint aMaxFragmentSize)
-	:CSingleTransferTest(aName, aIterations, aArgs, aExpected, aMaxFragmentSize, aPostTferChk, aPreTfer), iRequeArgSet(aRequeueArgs, aCount)
-	{}
-
-void CIsrRequeTest::Queue()
-	{
-	if(iActual.iRequestResult.iFragmentationResult == KErrNone)
-		{
-		iActual.iRequestResult.iQueueResult = iDmaSession.QueueRequestWithRequeue(iRequestSessionCookie, iRequeArgSet.iRequeArgs, iRequeArgSet.iCount, &iActual.iCallbackRecord);
-		}
-	}
-
-void CIsrRequeTest::PrintTestType() const
-	{
-	RDebug::RawPrint(_L("ISR Requeue"));
-	}
-
-/*
-//TODO will need to support buffer checking of the trasnfers
-TBool CIsrRequeTest::Result()
-	{
-	return CSingleTransferTest::Result();
-	}
-*/
-
-void CIsrRequeTest::PreTransferSetup()
-	{
-	if(iPreTransfer)
-		iPreTransfer->Setup(*this); //initialize test
-	}
-
-TInt CIsrRequeTest::DoPostTransferCheck()
-	{
-	return iPostTransferCheck->Check(*this);
-	}
-
-//////////////////////////////////////////////////////////////////////
-// TResultSet
-//////////////////////////////////////////////////////////////////////
-
-void TResultSet::Print() const
-	{
-	PRINT(iChannelOpenResult);
-	PRINT(iRequestResult.iCreate);
-	PRINT(iRequestResult.iFragmentCount);
-	PRINT(iRequestResult.iFragmentationResult);
-	PRINT(iRequestResult.iQueueResult);
-	PRINT(iPostTransferCheck);
-	}
-
-TBool TResultSet::operator == (const TResultSet& aOther) const
-	{
-	return (memcompare((TUint8*)this, sizeof(*this), (TUint8*)&aOther, sizeof(aOther)) == 0);
-	}
-
-//////////////////////////////////////////////////////////////////////
-// MPostTransferCheck classes
-//////////////////////////////////////////////////////////////////////
-
-TInt TCompareSrcDst::Check(const CSingleTransferTest& aTest) const
-	{
-	if(gVerboseOutput)
-		{
-		RDebug::Printf("Comparing CSingleTransferTest buffers");
-		}
-	return Check(aTest.TransferArgs(), aTest.Chunk().Base());
-	}
-
-//TODO
-//this check will not deal correctly transfers were subsequent
-//requeues overlap
-TInt TCompareSrcDst::Check(const CIsrRequeTest& aTest) const
-	{
-	if(gVerboseOutput)
-		{
-		RDebug::Printf("Comparing CIsrRequeTest buffers");
-		}
-	TUint8* chunkBase = aTest.Chunk().Base();
-	const TDmaTransferArgs& transferArgs = aTest.TransferArgs();
-	// check first transfer
-	TInt r = Check(transferArgs, chunkBase);
-
-	if(r != KErrNone)
-		return r;
-
-	// check re-queued transfers
-	const TIsrRequeArgsSet& requeueArgs = aTest.GetRequeueArgs();
-	return Check(requeueArgs, chunkBase, transferArgs);
-	}
-
-TInt TCompareSrcDst::Check(const TDmaTransferArgs& aTransferArgs, TUint8* aChunkBase) const
-	{
-	//TODO could make use of Fixup() method
-	const TUint32 srcOffset = aTransferArgs.iSrcConfig.iAddr;
-	const TUint32 dstOffset = aTransferArgs.iDstConfig.iAddr;
-	const TInt size = aTransferArgs.iTransferCount;
-
-	const TUint8* src = srcOffset + aChunkBase;
-	const TUint8* dst = dstOffset + aChunkBase;
-
-	if(gVerboseOutput)
-		{
-		RDebug::Printf("Comparing TDmaTransferArgs buffers src=0x%08x dst=0x%08x size=0x%08x",
-				src, dst, size);
-		}
-
-	return memcompare(src, size, dst, size);
-	}
-
-TInt TCompareSrcDst::Check(const TIsrRequeArgsSet& aRequeueArgSet, TUint8* aChunkBase, const TDmaTransferArgs& aTferArgs) const
-	{
-	TIsrRequeArgsSet argSet(aRequeueArgSet); //copy since Fixup will mutate object
-
-	argSet.Substitute(aTferArgs); // replace any default (0) values with the values in aTferArgs
-
-	argSet.Fixup((TLinAddr)aChunkBase); //convert address offsets to virtual user mode addresses
-
-	TInt r = KErrCorrupt;
-	while(!argSet.IsEmpty())
-		{
-		r = Check(argSet.GetArgs());
-		if(r != KErrNone)
-			break;
-		}
-	return r;
-	}
-
-TInt TCompareSrcDst::Check(const TIsrRequeArgs& aRequeueArgs) const
-	{
-	const TUint8* src = (TUint8*)aRequeueArgs.iSrcAddr;
-	const TUint8* dst = (TUint8*)aRequeueArgs.iDstAddr;
-	const TInt size = aRequeueArgs.iTransferCount;
-
-	if(gVerboseOutput)
-		{
-		RDebug::Printf("Comparing TIsrRequeArgs: src=0x%08x dst=0x%08x size=0x%08x",
-				src, dst, size);
-		}
-
-	return memcompare(src, size, dst, size);
-	}
-
-TInt TCompareSrcDst::Check(CMultiTransferTest& aTest) const
-	{
-	if(gVerboseOutput)
-		{
-		RDebug::Printf("Comparing CMultiTransferTest buffers");
-		}
-
-	const TInt transferCount = aTest.TransferCount();
-	TUint8* const chunkBase = aTest.Chunk().Base();
-
-	// check buffers for each transfer
-	for(TInt i=0; i<transferCount; i++)
-		{
-		TInt r = Check(aTest.TransferArgs(i), chunkBase);
-		aTest.SetPostTransferResult(i, r);
-		}
-	// CMultiTransferTest is handled differently to the others.
-	// Whereas CSingleTransferTest logs just the return value
-	// of the check, here, we write back a result for each transfer
-	// so the return value from this function is not important
-	return KErrNone;
-	}
-
-TInt TCompare2D::Check(const CSingleTransferTest& aTest) const
-	{
-	const TDmaTransferArgs& args = aTest.TransferArgs();
-	TUint8* const chunkBase = aTest.Chunk().Base();
-
-	TInt ret = KErrNone;
-
-	TTransferIter src_iter(args.iSrcConfig, chunkBase);
-	TTransferIter dst_iter(args.iDstConfig, chunkBase);
-	TTransferIter end;
-	for (; (src_iter != end) && (dst_iter !=end); ++src_iter, ++dst_iter)
-		{
-		if(*src_iter != *dst_iter)
-			{
-			ret = KErrCorrupt;
-			break;
-			}
-		}
-	return ret;
-	}
-
-TInt TCompare2D::Check(const CIsrRequeTest&) const
-	{
-	return KErrNotSupported;
-	}
-
-TInt TCompare2D::Check(CMultiTransferTest&) const
-	{
-	return KErrNotSupported;
-	}
-//////////////////////////////////////////////////////////////////////
-// MPreTransfer classes
-//////////////////////////////////////////////////////////////////////
-
-void TPreTransferIncrBytes::Setup(const CSingleTransferTest& aTest) const
-	{
-	if(gVerboseOutput)
-		{
-		RDebug::Printf("TPreTransferIncrBytes(CSingleTransferTest)");
-		}
-	TAddressParms params = GetAddrParms(aTest.TransferArgs());
-
-	TUint8* const chunkBase = aTest.Chunk().Base();
-	params.Fixup((TLinAddr)chunkBase);
-
-
-	Setup(params);
-	}
-
-void TPreTransferIncrBytes::Setup(const TAddressParms& aParams) const
-	{
-	if(gVerboseOutput)
-		{
-		RDebug::Printf("TPreTransferIncrBytes: setup memory buffers: src=0x%08x dst=0x%08x size=0x%08x",
-				aParams.iSrcAddr, aParams.iDstAddr, aParams.iTransferCount);
-		}
-	TUint8* const src = (TUint8*) aParams.iSrcAddr;
-	const TInt size = aParams.iTransferCount;
-
-	for(TInt i=0; i<size; i++)
-		{src[i] = (TUint8)i;} //each src byte holds its own offset (mod 256)
-
-	TUint8* const dst = (TUint8*) aParams.iDstAddr;
-	memclr(dst, size); //clear destination
-	}
-
-void TPreTransferIncrBytes::Setup(const CIsrRequeTest& aTest) const
-	{
-	if(gVerboseOutput)
-		{
-		RDebug::Printf("TPreTransferIncrBytes(CIsrRequeTest)");
-		}
-	if(!CheckBuffers(aTest))
-		{
-		RDebug::Printf("Successive transfer destinations may not overlap previous src or dst buffers");
-		RDebug::Printf("unless the whole transfer is an exact repeat of a previous one");
-		TEST_FAULT;
-		}
-
-	Setup(static_cast<CSingleTransferTest>(aTest)); // prepare the CSingleTransferTest parts
-
-	TIsrRequeArgsSet requeSet(aTest.GetRequeueArgs());
-
-	requeSet.Substitute(aTest.TransferArgs());
-
-	const TLinAddr chunkBase = (TLinAddr) aTest.Chunk().Base();
-	requeSet.Fixup(chunkBase);
-
-	while(!requeSet.IsEmpty())
-		{
-		TIsrRequeArgs args = requeSet.GetArgs();
-		Setup(args); // perform the setup operation for each TIsrRequeArgs
-		}
-	}
-
-void TPreTransferIncrBytes::Setup(const CMultiTransferTest& aTest) const
-	{
-	if(gVerboseOutput)
-		{
-		RDebug::Printf("TPreTransferIncrBytes(CMultiTransferTest)");
-		}
-	//TODO check for overlap
-
-	TUint8* const chunkBase = aTest.Chunk().Base();
-	const TInt transferCount = aTest.TransferCount();
-
-	// initialise buffers for each transfer
-	for(TInt i=0; i<transferCount; i++)
-		{
-		TAddressParms params = GetAddrParms(aTest.TransferArgs(i));
-
-		params.Fixup((TLinAddr)chunkBase);
-
-		Setup(params);
-		}
-	}
-
-TBool TPreTransferIncrBytes::CheckBuffers(const CIsrRequeTest& aTest) const
-	{
-	RArray<const TAddressParms> array;
-	array.AppendL(TAddressParms(aTest.TransferArgs()));
-
-	TIsrRequeArgsSet requeSet(aTest.GetRequeueArgs());
-	requeSet.Substitute(aTest.TransferArgs());
-
-	const TLinAddr chunkBase = (TLinAddr) aTest.Chunk().Base();
-	requeSet.Fixup(chunkBase);
-	while(!requeSet.IsEmpty())
-		{
-		const TIsrRequeArgs requeArgs = requeSet.GetArgs();
-		array.AppendL(requeArgs);
-		}
-
-	const TBool result = CheckBuffers(array);
-
-	array.Close();
-	return result;
-	}
-
-/**
-Check that the destination of each TAddressParms does not overlap with
-any previous source or destination or that if it does the whole transfer
-matches.
-This is so that successive transfers do not overwrite the destinations or
-sources of preceeding ones.
-Exactly matching transfers are allowed to test the case that a repeat
-transfer is required - though it can't then be determined just from
-looking at the buffers that the repeat was successful
-*/
-TBool TPreTransferIncrBytes::CheckBuffers(const RArray<const TAddressParms> aTransferParams) const
-	{
-	const TInt count = aTransferParams.Count();
-
-	for(TInt i=1; i<count; i++)
-		{
-		const TAddressParms& current = aTransferParams[i];
-		for(TInt j=0; j<i; j++)
-			{
-			const TAddressParms& previous = aTransferParams[j];
-			const TBool ok = !previous.Overlaps(current.DestRange()) || current == previous;
-			if(!ok)
-				return EFalse;
-			}
-		}
-	return ETrue;
-	}
-//////////////////////////////////////////////////////////////////////
-// TTransferIter class
-//////////////////////////////////////////////////////////////////////
-
-void TTransferIter::operator++ ()
-	{
-	iPtr++; //the standard post increment
-	if(iElem < (iCfg->iElementsPerFrame-1))
-		{
-		iPtr += iCfg->iElementSkip;
-		iElem++;
-		iBytes++;
-		}
-	else
-		{
-		TEST_ASSERT(iElem == iCfg->iElementsPerFrame-1);
-		if(iFrame < iCfg->iFramesPerTransfer-1)
-			{
-			iPtr += iCfg->iFrameSkip;
-			iFrame++;
-			iBytes++;
-			iElem = 0;
-			}
-		else
-			{
-			//we have reached the end
-			TEST_ASSERT(iFrame == iCfg->iFramesPerTransfer-1);
-			iPtr = NULL;
-			}
-		}
-
-	Invariant();
-	}
-
-void TTransferIter::Invariant() const
-	{
-	const TInt elemSize = iCfg->iElementSize;
-	RTest test(_L("TTransferIter invariant"));
-	const TInt bytesTransfered = (
-			elemSize * (iFrame * iCfg->iElementsPerFrame + iElem)
-			+ ((TUint)iPtr % (elemSize))
-			);
-	test_Equal(iBytes, bytesTransfered);
-	test.Close();
-	}
-
-///////////////////////////////////////////////////////////
-// TTestCase
-///////////////////////////////////////////////////////////
-TTestCase::TTestCase(CDmaTest* aTest,
-   TBool aConcurrent,
-   const TDmaCapability aCap1,
-   const TDmaCapability aCap2,
-   const TDmaCapability aCap3,
-   const TDmaCapability aCap4,
-   const TDmaCapability aCap5
-   )
-:
-	iTest(aTest), iConcurrentTest(aConcurrent)
-	{
-	iChannelCaps[0] = aCap1;
-	iChannelCaps[1] = aCap2;
-	iChannelCaps[2] = aCap3;
-	iChannelCaps[3] = aCap4;
-	iChannelCaps[4] = aCap5;
-	}
-
-TResult TTestCase::TestCaseValid(const SDmacCaps& aChannelCaps) const
-	{
-	const TDmaCapability* cap = &iChannelCaps[0];
-
-	TResult ret = ERun;
-	//We assume that the array is empty at the first ENone found
-	//any caps after this wil be ignored
-	while(cap->iCapsReq != ENone)
-		{
-		TResult t = cap->CompareToDmaCaps(aChannelCaps);
-		if(t > ret) //this relies on the enum ordering
-			ret = t;
-		cap++;
-		}
-	return ret;
-	}
-
-TResult TTestCase::TestCaseValid(const TDmacTestCaps& aChannelCaps) const
-	{
-	const TDmaCapability* cap = &iChannelCaps[0];
-
-	TResult ret = ERun;
-	//We assume that the array is empty at the first ENone found
-	//any caps after this wil be ignored
-	while(cap->iCapsReq != ENone)
-		{
-		TResult t = cap->CompareToDmaCaps(aChannelCaps);
-		if(t > ret) //this relies on the enum ordering
-			ret = t;
-		cap++;
-		}
-	return ret;
-	}
-/**
-Will report whether a value held in aChannelCaps satisfies a
-requirement specfied by this object
-*/
-TBool TDmaCapability::RequirementSatisfied(const SDmacCaps& aChannelCaps) const
-	{
-	switch(iCapsReq)
-		{
-	case ENone:
-		return ETrue;
-	case EChannelPriorities:
-		TEST_FAULT;
-	case EChannelPauseAndResume:
-		return aChannelCaps.iChannelPauseAndResume == (TBool)iValue;
-	case EAddrAlignedToElementSize:
-		TEST_FAULT;
-	case E1DAddressing:
-		return aChannelCaps.i1DIndexAddressing == (TBool)iValue;
-	case E2DAddressing:
-		return aChannelCaps.i2DIndexAddressing == (TBool)iValue;
-	case ESynchronizationTypes:
-	case EBurstTransactions:
-	case EDescriptorInterrupt:
-	case EFrameInterrupt:
-	case ELinkedListPausedInterrupt:
-	case EEndiannessConversion:
-	case EGraphicsOps:
-	case ERepeatingTransfers:
-	case EChannelLinking:
-		TEST_FAULT;
-	case EHwDescriptors:
-		return aChannelCaps.iHwDescriptors == (TBool)iValue;
-	case ESrcDstAsymmetry:
-	case EAsymHwDescriptors:
-		TEST_FAULT;
-	case EBalancedAsymSegments:
-		return aChannelCaps.iBalancedAsymSegments == (TBool)iValue;
-	case EAsymCompletionInterrupt:
-		return aChannelCaps.iAsymCompletionInterrupt == (TBool)iValue;
-	case EAsymDescriptorInterrupt:
-		return aChannelCaps.iAsymDescriptorInterrupt == (TBool)iValue;
-	case EAsymFrameInterrupt:
-		return aChannelCaps.iAsymFrameInterrupt == (TBool)iValue;
-	default:
-		TEST_FAULT;
-		}
-
-	return EFalse;
-	}
-
-/**
-Will report whether a value held in aChannelCaps satisfies a
-requirement specfied by this object
-*/
-TBool TDmaCapability::RequirementSatisfied(const TDmacTestCaps& aChannelCaps) const
-	{
-	switch(iCapsReq)
-		{
-	case EPilVersion:
-		return TestValue(aChannelCaps.iPILVersion);
-	default:
-		return RequirementSatisfied(static_cast<SDmacCaps>(aChannelCaps));
-		}
-	}
-
-TResult TDmaCapability::CompareToDmaCaps(const SDmacCaps& aChannelCaps) const
-	{
-	const TBool reqSatisfied = RequirementSatisfied(aChannelCaps);
-	if(reqSatisfied)
-		{
-		return ERun;
-		}
-	else
-		{
-		return iFail ? EFail : ESkip;
-		}
-	}
-
-TResult TDmaCapability::CompareToDmaCaps(const TDmacTestCaps& aChannelCaps) const
-	{
-	const TBool reqSatisfied = RequirementSatisfied(aChannelCaps);
-	if(reqSatisfied)
-		{
-		return ERun;
-		}
-	else
-		{
-		return iFail ? EFail : ESkip;
-		}
-	}
-/**
-Test that aValue satisfies the comparrison (iCapsReqType) with the
-reference value held in iValue
-*/
-TBool TDmaCapability::TestValue(TUint aValue) const
-	{
-	switch(iCapsReqType)
-		{
-	case EEqual:
-		return aValue == iValue;
-	case EGTE:
-		return aValue >= iValue;
-	case ELTE:
-		return aValue <= iValue;
-	case EBitsSet:
-	case EBitsClear:
-	default:
-		TEST_FAULT;
-		}
-	return EFalse;
-	}
-
-static RTest test(_L("DMAv2 test"));
-
-//////////////////////////////////////////////////////////////////////
-// TTestRunner
-//////////////////////////////////////////////////////////////////////
-TTestRunner::TTestRunner()
-	{
-	// Open RDmaSession handle
-	TInt r = iDmaSession.Open();
-	TEST_ASSERT(r == KErrNone);
-
-	// Get PSI Test info
-	r = iDmaSession.GetTestInfo(iPslTestInfo);
-	TEST_ASSERT(r == KErrNone);
-
-	//Retrieve PSL cookies
-	GetPslCookie();
-
-	//Generate the DMA channel records
-	GenerateChannelRecord();
-	}
-
-TTestRunner::~TTestRunner()
-	{
-	RTest::CloseHandleAndWaitForDestruction(iDmaSession);
-	iTestCases.Close(); //TestRunner does not own test cases
-	iChannelRecords.Close();
-	iPslCookies.Close();
-	}
-
-void TTestRunner::AddTestCases(RPointerArray<TTestCase>& aTTestCases)
-	{
-	const TInt count = aTTestCases.Count();
-	for(TInt i=0; i < count; i++)
-		{
-		iTestCases.AppendL(aTTestCases[i]);
-		}
-	}
-
-void TTestRunner::RunTests()
-	{
-	//Print PslTestInfo
-	if(gVerboseOutput)
-		{
-		Print(iPslTestInfo);
-		}
-
-	//iterate through the test case array
-	const TInt testCaseCount = iTestCases.Count();
-	for(TInt i=0; i < testCaseCount; i++)
-		{
-		const TTestCase& testCase = *iTestCases[i];
-
-		//Here, we must create a test thread for each channel
-		RPointerArray<CTest> concurrentTests;
-
-		if(testCase.iConcurrentTest)
-			RDebug::Printf("== Begin concurrent test run ==");
-
-		const TInt chanRecCount = iChannelRecords.Count();
-		for(TInt j=0; j < chanRecCount; j++)
-			{
-			const TChannelRecord& record = iChannelRecords[j];
-			const TDmacTestCaps& caps = record.iChannelCaps;
-
-			const TResult t = testCase.TestCaseValid(caps);
-
-			switch(t)
-				{
-			case ERun:
-				{
-				CDmaTest* dmaTest = static_cast<CDmaTest*>(testCase.iTest->Clone());
-				TEST_ASSERT(dmaTest != NULL);
-
-				dmaTest->SetChannelCookie(record.iCookie);
-				dmaTest->Announce();
-				if(testCase.iConcurrentTest)
-					{
-					//Add test to array to be run concurrently
-					TInt r = concurrentTests.Append(dmaTest);
-					TEST_ASSERT(r == KErrNone);
-					}
-				else
-					{
-					//Run test in this thread
-					(*dmaTest)();
-					//TTestThread(
-					TBool result = dmaTest->Result();
-					TEST_ASSERT(result);
-
-					delete dmaTest;
-					}
-
-				break;
-				}
-			case ESkip:
-				if(gVerboseOutput)
-				{
-				RDebug::Printf("Skipping test-case %S, PSL channel %d", &testCase.iTest->Name(), record.iCookie);
-				}
-				break;
-			case EFail:
-				if(gVerboseOutput)
-				{
-				RDebug::Printf("Failling test-case %S, PSL channel %d", &testCase.iTest->Name(), record.iCookie);
-				}
-				TEST_FAULT;
-			default:
-				TEST_FAULT;
-				}
-			//Depending on the value of iConcurrentTest the test runner will either block until the thread has completed or
-			//alternatively run the current test case on the next channel:
-
-			//if the test case has been run on all channels it will then  wait for all threads to complete.
-			}
-
-		const TInt count = concurrentTests.Count();
-		if(count>0)
-			{
-			MultipleTestRun(concurrentTests);
-			for(TInt i=0; i<count; i++)
-				{
-				TBool result = static_cast<CDmaTest*>(concurrentTests[i])->Result();
-				TEST_ASSERT(result);
-				}
-			RDebug::Printf("== End concurrent test run ==");
-			}
-
-		concurrentTests.ResetAndDestroy();
-		}
-	}
-
-void TTestRunner::GetPslCookie()
-	{
-	//Get Sb Channel cookies
-	for(TInt sb_channelcount=0; sb_channelcount<iPslTestInfo.iMaxSbChannels; sb_channelcount++)
-		{
-		iPslCookies.AppendL(iPslTestInfo.iSbChannels[sb_channelcount]);
-		}
-
-	//Get Db Channel cookies
-	for(TInt db_channelcount=0; db_channelcount<iPslTestInfo.iMaxDbChannels; db_channelcount++)
-		{
-		iPslCookies.AppendL(iPslTestInfo.iDbChannels[db_channelcount]);
-		}
-
-	//Get Sg Channel cookies
-	for(TInt sg_channelcount=0; sg_channelcount<iPslTestInfo.iMaxSgChannels; sg_channelcount++)
-		{
-		iPslCookies.AppendL(iPslTestInfo.iSgChannels[sg_channelcount]);
-		}
-	}
-
-void TTestRunner::GenerateChannelRecord()
-	{
-	//for each PSL cookie
-	for(TInt count=0; count<iPslCookies.Count(); count++)
-		{
-		//Get channel cookie
-		const TUint pslCookie = iPslCookies[count];
-		TUint sessionCookie;
-		TInt r = iDmaSession.ChannelOpen(pslCookie, sessionCookie);
-		TEST_ASSERT(r == KErrNone);
-		if(gVerboseOutput)
-		{
-		RDebug::Printf("Channel PSL Cookie[%d]  :0x%08x",count,pslCookie);
-		}
-
-		TChannelRecord dmaChannelRecord;
-		dmaChannelRecord.iCookie = pslCookie;
-
-		//Get Channel Caps
-		r = iDmaSession.ChannelCaps(sessionCookie, dmaChannelRecord.iChannelCaps);
-		TEST_ASSERT(r == KErrNone);
-
-		r = iDmaSession.ChannelClose(sessionCookie);
-		TEST_ASSERT(r == KErrNone);
-
-		//Append array
-		iChannelRecords.AppendL(dmaChannelRecord);
-		}
-	}
-//////////////////////////////////////////////////////////////////////
-// Global test functions and E32Main
-//////////////////////////////////////////////////////////////////////
-
-/**
-Displayed if used supplied no parameters, garbage, or a ? in the parameters
-*/
-void PrintUsage()
-	{
-	test.Printf(_L("*** DMA TEST FRAMEWORK ***\n"));
-	test.Printf(_L("Usage : t_dma2.exe [/option]\n"));
-	test.Printf(_L("  /V  or /VERBOSE    = Control test output\n"));
-	test.Printf(_L("  /S  or /SELFTEST   = Run DMA self test\n"));
-	test.Printf(_L("\n"));
-	}
-
-void ProcessCommandLineL()
-{
-	test.Printf(_L("Process command line arguments\n"));
-
-	TInt cmdLineLength(User::CommandLineLength());
-	HBufC* cmdLine = HBufC::NewMaxLC(cmdLineLength);
-	TPtr cmdLinePtr = cmdLine->Des();
-	User::CommandLine(cmdLinePtr);
-	TBool  tokenParsed(EFalse);
-
-	TLex args(*cmdLine);
-	args.SkipSpace(); // args are separated by spaces
-	
-	// first arg is the exe name, skip it
-	TPtrC cmdToken = args.NextToken();
-	HBufC* tc = HBufC::NewLC(KParameterTextLenMax);
-	*tc = cmdToken;
-	while (tc->Length())
-		{
-		tokenParsed = EFalse;
-		
-		// '/?' help wanted flag '?' or /? parameter
-		if ((0== tc->FindF(_L("?"))) || (0==tc->FindF(_L("/?")))) 
-			{
-			gHelpRequested = ETrue;
-			tokenParsed = ETrue;
-			}	
-		
-		// '/SELFTEST'			
-		if ((0== tc->FindF(KArgSelfTest)) || (0==tc->FindF(KArgSelfTest2))) 
-			{
-			// Run self test
-			test.Printf(_L("Command Line Options:Selftest option specified.\n"));
-			gSelfTest = ETrue;
-			tokenParsed = ETrue;
-			}
-
-		// '/VERBOSE' option	
-		if ((0== tc->FindF(KArgVerboseOutput)) || (0==tc->FindF(KArgVerboseOutput2)))
-			{ 
-			test.Printf(_L("Command Line Options:Verbose option specified.\n"));
-			gVerboseOutput = ETrue;
-			tokenParsed = ETrue;			
-			}
-
-		if (!tokenParsed)
-			{
-			// warn about unparsed parameter
-			test.Printf(_L("Warning: '%lS'??? not parsed\n"), tc);
-			gHelpRequested = ETrue;
-			}
-			
-		// next parameter
-		*tc = args.NextToken();
-		}
-	CleanupStack::PopAndDestroy(tc);
-	CleanupStack::PopAndDestroy(cmdLine);
-}
-
-void RunDMATests()
-	{
-	test.Start(_L("Creating test runner\n"));
-	TTestRunner testRunner;
-
-	test.Next(_L("Add global test cases to test runner\n"));
-	testRunner.AddTestCases(TestArray);
-
-	test.Next(_L("call TTestRunner::RunTests()\n"));
-	testRunner.RunTests();
-
-	test.End();
-	}
-
-TInt E32Main()
-	{
-	__UHEAP_MARK;
-	//__KHEAP_MARK;
-	test.Title();
-
-	gHelpRequested = EFalse;
-	TInt r;
-
-	// Create the new trap-cleanup mechanism
-	CTrapCleanup* cleanup = CTrapCleanup::New();
-
-	if (cleanup == NULL)
-		{
-		return KErrNoMemory;
-		}
-
-	// Process the command line parameters for batch/etc
-	TRAPD(err, ProcessCommandLineL());
-	if (err != KErrNone)
-		{
-		User::Panic(_L("DMA test run memory failure"), KErrNoMemory);
-		}
-	
-	if (gHelpRequested)
-		{
-		PrintUsage();
-		User::Leave(-2);	// nothing to do!
-		}
-	test.Start(_L("Loading test LDD"));
-	//load either the new test ldd, d_dma2.ldd,
-	//or d_dma2_compat.ldd - an ldd linked against
-	//the old DMA framework
-	_LIT(KDma, "D_DMA2.LDD");
-	r = User::LoadLogicalDevice(KDma);
-	const TBool dma2Loaded = ((r == KErrNone) || (r == KErrAlreadyExists));
-
-	_LIT(KDma2Compat, "D_DMA2_COMPAT.LDD");
-	r = User::LoadLogicalDevice(KDma2Compat);
-	const TBool dma2CompatLoaded = ((r == KErrNone) || (r == KErrAlreadyExists));
-
-	if (!(dma2Loaded || dma2CompatLoaded))
-		{
-		//TODO how can we distinguish this case from a platform where
-		//dma is supposed to be supported but the dma test ldd is
-		//missing?
-		test.Printf(_L("DMA not supported - test skipped\n"));
-		return 0;
-		}
-	else if (dma2Loaded && !dma2CompatLoaded)
-		{
-		test.Printf(_L("Loaded %S\n"), &KDma);
-		}
-	else if (!dma2Loaded && dma2CompatLoaded)
-		{
-		test.Printf(_L("Loaded %S\n"), &KDma2Compat);
-		}
-	else
-		{
-		test.Printf(_L("The ROM contains %S and %S - only one should be present\n"), &KDma, &KDma2Compat);
-		TEST_FAULT;
-		}
-	// Turn off evil lazy dll unloading
-	RLoader l;
-	test(l.Connect()==KErrNone);
-	test(l.CancelLazyDllUnload()==KErrNone);
-	RTest::CloseHandleAndWaitForDestruction(l);
-
-	__KHEAP_MARK;
-
-	if (gSelfTest) //Run self tests if specified on command line
-	{
-	SelfTests(); 	
-	}
-
-	ApiTests();
-
-	RunDMATests();
-
-	__KHEAP_MARKEND;
-
-	r = User::FreeLogicalDevice(KTestDmaLddName);
-	test_KErrNone(r);
-	test.End();
-	test.Close();
-
-	delete cleanup;
-
-	//__KHEAP_MARKEND;
-	__UHEAP_MARKEND;
-	return 0;
-	}
--- a/kerneltest/e32test/dmav2/t_dma2.h	Tue May 11 17:28:22 2010 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,719 +0,0 @@
-/*
-* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
-* All rights reserved.
-* This component and the accompanying materials are made available
-* under the terms of "Eclipse Public License v1.0"
-* which accompanies this distribution, and is available
-* at the URL "http://www.eclipse.org/legal/epl-v10.html".
-*
-* Initial Contributors:
-* Nokia Corporation - initial contribution.
-*
-* Contributors:
-*
-* Description:
-*
-*/
-#ifndef __T_DMA2_H__
-#define __T_DMA2_H__
-
-#include "cap_reqs.h"
-#include "test_thread.h"
-#include "d_dma2.h"
-#include <e32std.h>
-
-
-class TTestCase;
-// Global array of test cases
-extern RPointerArray<TTestCase> TestArray;
-
-
-extern TBool gVerboseOutput;   // Verbose output control
-
-
-const TInt KParameterTextLenMax = 80;	// command-line param length
-
-/**
-This function prints out the PSL test Information
-*/
-void Print(const TDmaV2TestInfo& aInfo);
-
-/**
-Runs all framework self tests
-*/
-void SelfTests();
-
-void ApiTests();
-
-class CSingleTransferTest;
-class CIsrRequeTest;
-class CMultiTransferTest;
-
-
-/**
-An interface to a classs that sets up the buffers before a test
-*/
-//TODO both pre and post transfer checks should perhaps derive from an
-//abstract visitor base
-class MPreTransfer
-	{
-public:
-	virtual ~MPreTransfer()
-		{}
-	virtual void Setup(const CSingleTransferTest& aTest) const = 0;
-	virtual void Setup(const CIsrRequeTest& aTest) const = 0;
-	virtual void Setup(const CMultiTransferTest& aTest) const = 0;
-	};
-
-/**
-An interface for a check which takes place at the end of a DMA
-transfer test to verify the transfer was as expected.
-*/
-class MPostTransferCheck
-	{
-public:
-	virtual ~MPostTransferCheck()
-		{}
-	virtual TInt Check(const CSingleTransferTest& aTest) const = 0;
-	virtual TInt Check(const CIsrRequeTest& aTest) const = 0;
-	virtual TInt Check(CMultiTransferTest& aTest) const = 0;
-	};
-
-class TCompare2D : public MPostTransferCheck
-	{
-public:
-	TCompare2D()
-		{}
-
-	virtual TInt Check(const CSingleTransferTest& aTest) const;
-	virtual TInt Check(const CIsrRequeTest& aTest) const;
-	virtual TInt Check(CMultiTransferTest& aTest) const;
-
-	};
-
-class TAlwaysFail : public MPostTransferCheck
-	{
-public:
-	virtual TInt Check(const CSingleTransferTest& /*aTest*/) const
-		{return KErrUnknown;}
-	virtual TInt Check(const CIsrRequeTest&) const
-		{return KErrUnknown;}
-	virtual TInt Check(CMultiTransferTest&) const
-		{return KErrUnknown;}
-	};
-
-class TAlwaysPass : public MPostTransferCheck
-	{
-public:
-	virtual TInt Check(const CSingleTransferTest& /*aTest*/) const
-		{return KErrNone;}
-	virtual TInt Check(const CIsrRequeTest&) const
-		{return KErrNone;}
-	virtual TInt Check(CMultiTransferTest&) const
-		{return KErrNone;}
-	};
-
-/**
-Compare that all the various source buffers of a test match
-its destination buffers
-*/
-class TCompareSrcDst : public MPostTransferCheck
-	{
-public:
-	TCompareSrcDst()
-		{}
-
-	virtual TInt Check(const CSingleTransferTest& aTest) const;
-	virtual TInt Check(const CIsrRequeTest& aTest) const;
-	virtual TInt Check(CMultiTransferTest& aTest) const;
-
-protected:
-	TInt Check(const TIsrRequeArgsSet& aRequeueArgSet, TUint8* aChunkBase, const TDmaTransferArgs& aTferArgs) const;
-	TInt Check(const TIsrRequeArgs& aRequeueArgs) const;
-	TInt Check(const TDmaTransferArgs& aTransferArgs, TUint8* aChunkBase) const;
-	};
-
-/**
-Base class for all DMA tests
-*/
-class CDmaTest : public CTest
-	{
-public:
-	CDmaTest(const TDesC& aName, TInt aIterations, const MPreTransfer* aPreTransfer, const MPostTransferCheck* aPostTransfer)
-		: CTest(aName, aIterations), iPreTransfer(aPreTransfer), iPostTransferCheck(aPostTransfer)
-		{}
-
-	void OpenDmaSession();
-	void CloseDmaSession();
-
-	virtual void PrintTestInfo() const;
-	virtual TBool Result() = 0;
-
-	const RChunk& Chunk() const
-		{return iChunk;}
-
-	/**
-	Tells the test which DMA channel it should run on
-	*/
-	void SetChannelCookie(TUint32 aCookie)
-		{iChannelCookie = aCookie;}
-
-	virtual void PreTransferSetup() =0;
-	virtual TInt DoPostTransferCheck() =0;
-protected:
-	RDmaSession iDmaSession;
-	RChunk iChunk;
-
-	/**
-	Identifies the channel to open (as understood by a DMA PSL)
-	*/
-	TUint iChannelCookie;
-	const MPreTransfer* iPreTransfer;
-
-	const MPostTransferCheck* iPostTransferCheck; //!< Some check to be run after the transfer
-	};
-
-/**
-Holds return codes for the various functions which must be called
-to create, fragment, and queue a DMA request
-*/
-struct TRequestResults
-	{
-	TRequestResults
-		(
-		TInt aCreate = KErrNone,
-		TInt aFragmentCount = 0,
-		TInt aFragmentationResult = KErrNone,
-		TInt aQueueResult = KErrNone
-		)
-		:iCreate(aCreate), iFragmentCount(aFragmentCount), iFragmentationResult(aFragmentationResult), iQueueResult(aQueueResult)
-		{}
-
-	/**
-	Constructs with error results
-	*/
-	TRequestResults(TFalse)
-		:iCreate(KErrUnknown), iFragmentCount(0), iFragmentationResult(KErrUnknown), iQueueResult(KErrUnknown)
-		{}
-
-	inline TRequestResults& CreationResult(TInt aErrorCode) {iCreate = aErrorCode; return *this;}
-	inline TRequestResults& FragmentCount(TInt aCount) {iFragmentCount = aCount; return *this;}
-	inline TRequestResults& FragmentationResult(TInt aErrorCode) {iFragmentationResult = aErrorCode; return *this;}
-	inline TRequestResults& QueueResult(TInt aErrorCode) {iQueueResult = aErrorCode; return *this;}
-
-	TInt iCreate;
-	TInt iFragmentCount; //!< 0 means any result permitted
-	TInt iFragmentationResult;
-	TInt iQueueResult;
-	};
-
-/**
-Holds all the results for a DMA CSingleTransferTest
-*/
-struct TResultSet
-	{
-	/**
-	No errors expected
-	*/
-	TResultSet(TInt aChannelOpenResult = KErrNone,
-			const TRequestResults aRequestResults = TRequestResults(),
-			TInt aPostTransferCheck = KErrNone,
-			const TCallbackRecord aCallbackRecord = TCallbackRecord(TCallbackRecord::EThread,1)
-			)
-		:
-		iChannelOpenResult(aChannelOpenResult),
-		iRequestResult(aRequestResults),
-		iPostTransferCheck(aPostTransferCheck),
-		iCallbackRecord(aCallbackRecord)
-		{}
-	
-	explicit TResultSet(const TCallbackRecord& aRecord)
-		:iChannelOpenResult(KErrNone),
-		 iRequestResult(),
-		 iPostTransferCheck(KErrNone),
-		 iCallbackRecord(aRecord)
-		{}
-
-	/**
-	Errors expected
-	*/
-	TResultSet(TFalse)
-		:iChannelOpenResult(KErrUnknown), 
-		iRequestResult(EFalse),
-		iPostTransferCheck(KErrUnknown),
-		iCallbackRecord(TCallbackRecord::Empty())
-		{}		
-	
-	void Print() const;
-	TBool operator == (const TResultSet& aOther) const;
-
-	/** Set channel opening result */
-	TResultSet& ChannelOpenResult(TInt aResult) {iChannelOpenResult = aResult; return *this;}
-	TResultSet& PostTransferResult(TInt aResult) {iPostTransferCheck = aResult; return *this;}
-	/** Set request results */
-	TResultSet& RequestResult(const TRequestResults& aResults) {iRequestResult = aResults; return *this;}
-	/** Set Callback record */
-	TResultSet& CallbackRecord(const TCallbackRecord& aCallbackRecord) {iCallbackRecord = aCallbackRecord; return *this;}
-
-	TInt iChannelOpenResult;
-	TRequestResults iRequestResult;
-	TInt iPostTransferCheck;
-	TCallbackRecord iCallbackRecord;
-	};
-
-/**
-Fills each source buffer with an increasing value and clears each destination
-*/
-class TPreTransferIncrBytes : public MPreTransfer
-	{
-public:
-	TPreTransferIncrBytes()
-		{}
-
-	virtual void Setup(const CSingleTransferTest& aTest) const;
-	virtual void Setup(const CIsrRequeTest& aTest) const;
-	virtual void Setup(const CMultiTransferTest& aTest) const;
-protected:
-	virtual void Setup(const TAddressParms& aParams) const;
-	TBool CheckBuffers(const CIsrRequeTest& aTest) const;
-	TBool CheckBuffers(const RArray<const TAddressParms> aTransferParams) const;
-	};
-
-const TPreTransferIncrBytes KPreTransferIncrBytes;
-const TCompareSrcDst KCompareSrcDst;
-const TCompare2D KCompare2D;
-
-
-/**
-Iterates over the bytes in buffer, in the order
-the supllied DMA config would access them
-*/
-class TTransferIter
-	{
-public:
-	TTransferIter()
-		:iCfg(NULL), iPtr(NULL)
-		{}
-
-	TTransferIter(const TDmaTransferConfig& aCfg, TUint8* aChunkBase=NULL)
-		:iElem(0), iFrame(0), iCfg(&aCfg), iChunkBase(aChunkBase), iPtr(Start()), iBytes(0)
-		{}
-
-	void operator++ ();
-	TUint8& operator* ()
-		{
-		Invariant();
-		return *iPtr;
-		}
-
-	TBool operator!= (const TTransferIter& aOther)
-		{
-		return (iPtr != aOther.iPtr);
-		}
-
-	static void SelfTest();
-private:
-	TUint8* Start() const
-		{
-		return iChunkBase + iCfg->iAddr;
-		}
-
-	void Invariant() const;
-
-	TUint iElem; //!< The current element
-	TUint iFrame; //!< The current frame
-
-	const TDmaTransferConfig* const iCfg;
-	TUint8* iChunkBase;
-
-	TUint8* iPtr; //<! Pointer to the current byte
-
-	TInt iBytes; //!< The number of bytes traversed
-	};
-
-/**
-Performs a single DMA transfer using the member TDmaTransferArgs on
-one channel. At each stage of the transfer results are recorded in a
-TResultSet struct: at the end these are compared with a set of expected
-results.
-*/
-class CSingleTransferTest : public CDmaTest
-	{
-public:
-	CSingleTransferTest(
-			const TDesC& aName, TInt aIterations,
-			const TDmaTransferArgs& aArgs,
-			const TResultSet& aExpected,
-			TUint aMaxFragmentSize = 0,
-			const MPostTransferCheck* aPostTferChk = &KCompareSrcDst,
-			const MPreTransfer* aPreTfer = &KPreTransferIncrBytes
-			)
-		: CDmaTest(aName, aIterations, aPreTfer, aPostTferChk),
-		iTransferArgs(aArgs),iExpected(aExpected),iActual(EFalse),
-		iUseNewRequest(ETrue),
-		iUseNewFragment(ETrue),
-		iMaxFragmentSize(aMaxFragmentSize)
-		{}
-
-	/**
-	Perform each stage of trasnfer
-	*/
-	virtual void RunTest();
-	virtual void PrintTestType() const;
-
-	virtual CTest* Clone() const {return new CSingleTransferTest(*this);}
-
-	/**
-	Compares the actual vs the exepected results and reports
-	of the test passed
-	@return ETrue for a pass, EFalse for a fail
-	 */
-	virtual TBool Result();
-
-	/**
-	An accessor function for the object's TDmaTransferArgs
-	*/
-	const TDmaTransferArgs& TransferArgs() const
-		{return iTransferArgs;}
-
-	// The below methods are setters, which may be chained together
-	// ie. The Named Parameter Idiom
-	// @see http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.18
-	inline CSingleTransferTest& UseNewRequest(TBool aFlag) {iUseNewRequest=aFlag; return *this;}
-	inline CSingleTransferTest& UseNewFragment(TBool aFlag) {iUseNewFragment=aFlag; return *this;}
-	inline CSingleTransferTest& UseNewDmaApi(TBool aFlag) {UseNewRequest(aFlag); UseNewFragment(aFlag); return *this;}
-
-protected:
-	virtual void OpenChannel();
-	virtual void PreTransferSetup();
-	virtual void CreateDmaRequest();
-	virtual void Fragment();
-	virtual void Queue();
-	virtual void PostTransferCheck();
-	virtual TInt DoPostTransferCheck();
-	virtual void FreeRequest();
-	virtual void CloseChannel();
-
-protected:
-	/**
-	A handle to kernel side TDmaChannel object received after a channel is opened.
-	*/
-	TUint iChannelSessionCookie;
-	/**
-	A handle to kernel side DDmaRequest object.
-	*/
-	TUint iRequestSessionCookie;
-
-	const TDmaTransferArgs& iTransferArgs;
-
-	/**
-	Expected transfer results
-	*/
-	TResultSet iExpected;
-
-	/**
-	Filled with actual transfer results
-	*/
-	TResultSet iActual;
-
-	TBool iUseNewRequest; //!< If true then CSingleTransferTest will create a DDmaRequest with the v2 ctor
-	TBool iUseNewFragment; //!< If true then CSingleTransferTest will use v2 Fragment API
-	const TUint iMaxFragmentSize;
-	};
-
-/**
-This class will be used for tests which benchmark certain DMA operations
-*/
-class CDmaBenchmark : public CSingleTransferTest
-	{
-public:
-	CDmaBenchmark(const TDesC& aName, TInt aIterations, const TResultSet& aExpectedResults, const TDmaTransferArgs& aTransferArgs, TUint aMaxFragmentSize);
-	~CDmaBenchmark();
-
-	virtual TBool Result();
-
-	static void SelfTest();
-
-protected:
-	/**
-	@return The mean average of the result array
-	*/
-	TUint64 MeanResult();
-
-	//TODO must be included within copy ctor or all instances will
-	//share on result set!
-	RArray<TUint64> iResultArray;
-
-	};
-
-/**
-Fragments requests (only) and records duration
-TODO make sure we are using old style DDmaRequest
-*/
-class CDmaBmFragmentation : public CDmaBenchmark
-	{
-public:
-	CDmaBmFragmentation(const TDesC& aName, TInt aIterations, const TDmaTransferArgs& aTransferArgs, TUint aMaxFragmentSize);
-	virtual CTest* Clone() const {return new CDmaBmFragmentation(*this);}
-	virtual TInt DoPostTransferCheck()
-		{TEST_FAULT; return KErrNotSupported;}
-
-	virtual void RunTest();
-	virtual void PrintTestType() const;
-
-protected:
-	void Fragment();
-	static const TResultSet ExpectedResults;
-	};
-
-/**
-Performs a transfer using an old style DDmaRequest and
-records the duration
-*/
-class CDmaBmTransfer : public CDmaBenchmark
-	{
-public:
-	CDmaBmTransfer(const TDesC& aName, TInt aIterations, const TDmaTransferArgs& aTransferArgs, TUint aMaxFragmentSize);
-	virtual CTest* Clone() const {return new CDmaBmTransfer(*this);}
-	virtual TInt DoPostTransferCheck()
-		{TEST_FAULT; return KErrNotSupported;}
-
-	virtual void RunTest();
-	virtual void PrintTestType() const;
-
-	inline CDmaBmTransfer& UseNewDmaApi(TBool aFlag) {CSingleTransferTest::UseNewDmaApi(aFlag); return *this;}
-	inline CDmaBmTransfer& ExpectedResults(const TResultSet& aArgs) {iExpected=aArgs; return *this;}
-protected:
-	void Queue();
-	};
-
-
-
-/**
-Will create and queue multiple requests
-
-Unlike CSingleTransferTest the class does not permit the use of TResultSet to
-define expected results (for neagative testing)
-*/
-class CMultiTransferTest : public CDmaTest
-	{
-public:
-	CMultiTransferTest(const TDesC& aName, TInt aIterations, const TDmaTransferArgs* aTransferArgs, const TResultSet* aResultSets, TInt aCount);
-	CMultiTransferTest(const CMultiTransferTest& aOther);
-	virtual ~CMultiTransferTest();
-	virtual CTest* Clone() const {return new CMultiTransferTest(*this);}
-
-	virtual TBool Result();
-	virtual void RunTest();
-	virtual void PrintTestType() const;
-
-	inline CMultiTransferTest& PauseWhileQueuing() {iPauseWhileQueuing = ETrue; return *this;}
-	inline CMultiTransferTest& SetPreTransferTest(const MPreTransfer* aPreTfer) {iPreTransfer = aPreTfer; return *this;}
-	inline CMultiTransferTest& SetPostTransferTest(const MPostTransferCheck* aPostTfer) {iPostTransferCheck = aPostTfer; return *this;}
-
-	const TDmaTransferArgs& TransferArgs(TInt aIndex) const;
-	inline TInt TransferCount() const {return iTransferArgsCount;}
-
-	void SetPostTransferResult(TInt aIndex, TInt aErrorCode);
-protected:
-	void OpenChannel();
-	TInt CloseChannel();
-	void CreateDmaRequests();
-	void Fragment();
-	void QueueRequests();
-
-	virtual void PreTransferSetup();
-	virtual TInt DoPostTransferCheck();
-
-	TBool Result(TInt aTransfer);
-
-	const TDmaTransferArgs* const iTransferArgs; //pointer to an array of transfer args
-	const TInt iTransferArgsCount;
-
-
-	TBool iNewDmaApi; //!< If true then CMultiTransferTest will use new style API
-
-	/**
-	A handle to kernel side TDmaChannel object received after a channel is opened.
-	*/
-	TUint iChannelSessionCookie;
-	RArray<TUint> iRequestCookies;
-
-	const TResultSet* const iExpectedArray; // array will be of length iTransferArgsCount
-	RArray<TResultSet> iActualResults;
-
-	/**
-	If set, the test will pause the channel before queuing requests, and
-	resume once they are all queued
-	*/
-	TBool iPauseWhileQueuing;
-	};
-
-/**
-Used for testing TDmaChannel::IsrRedoRequest
-
-Extends CSingle transfer by adding the capability to queue with
-additonal transfer parameters (TIsrRequeArgs) which are passed
-to IsrRedoRequest in ISR callback
-*/
-class CIsrRequeTest : public CSingleTransferTest
-	{
-public:
-	CIsrRequeTest(const TDesC& aName, TInt aIterations, const TDmaTransferArgs& aArgs,
-			TIsrRequeArgs* aRequeueArgs, TInt aCount,
-			const TResultSet& aExpected, const MPreTransfer* aPreTfer,
-			const MPostTransferCheck* aPostTferChk, TUint aMaxFragmentSize=0);
-
-	virtual void PrintTestType() const;
-
-	virtual void Queue();
-
-	/**
-	Compares the actual vs the exepected results and reports
-	of the test passed
-	@return ETrue for a pass, EFalse for a fail
-	 */
-	//virtual TBool Result();
-
-
-	virtual CTest* Clone() const {return new CIsrRequeTest(*this);}
-
-	const TIsrRequeArgsSet& GetRequeueArgs() const
-		{return iRequeArgSet;}
-
-
-protected:
-	virtual TInt DoPostTransferCheck();
-	virtual void PreTransferSetup();
-
-	TIsrRequeArgsSet iRequeArgSet;
-	};
-
-/**
-A channel record collects DMA channel capabilities and other PSL information
-before running tests.
-*/
-class TChannelRecord
-	{
-public:
-	TChannelRecord(){}
-	~TChannelRecord(){}
-
-	/**
-	DMA Channel Cookie
-	*/
-	TUint   iCookie;
-
-	/**
-	DMA Channel Capabilities
-	*/
-	TDmacTestCaps iChannelCaps;
-	};
-
-/**
-A test case collects together a DMA test (CDmaTest), its hardware prerequisites,
-and other information about how the test should be run.
-*/
-class TTestCase
-	{
-public:
-	//TODO it might be better to group sets of TDmaCapability
-	//into their own class eg. TDmaCapSet.
-	TTestCase(CDmaTest* aTest,
-           TBool aConcurrent = EFalse,
-		   const TDmaCapability = TDmaCapability(),
-		   const TDmaCapability = TDmaCapability(),
-		   const TDmaCapability = TDmaCapability(),
-		   const TDmaCapability = TDmaCapability(),
-		   const TDmaCapability = TDmaCapability()
-		   );
-
-	static void SelfTest();
-
-	/**
-	Compares the requirements held in the class
-	against those described in aChannelCaps and makes a decision
-	as to whether this test case should be run, skipped, or failed.
-	*/
-	TResult TestCaseValid(const SDmacCaps& aChannelCaps) const;
-	TResult TestCaseValid(const TDmacTestCaps& aChannelCaps) const;
-
-	enum {KMaxChannelCaps=5};
-	TDmaCapability	iChannelCaps[KMaxChannelCaps];
-	TUint iChannelType;
-	TInt iTimeout;
-	CDmaTest* iTest;
-	TBool iConcurrentTest;
-	TBool iDmaV2Only; //!< If true then this test cannot be run on DMA v1 framework
-	};
-
-/**
-A TestRunner manages the whole testing process.Before running any test cases it will open its own RDmaSession 
-handle, not associated with a DMA channel, so that it can recover the TDmaTestInfo object (as used by the 
-existing DMA framework) which says what channels are available to be tested.It will use TTestThread objects 
-to run tests in new threads.TTestThread contains a number of useful features such as waiting for thread exit 
-and accepting a TFunctor object to be run in a new thread. 
-*/
-class TTestRunner
-{
-public:
-	TTestRunner();
-	~TTestRunner();
-
-	/**
-	This function will populate TTestRunner with an array of test cases which 
-	would be a collection of DMA test,its hardware prerequisites,and other 
-	information about how the test	
-
-	@aTTestCases on return, this contains an the DMA test cases 
-	*/
-	void AddTestCases(RPointerArray<TTestCase>& aTTestCases);
-
-	/**
-	This will iterate over all test cases held by the test runner and
-	for each one will judge which DMA channels it can be run on, running
-	the test if possible.
-	*/
-	void RunTests();
-
-private:
-	/**
-	This functions retrieves the PSL cookies from all the DMA channels
-	and stores them in a single array.	It will use information from 
-	the PslTestInfo.
-	*/
-	void GetPslCookie();
-
-	/**
-	This function will generate the DMA channel records.i.e channel cookies,Caps.
-	*/
-	void GenerateChannelRecord();
-
-	/**
-	Holds the PslTestInfo
-	*/	
-	TDmaV2TestInfo iPslTestInfo;
-
-	/**
-	A handle to RDmaSession
-	*/
-	RDmaSession iDmaSession;
-	
-	/**
-	Array of DMA test cases 
-	*/
-	RPointerArray<TTestCase> iTestCases; 
-	
-	/**
-	Array of DMA channel records,channel capabilities and other PSL information
-	*/
-	RArray<TChannelRecord> iChannelRecords; 	
-
-	/**
-	Array of DMA channel cookies
-	*/
-	RArray<TUint> iPslCookies;
-};
-
-
-#endif // #ifndef __T_DMA2_H__
--- a/kerneltest/e32test/dmav2/test_cases.cpp	Tue May 11 17:28:22 2010 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1352 +0,0 @@
-/*
-* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
-* All rights reserved.
-* This component and the accompanying materials are made available
-* under the terms of "Eclipse Public License v1.0"
-* which accompanies this distribution, and is available
-* at the URL "http://www.eclipse.org/legal/epl-v10.html".
-*
-* Initial Contributors:
-* Nokia Corporation - initial contribution.
-*
-* Contributors:
-*
-* Description:
-* This file contains statically defined test cases, a pointer to each
-* new test case should be entered in StaticTestArray
-*
-*/
-
-#include "t_dma2.h"
-#include "cap_reqs.h"
-
-const TCallbackRecord threadCallback(TCallbackRecord::EThread,1);
-const TCallbackRecord isrCallback(TCallbackRecord::EIsr,1);
-
-const TInt size = 128 * KKilo;
-//--------------------------------------------------------------------------------------------
-//! @SYMTestCaseID      KBASE-DMA-2560
-//! @SYMTestType        CIT
-//! @SYMPREQ            REQ
-//! @SYMTestCaseDesc    Simple DMA transfer test using CSingleTransferTest and New DMA APIs
-//!
-//! @SYMTestActions     
-//!						1.
-//!						2.	
-//!
-//!
-//! @SYMTestExpectedResults 
-//!						1.  
-//!						2.		
-//!							
-//!
-//! @SYMTestPriority        High
-//! @SYMTestStatus          Implemented
-//----------------------------------------------------------------------------------------------
-namespace Simple_1
-	{
-	TDmaTransferArgs transferArgs(0, size, size, KDmaMemAddr);
-
-	const TResultSet expectedResults(threadCallback);
-
-	CSingleTransferTest simpleTest(_L("Simple Test - New DMA APIs"), 1, transferArgs, expectedResults);
-
-	TTestCase testCase(&simpleTest, EFalse, capAboveV1);
-	TTestCase testCaseConcurrent(&simpleTest, ETrue, capAboveV1);
-	}
-
-//----------------------------------------------------------------------------------------------
-//! @SYMTestCaseID      KBASE-DMA-2561
-//! @SYMTestType        CIT
-//! @SYMPREQ            REQ
-//! @SYMTestCaseDesc    Simple DMA transfer test using CSingleTransferTest and OLD DMA APIs
-//!
-//! @SYMTestActions     
-//!						1.
-//!						2.	
-//!
-//!
-//! @SYMTestExpectedResults 
-//!						1.  
-//!						2.						
-//!							
-//!
-//! @SYMTestPriority        High
-//! @SYMTestStatus          Implemented
-//----------------------------------------------------------------------------------------------
-namespace Simple_2
-	{
-	TDmaTransferArgs transferArgs(0, size, size, KDmaMemAddr);
-
-	const TResultSet expectedResults(threadCallback);
-
-	CSingleTransferTest simpleTest = CSingleTransferTest(_L("Simple Test - Old DMA APIs"), 1, transferArgs, expectedResults, 0).
-		UseNewDmaApi(EFalse);
-
-	TTestCase testCase(&simpleTest, EFalse);
-	TTestCase testCaseConcurrent(&simpleTest, ETrue);
-	}
-
-//----------------------------------------------------------------------------------------------
-//! @SYMTestCaseID      KBASE-DMA-2573
-//! @SYMTestType        CIT
-//! @SYMPREQ            REQ
-//! @SYMTestCaseDesc    DMA ISR Callback test (Isr Callback - use old request Ctor)
-//!
-//! @SYMTestActions     
-//!						1.
-//!						2.	
-//!
-//!
-//! @SYMTestExpectedResults 
-//!						1.  
-//!						2.		
-//!							
-//!
-//! @SYMTestPriority        High
-//! @SYMTestStatus          Implemented
-//----------------------------------------------------------------------------------------------
-namespace Callback
-	{
-	TDmaTransferArgs transferArgs(0, size, size, KDmaMemAddr, KDmaSyncAuto, KDmaRequestCallbackFromIsr);
-
-	const TResultSet expectedResults(isrCallback);
-
-	CSingleTransferTest isrTest(_L("Isr Callback"), 1, transferArgs, expectedResults);
-	TTestCase testCase(&isrTest, EFalse, capAboveV1);
-
-
-	const TRequestResults fragmentFails = TRequestResults().
-		FragmentationResult(KErrArgument).
-		QueueResult(KErrUnknown);
-
-	const TResultSet expectedResultsFail = TResultSet(EFalse).
-		ChannelOpenResult(KErrNone).
-		RequestResult(fragmentFails).
-		PostTransferResult(1); // PostTransferResult of 1 means buffers don't match
-
-	CSingleTransferTest isrTestOldRequest = CSingleTransferTest(_L("Isr Callback - use old request Ctor"), 1, transferArgs, expectedResultsFail)
-		.UseNewRequest(EFalse);
-	TTestCase testCaseOldRequest(&isrTestOldRequest, EFalse, capAboveV1);
-	}
-
-//----------------------------------------------------------------------------------------------
-//! @SYMTestCaseID      KBASE-DMA-2574,KBASE-DMA-2575
-//! @SYMTestType        CIT
-//! @SYMPREQ            REQ
-//! @SYMTestCaseDesc    DMA ISR Reque test
-//!
-//! @SYMTestActions     
-//!						1.
-//!						2.	
-//!
-//!
-//! @SYMTestExpectedResults 
-//!						1.  
-//!						2.		
-//!							
-//!
-//! @SYMTestPriority        High
-//! @SYMTestStatus          Implemented
-//----------------------------------------------------------------------------------------------
-namespace ISR_Reque
-	{
-	const TInt size = 4 * KKilo;
-	TDmaTransferArgs tferArgs(0, 2*size, size, KDmaMemAddr, KDmaSyncAuto, KDmaRequestCallbackFromIsr);
-
-	const TRequestResults requestResult(KErrNone, 1); // request must be in a single fragment
-
-	namespace endOnIsrCb
-		{
-		TIsrRequeArgs requeArgs[] = {
-			TIsrRequeArgs(),
-			TIsrRequeArgs(size,3*size,size,0, ETrue),
-			TIsrRequeArgs(size,4*size,size,0, ETrue),
-			TIsrRequeArgs(0,5*size,size,0, ETrue),
-		};
-		const TInt count = ARRAY_LENGTH(requeArgs);
-
-		// we expect a cb for each requeue + 1 for the original
-		// transfer
-		const TCallbackRecord callbackRecord = TCallbackRecord(TCallbackRecord::EIsr, count + 1).IsrRedoResult(KErrNone);
-		const TResultSet expected(KErrNone, requestResult, KErrNone, callbackRecord);
-
-		TTestCase testCase(new (ELeave) CIsrRequeTest(_L("4 Requeues - end on isr cb"), 1, tferArgs, requeArgs, count, expected, &KPreTransferIncrBytes, &KCompareSrcDst), ETrue, capAboveV1);
-		}
-
-	namespace endOnThreadCb
-		{
-		TIsrRequeArgs requeArgs[] = {
-			TIsrRequeArgs(),
-			TIsrRequeArgs(size,3*size,size,0, ETrue),
-			TIsrRequeArgs(size,4*size,size,0, ETrue),
-			TIsrRequeArgs(0,5*size,size,0, EFalse),
-		};
-		const TInt count = ARRAY_LENGTH(requeArgs);
-
-		const TCallbackRecord callbackRecord = TCallbackRecord(TCallbackRecord::EThread, count + 1).IsrRedoResult(KErrNone);
-		const TResultSet expected(KErrNone, requestResult, KErrNone, callbackRecord);
-
-		TTestCase testCase(new (ELeave) CIsrRequeTest(_L("4 Requeues - end on thread cb"), 1, tferArgs, requeArgs, count, expected, &KPreTransferIncrBytes, &KCompareSrcDst), ETrue, capAboveV1);
-		}
-
-	namespace changeSize
-		{
-		TIsrRequeArgs requeArgs[] = {
-			TIsrRequeArgs(3*size,5*size,2*size,0, EFalse),
-		};
-		const TInt count = ARRAY_LENGTH(requeArgs);
-
-		const TCallbackRecord callbackRecord = TCallbackRecord(TCallbackRecord::EThread, count + 1).IsrRedoResult(KErrNone);
-		const TResultSet expected(KErrNone, requestResult, KErrNone, callbackRecord);
-
-		TTestCase testCase(new (ELeave) CIsrRequeTest(_L("1 Requeues - change transfer size"), 1, tferArgs, requeArgs, count, expected, &KPreTransferIncrBytes, &KCompareSrcDst), ETrue, capAboveV1);
-		}
-
-	namespace endOnRedo
-		{
-		// TODO have made this bigger than 4k so that we don't miss the second interrupt when tracing enabled
-		// this indicates the PSL's interrupt handler misses an interrupt if it occurs during the interrupt.
-		const TInt size = 0x10000;
-		TDmaTransferArgs tferArgs(0, 2*size, size, KDmaMemAddr, KDmaSyncAuto, KDmaRequestCallbackFromIsr);
-
-		TIsrRequeArgs requeArgs[] = {
-			TIsrRequeArgs(3*size,5*size,2*size,0, ETrue),
-			TIsrRequeArgs() //repeat the previous transfer
-		};
-		const TInt count = ARRAY_LENGTH(requeArgs);
-
-		const TCallbackRecord callbackRecord = TCallbackRecord(TCallbackRecord::EIsr, count + 1).IsrRedoResult(KErrNone);
-		const TResultSet expected(KErrNone, requestResult, KErrNone, callbackRecord);
-
-		TTestCase testCase(new (ELeave) CIsrRequeTest(_L("2 Requeues - Isr redo request repeated"), 1, tferArgs, requeArgs, count, expected, &KPreTransferIncrBytes, &KCompareSrcDst), EFalse, capAboveV1);
-		}
-
-	namespace invalidAddresses
-		{
-		TIsrRequeArgs requeArgs[] = {
-			TIsrRequeArgs(size, size)
-		};
-		const TInt count = ARRAY_LENGTH(requeArgs);
-
-		const TCallbackRecord callbackRecord = TCallbackRecord(TCallbackRecord::EIsr, 1).IsrRedoResult(KErrArgument);
-		const TResultSet expected(KErrNone, requestResult, KErrUnknown, callbackRecord);
-
-		// pre and post test would fail because of bad requeue parameters
-		TTestCase testCase(new (ELeave) CIsrRequeTest(_L("Requeue with matching addresses"), 1, tferArgs, requeArgs, count, expected, NULL, NULL), ETrue, capAboveV1);
-		}
-
-	namespace multipleFragments
-		{
-		TIsrRequeArgs requeArgs[] = {
-			TIsrRequeArgs()
-		};
-		const TInt count = ARRAY_LENGTH(requeArgs);
-
-		const TCallbackRecord callbackRecord = TCallbackRecord(TCallbackRecord::EThread, count + 1).IsrRedoResult(KErrNone);
-
-		TRequestResults results2Fragments = TRequestResults(requestResult).FragmentCount(2);
-		const TResultSet expected(KErrNone, results2Fragments, KErrNone, callbackRecord);
-
-		TTestCase testCase(new (ELeave) CIsrRequeTest(_L("Attempt to Requeue 2 fragment request"), 1, tferArgs, requeArgs, count, expected, &KPreTransferIncrBytes, &KCompareSrcDst, size/2), ETrue, capAboveV1);
-
-		}
-	}
-
-//----------------------------------------------------------------------------------------------
-//! @SYMTestCaseID      PBASE-DMA-FUNC-xxx
-//! @SYMTestType        CIT
-//! @SYMPREQ            REQ
-//! @SYMTestCaseDesc    DMA Multiple transfer test
-//! @SYMTestActions     
-//!						1.
-//!						2.	
-//!
-//!
-//! @SYMTestExpectedResults 
-//!						1.  
-//!						2.		
-//!							
-//!
-//! @SYMTestPriority        High
-//! @SYMTestStatus          Implemented
-//----------------------------------------------------------------------------------------------
-namespace Multipart
-	{
-	// need long transfer, to try and force adjacent
-	// requests to be concatinated
-	const TInt size = 2 * KMega;
-	const TDmaTransferArgs transferArgArray[] = {
-		TDmaTransferArgs(0, size, size, KDmaMemAddr),
-		TDmaTransferArgs(size, 2 * size, size, KDmaMemAddr)
-	};
-
-	const TResultSet expected[] =
-		{
-		TResultSet(),
-		TResultSet()
-		};
-	const TResultSet expectedResults(isrCallback);
-
-	CMultiTransferTest multipart =
-		CMultiTransferTest(_L("Sg request concatination"), 1, transferArgArray, expected, ARRAY_LENGTH(transferArgArray))
-			.SetPreTransferTest(&KPreTransferIncrBytes)
-			.SetPostTransferTest(&KCompareSrcDst);
-
-	TTestCase testCase(&multipart, EFalse, hwDesWanted_skip);
-	}
-
-//----------------------------------------------------------------------------------------------
-//! @SYMTestCaseID      KBASE-DMA-2580
-//! @SYMTestType        CIT
-//! @SYMPREQ            REQ
-//! @SYMTestCaseDesc    These tests attempt to queue ISR cb requests while the queue is not 
-//!						empty and queing normal requests when an ISR cb is pending
-//! @SYMTestActions     
-//!						1.
-//!						2.	
-//!
-//!
-//! @SYMTestExpectedResults 
-//!						1.  
-//!						2.		
-//!							
-//!
-//! @SYMTestPriority        High
-//! @SYMTestStatus          Implemented
-//----------------------------------------------------------------------------------------------
-namespace IsrAndDfc
-	{
-	// need long transfer, so that 1st request is still queued
-	// when the second one is queued
-	// TODO pause is the better way to ensure this
-	//const TInt size = 2 * KMega;
-	//TODO have changed size to ensure that the first isr callback request in IsrBeforeDfc
-	//will only have one fragment
-	const TInt size = 0x40000;
-	TDmaTransferArgs dfcTransfer(0, size, size, KDmaMemAddr);
-	TDmaTransferArgs isrTransfer(2*size, 3*size, size, KDmaMemAddr, KDmaSyncAuto, KDmaRequestCallbackFromIsr);
-
-	const TResultSet success = TResultSet();
-	TResultSet queueFailure = TResultSet().
-			RequestResult(TRequestResults().QueueResult(KErrGeneral)).
-			CallbackRecord(TCallbackRecord::Empty()).
-			PostTransferResult(1);
-
-	namespace DfcBeforeIsr
-		{
-		const TDmaTransferArgs transferArgArray[] = {
-			dfcTransfer,
-			isrTransfer
-		};
-
-		const TResultSet expected[] =
-			{
-			success,
-			queueFailure
-			};
-		CMultiTransferTest dfcBeforeIsr =
-			CMultiTransferTest(_L("DFC cb req before ISR cb req "), 1, transferArgArray, expected, ARRAY_LENGTH(transferArgArray))
-				.SetPreTransferTest(&KPreTransferIncrBytes)
-				.SetPostTransferTest(&KCompareSrcDst);
-		TTestCase testCase(&dfcBeforeIsr, EFalse, hwDesWanted_skip);
-		}
-
-	namespace IsrBeforeDfc
-		{
-		const TDmaTransferArgs transferArgArray[] = {
-			isrTransfer,
-			dfcTransfer
-		};
-
-		TResultSet isrSuccess = TResultSet(success).CallbackRecord(isrCallback);
-		const TResultSet expected[] =
-			{
-			isrSuccess,
-			queueFailure
-			};
-		CMultiTransferTest dfcBeforeIsr =
-			CMultiTransferTest(_L("ISR cb req before DFC cb req "), 1, transferArgArray, expected, ARRAY_LENGTH(transferArgArray))
-				.SetPreTransferTest(&KPreTransferIncrBytes)
-				.SetPostTransferTest(&KCompareSrcDst);
-		TTestCase testCase(&dfcBeforeIsr, EFalse, hwDesWanted_skip);
-		}
-
-	}
-
-//----------------------------------------------------------------------------------------------
-//! @SYMTestCaseID      PBASE-DMA-FUNC-xxx
-//! @SYMTestType        CIT
-//! @SYMPREQ            REQ
-//! @SYMTestCaseDesc    DMA 2D transfer test
-//!
-//! @SYMTestActions     
-//!						1.
-//!						2.	
-//!
-//!
-//! @SYMTestExpectedResults 
-//!						1.  
-//!						2.		
-//!							
-//!
-//! @SYMTestPriority        High
-//! @SYMTestStatus          Implemented
-//----------------------------------------------------------------------------------------------
-namespace _2D_Test
-	{
-	// Image @ 0x0 with 640x480 pixels and 24 bits/pixel.
-
-	TDmaTransferConfig src(
-		0, /*iAddr*/
-		3, /*iElementSize*/
-		6, /*iElementsPerFrame*/
-		4, /*iFramesPerTransfer*/
-		0, /*iElementSkip*/
-		0, /*iFrameSkip*/
-		KDmaMemAddr /*iFlags*/
-		);
-
-	TDmaTransferConfig dst(
-		0x708000, /*iAddr*/
-		3, /*iElementSize*/
-		640, /*iElementsPerFrame*/
-		480, /*iFramesPerTransfer*/
-		1437, /*iElementSkip*/
-		-920166, /*iFrameSkip*/
-		KDmaMemAddr /*iFlags*/
-		);
-
-	TDmaTransferArgs transferArgs2D(src, dst);
-
-	TResultSet expectedResults; //all KErrNone
-
-	//source buffer is currently filled with increasing values
-	//instead of an image, but the test is still valid
-	CSingleTransferTest transfer2d(_L("2D Transfer"), 1, transferArgs2D, expectedResults, 0, &KCompare2D);
-
-	TTestCase testCase2d(&transfer2d, EFalse, cap_2DRequired, capAboveV1);
-	}
-
-//----------------------------------------------------------------------------------------------
-//! @SYMTestCaseID      KBASE-DMA-2565
-//! @SYMTestType        CIT
-//! @SYMPREQ            REQ
-//! @SYMTestCaseDesc    DMA Fragmentation count test
-//!
-//! @SYMTestActions     
-//!						1.
-//!						2.	
-//!
-//!
-//! @SYMTestExpectedResults 
-//!						1.  
-//!						2.		
-//!							
-//!
-//! @SYMTestPriority        High
-//! @SYMTestStatus          Implemented
-//----------------------------------------------------------------------------------------------
-namespace FragmentationCount
-	{
-	TDmaTransferArgs transferArgs(0, size, size, KDmaMemAddr);
-
-	const TRequestResults requestResult(KErrNone, 128);
-	const TResultSet expectedResults(KErrNone, requestResult, KErrNone, threadCallback);
-	CSingleTransferTest test1(_L("Fragmentation Count - 128 fragments"), 1, transferArgs, expectedResults, KKilo);
-	TTestCase testCase(&test1, EFalse);
-
-	const TRequestResults requestResult2(KErrNone, 4);
-	const TResultSet expectedResults2(KErrNone, requestResult2, KErrNone, threadCallback);
-	CSingleTransferTest test2(_L("Fragmentation Count - 4 fragments"), 1, transferArgs, expectedResults2, 32*KKilo);
-	TTestCase testCase2(&test2, EFalse);
-	}
-
-//----------------------------------------------------------------------------------------------
-//! @SYMTestCaseID      KBASE-DMA-2584,KBASE-DMA-2585
-//! @SYMTestType        CIT
-//! @SYMPREQ            REQ
-//! @SYMTestCaseDesc    DMA Benchmark tests
-//!
-//! @SYMTestActions     
-//!						1.
-//!						2.	
-//!
-//!
-//! @SYMTestExpectedResults 
-//!						1.  
-//!						2.		
-//!							
-//!
-//! @SYMTestPriority        High
-//! @SYMTestStatus          Implemented
-//-----------------------------------------------------------------------------------------------
-namespace Benchmark
-	{
-	const TInt bmIters = 10;
-	namespace Frag
-		{
-		const TInt size = 1 * KMega;
-		TDmaTransferArgs transferArgs(0, size, size, KDmaMemAddr);
-
-		TTestCase testCase_256k(new (ELeave) CDmaBmFragmentation(_L("1 Mb transfer - 256k frag size"), bmIters, transferArgs, 256 * KKilo), EFalse);
-		TTestCase testCase_8k(new (ELeave) CDmaBmFragmentation(_L("1 Mb transfer - 8k frag size"), bmIters, transferArgs, 8 * KKilo), EFalse);
-		}
-
-	namespace Transfer
-		{
-		namespace _4Bytes
-			{
-			const TInt size = 4;
-			TDmaTransferArgs transferArgs(0, size, size, KDmaMemAddr);
-
-			CDmaBmTransfer bmTest(_L("4 bytes"), bmIters, transferArgs, 0);
-			TTestCase testCase(&bmTest, EFalse);
-			}
-		namespace _128K
-			{
-			const TInt size = 128 * KKilo;
-			TDmaTransferArgs transferArgs(0, size, size, KDmaMemAddr);
-
-			TTestCase testCase_128(new (ELeave) CDmaBmTransfer(_L("128 K - 128K frag size"), bmIters, transferArgs, 128 * KKilo), EFalse);
-			TTestCase testCase_16(new (ELeave) CDmaBmTransfer(_L("128 K - 16k frag size"), bmIters, transferArgs, 16 * KKilo), EFalse);
-			TTestCase testCase_4(new (ELeave) CDmaBmTransfer(_L("128 K - 4k frag size"), bmIters, transferArgs, 4 * KKilo), EFalse);
-			TTestCase testCase_1(new (ELeave) CDmaBmTransfer(_L("128 K - 1k frag size"), bmIters, transferArgs, 1 * KKilo), EFalse);
-			}
-		namespace _4Mb
-			{
-			const TInt size = 4 * KMega;
-			TDmaTransferArgs transferArgs(0, size, size, KDmaMemAddr);
-
-			CDmaBmTransfer bmTest(_L("4 Mb"), bmIters, transferArgs, 0);
-			TTestCase testCase(&bmTest, EFalse);
-			}
-		}
-
-	/**
-	Compare time taken between queing and callback of 4 byte
-	request with both DFC and ISR callback
-	The new API calls are used
-	*/
-	namespace CompareIsrDfcCb
-		{
-		const TInt iterations = 50;
-
-		namespace Dfc
-			{
-			TResultSet expected = TResultSet(threadCallback).
-				PostTransferResult(KErrUnknown);
-
-			namespace _4Bytes
-				{
-				const TInt size = 4;
-				TDmaTransferArgs transferArgs(0, size, size, KDmaMemAddr);
-				CDmaBmTransfer bmTest = CDmaBmTransfer(_L("4 bytes DFC cb"), iterations, transferArgs, 0).
-					UseNewDmaApi(ETrue).
-					ExpectedResults(expected);
-				TTestCase testCase(&bmTest, EFalse);
-				}
-			namespace _4K
-				{
-				const TInt size = 4 * KKilo;
-				TDmaTransferArgs transferArgs(0, size, size, KDmaMemAddr);
-				CDmaBmTransfer bmTest = CDmaBmTransfer(_L("4K DFC cb"), iterations, transferArgs, 0).
-					UseNewDmaApi(ETrue).
-					ExpectedResults(expected);
-				TTestCase testCase(&bmTest, EFalse);
-				}
-			}
-
-		namespace Isr
-			{
-			TResultSet expected = TResultSet(isrCallback).
-				PostTransferResult(KErrUnknown);
-
-			namespace _4Bytes
-				{
-				const TInt size = 4;
-				TDmaTransferArgs transferArgs(0, size, size, KDmaMemAddr, KDmaSyncAuto, KDmaRequestCallbackFromIsr);
-				CDmaBmTransfer bmTest = CDmaBmTransfer(_L("4 bytes Isr cb"), iterations, transferArgs, 0).
-					UseNewDmaApi(ETrue).
-					ExpectedResults(expected);
-				TTestCase testCase(&bmTest, EFalse);
-				}
-			namespace _4K
-				{
-				const TInt size = 4 * KKilo;
-				TDmaTransferArgs transferArgs(0, size, size, KDmaMemAddr, KDmaSyncAuto, KDmaRequestCallbackFromIsr);
-				CDmaBmTransfer bmTest = CDmaBmTransfer(_L("4K Isr cb"), iterations, transferArgs, 0).
-					UseNewDmaApi(ETrue).
-					ExpectedResults(expected);
-				TTestCase testCase(&bmTest, EFalse);
-				}
-			}
-		}
-	}
-
-//----------------------------------------------------------------------------------------------
-//! @SYMTestCaseID      KBASE-DMA-2560
-//! @SYMTestType        CIT
-//! @SYMPREQ            REQ
-//! @SYMTestCaseDesc    TestNewStyleFragment using CSingleTransferTest
-//!						Test Scenario 1 - DstAddr > SrcAddr & TransferSize=32K & Location is 
-//!						address of a memory buffer
-//! @SYMTestActions     
-//!						1.	Set up the arguments for aTransfeArgs using the settings below.
-//!							
-//!							SrcAddr		 = 4 * KKilo;
-//!							desAddr		 = 64 * KKilo;
-//!							transferSize = 32 * KKilo;	
-//!							iFlags		 = KDmaMemAddr;
-//!
-//!						2.	Setup expected result.
-//!						3.	Create single transfer test and run test
-//!
-//! @SYMTestExpectedResults 
-//!						1.  TransfeArgs set up in DMA framework
-//!						2.	Expected results set up in DMA framework					
-//!						3.	Fragment request completes and KErrNone returned
-//!
-//! @SYMTestPriority        High
-//! @SYMTestStatus          Implemented
-//----------------------------------------------------------------------------------------------
-namespace TestNewStyleFragment_1
-	{	
-	const TInt srcAddr = 4 * KKilo;
-	const TInt desAddr = 64 * KKilo;
-
-	const TInt transferSize =  32 * KKilo;
-	
-	TDmaTransferArgs transferArgs( srcAddr, desAddr, transferSize, KDmaMemAddr);
-
-	const TRequestResults requestResult(KErrNone, 32); 
-	const TResultSet expectedResults(KErrNone, requestResult, KErrNone, threadCallback);
-
-	CSingleTransferTest testscenario_1(_L("TestNewStyleFragment - Test Scenario 1"), 1, transferArgs, expectedResults,KKilo);
-
-	TTestCase testCase(&testscenario_1, EFalse, capAboveV1);
-	TTestCase testCaseConcurrent(&testscenario_1, ETrue, capAboveV1);
-	}
-
-//----------------------------------------------------------------------------------------------
-//! @SYMTestCaseID      KBASE-DMA-2560
-//! @SYMTestType        CIT
-//! @SYMPREQ            REQ
-//! @SYMTestCaseDesc    TestNewStyleFragment using CSingleTransferTest
-//!						Test Scenario 2 -  SrcAddr	== DstAddr   					
-//!		
-//!						1.	Set up the arguments for aTransfeArgs using the settings below.
-//!							
-//!							SrcAddr	 = 4 * KKilo;
-//!							desAddr	 = 4 * KKilo;
-//!							transferSize = 32 * KKilo;	
-//!							iFlags		 = KDmaMemAddr;
-//!
-//!						2.	Setup expected result.
-//!						3.	Create single transfer test and run test
-//!
-//! @SYMTestExpectedResults 
-//!
-//!						1.  TransfeArgs set up in DMA framework
-//!						2.	Expected results set up in DMA framework					
-//!						3.	Fragment passes and KErrNone returned
-//!
-//! @SYMTestPriority        High
-//! @SYMTestStatus          Implemented
-//----------------------------------------------------------------------------------------------
-namespace TestNewStyleFragment_2
-	{
-	const TInt srcAddr = 4 * KKilo;
-	const TInt desAddr = 4 * KKilo;
-	const TInt transferSize =  32 * KKilo;
-
-	TDmaTransferArgs transferArgs(srcAddr,desAddr, transferSize, KDmaMemAddr);
-	const TRequestResults requestResult(KErrNone, 32); 
-	const TResultSet expectedResults(KErrNone, requestResult, KErrNone, threadCallback);
-
-	CSingleTransferTest testscenario_2(_L("TestNewStyleFragment - Test Scenario 2"), 1, transferArgs, expectedResults,KKilo);
-
-	TTestCase testCase(&testscenario_2, EFalse, capAboveV1);
-	TTestCase testCaseConcurrent(&testscenario_2, ETrue, capAboveV1);
-	}
-
-//----------------------------------------------------------------------------------------------
-//! @SYMTestCaseID      KBASE-DMA-2560
-//! @SYMTestType        CIT
-//! @SYMPREQ            REQ
-//! @SYMTestCaseDesc    TestNewStyleFragment using CSingleTransferTest
-//!						Test Scenario 3 -  TransferSize=0   
-//!
-//!						1.	Set up the arguments for aTransfeArgs using the settings below.
-//!							
-//!							SrcAddr		 = 32 * KKilo;
-//!							desAddr		 = 64 * KKilo;
-//!							transferSize = 0	
-//!							iFlags		 = KDmaMemAddr;
-//!
-//!						2.	Setup expected result.
-//!						3.	Create single transfer test and run test
-//!
-//!
-//! @SYMTestExpectedResults 
-//!
-//!						1.  TransfeArgs set up in DMA framework
-//!						2.	Expected results set up in DMA framework			
-//!						3.	Fragment request fails and KErrArgument returned
-//!
-//! @SYMTestPriority        High
-//! @SYMTestStatus          Implemented
-//----------------------------------------------------------------------------------------------
-namespace TestNewStyleFragment_3
-	{
-	const TInt srcAddr = 32 * KKilo;
-	const TInt desAddr = 64 * KKilo;
-	const TInt transferSize = 0;
-	
-	TDmaTransferArgs transferArgs( srcAddr, desAddr, transferSize,KDmaMemAddr);
-	const TRequestResults requestResult(KErrArgument, 0); 
-	const TResultSet expectedResults(KErrNone, requestResult, KErrNone, threadCallback);
-
-	CSingleTransferTest testscenario_3(_L("TestNewStyleFragment - Test Scenario 3"), 1, transferArgs, expectedResults);
-
-	TTestCase testCase(&testscenario_3, EFalse, capAboveV1);
-	TTestCase testCaseConcurrent(&testscenario_3, ETrue, capAboveV1);
-	}
-
-//----------------------------------------------------------------------------------------------
-//! @SYMTestCaseID      KBASE-DMA-2560
-//! @SYMTestType        CIT
-//! @SYMPREQ            REQ
-//! @SYMTestCaseDesc    TestNewStyleFragment using CSingleTransferTest
-//!						Test Scenario 4 -  TransferSize=1Byte   
-//!
-//!						1.	Set up the arguments for aTransfeArgs using the settings below.
-//!							
-//!							SrcAddr		 = 32K;
-//!							desAddr		 = 64K;
-//!							transferSize = 1 byte	
-//!							iFlags		 = KDmaMemAddr;
-//!
-//!						2.	Setup expected result.
-//!						3.	Create single transfer test and run test
-//!
-//! @SYMTestExpectedResults 
-//!
-//!						1.  TransfeArgs set up in DMA framework
-//!						2.	Expected results set up in DMA framework			
-//!						3.	Fragment request completes and KErrNone returned
-//!
-//! @SYMTestPriority        High
-//! @SYMTestStatus          Implemented
-//----------------------------------------------------------------------------------------------
-namespace TestNewStyleFragment_4
-	{	
-	const TInt srcAddr = 32 * KKilo;
-	const TInt desAddr = 64 * KKilo;
-	const TInt transferSize = 1;
-	
-	TDmaTransferArgs transferArgs(srcAddr, desAddr, transferSize, KDmaMemAddr);
-	const TRequestResults requestResult(KErrNone, 1);
-	const TResultSet expectedResults(KErrNone, requestResult, KErrNone, threadCallback);
-
-	CSingleTransferTest testscenario_4(_L("TestNewStyleFragment - Test Scenario 4"), 1, transferArgs, expectedResults);
-
-	TTestCase testCase(&testscenario_4, EFalse, capAboveV1);
-	TTestCase testCaseConcurrent(&testscenario_4, ETrue, capAboveV1);
-	}
-
-//----------------------------------------------------------------------------------------------
-//! @SYMTestCaseID      KBASE-DMA-2560
-//! @SYMTestType        CIT
-//! @SYMPREQ            REQ
-//! @SYMTestCaseDesc    TestNewStyleFragment using CSingleTransferTest
-//!						Test Scenario 5 -  TransferSize=128KB    
-//!
-//!						1.	Set up the arguments for aTransfeArgs using the settings below.
-//!							
-//!							SrcAddr		 = 16K;
-//!							desAddr		 = 2MB;
-//!							transferSize = 1MB;
-//!							iFlags		 = KDmaMemAddr;
-//!
-//!						2.	Setup expected result.
-//!						3.	Create single transfer test and run test
-//!
-//! @SYMTestExpectedResults 
-//!
-//!						1.  TransfeArgs set up in DMA framework
-//!						2.	Expected results set up in DMA framework			
-//!						3.	Fragment request completes and KErrNone returned
-//!
-//! @SYMTestPriority        High
-//! @SYMTestStatus          Implemented
-//----------------------------------------------------------------------------------------------
-namespace TestNewStyleFragment_5
-	{
-	
-	const TInt srcAddr		= 16 * KKilo;
-	const TInt desAddr		= 2 * KMega;	
-	const TInt transferSize = 1 * KMega;
-
-	TDmaTransferArgs transferArgs(srcAddr, desAddr, transferSize, KDmaMemAddr);
-	const TRequestResults requestResult(KErrNone); 
-	const TResultSet expectedResults(KErrNone, requestResult, KErrNone, threadCallback);
-
-	CSingleTransferTest testscenario_5(_L("TestNewStyleFragment - Test Scenario 5"), 1, transferArgs, expectedResults);
-
-	TTestCase testCase(&testscenario_5, EFalse, capAboveV1);
-	TTestCase testCaseConcurrent(&testscenario_5, ETrue, capAboveV1);
-	}
-
-//----------------------------------------------------------------------------------------------
-//! @SYMTestCaseID      KBASE-DMA-2560
-//! @SYMTestType        CIT
-//! @SYMPREQ            REQ
-//! @SYMTestCaseDesc    TestNewStyleFragment using CSingleTransferTest
-//!						Test Scenario 6 -  TransferSize=3MB   
-//!
-//!						1.	Set up the arguments for aTransfeArgs using the settings below.
-//!							
-//!							SrcAddr		 = 16K;
-//!							desAddr		 = 4MB;
-//!							transferSize = 3MB 	
-//!							iFlags		 = KDmaMemAddr;
-//!
-//!						2.	Setup expected result.
-//!						3.	Create single transfer test and run test
-//!
-//! @SYMTestExpectedResults 
-//!
-//!						1.  TransfeArgs set up in DMA framework
-//!						2.	Expected results set up in DMA framework			
-//!						3.	Fragment request completes and KErrNone returned
-//!
-//! @SYMTestPriority        High
-//! @SYMTestStatus          Implemented
-//----------------------------------------------------------------------------------------------
-namespace TestNewStyleFragment_6
-	{
-	const TInt srcAddr = 16 * KKilo;
-	const TInt desAddr = 4 * KMega;
-	const TInt transferSize = 3 * KMega;
-
-	TDmaTransferArgs transferArgs(srcAddr, desAddr, transferSize, KDmaMemAddr);
-	const TRequestResults requestResult(KErrNone); 
-	const TResultSet expectedResults(KErrNone, requestResult, KErrNone, threadCallback);
-
-	CSingleTransferTest testscenario_6(_L("TestNewStyleFragment - Test Scenario 6"), 1, transferArgs, expectedResults);
-
-	TTestCase testCase(&testscenario_6, EFalse, capAboveV1);
-	TTestCase testCaseConcurrent(&testscenario_6, ETrue, capAboveV1);
-	}
-
-//----------------------------------------------------------------------------------------------
-//! @SYMTestCaseID      KBASE-DMA-2561
-//! @SYMTestType        CIT
-//! @SYMPREQ            REQ
-//! @SYMTestCaseDesc    TestOldstyleFragment using CSingleTransferTest
-//!						Test Scenario 1 - DstAddr > SrcAddr & TransferSize=32K & Location is 
-//!						address of a memory buffer
-//!
-//!						1.	Set up the arguments for aTransfeArgs using the settings below.
-//!							
-//!							SrcAddr		 = 4 * KKilo;
-//!							desAddr		 = 64 * KKilo;
-//!							transferSize = 32 * KKilo;	
-//!							iFlags		 = KDmaMemAddr;
-
-//!						2.	Setup expected result.
-//!						3.	Create single transfer test and run test
-//!
-//! @SYMTestExpectedResults 
-//!
-//!						1.  TransfeArgs set up in DMA framework
-//!						2.	Expected results set up in DMA framework					
-//!						3.	Fragment request completes and KErrNone returned
-//!
-//! @SYMTestPriority        High
-//! @SYMTestStatus          Implemented
-//----------------------------------------------------------------------------------------------
-namespace TestOldStyleFragment_1
-	{	
-	const TInt srcAddr = 4 * KKilo;
-	const TInt desAddr = 64 * KKilo;
-	const TInt transferSize =  32 * KKilo;
-	
-	TDmaTransferArgs transferArgs( srcAddr, desAddr, transferSize, KDmaMemAddr);
-
-	const TRequestResults requestResult(KErrNone,32); 
-	const TResultSet expectedResults(KErrNone, requestResult, KErrNone, threadCallback);
-
-	CSingleTransferTest testscenario_1 = CSingleTransferTest(_L("TestOldStyleFragment - Test Scenario 1"), 1, transferArgs, expectedResults,KKilo).
-		UseNewDmaApi(EFalse);
-
-	TTestCase testCase(&testscenario_1, EFalse, capAboveV1);
-	TTestCase testCaseConcurrent(&testscenario_1, ETrue, capAboveV1);
-	}
-
-//----------------------------------------------------------------------------------------------
-//! @SYMTestCaseID      KBASE-DMA-2561
-//! @SYMTestType        CIT
-//! @SYMPREQ            REQ
-//! @SYMTestCaseDesc    TestOldstyleFragment using CSingleTransferTest
-//!						Test Scenario 2 - DstAddr == SrcAddr
-//!
-//!						1.	Set up the arguments for aTransfeArgs using the settings below.
-//!							
-//!							SrcAddr	 = 4 * KKilo;
-//!							desAddr	 = 4 * KKilo;
-//!							transferSize = 4 * KKilo
-//!							iFlags		 = KDmaMemAddr;
-//!
-//!						2.	Setup expected result.
-//!						3.	Create single transfer test and run test
-//!
-//! @SYMTestExpectedResults 
-//!
-//!						1.  TransfeArgs set up in DMA framework
-//!						2.	Expected results set up in DMA framework			
-//!						3.	Fragment passes and KErrNone returned
-//!
-//! @SYMTestPriority        High
-//! @SYMTestStatus          Implemented
-//----------------------------------------------------------------------------------------------
-namespace TestOldStyleFragment_2
-	{
-	const TInt srcAddr = 4 * KKilo;
-	const TInt desAddr = 4 * KKilo;
-	const TInt transferSize =  4 * KKilo;
-
-	TDmaTransferArgs transferArgs(srcAddr,desAddr, transferSize, KDmaMemAddr);
-	const TRequestResults requestResult(KErrNone, 4);  
-	const TResultSet expectedResults(KErrNone, requestResult, KErrNone, threadCallback);
-
-	CSingleTransferTest testscenario_2 = CSingleTransferTest(_L("TestOldStyleFragment - Test Scenario 2"), 1, transferArgs, expectedResults,KKilo)
-		.UseNewDmaApi(EFalse);
-
-	TTestCase testCase(&testscenario_2, EFalse, capAboveV1);
-	TTestCase testCaseConcurrent(&testscenario_2, ETrue, capAboveV1);
-	}
-
-//----------------------------------------------------------------------------------------------
-//! @SYMTestCaseID      KBASE-DMA-2561
-//! @SYMTestType        CIT
-//! @SYMPREQ            REQ
-//! @SYMTestCaseDesc    TestOldstyleFragment using CSingleTransferTest
-//!						Test Scenario 3 -  TransferSize=0  
-//!
-//!						1.	Set up the arguments for aTransfeArgs using the settings below.
-//!							
-//!							SrcAddr	 = 32K
-//!							desAddr	 = 64K;
-//!							transferSize = 0
-//!							iFlags		 = KDmaMemAddr;
-//!
-//!						2.	Setup expected result.
-//!						3.	Create single transfer test and run test
-//!
-//! @SYMTestExpectedResults 
-//!
-//!						1.  TransfeArgs set up in DMA framework
-//!						2.	Expected results set up in DMA framework			
-//!						3.	Fragment request Fails and KErrArgument returned
-//!
-//! @SYMTestPriority        High
-//! @SYMTestStatus          Implemented
-//----------------------------------------------------------------------------------------------
-namespace TestOldStyleFragment_3
-	{
-
-	const TInt srcAddr = 32 * KKilo;
-	const TInt desAddr = 64 * KKilo;
-	const TInt transferSize = 0;
-	
-	TDmaTransferArgs transferArgs(srcAddr, desAddr, transferSize,KDmaMemAddr);
-	const TRequestResults requestResult(KErrArgument, 0); 
-	const TResultSet expectedResults(KErrNone, requestResult, KErrNone, threadCallback);
-
-	CSingleTransferTest testscenario_3 = CSingleTransferTest(_L("TestOldStyleFragment - Test Scenario 3"), 1, transferArgs, expectedResults).
-		UseNewDmaApi(EFalse);
-
-	TTestCase testCase(&testscenario_3, EFalse, capAboveV1);
-	TTestCase testCaseConcurrent(&testscenario_3, ETrue, capAboveV1);
-	}
-
-//----------------------------------------------------------------------------------------------
-//! @SYMTestCaseID      KBASE-DMA-2561
-//! @SYMTestType        CIT
-//! @SYMPREQ            REQ
-//! @SYMTestCaseDesc    TestOldstyleFragment using CSingleTransferTest
-//!						Test Scenario 4 -  TransferSize=1Byte   
-//!
-//!						1.	Set up the arguments for aTransfeArgs using the settings below.
-//!							
-//!	
-//!							SrcAddr		 = 32K;
-//!							desAddr		 = 64K;
-//!							transferSize = 1 byte	
-//!							iFlags		 = KDmaMemAddr;
-//!
-//!						2.	Setup expected result.
-//!						3.	Create single transfer test and run test
-//!
-//! @SYMTestExpectedResults 
-//!
-//!						1.  TransfeArgs set up in DMA framework
-//!						2.	Expected results set up in DMA framework			
-//!						3.	Fragment request completes and KErrNone returned
-//!
-//! @SYMTestPriority        High
-//! @SYMTestStatus          Implemented
-//------------------------------------------------------------------------------------------------
-namespace TestOldStyleFragment_4
-	{	
-	const TInt srcAddr = 32 * KKilo;
-	const TInt desAddr = 64 * KKilo;
-	const TInt transferSize = 1;
-	
-	TDmaTransferArgs transferArgs( srcAddr, desAddr, transferSize, KDmaMemAddr);
-	const TRequestResults requestResult(KErrNone, 1); 
-	const TResultSet expectedResults(KErrNone, requestResult, KErrNone, threadCallback);
-
-	CSingleTransferTest testscenario_4 = CSingleTransferTest(_L("TestOldStyleFragment - Test Scenario 4"), 1, transferArgs, expectedResults).
-		UseNewDmaApi(EFalse);
-
-	TTestCase testCase(&testscenario_4, EFalse, capAboveV1);
-	TTestCase testCaseConcurrent(&testscenario_4, ETrue, capAboveV1);
-	}
-
-//----------------------------------------------------------------------------------------------
-//! @SYMTestCaseID      KBASE-DMA-2561
-//! @SYMTestType        CIT
-//! @SYMPREQ            REQ
-//! @SYMTestCaseDesc    TestOldstyleFragment using CSingleTransferTest
-//!						Test Scenario 5 -  TransferSize=1MB
-//!
-//!						1.	Set up the arguments for aTransfeArgs using the settings below.
-//!							
-//!							SrcAddr		 = 16K;
-//!							desAddr		 = 2MB;
-//!							transferSize = 1MB	
-//!							iFlags		 = KDmaMemAddr;
-//!
-//!						2.	Setup expected result.
-//!						3.	Create single transfer test and run test
-//!
-//! @SYMTestExpectedResults 
-//!
-//!						1.  TransfeArgs set up in DMA framework
-//!						2.	Expected results set up in DMA framework			
-//!						3.	Fragment request completes and KErrNone returned
-//!
-//! @SYMTestPriority        High
-//! @SYMTestStatus          Implemented
-//----------------------------------------------------------------------------------------------
-namespace TestOldStyleFragment_5
-	{
-	const TInt srcAddr = 16 * KKilo;	
-	const TInt desAddr = 2 * KMega;
-	const TInt transferSize = 1 *  KMega;
-
-	TDmaTransferArgs transferArgs(srcAddr, desAddr, transferSize, KDmaMemAddr);
-
-	const TRequestResults requestResult(KErrNone); 
-	const TResultSet expectedResults(KErrNone, requestResult, KErrNone, threadCallback);
-
-	CSingleTransferTest testscenario_5 = CSingleTransferTest(_L("TestOldStyleFragment - Test Scenario 5"), 1, transferArgs, expectedResults).
-		UseNewDmaApi(EFalse);
-
-	TTestCase testCase(&testscenario_5, EFalse, capAboveV1);
-	TTestCase testCaseConcurrent(&testscenario_5, ETrue, capAboveV1);
-	}
-
-//----------------------------------------------------------------------------------------------
-//! @SYMTestCaseID      KBASE-DMA-2561
-//! @SYMTestType        CIT
-//! @SYMPREQ            REQ
-//! @SYMTestCaseDesc    TestOldstyleFragment using CSingleTransferTest
-//!						Test Scenario 6 -  TransferSize=3MB     
-//!
-//!						1.	Set up the arguments for aTransfeArgs using the settings below.
-//!							
-//!							SrcAddr	 = 16K
-//!							desAddr	 = 4MB;
-//!							transferSize = 3MB  
-//!							iFlags		 = KDmaMemAddr;
-//!
-//!						2.	Setup expected result.
-//!						3.	Create single transfer test and run test
-//!
-//! @SYMTestExpectedResults 
-//!
-//!						1.  TransfeArgs set up in DMA framework
-//!						2.	Expected results set up in DMA framework			
-//!						3.	Fragment request completes and KErrNone returned
-//!
-//! @SYMTestPriority        High
-//! @SYMTestStatus          Implemented
-//----------------------------------------------------------------------------------------------
-namespace TestOldStyleFragment_6
-	{
-	const TInt srcAddr = 16 * KKilo;
-	const TInt desAddr = 4 * KMega;
-	const TInt transferSize = 3 * KMega; 
-	TDmaTransferArgs transferArgs(srcAddr, desAddr, transferSize, KDmaMemAddr);
-
-	const TRequestResults requestResult(KErrNone); 
-	const TResultSet expectedResults(KErrNone, requestResult, KErrNone, threadCallback);
-
-	CSingleTransferTest testscenario_6 = CSingleTransferTest(_L("TestOldStyleFragment - Test Scenario 6"), 1, transferArgs, expectedResults).
-		UseNewDmaApi(EFalse);
-
-	TTestCase testCase(&testscenario_6, EFalse, capAboveV1);
-	TTestCase testCaseConcurrent(&testscenario_6, ETrue, capAboveV1);
-	}
-
-//----------------------------------------------------------------------------------------------
-//! @SYMTestCaseID      KBASE-DMA-2562
-//! @SYMTestType        CIT
-//! @SYMPREQ            REQ
-//! @SYMTestCaseDesc    TestOldStyleDDmaRequest using CSingleTransferTest
-//!						Test Scenario 1 -  aMaxTransferSize=0 
-//!
-//!						1.	Set up the DDmaRequest using  aMaxTransferSize set to 0. 
-//!						2.	Setup expected result.
-//!						3.	Create single transfer test and run test
-//!
-//! @SYMTestExpectedResults 
-//!
-//!						1.  TransfeArgs set up in DMA framework
-//!						2.	Expected results set up in DMA framework			
-//!						3.	DDmaRequest constructor behaves as expected and KErrArgument returned
-//!
-//! @SYMTestPriority        High
-//! @SYMTestStatus          Implemented
-//------------------------------------------------------------------------------------------------
-namespace TestOldStyleDDmaRequest_1
-	{
-	const TInt desAddr = 4 * KKilo;
-	const TInt transferSize = 4 * KKilo;
-	TDmaTransferArgs transferArgs(0, desAddr, transferSize, KDmaMemAddr);
-
-	const TRequestResults requestResult(KErrNone, 0); 
-	const TResultSet expectedResults(KErrNone, requestResult, KErrNone, threadCallback);
-
-	CSingleTransferTest testscenario_1 = CSingleTransferTest(_L("TestOldStyleDDmaRequest - Test Scenario 1"), 1, transferArgs, expectedResults,0).
-		UseNewDmaApi(EFalse);
-
-	TTestCase testCase(&testscenario_1, EFalse, capAboveV1);
-	TTestCase testCaseConcurrent(&testscenario_1, ETrue, capAboveV1);
-	}
-
-//!-------------------------------------------------------------------------------------------------
-//! @SYMTestCaseID       KBASE-DMA-2562
-//! @SYMTestType        CIT
-//! @SYMPREQ            REQ
-//! @SYMTestCaseDesc    TestOldStyleDDmaRequest using CSingleTransferTest
-//!						Test Scenario 2 -  aMaxTransferSize= 65535   
-//!
-//!						1.	Set up the arguments for DDmaRequest using aMaxTransferSize set to 65535.
-//!						2.	Setup expected result.
-//!						3.	Create single transfer test and run test
-//!
-//! @SYMTestExpectedResults 
-//!
-//!						1.  TransfeArgs set up in DMA framework
-//!						2.	Expected results set up in DMA framework			
-//!						3.	DDmaRequest constructor behaves as expected and KErrArgument returned
-//!
-//! @SYMTestPriority        High
-//! @SYMTestStatus          Implemented
-//---------------------------------------------------------------------------------------------------
-namespace TestOldStyleDDmaRequest_2
-	{
-	const TInt desAddr = 4 * KKilo;
-	const TInt transferSize = 4 * KKilo;
-	TDmaTransferArgs transferArgs(0, desAddr, transferSize, KDmaMemAddr);
-
-	const TRequestResults requestResult(KErrNone, 1); 
-	const TResultSet expectedResults(KErrNone, requestResult, KErrNone, threadCallback);
-
-	CSingleTransferTest testscenario_2 = CSingleTransferTest(_L("TestOldStyleDDmaRequest - Test Scenario 2"), 1, transferArgs, expectedResults, 65535).
-		UseNewDmaApi(EFalse);
-
-	TTestCase testCase(&testscenario_2, EFalse, capAboveV1);
-	TTestCase testCaseConcurrent(&testscenario_2, ETrue, capAboveV1);
-	}
-
-//----------------------------------------------------------------------------------------------
-//! @SYMTestCaseID      KBASE-DMA-2563
-//! @SYMTestType        CIT
-//! @SYMPREQ            REQ
-//! @SYMTestCaseDesc    TestNewStyleDDmaRequest using CSingleTransferTest
-//!						Test Scenario 1 -  aMaxTransferSize=0 
-//!
-//!						1.	Set up the DDmaRequest using  aMaxTransferSize set to 0. 
-//!						2.	Setup expected result.
-//!						3.	Create single transfer test and run test
-//!
-//! @SYMTestExpectedResults 
-//!
-//!						1.  TransfeArgs set up in DMA framework
-//!						2.	Expected results set up in DMA framework			
-//!						3.	DDmaRequest constructor behaves as expected and KErrArgument returned
-//!
-//! @SYMTestPriority        High
-//! @SYMTestStatus          Implemented
-//----------------------------------------------------------------------------------------------
-namespace TestNewStyleDDmaRequest_1
-	{
-	const TInt desAddr = 4 * KKilo;
-	const TInt transferSize = 4 * KKilo;
-	TDmaTransferArgs transferArgs(0, desAddr, transferSize, KDmaMemAddr);
-
-	const TRequestResults requestResult(KErrNone, 0); 
-	const TResultSet expectedResults(KErrNone, requestResult, KErrNone, threadCallback);
-
-	CSingleTransferTest testscenario_1(_L("TestNewStyleDDmaRequest - Test Scenario 1"), 1, transferArgs, expectedResults,0);
-
-	TTestCase testCase(&testscenario_1, EFalse, capAboveV1);
-	TTestCase testCaseConcurrent(&testscenario_1, ETrue, capAboveV1);
-	}
-
-//!-------------------------------------------------------------------------------------------------
-//! @SYMTestCaseID      KBASE-DMA-2563
-//! @SYMTestType        CIT
-//! @SYMPREQ            REQ
-//! @SYMTestCaseDesc    TestNewStyleDDmaRequest using CSingleTransferTest
-//!						Test Scenario 2 -  aMaxTransferSize= 65535   
-//!
-//!						1.	Set up the arguments for DDmaRequest using aMaxTransferSize set to 65535.
-//!						2.	Setup expected result.
-//!						3.	Create single transfer test and run test
-//!
-//! @SYMTestExpectedResults 
-//!
-//!						1.  TransfeArgs set up in DMA framework
-//!						2.	Expected results set up in DMA framework			
-//!						3.	DDmaRequest constructor behaves as expected and KErrArgument returned
-//!
-//! @SYMTestPriority        High
-//! @SYMTestStatus          Implemented
-//---------------------------------------------------------------------------------------------------
-namespace TestNewStyleDDmaRequest_2
-	{
-	const TInt desAddr = 4 * KKilo;
-	const TInt transferSize = 4 * KKilo;
-	TDmaTransferArgs transferArgs(0, desAddr, transferSize, KDmaMemAddr);
-
-	const TRequestResults requestResult(KErrNone, 1); 
-	const TResultSet expectedResults(KErrNone, requestResult, KErrNone, threadCallback);
-
-	CSingleTransferTest testscenario_2(_L("TestNewStyleDDmaRequest - Test Scenario 2"), 1, transferArgs, expectedResults, 65535);
-
-	TTestCase testCase(&testscenario_2, EFalse, capAboveV1);
-	TTestCase testCaseConcurrent(&testscenario_2, ETrue, capAboveV1);
-	}
-
-//----------------------------------------------------------------------------------------------
-//! @SYMTestCaseID      PBASE-DMA-FUNC-xxx
-//! @SYMTestType        CIT
-//! @SYMPREQ            REQ
-//! @SYMTestCaseDesc    SmallFrags: This test provokes the failure seen in DEF140598
-//!						The test checks that requests with small fragments
-//!						do not trigger a spurious missed interrupt clean up
-//!
-//! @SYMTestExpectedResults 
-//!
-//!						1.  		
-//!						2.	
-//!
-//! @SYMTestPriority        High
-//! @SYMTestStatus          Implemented
-//----------------------------------------------------------------------------------------------
-namespace SmallFrags
-	{
-	const TInt size = 32;
-	TDmaTransferArgs transferArgs(0, size, size, KDmaMemAddr);
-
-	const TResultSet expectedResults(threadCallback);
-
-	TTestCase testCase(
-			new (ELeave) CSingleTransferTest(_L("8 * 4byte frags"), 10, transferArgs, expectedResults, 4),
-			EFalse, capAboveV1);
-	}
-
-
-//TODO TTestCase could automatically be added to aray by ctor
-//
-//Append new test cases here
-static TTestCase* StaticTestArray[] = {
-	&Simple_1::testCase,
-	&Simple_1::testCaseConcurrent,
-	&Simple_2::testCase,
-	&Simple_2::testCaseConcurrent,
-	&Callback::testCase,
-	&Callback::testCaseOldRequest,
-	&ISR_Reque::endOnRedo::testCase,
-	&ISR_Reque::endOnIsrCb::testCase,
-	&ISR_Reque::endOnThreadCb::testCase,
-	&ISR_Reque::changeSize::testCase,
-#ifdef _DEBUG
-	&ISR_Reque::invalidAddresses::testCase, // addresses only checked in UDEB
-#endif
-	//&ISR_Reque::multipleFragments::testCase, // This error condition is currently caught by a FAULT instead of a return code
-	&Multipart::testCase,
-	&IsrAndDfc::DfcBeforeIsr::testCase,
-	&IsrAndDfc::IsrBeforeDfc::testCase,
-	&_2D_Test::testCase2d,
-	&FragmentationCount::testCase,
-	&FragmentationCount::testCase2,
-	&SmallFrags::testCase,
-#ifndef _DEBUG
-	// Benchmarks are only really meaningful
-	// on UREL builds
-	&Benchmark::Frag::testCase_256k,
-	&Benchmark::Frag::testCase_8k,
-	&Benchmark::Transfer::_128K::testCase_128,
-	&Benchmark::Transfer::_128K::testCase_16,
-	&Benchmark::Transfer::_128K::testCase_4,
-	&Benchmark::Transfer::_128K::testCase_1,
-	&Benchmark::Transfer::_4Bytes::testCase,
-	&Benchmark::Transfer::_4Mb::testCase,
-	&Benchmark::CompareIsrDfcCb::Dfc::_4Bytes::testCase,
-	&Benchmark::CompareIsrDfcCb::Isr::_4Bytes::testCase,
-	&Benchmark::CompareIsrDfcCb::Dfc::_4K::testCase,
-	&Benchmark::CompareIsrDfcCb::Isr::_4K::testCase,
-#endif
-	&TestNewStyleFragment_1::testCase,
-	&TestNewStyleFragment_1::testCaseConcurrent,
-	&TestNewStyleFragment_2::testCase,
-	&TestNewStyleFragment_2::testCaseConcurrent,
-	//&TestNewStyleFragment_3::testCase,
-	//&TestNewStyleFragment_3::testCaseConcurrent,
-	&TestNewStyleFragment_4::testCase,
-	&TestNewStyleFragment_4::testCaseConcurrent,
-	&TestNewStyleFragment_5::testCase,
-	&TestNewStyleFragment_5::testCaseConcurrent,
-	&TestNewStyleFragment_6::testCase,
-	&TestNewStyleFragment_6::testCaseConcurrent,
-	&TestOldStyleFragment_1::testCase,
-	&TestOldStyleFragment_1::testCaseConcurrent,
-	&TestOldStyleFragment_2::testCase,
-	&TestOldStyleFragment_2::testCaseConcurrent,
-	//&TestOldStyleFragment_3::testCase,
-	//&TestOldStyleFragment_3::testCaseConcurrent,
-	&TestOldStyleFragment_4::testCase,
-	&TestOldStyleFragment_4::testCaseConcurrent,
-	&TestOldStyleFragment_5::testCase,
-	&TestOldStyleFragment_5::testCaseConcurrent,
-	&TestOldStyleFragment_6::testCase,
-	&TestOldStyleFragment_6::testCaseConcurrent,
-	&TestOldStyleDDmaRequest_1::testCase,
-	&TestOldStyleDDmaRequest_1::testCaseConcurrent,
-	&TestOldStyleDDmaRequest_2::testCase,
-	&TestOldStyleDDmaRequest_2::testCaseConcurrent,
-	&TestNewStyleDDmaRequest_1::testCase,
-	&TestNewStyleDDmaRequest_1::testCaseConcurrent,
-	&TestNewStyleDDmaRequest_2::testCase,
-	&TestNewStyleDDmaRequest_2::testCaseConcurrent,
-};
-
-RPointerArray<TTestCase> TestArray(StaticTestArray, ARRAY_LENGTH(StaticTestArray));
--- a/kerneltest/e32test/dmav2/test_thread.cpp	Tue May 11 17:28:22 2010 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,216 +0,0 @@
-/*
-* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
-* All rights reserved.
-* This component and the accompanying materials are made available
-* under the terms of "Eclipse Public License v1.0"
-* which accompanies this distribution, and is available
-* at the URL "http://www.eclipse.org/legal/epl-v10.html".
-*
-* Initial Contributors:
-* Nokia Corporation - initial contribution.
-*
-* Contributors:
-*
-* Description:
-* Implementation of test_thread.h
-*
-*/
-#include "test_thread.h"
-
-TInt TTestRemote::iCount=0;
-
-TInt TTestRemote::RunFunctor(TAny* aFunctor)
-	{
-	TFunctor& functor = *(TFunctor*)aFunctor;
-	functor();
-	return KErrNone;
-	}
-
-TTestThread::TTestThread(const TDesC& aName, TThreadFunction aFn, TAny* aData, TBool aAutoResume)
-	{
-	Init(aName, aFn, aData, aAutoResume);
-	}
-
-TTestThread::TTestThread(const TDesC& aName, TFunctor& aFunctor, TBool aAutoResume)
-	{
-	Init(aName, RunFunctor, &aFunctor, aAutoResume);
-	}
-
-TTestThread::~TTestThread()
-	{
-	//RTest::CloseHandleAndWaitForDestruction(iThread);
-	iThread.Close();
-	}
-
-void TTestThread::Resume()
-	{
-	iThread.Resume();
-	}
-
-TInt TTestThread::WaitForExitL()
-	{
-	User::WaitForRequest(iLogonStatus);
-	const TInt exitType = iThread.ExitType();
-	const TInt exitReason = iThread.ExitReason();
-
-	__ASSERT_ALWAYS(exitType != EExitPending, User::Panic(_L("TTestThread"),0));
-
-	if(exitType != EExitKill)
-		User::Leave(exitReason);
-
-	return exitReason;
-	}
-
-void TTestThread::Rendezvous(TRequestStatus& aStatus)
-	{
-	iThread.Rendezvous(aStatus);
-	}
-
-void TTestThread::Init(const TDesC& aName, TThreadFunction aFn, TAny* aData, TBool aAutoResume)
-	{
-	TKName name(aName);
-	name.AppendFormat(_L("-%d"), iCount++);
-	TInt r=iThread.Create(name, aFn, KDefaultStackSize, KHeapSize, KHeapSize, aData);
-	if(r!=KErrNone)
-		{
-		RDebug::Printf("RThread::Create failed, code=%d", r);
-		User::Panic(KPanicCat, EThreadCreateFailed);
-		}
-
-	iThread.Logon(iLogonStatus);
-	__ASSERT_ALWAYS(iLogonStatus == KRequestPending, User::Panic(_L("TTestThread"),0));
-
-	if(aAutoResume)
-		iThread.Resume();
-	}
-
-
-CTest::~CTest()
-	{
-	iName.Close();
-	}
-
-void CTest::operator()()
-	{
-	for(TInt i=0; i<iIterations; i++)
-		{
-		RunTest();
-		}
-	}
-
-
-void CTest::Announce() const
-{
-	RDebug::RawPrint(_L("Test: "));
-	PrintTestInfo();
-	RDebug::RawPrint(_L(": "));
-	PrintTestType();
-	RDebug::RawPrint(_L(": "));
-	RDebug::RawPrint(iName);
-	RDebug::RawPrint(_L(": "));
-	RDebug::Printf("(%d iterations)", iIterations);
-}
-
-
-void CTest::PrintTestInfo() const
-	{
-	}
-const TDesC& CTest::Name() const
-	{
-	return iName;
-	}
-
-CTest::CTest(const TDesC& aName, TInt aIterations)
-	:iIterations(aIterations)
-	{
-	iName.CreateL(aName);
-	}
-
-CTest::CTest(const CTest& aOther)
-	:iIterations(aOther.iIterations)
-	{
-	iName.CreateL(aOther.iName);
-	}
-
-void MultipleTestRun(RTest& test, const CTest& aTest, TInt aNumberOfThreads)
-	{
-	RPointerArray<CTest> testArray;
-	RPointerArray<TTestThread> threadArray;
-
-	for(TInt i=0; i<aNumberOfThreads; i++)
-		{
-		//test.Next(_L("Create test thread"));
-		CTest* newTest = aTest.Clone();
-		test_NotNull(newTest);
-
-		TTestThread* thread = new TTestThread(aTest.Name(), *newTest);
-		test_NotNull(thread);
-
-		threadArray.AppendL(thread);
-		testArray.AppendL(newTest);
-		}
-
-	const TInt count = threadArray.Count();
-	for(TInt j=0; j<count; j++)
-		{
-		TTestThread* thread = threadArray[0];
-		
-		TInt r = KErrNone;
-		TRAPD(leaveCode, r = thread->WaitForExitL());
-		if(leaveCode != KErrNone)
-			{
-			test.Printf(_L("Thread %d: Panic code:%d\n"), j, leaveCode);
-			test_KErrNone(leaveCode);
-			}
-
-		if(r!=KErrNone)
-			{
-			test.Printf(_L("Thread Number %d\n"), j);
-			test_KErrNone(r);
-			}
-
-		threadArray.Remove(0);
-		delete thread;
-		}
-	threadArray.Close();
-
-	testArray.ResetAndDestroy();
-	testArray.Close();
-	}
-
-/**
-Runs each CTest in aTests in its own thread
-Returns once all threads have terminated
-*/
-void MultipleTestRun(const RPointerArray<CTest>& aTests)
-	{
-	RTest test(_L("CTest::MultipleTestRun"));
-	RPointerArray<TTestThread> threads;
-
-	const TInt count = aTests.Count();
-
-	TInt i;
-	for(i=0; i<count; i++)
-		{
-		_LIT(KDmaTestThread, "DMA-test-thread");
-		TTestThread* thread = new TTestThread(KDmaTestThread, *aTests[i], EFalse);
-		test_NotNull(thread);
-		TInt r = threads.Append(thread);
-		test_KErrNone(r);
-		}
-
-	for(i=0; i<count; i++)
-		{
-		threads[i]->Resume();
-		}
-
-
-	for(i=0; i<count; i++)
-		{
-		TInt r = threads[i]->WaitForExitL();
-		test_KErrNone(r);
-		}
-
-	threads.ResetAndDestroy();
-	test.Close();
-	}
--- a/kerneltest/e32test/dmav2/test_thread.h	Tue May 11 17:28:22 2010 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,140 +0,0 @@
-/*
-* Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
-* All rights reserved.
-* This component and the accompanying materials are made available
-* under the terms of "Eclipse Public License v1.0"
-* which accompanies this distribution, and is available
-* at the URL "http://www.eclipse.org/legal/epl-v10.html".
-*
-* Initial Contributors:
-* Nokia Corporation - initial contribution.
-*
-* Contributors:
-*
-* Description: Some helper classes to assist with writing multi-threaded tests
-*
-*/
-
-
-#ifndef __TEST_THREAD_H__
-#define __TEST_THREAD_H__
-
-#include <e32base.h>
-#include <e32debug.h>
-#define __E32TEST_EXTENSION__
-#include <e32test.h>
-#include <e32cmn_private.h>
-
-_LIT(KPanicCat, "test_thread.h");
-
-
-static const TInt KHeapSize=0x2000;
-
-enum TPanicCode
-	{
-	EThreadCreateFailed
-	};
-
-/**
-A utility class for running functions in other threads/processes
-*/
-class TTestRemote
-	{
-public:
-	virtual TInt WaitForExitL() = 0;
-	virtual ~TTestRemote()
-		{}
-
-	virtual void Rendezvous(TRequestStatus& aStatus) = 0;
-
-protected:
-	TTestRemote()
-		{}
-
-	static TInt RunFunctor(TAny* aFunctor);
-
-	TRequestStatus iLogonStatus;
-	static TInt iCount;
-	};
-
-class TTestThread : public TTestRemote
-	{
-public:
-	TTestThread(const TDesC& aName, TThreadFunction aFn, TAny* aData, TBool aAutoResume=ETrue);
-
-	/**
-	Run aFunctor in another thread
-	*/
-	TTestThread(const TDesC& aName, TFunctor& aFunctor, TBool aAutoResume=ETrue);
-
-	~TTestThread();
-
-	void Resume();
-
-	/**
-	If thread exited normally, return its return code
-	Otherwise, leave with exit reason
-	*/
-	virtual TInt WaitForExitL();
-
-	virtual void Rendezvous(TRequestStatus& aStatus);
-
-private:
-	void Init(const TDesC& aName, TThreadFunction aFn, TAny* aData, TBool aAutoResume);
-
-	RThread iThread;
-	};
-
-class CTest : public CBase, public TFunctor
-	{
-public:
-	~CTest();
-
-	virtual void operator()();
-	virtual void RunTest() = 0;
-	virtual CTest* Clone() const = 0;
-
-	/**
-	Prints a formatted description of the test
-	*/
-	void Announce() const;
-
-	const TDesC& Name() const;
-
-	/**
-	Should print the type of test, with no newlines.
-	eg. "Transfer", "Fragmentation"
-	TODO drop the function, just add a test type member
-	*/
-	virtual void PrintTestType() const = 0;
-
-	/**
-	Display any information about test environment, with no newlines
-	eg. "DMA channel 16"
-	The base class version prints nothing.
-	*/
-	virtual void PrintTestInfo() const;
-
-protected:
-	CTest(const TDesC& aName, TInt aIterations);
-	CTest(const CTest& aOther);
-
-	//It would be useful to have an RTest member, but this can't be
-	//initialised untill the new thread is running as it will refer to
-	//the creating thread
-	RBuf iName;
-	const TInt iIterations;
-	};
-
-/**
-Make aNumberOfThreads copies of aTest and run
-each in its own thread
-
-@param test Reference to test object
-@param aTest Referance
-*/
-void MultipleTestRun(RTest& test, const CTest& aTest, TInt aNumberOfThreads);
-
-void MultipleTestRun(const RPointerArray<CTest>& aTests);
-#endif // #ifndef __TEST_THREAD_H__
-
--- a/kerneltest/e32test/group/bld.inf	Tue May 11 17:28:22 2010 +0300
+++ b/kerneltest/e32test/group/bld.inf	Tue May 25 14:09:55 2010 +0300
@@ -1,4 +1,4 @@
-// Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies).
+// Copyright (c) 1999-2010 Nokia Corporation and/or its subsidiary(-ies).
 // All rights reserved.
 // This component and the accompanying materials are made available
 // under the terms of the License "Eclipse Public License v1.0"
@@ -154,9 +154,6 @@
 #if defined(EPOC32) && !defined(X86)
 // Test LDD for real hardware DMA
 d_dma						support
-d_dma2						support
-d_dma_compat				support
-d_dma2_compat				support
 #endif
 
 #ifdef EPOC32
@@ -871,7 +868,6 @@
 
 // /E32TEST/DMA tests
 t_dma       // user-side test harness for real DMA framework
-t_dma2       // user-side test harness for DMAv2 framework
 
 // Example RTOS personality
 ../personality/example/t_expers support
--- a/kerneltest/e32test/group/d_dma2.mmp	Tue May 11 17:28:22 2010 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,52 +0,0 @@
-// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
-// All rights reserved.
-// This component and the accompanying materials are made available
-// under the terms of "Eclipse Public License v1.0"
-// which accompanies this distribution, and is available
-// at the URL "http://www.eclipse.org/legal/epl-v10.html".
-//
-// Initial Contributors:
-// Nokia Corporation - initial contribution.
-//
-// Contributors:
-//
-// Description:
-//
-
-#include "kernel/kern_ext.mmh"
-
-#ifdef	VariantDmaImportLib
-target		VariantTarget(d_dma2,ldd)
-#else
-target		d_dma2.ldd
-#endif
-
-targettype	ldd
-
-sourcepath	../dmav2
-source		d_dma2.cpp d_dma2_cmn.cpp
-
-#ifdef	VariantDmaImportLib
-library		VariantDmaImportLib
-#else
-library		dma2.lib
-#endif
-
-OS_LAYER_SYSTEMINCLUDE_SYMBIAN
-
-epocallowdlldata
-
-capability	all
-VENDORID 0x70000001
-
-// Don't put this in ROM here since it would stop ROMs building on platforms
-// without DMA support.
-romtarget
-
-#ifdef SMP
-MACRO CPU_AFFINITY_ANY
-#endif
-
-SMPSAFE
-
-MACRO DMA_APIV2
--- a/kerneltest/e32test/group/d_dma2_compat.mmp	Tue May 11 17:28:22 2010 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,53 +0,0 @@
-// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
-// All rights reserved.
-// This component and the accompanying materials are made available
-// under the terms of "Eclipse Public License v1.0"
-// which accompanies this distribution, and is available
-// at the URL "http://www.eclipse.org/legal/epl-v10.html".
-//
-// Initial Contributors:
-// Nokia Corporation - initial contribution.
-//
-// Contributors:
-//
-// Description:
-//
-
-#include "kernel/kern_ext.mmh"
-
-#ifdef	VariantDmaImportLib
-target		VariantTarget(d_dma2_compat,ldd)
-#else
-target		d_dma2_compat.ldd
-#endif
-
-targettype	ldd
-
-sourcepath	../dmav2
-source		d_dma2.cpp d_dma2_cmn.cpp
-
-sourcepath	../../../../kernelhwsrv/kernel/eka/drivers/dma
-source		dma2_shared.cpp
-
-#ifdef	VariantDmaImportLib
-library		VariantDmaImportLib
-#else
-library		dma.lib
-#endif
-
-OS_LAYER_SYSTEMINCLUDE_SYMBIAN
-
-epocallowdlldata
-
-capability	all
-VENDORID 0x70000001
-
-// Don't put this in ROM here since it would stop ROMs building on platforms
-// without DMA support.
-romtarget
-
-#ifdef SMP
-MACRO CPU_AFFINITY_ANY
-#endif
-
-SMPSAFE
--- a/kerneltest/e32test/group/d_dma_compat.mmp	Tue May 11 17:28:22 2010 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,52 +0,0 @@
-// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
-// All rights reserved.
-// This component and the accompanying materials are made available
-// under the terms of "Eclipse Public License v1.0"
-// which accompanies this distribution, and is available
-// at the URL "http://www.eclipse.org/legal/epl-v10.html".
-//
-// Initial Contributors:
-// Nokia Corporation - initial contribution.
-//
-// Contributors:
-//
-// Description:
-//
-
-#include "kernel/kern_ext.mmh"
-
-#ifdef	VariantDmaImportLib
-target		VariantTarget(d_dma_compat,ldd)
-#else
-target		d_dma_compat.ldd
-#endif
-
-targettype	ldd
-
-sourcepath	../dma
-source		d_dma.cpp
-
-#ifdef	VariantDmaImportLib
-library		VariantDmaImportLib
-#else
-library		dma2.lib
-#endif
-
-OS_LAYER_SYSTEMINCLUDE_SYMBIAN
-
-epocallowdlldata
-
-capability	all
-VENDORID 0x70000001
-
-// Don't put this in ROM here since it would stop ROMs building on platforms
-// without DMA support.
-romtarget
-
-#ifdef SMP
-MACRO CPU_AFFINITY_ANY
-#endif
-
-SMPSAFE
-
-MACRO DMA_APIV2
--- a/kerneltest/e32test/group/t_dma2.mmp	Tue May 11 17:28:22 2010 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,30 +0,0 @@
-// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
-// All rights reserved.
-// This component and the accompanying materials are made available
-// under the terms of "Eclipse Public License v1.0"
-// which accompanies this distribution, and is available
-// at the URL "http://www.eclipse.org/legal/epl-v10.html".
-//
-// Initial Contributors:
-// Nokia Corporation - initial contribution.
-//
-// Contributors:
-//
-// Description:
-//
-
-TARGET         t_dma2.exe
-TARGETTYPE     EXE
-SOURCEPATH	../dmav2
-SOURCE         t_dma2.cpp test_cases.cpp self_test.cpp dma_api_tests.cpp d_dma2_cmn.cpp
-SOURCE		   test_thread.cpp
-SOURCEPATH	../../../kernel/eka/drivers/dma
-SOURCE		dma2_shared.cpp
-LIBRARY        euser.lib
-OS_LAYER_SYSTEMINCLUDE_SYMBIAN
-
-CAPABILITY	NONE
-
-VENDORID 0x70000001
-
-SMPSAFE
--- a/kerneltest/e32test/group/t_ramall.mmp	Tue May 11 17:28:22 2010 +0300
+++ b/kerneltest/e32test/group/t_ramall.mmp	Tue May 25 14:09:55 2010 +0300
@@ -19,7 +19,7 @@
 targettype		exe
 sourcepath		../mmu
 source			t_ramall.cpp
-library			euser.lib  dptest.lib
+library			euser.lib  dptest.lib hal.lib
 OS_LAYER_SYSTEMINCLUDE_SYMBIAN
 
 
--- a/kerneltest/e32test/mmu/t_demandpaging.cpp	Tue May 11 17:28:22 2010 +0300
+++ b/kerneltest/e32test/mmu/t_demandpaging.cpp	Tue May 25 14:09:55 2010 +0300
@@ -121,15 +121,18 @@
 
 #define READ(a) ReadByte((volatile TUint8*)(a))
 
-void ThrashPaging(TUint aMaxBytes=KMaxTUint)
+void ThrashPaging(TUint aBytes)
 	{
 	TUint size = LargeBufferSize;
-	if(size>aMaxBytes)
-		size = aMaxBytes;
+	if(size > aBytes)
+		size = aBytes;
 
-	// read all ROM pages about 10 times each in a random order...
+	TUint readCount = 5 * size/PageSize;
+	
+	test.Printf(_L("ThrashPaging %u %u\n"), size, readCount);
+	
 	TUint32 random=1;
-	for(TInt i=size/(PageSize/10); i>0; --i)
+	for(TUint i = 0 ; i < readCount ; ++i)
 		{
 		READ(LargeBuffer+((TInt64(random)*TInt64(size))>>32));
 		random = random*69069+1;
@@ -207,8 +210,51 @@
 	}
 
 
+TInt SetCacheSize(TUint aNewMin, TUint aNewMax)
+	{
+	// set cache size and test 'get' function returns expected values
+	TInt r = DPTest::SetCacheSize(aNewMin, aNewMax);
+	if (r == KErrNone)
+		{
+		TUint min, max, current;
+		test_KErrNone(DPTest::CacheSize(min,max,current));
+		test_Equal(aNewMin, min);
+		test_Equal(aNewMax, max);
+		test(current >= min && current <= max);
+		}
+	return r;
+	}
+
+void DoResizeCache(TUint min, TUint max, TInt result, TUint& sizeMin, TUint& sizeMax, TUint originalMin, TUint originalMax)
+	{
+	test.Printf(_L("DPTest::SetCacheSize min=%u, max=%u, expected result=%d\n"),min/PageSize,max/PageSize,result);
+	TInt r=SetCacheSize(min,max);
+	test_Equal(result, r);
+	if(r==KErrNone)
+		{
+		// we've successfully changed the cache size...
+		if(max)
+			{
+			sizeMin = min;
+			sizeMax = max;
+			}
+		else
+			{
+			sizeMin = originalMin;
+			sizeMax = originalMax;
+			}
+		}
+	else if(r==KErrNoMemory)
+		{
+		// cache size after OOM is unpredictable, so reset our values
+		test_KErrNone(SetCacheSize(sizeMin,sizeMax));
+		}
+	}
+
+
 void TestResizeVMCache()
 	{
+	test.Start(_L("Test resizing VM cache"));
 	TInt r = DPTest::SetCacheSize(0,0); // restore cache size to defaults
 	test(r==KErrNone);
 	TUint sizeMin = 0;
@@ -217,10 +263,42 @@
 	DPTest::CacheSize(sizeMin,sizeMax,currentSize);
 	TUint originalMin = sizeMin;
 	TUint originalMax = sizeMax;
-	test.Printf(_L("original min=%u, original max=%u, current=%u\n"),originalMin/PageSize,originalMax/PageSize,currentSize/PageSize);
+	test.Printf(_L("original min=%u, original max=%u, current=%u\n"),
+				originalMin/PageSize,originalMax/PageSize,currentSize/PageSize);
 
 	int K = currentSize/PageSize+4;
 
+	// Exercise the cache reszing code by testing all valid combinations of the relationships
+	// between the current min size, current max size, new min size and new max size.
+	//
+	// This can be done using four cache size values.  Every assignment of these four values to the
+	// four variables is generated, and invalid combinations rejected.  This repeats some
+	// relationships but is simpler than calculating the minimum set of combinations exactly.
+
+	const TUint combinations = 256;  // 4 ^ 4
+	const TUint sizes[] = { K, K + 4, K + 8, K + 12, K + 16 };
+	for (TUint perm = 0 ; perm < combinations ; ++perm)
+		{
+		TUint vars[4] = { sizes[ perm & 3 ],
+						  sizes[ (perm >> 2) & 3 ],
+						  sizes[ (perm >> 4) & 3 ],
+						  sizes[ (perm >> 6) & 3 ]};
+		if ((vars[0] == vars[2] && vars[1] == vars[3]) || // ensure current != new
+			vars[0] > vars[1] ||                          // ensure current min <= current max
+			vars[2] > vars[3])                            // ensure new min <= new max
+			continue;
+		
+		test.Printf(_L("Test changing cache sizes from %u, %u to %u %u\n"),
+					vars[0], vars[1], vars[2], vars[3]);
+		
+		test_KErrNone(SetCacheSize(PageSize * vars[0], PageSize * vars[1]));
+		ThrashPaging(PageSize * vars[1]);
+		test_KErrNone(SetCacheSize(PageSize * vars[2], PageSize * vars[3]));
+		}
+	test_KErrNone(SetCacheSize(originalMin, originalMax));
+
+	// Now test some more specific resizings
+	
 	struct
 		{
 		TUint iMinPages;
@@ -240,22 +318,20 @@
 			{	K,		K,		KErrNone},
 			{	K+1,	K,		KErrArgument},
 			{	K,		K-1,	KErrArgument},
+			{	K,		K,		KErrNone},
 			{	KMaxTInt,	KMaxTInt,	KErrNoMemory},
 			{	K,		K,		KErrNone},
 
-			{	0,		0,		KErrNone}, // restore defaults
 			{	0,		0,		KMaxTInt} // list end marker
 		};
 
 	for(TInt j=0; j<2; ++j)
 		{
 		if(!j)
-			{
-			test.Start(_L("Changing size of flushed VM cache"));
-			test.Printf(_L("Original cache size min == %u, max == %u\n"),originalMin/PageSize,originalMax/PageSize);
-			}
+			test.Next(_L("Changing size of empty VM cache"));
 		else
 			test.Next(_L("Changing size of full VM cache"));
+		
 		TInt i=0;
 		while(testArgs[i].iResult!=KMaxTInt)
 			{
@@ -263,54 +339,21 @@
 			TUint max=testArgs[i].iMaxPages*PageSize;
 			TInt result=testArgs[i].iResult;
 
-			ThrashPaging(max*2);
 			if(!j)
 				DPTest::FlushCache();
+			else
+				ThrashPaging(max);
 
-			test.Printf(_L("DPTest::SetCacheSize min=%u, max=%u, expected result=%d\n"),min/PageSize,max/PageSize,result);
-			TInt r=DPTest::SetCacheSize(min,max);
-			if(r!=result)
-				{
-				test.Printf(_L("result=%d\n"),r);
-				test(0);
-				}
-			if(r==KErrNone)
-				{
-				// we've successfully changed the cache size...
-				if(max)
-					{
-					sizeMin = min;
-					sizeMax = max;
-					}
-				else
-					{
-					sizeMin = originalMin;
-					sizeMax = originalMax;
-					}
-				}
-			if(r==KErrNoMemory)
-				{
-				// cache size after OOM is unpredictable, so reset our values
-				DPTest::SetCacheSize(sizeMin,sizeMax);
-				}
-			else
-				{
-				// test 'get' function returns expected cache size
-				r=DPTest::CacheSize(min,max,currentSize);
-				test.Printf(_L("DPTest::CacheSize result=%d min=%u max=%u current=%u\n"),r,min/PageSize,max/PageSize,currentSize/PageSize);
-				if(r!=KErrNone || min!=sizeMin || max!=sizeMax)
-					test(0);
-				test(currentSize >= min && currentSize <= max);
-				}
+			DoResizeCache(min, max, result, sizeMin, sizeMax, originalMin, originalMax);
+			
 			++i;
 			}
 		}
-
+	
+	test_KErrNone(SetCacheSize(originalMin, originalMax));
 	test.End();
 	}
 
-
-
 void TestResizeVMCache2()
 	{
 	TUint originalMin = 0;
@@ -1240,6 +1283,8 @@
 	test.Title();
 	
 	test_KErrNone(UserSvr::HalFunction(EHalGroupKernel,EKernelHalPageSizeInBytes,&PageSize,0));
+
+	test.Start(_L("Initialisation"));
 	
 	if (DPTest::Attributes() & DPTest::ERomPaging)
 		test.Printf(_L("Rom paging supported\n"));
@@ -1258,9 +1303,6 @@
 		test(DataPagedChunk.IsPaged()); // this is only ever called if data paging is supported
 		DataPagedBuffer = (TUint8*)DataPagedChunk.Base();
 		}
-		
-	test.Start(_L("Test HAL interface"));
-	TestHAL();
 
 	if (DPTest::Attributes() & DPTest::ERomPaging)
 		{
@@ -1302,6 +1344,9 @@
 		test.End();
 		return 0;
 		}
+		
+	test.Next(_L("Test HAL interface"));
+	TestHAL();
 	
 	test(LargeBufferSize >= KMinBufferSize);
 	SmallBuffer = LargeBuffer;
--- a/kerneltest/e32test/mmu/t_ramall.cpp	Tue May 11 17:28:22 2010 +0300
+++ b/kerneltest/e32test/mmu/t_ramall.cpp	Tue May 25 14:09:55 2010 +0300
@@ -19,6 +19,7 @@
 
 #include <e32test.h>
 #include <e32uid.h>
+#include <hal.h>
 #include <e32hal.h>
 #include <dptest.h>
 #include "d_shadow.h"
@@ -32,7 +33,7 @@
 TInt PageSize;
 TInt PageShift;
 RShadow Shadow;
-TInt InitFreeRam;
+TInt TotalRam;
 RChunk Chunk;
 TUint ChunkCommitEnd;
 RThread TouchThread;
@@ -153,7 +154,7 @@
 	TUint initialFreeRam = FreeRam();
 	TInt r = KErrNone;
 	TUint allocations = 0;
-	for (; allocations <= maxAllocs + 1; allocations++)
+	for(; allocations <= maxAllocs; ++allocations)
 		{
 		TUint freeRam = FreeRam();			
 		r = AllocPhysicalRam(*pa, allocData.iSize, allocData.iAlign);
@@ -165,15 +166,11 @@
 			RDebug::Printf("Error alignment phys addr 0x%08x", *(pa - 1));
 			break;
 			}
-		if (allocData.iCheckFreeRam && freeRam - allocData.iSize != (TUint)FreeRam())
+		TUint newFreeRam = FreeRam();
+		if (allocData.iCheckFreeRam && freeRam - allocData.iSize != newFreeRam)
 			{
 			r = KErrGeneral;
-			RDebug::Printf("Error in free ram 0x%08x orig 0x%08x", FreeRam(), freeRam);
-			}
-		if (allocData.iCheckMaxAllocs && allocations > maxAllocs && r == KErrNone)
-			{
-			r = KErrOverflow;
-			RDebug::Printf("Error able to allocate too many pages");
+			RDebug::Printf("Error in free ram 0x%08x orig 0x%08x", newFreeRam, freeRam);
 			break;
 			}
 		}
@@ -187,10 +184,16 @@
 		}
 	if (failFrees)
 		r = KErrNotFound;
-	if (allocData.iCheckFreeRam && initialFreeRam != (TUint)FreeRam())
+	if (allocData.iCheckMaxAllocs && allocations > maxAllocs)
+		{
+		r = KErrOverflow;
+		RDebug::Printf("Error able to allocate too many pages");
+		}
+	TUint finalFreeRam = FreeRam();
+	if (allocData.iCheckFreeRam && initialFreeRam != finalFreeRam)
 		{
 		r = KErrGeneral;
-		RDebug::Printf("Error in free ram 0x%08x initial 0x%08x", FreeRam(), initialFreeRam);
+		RDebug::Printf("Error in free ram 0x%08x initial 0x%08x", finalFreeRam, initialFreeRam);
 		}
 	delete[] physAddrs;
 	if (r != KErrNone && r != KErrNoMemory)
@@ -218,8 +221,9 @@
 	TRequestStatus* status = new TRequestStatus[aNumThreads];
 	TUint i = 0;
 	for (; i < aNumThreads; i++)
-		{
-		TInt r = threads[i].Create(KNullDesC, FillPhysicalRam, KDefaultStackSize, PageSize, PageSize, (TAny*)&allocData);
+		{// Need enough heap to store addr of every possible allocation + 1.
+		TUint requiredHeapMax = Max(PageSize, ((TotalRam / aSize) * sizeof(TUint32)) + sizeof(TUint32));
+		TInt r = threads[i].Create(KNullDesC, FillPhysicalRam, KDefaultStackSize, PageSize, requiredHeapMax, (TAny*)&allocData);
 		test_KErrNone(r);
 		threads[i].Logon(status[i]);
 		}
@@ -248,6 +252,7 @@
 
 TInt TouchMemory(TAny*)
 	{
+	RThread::Rendezvous(KErrNone);	// Signal that this thread has started running.
 	while (!TouchDataStop)
 		{
 		TUint8* p = Chunk.Base();
@@ -301,8 +306,6 @@
 		{
 		test_KErrNone(Chunk.Decommit(offset, FragData.iSize));
 		}
-	if (!FragData.iFragThread)
-		test_Equal(FreeRam(), freeBlocks * FragData.iSize);
 
 	if (FragData.iDiscard && CacheSizeAdjustable && !FragThreadStop)
 		{
@@ -326,6 +329,7 @@
 
 TInt FragmentMemoryThreadFunc(TAny*)
 	{
+	RThread::Rendezvous(KErrNone);	// Signal that this thread has started running.
 	while (!FragThreadStop)
 		{
 		FragmentMemoryFunc();
@@ -345,7 +349,7 @@
 	FragData.iFragThread = aFragThread;
 
 	TChunkCreateInfo chunkInfo;
-	chunkInfo.SetDisconnected(0, 0, FreeRam());
+	chunkInfo.SetDisconnected(0, 0, TotalRam);
 	chunkInfo.SetPaging(TChunkCreateInfo::EUnpaged);
 	test_KErrNone(Chunk.Create(chunkInfo));
 
@@ -355,7 +359,11 @@
 		test_KErrNone(r);
 		FragThread.Logon(FragStatus);
 		FragThreadStop = EFalse;
+		TRequestStatus threadInitialised;
+		FragThread.Rendezvous(threadInitialised);
 		FragThread.Resume();
+		User::WaitForRequest(threadInitialised);
+		test_KErrNone(threadInitialised.Int());
 		}
 	else
 		{
@@ -369,7 +377,11 @@
 		test_KErrNone(r);
 		TouchThread.Logon(TouchStatus);
 		TouchDataStop = EFalse;
+		TRequestStatus threadInitialised;
+		TouchThread.Rendezvous(threadInitialised);
 		TouchThread.Resume();
+		User::WaitForRequest(threadInitialised);
+		test_KErrNone(threadInitialised.Int());
 		}
 	}
 
@@ -410,7 +422,8 @@
 	allocData.iCheckFreeRam = ETrue;
 	allocData.iSize = aAllocSize;
 	allocData.iAlign = aAllocAlign;
-	FillPhysicalRam(&allocData);
+	TInt r = FillPhysicalRam(&allocData);
+	test_Value(r, r >= 0);
 	UnfragmentMemory(aDiscard, aTouchMemory, EFalse);
 	}
 
@@ -491,8 +504,17 @@
 		ManualTest = cmdLine.Find(KManual) != KErrNotFound;
 		}
 
-	InitFreeRam=FreeRam();
-	test.Printf(_L("Free RAM=%08x, Page size=%x, Page shift=%d\n"),InitFreeRam,PageSize,PageShift);
+	// Turn off lazy dll unloading and ensure any supervisor clean up has completed 
+	// so the free ram checking isn't affected.
+	RLoader l;
+	test(l.Connect()==KErrNone);
+	test(l.CancelLazyDllUnload()==KErrNone);
+	l.Close();
+	UserSvr::HalFunction(EHalGroupKernel, EKernelHalSupervisorBarrier, 0, 0);
+
+	test_KErrNone(HAL::Get(HAL::EMemoryRAM, TotalRam));
+
+	test.Printf(_L("Free RAM=%08x, Page size=%x, Page shift=%d\n"),FreeRam(),PageSize,PageShift);
 
 	test.Next(_L("Open test LDD"));
 	r=Shadow.Open();
--- a/kerneltest/e32test/prime/t_semutx.cpp	Tue May 11 17:28:22 2010 +0300
+++ b/kerneltest/e32test/prime/t_semutx.cpp	Tue May 25 14:09:55 2010 +0300
@@ -38,7 +38,10 @@
 // 
 //
 
+#define __E32TEST_EXTENSION__
 #include <e32test.h>
+#include <u32std.h>
+#include <e32svr.h>
 
 const TInt KMaxBufferSize=10;
 const TInt KMaxArraySize=10;
@@ -221,7 +224,7 @@
 void StartWaitSemThread(RThread& aT, SWaitSem& aW, TThreadPriority aP=EPriorityLess)
 	{
 	TInt r = aT.Create(KNullDesC, &WaitSemThread, 0x1000, 0x1000, 0x1000, &aW);
-	test(r==KErrNone);
+	test_KErrNone(r);
 	aT.SetPriority(aP);
 	aT.Resume();
 	}
@@ -231,9 +234,9 @@
 	TRequestStatus s;
 	aT.Logon(s);
 	User::WaitForRequest(s);
-	test(aT.ExitType()==EExitKill);
-	test(aT.ExitReason()==aResult);
-	test(s.Int()==aResult);
+	test_Equal(EExitKill, aT.ExitType());
+	test_Equal(aResult, aT.ExitReason());
+	test_Equal(aResult, s.Int());
 	CLOSE_AND_WAIT(aT);
 	}
 
@@ -251,7 +254,7 @@
 	TTime final;
 	TInt elapsed=0;
 	TInt r = ws.iSem.CreateLocal(0);
-	test(r==KErrNone);
+	test_KErrNone(r);
 
 	RThread().SetPriority(EPriorityAbsoluteVeryLow);
 	TInt threadcount=0;
@@ -259,7 +262,7 @@
 	while (elapsed<1000000)
 		{
 		r = t.Create(KNullDesC, &DummyThread, 0x1000, NULL, NULL);
-		test(r==KErrNone);
+		test_KErrNone(r);
 		t.SetPriority(EPriorityMore);
 		t.Resume();
 		t.Close();
@@ -307,7 +310,7 @@
 	User::After(200000);
 	t.Resume();
 	WaitForWaitSemThread(t, KErrTimedOut);
-	test(ws.iSem.Wait(1)==KErrNone);
+	test_KErrNone(ws.iSem.Wait(1));
 
 	ws.iTimeout=100000;
 	StartWaitSemThread(t, ws, EPriorityMore);
@@ -316,7 +319,7 @@
 	User::After(50000);
 	t.Resume();
 	WaitForWaitSemThread(t, KErrNone);
-	test(ws.iSem.Wait(1)==KErrTimedOut);
+	test_Equal(KErrTimedOut, ws.iSem.Wait(1));
 
 	RThread t2;
 	ws.iTimeout=100000;
@@ -324,12 +327,12 @@
 	StartWaitSemThread(t2, ws, EPriorityMore);
 	t.Suspend();
 	ws.iSem.Signal();
-	test(t2.ExitType()==EExitKill);
-	test(t.ExitType()==EExitPending);
+	test_Equal(EExitKill, t2.ExitType());
+	test_Equal(EExitPending, t.ExitType());
 	t.Resume();
 	WaitForWaitSemThread(t, KErrTimedOut);
 	WaitForWaitSemThread(t2, KErrNone);
-	test(ws.iSem.Wait(1)==KErrTimedOut);
+	test_Equal(KErrTimedOut, ws.iSem.Wait(1));
 
 	ws.iTimeout=1000000;
 	initial.HomeTime();
@@ -376,11 +379,11 @@
 	initial.HomeTime();
 	StartWaitSemThread(t, ws, EPriorityMore);
 	StartWaitSemThread(t2, ws, EPriorityMuchMore);
-	test(t.ExitType()==EExitPending);
-	test(t2.ExitType()==EExitPending);
+	test_Equal(EExitPending, t.ExitType());
+	test_Equal(EExitPending, t2.ExitType());
 	ws.iSem.Close();
-	test(t.ExitType()==EExitKill);
-	test(t2.ExitType()==EExitKill);
+	test_Equal(EExitKill, t.ExitType());
+	test_Equal(EExitKill, t2.ExitType());
 	WaitForWaitSemThread(t2, KErrGeneral);
 	WaitForWaitSemThread(t, KErrGeneral);
 	final.HomeTime();
@@ -414,23 +417,23 @@
 	test.Next(_L("Producer/Consumer scenario"));
 	// Test Rsemaphore with the producer/consumer scenario	RThread thread1, thread2;
 	TRequestStatus stat1, stat2;
-	test(mutex.CreateLocal()==KErrNone);
-	test(slotAvailable.CreateLocal(KMaxBufferSize)==KErrNone);
-	test(itemAvailable.CreateLocal(0)==KErrNone);
-	test(thread1.Create(_L("Thread1"),Producer,KDefaultStackSize,0x200,0x200,NULL)==KErrNone);
-	test(thread2.Create(_L("Thread2"),Consumer,KDefaultStackSize,0x200,0x200,NULL)==KErrNone);
+	test_KErrNone(mutex.CreateLocal());
+	test_KErrNone(slotAvailable.CreateLocal(KMaxBufferSize));
+	test_KErrNone(itemAvailable.CreateLocal(0));
+	test_KErrNone(thread1.Create(_L("Thread1"),Producer,KDefaultStackSize,0x200,0x200,NULL));
+	test_KErrNone(thread2.Create(_L("Thread2"),Consumer,KDefaultStackSize,0x200,0x200,NULL));
 	thread1.Logon(stat1);
 	thread2.Logon(stat2);
-	test(stat1==KRequestPending);
-	test(stat2==KRequestPending);
+	test_Equal(KRequestPending, stat1.Int());
+	test_Equal(KRequestPending, stat2.Int());
 	thread1.Resume(); 
 	thread2.Resume();
 	User::WaitForRequest(stat1);
 	User::WaitForRequest(stat2);
-	test(stat1==KErrNone);
-	test(stat2==KErrNone);
+	test_KErrNone(stat1.Int());
+	test_KErrNone(stat2.Int());
 	for(TInt jj=0;jj<KNumProducerItems;jj++)
-		test(consumerArray[jj]==jj);		
+		test_Equal(jj, consumerArray[jj]);		
 	
 	test.Next(_L("Close"));
 	mutex.Close();
@@ -443,7 +446,7 @@
 	{
 	RMutex m;
 	test.Start(_L("Create"));
-	test(m.CreateLocal()==KErrNone);
+	test_KErrNone(m.CreateLocal());
 
 	// Test RMutex::IsHeld()
 	test.Next(_L("IsHeld ?"));
@@ -463,7 +466,7 @@
 void TestMutex()
 	{
 	test.Start(_L("Create"));
-	test(mutex.CreateLocal()==KErrNone);
+	test_KErrNone(mutex.CreateLocal());
 	
 	test.Next(_L("Threads writing to arrays test"));
 //
@@ -477,19 +480,19 @@
 //
 	arrayIndex=0;
 	RThread thread1,thread2;	
-	test(thread1.Create(_L("Thread1"),MutexThreadEntryPoint1,KDefaultStackSize,0x2000,0x2000,NULL)==KErrNone);
-	test(thread2.Create(_L("Thread2"),MutexThreadEntryPoint2,KDefaultStackSize,0x2000,0x2000,NULL)==KErrNone);			 
+	test_KErrNone(thread1.Create(_L("Thread1"),MutexThreadEntryPoint1,KDefaultStackSize,0x2000,0x2000,NULL));
+	test_KErrNone(thread2.Create(_L("Thread2"),MutexThreadEntryPoint2,KDefaultStackSize,0x2000,0x2000,NULL));			 
 	TRequestStatus stat1,stat2;
 	thread1.Logon(stat1);
 	thread2.Logon(stat2);
-	test(stat1==KRequestPending);
-	test(stat2==KRequestPending);
+	test_Equal(KRequestPending, stat1.Int());
+	test_Equal(KRequestPending, stat2.Int());
 	thread1.Resume(); 
 	thread2.Resume();
 	User::WaitForRequest(stat1);
 	User::WaitForRequest(stat2);
-	test(stat1==KErrNone);
-	test(stat2==KErrNone); 
+	test_KErrNone(stat1.Int());
+	test_KErrNone(stat2.Int()); 
 	TInt thread1ActualCount=0; 
 	TInt thread2ActualCount=0;
 	TInt ii=0;
@@ -502,10 +505,10 @@
 		ii++;
 		}
 	test.Printf(_L("T1 %d T1ACT %d T2 %d T2ACT %d"),thread1Count,thread1ActualCount,thread2Count,thread2ActualCount);
-	test(thread1ActualCount==thread1Count);
-	test(thread2ActualCount==thread2Count);
-	test(thread1Count==thread2Count);
-	test(thread1Count==(KMaxArraySize>>1));
+	test_Equal(thread1Count, thread1ActualCount);
+	test_Equal(thread2Count, thread2ActualCount);
+	test_Equal(thread2Count, thread1Count);
+	test_Equal((KMaxArraySize>>1), thread1Count);
 	
 	test.Next(_L("Close"));
 	CLOSE_AND_WAIT(thread1);
@@ -521,7 +524,7 @@
 	{
 	
 	test.Start(_L("Create"));
-	test(criticalSn.CreateLocal()==KErrNone);
+	test_KErrNone(criticalSn.CreateLocal());
 
 /***************** TO DO ***********************
 
@@ -551,19 +554,19 @@
 //
 	arrayIndex=0;
 	RThread thread1,thread2;	
-	test(thread1.Create(_L("Thread1"),CriticalSnThreadEntryPoint1,KDefaultStackSize,0x2000,0x2000,NULL)==KErrNone);
-	test(thread2.Create(_L("Thread2"),CriticalSnThreadEntryPoint2,KDefaultStackSize,0x2000,0x2000,NULL)==KErrNone);			 
+	test_KErrNone(thread1.Create(_L("Thread1"),CriticalSnThreadEntryPoint1,KDefaultStackSize,0x2000,0x2000,NULL));
+	test_KErrNone(thread2.Create(_L("Thread2"),CriticalSnThreadEntryPoint2,KDefaultStackSize,0x2000,0x2000,NULL));			 
 	TRequestStatus stat1,stat2;
 	thread1.Logon(stat1);
 	thread2.Logon(stat2);
-	test(stat1==KRequestPending);
-	test(stat2==KRequestPending);
+	test_Equal(KRequestPending, stat1.Int());
+	test_Equal(KRequestPending, stat2.Int());
 	thread1.Resume(); 
 	thread2.Resume();
 	User::WaitForRequest(stat1);
 	User::WaitForRequest(stat2);
-	test(stat1==KErrNone);
-	test(stat2==KErrNone); 
+	test_KErrNone(stat1.Int());
+	test_KErrNone(stat2.Int()); 
 	TInt thread1ActualCount=0; 
 	TInt thread2ActualCount=0;
 	TInt ii=0;
@@ -575,10 +578,10 @@
 			thread2ActualCount++;
 		ii++;
 		}
-	test(thread1ActualCount==thread1Count);
-	test(thread2ActualCount==thread2Count);
-	test(thread1Count==thread2Count);
-	test(thread1Count==(KMaxArraySize>>1));
+	test_Equal(thread1Count, thread1ActualCount);
+	test_Equal(thread2Count, thread2ActualCount);
+	test_Equal(thread2Count, thread1Count);
+	test_Equal((KMaxArraySize>>1), thread1Count);
 
 	test.Next(_L("Close"));
 	CLOSE_AND_WAIT(thread1);
@@ -590,6 +593,16 @@
 
 GLDEF_C TInt E32Main()
 	{	
+	TInt cpus = UserSvr::HalFunction(EHalGroupKernel, EKernelHalNumLogicalCpus, 0, 0);
+	if (cpus != 1)
+		{
+		test(cpus>1);
+		// This test will require compatibility mode (and probably other changes)
+		// to work on SMP - it depends on explicit scheduling order.
+		test.Printf(_L("T_SEMUTX skipped, does not work on SMP\n"));
+		return KErrNone;
+		}	
+	
 
 	test.Title();
  	__UHEAP_MARK;
--- a/kerneltest/e32test/prime/t_semutx2.cpp	Tue May 11 17:28:22 2010 +0300
+++ b/kerneltest/e32test/prime/t_semutx2.cpp	Tue May 25 14:09:55 2010 +0300
@@ -37,7 +37,10 @@
 // 
 //
 
+#define __E32TEST_EXTENSION__
 #include <e32test.h>
+#include <u32std.h>
+#include <e32svr.h>
 
 RMutex M1;
 RMutex M2;
@@ -62,8 +65,8 @@
 //#define MCOUNT(m,c)	test((m).Count() ==(c))
 // mutex count value is not visible for user any more
 #define MCOUNT(m,c) (void)(1)
-#define IDCHECK(x) test(GetNextId()==(x))
-#define NUMCHECK(x)	test(NumIdsPending()==(x))
+#define IDCHECK(x) test_Equal((x), GetNextId())
+#define NUMCHECK(x)	test_Equal((x), NumIdsPending())
 
 #define id0		id[0]
 #define id1		id[1]
@@ -153,38 +156,38 @@
 	TInt count=0;
 	TRequestStatus s;
 	TInt r=t.Create(_L("Test0"),Test0Thread,0x1000,NULL,&count);
-	test(r==KErrNone);
+	test_KErrNone(r);
 	t.Logon(s);
-	test(r==KErrNone);
+	test_KErrNone(r);
 	User::After(10000);		// make sure we have a full timeslice
 	t.Resume();
 
-	test(count==0);			// t shouldn't have run yet
+	test_Equal(0, count);			// t shouldn't have run yet
 	RThread().SetPriority(EPriorityMuchMore);	// shouldn't reschedule (priority unchanged)
-	test(count==0);
+	test_Equal(0, count);
 	RThread().SetPriority(EPriorityMore);	// shouldn't reschedule (priority decreasing, but not enough)
-	test(count==0);
+	test_Equal(0, count);
 	RThread().SetPriority(EPriorityMuchMore);	// shouldn't reschedule (priority increasing)
-	test(count==0);
+	test_Equal(0, count);
 	RThread().SetPriority(EPriorityNormal);	// should reschedule (we go behind t)
-	test(count==1);
+	test_Equal(1, count);
 	RThread().SetPriority(EPriorityLess);	// should reschedule (priority decreasing to below t)
-	test(count==2);
+	test_Equal(2, count);
 	t.SetPriority(EPriorityMuchMore);		// shouldn't reschedule (round-robin, timeslice not expired)
-	test(count==2);
+	test_Equal(2, count);
 	t.SetPriority(EPriorityNormal);			// shouldn't reschedule (t's priority decreasing)
-	test(count==2);
+	test_Equal(2, count);
 	t.SetPriority(EPriorityNormal);			// shouldn't reschedule (t's priority unchanged)
-	test(count==2);
+	test_Equal(2, count);
 	BusyWait(100000);		// use up our timeslice
 	t.SetPriority(EPriorityMuchMore);		// should reschedule (round-robin, timeslice expired)
-	test(count==3);
-	test(s==KRequestPending);
-	test(t.ExitType()==EExitPending);
+	test_Equal(3, count);
+	test_Equal(KRequestPending, s.Int());
+	test_Equal(EExitPending, t.ExitType());
 	t.SetPriority(EPriorityRealTime);		// should reschedule (t increases above current)
-	test(count==4);
-	test(s==KErrNone);						// t should have exited
-	test(t.ExitType()==EExitKill);
+	test_Equal(4, count);
+	test_KErrNone(s.Int());						// t should have exited
+	test_Equal(EExitKill, t.ExitType());
 	User::WaitForRequest(s);
 	RThread().SetPriority(EPriorityMuchMore);
 	t.Close();
@@ -201,11 +204,11 @@
 	{
 	test.Start(_L("Test signalling from wrong thread"));
 	TInt r=M1.CreateLocal();
-	test(r==KErrNone);
+	test_KErrNone(r);
 	M1.Wait();
 	RThread t;
 	r=t.Create(_L("Test1"),Test1Thread,0x1000,NULL,NULL);
-	test(r==KErrNone);
+	test_KErrNone(r);
 	TRequestStatus s;
 	t.Logon(s);
 	t.Resume();
@@ -213,9 +216,9 @@
 	User::SetJustInTime(EFalse);
 	User::WaitForRequest(s);
 	User::SetJustInTime(jit);
-	test(s==EAccessDenied);
-	test(t.ExitType()==EExitPanic);
-	test(t.ExitReason()==EAccessDenied);
+	test_Equal(EAccessDenied, s.Int());
+	test_Equal(EExitPanic, t.ExitType());
+	test_Equal(EAccessDenied, t.ExitReason());
 	test(t.ExitCategory()==_L("KERN-EXEC"));
 	t.Close();
 	M1.Close();
@@ -273,13 +276,13 @@
 
 	test.Next(_L("Create mutex"));
 	TInt r=M1.CreateLocal();
-	test(r==KErrNone);
+	test_KErrNone(r);
 
 	test.Next(_L("Create low priority thread"));
 	TInt lowcount=0;
 	RThread low;
 	r=low.Create(_L("low"),LowThread,0x1000,NULL,&lowcount);
-	test(r==KErrNone);
+	test_KErrNone(r);
 	low.SetPriority(EPriorityMuchLess);
 	test(Exists(_L("low")));
 
@@ -287,42 +290,42 @@
 	TInt medcount=0;
 	RThread med;
 	r=med.Create(_L("med"),MedThread,0x1000,NULL,&medcount);
-	test(r==KErrNone);
+	test_KErrNone(r);
 	med.SetPriority(EPriorityNormal);
 	test(Exists(_L("med")));
 
 	test.Next(_L("Start low priority thread"));
 	low.Resume();
 	User::AfterHighRes(KTestDelay/10);
-	test(lowcount==1);
+	test_Equal(1, lowcount);
 //	MCOUNT(M1,0);
 
 	test.Next(_L("Start medium priority thread"));
 	med.Resume();
 	User::AfterHighRes(KTestDelay/10);
-	test(medcount==1);
+	test_Equal(1, medcount);
 	Kick(med);
 	User::AfterHighRes(KTestDelay/10);
-	test(medcount==2);
+	test_Equal(2, medcount);
 	Kick(med);
 
 	M1.Wait();
-	test(lowcount==1);
-	test(medcount==2);
+	test_Equal(1, lowcount);
+	test_Equal(2, medcount);
 	test.Next(_L("Wait, check medium runs"));
 	User::AfterHighRes(KTestDelay/10);
-	test(medcount==3);
+	test_Equal(3, medcount);
 	M1.Signal();
 
 	test.Next(_L("Create mutex 2"));
 	r=M2.CreateLocal();
-	test(r==KErrNone);
+	test_KErrNone(r);
 
 	test.Next(_L("Create high priority thread"));
 	TInt highcount=0;
 	RThread high;
 	r=high.Create(_L("high"),HighThread,0x1000,NULL,&highcount);
-	test(r==KErrNone);
+	test_KErrNone(r);
 	high.SetPriority(EPriorityMore);
 	test(Exists(_L("high")));
 
@@ -336,15 +339,15 @@
 	User::AfterHighRes(KTestDelay/10);
 //	MCOUNT(M2,0);
 //	MCOUNT(M1,-1);
-	test(highcount==1);
+	test_Equal(1, highcount);
 
 	M2.Wait();
-	test(lowcount==2);
-	test(medcount==3);
-	test(highcount==2);
+	test_Equal(2, lowcount);
+	test_Equal(3, medcount);
+	test_Equal(2, highcount);
 	test.Next(_L("Wait, check medium runs"));
 	User::AfterHighRes(KTestDelay/10);
-	test(medcount==4);
+	test_Equal(4, medcount);
 	M2.Signal();
 
 	test.Next(_L("Kill threads"));
@@ -401,7 +404,7 @@
 	TBuf<4> b;
 	b.Num(n);
 	TInt r=t.Create(b,ThreadFunction,0x1000,NULL,aPtr);
-	test(r==KErrNone);
+	test_KErrNone(r);
 	t.Resume();
 	TUint id=t.Id();
 	test.Printf(_L("id=%d\n"),id);
@@ -516,7 +519,7 @@
 	Count=0;
 	test.Next(_L("Create mutex"));
 	TInt r=M1.CreateLocal();
-	test(r==KErrNone);
+	test_KErrNone(r);
 	MCOUNT(M1,1);
 	MutexWait();
 	MCOUNT(M1,0);
@@ -624,7 +627,7 @@
 	User::After(50000);		// let threads claim mutex
 	MutexWait();
 	MCOUNT(M1,0);			// check no threads waiting
-	test(t[2].ExitType()==EExitKill);	// check t2 has exited
+	test_Equal(EExitKill, t[2].ExitType());	// check t2 has exited
 	t[2].Close();
 	test(!Exists(2));
 	IDCHECK(id2);			// check they ran in order t2,t3,t4,t5,t1
@@ -942,12 +945,12 @@
 		{
 		if (i==3 || i==6 || i==7)
 			{
-			test(t[i].ExitType()==EExitPending);
+			test_Equal(EExitPending, t[i].ExitType());
 			}
 		else
 			{
-			test(t[i].ExitType()==EExitPanic);
-			test(t[i].ExitReason()==EBadHandle);
+			test_Equal(EExitPanic, t[i].ExitType());
+			test_Equal(EBadHandle, t[i].ExitReason());
 			test(t[i].ExitCategory()==_L("KERN-EXEC"));
 			t[i].Close();
 			test(!Exists(i));
@@ -963,8 +966,8 @@
 		{
 		if (i==3 || i==6 || i==7)
 			{
-			test(t[i].ExitType()==EExitPanic);
-			test(t[i].ExitReason()==EBadHandle);
+			test_Equal(EExitPanic, t[i].ExitType());
+			test_Equal(EBadHandle, t[i].ExitReason());
 			test(t[i].ExitCategory()==_L("KERN-EXEC"));
 			t[i].Close();
 			test(!Exists(i));
@@ -1008,11 +1011,11 @@
 	test.Start(_L("Test mutex speed"));
 	TInt count=0;
 	TInt r=M1.CreateLocal();
-	test(r==KErrNone);
+	test_KErrNone(r);
 
 	RThread t;
 	r=t.Create(_L("Speed"),MutexSpeed,0x1000,NULL,&count);
-	test(r==KErrNone);
+	test_KErrNone(r);
 	t.SetPriority(EPriorityRealTime);
 	t.Resume();
 	User::AfterHighRes(1000000);
@@ -1023,7 +1026,7 @@
 
 	TInt count2=0;
 	r=t.Create(_L("Speed2"),MutexSpeed2,0x1000,NULL,&count2);
-	test(r==KErrNone);
+	test_KErrNone(r);
 	t.SetPriority(EPriorityRealTime);
 	t.Resume();
 	User::AfterHighRes(1000000);
@@ -1074,7 +1077,7 @@
 	TBuf<4> b;
 	b.Num(n);
 	TInt r=t.Create(b,SemThreadFunction,0x1000,NULL,aPtr);
-	test(r==KErrNone);
+	test_KErrNone(r);
 	t.Resume();
 	TUint id=t.Id();
 	return id;
@@ -1147,7 +1150,7 @@
 	Count=0;
 	test.Next(_L("Create semaphore"));
 	TInt r=S.CreateLocal(2);
-	test(r==KErrNone);
+	test_KErrNone(r);
 	MCOUNT(S,2);
 	SemWait();
 	MCOUNT(S,1);
@@ -1312,20 +1315,20 @@
 		{
 		if (i==3 || i==7 || i==10)
 			{
-			test(t[i].ExitType()==EExitPending);
+			test_Equal(EExitPending, t[i].ExitType());
 			}
 		else if (i!=5)
 			{
-			test(t[i].ExitType()==EExitPanic);
-			test(t[i].ExitReason()==EBadHandle);
+			test_Equal(EExitPanic, t[i].ExitType());
+			test_Equal(EBadHandle, t[i].ExitReason());
 			test(t[i].ExitCategory()==_L("KERN-EXEC"));
 			t[i].Close();
 			test(!Exists(i));
 			}
 		else
 			{
-			test(t[i].ExitType()==EExitKill);
-			test(t[i].ExitReason()==0);
+			test_Equal(EExitKill, t[i].ExitType());
+			test_Equal(0, t[i].ExitReason());
 			t[i].Close();
 			test(!Exists(i));
 			}
@@ -1340,8 +1343,8 @@
 		{
 		if (i==3 || i==7 || i==10)
 			{
-			test(t[i].ExitType()==EExitPanic);
-			test(t[i].ExitReason()==EBadHandle);
+			test_Equal(EExitPanic, t[i].ExitType());
+			test_Equal(EBadHandle, t[i].ExitReason());
 			test(t[i].ExitCategory()==_L("KERN-EXEC"));
 			t[i].Close();
 			test(!Exists(i));
@@ -1371,11 +1374,11 @@
 	test.Start(_L("Test semaphore speed"));
 	TInt count=0;
 	TInt r=S.CreateLocal(1);
-	test(r==KErrNone);
+	test_KErrNone(r);
 
 	RThread t;
 	r=t.Create(_L("SemSpeed"),SemSpeed,0x1000,NULL,&count);
-	test(r==KErrNone);
+	test_KErrNone(r);
 	t.SetPriority(EPriorityRealTime);
 	t.Resume();
 	User::AfterHighRes(1000000);
@@ -1391,12 +1394,22 @@
 
 GLDEF_C TInt E32Main()
 	{
+	TInt cpus = UserSvr::HalFunction(EHalGroupKernel, EKernelHalNumLogicalCpus, 0, 0);
+	if (cpus != 1)
+		{
+		test(cpus>1);
+		// This test will require compatibility mode (and probably other changes)
+		// to work on SMP - it depends on explicit scheduling order.
+		test.Printf(_L("T_SEMUTX2 skipped, does not work on SMP\n"));
+		return KErrNone;
+		}	
+	
 	test.Title();
 
 	test.Start(_L("Test mutexes and semaphores"));
 	RThread().SetPriority(EPriorityMuchMore);
 	TInt r=Main.Duplicate(RThread());
-	test(r==KErrNone);
+	test_KErrNone(r);
 
 	Test0();
 	Test1();
--- a/kerneltest/e32test/system/t_condvar.cpp	Tue May 11 17:28:22 2010 +0300
+++ b/kerneltest/e32test/system/t_condvar.cpp	Tue May 25 14:09:55 2010 +0300
@@ -56,6 +56,7 @@
 #include <e32ldr.h>
 #include <e32def.h>
 #include <e32def_private.h>
+#include <u32std.h>
 
 RTest test(_L("T_CONDVAR"));
 RMutex M1;
@@ -527,6 +528,16 @@
 
 TInt E32Main()
 	{
+	TInt cpus = UserSvr::HalFunction(EHalGroupKernel, EKernelHalNumLogicalCpus, 0, 0);
+	if (cpus != 1)
+		{
+		test(cpus>1);
+		// This test will require compatibility mode (and probably other changes)
+		// to work on SMP - it depends on explicit scheduling order.
+		test.Printf(_L("T_CONDVAR skipped, does not work on SMP\n"));
+		return KErrNone;
+		}	
+	
 	__KHEAP_MARK;
 	__UHEAP_MARK;
 
--- a/kerneltest/f32test/server/t_falsespace.cpp	Tue May 11 17:28:22 2010 +0300
+++ b/kerneltest/f32test/server/t_falsespace.cpp	Tue May 25 14:09:55 2010 +0300
@@ -13,6 +13,7 @@
 // Description:
 //
 
+#define __E32TEST_EXTENSION__
 #include <f32file.h>
 #include <e32test.h>
 #include <e32svr.h>
@@ -67,7 +68,7 @@
 
     #endif
 
-    test(nRes == KErrNone);
+    test_KErrNone(nRes);
 }
 
 void SynchronousClose(RFs &aSession)
@@ -149,11 +150,11 @@
 
 	test.Start(_L("Fill disk to capacity"));
 	TInt r=TheFs.MkDirAll(KBasePath);
-	test(r==KErrNone || r==KErrAlreadyExists);
+	test_Value(r, r == KErrNone || r==KErrAlreadyExists);
 	gCount=0;
 	TFileName sessionPath;
 	r=TheFs.SessionPath(sessionPath);
-	test(r==KErrNone);
+	test_KErrNone(r);
 	TBuf<128> fileName=KBaseName();
 	
 	TInt64 freespace=0;
@@ -179,7 +180,7 @@
 				else
 					fillfilesize=fillfilesize/2;
 				}
-			test(r==KErrNone || r==KErrDiskFull);
+			test_Value(r, r == KErrNone || r==KErrDiskFull);
 			if(r==KErrNone)
 				gCount++;
 			}
@@ -222,7 +223,7 @@
 	TVolumeInfo v;
 
 	TInt r=TheFs.Volume(v,gTestDrive);
-	test(r==KErrNone);
+	test_KErrNone(r);
 	aFree=v.iFree;
 	}
 
@@ -242,31 +243,31 @@
 	TInt64 diff;
 
 	r=TheFs.GetReserveAccess(gTestDrive);
-	test(r==KErrPermissionDenied);
+	test_Value(r, r == KErrPermissionDenied);
 	
 	//make sure nothing odd happens if we didnt already have access
 	r=TheFs.ReleaseReserveAccess(gTestDrive);
-	test(r==KErrNone);
+	test_KErrNone(r);
 
 	
 	GetFreeDiskSpace(free2);
 
 	r=TheFs.ReserveDriveSpace(gTestDrive,0x1000);
-	test(r==KErrNone);
+	test_KErrNone(r);
 
 	GetFreeDiskSpace(free1);
 	diff = free2 - free1;
 	test(I64INT(diff) > 0xfe0 && I64INT(diff) < 0x1100); 
 	
 	r=TheFs.GetReserveAccess(gTestDrive);
-	test(r==KErrNone);
+	test_KErrNone(r);
 
 	GetFreeDiskSpace(free1);
 	TInt64 temp = free2-free1;
 	test(I64INT(temp)>(-0x90) && I64INT(temp)<0x90);
 	
 	r=TheFs.ReleaseReserveAccess(gTestDrive);
-	test(r==KErrNone);
+	test_KErrNone(r);
 	GetFreeDiskSpace(free1);
 
 	diff = free2 - free1;
@@ -275,24 +276,24 @@
 	
 	//test reallocation of reserved space is possible
 	r=TheFs.ReserveDriveSpace(gTestDrive,0x2000);
-	test(r==KErrNone);
+	test_KErrNone(r);
 
 	//test upper limit of reserved space 
 	r=TheFs.ReserveDriveSpace(gTestDrive,0x2000000);
-	test(r==KErrArgument);
+	test_Value(r, r == KErrArgument);
 
 	r=TheFs.ReserveDriveSpace(gTestDrive,0);
-	test(r==KErrNone);
+	test_KErrNone(r);
 	
 	r=TheFs.GetReserveAccess(gTestDrive);
-	test(r==KErrPermissionDenied);
+	test_Value(r, r == KErrPermissionDenied);
 
 	//make sure nothing odd happens if we didnt already have access
 	r=TheFs.ReleaseReserveAccess(gTestDrive);
-	test(r==KErrNone);
+	test_KErrNone(r);
 	
 	r=TheFs.ReserveDriveSpace(gTestDrive,-45);
-	test(r==KErrArgument);
+	test_Value(r, r == KErrArgument);
 	}
 
 
@@ -315,12 +316,12 @@
 	for(i=0; i<17; i++)
 		{
 		r = sessions[i].Connect();
-		test(r==KErrNone);
+		test_KErrNone(r);
 		}
 
 	test.Next(_L("Test breaching sesson reserve limit"));
 	r=sessions[0].ReserveDriveSpace(gTestDrive,0x10001);
-	test(r==KErrArgument);
+	test_Value(r, r == KErrArgument);
 
 	//Get Volume Free Space
 	r = sessions[0].Volume(v, gTestDrive);
@@ -332,12 +333,12 @@
 		for (i=0; i<16; i++)
 			{
 			r=sessions[i].ReserveDriveSpace(gTestDrive,0x10000);
-			test(r==KErrNone);
+			test_KErrNone(r);
 			}
 
 		//The straw
 		r=sessions[16].ReserveDriveSpace(gTestDrive,0x10);
-		test(r==KErrTooBig);
+		test_Value(r, r == KErrTooBig);
 		}
 	else
 		{
@@ -347,12 +348,12 @@
 		for(i=0; (v.iFree -= 0x10000) >= 0; i++)
 			{
 			r=sessions[i].ReserveDriveSpace(gTestDrive,0x10000);
-			test(r==KErrNone);
+			test_KErrNone(r);
 			}
 
 		//The straw
 		r=sessions[i].ReserveDriveSpace(gTestDrive,0x10000);
-		test(r==KErrDiskFull);
+		test_Value(r, r == KErrDiskFull);
 		}
 
 	//Close Sessions
@@ -379,16 +380,16 @@
 	
 	TInt r=0;
 	r = fs1.Connect();
-	test(r==KErrNone);
+	test_KErrNone(r);
 	r = fs2.Connect();
-	test(r==KErrNone);
+	test_KErrNone(r);
 
 	GetFreeDiskSpace(free1);
 
 	r=fs1.ReserveDriveSpace(gTestDrive,0x10000);
-	test(r==KErrNone);
+	test_KErrNone(r);
 	r=fs2.ReserveDriveSpace(gTestDrive,0x10000);
-	test(r==KErrNone);
+	test_KErrNone(r);
 
 	GetFreeDiskSpace(free2);
 	diff = free1 - free2;
@@ -401,14 +402,14 @@
 	test(I64INT(diff)>0xFA00 && I64INT(diff)<0x103C4); 
 
 	r = fs1.Connect();
-	test(r==KErrNone);
+	test_KErrNone(r);
 
 	GetFreeDiskSpace(free1);
 	diff= free1-free2;
 	test(I64INT(diff)== 0 || I64INT(diff)<0xFA0 ); 
 
 	r=fs1.ReserveDriveSpace(gTestDrive,0x10000);
-	test(r==KErrNone);
+	test_KErrNone(r);
 
 	GetFreeDiskSpace(free2);
 	diff = free1 - free2;
@@ -416,16 +417,16 @@
 
 	// Make sure no reserve space is allocated
 	r=fs1.ReserveDriveSpace(gTestDrive,0);
-	test(r==KErrNone);
+	test_KErrNone(r);
 	r=fs2.ReserveDriveSpace(gTestDrive,0);
-	test(r==KErrNone);
+	test_KErrNone(r);
 
 	// Now fill up the disk
 	FillUpDisk();
 	
 	// Should fail as there is no space
 	r=fs1.ReserveDriveSpace(gTestDrive,0x10000);
-	test(r==KErrDiskFull);
+	test_Value(r, r == KErrDiskFull);
 
 	SynchronousClose(fs1);
 	SynchronousClose(fs2);
@@ -452,7 +453,7 @@
 
 	RFs fs;
 	TInt r=fs.Connect();
-	test(r==KErrNone);
+	test_KErrNone(r);
 	TInt64 freeA(0);
 	TInt64 freeB(0);
 	RFile file;
@@ -465,140 +466,140 @@
 	buf[0]=(TUint16)gCh;
 
 	r=file.Replace(fs, buf, EFileWrite);
-	test(r==KErrNone);
+	test_KErrNone(r);
 
 	r=file.Write(KTestData());
-	test(r==KErrNone);
+	test_KErrNone(r);
 
 	file.Close();
 
 	r=fs.ReserveDriveSpace(gTestDrive,0x10000);		//reserve some disk space
-	test(r==KErrNone);
+	test_KErrNone(r);
 		
 	FillUpDisk();									//fill up the disk
 
 	TVolumeInfo v;									//get disk space
 	r=fs.Volume(v,gTestDrive);
-	test(r==KErrNone);
+	test_KErrNone(r);
 	freeA=v.iFree;
 
 	r=fs.GetReserveAccess(gTestDrive);				//get access to reserve space
-	test(r==KErrNone);
+	test_KErrNone(r);
 
 	r=fs.Volume(v,gTestDrive);						//get disk space
-	test(r==KErrNone);
+	test_KErrNone(r);
 	freeB=v.iFree;
 	
 	r=fs.ReleaseReserveAccess(gTestDrive);			//release reserve space
-	test(r==KErrNone);
+	test_KErrNone(r);
 	
 	test(freeA == (freeB - 0x10000));				//test difference in space is equal to the amount reserved
 
 	r=fs.Volume(v,gTestDrive);						//get disk space
-	test(r==KErrNone);
+	test_KErrNone(r);
 	freeB=v.iFree;
 	test(freeA == freeB);							//check reading is still correct
 	
 	TBuf <20> dir = KDir();
 	dir[0]=(TUint16)gCh;
 	r=fs.MkDir(dir);
-	test(r==KErrDiskFull);
+	test_Value(r, r == KErrDiskFull);
 
 	r=fs.MkDirAll(dir);
-	test(r==KErrDiskFull);
+	test_Value(r, r == KErrDiskFull);
 
 	TFileName temp;
 	TBuf<5> drv = KDrv();
 	drv[0]=(TUint16)gCh;
 	r=file.Temp(fs, drv, temp, EFileWrite);
-	test(r==KErrDiskFull);
+	test_Value(r, r == KErrDiskFull);
 
 	r=file.Replace(fs, buf, EFileWrite);
-	test(r==KErrDiskFull);
+	test_Value(r, r == KErrDiskFull);
 
 	r=file.Create(fs, buf, EFileWrite);
-	test(r==KErrDiskFull);
+	test_Value(r, r == KErrDiskFull);
 
 	r=file.Open(fs, buf, EFileWrite);
-	test(r==KErrNone);
+	test_KErrNone(r);
 
 	r=file.Write(128, KTestData());
 
 	if ((gDriveCacheFlags & EFileCacheWriteOn) && (r == KErrNone))
 		r = file.Flush();
 	
-	test(r==KErrDiskFull);
+	test_Value(r, r == KErrDiskFull);
 
 	r=file.SetSize(0x1000);
-	test(r==KErrDiskFull);
+	test_Value(r, r == KErrDiskFull);
 
 	r=file.SetAtt(KEntryAttHidden,0); 
-	test(r==KErrDiskFull);
+	test_Value(r, r == KErrDiskFull);
 
 	TTime dtime;
 	r=file.SetModified(dtime); 
-	test(r==KErrDiskFull);
+	test_Value(r, r == KErrDiskFull);
 
 	r=file.Set(dtime,KEntryAttHidden,0);
-	test(r==KErrDiskFull);
+	test_Value(r, r == KErrDiskFull);
 
 	r=file.Rename(buf);
-	test(r==KErrDiskFull);
+	test_Value(r, r == KErrDiskFull);
 
 	file.Close();
 
 
 	// Test that we can create a temporary file & write to it after acquiring reserved access, 
 	r=fs.GetReserveAccess(gTestDrive);				//get access to reserve space
-	test(r==KErrNone);
+	test_KErrNone(r);
 
 	r=fs.Volume(v,gTestDrive);						//get disk space
-	test(r==KErrNone);
+	test_KErrNone(r);
 	freeA = v.iFree;
 
 	r=file.Temp(fs, drv, temp, EFileWrite);
-	test(r==KErrNone);
+	test_KErrNone(r);
 
 	r = file.Write(KTestData());
-	test (r == KErrNone);
+	test_KErrNone(r);
 
 	// If write caching is enabled, call RFs::Entry() to flush the file "anonymously"
 	if ((gDriveCacheFlags & EFileCacheWriteOn) && (r == KErrNone))
 		{
 		r = file.Flush();
-		test (r == KErrNone);
+		test_KErrNone(r);
 		}
 
 	r=fs.Volume(v,gTestDrive);						//get disk space
-	test(r==KErrNone);
+	test_KErrNone(r);
 	freeB = v.iFree;
 	test (freeB < freeA);
 
 	file.Close();
 
 	r=fs.ReleaseReserveAccess(gTestDrive);			//release reserve space
-	test(r==KErrNone);
+	test_KErrNone(r);
 
 
 	TBuf<20> newname =KNewName();
 	newname[0]=(TUint16)gCh;
 	r=fs.Rename(buf, newname);
-	test(r==KErrDiskFull);
+	test_Value(r, r == KErrDiskFull);
 
 	r=fs.Replace(buf, newname);
-	test(r==KErrDiskFull);
+	test_Value(r, r == KErrDiskFull);
 
 	r=fs.SetEntry(buf, dtime, KEntryAttHidden, 0);
-	test(r==KErrDiskFull);
+	test_Value(r, r == KErrDiskFull);
 
 	r=fs.CreatePrivatePath(gTestDrive);
-	test(r==KErrDiskFull);
+	test_Value(r, r == KErrDiskFull);
 
 	r=fs.SetVolumeLabel(_L("Moooo"), gTestDrive);
-	test(r==KErrDiskFull);	
+	test_Value(r, r == KErrDiskFull);	
 
 	r=fs.SetModified(buf, dtime);
-	test(r==KErrDiskFull);	
+	test_Value(r, r == KErrDiskFull);	
 
 	SynchronousClose(fs);
 	}
@@ -626,41 +627,41 @@
 	TInt r=KErrNone;
 
 	r=fs1.Connect();
-	test(r==KErrNone);
+	test_KErrNone(r);
 	r=fs2.Connect();
-	test(r==KErrNone);
+	test_KErrNone(r);
 
 	FormatDrive();
 
 	r=fs1.ReserveDriveSpace(gTestDrive,0x10000);		
-	test(r==KErrNone);
+	test_KErrNone(r);
 
 	r=fs2.ReserveDriveSpace(gTestDrive,0x10000);		
-	test(r==KErrNone);
+	test_KErrNone(r);
 
 	FillUpDisk();									
 
 	r=fs1.GetReserveAccess(gTestDrive);				
-	test(r==KErrNone);
+	test_KErrNone(r);
 
 	TBuf<20> dir = KDir();
 	dir[0]=(TUint16)gCh;
 
 
 	r=fs2.MkDir(dir);
-	test(r==KErrDiskFull);
+	test_Value(r, r == KErrDiskFull);
 
 	r=fs1.ReserveDriveSpace(gTestDrive,0); //can not release reserve space while you have reserve access
-	test(r==KErrInUse);
+	test_Value(r, r == KErrInUse);
 
 	r=fs1.ReleaseReserveAccess(gTestDrive);				
-	test(r==KErrNone);
+	test_KErrNone(r);
 
 	r=fs1.ReserveDriveSpace(gTestDrive,0); 
-	test(r==KErrNone);
+	test_KErrNone(r);
 
 	r=fs2.MkDir(dir);
-	test(r==KErrNone);
+	test_KErrNone(r);
 
 	SynchronousClose(fs1);
 	SynchronousClose(fs2);
@@ -741,19 +742,19 @@
 	TRequestStatus tStat[KNumberThreads];
 
 	r=fsess.Connect();
-	test(r==KErrNone);
+	test_KErrNone(r);
 
 	FormatDrive();
 
 	r= fsess.ShareAuto();
-	test(r==KErrNone);
+	test_KErrNone(r);
 
 	GetFreeDiskSpace(free1);
 
 	fsess.ReserveDriveSpace(gTestDrive,0x1000);
 		
 	r = t[0].Create(_L("Sub_Thread1"),RsrvSpaceThread,KDefaultStackSize,KHeapSize,KHeapSize,&fsess); 
-	test(r==KErrNone);
+	test_KErrNone(r);
 
 	t[0].Rendezvous(tStat[0]);
 	t[0].Resume();
@@ -764,7 +765,7 @@
 	test(tStat[0]==KErrNone);
 
 	r = t[1].Create(_L("Sub_Thread2"),SessCloseThread,KDefaultStackSize,KHeapSize,KHeapSize,&fsess); 
-	test(r==KErrNone);
+	test_KErrNone(r);
 
 	t[1].Rendezvous(tStat[1]);
 	t[1].Resume();
@@ -820,12 +821,12 @@
 	fileName[0] = (TUint16)gCh;
 
 	err = theTestSession.Connect();
-	test(err == KErrNone);
+	test_KErrNone(err);
 
 	// determine the cluster size
 	RFile theFile;
 	err=theFile.Replace(theTestSession, fileName, EFileShareAny | EFileWrite);
-	test(err==KErrNone);
+	test_KErrNone(err);
 
 	// Neither notifier should be triggered here
 	err = theFile.SetSize(1);
@@ -876,7 +877,7 @@
 	// "Normal" notifier to trigger but not the "Reserved" notifier
 	//
 	err=theFile.Replace(theTestSession, fileName, EFileShareAny | EFileWrite);
-	test(err==KErrNone);
+	test_KErrNone(err);
 	test((statNrm == KRequestPending) && (statRes == KRequestPending));
 
 	// Neither notifier should be triggered here
@@ -901,7 +902,7 @@
 	err = theTestSession.ReserveDriveSpace(gTestDrive, resSpace * 3);
 	if (err != KErrArgument)	// will have exceeded limit if resSpace = 32K
 		{
-		test(err == KErrNone);
+		test_KErrNone(err);
 		test((statNrm == KErrNone) && (statRes == KRequestPending));
 		}
 
@@ -926,7 +927,7 @@
     
     RFs fs;
     TInt err = fs.Connect();
-    test(err == KErrNone);
+    test_KErrNone(err);
 
     RFile file;
     TBuf<20> fileName;
@@ -934,43 +935,43 @@
     fileName[0] = (TUint16)gCh;
     
     err = fs.ReserveDriveSpace(gTestDrive,0x10000); 
-    test(err == KErrNone);
+    test_KErrNone(err);
 
     err = file.Replace(fs, fileName, EFileWrite);
-    test(err == KErrNone);
+    test_KErrNone(err);
 
     err = file.Write(KTestData);
-    test(err == KErrNone);
+    test_KErrNone(err);
     
     err = file.Flush();
-    test(err == KErrNone);
+    test_KErrNone(err);
     
     file.Close();
     
     err = file.Open(fs, fileName, EFileRead);
-    test(err == KErrNone);
+    test_KErrNone(err);
     
     err = file.Att(att);
-    test(err == KErrNone);
+    test_KErrNone(err);
     
     err = file.Modified(time);
-    test(err == KErrNone);
+    test_KErrNone(err);
     
     file.Close();
     
     FillUpDisk();
     
     err = file.Open(fs, fileName, EFileRead);
-    test(err == KErrNone);
+    test_KErrNone(err);
     
     TUint att1;
     err = file.Att(att1);
-    test(err == KErrNone);
+    test_KErrNone(err);
     test(att1 == att);
     
     TTime time1;
     err = file.Modified(time1);
-    test(err == KErrNone);
+    test_KErrNone(err);
     test(time1 == time);
     
     file.Close();
@@ -1000,7 +1001,7 @@
     TVolumeInfo volInfo;
 	
 	TInt nRes = TheFs.Volume(volInfo,gTestDrive);
-	test(nRes == KErrNone);
+	test_KErrNone(nRes);
 	
     if(volInfo.iSize < K4Gig+K1MegaByte)
 		{
@@ -1014,7 +1015,7 @@
     //-- find out media position of the data region start
     TFatBootSector bootSector;
     nRes = ReadBootSector(TheFs, gTestDrive, 0, bootSector);
-    test(nRes == KErrNone);
+    test_KErrNone(nRes);
     test(bootSector.IsValid());
 
     const TInt64 dataStartPos = bootSector.FirstDataSector() << KDefaultSectorLog2;
@@ -1031,89 +1032,183 @@
     for(i=0; i<MaxDummyFiles; ++i)
 		{
         nRes = CreateFileX(KBaseFN, i, DummyFileLen); 
-        test(nRes == KErrNone);
+        test_KErrNone(nRes);
 		}
 
     //-- 3. create a real file that crosses 4G boundary
     nRes = CreateCheckableStuffedFile(TheFs, KBaseFN, 5*K1MegaByte);
-    test(nRes == KErrNone);
+    test_KErrNone(nRes);
     
     test.Printf(_L("Verifying the file that crosses 4G boundary.\n"));
 
     nRes = VerifyCheckableFile(TheFs, KBaseFN);
-    test(nRes == KErrNone);
+    test_KErrNone(nRes);
 
 	
 	nRes = TheFs.Delete(KBaseFN);
-	test(nRes == KErrNone);
+	test_KErrNone(nRes);
     for(i=0; i<MaxDummyFiles; ++i)
 	    {
         nRes = DeleteFileX(KBaseFN, i); 
-        test(nRes == KErrNone);
+        test_KErrNone(nRes);
 		}
 	}
 
+void TestRAMDriveNotification()
+	{
+	test.Next(_L("Verifying RFs::ReserveDriveSpace() triggers RFs::NotifyDiskSpace() events"));
+
+	TInt64 freeSpace;
+	GetFreeDiskSpace(freeSpace);
+	test.Printf(_L("free space: 0x%Lx bytes\n"), freeSpace);
+
+	// set a notification on half the amount we plan to reserve
+	TInt reserve = 4096;
+	TInt64 trigger = freeSpace - 2048;
+	test.Printf(_L("setting notification for space to fall below: 0x%Lx bytes ... "), trigger);
+	TRequestStatus stat;
+	TheFs.NotifyDiskSpace(trigger, gTestDrive, stat);
+	test_Value(stat.Int(), stat == KRequestPending);
+	test.Printf(_L("ok\n"));
+
+	// reserve the space and validate that this triggers the notification
+	test.Printf(_L("reserving 0x%x bytes ..."), reserve);
+	TInt r = TheFs.ReserveDriveSpace(gTestDrive, reserve);
+	test_KErrNone(r);
+	test.Printf(_L("ok\n"));
+
+	test.Printf(_L("validating that the disk space notification triggered ... "));
+	User::After(2000000);	// 2 seconds should be enough to cause the trigger
+	test_Value(stat.Int(), stat == KErrNone);
+	test.Printf(_L("ok\n"));
+	}
+
+
+
 //-----------------------------------------------------------------------------
+/**
+    Test that the reserving some drive space does not takes more space than required.
+*/
+void Test0()
+{
+    test.Next(_L("test ReserveDriveSpace threshold"));
+
+    TInt nRes;
+    TVolumeIOParamInfo volIop;
+    TInt64 freespace=0;
+
+    //-- 1. format the volume
+    FormatDrive();
+
+    GetFreeDiskSpace(freespace);
+    const TInt64 freeSpace1 = freespace; //-- initial amount of free space on the volume
 
-GLDEF_C void CallTestsL()
+    nRes = TheFs.VolumeIOParam(gTestDrive, volIop);
+    test_KErrNone(nRes);
+    const TInt KClusterSz = volIop.iClusterSize;
+    if(!IsPowerOf2(KClusterSz))
+        {
+        test.Next(_L("The FS hasn't reported a cluster size. The test is inconsistent, skipping"));
+        return;
+        }
+
+    //-- reserve exactly 1 cluster worth drive space.
+    nRes = TheFs.ReserveDriveSpace(gTestDrive, KClusterSz);
+    test_KErrNone(nRes);
+
+    GetFreeDiskSpace(freespace);
+    const TInt64 freeSpace2 = freespace;
+    test((freeSpace1 - freeSpace2) == KClusterSz);
+
+    //-- fill up a drive (it has a reserved space)
+    FillUpDisk();
+
+    //-- delete 1 file; 
+    nRes = DeleteFileX(KBaseName, 0);
+    test_KErrNone(nRes);
+
+    //-- try to create a file with the size that is exacly the same as free space; it should succeed
+    GetFreeDiskSpace(freespace);
+    
+    nRes = CreateEmptyFile(TheFs, _L("\\aaa1"), freespace);
+    test_KErrNone(nRes);
+
+    GetFreeDiskSpace(freespace);
+    test(freespace == 0);
+
+    //-- return the drive space to the system
+	nRes = TheFs.ReserveDriveSpace(gTestDrive,0);
+	test_KErrNone(nRes); 
+
+    //-- release drive space
+    nRes = TheFs.ReleaseReserveAccess(gTestDrive);
+    test_KErrNone(nRes);
+
+    GetFreeDiskSpace(freespace);
+    test(freespace == KClusterSz);
+
+    FormatDrive();
+}
+
+//-----------------------------------------------------------------------------
+void CallTestsL()
 //
 // Do tests relative to session path
 //
 	{
-    //-- set up console output 
-    Fat_Test_Utils::SetConsole(test.Console()); 
+	//-- set up console output 
+	Fat_Test_Utils::SetConsole(test.Console()); 
 	
-	if (UserSvr::DebugMask(2)&0x00000002) // TESTFAST mode set? (for automated test builds)
-		if(IsTestingLFFS())
-			{
-			// Don't run on LFFS (to increase speed of automated testing)
-			test.Printf(_L("TEST NOT RUN FOR THIS DRIVE"));
-			return;
-			}
+	// If TESTFAST mode (for automated test builds) is set, don't run LFFS tests.
+	if ((UserSvr::DebugMask(2) & 0x00000002) && IsTestingLFFS())
+		{
+		test.Printf(_L("TEST NOT RUN FOR LFFS DRIVE"));
+		return;
+		}
 
 	//get the number of the drive we are currently testing
 	TInt r=0;
 	r=RFs::CharToDrive(gSessionPath[0],gTestDrive);
-    test(r==KErrNone);
+	test_KErrNone(r);
 
 	r=RFs::DriveToChar(gTestDrive,gCh);
-	test(r==KErrNone);
-
-    TDriveInfo drv;
-    r = TheFs.Drive(drv, gTestDrive);
-    test(r == KErrNone);
+	test_KErrNone(r);
 
-    if (Is_Win32(TheFs, gTestDrive))
-        {
-        test.Printf(_L("Skipping on emulator %C: drive\n"), gSessionPath[0]);
-        return;
-        }
+	TDriveInfo drv;
+	r = TheFs.Drive(drv, gTestDrive);
+	test_KErrNone(r);
+
+
+	//-- print drive information
+	PrintDrvInfo(TheFs, gTestDrive);
+
 
-    // do not run this test on RAM drive
-    if (drv.iType == EMediaRam)
-        {
-        test.Printf(_L("Test can't run on RAM drive %C:\n"), gSessionPath[0]);
-        return;
-        }
+	// do not run the remainder of this test on RAM drive
+	if (drv.iType == EMediaRam)
+		{
+		TestRAMDriveNotification();	// Test drive space reservations trigger disk space notifications
+		test.Printf(_L("Main tests can't run on RAM drive %C:\n"), gSessionPath[0]);
+		return;
+		}
 
-    //-- print drive information
-    PrintDrvInfo(TheFs, gTestDrive);
+	if (Is_Win32(TheFs, gTestDrive))
+		{
+		test.Printf(_L("Skipping on emulator %C: drive\n"), gSessionPath[0]);
+		return;
+		}
 
-	Test1();	//General test for new APIs
-	Test2();	//Test to ensure drive and session reserve limits are not exceeded
+    Test0();
+	Test1();	// General test for new APIs
+	Test2();	// Test to ensure drive and session reserve limits are not exceeded
 	Test3();
-	Test4();	//test filling the drive and that each checked API fails
+	Test4();	// test filling the drive and that each checked API fails
 	Test5();
 	Test6();
 	Test7();
 	TestForDEF142554();
-	Test2();	//run this test to check reserves are being cleared correctly
+	Test2();	// run this test to check reserves are being cleared correctly
 
 	TestFAT4G_Boundary();
     
-    TurnAllocFailureOff();
+	TurnAllocFailureOff();
 	}
-
-
-
-
--- a/userlibandfileserver/fileserver/etshell/ts_com.cpp	Tue May 11 17:28:22 2010 +0300
+++ b/userlibandfileserver/fileserver/etshell/ts_com.cpp	Tue May 25 14:09:55 2010 +0300
@@ -256,7 +256,7 @@
 			aPath.Insert(0,TheShell->currentPath.Left(2));
 		}
 
-	RFile file;
+	RFile64 file;
 	r=file.Open(CShell::TheFs,aPath,EFileStream);
 	if (r!=KErrNone)	//		File could not be opened
 		{
@@ -1199,11 +1199,23 @@
                 //-- print out cluster size that FS reported
                 TVolumeIOParamInfo volIoInfo;
                 nRes = aFs.VolumeIOParam(aDrvNum, volIoInfo);
-                if(nRes == KErrNone && volIoInfo.iClusterSize >= 512)
+                if(nRes == KErrNone)
                 {
-                    Buf.AppendFormat(_L(", Cluster Sz:%d"), volIoInfo.iClusterSize);
+                    if(volIoInfo.iBlockSize >= 0)
+                    {
+                        Buf.AppendFormat(_L(", BlkSz:%d"), volIoInfo.iBlockSize);
+                    }
+                    
+                    if(volIoInfo.iClusterSize >= 0)
+                    {
+                        Buf.AppendFormat(_L(", ClSz:%d"), volIoInfo.iClusterSize);
+                    }
+
+                    Buf.AppendFormat(_L(", CacheFlags:0x%x"), volInfo.iFileCacheFlags);
+                
                 }
 
+
                 if(Buf.Length())
                 {
                     Buf.Append(_L("\n"));
@@ -1972,7 +1984,7 @@
 	ShellFunction::StripQuotes(aPath);
 
 	ParsePath(aPath);
-	RFile file;
+	RFile64 file;
 	TInt r=file.Open(TheShell->TheFs,aPath,EFileStream);
 	if (r!=KErrNone)
 		return(r);
@@ -3108,7 +3120,7 @@
 TInt ShellFunction::Type(TDes& aPath,TUint aSwitches)
 	{
 	ParsePath(aPath);
-	RFile file;
+	RFile64 file;
 	TInt r=file.Open(TheShell->TheFs,aPath,EFileStreamText|EFileShareReadersOnly);
 	if (r!=KErrNone)
 		return r;
--- a/userlibandfileserver/fileserver/group/release.txt	Tue May 11 17:28:22 2010 +0300
+++ b/userlibandfileserver/fileserver/group/release.txt	Tue May 25 14:09:55 2010 +0300
@@ -1,3 +1,30 @@
+Version 2.00.2057
+=================
+(Made by vfebvre 07/05/2010)
+
+1.	famustaf
+	1.	ou1cimx1#372053 CFileMan malfunctioning in copying
+
+2.	dlyokhin
+	1.	ou1cimx1#372172 File server may request more free space on the volume than necessary
+
+
+Version 2.00.2056
+=================
+(Made by vfebvre 05/05/2010)
+
+1.	niccox
+	1.	ou1cimx1#371021 shostmassstorage capabilities are too high
+
+
+Version 2.00.2055
+=================
+(Made by vfebvre 30/04/2010)
+
+1.	frhofman
+	1.	ou1cimx1#360143 BC Drivers: Os/KernelHwSrv: 2 failures in Base API on Vasco
+
+
 Version 2.00.2054
 =================
 (Made by vfebvre 23/04/2010)
--- a/userlibandfileserver/fileserver/inc/f32file.h	Tue May 11 17:28:22 2010 +0300
+++ b/userlibandfileserver/fileserver/inc/f32file.h	Tue May 25 14:09:55 2010 +0300
@@ -699,27 +699,28 @@
 	{
 public:
 	/**
-	The size of a block in bytes.
-	
-	Reads and writes that are aligned on block boundaries are up to twice as fast as when 
-	mis-aligned.	
-	
-	Read and write operations on certain underlying media is done in blocks.
-	A write operation that modifies only part of a block is less efficient, in general, than
-	one that modifies an entire block. Data throughput degrades linearly for reads and writes in smaller
-	sized units. 
+	The size of a media block in bytes. This is a physical property of a media and returned by the corresponding media driver.
+	This value is usually at least 512 bytes and always a power of 2. For some media types the meaning of this value is 
+    "the min. size of the aligned data buffer which write onto the media doesn't lead to read-modify-write operation."
+    Therefore, reads and writes that are aligned on block boundaries and with lenght of a multiple block size can be much faster.	
+	Read and write operations on certain underlying media is done in blocks. A write operation that modifies only part of a block is less efficient, 
+    in general, than one that modifies an entire block. Data throughput degrades linearly for reads and writes in smaller sized units. 
 	*/
 	TInt iBlockSize;
+	
 	/**
-	The size in bytes of a single disk cluster.
-	
-	Read and write operations that are aligned on cluster boundaries are more efficient.
-	
-	The file system organises and allocates the file data on the disk in clusters where each cluster is
-	one or more blocks. Files that are not zero length occupy at least one cluster of the disk, 
-	so large numbers of very small files use up more disk space than expected. 
+	The size in bytes of a single file system cluster. This is a logical property of the file system. 
+	The file system organises and allocates the data on the disk in clusters where each cluster usually consists of one or more blocks. 
+    Cluster is a minimal unit that the file system allocates on the volume. Thus, a file of 1 byte length occupies 1 cluster.
+
+	Read and write operations that are aligned on cluster boundaries are more efficient from the file system point of view.
+    In some circumstances cluster size can be less than a block size, but it is very inefficient.
+
+    This value is reported by a file system. The value less than 0 indicates a error.
 	*/
 	TInt iClusterSize;
+
+
 	/**
 	The recommended buffer size for optimised reading performance. 
 	
@@ -754,7 +755,7 @@
 
     /** 
     The maximum file size that is supported by the file system mounted on this volume. 
-    Not all file system may provide this parameter;  The value KMaxTUint64 (0xffffffffffffffff) means that this particular file system hasn't 
+    Not all file system may report this parameter;  The value KMaxTUint64 (0xffffffffffffffff) means that this particular file system hasn't 
     provided this information.
     */
     TUint64 iMaxSupportedFileSize;
--- a/userlibandfileserver/fileserver/inc/f32ver.h	Tue May 11 17:28:22 2010 +0300
+++ b/userlibandfileserver/fileserver/inc/f32ver.h	Tue May 25 14:09:55 2010 +0300
@@ -58,6 +58,6 @@
 
 @see TVersion
 */
-const TInt KF32BuildVersionNumber=2054;
+const TInt KF32BuildVersionNumber=2057;
 //
 #endif
--- a/userlibandfileserver/fileserver/sfat32/sl_mnt32.cpp	Tue May 11 17:28:22 2010 +0300
+++ b/userlibandfileserver/fileserver/sfat32/sl_mnt32.cpp	Tue May 25 14:09:55 2010 +0300
@@ -892,6 +892,9 @@
     if(aLevel == EMountVolParamQuery)
         {
         ASSERT(ConsistentState()); //-- volume state shall be consistent, otherwise its parameters do not make sense
+		if(iRamDrive)
+			return KErrNotSupported; //-- it requires knowledge of free space on the volume
+
         switch(aOption)
             {
             //-- Request a certain amount of free space on the volume.
@@ -927,9 +930,6 @@
             //-- A request to obtain size of the mounted volume without blocking (CMountCB::VolumeL() can block).
             case ESQ_MountedVolumeSize:
                 {
-                if(iRamDrive)
-                    return KErrNotSupported; //-- it requires knowledge of free space on the volume
-    
                 TUint64* pVal = (TUint64*)aParam; 
                 *pVal = iSize; //-- physical drive size
 
--- a/userlibandfileserver/fileserver/sfile/sf_file.cpp	Tue May 11 17:28:22 2010 +0300
+++ b/userlibandfileserver/fileserver/sfile/sf_file.cpp	Tue May 25 14:09:55 2010 +0300
@@ -241,7 +241,7 @@
     TUint32 mode=aRequest->Message().Int1();
 	if (anOpen==EFileCreate || anOpen==EFileReplace)
 		{
-		r = CheckDiskSpace(0, aRequest);
+		r = CheckDiskSpace(KMinFsCreateObjTreshold, aRequest);
 		if(r != KErrNone)
             return r;
         
@@ -601,7 +601,7 @@
 	{
 	__PRINT(_L("TFsFileTemp::DoRequestL(CFsRequest* aRequest)"));
     
-    TInt r = CheckDiskSpace(0, aRequest);
+    TInt r = CheckDiskSpace(KMinFsCreateObjTreshold, aRequest);
     if(r != KErrNone)
         return r;
 	
@@ -1652,7 +1652,7 @@
 	{
 	__PRINT(_L("TFsFileSetAtt::DoRequestL(CSessionFs* aSession)"));
     
-    TInt r = CheckDiskSpace(0, aRequest);
+    TInt r = CheckDiskSpace(KMinFsCreateObjTreshold, aRequest);
     if(r != KErrNone)
         return r;
 
@@ -1717,7 +1717,7 @@
 	{
 	__PRINT(_L("TFsFileSetModified::DoRequestL(CFsRequest* aRequest)"));
     
-    TInt r = CheckDiskSpace(0, aRequest);
+    TInt r = CheckDiskSpace(KMinFsCreateObjTreshold, aRequest);
     if(r != KErrNone)
         return r;
 
@@ -1757,7 +1757,7 @@
 	{
 	__PRINT(_L("TFsFileSet::DoRequestL(CFsRequest* aRequest)"));
 
-    TInt r = CheckDiskSpace(0, aRequest);
+    TInt r = CheckDiskSpace(KMinFsCreateObjTreshold, aRequest);
     if(r != KErrNone)
         return r;
 
@@ -1882,7 +1882,7 @@
 	{
 	__PRINT(_L("TFsFileRename::DoRequestL(CFsRequest* aRequest)"));
 
-    TInt r = CheckDiskSpace(0, aRequest);
+    TInt r = CheckDiskSpace(KMinFsCreateObjTreshold, aRequest);
     if(r != KErrNone)
         return r;
 
--- a/userlibandfileserver/fileserver/sfile/sf_nbs.cpp	Tue May 11 17:28:22 2010 +0300
+++ b/userlibandfileserver/fileserver/sfile/sf_nbs.cpp	Tue May 25 14:09:55 2010 +0300
@@ -22,7 +22,7 @@
 	{
 	__PRINT(_L("TFsMkDir::DoRequestL(CFsRequest* aRequest)"));
 
-    TInt r = CheckDiskSpace(0, aRequest);
+    TInt r = CheckDiskSpace(KMinFsCreateObjTreshold, aRequest);
     if(r != KErrNone)
         return r;
 
@@ -143,7 +143,7 @@
 //
 	{
 	__PRINT(_L("TFsRename::DoRequestL(CFsRequest* aRequest)"));
-    TInt r = CheckDiskSpace(0, aRequest);
+    TInt r = CheckDiskSpace(KMinFsCreateObjTreshold, aRequest);
     if(r != KErrNone)
         return r;
 	
@@ -182,7 +182,7 @@
 	{
 	__PRINT(_L("TFsReplace::DoRequestL(CFsRequest* aRequest)"));
 
-    TInt r = CheckDiskSpace(0, aRequest);
+    TInt r = CheckDiskSpace(KMinFsCreateObjTreshold, aRequest);
     if(r != KErrNone)
         return r;
 
@@ -261,7 +261,7 @@
 	{
 	__PRINT(_L("TFsSetEntry::DoRequestL(CFsRequest* aRequest)"));
 
-    TInt r = CheckDiskSpace(0, aRequest);
+    TInt r = CheckDiskSpace(KMinFsCreateObjTreshold, aRequest);
     if(r != KErrNone)
         return r;
 
@@ -892,7 +892,7 @@
 //	create the private path unless it already exists
 //
 	{
-    TInt ret = CheckDiskSpace(0, aRequest);
+    TInt ret = CheckDiskSpace(KMinFsCreateObjTreshold, aRequest);
     if(ret != KErrNone)
         return ret;
 
--- a/userlibandfileserver/fileserver/sfile/sf_std.h	Tue May 11 17:28:22 2010 +0300
+++ b/userlibandfileserver/fileserver/sfile/sf_std.h	Tue May 25 14:09:55 2010 +0300
@@ -144,6 +144,13 @@
 //-- absolute maximum file size that file server supports
 const TUint64 KMaxSupportedFileSize = KMaxTUint64;
 
+//-- this is a speculative value of a min. amount of free space on the volume necessary to create a file, directory etc.
+//-- it is used mostly in "reserve drive space" functionality, which is, actually, fundamentally flawed.
+//-- the problem is that the file server can't know exactly how much space is required to create some fs object on the volume, 
+//-- so, it has to guess. This is a default "sector size" value; the file system can round it up internally to its cluster size if any.
+const TInt KMinFsCreateObjTreshold = KDefaultVolumeBlockSize;
+
+
 //__DATA_CAGING__
 const TUint SHA1_LBLOCK=16;
 const TUint SHA1_HASH=20;
@@ -1839,10 +1846,6 @@
 
 typedef TPckgBuf<TMediaPswdReplyNotifyInfoV1> TMediaPswdReplyNotifyInfoV1Buf;
 
-#if defined(__WINS__)
- TInt MapWindowsFileName(TDes& aBuffer,const TDesC& aFileName);
-#endif
-
 enum TDllFindMethod {EFindInPath, EFindInSystemLibs, EFindInSystemBin, EFindExhausted};
 
 //---------------------------------------------------------------------------------------------------------------------
--- a/userlibandfileserver/fileserver/sfile/sf_svr.cpp	Tue May 11 17:28:22 2010 +0300
+++ b/userlibandfileserver/fileserver/sfile/sf_svr.cpp	Tue May 25 14:09:55 2010 +0300
@@ -590,7 +590,7 @@
 // Set the volume name.
 //
 	{
-    TInt r = CheckDiskSpace(0, aRequest);
+    TInt r = CheckDiskSpace(KMinFsCreateObjTreshold, aRequest);
     if(r != KErrNone)
         return r;
 
--- a/userlibandfileserver/fileserver/sfile/sf_utl.cpp	Tue May 11 17:28:22 2010 +0300
+++ b/userlibandfileserver/fileserver/sfile/sf_utl.cpp	Tue May 25 14:09:55 2010 +0300
@@ -1067,6 +1067,8 @@
 	if(KReservedSpace == 0 || KDriveNumber == EDriveZ)
 	    return KErrNone;
 
+    ASSERT(aThreshold);
+
     //-- if the drive has a reserved space, take it into account
 	CSessionFs* session=aRequest->Session(); 
 
@@ -1074,8 +1076,7 @@
         aThreshold += KReservedSpace;
 
     //-- ask the corresponding file system if there is aThreshold bytes available.
-    //-- for some reason it's required to be strictly > than aThreshold
-    return aRequest->Drive()->RequestFreeSpaceOnMount(aThreshold+1);
+    return aRequest->Drive()->RequestFreeSpaceOnMount(aThreshold);
 	}								
 
 
--- a/userlibandfileserver/fileserver/sfsrv/cl_fman.cpp	Tue May 11 17:28:22 2010 +0300
+++ b/userlibandfileserver/fileserver/sfsrv/cl_fman.cpp	Tue May 25 14:09:55 2010 +0300
@@ -1089,6 +1089,31 @@
 including any directories in the path specified by aNew which do not
 already exist.
 
+If the source (anOld) is a file and the recursive operation is set,
+then all the files with the same name as anOld in the source directory
+including those in subdirectories will be copied to the destination.
+
+For example, the initial directory structure is as follows:
+C:\dir1\file.txt
+C:\dir1\subdirA\file.txt
+C:\dir1\subdirB\file.txt
+
+@code
+CFileMan* fm(CFileMan::NewL(iFs));	// Where iFs is an RFs handle
+fm->Copy(_L("C:\\dir1\\file.txt"), _L("C:\\dir2\\file.txt"), CFileMan::ERecurse);
+// OR without specifying the filename in aNew:
+fm->Copy(_L("C:\\dir1\\file.txt"), _L("C:\\dir2\\"), CFileMan::ERecurse);
+@endcode
+
+Because of the recursive behaviour, the final directory structure after
+either one of the copy operations above will be as follows:
+C:\dir1\file.txt
+C:\dir1\subdirA\file.txt
+C:\dir1\subdirB\file.txt
+C:\dir2\file.txt
+C:\dir2\subdirA\file.txt
+C:\dir2\subdirB\file.txt
+
 If recursive operation is not set, only the matching files located in
 the single directory specified in anOld are copied.
 No intermediate directories will be created; if any directories in
@@ -1122,13 +1147,13 @@
  1.2	If there is no file to operate on i.e. if source directory is empty, the
  	function will do nothing and return error code KErrNotFound.
 
- 2. Files can be copied across drives.
-
- 3. Open files can be copied if they have been opened using
-      the EFileShareReadersOnly file share mode.
-
- 4. Read-only, hidden and system files can be copied and
-   the source file's attributes are preserved in the target file.
+ 2.	Files can be copied across drives.
+
+ 3.	Open files can be copied if they have been opened using
+	the EFileShareReadersOnly file share mode.
+
+ 4.	Read-only, hidden and system files can be copied and
+	the source file's attributes are preserved in the target file.
 
 @param anOld     Path indicating the file(s) to be copied.
                  Any path components which are not specified here will be
@@ -1393,7 +1418,7 @@
   recursively by default and moves both the last directory level and all of its content.
   Notice that no trailing backslash ("\") implies moving files recursively automatically.
 
-For example, if the directory level "b" contains the files F1,F2 and F3, then:
+For example, if the directory level "b" contains the files F1, F2 and F3, then:
 @code
 CFileMan* fm(CFileMan::NewL(iFs)); // Where iFs is an RFs handle
 ...
@@ -1421,7 +1446,7 @@
 0 is passed as an argument, the operation behaves the same way as by passing
 CFileMan::ERecurse flag.
 
-for example:
+For example:
 @code
 CFileMan* fm(CFileMan::NewL(iFs)); // Where iFs is an RFs handle
 ...
@@ -1436,6 +1461,31 @@
 fm->Move(_L("C:\\a\\b"), _L("C:\\x\\y\\"), CFileMan::ERecurse);
 @endcode
 
+If the source (anOld) is a file and the recursive operation is set,
+then all the files with the same name as anOld in the source directory
+including those in subdirectories will be moved to the destination.
+
+For example, the initial directory structure is as follows:
+C:\src\file.txt
+C:\src\subdirA\file.txt
+C:\src\subdirB\file.txt
+
+@code
+CFileMan* fm(CFileMan::NewL(iFs));	// Where iFs is an RFs handle
+fm->Move(_L("C:\\src\\file.txt"), _L("C:\\dest\\file.txt"), CFileMan::ERecurse);
+// OR without specifying the filename in aNew:
+fm->Move(_L("C:\\src\\file.txt"), _L("C:\\dest\\"), CFileMan::ERecurse);
+@endcode
+
+Because of the recursive behaviour, the final directory structure after
+either one of the move operations above will be as follows:
+C:\src\
+C:\src\subdirA\
+C:\src\subdirB\
+C:\dest\file.txt
+C:\dest\subdirA\file.txt
+C:\dest\subdirB\file.txt
+
 Notes:
 
 -# Read-only, hidden and system files can be moved and the source file's
@@ -1443,7 +1493,7 @@
    be moved. Attempting to move an open file will return an error for
    that file, as retrieved by CFileBase::GetLastError().
 
-@param anOld	 Path indicating the files to be moved. May be either a full path, or
+@param anOld	 Path indicating the directory/files to be moved. May be either a full path, or
 				 relative to the session path. Note that if you specify a directory level,
 				 then the behaviour of the move operation is sensitive to the presence
 				 (or absence) of a trailing backslash ("\") character. Any path components
--- a/userlibandfileserver/fileserver/shostmassstorage/client/hostmsclient.mmp	Tue May 11 17:28:22 2010 +0300
+++ b/userlibandfileserver/fileserver/shostmassstorage/client/hostmsclient.mmp	Tue May 25 14:09:55 2010 +0300
@@ -1,4 +1,4 @@
-// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
+// Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
 // All rights reserved.
 // This component and the accompanying materials are made available
 // under the terms of the License "Eclipse Public License v1.0"
@@ -30,7 +30,7 @@
 
 LIBRARY		efsrv.lib euser.lib hal.lib usbdescriptors.lib usbdi_utils.lib
 
-CAPABILITY ALL
+CAPABILITY TCB  ProtServ DiskAdmin AllFiles PowerMgmt CommDD NetworkControl WriteDeviceData
 
 //MACRO _USBMS_DEBUG_PRINT_
 
--- a/userlibandfileserver/fileserver/shostmassstorage/server/hostmsserver.mmp	Tue May 11 17:28:22 2010 +0300
+++ b/userlibandfileserver/fileserver/shostmassstorage/server/hostmsserver.mmp	Tue May 25 14:09:55 2010 +0300
@@ -1,4 +1,4 @@
-// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
+// Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
 // All rights reserved.
 // This component and the accompanying materials are made available
 // under the terms of the License "Eclipse Public License v1.0"
@@ -62,7 +62,7 @@
 BASEADDRESS		0x61000000 
 END
 
-CAPABILITY ALL -Tcb
+CAPABILITY AllFiles CommDD
 
 UID		0 0x10286A83