pgtable.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. #ifndef _ASM_POWERPC_PGTABLE_H
  2. #define _ASM_POWERPC_PGTABLE_H
  3. #ifdef __KERNEL__
  4. #ifndef __ASSEMBLY__
  5. #include <asm/processor.h> /* For TASK_SIZE */
  6. #include <asm/mmu.h>
  7. #include <asm/page.h>
  8. struct mm_struct;
  9. #ifdef CONFIG_DEBUG_VM
  10. extern void assert_pte_locked(struct mm_struct *mm, unsigned long addr);
  11. #else /* CONFIG_DEBUG_VM */
  12. static inline void assert_pte_locked(struct mm_struct *mm, unsigned long addr)
  13. {
  14. }
  15. #endif /* !CONFIG_DEBUG_VM */
  16. #endif /* !__ASSEMBLY__ */
  17. #if defined(CONFIG_PPC64)
  18. # include <asm/pgtable-ppc64.h>
  19. #else
  20. # include <asm/pgtable-ppc32.h>
  21. #endif
  22. #ifndef __ASSEMBLY__
  23. /* Generic accessors to PTE bits */
  24. static inline int pte_write(pte_t pte) { return pte_val(pte) & _PAGE_RW; }
  25. static inline int pte_dirty(pte_t pte) { return pte_val(pte) & _PAGE_DIRTY; }
  26. static inline int pte_young(pte_t pte) { return pte_val(pte) & _PAGE_ACCESSED; }
  27. static inline int pte_file(pte_t pte) { return pte_val(pte) & _PAGE_FILE; }
  28. static inline int pte_special(pte_t pte) { return pte_val(pte) & _PAGE_SPECIAL; }
  29. static inline int pte_present(pte_t pte) { return pte_val(pte) & _PAGE_PRESENT; }
  30. static inline int pte_none(pte_t pte) { return (pte_val(pte) & ~_PTE_NONE_MASK) == 0; }
  31. static inline pgprot_t pte_pgprot(pte_t pte) { return __pgprot(pte_val(pte) & PAGE_PROT_BITS); }
  32. /* Conversion functions: convert a page and protection to a page entry,
  33. * and a page entry and page directory to the page they refer to.
  34. *
  35. * Even if PTEs can be unsigned long long, a PFN is always an unsigned
  36. * long for now.
  37. */
  38. static inline pte_t pfn_pte(unsigned long pfn, pgprot_t pgprot) {
  39. return __pte(((pte_basic_t)(pfn) << PTE_RPN_SHIFT) |
  40. pgprot_val(pgprot)); }
  41. static inline unsigned long pte_pfn(pte_t pte) {
  42. return pte_val(pte) >> PTE_RPN_SHIFT; }
  43. /* Keep these as a macros to avoid include dependency mess */
  44. #define pte_page(x) pfn_to_page(pte_pfn(x))
  45. #define mk_pte(page, pgprot) pfn_pte(page_to_pfn(page), (pgprot))
  46. /* Generic modifiers for PTE bits */
  47. static inline pte_t pte_wrprotect(pte_t pte) {
  48. pte_val(pte) &= ~(_PAGE_RW | _PAGE_HWWRITE); return pte; }
  49. static inline pte_t pte_mkclean(pte_t pte) {
  50. pte_val(pte) &= ~(_PAGE_DIRTY | _PAGE_HWWRITE); return pte; }
  51. static inline pte_t pte_mkold(pte_t pte) {
  52. pte_val(pte) &= ~_PAGE_ACCESSED; return pte; }
  53. static inline pte_t pte_mkwrite(pte_t pte) {
  54. pte_val(pte) |= _PAGE_RW; return pte; }
  55. static inline pte_t pte_mkdirty(pte_t pte) {
  56. pte_val(pte) |= _PAGE_DIRTY; return pte; }
  57. static inline pte_t pte_mkyoung(pte_t pte) {
  58. pte_val(pte) |= _PAGE_ACCESSED; return pte; }
  59. static inline pte_t pte_mkspecial(pte_t pte) {
  60. pte_val(pte) |= _PAGE_SPECIAL; return pte; }
  61. static inline pte_t pte_mkhuge(pte_t pte) {
  62. return pte; }
  63. static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
  64. {
  65. pte_val(pte) = (pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot);
  66. return pte;
  67. }
  68. /* Insert a PTE, top-level function is out of line. It uses an inline
  69. * low level function in the respective pgtable-* files
  70. */
  71. extern void set_pte_at(struct mm_struct *mm, unsigned long addr, pte_t *ptep,
  72. pte_t pte);
  73. /* This low level function performs the actual PTE insertion
  74. * Setting the PTE depends on the MMU type and other factors. It's
  75. * an horrible mess that I'm not going to try to clean up now but
  76. * I'm keeping it in one place rather than spread around
  77. */
  78. static inline void __set_pte_at(struct mm_struct *mm, unsigned long addr,
  79. pte_t *ptep, pte_t pte, int percpu)
  80. {
  81. #if defined(CONFIG_PPC_STD_MMU_32) && defined(CONFIG_SMP) && !defined(CONFIG_PTE_64BIT)
  82. /* First case is 32-bit Hash MMU in SMP mode with 32-bit PTEs. We use the
  83. * helper pte_update() which does an atomic update. We need to do that
  84. * because a concurrent invalidation can clear _PAGE_HASHPTE. If it's a
  85. * per-CPU PTE such as a kmap_atomic, we do a simple update preserving
  86. * the hash bits instead (ie, same as the non-SMP case)
  87. */
  88. if (percpu)
  89. *ptep = __pte((pte_val(*ptep) & _PAGE_HASHPTE)
  90. | (pte_val(pte) & ~_PAGE_HASHPTE));
  91. else
  92. pte_update(ptep, ~_PAGE_HASHPTE, pte_val(pte));
  93. #elif defined(CONFIG_PPC32) && defined(CONFIG_PTE_64BIT)
  94. /* Second case is 32-bit with 64-bit PTE. In this case, we
  95. * can just store as long as we do the two halves in the right order
  96. * with a barrier in between. This is possible because we take care,
  97. * in the hash code, to pre-invalidate if the PTE was already hashed,
  98. * which synchronizes us with any concurrent invalidation.
  99. * In the percpu case, we also fallback to the simple update preserving
  100. * the hash bits
  101. */
  102. if (percpu) {
  103. *ptep = __pte((pte_val(*ptep) & _PAGE_HASHPTE)
  104. | (pte_val(pte) & ~_PAGE_HASHPTE));
  105. return;
  106. }
  107. #if _PAGE_HASHPTE != 0
  108. if (pte_val(*ptep) & _PAGE_HASHPTE)
  109. flush_hash_entry(mm, ptep, addr);
  110. #endif
  111. __asm__ __volatile__("\
  112. stw%U0%X0 %2,%0\n\
  113. eieio\n\
  114. stw%U0%X0 %L2,%1"
  115. : "=m" (*ptep), "=m" (*((unsigned char *)ptep+4))
  116. : "r" (pte) : "memory");
  117. #elif defined(CONFIG_PPC_STD_MMU_32)
  118. /* Third case is 32-bit hash table in UP mode, we need to preserve
  119. * the _PAGE_HASHPTE bit since we may not have invalidated the previous
  120. * translation in the hash yet (done in a subsequent flush_tlb_xxx())
  121. * and see we need to keep track that this PTE needs invalidating
  122. */
  123. *ptep = __pte((pte_val(*ptep) & _PAGE_HASHPTE)
  124. | (pte_val(pte) & ~_PAGE_HASHPTE));
  125. #else
  126. /* Anything else just stores the PTE normally. That covers all 64-bit
  127. * cases, and 32-bit non-hash with 32-bit PTEs.
  128. */
  129. *ptep = pte;
  130. #endif
  131. }
  132. #define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
  133. extern int ptep_set_access_flags(struct vm_area_struct *vma, unsigned long address,
  134. pte_t *ptep, pte_t entry, int dirty);
  135. /*
  136. * Macro to mark a page protection value as "uncacheable".
  137. */
  138. #define _PAGE_CACHE_CTL (_PAGE_COHERENT | _PAGE_GUARDED | _PAGE_NO_CACHE | \
  139. _PAGE_WRITETHRU)
  140. #define pgprot_noncached(prot) (__pgprot((pgprot_val(prot) & ~_PAGE_CACHE_CTL) | \
  141. _PAGE_NO_CACHE | _PAGE_GUARDED))
  142. #define pgprot_noncached_wc(prot) (__pgprot((pgprot_val(prot) & ~_PAGE_CACHE_CTL) | \
  143. _PAGE_NO_CACHE))
  144. #define pgprot_cached(prot) (__pgprot((pgprot_val(prot) & ~_PAGE_CACHE_CTL) | \
  145. _PAGE_COHERENT))
  146. #define pgprot_cached_wthru(prot) (__pgprot((pgprot_val(prot) & ~_PAGE_CACHE_CTL) | \
  147. _PAGE_COHERENT | _PAGE_WRITETHRU))
  148. #define pgprot_cached_noncoherent(prot) \
  149. (__pgprot(pgprot_val(prot) & ~_PAGE_CACHE_CTL))
  150. #define pgprot_writecombine pgprot_noncached_wc
  151. struct file;
  152. extern pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
  153. unsigned long size, pgprot_t vma_prot);
  154. #define __HAVE_PHYS_MEM_ACCESS_PROT
  155. /*
  156. * ZERO_PAGE is a global shared page that is always zero: used
  157. * for zero-mapped memory areas etc..
  158. */
  159. extern unsigned long empty_zero_page[];
  160. #define ZERO_PAGE(vaddr) (virt_to_page(empty_zero_page))
  161. extern pgd_t swapper_pg_dir[];
  162. extern void paging_init(void);
  163. /*
  164. * kern_addr_valid is intended to indicate whether an address is a valid
  165. * kernel address. Most 32-bit archs define it as always true (like this)
  166. * but most 64-bit archs actually perform a test. What should we do here?
  167. */
  168. #define kern_addr_valid(addr) (1)
  169. #define io_remap_pfn_range(vma, vaddr, pfn, size, prot) \
  170. remap_pfn_range(vma, vaddr, pfn, size, prot)
  171. #include <asm-generic/pgtable.h>
  172. /*
  173. * This gets called at the end of handling a page fault, when
  174. * the kernel has put a new PTE into the page table for the process.
  175. * We use it to ensure coherency between the i-cache and d-cache
  176. * for the page which has just been mapped in.
  177. * On machines which use an MMU hash table, we use this to put a
  178. * corresponding HPTE into the hash table ahead of time, instead of
  179. * waiting for the inevitable extra hash-table miss exception.
  180. */
  181. extern void update_mmu_cache(struct vm_area_struct *, unsigned long, pte_t *);
  182. extern int gup_hugepd(hugepd_t *hugepd, unsigned pdshift, unsigned long addr,
  183. unsigned long end, int write, struct page **pages, int *nr);
  184. #endif /* __ASSEMBLY__ */
  185. #endif /* __KERNEL__ */
  186. #endif /* _ASM_POWERPC_PGTABLE_H */