spitfire.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. /* $Id: spitfire.h,v 1.18 2001/11/29 16:42:10 kanoj Exp $
  2. * spitfire.h: SpitFire/BlackBird/Cheetah inline MMU operations.
  3. *
  4. * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
  5. */
  6. #ifndef _SPARC64_SPITFIRE_H
  7. #define _SPARC64_SPITFIRE_H
  8. #include <asm/asi.h>
  9. /* The following register addresses are accessible via ASI_DMMU
  10. * and ASI_IMMU, that is there is a distinct and unique copy of
  11. * each these registers for each TLB.
  12. */
  13. #define TSB_TAG_TARGET 0x0000000000000000 /* All chips */
  14. #define TLB_SFSR 0x0000000000000018 /* All chips */
  15. #define TSB_REG 0x0000000000000028 /* All chips */
  16. #define TLB_TAG_ACCESS 0x0000000000000030 /* All chips */
  17. #define VIRT_WATCHPOINT 0x0000000000000038 /* All chips */
  18. #define PHYS_WATCHPOINT 0x0000000000000040 /* All chips */
  19. #define TSB_EXTENSION_P 0x0000000000000048 /* Ultra-III and later */
  20. #define TSB_EXTENSION_S 0x0000000000000050 /* Ultra-III and later, D-TLB only */
  21. #define TSB_EXTENSION_N 0x0000000000000058 /* Ultra-III and later */
  22. #define TLB_TAG_ACCESS_EXT 0x0000000000000060 /* Ultra-III+ and later */
  23. /* These registers only exist as one entity, and are accessed
  24. * via ASI_DMMU only.
  25. */
  26. #define PRIMARY_CONTEXT 0x0000000000000008
  27. #define SECONDARY_CONTEXT 0x0000000000000010
  28. #define DMMU_SFAR 0x0000000000000020
  29. #define VIRT_WATCHPOINT 0x0000000000000038
  30. #define PHYS_WATCHPOINT 0x0000000000000040
  31. #define SPITFIRE_HIGHEST_LOCKED_TLBENT (64 - 1)
  32. #define CHEETAH_HIGHEST_LOCKED_TLBENT (16 - 1)
  33. #define L1DCACHE_SIZE 0x4000
  34. #ifndef __ASSEMBLY__
  35. enum ultra_tlb_layout {
  36. spitfire = 0,
  37. cheetah = 1,
  38. cheetah_plus = 2,
  39. };
  40. extern enum ultra_tlb_layout tlb_type;
  41. extern int cheetah_pcache_forced_on;
  42. extern void cheetah_enable_pcache(void);
  43. #define sparc64_highest_locked_tlbent() \
  44. (tlb_type == spitfire ? \
  45. SPITFIRE_HIGHEST_LOCKED_TLBENT : \
  46. CHEETAH_HIGHEST_LOCKED_TLBENT)
  47. /* The data cache is write through, so this just invalidates the
  48. * specified line.
  49. */
  50. static __inline__ void spitfire_put_dcache_tag(unsigned long addr, unsigned long tag)
  51. {
  52. __asm__ __volatile__("stxa %0, [%1] %2\n\t"
  53. "membar #Sync"
  54. : /* No outputs */
  55. : "r" (tag), "r" (addr), "i" (ASI_DCACHE_TAG));
  56. }
  57. /* The instruction cache lines are flushed with this, but note that
  58. * this does not flush the pipeline. It is possible for a line to
  59. * get flushed but stale instructions to still be in the pipeline,
  60. * a flush instruction (to any address) is sufficient to handle
  61. * this issue after the line is invalidated.
  62. */
  63. static __inline__ void spitfire_put_icache_tag(unsigned long addr, unsigned long tag)
  64. {
  65. __asm__ __volatile__("stxa %0, [%1] %2\n\t"
  66. "membar #Sync"
  67. : /* No outputs */
  68. : "r" (tag), "r" (addr), "i" (ASI_IC_TAG));
  69. }
  70. static __inline__ unsigned long spitfire_get_dtlb_data(int entry)
  71. {
  72. unsigned long data;
  73. __asm__ __volatile__("ldxa [%1] %2, %0"
  74. : "=r" (data)
  75. : "r" (entry << 3), "i" (ASI_DTLB_DATA_ACCESS));
  76. /* Clear TTE diag bits. */
  77. data &= ~0x0003fe0000000000UL;
  78. return data;
  79. }
  80. static __inline__ unsigned long spitfire_get_dtlb_tag(int entry)
  81. {
  82. unsigned long tag;
  83. __asm__ __volatile__("ldxa [%1] %2, %0"
  84. : "=r" (tag)
  85. : "r" (entry << 3), "i" (ASI_DTLB_TAG_READ));
  86. return tag;
  87. }
  88. static __inline__ void spitfire_put_dtlb_data(int entry, unsigned long data)
  89. {
  90. __asm__ __volatile__("stxa %0, [%1] %2\n\t"
  91. "membar #Sync"
  92. : /* No outputs */
  93. : "r" (data), "r" (entry << 3),
  94. "i" (ASI_DTLB_DATA_ACCESS));
  95. }
  96. static __inline__ unsigned long spitfire_get_itlb_data(int entry)
  97. {
  98. unsigned long data;
  99. __asm__ __volatile__("ldxa [%1] %2, %0"
  100. : "=r" (data)
  101. : "r" (entry << 3), "i" (ASI_ITLB_DATA_ACCESS));
  102. /* Clear TTE diag bits. */
  103. data &= ~0x0003fe0000000000UL;
  104. return data;
  105. }
  106. static __inline__ unsigned long spitfire_get_itlb_tag(int entry)
  107. {
  108. unsigned long tag;
  109. __asm__ __volatile__("ldxa [%1] %2, %0"
  110. : "=r" (tag)
  111. : "r" (entry << 3), "i" (ASI_ITLB_TAG_READ));
  112. return tag;
  113. }
  114. static __inline__ void spitfire_put_itlb_data(int entry, unsigned long data)
  115. {
  116. __asm__ __volatile__("stxa %0, [%1] %2\n\t"
  117. "membar #Sync"
  118. : /* No outputs */
  119. : "r" (data), "r" (entry << 3),
  120. "i" (ASI_ITLB_DATA_ACCESS));
  121. }
  122. static __inline__ void spitfire_flush_dtlb_nucleus_page(unsigned long page)
  123. {
  124. __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
  125. "membar #Sync"
  126. : /* No outputs */
  127. : "r" (page | 0x20), "i" (ASI_DMMU_DEMAP));
  128. }
  129. static __inline__ void spitfire_flush_itlb_nucleus_page(unsigned long page)
  130. {
  131. __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
  132. "membar #Sync"
  133. : /* No outputs */
  134. : "r" (page | 0x20), "i" (ASI_IMMU_DEMAP));
  135. }
  136. /* Cheetah has "all non-locked" tlb flushes. */
  137. static __inline__ void cheetah_flush_dtlb_all(void)
  138. {
  139. __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
  140. "membar #Sync"
  141. : /* No outputs */
  142. : "r" (0x80), "i" (ASI_DMMU_DEMAP));
  143. }
  144. static __inline__ void cheetah_flush_itlb_all(void)
  145. {
  146. __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
  147. "membar #Sync"
  148. : /* No outputs */
  149. : "r" (0x80), "i" (ASI_IMMU_DEMAP));
  150. }
  151. /* Cheetah has a 4-tlb layout so direct access is a bit different.
  152. * The first two TLBs are fully assosciative, hold 16 entries, and are
  153. * used only for locked and >8K sized translations. One exists for
  154. * data accesses and one for instruction accesses.
  155. *
  156. * The third TLB is for data accesses to 8K non-locked translations, is
  157. * 2 way assosciative, and holds 512 entries. The fourth TLB is for
  158. * instruction accesses to 8K non-locked translations, is 2 way
  159. * assosciative, and holds 128 entries.
  160. *
  161. * Cheetah has some bug where bogus data can be returned from
  162. * ASI_{D,I}TLB_DATA_ACCESS loads, doing the load twice fixes
  163. * the problem for me. -DaveM
  164. */
  165. static __inline__ unsigned long cheetah_get_ldtlb_data(int entry)
  166. {
  167. unsigned long data;
  168. __asm__ __volatile__("ldxa [%1] %2, %%g0\n\t"
  169. "ldxa [%1] %2, %0"
  170. : "=r" (data)
  171. : "r" ((0 << 16) | (entry << 3)),
  172. "i" (ASI_DTLB_DATA_ACCESS));
  173. return data;
  174. }
  175. static __inline__ unsigned long cheetah_get_litlb_data(int entry)
  176. {
  177. unsigned long data;
  178. __asm__ __volatile__("ldxa [%1] %2, %%g0\n\t"
  179. "ldxa [%1] %2, %0"
  180. : "=r" (data)
  181. : "r" ((0 << 16) | (entry << 3)),
  182. "i" (ASI_ITLB_DATA_ACCESS));
  183. return data;
  184. }
  185. static __inline__ unsigned long cheetah_get_ldtlb_tag(int entry)
  186. {
  187. unsigned long tag;
  188. __asm__ __volatile__("ldxa [%1] %2, %0"
  189. : "=r" (tag)
  190. : "r" ((0 << 16) | (entry << 3)),
  191. "i" (ASI_DTLB_TAG_READ));
  192. return tag;
  193. }
  194. static __inline__ unsigned long cheetah_get_litlb_tag(int entry)
  195. {
  196. unsigned long tag;
  197. __asm__ __volatile__("ldxa [%1] %2, %0"
  198. : "=r" (tag)
  199. : "r" ((0 << 16) | (entry << 3)),
  200. "i" (ASI_ITLB_TAG_READ));
  201. return tag;
  202. }
  203. static __inline__ void cheetah_put_ldtlb_data(int entry, unsigned long data)
  204. {
  205. __asm__ __volatile__("stxa %0, [%1] %2\n\t"
  206. "membar #Sync"
  207. : /* No outputs */
  208. : "r" (data),
  209. "r" ((0 << 16) | (entry << 3)),
  210. "i" (ASI_DTLB_DATA_ACCESS));
  211. }
  212. static __inline__ void cheetah_put_litlb_data(int entry, unsigned long data)
  213. {
  214. __asm__ __volatile__("stxa %0, [%1] %2\n\t"
  215. "membar #Sync"
  216. : /* No outputs */
  217. : "r" (data),
  218. "r" ((0 << 16) | (entry << 3)),
  219. "i" (ASI_ITLB_DATA_ACCESS));
  220. }
  221. static __inline__ unsigned long cheetah_get_dtlb_data(int entry, int tlb)
  222. {
  223. unsigned long data;
  224. __asm__ __volatile__("ldxa [%1] %2, %%g0\n\t"
  225. "ldxa [%1] %2, %0"
  226. : "=r" (data)
  227. : "r" ((tlb << 16) | (entry << 3)), "i" (ASI_DTLB_DATA_ACCESS));
  228. return data;
  229. }
  230. static __inline__ unsigned long cheetah_get_dtlb_tag(int entry, int tlb)
  231. {
  232. unsigned long tag;
  233. __asm__ __volatile__("ldxa [%1] %2, %0"
  234. : "=r" (tag)
  235. : "r" ((tlb << 16) | (entry << 3)), "i" (ASI_DTLB_TAG_READ));
  236. return tag;
  237. }
  238. static __inline__ void cheetah_put_dtlb_data(int entry, unsigned long data, int tlb)
  239. {
  240. __asm__ __volatile__("stxa %0, [%1] %2\n\t"
  241. "membar #Sync"
  242. : /* No outputs */
  243. : "r" (data),
  244. "r" ((tlb << 16) | (entry << 3)),
  245. "i" (ASI_DTLB_DATA_ACCESS));
  246. }
  247. static __inline__ unsigned long cheetah_get_itlb_data(int entry)
  248. {
  249. unsigned long data;
  250. __asm__ __volatile__("ldxa [%1] %2, %%g0\n\t"
  251. "ldxa [%1] %2, %0"
  252. : "=r" (data)
  253. : "r" ((2 << 16) | (entry << 3)),
  254. "i" (ASI_ITLB_DATA_ACCESS));
  255. return data;
  256. }
  257. static __inline__ unsigned long cheetah_get_itlb_tag(int entry)
  258. {
  259. unsigned long tag;
  260. __asm__ __volatile__("ldxa [%1] %2, %0"
  261. : "=r" (tag)
  262. : "r" ((2 << 16) | (entry << 3)), "i" (ASI_ITLB_TAG_READ));
  263. return tag;
  264. }
  265. static __inline__ void cheetah_put_itlb_data(int entry, unsigned long data)
  266. {
  267. __asm__ __volatile__("stxa %0, [%1] %2\n\t"
  268. "membar #Sync"
  269. : /* No outputs */
  270. : "r" (data), "r" ((2 << 16) | (entry << 3)),
  271. "i" (ASI_ITLB_DATA_ACCESS));
  272. }
  273. #endif /* !(__ASSEMBLY__) */
  274. #endif /* !(_SPARC64_SPITFIRE_H) */