dmaengine.h 38 KB

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