xref: /linux/arch/arm/include/asm/mpu.h (revision 3eb66e91a25497065c5322b1268cbc3953642227)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
2a2b45b0dSJonathan Austin #ifndef __ARM_MPU_H
3a2b45b0dSJonathan Austin #define __ARM_MPU_H
4a2b45b0dSJonathan Austin 
5a2b45b0dSJonathan Austin /* MPUIR layout */
6a2b45b0dSJonathan Austin #define MPUIR_nU		1
7a2b45b0dSJonathan Austin #define MPUIR_DREGION		8
8a2b45b0dSJonathan Austin #define MPUIR_IREGION		16
9a2b45b0dSJonathan Austin #define MPUIR_DREGION_SZMASK	(0xFF << MPUIR_DREGION)
10a2b45b0dSJonathan Austin #define MPUIR_IREGION_SZMASK	(0xFF << MPUIR_IREGION)
11a2b45b0dSJonathan Austin 
12a2b45b0dSJonathan Austin /* ID_MMFR0 data relevant to MPU */
13a2b45b0dSJonathan Austin #define MMFR0_PMSA		(0xF << 4)
14a2b45b0dSJonathan Austin #define MMFR0_PMSAv7		(3 << 4)
15*046835b4SVladimir Murzin #define MMFR0_PMSAv8		(4 << 4)
16a2b45b0dSJonathan Austin 
17a2b45b0dSJonathan Austin /* MPU D/I Size Register fields */
189cfb541aSVladimir Murzin #define PMSAv7_RSR_SZ		1
199cfb541aSVladimir Murzin #define PMSAv7_RSR_EN		0
209cfb541aSVladimir Murzin #define PMSAv7_RSR_SD		8
215c9d9a1bSVladimir Murzin 
225c9d9a1bSVladimir Murzin /* Number of subregions (SD) */
239cfb541aSVladimir Murzin #define PMSAv7_NR_SUBREGS	8
249cfb541aSVladimir Murzin #define PMSAv7_MIN_SUBREG_SIZE	256
25a2b45b0dSJonathan Austin 
26a2b45b0dSJonathan Austin /* The D/I RSR value for an enabled region spanning the whole of memory */
279cfb541aSVladimir Murzin #define PMSAv7_RSR_ALL_MEM	63
28a2b45b0dSJonathan Austin 
29a2b45b0dSJonathan Austin /* Individual bits in the DR/IR ACR */
309cfb541aSVladimir Murzin #define PMSAv7_ACR_XN		(1 << 12)
319cfb541aSVladimir Murzin #define PMSAv7_ACR_SHARED	(1 << 2)
32a2b45b0dSJonathan Austin 
33a2b45b0dSJonathan Austin /* C, B and TEX[2:0] bits only have semantic meanings when grouped */
349cfb541aSVladimir Murzin #define PMSAv7_RGN_CACHEABLE		0xB
359cfb541aSVladimir Murzin #define PMSAv7_RGN_SHARED_CACHEABLE	(PMSAv7_RGN_CACHEABLE | PMSAv7_ACR_SHARED)
369cfb541aSVladimir Murzin #define PMSAv7_RGN_STRONGLY_ORDERED	0
37a2b45b0dSJonathan Austin 
38a2b45b0dSJonathan Austin /* Main region should only be shared for SMP */
39a2b45b0dSJonathan Austin #ifdef CONFIG_SMP
409cfb541aSVladimir Murzin #define PMSAv7_RGN_NORMAL	(PMSAv7_RGN_CACHEABLE | PMSAv7_ACR_SHARED)
41a2b45b0dSJonathan Austin #else
429cfb541aSVladimir Murzin #define PMSAv7_RGN_NORMAL	PMSAv7_RGN_CACHEABLE
43a2b45b0dSJonathan Austin #endif
44a2b45b0dSJonathan Austin 
45a2b45b0dSJonathan Austin /* Access permission bits of ACR (only define those that we use)*/
469cfb541aSVladimir Murzin #define PMSAv7_AP_PL1RO_PL0NA	(0x5 << 8)
479cfb541aSVladimir Murzin #define PMSAv7_AP_PL1RW_PL0RW	(0x3 << 8)
489cfb541aSVladimir Murzin #define PMSAv7_AP_PL1RW_PL0R0	(0x2 << 8)
499cfb541aSVladimir Murzin #define PMSAv7_AP_PL1RW_PL0NA	(0x1 << 8)
50a2b45b0dSJonathan Austin 
51*046835b4SVladimir Murzin #define PMSAv8_BAR_XN		1
52*046835b4SVladimir Murzin 
53*046835b4SVladimir Murzin #define PMSAv8_LAR_EN		1
54*046835b4SVladimir Murzin #define PMSAv8_LAR_IDX(n)	(((n) & 0x7) << 1)
55*046835b4SVladimir Murzin 
56*046835b4SVladimir Murzin 
57*046835b4SVladimir Murzin #define PMSAv8_AP_PL1RW_PL0NA	(0 << 1)
58*046835b4SVladimir Murzin #define PMSAv8_AP_PL1RW_PL0RW	(1 << 1)
59*046835b4SVladimir Murzin #define PMSAv8_AP_PL1RO_PL0RO	(3 << 1)
60*046835b4SVladimir Murzin 
61*046835b4SVladimir Murzin #ifdef CONFIG_SMP
62*046835b4SVladimir Murzin #define PMSAv8_RGN_SHARED	(3 << 3) // inner sharable
63*046835b4SVladimir Murzin #else
64*046835b4SVladimir Murzin #define PMSAv8_RGN_SHARED	(0 << 3)
65*046835b4SVladimir Murzin #endif
66*046835b4SVladimir Murzin 
67*046835b4SVladimir Murzin #define PMSAv8_RGN_DEVICE_nGnRnE	0
68*046835b4SVladimir Murzin #define PMSAv8_RGN_NORMAL		1
69*046835b4SVladimir Murzin 
70*046835b4SVladimir Murzin #define PMSAv8_MAIR(attr, mt)	((attr) << ((mt) * 8))
71*046835b4SVladimir Murzin 
72*046835b4SVladimir Murzin #ifdef CONFIG_CPU_V7M
73*046835b4SVladimir Murzin #define PMSAv8_MINALIGN		32
74*046835b4SVladimir Murzin #else
75*046835b4SVladimir Murzin #define PMSAv8_MINALIGN		64
76*046835b4SVladimir Murzin #endif
77*046835b4SVladimir Murzin 
78a2b45b0dSJonathan Austin /* For minimal static MPU region configurations */
799cfb541aSVladimir Murzin #define PMSAv7_PROBE_REGION	0
809cfb541aSVladimir Murzin #define PMSAv7_BG_REGION	1
819cfb541aSVladimir Murzin #define PMSAv7_RAM_REGION	2
829cfb541aSVladimir Murzin #define PMSAv7_ROM_REGION	3
83a2b45b0dSJonathan Austin 
84*046835b4SVladimir Murzin /* Fixed for PMSAv8 only */
85*046835b4SVladimir Murzin #define PMSAv8_XIP_REGION	0
86*046835b4SVladimir Murzin #define PMSAv8_KERNEL_REGION	1
87*046835b4SVladimir Murzin 
88a2b45b0dSJonathan Austin /* Maximum number of regions Linux is interested in */
89a2b45b0dSJonathan Austin #define MPU_MAX_REGIONS	16
90a2b45b0dSJonathan Austin 
919cfb541aSVladimir Murzin #define PMSAv7_DATA_SIDE	0
929cfb541aSVladimir Murzin #define PMSAv7_INSTR_SIDE	1
9367c9845bSJonathan Austin 
94a2b45b0dSJonathan Austin #ifndef __ASSEMBLY__
95a2b45b0dSJonathan Austin 
96a2b45b0dSJonathan Austin struct mpu_rgn {
97a2b45b0dSJonathan Austin 	/* Assume same attributes for d/i-side  */
98*046835b4SVladimir Murzin 	union {
99*046835b4SVladimir Murzin 		u32 drbar;   /* PMSAv7 */
100*046835b4SVladimir Murzin 		u32 prbar;   /* PMSAv8 */
101*046835b4SVladimir Murzin 	};
102*046835b4SVladimir Murzin 	union {
103*046835b4SVladimir Murzin 		u32 drsr;   /* PMSAv7 */
104*046835b4SVladimir Murzin 		u32 prlar;  /* PMSAv8 */
105*046835b4SVladimir Murzin 	};
106*046835b4SVladimir Murzin 	union {
107*046835b4SVladimir Murzin 		u32 dracr;  /* PMSAv7 */
108*046835b4SVladimir Murzin 		u32 unused; /* not used in PMSAv8 */
109*046835b4SVladimir Murzin 	};
110a2b45b0dSJonathan Austin };
111a2b45b0dSJonathan Austin 
112a2b45b0dSJonathan Austin struct mpu_rgn_info {
113a0995c08SVladimir Murzin 	unsigned int used;
114a2b45b0dSJonathan Austin 	struct mpu_rgn rgns[MPU_MAX_REGIONS];
115a2b45b0dSJonathan Austin };
116a2b45b0dSJonathan Austin extern struct mpu_rgn_info mpu_rgn_info;
117a2b45b0dSJonathan Austin 
118877ec119SVladimir Murzin #ifdef CONFIG_ARM_MPU
1199cfb541aSVladimir Murzin extern void __init pmsav7_adjust_lowmem_bounds(void);
120*046835b4SVladimir Murzin extern void __init pmsav8_adjust_lowmem_bounds(void);
121*046835b4SVladimir Murzin 
1229cfb541aSVladimir Murzin extern void __init pmsav7_setup(void);
123*046835b4SVladimir Murzin extern void __init pmsav8_setup(void);
124877ec119SVladimir Murzin #else
pmsav7_adjust_lowmem_bounds(void)1259cfb541aSVladimir Murzin static inline void pmsav7_adjust_lowmem_bounds(void) {};
pmsav8_adjust_lowmem_bounds(void)126*046835b4SVladimir Murzin static inline void pmsav8_adjust_lowmem_bounds(void) {};
pmsav7_setup(void)1279cfb541aSVladimir Murzin static inline void pmsav7_setup(void) {};
pmsav8_setup(void)128*046835b4SVladimir Murzin static inline void pmsav8_setup(void) {};
1299cfb541aSVladimir Murzin #endif
130877ec119SVladimir Murzin 
131877ec119SVladimir Murzin #endif /* __ASSEMBLY__ */
132a2b45b0dSJonathan Austin 
133a2b45b0dSJonathan Austin #endif
134