os/kernelhwsrv/kerneltest/e32test/dma/d_dma.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/dma/d_dma.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,195 @@
     1.4 +// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// e32test\dma\d_dma.h
    1.18 +// User-side API for LDD used to test DMA framework.
    1.19 +// 
    1.20 +//
    1.21 +
    1.22 +#ifndef __D_DMA_H__
    1.23 +#define __D_DMA_H__
    1.24 +
    1.25 +#include <e32cmn.h>
    1.26 +#ifndef __KLIB_H__
    1.27 +#include <e32std.h>
    1.28 +#endif
    1.29 +
    1.30 +#ifdef __DMASIM__
    1.31 +_LIT(KTestDmaLddName, "TestDmaSim");
    1.32 +#else
    1.33 +_LIT(KTestDmaLddName, "TestDma");
    1.34 +#endif
    1.35 +
    1.36 +inline TVersion TestDmaLddVersion() { return TVersion(1, 0, 1); }
    1.37 +
    1.38 +class RTestDma : public RBusLogicalChannel
    1.39 +	{
    1.40 +public:
    1.41 +	struct TFragmentInfo
    1.42 +		{
    1.43 +		TInt iRequestIdx;
    1.44 +		TInt iSrcBufIdx;
    1.45 +		TInt iDestBufIdx;
    1.46 +		TInt iSize;
    1.47 +		TRequestStatus* iRs;
    1.48 +		};
    1.49 +	struct TOpenInfo
    1.50 +		{
    1.51 +		enum { EGetInfo, EOpen } iWhat;
    1.52 +		union
    1.53 +			{
    1.54 +			TAny* iInfo;
    1.55 +			struct
    1.56 +				{
    1.57 +				TUint32 iId;
    1.58 +				TInt iDesCount;
    1.59 +				TInt iMaxTransferSize;
    1.60 +				} iOpen;
    1.61 +			} U;
    1.62 +		};
    1.63 +	enum TControl
    1.64 +		{
    1.65 +		EAllocBuffer,
    1.66 +		EFreeAllBuffers,
    1.67 +		EFillBuffer,
    1.68 +		ECheckBuffer,
    1.69 +		EFragment,
    1.70 +		EExecute,
    1.71 +		EFailNext,
    1.72 +		EFragmentCount,
    1.73 +		EMissInterrupts,
    1.74 +		};
    1.75 +	enum { KMaxChannels = 32 };
    1.76 +	struct TInfo
    1.77 +		{
    1.78 +		TInt iMaxTransferSize;
    1.79 +		TUint iMemAlignMask;
    1.80 +		TInt iMaxSbChannels;
    1.81 +		TUint32 iSbChannels[KMaxChannels];
    1.82 +		TInt iMaxDbChannels;
    1.83 +		TUint32 iDbChannels[KMaxChannels];
    1.84 +		TInt iMaxSgChannels;
    1.85 +		TUint32 iSgChannels[KMaxChannels];
    1.86 +		};
    1.87 +public:
    1.88 +#ifndef __KERNEL_MODE__
    1.89 +	inline TInt GetInfo(TInfo& aInfo);
    1.90 +	inline TInt Open(TUint32 aId, TInt aDesCount, TInt aMaxTransferSize);
    1.91 +	inline TInt AllocBuffer(TInt aBufIdx, TInt aSize);
    1.92 +	inline void FreeAllBuffers();
    1.93 +	inline void FillBuffer(TInt aBufIdx, TUint8 aFillValue);
    1.94 +	inline TBool CheckBuffer(TInt aBufIdx, TUint8 aValue);
    1.95 +	inline TInt Fragment(TInt aRequestIdx, TInt aSrcBufIdx, TInt aDestBufIdx, TInt aSize, TRequestStatus* aRs=NULL);
    1.96 +	inline TInt Execute(const TDesC8& aCmd);
    1.97 +	inline TInt FailNext(TInt aFragmentCount);
    1.98 +	inline TInt FragmentCount(TInt aRequestIdx);
    1.99 +	inline TInt MissNextInterrupts(TInt aInterruptCount);
   1.100 +	inline TBool FragmentCheck(TInt aRequestIdx, TInt aExpectedCount);
   1.101 +#endif
   1.102 +	};
   1.103 +
   1.104 +#ifndef __KERNEL_MODE__
   1.105 +
   1.106 +inline TInt RTestDma::GetInfo(TInfo& aInfo)
   1.107 +	{
   1.108 +	TPckgBuf<TOpenInfo> infoBuf;
   1.109 +	infoBuf().iWhat = TOpenInfo::EGetInfo;
   1.110 +	infoBuf().U.iInfo = &aInfo;
   1.111 +	return DoCreate(KTestDmaLddName, TestDmaLddVersion(), 0, NULL, &infoBuf) == KErrDied ? KErrNone : KErrGeneral;
   1.112 +	}
   1.113 +
   1.114 +inline TInt RTestDma::Open(TUint32 aId, TInt aDesCount, TInt aMaxTransferSize)
   1.115 +	{
   1.116 +	TPckgBuf<TOpenInfo> infoBuf;
   1.117 +	infoBuf().iWhat = TOpenInfo::EOpen;
   1.118 +	infoBuf().U.iOpen.iId = aId;
   1.119 +	infoBuf().U.iOpen.iDesCount = aDesCount;
   1.120 +	infoBuf().U.iOpen.iMaxTransferSize = aMaxTransferSize;
   1.121 +	return DoCreate(KTestDmaLddName, TestDmaLddVersion(), 0, NULL, &infoBuf, EOwnerThread);
   1.122 +	}
   1.123 +
   1.124 +inline TInt RTestDma::AllocBuffer(TInt aBufIdx, TInt aSize)
   1.125 +	{
   1.126 +	return DoControl(EAllocBuffer, (TAny*)aBufIdx, (TAny*)aSize);
   1.127 +	}
   1.128 +
   1.129 +inline void RTestDma::FreeAllBuffers()
   1.130 +	{
   1.131 +	DoControl(EFreeAllBuffers, NULL, NULL);
   1.132 +	}
   1.133 +
   1.134 +inline void RTestDma::FillBuffer(TInt aBufIdx, TUint8 aFillValue)
   1.135 +	{
   1.136 +	DoControl(EFillBuffer, (TAny*)aBufIdx, (TAny*)(TUint)aFillValue);
   1.137 +	}
   1.138 +
   1.139 +inline TBool RTestDma::CheckBuffer(TInt aBufIdx, TUint8 aValue)
   1.140 +	{
   1.141 +	return DoControl(ECheckBuffer, (TAny*)aBufIdx, (TAny*)(TUint)aValue);
   1.142 +	}
   1.143 +
   1.144 +inline TInt RTestDma::Fragment(TInt aRequestIdx, TInt aSrcBufIdx, TInt aDestBufIdx, TInt aSize, TRequestStatus* aRs)
   1.145 +	{
   1.146 +	TFragmentInfo info;
   1.147 +	info.iRequestIdx = aRequestIdx;
   1.148 +	info.iSrcBufIdx = aSrcBufIdx;
   1.149 +	info.iDestBufIdx = aDestBufIdx;
   1.150 +	info.iSize = aSize;
   1.151 +	info.iRs = aRs;
   1.152 +	if (aRs != NULL)
   1.153 +		*aRs = KRequestPending;
   1.154 +	return DoControl(EFragment, &info, NULL);
   1.155 +	}
   1.156 +
   1.157 +inline TInt RTestDma::Execute(const TDesC8& aCmd)
   1.158 +	{
   1.159 +	return DoControl(EExecute, (TDesC8*)&aCmd, NULL);
   1.160 +	}
   1.161 +
   1.162 +inline TInt RTestDma::FailNext(TInt aFragmentCount)
   1.163 +	{
   1.164 +	return DoControl(EFailNext, (TAny*)aFragmentCount, NULL);
   1.165 +	}
   1.166 +
   1.167 +inline TInt RTestDma::FragmentCount(TInt aRequestIdx)
   1.168 +	{
   1.169 +	return DoControl(EFragmentCount, (TAny*)aRequestIdx, NULL);
   1.170 +	}
   1.171 +
   1.172 +inline TInt RTestDma::MissNextInterrupts(TInt aInterruptCount)
   1.173 +	{
   1.174 +	return DoControl(EMissInterrupts, (TAny*)aInterruptCount, NULL);
   1.175 +	}
   1.176 +
   1.177 +/**
   1.178 +@param The number of fragments expected, 0 means don't check
   1.179 +*/
   1.180 +inline TBool RTestDma::FragmentCheck(TInt aRequestIdx, TInt aExpectedCount)
   1.181 +	{
   1.182 +	if(aExpectedCount)
   1.183 +		{
   1.184 +		TInt actualCount = FragmentCount(aRequestIdx);
   1.185 +		if(actualCount == aExpectedCount)
   1.186 +			return ETrue;
   1.187 +		else
   1.188 +			{
   1.189 +			RDebug::Printf("Fragment count error: expected %d, got %d", aExpectedCount, actualCount);
   1.190 +			return EFalse;
   1.191 +			}
   1.192 +		}
   1.193 +	else
   1.194 +		return ETrue;
   1.195 +	}
   1.196 +#endif // #ifndef __KERNEL_MODE__
   1.197 +
   1.198 +#endif