blob: 2d00cc53008336d0044f24a41d32c26d815a9148 [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 Gibson0895ecd2009-10-26 19:24:31 +000087void flush_dcache_icache_hugepage(struct page *page);
88
Nicholas Piggin014a32b2018-03-07 11:37:17 +100089int slice_is_hugepage_only_range(struct mm_struct *mm, unsigned long addr,
Gerald Schaefer6d779072008-04-28 02:13:27 -070090 unsigned long len);
Nicholas Piggin014a32b2018-03-07 11:37:17 +100091
Becky Bruce41151e72011-06-28 09:54:48 +000092static inline int is_hugepage_only_range(struct mm_struct *mm,
93 unsigned long addr,
94 unsigned long len)
95{
Nicholas Piggin014a32b2018-03-07 11:37:17 +100096 if (IS_ENABLED(CONFIG_PPC_MM_SLICES) && !radix_enabled())
97 return slice_is_hugepage_only_range(mm, addr, len);
Becky Bruce41151e72011-06-28 09:54:48 +000098 return 0;
99}
Becky Bruce41151e72011-06-28 09:54:48 +0000100
Becky Bruced93e4d72011-11-28 14:43:33 +0000101void book3e_hugetlb_preload(struct vm_area_struct *vma, unsigned long ea,
102 pte_t pte);
Christophe Leroy4b9142862016-12-07 08:47:28 +0100103#ifdef CONFIG_PPC_8xx
104static inline void flush_hugetlb_page(struct vm_area_struct *vma,
105 unsigned long vmaddr)
106{
107 flush_tlb_page(vma, vmaddr);
108}
109#else
Becky Bruce41151e72011-06-28 09:54:48 +0000110void flush_hugetlb_page(struct vm_area_struct *vma, unsigned long vmaddr);
Christophe Leroy4b9142862016-12-07 08:47:28 +0100111#endif
Gerald Schaefer6d779072008-04-28 02:13:27 -0700112
Jan Beulich42b77722008-07-23 21:27:10 -0700113void hugetlb_free_pgd_range(struct mmu_gather *tlb, unsigned long addr,
Gerald Schaefer6d779072008-04-28 02:13:27 -0700114 unsigned long end, unsigned long floor,
115 unsigned long ceiling);
116
Gerald Schaefer6d779072008-04-28 02:13:27 -0700117/*
118 * If the arch doesn't supply something else, assume that hugepage
119 * size aligned regions are ok without further preparation.
120 */
Andi Kleena5516432008-07-23 21:27:41 -0700121static inline int prepare_hugepage_range(struct file *file,
122 unsigned long addr, unsigned long len)
Gerald Schaefer6d779072008-04-28 02:13:27 -0700123{
Jon Tollefson0d9ea752008-07-23 21:27:56 -0700124 struct hstate *h = hstate_file(file);
125 if (len & ~huge_page_mask(h))
Gerald Schaefer6d779072008-04-28 02:13:27 -0700126 return -EINVAL;
Jon Tollefson0d9ea752008-07-23 21:27:56 -0700127 if (addr & ~huge_page_mask(h))
Gerald Schaefer6d779072008-04-28 02:13:27 -0700128 return -EINVAL;
129 return 0;
130}
131
David Gibson0895ecd2009-10-26 19:24:31 +0000132static inline void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
133 pte_t *ptep, pte_t pte)
134{
135 set_pte_at(mm, addr, ptep, pte);
136}
137
138static inline pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
139 unsigned long addr, pte_t *ptep)
140{
Becky Bruce41151e72011-06-28 09:54:48 +0000141#ifdef CONFIG_PPC64
Aneesh Kumar K.V88247e82014-02-12 09:13:36 +0530142 return __pte(pte_update(mm, addr, ptep, ~0UL, 0, 1));
Becky Bruce41151e72011-06-28 09:54:48 +0000143#else
144 return __pte(pte_update(ptep, ~0UL, 0));
145#endif
David Gibson0895ecd2009-10-26 19:24:31 +0000146}
147
Gerald Schaefer8fe627e2008-04-28 02:13:28 -0700148static inline void huge_ptep_clear_flush(struct vm_area_struct *vma,
149 unsigned long addr, pte_t *ptep)
150{
David Gibson0895ecd2009-10-26 19:24:31 +0000151 pte_t pte;
152 pte = huge_ptep_get_and_clear(vma->vm_mm, addr, ptep);
Aneesh Kumar K.V13dce032016-07-13 15:06:38 +0530153 flush_hugetlb_page(vma, addr);
Gerald Schaefer8fe627e2008-04-28 02:13:28 -0700154}
155
Gerald Schaefer7f2e9522008-04-28 02:13:29 -0700156static inline int huge_pte_none(pte_t pte)
157{
158 return pte_none(pte);
159}
160
161static inline pte_t huge_pte_wrprotect(pte_t pte)
162{
163 return pte_wrprotect(pte);
164}
165
Aneesh Kumar K.Vf069ff32018-05-29 19:58:38 +0530166extern int huge_ptep_set_access_flags(struct vm_area_struct *vma,
167 unsigned long addr, pte_t *ptep,
168 pte_t pte, int dirty);
Gerald Schaefer7f2e9522008-04-28 02:13:29 -0700169
170static inline pte_t huge_ptep_get(pte_t *ptep)
171{
172 return *ptep;
173}
174
Will Deacon5d3a5512012-10-08 16:29:32 -0700175static inline void arch_clear_hugepage_flags(struct page *page)
176{
177}
178
Becky Bruce41151e72011-06-28 09:54:48 +0000179#else /* ! CONFIG_HUGETLB_PAGE */
Becky Bruce41151e72011-06-28 09:54:48 +0000180static inline void flush_hugetlb_page(struct vm_area_struct *vma,
181 unsigned long vmaddr)
182{
183}
Becky Brucea6146882011-10-10 10:50:43 +0000184
Aneesh Kumar K.V29409992013-06-20 14:30:16 +0530185#define hugepd_shift(x) 0
Aneesh Kumar K.Vb30e7592014-11-05 21:57:41 +0530186static inline pte_t *hugepte_offset(hugepd_t hpd, unsigned long addr,
Aneesh Kumar K.V29409992013-06-20 14:30:16 +0530187 unsigned pdshift)
188{
Mathieu Malaterred8731522018-04-13 20:41:43 +0200189 return NULL;
Aneesh Kumar K.V29409992013-06-20 14:30:16 +0530190}
191#endif /* CONFIG_HUGETLB_PAGE */
Becky Brucea6146882011-10-10 10:50:43 +0000192
Gerald Schaefer6d779072008-04-28 02:13:27 -0700193#endif /* _ASM_POWERPC_HUGETLB_H */