diff options
author | Michal Simek <monstr@monstr.eu> | 2009-03-27 09:25:29 -0400 |
---|---|---|
committer | Michal Simek <monstr@monstr.eu> | 2009-03-27 09:25:29 -0400 |
commit | a95d0e1602f9f3ab54c7dbc9727bf22095705d1e (patch) | |
tree | 95e055b7dd904c98acf25d9915cc6bd61a83d2cd /arch | |
parent | 65bc60930c32b4831800056c8e0a0571c9b6a0bf (diff) |
microblaze_v8: memory inicialization, MMU, TLB
Reviewed-by: Ingo Molnar <mingo@elte.hu>
Acked-by: John Linn <john.linn@xilinx.com>
Acked-by: Stephen Neuendorffer <stephen.neuendorffer@xilinx.com>
Acked-by: John Williams <john.williams@petalogix.com>
Signed-off-by: Michal Simek <monstr@monstr.eu>
Diffstat (limited to 'arch')
-rw-r--r-- | arch/microblaze/include/asm/mmu.h | 19 | ||||
-rw-r--r-- | arch/microblaze/include/asm/mmu_context.h | 21 | ||||
-rw-r--r-- | arch/microblaze/include/asm/tlb.h | 16 | ||||
-rw-r--r-- | arch/microblaze/include/asm/tlbflush.h | 20 | ||||
-rw-r--r-- | arch/microblaze/mm/init.c | 201 |
5 files changed, 277 insertions, 0 deletions
diff --git a/arch/microblaze/include/asm/mmu.h b/arch/microblaze/include/asm/mmu.h new file mode 100644 index 000000000000..0e0431d61635 --- /dev/null +++ b/arch/microblaze/include/asm/mmu.h | |||
@@ -0,0 +1,19 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2006 Atmark Techno, Inc. | ||
3 | * | ||
4 | * This file is subject to the terms and conditions of the GNU General Public | ||
5 | * License. See the file "COPYING" in the main directory of this archive | ||
6 | * for more details. | ||
7 | */ | ||
8 | |||
9 | #ifndef _ASM_MICROBLAZE_MMU_H | ||
10 | #define _ASM_MICROBLAZE_MMU_H | ||
11 | |||
12 | #ifndef __ASSEMBLY__ | ||
13 | typedef struct { | ||
14 | struct vm_list_struct *vmlist; | ||
15 | unsigned long end_brk; | ||
16 | } mm_context_t; | ||
17 | #endif /* __ASSEMBLY__ */ | ||
18 | |||
19 | #endif /* _ASM_MICROBLAZE_MMU_H */ | ||
diff --git a/arch/microblaze/include/asm/mmu_context.h b/arch/microblaze/include/asm/mmu_context.h new file mode 100644 index 000000000000..150ca01b74ba --- /dev/null +++ b/arch/microblaze/include/asm/mmu_context.h | |||
@@ -0,0 +1,21 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2006 Atmark Techno, Inc. | ||
3 | * | ||
4 | * This file is subject to the terms and conditions of the GNU General Public | ||
5 | * License. See the file "COPYING" in the main directory of this archive | ||
6 | * for more details. | ||
7 | */ | ||
8 | |||
9 | #ifndef _ASM_MICROBLAZE_MMU_CONTEXT_H | ||
10 | #define _ASM_MICROBLAZE_MMU_CONTEXT_H | ||
11 | |||
12 | # define init_new_context(tsk, mm) ({ 0; }) | ||
13 | |||
14 | # define enter_lazy_tlb(mm, tsk) do {} while (0) | ||
15 | # define change_mm_context(old, ctx, _pml4) do {} while (0) | ||
16 | # define destroy_context(mm) do {} while (0) | ||
17 | # define deactivate_mm(tsk, mm) do {} while (0) | ||
18 | # define switch_mm(prev, next, tsk) do {} while (0) | ||
19 | # define activate_mm(prev, next) do {} while (0) | ||
20 | |||
21 | #endif /* _ASM_MICROBLAZE_MMU_CONTEXT_H */ | ||
diff --git a/arch/microblaze/include/asm/tlb.h b/arch/microblaze/include/asm/tlb.h new file mode 100644 index 000000000000..d1dfe3791127 --- /dev/null +++ b/arch/microblaze/include/asm/tlb.h | |||
@@ -0,0 +1,16 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2006 Atmark Techno, Inc. | ||
3 | * | ||
4 | * This file is subject to the terms and conditions of the GNU General Public | ||
5 | * License. See the file "COPYING" in the main directory of this archive | ||
6 | * for more details. | ||
7 | */ | ||
8 | |||
9 | #ifndef _ASM_MICROBLAZE_TLB_H | ||
10 | #define _ASM_MICROBLAZE_TLB_H | ||
11 | |||
12 | #define tlb_flush(tlb) do {} while (0) | ||
13 | |||
14 | #include <asm-generic/tlb.h> | ||
15 | |||
16 | #endif /* _ASM_MICROBLAZE_TLB_H */ | ||
diff --git a/arch/microblaze/include/asm/tlbflush.h b/arch/microblaze/include/asm/tlbflush.h new file mode 100644 index 000000000000..d7fe7629001b --- /dev/null +++ b/arch/microblaze/include/asm/tlbflush.h | |||
@@ -0,0 +1,20 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2006 Atmark Techno, Inc. | ||
3 | * | ||
4 | * This file is subject to the terms and conditions of the GNU General Public | ||
5 | * License. See the file "COPYING" in the main directory of this archive | ||
6 | * for more details. | ||
7 | */ | ||
8 | |||
9 | #ifndef _ASM_MICROBLAZE_TLBFLUSH_H | ||
10 | #define _ASM_MICROBLAZE_TLBFLUSH_H | ||
11 | |||
12 | #define flush_tlb() BUG() | ||
13 | #define flush_tlb_all() BUG() | ||
14 | #define flush_tlb_mm(mm) BUG() | ||
15 | #define flush_tlb_page(vma, addr) BUG() | ||
16 | #define flush_tlb_range(mm, start, end) BUG() | ||
17 | #define flush_tlb_pgtables(mm, start, end) BUG() | ||
18 | #define flush_tlb_kernel_range(start, end) BUG() | ||
19 | |||
20 | #endif /* _ASM_MICROBLAZE_TLBFLUSH_H */ | ||
diff --git a/arch/microblaze/mm/init.c b/arch/microblaze/mm/init.c new file mode 100644 index 000000000000..b0c8213cd6cf --- /dev/null +++ b/arch/microblaze/mm/init.c | |||
@@ -0,0 +1,201 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2008 Michal Simek <monstr@monstr.eu> | ||
3 | * Copyright (C) 2006 Atmark Techno, Inc. | ||
4 | * | ||
5 | * This file is subject to the terms and conditions of the GNU General Public | ||
6 | * License. See the file "COPYING" in the main directory of this archive | ||
7 | * for more details. | ||
8 | */ | ||
9 | |||
10 | #include <linux/bootmem.h> | ||
11 | #include <linux/init.h> | ||
12 | #include <linux/kernel.h> | ||
13 | #include <linux/lmb.h> | ||
14 | #include <linux/mm.h> /* mem_init */ | ||
15 | #include <linux/initrd.h> | ||
16 | #include <linux/pagemap.h> | ||
17 | #include <linux/pfn.h> | ||
18 | #include <linux/swap.h> | ||
19 | |||
20 | #include <asm/page.h> | ||
21 | #include <asm/mmu_context.h> | ||
22 | #include <asm/pgalloc.h> | ||
23 | #include <asm/sections.h> | ||
24 | #include <asm/tlb.h> | ||
25 | |||
26 | unsigned int __page_offset; | ||
27 | /* EXPORT_SYMBOL(__page_offset); */ | ||
28 | |||
29 | char *klimit = _end; | ||
30 | |||
31 | /* | ||
32 | * Initialize the bootmem system and give it all the memory we | ||
33 | * have available. | ||
34 | */ | ||
35 | unsigned int memory_start; | ||
36 | unsigned int memory_end; /* due to mm/nommu.c */ | ||
37 | unsigned int memory_size; | ||
38 | |||
39 | /* | ||
40 | * paging_init() sets up the page tables - in fact we've already done this. | ||
41 | */ | ||
42 | static void __init paging_init(void) | ||
43 | { | ||
44 | int i; | ||
45 | unsigned long zones_size[MAX_NR_ZONES]; | ||
46 | |||
47 | /* | ||
48 | * old: we can DMA to/from any address.put all page into ZONE_DMA | ||
49 | * We use only ZONE_NORMAL | ||
50 | */ | ||
51 | zones_size[ZONE_NORMAL] = max_mapnr; | ||
52 | |||
53 | /* every other zones are empty */ | ||
54 | for (i = 1; i < MAX_NR_ZONES; i++) | ||
55 | zones_size[i] = 0; | ||
56 | |||
57 | free_area_init(zones_size); | ||
58 | } | ||
59 | |||
60 | void __init setup_memory(void) | ||
61 | { | ||
62 | int i; | ||
63 | unsigned long map_size; | ||
64 | u32 kernel_align_start, kernel_align_size; | ||
65 | |||
66 | /* Find main memory where is the kernel */ | ||
67 | for (i = 0; i < lmb.memory.cnt; i++) { | ||
68 | memory_start = (u32) lmb.memory.region[i].base; | ||
69 | memory_end = (u32) lmb.memory.region[i].base | ||
70 | + (u32) lmb.memory.region[i].size; | ||
71 | if ((memory_start <= (u32)_text) && | ||
72 | ((u32)_text <= memory_end)) { | ||
73 | memory_size = memory_end - memory_start; | ||
74 | PAGE_OFFSET = memory_start; | ||
75 | printk(KERN_INFO "%s: Main mem: 0x%x-0x%x, " | ||
76 | "size 0x%08x\n", __func__, memory_start, | ||
77 | memory_end, memory_size); | ||
78 | break; | ||
79 | } | ||
80 | } | ||
81 | |||
82 | if (!memory_start || !memory_end) { | ||
83 | panic("%s: Missing memory setting 0x%08x-0x%08x\n", | ||
84 | __func__, memory_start, memory_end); | ||
85 | } | ||
86 | |||
87 | /* reservation of region where is the kernel */ | ||
88 | kernel_align_start = PAGE_DOWN((u32)_text); | ||
89 | /* ALIGN can be remove because _end in vmlinux.lds.S is align */ | ||
90 | kernel_align_size = PAGE_UP((u32)klimit) - kernel_align_start; | ||
91 | lmb_reserve(kernel_align_start, kernel_align_size); | ||
92 | printk(KERN_INFO "%s: kernel addr=0x%08x-0x%08x size=0x%08x\n", | ||
93 | __func__, kernel_align_start, kernel_align_start | ||
94 | + kernel_align_size, kernel_align_size); | ||
95 | |||
96 | /* | ||
97 | * Kernel: | ||
98 | * start: base phys address of kernel - page align | ||
99 | * end: base phys address of kernel - page align | ||
100 | * | ||
101 | * min_low_pfn - the first page (mm/bootmem.c - node_boot_start) | ||
102 | * max_low_pfn | ||
103 | * max_mapnr - the first unused page (mm/bootmem.c - node_low_pfn) | ||
104 | * num_physpages - number of all pages | ||
105 | */ | ||
106 | |||
107 | /* memory start is from the kernel end (aligned) to higher addr */ | ||
108 | min_low_pfn = memory_start >> PAGE_SHIFT; /* minimum for allocation */ | ||
109 | /* RAM is assumed contiguous */ | ||
110 | num_physpages = max_mapnr = memory_size >> PAGE_SHIFT; | ||
111 | max_pfn = max_low_pfn = memory_end >> PAGE_SHIFT; | ||
112 | |||
113 | printk(KERN_INFO "%s: max_mapnr: %#lx\n", __func__, max_mapnr); | ||
114 | printk(KERN_INFO "%s: min_low_pfn: %#lx\n", __func__, min_low_pfn); | ||
115 | printk(KERN_INFO "%s: max_low_pfn: %#lx\n", __func__, max_low_pfn); | ||
116 | |||
117 | /* | ||
118 | * Find an area to use for the bootmem bitmap. | ||
119 | * We look for the first area which is at least | ||
120 | * 128kB in length (128kB is enough for a bitmap | ||
121 | * for 4GB of memory, using 4kB pages), plus 1 page | ||
122 | * (in case the address isn't page-aligned). | ||
123 | */ | ||
124 | map_size = init_bootmem_node(NODE_DATA(0), PFN_UP(TOPHYS((u32)_end)), | ||
125 | min_low_pfn, max_low_pfn); | ||
126 | |||
127 | lmb_reserve(PFN_UP(TOPHYS((u32)_end)) << PAGE_SHIFT, map_size); | ||
128 | |||
129 | /* free bootmem is whole main memory */ | ||
130 | free_bootmem(memory_start, memory_size); | ||
131 | |||
132 | /* reserve allocate blocks */ | ||
133 | for (i = 0; i < lmb.reserved.cnt; i++) { | ||
134 | pr_debug("reserved %d - 0x%08x-0x%08x\n", i, | ||
135 | (u32) lmb.reserved.region[i].base, | ||
136 | (u32) lmb_size_bytes(&lmb.reserved, i)); | ||
137 | reserve_bootmem(lmb.reserved.region[i].base, | ||
138 | lmb_size_bytes(&lmb.reserved, i) - 1, BOOTMEM_DEFAULT); | ||
139 | } | ||
140 | paging_init(); | ||
141 | } | ||
142 | |||
143 | void free_init_pages(char *what, unsigned long begin, unsigned long end) | ||
144 | { | ||
145 | unsigned long addr; | ||
146 | |||
147 | for (addr = begin; addr < end; addr += PAGE_SIZE) { | ||
148 | ClearPageReserved(virt_to_page(addr)); | ||
149 | init_page_count(virt_to_page(addr)); | ||
150 | memset((void *)addr, 0xcc, PAGE_SIZE); | ||
151 | free_page(addr); | ||
152 | totalram_pages++; | ||
153 | } | ||
154 | printk(KERN_INFO "Freeing %s: %ldk freed\n", what, (end - begin) >> 10); | ||
155 | } | ||
156 | |||
157 | #ifdef CONFIG_BLK_DEV_INITRD | ||
158 | void free_initrd_mem(unsigned long start, unsigned long end) | ||
159 | { | ||
160 | int pages = 0; | ||
161 | for (; start < end; start += PAGE_SIZE) { | ||
162 | ClearPageReserved(virt_to_page(start)); | ||
163 | init_page_count(virt_to_page(start)); | ||
164 | free_page(start); | ||
165 | totalram_pages++; | ||
166 | pages++; | ||
167 | } | ||
168 | printk(KERN_NOTICE "Freeing initrd memory: %dk freed\n", pages); | ||
169 | } | ||
170 | #endif | ||
171 | |||
172 | void free_initmem(void) | ||
173 | { | ||
174 | free_init_pages("unused kernel memory", | ||
175 | (unsigned long)(&__init_begin), | ||
176 | (unsigned long)(&__init_end)); | ||
177 | } | ||
178 | |||
179 | /* FIXME from arch/powerpc/mm/mem.c*/ | ||
180 | void show_mem(void) | ||
181 | { | ||
182 | printk(KERN_NOTICE "%s\n", __func__); | ||
183 | } | ||
184 | |||
185 | void __init mem_init(void) | ||
186 | { | ||
187 | high_memory = (void *)__va(memory_end); | ||
188 | /* this will put all memory onto the freelists */ | ||
189 | totalram_pages += free_all_bootmem(); | ||
190 | |||
191 | printk(KERN_INFO "Memory: %luk/%luk available\n", | ||
192 | (unsigned long) nr_free_pages() << (PAGE_SHIFT-10), | ||
193 | num_physpages << (PAGE_SHIFT-10)); | ||
194 | } | ||
195 | |||
196 | /* Check against bounds of physical memory */ | ||
197 | int ___range_ok(unsigned long addr, unsigned long size) | ||
198 | { | ||
199 | return ((addr < memory_start) || | ||
200 | ((addr + size) > memory_end)); | ||
201 | } | ||