1*91f16700Schasinglulu /* 2*91f16700Schasinglulu * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved. 3*91f16700Schasinglulu * 4*91f16700Schasinglulu * SPDX-License-Identifier: BSD-3-Clause 5*91f16700Schasinglulu */ 6*91f16700Schasinglulu 7*91f16700Schasinglulu #include <assert.h> 8*91f16700Schasinglulu #include <stdbool.h> 9*91f16700Schasinglulu #include <stdint.h> 10*91f16700Schasinglulu 11*91f16700Schasinglulu #include "../xlat_mpu_private.h" 12*91f16700Schasinglulu #include <arch.h> 13*91f16700Schasinglulu #include <arch_features.h> 14*91f16700Schasinglulu #include <lib/cassert.h> 15*91f16700Schasinglulu #include <lib/utils_def.h> 16*91f16700Schasinglulu #include <lib/xlat_tables/xlat_tables_v2.h> 17*91f16700Schasinglulu 18*91f16700Schasinglulu #include <fvp_r_arch_helpers.h> 19*91f16700Schasinglulu 20*91f16700Schasinglulu #warning "xlat_mpu library is currently experimental and its API may change in future." 21*91f16700Schasinglulu 22*91f16700Schasinglulu #if ENABLE_ASSERTIONS 23*91f16700Schasinglulu /* 24*91f16700Schasinglulu * Return minimum virtual address space size supported by the architecture 25*91f16700Schasinglulu */ 26*91f16700Schasinglulu uintptr_t xlat_get_min_virt_addr_space_size(void) 27*91f16700Schasinglulu { 28*91f16700Schasinglulu uintptr_t ret; 29*91f16700Schasinglulu 30*91f16700Schasinglulu if (is_armv8_4_ttst_present()) { 31*91f16700Schasinglulu ret = MIN_VIRT_ADDR_SPACE_SIZE_TTST; 32*91f16700Schasinglulu } else { 33*91f16700Schasinglulu ret = MIN_VIRT_ADDR_SPACE_SIZE; 34*91f16700Schasinglulu } 35*91f16700Schasinglulu return ret; 36*91f16700Schasinglulu } 37*91f16700Schasinglulu #endif /* ENABLE_ASSERTIONS*/ 38*91f16700Schasinglulu 39*91f16700Schasinglulu bool is_mpu_enabled_ctx(const xlat_ctx_t *ctx) 40*91f16700Schasinglulu { 41*91f16700Schasinglulu if (ctx->xlat_regime == EL1_EL0_REGIME) { 42*91f16700Schasinglulu assert(xlat_arch_current_el() >= 1U); 43*91f16700Schasinglulu return (read_sctlr_el1() & SCTLR_M_BIT) != 0U; 44*91f16700Schasinglulu } else { 45*91f16700Schasinglulu assert(xlat_arch_current_el() >= 2U); 46*91f16700Schasinglulu return (read_sctlr_el2() & SCTLR_M_BIT) != 0U; 47*91f16700Schasinglulu } 48*91f16700Schasinglulu } 49*91f16700Schasinglulu 50*91f16700Schasinglulu bool is_dcache_enabled(void) 51*91f16700Schasinglulu { 52*91f16700Schasinglulu unsigned int el = get_current_el(); 53*91f16700Schasinglulu 54*91f16700Schasinglulu if (el == 1U) { 55*91f16700Schasinglulu return (read_sctlr_el1() & SCTLR_C_BIT) != 0U; 56*91f16700Schasinglulu } else { /* must be EL2 */ 57*91f16700Schasinglulu return (read_sctlr_el2() & SCTLR_C_BIT) != 0U; 58*91f16700Schasinglulu } 59*91f16700Schasinglulu } 60*91f16700Schasinglulu 61*91f16700Schasinglulu unsigned int xlat_arch_current_el(void) 62*91f16700Schasinglulu { 63*91f16700Schasinglulu unsigned int el = (unsigned int)GET_EL(read_CurrentEl()); 64*91f16700Schasinglulu 65*91f16700Schasinglulu assert(el > 0U); 66*91f16700Schasinglulu 67*91f16700Schasinglulu return el; 68*91f16700Schasinglulu } 69*91f16700Schasinglulu 70