Linux kernel & device driver programming

Cross-Referenced Linux and Device Driver Code

[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ]
Version: [ 2.6.11.8 ] [ 2.6.25 ] [ 2.6.25.8 ] [ 2.6.31.13 ] Architecture: [ i386 ]
  1 /* include/asm-generic/tlb.h
  2  *
  3  *      Generic TLB shootdown code
  4  *
  5  * Copyright 2001 Red Hat, Inc.
  6  * Based on code from mm/memory.c Copyright Linus Torvalds and others.
  7  *
  8  * This program is free software; you can redistribute it and/or
  9  * modify it under the terms of the GNU General Public License
 10  * as published by the Free Software Foundation; either version
 11  * 2 of the License, or (at your option) any later version.
 12  */
 13 #ifndef _ASM_GENERIC__TLB_H
 14 #define _ASM_GENERIC__TLB_H
 15 
 16 #include <linux/swap.h>
 17 #include <asm/pgalloc.h>
 18 #include <asm/tlbflush.h>
 19 
 20 /*
 21  * For UP we don't need to worry about TLB flush
 22  * and page free order so much..
 23  */
 24 #ifdef CONFIG_SMP
 25   #ifdef ARCH_FREE_PTR_NR
 26     #define FREE_PTR_NR   ARCH_FREE_PTR_NR
 27   #else
 28     #define FREE_PTE_NR 506
 29   #endif
 30   #define tlb_fast_mode(tlb) ((tlb)->nr == ~0U)
 31 #else
 32   #define FREE_PTE_NR   1
 33   #define tlb_fast_mode(tlb) 1
 34 #endif
 35 
 36 /* struct mmu_gather is an opaque type used by the mm code for passing around
 37  * any data needed by arch specific code for tlb_remove_page.
 38  */
 39 struct mmu_gather {
 40         struct mm_struct        *mm;
 41         unsigned int            nr;     /* set to ~0U means fast mode */
 42         unsigned int            need_flush;/* Really unmapped some ptes? */
 43         unsigned int            fullmm; /* non-zero means full mm flush */
 44         int                     cpu;
 45         struct page *           pages[FREE_PTE_NR];
 46 };
 47 
 48 /* Users of the generic TLB shootdown code must declare this storage space. */
 49 DECLARE_PER_CPU_LOCKED(struct mmu_gather, mmu_gathers);
 50 
 51 /* tlb_gather_mmu
 52  *      Return a pointer to an initialized struct mmu_gather.
 53  */
 54 static inline struct mmu_gather *
 55 tlb_gather_mmu(struct mm_struct *mm, unsigned int full_mm_flush)
 56 {
 57         int cpu;
 58         struct mmu_gather *tlb = &get_cpu_var_locked(mmu_gathers, &cpu);
 59 
 60         tlb->cpu = cpu;
 61         tlb->mm = mm;
 62 
 63         /* Use fast mode if only one CPU is online */
 64         tlb->nr = num_online_cpus() > 1 ? 0U : ~0U;
 65 
 66         tlb->fullmm = full_mm_flush;
 67 
 68         return tlb;
 69 }
 70 
 71 static inline void
 72 tlb_flush_mmu(struct mmu_gather *tlb, unsigned long start, unsigned long end)
 73 {
 74         if (!tlb->need_flush)
 75                 return;
 76         tlb->need_flush = 0;
 77         tlb_flush(tlb);
 78         if (!tlb_fast_mode(tlb)) {
 79                 free_pages_and_swap_cache(tlb->pages, tlb->nr);
 80                 tlb->nr = 0;
 81         }
 82 }
 83 
 84 /* tlb_finish_mmu
 85  *      Called at the end of the shootdown operation to free up any resources
 86  *      that were required.
 87  */
 88 static inline void
 89 tlb_finish_mmu(struct mmu_gather *tlb, unsigned long start, unsigned long end)
 90 {
 91         tlb_flush_mmu(tlb, start, end);
 92 
 93         /* keep the page table cache within bounds */
 94         check_pgt_cache();
 95 
 96         put_cpu_var_locked(mmu_gathers, tlb->cpu);
 97 }
 98 
 99 /* tlb_remove_page
100  *      Must perform the equivalent to __free_pte(pte_get_and_clear(ptep)), while
101  *      handling the additional races in SMP caused by other CPUs caching valid
102  *      mappings in their TLBs.
103  */
104 static inline void tlb_remove_page(struct mmu_gather *tlb, struct page *page)
105 {
106         tlb->need_flush = 1;
107         if (tlb_fast_mode(tlb)) {
108                 free_page_and_swap_cache(page);
109                 return;
110         }
111         tlb->pages[tlb->nr++] = page;
112         if (tlb->nr >= FREE_PTE_NR)
113                 tlb_flush_mmu(tlb, 0, 0);
114 }
115 
116 /**
117  * tlb_remove_tlb_entry - remember a pte unmapping for later tlb invalidation.
118  *
119  * Record the fact that pte's were really umapped in ->need_flush, so we can
120  * later optimise away the tlb invalidate.   This helps when userspace is
121  * unmapping already-unmapped pages, which happens quite a lot.
122  */
123 #define tlb_remove_tlb_entry(tlb, ptep, address)                \
124         do {                                                    \
125                 tlb->need_flush = 1;                            \
126                 __tlb_remove_tlb_entry(tlb, ptep, address);     \
127         } while (0)
128 
129 #define pte_free_tlb(tlb, ptep)                                 \
130         do {                                                    \
131                 tlb->need_flush = 1;                            \
132                 __pte_free_tlb(tlb, ptep);                      \
133         } while (0)
134 
135 #ifndef __ARCH_HAS_4LEVEL_HACK
136 #define pud_free_tlb(tlb, pudp)                                 \
137         do {                                                    \
138                 tlb->need_flush = 1;                            \
139                 __pud_free_tlb(tlb, pudp);                      \
140         } while (0)
141 #endif
142 
143 #define pmd_free_tlb(tlb, pmdp)                                 \
144         do {                                                    \
145                 tlb->need_flush = 1;                            \
146                 __pmd_free_tlb(tlb, pmdp);                      \
147         } while (0)
148 
149 #define tlb_migrate_finish(mm) do {} while (0)
150 
151 #endif /* _ASM_GENERIC__TLB_H */
152 
  This page was automatically generated by the LXR engine.