pgtable_64.h 4.5 KB

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