spufs.h 6.5 KB

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