hugetlb.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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-radix.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.pd & HUGEPD_ADDR_MASK);
  21. }
  22. static inline unsigned int hugepd_mmu_psize(hugepd_t hpd)
  23. {
  24. return (hpd.pd & 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. return (pte_t *)((hpd.pd & ~HUGEPD_SHIFT_MASK) | PD_HUGE);
  47. }
  48. static inline unsigned int hugepd_shift(hugepd_t hpd)
  49. {
  50. return hpd.pd & HUGEPD_SHIFT_MASK;
  51. }
  52. #endif /* CONFIG_PPC_BOOK3S_64 */
  53. static inline pte_t *hugepte_offset(hugepd_t hpd, unsigned long addr,
  54. unsigned pdshift)
  55. {
  56. /*
  57. * On FSL BookE, we have multiple higher-level table entries that
  58. * point to the same hugepte. Just use the first one since they're all
  59. * identical. So for that case, idx=0.
  60. */
  61. unsigned long idx = 0;
  62. pte_t *dir = hugepd_page(hpd);
  63. #ifndef CONFIG_PPC_FSL_BOOK3E
  64. idx = (addr & ((1UL << pdshift) - 1)) >> hugepd_shift(hpd);
  65. #endif
  66. return dir + idx;
  67. }
  68. pte_t *huge_pte_offset_and_shift(struct mm_struct *mm,
  69. unsigned long addr, unsigned *shift);
  70. void flush_dcache_icache_hugepage(struct page *page);
  71. #if defined(CONFIG_PPC_MM_SLICES)
  72. int is_hugepage_only_range(struct mm_struct *mm, unsigned long addr,
  73. unsigned long len);
  74. #else
  75. static inline int is_hugepage_only_range(struct mm_struct *mm,
  76. unsigned long addr,
  77. unsigned long len)
  78. {
  79. return 0;
  80. }
  81. #endif
  82. void book3e_hugetlb_preload(struct vm_area_struct *vma, unsigned long ea,
  83. pte_t pte);
  84. void flush_hugetlb_page(struct vm_area_struct *vma, unsigned long vmaddr);
  85. void hugetlb_free_pgd_range(struct mmu_gather *tlb, unsigned long addr,
  86. unsigned long end, unsigned long floor,
  87. unsigned long ceiling);
  88. /*
  89. * The version of vma_mmu_pagesize() in arch/powerpc/mm/hugetlbpage.c needs
  90. * to override the version in mm/hugetlb.c
  91. */
  92. #define vma_mmu_pagesize vma_mmu_pagesize
  93. /*
  94. * If the arch doesn't supply something else, assume that hugepage
  95. * size aligned regions are ok without further preparation.
  96. */
  97. static inline int prepare_hugepage_range(struct file *file,
  98. unsigned long addr, unsigned long len)
  99. {
  100. struct hstate *h = hstate_file(file);
  101. if (len & ~huge_page_mask(h))
  102. return -EINVAL;
  103. if (addr & ~huge_page_mask(h))
  104. return -EINVAL;
  105. return 0;
  106. }
  107. static inline void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
  108. pte_t *ptep, pte_t pte)
  109. {
  110. set_pte_at(mm, addr, ptep, pte);
  111. }
  112. static inline pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
  113. unsigned long addr, pte_t *ptep)
  114. {
  115. #ifdef CONFIG_PPC64
  116. return __pte(pte_update(mm, addr, ptep, ~0UL, 0, 1));
  117. #else
  118. return __pte(pte_update(ptep, ~0UL, 0));
  119. #endif
  120. }
  121. static inline void huge_ptep_clear_flush(struct vm_area_struct *vma,
  122. unsigned long addr, pte_t *ptep)
  123. {
  124. pte_t pte;
  125. pte = huge_ptep_get_and_clear(vma->vm_mm, addr, ptep);
  126. flush_hugetlb_page(vma, addr);
  127. }
  128. static inline int huge_pte_none(pte_t pte)
  129. {
  130. return pte_none(pte);
  131. }
  132. static inline pte_t huge_pte_wrprotect(pte_t pte)
  133. {
  134. return pte_wrprotect(pte);
  135. }
  136. static inline int huge_ptep_set_access_flags(struct vm_area_struct *vma,
  137. unsigned long addr, pte_t *ptep,
  138. pte_t pte, int dirty)
  139. {
  140. #ifdef HUGETLB_NEED_PRELOAD
  141. /*
  142. * The "return 1" forces a call of update_mmu_cache, which will write a
  143. * TLB entry. Without this, platforms that don't do a write of the TLB
  144. * entry in the TLB miss handler asm will fault ad infinitum.
  145. */
  146. ptep_set_access_flags(vma, addr, ptep, pte, dirty);
  147. return 1;
  148. #else
  149. return ptep_set_access_flags(vma, addr, ptep, pte, dirty);
  150. #endif
  151. }
  152. static inline pte_t huge_ptep_get(pte_t *ptep)
  153. {
  154. return *ptep;
  155. }
  156. static inline void arch_clear_hugepage_flags(struct page *page)
  157. {
  158. }
  159. #else /* ! CONFIG_HUGETLB_PAGE */
  160. static inline void flush_hugetlb_page(struct vm_area_struct *vma,
  161. unsigned long vmaddr)
  162. {
  163. }
  164. #define hugepd_shift(x) 0
  165. static inline pte_t *hugepte_offset(hugepd_t hpd, unsigned long addr,
  166. unsigned pdshift)
  167. {
  168. return 0;
  169. }
  170. #endif /* CONFIG_HUGETLB_PAGE */
  171. /*
  172. * FSL Book3E platforms require special gpage handling - the gpages
  173. * are reserved early in the boot process by memblock instead of via
  174. * the .dts as on IBM platforms.
  175. */
  176. #if defined(CONFIG_HUGETLB_PAGE) && defined(CONFIG_PPC_FSL_BOOK3E)
  177. extern void __init reserve_hugetlb_gpages(void);
  178. #else
  179. static inline void reserve_hugetlb_gpages(void)
  180. {
  181. }
  182. #endif
  183. #endif /* _ASM_POWERPC_HUGETLB_H */