pgtable-bits.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 1994 - 2002 by Ralf Baechle
  7. * Copyright (C) 1999, 2000, 2001 Silicon Graphics, Inc.
  8. * Copyright (C) 2002 Maciej W. Rozycki
  9. */
  10. #ifndef _ASM_PGTABLE_BITS_H
  11. #define _ASM_PGTABLE_BITS_H
  12. /*
  13. * Note that we shift the lower 32bits of each EntryLo[01] entry
  14. * 6 bits to the left. That way we can convert the PFN into the
  15. * physical address by a single 'and' operation and gain 6 additional
  16. * bits for storing information which isn't present in a normal
  17. * MIPS page table.
  18. *
  19. * Similar to the Alpha port, we need to keep track of the ref
  20. * and mod bits in software. We have a software "yeah you can read
  21. * from this page" bit, and a hardware one which actually lets the
  22. * process read from the page. On the same token we have a software
  23. * writable bit and the real hardware one which actually lets the
  24. * process write to the page, this keeps a mod bit via the hardware
  25. * dirty bit.
  26. *
  27. * Certain revisions of the R4000 and R5000 have a bug where if a
  28. * certain sequence occurs in the last 3 instructions of an executable
  29. * page, and the following page is not mapped, the cpu can do
  30. * unpredictable things. The code (when it is written) to deal with
  31. * this problem will be in the update_mmu_cache() code for the r4k.
  32. */
  33. #if defined(CONFIG_PHYS_ADDR_T_64BIT) && defined(CONFIG_CPU_MIPS32)
  34. /*
  35. * The following bits are implemented by the TLB hardware
  36. */
  37. #define _PAGE_NO_EXEC_SHIFT 0
  38. #define _PAGE_NO_EXEC (1 << _PAGE_NO_EXEC_SHIFT)
  39. #define _PAGE_NO_READ_SHIFT (_PAGE_NO_EXEC_SHIFT + 1)
  40. #define _PAGE_NO_READ (1 << _PAGE_NO_READ_SHIFT)
  41. #define _PAGE_GLOBAL_SHIFT (_PAGE_NO_READ_SHIFT + 1)
  42. #define _PAGE_GLOBAL (1 << _PAGE_GLOBAL_SHIFT)
  43. #define _PAGE_VALID_SHIFT (_PAGE_GLOBAL_SHIFT + 1)
  44. #define _PAGE_VALID (1 << _PAGE_VALID_SHIFT)
  45. #define _PAGE_DIRTY_SHIFT (_PAGE_VALID_SHIFT + 1)
  46. #define _PAGE_DIRTY (1 << _PAGE_DIRTY_SHIFT)
  47. #define _CACHE_SHIFT (_PAGE_DIRTY_SHIFT + 1)
  48. #define _CACHE_MASK (7 << _CACHE_SHIFT)
  49. /*
  50. * The following bits are implemented in software
  51. */
  52. #define _PAGE_PRESENT_SHIFT (24)
  53. #define _PAGE_PRESENT (1 << _PAGE_PRESENT_SHIFT)
  54. #define _PAGE_READ_SHIFT (_PAGE_PRESENT_SHIFT + 1)
  55. #define _PAGE_READ (1 << _PAGE_READ_SHIFT)
  56. #define _PAGE_WRITE_SHIFT (_PAGE_READ_SHIFT + 1)
  57. #define _PAGE_WRITE (1 << _PAGE_WRITE_SHIFT)
  58. #define _PAGE_ACCESSED_SHIFT (_PAGE_WRITE_SHIFT + 1)
  59. #define _PAGE_ACCESSED (1 << _PAGE_ACCESSED_SHIFT)
  60. #define _PAGE_MODIFIED_SHIFT (_PAGE_ACCESSED_SHIFT + 1)
  61. #define _PAGE_MODIFIED (1 << _PAGE_MODIFIED_SHIFT)
  62. #define _PFN_SHIFT (PAGE_SHIFT - 12 + _CACHE_SHIFT + 3)
  63. /*
  64. * Bits for extended EntryLo0/EntryLo1 registers
  65. */
  66. #define _PFNX_MASK 0xffffff
  67. #elif defined(CONFIG_CPU_R3000) || defined(CONFIG_CPU_TX39XX)
  68. /*
  69. * The following bits are implemented in software
  70. */
  71. #define _PAGE_PRESENT_SHIFT (0)
  72. #define _PAGE_PRESENT (1 << _PAGE_PRESENT_SHIFT)
  73. #define _PAGE_READ_SHIFT (_PAGE_PRESENT_SHIFT + 1)
  74. #define _PAGE_READ (1 << _PAGE_READ_SHIFT)
  75. #define _PAGE_WRITE_SHIFT (_PAGE_READ_SHIFT + 1)
  76. #define _PAGE_WRITE (1 << _PAGE_WRITE_SHIFT)
  77. #define _PAGE_ACCESSED_SHIFT (_PAGE_WRITE_SHIFT + 1)
  78. #define _PAGE_ACCESSED (1 << _PAGE_ACCESSED_SHIFT)
  79. #define _PAGE_MODIFIED_SHIFT (_PAGE_ACCESSED_SHIFT + 1)
  80. #define _PAGE_MODIFIED (1 << _PAGE_MODIFIED_SHIFT)
  81. /*
  82. * The following bits are implemented by the TLB hardware
  83. */
  84. #define _PAGE_GLOBAL_SHIFT (_PAGE_MODIFIED_SHIFT + 4)
  85. #define _PAGE_GLOBAL (1 << _PAGE_GLOBAL_SHIFT)
  86. #define _PAGE_VALID_SHIFT (_PAGE_GLOBAL_SHIFT + 1)
  87. #define _PAGE_VALID (1 << _PAGE_VALID_SHIFT)
  88. #define _PAGE_DIRTY_SHIFT (_PAGE_VALID_SHIFT + 1)
  89. #define _PAGE_DIRTY (1 << _PAGE_DIRTY_SHIFT)
  90. #define _CACHE_UNCACHED_SHIFT (_PAGE_DIRTY_SHIFT + 1)
  91. #define _CACHE_UNCACHED (1 << _CACHE_UNCACHED_SHIFT)
  92. #define _CACHE_MASK _CACHE_UNCACHED
  93. #define _PFN_SHIFT PAGE_SHIFT
  94. #else
  95. /*
  96. * Below are the "Normal" R4K cases
  97. */
  98. /*
  99. * The following bits are implemented in software
  100. */
  101. #define _PAGE_PRESENT_SHIFT 0
  102. #define _PAGE_PRESENT (1 << _PAGE_PRESENT_SHIFT)
  103. /* R2 or later cores check for RI/XI support to determine _PAGE_READ */
  104. #if defined(CONFIG_CPU_MIPSR2) || defined(CONFIG_CPU_MIPSR6)
  105. #define _PAGE_WRITE_SHIFT (_PAGE_PRESENT_SHIFT + 1)
  106. #define _PAGE_WRITE (1 << _PAGE_WRITE_SHIFT)
  107. #else
  108. #define _PAGE_READ_SHIFT (_PAGE_PRESENT_SHIFT + 1)
  109. #define _PAGE_READ (1 << _PAGE_READ_SHIFT)
  110. #define _PAGE_WRITE_SHIFT (_PAGE_READ_SHIFT + 1)
  111. #define _PAGE_WRITE (1 << _PAGE_WRITE_SHIFT)
  112. #endif
  113. #define _PAGE_ACCESSED_SHIFT (_PAGE_WRITE_SHIFT + 1)
  114. #define _PAGE_ACCESSED (1 << _PAGE_ACCESSED_SHIFT)
  115. #define _PAGE_MODIFIED_SHIFT (_PAGE_ACCESSED_SHIFT + 1)
  116. #define _PAGE_MODIFIED (1 << _PAGE_MODIFIED_SHIFT)
  117. #if defined(CONFIG_64BIT) && defined(CONFIG_MIPS_HUGE_TLB_SUPPORT)
  118. /* Huge TLB page */
  119. #define _PAGE_HUGE_SHIFT (_PAGE_MODIFIED_SHIFT + 1)
  120. #define _PAGE_HUGE (1 << _PAGE_HUGE_SHIFT)
  121. #endif /* CONFIG_64BIT && CONFIG_MIPS_HUGE_TLB_SUPPORT */
  122. #if defined(CONFIG_CPU_MIPSR2) || defined(CONFIG_CPU_MIPSR6)
  123. /* XI - page cannot be executed */
  124. #ifdef _PAGE_HUGE_SHIFT
  125. #define _PAGE_NO_EXEC_SHIFT (_PAGE_HUGE_SHIFT + 1)
  126. #else
  127. #define _PAGE_NO_EXEC_SHIFT (_PAGE_MODIFIED_SHIFT + 1)
  128. #endif
  129. #define _PAGE_NO_EXEC (cpu_has_rixi ? (1 << _PAGE_NO_EXEC_SHIFT) : 0)
  130. /* RI - page cannot be read */
  131. #define _PAGE_READ_SHIFT (_PAGE_NO_EXEC_SHIFT + 1)
  132. #define _PAGE_READ (cpu_has_rixi ? 0 : (1 << _PAGE_READ_SHIFT))
  133. #define _PAGE_NO_READ_SHIFT _PAGE_READ_SHIFT
  134. #define _PAGE_NO_READ (cpu_has_rixi ? (1 << _PAGE_READ_SHIFT) : 0)
  135. #endif /* defined(CONFIG_CPU_MIPSR2) || defined(CONFIG_CPU_MIPSR6) */
  136. #if defined(_PAGE_NO_READ_SHIFT)
  137. #define _PAGE_GLOBAL_SHIFT (_PAGE_NO_READ_SHIFT + 1)
  138. #elif defined(_PAGE_HUGE_SHIFT)
  139. #define _PAGE_GLOBAL_SHIFT (_PAGE_HUGE_SHIFT + 1)
  140. #else
  141. #define _PAGE_GLOBAL_SHIFT (_PAGE_MODIFIED_SHIFT + 1)
  142. #endif
  143. #define _PAGE_GLOBAL (1 << _PAGE_GLOBAL_SHIFT)
  144. #define _PAGE_VALID_SHIFT (_PAGE_GLOBAL_SHIFT + 1)
  145. #define _PAGE_VALID (1 << _PAGE_VALID_SHIFT)
  146. #define _PAGE_DIRTY_SHIFT (_PAGE_VALID_SHIFT + 1)
  147. #define _PAGE_DIRTY (1 << _PAGE_DIRTY_SHIFT)
  148. #define _CACHE_SHIFT (_PAGE_DIRTY_SHIFT + 1)
  149. #define _CACHE_MASK (7 << _CACHE_SHIFT)
  150. #define _PFN_SHIFT (PAGE_SHIFT - 12 + _CACHE_SHIFT + 3)
  151. #endif /* defined(CONFIG_PHYS_ADDR_T_64BIT && defined(CONFIG_CPU_MIPS32) */
  152. #ifndef _PAGE_NO_EXEC
  153. #define _PAGE_NO_EXEC 0
  154. #endif
  155. #ifndef _PAGE_NO_READ
  156. #define _PAGE_NO_READ 0
  157. #endif
  158. #define _PAGE_SILENT_READ _PAGE_VALID
  159. #define _PAGE_SILENT_WRITE _PAGE_DIRTY
  160. #define _PFN_MASK (~((1 << (_PFN_SHIFT)) - 1))
  161. /*
  162. * The final layouts of the PTE bits are:
  163. *
  164. * 64-bit, R1 or earlier: CCC D V G [S H] M A W R P
  165. * 32-bit, R1 or earler: CCC D V G M A W R P
  166. * 64-bit, R2 or later: CCC D V G RI/R XI [S H] M A W P
  167. * 32-bit, R2 or later: CCC D V G RI/R XI M A W P
  168. */
  169. /*
  170. * pte_to_entrylo converts a page table entry (PTE) into a Mips
  171. * entrylo0/1 value.
  172. */
  173. static inline uint64_t pte_to_entrylo(unsigned long pte_val)
  174. {
  175. #if defined(CONFIG_CPU_MIPSR2) || defined(CONFIG_CPU_MIPSR6)
  176. if (cpu_has_rixi) {
  177. int sa;
  178. #ifdef CONFIG_32BIT
  179. sa = 31 - _PAGE_NO_READ_SHIFT;
  180. #else
  181. sa = 63 - _PAGE_NO_READ_SHIFT;
  182. #endif
  183. /*
  184. * C has no way to express that this is a DSRL
  185. * _PAGE_NO_EXEC_SHIFT followed by a ROTR 2. Luckily
  186. * in the fast path this is done in assembly
  187. */
  188. return (pte_val >> _PAGE_GLOBAL_SHIFT) |
  189. ((pte_val & (_PAGE_NO_EXEC | _PAGE_NO_READ)) << sa);
  190. }
  191. #endif
  192. return pte_val >> _PAGE_GLOBAL_SHIFT;
  193. }
  194. /*
  195. * Cache attributes
  196. */
  197. #if defined(CONFIG_CPU_R3000) || defined(CONFIG_CPU_TX39XX)
  198. #define _CACHE_CACHABLE_NONCOHERENT 0
  199. #define _CACHE_UNCACHED_ACCELERATED _CACHE_UNCACHED
  200. #elif defined(CONFIG_CPU_SB1)
  201. /* No penalty for being coherent on the SB1, so just
  202. use it for "noncoherent" spaces, too. Shouldn't hurt. */
  203. #define _CACHE_CACHABLE_NONCOHERENT (5<<_CACHE_SHIFT)
  204. #elif defined(CONFIG_CPU_LOONGSON3)
  205. /* Using COHERENT flag for NONCOHERENT doesn't hurt. */
  206. #define _CACHE_CACHABLE_NONCOHERENT (3<<_CACHE_SHIFT) /* LOONGSON */
  207. #define _CACHE_CACHABLE_COHERENT (3<<_CACHE_SHIFT) /* LOONGSON-3 */
  208. #elif defined(CONFIG_MACH_INGENIC)
  209. /* Ingenic uses the WA bit to achieve write-combine memory writes */
  210. #define _CACHE_UNCACHED_ACCELERATED (1<<_CACHE_SHIFT)
  211. #endif
  212. #ifndef _CACHE_CACHABLE_NO_WA
  213. #define _CACHE_CACHABLE_NO_WA (0<<_CACHE_SHIFT)
  214. #endif
  215. #ifndef _CACHE_CACHABLE_WA
  216. #define _CACHE_CACHABLE_WA (1<<_CACHE_SHIFT)
  217. #endif
  218. #ifndef _CACHE_UNCACHED
  219. #define _CACHE_UNCACHED (2<<_CACHE_SHIFT)
  220. #endif
  221. #ifndef _CACHE_CACHABLE_NONCOHERENT
  222. #define _CACHE_CACHABLE_NONCOHERENT (3<<_CACHE_SHIFT)
  223. #endif
  224. #ifndef _CACHE_CACHABLE_CE
  225. #define _CACHE_CACHABLE_CE (4<<_CACHE_SHIFT)
  226. #endif
  227. #ifndef _CACHE_CACHABLE_COW
  228. #define _CACHE_CACHABLE_COW (5<<_CACHE_SHIFT)
  229. #endif
  230. #ifndef _CACHE_CACHABLE_CUW
  231. #define _CACHE_CACHABLE_CUW (6<<_CACHE_SHIFT)
  232. #endif
  233. #ifndef _CACHE_UNCACHED_ACCELERATED
  234. #define _CACHE_UNCACHED_ACCELERATED (7<<_CACHE_SHIFT)
  235. #endif
  236. #define __READABLE (_PAGE_SILENT_READ | _PAGE_READ | _PAGE_ACCESSED)
  237. #define __WRITEABLE (_PAGE_SILENT_WRITE | _PAGE_WRITE | _PAGE_MODIFIED)
  238. #define _PAGE_CHG_MASK (_PAGE_ACCESSED | _PAGE_MODIFIED | \
  239. _PFN_MASK | _CACHE_MASK)
  240. #endif /* _ASM_PGTABLE_BITS_H */