pgtable.h 7.7 KB

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