Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef _I386_PGALLOC_H |
| 2 | #define _I386_PGALLOC_H |
| 3 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | #include <linux/threads.h> |
| 5 | #include <linux/mm.h> /* for struct page */ |
Ingo Molnar | 5aa0508 | 2008-01-31 22:05:48 +0100 | [diff] [blame] | 6 | #include <linux/pagemap.h> |
Jeremy Fitzhardinge | a5a19c6 | 2008-01-30 13:33:39 +0100 | [diff] [blame] | 7 | #include <asm/tlb.h> |
| 8 | #include <asm-generic/tlb.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | |
Zachary Amsden | c119ecc | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 10 | #ifdef CONFIG_PARAVIRT |
| 11 | #include <asm/paravirt.h> |
| 12 | #else |
Jeremy Fitzhardinge | fdb4c33 | 2007-07-17 18:37:03 -0700 | [diff] [blame] | 13 | #define paravirt_alloc_pt(mm, pfn) do { } while (0) |
Jeremy Fitzhardinge | 6c43545 | 2008-01-30 13:33:39 +0100 | [diff] [blame] | 14 | #define paravirt_alloc_pd(mm, pfn) do { } while (0) |
Zachary Amsden | c119ecc | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 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 | |
Jeremy Fitzhardinge | a5a19c6 | 2008-01-30 13:33:39 +0100 | [diff] [blame] | 20 | static 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 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
Jeremy Fitzhardinge | a5a19c6 | 2008-01-30 13:33:39 +0100 | [diff] [blame] | 27 | static 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 | } |
Zachary Amsden | c119ecc | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 34 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | /* |
| 36 | * Allocate and free page tables. |
| 37 | */ |
| 38 | extern pgd_t *pgd_alloc(struct mm_struct *); |
Benjamin Herrenschmidt | 5e54197 | 2008-02-04 22:29:14 -0800 | [diff] [blame] | 39 | extern void pgd_free(struct mm_struct *mm, pgd_t *pgd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
| 41 | extern pte_t *pte_alloc_one_kernel(struct mm_struct *, unsigned long); |
| 42 | extern struct page *pte_alloc_one(struct mm_struct *, unsigned long); |
| 43 | |
Benjamin Herrenschmidt | 5e54197 | 2008-02-04 22:29:14 -0800 | [diff] [blame] | 44 | static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | { |
| 46 | free_page((unsigned long)pte); |
| 47 | } |
| 48 | |
Benjamin Herrenschmidt | 5e54197 | 2008-02-04 22:29:14 -0800 | [diff] [blame] | 49 | static inline void pte_free(struct mm_struct *mm, struct page *pte) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | { |
| 51 | __free_page(pte); |
| 52 | } |
| 53 | |
| 54 | |
Ingo Molnar | 5aa0508 | 2008-01-31 22:05:48 +0100 | [diff] [blame] | 55 | extern void __pte_free_tlb(struct mmu_gather *tlb, struct page *pte); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
| 57 | #ifdef CONFIG_X86_PAE |
| 58 | /* |
| 59 | * In the PAE case we free the pmds as part of the pgd. |
| 60 | */ |
Jeremy Fitzhardinge | a5a19c6 | 2008-01-30 13:33:39 +0100 | [diff] [blame] | 61 | static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr) |
| 62 | { |
Jeremy Fitzhardinge | 6194ba6 | 2008-01-30 13:34:11 +0100 | [diff] [blame] | 63 | return (pmd_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT); |
Jeremy Fitzhardinge | a5a19c6 | 2008-01-30 13:33:39 +0100 | [diff] [blame] | 64 | } |
| 65 | |
Benjamin Herrenschmidt | 5e54197 | 2008-02-04 22:29:14 -0800 | [diff] [blame] | 66 | static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd) |
Jeremy Fitzhardinge | a5a19c6 | 2008-01-30 13:33:39 +0100 | [diff] [blame] | 67 | { |
Jeremy Fitzhardinge | 6194ba6 | 2008-01-30 13:34:11 +0100 | [diff] [blame] | 68 | BUG_ON((unsigned long)pmd & (PAGE_SIZE-1)); |
| 69 | free_page((unsigned long)pmd); |
Jeremy Fitzhardinge | a5a19c6 | 2008-01-30 13:33:39 +0100 | [diff] [blame] | 70 | } |
| 71 | |
Ingo Molnar | 5aa0508 | 2008-01-31 22:05:48 +0100 | [diff] [blame] | 72 | extern void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd); |
Jeremy Fitzhardinge | a5a19c6 | 2008-01-30 13:33:39 +0100 | [diff] [blame] | 73 | |
Jeremy Fitzhardinge | 6194ba6 | 2008-01-30 13:34:11 +0100 | [diff] [blame] | 74 | static inline void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd) |
Jeremy Fitzhardinge | a5a19c6 | 2008-01-30 13:33:39 +0100 | [diff] [blame] | 75 | { |
Jeremy Fitzhardinge | 6194ba6 | 2008-01-30 13:34:11 +0100 | [diff] [blame] | 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 | /* |
Jeremy Fitzhardinge | f5430f9 | 2008-02-04 16:48:02 +0100 | [diff] [blame] | 83 | * According to Intel App note "TLBs, Paging-Structure Caches, |
| 84 | * and Their Invalidation", April 2007, document 317080-001, |
| 85 | * section 8.1: in PAE mode we explicitly have to flush the |
| 86 | * TLB via cr3 if the top-level pgd is changed... |
Jeremy Fitzhardinge | 6194ba6 | 2008-01-30 13:34:11 +0100 | [diff] [blame] | 87 | */ |
| 88 | if (mm == current->active_mm) |
| 89 | write_cr3(read_cr3()); |
Jeremy Fitzhardinge | a5a19c6 | 2008-01-30 13:33:39 +0100 | [diff] [blame] | 90 | } |
| 91 | #endif /* CONFIG_X86_PAE */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | #endif /* _I386_PGALLOC_H */ |