pgtable-2level.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /*
  2. * arch/arm/include/asm/pgtable-2level.h
  3. *
  4. * Copyright (C) 1995-2002 Russell King
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #ifndef _ASM_PGTABLE_2LEVEL_H
  11. #define _ASM_PGTABLE_2LEVEL_H
  12. #define __PAGETABLE_PMD_FOLDED
  13. /*
  14. * Hardware-wise, we have a two level page table structure, where the first
  15. * level has 4096 entries, and the second level has 256 entries. Each entry
  16. * is one 32-bit word. Most of the bits in the second level entry are used
  17. * by hardware, and there aren't any "accessed" and "dirty" bits.
  18. *
  19. * Linux on the other hand has a three level page table structure, which can
  20. * be wrapped to fit a two level page table structure easily - using the PGD
  21. * and PTE only. However, Linux also expects one "PTE" table per page, and
  22. * at least a "dirty" bit.
  23. *
  24. * Therefore, we tweak the implementation slightly - we tell Linux that we
  25. * have 2048 entries in the first level, each of which is 8 bytes (iow, two
  26. * hardware pointers to the second level.) The second level contains two
  27. * hardware PTE tables arranged contiguously, preceded by Linux versions
  28. * which contain the state information Linux needs. We, therefore, end up
  29. * with 512 entries in the "PTE" level.
  30. *
  31. * This leads to the page tables having the following layout:
  32. *
  33. * pgd pte
  34. * | |
  35. * +--------+
  36. * | | +------------+ +0
  37. * +- - - - + | Linux pt 0 |
  38. * | | +------------+ +1024
  39. * +--------+ +0 | Linux pt 1 |
  40. * | |-----> +------------+ +2048
  41. * +- - - - + +4 | h/w pt 0 |
  42. * | |-----> +------------+ +3072
  43. * +--------+ +8 | h/w pt 1 |
  44. * | | +------------+ +4096
  45. *
  46. * See L_PTE_xxx below for definitions of bits in the "Linux pt", and
  47. * PTE_xxx for definitions of bits appearing in the "h/w pt".
  48. *
  49. * PMD_xxx definitions refer to bits in the first level page table.
  50. *
  51. * The "dirty" bit is emulated by only granting hardware write permission
  52. * iff the page is marked "writable" and "dirty" in the Linux PTE. This
  53. * means that a write to a clean page will cause a permission fault, and
  54. * the Linux MM layer will mark the page dirty via handle_pte_fault().
  55. * For the hardware to notice the permission change, the TLB entry must
  56. * be flushed, and ptep_set_access_flags() does that for us.
  57. *
  58. * The "accessed" or "young" bit is emulated by a similar method; we only
  59. * allow accesses to the page if the "young" bit is set. Accesses to the
  60. * page will cause a fault, and handle_pte_fault() will set the young bit
  61. * for us as long as the page is marked present in the corresponding Linux
  62. * PTE entry. Again, ptep_set_access_flags() will ensure that the TLB is
  63. * up to date.
  64. *
  65. * However, when the "young" bit is cleared, we deny access to the page
  66. * by clearing the hardware PTE. Currently Linux does not flush the TLB
  67. * for us in this case, which means the TLB will retain the transation
  68. * until either the TLB entry is evicted under pressure, or a context
  69. * switch which changes the user space mapping occurs.
  70. */
  71. #define PTRS_PER_PTE 512
  72. #define PTRS_PER_PMD 1
  73. #define PTRS_PER_PGD 2048
  74. #define PTE_HWTABLE_PTRS (PTRS_PER_PTE)
  75. #define PTE_HWTABLE_OFF (PTE_HWTABLE_PTRS * sizeof(pte_t))
  76. #define PTE_HWTABLE_SIZE (PTRS_PER_PTE * sizeof(u32))
  77. /*
  78. * PMD_SHIFT determines the size of the area a second-level page table can map
  79. * PGDIR_SHIFT determines what a third-level page table entry can map
  80. */
  81. #define PMD_SHIFT 21
  82. #define PGDIR_SHIFT 21
  83. #define PMD_SIZE (1UL << PMD_SHIFT)
  84. #define PMD_MASK (~(PMD_SIZE-1))
  85. #define PGDIR_SIZE (1UL << PGDIR_SHIFT)
  86. #define PGDIR_MASK (~(PGDIR_SIZE-1))
  87. /*
  88. * section address mask and size definitions.
  89. */
  90. #define SECTION_SHIFT 20
  91. #define SECTION_SIZE (1UL << SECTION_SHIFT)
  92. #define SECTION_MASK (~(SECTION_SIZE-1))
  93. /*
  94. * ARMv6 supersection address mask and size definitions.
  95. */
  96. #define SUPERSECTION_SHIFT 24
  97. #define SUPERSECTION_SIZE (1UL << SUPERSECTION_SHIFT)
  98. #define SUPERSECTION_MASK (~(SUPERSECTION_SIZE-1))
  99. #define USER_PTRS_PER_PGD (TASK_SIZE / PGDIR_SIZE)
  100. /*
  101. * "Linux" PTE definitions.
  102. *
  103. * We keep two sets of PTEs - the hardware and the linux version.
  104. * This allows greater flexibility in the way we map the Linux bits
  105. * onto the hardware tables, and allows us to have YOUNG and DIRTY
  106. * bits.
  107. *
  108. * The PTE table pointer refers to the hardware entries; the "Linux"
  109. * entries are stored 1024 bytes below.
  110. */
  111. #define L_PTE_VALID (_AT(pteval_t, 1) << 0) /* Valid */
  112. #define L_PTE_PRESENT (_AT(pteval_t, 1) << 0)
  113. #define L_PTE_YOUNG (_AT(pteval_t, 1) << 1)
  114. #define L_PTE_DIRTY (_AT(pteval_t, 1) << 6)
  115. #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7)
  116. #define L_PTE_USER (_AT(pteval_t, 1) << 8)
  117. #define L_PTE_XN (_AT(pteval_t, 1) << 9)
  118. #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
  119. #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
  120. /*
  121. * These are the memory types, defined to be compatible with
  122. * pre-ARMv6 CPUs cacheable and bufferable bits: n/a,n/a,C,B
  123. * ARMv6+ without TEX remapping, they are a table index.
  124. * ARMv6+ with TEX remapping, they correspond to n/a,TEX(0),C,B
  125. *
  126. * MT type Pre-ARMv6 ARMv6+ type / cacheable status
  127. * UNCACHED Uncached Strongly ordered
  128. * BUFFERABLE Bufferable Normal memory / non-cacheable
  129. * WRITETHROUGH Writethrough Normal memory / write through
  130. * WRITEBACK Writeback Normal memory / write back, read alloc
  131. * MINICACHE Minicache N/A
  132. * WRITEALLOC Writeback Normal memory / write back, write alloc
  133. * DEV_SHARED Uncached Device memory (shared)
  134. * DEV_NONSHARED Uncached Device memory (non-shared)
  135. * DEV_WC Bufferable Normal memory / non-cacheable
  136. * DEV_CACHED Writeback Normal memory / write back, read alloc
  137. * VECTORS Variable Normal memory / variable
  138. *
  139. * All normal memory mappings have the following properties:
  140. * - reads can be repeated with no side effects
  141. * - repeated reads return the last value written
  142. * - reads can fetch additional locations without side effects
  143. * - writes can be repeated (in certain cases) with no side effects
  144. * - writes can be merged before accessing the target
  145. * - unaligned accesses can be supported
  146. *
  147. * All device mappings have the following properties:
  148. * - no access speculation
  149. * - no repetition (eg, on return from an exception)
  150. * - number, order and size of accesses are maintained
  151. * - unaligned accesses are "unpredictable"
  152. */
  153. #define L_PTE_MT_UNCACHED (_AT(pteval_t, 0x00) << 2) /* 0000 */
  154. #define L_PTE_MT_BUFFERABLE (_AT(pteval_t, 0x01) << 2) /* 0001 */
  155. #define L_PTE_MT_WRITETHROUGH (_AT(pteval_t, 0x02) << 2) /* 0010 */
  156. #define L_PTE_MT_WRITEBACK (_AT(pteval_t, 0x03) << 2) /* 0011 */
  157. #define L_PTE_MT_MINICACHE (_AT(pteval_t, 0x06) << 2) /* 0110 (sa1100, xscale) */
  158. #define L_PTE_MT_WRITEALLOC (_AT(pteval_t, 0x07) << 2) /* 0111 */
  159. #define L_PTE_MT_DEV_SHARED (_AT(pteval_t, 0x04) << 2) /* 0100 */
  160. #define L_PTE_MT_DEV_NONSHARED (_AT(pteval_t, 0x0c) << 2) /* 1100 */
  161. #define L_PTE_MT_DEV_WC (_AT(pteval_t, 0x09) << 2) /* 1001 */
  162. #define L_PTE_MT_DEV_CACHED (_AT(pteval_t, 0x0b) << 2) /* 1011 */
  163. #define L_PTE_MT_VECTORS (_AT(pteval_t, 0x0f) << 2) /* 1111 */
  164. #define L_PTE_MT_MASK (_AT(pteval_t, 0x0f) << 2)
  165. #ifndef __ASSEMBLY__
  166. /*
  167. * The "pud_xxx()" functions here are trivial when the pmd is folded into
  168. * the pud: the pud entry is never bad, always exists, and can't be set or
  169. * cleared.
  170. */
  171. #define pud_none(pud) (0)
  172. #define pud_bad(pud) (0)
  173. #define pud_present(pud) (1)
  174. #define pud_clear(pudp) do { } while (0)
  175. #define set_pud(pud,pudp) do { } while (0)
  176. static inline pmd_t *pmd_offset(pud_t *pud, unsigned long addr)
  177. {
  178. return (pmd_t *)pud;
  179. }
  180. #define pmd_large(pmd) (pmd_val(pmd) & 2)
  181. #define pmd_bad(pmd) (pmd_val(pmd) & 2)
  182. #define pmd_present(pmd) (pmd_val(pmd))
  183. #define copy_pmd(pmdpd,pmdps) \
  184. do { \
  185. pmdpd[0] = pmdps[0]; \
  186. pmdpd[1] = pmdps[1]; \
  187. flush_pmd_entry(pmdpd); \
  188. } while (0)
  189. #define pmd_clear(pmdp) \
  190. do { \
  191. pmdp[0] = __pmd(0); \
  192. pmdp[1] = __pmd(0); \
  193. clean_pmd_entry(pmdp); \
  194. } while (0)
  195. /* we don't need complex calculations here as the pmd is folded into the pgd */
  196. #define pmd_addr_end(addr,end) (end)
  197. #define set_pte_ext(ptep,pte,ext) cpu_set_pte_ext(ptep,pte,ext)
  198. #define pte_special(pte) (0)
  199. static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
  200. /*
  201. * We don't have huge page support for short descriptors, for the moment
  202. * define empty stubs for use by pin_page_for_write.
  203. */
  204. #define pmd_hugewillfault(pmd) (0)
  205. #define pmd_thp_or_huge(pmd) (0)
  206. #endif /* __ASSEMBLY__ */
  207. #endif /* _ASM_PGTABLE_2LEVEL_H */