pgtable-3level.h 2.6 KB

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