leon.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  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. extern 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. extern 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. extern 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. extern 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. extern inline void sparc_leon3_disable_cache(void)
  180. {
  181. __asm__ __volatile__ ("lda [%%g0] 2, %%l1\n\t"
  182. "set 0x00000f, %%l2\n\t"
  183. "andn %%l2, %%l1, %%l2\n\t"
  184. "sta %%l2, [%%g0] 2\n\t" : : : "l1", "l2");
  185. };
  186. #endif /*!__ASSEMBLY__*/
  187. #ifdef CONFIG_SMP
  188. # define LEON3_IRQ_RESCHEDULE 13
  189. # define LEON3_IRQ_TICKER (leon_percpu_timer_dev[0].irq)
  190. # define LEON3_IRQ_CROSS_CALL 15
  191. #endif
  192. #if defined(PAGE_SIZE_LEON_8K)
  193. #define LEON_PAGE_SIZE_LEON 1
  194. #elif defined(PAGE_SIZE_LEON_16K)
  195. #define LEON_PAGE_SIZE_LEON 2)
  196. #else
  197. #define LEON_PAGE_SIZE_LEON 0
  198. #endif
  199. #if LEON_PAGE_SIZE_LEON == 0
  200. /* [ 8, 6, 6 ] + 12 */
  201. #define LEON_PGD_SH 24
  202. #define LEON_PGD_M 0xff
  203. #define LEON_PMD_SH 18
  204. #define LEON_PMD_SH_V (LEON_PGD_SH-2)
  205. #define LEON_PMD_M 0x3f
  206. #define LEON_PTE_SH 12
  207. #define LEON_PTE_M 0x3f
  208. #elif LEON_PAGE_SIZE_LEON == 1
  209. /* [ 7, 6, 6 ] + 13 */
  210. #define LEON_PGD_SH 25
  211. #define LEON_PGD_M 0x7f
  212. #define LEON_PMD_SH 19
  213. #define LEON_PMD_SH_V (LEON_PGD_SH-1)
  214. #define LEON_PMD_M 0x3f
  215. #define LEON_PTE_SH 13
  216. #define LEON_PTE_M 0x3f
  217. #elif LEON_PAGE_SIZE_LEON == 2
  218. /* [ 6, 6, 6 ] + 14 */
  219. #define LEON_PGD_SH 26
  220. #define LEON_PGD_M 0x3f
  221. #define LEON_PMD_SH 20
  222. #define LEON_PMD_SH_V (LEON_PGD_SH-0)
  223. #define LEON_PMD_M 0x3f
  224. #define LEON_PTE_SH 14
  225. #define LEON_PTE_M 0x3f
  226. #elif LEON_PAGE_SIZE_LEON == 3
  227. /* [ 4, 7, 6 ] + 15 */
  228. #define LEON_PGD_SH 28
  229. #define LEON_PGD_M 0x0f
  230. #define LEON_PMD_SH 21
  231. #define LEON_PMD_SH_V (LEON_PGD_SH-0)
  232. #define LEON_PMD_M 0x7f
  233. #define LEON_PTE_SH 15
  234. #define LEON_PTE_M 0x3f
  235. #else
  236. #error cannot determine LEON_PAGE_SIZE_LEON
  237. #endif
  238. #define PAGE_MIN_SHIFT (12)
  239. #define PAGE_MIN_SIZE (1UL << PAGE_MIN_SHIFT)
  240. #define LEON3_XCCR_SETS_MASK 0x07000000UL
  241. #define LEON3_XCCR_SSIZE_MASK 0x00f00000UL
  242. #define LEON2_CCR_DSETS_MASK 0x03000000UL
  243. #define LEON2_CFG_SSIZE_MASK 0x00007000UL
  244. #ifndef __ASSEMBLY__
  245. extern unsigned long srmmu_swprobe(unsigned long vaddr, unsigned long *paddr);
  246. extern void leon_flush_icache_all(void);
  247. extern void leon_flush_dcache_all(void);
  248. extern void leon_flush_cache_all(void);
  249. extern void leon_flush_tlb_all(void);
  250. extern int leon_flush_during_switch;
  251. extern int leon_flush_needed(void);
  252. struct vm_area_struct;
  253. extern void leon_flush_icache_all(void);
  254. extern void leon_flush_dcache_all(void);
  255. extern void leon_flush_pcache_all(struct vm_area_struct *vma, unsigned long page);
  256. extern void leon_flush_cache_all(void);
  257. extern void leon_flush_tlb_all(void);
  258. extern int leon_flush_during_switch;
  259. extern int leon_flush_needed(void);
  260. extern void leon_flush_pcache_all(struct vm_area_struct *vma, unsigned long page);
  261. /* struct that hold LEON3 cache configuration registers */
  262. struct leon3_cacheregs {
  263. unsigned long ccr; /* 0x00 - Cache Control Register */
  264. unsigned long iccr; /* 0x08 - Instruction Cache Configuration Register */
  265. unsigned long dccr; /* 0x0c - Data Cache Configuration Register */
  266. };
  267. /* struct that hold LEON2 cache configuration register
  268. * & configuration register
  269. */
  270. struct leon2_cacheregs {
  271. unsigned long ccr, cfg;
  272. };
  273. #ifdef __KERNEL__
  274. #include <linux/interrupt.h>
  275. struct device_node;
  276. extern int sparc_leon_eirq_get(int eirq, int cpu);
  277. extern irqreturn_t sparc_leon_eirq_isr(int dummy, void *dev_id);
  278. extern void sparc_leon_eirq_register(int eirq);
  279. extern void leon_clear_clock_irq(void);
  280. extern void leon_load_profile_irq(int cpu, unsigned int limit);
  281. extern void leon_init_timers(irq_handler_t counter_fn);
  282. extern void leon_clear_clock_irq(void);
  283. extern void leon_load_profile_irq(int cpu, unsigned int limit);
  284. extern void leon_trans_init(struct device_node *dp);
  285. extern void leon_node_init(struct device_node *dp, struct device_node ***nextp);
  286. extern void leon_init_IRQ(void);
  287. extern void leon_init(void);
  288. extern unsigned long srmmu_swprobe(unsigned long vaddr, unsigned long *paddr);
  289. extern void init_leon(void);
  290. extern void poke_leonsparc(void);
  291. extern void leon3_getCacheRegs(struct leon3_cacheregs *regs);
  292. extern int leon_flush_needed(void);
  293. extern void leon_switch_mm(void);
  294. extern int srmmu_swprobe_trace;
  295. #endif /* __KERNEL__ */
  296. #endif /* __ASSEMBLY__ */
  297. /* macros used in leon_mm.c */
  298. #define PFN(x) ((x) >> PAGE_SHIFT)
  299. #define _pfn_valid(pfn) ((pfn < last_valid_pfn) && (pfn >= PFN(phys_base)))
  300. #define _SRMMU_PTE_PMASK_LEON 0xffffffff
  301. #else /* defined(CONFIG_SPARC_LEON) */
  302. /* nop definitions for !LEON case */
  303. #define leon_init() do {} while (0)
  304. #define leon_switch_mm() do {} while (0)
  305. #define leon_init_IRQ() do {} while (0)
  306. #define init_leon() do {} while (0)
  307. #endif /* !defined(CONFIG_SPARC_LEON) */
  308. #endif