aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/dmaengine.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/dmaengine.h')
-rw-r--r--include/linux/dmaengine.h117
1 files changed, 55 insertions, 62 deletions
diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
index 40cd75e21ea2..50745e3a8a3f 100644
--- a/include/linux/dmaengine.h
+++ b/include/linux/dmaengine.h
@@ -189,25 +189,6 @@ enum dma_ctrl_flags {
189}; 189};
190 190
191/** 191/**
192 * enum dma_ctrl_cmd - DMA operations that can optionally be exercised
193 * on a running channel.
194 * @DMA_TERMINATE_ALL: terminate all ongoing transfers
195 * @DMA_PAUSE: pause ongoing transfers
196 * @DMA_RESUME: resume paused transfer
197 * @DMA_SLAVE_CONFIG: this command is only implemented by DMA controllers
198 * that need to runtime reconfigure the slave channels (as opposed to passing
199 * configuration data in statically from the platform). An additional
200 * argument of struct dma_slave_config must be passed in with this
201 * command.
202 */
203enum dma_ctrl_cmd {
204 DMA_TERMINATE_ALL,
205 DMA_PAUSE,
206 DMA_RESUME,
207 DMA_SLAVE_CONFIG,
208};
209
210/**
211 * enum sum_check_bits - bit position of pq_check_flags 192 * enum sum_check_bits - bit position of pq_check_flags
212 */ 193 */
213enum sum_check_bits { 194enum sum_check_bits {
@@ -336,9 +317,8 @@ enum dma_slave_buswidth {
336 * This struct is passed in as configuration data to a DMA engine 317 * This struct is passed in as configuration data to a DMA engine
337 * in order to set up a certain channel for DMA transport at runtime. 318 * in order to set up a certain channel for DMA transport at runtime.
338 * The DMA device/engine has to provide support for an additional 319 * The DMA device/engine has to provide support for an additional
339 * command in the channel config interface, DMA_SLAVE_CONFIG 320 * callback in the dma_device structure, device_config and this struct
340 * and this struct will then be passed in as an argument to the 321 * will then be passed in as an argument to the function.
341 * DMA engine device_control() function.
342 * 322 *
343 * The rationale for adding configuration information to this struct is as 323 * The rationale for adding configuration information to this struct is as
344 * follows: if it is likely that more than one DMA slave controllers in 324 * follows: if it is likely that more than one DMA slave controllers in
@@ -387,7 +367,7 @@ enum dma_residue_granularity {
387/* struct dma_slave_caps - expose capabilities of a slave channel only 367/* struct dma_slave_caps - expose capabilities of a slave channel only
388 * 368 *
389 * @src_addr_widths: bit mask of src addr widths the channel supports 369 * @src_addr_widths: bit mask of src addr widths the channel supports
390 * @dstn_addr_widths: bit mask of dstn addr widths the channel supports 370 * @dst_addr_widths: bit mask of dstn addr widths the channel supports
391 * @directions: bit mask of slave direction the channel supported 371 * @directions: bit mask of slave direction the channel supported
392 * since the enum dma_transfer_direction is not defined as bits for each 372 * since the enum dma_transfer_direction is not defined as bits for each
393 * type of direction, the dma controller should fill (1 << <TYPE>) and same 373 * type of direction, the dma controller should fill (1 << <TYPE>) and same
@@ -398,7 +378,7 @@ enum dma_residue_granularity {
398 */ 378 */
399struct dma_slave_caps { 379struct dma_slave_caps {
400 u32 src_addr_widths; 380 u32 src_addr_widths;
401 u32 dstn_addr_widths; 381 u32 dst_addr_widths;
402 u32 directions; 382 u32 directions;
403 bool cmd_pause; 383 bool cmd_pause;
404 bool cmd_terminate; 384 bool cmd_terminate;
@@ -594,6 +574,14 @@ struct dma_tx_state {
594 * @fill_align: alignment shift for memset operations 574 * @fill_align: alignment shift for memset operations
595 * @dev_id: unique device ID 575 * @dev_id: unique device ID
596 * @dev: struct device reference for dma mapping api 576 * @dev: struct device reference for dma mapping api
577 * @src_addr_widths: bit mask of src addr widths the device supports
578 * @dst_addr_widths: bit mask of dst addr widths the device supports
579 * @directions: bit mask of slave direction the device supports since
580 * the enum dma_transfer_direction is not defined as bits for
581 * each type of direction, the dma controller should fill (1 <<
582 * <TYPE>) and same should be checked by controller as well
583 * @residue_granularity: granularity of the transfer residue reported
584 * by tx_status
597 * @device_alloc_chan_resources: allocate resources and return the 585 * @device_alloc_chan_resources: allocate resources and return the
598 * number of allocated descriptors 586 * number of allocated descriptors
599 * @device_free_chan_resources: release DMA channel's resources 587 * @device_free_chan_resources: release DMA channel's resources
@@ -608,14 +596,19 @@ struct dma_tx_state {
608 * The function takes a buffer of size buf_len. The callback function will 596 * The function takes a buffer of size buf_len. The callback function will
609 * be called after period_len bytes have been transferred. 597 * be called after period_len bytes have been transferred.
610 * @device_prep_interleaved_dma: Transfer expression in a generic way. 598 * @device_prep_interleaved_dma: Transfer expression in a generic way.
611 * @device_control: manipulate all pending operations on a channel, returns 599 * @device_config: Pushes a new configuration to a channel, return 0 or an error
612 * zero or error code 600 * code
601 * @device_pause: Pauses any transfer happening on a channel. Returns
602 * 0 or an error code
603 * @device_resume: Resumes any transfer on a channel previously
604 * paused. Returns 0 or an error code
605 * @device_terminate_all: Aborts all transfers on a channel. Returns 0
606 * or an error code
613 * @device_tx_status: poll for transaction completion, the optional 607 * @device_tx_status: poll for transaction completion, the optional
614 * txstate parameter can be supplied with a pointer to get a 608 * txstate parameter can be supplied with a pointer to get a
615 * struct with auxiliary transfer status information, otherwise the call 609 * struct with auxiliary transfer status information, otherwise the call
616 * will just return a simple status code 610 * will just return a simple status code
617 * @device_issue_pending: push pending transactions to hardware 611 * @device_issue_pending: push pending transactions to hardware
618 * @device_slave_caps: return the slave channel capabilities
619 */ 612 */
620struct dma_device { 613struct dma_device {
621 614
@@ -635,14 +628,19 @@ struct dma_device {
635 int dev_id; 628 int dev_id;
636 struct device *dev; 629 struct device *dev;
637 630
631 u32 src_addr_widths;
632 u32 dst_addr_widths;
633 u32 directions;
634 enum dma_residue_granularity residue_granularity;
635
638 int (*device_alloc_chan_resources)(struct dma_chan *chan); 636 int (*device_alloc_chan_resources)(struct dma_chan *chan);
639 void (*device_free_chan_resources)(struct dma_chan *chan); 637 void (*device_free_chan_resources)(struct dma_chan *chan);
640 638
641 struct dma_async_tx_descriptor *(*device_prep_dma_memcpy)( 639 struct dma_async_tx_descriptor *(*device_prep_dma_memcpy)(
642 struct dma_chan *chan, dma_addr_t dest, dma_addr_t src, 640 struct dma_chan *chan, dma_addr_t dst, dma_addr_t src,
643 size_t len, unsigned long flags); 641 size_t len, unsigned long flags);
644 struct dma_async_tx_descriptor *(*device_prep_dma_xor)( 642 struct dma_async_tx_descriptor *(*device_prep_dma_xor)(
645 struct dma_chan *chan, dma_addr_t dest, dma_addr_t *src, 643 struct dma_chan *chan, dma_addr_t dst, dma_addr_t *src,
646 unsigned int src_cnt, size_t len, unsigned long flags); 644 unsigned int src_cnt, size_t len, unsigned long flags);
647 struct dma_async_tx_descriptor *(*device_prep_dma_xor_val)( 645 struct dma_async_tx_descriptor *(*device_prep_dma_xor_val)(
648 struct dma_chan *chan, dma_addr_t *src, unsigned int src_cnt, 646 struct dma_chan *chan, dma_addr_t *src, unsigned int src_cnt,
@@ -674,31 +672,26 @@ struct dma_device {
674 struct dma_async_tx_descriptor *(*device_prep_interleaved_dma)( 672 struct dma_async_tx_descriptor *(*device_prep_interleaved_dma)(
675 struct dma_chan *chan, struct dma_interleaved_template *xt, 673 struct dma_chan *chan, struct dma_interleaved_template *xt,
676 unsigned long flags); 674 unsigned long flags);
677 int (*device_control)(struct dma_chan *chan, enum dma_ctrl_cmd cmd, 675
678 unsigned long arg); 676 int (*device_config)(struct dma_chan *chan,
677 struct dma_slave_config *config);
678 int (*device_pause)(struct dma_chan *chan);
679 int (*device_resume)(struct dma_chan *chan);
680 int (*device_terminate_all)(struct dma_chan *chan);
679 681
680 enum dma_status (*device_tx_status)(struct dma_chan *chan, 682 enum dma_status (*device_tx_status)(struct dma_chan *chan,
681 dma_cookie_t cookie, 683 dma_cookie_t cookie,
682 struct dma_tx_state *txstate); 684 struct dma_tx_state *txstate);
683 void (*device_issue_pending)(struct dma_chan *chan); 685 void (*device_issue_pending)(struct dma_chan *chan);
684 int (*device_slave_caps)(struct dma_chan *chan, struct dma_slave_caps *caps);
685}; 686};
686 687
687static inline int dmaengine_device_control(struct dma_chan *chan,
688 enum dma_ctrl_cmd cmd,
689 unsigned long arg)
690{
691 if (chan->device->device_control)
692 return chan->device->device_control(chan, cmd, arg);
693
694 return -ENOSYS;
695}
696
697static inline int dmaengine_slave_config(struct dma_chan *chan, 688static inline int dmaengine_slave_config(struct dma_chan *chan,
698 struct dma_slave_config *config) 689 struct dma_slave_config *config)
699{ 690{
700 return dmaengine_device_control(chan, DMA_SLAVE_CONFIG, 691 if (chan->device->device_config)
701 (unsigned long)config); 692 return chan->device->device_config(chan, config);
693
694 return -ENOSYS;
702} 695}
703 696
704static inline bool is_slave_direction(enum dma_transfer_direction direction) 697static inline bool is_slave_direction(enum dma_transfer_direction direction)
@@ -765,34 +758,28 @@ static inline struct dma_async_tx_descriptor *dmaengine_prep_dma_sg(
765 src_sg, src_nents, flags); 758 src_sg, src_nents, flags);
766} 759}
767 760
768static inline int dma_get_slave_caps(struct dma_chan *chan, struct dma_slave_caps *caps)
769{
770 if (!chan || !caps)
771 return -EINVAL;
772
773 /* check if the channel supports slave transactions */
774 if (!test_bit(DMA_SLAVE, chan->device->cap_mask.bits))
775 return -ENXIO;
776
777 if (chan->device->device_slave_caps)
778 return chan->device->device_slave_caps(chan, caps);
779
780 return -ENXIO;
781}
782
783static inline int dmaengine_terminate_all(struct dma_chan *chan) 761static inline int dmaengine_terminate_all(struct dma_chan *chan)
784{ 762{
785 return dmaengine_device_control(chan, DMA_TERMINATE_ALL, 0); 763 if (chan->device->device_terminate_all)
764 return chan->device->device_terminate_all(chan);
765
766 return -ENOSYS;
786} 767}
787 768
788static inline int dmaengine_pause(struct dma_chan *chan) 769static inline int dmaengine_pause(struct dma_chan *chan)
789{ 770{
790 return dmaengine_device_control(chan, DMA_PAUSE, 0); 771 if (chan->device->device_pause)
772 return chan->device->device_pause(chan);
773
774 return -ENOSYS;
791} 775}
792 776
793static inline int dmaengine_resume(struct dma_chan *chan) 777static inline int dmaengine_resume(struct dma_chan *chan)
794{ 778{
795 return dmaengine_device_control(chan, DMA_RESUME, 0); 779 if (chan->device->device_resume)
780 return chan->device->device_resume(chan);
781
782 return -ENOSYS;
796} 783}
797 784
798static inline enum dma_status dmaengine_tx_status(struct dma_chan *chan, 785static inline enum dma_status dmaengine_tx_status(struct dma_chan *chan,
@@ -1059,6 +1046,7 @@ struct dma_chan *dma_request_slave_channel_reason(struct device *dev,
1059 const char *name); 1046 const char *name);
1060struct dma_chan *dma_request_slave_channel(struct device *dev, const char *name); 1047struct dma_chan *dma_request_slave_channel(struct device *dev, const char *name);
1061void dma_release_channel(struct dma_chan *chan); 1048void dma_release_channel(struct dma_chan *chan);
1049int dma_get_slave_caps(struct dma_chan *chan, struct dma_slave_caps *caps);
1062#else 1050#else
1063static inline struct dma_chan *dma_find_channel(enum dma_transaction_type tx_type) 1051static inline struct dma_chan *dma_find_channel(enum dma_transaction_type tx_type)
1064{ 1052{
@@ -1093,6 +1081,11 @@ static inline struct dma_chan *dma_request_slave_channel(struct device *dev,
1093static inline void dma_release_channel(struct dma_chan *chan) 1081static inline void dma_release_channel(struct dma_chan *chan)
1094{ 1082{
1095} 1083}
1084static inline int dma_get_slave_caps(struct dma_chan *chan,
1085 struct dma_slave_caps *caps)
1086{
1087 return -ENXIO;
1088}
1096#endif 1089#endif
1097 1090
1098/* --- DMA device --- */ 1091/* --- DMA device --- */