syscalls.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #include <linux/file.h>
  2. #include <linux/fs.h>
  3. #include <linux/module.h>
  4. #include <linux/mount.h>
  5. #include <linux/namei.h>
  6. #include <asm/uaccess.h>
  7. #include "spufs.h"
  8. /**
  9. * sys_spu_run - run code loaded into an SPU
  10. *
  11. * @unpc: next program counter for the SPU
  12. * @ustatus: status of the SPU
  13. *
  14. * This system call transfers the control of execution of a
  15. * user space thread to an SPU. It will return when the
  16. * SPU has finished executing or when it hits an error
  17. * condition and it will be interrupted if a signal needs
  18. * to be delivered to a handler in user space.
  19. *
  20. * The next program counter is set to the passed value
  21. * before the SPU starts fetching code and the user space
  22. * pointer gets updated with the new value when returning
  23. * from kernel space.
  24. *
  25. * The status value returned from spu_run reflects the
  26. * value of the spu_status register after the SPU has stopped.
  27. *
  28. */
  29. long do_spu_run(struct file *filp, __u32 __user *unpc, __u32 __user *ustatus)
  30. {
  31. long ret;
  32. struct spufs_inode_info *i;
  33. u32 npc, status;
  34. ret = -EFAULT;
  35. if (get_user(npc, unpc))
  36. goto out;
  37. ret = -EINVAL;
  38. if (filp->f_vfsmnt->mnt_sb->s_magic != SPUFS_MAGIC)
  39. goto out;
  40. i = SPUFS_I(filp->f_dentry->d_inode);
  41. ret = spufs_run_spu(filp, i->i_ctx, &npc, &status);
  42. if (ret ==-EAGAIN || ret == -EIO)
  43. ret = status;
  44. if (put_user(npc, unpc))
  45. ret = -EFAULT;
  46. if (ustatus && put_user(status, ustatus))
  47. ret = -EFAULT;
  48. out:
  49. return ret;
  50. }
  51. #ifndef MODULE
  52. asmlinkage long sys_spu_run(int fd, __u32 __user *unpc, __u32 __user *ustatus)
  53. {
  54. int fput_needed;
  55. struct file *filp;
  56. long ret;
  57. ret = -EBADF;
  58. filp = fget_light(fd, &fput_needed);
  59. if (filp) {
  60. ret = do_spu_run(filp, unpc, ustatus);
  61. fput_light(filp, fput_needed);
  62. }
  63. return ret;
  64. }
  65. #endif
  66. asmlinkage long sys_spu_create(const char __user *pathname,
  67. unsigned int flags, mode_t mode)
  68. {
  69. char *tmp;
  70. int ret;
  71. tmp = getname(pathname);
  72. ret = PTR_ERR(tmp);
  73. if (!IS_ERR(tmp)) {
  74. struct nameidata nd;
  75. ret = path_lookup(tmp, LOOKUP_PARENT|
  76. LOOKUP_OPEN|LOOKUP_CREATE, &nd);
  77. if (!ret) {
  78. ret = spufs_create_thread(&nd, pathname, flags, mode);
  79. path_release(&nd);
  80. }
  81. putname(tmp);
  82. }
  83. return ret;
  84. }
  85. struct spufs_calls spufs_calls = {
  86. .create_thread = sys_spu_create,
  87. .spu_run = do_spu_run,
  88. .owner = THIS_MODULE,
  89. };