^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) 2005-2017 Andes Technology Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) #ifndef _ASMNDS32_PGALLOC_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #define _ASMNDS32_PGALLOC_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <asm/processor.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <asm/cacheflush.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <asm/tlbflush.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <asm/proc-fns.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #define __HAVE_ARCH_PTE_ALLOC_ONE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <asm-generic/pgalloc.h> /* for pte_{alloc,free}_one */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * Since we have only two-level page tables, these are trivial
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define pmd_pgtable(pmd) pmd_page(pmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) extern pgd_t *pgd_alloc(struct mm_struct *mm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) extern void pgd_free(struct mm_struct *mm, pgd_t * pgd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) static inline pgtable_t pte_alloc_one(struct mm_struct *mm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) pgtable_t pte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) pte = __pte_alloc_one(mm, GFP_PGTABLE_USER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) if (pte)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) cpu_dcache_wb_page((unsigned long)page_address(pte));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) return pte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * Populate the pmdp entry with a pointer to the pte. This pmd is part
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * of the mm address space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * Ensure that we always set both PMD entries.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) pmd_populate_kernel(struct mm_struct *mm, pmd_t * pmdp, pte_t * ptep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) unsigned long pte_ptr = (unsigned long)ptep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) unsigned long pmdval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) BUG_ON(mm != &init_mm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * The pmd must be loaded with the physical
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * address of the PTE table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) pmdval = __pa(pte_ptr) | _PAGE_KERNEL_TABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) set_pmd(pmdp, __pmd(pmdval));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) pmd_populate(struct mm_struct *mm, pmd_t * pmdp, pgtable_t ptep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) unsigned long pmdval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) BUG_ON(mm == &init_mm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) pmdval = page_to_pfn(ptep) << PAGE_SHIFT | _PAGE_USER_TABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) set_pmd(pmdp, __pmd(pmdval));
^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) #endif