// SPDX-License-Identifier: GPL-2.0-or-later1/*2* This file contains the routines for handling the MMU.3*4* Copyright (C) 2007 Xilinx, Inc. All rights reserved.5*6* Derived from arch/ppc/mm/4xx_mmu.c:7* -- paulus8*9* Derived from arch/ppc/mm/init.c:10* Copyright (C) 1995-1996 Gary Thomas ([email protected])11*12* Modifications by Paul Mackerras (PowerMac) ([email protected])13* and Cort Dougan (PReP) ([email protected])14* Copyright (C) 1996 Paul Mackerras15* Amiga/APUS changes by Jesper Skov ([email protected]).16*17* Derived from "arch/i386/mm/init.c"18* Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds19*/2021#include <linux/mm.h>22#include <linux/init.h>2324#include <asm/tlbflush.h>25#include <asm/mmu_context.h>2627mm_context_t next_mmu_context;28unsigned long context_map[LAST_CONTEXT / BITS_PER_LONG + 1];29atomic_t nr_free_contexts;30struct mm_struct *context_mm[LAST_CONTEXT+1];3132/*33* Initialize the context management stuff.34*/35void __init mmu_context_init(void)36{37/*38* The use of context zero is reserved for the kernel.39* This code assumes FIRST_CONTEXT < 32.40*/41context_map[0] = (1 << FIRST_CONTEXT) - 1;42next_mmu_context = FIRST_CONTEXT;43atomic_set(&nr_free_contexts, LAST_CONTEXT - FIRST_CONTEXT + 1);44}4546/*47* Steal a context from a task that has one at the moment.48*49* This isn't an LRU system, it just frees up each context in50* turn (sort-of pseudo-random replacement :). This would be the51* place to implement an LRU scheme if anyone were motivated to do it.52*/53void steal_context(void)54{55struct mm_struct *mm;5657/* free up context `next_mmu_context' */58/* if we shouldn't free context 0, don't... */59if (next_mmu_context < FIRST_CONTEXT)60next_mmu_context = FIRST_CONTEXT;61mm = context_mm[next_mmu_context];62flush_tlb_mm(mm);63destroy_context(mm);64}656667