/*1* linux/arch/cris/mm/tlb.c2*3* Copyright (C) 2000, 2001 Axis Communications AB4*5* Authors: Bjorn Wesen ([email protected])6*7*/89#include <linux/init.h>10#include <linux/kernel.h>11#include <asm/tlb.h>1213#define D(x)1415/* The TLB can host up to 64 different mm contexts at the same time.16* The running context is R_MMU_CONTEXT, and each TLB entry contains a17* page_id that has to match to give a hit. In page_id_map, we keep track18* of which mm we have assigned to which page_id, so that we know when19* to invalidate TLB entries.20*21* The last page_id is never running - it is used as an invalid page_id22* so we can make TLB entries that will never match.23*24* Notice that we need to make the flushes atomic, otherwise an interrupt25* handler that uses vmalloced memory might cause a TLB load in the middle26* of a flush causing.27*/2829struct mm_struct *page_id_map[NUM_PAGEID];30static int map_replace_ptr = 1; /* which page_id_map entry to replace next */3132/* the following functions are similar to those used in the PPC port */3334static inline void35alloc_context(struct mm_struct *mm)36{37struct mm_struct *old_mm;3839D(printk("tlb: alloc context %d (%p)\n", map_replace_ptr, mm));4041/* did we replace an mm ? */4243old_mm = page_id_map[map_replace_ptr];4445if(old_mm) {46/* throw out any TLB entries belonging to the mm we replace47* in the map48*/49flush_tlb_mm(old_mm);5051old_mm->context.page_id = NO_CONTEXT;52}5354/* insert it into the page_id_map */5556mm->context.page_id = map_replace_ptr;57page_id_map[map_replace_ptr] = mm;5859map_replace_ptr++;6061if(map_replace_ptr == INVALID_PAGEID)62map_replace_ptr = 0; /* wrap around */63}6465/*66* if needed, get a new MMU context for the mm. otherwise nothing is done.67*/6869void70get_mmu_context(struct mm_struct *mm)71{72if(mm->context.page_id == NO_CONTEXT)73alloc_context(mm);74}7576/* called by __exit_mm to destroy the used MMU context if any before77* destroying the mm itself. this is only called when the last user of the mm78* drops it.79*80* the only thing we really need to do here is mark the used PID slot81* as empty.82*/8384void85destroy_context(struct mm_struct *mm)86{87if(mm->context.page_id != NO_CONTEXT) {88D(printk("destroy_context %d (%p)\n", mm->context.page_id, mm));89flush_tlb_mm(mm); /* TODO this might be redundant ? */90page_id_map[mm->context.page_id] = NULL;91}92}9394/* called once during VM initialization, from init.c */9596void __init97tlb_init(void)98{99int i;100101/* clear the page_id map */102103for (i = 1; i < ARRAY_SIZE(page_id_map); i++)104page_id_map[i] = NULL;105106/* invalidate the entire TLB */107108flush_tlb_all();109110/* the init_mm has context 0 from the boot */111112page_id_map[0] = &init_mm;113}114115116