blob: f40513e8dedea35c1085a83e7f45aba0fac13503 [file] [log] [blame]
Soby Mathewb4c6df42022-11-09 11:13:29 +00001/*
2 * SPDX-License-Identifier: BSD-3-Clause
3 * SPDX-FileCopyrightText: Copyright TF-RMM Contributors.
4 * SPDX-FileCopyrightText: Copyright Arm Limited and Contributors.
5 */
6
7/* This file is derived from xlat_table_v2 library in TF-A project */
8
9#ifndef XLAT_TABLES_PRIVATE_H
10#define XLAT_TABLES_PRIVATE_H
11
12#include <stdbool.h>
13#include <xlat_contexts.h>
14
Javier Almansa Sobrinoed932592023-01-24 12:50:41 +000015/*
16 * Initialize translation tables associated to the current context.
17 *
18 * This function assumes that the xlat_ctx_cfg field of the context has been
19 * properly configured by previous calls to xlat_ctx_cfg_init().
20 *
21 * This function returns 0 on success or an error code otherwise.
22 */
23int xlat_init_tables_ctx(struct xlat_ctx *ctx);
24
Soby Mathewb4c6df42022-11-09 11:13:29 +000025/* Determine the physical address space encoded in the 'attr' parameter. */
26uint64_t xlat_arch_get_pas(uint64_t attr);
27
28/*
29 * Invalidate all TLB entries that match the given virtual address. This
30 * operation applies to all PEs in the same Inner Shareable domain as the PE
31 * that executes this function. This functions must be called for every
32 * translation table entry that is modified. It only affects the EL2
33 * Translate regime
34 */
35void xlat_arch_tlbi_va(uintptr_t va);
36
37/*
38 * This function has to be called at the end of any code that uses the function
39 * xlat_arch_tlbi_va().
40 */
41void xlat_arch_tlbi_va_sync(void);
42
43/* Print VA, PA, size and attributes of all regions in the mmap array. */
44void xlat_mmap_print(const struct xlat_ctx *ctx);
45
46/*
47 * Print the current state of the translation tables by reading them from
48 * memory.
49 */
50void xlat_tables_print(struct xlat_ctx *ctx);
51
52/*
53 * Returns a block/page table descriptor for the given level and attributes.
54 */
55uintptr_t xlat_desc(uint64_t attr, uintptr_t addr_pa, unsigned int level);
56
57/*
58 * Return the maximum physical address supported by the hardware.
59 */
60uintptr_t xlat_arch_get_max_supported_pa(void);
61
62/*
63 * Return the unpriviledged execute-never mask that will prevent instruction
64 * fetch by EL0 at the EL2&0 translation regime.
65 */
66#define XLAT_GET_UXN_DESC() (UPPER_ATTRS(UXN))
67
68/*
69 * Return the priviledged execute-never mask that will prevent instruction
70 * fetch by EL2 at the EL2&0 translation regime.
71 */
72#define XLAT_GET_PXN_DESC() (UPPER_ATTRS(PXN))
73
74/*
75 * Return the contiguous mask for a page or block descriptor
76 */
77#define XLAT_GET_CONT_HINT() (UPPER_ATTRS(CONT_HINT))
78
79/*
80 * Return the NG flag for a page or block descriptor
81 */
82#define XLAT_GET_NG_HINT() (LOWER_ATTRS(NG_HINT))
83
84/*
Soby Mathewb4c6df42022-11-09 11:13:29 +000085 * Initialize an existing xlat_ctx_tbls structure with the given parameters
86 * This macro doesn't check parameters.
87 *
88 * _tlbs:
Javier Almansa Sobrinoed932592023-01-24 12:50:41 +000089 * Pointer to xlat_ctx_tlbs structure.
Soby Mathewb4c6df42022-11-09 11:13:29 +000090 *
91 * _tables:
Javier Almansa Sobrinoed932592023-01-24 12:50:41 +000092 * pointer to a translation table array containing all the translation
93 * tables.
Soby Mathewb4c6df42022-11-09 11:13:29 +000094 *
95 * _tnum:
Javier Almansa Sobrinoed932592023-01-24 12:50:41 +000096 * Maximum number of tables that can fit in the _tables area.
Soby Mathewb4c6df42022-11-09 11:13:29 +000097 */
Javier Almansa Sobrinoed932592023-01-24 12:50:41 +000098#define XLAT_INIT_CTX_TBLS(_tbls, _tables, _tnum) \
Soby Mathewb4c6df42022-11-09 11:13:29 +000099 { \
100 (_tbls)->tables = (_tables); \
101 (_tbls)->tables_num = (_tnum); \
Soby Mathewb4c6df42022-11-09 11:13:29 +0000102 (_tbls)->next_table = 0U; \
103 (_tbls)->initialized = false; \
104 }
105
106#endif /* XLAT_TABLES_PRIVATE_H */