xref: /openbmc/linux/arch/powerpc/platforms/cell/spufs/syscalls.c (revision 498495dba268b20e8eadd7fe93c140c68b6cc9d2)
1*b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
267207b96SArnd Bergmann #include <linux/file.h>
367207b96SArnd Bergmann #include <linux/fs.h>
44b16f8e2SPaul Gortmaker #include <linux/export.h>
567207b96SArnd Bergmann #include <linux/mount.h>
667207b96SArnd Bergmann #include <linux/namei.h>
75a0e3ad6STejun Heo #include <linux/slab.h>
867207b96SArnd Bergmann 
97c0f6ba6SLinus Torvalds #include <linux/uaccess.h>
1067207b96SArnd Bergmann 
1167207b96SArnd Bergmann #include "spufs.h"
1267207b96SArnd Bergmann 
1367207b96SArnd Bergmann /**
1467207b96SArnd Bergmann  * sys_spu_run - run code loaded into an SPU
1567207b96SArnd Bergmann  *
1667207b96SArnd Bergmann  * @unpc:    next program counter for the SPU
1767207b96SArnd Bergmann  * @ustatus: status of the SPU
1867207b96SArnd Bergmann  *
1967207b96SArnd Bergmann  * This system call transfers the control of execution of a
2067207b96SArnd Bergmann  * user space thread to an SPU. It will return when the
2167207b96SArnd Bergmann  * SPU has finished executing or when it hits an error
2267207b96SArnd Bergmann  * condition and it will be interrupted if a signal needs
2367207b96SArnd Bergmann  * to be delivered to a handler in user space.
2467207b96SArnd Bergmann  *
2567207b96SArnd Bergmann  * The next program counter is set to the passed value
2667207b96SArnd Bergmann  * before the SPU starts fetching code and the user space
2767207b96SArnd Bergmann  * pointer gets updated with the new value when returning
2867207b96SArnd Bergmann  * from kernel space.
2967207b96SArnd Bergmann  *
3067207b96SArnd Bergmann  * The status value returned from spu_run reflects the
3167207b96SArnd Bergmann  * value of the spu_status register after the SPU has stopped.
3267207b96SArnd Bergmann  *
3367207b96SArnd Bergmann  */
do_spu_run(struct file * filp,__u32 __user * unpc,__u32 __user * ustatus)348fce10a3SArnd Bergmann static long do_spu_run(struct file *filp,
358fce10a3SArnd Bergmann 			__u32 __user *unpc,
368fce10a3SArnd Bergmann 			__u32 __user *ustatus)
3767207b96SArnd Bergmann {
3867207b96SArnd Bergmann 	long ret;
3967207b96SArnd Bergmann 	struct spufs_inode_info *i;
4067207b96SArnd Bergmann 	u32 npc, status;
4167207b96SArnd Bergmann 
4267207b96SArnd Bergmann 	ret = -EFAULT;
439add11daSArnd Bergmann 	if (get_user(npc, unpc))
4467207b96SArnd Bergmann 		goto out;
4567207b96SArnd Bergmann 
46e80358adSArnd Bergmann 	/* check if this file was created by spu_create */
4767207b96SArnd Bergmann 	ret = -EINVAL;
48e80358adSArnd Bergmann 	if (filp->f_op != &spufs_context_fops)
4967207b96SArnd Bergmann 		goto out;
5067207b96SArnd Bergmann 
51496ad9aaSAl Viro 	i = SPUFS_I(file_inode(filp));
5250af32a9SJeremy Kerr 	ret = spufs_run_spu(i->i_ctx, &npc, &status);
5367207b96SArnd Bergmann 
549add11daSArnd Bergmann 	if (put_user(npc, unpc))
559add11daSArnd Bergmann 		ret = -EFAULT;
569add11daSArnd Bergmann 
579add11daSArnd Bergmann 	if (ustatus && put_user(status, ustatus))
5867207b96SArnd Bergmann 		ret = -EFAULT;
5967207b96SArnd Bergmann out:
6067207b96SArnd Bergmann 	return ret;
6167207b96SArnd Bergmann }
6267207b96SArnd Bergmann 
do_spu_create(const char __user * pathname,unsigned int flags,umode_t mode,struct file * neighbor)631e8b0f6dSJeremy Kerr static long do_spu_create(const char __user *pathname, unsigned int flags,
64c6684b26SAl Viro 		umode_t mode, struct file *neighbor)
6567207b96SArnd Bergmann {
661ba10681SAl Viro 	struct path path;
671ba10681SAl Viro 	struct dentry *dentry;
6867207b96SArnd Bergmann 	int ret;
6967207b96SArnd Bergmann 
701ac12b4bSJeff Layton 	dentry = user_path_create(AT_FDCWD, pathname, &path, LOOKUP_DIRECTORY);
711ba10681SAl Viro 	ret = PTR_ERR(dentry);
721ba10681SAl Viro 	if (!IS_ERR(dentry)) {
731ba10681SAl Viro 		ret = spufs_create(&path, dentry, flags, mode, neighbor);
74921a1650SAl Viro 		done_path_create(&path, dentry);
7567207b96SArnd Bergmann 	}
7667207b96SArnd Bergmann 
7767207b96SArnd Bergmann 	return ret;
7867207b96SArnd Bergmann }
7967207b96SArnd Bergmann 
8067207b96SArnd Bergmann struct spufs_calls spufs_calls = {
818e68e2f2SArnd Bergmann 	.create_thread = do_spu_create,
8267207b96SArnd Bergmann 	.spu_run = do_spu_run,
83aed3a8c9SBob Nelson 	.notify_spus_active = do_notify_spus_active,
8467207b96SArnd Bergmann 	.owner = THIS_MODULE,
85e623fbf1SMichael Ellerman #ifdef CONFIG_COREDUMP
86e623fbf1SMichael Ellerman 	.coredump_extra_notes_size = spufs_coredump_extra_notes_size,
87e623fbf1SMichael Ellerman 	.coredump_extra_notes_write = spufs_coredump_extra_notes_write,
88e623fbf1SMichael Ellerman #endif
8967207b96SArnd Bergmann };
90