spu_syscalls.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. if (neighbor) {
  44. ret = spufs_calls.create_thread(name, flags,
  45. mode, neighbor);
  46. fput_light(neighbor, fput_needed);
  47. }
  48. }
  49. else {
  50. ret = spufs_calls.create_thread(name, flags,
  51. mode, NULL);
  52. }
  53. module_put(owner);
  54. }
  55. return ret;
  56. }
  57. asmlinkage long sys_spu_run(int fd, __u32 __user *unpc, __u32 __user *ustatus)
  58. {
  59. long ret;
  60. struct file *filp;
  61. int fput_needed;
  62. struct module *owner = spufs_calls.owner;
  63. ret = -ENOSYS;
  64. if (owner && try_module_get(owner)) {
  65. ret = -EBADF;
  66. filp = fget_light(fd, &fput_needed);
  67. if (filp) {
  68. ret = spufs_calls.spu_run(filp, unpc, ustatus);
  69. fput_light(filp, fput_needed);
  70. }
  71. module_put(owner);
  72. }
  73. return ret;
  74. }
  75. int register_spu_syscalls(struct spufs_calls *calls)
  76. {
  77. if (spufs_calls.owner)
  78. return -EBUSY;
  79. spufs_calls.create_thread = calls->create_thread;
  80. spufs_calls.spu_run = calls->spu_run;
  81. smp_mb();
  82. spufs_calls.owner = calls->owner;
  83. return 0;
  84. }
  85. EXPORT_SYMBOL_GPL(register_spu_syscalls);
  86. void unregister_spu_syscalls(struct spufs_calls *calls)
  87. {
  88. BUG_ON(spufs_calls.owner != calls->owner);
  89. spufs_calls.owner = NULL;
  90. }
  91. EXPORT_SYMBOL_GPL(unregister_spu_syscalls);