spitfire.h 9.1 KB

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