pgalloc.h 3.5 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#ifndef _ASM_IA64_PGALLOC_H
#define _ASM_IA64_PGALLOC_H

/*
 * This file contains the functions and defines necessary to allocate
 * page tables.
 *
 * This hopefully works with any (fixed) ia-64 page-size, as defined
 * in <asm/page.h> (currently 8192).
 *
 * Copyright (C) 1998-2001 Hewlett-Packard Co
 *	David Mosberger-Tang <davidm@hpl.hp.com>
 * Copyright (C) 2000, Goutham Rao <goutham.rao@intel.com>
 */


#include <linux/compiler.h>
#include <linux/mm.h>
#include <linux/page-flags.h>
#include <linux/threads.h>

#include <asm/mmu_context.h>

24 25 26 27
DECLARE_PER_CPU(unsigned long *, __pgtable_quicklist);
#define pgtable_quicklist __ia64_per_cpu_var(__pgtable_quicklist)
DECLARE_PER_CPU(long, __pgtable_quicklist_size);
#define pgtable_quicklist_size __ia64_per_cpu_var(__pgtable_quicklist_size)
L
Linus Torvalds 已提交
28

29 30
static inline long pgtable_quicklist_total_size(void)
{
31
	long ql_size = 0;
32 33 34 35 36 37 38 39 40
	int cpuid;

	for_each_online_cpu(cpuid) {
		ql_size += per_cpu(__pgtable_quicklist_size, cpuid);
	}
	return ql_size;
}

static inline void *pgtable_quicklist_alloc(void)
L
Linus Torvalds 已提交
41 42 43 44 45
{
	unsigned long *ret = NULL;

	preempt_disable();

46
	ret = pgtable_quicklist;
L
Linus Torvalds 已提交
47
	if (likely(ret != NULL)) {
48
		pgtable_quicklist = (unsigned long *)(*ret);
L
Linus Torvalds 已提交
49
		ret[0] = 0;
50
		--pgtable_quicklist_size;
51
		preempt_enable();
52
	} else {
53
		preempt_enable();
54 55
		ret = (unsigned long *)__get_free_page(GFP_KERNEL | __GFP_ZERO);
	}
L
Linus Torvalds 已提交
56

57
	return ret;
L
Linus Torvalds 已提交
58 59
}

60
static inline void pgtable_quicklist_free(void *pgtable_entry)
L
Linus Torvalds 已提交
61
{
62
#ifdef CONFIG_NUMA
63
	int nid = page_to_nid(virt_to_page(pgtable_entry));
L
Linus Torvalds 已提交
64

65 66 67
	if (unlikely(nid != numa_node_id())) {
		free_page((unsigned long)pgtable_entry);
		return;
L
Linus Torvalds 已提交
68
	}
69
#endif
L
Linus Torvalds 已提交
70 71

	preempt_disable();
72 73 74
	*(unsigned long *)pgtable_entry = (unsigned long)pgtable_quicklist;
	pgtable_quicklist = (unsigned long *)pgtable_entry;
	++pgtable_quicklist_size;
L
Linus Torvalds 已提交
75 76 77
	preempt_enable();
}

78
static inline pgd_t *pgd_alloc(struct mm_struct *mm)
L
Linus Torvalds 已提交
79
{
80
	return pgtable_quicklist_alloc();
L
Linus Torvalds 已提交
81 82
}

83
static inline void pgd_free(pgd_t * pgd)
L
Linus Torvalds 已提交
84
{
85
	pgtable_quicklist_free(pgd);
L
Linus Torvalds 已提交
86 87
}

R
Robin Holt 已提交
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
#ifdef CONFIG_PGTABLE_4
static inline void
pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
{
	pgd_val(*pgd_entry) = __pa(pud);
}

static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
{
	return pgtable_quicklist_alloc();
}

static inline void pud_free(pud_t * pud)
{
	pgtable_quicklist_free(pud);
}
#define __pud_free_tlb(tlb, pud)	pud_free(pud)
#endif /* CONFIG_PGTABLE_4 */

107 108
static inline void
pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
L
Linus Torvalds 已提交
109
{
110 111
	pud_val(*pud_entry) = __pa(pmd);
}
L
Linus Torvalds 已提交
112

113 114 115
static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
{
	return pgtable_quicklist_alloc();
L
Linus Torvalds 已提交
116 117
}

118
static inline void pmd_free(pmd_t * pmd)
L
Linus Torvalds 已提交
119
{
120
	pgtable_quicklist_free(pmd);
L
Linus Torvalds 已提交
121 122 123 124 125
}

#define __pmd_free_tlb(tlb, pmd)	pmd_free(pmd)

static inline void
126
pmd_populate(struct mm_struct *mm, pmd_t * pmd_entry, struct page *pte)
L
Linus Torvalds 已提交
127 128 129 130 131
{
	pmd_val(*pmd_entry) = page_to_phys(pte);
}

static inline void
132
pmd_populate_kernel(struct mm_struct *mm, pmd_t * pmd_entry, pte_t * pte)
L
Linus Torvalds 已提交
133 134 135 136
{
	pmd_val(*pmd_entry) = __pa(pte);
}

137 138
static inline struct page *pte_alloc_one(struct mm_struct *mm,
					 unsigned long addr)
L
Linus Torvalds 已提交
139
{
140
	return virt_to_page(pgtable_quicklist_alloc());
L
Linus Torvalds 已提交
141 142
}

143 144
static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
					  unsigned long addr)
L
Linus Torvalds 已提交
145
{
146
	return pgtable_quicklist_alloc();
L
Linus Torvalds 已提交
147 148
}

149
static inline void pte_free(struct page *pte)
L
Linus Torvalds 已提交
150
{
151
	pgtable_quicklist_free(page_address(pte));
L
Linus Torvalds 已提交
152 153
}

154
static inline void pte_free_kernel(pte_t * pte)
L
Linus Torvalds 已提交
155
{
156
	pgtable_quicklist_free(pte);
L
Linus Torvalds 已提交
157 158
}

159
#define __pte_free_tlb(tlb, pte)	pte_free(pte)
L
Linus Torvalds 已提交
160

161
extern void check_pgt_cache(void);
L
Linus Torvalds 已提交
162

163
#endif				/* _ASM_IA64_PGALLOC_H */