Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Russell King | 4baa992 | 2008-08-02 10:55:55 +0100 | [diff] [blame] | 2 | * arch/arm/include/asm/tlb.h |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2002 Russell King |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | * |
| 10 | * Experimentation shows that on a StrongARM, it appears to be faster |
| 11 | * to use the "invalidate whole tlb" rather than "invalidate single |
| 12 | * tlb" for this. |
| 13 | * |
| 14 | * This appears true for both the process fork+exit case, as well as |
| 15 | * the munmap-large-area case. |
| 16 | */ |
| 17 | #ifndef __ASMARM_TLB_H |
| 18 | #define __ASMARM_TLB_H |
| 19 | |
| 20 | #include <asm/cacheflush.h> |
| 21 | #include <asm/tlbflush.h> |
Hyok S. Choi | 0157903 | 2006-02-24 21:41:25 +0000 | [diff] [blame] | 22 | |
| 23 | #ifndef CONFIG_MMU |
| 24 | |
| 25 | #include <linux/pagemap.h> |
| 26 | #include <asm-generic/tlb.h> |
| 27 | |
| 28 | #else /* !CONFIG_MMU */ |
| 29 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <asm/pgalloc.h> |
| 31 | |
| 32 | /* |
| 33 | * TLB handling. This allows us to remove pages from the page |
| 34 | * tables, and efficiently handle the TLB issues. |
| 35 | */ |
| 36 | struct mmu_gather { |
| 37 | struct mm_struct *mm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | unsigned int fullmm; |
Aaro Koskinen | 7fccfc0 | 2009-04-14 13:07:35 +0100 | [diff] [blame] | 39 | unsigned long range_start; |
| 40 | unsigned long range_end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | }; |
| 42 | |
| 43 | DECLARE_PER_CPU(struct mmu_gather, mmu_gathers); |
| 44 | |
| 45 | static inline struct mmu_gather * |
| 46 | tlb_gather_mmu(struct mm_struct *mm, unsigned int full_mm_flush) |
| 47 | { |
Hugh Dickins | 15a23ff | 2005-10-29 18:16:01 -0700 | [diff] [blame] | 48 | struct mmu_gather *tlb = &get_cpu_var(mmu_gathers); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
| 50 | tlb->mm = mm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | tlb->fullmm = full_mm_flush; |
| 52 | |
| 53 | return tlb; |
| 54 | } |
| 55 | |
| 56 | static inline void |
| 57 | tlb_finish_mmu(struct mmu_gather *tlb, unsigned long start, unsigned long end) |
| 58 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | if (tlb->fullmm) |
Hugh Dickins | fc2acab | 2005-10-29 18:16:03 -0700 | [diff] [blame] | 60 | flush_tlb_mm(tlb->mm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
| 62 | /* keep the page table cache within bounds */ |
| 63 | check_pgt_cache(); |
Hugh Dickins | 15a23ff | 2005-10-29 18:16:01 -0700 | [diff] [blame] | 64 | |
| 65 | put_cpu_var(mmu_gathers); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | } |
| 67 | |
Aaro Koskinen | 7fccfc0 | 2009-04-14 13:07:35 +0100 | [diff] [blame] | 68 | /* |
| 69 | * Memorize the range for the TLB flush. |
| 70 | */ |
| 71 | static inline void |
| 72 | tlb_remove_tlb_entry(struct mmu_gather *tlb, pte_t *ptep, unsigned long addr) |
| 73 | { |
| 74 | if (!tlb->fullmm) { |
| 75 | if (addr < tlb->range_start) |
| 76 | tlb->range_start = addr; |
| 77 | if (addr + PAGE_SIZE > tlb->range_end) |
| 78 | tlb->range_end = addr + PAGE_SIZE; |
| 79 | } |
| 80 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | |
| 82 | /* |
| 83 | * In the case of tlb vma handling, we can optimise these away in the |
| 84 | * case where we're doing a full MM flush. When we're doing a munmap, |
| 85 | * the vmas are adjusted to only cover the region to be torn down. |
| 86 | */ |
| 87 | static inline void |
| 88 | tlb_start_vma(struct mmu_gather *tlb, struct vm_area_struct *vma) |
| 89 | { |
Aaro Koskinen | 7fccfc0 | 2009-04-14 13:07:35 +0100 | [diff] [blame] | 90 | if (!tlb->fullmm) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | flush_cache_range(vma, vma->vm_start, vma->vm_end); |
Aaro Koskinen | 7fccfc0 | 2009-04-14 13:07:35 +0100 | [diff] [blame] | 92 | tlb->range_start = TASK_SIZE; |
| 93 | tlb->range_end = 0; |
| 94 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | static inline void |
| 98 | tlb_end_vma(struct mmu_gather *tlb, struct vm_area_struct *vma) |
| 99 | { |
Aaro Koskinen | 7fccfc0 | 2009-04-14 13:07:35 +0100 | [diff] [blame] | 100 | if (!tlb->fullmm && tlb->range_end > 0) |
| 101 | flush_tlb_range(vma, tlb->range_start, tlb->range_end); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | #define tlb_remove_page(tlb,page) free_page_and_swap_cache(page) |
Benjamin Herrenschmidt | 9e1b32c | 2009-07-22 15:44:28 +1000 | [diff] [blame] | 105 | #define pte_free_tlb(tlb, ptep, addr) pte_free((tlb)->mm, ptep) |
| 106 | #define pmd_free_tlb(tlb, pmdp, addr) pmd_free((tlb)->mm, pmdp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | |
| 108 | #define tlb_migrate_finish(mm) do { } while (0) |
| 109 | |
Hyok S. Choi | 0157903 | 2006-02-24 21:41:25 +0000 | [diff] [blame] | 110 | #endif /* CONFIG_MMU */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | #endif |