Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef __ASM_SH_PGALLOC_H |
| 2 | #define __ASM_SH_PGALLOC_H |
| 3 | |
Paul Mundt | 5f8c990 | 2007-05-08 11:55:21 +0900 | [diff] [blame] | 4 | #include <linux/quicklist.h> |
| 5 | #include <asm/page.h> |
| 6 | |
| 7 | #define QUICK_PGD 0 /* We preserve special mappings over free */ |
| 8 | #define QUICK_PT 1 /* Other page table pages that are zero on free */ |
| 9 | |
Stuart Menefy | 99a596f | 2006-11-21 15:38:05 +0900 | [diff] [blame] | 10 | static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd, |
| 11 | pte_t *pte) |
| 12 | { |
| 13 | set_pmd(pmd, __pmd((unsigned long)pte)); |
| 14 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | |
| 16 | static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd, |
| 17 | struct page *pte) |
| 18 | { |
Stuart Menefy | 99a596f | 2006-11-21 15:38:05 +0900 | [diff] [blame] | 19 | set_pmd(pmd, __pmd((unsigned long)page_address(pte))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | } |
| 21 | |
Paul Mundt | 5f8c990 | 2007-05-08 11:55:21 +0900 | [diff] [blame] | 22 | static inline void pgd_ctor(void *x) |
| 23 | { |
| 24 | pgd_t *pgd = x; |
| 25 | |
| 26 | memcpy(pgd + USER_PTRS_PER_PGD, |
| 27 | swapper_pg_dir + USER_PTRS_PER_PGD, |
| 28 | (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t)); |
| 29 | } |
| 30 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | /* |
| 32 | * Allocate and free page tables. |
| 33 | */ |
| 34 | static inline pgd_t *pgd_alloc(struct mm_struct *mm) |
| 35 | { |
Paul Mundt | 5f8c990 | 2007-05-08 11:55:21 +0900 | [diff] [blame] | 36 | return quicklist_alloc(QUICK_PGD, GFP_KERNEL | __GFP_REPEAT, pgd_ctor); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | static inline void pgd_free(pgd_t *pgd) |
| 40 | { |
Paul Mundt | 5f8c990 | 2007-05-08 11:55:21 +0900 | [diff] [blame] | 41 | quicklist_free(QUICK_PGD, NULL, pgd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm, |
| 45 | unsigned long address) |
| 46 | { |
Paul Mundt | 1039b9a | 2007-05-08 12:07:21 +0900 | [diff] [blame] | 47 | return quicklist_alloc(QUICK_PT, GFP_KERNEL | __GFP_REPEAT, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | static inline struct page *pte_alloc_one(struct mm_struct *mm, |
| 51 | unsigned long address) |
| 52 | { |
Paul Mundt | 1039b9a | 2007-05-08 12:07:21 +0900 | [diff] [blame] | 53 | void *pg = quicklist_alloc(QUICK_PT, GFP_KERNEL | __GFP_REPEAT, NULL); |
Paul Mundt | 5f8c990 | 2007-05-08 11:55:21 +0900 | [diff] [blame] | 54 | return pg ? virt_to_page(pg) : NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | static inline void pte_free_kernel(pte_t *pte) |
| 58 | { |
Paul Mundt | 5f8c990 | 2007-05-08 11:55:21 +0900 | [diff] [blame] | 59 | quicklist_free(QUICK_PT, NULL, pte); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | static inline void pte_free(struct page *pte) |
| 63 | { |
Paul Mundt | 5f8c990 | 2007-05-08 11:55:21 +0900 | [diff] [blame] | 64 | quicklist_free_page(QUICK_PT, NULL, pte); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | #define __pte_free_tlb(tlb,pte) tlb_remove_page((tlb),(pte)) |
| 68 | |
| 69 | /* |
| 70 | * allocating and freeing a pmd is trivial: the 1-entry pmd is |
| 71 | * inside the pgd, so has no extra memory associated with it. |
| 72 | */ |
| 73 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | #define pmd_free(x) do { } while (0) |
| 75 | #define __pmd_free_tlb(tlb,x) do { } while (0) |
Paul Mundt | 5f8c990 | 2007-05-08 11:55:21 +0900 | [diff] [blame] | 76 | |
| 77 | static inline void check_pgt_cache(void) |
| 78 | { |
| 79 | quicklist_trim(QUICK_PGD, NULL, 25, 16); |
| 80 | quicklist_trim(QUICK_PT, NULL, 25, 16); |
| 81 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | #endif /* __ASM_SH_PGALLOC_H */ |