syscalls.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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) || get_user(status, ustatus))
  36. goto out;
  37. /* check if this file was created by spu_create */
  38. ret = -EINVAL;
  39. if (filp->f_op != &spufs_context_fops)
  40. goto out;
  41. i = SPUFS_I(filp->f_dentry->d_inode);
  42. ret = spufs_run_spu(filp, i->i_ctx, &npc, &status);
  43. if (put_user(npc, unpc) || put_user(status, ustatus))
  44. ret = -EFAULT;
  45. out:
  46. return ret;
  47. }
  48. #ifndef MODULE
  49. asmlinkage long sys_spu_run(int fd, __u32 __user *unpc, __u32 __user *ustatus)
  50. {
  51. int fput_needed;
  52. struct file *filp;
  53. long ret;
  54. ret = -EBADF;
  55. filp = fget_light(fd, &fput_needed);
  56. if (filp) {
  57. ret = do_spu_run(filp, unpc, ustatus);
  58. fput_light(filp, fput_needed);
  59. }
  60. return ret;
  61. }
  62. #endif
  63. asmlinkage long sys_spu_create(const char __user *pathname,
  64. unsigned int flags, mode_t mode)
  65. {
  66. char *tmp;
  67. int ret;
  68. tmp = getname(pathname);
  69. ret = PTR_ERR(tmp);
  70. if (!IS_ERR(tmp)) {
  71. struct nameidata nd;
  72. ret = path_lookup(tmp, LOOKUP_PARENT|
  73. LOOKUP_OPEN|LOOKUP_CREATE, &nd);
  74. if (!ret) {
  75. ret = spufs_create_thread(&nd, flags, mode);
  76. path_release(&nd);
  77. }
  78. putname(tmp);
  79. }
  80. return ret;
  81. }
  82. struct spufs_calls spufs_calls = {
  83. .create_thread = sys_spu_create,
  84. .spu_run = do_spu_run,
  85. .owner = THIS_MODULE,
  86. };