Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 2 | /* |
| 3 | * Declarations of procedures and variables shared between files |
| 4 | * in arch/ppc/mm/. |
| 5 | * |
| 6 | * Derived from arch/ppc/mm/init.c: |
| 7 | * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org) |
| 8 | * |
| 9 | * Modifications by Paul Mackerras (PowerMac) (paulus@cs.anu.edu.au) |
| 10 | * and Cort Dougan (PReP) (cort@cs.nmt.edu) |
| 11 | * Copyright (C) 1996 Paul Mackerras |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 12 | * |
| 13 | * Derived from "arch/i386/mm/init.c" |
| 14 | * Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 15 | */ |
David Gibson | 6210230 | 2007-04-24 13:09:12 +1000 | [diff] [blame] | 16 | #include <linux/mm.h> |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 17 | #include <asm/mmu.h> |
| 18 | |
Benjamin Herrenschmidt | 2a4aca11 | 2008-12-18 19:13:42 +0000 | [diff] [blame] | 19 | #ifdef CONFIG_PPC_MMU_NOHASH |
Christophe Leroy | cf4a608 | 2018-03-21 15:16:58 +0100 | [diff] [blame] | 20 | #include <asm/trace.h> |
Benjamin Herrenschmidt | 2a4aca11 | 2008-12-18 19:13:42 +0000 | [diff] [blame] | 21 | |
| 22 | /* |
| 23 | * On 40x and 8xx, we directly inline tlbia and tlbivax |
| 24 | */ |
Christophe Leroy | 968159c | 2017-08-08 13:58:54 +0200 | [diff] [blame] | 25 | #if defined(CONFIG_40x) || defined(CONFIG_PPC_8xx) |
Benjamin Herrenschmidt | 2a4aca11 | 2008-12-18 19:13:42 +0000 | [diff] [blame] | 26 | static inline void _tlbil_all(void) |
| 27 | { |
Benjamin Herrenschmidt | 4a08268 | 2009-01-06 17:56:51 +0000 | [diff] [blame] | 28 | asm volatile ("sync; tlbia; isync" : : : "memory"); |
Christophe Leroy | 8114c36 | 2018-03-21 15:17:00 +0100 | [diff] [blame] | 29 | trace_tlbia(MMU_NO_CONTEXT); |
Benjamin Herrenschmidt | 2a4aca11 | 2008-12-18 19:13:42 +0000 | [diff] [blame] | 30 | } |
| 31 | static inline void _tlbil_pid(unsigned int pid) |
| 32 | { |
Benjamin Herrenschmidt | 4a08268 | 2009-01-06 17:56:51 +0000 | [diff] [blame] | 33 | asm volatile ("sync; tlbia; isync" : : : "memory"); |
Christophe Leroy | 8114c36 | 2018-03-21 15:17:00 +0100 | [diff] [blame] | 34 | trace_tlbia(pid); |
Benjamin Herrenschmidt | 2a4aca11 | 2008-12-18 19:13:42 +0000 | [diff] [blame] | 35 | } |
Benjamin Herrenschmidt | d4e167d | 2009-07-23 23:15:24 +0000 | [diff] [blame] | 36 | #define _tlbil_pid_noind(pid) _tlbil_pid(pid) |
| 37 | |
Christophe Leroy | 968159c | 2017-08-08 13:58:54 +0200 | [diff] [blame] | 38 | #else /* CONFIG_40x || CONFIG_PPC_8xx */ |
Benjamin Herrenschmidt | 2a4aca11 | 2008-12-18 19:13:42 +0000 | [diff] [blame] | 39 | extern void _tlbil_all(void); |
| 40 | extern void _tlbil_pid(unsigned int pid); |
Benjamin Herrenschmidt | 25d21ad | 2009-07-23 23:15:47 +0000 | [diff] [blame] | 41 | #ifdef CONFIG_PPC_BOOK3E |
| 42 | extern void _tlbil_pid_noind(unsigned int pid); |
| 43 | #else |
Benjamin Herrenschmidt | d4e167d | 2009-07-23 23:15:24 +0000 | [diff] [blame] | 44 | #define _tlbil_pid_noind(pid) _tlbil_pid(pid) |
Benjamin Herrenschmidt | 25d21ad | 2009-07-23 23:15:47 +0000 | [diff] [blame] | 45 | #endif |
Christophe Leroy | 968159c | 2017-08-08 13:58:54 +0200 | [diff] [blame] | 46 | #endif /* !(CONFIG_40x || CONFIG_PPC_8xx) */ |
Benjamin Herrenschmidt | 2a4aca11 | 2008-12-18 19:13:42 +0000 | [diff] [blame] | 47 | |
| 48 | /* |
| 49 | * On 8xx, we directly inline tlbie, on others, it's extern |
| 50 | */ |
Christophe Leroy | 968159c | 2017-08-08 13:58:54 +0200 | [diff] [blame] | 51 | #ifdef CONFIG_PPC_8xx |
Benjamin Herrenschmidt | d4e167d | 2009-07-23 23:15:24 +0000 | [diff] [blame] | 52 | static inline void _tlbil_va(unsigned long address, unsigned int pid, |
| 53 | unsigned int tsize, unsigned int ind) |
Benjamin Herrenschmidt | 2a4aca11 | 2008-12-18 19:13:42 +0000 | [diff] [blame] | 54 | { |
Benjamin Herrenschmidt | 4a08268 | 2009-01-06 17:56:51 +0000 | [diff] [blame] | 55 | asm volatile ("tlbie %0; sync" : : "r" (address) : "memory"); |
Christophe Leroy | cf4a608 | 2018-03-21 15:16:58 +0100 | [diff] [blame] | 56 | trace_tlbie(0, 0, address, pid, 0, 0, 0); |
Benjamin Herrenschmidt | 2a4aca11 | 2008-12-18 19:13:42 +0000 | [diff] [blame] | 57 | } |
Benjamin Herrenschmidt | 25d21ad | 2009-07-23 23:15:47 +0000 | [diff] [blame] | 58 | #elif defined(CONFIG_PPC_BOOK3E) |
| 59 | extern void _tlbil_va(unsigned long address, unsigned int pid, |
| 60 | unsigned int tsize, unsigned int ind); |
| 61 | #else |
Benjamin Herrenschmidt | d4e167d | 2009-07-23 23:15:24 +0000 | [diff] [blame] | 62 | extern void __tlbil_va(unsigned long address, unsigned int pid); |
| 63 | static inline void _tlbil_va(unsigned long address, unsigned int pid, |
| 64 | unsigned int tsize, unsigned int ind) |
| 65 | { |
| 66 | __tlbil_va(address, pid); |
| 67 | } |
Christophe Leroy | 968159c | 2017-08-08 13:58:54 +0200 | [diff] [blame] | 68 | #endif /* CONFIG_PPC_8xx */ |
Benjamin Herrenschmidt | 2a4aca11 | 2008-12-18 19:13:42 +0000 | [diff] [blame] | 69 | |
Dave Kleikamp | e7f75ad | 2010-03-05 10:43:12 +0000 | [diff] [blame] | 70 | #if defined(CONFIG_PPC_BOOK3E) || defined(CONFIG_PPC_47x) |
Benjamin Herrenschmidt | 25d21ad | 2009-07-23 23:15:47 +0000 | [diff] [blame] | 71 | extern void _tlbivax_bcast(unsigned long address, unsigned int pid, |
| 72 | unsigned int tsize, unsigned int ind); |
| 73 | #else |
Benjamin Herrenschmidt | d4e167d | 2009-07-23 23:15:24 +0000 | [diff] [blame] | 74 | static inline void _tlbivax_bcast(unsigned long address, unsigned int pid, |
| 75 | unsigned int tsize, unsigned int ind) |
Benjamin Herrenschmidt | 2a4aca11 | 2008-12-18 19:13:42 +0000 | [diff] [blame] | 76 | { |
| 77 | BUG(); |
| 78 | } |
Benjamin Herrenschmidt | 25d21ad | 2009-07-23 23:15:47 +0000 | [diff] [blame] | 79 | #endif |
Benjamin Herrenschmidt | 2a4aca11 | 2008-12-18 19:13:42 +0000 | [diff] [blame] | 80 | |
Christophe Leroy | e4dccf9 | 2019-04-26 16:36:39 +0000 | [diff] [blame] | 81 | static inline void print_system_hash_info(void) {} |
| 82 | |
Benjamin Herrenschmidt | 2a4aca11 | 2008-12-18 19:13:42 +0000 | [diff] [blame] | 83 | #else /* CONFIG_PPC_MMU_NOHASH */ |
| 84 | |
Benjamin Herrenschmidt | 2a4aca11 | 2008-12-18 19:13:42 +0000 | [diff] [blame] | 85 | extern void _tlbie(unsigned long address); |
| 86 | extern void _tlbia(void); |
| 87 | |
Christophe Leroy | e4dccf9 | 2019-04-26 16:36:39 +0000 | [diff] [blame] | 88 | void print_system_hash_info(void); |
| 89 | |
Benjamin Herrenschmidt | 2a4aca11 | 2008-12-18 19:13:42 +0000 | [diff] [blame] | 90 | #endif /* CONFIG_PPC_MMU_NOHASH */ |
| 91 | |
Paul Mackerras | ab1f9da | 2005-10-10 21:58:35 +1000 | [diff] [blame] | 92 | #ifdef CONFIG_PPC32 |
Trent Piepho | 19f5465 | 2008-12-08 19:34:55 -0800 | [diff] [blame] | 93 | |
Christophe Leroy | f49f4e2 | 2019-08-16 05:41:43 +0000 | [diff] [blame] | 94 | void hash_preload(struct mm_struct *mm, unsigned long ea); |
Christophe Leroy | e5a1edb | 2019-08-16 05:41:42 +0000 | [diff] [blame] | 95 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 96 | extern void mapin_ram(void); |
Becky Bruce | 7c5c432 | 2008-06-14 09:41:42 +1000 | [diff] [blame] | 97 | extern void setbat(int index, unsigned long virt, phys_addr_t phys, |
Michael Ellerman | 5dd4e4f | 2015-03-25 20:11:55 +1100 | [diff] [blame] | 98 | unsigned int size, pgprot_t prot); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 99 | |
| 100 | extern int __map_without_bats; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 101 | extern unsigned int rtas_data, rtas_size; |
| 102 | |
David Gibson | 8e561e7 | 2007-06-13 14:52:56 +1000 | [diff] [blame] | 103 | struct hash_pte; |
Christophe Leroy | 57e0491 | 2019-04-26 16:36:36 +0000 | [diff] [blame] | 104 | extern struct hash_pte *Hash; |
Christophe Leroy | 215b8237 | 2019-04-26 16:23:36 +0000 | [diff] [blame] | 105 | extern u8 early_hash[]; |
Benjamin Herrenschmidt | 32a7494 | 2009-07-23 23:15:58 +0000 | [diff] [blame] | 106 | |
| 107 | #endif /* CONFIG_PPC32 */ |
| 108 | |
Paul Mackerras | ab1f9da | 2005-10-10 21:58:35 +1000 | [diff] [blame] | 109 | extern unsigned long __max_low_memory; |
Kumar Gala | 09b5e63 | 2008-04-16 05:52:25 +1000 | [diff] [blame] | 110 | extern phys_addr_t __initial_memory_limit_addr; |
Stefan Roese | 2bf3016 | 2008-07-10 01:09:23 +1000 | [diff] [blame] | 111 | extern phys_addr_t total_memory; |
| 112 | extern phys_addr_t total_lowmem; |
Kumar Gala | 99c62dd7 | 2008-04-16 05:52:21 +1000 | [diff] [blame] | 113 | extern phys_addr_t memstart_addr; |
Kumar Gala | d7917ba | 2008-04-16 05:52:22 +1000 | [diff] [blame] | 114 | extern phys_addr_t lowmem_end_addr; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 115 | |
Albert Herranz | de32400 | 2009-12-12 06:31:53 +0000 | [diff] [blame] | 116 | #ifdef CONFIG_WII |
| 117 | extern unsigned long wii_hole_start; |
| 118 | extern unsigned long wii_hole_size; |
| 119 | |
| 120 | extern unsigned long wii_mmu_mapin_mem2(unsigned long top); |
| 121 | extern void wii_memory_fixups(void); |
| 122 | #endif |
| 123 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 124 | /* ...and now those things that may be slightly different between processor |
| 125 | * architectures. -- Dan |
| 126 | */ |
Christophe Leroy | a372acf | 2016-02-09 17:07:50 +0100 | [diff] [blame] | 127 | #ifdef CONFIG_PPC32 |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 128 | extern void MMU_init_hw(void); |
Christophe Leroy | 72f208c | 2019-04-26 16:23:35 +0000 | [diff] [blame] | 129 | void MMU_init_hw_patch(void); |
Christophe Leroy | 14e609d | 2019-02-21 19:08:38 +0000 | [diff] [blame] | 130 | unsigned long mmu_mapin_ram(unsigned long base, unsigned long top); |
Christophe Leroy | a372acf | 2016-02-09 17:07:50 +0100 | [diff] [blame] | 131 | #endif |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 132 | |
Christophe Leroy | a372acf | 2016-02-09 17:07:50 +0100 | [diff] [blame] | 133 | #ifdef CONFIG_PPC_FSL_BOOK3E |
Scott Wood | eba5de8 | 2015-10-06 22:48:10 -0500 | [diff] [blame] | 134 | extern unsigned long map_mem_in_cams(unsigned long ram, int max_cam_idx, |
| 135 | bool dryrun); |
Kumar Gala | 1dc91c3 | 2011-09-16 10:39:59 -0500 | [diff] [blame] | 136 | extern unsigned long calc_cam_sz(unsigned long ram, unsigned long virt, |
| 137 | phys_addr_t phys); |
Kumar Gala | 55fd766 | 2009-10-16 18:48:40 -0500 | [diff] [blame] | 138 | #ifdef CONFIG_PPC32 |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 139 | extern void adjust_total_lowmem(void); |
Kevin Hao | 78a235e | 2013-12-24 15:12:07 +0800 | [diff] [blame] | 140 | extern int switch_to_as1(void); |
Kevin Hao | 0be7d969b | 2013-12-24 15:12:11 +0800 | [diff] [blame] | 141 | extern void restore_to_as0(int esel, int offset, void *dt_ptr, int bootcpu); |
Jason Yan | aa1d209 | 2019-09-20 17:45:38 +0800 | [diff] [blame] | 142 | void create_kaslr_tlb_entry(int entry, unsigned long virt, phys_addr_t phys); |
Jason Yan | c061b38 | 2019-09-20 17:45:39 +0800 | [diff] [blame] | 143 | void reloc_kernel_entry(void *fdt, int addr); |
Jason Yan | 2b0e86cc | 2019-09-20 17:45:40 +0800 | [diff] [blame] | 144 | extern int is_second_reloc; |
Kumar Gala | 55fd766 | 2009-10-16 18:48:40 -0500 | [diff] [blame] | 145 | #endif |
Kumar Gala | 78f6223 | 2010-05-13 14:38:21 -0500 | [diff] [blame] | 146 | extern void loadcam_entry(unsigned int index); |
Scott Wood | d9e1831 | 2015-10-06 22:48:09 -0500 | [diff] [blame] | 147 | extern void loadcam_multi(int first_idx, int num, int tmp_idx); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 148 | |
Jason Yan | 2b0e86cc | 2019-09-20 17:45:40 +0800 | [diff] [blame] | 149 | #ifdef CONFIG_RANDOMIZE_BASE |
| 150 | void kaslr_early_init(void *dt_ptr, phys_addr_t size); |
Jason Yan | b396097 | 2019-09-20 17:45:42 +0800 | [diff] [blame] | 151 | void kaslr_late_init(void); |
Jason Yan | 2b0e86cc | 2019-09-20 17:45:40 +0800 | [diff] [blame] | 152 | #else |
| 153 | static inline void kaslr_early_init(void *dt_ptr, phys_addr_t size) {} |
Jason Yan | b396097 | 2019-09-20 17:45:42 +0800 | [diff] [blame] | 154 | static inline void kaslr_late_init(void) {} |
Jason Yan | 2b0e86cc | 2019-09-20 17:45:40 +0800 | [diff] [blame] | 155 | #endif |
| 156 | |
Kumar Gala | 78f6223 | 2010-05-13 14:38:21 -0500 | [diff] [blame] | 157 | struct tlbcam { |
| 158 | u32 MAS0; |
| 159 | u32 MAS1; |
| 160 | unsigned long MAS2; |
| 161 | u32 MAS3; |
| 162 | u32 MAS7; |
| 163 | }; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 164 | #endif |
Christophe Leroy | 3084cdb | 2016-02-09 17:07:58 +0100 | [diff] [blame] | 165 | |
Christophe Leroy | d7cceda | 2018-11-17 10:24:56 +0000 | [diff] [blame] | 166 | #if defined(CONFIG_PPC_BOOK3S_32) || defined(CONFIG_FSL_BOOKE) || defined(CONFIG_PPC_8xx) |
Christophe Leroy | 3084cdb | 2016-02-09 17:07:58 +0100 | [diff] [blame] | 167 | /* 6xx have BATS */ |
| 168 | /* FSL_BOOKE have TLBCAM */ |
Christophe Leroy | 4badd43 | 2016-05-17 09:02:45 +0200 | [diff] [blame] | 169 | /* 8xx have LTLB */ |
Christophe Leroy | 3084cdb | 2016-02-09 17:07:58 +0100 | [diff] [blame] | 170 | phys_addr_t v_block_mapped(unsigned long va); |
| 171 | unsigned long p_block_mapped(phys_addr_t pa); |
| 172 | #else |
| 173 | static inline phys_addr_t v_block_mapped(unsigned long va) { return 0; } |
| 174 | static inline unsigned long p_block_mapped(phys_addr_t pa) { return 0; } |
| 175 | #endif |
Christophe Leroy | 63b2bc6 | 2019-02-21 19:08:49 +0000 | [diff] [blame] | 176 | |
Christophe Leroy | d5f17ee | 2019-02-21 19:08:51 +0000 | [diff] [blame] | 177 | #if defined(CONFIG_PPC_BOOK3S_32) || defined(CONFIG_PPC_8xx) |
Christophe Leroy | 63b2bc6 | 2019-02-21 19:08:49 +0000 | [diff] [blame] | 178 | void mmu_mark_initmem_nx(void); |
| 179 | void mmu_mark_rodata_ro(void); |
| 180 | #else |
| 181 | static inline void mmu_mark_initmem_nx(void) { } |
| 182 | static inline void mmu_mark_rodata_ro(void) { } |
| 183 | #endif |
Christophe Leroy | 1e1c8b2 | 2020-01-14 07:14:40 +0000 | [diff] [blame] | 184 | |
| 185 | #ifdef CONFIG_PPC_DEBUG_WX |
| 186 | void ptdump_check_wx(void); |
| 187 | #else |
| 188 | static inline void ptdump_check_wx(void) { } |
| 189 | #endif |