1 #ifndef _ASM_IA64_PGALLOC_H
2 #define _ASM_IA64_PGALLOC_H
5 * This file contains the functions and defines necessary to allocate
8 * This hopefully works with any (fixed) ia-64 page-size, as defined
9 * in <asm/page.h> (currently 8192).
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>
16 #include <linux/config.h>
18 #include <linux/compiler.h>
20 #include <linux/page-flags.h>
21 #include <linux/threads.h>
23 #include <asm/mmu_context.h>
24 #include <asm/processor.h>
27 * Very stupidly, we used to get new pgd's and pmd's, init their contents
28 * to point to the NULL versions of the next level page table, later on
29 * completely re-init them the same way, then free them up. This wasted
30 * a lot of work and caused unnecessary memory traffic. How broken...
31 * We fix this by caching them.
33 #define pgd_quicklist (local_cpu_data->pgd_quick)
34 #define pmd_quicklist (local_cpu_data->pmd_quick)
35 #define pgtable_cache_size (local_cpu_data->pgtable_cache_sz)
38 pgd_alloc_one_fast (struct mm_struct *mm)
40 unsigned long *ret = pgd_quicklist;
42 if (likely(ret != NULL)) {
43 pgd_quicklist = (unsigned long *)(*ret);
52 pgd_alloc (struct mm_struct *mm)
54 /* the VM system never calls pgd_alloc_one_fast(), so we do it here. */
55 pgd_t *pgd = pgd_alloc_one_fast(mm);
57 if (unlikely(pgd == NULL)) {
58 pgd = (pgd_t *)__get_free_page(GFP_KERNEL);
59 if (likely(pgd != NULL))
68 *(unsigned long *)pgd = (unsigned long) pgd_quicklist;
69 pgd_quicklist = (unsigned long *) pgd;
74 pgd_populate (struct mm_struct *mm, pgd_t *pgd_entry, pmd_t *pmd)
76 pgd_val(*pgd_entry) = __pa(pmd);
81 pmd_alloc_one_fast (struct mm_struct *mm, unsigned long addr)
83 unsigned long *ret = (unsigned long *)pmd_quicklist;
85 if (likely(ret != NULL)) {
86 pmd_quicklist = (unsigned long *)(*ret);
94 pmd_alloc_one (struct mm_struct *mm, unsigned long addr)
96 pmd_t *pmd = (pmd_t *)__get_free_page(GFP_KERNEL|__GFP_REPEAT);
98 if (likely(pmd != NULL))
104 pmd_free (pmd_t *pmd)
106 *(unsigned long *)pmd = (unsigned long) pmd_quicklist;
107 pmd_quicklist = (unsigned long *) pmd;
108 ++pgtable_cache_size;
111 #define __pmd_free_tlb(tlb, pmd) pmd_free(pmd)
114 pmd_populate (struct mm_struct *mm, pmd_t *pmd_entry, struct page *pte)
116 pmd_val(*pmd_entry) = page_to_phys(pte);
120 pmd_populate_kernel (struct mm_struct *mm, pmd_t *pmd_entry, pte_t *pte)
122 pmd_val(*pmd_entry) = __pa(pte);
125 static inline struct page *
126 pte_alloc_one (struct mm_struct *mm, unsigned long addr)
128 struct page *pte = alloc_pages(GFP_KERNEL|__GFP_REPEAT, 0);
130 if (likely(pte != NULL))
131 clear_page(page_address(pte));
135 static inline pte_t *
136 pte_alloc_one_kernel (struct mm_struct *mm, unsigned long addr)
138 pte_t *pte = (pte_t *)__get_free_page(GFP_KERNEL|__GFP_REPEAT);
140 if (likely(pte != NULL))
146 pte_free (struct page *pte)
152 pte_free_kernel (pte_t *pte)
154 free_page((unsigned long) pte);
157 #define __pte_free_tlb(tlb, pte) tlb_remove_page((tlb), (pte))
159 extern void check_pgt_cache (void);
161 #endif /* _ASM_IA64_PGALLOC_H */