spitfire.h 9.2 KB

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