blob: ecea1bbdc11549e05f097b5bf75c5ceeb1af270b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* $Id: pgalloc.h,v 1.30 2001/12/21 04:56:17 davem Exp $ */
2#ifndef _SPARC64_PGALLOC_H
3#define _SPARC64_PGALLOC_H
4
5#include <linux/config.h>
6#include <linux/kernel.h>
7#include <linux/sched.h>
8#include <linux/mm.h>
9
10#include <asm/spitfire.h>
11#include <asm/cpudata.h>
12#include <asm/cacheflush.h>
David S. Miller6a9b4902005-09-19 20:11:57 -070013#include <asm/page.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014
15/* Page table allocation/freeing. */
16#ifdef CONFIG_SMP
17/* Sliiiicck */
18#define pgt_quicklists local_cpu_data()
19#else
20extern struct pgtable_cache_struct {
21 unsigned long *pgd_cache;
David S. Miller05e28f92006-01-31 18:30:13 -080022 unsigned long *pte_cache;
Linus Torvalds1da177e2005-04-16 15:20:36 -070023 unsigned int pgcache_size;
24} pgt_quicklists;
25#endif
26#define pgd_quicklist (pgt_quicklists.pgd_cache)
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#define pte_quicklist (pgt_quicklists.pte_cache)
28#define pgtable_cache_size (pgt_quicklists.pgcache_size)
29
David S. Miller05e28f92006-01-31 18:30:13 -080030static inline void free_pgd_fast(pgd_t *pgd)
Linus Torvalds1da177e2005-04-16 15:20:36 -070031{
32 preempt_disable();
33 *(unsigned long *)pgd = (unsigned long) pgd_quicklist;
34 pgd_quicklist = (unsigned long *) pgd;
35 pgtable_cache_size++;
36 preempt_enable();
37}
38
David S. Miller05e28f92006-01-31 18:30:13 -080039static inline pgd_t *get_pgd_fast(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070040{
41 unsigned long *ret;
42
43 preempt_disable();
44 if((ret = pgd_quicklist) != NULL) {
45 pgd_quicklist = (unsigned long *)(*ret);
46 ret[0] = 0;
47 pgtable_cache_size--;
48 preempt_enable();
49 } else {
50 preempt_enable();
51 ret = (unsigned long *) __get_free_page(GFP_KERNEL|__GFP_REPEAT);
52 if(ret)
53 memset(ret, 0, PAGE_SIZE);
54 }
55 return (pgd_t *)ret;
56}
57
David S. Miller05e28f92006-01-31 18:30:13 -080058static inline void free_pgd_slow(pgd_t *pgd)
Linus Torvalds1da177e2005-04-16 15:20:36 -070059{
60 free_page((unsigned long)pgd);
61}
62
Linus Torvalds1da177e2005-04-16 15:20:36 -070063#define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
64
David S. Miller05e28f92006-01-31 18:30:13 -080065static inline pmd_t *pmd_alloc_one_fast(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066{
67 unsigned long *ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
69 preempt_disable();
David S. Miller05e28f92006-01-31 18:30:13 -080070 ret = (unsigned long *) pte_quicklist;
71 if (likely(ret)) {
72 pte_quicklist = (unsigned long *)(*ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 ret[0] = 0;
74 pgtable_cache_size--;
75 }
76 preempt_enable();
77
David S. Miller05e28f92006-01-31 18:30:13 -080078 return (pmd_t *) ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079}
80
David S. Miller05e28f92006-01-31 18:30:13 -080081static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
Linus Torvalds1da177e2005-04-16 15:20:36 -070082{
83 pmd_t *pmd;
84
David S. Miller05e28f92006-01-31 18:30:13 -080085 pmd = pmd_alloc_one_fast();
86 if (unlikely(!pmd)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 pmd = (pmd_t *)__get_free_page(GFP_KERNEL|__GFP_REPEAT);
88 if (pmd)
89 memset(pmd, 0, PAGE_SIZE);
90 }
91 return pmd;
92}
93
David S. Miller05e28f92006-01-31 18:30:13 -080094static inline void free_pmd_fast(pmd_t *pmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -070095{
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 preempt_disable();
David S. Miller05e28f92006-01-31 18:30:13 -080097 *(unsigned long *)pmd = (unsigned long) pte_quicklist;
98 pte_quicklist = (unsigned long *) pmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 pgtable_cache_size++;
100 preempt_enable();
101}
102
David S. Miller05e28f92006-01-31 18:30:13 -0800103static inline void free_pmd_slow(pmd_t *pmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104{
105 free_page((unsigned long)pmd);
106}
107
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))
111
David S. Miller05e28f92006-01-31 18:30:13 -0800112static inline pte_t *pte_alloc_one_fast(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 unsigned long *ret;
115
116 preempt_disable();
David S. Miller05e28f92006-01-31 18:30:13 -0800117 ret = (unsigned long *) pte_quicklist;
118 if (likely(ret)) {
119 pte_quicklist = (unsigned long *)(*ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 ret[0] = 0;
121 pgtable_cache_size--;
122 }
123 preempt_enable();
David S. Miller05e28f92006-01-31 18:30:13 -0800124
125 return (pte_t *) ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126}
127
David S. Miller05e28f92006-01-31 18:30:13 -0800128static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129{
David S. Miller05e28f92006-01-31 18:30:13 -0800130 pte_t *ptep = pte_alloc_one_fast();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
David S. Miller05e28f92006-01-31 18:30:13 -0800132 if (likely(ptep))
133 return ptep;
134
135 return (pte_t *) get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
136}
137
138static inline struct page *pte_alloc_one(struct mm_struct *mm, unsigned long addr)
139{
140 pte_t *pte = pte_alloc_one_fast();
141
142 if (likely(pte))
143 return virt_to_page(pte);
144
145 return alloc_pages(GFP_KERNEL|__GFP_REPEAT|__GFP_ZERO, 0);
146}
147
148static inline void free_pte_fast(pte_t *pte)
149{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 preempt_disable();
David S. Miller05e28f92006-01-31 18:30:13 -0800151 *(unsigned long *)pte = (unsigned long) pte_quicklist;
152 pte_quicklist = (unsigned long *) pte;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 pgtable_cache_size++;
154 preempt_enable();
155}
156
David S. Miller05e28f92006-01-31 18:30:13 -0800157static inline void free_pte_slow(pte_t *pte)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158{
David S. Miller05e28f92006-01-31 18:30:13 -0800159 free_page((unsigned long) pte);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160}
161
162static inline void pte_free_kernel(pte_t *pte)
163{
164 free_pte_fast(pte);
165}
166
167static inline void pte_free(struct page *ptepage)
168{
169 free_pte_fast(page_address(ptepage));
170}
171
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()
175
176#endif /* _SPARC64_PGALLOC_H */