Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2004-2006 Atmel Corporation |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 as |
| 6 | * published by the Free Software Foundation. |
| 7 | */ |
| 8 | #ifndef __ASM_AVR32_PGALLOC_H |
| 9 | #define __ASM_AVR32_PGALLOC_H |
| 10 | |
Haavard Skinnemoen | 5a4d529 | 2008-01-14 23:33:44 +0100 | [diff] [blame] | 11 | #include <linux/quicklist.h> |
| 12 | #include <asm/page.h> |
| 13 | #include <asm/pgtable.h> |
| 14 | |
| 15 | #define QUICK_PGD 0 /* Preserve kernel mappings over free */ |
Haavard Skinnemoen | 3851075 | 2008-01-14 23:35:32 +0100 | [diff] [blame] | 16 | #define QUICK_PT 1 /* Zero on free */ |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 17 | |
Haavard Skinnemoen | cfd23e9 | 2008-01-14 22:15:05 +0100 | [diff] [blame] | 18 | static inline void pmd_populate_kernel(struct mm_struct *mm, |
| 19 | pmd_t *pmd, pte_t *pte) |
| 20 | { |
| 21 | set_pmd(pmd, __pmd((unsigned long)pte)); |
| 22 | } |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 23 | |
Haavard Skinnemoen | cfd23e9 | 2008-01-14 22:15:05 +0100 | [diff] [blame] | 24 | static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd, |
Martin Schwidefsky | 2f569af | 2008-02-08 04:22:04 -0800 | [diff] [blame] | 25 | pgtable_t pte) |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 26 | { |
Haavard Skinnemoen | cfd23e9 | 2008-01-14 22:15:05 +0100 | [diff] [blame] | 27 | set_pmd(pmd, __pmd((unsigned long)page_address(pte))); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 28 | } |
Martin Schwidefsky | 2f569af | 2008-02-08 04:22:04 -0800 | [diff] [blame] | 29 | #define pmd_pgtable(pmd) pmd_page(pmd) |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 30 | |
Haavard Skinnemoen | 5a4d529 | 2008-01-14 23:33:44 +0100 | [diff] [blame] | 31 | static inline void pgd_ctor(void *x) |
| 32 | { |
| 33 | pgd_t *pgd = x; |
| 34 | |
| 35 | memcpy(pgd + USER_PTRS_PER_PGD, |
| 36 | swapper_pg_dir + USER_PTRS_PER_PGD, |
| 37 | (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t)); |
| 38 | } |
| 39 | |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 40 | /* |
| 41 | * Allocate and free page tables |
| 42 | */ |
Haavard Skinnemoen | cfd23e9 | 2008-01-14 22:15:05 +0100 | [diff] [blame] | 43 | static inline pgd_t *pgd_alloc(struct mm_struct *mm) |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 44 | { |
Haavard Skinnemoen | 5a4d529 | 2008-01-14 23:33:44 +0100 | [diff] [blame] | 45 | return quicklist_alloc(QUICK_PGD, GFP_KERNEL | __GFP_REPEAT, pgd_ctor); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 46 | } |
| 47 | |
Benjamin Herrenschmidt | 5e54197 | 2008-02-04 22:29:14 -0800 | [diff] [blame] | 48 | static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd) |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 49 | { |
Haavard Skinnemoen | 5a4d529 | 2008-01-14 23:33:44 +0100 | [diff] [blame] | 50 | quicklist_free(QUICK_PGD, NULL, pgd); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm, |
| 54 | unsigned long address) |
| 55 | { |
Haavard Skinnemoen | 3851075 | 2008-01-14 23:35:32 +0100 | [diff] [blame] | 56 | return quicklist_alloc(QUICK_PT, GFP_KERNEL | __GFP_REPEAT, NULL); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 57 | } |
| 58 | |
Haavard Skinnemoen | 3851075 | 2008-01-14 23:35:32 +0100 | [diff] [blame] | 59 | static inline pgtable_t pte_alloc_one(struct mm_struct *mm, |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 60 | unsigned long address) |
| 61 | { |
Haavard Skinnemoen | 3851075 | 2008-01-14 23:35:32 +0100 | [diff] [blame] | 62 | struct page *page; |
| 63 | void *pg; |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 64 | |
Haavard Skinnemoen | 3851075 | 2008-01-14 23:35:32 +0100 | [diff] [blame] | 65 | pg = quicklist_alloc(QUICK_PT, GFP_KERNEL | __GFP_REPEAT, NULL); |
| 66 | if (!pg) |
Martin Schwidefsky | 2f569af | 2008-02-08 04:22:04 -0800 | [diff] [blame] | 67 | return NULL; |
Haavard Skinnemoen | 3851075 | 2008-01-14 23:35:32 +0100 | [diff] [blame] | 68 | |
| 69 | page = virt_to_page(pg); |
| 70 | pgtable_page_ctor(page); |
| 71 | |
| 72 | return page; |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 73 | } |
| 74 | |
Benjamin Herrenschmidt | 5e54197 | 2008-02-04 22:29:14 -0800 | [diff] [blame] | 75 | static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte) |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 76 | { |
Haavard Skinnemoen | 3851075 | 2008-01-14 23:35:32 +0100 | [diff] [blame] | 77 | quicklist_free(QUICK_PT, NULL, pte); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Martin Schwidefsky | 2f569af | 2008-02-08 04:22:04 -0800 | [diff] [blame] | 80 | static inline void pte_free(struct mm_struct *mm, pgtable_t pte) |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 81 | { |
Martin Schwidefsky | 2f569af | 2008-02-08 04:22:04 -0800 | [diff] [blame] | 82 | pgtable_page_dtor(pte); |
Haavard Skinnemoen | 3851075 | 2008-01-14 23:35:32 +0100 | [diff] [blame] | 83 | quicklist_free_page(QUICK_PT, NULL, pte); |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 84 | } |
| 85 | |
Martin Schwidefsky | 2f569af | 2008-02-08 04:22:04 -0800 | [diff] [blame] | 86 | #define __pte_free_tlb(tlb,pte) \ |
| 87 | do { \ |
| 88 | pgtable_page_dtor(pte); \ |
| 89 | tlb_remove_page((tlb), pte); \ |
| 90 | } while (0) |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 91 | |
Haavard Skinnemoen | 5a4d529 | 2008-01-14 23:33:44 +0100 | [diff] [blame] | 92 | static inline void check_pgt_cache(void) |
| 93 | { |
| 94 | quicklist_trim(QUICK_PGD, NULL, 25, 16); |
Haavard Skinnemoen | 3851075 | 2008-01-14 23:35:32 +0100 | [diff] [blame] | 95 | quicklist_trim(QUICK_PT, NULL, 25, 16); |
Haavard Skinnemoen | 5a4d529 | 2008-01-14 23:33:44 +0100 | [diff] [blame] | 96 | } |
Haavard Skinnemoen | 5f97f7f | 2006-09-25 23:32:13 -0700 | [diff] [blame] | 97 | |
| 98 | #endif /* __ASM_AVR32_PGALLOC_H */ |