blob: dbd8731a876aec90c2765df2dd1a1c6d5e2310d0 [file] [log] [blame]
Chris Zankel9a8fd552005-06-23 22:01:26 -07001/*
2 * include/asm-xtensa/mmu_context.h
3 *
4 * Switch an MMU context.
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
8 * for more details.
9 *
10 * Copyright (C) 2001 - 2005 Tensilica Inc.
11 */
12
13#ifndef _XTENSA_MMU_CONTEXT_H
14#define _XTENSA_MMU_CONTEXT_H
15
Johannes Weinere5083a62009-03-04 16:21:31 +010016#ifndef CONFIG_MMU
17#include <asm/nommu_context.h>
18#else
19
Chris Zankel9a8fd552005-06-23 22:01:26 -070020#include <linux/stringify.h>
Chris Zankelde4f6e52007-05-31 17:47:01 -070021#include <linux/sched.h>
Chris Zankel9a8fd552005-06-23 22:01:26 -070022
Johannes Weiner4f682fb2009-03-04 16:21:28 +010023#include <variant/core.h>
24
Chris Zankel9a8fd552005-06-23 22:01:26 -070025#include <asm/pgtable.h>
Chris Zankel9a8fd552005-06-23 22:01:26 -070026#include <asm/cacheflush.h>
27#include <asm/tlbflush.h>
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +020028#include <asm-generic/mm_hooks.h>
Chris Zankel9a8fd552005-06-23 22:01:26 -070029
Chris Zankel9a8fd552005-06-23 22:01:26 -070030#if (XCHAL_HAVE_TLBS != 1)
31# error "Linux must have an MMU!"
32#endif
33
Chris Zankel9a8fd552005-06-23 22:01:26 -070034extern unsigned long asid_cache;
Chris Zankel9a8fd552005-06-23 22:01:26 -070035
36/*
37 * NO_CONTEXT is the invalid ASID value that we don't ever assign to
Chris Zankel173d6682006-12-10 02:18:48 -080038 * any user or kernel context.
39 *
40 * 0 invalid
41 * 1 kernel
42 * 2 reserved
43 * 3 reserved
44 * 4...255 available
Chris Zankel9a8fd552005-06-23 22:01:26 -070045 */
46
Chris Zankel173d6682006-12-10 02:18:48 -080047#define NO_CONTEXT 0
48#define ASID_USER_FIRST 4
49#define ASID_MASK ((1 << XCHAL_MMU_ASID_BITS) - 1)
50#define ASID_INSERT(x) (0x03020001 | (((x) & ASID_MASK) << 8))
Chris Zankel9a8fd552005-06-23 22:01:26 -070051
Adrian Bunkd99cf712005-09-03 15:57:53 -070052static inline void set_rasid_register (unsigned long val)
Chris Zankel9a8fd552005-06-23 22:01:26 -070053{
54 __asm__ __volatile__ (" wsr %0, "__stringify(RASID)"\n\t"
55 " isync\n" : : "a" (val));
56}
57
Adrian Bunkd99cf712005-09-03 15:57:53 -070058static inline unsigned long get_rasid_register (void)
Chris Zankel9a8fd552005-06-23 22:01:26 -070059{
60 unsigned long tmp;
Chris Zankel173d6682006-12-10 02:18:48 -080061 __asm__ __volatile__ (" rsr %0,"__stringify(RASID)"\n\t" : "=a" (tmp));
Chris Zankel9a8fd552005-06-23 22:01:26 -070062 return tmp;
63}
64
Adrian Bunkd99cf712005-09-03 15:57:53 -070065static inline void
Chris Zankel173d6682006-12-10 02:18:48 -080066__get_new_mmu_context(struct mm_struct *mm)
Chris Zankel9a8fd552005-06-23 22:01:26 -070067{
68 extern void flush_tlb_all(void);
Chris Zankel173d6682006-12-10 02:18:48 -080069 if (! (++asid_cache & ASID_MASK) ) {
Chris Zankel9a8fd552005-06-23 22:01:26 -070070 flush_tlb_all(); /* start new asid cycle */
Chris Zankel173d6682006-12-10 02:18:48 -080071 asid_cache += ASID_USER_FIRST;
Chris Zankel9a8fd552005-06-23 22:01:26 -070072 }
Chris Zankel173d6682006-12-10 02:18:48 -080073 mm->context = asid_cache;
Chris Zankel9a8fd552005-06-23 22:01:26 -070074}
75
Adrian Bunkd99cf712005-09-03 15:57:53 -070076static inline void
Chris Zankel173d6682006-12-10 02:18:48 -080077__load_mmu_context(struct mm_struct *mm)
Chris Zankel9a8fd552005-06-23 22:01:26 -070078{
Chris Zankel173d6682006-12-10 02:18:48 -080079 set_rasid_register(ASID_INSERT(mm->context));
80 invalidate_page_directory();
Chris Zankel9a8fd552005-06-23 22:01:26 -070081}
82
Chris Zankel9a8fd552005-06-23 22:01:26 -070083/*
84 * Initialize the context related info for a new mm_struct
85 * instance.
86 */
87
Adrian Bunkd99cf712005-09-03 15:57:53 -070088static inline int
Chris Zankel9a8fd552005-06-23 22:01:26 -070089init_new_context(struct task_struct *tsk, struct mm_struct *mm)
90{
91 mm->context = NO_CONTEXT;
92 return 0;
93}
94
Chris Zankel173d6682006-12-10 02:18:48 -080095/*
96 * After we have set current->mm to a new value, this activates
97 * the context for the new mm so we see the new mappings.
98 */
99static inline void
100activate_mm(struct mm_struct *prev, struct mm_struct *next)
101{
102 /* Unconditionally get a new ASID. */
103
104 __get_new_mmu_context(next);
105 __load_mmu_context(next);
106}
107
108
Adrian Bunkd99cf712005-09-03 15:57:53 -0700109static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
Chris Zankel9a8fd552005-06-23 22:01:26 -0700110 struct task_struct *tsk)
111{
112 unsigned long asid = asid_cache;
113
114 /* Check if our ASID is of an older version and thus invalid */
115
Chris Zankel173d6682006-12-10 02:18:48 -0800116 if (next->context == NO_CONTEXT || ((next->context^asid) & ~ASID_MASK))
117 __get_new_mmu_context(next);
Chris Zankel9a8fd552005-06-23 22:01:26 -0700118
Chris Zankel173d6682006-12-10 02:18:48 -0800119 __load_mmu_context(next);
Chris Zankel9a8fd552005-06-23 22:01:26 -0700120}
121
122#define deactivate_mm(tsk, mm) do { } while(0)
123
124/*
125 * Destroy context related info for an mm_struct that is about
126 * to be put to rest.
127 */
Adrian Bunkd99cf712005-09-03 15:57:53 -0700128static inline void destroy_context(struct mm_struct *mm)
Chris Zankel9a8fd552005-06-23 22:01:26 -0700129{
Chris Zankel9a8fd552005-06-23 22:01:26 -0700130 invalidate_page_directory();
131}
132
133
134static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
135{
136 /* Nothing to do. */
137
138}
139
Johannes Weinere5083a62009-03-04 16:21:31 +0100140#endif /* CONFIG_MMU */
Chris Zankel9a8fd552005-06-23 22:01:26 -0700141#endif /* _XTENSA_MMU_CONTEXT_H */