spu_syscalls.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*
  2. * SPU file system -- system call stubs
  3. *
  4. * (C) Copyright IBM Deutschland Entwicklung GmbH 2005
  5. * (C) Copyright 2006-2007, IBM Corporation
  6. *
  7. * Author: Arnd Bergmann <arndb@de.ibm.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2, or (at your option)
  12. * any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22. */
  23. #include <linux/file.h>
  24. #include <linux/fs.h>
  25. #include <linux/module.h>
  26. #include <linux/syscalls.h>
  27. #include <linux/rcupdate.h>
  28. #include <asm/spu.h>
  29. /* protected by rcu */
  30. static struct spufs_calls *spufs_calls;
  31. #ifdef CONFIG_SPU_FS_MODULE
  32. static inline struct spufs_calls *spufs_calls_get(void)
  33. {
  34. struct spufs_calls *calls = NULL;
  35. rcu_read_lock();
  36. calls = rcu_dereference(spufs_calls);
  37. if (calls && !try_module_get(calls->owner))
  38. calls = NULL;
  39. rcu_read_unlock();
  40. return calls;
  41. }
  42. static inline void spufs_calls_put(struct spufs_calls *calls)
  43. {
  44. BUG_ON(calls != spufs_calls);
  45. /* we don't need to rcu this, as we hold a reference to the module */
  46. module_put(spufs_calls->owner);
  47. }
  48. #else /* !defined CONFIG_SPU_FS_MODULE */
  49. static inline struct spufs_calls *spufs_calls_get(void)
  50. {
  51. return spufs_calls;
  52. }
  53. static inline void spufs_calls_put(struct spufs_calls *calls) { }
  54. #endif /* CONFIG_SPU_FS_MODULE */
  55. SYSCALL_DEFINE4(spu_create, const char __user *, name, unsigned int, flags,
  56. umode_t, mode, int, neighbor_fd)
  57. {
  58. long ret;
  59. struct file *neighbor;
  60. int fput_needed;
  61. struct spufs_calls *calls;
  62. calls = spufs_calls_get();
  63. if (!calls)
  64. return -ENOSYS;
  65. if (flags & SPU_CREATE_AFFINITY_SPU) {
  66. ret = -EBADF;
  67. neighbor = fget_light(neighbor_fd, &fput_needed);
  68. if (neighbor) {
  69. ret = calls->create_thread(name, flags, mode, neighbor);
  70. fput_light(neighbor, fput_needed);
  71. }
  72. } else
  73. ret = calls->create_thread(name, flags, mode, NULL);
  74. spufs_calls_put(calls);
  75. return ret;
  76. }
  77. asmlinkage long sys_spu_run(int fd, __u32 __user *unpc, __u32 __user *ustatus)
  78. {
  79. long ret;
  80. struct file *filp;
  81. int fput_needed;
  82. struct spufs_calls *calls;
  83. calls = spufs_calls_get();
  84. if (!calls)
  85. return -ENOSYS;
  86. ret = -EBADF;
  87. filp = fget_light(fd, &fput_needed);
  88. if (filp) {
  89. ret = calls->spu_run(filp, unpc, ustatus);
  90. fput_light(filp, fput_needed);
  91. }
  92. spufs_calls_put(calls);
  93. return ret;
  94. }
  95. int elf_coredump_extra_notes_size(void)
  96. {
  97. struct spufs_calls *calls;
  98. int ret;
  99. calls = spufs_calls_get();
  100. if (!calls)
  101. return 0;
  102. ret = calls->coredump_extra_notes_size();
  103. spufs_calls_put(calls);
  104. return ret;
  105. }
  106. int elf_coredump_extra_notes_write(struct file *file, loff_t *foffset)
  107. {
  108. struct spufs_calls *calls;
  109. int ret;
  110. calls = spufs_calls_get();
  111. if (!calls)
  112. return 0;
  113. ret = calls->coredump_extra_notes_write(file, foffset);
  114. spufs_calls_put(calls);
  115. return ret;
  116. }
  117. void notify_spus_active(void)
  118. {
  119. struct spufs_calls *calls;
  120. calls = spufs_calls_get();
  121. if (!calls)
  122. return;
  123. calls->notify_spus_active();
  124. spufs_calls_put(calls);
  125. return;
  126. }
  127. int register_spu_syscalls(struct spufs_calls *calls)
  128. {
  129. if (spufs_calls)
  130. return -EBUSY;
  131. rcu_assign_pointer(spufs_calls, calls);
  132. return 0;
  133. }
  134. EXPORT_SYMBOL_GPL(register_spu_syscalls);
  135. void unregister_spu_syscalls(struct spufs_calls *calls)
  136. {
  137. BUG_ON(spufs_calls->owner != calls->owner);
  138. rcu_assign_pointer(spufs_calls, NULL);
  139. synchronize_rcu();
  140. }
  141. EXPORT_SYMBOL_GPL(unregister_spu_syscalls);