xref: /openbmc/linux/arch/powerpc/include/asm/cache.h (revision 78615c4d)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
2b8b572e1SStephen Rothwell #ifndef _ASM_POWERPC_CACHE_H
3b8b572e1SStephen Rothwell #define _ASM_POWERPC_CACHE_H
4b8b572e1SStephen Rothwell 
5b8b572e1SStephen Rothwell #ifdef __KERNEL__
6b8b572e1SStephen Rothwell 
7b8b572e1SStephen Rothwell 
8b8b572e1SStephen Rothwell /* bytes per L1 cache line */
91b5c0967SChristophe Leroy #if defined(CONFIG_PPC_8xx)
10b8b572e1SStephen Rothwell #define L1_CACHE_SHIFT		4
11b8b572e1SStephen Rothwell #define MAX_COPY_PREFETCH	1
121128bb78SChristophe Leroy #define IFETCH_ALIGN_SHIFT	2
13b8b572e1SStephen Rothwell #elif defined(CONFIG_PPC_E500MC)
14b8b572e1SStephen Rothwell #define L1_CACHE_SHIFT		6
15b8b572e1SStephen Rothwell #define MAX_COPY_PREFETCH	4
161128bb78SChristophe Leroy #define IFETCH_ALIGN_SHIFT	3
17b8b572e1SStephen Rothwell #elif defined(CONFIG_PPC32)
18b8b572e1SStephen Rothwell #define MAX_COPY_PREFETCH	4
191128bb78SChristophe Leroy #define IFETCH_ALIGN_SHIFT	3	/* 603 fetches 2 insn at a time */
20e7f75ad0SDave Kleikamp #if defined(CONFIG_PPC_47x)
21e7f75ad0SDave Kleikamp #define L1_CACHE_SHIFT		7
22e7f75ad0SDave Kleikamp #else
23e7f75ad0SDave Kleikamp #define L1_CACHE_SHIFT		5
24e7f75ad0SDave Kleikamp #endif
25b8b572e1SStephen Rothwell #else /* CONFIG_PPC64 */
26b8b572e1SStephen Rothwell #define L1_CACHE_SHIFT		7
27f4329f2eSNicholas Piggin #define IFETCH_ALIGN_SHIFT	4 /* POWER8,9 */
28b8b572e1SStephen Rothwell #endif
29b8b572e1SStephen Rothwell 
30b8b572e1SStephen Rothwell #define	L1_CACHE_BYTES		(1 << L1_CACHE_SHIFT)
31b8b572e1SStephen Rothwell 
32b8b572e1SStephen Rothwell #define	SMP_CACHE_BYTES		L1_CACHE_BYTES
33b8b572e1SStephen Rothwell 
34f4329f2eSNicholas Piggin #define IFETCH_ALIGN_BYTES	(1 << IFETCH_ALIGN_SHIFT)
35f4329f2eSNicholas Piggin 
36*78615c4dSCatalin Marinas #ifdef CONFIG_NOT_COHERENT_CACHE
37*78615c4dSCatalin Marinas #define ARCH_DMA_MINALIGN	L1_CACHE_BYTES
38*78615c4dSCatalin Marinas #endif
39*78615c4dSCatalin Marinas 
40d98fc70fSChristophe Leroy #if !defined(__ASSEMBLY__)
41d98fc70fSChristophe Leroy #ifdef CONFIG_PPC64
42e2827fe5SBenjamin Herrenschmidt 
43e2827fe5SBenjamin Herrenschmidt struct ppc_cache_info {
44e2827fe5SBenjamin Herrenschmidt 	u32 size;
45e2827fe5SBenjamin Herrenschmidt 	u32 line_size;
46e2827fe5SBenjamin Herrenschmidt 	u32 block_size;	/* L1 only */
47e2827fe5SBenjamin Herrenschmidt 	u32 log_block_size;
48e2827fe5SBenjamin Herrenschmidt 	u32 blocks_per_page;
49e2827fe5SBenjamin Herrenschmidt 	u32 sets;
5098a5f361SBenjamin Herrenschmidt 	u32 assoc;
51e2827fe5SBenjamin Herrenschmidt };
52e2827fe5SBenjamin Herrenschmidt 
53b8b572e1SStephen Rothwell struct ppc64_caches {
54e2827fe5SBenjamin Herrenschmidt 	struct ppc_cache_info l1d;
55e2827fe5SBenjamin Herrenschmidt 	struct ppc_cache_info l1i;
5665e01f38SBenjamin Herrenschmidt 	struct ppc_cache_info l2;
5765e01f38SBenjamin Herrenschmidt 	struct ppc_cache_info l3;
58b8b572e1SStephen Rothwell };
59b8b572e1SStephen Rothwell 
60b8b572e1SStephen Rothwell extern struct ppc64_caches ppc64_caches;
6122e9c88dSChristophe Leroy 
l1_dcache_shift(void)627a0745c5SAlastair D'Silva static inline u32 l1_dcache_shift(void)
6322e9c88dSChristophe Leroy {
6422e9c88dSChristophe Leroy 	return ppc64_caches.l1d.log_block_size;
6522e9c88dSChristophe Leroy }
6622e9c88dSChristophe Leroy 
l1_dcache_bytes(void)677a0745c5SAlastair D'Silva static inline u32 l1_dcache_bytes(void)
6822e9c88dSChristophe Leroy {
6922e9c88dSChristophe Leroy 	return ppc64_caches.l1d.block_size;
7022e9c88dSChristophe Leroy }
717a0745c5SAlastair D'Silva 
l1_icache_shift(void)727a0745c5SAlastair D'Silva static inline u32 l1_icache_shift(void)
737a0745c5SAlastair D'Silva {
747a0745c5SAlastair D'Silva 	return ppc64_caches.l1i.log_block_size;
757a0745c5SAlastair D'Silva }
767a0745c5SAlastair D'Silva 
l1_icache_bytes(void)777a0745c5SAlastair D'Silva static inline u32 l1_icache_bytes(void)
787a0745c5SAlastair D'Silva {
797a0745c5SAlastair D'Silva 	return ppc64_caches.l1i.block_size;
807a0745c5SAlastair D'Silva }
81d98fc70fSChristophe Leroy #else
l1_dcache_shift(void)827a0745c5SAlastair D'Silva static inline u32 l1_dcache_shift(void)
83d98fc70fSChristophe Leroy {
84d98fc70fSChristophe Leroy 	return L1_CACHE_SHIFT;
85d98fc70fSChristophe Leroy }
86d98fc70fSChristophe Leroy 
l1_dcache_bytes(void)877a0745c5SAlastair D'Silva static inline u32 l1_dcache_bytes(void)
88d98fc70fSChristophe Leroy {
89d98fc70fSChristophe Leroy 	return L1_CACHE_BYTES;
90d98fc70fSChristophe Leroy }
917a0745c5SAlastair D'Silva 
l1_icache_shift(void)927a0745c5SAlastair D'Silva static inline u32 l1_icache_shift(void)
937a0745c5SAlastair D'Silva {
947a0745c5SAlastair D'Silva 	return L1_CACHE_SHIFT;
957a0745c5SAlastair D'Silva }
967a0745c5SAlastair D'Silva 
l1_icache_bytes(void)977a0745c5SAlastair D'Silva static inline u32 l1_icache_bytes(void)
987a0745c5SAlastair D'Silva {
997a0745c5SAlastair D'Silva 	return L1_CACHE_BYTES;
1007a0745c5SAlastair D'Silva }
1017a0745c5SAlastair D'Silva 
102d98fc70fSChristophe Leroy #endif
103b8b572e1SStephen Rothwell 
10433def849SJoe Perches #define __read_mostly __section(".data..read_mostly")
105ae3a197eSDavid Howells 
106d7cceda9SChristophe Leroy #ifdef CONFIG_PPC_BOOK3S_32
107ae3a197eSDavid Howells extern long _get_L2CR(void);
108ae3a197eSDavid Howells extern long _get_L3CR(void);
109ae3a197eSDavid Howells extern void _set_L2CR(unsigned long);
110ae3a197eSDavid Howells extern void _set_L3CR(unsigned long);
111ae3a197eSDavid Howells #else
112ae3a197eSDavid Howells #define _get_L2CR()	0L
113ae3a197eSDavid Howells #define _get_L3CR()	0L
114ae3a197eSDavid Howells #define _set_L2CR(val)	do { } while(0)
115ae3a197eSDavid Howells #define _set_L3CR(val)	do { } while(0)
116b8b572e1SStephen Rothwell #endif
117b8b572e1SStephen Rothwell 
dcbz(void * addr)118d6bfa02fSChristophe Leroy static inline void dcbz(void *addr)
119d6bfa02fSChristophe Leroy {
120ed4289e8SMichael Ellerman 	__asm__ __volatile__ ("dcbz 0, %0" : : "r"(addr) : "memory");
121d6bfa02fSChristophe Leroy }
122d6bfa02fSChristophe Leroy 
dcbi(void * addr)123d6bfa02fSChristophe Leroy static inline void dcbi(void *addr)
124d6bfa02fSChristophe Leroy {
125ed4289e8SMichael Ellerman 	__asm__ __volatile__ ("dcbi 0, %0" : : "r"(addr) : "memory");
126d6bfa02fSChristophe Leroy }
127d6bfa02fSChristophe Leroy 
dcbf(void * addr)128d6bfa02fSChristophe Leroy static inline void dcbf(void *addr)
129d6bfa02fSChristophe Leroy {
130ed4289e8SMichael Ellerman 	__asm__ __volatile__ ("dcbf 0, %0" : : "r"(addr) : "memory");
131d6bfa02fSChristophe Leroy }
132d6bfa02fSChristophe Leroy 
dcbst(void * addr)133d6bfa02fSChristophe Leroy static inline void dcbst(void *addr)
134d6bfa02fSChristophe Leroy {
135ed4289e8SMichael Ellerman 	__asm__ __volatile__ ("dcbst 0, %0" : : "r"(addr) : "memory");
136d6bfa02fSChristophe Leroy }
13723eb7f56SAlastair D'Silva 
icbi(void * addr)13823eb7f56SAlastair D'Silva static inline void icbi(void *addr)
13923eb7f56SAlastair D'Silva {
14023eb7f56SAlastair D'Silva 	asm volatile ("icbi 0, %0" : : "r"(addr) : "memory");
14123eb7f56SAlastair D'Silva }
14223eb7f56SAlastair D'Silva 
iccci(void * addr)14323eb7f56SAlastair D'Silva static inline void iccci(void *addr)
14423eb7f56SAlastair D'Silva {
14523eb7f56SAlastair D'Silva 	asm volatile ("iccci 0, %0" : : "r"(addr) : "memory");
14623eb7f56SAlastair D'Silva }
14723eb7f56SAlastair D'Silva 
148ae3a197eSDavid Howells #endif /* !__ASSEMBLY__ */
149b8b572e1SStephen Rothwell #endif /* __KERNEL__ */
150b8b572e1SStephen Rothwell #endif /* _ASM_POWERPC_CACHE_H */
151