Merge master.kernel.org:/pub/scm/linux/kernel/git/steve/gfs2-2.6-nmw
[linux-2.6] / arch / powerpc / platforms / cell / spu_coredump.c
1 /*
2  * SPU core dump code
3  *
4  * (C) Copyright 2006 IBM Corp.
5  *
6  * Author: Dwayne Grant McConnell <decimal@us.ibm.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2, or (at your option)
11  * any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */
22
23 #include <linux/file.h>
24 #include <linux/module.h>
25 #include <linux/syscalls.h>
26
27 #include <asm/spu.h>
28
29 static struct spu_coredump_calls spu_coredump_calls;
30 static DEFINE_MUTEX(spu_coredump_mutex);
31
32 int arch_notes_size(void)
33 {
34         long ret;
35         struct module *owner = spu_coredump_calls.owner;
36
37         ret = -ENOSYS;
38         mutex_lock(&spu_coredump_mutex);
39         if (owner && try_module_get(owner)) {
40                 ret = spu_coredump_calls.arch_notes_size();
41                 module_put(owner);
42         }
43         mutex_unlock(&spu_coredump_mutex);
44         return ret;
45 }
46
47 void arch_write_notes(struct file *file)
48 {
49         struct module *owner = spu_coredump_calls.owner;
50
51         mutex_lock(&spu_coredump_mutex);
52         if (owner && try_module_get(owner)) {
53                 spu_coredump_calls.arch_write_notes(file);
54                 module_put(owner);
55         }
56         mutex_unlock(&spu_coredump_mutex);
57 }
58
59 int register_arch_coredump_calls(struct spu_coredump_calls *calls)
60 {
61         if (spu_coredump_calls.owner)
62                 return -EBUSY;
63
64         mutex_lock(&spu_coredump_mutex);
65         spu_coredump_calls.arch_notes_size = calls->arch_notes_size;
66         spu_coredump_calls.arch_write_notes = calls->arch_write_notes;
67         spu_coredump_calls.owner = calls->owner;
68         mutex_unlock(&spu_coredump_mutex);
69         return 0;
70 }
71 EXPORT_SYMBOL_GPL(register_arch_coredump_calls);
72
73 void unregister_arch_coredump_calls(struct spu_coredump_calls *calls)
74 {
75         BUG_ON(spu_coredump_calls.owner != calls->owner);
76
77         mutex_lock(&spu_coredump_mutex);
78         spu_coredump_calls.owner = NULL;
79         mutex_unlock(&spu_coredump_mutex);
80 }
81 EXPORT_SYMBOL_GPL(unregister_arch_coredump_calls);