dmaengine.h 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Copyright(c) 2004 - 2006 Intel Corporation. All rights reserved.
  4. */
  5. #ifndef LINUX_DMAENGINE_H
  6. #define LINUX_DMAENGINE_H
  7. #include <linux/device.h>
  8. #include <linux/err.h>
  9. #include <linux/uio.h>
  10. #include <linux/bug.h>
  11. #include <linux/scatterlist.h>
  12. #include <linux/bitmap.h>
  13. #include <linux/types.h>
  14. #include <linux/android_kabi.h>
  15. #include <asm/page.h>
  16. /**
  17. * typedef dma_cookie_t - an opaque DMA cookie
  18. *
  19. * if dma_cookie_t is >0 it's a DMA request cookie, <0 it's an error code
  20. */
  21. typedef s32 dma_cookie_t;
  22. #define DMA_MIN_COOKIE 1
  23. static inline int dma_submit_error(dma_cookie_t cookie)
  24. {
  25. return cookie < 0 ? cookie : 0;
  26. }
  27. /**
  28. * enum dma_status - DMA transaction status
  29. * @DMA_COMPLETE: transaction completed
  30. * @DMA_IN_PROGRESS: transaction not yet processed
  31. * @DMA_PAUSED: transaction is paused
  32. * @DMA_ERROR: transaction failed
  33. */
  34. enum dma_status {
  35. DMA_COMPLETE,
  36. DMA_IN_PROGRESS,
  37. DMA_PAUSED,
  38. DMA_ERROR,
  39. DMA_OUT_OF_ORDER,
  40. };
  41. /**
  42. * enum dma_transaction_type - DMA transaction types/indexes
  43. *
  44. * Note: The DMA_ASYNC_TX capability is not to be set by drivers. It is
  45. * automatically set as dma devices are registered.
  46. */
  47. enum dma_transaction_type {
  48. DMA_MEMCPY,
  49. DMA_XOR,
  50. DMA_PQ,
  51. DMA_XOR_VAL,
  52. DMA_PQ_VAL,
  53. DMA_MEMSET,
  54. DMA_MEMSET_SG,
  55. DMA_INTERRUPT,
  56. DMA_PRIVATE,
  57. DMA_ASYNC_TX,
  58. DMA_SLAVE,
  59. DMA_CYCLIC,
  60. DMA_INTERLEAVE,
  61. DMA_COMPLETION_NO_ORDER,
  62. DMA_REPEAT,
  63. DMA_LOAD_EOT,
  64. /* last transaction type for creation of the capabilities mask */
  65. DMA_TX_TYPE_END,
  66. };
  67. /**
  68. * enum dma_transfer_direction - dma transfer mode and direction indicator
  69. * @DMA_MEM_TO_MEM: Async/Memcpy mode
  70. * @DMA_MEM_TO_DEV: Slave mode & From Memory to Device
  71. * @DMA_DEV_TO_MEM: Slave mode & From Device to Memory
  72. * @DMA_DEV_TO_DEV: Slave mode & From Device to Device
  73. */
  74. enum dma_transfer_direction {
  75. DMA_MEM_TO_MEM,
  76. DMA_MEM_TO_DEV,
  77. DMA_DEV_TO_MEM,
  78. DMA_DEV_TO_DEV,
  79. DMA_TRANS_NONE,
  80. };
  81. /**
  82. * Interleaved Transfer Request
  83. * ----------------------------
  84. * A chunk is collection of contiguous bytes to be transferred.
  85. * The gap(in bytes) between two chunks is called inter-chunk-gap(ICG).
  86. * ICGs may or may not change between chunks.
  87. * A FRAME is the smallest series of contiguous {chunk,icg} pairs,
  88. * that when repeated an integral number of times, specifies the transfer.
  89. * A transfer template is specification of a Frame, the number of times
  90. * it is to be repeated and other per-transfer attributes.
  91. *
  92. * Practically, a client driver would have ready a template for each
  93. * type of transfer it is going to need during its lifetime and
  94. * set only 'src_start' and 'dst_start' before submitting the requests.
  95. *
  96. *
  97. * | Frame-1 | Frame-2 | ~ | Frame-'numf' |
  98. * |====....==.===...=...|====....==.===...=...| ~ |====....==.===...=...|
  99. *
  100. * == Chunk size
  101. * ... ICG
  102. */
  103. /**
  104. * struct data_chunk - Element of scatter-gather list that makes a frame.
  105. * @size: Number of bytes to read from source.
  106. * size_dst := fn(op, size_src), so doesn't mean much for destination.
  107. * @icg: Number of bytes to jump after last src/dst address of this
  108. * chunk and before first src/dst address for next chunk.
  109. * Ignored for dst(assumed 0), if dst_inc is true and dst_sgl is false.
  110. * Ignored for src(assumed 0), if src_inc is true and src_sgl is false.
  111. * @dst_icg: Number of bytes to jump after last dst address of this
  112. * chunk and before the first dst address for next chunk.
  113. * Ignored if dst_inc is true and dst_sgl is false.
  114. * @src_icg: Number of bytes to jump after last src address of this
  115. * chunk and before the first src address for next chunk.
  116. * Ignored if src_inc is true and src_sgl is false.
  117. */
  118. struct data_chunk {
  119. size_t size;
  120. size_t icg;
  121. size_t dst_icg;
  122. size_t src_icg;
  123. };
  124. /**
  125. * struct dma_interleaved_template - Template to convey DMAC the transfer pattern
  126. * and attributes.
  127. * @src_start: Bus address of source for the first chunk.
  128. * @dst_start: Bus address of destination for the first chunk.
  129. * @dir: Specifies the type of Source and Destination.
  130. * @src_inc: If the source address increments after reading from it.
  131. * @dst_inc: If the destination address increments after writing to it.
  132. * @src_sgl: If the 'icg' of sgl[] applies to Source (scattered read).
  133. * Otherwise, source is read contiguously (icg ignored).
  134. * Ignored if src_inc is false.
  135. * @dst_sgl: If the 'icg' of sgl[] applies to Destination (scattered write).
  136. * Otherwise, destination is filled contiguously (icg ignored).
  137. * Ignored if dst_inc is false.
  138. * @numf: Number of frames in this template.
  139. * @frame_size: Number of chunks in a frame i.e, size of sgl[].
  140. * @sgl: Array of {chunk,icg} pairs that make up a frame.
  141. */
  142. struct dma_interleaved_template {
  143. dma_addr_t src_start;
  144. dma_addr_t dst_start;
  145. enum dma_transfer_direction dir;
  146. bool src_inc;
  147. bool dst_inc;
  148. bool src_sgl;
  149. bool dst_sgl;
  150. size_t numf;
  151. size_t frame_size;
  152. struct data_chunk sgl[];
  153. };
  154. /**
  155. * enum dma_ctrl_flags - DMA flags to augment operation preparation,
  156. * control completion, and communicate status.
  157. * @DMA_PREP_INTERRUPT - trigger an interrupt (callback) upon completion of
  158. * this transaction
  159. * @DMA_CTRL_ACK - if clear, the descriptor cannot be reused until the client
  160. * acknowledges receipt, i.e. has a chance to establish any dependency
  161. * chains
  162. * @DMA_PREP_PQ_DISABLE_P - prevent generation of P while generating Q
  163. * @DMA_PREP_PQ_DISABLE_Q - prevent generation of Q while generating P
  164. * @DMA_PREP_CONTINUE - indicate to a driver that it is reusing buffers as
  165. * sources that were the result of a previous operation, in the case of a PQ
  166. * operation it continues the calculation with new sources
  167. * @DMA_PREP_FENCE - tell the driver that subsequent operations depend
  168. * on the result of this operation
  169. * @DMA_CTRL_REUSE: client can reuse the descriptor and submit again till
  170. * cleared or freed
  171. * @DMA_PREP_CMD: tell the driver that the data passed to DMA API is command
  172. * data and the descriptor should be in different format from normal
  173. * data descriptors.
  174. * @DMA_PREP_REPEAT: tell the driver that the transaction shall be automatically
  175. * repeated when it ends until a transaction is issued on the same channel
  176. * with the DMA_PREP_LOAD_EOT flag set. This flag is only applicable to
  177. * interleaved transactions and is ignored for all other transaction types.
  178. * @DMA_PREP_LOAD_EOT: tell the driver that the transaction shall replace any
  179. * active repeated (as indicated by DMA_PREP_REPEAT) transaction when the
  180. * repeated transaction ends. Not setting this flag when the previously queued
  181. * transaction is marked with DMA_PREP_REPEAT will cause the new transaction
  182. * to never be processed and stay in the issued queue forever. The flag is
  183. * ignored if the previous transaction is not a repeated transaction.
  184. */
  185. enum dma_ctrl_flags {
  186. DMA_PREP_INTERRUPT = (1 << 0),
  187. DMA_CTRL_ACK = (1 << 1),
  188. DMA_PREP_PQ_DISABLE_P = (1 << 2),
  189. DMA_PREP_PQ_DISABLE_Q = (1 << 3),
  190. DMA_PREP_CONTINUE = (1 << 4),
  191. DMA_PREP_FENCE = (1 << 5),
  192. DMA_CTRL_REUSE = (1 << 6),
  193. DMA_PREP_CMD = (1 << 7),
  194. DMA_PREP_REPEAT = (1 << 8),
  195. DMA_PREP_LOAD_EOT = (1 << 9),
  196. };
  197. /**
  198. * enum sum_check_bits - bit position of pq_check_flags
  199. */
  200. enum sum_check_bits {
  201. SUM_CHECK_P = 0,
  202. SUM_CHECK_Q = 1,
  203. };
  204. /**
  205. * enum pq_check_flags - result of async_{xor,pq}_zero_sum operations
  206. * @SUM_CHECK_P_RESULT - 1 if xor zero sum error, 0 otherwise
  207. * @SUM_CHECK_Q_RESULT - 1 if reed-solomon zero sum error, 0 otherwise
  208. */
  209. enum sum_check_flags {
  210. SUM_CHECK_P_RESULT = (1 << SUM_CHECK_P),
  211. SUM_CHECK_Q_RESULT = (1 << SUM_CHECK_Q),
  212. };
  213. /**
  214. * dma_cap_mask_t - capabilities bitmap modeled after cpumask_t.
  215. * See linux/cpumask.h
  216. */
  217. typedef struct { DECLARE_BITMAP(bits, DMA_TX_TYPE_END); } dma_cap_mask_t;
  218. /**
  219. * enum dma_desc_metadata_mode - per descriptor metadata mode types supported
  220. * @DESC_METADATA_CLIENT - the metadata buffer is allocated/provided by the
  221. * client driver and it is attached (via the dmaengine_desc_attach_metadata()
  222. * helper) to the descriptor.
  223. *
  224. * Client drivers interested to use this mode can follow:
  225. * - DMA_MEM_TO_DEV / DEV_MEM_TO_MEM:
  226. * 1. prepare the descriptor (dmaengine_prep_*)
  227. * construct the metadata in the client's buffer
  228. * 2. use dmaengine_desc_attach_metadata() to attach the buffer to the
  229. * descriptor
  230. * 3. submit the transfer
  231. * - DMA_DEV_TO_MEM:
  232. * 1. prepare the descriptor (dmaengine_prep_*)
  233. * 2. use dmaengine_desc_attach_metadata() to attach the buffer to the
  234. * descriptor
  235. * 3. submit the transfer
  236. * 4. when the transfer is completed, the metadata should be available in the
  237. * attached buffer
  238. *
  239. * @DESC_METADATA_ENGINE - the metadata buffer is allocated/managed by the DMA
  240. * driver. The client driver can ask for the pointer, maximum size and the
  241. * currently used size of the metadata and can directly update or read it.
  242. * dmaengine_desc_get_metadata_ptr() and dmaengine_desc_set_metadata_len() is
  243. * provided as helper functions.
  244. *
  245. * Note: the metadata area for the descriptor is no longer valid after the
  246. * transfer has been completed (valid up to the point when the completion
  247. * callback returns if used).
  248. *
  249. * Client drivers interested to use this mode can follow:
  250. * - DMA_MEM_TO_DEV / DEV_MEM_TO_MEM:
  251. * 1. prepare the descriptor (dmaengine_prep_*)
  252. * 2. use dmaengine_desc_get_metadata_ptr() to get the pointer to the engine's
  253. * metadata area
  254. * 3. update the metadata at the pointer
  255. * 4. use dmaengine_desc_set_metadata_len() to tell the DMA engine the amount
  256. * of data the client has placed into the metadata buffer
  257. * 5. submit the transfer
  258. * - DMA_DEV_TO_MEM:
  259. * 1. prepare the descriptor (dmaengine_prep_*)
  260. * 2. submit the transfer
  261. * 3. on transfer completion, use dmaengine_desc_get_metadata_ptr() to get the
  262. * pointer to the engine's metadata area
  263. * 4. Read out the metadata from the pointer
  264. *
  265. * Note: the two mode is not compatible and clients must use one mode for a
  266. * descriptor.
  267. */
  268. enum dma_desc_metadata_mode {
  269. DESC_METADATA_NONE = 0,
  270. DESC_METADATA_CLIENT = BIT(0),
  271. DESC_METADATA_ENGINE = BIT(1),
  272. };
  273. /**
  274. * struct dma_chan_percpu - the per-CPU part of struct dma_chan
  275. * @memcpy_count: transaction counter
  276. * @bytes_transferred: byte counter
  277. */
  278. struct dma_chan_percpu {
  279. /* stats */
  280. unsigned long memcpy_count;
  281. unsigned long bytes_transferred;
  282. };
  283. /**
  284. * struct dma_router - DMA router structure
  285. * @dev: pointer to the DMA router device
  286. * @route_free: function to be called when the route can be disconnected
  287. */
  288. struct dma_router {
  289. struct device *dev;
  290. void (*route_free)(struct device *dev, void *route_data);
  291. };
  292. /**
  293. * struct dma_chan - devices supply DMA channels, clients use them
  294. * @device: ptr to the dma device who supplies this channel, always !%NULL
  295. * @slave: ptr to the device using this channel
  296. * @cookie: last cookie value returned to client
  297. * @completed_cookie: last completed cookie for this channel
  298. * @chan_id: channel ID for sysfs
  299. * @dev: class device for sysfs
  300. * @name: backlink name for sysfs
  301. * @dbg_client_name: slave name for debugfs in format:
  302. * dev_name(requester's dev):channel name, for example: "2b00000.mcasp:tx"
  303. * @device_node: used to add this to the device chan list
  304. * @local: per-cpu pointer to a struct dma_chan_percpu
  305. * @client_count: how many clients are using this channel
  306. * @table_count: number of appearances in the mem-to-mem allocation table
  307. * @router: pointer to the DMA router structure
  308. * @route_data: channel specific data for the router
  309. * @private: private data for certain client-channel associations
  310. */
  311. struct dma_chan {
  312. struct dma_device *device;
  313. struct device *slave;
  314. dma_cookie_t cookie;
  315. dma_cookie_t completed_cookie;
  316. /* sysfs */
  317. int chan_id;
  318. struct dma_chan_dev *dev;
  319. const char *name;
  320. #ifdef CONFIG_DEBUG_FS
  321. char *dbg_client_name;
  322. #endif
  323. struct list_head device_node;
  324. struct dma_chan_percpu __percpu *local;
  325. int client_count;
  326. int table_count;
  327. /* DMA router */
  328. struct dma_router *router;
  329. void *route_data;
  330. void *private;
  331. };
  332. /**
  333. * struct dma_chan_dev - relate sysfs device node to backing channel device
  334. * @chan: driver channel device
  335. * @device: sysfs device
  336. * @dev_id: parent dma_device dev_id
  337. * @chan_dma_dev: The channel is using custom/different dma-mapping
  338. * compared to the parent dma_device
  339. */
  340. struct dma_chan_dev {
  341. struct dma_chan *chan;
  342. struct device device;
  343. int dev_id;
  344. bool chan_dma_dev;
  345. };
  346. /**
  347. * enum dma_slave_buswidth - defines bus width of the DMA slave
  348. * device, source or target buses
  349. */
  350. enum dma_slave_buswidth {
  351. DMA_SLAVE_BUSWIDTH_UNDEFINED = 0,
  352. DMA_SLAVE_BUSWIDTH_1_BYTE = 1,
  353. DMA_SLAVE_BUSWIDTH_2_BYTES = 2,
  354. DMA_SLAVE_BUSWIDTH_3_BYTES = 3,
  355. DMA_SLAVE_BUSWIDTH_4_BYTES = 4,
  356. DMA_SLAVE_BUSWIDTH_8_BYTES = 8,
  357. DMA_SLAVE_BUSWIDTH_16_BYTES = 16,
  358. DMA_SLAVE_BUSWIDTH_32_BYTES = 32,
  359. DMA_SLAVE_BUSWIDTH_64_BYTES = 64,
  360. DMA_SLAVE_BUSWIDTH_128_BYTES = 128,
  361. };
  362. /**
  363. * struct dma_slave_config - dma slave channel runtime config
  364. * @direction: whether the data shall go in or out on this slave
  365. * channel, right now. DMA_MEM_TO_DEV and DMA_DEV_TO_MEM are
  366. * legal values. DEPRECATED, drivers should use the direction argument
  367. * to the device_prep_slave_sg and device_prep_dma_cyclic functions or
  368. * the dir field in the dma_interleaved_template structure.
  369. * @src_addr: this is the physical address where DMA slave data
  370. * should be read (RX), if the source is memory this argument is
  371. * ignored.
  372. * @dst_addr: this is the physical address where DMA slave data
  373. * should be written (TX), if the source is memory this argument
  374. * is ignored.
  375. * @src_addr_width: this is the width in bytes of the source (RX)
  376. * register where DMA data shall be read. If the source
  377. * is memory this may be ignored depending on architecture.
  378. * Legal values: 1, 2, 3, 4, 8, 16, 32, 64, 128.
  379. * @dst_addr_width: same as src_addr_width but for destination
  380. * target (TX) mutatis mutandis.
  381. * @src_maxburst: the maximum number of words (note: words, as in
  382. * units of the src_addr_width member, not bytes) that can be sent
  383. * in one burst to the device. Typically something like half the
  384. * FIFO depth on I/O peripherals so you don't overflow it. This
  385. * may or may not be applicable on memory sources.
  386. * @dst_maxburst: same as src_maxburst but for destination target
  387. * mutatis mutandis.
  388. * @src_port_window_size: The length of the register area in words the data need
  389. * to be accessed on the device side. It is only used for devices which is using
  390. * an area instead of a single register to receive the data. Typically the DMA
  391. * loops in this area in order to transfer the data.
  392. * @dst_port_window_size: same as src_port_window_size but for the destination
  393. * port.
  394. * @device_fc: Flow Controller Settings. Only valid for slave channels. Fill
  395. * with 'true' if peripheral should be flow controller. Direction will be
  396. * selected at Runtime.
  397. * @peripheral_config: peripheral configuration for programming peripheral
  398. * for dmaengine transfer
  399. * @peripheral_size: peripheral configuration buffer size
  400. *
  401. * This struct is passed in as configuration data to a DMA engine
  402. * in order to set up a certain channel for DMA transport at runtime.
  403. * The DMA device/engine has to provide support for an additional
  404. * callback in the dma_device structure, device_config and this struct
  405. * will then be passed in as an argument to the function.
  406. *
  407. * The rationale for adding configuration information to this struct is as
  408. * follows: if it is likely that more than one DMA slave controllers in
  409. * the world will support the configuration option, then make it generic.
  410. * If not: if it is fixed so that it be sent in static from the platform
  411. * data, then prefer to do that.
  412. */
  413. struct dma_slave_config {
  414. enum dma_transfer_direction direction;
  415. phys_addr_t src_addr;
  416. phys_addr_t dst_addr;
  417. enum dma_slave_buswidth src_addr_width;
  418. enum dma_slave_buswidth dst_addr_width;
  419. u32 src_maxburst;
  420. u32 dst_maxburst;
  421. u32 src_port_window_size;
  422. u32 dst_port_window_size;
  423. bool device_fc;
  424. void *peripheral_config;
  425. size_t peripheral_size;
  426. };
  427. /**
  428. * enum dma_residue_granularity - Granularity of the reported transfer residue
  429. * @DMA_RESIDUE_GRANULARITY_DESCRIPTOR: Residue reporting is not support. The
  430. * DMA channel is only able to tell whether a descriptor has been completed or
  431. * not, which means residue reporting is not supported by this channel. The
  432. * residue field of the dma_tx_state field will always be 0.
  433. * @DMA_RESIDUE_GRANULARITY_SEGMENT: Residue is updated after each successfully
  434. * completed segment of the transfer (For cyclic transfers this is after each
  435. * period). This is typically implemented by having the hardware generate an
  436. * interrupt after each transferred segment and then the drivers updates the
  437. * outstanding residue by the size of the segment. Another possibility is if
  438. * the hardware supports scatter-gather and the segment descriptor has a field
  439. * which gets set after the segment has been completed. The driver then counts
  440. * the number of segments without the flag set to compute the residue.
  441. * @DMA_RESIDUE_GRANULARITY_BURST: Residue is updated after each transferred
  442. * burst. This is typically only supported if the hardware has a progress
  443. * register of some sort (E.g. a register with the current read/write address
  444. * or a register with the amount of bursts/beats/bytes that have been
  445. * transferred or still need to be transferred).
  446. */
  447. enum dma_residue_granularity {
  448. DMA_RESIDUE_GRANULARITY_DESCRIPTOR = 0,
  449. DMA_RESIDUE_GRANULARITY_SEGMENT = 1,
  450. DMA_RESIDUE_GRANULARITY_BURST = 2,
  451. };
  452. /**
  453. * struct dma_slave_caps - expose capabilities of a slave channel only
  454. * @src_addr_widths: bit mask of src addr widths the channel supports.
  455. * Width is specified in bytes, e.g. for a channel supporting
  456. * a width of 4 the mask should have BIT(4) set.
  457. * @dst_addr_widths: bit mask of dst addr widths the channel supports
  458. * @directions: bit mask of slave directions the channel supports.
  459. * Since the enum dma_transfer_direction is not defined as bit flag for
  460. * each type, the dma controller should set BIT(<TYPE>) and same
  461. * should be checked by controller as well
  462. * @min_burst: min burst capability per-transfer
  463. * @max_burst: max burst capability per-transfer
  464. * @max_sg_burst: max number of SG list entries executed in a single burst
  465. * DMA tansaction with no software intervention for reinitialization.
  466. * Zero value means unlimited number of entries.
  467. * @cmd_pause: true, if pause is supported (i.e. for reading residue or
  468. * for resume later)
  469. * @cmd_resume: true, if resume is supported
  470. * @cmd_terminate: true, if terminate cmd is supported
  471. * @residue_granularity: granularity of the reported transfer residue
  472. * @descriptor_reuse: if a descriptor can be reused by client and
  473. * resubmitted multiple times
  474. */
  475. struct dma_slave_caps {
  476. u32 src_addr_widths;
  477. u32 dst_addr_widths;
  478. u32 directions;
  479. u32 min_burst;
  480. u32 max_burst;
  481. u32 max_sg_burst;
  482. bool cmd_pause;
  483. bool cmd_resume;
  484. bool cmd_terminate;
  485. enum dma_residue_granularity residue_granularity;
  486. bool descriptor_reuse;
  487. };
  488. static inline const char *dma_chan_name(struct dma_chan *chan)
  489. {
  490. return dev_name(&chan->dev->device);
  491. }
  492. void dma_chan_cleanup(struct kref *kref);
  493. /**
  494. * typedef dma_filter_fn - callback filter for dma_request_channel
  495. * @chan: channel to be reviewed
  496. * @filter_param: opaque parameter passed through dma_request_channel
  497. *
  498. * When this optional parameter is specified in a call to dma_request_channel a
  499. * suitable channel is passed to this routine for further dispositioning before
  500. * being returned. Where 'suitable' indicates a non-busy channel that
  501. * satisfies the given capability mask. It returns 'true' to indicate that the
  502. * channel is suitable.
  503. */
  504. typedef bool (*dma_filter_fn)(struct dma_chan *chan, void *filter_param);
  505. typedef void (*dma_async_tx_callback)(void *dma_async_param);
  506. enum dmaengine_tx_result {
  507. DMA_TRANS_NOERROR = 0, /* SUCCESS */
  508. DMA_TRANS_READ_FAILED, /* Source DMA read failed */
  509. DMA_TRANS_WRITE_FAILED, /* Destination DMA write failed */
  510. DMA_TRANS_ABORTED, /* Op never submitted / aborted */
  511. };
  512. struct dmaengine_result {
  513. enum dmaengine_tx_result result;
  514. u32 residue;
  515. };
  516. typedef void (*dma_async_tx_callback_result)(void *dma_async_param,
  517. const struct dmaengine_result *result);
  518. struct dmaengine_unmap_data {
  519. #if IS_ENABLED(CONFIG_DMA_ENGINE_RAID)
  520. u16 map_cnt;
  521. #else
  522. u8 map_cnt;
  523. #endif
  524. u8 to_cnt;
  525. u8 from_cnt;
  526. u8 bidi_cnt;
  527. struct device *dev;
  528. struct kref kref;
  529. size_t len;
  530. dma_addr_t addr[];
  531. };
  532. struct dma_async_tx_descriptor;
  533. struct dma_descriptor_metadata_ops {
  534. int (*attach)(struct dma_async_tx_descriptor *desc, void *data,
  535. size_t len);
  536. void *(*get_ptr)(struct dma_async_tx_descriptor *desc,
  537. size_t *payload_len, size_t *max_len);
  538. int (*set_len)(struct dma_async_tx_descriptor *desc,
  539. size_t payload_len);
  540. };
  541. /**
  542. * struct dma_async_tx_descriptor - async transaction descriptor
  543. * ---dma generic offload fields---
  544. * @cookie: tracking cookie for this transaction, set to -EBUSY if
  545. * this tx is sitting on a dependency list
  546. * @flags: flags to augment operation preparation, control completion, and
  547. * communicate status
  548. * @phys: physical address of the descriptor
  549. * @chan: target channel for this operation
  550. * @tx_submit: accept the descriptor, assign ordered cookie and mark the
  551. * descriptor pending. To be pushed on .issue_pending() call
  552. * @callback: routine to call after this operation is complete
  553. * @callback_param: general parameter to pass to the callback routine
  554. * @desc_metadata_mode: core managed metadata mode to protect mixed use of
  555. * DESC_METADATA_CLIENT or DESC_METADATA_ENGINE. Otherwise
  556. * DESC_METADATA_NONE
  557. * @metadata_ops: DMA driver provided metadata mode ops, need to be set by the
  558. * DMA driver if metadata mode is supported with the descriptor
  559. * ---async_tx api specific fields---
  560. * @next: at completion submit this descriptor
  561. * @parent: pointer to the next level up in the dependency chain
  562. * @lock: protect the parent and next pointers
  563. */
  564. struct dma_async_tx_descriptor {
  565. dma_cookie_t cookie;
  566. enum dma_ctrl_flags flags; /* not a 'long' to pack with cookie */
  567. dma_addr_t phys;
  568. struct dma_chan *chan;
  569. dma_cookie_t (*tx_submit)(struct dma_async_tx_descriptor *tx);
  570. int (*desc_free)(struct dma_async_tx_descriptor *tx);
  571. dma_async_tx_callback callback;
  572. dma_async_tx_callback_result callback_result;
  573. void *callback_param;
  574. struct dmaengine_unmap_data *unmap;
  575. enum dma_desc_metadata_mode desc_metadata_mode;
  576. struct dma_descriptor_metadata_ops *metadata_ops;
  577. #ifdef CONFIG_ASYNC_TX_ENABLE_CHANNEL_SWITCH
  578. struct dma_async_tx_descriptor *next;
  579. struct dma_async_tx_descriptor *parent;
  580. spinlock_t lock;
  581. #endif
  582. ANDROID_KABI_RESERVE(1);
  583. ANDROID_KABI_RESERVE(2);
  584. ANDROID_KABI_RESERVE(3);
  585. ANDROID_KABI_RESERVE(4);
  586. };
  587. #ifdef CONFIG_DMA_ENGINE
  588. static inline void dma_set_unmap(struct dma_async_tx_descriptor *tx,
  589. struct dmaengine_unmap_data *unmap)
  590. {
  591. kref_get(&unmap->kref);
  592. tx->unmap = unmap;
  593. }
  594. struct dmaengine_unmap_data *
  595. dmaengine_get_unmap_data(struct device *dev, int nr, gfp_t flags);
  596. void dmaengine_unmap_put(struct dmaengine_unmap_data *unmap);
  597. #else
  598. static inline void dma_set_unmap(struct dma_async_tx_descriptor *tx,
  599. struct dmaengine_unmap_data *unmap)
  600. {
  601. }
  602. static inline struct dmaengine_unmap_data *
  603. dmaengine_get_unmap_data(struct device *dev, int nr, gfp_t flags)
  604. {
  605. return NULL;
  606. }
  607. static inline void dmaengine_unmap_put(struct dmaengine_unmap_data *unmap)
  608. {
  609. }
  610. #endif
  611. static inline void dma_descriptor_unmap(struct dma_async_tx_descriptor *tx)
  612. {
  613. if (!tx->unmap)
  614. return;
  615. dmaengine_unmap_put(tx->unmap);
  616. tx->unmap = NULL;
  617. }
  618. #ifndef CONFIG_ASYNC_TX_ENABLE_CHANNEL_SWITCH
  619. static inline void txd_lock(struct dma_async_tx_descriptor *txd)
  620. {
  621. }
  622. static inline void txd_unlock(struct dma_async_tx_descriptor *txd)
  623. {
  624. }
  625. static inline void txd_chain(struct dma_async_tx_descriptor *txd, struct dma_async_tx_descriptor *next)
  626. {
  627. BUG();
  628. }
  629. static inline void txd_clear_parent(struct dma_async_tx_descriptor *txd)
  630. {
  631. }
  632. static inline void txd_clear_next(struct dma_async_tx_descriptor *txd)
  633. {
  634. }
  635. static inline struct dma_async_tx_descriptor *txd_next(struct dma_async_tx_descriptor *txd)
  636. {
  637. return NULL;
  638. }
  639. static inline struct dma_async_tx_descriptor *txd_parent(struct dma_async_tx_descriptor *txd)
  640. {
  641. return NULL;
  642. }
  643. #else
  644. static inline void txd_lock(struct dma_async_tx_descriptor *txd)
  645. {
  646. spin_lock_bh(&txd->lock);
  647. }
  648. static inline void txd_unlock(struct dma_async_tx_descriptor *txd)
  649. {
  650. spin_unlock_bh(&txd->lock);
  651. }
  652. static inline void txd_chain(struct dma_async_tx_descriptor *txd, struct dma_async_tx_descriptor *next)
  653. {
  654. txd->next = next;
  655. next->parent = txd;
  656. }
  657. static inline void txd_clear_parent(struct dma_async_tx_descriptor *txd)
  658. {
  659. txd->parent = NULL;
  660. }
  661. static inline void txd_clear_next(struct dma_async_tx_descriptor *txd)
  662. {
  663. txd->next = NULL;
  664. }
  665. static inline struct dma_async_tx_descriptor *txd_parent(struct dma_async_tx_descriptor *txd)
  666. {
  667. return txd->parent;
  668. }
  669. static inline struct dma_async_tx_descriptor *txd_next(struct dma_async_tx_descriptor *txd)
  670. {
  671. return txd->next;
  672. }
  673. #endif
  674. /**
  675. * struct dma_tx_state - filled in to report the status of
  676. * a transfer.
  677. * @last: last completed DMA cookie
  678. * @used: last issued DMA cookie (i.e. the one in progress)
  679. * @residue: the remaining number of bytes left to transmit
  680. * on the selected transfer for states DMA_IN_PROGRESS and
  681. * DMA_PAUSED if this is implemented in the driver, else 0
  682. * @in_flight_bytes: amount of data in bytes cached by the DMA.
  683. */
  684. struct dma_tx_state {
  685. dma_cookie_t last;
  686. dma_cookie_t used;
  687. u32 residue;
  688. u32 in_flight_bytes;
  689. };
  690. /**
  691. * enum dmaengine_alignment - defines alignment of the DMA async tx
  692. * buffers
  693. */
  694. enum dmaengine_alignment {
  695. DMAENGINE_ALIGN_1_BYTE = 0,
  696. DMAENGINE_ALIGN_2_BYTES = 1,
  697. DMAENGINE_ALIGN_4_BYTES = 2,
  698. DMAENGINE_ALIGN_8_BYTES = 3,
  699. DMAENGINE_ALIGN_16_BYTES = 4,
  700. DMAENGINE_ALIGN_32_BYTES = 5,
  701. DMAENGINE_ALIGN_64_BYTES = 6,
  702. DMAENGINE_ALIGN_128_BYTES = 7,
  703. DMAENGINE_ALIGN_256_BYTES = 8,
  704. };
  705. /**
  706. * struct dma_slave_map - associates slave device and it's slave channel with
  707. * parameter to be used by a filter function
  708. * @devname: name of the device
  709. * @slave: slave channel name
  710. * @param: opaque parameter to pass to struct dma_filter.fn
  711. */
  712. struct dma_slave_map {
  713. const char *devname;
  714. const char *slave;
  715. void *param;
  716. };
  717. /**
  718. * struct dma_filter - information for slave device/channel to filter_fn/param
  719. * mapping
  720. * @fn: filter function callback
  721. * @mapcnt: number of slave device/channel in the map
  722. * @map: array of channel to filter mapping data
  723. */
  724. struct dma_filter {
  725. dma_filter_fn fn;
  726. int mapcnt;
  727. const struct dma_slave_map *map;
  728. };
  729. /**
  730. * struct dma_device - info on the entity supplying DMA services
  731. * @chancnt: how many DMA channels are supported
  732. * @privatecnt: how many DMA channels are requested by dma_request_channel
  733. * @channels: the list of struct dma_chan
  734. * @global_node: list_head for global dma_device_list
  735. * @filter: information for device/slave to filter function/param mapping
  736. * @cap_mask: one or more dma_capability flags
  737. * @desc_metadata_modes: supported metadata modes by the DMA device
  738. * @max_xor: maximum number of xor sources, 0 if no capability
  739. * @max_pq: maximum number of PQ sources and PQ-continue capability
  740. * @copy_align: alignment shift for memcpy operations
  741. * @xor_align: alignment shift for xor operations
  742. * @pq_align: alignment shift for pq operations
  743. * @fill_align: alignment shift for memset operations
  744. * @dev_id: unique device ID
  745. * @dev: struct device reference for dma mapping api
  746. * @owner: owner module (automatically set based on the provided dev)
  747. * @src_addr_widths: bit mask of src addr widths the device supports
  748. * Width is specified in bytes, e.g. for a device supporting
  749. * a width of 4 the mask should have BIT(4) set.
  750. * @dst_addr_widths: bit mask of dst addr widths the device supports
  751. * @directions: bit mask of slave directions the device supports.
  752. * Since the enum dma_transfer_direction is not defined as bit flag for
  753. * each type, the dma controller should set BIT(<TYPE>) and same
  754. * should be checked by controller as well
  755. * @min_burst: min burst capability per-transfer
  756. * @max_burst: max burst capability per-transfer
  757. * @max_sg_burst: max number of SG list entries executed in a single burst
  758. * DMA tansaction with no software intervention for reinitialization.
  759. * Zero value means unlimited number of entries.
  760. * @residue_granularity: granularity of the transfer residue reported
  761. * by tx_status
  762. * @device_alloc_chan_resources: allocate resources and return the
  763. * number of allocated descriptors
  764. * @device_router_config: optional callback for DMA router configuration
  765. * @device_free_chan_resources: release DMA channel's resources
  766. * @device_prep_dma_memcpy: prepares a memcpy operation
  767. * @device_prep_dma_xor: prepares a xor operation
  768. * @device_prep_dma_xor_val: prepares a xor validation operation
  769. * @device_prep_dma_pq: prepares a pq operation
  770. * @device_prep_dma_pq_val: prepares a pqzero_sum operation
  771. * @device_prep_dma_memset: prepares a memset operation
  772. * @device_prep_dma_memset_sg: prepares a memset operation over a scatter list
  773. * @device_prep_dma_interrupt: prepares an end of chain interrupt operation
  774. * @device_prep_slave_sg: prepares a slave dma operation
  775. * @device_prep_dma_cyclic: prepare a cyclic dma operation suitable for audio.
  776. * The function takes a buffer of size buf_len. The callback function will
  777. * be called after period_len bytes have been transferred.
  778. * @device_prep_interleaved_dma: Transfer expression in a generic way.
  779. * @device_prep_dma_imm_data: DMA's 8 byte immediate data to the dst address
  780. * @device_caps: May be used to override the generic DMA slave capabilities
  781. * with per-channel specific ones
  782. * @device_config: Pushes a new configuration to a channel, return 0 or an error
  783. * code
  784. * @device_pause: Pauses any transfer happening on a channel. Returns
  785. * 0 or an error code
  786. * @device_resume: Resumes any transfer on a channel previously
  787. * paused. Returns 0 or an error code
  788. * @device_terminate_all: Aborts all transfers on a channel. Returns 0
  789. * or an error code
  790. * @device_synchronize: Synchronizes the termination of a transfers to the
  791. * current context.
  792. * @device_tx_status: poll for transaction completion, the optional
  793. * txstate parameter can be supplied with a pointer to get a
  794. * struct with auxiliary transfer status information, otherwise the call
  795. * will just return a simple status code
  796. * @device_issue_pending: push pending transactions to hardware
  797. * @descriptor_reuse: a submitted transfer can be resubmitted after completion
  798. * @device_release: called sometime atfer dma_async_device_unregister() is
  799. * called and there are no further references to this structure. This
  800. * must be implemented to free resources however many existing drivers
  801. * do not and are therefore not safe to unbind while in use.
  802. * @dbg_summary_show: optional routine to show contents in debugfs; default code
  803. * will be used when this is omitted, but custom code can show extra,
  804. * controller specific information.
  805. */
  806. struct dma_device {
  807. struct kref ref;
  808. unsigned int chancnt;
  809. unsigned int privatecnt;
  810. struct list_head channels;
  811. struct list_head global_node;
  812. struct dma_filter filter;
  813. dma_cap_mask_t cap_mask;
  814. enum dma_desc_metadata_mode desc_metadata_modes;
  815. unsigned short max_xor;
  816. unsigned short max_pq;
  817. enum dmaengine_alignment copy_align;
  818. enum dmaengine_alignment xor_align;
  819. enum dmaengine_alignment pq_align;
  820. enum dmaengine_alignment fill_align;
  821. #define DMA_HAS_PQ_CONTINUE (1 << 15)
  822. int dev_id;
  823. struct device *dev;
  824. struct module *owner;
  825. struct ida chan_ida;
  826. u32 src_addr_widths;
  827. u32 dst_addr_widths;
  828. u32 directions;
  829. u32 min_burst;
  830. u32 max_burst;
  831. u32 max_sg_burst;
  832. bool descriptor_reuse;
  833. enum dma_residue_granularity residue_granularity;
  834. int (*device_alloc_chan_resources)(struct dma_chan *chan);
  835. int (*device_router_config)(struct dma_chan *chan);
  836. void (*device_free_chan_resources)(struct dma_chan *chan);
  837. struct dma_async_tx_descriptor *(*device_prep_dma_memcpy)(
  838. struct dma_chan *chan, dma_addr_t dst, dma_addr_t src,
  839. size_t len, unsigned long flags);
  840. struct dma_async_tx_descriptor *(*device_prep_dma_xor)(
  841. struct dma_chan *chan, dma_addr_t dst, dma_addr_t *src,
  842. unsigned int src_cnt, size_t len, unsigned long flags);
  843. struct dma_async_tx_descriptor *(*device_prep_dma_xor_val)(
  844. struct dma_chan *chan, dma_addr_t *src, unsigned int src_cnt,
  845. size_t len, enum sum_check_flags *result, unsigned long flags);
  846. struct dma_async_tx_descriptor *(*device_prep_dma_pq)(
  847. struct dma_chan *chan, dma_addr_t *dst, dma_addr_t *src,
  848. unsigned int src_cnt, const unsigned char *scf,
  849. size_t len, unsigned long flags);
  850. struct dma_async_tx_descriptor *(*device_prep_dma_pq_val)(
  851. struct dma_chan *chan, dma_addr_t *pq, dma_addr_t *src,
  852. unsigned int src_cnt, const unsigned char *scf, size_t len,
  853. enum sum_check_flags *pqres, unsigned long flags);
  854. struct dma_async_tx_descriptor *(*device_prep_dma_memset)(
  855. struct dma_chan *chan, dma_addr_t dest, int value, size_t len,
  856. unsigned long flags);
  857. struct dma_async_tx_descriptor *(*device_prep_dma_memset_sg)(
  858. struct dma_chan *chan, struct scatterlist *sg,
  859. unsigned int nents, int value, unsigned long flags);
  860. struct dma_async_tx_descriptor *(*device_prep_dma_interrupt)(
  861. struct dma_chan *chan, unsigned long flags);
  862. struct dma_async_tx_descriptor *(*device_prep_slave_sg)(
  863. struct dma_chan *chan, struct scatterlist *sgl,
  864. unsigned int sg_len, enum dma_transfer_direction direction,
  865. unsigned long flags, void *context);
  866. struct dma_async_tx_descriptor *(*device_prep_dma_cyclic)(
  867. struct dma_chan *chan, dma_addr_t buf_addr, size_t buf_len,
  868. size_t period_len, enum dma_transfer_direction direction,
  869. unsigned long flags);
  870. struct dma_async_tx_descriptor *(*device_prep_interleaved_dma)(
  871. struct dma_chan *chan, struct dma_interleaved_template *xt,
  872. unsigned long flags);
  873. struct dma_async_tx_descriptor *(*device_prep_dma_imm_data)(
  874. struct dma_chan *chan, dma_addr_t dst, u64 data,
  875. unsigned long flags);
  876. void (*device_caps)(struct dma_chan *chan,
  877. struct dma_slave_caps *caps);
  878. int (*device_config)(struct dma_chan *chan,
  879. struct dma_slave_config *config);
  880. int (*device_pause)(struct dma_chan *chan);
  881. int (*device_resume)(struct dma_chan *chan);
  882. int (*device_terminate_all)(struct dma_chan *chan);
  883. void (*device_synchronize)(struct dma_chan *chan);
  884. enum dma_status (*device_tx_status)(struct dma_chan *chan,
  885. dma_cookie_t cookie,
  886. struct dma_tx_state *txstate);
  887. void (*device_issue_pending)(struct dma_chan *chan);
  888. void (*device_release)(struct dma_device *dev);
  889. /* debugfs support */
  890. void (*dbg_summary_show)(struct seq_file *s, struct dma_device *dev);
  891. struct dentry *dbg_dev_root;
  892. };
  893. static inline int dmaengine_slave_config(struct dma_chan *chan,
  894. struct dma_slave_config *config)
  895. {
  896. if (chan->device->device_config)
  897. return chan->device->device_config(chan, config);
  898. return -ENOSYS;
  899. }
  900. static inline bool is_slave_direction(enum dma_transfer_direction direction)
  901. {
  902. return (direction == DMA_MEM_TO_DEV) || (direction == DMA_DEV_TO_MEM);
  903. }
  904. static inline struct dma_async_tx_descriptor *dmaengine_prep_slave_single(
  905. struct dma_chan *chan, dma_addr_t buf, size_t len,
  906. enum dma_transfer_direction dir, unsigned long flags)
  907. {
  908. struct scatterlist sg;
  909. sg_init_table(&sg, 1);
  910. sg_dma_address(&sg) = buf;
  911. sg_dma_len(&sg) = len;
  912. if (!chan || !chan->device || !chan->device->device_prep_slave_sg)
  913. return NULL;
  914. return chan->device->device_prep_slave_sg(chan, &sg, 1,
  915. dir, flags, NULL);
  916. }
  917. static inline struct dma_async_tx_descriptor *dmaengine_prep_slave_sg(
  918. struct dma_chan *chan, struct scatterlist *sgl, unsigned int sg_len,
  919. enum dma_transfer_direction dir, unsigned long flags)
  920. {
  921. if (!chan || !chan->device || !chan->device->device_prep_slave_sg)
  922. return NULL;
  923. return chan->device->device_prep_slave_sg(chan, sgl, sg_len,
  924. dir, flags, NULL);
  925. }
  926. #ifdef CONFIG_RAPIDIO_DMA_ENGINE
  927. struct rio_dma_ext;
  928. static inline struct dma_async_tx_descriptor *dmaengine_prep_rio_sg(
  929. struct dma_chan *chan, struct scatterlist *sgl, unsigned int sg_len,
  930. enum dma_transfer_direction dir, unsigned long flags,
  931. struct rio_dma_ext *rio_ext)
  932. {
  933. if (!chan || !chan->device || !chan->device->device_prep_slave_sg)
  934. return NULL;
  935. return chan->device->device_prep_slave_sg(chan, sgl, sg_len,
  936. dir, flags, rio_ext);
  937. }
  938. #endif
  939. static inline struct dma_async_tx_descriptor *dmaengine_prep_dma_cyclic(
  940. struct dma_chan *chan, dma_addr_t buf_addr, size_t buf_len,
  941. size_t period_len, enum dma_transfer_direction dir,
  942. unsigned long flags)
  943. {
  944. if (!chan || !chan->device || !chan->device->device_prep_dma_cyclic)
  945. return NULL;
  946. return chan->device->device_prep_dma_cyclic(chan, buf_addr, buf_len,
  947. period_len, dir, flags);
  948. }
  949. static inline struct dma_async_tx_descriptor *dmaengine_prep_interleaved_dma(
  950. struct dma_chan *chan, struct dma_interleaved_template *xt,
  951. unsigned long flags)
  952. {
  953. if (!chan || !chan->device || !chan->device->device_prep_interleaved_dma)
  954. return NULL;
  955. if (flags & DMA_PREP_REPEAT &&
  956. !test_bit(DMA_REPEAT, chan->device->cap_mask.bits))
  957. return NULL;
  958. return chan->device->device_prep_interleaved_dma(chan, xt, flags);
  959. }
  960. /**
  961. * dmaengine_prep_dma_memset() - Prepare a DMA memset descriptor.
  962. * @chan: The channel to be used for this descriptor
  963. * @dest: Address of buffer to be set
  964. * @value: Treated as a single byte value that fills the destination buffer
  965. * @len: The total size of dest
  966. * @flags: DMA engine flags
  967. */
  968. static inline struct dma_async_tx_descriptor *dmaengine_prep_dma_memset(
  969. struct dma_chan *chan, dma_addr_t dest, int value, size_t len,
  970. unsigned long flags)
  971. {
  972. if (!chan || !chan->device || !chan->device->device_prep_dma_memset)
  973. return NULL;
  974. return chan->device->device_prep_dma_memset(chan, dest, value,
  975. len, flags);
  976. }
  977. static inline struct dma_async_tx_descriptor *dmaengine_prep_dma_memcpy(
  978. struct dma_chan *chan, dma_addr_t dest, dma_addr_t src,
  979. size_t len, unsigned long flags)
  980. {
  981. if (!chan || !chan->device || !chan->device->device_prep_dma_memcpy)
  982. return NULL;
  983. return chan->device->device_prep_dma_memcpy(chan, dest, src,
  984. len, flags);
  985. }
  986. static inline bool dmaengine_is_metadata_mode_supported(struct dma_chan *chan,
  987. enum dma_desc_metadata_mode mode)
  988. {
  989. if (!chan)
  990. return false;
  991. return !!(chan->device->desc_metadata_modes & mode);
  992. }
  993. #ifdef CONFIG_DMA_ENGINE
  994. int dmaengine_desc_attach_metadata(struct dma_async_tx_descriptor *desc,
  995. void *data, size_t len);
  996. void *dmaengine_desc_get_metadata_ptr(struct dma_async_tx_descriptor *desc,
  997. size_t *payload_len, size_t *max_len);
  998. int dmaengine_desc_set_metadata_len(struct dma_async_tx_descriptor *desc,
  999. size_t payload_len);
  1000. #else /* CONFIG_DMA_ENGINE */
  1001. static inline int dmaengine_desc_attach_metadata(
  1002. struct dma_async_tx_descriptor *desc, void *data, size_t len)
  1003. {
  1004. return -EINVAL;
  1005. }
  1006. static inline void *dmaengine_desc_get_metadata_ptr(
  1007. struct dma_async_tx_descriptor *desc, size_t *payload_len,
  1008. size_t *max_len)
  1009. {
  1010. return NULL;
  1011. }
  1012. static inline int dmaengine_desc_set_metadata_len(
  1013. struct dma_async_tx_descriptor *desc, size_t payload_len)
  1014. {
  1015. return -EINVAL;
  1016. }
  1017. #endif /* CONFIG_DMA_ENGINE */
  1018. /**
  1019. * dmaengine_terminate_all() - Terminate all active DMA transfers
  1020. * @chan: The channel for which to terminate the transfers
  1021. *
  1022. * This function is DEPRECATED use either dmaengine_terminate_sync() or
  1023. * dmaengine_terminate_async() instead.
  1024. */
  1025. static inline int dmaengine_terminate_all(struct dma_chan *chan)
  1026. {
  1027. if (chan->device->device_terminate_all)
  1028. return chan->device->device_terminate_all(chan);
  1029. return -ENOSYS;
  1030. }
  1031. /**
  1032. * dmaengine_terminate_async() - Terminate all active DMA transfers
  1033. * @chan: The channel for which to terminate the transfers
  1034. *
  1035. * Calling this function will terminate all active and pending descriptors
  1036. * that have previously been submitted to the channel. It is not guaranteed
  1037. * though that the transfer for the active descriptor has stopped when the
  1038. * function returns. Furthermore it is possible the complete callback of a
  1039. * submitted transfer is still running when this function returns.
  1040. *
  1041. * dmaengine_synchronize() needs to be called before it is safe to free
  1042. * any memory that is accessed by previously submitted descriptors or before
  1043. * freeing any resources accessed from within the completion callback of any
  1044. * previously submitted descriptors.
  1045. *
  1046. * This function can be called from atomic context as well as from within a
  1047. * complete callback of a descriptor submitted on the same channel.
  1048. *
  1049. * If none of the two conditions above apply consider using
  1050. * dmaengine_terminate_sync() instead.
  1051. */
  1052. static inline int dmaengine_terminate_async(struct dma_chan *chan)
  1053. {
  1054. if (chan->device->device_terminate_all)
  1055. return chan->device->device_terminate_all(chan);
  1056. return -EINVAL;
  1057. }
  1058. /**
  1059. * dmaengine_synchronize() - Synchronize DMA channel termination
  1060. * @chan: The channel to synchronize
  1061. *
  1062. * Synchronizes to the DMA channel termination to the current context. When this
  1063. * function returns it is guaranteed that all transfers for previously issued
  1064. * descriptors have stopped and it is safe to free the memory associated
  1065. * with them. Furthermore it is guaranteed that all complete callback functions
  1066. * for a previously submitted descriptor have finished running and it is safe to
  1067. * free resources accessed from within the complete callbacks.
  1068. *
  1069. * The behavior of this function is undefined if dma_async_issue_pending() has
  1070. * been called between dmaengine_terminate_async() and this function.
  1071. *
  1072. * This function must only be called from non-atomic context and must not be
  1073. * called from within a complete callback of a descriptor submitted on the same
  1074. * channel.
  1075. */
  1076. static inline void dmaengine_synchronize(struct dma_chan *chan)
  1077. {
  1078. might_sleep();
  1079. if (chan->device->device_synchronize)
  1080. chan->device->device_synchronize(chan);
  1081. }
  1082. /**
  1083. * dmaengine_terminate_sync() - Terminate all active DMA transfers
  1084. * @chan: The channel for which to terminate the transfers
  1085. *
  1086. * Calling this function will terminate all active and pending transfers
  1087. * that have previously been submitted to the channel. It is similar to
  1088. * dmaengine_terminate_async() but guarantees that the DMA transfer has actually
  1089. * stopped and that all complete callbacks have finished running when the
  1090. * function returns.
  1091. *
  1092. * This function must only be called from non-atomic context and must not be
  1093. * called from within a complete callback of a descriptor submitted on the same
  1094. * channel.
  1095. */
  1096. static inline int dmaengine_terminate_sync(struct dma_chan *chan)
  1097. {
  1098. int ret;
  1099. ret = dmaengine_terminate_async(chan);
  1100. if (ret)
  1101. return ret;
  1102. dmaengine_synchronize(chan);
  1103. return 0;
  1104. }
  1105. static inline int dmaengine_pause(struct dma_chan *chan)
  1106. {
  1107. if (chan->device->device_pause)
  1108. return chan->device->device_pause(chan);
  1109. return -ENOSYS;
  1110. }
  1111. static inline int dmaengine_resume(struct dma_chan *chan)
  1112. {
  1113. if (chan->device->device_resume)
  1114. return chan->device->device_resume(chan);
  1115. return -ENOSYS;
  1116. }
  1117. static inline enum dma_status dmaengine_tx_status(struct dma_chan *chan,
  1118. dma_cookie_t cookie, struct dma_tx_state *state)
  1119. {
  1120. return chan->device->device_tx_status(chan, cookie, state);
  1121. }
  1122. static inline dma_cookie_t dmaengine_submit(struct dma_async_tx_descriptor *desc)
  1123. {
  1124. return desc->tx_submit(desc);
  1125. }
  1126. static inline bool dmaengine_check_align(enum dmaengine_alignment align,
  1127. size_t off1, size_t off2, size_t len)
  1128. {
  1129. return !(((1 << align) - 1) & (off1 | off2 | len));
  1130. }
  1131. static inline bool is_dma_copy_aligned(struct dma_device *dev, size_t off1,
  1132. size_t off2, size_t len)
  1133. {
  1134. return dmaengine_check_align(dev->copy_align, off1, off2, len);
  1135. }
  1136. static inline bool is_dma_xor_aligned(struct dma_device *dev, size_t off1,
  1137. size_t off2, size_t len)
  1138. {
  1139. return dmaengine_check_align(dev->xor_align, off1, off2, len);
  1140. }
  1141. static inline bool is_dma_pq_aligned(struct dma_device *dev, size_t off1,
  1142. size_t off2, size_t len)
  1143. {
  1144. return dmaengine_check_align(dev->pq_align, off1, off2, len);
  1145. }
  1146. static inline bool is_dma_fill_aligned(struct dma_device *dev, size_t off1,
  1147. size_t off2, size_t len)
  1148. {
  1149. return dmaengine_check_align(dev->fill_align, off1, off2, len);
  1150. }
  1151. static inline void
  1152. dma_set_maxpq(struct dma_device *dma, int maxpq, int has_pq_continue)
  1153. {
  1154. dma->max_pq = maxpq;
  1155. if (has_pq_continue)
  1156. dma->max_pq |= DMA_HAS_PQ_CONTINUE;
  1157. }
  1158. static inline bool dmaf_continue(enum dma_ctrl_flags flags)
  1159. {
  1160. return (flags & DMA_PREP_CONTINUE) == DMA_PREP_CONTINUE;
  1161. }
  1162. static inline bool dmaf_p_disabled_continue(enum dma_ctrl_flags flags)
  1163. {
  1164. enum dma_ctrl_flags mask = DMA_PREP_CONTINUE | DMA_PREP_PQ_DISABLE_P;
  1165. return (flags & mask) == mask;
  1166. }
  1167. static inline bool dma_dev_has_pq_continue(struct dma_device *dma)
  1168. {
  1169. return (dma->max_pq & DMA_HAS_PQ_CONTINUE) == DMA_HAS_PQ_CONTINUE;
  1170. }
  1171. static inline unsigned short dma_dev_to_maxpq(struct dma_device *dma)
  1172. {
  1173. return dma->max_pq & ~DMA_HAS_PQ_CONTINUE;
  1174. }
  1175. /* dma_maxpq - reduce maxpq in the face of continued operations
  1176. * @dma - dma device with PQ capability
  1177. * @flags - to check if DMA_PREP_CONTINUE and DMA_PREP_PQ_DISABLE_P are set
  1178. *
  1179. * When an engine does not support native continuation we need 3 extra
  1180. * source slots to reuse P and Q with the following coefficients:
  1181. * 1/ {00} * P : remove P from Q', but use it as a source for P'
  1182. * 2/ {01} * Q : use Q to continue Q' calculation
  1183. * 3/ {00} * Q : subtract Q from P' to cancel (2)
  1184. *
  1185. * In the case where P is disabled we only need 1 extra source:
  1186. * 1/ {01} * Q : use Q to continue Q' calculation
  1187. */
  1188. static inline int dma_maxpq(struct dma_device *dma, enum dma_ctrl_flags flags)
  1189. {
  1190. if (dma_dev_has_pq_continue(dma) || !dmaf_continue(flags))
  1191. return dma_dev_to_maxpq(dma);
  1192. if (dmaf_p_disabled_continue(flags))
  1193. return dma_dev_to_maxpq(dma) - 1;
  1194. if (dmaf_continue(flags))
  1195. return dma_dev_to_maxpq(dma) - 3;
  1196. BUG();
  1197. }
  1198. static inline size_t dmaengine_get_icg(bool inc, bool sgl, size_t icg,
  1199. size_t dir_icg)
  1200. {
  1201. if (inc) {
  1202. if (dir_icg)
  1203. return dir_icg;
  1204. if (sgl)
  1205. return icg;
  1206. }
  1207. return 0;
  1208. }
  1209. static inline size_t dmaengine_get_dst_icg(struct dma_interleaved_template *xt,
  1210. struct data_chunk *chunk)
  1211. {
  1212. return dmaengine_get_icg(xt->dst_inc, xt->dst_sgl,
  1213. chunk->icg, chunk->dst_icg);
  1214. }
  1215. static inline size_t dmaengine_get_src_icg(struct dma_interleaved_template *xt,
  1216. struct data_chunk *chunk)
  1217. {
  1218. return dmaengine_get_icg(xt->src_inc, xt->src_sgl,
  1219. chunk->icg, chunk->src_icg);
  1220. }
  1221. /* --- public DMA engine API --- */
  1222. #ifdef CONFIG_DMA_ENGINE
  1223. void dmaengine_get(void);
  1224. void dmaengine_put(void);
  1225. #else
  1226. static inline void dmaengine_get(void)
  1227. {
  1228. }
  1229. static inline void dmaengine_put(void)
  1230. {
  1231. }
  1232. #endif
  1233. #ifdef CONFIG_ASYNC_TX_DMA
  1234. #define async_dmaengine_get() dmaengine_get()
  1235. #define async_dmaengine_put() dmaengine_put()
  1236. #ifndef CONFIG_ASYNC_TX_ENABLE_CHANNEL_SWITCH
  1237. #define async_dma_find_channel(type) dma_find_channel(DMA_ASYNC_TX)
  1238. #else
  1239. #define async_dma_find_channel(type) dma_find_channel(type)
  1240. #endif /* CONFIG_ASYNC_TX_ENABLE_CHANNEL_SWITCH */
  1241. #else
  1242. static inline void async_dmaengine_get(void)
  1243. {
  1244. }
  1245. static inline void async_dmaengine_put(void)
  1246. {
  1247. }
  1248. static inline struct dma_chan *
  1249. async_dma_find_channel(enum dma_transaction_type type)
  1250. {
  1251. return NULL;
  1252. }
  1253. #endif /* CONFIG_ASYNC_TX_DMA */
  1254. void dma_async_tx_descriptor_init(struct dma_async_tx_descriptor *tx,
  1255. struct dma_chan *chan);
  1256. static inline void async_tx_ack(struct dma_async_tx_descriptor *tx)
  1257. {
  1258. tx->flags |= DMA_CTRL_ACK;
  1259. }
  1260. static inline void async_tx_clear_ack(struct dma_async_tx_descriptor *tx)
  1261. {
  1262. tx->flags &= ~DMA_CTRL_ACK;
  1263. }
  1264. static inline bool async_tx_test_ack(struct dma_async_tx_descriptor *tx)
  1265. {
  1266. return (tx->flags & DMA_CTRL_ACK) == DMA_CTRL_ACK;
  1267. }
  1268. #define dma_cap_set(tx, mask) __dma_cap_set((tx), &(mask))
  1269. static inline void
  1270. __dma_cap_set(enum dma_transaction_type tx_type, dma_cap_mask_t *dstp)
  1271. {
  1272. set_bit(tx_type, dstp->bits);
  1273. }
  1274. #define dma_cap_clear(tx, mask) __dma_cap_clear((tx), &(mask))
  1275. static inline void
  1276. __dma_cap_clear(enum dma_transaction_type tx_type, dma_cap_mask_t *dstp)
  1277. {
  1278. clear_bit(tx_type, dstp->bits);
  1279. }
  1280. #define dma_cap_zero(mask) __dma_cap_zero(&(mask))
  1281. static inline void __dma_cap_zero(dma_cap_mask_t *dstp)
  1282. {
  1283. bitmap_zero(dstp->bits, DMA_TX_TYPE_END);
  1284. }
  1285. #define dma_has_cap(tx, mask) __dma_has_cap((tx), &(mask))
  1286. static inline int
  1287. __dma_has_cap(enum dma_transaction_type tx_type, dma_cap_mask_t *srcp)
  1288. {
  1289. return test_bit(tx_type, srcp->bits);
  1290. }
  1291. #define for_each_dma_cap_mask(cap, mask) \
  1292. for_each_set_bit(cap, mask.bits, DMA_TX_TYPE_END)
  1293. /**
  1294. * dma_async_issue_pending - flush pending transactions to HW
  1295. * @chan: target DMA channel
  1296. *
  1297. * This allows drivers to push copies to HW in batches,
  1298. * reducing MMIO writes where possible.
  1299. */
  1300. static inline void dma_async_issue_pending(struct dma_chan *chan)
  1301. {
  1302. chan->device->device_issue_pending(chan);
  1303. }
  1304. /**
  1305. * dma_async_is_tx_complete - poll for transaction completion
  1306. * @chan: DMA channel
  1307. * @cookie: transaction identifier to check status of
  1308. * @last: returns last completed cookie, can be NULL
  1309. * @used: returns last issued cookie, can be NULL
  1310. *
  1311. * If @last and @used are passed in, upon return they reflect the driver
  1312. * internal state and can be used with dma_async_is_complete() to check
  1313. * the status of multiple cookies without re-checking hardware state.
  1314. */
  1315. static inline enum dma_status dma_async_is_tx_complete(struct dma_chan *chan,
  1316. dma_cookie_t cookie, dma_cookie_t *last, dma_cookie_t *used)
  1317. {
  1318. struct dma_tx_state state;
  1319. enum dma_status status;
  1320. status = chan->device->device_tx_status(chan, cookie, &state);
  1321. if (last)
  1322. *last = state.last;
  1323. if (used)
  1324. *used = state.used;
  1325. return status;
  1326. }
  1327. /**
  1328. * dma_async_is_complete - test a cookie against chan state
  1329. * @cookie: transaction identifier to test status of
  1330. * @last_complete: last know completed transaction
  1331. * @last_used: last cookie value handed out
  1332. *
  1333. * dma_async_is_complete() is used in dma_async_is_tx_complete()
  1334. * the test logic is separated for lightweight testing of multiple cookies
  1335. */
  1336. static inline enum dma_status dma_async_is_complete(dma_cookie_t cookie,
  1337. dma_cookie_t last_complete, dma_cookie_t last_used)
  1338. {
  1339. if (last_complete <= last_used) {
  1340. if ((cookie <= last_complete) || (cookie > last_used))
  1341. return DMA_COMPLETE;
  1342. } else {
  1343. if ((cookie <= last_complete) && (cookie > last_used))
  1344. return DMA_COMPLETE;
  1345. }
  1346. return DMA_IN_PROGRESS;
  1347. }
  1348. static inline void
  1349. dma_set_tx_state(struct dma_tx_state *st, dma_cookie_t last, dma_cookie_t used, u32 residue)
  1350. {
  1351. if (!st)
  1352. return;
  1353. st->last = last;
  1354. st->used = used;
  1355. st->residue = residue;
  1356. }
  1357. #ifdef CONFIG_DMA_ENGINE
  1358. struct dma_chan *dma_find_channel(enum dma_transaction_type tx_type);
  1359. enum dma_status dma_sync_wait(struct dma_chan *chan, dma_cookie_t cookie);
  1360. enum dma_status dma_wait_for_async_tx(struct dma_async_tx_descriptor *tx);
  1361. void dma_issue_pending_all(void);
  1362. struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask,
  1363. dma_filter_fn fn, void *fn_param,
  1364. struct device_node *np);
  1365. struct dma_chan *dma_request_chan(struct device *dev, const char *name);
  1366. struct dma_chan *dma_request_chan_by_mask(const dma_cap_mask_t *mask);
  1367. void dma_release_channel(struct dma_chan *chan);
  1368. int dma_get_slave_caps(struct dma_chan *chan, struct dma_slave_caps *caps);
  1369. #else
  1370. static inline struct dma_chan *dma_find_channel(enum dma_transaction_type tx_type)
  1371. {
  1372. return NULL;
  1373. }
  1374. static inline enum dma_status dma_sync_wait(struct dma_chan *chan, dma_cookie_t cookie)
  1375. {
  1376. return DMA_COMPLETE;
  1377. }
  1378. static inline enum dma_status dma_wait_for_async_tx(struct dma_async_tx_descriptor *tx)
  1379. {
  1380. return DMA_COMPLETE;
  1381. }
  1382. static inline void dma_issue_pending_all(void)
  1383. {
  1384. }
  1385. static inline struct dma_chan *__dma_request_channel(const dma_cap_mask_t *mask,
  1386. dma_filter_fn fn,
  1387. void *fn_param,
  1388. struct device_node *np)
  1389. {
  1390. return NULL;
  1391. }
  1392. static inline struct dma_chan *dma_request_chan(struct device *dev,
  1393. const char *name)
  1394. {
  1395. return ERR_PTR(-ENODEV);
  1396. }
  1397. static inline struct dma_chan *dma_request_chan_by_mask(
  1398. const dma_cap_mask_t *mask)
  1399. {
  1400. return ERR_PTR(-ENODEV);
  1401. }
  1402. static inline void dma_release_channel(struct dma_chan *chan)
  1403. {
  1404. }
  1405. static inline int dma_get_slave_caps(struct dma_chan *chan,
  1406. struct dma_slave_caps *caps)
  1407. {
  1408. return -ENXIO;
  1409. }
  1410. #endif
  1411. static inline int dmaengine_desc_set_reuse(struct dma_async_tx_descriptor *tx)
  1412. {
  1413. struct dma_slave_caps caps;
  1414. int ret;
  1415. ret = dma_get_slave_caps(tx->chan, &caps);
  1416. if (ret)
  1417. return ret;
  1418. if (!caps.descriptor_reuse)
  1419. return -EPERM;
  1420. tx->flags |= DMA_CTRL_REUSE;
  1421. return 0;
  1422. }
  1423. static inline void dmaengine_desc_clear_reuse(struct dma_async_tx_descriptor *tx)
  1424. {
  1425. tx->flags &= ~DMA_CTRL_REUSE;
  1426. }
  1427. static inline bool dmaengine_desc_test_reuse(struct dma_async_tx_descriptor *tx)
  1428. {
  1429. return (tx->flags & DMA_CTRL_REUSE) == DMA_CTRL_REUSE;
  1430. }
  1431. static inline int dmaengine_desc_free(struct dma_async_tx_descriptor *desc)
  1432. {
  1433. /* this is supported for reusable desc, so check that */
  1434. if (!dmaengine_desc_test_reuse(desc))
  1435. return -EPERM;
  1436. return desc->desc_free(desc);
  1437. }
  1438. /* --- DMA device --- */
  1439. int dma_async_device_register(struct dma_device *device);
  1440. int dmaenginem_async_device_register(struct dma_device *device);
  1441. void dma_async_device_unregister(struct dma_device *device);
  1442. int dma_async_device_channel_register(struct dma_device *device,
  1443. struct dma_chan *chan);
  1444. void dma_async_device_channel_unregister(struct dma_device *device,
  1445. struct dma_chan *chan);
  1446. void dma_run_dependencies(struct dma_async_tx_descriptor *tx);
  1447. #define dma_request_channel(mask, x, y) \
  1448. __dma_request_channel(&(mask), x, y, NULL)
  1449. /* Deprecated, please use dma_request_chan() directly */
  1450. static inline struct dma_chan * __deprecated
  1451. dma_request_slave_channel(struct device *dev, const char *name)
  1452. {
  1453. struct dma_chan *ch = dma_request_chan(dev, name);
  1454. return IS_ERR(ch) ? NULL : ch;
  1455. }
  1456. static inline struct dma_chan
  1457. *dma_request_slave_channel_compat(const dma_cap_mask_t mask,
  1458. dma_filter_fn fn, void *fn_param,
  1459. struct device *dev, const char *name)
  1460. {
  1461. struct dma_chan *chan;
  1462. chan = dma_request_slave_channel(dev, name);
  1463. if (chan)
  1464. return chan;
  1465. if (!fn || !fn_param)
  1466. return NULL;
  1467. return __dma_request_channel(&mask, fn, fn_param, NULL);
  1468. }
  1469. static inline char *
  1470. dmaengine_get_direction_text(enum dma_transfer_direction dir)
  1471. {
  1472. switch (dir) {
  1473. case DMA_DEV_TO_MEM:
  1474. return "DEV_TO_MEM";
  1475. case DMA_MEM_TO_DEV:
  1476. return "MEM_TO_DEV";
  1477. case DMA_MEM_TO_MEM:
  1478. return "MEM_TO_MEM";
  1479. case DMA_DEV_TO_DEV:
  1480. return "DEV_TO_DEV";
  1481. default:
  1482. return "invalid";
  1483. }
  1484. }
  1485. static inline struct device *dmaengine_get_dma_device(struct dma_chan *chan)
  1486. {
  1487. if (chan->dev->chan_dma_dev)
  1488. return &chan->dev->device;
  1489. return chan->device->dev;
  1490. }
  1491. #endif /* DMAENGINE_H */