14f04d8f0SCatalin Marinas /* 24f04d8f0SCatalin Marinas * Copyright (C) 2012 ARM Ltd. 34f04d8f0SCatalin Marinas * 44f04d8f0SCatalin Marinas * This program is free software; you can redistribute it and/or modify 54f04d8f0SCatalin Marinas * it under the terms of the GNU General Public License version 2 as 64f04d8f0SCatalin Marinas * published by the Free Software Foundation. 74f04d8f0SCatalin Marinas * 84f04d8f0SCatalin Marinas * This program is distributed in the hope that it will be useful, 94f04d8f0SCatalin Marinas * but WITHOUT ANY WARRANTY; without even the implied warranty of 104f04d8f0SCatalin Marinas * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 114f04d8f0SCatalin Marinas * GNU General Public License for more details. 124f04d8f0SCatalin Marinas * 134f04d8f0SCatalin Marinas * You should have received a copy of the GNU General Public License 144f04d8f0SCatalin Marinas * along with this program. If not, see <http://www.gnu.org/licenses/>. 154f04d8f0SCatalin Marinas */ 164f04d8f0SCatalin Marinas #ifndef __ASM_MMU_H 174f04d8f0SCatalin Marinas #define __ASM_MMU_H 184f04d8f0SCatalin Marinas 195ce93ab6SYury Norov #define MMCF_AARCH32 0x1 /* mm context flag for AArch32 executables */ 2079e9aa59SJames Morse #define USER_ASID_BIT 48 2179e9aa59SJames Morse #define USER_ASID_FLAG (UL(1) << USER_ASID_BIT) 22b519538dSWill Deacon #define TTBR_ASID_MASK (UL(0xffff) << 48) 235ce93ab6SYury Norov 244205a89bSMarc Zyngier #define BP_HARDEN_EL2_SLOTS 4 254205a89bSMarc Zyngier 26fc0e1299SWill Deacon #ifndef __ASSEMBLY__ 27fc0e1299SWill Deacon 284f04d8f0SCatalin Marinas typedef struct { 295aec715dSWill Deacon atomic64_t id; 304f04d8f0SCatalin Marinas void *vdso; 3106beb72fSPratyush Anand unsigned long flags; 324f04d8f0SCatalin Marinas } mm_context_t; 334f04d8f0SCatalin Marinas 345aec715dSWill Deacon /* 355aec715dSWill Deacon * This macro is only used by the TLBI code, which cannot race with an 365aec715dSWill Deacon * ASID change and therefore doesn't need to reload the counter using 375aec715dSWill Deacon * atomic64_read. 385aec715dSWill Deacon */ 395aec715dSWill Deacon #define ASID(mm) ((mm)->context.id.counter & 0xffff) 404f04d8f0SCatalin Marinas 41fc0e1299SWill Deacon static inline bool arm64_kernel_unmapped_at_el0(void) 42fc0e1299SWill Deacon { 43ea1e3de8SWill Deacon return IS_ENABLED(CONFIG_UNMAP_KERNEL_AT_EL0) && 44ea1e3de8SWill Deacon cpus_have_const_cap(ARM64_UNMAP_KERNEL_AT_EL0); 45fc0e1299SWill Deacon } 46fc0e1299SWill Deacon 470f15adbbSWill Deacon typedef void (*bp_hardening_cb_t)(void); 480f15adbbSWill Deacon 490f15adbbSWill Deacon struct bp_hardening_data { 500f15adbbSWill Deacon int hyp_vectors_slot; 510f15adbbSWill Deacon bp_hardening_cb_t fn; 520f15adbbSWill Deacon }; 530f15adbbSWill Deacon 54*dee39247SMarc Zyngier #if (defined(CONFIG_HARDEN_BRANCH_PREDICTOR) || \ 55*dee39247SMarc Zyngier defined(CONFIG_HARDEN_EL2_VECTORS)) 560f15adbbSWill Deacon extern char __bp_harden_hyp_vecs_start[], __bp_harden_hyp_vecs_end[]; 574205a89bSMarc Zyngier extern atomic_t arm64_el2_vector_last_slot; 58*dee39247SMarc Zyngier #endif /* CONFIG_HARDEN_BRANCH_PREDICTOR || CONFIG_HARDEN_EL2_VECTORS */ 590f15adbbSWill Deacon 60*dee39247SMarc Zyngier #ifdef CONFIG_HARDEN_BRANCH_PREDICTOR 610f15adbbSWill Deacon DECLARE_PER_CPU_READ_MOSTLY(struct bp_hardening_data, bp_hardening_data); 620f15adbbSWill Deacon 630f15adbbSWill Deacon static inline struct bp_hardening_data *arm64_get_bp_hardening_data(void) 640f15adbbSWill Deacon { 650f15adbbSWill Deacon return this_cpu_ptr(&bp_hardening_data); 660f15adbbSWill Deacon } 670f15adbbSWill Deacon 680f15adbbSWill Deacon static inline void arm64_apply_bp_hardening(void) 690f15adbbSWill Deacon { 700f15adbbSWill Deacon struct bp_hardening_data *d; 710f15adbbSWill Deacon 720f15adbbSWill Deacon if (!cpus_have_const_cap(ARM64_HARDEN_BRANCH_PREDICTOR)) 730f15adbbSWill Deacon return; 740f15adbbSWill Deacon 750f15adbbSWill Deacon d = arm64_get_bp_hardening_data(); 760f15adbbSWill Deacon if (d->fn) 770f15adbbSWill Deacon d->fn(); 780f15adbbSWill Deacon } 790f15adbbSWill Deacon #else 800f15adbbSWill Deacon static inline struct bp_hardening_data *arm64_get_bp_hardening_data(void) 810f15adbbSWill Deacon { 820f15adbbSWill Deacon return NULL; 830f15adbbSWill Deacon } 840f15adbbSWill Deacon 850f15adbbSWill Deacon static inline void arm64_apply_bp_hardening(void) { } 860f15adbbSWill Deacon #endif /* CONFIG_HARDEN_BRANCH_PREDICTOR */ 870f15adbbSWill Deacon 884f04d8f0SCatalin Marinas extern void paging_init(void); 893194ac6eSDavid Daney extern void bootmem_init(void); 902475ff9dSCatalin Marinas extern void __iomem *early_io_map(phys_addr_t phys, unsigned long virt); 910bf757c7SMark Salter extern void init_mem_pgprot(void); 928ce837ceSArd Biesheuvel extern void create_pgd_mapping(struct mm_struct *mm, phys_addr_t phys, 938ce837ceSArd Biesheuvel unsigned long virt, phys_addr_t size, 94f14c66ceSArd Biesheuvel pgprot_t prot, bool page_mappings_only); 9561bd93ceSArd Biesheuvel extern void *fixmap_remap_fdt(phys_addr_t dt_phys); 965ea5306cSArd Biesheuvel extern void mark_linear_text_alias_ro(void); 974f04d8f0SCatalin Marinas 98fc0e1299SWill Deacon #endif /* !__ASSEMBLY__ */ 994f04d8f0SCatalin Marinas #endif 100