David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 1 | /* MN10300 Memory management initialisation |
| 2 | * |
| 3 | * Copyright (C) 2007 Matsushita Electric Industrial Co., Ltd. |
| 4 | * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved. |
| 5 | * Modified by David Howells (dhowells@redhat.com) |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public Licence |
| 9 | * as published by the Free Software Foundation; either version |
| 10 | * 2 of the Licence, or (at your option) any later version. |
| 11 | */ |
| 12 | #include <linux/signal.h> |
| 13 | #include <linux/sched.h> |
| 14 | #include <linux/kernel.h> |
| 15 | #include <linux/errno.h> |
| 16 | #include <linux/string.h> |
| 17 | #include <linux/types.h> |
| 18 | #include <linux/ptrace.h> |
| 19 | #include <linux/mman.h> |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 20 | #include <linux/fs.h> |
| 21 | #include <linux/mm.h> |
| 22 | #include <linux/swap.h> |
| 23 | #include <linux/smp.h> |
| 24 | #include <linux/init.h> |
| 25 | #include <linux/initrd.h> |
| 26 | #include <linux/highmem.h> |
| 27 | #include <linux/pagemap.h> |
| 28 | #include <linux/bootmem.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 29 | #include <linux/gfp.h> |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 30 | |
| 31 | #include <asm/processor.h> |
| 32 | #include <asm/system.h> |
| 33 | #include <asm/uaccess.h> |
| 34 | #include <asm/pgtable.h> |
| 35 | #include <asm/pgalloc.h> |
| 36 | #include <asm/dma.h> |
| 37 | #include <asm/tlb.h> |
| 38 | #include <asm/sections.h> |
| 39 | |
| 40 | DEFINE_PER_CPU(struct mmu_gather, mmu_gathers); |
| 41 | |
| 42 | unsigned long highstart_pfn, highend_pfn; |
| 43 | |
| 44 | /* |
| 45 | * set up paging |
| 46 | */ |
| 47 | void __init paging_init(void) |
| 48 | { |
| 49 | unsigned long zones_size[MAX_NR_ZONES] = {0,}; |
| 50 | pte_t *ppte; |
| 51 | int loop; |
| 52 | |
| 53 | /* main kernel space -> RAM mapping is handled as 1:1 transparent by |
| 54 | * the MMU */ |
| 55 | memset(swapper_pg_dir, 0, sizeof(swapper_pg_dir)); |
| 56 | memset(kernel_vmalloc_ptes, 0, sizeof(kernel_vmalloc_ptes)); |
| 57 | |
| 58 | /* load the VMALLOC area PTE table addresses into the kernel PGD */ |
| 59 | ppte = kernel_vmalloc_ptes; |
| 60 | for (loop = VMALLOC_START / (PAGE_SIZE * PTRS_PER_PTE); |
| 61 | loop < VMALLOC_END / (PAGE_SIZE * PTRS_PER_PTE); |
| 62 | loop++ |
| 63 | ) { |
| 64 | set_pgd(swapper_pg_dir + loop, __pgd(__pa(ppte) | _PAGE_TABLE)); |
| 65 | ppte += PAGE_SIZE / sizeof(pte_t); |
| 66 | } |
| 67 | |
| 68 | /* declare the sizes of the RAM zones (only use the normal zone) */ |
| 69 | zones_size[ZONE_NORMAL] = |
Johannes Weiner | 3560e24 | 2008-07-23 21:28:09 -0700 | [diff] [blame] | 70 | contig_page_data.bdata->node_low_pfn - |
| 71 | contig_page_data.bdata->node_min_pfn; |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 72 | |
| 73 | /* pass the memory from the bootmem allocator to the main allocator */ |
| 74 | free_area_init(zones_size); |
| 75 | |
David Howells | 492e675 | 2010-10-27 17:28:49 +0100 | [diff] [blame^] | 76 | local_flush_tlb_all(); |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | /* |
| 80 | * transfer all the memory from the bootmem allocator to the runtime allocator |
| 81 | */ |
| 82 | void __init mem_init(void) |
| 83 | { |
| 84 | int codesize, reservedpages, datasize, initsize; |
| 85 | int tmp; |
| 86 | |
Stoyan Gaydarov | 292aa14 | 2010-10-27 17:28:33 +0100 | [diff] [blame] | 87 | BUG_ON(!mem_map); |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 88 | |
Johannes Weiner | 3560e24 | 2008-07-23 21:28:09 -0700 | [diff] [blame] | 89 | #define START_PFN (contig_page_data.bdata->node_min_pfn) |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 90 | #define MAX_LOW_PFN (contig_page_data.bdata->node_low_pfn) |
| 91 | |
| 92 | max_mapnr = num_physpages = MAX_LOW_PFN - START_PFN; |
| 93 | high_memory = (void *) __va(MAX_LOW_PFN * PAGE_SIZE); |
| 94 | |
| 95 | /* clear the zero-page */ |
| 96 | memset(empty_zero_page, 0, PAGE_SIZE); |
| 97 | |
| 98 | /* this will put all low memory onto the freelists */ |
| 99 | totalram_pages += free_all_bootmem(); |
| 100 | |
| 101 | reservedpages = 0; |
| 102 | for (tmp = 0; tmp < num_physpages; tmp++) |
| 103 | if (PageReserved(&mem_map[tmp])) |
| 104 | reservedpages++; |
| 105 | |
| 106 | codesize = (unsigned long) &_etext - (unsigned long) &_stext; |
| 107 | datasize = (unsigned long) &_edata - (unsigned long) &_etext; |
| 108 | initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin; |
| 109 | |
| 110 | printk(KERN_INFO |
| 111 | "Memory: %luk/%luk available" |
| 112 | " (%dk kernel code, %dk reserved, %dk data, %dk init," |
| 113 | " %ldk highmem)\n", |
Geert Uytterhoeven | cc013a8 | 2009-09-21 17:02:36 -0700 | [diff] [blame] | 114 | nr_free_pages() << (PAGE_SHIFT - 10), |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 115 | max_mapnr << (PAGE_SHIFT - 10), |
| 116 | codesize >> 10, |
| 117 | reservedpages << (PAGE_SHIFT - 10), |
| 118 | datasize >> 10, |
| 119 | initsize >> 10, |
Andreas Fenkart | 4b52940 | 2010-01-08 14:42:31 -0800 | [diff] [blame] | 120 | totalhigh_pages << (PAGE_SHIFT - 10)); |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | /* |
| 124 | * |
| 125 | */ |
| 126 | void free_init_pages(char *what, unsigned long begin, unsigned long end) |
| 127 | { |
| 128 | unsigned long addr; |
| 129 | |
| 130 | for (addr = begin; addr < end; addr += PAGE_SIZE) { |
| 131 | ClearPageReserved(virt_to_page(addr)); |
| 132 | init_page_count(virt_to_page(addr)); |
| 133 | memset((void *) addr, 0xcc, PAGE_SIZE); |
| 134 | free_page(addr); |
| 135 | totalram_pages++; |
| 136 | } |
| 137 | printk(KERN_INFO "Freeing %s: %ldk freed\n", what, (end - begin) >> 10); |
| 138 | } |
| 139 | |
| 140 | /* |
| 141 | * recycle memory containing stuff only required for initialisation |
| 142 | */ |
| 143 | void free_initmem(void) |
| 144 | { |
| 145 | free_init_pages("unused kernel memory", |
| 146 | (unsigned long) &__init_begin, |
| 147 | (unsigned long) &__init_end); |
| 148 | } |
| 149 | |
| 150 | /* |
| 151 | * dispose of the memory on which the initial ramdisk resided |
| 152 | */ |
| 153 | #ifdef CONFIG_BLK_DEV_INITRD |
| 154 | void free_initrd_mem(unsigned long start, unsigned long end) |
| 155 | { |
| 156 | free_init_pages("initrd memory", start, end); |
| 157 | } |
| 158 | #endif |