OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [include/] [asm-mips/] [mmu_context.h] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1276 phoenix
/*
2
 * Switch a MMU context.
3
 *
4
 * This file is subject to the terms and conditions of the GNU General Public
5
 * License.  See the file "COPYING" in the main directory of this archive
6
 * for more details.
7
 *
8
 * Copyright (C) 1996, 1997, 1998, 1999 by Ralf Baechle
9
 * Copyright (C) 1999 Silicon Graphics, Inc.
10
 */
11
#ifndef _ASM_MMU_CONTEXT_H
12
#define _ASM_MMU_CONTEXT_H
13
 
14
#include <linux/config.h>
15
#include <linux/slab.h>
16
#include <asm/pgalloc.h>
17
#include <asm/pgtable.h>
18
 
19
/*
20
 * For the fast tlb miss handlers, we currently keep a per cpu array
21
 * of pointers to the current pgd for each processor. Also, the proc.
22
 * id is stuffed into the context register. This should be changed to
23
 * use the processor id via current->processor, where current is stored
24
 * in watchhi/lo. The context register should be used to contiguously
25
 * map the page tables.
26
 */
27
#define TLBMISS_HANDLER_SETUP_PGD(pgd) \
28
        pgd_current[smp_processor_id()] = (unsigned long)(pgd)
29
#define TLBMISS_HANDLER_SETUP() \
30
        write_c0_context((unsigned long) smp_processor_id() << (23 + 3)); \
31
        TLBMISS_HANDLER_SETUP_PGD(swapper_pg_dir)
32
extern unsigned long pgd_current[];
33
 
34
#define cpu_context(cpu, mm)    ((mm)->context[cpu])
35
#define cpu_asid(cpu, mm)       (cpu_context((cpu), (mm)) & ASID_MASK)
36
#define asid_cache(cpu)         cpu_data[cpu].asid_cache
37
 
38
#if defined(CONFIG_CPU_R3000) || defined(CONFIG_CPU_TX39XX)
39
 
40
#define ASID_INC        0x40
41
#define ASID_MASK       0xfc0
42
 
43
#else /* FIXME: not correct for R6000, R8000 */
44
 
45
#define ASID_INC        0x1
46
#define ASID_MASK       0xff
47
 
48
#endif
49
 
50
static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk, unsigned cpu)
51
{
52
}
53
 
54
/*
55
 *  All unused by hardware upper bits will be considered
56
 *  as a software asid extension.
57
 */
58
#define ASID_VERSION_MASK  ((unsigned long)~(ASID_MASK|(ASID_MASK-1)))
59
#define ASID_FIRST_VERSION ((unsigned long)(~ASID_VERSION_MASK) + 1)
60
 
61
static inline void
62
get_new_mmu_context(struct mm_struct *mm, unsigned long cpu)
63
{
64
        unsigned long asid = asid_cache(cpu);
65
 
66
        if (! ((asid += ASID_INC) & ASID_MASK) ) {
67
                flush_icache_all();
68
                local_flush_tlb_all();  /* start new asid cycle */
69
                if (!asid)              /* fix version if needed */
70
                        asid = ASID_FIRST_VERSION;
71
        }
72
        cpu_context(cpu, mm) = asid_cache(cpu) = asid;
73
}
74
 
75
/*
76
 * Initialize the context related info for a new mm_struct
77
 * instance.
78
 */
79
static inline int
80
init_new_context(struct task_struct *tsk, struct mm_struct *mm)
81
{
82
        int i;
83
 
84
        for (i = 0; i < smp_num_cpus; i++)
85
                cpu_context(i, mm) = 0;
86
        return 0;
87
}
88
 
89
static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
90
                             struct task_struct *tsk, unsigned cpu)
91
{
92
        unsigned long flags;
93
 
94
        local_irq_save(flags);
95
 
96
        /* Check if our ASID is of an older version and thus invalid */
97
        if ((cpu_context(cpu, next) ^ asid_cache(cpu)) & ASID_VERSION_MASK)
98
                get_new_mmu_context(next, cpu);
99
 
100
        write_c0_entryhi(cpu_context(cpu, next));
101
        TLBMISS_HANDLER_SETUP_PGD(next->pgd);
102
 
103
        /*
104
         * Mark current->active_mm as not "active" anymore.
105
         * We don't want to mislead possible IPI tlb flush routines.
106
         */
107
        clear_bit(cpu, &prev->cpu_vm_mask);
108
        set_bit(cpu, &next->cpu_vm_mask);
109
 
110
        local_irq_restore(flags);
111
}
112
 
113
/*
114
 * Destroy context related info for an mm_struct that is about
115
 * to be put to rest.
116
 */
117
static inline void destroy_context(struct mm_struct *mm)
118
{
119
}
120
 
121
/*
122
 * After we have set current->mm to a new value, this activates
123
 * the context for the new mm so we see the new mappings.
124
 */
125
static inline void
126
activate_mm(struct mm_struct *prev, struct mm_struct *next)
127
{
128
        unsigned long flags;
129
        int cpu = smp_processor_id();
130
 
131
        local_irq_save(flags);
132
 
133
        /* Unconditionally get a new ASID.  */
134
        get_new_mmu_context(next, cpu);
135
 
136
        write_c0_entryhi(cpu_context(cpu, next));
137
        TLBMISS_HANDLER_SETUP_PGD(next->pgd);
138
 
139
        /* mark mmu ownership change */
140
        clear_bit(cpu, &prev->cpu_vm_mask);
141
        set_bit(cpu, &next->cpu_vm_mask);
142
 
143
        local_irq_restore(flags);
144
}
145
 
146
/*
147
 * If mm is currently active_mm, we can't really drop it.  Instead,
148
 * we will get a new one for it.
149
 */
150
static inline void
151
drop_mmu_context(struct mm_struct *mm, unsigned cpu)
152
{
153
        unsigned long flags;
154
 
155
        local_irq_save(flags);
156
 
157
        if (test_bit(cpu, &mm->cpu_vm_mask))  {
158
                get_new_mmu_context(mm, cpu);
159
                write_c0_entryhi(cpu_asid(cpu, mm));
160
        } else {
161
                /* will get a new context next time */
162
                cpu_context(cpu, mm) = 0;
163
        }
164
 
165
        local_irq_restore(flags);
166
}
167
 
168
#endif /* _ASM_MMU_CONTEXT_H */

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.