pgtable_64.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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. #include <asm/pda.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. #define SHARED_KERNEL_PMD 0
  23. /*
  24. * PGDIR_SHIFT determines what a top-level page table entry can map
  25. */
  26. #define PGDIR_SHIFT 39
  27. #define PTRS_PER_PGD 512
  28. /*
  29. * 3rd level page
  30. */
  31. #define PUD_SHIFT 30
  32. #define PTRS_PER_PUD 512
  33. /*
  34. * PMD_SHIFT determines the size of the area a middle-level
  35. * page table can map
  36. */
  37. #define PMD_SHIFT 21
  38. #define PTRS_PER_PMD 512
  39. /*
  40. * entries per page directory level
  41. */
  42. #define PTRS_PER_PTE 512
  43. #ifndef __ASSEMBLY__
  44. #define pte_ERROR(e) \
  45. printk("%s:%d: bad pte %p(%016lx).\n", \
  46. __FILE__, __LINE__, &(e), pte_val(e))
  47. #define pmd_ERROR(e) \
  48. printk("%s:%d: bad pmd %p(%016lx).\n", \
  49. __FILE__, __LINE__, &(e), pmd_val(e))
  50. #define pud_ERROR(e) \
  51. printk("%s:%d: bad pud %p(%016lx).\n", \
  52. __FILE__, __LINE__, &(e), pud_val(e))
  53. #define pgd_ERROR(e) \
  54. printk("%s:%d: bad pgd %p(%016lx).\n", \
  55. __FILE__, __LINE__, &(e), pgd_val(e))
  56. #define pgd_none(x) (!pgd_val(x))
  57. #define pud_none(x) (!pud_val(x))
  58. struct mm_struct;
  59. void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte);
  60. static inline void native_pte_clear(struct mm_struct *mm, unsigned long addr,
  61. pte_t *ptep)
  62. {
  63. *ptep = native_make_pte(0);
  64. }
  65. static inline void native_set_pte(pte_t *ptep, pte_t pte)
  66. {
  67. *ptep = pte;
  68. }
  69. static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
  70. {
  71. native_set_pte(ptep, pte);
  72. }
  73. static inline pte_t native_ptep_get_and_clear(pte_t *xp)
  74. {
  75. #ifdef CONFIG_SMP
  76. return native_make_pte(xchg(&xp->pte, 0));
  77. #else
  78. /* native_local_ptep_get_and_clear,
  79. but duplicated because of cyclic dependency */
  80. pte_t ret = *xp;
  81. native_pte_clear(NULL, 0, xp);
  82. return ret;
  83. #endif
  84. }
  85. static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
  86. {
  87. *pmdp = pmd;
  88. }
  89. static inline void native_pmd_clear(pmd_t *pmd)
  90. {
  91. native_set_pmd(pmd, native_make_pmd(0));
  92. }
  93. static inline void native_set_pud(pud_t *pudp, pud_t pud)
  94. {
  95. *pudp = pud;
  96. }
  97. static inline void native_pud_clear(pud_t *pud)
  98. {
  99. native_set_pud(pud, native_make_pud(0));
  100. }
  101. static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
  102. {
  103. *pgdp = pgd;
  104. }
  105. static inline void native_pgd_clear(pgd_t *pgd)
  106. {
  107. native_set_pgd(pgd, native_make_pgd(0));
  108. }
  109. #define pte_same(a, b) ((a).pte == (b).pte)
  110. #endif /* !__ASSEMBLY__ */
  111. #define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
  112. #define PMD_MASK (~(PMD_SIZE - 1))
  113. #define PUD_SIZE (_AC(1, UL) << PUD_SHIFT)
  114. #define PUD_MASK (~(PUD_SIZE - 1))
  115. #define PGDIR_SIZE (_AC(1, UL) << PGDIR_SHIFT)
  116. #define PGDIR_MASK (~(PGDIR_SIZE - 1))
  117. #define MAXMEM _AC(0x00003fffffffffff, UL)
  118. #define VMALLOC_START _AC(0xffffc20000000000, UL)
  119. #define VMALLOC_END _AC(0xffffe1ffffffffff, UL)
  120. #define VMEMMAP_START _AC(0xffffe20000000000, UL)
  121. #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
  122. #define MODULES_END _AC(0xffffffffff000000, UL)
  123. #define MODULES_LEN (MODULES_END - MODULES_VADDR)
  124. #ifndef __ASSEMBLY__
  125. static inline int pgd_bad(pgd_t pgd)
  126. {
  127. return (pgd_val(pgd) & ~(PTE_PFN_MASK | _PAGE_USER)) != _KERNPG_TABLE;
  128. }
  129. static inline int pud_bad(pud_t pud)
  130. {
  131. return (pud_val(pud) & ~(PTE_PFN_MASK | _PAGE_USER)) != _KERNPG_TABLE;
  132. }
  133. static inline int pmd_bad(pmd_t pmd)
  134. {
  135. return (pmd_val(pmd) & ~(PTE_PFN_MASK | _PAGE_USER)) != _KERNPG_TABLE;
  136. }
  137. #define pte_none(x) (!pte_val((x)))
  138. #define pte_present(x) (pte_val((x)) & (_PAGE_PRESENT | _PAGE_PROTNONE))
  139. #define pages_to_mb(x) ((x) >> (20 - PAGE_SHIFT)) /* FIXME: is this right? */
  140. /*
  141. * Macro to mark a page protection value as "uncacheable".
  142. */
  143. #define pgprot_noncached(prot) \
  144. (__pgprot(pgprot_val((prot)) | _PAGE_PCD | _PAGE_PWT))
  145. /*
  146. * Conversion functions: convert a page and protection to a page entry,
  147. * and a page entry and page directory to the page they refer to.
  148. */
  149. /*
  150. * Level 4 access.
  151. */
  152. #define pgd_page_vaddr(pgd) \
  153. ((unsigned long)__va((unsigned long)pgd_val((pgd)) & PTE_PFN_MASK))
  154. #define pgd_page(pgd) (pfn_to_page(pgd_val((pgd)) >> PAGE_SHIFT))
  155. #define pgd_present(pgd) (pgd_val(pgd) & _PAGE_PRESENT)
  156. static inline int pgd_large(pgd_t pgd) { return 0; }
  157. #define mk_kernel_pgd(address) __pgd((address) | _KERNPG_TABLE)
  158. /* PUD - Level3 access */
  159. /* to find an entry in a page-table-directory. */
  160. #define pud_page_vaddr(pud) \
  161. ((unsigned long)__va(pud_val((pud)) & PHYSICAL_PAGE_MASK))
  162. #define pud_page(pud) (pfn_to_page(pud_val((pud)) >> PAGE_SHIFT))
  163. #define pud_index(address) (((address) >> PUD_SHIFT) & (PTRS_PER_PUD - 1))
  164. #define pud_offset(pgd, address) \
  165. ((pud_t *)pgd_page_vaddr(*(pgd)) + pud_index((address)))
  166. #define pud_present(pud) (pud_val((pud)) & _PAGE_PRESENT)
  167. static inline int pud_large(pud_t pte)
  168. {
  169. return (pud_val(pte) & (_PAGE_PSE | _PAGE_PRESENT)) ==
  170. (_PAGE_PSE | _PAGE_PRESENT);
  171. }
  172. /* PMD - Level 2 access */
  173. #define pmd_page_vaddr(pmd) ((unsigned long) __va(pmd_val((pmd)) & PTE_PFN_MASK))
  174. #define pmd_page(pmd) (pfn_to_page(pmd_val((pmd)) >> PAGE_SHIFT))
  175. #define pmd_index(address) (((address) >> PMD_SHIFT) & (PTRS_PER_PMD - 1))
  176. #define pmd_offset(dir, address) ((pmd_t *)pud_page_vaddr(*(dir)) + \
  177. pmd_index(address))
  178. #define pmd_none(x) (!pmd_val((x)))
  179. #define pmd_present(x) (pmd_val((x)) & _PAGE_PRESENT)
  180. #define pfn_pmd(nr, prot) (__pmd(((nr) << PAGE_SHIFT) | pgprot_val((prot))))
  181. #define pmd_pfn(x) ((pmd_val((x)) & __PHYSICAL_MASK) >> PAGE_SHIFT)
  182. #define pte_to_pgoff(pte) ((pte_val((pte)) & PHYSICAL_PAGE_MASK) >> PAGE_SHIFT)
  183. #define pgoff_to_pte(off) ((pte_t) { .pte = ((off) << PAGE_SHIFT) | \
  184. _PAGE_FILE })
  185. #define PTE_FILE_MAX_BITS __PHYSICAL_MASK_SHIFT
  186. /* PTE - Level 1 access. */
  187. /* page, protection -> pte */
  188. #define mk_pte(page, pgprot) pfn_pte(page_to_pfn((page)), (pgprot))
  189. #define pte_index(address) (((address) >> PAGE_SHIFT) & (PTRS_PER_PTE - 1))
  190. #define pte_offset_kernel(dir, address) ((pte_t *) pmd_page_vaddr(*(dir)) + \
  191. pte_index((address)))
  192. /* x86-64 always has all page tables mapped. */
  193. #define pte_offset_map(dir, address) pte_offset_kernel((dir), (address))
  194. #define pte_offset_map_nested(dir, address) pte_offset_kernel((dir), (address))
  195. #define pte_unmap(pte) /* NOP */
  196. #define pte_unmap_nested(pte) /* NOP */
  197. #define update_mmu_cache(vma, address, pte) do { } while (0)
  198. extern int direct_gbpages;
  199. /* Encode and de-code a swap entry */
  200. #define __swp_type(x) (((x).val >> 1) & 0x3f)
  201. #define __swp_offset(x) ((x).val >> 8)
  202. #define __swp_entry(type, offset) ((swp_entry_t) { ((type) << 1) | \
  203. ((offset) << 8) })
  204. #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val((pte)) })
  205. #define __swp_entry_to_pte(x) ((pte_t) { .pte = (x).val })
  206. extern int kern_addr_valid(unsigned long addr);
  207. extern void cleanup_highmap(void);
  208. #define io_remap_pfn_range(vma, vaddr, pfn, size, prot) \
  209. remap_pfn_range(vma, vaddr, pfn, size, prot)
  210. #define HAVE_ARCH_UNMAPPED_AREA
  211. #define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
  212. #define pgtable_cache_init() do { } while (0)
  213. #define check_pgt_cache() do { } while (0)
  214. #define PAGE_AGP PAGE_KERNEL_NOCACHE
  215. #define HAVE_PAGE_AGP 1
  216. /* fs/proc/kcore.c */
  217. #define kc_vaddr_to_offset(v) ((v) & __VIRTUAL_MASK)
  218. #define kc_offset_to_vaddr(o) \
  219. (((o) & (1UL << (__VIRTUAL_MASK_SHIFT - 1))) \
  220. ? ((o) | ~__VIRTUAL_MASK) \
  221. : (o))
  222. #define __HAVE_ARCH_PTE_SAME
  223. #endif /* !__ASSEMBLY__ */
  224. #endif /* ASM_X86__PGTABLE_64_H */