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>
14 /* Page table allocation/freeing. */
17 #define pgt_quicklists local_cpu_data()
19 extern struct pgtable_cache_struct {
20 unsigned long *pgd_cache;
21 unsigned long *pte_cache[2];
22 unsigned int pgcache_size;
25 #define pgd_quicklist (pgt_quicklists.pgd_cache)
26 #define pmd_quicklist ((unsigned long *)0)
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 #ifdef DCACHE_ALIASING_POSSIBLE
64 #define VPTE_COLOR(address) (((address) >> (PAGE_SHIFT + 10)) & 1UL)
65 #define DCACHE_COLOR(address) (((address) >> PAGE_SHIFT) & 1UL)
67 #define VPTE_COLOR(address) 0
68 #define DCACHE_COLOR(address) 0
71 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
73 static __inline__ pmd_t *pmd_alloc_one_fast(struct mm_struct *mm, unsigned long address)
79 if (pte_quicklist[color] == NULL)
82 if((ret = (unsigned long *)pte_quicklist[color]) != NULL) {
83 pte_quicklist[color] = (unsigned long *)(*ret);
92 static __inline__ pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
96 pmd = pmd_alloc_one_fast(mm, address);
98 pmd = (pmd_t *)__get_free_page(GFP_KERNEL|__GFP_REPEAT);
100 memset(pmd, 0, PAGE_SIZE);
105 static __inline__ void free_pmd_fast(pmd_t *pmd)
107 unsigned long color = DCACHE_COLOR((unsigned long)pmd);
110 *(unsigned long *)pmd = (unsigned long) pte_quicklist[color];
111 pte_quicklist[color] = (unsigned long *) pmd;
112 pgtable_cache_size++;
116 static __inline__ void free_pmd_slow(pmd_t *pmd)
118 free_page((unsigned long)pmd);
121 #define pmd_populate_kernel(MM, PMD, PTE) pmd_set(PMD, PTE)
122 #define pmd_populate(MM,PMD,PTE_PAGE) \
123 pmd_populate_kernel(MM,PMD,page_address(PTE_PAGE))
125 extern pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address);
127 static inline struct page *
128 pte_alloc_one(struct mm_struct *mm, unsigned long addr)
130 pte_t *pte = pte_alloc_one_kernel(mm, addr);
133 return virt_to_page(pte);
138 static __inline__ pte_t *pte_alloc_one_fast(struct mm_struct *mm, unsigned long address)
140 unsigned long color = VPTE_COLOR(address);
144 if((ret = (unsigned long *)pte_quicklist[color]) != NULL) {
145 pte_quicklist[color] = (unsigned long *)(*ret);
147 pgtable_cache_size--;
153 static __inline__ void free_pte_fast(pte_t *pte)
155 unsigned long color = DCACHE_COLOR((unsigned long)pte);
158 *(unsigned long *)pte = (unsigned long) pte_quicklist[color];
159 pte_quicklist[color] = (unsigned long *) pte;
160 pgtable_cache_size++;
164 static __inline__ void free_pte_slow(pte_t *pte)
166 free_page((unsigned long)pte);
169 static inline void pte_free_kernel(pte_t *pte)
174 static inline void pte_free(struct page *ptepage)
176 free_pte_fast(page_address(ptepage));
179 #define pmd_free(pmd) free_pmd_fast(pmd)
180 #define pgd_free(pgd) free_pgd_fast(pgd)
181 #define pgd_alloc(mm) get_pgd_fast()
183 #endif /* _SPARC64_PGALLOC_H */