hugetlb.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _ASM_POWERPC_HUGETLB_H
  3. #define _ASM_POWERPC_HUGETLB_H
  4. #ifdef CONFIG_HUGETLB_PAGE
  5. #include <asm/page.h>
  6. #include <asm-generic/hugetlb.h>
  7. extern struct kmem_cache *hugepte_cache;
  8. #ifdef CONFIG_PPC_BOOK3S_64
  9. #include <asm/book3s/64/hugetlb.h>
  10. /*
  11. * This should work for other subarchs too. But right now we use the
  12. * new format only for 64bit book3s
  13. */
  14. static inline pte_t *hugepd_page(hugepd_t hpd)
  15. {
  16. BUG_ON(!hugepd_ok(hpd));
  17. /*
  18. * We have only four bits to encode, MMU page size
  19. */
  20. BUILD_BUG_ON((MMU_PAGE_COUNT - 1) > 0xf);
  21. return __va(hpd_val(hpd) & HUGEPD_ADDR_MASK);
  22. }
  23. static inline unsigned int hugepd_mmu_psize(hugepd_t hpd)
  24. {
  25. return (hpd_val(hpd) & HUGEPD_SHIFT_MASK) >> 2;
  26. }
  27. static inline unsigned int hugepd_shift(hugepd_t hpd)
  28. {
  29. return mmu_psize_to_shift(hugepd_mmu_psize(hpd));
  30. }
  31. static inline void flush_hugetlb_page(struct vm_area_struct *vma,
  32. unsigned long vmaddr)
  33. {
  34. if (radix_enabled())
  35. return radix__flush_hugetlb_page(vma, vmaddr);
  36. }
  37. #else
  38. static inline pte_t *hugepd_page(hugepd_t hpd)
  39. {
  40. BUG_ON(!hugepd_ok(hpd));
  41. #ifdef CONFIG_PPC_8xx
  42. return (pte_t *)__va(hpd_val(hpd) & ~HUGEPD_SHIFT_MASK);
  43. #else
  44. return (pte_t *)((hpd_val(hpd) &
  45. ~HUGEPD_SHIFT_MASK) | PD_HUGE);
  46. #endif
  47. }
  48. static inline unsigned int hugepd_shift(hugepd_t hpd)
  49. {
  50. #ifdef CONFIG_PPC_8xx
  51. return ((hpd_val(hpd) & _PMD_PAGE_MASK) >> 1) + 17;
  52. #else
  53. return hpd_val(hpd) & HUGEPD_SHIFT_MASK;
  54. #endif
  55. }
  56. #endif /* CONFIG_PPC_BOOK3S_64 */
  57. static inline pte_t *hugepte_offset(hugepd_t hpd, unsigned long addr,
  58. unsigned pdshift)
  59. {
  60. /*
  61. * On FSL BookE, we have multiple higher-level table entries that
  62. * point to the same hugepte. Just use the first one since they're all
  63. * identical. So for that case, idx=0.
  64. */
  65. unsigned long idx = 0;
  66. pte_t *dir = hugepd_page(hpd);
  67. #ifndef CONFIG_PPC_FSL_BOOK3E
  68. idx = (addr & ((1UL << pdshift) - 1)) >> hugepd_shift(hpd);
  69. #endif
  70. return dir + idx;
  71. }
  72. void flush_dcache_icache_hugepage(struct page *page);
  73. int slice_is_hugepage_only_range(struct mm_struct *mm, unsigned long addr,
  74. unsigned long len);
  75. static inline int is_hugepage_only_range(struct mm_struct *mm,
  76. unsigned long addr,
  77. unsigned long len)
  78. {
  79. if (IS_ENABLED(CONFIG_PPC_MM_SLICES) && !radix_enabled())
  80. return slice_is_hugepage_only_range(mm, addr, len);
  81. return 0;
  82. }
  83. void book3e_hugetlb_preload(struct vm_area_struct *vma, unsigned long ea,
  84. pte_t pte);
  85. #ifdef CONFIG_PPC_8xx
  86. static inline void flush_hugetlb_page(struct vm_area_struct *vma,
  87. unsigned long vmaddr)
  88. {
  89. flush_tlb_page(vma, vmaddr);
  90. }
  91. #else
  92. void flush_hugetlb_page(struct vm_area_struct *vma, unsigned long vmaddr);
  93. #endif
  94. void hugetlb_free_pgd_range(struct mmu_gather *tlb, unsigned long addr,
  95. unsigned long end, unsigned long floor,
  96. unsigned long ceiling);
  97. /*
  98. * If the arch doesn't supply something else, assume that hugepage
  99. * size aligned regions are ok without further preparation.
  100. */
  101. static inline int prepare_hugepage_range(struct file *file,
  102. unsigned long addr, unsigned long len)
  103. {
  104. struct hstate *h = hstate_file(file);
  105. if (len & ~huge_page_mask(h))
  106. return -EINVAL;
  107. if (addr & ~huge_page_mask(h))
  108. return -EINVAL;
  109. return 0;
  110. }
  111. static inline void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
  112. pte_t *ptep, pte_t pte)
  113. {
  114. set_pte_at(mm, addr, ptep, pte);
  115. }
  116. static inline pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
  117. unsigned long addr, pte_t *ptep)
  118. {
  119. #ifdef CONFIG_PPC64
  120. return __pte(pte_update(mm, addr, ptep, ~0UL, 0, 1));
  121. #else
  122. return __pte(pte_update(ptep, ~0UL, 0));
  123. #endif
  124. }
  125. static inline void huge_ptep_clear_flush(struct vm_area_struct *vma,
  126. unsigned long addr, pte_t *ptep)
  127. {
  128. pte_t pte;
  129. pte = huge_ptep_get_and_clear(vma->vm_mm, addr, ptep);
  130. flush_hugetlb_page(vma, addr);
  131. }
  132. static inline int huge_pte_none(pte_t pte)
  133. {
  134. return pte_none(pte);
  135. }
  136. static inline pte_t huge_pte_wrprotect(pte_t pte)
  137. {
  138. return pte_wrprotect(pte);
  139. }
  140. extern int huge_ptep_set_access_flags(struct vm_area_struct *vma,
  141. unsigned long addr, pte_t *ptep,
  142. pte_t pte, int dirty);
  143. static inline pte_t huge_ptep_get(pte_t *ptep)
  144. {
  145. return *ptep;
  146. }
  147. static inline void arch_clear_hugepage_flags(struct page *page)
  148. {
  149. }
  150. #else /* ! CONFIG_HUGETLB_PAGE */
  151. static inline void flush_hugetlb_page(struct vm_area_struct *vma,
  152. unsigned long vmaddr)
  153. {
  154. }
  155. #define hugepd_shift(x) 0
  156. static inline pte_t *hugepte_offset(hugepd_t hpd, unsigned long addr,
  157. unsigned pdshift)
  158. {
  159. return NULL;
  160. }
  161. #endif /* CONFIG_HUGETLB_PAGE */
  162. #endif /* _ASM_POWERPC_HUGETLB_H */