pgtable.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. #ifndef _ASM_POWERPC_PGTABLE_H
  2. #define _ASM_POWERPC_PGTABLE_H
  3. #ifdef __KERNEL__
  4. #ifndef __ASSEMBLY__
  5. #include <linux/mmdebug.h>
  6. #include <linux/mmzone.h>
  7. #include <asm/processor.h> /* For TASK_SIZE */
  8. #include <asm/mmu.h>
  9. #include <asm/page.h>
  10. struct mm_struct;
  11. #endif /* !__ASSEMBLY__ */
  12. #if defined(CONFIG_PPC64)
  13. # include <asm/pgtable-ppc64.h>
  14. #else
  15. # include <asm/pgtable-ppc32.h>
  16. #endif
  17. /*
  18. * We save the slot number & secondary bit in the second half of the
  19. * PTE page. We use the 8 bytes per each pte entry.
  20. */
  21. #define PTE_PAGE_HIDX_OFFSET (PTRS_PER_PTE * 8)
  22. #ifndef __ASSEMBLY__
  23. #include <asm/tlbflush.h>
  24. /* Generic accessors to PTE bits */
  25. static inline int pte_write(pte_t pte)
  26. { return (pte_val(pte) & (_PAGE_RW | _PAGE_RO)) != _PAGE_RO; }
  27. static inline int pte_dirty(pte_t pte) { return pte_val(pte) & _PAGE_DIRTY; }
  28. static inline int pte_young(pte_t pte) { return pte_val(pte) & _PAGE_ACCESSED; }
  29. static inline int pte_special(pte_t pte) { return pte_val(pte) & _PAGE_SPECIAL; }
  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. #ifdef CONFIG_NUMA_BALANCING
  33. /*
  34. * These work without NUMA balancing but the kernel does not care. See the
  35. * comment in include/asm-generic/pgtable.h . On powerpc, this will only
  36. * work for user pages and always return true for kernel pages.
  37. */
  38. static inline int pte_protnone(pte_t pte)
  39. {
  40. return (pte_val(pte) &
  41. (_PAGE_PRESENT | _PAGE_USER)) == _PAGE_PRESENT;
  42. }
  43. static inline int pmd_protnone(pmd_t pmd)
  44. {
  45. return pte_protnone(pmd_pte(pmd));
  46. }
  47. #endif /* CONFIG_NUMA_BALANCING */
  48. static inline int pte_present(pte_t pte)
  49. {
  50. return pte_val(pte) & _PAGE_PRESENT;
  51. }
  52. /* Conversion functions: convert a page and protection to a page entry,
  53. * and a page entry and page directory to the page they refer to.
  54. *
  55. * Even if PTEs can be unsigned long long, a PFN is always an unsigned
  56. * long for now.
  57. */
  58. static inline pte_t pfn_pte(unsigned long pfn, pgprot_t pgprot) {
  59. return __pte(((pte_basic_t)(pfn) << PTE_RPN_SHIFT) |
  60. pgprot_val(pgprot)); }
  61. static inline unsigned long pte_pfn(pte_t pte) {
  62. return pte_val(pte) >> PTE_RPN_SHIFT; }
  63. /* Keep these as a macros to avoid include dependency mess */
  64. #define pte_page(x) pfn_to_page(pte_pfn(x))
  65. #define mk_pte(page, pgprot) pfn_pte(page_to_pfn(page), (pgprot))
  66. /* Generic modifiers for PTE bits */
  67. static inline pte_t pte_wrprotect(pte_t pte) {
  68. pte_val(pte) &= ~(_PAGE_RW | _PAGE_HWWRITE);
  69. pte_val(pte) |= _PAGE_RO; return pte; }
  70. static inline pte_t pte_mkclean(pte_t pte) {
  71. pte_val(pte) &= ~(_PAGE_DIRTY | _PAGE_HWWRITE); return pte; }
  72. static inline pte_t pte_mkold(pte_t pte) {
  73. pte_val(pte) &= ~_PAGE_ACCESSED; return pte; }
  74. static inline pte_t pte_mkwrite(pte_t pte) {
  75. pte_val(pte) &= ~_PAGE_RO;
  76. pte_val(pte) |= _PAGE_RW; return pte; }
  77. static inline pte_t pte_mkdirty(pte_t pte) {
  78. pte_val(pte) |= _PAGE_DIRTY; return pte; }
  79. static inline pte_t pte_mkyoung(pte_t pte) {
  80. pte_val(pte) |= _PAGE_ACCESSED; return pte; }
  81. static inline pte_t pte_mkspecial(pte_t pte) {
  82. pte_val(pte) |= _PAGE_SPECIAL; return pte; }
  83. static inline pte_t pte_mkhuge(pte_t pte) {
  84. return pte; }
  85. static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
  86. {
  87. pte_val(pte) = (pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot);
  88. return pte;
  89. }
  90. /* Insert a PTE, top-level function is out of line. It uses an inline
  91. * low level function in the respective pgtable-* files
  92. */
  93. extern void set_pte_at(struct mm_struct *mm, unsigned long addr, pte_t *ptep,
  94. pte_t pte);
  95. /* This low level function performs the actual PTE insertion
  96. * Setting the PTE depends on the MMU type and other factors. It's
  97. * an horrible mess that I'm not going to try to clean up now but
  98. * I'm keeping it in one place rather than spread around
  99. */
  100. static inline void __set_pte_at(struct mm_struct *mm, unsigned long addr,
  101. pte_t *ptep, pte_t pte, int percpu)
  102. {
  103. #if defined(CONFIG_PPC_STD_MMU_32) && defined(CONFIG_SMP) && !defined(CONFIG_PTE_64BIT)
  104. /* First case is 32-bit Hash MMU in SMP mode with 32-bit PTEs. We use the
  105. * helper pte_update() which does an atomic update. We need to do that
  106. * because a concurrent invalidation can clear _PAGE_HASHPTE. If it's a
  107. * per-CPU PTE such as a kmap_atomic, we do a simple update preserving
  108. * the hash bits instead (ie, same as the non-SMP case)
  109. */
  110. if (percpu)
  111. *ptep = __pte((pte_val(*ptep) & _PAGE_HASHPTE)
  112. | (pte_val(pte) & ~_PAGE_HASHPTE));
  113. else
  114. pte_update(ptep, ~_PAGE_HASHPTE, pte_val(pte));
  115. #elif defined(CONFIG_PPC32) && defined(CONFIG_PTE_64BIT)
  116. /* Second case is 32-bit with 64-bit PTE. In this case, we
  117. * can just store as long as we do the two halves in the right order
  118. * with a barrier in between. This is possible because we take care,
  119. * in the hash code, to pre-invalidate if the PTE was already hashed,
  120. * which synchronizes us with any concurrent invalidation.
  121. * In the percpu case, we also fallback to the simple update preserving
  122. * the hash bits
  123. */
  124. if (percpu) {
  125. *ptep = __pte((pte_val(*ptep) & _PAGE_HASHPTE)
  126. | (pte_val(pte) & ~_PAGE_HASHPTE));
  127. return;
  128. }
  129. #if _PAGE_HASHPTE != 0
  130. if (pte_val(*ptep) & _PAGE_HASHPTE)
  131. flush_hash_entry(mm, ptep, addr);
  132. #endif
  133. __asm__ __volatile__("\
  134. stw%U0%X0 %2,%0\n\
  135. eieio\n\
  136. stw%U0%X0 %L2,%1"
  137. : "=m" (*ptep), "=m" (*((unsigned char *)ptep+4))
  138. : "r" (pte) : "memory");
  139. #elif defined(CONFIG_PPC_STD_MMU_32)
  140. /* Third case is 32-bit hash table in UP mode, we need to preserve
  141. * the _PAGE_HASHPTE bit since we may not have invalidated the previous
  142. * translation in the hash yet (done in a subsequent flush_tlb_xxx())
  143. * and see we need to keep track that this PTE needs invalidating
  144. */
  145. *ptep = __pte((pte_val(*ptep) & _PAGE_HASHPTE)
  146. | (pte_val(pte) & ~_PAGE_HASHPTE));
  147. #else
  148. /* Anything else just stores the PTE normally. That covers all 64-bit
  149. * cases, and 32-bit non-hash with 32-bit PTEs.
  150. */
  151. *ptep = pte;
  152. #ifdef CONFIG_PPC_BOOK3E_64
  153. /*
  154. * With hardware tablewalk, a sync is needed to ensure that
  155. * subsequent accesses see the PTE we just wrote. Unlike userspace
  156. * mappings, we can't tolerate spurious faults, so make sure
  157. * the new PTE will be seen the first time.
  158. */
  159. if (is_kernel_addr(addr))
  160. mb();
  161. #endif
  162. #endif
  163. }
  164. #define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
  165. extern int ptep_set_access_flags(struct vm_area_struct *vma, unsigned long address,
  166. pte_t *ptep, pte_t entry, int dirty);
  167. /*
  168. * Macro to mark a page protection value as "uncacheable".
  169. */
  170. #define _PAGE_CACHE_CTL (_PAGE_COHERENT | _PAGE_GUARDED | _PAGE_NO_CACHE | \
  171. _PAGE_WRITETHRU)
  172. #define pgprot_noncached(prot) (__pgprot((pgprot_val(prot) & ~_PAGE_CACHE_CTL) | \
  173. _PAGE_NO_CACHE | _PAGE_GUARDED))
  174. #define pgprot_noncached_wc(prot) (__pgprot((pgprot_val(prot) & ~_PAGE_CACHE_CTL) | \
  175. _PAGE_NO_CACHE))
  176. #define pgprot_cached(prot) (__pgprot((pgprot_val(prot) & ~_PAGE_CACHE_CTL) | \
  177. _PAGE_COHERENT))
  178. #define pgprot_cached_wthru(prot) (__pgprot((pgprot_val(prot) & ~_PAGE_CACHE_CTL) | \
  179. _PAGE_COHERENT | _PAGE_WRITETHRU))
  180. #define pgprot_cached_noncoherent(prot) \
  181. (__pgprot(pgprot_val(prot) & ~_PAGE_CACHE_CTL))
  182. #define pgprot_writecombine pgprot_noncached_wc
  183. struct file;
  184. extern pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
  185. unsigned long size, pgprot_t vma_prot);
  186. #define __HAVE_PHYS_MEM_ACCESS_PROT
  187. /*
  188. * ZERO_PAGE is a global shared page that is always zero: used
  189. * for zero-mapped memory areas etc..
  190. */
  191. extern unsigned long empty_zero_page[];
  192. #define ZERO_PAGE(vaddr) (virt_to_page(empty_zero_page))
  193. extern pgd_t swapper_pg_dir[];
  194. void limit_zone_pfn(enum zone_type zone, unsigned long max_pfn);
  195. int dma_pfn_limit_to_zone(u64 pfn_limit);
  196. extern void paging_init(void);
  197. /*
  198. * kern_addr_valid is intended to indicate whether an address is a valid
  199. * kernel address. Most 32-bit archs define it as always true (like this)
  200. * but most 64-bit archs actually perform a test. What should we do here?
  201. */
  202. #define kern_addr_valid(addr) (1)
  203. #include <asm-generic/pgtable.h>
  204. /*
  205. * This gets called at the end of handling a page fault, when
  206. * the kernel has put a new PTE into the page table for the process.
  207. * We use it to ensure coherency between the i-cache and d-cache
  208. * for the page which has just been mapped in.
  209. * On machines which use an MMU hash table, we use this to put a
  210. * corresponding HPTE into the hash table ahead of time, instead of
  211. * waiting for the inevitable extra hash-table miss exception.
  212. */
  213. extern void update_mmu_cache(struct vm_area_struct *, unsigned long, pte_t *);
  214. extern int gup_hugepte(pte_t *ptep, unsigned long sz, unsigned long addr,
  215. unsigned long end, int write,
  216. struct page **pages, int *nr);
  217. #ifndef CONFIG_TRANSPARENT_HUGEPAGE
  218. #define pmd_large(pmd) 0
  219. #define has_transparent_hugepage() 0
  220. #endif
  221. pte_t *__find_linux_pte_or_hugepte(pgd_t *pgdir, unsigned long ea,
  222. unsigned *shift);
  223. static inline pte_t *find_linux_pte_or_hugepte(pgd_t *pgdir, unsigned long ea,
  224. unsigned *shift)
  225. {
  226. if (!arch_irqs_disabled()) {
  227. pr_info("%s called with irq enabled\n", __func__);
  228. dump_stack();
  229. }
  230. return __find_linux_pte_or_hugepte(pgdir, ea, shift);
  231. }
  232. #endif /* __ASSEMBLY__ */
  233. #endif /* __KERNEL__ */
  234. #endif /* _ASM_POWERPC_PGTABLE_H */