syscalls.c 2.2 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. 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))
  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))
  46. ret = -EFAULT;
  47. if (ustatus && put_user(status, ustatus))
  48. ret = -EFAULT;
  49. out:
  50. return ret;
  51. }
  52. #ifndef MODULE
  53. asmlinkage long sys_spu_run(int fd, __u32 __user *unpc, __u32 __user *ustatus)
  54. {
  55. int fput_needed;
  56. struct file *filp;
  57. long ret;
  58. ret = -EBADF;
  59. filp = fget_light(fd, &fput_needed);
  60. if (filp) {
  61. ret = do_spu_run(filp, unpc, ustatus);
  62. fput_light(filp, fput_needed);
  63. }
  64. return ret;
  65. }
  66. #endif
  67. asmlinkage long sys_spu_create(const char __user *pathname,
  68. unsigned int flags, mode_t mode)
  69. {
  70. char *tmp;
  71. int ret;
  72. tmp = getname(pathname);
  73. ret = PTR_ERR(tmp);
  74. if (!IS_ERR(tmp)) {
  75. struct nameidata nd;
  76. ret = path_lookup(tmp, LOOKUP_PARENT|
  77. LOOKUP_OPEN|LOOKUP_CREATE, &nd);
  78. if (!ret) {
  79. ret = spufs_create(&nd, flags, mode);
  80. path_release(&nd);
  81. }
  82. putname(tmp);
  83. }
  84. return ret;
  85. }
  86. struct spufs_calls spufs_calls = {
  87. .create_thread = sys_spu_create,
  88. .spu_run = do_spu_run,
  89. .owner = THIS_MODULE,
  90. };