17bb01fb2SAntonio Nino Diaz /* 2883d1b5dSAntonio Nino Diaz * Copyright (c) 2014-2018, ARM Limited and Contributors. All rights reserved. 37bb01fb2SAntonio Nino Diaz * 482cb2c1aSdp-arm * SPDX-License-Identifier: BSD-3-Clause 57bb01fb2SAntonio Nino Diaz */ 67bb01fb2SAntonio Nino Diaz 7e7b9886cSAntonio Nino Diaz #ifndef XLAT_MMU_HELPERS_H 8e7b9886cSAntonio Nino Diaz #define XLAT_MMU_HELPERS_H 97bb01fb2SAntonio Nino Diaz 10883d1b5dSAntonio Nino Diaz /* 11883d1b5dSAntonio Nino Diaz * The following flags are passed to enable_mmu_xxx() to override the default 12883d1b5dSAntonio Nino Diaz * values used to program system registers while enabling the MMU. 13883d1b5dSAntonio Nino Diaz */ 14883d1b5dSAntonio Nino Diaz 15883d1b5dSAntonio Nino Diaz /* 16883d1b5dSAntonio Nino Diaz * When this flag is used, all data access to Normal memory from this EL and all 17883d1b5dSAntonio Nino Diaz * Normal memory accesses to the translation tables of this EL are non-cacheable 18883d1b5dSAntonio Nino Diaz * for all levels of data and unified cache until the caches are enabled by 19883d1b5dSAntonio Nino Diaz * setting the bit SCTLR_ELx.C. 20883d1b5dSAntonio Nino Diaz */ 21883d1b5dSAntonio Nino Diaz #define DISABLE_DCACHE (U(1) << 0) 22883d1b5dSAntonio Nino Diaz 23883d1b5dSAntonio Nino Diaz /* 24883d1b5dSAntonio Nino Diaz * Mark the translation tables as non-cacheable for the MMU table walker, which 25883d1b5dSAntonio Nino Diaz * is a different observer from the PE/CPU. If the flag is not specified, the 26883d1b5dSAntonio Nino Diaz * tables are cacheable for the MMU table walker. 27883d1b5dSAntonio Nino Diaz * 28883d1b5dSAntonio Nino Diaz * Note that, as far as the PE/CPU observer is concerned, the attributes used 29883d1b5dSAntonio Nino Diaz * are the ones specified in the translation tables themselves. The MAIR 30883d1b5dSAntonio Nino Diaz * register specifies the cacheability through the field AttrIndx of the lower 31883d1b5dSAntonio Nino Diaz * attributes of the translation tables. The shareability is specified in the SH 32883d1b5dSAntonio Nino Diaz * field of the lower attributes. 33883d1b5dSAntonio Nino Diaz * 34883d1b5dSAntonio Nino Diaz * The MMU table walker uses the attributes specified in the fields ORGNn, IRGNn 35883d1b5dSAntonio Nino Diaz * and SHn of the TCR register to access the translation tables. 36883d1b5dSAntonio Nino Diaz * 37883d1b5dSAntonio Nino Diaz * The attributes specified in the TCR register and the tables can be different 38883d1b5dSAntonio Nino Diaz * as there are no checks to prevent that. Special care must be taken to ensure 39883d1b5dSAntonio Nino Diaz * that there aren't mismatches. The behaviour in that case is described in the 40883d1b5dSAntonio Nino Diaz * sections 'Mismatched memory attributes' in the ARMv8 ARM. 41883d1b5dSAntonio Nino Diaz */ 42883d1b5dSAntonio Nino Diaz #define XLAT_TABLE_NC (U(1) << 1) 43883d1b5dSAntonio Nino Diaz 4463ddbae3SAntonio Nino Diaz /* 4563ddbae3SAntonio Nino Diaz * Offsets into a mmu_cfg_params array generated by setup_mmu_cfg(). All 4663ddbae3SAntonio Nino Diaz * parameters are 64 bits wide. 4763ddbae3SAntonio Nino Diaz */ 4863ddbae3SAntonio Nino Diaz #define MMU_CFG_MAIR 0 4963ddbae3SAntonio Nino Diaz #define MMU_CFG_TCR 1 5063ddbae3SAntonio Nino Diaz #define MMU_CFG_TTBR0 2 5163ddbae3SAntonio Nino Diaz #define MMU_CFG_PARAM_MAX 3 5263ddbae3SAntonio Nino Diaz 53d5dfdeb6SJulius Werner #ifndef __ASSEMBLER__ 54883d1b5dSAntonio Nino Diaz 555b395e37SAntonio Nino Diaz #include <stdbool.h> 56e7b9886cSAntonio Nino Diaz #include <stdint.h> 5793c78ed2SAntonio Nino Diaz #include <string.h> 58a0b9bb79SAntonio Nino Diaz 5963ddbae3SAntonio Nino Diaz /* 6063ddbae3SAntonio Nino Diaz * Return the values that the MMU configuration registers must contain for the 6163ddbae3SAntonio Nino Diaz * specified translation context. `params` must be a pointer to array of size 6263ddbae3SAntonio Nino Diaz * MMU_CFG_PARAM_MAX. 6363ddbae3SAntonio Nino Diaz */ 6463ddbae3SAntonio Nino Diaz void setup_mmu_cfg(uint64_t *params, unsigned int flags, 6563ddbae3SAntonio Nino Diaz const uint64_t *base_table, unsigned long long max_pa, 6663ddbae3SAntonio Nino Diaz uintptr_t max_va, int xlat_regime); 6763ddbae3SAntonio Nino Diaz 68*402b3cf8SJulius Werner #ifdef __aarch64__ 697bb01fb2SAntonio Nino Diaz /* AArch64 specific translation table APIs */ 707bb01fb2SAntonio Nino Diaz void enable_mmu_el1(unsigned int flags); 711a92a0e0SAntonio Nino Diaz void enable_mmu_el2(unsigned int flags); 727bb01fb2SAntonio Nino Diaz void enable_mmu_el3(unsigned int flags); 730cc7aa89SJeenu Viswambharan 740cc7aa89SJeenu Viswambharan void enable_mmu_direct_el1(unsigned int flags); 751a92a0e0SAntonio Nino Diaz void enable_mmu_direct_el2(unsigned int flags); 760cc7aa89SJeenu Viswambharan void enable_mmu_direct_el3(unsigned int flags); 77*402b3cf8SJulius Werner #else 78*402b3cf8SJulius Werner /* AArch32 specific translation table API */ 79*402b3cf8SJulius Werner void enable_mmu_svc_mon(unsigned int flags); 80*402b3cf8SJulius Werner void enable_mmu_hyp(unsigned int flags); 81*402b3cf8SJulius Werner 82*402b3cf8SJulius Werner void enable_mmu_direct_svc_mon(unsigned int flags); 83*402b3cf8SJulius Werner void enable_mmu_direct_hyp(unsigned int flags); 84*402b3cf8SJulius Werner #endif /* __aarch64__ */ 857bb01fb2SAntonio Nino Diaz 865b395e37SAntonio Nino Diaz bool xlat_arch_is_granule_size_supported(size_t size); 87a0b9bb79SAntonio Nino Diaz size_t xlat_arch_get_max_supported_granule_size(void); 88a0b9bb79SAntonio Nino Diaz 89d5dfdeb6SJulius Werner #endif /* __ASSEMBLER__ */ 90883d1b5dSAntonio Nino Diaz 91e7b9886cSAntonio Nino Diaz #endif /* XLAT_MMU_HELPERS_H */ 92