xref: /OK3568_Linux_fs/kernel/arch/powerpc/platforms/cell/spufs/syscalls.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun #include <linux/file.h>
3*4882a593Smuzhiyun #include <linux/fs.h>
4*4882a593Smuzhiyun #include <linux/export.h>
5*4882a593Smuzhiyun #include <linux/mount.h>
6*4882a593Smuzhiyun #include <linux/namei.h>
7*4882a593Smuzhiyun #include <linux/slab.h>
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun #include <linux/uaccess.h>
10*4882a593Smuzhiyun 
11*4882a593Smuzhiyun #include "spufs.h"
12*4882a593Smuzhiyun 
13*4882a593Smuzhiyun /**
14*4882a593Smuzhiyun  * sys_spu_run - run code loaded into an SPU
15*4882a593Smuzhiyun  *
16*4882a593Smuzhiyun  * @unpc:    next program counter for the SPU
17*4882a593Smuzhiyun  * @ustatus: status of the SPU
18*4882a593Smuzhiyun  *
19*4882a593Smuzhiyun  * This system call transfers the control of execution of a
20*4882a593Smuzhiyun  * user space thread to an SPU. It will return when the
21*4882a593Smuzhiyun  * SPU has finished executing or when it hits an error
22*4882a593Smuzhiyun  * condition and it will be interrupted if a signal needs
23*4882a593Smuzhiyun  * to be delivered to a handler in user space.
24*4882a593Smuzhiyun  *
25*4882a593Smuzhiyun  * The next program counter is set to the passed value
26*4882a593Smuzhiyun  * before the SPU starts fetching code and the user space
27*4882a593Smuzhiyun  * pointer gets updated with the new value when returning
28*4882a593Smuzhiyun  * from kernel space.
29*4882a593Smuzhiyun  *
30*4882a593Smuzhiyun  * The status value returned from spu_run reflects the
31*4882a593Smuzhiyun  * value of the spu_status register after the SPU has stopped.
32*4882a593Smuzhiyun  *
33*4882a593Smuzhiyun  */
do_spu_run(struct file * filp,__u32 __user * unpc,__u32 __user * ustatus)34*4882a593Smuzhiyun static long do_spu_run(struct file *filp,
35*4882a593Smuzhiyun 			__u32 __user *unpc,
36*4882a593Smuzhiyun 			__u32 __user *ustatus)
37*4882a593Smuzhiyun {
38*4882a593Smuzhiyun 	long ret;
39*4882a593Smuzhiyun 	struct spufs_inode_info *i;
40*4882a593Smuzhiyun 	u32 npc, status;
41*4882a593Smuzhiyun 
42*4882a593Smuzhiyun 	ret = -EFAULT;
43*4882a593Smuzhiyun 	if (get_user(npc, unpc))
44*4882a593Smuzhiyun 		goto out;
45*4882a593Smuzhiyun 
46*4882a593Smuzhiyun 	/* check if this file was created by spu_create */
47*4882a593Smuzhiyun 	ret = -EINVAL;
48*4882a593Smuzhiyun 	if (filp->f_op != &spufs_context_fops)
49*4882a593Smuzhiyun 		goto out;
50*4882a593Smuzhiyun 
51*4882a593Smuzhiyun 	i = SPUFS_I(file_inode(filp));
52*4882a593Smuzhiyun 	ret = spufs_run_spu(i->i_ctx, &npc, &status);
53*4882a593Smuzhiyun 
54*4882a593Smuzhiyun 	if (put_user(npc, unpc))
55*4882a593Smuzhiyun 		ret = -EFAULT;
56*4882a593Smuzhiyun 
57*4882a593Smuzhiyun 	if (ustatus && put_user(status, ustatus))
58*4882a593Smuzhiyun 		ret = -EFAULT;
59*4882a593Smuzhiyun out:
60*4882a593Smuzhiyun 	return ret;
61*4882a593Smuzhiyun }
62*4882a593Smuzhiyun 
do_spu_create(const char __user * pathname,unsigned int flags,umode_t mode,struct file * neighbor)63*4882a593Smuzhiyun static long do_spu_create(const char __user *pathname, unsigned int flags,
64*4882a593Smuzhiyun 		umode_t mode, struct file *neighbor)
65*4882a593Smuzhiyun {
66*4882a593Smuzhiyun 	struct path path;
67*4882a593Smuzhiyun 	struct dentry *dentry;
68*4882a593Smuzhiyun 	int ret;
69*4882a593Smuzhiyun 
70*4882a593Smuzhiyun 	dentry = user_path_create(AT_FDCWD, pathname, &path, LOOKUP_DIRECTORY);
71*4882a593Smuzhiyun 	ret = PTR_ERR(dentry);
72*4882a593Smuzhiyun 	if (!IS_ERR(dentry)) {
73*4882a593Smuzhiyun 		ret = spufs_create(&path, dentry, flags, mode, neighbor);
74*4882a593Smuzhiyun 		done_path_create(&path, dentry);
75*4882a593Smuzhiyun 	}
76*4882a593Smuzhiyun 
77*4882a593Smuzhiyun 	return ret;
78*4882a593Smuzhiyun }
79*4882a593Smuzhiyun 
80*4882a593Smuzhiyun struct spufs_calls spufs_calls = {
81*4882a593Smuzhiyun 	.create_thread = do_spu_create,
82*4882a593Smuzhiyun 	.spu_run = do_spu_run,
83*4882a593Smuzhiyun 	.notify_spus_active = do_notify_spus_active,
84*4882a593Smuzhiyun 	.owner = THIS_MODULE,
85*4882a593Smuzhiyun #ifdef CONFIG_COREDUMP
86*4882a593Smuzhiyun 	.coredump_extra_notes_size = spufs_coredump_extra_notes_size,
87*4882a593Smuzhiyun 	.coredump_extra_notes_write = spufs_coredump_extra_notes_write,
88*4882a593Smuzhiyun #endif
89*4882a593Smuzhiyun };
90