1 /* SPDX-License-Identifier: GPL-2.0 */ 2 // Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd. 3 4 #ifndef __ASM_CSKY_PGALLOC_H 5 #define __ASM_CSKY_PGALLOC_H 6 7 #include <linux/highmem.h> 8 #include <linux/mm.h> 9 #include <linux/sched.h> 10 11 #define __HAVE_ARCH_PTE_ALLOC_ONE_KERNEL 12 #include <asm-generic/pgalloc.h> /* for pte_{alloc,free}_one */ 13 14 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd, 15 pte_t *pte) 16 { 17 set_pmd(pmd, __pmd(__pa(pte))); 18 } 19 20 static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd, 21 pgtable_t pte) 22 { 23 set_pmd(pmd, __pmd(__pa(page_address(pte)))); 24 } 25 26 #define pmd_pgtable(pmd) pmd_page(pmd) 27 28 extern void pgd_init(unsigned long *p); 29 30 static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm) 31 { 32 pte_t *pte; 33 unsigned long i; 34 35 pte = (pte_t *) __get_free_page(GFP_KERNEL); 36 if (!pte) 37 return NULL; 38 39 for (i = 0; i < PAGE_SIZE/sizeof(pte_t); i++) 40 (pte + i)->pte_low = _PAGE_GLOBAL; 41 42 return pte; 43 } 44 45 static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd) 46 { 47 free_pages((unsigned long)pgd, PGD_ORDER); 48 } 49 50 static inline pgd_t *pgd_alloc(struct mm_struct *mm) 51 { 52 pgd_t *ret; 53 pgd_t *init; 54 55 ret = (pgd_t *) __get_free_pages(GFP_KERNEL, PGD_ORDER); 56 if (ret) { 57 init = pgd_offset(&init_mm, 0UL); 58 pgd_init((unsigned long *)ret); 59 memcpy(ret + USER_PTRS_PER_PGD, init + USER_PTRS_PER_PGD, 60 (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t)); 61 /* prevent out of order excute */ 62 smp_mb(); 63 #ifdef CONFIG_CPU_NEED_TLBSYNC 64 dcache_wb_range((unsigned int)ret, 65 (unsigned int)(ret + PTRS_PER_PGD)); 66 #endif 67 } 68 69 return ret; 70 } 71 72 #define __pte_free_tlb(tlb, pte, address) \ 73 do { \ 74 pgtable_page_dtor(pte); \ 75 tlb_remove_page(tlb, pte); \ 76 } while (0) 77 78 #define check_pgt_cache() do {} while (0) 79 80 extern void pagetable_init(void); 81 extern void pre_mmu_init(void); 82 extern void pre_trap_init(void); 83 84 #endif /* __ASM_CSKY_PGALLOC_H */ 85