Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

microblaze_mmu_v2: MMU initialization

Signed-off-by: Michal Simek <monstr@monstr.eu>

+154 -4
+154 -4
arch/microblaze/mm/init.c
··· 23 23 #include <asm/sections.h> 24 24 #include <asm/tlb.h> 25 25 26 + #ifndef CONFIG_MMU 26 27 unsigned int __page_offset; 27 28 EXPORT_SYMBOL(__page_offset); 29 + 30 + #else 31 + DEFINE_PER_CPU(struct mmu_gather, mmu_gathers); 32 + 33 + int mem_init_done; 34 + static int init_bootmem_done; 35 + #endif /* CONFIG_MMU */ 28 36 29 37 char *klimit = _end; 30 38 ··· 40 32 * Initialize the bootmem system and give it all the memory we 41 33 * have available. 42 34 */ 43 - unsigned int memory_start; 44 - unsigned int memory_end; /* due to mm/nommu.c */ 45 - unsigned int memory_size; 35 + unsigned long memory_start; 36 + unsigned long memory_end; /* due to mm/nommu.c */ 37 + unsigned long memory_size; 46 38 47 39 /* 48 40 * paging_init() sets up the page tables - in fact we've already done this. ··· 67 59 { 68 60 int i; 69 61 unsigned long map_size; 62 + #ifndef CONFIG_MMU 70 63 u32 kernel_align_start, kernel_align_size; 71 64 72 65 /* Find main memory where is the kernel */ ··· 100 91 __func__, kernel_align_start, kernel_align_start 101 92 + kernel_align_size, kernel_align_size); 102 93 94 + #endif 103 95 /* 104 96 * Kernel: 105 97 * start: base phys address of kernel - page align ··· 129 119 * for 4GB of memory, using 4kB pages), plus 1 page 130 120 * (in case the address isn't page-aligned). 131 121 */ 122 + #ifndef CONFIG_MMU 132 123 map_size = init_bootmem_node(NODE_DATA(0), PFN_UP(TOPHYS((u32)_end)), 133 124 min_low_pfn, max_low_pfn); 134 - 125 + #else 126 + map_size = init_bootmem_node(&contig_page_data, 127 + PFN_UP(TOPHYS((u32)_end)), min_low_pfn, max_low_pfn); 128 + #endif 135 129 lmb_reserve(PFN_UP(TOPHYS((u32)_end)) << PAGE_SHIFT, map_size); 136 130 137 131 /* free bootmem is whole main memory */ ··· 149 135 reserve_bootmem(lmb.reserved.region[i].base, 150 136 lmb_size_bytes(&lmb.reserved, i) - 1, BOOTMEM_DEFAULT); 151 137 } 138 + #ifdef CONFIG_MMU 139 + init_bootmem_done = 1; 140 + #endif 152 141 paging_init(); 153 142 } 154 143 ··· 206 189 printk(KERN_INFO "Memory: %luk/%luk available\n", 207 190 (unsigned long) nr_free_pages() << (PAGE_SHIFT-10), 208 191 num_physpages << (PAGE_SHIFT-10)); 192 + #ifdef CONFIG_MMU 193 + mem_init_done = 1; 194 + #endif 209 195 } 210 196 197 + #ifndef CONFIG_MMU 211 198 /* Check against bounds of physical memory */ 212 199 int ___range_ok(unsigned long addr, unsigned long size) 213 200 { ··· 219 198 ((addr + size) > memory_end)); 220 199 } 221 200 EXPORT_SYMBOL(___range_ok); 201 + 202 + #else 203 + int page_is_ram(unsigned long pfn) 204 + { 205 + return pfn < max_low_pfn; 206 + } 207 + 208 + /* 209 + * Check for command-line options that affect what MMU_init will do. 210 + */ 211 + static void mm_cmdline_setup(void) 212 + { 213 + unsigned long maxmem = 0; 214 + char *p = cmd_line; 215 + 216 + /* Look for mem= option on command line */ 217 + p = strstr(cmd_line, "mem="); 218 + if (p) { 219 + p += 4; 220 + maxmem = memparse(p, &p); 221 + if (maxmem && memory_size > maxmem) { 222 + memory_size = maxmem; 223 + memory_end = memory_start + memory_size; 224 + lmb.memory.region[0].size = memory_size; 225 + } 226 + } 227 + } 228 + 229 + /* 230 + * MMU_init_hw does the chip-specific initialization of the MMU hardware. 231 + */ 232 + static void __init mmu_init_hw(void) 233 + { 234 + /* 235 + * The Zone Protection Register (ZPR) defines how protection will 236 + * be applied to every page which is a member of a given zone. At 237 + * present, we utilize only two of the zones. 238 + * The zone index bits (of ZSEL) in the PTE are used for software 239 + * indicators, except the LSB. For user access, zone 1 is used, 240 + * for kernel access, zone 0 is used. We set all but zone 1 241 + * to zero, allowing only kernel access as indicated in the PTE. 242 + * For zone 1, we set a 01 binary (a value of 10 will not work) 243 + * to allow user access as indicated in the PTE. This also allows 244 + * kernel access as indicated in the PTE. 245 + */ 246 + __asm__ __volatile__ ("ori r11, r0, 0x10000000;" \ 247 + "mts rzpr, r11;" 248 + : : : "r11"); 249 + } 250 + 251 + /* 252 + * MMU_init sets up the basic memory mappings for the kernel, 253 + * including both RAM and possibly some I/O regions, 254 + * and sets up the page tables and the MMU hardware ready to go. 255 + */ 256 + 257 + /* called from head.S */ 258 + asmlinkage void __init mmu_init(void) 259 + { 260 + unsigned int kstart, ksize; 261 + 262 + if (!lmb.reserved.cnt) { 263 + printk(KERN_EMERG "Error memory count\n"); 264 + machine_restart(NULL); 265 + } 266 + 267 + if ((u32) lmb.memory.region[0].size < 0x1000000) { 268 + printk(KERN_EMERG "Memory must be greater than 16MB\n"); 269 + machine_restart(NULL); 270 + } 271 + /* Find main memory where the kernel is */ 272 + memory_start = (u32) lmb.memory.region[0].base; 273 + memory_end = (u32) lmb.memory.region[0].base + 274 + (u32) lmb.memory.region[0].size; 275 + memory_size = memory_end - memory_start; 276 + 277 + mm_cmdline_setup(); /* FIXME parse args from command line - not used */ 278 + 279 + /* 280 + * Map out the kernel text/data/bss from the available physical 281 + * memory. 282 + */ 283 + kstart = __pa(CONFIG_KERNEL_START); /* kernel start */ 284 + /* kernel size */ 285 + ksize = PAGE_ALIGN(((u32)_end - (u32)CONFIG_KERNEL_START)); 286 + lmb_reserve(kstart, ksize); 287 + 288 + #if defined(CONFIG_BLK_DEV_INITRD) 289 + /* Remove the init RAM disk from the available memory. */ 290 + /* if (initrd_start) { 291 + mem_pieces_remove(&phys_avail, __pa(initrd_start), 292 + initrd_end - initrd_start, 1); 293 + }*/ 294 + #endif /* CONFIG_BLK_DEV_INITRD */ 295 + 296 + /* Initialize the MMU hardware */ 297 + mmu_init_hw(); 298 + 299 + /* Map in all of RAM starting at CONFIG_KERNEL_START */ 300 + mapin_ram(); 301 + 302 + #ifdef HIGHMEM_START_BOOL 303 + ioremap_base = HIGHMEM_START; 304 + #else 305 + ioremap_base = 0xfe000000UL; /* for now, could be 0xfffff000 */ 306 + #endif /* CONFIG_HIGHMEM */ 307 + ioremap_bot = ioremap_base; 308 + 309 + /* Initialize the context management stuff */ 310 + mmu_context_init(); 311 + } 312 + 313 + /* This is only called until mem_init is done. */ 314 + void __init *early_get_page(void) 315 + { 316 + void *p; 317 + if (init_bootmem_done) { 318 + p = alloc_bootmem_pages(PAGE_SIZE); 319 + } else { 320 + /* 321 + * Mem start + 32MB -> here is limit 322 + * because of mem mapping from head.S 323 + */ 324 + p = __va(lmb_alloc_base(PAGE_SIZE, PAGE_SIZE, 325 + memory_start + 0x2000000)); 326 + } 327 + return p; 328 + } 329 + #endif /* CONFIG_MMU */