Glauber Costa | 6f53663 | 2008-03-25 18:36:20 -0300 | [diff] [blame] | 1 | #ifndef _ASM_DMA_MAPPING_H_ |
| 2 | #define _ASM_DMA_MAPPING_H_ |
| 3 | |
| 4 | /* |
| 5 | * IOMMU interface. See Documentation/DMA-mapping.txt and DMA-API.txt for |
| 6 | * documentation. |
| 7 | */ |
| 8 | |
| 9 | #include <linux/scatterlist.h> |
| 10 | #include <asm/io.h> |
| 11 | #include <asm/swiotlb.h> |
| 12 | |
| 13 | struct dma_mapping_ops { |
| 14 | int (*mapping_error)(dma_addr_t dma_addr); |
| 15 | void* (*alloc_coherent)(struct device *dev, size_t size, |
| 16 | dma_addr_t *dma_handle, gfp_t gfp); |
| 17 | void (*free_coherent)(struct device *dev, size_t size, |
| 18 | void *vaddr, dma_addr_t dma_handle); |
| 19 | dma_addr_t (*map_single)(struct device *hwdev, void *ptr, |
| 20 | size_t size, int direction); |
| 21 | /* like map_single, but doesn't check the device mask */ |
| 22 | dma_addr_t (*map_simple)(struct device *hwdev, char *ptr, |
| 23 | size_t size, int direction); |
| 24 | void (*unmap_single)(struct device *dev, dma_addr_t addr, |
| 25 | size_t size, int direction); |
| 26 | void (*sync_single_for_cpu)(struct device *hwdev, |
| 27 | dma_addr_t dma_handle, size_t size, |
| 28 | int direction); |
| 29 | void (*sync_single_for_device)(struct device *hwdev, |
| 30 | dma_addr_t dma_handle, size_t size, |
| 31 | int direction); |
| 32 | void (*sync_single_range_for_cpu)(struct device *hwdev, |
| 33 | dma_addr_t dma_handle, unsigned long offset, |
| 34 | size_t size, int direction); |
| 35 | void (*sync_single_range_for_device)(struct device *hwdev, |
| 36 | dma_addr_t dma_handle, unsigned long offset, |
| 37 | size_t size, int direction); |
| 38 | void (*sync_sg_for_cpu)(struct device *hwdev, |
| 39 | struct scatterlist *sg, int nelems, |
| 40 | int direction); |
| 41 | void (*sync_sg_for_device)(struct device *hwdev, |
| 42 | struct scatterlist *sg, int nelems, |
| 43 | int direction); |
| 44 | int (*map_sg)(struct device *hwdev, struct scatterlist *sg, |
| 45 | int nents, int direction); |
| 46 | void (*unmap_sg)(struct device *hwdev, |
| 47 | struct scatterlist *sg, int nents, |
| 48 | int direction); |
| 49 | int (*dma_supported)(struct device *hwdev, u64 mask); |
| 50 | int is_phys; |
| 51 | }; |
| 52 | |
Glauber Costa | 22456b9 | 2008-03-25 18:36:21 -0300 | [diff] [blame] | 53 | extern const struct dma_mapping_ops *dma_ops; |
| 54 | |
Thomas Gleixner | 96a388d | 2007-10-11 11:20:03 +0200 | [diff] [blame] | 55 | #ifdef CONFIG_X86_32 |
| 56 | # include "dma-mapping_32.h" |
| 57 | #else |
| 58 | # include "dma-mapping_64.h" |
| 59 | #endif |
Glauber Costa | 6f53663 | 2008-03-25 18:36:20 -0300 | [diff] [blame] | 60 | |
Glauber Costa | 22456b9 | 2008-03-25 18:36:21 -0300 | [diff] [blame] | 61 | static inline dma_addr_t |
| 62 | dma_map_single(struct device *hwdev, void *ptr, size_t size, |
| 63 | int direction) |
| 64 | { |
| 65 | BUG_ON(!valid_dma_direction(direction)); |
| 66 | return dma_ops->map_single(hwdev, ptr, size, direction); |
| 67 | } |
| 68 | |
Glauber Costa | 0cb0ae6 | 2008-03-25 18:36:22 -0300 | [diff] [blame] | 69 | static inline void |
| 70 | dma_unmap_single(struct device *dev, dma_addr_t addr, size_t size, |
| 71 | int direction) |
| 72 | { |
| 73 | BUG_ON(!valid_dma_direction(direction)); |
| 74 | if (dma_ops->unmap_single) |
| 75 | dma_ops->unmap_single(dev, addr, size, direction); |
| 76 | } |
| 77 | |
Glauber Costa | 16a3ce9 | 2008-03-25 18:36:23 -0300 | [diff] [blame] | 78 | static inline int |
| 79 | dma_map_sg(struct device *hwdev, struct scatterlist *sg, |
| 80 | int nents, int direction) |
| 81 | { |
| 82 | BUG_ON(!valid_dma_direction(direction)); |
| 83 | return dma_ops->map_sg(hwdev, sg, nents, direction); |
| 84 | } |
Glauber Costa | 72c784f | 2008-03-25 18:36:24 -0300 | [diff] [blame] | 85 | |
| 86 | static inline void |
| 87 | dma_unmap_sg(struct device *hwdev, struct scatterlist *sg, int nents, |
| 88 | int direction) |
| 89 | { |
| 90 | BUG_ON(!valid_dma_direction(direction)); |
| 91 | if (dma_ops->unmap_sg) |
| 92 | dma_ops->unmap_sg(hwdev, sg, nents, direction); |
| 93 | } |
Glauber Costa | c01dd8c | 2008-03-25 18:36:25 -0300 | [diff] [blame] | 94 | |
| 95 | static inline void |
| 96 | dma_sync_single_for_cpu(struct device *hwdev, dma_addr_t dma_handle, |
| 97 | size_t size, int direction) |
| 98 | { |
| 99 | BUG_ON(!valid_dma_direction(direction)); |
| 100 | if (dma_ops->sync_single_for_cpu) |
| 101 | dma_ops->sync_single_for_cpu(hwdev, dma_handle, size, |
| 102 | direction); |
| 103 | flush_write_buffers(); |
| 104 | } |
| 105 | |
Glauber Costa | 9231b26 | 2008-03-25 18:36:26 -0300 | [diff] [blame] | 106 | static inline void |
| 107 | dma_sync_single_for_device(struct device *hwdev, dma_addr_t dma_handle, |
| 108 | size_t size, int direction) |
| 109 | { |
| 110 | BUG_ON(!valid_dma_direction(direction)); |
| 111 | if (dma_ops->sync_single_for_device) |
| 112 | dma_ops->sync_single_for_device(hwdev, dma_handle, size, |
| 113 | direction); |
| 114 | flush_write_buffers(); |
| 115 | } |
| 116 | |
Glauber Costa | 627610f | 2008-03-25 18:36:27 -0300 | [diff] [blame] | 117 | static inline void |
| 118 | dma_sync_single_range_for_cpu(struct device *hwdev, dma_addr_t dma_handle, |
| 119 | unsigned long offset, size_t size, int direction) |
| 120 | { |
| 121 | BUG_ON(!valid_dma_direction(direction)); |
| 122 | if (dma_ops->sync_single_range_for_cpu) |
| 123 | dma_ops->sync_single_range_for_cpu(hwdev, dma_handle, offset, |
| 124 | size, direction); |
| 125 | |
| 126 | flush_write_buffers(); |
| 127 | } |
Glauber Costa | 7136233 | 2008-03-25 18:36:28 -0300 | [diff] [blame^] | 128 | |
| 129 | static inline void |
| 130 | dma_sync_single_range_for_device(struct device *hwdev, dma_addr_t dma_handle, |
| 131 | unsigned long offset, size_t size, |
| 132 | int direction) |
| 133 | { |
| 134 | BUG_ON(!valid_dma_direction(direction)); |
| 135 | if (dma_ops->sync_single_range_for_device) |
| 136 | dma_ops->sync_single_range_for_device(hwdev, dma_handle, |
| 137 | offset, size, direction); |
| 138 | |
| 139 | flush_write_buffers(); |
| 140 | } |
| 141 | |
Glauber Costa | 6f53663 | 2008-03-25 18:36:20 -0300 | [diff] [blame] | 142 | #endif |