blob: 5b0697d7ba027866dae8018375e05959643a24e8 [file] [log] [blame]
Gary Morrison5fb061e2021-01-27 13:08:47 -06001/*
Boyan Karatotev2cadf212025-03-12 11:45:05 +00002 * Copyright (c) 2021-2025, Arm Limited and Contributors. All rights reserved.
Gary Morrison5fb061e2021-01-27 13:08:47 -06003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef XLAT_MPU_PRIVATE_H
8#define XLAT_MPU_PRIVATE_H
9
10#include <stdbool.h>
11
12#include <lib/xlat_tables/xlat_tables_defs.h>
13#include <lib/xlat_tables/xlat_tables_v2.h>
14
15#include <platform_def.h>
16
17#if PLAT_XLAT_TABLES_DYNAMIC
18/*
19 * Private shifts and masks to access fields of an mmap attribute
20 */
21/* Dynamic or static */
22#define MT_DYN_SHIFT U(31)
23
24/*
25 * Memory mapping private attributes
26 *
27 * Private attributes not exposed in the public header.
28 */
29
30#endif /* PLAT_XLAT_TABLES_DYNAMIC */
31
32/* Calculate region-attributes byte for PRBAR part of MPU-region descriptor: */
33uint64_t prbar_attr_value(uint32_t attr);
34/* Calculate region-attributes byte for PRLAR part of MPU-region descriptor: */
35uint64_t prlar_attr_value(uint32_t attr);
36/* Calculates the attr value for a given PRBAR and PRLAR entry value: */
37uint32_t region_attr(uint64_t prbar_attr, uint64_t prlar_attr);
38
39#define PRBAR_PRLAR_ADDR_MASK UL(0xffffffffffc0)
40 /* mask for PRBAR & PRLAR MPU-region field */
41/* MPU region attribute bit fields: */
42#define PRBAR_SH_SHIFT UL(4)
43#define PRBAR_SH_MASK UL(0x3)
44#define PRBAR_AP_SHIFT UL(2)
45#define PRBAR_AP_MASK UL(0x3)
46#define PRBAR_XN_SHIFT UL(1)
47#define PRBAR_XN_MASK UL(0x3)
48#define PRLAR_NS_SHIFT UL(4)
49#define PRLAR_NS_MASK UL(0x3)
50#define PRBAR_ATTR_SHIFT UL(0)
51#define PRBAR_ATTR_MASK UL(0x3f)
52#define PRLAR_ATTR_SHIFT UL(1)
53#define PRLAR_ATTR_MASK UL(0x7)
54#define PRLAR_EN_SHIFT UL(0)
55#define PRLAR_EN_MASK UL(0x1)
56/* Aspects of the source attributes not defined elsewhere: */
57#define MT_PERM_MASK UL(0x1)
58#define MT_SEC_MASK UL(0x1)
59#define MT_EXECUTE_MASK UL(0x3)
60#define MT_TYPE_SHIFT UL(0)
61
Boyan Karatotev2cadf212025-03-12 11:45:05 +000062#define MPUIR_EL2 S3_4_C0_C0_4
63#define PRBAR_EL2 S3_4_C6_C8_0
64#define PRLAR_EL2 S3_4_C6_C8_1
65#define PRSELR_EL2 S3_4_C6_C2_1
66#define PRENR_EL2 S3_4_C6_C1_1
67
68/* v8-R64 MPU registers */
69DEFINE_RENAME_SYSREG_RW_FUNCS(mpuir_el2, MPUIR_EL2)
70DEFINE_RENAME_SYSREG_RW_FUNCS(prenr_el2, PRENR_EL2)
71DEFINE_RENAME_SYSREG_RW_FUNCS(prselr_el2, PRSELR_EL2)
72DEFINE_RENAME_SYSREG_RW_FUNCS(prbar_el2, PRBAR_EL2)
73DEFINE_RENAME_SYSREG_RW_FUNCS(prlar_el2, PRLAR_EL2)
74
Gary Morrison5fb061e2021-01-27 13:08:47 -060075extern uint64_t mmu_cfg_params[MMU_CFG_PARAM_MAX];
76
77/*
78 * Return the execute-never mask that will prevent instruction fetch at the
79 * given translation regime.
80 */
81uint64_t xlat_arch_regime_get_xn_desc(int xlat_regime);
82
83/* Print VA, PA, size and attributes of all regions in the mmap array. */
84void xlat_mmap_print(const mmap_region_t *mmap);
85
86/*
87 * Print the current state of the translation tables by reading them from
88 * memory.
89 */
90void xlat_tables_print(xlat_ctx_t *ctx);
91
92/*
93 * Returns a block/page table descriptor for the given level and attributes.
94 */
95uint64_t xlat_desc(const xlat_ctx_t *ctx, uint32_t attr,
96 unsigned long long addr_pa, unsigned int level);
97
98/*
99 * Architecture-specific initialization code.
100 */
101
102/* Returns the current Exception Level. The returned EL must be 1 or higher. */
103unsigned int xlat_arch_current_el(void);
104
105/*
106 * Returns true if the MMU of the translation regime managed by the given
107 * xlat_ctx_t is enabled, false otherwise.
108 */
109bool is_mpu_enabled_ctx(const xlat_ctx_t *ctx);
110
111/*
112 * Returns minimum virtual address space size supported by the architecture
113 */
114uintptr_t xlat_get_min_virt_addr_space_size(void);
115
116#endif /* XLAT_MPU_PRIVATE_H */