1 #ifndef _ASM_I386_DMA_MAPPING_H
2 #define _ASM_I386_DMA_MAPPING_H
5 * IOMMU interface. See Documentation/DMA-mapping.txt and DMA-API.txt for
9 #include <linux/config.h>
11 #include <asm/cache.h>
13 #include <asm/scatterlist.h>
14 #include <asm/swiotlb.h>
17 address_needs_mapping(struct device *hwdev, dma_addr_t addr)
19 dma_addr_t mask = 0xffffffff;
20 /* If the device has a mask, use it, otherwise default to 32 bits */
21 if (hwdev && hwdev->dma_mask)
22 mask = *hwdev->dma_mask;
23 return (addr & ~mask) != 0;
27 range_straddles_page_boundary(void *p, size_t size)
29 extern unsigned long *contiguous_bitmap;
30 return (((((unsigned long)p & ~PAGE_MASK) + size) > PAGE_SIZE) &&
31 !test_bit(__pa(p) >> PAGE_SHIFT, contiguous_bitmap));
34 #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
35 #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
37 void *dma_alloc_coherent(struct device *dev, size_t size,
38 dma_addr_t *dma_handle, gfp_t flag);
40 void dma_free_coherent(struct device *dev, size_t size,
41 void *vaddr, dma_addr_t dma_handle);
44 dma_map_single(struct device *dev, void *ptr, size_t size,
45 enum dma_data_direction direction);
48 dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size,
49 enum dma_data_direction direction);
51 extern int dma_map_sg(struct device *hwdev, struct scatterlist *sg,
52 int nents, enum dma_data_direction direction);
53 extern void dma_unmap_sg(struct device *hwdev, struct scatterlist *sg,
54 int nents, enum dma_data_direction direction);
57 dma_map_page(struct device *dev, struct page *page, unsigned long offset,
58 size_t size, enum dma_data_direction direction);
61 dma_unmap_page(struct device *dev, dma_addr_t dma_address, size_t size,
62 enum dma_data_direction direction);
65 dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle, size_t size,
66 enum dma_data_direction direction);
69 dma_sync_single_for_device(struct device *dev, dma_addr_t dma_handle, size_t size,
70 enum dma_data_direction direction);
73 dma_sync_single_range_for_cpu(struct device *dev, dma_addr_t dma_handle,
74 unsigned long offset, size_t size,
75 enum dma_data_direction direction)
77 dma_sync_single_for_cpu(dev, dma_handle+offset, size, direction);
81 dma_sync_single_range_for_device(struct device *dev, dma_addr_t dma_handle,
82 unsigned long offset, size_t size,
83 enum dma_data_direction direction)
85 dma_sync_single_for_device(dev, dma_handle+offset, size, direction);
89 dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg, int nelems,
90 enum dma_data_direction direction)
93 swiotlb_sync_sg_for_cpu(dev,sg,nelems,direction);
94 flush_write_buffers();
98 dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg, int nelems,
99 enum dma_data_direction direction)
102 swiotlb_sync_sg_for_device(dev,sg,nelems,direction);
103 flush_write_buffers();
107 dma_mapping_error(dma_addr_t dma_addr);
110 dma_supported(struct device *dev, u64 mask);
113 dma_set_mask(struct device *dev, u64 mask)
115 if(!dev->dma_mask || !dma_supported(dev, mask))
118 *dev->dma_mask = mask;
124 dma_get_cache_alignment(void)
126 /* no easy way to get cache size on all x86, so return the
127 * maximum possible, to be safe */
128 return (1 << INTERNODE_CACHE_SHIFT);
131 #define dma_is_consistent(d) (1)
134 dma_cache_sync(void *vaddr, size_t size,
135 enum dma_data_direction direction)
137 flush_write_buffers();
140 #define ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY
142 dma_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr,
143 dma_addr_t device_addr, size_t size, int flags);
146 dma_release_declared_memory(struct device *dev);
149 dma_mark_declared_memory_occupied(struct device *dev,
150 dma_addr_t device_addr, size_t size);