xref: /openbmc/linux/arch/arm64/include/asm/mmu.h (revision 83f865d7)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (C) 2012 ARM Ltd.
4  */
5 #ifndef __ASM_MMU_H
6 #define __ASM_MMU_H
7 
8 #include <asm/cputype.h>
9 
10 #define MMCF_AARCH32	0x1	/* mm context flag for AArch32 executables */
11 #define USER_ASID_BIT	48
12 #define USER_ASID_FLAG	(UL(1) << USER_ASID_BIT)
13 #define TTBR_ASID_MASK	(UL(0xffff) << 48)
14 
15 #define BP_HARDEN_EL2_SLOTS 4
16 #define __BP_HARDEN_HYP_VECS_SZ (BP_HARDEN_EL2_SLOTS * SZ_2K)
17 
18 #ifndef __ASSEMBLY__
19 
20 #include <linux/refcount.h>
21 
22 typedef struct {
23 	atomic64_t	id;
24 #ifdef CONFIG_COMPAT
25 	void		*sigpage;
26 #endif
27 	refcount_t	pinned;
28 	void		*vdso;
29 	unsigned long	flags;
30 } mm_context_t;
31 
32 /*
33  * This macro is only used by the TLBI and low-level switch_mm() code,
34  * neither of which can race with an ASID change. We therefore don't
35  * need to reload the counter using atomic64_read().
36  */
37 #define ASID(mm)	((mm)->context.id.counter & 0xffff)
38 
39 static inline bool arm64_kernel_unmapped_at_el0(void)
40 {
41 	return cpus_have_const_cap(ARM64_UNMAP_KERNEL_AT_EL0);
42 }
43 
44 typedef void (*bp_hardening_cb_t)(void);
45 
46 struct bp_hardening_data {
47 	int			hyp_vectors_slot;
48 	bp_hardening_cb_t	fn;
49 };
50 
51 DECLARE_PER_CPU_READ_MOSTLY(struct bp_hardening_data, bp_hardening_data);
52 
53 static inline struct bp_hardening_data *arm64_get_bp_hardening_data(void)
54 {
55 	return this_cpu_ptr(&bp_hardening_data);
56 }
57 
58 static inline void arm64_apply_bp_hardening(void)
59 {
60 	struct bp_hardening_data *d;
61 
62 	if (!cpus_have_const_cap(ARM64_SPECTRE_V2))
63 		return;
64 
65 	d = arm64_get_bp_hardening_data();
66 	if (d->fn)
67 		d->fn();
68 }
69 
70 extern void arm64_memblock_init(void);
71 extern void paging_init(void);
72 extern void bootmem_init(void);
73 extern void __iomem *early_io_map(phys_addr_t phys, unsigned long virt);
74 extern void init_mem_pgprot(void);
75 extern void create_pgd_mapping(struct mm_struct *mm, phys_addr_t phys,
76 			       unsigned long virt, phys_addr_t size,
77 			       pgprot_t prot, bool page_mappings_only);
78 extern void *fixmap_remap_fdt(phys_addr_t dt_phys, int *size, pgprot_t prot);
79 extern void mark_linear_text_alias_ro(void);
80 extern bool kaslr_requires_kpti(void);
81 
82 #define INIT_MM_CONTEXT(name)	\
83 	.pgd = init_pg_dir,
84 
85 #endif	/* !__ASSEMBLY__ */
86 #endif
87