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.c44
1 files changed, 33 insertions, 11 deletions
diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
index 235eb775fc78..e4e7f6cba1ab 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,36 @@ 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#define CONSISTENT_OFFSET(x) (((unsigned long)(x) - consistent_base) >> PAGE_SHIFT)
126#define CONSISTENT_PTE_INDEX(x) (((unsigned long)(x) - CONSISTENT_BASE) >> PMD_SHIFT) 124#define CONSISTENT_PTE_INDEX(x) (((unsigned long)(x) - consistent_base) >> PMD_SHIFT)
127#define NUM_CONSISTENT_PTES (CONSISTENT_DMA_SIZE >> PMD_SHIFT)
128 125
129/* 126/*
130 * These are the page tables (2MB each) covering uncached, DMA consistent allocations 127 * These are the page tables (2MB each) covering uncached, DMA consistent allocations
131 */ 128 */
132static pte_t *consistent_pte[NUM_CONSISTENT_PTES]; 129static pte_t **consistent_pte;
130
131#define DEFAULT_CONSISTENT_DMA_SIZE SZ_2M
132
133unsigned long consistent_base = CONSISTENT_END - DEFAULT_CONSISTENT_DMA_SIZE;
134
135void __init init_consistent_dma_size(unsigned long size)
136{
137 unsigned long base = CONSISTENT_END - ALIGN(size, SZ_2M);
138
139 BUG_ON(consistent_pte); /* Check we're called before DMA region init */
140 BUG_ON(base < VMALLOC_END);
141
142 /* Grow region to accommodate specified size */
143 if (base < consistent_base)
144 consistent_base = base;
145}
133 146
134#include "vmregion.h" 147#include "vmregion.h"
135 148
136static struct arm_vmregion_head consistent_head = { 149static struct arm_vmregion_head consistent_head = {
137 .vm_lock = __SPIN_LOCK_UNLOCKED(&consistent_head.vm_lock), 150 .vm_lock = __SPIN_LOCK_UNLOCKED(&consistent_head.vm_lock),
138 .vm_list = LIST_HEAD_INIT(consistent_head.vm_list), 151 .vm_list = LIST_HEAD_INIT(consistent_head.vm_list),
139 .vm_start = CONSISTENT_BASE,
140 .vm_end = CONSISTENT_END, 152 .vm_end = CONSISTENT_END,
141}; 153};
142 154
@@ -155,7 +167,17 @@ static int __init consistent_init(void)
155 pmd_t *pmd; 167 pmd_t *pmd;
156 pte_t *pte; 168 pte_t *pte;
157 int i = 0; 169 int i = 0;
158 u32 base = CONSISTENT_BASE; 170 unsigned long base = consistent_base;
171 unsigned long num_ptes = (CONSISTENT_END - base) >> PGDIR_SHIFT;
172
173 consistent_pte = kmalloc(num_ptes * sizeof(pte_t), GFP_KERNEL);
174 if (!consistent_pte) {
175 pr_err("%s: no memory\n", __func__);
176 return -ENOMEM;
177 }
178
179 pr_debug("DMA memory: 0x%08lx - 0x%08lx:\n", base, CONSISTENT_END);
180 consistent_head.vm_start = base;
159 181
160 do { 182 do {
161 pgd = pgd_offset(&init_mm, base); 183 pgd = pgd_offset(&init_mm, base);
@@ -198,7 +220,7 @@ __dma_alloc_remap(struct page *page, size_t size, gfp_t gfp, pgprot_t prot)
198 size_t align; 220 size_t align;
199 int bit; 221 int bit;
200 222
201 if (!consistent_pte[0]) { 223 if (!consistent_pte) {
202 printk(KERN_ERR "%s: not initialised\n", __func__); 224 printk(KERN_ERR "%s: not initialised\n", __func__);
203 dump_stack(); 225 dump_stack();
204 return NULL; 226 return NULL;