Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/m32r/mm/init.c |
| 3 | * |
| 4 | * Copyright (c) 2001, 2002 Hitoshi Yamamoto |
| 5 | * |
| 6 | * Some code taken from sh version. |
| 7 | * Copyright (C) 1999 Niibe Yutaka |
| 8 | * Based on linux/arch/i386/mm/init.c: |
| 9 | * Copyright (C) 1995 Linus Torvalds |
| 10 | */ |
| 11 | |
| 12 | #include <linux/init.h> |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/mm.h> |
| 15 | #include <linux/pagemap.h> |
| 16 | #include <linux/bootmem.h> |
| 17 | #include <linux/swap.h> |
| 18 | #include <linux/highmem.h> |
| 19 | #include <linux/bitops.h> |
| 20 | #include <linux/nodemask.h> |
Dave Hansen | 22a9835 | 2006-03-27 01:16:04 -0800 | [diff] [blame] | 21 | #include <linux/pfn.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <asm/types.h> |
| 23 | #include <asm/processor.h> |
| 24 | #include <asm/page.h> |
| 25 | #include <asm/pgtable.h> |
| 26 | #include <asm/pgalloc.h> |
| 27 | #include <asm/mmu_context.h> |
| 28 | #include <asm/setup.h> |
| 29 | #include <asm/tlb.h> |
| 30 | |
| 31 | /* References to section boundaries */ |
| 32 | extern char _text, _etext, _edata; |
| 33 | extern char __init_begin, __init_end; |
| 34 | |
| 35 | pgd_t swapper_pg_dir[1024]; |
| 36 | |
| 37 | DEFINE_PER_CPU(struct mmu_gather, mmu_gathers); |
| 38 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | /* |
| 40 | * Cache of MMU context last used. |
| 41 | */ |
| 42 | #ifndef CONFIG_SMP |
| 43 | unsigned long mmu_context_cache_dat; |
| 44 | #else |
| 45 | unsigned long mmu_context_cache_dat[NR_CPUS]; |
| 46 | #endif |
| 47 | static unsigned long hole_pages; |
| 48 | |
| 49 | /* |
| 50 | * function prototype |
| 51 | */ |
| 52 | void __init paging_init(void); |
| 53 | void __init mem_init(void); |
| 54 | void free_initmem(void); |
| 55 | #ifdef CONFIG_BLK_DEV_INITRD |
| 56 | void free_initrd_mem(unsigned long, unsigned long); |
| 57 | #endif |
| 58 | |
| 59 | /* It'd be good if these lines were in the standard header file. */ |
Johannes Weiner | 3560e24 | 2008-07-23 21:28:09 -0700 | [diff] [blame] | 60 | #define START_PFN(nid) (NODE_DATA(nid)->bdata->node_min_pfn) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | #define MAX_LOW_PFN(nid) (NODE_DATA(nid)->bdata->node_low_pfn) |
| 62 | |
| 63 | #ifndef CONFIG_DISCONTIGMEM |
| 64 | unsigned long __init zone_sizes_init(void) |
| 65 | { |
Christoph Lameter | f06a968 | 2006-09-25 23:31:10 -0700 | [diff] [blame] | 66 | unsigned long zones_size[MAX_NR_ZONES] = {0, }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | unsigned long max_dma; |
| 68 | unsigned long low; |
| 69 | unsigned long start_pfn; |
| 70 | |
| 71 | #ifdef CONFIG_MMU |
| 72 | start_pfn = START_PFN(0); |
| 73 | max_dma = virt_to_phys((char *)MAX_DMA_ADDRESS) >> PAGE_SHIFT; |
| 74 | low = MAX_LOW_PFN(0); |
| 75 | |
| 76 | if (low < max_dma){ |
| 77 | zones_size[ZONE_DMA] = low - start_pfn; |
| 78 | zones_size[ZONE_NORMAL] = 0; |
| 79 | } else { |
| 80 | zones_size[ZONE_DMA] = low - start_pfn; |
| 81 | zones_size[ZONE_NORMAL] = low - max_dma; |
| 82 | } |
| 83 | #else |
| 84 | zones_size[ZONE_DMA] = 0 >> PAGE_SHIFT; |
| 85 | zones_size[ZONE_NORMAL] = __MEMORY_SIZE >> PAGE_SHIFT; |
| 86 | start_pfn = __MEMORY_START >> PAGE_SHIFT; |
| 87 | #endif /* CONFIG_MMU */ |
| 88 | |
Johannes Weiner | 9109fb7 | 2008-07-23 21:27:20 -0700 | [diff] [blame] | 89 | free_area_init_node(0, zones_size, start_pfn, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | |
| 91 | return 0; |
| 92 | } |
| 93 | #else /* CONFIG_DISCONTIGMEM */ |
| 94 | extern unsigned long zone_sizes_init(void); |
| 95 | #endif /* CONFIG_DISCONTIGMEM */ |
| 96 | |
| 97 | /*======================================================================* |
| 98 | * paging_init() : sets up the page tables |
| 99 | *======================================================================*/ |
| 100 | void __init paging_init(void) |
| 101 | { |
| 102 | #ifdef CONFIG_MMU |
| 103 | int i; |
| 104 | pgd_t *pg_dir; |
| 105 | |
| 106 | /* We don't need kernel mapping as hardware support that. */ |
| 107 | pg_dir = swapper_pg_dir; |
| 108 | |
| 109 | for (i = 0 ; i < USER_PTRS_PER_PGD * 2 ; i++) |
| 110 | pgd_val(pg_dir[i]) = 0; |
| 111 | #endif /* CONFIG_MMU */ |
| 112 | hole_pages = zone_sizes_init(); |
| 113 | } |
| 114 | |
| 115 | int __init reservedpages_count(void) |
| 116 | { |
| 117 | int reservedpages, nid, i; |
| 118 | |
| 119 | reservedpages = 0; |
Dave Hansen | 208d54e | 2005-10-29 18:16:52 -0700 | [diff] [blame] | 120 | for_each_online_node(nid) { |
| 121 | unsigned long flags; |
| 122 | pgdat_resize_lock(NODE_DATA(nid), &flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | for (i = 0 ; i < MAX_LOW_PFN(nid) - START_PFN(nid) ; i++) |
Dave Hansen | 408fde8 | 2005-06-23 00:07:37 -0700 | [diff] [blame] | 124 | if (PageReserved(nid_page_nr(nid, i))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | reservedpages++; |
Dave Hansen | 208d54e | 2005-10-29 18:16:52 -0700 | [diff] [blame] | 126 | pgdat_resize_unlock(NODE_DATA(nid), &flags); |
| 127 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | |
| 129 | return reservedpages; |
| 130 | } |
| 131 | |
| 132 | /*======================================================================* |
| 133 | * mem_init() : |
| 134 | * orig : arch/sh/mm/init.c |
| 135 | *======================================================================*/ |
| 136 | void __init mem_init(void) |
| 137 | { |
| 138 | int codesize, reservedpages, datasize, initsize; |
| 139 | int nid; |
| 140 | #ifndef CONFIG_MMU |
| 141 | extern unsigned long memory_end; |
| 142 | #endif |
| 143 | |
| 144 | num_physpages = 0; |
| 145 | for_each_online_node(nid) |
| 146 | num_physpages += MAX_LOW_PFN(nid) - START_PFN(nid) + 1; |
| 147 | |
| 148 | num_physpages -= hole_pages; |
| 149 | |
| 150 | #ifndef CONFIG_DISCONTIGMEM |
| 151 | max_mapnr = num_physpages; |
| 152 | #endif /* CONFIG_DISCONTIGMEM */ |
| 153 | |
| 154 | #ifdef CONFIG_MMU |
| 155 | high_memory = (void *)__va(PFN_PHYS(MAX_LOW_PFN(0))); |
| 156 | #else |
| 157 | high_memory = (void *)(memory_end & PAGE_MASK); |
| 158 | #endif /* CONFIG_MMU */ |
| 159 | |
| 160 | /* clear the zero-page */ |
| 161 | memset(empty_zero_page, 0, PAGE_SIZE); |
| 162 | |
| 163 | /* this will put all low memory onto the freelists */ |
| 164 | for_each_online_node(nid) |
| 165 | totalram_pages += free_all_bootmem_node(NODE_DATA(nid)); |
| 166 | |
| 167 | reservedpages = reservedpages_count() - hole_pages; |
| 168 | codesize = (unsigned long) &_etext - (unsigned long)&_text; |
| 169 | datasize = (unsigned long) &_edata - (unsigned long)&_etext; |
| 170 | initsize = (unsigned long) &__init_end - (unsigned long)&__init_begin; |
| 171 | |
| 172 | printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, " |
| 173 | "%dk reserved, %dk data, %dk init)\n", |
| 174 | (unsigned long) nr_free_pages() << (PAGE_SHIFT-10), |
| 175 | num_physpages << (PAGE_SHIFT-10), |
| 176 | codesize >> 10, |
| 177 | reservedpages << (PAGE_SHIFT-10), |
| 178 | datasize >> 10, |
| 179 | initsize >> 10); |
| 180 | } |
| 181 | |
| 182 | /*======================================================================* |
| 183 | * free_initmem() : |
| 184 | * orig : arch/sh/mm/init.c |
| 185 | *======================================================================*/ |
| 186 | void free_initmem(void) |
| 187 | { |
| 188 | unsigned long addr; |
| 189 | |
| 190 | addr = (unsigned long)(&__init_begin); |
| 191 | for (; addr < (unsigned long)(&__init_end); addr += PAGE_SIZE) { |
| 192 | ClearPageReserved(virt_to_page(addr)); |
Nick Piggin | 7835e98 | 2006-03-22 00:08:40 -0800 | [diff] [blame] | 193 | init_page_count(virt_to_page(addr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | free_page(addr); |
| 195 | totalram_pages++; |
| 196 | } |
| 197 | printk (KERN_INFO "Freeing unused kernel memory: %dk freed\n", \ |
| 198 | (int)(&__init_end - &__init_begin) >> 10); |
| 199 | } |
| 200 | |
| 201 | #ifdef CONFIG_BLK_DEV_INITRD |
| 202 | /*======================================================================* |
| 203 | * free_initrd_mem() : |
| 204 | * orig : arch/sh/mm/init.c |
| 205 | *======================================================================*/ |
| 206 | void free_initrd_mem(unsigned long start, unsigned long end) |
| 207 | { |
| 208 | unsigned long p; |
| 209 | for (p = start; p < end; p += PAGE_SIZE) { |
| 210 | ClearPageReserved(virt_to_page(p)); |
Nick Piggin | 7835e98 | 2006-03-22 00:08:40 -0800 | [diff] [blame] | 211 | init_page_count(virt_to_page(p)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | free_page(p); |
| 213 | totalram_pages++; |
| 214 | } |
| 215 | printk (KERN_INFO "Freeing initrd memory: %ldk freed\n", (end - start) >> 10); |
| 216 | } |
| 217 | #endif |