Greg Ungerer | dd1cb3a | 2012-10-24 22:36:27 +1000 | [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 | |
| 10 | #include <linux/module.h> |
| 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 | #include <linux/gfp.h> |
| 21 | |
| 22 | #include <asm/setup.h> |
| 23 | #include <asm/uaccess.h> |
| 24 | #include <asm/page.h> |
| 25 | #include <asm/pgalloc.h> |
| 26 | #include <asm/traps.h> |
| 27 | #include <asm/machdep.h> |
| 28 | #include <asm/io.h> |
| 29 | #ifdef CONFIG_ATARI |
| 30 | #include <asm/atari_stram.h> |
| 31 | #endif |
| 32 | #include <asm/sections.h> |
| 33 | #include <asm/tlb.h> |
| 34 | |
| 35 | /* |
| 36 | * ZERO_PAGE is a special page that is used for zero-initialized |
| 37 | * data and COW. |
| 38 | */ |
| 39 | void *empty_zero_page; |
| 40 | EXPORT_SYMBOL(empty_zero_page); |
| 41 | |
Greg Ungerer | d6fccc7 | 2013-01-07 16:13:04 +1000 | [diff] [blame] | 42 | #if !defined(CONFIG_SUN3) && !defined(CONFIG_COLDFIRE) |
| 43 | extern void init_pointer_table(unsigned long ptable); |
| 44 | extern pmd_t *zero_pgtable; |
| 45 | #endif |
| 46 | |
Greg Ungerer | 66d857b | 2011-03-22 13:39:27 +1000 | [diff] [blame] | 47 | #ifdef CONFIG_MMU |
Greg Ungerer | dd1cb3a | 2012-10-24 22:36:27 +1000 | [diff] [blame] | 48 | |
| 49 | pg_data_t pg_data_map[MAX_NUMNODES]; |
| 50 | EXPORT_SYMBOL(pg_data_map); |
| 51 | |
| 52 | int m68k_virt_to_node_shift; |
| 53 | |
| 54 | #ifndef CONFIG_SINGLE_MEMORY_CHUNK |
| 55 | pg_data_t *pg_data_table[65]; |
| 56 | EXPORT_SYMBOL(pg_data_table); |
| 57 | #endif |
| 58 | |
| 59 | void __init m68k_setup_node(int node) |
| 60 | { |
| 61 | #ifndef CONFIG_SINGLE_MEMORY_CHUNK |
| 62 | struct mem_info *info = m68k_memory + node; |
| 63 | int i, end; |
| 64 | |
| 65 | i = (unsigned long)phys_to_virt(info->addr) >> __virt_to_node_shift(); |
| 66 | end = (unsigned long)phys_to_virt(info->addr + info->size - 1) >> __virt_to_node_shift(); |
| 67 | for (; i <= end; i++) { |
| 68 | if (pg_data_table[i]) |
| 69 | printk("overlap at %u for chunk %u\n", i, node); |
| 70 | pg_data_table[i] = pg_data_map + node; |
| 71 | } |
| 72 | #endif |
| 73 | pg_data_map[node].bdata = bootmem_node_data + node; |
| 74 | node_set_online(node); |
| 75 | } |
| 76 | |
Greg Ungerer | dd1cb3a | 2012-10-24 22:36:27 +1000 | [diff] [blame] | 77 | #else /* CONFIG_MMU */ |
| 78 | |
| 79 | /* |
| 80 | * paging_init() continues the virtual memory environment setup which |
| 81 | * was begun by the code in arch/head.S. |
| 82 | * The parameters are pointers to where to stick the starting and ending |
| 83 | * addresses of available kernel virtual memory. |
| 84 | */ |
| 85 | void __init paging_init(void) |
| 86 | { |
| 87 | /* |
| 88 | * Make sure start_mem is page aligned, otherwise bootmem and |
| 89 | * page_alloc get different views of the world. |
| 90 | */ |
| 91 | unsigned long end_mem = memory_end & PAGE_MASK; |
| 92 | unsigned long zones_size[MAX_NR_ZONES] = { 0, }; |
| 93 | |
| 94 | high_memory = (void *) end_mem; |
| 95 | |
| 96 | empty_zero_page = alloc_bootmem_pages(PAGE_SIZE); |
| 97 | memset(empty_zero_page, 0, PAGE_SIZE); |
| 98 | |
| 99 | /* |
| 100 | * Set up SFC/DFC registers (user data space). |
| 101 | */ |
| 102 | set_fs (USER_DS); |
| 103 | |
| 104 | zones_size[ZONE_DMA] = (end_mem - PAGE_OFFSET) >> PAGE_SHIFT; |
| 105 | free_area_init(zones_size); |
| 106 | } |
| 107 | |
Greg Ungerer | f50bf88 | 2012-10-23 13:40:36 +1000 | [diff] [blame] | 108 | #endif /* CONFIG_MMU */ |
| 109 | |
Greg Ungerer | dd1cb3a | 2012-10-24 22:36:27 +1000 | [diff] [blame] | 110 | void free_initmem(void) |
| 111 | { |
Greg Ungerer | f50bf88 | 2012-10-23 13:40:36 +1000 | [diff] [blame] | 112 | #ifndef CONFIG_MMU_SUN3 |
Greg Ungerer | dd1cb3a | 2012-10-24 22:36:27 +1000 | [diff] [blame] | 113 | unsigned long addr; |
| 114 | |
Greg Ungerer | f50bf88 | 2012-10-23 13:40:36 +1000 | [diff] [blame] | 115 | addr = (unsigned long) __init_begin; |
| 116 | for (; addr < ((unsigned long) __init_end); addr += PAGE_SIZE) { |
Greg Ungerer | dd1cb3a | 2012-10-24 22:36:27 +1000 | [diff] [blame] | 117 | ClearPageReserved(virt_to_page(addr)); |
| 118 | init_page_count(virt_to_page(addr)); |
| 119 | free_page(addr); |
| 120 | totalram_pages++; |
| 121 | } |
| 122 | pr_notice("Freeing unused kernel memory: %luk freed (0x%x - 0x%x)\n", |
Greg Ungerer | f50bf88 | 2012-10-23 13:40:36 +1000 | [diff] [blame] | 123 | (addr - (unsigned long) __init_begin) >> 10, |
| 124 | (unsigned int) __init_begin, (unsigned int) __init_end); |
| 125 | #endif /* CONFIG_MMU_SUN3 */ |
Greg Ungerer | dd1cb3a | 2012-10-24 22:36:27 +1000 | [diff] [blame] | 126 | } |
| 127 | |
Greg Ungerer | dd1cb3a | 2012-10-24 22:36:27 +1000 | [diff] [blame] | 128 | #if defined(CONFIG_MMU) && !defined(CONFIG_COLDFIRE) |
| 129 | #define VECTORS &vectors[0] |
Greg Ungerer | 66d857b | 2011-03-22 13:39:27 +1000 | [diff] [blame] | 130 | #else |
Greg Ungerer | dd1cb3a | 2012-10-24 22:36:27 +1000 | [diff] [blame] | 131 | #define VECTORS _ramvec |
| 132 | #endif |
| 133 | |
| 134 | void __init print_memmap(void) |
| 135 | { |
| 136 | #define UL(x) ((unsigned long) (x)) |
| 137 | #define MLK(b, t) UL(b), UL(t), (UL(t) - UL(b)) >> 10 |
| 138 | #define MLM(b, t) UL(b), UL(t), (UL(t) - UL(b)) >> 20 |
| 139 | #define MLK_ROUNDUP(b, t) b, t, DIV_ROUND_UP(((t) - (b)), 1024) |
| 140 | |
| 141 | pr_notice("Virtual kernel memory layout:\n" |
| 142 | " vector : 0x%08lx - 0x%08lx (%4ld KiB)\n" |
| 143 | " kmap : 0x%08lx - 0x%08lx (%4ld MiB)\n" |
| 144 | " vmalloc : 0x%08lx - 0x%08lx (%4ld MiB)\n" |
| 145 | " lowmem : 0x%08lx - 0x%08lx (%4ld MiB)\n" |
| 146 | " .init : 0x%p" " - 0x%p" " (%4d KiB)\n" |
| 147 | " .text : 0x%p" " - 0x%p" " (%4d KiB)\n" |
| 148 | " .data : 0x%p" " - 0x%p" " (%4d KiB)\n" |
| 149 | " .bss : 0x%p" " - 0x%p" " (%4d KiB)\n", |
| 150 | MLK(VECTORS, VECTORS + 256), |
| 151 | MLM(KMAP_START, KMAP_END), |
| 152 | MLM(VMALLOC_START, VMALLOC_END), |
| 153 | MLM(PAGE_OFFSET, (unsigned long)high_memory), |
| 154 | MLK_ROUNDUP(__init_begin, __init_end), |
| 155 | MLK_ROUNDUP(_stext, _etext), |
| 156 | MLK_ROUNDUP(_sdata, _edata), |
| 157 | MLK_ROUNDUP(__bss_start, __bss_stop)); |
| 158 | } |
| 159 | |
| 160 | void __init mem_init(void) |
| 161 | { |
| 162 | pg_data_t *pgdat; |
| 163 | int codepages = 0; |
| 164 | int datapages = 0; |
| 165 | int initpages = 0; |
| 166 | int i; |
| 167 | |
| 168 | /* this will put all memory onto the freelists */ |
| 169 | totalram_pages = num_physpages = 0; |
| 170 | for_each_online_pgdat(pgdat) { |
| 171 | num_physpages += pgdat->node_present_pages; |
| 172 | |
| 173 | totalram_pages += free_all_bootmem_node(pgdat); |
| 174 | for (i = 0; i < pgdat->node_spanned_pages; i++) { |
| 175 | struct page *page = pgdat->node_mem_map + i; |
| 176 | char *addr = page_to_virt(page); |
| 177 | |
| 178 | if (!PageReserved(page)) |
| 179 | continue; |
| 180 | if (addr >= _text && |
| 181 | addr < _etext) |
| 182 | codepages++; |
| 183 | else if (addr >= __init_begin && |
| 184 | addr < __init_end) |
| 185 | initpages++; |
| 186 | else |
| 187 | datapages++; |
| 188 | } |
| 189 | } |
| 190 | |
Thadeu Lima de Souza Cascardo | be3f695 | 2013-02-16 23:33:34 -0200 | [diff] [blame^] | 191 | #if defined(CONFIG_MMU) && !defined(CONFIG_SUN3) && !defined(CONFIG_COLDFIRE) |
Greg Ungerer | dd1cb3a | 2012-10-24 22:36:27 +1000 | [diff] [blame] | 192 | /* insert pointer tables allocated so far into the tablelist */ |
| 193 | init_pointer_table((unsigned long)kernel_pg_dir); |
| 194 | for (i = 0; i < PTRS_PER_PGD; i++) { |
| 195 | if (pgd_present(kernel_pg_dir[i])) |
| 196 | init_pointer_table(__pgd_page(kernel_pg_dir[i])); |
| 197 | } |
| 198 | |
| 199 | /* insert also pointer table that we used to unmap the zero page */ |
| 200 | if (zero_pgtable) |
| 201 | init_pointer_table((unsigned long)zero_pgtable); |
| 202 | #endif |
| 203 | |
| 204 | pr_info("Memory: %luk/%luk available (%dk kernel code, %dk data, %dk init)\n", |
| 205 | nr_free_pages() << (PAGE_SHIFT-10), |
| 206 | totalram_pages << (PAGE_SHIFT-10), |
| 207 | codepages << (PAGE_SHIFT-10), |
| 208 | datapages << (PAGE_SHIFT-10), |
| 209 | initpages << (PAGE_SHIFT-10)); |
| 210 | print_memmap(); |
| 211 | } |
| 212 | |
| 213 | #ifdef CONFIG_BLK_DEV_INITRD |
| 214 | void free_initrd_mem(unsigned long start, unsigned long end) |
| 215 | { |
| 216 | int pages = 0; |
| 217 | for (; start < end; start += PAGE_SIZE) { |
| 218 | ClearPageReserved(virt_to_page(start)); |
| 219 | init_page_count(virt_to_page(start)); |
| 220 | free_page(start); |
| 221 | totalram_pages++; |
| 222 | pages++; |
| 223 | } |
| 224 | pr_notice("Freeing initrd memory: %dk freed\n", |
| 225 | pages << (PAGE_SHIFT - 10)); |
| 226 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | #endif |