Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at v2.6.21 163 lines 4.2 kB view raw
1#ifndef _ASM_M32R_MMU_CONTEXT_H 2#define _ASM_M32R_MMU_CONTEXT_H 3#ifdef __KERNEL__ 4 5#include <asm/m32r.h> 6 7#define MMU_CONTEXT_ASID_MASK (0x000000FF) 8#define MMU_CONTEXT_VERSION_MASK (0xFFFFFF00) 9#define MMU_CONTEXT_FIRST_VERSION (0x00000100) 10#define NO_CONTEXT (0x00000000) 11 12#ifndef __ASSEMBLY__ 13 14#include <asm/atomic.h> 15#include <asm/pgalloc.h> 16#include <asm/mmu.h> 17#include <asm/tlbflush.h> 18 19/* 20 * Cache of MMU context last used. 21 */ 22#ifndef CONFIG_SMP 23extern unsigned long mmu_context_cache_dat; 24#define mmu_context_cache mmu_context_cache_dat 25#define mm_context(mm) mm->context 26#else /* not CONFIG_SMP */ 27extern unsigned long mmu_context_cache_dat[]; 28#define mmu_context_cache mmu_context_cache_dat[smp_processor_id()] 29#define mm_context(mm) mm->context[smp_processor_id()] 30#endif /* not CONFIG_SMP */ 31 32#define set_tlb_tag(entry, tag) (*entry = (tag & PAGE_MASK)|get_asid()) 33#define set_tlb_data(entry, data) (*entry = (data | _PAGE_PRESENT)) 34 35#ifdef CONFIG_MMU 36#define enter_lazy_tlb(mm, tsk) do { } while (0) 37 38static inline void get_new_mmu_context(struct mm_struct *mm) 39{ 40 unsigned long mc = ++mmu_context_cache; 41 42 if (!(mc & MMU_CONTEXT_ASID_MASK)) { 43 /* We exhaust ASID of this version. 44 Flush all TLB and start new cycle. */ 45 local_flush_tlb_all(); 46 /* Fix version if needed. 47 Note that we avoid version #0 to distingush NO_CONTEXT. */ 48 if (!mc) 49 mmu_context_cache = mc = MMU_CONTEXT_FIRST_VERSION; 50 } 51 mm_context(mm) = mc; 52} 53 54/* 55 * Get MMU context if needed. 56 */ 57static inline void get_mmu_context(struct mm_struct *mm) 58{ 59 if (mm) { 60 unsigned long mc = mmu_context_cache; 61 62 /* Check if we have old version of context. 63 If it's old, we need to get new context with new version. */ 64 if ((mm_context(mm) ^ mc) & MMU_CONTEXT_VERSION_MASK) 65 get_new_mmu_context(mm); 66 } 67} 68 69/* 70 * Initialize the context related info for a new mm_struct 71 * instance. 72 */ 73static inline int init_new_context(struct task_struct *tsk, 74 struct mm_struct *mm) 75{ 76#ifndef CONFIG_SMP 77 mm->context = NO_CONTEXT; 78#else /* CONFIG_SMP */ 79 int num_cpus = num_online_cpus(); 80 int i; 81 82 for (i = 0 ; i < num_cpus ; i++) 83 mm->context[i] = NO_CONTEXT; 84#endif /* CONFIG_SMP */ 85 86 return 0; 87} 88 89/* 90 * Destroy context related info for an mm_struct that is about 91 * to be put to rest. 92 */ 93#define destroy_context(mm) do { } while (0) 94 95static inline void set_asid(unsigned long asid) 96{ 97 *(volatile unsigned long *)MASID = (asid & MMU_CONTEXT_ASID_MASK); 98} 99 100static inline unsigned long get_asid(void) 101{ 102 unsigned long asid; 103 104 asid = *(volatile long *)MASID; 105 asid &= MMU_CONTEXT_ASID_MASK; 106 107 return asid; 108} 109 110/* 111 * After we have set current->mm to a new value, this activates 112 * the context for the new mm so we see the new mappings. 113 */ 114static inline void activate_context(struct mm_struct *mm) 115{ 116 get_mmu_context(mm); 117 set_asid(mm_context(mm) & MMU_CONTEXT_ASID_MASK); 118} 119 120static inline void switch_mm(struct mm_struct *prev, 121 struct mm_struct *next, struct task_struct *tsk) 122{ 123#ifdef CONFIG_SMP 124 int cpu = smp_processor_id(); 125#endif /* CONFIG_SMP */ 126 127 if (prev != next) { 128#ifdef CONFIG_SMP 129 cpu_set(cpu, next->cpu_vm_mask); 130#endif /* CONFIG_SMP */ 131 /* Set MPTB = next->pgd */ 132 *(volatile unsigned long *)MPTB = (unsigned long)next->pgd; 133 activate_context(next); 134 } 135#ifdef CONFIG_SMP 136 else 137 if (!cpu_test_and_set(cpu, next->cpu_vm_mask)) 138 activate_context(next); 139#endif /* CONFIG_SMP */ 140} 141 142#define deactivate_mm(tsk, mm) do { } while (0) 143 144#define activate_mm(prev, next) \ 145 switch_mm((prev), (next), NULL) 146 147#else /* not CONFIG_MMU */ 148#define get_mmu_context(mm) do { } while (0) 149#define init_new_context(tsk,mm) (0) 150#define destroy_context(mm) do { } while (0) 151#define set_asid(asid) do { } while (0) 152#define get_asid() (0) 153#define activate_context(mm) do { } while (0) 154#define switch_mm(prev,next,tsk) do { } while (0) 155#define deactivate_mm(mm,tsk) do { } while (0) 156#define activate_mm(prev,next) do { } while (0) 157#define enter_lazy_tlb(mm,tsk) do { } while (0) 158#endif /* not CONFIG_MMU */ 159 160#endif /* not __ASSEMBLY__ */ 161 162#endif /* __KERNEL__ */ 163#endif /* _ASM_M32R_MMU_CONTEXT_H */