2 * SPU file system -- system call stubs
4 * (C) Copyright IBM Deutschland Entwicklung GmbH 2005
5 * (C) Copyright 2006-2007, IBM Corporation
7 * Author: Arnd Bergmann <arndb@de.ibm.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2, or (at your option)
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include <linux/file.h>
25 #include <linux/module.h>
26 #include <linux/syscalls.h>
27 #include <linux/rcupdate.h>
31 /* protected by rcu */
32 static struct spufs_calls
*spufs_calls
;
34 #ifdef CONFIG_SPU_FS_MODULE
36 static inline struct spufs_calls
*spufs_calls_get(void)
38 struct spufs_calls
*calls
= NULL
;
41 calls
= rcu_dereference(spufs_calls
);
42 if (calls
&& !try_module_get(calls
->owner
))
49 static inline void spufs_calls_put(struct spufs_calls
*calls
)
51 BUG_ON(calls
!= spufs_calls
);
53 /* we don't need to rcu this, as we hold a reference to the module */
54 module_put(spufs_calls
->owner
);
57 #else /* !defined CONFIG_SPU_FS_MODULE */
59 static inline struct spufs_calls
*spufs_calls_get(void)
64 static inline void spufs_calls_put(struct spufs_calls
*calls
) { }
66 #endif /* CONFIG_SPU_FS_MODULE */
68 SYSCALL_DEFINE4(spu_create
, const char __user
*, name
, unsigned int, flags
,
69 umode_t
, mode
, int, neighbor_fd
)
72 struct file
*neighbor
;
74 struct spufs_calls
*calls
;
76 calls
= spufs_calls_get();
80 if (flags
& SPU_CREATE_AFFINITY_SPU
) {
82 neighbor
= fget_light(neighbor_fd
, &fput_needed
);
84 ret
= calls
->create_thread(name
, flags
, mode
, neighbor
);
85 fput_light(neighbor
, fput_needed
);
88 ret
= calls
->create_thread(name
, flags
, mode
, NULL
);
90 spufs_calls_put(calls
);
94 asmlinkage
long sys_spu_run(int fd
, __u32 __user
*unpc
, __u32 __user
*ustatus
)
99 struct spufs_calls
*calls
;
101 calls
= spufs_calls_get();
106 filp
= fget_light(fd
, &fput_needed
);
108 ret
= calls
->spu_run(filp
, unpc
, ustatus
);
109 fput_light(filp
, fput_needed
);
112 spufs_calls_put(calls
);
116 int elf_coredump_extra_notes_size(void)
118 struct spufs_calls
*calls
;
121 calls
= spufs_calls_get();
125 ret
= calls
->coredump_extra_notes_size();
127 spufs_calls_put(calls
);
132 int elf_coredump_extra_notes_write(struct file
*file
, loff_t
*foffset
)
134 struct spufs_calls
*calls
;
137 calls
= spufs_calls_get();
141 ret
= calls
->coredump_extra_notes_write(file
, foffset
);
143 spufs_calls_put(calls
);
148 void notify_spus_active(void)
150 struct spufs_calls
*calls
;
152 calls
= spufs_calls_get();
156 calls
->notify_spus_active();
157 spufs_calls_put(calls
);
162 int register_spu_syscalls(struct spufs_calls
*calls
)
167 rcu_assign_pointer(spufs_calls
, calls
);
170 EXPORT_SYMBOL_GPL(register_spu_syscalls
);
172 void unregister_spu_syscalls(struct spufs_calls
*calls
)
174 BUG_ON(spufs_calls
->owner
!= calls
->owner
);
175 rcu_assign_pointer(spufs_calls
, NULL
);
178 EXPORT_SYMBOL_GPL(unregister_spu_syscalls
);