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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | |
| 17 | #include <linux/compiler.h> |
| 18 | #include <linux/mm.h> |
| 19 | #include <linux/page-flags.h> |
| 20 | #include <linux/threads.h> |
Christoph Lameter | 2bd62a4 | 2007-05-10 22:42:53 -0700 | [diff] [blame] | 21 | #include <linux/quicklist.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
| 23 | #include <asm/mmu_context.h> |
| 24 | |
Robin Holt | fde740e | 2005-04-25 13:13:16 -0700 | [diff] [blame] | 25 | static inline pgd_t *pgd_alloc(struct mm_struct *mm) |
| 26 | { |
Christoph Lameter | 2bd62a4 | 2007-05-10 22:42:53 -0700 | [diff] [blame] | 27 | return quicklist_alloc(0, GFP_KERNEL, NULL); |
Robin Holt | fde740e | 2005-04-25 13:13:16 -0700 | [diff] [blame] | 28 | } |
| 29 | |
Benjamin Herrenschmidt | 5e54197 | 2008-02-04 22:29:14 -0800 | [diff] [blame] | 30 | static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd) |
Robin Holt | fde740e | 2005-04-25 13:13:16 -0700 | [diff] [blame] | 31 | { |
Christoph Lameter | 2bd62a4 | 2007-05-10 22:42:53 -0700 | [diff] [blame] | 32 | quicklist_free(0, NULL, pgd); |
Robin Holt | fde740e | 2005-04-25 13:13:16 -0700 | [diff] [blame] | 33 | } |
| 34 | |
Robin Holt | 837cd0b | 2005-11-11 09:35:43 -0600 | [diff] [blame] | 35 | #ifdef CONFIG_PGTABLE_4 |
| 36 | static inline void |
| 37 | pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud) |
| 38 | { |
| 39 | pgd_val(*pgd_entry) = __pa(pud); |
| 40 | } |
| 41 | |
| 42 | static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr) |
| 43 | { |
Christoph Lameter | 2bd62a4 | 2007-05-10 22:42:53 -0700 | [diff] [blame] | 44 | return quicklist_alloc(0, GFP_KERNEL, NULL); |
Robin Holt | 837cd0b | 2005-11-11 09:35:43 -0600 | [diff] [blame] | 45 | } |
| 46 | |
Benjamin Herrenschmidt | 5e54197 | 2008-02-04 22:29:14 -0800 | [diff] [blame] | 47 | static inline void pud_free(struct mm_struct *mm, pud_t *pud) |
Robin Holt | 837cd0b | 2005-11-11 09:35:43 -0600 | [diff] [blame] | 48 | { |
Christoph Lameter | 2bd62a4 | 2007-05-10 22:42:53 -0700 | [diff] [blame] | 49 | quicklist_free(0, NULL, pud); |
Robin Holt | 837cd0b | 2005-11-11 09:35:43 -0600 | [diff] [blame] | 50 | } |
Benjamin Herrenschmidt | 5e54197 | 2008-02-04 22:29:14 -0800 | [diff] [blame] | 51 | #define __pud_free_tlb(tlb, pud) pud_free((tlb)->mm, pud) |
Robin Holt | 837cd0b | 2005-11-11 09:35:43 -0600 | [diff] [blame] | 52 | #endif /* CONFIG_PGTABLE_4 */ |
| 53 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | static inline void |
Robin Holt | fde740e | 2005-04-25 13:13:16 -0700 | [diff] [blame] | 55 | 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] | 56 | { |
| 57 | pud_val(*pud_entry) = __pa(pmd); |
| 58 | } |
| 59 | |
Robin Holt | fde740e | 2005-04-25 13:13:16 -0700 | [diff] [blame] | 60 | 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] | 61 | { |
Christoph Lameter | 2bd62a4 | 2007-05-10 22:42:53 -0700 | [diff] [blame] | 62 | return quicklist_alloc(0, GFP_KERNEL, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | } |
| 64 | |
Benjamin Herrenschmidt | 5e54197 | 2008-02-04 22:29:14 -0800 | [diff] [blame] | 65 | static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | { |
Christoph Lameter | 2bd62a4 | 2007-05-10 22:42:53 -0700 | [diff] [blame] | 67 | quicklist_free(0, NULL, pmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | } |
| 69 | |
Benjamin Herrenschmidt | 5e54197 | 2008-02-04 22:29:14 -0800 | [diff] [blame] | 70 | #define __pmd_free_tlb(tlb, pmd) pmd_free((tlb)->mm, pmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
| 72 | static inline void |
Martin Schwidefsky | 2f569af | 2008-02-08 04:22:04 -0800 | [diff] [blame] | 73 | pmd_populate(struct mm_struct *mm, pmd_t * pmd_entry, pgtable_t pte) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | { |
| 75 | pmd_val(*pmd_entry) = page_to_phys(pte); |
| 76 | } |
Martin Schwidefsky | 2f569af | 2008-02-08 04:22:04 -0800 | [diff] [blame] | 77 | #define pmd_pgtable(pmd) pmd_page(pmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | |
| 79 | static inline void |
Robin Holt | fde740e | 2005-04-25 13:13:16 -0700 | [diff] [blame] | 80 | 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] | 81 | { |
| 82 | pmd_val(*pmd_entry) = __pa(pte); |
| 83 | } |
| 84 | |
Martin Schwidefsky | 2f569af | 2008-02-08 04:22:04 -0800 | [diff] [blame] | 85 | static inline pgtable_t pte_alloc_one(struct mm_struct *mm, unsigned long addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | { |
Martin Schwidefsky | 2f569af | 2008-02-08 04:22:04 -0800 | [diff] [blame] | 87 | struct page *page; |
| 88 | void *pg; |
| 89 | |
| 90 | pg = quicklist_alloc(0, GFP_KERNEL, NULL); |
| 91 | if (!pg) |
| 92 | return NULL; |
| 93 | page = virt_to_page(pg); |
| 94 | pgtable_page_ctor(page); |
| 95 | return page; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | } |
| 97 | |
Robin Holt | fde740e | 2005-04-25 13:13:16 -0700 | [diff] [blame] | 98 | static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm, |
| 99 | unsigned long addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | { |
Christoph Lameter | 2bd62a4 | 2007-05-10 22:42:53 -0700 | [diff] [blame] | 101 | return quicklist_alloc(0, GFP_KERNEL, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Martin Schwidefsky | 2f569af | 2008-02-08 04:22:04 -0800 | [diff] [blame] | 104 | static inline void pte_free(struct mm_struct *mm, pgtable_t pte) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | { |
Martin Schwidefsky | 2f569af | 2008-02-08 04:22:04 -0800 | [diff] [blame] | 106 | pgtable_page_dtor(pte); |
Christoph Lameter | 2bd62a4 | 2007-05-10 22:42:53 -0700 | [diff] [blame] | 107 | quicklist_free_page(0, NULL, pte); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | } |
| 109 | |
Benjamin Herrenschmidt | 5e54197 | 2008-02-04 22:29:14 -0800 | [diff] [blame] | 110 | static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | { |
Christoph Lameter | 2bd62a4 | 2007-05-10 22:42:53 -0700 | [diff] [blame] | 112 | quicklist_free(0, NULL, pte); |
| 113 | } |
| 114 | |
| 115 | static inline void check_pgt_cache(void) |
| 116 | { |
| 117 | quicklist_trim(0, NULL, 25, 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | } |
| 119 | |
Benjamin Herrenschmidt | 5e54197 | 2008-02-04 22:29:14 -0800 | [diff] [blame] | 120 | #define __pte_free_tlb(tlb, pte) pte_free((tlb)->mm, pte) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
Robin Holt | fde740e | 2005-04-25 13:13:16 -0700 | [diff] [blame] | 122 | #endif /* _ASM_IA64_PGALLOC_H */ |