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> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 20 | #include <linux/gfp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
| 22 | #include <asm/setup.h> |
| 23 | #include <asm/uaccess.h> |
| 24 | #include <asm/page.h> |
| 25 | #include <asm/pgalloc.h> |
| 26 | #include <asm/system.h> |
| 27 | #include <asm/machdep.h> |
| 28 | #include <asm/io.h> |
| 29 | #ifdef CONFIG_ATARI |
| 30 | #include <asm/atari_stram.h> |
| 31 | #endif |
Geert Uytterhoeven | c85627f | 2008-12-21 12:03:37 +0100 | [diff] [blame] | 32 | #include <asm/sections.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <asm/tlb.h> |
| 34 | |
| 35 | DEFINE_PER_CPU(struct mmu_gather, mmu_gathers); |
| 36 | |
Roman Zippel | 12d810c | 2007-05-31 00:40:54 -0700 | [diff] [blame] | 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 |
Johannes Weiner | b61bfa3 | 2008-07-23 21:26:55 -0700 | [diff] [blame] | 61 | pg_data_map[node].bdata = bootmem_node_data + node; |
Roman Zippel | 12d810c | 2007-05-31 00:40:54 -0700 | [diff] [blame] | 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; |
Aneesh Kumar K.V | 5fcf430 | 2008-04-29 08:11:12 -0400 | [diff] [blame] | 72 | EXPORT_SYMBOL(empty_zero_page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | extern void init_pointer_table(unsigned long ptable); |
| 75 | |
| 76 | /* References to section boundaries */ |
| 77 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | extern pmd_t *zero_pgtable; |
| 79 | |
| 80 | void __init mem_init(void) |
| 81 | { |
Roman Zippel | 12d810c | 2007-05-31 00:40:54 -0700 | [diff] [blame] | 82 | pg_data_t *pgdat; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | int codepages = 0; |
| 84 | int datapages = 0; |
| 85 | int initpages = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | |
| 88 | #ifdef CONFIG_ATARI |
| 89 | if (MACH_IS_ATARI) |
| 90 | atari_stram_mem_init_hook(); |
| 91 | #endif |
| 92 | |
| 93 | /* this will put all memory onto the freelists */ |
Roman Zippel | 12d810c | 2007-05-31 00:40:54 -0700 | [diff] [blame] | 94 | totalram_pages = num_physpages = 0; |
| 95 | for_each_online_pgdat(pgdat) { |
| 96 | num_physpages += pgdat->node_present_pages; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | |
Roman Zippel | 12d810c | 2007-05-31 00:40:54 -0700 | [diff] [blame] | 98 | totalram_pages += free_all_bootmem_node(pgdat); |
| 99 | for (i = 0; i < pgdat->node_spanned_pages; i++) { |
| 100 | struct page *page = pgdat->node_mem_map + i; |
| 101 | char *addr = page_to_virt(page); |
| 102 | |
| 103 | if (!PageReserved(page)) |
| 104 | continue; |
| 105 | if (addr >= _text && |
| 106 | addr < _etext) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | codepages++; |
Roman Zippel | 12d810c | 2007-05-31 00:40:54 -0700 | [diff] [blame] | 108 | else if (addr >= __init_begin && |
| 109 | addr < __init_end) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | initpages++; |
| 111 | else |
| 112 | datapages++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | } |
| 114 | } |
| 115 | |
| 116 | #ifndef CONFIG_SUN3 |
| 117 | /* insert pointer tables allocated so far into the tablelist */ |
| 118 | init_pointer_table((unsigned long)kernel_pg_dir); |
| 119 | for (i = 0; i < PTRS_PER_PGD; i++) { |
| 120 | if (pgd_present(kernel_pg_dir[i])) |
| 121 | init_pointer_table(__pgd_page(kernel_pg_dir[i])); |
| 122 | } |
| 123 | |
| 124 | /* insert also pointer table that we used to unmap the zero page */ |
| 125 | if (zero_pgtable) |
| 126 | init_pointer_table((unsigned long)zero_pgtable); |
| 127 | #endif |
| 128 | |
| 129 | printk("Memory: %luk/%luk available (%dk kernel code, %dk data, %dk init)\n", |
Geert Uytterhoeven | cc013a8 | 2009-09-21 17:02:36 -0700 | [diff] [blame] | 130 | nr_free_pages() << (PAGE_SHIFT-10), |
Roman Zippel | 12d810c | 2007-05-31 00:40:54 -0700 | [diff] [blame] | 131 | totalram_pages << (PAGE_SHIFT-10), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | codepages << (PAGE_SHIFT-10), |
| 133 | datapages << (PAGE_SHIFT-10), |
| 134 | initpages << (PAGE_SHIFT-10)); |
| 135 | } |
| 136 | |
| 137 | #ifdef CONFIG_BLK_DEV_INITRD |
| 138 | void free_initrd_mem(unsigned long start, unsigned long end) |
| 139 | { |
| 140 | int pages = 0; |
| 141 | for (; start < end; start += PAGE_SIZE) { |
| 142 | ClearPageReserved(virt_to_page(start)); |
Nick Piggin | 7835e98 | 2006-03-22 00:08:40 -0800 | [diff] [blame] | 143 | init_page_count(virt_to_page(start)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | free_page(start); |
| 145 | totalram_pages++; |
| 146 | pages++; |
| 147 | } |
| 148 | printk ("Freeing initrd memory: %dk freed\n", pages); |
| 149 | } |
| 150 | #endif |