1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* spitfire.h: SpitFire/BlackBird/Cheetah inline MMU operations.
4 * Copyright (C) 1996 David S. Miller (davem@davemloft.net)
7 #ifndef _SPARC64_SPITFIRE_H
8 #define _SPARC64_SPITFIRE_H
14 /* The following register addresses are accessible via ASI_DMMU
15 * and ASI_IMMU, that is there is a distinct and unique copy of
16 * each these registers for each TLB.
18 #define TSB_TAG_TARGET 0x0000000000000000 /* All chips */
19 #define TLB_SFSR 0x0000000000000018 /* All chips */
20 #define TSB_REG 0x0000000000000028 /* All chips */
21 #define TLB_TAG_ACCESS 0x0000000000000030 /* All chips */
22 #define VIRT_WATCHPOINT 0x0000000000000038 /* All chips */
23 #define PHYS_WATCHPOINT 0x0000000000000040 /* All chips */
24 #define TSB_EXTENSION_P 0x0000000000000048 /* Ultra-III and later */
25 #define TSB_EXTENSION_S 0x0000000000000050 /* Ultra-III and later, D-TLB only */
26 #define TSB_EXTENSION_N 0x0000000000000058 /* Ultra-III and later */
27 #define TLB_TAG_ACCESS_EXT 0x0000000000000060 /* Ultra-III+ and later */
29 /* These registers only exist as one entity, and are accessed
32 #define PRIMARY_CONTEXT 0x0000000000000008
33 #define SECONDARY_CONTEXT 0x0000000000000010
34 #define DMMU_SFAR 0x0000000000000020
35 #define VIRT_WATCHPOINT 0x0000000000000038
36 #define PHYS_WATCHPOINT 0x0000000000000040
38 #define SPITFIRE_HIGHEST_LOCKED_TLBENT (64 - 1)
39 #define CHEETAH_HIGHEST_LOCKED_TLBENT (16 - 1)
41 #define L1DCACHE_SIZE 0x4000
43 #define SUN4V_CHIP_INVALID 0x00
44 #define SUN4V_CHIP_NIAGARA1 0x01
45 #define SUN4V_CHIP_NIAGARA2 0x02
46 #define SUN4V_CHIP_NIAGARA3 0x03
47 #define SUN4V_CHIP_NIAGARA4 0x04
48 #define SUN4V_CHIP_NIAGARA5 0x05
49 #define SUN4V_CHIP_SPARC_M6 0x06
50 #define SUN4V_CHIP_SPARC_M7 0x07
51 #define SUN4V_CHIP_SPARC_M8 0x08
52 #define SUN4V_CHIP_SPARC64X 0x8a
53 #define SUN4V_CHIP_SPARC_SN 0x8b
54 #define SUN4V_CHIP_UNKNOWN 0xff
57 * The following CPU_ID_xxx constants are used
58 * to identify the CPU type in the setup phase
61 #define CPU_ID_NIAGARA1 ('1')
62 #define CPU_ID_NIAGARA2 ('2')
63 #define CPU_ID_NIAGARA3 ('3')
64 #define CPU_ID_NIAGARA4 ('4')
65 #define CPU_ID_NIAGARA5 ('5')
66 #define CPU_ID_M6 ('6')
67 #define CPU_ID_M7 ('7')
68 #define CPU_ID_M8 ('8')
69 #define CPU_ID_SONOMA1 ('N')
73 enum ultra_tlb_layout
{
80 extern enum ultra_tlb_layout tlb_type
;
82 extern int sun4v_chip_type
;
84 extern int cheetah_pcache_forced_on
;
85 void cheetah_enable_pcache(void);
87 #define sparc64_highest_locked_tlbent() \
88 (tlb_type == spitfire ? \
89 SPITFIRE_HIGHEST_LOCKED_TLBENT : \
90 CHEETAH_HIGHEST_LOCKED_TLBENT)
92 extern int num_kernel_image_mappings
;
94 /* The data cache is write through, so this just invalidates the
97 static inline void spitfire_put_dcache_tag(unsigned long addr
, unsigned long tag
)
99 __asm__
__volatile__("stxa %0, [%1] %2\n\t"
102 : "r" (tag
), "r" (addr
), "i" (ASI_DCACHE_TAG
));
105 /* The instruction cache lines are flushed with this, but note that
106 * this does not flush the pipeline. It is possible for a line to
107 * get flushed but stale instructions to still be in the pipeline,
108 * a flush instruction (to any address) is sufficient to handle
109 * this issue after the line is invalidated.
111 static inline void spitfire_put_icache_tag(unsigned long addr
, unsigned long tag
)
113 __asm__
__volatile__("stxa %0, [%1] %2\n\t"
116 : "r" (tag
), "r" (addr
), "i" (ASI_IC_TAG
));
119 static inline unsigned long spitfire_get_dtlb_data(int entry
)
123 __asm__
__volatile__("ldxa [%1] %2, %0"
125 : "r" (entry
<< 3), "i" (ASI_DTLB_DATA_ACCESS
));
127 /* Clear TTE diag bits. */
128 data
&= ~0x0003fe0000000000UL
;
133 static inline unsigned long spitfire_get_dtlb_tag(int entry
)
137 __asm__
__volatile__("ldxa [%1] %2, %0"
139 : "r" (entry
<< 3), "i" (ASI_DTLB_TAG_READ
));
143 static inline void spitfire_put_dtlb_data(int entry
, unsigned long data
)
145 __asm__
__volatile__("stxa %0, [%1] %2\n\t"
148 : "r" (data
), "r" (entry
<< 3),
149 "i" (ASI_DTLB_DATA_ACCESS
));
152 static inline unsigned long spitfire_get_itlb_data(int entry
)
156 __asm__
__volatile__("ldxa [%1] %2, %0"
158 : "r" (entry
<< 3), "i" (ASI_ITLB_DATA_ACCESS
));
160 /* Clear TTE diag bits. */
161 data
&= ~0x0003fe0000000000UL
;
166 static inline unsigned long spitfire_get_itlb_tag(int entry
)
170 __asm__
__volatile__("ldxa [%1] %2, %0"
172 : "r" (entry
<< 3), "i" (ASI_ITLB_TAG_READ
));
176 static inline void spitfire_put_itlb_data(int entry
, unsigned long data
)
178 __asm__
__volatile__("stxa %0, [%1] %2\n\t"
181 : "r" (data
), "r" (entry
<< 3),
182 "i" (ASI_ITLB_DATA_ACCESS
));
185 static inline void spitfire_flush_dtlb_nucleus_page(unsigned long page
)
187 __asm__
__volatile__("stxa %%g0, [%0] %1\n\t"
190 : "r" (page
| 0x20), "i" (ASI_DMMU_DEMAP
));
193 static inline void spitfire_flush_itlb_nucleus_page(unsigned long page
)
195 __asm__
__volatile__("stxa %%g0, [%0] %1\n\t"
198 : "r" (page
| 0x20), "i" (ASI_IMMU_DEMAP
));
201 /* Cheetah has "all non-locked" tlb flushes. */
202 static inline void cheetah_flush_dtlb_all(void)
204 __asm__
__volatile__("stxa %%g0, [%0] %1\n\t"
207 : "r" (0x80), "i" (ASI_DMMU_DEMAP
));
210 static inline void cheetah_flush_itlb_all(void)
212 __asm__
__volatile__("stxa %%g0, [%0] %1\n\t"
215 : "r" (0x80), "i" (ASI_IMMU_DEMAP
));
218 /* Cheetah has a 4-tlb layout so direct access is a bit different.
219 * The first two TLBs are fully assosciative, hold 16 entries, and are
220 * used only for locked and >8K sized translations. One exists for
221 * data accesses and one for instruction accesses.
223 * The third TLB is for data accesses to 8K non-locked translations, is
224 * 2 way assosciative, and holds 512 entries. The fourth TLB is for
225 * instruction accesses to 8K non-locked translations, is 2 way
226 * assosciative, and holds 128 entries.
228 * Cheetah has some bug where bogus data can be returned from
229 * ASI_{D,I}TLB_DATA_ACCESS loads, doing the load twice fixes
230 * the problem for me. -DaveM
232 static inline unsigned long cheetah_get_ldtlb_data(int entry
)
236 __asm__
__volatile__("ldxa [%1] %2, %%g0\n\t"
239 : "r" ((0 << 16) | (entry
<< 3)),
240 "i" (ASI_DTLB_DATA_ACCESS
));
245 static inline unsigned long cheetah_get_litlb_data(int entry
)
249 __asm__
__volatile__("ldxa [%1] %2, %%g0\n\t"
252 : "r" ((0 << 16) | (entry
<< 3)),
253 "i" (ASI_ITLB_DATA_ACCESS
));
258 static inline unsigned long cheetah_get_ldtlb_tag(int entry
)
262 __asm__
__volatile__("ldxa [%1] %2, %0"
264 : "r" ((0 << 16) | (entry
<< 3)),
265 "i" (ASI_DTLB_TAG_READ
));
270 static inline unsigned long cheetah_get_litlb_tag(int entry
)
274 __asm__
__volatile__("ldxa [%1] %2, %0"
276 : "r" ((0 << 16) | (entry
<< 3)),
277 "i" (ASI_ITLB_TAG_READ
));
282 static inline void cheetah_put_ldtlb_data(int entry
, unsigned long data
)
284 __asm__
__volatile__("stxa %0, [%1] %2\n\t"
288 "r" ((0 << 16) | (entry
<< 3)),
289 "i" (ASI_DTLB_DATA_ACCESS
));
292 static inline void cheetah_put_litlb_data(int entry
, unsigned long data
)
294 __asm__
__volatile__("stxa %0, [%1] %2\n\t"
298 "r" ((0 << 16) | (entry
<< 3)),
299 "i" (ASI_ITLB_DATA_ACCESS
));
302 static inline unsigned long cheetah_get_dtlb_data(int entry
, int tlb
)
306 __asm__
__volatile__("ldxa [%1] %2, %%g0\n\t"
309 : "r" ((tlb
<< 16) | (entry
<< 3)), "i" (ASI_DTLB_DATA_ACCESS
));
314 static inline unsigned long cheetah_get_dtlb_tag(int entry
, int tlb
)
318 __asm__
__volatile__("ldxa [%1] %2, %0"
320 : "r" ((tlb
<< 16) | (entry
<< 3)), "i" (ASI_DTLB_TAG_READ
));
324 static inline void cheetah_put_dtlb_data(int entry
, unsigned long data
, int tlb
)
326 __asm__
__volatile__("stxa %0, [%1] %2\n\t"
330 "r" ((tlb
<< 16) | (entry
<< 3)),
331 "i" (ASI_DTLB_DATA_ACCESS
));
334 static inline unsigned long cheetah_get_itlb_data(int entry
)
338 __asm__
__volatile__("ldxa [%1] %2, %%g0\n\t"
341 : "r" ((2 << 16) | (entry
<< 3)),
342 "i" (ASI_ITLB_DATA_ACCESS
));
347 static inline unsigned long cheetah_get_itlb_tag(int entry
)
351 __asm__
__volatile__("ldxa [%1] %2, %0"
353 : "r" ((2 << 16) | (entry
<< 3)), "i" (ASI_ITLB_TAG_READ
));
357 static inline void cheetah_put_itlb_data(int entry
, unsigned long data
)
359 __asm__
__volatile__("stxa %0, [%1] %2\n\t"
362 : "r" (data
), "r" ((2 << 16) | (entry
<< 3)),
363 "i" (ASI_ITLB_DATA_ACCESS
));
366 #endif /* !(__ASSEMBLY__) */
367 #endif /* CONFIG_SPARC64 */
368 #endif /* !(_SPARC64_SPITFIRE_H) */