xref: /rk3399_rockchip-uboot/arch/powerpc/include/asm/cache.h (revision 87e4c6020eff05133e40ab8b7b0e37e6a2be37e4)
1a47a12beSStefan Roese /*
2a47a12beSStefan Roese  * include/asm-ppc/cache.h
3a47a12beSStefan Roese  */
4a47a12beSStefan Roese #ifndef __ARCH_PPC_CACHE_H
5a47a12beSStefan Roese #define __ARCH_PPC_CACHE_H
6a47a12beSStefan Roese 
7a47a12beSStefan Roese #include <asm/processor.h>
8a47a12beSStefan Roese 
9a47a12beSStefan Roese /* bytes per L1 cache line */
10*87e4c602SChristophe Leroy #if defined(CONFIG_MPC8xx)
11907208c4SChristophe Leroy #define	L1_CACHE_SHIFT	4
12907208c4SChristophe Leroy #elif defined(CONFIG_PPC64BRIDGE)
13a47a12beSStefan Roese #define L1_CACHE_SHIFT	7
14a47a12beSStefan Roese #elif defined(CONFIG_E500MC)
15a47a12beSStefan Roese #define L1_CACHE_SHIFT	6
16a47a12beSStefan Roese #else
17a47a12beSStefan Roese #define	L1_CACHE_SHIFT	5
18a47a12beSStefan Roese #endif
19a47a12beSStefan Roese 
20a47a12beSStefan Roese #define L1_CACHE_BYTES          (1 << L1_CACHE_SHIFT)
21a47a12beSStefan Roese 
22a47a12beSStefan Roese /*
230991701aSAnton Staaf  * Use the L1 data cache line size value for the minimum DMA buffer alignment
240991701aSAnton Staaf  * on PowerPC.
250991701aSAnton Staaf  */
260991701aSAnton Staaf #define ARCH_DMA_MINALIGN	L1_CACHE_BYTES
270991701aSAnton Staaf 
280991701aSAnton Staaf /*
29a47a12beSStefan Roese  * For compatibility reasons support the CONFIG_SYS_CACHELINE_SIZE too
30a47a12beSStefan Roese  */
31a47a12beSStefan Roese #ifndef CONFIG_SYS_CACHELINE_SIZE
32a47a12beSStefan Roese #define CONFIG_SYS_CACHELINE_SIZE	L1_CACHE_BYTES
33a47a12beSStefan Roese #endif
34a47a12beSStefan Roese 
35a47a12beSStefan Roese #define	L1_CACHE_ALIGN(x)       (((x)+(L1_CACHE_BYTES-1))&~(L1_CACHE_BYTES-1))
36a47a12beSStefan Roese #define	L1_CACHE_PAGES		8
37a47a12beSStefan Roese 
38a47a12beSStefan Roese #define	SMP_CACHE_BYTES L1_CACHE_BYTES
39a47a12beSStefan Roese 
40a47a12beSStefan Roese #ifdef MODULE
41a47a12beSStefan Roese #define __cacheline_aligned __attribute__((__aligned__(L1_CACHE_BYTES)))
42a47a12beSStefan Roese #else
43a47a12beSStefan Roese #define __cacheline_aligned					\
44a47a12beSStefan Roese   __attribute__((__aligned__(L1_CACHE_BYTES),			\
45a47a12beSStefan Roese 		 __section__(".data.cacheline_aligned")))
46a47a12beSStefan Roese #endif
47a47a12beSStefan Roese 
48a47a12beSStefan Roese #if defined(__KERNEL__) && !defined(__ASSEMBLY__)
49a47a12beSStefan Roese extern void flush_dcache_range(unsigned long start, unsigned long stop);
50a47a12beSStefan Roese extern void clean_dcache_range(unsigned long start, unsigned long stop);
51a47a12beSStefan Roese extern void invalidate_dcache_range(unsigned long start, unsigned long stop);
52a47a12beSStefan Roese extern void flush_dcache(void);
53a47a12beSStefan Roese extern void invalidate_dcache(void);
54a47a12beSStefan Roese extern void invalidate_icache(void);
55a47a12beSStefan Roese #ifdef CONFIG_SYS_INIT_RAM_LOCK
56a47a12beSStefan Roese extern void unlock_ram_in_cache(void);
57a47a12beSStefan Roese #endif /* CONFIG_SYS_INIT_RAM_LOCK */
58a47a12beSStefan Roese #endif /* __ASSEMBLY__ */
59a47a12beSStefan Roese 
607cb72723STang Yuantian #if defined(__KERNEL__) && !defined(__ASSEMBLY__)
617cb72723STang Yuantian int l2cache_init(void);
627cb72723STang Yuantian void enable_cpc(void);
637cb72723STang Yuantian void disable_cpc_sram(void);
647cb72723STang Yuantian #endif
657cb72723STang Yuantian 
66a47a12beSStefan Roese /* prep registers for L2 */
67a47a12beSStefan Roese #define CACHECRBA       0x80000823      /* Cache configuration register address */
68a47a12beSStefan Roese #define L2CACHE_MASK	0x03	/* Mask for 2 L2 Cache bits */
69a47a12beSStefan Roese #define L2CACHE_512KB	0x00	/* 512KB */
70a47a12beSStefan Roese #define L2CACHE_256KB	0x01	/* 256KB */
71a47a12beSStefan Roese #define L2CACHE_1MB	0x02	/* 1MB */
72a47a12beSStefan Roese #define L2CACHE_NONE	0x03	/* NONE */
73a47a12beSStefan Roese #define L2CACHE_PARITY  0x08    /* Mask for L2 Cache Parity Protected bit */
74a47a12beSStefan Roese 
75*87e4c602SChristophe Leroy #ifdef CONFIG_MPC8xx
76907208c4SChristophe Leroy /* Cache control on the MPC8xx is provided through some additional
77907208c4SChristophe Leroy  * special purpose registers.
78907208c4SChristophe Leroy  */
79907208c4SChristophe Leroy #define IC_CST		560	/* Instruction cache control/status */
80907208c4SChristophe Leroy #define IC_ADR		561	/* Address needed for some commands */
81907208c4SChristophe Leroy #define IC_DAT		562	/* Read-only data register */
82907208c4SChristophe Leroy #define DC_CST		568	/* Data cache control/status */
83907208c4SChristophe Leroy #define DC_ADR		569	/* Address needed for some commands */
84907208c4SChristophe Leroy #define DC_DAT		570	/* Read-only data register */
85907208c4SChristophe Leroy 
86907208c4SChristophe Leroy /* Commands.  Only the first few are available to the instruction cache.
87907208c4SChristophe Leroy */
88907208c4SChristophe Leroy #define	IDC_ENABLE	0x02000000	/* Cache enable */
89907208c4SChristophe Leroy #define IDC_DISABLE	0x04000000	/* Cache disable */
90907208c4SChristophe Leroy #define IDC_LDLCK	0x06000000	/* Load and lock */
91907208c4SChristophe Leroy #define IDC_UNLINE	0x08000000	/* Unlock line */
92907208c4SChristophe Leroy #define IDC_UNALL	0x0a000000	/* Unlock all */
93907208c4SChristophe Leroy #define IDC_INVALL	0x0c000000	/* Invalidate all */
94907208c4SChristophe Leroy 
95907208c4SChristophe Leroy #define DC_FLINE	0x0e000000	/* Flush data cache line */
96907208c4SChristophe Leroy #define DC_SFWT		0x01000000	/* Set forced writethrough mode */
97907208c4SChristophe Leroy #define DC_CFWT		0x03000000	/* Clear forced writethrough mode */
98907208c4SChristophe Leroy #define DC_SLES		0x05000000	/* Set little endian swap mode */
99907208c4SChristophe Leroy #define DC_CLES		0x07000000	/* Clear little endian swap mode */
100907208c4SChristophe Leroy 
101907208c4SChristophe Leroy /* Status.
102907208c4SChristophe Leroy */
103907208c4SChristophe Leroy #define IDC_ENABLED	0x80000000	/* Cache is enabled */
104907208c4SChristophe Leroy #define IDC_CERR1	0x00200000	/* Cache error 1 */
105907208c4SChristophe Leroy #define IDC_CERR2	0x00100000	/* Cache error 2 */
106907208c4SChristophe Leroy #define IDC_CERR3	0x00080000	/* Cache error 3 */
107907208c4SChristophe Leroy 
108907208c4SChristophe Leroy #define DC_DFWT		0x40000000	/* Data cache is forced write through */
109907208c4SChristophe Leroy #define DC_LES		0x20000000	/* Caches are little endian mode */
110506cb8beSChristophe Leroy 
111506cb8beSChristophe Leroy #if !defined(__ASSEMBLY__)
rd_ic_cst(void)112506cb8beSChristophe Leroy static inline uint rd_ic_cst(void)
113506cb8beSChristophe Leroy {
114506cb8beSChristophe Leroy 	return mfspr(IC_CST);
115506cb8beSChristophe Leroy }
116506cb8beSChristophe Leroy 
wr_ic_cst(uint val)117506cb8beSChristophe Leroy static inline void wr_ic_cst(uint val)
118506cb8beSChristophe Leroy {
119506cb8beSChristophe Leroy 	mtspr(IC_CST, val);
120506cb8beSChristophe Leroy }
121506cb8beSChristophe Leroy 
wr_ic_adr(uint val)122506cb8beSChristophe Leroy static inline void wr_ic_adr(uint val)
123506cb8beSChristophe Leroy {
124506cb8beSChristophe Leroy 	mtspr(IC_ADR, val);
125506cb8beSChristophe Leroy }
126506cb8beSChristophe Leroy 
rd_dc_cst(void)127506cb8beSChristophe Leroy static inline uint rd_dc_cst(void)
128506cb8beSChristophe Leroy {
129506cb8beSChristophe Leroy 	return mfspr(DC_CST);
130506cb8beSChristophe Leroy }
131506cb8beSChristophe Leroy 
wr_dc_cst(uint val)132506cb8beSChristophe Leroy static inline void wr_dc_cst(uint val)
133506cb8beSChristophe Leroy {
134506cb8beSChristophe Leroy 	mtspr(DC_CST, val);
135506cb8beSChristophe Leroy }
136506cb8beSChristophe Leroy 
wr_dc_adr(uint val)137506cb8beSChristophe Leroy static inline void wr_dc_adr(uint val)
138506cb8beSChristophe Leroy {
139506cb8beSChristophe Leroy 	mtspr(DC_ADR, val);
140506cb8beSChristophe Leroy }
141506cb8beSChristophe Leroy #endif
142*87e4c602SChristophe Leroy #endif /* CONFIG_MPC8xx */
143907208c4SChristophe Leroy 
144a47a12beSStefan Roese #endif
145