Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 #include <linux/file.h>
0003 #include <linux/fs.h>
0004 #include <linux/export.h>
0005 #include <linux/mount.h>
0006 #include <linux/namei.h>
0007 #include <linux/slab.h>
0008 
0009 #include <linux/uaccess.h>
0010 
0011 #include "spufs.h"
0012 
0013 /**
0014  * sys_spu_run - run code loaded into an SPU
0015  *
0016  * @unpc:    next program counter for the SPU
0017  * @ustatus: status of the SPU
0018  *
0019  * This system call transfers the control of execution of a
0020  * user space thread to an SPU. It will return when the
0021  * SPU has finished executing or when it hits an error
0022  * condition and it will be interrupted if a signal needs
0023  * to be delivered to a handler in user space.
0024  *
0025  * The next program counter is set to the passed value
0026  * before the SPU starts fetching code and the user space
0027  * pointer gets updated with the new value when returning
0028  * from kernel space.
0029  *
0030  * The status value returned from spu_run reflects the
0031  * value of the spu_status register after the SPU has stopped.
0032  *
0033  */
0034 static long do_spu_run(struct file *filp,
0035             __u32 __user *unpc,
0036             __u32 __user *ustatus)
0037 {
0038     long ret;
0039     struct spufs_inode_info *i;
0040     u32 npc, status;
0041 
0042     ret = -EFAULT;
0043     if (get_user(npc, unpc))
0044         goto out;
0045 
0046     /* check if this file was created by spu_create */
0047     ret = -EINVAL;
0048     if (filp->f_op != &spufs_context_fops)
0049         goto out;
0050 
0051     i = SPUFS_I(file_inode(filp));
0052     ret = spufs_run_spu(i->i_ctx, &npc, &status);
0053 
0054     if (put_user(npc, unpc))
0055         ret = -EFAULT;
0056 
0057     if (ustatus && put_user(status, ustatus))
0058         ret = -EFAULT;
0059 out:
0060     return ret;
0061 }
0062 
0063 static long do_spu_create(const char __user *pathname, unsigned int flags,
0064         umode_t mode, struct file *neighbor)
0065 {
0066     struct path path;
0067     struct dentry *dentry;
0068     int ret;
0069 
0070     dentry = user_path_create(AT_FDCWD, pathname, &path, LOOKUP_DIRECTORY);
0071     ret = PTR_ERR(dentry);
0072     if (!IS_ERR(dentry)) {
0073         ret = spufs_create(&path, dentry, flags, mode, neighbor);
0074         done_path_create(&path, dentry);
0075     }
0076 
0077     return ret;
0078 }
0079 
0080 struct spufs_calls spufs_calls = {
0081     .create_thread = do_spu_create,
0082     .spu_run = do_spu_run,
0083     .notify_spus_active = do_notify_spus_active,
0084     .owner = THIS_MODULE,
0085 #ifdef CONFIG_COREDUMP
0086     .coredump_extra_notes_size = spufs_coredump_extra_notes_size,
0087     .coredump_extra_notes_write = spufs_coredump_extra_notes_write,
0088 #endif
0089 };