blob: 75248141c6137212893aafcc669e1bbd44e2100d [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,
20 struct page *pte)
21{
22 set_pmd(pmd, __pmd(_PAGE_TABLE + page_to_phys(pte)));
23}
24
25/*
26 * Allocate and free page tables
27 */
28static __inline__ pgd_t *pgd_alloc(struct mm_struct *mm)
29{
Mariusz Kozlowski5221b342007-07-31 23:41:00 +020030 return kcalloc(USER_PTRS_PER_PGD, sizeof(pgd_t), GFP_KERNEL);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070031}
32
33static inline void pgd_free(pgd_t *pgd)
34{
35 kfree(pgd);
36}
37
38static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
39 unsigned long address)
40{
41 int count = 0;
42 pte_t *pte;
43
44 do {
45 pte = (pte_t *) __get_free_page(GFP_KERNEL | __GFP_REPEAT);
46 if (pte)
47 clear_page(pte);
48 else {
49 current->state = TASK_UNINTERRUPTIBLE;
50 schedule_timeout(HZ);
51 }
52 } while (!pte && (count++ < 10));
53
54 return pte;
55}
56
57static inline struct page *pte_alloc_one(struct mm_struct *mm,
58 unsigned long address)
59{
60 int count = 0;
61 struct page *pte;
62
63 do {
64 pte = alloc_pages(GFP_KERNEL, 0);
65 if (pte)
66 clear_page(page_address(pte));
67 else {
68 current->state = TASK_UNINTERRUPTIBLE;
69 schedule_timeout(HZ);
70 }
71 } while (!pte && (count++ < 10));
72
73 return pte;
74}
75
76static inline void pte_free_kernel(pte_t *pte)
77{
78 free_page((unsigned long)pte);
79}
80
81static inline void pte_free(struct page *pte)
82{
83 __free_page(pte);
84}
85
86#define __pte_free_tlb(tlb,pte) tlb_remove_page((tlb),(pte))
87
88#define check_pgt_cache() do { } while(0)
89
90#endif /* __ASM_AVR32_PGALLOC_H */