spu_syscalls.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * SPU file system -- system call stubs
  3. *
  4. * (C) Copyright IBM Deutschland Entwicklung GmbH 2005
  5. *
  6. * Author: Arnd Bergmann <arndb@de.ibm.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2, or (at your option)
  11. * any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. */
  22. #include <linux/file.h>
  23. #include <linux/module.h>
  24. #include <linux/syscalls.h>
  25. #include <asm/spu.h>
  26. struct spufs_calls spufs_calls = {
  27. .owner = NULL,
  28. };
  29. /* These stub syscalls are needed to have the actual implementation
  30. * within a loadable module. When spufs is built into the kernel,
  31. * this file is not used and the syscalls directly enter the fs code */
  32. asmlinkage long sys_spu_create(const char __user *name,
  33. unsigned int flags, mode_t mode, int neighbor_fd)
  34. {
  35. long ret;
  36. struct module *owner = spufs_calls.owner;
  37. struct file *neighbor;
  38. int fput_needed;
  39. ret = -ENOSYS;
  40. if (owner && try_module_get(owner)) {
  41. if (flags & SPU_CREATE_AFFINITY_SPU) {
  42. neighbor = fget_light(neighbor_fd, &fput_needed);
  43. ret = -EBADF;
  44. if (neighbor) {
  45. ret = spufs_calls.create_thread(name, flags,
  46. mode, neighbor);
  47. fput_light(neighbor, fput_needed);
  48. }
  49. }
  50. else {
  51. ret = spufs_calls.create_thread(name, flags,
  52. mode, NULL);
  53. }
  54. module_put(owner);
  55. }
  56. return ret;
  57. }
  58. asmlinkage long sys_spu_run(int fd, __u32 __user *unpc, __u32 __user *ustatus)
  59. {
  60. long ret;
  61. struct file *filp;
  62. int fput_needed;
  63. struct module *owner = spufs_calls.owner;
  64. ret = -ENOSYS;
  65. if (owner && try_module_get(owner)) {
  66. ret = -EBADF;
  67. filp = fget_light(fd, &fput_needed);
  68. if (filp) {
  69. ret = spufs_calls.spu_run(filp, unpc, ustatus);
  70. fput_light(filp, fput_needed);
  71. }
  72. module_put(owner);
  73. }
  74. return ret;
  75. }
  76. int register_spu_syscalls(struct spufs_calls *calls)
  77. {
  78. if (spufs_calls.owner)
  79. return -EBUSY;
  80. spufs_calls.create_thread = calls->create_thread;
  81. spufs_calls.spu_run = calls->spu_run;
  82. smp_mb();
  83. spufs_calls.owner = calls->owner;
  84. return 0;
  85. }
  86. EXPORT_SYMBOL_GPL(register_spu_syscalls);
  87. void unregister_spu_syscalls(struct spufs_calls *calls)
  88. {
  89. BUG_ON(spufs_calls.owner != calls->owner);
  90. spufs_calls.owner = NULL;
  91. }
  92. EXPORT_SYMBOL_GPL(unregister_spu_syscalls);