diff options
Diffstat (limited to 'arch/blackfin/kernel/dma-mapping.c')
-rw-r--r-- | arch/blackfin/kernel/dma-mapping.c | 95 |
1 files changed, 28 insertions, 67 deletions
diff --git a/arch/blackfin/kernel/dma-mapping.c b/arch/blackfin/kernel/dma-mapping.c index 2f62a9f4058a..e937f323d82c 100644 --- a/arch/blackfin/kernel/dma-mapping.c +++ b/arch/blackfin/kernel/dma-mapping.c | |||
@@ -1,57 +1,31 @@ | |||
1 | /* | 1 | /* |
2 | * File: arch/blackfin/kernel/dma-mapping.c | 2 | * Dynamic DMA mapping support |
3 | * Based on: | ||
4 | * Author: | ||
5 | * | 3 | * |
6 | * Created: | 4 | * Copyright 2005-2009 Analog Devices Inc. |
7 | * Description: Dynamic DMA mapping support. | ||
8 | * | 5 | * |
9 | * Modified: | 6 | * Licensed under the GPL-2 or later |
10 | * Copyright 2004-2006 Analog Devices Inc. | ||
11 | * | ||
12 | * Bugs: Enter bugs at http://blackfin.uclinux.org/ | ||
13 | * | ||
14 | * This program is free software; you can redistribute it and/or modify | ||
15 | * it under the terms of the GNU General Public License as published by | ||
16 | * the Free Software Foundation; either version 2 of the License, or | ||
17 | * (at your option) any later version. | ||
18 | * | ||
19 | * This program is distributed in the hope that it will be useful, | ||
20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
22 | * GNU General Public License for more details. | ||
23 | * | ||
24 | * You should have received a copy of the GNU General Public License | ||
25 | * along with this program; if not, see the file COPYING, or write | ||
26 | * to the Free Software Foundation, Inc., | ||
27 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
28 | */ | 7 | */ |
29 | 8 | ||
30 | #include <linux/types.h> | 9 | #include <linux/types.h> |
31 | #include <linux/mm.h> | 10 | #include <linux/gfp.h> |
32 | #include <linux/string.h> | 11 | #include <linux/string.h> |
33 | #include <linux/bootmem.h> | ||
34 | #include <linux/spinlock.h> | 12 | #include <linux/spinlock.h> |
35 | #include <linux/device.h> | ||
36 | #include <linux/dma-mapping.h> | 13 | #include <linux/dma-mapping.h> |
37 | #include <linux/io.h> | ||
38 | #include <linux/scatterlist.h> | 14 | #include <linux/scatterlist.h> |
39 | #include <asm/cacheflush.h> | ||
40 | #include <asm/bfin-global.h> | ||
41 | 15 | ||
42 | static spinlock_t dma_page_lock; | 16 | static spinlock_t dma_page_lock; |
43 | static unsigned int *dma_page; | 17 | static unsigned long *dma_page; |
44 | static unsigned int dma_pages; | 18 | static unsigned int dma_pages; |
45 | static unsigned long dma_base; | 19 | static unsigned long dma_base; |
46 | static unsigned long dma_size; | 20 | static unsigned long dma_size; |
47 | static unsigned int dma_initialized; | 21 | static unsigned int dma_initialized; |
48 | 22 | ||
49 | void dma_alloc_init(unsigned long start, unsigned long end) | 23 | static void dma_alloc_init(unsigned long start, unsigned long end) |
50 | { | 24 | { |
51 | spin_lock_init(&dma_page_lock); | 25 | spin_lock_init(&dma_page_lock); |
52 | dma_initialized = 0; | 26 | dma_initialized = 0; |
53 | 27 | ||
54 | dma_page = (unsigned int *)__get_free_page(GFP_KERNEL); | 28 | dma_page = (unsigned long *)__get_free_page(GFP_KERNEL); |
55 | memset(dma_page, 0, PAGE_SIZE); | 29 | memset(dma_page, 0, PAGE_SIZE); |
56 | dma_base = PAGE_ALIGN(start); | 30 | dma_base = PAGE_ALIGN(start); |
57 | dma_size = PAGE_ALIGN(end) - PAGE_ALIGN(start); | 31 | dma_size = PAGE_ALIGN(end) - PAGE_ALIGN(start); |
@@ -79,10 +53,11 @@ static unsigned long __alloc_dma_pages(unsigned int pages) | |||
79 | spin_lock_irqsave(&dma_page_lock, flags); | 53 | spin_lock_irqsave(&dma_page_lock, flags); |
80 | 54 | ||
81 | for (i = 0; i < dma_pages;) { | 55 | for (i = 0; i < dma_pages;) { |
82 | if (dma_page[i++] == 0) { | 56 | if (test_bit(i++, dma_page) == 0) { |
83 | if (++count == pages) { | 57 | if (++count == pages) { |
84 | while (count--) | 58 | while (count--) |
85 | dma_page[--i] = 1; | 59 | __set_bit(--i, dma_page); |
60 | |||
86 | ret = dma_base + (i << PAGE_SHIFT); | 61 | ret = dma_base + (i << PAGE_SHIFT); |
87 | break; | 62 | break; |
88 | } | 63 | } |
@@ -105,14 +80,14 @@ static void __free_dma_pages(unsigned long addr, unsigned int pages) | |||
105 | } | 80 | } |
106 | 81 | ||
107 | spin_lock_irqsave(&dma_page_lock, flags); | 82 | spin_lock_irqsave(&dma_page_lock, flags); |
108 | for (i = page; i < page + pages; i++) { | 83 | for (i = page; i < page + pages; i++) |
109 | dma_page[i] = 0; | 84 | __clear_bit(i, dma_page); |
110 | } | 85 | |
111 | spin_unlock_irqrestore(&dma_page_lock, flags); | 86 | spin_unlock_irqrestore(&dma_page_lock, flags); |
112 | } | 87 | } |
113 | 88 | ||
114 | void *dma_alloc_coherent(struct device *dev, size_t size, | 89 | void *dma_alloc_coherent(struct device *dev, size_t size, |
115 | dma_addr_t * dma_handle, gfp_t gfp) | 90 | dma_addr_t *dma_handle, gfp_t gfp) |
116 | { | 91 | { |
117 | void *ret; | 92 | void *ret; |
118 | 93 | ||
@@ -136,21 +111,14 @@ dma_free_coherent(struct device *dev, size_t size, void *vaddr, | |||
136 | EXPORT_SYMBOL(dma_free_coherent); | 111 | EXPORT_SYMBOL(dma_free_coherent); |
137 | 112 | ||
138 | /* | 113 | /* |
139 | * Dummy functions defined for some existing drivers | 114 | * Streaming DMA mappings |
140 | */ | 115 | */ |
141 | 116 | void __dma_sync(dma_addr_t addr, size_t size, | |
142 | dma_addr_t | 117 | enum dma_data_direction dir) |
143 | dma_map_single(struct device *dev, void *ptr, size_t size, | ||
144 | enum dma_data_direction direction) | ||
145 | { | 118 | { |
146 | BUG_ON(direction == DMA_NONE); | 119 | _dma_sync(addr, size, dir); |
147 | |||
148 | invalidate_dcache_range((unsigned long)ptr, | ||
149 | (unsigned long)ptr + size); | ||
150 | |||
151 | return (dma_addr_t) ptr; | ||
152 | } | 120 | } |
153 | EXPORT_SYMBOL(dma_map_single); | 121 | EXPORT_SYMBOL(__dma_sync); |
154 | 122 | ||
155 | int | 123 | int |
156 | dma_map_sg(struct device *dev, struct scatterlist *sg, int nents, | 124 | dma_map_sg(struct device *dev, struct scatterlist *sg, int nents, |
@@ -158,30 +126,23 @@ dma_map_sg(struct device *dev, struct scatterlist *sg, int nents, | |||
158 | { | 126 | { |
159 | int i; | 127 | int i; |
160 | 128 | ||
161 | BUG_ON(direction == DMA_NONE); | ||
162 | |||
163 | for (i = 0; i < nents; i++, sg++) { | 129 | for (i = 0; i < nents; i++, sg++) { |
164 | sg->dma_address = (dma_addr_t) sg_virt(sg); | 130 | sg->dma_address = (dma_addr_t) sg_virt(sg); |
165 | 131 | __dma_sync(sg_dma_address(sg), sg_dma_len(sg), direction); | |
166 | invalidate_dcache_range(sg_dma_address(sg), | ||
167 | sg_dma_address(sg) + | ||
168 | sg_dma_len(sg)); | ||
169 | } | 132 | } |
170 | 133 | ||
171 | return nents; | 134 | return nents; |
172 | } | 135 | } |
173 | EXPORT_SYMBOL(dma_map_sg); | 136 | EXPORT_SYMBOL(dma_map_sg); |
174 | 137 | ||
175 | void dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size, | 138 | void dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg, |
176 | enum dma_data_direction direction) | 139 | int nelems, enum dma_data_direction direction) |
177 | { | 140 | { |
178 | BUG_ON(direction == DMA_NONE); | 141 | int i; |
179 | } | ||
180 | EXPORT_SYMBOL(dma_unmap_single); | ||
181 | 142 | ||
182 | void dma_unmap_sg(struct device *dev, struct scatterlist *sg, | 143 | for (i = 0; i < nelems; i++, sg++) { |
183 | int nhwentries, enum dma_data_direction direction) | 144 | sg->dma_address = (dma_addr_t) sg_virt(sg); |
184 | { | 145 | __dma_sync(sg_dma_address(sg), sg_dma_len(sg), direction); |
185 | BUG_ON(direction == DMA_NONE); | 146 | } |
186 | } | 147 | } |
187 | EXPORT_SYMBOL(dma_unmap_sg); | 148 | EXPORT_SYMBOL(dma_sync_sg_for_device); |