pgtable_64.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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 void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
  49. {
  50. *pmdp = pmd;
  51. }
  52. static inline void native_pmd_clear(pmd_t *pmd)
  53. {
  54. native_set_pmd(pmd, native_make_pmd(0));
  55. }
  56. static inline pte_t native_ptep_get_and_clear(pte_t *xp)
  57. {
  58. #ifdef CONFIG_SMP
  59. return native_make_pte(xchg(&xp->pte, 0));
  60. #else
  61. /* native_local_ptep_get_and_clear,
  62. but duplicated because of cyclic dependency */
  63. pte_t ret = *xp;
  64. native_pte_clear(NULL, 0, xp);
  65. return ret;
  66. #endif
  67. }
  68. static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
  69. {
  70. #ifdef CONFIG_SMP
  71. return native_make_pmd(xchg(&xp->pmd, 0));
  72. #else
  73. /* native_local_pmdp_get_and_clear,
  74. but duplicated because of cyclic dependency */
  75. pmd_t ret = *xp;
  76. native_pmd_clear(xp);
  77. return ret;
  78. #endif
  79. }
  80. static inline void native_set_pud(pud_t *pudp, pud_t pud)
  81. {
  82. *pudp = pud;
  83. }
  84. static inline void native_pud_clear(pud_t *pud)
  85. {
  86. native_set_pud(pud, native_make_pud(0));
  87. }
  88. static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
  89. {
  90. *pgdp = pgd;
  91. }
  92. static inline void native_pgd_clear(pgd_t *pgd)
  93. {
  94. native_set_pgd(pgd, native_make_pgd(0));
  95. }
  96. extern void sync_global_pgds(unsigned long start, unsigned long end);
  97. /*
  98. * Conversion functions: convert a page and protection to a page entry,
  99. * and a page entry and page directory to the page they refer to.
  100. */
  101. /*
  102. * Level 4 access.
  103. */
  104. static inline int pgd_large(pgd_t pgd) { return 0; }
  105. #define mk_kernel_pgd(address) __pgd((address) | _KERNPG_TABLE)
  106. /* PUD - Level3 access */
  107. /* PMD - Level 2 access */
  108. #define pte_to_pgoff(pte) ((pte_val((pte)) & PHYSICAL_PAGE_MASK) >> PAGE_SHIFT)
  109. #define pgoff_to_pte(off) ((pte_t) { .pte = ((off) << PAGE_SHIFT) | \
  110. _PAGE_FILE })
  111. #define PTE_FILE_MAX_BITS __PHYSICAL_MASK_SHIFT
  112. /* PTE - Level 1 access. */
  113. /* x86-64 always has all page tables mapped. */
  114. #define pte_offset_map(dir, address) pte_offset_kernel((dir), (address))
  115. #define pte_unmap(pte) ((void)(pte))/* NOP */
  116. #define update_mmu_cache(vma, address, ptep) do { } while (0)
  117. /* Encode and de-code a swap entry */
  118. #if _PAGE_BIT_FILE < _PAGE_BIT_PROTNONE
  119. #define SWP_TYPE_BITS (_PAGE_BIT_FILE - _PAGE_BIT_PRESENT - 1)
  120. #define SWP_OFFSET_SHIFT (_PAGE_BIT_PROTNONE + 1)
  121. #else
  122. #define SWP_TYPE_BITS (_PAGE_BIT_PROTNONE - _PAGE_BIT_PRESENT - 1)
  123. #define SWP_OFFSET_SHIFT (_PAGE_BIT_FILE + 1)
  124. #endif
  125. #define MAX_SWAPFILES_CHECK() BUILD_BUG_ON(MAX_SWAPFILES_SHIFT > SWP_TYPE_BITS)
  126. #define __swp_type(x) (((x).val >> (_PAGE_BIT_PRESENT + 1)) \
  127. & ((1U << SWP_TYPE_BITS) - 1))
  128. #define __swp_offset(x) ((x).val >> SWP_OFFSET_SHIFT)
  129. #define __swp_entry(type, offset) ((swp_entry_t) { \
  130. ((type) << (_PAGE_BIT_PRESENT + 1)) \
  131. | ((offset) << SWP_OFFSET_SHIFT) })
  132. #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val((pte)) })
  133. #define __swp_entry_to_pte(x) ((pte_t) { .pte = (x).val })
  134. extern int kern_addr_valid(unsigned long addr);
  135. extern void cleanup_highmap(void);
  136. #define HAVE_ARCH_UNMAPPED_AREA
  137. #define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
  138. #define pgtable_cache_init() do { } while (0)
  139. #define check_pgt_cache() do { } while (0)
  140. #define PAGE_AGP PAGE_KERNEL_NOCACHE
  141. #define HAVE_PAGE_AGP 1
  142. /* fs/proc/kcore.c */
  143. #define kc_vaddr_to_offset(v) ((v) & __VIRTUAL_MASK)
  144. #define kc_offset_to_vaddr(o) ((o) | ~__VIRTUAL_MASK)
  145. #define __HAVE_ARCH_PTE_SAME
  146. #endif /* !__ASSEMBLY__ */
  147. #endif /* _ASM_X86_PGTABLE_64_H */