blob: 8c00785c60d5b2517dd83c3b75b7ac50b0d10e1d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef __ASM_SH_PGALLOC_H
2#define __ASM_SH_PGALLOC_H
3
Paul Mundt5f8c9902007-05-08 11:55:21 +09004#include <linux/quicklist.h>
5#include <asm/page.h>
6
Paul Mundt0176bd32010-01-05 12:35:00 +09007#define QUICK_PT 0 /* Other page table pages that are zero on free */
Paul Mundt5f8c9902007-05-08 11:55:21 +09008
Matt Fleming2a5eacc2009-12-31 12:19:24 +00009extern pgd_t *pgd_alloc(struct mm_struct *);
10extern void pgd_free(struct mm_struct *mm, pgd_t *pgd);
11
Paul Mundt782bb5a2010-01-13 19:11:14 +090012#if PAGETABLE_LEVELS > 2
Matt Fleming2a5eacc2009-12-31 12:19:24 +000013extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
14extern pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address);
15extern void pmd_free(struct mm_struct *mm, pmd_t *pmd);
Matt Fleming5d9b4b12009-12-13 14:38:50 +000016#endif
Matt Flemingb73c8062009-11-25 22:00:08 +000017
Stuart Menefy99a596f2006-11-21 15:38:05 +090018static 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 Torvalds1da177e2005-04-16 15:20:36 -070023
24static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080025 pgtable_t pte)
Linus Torvalds1da177e2005-04-16 15:20:36 -070026{
Stuart Menefy99a596f2006-11-21 15:38:05 +090027 set_pmd(pmd, __pmd((unsigned long)page_address(pte)));
Linus Torvalds1da177e2005-04-16 15:20:36 -070028}
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080029#define pmd_pgtable(pmd) pmd_page(pmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
31/*
32 * Allocate and free page tables.
33 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070034static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
35 unsigned long address)
36{
Paul Mundt1039b9a2007-05-08 12:07:21 +090037 return quicklist_alloc(QUICK_PT, GFP_KERNEL | __GFP_REPEAT, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070038}
39
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080040static inline pgtable_t pte_alloc_one(struct mm_struct *mm,
41 unsigned long address)
Linus Torvalds1da177e2005-04-16 15:20:36 -070042{
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080043 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 Torvalds1da177e2005-04-16 15:20:36 -070052}
53
Benjamin Herrenschmidt5e541972008-02-04 22:29:14 -080054static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
Linus Torvalds1da177e2005-04-16 15:20:36 -070055{
Paul Mundt5f8c9902007-05-08 11:55:21 +090056 quicklist_free(QUICK_PT, NULL, pte);
Linus Torvalds1da177e2005-04-16 15:20:36 -070057}
58
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080059static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
Linus Torvalds1da177e2005-04-16 15:20:36 -070060{
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080061 pgtable_page_dtor(pte);
Paul Mundt5f8c9902007-05-08 11:55:21 +090062 quicklist_free_page(QUICK_PT, NULL, pte);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063}
64
Benjamin Herrenschmidt9e1b32c2009-07-22 15:44:28 +100065#define __pte_free_tlb(tlb,pte,addr) \
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080066do { \
67 pgtable_page_dtor(pte); \
68 tlb_remove_page((tlb), (pte)); \
69} while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
Paul Mundt5f8c9902007-05-08 11:55:21 +090071static inline void check_pgt_cache(void)
72{
Paul Mundt5f8c9902007-05-08 11:55:21 +090073 quicklist_trim(QUICK_PT, NULL, 25, 16);
74}
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
Linus Torvalds1da177e2005-04-16 15:20:36 -070076#endif /* __ASM_SH_PGALLOC_H */