xref: /arm-trusted-firmware/include/lib/xlat_tables/xlat_tables_v2.h (revision 91f16700b400a8c0651d24a598fc48ee2997a0d7)
1*91f16700Schasinglulu /*
2*91f16700Schasinglulu  * Copyright (c) 2017-2021, Arm Limited and Contributors. All rights reserved.
3*91f16700Schasinglulu  *
4*91f16700Schasinglulu  * SPDX-License-Identifier: BSD-3-Clause
5*91f16700Schasinglulu  */
6*91f16700Schasinglulu 
7*91f16700Schasinglulu #ifndef XLAT_TABLES_V2_H
8*91f16700Schasinglulu #define XLAT_TABLES_V2_H
9*91f16700Schasinglulu 
10*91f16700Schasinglulu #include <lib/xlat_tables/xlat_tables_defs.h>
11*91f16700Schasinglulu #include <lib/xlat_tables/xlat_tables_v2_helpers.h>
12*91f16700Schasinglulu 
13*91f16700Schasinglulu #ifndef __ASSEMBLER__
14*91f16700Schasinglulu #include <stddef.h>
15*91f16700Schasinglulu #include <stdint.h>
16*91f16700Schasinglulu 
17*91f16700Schasinglulu #include <lib/xlat_tables/xlat_mmu_helpers.h>
18*91f16700Schasinglulu 
19*91f16700Schasinglulu /*
20*91f16700Schasinglulu  * Default granularity size for an mmap_region_t.
21*91f16700Schasinglulu  * Useful when no specific granularity is required.
22*91f16700Schasinglulu  *
23*91f16700Schasinglulu  * By default, choose the biggest possible block size allowed by the
24*91f16700Schasinglulu  * architectural state and granule size in order to minimize the number of page
25*91f16700Schasinglulu  * tables required for the mapping.
26*91f16700Schasinglulu  */
27*91f16700Schasinglulu #define REGION_DEFAULT_GRANULARITY	XLAT_BLOCK_SIZE(MIN_LVL_BLOCK_DESC)
28*91f16700Schasinglulu 
29*91f16700Schasinglulu /* Helper macro to define an mmap_region_t. */
30*91f16700Schasinglulu #define MAP_REGION(_pa, _va, _sz, _attr)	\
31*91f16700Schasinglulu 	MAP_REGION_FULL_SPEC(_pa, _va, _sz, _attr, REGION_DEFAULT_GRANULARITY)
32*91f16700Schasinglulu 
33*91f16700Schasinglulu /* Helper macro to define an mmap_region_t with an identity mapping. */
34*91f16700Schasinglulu #define MAP_REGION_FLAT(_adr, _sz, _attr)			\
35*91f16700Schasinglulu 	MAP_REGION(_adr, _adr, _sz, _attr)
36*91f16700Schasinglulu 
37*91f16700Schasinglulu /*
38*91f16700Schasinglulu  * Helper macro to define entries for mmap_region_t. It allows to define 'pa'
39*91f16700Schasinglulu  * and sets 'va' to 0 for each region. To be used with mmap_add_alloc_va().
40*91f16700Schasinglulu  */
41*91f16700Schasinglulu #define MAP_REGION_ALLOC_VA(pa, sz, attr)	MAP_REGION(pa, 0, sz, attr)
42*91f16700Schasinglulu 
43*91f16700Schasinglulu /*
44*91f16700Schasinglulu  * Helper macro to define an mmap_region_t to map with the desired granularity
45*91f16700Schasinglulu  * of translation tables.
46*91f16700Schasinglulu  *
47*91f16700Schasinglulu  * The granularity value passed to this macro must be a valid block or page
48*91f16700Schasinglulu  * size. When using a 4KB translation granule, this might be 4KB, 2MB or 1GB.
49*91f16700Schasinglulu  * Passing REGION_DEFAULT_GRANULARITY is also allowed and means that the library
50*91f16700Schasinglulu  * is free to choose the granularity for this region. In this case, it is
51*91f16700Schasinglulu  * equivalent to the MAP_REGION() macro.
52*91f16700Schasinglulu  */
53*91f16700Schasinglulu #define MAP_REGION2(_pa, _va, _sz, _attr, _gr)			\
54*91f16700Schasinglulu 	MAP_REGION_FULL_SPEC(_pa, _va, _sz, _attr, _gr)
55*91f16700Schasinglulu 
56*91f16700Schasinglulu /*
57*91f16700Schasinglulu  * Shifts and masks to access fields of an mmap attribute
58*91f16700Schasinglulu  */
59*91f16700Schasinglulu #define MT_TYPE_MASK		U(0x7)
60*91f16700Schasinglulu #define MT_TYPE(_attr)		((_attr) & MT_TYPE_MASK)
61*91f16700Schasinglulu /* Access permissions (RO/RW) */
62*91f16700Schasinglulu #define MT_PERM_SHIFT		U(3)
63*91f16700Schasinglulu 
64*91f16700Schasinglulu /* Physical address space (SECURE/NS/Root/Realm) */
65*91f16700Schasinglulu #define	MT_PAS_SHIFT		U(4)
66*91f16700Schasinglulu #define MT_PAS_MASK		(U(3) << MT_PAS_SHIFT)
67*91f16700Schasinglulu #define MT_PAS(_attr)		((_attr) & MT_PAS_MASK)
68*91f16700Schasinglulu 
69*91f16700Schasinglulu /* Access permissions for instruction execution (EXECUTE/EXECUTE_NEVER) */
70*91f16700Schasinglulu #define MT_EXECUTE_SHIFT	U(6)
71*91f16700Schasinglulu /* In the EL1&0 translation regime, User (EL0) or Privileged (EL1). */
72*91f16700Schasinglulu #define MT_USER_SHIFT		U(7)
73*91f16700Schasinglulu 
74*91f16700Schasinglulu /* Shareability attribute for the memory region */
75*91f16700Schasinglulu #define MT_SHAREABILITY_SHIFT	U(8)
76*91f16700Schasinglulu #define MT_SHAREABILITY_MASK	(U(3) << MT_SHAREABILITY_SHIFT)
77*91f16700Schasinglulu #define MT_SHAREABILITY(_attr)	((_attr) & MT_SHAREABILITY_MASK)
78*91f16700Schasinglulu 
79*91f16700Schasinglulu /* All other bits are reserved */
80*91f16700Schasinglulu 
81*91f16700Schasinglulu /*
82*91f16700Schasinglulu  * Memory mapping attributes
83*91f16700Schasinglulu  */
84*91f16700Schasinglulu 
85*91f16700Schasinglulu /*
86*91f16700Schasinglulu  * Memory types supported.
87*91f16700Schasinglulu  * These are organised so that, going down the list, the memory types are
88*91f16700Schasinglulu  * getting weaker; conversely going up the list the memory types are getting
89*91f16700Schasinglulu  * stronger.
90*91f16700Schasinglulu  */
91*91f16700Schasinglulu #define MT_DEVICE		U(0)
92*91f16700Schasinglulu #define MT_NON_CACHEABLE	U(1)
93*91f16700Schasinglulu #define MT_MEMORY		U(2)
94*91f16700Schasinglulu /* Values up to 7 are reserved to add new memory types in the future */
95*91f16700Schasinglulu 
96*91f16700Schasinglulu #define MT_RO			(U(0) << MT_PERM_SHIFT)
97*91f16700Schasinglulu #define MT_RW			(U(1) << MT_PERM_SHIFT)
98*91f16700Schasinglulu 
99*91f16700Schasinglulu #define MT_SECURE		(U(0) << MT_PAS_SHIFT)
100*91f16700Schasinglulu #define MT_NS			(U(1) << MT_PAS_SHIFT)
101*91f16700Schasinglulu #define MT_ROOT			(U(2) << MT_PAS_SHIFT)
102*91f16700Schasinglulu #define MT_REALM		(U(3) << MT_PAS_SHIFT)
103*91f16700Schasinglulu 
104*91f16700Schasinglulu /*
105*91f16700Schasinglulu  * Access permissions for instruction execution are only relevant for normal
106*91f16700Schasinglulu  * read-only memory, i.e. MT_MEMORY | MT_RO. They are ignored (and potentially
107*91f16700Schasinglulu  * overridden) otherwise:
108*91f16700Schasinglulu  *  - Device memory is always marked as execute-never.
109*91f16700Schasinglulu  *  - Read-write normal memory is always marked as execute-never.
110*91f16700Schasinglulu  */
111*91f16700Schasinglulu #define MT_EXECUTE		(U(0) << MT_EXECUTE_SHIFT)
112*91f16700Schasinglulu #define MT_EXECUTE_NEVER	(U(1) << MT_EXECUTE_SHIFT)
113*91f16700Schasinglulu 
114*91f16700Schasinglulu /*
115*91f16700Schasinglulu  * When mapping a region at EL0 or EL1, this attribute will be used to determine
116*91f16700Schasinglulu  * if a User mapping (EL0) will be created or a Privileged mapping (EL1).
117*91f16700Schasinglulu  */
118*91f16700Schasinglulu #define MT_USER			(U(1) << MT_USER_SHIFT)
119*91f16700Schasinglulu #define MT_PRIVILEGED		(U(0) << MT_USER_SHIFT)
120*91f16700Schasinglulu 
121*91f16700Schasinglulu /*
122*91f16700Schasinglulu  * Shareability defines the visibility of any cache changes to
123*91f16700Schasinglulu  * all masters belonging to a shareable domain.
124*91f16700Schasinglulu  *
125*91f16700Schasinglulu  * MT_SHAREABILITY_ISH: For inner shareable domain
126*91f16700Schasinglulu  * MT_SHAREABILITY_OSH: For outer shareable domain
127*91f16700Schasinglulu  * MT_SHAREABILITY_NSH: For non shareable domain
128*91f16700Schasinglulu  */
129*91f16700Schasinglulu #define MT_SHAREABILITY_ISH	(U(1) << MT_SHAREABILITY_SHIFT)
130*91f16700Schasinglulu #define MT_SHAREABILITY_OSH	(U(2) << MT_SHAREABILITY_SHIFT)
131*91f16700Schasinglulu #define MT_SHAREABILITY_NSH	(U(3) << MT_SHAREABILITY_SHIFT)
132*91f16700Schasinglulu 
133*91f16700Schasinglulu /* Compound attributes for most common usages */
134*91f16700Schasinglulu #define MT_CODE			(MT_MEMORY | MT_RO | MT_EXECUTE)
135*91f16700Schasinglulu #define MT_RO_DATA		(MT_MEMORY | MT_RO | MT_EXECUTE_NEVER)
136*91f16700Schasinglulu #define MT_RW_DATA		(MT_MEMORY | MT_RW | MT_EXECUTE_NEVER)
137*91f16700Schasinglulu 
138*91f16700Schasinglulu /*
139*91f16700Schasinglulu  * Structure for specifying a single region of memory.
140*91f16700Schasinglulu  */
141*91f16700Schasinglulu typedef struct mmap_region {
142*91f16700Schasinglulu 	unsigned long long	base_pa;
143*91f16700Schasinglulu 	uintptr_t		base_va;
144*91f16700Schasinglulu 	size_t			size;
145*91f16700Schasinglulu 	unsigned int		attr;
146*91f16700Schasinglulu 	/* Desired granularity. See the MAP_REGION2() macro for more details. */
147*91f16700Schasinglulu 	size_t			granularity;
148*91f16700Schasinglulu } mmap_region_t;
149*91f16700Schasinglulu 
150*91f16700Schasinglulu /*
151*91f16700Schasinglulu  * Translation regimes supported by this library. EL_REGIME_INVALID tells the
152*91f16700Schasinglulu  * library to detect it at runtime.
153*91f16700Schasinglulu  */
154*91f16700Schasinglulu #define EL1_EL0_REGIME		1
155*91f16700Schasinglulu #define EL2_REGIME		2
156*91f16700Schasinglulu #define EL3_REGIME		3
157*91f16700Schasinglulu #define EL_REGIME_INVALID	-1
158*91f16700Schasinglulu 
159*91f16700Schasinglulu /* Memory type for EL3 regions. With RME, EL3 is in ROOT PAS */
160*91f16700Schasinglulu #if ENABLE_RME
161*91f16700Schasinglulu #define EL3_PAS			MT_ROOT
162*91f16700Schasinglulu #else
163*91f16700Schasinglulu #define EL3_PAS			MT_SECURE
164*91f16700Schasinglulu #endif /* ENABLE_RME */
165*91f16700Schasinglulu 
166*91f16700Schasinglulu /*
167*91f16700Schasinglulu  * Declare the translation context type.
168*91f16700Schasinglulu  * Its definition is private.
169*91f16700Schasinglulu  */
170*91f16700Schasinglulu typedef struct xlat_ctx xlat_ctx_t;
171*91f16700Schasinglulu 
172*91f16700Schasinglulu /*
173*91f16700Schasinglulu  * Statically allocate a translation context and associated structures. Also
174*91f16700Schasinglulu  * initialize them.
175*91f16700Schasinglulu  *
176*91f16700Schasinglulu  * _ctx_name:
177*91f16700Schasinglulu  *   Prefix for the translation context variable.
178*91f16700Schasinglulu  *   E.g. If _ctx_name is 'foo', the variable will be called 'foo_xlat_ctx'.
179*91f16700Schasinglulu  *   Useful to distinguish multiple contexts from one another.
180*91f16700Schasinglulu  *
181*91f16700Schasinglulu  * _mmap_count:
182*91f16700Schasinglulu  *   Number of mmap_region_t to allocate.
183*91f16700Schasinglulu  *   Would typically be MAX_MMAP_REGIONS for the translation context describing
184*91f16700Schasinglulu  *   the BL image currently executing.
185*91f16700Schasinglulu  *
186*91f16700Schasinglulu  * _xlat_tables_count:
187*91f16700Schasinglulu  *   Number of sub-translation tables to allocate.
188*91f16700Schasinglulu  *   Would typically be MAX_XLAT_TABLES for the translation context describing
189*91f16700Schasinglulu  *   the BL image currently executing.
190*91f16700Schasinglulu  *   Note that this is only for sub-tables ; at the initial lookup level, there
191*91f16700Schasinglulu  *   is always a single table.
192*91f16700Schasinglulu  *
193*91f16700Schasinglulu  * _virt_addr_space_size, _phy_addr_space_size:
194*91f16700Schasinglulu  *   Size (in bytes) of the virtual (resp. physical) address space.
195*91f16700Schasinglulu  *   Would typically be PLAT_VIRT_ADDR_SPACE_SIZE
196*91f16700Schasinglulu  *   (resp. PLAT_PHY_ADDR_SPACE_SIZE) for the translation context describing the
197*91f16700Schasinglulu  *   BL image currently executing.
198*91f16700Schasinglulu  */
199*91f16700Schasinglulu #define REGISTER_XLAT_CONTEXT(_ctx_name, _mmap_count, _xlat_tables_count, \
200*91f16700Schasinglulu 			      _virt_addr_space_size, _phy_addr_space_size) \
201*91f16700Schasinglulu 	REGISTER_XLAT_CONTEXT_FULL_SPEC(_ctx_name, (_mmap_count),	\
202*91f16700Schasinglulu 					 (_xlat_tables_count),		\
203*91f16700Schasinglulu 					 (_virt_addr_space_size),	\
204*91f16700Schasinglulu 					 (_phy_addr_space_size),	\
205*91f16700Schasinglulu 					 EL_REGIME_INVALID,		\
206*91f16700Schasinglulu 					 ".xlat_table", ".base_xlat_table")
207*91f16700Schasinglulu 
208*91f16700Schasinglulu /*
209*91f16700Schasinglulu  * Same as REGISTER_XLAT_CONTEXT plus the additional parameters:
210*91f16700Schasinglulu  *
211*91f16700Schasinglulu  * _xlat_regime:
212*91f16700Schasinglulu  *   Specify the translation regime managed by this xlat_ctx_t instance. The
213*91f16700Schasinglulu  *   values are the one from the EL*_REGIME definitions.
214*91f16700Schasinglulu  *
215*91f16700Schasinglulu  * _section_name:
216*91f16700Schasinglulu  *   Specify the name of the section where the translation tables have to be
217*91f16700Schasinglulu  *   placed by the linker.
218*91f16700Schasinglulu  *
219*91f16700Schasinglulu  * _base_table_section_name:
220*91f16700Schasinglulu  *   Specify the name of the section where the base translation tables have to
221*91f16700Schasinglulu  *   be placed by the linker.
222*91f16700Schasinglulu  */
223*91f16700Schasinglulu #define REGISTER_XLAT_CONTEXT2(_ctx_name, _mmap_count, _xlat_tables_count, \
224*91f16700Schasinglulu 			_virt_addr_space_size, _phy_addr_space_size,	\
225*91f16700Schasinglulu 			_xlat_regime, _section_name, _base_table_section_name) \
226*91f16700Schasinglulu 	REGISTER_XLAT_CONTEXT_FULL_SPEC(_ctx_name, (_mmap_count),	\
227*91f16700Schasinglulu 					 (_xlat_tables_count),		\
228*91f16700Schasinglulu 					 (_virt_addr_space_size),	\
229*91f16700Schasinglulu 					 (_phy_addr_space_size),	\
230*91f16700Schasinglulu 					 (_xlat_regime),		\
231*91f16700Schasinglulu 					 (_section_name), (_base_table_section_name) \
232*91f16700Schasinglulu )
233*91f16700Schasinglulu 
234*91f16700Schasinglulu /******************************************************************************
235*91f16700Schasinglulu  * Generic translation table APIs.
236*91f16700Schasinglulu  * Each API comes in 2 variants:
237*91f16700Schasinglulu  * - one that acts on the current translation context for this BL image
238*91f16700Schasinglulu  * - another that acts on the given translation context instead. This variant
239*91f16700Schasinglulu  *   is named after the 1st version, with an additional '_ctx' suffix.
240*91f16700Schasinglulu  *****************************************************************************/
241*91f16700Schasinglulu 
242*91f16700Schasinglulu /*
243*91f16700Schasinglulu  * Initialize translation tables from the current list of mmap regions. Calling
244*91f16700Schasinglulu  * this function marks the transition point after which static regions can no
245*91f16700Schasinglulu  * longer be added.
246*91f16700Schasinglulu  */
247*91f16700Schasinglulu void init_xlat_tables(void);
248*91f16700Schasinglulu void init_xlat_tables_ctx(xlat_ctx_t *ctx);
249*91f16700Schasinglulu 
250*91f16700Schasinglulu /*
251*91f16700Schasinglulu  * Fill all fields of a dynamic translation tables context. It must be done
252*91f16700Schasinglulu  * either statically with REGISTER_XLAT_CONTEXT() or at runtime with this
253*91f16700Schasinglulu  * function.
254*91f16700Schasinglulu  */
255*91f16700Schasinglulu void xlat_setup_dynamic_ctx(xlat_ctx_t *ctx, unsigned long long pa_max,
256*91f16700Schasinglulu 			    uintptr_t va_max, struct mmap_region *mmap,
257*91f16700Schasinglulu 			    unsigned int mmap_num, uint64_t **tables,
258*91f16700Schasinglulu 			    unsigned int tables_num, uint64_t *base_table,
259*91f16700Schasinglulu 			    int xlat_regime, int *mapped_regions);
260*91f16700Schasinglulu 
261*91f16700Schasinglulu /*
262*91f16700Schasinglulu  * Add a static region with defined base PA and base VA. This function can only
263*91f16700Schasinglulu  * be used before initializing the translation tables. The region cannot be
264*91f16700Schasinglulu  * removed afterwards.
265*91f16700Schasinglulu  */
266*91f16700Schasinglulu void mmap_add_region(unsigned long long base_pa, uintptr_t base_va,
267*91f16700Schasinglulu 		     size_t size, unsigned int attr);
268*91f16700Schasinglulu void mmap_add_region_ctx(xlat_ctx_t *ctx, const mmap_region_t *mm);
269*91f16700Schasinglulu 
270*91f16700Schasinglulu /*
271*91f16700Schasinglulu  * Add an array of static regions with defined base PA and base VA. This
272*91f16700Schasinglulu  * function can only be used before initializing the translation tables. The
273*91f16700Schasinglulu  * regions cannot be removed afterwards.
274*91f16700Schasinglulu  */
275*91f16700Schasinglulu void mmap_add(const mmap_region_t *mm);
276*91f16700Schasinglulu void mmap_add_ctx(xlat_ctx_t *ctx, const mmap_region_t *mm);
277*91f16700Schasinglulu 
278*91f16700Schasinglulu /*
279*91f16700Schasinglulu  * Add a region with defined base PA. Returns base VA calculated using the
280*91f16700Schasinglulu  * highest existing region in the mmap array even if it fails to allocate the
281*91f16700Schasinglulu  * region.
282*91f16700Schasinglulu  */
283*91f16700Schasinglulu void mmap_add_region_alloc_va(unsigned long long base_pa, uintptr_t *base_va,
284*91f16700Schasinglulu 			      size_t size, unsigned int attr);
285*91f16700Schasinglulu void mmap_add_region_alloc_va_ctx(xlat_ctx_t *ctx, mmap_region_t *mm);
286*91f16700Schasinglulu 
287*91f16700Schasinglulu /*
288*91f16700Schasinglulu  * Add an array of static regions with defined base PA, and fill the base VA
289*91f16700Schasinglulu  * field on the array of structs. This function can only be used before
290*91f16700Schasinglulu  * initializing the translation tables. The regions cannot be removed afterwards.
291*91f16700Schasinglulu  */
292*91f16700Schasinglulu void mmap_add_alloc_va(mmap_region_t *mm);
293*91f16700Schasinglulu 
294*91f16700Schasinglulu #if PLAT_XLAT_TABLES_DYNAMIC
295*91f16700Schasinglulu /*
296*91f16700Schasinglulu  * Add a dynamic region with defined base PA and base VA. This type of region
297*91f16700Schasinglulu  * can be added and removed even after the translation tables are initialized.
298*91f16700Schasinglulu  *
299*91f16700Schasinglulu  * Returns:
300*91f16700Schasinglulu  *        0: Success.
301*91f16700Schasinglulu  *   EINVAL: Invalid values were used as arguments.
302*91f16700Schasinglulu  *   ERANGE: Memory limits were surpassed.
303*91f16700Schasinglulu  *   ENOMEM: Not enough space in the mmap array or not enough free xlat tables.
304*91f16700Schasinglulu  *    EPERM: It overlaps another region in an invalid way.
305*91f16700Schasinglulu  */
306*91f16700Schasinglulu int mmap_add_dynamic_region(unsigned long long base_pa, uintptr_t base_va,
307*91f16700Schasinglulu 			    size_t size, unsigned int attr);
308*91f16700Schasinglulu int mmap_add_dynamic_region_ctx(xlat_ctx_t *ctx, mmap_region_t *mm);
309*91f16700Schasinglulu 
310*91f16700Schasinglulu /*
311*91f16700Schasinglulu  * Add a dynamic region with defined base PA. Returns base VA calculated using
312*91f16700Schasinglulu  * the highest existing region in the mmap array even if it fails to allocate
313*91f16700Schasinglulu  * the region.
314*91f16700Schasinglulu  *
315*91f16700Schasinglulu  * mmap_add_dynamic_region_alloc_va() returns the allocated VA in 'base_va'.
316*91f16700Schasinglulu  * mmap_add_dynamic_region_alloc_va_ctx() returns it in 'mm->base_va'.
317*91f16700Schasinglulu  *
318*91f16700Schasinglulu  * It returns the same error values as mmap_add_dynamic_region().
319*91f16700Schasinglulu  */
320*91f16700Schasinglulu int mmap_add_dynamic_region_alloc_va(unsigned long long base_pa,
321*91f16700Schasinglulu 				     uintptr_t *base_va,
322*91f16700Schasinglulu 				     size_t size, unsigned int attr);
323*91f16700Schasinglulu int mmap_add_dynamic_region_alloc_va_ctx(xlat_ctx_t *ctx, mmap_region_t *mm);
324*91f16700Schasinglulu 
325*91f16700Schasinglulu /*
326*91f16700Schasinglulu  * Remove a region with the specified base VA and size. Only dynamic regions can
327*91f16700Schasinglulu  * be removed, and they can be removed even if the translation tables are
328*91f16700Schasinglulu  * initialized.
329*91f16700Schasinglulu  *
330*91f16700Schasinglulu  * Returns:
331*91f16700Schasinglulu  *        0: Success.
332*91f16700Schasinglulu  *   EINVAL: The specified region wasn't found.
333*91f16700Schasinglulu  *    EPERM: Trying to remove a static region.
334*91f16700Schasinglulu  */
335*91f16700Schasinglulu int mmap_remove_dynamic_region(uintptr_t base_va, size_t size);
336*91f16700Schasinglulu int mmap_remove_dynamic_region_ctx(xlat_ctx_t *ctx,
337*91f16700Schasinglulu 				uintptr_t base_va,
338*91f16700Schasinglulu 				size_t size);
339*91f16700Schasinglulu 
340*91f16700Schasinglulu #endif /* PLAT_XLAT_TABLES_DYNAMIC */
341*91f16700Schasinglulu 
342*91f16700Schasinglulu /*
343*91f16700Schasinglulu  * Change the memory attributes of the memory region starting from a given
344*91f16700Schasinglulu  * virtual address in a set of translation tables.
345*91f16700Schasinglulu  *
346*91f16700Schasinglulu  * This function can only be used after the translation tables have been
347*91f16700Schasinglulu  * initialized.
348*91f16700Schasinglulu  *
349*91f16700Schasinglulu  * The base address of the memory region must be aligned on a page boundary.
350*91f16700Schasinglulu  * The size of this memory region must be a multiple of a page size.
351*91f16700Schasinglulu  * The memory region must be already mapped by the given translation tables
352*91f16700Schasinglulu  * and it must be mapped at the granularity of a page.
353*91f16700Schasinglulu  *
354*91f16700Schasinglulu  * Return 0 on success, a negative value on error.
355*91f16700Schasinglulu  *
356*91f16700Schasinglulu  * In case of error, the memory attributes remain unchanged and this function
357*91f16700Schasinglulu  * has no effect.
358*91f16700Schasinglulu  *
359*91f16700Schasinglulu  * ctx
360*91f16700Schasinglulu  *   Translation context to work on.
361*91f16700Schasinglulu  * base_va:
362*91f16700Schasinglulu  *   Virtual address of the 1st page to change the attributes of.
363*91f16700Schasinglulu  * size:
364*91f16700Schasinglulu  *   Size in bytes of the memory region.
365*91f16700Schasinglulu  * attr:
366*91f16700Schasinglulu  *   New attributes of the page tables. The attributes that can be changed are
367*91f16700Schasinglulu  *   data access (MT_RO/MT_RW), instruction access (MT_EXECUTE_NEVER/MT_EXECUTE)
368*91f16700Schasinglulu  *   and user/privileged access (MT_USER/MT_PRIVILEGED) in the case of contexts
369*91f16700Schasinglulu  *   that are used in the EL1&0 translation regime. Also, note that this
370*91f16700Schasinglulu  *   function doesn't allow to remap a region as RW and executable, or to remap
371*91f16700Schasinglulu  *   device memory as executable.
372*91f16700Schasinglulu  *
373*91f16700Schasinglulu  * NOTE: The caller of this function must be able to write to the translation
374*91f16700Schasinglulu  * tables, i.e. the memory where they are stored must be mapped with read-write
375*91f16700Schasinglulu  * access permissions. This function assumes it is the case. If this is not
376*91f16700Schasinglulu  * the case then this function might trigger a data abort exception.
377*91f16700Schasinglulu  *
378*91f16700Schasinglulu  * NOTE2: The caller is responsible for making sure that the targeted
379*91f16700Schasinglulu  * translation tables are not modified by any other code while this function is
380*91f16700Schasinglulu  * executing.
381*91f16700Schasinglulu  */
382*91f16700Schasinglulu int xlat_change_mem_attributes_ctx(const xlat_ctx_t *ctx, uintptr_t base_va,
383*91f16700Schasinglulu 				   size_t size, uint32_t attr);
384*91f16700Schasinglulu int xlat_change_mem_attributes(uintptr_t base_va, size_t size, uint32_t attr);
385*91f16700Schasinglulu 
386*91f16700Schasinglulu #if PLAT_RO_XLAT_TABLES
387*91f16700Schasinglulu /*
388*91f16700Schasinglulu  * Change the memory attributes of the memory region encompassing the higher
389*91f16700Schasinglulu  * level translation tables to secure read-only data.
390*91f16700Schasinglulu  *
391*91f16700Schasinglulu  * Return 0 on success, a negative error code on error.
392*91f16700Schasinglulu  */
393*91f16700Schasinglulu int xlat_make_tables_readonly(void);
394*91f16700Schasinglulu #endif
395*91f16700Schasinglulu 
396*91f16700Schasinglulu /*
397*91f16700Schasinglulu  * Query the memory attributes of a memory page in a set of translation tables.
398*91f16700Schasinglulu  *
399*91f16700Schasinglulu  * Return 0 on success, a negative error code on error.
400*91f16700Schasinglulu  * On success, the attributes are stored into *attr.
401*91f16700Schasinglulu  *
402*91f16700Schasinglulu  * ctx
403*91f16700Schasinglulu  *   Translation context to work on.
404*91f16700Schasinglulu  * base_va
405*91f16700Schasinglulu  *   Virtual address of the page to get the attributes of.
406*91f16700Schasinglulu  *   There are no alignment restrictions on this address. The attributes of the
407*91f16700Schasinglulu  *   memory page it lies within are returned.
408*91f16700Schasinglulu  * attr
409*91f16700Schasinglulu  *   Output parameter where to store the attributes of the targeted memory page.
410*91f16700Schasinglulu  */
411*91f16700Schasinglulu int xlat_get_mem_attributes_ctx(const xlat_ctx_t *ctx, uintptr_t base_va,
412*91f16700Schasinglulu 				uint32_t *attr);
413*91f16700Schasinglulu int xlat_get_mem_attributes(uintptr_t base_va, uint32_t *attr);
414*91f16700Schasinglulu 
415*91f16700Schasinglulu #endif /*__ASSEMBLER__*/
416*91f16700Schasinglulu #endif /* XLAT_TABLES_V2_H */
417