Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #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 Holt | fde740e | 2005-04-25 13:13:16 -0700 | [diff] [blame] | 25 | DECLARE_PER_CPU(unsigned long *, __pgtable_quicklist); |
| 26 | #define pgtable_quicklist __ia64_per_cpu_var(__pgtable_quicklist) |
| 27 | DECLARE_PER_CPU(long, __pgtable_quicklist_size); |
| 28 | #define pgtable_quicklist_size __ia64_per_cpu_var(__pgtable_quicklist_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
Robin Holt | fde740e | 2005-04-25 13:13:16 -0700 | [diff] [blame] | 30 | static inline long pgtable_quicklist_total_size(void) |
| 31 | { |
Tony Luck | c411cb5 | 2005-04-25 13:16:16 -0700 | [diff] [blame] | 32 | long ql_size = 0; |
Robin Holt | fde740e | 2005-04-25 13:13:16 -0700 | [diff] [blame] | 33 | 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 | |
| 41 | static inline void *pgtable_quicklist_alloc(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | { |
| 43 | unsigned long *ret = NULL; |
| 44 | |
| 45 | preempt_disable(); |
| 46 | |
Robin Holt | fde740e | 2005-04-25 13:13:16 -0700 | [diff] [blame] | 47 | ret = pgtable_quicklist; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | if (likely(ret != NULL)) { |
Robin Holt | fde740e | 2005-04-25 13:13:16 -0700 | [diff] [blame] | 49 | pgtable_quicklist = (unsigned long *)(*ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | ret[0] = 0; |
Robin Holt | fde740e | 2005-04-25 13:13:16 -0700 | [diff] [blame] | 51 | --pgtable_quicklist_size; |
Martin Hicks | 2d29306 | 2005-04-26 09:04:31 -0700 | [diff] [blame] | 52 | preempt_enable(); |
Robin Holt | fde740e | 2005-04-25 13:13:16 -0700 | [diff] [blame] | 53 | } else { |
Martin Hicks | 2d29306 | 2005-04-26 09:04:31 -0700 | [diff] [blame] | 54 | preempt_enable(); |
Robin Holt | fde740e | 2005-04-25 13:13:16 -0700 | [diff] [blame] | 55 | ret = (unsigned long *)__get_free_page(GFP_KERNEL | __GFP_ZERO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | } |
Robin Holt | fde740e | 2005-04-25 13:13:16 -0700 | [diff] [blame] | 57 | |
Robin Holt | fde740e | 2005-04-25 13:13:16 -0700 | [diff] [blame] | 58 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | } |
| 60 | |
Robin Holt | fde740e | 2005-04-25 13:13:16 -0700 | [diff] [blame] | 61 | static inline void pgtable_quicklist_free(void *pgtable_entry) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | { |
Robin Holt | fde740e | 2005-04-25 13:13:16 -0700 | [diff] [blame] | 63 | #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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | preempt_disable(); |
Robin Holt | fde740e | 2005-04-25 13:13:16 -0700 | [diff] [blame] | 73 | *(unsigned long *)pgtable_entry = (unsigned long)pgtable_quicklist; |
| 74 | pgtable_quicklist = (unsigned long *)pgtable_entry; |
| 75 | ++pgtable_quicklist_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | preempt_enable(); |
| 77 | } |
| 78 | |
Robin Holt | fde740e | 2005-04-25 13:13:16 -0700 | [diff] [blame] | 79 | static inline pgd_t *pgd_alloc(struct mm_struct *mm) |
| 80 | { |
| 81 | return pgtable_quicklist_alloc(); |
| 82 | } |
| 83 | |
| 84 | static inline void pgd_free(pgd_t * pgd) |
| 85 | { |
| 86 | pgtable_quicklist_free(pgd); |
| 87 | } |
| 88 | |
Robin Holt | 837cd0b | 2005-11-11 09:35:43 -0600 | [diff] [blame] | 89 | #ifdef CONFIG_PGTABLE_4 |
| 90 | static inline void |
| 91 | pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud) |
| 92 | { |
| 93 | pgd_val(*pgd_entry) = __pa(pud); |
| 94 | } |
| 95 | |
| 96 | static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr) |
| 97 | { |
| 98 | return pgtable_quicklist_alloc(); |
| 99 | } |
| 100 | |
| 101 | static inline void pud_free(pud_t * pud) |
| 102 | { |
| 103 | pgtable_quicklist_free(pud); |
| 104 | } |
| 105 | #define __pud_free_tlb(tlb, pud) pud_free(pud) |
| 106 | #endif /* CONFIG_PGTABLE_4 */ |
| 107 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | static inline void |
Robin Holt | fde740e | 2005-04-25 13:13:16 -0700 | [diff] [blame] | 109 | pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | { |
| 111 | pud_val(*pud_entry) = __pa(pmd); |
| 112 | } |
| 113 | |
Robin Holt | fde740e | 2005-04-25 13:13:16 -0700 | [diff] [blame] | 114 | static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | { |
Robin Holt | fde740e | 2005-04-25 13:13:16 -0700 | [diff] [blame] | 116 | return pgtable_quicklist_alloc(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | } |
| 118 | |
Robin Holt | fde740e | 2005-04-25 13:13:16 -0700 | [diff] [blame] | 119 | static inline void pmd_free(pmd_t * pmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | { |
Robin Holt | fde740e | 2005-04-25 13:13:16 -0700 | [diff] [blame] | 121 | pgtable_quicklist_free(pmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | #define __pmd_free_tlb(tlb, pmd) pmd_free(pmd) |
| 125 | |
| 126 | static inline void |
Robin Holt | fde740e | 2005-04-25 13:13:16 -0700 | [diff] [blame] | 127 | pmd_populate(struct mm_struct *mm, pmd_t * pmd_entry, struct page *pte) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | { |
| 129 | pmd_val(*pmd_entry) = page_to_phys(pte); |
| 130 | } |
| 131 | |
| 132 | static inline void |
Robin Holt | fde740e | 2005-04-25 13:13:16 -0700 | [diff] [blame] | 133 | pmd_populate_kernel(struct mm_struct *mm, pmd_t * pmd_entry, pte_t * pte) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | { |
| 135 | pmd_val(*pmd_entry) = __pa(pte); |
| 136 | } |
| 137 | |
Robin Holt | fde740e | 2005-04-25 13:13:16 -0700 | [diff] [blame] | 138 | static inline struct page *pte_alloc_one(struct mm_struct *mm, |
| 139 | unsigned long addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | { |
Robin Holt | fde740e | 2005-04-25 13:13:16 -0700 | [diff] [blame] | 141 | return virt_to_page(pgtable_quicklist_alloc()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | } |
| 143 | |
Robin Holt | fde740e | 2005-04-25 13:13:16 -0700 | [diff] [blame] | 144 | static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm, |
| 145 | unsigned long addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | { |
Robin Holt | fde740e | 2005-04-25 13:13:16 -0700 | [diff] [blame] | 147 | return pgtable_quicklist_alloc(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | } |
| 149 | |
Robin Holt | fde740e | 2005-04-25 13:13:16 -0700 | [diff] [blame] | 150 | static inline void pte_free(struct page *pte) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | { |
Robin Holt | fde740e | 2005-04-25 13:13:16 -0700 | [diff] [blame] | 152 | pgtable_quicklist_free(page_address(pte)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | } |
| 154 | |
Robin Holt | fde740e | 2005-04-25 13:13:16 -0700 | [diff] [blame] | 155 | static inline void pte_free_kernel(pte_t * pte) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | { |
Robin Holt | fde740e | 2005-04-25 13:13:16 -0700 | [diff] [blame] | 157 | pgtable_quicklist_free(pte); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | } |
| 159 | |
Robin Holt | fde740e | 2005-04-25 13:13:16 -0700 | [diff] [blame] | 160 | #define __pte_free_tlb(tlb, pte) pte_free(pte) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | |
Robin Holt | fde740e | 2005-04-25 13:13:16 -0700 | [diff] [blame] | 162 | extern void check_pgt_cache(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | |
Robin Holt | fde740e | 2005-04-25 13:13:16 -0700 | [diff] [blame] | 164 | #endif /* _ASM_IA64_PGALLOC_H */ |