bfin_dma.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  1. /*
  2. * bfin_dma.c - Blackfin DMA implementation
  3. *
  4. * Copyright 2004-2008 Analog Devices Inc.
  5. *
  6. * Licensed under the GPL-2 or later.
  7. */
  8. #include <linux/errno.h>
  9. #include <linux/interrupt.h>
  10. #include <linux/kernel.h>
  11. #include <linux/module.h>
  12. #include <linux/param.h>
  13. #include <linux/proc_fs.h>
  14. #include <linux/sched.h>
  15. #include <linux/seq_file.h>
  16. #include <linux/spinlock.h>
  17. #include <asm/blackfin.h>
  18. #include <asm/cacheflush.h>
  19. #include <asm/dma.h>
  20. #include <asm/uaccess.h>
  21. #include <asm/early_printk.h>
  22. /*
  23. * To make sure we work around 05000119 - we always check DMA_DONE bit,
  24. * never the DMA_RUN bit
  25. */
  26. struct dma_channel dma_ch[MAX_DMA_CHANNELS];
  27. EXPORT_SYMBOL(dma_ch);
  28. static int __init blackfin_dma_init(void)
  29. {
  30. int i;
  31. printk(KERN_INFO "Blackfin DMA Controller\n");
  32. #if ANOMALY_05000480
  33. bfin_write_DMAC_TC_PER(0x0111);
  34. #endif
  35. for (i = 0; i < MAX_DMA_CHANNELS; i++) {
  36. atomic_set(&dma_ch[i].chan_status, 0);
  37. dma_ch[i].regs = dma_io_base_addr[i];
  38. }
  39. #ifdef CH_MEM_STREAM3_SRC
  40. /* Mark MEMDMA Channel 3 as requested since we're using it internally */
  41. request_dma(CH_MEM_STREAM3_DEST, "Blackfin dma_memcpy");
  42. request_dma(CH_MEM_STREAM3_SRC, "Blackfin dma_memcpy");
  43. #else
  44. /* Mark MEMDMA Channel 0 as requested since we're using it internally */
  45. request_dma(CH_MEM_STREAM0_DEST, "Blackfin dma_memcpy");
  46. request_dma(CH_MEM_STREAM0_SRC, "Blackfin dma_memcpy");
  47. #endif
  48. #if defined(CONFIG_DEB_DMA_URGENT)
  49. bfin_write_EBIU_DDRQUE(bfin_read_EBIU_DDRQUE()
  50. | DEB1_URGENT | DEB2_URGENT | DEB3_URGENT);
  51. #endif
  52. return 0;
  53. }
  54. arch_initcall(blackfin_dma_init);
  55. #ifdef CONFIG_PROC_FS
  56. static int proc_dma_show(struct seq_file *m, void *v)
  57. {
  58. int i;
  59. for (i = 0; i < MAX_DMA_CHANNELS; ++i)
  60. if (dma_channel_active(i))
  61. seq_printf(m, "%2d: %s\n", i, dma_ch[i].device_id);
  62. return 0;
  63. }
  64. static int proc_dma_open(struct inode *inode, struct file *file)
  65. {
  66. return single_open(file, proc_dma_show, NULL);
  67. }
  68. static const struct file_operations proc_dma_operations = {
  69. .open = proc_dma_open,
  70. .read = seq_read,
  71. .llseek = seq_lseek,
  72. .release = single_release,
  73. };
  74. static int __init proc_dma_init(void)
  75. {
  76. return proc_create("dma", 0, NULL, &proc_dma_operations) != NULL;
  77. }
  78. late_initcall(proc_dma_init);
  79. #endif
  80. static void set_dma_peripheral_map(unsigned int channel, const char *device_id)
  81. {
  82. #ifdef CONFIG_BF54x
  83. unsigned int per_map;
  84. switch (channel) {
  85. case CH_UART2_RX: per_map = 0xC << 12; break;
  86. case CH_UART2_TX: per_map = 0xD << 12; break;
  87. case CH_UART3_RX: per_map = 0xE << 12; break;
  88. case CH_UART3_TX: per_map = 0xF << 12; break;
  89. default: return;
  90. }
  91. if (strncmp(device_id, "BFIN_UART", 9) == 0)
  92. dma_ch[channel].regs->peripheral_map = per_map;
  93. #endif
  94. }
  95. /**
  96. * request_dma - request a DMA channel
  97. *
  98. * Request the specific DMA channel from the system if it's available.
  99. */
  100. int request_dma(unsigned int channel, const char *device_id)
  101. {
  102. pr_debug("request_dma() : BEGIN\n");
  103. if (device_id == NULL)
  104. printk(KERN_WARNING "request_dma(%u): no device_id given\n", channel);
  105. #if defined(CONFIG_BF561) && ANOMALY_05000182
  106. if (channel >= CH_IMEM_STREAM0_DEST && channel <= CH_IMEM_STREAM1_DEST) {
  107. if (get_cclk() > 500000000) {
  108. printk(KERN_WARNING
  109. "Request IMDMA failed due to ANOMALY 05000182\n");
  110. return -EFAULT;
  111. }
  112. }
  113. #endif
  114. if (atomic_cmpxchg(&dma_ch[channel].chan_status, 0, 1)) {
  115. pr_debug("DMA CHANNEL IN USE\n");
  116. return -EBUSY;
  117. }
  118. set_dma_peripheral_map(channel, device_id);
  119. dma_ch[channel].device_id = device_id;
  120. dma_ch[channel].irq = 0;
  121. /* This is to be enabled by putting a restriction -
  122. * you have to request DMA, before doing any operations on
  123. * descriptor/channel
  124. */
  125. pr_debug("request_dma() : END\n");
  126. return 0;
  127. }
  128. EXPORT_SYMBOL(request_dma);
  129. int set_dma_callback(unsigned int channel, irq_handler_t callback, void *data)
  130. {
  131. int ret;
  132. unsigned int irq;
  133. BUG_ON(channel >= MAX_DMA_CHANNELS || !callback ||
  134. !atomic_read(&dma_ch[channel].chan_status));
  135. irq = channel2irq(channel);
  136. ret = request_irq(irq, callback, 0, dma_ch[channel].device_id, data);
  137. if (ret)
  138. return ret;
  139. dma_ch[channel].irq = irq;
  140. dma_ch[channel].data = data;
  141. return 0;
  142. }
  143. EXPORT_SYMBOL(set_dma_callback);
  144. /**
  145. * clear_dma_buffer - clear DMA fifos for specified channel
  146. *
  147. * Set the Buffer Clear bit in the Configuration register of specific DMA
  148. * channel. This will stop the descriptor based DMA operation.
  149. */
  150. static void clear_dma_buffer(unsigned int channel)
  151. {
  152. dma_ch[channel].regs->cfg |= RESTART;
  153. SSYNC();
  154. dma_ch[channel].regs->cfg &= ~RESTART;
  155. }
  156. void free_dma(unsigned int channel)
  157. {
  158. pr_debug("freedma() : BEGIN\n");
  159. BUG_ON(channel >= MAX_DMA_CHANNELS ||
  160. !atomic_read(&dma_ch[channel].chan_status));
  161. /* Halt the DMA */
  162. disable_dma(channel);
  163. clear_dma_buffer(channel);
  164. if (dma_ch[channel].irq)
  165. free_irq(dma_ch[channel].irq, dma_ch[channel].data);
  166. /* Clear the DMA Variable in the Channel */
  167. atomic_set(&dma_ch[channel].chan_status, 0);
  168. pr_debug("freedma() : END\n");
  169. }
  170. EXPORT_SYMBOL(free_dma);
  171. #ifdef CONFIG_PM
  172. # ifndef MAX_DMA_SUSPEND_CHANNELS
  173. # define MAX_DMA_SUSPEND_CHANNELS MAX_DMA_CHANNELS
  174. # endif
  175. # ifndef CONFIG_BF60x
  176. int blackfin_dma_suspend(void)
  177. {
  178. int i;
  179. for (i = 0; i < MAX_DMA_CHANNELS; ++i) {
  180. if (dma_ch[i].regs->cfg & DMAEN) {
  181. printk(KERN_ERR "DMA Channel %d failed to suspend\n", i);
  182. return -EBUSY;
  183. }
  184. if (i < MAX_DMA_SUSPEND_CHANNELS)
  185. dma_ch[i].saved_peripheral_map = dma_ch[i].regs->peripheral_map;
  186. }
  187. #if ANOMALY_05000480
  188. bfin_write_DMAC_TC_PER(0x0);
  189. #endif
  190. return 0;
  191. }
  192. void blackfin_dma_resume(void)
  193. {
  194. int i;
  195. for (i = 0; i < MAX_DMA_CHANNELS; ++i) {
  196. dma_ch[i].regs->cfg = 0;
  197. if (i < MAX_DMA_SUSPEND_CHANNELS)
  198. dma_ch[i].regs->peripheral_map = dma_ch[i].saved_peripheral_map;
  199. }
  200. #if ANOMALY_05000480
  201. bfin_write_DMAC_TC_PER(0x0111);
  202. #endif
  203. }
  204. # else
  205. int blackfin_dma_suspend(void)
  206. {
  207. return 0;
  208. }
  209. void blackfin_dma_resume(void)
  210. {
  211. }
  212. #endif
  213. #endif
  214. /**
  215. * blackfin_dma_early_init - minimal DMA init
  216. *
  217. * Setup a few DMA registers so we can safely do DMA transfers early on in
  218. * the kernel booting process. Really this just means using dma_memcpy().
  219. */
  220. void __init blackfin_dma_early_init(void)
  221. {
  222. early_shadow_stamp();
  223. bfin_write_MDMA_S0_CONFIG(0);
  224. bfin_write_MDMA_S1_CONFIG(0);
  225. }
  226. void __init early_dma_memcpy(void *pdst, const void *psrc, size_t size)
  227. {
  228. unsigned long dst = (unsigned long)pdst;
  229. unsigned long src = (unsigned long)psrc;
  230. struct dma_register *dst_ch, *src_ch;
  231. early_shadow_stamp();
  232. /* We assume that everything is 4 byte aligned, so include
  233. * a basic sanity check
  234. */
  235. BUG_ON(dst % 4);
  236. BUG_ON(src % 4);
  237. BUG_ON(size % 4);
  238. src_ch = 0;
  239. /* Find an avalible memDMA channel */
  240. while (1) {
  241. if (src_ch == (struct dma_register *)MDMA_S0_NEXT_DESC_PTR) {
  242. dst_ch = (struct dma_register *)MDMA_D1_NEXT_DESC_PTR;
  243. src_ch = (struct dma_register *)MDMA_S1_NEXT_DESC_PTR;
  244. } else {
  245. dst_ch = (struct dma_register *)MDMA_D0_NEXT_DESC_PTR;
  246. src_ch = (struct dma_register *)MDMA_S0_NEXT_DESC_PTR;
  247. }
  248. if (!DMA_MMR_READ(&src_ch->cfg))
  249. break;
  250. else if (DMA_MMR_READ(&dst_ch->irq_status) & DMA_DONE) {
  251. DMA_MMR_WRITE(&src_ch->cfg, 0);
  252. break;
  253. }
  254. }
  255. /* Force a sync in case a previous config reset on this channel
  256. * occurred. This is needed so subsequent writes to DMA registers
  257. * are not spuriously lost/corrupted.
  258. */
  259. __builtin_bfin_ssync();
  260. /* Destination */
  261. bfin_write32(&dst_ch->start_addr, dst);
  262. DMA_MMR_WRITE(&dst_ch->x_count, size >> 2);
  263. DMA_MMR_WRITE(&dst_ch->x_modify, 1 << 2);
  264. DMA_MMR_WRITE(&dst_ch->irq_status, DMA_DONE | DMA_ERR);
  265. /* Source */
  266. bfin_write32(&src_ch->start_addr, src);
  267. DMA_MMR_WRITE(&src_ch->x_count, size >> 2);
  268. DMA_MMR_WRITE(&src_ch->x_modify, 1 << 2);
  269. DMA_MMR_WRITE(&src_ch->irq_status, DMA_DONE | DMA_ERR);
  270. /* Enable */
  271. DMA_MMR_WRITE(&src_ch->cfg, DMAEN | WDSIZE_32);
  272. DMA_MMR_WRITE(&dst_ch->cfg, WNR | DI_EN_X | DMAEN | WDSIZE_32);
  273. /* Since we are atomic now, don't use the workaround ssync */
  274. __builtin_bfin_ssync();
  275. #ifdef CONFIG_BF60x
  276. /* Work around a possible MDMA anomaly. Running 2 MDMA channels to
  277. * transfer DDR data to L1 SRAM may corrupt data.
  278. * Should be reverted after this issue is root caused.
  279. */
  280. while (!(DMA_MMR_READ(&dst_ch->irq_status) & DMA_DONE))
  281. continue;
  282. #endif
  283. }
  284. void __init early_dma_memcpy_done(void)
  285. {
  286. early_shadow_stamp();
  287. while ((bfin_read_MDMA_S0_CONFIG() && !(bfin_read_MDMA_D0_IRQ_STATUS() & DMA_DONE)) ||
  288. (bfin_read_MDMA_S1_CONFIG() && !(bfin_read_MDMA_D1_IRQ_STATUS() & DMA_DONE)))
  289. continue;
  290. bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
  291. bfin_write_MDMA_D1_IRQ_STATUS(DMA_DONE | DMA_ERR);
  292. /*
  293. * Now that DMA is done, we would normally flush cache, but
  294. * i/d cache isn't running this early, so we don't bother,
  295. * and just clear out the DMA channel for next time
  296. */
  297. bfin_write_MDMA_S0_CONFIG(0);
  298. bfin_write_MDMA_S1_CONFIG(0);
  299. bfin_write_MDMA_D0_CONFIG(0);
  300. bfin_write_MDMA_D1_CONFIG(0);
  301. __builtin_bfin_ssync();
  302. }
  303. #ifdef CH_MEM_STREAM3_SRC
  304. #define bfin_read_MDMA_S_CONFIG bfin_read_MDMA_S3_CONFIG
  305. #define bfin_write_MDMA_S_CONFIG bfin_write_MDMA_S3_CONFIG
  306. #define bfin_write_MDMA_S_START_ADDR bfin_write_MDMA_S3_START_ADDR
  307. #define bfin_write_MDMA_S_IRQ_STATUS bfin_write_MDMA_S3_IRQ_STATUS
  308. #define bfin_write_MDMA_S_X_COUNT bfin_write_MDMA_S3_X_COUNT
  309. #define bfin_write_MDMA_S_X_MODIFY bfin_write_MDMA_S3_X_MODIFY
  310. #define bfin_write_MDMA_S_Y_COUNT bfin_write_MDMA_S3_Y_COUNT
  311. #define bfin_write_MDMA_S_Y_MODIFY bfin_write_MDMA_S3_Y_MODIFY
  312. #define bfin_write_MDMA_D_CONFIG bfin_write_MDMA_D3_CONFIG
  313. #define bfin_write_MDMA_D_START_ADDR bfin_write_MDMA_D3_START_ADDR
  314. #define bfin_read_MDMA_D_IRQ_STATUS bfin_read_MDMA_D3_IRQ_STATUS
  315. #define bfin_write_MDMA_D_IRQ_STATUS bfin_write_MDMA_D3_IRQ_STATUS
  316. #define bfin_write_MDMA_D_X_COUNT bfin_write_MDMA_D3_X_COUNT
  317. #define bfin_write_MDMA_D_X_MODIFY bfin_write_MDMA_D3_X_MODIFY
  318. #define bfin_write_MDMA_D_Y_COUNT bfin_write_MDMA_D3_Y_COUNT
  319. #define bfin_write_MDMA_D_Y_MODIFY bfin_write_MDMA_D3_Y_MODIFY
  320. #else
  321. #define bfin_read_MDMA_S_CONFIG bfin_read_MDMA_S0_CONFIG
  322. #define bfin_write_MDMA_S_CONFIG bfin_write_MDMA_S0_CONFIG
  323. #define bfin_write_MDMA_S_START_ADDR bfin_write_MDMA_S0_START_ADDR
  324. #define bfin_write_MDMA_S_IRQ_STATUS bfin_write_MDMA_S0_IRQ_STATUS
  325. #define bfin_write_MDMA_S_X_COUNT bfin_write_MDMA_S0_X_COUNT
  326. #define bfin_write_MDMA_S_X_MODIFY bfin_write_MDMA_S0_X_MODIFY
  327. #define bfin_write_MDMA_S_Y_COUNT bfin_write_MDMA_S0_Y_COUNT
  328. #define bfin_write_MDMA_S_Y_MODIFY bfin_write_MDMA_S0_Y_MODIFY
  329. #define bfin_write_MDMA_D_CONFIG bfin_write_MDMA_D0_CONFIG
  330. #define bfin_write_MDMA_D_START_ADDR bfin_write_MDMA_D0_START_ADDR
  331. #define bfin_read_MDMA_D_IRQ_STATUS bfin_read_MDMA_D0_IRQ_STATUS
  332. #define bfin_write_MDMA_D_IRQ_STATUS bfin_write_MDMA_D0_IRQ_STATUS
  333. #define bfin_write_MDMA_D_X_COUNT bfin_write_MDMA_D0_X_COUNT
  334. #define bfin_write_MDMA_D_X_MODIFY bfin_write_MDMA_D0_X_MODIFY
  335. #define bfin_write_MDMA_D_Y_COUNT bfin_write_MDMA_D0_Y_COUNT
  336. #define bfin_write_MDMA_D_Y_MODIFY bfin_write_MDMA_D0_Y_MODIFY
  337. #endif
  338. /**
  339. * __dma_memcpy - program the MDMA registers
  340. *
  341. * Actually program MDMA0 and wait for the transfer to finish. Disable IRQs
  342. * while programming registers so that everything is fully configured. Wait
  343. * for DMA to finish with IRQs enabled. If interrupted, the initial DMA_DONE
  344. * check will make sure we don't clobber any existing transfer.
  345. */
  346. static void __dma_memcpy(u32 daddr, s16 dmod, u32 saddr, s16 smod, size_t cnt, u32 conf)
  347. {
  348. static DEFINE_SPINLOCK(mdma_lock);
  349. unsigned long flags;
  350. spin_lock_irqsave(&mdma_lock, flags);
  351. /* Force a sync in case a previous config reset on this channel
  352. * occurred. This is needed so subsequent writes to DMA registers
  353. * are not spuriously lost/corrupted. Do it under irq lock and
  354. * without the anomaly version (because we are atomic already).
  355. */
  356. __builtin_bfin_ssync();
  357. if (bfin_read_MDMA_S_CONFIG())
  358. while (!(bfin_read_MDMA_D_IRQ_STATUS() & DMA_DONE))
  359. continue;
  360. if (conf & DMA2D) {
  361. /* For larger bit sizes, we've already divided down cnt so it
  362. * is no longer a multiple of 64k. So we have to break down
  363. * the limit here so it is a multiple of the incoming size.
  364. * There is no limitation here in terms of total size other
  365. * than the hardware though as the bits lost in the shift are
  366. * made up by MODIFY (== we can hit the whole address space).
  367. * X: (2^(16 - 0)) * 1 == (2^(16 - 1)) * 2 == (2^(16 - 2)) * 4
  368. */
  369. u32 shift = abs(dmod) >> 1;
  370. size_t ycnt = cnt >> (16 - shift);
  371. cnt = 1 << (16 - shift);
  372. bfin_write_MDMA_D_Y_COUNT(ycnt);
  373. bfin_write_MDMA_S_Y_COUNT(ycnt);
  374. bfin_write_MDMA_D_Y_MODIFY(dmod);
  375. bfin_write_MDMA_S_Y_MODIFY(smod);
  376. }
  377. bfin_write_MDMA_D_START_ADDR(daddr);
  378. bfin_write_MDMA_D_X_COUNT(cnt);
  379. bfin_write_MDMA_D_X_MODIFY(dmod);
  380. bfin_write_MDMA_D_IRQ_STATUS(DMA_DONE | DMA_ERR);
  381. bfin_write_MDMA_S_START_ADDR(saddr);
  382. bfin_write_MDMA_S_X_COUNT(cnt);
  383. bfin_write_MDMA_S_X_MODIFY(smod);
  384. bfin_write_MDMA_S_IRQ_STATUS(DMA_DONE | DMA_ERR);
  385. bfin_write_MDMA_S_CONFIG(DMAEN | conf);
  386. if (conf & DMA2D)
  387. bfin_write_MDMA_D_CONFIG(WNR | DI_EN_Y | DMAEN | conf);
  388. else
  389. bfin_write_MDMA_D_CONFIG(WNR | DI_EN_X | DMAEN | conf);
  390. spin_unlock_irqrestore(&mdma_lock, flags);
  391. SSYNC();
  392. while (!(bfin_read_MDMA_D_IRQ_STATUS() & DMA_DONE))
  393. if (bfin_read_MDMA_S_CONFIG())
  394. continue;
  395. else
  396. return;
  397. bfin_write_MDMA_D_IRQ_STATUS(DMA_DONE | DMA_ERR);
  398. bfin_write_MDMA_S_CONFIG(0);
  399. bfin_write_MDMA_D_CONFIG(0);
  400. }
  401. /**
  402. * _dma_memcpy - translate C memcpy settings into MDMA settings
  403. *
  404. * Handle all the high level steps before we touch the MDMA registers. So
  405. * handle direction, tweaking of sizes, and formatting of addresses.
  406. */
  407. static void *_dma_memcpy(void *pdst, const void *psrc, size_t size)
  408. {
  409. u32 conf, shift;
  410. s16 mod;
  411. unsigned long dst = (unsigned long)pdst;
  412. unsigned long src = (unsigned long)psrc;
  413. if (size == 0)
  414. return NULL;
  415. if (dst % 4 == 0 && src % 4 == 0 && size % 4 == 0) {
  416. conf = WDSIZE_32;
  417. shift = 2;
  418. } else if (dst % 2 == 0 && src % 2 == 0 && size % 2 == 0) {
  419. conf = WDSIZE_16;
  420. shift = 1;
  421. } else {
  422. conf = WDSIZE_8;
  423. shift = 0;
  424. }
  425. /* If the two memory regions have a chance of overlapping, make
  426. * sure the memcpy still works as expected. Do this by having the
  427. * copy run backwards instead.
  428. */
  429. mod = 1 << shift;
  430. if (src < dst) {
  431. mod *= -1;
  432. dst += size + mod;
  433. src += size + mod;
  434. }
  435. size >>= shift;
  436. #ifndef DMA_MMR_SIZE_32
  437. if (size > 0x10000)
  438. conf |= DMA2D;
  439. #endif
  440. __dma_memcpy(dst, mod, src, mod, size, conf);
  441. return pdst;
  442. }
  443. /**
  444. * dma_memcpy - DMA memcpy under mutex lock
  445. *
  446. * Do not check arguments before starting the DMA memcpy. Break the transfer
  447. * up into two pieces. The first transfer is in multiples of 64k and the
  448. * second transfer is the piece smaller than 64k.
  449. */
  450. void *dma_memcpy(void *pdst, const void *psrc, size_t size)
  451. {
  452. unsigned long dst = (unsigned long)pdst;
  453. unsigned long src = (unsigned long)psrc;
  454. if (bfin_addr_dcacheable(src))
  455. blackfin_dcache_flush_range(src, src + size);
  456. if (bfin_addr_dcacheable(dst))
  457. blackfin_dcache_invalidate_range(dst, dst + size);
  458. return dma_memcpy_nocache(pdst, psrc, size);
  459. }
  460. EXPORT_SYMBOL(dma_memcpy);
  461. /**
  462. * dma_memcpy_nocache - DMA memcpy under mutex lock
  463. * - No cache flush/invalidate
  464. *
  465. * Do not check arguments before starting the DMA memcpy. Break the transfer
  466. * up into two pieces. The first transfer is in multiples of 64k and the
  467. * second transfer is the piece smaller than 64k.
  468. */
  469. void *dma_memcpy_nocache(void *pdst, const void *psrc, size_t size)
  470. {
  471. #ifdef DMA_MMR_SIZE_32
  472. _dma_memcpy(pdst, psrc, size);
  473. #else
  474. size_t bulk, rest;
  475. bulk = size & ~0xffff;
  476. rest = size - bulk;
  477. if (bulk)
  478. _dma_memcpy(pdst, psrc, bulk);
  479. _dma_memcpy(pdst + bulk, psrc + bulk, rest);
  480. #endif
  481. return pdst;
  482. }
  483. EXPORT_SYMBOL(dma_memcpy_nocache);
  484. /**
  485. * safe_dma_memcpy - DMA memcpy w/argument checking
  486. *
  487. * Verify arguments are safe before heading to dma_memcpy().
  488. */
  489. void *safe_dma_memcpy(void *dst, const void *src, size_t size)
  490. {
  491. if (!access_ok(VERIFY_WRITE, dst, size))
  492. return NULL;
  493. if (!access_ok(VERIFY_READ, src, size))
  494. return NULL;
  495. return dma_memcpy(dst, src, size);
  496. }
  497. EXPORT_SYMBOL(safe_dma_memcpy);
  498. static void _dma_out(unsigned long addr, unsigned long buf, unsigned DMA_MMR_SIZE_TYPE len,
  499. u16 size, u16 dma_size)
  500. {
  501. blackfin_dcache_flush_range(buf, buf + len * size);
  502. __dma_memcpy(addr, 0, buf, size, len, dma_size);
  503. }
  504. static void _dma_in(unsigned long addr, unsigned long buf, unsigned DMA_MMR_SIZE_TYPE len,
  505. u16 size, u16 dma_size)
  506. {
  507. blackfin_dcache_invalidate_range(buf, buf + len * size);
  508. __dma_memcpy(buf, size, addr, 0, len, dma_size);
  509. }
  510. #define MAKE_DMA_IO(io, bwl, isize, dmasize, cnst) \
  511. void dma_##io##s##bwl(unsigned long addr, cnst void *buf, unsigned DMA_MMR_SIZE_TYPE len) \
  512. { \
  513. _dma_##io(addr, (unsigned long)buf, len, isize, WDSIZE_##dmasize); \
  514. } \
  515. EXPORT_SYMBOL(dma_##io##s##bwl)
  516. MAKE_DMA_IO(out, b, 1, 8, const);
  517. MAKE_DMA_IO(in, b, 1, 8, );
  518. MAKE_DMA_IO(out, w, 2, 16, const);
  519. MAKE_DMA_IO(in, w, 2, 16, );
  520. MAKE_DMA_IO(out, l, 4, 32, const);
  521. MAKE_DMA_IO(in, l, 4, 32, );