162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Declarations of procedures and variables shared between files 462306a36Sopenharmony_ci * in arch/ppc/mm/. 562306a36Sopenharmony_ci * 662306a36Sopenharmony_ci * Derived from arch/ppc/mm/init.c: 762306a36Sopenharmony_ci * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org) 862306a36Sopenharmony_ci * 962306a36Sopenharmony_ci * Modifications by Paul Mackerras (PowerMac) (paulus@cs.anu.edu.au) 1062306a36Sopenharmony_ci * and Cort Dougan (PReP) (cort@cs.nmt.edu) 1162306a36Sopenharmony_ci * Copyright (C) 1996 Paul Mackerras 1262306a36Sopenharmony_ci * 1362306a36Sopenharmony_ci * Derived from "arch/i386/mm/init.c" 1462306a36Sopenharmony_ci * Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds 1562306a36Sopenharmony_ci */ 1662306a36Sopenharmony_ci#include <linux/mm.h> 1762306a36Sopenharmony_ci#include <asm/mmu.h> 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_ci#ifdef CONFIG_PPC_MMU_NOHASH 2062306a36Sopenharmony_ci#include <asm/trace.h> 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ci/* 2362306a36Sopenharmony_ci * On 40x and 8xx, we directly inline tlbia and tlbivax 2462306a36Sopenharmony_ci */ 2562306a36Sopenharmony_ci#if defined(CONFIG_40x) || defined(CONFIG_PPC_8xx) 2662306a36Sopenharmony_cistatic inline void _tlbil_all(void) 2762306a36Sopenharmony_ci{ 2862306a36Sopenharmony_ci asm volatile ("sync; tlbia; isync" : : : "memory"); 2962306a36Sopenharmony_ci trace_tlbia(MMU_NO_CONTEXT); 3062306a36Sopenharmony_ci} 3162306a36Sopenharmony_cistatic inline void _tlbil_pid(unsigned int pid) 3262306a36Sopenharmony_ci{ 3362306a36Sopenharmony_ci asm volatile ("sync; tlbia; isync" : : : "memory"); 3462306a36Sopenharmony_ci trace_tlbia(pid); 3562306a36Sopenharmony_ci} 3662306a36Sopenharmony_ci#define _tlbil_pid_noind(pid) _tlbil_pid(pid) 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ci#else /* CONFIG_40x || CONFIG_PPC_8xx */ 3962306a36Sopenharmony_ciextern void _tlbil_all(void); 4062306a36Sopenharmony_ciextern void _tlbil_pid(unsigned int pid); 4162306a36Sopenharmony_ci#ifdef CONFIG_PPC_BOOK3E_64 4262306a36Sopenharmony_ciextern void _tlbil_pid_noind(unsigned int pid); 4362306a36Sopenharmony_ci#else 4462306a36Sopenharmony_ci#define _tlbil_pid_noind(pid) _tlbil_pid(pid) 4562306a36Sopenharmony_ci#endif 4662306a36Sopenharmony_ci#endif /* !(CONFIG_40x || CONFIG_PPC_8xx) */ 4762306a36Sopenharmony_ci 4862306a36Sopenharmony_ci/* 4962306a36Sopenharmony_ci * On 8xx, we directly inline tlbie, on others, it's extern 5062306a36Sopenharmony_ci */ 5162306a36Sopenharmony_ci#ifdef CONFIG_PPC_8xx 5262306a36Sopenharmony_cistatic inline void _tlbil_va(unsigned long address, unsigned int pid, 5362306a36Sopenharmony_ci unsigned int tsize, unsigned int ind) 5462306a36Sopenharmony_ci{ 5562306a36Sopenharmony_ci asm volatile ("tlbie %0; sync" : : "r" (address) : "memory"); 5662306a36Sopenharmony_ci trace_tlbie(0, 0, address, pid, 0, 0, 0); 5762306a36Sopenharmony_ci} 5862306a36Sopenharmony_ci#elif defined(CONFIG_PPC_BOOK3E_64) 5962306a36Sopenharmony_ciextern void _tlbil_va(unsigned long address, unsigned int pid, 6062306a36Sopenharmony_ci unsigned int tsize, unsigned int ind); 6162306a36Sopenharmony_ci#else 6262306a36Sopenharmony_ciextern void __tlbil_va(unsigned long address, unsigned int pid); 6362306a36Sopenharmony_cistatic inline void _tlbil_va(unsigned long address, unsigned int pid, 6462306a36Sopenharmony_ci unsigned int tsize, unsigned int ind) 6562306a36Sopenharmony_ci{ 6662306a36Sopenharmony_ci __tlbil_va(address, pid); 6762306a36Sopenharmony_ci} 6862306a36Sopenharmony_ci#endif /* CONFIG_PPC_8xx */ 6962306a36Sopenharmony_ci 7062306a36Sopenharmony_ci#if defined(CONFIG_PPC_BOOK3E_64) || defined(CONFIG_PPC_47x) 7162306a36Sopenharmony_ciextern void _tlbivax_bcast(unsigned long address, unsigned int pid, 7262306a36Sopenharmony_ci unsigned int tsize, unsigned int ind); 7362306a36Sopenharmony_ci#else 7462306a36Sopenharmony_cistatic inline void _tlbivax_bcast(unsigned long address, unsigned int pid, 7562306a36Sopenharmony_ci unsigned int tsize, unsigned int ind) 7662306a36Sopenharmony_ci{ 7762306a36Sopenharmony_ci BUG(); 7862306a36Sopenharmony_ci} 7962306a36Sopenharmony_ci#endif 8062306a36Sopenharmony_ci 8162306a36Sopenharmony_cistatic inline void print_system_hash_info(void) {} 8262306a36Sopenharmony_ci 8362306a36Sopenharmony_ci#else /* CONFIG_PPC_MMU_NOHASH */ 8462306a36Sopenharmony_ci 8562306a36Sopenharmony_civoid print_system_hash_info(void); 8662306a36Sopenharmony_ci 8762306a36Sopenharmony_ci#endif /* CONFIG_PPC_MMU_NOHASH */ 8862306a36Sopenharmony_ci 8962306a36Sopenharmony_ci#ifdef CONFIG_PPC32 9062306a36Sopenharmony_ci 9162306a36Sopenharmony_ciextern void mapin_ram(void); 9262306a36Sopenharmony_ciextern void setbat(int index, unsigned long virt, phys_addr_t phys, 9362306a36Sopenharmony_ci unsigned int size, pgprot_t prot); 9462306a36Sopenharmony_ci 9562306a36Sopenharmony_ciextern u8 early_hash[]; 9662306a36Sopenharmony_ci 9762306a36Sopenharmony_ci#endif /* CONFIG_PPC32 */ 9862306a36Sopenharmony_ci 9962306a36Sopenharmony_ciextern unsigned long __max_low_memory; 10062306a36Sopenharmony_ciextern phys_addr_t total_memory; 10162306a36Sopenharmony_ciextern phys_addr_t total_lowmem; 10262306a36Sopenharmony_ciextern phys_addr_t memstart_addr; 10362306a36Sopenharmony_ciextern phys_addr_t lowmem_end_addr; 10462306a36Sopenharmony_ci 10562306a36Sopenharmony_ci/* ...and now those things that may be slightly different between processor 10662306a36Sopenharmony_ci * architectures. -- Dan 10762306a36Sopenharmony_ci */ 10862306a36Sopenharmony_ci#ifdef CONFIG_PPC32 10962306a36Sopenharmony_ciextern void MMU_init_hw(void); 11062306a36Sopenharmony_civoid MMU_init_hw_patch(void); 11162306a36Sopenharmony_ciunsigned long mmu_mapin_ram(unsigned long base, unsigned long top); 11262306a36Sopenharmony_ci#endif 11362306a36Sopenharmony_civoid mmu_init_secondary(int cpu); 11462306a36Sopenharmony_ci 11562306a36Sopenharmony_ci#ifdef CONFIG_PPC_E500 11662306a36Sopenharmony_ciextern unsigned long map_mem_in_cams(unsigned long ram, int max_cam_idx, 11762306a36Sopenharmony_ci bool dryrun, bool init); 11862306a36Sopenharmony_ci#ifdef CONFIG_PPC32 11962306a36Sopenharmony_ciextern void adjust_total_lowmem(void); 12062306a36Sopenharmony_ciextern int switch_to_as1(void); 12162306a36Sopenharmony_ciextern void restore_to_as0(int esel, int offset, void *dt_ptr, int bootcpu); 12262306a36Sopenharmony_civoid create_kaslr_tlb_entry(int entry, unsigned long virt, phys_addr_t phys); 12362306a36Sopenharmony_civoid reloc_kernel_entry(void *fdt, int addr); 12462306a36Sopenharmony_civoid relocate_init(u64 dt_ptr, phys_addr_t start); 12562306a36Sopenharmony_ciextern int is_second_reloc; 12662306a36Sopenharmony_ci#endif 12762306a36Sopenharmony_ciextern void loadcam_entry(unsigned int index); 12862306a36Sopenharmony_ciextern void loadcam_multi(int first_idx, int num, int tmp_idx); 12962306a36Sopenharmony_ci 13062306a36Sopenharmony_ci#ifdef CONFIG_RANDOMIZE_BASE 13162306a36Sopenharmony_civoid kaslr_early_init(void *dt_ptr, phys_addr_t size); 13262306a36Sopenharmony_civoid kaslr_late_init(void); 13362306a36Sopenharmony_ci#else 13462306a36Sopenharmony_cistatic inline void kaslr_early_init(void *dt_ptr, phys_addr_t size) {} 13562306a36Sopenharmony_cistatic inline void kaslr_late_init(void) {} 13662306a36Sopenharmony_ci#endif 13762306a36Sopenharmony_ci 13862306a36Sopenharmony_cistruct tlbcam { 13962306a36Sopenharmony_ci u32 MAS0; 14062306a36Sopenharmony_ci u32 MAS1; 14162306a36Sopenharmony_ci unsigned long MAS2; 14262306a36Sopenharmony_ci u32 MAS3; 14362306a36Sopenharmony_ci u32 MAS7; 14462306a36Sopenharmony_ci}; 14562306a36Sopenharmony_ci 14662306a36Sopenharmony_ci#define NUM_TLBCAMS 64 14762306a36Sopenharmony_ci 14862306a36Sopenharmony_ciextern struct tlbcam TLBCAM[NUM_TLBCAMS]; 14962306a36Sopenharmony_ci#endif 15062306a36Sopenharmony_ci 15162306a36Sopenharmony_ci#if defined(CONFIG_PPC_BOOK3S_32) || defined(CONFIG_PPC_85xx) || defined(CONFIG_PPC_8xx) 15262306a36Sopenharmony_ci/* 6xx have BATS */ 15362306a36Sopenharmony_ci/* PPC_85xx have TLBCAM */ 15462306a36Sopenharmony_ci/* 8xx have LTLB */ 15562306a36Sopenharmony_ciphys_addr_t v_block_mapped(unsigned long va); 15662306a36Sopenharmony_ciunsigned long p_block_mapped(phys_addr_t pa); 15762306a36Sopenharmony_ci#else 15862306a36Sopenharmony_cistatic inline phys_addr_t v_block_mapped(unsigned long va) { return 0; } 15962306a36Sopenharmony_cistatic inline unsigned long p_block_mapped(phys_addr_t pa) { return 0; } 16062306a36Sopenharmony_ci#endif 16162306a36Sopenharmony_ci 16262306a36Sopenharmony_ci#if defined(CONFIG_PPC_BOOK3S_32) || defined(CONFIG_PPC_8xx) || defined(CONFIG_PPC_E500) 16362306a36Sopenharmony_civoid mmu_mark_initmem_nx(void); 16462306a36Sopenharmony_civoid mmu_mark_rodata_ro(void); 16562306a36Sopenharmony_ci#else 16662306a36Sopenharmony_cistatic inline void mmu_mark_initmem_nx(void) { } 16762306a36Sopenharmony_cistatic inline void mmu_mark_rodata_ro(void) { } 16862306a36Sopenharmony_ci#endif 16962306a36Sopenharmony_ci 17062306a36Sopenharmony_ci#ifdef CONFIG_PPC_8xx 17162306a36Sopenharmony_civoid __init mmu_mapin_immr(void); 17262306a36Sopenharmony_ci#endif 17362306a36Sopenharmony_ci 17462306a36Sopenharmony_ci#ifdef CONFIG_DEBUG_WX 17562306a36Sopenharmony_civoid ptdump_check_wx(void); 17662306a36Sopenharmony_ci#else 17762306a36Sopenharmony_cistatic inline void ptdump_check_wx(void) { } 17862306a36Sopenharmony_ci#endif 17962306a36Sopenharmony_ci 18062306a36Sopenharmony_cistatic inline bool debug_pagealloc_enabled_or_kfence(void) 18162306a36Sopenharmony_ci{ 18262306a36Sopenharmony_ci return IS_ENABLED(CONFIG_KFENCE) || debug_pagealloc_enabled(); 18362306a36Sopenharmony_ci} 18462306a36Sopenharmony_ci 18562306a36Sopenharmony_ci#ifdef CONFIG_MEMORY_HOTPLUG 18662306a36Sopenharmony_ciint create_section_mapping(unsigned long start, unsigned long end, 18762306a36Sopenharmony_ci int nid, pgprot_t prot); 18862306a36Sopenharmony_ci#endif 189