13ca9928dSSoby Mathew /* 23ca9928dSSoby Mathew * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved. 33ca9928dSSoby Mathew * 43ca9928dSSoby Mathew * Redistribution and use in source and binary forms, with or without 53ca9928dSSoby Mathew * modification, are permitted provided that the following conditions are met: 63ca9928dSSoby Mathew * 73ca9928dSSoby Mathew * Redistributions of source code must retain the above copyright notice, this 83ca9928dSSoby Mathew * list of conditions and the following disclaimer. 93ca9928dSSoby Mathew * 103ca9928dSSoby Mathew * Redistributions in binary form must reproduce the above copyright notice, 113ca9928dSSoby Mathew * this list of conditions and the following disclaimer in the documentation 123ca9928dSSoby Mathew * and/or other materials provided with the distribution. 133ca9928dSSoby Mathew * 143ca9928dSSoby Mathew * Neither the name of ARM nor the names of its contributors may be used 153ca9928dSSoby Mathew * to endorse or promote products derived from this software without specific 163ca9928dSSoby Mathew * prior written permission. 173ca9928dSSoby Mathew * 183ca9928dSSoby Mathew * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 193ca9928dSSoby Mathew * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 203ca9928dSSoby Mathew * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 213ca9928dSSoby Mathew * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 223ca9928dSSoby Mathew * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 233ca9928dSSoby Mathew * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 243ca9928dSSoby Mathew * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 253ca9928dSSoby Mathew * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 263ca9928dSSoby Mathew * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 273ca9928dSSoby Mathew * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 283ca9928dSSoby Mathew * POSSIBILITY OF SUCH DAMAGE. 293ca9928dSSoby Mathew */ 303ca9928dSSoby Mathew 313ca9928dSSoby Mathew #ifndef __XLAT_TABLES_PRIVATE_H__ 323ca9928dSSoby Mathew #define __XLAT_TABLES_PRIVATE_H__ 333ca9928dSSoby Mathew 34e8719552SAntonio Nino Diaz #include <cassert.h> 350029624fSAntonio Nino Diaz #include <platform_def.h> 3653d9c9c8SScott Branden #include <utils_def.h> 37e8719552SAntonio Nino Diaz 380029624fSAntonio Nino Diaz /* 390029624fSAntonio Nino Diaz * If the platform hasn't defined a physical and a virtual address space size 400029624fSAntonio Nino Diaz * default to ADDR_SPACE_SIZE. 410029624fSAntonio Nino Diaz */ 420029624fSAntonio Nino Diaz #if ERROR_DEPRECATED 430029624fSAntonio Nino Diaz # ifdef ADDR_SPACE_SIZE 440029624fSAntonio Nino Diaz # error "ADDR_SPACE_SIZE is deprecated. Use PLAT_xxx_ADDR_SPACE_SIZE instead." 450029624fSAntonio Nino Diaz # endif 460029624fSAntonio Nino Diaz #elif defined(ADDR_SPACE_SIZE) 470029624fSAntonio Nino Diaz # ifndef PLAT_PHY_ADDR_SPACE_SIZE 480029624fSAntonio Nino Diaz # define PLAT_PHY_ADDR_SPACE_SIZE ADDR_SPACE_SIZE 490029624fSAntonio Nino Diaz # endif 500029624fSAntonio Nino Diaz # ifndef PLAT_VIRT_ADDR_SPACE_SIZE 510029624fSAntonio Nino Diaz # define PLAT_VIRT_ADDR_SPACE_SIZE ADDR_SPACE_SIZE 520029624fSAntonio Nino Diaz # endif 530029624fSAntonio Nino Diaz #endif 540029624fSAntonio Nino Diaz 550029624fSAntonio Nino Diaz /* The virtual and physical address space sizes must be powers of two. */ 560029624fSAntonio Nino Diaz CASSERT(IS_POWER_OF_TWO(PLAT_VIRT_ADDR_SPACE_SIZE), 570029624fSAntonio Nino Diaz assert_valid_virt_addr_space_size); 580029624fSAntonio Nino Diaz CASSERT(IS_POWER_OF_TWO(PLAT_PHY_ADDR_SPACE_SIZE), 590029624fSAntonio Nino Diaz assert_valid_phy_addr_space_size); 60e8719552SAntonio Nino Diaz 612240f45bSAntonio Nino Diaz /* 622240f45bSAntonio Nino Diaz * In AArch32 state, the MMU only supports 4KB page granularity, which means 632240f45bSAntonio Nino Diaz * that the first translation table level is either 1 or 2. Both of them are 642240f45bSAntonio Nino Diaz * allowed to have block and table descriptors. See section G4.5.6 of the 652240f45bSAntonio Nino Diaz * ARMv8-A Architecture Reference Manual (DDI 0487A.k) for more information. 662240f45bSAntonio Nino Diaz * 672240f45bSAntonio Nino Diaz * In AArch64 state, the MMU may support 4 KB, 16 KB and 64 KB page 682240f45bSAntonio Nino Diaz * granularity. For 4KB granularity, a level 0 table descriptor doesn't support 692240f45bSAntonio Nino Diaz * block translation. For 16KB, the same thing happens to levels 0 and 1. For 702240f45bSAntonio Nino Diaz * 64KB, same for level 1. See section D4.3.1 of the ARMv8-A Architecture 712240f45bSAntonio Nino Diaz * Reference Manual (DDI 0487A.k) for more information. 722240f45bSAntonio Nino Diaz * 732240f45bSAntonio Nino Diaz * The define below specifies the first table level that allows block 742240f45bSAntonio Nino Diaz * descriptors. 752240f45bSAntonio Nino Diaz */ 762240f45bSAntonio Nino Diaz 772240f45bSAntonio Nino Diaz #ifdef AARCH32 782240f45bSAntonio Nino Diaz 792240f45bSAntonio Nino Diaz # define XLAT_BLOCK_LEVEL_MIN 1 802240f45bSAntonio Nino Diaz 812240f45bSAntonio Nino Diaz #else /* if AArch64 */ 822240f45bSAntonio Nino Diaz 832240f45bSAntonio Nino Diaz # if PAGE_SIZE == (4*1024) /* 4KB */ 842240f45bSAntonio Nino Diaz # define XLAT_BLOCK_LEVEL_MIN 1 852240f45bSAntonio Nino Diaz # else /* 16KB or 64KB */ 862240f45bSAntonio Nino Diaz # define XLAT_BLOCK_LEVEL_MIN 2 872240f45bSAntonio Nino Diaz # endif 882240f45bSAntonio Nino Diaz 892240f45bSAntonio Nino Diaz #endif /* AARCH32 */ 902240f45bSAntonio Nino Diaz 913ca9928dSSoby Mathew void print_mmap(void); 92*a5640252SAntonio Nino Diaz 93*a5640252SAntonio Nino Diaz /* Returns the current Exception Level. The returned EL must be 1 or higher. */ 94*a5640252SAntonio Nino Diaz int xlat_arch_current_el(void); 95*a5640252SAntonio Nino Diaz 96*a5640252SAntonio Nino Diaz /* 97*a5640252SAntonio Nino Diaz * Returns the bit mask that has to be ORed to the rest of a translation table 98*a5640252SAntonio Nino Diaz * descriptor so that execution of code is prohibited at the given Exception 99*a5640252SAntonio Nino Diaz * Level. 100*a5640252SAntonio Nino Diaz */ 101*a5640252SAntonio Nino Diaz uint64_t xlat_arch_get_xn_desc(int el); 102*a5640252SAntonio Nino Diaz 1033ca9928dSSoby Mathew void init_xlation_table(uintptr_t base_va, uint64_t *table, 1043ca9928dSSoby Mathew int level, uintptr_t *max_va, 1053ca9928dSSoby Mathew unsigned long long *max_pa); 1063ca9928dSSoby Mathew 1073ca9928dSSoby Mathew #endif /* __XLAT_TABLES_PRIVATE_H__ */ 108