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 16*6e52aab9SMark Brown #define __BP_HARDEN_HYP_VECS_SZ (BP_HARDEN_EL2_SLOTS * SZ_2K) 174205a89bSMarc Zyngier 18fc0e1299SWill Deacon #ifndef __ASSEMBLY__ 19fc0e1299SWill Deacon 204f04d8f0SCatalin Marinas typedef struct { 215aec715dSWill Deacon atomic64_t id; 224f04d8f0SCatalin Marinas void *vdso; 2306beb72fSPratyush Anand unsigned long flags; 244f04d8f0SCatalin Marinas } mm_context_t; 254f04d8f0SCatalin Marinas 265aec715dSWill Deacon /* 275aec715dSWill Deacon * This macro is only used by the TLBI code, which cannot race with an 285aec715dSWill Deacon * ASID change and therefore doesn't need to reload the counter using 295aec715dSWill Deacon * atomic64_read. 305aec715dSWill Deacon */ 315aec715dSWill Deacon #define ASID(mm) ((mm)->context.id.counter & 0xffff) 324f04d8f0SCatalin Marinas 3309e3c22aSMark Brown extern bool arm64_use_ng_mappings; 3409e3c22aSMark Brown 35fc0e1299SWill Deacon static inline bool arm64_kernel_unmapped_at_el0(void) 36fc0e1299SWill Deacon { 3709e3c22aSMark Brown return arm64_use_ng_mappings; 38b89d82efSWill Deacon } 39b89d82efSWill Deacon 400f15adbbSWill Deacon typedef void (*bp_hardening_cb_t)(void); 410f15adbbSWill Deacon 420f15adbbSWill Deacon struct bp_hardening_data { 430f15adbbSWill Deacon int hyp_vectors_slot; 440f15adbbSWill Deacon bp_hardening_cb_t fn; 450f15adbbSWill Deacon }; 460f15adbbSWill Deacon 47dee39247SMarc Zyngier #if (defined(CONFIG_HARDEN_BRANCH_PREDICTOR) || \ 48dee39247SMarc Zyngier defined(CONFIG_HARDEN_EL2_VECTORS)) 49*6e52aab9SMark Brown 50*6e52aab9SMark Brown extern char __bp_harden_hyp_vecs[]; 514205a89bSMarc Zyngier extern atomic_t arm64_el2_vector_last_slot; 52dee39247SMarc Zyngier #endif /* CONFIG_HARDEN_BRANCH_PREDICTOR || CONFIG_HARDEN_EL2_VECTORS */ 530f15adbbSWill Deacon 54dee39247SMarc Zyngier #ifdef CONFIG_HARDEN_BRANCH_PREDICTOR 550f15adbbSWill Deacon DECLARE_PER_CPU_READ_MOSTLY(struct bp_hardening_data, bp_hardening_data); 560f15adbbSWill Deacon 570f15adbbSWill Deacon static inline struct bp_hardening_data *arm64_get_bp_hardening_data(void) 580f15adbbSWill Deacon { 590f15adbbSWill Deacon return this_cpu_ptr(&bp_hardening_data); 600f15adbbSWill Deacon } 610f15adbbSWill Deacon 620f15adbbSWill Deacon static inline void arm64_apply_bp_hardening(void) 630f15adbbSWill Deacon { 640f15adbbSWill Deacon struct bp_hardening_data *d; 650f15adbbSWill Deacon 660f15adbbSWill Deacon if (!cpus_have_const_cap(ARM64_HARDEN_BRANCH_PREDICTOR)) 670f15adbbSWill Deacon return; 680f15adbbSWill Deacon 690f15adbbSWill Deacon d = arm64_get_bp_hardening_data(); 700f15adbbSWill Deacon if (d->fn) 710f15adbbSWill Deacon d->fn(); 720f15adbbSWill Deacon } 730f15adbbSWill Deacon #else 740f15adbbSWill Deacon static inline struct bp_hardening_data *arm64_get_bp_hardening_data(void) 750f15adbbSWill Deacon { 760f15adbbSWill Deacon return NULL; 770f15adbbSWill Deacon } 780f15adbbSWill Deacon 790f15adbbSWill Deacon static inline void arm64_apply_bp_hardening(void) { } 800f15adbbSWill Deacon #endif /* CONFIG_HARDEN_BRANCH_PREDICTOR */ 810f15adbbSWill Deacon 8283504032SWill Deacon extern void arm64_memblock_init(void); 834f04d8f0SCatalin Marinas extern void paging_init(void); 843194ac6eSDavid Daney extern void bootmem_init(void); 852475ff9dSCatalin Marinas extern void __iomem *early_io_map(phys_addr_t phys, unsigned long virt); 860bf757c7SMark Salter extern void init_mem_pgprot(void); 878ce837ceSArd Biesheuvel extern void create_pgd_mapping(struct mm_struct *mm, phys_addr_t phys, 888ce837ceSArd Biesheuvel unsigned long virt, phys_addr_t size, 89f14c66ceSArd Biesheuvel pgprot_t prot, bool page_mappings_only); 90e112b032SHsin-Yi Wang extern void *fixmap_remap_fdt(phys_addr_t dt_phys, int *size, pgprot_t prot); 915ea5306cSArd Biesheuvel extern void mark_linear_text_alias_ro(void); 9209e3c22aSMark Brown extern bool kaslr_requires_kpti(void); 934f04d8f0SCatalin Marinas 942b5548b6SJun Yao #define INIT_MM_CONTEXT(name) \ 952b5548b6SJun Yao .pgd = init_pg_dir, 962b5548b6SJun Yao 97fc0e1299SWill Deacon #endif /* !__ASSEMBLY__ */ 984f04d8f0SCatalin Marinas #endif 99