1*7bb01fb2SAntonio Nino Diaz /* 2*7bb01fb2SAntonio Nino Diaz * Copyright (c) 2017, ARM Limited and Contributors. All rights reserved. 3*7bb01fb2SAntonio Nino Diaz * 4*7bb01fb2SAntonio Nino Diaz * Redistribution and use in source and binary forms, with or without 5*7bb01fb2SAntonio Nino Diaz * modification, are permitted provided that the following conditions are met: 6*7bb01fb2SAntonio Nino Diaz * 7*7bb01fb2SAntonio Nino Diaz * Redistributions of source code must retain the above copyright notice, this 8*7bb01fb2SAntonio Nino Diaz * list of conditions and the following disclaimer. 9*7bb01fb2SAntonio Nino Diaz * 10*7bb01fb2SAntonio Nino Diaz * Redistributions in binary form must reproduce the above copyright notice, 11*7bb01fb2SAntonio Nino Diaz * this list of conditions and the following disclaimer in the documentation 12*7bb01fb2SAntonio Nino Diaz * and/or other materials provided with the distribution. 13*7bb01fb2SAntonio Nino Diaz * 14*7bb01fb2SAntonio Nino Diaz * Neither the name of ARM nor the names of its contributors may be used 15*7bb01fb2SAntonio Nino Diaz * to endorse or promote products derived from this software without specific 16*7bb01fb2SAntonio Nino Diaz * prior written permission. 17*7bb01fb2SAntonio Nino Diaz * 18*7bb01fb2SAntonio Nino Diaz * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19*7bb01fb2SAntonio Nino Diaz * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20*7bb01fb2SAntonio Nino Diaz * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21*7bb01fb2SAntonio Nino Diaz * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22*7bb01fb2SAntonio Nino Diaz * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23*7bb01fb2SAntonio Nino Diaz * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24*7bb01fb2SAntonio Nino Diaz * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25*7bb01fb2SAntonio Nino Diaz * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26*7bb01fb2SAntonio Nino Diaz * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27*7bb01fb2SAntonio Nino Diaz * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28*7bb01fb2SAntonio Nino Diaz * POSSIBILITY OF SUCH DAMAGE. 29*7bb01fb2SAntonio Nino Diaz */ 30*7bb01fb2SAntonio Nino Diaz 31*7bb01fb2SAntonio Nino Diaz #ifndef __XLAT_TABLES_PRIVATE_H__ 32*7bb01fb2SAntonio Nino Diaz #define __XLAT_TABLES_PRIVATE_H__ 33*7bb01fb2SAntonio Nino Diaz 34*7bb01fb2SAntonio Nino Diaz #include <cassert.h> 35*7bb01fb2SAntonio Nino Diaz #include <platform_def.h> 36*7bb01fb2SAntonio Nino Diaz #include <utils.h> 37*7bb01fb2SAntonio Nino Diaz 38*7bb01fb2SAntonio Nino Diaz /* 39*7bb01fb2SAntonio Nino Diaz * If the platform hasn't defined a physical and a virtual address space size 40*7bb01fb2SAntonio Nino Diaz * default to ADDR_SPACE_SIZE. 41*7bb01fb2SAntonio Nino Diaz */ 42*7bb01fb2SAntonio Nino Diaz #if ERROR_DEPRECATED 43*7bb01fb2SAntonio Nino Diaz # ifdef ADDR_SPACE_SIZE 44*7bb01fb2SAntonio Nino Diaz # error "ADDR_SPACE_SIZE is deprecated. Use PLAT_xxx_ADDR_SPACE_SIZE instead." 45*7bb01fb2SAntonio Nino Diaz # endif 46*7bb01fb2SAntonio Nino Diaz #elif defined(ADDR_SPACE_SIZE) 47*7bb01fb2SAntonio Nino Diaz # ifndef PLAT_PHY_ADDR_SPACE_SIZE 48*7bb01fb2SAntonio Nino Diaz # define PLAT_PHY_ADDR_SPACE_SIZE ADDR_SPACE_SIZE 49*7bb01fb2SAntonio Nino Diaz # endif 50*7bb01fb2SAntonio Nino Diaz # ifndef PLAT_VIRT_ADDR_SPACE_SIZE 51*7bb01fb2SAntonio Nino Diaz # define PLAT_VIRT_ADDR_SPACE_SIZE ADDR_SPACE_SIZE 52*7bb01fb2SAntonio Nino Diaz # endif 53*7bb01fb2SAntonio Nino Diaz #endif 54*7bb01fb2SAntonio Nino Diaz 55*7bb01fb2SAntonio Nino Diaz /* The virtual and physical address space sizes must be powers of two. */ 56*7bb01fb2SAntonio Nino Diaz CASSERT(IS_POWER_OF_TWO(PLAT_VIRT_ADDR_SPACE_SIZE), 57*7bb01fb2SAntonio Nino Diaz assert_valid_virt_addr_space_size); 58*7bb01fb2SAntonio Nino Diaz CASSERT(IS_POWER_OF_TWO(PLAT_PHY_ADDR_SPACE_SIZE), 59*7bb01fb2SAntonio Nino Diaz assert_valid_phy_addr_space_size); 60*7bb01fb2SAntonio Nino Diaz 61*7bb01fb2SAntonio Nino Diaz /* Struct that holds all information about the translation tables. */ 62*7bb01fb2SAntonio Nino Diaz typedef struct { 63*7bb01fb2SAntonio Nino Diaz 64*7bb01fb2SAntonio Nino Diaz /* 65*7bb01fb2SAntonio Nino Diaz * Max allowed Virtual and Physical Addresses. 66*7bb01fb2SAntonio Nino Diaz */ 67*7bb01fb2SAntonio Nino Diaz unsigned long long pa_max_address; 68*7bb01fb2SAntonio Nino Diaz uintptr_t va_max_address; 69*7bb01fb2SAntonio Nino Diaz 70*7bb01fb2SAntonio Nino Diaz /* 71*7bb01fb2SAntonio Nino Diaz * Array of all memory regions stored in order of ascending end address 72*7bb01fb2SAntonio Nino Diaz * and ascending size to simplify the code that allows overlapping 73*7bb01fb2SAntonio Nino Diaz * regions. The list is terminated by the first entry with size == 0. 74*7bb01fb2SAntonio Nino Diaz */ 75*7bb01fb2SAntonio Nino Diaz mmap_region_t *mmap; /* mmap_num + 1 elements */ 76*7bb01fb2SAntonio Nino Diaz int mmap_num; 77*7bb01fb2SAntonio Nino Diaz 78*7bb01fb2SAntonio Nino Diaz /* 79*7bb01fb2SAntonio Nino Diaz * Array of finer-grain translation tables. 80*7bb01fb2SAntonio Nino Diaz * For example, if the initial lookup level is 1 then this array would 81*7bb01fb2SAntonio Nino Diaz * contain both level-2 and level-3 entries. 82*7bb01fb2SAntonio Nino Diaz */ 83*7bb01fb2SAntonio Nino Diaz uint64_t (*tables)[XLAT_TABLE_ENTRIES]; 84*7bb01fb2SAntonio Nino Diaz int tables_num; 85*7bb01fb2SAntonio Nino Diaz 86*7bb01fb2SAntonio Nino Diaz int next_table; 87*7bb01fb2SAntonio Nino Diaz 88*7bb01fb2SAntonio Nino Diaz /* 89*7bb01fb2SAntonio Nino Diaz * Base translation table. It doesn't need to have the same amount of 90*7bb01fb2SAntonio Nino Diaz * entries as the ones used for other levels. 91*7bb01fb2SAntonio Nino Diaz */ 92*7bb01fb2SAntonio Nino Diaz uint64_t *base_table; 93*7bb01fb2SAntonio Nino Diaz int base_table_entries; 94*7bb01fb2SAntonio Nino Diaz 95*7bb01fb2SAntonio Nino Diaz unsigned long long max_pa; 96*7bb01fb2SAntonio Nino Diaz uintptr_t max_va; 97*7bb01fb2SAntonio Nino Diaz 98*7bb01fb2SAntonio Nino Diaz /* Level of the base translation table. */ 99*7bb01fb2SAntonio Nino Diaz int base_level; 100*7bb01fb2SAntonio Nino Diaz 101*7bb01fb2SAntonio Nino Diaz /* Set to 1 when the translation tables are initialized. */ 102*7bb01fb2SAntonio Nino Diaz int initialized; 103*7bb01fb2SAntonio Nino Diaz 104*7bb01fb2SAntonio Nino Diaz } xlat_ctx_t; 105*7bb01fb2SAntonio Nino Diaz 106*7bb01fb2SAntonio Nino Diaz /* Print VA, PA, size and attributes of all regions in the mmap array. */ 107*7bb01fb2SAntonio Nino Diaz void print_mmap(mmap_region_t *const mmap); 108*7bb01fb2SAntonio Nino Diaz 109*7bb01fb2SAntonio Nino Diaz /* 110*7bb01fb2SAntonio Nino Diaz * Print the current state of the translation tables by reading them from 111*7bb01fb2SAntonio Nino Diaz * memory. 112*7bb01fb2SAntonio Nino Diaz */ 113*7bb01fb2SAntonio Nino Diaz void xlat_tables_print(xlat_ctx_t *ctx); 114*7bb01fb2SAntonio Nino Diaz 115*7bb01fb2SAntonio Nino Diaz /* 116*7bb01fb2SAntonio Nino Diaz * Initialize the translation tables by mapping all regions added to the 117*7bb01fb2SAntonio Nino Diaz * specified context. 118*7bb01fb2SAntonio Nino Diaz */ 119*7bb01fb2SAntonio Nino Diaz void init_xlation_table(xlat_ctx_t *ctx); 120*7bb01fb2SAntonio Nino Diaz 121*7bb01fb2SAntonio Nino Diaz /* Add a static region to the specified context. */ 122*7bb01fb2SAntonio Nino Diaz void mmap_add_region_ctx(xlat_ctx_t *ctx, mmap_region_t *mm); 123*7bb01fb2SAntonio Nino Diaz 124*7bb01fb2SAntonio Nino Diaz /* 125*7bb01fb2SAntonio Nino Diaz * Architecture-specific initialization code. 126*7bb01fb2SAntonio Nino Diaz */ 127*7bb01fb2SAntonio Nino Diaz 128*7bb01fb2SAntonio Nino Diaz /* Execute architecture-specific translation table initialization code. */ 129*7bb01fb2SAntonio Nino Diaz void init_xlat_tables_arch(unsigned long long max_pa); 130*7bb01fb2SAntonio Nino Diaz 131*7bb01fb2SAntonio Nino Diaz /* Enable MMU and configure it to use the specified translation tables. */ 132*7bb01fb2SAntonio Nino Diaz void enable_mmu_arch(unsigned int flags, uint64_t *base_table); 133*7bb01fb2SAntonio Nino Diaz 134*7bb01fb2SAntonio Nino Diaz /* Return 1 if the MMU of this Exception Level is enabled, 0 otherwise. */ 135*7bb01fb2SAntonio Nino Diaz int is_mmu_enabled(void); 136*7bb01fb2SAntonio Nino Diaz 137*7bb01fb2SAntonio Nino Diaz #endif /* __XLAT_TABLES_PRIVATE_H__ */ 138