kerneltest/e32test/dmav2/dma2_sim.cpp
changeset 243 c7a0ce20c48c
parent 199 189ece41fa29
equal deleted inserted replaced
231:75252ea6123b 243:c7a0ce20c48c
    28 static const char KDmaPanicCat[] = "DMA PSL - " __FILE__;
    28 static const char KDmaPanicCat[] = "DMA PSL - " __FILE__;
    29 
    29 
    30 static const TInt KMaxTransferLen = 0x1000;	// max transfer length for this DMAC
    30 static const TInt KMaxTransferLen = 0x1000;	// max transfer length for this DMAC
    31 static const TInt KMemAlignMask = 0; // memory addresses passed to DMAC must be multiple of 8
    31 static const TInt KMemAlignMask = 0; // memory addresses passed to DMAC must be multiple of 8
    32 static const TInt KDesCount = 160;				// Initial DMA descriptor count
    32 static const TInt KDesCount = 160;				// Initial DMA descriptor count
       
    33 
       
    34 #define TEST_RETURN(X) if (!(X))\
       
    35 	{\
       
    36 	__KTRACE_OPT(KPANIC, Kern::Printf("Simulated Dma test failure: " __FILE__ " line %d", __LINE__));\
       
    37 	return KErrAbort;\
       
    38 	}
    33 
    39 
    34 class TDmaDesc
    40 class TDmaDesc
    35 //
    41 //
    36 // Hardware DMA descriptor
    42 // Hardware DMA descriptor
    37 //
    43 //
    99 
   105 
   100 //////////////////////////////////////////////////////////////////////////////
   106 //////////////////////////////////////////////////////////////////////////////
   101 // Simulated channel
   107 // Simulated channel
   102 //////////////////////////////////////////////////////////////////////////////
   108 //////////////////////////////////////////////////////////////////////////////
   103 
   109 
       
   110 /**
       
   111 An interface class to add simulation specific functionallity to any DMA channel
       
   112 */
   104 class MSimChannel
   113 class MSimChannel
   105 	{
   114 	{
   106 public:
   115 public:
   107 	virtual void PreOpen() {}
   116 	virtual TInt PreOpen() =0;
       
   117 	virtual TDmaChannel& Channel() =0;
   108 	};
   118 	};
   109 
   119 
   110 //////////////////////////////////////////////////////////////////////////////
   120 //////////////////////////////////////////////////////////////////////////////
   111 // Derived Channel (Scatter/Gather)
   121 // Derived Channel (Scatter/Gather)
   112 //////////////////////////////////////////////////////////////////////////////
   122 //////////////////////////////////////////////////////////////////////////////
   166 public:
   176 public:
   167 	// Virtual from TDmaChannel
   177 	// Virtual from TDmaChannel
   168 	void DoCancelAll();
   178 	void DoCancelAll();
   169 
   179 
   170 	void CallDefaultVirtuals();
   180 	void CallDefaultVirtuals();
       
   181 	TInt CheckExtensionStubs();
   171 
   182 
   172 	// From MSimChannel
   183 	// From MSimChannel
   173 	void PreOpen();
   184 	TInt PreOpen();
       
   185 	TDmaChannel& Channel() {return *this;}
   174 	};
   186 	};
   175 
   187 
   176 void TEmptyChannel::DoCancelAll()
   188 void TEmptyChannel::DoCancelAll()
   177 	{
   189 	{
   178 	__DMA_CANT_HAPPEN();
   190 	__DMA_CANT_HAPPEN();
   190 	DoDfc(*req, hdr, hdr);
   202 	DoDfc(*req, hdr, hdr);
   191 
   203 
   192 	QueuedRequestCountChanged();
   204 	QueuedRequestCountChanged();
   193 	}
   205 	}
   194 
   206 
   195 void TEmptyChannel::PreOpen()
   207 TInt TEmptyChannel::CheckExtensionStubs()
       
   208 	{
       
   209 	DMA_PSL_TRACE("Calling extension stubs");
       
   210 
       
   211 	TInt r = Extension(0, NULL);
       
   212 	TEST_RETURN(r == KErrNotSupported)
       
   213 
       
   214 	r = StaticExtension(0, NULL);
       
   215 	TEST_RETURN(r == KErrNotSupported)
       
   216 
       
   217 	return KErrNone;
       
   218 	}
       
   219 
       
   220 TInt TEmptyChannel::PreOpen()
   196 	{
   221 	{
   197 	CallDefaultVirtuals();
   222 	CallDefaultVirtuals();
       
   223 	return CheckExtensionStubs();
   198 	}
   224 	}
   199 
   225 
   200 //////////////////////////////////////////////////////////////////////////////
   226 //////////////////////////////////////////////////////////////////////////////
   201 // Derived SkelControllerSw Class
   227 // Derived SkelControllerSw Class
   202 //////////////////////////////////////////////////////////////////////////////
   228 //////////////////////////////////////////////////////////////////////////////
   256 //
   282 //
   257 // Constructor.
   283 // Constructor.
   258 //
   284 //
   259 	: TDmac(aInfo)
   285 	: TDmac(aInfo)
   260 	{
   286 	{
   261 	// TODO remove this once DMAC can be created and destroyed from test LDD entry
       
   262 	// point
       
   263 	TInt r = Create(aInfo);
   287 	TInt r = Create(aInfo);
   264 	__NK_ASSERT_ALWAYS(r == KErrNone);
   288 	__NK_ASSERT_ALWAYS(r == KErrNone);
   265 
   289 
   266 	CallDefaultVirtuals();
   290 	CallDefaultVirtuals();
   267 	r = TestPool();
   291 	r = TestPool();
   552 //
   576 //
   553 // Constructor.
   577 // Constructor.
   554 //
   578 //
   555 	: TDmac(KInfo)
   579 	: TDmac(KInfo)
   556 	{
   580 	{
   557 	// TODO remove this once DMAC can be created and destroyed from test LDD entry
       
   558 	// point
       
   559 	TInt r = Create();
   581 	TInt r = Create();
   560 	__NK_ASSERT_ALWAYS(r == KErrNone);
   582 	__NK_ASSERT_ALWAYS(r == KErrNone);
   561 	}
   583 	}
   562 
   584 
   563 
   585 
   652 // Channel Opening/Closing (Channel Allocator)
   674 // Channel Opening/Closing (Channel Allocator)
   653 //////////////////////////////////////////////////////////////////////////////
   675 //////////////////////////////////////////////////////////////////////////////
   654 
   676 
   655 struct TChanEntry
   677 struct TChanEntry
   656 	{
   678 	{
   657 	TChanEntry(TDmac& aController, TDmaChannel& aChannel, const SDmacCaps& aCaps)
   679 	TChanEntry(TDmac& aController, MSimChannel& aChannel, const SDmacCaps& aCaps)
   658 		:
   680 		:
   659 			iController(aController),
   681 			iController(aController),
   660 			iChannel(aChannel),
   682 			iSimChannel(aChannel),
   661 			iCaps(aCaps)
   683 			iCaps(aCaps)
   662 	{}
   684 	{}
   663 
   685 
   664 	TDmac& iController;
   686 	TDmac& iController;
   665 	TDmaChannel& iChannel;
   687 	MSimChannel& iSimChannel;
   666 	const SDmacCaps& iCaps;
   688 	const SDmacCaps& iCaps;
   667 	};
   689 	};
   668 
   690 
   669 const TChanEntry ChannelTable[] =
   691 const TChanEntry ChannelTable[] =
   670 	{
   692 	{
   684 	__KTRACE_OPT(KDMA, Kern::Printf(">DmaChannelMgr::Open aOpenId=%d", aOpenId));
   706 	__KTRACE_OPT(KDMA, Kern::Printf(">DmaChannelMgr::Open aOpenId=%d", aOpenId));
   685 
   707 
   686 	__DMA_ASSERTA(aOpenId < static_cast<TUint32>(KChannelCount));
   708 	__DMA_ASSERTA(aOpenId < static_cast<TUint32>(KChannelCount));
   687 
   709 
   688 	const TChanEntry& entry = ChannelTable[aOpenId];
   710 	const TChanEntry& entry = ChannelTable[aOpenId];
   689 	TDmaChannel* pC = &entry.iChannel;
   711 	TDmaChannel* pC = &entry.iSimChannel.Channel();
   690 	if (pC->IsOpened())
   712 	if (pC->IsOpened())
   691 		{
   713 		{
   692 		pC = NULL;
   714 		pC = NULL;
   693 		}
   715 		}
   694 	else
   716 	else
   700 		// It is safe to signal here,
   722 		// It is safe to signal here,
   701 		// setting iController marks the channel
   723 		// setting iController marks the channel
   702 		// as taken
   724 		// as taken
   703 		Signal();
   725 		Signal();
   704 
   726 
   705 		static_cast<TEmptyChannel*>(pC)->PreOpen();
   727 		TInt r = entry.iSimChannel.PreOpen();
   706 
   728 
   707 		Wait();
   729 		Wait();
       
   730 
       
   731 		// If there was an error
       
   732 		// Close channel after retaking mutex
       
   733 		if(r != KErrNone)
       
   734 			{
       
   735 			pC->iController = NULL;
       
   736 			pC = NULL;
       
   737 			}
       
   738 
       
   739 
   708 		}
   740 		}
   709 	return pC;
   741 	return pC;
   710 	}
   742 	}
   711 
   743 
   712 
   744