blob: 4ea27855c3b5ee4dd1fff9848a014e86ad599669 [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 Mundt5f8c9902007-05-08 11:55:21 +09007#define QUICK_PT 1 /* Other page table pages that are zero on free */
8
Matt Fleming5d9b4b12009-12-13 14:38:50 +00009#ifdef CONFIG_PGTABLE_LEVELS_3
10#include <asm/pgalloc_pmd.h>
11#else
Matt Flemingb73c8062009-11-25 22:00:08 +000012#include <asm/pgalloc_nopmd.h>
Matt Fleming5d9b4b12009-12-13 14:38:50 +000013#endif
Matt Flemingb73c8062009-11-25 22:00:08 +000014
Stuart Menefy99a596f2006-11-21 15:38:05 +090015static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
16 pte_t *pte)
17{
18 set_pmd(pmd, __pmd((unsigned long)pte));
19}
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
21static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080022 pgtable_t pte)
Linus Torvalds1da177e2005-04-16 15:20:36 -070023{
Stuart Menefy99a596f2006-11-21 15:38:05 +090024 set_pmd(pmd, __pmd((unsigned long)page_address(pte)));
Linus Torvalds1da177e2005-04-16 15:20:36 -070025}
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080026#define pmd_pgtable(pmd) pmd_page(pmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
28/*
29 * Allocate and free page tables.
30 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070031static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
32 unsigned long address)
33{
Paul Mundt1039b9a2007-05-08 12:07:21 +090034 return quicklist_alloc(QUICK_PT, GFP_KERNEL | __GFP_REPEAT, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070035}
36
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080037static inline pgtable_t pte_alloc_one(struct mm_struct *mm,
38 unsigned long address)
Linus Torvalds1da177e2005-04-16 15:20:36 -070039{
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080040 struct page *page;
41 void *pg;
42
43 pg = quicklist_alloc(QUICK_PT, GFP_KERNEL | __GFP_REPEAT, NULL);
44 if (!pg)
45 return NULL;
46 page = virt_to_page(pg);
47 pgtable_page_ctor(page);
48 return page;
Linus Torvalds1da177e2005-04-16 15:20:36 -070049}
50
Benjamin Herrenschmidt5e541972008-02-04 22:29:14 -080051static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
Linus Torvalds1da177e2005-04-16 15:20:36 -070052{
Paul Mundt5f8c9902007-05-08 11:55:21 +090053 quicklist_free(QUICK_PT, NULL, pte);
Linus Torvalds1da177e2005-04-16 15:20:36 -070054}
55
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080056static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
Linus Torvalds1da177e2005-04-16 15:20:36 -070057{
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080058 pgtable_page_dtor(pte);
Paul Mundt5f8c9902007-05-08 11:55:21 +090059 quicklist_free_page(QUICK_PT, NULL, pte);
Linus Torvalds1da177e2005-04-16 15:20:36 -070060}
61
Benjamin Herrenschmidt9e1b32c2009-07-22 15:44:28 +100062#define __pte_free_tlb(tlb,pte,addr) \
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080063do { \
64 pgtable_page_dtor(pte); \
65 tlb_remove_page((tlb), (pte)); \
66} while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
Paul Mundt5f8c9902007-05-08 11:55:21 +090068static inline void check_pgt_cache(void)
69{
Matt Flemingb73c8062009-11-25 22:00:08 +000070 __check_pgt_cache();
Paul Mundt5f8c9902007-05-08 11:55:21 +090071 quicklist_trim(QUICK_PT, NULL, 25, 16);
72}
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
Linus Torvalds1da177e2005-04-16 15:20:36 -070074#endif /* __ASM_SH_PGALLOC_H */