pgtable-3level.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. #ifndef _I386_PGTABLE_3LEVEL_H
  2. #define _I386_PGTABLE_3LEVEL_H
  3. #include <asm-generic/pgtable-nopud.h>
  4. /*
  5. * Intel Physical Address Extension (PAE) Mode - three-level page
  6. * tables on PPro+ CPUs.
  7. *
  8. * Copyright (C) 1999 Ingo Molnar <mingo@redhat.com>
  9. */
  10. #define pte_ERROR(e) \
  11. printk("%s:%d: bad pte %p(%08lx%08lx).\n", __FILE__, __LINE__, &(e), (e).pte_high, (e).pte_low)
  12. #define pmd_ERROR(e) \
  13. printk("%s:%d: bad pmd %p(%016Lx).\n", __FILE__, __LINE__, &(e), pmd_val(e))
  14. #define pgd_ERROR(e) \
  15. printk("%s:%d: bad pgd %p(%016Lx).\n", __FILE__, __LINE__, &(e), pgd_val(e))
  16. #define pud_none(pud) 0
  17. #define pud_bad(pud) 0
  18. #define pud_present(pud) 1
  19. /*
  20. * Is the pte executable?
  21. */
  22. static inline int pte_x(pte_t pte)
  23. {
  24. return !(pte_val(pte) & _PAGE_NX);
  25. }
  26. /*
  27. * All present user-pages with !NX bit are user-executable:
  28. */
  29. static inline int pte_exec(pte_t pte)
  30. {
  31. return pte_user(pte) && pte_x(pte);
  32. }
  33. /*
  34. * All present pages with !NX bit are kernel-executable:
  35. */
  36. static inline int pte_exec_kernel(pte_t pte)
  37. {
  38. return pte_x(pte);
  39. }
  40. /* Rules for using set_pte: the pte being assigned *must* be
  41. * either not present or in a state where the hardware will
  42. * not attempt to update the pte. In places where this is
  43. * not possible, use pte_get_and_clear to obtain the old pte
  44. * value and then use set_pte to update it. -ben
  45. */
  46. static inline void set_pte(pte_t *ptep, pte_t pte)
  47. {
  48. ptep->pte_high = pte.pte_high;
  49. smp_wmb();
  50. ptep->pte_low = pte.pte_low;
  51. }
  52. #define set_pte_at(mm,addr,ptep,pteval) set_pte(ptep,pteval)
  53. /*
  54. * Since this is only called on user PTEs, and the page fault handler
  55. * must handle the already racy situation of simultaneous page faults,
  56. * we are justified in merely clearing the PTE present bit, followed
  57. * by a set. The ordering here is important.
  58. */
  59. static inline void set_pte_present(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte)
  60. {
  61. ptep->pte_low = 0;
  62. smp_wmb();
  63. ptep->pte_high = pte.pte_high;
  64. smp_wmb();
  65. ptep->pte_low = pte.pte_low;
  66. }
  67. #define set_pte_atomic(pteptr,pteval) \
  68. set_64bit((unsigned long long *)(pteptr),pte_val(pteval))
  69. #define set_pmd(pmdptr,pmdval) \
  70. set_64bit((unsigned long long *)(pmdptr),pmd_val(pmdval))
  71. #define set_pud(pudptr,pudval) \
  72. (*(pudptr) = (pudval))
  73. /*
  74. * Pentium-II erratum A13: in PAE mode we explicitly have to flush
  75. * the TLB via cr3 if the top-level pgd is changed...
  76. * We do not let the generic code free and clear pgd entries due to
  77. * this erratum.
  78. */
  79. static inline void pud_clear (pud_t * pud) { }
  80. #define pud_page(pud) \
  81. ((struct page *) __va(pud_val(pud) & PAGE_MASK))
  82. #define pud_page_vaddr(pud) \
  83. ((unsigned long) __va(pud_val(pud) & PAGE_MASK))
  84. /* Find an entry in the second-level page table.. */
  85. #define pmd_offset(pud, address) ((pmd_t *) pud_page(*(pud)) + \
  86. pmd_index(address))
  87. /*
  88. * For PTEs and PDEs, we must clear the P-bit first when clearing a page table
  89. * entry, so clear the bottom half first and enforce ordering with a compiler
  90. * barrier.
  91. */
  92. static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
  93. {
  94. ptep->pte_low = 0;
  95. smp_wmb();
  96. ptep->pte_high = 0;
  97. }
  98. static inline void pmd_clear(pmd_t *pmd)
  99. {
  100. u32 *tmp = (u32 *)pmd;
  101. *tmp = 0;
  102. smp_wmb();
  103. *(tmp + 1) = 0;
  104. }
  105. #define __HAVE_ARCH_PTEP_GET_AND_CLEAR
  106. static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
  107. {
  108. pte_t res;
  109. /* xchg acts as a barrier before the setting of the high bits */
  110. res.pte_low = xchg(&ptep->pte_low, 0);
  111. res.pte_high = ptep->pte_high;
  112. ptep->pte_high = 0;
  113. return res;
  114. }
  115. #define __HAVE_ARCH_PTE_SAME
  116. static inline int pte_same(pte_t a, pte_t b)
  117. {
  118. return a.pte_low == b.pte_low && a.pte_high == b.pte_high;
  119. }
  120. #define pte_page(x) pfn_to_page(pte_pfn(x))
  121. static inline int pte_none(pte_t pte)
  122. {
  123. return !pte.pte_low && !pte.pte_high;
  124. }
  125. static inline unsigned long pte_pfn(pte_t pte)
  126. {
  127. return (pte.pte_low >> PAGE_SHIFT) |
  128. (pte.pte_high << (32 - PAGE_SHIFT));
  129. }
  130. extern unsigned long long __supported_pte_mask;
  131. static inline pte_t pfn_pte(unsigned long page_nr, pgprot_t pgprot)
  132. {
  133. pte_t pte;
  134. pte.pte_high = (page_nr >> (32 - PAGE_SHIFT)) | \
  135. (pgprot_val(pgprot) >> 32);
  136. pte.pte_high &= (__supported_pte_mask >> 32);
  137. pte.pte_low = ((page_nr << PAGE_SHIFT) | pgprot_val(pgprot)) & \
  138. __supported_pte_mask;
  139. return pte;
  140. }
  141. static inline pmd_t pfn_pmd(unsigned long page_nr, pgprot_t pgprot)
  142. {
  143. return __pmd((((unsigned long long)page_nr << PAGE_SHIFT) | \
  144. pgprot_val(pgprot)) & __supported_pte_mask);
  145. }
  146. /*
  147. * Bits 0, 6 and 7 are taken in the low part of the pte,
  148. * put the 32 bits of offset into the high part.
  149. */
  150. #define pte_to_pgoff(pte) ((pte).pte_high)
  151. #define pgoff_to_pte(off) ((pte_t) { _PAGE_FILE, (off) })
  152. #define PTE_FILE_MAX_BITS 32
  153. /* Encode and de-code a swap entry */
  154. #define __swp_type(x) (((x).val) & 0x1f)
  155. #define __swp_offset(x) ((x).val >> 5)
  156. #define __swp_entry(type, offset) ((swp_entry_t){(type) | (offset) << 5})
  157. #define __pte_to_swp_entry(pte) ((swp_entry_t){ (pte).pte_high })
  158. #define __swp_entry_to_pte(x) ((pte_t){ 0, (x).val })
  159. #define __pmd_free_tlb(tlb, x) do { } while (0)
  160. #define vmalloc_sync_all() ((void)0)
  161. #endif /* _I386_PGTABLE_3LEVEL_H */