pgtable_64.h 4.6 KB

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