Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1 | #include <linux/file.h> |
| 2 | #include <linux/fs.h> |
Paul Gortmaker | 4b16f8e | 2011-07-22 18:24:23 -0400 | [diff] [blame] | 3 | #include <linux/export.h> |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 4 | #include <linux/mount.h> |
| 5 | #include <linux/namei.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 6 | #include <linux/slab.h> |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 7 | |
| 8 | #include <asm/uaccess.h> |
| 9 | |
| 10 | #include "spufs.h" |
| 11 | |
| 12 | /** |
| 13 | * sys_spu_run - run code loaded into an SPU |
| 14 | * |
| 15 | * @unpc: next program counter for the SPU |
| 16 | * @ustatus: status of the SPU |
| 17 | * |
| 18 | * This system call transfers the control of execution of a |
| 19 | * user space thread to an SPU. It will return when the |
| 20 | * SPU has finished executing or when it hits an error |
| 21 | * condition and it will be interrupted if a signal needs |
| 22 | * to be delivered to a handler in user space. |
| 23 | * |
| 24 | * The next program counter is set to the passed value |
| 25 | * before the SPU starts fetching code and the user space |
| 26 | * pointer gets updated with the new value when returning |
| 27 | * from kernel space. |
| 28 | * |
| 29 | * The status value returned from spu_run reflects the |
| 30 | * value of the spu_status register after the SPU has stopped. |
| 31 | * |
| 32 | */ |
Arnd Bergmann | 8fce10a | 2006-01-11 23:07:11 +0000 | [diff] [blame] | 33 | static long do_spu_run(struct file *filp, |
| 34 | __u32 __user *unpc, |
| 35 | __u32 __user *ustatus) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 36 | { |
| 37 | long ret; |
| 38 | struct spufs_inode_info *i; |
| 39 | u32 npc, status; |
| 40 | |
| 41 | ret = -EFAULT; |
Arnd Bergmann | 9add11d | 2006-10-04 17:26:14 +0200 | [diff] [blame] | 42 | if (get_user(npc, unpc)) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 43 | goto out; |
| 44 | |
Arnd Bergmann | e80358a | 2006-01-04 20:31:23 +0100 | [diff] [blame] | 45 | /* check if this file was created by spu_create */ |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 46 | ret = -EINVAL; |
Arnd Bergmann | e80358a | 2006-01-04 20:31:23 +0100 | [diff] [blame] | 47 | if (filp->f_op != &spufs_context_fops) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 48 | goto out; |
| 49 | |
Josef Sipek | b4d1ab5 | 2006-12-08 02:37:30 -0800 | [diff] [blame] | 50 | i = SPUFS_I(filp->f_path.dentry->d_inode); |
Jeremy Kerr | 50af32a | 2007-07-20 21:39:42 +0200 | [diff] [blame] | 51 | ret = spufs_run_spu(i->i_ctx, &npc, &status); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 52 | |
Arnd Bergmann | 9add11d | 2006-10-04 17:26:14 +0200 | [diff] [blame] | 53 | if (put_user(npc, unpc)) |
| 54 | ret = -EFAULT; |
| 55 | |
| 56 | if (ustatus && put_user(status, ustatus)) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 57 | ret = -EFAULT; |
| 58 | out: |
| 59 | return ret; |
| 60 | } |
| 61 | |
Jeremy Kerr | 1e8b0f6 | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 62 | static long do_spu_create(const char __user *pathname, unsigned int flags, |
Al Viro | c6684b2 | 2011-07-26 04:47:14 -0400 | [diff] [blame] | 63 | umode_t mode, struct file *neighbor) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 64 | { |
Al Viro | 1ba1068 | 2011-06-26 11:54:58 -0400 | [diff] [blame] | 65 | struct path path; |
| 66 | struct dentry *dentry; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 67 | int ret; |
| 68 | |
Jeff Layton | 1ac12b4 | 2012-12-11 12:10:06 -0500 | [diff] [blame^] | 69 | dentry = user_path_create(AT_FDCWD, pathname, &path, LOOKUP_DIRECTORY); |
Al Viro | 1ba1068 | 2011-06-26 11:54:58 -0400 | [diff] [blame] | 70 | ret = PTR_ERR(dentry); |
| 71 | if (!IS_ERR(dentry)) { |
| 72 | ret = spufs_create(&path, dentry, flags, mode, neighbor); |
Al Viro | 921a165 | 2012-07-20 01:15:31 +0400 | [diff] [blame] | 73 | done_path_create(&path, dentry); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | return ret; |
| 77 | } |
| 78 | |
| 79 | struct spufs_calls spufs_calls = { |
Arnd Bergmann | 8e68e2f | 2007-07-20 21:39:47 +0200 | [diff] [blame] | 80 | .create_thread = do_spu_create, |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 81 | .spu_run = do_spu_run, |
Michael Ellerman | 48cad41 | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 82 | .coredump_extra_notes_size = spufs_coredump_extra_notes_size, |
| 83 | .coredump_extra_notes_write = spufs_coredump_extra_notes_write, |
Bob Nelson | aed3a8c | 2007-12-15 01:27:30 +1100 | [diff] [blame] | 84 | .notify_spus_active = do_notify_spus_active, |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 85 | .owner = THIS_MODULE, |
| 86 | }; |