Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef _ASM_IA64_DMA_MAPPING_H |
| 2 | #define _ASM_IA64_DMA_MAPPING_H |
| 3 | |
| 4 | /* |
| 5 | * Copyright (C) 2003-2004 Hewlett-Packard Co |
| 6 | * David Mosberger-Tang <davidm@hpl.hp.com> |
| 7 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #include <asm/machvec.h> |
Jens Axboe | 9b6eccf | 2007-10-16 11:27:26 +0200 | [diff] [blame] | 9 | #include <linux/scatterlist.h> |
Fenghua Yu | 62fdd76 | 2008-10-17 12:14:13 -0700 | [diff] [blame] | 10 | #include <asm/swiotlb.h> |
FUJITA Tomonori | 9916219 | 2009-06-17 16:28:14 -0700 | [diff] [blame] | 11 | #include <linux/dma-debug.h> |
Fenghua Yu | 62fdd76 | 2008-10-17 12:14:13 -0700 | [diff] [blame] | 12 | |
John Keller | 175add1 | 2008-11-24 16:47:17 -0600 | [diff] [blame] | 13 | #define ARCH_HAS_DMA_GET_REQUIRED_MASK |
| 14 | |
Konrad Rzeszutek Wilk | 9f97535 | 2010-12-06 18:24:32 -0500 | [diff] [blame] | 15 | #define DMA_ERROR_CODE 0 |
| 16 | |
FUJITA Tomonori | 160c1d8 | 2009-01-05 23:59:02 +0900 | [diff] [blame] | 17 | extern struct dma_map_ops *dma_ops; |
Fenghua Yu | 62fdd76 | 2008-10-17 12:14:13 -0700 | [diff] [blame] | 18 | extern struct ia64_machine_vector ia64_mv; |
| 19 | extern void set_iommu_machvec(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | |
FUJITA Tomonori | c299030 | 2009-01-07 02:13:42 +0900 | [diff] [blame] | 21 | extern void machvec_dma_sync_single(struct device *, dma_addr_t, size_t, |
| 22 | enum dma_data_direction); |
| 23 | extern void machvec_dma_sync_sg(struct device *, struct scatterlist *, int, |
| 24 | enum dma_data_direction); |
| 25 | |
Andrzej Pietrasiewicz | baa676f | 2012-03-27 14:28:18 +0200 | [diff] [blame] | 26 | #define dma_alloc_coherent(d,s,h,f) dma_alloc_attrs(d,s,h,f,NULL) |
| 27 | |
| 28 | static inline void *dma_alloc_attrs(struct device *dev, size_t size, |
| 29 | dma_addr_t *daddr, gfp_t gfp, |
| 30 | struct dma_attrs *attrs) |
FUJITA Tomonori | b7ea6e9 | 2009-01-05 23:36:13 +0900 | [diff] [blame] | 31 | { |
FUJITA Tomonori | 160c1d8 | 2009-01-05 23:59:02 +0900 | [diff] [blame] | 32 | struct dma_map_ops *ops = platform_dma_get_ops(dev); |
FUJITA Tomonori | 9916219 | 2009-06-17 16:28:14 -0700 | [diff] [blame] | 33 | void *caddr; |
| 34 | |
Andrzej Pietrasiewicz | baa676f | 2012-03-27 14:28:18 +0200 | [diff] [blame] | 35 | caddr = ops->alloc(dev, size, daddr, gfp, attrs); |
FUJITA Tomonori | 9916219 | 2009-06-17 16:28:14 -0700 | [diff] [blame] | 36 | debug_dma_alloc_coherent(dev, size, *daddr, caddr); |
| 37 | return caddr; |
FUJITA Tomonori | b7ea6e9 | 2009-01-05 23:36:13 +0900 | [diff] [blame] | 38 | } |
FUJITA Tomonori | 3a80b6a | 2008-09-08 18:10:10 +0900 | [diff] [blame] | 39 | |
Andrzej Pietrasiewicz | baa676f | 2012-03-27 14:28:18 +0200 | [diff] [blame] | 40 | #define dma_free_coherent(d,s,c,h) dma_free_attrs(d,s,c,h,NULL) |
| 41 | |
| 42 | static inline void dma_free_attrs(struct device *dev, size_t size, |
| 43 | void *caddr, dma_addr_t daddr, |
| 44 | struct dma_attrs *attrs) |
Roland Dreier | b7de8e7 | 2007-02-14 00:32:53 -0800 | [diff] [blame] | 45 | { |
FUJITA Tomonori | 160c1d8 | 2009-01-05 23:59:02 +0900 | [diff] [blame] | 46 | struct dma_map_ops *ops = platform_dma_get_ops(dev); |
FUJITA Tomonori | 9916219 | 2009-06-17 16:28:14 -0700 | [diff] [blame] | 47 | debug_dma_free_coherent(dev, size, caddr, daddr); |
Andrzej Pietrasiewicz | baa676f | 2012-03-27 14:28:18 +0200 | [diff] [blame] | 48 | ops->free(dev, size, caddr, daddr, attrs); |
Roland Dreier | b7de8e7 | 2007-02-14 00:32:53 -0800 | [diff] [blame] | 49 | } |
FUJITA Tomonori | b7ea6e9 | 2009-01-05 23:36:13 +0900 | [diff] [blame] | 50 | |
| 51 | #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f) |
| 52 | #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h) |
| 53 | |
FUJITA Tomonori | d6d0a6a | 2009-06-17 16:28:13 -0700 | [diff] [blame] | 54 | #define get_dma_ops(dev) platform_dma_get_ops(dev) |
FUJITA Tomonori | b7ea6e9 | 2009-01-05 23:36:13 +0900 | [diff] [blame] | 55 | |
FUJITA Tomonori | d6d0a6a | 2009-06-17 16:28:13 -0700 | [diff] [blame] | 56 | #include <asm-generic/dma-mapping-common.h> |
FUJITA Tomonori | b7ea6e9 | 2009-01-05 23:36:13 +0900 | [diff] [blame] | 57 | |
| 58 | static inline int dma_mapping_error(struct device *dev, dma_addr_t daddr) |
| 59 | { |
FUJITA Tomonori | 160c1d8 | 2009-01-05 23:59:02 +0900 | [diff] [blame] | 60 | struct dma_map_ops *ops = platform_dma_get_ops(dev); |
FUJITA Tomonori | c190ab0 | 2009-01-05 23:36:16 +0900 | [diff] [blame] | 61 | return ops->mapping_error(dev, daddr); |
FUJITA Tomonori | b7ea6e9 | 2009-01-05 23:36:13 +0900 | [diff] [blame] | 62 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | |
FUJITA Tomonori | b7ea6e9 | 2009-01-05 23:36:13 +0900 | [diff] [blame] | 64 | static inline int dma_supported(struct device *dev, u64 mask) |
| 65 | { |
FUJITA Tomonori | 160c1d8 | 2009-01-05 23:59:02 +0900 | [diff] [blame] | 66 | struct dma_map_ops *ops = platform_dma_get_ops(dev); |
| 67 | return ops->dma_supported(dev, mask); |
FUJITA Tomonori | b7ea6e9 | 2009-01-05 23:36:13 +0900 | [diff] [blame] | 68 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
| 70 | static inline int |
| 71 | dma_set_mask (struct device *dev, u64 mask) |
| 72 | { |
| 73 | if (!dev->dma_mask || !dma_supported(dev, mask)) |
| 74 | return -EIO; |
| 75 | *dev->dma_mask = mask; |
| 76 | return 0; |
| 77 | } |
| 78 | |
FUJITA Tomonori | a0b00ca | 2009-07-10 10:04:56 +0900 | [diff] [blame] | 79 | static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size) |
| 80 | { |
| 81 | if (!dev->dma_mask) |
| 82 | return 0; |
| 83 | |
Jan Beulich | ac2b3e6 | 2009-12-15 16:47:43 -0800 | [diff] [blame] | 84 | return addr + size - 1 <= *dev->dma_mask; |
FUJITA Tomonori | a0b00ca | 2009-07-10 10:04:56 +0900 | [diff] [blame] | 85 | } |
| 86 | |
FUJITA Tomonori | 8d4f533 | 2009-07-10 10:05:01 +0900 | [diff] [blame] | 87 | static inline dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr) |
| 88 | { |
| 89 | return paddr; |
| 90 | } |
| 91 | |
| 92 | static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr) |
| 93 | { |
| 94 | return daddr; |
| 95 | } |
| 96 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | static inline void |
Ralf Baechle | d3fa72e | 2006-12-06 20:38:56 -0800 | [diff] [blame] | 98 | dma_cache_sync (struct device *dev, void *vaddr, size_t size, |
| 99 | enum dma_data_direction dir) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | { |
| 101 | /* |
| 102 | * IA-64 is cache-coherent, so this is mostly a no-op. However, we do need to |
| 103 | * ensure that dma_cache_sync() enforces order, hence the mb(). |
| 104 | */ |
| 105 | mb(); |
| 106 | } |
| 107 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | #endif /* _ASM_IA64_DMA_MAPPING_H */ |