xref: /openbmc/linux/arch/ia64/include/asm/pgalloc.h (revision 151f4e2b)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_IA64_PGALLOC_H
3 #define _ASM_IA64_PGALLOC_H
4 
5 /*
6  * This file contains the functions and defines necessary to allocate
7  * page tables.
8  *
9  * This hopefully works with any (fixed) ia-64 page-size, as defined
10  * in <asm/page.h> (currently 8192).
11  *
12  * Copyright (C) 1998-2001 Hewlett-Packard Co
13  *	David Mosberger-Tang <davidm@hpl.hp.com>
14  * Copyright (C) 2000, Goutham Rao <goutham.rao@intel.com>
15  */
16 
17 
18 #include <linux/compiler.h>
19 #include <linux/mm.h>
20 #include <linux/page-flags.h>
21 #include <linux/threads.h>
22 #include <linux/quicklist.h>
23 
24 #include <asm/mmu_context.h>
25 
26 static inline pgd_t *pgd_alloc(struct mm_struct *mm)
27 {
28 	return quicklist_alloc(0, GFP_KERNEL, NULL);
29 }
30 
31 static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
32 {
33 	quicklist_free(0, NULL, pgd);
34 }
35 
36 #if CONFIG_PGTABLE_LEVELS == 4
37 static inline void
38 pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
39 {
40 	pgd_val(*pgd_entry) = __pa(pud);
41 }
42 
43 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
44 {
45 	return quicklist_alloc(0, GFP_KERNEL, NULL);
46 }
47 
48 static inline void pud_free(struct mm_struct *mm, pud_t *pud)
49 {
50 	quicklist_free(0, NULL, pud);
51 }
52 #define __pud_free_tlb(tlb, pud, address)	pud_free((tlb)->mm, pud)
53 #endif /* CONFIG_PGTABLE_LEVELS == 4 */
54 
55 static inline void
56 pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
57 {
58 	pud_val(*pud_entry) = __pa(pmd);
59 }
60 
61 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
62 {
63 	return quicklist_alloc(0, GFP_KERNEL, NULL);
64 }
65 
66 static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
67 {
68 	quicklist_free(0, NULL, pmd);
69 }
70 
71 #define __pmd_free_tlb(tlb, pmd, address)	pmd_free((tlb)->mm, pmd)
72 
73 static inline void
74 pmd_populate(struct mm_struct *mm, pmd_t * pmd_entry, pgtable_t pte)
75 {
76 	pmd_val(*pmd_entry) = page_to_phys(pte);
77 }
78 #define pmd_pgtable(pmd) pmd_page(pmd)
79 
80 static inline void
81 pmd_populate_kernel(struct mm_struct *mm, pmd_t * pmd_entry, pte_t * pte)
82 {
83 	pmd_val(*pmd_entry) = __pa(pte);
84 }
85 
86 static inline pgtable_t pte_alloc_one(struct mm_struct *mm)
87 {
88 	struct page *page;
89 	void *pg;
90 
91 	pg = quicklist_alloc(0, GFP_KERNEL, NULL);
92 	if (!pg)
93 		return NULL;
94 	page = virt_to_page(pg);
95 	if (!pgtable_page_ctor(page)) {
96 		quicklist_free(0, NULL, pg);
97 		return NULL;
98 	}
99 	return page;
100 }
101 
102 static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm)
103 {
104 	return quicklist_alloc(0, GFP_KERNEL, NULL);
105 }
106 
107 static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
108 {
109 	pgtable_page_dtor(pte);
110 	quicklist_free_page(0, NULL, pte);
111 }
112 
113 static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
114 {
115 	quicklist_free(0, NULL, pte);
116 }
117 
118 static inline void check_pgt_cache(void)
119 {
120 	quicklist_trim(0, NULL, 25, 16);
121 }
122 
123 #define __pte_free_tlb(tlb, pte, address)	pte_free((tlb)->mm, pte)
124 
125 #endif				/* _ASM_IA64_PGALLOC_H */
126