12874c5fdSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */ 214cf11afSPaul Mackerras /* 314cf11afSPaul Mackerras * Declarations of procedures and variables shared between files 414cf11afSPaul Mackerras * in arch/ppc/mm/. 514cf11afSPaul Mackerras * 614cf11afSPaul Mackerras * Derived from arch/ppc/mm/init.c: 714cf11afSPaul Mackerras * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org) 814cf11afSPaul Mackerras * 914cf11afSPaul Mackerras * Modifications by Paul Mackerras (PowerMac) (paulus@cs.anu.edu.au) 1014cf11afSPaul Mackerras * and Cort Dougan (PReP) (cort@cs.nmt.edu) 1114cf11afSPaul Mackerras * Copyright (C) 1996 Paul Mackerras 1214cf11afSPaul Mackerras * 1314cf11afSPaul Mackerras * Derived from "arch/i386/mm/init.c" 1414cf11afSPaul Mackerras * Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds 1514cf11afSPaul Mackerras */ 1662102307SDavid Gibson #include <linux/mm.h> 1714cf11afSPaul Mackerras #include <asm/mmu.h> 1814cf11afSPaul Mackerras 192a4aca11SBenjamin Herrenschmidt #ifdef CONFIG_PPC_MMU_NOHASH 20cf4a6085SChristophe Leroy #include <asm/trace.h> 212a4aca11SBenjamin Herrenschmidt 222a4aca11SBenjamin Herrenschmidt /* 232a4aca11SBenjamin Herrenschmidt * On 40x and 8xx, we directly inline tlbia and tlbivax 242a4aca11SBenjamin Herrenschmidt */ 25968159c0SChristophe Leroy #if defined(CONFIG_40x) || defined(CONFIG_PPC_8xx) 262a4aca11SBenjamin Herrenschmidt static inline void _tlbil_all(void) 272a4aca11SBenjamin Herrenschmidt { 284a082682SBenjamin Herrenschmidt asm volatile ("sync; tlbia; isync" : : : "memory"); 298114c36eSChristophe Leroy trace_tlbia(MMU_NO_CONTEXT); 302a4aca11SBenjamin Herrenschmidt } 312a4aca11SBenjamin Herrenschmidt static inline void _tlbil_pid(unsigned int pid) 322a4aca11SBenjamin Herrenschmidt { 334a082682SBenjamin Herrenschmidt asm volatile ("sync; tlbia; isync" : : : "memory"); 348114c36eSChristophe Leroy trace_tlbia(pid); 352a4aca11SBenjamin Herrenschmidt } 36d4e167daSBenjamin Herrenschmidt #define _tlbil_pid_noind(pid) _tlbil_pid(pid) 37d4e167daSBenjamin Herrenschmidt 38968159c0SChristophe Leroy #else /* CONFIG_40x || CONFIG_PPC_8xx */ 392a4aca11SBenjamin Herrenschmidt extern void _tlbil_all(void); 402a4aca11SBenjamin Herrenschmidt extern void _tlbil_pid(unsigned int pid); 4125d21ad6SBenjamin Herrenschmidt #ifdef CONFIG_PPC_BOOK3E 4225d21ad6SBenjamin Herrenschmidt extern void _tlbil_pid_noind(unsigned int pid); 4325d21ad6SBenjamin Herrenschmidt #else 44d4e167daSBenjamin Herrenschmidt #define _tlbil_pid_noind(pid) _tlbil_pid(pid) 4525d21ad6SBenjamin Herrenschmidt #endif 46968159c0SChristophe Leroy #endif /* !(CONFIG_40x || CONFIG_PPC_8xx) */ 472a4aca11SBenjamin Herrenschmidt 482a4aca11SBenjamin Herrenschmidt /* 492a4aca11SBenjamin Herrenschmidt * On 8xx, we directly inline tlbie, on others, it's extern 502a4aca11SBenjamin Herrenschmidt */ 51968159c0SChristophe Leroy #ifdef CONFIG_PPC_8xx 52d4e167daSBenjamin Herrenschmidt static inline void _tlbil_va(unsigned long address, unsigned int pid, 53d4e167daSBenjamin Herrenschmidt unsigned int tsize, unsigned int ind) 542a4aca11SBenjamin Herrenschmidt { 554a082682SBenjamin Herrenschmidt asm volatile ("tlbie %0; sync" : : "r" (address) : "memory"); 56cf4a6085SChristophe Leroy trace_tlbie(0, 0, address, pid, 0, 0, 0); 572a4aca11SBenjamin Herrenschmidt } 5825d21ad6SBenjamin Herrenschmidt #elif defined(CONFIG_PPC_BOOK3E) 5925d21ad6SBenjamin Herrenschmidt extern void _tlbil_va(unsigned long address, unsigned int pid, 6025d21ad6SBenjamin Herrenschmidt unsigned int tsize, unsigned int ind); 6125d21ad6SBenjamin Herrenschmidt #else 62d4e167daSBenjamin Herrenschmidt extern void __tlbil_va(unsigned long address, unsigned int pid); 63d4e167daSBenjamin Herrenschmidt static inline void _tlbil_va(unsigned long address, unsigned int pid, 64d4e167daSBenjamin Herrenschmidt unsigned int tsize, unsigned int ind) 65d4e167daSBenjamin Herrenschmidt { 66d4e167daSBenjamin Herrenschmidt __tlbil_va(address, pid); 67d4e167daSBenjamin Herrenschmidt } 68968159c0SChristophe Leroy #endif /* CONFIG_PPC_8xx */ 692a4aca11SBenjamin Herrenschmidt 70e7f75ad0SDave Kleikamp #if defined(CONFIG_PPC_BOOK3E) || defined(CONFIG_PPC_47x) 7125d21ad6SBenjamin Herrenschmidt extern void _tlbivax_bcast(unsigned long address, unsigned int pid, 7225d21ad6SBenjamin Herrenschmidt unsigned int tsize, unsigned int ind); 7325d21ad6SBenjamin Herrenschmidt #else 74d4e167daSBenjamin Herrenschmidt static inline void _tlbivax_bcast(unsigned long address, unsigned int pid, 75d4e167daSBenjamin Herrenschmidt unsigned int tsize, unsigned int ind) 762a4aca11SBenjamin Herrenschmidt { 772a4aca11SBenjamin Herrenschmidt BUG(); 782a4aca11SBenjamin Herrenschmidt } 7925d21ad6SBenjamin Herrenschmidt #endif 802a4aca11SBenjamin Herrenschmidt 81e4dccf90SChristophe Leroy static inline void print_system_hash_info(void) {} 82e4dccf90SChristophe Leroy 832a4aca11SBenjamin Herrenschmidt #else /* CONFIG_PPC_MMU_NOHASH */ 842a4aca11SBenjamin Herrenschmidt 85e4dccf90SChristophe Leroy void print_system_hash_info(void); 86e4dccf90SChristophe Leroy 872a4aca11SBenjamin Herrenschmidt #endif /* CONFIG_PPC_MMU_NOHASH */ 882a4aca11SBenjamin Herrenschmidt 89ab1f9dacSPaul Mackerras #ifdef CONFIG_PPC32 9019f5465eSTrent Piepho 9114cf11afSPaul Mackerras extern void mapin_ram(void); 927c5c4325SBecky Bruce extern void setbat(int index, unsigned long virt, phys_addr_t phys, 935dd4e4f6SMichael Ellerman unsigned int size, pgprot_t prot); 9414cf11afSPaul Mackerras 9514cf11afSPaul Mackerras extern int __map_without_bats; 9614cf11afSPaul Mackerras extern unsigned int rtas_data, rtas_size; 9714cf11afSPaul Mackerras 988e561e7eSDavid Gibson struct hash_pte; 99215b8237SChristophe Leroy extern u8 early_hash[]; 10032a74949SBenjamin Herrenschmidt 10132a74949SBenjamin Herrenschmidt #endif /* CONFIG_PPC32 */ 10232a74949SBenjamin Herrenschmidt 103ab1f9dacSPaul Mackerras extern unsigned long __max_low_memory; 10409b5e63fSKumar Gala extern phys_addr_t __initial_memory_limit_addr; 1052bf3016fSStefan Roese extern phys_addr_t total_memory; 1062bf3016fSStefan Roese extern phys_addr_t total_lowmem; 10799c62dd7SKumar Gala extern phys_addr_t memstart_addr; 108d7917ba7SKumar Gala extern phys_addr_t lowmem_end_addr; 10914cf11afSPaul Mackerras 110de32400dSAlbert Herranz #ifdef CONFIG_WII 111de32400dSAlbert Herranz extern unsigned long wii_hole_start; 112de32400dSAlbert Herranz extern unsigned long wii_hole_size; 113de32400dSAlbert Herranz 114de32400dSAlbert Herranz extern unsigned long wii_mmu_mapin_mem2(unsigned long top); 115de32400dSAlbert Herranz extern void wii_memory_fixups(void); 116de32400dSAlbert Herranz #endif 117de32400dSAlbert Herranz 11814cf11afSPaul Mackerras /* ...and now those things that may be slightly different between processor 11914cf11afSPaul Mackerras * architectures. -- Dan 12014cf11afSPaul Mackerras */ 121a372acfaSChristophe Leroy #ifdef CONFIG_PPC32 12214cf11afSPaul Mackerras extern void MMU_init_hw(void); 12372f208c6SChristophe Leroy void MMU_init_hw_patch(void); 12414e609d6SChristophe Leroy unsigned long mmu_mapin_ram(unsigned long base, unsigned long top); 125a372acfaSChristophe Leroy #endif 12614cf11afSPaul Mackerras 127a372acfaSChristophe Leroy #ifdef CONFIG_PPC_FSL_BOOK3E 128eba5de8dSScott Wood extern unsigned long map_mem_in_cams(unsigned long ram, int max_cam_idx, 12952bda69aSChristophe Leroy bool dryrun, bool init); 1301dc91c3eSKumar Gala extern unsigned long calc_cam_sz(unsigned long ram, unsigned long virt, 1311dc91c3eSKumar Gala phys_addr_t phys); 13255fd766bSKumar Gala #ifdef CONFIG_PPC32 13314cf11afSPaul Mackerras extern void adjust_total_lowmem(void); 13478a235efSKevin Hao extern int switch_to_as1(void); 1350be7d969SKevin Hao extern void restore_to_as0(int esel, int offset, void *dt_ptr, int bootcpu); 136aa1d2090SJason Yan void create_kaslr_tlb_entry(int entry, unsigned long virt, phys_addr_t phys); 137c061b38aSJason Yan void reloc_kernel_entry(void *fdt, int addr); 1382b0e86ccSJason Yan extern int is_second_reloc; 13955fd766bSKumar Gala #endif 14078f62237SKumar Gala extern void loadcam_entry(unsigned int index); 141d9e1831aSScott Wood extern void loadcam_multi(int first_idx, int num, int tmp_idx); 14214cf11afSPaul Mackerras 1432b0e86ccSJason Yan #ifdef CONFIG_RANDOMIZE_BASE 1442b0e86ccSJason Yan void kaslr_early_init(void *dt_ptr, phys_addr_t size); 145b3960972SJason Yan void kaslr_late_init(void); 1462b0e86ccSJason Yan #else 1472b0e86ccSJason Yan static inline void kaslr_early_init(void *dt_ptr, phys_addr_t size) {} 148b3960972SJason Yan static inline void kaslr_late_init(void) {} 1492b0e86ccSJason Yan #endif 1502b0e86ccSJason Yan 15178f62237SKumar Gala struct tlbcam { 15278f62237SKumar Gala u32 MAS0; 15378f62237SKumar Gala u32 MAS1; 15478f62237SKumar Gala unsigned long MAS2; 15578f62237SKumar Gala u32 MAS3; 15678f62237SKumar Gala u32 MAS7; 15778f62237SKumar Gala }; 158*87ccc668SChristophe Leroy 159*87ccc668SChristophe Leroy #define NUM_TLBCAMS 64 160*87ccc668SChristophe Leroy 161*87ccc668SChristophe Leroy extern struct tlbcam TLBCAM[NUM_TLBCAMS]; 16214cf11afSPaul Mackerras #endif 1633084cdb7SChristophe Leroy 164d7cceda9SChristophe Leroy #if defined(CONFIG_PPC_BOOK3S_32) || defined(CONFIG_FSL_BOOKE) || defined(CONFIG_PPC_8xx) 1653084cdb7SChristophe Leroy /* 6xx have BATS */ 1663084cdb7SChristophe Leroy /* FSL_BOOKE have TLBCAM */ 1674badd43aSChristophe Leroy /* 8xx have LTLB */ 1683084cdb7SChristophe Leroy phys_addr_t v_block_mapped(unsigned long va); 1693084cdb7SChristophe Leroy unsigned long p_block_mapped(phys_addr_t pa); 1703084cdb7SChristophe Leroy #else 1713084cdb7SChristophe Leroy static inline phys_addr_t v_block_mapped(unsigned long va) { return 0; } 1723084cdb7SChristophe Leroy static inline unsigned long p_block_mapped(phys_addr_t pa) { return 0; } 1733084cdb7SChristophe Leroy #endif 17463b2bc61SChristophe Leroy 175d5970045SChristophe Leroy #if defined(CONFIG_PPC_BOOK3S_32) || defined(CONFIG_PPC_8xx) || defined(CONFIG_PPC_FSL_BOOK3E) 17663b2bc61SChristophe Leroy void mmu_mark_initmem_nx(void); 17763b2bc61SChristophe Leroy void mmu_mark_rodata_ro(void); 17863b2bc61SChristophe Leroy #else 17963b2bc61SChristophe Leroy static inline void mmu_mark_initmem_nx(void) { } 18063b2bc61SChristophe Leroy static inline void mmu_mark_rodata_ro(void) { } 18163b2bc61SChristophe Leroy #endif 1821e1c8b2cSChristophe Leroy 183136a9a0fSChristophe Leroy #ifdef CONFIG_PPC_8xx 184136a9a0fSChristophe Leroy void __init mmu_mapin_immr(void); 185136a9a0fSChristophe Leroy #endif 186136a9a0fSChristophe Leroy 187e0847283SChristophe Leroy #ifdef CONFIG_DEBUG_WX 1881e1c8b2cSChristophe Leroy void ptdump_check_wx(void); 1891e1c8b2cSChristophe Leroy #else 1901e1c8b2cSChristophe Leroy static inline void ptdump_check_wx(void) { } 1911e1c8b2cSChristophe Leroy #endif 19290cbac0eSChristophe Leroy 19390cbac0eSChristophe Leroy static inline bool debug_pagealloc_enabled_or_kfence(void) 19490cbac0eSChristophe Leroy { 19590cbac0eSChristophe Leroy return IS_ENABLED(CONFIG_KFENCE) || debug_pagealloc_enabled(); 19690cbac0eSChristophe Leroy } 197