blob: 92f948392ebccede88123965b1d71bd91c1a48ca [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
Chris Zankel9a8fd552005-06-23 22:01:26 -070016#include <linux/stringify.h>
17
18#include <asm/pgtable.h>
Chris Zankel9a8fd552005-06-23 22:01:26 -070019#include <asm/cacheflush.h>
20#include <asm/tlbflush.h>
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +020021#include <asm-generic/mm_hooks.h>
Chris Zankel9a8fd552005-06-23 22:01:26 -070022
Chris Zankel173d6682006-12-10 02:18:48 -080023#define XCHAL_MMU_ASID_BITS 8
Chris Zankel9a8fd552005-06-23 22:01:26 -070024
25#if (XCHAL_HAVE_TLBS != 1)
26# error "Linux must have an MMU!"
27#endif
28
Chris Zankel9a8fd552005-06-23 22:01:26 -070029extern unsigned long asid_cache;
Chris Zankel9a8fd552005-06-23 22:01:26 -070030
31/*
32 * NO_CONTEXT is the invalid ASID value that we don't ever assign to
Chris Zankel173d6682006-12-10 02:18:48 -080033 * any user or kernel context.
34 *
35 * 0 invalid
36 * 1 kernel
37 * 2 reserved
38 * 3 reserved
39 * 4...255 available
Chris Zankel9a8fd552005-06-23 22:01:26 -070040 */
41
Chris Zankel173d6682006-12-10 02:18:48 -080042#define NO_CONTEXT 0
43#define ASID_USER_FIRST 4
44#define ASID_MASK ((1 << XCHAL_MMU_ASID_BITS) - 1)
45#define ASID_INSERT(x) (0x03020001 | (((x) & ASID_MASK) << 8))
Chris Zankel9a8fd552005-06-23 22:01:26 -070046
Adrian Bunkd99cf712005-09-03 15:57:53 -070047static inline void set_rasid_register (unsigned long val)
Chris Zankel9a8fd552005-06-23 22:01:26 -070048{
49 __asm__ __volatile__ (" wsr %0, "__stringify(RASID)"\n\t"
50 " isync\n" : : "a" (val));
51}
52
Adrian Bunkd99cf712005-09-03 15:57:53 -070053static inline unsigned long get_rasid_register (void)
Chris Zankel9a8fd552005-06-23 22:01:26 -070054{
55 unsigned long tmp;
Chris Zankel173d6682006-12-10 02:18:48 -080056 __asm__ __volatile__ (" rsr %0,"__stringify(RASID)"\n\t" : "=a" (tmp));
Chris Zankel9a8fd552005-06-23 22:01:26 -070057 return tmp;
58}
59
Adrian Bunkd99cf712005-09-03 15:57:53 -070060static inline void
Chris Zankel173d6682006-12-10 02:18:48 -080061__get_new_mmu_context(struct mm_struct *mm)
Chris Zankel9a8fd552005-06-23 22:01:26 -070062{
63 extern void flush_tlb_all(void);
Chris Zankel173d6682006-12-10 02:18:48 -080064 if (! (++asid_cache & ASID_MASK) ) {
Chris Zankel9a8fd552005-06-23 22:01:26 -070065 flush_tlb_all(); /* start new asid cycle */
Chris Zankel173d6682006-12-10 02:18:48 -080066 asid_cache += ASID_USER_FIRST;
Chris Zankel9a8fd552005-06-23 22:01:26 -070067 }
Chris Zankel173d6682006-12-10 02:18:48 -080068 mm->context = asid_cache;
Chris Zankel9a8fd552005-06-23 22:01:26 -070069}
70
Adrian Bunkd99cf712005-09-03 15:57:53 -070071static inline void
Chris Zankel173d6682006-12-10 02:18:48 -080072__load_mmu_context(struct mm_struct *mm)
Chris Zankel9a8fd552005-06-23 22:01:26 -070073{
Chris Zankel173d6682006-12-10 02:18:48 -080074 set_rasid_register(ASID_INSERT(mm->context));
75 invalidate_page_directory();
Chris Zankel9a8fd552005-06-23 22:01:26 -070076}
77
Chris Zankel9a8fd552005-06-23 22:01:26 -070078/*
79 * Initialize the context related info for a new mm_struct
80 * instance.
81 */
82
Adrian Bunkd99cf712005-09-03 15:57:53 -070083static inline int
Chris Zankel9a8fd552005-06-23 22:01:26 -070084init_new_context(struct task_struct *tsk, struct mm_struct *mm)
85{
86 mm->context = NO_CONTEXT;
87 return 0;
88}
89
Chris Zankel173d6682006-12-10 02:18:48 -080090/*
91 * After we have set current->mm to a new value, this activates
92 * the context for the new mm so we see the new mappings.
93 */
94static inline void
95activate_mm(struct mm_struct *prev, struct mm_struct *next)
96{
97 /* Unconditionally get a new ASID. */
98
99 __get_new_mmu_context(next);
100 __load_mmu_context(next);
101}
102
103
Adrian Bunkd99cf712005-09-03 15:57:53 -0700104static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
Chris Zankel9a8fd552005-06-23 22:01:26 -0700105 struct task_struct *tsk)
106{
107 unsigned long asid = asid_cache;
108
109 /* Check if our ASID is of an older version and thus invalid */
110
Chris Zankel173d6682006-12-10 02:18:48 -0800111 if (next->context == NO_CONTEXT || ((next->context^asid) & ~ASID_MASK))
112 __get_new_mmu_context(next);
Chris Zankel9a8fd552005-06-23 22:01:26 -0700113
Chris Zankel173d6682006-12-10 02:18:48 -0800114 __load_mmu_context(next);
Chris Zankel9a8fd552005-06-23 22:01:26 -0700115}
116
117#define deactivate_mm(tsk, mm) do { } while(0)
118
119/*
120 * Destroy context related info for an mm_struct that is about
121 * to be put to rest.
122 */
Adrian Bunkd99cf712005-09-03 15:57:53 -0700123static inline void destroy_context(struct mm_struct *mm)
Chris Zankel9a8fd552005-06-23 22:01:26 -0700124{
Chris Zankel9a8fd552005-06-23 22:01:26 -0700125 invalidate_page_directory();
126}
127
128
129static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
130{
131 /* Nothing to do. */
132
133}
134
135#endif /* _XTENSA_MMU_CONTEXT_H */