2005-04-16 16:20:36 -06:00
|
|
|
/* $Id: pgalloc.h,v 1.30 2001/12/21 04:56:17 davem Exp $ */
|
|
|
|
#ifndef _SPARC64_PGALLOC_H
|
|
|
|
#define _SPARC64_PGALLOC_H
|
|
|
|
|
|
|
|
#include <linux/config.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
|
|
|
|
#include <asm/spitfire.h>
|
|
|
|
#include <asm/cpudata.h>
|
|
|
|
#include <asm/cacheflush.h>
|
2005-09-19 21:11:57 -06:00
|
|
|
#include <asm/page.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/* Page table allocation/freeing. */
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
/* Sliiiicck */
|
|
|
|
#define pgt_quicklists local_cpu_data()
|
|
|
|
#else
|
|
|
|
extern struct pgtable_cache_struct {
|
|
|
|
unsigned long *pgd_cache;
|
2006-01-31 19:30:13 -07:00
|
|
|
unsigned long *pte_cache;
|
2005-04-16 16:20:36 -06:00
|
|
|
unsigned int pgcache_size;
|
|
|
|
} pgt_quicklists;
|
|
|
|
#endif
|
|
|
|
#define pgd_quicklist (pgt_quicklists.pgd_cache)
|
|
|
|
#define pte_quicklist (pgt_quicklists.pte_cache)
|
|
|
|
#define pgtable_cache_size (pgt_quicklists.pgcache_size)
|
|
|
|
|
2006-01-31 19:30:13 -07:00
|
|
|
static inline void free_pgd_fast(pgd_t *pgd)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
preempt_disable();
|
|
|
|
*(unsigned long *)pgd = (unsigned long) pgd_quicklist;
|
|
|
|
pgd_quicklist = (unsigned long *) pgd;
|
|
|
|
pgtable_cache_size++;
|
|
|
|
preempt_enable();
|
|
|
|
}
|
|
|
|
|
2006-01-31 19:30:13 -07:00
|
|
|
static inline pgd_t *get_pgd_fast(void)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
unsigned long *ret;
|
|
|
|
|
|
|
|
preempt_disable();
|
|
|
|
if((ret = pgd_quicklist) != NULL) {
|
|
|
|
pgd_quicklist = (unsigned long *)(*ret);
|
|
|
|
ret[0] = 0;
|
|
|
|
pgtable_cache_size--;
|
|
|
|
preempt_enable();
|
|
|
|
} else {
|
|
|
|
preempt_enable();
|
|
|
|
ret = (unsigned long *) __get_free_page(GFP_KERNEL|__GFP_REPEAT);
|
|
|
|
if(ret)
|
|
|
|
memset(ret, 0, PAGE_SIZE);
|
|
|
|
}
|
|
|
|
return (pgd_t *)ret;
|
|
|
|
}
|
|
|
|
|
2006-01-31 19:30:13 -07:00
|
|
|
static inline void free_pgd_slow(pgd_t *pgd)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
free_page((unsigned long)pgd);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
|
|
|
|
|
2006-01-31 19:30:13 -07:00
|
|
|
static inline pmd_t *pmd_alloc_one_fast(void)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
unsigned long *ret;
|
|
|
|
|
|
|
|
preempt_disable();
|
2006-01-31 19:30:13 -07:00
|
|
|
ret = (unsigned long *) pte_quicklist;
|
|
|
|
if (likely(ret)) {
|
|
|
|
pte_quicklist = (unsigned long *)(*ret);
|
2005-04-16 16:20:36 -06:00
|
|
|
ret[0] = 0;
|
|
|
|
pgtable_cache_size--;
|
|
|
|
}
|
|
|
|
preempt_enable();
|
|
|
|
|
2006-01-31 19:30:13 -07:00
|
|
|
return (pmd_t *) ret;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2006-01-31 19:30:13 -07:00
|
|
|
static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
pmd_t *pmd;
|
|
|
|
|
2006-01-31 19:30:13 -07:00
|
|
|
pmd = pmd_alloc_one_fast();
|
|
|
|
if (unlikely(!pmd)) {
|
2005-04-16 16:20:36 -06:00
|
|
|
pmd = (pmd_t *)__get_free_page(GFP_KERNEL|__GFP_REPEAT);
|
|
|
|
if (pmd)
|
|
|
|
memset(pmd, 0, PAGE_SIZE);
|
|
|
|
}
|
|
|
|
return pmd;
|
|
|
|
}
|
|
|
|
|
2006-01-31 19:30:13 -07:00
|
|
|
static inline void free_pmd_fast(pmd_t *pmd)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
preempt_disable();
|
2006-01-31 19:30:13 -07:00
|
|
|
*(unsigned long *)pmd = (unsigned long) pte_quicklist;
|
|
|
|
pte_quicklist = (unsigned long *) pmd;
|
2005-04-16 16:20:36 -06:00
|
|
|
pgtable_cache_size++;
|
|
|
|
preempt_enable();
|
|
|
|
}
|
|
|
|
|
2006-01-31 19:30:13 -07:00
|
|
|
static inline void free_pmd_slow(pmd_t *pmd)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
free_page((unsigned long)pmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define pmd_populate_kernel(MM, PMD, PTE) pmd_set(PMD, PTE)
|
|
|
|
#define pmd_populate(MM,PMD,PTE_PAGE) \
|
|
|
|
pmd_populate_kernel(MM,PMD,page_address(PTE_PAGE))
|
|
|
|
|
2006-01-31 19:30:13 -07:00
|
|
|
static inline pte_t *pte_alloc_one_fast(void)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
unsigned long *ret;
|
|
|
|
|
|
|
|
preempt_disable();
|
2006-01-31 19:30:13 -07:00
|
|
|
ret = (unsigned long *) pte_quicklist;
|
|
|
|
if (likely(ret)) {
|
|
|
|
pte_quicklist = (unsigned long *)(*ret);
|
2005-04-16 16:20:36 -06:00
|
|
|
ret[0] = 0;
|
|
|
|
pgtable_cache_size--;
|
|
|
|
}
|
|
|
|
preempt_enable();
|
2006-01-31 19:30:13 -07:00
|
|
|
|
|
|
|
return (pte_t *) ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address)
|
|
|
|
{
|
|
|
|
pte_t *ptep = pte_alloc_one_fast();
|
|
|
|
|
|
|
|
if (likely(ptep))
|
|
|
|
return ptep;
|
|
|
|
|
|
|
|
return (pte_t *) get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2006-01-31 19:30:13 -07:00
|
|
|
static inline struct page *pte_alloc_one(struct mm_struct *mm, unsigned long addr)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2006-01-31 19:30:13 -07:00
|
|
|
pte_t *pte = pte_alloc_one_fast();
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2006-01-31 19:30:13 -07:00
|
|
|
if (likely(pte))
|
|
|
|
return virt_to_page(pte);
|
|
|
|
|
|
|
|
return alloc_pages(GFP_KERNEL|__GFP_REPEAT|__GFP_ZERO, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void free_pte_fast(pte_t *pte)
|
|
|
|
{
|
2005-04-16 16:20:36 -06:00
|
|
|
preempt_disable();
|
2006-01-31 19:30:13 -07:00
|
|
|
*(unsigned long *)pte = (unsigned long) pte_quicklist;
|
|
|
|
pte_quicklist = (unsigned long *) pte;
|
2005-04-16 16:20:36 -06:00
|
|
|
pgtable_cache_size++;
|
|
|
|
preempt_enable();
|
|
|
|
}
|
|
|
|
|
2006-01-31 19:30:13 -07:00
|
|
|
static inline void free_pte_slow(pte_t *pte)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2006-01-31 19:30:13 -07:00
|
|
|
free_page((unsigned long) pte);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void pte_free_kernel(pte_t *pte)
|
|
|
|
{
|
|
|
|
free_pte_fast(pte);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void pte_free(struct page *ptepage)
|
|
|
|
{
|
|
|
|
free_pte_fast(page_address(ptepage));
|
|
|
|
}
|
|
|
|
|
|
|
|
#define pmd_free(pmd) free_pmd_fast(pmd)
|
|
|
|
#define pgd_free(pgd) free_pgd_fast(pgd)
|
|
|
|
#define pgd_alloc(mm) get_pgd_fast()
|
|
|
|
|
|
|
|
#endif /* _SPARC64_PGALLOC_H */
|