aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mm/dma-mapping.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/arm/mm/dma-mapping.c')
-rw-r--r--arch/arm/mm/dma-mapping.c45
1 files changed, 34 insertions, 11 deletions
diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
index c3ff82f92d9c..01f5987eb1ad 100644
--- a/arch/arm/mm/dma-mapping.c
+++ b/arch/arm/mm/dma-mapping.c
@@ -18,12 +18,14 @@
18#include <linux/device.h> 18#include <linux/device.h>
19#include <linux/dma-mapping.h> 19#include <linux/dma-mapping.h>
20#include <linux/highmem.h> 20#include <linux/highmem.h>
21#include <linux/slab.h>
21 22
22#include <asm/memory.h> 23#include <asm/memory.h>
23#include <asm/highmem.h> 24#include <asm/highmem.h>
24#include <asm/cacheflush.h> 25#include <asm/cacheflush.h>
25#include <asm/tlbflush.h> 26#include <asm/tlbflush.h>
26#include <asm/sizes.h> 27#include <asm/sizes.h>
28#include <asm/mach/arch.h>
27 29
28#include "mm.h" 30#include "mm.h"
29 31
@@ -117,26 +119,37 @@ static void __dma_free_buffer(struct page *page, size_t size)
117} 119}
118 120
119#ifdef CONFIG_MMU 121#ifdef CONFIG_MMU
120/* Sanity check size */
121#if (CONSISTENT_DMA_SIZE % SZ_2M)
122#error "CONSISTENT_DMA_SIZE must be multiple of 2MiB"
123#endif
124 122
125#define CONSISTENT_OFFSET(x) (((unsigned long)(x) - CONSISTENT_BASE) >> PAGE_SHIFT) 123
126#define CONSISTENT_PTE_INDEX(x) (((unsigned long)(x) - CONSISTENT_BASE) >> PGDIR_SHIFT) 124#define CONSISTENT_OFFSET(x) (((unsigned long)(x) - consistent_base) >> PAGE_SHIFT)
127#define NUM_CONSISTENT_PTES (CONSISTENT_DMA_SIZE >> PGDIR_SHIFT) 125#define CONSISTENT_PTE_INDEX(x) (((unsigned long)(x) - consistent_base) >> PGDIR_SHIFT)
128 126
129/* 127/*
130 * These are the page tables (2MB each) covering uncached, DMA consistent allocations 128 * These are the page tables (2MB each) covering uncached, DMA consistent allocations
131 */ 129 */
132static pte_t *consistent_pte[NUM_CONSISTENT_PTES]; 130static pte_t **consistent_pte;
131
132#define DEFAULT_CONSISTENT_DMA_SIZE SZ_2M
133
134unsigned long consistent_base = CONSISTENT_END - DEFAULT_CONSISTENT_DMA_SIZE;
135
136void __init init_consistent_dma_size(unsigned long size)
137{
138 unsigned long base = CONSISTENT_END - ALIGN(size, SZ_2M);
139
140 BUG_ON(consistent_pte); /* Check we're called before DMA region init */
141 BUG_ON(base < VMALLOC_END);
142
143 /* Grow region to accommodate specified size */
144 if (base < consistent_base)
145 consistent_base = base;
146}
133 147
134#include "vmregion.h" 148#include "vmregion.h"
135 149
136static struct arm_vmregion_head consistent_head = { 150static struct arm_vmregion_head consistent_head = {
137 .vm_lock = __SPIN_LOCK_UNLOCKED(&consistent_head.vm_lock), 151 .vm_lock = __SPIN_LOCK_UNLOCKED(&consistent_head.vm_lock),
138 .vm_list = LIST_HEAD_INIT(consistent_head.vm_list), 152 .vm_list = LIST_HEAD_INIT(consistent_head.vm_list),
139 .vm_start = CONSISTENT_BASE,
140 .vm_end = CONSISTENT_END, 153 .vm_end = CONSISTENT_END,
141}; 154};
142 155
@@ -155,7 +168,17 @@ static int __init consistent_init(void)
155 pmd_t *pmd; 168 pmd_t *pmd;
156 pte_t *pte; 169 pte_t *pte;
157 int i = 0; 170 int i = 0;
158 u32 base = CONSISTENT_BASE; 171 unsigned long base = consistent_base;
172 unsigned long num_ptes = (CONSISTENT_END - base) >> PGDIR_SHIFT;
173
174 consistent_pte = kmalloc(num_ptes * sizeof(pte_t), GFP_KERNEL);
175 if (!consistent_pte) {
176 pr_err("%s: no memory\n", __func__);
177 return -ENOMEM;
178 }
179
180 pr_debug("DMA memory: 0x%08lx - 0x%08lx:\n", base, CONSISTENT_END);
181 consistent_head.vm_start = base;
159 182
160 do { 183 do {
161 pgd = pgd_offset(&init_mm, base); 184 pgd = pgd_offset(&init_mm, base);
@@ -198,7 +221,7 @@ __dma_alloc_remap(struct page *page, size_t size, gfp_t gfp, pgprot_t prot)
198 size_t align; 221 size_t align;
199 int bit; 222 int bit;
200 223
201 if (!consistent_pte[0]) { 224 if (!consistent_pte) {
202 printk(KERN_ERR "%s: not initialised\n", __func__); 225 printk(KERN_ERR "%s: not initialised\n", __func__);
203 dump_stack(); 226 dump_stack();
204 return NULL; 227 return NULL;