asm-generic: pgalloc: provide generic pmd_alloc_one() and pmd_free_one()
[linux-block.git] / arch / mips / include / asm / pgalloc.h
CommitLineData
1da177e4
LT
1/*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
6 * Copyright (C) 1994 - 2001, 2003 by Ralf Baechle
7 * Copyright (C) 1999, 2000, 2001 Silicon Graphics, Inc.
8 */
9#ifndef _ASM_PGALLOC_H
10#define _ASM_PGALLOC_H
11
1da177e4
LT
12#include <linux/highmem.h>
13#include <linux/mm.h>
e8edc6e0 14#include <linux/sched.h>
1da177e4 15
1355c31e
MR
16#define __HAVE_ARCH_PMD_ALLOC_ONE
17#include <asm-generic/pgalloc.h>
b7902ce1 18
1da177e4
LT
19static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
20 pte_t *pte)
21{
22 set_pmd(pmd, __pmd((unsigned long)pte));
23}
24
25static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
2f569afd 26 pgtable_t pte)
1da177e4
LT
27{
28 set_pmd(pmd, __pmd((unsigned long)page_address(pte)));
29}
2f569afd 30#define pmd_pgtable(pmd) pmd_page(pmd)
1da177e4 31
c6e8b587
RB
32/*
33 * Initialize a new pmd table with invalid pointers.
34 */
35extern void pmd_init(unsigned long page, unsigned long pagetable);
36
325f8a0a 37#ifndef __PAGETABLE_PMD_FOLDED
c6e8b587
RB
38
39static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
40{
41 set_pud(pud, __pud((unsigned long)pmd));
42}
43#endif
44
1da177e4
LT
45/*
46 * Initialize a new pgd / pmd table with invalid pointers.
47 */
48extern void pgd_init(unsigned long page);
814f91bf 49extern pgd_t *pgd_alloc(struct mm_struct *mm);
1da177e4 50
5e541973 51static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
1da177e4
LT
52{
53 free_pages((unsigned long)pgd, PGD_ORDER);
54}
55
9e1b32ca 56#define __pte_free_tlb(tlb,pte,address) \
2f569afd 57do { \
b4ed71f5 58 pgtable_pte_page_dtor(pte); \
2f569afd
MS
59 tlb_remove_page((tlb), pte); \
60} while (0)
1da177e4 61
325f8a0a 62#ifndef __PAGETABLE_PMD_FOLDED
1da177e4 63
1da177e4
LT
64static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
65{
66 pmd_t *pmd;
67
65f84656 68 pmd = (pmd_t *) __get_free_pages(GFP_KERNEL, PMD_ORDER);
1da177e4
LT
69 if (pmd)
70 pmd_init((unsigned long)pmd, (unsigned long)invalid_pte_table);
71 return pmd;
72}
73
9e1b32ca 74#define __pmd_free_tlb(tlb, x, addr) pmd_free((tlb)->mm, x)
1da177e4
LT
75
76#endif
77
3377e227
AB
78#ifndef __PAGETABLE_PUD_FOLDED
79
80static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long address)
81{
82 pud_t *pud;
83
473738eb 84 pud = (pud_t *) __get_free_pages(GFP_KERNEL, PUD_ORDER);
3377e227
AB
85 if (pud)
86 pud_init((unsigned long)pud, (unsigned long)invalid_pmd_table);
87 return pud;
88}
89
90static inline void pud_free(struct mm_struct *mm, pud_t *pud)
91{
92 free_pages((unsigned long)pud, PUD_ORDER);
93}
94
2bee1b58 95static inline void p4d_populate(struct mm_struct *mm, p4d_t *p4d, pud_t *pud)
3377e227 96{
2bee1b58 97 set_p4d(p4d, __p4d((unsigned long)pud));
3377e227
AB
98}
99
100#define __pud_free_tlb(tlb, x, addr) pud_free((tlb)->mm, x)
101
102#endif /* __PAGETABLE_PUD_FOLDED */
103
6a1e5529
AN
104extern void pagetable_init(void);
105
1da177e4 106#endif /* _ASM_PGALLOC_H */