Commit | Line | Data |
---|---|---|
5e696617 BH |
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, | |
0f369103 | 5 | * and 8260 implementations but excludes the 8xx and 4xx. |
5e696617 BH |
6 | * -- paulus |
7 | * | |
8 | * Derived from arch/ppc/mm/init.c: | |
9 | * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org) | |
10 | * | |
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 | * | |
15 | * Derived from "arch/i386/mm/init.c" | |
16 | * Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds | |
17 | * | |
18 | * This program is free software; you can redistribute it and/or | |
19 | * modify it under the terms of the GNU General Public License | |
20 | * as published by the Free Software Foundation; either version | |
21 | * 2 of the License, or (at your option) any later version. | |
22 | * | |
23 | */ | |
24 | ||
25 | #include <linux/mm.h> | |
26 | #include <linux/init.h> | |
93087948 | 27 | #include <linux/export.h> |
5e696617 BH |
28 | |
29 | #include <asm/mmu_context.h> | |
5e696617 BH |
30 | |
31 | /* | |
32 | * On 32-bit PowerPC 6xx/7xx/7xxx CPUs, we use a set of 16 VSIDs | |
33 | * (virtual segment identifiers) for each context. Although the | |
34 | * hardware supports 24-bit VSIDs, and thus >1 million contexts, | |
35 | * we only use 32,768 of them. That is ample, since there can be | |
36 | * at most around 30,000 tasks in the system anyway, and it means | |
37 | * that we can use a bitmap to indicate which contexts are in use. | |
38 | * Using a bitmap means that we entirely avoid all of the problems | |
39 | * that we used to have when the context number overflowed, | |
40 | * particularly on SMP systems. | |
41 | * -- paulus. | |
42 | */ | |
43 | #define NO_CONTEXT ((unsigned long) -1) | |
44 | #define LAST_CONTEXT 32767 | |
45 | #define FIRST_CONTEXT 1 | |
46 | ||
47 | /* | |
48 | * This function defines the mapping from contexts to VSIDs (virtual | |
49 | * segment IDs). We use a skew on both the context and the high 4 bits | |
50 | * of the 32-bit virtual address (the "effective segment ID") in order | |
51 | * to spread out the entries in the MMU hash table. Note, if this | |
52 | * function is changed then arch/ppc/mm/hashtable.S will have to be | |
53 | * changed to correspond. | |
54 | * | |
55 | * | |
56 | * CTX_TO_VSID(ctx, va) (((ctx) * (897 * 16) + ((va) >> 28) * 0x111) \ | |
57 | * & 0xffffff) | |
58 | */ | |
59 | ||
60 | static unsigned long next_mmu_context; | |
61 | static unsigned long context_map[LAST_CONTEXT / BITS_PER_LONG + 1]; | |
62 | ||
c83ec269 | 63 | unsigned long __init_new_context(void) |
5e696617 BH |
64 | { |
65 | unsigned long ctx = next_mmu_context; | |
66 | ||
67 | while (test_and_set_bit(ctx, context_map)) { | |
68 | ctx = find_next_zero_bit(context_map, LAST_CONTEXT+1, ctx); | |
69 | if (ctx > LAST_CONTEXT) | |
70 | ctx = 0; | |
71 | } | |
72 | next_mmu_context = (ctx + 1) & LAST_CONTEXT; | |
c83ec269 AG |
73 | |
74 | return ctx; | |
75 | } | |
76 | EXPORT_SYMBOL_GPL(__init_new_context); | |
77 | ||
78 | /* | |
79 | * Set up the context for a new address space. | |
80 | */ | |
81 | int init_new_context(struct task_struct *t, struct mm_struct *mm) | |
82 | { | |
83 | mm->context.id = __init_new_context(); | |
5e696617 BH |
84 | |
85 | return 0; | |
86 | } | |
87 | ||
c83ec269 AG |
88 | /* |
89 | * Free a context ID. Make sure to call this with preempt disabled! | |
90 | */ | |
91 | void __destroy_context(unsigned long ctx) | |
92 | { | |
93 | clear_bit(ctx, context_map); | |
94 | } | |
95 | EXPORT_SYMBOL_GPL(__destroy_context); | |
96 | ||
5e696617 BH |
97 | /* |
98 | * We're finished using the context for an address space. | |
99 | */ | |
100 | void destroy_context(struct mm_struct *mm) | |
101 | { | |
102 | preempt_disable(); | |
103 | if (mm->context.id != NO_CONTEXT) { | |
c83ec269 | 104 | __destroy_context(mm->context.id); |
5e696617 BH |
105 | mm->context.id = NO_CONTEXT; |
106 | } | |
107 | preempt_enable(); | |
108 | } | |
109 | ||
110 | /* | |
111 | * Initialize the context management stuff. | |
112 | */ | |
113 | void __init mmu_context_init(void) | |
114 | { | |
115 | /* Reserve context 0 for kernel use */ | |
116 | context_map[0] = (1 << FIRST_CONTEXT) - 1; | |
117 | next_mmu_context = FIRST_CONTEXT; | |
118 | } |