hugetlb.h 4.9 KB

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