sparc32,leon: move leon ASI definitions to asi.h
[firefly-linux-kernel-4.4.55.git] / arch / sparc / include / asm / leon.h
1 /*
2  * Copyright (C) 2004 Konrad Eisele (eiselekd@web.de,konrad@gaisler.com) Gaisler Research
3  * Copyright (C) 2004 Stefan Holst (mail@s-holst.de) Uni-Stuttgart
4  * Copyright (C) 2009 Daniel Hellstrom (daniel@gaisler.com) Aeroflex Gaisler AB
5  * Copyright (C) 2009 Konrad Eisele (konrad@gaisler.com) Aeroflex Gaisler AB
6  */
7
8 #ifndef LEON_H_INCLUDE
9 #define LEON_H_INCLUDE
10
11 #ifdef CONFIG_SPARC_LEON
12
13 /* mmu register access, ASI_LEON_MMUREGS */
14 #define LEON_CNR_CTRL           0x000
15 #define LEON_CNR_CTXP           0x100
16 #define LEON_CNR_CTX            0x200
17 #define LEON_CNR_F              0x300
18 #define LEON_CNR_FADDR          0x400
19
20 #define LEON_CNR_CTX_NCTX       256     /*number of MMU ctx */
21
22 #define LEON_CNR_CTRL_TLBDIS    0x80000000
23
24 #define LEON_MMUTLB_ENT_MAX     64
25
26 /*
27  * diagnostic access from mmutlb.vhd:
28  * 0: pte address
29  * 4: pte
30  * 8: additional flags
31  */
32 #define LEON_DIAGF_LVL          0x3
33 #define LEON_DIAGF_WR           0x8
34 #define LEON_DIAGF_WR_SHIFT     3
35 #define LEON_DIAGF_HIT          0x10
36 #define LEON_DIAGF_HIT_SHIFT    4
37 #define LEON_DIAGF_CTX          0x1fe0
38 #define LEON_DIAGF_CTX_SHIFT    5
39 #define LEON_DIAGF_VALID        0x2000
40 #define LEON_DIAGF_VALID_SHIFT  13
41
42 /* irq masks */
43 #define LEON_HARD_INT(x)        (1 << (x))      /* irq 0-15 */
44 #define LEON_IRQMASK_R          0x0000fffe      /* bit 15- 1 of lregs.irqmask */
45 #define LEON_IRQPRIO_R          0xfffe0000      /* bit 31-17 of lregs.irqmask */
46
47 /* leon uart register definitions */
48 #define LEON_OFF_UDATA  0x0
49 #define LEON_OFF_USTAT  0x4
50 #define LEON_OFF_UCTRL  0x8
51 #define LEON_OFF_USCAL  0xc
52
53 #define LEON_UCTRL_RE   0x01
54 #define LEON_UCTRL_TE   0x02
55 #define LEON_UCTRL_RI   0x04
56 #define LEON_UCTRL_TI   0x08
57 #define LEON_UCTRL_PS   0x10
58 #define LEON_UCTRL_PE   0x20
59 #define LEON_UCTRL_FL   0x40
60 #define LEON_UCTRL_LB   0x80
61
62 #define LEON_USTAT_DR   0x01
63 #define LEON_USTAT_TS   0x02
64 #define LEON_USTAT_TH   0x04
65 #define LEON_USTAT_BR   0x08
66 #define LEON_USTAT_OV   0x10
67 #define LEON_USTAT_PE   0x20
68 #define LEON_USTAT_FE   0x40
69
70 #define LEON_MCFG2_SRAMDIS              0x00002000
71 #define LEON_MCFG2_SDRAMEN              0x00004000
72 #define LEON_MCFG2_SRAMBANKSZ           0x00001e00      /* [12-9] */
73 #define LEON_MCFG2_SRAMBANKSZ_SHIFT     9
74 #define LEON_MCFG2_SDRAMBANKSZ          0x03800000      /* [25-23] */
75 #define LEON_MCFG2_SDRAMBANKSZ_SHIFT    23
76
77 #define LEON_TCNT0_MASK 0x7fffff
78
79 #define LEON_USTAT_ERROR (LEON_USTAT_OV | LEON_USTAT_PE | LEON_USTAT_FE)
80 /* no break yet */
81
82 #define ASI_LEON3_SYSCTRL               0x02
83 #define ASI_LEON3_SYSCTRL_ICFG          0x08
84 #define ASI_LEON3_SYSCTRL_DCFG          0x0c
85 #define ASI_LEON3_SYSCTRL_CFG_SNOOPING (1 << 27)
86 #define ASI_LEON3_SYSCTRL_CFG_SSIZE(c) (1 << ((c >> 20) & 0xf))
87
88 #ifndef __ASSEMBLY__
89
90 /* do a virtual address read without cache */
91 static inline unsigned long leon_readnobuffer_reg(unsigned long paddr)
92 {
93         unsigned long retval;
94         __asm__ __volatile__("lda [%1] %2, %0\n\t" :
95                              "=r"(retval) : "r"(paddr), "i"(ASI_LEON_NOCACHE));
96         return retval;
97 }
98
99 /* do a physical address bypass write, i.e. for 0x80000000 */
100 static inline void leon_store_reg(unsigned long paddr, unsigned long value)
101 {
102         __asm__ __volatile__("sta %0, [%1] %2\n\t" : : "r"(value), "r"(paddr),
103                              "i"(ASI_LEON_BYPASS) : "memory");
104 }
105
106 /* do a physical address bypass load, i.e. for 0x80000000 */
107 static inline unsigned long leon_load_reg(unsigned long paddr)
108 {
109         unsigned long retval;
110         __asm__ __volatile__("lda [%1] %2, %0\n\t" :
111                              "=r"(retval) : "r"(paddr), "i"(ASI_LEON_BYPASS));
112         return retval;
113 }
114
115 static inline void leon_srmmu_disabletlb(void)
116 {
117         unsigned int retval;
118         __asm__ __volatile__("lda [%%g0] %2, %0\n\t" : "=r"(retval) : "r"(0),
119                              "i"(ASI_LEON_MMUREGS));
120         retval |= LEON_CNR_CTRL_TLBDIS;
121         __asm__ __volatile__("sta %0, [%%g0] %2\n\t" : : "r"(retval), "r"(0),
122                              "i"(ASI_LEON_MMUREGS) : "memory");
123 }
124
125 static inline void leon_srmmu_enabletlb(void)
126 {
127         unsigned int retval;
128         __asm__ __volatile__("lda [%%g0] %2, %0\n\t" : "=r"(retval) : "r"(0),
129                              "i"(ASI_LEON_MMUREGS));
130         retval = retval & ~LEON_CNR_CTRL_TLBDIS;
131         __asm__ __volatile__("sta %0, [%%g0] %2\n\t" : : "r"(retval), "r"(0),
132                              "i"(ASI_LEON_MMUREGS) : "memory");
133 }
134
135 /* macro access for leon_load_reg() and leon_store_reg() */
136 #define LEON3_BYPASS_LOAD_PA(x)     (leon_load_reg((unsigned long)(x)))
137 #define LEON3_BYPASS_STORE_PA(x, v) (leon_store_reg((unsigned long)(x), (unsigned long)(v)))
138 #define LEON3_BYPASS_ANDIN_PA(x, v) LEON3_BYPASS_STORE_PA(x, LEON3_BYPASS_LOAD_PA(x) & v)
139 #define LEON3_BYPASS_ORIN_PA(x, v)  LEON3_BYPASS_STORE_PA(x, LEON3_BYPASS_LOAD_PA(x) | v)
140 #define LEON_BYPASS_LOAD_PA(x)      leon_load_reg((unsigned long)(x))
141 #define LEON_BYPASS_STORE_PA(x, v)  leon_store_reg((unsigned long)(x), (unsigned long)(v))
142 #define LEON_REGLOAD_PA(x)          leon_load_reg((unsigned long)(x)+LEON_PREGS)
143 #define LEON_REGSTORE_PA(x, v)      leon_store_reg((unsigned long)(x)+LEON_PREGS, (unsigned long)(v))
144 #define LEON_REGSTORE_OR_PA(x, v)   LEON_REGSTORE_PA(x, LEON_REGLOAD_PA(x) | (unsigned long)(v))
145 #define LEON_REGSTORE_AND_PA(x, v)  LEON_REGSTORE_PA(x, LEON_REGLOAD_PA(x) & (unsigned long)(v))
146
147 /* macro access for leon_readnobuffer_reg() */
148 #define LEON_BYPASSCACHE_LOAD_VA(x) leon_readnobuffer_reg((unsigned long)(x))
149
150 extern void leon_init(void);
151 extern void leon_switch_mm(void);
152 extern void leon_init_IRQ(void);
153
154 extern unsigned long last_valid_pfn;
155
156 static inline unsigned long sparc_leon3_get_dcachecfg(void)
157 {
158         unsigned int retval;
159         __asm__ __volatile__("lda [%1] %2, %0\n\t" :
160                              "=r"(retval) :
161                              "r"(ASI_LEON3_SYSCTRL_DCFG),
162                              "i"(ASI_LEON3_SYSCTRL));
163         return retval;
164 }
165
166 /* enable snooping */
167 static inline void sparc_leon3_enable_snooping(void)
168 {
169         __asm__ __volatile__ ("lda [%%g0] 2, %%l1\n\t"
170                           "set 0x800000, %%l2\n\t"
171                           "or  %%l2, %%l1, %%l2\n\t"
172                           "sta %%l2, [%%g0] 2\n\t" : : : "l1", "l2");
173 };
174
175 static inline int sparc_leon3_snooping_enabled(void)
176 {
177         u32 cctrl;
178         __asm__ __volatile__("lda [%%g0] 2, %0\n\t" : "=r"(cctrl));
179         return (cctrl >> 23) & 1;
180 };
181
182 static inline void sparc_leon3_disable_cache(void)
183 {
184         __asm__ __volatile__ ("lda [%%g0] 2, %%l1\n\t"
185                           "set 0x00000f, %%l2\n\t"
186                           "andn  %%l2, %%l1, %%l2\n\t"
187                           "sta %%l2, [%%g0] 2\n\t" : : : "l1", "l2");
188 };
189
190 static inline unsigned long sparc_leon3_asr17(void)
191 {
192         u32 asr17;
193         __asm__ __volatile__ ("rd %%asr17, %0\n\t" : "=r"(asr17));
194         return asr17;
195 };
196
197 static inline int sparc_leon3_cpuid(void)
198 {
199         return sparc_leon3_asr17() >> 28;
200 }
201
202 #endif /*!__ASSEMBLY__*/
203
204 #ifdef CONFIG_SMP
205 # define LEON3_IRQ_IPI_DEFAULT          13
206 # define LEON3_IRQ_TICKER               (leon3_ticker_irq)
207 # define LEON3_IRQ_CROSS_CALL           15
208 #endif
209
210 #if defined(PAGE_SIZE_LEON_8K)
211 #define LEON_PAGE_SIZE_LEON 1
212 #elif defined(PAGE_SIZE_LEON_16K)
213 #define LEON_PAGE_SIZE_LEON 2)
214 #else
215 #define LEON_PAGE_SIZE_LEON 0
216 #endif
217
218 #if LEON_PAGE_SIZE_LEON == 0
219 /* [ 8, 6, 6 ] + 12 */
220 #define LEON_PGD_SH    24
221 #define LEON_PGD_M     0xff
222 #define LEON_PMD_SH    18
223 #define LEON_PMD_SH_V  (LEON_PGD_SH-2)
224 #define LEON_PMD_M     0x3f
225 #define LEON_PTE_SH    12
226 #define LEON_PTE_M     0x3f
227 #elif LEON_PAGE_SIZE_LEON == 1
228 /* [ 7, 6, 6 ] + 13 */
229 #define LEON_PGD_SH    25
230 #define LEON_PGD_M     0x7f
231 #define LEON_PMD_SH    19
232 #define LEON_PMD_SH_V  (LEON_PGD_SH-1)
233 #define LEON_PMD_M     0x3f
234 #define LEON_PTE_SH    13
235 #define LEON_PTE_M     0x3f
236 #elif LEON_PAGE_SIZE_LEON == 2
237 /* [ 6, 6, 6 ] + 14 */
238 #define LEON_PGD_SH    26
239 #define LEON_PGD_M     0x3f
240 #define LEON_PMD_SH    20
241 #define LEON_PMD_SH_V  (LEON_PGD_SH-0)
242 #define LEON_PMD_M     0x3f
243 #define LEON_PTE_SH    14
244 #define LEON_PTE_M     0x3f
245 #elif LEON_PAGE_SIZE_LEON == 3
246 /* [ 4, 7, 6 ] + 15 */
247 #define LEON_PGD_SH    28
248 #define LEON_PGD_M     0x0f
249 #define LEON_PMD_SH    21
250 #define LEON_PMD_SH_V  (LEON_PGD_SH-0)
251 #define LEON_PMD_M     0x7f
252 #define LEON_PTE_SH    15
253 #define LEON_PTE_M     0x3f
254 #else
255 #error cannot determine LEON_PAGE_SIZE_LEON
256 #endif
257
258 #define PAGE_MIN_SHIFT   (12)
259 #define PAGE_MIN_SIZE    (1UL << PAGE_MIN_SHIFT)
260
261 #define LEON3_XCCR_SETS_MASK  0x07000000UL
262 #define LEON3_XCCR_SSIZE_MASK 0x00f00000UL
263
264 #define LEON2_CCR_DSETS_MASK 0x03000000UL
265 #define LEON2_CFG_SSIZE_MASK 0x00007000UL
266
267 #ifndef __ASSEMBLY__
268 extern unsigned long srmmu_swprobe(unsigned long vaddr, unsigned long *paddr);
269 extern void leon_flush_icache_all(void);
270 extern void leon_flush_dcache_all(void);
271 extern void leon_flush_cache_all(void);
272 extern void leon_flush_tlb_all(void);
273 extern int leon_flush_during_switch;
274 extern int leon_flush_needed(void);
275
276 struct vm_area_struct;
277 extern void leon_flush_icache_all(void);
278 extern void leon_flush_dcache_all(void);
279 extern void leon_flush_pcache_all(struct vm_area_struct *vma, unsigned long page);
280 extern void leon_flush_cache_all(void);
281 extern void leon_flush_tlb_all(void);
282 extern int leon_flush_during_switch;
283 extern int leon_flush_needed(void);
284 extern void leon_flush_pcache_all(struct vm_area_struct *vma, unsigned long page);
285
286 /* struct that hold LEON3 cache configuration registers */
287 struct leon3_cacheregs {
288         unsigned long ccr;      /* 0x00 - Cache Control Register  */
289         unsigned long iccr;     /* 0x08 - Instruction Cache Configuration Register */
290         unsigned long dccr;     /* 0x0c - Data Cache Configuration Register */
291 };
292
293 /* struct that hold LEON2 cache configuration register
294  * & configuration register
295  */
296 struct leon2_cacheregs {
297         unsigned long ccr, cfg;
298 };
299
300 #ifdef __KERNEL__
301
302 #include <linux/interrupt.h>
303
304 struct device_node;
305 extern unsigned int leon_build_device_irq(unsigned int real_irq,
306                                            irq_flow_handler_t flow_handler,
307                                            const char *name, int do_ack);
308 extern void leon_update_virq_handling(unsigned int virq,
309                               irq_flow_handler_t flow_handler,
310                               const char *name, int do_ack);
311 extern void leon_init_timers(void);
312 extern void leon_trans_init(struct device_node *dp);
313 extern void leon_node_init(struct device_node *dp, struct device_node ***nextp);
314 extern void leon_init_IRQ(void);
315 extern void leon_init(void);
316 extern unsigned long srmmu_swprobe(unsigned long vaddr, unsigned long *paddr);
317 extern void init_leon(void);
318 extern void poke_leonsparc(void);
319 extern void leon3_getCacheRegs(struct leon3_cacheregs *regs);
320 extern int leon_flush_needed(void);
321 extern void leon_switch_mm(void);
322 extern int srmmu_swprobe_trace;
323 extern int leon3_ticker_irq;
324
325 #ifdef CONFIG_SMP
326 extern int leon_smp_nrcpus(void);
327 extern void leon_clear_profile_irq(int cpu);
328 extern void leon_smp_done(void);
329 extern void leon_boot_cpus(void);
330 extern int leon_boot_one_cpu(int i);
331 void leon_init_smp(void);
332 extern void cpu_idle(void);
333 extern void init_IRQ(void);
334 extern void cpu_panic(void);
335 extern int __leon_processor_id(void);
336 void leon_enable_irq_cpu(unsigned int irq_nr, unsigned int cpu);
337 extern irqreturn_t leon_percpu_timer_interrupt(int irq, void *unused);
338
339 extern unsigned int real_irq_entry[];
340 extern unsigned int smpleon_ipi[];
341 extern unsigned int patchme_maybe_smp_msg[];
342 extern unsigned int t_nmi[], linux_trap_ipi15_leon[];
343 extern unsigned int linux_trap_ipi15_sun4m[];
344 extern int leon_ipi_irq;
345
346 #endif /* CONFIG_SMP */
347
348 #endif /* __KERNEL__ */
349
350 #endif /* __ASSEMBLY__ */
351
352 /* macros used in leon_mm.c */
353 #define PFN(x)           ((x) >> PAGE_SHIFT)
354 #define _pfn_valid(pfn)  ((pfn < last_valid_pfn) && (pfn >= PFN(phys_base)))
355 #define _SRMMU_PTE_PMASK_LEON 0xffffffff
356
357 #else /* defined(CONFIG_SPARC_LEON) */
358
359 /* nop definitions for !LEON case */
360 #define leon_init() do {} while (0)
361 #define leon_switch_mm() do {} while (0)
362 #define leon_init_IRQ() do {} while (0)
363 #define init_leon() do {} while (0)
364 #define leon_smp_done() do {} while (0)
365 #define leon_boot_cpus() do {} while (0)
366 #define leon_boot_one_cpu(i) 1
367 #define leon_init_smp() do {} while (0)
368
369 #endif /* !defined(CONFIG_SPARC_LEON) */
370
371 #endif