spitfire.h 9.0 KB

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