Sam Ravnborg | a439fe5 | 2008-07-27 23:00:59 +0200 | [diff] [blame] | 1 | #ifndef ___ASM_SPARC_DMA_MAPPING_H |
| 2 | #define ___ASM_SPARC_DMA_MAPPING_H |
FUJITA Tomonori | d698641 | 2009-05-14 16:23:11 +0000 | [diff] [blame] | 3 | |
| 4 | #include <linux/scatterlist.h> |
| 5 | #include <linux/mm.h> |
FUJITA Tomonori | 02f7a18 | 2009-08-10 11:53:13 +0900 | [diff] [blame] | 6 | #include <linux/dma-debug.h> |
FUJITA Tomonori | b9f69f4 | 2009-05-14 16:23:08 +0000 | [diff] [blame] | 7 | |
| 8 | #define DMA_ERROR_CODE (~(dma_addr_t)0x0) |
| 9 | |
| 10 | extern int dma_supported(struct device *dev, u64 mask); |
FUJITA Tomonori | b9f69f4 | 2009-05-14 16:23:08 +0000 | [diff] [blame] | 11 | |
FUJITA Tomonori | b9f69f4 | 2009-05-14 16:23:08 +0000 | [diff] [blame] | 12 | #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f) |
| 13 | #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h) |
FUJITA Tomonori | b9f69f4 | 2009-05-14 16:23:08 +0000 | [diff] [blame] | 14 | |
FUJITA Tomonori | ee664a9 | 2009-08-10 11:53:16 +0900 | [diff] [blame] | 15 | extern struct dma_map_ops *dma_ops, pci32_dma_ops; |
| 16 | extern struct bus_type pci_bus_type; |
FUJITA Tomonori | 02f7a18 | 2009-08-10 11:53:13 +0900 | [diff] [blame] | 17 | |
| 18 | static inline struct dma_map_ops *get_dma_ops(struct device *dev) |
| 19 | { |
FUJITA Tomonori | ee664a9 | 2009-08-10 11:53:16 +0900 | [diff] [blame] | 20 | #if defined(CONFIG_SPARC32) && defined(CONFIG_PCI) |
| 21 | if (dev->bus == &pci_bus_type) |
| 22 | return &pci32_dma_ops; |
| 23 | #endif |
FUJITA Tomonori | 02f7a18 | 2009-08-10 11:53:13 +0900 | [diff] [blame] | 24 | return dma_ops; |
| 25 | } |
| 26 | |
| 27 | #include <asm-generic/dma-mapping-common.h> |
FUJITA Tomonori | d698641 | 2009-05-14 16:23:11 +0000 | [diff] [blame] | 28 | |
Andrzej Pietrasiewicz | c416258 | 2012-03-27 14:56:55 +0200 | [diff] [blame^] | 29 | #define dma_alloc_coherent(d,s,h,f) dma_alloc_attrs(d,s,h,f,NULL) |
| 30 | |
| 31 | static inline void *dma_alloc_attrs(struct device *dev, size_t size, |
| 32 | dma_addr_t *dma_handle, gfp_t flag, |
| 33 | struct dma_attrs *attrs) |
FUJITA Tomonori | d698641 | 2009-05-14 16:23:11 +0000 | [diff] [blame] | 34 | { |
FUJITA Tomonori | 02f7a18 | 2009-08-10 11:53:13 +0900 | [diff] [blame] | 35 | struct dma_map_ops *ops = get_dma_ops(dev); |
FUJITA Tomonori | 451d740 | 2009-08-10 11:53:17 +0900 | [diff] [blame] | 36 | void *cpu_addr; |
FUJITA Tomonori | 02f7a18 | 2009-08-10 11:53:13 +0900 | [diff] [blame] | 37 | |
Andrzej Pietrasiewicz | c416258 | 2012-03-27 14:56:55 +0200 | [diff] [blame^] | 38 | cpu_addr = ops->alloc(dev, size, dma_handle, flag, attrs); |
FUJITA Tomonori | 451d740 | 2009-08-10 11:53:17 +0900 | [diff] [blame] | 39 | debug_dma_alloc_coherent(dev, size, *dma_handle, cpu_addr); |
| 40 | return cpu_addr; |
FUJITA Tomonori | d698641 | 2009-05-14 16:23:11 +0000 | [diff] [blame] | 41 | } |
| 42 | |
Andrzej Pietrasiewicz | c416258 | 2012-03-27 14:56:55 +0200 | [diff] [blame^] | 43 | #define dma_free_coherent(d,s,c,h) dma_free_attrs(d,s,c,h,NULL) |
| 44 | |
| 45 | static inline void dma_free_attrs(struct device *dev, size_t size, |
| 46 | void *cpu_addr, dma_addr_t dma_handle, |
| 47 | struct dma_attrs *attrs) |
FUJITA Tomonori | d698641 | 2009-05-14 16:23:11 +0000 | [diff] [blame] | 48 | { |
FUJITA Tomonori | 02f7a18 | 2009-08-10 11:53:13 +0900 | [diff] [blame] | 49 | struct dma_map_ops *ops = get_dma_ops(dev); |
FUJITA Tomonori | d698641 | 2009-05-14 16:23:11 +0000 | [diff] [blame] | 50 | |
FUJITA Tomonori | 451d740 | 2009-08-10 11:53:17 +0900 | [diff] [blame] | 51 | debug_dma_free_coherent(dev, size, cpu_addr, dma_handle); |
Andrzej Pietrasiewicz | c416258 | 2012-03-27 14:56:55 +0200 | [diff] [blame^] | 52 | ops->free(dev, size, cpu_addr, dma_handle, attrs); |
FUJITA Tomonori | d698641 | 2009-05-14 16:23:11 +0000 | [diff] [blame] | 53 | } |
| 54 | |
FUJITA Tomonori | d698641 | 2009-05-14 16:23:11 +0000 | [diff] [blame] | 55 | static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr) |
| 56 | { |
| 57 | return (dma_addr == DMA_ERROR_CODE); |
| 58 | } |
| 59 | |
FUJITA Tomonori | 3490042 | 2010-03-10 15:23:35 -0800 | [diff] [blame] | 60 | static inline int dma_set_mask(struct device *dev, u64 mask) |
| 61 | { |
| 62 | #ifdef CONFIG_PCI |
| 63 | if (dev->bus == &pci_bus_type) { |
| 64 | if (!dev->dma_mask || !dma_supported(dev, mask)) |
| 65 | return -EINVAL; |
| 66 | *dev->dma_mask = mask; |
| 67 | return 0; |
| 68 | } |
| 69 | #endif |
| 70 | return -EINVAL; |
| 71 | } |
| 72 | |
Sam Ravnborg | a439fe5 | 2008-07-27 23:00:59 +0200 | [diff] [blame] | 73 | #endif |