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 852a4aca11SBenjamin Herrenschmidt extern void _tlbie(unsigned long address); 862a4aca11SBenjamin Herrenschmidt extern void _tlbia(void); 872a4aca11SBenjamin Herrenschmidt 88e4dccf90SChristophe Leroy void print_system_hash_info(void); 89e4dccf90SChristophe Leroy 902a4aca11SBenjamin Herrenschmidt #endif /* CONFIG_PPC_MMU_NOHASH */ 912a4aca11SBenjamin Herrenschmidt 92ab1f9dacSPaul Mackerras #ifdef CONFIG_PPC32 9319f5465eSTrent Piepho 94f49f4e2bSChristophe Leroy void hash_preload(struct mm_struct *mm, unsigned long ea); 95e5a1edb9SChristophe Leroy 9614cf11afSPaul Mackerras extern void mapin_ram(void); 977c5c4325SBecky Bruce extern void setbat(int index, unsigned long virt, phys_addr_t phys, 985dd4e4f6SMichael Ellerman unsigned int size, pgprot_t prot); 9914cf11afSPaul Mackerras 10014cf11afSPaul Mackerras extern int __map_without_bats; 10114cf11afSPaul Mackerras extern unsigned int rtas_data, rtas_size; 10214cf11afSPaul Mackerras 1038e561e7eSDavid Gibson struct hash_pte; 10457e0491bSChristophe Leroy extern struct hash_pte *Hash; 105215b8237SChristophe Leroy extern u8 early_hash[]; 10632a74949SBenjamin Herrenschmidt 10732a74949SBenjamin Herrenschmidt #endif /* CONFIG_PPC32 */ 10832a74949SBenjamin Herrenschmidt 109ab1f9dacSPaul Mackerras extern unsigned long __max_low_memory; 11009b5e63fSKumar Gala extern phys_addr_t __initial_memory_limit_addr; 1112bf3016fSStefan Roese extern phys_addr_t total_memory; 1122bf3016fSStefan Roese extern phys_addr_t total_lowmem; 11399c62dd7SKumar Gala extern phys_addr_t memstart_addr; 114d7917ba7SKumar Gala extern phys_addr_t lowmem_end_addr; 11514cf11afSPaul Mackerras 116de32400dSAlbert Herranz #ifdef CONFIG_WII 117de32400dSAlbert Herranz extern unsigned long wii_hole_start; 118de32400dSAlbert Herranz extern unsigned long wii_hole_size; 119de32400dSAlbert Herranz 120de32400dSAlbert Herranz extern unsigned long wii_mmu_mapin_mem2(unsigned long top); 121de32400dSAlbert Herranz extern void wii_memory_fixups(void); 122de32400dSAlbert Herranz #endif 123de32400dSAlbert Herranz 12414cf11afSPaul Mackerras /* ...and now those things that may be slightly different between processor 12514cf11afSPaul Mackerras * architectures. -- Dan 12614cf11afSPaul Mackerras */ 127a372acfaSChristophe Leroy #ifdef CONFIG_PPC32 12814cf11afSPaul Mackerras extern void MMU_init_hw(void); 12972f208c6SChristophe Leroy void MMU_init_hw_patch(void); 13014e609d6SChristophe Leroy unsigned long mmu_mapin_ram(unsigned long base, unsigned long top); 131a372acfaSChristophe Leroy #endif 13214cf11afSPaul Mackerras 133a372acfaSChristophe Leroy #ifdef CONFIG_PPC_FSL_BOOK3E 134eba5de8dSScott Wood extern unsigned long map_mem_in_cams(unsigned long ram, int max_cam_idx, 135eba5de8dSScott Wood bool dryrun); 1361dc91c3eSKumar Gala extern unsigned long calc_cam_sz(unsigned long ram, unsigned long virt, 1371dc91c3eSKumar Gala phys_addr_t phys); 13855fd766bSKumar Gala #ifdef CONFIG_PPC32 13914cf11afSPaul Mackerras extern void adjust_total_lowmem(void); 14078a235efSKevin Hao extern int switch_to_as1(void); 1410be7d969SKevin Hao extern void restore_to_as0(int esel, int offset, void *dt_ptr, int bootcpu); 142*aa1d2090SJason Yan void create_kaslr_tlb_entry(int entry, unsigned long virt, phys_addr_t phys); 14355fd766bSKumar Gala #endif 14478f62237SKumar Gala extern void loadcam_entry(unsigned int index); 145d9e1831aSScott Wood extern void loadcam_multi(int first_idx, int num, int tmp_idx); 14614cf11afSPaul Mackerras 14778f62237SKumar Gala struct tlbcam { 14878f62237SKumar Gala u32 MAS0; 14978f62237SKumar Gala u32 MAS1; 15078f62237SKumar Gala unsigned long MAS2; 15178f62237SKumar Gala u32 MAS3; 15278f62237SKumar Gala u32 MAS7; 15378f62237SKumar Gala }; 15414cf11afSPaul Mackerras #endif 1553084cdb7SChristophe Leroy 156d7cceda9SChristophe Leroy #if defined(CONFIG_PPC_BOOK3S_32) || defined(CONFIG_FSL_BOOKE) || defined(CONFIG_PPC_8xx) 1573084cdb7SChristophe Leroy /* 6xx have BATS */ 1583084cdb7SChristophe Leroy /* FSL_BOOKE have TLBCAM */ 1594badd43aSChristophe Leroy /* 8xx have LTLB */ 1603084cdb7SChristophe Leroy phys_addr_t v_block_mapped(unsigned long va); 1613084cdb7SChristophe Leroy unsigned long p_block_mapped(phys_addr_t pa); 1623084cdb7SChristophe Leroy #else 1633084cdb7SChristophe Leroy static inline phys_addr_t v_block_mapped(unsigned long va) { return 0; } 1643084cdb7SChristophe Leroy static inline unsigned long p_block_mapped(phys_addr_t pa) { return 0; } 1653084cdb7SChristophe Leroy #endif 16663b2bc61SChristophe Leroy 167d5f17ee9SChristophe Leroy #if defined(CONFIG_PPC_BOOK3S_32) || defined(CONFIG_PPC_8xx) 16863b2bc61SChristophe Leroy void mmu_mark_initmem_nx(void); 16963b2bc61SChristophe Leroy void mmu_mark_rodata_ro(void); 17063b2bc61SChristophe Leroy #else 17163b2bc61SChristophe Leroy static inline void mmu_mark_initmem_nx(void) { } 17263b2bc61SChristophe Leroy static inline void mmu_mark_rodata_ro(void) { } 17363b2bc61SChristophe Leroy #endif 174