18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci#ifndef __ARM_MPU_H 38c2ecf20Sopenharmony_ci#define __ARM_MPU_H 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci/* MPUIR layout */ 68c2ecf20Sopenharmony_ci#define MPUIR_nU 1 78c2ecf20Sopenharmony_ci#define MPUIR_DREGION 8 88c2ecf20Sopenharmony_ci#define MPUIR_IREGION 16 98c2ecf20Sopenharmony_ci#define MPUIR_DREGION_SZMASK (0xFF << MPUIR_DREGION) 108c2ecf20Sopenharmony_ci#define MPUIR_IREGION_SZMASK (0xFF << MPUIR_IREGION) 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci/* ID_MMFR0 data relevant to MPU */ 138c2ecf20Sopenharmony_ci#define MMFR0_PMSA (0xF << 4) 148c2ecf20Sopenharmony_ci#define MMFR0_PMSAv7 (3 << 4) 158c2ecf20Sopenharmony_ci#define MMFR0_PMSAv8 (4 << 4) 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci/* MPU D/I Size Register fields */ 188c2ecf20Sopenharmony_ci#define PMSAv7_RSR_SZ 1 198c2ecf20Sopenharmony_ci#define PMSAv7_RSR_EN 0 208c2ecf20Sopenharmony_ci#define PMSAv7_RSR_SD 8 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci/* Number of subregions (SD) */ 238c2ecf20Sopenharmony_ci#define PMSAv7_NR_SUBREGS 8 248c2ecf20Sopenharmony_ci#define PMSAv7_MIN_SUBREG_SIZE 256 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci/* The D/I RSR value for an enabled region spanning the whole of memory */ 278c2ecf20Sopenharmony_ci#define PMSAv7_RSR_ALL_MEM 63 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci/* Individual bits in the DR/IR ACR */ 308c2ecf20Sopenharmony_ci#define PMSAv7_ACR_XN (1 << 12) 318c2ecf20Sopenharmony_ci#define PMSAv7_ACR_SHARED (1 << 2) 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci/* C, B and TEX[2:0] bits only have semantic meanings when grouped */ 348c2ecf20Sopenharmony_ci#define PMSAv7_RGN_CACHEABLE 0xB 358c2ecf20Sopenharmony_ci#define PMSAv7_RGN_SHARED_CACHEABLE (PMSAv7_RGN_CACHEABLE | PMSAv7_ACR_SHARED) 368c2ecf20Sopenharmony_ci#define PMSAv7_RGN_STRONGLY_ORDERED 0 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci/* Main region should only be shared for SMP */ 398c2ecf20Sopenharmony_ci#ifdef CONFIG_SMP 408c2ecf20Sopenharmony_ci#define PMSAv7_RGN_NORMAL (PMSAv7_RGN_CACHEABLE | PMSAv7_ACR_SHARED) 418c2ecf20Sopenharmony_ci#else 428c2ecf20Sopenharmony_ci#define PMSAv7_RGN_NORMAL PMSAv7_RGN_CACHEABLE 438c2ecf20Sopenharmony_ci#endif 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci/* Access permission bits of ACR (only define those that we use)*/ 468c2ecf20Sopenharmony_ci#define PMSAv7_AP_PL1RO_PL0NA (0x5 << 8) 478c2ecf20Sopenharmony_ci#define PMSAv7_AP_PL1RW_PL0RW (0x3 << 8) 488c2ecf20Sopenharmony_ci#define PMSAv7_AP_PL1RW_PL0R0 (0x2 << 8) 498c2ecf20Sopenharmony_ci#define PMSAv7_AP_PL1RW_PL0NA (0x1 << 8) 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci#define PMSAv8_BAR_XN 1 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci#define PMSAv8_LAR_EN 1 548c2ecf20Sopenharmony_ci#define PMSAv8_LAR_IDX(n) (((n) & 0x7) << 1) 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci#define PMSAv8_AP_PL1RW_PL0NA (0 << 1) 588c2ecf20Sopenharmony_ci#define PMSAv8_AP_PL1RW_PL0RW (1 << 1) 598c2ecf20Sopenharmony_ci#define PMSAv8_AP_PL1RO_PL0RO (3 << 1) 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci#ifdef CONFIG_SMP 628c2ecf20Sopenharmony_ci#define PMSAv8_RGN_SHARED (3 << 3) // inner sharable 638c2ecf20Sopenharmony_ci#else 648c2ecf20Sopenharmony_ci#define PMSAv8_RGN_SHARED (0 << 3) 658c2ecf20Sopenharmony_ci#endif 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci#define PMSAv8_RGN_DEVICE_nGnRnE 0 688c2ecf20Sopenharmony_ci#define PMSAv8_RGN_NORMAL 1 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci#define PMSAv8_MAIR(attr, mt) ((attr) << ((mt) * 8)) 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ci#ifdef CONFIG_CPU_V7M 738c2ecf20Sopenharmony_ci#define PMSAv8_MINALIGN 32 748c2ecf20Sopenharmony_ci#else 758c2ecf20Sopenharmony_ci#define PMSAv8_MINALIGN 64 768c2ecf20Sopenharmony_ci#endif 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci/* For minimal static MPU region configurations */ 798c2ecf20Sopenharmony_ci#define PMSAv7_PROBE_REGION 0 808c2ecf20Sopenharmony_ci#define PMSAv7_BG_REGION 1 818c2ecf20Sopenharmony_ci#define PMSAv7_RAM_REGION 2 828c2ecf20Sopenharmony_ci#define PMSAv7_ROM_REGION 3 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_ci/* Fixed for PMSAv8 only */ 858c2ecf20Sopenharmony_ci#define PMSAv8_XIP_REGION 0 868c2ecf20Sopenharmony_ci#define PMSAv8_KERNEL_REGION 1 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci/* Maximum number of regions Linux is interested in */ 898c2ecf20Sopenharmony_ci#define MPU_MAX_REGIONS 16 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_ci#define PMSAv7_DATA_SIDE 0 928c2ecf20Sopenharmony_ci#define PMSAv7_INSTR_SIDE 1 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__ 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_cistruct mpu_rgn { 978c2ecf20Sopenharmony_ci /* Assume same attributes for d/i-side */ 988c2ecf20Sopenharmony_ci union { 998c2ecf20Sopenharmony_ci u32 drbar; /* PMSAv7 */ 1008c2ecf20Sopenharmony_ci u32 prbar; /* PMSAv8 */ 1018c2ecf20Sopenharmony_ci }; 1028c2ecf20Sopenharmony_ci union { 1038c2ecf20Sopenharmony_ci u32 drsr; /* PMSAv7 */ 1048c2ecf20Sopenharmony_ci u32 prlar; /* PMSAv8 */ 1058c2ecf20Sopenharmony_ci }; 1068c2ecf20Sopenharmony_ci union { 1078c2ecf20Sopenharmony_ci u32 dracr; /* PMSAv7 */ 1088c2ecf20Sopenharmony_ci u32 unused; /* not used in PMSAv8 */ 1098c2ecf20Sopenharmony_ci }; 1108c2ecf20Sopenharmony_ci}; 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_cistruct mpu_rgn_info { 1138c2ecf20Sopenharmony_ci unsigned int used; 1148c2ecf20Sopenharmony_ci struct mpu_rgn rgns[MPU_MAX_REGIONS]; 1158c2ecf20Sopenharmony_ci}; 1168c2ecf20Sopenharmony_ciextern struct mpu_rgn_info mpu_rgn_info; 1178c2ecf20Sopenharmony_ci 1188c2ecf20Sopenharmony_ci#ifdef CONFIG_ARM_MPU 1198c2ecf20Sopenharmony_ciextern void __init pmsav7_adjust_lowmem_bounds(void); 1208c2ecf20Sopenharmony_ciextern void __init pmsav8_adjust_lowmem_bounds(void); 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_ciextern void __init pmsav7_setup(void); 1238c2ecf20Sopenharmony_ciextern void __init pmsav8_setup(void); 1248c2ecf20Sopenharmony_ci#else 1258c2ecf20Sopenharmony_cistatic inline void pmsav7_adjust_lowmem_bounds(void) {}; 1268c2ecf20Sopenharmony_cistatic inline void pmsav8_adjust_lowmem_bounds(void) {}; 1278c2ecf20Sopenharmony_cistatic inline void pmsav7_setup(void) {}; 1288c2ecf20Sopenharmony_cistatic inline void pmsav8_setup(void) {}; 1298c2ecf20Sopenharmony_ci#endif 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_ci#endif /* __ASSEMBLY__ */ 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci#endif 134