17bb01fb2SAntonio Nino Diaz /* 20cc7aa89SJeenu Viswambharan * Copyright (c) 2017-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_TABLES_V2_H 8e7b9886cSAntonio Nino Diaz #define XLAT_TABLES_V2_H 97bb01fb2SAntonio Nino Diaz 107bb01fb2SAntonio Nino Diaz #include <xlat_tables_defs.h> 110cc7aa89SJeenu Viswambharan #include <xlat_tables_v2_helpers.h> 127bb01fb2SAntonio Nino Diaz 137bb01fb2SAntonio Nino Diaz #ifndef __ASSEMBLY__ 147bb01fb2SAntonio Nino Diaz #include <stddef.h> 157bb01fb2SAntonio Nino Diaz #include <stdint.h> 167bb01fb2SAntonio Nino Diaz #include <xlat_mmu_helpers.h> 177bb01fb2SAntonio Nino Diaz 18fdb1964cSSandrine Bailleux /* 19fdb1964cSSandrine Bailleux * Default granularity size for an mmap_region_t. 20fdb1964cSSandrine Bailleux * Useful when no specific granularity is required. 21fdb1964cSSandrine Bailleux * 22fdb1964cSSandrine Bailleux * By default, choose the biggest possible block size allowed by the 23fdb1964cSSandrine Bailleux * architectural state and granule size in order to minimize the number of page 24fdb1964cSSandrine Bailleux * tables required for the mapping. 257bb01fb2SAntonio Nino Diaz */ 26fdb1964cSSandrine Bailleux #define REGION_DEFAULT_GRANULARITY XLAT_BLOCK_SIZE(MIN_LVL_BLOCK_DESC) 277bb01fb2SAntonio Nino Diaz 28fdb1964cSSandrine Bailleux /* Helper macro to define an mmap_region_t. */ 29fdb1964cSSandrine Bailleux #define MAP_REGION(_pa, _va, _sz, _attr) \ 30e7b9886cSAntonio Nino Diaz MAP_REGION_FULL_SPEC(_pa, _va, _sz, _attr, REGION_DEFAULT_GRANULARITY) 31fdb1964cSSandrine Bailleux 32fdb1964cSSandrine Bailleux /* Helper macro to define an mmap_region_t with an identity mapping. */ 33fdb1964cSSandrine Bailleux #define MAP_REGION_FLAT(_adr, _sz, _attr) \ 34fdb1964cSSandrine Bailleux MAP_REGION(_adr, _adr, _sz, _attr) 35fdb1964cSSandrine Bailleux 36fdb1964cSSandrine Bailleux /* 37*9056f108SAntonio Nino Diaz * Helper macro to define entries for mmap_region_t. It allows to define 'pa' 38*9056f108SAntonio Nino Diaz * and sets 'va' to 0 for each region. To be used with mmap_add_alloc_va(). 39*9056f108SAntonio Nino Diaz */ 40*9056f108SAntonio Nino Diaz #define MAP_REGION_ALLOC_VA(pa, sz, attr) MAP_REGION(pa, 0, sz, attr) 41*9056f108SAntonio Nino Diaz 42*9056f108SAntonio Nino Diaz /* 43fdb1964cSSandrine Bailleux * Helper macro to define an mmap_region_t to map with the desired granularity 44fdb1964cSSandrine Bailleux * of translation tables. 45fdb1964cSSandrine Bailleux * 46fdb1964cSSandrine Bailleux * The granularity value passed to this macro must be a valid block or page 47fdb1964cSSandrine Bailleux * size. When using a 4KB translation granule, this might be 4KB, 2MB or 1GB. 48fdb1964cSSandrine Bailleux * Passing REGION_DEFAULT_GRANULARITY is also allowed and means that the library 49fdb1964cSSandrine Bailleux * is free to choose the granularity for this region. In this case, it is 50fdb1964cSSandrine Bailleux * equivalent to the MAP_REGION() macro. 517bb01fb2SAntonio Nino Diaz */ 52fdb1964cSSandrine Bailleux #define MAP_REGION2(_pa, _va, _sz, _attr, _gr) \ 53e7b9886cSAntonio Nino Diaz MAP_REGION_FULL_SPEC(_pa, _va, _sz, _attr, _gr) 547bb01fb2SAntonio Nino Diaz 557bb01fb2SAntonio Nino Diaz /* 563a1b7b10SAntonio Nino Diaz * Shifts and masks to access fields of an mmap attribute 577bb01fb2SAntonio Nino Diaz */ 58030567e6SVarun Wadekar #define MT_TYPE_MASK U(0x7) 597bb01fb2SAntonio Nino Diaz #define MT_TYPE(_attr) ((_attr) & MT_TYPE_MASK) 607bb01fb2SAntonio Nino Diaz /* Access permissions (RO/RW) */ 61030567e6SVarun Wadekar #define MT_PERM_SHIFT U(3) 627bb01fb2SAntonio Nino Diaz /* Security state (SECURE/NS) */ 63030567e6SVarun Wadekar #define MT_SEC_SHIFT U(4) 647bb01fb2SAntonio Nino Diaz /* Access permissions for instruction execution (EXECUTE/EXECUTE_NEVER) */ 65030567e6SVarun Wadekar #define MT_EXECUTE_SHIFT U(5) 663a1b7b10SAntonio Nino Diaz /* In the EL1&0 translation regime, User (EL0) or Privileged (EL1). */ 67609c9191SAntonio Nino Diaz #define MT_USER_SHIFT U(6) 680b64f4efSAntonio Nino Diaz /* All other bits are reserved */ 697bb01fb2SAntonio Nino Diaz 707bb01fb2SAntonio Nino Diaz /* 717bb01fb2SAntonio Nino Diaz * Memory mapping attributes 727bb01fb2SAntonio Nino Diaz */ 733a1b7b10SAntonio Nino Diaz 747bb01fb2SAntonio Nino Diaz /* 757bb01fb2SAntonio Nino Diaz * Memory types supported. 763a1b7b10SAntonio Nino Diaz * These are organised so that, going down the list, the memory types are 773a1b7b10SAntonio Nino Diaz * getting weaker; conversely going up the list the memory types are getting 783a1b7b10SAntonio Nino Diaz * stronger. 797bb01fb2SAntonio Nino Diaz */ 803a1b7b10SAntonio Nino Diaz #define MT_DEVICE U(0) 813a1b7b10SAntonio Nino Diaz #define MT_NON_CACHEABLE U(1) 823a1b7b10SAntonio Nino Diaz #define MT_MEMORY U(2) 837bb01fb2SAntonio Nino Diaz /* Values up to 7 are reserved to add new memory types in the future */ 847bb01fb2SAntonio Nino Diaz 853a1b7b10SAntonio Nino Diaz #define MT_RO (U(0) << MT_PERM_SHIFT) 863a1b7b10SAntonio Nino Diaz #define MT_RW (U(1) << MT_PERM_SHIFT) 877bb01fb2SAntonio Nino Diaz 883a1b7b10SAntonio Nino Diaz #define MT_SECURE (U(0) << MT_SEC_SHIFT) 893a1b7b10SAntonio Nino Diaz #define MT_NS (U(1) << MT_SEC_SHIFT) 907bb01fb2SAntonio Nino Diaz 917bb01fb2SAntonio Nino Diaz /* 923a1b7b10SAntonio Nino Diaz * Access permissions for instruction execution are only relevant for normal 933a1b7b10SAntonio Nino Diaz * read-only memory, i.e. MT_MEMORY | MT_RO. They are ignored (and potentially 943a1b7b10SAntonio Nino Diaz * overridden) otherwise: 957bb01fb2SAntonio Nino Diaz * - Device memory is always marked as execute-never. 967bb01fb2SAntonio Nino Diaz * - Read-write normal memory is always marked as execute-never. 977bb01fb2SAntonio Nino Diaz */ 983a1b7b10SAntonio Nino Diaz #define MT_EXECUTE (U(0) << MT_EXECUTE_SHIFT) 993a1b7b10SAntonio Nino Diaz #define MT_EXECUTE_NEVER (U(1) << MT_EXECUTE_SHIFT) 100609c9191SAntonio Nino Diaz 101609c9191SAntonio Nino Diaz /* 1023a1b7b10SAntonio Nino Diaz * When mapping a region at EL0 or EL1, this attribute will be used to determine 1033a1b7b10SAntonio Nino Diaz * if a User mapping (EL0) will be created or a Privileged mapping (EL1). 104609c9191SAntonio Nino Diaz */ 1053a1b7b10SAntonio Nino Diaz #define MT_USER (U(1) << MT_USER_SHIFT) 1063a1b7b10SAntonio Nino Diaz #define MT_PRIVILEGED (U(0) << MT_USER_SHIFT) 1077bb01fb2SAntonio Nino Diaz 108609c9191SAntonio Nino Diaz /* Compound attributes for most common usages */ 1097bb01fb2SAntonio Nino Diaz #define MT_CODE (MT_MEMORY | MT_RO | MT_EXECUTE) 1107bb01fb2SAntonio Nino Diaz #define MT_RO_DATA (MT_MEMORY | MT_RO | MT_EXECUTE_NEVER) 111609c9191SAntonio Nino Diaz #define MT_RW_DATA (MT_MEMORY | MT_RW | MT_EXECUTE_NEVER) 1127bb01fb2SAntonio Nino Diaz 1137bb01fb2SAntonio Nino Diaz /* 1147bb01fb2SAntonio Nino Diaz * Structure for specifying a single region of memory. 1157bb01fb2SAntonio Nino Diaz */ 1167bb01fb2SAntonio Nino Diaz typedef struct mmap_region { 1177bb01fb2SAntonio Nino Diaz unsigned long long base_pa; 1187bb01fb2SAntonio Nino Diaz uintptr_t base_va; 1197bb01fb2SAntonio Nino Diaz size_t size; 1203a1b7b10SAntonio Nino Diaz unsigned int attr; 121fdb1964cSSandrine Bailleux /* Desired granularity. See the MAP_REGION2() macro for more details. */ 122fdb1964cSSandrine Bailleux size_t granularity; 1237bb01fb2SAntonio Nino Diaz } mmap_region_t; 1247bb01fb2SAntonio Nino Diaz 12555c84964SSandrine Bailleux /* 126aa1d5f60SAntonio Nino Diaz * Translation regimes supported by this library. EL_REGIME_INVALID tells the 127aa1d5f60SAntonio Nino Diaz * library to detect it at runtime. 128b4ae615bSDouglas Raillard */ 129fd2299e6SAntonio Nino Diaz #define EL1_EL0_REGIME 1 1301a92a0e0SAntonio Nino Diaz #define EL2_REGIME 2 131fd2299e6SAntonio Nino Diaz #define EL3_REGIME 3 132aa1d5f60SAntonio Nino Diaz #define EL_REGIME_INVALID -1 133b4ae615bSDouglas Raillard 134b4ae615bSDouglas Raillard /* 13555c84964SSandrine Bailleux * Declare the translation context type. 13655c84964SSandrine Bailleux * Its definition is private. 13755c84964SSandrine Bailleux */ 13855c84964SSandrine Bailleux typedef struct xlat_ctx xlat_ctx_t; 13955c84964SSandrine Bailleux 14055c84964SSandrine Bailleux /* 14155c84964SSandrine Bailleux * Statically allocate a translation context and associated structures. Also 14255c84964SSandrine Bailleux * initialize them. 14355c84964SSandrine Bailleux * 14455c84964SSandrine Bailleux * _ctx_name: 14555c84964SSandrine Bailleux * Prefix for the translation context variable. 14655c84964SSandrine Bailleux * E.g. If _ctx_name is 'foo', the variable will be called 'foo_xlat_ctx'. 14755c84964SSandrine Bailleux * Useful to distinguish multiple contexts from one another. 14855c84964SSandrine Bailleux * 14955c84964SSandrine Bailleux * _mmap_count: 15055c84964SSandrine Bailleux * Number of mmap_region_t to allocate. 15155c84964SSandrine Bailleux * Would typically be MAX_MMAP_REGIONS for the translation context describing 15255c84964SSandrine Bailleux * the BL image currently executing. 15355c84964SSandrine Bailleux * 15455c84964SSandrine Bailleux * _xlat_tables_count: 15555c84964SSandrine Bailleux * Number of sub-translation tables to allocate. 15655c84964SSandrine Bailleux * Would typically be MAX_XLAT_TABLES for the translation context describing 15755c84964SSandrine Bailleux * the BL image currently executing. 15855c84964SSandrine Bailleux * Note that this is only for sub-tables ; at the initial lookup level, there 15955c84964SSandrine Bailleux * is always a single table. 16055c84964SSandrine Bailleux * 16155c84964SSandrine Bailleux * _virt_addr_space_size, _phy_addr_space_size: 16255c84964SSandrine Bailleux * Size (in bytes) of the virtual (resp. physical) address space. 16355c84964SSandrine Bailleux * Would typically be PLAT_VIRT_ADDR_SPACE_SIZE 16455c84964SSandrine Bailleux * (resp. PLAT_PHY_ADDR_SPACE_SIZE) for the translation context describing the 16555c84964SSandrine Bailleux * BL image currently executing. 16655c84964SSandrine Bailleux */ 16755c84964SSandrine Bailleux #define REGISTER_XLAT_CONTEXT(_ctx_name, _mmap_count, _xlat_tables_count, \ 16855c84964SSandrine Bailleux _virt_addr_space_size, _phy_addr_space_size) \ 169e7b9886cSAntonio Nino Diaz REGISTER_XLAT_CONTEXT_FULL_SPEC(_ctx_name, (_mmap_count), \ 170fd2299e6SAntonio Nino Diaz (_xlat_tables_count), \ 171fd2299e6SAntonio Nino Diaz (_virt_addr_space_size), \ 172fd2299e6SAntonio Nino Diaz (_phy_addr_space_size), \ 173aa1d5f60SAntonio Nino Diaz EL_REGIME_INVALID, "xlat_table") 174609c9191SAntonio Nino Diaz 175609c9191SAntonio Nino Diaz /* 17645d640f0SAntonio Nino Diaz * Same as REGISTER_XLAT_CONTEXT plus the additional parameters: 17745d640f0SAntonio Nino Diaz * 17845d640f0SAntonio Nino Diaz * _xlat_regime: 17945d640f0SAntonio Nino Diaz * Specify the translation regime managed by this xlat_ctx_t instance. The 180fd2299e6SAntonio Nino Diaz * values are the one from the EL*_REGIME definitions. 18145d640f0SAntonio Nino Diaz * 18245d640f0SAntonio Nino Diaz * _section_name: 18345d640f0SAntonio Nino Diaz * Specify the name of the section where the translation tables have to be 18445d640f0SAntonio Nino Diaz * placed by the linker. 185609c9191SAntonio Nino Diaz */ 186609c9191SAntonio Nino Diaz #define REGISTER_XLAT_CONTEXT2(_ctx_name, _mmap_count, _xlat_tables_count, \ 187609c9191SAntonio Nino Diaz _virt_addr_space_size, _phy_addr_space_size, \ 18845d640f0SAntonio Nino Diaz _xlat_regime, _section_name) \ 189e7b9886cSAntonio Nino Diaz REGISTER_XLAT_CONTEXT_FULL_SPEC(_ctx_name, (_mmap_count), \ 190fd2299e6SAntonio Nino Diaz (_xlat_tables_count), \ 191fd2299e6SAntonio Nino Diaz (_virt_addr_space_size), \ 192fd2299e6SAntonio Nino Diaz (_phy_addr_space_size), \ 193fd2299e6SAntonio Nino Diaz (_xlat_regime), (_section_name)) 19455c84964SSandrine Bailleux 195a9ad848cSSandrine Bailleux /****************************************************************************** 196a9ad848cSSandrine Bailleux * Generic translation table APIs. 197a9ad848cSSandrine Bailleux * Each API comes in 2 variants: 198a9ad848cSSandrine Bailleux * - one that acts on the current translation context for this BL image 199a9ad848cSSandrine Bailleux * - another that acts on the given translation context instead. This variant 200a9ad848cSSandrine Bailleux * is named after the 1st version, with an additional '_ctx' suffix. 201a9ad848cSSandrine Bailleux *****************************************************************************/ 202e769db3eSAntonio Nino Diaz 203e769db3eSAntonio Nino Diaz /* 204e769db3eSAntonio Nino Diaz * Initialize translation tables from the current list of mmap regions. Calling 205e769db3eSAntonio Nino Diaz * this function marks the transition point after which static regions can no 206e769db3eSAntonio Nino Diaz * longer be added. 207e769db3eSAntonio Nino Diaz */ 2087bb01fb2SAntonio Nino Diaz void init_xlat_tables(void); 209a9ad848cSSandrine Bailleux void init_xlat_tables_ctx(xlat_ctx_t *ctx); 2107bb01fb2SAntonio Nino Diaz 2117bb01fb2SAntonio Nino Diaz /* 212e769db3eSAntonio Nino Diaz * Add a static region with defined base PA and base VA. This function can only 213e769db3eSAntonio Nino Diaz * be used before initializing the translation tables. The region cannot be 214e769db3eSAntonio Nino Diaz * removed afterwards. 2157bb01fb2SAntonio Nino Diaz */ 2167bb01fb2SAntonio Nino Diaz void mmap_add_region(unsigned long long base_pa, uintptr_t base_va, 2173a1b7b10SAntonio Nino Diaz size_t size, unsigned int attr); 218a9ad848cSSandrine Bailleux void mmap_add_region_ctx(xlat_ctx_t *ctx, const mmap_region_t *mm); 2197bb01fb2SAntonio Nino Diaz 2207bb01fb2SAntonio Nino Diaz /* 221a9ad848cSSandrine Bailleux * Add an array of static regions with defined base PA and base VA. This 222a9ad848cSSandrine Bailleux * function can only be used before initializing the translation tables. The 223a9ad848cSSandrine Bailleux * regions cannot be removed afterwards. 224a9ad848cSSandrine Bailleux */ 225a9ad848cSSandrine Bailleux void mmap_add(const mmap_region_t *mm); 226a9ad848cSSandrine Bailleux void mmap_add_ctx(xlat_ctx_t *ctx, const mmap_region_t *mm); 227a9ad848cSSandrine Bailleux 228*9056f108SAntonio Nino Diaz /* 229*9056f108SAntonio Nino Diaz * Add a region with defined base PA. Returns base VA calculated using the 230*9056f108SAntonio Nino Diaz * highest existing region in the mmap array even if it fails to allocate the 231*9056f108SAntonio Nino Diaz * region. 232*9056f108SAntonio Nino Diaz */ 233*9056f108SAntonio Nino Diaz void mmap_add_region_alloc_va(unsigned long long base_pa, uintptr_t *base_va, 234*9056f108SAntonio Nino Diaz size_t size, unsigned int attr); 235*9056f108SAntonio Nino Diaz void mmap_add_region_alloc_va_ctx(xlat_ctx_t *ctx, mmap_region_t *mm); 236*9056f108SAntonio Nino Diaz 237*9056f108SAntonio Nino Diaz /* 238*9056f108SAntonio Nino Diaz * Add an array of static regions with defined base PA, and fill the base VA 239*9056f108SAntonio Nino Diaz * field on the array of structs. This function can only be used before 240*9056f108SAntonio Nino Diaz * initializing the translation tables. The regions cannot be removed afterwards. 241*9056f108SAntonio Nino Diaz */ 242*9056f108SAntonio Nino Diaz void mmap_add_alloc_va(mmap_region_t *mm); 243a9ad848cSSandrine Bailleux 244a9ad848cSSandrine Bailleux #if PLAT_XLAT_TABLES_DYNAMIC 245a9ad848cSSandrine Bailleux /* 246e769db3eSAntonio Nino Diaz * Add a dynamic region with defined base PA and base VA. This type of region 247e769db3eSAntonio Nino Diaz * can be added and removed even after the translation tables are initialized. 2480b64f4efSAntonio Nino Diaz * 2490b64f4efSAntonio Nino Diaz * Returns: 2500b64f4efSAntonio Nino Diaz * 0: Success. 2510b64f4efSAntonio Nino Diaz * EINVAL: Invalid values were used as arguments. 2520b64f4efSAntonio Nino Diaz * ERANGE: Memory limits were surpassed. 2530b64f4efSAntonio Nino Diaz * ENOMEM: Not enough space in the mmap array or not enough free xlat tables. 2540b64f4efSAntonio Nino Diaz * EPERM: It overlaps another region in an invalid way. 2550b64f4efSAntonio Nino Diaz */ 2560b64f4efSAntonio Nino Diaz int mmap_add_dynamic_region(unsigned long long base_pa, uintptr_t base_va, 2573a1b7b10SAntonio Nino Diaz size_t size, unsigned int attr); 258a9ad848cSSandrine Bailleux int mmap_add_dynamic_region_ctx(xlat_ctx_t *ctx, mmap_region_t *mm); 2597bb01fb2SAntonio Nino Diaz 2600b64f4efSAntonio Nino Diaz /* 261*9056f108SAntonio Nino Diaz * Add a dynamic region with defined base PA. Returns base VA calculated using 262*9056f108SAntonio Nino Diaz * the highest existing region in the mmap array even if it fails to allocate 263*9056f108SAntonio Nino Diaz * the region. 264*9056f108SAntonio Nino Diaz * 265*9056f108SAntonio Nino Diaz * mmap_add_dynamic_region_alloc_va() returns the allocated VA in 'base_va'. 266*9056f108SAntonio Nino Diaz * mmap_add_dynamic_region_alloc_va_ctx() returns it in 'mm->base_va'. 267*9056f108SAntonio Nino Diaz * 268*9056f108SAntonio Nino Diaz * It returns the same error values as mmap_add_dynamic_region(). 269*9056f108SAntonio Nino Diaz */ 270*9056f108SAntonio Nino Diaz int mmap_add_dynamic_region_alloc_va(unsigned long long base_pa, 271*9056f108SAntonio Nino Diaz uintptr_t *base_va, 272*9056f108SAntonio Nino Diaz size_t size, unsigned int attr); 273*9056f108SAntonio Nino Diaz int mmap_add_dynamic_region_alloc_va_ctx(xlat_ctx_t *ctx, mmap_region_t *mm); 274*9056f108SAntonio Nino Diaz 275*9056f108SAntonio Nino Diaz /* 2760b64f4efSAntonio Nino Diaz * Remove a region with the specified base VA and size. Only dynamic regions can 277e769db3eSAntonio Nino Diaz * be removed, and they can be removed even if the translation tables are 278e769db3eSAntonio Nino Diaz * initialized. 2790b64f4efSAntonio Nino Diaz * 2800b64f4efSAntonio Nino Diaz * Returns: 2810b64f4efSAntonio Nino Diaz * 0: Success. 2820b64f4efSAntonio Nino Diaz * EINVAL: The specified region wasn't found. 2830b64f4efSAntonio Nino Diaz * EPERM: Trying to remove a static region. 2840b64f4efSAntonio Nino Diaz */ 2850b64f4efSAntonio Nino Diaz int mmap_remove_dynamic_region(uintptr_t base_va, size_t size); 286a9ad848cSSandrine Bailleux int mmap_remove_dynamic_region_ctx(xlat_ctx_t *ctx, 287a9ad848cSSandrine Bailleux uintptr_t base_va, 288a9ad848cSSandrine Bailleux size_t size); 289a9ad848cSSandrine Bailleux 290a9ad848cSSandrine Bailleux #endif /* PLAT_XLAT_TABLES_DYNAMIC */ 2910b64f4efSAntonio Nino Diaz 2921be910bbSSandrine Bailleux /* 293996d6b39SSandrine Bailleux * Change the memory attributes of the memory region starting from a given 294996d6b39SSandrine Bailleux * virtual address in a set of translation tables. 295996d6b39SSandrine Bailleux * 296996d6b39SSandrine Bailleux * This function can only be used after the translation tables have been 297996d6b39SSandrine Bailleux * initialized. 298996d6b39SSandrine Bailleux * 299996d6b39SSandrine Bailleux * The base address of the memory region must be aligned on a page boundary. 300996d6b39SSandrine Bailleux * The size of this memory region must be a multiple of a page size. 301996d6b39SSandrine Bailleux * The memory region must be already mapped by the given translation tables 302996d6b39SSandrine Bailleux * and it must be mapped at the granularity of a page. 303996d6b39SSandrine Bailleux * 304996d6b39SSandrine Bailleux * Return 0 on success, a negative value on error. 305996d6b39SSandrine Bailleux * 306996d6b39SSandrine Bailleux * In case of error, the memory attributes remain unchanged and this function 307996d6b39SSandrine Bailleux * has no effect. 308996d6b39SSandrine Bailleux * 309996d6b39SSandrine Bailleux * ctx 310996d6b39SSandrine Bailleux * Translation context to work on. 311996d6b39SSandrine Bailleux * base_va: 312996d6b39SSandrine Bailleux * Virtual address of the 1st page to change the attributes of. 313996d6b39SSandrine Bailleux * size: 314996d6b39SSandrine Bailleux * Size in bytes of the memory region. 315996d6b39SSandrine Bailleux * attr: 316996d6b39SSandrine Bailleux * New attributes of the page tables. The attributes that can be changed are 317996d6b39SSandrine Bailleux * data access (MT_RO/MT_RW), instruction access (MT_EXECUTE_NEVER/MT_EXECUTE) 318996d6b39SSandrine Bailleux * and user/privileged access (MT_USER/MT_PRIVILEGED) in the case of contexts 319996d6b39SSandrine Bailleux * that are used in the EL1&0 translation regime. Also, note that this 320996d6b39SSandrine Bailleux * function doesn't allow to remap a region as RW and executable, or to remap 321996d6b39SSandrine Bailleux * device memory as executable. 322996d6b39SSandrine Bailleux * 323996d6b39SSandrine Bailleux * NOTE: The caller of this function must be able to write to the translation 324996d6b39SSandrine Bailleux * tables, i.e. the memory where they are stored must be mapped with read-write 325996d6b39SSandrine Bailleux * access permissions. This function assumes it is the case. If this is not 326996d6b39SSandrine Bailleux * the case then this function might trigger a data abort exception. 327996d6b39SSandrine Bailleux * 328996d6b39SSandrine Bailleux * NOTE2: The caller is responsible for making sure that the targeted 329996d6b39SSandrine Bailleux * translation tables are not modified by any other code while this function is 330996d6b39SSandrine Bailleux * executing. 331996d6b39SSandrine Bailleux */ 332e5d59519SAntonio Nino Diaz int xlat_change_mem_attributes_ctx(const xlat_ctx_t *ctx, uintptr_t base_va, 333e5d59519SAntonio Nino Diaz size_t size, uint32_t attr); 334e5d59519SAntonio Nino Diaz int xlat_change_mem_attributes(uintptr_t base_va, size_t size, uint32_t attr); 335996d6b39SSandrine Bailleux 336996d6b39SSandrine Bailleux /* 3371be910bbSSandrine Bailleux * Query the memory attributes of a memory page in a set of translation tables. 3381be910bbSSandrine Bailleux * 3391be910bbSSandrine Bailleux * Return 0 on success, a negative error code on error. 340e5d59519SAntonio Nino Diaz * On success, the attributes are stored into *attr. 3411be910bbSSandrine Bailleux * 3421be910bbSSandrine Bailleux * ctx 3431be910bbSSandrine Bailleux * Translation context to work on. 3441be910bbSSandrine Bailleux * base_va 3451be910bbSSandrine Bailleux * Virtual address of the page to get the attributes of. 3461be910bbSSandrine Bailleux * There are no alignment restrictions on this address. The attributes of the 3471be910bbSSandrine Bailleux * memory page it lies within are returned. 348e5d59519SAntonio Nino Diaz * attr 3491be910bbSSandrine Bailleux * Output parameter where to store the attributes of the targeted memory page. 3501be910bbSSandrine Bailleux */ 351e5d59519SAntonio Nino Diaz int xlat_get_mem_attributes_ctx(const xlat_ctx_t *ctx, uintptr_t base_va, 352e5d59519SAntonio Nino Diaz uint32_t *attr); 353e5d59519SAntonio Nino Diaz int xlat_get_mem_attributes(uintptr_t base_va, uint32_t *attr); 3541be910bbSSandrine Bailleux 3557bb01fb2SAntonio Nino Diaz #endif /*__ASSEMBLY__*/ 356e7b9886cSAntonio Nino Diaz #endif /* XLAT_TABLES_V2_H */ 357