]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - arch/powerpc/include/asm/hugetlb.h
UBUNTU: Ubuntu-4.15.0-96.97
[mirror_ubuntu-bionic-kernel.git] / arch / powerpc / include / asm / hugetlb.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
6d779079
GS
2#ifndef _ASM_POWERPC_HUGETLB_H
3#define _ASM_POWERPC_HUGETLB_H
4
41151e77 5#ifdef CONFIG_HUGETLB_PAGE
6d779079 6#include <asm/page.h>
106c992a 7#include <asm-generic/hugetlb.h>
6d779079 8
41151e77 9extern struct kmem_cache *hugepte_cache;
41151e77 10
cf9427b8 11#ifdef CONFIG_PPC_BOOK3S_64
48483760 12
bee8b3b5 13#include <asm/book3s/64/hugetlb.h>
cf9427b8
AK
14/*
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);
20717e1f 25 return __va(hpd_val(hpd) & HUGEPD_ADDR_MASK);
cf9427b8
AK
26}
27
28static inline unsigned int hugepd_mmu_psize(hugepd_t hpd)
29{
20717e1f 30 return (hpd_val(hpd) & HUGEPD_SHIFT_MASK) >> 2;
cf9427b8
AK
31}
32
33static inline unsigned int hugepd_shift(hugepd_t hpd)
34{
35 return mmu_psize_to_shift(hugepd_mmu_psize(hpd));
36}
48483760
AK
37static 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}
cf9427b8
AK
43
44#else
45
41151e77
BB
46static inline pte_t *hugepd_page(hugepd_t hpd)
47{
48 BUG_ON(!hugepd_ok(hpd));
4b914286 49#ifdef CONFIG_PPC_8xx
20717e1f
AK
50 return (pte_t *)__va(hpd_val(hpd) &
51 ~(_PMD_PAGE_MASK | _PMD_PRESENT_MASK));
4b914286 52#else
20717e1f
AK
53 return (pte_t *)((hpd_val(hpd) &
54 ~HUGEPD_SHIFT_MASK) | PD_HUGE);
4b914286 55#endif
41151e77
BB
56}
57
58static inline unsigned int hugepd_shift(hugepd_t hpd)
59{
4b914286 60#ifdef CONFIG_PPC_8xx
20717e1f 61 return ((hpd_val(hpd) & _PMD_PAGE_MASK) >> 1) + 17;
4b914286 62#else
20717e1f 63 return hpd_val(hpd) & HUGEPD_SHIFT_MASK;
4b914286 64#endif
41151e77
BB
65}
66
cf9427b8
AK
67#endif /* CONFIG_PPC_BOOK3S_64 */
68
69
b30e7590 70static inline pte_t *hugepte_offset(hugepd_t hpd, unsigned long addr,
41151e77
BB
71 unsigned pdshift)
72{
73 /*
881fde1d
BB
74 * On FSL BookE, we have multiple higher-level table entries that
75 * point to the same hugepte. Just use the first one since they're all
41151e77
BB
76 * identical. So for that case, idx=0.
77 */
78 unsigned long idx = 0;
79
b30e7590 80 pte_t *dir = hugepd_page(hpd);
881fde1d 81#ifndef CONFIG_PPC_FSL_BOOK3E
b30e7590 82 idx = (addr & ((1UL << pdshift) - 1)) >> hugepd_shift(hpd);
41151e77
BB
83#endif
84
85 return dir + idx;
86}
87
883a3e52
DG
88pte_t *huge_pte_offset_and_shift(struct mm_struct *mm,
89 unsigned long addr, unsigned *shift);
90
0895ecda
DG
91void flush_dcache_icache_hugepage(struct page *page);
92
ca5f1d16 93#if defined(CONFIG_PPC_MM_SLICES)
6d779079
GS
94int is_hugepage_only_range(struct mm_struct *mm, unsigned long addr,
95 unsigned long len);
41151e77
BB
96#else
97static inline int is_hugepage_only_range(struct mm_struct *mm,
98 unsigned long addr,
99 unsigned long len)
100{
101 return 0;
102}
103#endif
104
d93e4d7d
BB
105void book3e_hugetlb_preload(struct vm_area_struct *vma, unsigned long ea,
106 pte_t pte);
4b914286
CL
107#ifdef CONFIG_PPC_8xx
108static inline void flush_hugetlb_page(struct vm_area_struct *vma,
109 unsigned long vmaddr)
110{
111 flush_tlb_page(vma, vmaddr);
112}
113#else
41151e77 114void flush_hugetlb_page(struct vm_area_struct *vma, unsigned long vmaddr);
4b914286 115#endif
6d779079 116
42b77728 117void hugetlb_free_pgd_range(struct mmu_gather *tlb, unsigned long addr,
6d779079
GS
118 unsigned long end, unsigned long floor,
119 unsigned long ceiling);
120
3340289d
MG
121/*
122 * The version of vma_mmu_pagesize() in arch/powerpc/mm/hugetlbpage.c needs
123 * to override the version in mm/hugetlb.c
124 */
125#define vma_mmu_pagesize vma_mmu_pagesize
126
6d779079
GS
127/*
128 * If the arch doesn't supply something else, assume that hugepage
129 * size aligned regions are ok without further preparation.
130 */
a5516438
AK
131static inline int prepare_hugepage_range(struct file *file,
132 unsigned long addr, unsigned long len)
6d779079 133{
0d9ea754
JT
134 struct hstate *h = hstate_file(file);
135 if (len & ~huge_page_mask(h))
6d779079 136 return -EINVAL;
0d9ea754 137 if (addr & ~huge_page_mask(h))
6d779079
GS
138 return -EINVAL;
139 return 0;
140}
141
0895ecda
DG
142static inline void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
143 pte_t *ptep, pte_t pte)
144{
145 set_pte_at(mm, addr, ptep, pte);
146}
147
148static inline pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
149 unsigned long addr, pte_t *ptep)
150{
41151e77 151#ifdef CONFIG_PPC64
88247e8d 152 return __pte(pte_update(mm, addr, ptep, ~0UL, 0, 1));
41151e77
BB
153#else
154 return __pte(pte_update(ptep, ~0UL, 0));
155#endif
0895ecda
DG
156}
157
8fe627ec
GS
158static inline void huge_ptep_clear_flush(struct vm_area_struct *vma,
159 unsigned long addr, pte_t *ptep)
160{
0895ecda
DG
161 pte_t pte;
162 pte = huge_ptep_get_and_clear(vma->vm_mm, addr, ptep);
13dce033 163 flush_hugetlb_page(vma, addr);
8fe627ec
GS
164}
165
7f2e9525
GS
166static inline int huge_pte_none(pte_t pte)
167{
168 return pte_none(pte);
169}
170
171static inline pte_t huge_pte_wrprotect(pte_t pte)
172{
173 return pte_wrprotect(pte);
174}
175
ace86179
AK
176extern int huge_ptep_set_access_flags(struct vm_area_struct *vma,
177 unsigned long addr, pte_t *ptep,
178 pte_t pte, int dirty);
7f2e9525
GS
179
180static inline pte_t huge_ptep_get(pte_t *ptep)
181{
182 return *ptep;
183}
184
5d3a551c
WD
185static inline void arch_clear_hugepage_flags(struct page *page)
186{
187}
188
41151e77 189#else /* ! CONFIG_HUGETLB_PAGE */
41151e77
BB
190static inline void flush_hugetlb_page(struct vm_area_struct *vma,
191 unsigned long vmaddr)
192{
193}
a6146888 194
29409997 195#define hugepd_shift(x) 0
b30e7590 196static inline pte_t *hugepte_offset(hugepd_t hpd, unsigned long addr,
29409997
AK
197 unsigned pdshift)
198{
199 return 0;
200}
201#endif /* CONFIG_HUGETLB_PAGE */
a6146888 202
6d779079 203#endif /* _ASM_POWERPC_HUGETLB_H */