]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame_incremental - arch/powerpc/platforms/cell/spufs/spufs.h
[CELL] add support for MSI on Axon-based Cell systems
[mirror_ubuntu-hirsute-kernel.git] / arch / powerpc / platforms / cell / spufs / spufs.h
... / ...
CommitLineData
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
25#include <linux/kref.h>
26#include <linux/mutex.h>
27#include <linux/spinlock.h>
28#include <linux/fs.h>
29#include <linux/cpumask.h>
30
31#include <asm/spu.h>
32#include <asm/spu_csa.h>
33#include <asm/spu_info.h>
34
35/* The magic number for our file system */
36enum {
37 SPUFS_MAGIC = 0x23c9b64e,
38};
39
40struct spu_context_ops;
41struct spu_gang;
42
43/*
44 * This is the state for spu utilization reporting to userspace.
45 * Because this state is visible to userspace it must never change and needs
46 * to be kept strictly separate from any internal state kept by the kernel.
47 */
48enum spuctx_execution_state {
49 SPUCTX_UTIL_USER = 0,
50 SPUCTX_UTIL_SYSTEM,
51 SPUCTX_UTIL_IOWAIT,
52 SPUCTX_UTIL_LOADED,
53 SPUCTX_UTIL_MAX
54};
55
56struct spu_context {
57 struct spu *spu; /* pointer to a physical SPU */
58 struct spu_state csa; /* SPU context save area. */
59 spinlock_t mmio_lock; /* protects mmio access */
60 struct address_space *local_store; /* local store mapping. */
61 struct address_space *mfc; /* 'mfc' area mappings. */
62 struct address_space *cntl; /* 'control' area mappings. */
63 struct address_space *signal1; /* 'signal1' area mappings. */
64 struct address_space *signal2; /* 'signal2' area mappings. */
65 struct address_space *mss; /* 'mss' area mappings. */
66 struct address_space *psmap; /* 'psmap' area mappings. */
67 struct mutex mapping_lock;
68 u64 object_id; /* user space pointer for oprofile */
69
70 enum { SPU_STATE_RUNNABLE, SPU_STATE_SAVED } state;
71 struct mutex state_mutex;
72 struct mutex run_mutex;
73
74 struct mm_struct *owner;
75
76 struct kref kref;
77 wait_queue_head_t ibox_wq;
78 wait_queue_head_t wbox_wq;
79 wait_queue_head_t stop_wq;
80 wait_queue_head_t mfc_wq;
81 struct fasync_struct *ibox_fasync;
82 struct fasync_struct *wbox_fasync;
83 struct fasync_struct *mfc_fasync;
84 u32 tagwait;
85 struct spu_context_ops *ops;
86 struct work_struct reap_work;
87 unsigned long flags;
88 unsigned long event_return;
89
90 struct list_head gang_list;
91 struct spu_gang *gang;
92
93 /* owner thread */
94 pid_t tid;
95
96 /* scheduler fields */
97 struct list_head rq;
98 unsigned int time_slice;
99 unsigned long sched_flags;
100 cpumask_t cpus_allowed;
101 int policy;
102 int prio;
103
104 /* statistics */
105 struct {
106 /* updates protected by ctx->state_mutex */
107 enum spuctx_execution_state execution_state;
108 unsigned long tstamp; /* time of last ctx switch */
109 unsigned long times[SPUCTX_UTIL_MAX];
110 unsigned long long vol_ctx_switch;
111 unsigned long long invol_ctx_switch;
112 unsigned long long min_flt;
113 unsigned long long maj_flt;
114 unsigned long long hash_flt;
115 unsigned long long slb_flt;
116 unsigned long long slb_flt_base; /* # at last ctx switch */
117 unsigned long long class2_intr;
118 unsigned long long class2_intr_base; /* # at last ctx switch */
119 unsigned long long libassist;
120 } stats;
121};
122
123struct spu_gang {
124 struct list_head list;
125 struct mutex mutex;
126 struct kref kref;
127 int contexts;
128};
129
130struct mfc_dma_command {
131 int32_t pad; /* reserved */
132 uint32_t lsa; /* local storage address */
133 uint64_t ea; /* effective address */
134 uint16_t size; /* transfer size */
135 uint16_t tag; /* command tag */
136 uint16_t class; /* class ID */
137 uint16_t cmd; /* command opcode */
138};
139
140
141/* SPU context query/set operations. */
142struct spu_context_ops {
143 int (*mbox_read) (struct spu_context * ctx, u32 * data);
144 u32(*mbox_stat_read) (struct spu_context * ctx);
145 unsigned int (*mbox_stat_poll)(struct spu_context *ctx,
146 unsigned int events);
147 int (*ibox_read) (struct spu_context * ctx, u32 * data);
148 int (*wbox_write) (struct spu_context * ctx, u32 data);
149 u32(*signal1_read) (struct spu_context * ctx);
150 void (*signal1_write) (struct spu_context * ctx, u32 data);
151 u32(*signal2_read) (struct spu_context * ctx);
152 void (*signal2_write) (struct spu_context * ctx, u32 data);
153 void (*signal1_type_set) (struct spu_context * ctx, u64 val);
154 u64(*signal1_type_get) (struct spu_context * ctx);
155 void (*signal2_type_set) (struct spu_context * ctx, u64 val);
156 u64(*signal2_type_get) (struct spu_context * ctx);
157 u32(*npc_read) (struct spu_context * ctx);
158 void (*npc_write) (struct spu_context * ctx, u32 data);
159 u32(*status_read) (struct spu_context * ctx);
160 char*(*get_ls) (struct spu_context * ctx);
161 u32 (*runcntl_read) (struct spu_context * ctx);
162 void (*runcntl_write) (struct spu_context * ctx, u32 data);
163 void (*master_start) (struct spu_context * ctx);
164 void (*master_stop) (struct spu_context * ctx);
165 int (*set_mfc_query)(struct spu_context * ctx, u32 mask, u32 mode);
166 u32 (*read_mfc_tagstatus)(struct spu_context * ctx);
167 u32 (*get_mfc_free_elements)(struct spu_context *ctx);
168 int (*send_mfc_command)(struct spu_context * ctx,
169 struct mfc_dma_command * cmd);
170 void (*dma_info_read) (struct spu_context * ctx,
171 struct spu_dma_info * info);
172 void (*proxydma_info_read) (struct spu_context * ctx,
173 struct spu_proxydma_info * info);
174 void (*restart_dma)(struct spu_context *ctx);
175};
176
177extern struct spu_context_ops spu_hw_ops;
178extern struct spu_context_ops spu_backing_ops;
179
180struct spufs_inode_info {
181 struct spu_context *i_ctx;
182 struct spu_gang *i_gang;
183 struct inode vfs_inode;
184 int i_openers;
185};
186#define SPUFS_I(inode) \
187 container_of(inode, struct spufs_inode_info, vfs_inode)
188
189extern struct tree_descr spufs_dir_contents[];
190extern struct tree_descr spufs_dir_nosched_contents[];
191
192/* system call implementation */
193long spufs_run_spu(struct file *file,
194 struct spu_context *ctx, u32 *npc, u32 *status);
195long spufs_create(struct nameidata *nd,
196 unsigned int flags, mode_t mode);
197extern const struct file_operations spufs_context_fops;
198
199/* gang management */
200struct spu_gang *alloc_spu_gang(void);
201struct spu_gang *get_spu_gang(struct spu_gang *gang);
202int put_spu_gang(struct spu_gang *gang);
203void spu_gang_remove_ctx(struct spu_gang *gang, struct spu_context *ctx);
204void spu_gang_add_ctx(struct spu_gang *gang, struct spu_context *ctx);
205
206/* fault handling */
207int spufs_handle_class1(struct spu_context *ctx);
208
209/* context management */
210extern atomic_t nr_spu_contexts;
211static inline void spu_acquire(struct spu_context *ctx)
212{
213 mutex_lock(&ctx->state_mutex);
214}
215
216static inline void spu_release(struct spu_context *ctx)
217{
218 mutex_unlock(&ctx->state_mutex);
219}
220
221struct spu_context * alloc_spu_context(struct spu_gang *gang);
222void destroy_spu_context(struct kref *kref);
223struct spu_context * get_spu_context(struct spu_context *ctx);
224int put_spu_context(struct spu_context *ctx);
225void spu_unmap_mappings(struct spu_context *ctx);
226
227void spu_forget(struct spu_context *ctx);
228int spu_acquire_runnable(struct spu_context *ctx, unsigned long flags);
229void spu_acquire_saved(struct spu_context *ctx);
230
231int spu_activate(struct spu_context *ctx, unsigned long flags);
232void spu_deactivate(struct spu_context *ctx);
233void spu_yield(struct spu_context *ctx);
234void spu_set_timeslice(struct spu_context *ctx);
235void spu_update_sched_info(struct spu_context *ctx);
236void __spu_update_sched_info(struct spu_context *ctx);
237int __init spu_sched_init(void);
238void __exit spu_sched_exit(void);
239
240extern char *isolated_loader;
241
242/*
243 * spufs_wait
244 * Same as wait_event_interruptible(), except that here
245 * we need to call spu_release(ctx) before sleeping, and
246 * then spu_acquire(ctx) when awoken.
247 */
248
249#define spufs_wait(wq, condition) \
250({ \
251 int __ret = 0; \
252 DEFINE_WAIT(__wait); \
253 for (;;) { \
254 prepare_to_wait(&(wq), &__wait, TASK_INTERRUPTIBLE); \
255 if (condition) \
256 break; \
257 if (signal_pending(current)) { \
258 __ret = -ERESTARTSYS; \
259 break; \
260 } \
261 spu_release(ctx); \
262 schedule(); \
263 spu_acquire(ctx); \
264 } \
265 finish_wait(&(wq), &__wait); \
266 __ret; \
267})
268
269size_t spu_wbox_write(struct spu_context *ctx, u32 data);
270size_t spu_ibox_read(struct spu_context *ctx, u32 *data);
271
272/* irq callback funcs. */
273void spufs_ibox_callback(struct spu *spu);
274void spufs_wbox_callback(struct spu *spu);
275void spufs_stop_callback(struct spu *spu);
276void spufs_mfc_callback(struct spu *spu);
277void spufs_dma_callback(struct spu *spu, int type);
278
279extern struct spu_coredump_calls spufs_coredump_calls;
280struct spufs_coredump_reader {
281 char *name;
282 ssize_t (*read)(struct spu_context *ctx,
283 char __user *buffer, size_t size, loff_t *pos);
284 u64 (*get)(void *data);
285 size_t size;
286};
287extern struct spufs_coredump_reader spufs_coredump_read[];
288extern int spufs_coredump_num_notes;
289
290/*
291 * This function is a little bit too large for an inline, but
292 * as fault.c is built into the kernel we can't move it out of
293 * line.
294 */
295static inline void spuctx_switch_state(struct spu_context *ctx,
296 enum spuctx_execution_state new_state)
297{
298 WARN_ON(!mutex_is_locked(&ctx->state_mutex));
299
300 if (ctx->stats.execution_state != new_state) {
301 unsigned long curtime = jiffies;
302
303 ctx->stats.times[ctx->stats.execution_state] +=
304 curtime - ctx->stats.tstamp;
305 ctx->stats.tstamp = curtime;
306 ctx->stats.execution_state = new_state;
307 }
308}
309
310static inline void spu_switch_state(struct spu *spu,
311 enum spuctx_execution_state new_state)
312{
313 if (spu->stats.utilization_state != new_state) {
314 unsigned long curtime = jiffies;
315
316 spu->stats.times[spu->stats.utilization_state] +=
317 curtime - spu->stats.tstamp;
318 spu->stats.tstamp = curtime;
319 spu->stats.utilization_state = new_state;
320 }
321}
322
323#endif