spufs.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /*
  2. * SPU file system
  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. #ifndef SPUFS_H
  23. #define SPUFS_H
  24. #include <linux/kref.h>
  25. #include <linux/rwsem.h>
  26. #include <linux/spinlock.h>
  27. #include <linux/fs.h>
  28. #include <asm/spu.h>
  29. #include <asm/spu_csa.h>
  30. #include <asm/spu_info.h>
  31. /* The magic number for our file system */
  32. enum {
  33. SPUFS_MAGIC = 0x23c9b64e,
  34. };
  35. struct spu_context_ops;
  36. #define SPU_CONTEXT_PREEMPT 0UL
  37. struct spu_gang;
  38. struct spu_context {
  39. struct spu *spu; /* pointer to a physical SPU */
  40. struct spu_state csa; /* SPU context save area. */
  41. spinlock_t mmio_lock; /* protects mmio access */
  42. struct address_space *local_store; /* local store mapping. */
  43. struct address_space *mfc; /* 'mfc' area mappings. */
  44. struct address_space *cntl; /* 'control' area mappings. */
  45. struct address_space *signal1; /* 'signal1' area mappings. */
  46. struct address_space *signal2; /* 'signal2' area mappings. */
  47. u64 object_id; /* user space pointer for oprofile */
  48. enum { SPU_STATE_RUNNABLE, SPU_STATE_SAVED } state;
  49. struct rw_semaphore state_sema;
  50. struct semaphore run_sema;
  51. struct mm_struct *owner;
  52. struct kref kref;
  53. wait_queue_head_t ibox_wq;
  54. wait_queue_head_t wbox_wq;
  55. wait_queue_head_t stop_wq;
  56. wait_queue_head_t mfc_wq;
  57. struct fasync_struct *ibox_fasync;
  58. struct fasync_struct *wbox_fasync;
  59. struct fasync_struct *mfc_fasync;
  60. u32 tagwait;
  61. struct spu_context_ops *ops;
  62. struct work_struct reap_work;
  63. unsigned long flags;
  64. unsigned long event_return;
  65. struct list_head gang_list;
  66. struct spu_gang *gang;
  67. };
  68. struct spu_gang {
  69. struct list_head list;
  70. struct mutex mutex;
  71. struct kref kref;
  72. int contexts;
  73. };
  74. struct mfc_dma_command {
  75. int32_t pad; /* reserved */
  76. uint32_t lsa; /* local storage address */
  77. uint64_t ea; /* effective address */
  78. uint16_t size; /* transfer size */
  79. uint16_t tag; /* command tag */
  80. uint16_t class; /* class ID */
  81. uint16_t cmd; /* command opcode */
  82. };
  83. /* SPU context query/set operations. */
  84. struct spu_context_ops {
  85. int (*mbox_read) (struct spu_context * ctx, u32 * data);
  86. u32(*mbox_stat_read) (struct spu_context * ctx);
  87. unsigned int (*mbox_stat_poll)(struct spu_context *ctx,
  88. unsigned int events);
  89. int (*ibox_read) (struct spu_context * ctx, u32 * data);
  90. int (*wbox_write) (struct spu_context * ctx, u32 data);
  91. u32(*signal1_read) (struct spu_context * ctx);
  92. void (*signal1_write) (struct spu_context * ctx, u32 data);
  93. u32(*signal2_read) (struct spu_context * ctx);
  94. void (*signal2_write) (struct spu_context * ctx, u32 data);
  95. void (*signal1_type_set) (struct spu_context * ctx, u64 val);
  96. u64(*signal1_type_get) (struct spu_context * ctx);
  97. void (*signal2_type_set) (struct spu_context * ctx, u64 val);
  98. u64(*signal2_type_get) (struct spu_context * ctx);
  99. u32(*npc_read) (struct spu_context * ctx);
  100. void (*npc_write) (struct spu_context * ctx, u32 data);
  101. u32(*status_read) (struct spu_context * ctx);
  102. char*(*get_ls) (struct spu_context * ctx);
  103. u32 (*runcntl_read) (struct spu_context * ctx);
  104. void (*runcntl_write) (struct spu_context * ctx, u32 data);
  105. void (*master_start) (struct spu_context * ctx);
  106. void (*master_stop) (struct spu_context * ctx);
  107. int (*set_mfc_query)(struct spu_context * ctx, u32 mask, u32 mode);
  108. u32 (*read_mfc_tagstatus)(struct spu_context * ctx);
  109. u32 (*get_mfc_free_elements)(struct spu_context *ctx);
  110. int (*send_mfc_command)(struct spu_context * ctx,
  111. struct mfc_dma_command * cmd);
  112. void (*dma_info_read) (struct spu_context * ctx,
  113. struct spu_dma_info * info);
  114. void (*proxydma_info_read) (struct spu_context * ctx,
  115. struct spu_proxydma_info * info);
  116. };
  117. extern struct spu_context_ops spu_hw_ops;
  118. extern struct spu_context_ops spu_backing_ops;
  119. struct spufs_inode_info {
  120. struct spu_context *i_ctx;
  121. struct spu_gang *i_gang;
  122. struct inode vfs_inode;
  123. };
  124. #define SPUFS_I(inode) \
  125. container_of(inode, struct spufs_inode_info, vfs_inode)
  126. extern struct tree_descr spufs_dir_contents[];
  127. extern struct tree_descr spufs_dir_nosched_contents[];
  128. /* system call implementation */
  129. long spufs_run_spu(struct file *file,
  130. struct spu_context *ctx, u32 *npc, u32 *status);
  131. long spufs_create(struct nameidata *nd,
  132. unsigned int flags, mode_t mode);
  133. extern struct file_operations spufs_context_fops;
  134. /* gang management */
  135. struct spu_gang *alloc_spu_gang(void);
  136. struct spu_gang *get_spu_gang(struct spu_gang *gang);
  137. int put_spu_gang(struct spu_gang *gang);
  138. void spu_gang_remove_ctx(struct spu_gang *gang, struct spu_context *ctx);
  139. void spu_gang_add_ctx(struct spu_gang *gang, struct spu_context *ctx);
  140. /* context management */
  141. struct spu_context * alloc_spu_context(struct spu_gang *gang);
  142. void destroy_spu_context(struct kref *kref);
  143. struct spu_context * get_spu_context(struct spu_context *ctx);
  144. int put_spu_context(struct spu_context *ctx);
  145. void spu_unmap_mappings(struct spu_context *ctx);
  146. void spu_forget(struct spu_context *ctx);
  147. void spu_acquire(struct spu_context *ctx);
  148. void spu_release(struct spu_context *ctx);
  149. int spu_acquire_runnable(struct spu_context *ctx);
  150. void spu_acquire_saved(struct spu_context *ctx);
  151. int spu_acquire_exclusive(struct spu_context *ctx);
  152. static inline void spu_release_exclusive(struct spu_context *ctx)
  153. {
  154. up_write(&ctx->state_sema);
  155. }
  156. int spu_activate(struct spu_context *ctx, u64 flags);
  157. void spu_deactivate(struct spu_context *ctx);
  158. void spu_yield(struct spu_context *ctx);
  159. int __init spu_sched_init(void);
  160. void __exit spu_sched_exit(void);
  161. extern char *isolated_loader;
  162. /*
  163. * spufs_wait
  164. * Same as wait_event_interruptible(), except that here
  165. * we need to call spu_release(ctx) before sleeping, and
  166. * then spu_acquire(ctx) when awoken.
  167. */
  168. #define spufs_wait(wq, condition) \
  169. ({ \
  170. int __ret = 0; \
  171. DEFINE_WAIT(__wait); \
  172. for (;;) { \
  173. prepare_to_wait(&(wq), &__wait, TASK_INTERRUPTIBLE); \
  174. if (condition) \
  175. break; \
  176. if (!signal_pending(current)) { \
  177. spu_release(ctx); \
  178. schedule(); \
  179. spu_acquire(ctx); \
  180. continue; \
  181. } \
  182. __ret = -ERESTARTSYS; \
  183. break; \
  184. } \
  185. finish_wait(&(wq), &__wait); \
  186. __ret; \
  187. })
  188. size_t spu_wbox_write(struct spu_context *ctx, u32 data);
  189. size_t spu_ibox_read(struct spu_context *ctx, u32 *data);
  190. /* irq callback funcs. */
  191. void spufs_ibox_callback(struct spu *spu);
  192. void spufs_wbox_callback(struct spu *spu);
  193. void spufs_stop_callback(struct spu *spu);
  194. void spufs_mfc_callback(struct spu *spu);
  195. void spufs_dma_callback(struct spu *spu, int type);
  196. extern struct spu_coredump_calls spufs_coredump_calls;
  197. struct spufs_coredump_reader {
  198. char *name;
  199. ssize_t (*read)(struct spu_context *ctx,
  200. char __user *buffer, size_t size, loff_t *pos);
  201. u64 (*get)(void *data);
  202. size_t size;
  203. };
  204. extern struct spufs_coredump_reader spufs_coredump_read[];
  205. extern int spufs_coredump_num_notes;
  206. #endif