pgtable.h 8.0 KB

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