xref: /openbmc/linux/arch/sh/include/asm/pgalloc.h (revision 9e1b32caa525cb236e80e9c671e179bcecccc657)
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_PGD 0	/* We preserve special mappings over free */
8f15cbe6fSPaul Mundt #define QUICK_PT 1	/* Other page table pages that are zero on free */
9f15cbe6fSPaul Mundt 
10f15cbe6fSPaul Mundt static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
11f15cbe6fSPaul Mundt 				       pte_t *pte)
12f15cbe6fSPaul Mundt {
13f15cbe6fSPaul Mundt 	set_pmd(pmd, __pmd((unsigned long)pte));
14f15cbe6fSPaul Mundt }
15f15cbe6fSPaul Mundt 
16f15cbe6fSPaul Mundt static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
17f15cbe6fSPaul Mundt 				pgtable_t pte)
18f15cbe6fSPaul Mundt {
19f15cbe6fSPaul Mundt 	set_pmd(pmd, __pmd((unsigned long)page_address(pte)));
20f15cbe6fSPaul Mundt }
21f15cbe6fSPaul Mundt #define pmd_pgtable(pmd) pmd_page(pmd)
22f15cbe6fSPaul Mundt 
23f15cbe6fSPaul Mundt static inline void pgd_ctor(void *x)
24f15cbe6fSPaul Mundt {
25f15cbe6fSPaul Mundt 	pgd_t *pgd = x;
26f15cbe6fSPaul Mundt 
27f15cbe6fSPaul Mundt 	memcpy(pgd + USER_PTRS_PER_PGD,
28f15cbe6fSPaul Mundt 	       swapper_pg_dir + USER_PTRS_PER_PGD,
29f15cbe6fSPaul Mundt 	       (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t));
30f15cbe6fSPaul Mundt }
31f15cbe6fSPaul Mundt 
32f15cbe6fSPaul Mundt /*
33f15cbe6fSPaul Mundt  * Allocate and free page tables.
34f15cbe6fSPaul Mundt  */
35f15cbe6fSPaul Mundt static inline pgd_t *pgd_alloc(struct mm_struct *mm)
36f15cbe6fSPaul Mundt {
37f15cbe6fSPaul Mundt 	return quicklist_alloc(QUICK_PGD, GFP_KERNEL | __GFP_REPEAT, pgd_ctor);
38f15cbe6fSPaul Mundt }
39f15cbe6fSPaul Mundt 
40f15cbe6fSPaul Mundt static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
41f15cbe6fSPaul Mundt {
42f15cbe6fSPaul Mundt 	quicklist_free(QUICK_PGD, NULL, pgd);
43f15cbe6fSPaul Mundt }
44f15cbe6fSPaul Mundt 
45f15cbe6fSPaul Mundt static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
46f15cbe6fSPaul Mundt 					  unsigned long address)
47f15cbe6fSPaul Mundt {
48f15cbe6fSPaul Mundt 	return quicklist_alloc(QUICK_PT, GFP_KERNEL | __GFP_REPEAT, NULL);
49f15cbe6fSPaul Mundt }
50f15cbe6fSPaul Mundt 
51f15cbe6fSPaul Mundt static inline pgtable_t pte_alloc_one(struct mm_struct *mm,
52f15cbe6fSPaul Mundt 					unsigned long address)
53f15cbe6fSPaul Mundt {
54f15cbe6fSPaul Mundt 	struct page *page;
55f15cbe6fSPaul Mundt 	void *pg;
56f15cbe6fSPaul Mundt 
57f15cbe6fSPaul Mundt 	pg = quicklist_alloc(QUICK_PT, GFP_KERNEL | __GFP_REPEAT, NULL);
58f15cbe6fSPaul Mundt 	if (!pg)
59f15cbe6fSPaul Mundt 		return NULL;
60f15cbe6fSPaul Mundt 	page = virt_to_page(pg);
61f15cbe6fSPaul Mundt 	pgtable_page_ctor(page);
62f15cbe6fSPaul Mundt 	return page;
63f15cbe6fSPaul Mundt }
64f15cbe6fSPaul Mundt 
65f15cbe6fSPaul Mundt static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
66f15cbe6fSPaul Mundt {
67f15cbe6fSPaul Mundt 	quicklist_free(QUICK_PT, NULL, pte);
68f15cbe6fSPaul Mundt }
69f15cbe6fSPaul Mundt 
70f15cbe6fSPaul Mundt static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
71f15cbe6fSPaul Mundt {
72f15cbe6fSPaul Mundt 	pgtable_page_dtor(pte);
73f15cbe6fSPaul Mundt 	quicklist_free_page(QUICK_PT, NULL, pte);
74f15cbe6fSPaul Mundt }
75f15cbe6fSPaul Mundt 
76*9e1b32caSBenjamin Herrenschmidt #define __pte_free_tlb(tlb,pte,addr)			\
77f15cbe6fSPaul Mundt do {							\
78f15cbe6fSPaul Mundt 	pgtable_page_dtor(pte);				\
79f15cbe6fSPaul Mundt 	tlb_remove_page((tlb), (pte));			\
80f15cbe6fSPaul Mundt } while (0)
81f15cbe6fSPaul Mundt 
82f15cbe6fSPaul Mundt /*
83f15cbe6fSPaul Mundt  * allocating and freeing a pmd is trivial: the 1-entry pmd is
84f15cbe6fSPaul Mundt  * inside the pgd, so has no extra memory associated with it.
85f15cbe6fSPaul Mundt  */
86f15cbe6fSPaul Mundt 
87f15cbe6fSPaul Mundt #define pmd_free(mm, x)			do { } while (0)
88*9e1b32caSBenjamin Herrenschmidt #define __pmd_free_tlb(tlb,x,addr)	do { } while (0)
89f15cbe6fSPaul Mundt 
90f15cbe6fSPaul Mundt static inline void check_pgt_cache(void)
91f15cbe6fSPaul Mundt {
92f15cbe6fSPaul Mundt 	quicklist_trim(QUICK_PGD, NULL, 25, 16);
93f15cbe6fSPaul Mundt 	quicklist_trim(QUICK_PT, NULL, 25, 16);
94f15cbe6fSPaul Mundt }
95f15cbe6fSPaul Mundt 
96f15cbe6fSPaul Mundt #endif /* __ASM_SH_PGALLOC_H */
97