Antonio Nino Diaz | 233c7c1 | 2017-03-08 14:40:23 +0000 | [diff] [blame] | 1 | /* |
Govindraj Raja | eee28e7 | 2023-08-01 15:52:40 -0500 | [diff] [blame] | 2 | * Copyright (c) 2014-2018, Arm Limited and Contributors. All rights reserved. |
Antonio Nino Diaz | 233c7c1 | 2017-03-08 14:40:23 +0000 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Antonio Nino Diaz | 233c7c1 | 2017-03-08 14:40:23 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
Antonio Nino Diaz | 50eb374 | 2018-07-24 10:20:53 +0100 | [diff] [blame] | 7 | #ifndef XLAT_MMU_HELPERS_H |
| 8 | #define XLAT_MMU_HELPERS_H |
Antonio Nino Diaz | 233c7c1 | 2017-03-08 14:40:23 +0000 | [diff] [blame] | 9 | |
Antonio Nino Diaz | 7c2a3ca | 2018-02-23 15:07:54 +0000 | [diff] [blame] | 10 | /* |
| 11 | * The following flags are passed to enable_mmu_xxx() to override the default |
| 12 | * values used to program system registers while enabling the MMU. |
| 13 | */ |
| 14 | |
| 15 | /* |
| 16 | * When this flag is used, all data access to Normal memory from this EL and all |
| 17 | * Normal memory accesses to the translation tables of this EL are non-cacheable |
| 18 | * for all levels of data and unified cache until the caches are enabled by |
| 19 | * setting the bit SCTLR_ELx.C. |
| 20 | */ |
| 21 | #define DISABLE_DCACHE (U(1) << 0) |
| 22 | |
| 23 | /* |
| 24 | * Mark the translation tables as non-cacheable for the MMU table walker, which |
| 25 | * is a different observer from the PE/CPU. If the flag is not specified, the |
| 26 | * tables are cacheable for the MMU table walker. |
| 27 | * |
| 28 | * Note that, as far as the PE/CPU observer is concerned, the attributes used |
| 29 | * are the ones specified in the translation tables themselves. The MAIR |
| 30 | * register specifies the cacheability through the field AttrIndx of the lower |
| 31 | * attributes of the translation tables. The shareability is specified in the SH |
| 32 | * field of the lower attributes. |
| 33 | * |
| 34 | * The MMU table walker uses the attributes specified in the fields ORGNn, IRGNn |
| 35 | * and SHn of the TCR register to access the translation tables. |
| 36 | * |
| 37 | * The attributes specified in the TCR register and the tables can be different |
| 38 | * as there are no checks to prevent that. Special care must be taken to ensure |
| 39 | * that there aren't mismatches. The behaviour in that case is described in the |
| 40 | * sections 'Mismatched memory attributes' in the ARMv8 ARM. |
| 41 | */ |
| 42 | #define XLAT_TABLE_NC (U(1) << 1) |
| 43 | |
Antonio Nino Diaz | 67f799e | 2018-07-15 16:42:01 +0100 | [diff] [blame] | 44 | /* |
| 45 | * Offsets into a mmu_cfg_params array generated by setup_mmu_cfg(). All |
| 46 | * parameters are 64 bits wide. |
| 47 | */ |
| 48 | #define MMU_CFG_MAIR 0 |
| 49 | #define MMU_CFG_TCR 1 |
| 50 | #define MMU_CFG_TTBR0 2 |
| 51 | #define MMU_CFG_PARAM_MAX 3 |
| 52 | |
Julius Werner | 53456fc | 2019-07-09 13:49:11 -0700 | [diff] [blame] | 53 | #ifndef __ASSEMBLER__ |
Antonio Nino Diaz | 7c2a3ca | 2018-02-23 15:07:54 +0000 | [diff] [blame] | 54 | |
Antonio Nino Diaz | 5c97bd1 | 2018-08-02 09:57:29 +0100 | [diff] [blame] | 55 | #include <stdbool.h> |
Antonio Nino Diaz | 50eb374 | 2018-07-24 10:20:53 +0100 | [diff] [blame] | 56 | #include <stdint.h> |
Antonio Nino Diaz | 4b32e62 | 2018-08-16 16:52:57 +0100 | [diff] [blame] | 57 | #include <string.h> |
Antonio Nino Diaz | 4413ad5 | 2018-06-11 13:40:32 +0100 | [diff] [blame] | 58 | |
Masahiro Yamada | fb10bfd | 2020-03-26 13:18:48 +0900 | [diff] [blame] | 59 | #include <arch_helpers.h> |
| 60 | |
Antonio Nino Diaz | 67f799e | 2018-07-15 16:42:01 +0100 | [diff] [blame] | 61 | /* |
| 62 | * Return the values that the MMU configuration registers must contain for the |
| 63 | * specified translation context. `params` must be a pointer to array of size |
| 64 | * MMU_CFG_PARAM_MAX. |
| 65 | */ |
| 66 | void setup_mmu_cfg(uint64_t *params, unsigned int flags, |
| 67 | const uint64_t *base_table, unsigned long long max_pa, |
| 68 | uintptr_t max_va, int xlat_regime); |
| 69 | |
Julius Werner | 8e0ef0f | 2019-07-09 14:02:43 -0700 | [diff] [blame] | 70 | #ifdef __aarch64__ |
Antonio Nino Diaz | 233c7c1 | 2017-03-08 14:40:23 +0000 | [diff] [blame] | 71 | /* AArch64 specific translation table APIs */ |
| 72 | void enable_mmu_el1(unsigned int flags); |
Antonio Nino Diaz | 128de8d | 2018-08-07 19:59:49 +0100 | [diff] [blame] | 73 | void enable_mmu_el2(unsigned int flags); |
Antonio Nino Diaz | 233c7c1 | 2017-03-08 14:40:23 +0000 | [diff] [blame] | 74 | void enable_mmu_el3(unsigned int flags); |
Masahiro Yamada | fb10bfd | 2020-03-26 13:18:48 +0900 | [diff] [blame] | 75 | void enable_mmu(unsigned int flags); |
Jeenu Viswambharan | 58e8148 | 2018-04-27 15:06:57 +0100 | [diff] [blame] | 76 | |
| 77 | void enable_mmu_direct_el1(unsigned int flags); |
Antonio Nino Diaz | 128de8d | 2018-08-07 19:59:49 +0100 | [diff] [blame] | 78 | void enable_mmu_direct_el2(unsigned int flags); |
Jeenu Viswambharan | 58e8148 | 2018-04-27 15:06:57 +0100 | [diff] [blame] | 79 | void enable_mmu_direct_el3(unsigned int flags); |
Julius Werner | 8e0ef0f | 2019-07-09 14:02:43 -0700 | [diff] [blame] | 80 | #else |
| 81 | /* AArch32 specific translation table API */ |
| 82 | void enable_mmu_svc_mon(unsigned int flags); |
| 83 | void enable_mmu_hyp(unsigned int flags); |
| 84 | |
| 85 | void enable_mmu_direct_svc_mon(unsigned int flags); |
| 86 | void enable_mmu_direct_hyp(unsigned int flags); |
| 87 | #endif /* __aarch64__ */ |
Antonio Nino Diaz | 233c7c1 | 2017-03-08 14:40:23 +0000 | [diff] [blame] | 88 | |
Antonio Nino Diaz | 5c97bd1 | 2018-08-02 09:57:29 +0100 | [diff] [blame] | 89 | bool xlat_arch_is_granule_size_supported(size_t size); |
Antonio Nino Diaz | 4413ad5 | 2018-06-11 13:40:32 +0100 | [diff] [blame] | 90 | size_t xlat_arch_get_max_supported_granule_size(void); |
| 91 | |
Julius Werner | 53456fc | 2019-07-09 13:49:11 -0700 | [diff] [blame] | 92 | #endif /* __ASSEMBLER__ */ |
Antonio Nino Diaz | 7c2a3ca | 2018-02-23 15:07:54 +0000 | [diff] [blame] | 93 | |
Antonio Nino Diaz | 50eb374 | 2018-07-24 10:20:53 +0100 | [diff] [blame] | 94 | #endif /* XLAT_MMU_HELPERS_H */ |