]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | #ifndef _ASM_IA64_PGALLOC_H |
2 | #define _ASM_IA64_PGALLOC_H | |
3 | ||
4 | /* | |
5 | * This file contains the functions and defines necessary to allocate | |
6 | * page tables. | |
7 | * | |
8 | * This hopefully works with any (fixed) ia-64 page-size, as defined | |
9 | * in <asm/page.h> (currently 8192). | |
10 | * | |
11 | * Copyright (C) 1998-2001 Hewlett-Packard Co | |
12 | * David Mosberger-Tang <davidm@hpl.hp.com> | |
13 | * Copyright (C) 2000, Goutham Rao <goutham.rao@intel.com> | |
14 | */ | |
15 | ||
1da177e4 LT |
16 | |
17 | #include <linux/compiler.h> | |
18 | #include <linux/mm.h> | |
19 | #include <linux/page-flags.h> | |
20 | #include <linux/threads.h> | |
21 | ||
22 | #include <asm/mmu_context.h> | |
23 | ||
fde740e4 RH |
24 | DECLARE_PER_CPU(unsigned long *, __pgtable_quicklist); |
25 | #define pgtable_quicklist __ia64_per_cpu_var(__pgtable_quicklist) | |
26 | DECLARE_PER_CPU(long, __pgtable_quicklist_size); | |
27 | #define pgtable_quicklist_size __ia64_per_cpu_var(__pgtable_quicklist_size) | |
1da177e4 | 28 | |
fde740e4 RH |
29 | static inline long pgtable_quicklist_total_size(void) |
30 | { | |
c411cb56 | 31 | long ql_size = 0; |
fde740e4 RH |
32 | int cpuid; |
33 | ||
34 | for_each_online_cpu(cpuid) { | |
35 | ql_size += per_cpu(__pgtable_quicklist_size, cpuid); | |
36 | } | |
37 | return ql_size; | |
38 | } | |
39 | ||
40 | static inline void *pgtable_quicklist_alloc(void) | |
1da177e4 LT |
41 | { |
42 | unsigned long *ret = NULL; | |
43 | ||
44 | preempt_disable(); | |
45 | ||
fde740e4 | 46 | ret = pgtable_quicklist; |
1da177e4 | 47 | if (likely(ret != NULL)) { |
fde740e4 | 48 | pgtable_quicklist = (unsigned long *)(*ret); |
1da177e4 | 49 | ret[0] = 0; |
fde740e4 | 50 | --pgtable_quicklist_size; |
2d29306b | 51 | preempt_enable(); |
fde740e4 | 52 | } else { |
2d29306b | 53 | preempt_enable(); |
fde740e4 RH |
54 | ret = (unsigned long *)__get_free_page(GFP_KERNEL | __GFP_ZERO); |
55 | } | |
1da177e4 | 56 | |
fde740e4 | 57 | return ret; |
1da177e4 LT |
58 | } |
59 | ||
fde740e4 | 60 | static inline void pgtable_quicklist_free(void *pgtable_entry) |
1da177e4 | 61 | { |
fde740e4 | 62 | #ifdef CONFIG_NUMA |
25ba77c1 | 63 | int nid = page_to_nid(virt_to_page(pgtable_entry)); |
1da177e4 | 64 | |
fde740e4 RH |
65 | if (unlikely(nid != numa_node_id())) { |
66 | free_page((unsigned long)pgtable_entry); | |
67 | return; | |
1da177e4 | 68 | } |
fde740e4 | 69 | #endif |
1da177e4 | 70 | |
1da177e4 | 71 | preempt_disable(); |
fde740e4 RH |
72 | *(unsigned long *)pgtable_entry = (unsigned long)pgtable_quicklist; |
73 | pgtable_quicklist = (unsigned long *)pgtable_entry; | |
74 | ++pgtable_quicklist_size; | |
1da177e4 LT |
75 | preempt_enable(); |
76 | } | |
77 | ||
fde740e4 | 78 | static inline pgd_t *pgd_alloc(struct mm_struct *mm) |
1da177e4 | 79 | { |
fde740e4 | 80 | return pgtable_quicklist_alloc(); |
1da177e4 LT |
81 | } |
82 | ||
fde740e4 | 83 | static inline void pgd_free(pgd_t * pgd) |
1da177e4 | 84 | { |
fde740e4 | 85 | pgtable_quicklist_free(pgd); |
1da177e4 LT |
86 | } |
87 | ||
837cd0bd RH |
88 | #ifdef CONFIG_PGTABLE_4 |
89 | static inline void | |
90 | pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud) | |
91 | { | |
92 | pgd_val(*pgd_entry) = __pa(pud); | |
93 | } | |
94 | ||
95 | static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr) | |
96 | { | |
97 | return pgtable_quicklist_alloc(); | |
98 | } | |
99 | ||
100 | static inline void pud_free(pud_t * pud) | |
101 | { | |
102 | pgtable_quicklist_free(pud); | |
103 | } | |
104 | #define __pud_free_tlb(tlb, pud) pud_free(pud) | |
105 | #endif /* CONFIG_PGTABLE_4 */ | |
106 | ||
fde740e4 RH |
107 | static inline void |
108 | pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd) | |
1da177e4 | 109 | { |
fde740e4 RH |
110 | pud_val(*pud_entry) = __pa(pmd); |
111 | } | |
1da177e4 | 112 | |
fde740e4 RH |
113 | static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr) |
114 | { | |
115 | return pgtable_quicklist_alloc(); | |
1da177e4 LT |
116 | } |
117 | ||
fde740e4 | 118 | static inline void pmd_free(pmd_t * pmd) |
1da177e4 | 119 | { |
fde740e4 | 120 | pgtable_quicklist_free(pmd); |
1da177e4 LT |
121 | } |
122 | ||
123 | #define __pmd_free_tlb(tlb, pmd) pmd_free(pmd) | |
124 | ||
125 | static inline void | |
fde740e4 | 126 | pmd_populate(struct mm_struct *mm, pmd_t * pmd_entry, struct page *pte) |
1da177e4 LT |
127 | { |
128 | pmd_val(*pmd_entry) = page_to_phys(pte); | |
129 | } | |
130 | ||
131 | static inline void | |
fde740e4 | 132 | pmd_populate_kernel(struct mm_struct *mm, pmd_t * pmd_entry, pte_t * pte) |
1da177e4 LT |
133 | { |
134 | pmd_val(*pmd_entry) = __pa(pte); | |
135 | } | |
136 | ||
fde740e4 RH |
137 | static inline struct page *pte_alloc_one(struct mm_struct *mm, |
138 | unsigned long addr) | |
1da177e4 | 139 | { |
fde740e4 | 140 | return virt_to_page(pgtable_quicklist_alloc()); |
1da177e4 LT |
141 | } |
142 | ||
fde740e4 RH |
143 | static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm, |
144 | unsigned long addr) | |
1da177e4 | 145 | { |
fde740e4 | 146 | return pgtable_quicklist_alloc(); |
1da177e4 LT |
147 | } |
148 | ||
fde740e4 | 149 | static inline void pte_free(struct page *pte) |
1da177e4 | 150 | { |
fde740e4 | 151 | pgtable_quicklist_free(page_address(pte)); |
1da177e4 LT |
152 | } |
153 | ||
fde740e4 | 154 | static inline void pte_free_kernel(pte_t * pte) |
1da177e4 | 155 | { |
fde740e4 | 156 | pgtable_quicklist_free(pte); |
1da177e4 LT |
157 | } |
158 | ||
fde740e4 | 159 | #define __pte_free_tlb(tlb, pte) pte_free(pte) |
1da177e4 | 160 | |
fde740e4 | 161 | extern void check_pgt_cache(void); |
1da177e4 | 162 | |
fde740e4 | 163 | #endif /* _ASM_IA64_PGALLOC_H */ |