xref: /openbmc/linux/arch/arm64/include/asm/mmu.h (revision 48118151d8cc7a457f61d91df0c053473d4b31b1)
1caab277bSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
24f04d8f0SCatalin Marinas /*
34f04d8f0SCatalin Marinas  * Copyright (C) 2012 ARM Ltd.
44f04d8f0SCatalin Marinas  */
54f04d8f0SCatalin Marinas #ifndef __ASM_MMU_H
64f04d8f0SCatalin Marinas #define __ASM_MMU_H
74f04d8f0SCatalin Marinas 
8b89d82efSWill Deacon #include <asm/cputype.h>
9b89d82efSWill Deacon 
105ce93ab6SYury Norov #define MMCF_AARCH32	0x1	/* mm context flag for AArch32 executables */
1179e9aa59SJames Morse #define USER_ASID_BIT	48
1279e9aa59SJames Morse #define USER_ASID_FLAG	(UL(1) << USER_ASID_BIT)
13b519538dSWill Deacon #define TTBR_ASID_MASK	(UL(0xffff) << 48)
145ce93ab6SYury Norov 
154205a89bSMarc Zyngier #define BP_HARDEN_EL2_SLOTS 4
166e52aab9SMark Brown #define __BP_HARDEN_HYP_VECS_SZ (BP_HARDEN_EL2_SLOTS * SZ_2K)
174205a89bSMarc Zyngier 
18fc0e1299SWill Deacon #ifndef __ASSEMBLY__
19fc0e1299SWill Deacon 
20*48118151SJean-Philippe Brucker #include <linux/refcount.h>
21*48118151SJean-Philippe Brucker 
224f04d8f0SCatalin Marinas typedef struct {
235aec715dSWill Deacon 	atomic64_t	id;
24a39060b0SWill Deacon #ifdef CONFIG_COMPAT
25a39060b0SWill Deacon 	void		*sigpage;
26a39060b0SWill Deacon #endif
27*48118151SJean-Philippe Brucker 	refcount_t	pinned;
284f04d8f0SCatalin Marinas 	void		*vdso;
2906beb72fSPratyush Anand 	unsigned long	flags;
304f04d8f0SCatalin Marinas } mm_context_t;
314f04d8f0SCatalin Marinas 
325aec715dSWill Deacon /*
3390765f74SWill Deacon  * This macro is only used by the TLBI and low-level switch_mm() code,
3490765f74SWill Deacon  * neither of which can race with an ASID change. We therefore don't
3590765f74SWill Deacon  * need to reload the counter using atomic64_read().
365aec715dSWill Deacon  */
375aec715dSWill Deacon #define ASID(mm)	((mm)->context.id.counter & 0xffff)
384f04d8f0SCatalin Marinas 
39fc0e1299SWill Deacon static inline bool arm64_kernel_unmapped_at_el0(void)
40fc0e1299SWill Deacon {
41c8355785SWill Deacon 	return cpus_have_const_cap(ARM64_UNMAP_KERNEL_AT_EL0);
42b89d82efSWill Deacon }
43b89d82efSWill Deacon 
440f15adbbSWill Deacon typedef void (*bp_hardening_cb_t)(void);
450f15adbbSWill Deacon 
460f15adbbSWill Deacon struct bp_hardening_data {
470f15adbbSWill Deacon 	int			hyp_vectors_slot;
480f15adbbSWill Deacon 	bp_hardening_cb_t	fn;
490f15adbbSWill Deacon };
500f15adbbSWill Deacon 
51dee39247SMarc Zyngier #ifdef CONFIG_HARDEN_BRANCH_PREDICTOR
520f15adbbSWill Deacon DECLARE_PER_CPU_READ_MOSTLY(struct bp_hardening_data, bp_hardening_data);
530f15adbbSWill Deacon 
540f15adbbSWill Deacon static inline struct bp_hardening_data *arm64_get_bp_hardening_data(void)
550f15adbbSWill Deacon {
560f15adbbSWill Deacon 	return this_cpu_ptr(&bp_hardening_data);
570f15adbbSWill Deacon }
580f15adbbSWill Deacon 
590f15adbbSWill Deacon static inline void arm64_apply_bp_hardening(void)
600f15adbbSWill Deacon {
610f15adbbSWill Deacon 	struct bp_hardening_data *d;
620f15adbbSWill Deacon 
630f15adbbSWill Deacon 	if (!cpus_have_const_cap(ARM64_HARDEN_BRANCH_PREDICTOR))
640f15adbbSWill Deacon 		return;
650f15adbbSWill Deacon 
660f15adbbSWill Deacon 	d = arm64_get_bp_hardening_data();
670f15adbbSWill Deacon 	if (d->fn)
680f15adbbSWill Deacon 		d->fn();
690f15adbbSWill Deacon }
700f15adbbSWill Deacon #else
710f15adbbSWill Deacon static inline struct bp_hardening_data *arm64_get_bp_hardening_data(void)
720f15adbbSWill Deacon {
730f15adbbSWill Deacon 	return NULL;
740f15adbbSWill Deacon }
750f15adbbSWill Deacon 
760f15adbbSWill Deacon static inline void arm64_apply_bp_hardening(void)	{ }
770f15adbbSWill Deacon #endif	/* CONFIG_HARDEN_BRANCH_PREDICTOR */
780f15adbbSWill Deacon 
7983504032SWill Deacon extern void arm64_memblock_init(void);
804f04d8f0SCatalin Marinas extern void paging_init(void);
813194ac6eSDavid Daney extern void bootmem_init(void);
822475ff9dSCatalin Marinas extern void __iomem *early_io_map(phys_addr_t phys, unsigned long virt);
830bf757c7SMark Salter extern void init_mem_pgprot(void);
848ce837ceSArd Biesheuvel extern void create_pgd_mapping(struct mm_struct *mm, phys_addr_t phys,
858ce837ceSArd Biesheuvel 			       unsigned long virt, phys_addr_t size,
86f14c66ceSArd Biesheuvel 			       pgprot_t prot, bool page_mappings_only);
87e112b032SHsin-Yi Wang extern void *fixmap_remap_fdt(phys_addr_t dt_phys, int *size, pgprot_t prot);
885ea5306cSArd Biesheuvel extern void mark_linear_text_alias_ro(void);
8909e3c22aSMark Brown extern bool kaslr_requires_kpti(void);
904f04d8f0SCatalin Marinas 
912b5548b6SJun Yao #define INIT_MM_CONTEXT(name)	\
922b5548b6SJun Yao 	.pgd = init_pg_dir,
932b5548b6SJun Yao 
94fc0e1299SWill Deacon #endif	/* !__ASSEMBLY__ */
954f04d8f0SCatalin Marinas #endif
96