Linux 2.6.26-rc5
[linux-2.6/openmoko-kernel/knife-kernel.git] / arch / ppc / mm / mmu_context.c
blobdacf45ced473f05a0a03975bbb4b4fcb307ddbb6
1 /*
2 * This file contains the routines for handling the MMU on those
3 * PowerPC implementations where the MMU substantially follows the
4 * architecture specification. This includes the 6xx, 7xx, 7xxx,
5 * and 8260 implementations but excludes the 8xx and 4xx.
6 * -- paulus
8 * Derived from arch/ppc/mm/init.c:
9 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
11 * Modifications by Paul Mackerras (PowerMac) (paulus@cs.anu.edu.au)
12 * and Cort Dougan (PReP) (cort@cs.nmt.edu)
13 * Copyright (C) 1996 Paul Mackerras
14 * Amiga/APUS changes by Jesper Skov (jskov@cygnus.co.uk).
16 * Derived from "arch/i386/mm/init.c"
17 * Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds
19 * This program is free software; you can redistribute it and/or
20 * modify it under the terms of the GNU General Public License
21 * as published by the Free Software Foundation; either version
22 * 2 of the License, or (at your option) any later version.
26 #include <linux/mm.h>
27 #include <linux/init.h>
29 #include <asm/mmu_context.h>
30 #include <asm/tlbflush.h>
32 unsigned long next_mmu_context;
33 unsigned long context_map[LAST_CONTEXT / BITS_PER_LONG + 1];
34 #ifdef FEW_CONTEXTS
35 atomic_t nr_free_contexts;
36 struct mm_struct *context_mm[LAST_CONTEXT+1];
37 void steal_context(void);
38 #endif /* FEW_CONTEXTS */
41 * Initialize the context management stuff.
43 void __init
44 mmu_context_init(void)
47 * Some processors have too few contexts to reserve one for
48 * init_mm, and require using context 0 for a normal task.
49 * Other processors reserve the use of context zero for the kernel.
50 * This code assumes FIRST_CONTEXT < 32.
52 context_map[0] = (1 << FIRST_CONTEXT) - 1;
53 next_mmu_context = FIRST_CONTEXT;
54 #ifdef FEW_CONTEXTS
55 atomic_set(&nr_free_contexts, LAST_CONTEXT - FIRST_CONTEXT + 1);
56 #endif /* FEW_CONTEXTS */
59 #ifdef FEW_CONTEXTS
61 * Steal a context from a task that has one at the moment.
62 * This is only used on 8xx and 4xx and we presently assume that
63 * they don't do SMP. If they do then this will have to check
64 * whether the MM we steal is in use.
65 * We also assume that this is only used on systems that don't
66 * use an MMU hash table - this is true for 8xx and 4xx.
67 * This isn't an LRU system, it just frees up each context in
68 * turn (sort-of pseudo-random replacement :). This would be the
69 * place to implement an LRU scheme if anyone was motivated to do it.
70 * -- paulus
72 void
73 steal_context(void)
75 struct mm_struct *mm;
77 /* free up context `next_mmu_context' */
78 /* if we shouldn't free context 0, don't... */
79 if (next_mmu_context < FIRST_CONTEXT)
80 next_mmu_context = FIRST_CONTEXT;
81 mm = context_mm[next_mmu_context];
82 flush_tlb_mm(mm);
83 destroy_context(mm);
85 #endif /* FEW_CONTEXTS */