Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef _MOTOROLA_PGALLOC_H |
| 2 | #define _MOTOROLA_PGALLOC_H |
| 3 | |
| 4 | #include <asm/tlb.h> |
| 5 | #include <asm/tlbflush.h> |
| 6 | |
| 7 | extern pmd_t *get_pointer_table(void); |
| 8 | extern int free_pointer_table(pmd_t *); |
| 9 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address) |
| 11 | { |
| 12 | pte_t *pte; |
| 13 | |
| 14 | pte = (pte_t *)__get_free_page(GFP_KERNEL|__GFP_REPEAT|__GFP_ZERO); |
| 15 | if (pte) { |
| 16 | __flush_page_to_ram(pte); |
| 17 | flush_tlb_kernel_page(pte); |
| 18 | nocache_page(pte); |
| 19 | } |
| 20 | |
| 21 | return pte; |
| 22 | } |
| 23 | |
Benjamin Herrenschmidt | 5e54197 | 2008-02-04 22:29:14 -0800 | [diff] [blame] | 24 | 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] | 25 | { |
| 26 | cache_page(pte); |
| 27 | free_page((unsigned long) pte); |
| 28 | } |
| 29 | |
Martin Schwidefsky | 2f569af | 2008-02-08 04:22:04 -0800 | [diff] [blame] | 30 | static inline pgtable_t pte_alloc_one(struct mm_struct *mm, unsigned long address) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | { |
| 32 | struct page *page = alloc_pages(GFP_KERNEL|__GFP_REPEAT|__GFP_ZERO, 0); |
| 33 | pte_t *pte; |
| 34 | |
| 35 | if(!page) |
| 36 | return NULL; |
| 37 | |
| 38 | pte = kmap(page); |
| 39 | if (pte) { |
| 40 | __flush_page_to_ram(pte); |
| 41 | flush_tlb_kernel_page(pte); |
| 42 | nocache_page(pte); |
| 43 | } |
| 44 | kunmap(pte); |
Martin Schwidefsky | 2f569af | 2008-02-08 04:22:04 -0800 | [diff] [blame] | 45 | pgtable_page_ctor(page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | return page; |
| 47 | } |
| 48 | |
Martin Schwidefsky | 2f569af | 2008-02-08 04:22:04 -0800 | [diff] [blame] | 49 | static inline void pte_free(struct mm_struct *mm, pgtable_t page) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | { |
Martin Schwidefsky | 2f569af | 2008-02-08 04:22:04 -0800 | [diff] [blame] | 51 | pgtable_page_dtor(page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | cache_page(kmap(page)); |
| 53 | kunmap(page); |
| 54 | __free_page(page); |
| 55 | } |
| 56 | |
Benjamin Herrenschmidt | 9e1b32c | 2009-07-22 15:44:28 +1000 | [diff] [blame] | 57 | static inline void __pte_free_tlb(struct mmu_gather *tlb, pgtable_t page, |
| 58 | unsigned long address) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | { |
Martin Schwidefsky | 2f569af | 2008-02-08 04:22:04 -0800 | [diff] [blame] | 60 | pgtable_page_dtor(page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | cache_page(kmap(page)); |
| 62 | kunmap(page); |
| 63 | __free_page(page); |
| 64 | } |
| 65 | |
| 66 | |
| 67 | static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address) |
| 68 | { |
| 69 | return get_pointer_table(); |
| 70 | } |
| 71 | |
Benjamin Herrenschmidt | 5e54197 | 2008-02-04 22:29:14 -0800 | [diff] [blame] | 72 | static inline int pmd_free(struct mm_struct *mm, pmd_t *pmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | { |
| 74 | return free_pointer_table(pmd); |
| 75 | } |
| 76 | |
Benjamin Herrenschmidt | 9e1b32c | 2009-07-22 15:44:28 +1000 | [diff] [blame] | 77 | static inline int __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd, |
| 78 | unsigned long address) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | { |
| 80 | return free_pointer_table(pmd); |
| 81 | } |
| 82 | |
| 83 | |
Benjamin Herrenschmidt | 5e54197 | 2008-02-04 22:29:14 -0800 | [diff] [blame] | 84 | static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | { |
Benjamin Herrenschmidt | 5e54197 | 2008-02-04 22:29:14 -0800 | [diff] [blame] | 86 | pmd_free(mm, (pmd_t *)pgd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | static inline pgd_t *pgd_alloc(struct mm_struct *mm) |
| 90 | { |
| 91 | return (pgd_t *)get_pointer_table(); |
| 92 | } |
| 93 | |
| 94 | |
| 95 | static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd, pte_t *pte) |
| 96 | { |
| 97 | pmd_set(pmd, pte); |
| 98 | } |
| 99 | |
Martin Schwidefsky | 2f569af | 2008-02-08 04:22:04 -0800 | [diff] [blame] | 100 | static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd, pgtable_t page) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | { |
| 102 | pmd_set(pmd, page_address(page)); |
| 103 | } |
Martin Schwidefsky | 2f569af | 2008-02-08 04:22:04 -0800 | [diff] [blame] | 104 | #define pmd_pgtable(pmd) pmd_page(pmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | |
| 106 | static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd) |
| 107 | { |
| 108 | pgd_set(pgd, pmd); |
| 109 | } |
| 110 | |
| 111 | #endif /* _MOTOROLA_PGALLOC_H */ |