1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * SPU file system -- system call stubs
5 * (C) Copyright IBM Deutschland Entwicklung GmbH 2005
6 * (C) Copyright 2006-2007, IBM Corporation
8 * Author: Arnd Bergmann <arndb@de.ibm.com>
10 #include <linux/file.h>
12 #include <linux/module.h>
13 #include <linux/syscalls.h>
14 #include <linux/rcupdate.h>
15 #include <linux/binfmts.h>
19 /* protected by rcu */
20 static struct spufs_calls *spufs_calls;
22 #ifdef CONFIG_SPU_FS_MODULE
24 static inline struct spufs_calls *spufs_calls_get(void)
26 struct spufs_calls *calls = NULL;
29 calls = rcu_dereference(spufs_calls);
30 if (calls && !try_module_get(calls->owner))
37 static inline void spufs_calls_put(struct spufs_calls *calls)
39 BUG_ON(calls != spufs_calls);
41 /* we don't need to rcu this, as we hold a reference to the module */
42 module_put(spufs_calls->owner);
45 #else /* !defined CONFIG_SPU_FS_MODULE */
47 static inline struct spufs_calls *spufs_calls_get(void)
52 static inline void spufs_calls_put(struct spufs_calls *calls) { }
54 #endif /* CONFIG_SPU_FS_MODULE */
56 SYSCALL_DEFINE4(spu_create, const char __user *, name, unsigned int, flags,
57 umode_t, mode, int, neighbor_fd)
60 struct spufs_calls *calls;
62 calls = spufs_calls_get();
66 if (flags & SPU_CREATE_AFFINITY_SPU) {
67 struct fd neighbor = fdget(neighbor_fd);
70 ret = calls->create_thread(name, flags, mode, neighbor.file);
74 ret = calls->create_thread(name, flags, mode, NULL);
76 spufs_calls_put(calls);
80 SYSCALL_DEFINE3(spu_run,int, fd, __u32 __user *, unpc, __u32 __user *, ustatus)
84 struct spufs_calls *calls;
86 calls = spufs_calls_get();
93 ret = calls->spu_run(arg.file, unpc, ustatus);
97 spufs_calls_put(calls);
101 #ifdef CONFIG_COREDUMP
102 int elf_coredump_extra_notes_size(void)
104 struct spufs_calls *calls;
107 calls = spufs_calls_get();
111 ret = calls->coredump_extra_notes_size();
113 spufs_calls_put(calls);
118 int elf_coredump_extra_notes_write(struct coredump_params *cprm)
120 struct spufs_calls *calls;
123 calls = spufs_calls_get();
127 ret = calls->coredump_extra_notes_write(cprm);
129 spufs_calls_put(calls);
135 void notify_spus_active(void)
137 struct spufs_calls *calls;
139 calls = spufs_calls_get();
143 calls->notify_spus_active();
144 spufs_calls_put(calls);
149 int register_spu_syscalls(struct spufs_calls *calls)
154 rcu_assign_pointer(spufs_calls, calls);
157 EXPORT_SYMBOL_GPL(register_spu_syscalls);
159 void unregister_spu_syscalls(struct spufs_calls *calls)
161 BUG_ON(spufs_calls->owner != calls->owner);
162 RCU_INIT_POINTER(spufs_calls, NULL);
165 EXPORT_SYMBOL_GPL(unregister_spu_syscalls);