spufs.h 7.9 KB

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