1c13c8260SChris Leech /* 2c13c8260SChris Leech * Copyright(c) 2004 - 2006 Intel Corporation. All rights reserved. 3c13c8260SChris Leech * 4c13c8260SChris Leech * This program is free software; you can redistribute it and/or modify it 5c13c8260SChris Leech * under the terms of the GNU General Public License as published by the Free 6c13c8260SChris Leech * Software Foundation; either version 2 of the License, or (at your option) 7c13c8260SChris Leech * any later version. 8c13c8260SChris Leech * 9c13c8260SChris Leech * This program is distributed in the hope that it will be useful, but WITHOUT 10c13c8260SChris Leech * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11c13c8260SChris Leech * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12c13c8260SChris Leech * more details. 13c13c8260SChris Leech * 14c13c8260SChris Leech * You should have received a copy of the GNU General Public License along with 15c13c8260SChris Leech * this program; if not, write to the Free Software Foundation, Inc., 59 16c13c8260SChris Leech * Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17c13c8260SChris Leech * 18c13c8260SChris Leech * The full GNU General Public License is included in this distribution in the 19c13c8260SChris Leech * file called COPYING. 20c13c8260SChris Leech */ 21c13c8260SChris Leech #ifndef DMAENGINE_H 22c13c8260SChris Leech #define DMAENGINE_H 231c0f16e5SDavid Woodhouse 24c13c8260SChris Leech #include <linux/device.h> 25c13c8260SChris Leech #include <linux/uio.h> 26c13c8260SChris Leech #include <linux/kref.h> 27c13c8260SChris Leech #include <linux/completion.h> 28c13c8260SChris Leech #include <linux/rcupdate.h> 297405f74bSDan Williams #include <linux/dma-mapping.h> 30c13c8260SChris Leech 31c13c8260SChris Leech /** 32fd3f8984SJoe Perches * enum dma_state - resource PNP/power management state 33c13c8260SChris Leech * @DMA_RESOURCE_SUSPEND: DMA device going into low power state 34c13c8260SChris Leech * @DMA_RESOURCE_RESUME: DMA device returning to full power 35d379b01eSDan Williams * @DMA_RESOURCE_AVAILABLE: DMA device available to the system 36c13c8260SChris Leech * @DMA_RESOURCE_REMOVED: DMA device removed from the system 37c13c8260SChris Leech */ 38d379b01eSDan Williams enum dma_state { 39c13c8260SChris Leech DMA_RESOURCE_SUSPEND, 40c13c8260SChris Leech DMA_RESOURCE_RESUME, 41d379b01eSDan Williams DMA_RESOURCE_AVAILABLE, 42c13c8260SChris Leech DMA_RESOURCE_REMOVED, 43c13c8260SChris Leech }; 44c13c8260SChris Leech 45c13c8260SChris Leech /** 46d379b01eSDan Williams * enum dma_state_client - state of the channel in the client 47d379b01eSDan Williams * @DMA_ACK: client would like to use, or was using this channel 48d379b01eSDan Williams * @DMA_DUP: client has already seen this channel, or is not using this channel 49d379b01eSDan Williams * @DMA_NAK: client does not want to see any more channels 50d379b01eSDan Williams */ 51d379b01eSDan Williams enum dma_state_client { 52d379b01eSDan Williams DMA_ACK, 53d379b01eSDan Williams DMA_DUP, 54d379b01eSDan Williams DMA_NAK, 55d379b01eSDan Williams }; 56d379b01eSDan Williams 57d379b01eSDan Williams /** 58fe4ada2dSRandy Dunlap * typedef dma_cookie_t - an opaque DMA cookie 59c13c8260SChris Leech * 60c13c8260SChris Leech * if dma_cookie_t is >0 it's a DMA request cookie, <0 it's an error code 61c13c8260SChris Leech */ 62c13c8260SChris Leech typedef s32 dma_cookie_t; 63c13c8260SChris Leech 64c13c8260SChris Leech #define dma_submit_error(cookie) ((cookie) < 0 ? 1 : 0) 65c13c8260SChris Leech 66c13c8260SChris Leech /** 67c13c8260SChris Leech * enum dma_status - DMA transaction status 68c13c8260SChris Leech * @DMA_SUCCESS: transaction completed successfully 69c13c8260SChris Leech * @DMA_IN_PROGRESS: transaction not yet processed 70c13c8260SChris Leech * @DMA_ERROR: transaction failed 71c13c8260SChris Leech */ 72c13c8260SChris Leech enum dma_status { 73c13c8260SChris Leech DMA_SUCCESS, 74c13c8260SChris Leech DMA_IN_PROGRESS, 75c13c8260SChris Leech DMA_ERROR, 76c13c8260SChris Leech }; 77c13c8260SChris Leech 78c13c8260SChris Leech /** 797405f74bSDan Williams * enum dma_transaction_type - DMA transaction types/indexes 807405f74bSDan Williams */ 817405f74bSDan Williams enum dma_transaction_type { 827405f74bSDan Williams DMA_MEMCPY, 837405f74bSDan Williams DMA_XOR, 847405f74bSDan Williams DMA_PQ_XOR, 857405f74bSDan Williams DMA_DUAL_XOR, 867405f74bSDan Williams DMA_PQ_UPDATE, 877405f74bSDan Williams DMA_ZERO_SUM, 887405f74bSDan Williams DMA_PQ_ZERO_SUM, 897405f74bSDan Williams DMA_MEMSET, 907405f74bSDan Williams DMA_MEMCPY_CRC32C, 917405f74bSDan Williams DMA_INTERRUPT, 927405f74bSDan Williams }; 937405f74bSDan Williams 947405f74bSDan Williams /* last transaction type for creation of the capabilities mask */ 957405f74bSDan Williams #define DMA_TX_TYPE_END (DMA_INTERRUPT + 1) 967405f74bSDan Williams 977405f74bSDan Williams /** 98d4c56f97SDan Williams * enum dma_prep_flags - DMA flags to augment operation preparation 99d4c56f97SDan Williams * @DMA_PREP_INTERRUPT - trigger an interrupt (callback) upon completion of 100d4c56f97SDan Williams * this transaction 101d4c56f97SDan Williams */ 102d4c56f97SDan Williams enum dma_prep_flags { 103d4c56f97SDan Williams DMA_PREP_INTERRUPT = (1 << 0), 104d4c56f97SDan Williams }; 105d4c56f97SDan Williams 106d4c56f97SDan Williams /** 1077405f74bSDan Williams * dma_cap_mask_t - capabilities bitmap modeled after cpumask_t. 1087405f74bSDan Williams * See linux/cpumask.h 1097405f74bSDan Williams */ 1107405f74bSDan Williams typedef struct { DECLARE_BITMAP(bits, DMA_TX_TYPE_END); } dma_cap_mask_t; 1117405f74bSDan Williams 1127405f74bSDan Williams /** 113c13c8260SChris Leech * struct dma_chan_percpu - the per-CPU part of struct dma_chan 114c13c8260SChris Leech * @refcount: local_t used for open-coded "bigref" counting 115c13c8260SChris Leech * @memcpy_count: transaction counter 116c13c8260SChris Leech * @bytes_transferred: byte counter 117c13c8260SChris Leech */ 118c13c8260SChris Leech 119c13c8260SChris Leech struct dma_chan_percpu { 120c13c8260SChris Leech local_t refcount; 121c13c8260SChris Leech /* stats */ 122c13c8260SChris Leech unsigned long memcpy_count; 123c13c8260SChris Leech unsigned long bytes_transferred; 124c13c8260SChris Leech }; 125c13c8260SChris Leech 126c13c8260SChris Leech /** 127c13c8260SChris Leech * struct dma_chan - devices supply DMA channels, clients use them 128fe4ada2dSRandy Dunlap * @device: ptr to the dma device who supplies this channel, always !%NULL 129c13c8260SChris Leech * @cookie: last cookie value returned to client 130fe4ada2dSRandy Dunlap * @chan_id: channel ID for sysfs 131fe4ada2dSRandy Dunlap * @class_dev: class device for sysfs 132c13c8260SChris Leech * @refcount: kref, used in "bigref" slow-mode 133fe4ada2dSRandy Dunlap * @slow_ref: indicates that the DMA channel is free 134fe4ada2dSRandy Dunlap * @rcu: the DMA channel's RCU head 135c13c8260SChris Leech * @device_node: used to add this to the device chan list 136c13c8260SChris Leech * @local: per-cpu pointer to a struct dma_chan_percpu 137c13c8260SChris Leech */ 138c13c8260SChris Leech struct dma_chan { 139c13c8260SChris Leech struct dma_device *device; 140c13c8260SChris Leech dma_cookie_t cookie; 141c13c8260SChris Leech 142c13c8260SChris Leech /* sysfs */ 143c13c8260SChris Leech int chan_id; 144891f78eaSTony Jones struct device dev; 145c13c8260SChris Leech 146c13c8260SChris Leech struct kref refcount; 147c13c8260SChris Leech int slow_ref; 148c13c8260SChris Leech struct rcu_head rcu; 149c13c8260SChris Leech 150c13c8260SChris Leech struct list_head device_node; 151c13c8260SChris Leech struct dma_chan_percpu *local; 152c13c8260SChris Leech }; 153c13c8260SChris Leech 154891f78eaSTony Jones #define to_dma_chan(p) container_of(p, struct dma_chan, dev) 155d379b01eSDan Williams 156c13c8260SChris Leech void dma_chan_cleanup(struct kref *kref); 157c13c8260SChris Leech 158c13c8260SChris Leech static inline void dma_chan_get(struct dma_chan *chan) 159c13c8260SChris Leech { 160c13c8260SChris Leech if (unlikely(chan->slow_ref)) 161c13c8260SChris Leech kref_get(&chan->refcount); 162c13c8260SChris Leech else { 163c13c8260SChris Leech local_inc(&(per_cpu_ptr(chan->local, get_cpu())->refcount)); 164c13c8260SChris Leech put_cpu(); 165c13c8260SChris Leech } 166c13c8260SChris Leech } 167c13c8260SChris Leech 168c13c8260SChris Leech static inline void dma_chan_put(struct dma_chan *chan) 169c13c8260SChris Leech { 170c13c8260SChris Leech if (unlikely(chan->slow_ref)) 171c13c8260SChris Leech kref_put(&chan->refcount, dma_chan_cleanup); 172c13c8260SChris Leech else { 173c13c8260SChris Leech local_dec(&(per_cpu_ptr(chan->local, get_cpu())->refcount)); 174c13c8260SChris Leech put_cpu(); 175c13c8260SChris Leech } 176c13c8260SChris Leech } 177c13c8260SChris Leech 178c13c8260SChris Leech /* 179c13c8260SChris Leech * typedef dma_event_callback - function pointer to a DMA event callback 180d379b01eSDan Williams * For each channel added to the system this routine is called for each client. 181d379b01eSDan Williams * If the client would like to use the channel it returns '1' to signal (ack) 182d379b01eSDan Williams * the dmaengine core to take out a reference on the channel and its 183d379b01eSDan Williams * corresponding device. A client must not 'ack' an available channel more 184d379b01eSDan Williams * than once. When a channel is removed all clients are notified. If a client 185d379b01eSDan Williams * is using the channel it must 'ack' the removal. A client must not 'ack' a 186d379b01eSDan Williams * removed channel more than once. 187d379b01eSDan Williams * @client - 'this' pointer for the client context 188d379b01eSDan Williams * @chan - channel to be acted upon 189d379b01eSDan Williams * @state - available or removed 190c13c8260SChris Leech */ 191d379b01eSDan Williams struct dma_client; 192d379b01eSDan Williams typedef enum dma_state_client (*dma_event_callback) (struct dma_client *client, 193d379b01eSDan Williams struct dma_chan *chan, enum dma_state state); 194c13c8260SChris Leech 195c13c8260SChris Leech /** 196c13c8260SChris Leech * struct dma_client - info on the entity making use of DMA services 197c13c8260SChris Leech * @event_callback: func ptr to call when something happens 198d379b01eSDan Williams * @cap_mask: only return channels that satisfy the requested capabilities 199d379b01eSDan Williams * a value of zero corresponds to any capability 200c13c8260SChris Leech * @global_node: list_head for global dma_client_list 201c13c8260SChris Leech */ 202c13c8260SChris Leech struct dma_client { 203c13c8260SChris Leech dma_event_callback event_callback; 204d379b01eSDan Williams dma_cap_mask_t cap_mask; 205c13c8260SChris Leech struct list_head global_node; 206c13c8260SChris Leech }; 207c13c8260SChris Leech 2087405f74bSDan Williams typedef void (*dma_async_tx_callback)(void *dma_async_param); 2097405f74bSDan Williams /** 2107405f74bSDan Williams * struct dma_async_tx_descriptor - async transaction descriptor 2117405f74bSDan Williams * ---dma generic offload fields--- 2127405f74bSDan Williams * @cookie: tracking cookie for this transaction, set to -EBUSY if 2137405f74bSDan Williams * this tx is sitting on a dependency list 2147405f74bSDan Williams * @ack: the descriptor can not be reused until the client acknowledges 2157405f74bSDan Williams * receipt, i.e. has has a chance to establish any dependency chains 2167405f74bSDan Williams * @phys: physical address of the descriptor 2177405f74bSDan Williams * @tx_list: driver common field for operations that require multiple 2187405f74bSDan Williams * descriptors 2197405f74bSDan Williams * @chan: target channel for this operation 2207405f74bSDan Williams * @tx_submit: set the prepared descriptor(s) to be executed by the engine 2217405f74bSDan Williams * @callback: routine to call after this operation is complete 2227405f74bSDan Williams * @callback_param: general parameter to pass to the callback routine 2237405f74bSDan Williams * ---async_tx api specific fields--- 2247405f74bSDan Williams * @depend_list: at completion this list of transactions are submitted 2257405f74bSDan Williams * @depend_node: allow this transaction to be executed after another 2267405f74bSDan Williams * transaction has completed, possibly on another channel 2277405f74bSDan Williams * @parent: pointer to the next level up in the dependency chain 2287405f74bSDan Williams * @lock: protect the dependency list 2297405f74bSDan Williams */ 2307405f74bSDan Williams struct dma_async_tx_descriptor { 2317405f74bSDan Williams dma_cookie_t cookie; 2327405f74bSDan Williams int ack; 2337405f74bSDan Williams dma_addr_t phys; 2347405f74bSDan Williams struct list_head tx_list; 2357405f74bSDan Williams struct dma_chan *chan; 2367405f74bSDan Williams dma_cookie_t (*tx_submit)(struct dma_async_tx_descriptor *tx); 2377405f74bSDan Williams dma_async_tx_callback callback; 2387405f74bSDan Williams void *callback_param; 2397405f74bSDan Williams struct list_head depend_list; 2407405f74bSDan Williams struct list_head depend_node; 2417405f74bSDan Williams struct dma_async_tx_descriptor *parent; 2427405f74bSDan Williams spinlock_t lock; 2437405f74bSDan Williams }; 2447405f74bSDan Williams 245c13c8260SChris Leech /** 246c13c8260SChris Leech * struct dma_device - info on the entity supplying DMA services 247c13c8260SChris Leech * @chancnt: how many DMA channels are supported 248c13c8260SChris Leech * @channels: the list of struct dma_chan 249c13c8260SChris Leech * @global_node: list_head for global dma_device_list 2507405f74bSDan Williams * @cap_mask: one or more dma_capability flags 2517405f74bSDan Williams * @max_xor: maximum number of xor sources, 0 if no capability 252fe4ada2dSRandy Dunlap * @refcount: reference count 253fe4ada2dSRandy Dunlap * @done: IO completion struct 254fe4ada2dSRandy Dunlap * @dev_id: unique device ID 2557405f74bSDan Williams * @dev: struct device reference for dma mapping api 256fe4ada2dSRandy Dunlap * @device_alloc_chan_resources: allocate resources and return the 257fe4ada2dSRandy Dunlap * number of allocated descriptors 258fe4ada2dSRandy Dunlap * @device_free_chan_resources: release DMA channel's resources 2597405f74bSDan Williams * @device_prep_dma_memcpy: prepares a memcpy operation 2607405f74bSDan Williams * @device_prep_dma_xor: prepares a xor operation 2617405f74bSDan Williams * @device_prep_dma_zero_sum: prepares a zero_sum operation 2627405f74bSDan Williams * @device_prep_dma_memset: prepares a memset operation 2637405f74bSDan Williams * @device_prep_dma_interrupt: prepares an end of chain interrupt operation 2647405f74bSDan Williams * @device_dependency_added: async_tx notifies the channel about new deps 2657405f74bSDan Williams * @device_issue_pending: push pending transactions to hardware 266c13c8260SChris Leech */ 267c13c8260SChris Leech struct dma_device { 268c13c8260SChris Leech 269c13c8260SChris Leech unsigned int chancnt; 270c13c8260SChris Leech struct list_head channels; 271c13c8260SChris Leech struct list_head global_node; 2727405f74bSDan Williams dma_cap_mask_t cap_mask; 2737405f74bSDan Williams int max_xor; 274c13c8260SChris Leech 275c13c8260SChris Leech struct kref refcount; 276c13c8260SChris Leech struct completion done; 277c13c8260SChris Leech 278c13c8260SChris Leech int dev_id; 2797405f74bSDan Williams struct device *dev; 280c13c8260SChris Leech 281c13c8260SChris Leech int (*device_alloc_chan_resources)(struct dma_chan *chan); 282c13c8260SChris Leech void (*device_free_chan_resources)(struct dma_chan *chan); 2837405f74bSDan Williams 2847405f74bSDan Williams struct dma_async_tx_descriptor *(*device_prep_dma_memcpy)( 2850036731cSDan Williams struct dma_chan *chan, dma_addr_t dest, dma_addr_t src, 286d4c56f97SDan Williams size_t len, unsigned long flags); 2877405f74bSDan Williams struct dma_async_tx_descriptor *(*device_prep_dma_xor)( 2880036731cSDan Williams struct dma_chan *chan, dma_addr_t dest, dma_addr_t *src, 289d4c56f97SDan Williams unsigned int src_cnt, size_t len, unsigned long flags); 2907405f74bSDan Williams struct dma_async_tx_descriptor *(*device_prep_dma_zero_sum)( 2910036731cSDan Williams struct dma_chan *chan, dma_addr_t *src, unsigned int src_cnt, 292d4c56f97SDan Williams size_t len, u32 *result, unsigned long flags); 2937405f74bSDan Williams struct dma_async_tx_descriptor *(*device_prep_dma_memset)( 2940036731cSDan Williams struct dma_chan *chan, dma_addr_t dest, int value, size_t len, 295d4c56f97SDan Williams unsigned long flags); 2967405f74bSDan Williams struct dma_async_tx_descriptor *(*device_prep_dma_interrupt)( 2977405f74bSDan Williams struct dma_chan *chan); 2987405f74bSDan Williams 2997405f74bSDan Williams void (*device_dependency_added)(struct dma_chan *chan); 3007405f74bSDan Williams enum dma_status (*device_is_tx_complete)(struct dma_chan *chan, 301c13c8260SChris Leech dma_cookie_t cookie, dma_cookie_t *last, 302c13c8260SChris Leech dma_cookie_t *used); 3037405f74bSDan Williams void (*device_issue_pending)(struct dma_chan *chan); 304c13c8260SChris Leech }; 305c13c8260SChris Leech 306c13c8260SChris Leech /* --- public DMA engine API --- */ 307c13c8260SChris Leech 308d379b01eSDan Williams void dma_async_client_register(struct dma_client *client); 309c13c8260SChris Leech void dma_async_client_unregister(struct dma_client *client); 310d379b01eSDan Williams void dma_async_client_chan_request(struct dma_client *client); 3117405f74bSDan Williams dma_cookie_t dma_async_memcpy_buf_to_buf(struct dma_chan *chan, 3127405f74bSDan Williams void *dest, void *src, size_t len); 3137405f74bSDan Williams dma_cookie_t dma_async_memcpy_buf_to_pg(struct dma_chan *chan, 3147405f74bSDan Williams struct page *page, unsigned int offset, void *kdata, size_t len); 3157405f74bSDan Williams dma_cookie_t dma_async_memcpy_pg_to_pg(struct dma_chan *chan, 316c13c8260SChris Leech struct page *dest_pg, unsigned int dest_off, struct page *src_pg, 3177405f74bSDan Williams unsigned int src_off, size_t len); 3187405f74bSDan Williams void dma_async_tx_descriptor_init(struct dma_async_tx_descriptor *tx, 3197405f74bSDan Williams struct dma_chan *chan); 320c13c8260SChris Leech 3217405f74bSDan Williams static inline void 3227405f74bSDan Williams async_tx_ack(struct dma_async_tx_descriptor *tx) 3237405f74bSDan Williams { 3247405f74bSDan Williams tx->ack = 1; 325c13c8260SChris Leech } 326c13c8260SChris Leech 3277405f74bSDan Williams #define first_dma_cap(mask) __first_dma_cap(&(mask)) 3287405f74bSDan Williams static inline int __first_dma_cap(const dma_cap_mask_t *srcp) 3297405f74bSDan Williams { 3307405f74bSDan Williams return min_t(int, DMA_TX_TYPE_END, 3317405f74bSDan Williams find_first_bit(srcp->bits, DMA_TX_TYPE_END)); 3327405f74bSDan Williams } 3337405f74bSDan Williams 3347405f74bSDan Williams #define next_dma_cap(n, mask) __next_dma_cap((n), &(mask)) 3357405f74bSDan Williams static inline int __next_dma_cap(int n, const dma_cap_mask_t *srcp) 3367405f74bSDan Williams { 3377405f74bSDan Williams return min_t(int, DMA_TX_TYPE_END, 3387405f74bSDan Williams find_next_bit(srcp->bits, DMA_TX_TYPE_END, n+1)); 3397405f74bSDan Williams } 3407405f74bSDan Williams 3417405f74bSDan Williams #define dma_cap_set(tx, mask) __dma_cap_set((tx), &(mask)) 3427405f74bSDan Williams static inline void 3437405f74bSDan Williams __dma_cap_set(enum dma_transaction_type tx_type, dma_cap_mask_t *dstp) 3447405f74bSDan Williams { 3457405f74bSDan Williams set_bit(tx_type, dstp->bits); 3467405f74bSDan Williams } 3477405f74bSDan Williams 3487405f74bSDan Williams #define dma_has_cap(tx, mask) __dma_has_cap((tx), &(mask)) 3497405f74bSDan Williams static inline int 3507405f74bSDan Williams __dma_has_cap(enum dma_transaction_type tx_type, dma_cap_mask_t *srcp) 3517405f74bSDan Williams { 3527405f74bSDan Williams return test_bit(tx_type, srcp->bits); 3537405f74bSDan Williams } 3547405f74bSDan Williams 3557405f74bSDan Williams #define for_each_dma_cap_mask(cap, mask) \ 3567405f74bSDan Williams for ((cap) = first_dma_cap(mask); \ 3577405f74bSDan Williams (cap) < DMA_TX_TYPE_END; \ 3587405f74bSDan Williams (cap) = next_dma_cap((cap), (mask))) 3597405f74bSDan Williams 360c13c8260SChris Leech /** 3617405f74bSDan Williams * dma_async_issue_pending - flush pending transactions to HW 362fe4ada2dSRandy Dunlap * @chan: target DMA channel 363c13c8260SChris Leech * 364c13c8260SChris Leech * This allows drivers to push copies to HW in batches, 365c13c8260SChris Leech * reducing MMIO writes where possible. 366c13c8260SChris Leech */ 3677405f74bSDan Williams static inline void dma_async_issue_pending(struct dma_chan *chan) 368c13c8260SChris Leech { 369ec8670f1SDan Williams chan->device->device_issue_pending(chan); 370c13c8260SChris Leech } 371c13c8260SChris Leech 3727405f74bSDan Williams #define dma_async_memcpy_issue_pending(chan) dma_async_issue_pending(chan) 3737405f74bSDan Williams 374c13c8260SChris Leech /** 3757405f74bSDan Williams * dma_async_is_tx_complete - poll for transaction completion 376c13c8260SChris Leech * @chan: DMA channel 377c13c8260SChris Leech * @cookie: transaction identifier to check status of 378c13c8260SChris Leech * @last: returns last completed cookie, can be NULL 379c13c8260SChris Leech * @used: returns last issued cookie, can be NULL 380c13c8260SChris Leech * 381c13c8260SChris Leech * If @last and @used are passed in, upon return they reflect the driver 382c13c8260SChris Leech * internal state and can be used with dma_async_is_complete() to check 383c13c8260SChris Leech * the status of multiple cookies without re-checking hardware state. 384c13c8260SChris Leech */ 3857405f74bSDan Williams static inline enum dma_status dma_async_is_tx_complete(struct dma_chan *chan, 386c13c8260SChris Leech dma_cookie_t cookie, dma_cookie_t *last, dma_cookie_t *used) 387c13c8260SChris Leech { 3887405f74bSDan Williams return chan->device->device_is_tx_complete(chan, cookie, last, used); 389c13c8260SChris Leech } 390c13c8260SChris Leech 3917405f74bSDan Williams #define dma_async_memcpy_complete(chan, cookie, last, used)\ 3927405f74bSDan Williams dma_async_is_tx_complete(chan, cookie, last, used) 3937405f74bSDan Williams 394c13c8260SChris Leech /** 395c13c8260SChris Leech * dma_async_is_complete - test a cookie against chan state 396c13c8260SChris Leech * @cookie: transaction identifier to test status of 397c13c8260SChris Leech * @last_complete: last know completed transaction 398c13c8260SChris Leech * @last_used: last cookie value handed out 399c13c8260SChris Leech * 400c13c8260SChris Leech * dma_async_is_complete() is used in dma_async_memcpy_complete() 401c13c8260SChris Leech * the test logic is seperated for lightweight testing of multiple cookies 402c13c8260SChris Leech */ 403c13c8260SChris Leech static inline enum dma_status dma_async_is_complete(dma_cookie_t cookie, 404c13c8260SChris Leech dma_cookie_t last_complete, dma_cookie_t last_used) 405c13c8260SChris Leech { 406c13c8260SChris Leech if (last_complete <= last_used) { 407c13c8260SChris Leech if ((cookie <= last_complete) || (cookie > last_used)) 408c13c8260SChris Leech return DMA_SUCCESS; 409c13c8260SChris Leech } else { 410c13c8260SChris Leech if ((cookie <= last_complete) && (cookie > last_used)) 411c13c8260SChris Leech return DMA_SUCCESS; 412c13c8260SChris Leech } 413c13c8260SChris Leech return DMA_IN_PROGRESS; 414c13c8260SChris Leech } 415c13c8260SChris Leech 4167405f74bSDan Williams enum dma_status dma_sync_wait(struct dma_chan *chan, dma_cookie_t cookie); 417c13c8260SChris Leech 418c13c8260SChris Leech /* --- DMA device --- */ 419c13c8260SChris Leech 420c13c8260SChris Leech int dma_async_device_register(struct dma_device *device); 421c13c8260SChris Leech void dma_async_device_unregister(struct dma_device *device); 422c13c8260SChris Leech 423de5506e1SChris Leech /* --- Helper iov-locking functions --- */ 424de5506e1SChris Leech 425de5506e1SChris Leech struct dma_page_list { 426*b2ddb901SAl Viro char __user *base_address; 427de5506e1SChris Leech int nr_pages; 428de5506e1SChris Leech struct page **pages; 429de5506e1SChris Leech }; 430de5506e1SChris Leech 431de5506e1SChris Leech struct dma_pinned_list { 432de5506e1SChris Leech int nr_iovecs; 433de5506e1SChris Leech struct dma_page_list page_list[0]; 434de5506e1SChris Leech }; 435de5506e1SChris Leech 436de5506e1SChris Leech struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len); 437de5506e1SChris Leech void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list); 438de5506e1SChris Leech 439de5506e1SChris Leech dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov, 440de5506e1SChris Leech struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len); 441de5506e1SChris Leech dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov, 442de5506e1SChris Leech struct dma_pinned_list *pinned_list, struct page *page, 443de5506e1SChris Leech unsigned int offset, size_t len); 444de5506e1SChris Leech 445c13c8260SChris Leech #endif /* DMAENGINE_H */ 446