Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1#ifndef _I386_PGALLOC_H
2#define _I386_PGALLOC_H
3
4#include <linux/threads.h>
5#include <linux/mm.h> /* for struct page */
6#include <linux/pagemap.h>
7#include <asm/tlb.h>
8#include <asm-generic/tlb.h>
9
10#ifdef CONFIG_PARAVIRT
11#include <asm/paravirt.h>
12#else
13#define paravirt_alloc_pt(mm, pfn) do { } while (0)
14#define paravirt_alloc_pd(mm, pfn) do { } while (0)
15#define paravirt_alloc_pd_clone(pfn, clonepfn, start, count) do { } while (0)
16#define paravirt_release_pt(pfn) do { } while (0)
17#define paravirt_release_pd(pfn) do { } while (0)
18#endif
19
20static inline void pmd_populate_kernel(struct mm_struct *mm,
21 pmd_t *pmd, pte_t *pte)
22{
23 paravirt_alloc_pt(mm, __pa(pte) >> PAGE_SHIFT);
24 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
25}
26
27static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd, struct page *pte)
28{
29 unsigned long pfn = page_to_pfn(pte);
30
31 paravirt_alloc_pt(mm, pfn);
32 set_pmd(pmd, __pmd(((pteval_t)pfn << PAGE_SHIFT) | _PAGE_TABLE));
33}
34
35/*
36 * Allocate and free page tables.
37 */
38extern pgd_t *pgd_alloc(struct mm_struct *);
39extern void pgd_free(pgd_t *pgd);
40
41extern pte_t *pte_alloc_one_kernel(struct mm_struct *, unsigned long);
42extern struct page *pte_alloc_one(struct mm_struct *, unsigned long);
43
44static inline void pte_free_kernel(pte_t *pte)
45{
46 free_page((unsigned long)pte);
47}
48
49static inline void pte_free(struct page *pte)
50{
51 __free_page(pte);
52}
53
54
55extern void __pte_free_tlb(struct mmu_gather *tlb, struct page *pte);
56
57#ifdef CONFIG_X86_PAE
58/*
59 * In the PAE case we free the pmds as part of the pgd.
60 */
61static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
62{
63 return (pmd_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
64}
65
66static inline void pmd_free(pmd_t *pmd)
67{
68 BUG_ON((unsigned long)pmd & (PAGE_SIZE-1));
69 free_page((unsigned long)pmd);
70}
71
72extern void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd);
73
74static inline void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
75{
76 paravirt_alloc_pd(mm, __pa(pmd) >> PAGE_SHIFT);
77
78 /* Note: almost everything apart from _PAGE_PRESENT is
79 reserved at the pmd (PDPT) level. */
80 set_pud(pudp, __pud(__pa(pmd) | _PAGE_PRESENT));
81
82 /*
83 * Pentium-II erratum A13: in PAE mode we explicitly have to flush
84 * the TLB via cr3 if the top-level pgd is changed...
85 */
86 if (mm == current->active_mm)
87 write_cr3(read_cr3());
88}
89#endif /* CONFIG_X86_PAE */
90
91#endif /* _I386_PGALLOC_H */