xref: /openbmc/linux/arch/sh/include/asm/pgalloc.h (revision 2a5eacca85d39d8b6dffae821d7d260f05584dc7)
1f15cbe6fSPaul Mundt #ifndef __ASM_SH_PGALLOC_H
2f15cbe6fSPaul Mundt #define __ASM_SH_PGALLOC_H
3f15cbe6fSPaul Mundt 
4f15cbe6fSPaul Mundt #include <linux/quicklist.h>
5f15cbe6fSPaul Mundt #include <asm/page.h>
6f15cbe6fSPaul Mundt 
7f15cbe6fSPaul Mundt #define QUICK_PT 1	/* Other page table pages that are zero on free */
8f15cbe6fSPaul Mundt 
9*2a5eaccaSMatt Fleming extern pgd_t *pgd_alloc(struct mm_struct *);
10*2a5eaccaSMatt Fleming extern void pgd_free(struct mm_struct *mm, pgd_t *pgd);
11*2a5eaccaSMatt Fleming 
125d9b4b19SMatt Fleming #ifdef CONFIG_PGTABLE_LEVELS_3
13*2a5eaccaSMatt Fleming extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
14*2a5eaccaSMatt Fleming extern pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address);
15*2a5eaccaSMatt Fleming extern void pmd_free(struct mm_struct *mm, pmd_t *pmd);
165d9b4b19SMatt Fleming #endif
17b73c8063SMatt Fleming 
18f15cbe6fSPaul Mundt static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
19f15cbe6fSPaul Mundt 				       pte_t *pte)
20f15cbe6fSPaul Mundt {
21f15cbe6fSPaul Mundt 	set_pmd(pmd, __pmd((unsigned long)pte));
22f15cbe6fSPaul Mundt }
23f15cbe6fSPaul Mundt 
24f15cbe6fSPaul Mundt static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
25f15cbe6fSPaul Mundt 				pgtable_t pte)
26f15cbe6fSPaul Mundt {
27f15cbe6fSPaul Mundt 	set_pmd(pmd, __pmd((unsigned long)page_address(pte)));
28f15cbe6fSPaul Mundt }
29f15cbe6fSPaul Mundt #define pmd_pgtable(pmd) pmd_page(pmd)
30f15cbe6fSPaul Mundt 
31f15cbe6fSPaul Mundt /*
32f15cbe6fSPaul Mundt  * Allocate and free page tables.
33f15cbe6fSPaul Mundt  */
34f15cbe6fSPaul Mundt static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
35f15cbe6fSPaul Mundt 					  unsigned long address)
36f15cbe6fSPaul Mundt {
37f15cbe6fSPaul Mundt 	return quicklist_alloc(QUICK_PT, GFP_KERNEL | __GFP_REPEAT, NULL);
38f15cbe6fSPaul Mundt }
39f15cbe6fSPaul Mundt 
40f15cbe6fSPaul Mundt static inline pgtable_t pte_alloc_one(struct mm_struct *mm,
41f15cbe6fSPaul Mundt 					unsigned long address)
42f15cbe6fSPaul Mundt {
43f15cbe6fSPaul Mundt 	struct page *page;
44f15cbe6fSPaul Mundt 	void *pg;
45f15cbe6fSPaul Mundt 
46f15cbe6fSPaul Mundt 	pg = quicklist_alloc(QUICK_PT, GFP_KERNEL | __GFP_REPEAT, NULL);
47f15cbe6fSPaul Mundt 	if (!pg)
48f15cbe6fSPaul Mundt 		return NULL;
49f15cbe6fSPaul Mundt 	page = virt_to_page(pg);
50f15cbe6fSPaul Mundt 	pgtable_page_ctor(page);
51f15cbe6fSPaul Mundt 	return page;
52f15cbe6fSPaul Mundt }
53f15cbe6fSPaul Mundt 
54f15cbe6fSPaul Mundt static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
55f15cbe6fSPaul Mundt {
56f15cbe6fSPaul Mundt 	quicklist_free(QUICK_PT, NULL, pte);
57f15cbe6fSPaul Mundt }
58f15cbe6fSPaul Mundt 
59f15cbe6fSPaul Mundt static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
60f15cbe6fSPaul Mundt {
61f15cbe6fSPaul Mundt 	pgtable_page_dtor(pte);
62f15cbe6fSPaul Mundt 	quicklist_free_page(QUICK_PT, NULL, pte);
63f15cbe6fSPaul Mundt }
64f15cbe6fSPaul Mundt 
659e1b32caSBenjamin Herrenschmidt #define __pte_free_tlb(tlb,pte,addr)			\
66f15cbe6fSPaul Mundt do {							\
67f15cbe6fSPaul Mundt 	pgtable_page_dtor(pte);				\
68f15cbe6fSPaul Mundt 	tlb_remove_page((tlb), (pte));			\
69f15cbe6fSPaul Mundt } while (0)
70f15cbe6fSPaul Mundt 
71f15cbe6fSPaul Mundt static inline void check_pgt_cache(void)
72f15cbe6fSPaul Mundt {
73f15cbe6fSPaul Mundt 	quicklist_trim(QUICK_PT, NULL, 25, 16);
74f15cbe6fSPaul Mundt }
75f15cbe6fSPaul Mundt 
76f15cbe6fSPaul Mundt #endif /* __ASM_SH_PGALLOC_H */
77