kernel/eka/include/drivers/dma_v2.h
changeset 130 c30940f6d922
parent 90 947f0dc9f7a8
child 132 e4a7b1cbe40c
child 152 657f875b013e
equal deleted inserted replaced
129:a990138eda40 130:c30940f6d922
    16 //
    16 //
    17 // NB: DMA clients should never include this file directly, but only ever the
    17 // NB: DMA clients should never include this file directly, but only ever the
    18 // generic header file <drivers/dma.h>.
    18 // generic header file <drivers/dma.h>.
    19 //
    19 //
    20 
    20 
       
    21 /** @file
       
    22 	@publishedPartner
       
    23 */
       
    24 
    21 #ifndef __DMA_H__
    25 #ifndef __DMA_H__
    22 #error "dma_v2.h must'n be included directly - use <drivers/dma.h> instead"
    26 #error "dma_v2.h must'n be included directly - use <drivers/dma.h> instead"
    23 #endif	// #ifndef __DMA_H__
    27 #endif	// #ifndef __DMA_H__
    24 
    28 
    25 #ifndef __DMA_V2_H__
    29 #ifndef __DMA_V2_H__
    65 	The EKA1 "Fill Mode" can be implemented by omitting KDmaIncSrc.
    69 	The EKA1 "Fill Mode" can be implemented by omitting KDmaIncSrc.
    66 
    70 
    67 	Some peripherals may require a post-increment address mode.
    71 	Some peripherals may require a post-increment address mode.
    68 
    72 
    69 	@see DDmaRequest::Fragment
    73 	@see DDmaRequest::Fragment
    70 	@publishedPartner
    74 
    71 	@released
    75 	Note: This enum is only required for backwards compatibility with the old
       
    76 	DMA framework, it can be removed once this is no longer needed.
       
    77 
       
    78 	@deprecated
    72 */
    79 */
    73 enum TDmaRequestFlags
    80 enum TDmaRequestFlags
    74 	{
    81 	{
    75 	// Note: This enum is only required for backwards compatibility with the
       
    76 	// old DMA framework, it can be removed once this is no longer needed.
       
    77 
       
    78 	/** Source is address of memory buffer */
    82 	/** Source is address of memory buffer */
    79 	KDmaMemSrc       = 0x01,
    83 	KDmaMemSrc       = 0x01,
    80 	/** Destination is address of memory buffer */
    84 	/** Destination is address of memory buffer */
    81 	KDmaMemDest      = 0x02,
    85 	KDmaMemDest      = 0x02,
    82 	/** Source address must be post-incremented during transfer */
    86 	/** Source address must be post-incremented during transfer */
    94 
    98 
    95 /** Each hardware or pseudo descriptor is associated with a header.  Headers
    99 /** Each hardware or pseudo descriptor is associated with a header.  Headers
    96 	are needed because hardware descriptors can not easily be extended to store
   100 	are needed because hardware descriptors can not easily be extended to store
    97 	additional information.
   101 	additional information.
    98 
   102 
    99 	@publishedPartner
       
   100 	@released
   103 	@released
   101 */
   104 */
   102 struct SDmaDesHdr
   105 struct SDmaDesHdr
   103 	{
   106 	{
   104 	SDmaDesHdr* iNext;
   107 	SDmaDesHdr* iNext;
   105 	};
   108 	};
   106 
   109 
       
   110 
   107 /** Pointer to signature of the new extended callback function.
   111 /** Pointer to signature of the new extended callback function.
   108 
   112 
   109 	TUint - bitmask of one or more TDmaCallbackType values
   113 	TUint       - bitmask of one or more TDmaCallbackType values
   110 	TDmaResult - just that
   114 	TDmaResult  - just that
   111 	TAny* - was provided by client in DDmaRequest constructor
   115 	TAny*       - was provided by client in DDmaRequest constructor
   112 	SDmaDesHdr* - points to header (and thus descriptor) which caused a
   116 	SDmaDesHdr* - points to header (and thus descriptor) which caused a
   113 	'descriptor completed' or 'descriptor paused' event.
   117 	'descriptor completed' or 'descriptor paused' event
       
   118 
       
   119 	@released
   114  */
   120  */
   115 typedef void (*TDmaCallback)(TUint, TDmaResult, TAny*, SDmaDesHdr*);
   121 typedef void (*TDmaCallback)(TUint, TDmaResult, TAny*, SDmaDesHdr*);
   116 
   122 
       
   123 
   117 class TDmaChannel;
   124 class TDmaChannel;
       
   125 
   118 
   126 
   119 /** A DMA request is a list of fragments small enough to be transferred in one go
   127 /** A DMA request is a list of fragments small enough to be transferred in one go
   120 	by the DMAC.
   128 	by the DMAC.
   121 
   129 
   122 	In general, fragmentation is done in the framework by calling Fragment() but
   130 	In general, fragmentation is done in the framework by calling Fragment() but
   130 	Multithreaded clients must implement their own locking scheme (via DMutex).
   138 	Multithreaded clients must implement their own locking scheme (via DMutex).
   131 
   139 
   132 	Mutexes are used internally to protect data structures accessed both by the
   140 	Mutexes are used internally to protect data structures accessed both by the
   133 	client thread and the DFC thread. Therefore no fast mutex can be held when
   141 	client thread and the DFC thread. Therefore no fast mutex can be held when
   134 	calling a request function.
   142 	calling a request function.
   135 
   143 */
   136 	@publishedPartner
       
   137 	@released
       
   138  */
       
   139 class DDmaRequest : public DBase
   144 class DDmaRequest : public DBase
   140 	{
   145 	{
   141 	friend class TDmaChannel;
   146 	friend class TDmaChannel;
   142 
   147 
   143 public:
   148 public:
   144 	/** The outcome of the transfer
   149 	/** The outcome of the transfer
   145 
   150 
       
   151 		@see TDmaResult
       
   152 
   146 		@deprecated
   153 		@deprecated
   147 		@see TDmaResult
       
   148 	*/
   154 	*/
   149 	enum TResult {EBadResult=0, EOk, EError};
   155 	enum TResult {EBadResult=0, EOk, EError};
       
   156 
   150 	/** The signature of the completion/failure callback function
   157 	/** The signature of the completion/failure callback function
   151 
   158 
       
   159 		@see TDmaCallback
       
   160 
   152 		@deprecated
   161 		@deprecated
   153 		@see TDmaCallback
       
   154 	*/
   162 	*/
   155 	typedef void (*TCallback)(TResult, TAny*);
   163 	typedef void (*TCallback)(TResult, TAny*);
   156 
   164 
   157 public:
   165 public:
   158     /** Constructor.
   166     /** Constructor.
   181 		failure (in channel DFC or ISR context). Can be NULL.
   189 		failure (in channel DFC or ISR context). Can be NULL.
   182 		@param aCbArg Argument passed to callback function.
   190 		@param aCbArg Argument passed to callback function.
   183 		@param aMaxTransferSize Maximum fragment size. If not specified,
   191 		@param aMaxTransferSize Maximum fragment size. If not specified,
   184 		defaults to the maximum size supported by the DMA controller for the
   192 		defaults to the maximum size supported by the DMA controller for the
   185 		type of transfer that is later scheduled.
   193 		type of transfer that is later scheduled.
   186 	*/
   194 
   187 	IMPORT_C DDmaRequest(TDmaChannel& aChannel, TDmaCallback aDmaCb, TAny* aCbArg=NULL,
   195 		@released
   188 						 TUint aMaxTransferSize=0);
   196 	*/
       
   197 	IMPORT_C DDmaRequest(TDmaChannel& aChannel, TDmaCallback aDmaCb,
       
   198 						 TAny* aCbArg=NULL, TUint aMaxTransferSize=0);
   189 
   199 
   190 
   200 
   191 	/** Destructor.
   201 	/** Destructor.
   192 
   202 
   193 		Assume the request is not being transferred or pending.
   203 		Assume the request is not being transferred or pending.
   194     */
   204 
       
   205 		@released
       
   206 	*/
   195 	IMPORT_C ~DDmaRequest();
   207 	IMPORT_C ~DDmaRequest();
   196 
   208 
   197 
   209 
   198 	/** Split request into a list of fragments small enough to be fed to the
   210 	/** Split request into a list of fragments small enough to be fed to the
   199 		DMAC.
   211 		DMAC.
   209 		magic cookie by the PIL and passed straight to the PSL.
   221 		magic cookie by the PIL and passed straight to the PSL.
   210 
   222 
   211 		The request can be uninitialised or may have been fragmented
   223 		The request can be uninitialised or may have been fragmented
   212 		previously. The previous configuration if any is lost whether or not
   224 		previously. The previous configuration if any is lost whether or not
   213 		the function succeeds.
   225 		the function succeeds.
       
   226 
       
   227 		The client must ensure that any memory buffers involved in the transfer
       
   228 		have been suitably prepared for DMA. For memory allocated on the kernel
       
   229 		side or in a shared chunk this amounts to ensuring cache consistency
       
   230 		before Queue() is called. However for memory that was allocated on the
       
   231 		user side the client must also ensure that the memory is protected from
       
   232 		both data paging and RAM defragmentation before Fragment() is called
       
   233 		@see Kern::MapAndPinMemory(). Note however, that this function is only
       
   234 		available if the flexible memory model (FMM) is in use.
   214 
   235 
   215 		@param aSrc Source memory buffer linear address or peripheral magic
   236 		@param aSrc Source memory buffer linear address or peripheral magic
   216 		cookie.
   237 		cookie.
   217 		@param aDest Destination memory buffer linear address or peripheral
   238 		@param aDest Destination memory buffer linear address or peripheral
   218 		magic cookie.
   239 		magic cookie.
   235 	IMPORT_C TInt Fragment(TUint32 aSrc, TUint32 aDest, TInt aCount, TUint aFlags, TUint32 aPslInfo);
   256 	IMPORT_C TInt Fragment(TUint32 aSrc, TUint32 aDest, TInt aCount, TUint aFlags, TUint32 aPslInfo);
   236 
   257 
   237 
   258 
   238 	/** New version of the DMA request fragment function, to be used with the
   259 	/** New version of the DMA request fragment function, to be used with the
   239 		TDmaTransferArgs structure.
   260 		TDmaTransferArgs structure.
       
   261 
       
   262 		Split request into a list of fragments small enough to be fed to the
       
   263 		DMAC.
       
   264 
       
   265 		The size of each fragment is smaller than or equal to the maximum
       
   266 		transfer size supported by the DMAC. If the source and/or destination
       
   267 		is memory, each fragment points to memory which is physically
       
   268 		contiguous.
       
   269 
       
   270 		The request can be uninitialised or may have been fragmented
       
   271 		previously. Any previous configuration is lost whether or not the
       
   272 		function succeeds.
       
   273 
       
   274 		The client must ensure that any memory buffers involved in the transfer
       
   275 		have been suitably prepared for DMA. For memory allocated on the kernel
       
   276 		side or in a shared chunk this amounts to ensuring cache consistency
       
   277 		before Queue() is called. However for memory that was allocated on the
       
   278 		user side the client must also ensure that the memory is protected from
       
   279 		both data paging and RAM defragmentation before Fragment() is called
       
   280 		@see Kern::MapAndPinMemory(). Note however, that this function is only
       
   281 		available if the flexible memory model (FMM) is in use.
       
   282 
       
   283 		@param aTransferArgs Describes the transfer to be performed.
       
   284 
       
   285 		@return KErrNone if success. KErrArgument if certain arguments are
       
   286 		invalid. May also fail if running out of descriptors.
       
   287 
       
   288 		@pre The request is not being transferred or pending.
       
   289 		@pre The various parameters must be valid. The PIL or PSL will fault
       
   290 		the kernel if not.
       
   291 
       
   292 		@released
   240 	*/
   293 	*/
   241 	IMPORT_C TInt Fragment(const TDmaTransferArgs& aTransferArgs);
   294 	IMPORT_C TInt Fragment(const TDmaTransferArgs& aTransferArgs);
   242 
   295 
   243 
   296 
   244 	/** Transfer asynchronously this request.
   297 	/** Transfer asynchronously this request.
   248 
   301 
   249 		The client is responsible for ensuring cache consistency before and/or
   302 		The client is responsible for ensuring cache consistency before and/or
   250 		after the transfer if necessary.
   303 		after the transfer if necessary.
   251 
   304 
   252 		@return KErrNone if success, KErrGeneral otherwise.
   305 		@return KErrNone if success, KErrGeneral otherwise.
   253     */
   306 
       
   307 		@released
       
   308 	*/
   254 	IMPORT_C TInt Queue();
   309 	IMPORT_C TInt Queue();
   255 
   310 
   256 
   311 
   257     /** Append new descriptor(s) to existing list.
   312 	/** Append new descriptor(s) to existing list.
   258 
   313 
   259 		Clients needing to build a custom descriptor list should call this
   314 		Clients needing to build a custom descriptor list should call this
   260 		function to allocate the list and access the resulting list through
   315 		function to allocate the list and access the resulting list through
   261 		iFirstHdr and iLastHdr.
   316 		iFirstHdr and iLastHdr.
   262 
   317 
   268 		Assume the request is not being transferred or pending.
   323 		Assume the request is not being transferred or pending.
   269 
   324 
   270 		@param aCount Number of descriptors to append.
   325 		@param aCount Number of descriptors to append.
   271 
   326 
   272 		@return KErrNone or standard error code.
   327 		@return KErrNone or standard error code.
   273     */
   328 
       
   329 		@released
       
   330 	*/
   274 	IMPORT_C TInt ExpandDesList(TInt aCount=1);
   331 	IMPORT_C TInt ExpandDesList(TInt aCount=1);
   275 
   332 
   276 
   333 
   277     /** Append new descriptor(s) to existing list. This function variant
   334 	/** Append new descriptor(s) to existing list. This function variant
   278 		operates on the source port descriptor chain.
   335 		operates on the source port descriptor chain.
   279 
   336 
   280 		Works like ExpandDesList except that it uses the iSrcFirstHdr and
   337 		Works like ExpandDesList except that it uses the iSrcFirstHdr and
   281 		iSrcLastHdr fields.
   338 		iSrcLastHdr fields.
   282 
   339 
   286 		true, otherwise it will just return KErrGeneral.
   343 		true, otherwise it will just return KErrGeneral.
   287 
   344 
   288 		@param aCount Number of descriptors to append.
   345 		@param aCount Number of descriptors to append.
   289 
   346 
   290 		@return KErrNone or standard error code.
   347 		@return KErrNone or standard error code.
   291     */
   348 
       
   349 		@prototype
       
   350 	*/
   292 	IMPORT_C TInt ExpandSrcDesList(TInt aCount=1);
   351 	IMPORT_C TInt ExpandSrcDesList(TInt aCount=1);
   293 
   352 
   294 
   353 
   295     /** Append new descriptor(s) to existing list. This function variant
   354 	/** Append new descriptor(s) to existing list. This function variant
   296 		operates on the destination port descriptor chain.
   355 		operates on the destination port descriptor chain.
   297 
   356 
   298 		Works like ExpandDesList except that it uses the iDstFirstHdr and
   357 		Works like ExpandDesList except that it uses the iDstFirstHdr and
   299 		iDstLastHdr fields.
   358 		iDstLastHdr fields.
   300 
   359 
   304 		true, otherwise it will just return KErrGeneral.
   363 		true, otherwise it will just return KErrGeneral.
   305 
   364 
   306 		@param aCount Number of descriptors to append.
   365 		@param aCount Number of descriptors to append.
   307 
   366 
   308 		@return KErrNone or standard error code.
   367 		@return KErrNone or standard error code.
   309     */
   368 
       
   369 		@prototype
       
   370 	*/
   310 	IMPORT_C TInt ExpandDstDesList(TInt aCount=1);
   371 	IMPORT_C TInt ExpandDstDesList(TInt aCount=1);
   311 
   372 
   312 
   373 
   313 	/** Free resources associated with this request.
   374 	/** Free resources associated with this request.
   314 
   375 
   315 		Assume the request is not being transferred or pending.
   376 		Assume the request is not being transferred or pending.
   316     */
   377 
       
   378 		@released
       
   379 	*/
   317 	IMPORT_C void FreeDesList();
   380 	IMPORT_C void FreeDesList();
   318 
   381 
   319 
   382 
   320 	/** Free resources associated with this request. This function variant
   383 	/** Free resources associated with this request. This function variant
   321 		operates on the source port descriptor chain.
   384 		operates on the source port descriptor chain.
   322 
   385 
   323 		@see FreeDesList
   386 		@see FreeDesList
   324 
   387 
   325 		This function can only be used if SDmacCaps::iAsymHwDescriptors is
   388 		This function can only be used if SDmacCaps::iAsymHwDescriptors is
   326 		true, otherwise it will do nothing.
   389 		true, otherwise it will do nothing.
   327     */
   390 
       
   391 		@prototype
       
   392 	*/
   328 	IMPORT_C void FreeSrcDesList();
   393 	IMPORT_C void FreeSrcDesList();
   329 
   394 
   330 
   395 
   331 	/** Free resources associated with this request. This function variant
   396 	/** Free resources associated with this request. This function variant
   332 		operates on the destination port descriptor chain.
   397 		operates on the destination port descriptor chain.
   333 
   398 
   334 		@see FreeDesList
   399 		@see FreeDesList
   335 
   400 
   336 		This function can only be used if SDmacCaps::iAsymHwDescriptors is
   401 		This function can only be used if SDmacCaps::iAsymHwDescriptors is
   337 		true, otherwise it will do nothing.
   402 		true, otherwise it will do nothing.
   338     */
   403 
       
   404 		@prototype
       
   405 	*/
   339 	IMPORT_C void FreeDstDesList();
   406 	IMPORT_C void FreeDstDesList();
   340 
   407 
   341 
   408 
   342 	/** Enables the functionality for counting the transferred source
   409 	/** Enables the functionality for counting the transferred source
   343 		elements.
   410 		elements.
   365 		variable will be reset to zero, otherwise it will retain its current
   432 		variable will be reset to zero, otherwise it will retain its current
   366 		value.
   433 		value.
   367 
   434 
   368 		@see Queue()
   435 		@see Queue()
   369 		@see TotalNumSrcElementsTransferred()
   436 		@see TotalNumSrcElementsTransferred()
       
   437 
       
   438 		@prototype
   370 	*/
   439 	*/
   371 	IMPORT_C void EnableSrcElementCounting(TBool aResetElementCount=ETrue);
   440 	IMPORT_C void EnableSrcElementCounting(TBool aResetElementCount=ETrue);
   372 
   441 
   373 
   442 
   374 	/** Enables the functionality for counting the transferred destination
   443 	/** Enables the functionality for counting the transferred destination
   397 		variable will be reset to zero, otherwise it will retain its current
   466 		variable will be reset to zero, otherwise it will retain its current
   398 		value.
   467 		value.
   399 
   468 
   400 		@see Queue()
   469 		@see Queue()
   401 		@see TotalNumDstElementsTransferred()
   470 		@see TotalNumDstElementsTransferred()
       
   471 
       
   472 		@prototype
   402 	*/
   473 	*/
   403 	IMPORT_C void EnableDstElementCounting(TBool aResetElementCount=ETrue);
   474 	IMPORT_C void EnableDstElementCounting(TBool aResetElementCount=ETrue);
   404 
   475 
   405 
   476 
   406 	/** Disables the functionality for counting the transferred source
   477 	/** Disables the functionality for counting the transferred source
   425 		Once a status has been set, it remains valid for the entire duration of
   496 		Once a status has been set, it remains valid for the entire duration of
   426 		the transfer (and beyond, if it is not changed again).
   497 		the transfer (and beyond, if it is not changed again).
   427 
   498 
   428 		@see Queue()
   499 		@see Queue()
   429 		@see TotalNumSrcElementsTransferred()
   500 		@see TotalNumSrcElementsTransferred()
       
   501 
       
   502 		@prototype
   430 	*/
   503 	*/
   431 	IMPORT_C void DisableSrcElementCounting();
   504 	IMPORT_C void DisableSrcElementCounting();
   432 
   505 
   433 
   506 
   434 	/** Disables the functionality for counting the transferred destination
   507 	/** Disables the functionality for counting the transferred destination
   453 		Once a status has been set, it remains valid for the entire duration of
   526 		Once a status has been set, it remains valid for the entire duration of
   454 		the transfer (and beyond, if it is not changed again).
   527 		the transfer (and beyond, if it is not changed again).
   455 
   528 
   456 		@see Queue()
   529 		@see Queue()
   457 		@see TotalNumDstElementsTransferred()
   530 		@see TotalNumDstElementsTransferred()
       
   531 
       
   532 		@prototype
   458 	*/
   533 	*/
   459 	IMPORT_C void DisableDstElementCounting();
   534 	IMPORT_C void DisableDstElementCounting();
   460 
   535 
   461 
   536 
   462 	/** Returns the number of elements that have been transferred by this
   537 	/** Returns the number of elements that have been transferred by this
   473 		(completed with or without error, or because it was cancelled) or while
   548 		(completed with or without error, or because it was cancelled) or while
   474 		it is paused. Otherwise it may just return 0.
   549 		it is paused. Otherwise it may just return 0.
   475 
   550 
   476 		@return The number of elements that have been transferred by this
   551 		@return The number of elements that have been transferred by this
   477 		transfer request at the source port.
   552 		transfer request at the source port.
       
   553 
       
   554 		@prototype
   478 	*/
   555 	*/
   479 	IMPORT_C TUint32 TotalNumSrcElementsTransferred();
   556 	IMPORT_C TUint32 TotalNumSrcElementsTransferred();
   480 
   557 
   481 
   558 
   482 	/** Returns the number of elements that have been transferred by this
   559 	/** Returns the number of elements that have been transferred by this
   493 		(completed with or without error, or because it was cancelled) or while
   570 		(completed with or without error, or because it was cancelled) or while
   494 		it is paused. Otherwise it may just return 0.
   571 		it is paused. Otherwise it may just return 0.
   495 
   572 
   496 		@return The number of elements that have been transferred by this
   573 		@return The number of elements that have been transferred by this
   497 		transfer request at the destination port.
   574 		transfer request at the destination port.
       
   575 
       
   576 		@prototype
   498 	*/
   577 	*/
   499 	IMPORT_C TUint32 TotalNumDstElementsTransferred();
   578 	IMPORT_C TUint32 TotalNumDstElementsTransferred();
   500 
   579 
   501 
   580 
   502 	/** Returns the number of fragments that this transfer request has been
   581 	/** Returns the number of fragments that this transfer request has been
   510 		return 0, and SrcFragmentCount() / DstFragmentCount() should be used
   589 		return 0, and SrcFragmentCount() / DstFragmentCount() should be used
   511 		instead.
   590 		instead.
   512 
   591 
   513 		@return The number of fragments (descriptors / pseudo descriptors) that
   592 		@return The number of fragments (descriptors / pseudo descriptors) that
   514 		this transfer request has been split into.
   593 		this transfer request has been split into.
   515 	 */
   594 
       
   595 		@released
       
   596 	*/
   516 	IMPORT_C TInt FragmentCount();
   597 	IMPORT_C TInt FragmentCount();
       
   598 
   517 
   599 
   518 	/** Returns the number of source port fragments that this transfer request
   600 	/** Returns the number of source port fragments that this transfer request
   519 		has been split into.
   601 		has been split into.
   520 
   602 
   521 		This number will only be different from 0 once Fragment() has been
   603 		This number will only be different from 0 once Fragment() has been
   525 		This function can only be used if SDmacCaps::iAsymHwDescriptors is
   607 		This function can only be used if SDmacCaps::iAsymHwDescriptors is
   526 		true, otherwise it will always return 0.
   608 		true, otherwise it will always return 0.
   527 
   609 
   528 		@return The number of source port fragments (descriptors) that this
   610 		@return The number of source port fragments (descriptors) that this
   529 		transfer request has been split into.
   611 		transfer request has been split into.
   530 	 */
   612 
       
   613 		@prototype
       
   614 	*/
   531 	IMPORT_C TInt SrcFragmentCount();
   615 	IMPORT_C TInt SrcFragmentCount();
   532 
   616 
   533 
   617 
   534 	/** Returns the number of destination port fragments that this transfer
   618 	/** Returns the number of destination port fragments that this transfer
   535 		request has been split into.
   619 		request has been split into.
   541 		This function can only be used if SDmacCaps::iAsymHwDescriptors is
   625 		This function can only be used if SDmacCaps::iAsymHwDescriptors is
   542 		true, otherwise it will always return 0.
   626 		true, otherwise it will always return 0.
   543 
   627 
   544 		@return The number of destination port fragments (descriptors) that
   628 		@return The number of destination port fragments (descriptors) that
   545 		this transfer request has been split into.
   629 		this transfer request has been split into.
   546 	 */
   630 
       
   631 		@prototype
       
   632 	*/
   547 	IMPORT_C TInt DstFragmentCount();
   633 	IMPORT_C TInt DstFragmentCount();
   548 
   634 
   549 private:
   635 private:
   550 	inline void OnDeque();
   636 	inline void OnDeque();
   551 	TUint GetTransferCount(const TDmaTransferArgs& aTransferArgs);
   637 	TInt CheckTransferConfig(const TDmaTransferConfig& aTarget, TUint aCount) const;
       
   638 	TInt CheckMemFlags(const TDmaTransferConfig& aTarget, TUint aCount) const;
       
   639 	TInt AdjustFragmentSize(TUint& aFragSize, TUint aElementSize, TUint aFrameSize);
       
   640 	TUint GetTransferCount(const TDmaTransferArgs& aTransferArgs) const;
       
   641 	TUint GetMaxTransferlength(const TDmaTransferArgs& aTransferArgs, TUint aCount) const;
   552 	TInt Frag(TDmaTransferArgs& aTransferArgs);
   642 	TInt Frag(TDmaTransferArgs& aTransferArgs);
   553 	TInt FragSym(TDmaTransferArgs& aTransferArgs, TUint aCount, TUint aMaxTransferLen);
   643 	TInt FragSym(TDmaTransferArgs& aTransferArgs, TUint aCount, TUint aMaxTransferLen);
   554 	TInt FragAsym(TDmaTransferArgs& aTransferArgs, TUint aCount, TUint aMaxTransferLen);
   644 	TInt FragAsym(TDmaTransferArgs& aTransferArgs, TUint aCount, TUint aMaxTransferLen);
   555 	TInt FragAsymSrc(TDmaTransferArgs& aTransferArgs, TUint aCount, TUint aMaxTransferLen);
   645 	TInt FragAsymSrc(TDmaTransferArgs& aTransferArgs, TUint aCount, TUint aMaxTransferLen);
   556 	TInt FragAsymDst(TDmaTransferArgs& aTransferArgs, TUint aCount, TUint aMaxTransferLen);
   646 	TInt FragAsymDst(TDmaTransferArgs& aTransferArgs, TUint aCount, TUint aMaxTransferLen);
       
   647 	TInt FragBalancedAsym(TDmaTransferArgs& aTransferArgs, TUint aCount, TUint aMaxTransferLen);
   557 	TInt ExpandDesList(TInt aCount, TInt& aDesCount, SDmaDesHdr*& aFirstHdr,
   648 	TInt ExpandDesList(TInt aCount, TInt& aDesCount, SDmaDesHdr*& aFirstHdr,
   558 					   SDmaDesHdr*& aLastHdr);
   649 					   SDmaDesHdr*& aLastHdr);
   559 	void FreeDesList(TInt& aDesCount, SDmaDesHdr*& aFirstHdr, SDmaDesHdr*& aLastHdr);
   650 	void FreeDesList(TInt& aDesCount, SDmaDesHdr*& aFirstHdr, SDmaDesHdr*& aLastHdr);
   560 	TInt FragmentCount(const SDmaDesHdr* aHdr);
   651 	TInt FragmentCount(const SDmaDesHdr* aHdr);
   561 
   652 
   562 public:
   653 public:
   563 	// WARNING: The following attributes are accessed both in client and DFC
   654 	// WARNING: The following attributes are accessed both in client and DFC
   564 	// context and so accesses must be protected with the channel lock.
   655 	// thread context, so accesses must be protected with the channel lock.
   565 	TDmaChannel& iChannel;		/**< The channel this request is bound to */
   656 	TDmaChannel& iChannel;		/**< The channel this request is bound to */
   566 	TCallback iCb;			 /**< Called on completion/failure (can be NULL) */
   657 	TCallback iCb;			 /**< Called on completion/failure (can be NULL) */
   567 	TAny* iCbArg;			 /**< Callback argument */
   658 	TAny* iCbArg;			 /**< Callback argument */
   568 	TDmaCallback iDmaCb;		// the new-style callback function
   659 	TDmaCallback iDmaCb;		// the new-style callback function
   569 	TAny* iDmaCbArg;			// the new-style callback arg
   660 	TAny* iDmaCbArg;			// the new-style callback arg
   606 	scheme (via DMutex).
   697 	scheme (via DMutex).
   607 
   698 
   608 	Mutexes are used internally to protect data structures accessed both by the
   699 	Mutexes are used internally to protect data structures accessed both by the
   609 	client thread and the DFC one. Therefore no fast mutex can be held when
   700 	client thread and the DFC one. Therefore no fast mutex can be held when
   610 	calling a channel function.
   701 	calling a channel function.
   611 
   702 */
   612 	@publishedPartner
       
   613 	@released
       
   614  */
       
   615 class TDmaChannel
   703 class TDmaChannel
   616 	{
   704 	{
   617 	friend class DDmaRequest;
   705 	friend class DDmaRequest;
   618 	friend class TDmac;
   706 	friend class TDmac;
   619 	friend class DmaChannelMgr;
   707 	friend class DmaChannelMgr;
       
   708 
   620 public:
   709 public:
   621 
   710 	/** Information passed by client when opening a channel. */
   622 	/** Information passed by client when opening a channel */
       
   623 	struct SCreateInfo
   711 	struct SCreateInfo
   624 		{
   712 		{
   625 		/** Default constructor. Initializes all fields with meaningful default
   713 		/** Default constructor. Initializes all fields with meaningful default
   626 			values.
   714 			values.
   627 
   715 
   628 			Must be inline (for now) because exporting it would break existing
   716 			Must be inline (for now) because exporting it would break existing
   629 			custom DMA libs as their clients would need the export which would
   717 			custom DMA libs as their clients would need the export which would
   630 			be missing from the custom .def files.
   718 			be missing from the custom .def files.
       
   719 
       
   720 			@released
   631 		*/
   721 		*/
   632 		SCreateInfo() : iPriority(KDmaPriorityNone), iDynChannel(EFalse) {};
   722 		SCreateInfo() : iPriority(KDmaPriorityNone), iDynChannel(EFalse) {};
   633 
   723 
   634 		/** Identifier used by PSL to select channel to open */
   724 		/** Identifier used by PSL to select channel to open.
       
   725 
       
   726 			@released
       
   727 		*/
   635 		TUint32 iCookie;
   728 		TUint32 iCookie;
   636 		/** Number of descriptors this channel can use.
   729 		/** Number of descriptors this channel can maximally use.
   637 
   730 
   638 			This number is not used in the upgraded version of the DMA
   731 			This value will not be used in the fully implemented new version of
   639 			framework and is kept there only for source compatibility. If the
   732 			the DMA framework. Until then it is still required.
   640 			client is certain that it will only ever use that version, then the
   733 
   641 			value passed here doesn't matter - the framework will ignore it.
   734 			@released
   642 
   735 		*/
   643 			@deprecated
       
   644 		 */
       
   645 		TInt iDesCount;
   736 		TInt iDesCount;
   646 		/** DFC queue used to service DMA interrupts.
   737 		/** DFC queue used to service DMA interrupts.
   647 
   738 
   648 			The DFC thread priority must be higher than any client thread
   739 			The DFC thread priority must be higher than any client thread
   649 			priority to avoid a situation where a transfer completes while
   740 			priority to avoid a situation where a transfer completes while
   650 			being cancelled and another transfer is started before the DFC
   741 			being cancelled and another transfer is started before the DFC
   651 			thread gets a chance to run. This would lead to a stray DFC.
   742 			thread gets a chance to run. This would lead to a stray DFC.
       
   743 
       
   744 			@released
   652 		*/
   745 		*/
   653 		TDfcQue* iDfcQ;
   746 		TDfcQue* iDfcQ;
   654 		/** DFC priority */
   747 		/** DFC priority.
       
   748 
       
   749 			@released
       
   750 		*/
   655 		TUint8 iDfcPriority;
   751 		TUint8 iDfcPriority;
   656 		/** Used by PSL to configure a channel priority (if possible).
   752 		/** Used by PSL to configure a channel priority (if possible).
   657 
   753 
   658 			The default is KDmaPriorityNone (the don't care value).
   754 			The default is KDmaPriorityNone (the don't care value).
   659 
   755 
   660 		    @see TDmaPriority
   756 			@see TDmaPriority
       
   757 
       
   758 			@prototype
   661 		*/
   759 		*/
   662 		TUint iPriority;
   760 		TUint iPriority;
   663 		/** Request a dynamic DMA channel.
   761 		/** Request a dynamic DMA channel.
   664 
   762 
   665 			If this is set to ETrue then the Open call is for a 'dynamic' as
   763 			If this is set to ETrue then the Open call is for a 'dynamic' as
   666 			opposed to a static and solely owned DMA channel. A number of
   764 			opposed to a static and solely owned DMA channel. A number of
   667 			properties of the opened TDmaChannel object will be different in
   765 			properties of the opened TDmaChannel object will be different in
   668 			that case.
   766 			that case.
   669 
   767 
   670 			The default value is EFalse.
   768 			The default value is EFalse.
       
   769 
       
   770 			@prototype
   671 		 */
   771 		 */
   672 		TBool iDynChannel;
   772 		TBool iDynChannel;
   673 		};
   773 		};
   674 
   774 
   675 public:
   775 public:
   676     /** Opens the DMA channel.
   776 	/** Opens the DMA channel.
   677 
   777 
   678 		Channel selection is done by the hardware-specific layer using a cookie
   778 		Channel selection is done by the hardware-specific layer using a cookie
   679 		passed in via aInfo.
   779 		passed in via aInfo.
   680 
   780 
   681 		The client should not delete the returned pointer as the framework owns
   781 		The client should not delete the returned pointer as the framework owns
   687 
   787 
   688 		@param aChannel Points to open channel on successful return. NULL
   788 		@param aChannel Points to open channel on successful return. NULL
   689 		otherwise.
   789 		otherwise.
   690 
   790 
   691 		@return KErrNone or standard error code.
   791 		@return KErrNone or standard error code.
   692  	*/
   792 
       
   793 		@released
       
   794 	*/
   693 	IMPORT_C static TInt Open(const SCreateInfo& aInfo, TDmaChannel*& aChannel);
   795 	IMPORT_C static TInt Open(const SCreateInfo& aInfo, TDmaChannel*& aChannel);
   694 
   796 
   695 
   797 
   696 	/** Closes a previously opened DMA channel.
   798 	/** Closes a previously opened DMA channel.
   697 
   799 
   699 
   801 
   700 		The call will cause the resources associated with this channel to be
   802 		The call will cause the resources associated with this channel to be
   701 		released, and the pointer/reference to it mustn't therefore be accessed
   803 		released, and the pointer/reference to it mustn't therefore be accessed
   702 		any longer after the function has returned. The channel pointer should
   804 		any longer after the function has returned. The channel pointer should
   703 		be set to NULL by the client.
   805 		be set to NULL by the client.
       
   806 
       
   807 		@released
   704  	*/
   808  	*/
   705 	IMPORT_C void Close();
   809 	IMPORT_C void Close();
   706 
   810 
   707 
   811 
   708 	/** Logically links this channel to the one specified as an argument, or,
   812 	/** Logically links this channel to the one specified as an argument, or,
   731 		successfully, KErrCompletion if this channel was already linked to
   835 		successfully, KErrCompletion if this channel was already linked to
   732 		aChannel or already unlinked, KErrNotSupported if the DMAC doesn't
   836 		aChannel or already unlinked, KErrNotSupported if the DMAC doesn't
   733 		support channel linking, KErrArgument if this channel was already
   837 		support channel linking, KErrArgument if this channel was already
   734 		linked to a different channel, KErrGeneral if a general error occurred
   838 		linked to a different channel, KErrGeneral if a general error occurred
   735 		preventing a successful outcome.
   839 		preventing a successful outcome.
   736 	 */
   840 
       
   841 		@prototype
       
   842 	*/
   737 	IMPORT_C TInt LinkToChannel(TDmaChannel* aChannel);
   843 	IMPORT_C TInt LinkToChannel(TDmaChannel* aChannel);
       
   844 
   738 
   845 
   739 	/** Pauses an active transfer on this channel.
   846 	/** Pauses an active transfer on this channel.
   740 
   847 
   741 		A paused channel transfer can be resumed by calling Resume() or it can
   848 		A paused channel transfer can be resumed by calling Resume() or it can
   742 		be stopped altogether by calling CancelAll().
   849 		be stopped altogether by calling CancelAll().
   749 
   856 
   750 		@return KErrNone if a transfer has been paused successfully,
   857 		@return KErrNone if a transfer has been paused successfully,
   751 		KErrCompletion if a transfer was already paused, KErrNotSupported if
   858 		KErrCompletion if a transfer was already paused, KErrNotSupported if
   752 		the DMAC doesn't support channel transfer pausing/resuming, KErrGeneral
   859 		the DMAC doesn't support channel transfer pausing/resuming, KErrGeneral
   753 		if a general error occurred preventing a successful outcome.
   860 		if a general error occurred preventing a successful outcome.
   754 	 */
   861 
       
   862 		@released
       
   863 	*/
   755 	IMPORT_C TInt Pause();
   864 	IMPORT_C TInt Pause();
   756 
   865 
   757 
   866 
   758 	/** Resumes a transfer on this channel that is paused.
   867 	/** Resumes a transfer on this channel that is paused.
   759 
   868 
   765 		@see TDmaCallbackType::EDmaCallbackLinkedListPaused
   874 		@see TDmaCallbackType::EDmaCallbackLinkedListPaused
   766 
   875 
   767 		Function can only be used if the DMAC supports this functionality.
   876 		Function can only be used if the DMAC supports this functionality.
   768 
   877 
   769 		@see SDmacCaps::iChannelPauseAndResume
   878 		@see SDmacCaps::iChannelPauseAndResume
       
   879 		@see SDmacCaps::iLinkedListPausedInterrupt
   770 
   880 
   771 		@return KErrNone if a paused transfer has been resumed successfully,
   881 		@return KErrNone if a paused transfer has been resumed successfully,
   772 		KErrCompletion if there was no paused transfer, KErrNotSupported if the
   882 		KErrCompletion if there was no paused transfer, KErrNotSupported if the
   773 		DMAC doesn't support channel transfer pausing/resuming, KErrGeneral if
   883 		DMAC doesn't support channel transfer pausing/resuming, KErrGeneral if
   774 		a general error occurred preventing a successful outcome.
   884 		a general error occurred preventing a successful outcome.
   775 	 */
   885 
       
   886 		@released
       
   887 	*/
   776 	IMPORT_C TInt Resume();
   888 	IMPORT_C TInt Resume();
   777 
   889 
   778 
   890 
   779 	/** Cancels the current request and all the pending ones.
   891 	/** Cancels the current request and all the pending ones.
   780 	 */
   892 
       
   893 		@released
       
   894 	*/
   781 	IMPORT_C void CancelAll();
   895 	IMPORT_C void CancelAll();
   782 
   896 
   783 
   897 
   784 	/** Returns the channel's maximum transfer length based on the passed
   898 	/** Returns the channel's maximum transfer length based on the passed
   785 		arguments.
   899 		arguments.
   793 		@param aPslInfo Cookie passed to the PSL
   907 		@param aPslInfo Cookie passed to the PSL
   794 		@see TDmaTransferArgs::iPslRequestInfo
   908 		@see TDmaTransferArgs::iPslRequestInfo
   795 
   909 
   796 		@return 0 if transfer length is not limited, the maximum transfer
   910 		@return 0 if transfer length is not limited, the maximum transfer
   797 		length in bytes otherwise.
   911 		length in bytes otherwise.
       
   912 
       
   913 		@released
   798  	*/
   914  	*/
   799 	IMPORT_C TUint MaxTransferLength(TUint aSrcFlags, TUint aDstFlags, TUint32 aPslInfo);
   915 	IMPORT_C TUint MaxTransferLength(TUint aSrcFlags, TUint aDstFlags, TUint32 aPslInfo);
   800 
   916 
   801 
   917 
   802 	/** Retrieves from the PSL the address / memory alignment mask based on the
   918 	/** Retrieves from the PSL the address / memory alignment mask based on the
   817 		@param aPslInfo Cookie passed to the PSL
   933 		@param aPslInfo Cookie passed to the PSL
   818 		@see TDmaTransferArgs::iPslRequestInfo
   934 		@see TDmaTransferArgs::iPslRequestInfo
   819 
   935 
   820 		@return A value representing the alignment mask (e.g. 3 if buffer must
   936 		@return A value representing the alignment mask (e.g. 3 if buffer must
   821 		be 4-byte aligned)
   937 		be 4-byte aligned)
   822 	 */
   938 
       
   939 		@released
       
   940 	*/
   823 	IMPORT_C TUint AddressAlignMask(TUint aTargetFlags, TUint aElementSize,
   941 	IMPORT_C TUint AddressAlignMask(TUint aTargetFlags, TUint aElementSize,
   824 									TUint32 aPslInfo);
   942 									TUint32 aPslInfo);
   825 
   943 
   826 
   944 
   827 	/** Returns a reference to a structure containing the capabilities and
   945 	/** Returns a reference to a structure containing the capabilities and
   828 		features of the DMA controller associated with this channel.
   946 		features of the DMA controller associated with this channel.
   829 
   947 
   830 		@return A reference to a structure containing the capabilities and
   948 		@return A reference to a structure containing the capabilities and
   831 		features of the DMA controller associated with this channel.
   949 		features of the DMA controller associated with this channel.
   832 	 */
   950 
       
   951 		@released
       
   952 	*/
   833 	IMPORT_C const SDmacCaps& DmacCaps();
   953 	IMPORT_C const SDmacCaps& DmacCaps();
   834 
   954 
   835 
   955 
   836 	/** Sets up once more the transfer request that has just completed, after
   956 	/** Sets up once more the transfer request that has just completed, after
   837 		optionally having adjusted the transfer parameters as specified.
   957 		optionally having adjusted the transfer parameters as specified.
   874 		@see DDmaRequest::DDmaRequest(TDmaChannel&, TDmaCallback, TAny*, TUint)
   994 		@see DDmaRequest::DDmaRequest(TDmaChannel&, TDmaCallback, TAny*, TUint)
   875 		@see TDmaCallbackType::EDmaCallbackRequestCompletion
   995 		@see TDmaCallbackType::EDmaCallbackRequestCompletion
   876 		@see TDmaPILFlags::KDmaRequestCallbackFromIsr
   996 		@see TDmaPILFlags::KDmaRequestCallbackFromIsr
   877 
   997 
   878 		@return KErrGeneral if there was an error, KErrNone otherwise.
   998 		@return KErrGeneral if there was an error, KErrNone otherwise.
   879 	 */
   999 
       
  1000 		@released
       
  1001 	*/
   880 	IMPORT_C TInt IsrRedoRequest(TUint32 aSrcAddr=KPhysAddrInvalid,
  1002 	IMPORT_C TInt IsrRedoRequest(TUint32 aSrcAddr=KPhysAddrInvalid,
   881 								 TUint32 aDstAddr=KPhysAddrInvalid,
  1003 								 TUint32 aDstAddr=KPhysAddrInvalid,
   882 								 TUint aTransferCount=0,
  1004 								 TUint aTransferCount=0,
   883 								 TUint32 aPslRequestInfo=0,
  1005 								 TUint32 aPslRequestInfo=0,
   884 								 TBool aIsrCb=ETrue);
  1006 								 TBool aIsrCb=ETrue);
   889 		@return ETrue if channel is currently opened, EFalse otherwise.
  1011 		@return ETrue if channel is currently opened, EFalse otherwise.
   890 
  1012 
   891 		NB: This API should not be used any longer.
  1013 		NB: This API should not be used any longer.
   892 
  1014 
   893 		After calling TDmaChannel::Open() successfully the channel is
  1015 		After calling TDmaChannel::Open() successfully the channel is
   894 		guaranteed to be open. Therefore there seems no good reason for this
  1016 		guaranteed to be open, hence there seems no good reason for this API to
   895 		API to exist.
  1017 		exist.
   896 
  1018 
   897 		@deprecated
  1019 		@deprecated
   898 	 */
  1020 	*/
   899 	inline TBool IsOpened() const;
  1021 	inline TBool IsOpened() const;
   900 
  1022 
   901 
  1023 
   902 	/** Tests whether the channel's request queue is currently empty.
  1024 	/** Tests whether the channel's request queue is currently empty.
   903 
  1025 
   904 		@return ETrue if request queue is currently empty, EFalse otherwise.
  1026 		@return ETrue if request queue is currently empty, EFalse otherwise.
   905 	 */
  1027 
       
  1028 		@released
       
  1029 	*/
   906 	inline TBool IsQueueEmpty() const;
  1030 	inline TBool IsQueueEmpty() const;
   907 
  1031 
   908 
  1032 
   909 	/** Returns a PSL-specific value which uniquely identifies this channel -
  1033 	/** Returns a PSL-specific value which uniquely identifies this channel -
   910 		it is used for debug tracing by the PIL.
  1034 		it is used for debug tracing by the PIL.
   911 
  1035 
   912 		@return PSL-specific value which uniquely identifies this channel.
  1036 		@return PSL-specific value which uniquely identifies this channel.
   913 	 */
  1037 
       
  1038 		@released
       
  1039 	*/
   914 	inline TUint32 PslId() const;
  1040 	inline TUint32 PslId() const;
   915 
  1041 
   916 
  1042 
   917 	/** Called by a test harness to force an error when the next fragment is
  1043 	/** Called by a test harness to force an error when the next fragment is
   918 		transferred.
  1044 		transferred.
   919 
  1045 
   920 		@param aFragmentCount The number of consecutive fragments to fail
  1046 		@param aFragmentCount The number of consecutive fragments to fail
   921 	 */
  1047 
       
  1048 		@released
       
  1049 	*/
   922 	IMPORT_C TInt FailNext(TInt aFragmentCount);
  1050 	IMPORT_C TInt FailNext(TInt aFragmentCount);
   923 
  1051 
   924 
  1052 
   925 	/** Called by a test harness to force the DMA controller to miss one or
  1053 	/** Called by a test harness to force the DMA controller to miss one or
   926 		more interrupts.
  1054 		more interrupts.
   927 
  1055 
   928 		@param aInterruptCount The number of consecutive interrupts to miss
  1056 		@param aInterruptCount The number of consecutive interrupts to miss
   929 	 */
  1057 
       
  1058 		@released
       
  1059 	*/
   930 	IMPORT_C TInt MissNextInterrupts(TInt aInterruptCount);
  1060 	IMPORT_C TInt MissNextInterrupts(TInt aInterruptCount);
   931 
  1061 
   932 
  1062 
   933 	/** Function allowing platform-specific layer to extend channel API with
  1063 	/** Function allowing platform-specific layer to extend channel API with
   934 		new channel-specific operations.
  1064 		new channel-specific operations.
   935 
  1065 
   936 		@param aCmd Command identifier. Negative values are reserved for use by
  1066 		@param aCmd Command identifier.
   937 		Nokia.
       
   938 		@param aArg PSL-specific argument
  1067 		@param aArg PSL-specific argument
   939 
  1068 
   940 		@return KErrNotSupported if aCmd is not supported. PSL-specific value
  1069 		@return KErrNotSupported if aCmd is not supported. PSL-specific value
   941 		otherwise.
  1070 		otherwise.
   942 	 */
  1071 
       
  1072 		@released
       
  1073 	*/
   943 	IMPORT_C TInt Extension(TInt aCmd, TAny* aArg);
  1074 	IMPORT_C TInt Extension(TInt aCmd, TAny* aArg);
   944 
  1075 
   945 
  1076 
   946 	/** This is a function that allows the Platform Specific Layer (PSL) to
  1077 	/** This is a function that allows the Platform Specific Layer (PSL) to
   947 		extend the DMA API with new channel-independent operations.
  1078 		extend the DMA API with new channel-independent operations.
   948 
  1079 
   949 		@param aCmd Command identifier. Negative values are reserved for
  1080 		@param aCmd Command identifier.
   950 		Symbian use.
       
   951 		@param aArg PSL-specific.
  1081 		@param aArg PSL-specific.
   952 
  1082 
   953 		@return KErrNotSupported if aCmd is not supported; a PSL specific value
  1083 		@return KErrNotSupported if aCmd is not supported; a PSL specific value
   954 		otherwise.
  1084 		otherwise.
       
  1085 
       
  1086 		@released
   955  	*/
  1087  	*/
   956 	IMPORT_C TInt StaticExtension(TInt aCmd, TAny* aArg);
  1088 	IMPORT_C TInt StaticExtension(TInt aCmd, TAny* aArg);
   957 
  1089 
   958 
  1090 
   959 	/** @deprecated
  1091 	/** @see DmacCaps()
   960 		@see DmacCaps()
  1092 
   961 	 */
  1093 		@deprecated
       
  1094 	*/
   962 	inline const TDmac* Controller() const;
  1095 	inline const TDmac* Controller() const;
   963 
  1096 
   964 	/** @deprecated
  1097 	/** @see MaxTransferLength()
   965 		@see MaxTransferLength()
  1098 
   966 	 */
  1099 		@deprecated
       
  1100 	*/
   967 	inline TInt MaxTransferSize(TUint aFlags, TUint32 aPslInfo);
  1101 	inline TInt MaxTransferSize(TUint aFlags, TUint32 aPslInfo);
   968 
  1102 
   969 	/** @deprecated
  1103 	/** @see AddressAlignMask()
   970 		@see AddressAlignMask()
  1104 
   971 	 */
  1105 		@deprecated
       
  1106 	*/
   972 	inline TUint MemAlignMask(TUint aFlags, TUint32 aPslInfo);
  1107 	inline TUint MemAlignMask(TUint aFlags, TUint32 aPslInfo);
   973 
  1108 
   974 protected:
  1109 protected:
   975 	// Interface with state machines
  1110 	// Interface with state machines
       
  1111 
       
  1112 	/** Constructor.
       
  1113 
       
  1114 		@released
       
  1115 	*/
   976 	TDmaChannel();
  1116 	TDmaChannel();
   977 
  1117 
   978 	/** Called by the PIL when adding a new request to the channel's queue.
  1118 	/** Called by the PIL when adding a new request to the channel's queue.
   979 		The implementation should update the channel's state as appropriate
  1119 		The implementation should update the channel's state as appropriate
   980 		and begin transfer of aReq if possible.
  1120 		and begin transfer of aReq if possible.
   981 
  1121 
   982 		@param aReq The request which has been added to the queue
  1122 		@param aReq The request which has been added to the queue
       
  1123 
       
  1124 		@released
   983 	*/
  1125 	*/
   984 	virtual void DoQueue(const DDmaRequest& aReq);
  1126 	virtual void DoQueue(const DDmaRequest& aReq);
   985 
  1127 
   986 	/** Called by the PIL in response to a CancelAll call. It should update
  1128 	/** Called by the PIL in response to a CancelAll call. It should update
   987 		the channel state appropriately.
  1129 		the channel state appropriately.
       
  1130 
       
  1131 		@released
   988 	*/
  1132 	*/
   989 	virtual void DoCancelAll() = 0;
  1133 	virtual void DoCancelAll() = 0;
   990 
  1134 
   991 	/** This is called by the PIL when a DDmaRequest is removed from the
  1135 	/** This is called by the PIL when a DDmaRequest is removed from the
   992 		channel's queue. In general the implementation simply needs to unlink
  1136 		channel's queue. In general the implementation simply needs to unlink
   997 		is completed so that the request may be requeued by the client without
  1141 		is completed so that the request may be requeued by the client without
   998 		having called DDmaRequest::Fragment again.
  1142 		having called DDmaRequest::Fragment again.
   999 
  1143 
  1000 		@param aHdr The header for a descriptor, which must be unlinked
  1144 		@param aHdr The header for a descriptor, which must be unlinked
  1001 		from its next descriptor (if there is one)
  1145 		from its next descriptor (if there is one)
       
  1146 
       
  1147 		@released
  1002 	*/
  1148 	*/
  1003 	virtual void DoUnlink(SDmaDesHdr& aHdr);
  1149 	virtual void DoUnlink(SDmaDesHdr& aHdr);
  1004 
  1150 
  1005 	/** Called by the PIL whenever a transfer associated with aCurReq is
  1151 	/** Called by the PIL whenever a transfer associated with aCurReq is
  1006 		done. The implementation must advance the channel's state and
  1152 		done. The implementation must advance the channel's state and
  1010 		complete.
  1156 		complete.
  1011 
  1157 
  1012 		@param aCurReq The current request.
  1158 		@param aCurReq The current request.
  1013 		@param aCompletedHdr Must be set by the implementation to the header
  1159 		@param aCompletedHdr Must be set by the implementation to the header
  1014 		of the last transfer to complete.
  1160 		of the last transfer to complete.
       
  1161 
       
  1162 		@released
  1015 	*/
  1163 	*/
  1016 	virtual void DoDfc(const DDmaRequest& aCurReq, SDmaDesHdr*& aCompletedHdr);
  1164 	virtual void DoDfc(const DDmaRequest& aCurReq, SDmaDesHdr*& aCompletedHdr);
  1017 
  1165 
  1018 	/** Called by the PIL whenever a transfer associated with aCurReq is
  1166 	/** Called by the PIL whenever a transfer associated with aCurReq is
  1019 		done. The implementation must advance the channel's state and
  1167 		done. The implementation must advance the channel's state and
  1030 		@param aSrcCompletedHdr Must be set by the implementation to
  1178 		@param aSrcCompletedHdr Must be set by the implementation to
  1031 		the header of the last source descriptor to complete.
  1179 		the header of the last source descriptor to complete.
  1032 
  1180 
  1033 		@param aDstCompletedHdr Must be set by the implementation to
  1181 		@param aDstCompletedHdr Must be set by the implementation to
  1034 		the header of the last destination descriptor to complete.
  1182 		the header of the last destination descriptor to complete.
       
  1183 
       
  1184 		@prototype
  1035 	*/
  1185 	*/
  1036 	virtual void DoDfc(const DDmaRequest& aCurReq, SDmaDesHdr*& aSrcCompletedHdr,
  1186 	virtual void DoDfc(const DDmaRequest& aCurReq, SDmaDesHdr*& aSrcCompletedHdr,
  1037 					   SDmaDesHdr*& aDstCompletedHdr);
  1187 					   SDmaDesHdr*& aDstCompletedHdr);
  1038 
  1188 
  1039 	/** This function allows the Platform Specific Layer (PSL) to control the
  1189 	/** This function allows the Platform Specific Layer (PSL) to control the
  1078 	TBool iDynChannel;		 // this is a dynamically allocated channel
  1228 	TBool iDynChannel;		 // this is a dynamically allocated channel
  1079 	TUint iPriority;		 // hardware priority of this channel
  1229 	TUint iPriority;		 // hardware priority of this channel
  1080 	NFastMutex iLock;		 // for data accessed in both client & DFC context
  1230 	NFastMutex iLock;		 // for data accessed in both client & DFC context
  1081 	SDmaDesHdr* iCurHdr;	 // fragment being transferred or NULL
  1231 	SDmaDesHdr* iCurHdr;	 // fragment being transferred or NULL
  1082 	SDmaDesHdr** iNullPtr;	 // Pointer to NULL pointer following last fragment
  1232 	SDmaDesHdr** iNullPtr;	 // Pointer to NULL pointer following last fragment
  1083 	TDfc iDfc;				  // transfer completion/failure DFC
  1233 	TDfc iDfc;				 // transfer completion/failure DFC
  1084 	TInt iMaxDesCount;		  // maximum number of allocable descriptors
  1234 	TInt iMaxDesCount;		 // maximum number of allocable descriptors
  1085 	TInt iAvailDesCount;	  // available number of descriptors
  1235 	TInt iAvailDesCount;	 // available number of descriptors
  1086 	volatile TUint32 iIsrDfc; // Interface between ISR and DFC:
  1236 	volatile TUint32 iIsrDfc; // Interface between ISR and DFC:
  1087 	enum {KErrorFlagMask = 0x80000000};	   // bit 31 - error flag
  1237 	enum {KErrorFlagMask = 0x80000000};	   // bit 31 - error flag
  1088 	enum {KCancelFlagMask = 0x40000000};   // bit 30 - cancel flag
  1238 	enum {KCancelFlagMask = 0x40000000};   // bit 30 - cancel flag
  1089 	enum {KDfcCountMask = 0x3FFFFFFF};	   // bits 0-29 - number of queued DFCs
  1239 	enum {KDfcCountMask = 0x3FFFFFFF};	   // bits 0-29 - number of queued DFCs
  1090 	SDblQue iReqQ;				 // being/about to be transferred request queue
  1240 	SDblQue iReqQ;			// being/about to be transferred request queue
  1091 	TInt iReqCount;				 // number of requests attached to this channel
  1241 	TInt iReqCount;			// number of requests attached to this channel
  1092 	TInt iQueuedRequests; // number of requests currently queued on this channel
  1242 	TInt iQueuedRequests; 	// number of requests currently queued on this channel
       
  1243 
  1093 private:
  1244 private:
  1094 	TDmaCancelInfo* iCancelInfo; // ...
  1245 	TDmaCancelInfo* iCancelInfo; // ...
  1095 	TBool iRedoRequest;			 // client ISR callback wants a redo of request
  1246 	TBool iRedoRequest;		// client ISR callback wants a redo of request
  1096 	TBool iIsrCbRequest;		 // request on queue using ISR callback
  1247 	TBool iIsrCbRequest;	// request on queue using ISR callback
  1097 
  1248 
  1098 	__DMA_DECLARE_INVARIANT
  1249 	__DMA_DECLARE_INVARIANT
  1099 	};
  1250 	};
  1100 
  1251 
  1101 
  1252 
  1102 //////////////////////////////////////////////////////////////////////////////
  1253 //////////////////////////////////////////////////////////////////////////////
  1103 // INTERFACE WITH TEST HARNESS
  1254 // INTERFACE WITH TEST HARNESS
  1104 //////////////////////////////////////////////////////////////////////////////
  1255 //////////////////////////////////////////////////////////////////////////////
  1105 
  1256 
  1106 /** Set of information used by test harness.
       
  1107 
       
  1108 	@publishedPartner
       
  1109 	@released
       
  1110 */
       
  1111 struct TDmaTestInfo
       
  1112 	{
       
  1113 	/** Maximum transfer size in bytes for all channels (ie. the minimum of all channels' maximum size)*/
       
  1114 	TUint iMaxTransferSize;
       
  1115 	/** 3->Memory buffers must be 4-byte aligned, 7->8-byte aligned, ... */
       
  1116 	TUint iMemAlignMask;
       
  1117 	/** Cookie to pass to DDmaRequest::Fragment for memory-memory transfer*/
       
  1118 	TUint32 iMemMemPslInfo;
       
  1119 	/** Number of test single-buffer channels */
       
  1120 	TInt iMaxSbChannels;
       
  1121 	/** Pointer to array containing single-buffer test channel ids */
       
  1122 	TUint32* iSbChannels;
       
  1123 	/** Number of test double-buffer channels */
       
  1124 	TInt iMaxDbChannels;
       
  1125 	/** Pointer to array containing double-buffer test channel ids */
       
  1126 	TUint32* iDbChannels;
       
  1127 	/** Number of test scatter-gather channels */
       
  1128 	TInt iMaxSgChannels;
       
  1129 	/** Pointer to array containing scatter-gather test channel ids */
       
  1130 	TUint32* iSgChannels;
       
  1131 	};
       
  1132 
       
  1133 
       
  1134 /** Provides access to test information structure stored in the PSL.
  1257 /** Provides access to test information structure stored in the PSL.
  1135 
  1258 
  1136 	Must be implemented by the PSL.
  1259 	Must be implemented by the PSL (v1).
  1137 
  1260 
  1138 	@publishedPartner
  1261 	@deprecated
  1139 	@released
       
  1140 */
  1262 */
  1141 IMPORT_C const TDmaTestInfo& DmaTestInfo();
  1263 IMPORT_C const TDmaTestInfo& DmaTestInfo();
  1142 
  1264 
       
  1265 
  1143 /** Provides access to test information structure stored in the PSL.
  1266 /** Provides access to test information structure stored in the PSL.
  1144 
  1267 
  1145 	Must be implemented by the PSL.
  1268 	Must be implemented by the PSL (v2).
  1146 
  1269 
  1147 	@publishedPartner
       
  1148 	@released
  1270 	@released
  1149 */
  1271 */
  1150 IMPORT_C const TDmaV2TestInfo& DmaTestInfoV2();
  1272 IMPORT_C const TDmaV2TestInfo& DmaTestInfoV2();
  1151 
  1273 
  1152 
  1274 
  1153 
       
  1154 //////////////////////////////////////////////////////////////////////////////
  1275 //////////////////////////////////////////////////////////////////////////////
  1155 
  1276 
  1156 
  1277 
  1157 #include <drivers/dma_compat.inl>
  1278 #include <drivers/dma_compat.inl>
  1158 #include <drivers/dma_v2.inl>
  1279 #include <drivers/dma_v2.inl>