dmaengine.h 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146
  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. #include <linux/device.h>
  24. #include <linux/err.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 dma_cookie_t - an opaque DMA cookie
  33. *
  34. * if dma_cookie_t is >0 it's a DMA request cookie, <0 it's an error code
  35. */
  36. typedef s32 dma_cookie_t;
  37. #define DMA_MIN_COOKIE 1
  38. static inline int dma_submit_error(dma_cookie_t cookie)
  39. {
  40. return cookie < 0 ? cookie : 0;
  41. }
  42. /**
  43. * enum dma_status - DMA transaction status
  44. * @DMA_COMPLETE: transaction completed
  45. * @DMA_IN_PROGRESS: transaction not yet processed
  46. * @DMA_PAUSED: transaction is paused
  47. * @DMA_ERROR: transaction failed
  48. */
  49. enum dma_status {
  50. DMA_COMPLETE,
  51. DMA_IN_PROGRESS,
  52. DMA_PAUSED,
  53. DMA_ERROR,
  54. };
  55. /**
  56. * enum dma_transaction_type - DMA transaction types/indexes
  57. *
  58. * Note: The DMA_ASYNC_TX capability is not to be set by drivers. It is
  59. * automatically set as dma devices are registered.
  60. */
  61. enum dma_transaction_type {
  62. DMA_MEMCPY,
  63. DMA_XOR,
  64. DMA_PQ,
  65. DMA_XOR_VAL,
  66. DMA_PQ_VAL,
  67. DMA_INTERRUPT,
  68. DMA_SG,
  69. DMA_PRIVATE,
  70. DMA_ASYNC_TX,
  71. DMA_SLAVE,
  72. DMA_CYCLIC,
  73. DMA_INTERLEAVE,
  74. /* last transaction type for creation of the capabilities mask */
  75. DMA_TX_TYPE_END,
  76. };
  77. /**
  78. * enum dma_transfer_direction - dma transfer mode and direction indicator
  79. * @DMA_MEM_TO_MEM: Async/Memcpy mode
  80. * @DMA_MEM_TO_DEV: Slave mode & From Memory to Device
  81. * @DMA_DEV_TO_MEM: Slave mode & From Device to Memory
  82. * @DMA_DEV_TO_DEV: Slave mode & From Device to Device
  83. */
  84. enum dma_transfer_direction {
  85. DMA_MEM_TO_MEM,
  86. DMA_MEM_TO_DEV,
  87. DMA_DEV_TO_MEM,
  88. DMA_DEV_TO_DEV,
  89. DMA_TRANS_NONE,
  90. };
  91. /**
  92. * Interleaved Transfer Request
  93. * ----------------------------
  94. * A chunk is collection of contiguous bytes to be transfered.
  95. * The gap(in bytes) between two chunks is called inter-chunk-gap(ICG).
  96. * ICGs may or maynot change between chunks.
  97. * A FRAME is the smallest series of contiguous {chunk,icg} pairs,
  98. * that when repeated an integral number of times, specifies the transfer.
  99. * A transfer template is specification of a Frame, the number of times
  100. * it is to be repeated and other per-transfer attributes.
  101. *
  102. * Practically, a client driver would have ready a template for each
  103. * type of transfer it is going to need during its lifetime and
  104. * set only 'src_start' and 'dst_start' before submitting the requests.
  105. *
  106. *
  107. * | Frame-1 | Frame-2 | ~ | Frame-'numf' |
  108. * |====....==.===...=...|====....==.===...=...| ~ |====....==.===...=...|
  109. *
  110. * == Chunk size
  111. * ... ICG
  112. */
  113. /**
  114. * struct data_chunk - Element of scatter-gather list that makes a frame.
  115. * @size: Number of bytes to read from source.
  116. * size_dst := fn(op, size_src), so doesn't mean much for destination.
  117. * @icg: Number of bytes to jump after last src/dst address of this
  118. * chunk and before first src/dst address for next chunk.
  119. * Ignored for dst(assumed 0), if dst_inc is true and dst_sgl is false.
  120. * Ignored for src(assumed 0), if src_inc is true and src_sgl is false.
  121. */
  122. struct data_chunk {
  123. size_t size;
  124. size_t icg;
  125. };
  126. /**
  127. * struct dma_interleaved_template - Template to convey DMAC the transfer pattern
  128. * and attributes.
  129. * @src_start: Bus address of source for the first chunk.
  130. * @dst_start: Bus address of destination for the first chunk.
  131. * @dir: Specifies the type of Source and Destination.
  132. * @src_inc: If the source address increments after reading from it.
  133. * @dst_inc: If the destination address increments after writing to it.
  134. * @src_sgl: If the 'icg' of sgl[] applies to Source (scattered read).
  135. * Otherwise, source is read contiguously (icg ignored).
  136. * Ignored if src_inc is false.
  137. * @dst_sgl: If the 'icg' of sgl[] applies to Destination (scattered write).
  138. * Otherwise, destination is filled contiguously (icg ignored).
  139. * Ignored if dst_inc is false.
  140. * @numf: Number of frames in this template.
  141. * @frame_size: Number of chunks in a frame i.e, size of sgl[].
  142. * @sgl: Array of {chunk,icg} pairs that make up a frame.
  143. */
  144. struct dma_interleaved_template {
  145. dma_addr_t src_start;
  146. dma_addr_t dst_start;
  147. enum dma_transfer_direction dir;
  148. bool src_inc;
  149. bool dst_inc;
  150. bool src_sgl;
  151. bool dst_sgl;
  152. size_t numf;
  153. size_t frame_size;
  154. struct data_chunk sgl[0];
  155. };
  156. /**
  157. * enum dma_ctrl_flags - DMA flags to augment operation preparation,
  158. * control completion, and communicate status.
  159. * @DMA_PREP_INTERRUPT - trigger an interrupt (callback) upon completion of
  160. * this transaction
  161. * @DMA_CTRL_ACK - if clear, the descriptor cannot be reused until the client
  162. * acknowledges receipt, i.e. has has a chance to establish any dependency
  163. * chains
  164. * @DMA_PREP_PQ_DISABLE_P - prevent generation of P while generating Q
  165. * @DMA_PREP_PQ_DISABLE_Q - prevent generation of Q while generating P
  166. * @DMA_PREP_CONTINUE - indicate to a driver that it is reusing buffers as
  167. * sources that were the result of a previous operation, in the case of a PQ
  168. * operation it continues the calculation with new sources
  169. * @DMA_PREP_FENCE - tell the driver that subsequent operations depend
  170. * on the result of this operation
  171. */
  172. enum dma_ctrl_flags {
  173. DMA_PREP_INTERRUPT = (1 << 0),
  174. DMA_CTRL_ACK = (1 << 1),
  175. DMA_PREP_PQ_DISABLE_P = (1 << 2),
  176. DMA_PREP_PQ_DISABLE_Q = (1 << 3),
  177. DMA_PREP_CONTINUE = (1 << 4),
  178. DMA_PREP_FENCE = (1 << 5),
  179. };
  180. /**
  181. * enum dma_ctrl_cmd - DMA operations that can optionally be exercised
  182. * on a running channel.
  183. * @DMA_TERMINATE_ALL: terminate all ongoing transfers
  184. * @DMA_PAUSE: pause ongoing transfers
  185. * @DMA_RESUME: resume paused transfer
  186. * @DMA_SLAVE_CONFIG: this command is only implemented by DMA controllers
  187. * that need to runtime reconfigure the slave channels (as opposed to passing
  188. * configuration data in statically from the platform). An additional
  189. * argument of struct dma_slave_config must be passed in with this
  190. * command.
  191. */
  192. enum dma_ctrl_cmd {
  193. DMA_TERMINATE_ALL,
  194. DMA_PAUSE,
  195. DMA_RESUME,
  196. DMA_SLAVE_CONFIG,
  197. };
  198. /**
  199. * enum sum_check_bits - bit position of pq_check_flags
  200. */
  201. enum sum_check_bits {
  202. SUM_CHECK_P = 0,
  203. SUM_CHECK_Q = 1,
  204. };
  205. /**
  206. * enum pq_check_flags - result of async_{xor,pq}_zero_sum operations
  207. * @SUM_CHECK_P_RESULT - 1 if xor zero sum error, 0 otherwise
  208. * @SUM_CHECK_Q_RESULT - 1 if reed-solomon zero sum error, 0 otherwise
  209. */
  210. enum sum_check_flags {
  211. SUM_CHECK_P_RESULT = (1 << SUM_CHECK_P),
  212. SUM_CHECK_Q_RESULT = (1 << SUM_CHECK_Q),
  213. };
  214. /**
  215. * dma_cap_mask_t - capabilities bitmap modeled after cpumask_t.
  216. * See linux/cpumask.h
  217. */
  218. typedef struct { DECLARE_BITMAP(bits, DMA_TX_TYPE_END); } dma_cap_mask_t;
  219. /**
  220. * struct dma_chan_percpu - the per-CPU part of struct dma_chan
  221. * @memcpy_count: transaction counter
  222. * @bytes_transferred: byte counter
  223. */
  224. struct dma_chan_percpu {
  225. /* stats */
  226. unsigned long memcpy_count;
  227. unsigned long bytes_transferred;
  228. };
  229. /**
  230. * struct dma_chan - devices supply DMA channels, clients use them
  231. * @device: ptr to the dma device who supplies this channel, always !%NULL
  232. * @cookie: last cookie value returned to client
  233. * @completed_cookie: last completed cookie for this channel
  234. * @chan_id: channel ID for sysfs
  235. * @dev: class device for sysfs
  236. * @device_node: used to add this to the device chan list
  237. * @local: per-cpu pointer to a struct dma_chan_percpu
  238. * @client_count: how many clients are using this channel
  239. * @table_count: number of appearances in the mem-to-mem allocation table
  240. * @private: private data for certain client-channel associations
  241. */
  242. struct dma_chan {
  243. struct dma_device *device;
  244. dma_cookie_t cookie;
  245. dma_cookie_t completed_cookie;
  246. /* sysfs */
  247. int chan_id;
  248. struct dma_chan_dev *dev;
  249. struct list_head device_node;
  250. struct dma_chan_percpu __percpu *local;
  251. int client_count;
  252. int table_count;
  253. void *private;
  254. };
  255. /**
  256. * struct dma_chan_dev - relate sysfs device node to backing channel device
  257. * @chan: driver channel device
  258. * @device: sysfs device
  259. * @dev_id: parent dma_device dev_id
  260. * @idr_ref: reference count to gate release of dma_device dev_id
  261. */
  262. struct dma_chan_dev {
  263. struct dma_chan *chan;
  264. struct device device;
  265. int dev_id;
  266. atomic_t *idr_ref;
  267. };
  268. /**
  269. * enum dma_slave_buswidth - defines bus width of the DMA slave
  270. * device, source or target buses
  271. */
  272. enum dma_slave_buswidth {
  273. DMA_SLAVE_BUSWIDTH_UNDEFINED = 0,
  274. DMA_SLAVE_BUSWIDTH_1_BYTE = 1,
  275. DMA_SLAVE_BUSWIDTH_2_BYTES = 2,
  276. DMA_SLAVE_BUSWIDTH_3_BYTES = 3,
  277. DMA_SLAVE_BUSWIDTH_4_BYTES = 4,
  278. DMA_SLAVE_BUSWIDTH_8_BYTES = 8,
  279. };
  280. /**
  281. * struct dma_slave_config - dma slave channel runtime config
  282. * @direction: whether the data shall go in or out on this slave
  283. * channel, right now. DMA_MEM_TO_DEV and DMA_DEV_TO_MEM are
  284. * legal values. DEPRECATED, drivers should use the direction argument
  285. * to the device_prep_slave_sg and device_prep_dma_cyclic functions or
  286. * the dir field in the dma_interleaved_template structure.
  287. * @src_addr: this is the physical address where DMA slave data
  288. * should be read (RX), if the source is memory this argument is
  289. * ignored.
  290. * @dst_addr: this is the physical address where DMA slave data
  291. * should be written (TX), if the source is memory this argument
  292. * is ignored.
  293. * @src_addr_width: this is the width in bytes of the source (RX)
  294. * register where DMA data shall be read. If the source
  295. * is memory this may be ignored depending on architecture.
  296. * Legal values: 1, 2, 4, 8.
  297. * @dst_addr_width: same as src_addr_width but for destination
  298. * target (TX) mutatis mutandis.
  299. * @src_maxburst: the maximum number of words (note: words, as in
  300. * units of the src_addr_width member, not bytes) that can be sent
  301. * in one burst to the device. Typically something like half the
  302. * FIFO depth on I/O peripherals so you don't overflow it. This
  303. * may or may not be applicable on memory sources.
  304. * @dst_maxburst: same as src_maxburst but for destination target
  305. * mutatis mutandis.
  306. * @device_fc: Flow Controller Settings. Only valid for slave channels. Fill
  307. * with 'true' if peripheral should be flow controller. Direction will be
  308. * selected at Runtime.
  309. * @slave_id: Slave requester id. Only valid for slave channels. The dma
  310. * slave peripheral will have unique id as dma requester which need to be
  311. * pass as slave config.
  312. *
  313. * This struct is passed in as configuration data to a DMA engine
  314. * in order to set up a certain channel for DMA transport at runtime.
  315. * The DMA device/engine has to provide support for an additional
  316. * command in the channel config interface, DMA_SLAVE_CONFIG
  317. * and this struct will then be passed in as an argument to the
  318. * DMA engine device_control() function.
  319. *
  320. * The rationale for adding configuration information to this struct is as
  321. * follows: if it is likely that more than one DMA slave controllers in
  322. * the world will support the configuration option, then make it generic.
  323. * If not: if it is fixed so that it be sent in static from the platform
  324. * data, then prefer to do that.
  325. */
  326. struct dma_slave_config {
  327. enum dma_transfer_direction direction;
  328. dma_addr_t src_addr;
  329. dma_addr_t dst_addr;
  330. enum dma_slave_buswidth src_addr_width;
  331. enum dma_slave_buswidth dst_addr_width;
  332. u32 src_maxburst;
  333. u32 dst_maxburst;
  334. bool device_fc;
  335. unsigned int slave_id;
  336. };
  337. /**
  338. * enum dma_residue_granularity - Granularity of the reported transfer residue
  339. * @DMA_RESIDUE_GRANULARITY_DESCRIPTOR: Residue reporting is not support. The
  340. * DMA channel is only able to tell whether a descriptor has been completed or
  341. * not, which means residue reporting is not supported by this channel. The
  342. * residue field of the dma_tx_state field will always be 0.
  343. * @DMA_RESIDUE_GRANULARITY_SEGMENT: Residue is updated after each successfully
  344. * completed segment of the transfer (For cyclic transfers this is after each
  345. * period). This is typically implemented by having the hardware generate an
  346. * interrupt after each transferred segment and then the drivers updates the
  347. * outstanding residue by the size of the segment. Another possibility is if
  348. * the hardware supports scatter-gather and the segment descriptor has a field
  349. * which gets set after the segment has been completed. The driver then counts
  350. * the number of segments without the flag set to compute the residue.
  351. * @DMA_RESIDUE_GRANULARITY_BURST: Residue is updated after each transferred
  352. * burst. This is typically only supported if the hardware has a progress
  353. * register of some sort (E.g. a register with the current read/write address
  354. * or a register with the amount of bursts/beats/bytes that have been
  355. * transferred or still need to be transferred).
  356. */
  357. enum dma_residue_granularity {
  358. DMA_RESIDUE_GRANULARITY_DESCRIPTOR = 0,
  359. DMA_RESIDUE_GRANULARITY_SEGMENT = 1,
  360. DMA_RESIDUE_GRANULARITY_BURST = 2,
  361. };
  362. /* struct dma_slave_caps - expose capabilities of a slave channel only
  363. *
  364. * @src_addr_widths: bit mask of src addr widths the channel supports
  365. * @dstn_addr_widths: bit mask of dstn addr widths the channel supports
  366. * @directions: bit mask of slave direction the channel supported
  367. * since the enum dma_transfer_direction is not defined as bits for each
  368. * type of direction, the dma controller should fill (1 << <TYPE>) and same
  369. * should be checked by controller as well
  370. * @cmd_pause: true, if pause and thereby resume is supported
  371. * @cmd_terminate: true, if terminate cmd is supported
  372. * @residue_granularity: granularity of the reported transfer residue
  373. */
  374. struct dma_slave_caps {
  375. u32 src_addr_widths;
  376. u32 dstn_addr_widths;
  377. u32 directions;
  378. bool cmd_pause;
  379. bool cmd_terminate;
  380. enum dma_residue_granularity residue_granularity;
  381. };
  382. static inline const char *dma_chan_name(struct dma_chan *chan)
  383. {
  384. return dev_name(&chan->dev->device);
  385. }
  386. void dma_chan_cleanup(struct kref *kref);
  387. /**
  388. * typedef dma_filter_fn - callback filter for dma_request_channel
  389. * @chan: channel to be reviewed
  390. * @filter_param: opaque parameter passed through dma_request_channel
  391. *
  392. * When this optional parameter is specified in a call to dma_request_channel a
  393. * suitable channel is passed to this routine for further dispositioning before
  394. * being returned. Where 'suitable' indicates a non-busy channel that
  395. * satisfies the given capability mask. It returns 'true' to indicate that the
  396. * channel is suitable.
  397. */
  398. typedef bool (*dma_filter_fn)(struct dma_chan *chan, void *filter_param);
  399. typedef void (*dma_async_tx_callback)(void *dma_async_param);
  400. struct dmaengine_unmap_data {
  401. u8 map_cnt;
  402. u8 to_cnt;
  403. u8 from_cnt;
  404. u8 bidi_cnt;
  405. struct device *dev;
  406. struct kref kref;
  407. size_t len;
  408. dma_addr_t addr[0];
  409. };
  410. /**
  411. * struct dma_async_tx_descriptor - async transaction descriptor
  412. * ---dma generic offload fields---
  413. * @cookie: tracking cookie for this transaction, set to -EBUSY if
  414. * this tx is sitting on a dependency list
  415. * @flags: flags to augment operation preparation, control completion, and
  416. * communicate status
  417. * @phys: physical address of the descriptor
  418. * @chan: target channel for this operation
  419. * @tx_submit: accept the descriptor, assign ordered cookie and mark the
  420. * descriptor pending. To be pushed on .issue_pending() call
  421. * @callback: routine to call after this operation is complete
  422. * @callback_param: general parameter to pass to the callback routine
  423. * ---async_tx api specific fields---
  424. * @next: at completion submit this descriptor
  425. * @parent: pointer to the next level up in the dependency chain
  426. * @lock: protect the parent and next pointers
  427. */
  428. struct dma_async_tx_descriptor {
  429. dma_cookie_t cookie;
  430. enum dma_ctrl_flags flags; /* not a 'long' to pack with cookie */
  431. dma_addr_t phys;
  432. struct dma_chan *chan;
  433. dma_cookie_t (*tx_submit)(struct dma_async_tx_descriptor *tx);
  434. dma_async_tx_callback callback;
  435. void *callback_param;
  436. struct dmaengine_unmap_data *unmap;
  437. #ifdef CONFIG_ASYNC_TX_ENABLE_CHANNEL_SWITCH
  438. struct dma_async_tx_descriptor *next;
  439. struct dma_async_tx_descriptor *parent;
  440. spinlock_t lock;
  441. #endif
  442. };
  443. #ifdef CONFIG_DMA_ENGINE
  444. static inline void dma_set_unmap(struct dma_async_tx_descriptor *tx,
  445. struct dmaengine_unmap_data *unmap)
  446. {
  447. kref_get(&unmap->kref);
  448. tx->unmap = unmap;
  449. }
  450. struct dmaengine_unmap_data *
  451. dmaengine_get_unmap_data(struct device *dev, int nr, gfp_t flags);
  452. void dmaengine_unmap_put(struct dmaengine_unmap_data *unmap);
  453. #else
  454. static inline void dma_set_unmap(struct dma_async_tx_descriptor *tx,
  455. struct dmaengine_unmap_data *unmap)
  456. {
  457. }
  458. static inline struct dmaengine_unmap_data *
  459. dmaengine_get_unmap_data(struct device *dev, int nr, gfp_t flags)
  460. {
  461. return NULL;
  462. }
  463. static inline void dmaengine_unmap_put(struct dmaengine_unmap_data *unmap)
  464. {
  465. }
  466. #endif
  467. static inline void dma_descriptor_unmap(struct dma_async_tx_descriptor *tx)
  468. {
  469. if (tx->unmap) {
  470. dmaengine_unmap_put(tx->unmap);
  471. tx->unmap = NULL;
  472. }
  473. }
  474. #ifndef CONFIG_ASYNC_TX_ENABLE_CHANNEL_SWITCH
  475. static inline void txd_lock(struct dma_async_tx_descriptor *txd)
  476. {
  477. }
  478. static inline void txd_unlock(struct dma_async_tx_descriptor *txd)
  479. {
  480. }
  481. static inline void txd_chain(struct dma_async_tx_descriptor *txd, struct dma_async_tx_descriptor *next)
  482. {
  483. BUG();
  484. }
  485. static inline void txd_clear_parent(struct dma_async_tx_descriptor *txd)
  486. {
  487. }
  488. static inline void txd_clear_next(struct dma_async_tx_descriptor *txd)
  489. {
  490. }
  491. static inline struct dma_async_tx_descriptor *txd_next(struct dma_async_tx_descriptor *txd)
  492. {
  493. return NULL;
  494. }
  495. static inline struct dma_async_tx_descriptor *txd_parent(struct dma_async_tx_descriptor *txd)
  496. {
  497. return NULL;
  498. }
  499. #else
  500. static inline void txd_lock(struct dma_async_tx_descriptor *txd)
  501. {
  502. spin_lock_bh(&txd->lock);
  503. }
  504. static inline void txd_unlock(struct dma_async_tx_descriptor *txd)
  505. {
  506. spin_unlock_bh(&txd->lock);
  507. }
  508. static inline void txd_chain(struct dma_async_tx_descriptor *txd, struct dma_async_tx_descriptor *next)
  509. {
  510. txd->next = next;
  511. next->parent = txd;
  512. }
  513. static inline void txd_clear_parent(struct dma_async_tx_descriptor *txd)
  514. {
  515. txd->parent = NULL;
  516. }
  517. static inline void txd_clear_next(struct dma_async_tx_descriptor *txd)
  518. {
  519. txd->next = NULL;
  520. }
  521. static inline struct dma_async_tx_descriptor *txd_parent(struct dma_async_tx_descriptor *txd)
  522. {
  523. return txd->parent;
  524. }
  525. static inline struct dma_async_tx_descriptor *txd_next(struct dma_async_tx_descriptor *txd)
  526. {
  527. return txd->next;
  528. }
  529. #endif
  530. /**
  531. * struct dma_tx_state - filled in to report the status of
  532. * a transfer.
  533. * @last: last completed DMA cookie
  534. * @used: last issued DMA cookie (i.e. the one in progress)
  535. * @residue: the remaining number of bytes left to transmit
  536. * on the selected transfer for states DMA_IN_PROGRESS and
  537. * DMA_PAUSED if this is implemented in the driver, else 0
  538. */
  539. struct dma_tx_state {
  540. dma_cookie_t last;
  541. dma_cookie_t used;
  542. u32 residue;
  543. };
  544. /**
  545. * struct dma_device - info on the entity supplying DMA services
  546. * @chancnt: how many DMA channels are supported
  547. * @privatecnt: how many DMA channels are requested by dma_request_channel
  548. * @channels: the list of struct dma_chan
  549. * @global_node: list_head for global dma_device_list
  550. * @cap_mask: one or more dma_capability flags
  551. * @max_xor: maximum number of xor sources, 0 if no capability
  552. * @max_pq: maximum number of PQ sources and PQ-continue capability
  553. * @copy_align: alignment shift for memcpy operations
  554. * @xor_align: alignment shift for xor operations
  555. * @pq_align: alignment shift for pq operations
  556. * @fill_align: alignment shift for memset operations
  557. * @dev_id: unique device ID
  558. * @dev: struct device reference for dma mapping api
  559. * @device_alloc_chan_resources: allocate resources and return the
  560. * number of allocated descriptors
  561. * @device_free_chan_resources: release DMA channel's resources
  562. * @device_prep_dma_memcpy: prepares a memcpy operation
  563. * @device_prep_dma_xor: prepares a xor operation
  564. * @device_prep_dma_xor_val: prepares a xor validation operation
  565. * @device_prep_dma_pq: prepares a pq operation
  566. * @device_prep_dma_pq_val: prepares a pqzero_sum operation
  567. * @device_prep_dma_interrupt: prepares an end of chain interrupt operation
  568. * @device_prep_slave_sg: prepares a slave dma operation
  569. * @device_prep_dma_cyclic: prepare a cyclic dma operation suitable for audio.
  570. * The function takes a buffer of size buf_len. The callback function will
  571. * be called after period_len bytes have been transferred.
  572. * @device_prep_interleaved_dma: Transfer expression in a generic way.
  573. * @device_control: manipulate all pending operations on a channel, returns
  574. * zero or error code
  575. * @device_tx_status: poll for transaction completion, the optional
  576. * txstate parameter can be supplied with a pointer to get a
  577. * struct with auxiliary transfer status information, otherwise the call
  578. * will just return a simple status code
  579. * @device_issue_pending: push pending transactions to hardware
  580. * @device_slave_caps: return the slave channel capabilities
  581. */
  582. struct dma_device {
  583. unsigned int chancnt;
  584. unsigned int privatecnt;
  585. struct list_head channels;
  586. struct list_head global_node;
  587. dma_cap_mask_t cap_mask;
  588. unsigned short max_xor;
  589. unsigned short max_pq;
  590. u8 copy_align;
  591. u8 xor_align;
  592. u8 pq_align;
  593. u8 fill_align;
  594. #define DMA_HAS_PQ_CONTINUE (1 << 15)
  595. int dev_id;
  596. struct device *dev;
  597. int (*device_alloc_chan_resources)(struct dma_chan *chan);
  598. void (*device_free_chan_resources)(struct dma_chan *chan);
  599. struct dma_async_tx_descriptor *(*device_prep_dma_memcpy)(
  600. struct dma_chan *chan, dma_addr_t dest, dma_addr_t src,
  601. size_t len, unsigned long flags);
  602. struct dma_async_tx_descriptor *(*device_prep_dma_xor)(
  603. struct dma_chan *chan, dma_addr_t dest, dma_addr_t *src,
  604. unsigned int src_cnt, size_t len, unsigned long flags);
  605. struct dma_async_tx_descriptor *(*device_prep_dma_xor_val)(
  606. struct dma_chan *chan, dma_addr_t *src, unsigned int src_cnt,
  607. size_t len, enum sum_check_flags *result, unsigned long flags);
  608. struct dma_async_tx_descriptor *(*device_prep_dma_pq)(
  609. struct dma_chan *chan, dma_addr_t *dst, dma_addr_t *src,
  610. unsigned int src_cnt, const unsigned char *scf,
  611. size_t len, unsigned long flags);
  612. struct dma_async_tx_descriptor *(*device_prep_dma_pq_val)(
  613. struct dma_chan *chan, dma_addr_t *pq, dma_addr_t *src,
  614. unsigned int src_cnt, const unsigned char *scf, size_t len,
  615. enum sum_check_flags *pqres, unsigned long flags);
  616. struct dma_async_tx_descriptor *(*device_prep_dma_interrupt)(
  617. struct dma_chan *chan, unsigned long flags);
  618. struct dma_async_tx_descriptor *(*device_prep_dma_sg)(
  619. struct dma_chan *chan,
  620. struct scatterlist *dst_sg, unsigned int dst_nents,
  621. struct scatterlist *src_sg, unsigned int src_nents,
  622. unsigned long flags);
  623. struct dma_async_tx_descriptor *(*device_prep_slave_sg)(
  624. struct dma_chan *chan, struct scatterlist *sgl,
  625. unsigned int sg_len, enum dma_transfer_direction direction,
  626. unsigned long flags, void *context);
  627. struct dma_async_tx_descriptor *(*device_prep_dma_cyclic)(
  628. struct dma_chan *chan, dma_addr_t buf_addr, size_t buf_len,
  629. size_t period_len, enum dma_transfer_direction direction,
  630. unsigned long flags);
  631. struct dma_async_tx_descriptor *(*device_prep_interleaved_dma)(
  632. struct dma_chan *chan, struct dma_interleaved_template *xt,
  633. unsigned long flags);
  634. int (*device_control)(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
  635. unsigned long arg);
  636. enum dma_status (*device_tx_status)(struct dma_chan *chan,
  637. dma_cookie_t cookie,
  638. struct dma_tx_state *txstate);
  639. void (*device_issue_pending)(struct dma_chan *chan);
  640. int (*device_slave_caps)(struct dma_chan *chan, struct dma_slave_caps *caps);
  641. };
  642. static inline int dmaengine_device_control(struct dma_chan *chan,
  643. enum dma_ctrl_cmd cmd,
  644. unsigned long arg)
  645. {
  646. if (chan->device->device_control)
  647. return chan->device->device_control(chan, cmd, arg);
  648. return -ENOSYS;
  649. }
  650. static inline int dmaengine_slave_config(struct dma_chan *chan,
  651. struct dma_slave_config *config)
  652. {
  653. return dmaengine_device_control(chan, DMA_SLAVE_CONFIG,
  654. (unsigned long)config);
  655. }
  656. static inline bool is_slave_direction(enum dma_transfer_direction direction)
  657. {
  658. return (direction == DMA_MEM_TO_DEV) || (direction == DMA_DEV_TO_MEM);
  659. }
  660. static inline struct dma_async_tx_descriptor *dmaengine_prep_slave_single(
  661. struct dma_chan *chan, dma_addr_t buf, size_t len,
  662. enum dma_transfer_direction dir, unsigned long flags)
  663. {
  664. struct scatterlist sg;
  665. sg_init_table(&sg, 1);
  666. sg_dma_address(&sg) = buf;
  667. sg_dma_len(&sg) = len;
  668. return chan->device->device_prep_slave_sg(chan, &sg, 1,
  669. dir, flags, NULL);
  670. }
  671. static inline struct dma_async_tx_descriptor *dmaengine_prep_slave_sg(
  672. struct dma_chan *chan, struct scatterlist *sgl, unsigned int sg_len,
  673. enum dma_transfer_direction dir, unsigned long flags)
  674. {
  675. return chan->device->device_prep_slave_sg(chan, sgl, sg_len,
  676. dir, flags, NULL);
  677. }
  678. #ifdef CONFIG_RAPIDIO_DMA_ENGINE
  679. struct rio_dma_ext;
  680. static inline struct dma_async_tx_descriptor *dmaengine_prep_rio_sg(
  681. struct dma_chan *chan, struct scatterlist *sgl, unsigned int sg_len,
  682. enum dma_transfer_direction dir, unsigned long flags,
  683. struct rio_dma_ext *rio_ext)
  684. {
  685. return chan->device->device_prep_slave_sg(chan, sgl, sg_len,
  686. dir, flags, rio_ext);
  687. }
  688. #endif
  689. static inline struct dma_async_tx_descriptor *dmaengine_prep_dma_cyclic(
  690. struct dma_chan *chan, dma_addr_t buf_addr, size_t buf_len,
  691. size_t period_len, enum dma_transfer_direction dir,
  692. unsigned long flags)
  693. {
  694. return chan->device->device_prep_dma_cyclic(chan, buf_addr, buf_len,
  695. period_len, dir, flags);
  696. }
  697. static inline struct dma_async_tx_descriptor *dmaengine_prep_interleaved_dma(
  698. struct dma_chan *chan, struct dma_interleaved_template *xt,
  699. unsigned long flags)
  700. {
  701. return chan->device->device_prep_interleaved_dma(chan, xt, flags);
  702. }
  703. static inline struct dma_async_tx_descriptor *dmaengine_prep_dma_sg(
  704. struct dma_chan *chan,
  705. struct scatterlist *dst_sg, unsigned int dst_nents,
  706. struct scatterlist *src_sg, unsigned int src_nents,
  707. unsigned long flags)
  708. {
  709. return chan->device->device_prep_dma_sg(chan, dst_sg, dst_nents,
  710. src_sg, src_nents, flags);
  711. }
  712. static inline int dma_get_slave_caps(struct dma_chan *chan, struct dma_slave_caps *caps)
  713. {
  714. if (!chan || !caps)
  715. return -EINVAL;
  716. /* check if the channel supports slave transactions */
  717. if (!test_bit(DMA_SLAVE, chan->device->cap_mask.bits))
  718. return -ENXIO;
  719. if (chan->device->device_slave_caps)
  720. return chan->device->device_slave_caps(chan, caps);
  721. return -ENXIO;
  722. }
  723. static inline int dmaengine_terminate_all(struct dma_chan *chan)
  724. {
  725. return dmaengine_device_control(chan, DMA_TERMINATE_ALL, 0);
  726. }
  727. static inline int dmaengine_pause(struct dma_chan *chan)
  728. {
  729. return dmaengine_device_control(chan, DMA_PAUSE, 0);
  730. }
  731. static inline int dmaengine_resume(struct dma_chan *chan)
  732. {
  733. return dmaengine_device_control(chan, DMA_RESUME, 0);
  734. }
  735. static inline enum dma_status dmaengine_tx_status(struct dma_chan *chan,
  736. dma_cookie_t cookie, struct dma_tx_state *state)
  737. {
  738. return chan->device->device_tx_status(chan, cookie, state);
  739. }
  740. static inline dma_cookie_t dmaengine_submit(struct dma_async_tx_descriptor *desc)
  741. {
  742. return desc->tx_submit(desc);
  743. }
  744. static inline bool dmaengine_check_align(u8 align, size_t off1, size_t off2, size_t len)
  745. {
  746. size_t mask;
  747. if (!align)
  748. return true;
  749. mask = (1 << align) - 1;
  750. if (mask & (off1 | off2 | len))
  751. return false;
  752. return true;
  753. }
  754. static inline bool is_dma_copy_aligned(struct dma_device *dev, size_t off1,
  755. size_t off2, size_t len)
  756. {
  757. return dmaengine_check_align(dev->copy_align, off1, off2, len);
  758. }
  759. static inline bool is_dma_xor_aligned(struct dma_device *dev, size_t off1,
  760. size_t off2, size_t len)
  761. {
  762. return dmaengine_check_align(dev->xor_align, off1, off2, len);
  763. }
  764. static inline bool is_dma_pq_aligned(struct dma_device *dev, size_t off1,
  765. size_t off2, size_t len)
  766. {
  767. return dmaengine_check_align(dev->pq_align, off1, off2, len);
  768. }
  769. static inline bool is_dma_fill_aligned(struct dma_device *dev, size_t off1,
  770. size_t off2, size_t len)
  771. {
  772. return dmaengine_check_align(dev->fill_align, off1, off2, len);
  773. }
  774. static inline void
  775. dma_set_maxpq(struct dma_device *dma, int maxpq, int has_pq_continue)
  776. {
  777. dma->max_pq = maxpq;
  778. if (has_pq_continue)
  779. dma->max_pq |= DMA_HAS_PQ_CONTINUE;
  780. }
  781. static inline bool dmaf_continue(enum dma_ctrl_flags flags)
  782. {
  783. return (flags & DMA_PREP_CONTINUE) == DMA_PREP_CONTINUE;
  784. }
  785. static inline bool dmaf_p_disabled_continue(enum dma_ctrl_flags flags)
  786. {
  787. enum dma_ctrl_flags mask = DMA_PREP_CONTINUE | DMA_PREP_PQ_DISABLE_P;
  788. return (flags & mask) == mask;
  789. }
  790. static inline bool dma_dev_has_pq_continue(struct dma_device *dma)
  791. {
  792. return (dma->max_pq & DMA_HAS_PQ_CONTINUE) == DMA_HAS_PQ_CONTINUE;
  793. }
  794. static inline unsigned short dma_dev_to_maxpq(struct dma_device *dma)
  795. {
  796. return dma->max_pq & ~DMA_HAS_PQ_CONTINUE;
  797. }
  798. /* dma_maxpq - reduce maxpq in the face of continued operations
  799. * @dma - dma device with PQ capability
  800. * @flags - to check if DMA_PREP_CONTINUE and DMA_PREP_PQ_DISABLE_P are set
  801. *
  802. * When an engine does not support native continuation we need 3 extra
  803. * source slots to reuse P and Q with the following coefficients:
  804. * 1/ {00} * P : remove P from Q', but use it as a source for P'
  805. * 2/ {01} * Q : use Q to continue Q' calculation
  806. * 3/ {00} * Q : subtract Q from P' to cancel (2)
  807. *
  808. * In the case where P is disabled we only need 1 extra source:
  809. * 1/ {01} * Q : use Q to continue Q' calculation
  810. */
  811. static inline int dma_maxpq(struct dma_device *dma, enum dma_ctrl_flags flags)
  812. {
  813. if (dma_dev_has_pq_continue(dma) || !dmaf_continue(flags))
  814. return dma_dev_to_maxpq(dma);
  815. else if (dmaf_p_disabled_continue(flags))
  816. return dma_dev_to_maxpq(dma) - 1;
  817. else if (dmaf_continue(flags))
  818. return dma_dev_to_maxpq(dma) - 3;
  819. BUG();
  820. }
  821. /* --- public DMA engine API --- */
  822. #ifdef CONFIG_DMA_ENGINE
  823. void dmaengine_get(void);
  824. void dmaengine_put(void);
  825. #else
  826. static inline void dmaengine_get(void)
  827. {
  828. }
  829. static inline void dmaengine_put(void)
  830. {
  831. }
  832. #endif
  833. #ifdef CONFIG_ASYNC_TX_DMA
  834. #define async_dmaengine_get() dmaengine_get()
  835. #define async_dmaengine_put() dmaengine_put()
  836. #ifndef CONFIG_ASYNC_TX_ENABLE_CHANNEL_SWITCH
  837. #define async_dma_find_channel(type) dma_find_channel(DMA_ASYNC_TX)
  838. #else
  839. #define async_dma_find_channel(type) dma_find_channel(type)
  840. #endif /* CONFIG_ASYNC_TX_ENABLE_CHANNEL_SWITCH */
  841. #else
  842. static inline void async_dmaengine_get(void)
  843. {
  844. }
  845. static inline void async_dmaengine_put(void)
  846. {
  847. }
  848. static inline struct dma_chan *
  849. async_dma_find_channel(enum dma_transaction_type type)
  850. {
  851. return NULL;
  852. }
  853. #endif /* CONFIG_ASYNC_TX_DMA */
  854. void dma_async_tx_descriptor_init(struct dma_async_tx_descriptor *tx,
  855. struct dma_chan *chan);
  856. static inline void async_tx_ack(struct dma_async_tx_descriptor *tx)
  857. {
  858. tx->flags |= DMA_CTRL_ACK;
  859. }
  860. static inline void async_tx_clear_ack(struct dma_async_tx_descriptor *tx)
  861. {
  862. tx->flags &= ~DMA_CTRL_ACK;
  863. }
  864. static inline bool async_tx_test_ack(struct dma_async_tx_descriptor *tx)
  865. {
  866. return (tx->flags & DMA_CTRL_ACK) == DMA_CTRL_ACK;
  867. }
  868. #define dma_cap_set(tx, mask) __dma_cap_set((tx), &(mask))
  869. static inline void
  870. __dma_cap_set(enum dma_transaction_type tx_type, dma_cap_mask_t *dstp)
  871. {
  872. set_bit(tx_type, dstp->bits);
  873. }
  874. #define dma_cap_clear(tx, mask) __dma_cap_clear((tx), &(mask))
  875. static inline void
  876. __dma_cap_clear(enum dma_transaction_type tx_type, dma_cap_mask_t *dstp)
  877. {
  878. clear_bit(tx_type, dstp->bits);
  879. }
  880. #define dma_cap_zero(mask) __dma_cap_zero(&(mask))
  881. static inline void __dma_cap_zero(dma_cap_mask_t *dstp)
  882. {
  883. bitmap_zero(dstp->bits, DMA_TX_TYPE_END);
  884. }
  885. #define dma_has_cap(tx, mask) __dma_has_cap((tx), &(mask))
  886. static inline int
  887. __dma_has_cap(enum dma_transaction_type tx_type, dma_cap_mask_t *srcp)
  888. {
  889. return test_bit(tx_type, srcp->bits);
  890. }
  891. #define for_each_dma_cap_mask(cap, mask) \
  892. for_each_set_bit(cap, mask.bits, DMA_TX_TYPE_END)
  893. /**
  894. * dma_async_issue_pending - flush pending transactions to HW
  895. * @chan: target DMA channel
  896. *
  897. * This allows drivers to push copies to HW in batches,
  898. * reducing MMIO writes where possible.
  899. */
  900. static inline void dma_async_issue_pending(struct dma_chan *chan)
  901. {
  902. chan->device->device_issue_pending(chan);
  903. }
  904. /**
  905. * dma_async_is_tx_complete - poll for transaction completion
  906. * @chan: DMA channel
  907. * @cookie: transaction identifier to check status of
  908. * @last: returns last completed cookie, can be NULL
  909. * @used: returns last issued cookie, can be NULL
  910. *
  911. * If @last and @used are passed in, upon return they reflect the driver
  912. * internal state and can be used with dma_async_is_complete() to check
  913. * the status of multiple cookies without re-checking hardware state.
  914. */
  915. static inline enum dma_status dma_async_is_tx_complete(struct dma_chan *chan,
  916. dma_cookie_t cookie, dma_cookie_t *last, dma_cookie_t *used)
  917. {
  918. struct dma_tx_state state;
  919. enum dma_status status;
  920. status = chan->device->device_tx_status(chan, cookie, &state);
  921. if (last)
  922. *last = state.last;
  923. if (used)
  924. *used = state.used;
  925. return status;
  926. }
  927. /**
  928. * dma_async_is_complete - test a cookie against chan state
  929. * @cookie: transaction identifier to test status of
  930. * @last_complete: last know completed transaction
  931. * @last_used: last cookie value handed out
  932. *
  933. * dma_async_is_complete() is used in dma_async_is_tx_complete()
  934. * the test logic is separated for lightweight testing of multiple cookies
  935. */
  936. static inline enum dma_status dma_async_is_complete(dma_cookie_t cookie,
  937. dma_cookie_t last_complete, dma_cookie_t last_used)
  938. {
  939. if (last_complete <= last_used) {
  940. if ((cookie <= last_complete) || (cookie > last_used))
  941. return DMA_COMPLETE;
  942. } else {
  943. if ((cookie <= last_complete) && (cookie > last_used))
  944. return DMA_COMPLETE;
  945. }
  946. return DMA_IN_PROGRESS;
  947. }
  948. static inline void
  949. dma_set_tx_state(struct dma_tx_state *st, dma_cookie_t last, dma_cookie_t used, u32 residue)
  950. {
  951. if (st) {
  952. st->last = last;
  953. st->used = used;
  954. st->residue = residue;
  955. }
  956. }
  957. #ifdef CONFIG_DMA_ENGINE
  958. struct dma_chan *dma_find_channel(enum dma_transaction_type tx_type);
  959. enum dma_status dma_sync_wait(struct dma_chan *chan, dma_cookie_t cookie);
  960. enum dma_status dma_wait_for_async_tx(struct dma_async_tx_descriptor *tx);
  961. void dma_issue_pending_all(void);
  962. struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask,
  963. dma_filter_fn fn, void *fn_param);
  964. struct dma_chan *dma_request_slave_channel_reason(struct device *dev,
  965. const char *name);
  966. struct dma_chan *dma_request_slave_channel(struct device *dev, const char *name);
  967. void dma_release_channel(struct dma_chan *chan);
  968. #else
  969. static inline struct dma_chan *dma_find_channel(enum dma_transaction_type tx_type)
  970. {
  971. return NULL;
  972. }
  973. static inline enum dma_status dma_sync_wait(struct dma_chan *chan, dma_cookie_t cookie)
  974. {
  975. return DMA_COMPLETE;
  976. }
  977. static inline enum dma_status dma_wait_for_async_tx(struct dma_async_tx_descriptor *tx)
  978. {
  979. return DMA_COMPLETE;
  980. }
  981. static inline void dma_issue_pending_all(void)
  982. {
  983. }
  984. static inline struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask,
  985. dma_filter_fn fn, void *fn_param)
  986. {
  987. return NULL;
  988. }
  989. static inline struct dma_chan *dma_request_slave_channel_reason(
  990. struct device *dev, const char *name)
  991. {
  992. return ERR_PTR(-ENODEV);
  993. }
  994. static inline struct dma_chan *dma_request_slave_channel(struct device *dev,
  995. const char *name)
  996. {
  997. return NULL;
  998. }
  999. static inline void dma_release_channel(struct dma_chan *chan)
  1000. {
  1001. }
  1002. #endif
  1003. /* --- DMA device --- */
  1004. int dma_async_device_register(struct dma_device *device);
  1005. void dma_async_device_unregister(struct dma_device *device);
  1006. void dma_run_dependencies(struct dma_async_tx_descriptor *tx);
  1007. struct dma_chan *dma_get_slave_channel(struct dma_chan *chan);
  1008. struct dma_chan *dma_get_any_slave_channel(struct dma_device *device);
  1009. struct dma_chan *net_dma_find_channel(void);
  1010. #define dma_request_channel(mask, x, y) __dma_request_channel(&(mask), x, y)
  1011. #define dma_request_slave_channel_compat(mask, x, y, dev, name) \
  1012. __dma_request_slave_channel_compat(&(mask), x, y, dev, name)
  1013. static inline struct dma_chan
  1014. *__dma_request_slave_channel_compat(const dma_cap_mask_t *mask,
  1015. dma_filter_fn fn, void *fn_param,
  1016. struct device *dev, char *name)
  1017. {
  1018. struct dma_chan *chan;
  1019. chan = dma_request_slave_channel(dev, name);
  1020. if (chan)
  1021. return chan;
  1022. return __dma_request_channel(mask, fn, fn_param);
  1023. }
  1024. /* --- Helper iov-locking functions --- */
  1025. struct dma_page_list {
  1026. char __user *base_address;
  1027. int nr_pages;
  1028. struct page **pages;
  1029. };
  1030. struct dma_pinned_list {
  1031. int nr_iovecs;
  1032. struct dma_page_list page_list[0];
  1033. };
  1034. struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
  1035. void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
  1036. dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
  1037. struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
  1038. dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
  1039. struct dma_pinned_list *pinned_list, struct page *page,
  1040. unsigned int offset, size_t len);
  1041. #endif /* DMAENGINE_H */