spitfire.h 9.1 KB

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