Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Greg Ungerer | dd1cb3a | 2012-10-24 22:36:27 +1000 | [diff] [blame] | 2 | /* |
| 3 | * linux/arch/m68k/mm/init.c |
| 4 | * |
| 5 | * Copyright (C) 1995 Hamish Macdonald |
| 6 | * |
| 7 | * Contains common initialization routines, specific init code moved |
| 8 | * to motorola.c and sun3mmu.c |
| 9 | */ |
| 10 | |
| 11 | #include <linux/module.h> |
| 12 | #include <linux/signal.h> |
| 13 | #include <linux/sched.h> |
| 14 | #include <linux/mm.h> |
| 15 | #include <linux/swap.h> |
| 16 | #include <linux/kernel.h> |
| 17 | #include <linux/string.h> |
| 18 | #include <linux/types.h> |
| 19 | #include <linux/init.h> |
| 20 | #include <linux/bootmem.h> |
| 21 | #include <linux/gfp.h> |
| 22 | |
| 23 | #include <asm/setup.h> |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 24 | #include <linux/uaccess.h> |
Greg Ungerer | dd1cb3a | 2012-10-24 22:36:27 +1000 | [diff] [blame] | 25 | #include <asm/page.h> |
| 26 | #include <asm/pgalloc.h> |
| 27 | #include <asm/traps.h> |
| 28 | #include <asm/machdep.h> |
| 29 | #include <asm/io.h> |
| 30 | #ifdef CONFIG_ATARI |
| 31 | #include <asm/atari_stram.h> |
| 32 | #endif |
| 33 | #include <asm/sections.h> |
| 34 | #include <asm/tlb.h> |
| 35 | |
| 36 | /* |
| 37 | * ZERO_PAGE is a special page that is used for zero-initialized |
| 38 | * data and COW. |
| 39 | */ |
| 40 | void *empty_zero_page; |
| 41 | EXPORT_SYMBOL(empty_zero_page); |
| 42 | |
Greg Ungerer | d6fccc7 | 2013-01-07 16:13:04 +1000 | [diff] [blame] | 43 | #if !defined(CONFIG_SUN3) && !defined(CONFIG_COLDFIRE) |
| 44 | extern void init_pointer_table(unsigned long ptable); |
| 45 | extern pmd_t *zero_pgtable; |
| 46 | #endif |
| 47 | |
Greg Ungerer | 66d857b | 2011-03-22 13:39:27 +1000 | [diff] [blame] | 48 | #ifdef CONFIG_MMU |
Greg Ungerer | dd1cb3a | 2012-10-24 22:36:27 +1000 | [diff] [blame] | 49 | |
| 50 | pg_data_t pg_data_map[MAX_NUMNODES]; |
| 51 | EXPORT_SYMBOL(pg_data_map); |
| 52 | |
| 53 | int m68k_virt_to_node_shift; |
| 54 | |
| 55 | #ifndef CONFIG_SINGLE_MEMORY_CHUNK |
| 56 | pg_data_t *pg_data_table[65]; |
| 57 | EXPORT_SYMBOL(pg_data_table); |
| 58 | #endif |
| 59 | |
| 60 | void __init m68k_setup_node(int node) |
| 61 | { |
| 62 | #ifndef CONFIG_SINGLE_MEMORY_CHUNK |
Geert Uytterhoeven | 7993008 | 2013-10-02 21:50:56 +0200 | [diff] [blame] | 63 | struct m68k_mem_info *info = m68k_memory + node; |
Greg Ungerer | dd1cb3a | 2012-10-24 22:36:27 +1000 | [diff] [blame] | 64 | int i, end; |
| 65 | |
| 66 | i = (unsigned long)phys_to_virt(info->addr) >> __virt_to_node_shift(); |
| 67 | end = (unsigned long)phys_to_virt(info->addr + info->size - 1) >> __virt_to_node_shift(); |
| 68 | for (; i <= end; i++) { |
| 69 | if (pg_data_table[i]) |
Geert Uytterhoeven | e699113 | 2016-12-06 19:47:39 +0100 | [diff] [blame] | 70 | pr_warn("overlap at %u for chunk %u\n", i, node); |
Greg Ungerer | dd1cb3a | 2012-10-24 22:36:27 +1000 | [diff] [blame] | 71 | pg_data_table[i] = pg_data_map + node; |
| 72 | } |
| 73 | #endif |
Greg Ungerer | dd1cb3a | 2012-10-24 22:36:27 +1000 | [diff] [blame] | 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); |
Greg Ungerer | dd1cb3a | 2012-10-24 22:36:27 +1000 | [diff] [blame] | 97 | |
| 98 | /* |
| 99 | * Set up SFC/DFC registers (user data space). |
| 100 | */ |
| 101 | set_fs (USER_DS); |
| 102 | |
| 103 | zones_size[ZONE_DMA] = (end_mem - PAGE_OFFSET) >> PAGE_SHIFT; |
| 104 | free_area_init(zones_size); |
| 105 | } |
| 106 | |
Greg Ungerer | f50bf88 | 2012-10-23 13:40:36 +1000 | [diff] [blame] | 107 | #endif /* CONFIG_MMU */ |
| 108 | |
Greg Ungerer | dd1cb3a | 2012-10-24 22:36:27 +1000 | [diff] [blame] | 109 | void free_initmem(void) |
| 110 | { |
Greg Ungerer | f50bf88 | 2012-10-23 13:40:36 +1000 | [diff] [blame] | 111 | #ifndef CONFIG_MMU_SUN3 |
Jiang Liu | dbe67df | 2013-07-03 15:02:51 -0700 | [diff] [blame] | 112 | free_initmem_default(-1); |
Greg Ungerer | f50bf88 | 2012-10-23 13:40:36 +1000 | [diff] [blame] | 113 | #endif /* CONFIG_MMU_SUN3 */ |
Greg Ungerer | dd1cb3a | 2012-10-24 22:36:27 +1000 | [diff] [blame] | 114 | } |
| 115 | |
Greg Ungerer | dd1cb3a | 2012-10-24 22:36:27 +1000 | [diff] [blame] | 116 | #if defined(CONFIG_MMU) && !defined(CONFIG_COLDFIRE) |
| 117 | #define VECTORS &vectors[0] |
Greg Ungerer | 66d857b | 2011-03-22 13:39:27 +1000 | [diff] [blame] | 118 | #else |
Greg Ungerer | dd1cb3a | 2012-10-24 22:36:27 +1000 | [diff] [blame] | 119 | #define VECTORS _ramvec |
| 120 | #endif |
| 121 | |
Jiang Liu | 3e548a9 | 2013-07-03 15:04:37 -0700 | [diff] [blame] | 122 | static inline void init_pointer_tables(void) |
Greg Ungerer | dd1cb3a | 2012-10-24 22:36:27 +1000 | [diff] [blame] | 123 | { |
Jiang Liu | 3e548a9 | 2013-07-03 15:04:37 -0700 | [diff] [blame] | 124 | #if defined(CONFIG_MMU) && !defined(CONFIG_SUN3) && !defined(CONFIG_COLDFIRE) |
Greg Ungerer | dd1cb3a | 2012-10-24 22:36:27 +1000 | [diff] [blame] | 125 | int i; |
| 126 | |
Greg Ungerer | dd1cb3a | 2012-10-24 22:36:27 +1000 | [diff] [blame] | 127 | /* insert pointer tables allocated so far into the tablelist */ |
| 128 | init_pointer_table((unsigned long)kernel_pg_dir); |
| 129 | for (i = 0; i < PTRS_PER_PGD; i++) { |
| 130 | if (pgd_present(kernel_pg_dir[i])) |
| 131 | init_pointer_table(__pgd_page(kernel_pg_dir[i])); |
| 132 | } |
| 133 | |
| 134 | /* insert also pointer table that we used to unmap the zero page */ |
| 135 | if (zero_pgtable) |
| 136 | init_pointer_table((unsigned long)zero_pgtable); |
| 137 | #endif |
Jiang Liu | 3e548a9 | 2013-07-03 15:04:37 -0700 | [diff] [blame] | 138 | } |
Greg Ungerer | dd1cb3a | 2012-10-24 22:36:27 +1000 | [diff] [blame] | 139 | |
Jiang Liu | 3e548a9 | 2013-07-03 15:04:37 -0700 | [diff] [blame] | 140 | void __init mem_init(void) |
| 141 | { |
| 142 | /* this will put all memory onto the freelists */ |
| 143 | free_all_bootmem(); |
| 144 | init_pointer_tables(); |
Jiang Liu | 9671468 | 2013-07-03 15:04:00 -0700 | [diff] [blame] | 145 | mem_init_print_info(NULL); |
Greg Ungerer | dd1cb3a | 2012-10-24 22:36:27 +1000 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | #ifdef CONFIG_BLK_DEV_INITRD |
| 149 | void free_initrd_mem(unsigned long start, unsigned long end) |
| 150 | { |
Jiang Liu | dbe67df | 2013-07-03 15:02:51 -0700 | [diff] [blame] | 151 | free_reserved_area((void *)start, (void *)end, -1, "initrd"); |
Greg Ungerer | dd1cb3a | 2012-10-24 22:36:27 +1000 | [diff] [blame] | 152 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | #endif |