2 * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
10 * DMA Coherent API Notes
12 * I/O is inherently non-coherent on ARC. So a coherent DMA buffer is
13 * implemented by accessintg it using a kernel virtual address, with
14 * Cache bit off in the TLB entry.
16 * The default DMA address == Phy address which is 0x8000_0000 based.
19 #include <linux/dma-mapping.h>
20 #include <linux/dma-debug.h>
21 #include <linux/export.h>
22 #include <asm/cacheflush.h>
25 * Helpers for Coherent DMA API.
27 void *dma_alloc_noncoherent(struct device
*dev
, size_t size
,
28 dma_addr_t
*dma_handle
, gfp_t gfp
)
32 /* This is linear addr (0x8000_0000 based) */
33 paddr
= alloc_pages_exact(size
, gfp
);
37 /* This is bus address, platform dependent */
38 *dma_handle
= (dma_addr_t
)paddr
;
42 EXPORT_SYMBOL(dma_alloc_noncoherent
);
44 void dma_free_noncoherent(struct device
*dev
, size_t size
, void *vaddr
,
45 dma_addr_t dma_handle
)
47 free_pages_exact((void *)dma_handle
, size
);
49 EXPORT_SYMBOL(dma_free_noncoherent
);
51 void *dma_alloc_coherent(struct device
*dev
, size_t size
,
52 dma_addr_t
*dma_handle
, gfp_t gfp
)
56 /* This is linear addr (0x8000_0000 based) */
57 paddr
= alloc_pages_exact(size
, gfp
);
61 /* This is kernel Virtual address (0x7000_0000 based) */
62 kvaddr
= ioremap_nocache((unsigned long)paddr
, size
);
66 /* This is bus address, platform dependent */
67 *dma_handle
= (dma_addr_t
)paddr
;
70 * Evict any existing L1 and/or L2 lines for the backing page
71 * in case it was used earlier as a normal "cached" page.
72 * Yeah this bit us - STAR 9000898266
74 * Although core does call flush_cache_vmap(), it gets kvaddr hence
75 * can't be used to efficiently flush L1 and/or L2 which need paddr
76 * Currently flush_cache_vmap nukes the L1 cache completely which
77 * will be optimized as a separate commit
79 dma_cache_wback_inv((unsigned long)paddr
, size
);
83 EXPORT_SYMBOL(dma_alloc_coherent
);
85 void dma_free_coherent(struct device
*dev
, size_t size
, void *kvaddr
,
86 dma_addr_t dma_handle
)
88 iounmap((void __force __iomem
*)kvaddr
);
90 free_pages_exact((void *)dma_handle
, size
);
92 EXPORT_SYMBOL(dma_free_coherent
);
95 * Helper for streaming DMA...
97 void __arc_dma_cache_sync(unsigned long paddr
, size_t size
,
98 enum dma_data_direction dir
)
100 __inline_dma_cache_sync(paddr
, size
, dir
);
102 EXPORT_SYMBOL(__arc_dma_cache_sync
);