syscalls.c 2.1 KB
Newer Older
1 2
#include <linux/file.h>
#include <linux/fs.h>
3
#include <linux/export.h>
4 5
#include <linux/mount.h>
#include <linux/namei.h>
6
#include <linux/slab.h>
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32

#include <asm/uaccess.h>

#include "spufs.h"

/**
 * sys_spu_run - run code loaded into an SPU
 *
 * @unpc:    next program counter for the SPU
 * @ustatus: status of the SPU
 *
 * This system call transfers the control of execution of a
 * user space thread to an SPU. It will return when the
 * SPU has finished executing or when it hits an error
 * condition and it will be interrupted if a signal needs
 * to be delivered to a handler in user space.
 *
 * The next program counter is set to the passed value
 * before the SPU starts fetching code and the user space
 * pointer gets updated with the new value when returning
 * from kernel space.
 *
 * The status value returned from spu_run reflects the
 * value of the spu_status register after the SPU has stopped.
 *
 */
33 34 35
static long do_spu_run(struct file *filp,
			__u32 __user *unpc,
			__u32 __user *ustatus)
36 37 38 39 40 41
{
	long ret;
	struct spufs_inode_info *i;
	u32 npc, status;

	ret = -EFAULT;
42
	if (get_user(npc, unpc))
43 44
		goto out;

45
	/* check if this file was created by spu_create */
46
	ret = -EINVAL;
47
	if (filp->f_op != &spufs_context_fops)
48 49
		goto out;

J
Josef Sipek 已提交
50
	i = SPUFS_I(filp->f_path.dentry->d_inode);
51
	ret = spufs_run_spu(i->i_ctx, &npc, &status);
52

53 54 55 56
	if (put_user(npc, unpc))
		ret = -EFAULT;

	if (ustatus && put_user(status, ustatus))
57 58 59 60 61
		ret = -EFAULT;
out:
	return ret;
}

62
static long do_spu_create(const char __user *pathname, unsigned int flags,
A
Al Viro 已提交
63
		umode_t mode, struct file *neighbor)
64
{
65 66
	struct path path;
	struct dentry *dentry;
67 68
	int ret;

69
	dentry = user_path_create(AT_FDCWD, pathname, &path, LOOKUP_DIRECTORY);
70 71 72
	ret = PTR_ERR(dentry);
	if (!IS_ERR(dentry)) {
		ret = spufs_create(&path, dentry, flags, mode, neighbor);
A
Al Viro 已提交
73
		done_path_create(&path, dentry);
74 75 76 77 78 79
	}

	return ret;
}

struct spufs_calls spufs_calls = {
80
	.create_thread = do_spu_create,
81
	.spu_run = do_spu_run,
82 83
	.coredump_extra_notes_size = spufs_coredump_extra_notes_size,
	.coredump_extra_notes_write = spufs_coredump_extra_notes_write,
84
	.notify_spus_active = do_notify_spus_active,
85 86
	.owner = THIS_MODULE,
};