xref: /rk3399_ARM-atf/lib/xlat_tables_v2/xlat_tables_private.h (revision b4ae615bd734104cfed5d2534b4c14278415057e)
17bb01fb2SAntonio Nino Diaz /*
27bb01fb2SAntonio Nino Diaz  * Copyright (c) 2017, ARM Limited and Contributors. All rights reserved.
37bb01fb2SAntonio Nino Diaz  *
482cb2c1aSdp-arm  * SPDX-License-Identifier: BSD-3-Clause
57bb01fb2SAntonio Nino Diaz  */
67bb01fb2SAntonio Nino Diaz 
77bb01fb2SAntonio Nino Diaz #ifndef __XLAT_TABLES_PRIVATE_H__
87bb01fb2SAntonio Nino Diaz #define __XLAT_TABLES_PRIVATE_H__
97bb01fb2SAntonio Nino Diaz 
107bb01fb2SAntonio Nino Diaz #include <platform_def.h>
118933c34bSSandrine Bailleux #include <xlat_tables_defs.h>
127bb01fb2SAntonio Nino Diaz 
130b64f4efSAntonio Nino Diaz #if PLAT_XLAT_TABLES_DYNAMIC
140b64f4efSAntonio Nino Diaz /*
150b64f4efSAntonio Nino Diaz  * Shifts and masks to access fields of an mmap_attr_t
160b64f4efSAntonio Nino Diaz  */
170b64f4efSAntonio Nino Diaz /* Dynamic or static */
180b64f4efSAntonio Nino Diaz #define MT_DYN_SHIFT		30 /* 31 would cause undefined behaviours */
190b64f4efSAntonio Nino Diaz 
200b64f4efSAntonio Nino Diaz /*
210b64f4efSAntonio Nino Diaz  * Memory mapping private attributes
220b64f4efSAntonio Nino Diaz  *
230b64f4efSAntonio Nino Diaz  * Private attributes not exposed in the mmap_attr_t enum.
240b64f4efSAntonio Nino Diaz  */
250b64f4efSAntonio Nino Diaz typedef enum  {
260b64f4efSAntonio Nino Diaz 	/*
270b64f4efSAntonio Nino Diaz 	 * Regions mapped before the MMU can't be unmapped dynamically (they are
280b64f4efSAntonio Nino Diaz 	 * static) and regions mapped with MMU enabled can be unmapped. This
290b64f4efSAntonio Nino Diaz 	 * behaviour can't be overridden.
300b64f4efSAntonio Nino Diaz 	 *
310b64f4efSAntonio Nino Diaz 	 * Static regions can overlap each other, dynamic regions can't.
320b64f4efSAntonio Nino Diaz 	 */
330b64f4efSAntonio Nino Diaz 	MT_STATIC	= 0 << MT_DYN_SHIFT,
340b64f4efSAntonio Nino Diaz 	MT_DYNAMIC	= 1 << MT_DYN_SHIFT
350b64f4efSAntonio Nino Diaz } mmap_priv_attr_t;
360b64f4efSAntonio Nino Diaz 
37f301da44SSandrine Bailleux #endif /* PLAT_XLAT_TABLES_DYNAMIC */
38f301da44SSandrine Bailleux 
390b64f4efSAntonio Nino Diaz /*
40*b4ae615bSDouglas Raillard  * Invalidate all TLB entries that match the given virtual address. This
41*b4ae615bSDouglas Raillard  * operation applies to all PEs in the same Inner Shareable domain as the PE
42*b4ae615bSDouglas Raillard  * that executes this function. This functions must be called for every
43*b4ae615bSDouglas Raillard  * translation table entry that is modified.
44*b4ae615bSDouglas Raillard  *
45*b4ae615bSDouglas Raillard  * xlat_arch_tlbi_va() applies the invalidation to the exception level of the
46*b4ae615bSDouglas Raillard  * current translation regime, whereas xlat_arch_tlbi_va_regime() applies it to
47*b4ae615bSDouglas Raillard  * the given translation regime.
48*b4ae615bSDouglas Raillard  *
49*b4ae615bSDouglas Raillard  * Note, however, that it is architecturally UNDEFINED to invalidate TLB entries
50*b4ae615bSDouglas Raillard  * pertaining to a higher exception level, e.g. invalidating EL3 entries from
51*b4ae615bSDouglas Raillard  * S-EL1.
520b64f4efSAntonio Nino Diaz  */
530b64f4efSAntonio Nino Diaz void xlat_arch_tlbi_va(uintptr_t va);
54*b4ae615bSDouglas Raillard void xlat_arch_tlbi_va_regime(uintptr_t va, xlat_regime_t xlat_regime);
550b64f4efSAntonio Nino Diaz 
560b64f4efSAntonio Nino Diaz /*
570b64f4efSAntonio Nino Diaz  * This function has to be called at the end of any code that uses the function
580b64f4efSAntonio Nino Diaz  * xlat_arch_tlbi_va().
590b64f4efSAntonio Nino Diaz  */
600b64f4efSAntonio Nino Diaz void xlat_arch_tlbi_va_sync(void);
610b64f4efSAntonio Nino Diaz 
627bb01fb2SAntonio Nino Diaz /* Print VA, PA, size and attributes of all regions in the mmap array. */
637bb01fb2SAntonio Nino Diaz void print_mmap(mmap_region_t *const mmap);
647bb01fb2SAntonio Nino Diaz 
657bb01fb2SAntonio Nino Diaz /*
667bb01fb2SAntonio Nino Diaz  * Print the current state of the translation tables by reading them from
677bb01fb2SAntonio Nino Diaz  * memory.
687bb01fb2SAntonio Nino Diaz  */
697bb01fb2SAntonio Nino Diaz void xlat_tables_print(xlat_ctx_t *ctx);
707bb01fb2SAntonio Nino Diaz 
717bb01fb2SAntonio Nino Diaz /*
727bb01fb2SAntonio Nino Diaz  * Architecture-specific initialization code.
737bb01fb2SAntonio Nino Diaz  */
747bb01fb2SAntonio Nino Diaz 
75a5640252SAntonio Nino Diaz /* Returns the current Exception Level. The returned EL must be 1 or higher. */
76a5640252SAntonio Nino Diaz int xlat_arch_current_el(void);
77a5640252SAntonio Nino Diaz 
78a5640252SAntonio Nino Diaz /*
79a5640252SAntonio Nino Diaz  * Returns the bit mask that has to be ORed to the rest of a translation table
80a5640252SAntonio Nino Diaz  * descriptor so that execution of code is prohibited at the given Exception
81a5640252SAntonio Nino Diaz  * Level.
82a5640252SAntonio Nino Diaz  */
83a5640252SAntonio Nino Diaz uint64_t xlat_arch_get_xn_desc(int el);
84a5640252SAntonio Nino Diaz 
8599f60798SSandrine Bailleux /*
8699f60798SSandrine Bailleux  * Return the maximum physical address supported by the hardware.
8799f60798SSandrine Bailleux  * This value depends on the execution state (AArch32/AArch64).
8899f60798SSandrine Bailleux  */
8999f60798SSandrine Bailleux unsigned long long xlat_arch_get_max_supported_pa(void);
907bb01fb2SAntonio Nino Diaz 
917bb01fb2SAntonio Nino Diaz /* Enable MMU and configure it to use the specified translation tables. */
92347621bbSSandrine Bailleux void enable_mmu_arch(unsigned int flags, uint64_t *base_table,
93347621bbSSandrine Bailleux 		unsigned long long pa, uintptr_t max_va);
947bb01fb2SAntonio Nino Diaz 
957bb01fb2SAntonio Nino Diaz /* Return 1 if the MMU of this Exception Level is enabled, 0 otherwise. */
967bb01fb2SAntonio Nino Diaz int is_mmu_enabled(void);
977bb01fb2SAntonio Nino Diaz 
987bb01fb2SAntonio Nino Diaz #endif /* __XLAT_TABLES_PRIVATE_H__ */
99