leon.h 7.3 KB

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