xref: /openbmc/linux/arch/powerpc/mm/mmu_decl.h (revision e0d68273)
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);
41*e0d68273SChristophe 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
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 }
58*e0d68273SChristophe 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);
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 
70*e0d68273SChristophe 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
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 
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
11314cf11afSPaul Mackerras 
114a372acfaSChristophe Leroy #ifdef CONFIG_PPC_FSL_BOOK3E
115eba5de8dSScott Wood extern unsigned long map_mem_in_cams(unsigned long ram, int max_cam_idx,
11652bda69aSChristophe Leroy 				     bool dryrun, bool init);
11755fd766bSKumar Gala #ifdef CONFIG_PPC32
11814cf11afSPaul Mackerras extern void adjust_total_lowmem(void);
11978a235efSKevin Hao extern int switch_to_as1(void);
1200be7d969SKevin Hao extern void restore_to_as0(int esel, int offset, void *dt_ptr, int bootcpu);
121aa1d2090SJason Yan void create_kaslr_tlb_entry(int entry, unsigned long virt, phys_addr_t phys);
122c061b38aSJason Yan void reloc_kernel_entry(void *fdt, int addr);
1232b0e86ccSJason Yan extern int is_second_reloc;
12455fd766bSKumar Gala #endif
12578f62237SKumar Gala extern void loadcam_entry(unsigned int index);
126d9e1831aSScott Wood extern void loadcam_multi(int first_idx, int num, int tmp_idx);
12714cf11afSPaul Mackerras 
1282b0e86ccSJason Yan #ifdef CONFIG_RANDOMIZE_BASE
1292b0e86ccSJason Yan void kaslr_early_init(void *dt_ptr, phys_addr_t size);
130b3960972SJason Yan void kaslr_late_init(void);
1312b0e86ccSJason Yan #else
1322b0e86ccSJason Yan static inline void kaslr_early_init(void *dt_ptr, phys_addr_t size) {}
133b3960972SJason Yan static inline void kaslr_late_init(void) {}
1342b0e86ccSJason Yan #endif
1352b0e86ccSJason Yan 
13678f62237SKumar Gala struct tlbcam {
13778f62237SKumar Gala 	u32	MAS0;
13878f62237SKumar Gala 	u32	MAS1;
13978f62237SKumar Gala 	unsigned long	MAS2;
14078f62237SKumar Gala 	u32	MAS3;
14178f62237SKumar Gala 	u32	MAS7;
14278f62237SKumar Gala };
14387ccc668SChristophe Leroy 
14487ccc668SChristophe Leroy #define NUM_TLBCAMS	64
14587ccc668SChristophe Leroy 
14687ccc668SChristophe Leroy extern struct tlbcam TLBCAM[NUM_TLBCAMS];
14714cf11afSPaul Mackerras #endif
1483084cdb7SChristophe Leroy 
149dfc3095cSChristophe Leroy #if defined(CONFIG_PPC_BOOK3S_32) || defined(CONFIG_PPC_85xx) || defined(CONFIG_PPC_8xx)
1503084cdb7SChristophe Leroy /* 6xx have BATS */
151dfc3095cSChristophe Leroy /* PPC_85xx have TLBCAM */
1524badd43aSChristophe Leroy /* 8xx have LTLB */
1533084cdb7SChristophe Leroy phys_addr_t v_block_mapped(unsigned long va);
1543084cdb7SChristophe Leroy unsigned long p_block_mapped(phys_addr_t pa);
1553084cdb7SChristophe Leroy #else
1563084cdb7SChristophe Leroy static inline phys_addr_t v_block_mapped(unsigned long va) { return 0; }
1573084cdb7SChristophe Leroy static inline unsigned long p_block_mapped(phys_addr_t pa) { return 0; }
1583084cdb7SChristophe Leroy #endif
15963b2bc61SChristophe Leroy 
160d5970045SChristophe Leroy #if defined(CONFIG_PPC_BOOK3S_32) || defined(CONFIG_PPC_8xx) || defined(CONFIG_PPC_FSL_BOOK3E)
16163b2bc61SChristophe Leroy void mmu_mark_initmem_nx(void);
16263b2bc61SChristophe Leroy void mmu_mark_rodata_ro(void);
16363b2bc61SChristophe Leroy #else
16463b2bc61SChristophe Leroy static inline void mmu_mark_initmem_nx(void) { }
16563b2bc61SChristophe Leroy static inline void mmu_mark_rodata_ro(void) { }
16663b2bc61SChristophe Leroy #endif
1671e1c8b2cSChristophe Leroy 
168136a9a0fSChristophe Leroy #ifdef CONFIG_PPC_8xx
169136a9a0fSChristophe Leroy void __init mmu_mapin_immr(void);
170136a9a0fSChristophe Leroy #endif
171136a9a0fSChristophe Leroy 
172e0847283SChristophe Leroy #ifdef CONFIG_DEBUG_WX
1731e1c8b2cSChristophe Leroy void ptdump_check_wx(void);
1741e1c8b2cSChristophe Leroy #else
1751e1c8b2cSChristophe Leroy static inline void ptdump_check_wx(void) { }
1761e1c8b2cSChristophe Leroy #endif
17790cbac0eSChristophe Leroy 
17890cbac0eSChristophe Leroy static inline bool debug_pagealloc_enabled_or_kfence(void)
17990cbac0eSChristophe Leroy {
18090cbac0eSChristophe Leroy 	return IS_ENABLED(CONFIG_KFENCE) || debug_pagealloc_enabled();
18190cbac0eSChristophe Leroy }
182