syscalls.c 2.1 KB

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