spufs.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. struct fasync_struct *ibox_fasync;
  50. struct fasync_struct *wbox_fasync;
  51. struct spu_context_ops *ops;
  52. struct work_struct reap_work;
  53. u64 flags;
  54. };
  55. /* SPU context query/set operations. */
  56. struct spu_context_ops {
  57. int (*mbox_read) (struct spu_context * ctx, u32 * data);
  58. u32(*mbox_stat_read) (struct spu_context * ctx);
  59. unsigned int (*mbox_stat_poll)(struct spu_context *ctx,
  60. unsigned int events);
  61. int (*ibox_read) (struct spu_context * ctx, u32 * data);
  62. int (*wbox_write) (struct spu_context * ctx, u32 data);
  63. u32(*signal1_read) (struct spu_context * ctx);
  64. void (*signal1_write) (struct spu_context * ctx, u32 data);
  65. u32(*signal2_read) (struct spu_context * ctx);
  66. void (*signal2_write) (struct spu_context * ctx, u32 data);
  67. void (*signal1_type_set) (struct spu_context * ctx, u64 val);
  68. u64(*signal1_type_get) (struct spu_context * ctx);
  69. void (*signal2_type_set) (struct spu_context * ctx, u64 val);
  70. u64(*signal2_type_get) (struct spu_context * ctx);
  71. u32(*npc_read) (struct spu_context * ctx);
  72. void (*npc_write) (struct spu_context * ctx, u32 data);
  73. u32(*status_read) (struct spu_context * ctx);
  74. char*(*get_ls) (struct spu_context * ctx);
  75. void (*runcntl_write) (struct spu_context * ctx, u32 data);
  76. void (*runcntl_stop) (struct spu_context * ctx);
  77. };
  78. extern struct spu_context_ops spu_hw_ops;
  79. extern struct spu_context_ops spu_backing_ops;
  80. struct spufs_inode_info {
  81. struct spu_context *i_ctx;
  82. struct inode vfs_inode;
  83. };
  84. #define SPUFS_I(inode) \
  85. container_of(inode, struct spufs_inode_info, vfs_inode)
  86. extern struct tree_descr spufs_dir_contents[];
  87. /* system call implementation */
  88. long spufs_run_spu(struct file *file,
  89. struct spu_context *ctx, u32 *npc, u32 *status);
  90. long spufs_create_thread(struct nameidata *nd,
  91. unsigned int flags, mode_t mode);
  92. extern struct file_operations spufs_context_fops;
  93. /* context management */
  94. struct spu_context * alloc_spu_context(struct address_space *local_store);
  95. void destroy_spu_context(struct kref *kref);
  96. struct spu_context * get_spu_context(struct spu_context *ctx);
  97. int put_spu_context(struct spu_context *ctx);
  98. void spu_unmap_mappings(struct spu_context *ctx);
  99. void spu_forget(struct spu_context *ctx);
  100. void spu_acquire(struct spu_context *ctx);
  101. void spu_release(struct spu_context *ctx);
  102. int spu_acquire_runnable(struct spu_context *ctx);
  103. void spu_acquire_saved(struct spu_context *ctx);
  104. int spu_activate(struct spu_context *ctx, u64 flags);
  105. void spu_deactivate(struct spu_context *ctx);
  106. void spu_yield(struct spu_context *ctx);
  107. int __init spu_sched_init(void);
  108. void __exit spu_sched_exit(void);
  109. /*
  110. * spufs_wait
  111. * Same as wait_event_interruptible(), except that here
  112. * we need to call spu_release(ctx) before sleeping, and
  113. * then spu_acquire(ctx) when awoken.
  114. */
  115. #define spufs_wait(wq, condition) \
  116. ({ \
  117. int __ret = 0; \
  118. DEFINE_WAIT(__wait); \
  119. for (;;) { \
  120. prepare_to_wait(&(wq), &__wait, TASK_INTERRUPTIBLE); \
  121. if (condition) \
  122. break; \
  123. if (!signal_pending(current)) { \
  124. spu_release(ctx); \
  125. schedule(); \
  126. spu_acquire(ctx); \
  127. continue; \
  128. } \
  129. __ret = -ERESTARTSYS; \
  130. break; \
  131. } \
  132. finish_wait(&(wq), &__wait); \
  133. __ret; \
  134. })
  135. size_t spu_wbox_write(struct spu_context *ctx, u32 data);
  136. size_t spu_ibox_read(struct spu_context *ctx, u32 *data);
  137. /* irq callback funcs. */
  138. void spufs_ibox_callback(struct spu *spu);
  139. void spufs_wbox_callback(struct spu *spu);
  140. void spufs_stop_callback(struct spu *spu);
  141. #endif