Path: blob/master/arch/powerpc/mm/mmu_context_hash32.c
10817 views
/*1* This file contains the routines for handling the MMU on those2* PowerPC implementations where the MMU substantially follows the3* architecture specification. This includes the 6xx, 7xx, 7xxx,4* 8260, and POWER3 implementations but excludes the 8xx and 4xx.5* -- paulus6*7* Derived from arch/ppc/mm/init.c:8* Copyright (C) 1995-1996 Gary Thomas ([email protected])9*10* Modifications by Paul Mackerras (PowerMac) ([email protected])11* and Cort Dougan (PReP) ([email protected])12* Copyright (C) 1996 Paul Mackerras13*14* Derived from "arch/i386/mm/init.c"15* Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds16*17* This program is free software; you can redistribute it and/or18* modify it under the terms of the GNU General Public License19* as published by the Free Software Foundation; either version20* 2 of the License, or (at your option) any later version.21*22*/2324#include <linux/mm.h>25#include <linux/init.h>2627#include <asm/mmu_context.h>28#include <asm/tlbflush.h>2930/*31* On 32-bit PowerPC 6xx/7xx/7xxx CPUs, we use a set of 16 VSIDs32* (virtual segment identifiers) for each context. Although the33* hardware supports 24-bit VSIDs, and thus >1 million contexts,34* we only use 32,768 of them. That is ample, since there can be35* at most around 30,000 tasks in the system anyway, and it means36* that we can use a bitmap to indicate which contexts are in use.37* Using a bitmap means that we entirely avoid all of the problems38* that we used to have when the context number overflowed,39* particularly on SMP systems.40* -- paulus.41*/42#define NO_CONTEXT ((unsigned long) -1)43#define LAST_CONTEXT 3276744#define FIRST_CONTEXT 14546/*47* This function defines the mapping from contexts to VSIDs (virtual48* segment IDs). We use a skew on both the context and the high 4 bits49* of the 32-bit virtual address (the "effective segment ID") in order50* to spread out the entries in the MMU hash table. Note, if this51* function is changed then arch/ppc/mm/hashtable.S will have to be52* changed to correspond.53*54*55* CTX_TO_VSID(ctx, va) (((ctx) * (897 * 16) + ((va) >> 28) * 0x111) \56* & 0xffffff)57*/5859static unsigned long next_mmu_context;60static unsigned long context_map[LAST_CONTEXT / BITS_PER_LONG + 1];6162unsigned long __init_new_context(void)63{64unsigned long ctx = next_mmu_context;6566while (test_and_set_bit(ctx, context_map)) {67ctx = find_next_zero_bit(context_map, LAST_CONTEXT+1, ctx);68if (ctx > LAST_CONTEXT)69ctx = 0;70}71next_mmu_context = (ctx + 1) & LAST_CONTEXT;7273return ctx;74}75EXPORT_SYMBOL_GPL(__init_new_context);7677/*78* Set up the context for a new address space.79*/80int init_new_context(struct task_struct *t, struct mm_struct *mm)81{82mm->context.id = __init_new_context();8384return 0;85}8687/*88* Free a context ID. Make sure to call this with preempt disabled!89*/90void __destroy_context(unsigned long ctx)91{92clear_bit(ctx, context_map);93}94EXPORT_SYMBOL_GPL(__destroy_context);9596/*97* We're finished using the context for an address space.98*/99void destroy_context(struct mm_struct *mm)100{101preempt_disable();102if (mm->context.id != NO_CONTEXT) {103__destroy_context(mm->context.id);104mm->context.id = NO_CONTEXT;105}106preempt_enable();107}108109/*110* Initialize the context management stuff.111*/112void __init mmu_context_init(void)113{114/* Reserve context 0 for kernel use */115context_map[0] = (1 << FIRST_CONTEXT) - 1;116next_mmu_context = FIRST_CONTEXT;117}118119120