2 * ICSWX and ACOP/PID Management
4 * Copyright (C) 2011 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/types.h>
18 #include <linux/spinlock.h>
19 #include <linux/idr.h>
20 #include <linux/module.h>
23 #define COP_PID_MIN (COP_PID_NONE + 1)
24 #define COP_PID_MAX (0xFFFF)
26 static DEFINE_SPINLOCK(mmu_context_acop_lock);
27 static DEFINE_IDA(cop_ida);
29 static int new_cop_pid(struct ida *ida, int min_id, int max_id,
36 if (!ida_pre_get(ida, GFP_KERNEL))
40 err = ida_get_new_above(ida, min_id, &index);
50 ida_remove(ida, index);
58 int get_cop_pid(struct mm_struct *mm)
62 if (mm->context.cop_pid == COP_PID_NONE) {
63 pid = new_cop_pid(&cop_ida, COP_PID_MIN, COP_PID_MAX,
64 &mmu_context_acop_lock);
66 mm->context.cop_pid = pid;
68 return mm->context.cop_pid;
71 int disable_cop_pid(struct mm_struct *mm)
73 int free_pid = COP_PID_NONE;
75 if ((!mm->context.acop) && (mm->context.cop_pid != COP_PID_NONE)) {
76 free_pid = mm->context.cop_pid;
77 mm->context.cop_pid = COP_PID_NONE;
82 void free_cop_pid(int free_pid)
84 spin_lock(&mmu_context_acop_lock);
85 ida_remove(&cop_ida, free_pid);
86 spin_unlock(&mmu_context_acop_lock);