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> |
Mike Rapoport | 57c8a66 | 2018-10-30 15:09:49 -0700 | [diff] [blame] | 20 | #include <linux/memblock.h> |
Greg Ungerer | dd1cb3a | 2012-10-24 22:36:27 +1000 | [diff] [blame] | 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 | 66d857b | 2011-03-22 13:39:27 +1000 | [diff] [blame] | 43 | #ifdef CONFIG_MMU |
Greg Ungerer | dd1cb3a | 2012-10-24 22:36:27 +1000 | [diff] [blame] | 44 | |
Greg Ungerer | dd1cb3a | 2012-10-24 22:36:27 +1000 | [diff] [blame] | 45 | int m68k_virt_to_node_shift; |
| 46 | |
Greg Ungerer | dd1cb3a | 2012-10-24 22:36:27 +1000 | [diff] [blame] | 47 | void __init m68k_setup_node(int node) |
| 48 | { |
Greg Ungerer | dd1cb3a | 2012-10-24 22:36:27 +1000 | [diff] [blame] | 49 | node_set_online(node); |
| 50 | } |
| 51 | |
Greg Ungerer | dd1cb3a | 2012-10-24 22:36:27 +1000 | [diff] [blame] | 52 | #else /* CONFIG_MMU */ |
| 53 | |
| 54 | /* |
| 55 | * paging_init() continues the virtual memory environment setup which |
| 56 | * was begun by the code in arch/head.S. |
| 57 | * The parameters are pointers to where to stick the starting and ending |
| 58 | * addresses of available kernel virtual memory. |
| 59 | */ |
| 60 | void __init paging_init(void) |
| 61 | { |
| 62 | /* |
| 63 | * Make sure start_mem is page aligned, otherwise bootmem and |
| 64 | * page_alloc get different views of the world. |
| 65 | */ |
| 66 | unsigned long end_mem = memory_end & PAGE_MASK; |
Mike Rapoport | fa3354e | 2020-06-03 15:57:06 -0700 | [diff] [blame] | 67 | unsigned long max_zone_pfn[MAX_NR_ZONES] = { 0, }; |
Greg Ungerer | dd1cb3a | 2012-10-24 22:36:27 +1000 | [diff] [blame] | 68 | |
| 69 | high_memory = (void *) end_mem; |
| 70 | |
Mike Rapoport | 15c3c11 | 2018-10-30 15:08:58 -0700 | [diff] [blame] | 71 | empty_zero_page = memblock_alloc(PAGE_SIZE, PAGE_SIZE); |
Mike Rapoport | 8a7f97b | 2019-03-11 23:30:31 -0700 | [diff] [blame] | 72 | if (!empty_zero_page) |
| 73 | panic("%s: Failed to allocate %lu bytes align=0x%lx\n", |
| 74 | __func__, PAGE_SIZE, PAGE_SIZE); |
Mike Rapoport | fa3354e | 2020-06-03 15:57:06 -0700 | [diff] [blame] | 75 | max_zone_pfn[ZONE_DMA] = end_mem >> PAGE_SHIFT; |
| 76 | free_area_init(max_zone_pfn); |
Greg Ungerer | dd1cb3a | 2012-10-24 22:36:27 +1000 | [diff] [blame] | 77 | } |
| 78 | |
Greg Ungerer | f50bf88 | 2012-10-23 13:40:36 +1000 | [diff] [blame] | 79 | #endif /* CONFIG_MMU */ |
| 80 | |
Greg Ungerer | dd1cb3a | 2012-10-24 22:36:27 +1000 | [diff] [blame] | 81 | void free_initmem(void) |
| 82 | { |
Greg Ungerer | f50bf88 | 2012-10-23 13:40:36 +1000 | [diff] [blame] | 83 | #ifndef CONFIG_MMU_SUN3 |
Jiang Liu | dbe67df | 2013-07-03 15:02:51 -0700 | [diff] [blame] | 84 | free_initmem_default(-1); |
Greg Ungerer | f50bf88 | 2012-10-23 13:40:36 +1000 | [diff] [blame] | 85 | #endif /* CONFIG_MMU_SUN3 */ |
Greg Ungerer | dd1cb3a | 2012-10-24 22:36:27 +1000 | [diff] [blame] | 86 | } |
| 87 | |
Greg Ungerer | dd1cb3a | 2012-10-24 22:36:27 +1000 | [diff] [blame] | 88 | #if defined(CONFIG_MMU) && !defined(CONFIG_COLDFIRE) |
| 89 | #define VECTORS &vectors[0] |
Greg Ungerer | 66d857b | 2011-03-22 13:39:27 +1000 | [diff] [blame] | 90 | #else |
Greg Ungerer | dd1cb3a | 2012-10-24 22:36:27 +1000 | [diff] [blame] | 91 | #define VECTORS _ramvec |
| 92 | #endif |
| 93 | |
Jiang Liu | 3e548a9 | 2013-07-03 15:04:37 -0700 | [diff] [blame] | 94 | static inline void init_pointer_tables(void) |
Greg Ungerer | dd1cb3a | 2012-10-24 22:36:27 +1000 | [diff] [blame] | 95 | { |
Jiang Liu | 3e548a9 | 2013-07-03 15:04:37 -0700 | [diff] [blame] | 96 | #if defined(CONFIG_MMU) && !defined(CONFIG_SUN3) && !defined(CONFIG_COLDFIRE) |
Peter Zijlstra | 518a6b5 | 2020-01-31 13:45:40 +0100 | [diff] [blame] | 97 | int i, j; |
Greg Ungerer | dd1cb3a | 2012-10-24 22:36:27 +1000 | [diff] [blame] | 98 | |
Greg Ungerer | dd1cb3a | 2012-10-24 22:36:27 +1000 | [diff] [blame] | 99 | /* insert pointer tables allocated so far into the tablelist */ |
Peter Zijlstra | 0e071ee | 2020-01-31 13:45:39 +0100 | [diff] [blame] | 100 | init_pointer_table(kernel_pg_dir, TABLE_PGD); |
Greg Ungerer | dd1cb3a | 2012-10-24 22:36:27 +1000 | [diff] [blame] | 101 | for (i = 0; i < PTRS_PER_PGD; i++) { |
Peter Zijlstra | 0e071ee | 2020-01-31 13:45:39 +0100 | [diff] [blame] | 102 | pud_t *pud = (pud_t *)&kernel_pg_dir[i]; |
| 103 | pmd_t *pmd_dir; |
Mike Rapoport | 60e50f3 | 2019-12-04 16:53:59 -0800 | [diff] [blame] | 104 | |
Peter Zijlstra | 0e071ee | 2020-01-31 13:45:39 +0100 | [diff] [blame] | 105 | if (!pud_present(*pud)) |
| 106 | continue; |
| 107 | |
| 108 | pmd_dir = (pmd_t *)pgd_page_vaddr(kernel_pg_dir[i]); |
| 109 | init_pointer_table(pmd_dir, TABLE_PMD); |
Peter Zijlstra | 518a6b5 | 2020-01-31 13:45:40 +0100 | [diff] [blame] | 110 | |
| 111 | for (j = 0; j < PTRS_PER_PMD; j++) { |
| 112 | pmd_t *pmd = &pmd_dir[j]; |
| 113 | pte_t *pte_dir; |
| 114 | |
| 115 | if (!pmd_present(*pmd)) |
| 116 | continue; |
| 117 | |
Mike Rapoport | 974b9b2 | 2020-06-08 21:33:10 -0700 | [diff] [blame] | 118 | pte_dir = (pte_t *)pmd_page_vaddr(*pmd); |
Peter Zijlstra | 518a6b5 | 2020-01-31 13:45:40 +0100 | [diff] [blame] | 119 | init_pointer_table(pte_dir, TABLE_PTE); |
| 120 | } |
Greg Ungerer | dd1cb3a | 2012-10-24 22:36:27 +1000 | [diff] [blame] | 121 | } |
Greg Ungerer | dd1cb3a | 2012-10-24 22:36:27 +1000 | [diff] [blame] | 122 | #endif |
Jiang Liu | 3e548a9 | 2013-07-03 15:04:37 -0700 | [diff] [blame] | 123 | } |
Greg Ungerer | dd1cb3a | 2012-10-24 22:36:27 +1000 | [diff] [blame] | 124 | |
Jiang Liu | 3e548a9 | 2013-07-03 15:04:37 -0700 | [diff] [blame] | 125 | void __init mem_init(void) |
| 126 | { |
| 127 | /* this will put all memory onto the freelists */ |
Mike Rapoport | c6ffc5c | 2018-10-30 15:09:30 -0700 | [diff] [blame] | 128 | memblock_free_all(); |
Jiang Liu | 3e548a9 | 2013-07-03 15:04:37 -0700 | [diff] [blame] | 129 | init_pointer_tables(); |
Greg Ungerer | dd1cb3a | 2012-10-24 22:36:27 +1000 | [diff] [blame] | 130 | } |