Update contrib.
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
14 * Description: Implmentation of DMAv2 test code, common
15 * to both user and kernel side
18 #ifdef __KERNEL_MODE__
35 TCallbackRecord::TCallbackRecord(
51 //Default iIsrRedoRequestResult is 1 as this is an invalid error code
52 :iResult(aResult), iContext(aContext), iIsrRedoRequestResult(1)
54 SetCount(EDmaCallbackRequestCompletion, aReq);
55 SetCount(EDmaCallbackRequestCompletion_Src, aReqSrc);
56 SetCount(EDmaCallbackRequestCompletion_Dst, aReqDst);
57 SetCount(EDmaCallbackDescriptorCompletion, aDes);
58 SetCount(EDmaCallbackDescriptorCompletion_Src, aDesSrc);
59 SetCount(EDmaCallbackDescriptorCompletion_Dst, aDesDst);
60 SetCount(EDmaCallbackFrameCompletion, aFrame);
61 SetCount(EDmaCallbackFrameCompletion_Src, aFrameSrc);
62 SetCount(EDmaCallbackFrameCompletion_Dst, aFrameDst);
63 SetCount(EDmaCallbackLinkedListPaused, aPause);
64 SetCount(EDmaCallbackLinkedListPaused_Src, aPauseSrc);
65 SetCount(EDmaCallbackLinkedListPaused_Dst, aPauseDst);
68 TCallbackRecord TCallbackRecord::Empty()
70 return TCallbackRecord(EInvalid,0,0,0,0,0,0,0,0,0,0,0,0,EDmaResultError);
73 void TCallbackRecord::Reset()
75 new (this) TCallbackRecord();
78 TBool TCallbackRecord::operator == (const TCallbackRecord aOther) const
80 return (memcompare((TUint8*)this, sizeof(*this), (TUint8*)&aOther, sizeof(aOther)) == 0);
83 TInt TCallbackRecord::GetCount(TDmaCallbackType aCbType) const
85 const TInt index = BitToIndex(aCbType);
86 return iCallbackLog[index];
89 void TCallbackRecord::SetCount(TDmaCallbackType aCbType, TInt aCount)
91 const TInt index = BitToIndex(aCbType);
92 iCallbackLog[index] = aCount;
95 TInt TCallbackRecord::BitToIndex(TDmaCallbackType aCbType) const
97 const TInt index = Log2(aCbType);
98 TEST_ASSERT(index >=0 && index < KNumberOfCallbacks);
103 void TCallbackRecord::ProcessCallback(TUint aCallbackMask, TDmaResult aResult)
105 // This function may be called several
106 // times and will accumulate the number of each callback
107 // received. However, it will only ever remember the last
108 // result and context value,
110 iContext = CurrentContext();
111 TEST_ASSERT(iContext != EInvalid);
113 for(TInt i=0; i < KNumberOfCallbacks; i++)
115 if(aCallbackMask & 1)
121 // Assert that we have handled all bits
122 // if not then maybe KNumberOfCallbacks is too small
123 // or there is a spurious bit in aCallbackMask
124 TEST_ASSERT(aCallbackMask == 0);
127 TCallbackRecord::TCbContext TCallbackRecord::CurrentContext() const
129 #ifdef __KERNEL_MODE__
130 switch(NKern::CurrentContext())
134 case NKern::EInterrupt:
136 case NKern::EIDFC: //fall-through
137 case NKern::EEscaped:
142 //for the benefit of user-mode testing
147 void TCallbackRecord::Print() const
149 PRINT(GetCount(EDmaCallbackRequestCompletion));
150 PRINT(GetCount(EDmaCallbackRequestCompletion_Src));
151 PRINT(GetCount(EDmaCallbackRequestCompletion_Dst));
152 PRINT(GetCount(EDmaCallbackDescriptorCompletion));
153 PRINT(GetCount(EDmaCallbackDescriptorCompletion_Src));
154 PRINT(GetCount(EDmaCallbackDescriptorCompletion_Dst));
155 PRINT(GetCount(EDmaCallbackFrameCompletion));
156 PRINT(GetCount(EDmaCallbackFrameCompletion_Src));
157 PRINT(GetCount(EDmaCallbackFrameCompletion_Dst));
158 PRINT(GetCount(EDmaCallbackLinkedListPaused));
159 PRINT(GetCount(EDmaCallbackLinkedListPaused_Src));
160 PRINT(GetCount(EDmaCallbackLinkedListPaused_Dst));
163 PRINT(iIsrRedoRequestResult);
166 TDmacTestCaps::TDmacTestCaps()
171 TDmacTestCaps::TDmacTestCaps(const SDmacCaps& aDmacCaps, TInt aVersion)
172 :SDmacCaps(aDmacCaps), iPILVersion(aVersion)
175 TAddrRange::TAddrRange(TUint aStart, TUint aLength)
176 :iStart(aStart), iLength(aLength)
178 TEST_ASSERT(iLength > 0);
181 TBool TAddrRange::Contains(TAddrRange aRange) const
183 return Contains(aRange.Start()) && Contains(aRange.End());
186 TBool TAddrRange::Overlaps(const TAddrRange& aRange) const
188 return (aRange.Contains(iStart) || aRange.Contains(End()) ||
189 Contains(aRange.Start()) || Contains(aRange.End()));
192 If addresses have been left as KPhysAddrInvalid or the count as 0
193 (ie. the default values used for IsrRedoRequest)
194 then substitute the values from aTransferArgs.
196 void TAddressParms::Substitute(const TDmaTransferArgs& aTransferArgs)
198 if(iSrcAddr == KPhysAddrInvalidUser)
199 iSrcAddr = aTransferArgs.iSrcConfig.iAddr;
201 if(iDstAddr == KPhysAddrInvalidUser)
202 iDstAddr = aTransferArgs.iDstConfig.iAddr;
204 if(iTransferCount == 0)
205 iTransferCount = aTransferArgs.iTransferCount;
209 Addresses are converted into absolute,
210 addresses (virtual in user mode, physical in kernel)
211 unless they are KPhysAddrInvalid
213 void TAddressParms::Fixup(TLinAddr aChunkBase)
215 if(iSrcAddr != KPhysAddrInvalidUser)
217 iSrcAddr += aChunkBase;
219 #ifdef __KERNEL_MODE__
220 iSrcAddr = Epoc::LinearToPhysical(iSrcAddr);
221 TEST_ASSERT(iSrcAddr != KPhysAddrInvalid);
224 #ifndef __KERNEL_MODE__
227 // Substitute must be called before
228 // Fixup on user side
233 if(iDstAddr != KPhysAddrInvalidUser)
235 iDstAddr += aChunkBase;
237 #ifdef __KERNEL_MODE__
238 iDstAddr = Epoc::LinearToPhysical(iDstAddr);
239 TEST_ASSERT(iDstAddr != KPhysAddrInvalid);
242 #ifndef __KERNEL_MODE__
245 // Substitute must be called before
246 // Fixup on user side
252 TBool TAddressParms::CheckRange(TLinAddr aStart, TUint aSize)
254 TAddrRange chunk(aStart, aSize);
255 return chunk.Contains(SourceRange()) && chunk.Contains(DestRange());
259 @return ETrue if the source or destination range of this object
262 TBool TAddressParms::Overlaps(const TAddrRange aRange) const
264 return SourceRange().Overlaps(aRange) || DestRange().Overlaps(aRange);
268 @return ETrue if either the source or dest range of this
269 overlap with either of those of aParm
271 TBool TAddressParms::Overlaps(const TAddressParms aParm) const
273 return Overlaps(aParm.SourceRange()) || Overlaps(aParm.DestRange());
276 TBool TAddressParms::operator==(const TAddressParms& aOther) const
278 return iSrcAddr == aOther.iSrcAddr &&
279 iDstAddr == aOther.iDstAddr &&
280 iTransferCount == aOther.iTransferCount;
283 TAddressParms GetAddrParms(const TDmaTransferArgs& aArgs)
285 return TAddressParms(aArgs);
288 TAddrRange TAddressParms::SourceRange() const
290 return TAddrRange(iSrcAddr, iTransferCount);
293 TAddrRange TAddressParms::DestRange() const
295 return TAddrRange(iDstAddr, iTransferCount);
298 void SetAddrParms(TDmaTransferArgs& aTransferArgs, const TAddressParms& aAddrParams)
300 aTransferArgs.iSrcConfig.iAddr = aAddrParams.iSrcAddr;
301 aTransferArgs.iDstConfig.iAddr = aAddrParams.iDstAddr;
302 aTransferArgs.iTransferCount = aAddrParams.iTransferCount;
305 TIsrRequeArgs TIsrRequeArgsSet::GetArgs()
307 TEST_ASSERT(!IsEmpty());
308 const TIsrRequeArgs args(iRequeArgs[iIndex]);
315 void TIsrRequeArgsSet::Substitute(const TDmaTransferArgs& aTransferArgs)
317 for(TInt i=0; i<iCount; i++)
319 iRequeArgs[i].Substitute(aTransferArgs);
322 void TIsrRequeArgsSet::Fixup(TLinAddr aChunkBase)
324 for(TInt i=0; i<iCount; i++)
326 iRequeArgs[i].Fixup(aChunkBase);