summaryrefslogtreecommitdiff
path: root/arch/arm/include/asm/armv8/mpu.h
blob: c6c8828325e63390438d0171d9310eb2cec7cd05 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
 * SPDX-License-Identifier: GPL-2.0+
 *
 * (C) Copyright 2021 Arm Limited
 */

#ifndef _ASM_ARMV8_MPU_H_
#define _ASM_ARMV8_MPU_H_

#include <asm/armv8/mmu.h>
#include <asm/barriers.h>
#include <linux/stringify.h>

#define PRSELR_EL2		S3_4_c6_c2_1
#define PRBAR_EL2		S3_4_c6_c8_0
#define PRLAR_EL2		S3_4_c6_c8_1
#define MPUIR_EL2		S3_4_c0_c0_4

#define PRBAR_ADDRESS(addr)	((addr) & ~(0x3fULL))

/* Access permissions */
#define PRBAR_AP(val)		(((val) & 0x3) << 2)
#define PRBAR_AP_RW_HYP		PRBAR_AP(0x0)
#define PRBAR_AP_RW_ANY		PRBAR_AP(0x1)
#define PRBAR_AP_RO_HYP		PRBAR_AP(0x2)
#define PRBAR_AP_RO_ANY		PRBAR_AP(0x3)

/* Shareability */
#define PRBAR_SH(val)		(((val) & 0x3) << 4)
#define PRBAR_NON_SH		PRBAR_SH(0x0)
#define PRBAR_OUTER_SH		PRBAR_SH(0x2)
#define PRBAR_INNER_SH		PRBAR_SH(0x3)

/* Memory attribute (MAIR idx) */
#define PRLAR_ATTRIDX(val)	(((val) & 0x7) << 1)
#define PRLAR_EN_BIT		(0x1)
#define PRLAR_ADDRESS(addr)	((addr) & ~(0x3fULL))

#ifndef __ASSEMBLY__

static inline void setup_el2_mpu_region(uint8_t region, uint64_t base, uint64_t limit)
{
	asm volatile("msr " __stringify(PRSELR_EL2) ", %0" : : "r" (region));
	isb();
	asm volatile("msr " __stringify(PRBAR_EL2) ", %0" : : "r" (base));
	asm volatile("msr " __stringify(PRLAR_EL2) ", %0" : : "r" (limit));
	dsb();
	isb();
}

#endif

struct mpu_region {
	u64 start;
	u64 end;
	u64 attrs;
};

extern struct mpu_region *mpu_mem_map;

#endif /* _ASM_ARMV8_MPU_H_ */