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|__GFP_ZERO);
78 ret = (struct page *)page_address(page);
79 page->lru.prev = (void *) 2UL;
82 page->lru.next = (void *) pgd_quicklist;
83 pgd_quicklist = (unsigned long *)page;
91 #else /* CONFIG_SMP */
93 static __inline__ void free_pgd_fast(pgd_t *pgd)
96 *(unsigned long *)pgd = (unsigned long) pgd_quicklist;
97 pgd_quicklist = (unsigned long *) pgd;
102 static __inline__ pgd_t *get_pgd_fast(void)
107 if((ret = pgd_quicklist) != NULL) {
108 pgd_quicklist = (unsigned long *)(*ret);
110 pgtable_cache_size--;
114 ret = (unsigned long *) __get_free_page(GFP_KERNEL|__GFP_REPEAT);
116 memset(ret, 0, PAGE_SIZE);
121 static __inline__ void free_pgd_slow(pgd_t *pgd)
123 free_page((unsigned long)pgd);
126 #endif /* CONFIG_SMP */
128 #if (L1DCACHE_SIZE > PAGE_SIZE) /* is there D$ aliasing problem */
129 #define VPTE_COLOR(address) (((address) >> (PAGE_SHIFT + 10)) & 1UL)
130 #define DCACHE_COLOR(address) (((address) >> PAGE_SHIFT) & 1UL)
132 #define VPTE_COLOR(address) 0
133 #define DCACHE_COLOR(address) 0
136 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
138 static __inline__ pmd_t *pmd_alloc_one_fast(struct mm_struct *mm, unsigned long address)
144 if (pte_quicklist[color] == NULL)
147 if((ret = (unsigned long *)pte_quicklist[color]) != NULL) {
148 pte_quicklist[color] = (unsigned long *)(*ret);
150 pgtable_cache_size--;
157 static __inline__ pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
161 pmd = pmd_alloc_one_fast(mm, address);
163 pmd = (pmd_t *)__get_free_page(GFP_KERNEL|__GFP_REPEAT);
165 memset(pmd, 0, PAGE_SIZE);
170 static __inline__ void free_pmd_fast(pmd_t *pmd)
172 unsigned long color = DCACHE_COLOR((unsigned long)pmd);
175 *(unsigned long *)pmd = (unsigned long) pte_quicklist[color];
176 pte_quicklist[color] = (unsigned long *) pmd;
177 pgtable_cache_size++;
181 static __inline__ void free_pmd_slow(pmd_t *pmd)
183 free_page((unsigned long)pmd);
186 #define pmd_populate_kernel(MM, PMD, PTE) pmd_set(PMD, PTE)
187 #define pmd_populate(MM,PMD,PTE_PAGE) \
188 pmd_populate_kernel(MM,PMD,page_address(PTE_PAGE))
190 extern pte_t *__pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address);
192 static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address)
194 pte_t *pte = __pte_alloc_one_kernel(mm, address);
196 struct page *page = virt_to_page(pte);
197 page->mapping = (void *) mm;
198 page->index = address & PMD_MASK;
203 static inline struct page *
204 pte_alloc_one(struct mm_struct *mm, unsigned long addr)
206 pte_t *pte = __pte_alloc_one_kernel(mm, addr);
208 struct page *page = virt_to_page(pte);
209 page->mapping = (void *) mm;
210 page->index = addr & PMD_MASK;
216 static __inline__ pte_t *pte_alloc_one_fast(struct mm_struct *mm, unsigned long address)
218 unsigned long color = VPTE_COLOR(address);
222 if((ret = (unsigned long *)pte_quicklist[color]) != NULL) {
223 pte_quicklist[color] = (unsigned long *)(*ret);
225 pgtable_cache_size--;
231 static __inline__ void free_pte_fast(pte_t *pte)
233 unsigned long color = DCACHE_COLOR((unsigned long)pte);
236 *(unsigned long *)pte = (unsigned long) pte_quicklist[color];
237 pte_quicklist[color] = (unsigned long *) pte;
238 pgtable_cache_size++;
242 static __inline__ void free_pte_slow(pte_t *pte)
244 free_page((unsigned long)pte);
247 static inline void pte_free_kernel(pte_t *pte)
249 virt_to_page(pte)->mapping = NULL;
253 static inline void pte_free(struct page *ptepage)
255 ptepage->mapping = NULL;
256 free_pte_fast(page_address(ptepage));
259 #define pmd_free(pmd) free_pmd_fast(pmd)
260 #define pgd_free(pgd) free_pgd_fast(pgd)
261 #define pgd_alloc(mm) get_pgd_fast()
263 #endif /* _SPARC64_PGALLOC_H */