18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci#ifndef _ASM_POWERPC_CACHE_H 38c2ecf20Sopenharmony_ci#define _ASM_POWERPC_CACHE_H 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci#ifdef __KERNEL__ 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci/* bytes per L1 cache line */ 98c2ecf20Sopenharmony_ci#if defined(CONFIG_PPC_8xx) 108c2ecf20Sopenharmony_ci#define L1_CACHE_SHIFT 4 118c2ecf20Sopenharmony_ci#define MAX_COPY_PREFETCH 1 128c2ecf20Sopenharmony_ci#define IFETCH_ALIGN_SHIFT 2 138c2ecf20Sopenharmony_ci#elif defined(CONFIG_PPC_E500MC) 148c2ecf20Sopenharmony_ci#define L1_CACHE_SHIFT 6 158c2ecf20Sopenharmony_ci#define MAX_COPY_PREFETCH 4 168c2ecf20Sopenharmony_ci#define IFETCH_ALIGN_SHIFT 3 178c2ecf20Sopenharmony_ci#elif defined(CONFIG_PPC32) 188c2ecf20Sopenharmony_ci#define MAX_COPY_PREFETCH 4 198c2ecf20Sopenharmony_ci#define IFETCH_ALIGN_SHIFT 3 /* 603 fetches 2 insn at a time */ 208c2ecf20Sopenharmony_ci#if defined(CONFIG_PPC_47x) 218c2ecf20Sopenharmony_ci#define L1_CACHE_SHIFT 7 228c2ecf20Sopenharmony_ci#else 238c2ecf20Sopenharmony_ci#define L1_CACHE_SHIFT 5 248c2ecf20Sopenharmony_ci#endif 258c2ecf20Sopenharmony_ci#else /* CONFIG_PPC64 */ 268c2ecf20Sopenharmony_ci#define L1_CACHE_SHIFT 7 278c2ecf20Sopenharmony_ci#define IFETCH_ALIGN_SHIFT 4 /* POWER8,9 */ 288c2ecf20Sopenharmony_ci#endif 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT) 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci#define SMP_CACHE_BYTES L1_CACHE_BYTES 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci#define IFETCH_ALIGN_BYTES (1 << IFETCH_ALIGN_SHIFT) 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci#if !defined(__ASSEMBLY__) 378c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC64 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_cistruct ppc_cache_info { 408c2ecf20Sopenharmony_ci u32 size; 418c2ecf20Sopenharmony_ci u32 line_size; 428c2ecf20Sopenharmony_ci u32 block_size; /* L1 only */ 438c2ecf20Sopenharmony_ci u32 log_block_size; 448c2ecf20Sopenharmony_ci u32 blocks_per_page; 458c2ecf20Sopenharmony_ci u32 sets; 468c2ecf20Sopenharmony_ci u32 assoc; 478c2ecf20Sopenharmony_ci}; 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_cistruct ppc64_caches { 508c2ecf20Sopenharmony_ci struct ppc_cache_info l1d; 518c2ecf20Sopenharmony_ci struct ppc_cache_info l1i; 528c2ecf20Sopenharmony_ci struct ppc_cache_info l2; 538c2ecf20Sopenharmony_ci struct ppc_cache_info l3; 548c2ecf20Sopenharmony_ci}; 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ciextern struct ppc64_caches ppc64_caches; 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_cistatic inline u32 l1_dcache_shift(void) 598c2ecf20Sopenharmony_ci{ 608c2ecf20Sopenharmony_ci return ppc64_caches.l1d.log_block_size; 618c2ecf20Sopenharmony_ci} 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_cistatic inline u32 l1_dcache_bytes(void) 648c2ecf20Sopenharmony_ci{ 658c2ecf20Sopenharmony_ci return ppc64_caches.l1d.block_size; 668c2ecf20Sopenharmony_ci} 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_cistatic inline u32 l1_icache_shift(void) 698c2ecf20Sopenharmony_ci{ 708c2ecf20Sopenharmony_ci return ppc64_caches.l1i.log_block_size; 718c2ecf20Sopenharmony_ci} 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_cistatic inline u32 l1_icache_bytes(void) 748c2ecf20Sopenharmony_ci{ 758c2ecf20Sopenharmony_ci return ppc64_caches.l1i.block_size; 768c2ecf20Sopenharmony_ci} 778c2ecf20Sopenharmony_ci#else 788c2ecf20Sopenharmony_cistatic inline u32 l1_dcache_shift(void) 798c2ecf20Sopenharmony_ci{ 808c2ecf20Sopenharmony_ci return L1_CACHE_SHIFT; 818c2ecf20Sopenharmony_ci} 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_cistatic inline u32 l1_dcache_bytes(void) 848c2ecf20Sopenharmony_ci{ 858c2ecf20Sopenharmony_ci return L1_CACHE_BYTES; 868c2ecf20Sopenharmony_ci} 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_cistatic inline u32 l1_icache_shift(void) 898c2ecf20Sopenharmony_ci{ 908c2ecf20Sopenharmony_ci return L1_CACHE_SHIFT; 918c2ecf20Sopenharmony_ci} 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_cistatic inline u32 l1_icache_bytes(void) 948c2ecf20Sopenharmony_ci{ 958c2ecf20Sopenharmony_ci return L1_CACHE_BYTES; 968c2ecf20Sopenharmony_ci} 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ci#endif 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_ci#define __read_mostly __section(".data..read_mostly") 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC_BOOK3S_32 1038c2ecf20Sopenharmony_ciextern long _get_L2CR(void); 1048c2ecf20Sopenharmony_ciextern long _get_L3CR(void); 1058c2ecf20Sopenharmony_ciextern void _set_L2CR(unsigned long); 1068c2ecf20Sopenharmony_ciextern void _set_L3CR(unsigned long); 1078c2ecf20Sopenharmony_ci#else 1088c2ecf20Sopenharmony_ci#define _get_L2CR() 0L 1098c2ecf20Sopenharmony_ci#define _get_L3CR() 0L 1108c2ecf20Sopenharmony_ci#define _set_L2CR(val) do { } while(0) 1118c2ecf20Sopenharmony_ci#define _set_L3CR(val) do { } while(0) 1128c2ecf20Sopenharmony_ci#endif 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_cistatic inline void dcbz(void *addr) 1158c2ecf20Sopenharmony_ci{ 1168c2ecf20Sopenharmony_ci __asm__ __volatile__ ("dcbz 0, %0" : : "r"(addr) : "memory"); 1178c2ecf20Sopenharmony_ci} 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_cistatic inline void dcbi(void *addr) 1208c2ecf20Sopenharmony_ci{ 1218c2ecf20Sopenharmony_ci __asm__ __volatile__ ("dcbi 0, %0" : : "r"(addr) : "memory"); 1228c2ecf20Sopenharmony_ci} 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_cistatic inline void dcbf(void *addr) 1258c2ecf20Sopenharmony_ci{ 1268c2ecf20Sopenharmony_ci __asm__ __volatile__ ("dcbf 0, %0" : : "r"(addr) : "memory"); 1278c2ecf20Sopenharmony_ci} 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_cistatic inline void dcbst(void *addr) 1308c2ecf20Sopenharmony_ci{ 1318c2ecf20Sopenharmony_ci __asm__ __volatile__ ("dcbst 0, %0" : : "r"(addr) : "memory"); 1328c2ecf20Sopenharmony_ci} 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_cistatic inline void icbi(void *addr) 1358c2ecf20Sopenharmony_ci{ 1368c2ecf20Sopenharmony_ci asm volatile ("icbi 0, %0" : : "r"(addr) : "memory"); 1378c2ecf20Sopenharmony_ci} 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_cistatic inline void iccci(void *addr) 1408c2ecf20Sopenharmony_ci{ 1418c2ecf20Sopenharmony_ci asm volatile ("iccci 0, %0" : : "r"(addr) : "memory"); 1428c2ecf20Sopenharmony_ci} 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_ci#endif /* !__ASSEMBLY__ */ 1458c2ecf20Sopenharmony_ci#endif /* __KERNEL__ */ 1468c2ecf20Sopenharmony_ci#endif /* _ASM_POWERPC_CACHE_H */ 147