blob: 48f2ed2a71ae057eb669ad43ff212ff02a541c84 [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/*
Mel Gorman33402892009-01-06 14:38:54 -0800121 * The version of vma_mmu_pagesize() in arch/powerpc/mm/hugetlbpage.c needs
122 * to override the version in mm/hugetlb.c
123 */
124#define vma_mmu_pagesize vma_mmu_pagesize
125
126/*
Gerald Schaefer6d779072008-04-28 02:13:27 -0700127 * If the arch doesn't supply something else, assume that hugepage
128 * size aligned regions are ok without further preparation.
129 */
Andi Kleena5516432008-07-23 21:27:41 -0700130static inline int prepare_hugepage_range(struct file *file,
131 unsigned long addr, unsigned long len)
Gerald Schaefer6d779072008-04-28 02:13:27 -0700132{
Jon Tollefson0d9ea752008-07-23 21:27:56 -0700133 struct hstate *h = hstate_file(file);
134 if (len & ~huge_page_mask(h))
Gerald Schaefer6d779072008-04-28 02:13:27 -0700135 return -EINVAL;
Jon Tollefson0d9ea752008-07-23 21:27:56 -0700136 if (addr & ~huge_page_mask(h))
Gerald Schaefer6d779072008-04-28 02:13:27 -0700137 return -EINVAL;
138 return 0;
139}
140
David Gibson0895ecd2009-10-26 19:24:31 +0000141static inline void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
142 pte_t *ptep, pte_t pte)
143{
144 set_pte_at(mm, addr, ptep, pte);
145}
146
147static inline pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
148 unsigned long addr, pte_t *ptep)
149{
Becky Bruce41151e72011-06-28 09:54:48 +0000150#ifdef CONFIG_PPC64
Aneesh Kumar K.V88247e82014-02-12 09:13:36 +0530151 return __pte(pte_update(mm, addr, ptep, ~0UL, 0, 1));
Becky Bruce41151e72011-06-28 09:54:48 +0000152#else
153 return __pte(pte_update(ptep, ~0UL, 0));
154#endif
David Gibson0895ecd2009-10-26 19:24:31 +0000155}
156
Gerald Schaefer8fe627e2008-04-28 02:13:28 -0700157static inline void huge_ptep_clear_flush(struct vm_area_struct *vma,
158 unsigned long addr, pte_t *ptep)
159{
David Gibson0895ecd2009-10-26 19:24:31 +0000160 pte_t pte;
161 pte = huge_ptep_get_and_clear(vma->vm_mm, addr, ptep);
Aneesh Kumar K.V13dce032016-07-13 15:06:38 +0530162 flush_hugetlb_page(vma, addr);
Gerald Schaefer8fe627e2008-04-28 02:13:28 -0700163}
164
Gerald Schaefer7f2e9522008-04-28 02:13:29 -0700165static inline int huge_pte_none(pte_t pte)
166{
167 return pte_none(pte);
168}
169
170static inline pte_t huge_pte_wrprotect(pte_t pte)
171{
172 return pte_wrprotect(pte);
173}
174
Gerald Schaefer7f2e9522008-04-28 02:13:29 -0700175static inline int huge_ptep_set_access_flags(struct vm_area_struct *vma,
176 unsigned long addr, pte_t *ptep,
177 pte_t pte, int dirty)
178{
Becky Bruce1f6820b2011-11-29 15:10:39 +0000179#ifdef HUGETLB_NEED_PRELOAD
Becky Bruce97632e62011-10-10 10:50:37 +0000180 /*
181 * The "return 1" forces a call of update_mmu_cache, which will write a
182 * TLB entry. Without this, platforms that don't do a write of the TLB
183 * entry in the TLB miss handler asm will fault ad infinitum.
184 */
185 ptep_set_access_flags(vma, addr, ptep, pte, dirty);
186 return 1;
187#else
Gerald Schaefer7f2e9522008-04-28 02:13:29 -0700188 return ptep_set_access_flags(vma, addr, ptep, pte, dirty);
Becky Bruce97632e62011-10-10 10:50:37 +0000189#endif
Gerald Schaefer7f2e9522008-04-28 02:13:29 -0700190}
191
192static inline pte_t huge_ptep_get(pte_t *ptep)
193{
194 return *ptep;
195}
196
Will Deacon5d3a5512012-10-08 16:29:32 -0700197static inline void arch_clear_hugepage_flags(struct page *page)
198{
199}
200
Becky Bruce41151e72011-06-28 09:54:48 +0000201#else /* ! CONFIG_HUGETLB_PAGE */
Becky Bruce41151e72011-06-28 09:54:48 +0000202static inline void flush_hugetlb_page(struct vm_area_struct *vma,
203 unsigned long vmaddr)
204{
205}
Becky Brucea6146882011-10-10 10:50:43 +0000206
Aneesh Kumar K.V29409992013-06-20 14:30:16 +0530207#define hugepd_shift(x) 0
Aneesh Kumar K.Vb30e7592014-11-05 21:57:41 +0530208static inline pte_t *hugepte_offset(hugepd_t hpd, unsigned long addr,
Aneesh Kumar K.V29409992013-06-20 14:30:16 +0530209 unsigned pdshift)
210{
211 return 0;
212}
213#endif /* CONFIG_HUGETLB_PAGE */
Becky Brucea6146882011-10-10 10:50:43 +0000214
Gerald Schaefer6d779072008-04-28 02:13:27 -0700215#endif /* _ASM_POWERPC_HUGETLB_H */