Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright(c) 2004 - 2006 Intel Corporation. All rights reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms of the GNU General Public License as published by the Free |
| 6 | * Software Foundation; either version 2 of the License, or (at your option) |
| 7 | * any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 12 | * more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License along with |
| 15 | * this program; if not, write to the Free Software Foundation, Inc., 59 |
| 16 | * Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 17 | * |
| 18 | * The full GNU General Public License is included in this distribution in the |
| 19 | * file called COPYING. |
| 20 | */ |
| 21 | #ifndef LINUX_DMAENGINE_H |
| 22 | #define LINUX_DMAENGINE_H |
| 23 | |
| 24 | #include <linux/device.h> |
| 25 | #include <linux/uio.h> |
| 26 | #include <linux/bug.h> |
| 27 | #include <linux/scatterlist.h> |
| 28 | #include <linux/bitmap.h> |
| 29 | #include <linux/types.h> |
| 30 | #include <asm/page.h> |
| 31 | |
| 32 | typedef s32 dma_cookie_t; |
| 33 | #define DMA_MIN_COOKIE 1 |
| 34 | #define DMA_MAX_COOKIE INT_MAX |
| 35 | |
| 36 | #define dma_submit_error(cookie) ((cookie) < 0 ? 1 : 0) |
| 37 | |
| 38 | enum dma_status { |
| 39 | DMA_SUCCESS, |
| 40 | DMA_IN_PROGRESS, |
| 41 | DMA_PAUSED, |
| 42 | DMA_ERROR, |
| 43 | }; |
| 44 | |
| 45 | enum dma_transaction_type { |
| 46 | DMA_MEMCPY, |
| 47 | DMA_XOR, |
| 48 | DMA_PQ, |
| 49 | DMA_XOR_VAL, |
| 50 | DMA_PQ_VAL, |
| 51 | DMA_MEMSET, |
| 52 | DMA_INTERRUPT, |
| 53 | DMA_SG, |
| 54 | DMA_PRIVATE, |
| 55 | DMA_ASYNC_TX, |
| 56 | DMA_SLAVE, |
| 57 | DMA_CYCLIC, |
| 58 | DMA_INTERLEAVE, |
| 59 | DMA_TX_TYPE_END, |
| 60 | }; |
| 61 | |
| 62 | enum dma_transfer_direction { |
| 63 | DMA_MEM_TO_MEM, |
| 64 | DMA_MEM_TO_DEV, |
| 65 | DMA_DEV_TO_MEM, |
| 66 | DMA_DEV_TO_DEV, |
| 67 | DMA_TRANS_NONE, |
| 68 | }; |
| 69 | |
| 70 | |
| 71 | struct data_chunk { |
| 72 | size_t size; |
| 73 | size_t icg; |
| 74 | }; |
| 75 | |
| 76 | struct dma_interleaved_template { |
| 77 | dma_addr_t src_start; |
| 78 | dma_addr_t dst_start; |
| 79 | enum dma_transfer_direction dir; |
| 80 | bool src_inc; |
| 81 | bool dst_inc; |
| 82 | bool src_sgl; |
| 83 | bool dst_sgl; |
| 84 | size_t numf; |
| 85 | size_t frame_size; |
| 86 | struct data_chunk sgl[0]; |
| 87 | }; |
| 88 | |
| 89 | enum dma_ctrl_flags { |
| 90 | DMA_PREP_INTERRUPT = (1 << 0), |
| 91 | DMA_CTRL_ACK = (1 << 1), |
| 92 | DMA_COMPL_SKIP_SRC_UNMAP = (1 << 2), |
| 93 | DMA_COMPL_SKIP_DEST_UNMAP = (1 << 3), |
| 94 | DMA_COMPL_SRC_UNMAP_SINGLE = (1 << 4), |
| 95 | DMA_COMPL_DEST_UNMAP_SINGLE = (1 << 5), |
| 96 | DMA_PREP_PQ_DISABLE_P = (1 << 6), |
| 97 | DMA_PREP_PQ_DISABLE_Q = (1 << 7), |
| 98 | DMA_PREP_CONTINUE = (1 << 8), |
| 99 | DMA_PREP_FENCE = (1 << 9), |
| 100 | }; |
| 101 | |
| 102 | enum dma_ctrl_cmd { |
| 103 | DMA_TERMINATE_ALL, |
| 104 | DMA_PAUSE, |
| 105 | DMA_RESUME, |
| 106 | DMA_SLAVE_CONFIG, |
| 107 | FSLDMA_EXTERNAL_START, |
| 108 | }; |
| 109 | |
| 110 | enum sum_check_bits { |
| 111 | SUM_CHECK_P = 0, |
| 112 | SUM_CHECK_Q = 1, |
| 113 | }; |
| 114 | |
| 115 | enum sum_check_flags { |
| 116 | SUM_CHECK_P_RESULT = (1 << SUM_CHECK_P), |
| 117 | SUM_CHECK_Q_RESULT = (1 << SUM_CHECK_Q), |
| 118 | }; |
| 119 | |
| 120 | |
| 121 | typedef struct { DECLARE_BITMAP(bits, DMA_TX_TYPE_END); } dma_cap_mask_t; |
| 122 | |
| 123 | |
| 124 | struct dma_chan_percpu { |
| 125 | |
| 126 | unsigned long memcpy_count; |
| 127 | unsigned long bytes_transferred; |
| 128 | }; |
| 129 | |
| 130 | struct dma_chan { |
| 131 | struct dma_device *device; |
| 132 | dma_cookie_t cookie; |
| 133 | dma_cookie_t completed_cookie; |
| 134 | |
| 135 | |
| 136 | int chan_id; |
| 137 | struct dma_chan_dev *dev; |
| 138 | |
| 139 | struct list_head device_node; |
| 140 | struct dma_chan_percpu __percpu *local; |
| 141 | int client_count; |
| 142 | int table_count; |
| 143 | void *private; |
| 144 | }; |
| 145 | |
| 146 | struct dma_chan_dev { |
| 147 | struct dma_chan *chan; |
| 148 | struct device device; |
| 149 | int dev_id; |
| 150 | atomic_t *idr_ref; |
| 151 | }; |
| 152 | |
| 153 | enum dma_slave_buswidth { |
| 154 | DMA_SLAVE_BUSWIDTH_UNDEFINED = 0, |
| 155 | DMA_SLAVE_BUSWIDTH_1_BYTE = 1, |
| 156 | DMA_SLAVE_BUSWIDTH_2_BYTES = 2, |
| 157 | DMA_SLAVE_BUSWIDTH_4_BYTES = 4, |
| 158 | DMA_SLAVE_BUSWIDTH_8_BYTES = 8, |
| 159 | }; |
| 160 | |
| 161 | /** |
| 162 | * struct dma_slave_config - dma slave channel runtime config |
| 163 | * @direction: whether the data shall go in or out on this slave |
| 164 | * channel, right now. DMA_TO_DEVICE and DMA_FROM_DEVICE are |
| 165 | * legal values, DMA_BIDIRECTIONAL is not acceptable since we |
| 166 | * need to differentiate source and target addresses. |
| 167 | * @src_addr: this is the physical address where DMA slave data |
| 168 | * should be read (RX), if the source is memory this argument is |
| 169 | * ignored. |
| 170 | * @dst_addr: this is the physical address where DMA slave data |
| 171 | * should be written (TX), if the source is memory this argument |
| 172 | * is ignored. |
| 173 | * @src_addr_width: this is the width in bytes of the source (RX) |
| 174 | * register where DMA data shall be read. If the source |
| 175 | * is memory this may be ignored depending on architecture. |
| 176 | * Legal values: 1, 2, 4, 8. |
| 177 | * @dst_addr_width: same as src_addr_width but for destination |
| 178 | * target (TX) mutatis mutandis. |
| 179 | * @src_maxburst: the maximum number of words (note: words, as in |
| 180 | * units of the src_addr_width member, not bytes) that can be sent |
| 181 | * in one burst to the device. Typically something like half the |
| 182 | * FIFO depth on I/O peripherals so you don't overflow it. This |
| 183 | * may or may not be applicable on memory sources. |
| 184 | * @dst_maxburst: same as src_maxburst but for destination target |
| 185 | * mutatis mutandis. |
| 186 | * @device_fc: Flow Controller Settings. Only valid for slave channels. Fill |
| 187 | * with 'true' if peripheral should be flow controller. Direction will be |
| 188 | * selected at Runtime. |
| 189 | * |
| 190 | * This struct is passed in as configuration data to a DMA engine |
| 191 | * in order to set up a certain channel for DMA transport at runtime. |
| 192 | * The DMA device/engine has to provide support for an additional |
| 193 | * command in the channel config interface, DMA_SLAVE_CONFIG |
| 194 | * and this struct will then be passed in as an argument to the |
| 195 | * DMA engine device_control() function. |
| 196 | * |
| 197 | * The rationale for adding configuration information to this struct |
| 198 | * is as follows: if it is likely that most DMA slave controllers in |
| 199 | * the world will support the configuration option, then make it |
| 200 | * generic. If not: if it is fixed so that it be sent in static from |
| 201 | * the platform data, then prefer to do that. Else, if it is neither |
| 202 | * fixed at runtime, nor generic enough (such as bus mastership on |
| 203 | * some CPU family and whatnot) then create a custom slave config |
| 204 | * struct and pass that, then make this config a member of that |
| 205 | * struct, if applicable. |
| 206 | */ |
| 207 | struct dma_slave_config { |
| 208 | enum dma_transfer_direction direction; |
| 209 | dma_addr_t src_addr; |
| 210 | dma_addr_t dst_addr; |
| 211 | enum dma_slave_buswidth src_addr_width; |
| 212 | enum dma_slave_buswidth dst_addr_width; |
| 213 | u32 src_maxburst; |
| 214 | u32 dst_maxburst; |
| 215 | bool device_fc; |
| 216 | }; |
| 217 | |
| 218 | static inline const char *dma_chan_name(struct dma_chan *chan) |
| 219 | { |
| 220 | return dev_name(&chan->dev->device); |
| 221 | } |
| 222 | |
| 223 | void dma_chan_cleanup(struct kref *kref); |
| 224 | |
| 225 | typedef bool (*dma_filter_fn)(struct dma_chan *chan, void *filter_param); |
| 226 | |
| 227 | typedef void (*dma_async_tx_callback)(void *dma_async_param); |
| 228 | struct dma_async_tx_descriptor { |
| 229 | dma_cookie_t cookie; |
| 230 | enum dma_ctrl_flags flags; |
| 231 | dma_addr_t phys; |
| 232 | struct dma_chan *chan; |
| 233 | dma_cookie_t (*tx_submit)(struct dma_async_tx_descriptor *tx); |
| 234 | dma_async_tx_callback callback; |
| 235 | void *callback_param; |
| 236 | #ifdef CONFIG_ASYNC_TX_ENABLE_CHANNEL_SWITCH |
| 237 | struct dma_async_tx_descriptor *next; |
| 238 | struct dma_async_tx_descriptor *parent; |
| 239 | spinlock_t lock; |
| 240 | #endif |
| 241 | }; |
| 242 | |
| 243 | #ifndef CONFIG_ASYNC_TX_ENABLE_CHANNEL_SWITCH |
| 244 | static inline void txd_lock(struct dma_async_tx_descriptor *txd) |
| 245 | { |
| 246 | } |
| 247 | static inline void txd_unlock(struct dma_async_tx_descriptor *txd) |
| 248 | { |
| 249 | } |
| 250 | static inline void txd_chain(struct dma_async_tx_descriptor *txd, struct dma_async_tx_descriptor *next) |
| 251 | { |
| 252 | BUG(); |
| 253 | } |
| 254 | static inline void txd_clear_parent(struct dma_async_tx_descriptor *txd) |
| 255 | { |
| 256 | } |
| 257 | static inline void txd_clear_next(struct dma_async_tx_descriptor *txd) |
| 258 | { |
| 259 | } |
| 260 | static inline struct dma_async_tx_descriptor *txd_next(struct dma_async_tx_descriptor *txd) |
| 261 | { |
| 262 | return NULL; |
| 263 | } |
| 264 | static inline struct dma_async_tx_descriptor *txd_parent(struct dma_async_tx_descriptor *txd) |
| 265 | { |
| 266 | return NULL; |
| 267 | } |
| 268 | |
| 269 | #else |
| 270 | static inline void txd_lock(struct dma_async_tx_descriptor *txd) |
| 271 | { |
| 272 | spin_lock_bh(&txd->lock); |
| 273 | } |
| 274 | static inline void txd_unlock(struct dma_async_tx_descriptor *txd) |
| 275 | { |
| 276 | spin_unlock_bh(&txd->lock); |
| 277 | } |
| 278 | static inline void txd_chain(struct dma_async_tx_descriptor *txd, struct dma_async_tx_descriptor *next) |
| 279 | { |
| 280 | txd->next = next; |
| 281 | next->parent = txd; |
| 282 | } |
| 283 | static inline void txd_clear_parent(struct dma_async_tx_descriptor *txd) |
| 284 | { |
| 285 | txd->parent = NULL; |
| 286 | } |
| 287 | static inline void txd_clear_next(struct dma_async_tx_descriptor *txd) |
| 288 | { |
| 289 | txd->next = NULL; |
| 290 | } |
| 291 | static inline struct dma_async_tx_descriptor *txd_parent(struct dma_async_tx_descriptor *txd) |
| 292 | { |
| 293 | return txd->parent; |
| 294 | } |
| 295 | static inline struct dma_async_tx_descriptor *txd_next(struct dma_async_tx_descriptor *txd) |
| 296 | { |
| 297 | return txd->next; |
| 298 | } |
| 299 | #endif |
| 300 | |
| 301 | struct dma_tx_state { |
| 302 | dma_cookie_t last; |
| 303 | dma_cookie_t used; |
| 304 | u32 residue; |
| 305 | }; |
| 306 | |
| 307 | struct dma_device { |
| 308 | |
| 309 | unsigned int chancnt; |
| 310 | unsigned int privatecnt; |
| 311 | struct list_head channels; |
| 312 | struct list_head global_node; |
| 313 | dma_cap_mask_t cap_mask; |
| 314 | unsigned short max_xor; |
| 315 | unsigned short max_pq; |
| 316 | u8 copy_align; |
| 317 | u8 xor_align; |
| 318 | u8 pq_align; |
| 319 | u8 fill_align; |
| 320 | #define DMA_HAS_PQ_CONTINUE (1 << 15) |
| 321 | |
| 322 | int dev_id; |
| 323 | struct device *dev; |
| 324 | |
| 325 | int (*device_alloc_chan_resources)(struct dma_chan *chan); |
| 326 | void (*device_free_chan_resources)(struct dma_chan *chan); |
| 327 | |
| 328 | struct dma_async_tx_descriptor *(*device_prep_dma_memcpy)( |
| 329 | struct dma_chan *chan, dma_addr_t dest, dma_addr_t src, |
| 330 | size_t len, unsigned long flags); |
| 331 | struct dma_async_tx_descriptor *(*device_prep_dma_xor)( |
| 332 | struct dma_chan *chan, dma_addr_t dest, dma_addr_t *src, |
| 333 | unsigned int src_cnt, size_t len, unsigned long flags); |
| 334 | struct dma_async_tx_descriptor *(*device_prep_dma_xor_val)( |
| 335 | struct dma_chan *chan, dma_addr_t *src, unsigned int src_cnt, |
| 336 | size_t len, enum sum_check_flags *result, unsigned long flags); |
| 337 | struct dma_async_tx_descriptor *(*device_prep_dma_pq)( |
| 338 | struct dma_chan *chan, dma_addr_t *dst, dma_addr_t *src, |
| 339 | unsigned int src_cnt, const unsigned char *scf, |
| 340 | size_t len, unsigned long flags); |
| 341 | struct dma_async_tx_descriptor *(*device_prep_dma_pq_val)( |
| 342 | struct dma_chan *chan, dma_addr_t *pq, dma_addr_t *src, |
| 343 | unsigned int src_cnt, const unsigned char *scf, size_t len, |
| 344 | enum sum_check_flags *pqres, unsigned long flags); |
| 345 | struct dma_async_tx_descriptor *(*device_prep_dma_memset)( |
| 346 | struct dma_chan *chan, dma_addr_t dest, int value, size_t len, |
| 347 | unsigned long flags); |
| 348 | struct dma_async_tx_descriptor *(*device_prep_dma_interrupt)( |
| 349 | struct dma_chan *chan, unsigned long flags); |
| 350 | struct dma_async_tx_descriptor *(*device_prep_dma_sg)( |
| 351 | struct dma_chan *chan, |
| 352 | struct scatterlist *dst_sg, unsigned int dst_nents, |
| 353 | struct scatterlist *src_sg, unsigned int src_nents, |
| 354 | unsigned long flags); |
| 355 | |
| 356 | struct dma_async_tx_descriptor *(*device_prep_slave_sg)( |
| 357 | struct dma_chan *chan, struct scatterlist *sgl, |
| 358 | unsigned int sg_len, enum dma_transfer_direction direction, |
| 359 | unsigned long flags, void *context); |
| 360 | struct dma_async_tx_descriptor *(*device_prep_dma_cyclic)( |
| 361 | struct dma_chan *chan, dma_addr_t buf_addr, size_t buf_len, |
| 362 | size_t period_len, enum dma_transfer_direction direction, |
| 363 | void *context); |
| 364 | struct dma_async_tx_descriptor *(*device_prep_interleaved_dma)( |
| 365 | struct dma_chan *chan, struct dma_interleaved_template *xt, |
| 366 | unsigned long flags); |
| 367 | int (*device_control)(struct dma_chan *chan, enum dma_ctrl_cmd cmd, |
| 368 | unsigned long arg); |
| 369 | |
| 370 | enum dma_status (*device_tx_status)(struct dma_chan *chan, |
| 371 | dma_cookie_t cookie, |
| 372 | struct dma_tx_state *txstate); |
| 373 | void (*device_issue_pending)(struct dma_chan *chan); |
| 374 | }; |
| 375 | |
| 376 | static inline int dmaengine_device_control(struct dma_chan *chan, |
| 377 | enum dma_ctrl_cmd cmd, |
| 378 | unsigned long arg) |
| 379 | { |
| 380 | return chan->device->device_control(chan, cmd, arg); |
| 381 | } |
| 382 | |
| 383 | static inline int dmaengine_slave_config(struct dma_chan *chan, |
| 384 | struct dma_slave_config *config) |
| 385 | { |
| 386 | return dmaengine_device_control(chan, DMA_SLAVE_CONFIG, |
| 387 | (unsigned long)config); |
| 388 | } |
| 389 | |
| 390 | static inline struct dma_async_tx_descriptor *dmaengine_prep_slave_single( |
| 391 | struct dma_chan *chan, void *buf, size_t len, |
| 392 | enum dma_transfer_direction dir, unsigned long flags) |
| 393 | { |
| 394 | struct scatterlist sg; |
| 395 | sg_init_one(&sg, buf, len); |
| 396 | |
| 397 | return chan->device->device_prep_slave_sg(chan, &sg, 1, |
| 398 | dir, flags, NULL); |
| 399 | } |
| 400 | |
| 401 | static inline struct dma_async_tx_descriptor *dmaengine_prep_slave_sg( |
| 402 | struct dma_chan *chan, struct scatterlist *sgl, unsigned int sg_len, |
| 403 | enum dma_transfer_direction dir, unsigned long flags) |
| 404 | { |
| 405 | return chan->device->device_prep_slave_sg(chan, sgl, sg_len, |
| 406 | dir, flags, NULL); |
| 407 | } |
| 408 | |
| 409 | static inline struct dma_async_tx_descriptor *dmaengine_prep_dma_cyclic( |
| 410 | struct dma_chan *chan, dma_addr_t buf_addr, size_t buf_len, |
| 411 | size_t period_len, enum dma_transfer_direction dir) |
| 412 | { |
| 413 | return chan->device->device_prep_dma_cyclic(chan, buf_addr, buf_len, |
| 414 | period_len, dir, NULL); |
| 415 | } |
| 416 | |
| 417 | static inline int dmaengine_terminate_all(struct dma_chan *chan) |
| 418 | { |
| 419 | return dmaengine_device_control(chan, DMA_TERMINATE_ALL, 0); |
| 420 | } |
| 421 | |
| 422 | static inline int dmaengine_pause(struct dma_chan *chan) |
| 423 | { |
| 424 | return dmaengine_device_control(chan, DMA_PAUSE, 0); |
| 425 | } |
| 426 | |
| 427 | static inline int dmaengine_resume(struct dma_chan *chan) |
| 428 | { |
| 429 | return dmaengine_device_control(chan, DMA_RESUME, 0); |
| 430 | } |
| 431 | |
| 432 | static inline dma_cookie_t dmaengine_submit(struct dma_async_tx_descriptor *desc) |
| 433 | { |
| 434 | return desc->tx_submit(desc); |
| 435 | } |
| 436 | |
| 437 | static inline bool dmaengine_check_align(u8 align, size_t off1, size_t off2, size_t len) |
| 438 | { |
| 439 | size_t mask; |
| 440 | |
| 441 | if (!align) |
| 442 | return true; |
| 443 | mask = (1 << align) - 1; |
| 444 | if (mask & (off1 | off2 | len)) |
| 445 | return false; |
| 446 | return true; |
| 447 | } |
| 448 | |
| 449 | static inline bool is_dma_copy_aligned(struct dma_device *dev, size_t off1, |
| 450 | size_t off2, size_t len) |
| 451 | { |
| 452 | return dmaengine_check_align(dev->copy_align, off1, off2, len); |
| 453 | } |
| 454 | |
| 455 | static inline bool is_dma_xor_aligned(struct dma_device *dev, size_t off1, |
| 456 | size_t off2, size_t len) |
| 457 | { |
| 458 | return dmaengine_check_align(dev->xor_align, off1, off2, len); |
| 459 | } |
| 460 | |
| 461 | static inline bool is_dma_pq_aligned(struct dma_device *dev, size_t off1, |
| 462 | size_t off2, size_t len) |
| 463 | { |
| 464 | return dmaengine_check_align(dev->pq_align, off1, off2, len); |
| 465 | } |
| 466 | |
| 467 | static inline bool is_dma_fill_aligned(struct dma_device *dev, size_t off1, |
| 468 | size_t off2, size_t len) |
| 469 | { |
| 470 | return dmaengine_check_align(dev->fill_align, off1, off2, len); |
| 471 | } |
| 472 | |
| 473 | static inline void |
| 474 | dma_set_maxpq(struct dma_device *dma, int maxpq, int has_pq_continue) |
| 475 | { |
| 476 | dma->max_pq = maxpq; |
| 477 | if (has_pq_continue) |
| 478 | dma->max_pq |= DMA_HAS_PQ_CONTINUE; |
| 479 | } |
| 480 | |
| 481 | static inline bool dmaf_continue(enum dma_ctrl_flags flags) |
| 482 | { |
| 483 | return (flags & DMA_PREP_CONTINUE) == DMA_PREP_CONTINUE; |
| 484 | } |
| 485 | |
| 486 | static inline bool dmaf_p_disabled_continue(enum dma_ctrl_flags flags) |
| 487 | { |
| 488 | enum dma_ctrl_flags mask = DMA_PREP_CONTINUE | DMA_PREP_PQ_DISABLE_P; |
| 489 | |
| 490 | return (flags & mask) == mask; |
| 491 | } |
| 492 | |
| 493 | static inline bool dma_dev_has_pq_continue(struct dma_device *dma) |
| 494 | { |
| 495 | return (dma->max_pq & DMA_HAS_PQ_CONTINUE) == DMA_HAS_PQ_CONTINUE; |
| 496 | } |
| 497 | |
| 498 | static inline unsigned short dma_dev_to_maxpq(struct dma_device *dma) |
| 499 | { |
| 500 | return dma->max_pq & ~DMA_HAS_PQ_CONTINUE; |
| 501 | } |
| 502 | |
| 503 | static inline int dma_maxpq(struct dma_device *dma, enum dma_ctrl_flags flags) |
| 504 | { |
| 505 | if (dma_dev_has_pq_continue(dma) || !dmaf_continue(flags)) |
| 506 | return dma_dev_to_maxpq(dma); |
| 507 | else if (dmaf_p_disabled_continue(flags)) |
| 508 | return dma_dev_to_maxpq(dma) - 1; |
| 509 | else if (dmaf_continue(flags)) |
| 510 | return dma_dev_to_maxpq(dma) - 3; |
| 511 | BUG(); |
| 512 | } |
| 513 | |
| 514 | |
| 515 | #ifdef CONFIG_DMA_ENGINE |
| 516 | void dmaengine_get(void); |
| 517 | void dmaengine_put(void); |
| 518 | #else |
| 519 | static inline void dmaengine_get(void) |
| 520 | { |
| 521 | } |
| 522 | static inline void dmaengine_put(void) |
| 523 | { |
| 524 | } |
| 525 | #endif |
| 526 | |
| 527 | #ifdef CONFIG_NET_DMA |
| 528 | #define net_dmaengine_get() dmaengine_get() |
| 529 | #define net_dmaengine_put() dmaengine_put() |
| 530 | #else |
| 531 | static inline void net_dmaengine_get(void) |
| 532 | { |
| 533 | } |
| 534 | static inline void net_dmaengine_put(void) |
| 535 | { |
| 536 | } |
| 537 | #endif |
| 538 | |
| 539 | #ifdef CONFIG_ASYNC_TX_DMA |
| 540 | #define async_dmaengine_get() dmaengine_get() |
| 541 | #define async_dmaengine_put() dmaengine_put() |
| 542 | #ifndef CONFIG_ASYNC_TX_ENABLE_CHANNEL_SWITCH |
| 543 | #define async_dma_find_channel(type) dma_find_channel(DMA_ASYNC_TX) |
| 544 | #else |
| 545 | #define async_dma_find_channel(type) dma_find_channel(type) |
| 546 | #endif |
| 547 | #else |
| 548 | static inline void async_dmaengine_get(void) |
| 549 | { |
| 550 | } |
| 551 | static inline void async_dmaengine_put(void) |
| 552 | { |
| 553 | } |
| 554 | static inline struct dma_chan * |
| 555 | async_dma_find_channel(enum dma_transaction_type type) |
| 556 | { |
| 557 | return NULL; |
| 558 | } |
| 559 | #endif |
| 560 | |
| 561 | dma_cookie_t dma_async_memcpy_buf_to_buf(struct dma_chan *chan, |
| 562 | void *dest, void *src, size_t len); |
| 563 | dma_cookie_t dma_async_memcpy_buf_to_pg(struct dma_chan *chan, |
| 564 | struct page *page, unsigned int offset, void *kdata, size_t len); |
| 565 | dma_cookie_t dma_async_memcpy_pg_to_pg(struct dma_chan *chan, |
| 566 | struct page *dest_pg, unsigned int dest_off, struct page *src_pg, |
| 567 | unsigned int src_off, size_t len); |
| 568 | void dma_async_tx_descriptor_init(struct dma_async_tx_descriptor *tx, |
| 569 | struct dma_chan *chan); |
| 570 | |
| 571 | static inline void async_tx_ack(struct dma_async_tx_descriptor *tx) |
| 572 | { |
| 573 | tx->flags |= DMA_CTRL_ACK; |
| 574 | } |
| 575 | |
| 576 | static inline void async_tx_clear_ack(struct dma_async_tx_descriptor *tx) |
| 577 | { |
| 578 | tx->flags &= ~DMA_CTRL_ACK; |
| 579 | } |
| 580 | |
| 581 | static inline bool async_tx_test_ack(struct dma_async_tx_descriptor *tx) |
| 582 | { |
| 583 | return (tx->flags & DMA_CTRL_ACK) == DMA_CTRL_ACK; |
| 584 | } |
| 585 | |
| 586 | #define first_dma_cap(mask) __first_dma_cap(&(mask)) |
| 587 | static inline int __first_dma_cap(const dma_cap_mask_t *srcp) |
| 588 | { |
| 589 | return min_t(int, DMA_TX_TYPE_END, |
| 590 | find_first_bit(srcp->bits, DMA_TX_TYPE_END)); |
| 591 | } |
| 592 | |
| 593 | #define next_dma_cap(n, mask) __next_dma_cap((n), &(mask)) |
| 594 | static inline int __next_dma_cap(int n, const dma_cap_mask_t *srcp) |
| 595 | { |
| 596 | return min_t(int, DMA_TX_TYPE_END, |
| 597 | find_next_bit(srcp->bits, DMA_TX_TYPE_END, n+1)); |
| 598 | } |
| 599 | |
| 600 | #define dma_cap_set(tx, mask) __dma_cap_set((tx), &(mask)) |
| 601 | static inline void |
| 602 | __dma_cap_set(enum dma_transaction_type tx_type, dma_cap_mask_t *dstp) |
| 603 | { |
| 604 | set_bit(tx_type, dstp->bits); |
| 605 | } |
| 606 | |
| 607 | #define dma_cap_clear(tx, mask) __dma_cap_clear((tx), &(mask)) |
| 608 | static inline void |
| 609 | __dma_cap_clear(enum dma_transaction_type tx_type, dma_cap_mask_t *dstp) |
| 610 | { |
| 611 | clear_bit(tx_type, dstp->bits); |
| 612 | } |
| 613 | |
| 614 | #define dma_cap_zero(mask) __dma_cap_zero(&(mask)) |
| 615 | static inline void __dma_cap_zero(dma_cap_mask_t *dstp) |
| 616 | { |
| 617 | bitmap_zero(dstp->bits, DMA_TX_TYPE_END); |
| 618 | } |
| 619 | |
| 620 | #define dma_has_cap(tx, mask) __dma_has_cap((tx), &(mask)) |
| 621 | static inline int |
| 622 | __dma_has_cap(enum dma_transaction_type tx_type, dma_cap_mask_t *srcp) |
| 623 | { |
| 624 | return test_bit(tx_type, srcp->bits); |
| 625 | } |
| 626 | |
| 627 | #define for_each_dma_cap_mask(cap, mask) \ |
| 628 | for ((cap) = first_dma_cap(mask); \ |
| 629 | (cap) < DMA_TX_TYPE_END; \ |
| 630 | (cap) = next_dma_cap((cap), (mask))) |
| 631 | |
| 632 | static inline void dma_async_issue_pending(struct dma_chan *chan) |
| 633 | { |
| 634 | chan->device->device_issue_pending(chan); |
| 635 | } |
| 636 | |
| 637 | #define dma_async_memcpy_issue_pending(chan) dma_async_issue_pending(chan) |
| 638 | |
| 639 | static inline enum dma_status dma_async_is_tx_complete(struct dma_chan *chan, |
| 640 | dma_cookie_t cookie, dma_cookie_t *last, dma_cookie_t *used) |
| 641 | { |
| 642 | struct dma_tx_state state; |
| 643 | enum dma_status status; |
| 644 | |
| 645 | status = chan->device->device_tx_status(chan, cookie, &state); |
| 646 | if (last) |
| 647 | *last = state.last; |
| 648 | if (used) |
| 649 | *used = state.used; |
| 650 | return status; |
| 651 | } |
| 652 | |
| 653 | #define dma_async_memcpy_complete(chan, cookie, last, used)\ |
| 654 | dma_async_is_tx_complete(chan, cookie, last, used) |
| 655 | |
| 656 | static inline enum dma_status dma_async_is_complete(dma_cookie_t cookie, |
| 657 | dma_cookie_t last_complete, dma_cookie_t last_used) |
| 658 | { |
| 659 | if (last_complete <= last_used) { |
| 660 | if ((cookie <= last_complete) || (cookie > last_used)) |
| 661 | return DMA_SUCCESS; |
| 662 | } else { |
| 663 | if ((cookie <= last_complete) && (cookie > last_used)) |
| 664 | return DMA_SUCCESS; |
| 665 | } |
| 666 | return DMA_IN_PROGRESS; |
| 667 | } |
| 668 | |
| 669 | static inline void |
| 670 | dma_set_tx_state(struct dma_tx_state *st, dma_cookie_t last, dma_cookie_t used, u32 residue) |
| 671 | { |
| 672 | if (st) { |
| 673 | st->last = last; |
| 674 | st->used = used; |
| 675 | st->residue = residue; |
| 676 | } |
| 677 | } |
| 678 | |
| 679 | enum dma_status dma_sync_wait(struct dma_chan *chan, dma_cookie_t cookie); |
| 680 | #ifdef CONFIG_DMA_ENGINE |
| 681 | enum dma_status dma_wait_for_async_tx(struct dma_async_tx_descriptor *tx); |
| 682 | void dma_issue_pending_all(void); |
| 683 | struct dma_chan *__dma_request_channel(dma_cap_mask_t *mask, dma_filter_fn fn, void *fn_param); |
| 684 | void dma_release_channel(struct dma_chan *chan); |
| 685 | #else |
| 686 | static inline enum dma_status dma_wait_for_async_tx(struct dma_async_tx_descriptor *tx) |
| 687 | { |
| 688 | return DMA_SUCCESS; |
| 689 | } |
| 690 | static inline void dma_issue_pending_all(void) |
| 691 | { |
| 692 | } |
| 693 | static inline struct dma_chan *__dma_request_channel(dma_cap_mask_t *mask, |
| 694 | dma_filter_fn fn, void *fn_param) |
| 695 | { |
| 696 | return NULL; |
| 697 | } |
| 698 | static inline void dma_release_channel(struct dma_chan *chan) |
| 699 | { |
| 700 | } |
| 701 | #endif |
| 702 | |
| 703 | |
| 704 | int dma_async_device_register(struct dma_device *device); |
| 705 | void dma_async_device_unregister(struct dma_device *device); |
| 706 | void dma_run_dependencies(struct dma_async_tx_descriptor *tx); |
| 707 | struct dma_chan *dma_find_channel(enum dma_transaction_type tx_type); |
| 708 | struct dma_chan *net_dma_find_channel(void); |
| 709 | #define dma_request_channel(mask, x, y) __dma_request_channel(&(mask), x, y) |
| 710 | |
| 711 | |
| 712 | struct dma_page_list { |
| 713 | char __user *base_address; |
| 714 | int nr_pages; |
| 715 | struct page **pages; |
| 716 | }; |
| 717 | |
| 718 | struct dma_pinned_list { |
| 719 | int nr_iovecs; |
| 720 | struct dma_page_list page_list[0]; |
| 721 | }; |
| 722 | |
| 723 | struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len); |
| 724 | void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list); |
| 725 | |
| 726 | dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov, |
| 727 | struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len); |
| 728 | dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov, |
| 729 | struct dma_pinned_list *pinned_list, struct page *page, |
| 730 | unsigned int offset, size_t len); |
| 731 | |
| 732 | #endif |