blob: 57d687ca3f038a091c8b643b65974ba3250dc7ca [file] [log] [blame]
Arnd Bergmann67207b92005-11-15 15:53:48 -05001/*
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
25#include <linux/kref.h>
26#include <linux/rwsem.h>
27#include <linux/spinlock.h>
28#include <linux/fs.h>
29
30#include <asm/spu.h>
Mark Nutter5473af02005-11-15 15:53:49 -050031#include <asm/spu_csa.h>
Arnd Bergmann67207b92005-11-15 15:53:48 -050032
33/* The magic number for our file system */
34enum {
35 SPUFS_MAGIC = 0x23c9b64e,
36};
37
Arnd Bergmann8b3d6662005-11-15 15:53:52 -050038struct spu_context_ops;
39
Arnd Bergmann8837d922006-01-04 20:31:28 +010040#define SPU_CONTEXT_PREEMPT 0UL
Arnd Bergmann2a911f02005-12-05 22:52:26 -050041
Arnd Bergmann67207b92005-11-15 15:53:48 -050042struct spu_context {
43 struct spu *spu; /* pointer to a physical SPU */
Mark Nutter5473af02005-11-15 15:53:49 -050044 struct spu_state csa; /* SPU context save area. */
Arnd Bergmann67207b92005-11-15 15:53:48 -050045 spinlock_t mmio_lock; /* protects mmio access */
Arnd Bergmann8b3d6662005-11-15 15:53:52 -050046 struct address_space *local_store;/* local store backing store */
47
48 enum { SPU_STATE_RUNNABLE, SPU_STATE_SAVED } state;
49 struct rw_semaphore state_sema;
Arnd Bergmann5ef82242006-01-04 20:31:24 +010050 struct semaphore run_sema;
Arnd Bergmann8b3d6662005-11-15 15:53:52 -050051
52 struct mm_struct *owner;
Arnd Bergmann67207b92005-11-15 15:53:48 -050053
54 struct kref kref;
Arnd Bergmann8b3d6662005-11-15 15:53:52 -050055 wait_queue_head_t ibox_wq;
56 wait_queue_head_t wbox_wq;
Arnd Bergmann51104592005-12-05 22:52:25 -050057 wait_queue_head_t stop_wq;
Arnd Bergmanna33a7d72006-03-23 00:00:11 +010058 wait_queue_head_t mfc_wq;
Arnd Bergmann8b3d6662005-11-15 15:53:52 -050059 struct fasync_struct *ibox_fasync;
60 struct fasync_struct *wbox_fasync;
Arnd Bergmanna33a7d72006-03-23 00:00:11 +010061 struct fasync_struct *mfc_fasync;
62 u32 tagwait;
Arnd Bergmann8b3d6662005-11-15 15:53:52 -050063 struct spu_context_ops *ops;
Arnd Bergmann2a911f02005-12-05 22:52:26 -050064 struct work_struct reap_work;
65 u64 flags;
Arnd Bergmann67207b92005-11-15 15:53:48 -050066};
67
Arnd Bergmanna33a7d72006-03-23 00:00:11 +010068struct mfc_dma_command {
69 int32_t pad; /* reserved */
70 uint32_t lsa; /* local storage address */
71 uint64_t ea; /* effective address */
72 uint16_t size; /* transfer size */
73 uint16_t tag; /* command tag */
74 uint16_t class; /* class ID */
75 uint16_t cmd; /* command opcode */
76};
77
78
Arnd Bergmann8b3d6662005-11-15 15:53:52 -050079/* SPU context query/set operations. */
80struct spu_context_ops {
81 int (*mbox_read) (struct spu_context * ctx, u32 * data);
82 u32(*mbox_stat_read) (struct spu_context * ctx);
Arnd Bergmann3a843d72005-12-05 22:52:27 -050083 unsigned int (*mbox_stat_poll)(struct spu_context *ctx,
84 unsigned int events);
Arnd Bergmann8b3d6662005-11-15 15:53:52 -050085 int (*ibox_read) (struct spu_context * ctx, u32 * data);
86 int (*wbox_write) (struct spu_context * ctx, u32 data);
87 u32(*signal1_read) (struct spu_context * ctx);
88 void (*signal1_write) (struct spu_context * ctx, u32 data);
89 u32(*signal2_read) (struct spu_context * ctx);
90 void (*signal2_write) (struct spu_context * ctx, u32 data);
91 void (*signal1_type_set) (struct spu_context * ctx, u64 val);
92 u64(*signal1_type_get) (struct spu_context * ctx);
93 void (*signal2_type_set) (struct spu_context * ctx, u64 val);
94 u64(*signal2_type_get) (struct spu_context * ctx);
95 u32(*npc_read) (struct spu_context * ctx);
96 void (*npc_write) (struct spu_context * ctx, u32 data);
97 u32(*status_read) (struct spu_context * ctx);
98 char*(*get_ls) (struct spu_context * ctx);
Arnd Bergmann51104592005-12-05 22:52:25 -050099 void (*runcntl_write) (struct spu_context * ctx, u32 data);
100 void (*runcntl_stop) (struct spu_context * ctx);
Arnd Bergmanna33a7d72006-03-23 00:00:11 +0100101 int (*set_mfc_query)(struct spu_context * ctx, u32 mask, u32 mode);
102 u32 (*read_mfc_tagstatus)(struct spu_context * ctx);
103 u32 (*get_mfc_free_elements)(struct spu_context *ctx);
104 int (*send_mfc_command)(struct spu_context *ctx,
105 struct mfc_dma_command *cmd);
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500106};
107
108extern struct spu_context_ops spu_hw_ops;
109extern struct spu_context_ops spu_backing_ops;
110
Arnd Bergmann67207b92005-11-15 15:53:48 -0500111struct spufs_inode_info {
112 struct spu_context *i_ctx;
113 struct inode vfs_inode;
114};
115#define SPUFS_I(inode) \
116 container_of(inode, struct spufs_inode_info, vfs_inode)
117
118extern struct tree_descr spufs_dir_contents[];
119
120/* system call implementation */
121long spufs_run_spu(struct file *file,
122 struct spu_context *ctx, u32 *npc, u32 *status);
Arnd Bergmann6ff730c2006-01-04 20:31:31 +0100123long spufs_create_thread(struct nameidata *nd,
Arnd Bergmann67207b92005-11-15 15:53:48 -0500124 unsigned int flags, mode_t mode);
Arnd Bergmanne80358a2006-01-04 20:31:23 +0100125extern struct file_operations spufs_context_fops;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500126
127/* context management */
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500128struct spu_context * alloc_spu_context(struct address_space *local_store);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500129void destroy_spu_context(struct kref *kref);
130struct spu_context * get_spu_context(struct spu_context *ctx);
131int put_spu_context(struct spu_context *ctx);
Arnd Bergmann51104592005-12-05 22:52:25 -0500132void spu_unmap_mappings(struct spu_context *ctx);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500133
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500134void spu_forget(struct spu_context *ctx);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500135void spu_acquire(struct spu_context *ctx);
136void spu_release(struct spu_context *ctx);
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500137int spu_acquire_runnable(struct spu_context *ctx);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500138void spu_acquire_saved(struct spu_context *ctx);
139
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500140int spu_activate(struct spu_context *ctx, u64 flags);
141void spu_deactivate(struct spu_context *ctx);
142void spu_yield(struct spu_context *ctx);
143int __init spu_sched_init(void);
144void __exit spu_sched_exit(void);
145
Arnd Bergmannce8ab852006-01-04 20:31:29 +0100146/*
147 * spufs_wait
148 * Same as wait_event_interruptible(), except that here
149 * we need to call spu_release(ctx) before sleeping, and
150 * then spu_acquire(ctx) when awoken.
151 */
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
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500174size_t spu_wbox_write(struct spu_context *ctx, u32 data);
175size_t spu_ibox_read(struct spu_context *ctx, u32 *data);
176
177/* irq callback funcs. */
178void spufs_ibox_callback(struct spu *spu);
179void spufs_wbox_callback(struct spu *spu);
Arnd Bergmann51104592005-12-05 22:52:25 -0500180void spufs_stop_callback(struct spu *spu);
Arnd Bergmanna33a7d72006-03-23 00:00:11 +0100181void spufs_mfc_callback(struct spu *spu);
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500182
Arnd Bergmann67207b92005-11-15 15:53:48 -0500183#endif