blob: e6565a949ddc727b11299b4374001ff70a67e326 [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>
6
7#include <asm/uaccess.h>
8
9#include "spufs.h"
10
11/**
12 * sys_spu_run - run code loaded into an SPU
13 *
14 * @unpc: next program counter for the SPU
15 * @ustatus: status of the SPU
16 *
17 * This system call transfers the control of execution of a
18 * user space thread to an SPU. It will return when the
19 * SPU has finished executing or when it hits an error
20 * condition and it will be interrupted if a signal needs
21 * to be delivered to a handler in user space.
22 *
23 * The next program counter is set to the passed value
24 * before the SPU starts fetching code and the user space
25 * pointer gets updated with the new value when returning
26 * from kernel space.
27 *
28 * The status value returned from spu_run reflects the
29 * value of the spu_status register after the SPU has stopped.
30 *
31 */
Arnd Bergmann8fce10a2006-01-11 23:07:11 +000032static long do_spu_run(struct file *filp,
33 __u32 __user *unpc,
34 __u32 __user *ustatus)
Arnd Bergmann67207b92005-11-15 15:53:48 -050035{
36 long ret;
37 struct spufs_inode_info *i;
38 u32 npc, status;
39
40 ret = -EFAULT;
Arnd Bergmann8b3d6662005-11-15 15:53:52 -050041 if (get_user(npc, unpc) || get_user(status, ustatus))
Arnd Bergmann67207b92005-11-15 15:53:48 -050042 goto out;
43
Arnd Bergmanne80358a2006-01-04 20:31:23 +010044 /* check if this file was created by spu_create */
Arnd Bergmann67207b92005-11-15 15:53:48 -050045 ret = -EINVAL;
Arnd Bergmanne80358a2006-01-04 20:31:23 +010046 if (filp->f_op != &spufs_context_fops)
Arnd Bergmann67207b92005-11-15 15:53:48 -050047 goto out;
48
49 i = SPUFS_I(filp->f_dentry->d_inode);
50 ret = spufs_run_spu(filp, i->i_ctx, &npc, &status);
51
Arnd Bergmann8b3d6662005-11-15 15:53:52 -050052 if (put_user(npc, unpc) || put_user(status, ustatus))
Arnd Bergmann67207b92005-11-15 15:53:48 -050053 ret = -EFAULT;
54out:
55 return ret;
56}
57
58#ifndef MODULE
59asmlinkage long sys_spu_run(int fd, __u32 __user *unpc, __u32 __user *ustatus)
60{
61 int fput_needed;
62 struct file *filp;
63 long ret;
64
65 ret = -EBADF;
66 filp = fget_light(fd, &fput_needed);
67 if (filp) {
68 ret = do_spu_run(filp, unpc, ustatus);
69 fput_light(filp, fput_needed);
70 }
71
72 return ret;
73}
74#endif
75
76asmlinkage long sys_spu_create(const char __user *pathname,
77 unsigned int flags, mode_t mode)
78{
79 char *tmp;
80 int ret;
81
82 tmp = getname(pathname);
83 ret = PTR_ERR(tmp);
84 if (!IS_ERR(tmp)) {
85 struct nameidata nd;
86
87 ret = path_lookup(tmp, LOOKUP_PARENT|
88 LOOKUP_OPEN|LOOKUP_CREATE, &nd);
89 if (!ret) {
Arnd Bergmann6ff730c2006-01-04 20:31:31 +010090 ret = spufs_create_thread(&nd, flags, mode);
Arnd Bergmann67207b92005-11-15 15:53:48 -050091 path_release(&nd);
92 }
93 putname(tmp);
94 }
95
96 return ret;
97}
98
99struct spufs_calls spufs_calls = {
100 .create_thread = sys_spu_create,
101 .spu_run = do_spu_run,
102 .owner = THIS_MODULE,
103};