pgtable-3level.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. #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 FIRST_USER_ADDRESS 0UL
  36. #define pte_ERROR(e) \
  37. printk("%s:%d: bad pte %p(%016lx).\n", __FILE__, __LINE__, &(e), \
  38. pte_val(e))
  39. #define pmd_ERROR(e) \
  40. printk("%s:%d: bad pmd %p(%016lx).\n", __FILE__, __LINE__, &(e), \
  41. pmd_val(e))
  42. #define pgd_ERROR(e) \
  43. printk("%s:%d: bad pgd %p(%016lx).\n", __FILE__, __LINE__, &(e), \
  44. pgd_val(e))
  45. #define pud_none(x) (!(pud_val(x) & ~_PAGE_NEWPAGE))
  46. #define pud_bad(x) ((pud_val(x) & (~PAGE_MASK & ~_PAGE_USER)) != _KERNPG_TABLE)
  47. #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
  48. #define pud_populate(mm, pud, pmd) \
  49. set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
  50. #ifdef CONFIG_64BIT
  51. #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
  52. #else
  53. #define set_pud(pudptr, pudval) (*(pudptr) = (pudval))
  54. #endif
  55. static inline int pgd_newpage(pgd_t pgd)
  56. {
  57. return(pgd_val(pgd) & _PAGE_NEWPAGE);
  58. }
  59. static inline void pgd_mkuptodate(pgd_t pgd) { pgd_val(pgd) &= ~_PAGE_NEWPAGE; }
  60. #ifdef CONFIG_64BIT
  61. #define set_pmd(pmdptr, pmdval) set_64bit((u64 *) (pmdptr), pmd_val(pmdval))
  62. #else
  63. #define set_pmd(pmdptr, pmdval) (*(pmdptr) = (pmdval))
  64. #endif
  65. struct mm_struct;
  66. extern pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address);
  67. static inline void pud_clear (pud_t *pud)
  68. {
  69. set_pud(pud, __pud(_PAGE_NEWPAGE));
  70. }
  71. #define pud_page(pud) phys_to_page(pud_val(pud) & PAGE_MASK)
  72. #define pud_page_vaddr(pud) ((unsigned long) __va(pud_val(pud) & PAGE_MASK))
  73. /* Find an entry in the second-level page table.. */
  74. #define pmd_offset(pud, address) ((pmd_t *) pud_page_vaddr(*(pud)) + \
  75. pmd_index(address))
  76. static inline unsigned long pte_pfn(pte_t pte)
  77. {
  78. return phys_to_pfn(pte_val(pte));
  79. }
  80. static inline pte_t pfn_pte(pfn_t page_nr, pgprot_t pgprot)
  81. {
  82. pte_t pte;
  83. phys_t phys = pfn_to_phys(page_nr);
  84. pte_set_val(pte, phys, pgprot);
  85. return pte;
  86. }
  87. static inline pmd_t pfn_pmd(pfn_t page_nr, pgprot_t pgprot)
  88. {
  89. return __pmd((page_nr << PAGE_SHIFT) | pgprot_val(pgprot));
  90. }
  91. #endif