1 /* spitfire.h: SpitFire/BlackBird/Cheetah inline MMU operations.
3 * Copyright (C) 1996 David S. Miller (davem@davemloft.net)
6 #ifndef _SPARC64_SPITFIRE_H
7 #define _SPARC64_SPITFIRE_H
13 /* The following register addresses are accessible via ASI_DMMU
14 * and ASI_IMMU, that is there is a distinct and unique copy of
15 * each these registers for each TLB.
17 #define TSB_TAG_TARGET 0x0000000000000000 /* All chips */
18 #define TLB_SFSR 0x0000000000000018 /* All chips */
19 #define TSB_REG 0x0000000000000028 /* All chips */
20 #define TLB_TAG_ACCESS 0x0000000000000030 /* All chips */
21 #define VIRT_WATCHPOINT 0x0000000000000038 /* All chips */
22 #define PHYS_WATCHPOINT 0x0000000000000040 /* All chips */
23 #define TSB_EXTENSION_P 0x0000000000000048 /* Ultra-III and later */
24 #define TSB_EXTENSION_S 0x0000000000000050 /* Ultra-III and later, D-TLB only */
25 #define TSB_EXTENSION_N 0x0000000000000058 /* Ultra-III and later */
26 #define TLB_TAG_ACCESS_EXT 0x0000000000000060 /* Ultra-III+ and later */
28 /* These registers only exist as one entity, and are accessed
31 #define PRIMARY_CONTEXT 0x0000000000000008
32 #define SECONDARY_CONTEXT 0x0000000000000010
33 #define DMMU_SFAR 0x0000000000000020
34 #define VIRT_WATCHPOINT 0x0000000000000038
35 #define PHYS_WATCHPOINT 0x0000000000000040
37 #define SPITFIRE_HIGHEST_LOCKED_TLBENT (64 - 1)
38 #define CHEETAH_HIGHEST_LOCKED_TLBENT (16 - 1)
40 #define L1DCACHE_SIZE 0x4000
42 #define SUN4V_CHIP_INVALID 0x00
43 #define SUN4V_CHIP_NIAGARA1 0x01
44 #define SUN4V_CHIP_NIAGARA2 0x02
45 #define SUN4V_CHIP_NIAGARA3 0x03
46 #define SUN4V_CHIP_NIAGARA4 0x04
47 #define SUN4V_CHIP_NIAGARA5 0x05
48 #define SUN4V_CHIP_SPARC_M6 0x06
49 #define SUN4V_CHIP_SPARC_M7 0x07
50 #define SUN4V_CHIP_SPARC64X 0x8a
51 #define SUN4V_CHIP_SPARC_SN 0x8b
52 #define SUN4V_CHIP_UNKNOWN 0xff
55 * The following CPU_ID_xxx constants are used
56 * to identify the CPU type in the setup phase
59 #define CPU_ID_NIAGARA1 ('1')
60 #define CPU_ID_NIAGARA2 ('2')
61 #define CPU_ID_NIAGARA3 ('3')
62 #define CPU_ID_NIAGARA4 ('4')
63 #define CPU_ID_NIAGARA5 ('5')
64 #define CPU_ID_M6 ('6')
65 #define CPU_ID_M7 ('7')
66 #define CPU_ID_SONOMA1 ('N')
70 enum ultra_tlb_layout {
77 extern enum ultra_tlb_layout tlb_type;
79 extern int sun4v_chip_type;
81 extern int cheetah_pcache_forced_on;
82 void cheetah_enable_pcache(void);
84 #define sparc64_highest_locked_tlbent() \
85 (tlb_type == spitfire ? \
86 SPITFIRE_HIGHEST_LOCKED_TLBENT : \
87 CHEETAH_HIGHEST_LOCKED_TLBENT)
89 extern int num_kernel_image_mappings;
91 /* The data cache is write through, so this just invalidates the
94 static inline void spitfire_put_dcache_tag(unsigned long addr, unsigned long tag)
96 __asm__ __volatile__("stxa %0, [%1] %2\n\t"
99 : "r" (tag), "r" (addr), "i" (ASI_DCACHE_TAG));
102 /* The instruction cache lines are flushed with this, but note that
103 * this does not flush the pipeline. It is possible for a line to
104 * get flushed but stale instructions to still be in the pipeline,
105 * a flush instruction (to any address) is sufficient to handle
106 * this issue after the line is invalidated.
108 static inline void spitfire_put_icache_tag(unsigned long addr, unsigned long tag)
110 __asm__ __volatile__("stxa %0, [%1] %2\n\t"
113 : "r" (tag), "r" (addr), "i" (ASI_IC_TAG));
116 static inline unsigned long spitfire_get_dtlb_data(int entry)
120 __asm__ __volatile__("ldxa [%1] %2, %0"
122 : "r" (entry << 3), "i" (ASI_DTLB_DATA_ACCESS));
124 /* Clear TTE diag bits. */
125 data &= ~0x0003fe0000000000UL;
130 static inline unsigned long spitfire_get_dtlb_tag(int entry)
134 __asm__ __volatile__("ldxa [%1] %2, %0"
136 : "r" (entry << 3), "i" (ASI_DTLB_TAG_READ));
140 static inline void spitfire_put_dtlb_data(int entry, unsigned long data)
142 __asm__ __volatile__("stxa %0, [%1] %2\n\t"
145 : "r" (data), "r" (entry << 3),
146 "i" (ASI_DTLB_DATA_ACCESS));
149 static inline unsigned long spitfire_get_itlb_data(int entry)
153 __asm__ __volatile__("ldxa [%1] %2, %0"
155 : "r" (entry << 3), "i" (ASI_ITLB_DATA_ACCESS));
157 /* Clear TTE diag bits. */
158 data &= ~0x0003fe0000000000UL;
163 static inline unsigned long spitfire_get_itlb_tag(int entry)
167 __asm__ __volatile__("ldxa [%1] %2, %0"
169 : "r" (entry << 3), "i" (ASI_ITLB_TAG_READ));
173 static inline void spitfire_put_itlb_data(int entry, unsigned long data)
175 __asm__ __volatile__("stxa %0, [%1] %2\n\t"
178 : "r" (data), "r" (entry << 3),
179 "i" (ASI_ITLB_DATA_ACCESS));
182 static inline void spitfire_flush_dtlb_nucleus_page(unsigned long page)
184 __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
187 : "r" (page | 0x20), "i" (ASI_DMMU_DEMAP));
190 static inline void spitfire_flush_itlb_nucleus_page(unsigned long page)
192 __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
195 : "r" (page | 0x20), "i" (ASI_IMMU_DEMAP));
198 /* Cheetah has "all non-locked" tlb flushes. */
199 static inline void cheetah_flush_dtlb_all(void)
201 __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
204 : "r" (0x80), "i" (ASI_DMMU_DEMAP));
207 static inline void cheetah_flush_itlb_all(void)
209 __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
212 : "r" (0x80), "i" (ASI_IMMU_DEMAP));
215 /* Cheetah has a 4-tlb layout so direct access is a bit different.
216 * The first two TLBs are fully assosciative, hold 16 entries, and are
217 * used only for locked and >8K sized translations. One exists for
218 * data accesses and one for instruction accesses.
220 * The third TLB is for data accesses to 8K non-locked translations, is
221 * 2 way assosciative, and holds 512 entries. The fourth TLB is for
222 * instruction accesses to 8K non-locked translations, is 2 way
223 * assosciative, and holds 128 entries.
225 * Cheetah has some bug where bogus data can be returned from
226 * ASI_{D,I}TLB_DATA_ACCESS loads, doing the load twice fixes
227 * the problem for me. -DaveM
229 static inline unsigned long cheetah_get_ldtlb_data(int entry)
233 __asm__ __volatile__("ldxa [%1] %2, %%g0\n\t"
236 : "r" ((0 << 16) | (entry << 3)),
237 "i" (ASI_DTLB_DATA_ACCESS));
242 static inline unsigned long cheetah_get_litlb_data(int entry)
246 __asm__ __volatile__("ldxa [%1] %2, %%g0\n\t"
249 : "r" ((0 << 16) | (entry << 3)),
250 "i" (ASI_ITLB_DATA_ACCESS));
255 static inline unsigned long cheetah_get_ldtlb_tag(int entry)
259 __asm__ __volatile__("ldxa [%1] %2, %0"
261 : "r" ((0 << 16) | (entry << 3)),
262 "i" (ASI_DTLB_TAG_READ));
267 static inline unsigned long cheetah_get_litlb_tag(int entry)
271 __asm__ __volatile__("ldxa [%1] %2, %0"
273 : "r" ((0 << 16) | (entry << 3)),
274 "i" (ASI_ITLB_TAG_READ));
279 static inline void cheetah_put_ldtlb_data(int entry, unsigned long data)
281 __asm__ __volatile__("stxa %0, [%1] %2\n\t"
285 "r" ((0 << 16) | (entry << 3)),
286 "i" (ASI_DTLB_DATA_ACCESS));
289 static inline void cheetah_put_litlb_data(int entry, unsigned long data)
291 __asm__ __volatile__("stxa %0, [%1] %2\n\t"
295 "r" ((0 << 16) | (entry << 3)),
296 "i" (ASI_ITLB_DATA_ACCESS));
299 static inline unsigned long cheetah_get_dtlb_data(int entry, int tlb)
303 __asm__ __volatile__("ldxa [%1] %2, %%g0\n\t"
306 : "r" ((tlb << 16) | (entry << 3)), "i" (ASI_DTLB_DATA_ACCESS));
311 static inline unsigned long cheetah_get_dtlb_tag(int entry, int tlb)
315 __asm__ __volatile__("ldxa [%1] %2, %0"
317 : "r" ((tlb << 16) | (entry << 3)), "i" (ASI_DTLB_TAG_READ));
321 static inline void cheetah_put_dtlb_data(int entry, unsigned long data, int tlb)
323 __asm__ __volatile__("stxa %0, [%1] %2\n\t"
327 "r" ((tlb << 16) | (entry << 3)),
328 "i" (ASI_DTLB_DATA_ACCESS));
331 static inline unsigned long cheetah_get_itlb_data(int entry)
335 __asm__ __volatile__("ldxa [%1] %2, %%g0\n\t"
338 : "r" ((2 << 16) | (entry << 3)),
339 "i" (ASI_ITLB_DATA_ACCESS));
344 static inline unsigned long cheetah_get_itlb_tag(int entry)
348 __asm__ __volatile__("ldxa [%1] %2, %0"
350 : "r" ((2 << 16) | (entry << 3)), "i" (ASI_ITLB_TAG_READ));
354 static inline void cheetah_put_itlb_data(int entry, unsigned long data)
356 __asm__ __volatile__("stxa %0, [%1] %2\n\t"
359 : "r" (data), "r" ((2 << 16) | (entry << 3)),
360 "i" (ASI_ITLB_DATA_ACCESS));
363 #endif /* !(__ASSEMBLY__) */
364 #endif /* CONFIG_SPARC64 */
365 #endif /* !(_SPARC64_SPITFIRE_H) */