blob: 9cb68e9b377e2c831f71187dc1314643b83fc933 [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
17#include <linux/compiler.h>
18#include <linux/mm.h>
19#include <linux/page-flags.h>
20#include <linux/threads.h>
21
22#include <asm/mmu_context.h>
23
Robin Holtfde740e2005-04-25 13:13:16 -070024DECLARE_PER_CPU(unsigned long *, __pgtable_quicklist);
25#define pgtable_quicklist __ia64_per_cpu_var(__pgtable_quicklist)
26DECLARE_PER_CPU(long, __pgtable_quicklist_size);
27#define pgtable_quicklist_size __ia64_per_cpu_var(__pgtable_quicklist_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Robin Holtfde740e2005-04-25 13:13:16 -070029static inline long pgtable_quicklist_total_size(void)
30{
Tony Luckc411cb52005-04-25 13:16:16 -070031 long ql_size = 0;
Robin Holtfde740e2005-04-25 13:13:16 -070032 int cpuid;
33
34 for_each_online_cpu(cpuid) {
35 ql_size += per_cpu(__pgtable_quicklist_size, cpuid);
36 }
37 return ql_size;
38}
39
40static inline void *pgtable_quicklist_alloc(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070041{
42 unsigned long *ret = NULL;
43
44 preempt_disable();
45
Robin Holtfde740e2005-04-25 13:13:16 -070046 ret = pgtable_quicklist;
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 if (likely(ret != NULL)) {
Robin Holtfde740e2005-04-25 13:13:16 -070048 pgtable_quicklist = (unsigned long *)(*ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 ret[0] = 0;
Robin Holtfde740e2005-04-25 13:13:16 -070050 --pgtable_quicklist_size;
Martin Hicks2d293062005-04-26 09:04:31 -070051 preempt_enable();
Robin Holtfde740e2005-04-25 13:13:16 -070052 } else {
Martin Hicks2d293062005-04-26 09:04:31 -070053 preempt_enable();
Robin Holtfde740e2005-04-25 13:13:16 -070054 ret = (unsigned long *)__get_free_page(GFP_KERNEL | __GFP_ZERO);
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 }
Robin Holtfde740e2005-04-25 13:13:16 -070056
Robin Holtfde740e2005-04-25 13:13:16 -070057 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070058}
59
Robin Holtfde740e2005-04-25 13:13:16 -070060static inline void pgtable_quicklist_free(void *pgtable_entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -070061{
Robin Holtfde740e2005-04-25 13:13:16 -070062#ifdef CONFIG_NUMA
63 unsigned long nid = page_to_nid(virt_to_page(pgtable_entry));
64
65 if (unlikely(nid != numa_node_id())) {
66 free_page((unsigned long)pgtable_entry);
67 return;
68 }
69#endif
70
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 preempt_disable();
Robin Holtfde740e2005-04-25 13:13:16 -070072 *(unsigned long *)pgtable_entry = (unsigned long)pgtable_quicklist;
73 pgtable_quicklist = (unsigned long *)pgtable_entry;
74 ++pgtable_quicklist_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 preempt_enable();
76}
77
Robin Holtfde740e2005-04-25 13:13:16 -070078static inline pgd_t *pgd_alloc(struct mm_struct *mm)
79{
80 return pgtable_quicklist_alloc();
81}
82
83static inline void pgd_free(pgd_t * pgd)
84{
85 pgtable_quicklist_free(pgd);
86}
87
Robin Holt837cd0b2005-11-11 09:35:43 -060088#ifdef CONFIG_PGTABLE_4
89static inline void
90pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
91{
92 pgd_val(*pgd_entry) = __pa(pud);
93}
94
95static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
96{
97 return pgtable_quicklist_alloc();
98}
99
100static inline void pud_free(pud_t * pud)
101{
102 pgtable_quicklist_free(pud);
103}
104#define __pud_free_tlb(tlb, pud) pud_free(pud)
105#endif /* CONFIG_PGTABLE_4 */
106
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107static inline void
Robin Holtfde740e2005-04-25 13:13:16 -0700108pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109{
110 pud_val(*pud_entry) = __pa(pmd);
111}
112
Robin Holtfde740e2005-04-25 13:13:16 -0700113static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114{
Robin Holtfde740e2005-04-25 13:13:16 -0700115 return pgtable_quicklist_alloc();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116}
117
Robin Holtfde740e2005-04-25 13:13:16 -0700118static inline void pmd_free(pmd_t * pmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119{
Robin Holtfde740e2005-04-25 13:13:16 -0700120 pgtable_quicklist_free(pmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121}
122
123#define __pmd_free_tlb(tlb, pmd) pmd_free(pmd)
124
125static inline void
Robin Holtfde740e2005-04-25 13:13:16 -0700126pmd_populate(struct mm_struct *mm, pmd_t * pmd_entry, struct page *pte)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127{
128 pmd_val(*pmd_entry) = page_to_phys(pte);
129}
130
131static inline void
Robin Holtfde740e2005-04-25 13:13:16 -0700132pmd_populate_kernel(struct mm_struct *mm, pmd_t * pmd_entry, pte_t * pte)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133{
134 pmd_val(*pmd_entry) = __pa(pte);
135}
136
Robin Holtfde740e2005-04-25 13:13:16 -0700137static inline struct page *pte_alloc_one(struct mm_struct *mm,
138 unsigned long addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139{
Robin Holtfde740e2005-04-25 13:13:16 -0700140 return virt_to_page(pgtable_quicklist_alloc());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141}
142
Robin Holtfde740e2005-04-25 13:13:16 -0700143static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
144 unsigned long addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145{
Robin Holtfde740e2005-04-25 13:13:16 -0700146 return pgtable_quicklist_alloc();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147}
148
Robin Holtfde740e2005-04-25 13:13:16 -0700149static inline void pte_free(struct page *pte)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150{
Robin Holtfde740e2005-04-25 13:13:16 -0700151 pgtable_quicklist_free(page_address(pte));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152}
153
Robin Holtfde740e2005-04-25 13:13:16 -0700154static inline void pte_free_kernel(pte_t * pte)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155{
Robin Holtfde740e2005-04-25 13:13:16 -0700156 pgtable_quicklist_free(pte);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157}
158
Robin Holtfde740e2005-04-25 13:13:16 -0700159#define __pte_free_tlb(tlb, pte) pte_free(pte)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160
Robin Holtfde740e2005-04-25 13:13:16 -0700161extern void check_pgt_cache(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
Robin Holtfde740e2005-04-25 13:13:16 -0700163#endif /* _ASM_IA64_PGALLOC_H */