ia64/xen-unstable

view linux-2.6-xen-sparse/include/asm-xen/asm-i386/dma-mapping.h @ 8534:da7873110bbb

Tiny bootstrap cleanup.

Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Mon Jan 09 19:46:46 2006 +0100 (2006-01-09)
parents 06d84bf87159
children
line source
1 #ifndef _ASM_I386_DMA_MAPPING_H
2 #define _ASM_I386_DMA_MAPPING_H
4 /*
5 * IOMMU interface. See Documentation/DMA-mapping.txt and DMA-API.txt for
6 * documentation.
7 */
9 #include <linux/config.h>
10 #include <linux/mm.h>
11 #include <asm/cache.h>
12 #include <asm/io.h>
13 #include <asm/scatterlist.h>
14 #include <asm-i386/swiotlb.h>
16 static inline int
17 address_needs_mapping(struct device *hwdev, dma_addr_t addr)
18 {
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;
24 }
26 static inline int
27 range_straddles_page_boundary(void *p, size_t size)
28 {
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));
32 }
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, unsigned int __nocast flag);
40 void dma_free_coherent(struct device *dev, size_t size,
41 void *vaddr, dma_addr_t dma_handle);
43 extern dma_addr_t
44 dma_map_single(struct device *dev, void *ptr, size_t size,
45 enum dma_data_direction direction);
47 extern void
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);
56 extern dma_addr_t
57 dma_map_page(struct device *dev, struct page *page, unsigned long offset,
58 size_t size, enum dma_data_direction direction);
60 extern void
61 dma_unmap_page(struct device *dev, dma_addr_t dma_address, size_t size,
62 enum dma_data_direction direction);
64 extern void
65 dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle, size_t size,
66 enum dma_data_direction direction);
68 extern void
69 dma_sync_single_for_device(struct device *dev, dma_addr_t dma_handle, size_t size,
70 enum dma_data_direction direction);
72 static inline void
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)
76 {
77 dma_sync_single_for_cpu(dev, dma_handle+offset, size, direction);
78 }
80 static inline void
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)
84 {
85 dma_sync_single_for_device(dev, dma_handle+offset, size, direction);
86 }
88 static inline void
89 dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg, int nelems,
90 enum dma_data_direction direction)
91 {
92 if (swiotlb)
93 swiotlb_sync_sg_for_cpu(dev,sg,nelems,direction);
94 flush_write_buffers();
95 }
97 static inline void
98 dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg, int nelems,
99 enum dma_data_direction direction)
100 {
101 if (swiotlb)
102 swiotlb_sync_sg_for_device(dev,sg,nelems,direction);
103 flush_write_buffers();
104 }
106 extern int
107 dma_mapping_error(dma_addr_t dma_addr);
109 extern int
110 dma_supported(struct device *dev, u64 mask);
112 static inline int
113 dma_set_mask(struct device *dev, u64 mask)
114 {
115 if(!dev->dma_mask || !dma_supported(dev, mask))
116 return -EIO;
118 *dev->dma_mask = mask;
120 return 0;
121 }
123 #ifdef __i386__
124 static inline int
125 dma_get_cache_alignment(void)
126 {
127 /* no easy way to get cache size on all x86, so return the
128 * maximum possible, to be safe */
129 return (1 << L1_CACHE_SHIFT_MAX);
130 }
131 #else
132 extern int dma_get_cache_alignment(void);
133 #endif
135 #define dma_is_consistent(d) (1)
137 static inline void
138 dma_cache_sync(void *vaddr, size_t size,
139 enum dma_data_direction direction)
140 {
141 flush_write_buffers();
142 }
144 #define ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY
145 extern int
146 dma_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr,
147 dma_addr_t device_addr, size_t size, int flags);
149 extern void
150 dma_release_declared_memory(struct device *dev);
152 extern void *
153 dma_mark_declared_memory_occupied(struct device *dev,
154 dma_addr_t device_addr, size_t size);
156 #endif