blob: 51fc1f6e4b17afb9d73b7065ad6bea459549d205 [file] [log] [blame]
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001/*
2 * Copyright (C) 2004-2006 Atmel Corporation
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
8#ifndef __ASM_AVR32_PGALLOC_H
9#define __ASM_AVR32_PGALLOC_H
10
11#include <asm/processor.h>
12#include <linux/threads.h>
13#include <linux/slab.h>
14#include <linux/mm.h>
15
16#define pmd_populate_kernel(mm, pmd, pte) \
17 set_pmd(pmd, __pmd(_PAGE_TABLE + __pa(pte)))
18
19static __inline__ void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080020 pgtable_t pte)
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070021{
22 set_pmd(pmd, __pmd(_PAGE_TABLE + page_to_phys(pte)));
23}
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080024#define pmd_pgtable(pmd) pmd_page(pmd)
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070025
26/*
27 * Allocate and free page tables
28 */
29static __inline__ pgd_t *pgd_alloc(struct mm_struct *mm)
30{
Mariusz Kozlowski5221b342007-07-31 23:41:00 +020031 return kcalloc(USER_PTRS_PER_PGD, sizeof(pgd_t), GFP_KERNEL);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070032}
33
Benjamin Herrenschmidt5e541972008-02-04 22:29:14 -080034static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070035{
36 kfree(pgd);
37}
38
39static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
40 unsigned long address)
41{
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070042 pte_t *pte;
43
Haavard Skinnemoene7f3bac2007-08-03 13:29:01 +020044 pte = (pte_t *)get_zeroed_page(GFP_KERNEL | __GFP_REPEAT);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070045
46 return pte;
47}
48
49static inline struct page *pte_alloc_one(struct mm_struct *mm,
50 unsigned long address)
51{
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070052 struct page *pte;
53
Haavard Skinnemoene7f3bac2007-08-03 13:29:01 +020054 pte = alloc_page(GFP_KERNEL | __GFP_REPEAT | __GFP_ZERO);
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080055 if (!pte)
56 return NULL;
57 pgtable_page_ctor(pte);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070058 return pte;
59}
60
Benjamin Herrenschmidt5e541972008-02-04 22:29:14 -080061static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070062{
63 free_page((unsigned long)pte);
64}
65
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080066static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070067{
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080068 pgtable_page_dtor(pte);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070069 __free_page(pte);
70}
71
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080072#define __pte_free_tlb(tlb,pte) \
73do { \
74 pgtable_page_dtor(pte); \
75 tlb_remove_page((tlb), pte); \
76} while (0)
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070077
78#define check_pgt_cache() do { } while(0)
79
80#endif /* __ASM_AVR32_PGALLOC_H */