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> |
| 21 | #include <asm/types.h> |
| 22 | #include <asm/processor.h> |
| 23 | #include <asm/page.h> |
| 24 | #include <asm/pgtable.h> |
| 25 | #include <asm/pgalloc.h> |
| 26 | #include <asm/mmu_context.h> |
| 27 | #include <asm/setup.h> |
| 28 | #include <asm/tlb.h> |
| 29 | |
| 30 | /* References to section boundaries */ |
| 31 | extern char _text, _etext, _edata; |
| 32 | extern char __init_begin, __init_end; |
| 33 | |
| 34 | pgd_t swapper_pg_dir[1024]; |
| 35 | |
| 36 | DEFINE_PER_CPU(struct mmu_gather, mmu_gathers); |
| 37 | |
| 38 | void show_mem(void) |
| 39 | { |
| 40 | int total = 0, reserved = 0; |
| 41 | int shared = 0, cached = 0; |
| 42 | int highmem = 0; |
| 43 | struct page *page; |
| 44 | pg_data_t *pgdat; |
| 45 | unsigned long i; |
| 46 | |
| 47 | printk("Mem-info:\n"); |
| 48 | show_free_areas(); |
| 49 | printk("Free swap: %6ldkB\n",nr_swap_pages<<(PAGE_SHIFT-10)); |
| 50 | for_each_pgdat(pgdat) { |
Dave Hansen | 208d54e | 2005-10-29 18:16:52 -0700 | [diff] [blame] | 51 | unsigned long flags; |
| 52 | pgdat_resize_lock(pgdat, &flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | for (i = 0; i < pgdat->node_spanned_pages; ++i) { |
Dave Hansen | 408fde8 | 2005-06-23 00:07:37 -0700 | [diff] [blame] | 54 | page = pgdat_page_nr(pgdat, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | total++; |
| 56 | if (PageHighMem(page)) |
| 57 | highmem++; |
| 58 | if (PageReserved(page)) |
| 59 | reserved++; |
| 60 | else if (PageSwapCache(page)) |
| 61 | cached++; |
| 62 | else if (page_count(page)) |
| 63 | shared += page_count(page) - 1; |
| 64 | } |
Dave Hansen | 208d54e | 2005-10-29 18:16:52 -0700 | [diff] [blame] | 65 | pgdat_resize_unlock(pgdat, &flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | } |
| 67 | printk("%d pages of RAM\n", total); |
| 68 | printk("%d pages of HIGHMEM\n",highmem); |
| 69 | printk("%d reserved pages\n",reserved); |
| 70 | printk("%d pages shared\n",shared); |
| 71 | printk("%d pages swap cached\n",cached); |
| 72 | } |
| 73 | |
| 74 | /* |
| 75 | * Cache of MMU context last used. |
| 76 | */ |
| 77 | #ifndef CONFIG_SMP |
| 78 | unsigned long mmu_context_cache_dat; |
| 79 | #else |
| 80 | unsigned long mmu_context_cache_dat[NR_CPUS]; |
| 81 | #endif |
| 82 | static unsigned long hole_pages; |
| 83 | |
| 84 | /* |
| 85 | * function prototype |
| 86 | */ |
| 87 | void __init paging_init(void); |
| 88 | void __init mem_init(void); |
| 89 | void free_initmem(void); |
| 90 | #ifdef CONFIG_BLK_DEV_INITRD |
| 91 | void free_initrd_mem(unsigned long, unsigned long); |
| 92 | #endif |
| 93 | |
| 94 | /* It'd be good if these lines were in the standard header file. */ |
| 95 | #define START_PFN(nid) \ |
| 96 | (NODE_DATA(nid)->bdata->node_boot_start >> PAGE_SHIFT) |
| 97 | #define MAX_LOW_PFN(nid) (NODE_DATA(nid)->bdata->node_low_pfn) |
| 98 | |
| 99 | #ifndef CONFIG_DISCONTIGMEM |
| 100 | unsigned long __init zone_sizes_init(void) |
| 101 | { |
| 102 | unsigned long zones_size[MAX_NR_ZONES] = {0, 0, 0}; |
| 103 | unsigned long max_dma; |
| 104 | unsigned long low; |
| 105 | unsigned long start_pfn; |
| 106 | |
| 107 | #ifdef CONFIG_MMU |
| 108 | start_pfn = START_PFN(0); |
| 109 | max_dma = virt_to_phys((char *)MAX_DMA_ADDRESS) >> PAGE_SHIFT; |
| 110 | low = MAX_LOW_PFN(0); |
| 111 | |
| 112 | if (low < max_dma){ |
| 113 | zones_size[ZONE_DMA] = low - start_pfn; |
| 114 | zones_size[ZONE_NORMAL] = 0; |
| 115 | } else { |
| 116 | zones_size[ZONE_DMA] = low - start_pfn; |
| 117 | zones_size[ZONE_NORMAL] = low - max_dma; |
| 118 | } |
| 119 | #else |
| 120 | zones_size[ZONE_DMA] = 0 >> PAGE_SHIFT; |
| 121 | zones_size[ZONE_NORMAL] = __MEMORY_SIZE >> PAGE_SHIFT; |
| 122 | start_pfn = __MEMORY_START >> PAGE_SHIFT; |
| 123 | #endif /* CONFIG_MMU */ |
| 124 | |
| 125 | free_area_init_node(0, NODE_DATA(0), zones_size, start_pfn, 0); |
| 126 | |
| 127 | return 0; |
| 128 | } |
| 129 | #else /* CONFIG_DISCONTIGMEM */ |
| 130 | extern unsigned long zone_sizes_init(void); |
| 131 | #endif /* CONFIG_DISCONTIGMEM */ |
| 132 | |
| 133 | /*======================================================================* |
| 134 | * paging_init() : sets up the page tables |
| 135 | *======================================================================*/ |
| 136 | void __init paging_init(void) |
| 137 | { |
| 138 | #ifdef CONFIG_MMU |
| 139 | int i; |
| 140 | pgd_t *pg_dir; |
| 141 | |
| 142 | /* We don't need kernel mapping as hardware support that. */ |
| 143 | pg_dir = swapper_pg_dir; |
| 144 | |
| 145 | for (i = 0 ; i < USER_PTRS_PER_PGD * 2 ; i++) |
| 146 | pgd_val(pg_dir[i]) = 0; |
| 147 | #endif /* CONFIG_MMU */ |
| 148 | hole_pages = zone_sizes_init(); |
| 149 | } |
| 150 | |
| 151 | int __init reservedpages_count(void) |
| 152 | { |
| 153 | int reservedpages, nid, i; |
| 154 | |
| 155 | reservedpages = 0; |
Dave Hansen | 208d54e | 2005-10-29 18:16:52 -0700 | [diff] [blame] | 156 | for_each_online_node(nid) { |
| 157 | unsigned long flags; |
| 158 | pgdat_resize_lock(NODE_DATA(nid), &flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | for (i = 0 ; i < MAX_LOW_PFN(nid) - START_PFN(nid) ; i++) |
Dave Hansen | 408fde8 | 2005-06-23 00:07:37 -0700 | [diff] [blame] | 160 | if (PageReserved(nid_page_nr(nid, i))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | reservedpages++; |
Dave Hansen | 208d54e | 2005-10-29 18:16:52 -0700 | [diff] [blame] | 162 | pgdat_resize_unlock(NODE_DATA(nid), &flags); |
| 163 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | |
| 165 | return reservedpages; |
| 166 | } |
| 167 | |
| 168 | /*======================================================================* |
| 169 | * mem_init() : |
| 170 | * orig : arch/sh/mm/init.c |
| 171 | *======================================================================*/ |
| 172 | void __init mem_init(void) |
| 173 | { |
| 174 | int codesize, reservedpages, datasize, initsize; |
| 175 | int nid; |
| 176 | #ifndef CONFIG_MMU |
| 177 | extern unsigned long memory_end; |
| 178 | #endif |
| 179 | |
| 180 | num_physpages = 0; |
| 181 | for_each_online_node(nid) |
| 182 | num_physpages += MAX_LOW_PFN(nid) - START_PFN(nid) + 1; |
| 183 | |
| 184 | num_physpages -= hole_pages; |
| 185 | |
| 186 | #ifndef CONFIG_DISCONTIGMEM |
| 187 | max_mapnr = num_physpages; |
| 188 | #endif /* CONFIG_DISCONTIGMEM */ |
| 189 | |
| 190 | #ifdef CONFIG_MMU |
| 191 | high_memory = (void *)__va(PFN_PHYS(MAX_LOW_PFN(0))); |
| 192 | #else |
| 193 | high_memory = (void *)(memory_end & PAGE_MASK); |
| 194 | #endif /* CONFIG_MMU */ |
| 195 | |
| 196 | /* clear the zero-page */ |
| 197 | memset(empty_zero_page, 0, PAGE_SIZE); |
| 198 | |
| 199 | /* this will put all low memory onto the freelists */ |
| 200 | for_each_online_node(nid) |
| 201 | totalram_pages += free_all_bootmem_node(NODE_DATA(nid)); |
| 202 | |
| 203 | reservedpages = reservedpages_count() - hole_pages; |
| 204 | codesize = (unsigned long) &_etext - (unsigned long)&_text; |
| 205 | datasize = (unsigned long) &_edata - (unsigned long)&_etext; |
| 206 | initsize = (unsigned long) &__init_end - (unsigned long)&__init_begin; |
| 207 | |
| 208 | printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, " |
| 209 | "%dk reserved, %dk data, %dk init)\n", |
| 210 | (unsigned long) nr_free_pages() << (PAGE_SHIFT-10), |
| 211 | num_physpages << (PAGE_SHIFT-10), |
| 212 | codesize >> 10, |
| 213 | reservedpages << (PAGE_SHIFT-10), |
| 214 | datasize >> 10, |
| 215 | initsize >> 10); |
| 216 | } |
| 217 | |
| 218 | /*======================================================================* |
| 219 | * free_initmem() : |
| 220 | * orig : arch/sh/mm/init.c |
| 221 | *======================================================================*/ |
| 222 | void free_initmem(void) |
| 223 | { |
| 224 | unsigned long addr; |
| 225 | |
| 226 | addr = (unsigned long)(&__init_begin); |
| 227 | for (; addr < (unsigned long)(&__init_end); addr += PAGE_SIZE) { |
| 228 | ClearPageReserved(virt_to_page(addr)); |
Nick Piggin | 7835e98 | 2006-03-22 00:08:40 -0800 | [diff] [blame^] | 229 | init_page_count(virt_to_page(addr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | free_page(addr); |
| 231 | totalram_pages++; |
| 232 | } |
| 233 | printk (KERN_INFO "Freeing unused kernel memory: %dk freed\n", \ |
| 234 | (int)(&__init_end - &__init_begin) >> 10); |
| 235 | } |
| 236 | |
| 237 | #ifdef CONFIG_BLK_DEV_INITRD |
| 238 | /*======================================================================* |
| 239 | * free_initrd_mem() : |
| 240 | * orig : arch/sh/mm/init.c |
| 241 | *======================================================================*/ |
| 242 | void free_initrd_mem(unsigned long start, unsigned long end) |
| 243 | { |
| 244 | unsigned long p; |
| 245 | for (p = start; p < end; p += PAGE_SIZE) { |
| 246 | ClearPageReserved(virt_to_page(p)); |
Nick Piggin | 7835e98 | 2006-03-22 00:08:40 -0800 | [diff] [blame^] | 247 | init_page_count(virt_to_page(p)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | free_page(p); |
| 249 | totalram_pages++; |
| 250 | } |
| 251 | printk (KERN_INFO "Freeing initrd memory: %ldk freed\n", (end - start) >> 10); |
| 252 | } |
| 253 | #endif |
| 254 | |