Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/m68k/mm/init.c |
| 3 | * |
| 4 | * Copyright (C) 1995 Hamish Macdonald |
| 5 | * |
| 6 | * Contains common initialization routines, specific init code moved |
| 7 | * to motorola.c and sun3mmu.c |
| 8 | */ |
| 9 | |
Roman Zippel | 12d810c | 2007-05-31 00:40:54 -0700 | [diff] [blame] | 10 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/signal.h> |
| 12 | #include <linux/sched.h> |
| 13 | #include <linux/mm.h> |
| 14 | #include <linux/swap.h> |
| 15 | #include <linux/kernel.h> |
| 16 | #include <linux/string.h> |
| 17 | #include <linux/types.h> |
| 18 | #include <linux/init.h> |
| 19 | #include <linux/bootmem.h> |
| 20 | |
| 21 | #include <asm/setup.h> |
| 22 | #include <asm/uaccess.h> |
| 23 | #include <asm/page.h> |
| 24 | #include <asm/pgalloc.h> |
| 25 | #include <asm/system.h> |
| 26 | #include <asm/machdep.h> |
| 27 | #include <asm/io.h> |
| 28 | #ifdef CONFIG_ATARI |
| 29 | #include <asm/atari_stram.h> |
| 30 | #endif |
| 31 | #include <asm/tlb.h> |
| 32 | |
| 33 | DEFINE_PER_CPU(struct mmu_gather, mmu_gathers); |
| 34 | |
Roman Zippel | 12d810c | 2007-05-31 00:40:54 -0700 | [diff] [blame] | 35 | static bootmem_data_t __initdata bootmem_data[MAX_NUMNODES]; |
| 36 | |
| 37 | pg_data_t pg_data_map[MAX_NUMNODES]; |
| 38 | EXPORT_SYMBOL(pg_data_map); |
| 39 | |
| 40 | int m68k_virt_to_node_shift; |
| 41 | |
| 42 | #ifndef CONFIG_SINGLE_MEMORY_CHUNK |
| 43 | pg_data_t *pg_data_table[65]; |
| 44 | EXPORT_SYMBOL(pg_data_table); |
| 45 | #endif |
| 46 | |
Al Viro | 66a3f82 | 2007-07-20 04:33:28 +0100 | [diff] [blame] | 47 | void __init m68k_setup_node(int node) |
Roman Zippel | 12d810c | 2007-05-31 00:40:54 -0700 | [diff] [blame] | 48 | { |
| 49 | #ifndef CONFIG_SINGLE_MEMORY_CHUNK |
| 50 | struct mem_info *info = m68k_memory + node; |
| 51 | int i, end; |
| 52 | |
| 53 | i = (unsigned long)phys_to_virt(info->addr) >> __virt_to_node_shift(); |
| 54 | end = (unsigned long)phys_to_virt(info->addr + info->size - 1) >> __virt_to_node_shift(); |
| 55 | for (; i <= end; i++) { |
| 56 | if (pg_data_table[i]) |
| 57 | printk("overlap at %u for chunk %u\n", i, node); |
| 58 | pg_data_table[i] = pg_data_map + node; |
| 59 | } |
| 60 | #endif |
| 61 | pg_data_map[node].bdata = bootmem_data + node; |
| 62 | node_set_online(node); |
| 63 | } |
| 64 | |
| 65 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | /* |
| 67 | * ZERO_PAGE is a special page that is used for zero-initialized |
| 68 | * data and COW. |
| 69 | */ |
| 70 | |
| 71 | void *empty_zero_page; |
| 72 | |
| 73 | void show_mem(void) |
| 74 | { |
Roman Zippel | 12d810c | 2007-05-31 00:40:54 -0700 | [diff] [blame] | 75 | pg_data_t *pgdat; |
| 76 | int free = 0, total = 0, reserved = 0, shared = 0; |
| 77 | int cached = 0; |
| 78 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
Roman Zippel | 12d810c | 2007-05-31 00:40:54 -0700 | [diff] [blame] | 80 | printk("\nMem-info:\n"); |
| 81 | show_free_areas(); |
| 82 | printk("Free swap: %6ldkB\n", nr_swap_pages<<(PAGE_SHIFT-10)); |
| 83 | for_each_online_pgdat(pgdat) { |
| 84 | for (i = 0; i < pgdat->node_spanned_pages; i++) { |
| 85 | struct page *page = pgdat->node_mem_map + i; |
| 86 | total++; |
| 87 | if (PageReserved(page)) |
| 88 | reserved++; |
| 89 | else if (PageSwapCache(page)) |
| 90 | cached++; |
| 91 | else if (!page_count(page)) |
| 92 | free++; |
| 93 | else |
| 94 | shared += page_count(page) - 1; |
| 95 | } |
| 96 | } |
| 97 | printk("%d pages of RAM\n",total); |
| 98 | printk("%d free pages\n",free); |
| 99 | printk("%d reserved pages\n",reserved); |
| 100 | printk("%d pages shared\n",shared); |
| 101 | printk("%d pages swap cached\n",cached); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | extern void init_pointer_table(unsigned long ptable); |
| 105 | |
| 106 | /* References to section boundaries */ |
| 107 | |
Roman Zippel | 12d810c | 2007-05-31 00:40:54 -0700 | [diff] [blame] | 108 | extern char _text[], _etext[]; |
| 109 | extern char __init_begin[], __init_end[]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | |
| 111 | extern pmd_t *zero_pgtable; |
| 112 | |
| 113 | void __init mem_init(void) |
| 114 | { |
Roman Zippel | 12d810c | 2007-05-31 00:40:54 -0700 | [diff] [blame] | 115 | pg_data_t *pgdat; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | int codepages = 0; |
| 117 | int datapages = 0; |
| 118 | int initpages = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | |
| 121 | #ifdef CONFIG_ATARI |
| 122 | if (MACH_IS_ATARI) |
| 123 | atari_stram_mem_init_hook(); |
| 124 | #endif |
| 125 | |
| 126 | /* this will put all memory onto the freelists */ |
Roman Zippel | 12d810c | 2007-05-31 00:40:54 -0700 | [diff] [blame] | 127 | totalram_pages = num_physpages = 0; |
| 128 | for_each_online_pgdat(pgdat) { |
| 129 | num_physpages += pgdat->node_present_pages; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | |
Roman Zippel | 12d810c | 2007-05-31 00:40:54 -0700 | [diff] [blame] | 131 | totalram_pages += free_all_bootmem_node(pgdat); |
| 132 | for (i = 0; i < pgdat->node_spanned_pages; i++) { |
| 133 | struct page *page = pgdat->node_mem_map + i; |
| 134 | char *addr = page_to_virt(page); |
| 135 | |
| 136 | if (!PageReserved(page)) |
| 137 | continue; |
| 138 | if (addr >= _text && |
| 139 | addr < _etext) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | codepages++; |
Roman Zippel | 12d810c | 2007-05-31 00:40:54 -0700 | [diff] [blame] | 141 | else if (addr >= __init_begin && |
| 142 | addr < __init_end) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | initpages++; |
| 144 | else |
| 145 | datapages++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | } |
| 147 | } |
| 148 | |
| 149 | #ifndef CONFIG_SUN3 |
| 150 | /* insert pointer tables allocated so far into the tablelist */ |
| 151 | init_pointer_table((unsigned long)kernel_pg_dir); |
| 152 | for (i = 0; i < PTRS_PER_PGD; i++) { |
| 153 | if (pgd_present(kernel_pg_dir[i])) |
| 154 | init_pointer_table(__pgd_page(kernel_pg_dir[i])); |
| 155 | } |
| 156 | |
| 157 | /* insert also pointer table that we used to unmap the zero page */ |
| 158 | if (zero_pgtable) |
| 159 | init_pointer_table((unsigned long)zero_pgtable); |
| 160 | #endif |
| 161 | |
| 162 | printk("Memory: %luk/%luk available (%dk kernel code, %dk data, %dk init)\n", |
| 163 | (unsigned long)nr_free_pages() << (PAGE_SHIFT-10), |
Roman Zippel | 12d810c | 2007-05-31 00:40:54 -0700 | [diff] [blame] | 164 | totalram_pages << (PAGE_SHIFT-10), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | codepages << (PAGE_SHIFT-10), |
| 166 | datapages << (PAGE_SHIFT-10), |
| 167 | initpages << (PAGE_SHIFT-10)); |
| 168 | } |
| 169 | |
| 170 | #ifdef CONFIG_BLK_DEV_INITRD |
| 171 | void free_initrd_mem(unsigned long start, unsigned long end) |
| 172 | { |
| 173 | int pages = 0; |
| 174 | for (; start < end; start += PAGE_SIZE) { |
| 175 | ClearPageReserved(virt_to_page(start)); |
Nick Piggin | 7835e98 | 2006-03-22 00:08:40 -0800 | [diff] [blame] | 176 | init_page_count(virt_to_page(start)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | free_page(start); |
| 178 | totalram_pages++; |
| 179 | pages++; |
| 180 | } |
| 181 | printk ("Freeing initrd memory: %dk freed\n", pages); |
| 182 | } |
| 183 | #endif |