blob: eed2cad57d6818ed897242b5c7420fa1013eea05 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002#ifndef _ASM_M32R_PGALLOC_H
3#define _ASM_M32R_PGALLOC_H
4
Linus Torvalds1da177e2005-04-16 15:20:36 -07005#include <linux/mm.h>
6
7#include <asm/io.h>
8
9#define pmd_populate_kernel(mm, pmd, pte) \
10 set_pmd(pmd, __pmd(_PAGE_TABLE + __pa(pte)))
11
12static __inline__ void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080013 pgtable_t pte)
Linus Torvalds1da177e2005-04-16 15:20:36 -070014{
15 set_pmd(pmd, __pmd(_PAGE_TABLE + page_to_phys(pte)));
16}
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080017#define pmd_pgtable(pmd) pmd_page(pmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
19/*
20 * Allocate and free page tables.
21 */
22static __inline__ pgd_t *pgd_alloc(struct mm_struct *mm)
23{
24 pgd_t *pgd = (pgd_t *)__get_free_page(GFP_KERNEL|__GFP_ZERO);
25
26 return pgd;
27}
28
Benjamin Herrenschmidt5e541972008-02-04 22:29:14 -080029static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
Linus Torvalds1da177e2005-04-16 15:20:36 -070030{
31 free_page((unsigned long)pgd);
32}
33
34static __inline__ pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
35 unsigned long address)
36{
37 pte_t *pte = (pte_t *)__get_free_page(GFP_KERNEL|__GFP_ZERO);
38
39 return pte;
40}
41
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080042static __inline__ pgtable_t pte_alloc_one(struct mm_struct *mm,
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 unsigned long address)
44{
45 struct page *pte = alloc_page(GFP_KERNEL|__GFP_ZERO);
46
Kirill A. Shutemovfecf3742013-11-14 14:31:18 -080047 if (!pte)
48 return NULL;
Kirill A. Shutemov7251ab62013-11-14 14:31:33 -080049 if (!pgtable_page_ctor(pte)) {
50 __free_page(pte);
51 return NULL;
52 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 return pte;
54}
55
Benjamin Herrenschmidt5e541972008-02-04 22:29:14 -080056static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
Linus Torvalds1da177e2005-04-16 15:20:36 -070057{
58 free_page((unsigned long)pte);
59}
60
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080061static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
Linus Torvalds1da177e2005-04-16 15:20:36 -070062{
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080063 pgtable_page_dtor(pte);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 __free_page(pte);
65}
66
Benjamin Herrenschmidt9e1b32c2009-07-22 15:44:28 +100067#define __pte_free_tlb(tlb, pte, addr) pte_free((tlb)->mm, (pte))
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
69/*
70 * allocating and freeing a pmd is trivial: the 1-entry pmd is
71 * inside the pgd, so has no extra memory associated with it.
72 * (In the PAE case we free the pmds as part of the pgd.)
73 */
74
75#define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
Benjamin Herrenschmidt5e541972008-02-04 22:29:14 -080076#define pmd_free(mm, x) do { } while (0)
Benjamin Herrenschmidt9e1b32c2009-07-22 15:44:28 +100077#define __pmd_free_tlb(tlb, x, addr) do { } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070078#define pgd_populate(mm, pmd, pte) BUG()
79
80#define check_pgt_cache() do { } while (0)
81
82#endif /* _ASM_M32R_PGALLOC_H */