spitfire.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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. hypervisor = 3,
  40. };
  41. extern enum ultra_tlb_layout tlb_type;
  42. extern int cheetah_pcache_forced_on;
  43. extern void cheetah_enable_pcache(void);
  44. #define sparc64_highest_locked_tlbent() \
  45. (tlb_type == spitfire ? \
  46. SPITFIRE_HIGHEST_LOCKED_TLBENT : \
  47. CHEETAH_HIGHEST_LOCKED_TLBENT)
  48. /* The data cache is write through, so this just invalidates the
  49. * specified line.
  50. */
  51. static __inline__ void spitfire_put_dcache_tag(unsigned long addr, unsigned long tag)
  52. {
  53. __asm__ __volatile__("stxa %0, [%1] %2\n\t"
  54. "membar #Sync"
  55. : /* No outputs */
  56. : "r" (tag), "r" (addr), "i" (ASI_DCACHE_TAG));
  57. }
  58. /* The instruction cache lines are flushed with this, but note that
  59. * this does not flush the pipeline. It is possible for a line to
  60. * get flushed but stale instructions to still be in the pipeline,
  61. * a flush instruction (to any address) is sufficient to handle
  62. * this issue after the line is invalidated.
  63. */
  64. static __inline__ void spitfire_put_icache_tag(unsigned long addr, unsigned long tag)
  65. {
  66. __asm__ __volatile__("stxa %0, [%1] %2\n\t"
  67. "membar #Sync"
  68. : /* No outputs */
  69. : "r" (tag), "r" (addr), "i" (ASI_IC_TAG));
  70. }
  71. static __inline__ unsigned long spitfire_get_dtlb_data(int entry)
  72. {
  73. unsigned long data;
  74. __asm__ __volatile__("ldxa [%1] %2, %0"
  75. : "=r" (data)
  76. : "r" (entry << 3), "i" (ASI_DTLB_DATA_ACCESS));
  77. /* Clear TTE diag bits. */
  78. data &= ~0x0003fe0000000000UL;
  79. return data;
  80. }
  81. static __inline__ unsigned long spitfire_get_dtlb_tag(int entry)
  82. {
  83. unsigned long tag;
  84. __asm__ __volatile__("ldxa [%1] %2, %0"
  85. : "=r" (tag)
  86. : "r" (entry << 3), "i" (ASI_DTLB_TAG_READ));
  87. return tag;
  88. }
  89. static __inline__ void spitfire_put_dtlb_data(int entry, unsigned long data)
  90. {
  91. __asm__ __volatile__("stxa %0, [%1] %2\n\t"
  92. "membar #Sync"
  93. : /* No outputs */
  94. : "r" (data), "r" (entry << 3),
  95. "i" (ASI_DTLB_DATA_ACCESS));
  96. }
  97. static __inline__ unsigned long spitfire_get_itlb_data(int entry)
  98. {
  99. unsigned long data;
  100. __asm__ __volatile__("ldxa [%1] %2, %0"
  101. : "=r" (data)
  102. : "r" (entry << 3), "i" (ASI_ITLB_DATA_ACCESS));
  103. /* Clear TTE diag bits. */
  104. data &= ~0x0003fe0000000000UL;
  105. return data;
  106. }
  107. static __inline__ unsigned long spitfire_get_itlb_tag(int entry)
  108. {
  109. unsigned long tag;
  110. __asm__ __volatile__("ldxa [%1] %2, %0"
  111. : "=r" (tag)
  112. : "r" (entry << 3), "i" (ASI_ITLB_TAG_READ));
  113. return tag;
  114. }
  115. static __inline__ void spitfire_put_itlb_data(int entry, unsigned long data)
  116. {
  117. __asm__ __volatile__("stxa %0, [%1] %2\n\t"
  118. "membar #Sync"
  119. : /* No outputs */
  120. : "r" (data), "r" (entry << 3),
  121. "i" (ASI_ITLB_DATA_ACCESS));
  122. }
  123. static __inline__ void spitfire_flush_dtlb_nucleus_page(unsigned long page)
  124. {
  125. __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
  126. "membar #Sync"
  127. : /* No outputs */
  128. : "r" (page | 0x20), "i" (ASI_DMMU_DEMAP));
  129. }
  130. static __inline__ void spitfire_flush_itlb_nucleus_page(unsigned long page)
  131. {
  132. __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
  133. "membar #Sync"
  134. : /* No outputs */
  135. : "r" (page | 0x20), "i" (ASI_IMMU_DEMAP));
  136. }
  137. /* Cheetah has "all non-locked" tlb flushes. */
  138. static __inline__ void cheetah_flush_dtlb_all(void)
  139. {
  140. __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
  141. "membar #Sync"
  142. : /* No outputs */
  143. : "r" (0x80), "i" (ASI_DMMU_DEMAP));
  144. }
  145. static __inline__ void cheetah_flush_itlb_all(void)
  146. {
  147. __asm__ __volatile__("stxa %%g0, [%0] %1\n\t"
  148. "membar #Sync"
  149. : /* No outputs */
  150. : "r" (0x80), "i" (ASI_IMMU_DEMAP));
  151. }
  152. /* Cheetah has a 4-tlb layout so direct access is a bit different.
  153. * The first two TLBs are fully assosciative, hold 16 entries, and are
  154. * used only for locked and >8K sized translations. One exists for
  155. * data accesses and one for instruction accesses.
  156. *
  157. * The third TLB is for data accesses to 8K non-locked translations, is
  158. * 2 way assosciative, and holds 512 entries. The fourth TLB is for
  159. * instruction accesses to 8K non-locked translations, is 2 way
  160. * assosciative, and holds 128 entries.
  161. *
  162. * Cheetah has some bug where bogus data can be returned from
  163. * ASI_{D,I}TLB_DATA_ACCESS loads, doing the load twice fixes
  164. * the problem for me. -DaveM
  165. */
  166. static __inline__ unsigned long cheetah_get_ldtlb_data(int entry)
  167. {
  168. unsigned long data;
  169. __asm__ __volatile__("ldxa [%1] %2, %%g0\n\t"
  170. "ldxa [%1] %2, %0"
  171. : "=r" (data)
  172. : "r" ((0 << 16) | (entry << 3)),
  173. "i" (ASI_DTLB_DATA_ACCESS));
  174. return data;
  175. }
  176. static __inline__ unsigned long cheetah_get_litlb_data(int entry)
  177. {
  178. unsigned long data;
  179. __asm__ __volatile__("ldxa [%1] %2, %%g0\n\t"
  180. "ldxa [%1] %2, %0"
  181. : "=r" (data)
  182. : "r" ((0 << 16) | (entry << 3)),
  183. "i" (ASI_ITLB_DATA_ACCESS));
  184. return data;
  185. }
  186. static __inline__ unsigned long cheetah_get_ldtlb_tag(int entry)
  187. {
  188. unsigned long tag;
  189. __asm__ __volatile__("ldxa [%1] %2, %0"
  190. : "=r" (tag)
  191. : "r" ((0 << 16) | (entry << 3)),
  192. "i" (ASI_DTLB_TAG_READ));
  193. return tag;
  194. }
  195. static __inline__ unsigned long cheetah_get_litlb_tag(int entry)
  196. {
  197. unsigned long tag;
  198. __asm__ __volatile__("ldxa [%1] %2, %0"
  199. : "=r" (tag)
  200. : "r" ((0 << 16) | (entry << 3)),
  201. "i" (ASI_ITLB_TAG_READ));
  202. return tag;
  203. }
  204. static __inline__ void cheetah_put_ldtlb_data(int entry, unsigned long data)
  205. {
  206. __asm__ __volatile__("stxa %0, [%1] %2\n\t"
  207. "membar #Sync"
  208. : /* No outputs */
  209. : "r" (data),
  210. "r" ((0 << 16) | (entry << 3)),
  211. "i" (ASI_DTLB_DATA_ACCESS));
  212. }
  213. static __inline__ void cheetah_put_litlb_data(int entry, unsigned long data)
  214. {
  215. __asm__ __volatile__("stxa %0, [%1] %2\n\t"
  216. "membar #Sync"
  217. : /* No outputs */
  218. : "r" (data),
  219. "r" ((0 << 16) | (entry << 3)),
  220. "i" (ASI_ITLB_DATA_ACCESS));
  221. }
  222. static __inline__ unsigned long cheetah_get_dtlb_data(int entry, int tlb)
  223. {
  224. unsigned long data;
  225. __asm__ __volatile__("ldxa [%1] %2, %%g0\n\t"
  226. "ldxa [%1] %2, %0"
  227. : "=r" (data)
  228. : "r" ((tlb << 16) | (entry << 3)), "i" (ASI_DTLB_DATA_ACCESS));
  229. return data;
  230. }
  231. static __inline__ unsigned long cheetah_get_dtlb_tag(int entry, int tlb)
  232. {
  233. unsigned long tag;
  234. __asm__ __volatile__("ldxa [%1] %2, %0"
  235. : "=r" (tag)
  236. : "r" ((tlb << 16) | (entry << 3)), "i" (ASI_DTLB_TAG_READ));
  237. return tag;
  238. }
  239. static __inline__ void cheetah_put_dtlb_data(int entry, unsigned long data, int tlb)
  240. {
  241. __asm__ __volatile__("stxa %0, [%1] %2\n\t"
  242. "membar #Sync"
  243. : /* No outputs */
  244. : "r" (data),
  245. "r" ((tlb << 16) | (entry << 3)),
  246. "i" (ASI_DTLB_DATA_ACCESS));
  247. }
  248. static __inline__ unsigned long cheetah_get_itlb_data(int entry)
  249. {
  250. unsigned long data;
  251. __asm__ __volatile__("ldxa [%1] %2, %%g0\n\t"
  252. "ldxa [%1] %2, %0"
  253. : "=r" (data)
  254. : "r" ((2 << 16) | (entry << 3)),
  255. "i" (ASI_ITLB_DATA_ACCESS));
  256. return data;
  257. }
  258. static __inline__ unsigned long cheetah_get_itlb_tag(int entry)
  259. {
  260. unsigned long tag;
  261. __asm__ __volatile__("ldxa [%1] %2, %0"
  262. : "=r" (tag)
  263. : "r" ((2 << 16) | (entry << 3)), "i" (ASI_ITLB_TAG_READ));
  264. return tag;
  265. }
  266. static __inline__ void cheetah_put_itlb_data(int entry, unsigned long data)
  267. {
  268. __asm__ __volatile__("stxa %0, [%1] %2\n\t"
  269. "membar #Sync"
  270. : /* No outputs */
  271. : "r" (data), "r" ((2 << 16) | (entry << 3)),
  272. "i" (ASI_ITLB_DATA_ACCESS));
  273. }
  274. #endif /* !(__ASSEMBLY__) */
  275. #endif /* !(_SPARC64_SPITFIRE_H) */