diff options
Diffstat (limited to 'arch/sh/mm/consistent.c')
-rw-r--r-- | arch/sh/mm/consistent.c | 98 |
1 files changed, 3 insertions, 95 deletions
diff --git a/arch/sh/mm/consistent.c b/arch/sh/mm/consistent.c index 8277982d0938..b2ce014401b5 100644 --- a/arch/sh/mm/consistent.c +++ b/arch/sh/mm/consistent.c | |||
@@ -28,21 +28,10 @@ void *dma_alloc_coherent(struct device *dev, size_t size, | |||
28 | dma_addr_t *dma_handle, gfp_t gfp) | 28 | dma_addr_t *dma_handle, gfp_t gfp) |
29 | { | 29 | { |
30 | void *ret, *ret_nocache; | 30 | void *ret, *ret_nocache; |
31 | struct dma_coherent_mem *mem = dev ? dev->dma_mem : NULL; | ||
32 | int order = get_order(size); | 31 | int order = get_order(size); |
33 | 32 | ||
34 | if (mem) { | 33 | if (dma_alloc_from_coherent(dev, size, dma_handle, &ret)) |
35 | int page = bitmap_find_free_region(mem->bitmap, mem->size, | 34 | return ret; |
36 | order); | ||
37 | if (page >= 0) { | ||
38 | *dma_handle = mem->device_base + (page << PAGE_SHIFT); | ||
39 | ret = mem->virt_base + (page << PAGE_SHIFT); | ||
40 | memset(ret, 0, size); | ||
41 | return ret; | ||
42 | } | ||
43 | if (mem->flags & DMA_MEMORY_EXCLUSIVE) | ||
44 | return NULL; | ||
45 | } | ||
46 | 35 | ||
47 | ret = (void *)__get_free_pages(gfp, order); | 36 | ret = (void *)__get_free_pages(gfp, order); |
48 | if (!ret) | 37 | if (!ret) |
@@ -72,11 +61,7 @@ void dma_free_coherent(struct device *dev, size_t size, | |||
72 | struct dma_coherent_mem *mem = dev ? dev->dma_mem : NULL; | 61 | struct dma_coherent_mem *mem = dev ? dev->dma_mem : NULL; |
73 | int order = get_order(size); | 62 | int order = get_order(size); |
74 | 63 | ||
75 | if (mem && vaddr >= mem->virt_base && vaddr < (mem->virt_base + (mem->size << PAGE_SHIFT))) { | 64 | if (!dma_release_from_coherent(dev, order, vaddr)) { |
76 | int page = (vaddr - mem->virt_base) >> PAGE_SHIFT; | ||
77 | |||
78 | bitmap_release_region(mem->bitmap, page, order); | ||
79 | } else { | ||
80 | WARN_ON(irqs_disabled()); /* for portability */ | 65 | WARN_ON(irqs_disabled()); /* for portability */ |
81 | BUG_ON(mem && mem->flags & DMA_MEMORY_EXCLUSIVE); | 66 | BUG_ON(mem && mem->flags & DMA_MEMORY_EXCLUSIVE); |
82 | free_pages((unsigned long)phys_to_virt(dma_handle), order); | 67 | free_pages((unsigned long)phys_to_virt(dma_handle), order); |
@@ -85,83 +70,6 @@ void dma_free_coherent(struct device *dev, size_t size, | |||
85 | } | 70 | } |
86 | EXPORT_SYMBOL(dma_free_coherent); | 71 | EXPORT_SYMBOL(dma_free_coherent); |
87 | 72 | ||
88 | int dma_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr, | ||
89 | dma_addr_t device_addr, size_t size, int flags) | ||
90 | { | ||
91 | void __iomem *mem_base = NULL; | ||
92 | int pages = size >> PAGE_SHIFT; | ||
93 | int bitmap_size = BITS_TO_LONGS(pages) * sizeof(long); | ||
94 | |||
95 | if ((flags & (DMA_MEMORY_MAP | DMA_MEMORY_IO)) == 0) | ||
96 | goto out; | ||
97 | if (!size) | ||
98 | goto out; | ||
99 | if (dev->dma_mem) | ||
100 | goto out; | ||
101 | |||
102 | /* FIXME: this routine just ignores DMA_MEMORY_INCLUDES_CHILDREN */ | ||
103 | |||
104 | mem_base = ioremap_nocache(bus_addr, size); | ||
105 | if (!mem_base) | ||
106 | goto out; | ||
107 | |||
108 | dev->dma_mem = kmalloc(sizeof(struct dma_coherent_mem), GFP_KERNEL); | ||
109 | if (!dev->dma_mem) | ||
110 | goto out; | ||
111 | dev->dma_mem->bitmap = kzalloc(bitmap_size, GFP_KERNEL); | ||
112 | if (!dev->dma_mem->bitmap) | ||
113 | goto free1_out; | ||
114 | |||
115 | dev->dma_mem->virt_base = mem_base; | ||
116 | dev->dma_mem->device_base = device_addr; | ||
117 | dev->dma_mem->size = pages; | ||
118 | dev->dma_mem->flags = flags; | ||
119 | |||
120 | if (flags & DMA_MEMORY_MAP) | ||
121 | return DMA_MEMORY_MAP; | ||
122 | |||
123 | return DMA_MEMORY_IO; | ||
124 | |||
125 | free1_out: | ||
126 | kfree(dev->dma_mem); | ||
127 | out: | ||
128 | if (mem_base) | ||
129 | iounmap(mem_base); | ||
130 | return 0; | ||
131 | } | ||
132 | EXPORT_SYMBOL(dma_declare_coherent_memory); | ||
133 | |||
134 | void dma_release_declared_memory(struct device *dev) | ||
135 | { | ||
136 | struct dma_coherent_mem *mem = dev->dma_mem; | ||
137 | |||
138 | if (!mem) | ||
139 | return; | ||
140 | dev->dma_mem = NULL; | ||
141 | iounmap(mem->virt_base); | ||
142 | kfree(mem->bitmap); | ||
143 | kfree(mem); | ||
144 | } | ||
145 | EXPORT_SYMBOL(dma_release_declared_memory); | ||
146 | |||
147 | void *dma_mark_declared_memory_occupied(struct device *dev, | ||
148 | dma_addr_t device_addr, size_t size) | ||
149 | { | ||
150 | struct dma_coherent_mem *mem = dev->dma_mem; | ||
151 | int pages = (size + (device_addr & ~PAGE_MASK) + PAGE_SIZE - 1) >> PAGE_SHIFT; | ||
152 | int pos, err; | ||
153 | |||
154 | if (!mem) | ||
155 | return ERR_PTR(-EINVAL); | ||
156 | |||
157 | pos = (device_addr - mem->device_base) >> PAGE_SHIFT; | ||
158 | err = bitmap_allocate_region(mem->bitmap, pos, get_order(pages)); | ||
159 | if (err != 0) | ||
160 | return ERR_PTR(err); | ||
161 | return mem->virt_base + (pos << PAGE_SHIFT); | ||
162 | } | ||
163 | EXPORT_SYMBOL(dma_mark_declared_memory_occupied); | ||
164 | |||
165 | void dma_cache_sync(struct device *dev, void *vaddr, size_t size, | 73 | void dma_cache_sync(struct device *dev, void *vaddr, size_t size, |
166 | enum dma_data_direction direction) | 74 | enum dma_data_direction direction) |
167 | { | 75 | { |