pgtable-3level.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * Copyright 2003 PathScale Inc
  3. * Derived from include/asm-i386/pgtable.h
  4. * Licensed under the GPL
  5. */
  6. #ifndef __UM_PGTABLE_3LEVEL_H
  7. #define __UM_PGTABLE_3LEVEL_H
  8. #define __ARCH_USE_5LEVEL_HACK
  9. #include <asm-generic/pgtable-nopud.h>
  10. /* PGDIR_SHIFT determines what a third-level page table entry can map */
  11. #ifdef CONFIG_64BIT
  12. #define PGDIR_SHIFT 30
  13. #else
  14. #define PGDIR_SHIFT 31
  15. #endif
  16. #define PGDIR_SIZE (1UL << PGDIR_SHIFT)
  17. #define PGDIR_MASK (~(PGDIR_SIZE-1))
  18. /* PMD_SHIFT determines the size of the area a second-level page table can
  19. * map
  20. */
  21. #define PMD_SHIFT 21
  22. #define PMD_SIZE (1UL << PMD_SHIFT)
  23. #define PMD_MASK (~(PMD_SIZE-1))
  24. /*
  25. * entries per page directory level
  26. */
  27. #define PTRS_PER_PTE 512
  28. #ifdef CONFIG_64BIT
  29. #define PTRS_PER_PMD 512
  30. #define PTRS_PER_PGD 512
  31. #else
  32. #define PTRS_PER_PMD 1024
  33. #define PTRS_PER_PGD 1024
  34. #endif
  35. #define USER_PTRS_PER_PGD ((TASK_SIZE + (PGDIR_SIZE - 1)) / PGDIR_SIZE)
  36. #define FIRST_USER_ADDRESS 0UL
  37. #define pte_ERROR(e) \
  38. printk("%s:%d: bad pte %p(%016lx).\n", __FILE__, __LINE__, &(e), \
  39. pte_val(e))
  40. #define pmd_ERROR(e) \
  41. printk("%s:%d: bad pmd %p(%016lx).\n", __FILE__, __LINE__, &(e), \
  42. pmd_val(e))
  43. #define pgd_ERROR(e) \
  44. printk("%s:%d: bad pgd %p(%016lx).\n", __FILE__, __LINE__, &(e), \
  45. pgd_val(e))
  46. #define pud_none(x) (!(pud_val(x) & ~_PAGE_NEWPAGE))
  47. #define pud_bad(x) ((pud_val(x) & (~PAGE_MASK & ~_PAGE_USER)) != _KERNPG_TABLE)
  48. #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
  49. #define pud_populate(mm, pud, pmd) \
  50. set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
  51. #ifdef CONFIG_64BIT
  52. #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
  53. #else
  54. #define set_pud(pudptr, pudval) (*(pudptr) = (pudval))
  55. #endif
  56. static inline int pgd_newpage(pgd_t pgd)
  57. {
  58. return(pgd_val(pgd) & _PAGE_NEWPAGE);
  59. }
  60. static inline void pgd_mkuptodate(pgd_t pgd) { pgd_val(pgd) &= ~_PAGE_NEWPAGE; }
  61. #ifdef CONFIG_64BIT
  62. #define set_pmd(pmdptr, pmdval) set_64bit((u64 *) (pmdptr), pmd_val(pmdval))
  63. #else
  64. #define set_pmd(pmdptr, pmdval) (*(pmdptr) = (pmdval))
  65. #endif
  66. struct mm_struct;
  67. extern pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address);
  68. static inline void pud_clear (pud_t *pud)
  69. {
  70. set_pud(pud, __pud(_PAGE_NEWPAGE));
  71. }
  72. #define pud_page(pud) phys_to_page(pud_val(pud) & PAGE_MASK)
  73. #define pud_page_vaddr(pud) ((unsigned long) __va(pud_val(pud) & PAGE_MASK))
  74. /* Find an entry in the second-level page table.. */
  75. #define pmd_offset(pud, address) ((pmd_t *) pud_page_vaddr(*(pud)) + \
  76. pmd_index(address))
  77. static inline unsigned long pte_pfn(pte_t pte)
  78. {
  79. return phys_to_pfn(pte_val(pte));
  80. }
  81. static inline pte_t pfn_pte(unsigned long page_nr, pgprot_t pgprot)
  82. {
  83. pte_t pte;
  84. phys_t phys = pfn_to_phys(page_nr);
  85. pte_set_val(pte, phys, pgprot);
  86. return pte;
  87. }
  88. static inline pmd_t pfn_pmd(unsigned long page_nr, pgprot_t pgprot)
  89. {
  90. return __pmd((page_nr << PAGE_SHIFT) | pgprot_val(pgprot));
  91. }
  92. #endif