spitfire.h 9.3 KB

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