blob: 3225eb6402cc61d5538d9a9e320dc651a78ab17a [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Gerald Schaefer6d779072008-04-28 02:13:27 -07002#ifndef _ASM_POWERPC_HUGETLB_H
3#define _ASM_POWERPC_HUGETLB_H
4
Becky Bruce41151e72011-06-28 09:54:48 +00005#ifdef CONFIG_HUGETLB_PAGE
Gerald Schaefer6d779072008-04-28 02:13:27 -07006#include <asm/page.h>
Gerald Schaefer106c9922013-04-29 15:07:23 -07007#include <asm-generic/hugetlb.h>
Gerald Schaefer6d779072008-04-28 02:13:27 -07008
Becky Bruce41151e72011-06-28 09:54:48 +00009extern struct kmem_cache *hugepte_cache;
Becky Bruce41151e72011-06-28 09:54:48 +000010
Aneesh Kumar K.Vcf9427b2013-04-28 09:37:29 +000011#ifdef CONFIG_PPC_BOOK3S_64
Aneesh Kumar K.V48483762016-04-29 23:26:25 +100012
Aneesh Kumar K.Vbee8b3b2016-11-28 11:46:58 +053013#include <asm/book3s/64/hugetlb.h>
Aneesh Kumar K.Vcf9427b2013-04-28 09:37:29 +000014/*
15 * This should work for other subarchs too. But right now we use the
16 * new format only for 64bit book3s
17 */
18static inline pte_t *hugepd_page(hugepd_t hpd)
19{
20 BUG_ON(!hugepd_ok(hpd));
21 /*
22 * We have only four bits to encode, MMU page size
23 */
24 BUILD_BUG_ON((MMU_PAGE_COUNT - 1) > 0xf);
Aneesh Kumar K.V20717e12016-12-14 10:07:53 +053025 return __va(hpd_val(hpd) & HUGEPD_ADDR_MASK);
Aneesh Kumar K.Vcf9427b2013-04-28 09:37:29 +000026}
27
28static inline unsigned int hugepd_mmu_psize(hugepd_t hpd)
29{
Aneesh Kumar K.V20717e12016-12-14 10:07:53 +053030 return (hpd_val(hpd) & HUGEPD_SHIFT_MASK) >> 2;
Aneesh Kumar K.Vcf9427b2013-04-28 09:37:29 +000031}
32
33static inline unsigned int hugepd_shift(hugepd_t hpd)
34{
35 return mmu_psize_to_shift(hugepd_mmu_psize(hpd));
36}
Aneesh Kumar K.V48483762016-04-29 23:26:25 +100037static inline void flush_hugetlb_page(struct vm_area_struct *vma,
38 unsigned long vmaddr)
39{
40 if (radix_enabled())
41 return radix__flush_hugetlb_page(vma, vmaddr);
42}
Aneesh Kumar K.Vcf9427b2013-04-28 09:37:29 +000043
44#else
45
Becky Bruce41151e72011-06-28 09:54:48 +000046static inline pte_t *hugepd_page(hugepd_t hpd)
47{
48 BUG_ON(!hugepd_ok(hpd));
Christophe Leroy4b9142862016-12-07 08:47:28 +010049#ifdef CONFIG_PPC_8xx
Christophe Leroyde0f9382018-01-12 13:45:31 +010050 return (pte_t *)__va(hpd_val(hpd) & ~HUGEPD_SHIFT_MASK);
Christophe Leroy4b9142862016-12-07 08:47:28 +010051#else
Aneesh Kumar K.V20717e12016-12-14 10:07:53 +053052 return (pte_t *)((hpd_val(hpd) &
53 ~HUGEPD_SHIFT_MASK) | PD_HUGE);
Christophe Leroy4b9142862016-12-07 08:47:28 +010054#endif
Becky Bruce41151e72011-06-28 09:54:48 +000055}
56
57static inline unsigned int hugepd_shift(hugepd_t hpd)
58{
Christophe Leroy4b9142862016-12-07 08:47:28 +010059#ifdef CONFIG_PPC_8xx
Aneesh Kumar K.V20717e12016-12-14 10:07:53 +053060 return ((hpd_val(hpd) & _PMD_PAGE_MASK) >> 1) + 17;
Christophe Leroy4b9142862016-12-07 08:47:28 +010061#else
Aneesh Kumar K.V20717e12016-12-14 10:07:53 +053062 return hpd_val(hpd) & HUGEPD_SHIFT_MASK;
Christophe Leroy4b9142862016-12-07 08:47:28 +010063#endif
Becky Bruce41151e72011-06-28 09:54:48 +000064}
65
Aneesh Kumar K.Vcf9427b2013-04-28 09:37:29 +000066#endif /* CONFIG_PPC_BOOK3S_64 */
67
68
Aneesh Kumar K.Vb30e7592014-11-05 21:57:41 +053069static inline pte_t *hugepte_offset(hugepd_t hpd, unsigned long addr,
Becky Bruce41151e72011-06-28 09:54:48 +000070 unsigned pdshift)
71{
72 /*
Becky Bruce881fde12011-10-10 10:50:40 +000073 * On FSL BookE, we have multiple higher-level table entries that
74 * point to the same hugepte. Just use the first one since they're all
Becky Bruce41151e72011-06-28 09:54:48 +000075 * identical. So for that case, idx=0.
76 */
77 unsigned long idx = 0;
78
Aneesh Kumar K.Vb30e7592014-11-05 21:57:41 +053079 pte_t *dir = hugepd_page(hpd);
Becky Bruce881fde12011-10-10 10:50:40 +000080#ifndef CONFIG_PPC_FSL_BOOK3E
Aneesh Kumar K.Vb30e7592014-11-05 21:57:41 +053081 idx = (addr & ((1UL << pdshift) - 1)) >> hugepd_shift(hpd);
Becky Bruce41151e72011-06-28 09:54:48 +000082#endif
83
84 return dir + idx;
85}
86
David Gibson883a3e52009-10-26 19:24:31 +000087pte_t *huge_pte_offset_and_shift(struct mm_struct *mm,
88 unsigned long addr, unsigned *shift);
89
David Gibson0895ecd2009-10-26 19:24:31 +000090void flush_dcache_icache_hugepage(struct page *page);
91
Nicholas Piggin014a32b2018-03-07 11:37:17 +100092int slice_is_hugepage_only_range(struct mm_struct *mm, unsigned long addr,
Gerald Schaefer6d779072008-04-28 02:13:27 -070093 unsigned long len);
Nicholas Piggin014a32b2018-03-07 11:37:17 +100094
Becky Bruce41151e72011-06-28 09:54:48 +000095static inline int is_hugepage_only_range(struct mm_struct *mm,
96 unsigned long addr,
97 unsigned long len)
98{
Nicholas Piggin014a32b2018-03-07 11:37:17 +100099 if (IS_ENABLED(CONFIG_PPC_MM_SLICES) && !radix_enabled())
100 return slice_is_hugepage_only_range(mm, addr, len);
Becky Bruce41151e72011-06-28 09:54:48 +0000101 return 0;
102}
Becky Bruce41151e72011-06-28 09:54:48 +0000103
Becky Bruced93e4d72011-11-28 14:43:33 +0000104void book3e_hugetlb_preload(struct vm_area_struct *vma, unsigned long ea,
105 pte_t pte);
Christophe Leroy4b9142862016-12-07 08:47:28 +0100106#ifdef CONFIG_PPC_8xx
107static inline void flush_hugetlb_page(struct vm_area_struct *vma,
108 unsigned long vmaddr)
109{
110 flush_tlb_page(vma, vmaddr);
111}
112#else
Becky Bruce41151e72011-06-28 09:54:48 +0000113void flush_hugetlb_page(struct vm_area_struct *vma, unsigned long vmaddr);
Christophe Leroy4b9142862016-12-07 08:47:28 +0100114#endif
Gerald Schaefer6d779072008-04-28 02:13:27 -0700115
Jan Beulich42b77722008-07-23 21:27:10 -0700116void hugetlb_free_pgd_range(struct mmu_gather *tlb, unsigned long addr,
Gerald Schaefer6d779072008-04-28 02:13:27 -0700117 unsigned long end, unsigned long floor,
118 unsigned long ceiling);
119
Gerald Schaefer6d779072008-04-28 02:13:27 -0700120/*
121 * If the arch doesn't supply something else, assume that hugepage
122 * size aligned regions are ok without further preparation.
123 */
Andi Kleena5516432008-07-23 21:27:41 -0700124static inline int prepare_hugepage_range(struct file *file,
125 unsigned long addr, unsigned long len)
Gerald Schaefer6d779072008-04-28 02:13:27 -0700126{
Jon Tollefson0d9ea752008-07-23 21:27:56 -0700127 struct hstate *h = hstate_file(file);
128 if (len & ~huge_page_mask(h))
Gerald Schaefer6d779072008-04-28 02:13:27 -0700129 return -EINVAL;
Jon Tollefson0d9ea752008-07-23 21:27:56 -0700130 if (addr & ~huge_page_mask(h))
Gerald Schaefer6d779072008-04-28 02:13:27 -0700131 return -EINVAL;
132 return 0;
133}
134
David Gibson0895ecd2009-10-26 19:24:31 +0000135static inline void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
136 pte_t *ptep, pte_t pte)
137{
138 set_pte_at(mm, addr, ptep, pte);
139}
140
141static inline pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
142 unsigned long addr, pte_t *ptep)
143{
Becky Bruce41151e72011-06-28 09:54:48 +0000144#ifdef CONFIG_PPC64
Aneesh Kumar K.V88247e82014-02-12 09:13:36 +0530145 return __pte(pte_update(mm, addr, ptep, ~0UL, 0, 1));
Becky Bruce41151e72011-06-28 09:54:48 +0000146#else
147 return __pte(pte_update(ptep, ~0UL, 0));
148#endif
David Gibson0895ecd2009-10-26 19:24:31 +0000149}
150
Gerald Schaefer8fe627e2008-04-28 02:13:28 -0700151static inline void huge_ptep_clear_flush(struct vm_area_struct *vma,
152 unsigned long addr, pte_t *ptep)
153{
David Gibson0895ecd2009-10-26 19:24:31 +0000154 pte_t pte;
155 pte = huge_ptep_get_and_clear(vma->vm_mm, addr, ptep);
Aneesh Kumar K.V13dce032016-07-13 15:06:38 +0530156 flush_hugetlb_page(vma, addr);
Gerald Schaefer8fe627e2008-04-28 02:13:28 -0700157}
158
Gerald Schaefer7f2e9522008-04-28 02:13:29 -0700159static inline int huge_pte_none(pte_t pte)
160{
161 return pte_none(pte);
162}
163
164static inline pte_t huge_pte_wrprotect(pte_t pte)
165{
166 return pte_wrprotect(pte);
167}
168
Aneesh Kumar K.Vf069ff32018-05-29 19:58:38 +0530169extern int huge_ptep_set_access_flags(struct vm_area_struct *vma,
170 unsigned long addr, pte_t *ptep,
171 pte_t pte, int dirty);
Gerald Schaefer7f2e9522008-04-28 02:13:29 -0700172
173static inline pte_t huge_ptep_get(pte_t *ptep)
174{
175 return *ptep;
176}
177
Will Deacon5d3a5512012-10-08 16:29:32 -0700178static inline void arch_clear_hugepage_flags(struct page *page)
179{
180}
181
Becky Bruce41151e72011-06-28 09:54:48 +0000182#else /* ! CONFIG_HUGETLB_PAGE */
Becky Bruce41151e72011-06-28 09:54:48 +0000183static inline void flush_hugetlb_page(struct vm_area_struct *vma,
184 unsigned long vmaddr)
185{
186}
Becky Brucea6146882011-10-10 10:50:43 +0000187
Aneesh Kumar K.V29409992013-06-20 14:30:16 +0530188#define hugepd_shift(x) 0
Aneesh Kumar K.Vb30e7592014-11-05 21:57:41 +0530189static inline pte_t *hugepte_offset(hugepd_t hpd, unsigned long addr,
Aneesh Kumar K.V29409992013-06-20 14:30:16 +0530190 unsigned pdshift)
191{
Mathieu Malaterred8731522018-04-13 20:41:43 +0200192 return NULL;
Aneesh Kumar K.V29409992013-06-20 14:30:16 +0530193}
194#endif /* CONFIG_HUGETLB_PAGE */
Becky Brucea6146882011-10-10 10:50:43 +0000195
Gerald Schaefer6d779072008-04-28 02:13:27 -0700196#endif /* _ASM_POWERPC_HUGETLB_H */