Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1 | /* |
| 2 | * SPU file system -- system call stubs |
| 3 | * |
| 4 | * (C) Copyright IBM Deutschland Entwicklung GmbH 2005 |
| 5 | * |
| 6 | * Author: Arnd Bergmann <arndb@de.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 | #include <linux/file.h> |
| 23 | #include <linux/module.h> |
| 24 | #include <linux/syscalls.h> |
| 25 | |
| 26 | #include <asm/spu.h> |
| 27 | |
| 28 | struct spufs_calls spufs_calls = { |
| 29 | .owner = NULL, |
| 30 | }; |
| 31 | |
| 32 | /* These stub syscalls are needed to have the actual implementation |
| 33 | * within a loadable module. When spufs is built into the kernel, |
| 34 | * this file is not used and the syscalls directly enter the fs code */ |
| 35 | |
| 36 | asmlinkage long sys_spu_create(const char __user *name, |
Arnd Bergmann | 8e68e2f | 2007-07-20 21:39:47 +0200 | [diff] [blame] | 37 | unsigned int flags, mode_t mode, int neighbor_fd) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 38 | { |
| 39 | long ret; |
Arnd Bergmann | b41305a | 2005-12-05 22:52:23 -0500 | [diff] [blame] | 40 | struct module *owner = spufs_calls.owner; |
Arnd Bergmann | 8e68e2f | 2007-07-20 21:39:47 +0200 | [diff] [blame] | 41 | struct file *neighbor; |
| 42 | int fput_needed; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 43 | |
| 44 | ret = -ENOSYS; |
Arnd Bergmann | 59d6d39 | 2005-12-09 19:04:15 +0100 | [diff] [blame] | 45 | if (owner && try_module_get(owner)) { |
Arnd Bergmann | 8e68e2f | 2007-07-20 21:39:47 +0200 | [diff] [blame] | 46 | if (flags & SPU_CREATE_AFFINITY_SPU) { |
| 47 | neighbor = fget_light(neighbor_fd, &fput_needed); |
Jeremy Kerr | ad941fe | 2007-08-13 13:22:44 +1000 | [diff] [blame] | 48 | ret = -EBADF; |
Arnd Bergmann | 8e68e2f | 2007-07-20 21:39:47 +0200 | [diff] [blame] | 49 | if (neighbor) { |
| 50 | ret = spufs_calls.create_thread(name, flags, |
| 51 | mode, neighbor); |
| 52 | fput_light(neighbor, fput_needed); |
| 53 | } |
| 54 | } |
| 55 | else { |
| 56 | ret = spufs_calls.create_thread(name, flags, |
| 57 | mode, NULL); |
| 58 | } |
Arnd Bergmann | b41305a | 2005-12-05 22:52:23 -0500 | [diff] [blame] | 59 | module_put(owner); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 60 | } |
| 61 | return ret; |
| 62 | } |
| 63 | |
| 64 | asmlinkage long sys_spu_run(int fd, __u32 __user *unpc, __u32 __user *ustatus) |
| 65 | { |
| 66 | long ret; |
| 67 | struct file *filp; |
| 68 | int fput_needed; |
Arnd Bergmann | b41305a | 2005-12-05 22:52:23 -0500 | [diff] [blame] | 69 | struct module *owner = spufs_calls.owner; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 70 | |
| 71 | ret = -ENOSYS; |
Arnd Bergmann | b41305a | 2005-12-05 22:52:23 -0500 | [diff] [blame] | 72 | if (owner && try_module_get(owner)) { |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 73 | ret = -EBADF; |
| 74 | filp = fget_light(fd, &fput_needed); |
| 75 | if (filp) { |
| 76 | ret = spufs_calls.spu_run(filp, unpc, ustatus); |
| 77 | fput_light(filp, fput_needed); |
| 78 | } |
Arnd Bergmann | b41305a | 2005-12-05 22:52:23 -0500 | [diff] [blame] | 79 | module_put(owner); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 80 | } |
| 81 | return ret; |
| 82 | } |
| 83 | |
| 84 | int register_spu_syscalls(struct spufs_calls *calls) |
| 85 | { |
| 86 | if (spufs_calls.owner) |
| 87 | return -EBUSY; |
| 88 | |
| 89 | spufs_calls.create_thread = calls->create_thread; |
| 90 | spufs_calls.spu_run = calls->spu_run; |
| 91 | smp_mb(); |
| 92 | spufs_calls.owner = calls->owner; |
| 93 | return 0; |
| 94 | } |
| 95 | EXPORT_SYMBOL_GPL(register_spu_syscalls); |
| 96 | |
| 97 | void unregister_spu_syscalls(struct spufs_calls *calls) |
| 98 | { |
| 99 | BUG_ON(spufs_calls.owner != calls->owner); |
| 100 | spufs_calls.owner = NULL; |
| 101 | } |
| 102 | EXPORT_SYMBOL_GPL(unregister_spu_syscalls); |