Nishad Kamdar | 7f9ea6b | 2019-04-16 20:54:35 +0530 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Greentime Hu | 2e1aecb | 2017-10-24 14:53:31 +0800 | [diff] [blame] | 2 | // Copyright (C) 2005-2017 Andes Technology Corporation |
| 3 | |
| 4 | #ifndef _ASMNDS32_PGALLOC_H |
| 5 | #define _ASMNDS32_PGALLOC_H |
| 6 | |
| 7 | #include <asm/processor.h> |
| 8 | #include <asm/cacheflush.h> |
| 9 | #include <asm/tlbflush.h> |
| 10 | #include <asm/proc-fns.h> |
| 11 | |
Mike Rapoport | f52a8e1 | 2019-07-11 20:58:18 -0700 | [diff] [blame] | 12 | #define __HAVE_ARCH_PTE_ALLOC_ONE |
| 13 | #include <asm-generic/pgalloc.h> /* for pte_{alloc,free}_one */ |
| 14 | |
Greentime Hu | 2e1aecb | 2017-10-24 14:53:31 +0800 | [diff] [blame] | 15 | /* |
| 16 | * Since we have only two-level page tables, these are trivial |
| 17 | */ |
Greentime Hu | 2e1aecb | 2017-10-24 14:53:31 +0800 | [diff] [blame] | 18 | #define pmd_pgtable(pmd) pmd_page(pmd) |
| 19 | |
| 20 | extern pgd_t *pgd_alloc(struct mm_struct *mm); |
| 21 | extern void pgd_free(struct mm_struct *mm, pgd_t * pgd); |
| 22 | |
Joel Fernandes (Google) | 4cf5892 | 2019-01-03 15:28:34 -0800 | [diff] [blame] | 23 | static inline pgtable_t pte_alloc_one(struct mm_struct *mm) |
Greentime Hu | 2e1aecb | 2017-10-24 14:53:31 +0800 | [diff] [blame] | 24 | { |
| 25 | pgtable_t pte; |
| 26 | |
Mike Rapoport | f52a8e1 | 2019-07-11 20:58:18 -0700 | [diff] [blame] | 27 | pte = __pte_alloc_one(mm, GFP_PGTABLE_USER); |
Greentime Hu | 2e1aecb | 2017-10-24 14:53:31 +0800 | [diff] [blame] | 28 | if (pte) |
| 29 | cpu_dcache_wb_page((unsigned long)page_address(pte)); |
| 30 | |
| 31 | return pte; |
| 32 | } |
| 33 | |
| 34 | /* |
Greentime Hu | 2e1aecb | 2017-10-24 14:53:31 +0800 | [diff] [blame] | 35 | * Populate the pmdp entry with a pointer to the pte. This pmd is part |
| 36 | * of the mm address space. |
| 37 | * |
| 38 | * Ensure that we always set both PMD entries. |
| 39 | */ |
| 40 | static inline void |
| 41 | pmd_populate_kernel(struct mm_struct *mm, pmd_t * pmdp, pte_t * ptep) |
| 42 | { |
| 43 | unsigned long pte_ptr = (unsigned long)ptep; |
| 44 | unsigned long pmdval; |
| 45 | |
| 46 | BUG_ON(mm != &init_mm); |
| 47 | |
| 48 | /* |
| 49 | * The pmd must be loaded with the physical |
| 50 | * address of the PTE table |
| 51 | */ |
| 52 | pmdval = __pa(pte_ptr) | _PAGE_KERNEL_TABLE; |
| 53 | set_pmd(pmdp, __pmd(pmdval)); |
| 54 | } |
| 55 | |
| 56 | static inline void |
| 57 | pmd_populate(struct mm_struct *mm, pmd_t * pmdp, pgtable_t ptep) |
| 58 | { |
| 59 | unsigned long pmdval; |
| 60 | |
| 61 | BUG_ON(mm == &init_mm); |
| 62 | |
| 63 | pmdval = page_to_pfn(ptep) << PAGE_SHIFT | _PAGE_USER_TABLE; |
| 64 | set_pmd(pmdp, __pmd(pmdval)); |
| 65 | } |
| 66 | |
| 67 | #endif |