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>
10 #include <asm/spitfire.h>
11 #include <asm/cpudata.h>
12 #include <asm/cacheflush.h>
15 /* Page table allocation/freeing. */
18 #define pgt_quicklists local_cpu_data()
20 extern struct pgtable_cache_struct {
21 unsigned long *pgd_cache;
22 unsigned long *pte_cache;
23 unsigned int pgcache_size;
26 #define pgd_quicklist (pgt_quicklists.pgd_cache)
27 #define pte_quicklist (pgt_quicklists.pte_cache)
28 #define pgtable_cache_size (pgt_quicklists.pgcache_size)
30 static inline void free_pgd_fast(pgd_t *pgd)
33 *(unsigned long *)pgd = (unsigned long) pgd_quicklist;
34 pgd_quicklist = (unsigned long *) pgd;
39 static inline pgd_t *get_pgd_fast(void)
44 if((ret = pgd_quicklist) != NULL) {
45 pgd_quicklist = (unsigned long *)(*ret);
51 ret = (unsigned long *) __get_free_page(GFP_KERNEL|__GFP_REPEAT);
53 memset(ret, 0, PAGE_SIZE);
58 static inline void free_pgd_slow(pgd_t *pgd)
60 free_page((unsigned long)pgd);
63 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
65 static inline pmd_t *pmd_alloc_one_fast(void)
70 ret = (unsigned long *) pte_quicklist;
72 pte_quicklist = (unsigned long *)(*ret);
81 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
85 pmd = pmd_alloc_one_fast();
87 pmd = (pmd_t *)__get_free_page(GFP_KERNEL|__GFP_REPEAT);
89 memset(pmd, 0, PAGE_SIZE);
94 static inline void free_pmd_fast(pmd_t *pmd)
97 *(unsigned long *)pmd = (unsigned long) pte_quicklist;
98 pte_quicklist = (unsigned long *) pmd;
103 static inline void free_pmd_slow(pmd_t *pmd)
105 free_page((unsigned long)pmd);
108 #define pmd_populate_kernel(MM, PMD, PTE) pmd_set(PMD, PTE)
109 #define pmd_populate(MM,PMD,PTE_PAGE) \
110 pmd_populate_kernel(MM,PMD,page_address(PTE_PAGE))
112 static inline pte_t *pte_alloc_one_fast(void)
117 ret = (unsigned long *) pte_quicklist;
119 pte_quicklist = (unsigned long *)(*ret);
121 pgtable_cache_size--;
125 return (pte_t *) ret;
128 static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address)
130 pte_t *ptep = pte_alloc_one_fast();
135 return (pte_t *) get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
138 static inline struct page *pte_alloc_one(struct mm_struct *mm, unsigned long addr)
140 pte_t *pte = pte_alloc_one_fast();
143 return virt_to_page(pte);
145 return alloc_pages(GFP_KERNEL|__GFP_REPEAT|__GFP_ZERO, 0);
148 static inline void free_pte_fast(pte_t *pte)
151 *(unsigned long *)pte = (unsigned long) pte_quicklist;
152 pte_quicklist = (unsigned long *) pte;
153 pgtable_cache_size++;
157 static inline void free_pte_slow(pte_t *pte)
159 free_page((unsigned long) pte);
162 static inline void pte_free_kernel(pte_t *pte)
167 static inline void pte_free(struct page *ptepage)
169 free_pte_fast(page_address(ptepage));
172 #define pmd_free(pmd) free_pmd_fast(pmd)
173 #define pgd_free(pgd) free_pgd_fast(pgd)
174 #define pgd_alloc(mm) get_pgd_fast()
176 #endif /* _SPARC64_PGALLOC_H */