viking.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * viking.h: Defines specific to the GNU/Viking MBUS module.
  4. * This is SRMMU stuff.
  5. *
  6. * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
  7. */
  8. #ifndef _SPARC_VIKING_H
  9. #define _SPARC_VIKING_H
  10. #include <asm/asi.h>
  11. #include <asm/mxcc.h>
  12. #include <asm/pgtsrmmu.h>
  13. /* Bits in the SRMMU control register for GNU/Viking modules.
  14. *
  15. * -----------------------------------------------------------
  16. * |impl-vers| RSV |TC|AC|SP|BM|PC|MBM|SB|IC|DC|PSO|RSV|NF|ME|
  17. * -----------------------------------------------------------
  18. * 31 24 23-17 16 15 14 13 12 11 10 9 8 7 6-2 1 0
  19. *
  20. * TC: Tablewalk Cacheable -- 0 = Twalks are not cacheable in E-cache
  21. * 1 = Twalks are cacheable in E-cache
  22. *
  23. * GNU/Viking will only cache tablewalks in the E-cache (mxcc) if present
  24. * and never caches them internally (or so states the docs). Therefore
  25. * for machines lacking an E-cache (ie. in MBUS mode) this bit must
  26. * remain cleared.
  27. *
  28. * AC: Alternate Cacheable -- 0 = Passthru physical accesses not cacheable
  29. * 1 = Passthru physical accesses cacheable
  30. *
  31. * This indicates whether accesses are cacheable when no cachable bit
  32. * is present in the pte when the processor is in boot-mode or the
  33. * access does not need pte's for translation (ie. pass-thru ASI's).
  34. * "Cachable" is only referring to E-cache (if present) and not the
  35. * on chip split I/D caches of the GNU/Viking.
  36. *
  37. * SP: SnooP Enable -- 0 = bus snooping off, 1 = bus snooping on
  38. *
  39. * This enables snooping on the GNU/Viking bus. This must be on
  40. * for the hardware cache consistency mechanisms of the GNU/Viking
  41. * to work at all. On non-mxcc GNU/Viking modules the split I/D
  42. * caches will snoop regardless of whether they are enabled, this
  43. * takes care of the case where the I or D or both caches are turned
  44. * off yet still contain valid data. Note also that this bit does
  45. * not affect GNU/Viking store-buffer snoops, those happen if the
  46. * store-buffer is enabled no matter what.
  47. *
  48. * BM: Boot Mode -- 0 = not in boot mode, 1 = in boot mode
  49. *
  50. * This indicates whether the GNU/Viking is in boot-mode or not,
  51. * if it is then all instruction fetch physical addresses are
  52. * computed as 0xff0000000 + low 28 bits of requested address.
  53. * GNU/Viking boot-mode does not affect data accesses. Also,
  54. * in boot mode instruction accesses bypass the split on chip I/D
  55. * caches, they may be cached by the GNU/MXCC if present and enabled.
  56. *
  57. * MBM: MBus Mode -- 0 = not in MBus mode, 1 = in MBus mode
  58. *
  59. * This indicated the GNU/Viking configuration present. If in
  60. * MBUS mode, the GNU/Viking lacks a GNU/MXCC E-cache. If it is
  61. * not then the GNU/Viking is on a module VBUS connected directly
  62. * to a GNU/MXCC cache controller. The GNU/MXCC can be thus connected
  63. * to either an GNU/MBUS (sun4m) or the packet-switched GNU/XBus (sun4d).
  64. *
  65. * SB: StoreBuffer enable -- 0 = store buffer off, 1 = store buffer on
  66. *
  67. * The GNU/Viking store buffer allows the chip to continue execution
  68. * after a store even if the data cannot be placed in one of the
  69. * caches during that cycle. If disabled, all stores operations
  70. * occur synchronously.
  71. *
  72. * IC: Instruction Cache -- 0 = off, 1 = on
  73. * DC: Data Cache -- 0 = off, 1 = 0n
  74. *
  75. * These bits enable the on-cpu GNU/Viking split I/D caches. Note,
  76. * as mentioned above, these caches will snoop the bus in GNU/MBUS
  77. * configurations even when disabled to avoid data corruption.
  78. *
  79. * NF: No Fault -- 0 = faults generate traps, 1 = faults don't trap
  80. * ME: MMU enable -- 0 = mmu not translating, 1 = mmu translating
  81. *
  82. */
  83. #define VIKING_MMUENABLE 0x00000001
  84. #define VIKING_NOFAULT 0x00000002
  85. #define VIKING_PSO 0x00000080
  86. #define VIKING_DCENABLE 0x00000100 /* Enable data cache */
  87. #define VIKING_ICENABLE 0x00000200 /* Enable instruction cache */
  88. #define VIKING_SBENABLE 0x00000400 /* Enable store buffer */
  89. #define VIKING_MMODE 0x00000800 /* MBUS mode */
  90. #define VIKING_PCENABLE 0x00001000 /* Enable parity checking */
  91. #define VIKING_BMODE 0x00002000
  92. #define VIKING_SPENABLE 0x00004000 /* Enable bus cache snooping */
  93. #define VIKING_ACENABLE 0x00008000 /* Enable alternate caching */
  94. #define VIKING_TCENABLE 0x00010000 /* Enable table-walks to be cached */
  95. #define VIKING_DPENABLE 0x00040000 /* Enable the data prefetcher */
  96. /*
  97. * GNU/Viking Breakpoint Action Register fields.
  98. */
  99. #define VIKING_ACTION_MIX 0x00001000 /* Enable multiple instructions */
  100. /*
  101. * GNU/Viking Cache Tags.
  102. */
  103. #define VIKING_PTAG_VALID 0x01000000 /* Cache block is valid */
  104. #define VIKING_PTAG_DIRTY 0x00010000 /* Block has been modified */
  105. #define VIKING_PTAG_SHARED 0x00000100 /* Shared with some other cache */
  106. #ifndef __ASSEMBLY__
  107. static inline void viking_flush_icache(void)
  108. {
  109. __asm__ __volatile__("sta %%g0, [%%g0] %0\n\t"
  110. : /* no outputs */
  111. : "i" (ASI_M_IC_FLCLEAR)
  112. : "memory");
  113. }
  114. static inline void viking_flush_dcache(void)
  115. {
  116. __asm__ __volatile__("sta %%g0, [%%g0] %0\n\t"
  117. : /* no outputs */
  118. : "i" (ASI_M_DC_FLCLEAR)
  119. : "memory");
  120. }
  121. static inline void viking_unlock_icache(void)
  122. {
  123. __asm__ __volatile__("sta %%g0, [%0] %1\n\t"
  124. : /* no outputs */
  125. : "r" (0x80000000), "i" (ASI_M_IC_FLCLEAR)
  126. : "memory");
  127. }
  128. static inline void viking_unlock_dcache(void)
  129. {
  130. __asm__ __volatile__("sta %%g0, [%0] %1\n\t"
  131. : /* no outputs */
  132. : "r" (0x80000000), "i" (ASI_M_DC_FLCLEAR)
  133. : "memory");
  134. }
  135. static inline void viking_set_bpreg(unsigned long regval)
  136. {
  137. __asm__ __volatile__("sta %0, [%%g0] %1\n\t"
  138. : /* no outputs */
  139. : "r" (regval), "i" (ASI_M_ACTION)
  140. : "memory");
  141. }
  142. static inline unsigned long viking_get_bpreg(void)
  143. {
  144. unsigned long regval;
  145. __asm__ __volatile__("lda [%%g0] %1, %0\n\t"
  146. : "=r" (regval)
  147. : "i" (ASI_M_ACTION));
  148. return regval;
  149. }
  150. static inline void viking_get_dcache_ptag(int set, int block,
  151. unsigned long *data)
  152. {
  153. unsigned long ptag = ((set & 0x7f) << 5) | ((block & 0x3) << 26) |
  154. 0x80000000;
  155. unsigned long info, page;
  156. __asm__ __volatile__ ("ldda [%2] %3, %%g2\n\t"
  157. "or %%g0, %%g2, %0\n\t"
  158. "or %%g0, %%g3, %1\n\t"
  159. : "=r" (info), "=r" (page)
  160. : "r" (ptag), "i" (ASI_M_DATAC_TAG)
  161. : "g2", "g3");
  162. data[0] = info;
  163. data[1] = page;
  164. }
  165. static inline void viking_mxcc_turn_off_parity(unsigned long *mregp,
  166. unsigned long *mxcc_cregp)
  167. {
  168. unsigned long mreg = *mregp;
  169. unsigned long mxcc_creg = *mxcc_cregp;
  170. mreg &= ~(VIKING_PCENABLE);
  171. mxcc_creg &= ~(MXCC_CTL_PARE);
  172. __asm__ __volatile__ ("set 1f, %%g2\n\t"
  173. "andcc %%g2, 4, %%g0\n\t"
  174. "bne 2f\n\t"
  175. " nop\n"
  176. "1:\n\t"
  177. "sta %0, [%%g0] %3\n\t"
  178. "sta %1, [%2] %4\n\t"
  179. "b 1f\n\t"
  180. " nop\n\t"
  181. "nop\n"
  182. "2:\n\t"
  183. "sta %0, [%%g0] %3\n\t"
  184. "sta %1, [%2] %4\n"
  185. "1:\n\t"
  186. : /* no output */
  187. : "r" (mreg), "r" (mxcc_creg),
  188. "r" (MXCC_CREG), "i" (ASI_M_MMUREGS),
  189. "i" (ASI_M_MXCC)
  190. : "g2", "memory", "cc");
  191. *mregp = mreg;
  192. *mxcc_cregp = mxcc_creg;
  193. }
  194. static inline unsigned long viking_hwprobe(unsigned long vaddr)
  195. {
  196. unsigned long val;
  197. vaddr &= PAGE_MASK;
  198. /* Probe all MMU entries. */
  199. __asm__ __volatile__("lda [%1] %2, %0\n\t"
  200. : "=r" (val)
  201. : "r" (vaddr | 0x400), "i" (ASI_M_FLUSH_PROBE));
  202. if (!val)
  203. return 0;
  204. /* Probe region. */
  205. __asm__ __volatile__("lda [%1] %2, %0\n\t"
  206. : "=r" (val)
  207. : "r" (vaddr | 0x200), "i" (ASI_M_FLUSH_PROBE));
  208. if ((val & SRMMU_ET_MASK) == SRMMU_ET_PTE) {
  209. vaddr &= ~SRMMU_PGDIR_MASK;
  210. vaddr >>= PAGE_SHIFT;
  211. return val | (vaddr << 8);
  212. }
  213. /* Probe segment. */
  214. __asm__ __volatile__("lda [%1] %2, %0\n\t"
  215. : "=r" (val)
  216. : "r" (vaddr | 0x100), "i" (ASI_M_FLUSH_PROBE));
  217. if ((val & SRMMU_ET_MASK) == SRMMU_ET_PTE) {
  218. vaddr &= ~SRMMU_REAL_PMD_MASK;
  219. vaddr >>= PAGE_SHIFT;
  220. return val | (vaddr << 8);
  221. }
  222. /* Probe page. */
  223. __asm__ __volatile__("lda [%1] %2, %0\n\t"
  224. : "=r" (val)
  225. : "r" (vaddr), "i" (ASI_M_FLUSH_PROBE));
  226. return val;
  227. }
  228. #endif /* !__ASSEMBLY__ */
  229. #endif /* !(_SPARC_VIKING_H) */