pte-e500.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _ASM_POWERPC_NOHASH_PTE_E500_H
  3. #define _ASM_POWERPC_NOHASH_PTE_E500_H
  4. #ifdef __KERNEL__
  5. /* PTE bit definitions for processors compliant to the Book3E
  6. * architecture 2.06 or later. The position of the PTE bits
  7. * matches the HW definition of the optional Embedded Page Table
  8. * category.
  9. */
  10. /* Architected bits */
  11. #define _PAGE_PRESENT 0x000001 /* software: pte contains a translation */
  12. #define _PAGE_SW1 0x000002
  13. #define _PAGE_BIT_SWAP_TYPE 2
  14. #define _PAGE_BAP_SR 0x000004
  15. #define _PAGE_BAP_UR 0x000008
  16. #define _PAGE_BAP_SW 0x000010
  17. #define _PAGE_BAP_UW 0x000020
  18. #define _PAGE_BAP_SX 0x000040
  19. #define _PAGE_BAP_UX 0x000080
  20. #define _PAGE_PSIZE_MSK 0x000f00
  21. #define _PAGE_PSIZE_4K 0x000200
  22. #define _PAGE_PSIZE_8K 0x000300
  23. #define _PAGE_PSIZE_16K 0x000400
  24. #define _PAGE_PSIZE_32K 0x000500
  25. #define _PAGE_PSIZE_64K 0x000600
  26. #define _PAGE_PSIZE_128K 0x000700
  27. #define _PAGE_PSIZE_256K 0x000800
  28. #define _PAGE_PSIZE_512K 0x000900
  29. #define _PAGE_PSIZE_1M 0x000a00
  30. #define _PAGE_PSIZE_2M 0x000b00
  31. #define _PAGE_PSIZE_4M 0x000c00
  32. #define _PAGE_PSIZE_8M 0x000d00
  33. #define _PAGE_PSIZE_16M 0x000e00
  34. #define _PAGE_PSIZE_32M 0x000f00
  35. #define _PAGE_DIRTY 0x001000 /* C: page changed */
  36. #define _PAGE_SW0 0x002000
  37. #define _PAGE_U3 0x004000
  38. #define _PAGE_U2 0x008000
  39. #define _PAGE_U1 0x010000
  40. #define _PAGE_U0 0x020000
  41. #define _PAGE_ACCESSED 0x040000
  42. #define _PAGE_ENDIAN 0x080000
  43. #define _PAGE_GUARDED 0x100000
  44. #define _PAGE_COHERENT 0x200000 /* M: enforce memory coherence */
  45. #define _PAGE_NO_CACHE 0x400000 /* I: cache inhibit */
  46. #define _PAGE_WRITETHRU 0x800000 /* W: cache write-through */
  47. /* "Higher level" linux bit combinations */
  48. #define _PAGE_EXEC (_PAGE_BAP_SX | _PAGE_BAP_UX) /* .. and was cache cleaned */
  49. #define _PAGE_RW (_PAGE_BAP_SW | _PAGE_BAP_UW) /* User write permission */
  50. #define _PAGE_KERNEL_RW (_PAGE_BAP_SW | _PAGE_BAP_SR | _PAGE_DIRTY)
  51. #define _PAGE_KERNEL_RO (_PAGE_BAP_SR)
  52. #define _PAGE_KERNEL_RWX (_PAGE_BAP_SW | _PAGE_BAP_SR | _PAGE_DIRTY | _PAGE_BAP_SX)
  53. #define _PAGE_KERNEL_ROX (_PAGE_BAP_SR | _PAGE_BAP_SX)
  54. #define _PAGE_USER (_PAGE_BAP_UR | _PAGE_BAP_SR) /* Can be read */
  55. #define _PAGE_PRIVILEGED (_PAGE_BAP_SR)
  56. #define _PAGE_SPECIAL _PAGE_SW0
  57. /* Base page size */
  58. #define _PAGE_PSIZE _PAGE_PSIZE_4K
  59. #define PTE_RPN_SHIFT (24)
  60. #define PTE_WIMGE_SHIFT (19)
  61. #define PTE_BAP_SHIFT (2)
  62. /* On 32-bit, we never clear the top part of the PTE */
  63. #ifdef CONFIG_PPC32
  64. #define _PTE_NONE_MASK 0xffffffff00000000ULL
  65. #define _PMD_PRESENT 0
  66. #define _PMD_PRESENT_MASK (PAGE_MASK)
  67. #define _PMD_BAD (~PAGE_MASK)
  68. #define _PMD_USER 0
  69. #else
  70. #define _PTE_NONE_MASK 0
  71. #endif
  72. /*
  73. * We define 2 sets of base prot bits, one for basic pages (ie,
  74. * cacheable kernel and user pages) and one for non cacheable
  75. * pages. We always set _PAGE_COHERENT when SMP is enabled or
  76. * the processor might need it for DMA coherency.
  77. */
  78. #define _PAGE_BASE_NC (_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_PSIZE)
  79. #if defined(CONFIG_SMP)
  80. #define _PAGE_BASE (_PAGE_BASE_NC | _PAGE_COHERENT)
  81. #else
  82. #define _PAGE_BASE (_PAGE_BASE_NC)
  83. #endif
  84. /* Permission masks used to generate the __P and __S table */
  85. #define PAGE_NONE __pgprot(_PAGE_BASE)
  86. #define PAGE_SHARED __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RW)
  87. #define PAGE_SHARED_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RW | _PAGE_BAP_UX)
  88. #define PAGE_COPY __pgprot(_PAGE_BASE | _PAGE_USER)
  89. #define PAGE_COPY_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_BAP_UX)
  90. #define PAGE_READONLY __pgprot(_PAGE_BASE | _PAGE_USER)
  91. #define PAGE_READONLY_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_BAP_UX)
  92. #ifndef __ASSEMBLY__
  93. static inline pte_t pte_mkprivileged(pte_t pte)
  94. {
  95. return __pte((pte_val(pte) & ~_PAGE_USER) | _PAGE_PRIVILEGED);
  96. }
  97. #define pte_mkprivileged pte_mkprivileged
  98. static inline pte_t pte_mkuser(pte_t pte)
  99. {
  100. return __pte((pte_val(pte) & ~_PAGE_PRIVILEGED) | _PAGE_USER);
  101. }
  102. #define pte_mkuser pte_mkuser
  103. static inline pte_t pte_mkexec(pte_t pte)
  104. {
  105. if (pte_val(pte) & _PAGE_BAP_UR)
  106. return __pte((pte_val(pte) & ~_PAGE_BAP_SX) | _PAGE_BAP_UX);
  107. else
  108. return __pte((pte_val(pte) & ~_PAGE_BAP_UX) | _PAGE_BAP_SX);
  109. }
  110. #define pte_mkexec pte_mkexec
  111. #endif /* __ASSEMBLY__ */
  112. #endif /* __KERNEL__ */
  113. #endif /* _ASM_POWERPC_NOHASH_PTE_E500_H */