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[2];
23 unsigned int pgcache_size;
26 #define pgd_quicklist (pgt_quicklists.pgd_cache)
27 #define pmd_quicklist ((unsigned long *)0)
28 #define pte_quicklist (pgt_quicklists.pte_cache)
29 #define pgtable_cache_size (pgt_quicklists.pgcache_size)
31 static __inline__ void free_pgd_fast(pgd_t *pgd)
34 *(unsigned long *)pgd = (unsigned long) pgd_quicklist;
35 pgd_quicklist = (unsigned long *) pgd;
40 static __inline__ pgd_t *get_pgd_fast(void)
45 if((ret = pgd_quicklist) != NULL) {
46 pgd_quicklist = (unsigned long *)(*ret);
52 ret = (unsigned long *) __get_free_page(GFP_KERNEL|__GFP_REPEAT);
54 memset(ret, 0, PAGE_SIZE);
59 static __inline__ void free_pgd_slow(pgd_t *pgd)
61 free_page((unsigned long)pgd);
64 #ifdef DCACHE_ALIASING_POSSIBLE
65 #define VPTE_COLOR(address) (((address) >> (PAGE_SHIFT + 10)) & 1UL)
66 #define DCACHE_COLOR(address) (((address) >> PAGE_SHIFT) & 1UL)
68 #define VPTE_COLOR(address) 0
69 #define DCACHE_COLOR(address) 0
72 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
74 static __inline__ pmd_t *pmd_alloc_one_fast(struct mm_struct *mm, unsigned long address)
80 if (pte_quicklist[color] == NULL)
83 if((ret = (unsigned long *)pte_quicklist[color]) != NULL) {
84 pte_quicklist[color] = (unsigned long *)(*ret);
93 static __inline__ pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
97 pmd = pmd_alloc_one_fast(mm, address);
99 pmd = (pmd_t *)__get_free_page(GFP_KERNEL|__GFP_REPEAT);
101 memset(pmd, 0, PAGE_SIZE);
106 static __inline__ void free_pmd_fast(pmd_t *pmd)
108 unsigned long color = DCACHE_COLOR((unsigned long)pmd);
111 *(unsigned long *)pmd = (unsigned long) pte_quicklist[color];
112 pte_quicklist[color] = (unsigned long *) pmd;
113 pgtable_cache_size++;
117 static __inline__ void free_pmd_slow(pmd_t *pmd)
119 free_page((unsigned long)pmd);
122 #define pmd_populate_kernel(MM, PMD, PTE) pmd_set(PMD, PTE)
123 #define pmd_populate(MM,PMD,PTE_PAGE) \
124 pmd_populate_kernel(MM,PMD,page_address(PTE_PAGE))
126 extern pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address);
128 static inline struct page *
129 pte_alloc_one(struct mm_struct *mm, unsigned long addr)
131 pte_t *pte = pte_alloc_one_kernel(mm, addr);
134 return virt_to_page(pte);
139 static __inline__ pte_t *pte_alloc_one_fast(struct mm_struct *mm, unsigned long address)
141 unsigned long color = VPTE_COLOR(address);
145 if((ret = (unsigned long *)pte_quicklist[color]) != NULL) {
146 pte_quicklist[color] = (unsigned long *)(*ret);
148 pgtable_cache_size--;
154 static __inline__ void free_pte_fast(pte_t *pte)
156 unsigned long color = DCACHE_COLOR((unsigned long)pte);
159 *(unsigned long *)pte = (unsigned long) pte_quicklist[color];
160 pte_quicklist[color] = (unsigned long *) pte;
161 pgtable_cache_size++;
165 static __inline__ void free_pte_slow(pte_t *pte)
167 free_page((unsigned long)pte);
170 static inline void pte_free_kernel(pte_t *pte)
175 static inline void pte_free(struct page *ptepage)
177 free_pte_fast(page_address(ptepage));
180 #define pmd_free(pmd) free_pmd_fast(pmd)
181 #define pgd_free(pgd) free_pgd_fast(pgd)
182 #define pgd_alloc(mm) get_pgd_fast()
184 #endif /* _SPARC64_PGALLOC_H */