David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Based on arch/arm/include/asm/pgalloc.h |
| 4 | * |
| 5 | * Copyright (C) 2000-2001 Russell King |
| 6 | * Copyright (C) 2012 ARM Ltd. |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 7 | */ |
| 8 | #ifndef __ASM_PGALLOC_H |
| 9 | #define __ASM_PGALLOC_H |
| 10 | |
| 11 | #include <asm/pgtable-hwdef.h> |
| 12 | #include <asm/processor.h> |
| 13 | #include <asm/cacheflush.h> |
| 14 | #include <asm/tlbflush.h> |
| 15 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 16 | #define __HAVE_ARCH_PGD_FREE |
| 17 | #include <asm-generic/pgalloc.h> |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 18 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 19 | #define PGD_SIZE (PTRS_PER_PGD * sizeof(pgd_t)) |
| 20 | |
| 21 | #if CONFIG_PGTABLE_LEVELS > 2 |
| 22 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 23 | static inline void __pud_populate(pud_t *pudp, phys_addr_t pmdp, pudval_t prot) |
| 24 | { |
| 25 | set_pud(pudp, __pud(__phys_to_pud_val(pmdp) | prot)); |
| 26 | } |
| 27 | |
| 28 | static inline void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmdp) |
| 29 | { |
| 30 | __pud_populate(pudp, __pa(pmdp), PMD_TYPE_TABLE); |
| 31 | } |
| 32 | #else |
| 33 | static inline void __pud_populate(pud_t *pudp, phys_addr_t pmdp, pudval_t prot) |
| 34 | { |
| 35 | BUILD_BUG(); |
| 36 | } |
| 37 | #endif /* CONFIG_PGTABLE_LEVELS > 2 */ |
| 38 | |
| 39 | #if CONFIG_PGTABLE_LEVELS > 3 |
| 40 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 41 | static inline void __p4d_populate(p4d_t *p4dp, phys_addr_t pudp, p4dval_t prot) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 42 | { |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 43 | set_p4d(p4dp, __p4d(__phys_to_p4d_val(pudp) | prot)); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 44 | } |
| 45 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 46 | static inline void p4d_populate(struct mm_struct *mm, p4d_t *p4dp, pud_t *pudp) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 47 | { |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 48 | __p4d_populate(p4dp, __pa(pudp), PUD_TYPE_TABLE); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 49 | } |
| 50 | #else |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 51 | static inline void __p4d_populate(p4d_t *p4dp, phys_addr_t pudp, p4dval_t prot) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 52 | { |
| 53 | BUILD_BUG(); |
| 54 | } |
| 55 | #endif /* CONFIG_PGTABLE_LEVELS > 3 */ |
| 56 | |
| 57 | extern pgd_t *pgd_alloc(struct mm_struct *mm); |
| 58 | extern void pgd_free(struct mm_struct *mm, pgd_t *pgdp); |
| 59 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 60 | static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t ptep, |
| 61 | pmdval_t prot) |
| 62 | { |
| 63 | set_pmd(pmdp, __pmd(__phys_to_pmd_val(ptep) | prot)); |
| 64 | } |
| 65 | |
| 66 | /* |
| 67 | * Populate the pmdp entry with a pointer to the pte. This pmd is part |
| 68 | * of the mm address space. |
| 69 | */ |
| 70 | static inline void |
| 71 | pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep) |
| 72 | { |
| 73 | /* |
| 74 | * The pmd must be loaded with the physical address of the PTE table |
| 75 | */ |
| 76 | __pmd_populate(pmdp, __pa(ptep), PMD_TYPE_TABLE); |
| 77 | } |
| 78 | |
| 79 | static inline void |
| 80 | pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep) |
| 81 | { |
| 82 | __pmd_populate(pmdp, page_to_phys(ptep), PMD_TYPE_TABLE); |
| 83 | } |
| 84 | #define pmd_pgtable(pmd) pmd_page(pmd) |
| 85 | |
| 86 | #endif |