Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[cris-mirror.git] / arch / cris / mm / tlb.c
blobe0dbea62cb81d9761abd86d9bc9be06eb9302a11
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * linux/arch/cris/mm/tlb.c
5 * Copyright (C) 2000, 2001 Axis Communications AB
6 *
7 * Authors: Bjorn Wesen (bjornw@axis.com)
9 */
11 #include <linux/init.h>
12 #include <linux/kernel.h>
13 #include <linux/mm_types.h>
15 #include <asm/tlb.h>
17 #define D(x)
19 /* The TLB can host up to 64 different mm contexts at the same time.
20 * The running context is R_MMU_CONTEXT, and each TLB entry contains a
21 * page_id that has to match to give a hit. In page_id_map, we keep track
22 * of which mm we have assigned to which page_id, so that we know when
23 * to invalidate TLB entries.
25 * The last page_id is never running - it is used as an invalid page_id
26 * so we can make TLB entries that will never match.
28 * Notice that we need to make the flushes atomic, otherwise an interrupt
29 * handler that uses vmalloced memory might cause a TLB load in the middle
30 * of a flush causing.
33 struct mm_struct *page_id_map[NUM_PAGEID];
34 static int map_replace_ptr = 1; /* which page_id_map entry to replace next */
36 /* the following functions are similar to those used in the PPC port */
38 static inline void
39 alloc_context(struct mm_struct *mm)
41 struct mm_struct *old_mm;
43 D(printk("tlb: alloc context %d (%p)\n", map_replace_ptr, mm));
45 /* did we replace an mm ? */
47 old_mm = page_id_map[map_replace_ptr];
49 if(old_mm) {
50 /* throw out any TLB entries belonging to the mm we replace
51 * in the map
53 flush_tlb_mm(old_mm);
55 old_mm->context.page_id = NO_CONTEXT;
58 /* insert it into the page_id_map */
60 mm->context.page_id = map_replace_ptr;
61 page_id_map[map_replace_ptr] = mm;
63 map_replace_ptr++;
65 if(map_replace_ptr == INVALID_PAGEID)
66 map_replace_ptr = 0; /* wrap around */
69 /*
70 * if needed, get a new MMU context for the mm. otherwise nothing is done.
73 void
74 get_mmu_context(struct mm_struct *mm)
76 if(mm->context.page_id == NO_CONTEXT)
77 alloc_context(mm);
80 /* called by __exit_mm to destroy the used MMU context if any before
81 * destroying the mm itself. this is only called when the last user of the mm
82 * drops it.
84 * the only thing we really need to do here is mark the used PID slot
85 * as empty.
88 void
89 destroy_context(struct mm_struct *mm)
91 if(mm->context.page_id != NO_CONTEXT) {
92 D(printk("destroy_context %d (%p)\n", mm->context.page_id, mm));
93 flush_tlb_mm(mm); /* TODO this might be redundant ? */
94 page_id_map[mm->context.page_id] = NULL;
98 /* called once during VM initialization, from init.c */
100 void __init
101 tlb_init(void)
103 int i;
105 /* clear the page_id map */
107 for (i = 1; i < ARRAY_SIZE(page_id_map); i++)
108 page_id_map[i] = NULL;
110 /* invalidate the entire TLB */
112 flush_tlb_all();
114 /* the init_mm has context 0 from the boot */
116 page_id_map[0] = &init_mm;