at v5.3 3.5 kB view raw
1/* SPDX-License-Identifier: GPL-2.0-only */ 2/* 3 * arch/arm/include/asm/pgalloc.h 4 * 5 * Copyright (C) 2000-2001 Russell King 6 */ 7#ifndef _ASMARM_PGALLOC_H 8#define _ASMARM_PGALLOC_H 9 10#include <linux/pagemap.h> 11 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> 17 18#define check_pgt_cache() do { } while (0) 19 20#ifdef CONFIG_MMU 21 22#define _PAGE_USER_TABLE (PMD_TYPE_TABLE | PMD_BIT4 | PMD_DOMAIN(DOMAIN_USER)) 23#define _PAGE_KERNEL_TABLE (PMD_TYPE_TABLE | PMD_BIT4 | PMD_DOMAIN(DOMAIN_KERNEL)) 24 25#ifdef CONFIG_ARM_LPAE 26 27static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr) 28{ 29 return (pmd_t *)get_zeroed_page(GFP_KERNEL); 30} 31 32static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd) 33{ 34 BUG_ON((unsigned long)pmd & (PAGE_SIZE-1)); 35 free_page((unsigned long)pmd); 36} 37 38static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd) 39{ 40 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE)); 41} 42 43#else /* !CONFIG_ARM_LPAE */ 44 45/* 46 * Since we have only two-level page tables, these are trivial 47 */ 48#define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); }) 49#define pmd_free(mm, pmd) do { } while (0) 50#define pud_populate(mm,pmd,pte) BUG() 51 52#endif /* CONFIG_ARM_LPAE */ 53 54extern pgd_t *pgd_alloc(struct mm_struct *mm); 55extern void pgd_free(struct mm_struct *mm, pgd_t *pgd); 56 57static inline void clean_pte_table(pte_t *pte) 58{ 59 clean_dcache_area(pte + PTE_HWTABLE_PTRS, PTE_HWTABLE_SIZE); 60} 61 62/* 63 * Allocate one PTE table. 64 * 65 * This actually allocates two hardware PTE tables, but we wrap this up 66 * into one table thus: 67 * 68 * +------------+ 69 * | Linux pt 0 | 70 * +------------+ 71 * | Linux pt 1 | 72 * +------------+ 73 * | h/w pt 0 | 74 * +------------+ 75 * | h/w pt 1 | 76 * +------------+ 77 */ 78 79#define __HAVE_ARCH_PTE_ALLOC_ONE_KERNEL 80#define __HAVE_ARCH_PTE_ALLOC_ONE 81#include <asm-generic/pgalloc.h> 82 83static inline pte_t * 84pte_alloc_one_kernel(struct mm_struct *mm) 85{ 86 pte_t *pte = __pte_alloc_one_kernel(mm); 87 88 if (pte) 89 clean_pte_table(pte); 90 91 return pte; 92} 93 94#ifdef CONFIG_HIGHPTE 95#define PGTABLE_HIGHMEM __GFP_HIGHMEM 96#else 97#define PGTABLE_HIGHMEM 0 98#endif 99 100static inline pgtable_t 101pte_alloc_one(struct mm_struct *mm) 102{ 103 struct page *pte; 104 105 pte = __pte_alloc_one(mm, GFP_PGTABLE_USER | PGTABLE_HIGHMEM); 106 if (!pte) 107 return NULL; 108 if (!PageHighMem(pte)) 109 clean_pte_table(page_address(pte)); 110 return pte; 111} 112 113static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte, 114 pmdval_t prot) 115{ 116 pmdval_t pmdval = (pte + PTE_HWTABLE_OFF) | prot; 117 pmdp[0] = __pmd(pmdval); 118#ifndef CONFIG_ARM_LPAE 119 pmdp[1] = __pmd(pmdval + 256 * sizeof(pte_t)); 120#endif 121 flush_pmd_entry(pmdp); 122} 123 124/* 125 * Populate the pmdp entry with a pointer to the pte. This pmd is part 126 * of the mm address space. 127 * 128 * Ensure that we always set both PMD entries. 129 */ 130static inline void 131pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep) 132{ 133 /* 134 * The pmd must be loaded with the physical address of the PTE table 135 */ 136 __pmd_populate(pmdp, __pa(ptep), _PAGE_KERNEL_TABLE); 137} 138 139static inline void 140pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep) 141{ 142 extern pmdval_t user_pmd_table; 143 pmdval_t prot; 144 145 if (__LINUX_ARM_ARCH__ >= 6 && !IS_ENABLED(CONFIG_ARM_LPAE)) 146 prot = user_pmd_table; 147 else 148 prot = _PAGE_USER_TABLE; 149 150 __pmd_populate(pmdp, page_to_phys(ptep), prot); 151} 152#define pmd_pgtable(pmd) pmd_page(pmd) 153 154#endif /* CONFIG_MMU */ 155 156#endif