/arch/powerpc/platforms/cell/spufs/spufs.h

http://github.com/mirrors/linux · C Header · 360 lines · 279 code · 48 blank · 33 comment · 4 complexity · c4948c941aded818b978163dbb4f6ddb MD5 · raw file

  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * SPU file system
  4. *
  5. * (C) Copyright IBM Deutschland Entwicklung GmbH 2005
  6. *
  7. * Author: Arnd Bergmann <arndb@de.ibm.com>
  8. */
  9. #ifndef SPUFS_H
  10. #define SPUFS_H
  11. #include <linux/kref.h>
  12. #include <linux/mutex.h>
  13. #include <linux/spinlock.h>
  14. #include <linux/fs.h>
  15. #include <linux/cpumask.h>
  16. #include <linux/sched/signal.h>
  17. #include <asm/spu.h>
  18. #include <asm/spu_csa.h>
  19. #include <asm/spu_info.h>
  20. #define SPUFS_PS_MAP_SIZE 0x20000
  21. #define SPUFS_MFC_MAP_SIZE 0x1000
  22. #define SPUFS_CNTL_MAP_SIZE 0x1000
  23. #define SPUFS_SIGNAL_MAP_SIZE PAGE_SIZE
  24. #define SPUFS_MSS_MAP_SIZE 0x1000
  25. /* The magic number for our file system */
  26. enum {
  27. SPUFS_MAGIC = 0x23c9b64e,
  28. };
  29. struct spu_context_ops;
  30. struct spu_gang;
  31. /* ctx->sched_flags */
  32. enum {
  33. SPU_SCHED_NOTIFY_ACTIVE,
  34. SPU_SCHED_WAS_ACTIVE, /* was active upon spu_acquire_saved() */
  35. SPU_SCHED_SPU_RUN, /* context is within spu_run */
  36. };
  37. enum {
  38. SWITCH_LOG_BUFSIZE = 4096,
  39. };
  40. enum {
  41. SWITCH_LOG_START,
  42. SWITCH_LOG_STOP,
  43. SWITCH_LOG_EXIT,
  44. };
  45. struct switch_log {
  46. wait_queue_head_t wait;
  47. unsigned long head;
  48. unsigned long tail;
  49. struct switch_log_entry {
  50. struct timespec64 tstamp;
  51. s32 spu_id;
  52. u32 type;
  53. u32 val;
  54. u64 timebase;
  55. } log[];
  56. };
  57. struct spu_context {
  58. struct spu *spu; /* pointer to a physical SPU */
  59. struct spu_state csa; /* SPU context save area. */
  60. spinlock_t mmio_lock; /* protects mmio access */
  61. struct address_space *local_store; /* local store mapping. */
  62. struct address_space *mfc; /* 'mfc' area mappings. */
  63. struct address_space *cntl; /* 'control' area mappings. */
  64. struct address_space *signal1; /* 'signal1' area mappings. */
  65. struct address_space *signal2; /* 'signal2' area mappings. */
  66. struct address_space *mss; /* 'mss' area mappings. */
  67. struct address_space *psmap; /* 'psmap' area mappings. */
  68. struct mutex mapping_lock;
  69. u64 object_id; /* user space pointer for oprofile */
  70. enum { SPU_STATE_RUNNABLE, SPU_STATE_SAVED } state;
  71. struct mutex state_mutex;
  72. struct mutex run_mutex;
  73. struct mm_struct *owner;
  74. struct kref kref;
  75. wait_queue_head_t ibox_wq;
  76. wait_queue_head_t wbox_wq;
  77. wait_queue_head_t stop_wq;
  78. wait_queue_head_t mfc_wq;
  79. wait_queue_head_t run_wq;
  80. u32 tagwait;
  81. struct spu_context_ops *ops;
  82. struct work_struct reap_work;
  83. unsigned long flags;
  84. unsigned long event_return;
  85. struct list_head gang_list;
  86. struct spu_gang *gang;
  87. struct kref *prof_priv_kref;
  88. void ( * prof_priv_release) (struct kref *kref);
  89. /* owner thread */
  90. pid_t tid;
  91. /* scheduler fields */
  92. struct list_head rq;
  93. unsigned int time_slice;
  94. unsigned long sched_flags;
  95. cpumask_t cpus_allowed;
  96. int policy;
  97. int prio;
  98. int last_ran;
  99. /* statistics */
  100. struct {
  101. /* updates protected by ctx->state_mutex */
  102. enum spu_utilization_state util_state;
  103. unsigned long long tstamp; /* time of last state switch */
  104. unsigned long long times[SPU_UTIL_MAX];
  105. unsigned long long vol_ctx_switch;
  106. unsigned long long invol_ctx_switch;
  107. unsigned long long min_flt;
  108. unsigned long long maj_flt;
  109. unsigned long long hash_flt;
  110. unsigned long long slb_flt;
  111. unsigned long long slb_flt_base; /* # at last ctx switch */
  112. unsigned long long class2_intr;
  113. unsigned long long class2_intr_base; /* # at last ctx switch */
  114. unsigned long long libassist;
  115. } stats;
  116. /* context switch log */
  117. struct switch_log *switch_log;
  118. struct list_head aff_list;
  119. int aff_head;
  120. int aff_offset;
  121. };
  122. struct spu_gang {
  123. struct list_head list;
  124. struct mutex mutex;
  125. struct kref kref;
  126. int contexts;
  127. struct spu_context *aff_ref_ctx;
  128. struct list_head aff_list_head;
  129. struct mutex aff_mutex;
  130. int aff_flags;
  131. struct spu *aff_ref_spu;
  132. atomic_t aff_sched_count;
  133. };
  134. /* Flag bits for spu_gang aff_flags */
  135. #define AFF_OFFSETS_SET 1
  136. #define AFF_MERGED 2
  137. struct mfc_dma_command {
  138. int32_t pad; /* reserved */
  139. uint32_t lsa; /* local storage address */
  140. uint64_t ea; /* effective address */
  141. uint16_t size; /* transfer size */
  142. uint16_t tag; /* command tag */
  143. uint16_t class; /* class ID */
  144. uint16_t cmd; /* command opcode */
  145. };
  146. /* SPU context query/set operations. */
  147. struct spu_context_ops {
  148. int (*mbox_read) (struct spu_context * ctx, u32 * data);
  149. u32(*mbox_stat_read) (struct spu_context * ctx);
  150. __poll_t (*mbox_stat_poll)(struct spu_context *ctx, __poll_t events);
  151. int (*ibox_read) (struct spu_context * ctx, u32 * data);
  152. int (*wbox_write) (struct spu_context * ctx, u32 data);
  153. u32(*signal1_read) (struct spu_context * ctx);
  154. void (*signal1_write) (struct spu_context * ctx, u32 data);
  155. u32(*signal2_read) (struct spu_context * ctx);
  156. void (*signal2_write) (struct spu_context * ctx, u32 data);
  157. void (*signal1_type_set) (struct spu_context * ctx, u64 val);
  158. u64(*signal1_type_get) (struct spu_context * ctx);
  159. void (*signal2_type_set) (struct spu_context * ctx, u64 val);
  160. u64(*signal2_type_get) (struct spu_context * ctx);
  161. u32(*npc_read) (struct spu_context * ctx);
  162. void (*npc_write) (struct spu_context * ctx, u32 data);
  163. u32(*status_read) (struct spu_context * ctx);
  164. char*(*get_ls) (struct spu_context * ctx);
  165. void (*privcntl_write) (struct spu_context *ctx, u64 data);
  166. u32 (*runcntl_read) (struct spu_context * ctx);
  167. void (*runcntl_write) (struct spu_context * ctx, u32 data);
  168. void (*runcntl_stop) (struct spu_context * ctx);
  169. void (*master_start) (struct spu_context * ctx);
  170. void (*master_stop) (struct spu_context * ctx);
  171. int (*set_mfc_query)(struct spu_context * ctx, u32 mask, u32 mode);
  172. u32 (*read_mfc_tagstatus)(struct spu_context * ctx);
  173. u32 (*get_mfc_free_elements)(struct spu_context *ctx);
  174. int (*send_mfc_command)(struct spu_context * ctx,
  175. struct mfc_dma_command * cmd);
  176. void (*dma_info_read) (struct spu_context * ctx,
  177. struct spu_dma_info * info);
  178. void (*proxydma_info_read) (struct spu_context * ctx,
  179. struct spu_proxydma_info * info);
  180. void (*restart_dma)(struct spu_context *ctx);
  181. };
  182. extern struct spu_context_ops spu_hw_ops;
  183. extern struct spu_context_ops spu_backing_ops;
  184. struct spufs_inode_info {
  185. struct spu_context *i_ctx;
  186. struct spu_gang *i_gang;
  187. struct inode vfs_inode;
  188. int i_openers;
  189. };
  190. #define SPUFS_I(inode) \
  191. container_of(inode, struct spufs_inode_info, vfs_inode)
  192. struct spufs_tree_descr {
  193. const char *name;
  194. const struct file_operations *ops;
  195. umode_t mode;
  196. size_t size;
  197. };
  198. extern const struct spufs_tree_descr spufs_dir_contents[];
  199. extern const struct spufs_tree_descr spufs_dir_nosched_contents[];
  200. extern const struct spufs_tree_descr spufs_dir_debug_contents[];
  201. /* system call implementation */
  202. extern struct spufs_calls spufs_calls;
  203. struct coredump_params;
  204. long spufs_run_spu(struct spu_context *ctx, u32 *npc, u32 *status);
  205. long spufs_create(struct path *nd, struct dentry *dentry, unsigned int flags,
  206. umode_t mode, struct file *filp);
  207. /* ELF coredump callbacks for writing SPU ELF notes */
  208. extern int spufs_coredump_extra_notes_size(void);
  209. extern int spufs_coredump_extra_notes_write(struct coredump_params *cprm);
  210. extern const struct file_operations spufs_context_fops;
  211. /* gang management */
  212. struct spu_gang *alloc_spu_gang(void);
  213. struct spu_gang *get_spu_gang(struct spu_gang *gang);
  214. int put_spu_gang(struct spu_gang *gang);
  215. void spu_gang_remove_ctx(struct spu_gang *gang, struct spu_context *ctx);
  216. void spu_gang_add_ctx(struct spu_gang *gang, struct spu_context *ctx);
  217. /* fault handling */
  218. int spufs_handle_class1(struct spu_context *ctx);
  219. int spufs_handle_class0(struct spu_context *ctx);
  220. /* affinity */
  221. struct spu *affinity_check(struct spu_context *ctx);
  222. /* context management */
  223. extern atomic_t nr_spu_contexts;
  224. static inline int __must_check spu_acquire(struct spu_context *ctx)
  225. {
  226. return mutex_lock_interruptible(&ctx->state_mutex);
  227. }
  228. static inline void spu_release(struct spu_context *ctx)
  229. {
  230. mutex_unlock(&ctx->state_mutex);
  231. }
  232. struct spu_context * alloc_spu_context(struct spu_gang *gang);
  233. void destroy_spu_context(struct kref *kref);
  234. struct spu_context * get_spu_context(struct spu_context *ctx);
  235. int put_spu_context(struct spu_context *ctx);
  236. void spu_unmap_mappings(struct spu_context *ctx);
  237. void spu_forget(struct spu_context *ctx);
  238. int __must_check spu_acquire_saved(struct spu_context *ctx);
  239. void spu_release_saved(struct spu_context *ctx);
  240. int spu_stopped(struct spu_context *ctx, u32 * stat);
  241. void spu_del_from_rq(struct spu_context *ctx);
  242. int spu_activate(struct spu_context *ctx, unsigned long flags);
  243. void spu_deactivate(struct spu_context *ctx);
  244. void spu_yield(struct spu_context *ctx);
  245. void spu_switch_notify(struct spu *spu, struct spu_context *ctx);
  246. void spu_switch_log_notify(struct spu *spu, struct spu_context *ctx,
  247. u32 type, u32 val);
  248. void spu_set_timeslice(struct spu_context *ctx);
  249. void spu_update_sched_info(struct spu_context *ctx);
  250. void __spu_update_sched_info(struct spu_context *ctx);
  251. int __init spu_sched_init(void);
  252. void spu_sched_exit(void);
  253. extern char *isolated_loader;
  254. /*
  255. * spufs_wait
  256. * Same as wait_event_interruptible(), except that here
  257. * we need to call spu_release(ctx) before sleeping, and
  258. * then spu_acquire(ctx) when awoken.
  259. *
  260. * Returns with state_mutex re-acquired when successful or
  261. * with -ERESTARTSYS and the state_mutex dropped when interrupted.
  262. */
  263. #define spufs_wait(wq, condition) \
  264. ({ \
  265. int __ret = 0; \
  266. DEFINE_WAIT(__wait); \
  267. for (;;) { \
  268. prepare_to_wait(&(wq), &__wait, TASK_INTERRUPTIBLE); \
  269. if (condition) \
  270. break; \
  271. spu_release(ctx); \
  272. if (signal_pending(current)) { \
  273. __ret = -ERESTARTSYS; \
  274. break; \
  275. } \
  276. schedule(); \
  277. __ret = spu_acquire(ctx); \
  278. if (__ret) \
  279. break; \
  280. } \
  281. finish_wait(&(wq), &__wait); \
  282. __ret; \
  283. })
  284. size_t spu_wbox_write(struct spu_context *ctx, u32 data);
  285. size_t spu_ibox_read(struct spu_context *ctx, u32 *data);
  286. /* irq callback funcs. */
  287. void spufs_ibox_callback(struct spu *spu);
  288. void spufs_wbox_callback(struct spu *spu);
  289. void spufs_stop_callback(struct spu *spu, int irq);
  290. void spufs_mfc_callback(struct spu *spu);
  291. void spufs_dma_callback(struct spu *spu, int type);
  292. extern struct spu_coredump_calls spufs_coredump_calls;
  293. struct spufs_coredump_reader {
  294. char *name;
  295. ssize_t (*read)(struct spu_context *ctx,
  296. char __user *buffer, size_t size, loff_t *pos);
  297. u64 (*get)(struct spu_context *ctx);
  298. size_t size;
  299. };
  300. extern const struct spufs_coredump_reader spufs_coredump_read[];
  301. extern int spufs_coredump_num_notes;
  302. extern int spu_init_csa(struct spu_state *csa);
  303. extern void spu_fini_csa(struct spu_state *csa);
  304. extern int spu_save(struct spu_state *prev, struct spu *spu);
  305. extern int spu_restore(struct spu_state *new, struct spu *spu);
  306. extern int spu_switch(struct spu_state *prev, struct spu_state *new,
  307. struct spu *spu);
  308. extern int spu_alloc_lscsa(struct spu_state *csa);
  309. extern void spu_free_lscsa(struct spu_state *csa);
  310. extern void spuctx_switch_state(struct spu_context *ctx,
  311. enum spu_utilization_state new_state);
  312. #endif