leon.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 2004 Konrad Eisele ([email protected],[email protected]) Gaisler Research
  4. * Copyright (C) 2004 Stefan Holst ([email protected]) Uni-Stuttgart
  5. * Copyright (C) 2009 Daniel Hellstrom ([email protected]) Aeroflex Gaisler AB
  6. * Copyright (C) 2009 Konrad Eisele ([email protected]) Aeroflex Gaisler AB
  7. */
  8. #ifndef LEON_H_INCLUDE
  9. #define LEON_H_INCLUDE
  10. /* mmu register access, ASI_LEON_MMUREGS */
  11. #define LEON_CNR_CTRL 0x000
  12. #define LEON_CNR_CTXP 0x100
  13. #define LEON_CNR_CTX 0x200
  14. #define LEON_CNR_F 0x300
  15. #define LEON_CNR_FADDR 0x400
  16. #define LEON_CNR_CTX_NCTX 256 /*number of MMU ctx */
  17. #define LEON_CNR_CTRL_TLBDIS 0x80000000
  18. #define LEON_MMUTLB_ENT_MAX 64
  19. /*
  20. * diagnostic access from mmutlb.vhd:
  21. * 0: pte address
  22. * 4: pte
  23. * 8: additional flags
  24. */
  25. #define LEON_DIAGF_LVL 0x3
  26. #define LEON_DIAGF_WR 0x8
  27. #define LEON_DIAGF_WR_SHIFT 3
  28. #define LEON_DIAGF_HIT 0x10
  29. #define LEON_DIAGF_HIT_SHIFT 4
  30. #define LEON_DIAGF_CTX 0x1fe0
  31. #define LEON_DIAGF_CTX_SHIFT 5
  32. #define LEON_DIAGF_VALID 0x2000
  33. #define LEON_DIAGF_VALID_SHIFT 13
  34. /* irq masks */
  35. #define LEON_HARD_INT(x) (1 << (x)) /* irq 0-15 */
  36. #define LEON_IRQMASK_R 0x0000fffe /* bit 15- 1 of lregs.irqmask */
  37. #define LEON_IRQPRIO_R 0xfffe0000 /* bit 31-17 of lregs.irqmask */
  38. #define LEON_MCFG2_SRAMDIS 0x00002000
  39. #define LEON_MCFG2_SDRAMEN 0x00004000
  40. #define LEON_MCFG2_SRAMBANKSZ 0x00001e00 /* [12-9] */
  41. #define LEON_MCFG2_SRAMBANKSZ_SHIFT 9
  42. #define LEON_MCFG2_SDRAMBANKSZ 0x03800000 /* [25-23] */
  43. #define LEON_MCFG2_SDRAMBANKSZ_SHIFT 23
  44. #define LEON_TCNT0_MASK 0x7fffff
  45. #define ASI_LEON3_SYSCTRL 0x02
  46. #define ASI_LEON3_SYSCTRL_ICFG 0x08
  47. #define ASI_LEON3_SYSCTRL_DCFG 0x0c
  48. #define ASI_LEON3_SYSCTRL_CFG_SNOOPING (1 << 27)
  49. #define ASI_LEON3_SYSCTRL_CFG_SSIZE(c) (1 << ((c >> 20) & 0xf))
  50. #ifndef __ASSEMBLY__
  51. /* do a physical address bypass write, i.e. for 0x80000000 */
  52. static inline void leon_store_reg(unsigned long paddr, unsigned long value)
  53. {
  54. __asm__ __volatile__("sta %0, [%1] %2\n\t" : : "r"(value), "r"(paddr),
  55. "i"(ASI_LEON_BYPASS) : "memory");
  56. }
  57. /* do a physical address bypass load, i.e. for 0x80000000 */
  58. static inline unsigned long leon_load_reg(unsigned long paddr)
  59. {
  60. unsigned long retval;
  61. __asm__ __volatile__("lda [%1] %2, %0\n\t" :
  62. "=r"(retval) : "r"(paddr), "i"(ASI_LEON_BYPASS));
  63. return retval;
  64. }
  65. /* macro access for leon_load_reg() and leon_store_reg() */
  66. #define LEON3_BYPASS_LOAD_PA(x) (leon_load_reg((unsigned long)(x)))
  67. #define LEON3_BYPASS_STORE_PA(x, v) (leon_store_reg((unsigned long)(x), (unsigned long)(v)))
  68. #define LEON_BYPASS_LOAD_PA(x) leon_load_reg((unsigned long)(x))
  69. #define LEON_BYPASS_STORE_PA(x, v) leon_store_reg((unsigned long)(x), (unsigned long)(v))
  70. void leon_switch_mm(void);
  71. void leon_init_IRQ(void);
  72. static inline unsigned long sparc_leon3_get_dcachecfg(void)
  73. {
  74. unsigned int retval;
  75. __asm__ __volatile__("lda [%1] %2, %0\n\t" :
  76. "=r"(retval) :
  77. "r"(ASI_LEON3_SYSCTRL_DCFG),
  78. "i"(ASI_LEON3_SYSCTRL));
  79. return retval;
  80. }
  81. /* enable snooping */
  82. static inline void sparc_leon3_enable_snooping(void)
  83. {
  84. __asm__ __volatile__ ("lda [%%g0] 2, %%l1\n\t"
  85. "set 0x800000, %%l2\n\t"
  86. "or %%l2, %%l1, %%l2\n\t"
  87. "sta %%l2, [%%g0] 2\n\t" : : : "l1", "l2");
  88. };
  89. static inline int sparc_leon3_snooping_enabled(void)
  90. {
  91. u32 cctrl;
  92. __asm__ __volatile__("lda [%%g0] 2, %0\n\t" : "=r"(cctrl));
  93. return ((cctrl >> 23) & 1) && ((cctrl >> 17) & 1);
  94. };
  95. static inline void sparc_leon3_disable_cache(void)
  96. {
  97. __asm__ __volatile__ ("lda [%%g0] 2, %%l1\n\t"
  98. "set 0x00000f, %%l2\n\t"
  99. "andn %%l2, %%l1, %%l2\n\t"
  100. "sta %%l2, [%%g0] 2\n\t" : : : "l1", "l2");
  101. };
  102. static inline unsigned long sparc_leon3_asr17(void)
  103. {
  104. u32 asr17;
  105. __asm__ __volatile__ ("rd %%asr17, %0\n\t" : "=r"(asr17));
  106. return asr17;
  107. };
  108. static inline int sparc_leon3_cpuid(void)
  109. {
  110. return sparc_leon3_asr17() >> 28;
  111. }
  112. #endif /*!__ASSEMBLY__*/
  113. #ifdef CONFIG_SMP
  114. # define LEON3_IRQ_IPI_DEFAULT 13
  115. # define LEON3_IRQ_TICKER (leon3_gptimer_irq)
  116. # define LEON3_IRQ_CROSS_CALL 15
  117. #endif
  118. #if defined(PAGE_SIZE_LEON_8K)
  119. #define LEON_PAGE_SIZE_LEON 1
  120. #elif defined(PAGE_SIZE_LEON_16K)
  121. #define LEON_PAGE_SIZE_LEON 2)
  122. #else
  123. #define LEON_PAGE_SIZE_LEON 0
  124. #endif
  125. #if LEON_PAGE_SIZE_LEON == 0
  126. /* [ 8, 6, 6 ] + 12 */
  127. #define LEON_PGD_SH 24
  128. #define LEON_PGD_M 0xff
  129. #define LEON_PMD_SH 18
  130. #define LEON_PMD_SH_V (LEON_PGD_SH-2)
  131. #define LEON_PMD_M 0x3f
  132. #define LEON_PTE_SH 12
  133. #define LEON_PTE_M 0x3f
  134. #elif LEON_PAGE_SIZE_LEON == 1
  135. /* [ 7, 6, 6 ] + 13 */
  136. #define LEON_PGD_SH 25
  137. #define LEON_PGD_M 0x7f
  138. #define LEON_PMD_SH 19
  139. #define LEON_PMD_SH_V (LEON_PGD_SH-1)
  140. #define LEON_PMD_M 0x3f
  141. #define LEON_PTE_SH 13
  142. #define LEON_PTE_M 0x3f
  143. #elif LEON_PAGE_SIZE_LEON == 2
  144. /* [ 6, 6, 6 ] + 14 */
  145. #define LEON_PGD_SH 26
  146. #define LEON_PGD_M 0x3f
  147. #define LEON_PMD_SH 20
  148. #define LEON_PMD_SH_V (LEON_PGD_SH-0)
  149. #define LEON_PMD_M 0x3f
  150. #define LEON_PTE_SH 14
  151. #define LEON_PTE_M 0x3f
  152. #elif LEON_PAGE_SIZE_LEON == 3
  153. /* [ 4, 7, 6 ] + 15 */
  154. #define LEON_PGD_SH 28
  155. #define LEON_PGD_M 0x0f
  156. #define LEON_PMD_SH 21
  157. #define LEON_PMD_SH_V (LEON_PGD_SH-0)
  158. #define LEON_PMD_M 0x7f
  159. #define LEON_PTE_SH 15
  160. #define LEON_PTE_M 0x3f
  161. #else
  162. #error cannot determine LEON_PAGE_SIZE_LEON
  163. #endif
  164. #define LEON3_XCCR_SETS_MASK 0x07000000UL
  165. #define LEON3_XCCR_SSIZE_MASK 0x00f00000UL
  166. #define LEON2_CCR_DSETS_MASK 0x03000000UL
  167. #define LEON2_CFG_SSIZE_MASK 0x00007000UL
  168. #ifndef __ASSEMBLY__
  169. struct vm_area_struct;
  170. unsigned long leon_swprobe(unsigned long vaddr, unsigned long *paddr);
  171. void leon_flush_icache_all(void);
  172. void leon_flush_dcache_all(void);
  173. void leon_flush_cache_all(void);
  174. void leon_flush_tlb_all(void);
  175. extern int leon_flush_during_switch;
  176. int leon_flush_needed(void);
  177. void leon_flush_pcache_all(struct vm_area_struct *vma, unsigned long page);
  178. /* struct that hold LEON3 cache configuration registers */
  179. struct leon3_cacheregs {
  180. unsigned long ccr; /* 0x00 - Cache Control Register */
  181. unsigned long iccr; /* 0x08 - Instruction Cache Configuration Register */
  182. unsigned long dccr; /* 0x0c - Data Cache Configuration Register */
  183. };
  184. #include <linux/irq.h>
  185. #include <linux/interrupt.h>
  186. struct device_node;
  187. struct task_struct;
  188. unsigned int leon_build_device_irq(unsigned int real_irq,
  189. irq_flow_handler_t flow_handler,
  190. const char *name, int do_ack);
  191. void leon_update_virq_handling(unsigned int virq,
  192. irq_flow_handler_t flow_handler,
  193. const char *name, int do_ack);
  194. void leon_init_timers(void);
  195. void leon_node_init(struct device_node *dp, struct device_node ***nextp);
  196. void init_leon(void);
  197. void poke_leonsparc(void);
  198. void leon3_getCacheRegs(struct leon3_cacheregs *regs);
  199. extern int leon3_ticker_irq;
  200. #ifdef CONFIG_SMP
  201. int leon_smp_nrcpus(void);
  202. void leon_clear_profile_irq(int cpu);
  203. void leon_smp_done(void);
  204. void leon_boot_cpus(void);
  205. int leon_boot_one_cpu(int i, struct task_struct *);
  206. void leon_init_smp(void);
  207. void leon_enable_irq_cpu(unsigned int irq_nr, unsigned int cpu);
  208. irqreturn_t leon_percpu_timer_interrupt(int irq, void *unused);
  209. extern unsigned int smpleon_ipi[];
  210. extern unsigned int linux_trap_ipi15_leon[];
  211. extern int leon_ipi_irq;
  212. #endif /* CONFIG_SMP */
  213. #endif /* __ASSEMBLY__ */
  214. /* macros used in leon_mm.c */
  215. #define PFN(x) ((x) >> PAGE_SHIFT)
  216. #define _pfn_valid(pfn) ((pfn < last_valid_pfn) && (pfn >= PFN(phys_base)))
  217. #define _SRMMU_PTE_PMASK_LEON 0xffffffff
  218. /*
  219. * On LEON PCI Memory space is mapped 1:1 with physical address space.
  220. *
  221. * I/O space is located at low 64Kbytes in PCI I/O space. The I/O addresses
  222. * are converted into CPU addresses to virtual addresses that are mapped with
  223. * MMU to the PCI Host PCI I/O space window which are translated to the low
  224. * 64Kbytes by the Host controller.
  225. */
  226. #endif