diff options
Diffstat (limited to 'arch/arm/mm/init.c')
| -rw-r--r-- | arch/arm/mm/init.c | 224 |
1 files changed, 16 insertions, 208 deletions
diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c index fe3f7f625008..22217fe2650b 100644 --- a/arch/arm/mm/init.c +++ b/arch/arm/mm/init.c | |||
| @@ -25,10 +25,9 @@ | |||
| 25 | #include <asm/mach/arch.h> | 25 | #include <asm/mach/arch.h> |
| 26 | #include <asm/mach/map.h> | 26 | #include <asm/mach/map.h> |
| 27 | 27 | ||
| 28 | DEFINE_PER_CPU(struct mmu_gather, mmu_gathers); | 28 | #include "mm.h" |
| 29 | 29 | ||
| 30 | extern pgd_t swapper_pg_dir[PTRS_PER_PGD]; | 30 | extern void _text, _etext, __data_start, _end, __init_begin, __init_end; |
| 31 | extern void _stext, _text, _etext, __data_start, _end, __init_begin, __init_end; | ||
| 32 | extern unsigned long phys_initrd_start; | 31 | extern unsigned long phys_initrd_start; |
| 33 | extern unsigned long phys_initrd_size; | 32 | extern unsigned long phys_initrd_size; |
| 34 | 33 | ||
| @@ -38,12 +37,6 @@ extern unsigned long phys_initrd_size; | |||
| 38 | */ | 37 | */ |
| 39 | static struct meminfo meminfo __initdata = { 0, }; | 38 | static struct meminfo meminfo __initdata = { 0, }; |
| 40 | 39 | ||
| 41 | /* | ||
| 42 | * empty_zero_page is a special page that is used for | ||
| 43 | * zero-initialized data and COW. | ||
| 44 | */ | ||
| 45 | struct page *empty_zero_page; | ||
| 46 | |||
| 47 | void show_mem(void) | 40 | void show_mem(void) |
| 48 | { | 41 | { |
| 49 | int free = 0, total = 0, reserved = 0; | 42 | int free = 0, total = 0, reserved = 0; |
| @@ -83,16 +76,6 @@ void show_mem(void) | |||
| 83 | printk("%d pages swap cached\n", cached); | 76 | printk("%d pages swap cached\n", cached); |
| 84 | } | 77 | } |
| 85 | 78 | ||
| 86 | static inline pmd_t *pmd_off(pgd_t *pgd, unsigned long virt) | ||
| 87 | { | ||
| 88 | return pmd_offset(pgd, virt); | ||
| 89 | } | ||
| 90 | |||
| 91 | static inline pmd_t *pmd_off_k(unsigned long virt) | ||
| 92 | { | ||
| 93 | return pmd_off(pgd_offset_k(virt), virt); | ||
| 94 | } | ||
| 95 | |||
| 96 | #define for_each_nodebank(iter,mi,no) \ | 79 | #define for_each_nodebank(iter,mi,no) \ |
| 97 | for (iter = 0; iter < mi->nr_banks; iter++) \ | 80 | for (iter = 0; iter < mi->nr_banks; iter++) \ |
| 98 | if (mi->bank[iter].node == no) | 81 | if (mi->bank[iter].node == no) |
| @@ -176,62 +159,20 @@ static int __init check_initrd(struct meminfo *mi) | |||
| 176 | return initrd_node; | 159 | return initrd_node; |
| 177 | } | 160 | } |
| 178 | 161 | ||
| 179 | /* | 162 | static inline void map_memory_bank(struct membank *bank) |
| 180 | * Reserve the various regions of node 0 | ||
| 181 | */ | ||
| 182 | static __init void reserve_node_zero(pg_data_t *pgdat) | ||
| 183 | { | 163 | { |
| 184 | unsigned long res_size = 0; | 164 | #ifdef CONFIG_MMU |
| 185 | 165 | struct map_desc map; | |
| 186 | /* | ||
| 187 | * Register the kernel text and data with bootmem. | ||
| 188 | * Note that this can only be in node 0. | ||
| 189 | */ | ||
| 190 | #ifdef CONFIG_XIP_KERNEL | ||
| 191 | reserve_bootmem_node(pgdat, __pa(&__data_start), &_end - &__data_start); | ||
| 192 | #else | ||
| 193 | reserve_bootmem_node(pgdat, __pa(&_stext), &_end - &_stext); | ||
| 194 | #endif | ||
| 195 | |||
| 196 | /* | ||
| 197 | * Reserve the page tables. These are already in use, | ||
| 198 | * and can only be in node 0. | ||
| 199 | */ | ||
| 200 | reserve_bootmem_node(pgdat, __pa(swapper_pg_dir), | ||
| 201 | PTRS_PER_PGD * sizeof(pgd_t)); | ||
| 202 | |||
| 203 | /* | ||
| 204 | * Hmm... This should go elsewhere, but we really really need to | ||
| 205 | * stop things allocating the low memory; ideally we need a better | ||
| 206 | * implementation of GFP_DMA which does not assume that DMA-able | ||
| 207 | * memory starts at zero. | ||
| 208 | */ | ||
| 209 | if (machine_is_integrator() || machine_is_cintegrator()) | ||
| 210 | res_size = __pa(swapper_pg_dir) - PHYS_OFFSET; | ||
| 211 | 166 | ||
| 212 | /* | 167 | map.pfn = __phys_to_pfn(bank->start); |
| 213 | * These should likewise go elsewhere. They pre-reserve the | 168 | map.virtual = __phys_to_virt(bank->start); |
| 214 | * screen memory region at the start of main system memory. | 169 | map.length = bank->size; |
| 215 | */ | 170 | map.type = MT_MEMORY; |
| 216 | if (machine_is_edb7211()) | ||
| 217 | res_size = 0x00020000; | ||
| 218 | if (machine_is_p720t()) | ||
| 219 | res_size = 0x00014000; | ||
| 220 | 171 | ||
| 221 | #ifdef CONFIG_SA1111 | 172 | create_mapping(&map); |
| 222 | /* | ||
| 223 | * Because of the SA1111 DMA bug, we want to preserve our | ||
| 224 | * precious DMA-able memory... | ||
| 225 | */ | ||
| 226 | res_size = __pa(swapper_pg_dir) - PHYS_OFFSET; | ||
| 227 | #endif | 173 | #endif |
| 228 | if (res_size) | ||
| 229 | reserve_bootmem_node(pgdat, PHYS_OFFSET, res_size); | ||
| 230 | } | 174 | } |
| 231 | 175 | ||
| 232 | void __init build_mem_type_table(void); | ||
| 233 | void __init create_mapping(struct map_desc *md); | ||
| 234 | |||
| 235 | static unsigned long __init | 176 | static unsigned long __init |
| 236 | bootmem_init_node(int node, int initrd_node, struct meminfo *mi) | 177 | bootmem_init_node(int node, int initrd_node, struct meminfo *mi) |
| 237 | { | 178 | { |
| @@ -248,23 +189,18 @@ bootmem_init_node(int node, int initrd_node, struct meminfo *mi) | |||
| 248 | * Calculate the pfn range, and map the memory banks for this node. | 189 | * Calculate the pfn range, and map the memory banks for this node. |
| 249 | */ | 190 | */ |
| 250 | for_each_nodebank(i, mi, node) { | 191 | for_each_nodebank(i, mi, node) { |
| 192 | struct membank *bank = &mi->bank[i]; | ||
| 251 | unsigned long start, end; | 193 | unsigned long start, end; |
| 252 | struct map_desc map; | ||
| 253 | 194 | ||
| 254 | start = mi->bank[i].start >> PAGE_SHIFT; | 195 | start = bank->start >> PAGE_SHIFT; |
| 255 | end = (mi->bank[i].start + mi->bank[i].size) >> PAGE_SHIFT; | 196 | end = (bank->start + bank->size) >> PAGE_SHIFT; |
| 256 | 197 | ||
| 257 | if (start_pfn > start) | 198 | if (start_pfn > start) |
| 258 | start_pfn = start; | 199 | start_pfn = start; |
| 259 | if (end_pfn < end) | 200 | if (end_pfn < end) |
| 260 | end_pfn = end; | 201 | end_pfn = end; |
| 261 | 202 | ||
| 262 | map.pfn = __phys_to_pfn(mi->bank[i].start); | 203 | map_memory_bank(bank); |
| 263 | map.virtual = __phys_to_virt(mi->bank[i].start); | ||
| 264 | map.length = mi->bank[i].size; | ||
| 265 | map.type = MT_MEMORY; | ||
| 266 | |||
| 267 | create_mapping(&map); | ||
| 268 | } | 204 | } |
| 269 | 205 | ||
| 270 | /* | 206 | /* |
| @@ -346,9 +282,9 @@ bootmem_init_node(int node, int initrd_node, struct meminfo *mi) | |||
| 346 | return end_pfn; | 282 | return end_pfn; |
| 347 | } | 283 | } |
| 348 | 284 | ||
| 349 | static void __init bootmem_init(struct meminfo *mi) | 285 | void __init bootmem_init(struct meminfo *mi) |
| 350 | { | 286 | { |
| 351 | unsigned long addr, memend_pfn = 0; | 287 | unsigned long memend_pfn = 0; |
| 352 | int node, initrd_node, i; | 288 | int node, initrd_node, i; |
| 353 | 289 | ||
| 354 | /* | 290 | /* |
| @@ -361,26 +297,6 @@ static void __init bootmem_init(struct meminfo *mi) | |||
| 361 | memcpy(&meminfo, mi, sizeof(meminfo)); | 297 | memcpy(&meminfo, mi, sizeof(meminfo)); |
| 362 | 298 | ||
| 363 | /* | 299 | /* |
| 364 | * Clear out all the mappings below the kernel image. | ||
| 365 | */ | ||
| 366 | for (addr = 0; addr < MODULE_START; addr += PGDIR_SIZE) | ||
| 367 | pmd_clear(pmd_off_k(addr)); | ||
| 368 | #ifdef CONFIG_XIP_KERNEL | ||
| 369 | /* The XIP kernel is mapped in the module area -- skip over it */ | ||
| 370 | addr = ((unsigned long)&_etext + PGDIR_SIZE - 1) & PGDIR_MASK; | ||
| 371 | #endif | ||
| 372 | for ( ; addr < PAGE_OFFSET; addr += PGDIR_SIZE) | ||
| 373 | pmd_clear(pmd_off_k(addr)); | ||
| 374 | |||
| 375 | /* | ||
| 376 | * Clear out all the kernel space mappings, except for the first | ||
| 377 | * memory bank, up to the end of the vmalloc region. | ||
| 378 | */ | ||
| 379 | for (addr = __phys_to_virt(mi->bank[0].start + mi->bank[0].size); | ||
| 380 | addr < VMALLOC_END; addr += PGDIR_SIZE) | ||
| 381 | pmd_clear(pmd_off_k(addr)); | ||
| 382 | |||
| 383 | /* | ||
| 384 | * Locate which node contains the ramdisk image, if any. | 300 | * Locate which node contains the ramdisk image, if any. |
| 385 | */ | 301 | */ |
| 386 | initrd_node = check_initrd(mi); | 302 | initrd_node = check_initrd(mi); |
| @@ -413,114 +329,6 @@ static void __init bootmem_init(struct meminfo *mi) | |||
| 413 | max_pfn = max_low_pfn = memend_pfn - PHYS_PFN_OFFSET; | 329 | max_pfn = max_low_pfn = memend_pfn - PHYS_PFN_OFFSET; |
| 414 | } | 330 | } |
| 415 | 331 | ||
| 416 | /* | ||
| 417 | * Set up device the mappings. Since we clear out the page tables for all | ||
| 418 | * mappings above VMALLOC_END, we will remove any debug device mappings. | ||
| 419 | * This means you have to be careful how you debug this function, or any | ||
| 420 | * called function. This means you can't use any function or debugging | ||
| 421 | * method which may touch any device, otherwise the kernel _will_ crash. | ||
| 422 | */ | ||
| 423 | static void __init devicemaps_init(struct machine_desc *mdesc) | ||
| 424 | { | ||
| 425 | struct map_desc map; | ||
| 426 | unsigned long addr; | ||
| 427 | void *vectors; | ||
| 428 | |||
| 429 | /* | ||
| 430 | * Allocate the vector page early. | ||
| 431 | */ | ||
| 432 | vectors = alloc_bootmem_low_pages(PAGE_SIZE); | ||
| 433 | BUG_ON(!vectors); | ||
| 434 | |||
| 435 | for (addr = VMALLOC_END; addr; addr += PGDIR_SIZE) | ||
| 436 | pmd_clear(pmd_off_k(addr)); | ||
| 437 | |||
| 438 | /* | ||
| 439 | * Map the kernel if it is XIP. | ||
| 440 | * It is always first in the modulearea. | ||
| 441 | */ | ||
| 442 | #ifdef CONFIG_XIP_KERNEL | ||
| 443 | map.pfn = __phys_to_pfn(CONFIG_XIP_PHYS_ADDR & PGDIR_MASK); | ||
| 444 | map.virtual = MODULE_START; | ||
| 445 | map.length = ((unsigned long)&_etext - map.virtual + ~PGDIR_MASK) & PGDIR_MASK; | ||
| 446 | map.type = MT_ROM; | ||
| 447 | create_mapping(&map); | ||
| 448 | #endif | ||
| 449 | |||
| 450 | /* | ||
| 451 | * Map the cache flushing regions. | ||
| 452 | */ | ||
| 453 | #ifdef FLUSH_BASE | ||
| 454 | map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS); | ||
| 455 | map.virtual = FLUSH_BASE; | ||
| 456 | map.length = SZ_1M; | ||
| 457 | map.type = MT_CACHECLEAN; | ||
| 458 | create_mapping(&map); | ||
| 459 | #endif | ||
| 460 | #ifdef FLUSH_BASE_MINICACHE | ||
| 461 | map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS + SZ_1M); | ||
| 462 | map.virtual = FLUSH_BASE_MINICACHE; | ||
| 463 | map.length = SZ_1M; | ||
| 464 | map.type = MT_MINICLEAN; | ||
| 465 | create_mapping(&map); | ||
| 466 | #endif | ||
| 467 | |||
| 468 | /* | ||
| 469 | * Create a mapping for the machine vectors at the high-vectors | ||
| 470 | * location (0xffff0000). If we aren't using high-vectors, also | ||
| 471 | * create a mapping at the low-vectors virtual address. | ||
| 472 | */ | ||
| 473 | map.pfn = __phys_to_pfn(virt_to_phys(vectors)); | ||
| 474 | map.virtual = 0xffff0000; | ||
| 475 | map.length = PAGE_SIZE; | ||
| 476 | map.type = MT_HIGH_VECTORS; | ||
| 477 | create_mapping(&map); | ||
| 478 | |||
| 479 | if (!vectors_high()) { | ||
| 480 | map.virtual = 0; | ||
| 481 | map.type = MT_LOW_VECTORS; | ||
| 482 | create_mapping(&map); | ||
| 483 | } | ||
| 484 | |||
| 485 | /* | ||
| 486 | * Ask the machine support to map in the statically mapped devices. | ||
| 487 | */ | ||
| 488 | if (mdesc->map_io) | ||
| 489 | mdesc->map_io(); | ||
| 490 | |||
| 491 | /* | ||
| 492 | * Finally flush the caches and tlb to ensure that we're in a | ||
| 493 | * consistent state wrt the writebuffer. This also ensures that | ||
| 494 | * any write-allocated cache lines in the vector page are written | ||
| 495 | * back. After this point, we can start to touch devices again. | ||
| 496 | */ | ||
| 497 | local_flush_tlb_all(); | ||
| 498 | flush_cache_all(); | ||
| 499 | } | ||
| 500 | |||
| 501 | /* | ||
| 502 | * paging_init() sets up the page tables, initialises the zone memory | ||
| 503 | * maps, and sets up the zero page, bad page and bad page tables. | ||
| 504 | */ | ||
| 505 | void __init paging_init(struct meminfo *mi, struct machine_desc *mdesc) | ||
| 506 | { | ||
| 507 | void *zero_page; | ||
| 508 | |||
| 509 | build_mem_type_table(); | ||
| 510 | bootmem_init(mi); | ||
| 511 | devicemaps_init(mdesc); | ||
| 512 | |||
| 513 | top_pmd = pmd_off_k(0xffff0000); | ||
| 514 | |||
| 515 | /* | ||
| 516 | * allocate the zero page. Note that we count on this going ok. | ||
| 517 | */ | ||
| 518 | zero_page = alloc_bootmem_low_pages(PAGE_SIZE); | ||
| 519 | memzero(zero_page, PAGE_SIZE); | ||
| 520 | empty_zero_page = virt_to_page(zero_page); | ||
| 521 | flush_dcache_page(empty_zero_page); | ||
| 522 | } | ||
| 523 | |||
| 524 | static inline void free_area(unsigned long addr, unsigned long end, char *s) | 332 | static inline void free_area(unsigned long addr, unsigned long end, char *s) |
| 525 | { | 333 | { |
| 526 | unsigned int size = (end - addr) >> 10; | 334 | unsigned int size = (end - addr) >> 10; |
