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