xref: /openbmc/linux/arch/powerpc/mm/mmu_decl.h (revision 2074271a)
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)
_tlbil_all(void)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 }
_tlbil_pid(unsigned int pid)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);
41e0d68273SChristophe Leroy #ifdef CONFIG_PPC_BOOK3E_64
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
_tlbil_va(unsigned long address,unsigned int pid,unsigned int tsize,unsigned int ind)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 }
58e0d68273SChristophe Leroy #elif defined(CONFIG_PPC_BOOK3E_64)
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);
_tlbil_va(unsigned long address,unsigned int pid,unsigned int tsize,unsigned int ind)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 
70e0d68273SChristophe Leroy #if defined(CONFIG_PPC_BOOK3E_64) || 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
_tlbivax_bcast(unsigned long address,unsigned int pid,unsigned int tsize,unsigned int ind)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 
print_system_hash_info(void)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 
95215b8237SChristophe Leroy extern u8 early_hash[];
9632a74949SBenjamin Herrenschmidt 
9732a74949SBenjamin Herrenschmidt #endif /* CONFIG_PPC32 */
9832a74949SBenjamin Herrenschmidt 
99ab1f9dacSPaul Mackerras extern unsigned long __max_low_memory;
1002bf3016fSStefan Roese extern phys_addr_t total_memory;
1012bf3016fSStefan Roese extern phys_addr_t total_lowmem;
10299c62dd7SKumar Gala extern phys_addr_t memstart_addr;
103d7917ba7SKumar Gala extern phys_addr_t lowmem_end_addr;
10414cf11afSPaul Mackerras 
10514cf11afSPaul Mackerras /* ...and now those things that may be slightly different between processor
10614cf11afSPaul Mackerras  * architectures.  -- Dan
10714cf11afSPaul Mackerras  */
108a372acfaSChristophe Leroy #ifdef CONFIG_PPC32
10914cf11afSPaul Mackerras extern void MMU_init_hw(void);
11072f208c6SChristophe Leroy void MMU_init_hw_patch(void);
11114e609d6SChristophe Leroy unsigned long mmu_mapin_ram(unsigned long base, unsigned long top);
112a372acfaSChristophe Leroy #endif
113b27c1a0aSChristophe Leroy void mmu_init_secondary(int cpu);
11414cf11afSPaul Mackerras 
1153e731858SChristophe Leroy #ifdef CONFIG_PPC_E500
116eba5de8dSScott Wood extern unsigned long map_mem_in_cams(unsigned long ram, int max_cam_idx,
11752bda69aSChristophe Leroy 				     bool dryrun, bool init);
11855fd766bSKumar Gala #ifdef CONFIG_PPC32
11914cf11afSPaul Mackerras extern void adjust_total_lowmem(void);
12078a235efSKevin Hao extern int switch_to_as1(void);
1210be7d969SKevin Hao extern void restore_to_as0(int esel, int offset, void *dt_ptr, int bootcpu);
122aa1d2090SJason Yan void create_kaslr_tlb_entry(int entry, unsigned long virt, phys_addr_t phys);
123c061b38aSJason Yan void reloc_kernel_entry(void *fdt, int addr);
1246f8675a6SChristophe Leroy void relocate_init(u64 dt_ptr, phys_addr_t start);
1252b0e86ccSJason Yan extern int is_second_reloc;
12655fd766bSKumar Gala #endif
12778f62237SKumar Gala extern void loadcam_entry(unsigned int index);
128d9e1831aSScott Wood extern void loadcam_multi(int first_idx, int num, int tmp_idx);
12914cf11afSPaul Mackerras 
1302b0e86ccSJason Yan #ifdef CONFIG_RANDOMIZE_BASE
1312b0e86ccSJason Yan void kaslr_early_init(void *dt_ptr, phys_addr_t size);
132b3960972SJason Yan void kaslr_late_init(void);
1332b0e86ccSJason Yan #else
kaslr_early_init(void * dt_ptr,phys_addr_t size)1342b0e86ccSJason Yan static inline void kaslr_early_init(void *dt_ptr, phys_addr_t size) {}
kaslr_late_init(void)135b3960972SJason Yan static inline void kaslr_late_init(void) {}
1362b0e86ccSJason Yan #endif
1372b0e86ccSJason Yan 
13878f62237SKumar Gala struct tlbcam {
13978f62237SKumar Gala 	u32	MAS0;
14078f62237SKumar Gala 	u32	MAS1;
14178f62237SKumar Gala 	unsigned long	MAS2;
14278f62237SKumar Gala 	u32	MAS3;
14378f62237SKumar Gala 	u32	MAS7;
14478f62237SKumar Gala };
14587ccc668SChristophe Leroy 
14687ccc668SChristophe Leroy #define NUM_TLBCAMS	64
14787ccc668SChristophe Leroy 
14887ccc668SChristophe Leroy extern struct tlbcam TLBCAM[NUM_TLBCAMS];
14914cf11afSPaul Mackerras #endif
1503084cdb7SChristophe Leroy 
151dfc3095cSChristophe Leroy #if defined(CONFIG_PPC_BOOK3S_32) || defined(CONFIG_PPC_85xx) || defined(CONFIG_PPC_8xx)
1523084cdb7SChristophe Leroy /* 6xx have BATS */
153dfc3095cSChristophe Leroy /* PPC_85xx have TLBCAM */
1544badd43aSChristophe Leroy /* 8xx have LTLB */
1553084cdb7SChristophe Leroy phys_addr_t v_block_mapped(unsigned long va);
1563084cdb7SChristophe Leroy unsigned long p_block_mapped(phys_addr_t pa);
1573084cdb7SChristophe Leroy #else
v_block_mapped(unsigned long va)1583084cdb7SChristophe Leroy static inline phys_addr_t v_block_mapped(unsigned long va) { return 0; }
p_block_mapped(phys_addr_t pa)1593084cdb7SChristophe Leroy static inline unsigned long p_block_mapped(phys_addr_t pa) { return 0; }
1603084cdb7SChristophe Leroy #endif
16163b2bc61SChristophe Leroy 
1623e731858SChristophe Leroy #if defined(CONFIG_PPC_BOOK3S_32) || defined(CONFIG_PPC_8xx) || defined(CONFIG_PPC_E500)
16363b2bc61SChristophe Leroy void mmu_mark_initmem_nx(void);
16463b2bc61SChristophe Leroy void mmu_mark_rodata_ro(void);
16563b2bc61SChristophe Leroy #else
mmu_mark_initmem_nx(void)16663b2bc61SChristophe Leroy static inline void mmu_mark_initmem_nx(void) { }
mmu_mark_rodata_ro(void)16763b2bc61SChristophe Leroy static inline void mmu_mark_rodata_ro(void) { }
16863b2bc61SChristophe Leroy #endif
1691e1c8b2cSChristophe Leroy 
170136a9a0fSChristophe Leroy #ifdef CONFIG_PPC_8xx
171136a9a0fSChristophe Leroy void __init mmu_mapin_immr(void);
172136a9a0fSChristophe Leroy #endif
173136a9a0fSChristophe Leroy 
174e0847283SChristophe Leroy #ifdef CONFIG_DEBUG_WX
1751e1c8b2cSChristophe Leroy void ptdump_check_wx(void);
1761e1c8b2cSChristophe Leroy #else
ptdump_check_wx(void)1771e1c8b2cSChristophe Leroy static inline void ptdump_check_wx(void) { }
1781e1c8b2cSChristophe Leroy #endif
17990cbac0eSChristophe Leroy 
debug_pagealloc_enabled_or_kfence(void)18090cbac0eSChristophe Leroy static inline bool debug_pagealloc_enabled_or_kfence(void)
18190cbac0eSChristophe Leroy {
18290cbac0eSChristophe Leroy 	return IS_ENABLED(CONFIG_KFENCE) || debug_pagealloc_enabled();
18390cbac0eSChristophe Leroy }
184*2074271aSMichael Ellerman 
185*2074271aSMichael Ellerman #ifdef CONFIG_MEMORY_HOTPLUG
186*2074271aSMichael Ellerman int create_section_mapping(unsigned long start, unsigned long end,
187*2074271aSMichael Ellerman 			   int nid, pgprot_t prot);
188*2074271aSMichael Ellerman #endif
189