David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [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 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 12 | #define __HAVE_ARCH_PTE_ALLOC_ONE |
| 13 | #include <asm-generic/pgalloc.h> /* for pte_{alloc,free}_one */ |
| 14 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15 | /* |
| 16 | * Since we have only two-level page tables, these are trivial |
| 17 | */ |
| 18 | #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); }) |
| 19 | #define pmd_free(mm, pmd) do { } while (0) |
| 20 | #define pgd_populate(mm, pmd, pte) BUG() |
| 21 | #define pmd_pgtable(pmd) pmd_page(pmd) |
| 22 | |
| 23 | extern pgd_t *pgd_alloc(struct mm_struct *mm); |
| 24 | extern void pgd_free(struct mm_struct *mm, pgd_t * pgd); |
| 25 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 26 | static inline pgtable_t pte_alloc_one(struct mm_struct *mm) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 27 | { |
| 28 | pgtable_t pte; |
| 29 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 30 | pte = __pte_alloc_one(mm, GFP_PGTABLE_USER); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 31 | if (pte) |
| 32 | cpu_dcache_wb_page((unsigned long)page_address(pte)); |
| 33 | |
| 34 | return pte; |
| 35 | } |
| 36 | |
| 37 | /* |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 38 | * Populate the pmdp entry with a pointer to the pte. This pmd is part |
| 39 | * of the mm address space. |
| 40 | * |
| 41 | * Ensure that we always set both PMD entries. |
| 42 | */ |
| 43 | static inline void |
| 44 | pmd_populate_kernel(struct mm_struct *mm, pmd_t * pmdp, pte_t * ptep) |
| 45 | { |
| 46 | unsigned long pte_ptr = (unsigned long)ptep; |
| 47 | unsigned long pmdval; |
| 48 | |
| 49 | BUG_ON(mm != &init_mm); |
| 50 | |
| 51 | /* |
| 52 | * The pmd must be loaded with the physical |
| 53 | * address of the PTE table |
| 54 | */ |
| 55 | pmdval = __pa(pte_ptr) | _PAGE_KERNEL_TABLE; |
| 56 | set_pmd(pmdp, __pmd(pmdval)); |
| 57 | } |
| 58 | |
| 59 | static inline void |
| 60 | pmd_populate(struct mm_struct *mm, pmd_t * pmdp, pgtable_t ptep) |
| 61 | { |
| 62 | unsigned long pmdval; |
| 63 | |
| 64 | BUG_ON(mm == &init_mm); |
| 65 | |
| 66 | pmdval = page_to_pfn(ptep) << PAGE_SHIFT | _PAGE_USER_TABLE; |
| 67 | set_pmd(pmdp, __pmd(pmdval)); |
| 68 | } |
| 69 | |
| 70 | #endif |