blob: fd090155dccd14367fcde13c425f5d224de7eb21 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _ALPHA_PGALLOC_H
2#define _ALPHA_PGALLOC_H
3
Linus Torvalds1da177e2005-04-16 15:20:36 -07004#include <linux/mm.h>
5#include <linux/mmzone.h>
6
7/*
8 * Allocate and free page tables. The xxx_kernel() versions are
9 * used to allocate a kernel page table - this turns on ASN bits
10 * if any.
11 */
12
13static inline void
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080014pmd_populate(struct mm_struct *mm, pmd_t *pmd, pgtable_t pte)
Linus Torvalds1da177e2005-04-16 15:20:36 -070015{
16 pmd_set(pmd, (pte_t *)(page_to_pa(pte) + PAGE_OFFSET));
17}
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080018#define pmd_pgtable(pmd) pmd_page(pmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
20static inline void
21pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd, pte_t *pte)
22{
23 pmd_set(pmd, pte);
24}
25
26static inline void
27pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
28{
29 pgd_set(pgd, pmd);
30}
31
32extern pgd_t *pgd_alloc(struct mm_struct *mm);
33
34static inline void
Benjamin Herrenschmidt5e541972008-02-04 22:29:14 -080035pgd_free(struct mm_struct *mm, pgd_t *pgd)
Linus Torvalds1da177e2005-04-16 15:20:36 -070036{
37 free_page((unsigned long)pgd);
38}
39
40static inline pmd_t *
41pmd_alloc_one(struct mm_struct *mm, unsigned long address)
42{
43 pmd_t *ret = (pmd_t *)__get_free_page(GFP_KERNEL|__GFP_REPEAT|__GFP_ZERO);
44 return ret;
45}
46
47static inline void
Benjamin Herrenschmidt5e541972008-02-04 22:29:14 -080048pmd_free(struct mm_struct *mm, pmd_t *pmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -070049{
50 free_page((unsigned long)pmd);
51}
52
53extern pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long addr);
54
55static inline void
Benjamin Herrenschmidt5e541972008-02-04 22:29:14 -080056pte_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 pgtable_t
62pte_alloc_one(struct mm_struct *mm, unsigned long address)
Linus Torvalds1da177e2005-04-16 15:20:36 -070063{
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080064 pte_t *pte = pte_alloc_one_kernel(mm, address);
65 struct page *page;
66
67 if (!pte)
68 return NULL;
69 page = virt_to_page(pte);
70 pgtable_page_ctor(page);
71 return page;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072}
73
74static inline void
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080075pte_free(struct mm_struct *mm, pgtable_t page)
Linus Torvalds1da177e2005-04-16 15:20:36 -070076{
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080077 pgtable_page_dtor(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 __free_page(page);
79}
80
81#define check_pgt_cache() do { } while (0)
82
83#endif /* _ALPHA_PGALLOC_H */