at v5.2 2.1 kB view raw
1/* SPDX-License-Identifier: GPL-2.0 */ 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 12/* 13 * Since we have only two-level page tables, these are trivial 14 */ 15#define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); }) 16#define pmd_free(mm, pmd) do { } while (0) 17#define pgd_populate(mm, pmd, pte) BUG() 18#define pmd_pgtable(pmd) pmd_page(pmd) 19 20extern pgd_t *pgd_alloc(struct mm_struct *mm); 21extern void pgd_free(struct mm_struct *mm, pgd_t * pgd); 22 23#define check_pgt_cache() do { } while (0) 24 25static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm) 26{ 27 pte_t *pte; 28 29 pte = 30 (pte_t *) __get_free_page(GFP_KERNEL | __GFP_RETRY_MAYFAIL | 31 __GFP_ZERO); 32 33 return pte; 34} 35 36static inline pgtable_t pte_alloc_one(struct mm_struct *mm) 37{ 38 pgtable_t pte; 39 40 pte = alloc_pages(GFP_KERNEL | __GFP_RETRY_MAYFAIL | __GFP_ZERO, 0); 41 if (pte) 42 cpu_dcache_wb_page((unsigned long)page_address(pte)); 43 44 return pte; 45} 46 47/* 48 * Free one PTE table. 49 */ 50static inline void pte_free_kernel(struct mm_struct *mm, pte_t * pte) 51{ 52 if (pte) { 53 free_page((unsigned long)pte); 54 } 55} 56 57static inline void pte_free(struct mm_struct *mm, pgtable_t pte) 58{ 59 __free_page(pte); 60} 61 62/* 63 * Populate the pmdp entry with a pointer to the pte. This pmd is part 64 * of the mm address space. 65 * 66 * Ensure that we always set both PMD entries. 67 */ 68static inline void 69pmd_populate_kernel(struct mm_struct *mm, pmd_t * pmdp, pte_t * ptep) 70{ 71 unsigned long pte_ptr = (unsigned long)ptep; 72 unsigned long pmdval; 73 74 BUG_ON(mm != &init_mm); 75 76 /* 77 * The pmd must be loaded with the physical 78 * address of the PTE table 79 */ 80 pmdval = __pa(pte_ptr) | _PAGE_KERNEL_TABLE; 81 set_pmd(pmdp, __pmd(pmdval)); 82} 83 84static inline void 85pmd_populate(struct mm_struct *mm, pmd_t * pmdp, pgtable_t ptep) 86{ 87 unsigned long pmdval; 88 89 BUG_ON(mm == &init_mm); 90 91 pmdval = page_to_pfn(ptep) << PAGE_SHIFT | _PAGE_USER_TABLE; 92 set_pmd(pmdp, __pmd(pmdval)); 93} 94 95#endif