aboutsummaryrefslogtreecommitdiffstats
path: root/arch/blackfin/kernel/dma-mapping.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/blackfin/kernel/dma-mapping.c')
-rw-r--r--arch/blackfin/kernel/dma-mapping.c68
1 files changed, 25 insertions, 43 deletions
diff --git a/arch/blackfin/kernel/dma-mapping.c b/arch/blackfin/kernel/dma-mapping.c
index e74e74d7733f..e937f323d82c 100644
--- a/arch/blackfin/kernel/dma-mapping.c
+++ b/arch/blackfin/kernel/dma-mapping.c
@@ -7,30 +7,25 @@
7 */ 7 */
8 8
9#include <linux/types.h> 9#include <linux/types.h>
10#include <linux/mm.h> 10#include <linux/gfp.h>
11#include <linux/string.h> 11#include <linux/string.h>
12#include <linux/bootmem.h>
13#include <linux/spinlock.h> 12#include <linux/spinlock.h>
14#include <linux/device.h>
15#include <linux/dma-mapping.h> 13#include <linux/dma-mapping.h>
16#include <linux/io.h>
17#include <linux/scatterlist.h> 14#include <linux/scatterlist.h>
18#include <asm/cacheflush.h>
19#include <asm/bfin-global.h>
20 15
21static spinlock_t dma_page_lock; 16static spinlock_t dma_page_lock;
22static unsigned int *dma_page; 17static unsigned long *dma_page;
23static unsigned int dma_pages; 18static unsigned int dma_pages;
24static unsigned long dma_base; 19static unsigned long dma_base;
25static unsigned long dma_size; 20static unsigned long dma_size;
26static unsigned int dma_initialized; 21static unsigned int dma_initialized;
27 22
28void dma_alloc_init(unsigned long start, unsigned long end) 23static void dma_alloc_init(unsigned long start, unsigned long end)
29{ 24{
30 spin_lock_init(&dma_page_lock); 25 spin_lock_init(&dma_page_lock);
31 dma_initialized = 0; 26 dma_initialized = 0;
32 27
33 dma_page = (unsigned int *)__get_free_page(GFP_KERNEL); 28 dma_page = (unsigned long *)__get_free_page(GFP_KERNEL);
34 memset(dma_page, 0, PAGE_SIZE); 29 memset(dma_page, 0, PAGE_SIZE);
35 dma_base = PAGE_ALIGN(start); 30 dma_base = PAGE_ALIGN(start);
36 dma_size = PAGE_ALIGN(end) - PAGE_ALIGN(start); 31 dma_size = PAGE_ALIGN(end) - PAGE_ALIGN(start);
@@ -58,10 +53,11 @@ static unsigned long __alloc_dma_pages(unsigned int pages)
58 spin_lock_irqsave(&dma_page_lock, flags); 53 spin_lock_irqsave(&dma_page_lock, flags);
59 54
60 for (i = 0; i < dma_pages;) { 55 for (i = 0; i < dma_pages;) {
61 if (dma_page[i++] == 0) { 56 if (test_bit(i++, dma_page) == 0) {
62 if (++count == pages) { 57 if (++count == pages) {
63 while (count--) 58 while (count--)
64 dma_page[--i] = 1; 59 __set_bit(--i, dma_page);
60
65 ret = dma_base + (i << PAGE_SHIFT); 61 ret = dma_base + (i << PAGE_SHIFT);
66 break; 62 break;
67 } 63 }
@@ -84,14 +80,14 @@ static void __free_dma_pages(unsigned long addr, unsigned int pages)
84 } 80 }
85 81
86 spin_lock_irqsave(&dma_page_lock, flags); 82 spin_lock_irqsave(&dma_page_lock, flags);
87 for (i = page; i < page + pages; i++) { 83 for (i = page; i < page + pages; i++)
88 dma_page[i] = 0; 84 __clear_bit(i, dma_page);
89 } 85
90 spin_unlock_irqrestore(&dma_page_lock, flags); 86 spin_unlock_irqrestore(&dma_page_lock, flags);
91} 87}
92 88
93void *dma_alloc_coherent(struct device *dev, size_t size, 89void *dma_alloc_coherent(struct device *dev, size_t size,
94 dma_addr_t * dma_handle, gfp_t gfp) 90 dma_addr_t *dma_handle, gfp_t gfp)
95{ 91{
96 void *ret; 92 void *ret;
97 93
@@ -115,21 +111,14 @@ dma_free_coherent(struct device *dev, size_t size, void *vaddr,
115EXPORT_SYMBOL(dma_free_coherent); 111EXPORT_SYMBOL(dma_free_coherent);
116 112
117/* 113/*
118 * Dummy functions defined for some existing drivers 114 * Streaming DMA mappings
119 */ 115 */
120 116void __dma_sync(dma_addr_t addr, size_t size,
121dma_addr_t 117 enum dma_data_direction dir)
122dma_map_single(struct device *dev, void *ptr, size_t size,
123 enum dma_data_direction direction)
124{ 118{
125 BUG_ON(direction == DMA_NONE); 119 _dma_sync(addr, size, dir);
126
127 invalidate_dcache_range((unsigned long)ptr,
128 (unsigned long)ptr + size);
129
130 return (dma_addr_t) ptr;
131} 120}
132EXPORT_SYMBOL(dma_map_single); 121EXPORT_SYMBOL(__dma_sync);
133 122
134int 123int
135dma_map_sg(struct device *dev, struct scatterlist *sg, int nents, 124dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
@@ -137,30 +126,23 @@ dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
137{ 126{
138 int i; 127 int i;
139 128
140 BUG_ON(direction == DMA_NONE);
141
142 for (i = 0; i < nents; i++, sg++) { 129 for (i = 0; i < nents; i++, sg++) {
143 sg->dma_address = (dma_addr_t) sg_virt(sg); 130 sg->dma_address = (dma_addr_t) sg_virt(sg);
144 131 __dma_sync(sg_dma_address(sg), sg_dma_len(sg), direction);
145 invalidate_dcache_range(sg_dma_address(sg),
146 sg_dma_address(sg) +
147 sg_dma_len(sg));
148 } 132 }
149 133
150 return nents; 134 return nents;
151} 135}
152EXPORT_SYMBOL(dma_map_sg); 136EXPORT_SYMBOL(dma_map_sg);
153 137
154void dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size, 138void dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
155 enum dma_data_direction direction) 139 int nelems, enum dma_data_direction direction)
156{ 140{
157 BUG_ON(direction == DMA_NONE); 141 int i;
158}
159EXPORT_SYMBOL(dma_unmap_single);
160 142
161void dma_unmap_sg(struct device *dev, struct scatterlist *sg, 143 for (i = 0; i < nelems; i++, sg++) {
162 int nhwentries, enum dma_data_direction direction) 144 sg->dma_address = (dma_addr_t) sg_virt(sg);
163{ 145 __dma_sync(sg_dma_address(sg), sg_dma_len(sg), direction);
164 BUG_ON(direction == DMA_NONE); 146 }
165} 147}
166EXPORT_SYMBOL(dma_unmap_sg); 148EXPORT_SYMBOL(dma_sync_sg_for_device);