aboutsummaryrefslogtreecommitdiffstats
path: root/arch/microblaze/mm
diff options
context:
space:
mode:
Diffstat (limited to 'arch/microblaze/mm')
-rw-r--r--arch/microblaze/mm/Makefile2
-rw-r--r--arch/microblaze/mm/consistent.c247
-rw-r--r--arch/microblaze/mm/fault.c24
-rw-r--r--arch/microblaze/mm/init.c45
-rw-r--r--arch/microblaze/mm/pgtable.c4
5 files changed, 291 insertions, 31 deletions
diff --git a/arch/microblaze/mm/Makefile b/arch/microblaze/mm/Makefile
index 6c8a924d9e26..09c49ed87235 100644
--- a/arch/microblaze/mm/Makefile
+++ b/arch/microblaze/mm/Makefile
@@ -2,6 +2,6 @@
2# Makefile 2# Makefile
3# 3#
4 4
5obj-y := init.o 5obj-y := consistent.o init.o
6 6
7obj-$(CONFIG_MMU) += pgtable.o mmu_context.o fault.o 7obj-$(CONFIG_MMU) += pgtable.o mmu_context.o fault.o
diff --git a/arch/microblaze/mm/consistent.c b/arch/microblaze/mm/consistent.c
new file mode 100644
index 000000000000..f956e24fe49c
--- /dev/null
+++ b/arch/microblaze/mm/consistent.c
@@ -0,0 +1,247 @@
1/*
2 * Microblaze support for cache consistent memory.
3 * Copyright (C) 2010 Michal Simek <monstr@monstr.eu>
4 * Copyright (C) 2010 PetaLogix
5 * Copyright (C) 2005 John Williams <jwilliams@itee.uq.edu.au>
6 *
7 * Based on PowerPC version derived from arch/arm/mm/consistent.c
8 * Copyright (C) 2001 Dan Malek (dmalek@jlc.net)
9 * Copyright (C) 2000 Russell King
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
14 */
15
16#include <linux/module.h>
17#include <linux/signal.h>
18#include <linux/sched.h>
19#include <linux/kernel.h>
20#include <linux/errno.h>
21#include <linux/string.h>
22#include <linux/types.h>
23#include <linux/ptrace.h>
24#include <linux/mman.h>
25#include <linux/mm.h>
26#include <linux/swap.h>
27#include <linux/stddef.h>
28#include <linux/vmalloc.h>
29#include <linux/init.h>
30#include <linux/delay.h>
31#include <linux/bootmem.h>
32#include <linux/highmem.h>
33#include <linux/pci.h>
34#include <linux/interrupt.h>
35#include <linux/gfp.h>
36
37#include <asm/pgalloc.h>
38#include <linux/io.h>
39#include <linux/hardirq.h>
40#include <asm/mmu_context.h>
41#include <asm/mmu.h>
42#include <linux/uaccess.h>
43#include <asm/pgtable.h>
44#include <asm/cpuinfo.h>
45
46#ifndef CONFIG_MMU
47
48/* I have to use dcache values because I can't relate on ram size */
49#define UNCACHED_SHADOW_MASK (cpuinfo.dcache_high - cpuinfo.dcache_base + 1)
50
51/*
52 * Consistent memory allocators. Used for DMA devices that want to
53 * share uncached memory with the processor core.
54 * My crufty no-MMU approach is simple. In the HW platform we can optionally
55 * mirror the DDR up above the processor cacheable region. So, memory accessed
56 * in this mirror region will not be cached. It's alloced from the same
57 * pool as normal memory, but the handle we return is shifted up into the
58 * uncached region. This will no doubt cause big problems if memory allocated
59 * here is not also freed properly. -- JW
60 */
61void *consistent_alloc(int gfp, size_t size, dma_addr_t *dma_handle)
62{
63 struct page *page, *end, *free;
64 unsigned long order;
65 void *ret, *virt;
66
67 if (in_interrupt())
68 BUG();
69
70 size = PAGE_ALIGN(size);
71 order = get_order(size);
72
73 page = alloc_pages(gfp, order);
74 if (!page)
75 goto no_page;
76
77 /* We could do with a page_to_phys and page_to_bus here. */
78 virt = page_address(page);
79 ret = ioremap(virt_to_phys(virt), size);
80 if (!ret)
81 goto no_remap;
82
83 /*
84 * Here's the magic! Note if the uncached shadow is not implemented,
85 * it's up to the calling code to also test that condition and make
86 * other arranegments, such as manually flushing the cache and so on.
87 */
88#ifdef CONFIG_XILINX_UNCACHED_SHADOW
89 ret = (void *)((unsigned) ret | UNCACHED_SHADOW_MASK);
90#endif
91 /* dma_handle is same as physical (shadowed) address */
92 *dma_handle = (dma_addr_t)ret;
93
94 /*
95 * free wasted pages. We skip the first page since we know
96 * that it will have count = 1 and won't require freeing.
97 * We also mark the pages in use as reserved so that
98 * remap_page_range works.
99 */
100 page = virt_to_page(virt);
101 free = page + (size >> PAGE_SHIFT);
102 end = page + (1 << order);
103
104 for (; page < end; page++) {
105 init_page_count(page);
106 if (page >= free)
107 __free_page(page);
108 else
109 SetPageReserved(page);
110 }
111
112 return ret;
113no_remap:
114 __free_pages(page, order);
115no_page:
116 return NULL;
117}
118
119#else
120
121void *consistent_alloc(int gfp, size_t size, dma_addr_t *dma_handle)
122{
123 int order, err, i;
124 unsigned long page, va, flags;
125 phys_addr_t pa;
126 struct vm_struct *area;
127 void *ret;
128
129 if (in_interrupt())
130 BUG();
131
132 /* Only allocate page size areas. */
133 size = PAGE_ALIGN(size);
134 order = get_order(size);
135
136 page = __get_free_pages(gfp, order);
137 if (!page) {
138 BUG();
139 return NULL;
140 }
141
142 /*
143 * we need to ensure that there are no cachelines in use,
144 * or worse dirty in this area.
145 */
146 flush_dcache_range(virt_to_phys(page), virt_to_phys(page) + size);
147
148 /* Allocate some common virtual space to map the new pages. */
149 area = get_vm_area(size, VM_ALLOC);
150 if (area == NULL) {
151 free_pages(page, order);
152 return NULL;
153 }
154 va = (unsigned long) area->addr;
155 ret = (void *)va;
156
157 /* This gives us the real physical address of the first page. */
158 *dma_handle = pa = virt_to_bus((void *)page);
159
160 /* MS: This is the whole magic - use cache inhibit pages */
161 flags = _PAGE_KERNEL | _PAGE_NO_CACHE;
162
163 /*
164 * Set refcount=1 on all pages in an order>0
165 * allocation so that vfree() will actually
166 * free all pages that were allocated.
167 */
168 if (order > 0) {
169 struct page *rpage = virt_to_page(page);
170 for (i = 1; i < (1 << order); i++)
171 init_page_count(rpage+i);
172 }
173
174 err = 0;
175 for (i = 0; i < size && err == 0; i += PAGE_SIZE)
176 err = map_page(va+i, pa+i, flags);
177
178 if (err) {
179 vfree((void *)va);
180 return NULL;
181 }
182
183 return ret;
184}
185#endif /* CONFIG_MMU */
186EXPORT_SYMBOL(consistent_alloc);
187
188/*
189 * free page(s) as defined by the above mapping.
190 */
191void consistent_free(void *vaddr)
192{
193 if (in_interrupt())
194 BUG();
195
196 /* Clear SHADOW_MASK bit in address, and free as per usual */
197#ifdef CONFIG_XILINX_UNCACHED_SHADOW
198 vaddr = (void *)((unsigned)vaddr & ~UNCACHED_SHADOW_MASK);
199#endif
200 vfree(vaddr);
201}
202EXPORT_SYMBOL(consistent_free);
203
204/*
205 * make an area consistent.
206 */
207void consistent_sync(void *vaddr, size_t size, int direction)
208{
209 unsigned long start;
210 unsigned long end;
211
212 start = (unsigned long)vaddr;
213
214 /* Convert start address back down to unshadowed memory region */
215#ifdef CONFIG_XILINX_UNCACHED_SHADOW
216 start &= ~UNCACHED_SHADOW_MASK;
217#endif
218 end = start + size;
219
220 switch (direction) {
221 case PCI_DMA_NONE:
222 BUG();
223 case PCI_DMA_FROMDEVICE: /* invalidate only */
224 flush_dcache_range(start, end);
225 break;
226 case PCI_DMA_TODEVICE: /* writeback only */
227 flush_dcache_range(start, end);
228 break;
229 case PCI_DMA_BIDIRECTIONAL: /* writeback and invalidate */
230 flush_dcache_range(start, end);
231 break;
232 }
233}
234EXPORT_SYMBOL(consistent_sync);
235
236/*
237 * consistent_sync_page makes memory consistent. identical
238 * to consistent_sync, but takes a struct page instead of a
239 * virtual address
240 */
241void consistent_sync_page(struct page *page, unsigned long offset,
242 size_t size, int direction)
243{
244 unsigned long start = (unsigned long)page_address(page) + offset;
245 consistent_sync((void *)start, size, direction);
246}
247EXPORT_SYMBOL(consistent_sync_page);
diff --git a/arch/microblaze/mm/fault.c b/arch/microblaze/mm/fault.c
index d9d249a66ff2..7af87f4b2c2c 100644
--- a/arch/microblaze/mm/fault.c
+++ b/arch/microblaze/mm/fault.c
@@ -106,7 +106,7 @@ void do_page_fault(struct pt_regs *regs, unsigned long address,
106 regs->esr = error_code; 106 regs->esr = error_code;
107 107
108 /* On a kernel SLB miss we can only check for a valid exception entry */ 108 /* On a kernel SLB miss we can only check for a valid exception entry */
109 if (kernel_mode(regs) && (address >= TASK_SIZE)) { 109 if (unlikely(kernel_mode(regs) && (address >= TASK_SIZE))) {
110 printk(KERN_WARNING "kernel task_size exceed"); 110 printk(KERN_WARNING "kernel task_size exceed");
111 _exception(SIGSEGV, regs, code, address); 111 _exception(SIGSEGV, regs, code, address);
112 } 112 }
@@ -122,7 +122,7 @@ void do_page_fault(struct pt_regs *regs, unsigned long address,
122 } 122 }
123#endif /* CONFIG_KGDB */ 123#endif /* CONFIG_KGDB */
124 124
125 if (in_atomic() || !mm) { 125 if (unlikely(in_atomic() || !mm)) {
126 if (kernel_mode(regs)) 126 if (kernel_mode(regs))
127 goto bad_area_nosemaphore; 127 goto bad_area_nosemaphore;
128 128
@@ -150,7 +150,7 @@ void do_page_fault(struct pt_regs *regs, unsigned long address,
150 * source. If this is invalid we can skip the address space check, 150 * source. If this is invalid we can skip the address space check,
151 * thus avoiding the deadlock. 151 * thus avoiding the deadlock.
152 */ 152 */
153 if (!down_read_trylock(&mm->mmap_sem)) { 153 if (unlikely(!down_read_trylock(&mm->mmap_sem))) {
154 if (kernel_mode(regs) && !search_exception_tables(regs->pc)) 154 if (kernel_mode(regs) && !search_exception_tables(regs->pc))
155 goto bad_area_nosemaphore; 155 goto bad_area_nosemaphore;
156 156
@@ -158,16 +158,16 @@ void do_page_fault(struct pt_regs *regs, unsigned long address,
158 } 158 }
159 159
160 vma = find_vma(mm, address); 160 vma = find_vma(mm, address);
161 if (!vma) 161 if (unlikely(!vma))
162 goto bad_area; 162 goto bad_area;
163 163
164 if (vma->vm_start <= address) 164 if (vma->vm_start <= address)
165 goto good_area; 165 goto good_area;
166 166
167 if (!(vma->vm_flags & VM_GROWSDOWN)) 167 if (unlikely(!(vma->vm_flags & VM_GROWSDOWN)))
168 goto bad_area; 168 goto bad_area;
169 169
170 if (!is_write) 170 if (unlikely(!is_write))
171 goto bad_area; 171 goto bad_area;
172 172
173 /* 173 /*
@@ -179,7 +179,7 @@ void do_page_fault(struct pt_regs *regs, unsigned long address,
179 * before setting the user r1. Thus we allow the stack to 179 * before setting the user r1. Thus we allow the stack to
180 * expand to 1MB without further checks. 180 * expand to 1MB without further checks.
181 */ 181 */
182 if (address + 0x100000 < vma->vm_end) { 182 if (unlikely(address + 0x100000 < vma->vm_end)) {
183 183
184 /* get user regs even if this fault is in kernel mode */ 184 /* get user regs even if this fault is in kernel mode */
185 struct pt_regs *uregs = current->thread.regs; 185 struct pt_regs *uregs = current->thread.regs;
@@ -209,15 +209,15 @@ good_area:
209 code = SEGV_ACCERR; 209 code = SEGV_ACCERR;
210 210
211 /* a write */ 211 /* a write */
212 if (is_write) { 212 if (unlikely(is_write)) {
213 if (!(vma->vm_flags & VM_WRITE)) 213 if (unlikely(!(vma->vm_flags & VM_WRITE)))
214 goto bad_area; 214 goto bad_area;
215 /* a read */ 215 /* a read */
216 } else { 216 } else {
217 /* protection fault */ 217 /* protection fault */
218 if (error_code & 0x08000000) 218 if (unlikely(error_code & 0x08000000))
219 goto bad_area; 219 goto bad_area;
220 if (!(vma->vm_flags & (VM_READ | VM_EXEC))) 220 if (unlikely(!(vma->vm_flags & (VM_READ | VM_EXEC))))
221 goto bad_area; 221 goto bad_area;
222 } 222 }
223 223
@@ -235,7 +235,7 @@ survive:
235 goto do_sigbus; 235 goto do_sigbus;
236 BUG(); 236 BUG();
237 } 237 }
238 if (fault & VM_FAULT_MAJOR) 238 if (unlikely(fault & VM_FAULT_MAJOR))
239 current->maj_flt++; 239 current->maj_flt++;
240 else 240 else
241 current->min_flt++; 241 current->min_flt++;
diff --git a/arch/microblaze/mm/init.c b/arch/microblaze/mm/init.c
index a57cedf36715..f42c2dde8b1c 100644
--- a/arch/microblaze/mm/init.c
+++ b/arch/microblaze/mm/init.c
@@ -15,6 +15,7 @@
15#include <linux/initrd.h> 15#include <linux/initrd.h>
16#include <linux/pagemap.h> 16#include <linux/pagemap.h>
17#include <linux/pfn.h> 17#include <linux/pfn.h>
18#include <linux/slab.h>
18#include <linux/swap.h> 19#include <linux/swap.h>
19 20
20#include <asm/page.h> 21#include <asm/page.h>
@@ -23,6 +24,9 @@
23#include <asm/sections.h> 24#include <asm/sections.h>
24#include <asm/tlb.h> 25#include <asm/tlb.h>
25 26
27/* Use for MMU and noMMU because of PCI generic code */
28int mem_init_done;
29
26#ifndef CONFIG_MMU 30#ifndef CONFIG_MMU
27unsigned int __page_offset; 31unsigned int __page_offset;
28EXPORT_SYMBOL(__page_offset); 32EXPORT_SYMBOL(__page_offset);
@@ -30,7 +34,6 @@ EXPORT_SYMBOL(__page_offset);
30#else 34#else
31DEFINE_PER_CPU(struct mmu_gather, mmu_gathers); 35DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);
32 36
33int mem_init_done;
34static int init_bootmem_done; 37static int init_bootmem_done;
35#endif /* CONFIG_MMU */ 38#endif /* CONFIG_MMU */
36 39
@@ -163,7 +166,6 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
163 for (addr = begin; addr < end; addr += PAGE_SIZE) { 166 for (addr = begin; addr < end; addr += PAGE_SIZE) {
164 ClearPageReserved(virt_to_page(addr)); 167 ClearPageReserved(virt_to_page(addr));
165 init_page_count(virt_to_page(addr)); 168 init_page_count(virt_to_page(addr));
166 memset((void *)addr, 0xcc, PAGE_SIZE);
167 free_page(addr); 169 free_page(addr);
168 totalram_pages++; 170 totalram_pages++;
169 } 171 }
@@ -193,12 +195,6 @@ void free_initmem(void)
193 (unsigned long)(&__init_end)); 195 (unsigned long)(&__init_end));
194} 196}
195 197
196/* FIXME from arch/powerpc/mm/mem.c*/
197void show_mem(void)
198{
199 printk(KERN_NOTICE "%s\n", __func__);
200}
201
202void __init mem_init(void) 198void __init mem_init(void)
203{ 199{
204 high_memory = (void *)__va(memory_end); 200 high_memory = (void *)__va(memory_end);
@@ -208,20 +204,14 @@ void __init mem_init(void)
208 printk(KERN_INFO "Memory: %luk/%luk available\n", 204 printk(KERN_INFO "Memory: %luk/%luk available\n",
209 nr_free_pages() << (PAGE_SHIFT-10), 205 nr_free_pages() << (PAGE_SHIFT-10),
210 num_physpages << (PAGE_SHIFT-10)); 206 num_physpages << (PAGE_SHIFT-10));
211#ifdef CONFIG_MMU
212 mem_init_done = 1; 207 mem_init_done = 1;
213#endif
214} 208}
215 209
216#ifndef CONFIG_MMU 210#ifndef CONFIG_MMU
217/* Check against bounds of physical memory */ 211int page_is_ram(unsigned long pfn)
218int ___range_ok(unsigned long addr, unsigned long size)
219{ 212{
220 return ((addr < memory_start) || 213 return __range_ok(pfn, 0);
221 ((addr + size) > memory_end));
222} 214}
223EXPORT_SYMBOL(___range_ok);
224
225#else 215#else
226int page_is_ram(unsigned long pfn) 216int page_is_ram(unsigned long pfn)
227{ 217{
@@ -349,4 +339,27 @@ void __init *early_get_page(void)
349 } 339 }
350 return p; 340 return p;
351} 341}
342
352#endif /* CONFIG_MMU */ 343#endif /* CONFIG_MMU */
344
345void * __init_refok alloc_maybe_bootmem(size_t size, gfp_t mask)
346{
347 if (mem_init_done)
348 return kmalloc(size, mask);
349 else
350 return alloc_bootmem(size);
351}
352
353void * __init_refok zalloc_maybe_bootmem(size_t size, gfp_t mask)
354{
355 void *p;
356
357 if (mem_init_done)
358 p = kzalloc(size, mask);
359 else {
360 p = alloc_bootmem(size);
361 if (p)
362 memset(p, 0, size);
363 }
364 return p;
365}
diff --git a/arch/microblaze/mm/pgtable.c b/arch/microblaze/mm/pgtable.c
index 2820081b21ab..d31312cde6ea 100644
--- a/arch/microblaze/mm/pgtable.c
+++ b/arch/microblaze/mm/pgtable.c
@@ -103,7 +103,7 @@ static void __iomem *__ioremap(phys_addr_t addr, unsigned long size,
103 area = get_vm_area(size, VM_IOREMAP); 103 area = get_vm_area(size, VM_IOREMAP);
104 if (area == NULL) 104 if (area == NULL)
105 return NULL; 105 return NULL;
106 v = VMALLOC_VMADDR(area->addr); 106 v = (unsigned long) area->addr;
107 } else { 107 } else {
108 v = (ioremap_bot -= size); 108 v = (ioremap_bot -= size);
109 } 109 }
@@ -154,7 +154,7 @@ int map_page(unsigned long va, phys_addr_t pa, int flags)
154 err = 0; 154 err = 0;
155 set_pte_at(&init_mm, va, pg, pfn_pte(pa >> PAGE_SHIFT, 155 set_pte_at(&init_mm, va, pg, pfn_pte(pa >> PAGE_SHIFT,
156 __pgprot(flags))); 156 __pgprot(flags)));
157 if (mem_init_done) 157 if (unlikely(mem_init_done))
158 flush_HPTE(0, va, pmd_val(*pd)); 158 flush_HPTE(0, va, pmd_val(*pd));
159 /* flush_HPTE(0, va, pg); */ 159 /* flush_HPTE(0, va, pg); */
160 } 160 }