spitfire.h 9.1 KB

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