2 * MMU context allocation for 64-bit kernels.
4 * Copyright (C) 2004 Anton Blanchard, IBM Corp. <anton@samba.org>
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.
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>
19 #include <linux/spinlock.h>
20 #include <linux/idr.h>
22 #include <asm/mmu_context.h>
24 static DEFINE_SPINLOCK(mmu_context_lock
);
25 static DEFINE_IDR(mmu_context_idr
);
27 int init_new_context(struct task_struct
*tsk
, struct mm_struct
*mm
)
33 if (!idr_pre_get(&mmu_context_idr
, GFP_KERNEL
))
36 spin_lock(&mmu_context_lock
);
37 err
= idr_get_new_above(&mmu_context_idr
, NULL
, 1, &index
);
38 spin_unlock(&mmu_context_lock
);
45 if (index
> MAX_CONTEXT
) {
46 spin_lock(&mmu_context_lock
);
47 idr_remove(&mmu_context_idr
, index
);
48 spin_unlock(&mmu_context_lock
);
52 mm
->context
.id
= index
;
53 mm
->context
.user_psize
= mmu_virtual_psize
;
54 mm
->context
.sllp
= SLB_VSID_USER
|
55 mmu_psize_defs
[mmu_virtual_psize
].sllp
;
60 void destroy_context(struct mm_struct
*mm
)
62 spin_lock(&mmu_context_lock
);
63 idr_remove(&mmu_context_idr
, mm
->context
.id
);
64 spin_unlock(&mmu_context_lock
);
66 mm
->context
.id
= NO_CONTEXT
;