Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef _ALPHA_PGALLOC_H |
| 2 | #define _ALPHA_PGALLOC_H |
| 3 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | #include <linux/mm.h> |
| 5 | #include <linux/mmzone.h> |
| 6 | |
| 7 | /* |
| 8 | * Allocate and free page tables. The xxx_kernel() versions are |
| 9 | * used to allocate a kernel page table - this turns on ASN bits |
| 10 | * if any. |
| 11 | */ |
| 12 | |
| 13 | static inline void |
Martin Schwidefsky | 2f569af | 2008-02-08 04:22:04 -0800 | [diff] [blame] | 14 | pmd_populate(struct mm_struct *mm, pmd_t *pmd, pgtable_t pte) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | { |
| 16 | pmd_set(pmd, (pte_t *)(page_to_pa(pte) + PAGE_OFFSET)); |
| 17 | } |
Martin Schwidefsky | 2f569af | 2008-02-08 04:22:04 -0800 | [diff] [blame] | 18 | #define pmd_pgtable(pmd) pmd_page(pmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
| 20 | static inline void |
| 21 | pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd, pte_t *pte) |
| 22 | { |
| 23 | pmd_set(pmd, pte); |
| 24 | } |
| 25 | |
| 26 | static inline void |
| 27 | pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd) |
| 28 | { |
| 29 | pgd_set(pgd, pmd); |
| 30 | } |
| 31 | |
| 32 | extern pgd_t *pgd_alloc(struct mm_struct *mm); |
| 33 | |
| 34 | static inline void |
Benjamin Herrenschmidt | 5e54197 | 2008-02-04 22:29:14 -0800 | [diff] [blame] | 35 | pgd_free(struct mm_struct *mm, pgd_t *pgd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | { |
| 37 | free_page((unsigned long)pgd); |
| 38 | } |
| 39 | |
| 40 | static inline pmd_t * |
| 41 | pmd_alloc_one(struct mm_struct *mm, unsigned long address) |
| 42 | { |
Michal Hocko | 32d6bd9 | 2016-06-24 14:48:47 -0700 | [diff] [blame] | 43 | pmd_t *ret = (pmd_t *)__get_free_page(GFP_KERNEL|__GFP_ZERO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | return ret; |
| 45 | } |
| 46 | |
| 47 | static inline void |
Benjamin Herrenschmidt | 5e54197 | 2008-02-04 22:29:14 -0800 | [diff] [blame] | 48 | pmd_free(struct mm_struct *mm, pmd_t *pmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | { |
| 50 | free_page((unsigned long)pmd); |
| 51 | } |
| 52 | |
Ivan Kokshaysky | 5da7f3d | 2009-01-15 13:51:20 -0800 | [diff] [blame] | 53 | static inline pte_t * |
| 54 | pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address) |
| 55 | { |
Michal Hocko | 32d6bd9 | 2016-06-24 14:48:47 -0700 | [diff] [blame] | 56 | pte_t *pte = (pte_t *)__get_free_page(GFP_KERNEL|__GFP_ZERO); |
Ivan Kokshaysky | 5da7f3d | 2009-01-15 13:51:20 -0800 | [diff] [blame] | 57 | return pte; |
| 58 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
| 60 | static inline void |
Benjamin Herrenschmidt | 5e54197 | 2008-02-04 22:29:14 -0800 | [diff] [blame] | 61 | pte_free_kernel(struct mm_struct *mm, pte_t *pte) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | { |
| 63 | free_page((unsigned long)pte); |
| 64 | } |
| 65 | |
Martin Schwidefsky | 2f569af | 2008-02-08 04:22:04 -0800 | [diff] [blame] | 66 | static inline pgtable_t |
| 67 | pte_alloc_one(struct mm_struct *mm, unsigned long address) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | { |
Martin Schwidefsky | 2f569af | 2008-02-08 04:22:04 -0800 | [diff] [blame] | 69 | pte_t *pte = pte_alloc_one_kernel(mm, address); |
| 70 | struct page *page; |
| 71 | |
| 72 | if (!pte) |
| 73 | return NULL; |
| 74 | page = virt_to_page(pte); |
Kirill A. Shutemov | 3fd681b | 2013-11-14 14:31:24 -0800 | [diff] [blame] | 75 | if (!pgtable_page_ctor(page)) { |
| 76 | __free_page(page); |
| 77 | return NULL; |
| 78 | } |
Martin Schwidefsky | 2f569af | 2008-02-08 04:22:04 -0800 | [diff] [blame] | 79 | return page; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | static inline void |
Martin Schwidefsky | 2f569af | 2008-02-08 04:22:04 -0800 | [diff] [blame] | 83 | pte_free(struct mm_struct *mm, pgtable_t page) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | { |
Martin Schwidefsky | 2f569af | 2008-02-08 04:22:04 -0800 | [diff] [blame] | 85 | pgtable_page_dtor(page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | __free_page(page); |
| 87 | } |
| 88 | |
| 89 | #define check_pgt_cache() do { } while (0) |
| 90 | |
| 91 | #endif /* _ALPHA_PGALLOC_H */ |