pgtable-bits.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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_XPA)
  34. /*
  35. * Page table bit offsets used for 64 bit physical addressing on
  36. * MIPS32r5 with XPA.
  37. */
  38. enum pgtable_bits {
  39. /* Used by TLB hardware (placed in EntryLo*) */
  40. _PAGE_NO_EXEC_SHIFT,
  41. _PAGE_NO_READ_SHIFT,
  42. _PAGE_GLOBAL_SHIFT,
  43. _PAGE_VALID_SHIFT,
  44. _PAGE_DIRTY_SHIFT,
  45. _CACHE_SHIFT,
  46. /* Used only by software (masked out before writing EntryLo*) */
  47. _PAGE_PRESENT_SHIFT = 24,
  48. _PAGE_WRITE_SHIFT,
  49. _PAGE_ACCESSED_SHIFT,
  50. _PAGE_MODIFIED_SHIFT,
  51. };
  52. /*
  53. * Bits for extended EntryLo0/EntryLo1 registers
  54. */
  55. #define _PFNX_MASK 0xffffff
  56. #elif defined(CONFIG_PHYS_ADDR_T_64BIT) && defined(CONFIG_CPU_MIPS32)
  57. /*
  58. * Page table bit offsets used for 36 bit physical addressing on MIPS32,
  59. * for example with Alchemy or Netlogic XLP/XLR.
  60. */
  61. enum pgtable_bits {
  62. /* Used by TLB hardware (placed in EntryLo*) */
  63. _PAGE_GLOBAL_SHIFT,
  64. _PAGE_VALID_SHIFT,
  65. _PAGE_DIRTY_SHIFT,
  66. _CACHE_SHIFT,
  67. /* Used only by software (masked out before writing EntryLo*) */
  68. _PAGE_PRESENT_SHIFT = _CACHE_SHIFT + 3,
  69. _PAGE_NO_READ_SHIFT,
  70. _PAGE_WRITE_SHIFT,
  71. _PAGE_ACCESSED_SHIFT,
  72. _PAGE_MODIFIED_SHIFT,
  73. };
  74. #elif defined(CONFIG_CPU_R3000) || defined(CONFIG_CPU_TX39XX)
  75. /* Page table bits used for r3k systems */
  76. enum pgtable_bits {
  77. /* Used only by software (writes to EntryLo ignored) */
  78. _PAGE_PRESENT_SHIFT,
  79. _PAGE_NO_READ_SHIFT,
  80. _PAGE_WRITE_SHIFT,
  81. _PAGE_ACCESSED_SHIFT,
  82. _PAGE_MODIFIED_SHIFT,
  83. /* Used by TLB hardware (placed in EntryLo) */
  84. _PAGE_GLOBAL_SHIFT = 8,
  85. _PAGE_VALID_SHIFT,
  86. _PAGE_DIRTY_SHIFT,
  87. _CACHE_UNCACHED_SHIFT,
  88. };
  89. #else
  90. /* Page table bits used for r4k systems */
  91. enum pgtable_bits {
  92. /* Used only by software (masked out before writing EntryLo*) */
  93. _PAGE_PRESENT_SHIFT,
  94. #if !defined(CONFIG_CPU_HAS_RIXI)
  95. _PAGE_NO_READ_SHIFT,
  96. #endif
  97. _PAGE_WRITE_SHIFT,
  98. _PAGE_ACCESSED_SHIFT,
  99. _PAGE_MODIFIED_SHIFT,
  100. #if defined(CONFIG_64BIT) && defined(CONFIG_MIPS_HUGE_TLB_SUPPORT)
  101. _PAGE_HUGE_SHIFT,
  102. #endif
  103. /* Used by TLB hardware (placed in EntryLo*) */
  104. #if defined(CONFIG_CPU_HAS_RIXI)
  105. _PAGE_NO_EXEC_SHIFT,
  106. _PAGE_NO_READ_SHIFT,
  107. #endif
  108. _PAGE_GLOBAL_SHIFT,
  109. _PAGE_VALID_SHIFT,
  110. _PAGE_DIRTY_SHIFT,
  111. _CACHE_SHIFT,
  112. };
  113. #endif /* defined(CONFIG_PHYS_ADDR_T_64BIT && defined(CONFIG_CPU_MIPS32) */
  114. /* Used only by software */
  115. #define _PAGE_PRESENT (1 << _PAGE_PRESENT_SHIFT)
  116. #define _PAGE_WRITE (1 << _PAGE_WRITE_SHIFT)
  117. #define _PAGE_ACCESSED (1 << _PAGE_ACCESSED_SHIFT)
  118. #define _PAGE_MODIFIED (1 << _PAGE_MODIFIED_SHIFT)
  119. #if defined(CONFIG_64BIT) && defined(CONFIG_MIPS_HUGE_TLB_SUPPORT)
  120. # define _PAGE_HUGE (1 << _PAGE_HUGE_SHIFT)
  121. #endif
  122. /* Used by TLB hardware (placed in EntryLo*) */
  123. #if defined(CONFIG_XPA)
  124. # define _PAGE_NO_EXEC (1 << _PAGE_NO_EXEC_SHIFT)
  125. #elif defined(CONFIG_CPU_HAS_RIXI)
  126. # define _PAGE_NO_EXEC (cpu_has_rixi ? (1 << _PAGE_NO_EXEC_SHIFT) : 0)
  127. #endif
  128. #define _PAGE_NO_READ (1 << _PAGE_NO_READ_SHIFT)
  129. #define _PAGE_GLOBAL (1 << _PAGE_GLOBAL_SHIFT)
  130. #define _PAGE_VALID (1 << _PAGE_VALID_SHIFT)
  131. #define _PAGE_DIRTY (1 << _PAGE_DIRTY_SHIFT)
  132. #if defined(CONFIG_CPU_R3000) || defined(CONFIG_CPU_TX39XX)
  133. # define _CACHE_UNCACHED (1 << _CACHE_UNCACHED_SHIFT)
  134. # define _CACHE_MASK _CACHE_UNCACHED
  135. # define _PFN_SHIFT PAGE_SHIFT
  136. #else
  137. # define _CACHE_MASK (7 << _CACHE_SHIFT)
  138. # define _PFN_SHIFT (PAGE_SHIFT - 12 + _CACHE_SHIFT + 3)
  139. #endif
  140. #ifndef _PAGE_NO_EXEC
  141. #define _PAGE_NO_EXEC 0
  142. #endif
  143. #define _PAGE_SILENT_READ _PAGE_VALID
  144. #define _PAGE_SILENT_WRITE _PAGE_DIRTY
  145. #define _PFN_MASK (~((1 << (_PFN_SHIFT)) - 1))
  146. /*
  147. * The final layouts of the PTE bits are:
  148. *
  149. * 64-bit, R1 or earlier: CCC D V G [S H] M A W R P
  150. * 32-bit, R1 or earler: CCC D V G M A W R P
  151. * 64-bit, R2 or later: CCC D V G RI/R XI [S H] M A W P
  152. * 32-bit, R2 or later: CCC D V G RI/R XI M A W P
  153. */
  154. /*
  155. * pte_to_entrylo converts a page table entry (PTE) into a Mips
  156. * entrylo0/1 value.
  157. */
  158. static inline uint64_t pte_to_entrylo(unsigned long pte_val)
  159. {
  160. #ifdef CONFIG_CPU_HAS_RIXI
  161. if (cpu_has_rixi) {
  162. int sa;
  163. #ifdef CONFIG_32BIT
  164. sa = 31 - _PAGE_NO_READ_SHIFT;
  165. #else
  166. sa = 63 - _PAGE_NO_READ_SHIFT;
  167. #endif
  168. /*
  169. * C has no way to express that this is a DSRL
  170. * _PAGE_NO_EXEC_SHIFT followed by a ROTR 2. Luckily
  171. * in the fast path this is done in assembly
  172. */
  173. return (pte_val >> _PAGE_GLOBAL_SHIFT) |
  174. ((pte_val & (_PAGE_NO_EXEC | _PAGE_NO_READ)) << sa);
  175. }
  176. #endif
  177. return pte_val >> _PAGE_GLOBAL_SHIFT;
  178. }
  179. /*
  180. * Cache attributes
  181. */
  182. #if defined(CONFIG_CPU_R3000) || defined(CONFIG_CPU_TX39XX)
  183. #define _CACHE_CACHABLE_NONCOHERENT 0
  184. #define _CACHE_UNCACHED_ACCELERATED _CACHE_UNCACHED
  185. #elif defined(CONFIG_CPU_SB1)
  186. /* No penalty for being coherent on the SB1, so just
  187. use it for "noncoherent" spaces, too. Shouldn't hurt. */
  188. #define _CACHE_CACHABLE_NONCOHERENT (5<<_CACHE_SHIFT)
  189. #elif defined(CONFIG_CPU_LOONGSON3)
  190. /* Using COHERENT flag for NONCOHERENT doesn't hurt. */
  191. #define _CACHE_CACHABLE_NONCOHERENT (3<<_CACHE_SHIFT) /* LOONGSON */
  192. #define _CACHE_CACHABLE_COHERENT (3<<_CACHE_SHIFT) /* LOONGSON-3 */
  193. #elif defined(CONFIG_MACH_INGENIC)
  194. /* Ingenic uses the WA bit to achieve write-combine memory writes */
  195. #define _CACHE_UNCACHED_ACCELERATED (1<<_CACHE_SHIFT)
  196. #endif
  197. #ifndef _CACHE_CACHABLE_NO_WA
  198. #define _CACHE_CACHABLE_NO_WA (0<<_CACHE_SHIFT)
  199. #endif
  200. #ifndef _CACHE_CACHABLE_WA
  201. #define _CACHE_CACHABLE_WA (1<<_CACHE_SHIFT)
  202. #endif
  203. #ifndef _CACHE_UNCACHED
  204. #define _CACHE_UNCACHED (2<<_CACHE_SHIFT)
  205. #endif
  206. #ifndef _CACHE_CACHABLE_NONCOHERENT
  207. #define _CACHE_CACHABLE_NONCOHERENT (3<<_CACHE_SHIFT)
  208. #endif
  209. #ifndef _CACHE_CACHABLE_CE
  210. #define _CACHE_CACHABLE_CE (4<<_CACHE_SHIFT)
  211. #endif
  212. #ifndef _CACHE_CACHABLE_COW
  213. #define _CACHE_CACHABLE_COW (5<<_CACHE_SHIFT)
  214. #endif
  215. #ifndef _CACHE_CACHABLE_CUW
  216. #define _CACHE_CACHABLE_CUW (6<<_CACHE_SHIFT)
  217. #endif
  218. #ifndef _CACHE_UNCACHED_ACCELERATED
  219. #define _CACHE_UNCACHED_ACCELERATED (7<<_CACHE_SHIFT)
  220. #endif
  221. #define __READABLE (_PAGE_SILENT_READ | _PAGE_ACCESSED)
  222. #define __WRITEABLE (_PAGE_SILENT_WRITE | _PAGE_WRITE | _PAGE_MODIFIED)
  223. #define _PAGE_CHG_MASK (_PAGE_ACCESSED | _PAGE_MODIFIED | \
  224. _PFN_MASK | _CACHE_MASK)
  225. #endif /* _ASM_PGTABLE_BITS_H */