1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun #ifndef _ASM_POWERPC_BOOK3S_32_PGALLOC_H
3*4882a593Smuzhiyun #define _ASM_POWERPC_BOOK3S_32_PGALLOC_H
4*4882a593Smuzhiyun
5*4882a593Smuzhiyun #include <linux/threads.h>
6*4882a593Smuzhiyun #include <linux/slab.h>
7*4882a593Smuzhiyun
pgd_alloc(struct mm_struct * mm)8*4882a593Smuzhiyun static inline pgd_t *pgd_alloc(struct mm_struct *mm)
9*4882a593Smuzhiyun {
10*4882a593Smuzhiyun return kmem_cache_alloc(PGT_CACHE(PGD_INDEX_SIZE),
11*4882a593Smuzhiyun pgtable_gfp_flags(mm, GFP_KERNEL));
12*4882a593Smuzhiyun }
13*4882a593Smuzhiyun
pgd_free(struct mm_struct * mm,pgd_t * pgd)14*4882a593Smuzhiyun static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
15*4882a593Smuzhiyun {
16*4882a593Smuzhiyun kmem_cache_free(PGT_CACHE(PGD_INDEX_SIZE), pgd);
17*4882a593Smuzhiyun }
18*4882a593Smuzhiyun
19*4882a593Smuzhiyun /*
20*4882a593Smuzhiyun * We don't have any real pmd's, and this code never triggers because
21*4882a593Smuzhiyun * the pgd will always be present..
22*4882a593Smuzhiyun */
23*4882a593Smuzhiyun /* #define pmd_alloc_one(mm,address) ({ BUG(); ((pmd_t *)2); }) */
24*4882a593Smuzhiyun #define pmd_free(mm, x) do { } while (0)
25*4882a593Smuzhiyun #define __pmd_free_tlb(tlb,x,a) do { } while (0)
26*4882a593Smuzhiyun /* #define pgd_populate(mm, pmd, pte) BUG() */
27*4882a593Smuzhiyun
pmd_populate_kernel(struct mm_struct * mm,pmd_t * pmdp,pte_t * pte)28*4882a593Smuzhiyun static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp,
29*4882a593Smuzhiyun pte_t *pte)
30*4882a593Smuzhiyun {
31*4882a593Smuzhiyun *pmdp = __pmd(__pa(pte) | _PMD_PRESENT);
32*4882a593Smuzhiyun }
33*4882a593Smuzhiyun
pmd_populate(struct mm_struct * mm,pmd_t * pmdp,pgtable_t pte_page)34*4882a593Smuzhiyun static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmdp,
35*4882a593Smuzhiyun pgtable_t pte_page)
36*4882a593Smuzhiyun {
37*4882a593Smuzhiyun *pmdp = __pmd(__pa(pte_page) | _PMD_PRESENT);
38*4882a593Smuzhiyun }
39*4882a593Smuzhiyun
pgtable_free(void * table,unsigned index_size)40*4882a593Smuzhiyun static inline void pgtable_free(void *table, unsigned index_size)
41*4882a593Smuzhiyun {
42*4882a593Smuzhiyun if (!index_size) {
43*4882a593Smuzhiyun pte_fragment_free((unsigned long *)table, 0);
44*4882a593Smuzhiyun } else {
45*4882a593Smuzhiyun BUG_ON(index_size > MAX_PGTABLE_INDEX_SIZE);
46*4882a593Smuzhiyun kmem_cache_free(PGT_CACHE(index_size), table);
47*4882a593Smuzhiyun }
48*4882a593Smuzhiyun }
49*4882a593Smuzhiyun
50*4882a593Smuzhiyun #define get_hugepd_cache_index(x) (x)
51*4882a593Smuzhiyun
pgtable_free_tlb(struct mmu_gather * tlb,void * table,int shift)52*4882a593Smuzhiyun static inline void pgtable_free_tlb(struct mmu_gather *tlb,
53*4882a593Smuzhiyun void *table, int shift)
54*4882a593Smuzhiyun {
55*4882a593Smuzhiyun unsigned long pgf = (unsigned long)table;
56*4882a593Smuzhiyun BUG_ON(shift > MAX_PGTABLE_INDEX_SIZE);
57*4882a593Smuzhiyun pgf |= shift;
58*4882a593Smuzhiyun tlb_remove_table(tlb, (void *)pgf);
59*4882a593Smuzhiyun }
60*4882a593Smuzhiyun
__tlb_remove_table(void * _table)61*4882a593Smuzhiyun static inline void __tlb_remove_table(void *_table)
62*4882a593Smuzhiyun {
63*4882a593Smuzhiyun void *table = (void *)((unsigned long)_table & ~MAX_PGTABLE_INDEX_SIZE);
64*4882a593Smuzhiyun unsigned shift = (unsigned long)_table & MAX_PGTABLE_INDEX_SIZE;
65*4882a593Smuzhiyun
66*4882a593Smuzhiyun pgtable_free(table, shift);
67*4882a593Smuzhiyun }
68*4882a593Smuzhiyun
__pte_free_tlb(struct mmu_gather * tlb,pgtable_t table,unsigned long address)69*4882a593Smuzhiyun static inline void __pte_free_tlb(struct mmu_gather *tlb, pgtable_t table,
70*4882a593Smuzhiyun unsigned long address)
71*4882a593Smuzhiyun {
72*4882a593Smuzhiyun pgtable_free_tlb(tlb, table, 0);
73*4882a593Smuzhiyun }
74*4882a593Smuzhiyun #endif /* _ASM_POWERPC_BOOK3S_32_PGALLOC_H */
75