blob: 84dd2db7104c74f4f57eb4f1c7d0bfc1f4159869 [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
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 Menefy99a596f2006-11-21 15:38:05 +090010static 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 Torvalds1da177e2005-04-16 15:20:36 -070015
16static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080017 pgtable_t pte)
Linus Torvalds1da177e2005-04-16 15:20:36 -070018{
Stuart Menefy99a596f2006-11-21 15:38:05 +090019 set_pmd(pmd, __pmd((unsigned long)page_address(pte)));
Linus Torvalds1da177e2005-04-16 15:20:36 -070020}
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080021#define pmd_pgtable(pmd) pmd_page(pmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
Paul Mundt5f8c9902007-05-08 11:55:21 +090023static inline void pgd_ctor(void *x)
24{
25 pgd_t *pgd = x;
26
27 memcpy(pgd + USER_PTRS_PER_PGD,
28 swapper_pg_dir + USER_PTRS_PER_PGD,
29 (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t));
30}
31
Linus Torvalds1da177e2005-04-16 15:20:36 -070032/*
33 * Allocate and free page tables.
34 */
35static inline pgd_t *pgd_alloc(struct mm_struct *mm)
36{
Paul Mundt5f8c9902007-05-08 11:55:21 +090037 return quicklist_alloc(QUICK_PGD, GFP_KERNEL | __GFP_REPEAT, pgd_ctor);
Linus Torvalds1da177e2005-04-16 15:20:36 -070038}
39
Benjamin Herrenschmidt5e541972008-02-04 22:29:14 -080040static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
Linus Torvalds1da177e2005-04-16 15:20:36 -070041{
Paul Mundt5f8c9902007-05-08 11:55:21 +090042 quicklist_free(QUICK_PGD, NULL, pgd);
Linus Torvalds1da177e2005-04-16 15:20:36 -070043}
44
45static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
46 unsigned long address)
47{
Paul Mundt1039b9a2007-05-08 12:07:21 +090048 return quicklist_alloc(QUICK_PT, GFP_KERNEL | __GFP_REPEAT, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070049}
50
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080051static inline pgtable_t pte_alloc_one(struct mm_struct *mm,
52 unsigned long address)
Linus Torvalds1da177e2005-04-16 15:20:36 -070053{
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080054 struct page *page;
55 void *pg;
56
57 pg = quicklist_alloc(QUICK_PT, GFP_KERNEL | __GFP_REPEAT, NULL);
58 if (!pg)
59 return NULL;
60 page = virt_to_page(pg);
61 pgtable_page_ctor(page);
62 return page;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063}
64
Benjamin Herrenschmidt5e541972008-02-04 22:29:14 -080065static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066{
Paul Mundt5f8c9902007-05-08 11:55:21 +090067 quicklist_free(QUICK_PT, NULL, pte);
Linus Torvalds1da177e2005-04-16 15:20:36 -070068}
69
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080070static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
Linus Torvalds1da177e2005-04-16 15:20:36 -070071{
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080072 pgtable_page_dtor(pte);
Paul Mundt5f8c9902007-05-08 11:55:21 +090073 quicklist_free_page(QUICK_PT, NULL, pte);
Linus Torvalds1da177e2005-04-16 15:20:36 -070074}
75
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080076#define __pte_free_tlb(tlb,pte) \
77do { \
78 pgtable_page_dtor(pte); \
79 tlb_remove_page((tlb), (pte)); \
80} while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
82/*
83 * allocating and freeing a pmd is trivial: the 1-entry pmd is
84 * inside the pgd, so has no extra memory associated with it.
85 */
86
Benjamin Herrenschmidt5e541972008-02-04 22:29:14 -080087#define pmd_free(mm, x) do { } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070088#define __pmd_free_tlb(tlb,x) do { } while (0)
Paul Mundt5f8c9902007-05-08 11:55:21 +090089
90static inline void check_pgt_cache(void)
91{
92 quicklist_trim(QUICK_PGD, NULL, 25, 16);
93 quicklist_trim(QUICK_PT, NULL, 25, 16);
94}
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
Linus Torvalds1da177e2005-04-16 15:20:36 -070096#endif /* __ASM_SH_PGALLOC_H */