pgalloc.h 1.8 KB
Newer Older
H
Haavard Skinnemoen 已提交
1 2 3 4 5 6 7 8 9 10 11
/*
 * Copyright (C) 2004-2006 Atmel Corporation
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */
#ifndef __ASM_AVR32_PGALLOC_H
#define __ASM_AVR32_PGALLOC_H

#include <linux/mm.h>
12 13
#include <linux/sched.h>
#include <linux/slab.h>
H
Haavard Skinnemoen 已提交
14

15 16 17 18 19
static inline void pmd_populate_kernel(struct mm_struct *mm,
				       pmd_t *pmd, pte_t *pte)
{
	set_pmd(pmd, __pmd((unsigned long)pte));
}
H
Haavard Skinnemoen 已提交
20

21
static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
22
				    pgtable_t pte)
H
Haavard Skinnemoen 已提交
23
{
24
	set_pmd(pmd, __pmd((unsigned long)page_address(pte)));
H
Haavard Skinnemoen 已提交
25
}
26
#define pmd_pgtable(pmd) pmd_page(pmd)
H
Haavard Skinnemoen 已提交
27 28 29 30

/*
 * Allocate and free page tables
 */
31
static inline pgd_t *pgd_alloc(struct mm_struct *mm)
H
Haavard Skinnemoen 已提交
32
{
33
	return kcalloc(USER_PTRS_PER_PGD, sizeof(pgd_t), GFP_KERNEL);
H
Haavard Skinnemoen 已提交
34 35
}

36
static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
H
Haavard Skinnemoen 已提交
37 38 39 40 41 42 43 44 45
{
	kfree(pgd);
}

static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
					  unsigned long address)
{
	pte_t *pte;

46
	pte = (pte_t *)get_zeroed_page(GFP_KERNEL | __GFP_REPEAT);
H
Haavard Skinnemoen 已提交
47 48 49 50 51 52 53 54 55

	return pte;
}

static inline struct page *pte_alloc_one(struct mm_struct *mm,
					 unsigned long address)
{
	struct page *pte;

56
	pte = alloc_page(GFP_KERNEL | __GFP_REPEAT | __GFP_ZERO);
57 58 59
	if (!pte)
		return NULL;
	pgtable_page_ctor(pte);
H
Haavard Skinnemoen 已提交
60 61 62
	return pte;
}

63
static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
H
Haavard Skinnemoen 已提交
64 65 66 67
{
	free_page((unsigned long)pte);
}

68
static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
H
Haavard Skinnemoen 已提交
69
{
70
	pgtable_page_dtor(pte);
H
Haavard Skinnemoen 已提交
71 72 73
	__free_page(pte);
}

74 75 76 77 78
#define __pte_free_tlb(tlb,pte)				\
do {							\
	pgtable_page_dtor(pte);				\
	tlb_remove_page((tlb), pte);			\
} while (0)
H
Haavard Skinnemoen 已提交
79 80 81 82

#define check_pgt_cache() do { } while(0)

#endif /* __ASM_AVR32_PGALLOC_H */