spufs.h 5.7 KB

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