Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1 | #ifndef _BLACKFIN_DMA_MAPPING_H |
| 2 | #define _BLACKFIN_DMA_MAPPING_H |
| 3 | |
| 4 | #include <asm/scatterlist.h> |
| 5 | |
| 6 | void dma_alloc_init(unsigned long start, unsigned long end); |
| 7 | void *dma_alloc_coherent(struct device *dev, size_t size, |
| 8 | dma_addr_t *dma_handle, gfp_t gfp); |
| 9 | void dma_free_coherent(struct device *dev, size_t size, void *vaddr, |
| 10 | dma_addr_t dma_handle); |
| 11 | |
| 12 | /* |
| 13 | * Now for the API extensions over the pci_ one |
| 14 | */ |
| 15 | #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f) |
| 16 | #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h) |
| 17 | |
Sonic Zhang | 334280f | 2007-06-21 11:34:16 +0800 | [diff] [blame] | 18 | #define dma_mapping_error |
| 19 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 20 | /* |
| 21 | * Map a single buffer of the indicated size for DMA in streaming mode. |
| 22 | * The 32-bit bus address to use is returned. |
| 23 | * |
| 24 | * Once the device is given the dma address, the device owns this memory |
| 25 | * until either pci_unmap_single or pci_dma_sync_single is performed. |
| 26 | */ |
| 27 | extern dma_addr_t dma_map_single(struct device *dev, void *ptr, size_t size, |
| 28 | enum dma_data_direction direction); |
| 29 | |
Bryan Wu | 9fcdc78 | 2008-04-23 07:41:52 +0800 | [diff] [blame^] | 30 | static inline dma_addr_t |
| 31 | dma_map_page(struct device *dev, struct page *page, |
| 32 | unsigned long offset, size_t size, |
| 33 | enum dma_data_direction dir) |
| 34 | { |
| 35 | return dma_map_single(dev, page_address(page) + offset, size, dir); |
| 36 | } |
| 37 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 38 | /* |
| 39 | * Unmap a single streaming mode DMA translation. The dma_addr and size |
| 40 | * must match what was provided for in a previous pci_map_single call. All |
| 41 | * other usages are undefined. |
| 42 | * |
| 43 | * After this call, reads by the cpu to the buffer are guarenteed to see |
| 44 | * whatever the device wrote there. |
| 45 | */ |
| 46 | extern void dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size, |
| 47 | enum dma_data_direction direction); |
| 48 | |
Bryan Wu | 9fcdc78 | 2008-04-23 07:41:52 +0800 | [diff] [blame^] | 49 | static inline void |
| 50 | dma_unmap_page(struct device *dev, dma_addr_t dma_addr, size_t size, |
| 51 | enum dma_data_direction dir) |
| 52 | { |
| 53 | dma_unmap_single(dev, dma_addr, size, dir); |
| 54 | } |
| 55 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 56 | /* |
| 57 | * Map a set of buffers described by scatterlist in streaming |
| 58 | * mode for DMA. This is the scather-gather version of the |
| 59 | * above pci_map_single interface. Here the scatter gather list |
| 60 | * elements are each tagged with the appropriate dma address |
| 61 | * and length. They are obtained via sg_dma_{address,length}(SG). |
| 62 | * |
| 63 | * NOTE: An implementation may be able to use a smaller number of |
| 64 | * DMA address/length pairs than there are SG table elements. |
| 65 | * (for example via virtual mapping capabilities) |
| 66 | * The routine returns the number of addr/length pairs actually |
| 67 | * used, at most nents. |
| 68 | * |
| 69 | * Device ownership issues as mentioned above for pci_map_single are |
| 70 | * the same here. |
| 71 | */ |
| 72 | extern int dma_map_sg(struct device *dev, struct scatterlist *sg, int nents, |
| 73 | enum dma_data_direction direction); |
| 74 | |
| 75 | /* |
| 76 | * Unmap a set of streaming mode DMA translations. |
| 77 | * Again, cpu read rules concerning calls here are the same as for |
| 78 | * pci_unmap_single() above. |
| 79 | */ |
| 80 | extern void dma_unmap_sg(struct device *dev, struct scatterlist *sg, |
| 81 | int nhwentries, enum dma_data_direction direction); |
| 82 | |
| 83 | #endif /* _BLACKFIN_DMA_MAPPING_H */ |