spu_syscalls.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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)
  34. {
  35. long ret;
  36. struct module *owner = spufs_calls.owner;
  37. ret = -ENOSYS;
  38. if (owner && try_module_get(owner)) {
  39. ret = spufs_calls.create_thread(name, flags, mode);
  40. module_put(owner);
  41. }
  42. return ret;
  43. }
  44. asmlinkage long sys_spu_run(int fd, __u32 __user *unpc, __u32 __user *ustatus)
  45. {
  46. long ret;
  47. struct file *filp;
  48. int fput_needed;
  49. struct module *owner = spufs_calls.owner;
  50. ret = -ENOSYS;
  51. if (owner && try_module_get(owner)) {
  52. ret = -EBADF;
  53. filp = fget_light(fd, &fput_needed);
  54. if (filp) {
  55. ret = spufs_calls.spu_run(filp, unpc, ustatus);
  56. fput_light(filp, fput_needed);
  57. }
  58. module_put(owner);
  59. }
  60. return ret;
  61. }
  62. int register_spu_syscalls(struct spufs_calls *calls)
  63. {
  64. if (spufs_calls.owner)
  65. return -EBUSY;
  66. spufs_calls.create_thread = calls->create_thread;
  67. spufs_calls.spu_run = calls->spu_run;
  68. smp_mb();
  69. spufs_calls.owner = calls->owner;
  70. return 0;
  71. }
  72. EXPORT_SYMBOL_GPL(register_spu_syscalls);
  73. void unregister_spu_syscalls(struct spufs_calls *calls)
  74. {
  75. BUG_ON(spufs_calls.owner != calls->owner);
  76. spufs_calls.owner = NULL;
  77. }
  78. EXPORT_SYMBOL_GPL(unregister_spu_syscalls);