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 | |
Paul Mundt | 0176bd3 | 2010-01-05 12:35:00 +0900 | [diff] [blame] | 7 | #define QUICK_PT 0 /* Other page table pages that are zero on free */ |
Paul Mundt | 5f8c990 | 2007-05-08 11:55:21 +0900 | [diff] [blame] | 8 | |
Matt Fleming | 2a5eacc | 2009-12-31 12:19:24 +0000 | [diff] [blame] | 9 | extern pgd_t *pgd_alloc(struct mm_struct *); |
| 10 | extern void pgd_free(struct mm_struct *mm, pgd_t *pgd); |
| 11 | |
Paul Mundt | 782bb5a | 2010-01-13 19:11:14 +0900 | [diff] [blame] | 12 | #if PAGETABLE_LEVELS > 2 |
Matt Fleming | 2a5eacc | 2009-12-31 12:19:24 +0000 | [diff] [blame] | 13 | extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd); |
| 14 | extern pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address); |
| 15 | extern void pmd_free(struct mm_struct *mm, pmd_t *pmd); |
Matt Fleming | 5d9b4b1 | 2009-12-13 14:38:50 +0000 | [diff] [blame] | 16 | #endif |
Matt Fleming | b73c806 | 2009-11-25 22:00:08 +0000 | [diff] [blame] | 17 | |
Stuart Menefy | 99a596f | 2006-11-21 15:38:05 +0900 | [diff] [blame] | 18 | static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd, |
| 19 | pte_t *pte) |
| 20 | { |
| 21 | set_pmd(pmd, __pmd((unsigned long)pte)); |
| 22 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | |
| 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) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | { |
Stuart Menefy | 99a596f | 2006-11-21 15:38:05 +0900 | [diff] [blame] | 27 | set_pmd(pmd, __pmd((unsigned long)page_address(pte))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | } |
Martin Schwidefsky | 2f569af | 2008-02-08 04:22:04 -0800 | [diff] [blame] | 29 | #define pmd_pgtable(pmd) pmd_page(pmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | |
| 31 | /* |
| 32 | * Allocate and free page tables. |
| 33 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm, |
| 35 | unsigned long address) |
| 36 | { |
Paul Mundt | 1039b9a | 2007-05-08 12:07:21 +0900 | [diff] [blame] | 37 | return quicklist_alloc(QUICK_PT, GFP_KERNEL | __GFP_REPEAT, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | } |
| 39 | |
Martin Schwidefsky | 2f569af | 2008-02-08 04:22:04 -0800 | [diff] [blame] | 40 | static inline pgtable_t pte_alloc_one(struct mm_struct *mm, |
| 41 | unsigned long address) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | { |
Martin Schwidefsky | 2f569af | 2008-02-08 04:22:04 -0800 | [diff] [blame] | 43 | struct page *page; |
| 44 | void *pg; |
| 45 | |
| 46 | pg = quicklist_alloc(QUICK_PT, GFP_KERNEL | __GFP_REPEAT, NULL); |
| 47 | if (!pg) |
| 48 | return NULL; |
| 49 | page = virt_to_page(pg); |
| 50 | pgtable_page_ctor(page); |
| 51 | return page; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | } |
| 53 | |
Benjamin Herrenschmidt | 5e54197 | 2008-02-04 22:29:14 -0800 | [diff] [blame] | 54 | 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] | 55 | { |
Paul Mundt | 5f8c990 | 2007-05-08 11:55:21 +0900 | [diff] [blame] | 56 | quicklist_free(QUICK_PT, NULL, pte); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | } |
| 58 | |
Martin Schwidefsky | 2f569af | 2008-02-08 04:22:04 -0800 | [diff] [blame] | 59 | static inline void pte_free(struct mm_struct *mm, pgtable_t pte) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | { |
Martin Schwidefsky | 2f569af | 2008-02-08 04:22:04 -0800 | [diff] [blame] | 61 | pgtable_page_dtor(pte); |
Paul Mundt | 5f8c990 | 2007-05-08 11:55:21 +0900 | [diff] [blame] | 62 | quicklist_free_page(QUICK_PT, NULL, pte); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | } |
| 64 | |
Benjamin Herrenschmidt | 9e1b32c | 2009-07-22 15:44:28 +1000 | [diff] [blame] | 65 | #define __pte_free_tlb(tlb,pte,addr) \ |
Martin Schwidefsky | 2f569af | 2008-02-08 04:22:04 -0800 | [diff] [blame] | 66 | do { \ |
| 67 | pgtable_page_dtor(pte); \ |
| 68 | tlb_remove_page((tlb), (pte)); \ |
| 69 | } while (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | |
Paul Mundt | 5f8c990 | 2007-05-08 11:55:21 +0900 | [diff] [blame] | 71 | static inline void check_pgt_cache(void) |
| 72 | { |
Paul Mundt | 5f8c990 | 2007-05-08 11:55:21 +0900 | [diff] [blame] | 73 | quicklist_trim(QUICK_PT, NULL, 25, 16); |
| 74 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | #endif /* __ASM_SH_PGALLOC_H */ |