1 /* $Id: pgalloc.h,v 1.30 2001/12/21 04:56:17 davem Exp $ */
2 #ifndef _SPARC64_PGALLOC_H
3 #define _SPARC64_PGALLOC_H
5 #include <linux/config.h>
6 #include <linux/kernel.h>
7 #include <linux/sched.h>
11 #include <asm/spitfire.h>
12 #include <asm/pgtable.h>
13 #include <asm/cpudata.h>
15 /* Page table allocation/freeing. */
18 #define pgt_quicklists cpu_data(smp_processor_id())
20 extern struct pgtable_cache_struct {
21 unsigned long *pgd_cache;
22 unsigned long *pte_cache[2];
23 unsigned int pgcache_size;
24 unsigned int pgdcache_size;
27 #define pgd_quicklist (pgt_quicklists.pgd_cache)
28 #define pmd_quicklist ((unsigned long *)0)
29 #define pte_quicklist (pgt_quicklists.pte_cache)
30 #define pgtable_cache_size (pgt_quicklists.pgcache_size)
31 #define pgd_cache_size (pgt_quicklists.pgdcache_size)
35 static __inline__ void free_pgd_fast(pgd_t *pgd)
37 struct page *page = virt_to_page(pgd);
40 if (!page->lru.prev) {
41 page->lru.next = (void *) pgd_quicklist;
42 pgd_quicklist = (unsigned long *)page;
44 page->lru.prev = (void *)
45 (((unsigned long)page->lru.prev) |
46 (((unsigned long)pgd & (PAGE_SIZE / 2)) ? 2 : 1));
51 static __inline__ pgd_t *get_pgd_fast(void)
56 if ((ret = (struct page *)pgd_quicklist) != NULL) {
57 unsigned long mask = (unsigned long)ret->lru.prev;
58 unsigned long off = 0;
66 ret->lru.prev = (void *) mask;
68 pgd_quicklist = (unsigned long *)ret->lru.next;
69 ret = (struct page *)(__page_address(ret) + off);
76 page = alloc_page(GFP_KERNEL|__GFP_REPEAT);
78 ret = (struct page *)page_address(page);
80 page->lru.prev = (void *) 2UL;
83 page->lru.next = (void *) pgd_quicklist;
84 pgd_quicklist = (unsigned long *)page;
92 #else /* CONFIG_SMP */
94 static __inline__ void free_pgd_fast(pgd_t *pgd)
97 *(unsigned long *)pgd = (unsigned long) pgd_quicklist;
98 pgd_quicklist = (unsigned long *) pgd;
103 static __inline__ pgd_t *get_pgd_fast(void)
108 if((ret = pgd_quicklist) != NULL) {
109 pgd_quicklist = (unsigned long *)(*ret);
111 pgtable_cache_size--;
115 ret = (unsigned long *) __get_free_page(GFP_KERNEL|__GFP_REPEAT);
117 memset(ret, 0, PAGE_SIZE);
122 static __inline__ void free_pgd_slow(pgd_t *pgd)
124 free_page((unsigned long)pgd);
127 #endif /* CONFIG_SMP */
129 #if (L1DCACHE_SIZE > PAGE_SIZE) /* is there D$ aliasing problem */
130 #define VPTE_COLOR(address) (((address) >> (PAGE_SHIFT + 10)) & 1UL)
131 #define DCACHE_COLOR(address) (((address) >> PAGE_SHIFT) & 1UL)
133 #define VPTE_COLOR(address) 0
134 #define DCACHE_COLOR(address) 0
137 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
139 static __inline__ pmd_t *pmd_alloc_one_fast(struct mm_struct *mm, unsigned long address)
145 if (pte_quicklist[color] == NULL)
148 if((ret = (unsigned long *)pte_quicklist[color]) != NULL) {
149 pte_quicklist[color] = (unsigned long *)(*ret);
151 pgtable_cache_size--;
158 static __inline__ pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
162 pmd = pmd_alloc_one_fast(mm, address);
164 pmd = (pmd_t *)__get_free_page(GFP_KERNEL|__GFP_REPEAT);
166 memset(pmd, 0, PAGE_SIZE);
171 static __inline__ void free_pmd_fast(pmd_t *pmd)
173 unsigned long color = DCACHE_COLOR((unsigned long)pmd);
176 *(unsigned long *)pmd = (unsigned long) pte_quicklist[color];
177 pte_quicklist[color] = (unsigned long *) pmd;
178 pgtable_cache_size++;
182 static __inline__ void free_pmd_slow(pmd_t *pmd)
184 free_page((unsigned long)pmd);
187 #define pmd_populate_kernel(MM, PMD, PTE) pmd_set(PMD, PTE)
188 #define pmd_populate(MM,PMD,PTE_PAGE) \
189 pmd_populate_kernel(MM,PMD,page_address(PTE_PAGE))
191 extern pte_t *__pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address);
193 static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address)
195 pte_t *pte = __pte_alloc_one_kernel(mm, address);
197 struct page *page = virt_to_page(pte);
198 page->mapping = (void *) mm;
199 page->index = address & PMD_MASK;
204 static inline struct page *
205 pte_alloc_one(struct mm_struct *mm, unsigned long addr)
207 pte_t *pte = __pte_alloc_one_kernel(mm, addr);
209 struct page *page = virt_to_page(pte);
210 page->mapping = (void *) mm;
211 page->index = addr & PMD_MASK;
217 static __inline__ pte_t *pte_alloc_one_fast(struct mm_struct *mm, unsigned long address)
219 unsigned long color = VPTE_COLOR(address);
223 if((ret = (unsigned long *)pte_quicklist[color]) != NULL) {
224 pte_quicklist[color] = (unsigned long *)(*ret);
226 pgtable_cache_size--;
232 static __inline__ void free_pte_fast(pte_t *pte)
234 unsigned long color = DCACHE_COLOR((unsigned long)pte);
237 *(unsigned long *)pte = (unsigned long) pte_quicklist[color];
238 pte_quicklist[color] = (unsigned long *) pte;
239 pgtable_cache_size++;
243 static __inline__ void free_pte_slow(pte_t *pte)
245 free_page((unsigned long)pte);
248 static inline void pte_free_kernel(pte_t *pte)
250 virt_to_page(pte)->mapping = NULL;
254 static inline void pte_free(struct page *ptepage)
256 ptepage->mapping = NULL;
257 free_pte_fast(page_address(ptepage));
260 #define pmd_free(pmd) free_pmd_fast(pmd)
261 #define pgd_free(pgd) free_pgd_fast(pgd)
262 #define pgd_alloc(mm) get_pgd_fast()
264 #endif /* _SPARC64_PGALLOC_H */