1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
|
#ifndef _X86_64_PGALLOC_H
#define _X86_64_PGALLOC_H
#include <linux/config.h>
#include <asm/processor.h>
#include <asm/fixmap.h>
#include <asm/pda.h>
#include <linux/threads.h>
#include <linux/mm.h>
#include <asm/page.h>
#define inc_pgcache_size() add_pda(pgtable_cache_sz,1UL)
#define dec_pgcache_size() sub_pda(pgtable_cache_sz,1UL)
#define pmd_populate(mm, pmd, pte) \
set_pmd(pmd, __pmd(_PAGE_TABLE | __pa(pte)))
#define pgd_populate(mm, pgd, pmd) \
set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pmd)))
extern __inline__ pmd_t *get_pmd_slow(void)
{
return (pmd_t *)get_zeroed_page(GFP_KERNEL);
}
extern __inline__ pmd_t *get_pmd_fast(void)
{
unsigned long *ret;
if ((ret = read_pda(pmd_quick)) != NULL) {
write_pda(pmd_quick, (unsigned long *)(*ret));
ret[0] = 0;
dec_pgcache_size();
} else
ret = (unsigned long *)get_pmd_slow();
return (pmd_t *)ret;
}
extern __inline__ void pmd_free(pmd_t *pmd)
{
*(unsigned long *)pmd = (unsigned long) read_pda(pmd_quick);
write_pda(pmd_quick,(unsigned long *) pmd);
inc_pgcache_size();
}
extern __inline__ void pmd_free_slow(pmd_t *pmd)
{
if ((unsigned long)pmd & (PAGE_SIZE-1))
out_of_line_bug();
free_page((unsigned long)pmd);
}
static inline pmd_t *pmd_alloc_one_fast (struct mm_struct *mm, unsigned long addr)
{
unsigned long *ret = (unsigned long *)read_pda(pmd_quick);
if (ret != NULL) {
write_pda(pmd_quick, (unsigned long *)(*ret));
ret[0] = 0;
dec_pgcache_size();
}
return (pmd_t *)ret;
}
static inline pmd_t *pmd_alloc_one (struct mm_struct *mm, unsigned long addr)
{
return (pmd_t *)get_zeroed_page(GFP_KERNEL);
}
static inline pgd_t *pgd_alloc_one_fast (void)
{
unsigned long *ret = read_pda(pgd_quick);
if (ret) {
write_pda(pgd_quick,(unsigned long *)(*ret));
ret[0] = 0;
dec_pgcache_size();
}
return (pgd_t *) ret;
}
static inline pgd_t *pgd_alloc (struct mm_struct *mm)
{
/* the VM system never calls pgd_alloc_one_fast(), so we do it here. */
pgd_t *pgd = pgd_alloc_one_fast();
if (pgd == NULL)
pgd = (pgd_t *)get_zeroed_page(GFP_KERNEL);
return pgd;
}
static inline void pgd_free (pgd_t *pgd)
{
*(unsigned long *)pgd = (unsigned long) read_pda(pgd_quick);
write_pda(pgd_quick,(unsigned long *) pgd);
inc_pgcache_size();
}
static inline void pgd_free_slow (pgd_t *pgd)
{
if ((unsigned long)pgd & (PAGE_SIZE-1))
out_of_line_bug();
free_page((unsigned long)pgd);
}
static inline pte_t *pte_alloc_one(struct mm_struct *mm, unsigned long address)
{
return (pte_t *)get_zeroed_page(GFP_KERNEL);
}
extern __inline__ pte_t *pte_alloc_one_fast(struct mm_struct *mm, unsigned long address)
{
unsigned long *ret;
if ((ret = read_pda(pte_quick)) != NULL) {
write_pda(pte_quick, (unsigned long *)(*ret));
ret[0] = ret[1];
dec_pgcache_size();
}
return (pte_t *)ret;
}
/* Should really implement gc for free page table pages. This could be done with
a reference count in struct page. */
extern __inline__ void pte_free(pte_t *pte)
{
*(unsigned long *)pte = (unsigned long) read_pda(pte_quick);
write_pda(pte_quick, (unsigned long *) pte);
inc_pgcache_size();
}
extern __inline__ void pte_free_slow(pte_t *pte)
{
if ((unsigned long)pte & (PAGE_SIZE-1))
out_of_line_bug();
free_page((unsigned long)pte);
}
extern int do_check_pgt_cache(int, int);
/*
* TLB flushing:
*
* - flush_tlb() flushes the current mm struct TLBs
* - flush_tlb_all() flushes all processes TLBs
* - flush_tlb_mm(mm) flushes the specified mm context TLB's
* - flush_tlb_page(vma, vmaddr) flushes one page
* - flush_tlb_range(mm, start, end) flushes a range of pages
* - flush_tlb_pgtables(mm, start, end) flushes a range of page tables
*/
#ifndef CONFIG_SMP
#define flush_tlb() __flush_tlb()
#define flush_tlb_all() __flush_tlb_all()
#define local_flush_tlb() __flush_tlb()
static inline void flush_tlb_mm(struct mm_struct *mm)
{
if (mm == current->active_mm)
__flush_tlb();
}
static inline void flush_tlb_page(struct vm_area_struct *vma,
unsigned long addr)
{
if (vma->vm_mm == current->active_mm)
__flush_tlb_one(addr);
}
static inline void flush_tlb_range(struct mm_struct *mm,
unsigned long start, unsigned long end)
{
if (mm == current->active_mm)
__flush_tlb();
}
#else
#include <asm/smp.h>
#define local_flush_tlb() \
__flush_tlb()
extern void flush_tlb_all(void);
extern void flush_tlb_current_task(void);
extern void flush_tlb_mm(struct mm_struct *);
extern void flush_tlb_page(struct vm_area_struct *, unsigned long);
#define flush_tlb() flush_tlb_current_task()
static inline void flush_tlb_range(struct mm_struct * mm, unsigned long start, unsigned long end)
{
flush_tlb_mm(mm);
}
#define TLBSTATE_OK 1
#define TLBSTATE_LAZY 2
struct tlb_state
{
struct mm_struct *active_mm;
int state;
} ____cacheline_aligned;
extern struct tlb_state cpu_tlbstate[NR_CPUS];
#endif
extern inline void flush_tlb_pgtables(struct mm_struct *mm,
unsigned long start, unsigned long end)
{
flush_tlb_mm(mm);
}
#endif /* _X86_64_PGALLOC_H */
|