| .. | .. |
|---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-only */ |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Based on arch/arm/include/asm/pgalloc.h |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (C) 2000-2001 Russell King |
|---|
| 5 | 6 | * Copyright (C) 2012 ARM Ltd. |
|---|
| 6 | | - * |
|---|
| 7 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 8 | | - * it under the terms of the GNU General Public License version 2 as |
|---|
| 9 | | - * published by the Free Software Foundation. |
|---|
| 10 | | - * |
|---|
| 11 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 12 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | | - * GNU General Public License for more details. |
|---|
| 15 | | - * |
|---|
| 16 | | - * You should have received a copy of the GNU General Public License |
|---|
| 17 | | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|---|
| 18 | 7 | */ |
|---|
| 19 | 8 | #ifndef __ASM_PGALLOC_H |
|---|
| 20 | 9 | #define __ASM_PGALLOC_H |
|---|
| .. | .. |
|---|
| 24 | 13 | #include <asm/cacheflush.h> |
|---|
| 25 | 14 | #include <asm/tlbflush.h> |
|---|
| 26 | 15 | |
|---|
| 27 | | -#define check_pgt_cache() do { } while (0) |
|---|
| 16 | +#define __HAVE_ARCH_PGD_FREE |
|---|
| 17 | +#include <asm-generic/pgalloc.h> |
|---|
| 28 | 18 | |
|---|
| 29 | | -#define PGALLOC_GFP (GFP_KERNEL | __GFP_ZERO) |
|---|
| 30 | 19 | #define PGD_SIZE (PTRS_PER_PGD * sizeof(pgd_t)) |
|---|
| 31 | 20 | |
|---|
| 32 | 21 | #if CONFIG_PGTABLE_LEVELS > 2 |
|---|
| 33 | | - |
|---|
| 34 | | -static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr) |
|---|
| 35 | | -{ |
|---|
| 36 | | - return (pmd_t *)__get_free_page(PGALLOC_GFP); |
|---|
| 37 | | -} |
|---|
| 38 | | - |
|---|
| 39 | | -static inline void pmd_free(struct mm_struct *mm, pmd_t *pmdp) |
|---|
| 40 | | -{ |
|---|
| 41 | | - BUG_ON((unsigned long)pmdp & (PAGE_SIZE-1)); |
|---|
| 42 | | - free_page((unsigned long)pmdp); |
|---|
| 43 | | -} |
|---|
| 44 | 22 | |
|---|
| 45 | 23 | static inline void __pud_populate(pud_t *pudp, phys_addr_t pmdp, pudval_t prot) |
|---|
| 46 | 24 | { |
|---|
| .. | .. |
|---|
| 60 | 38 | |
|---|
| 61 | 39 | #if CONFIG_PGTABLE_LEVELS > 3 |
|---|
| 62 | 40 | |
|---|
| 63 | | -static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr) |
|---|
| 41 | +static inline void __p4d_populate(p4d_t *p4dp, phys_addr_t pudp, p4dval_t prot) |
|---|
| 64 | 42 | { |
|---|
| 65 | | - return (pud_t *)__get_free_page(PGALLOC_GFP); |
|---|
| 43 | + set_p4d(p4dp, __p4d(__phys_to_p4d_val(pudp) | prot)); |
|---|
| 66 | 44 | } |
|---|
| 67 | 45 | |
|---|
| 68 | | -static inline void pud_free(struct mm_struct *mm, pud_t *pudp) |
|---|
| 46 | +static inline void p4d_populate(struct mm_struct *mm, p4d_t *p4dp, pud_t *pudp) |
|---|
| 69 | 47 | { |
|---|
| 70 | | - BUG_ON((unsigned long)pudp & (PAGE_SIZE-1)); |
|---|
| 71 | | - free_page((unsigned long)pudp); |
|---|
| 72 | | -} |
|---|
| 73 | | - |
|---|
| 74 | | -static inline void __pgd_populate(pgd_t *pgdp, phys_addr_t pudp, pgdval_t prot) |
|---|
| 75 | | -{ |
|---|
| 76 | | - set_pgd(pgdp, __pgd(__phys_to_pgd_val(pudp) | prot)); |
|---|
| 77 | | -} |
|---|
| 78 | | - |
|---|
| 79 | | -static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgdp, pud_t *pudp) |
|---|
| 80 | | -{ |
|---|
| 81 | | - __pgd_populate(pgdp, __pa(pudp), PUD_TYPE_TABLE); |
|---|
| 48 | + __p4d_populate(p4dp, __pa(pudp), PUD_TYPE_TABLE); |
|---|
| 82 | 49 | } |
|---|
| 83 | 50 | #else |
|---|
| 84 | | -static inline void __pgd_populate(pgd_t *pgdp, phys_addr_t pudp, pgdval_t prot) |
|---|
| 51 | +static inline void __p4d_populate(p4d_t *p4dp, phys_addr_t pudp, p4dval_t prot) |
|---|
| 85 | 52 | { |
|---|
| 86 | 53 | BUILD_BUG(); |
|---|
| 87 | 54 | } |
|---|
| .. | .. |
|---|
| 89 | 56 | |
|---|
| 90 | 57 | extern pgd_t *pgd_alloc(struct mm_struct *mm); |
|---|
| 91 | 58 | extern void pgd_free(struct mm_struct *mm, pgd_t *pgdp); |
|---|
| 92 | | - |
|---|
| 93 | | -static inline pte_t * |
|---|
| 94 | | -pte_alloc_one_kernel(struct mm_struct *mm, unsigned long addr) |
|---|
| 95 | | -{ |
|---|
| 96 | | - return (pte_t *)__get_free_page(PGALLOC_GFP); |
|---|
| 97 | | -} |
|---|
| 98 | | - |
|---|
| 99 | | -static inline pgtable_t |
|---|
| 100 | | -pte_alloc_one(struct mm_struct *mm, unsigned long addr) |
|---|
| 101 | | -{ |
|---|
| 102 | | - struct page *pte; |
|---|
| 103 | | - |
|---|
| 104 | | - pte = alloc_pages(PGALLOC_GFP, 0); |
|---|
| 105 | | - if (!pte) |
|---|
| 106 | | - return NULL; |
|---|
| 107 | | - if (!pgtable_page_ctor(pte)) { |
|---|
| 108 | | - __free_page(pte); |
|---|
| 109 | | - return NULL; |
|---|
| 110 | | - } |
|---|
| 111 | | - return pte; |
|---|
| 112 | | -} |
|---|
| 113 | | - |
|---|
| 114 | | -/* |
|---|
| 115 | | - * Free a PTE table. |
|---|
| 116 | | - */ |
|---|
| 117 | | -static inline void pte_free_kernel(struct mm_struct *mm, pte_t *ptep) |
|---|
| 118 | | -{ |
|---|
| 119 | | - if (ptep) |
|---|
| 120 | | - free_page((unsigned long)ptep); |
|---|
| 121 | | -} |
|---|
| 122 | | - |
|---|
| 123 | | -static inline void pte_free(struct mm_struct *mm, pgtable_t pte) |
|---|
| 124 | | -{ |
|---|
| 125 | | - pgtable_page_dtor(pte); |
|---|
| 126 | | - __free_page(pte); |
|---|
| 127 | | -} |
|---|
| 128 | 59 | |
|---|
| 129 | 60 | static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t ptep, |
|---|
| 130 | 61 | pmdval_t prot) |
|---|