WIP FPC-III support
[linux/fpc-iii.git] / arch / arm / include / asm / pgalloc.h
blobfdee1f04f4f3dc0f424b337d68b86c485c0e5a39
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3 * arch/arm/include/asm/pgalloc.h
5 * Copyright (C) 2000-2001 Russell King
6 */
7 #ifndef _ASMARM_PGALLOC_H
8 #define _ASMARM_PGALLOC_H
10 #include <linux/pagemap.h>
12 #include <asm/domain.h>
13 #include <asm/pgtable-hwdef.h>
14 #include <asm/processor.h>
15 #include <asm/cacheflush.h>
16 #include <asm/tlbflush.h>
18 #ifdef CONFIG_MMU
20 #define _PAGE_USER_TABLE (PMD_TYPE_TABLE | PMD_BIT4 | PMD_DOMAIN(DOMAIN_USER))
21 #define _PAGE_KERNEL_TABLE (PMD_TYPE_TABLE | PMD_BIT4 | PMD_DOMAIN(DOMAIN_KERNEL))
23 #ifdef CONFIG_ARM_LPAE
24 #define PGD_SIZE (PTRS_PER_PGD * sizeof(pgd_t))
26 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
28 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
31 #else /* !CONFIG_ARM_LPAE */
32 #define PGD_SIZE (PAGE_SIZE << 2)
35 * Since we have only two-level page tables, these are trivial
37 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
38 #define pmd_free(mm, pmd) do { } while (0)
39 #ifdef CONFIG_KASAN
40 /* The KASan core unconditionally calls pud_populate() on all architectures */
41 #define pud_populate(mm,pmd,pte) do { } while (0)
42 #else
43 #define pud_populate(mm,pmd,pte) BUG()
44 #endif
45 #endif /* CONFIG_ARM_LPAE */
47 extern pgd_t *pgd_alloc(struct mm_struct *mm);
48 extern void pgd_free(struct mm_struct *mm, pgd_t *pgd);
50 static inline void clean_pte_table(pte_t *pte)
52 clean_dcache_area(pte + PTE_HWTABLE_PTRS, PTE_HWTABLE_SIZE);
56 * Allocate one PTE table.
58 * This actually allocates two hardware PTE tables, but we wrap this up
59 * into one table thus:
61 * +------------+
62 * | Linux pt 0 |
63 * +------------+
64 * | Linux pt 1 |
65 * +------------+
66 * | h/w pt 0 |
67 * +------------+
68 * | h/w pt 1 |
69 * +------------+
72 #define __HAVE_ARCH_PTE_ALLOC_ONE_KERNEL
73 #define __HAVE_ARCH_PTE_ALLOC_ONE
74 #define __HAVE_ARCH_PGD_FREE
75 #include <asm-generic/pgalloc.h>
77 static inline pte_t *
78 pte_alloc_one_kernel(struct mm_struct *mm)
80 pte_t *pte = __pte_alloc_one_kernel(mm);
82 if (pte)
83 clean_pte_table(pte);
85 return pte;
88 #ifdef CONFIG_HIGHPTE
89 #define PGTABLE_HIGHMEM __GFP_HIGHMEM
90 #else
91 #define PGTABLE_HIGHMEM 0
92 #endif
94 static inline pgtable_t
95 pte_alloc_one(struct mm_struct *mm)
97 struct page *pte;
99 pte = __pte_alloc_one(mm, GFP_PGTABLE_USER | PGTABLE_HIGHMEM);
100 if (!pte)
101 return NULL;
102 if (!PageHighMem(pte))
103 clean_pte_table(page_address(pte));
104 return pte;
107 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
108 pmdval_t prot)
110 pmdval_t pmdval = (pte + PTE_HWTABLE_OFF) | prot;
111 pmdp[0] = __pmd(pmdval);
112 #ifndef CONFIG_ARM_LPAE
113 pmdp[1] = __pmd(pmdval + 256 * sizeof(pte_t));
114 #endif
115 flush_pmd_entry(pmdp);
119 * Populate the pmdp entry with a pointer to the pte. This pmd is part
120 * of the mm address space.
122 * Ensure that we always set both PMD entries.
124 static inline void
125 pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
128 * The pmd must be loaded with the physical address of the PTE table
130 __pmd_populate(pmdp, __pa(ptep), _PAGE_KERNEL_TABLE);
133 static inline void
134 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
136 extern pmdval_t user_pmd_table;
137 pmdval_t prot;
139 if (__LINUX_ARM_ARCH__ >= 6 && !IS_ENABLED(CONFIG_ARM_LPAE))
140 prot = user_pmd_table;
141 else
142 prot = _PAGE_USER_TABLE;
144 __pmd_populate(pmdp, page_to_phys(ptep), prot);
146 #define pmd_pgtable(pmd) pmd_page(pmd)
148 #endif /* CONFIG_MMU */
150 #endif