blob: a5f214554afd278830788f5e0673ac2d91fbba04 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _ASM_IA64_PGALLOC_H
2#define _ASM_IA64_PGALLOC_H
3
4/*
5 * This file contains the functions and defines necessary to allocate
6 * page tables.
7 *
8 * This hopefully works with any (fixed) ia-64 page-size, as defined
9 * in <asm/page.h> (currently 8192).
10 *
11 * Copyright (C) 1998-2001 Hewlett-Packard Co
12 * David Mosberger-Tang <davidm@hpl.hp.com>
13 * Copyright (C) 2000, Goutham Rao <goutham.rao@intel.com>
14 */
15
16#include <linux/config.h>
17
18#include <linux/compiler.h>
19#include <linux/mm.h>
20#include <linux/page-flags.h>
21#include <linux/threads.h>
22
23#include <asm/mmu_context.h>
24
Robin Holtfde740e2005-04-25 13:13:16 -070025DECLARE_PER_CPU(unsigned long *, __pgtable_quicklist);
26#define pgtable_quicklist __ia64_per_cpu_var(__pgtable_quicklist)
27DECLARE_PER_CPU(long, __pgtable_quicklist_size);
28#define pgtable_quicklist_size __ia64_per_cpu_var(__pgtable_quicklist_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
Robin Holtfde740e2005-04-25 13:13:16 -070030static inline long pgtable_quicklist_total_size(void)
31{
Tony Luckc411cb52005-04-25 13:16:16 -070032 long ql_size = 0;
Robin Holtfde740e2005-04-25 13:13:16 -070033 int cpuid;
34
35 for_each_online_cpu(cpuid) {
36 ql_size += per_cpu(__pgtable_quicklist_size, cpuid);
37 }
38 return ql_size;
39}
40
41static inline void *pgtable_quicklist_alloc(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070042{
43 unsigned long *ret = NULL;
44
45 preempt_disable();
46
Robin Holtfde740e2005-04-25 13:13:16 -070047 ret = pgtable_quicklist;
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 if (likely(ret != NULL)) {
Robin Holtfde740e2005-04-25 13:13:16 -070049 pgtable_quicklist = (unsigned long *)(*ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 ret[0] = 0;
Robin Holtfde740e2005-04-25 13:13:16 -070051 --pgtable_quicklist_size;
Martin Hicks2d293062005-04-26 09:04:31 -070052 preempt_enable();
Robin Holtfde740e2005-04-25 13:13:16 -070053 } else {
Martin Hicks2d293062005-04-26 09:04:31 -070054 preempt_enable();
Robin Holtfde740e2005-04-25 13:13:16 -070055 ret = (unsigned long *)__get_free_page(GFP_KERNEL | __GFP_ZERO);
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 }
Robin Holtfde740e2005-04-25 13:13:16 -070057
Robin Holtfde740e2005-04-25 13:13:16 -070058 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059}
60
Robin Holtfde740e2005-04-25 13:13:16 -070061static inline void pgtable_quicklist_free(void *pgtable_entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -070062{
Robin Holtfde740e2005-04-25 13:13:16 -070063#ifdef CONFIG_NUMA
64 unsigned long nid = page_to_nid(virt_to_page(pgtable_entry));
65
66 if (unlikely(nid != numa_node_id())) {
67 free_page((unsigned long)pgtable_entry);
68 return;
69 }
70#endif
71
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 preempt_disable();
Robin Holtfde740e2005-04-25 13:13:16 -070073 *(unsigned long *)pgtable_entry = (unsigned long)pgtable_quicklist;
74 pgtable_quicklist = (unsigned long *)pgtable_entry;
75 ++pgtable_quicklist_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 preempt_enable();
77}
78
Robin Holtfde740e2005-04-25 13:13:16 -070079static inline pgd_t *pgd_alloc(struct mm_struct *mm)
80{
81 return pgtable_quicklist_alloc();
82}
83
84static inline void pgd_free(pgd_t * pgd)
85{
86 pgtable_quicklist_free(pgd);
87}
88
Linus Torvalds1da177e2005-04-16 15:20:36 -070089static inline void
Robin Holtfde740e2005-04-25 13:13:16 -070090pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -070091{
92 pud_val(*pud_entry) = __pa(pmd);
93}
94
Robin Holtfde740e2005-04-25 13:13:16 -070095static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070096{
Robin Holtfde740e2005-04-25 13:13:16 -070097 return pgtable_quicklist_alloc();
Linus Torvalds1da177e2005-04-16 15:20:36 -070098}
99
Robin Holtfde740e2005-04-25 13:13:16 -0700100static inline void pmd_free(pmd_t * pmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101{
Robin Holtfde740e2005-04-25 13:13:16 -0700102 pgtable_quicklist_free(pmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103}
104
105#define __pmd_free_tlb(tlb, pmd) pmd_free(pmd)
106
107static inline void
Robin Holtfde740e2005-04-25 13:13:16 -0700108pmd_populate(struct mm_struct *mm, pmd_t * pmd_entry, struct page *pte)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109{
110 pmd_val(*pmd_entry) = page_to_phys(pte);
111}
112
113static inline void
Robin Holtfde740e2005-04-25 13:13:16 -0700114pmd_populate_kernel(struct mm_struct *mm, pmd_t * pmd_entry, pte_t * pte)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115{
116 pmd_val(*pmd_entry) = __pa(pte);
117}
118
Robin Holtfde740e2005-04-25 13:13:16 -0700119static inline struct page *pte_alloc_one(struct mm_struct *mm,
120 unsigned long addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121{
Robin Holtfde740e2005-04-25 13:13:16 -0700122 return virt_to_page(pgtable_quicklist_alloc());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123}
124
Robin Holtfde740e2005-04-25 13:13:16 -0700125static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
126 unsigned long addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127{
Robin Holtfde740e2005-04-25 13:13:16 -0700128 return pgtable_quicklist_alloc();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129}
130
Robin Holtfde740e2005-04-25 13:13:16 -0700131static inline void pte_free(struct page *pte)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132{
Robin Holtfde740e2005-04-25 13:13:16 -0700133 pgtable_quicklist_free(page_address(pte));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134}
135
Robin Holtfde740e2005-04-25 13:13:16 -0700136static inline void pte_free_kernel(pte_t * pte)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137{
Robin Holtfde740e2005-04-25 13:13:16 -0700138 pgtable_quicklist_free(pte);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139}
140
Robin Holtfde740e2005-04-25 13:13:16 -0700141#define __pte_free_tlb(tlb, pte) pte_free(pte)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
Robin Holtfde740e2005-04-25 13:13:16 -0700143extern void check_pgt_cache(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144
Robin Holtfde740e2005-04-25 13:13:16 -0700145#endif /* _ASM_IA64_PGALLOC_H */