pgtable_64.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. #ifndef _ASM_X86_PGTABLE_64_H
  2. #define _ASM_X86_PGTABLE_64_H
  3. #include <linux/const.h>
  4. #ifndef __ASSEMBLY__
  5. /*
  6. * This file contains the functions and defines necessary to modify and use
  7. * the x86-64 page table tree.
  8. */
  9. #include <asm/processor.h>
  10. #include <linux/bitops.h>
  11. #include <linux/threads.h>
  12. extern pud_t level3_kernel_pgt[512];
  13. extern pud_t level3_ident_pgt[512];
  14. extern pmd_t level2_kernel_pgt[512];
  15. extern pmd_t level2_fixmap_pgt[512];
  16. extern pmd_t level2_ident_pgt[512];
  17. extern pgd_t init_level4_pgt[];
  18. #define swapper_pg_dir init_level4_pgt
  19. extern void paging_init(void);
  20. #endif /* !__ASSEMBLY__ */
  21. #define SHARED_KERNEL_PMD 0
  22. /*
  23. * PGDIR_SHIFT determines what a top-level page table entry can map
  24. */
  25. #define PGDIR_SHIFT 39
  26. #define PTRS_PER_PGD 512
  27. /*
  28. * 3rd level page
  29. */
  30. #define PUD_SHIFT 30
  31. #define PTRS_PER_PUD 512
  32. /*
  33. * PMD_SHIFT determines the size of the area a middle-level
  34. * page table can map
  35. */
  36. #define PMD_SHIFT 21
  37. #define PTRS_PER_PMD 512
  38. /*
  39. * entries per page directory level
  40. */
  41. #define PTRS_PER_PTE 512
  42. #ifndef __ASSEMBLY__
  43. #define pte_ERROR(e) \
  44. printk("%s:%d: bad pte %p(%016lx).\n", \
  45. __FILE__, __LINE__, &(e), pte_val(e))
  46. #define pmd_ERROR(e) \
  47. printk("%s:%d: bad pmd %p(%016lx).\n", \
  48. __FILE__, __LINE__, &(e), pmd_val(e))
  49. #define pud_ERROR(e) \
  50. printk("%s:%d: bad pud %p(%016lx).\n", \
  51. __FILE__, __LINE__, &(e), pud_val(e))
  52. #define pgd_ERROR(e) \
  53. printk("%s:%d: bad pgd %p(%016lx).\n", \
  54. __FILE__, __LINE__, &(e), pgd_val(e))
  55. struct mm_struct;
  56. void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte);
  57. static inline void native_pte_clear(struct mm_struct *mm, unsigned long addr,
  58. pte_t *ptep)
  59. {
  60. *ptep = native_make_pte(0);
  61. }
  62. static inline void native_set_pte(pte_t *ptep, pte_t pte)
  63. {
  64. *ptep = pte;
  65. }
  66. static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
  67. {
  68. native_set_pte(ptep, pte);
  69. }
  70. static inline pte_t native_ptep_get_and_clear(pte_t *xp)
  71. {
  72. #ifdef CONFIG_SMP
  73. return native_make_pte(xchg(&xp->pte, 0));
  74. #else
  75. /* native_local_ptep_get_and_clear,
  76. but duplicated because of cyclic dependency */
  77. pte_t ret = *xp;
  78. native_pte_clear(NULL, 0, xp);
  79. return ret;
  80. #endif
  81. }
  82. static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
  83. {
  84. *pmdp = pmd;
  85. }
  86. static inline void native_pmd_clear(pmd_t *pmd)
  87. {
  88. native_set_pmd(pmd, native_make_pmd(0));
  89. }
  90. static inline void native_set_pud(pud_t *pudp, pud_t pud)
  91. {
  92. *pudp = pud;
  93. }
  94. static inline void native_pud_clear(pud_t *pud)
  95. {
  96. native_set_pud(pud, native_make_pud(0));
  97. }
  98. static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
  99. {
  100. *pgdp = pgd;
  101. }
  102. static inline void native_pgd_clear(pgd_t *pgd)
  103. {
  104. native_set_pgd(pgd, native_make_pgd(0));
  105. }
  106. #endif /* !__ASSEMBLY__ */
  107. #define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
  108. #define PMD_MASK (~(PMD_SIZE - 1))
  109. #define PUD_SIZE (_AC(1, UL) << PUD_SHIFT)
  110. #define PUD_MASK (~(PUD_SIZE - 1))
  111. #define PGDIR_SIZE (_AC(1, UL) << PGDIR_SHIFT)
  112. #define PGDIR_MASK (~(PGDIR_SIZE - 1))
  113. #define MAXMEM _AC(__AC(1, UL) << MAX_PHYSMEM_BITS, UL)
  114. #define VMALLOC_START _AC(0xffffc20000000000, UL)
  115. #define VMALLOC_END _AC(0xffffe1ffffffffff, UL)
  116. #define VMEMMAP_START _AC(0xffffe20000000000, UL)
  117. #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
  118. #define MODULES_END _AC(0xffffffffff000000, UL)
  119. #define MODULES_LEN (MODULES_END - MODULES_VADDR)
  120. #ifndef __ASSEMBLY__
  121. /*
  122. * Conversion functions: convert a page and protection to a page entry,
  123. * and a page entry and page directory to the page they refer to.
  124. */
  125. /*
  126. * Level 4 access.
  127. */
  128. static inline int pgd_large(pgd_t pgd) { return 0; }
  129. #define mk_kernel_pgd(address) __pgd((address) | _KERNPG_TABLE)
  130. /* PUD - Level3 access */
  131. /* PMD - Level 2 access */
  132. #define pte_to_pgoff(pte) ((pte_val((pte)) & PHYSICAL_PAGE_MASK) >> PAGE_SHIFT)
  133. #define pgoff_to_pte(off) ((pte_t) { .pte = ((off) << PAGE_SHIFT) | \
  134. _PAGE_FILE })
  135. #define PTE_FILE_MAX_BITS __PHYSICAL_MASK_SHIFT
  136. /* PTE - Level 1 access. */
  137. /* x86-64 always has all page tables mapped. */
  138. #define pte_offset_map(dir, address) pte_offset_kernel((dir), (address))
  139. #define pte_offset_map_nested(dir, address) pte_offset_kernel((dir), (address))
  140. #define pte_unmap(pte) /* NOP */
  141. #define pte_unmap_nested(pte) /* NOP */
  142. #define update_mmu_cache(vma, address, pte) do { } while (0)
  143. extern int direct_gbpages;
  144. /* Encode and de-code a swap entry */
  145. #if _PAGE_BIT_FILE < _PAGE_BIT_PROTNONE
  146. #define SWP_TYPE_BITS (_PAGE_BIT_FILE - _PAGE_BIT_PRESENT - 1)
  147. #define SWP_OFFSET_SHIFT (_PAGE_BIT_PROTNONE + 1)
  148. #else
  149. #define SWP_TYPE_BITS (_PAGE_BIT_PROTNONE - _PAGE_BIT_PRESENT - 1)
  150. #define SWP_OFFSET_SHIFT (_PAGE_BIT_FILE + 1)
  151. #endif
  152. #define MAX_SWAPFILES_CHECK() BUILD_BUG_ON(MAX_SWAPFILES_SHIFT > SWP_TYPE_BITS)
  153. #define __swp_type(x) (((x).val >> (_PAGE_BIT_PRESENT + 1)) \
  154. & ((1U << SWP_TYPE_BITS) - 1))
  155. #define __swp_offset(x) ((x).val >> SWP_OFFSET_SHIFT)
  156. #define __swp_entry(type, offset) ((swp_entry_t) { \
  157. ((type) << (_PAGE_BIT_PRESENT + 1)) \
  158. | ((offset) << SWP_OFFSET_SHIFT) })
  159. #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val((pte)) })
  160. #define __swp_entry_to_pte(x) ((pte_t) { .pte = (x).val })
  161. extern int kern_addr_valid(unsigned long addr);
  162. extern void cleanup_highmap(void);
  163. #define HAVE_ARCH_UNMAPPED_AREA
  164. #define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
  165. #define pgtable_cache_init() do { } while (0)
  166. #define check_pgt_cache() do { } while (0)
  167. #define PAGE_AGP PAGE_KERNEL_NOCACHE
  168. #define HAVE_PAGE_AGP 1
  169. /* fs/proc/kcore.c */
  170. #define kc_vaddr_to_offset(v) ((v) & __VIRTUAL_MASK)
  171. #define kc_offset_to_vaddr(o) \
  172. (((o) & (1UL << (__VIRTUAL_MASK_SHIFT - 1))) \
  173. ? ((o) | ~__VIRTUAL_MASK) \
  174. : (o))
  175. #define __HAVE_ARCH_PTE_SAME
  176. #endif /* !__ASSEMBLY__ */
  177. #endif /* _ASM_X86_PGTABLE_64_H */