blob: 9cc2afe10ef01a101ba544e08524eb9e4200f888 [file] [log] [blame]
Sam Ravnborga00736e2008-06-19 20:26:19 +02001/* spitfire.h: SpitFire/BlackBird/Cheetah inline MMU operations.
2 *
3 * Copyright (C) 1996 David S. Miller (davem@davemloft.net)
4 */
5
6#ifndef _SPARC64_SPITFIRE_H
7#define _SPARC64_SPITFIRE_H
8
Sam Ravnborgd34dd822008-12-07 00:04:30 -08009#ifdef CONFIG_SPARC64
10
Sam Ravnborga00736e2008-06-19 20:26:19 +020011#include <asm/asi.h>
12
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.
16 */
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 */
27
28/* These registers only exist as one entity, and are accessed
29 * via ASI_DMMU only.
30 */
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
36
37#define SPITFIRE_HIGHEST_LOCKED_TLBENT (64 - 1)
38#define CHEETAH_HIGHEST_LOCKED_TLBENT (16 - 1)
39
40#define L1DCACHE_SIZE 0x4000
41
42#define SUN4V_CHIP_INVALID 0x00
43#define SUN4V_CHIP_NIAGARA1 0x01
44#define SUN4V_CHIP_NIAGARA2 0x02
David S. Miller15e36082011-07-27 20:42:51 -070045#define SUN4V_CHIP_NIAGARA3 0x03
David S. Miller08cefa92011-09-11 10:42:20 -070046#define SUN4V_CHIP_NIAGARA4 0x04
47#define SUN4V_CHIP_NIAGARA5 0x05
Allen Paiscadbb582014-09-08 11:48:53 +053048#define SUN4V_CHIP_SPARC_M6 0x06
49#define SUN4V_CHIP_SPARC_M7 0x07
Allen Pais76950e62013-03-05 23:47:59 +000050#define SUN4V_CHIP_SPARC64X 0x8a
Khalid Azizc5b8b5b2016-04-19 11:12:54 -060051#define SUN4V_CHIP_SPARC_SN 0x8b
Sam Ravnborga00736e2008-06-19 20:26:19 +020052#define SUN4V_CHIP_UNKNOWN 0xff
53
Allen Pais9e48cd42017-07-24 11:44:17 +053054/*
55 * The following CPU_ID_xxx constants are used
56 * to identify the CPU type in the setup phase
57 * (see head_64.S)
58 */
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')
67
Sam Ravnborga00736e2008-06-19 20:26:19 +020068#ifndef __ASSEMBLY__
69
70enum ultra_tlb_layout {
71 spitfire = 0,
72 cheetah = 1,
73 cheetah_plus = 2,
74 hypervisor = 3,
75};
76
77extern enum ultra_tlb_layout tlb_type;
78
79extern int sun4v_chip_type;
80
81extern int cheetah_pcache_forced_on;
Sam Ravnborgf05a6862014-05-16 23:25:50 +020082void cheetah_enable_pcache(void);
Sam Ravnborga00736e2008-06-19 20:26:19 +020083
84#define sparc64_highest_locked_tlbent() \
85 (tlb_type == spitfire ? \
86 SPITFIRE_HIGHEST_LOCKED_TLBENT : \
87 CHEETAH_HIGHEST_LOCKED_TLBENT)
88
89extern int num_kernel_image_mappings;
90
91/* The data cache is write through, so this just invalidates the
92 * specified line.
93 */
94static inline void spitfire_put_dcache_tag(unsigned long addr, unsigned long tag)
95{
96 __asm__ __volatile__("stxa %0, [%1] %2\n\t"
97 "membar #Sync"
98 : /* No outputs */
99 : "r" (tag), "r" (addr), "i" (ASI_DCACHE_TAG));
100}
101
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.
107 */
108static inline void spitfire_put_icache_tag(unsigned long addr, unsigned long tag)
109{
110 __asm__ __volatile__("stxa %0, [%1] %2\n\t"
111 "membar #Sync"
112 : /* No outputs */
113 : "r" (tag), "r" (addr), "i" (ASI_IC_TAG));
114}
115
116static inline unsigned long spitfire_get_dtlb_data(int entry)
117{
118 unsigned long data;
119
120 __asm__ __volatile__("ldxa [%1] %2, %0"
121 : "=r" (data)
122 : "r" (entry << 3), "i" (ASI_DTLB_DATA_ACCESS));
123
124 /* Clear TTE diag bits. */
125 data &= ~0x0003fe0000000000UL;
126
127 return data;
128}
129
130static inline unsigned long spitfire_get_dtlb_tag(int entry)
131{
132 unsigned long tag;
133
134 __asm__ __volatile__("ldxa [%1] %2, %0"
135 : "=r" (tag)
136 : "r" (entry << 3), "i" (ASI_DTLB_TAG_READ));
137 return tag;
138}
139
140static inline void spitfire_put_dtlb_data(int entry, unsigned long data)
141{
142 __asm__ __volatile__("stxa %0, [%1] %2\n\t"
143 "membar #Sync"
144 : /* No outputs */
145 : "r" (data), "r" (entry << 3),
146 "i" (ASI_DTLB_DATA_ACCESS));
147}
148
149static inline unsigned long spitfire_get_itlb_data(int entry)
150{
151 unsigned long data;
152
153 __asm__ __volatile__("ldxa [%1] %2, %0"
154 : "=r" (data)
155 : "r" (entry << 3), "i" (ASI_ITLB_DATA_ACCESS));
156
157 /* Clear TTE diag bits. */
158 data &= ~0x0003fe0000000000UL;
159
160 return data;
161}
162
163static inline unsigned long spitfire_get_itlb_tag(int entry)
164{
165 unsigned long tag;
166
167 __asm__ __volatile__("ldxa [%1] %2, %0"
168 : "=r" (tag)
169 : "r" (entry << 3), "i" (ASI_ITLB_TAG_READ));
170 return tag;
171}
172
173static inline void spitfire_put_itlb_data(int entry, unsigned long data)
174{
175 __asm__ __volatile__("stxa %0, [%1] %2\n\t"
176 "membar #Sync"
177 : /* No outputs */
178 : "r" (data), "r" (entry << 3),
179 "i" (ASI_ITLB_DATA_ACCESS));
180}
181
182static inline void spitfire_flush_dtlb_nucleus_page(unsigned long page)
183{
184 __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
185 "membar #Sync"
186 : /* No outputs */
187 : "r" (page | 0x20), "i" (ASI_DMMU_DEMAP));
188}
189
190static inline void spitfire_flush_itlb_nucleus_page(unsigned long page)
191{
192 __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
193 "membar #Sync"
194 : /* No outputs */
195 : "r" (page | 0x20), "i" (ASI_IMMU_DEMAP));
196}
197
198/* Cheetah has "all non-locked" tlb flushes. */
199static inline void cheetah_flush_dtlb_all(void)
200{
201 __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
202 "membar #Sync"
203 : /* No outputs */
204 : "r" (0x80), "i" (ASI_DMMU_DEMAP));
205}
206
207static inline void cheetah_flush_itlb_all(void)
208{
209 __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
210 "membar #Sync"
211 : /* No outputs */
212 : "r" (0x80), "i" (ASI_IMMU_DEMAP));
213}
214
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.
219 *
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.
224 *
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
228 */
229static inline unsigned long cheetah_get_ldtlb_data(int entry)
230{
231 unsigned long data;
232
233 __asm__ __volatile__("ldxa [%1] %2, %%g0\n\t"
234 "ldxa [%1] %2, %0"
235 : "=r" (data)
236 : "r" ((0 << 16) | (entry << 3)),
237 "i" (ASI_DTLB_DATA_ACCESS));
238
239 return data;
240}
241
242static inline unsigned long cheetah_get_litlb_data(int entry)
243{
244 unsigned long data;
245
246 __asm__ __volatile__("ldxa [%1] %2, %%g0\n\t"
247 "ldxa [%1] %2, %0"
248 : "=r" (data)
249 : "r" ((0 << 16) | (entry << 3)),
250 "i" (ASI_ITLB_DATA_ACCESS));
251
252 return data;
253}
254
255static inline unsigned long cheetah_get_ldtlb_tag(int entry)
256{
257 unsigned long tag;
258
259 __asm__ __volatile__("ldxa [%1] %2, %0"
260 : "=r" (tag)
261 : "r" ((0 << 16) | (entry << 3)),
262 "i" (ASI_DTLB_TAG_READ));
263
264 return tag;
265}
266
267static inline unsigned long cheetah_get_litlb_tag(int entry)
268{
269 unsigned long tag;
270
271 __asm__ __volatile__("ldxa [%1] %2, %0"
272 : "=r" (tag)
273 : "r" ((0 << 16) | (entry << 3)),
274 "i" (ASI_ITLB_TAG_READ));
275
276 return tag;
277}
278
279static inline void cheetah_put_ldtlb_data(int entry, unsigned long data)
280{
281 __asm__ __volatile__("stxa %0, [%1] %2\n\t"
282 "membar #Sync"
283 : /* No outputs */
284 : "r" (data),
285 "r" ((0 << 16) | (entry << 3)),
286 "i" (ASI_DTLB_DATA_ACCESS));
287}
288
289static inline void cheetah_put_litlb_data(int entry, unsigned long data)
290{
291 __asm__ __volatile__("stxa %0, [%1] %2\n\t"
292 "membar #Sync"
293 : /* No outputs */
294 : "r" (data),
295 "r" ((0 << 16) | (entry << 3)),
296 "i" (ASI_ITLB_DATA_ACCESS));
297}
298
299static inline unsigned long cheetah_get_dtlb_data(int entry, int tlb)
300{
301 unsigned long data;
302
303 __asm__ __volatile__("ldxa [%1] %2, %%g0\n\t"
304 "ldxa [%1] %2, %0"
305 : "=r" (data)
306 : "r" ((tlb << 16) | (entry << 3)), "i" (ASI_DTLB_DATA_ACCESS));
307
308 return data;
309}
310
311static inline unsigned long cheetah_get_dtlb_tag(int entry, int tlb)
312{
313 unsigned long tag;
314
315 __asm__ __volatile__("ldxa [%1] %2, %0"
316 : "=r" (tag)
317 : "r" ((tlb << 16) | (entry << 3)), "i" (ASI_DTLB_TAG_READ));
318 return tag;
319}
320
321static inline void cheetah_put_dtlb_data(int entry, unsigned long data, int tlb)
322{
323 __asm__ __volatile__("stxa %0, [%1] %2\n\t"
324 "membar #Sync"
325 : /* No outputs */
326 : "r" (data),
327 "r" ((tlb << 16) | (entry << 3)),
328 "i" (ASI_DTLB_DATA_ACCESS));
329}
330
331static inline unsigned long cheetah_get_itlb_data(int entry)
332{
333 unsigned long data;
334
335 __asm__ __volatile__("ldxa [%1] %2, %%g0\n\t"
336 "ldxa [%1] %2, %0"
337 : "=r" (data)
338 : "r" ((2 << 16) | (entry << 3)),
339 "i" (ASI_ITLB_DATA_ACCESS));
340
341 return data;
342}
343
344static inline unsigned long cheetah_get_itlb_tag(int entry)
345{
346 unsigned long tag;
347
348 __asm__ __volatile__("ldxa [%1] %2, %0"
349 : "=r" (tag)
350 : "r" ((2 << 16) | (entry << 3)), "i" (ASI_ITLB_TAG_READ));
351 return tag;
352}
353
354static inline void cheetah_put_itlb_data(int entry, unsigned long data)
355{
356 __asm__ __volatile__("stxa %0, [%1] %2\n\t"
357 "membar #Sync"
358 : /* No outputs */
359 : "r" (data), "r" ((2 << 16) | (entry << 3)),
360 "i" (ASI_ITLB_DATA_ACCESS));
361}
362
363#endif /* !(__ASSEMBLY__) */
Sam Ravnborgd34dd822008-12-07 00:04:30 -0800364#endif /* CONFIG_SPARC64 */
Sam Ravnborga00736e2008-06-19 20:26:19 +0200365#endif /* !(_SPARC64_SPITFIRE_H) */