syscalls.c 2.2 KB

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