aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc/mm/mmu_context_hash64.c
diff options
context:
space:
mode:
authorBenjamin Herrenschmidt <benh@kernel.crashing.org>2008-12-18 14:13:24 -0500
committerPaul Mackerras <paulus@samba.org>2008-12-20 22:21:15 -0500
commit5e696617c425eb97bd943d781f3941fb1e8f0e5b (patch)
tree82138fbda2e28fbe8d0e5821f218cb160230ce27 /arch/powerpc/mm/mmu_context_hash64.c
parent6d2170be4561293a6aa821c773687bd3f18e8206 (diff)
powerpc/mm: Split mmu_context handling
This splits the mmu_context handling between 32-bit hash based processors, 64-bit hash based processors and everybody else. This is preliminary work for adding SMP support for BookE processors. Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org> Acked-by: Kumar Gala <galak@kernel.crashing.org> Signed-off-by: Paul Mackerras <paulus@samba.org>
Diffstat (limited to 'arch/powerpc/mm/mmu_context_hash64.c')
-rw-r--r--arch/powerpc/mm/mmu_context_hash64.c78
1 files changed, 78 insertions, 0 deletions
diff --git a/arch/powerpc/mm/mmu_context_hash64.c b/arch/powerpc/mm/mmu_context_hash64.c
new file mode 100644
index 000000000000..dbeb86ac90cd
--- /dev/null
+++ b/arch/powerpc/mm/mmu_context_hash64.c
@@ -0,0 +1,78 @@
1/*
2 * MMU context allocation for 64-bit kernels.
3 *
4 * Copyright (C) 2004 Anton Blanchard, IBM Corp. <anton@samba.org>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 *
11 */
12
13#include <linux/sched.h>
14#include <linux/kernel.h>
15#include <linux/errno.h>
16#include <linux/string.h>
17#include <linux/types.h>
18#include <linux/mm.h>
19#include <linux/spinlock.h>
20#include <linux/idr.h>
21
22#include <asm/mmu_context.h>
23
24static DEFINE_SPINLOCK(mmu_context_lock);
25static DEFINE_IDR(mmu_context_idr);
26
27/*
28 * The proto-VSID space has 2^35 - 1 segments available for user mappings.
29 * Each segment contains 2^28 bytes. Each context maps 2^44 bytes,
30 * so we can support 2^19-1 contexts (19 == 35 + 28 - 44).
31 */
32#define NO_CONTEXT 0
33#define MAX_CONTEXT ((1UL << 19) - 1)
34
35int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
36{
37 int index;
38 int err;
39
40again:
41 if (!idr_pre_get(&mmu_context_idr, GFP_KERNEL))
42 return -ENOMEM;
43
44 spin_lock(&mmu_context_lock);
45 err = idr_get_new_above(&mmu_context_idr, NULL, 1, &index);
46 spin_unlock(&mmu_context_lock);
47
48 if (err == -EAGAIN)
49 goto again;
50 else if (err)
51 return err;
52
53 if (index > MAX_CONTEXT) {
54 spin_lock(&mmu_context_lock);
55 idr_remove(&mmu_context_idr, index);
56 spin_unlock(&mmu_context_lock);
57 return -ENOMEM;
58 }
59
60 /* The old code would re-promote on fork, we don't do that
61 * when using slices as it could cause problem promoting slices
62 * that have been forced down to 4K
63 */
64 if (slice_mm_new_context(mm))
65 slice_set_user_psize(mm, mmu_virtual_psize);
66 mm->context.id = index;
67
68 return 0;
69}
70
71void destroy_context(struct mm_struct *mm)
72{
73 spin_lock(&mmu_context_lock);
74 idr_remove(&mmu_context_idr, mm->context.id);
75 spin_unlock(&mmu_context_lock);
76
77 mm->context.id = NO_CONTEXT;
78}