dma.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. /*****************************************************************************
  2. * Copyright 2004 - 2008 Broadcom Corporation. All rights reserved.
  3. *
  4. * Unless you and Broadcom execute a separate written software license
  5. * agreement governing use of this software, this software is licensed to you
  6. * under the terms of the GNU General Public License version 2, available at
  7. * http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  8. *
  9. * Notwithstanding the above, under no circumstances may you combine this
  10. * software in any way with any other Broadcom software provided under a
  11. * license other than the GPL, without Broadcom's express prior written
  12. * consent.
  13. *****************************************************************************/
  14. /****************************************************************************/
  15. /**
  16. * @file dma.h
  17. *
  18. * @brief API definitions for the linux DMA interface.
  19. */
  20. /****************************************************************************/
  21. #if !defined(ASM_ARM_ARCH_BCMRING_DMA_H)
  22. #define ASM_ARM_ARCH_BCMRING_DMA_H
  23. /* ---- Include Files ---------------------------------------------------- */
  24. #include <linux/kernel.h>
  25. #include <linux/semaphore.h>
  26. #include <csp/dmacHw.h>
  27. #include <mach/timer.h>
  28. /* ---- Constants and Types ---------------------------------------------- */
  29. /* If DMA_DEBUG_TRACK_RESERVATION is set to a non-zero value, then the filename */
  30. /* and line number of the reservation request will be recorded in the channel table */
  31. #define DMA_DEBUG_TRACK_RESERVATION 1
  32. #define DMA_NUM_CONTROLLERS 2
  33. #define DMA_NUM_CHANNELS 8 /* per controller */
  34. typedef enum {
  35. DMA_DEVICE_MEM_TO_MEM, /* For memory to memory transfers */
  36. DMA_DEVICE_I2S0_DEV_TO_MEM,
  37. DMA_DEVICE_I2S0_MEM_TO_DEV,
  38. DMA_DEVICE_I2S1_DEV_TO_MEM,
  39. DMA_DEVICE_I2S1_MEM_TO_DEV,
  40. DMA_DEVICE_APM_CODEC_A_DEV_TO_MEM,
  41. DMA_DEVICE_APM_CODEC_A_MEM_TO_DEV,
  42. DMA_DEVICE_APM_CODEC_B_DEV_TO_MEM,
  43. DMA_DEVICE_APM_CODEC_B_MEM_TO_DEV,
  44. DMA_DEVICE_APM_CODEC_C_DEV_TO_MEM, /* Additional mic input for beam-forming */
  45. DMA_DEVICE_APM_PCM0_DEV_TO_MEM,
  46. DMA_DEVICE_APM_PCM0_MEM_TO_DEV,
  47. DMA_DEVICE_APM_PCM1_DEV_TO_MEM,
  48. DMA_DEVICE_APM_PCM1_MEM_TO_DEV,
  49. DMA_DEVICE_SPUM_DEV_TO_MEM,
  50. DMA_DEVICE_SPUM_MEM_TO_DEV,
  51. DMA_DEVICE_SPIH_DEV_TO_MEM,
  52. DMA_DEVICE_SPIH_MEM_TO_DEV,
  53. DMA_DEVICE_UART_A_DEV_TO_MEM,
  54. DMA_DEVICE_UART_A_MEM_TO_DEV,
  55. DMA_DEVICE_UART_B_DEV_TO_MEM,
  56. DMA_DEVICE_UART_B_MEM_TO_DEV,
  57. DMA_DEVICE_PIF_MEM_TO_DEV,
  58. DMA_DEVICE_PIF_DEV_TO_MEM,
  59. DMA_DEVICE_ESW_DEV_TO_MEM,
  60. DMA_DEVICE_ESW_MEM_TO_DEV,
  61. DMA_DEVICE_VPM_MEM_TO_MEM,
  62. DMA_DEVICE_CLCD_MEM_TO_MEM,
  63. DMA_DEVICE_NAND_MEM_TO_MEM,
  64. DMA_DEVICE_MEM_TO_VRAM,
  65. DMA_DEVICE_VRAM_TO_MEM,
  66. /* Add new entries before this line. */
  67. DMA_NUM_DEVICE_ENTRIES,
  68. DMA_DEVICE_NONE = 0xff, /* Special value to indicate that no device is currently assigned. */
  69. } DMA_Device_t;
  70. /****************************************************************************
  71. *
  72. * The DMA_Handle_t is the primary object used by callers of the API.
  73. *
  74. *****************************************************************************/
  75. #define DMA_INVALID_HANDLE ((DMA_Handle_t) -1)
  76. typedef int DMA_Handle_t;
  77. /****************************************************************************
  78. *
  79. * The DMA_DescriptorRing_t contains a ring of descriptors which is used
  80. * to point to regions of memory.
  81. *
  82. *****************************************************************************/
  83. typedef struct {
  84. void *virtAddr; /* Virtual Address of the descriptor ring */
  85. dma_addr_t physAddr; /* Physical address of the descriptor ring */
  86. int descriptorsAllocated; /* Number of descriptors allocated in the descriptor ring */
  87. size_t bytesAllocated; /* Number of bytes allocated in the descriptor ring */
  88. } DMA_DescriptorRing_t;
  89. /****************************************************************************
  90. *
  91. * The DMA_DeviceAttribute_t contains information which describes a
  92. * particular DMA device (or peripheral).
  93. *
  94. * It is anticipated that the arrary of DMA_DeviceAttribute_t's will be
  95. * statically initialized.
  96. *
  97. *****************************************************************************/
  98. /* The device handler is called whenever a DMA operation completes. The reaon */
  99. /* for it to be called will be a bitmask with one or more of the following bits */
  100. /* set. */
  101. #define DMA_HANDLER_REASON_BLOCK_COMPLETE dmacHw_INTERRUPT_STATUS_BLOCK
  102. #define DMA_HANDLER_REASON_TRANSFER_COMPLETE dmacHw_INTERRUPT_STATUS_TRANS
  103. #define DMA_HANDLER_REASON_ERROR dmacHw_INTERRUPT_STATUS_ERROR
  104. typedef void (*DMA_DeviceHandler_t) (DMA_Device_t dev, int reason,
  105. void *userData);
  106. #define DMA_DEVICE_FLAG_ON_DMA0 0x00000001
  107. #define DMA_DEVICE_FLAG_ON_DMA1 0x00000002
  108. #define DMA_DEVICE_FLAG_PORT_PER_DMAC 0x00000004 /* If set, it means that the port used on DMAC0 is different from the port used on DMAC1 */
  109. #define DMA_DEVICE_FLAG_ALLOC_DMA1_FIRST 0x00000008 /* If set, allocate from DMA1 before allocating from DMA0 */
  110. #define DMA_DEVICE_FLAG_IS_DEDICATED 0x00000100
  111. #define DMA_DEVICE_FLAG_NO_ISR 0x00000200
  112. #define DMA_DEVICE_FLAG_ALLOW_LARGE_FIFO 0x00000400
  113. #define DMA_DEVICE_FLAG_IN_USE 0x00000800 /* If set, device is in use on a channel */
  114. /* Note: Some DMA devices can be used from multiple DMA Controllers. The bitmask is used to */
  115. /* determine which DMA controllers a given device can be used from, and the interface */
  116. /* array determeines the actual interface number to use for a given controller. */
  117. typedef struct {
  118. uint32_t flags; /* Bitmask of DMA_DEVICE_FLAG_xxx constants */
  119. uint8_t dedicatedController; /* Controller number to use if DMA_DEVICE_FLAG_IS_DEDICATED is set. */
  120. uint8_t dedicatedChannel; /* Channel number to use if DMA_DEVICE_FLAG_IS_DEDICATED is set. */
  121. const char *name; /* Will show up in the /proc entry */
  122. uint32_t dmacPort[DMA_NUM_CONTROLLERS]; /* Specifies the port number when DMA_DEVICE_FLAG_PORT_PER_DMAC flag is set */
  123. dmacHw_CONFIG_t config; /* Configuration to use when DMA'ing using this device */
  124. void *userData; /* Passed to the devHandler */
  125. DMA_DeviceHandler_t devHandler; /* Called when DMA operations finish. */
  126. timer_tick_count_t transferStartTime; /* Time the current transfer was started */
  127. /* The following statistical information will be collected and presented in a proc entry. */
  128. /* Note: With a contiuous bandwidth of 1 Gb/sec, it would take 584 years to overflow */
  129. /* a 64 bit counter. */
  130. uint64_t numTransfers; /* Number of DMA transfers performed */
  131. uint64_t transferTicks; /* Total time spent doing DMA transfers (measured in timer_tick_count_t's) */
  132. uint64_t transferBytes; /* Total bytes transferred */
  133. uint32_t timesBlocked; /* Number of times a channel was unavailable */
  134. uint32_t numBytes; /* Last transfer size */
  135. /* It's not possible to free memory which is allocated for the descriptors from within */
  136. /* the ISR. So make the presumption that a given device will tend to use the */
  137. /* same sized buffers over and over again, and we keep them around. */
  138. DMA_DescriptorRing_t ring; /* Ring of descriptors allocated for this device */
  139. /* We stash away some of the information from the previous transfer. If back-to-back */
  140. /* transfers are performed from the same buffer, then we don't have to keep re-initializing */
  141. /* the descriptor buffers. */
  142. uint32_t prevNumBytes;
  143. dma_addr_t prevSrcData;
  144. dma_addr_t prevDstData;
  145. } DMA_DeviceAttribute_t;
  146. /****************************************************************************
  147. *
  148. * DMA_Channel_t, DMA_Controller_t, and DMA_State_t are really internal
  149. * data structures and don't belong in this header file, but are included
  150. * merely for discussion.
  151. *
  152. * By the time this is implemented, these structures will be moved out into
  153. * the appropriate C source file instead.
  154. *
  155. *****************************************************************************/
  156. /****************************************************************************
  157. *
  158. * The DMA_Channel_t contains state information about each DMA channel. Some
  159. * of the channels are dedicated. Non-dedicated channels are shared
  160. * amongst the other devices.
  161. *
  162. *****************************************************************************/
  163. #define DMA_CHANNEL_FLAG_IN_USE 0x00000001
  164. #define DMA_CHANNEL_FLAG_IS_DEDICATED 0x00000002
  165. #define DMA_CHANNEL_FLAG_NO_ISR 0x00000004
  166. #define DMA_CHANNEL_FLAG_LARGE_FIFO 0x00000008
  167. typedef struct {
  168. uint32_t flags; /* bitmask of DMA_CHANNEL_FLAG_xxx constants */
  169. DMA_Device_t devType; /* Device this channel is currently reserved for */
  170. DMA_Device_t lastDevType; /* Device type that used this previously */
  171. char name[20]; /* Name passed onto request_irq */
  172. #if (DMA_DEBUG_TRACK_RESERVATION)
  173. const char *fileName; /* Place where channel reservation took place */
  174. int lineNum; /* Place where channel reservation took place */
  175. #endif
  176. dmacHw_HANDLE_t dmacHwHandle; /* low level channel handle. */
  177. } DMA_Channel_t;
  178. /****************************************************************************
  179. *
  180. * The DMA_Controller_t contains state information about each DMA controller.
  181. *
  182. * The freeChannelQ is stored in the controller data structure rather than
  183. * the channel data structure since several of the devices are accessible
  184. * from multiple controllers, and there is no way to know which controller
  185. * will become available first.
  186. *
  187. *****************************************************************************/
  188. typedef struct {
  189. DMA_Channel_t channel[DMA_NUM_CHANNELS];
  190. } DMA_Controller_t;
  191. /****************************************************************************
  192. *
  193. * The DMA_Global_t contains all of the global state information used by
  194. * the DMA code.
  195. *
  196. * Callers which need to allocate a shared channel will be queued up
  197. * on the freeChannelQ until a channel becomes available.
  198. *
  199. *****************************************************************************/
  200. typedef struct {
  201. struct semaphore lock; /* acquired when manipulating table entries */
  202. wait_queue_head_t freeChannelQ;
  203. DMA_Controller_t controller[DMA_NUM_CONTROLLERS];
  204. } DMA_Global_t;
  205. /* ---- Variable Externs ------------------------------------------------- */
  206. extern DMA_DeviceAttribute_t DMA_gDeviceAttribute[DMA_NUM_DEVICE_ENTRIES];
  207. /* ---- Function Prototypes ---------------------------------------------- */
  208. #if defined(__KERNEL__)
  209. /****************************************************************************/
  210. /**
  211. * Initializes the DMA module.
  212. *
  213. * @return
  214. * 0 - Success
  215. * < 0 - Error
  216. */
  217. /****************************************************************************/
  218. int dma_init(void);
  219. #if (DMA_DEBUG_TRACK_RESERVATION)
  220. DMA_Handle_t dma_request_channel_dbg(DMA_Device_t dev, const char *fileName,
  221. int lineNum);
  222. #define dma_request_channel(dev) dma_request_channel_dbg(dev, __FILE__, __LINE__)
  223. #else
  224. /****************************************************************************/
  225. /**
  226. * Reserves a channel for use with @a dev. If the device is setup to use
  227. * a shared channel, then this function will block until a free channel
  228. * becomes available.
  229. *
  230. * @return
  231. * >= 0 - A valid DMA Handle.
  232. * -EBUSY - Device is currently being used.
  233. * -ENODEV - Device handed in is invalid.
  234. */
  235. /****************************************************************************/
  236. DMA_Handle_t dma_request_channel(DMA_Device_t dev /* Device to use with the allocated channel. */
  237. );
  238. #endif
  239. /****************************************************************************/
  240. /**
  241. * Frees a previously allocated DMA Handle.
  242. *
  243. * @return
  244. * 0 - DMA Handle was released successfully.
  245. * -EINVAL - Invalid DMA handle
  246. */
  247. /****************************************************************************/
  248. int dma_free_channel(DMA_Handle_t channel /* DMA handle. */
  249. );
  250. /****************************************************************************/
  251. /**
  252. * Determines if a given device has been configured as using a shared
  253. * channel.
  254. *
  255. * @return boolean
  256. * 0 Device uses a dedicated channel
  257. * non-zero Device uses a shared channel
  258. */
  259. /****************************************************************************/
  260. int dma_device_is_channel_shared(DMA_Device_t dev /* Device to check. */
  261. );
  262. /****************************************************************************/
  263. /**
  264. * Allocates memory to hold a descriptor ring. The descriptor ring then
  265. * needs to be populated by making one or more calls to
  266. * dna_add_descriptors.
  267. *
  268. * The returned descriptor ring will be automatically initialized.
  269. *
  270. * @return
  271. * 0 Descriptor ring was allocated successfully
  272. * -ENOMEM Unable to allocate memory for the desired number of descriptors.
  273. */
  274. /****************************************************************************/
  275. int dma_alloc_descriptor_ring(DMA_DescriptorRing_t *ring, /* Descriptor ring to populate */
  276. int numDescriptors /* Number of descriptors that need to be allocated. */
  277. );
  278. /****************************************************************************/
  279. /**
  280. * Releases the memory which was previously allocated for a descriptor ring.
  281. */
  282. /****************************************************************************/
  283. void dma_free_descriptor_ring(DMA_DescriptorRing_t *ring /* Descriptor to release */
  284. );
  285. /****************************************************************************/
  286. /**
  287. * Initializes a descriptor ring, so that descriptors can be added to it.
  288. * Once a descriptor ring has been allocated, it may be reinitialized for
  289. * use with additional/different regions of memory.
  290. *
  291. * Note that if 7 descriptors are allocated, it's perfectly acceptable to
  292. * initialize the ring with a smaller number of descriptors. The amount
  293. * of memory allocated for the descriptor ring will not be reduced, and
  294. * the descriptor ring may be reinitialized later
  295. *
  296. * @return
  297. * 0 Descriptor ring was initialized successfully
  298. * -ENOMEM The descriptor which was passed in has insufficient space
  299. * to hold the desired number of descriptors.
  300. */
  301. /****************************************************************************/
  302. int dma_init_descriptor_ring(DMA_DescriptorRing_t *ring, /* Descriptor ring to initialize */
  303. int numDescriptors /* Number of descriptors to initialize. */
  304. );
  305. /****************************************************************************/
  306. /**
  307. * Determines the number of descriptors which would be required for a
  308. * transfer of the indicated memory region.
  309. *
  310. * This function also needs to know which DMA device this transfer will
  311. * be destined for, so that the appropriate DMA configuration can be retrieved.
  312. * DMA parameters such as transfer width, and whether this is a memory-to-memory
  313. * or memory-to-peripheral, etc can all affect the actual number of descriptors
  314. * required.
  315. *
  316. * @return
  317. * > 0 Returns the number of descriptors required for the indicated transfer
  318. * -EINVAL Invalid device type for this kind of transfer
  319. * (i.e. the device is _MEM_TO_DEV and not _DEV_TO_MEM)
  320. * -ENOMEM Memory exhausted
  321. */
  322. /****************************************************************************/
  323. int dma_calculate_descriptor_count(DMA_Device_t device, /* DMA Device that this will be associated with */
  324. dma_addr_t srcData, /* Place to get data to write to device */
  325. dma_addr_t dstData, /* Pointer to device data address */
  326. size_t numBytes /* Number of bytes to transfer to the device */
  327. );
  328. /****************************************************************************/
  329. /**
  330. * Adds a region of memory to the descriptor ring. Note that it may take
  331. * multiple descriptors for each region of memory. It is the callers
  332. * responsibility to allocate a sufficiently large descriptor ring.
  333. *
  334. * @return
  335. * 0 Descriptors were added successfully
  336. * -EINVAL Invalid device type for this kind of transfer
  337. * (i.e. the device is _MEM_TO_DEV and not _DEV_TO_MEM)
  338. * -ENOMEM Memory exhausted
  339. */
  340. /****************************************************************************/
  341. int dma_add_descriptors(DMA_DescriptorRing_t *ring, /* Descriptor ring to add descriptors to */
  342. DMA_Device_t device, /* DMA Device that descriptors are for */
  343. dma_addr_t srcData, /* Place to get data (memory or device) */
  344. dma_addr_t dstData, /* Place to put data (memory or device) */
  345. size_t numBytes /* Number of bytes to transfer to the device */
  346. );
  347. /****************************************************************************/
  348. /**
  349. * Sets the descriptor ring associated with a device.
  350. *
  351. * Once set, the descriptor ring will be associated with the device, even
  352. * across channel request/free calls. Passing in a NULL descriptor ring
  353. * will release any descriptor ring currently associated with the device.
  354. *
  355. * Note: If you call dma_transfer, or one of the other dma_alloc_ functions
  356. * the descriptor ring may be released and reallocated.
  357. *
  358. * Note: This function will release the descriptor memory for any current
  359. * descriptor ring associated with this device.
  360. */
  361. /****************************************************************************/
  362. int dma_set_device_descriptor_ring(DMA_Device_t device, /* Device to update the descriptor ring for. */
  363. DMA_DescriptorRing_t *ring /* Descriptor ring to add descriptors to */
  364. );
  365. /****************************************************************************/
  366. /**
  367. * Retrieves the descriptor ring associated with a device.
  368. */
  369. /****************************************************************************/
  370. int dma_get_device_descriptor_ring(DMA_Device_t device, /* Device to retrieve the descriptor ring for. */
  371. DMA_DescriptorRing_t *ring /* Place to store retrieved ring */
  372. );
  373. /****************************************************************************/
  374. /**
  375. * Allocates buffers for the descriptors. This is normally done automatically
  376. * but needs to be done explicitly when initiating a dma from interrupt
  377. * context.
  378. *
  379. * @return
  380. * 0 Descriptors were allocated successfully
  381. * -EINVAL Invalid device type for this kind of transfer
  382. * (i.e. the device is _MEM_TO_DEV and not _DEV_TO_MEM)
  383. * -ENOMEM Memory exhausted
  384. */
  385. /****************************************************************************/
  386. int dma_alloc_descriptors(DMA_Handle_t handle, /* DMA Handle */
  387. dmacHw_TRANSFER_TYPE_e transferType, /* Type of transfer being performed */
  388. dma_addr_t srcData, /* Place to get data to write to device */
  389. dma_addr_t dstData, /* Pointer to device data address */
  390. size_t numBytes /* Number of bytes to transfer to the device */
  391. );
  392. /****************************************************************************/
  393. /**
  394. * Allocates and sets up descriptors for a double buffered circular buffer.
  395. *
  396. * This is primarily intended to be used for things like the ingress samples
  397. * from a microphone.
  398. *
  399. * @return
  400. * > 0 Number of descriptors actually allocated.
  401. * -EINVAL Invalid device type for this kind of transfer
  402. * (i.e. the device is _MEM_TO_DEV and not _DEV_TO_MEM)
  403. * -ENOMEM Memory exhausted
  404. */
  405. /****************************************************************************/
  406. int dma_alloc_double_dst_descriptors(DMA_Handle_t handle, /* DMA Handle */
  407. dma_addr_t srcData, /* Physical address of source data */
  408. dma_addr_t dstData1, /* Physical address of first destination buffer */
  409. dma_addr_t dstData2, /* Physical address of second destination buffer */
  410. size_t numBytes /* Number of bytes in each destination buffer */
  411. );
  412. /****************************************************************************/
  413. /**
  414. * Initiates a transfer when the descriptors have already been setup.
  415. *
  416. * This is a special case, and normally, the dma_transfer_xxx functions should
  417. * be used.
  418. *
  419. * @return
  420. * 0 Transfer was started successfully
  421. * -ENODEV Invalid handle
  422. */
  423. /****************************************************************************/
  424. int dma_start_transfer(DMA_Handle_t handle);
  425. /****************************************************************************/
  426. /**
  427. * Stops a previously started DMA transfer.
  428. *
  429. * @return
  430. * 0 Transfer was stopped successfully
  431. * -ENODEV Invalid handle
  432. */
  433. /****************************************************************************/
  434. int dma_stop_transfer(DMA_Handle_t handle);
  435. /****************************************************************************/
  436. /**
  437. * Waits for a DMA to complete by polling. This function is only intended
  438. * to be used for testing. Interrupts should be used for most DMA operations.
  439. */
  440. /****************************************************************************/
  441. int dma_wait_transfer_done(DMA_Handle_t handle);
  442. /****************************************************************************/
  443. /**
  444. * Initiates a DMA transfer
  445. *
  446. * @return
  447. * 0 Transfer was started successfully
  448. * -EINVAL Invalid device type for this kind of transfer
  449. * (i.e. the device is _MEM_TO_DEV and not _DEV_TO_MEM)
  450. */
  451. /****************************************************************************/
  452. int dma_transfer(DMA_Handle_t handle, /* DMA Handle */
  453. dmacHw_TRANSFER_TYPE_e transferType, /* Type of transfer being performed */
  454. dma_addr_t srcData, /* Place to get data to write to device */
  455. dma_addr_t dstData, /* Pointer to device data address */
  456. size_t numBytes /* Number of bytes to transfer to the device */
  457. );
  458. /****************************************************************************/
  459. /**
  460. * Initiates a transfer from memory to a device.
  461. *
  462. * @return
  463. * 0 Transfer was started successfully
  464. * -EINVAL Invalid device type for this kind of transfer
  465. * (i.e. the device is _DEV_TO_MEM and not _MEM_TO_DEV)
  466. */
  467. /****************************************************************************/
  468. static inline int dma_transfer_to_device(DMA_Handle_t handle, /* DMA Handle */
  469. dma_addr_t srcData, /* Place to get data to write to device (physical address) */
  470. dma_addr_t dstData, /* Pointer to device data address (physical address) */
  471. size_t numBytes /* Number of bytes to transfer to the device */
  472. ) {
  473. return dma_transfer(handle,
  474. dmacHw_TRANSFER_TYPE_MEM_TO_PERIPHERAL,
  475. srcData, dstData, numBytes);
  476. }
  477. /****************************************************************************/
  478. /**
  479. * Initiates a transfer from a device to memory.
  480. *
  481. * @return
  482. * 0 Transfer was started successfully
  483. * -EINVAL Invalid device type for this kind of transfer
  484. * (i.e. the device is _MEM_TO_DEV and not _DEV_TO_MEM)
  485. */
  486. /****************************************************************************/
  487. static inline int dma_transfer_from_device(DMA_Handle_t handle, /* DMA Handle */
  488. dma_addr_t srcData, /* Pointer to the device data address (physical address) */
  489. dma_addr_t dstData, /* Place to store data retrieved from the device (physical address) */
  490. size_t numBytes /* Number of bytes to retrieve from the device */
  491. ) {
  492. return dma_transfer(handle,
  493. dmacHw_TRANSFER_TYPE_PERIPHERAL_TO_MEM,
  494. srcData, dstData, numBytes);
  495. }
  496. /****************************************************************************/
  497. /**
  498. * Initiates a memory to memory transfer.
  499. *
  500. * @return
  501. * 0 Transfer was started successfully
  502. * -EINVAL Invalid device type for this kind of transfer
  503. * (i.e. the device wasn't DMA_DEVICE_MEM_TO_MEM)
  504. */
  505. /****************************************************************************/
  506. static inline int dma_transfer_mem_to_mem(DMA_Handle_t handle, /* DMA Handle */
  507. dma_addr_t srcData, /* Place to transfer data from (physical address) */
  508. dma_addr_t dstData, /* Place to transfer data to (physical address) */
  509. size_t numBytes /* Number of bytes to transfer */
  510. ) {
  511. return dma_transfer(handle,
  512. dmacHw_TRANSFER_TYPE_MEM_TO_MEM,
  513. srcData, dstData, numBytes);
  514. }
  515. /****************************************************************************/
  516. /**
  517. * Set the callback function which will be called when a transfer completes.
  518. * If a NULL callback function is set, then no callback will occur.
  519. *
  520. * @note @a devHandler will be called from IRQ context.
  521. *
  522. * @return
  523. * 0 - Success
  524. * -ENODEV - Device handed in is invalid.
  525. */
  526. /****************************************************************************/
  527. int dma_set_device_handler(DMA_Device_t dev, /* Device to set the callback for. */
  528. DMA_DeviceHandler_t devHandler, /* Function to call when the DMA completes */
  529. void *userData /* Pointer which will be passed to devHandler. */
  530. );
  531. #endif
  532. #endif /* ASM_ARM_ARCH_BCMRING_DMA_H */