hugetlb.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. #ifndef _ASM_POWERPC_HUGETLB_H
  2. #define _ASM_POWERPC_HUGETLB_H
  3. #ifdef CONFIG_HUGETLB_PAGE
  4. #include <asm/page.h>
  5. #include <asm-generic/hugetlb.h>
  6. extern struct kmem_cache *hugepte_cache;
  7. #ifdef CONFIG_PPC_BOOK3S_64
  8. #include <asm/book3s/64/hugetlb.h>
  9. /*
  10. * This should work for other subarchs too. But right now we use the
  11. * new format only for 64bit book3s
  12. */
  13. static inline pte_t *hugepd_page(hugepd_t hpd)
  14. {
  15. BUG_ON(!hugepd_ok(hpd));
  16. /*
  17. * We have only four bits to encode, MMU page size
  18. */
  19. BUILD_BUG_ON((MMU_PAGE_COUNT - 1) > 0xf);
  20. return __va(hpd_val(hpd) & HUGEPD_ADDR_MASK);
  21. }
  22. static inline unsigned int hugepd_mmu_psize(hugepd_t hpd)
  23. {
  24. return (hpd_val(hpd) & HUGEPD_SHIFT_MASK) >> 2;
  25. }
  26. static inline unsigned int hugepd_shift(hugepd_t hpd)
  27. {
  28. return mmu_psize_to_shift(hugepd_mmu_psize(hpd));
  29. }
  30. static inline void flush_hugetlb_page(struct vm_area_struct *vma,
  31. unsigned long vmaddr)
  32. {
  33. if (radix_enabled())
  34. return radix__flush_hugetlb_page(vma, vmaddr);
  35. }
  36. static inline void __local_flush_hugetlb_page(struct vm_area_struct *vma,
  37. unsigned long vmaddr)
  38. {
  39. if (radix_enabled())
  40. return radix__local_flush_hugetlb_page(vma, vmaddr);
  41. }
  42. #else
  43. static inline pte_t *hugepd_page(hugepd_t hpd)
  44. {
  45. BUG_ON(!hugepd_ok(hpd));
  46. #ifdef CONFIG_PPC_8xx
  47. return (pte_t *)__va(hpd_val(hpd) &
  48. ~(_PMD_PAGE_MASK | _PMD_PRESENT_MASK));
  49. #else
  50. return (pte_t *)((hpd_val(hpd) &
  51. ~HUGEPD_SHIFT_MASK) | PD_HUGE);
  52. #endif
  53. }
  54. static inline unsigned int hugepd_shift(hugepd_t hpd)
  55. {
  56. #ifdef CONFIG_PPC_8xx
  57. return ((hpd_val(hpd) & _PMD_PAGE_MASK) >> 1) + 17;
  58. #else
  59. return hpd_val(hpd) & HUGEPD_SHIFT_MASK;
  60. #endif
  61. }
  62. #endif /* CONFIG_PPC_BOOK3S_64 */
  63. static inline pte_t *hugepte_offset(hugepd_t hpd, unsigned long addr,
  64. unsigned pdshift)
  65. {
  66. /*
  67. * On FSL BookE, we have multiple higher-level table entries that
  68. * point to the same hugepte. Just use the first one since they're all
  69. * identical. So for that case, idx=0.
  70. */
  71. unsigned long idx = 0;
  72. pte_t *dir = hugepd_page(hpd);
  73. #ifndef CONFIG_PPC_FSL_BOOK3E
  74. idx = (addr & ((1UL << pdshift) - 1)) >> hugepd_shift(hpd);
  75. #endif
  76. return dir + idx;
  77. }
  78. pte_t *huge_pte_offset_and_shift(struct mm_struct *mm,
  79. unsigned long addr, unsigned *shift);
  80. void flush_dcache_icache_hugepage(struct page *page);
  81. #if defined(CONFIG_PPC_MM_SLICES)
  82. int is_hugepage_only_range(struct mm_struct *mm, unsigned long addr,
  83. unsigned long len);
  84. #else
  85. static inline int is_hugepage_only_range(struct mm_struct *mm,
  86. unsigned long addr,
  87. unsigned long len)
  88. {
  89. return 0;
  90. }
  91. #endif
  92. void book3e_hugetlb_preload(struct vm_area_struct *vma, unsigned long ea,
  93. pte_t pte);
  94. #ifdef CONFIG_PPC_8xx
  95. static inline void flush_hugetlb_page(struct vm_area_struct *vma,
  96. unsigned long vmaddr)
  97. {
  98. flush_tlb_page(vma, vmaddr);
  99. }
  100. #else
  101. void flush_hugetlb_page(struct vm_area_struct *vma, unsigned long vmaddr);
  102. #endif
  103. void hugetlb_free_pgd_range(struct mmu_gather *tlb, unsigned long addr,
  104. unsigned long end, unsigned long floor,
  105. unsigned long ceiling);
  106. /*
  107. * The version of vma_mmu_pagesize() in arch/powerpc/mm/hugetlbpage.c needs
  108. * to override the version in mm/hugetlb.c
  109. */
  110. #define vma_mmu_pagesize vma_mmu_pagesize
  111. /*
  112. * If the arch doesn't supply something else, assume that hugepage
  113. * size aligned regions are ok without further preparation.
  114. */
  115. static inline int prepare_hugepage_range(struct file *file,
  116. unsigned long addr, unsigned long len)
  117. {
  118. struct hstate *h = hstate_file(file);
  119. if (len & ~huge_page_mask(h))
  120. return -EINVAL;
  121. if (addr & ~huge_page_mask(h))
  122. return -EINVAL;
  123. return 0;
  124. }
  125. static inline void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
  126. pte_t *ptep, pte_t pte)
  127. {
  128. set_pte_at(mm, addr, ptep, pte);
  129. }
  130. static inline pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
  131. unsigned long addr, pte_t *ptep)
  132. {
  133. #ifdef CONFIG_PPC64
  134. return __pte(pte_update(mm, addr, ptep, ~0UL, 0, 1));
  135. #else
  136. return __pte(pte_update(ptep, ~0UL, 0));
  137. #endif
  138. }
  139. static inline void huge_ptep_clear_flush(struct vm_area_struct *vma,
  140. unsigned long addr, pte_t *ptep)
  141. {
  142. pte_t pte;
  143. pte = huge_ptep_get_and_clear(vma->vm_mm, addr, ptep);
  144. flush_hugetlb_page(vma, addr);
  145. }
  146. static inline int huge_pte_none(pte_t pte)
  147. {
  148. return pte_none(pte);
  149. }
  150. static inline pte_t huge_pte_wrprotect(pte_t pte)
  151. {
  152. return pte_wrprotect(pte);
  153. }
  154. static inline int huge_ptep_set_access_flags(struct vm_area_struct *vma,
  155. unsigned long addr, pte_t *ptep,
  156. pte_t pte, int dirty)
  157. {
  158. #ifdef HUGETLB_NEED_PRELOAD
  159. /*
  160. * The "return 1" forces a call of update_mmu_cache, which will write a
  161. * TLB entry. Without this, platforms that don't do a write of the TLB
  162. * entry in the TLB miss handler asm will fault ad infinitum.
  163. */
  164. ptep_set_access_flags(vma, addr, ptep, pte, dirty);
  165. return 1;
  166. #else
  167. return ptep_set_access_flags(vma, addr, ptep, pte, dirty);
  168. #endif
  169. }
  170. static inline pte_t huge_ptep_get(pte_t *ptep)
  171. {
  172. return *ptep;
  173. }
  174. static inline void arch_clear_hugepage_flags(struct page *page)
  175. {
  176. }
  177. #else /* ! CONFIG_HUGETLB_PAGE */
  178. static inline void flush_hugetlb_page(struct vm_area_struct *vma,
  179. unsigned long vmaddr)
  180. {
  181. }
  182. #define hugepd_shift(x) 0
  183. static inline pte_t *hugepte_offset(hugepd_t hpd, unsigned long addr,
  184. unsigned pdshift)
  185. {
  186. return 0;
  187. }
  188. #endif /* CONFIG_HUGETLB_PAGE */
  189. /*
  190. * FSL Book3E platforms require special gpage handling - the gpages
  191. * are reserved early in the boot process by memblock instead of via
  192. * the .dts as on IBM platforms.
  193. */
  194. #if defined(CONFIG_HUGETLB_PAGE) && (defined(CONFIG_PPC_FSL_BOOK3E) || \
  195. defined(CONFIG_PPC_8xx))
  196. extern void __init reserve_hugetlb_gpages(void);
  197. #else
  198. static inline void reserve_hugetlb_gpages(void)
  199. {
  200. }
  201. #endif
  202. #endif /* _ASM_POWERPC_HUGETLB_H */