xref: /openbmc/linux/arch/powerpc/include/asm/cache.h (revision 98a5f361b8625c6f4841d6ba013bbf0e80d08147)
1b8b572e1SStephen Rothwell #ifndef _ASM_POWERPC_CACHE_H
2b8b572e1SStephen Rothwell #define _ASM_POWERPC_CACHE_H
3b8b572e1SStephen Rothwell 
4b8b572e1SStephen Rothwell #ifdef __KERNEL__
5b8b572e1SStephen Rothwell 
6b8b572e1SStephen Rothwell 
7b8b572e1SStephen Rothwell /* bytes per L1 cache line */
8b8b572e1SStephen Rothwell #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
9b8b572e1SStephen Rothwell #define L1_CACHE_SHIFT		4
10b8b572e1SStephen Rothwell #define MAX_COPY_PREFETCH	1
11b8b572e1SStephen Rothwell #elif defined(CONFIG_PPC_E500MC)
12b8b572e1SStephen Rothwell #define L1_CACHE_SHIFT		6
13b8b572e1SStephen Rothwell #define MAX_COPY_PREFETCH	4
14b8b572e1SStephen Rothwell #elif defined(CONFIG_PPC32)
15b8b572e1SStephen Rothwell #define MAX_COPY_PREFETCH	4
16e7f75ad0SDave Kleikamp #if defined(CONFIG_PPC_47x)
17e7f75ad0SDave Kleikamp #define L1_CACHE_SHIFT		7
18e7f75ad0SDave Kleikamp #else
19e7f75ad0SDave Kleikamp #define L1_CACHE_SHIFT		5
20e7f75ad0SDave Kleikamp #endif
21b8b572e1SStephen Rothwell #else /* CONFIG_PPC64 */
22b8b572e1SStephen Rothwell #define L1_CACHE_SHIFT		7
23f4329f2eSNicholas Piggin #define IFETCH_ALIGN_SHIFT	4 /* POWER8,9 */
24b8b572e1SStephen Rothwell #endif
25b8b572e1SStephen Rothwell 
26b8b572e1SStephen Rothwell #define	L1_CACHE_BYTES		(1 << L1_CACHE_SHIFT)
27b8b572e1SStephen Rothwell 
28b8b572e1SStephen Rothwell #define	SMP_CACHE_BYTES		L1_CACHE_BYTES
29b8b572e1SStephen Rothwell 
30f4329f2eSNicholas Piggin #define IFETCH_ALIGN_BYTES	(1 << IFETCH_ALIGN_SHIFT)
31f4329f2eSNicholas Piggin 
32b8b572e1SStephen Rothwell #if defined(__powerpc64__) && !defined(__ASSEMBLY__)
33e2827fe5SBenjamin Herrenschmidt 
34e2827fe5SBenjamin Herrenschmidt struct ppc_cache_info {
35e2827fe5SBenjamin Herrenschmidt 	u32 size;
36e2827fe5SBenjamin Herrenschmidt 	u32 line_size;
37e2827fe5SBenjamin Herrenschmidt 	u32 block_size;	/* L1 only */
38e2827fe5SBenjamin Herrenschmidt 	u32 log_block_size;
39e2827fe5SBenjamin Herrenschmidt 	u32 blocks_per_page;
40e2827fe5SBenjamin Herrenschmidt 	u32 sets;
41*98a5f361SBenjamin Herrenschmidt 	u32 assoc;
42e2827fe5SBenjamin Herrenschmidt };
43e2827fe5SBenjamin Herrenschmidt 
44b8b572e1SStephen Rothwell struct ppc64_caches {
45e2827fe5SBenjamin Herrenschmidt 	struct ppc_cache_info l1d;
46e2827fe5SBenjamin Herrenschmidt 	struct ppc_cache_info l1i;
4765e01f38SBenjamin Herrenschmidt 	struct ppc_cache_info l2;
4865e01f38SBenjamin Herrenschmidt 	struct ppc_cache_info l3;
49b8b572e1SStephen Rothwell };
50b8b572e1SStephen Rothwell 
51b8b572e1SStephen Rothwell extern struct ppc64_caches ppc64_caches;
52b8b572e1SStephen Rothwell #endif /* __powerpc64__ && ! __ASSEMBLY__ */
53b8b572e1SStephen Rothwell 
540ce63670SKevin Hao #if defined(__ASSEMBLY__)
550ce63670SKevin Hao /*
560ce63670SKevin Hao  * For a snooping icache, we still need a dummy icbi to purge all the
570ce63670SKevin Hao  * prefetched instructions from the ifetch buffers. We also need a sync
580ce63670SKevin Hao  * before the icbi to order the the actual stores to memory that might
590ce63670SKevin Hao  * have modified instructions with the icbi.
600ce63670SKevin Hao  */
610ce63670SKevin Hao #define PURGE_PREFETCHED_INS	\
620ce63670SKevin Hao 	sync;			\
630ce63670SKevin Hao 	icbi	0,r3;		\
640ce63670SKevin Hao 	sync;			\
650ce63670SKevin Hao 	isync
66ae3a197eSDavid Howells 
670ce63670SKevin Hao #else
6854cb27a7SDenys Vlasenko #define __read_mostly __attribute__((__section__(".data..read_mostly")))
69ae3a197eSDavid Howells 
70ae3a197eSDavid Howells #ifdef CONFIG_6xx
71ae3a197eSDavid Howells extern long _get_L2CR(void);
72ae3a197eSDavid Howells extern long _get_L3CR(void);
73ae3a197eSDavid Howells extern void _set_L2CR(unsigned long);
74ae3a197eSDavid Howells extern void _set_L3CR(unsigned long);
75ae3a197eSDavid Howells #else
76ae3a197eSDavid Howells #define _get_L2CR()	0L
77ae3a197eSDavid Howells #define _get_L3CR()	0L
78ae3a197eSDavid Howells #define _set_L2CR(val)	do { } while(0)
79ae3a197eSDavid Howells #define _set_L3CR(val)	do { } while(0)
80b8b572e1SStephen Rothwell #endif
81b8b572e1SStephen Rothwell 
82d6bfa02fSChristophe Leroy static inline void dcbz(void *addr)
83d6bfa02fSChristophe Leroy {
84d6bfa02fSChristophe Leroy 	__asm__ __volatile__ ("dcbz 0, %0" : : "r"(addr) : "memory");
85d6bfa02fSChristophe Leroy }
86d6bfa02fSChristophe Leroy 
87d6bfa02fSChristophe Leroy static inline void dcbi(void *addr)
88d6bfa02fSChristophe Leroy {
89d6bfa02fSChristophe Leroy 	__asm__ __volatile__ ("dcbi 0, %0" : : "r"(addr) : "memory");
90d6bfa02fSChristophe Leroy }
91d6bfa02fSChristophe Leroy 
92d6bfa02fSChristophe Leroy static inline void dcbf(void *addr)
93d6bfa02fSChristophe Leroy {
94d6bfa02fSChristophe Leroy 	__asm__ __volatile__ ("dcbf 0, %0" : : "r"(addr) : "memory");
95d6bfa02fSChristophe Leroy }
96d6bfa02fSChristophe Leroy 
97d6bfa02fSChristophe Leroy static inline void dcbst(void *addr)
98d6bfa02fSChristophe Leroy {
99d6bfa02fSChristophe Leroy 	__asm__ __volatile__ ("dcbst 0, %0" : : "r"(addr) : "memory");
100d6bfa02fSChristophe Leroy }
101ae3a197eSDavid Howells #endif /* !__ASSEMBLY__ */
102b8b572e1SStephen Rothwell #endif /* __KERNEL__ */
103b8b572e1SStephen Rothwell #endif /* _ASM_POWERPC_CACHE_H */
104