1 /* SPDX-License-Identifier: GPL-2.0 */
2 // Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
4 #ifndef __ASM_CSKY_PGALLOC_H
5 #define __ASM_CSKY_PGALLOC_H
7 #include <linux/highmem.h>
9 #include <linux/sched.h>
11 #define __HAVE_ARCH_PTE_ALLOC_ONE_KERNEL
12 #include <asm-generic/pgalloc.h>
14 static inline void pmd_populate_kernel(struct mm_struct
*mm
, pmd_t
*pmd
,
17 set_pmd(pmd
, __pmd(__pa(pte
)));
20 static inline void pmd_populate(struct mm_struct
*mm
, pmd_t
*pmd
,
23 set_pmd(pmd
, __pmd(__pa(page_address(pte
))));
26 #define pmd_pgtable(pmd) pmd_page(pmd)
28 extern void pgd_init(unsigned long *p
);
30 static inline pte_t
*pte_alloc_one_kernel(struct mm_struct
*mm
)
35 pte
= (pte_t
*) __get_free_page(GFP_KERNEL
);
39 for (i
= 0; i
< PAGE_SIZE
/sizeof(pte_t
); i
++)
40 (pte
+ i
)->pte_low
= _PAGE_GLOBAL
;
45 static inline pgd_t
*pgd_alloc(struct mm_struct
*mm
)
50 ret
= (pgd_t
*) __get_free_pages(GFP_KERNEL
, PGD_ORDER
);
52 init
= pgd_offset(&init_mm
, 0UL);
53 pgd_init((unsigned long *)ret
);
54 memcpy(ret
+ USER_PTRS_PER_PGD
, init
+ USER_PTRS_PER_PGD
,
55 (PTRS_PER_PGD
- USER_PTRS_PER_PGD
) * sizeof(pgd_t
));
56 /* prevent out of order excute */
58 #ifdef CONFIG_CPU_NEED_TLBSYNC
59 dcache_wb_range((unsigned int)ret
,
60 (unsigned int)(ret
+ PTRS_PER_PGD
));
67 #define __pte_free_tlb(tlb, pte, address) \
69 pgtable_pte_page_dtor(pte); \
70 tlb_remove_page(tlb, pte); \
73 extern void pagetable_init(void);
74 extern void pre_mmu_init(void);
75 extern void pre_trap_init(void);
77 #endif /* __ASM_CSKY_PGALLOC_H */