blob: 187a7d32f86a25ea2ff19e1fab99f7c551d0d59e [file] [log] [blame]
Arnd Bergmann67207b92005-11-15 15:53:48 -05001#include <linux/file.h>
2#include <linux/fs.h>
3#include <linux/module.h>
4#include <linux/mount.h>
5#include <linux/namei.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09006#include <linux/slab.h>
Arnd Bergmann67207b92005-11-15 15:53:48 -05007
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 Bergmann8fce10a2006-01-11 23:07:11 +000033static long do_spu_run(struct file *filp,
34 __u32 __user *unpc,
35 __u32 __user *ustatus)
Arnd Bergmann67207b92005-11-15 15:53:48 -050036{
37 long ret;
38 struct spufs_inode_info *i;
39 u32 npc, status;
40
41 ret = -EFAULT;
Arnd Bergmann9add11d2006-10-04 17:26:14 +020042 if (get_user(npc, unpc))
Arnd Bergmann67207b92005-11-15 15:53:48 -050043 goto out;
44
Arnd Bergmanne80358a2006-01-04 20:31:23 +010045 /* check if this file was created by spu_create */
Arnd Bergmann67207b92005-11-15 15:53:48 -050046 ret = -EINVAL;
Arnd Bergmanne80358a2006-01-04 20:31:23 +010047 if (filp->f_op != &spufs_context_fops)
Arnd Bergmann67207b92005-11-15 15:53:48 -050048 goto out;
49
Josef Sipekb4d1ab52006-12-08 02:37:30 -080050 i = SPUFS_I(filp->f_path.dentry->d_inode);
Jeremy Kerr50af32a2007-07-20 21:39:42 +020051 ret = spufs_run_spu(i->i_ctx, &npc, &status);
Arnd Bergmann67207b92005-11-15 15:53:48 -050052
Arnd Bergmann9add11d2006-10-04 17:26:14 +020053 if (put_user(npc, unpc))
54 ret = -EFAULT;
55
56 if (ustatus && put_user(status, ustatus))
Arnd Bergmann67207b92005-11-15 15:53:48 -050057 ret = -EFAULT;
58out:
59 return ret;
60}
61
Jeremy Kerr1e8b0f62007-09-19 14:38:12 +100062static long do_spu_create(const char __user *pathname, unsigned int flags,
63 mode_t mode, struct file *neighbor)
Arnd Bergmann67207b92005-11-15 15:53:48 -050064{
65 char *tmp;
66 int ret;
67
68 tmp = getname(pathname);
69 ret = PTR_ERR(tmp);
70 if (!IS_ERR(tmp)) {
71 struct nameidata nd;
72
Al Viro2c552d82008-08-02 22:40:42 -040073 ret = path_lookup(tmp, LOOKUP_PARENT, &nd);
Arnd Bergmann67207b92005-11-15 15:53:48 -050074 if (!ret) {
Al Viro2c552d82008-08-02 22:40:42 -040075 nd.flags |= LOOKUP_OPEN | LOOKUP_CREATE;
Arnd Bergmann8e68e2f2007-07-20 21:39:47 +020076 ret = spufs_create(&nd, flags, mode, neighbor);
Jan Blunck1d957f92008-02-14 19:34:35 -080077 path_put(&nd.path);
Arnd Bergmann67207b92005-11-15 15:53:48 -050078 }
79 putname(tmp);
80 }
81
82 return ret;
83}
84
85struct spufs_calls spufs_calls = {
Arnd Bergmann8e68e2f2007-07-20 21:39:47 +020086 .create_thread = do_spu_create,
Arnd Bergmann67207b92005-11-15 15:53:48 -050087 .spu_run = do_spu_run,
Michael Ellerman48cad412007-09-19 14:38:12 +100088 .coredump_extra_notes_size = spufs_coredump_extra_notes_size,
89 .coredump_extra_notes_write = spufs_coredump_extra_notes_write,
Bob Nelsonaed3a8c2007-12-15 01:27:30 +110090 .notify_spus_active = do_notify_spus_active,
Arnd Bergmann67207b92005-11-15 15:53:48 -050091 .owner = THIS_MODULE,
92};