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 /** 32d379b01eSDan Williams * enum dma_state - resource PNP/power managment 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 /** 987405f74bSDan Williams * dma_cap_mask_t - capabilities bitmap modeled after cpumask_t. 997405f74bSDan Williams * See linux/cpumask.h 1007405f74bSDan Williams */ 1017405f74bSDan Williams typedef struct { DECLARE_BITMAP(bits, DMA_TX_TYPE_END); } dma_cap_mask_t; 1027405f74bSDan Williams 1037405f74bSDan Williams /** 104c13c8260SChris Leech * struct dma_chan_percpu - the per-CPU part of struct dma_chan 105c13c8260SChris Leech * @refcount: local_t used for open-coded "bigref" counting 106c13c8260SChris Leech * @memcpy_count: transaction counter 107c13c8260SChris Leech * @bytes_transferred: byte counter 108c13c8260SChris Leech */ 109c13c8260SChris Leech 110c13c8260SChris Leech struct dma_chan_percpu { 111c13c8260SChris Leech local_t refcount; 112c13c8260SChris Leech /* stats */ 113c13c8260SChris Leech unsigned long memcpy_count; 114c13c8260SChris Leech unsigned long bytes_transferred; 115c13c8260SChris Leech }; 116c13c8260SChris Leech 117c13c8260SChris Leech /** 118c13c8260SChris Leech * struct dma_chan - devices supply DMA channels, clients use them 119fe4ada2dSRandy Dunlap * @device: ptr to the dma device who supplies this channel, always !%NULL 120c13c8260SChris Leech * @cookie: last cookie value returned to client 121fe4ada2dSRandy Dunlap * @chan_id: channel ID for sysfs 122fe4ada2dSRandy Dunlap * @class_dev: class device for sysfs 123c13c8260SChris Leech * @refcount: kref, used in "bigref" slow-mode 124fe4ada2dSRandy Dunlap * @slow_ref: indicates that the DMA channel is free 125fe4ada2dSRandy Dunlap * @rcu: the DMA channel's RCU head 126c13c8260SChris Leech * @device_node: used to add this to the device chan list 127c13c8260SChris Leech * @local: per-cpu pointer to a struct dma_chan_percpu 128c13c8260SChris Leech */ 129c13c8260SChris Leech struct dma_chan { 130c13c8260SChris Leech struct dma_device *device; 131c13c8260SChris Leech dma_cookie_t cookie; 132c13c8260SChris Leech 133c13c8260SChris Leech /* sysfs */ 134c13c8260SChris Leech int chan_id; 135*891f78eaSTony Jones struct device dev; 136c13c8260SChris Leech 137c13c8260SChris Leech struct kref refcount; 138c13c8260SChris Leech int slow_ref; 139c13c8260SChris Leech struct rcu_head rcu; 140c13c8260SChris Leech 141c13c8260SChris Leech struct list_head device_node; 142c13c8260SChris Leech struct dma_chan_percpu *local; 143c13c8260SChris Leech }; 144c13c8260SChris Leech 145*891f78eaSTony Jones #define to_dma_chan(p) container_of(p, struct dma_chan, dev) 146d379b01eSDan Williams 147c13c8260SChris Leech void dma_chan_cleanup(struct kref *kref); 148c13c8260SChris Leech 149c13c8260SChris Leech static inline void dma_chan_get(struct dma_chan *chan) 150c13c8260SChris Leech { 151c13c8260SChris Leech if (unlikely(chan->slow_ref)) 152c13c8260SChris Leech kref_get(&chan->refcount); 153c13c8260SChris Leech else { 154c13c8260SChris Leech local_inc(&(per_cpu_ptr(chan->local, get_cpu())->refcount)); 155c13c8260SChris Leech put_cpu(); 156c13c8260SChris Leech } 157c13c8260SChris Leech } 158c13c8260SChris Leech 159c13c8260SChris Leech static inline void dma_chan_put(struct dma_chan *chan) 160c13c8260SChris Leech { 161c13c8260SChris Leech if (unlikely(chan->slow_ref)) 162c13c8260SChris Leech kref_put(&chan->refcount, dma_chan_cleanup); 163c13c8260SChris Leech else { 164c13c8260SChris Leech local_dec(&(per_cpu_ptr(chan->local, get_cpu())->refcount)); 165c13c8260SChris Leech put_cpu(); 166c13c8260SChris Leech } 167c13c8260SChris Leech } 168c13c8260SChris Leech 169c13c8260SChris Leech /* 170c13c8260SChris Leech * typedef dma_event_callback - function pointer to a DMA event callback 171d379b01eSDan Williams * For each channel added to the system this routine is called for each client. 172d379b01eSDan Williams * If the client would like to use the channel it returns '1' to signal (ack) 173d379b01eSDan Williams * the dmaengine core to take out a reference on the channel and its 174d379b01eSDan Williams * corresponding device. A client must not 'ack' an available channel more 175d379b01eSDan Williams * than once. When a channel is removed all clients are notified. If a client 176d379b01eSDan Williams * is using the channel it must 'ack' the removal. A client must not 'ack' a 177d379b01eSDan Williams * removed channel more than once. 178d379b01eSDan Williams * @client - 'this' pointer for the client context 179d379b01eSDan Williams * @chan - channel to be acted upon 180d379b01eSDan Williams * @state - available or removed 181c13c8260SChris Leech */ 182d379b01eSDan Williams struct dma_client; 183d379b01eSDan Williams typedef enum dma_state_client (*dma_event_callback) (struct dma_client *client, 184d379b01eSDan Williams struct dma_chan *chan, enum dma_state state); 185c13c8260SChris Leech 186c13c8260SChris Leech /** 187c13c8260SChris Leech * struct dma_client - info on the entity making use of DMA services 188c13c8260SChris Leech * @event_callback: func ptr to call when something happens 189d379b01eSDan Williams * @cap_mask: only return channels that satisfy the requested capabilities 190d379b01eSDan Williams * a value of zero corresponds to any capability 191c13c8260SChris Leech * @global_node: list_head for global dma_client_list 192c13c8260SChris Leech */ 193c13c8260SChris Leech struct dma_client { 194c13c8260SChris Leech dma_event_callback event_callback; 195d379b01eSDan Williams dma_cap_mask_t cap_mask; 196c13c8260SChris Leech struct list_head global_node; 197c13c8260SChris Leech }; 198c13c8260SChris Leech 1997405f74bSDan Williams typedef void (*dma_async_tx_callback)(void *dma_async_param); 2007405f74bSDan Williams /** 2017405f74bSDan Williams * struct dma_async_tx_descriptor - async transaction descriptor 2027405f74bSDan Williams * ---dma generic offload fields--- 2037405f74bSDan Williams * @cookie: tracking cookie for this transaction, set to -EBUSY if 2047405f74bSDan Williams * this tx is sitting on a dependency list 2057405f74bSDan Williams * @ack: the descriptor can not be reused until the client acknowledges 2067405f74bSDan Williams * receipt, i.e. has has a chance to establish any dependency chains 2077405f74bSDan Williams * @phys: physical address of the descriptor 2087405f74bSDan Williams * @tx_list: driver common field for operations that require multiple 2097405f74bSDan Williams * descriptors 2107405f74bSDan Williams * @chan: target channel for this operation 2117405f74bSDan Williams * @tx_submit: set the prepared descriptor(s) to be executed by the engine 2127405f74bSDan Williams * @tx_set_dest: set a destination address in a hardware descriptor 2137405f74bSDan Williams * @tx_set_src: set a source address in a hardware descriptor 2147405f74bSDan Williams * @callback: routine to call after this operation is complete 2157405f74bSDan Williams * @callback_param: general parameter to pass to the callback routine 2167405f74bSDan Williams * ---async_tx api specific fields--- 2177405f74bSDan Williams * @depend_list: at completion this list of transactions are submitted 2187405f74bSDan Williams * @depend_node: allow this transaction to be executed after another 2197405f74bSDan Williams * transaction has completed, possibly on another channel 2207405f74bSDan Williams * @parent: pointer to the next level up in the dependency chain 2217405f74bSDan Williams * @lock: protect the dependency list 2227405f74bSDan Williams */ 2237405f74bSDan Williams struct dma_async_tx_descriptor { 2247405f74bSDan Williams dma_cookie_t cookie; 2257405f74bSDan Williams int ack; 2267405f74bSDan Williams dma_addr_t phys; 2277405f74bSDan Williams struct list_head tx_list; 2287405f74bSDan Williams struct dma_chan *chan; 2297405f74bSDan Williams dma_cookie_t (*tx_submit)(struct dma_async_tx_descriptor *tx); 2307405f74bSDan Williams void (*tx_set_dest)(dma_addr_t addr, 2317405f74bSDan Williams struct dma_async_tx_descriptor *tx, int index); 2327405f74bSDan Williams void (*tx_set_src)(dma_addr_t addr, 2337405f74bSDan Williams struct dma_async_tx_descriptor *tx, int index); 2347405f74bSDan Williams dma_async_tx_callback callback; 2357405f74bSDan Williams void *callback_param; 2367405f74bSDan Williams struct list_head depend_list; 2377405f74bSDan Williams struct list_head depend_node; 2387405f74bSDan Williams struct dma_async_tx_descriptor *parent; 2397405f74bSDan Williams spinlock_t lock; 2407405f74bSDan Williams }; 2417405f74bSDan Williams 242c13c8260SChris Leech /** 243c13c8260SChris Leech * struct dma_device - info on the entity supplying DMA services 244c13c8260SChris Leech * @chancnt: how many DMA channels are supported 245c13c8260SChris Leech * @channels: the list of struct dma_chan 246c13c8260SChris Leech * @global_node: list_head for global dma_device_list 2477405f74bSDan Williams * @cap_mask: one or more dma_capability flags 2487405f74bSDan Williams * @max_xor: maximum number of xor sources, 0 if no capability 249fe4ada2dSRandy Dunlap * @refcount: reference count 250fe4ada2dSRandy Dunlap * @done: IO completion struct 251fe4ada2dSRandy Dunlap * @dev_id: unique device ID 2527405f74bSDan Williams * @dev: struct device reference for dma mapping api 253fe4ada2dSRandy Dunlap * @device_alloc_chan_resources: allocate resources and return the 254fe4ada2dSRandy Dunlap * number of allocated descriptors 255fe4ada2dSRandy Dunlap * @device_free_chan_resources: release DMA channel's resources 2567405f74bSDan Williams * @device_prep_dma_memcpy: prepares a memcpy operation 2577405f74bSDan Williams * @device_prep_dma_xor: prepares a xor operation 2587405f74bSDan Williams * @device_prep_dma_zero_sum: prepares a zero_sum operation 2597405f74bSDan Williams * @device_prep_dma_memset: prepares a memset operation 2607405f74bSDan Williams * @device_prep_dma_interrupt: prepares an end of chain interrupt operation 2617405f74bSDan Williams * @device_dependency_added: async_tx notifies the channel about new deps 2627405f74bSDan Williams * @device_issue_pending: push pending transactions to hardware 263c13c8260SChris Leech */ 264c13c8260SChris Leech struct dma_device { 265c13c8260SChris Leech 266c13c8260SChris Leech unsigned int chancnt; 267c13c8260SChris Leech struct list_head channels; 268c13c8260SChris Leech struct list_head global_node; 2697405f74bSDan Williams dma_cap_mask_t cap_mask; 2707405f74bSDan Williams int max_xor; 271c13c8260SChris Leech 272c13c8260SChris Leech struct kref refcount; 273c13c8260SChris Leech struct completion done; 274c13c8260SChris Leech 275c13c8260SChris Leech int dev_id; 2767405f74bSDan Williams struct device *dev; 277c13c8260SChris Leech 278c13c8260SChris Leech int (*device_alloc_chan_resources)(struct dma_chan *chan); 279c13c8260SChris Leech void (*device_free_chan_resources)(struct dma_chan *chan); 2807405f74bSDan Williams 2817405f74bSDan Williams struct dma_async_tx_descriptor *(*device_prep_dma_memcpy)( 2827405f74bSDan Williams struct dma_chan *chan, size_t len, int int_en); 2837405f74bSDan Williams struct dma_async_tx_descriptor *(*device_prep_dma_xor)( 2847405f74bSDan Williams struct dma_chan *chan, unsigned int src_cnt, size_t len, 2857405f74bSDan Williams int int_en); 2867405f74bSDan Williams struct dma_async_tx_descriptor *(*device_prep_dma_zero_sum)( 2877405f74bSDan Williams struct dma_chan *chan, unsigned int src_cnt, size_t len, 2887405f74bSDan Williams u32 *result, int int_en); 2897405f74bSDan Williams struct dma_async_tx_descriptor *(*device_prep_dma_memset)( 2907405f74bSDan Williams struct dma_chan *chan, int value, size_t len, int int_en); 2917405f74bSDan Williams struct dma_async_tx_descriptor *(*device_prep_dma_interrupt)( 2927405f74bSDan Williams struct dma_chan *chan); 2937405f74bSDan Williams 2947405f74bSDan Williams void (*device_dependency_added)(struct dma_chan *chan); 2957405f74bSDan Williams enum dma_status (*device_is_tx_complete)(struct dma_chan *chan, 296c13c8260SChris Leech dma_cookie_t cookie, dma_cookie_t *last, 297c13c8260SChris Leech dma_cookie_t *used); 2987405f74bSDan Williams void (*device_issue_pending)(struct dma_chan *chan); 299c13c8260SChris Leech }; 300c13c8260SChris Leech 301c13c8260SChris Leech /* --- public DMA engine API --- */ 302c13c8260SChris Leech 303d379b01eSDan Williams void dma_async_client_register(struct dma_client *client); 304c13c8260SChris Leech void dma_async_client_unregister(struct dma_client *client); 305d379b01eSDan Williams void dma_async_client_chan_request(struct dma_client *client); 3067405f74bSDan Williams dma_cookie_t dma_async_memcpy_buf_to_buf(struct dma_chan *chan, 3077405f74bSDan Williams void *dest, void *src, size_t len); 3087405f74bSDan Williams dma_cookie_t dma_async_memcpy_buf_to_pg(struct dma_chan *chan, 3097405f74bSDan Williams struct page *page, unsigned int offset, void *kdata, size_t len); 3107405f74bSDan Williams dma_cookie_t dma_async_memcpy_pg_to_pg(struct dma_chan *chan, 311c13c8260SChris Leech struct page *dest_pg, unsigned int dest_off, struct page *src_pg, 3127405f74bSDan Williams unsigned int src_off, size_t len); 3137405f74bSDan Williams void dma_async_tx_descriptor_init(struct dma_async_tx_descriptor *tx, 3147405f74bSDan Williams struct dma_chan *chan); 315c13c8260SChris Leech 3167405f74bSDan Williams static inline void 3177405f74bSDan Williams async_tx_ack(struct dma_async_tx_descriptor *tx) 3187405f74bSDan Williams { 3197405f74bSDan Williams tx->ack = 1; 320c13c8260SChris Leech } 321c13c8260SChris Leech 3227405f74bSDan Williams #define first_dma_cap(mask) __first_dma_cap(&(mask)) 3237405f74bSDan Williams static inline int __first_dma_cap(const dma_cap_mask_t *srcp) 3247405f74bSDan Williams { 3257405f74bSDan Williams return min_t(int, DMA_TX_TYPE_END, 3267405f74bSDan Williams find_first_bit(srcp->bits, DMA_TX_TYPE_END)); 3277405f74bSDan Williams } 3287405f74bSDan Williams 3297405f74bSDan Williams #define next_dma_cap(n, mask) __next_dma_cap((n), &(mask)) 3307405f74bSDan Williams static inline int __next_dma_cap(int n, const dma_cap_mask_t *srcp) 3317405f74bSDan Williams { 3327405f74bSDan Williams return min_t(int, DMA_TX_TYPE_END, 3337405f74bSDan Williams find_next_bit(srcp->bits, DMA_TX_TYPE_END, n+1)); 3347405f74bSDan Williams } 3357405f74bSDan Williams 3367405f74bSDan Williams #define dma_cap_set(tx, mask) __dma_cap_set((tx), &(mask)) 3377405f74bSDan Williams static inline void 3387405f74bSDan Williams __dma_cap_set(enum dma_transaction_type tx_type, dma_cap_mask_t *dstp) 3397405f74bSDan Williams { 3407405f74bSDan Williams set_bit(tx_type, dstp->bits); 3417405f74bSDan Williams } 3427405f74bSDan Williams 3437405f74bSDan Williams #define dma_has_cap(tx, mask) __dma_has_cap((tx), &(mask)) 3447405f74bSDan Williams static inline int 3457405f74bSDan Williams __dma_has_cap(enum dma_transaction_type tx_type, dma_cap_mask_t *srcp) 3467405f74bSDan Williams { 3477405f74bSDan Williams return test_bit(tx_type, srcp->bits); 3487405f74bSDan Williams } 3497405f74bSDan Williams 3507405f74bSDan Williams #define for_each_dma_cap_mask(cap, mask) \ 3517405f74bSDan Williams for ((cap) = first_dma_cap(mask); \ 3527405f74bSDan Williams (cap) < DMA_TX_TYPE_END; \ 3537405f74bSDan Williams (cap) = next_dma_cap((cap), (mask))) 3547405f74bSDan Williams 355c13c8260SChris Leech /** 3567405f74bSDan Williams * dma_async_issue_pending - flush pending transactions to HW 357fe4ada2dSRandy Dunlap * @chan: target DMA channel 358c13c8260SChris Leech * 359c13c8260SChris Leech * This allows drivers to push copies to HW in batches, 360c13c8260SChris Leech * reducing MMIO writes where possible. 361c13c8260SChris Leech */ 3627405f74bSDan Williams static inline void dma_async_issue_pending(struct dma_chan *chan) 363c13c8260SChris Leech { 3647405f74bSDan Williams return chan->device->device_issue_pending(chan); 365c13c8260SChris Leech } 366c13c8260SChris Leech 3677405f74bSDan Williams #define dma_async_memcpy_issue_pending(chan) dma_async_issue_pending(chan) 3687405f74bSDan Williams 369c13c8260SChris Leech /** 3707405f74bSDan Williams * dma_async_is_tx_complete - poll for transaction completion 371c13c8260SChris Leech * @chan: DMA channel 372c13c8260SChris Leech * @cookie: transaction identifier to check status of 373c13c8260SChris Leech * @last: returns last completed cookie, can be NULL 374c13c8260SChris Leech * @used: returns last issued cookie, can be NULL 375c13c8260SChris Leech * 376c13c8260SChris Leech * If @last and @used are passed in, upon return they reflect the driver 377c13c8260SChris Leech * internal state and can be used with dma_async_is_complete() to check 378c13c8260SChris Leech * the status of multiple cookies without re-checking hardware state. 379c13c8260SChris Leech */ 3807405f74bSDan Williams static inline enum dma_status dma_async_is_tx_complete(struct dma_chan *chan, 381c13c8260SChris Leech dma_cookie_t cookie, dma_cookie_t *last, dma_cookie_t *used) 382c13c8260SChris Leech { 3837405f74bSDan Williams return chan->device->device_is_tx_complete(chan, cookie, last, used); 384c13c8260SChris Leech } 385c13c8260SChris Leech 3867405f74bSDan Williams #define dma_async_memcpy_complete(chan, cookie, last, used)\ 3877405f74bSDan Williams dma_async_is_tx_complete(chan, cookie, last, used) 3887405f74bSDan Williams 389c13c8260SChris Leech /** 390c13c8260SChris Leech * dma_async_is_complete - test a cookie against chan state 391c13c8260SChris Leech * @cookie: transaction identifier to test status of 392c13c8260SChris Leech * @last_complete: last know completed transaction 393c13c8260SChris Leech * @last_used: last cookie value handed out 394c13c8260SChris Leech * 395c13c8260SChris Leech * dma_async_is_complete() is used in dma_async_memcpy_complete() 396c13c8260SChris Leech * the test logic is seperated for lightweight testing of multiple cookies 397c13c8260SChris Leech */ 398c13c8260SChris Leech static inline enum dma_status dma_async_is_complete(dma_cookie_t cookie, 399c13c8260SChris Leech dma_cookie_t last_complete, dma_cookie_t last_used) 400c13c8260SChris Leech { 401c13c8260SChris Leech if (last_complete <= last_used) { 402c13c8260SChris Leech if ((cookie <= last_complete) || (cookie > last_used)) 403c13c8260SChris Leech return DMA_SUCCESS; 404c13c8260SChris Leech } else { 405c13c8260SChris Leech if ((cookie <= last_complete) && (cookie > last_used)) 406c13c8260SChris Leech return DMA_SUCCESS; 407c13c8260SChris Leech } 408c13c8260SChris Leech return DMA_IN_PROGRESS; 409c13c8260SChris Leech } 410c13c8260SChris Leech 4117405f74bSDan Williams enum dma_status dma_sync_wait(struct dma_chan *chan, dma_cookie_t cookie); 412c13c8260SChris Leech 413c13c8260SChris Leech /* --- DMA device --- */ 414c13c8260SChris Leech 415c13c8260SChris Leech int dma_async_device_register(struct dma_device *device); 416c13c8260SChris Leech void dma_async_device_unregister(struct dma_device *device); 417c13c8260SChris Leech 418de5506e1SChris Leech /* --- Helper iov-locking functions --- */ 419de5506e1SChris Leech 420de5506e1SChris Leech struct dma_page_list { 421de5506e1SChris Leech char *base_address; 422de5506e1SChris Leech int nr_pages; 423de5506e1SChris Leech struct page **pages; 424de5506e1SChris Leech }; 425de5506e1SChris Leech 426de5506e1SChris Leech struct dma_pinned_list { 427de5506e1SChris Leech int nr_iovecs; 428de5506e1SChris Leech struct dma_page_list page_list[0]; 429de5506e1SChris Leech }; 430de5506e1SChris Leech 431de5506e1SChris Leech struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len); 432de5506e1SChris Leech void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list); 433de5506e1SChris Leech 434de5506e1SChris Leech dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov, 435de5506e1SChris Leech struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len); 436de5506e1SChris Leech dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov, 437de5506e1SChris Leech struct dma_pinned_list *pinned_list, struct page *page, 438de5506e1SChris Leech unsigned int offset, size_t len); 439de5506e1SChris Leech 440c13c8260SChris Leech #endif /* DMAENGINE_H */ 441