Update contrib.
1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\dmav2\d_dma2.h
15 // User-side API for LDD used to test DMAv2 framework.
23 #include <drivers/dmadefs.h>
26 #define ARRAY_LENGTH(ARRAY) sizeof(ARRAY)/sizeof(ARRAY[0])
28 #ifdef __KERNEL_MODE__
31 #define TEST_FAULT FAULT();
32 #define PRINT(N) Kern::Printf("%s = 0x%08x (%d)", #N, (N), (N))
36 #define TEST_FAULT RDebug::Printf("Assertion failure in %s, %d", __FILE__, __LINE__); User::Invariant()
37 #define PRINT(N) RDebug::Printf("%s = 0x%08x (%d)", #N, (N), (N))
40 #define TEST_ASSERT(C) if(!(C)) {TEST_FAULT;}
42 const TUint KPhysAddrInvalidUser=0xFFFFFFFFu; // KPhysAddrInvalid is not defined on the user side
43 #ifdef __KERNEL_MODE__
44 //if this fails then KPhysAddrInvalidUser must be updated to match
46 __ASSERT_COMPILE(KPhysAddrInvalidUser == KPhysAddrInvalid);
50 _LIT(KTestDmaLddName, "TestDmaV2");
52 inline TVersion TestDmaLddVersion() { return TVersion(1, 0, 1); }
57 Indicates the number of each type of call back received
60 TODO as yet, it does not indicate the context of each callback, only
63 const TInt KNumberOfCallbacks = 12;
69 { EInvalid, EThread, EIsr };
72 TCbContext aContext = EThread,
88 TDmaResult aResult = EDmaResultOK
91 static TCallbackRecord Empty();
96 Allows 2 callback records to be compared
98 TBool operator == (const TCallbackRecord aOther) const;
102 Get the number of callbacks for callback aCbType
104 TInt GetCount(TDmaCallbackType aCbType) const;
106 void SetCount(TDmaCallbackType aCbType, TInt aCount);
109 Set the result (expected or actual) from
110 TDmaChannel::IsrRedoRequest
112 inline TCallbackRecord& IsrRedoResult(TInt aResult) {iIsrRedoRequestResult = aResult; return *this;}
115 Reports the context in which the callback occurred.
117 inline TCbContext GetContext()
121 Updates data based on callback mask aCallbackMask
122 @param aCallbackMask Bitmask of callback events @see TDmaCallbackType
123 @oaram aResult The result reported by the current callback
125 void ProcessCallback(TUint aCallbackMask, TDmaResult aResultaContext);
127 static void SelfTest();
129 // The below methods are setters, which may be chained together
130 // ie. The Named Parameter Idiom
131 // @see http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.18
132 TCallbackRecord& Context(TCbContext aContext) {iContext = aContext; return *this;}
135 TInt BitToIndex(TDmaCallbackType aCbType) const;
137 TCbContext CurrentContext() const;
139 TInt iCallbackLog[KNumberOfCallbacks];
143 /** Result of the most recent redo request call */
144 TInt iIsrRedoRequestResult;
148 Extends SDmacCaps to contain the DMA PIL
151 struct TDmacTestCaps : public SDmacCaps
154 TDmacTestCaps(const SDmacCaps& aDmacCaps, TInt aVersion = 2);
164 TAddrRange(TUint aStart, TUint aLength);
165 inline TUint End() const {return (iStart + iLength -1);}
166 inline TUint Start() const {return iStart;}
168 inline TBool Contains(TUint aValue) const {return Rng(iStart, aValue, End());}
169 TBool Contains(TAddrRange aRange) const;
171 TBool Overlaps(const TAddrRange& aRange) const;
172 static void SelfTest();
182 TAddressParms(TUint32 aSrcAddr=0, TUint32 aDstAddr=0, TUint aTransferCount=0)
183 :iSrcAddr(aSrcAddr), iDstAddr(aDstAddr), iTransferCount(aTransferCount)
186 TAddressParms(const TDmaTransferArgs& aArgs)
187 :iSrcAddr(aArgs.iSrcConfig.iAddr),
188 iDstAddr(aArgs.iDstConfig.iAddr),
189 iTransferCount(aArgs.iTransferCount)
193 If any src, dst, or transfer count are zero, substitute the values from
194 aTransferArgs in their place
196 void Substitute(const TDmaTransferArgs& aTransferArgs);
199 When recieved by the test driver, src and dst
200 addresses will be offsets from the dma test session's
201 chunk base. They must be converted to absolute, *physical* addresses
203 void Fixup(TLinAddr aChunkBase);
206 Check that both the src and destination lie within the area
207 defined by aStart and aSize
209 TBool CheckRange(TLinAddr aStart, TUint aSize);
211 TAddrRange SourceRange() const;
212 TAddrRange DestRange() const;
214 TBool Overlaps(const TAddrRange aRange) const;
215 TBool Overlaps(const TAddressParms aParm) const;
217 TBool operator==(const TAddressParms& aOther) const;
219 static void SelfTest();
223 TUint iTransferCount;
226 // These functions can be used for accessing TDmaTransferArgs in
227 // terms of TAddressParms. (TAddressParms would be a natural base
228 // class for TDmaTransferArgs but changing the production code
230 TAddressParms GetAddrParms(const TDmaTransferArgs&);
231 void SetAddrParms(TDmaTransferArgs&, const TAddressParms&);
234 This struct holds the arguments which can be used with TDmaChannel::IsrRedoRequest
236 struct TIsrRequeArgs : public TAddressParms
238 TIsrRequeArgs(TUint32 aSrcAddr=KPhysAddrInvalidUser, TUint32 aDstAddr=KPhysAddrInvalidUser,
239 TUint aTransferCount=0, TUint32 aPslRequestInfo=0,
241 : TAddressParms(aSrcAddr, aDstAddr, aTransferCount), iPslRequestInfo(aPslRequestInfo), iIsrCb(aIsrCb)
245 TInt Call(TDmaChannel& aChannel);
247 TBool CheckRange(TLinAddr aStart, TUint aSize) const;
249 TUint32 iPslRequestInfo;
254 A collection of TIsrRequeArgs
256 struct TIsrRequeArgsSet
259 friend class CIsrRequeTest; //TODO see line 394 t_dma2.cpp
260 TIsrRequeArgsSet(TIsrRequeArgs* aRequeueArgs=NULL, TInt aCount =0)
261 :iCount(aCount), iIndex(0)
263 TEST_ASSERT(iCount <= MaxCount);
264 for(TInt i=0; i<iCount; i++)
266 iRequeArgs[i] = aRequeueArgs[i];
271 TBool IsEmpty() const
272 {return iCount == 0;}
274 TIsrRequeArgs GetArgs();
276 void Substitute(const TDmaTransferArgs& aTransferArgs);
277 void Fixup(TLinAddr aChunkBase);
278 TBool CheckRange(TLinAddr aAddr, TUint aSize) const;
284 TIsrRequeArgs iRequeArgs[MaxCount];
287 class DDmaTestSession;
288 class RDmaSession : public RBusLogicalChannel
290 friend class DDmaTestSession;
292 #ifndef __KERNEL_MODE__
293 TInt ChannelIsQueueEmpty(TUint aDriverCookie,TBool& aQueueEmpty)
295 return DoControl(EIsQueueEmpty, reinterpret_cast<TAny*>(aDriverCookie), &aQueueEmpty);
298 TInt ChannelIsOpened(TUint aDriverCookie,TBool &aChannelOpen)
300 return DoControl(EIsOpened, reinterpret_cast<TAny*>(aDriverCookie), &aChannelOpen);
303 TInt ChannelIsrRedoRequest(TUint aDriverCookie,TUint32 aSrcAddr,TUint32 aDstAddr,TInt aTransferCount,TUint32 aPslRequestInfo,TBool aIsrCb)
305 TIsrRedoReqArgs args(aDriverCookie,aSrcAddr,aDstAddr,aTransferCount,aPslRequestInfo,aIsrCb);
306 TPckgC<TIsrRedoReqArgs> package(args);
307 return DoControl(EIsrRedoRequest,&package);
310 TInt ChannelCancelAll(TUint aDriverCookie)
312 return DoControl(ECancelAllChannel, reinterpret_cast<TAny*>(aDriverCookie));
315 TInt ChannelOpen(TUint aPslCookie, TUint& aDriverCookie)
317 return DoControl(EOpenChannel, reinterpret_cast<TAny*>(aPslCookie), &aDriverCookie);
320 TInt ChannelClose(TUint aDriverCookie)
322 return DoControl(ECloseChannel, reinterpret_cast<TAny*>(aDriverCookie));
325 TInt ChannelPause(TUint aDriverCookie)
327 return DoControl(EPauseChannel, reinterpret_cast<TAny*>(aDriverCookie));
330 TInt ChannelResume(TUint aDriverCookie)
332 return DoControl(EResumeChannel, reinterpret_cast<TAny*>(aDriverCookie));
335 TInt ChannelCaps(TUint aDriverCookie, SDmacCaps& aChannelCaps)
338 TInt r = ChannelCaps(aDriverCookie, caps);
343 TInt ChannelCaps(TUint aDriverCookie, TDmacTestCaps& aChannelCaps)
345 TPckg<TDmacTestCaps> package(aChannelCaps);
346 return DoControl(EChannelCaps, reinterpret_cast<TAny*>(aDriverCookie), &package);
350 {// TO DO: Add Info , this class is just to test the opening of channels
351 //TPckgBuf<TOpenInfo> infoBuf;
352 //infoBuf().iWhat = TOpenInfo::EOpen;
353 //infoBuf().U.iOpen.iId = aId;
354 //infoBuf().U.iOpen.iDesCount = aDesCount;
355 //infoBuf().U.iOpen.iMaxTransferSize = aMaxTransferSize;
356 return DoCreate(KTestDmaLddName,TestDmaLddVersion(), 0, NULL, NULL, EOwnerThread);
359 //TODO rename this (append "old")
360 TInt RequestCreate(TUint aChannelCookie, TUint& aRequestCookie, TUint aMaxTransferSize=0)
362 return DoRequestCreate(aChannelCookie, EFalse, aMaxTransferSize, aRequestCookie);
365 //TODO rename this (get rid of "new"
366 TInt RequestCreateNew(TUint aChannelCookie, TUint& aRequestCookie, TUint aMaxTransferSize=0)
368 return DoRequestCreate(aChannelCookie, ETrue, aMaxTransferSize, aRequestCookie);
371 TInt RequestDestroy(TUint aRequestCookie)
373 return DoControl(ERequestClose, reinterpret_cast<TAny*>(aRequestCookie));
376 TInt RequestFragmentCount(TUint aRequestCookie)
378 return DoControl(EFragmentCount, reinterpret_cast<TAny*>(aRequestCookie));
382 Will fragment a DMA request using the legacy API
384 TInt FragmentRequestOld(TUint aRequestCookie, const TDmaTransferArgs& aTransferArgs, TUint64* aDurationMicroSecs=NULL)
386 const TFragmentArgs args(aRequestCookie, aTransferArgs, aDurationMicroSecs);
387 TPckgC<TFragmentArgs> package(args);
388 return DoControl(EFragmentLegacy, &package);
392 Will fragment a DMA request using the new API
394 TInt FragmentRequest(TUint aRequestCookie, const TDmaTransferArgs& aTransferArgs, TUint64* aDurationMicroSecs=NULL)
396 const TFragmentArgs args(aRequestCookie, aTransferArgs, aDurationMicroSecs);
397 TPckgC<TFragmentArgs> package(args);
398 return DoControl(EFragment, &package);
401 TInt QueueRequest(TUint aRequestCookie, TRequestStatus& aStatus, TCallbackRecord* aRecord = NULL, TUint64* aDurationMicroSecs=NULL)
403 //These dummy values can accept the writeback from the driver
404 //if the client does not want them.
405 //(TClientDataRequest can not be programmed with a NULL to
406 //indicate that an argument is unwanted)
407 TCallbackRecord dummyRec;
410 TQueueArgs args(aRequestCookie, &aStatus, aRecord ? aRecord : &dummyRec, aDurationMicroSecs ? aDurationMicroSecs : &dummyTime);
411 TPckgC<TQueueArgs> package(args);
412 return DoControl(EQueueRequest, &package);
416 Synchronous version of QueueRequest
418 TInt QueueRequest(TUint aRequestCookie, TCallbackRecord* aRecord = NULL, TUint64* aDurationMicroSecs=NULL)
420 TRequestStatus status;
421 TInt r = QueueRequest(aRequestCookie, status, aRecord, aDurationMicroSecs);
422 User::WaitForRequest(status);
427 Queue a previously fragmented request.
428 Additional request parameters are included in iRequeueArgs, these will be
429 transferred from ISR context callback using the TDmaChannel::IsrRedoRequest function
431 @pre Isr callback for completion must have been requested at request fragmentation time
433 TInt QueueRequestWithRequeue(TUint aRequestCookie, TIsrRequeArgs* aRequeueArgs, TInt aCount, TRequestStatus& aStatus, TCallbackRecord* aRecord = NULL, TUint64* aDurationMicroSecs=NULL)
435 //These dummy values can accept the writeback from the driver
436 //if the client does not want them.
437 //(TClientDataRequest can not be programmed with a NULL to
438 //indicate that an argument is unwanted)
439 TCallbackRecord dummyRec;
442 TQueueArgsWithReque args(aRequeueArgs, aCount, aRequestCookie, &aStatus, aRecord ? aRecord : &dummyRec, aDurationMicroSecs ? aDurationMicroSecs : &dummyTime);
443 TPckgC<TQueueArgsWithReque> package(args);
444 return DoControl(EQueueRequestWithReque, &package);
448 Synchronous version of QueueRequestWithRequeue
450 TInt QueueRequestWithRequeue(TUint aRequestCookie, TIsrRequeArgs* aRequeueArgs, TInt aCount, TCallbackRecord* aRecord = NULL, TUint64* aDurationMicroSecs=NULL)
452 TRequestStatus status;
453 TInt r = QueueRequestWithRequeue(aRequestCookie, aRequeueArgs, aCount, status, aRecord, aDurationMicroSecs);
454 User::WaitForRequest(status);
458 TInt OpenSharedChunk(RChunk& aChunk)
460 TUint chunkHandle = DoControl(EOpenSharedChunk);
461 return aChunk.SetReturnedHandle(chunkHandle);
464 TInt GetTestInfo(TDmaV2TestInfo& aInfo)
466 TPckg<TDmaV2TestInfo> package(aInfo);
467 return DoControl(EGetTestInfo, &package);
470 static void SelfTest();
472 static void ApiTest();
473 #endif // __KERNEL_MODE__
477 TInt DoRequestCreate(TUint aChannelCookie, TBool aNewStyle, TUint aMaxTransferSize, TUint& aRequestCookie)
479 TRequestCreateArgs args(aChannelCookie, aNewStyle, aMaxTransferSize);
480 TPckgC<TRequestCreateArgs> package(args);
481 return DoControl(ERequestOpen, &package, &aRequestCookie);
485 struct TRequestCreateArgs
487 TRequestCreateArgs(TUint aChannelCookie, TBool aNewStyle, TUint aMaxFragmentSize)
488 :iChannelCookie(aChannelCookie), iNewStyle(aNewStyle), iMaxFragmentSize(aMaxFragmentSize)
491 TUint iChannelCookie;
493 TUint iMaxFragmentSize;
499 :iRequestCookie(0), iTransferArgs(), iDurationMicroSecs(NULL)
501 TFragmentArgs(TUint aRequestCookie, const TDmaTransferArgs& aTransferArgs, TUint64* aDurationMicroSecs = NULL)
502 :iRequestCookie(aRequestCookie), iTransferArgs(aTransferArgs), iDurationMicroSecs(aDurationMicroSecs)
505 const TUint iRequestCookie;
506 const TDmaTransferArgs iTransferArgs;
507 TUint64* const iDurationMicroSecs;
512 TQueueArgs(TUint aRequestCookie=0, TRequestStatus* aStatus=NULL, TCallbackRecord* aCallbackRecord=NULL, TUint64* aDurationMicroSecs=NULL)
513 :iRequestCookie(aRequestCookie), iStatus(aStatus), iCallbackRecord(aCallbackRecord), iDurationMicroSecs(aDurationMicroSecs)
515 TUint iRequestCookie;
516 TRequestStatus* iStatus;
517 TCallbackRecord* iCallbackRecord;
518 TUint64* iDurationMicroSecs;
521 struct TIsrRedoReqArgs
523 TIsrRedoReqArgs(TUint aDriverCookie=0,TUint32 aSrcAddr=0, TUint32 aDstAddr=0, TInt aTransferCount=0, TUint32 aPslRequestInfo=0,TBool aIsrCb=ETrue)
524 :iDriverCookie(aDriverCookie),iSrcAddr(aSrcAddr),iDstAddr(aDstAddr),iTransferCount(aTransferCount),iPslRequestInfo(aPslRequestInfo),iIsrCb(aIsrCb)
530 TUint32 iPslRequestInfo;
535 This struct is used for queing and including a set of transfers
536 to be setup from ISR context callback
538 struct TQueueArgsWithReque : public TQueueArgs
540 TQueueArgsWithReque(TIsrRequeArgs* aRequeueArgs=NULL, TInt aCount=0,
541 TUint aRequestCookie=0, TRequestStatus* aStatus=NULL, TCallbackRecord* aCallbackRecord=NULL, TUint64* aDurationMicroSecs=NULL)
542 :TQueueArgs(aRequestCookie, aStatus, aCallbackRecord, aDurationMicroSecs), iRequeSet(aRequeueArgs, aCount)
546 TIsrRequeArgsSet iRequeSet;
569 EQueueRequestWithReque
572 #endif // __D_DMA2_H__