leon.h 12 KB

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