nfsd4: typo logical vs bitwise negate for want_mask
[linux-btrfs-devel.git] / arch / mn10300 / include / asm / dma-mapping.h
blobc1be4397b1edb4b059e917331c5ef8173bcf1096
1 /* DMA mapping routines for the MN10300 arch
3 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public Licence
8 * as published by the Free Software Foundation; either version
9 * 2 of the Licence, or (at your option) any later version.
11 #ifndef _ASM_DMA_MAPPING_H
12 #define _ASM_DMA_MAPPING_H
14 #include <linux/mm.h>
15 #include <linux/scatterlist.h>
17 #include <asm/cache.h>
18 #include <asm/io.h>
21 * See Documentation/DMA-API.txt for the description of how the
22 * following DMA API should work.
25 extern void *dma_alloc_coherent(struct device *dev, size_t size,
26 dma_addr_t *dma_handle, int flag);
28 extern void dma_free_coherent(struct device *dev, size_t size,
29 void *vaddr, dma_addr_t dma_handle);
31 #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent((d), (s), (h), (f))
32 #define dma_free_noncoherent(d, s, v, h) dma_free_coherent((d), (s), (v), (h))
34 static inline
35 dma_addr_t dma_map_single(struct device *dev, void *ptr, size_t size,
36 enum dma_data_direction direction)
38 BUG_ON(direction == DMA_NONE);
39 mn10300_dcache_flush_inv();
40 return virt_to_bus(ptr);
43 static inline
44 void dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size,
45 enum dma_data_direction direction)
47 BUG_ON(direction == DMA_NONE);
50 static inline
51 int dma_map_sg(struct device *dev, struct scatterlist *sglist, int nents,
52 enum dma_data_direction direction)
54 struct scatterlist *sg;
55 int i;
57 BUG_ON(!valid_dma_direction(direction));
58 WARN_ON(nents == 0 || sglist[0].length == 0);
60 for_each_sg(sglist, sg, nents, i) {
61 BUG_ON(!sg_page(sg));
63 sg->dma_address = sg_phys(sg);
66 mn10300_dcache_flush_inv();
67 return nents;
70 static inline
71 void dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nhwentries,
72 enum dma_data_direction direction)
74 BUG_ON(!valid_dma_direction(direction));
77 static inline
78 dma_addr_t dma_map_page(struct device *dev, struct page *page,
79 unsigned long offset, size_t size,
80 enum dma_data_direction direction)
82 BUG_ON(direction == DMA_NONE);
83 return page_to_bus(page) + offset;
86 static inline
87 void dma_unmap_page(struct device *dev, dma_addr_t dma_address, size_t size,
88 enum dma_data_direction direction)
90 BUG_ON(direction == DMA_NONE);
93 static inline
94 void dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle,
95 size_t size, enum dma_data_direction direction)
99 static inline
100 void dma_sync_single_for_device(struct device *dev, dma_addr_t dma_handle,
101 size_t size, enum dma_data_direction direction)
103 mn10300_dcache_flush_inv();
106 static inline
107 void dma_sync_single_range_for_cpu(struct device *dev, dma_addr_t dma_handle,
108 unsigned long offset, size_t size,
109 enum dma_data_direction direction)
113 static inline void
114 dma_sync_single_range_for_device(struct device *dev, dma_addr_t dma_handle,
115 unsigned long offset, size_t size,
116 enum dma_data_direction direction)
118 mn10300_dcache_flush_inv();
122 static inline
123 void dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
124 int nelems, enum dma_data_direction direction)
128 static inline
129 void dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
130 int nelems, enum dma_data_direction direction)
132 mn10300_dcache_flush_inv();
135 static inline
136 int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
138 return 0;
141 static inline
142 int dma_supported(struct device *dev, u64 mask)
145 * we fall back to GFP_DMA when the mask isn't all 1s, so we can't
146 * guarantee allocations that must be within a tighter range than
147 * GFP_DMA
149 if (mask < 0x00ffffff)
150 return 0;
151 return 1;
154 static inline
155 int dma_set_mask(struct device *dev, u64 mask)
157 if (!dev->dma_mask || !dma_supported(dev, mask))
158 return -EIO;
160 *dev->dma_mask = mask;
161 return 0;
164 static inline
165 void dma_cache_sync(void *vaddr, size_t size,
166 enum dma_data_direction direction)
168 mn10300_dcache_flush_inv();
171 #endif