18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Bit definitions for the MCF54xx ACR and CACR registers. 48c2ecf20Sopenharmony_ci */ 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci#ifndef m54xxacr_h 78c2ecf20Sopenharmony_ci#define m54xxacr_h 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci/* 108c2ecf20Sopenharmony_ci * Define the Cache register flags. 118c2ecf20Sopenharmony_ci */ 128c2ecf20Sopenharmony_ci#define CACR_DEC 0x80000000 /* Enable data cache */ 138c2ecf20Sopenharmony_ci#define CACR_DWP 0x40000000 /* Data write protection */ 148c2ecf20Sopenharmony_ci#define CACR_DESB 0x20000000 /* Enable data store buffer */ 158c2ecf20Sopenharmony_ci#define CACR_DDPI 0x10000000 /* Disable invalidation by CPUSHL */ 168c2ecf20Sopenharmony_ci#define CACR_DHCLK 0x08000000 /* Half data cache lock mode */ 178c2ecf20Sopenharmony_ci#define CACR_DDCM_WT 0x00000000 /* Write through cache*/ 188c2ecf20Sopenharmony_ci#define CACR_DDCM_CP 0x02000000 /* Copyback cache */ 198c2ecf20Sopenharmony_ci#define CACR_DDCM_P 0x04000000 /* No cache, precise */ 208c2ecf20Sopenharmony_ci#define CACR_DDCM_IMP 0x06000000 /* No cache, imprecise */ 218c2ecf20Sopenharmony_ci#define CACR_DCINVA 0x01000000 /* Invalidate data cache */ 228c2ecf20Sopenharmony_ci#define CACR_BEC 0x00080000 /* Enable branch cache */ 238c2ecf20Sopenharmony_ci#define CACR_BCINVA 0x00040000 /* Invalidate branch cache */ 248c2ecf20Sopenharmony_ci#define CACR_IEC 0x00008000 /* Enable instruction cache */ 258c2ecf20Sopenharmony_ci#define CACR_DNFB 0x00002000 /* Inhibited fill buffer */ 268c2ecf20Sopenharmony_ci#define CACR_IDPI 0x00001000 /* Disable CPUSHL */ 278c2ecf20Sopenharmony_ci#define CACR_IHLCK 0x00000800 /* Instruction cache half lock */ 288c2ecf20Sopenharmony_ci#define CACR_IDCM 0x00000400 /* Instruction cache inhibit */ 298c2ecf20Sopenharmony_ci#define CACR_ICINVA 0x00000100 /* Invalidate instr cache */ 308c2ecf20Sopenharmony_ci#define CACR_EUSP 0x00000020 /* Enable separate user a7 */ 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci#define ACR_BASE_POS 24 /* Address Base */ 338c2ecf20Sopenharmony_ci#define ACR_MASK_POS 16 /* Address Mask */ 348c2ecf20Sopenharmony_ci#define ACR_ENABLE 0x00008000 /* Enable address */ 358c2ecf20Sopenharmony_ci#define ACR_USER 0x00000000 /* User mode access only */ 368c2ecf20Sopenharmony_ci#define ACR_SUPER 0x00002000 /* Supervisor mode only */ 378c2ecf20Sopenharmony_ci#define ACR_ANY 0x00004000 /* Match any access mode */ 388c2ecf20Sopenharmony_ci#define ACR_CM_WT 0x00000000 /* Write through mode */ 398c2ecf20Sopenharmony_ci#define ACR_CM_CP 0x00000020 /* Copyback mode */ 408c2ecf20Sopenharmony_ci#define ACR_CM_OFF_PRE 0x00000040 /* No cache, precise */ 418c2ecf20Sopenharmony_ci#define ACR_CM_OFF_IMP 0x00000060 /* No cache, imprecise */ 428c2ecf20Sopenharmony_ci#define ACR_CM 0x00000060 /* Cache mode mask */ 438c2ecf20Sopenharmony_ci#define ACR_SP 0x00000008 /* Supervisor protect */ 448c2ecf20Sopenharmony_ci#define ACR_WPROTECT 0x00000004 /* Write protect */ 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci#define ACR_BA(x) ((x) & 0xff000000) 478c2ecf20Sopenharmony_ci#define ACR_ADMSK(x) ((((x) - 1) & 0xff000000) >> 8) 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci#if defined(CONFIG_M5407) 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci#define ICACHE_SIZE 0x4000 /* instruction - 16k */ 528c2ecf20Sopenharmony_ci#define DCACHE_SIZE 0x2000 /* data - 8k */ 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_ci#elif defined(CONFIG_M54xx) 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci#define ICACHE_SIZE 0x8000 /* instruction - 32k */ 578c2ecf20Sopenharmony_ci#define DCACHE_SIZE 0x8000 /* data - 32k */ 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci#elif defined(CONFIG_M5441x) 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci#define ICACHE_SIZE 0x2000 /* instruction - 8k */ 628c2ecf20Sopenharmony_ci#define DCACHE_SIZE 0x2000 /* data - 8k */ 638c2ecf20Sopenharmony_ci#endif 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ci#define CACHE_LINE_SIZE 0x0010 /* 16 bytes */ 668c2ecf20Sopenharmony_ci#define CACHE_WAYS 4 /* 4 ways */ 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci#define ICACHE_SET_MASK ((ICACHE_SIZE / 64 - 1) << CACHE_WAYS) 698c2ecf20Sopenharmony_ci#define DCACHE_SET_MASK ((DCACHE_SIZE / 64 - 1) << CACHE_WAYS) 708c2ecf20Sopenharmony_ci#define ICACHE_MAX_ADDR ICACHE_SET_MASK 718c2ecf20Sopenharmony_ci#define DCACHE_MAX_ADDR DCACHE_SET_MASK 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ci/* 748c2ecf20Sopenharmony_ci * Version 4 cores have a true harvard style separate instruction 758c2ecf20Sopenharmony_ci * and data cache. Enable data and instruction caches, also enable write 768c2ecf20Sopenharmony_ci * buffers and branch accelerator. 778c2ecf20Sopenharmony_ci */ 788c2ecf20Sopenharmony_ci/* attention : enabling CACR_DESB requires a "nop" to flush the store buffer */ 798c2ecf20Sopenharmony_ci/* use '+' instead of '|' for assembler's sake */ 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_ci /* Enable data cache */ 828c2ecf20Sopenharmony_ci /* Enable data store buffer */ 838c2ecf20Sopenharmony_ci /* outside ACRs : No cache, precise */ 848c2ecf20Sopenharmony_ci /* Enable instruction+branch caches */ 858c2ecf20Sopenharmony_ci#if defined(CONFIG_M5407) 868c2ecf20Sopenharmony_ci#define CACHE_MODE (CACR_DEC+CACR_DESB+CACR_DDCM_P+CACR_BEC+CACR_IEC) 878c2ecf20Sopenharmony_ci#else 888c2ecf20Sopenharmony_ci#define CACHE_MODE (CACR_DEC+CACR_DESB+CACR_DDCM_P+CACR_BEC+CACR_IEC+CACR_EUSP) 898c2ecf20Sopenharmony_ci#endif 908c2ecf20Sopenharmony_ci#define CACHE_INIT (CACR_DCINVA+CACR_BCINVA+CACR_ICINVA) 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ci#if defined(CONFIG_MMU) 938c2ecf20Sopenharmony_ci/* 948c2ecf20Sopenharmony_ci * If running with the MMU enabled then we need to map the internal 958c2ecf20Sopenharmony_ci * register region as non-cacheable. And then we map all our RAM as 968c2ecf20Sopenharmony_ci * cacheable and supervisor access only. 978c2ecf20Sopenharmony_ci */ 988c2ecf20Sopenharmony_ci#define ACR0_MODE (ACR_BA(IOMEMBASE)+ACR_ADMSK(IOMEMSIZE)+ \ 998c2ecf20Sopenharmony_ci ACR_ENABLE+ACR_SUPER+ACR_CM_OFF_PRE+ACR_SP) 1008c2ecf20Sopenharmony_ci#if defined(CONFIG_CACHE_COPYBACK) 1018c2ecf20Sopenharmony_ci#define ACR1_MODE (ACR_BA(CONFIG_RAMBASE)+ACR_ADMSK(CONFIG_RAMSIZE)+ \ 1028c2ecf20Sopenharmony_ci ACR_ENABLE+ACR_SUPER+ACR_SP+ACR_CM_CP) 1038c2ecf20Sopenharmony_ci#else 1048c2ecf20Sopenharmony_ci#define ACR1_MODE (ACR_BA(CONFIG_RAMBASE)+ACR_ADMSK(CONFIG_RAMSIZE)+ \ 1058c2ecf20Sopenharmony_ci ACR_ENABLE+ACR_SUPER+ACR_SP+ACR_CM_WT) 1068c2ecf20Sopenharmony_ci#endif 1078c2ecf20Sopenharmony_ci#define ACR2_MODE 0 1088c2ecf20Sopenharmony_ci#define ACR3_MODE (ACR_BA(CONFIG_RAMBASE)+ACR_ADMSK(CONFIG_RAMSIZE)+ \ 1098c2ecf20Sopenharmony_ci ACR_ENABLE+ACR_SUPER+ACR_SP) 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_ci#else 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ci/* 1148c2ecf20Sopenharmony_ci * For the non-MMU enabled case we map all of RAM as cacheable. 1158c2ecf20Sopenharmony_ci */ 1168c2ecf20Sopenharmony_ci#if defined(CONFIG_CACHE_COPYBACK) 1178c2ecf20Sopenharmony_ci#define DATA_CACHE_MODE (ACR_ENABLE+ACR_ANY+ACR_CM_CP) 1188c2ecf20Sopenharmony_ci#else 1198c2ecf20Sopenharmony_ci#define DATA_CACHE_MODE (ACR_ENABLE+ACR_ANY+ACR_CM_WT) 1208c2ecf20Sopenharmony_ci#endif 1218c2ecf20Sopenharmony_ci#define INSN_CACHE_MODE (ACR_ENABLE+ACR_ANY) 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ci#define CACHE_INVALIDATE (CACHE_MODE+CACR_DCINVA+CACR_BCINVA+CACR_ICINVA) 1248c2ecf20Sopenharmony_ci#define CACHE_INVALIDATEI (CACHE_MODE+CACR_BCINVA+CACR_ICINVA) 1258c2ecf20Sopenharmony_ci#define CACHE_INVALIDATED (CACHE_MODE+CACR_DCINVA) 1268c2ecf20Sopenharmony_ci#define ACR0_MODE (0x000f0000+DATA_CACHE_MODE) 1278c2ecf20Sopenharmony_ci#define ACR1_MODE 0 1288c2ecf20Sopenharmony_ci#define ACR2_MODE (0x000f0000+INSN_CACHE_MODE) 1298c2ecf20Sopenharmony_ci#define ACR3_MODE 0 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_ci#if ((DATA_CACHE_MODE & ACR_CM) == ACR_CM_CP) 1328c2ecf20Sopenharmony_ci/* Copyback cache mode must push dirty cache lines first */ 1338c2ecf20Sopenharmony_ci#define CACHE_PUSH 1348c2ecf20Sopenharmony_ci#endif 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ci#endif /* CONFIG_MMU */ 1378c2ecf20Sopenharmony_ci#endif /* m54xxacr_h */ 138