Loading...
Note: File does not exist in v6.2.
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#include <linux/export.h>
22#include <linux/gfp.h>
23#include <linux/slab.h>
24
25#include <asm/mmu_context.h>
26
27#include "icswx.h"
28
29static DEFINE_SPINLOCK(mmu_context_lock);
30static DEFINE_IDA(mmu_context_ida);
31
32/*
33 * The proto-VSID space has 2^35 - 1 segments available for user mappings.
34 * Each segment contains 2^28 bytes. Each context maps 2^44 bytes,
35 * so we can support 2^19-1 contexts (19 == 35 + 28 - 44).
36 */
37#define MAX_CONTEXT ((1UL << 19) - 1)
38
39int __init_new_context(void)
40{
41 int index;
42 int err;
43
44again:
45 if (!ida_pre_get(&mmu_context_ida, GFP_KERNEL))
46 return -ENOMEM;
47
48 spin_lock(&mmu_context_lock);
49 err = ida_get_new_above(&mmu_context_ida, 1, &index);
50 spin_unlock(&mmu_context_lock);
51
52 if (err == -EAGAIN)
53 goto again;
54 else if (err)
55 return err;
56
57 if (index > MAX_CONTEXT) {
58 spin_lock(&mmu_context_lock);
59 ida_remove(&mmu_context_ida, index);
60 spin_unlock(&mmu_context_lock);
61 return -ENOMEM;
62 }
63
64 return index;
65}
66EXPORT_SYMBOL_GPL(__init_new_context);
67
68int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
69{
70 int index;
71
72 index = __init_new_context();
73 if (index < 0)
74 return index;
75
76 /* The old code would re-promote on fork, we don't do that
77 * when using slices as it could cause problem promoting slices
78 * that have been forced down to 4K
79 */
80 if (slice_mm_new_context(mm))
81 slice_set_user_psize(mm, mmu_virtual_psize);
82 subpage_prot_init_new_context(mm);
83 mm->context.id = index;
84#ifdef CONFIG_PPC_ICSWX
85 mm->context.cop_lockp = kmalloc(sizeof(spinlock_t), GFP_KERNEL);
86 if (!mm->context.cop_lockp) {
87 __destroy_context(index);
88 subpage_prot_free(mm);
89 mm->context.id = MMU_NO_CONTEXT;
90 return -ENOMEM;
91 }
92 spin_lock_init(mm->context.cop_lockp);
93#endif /* CONFIG_PPC_ICSWX */
94
95 return 0;
96}
97
98void __destroy_context(int context_id)
99{
100 spin_lock(&mmu_context_lock);
101 ida_remove(&mmu_context_ida, context_id);
102 spin_unlock(&mmu_context_lock);
103}
104EXPORT_SYMBOL_GPL(__destroy_context);
105
106void destroy_context(struct mm_struct *mm)
107{
108#ifdef CONFIG_PPC_ICSWX
109 drop_cop(mm->context.acop, mm);
110 kfree(mm->context.cop_lockp);
111 mm->context.cop_lockp = NULL;
112#endif /* CONFIG_PPC_ICSWX */
113 __destroy_context(mm->context.id);
114 subpage_prot_free(mm);
115 mm->context.id = MMU_NO_CONTEXT;
116}