spitfire.h 9.2 KB

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