Merge commit 'origin/master' into next
[deliverable/linux.git] / arch / powerpc / platforms / cell / spufs / spufs.h
CommitLineData
67207b96
AB
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>
650f8b02 26#include <linux/mutex.h>
67207b96
AB
27#include <linux/spinlock.h>
28#include <linux/fs.h>
ea1ae594 29#include <linux/cpumask.h>
67207b96
AB
30
31#include <asm/spu.h>
5473af04 32#include <asm/spu_csa.h>
b9e3bd77 33#include <asm/spu_info.h>
67207b96 34
87ff6090
JK
35#define SPUFS_PS_MAP_SIZE 0x20000
36#define SPUFS_MFC_MAP_SIZE 0x1000
37#define SPUFS_CNTL_MAP_SIZE 0x1000
38#define SPUFS_CNTL_MAP_SIZE 0x1000
39#define SPUFS_SIGNAL_MAP_SIZE PAGE_SIZE
40#define SPUFS_MSS_MAP_SIZE 0x1000
41
67207b96
AB
42/* The magic number for our file system */
43enum {
44 SPUFS_MAGIC = 0x23c9b64e,
45};
46
8b3d6663 47struct spu_context_ops;
6263203e
AB
48struct spu_gang;
49
36aaccc1
BN
50/* ctx->sched_flags */
51enum {
52 SPU_SCHED_NOTIFY_ACTIVE,
b2c863bd 53 SPU_SCHED_WAS_ACTIVE, /* was active upon spu_acquire_saved() */
ce7c191b 54 SPU_SCHED_SPU_RUN, /* context is within spu_run */
36aaccc1
BN
55};
56
5158e9b5
CH
57enum {
58 SWITCH_LOG_BUFSIZE = 4096,
59};
60
61enum {
62 SWITCH_LOG_START,
63 SWITCH_LOG_STOP,
64 SWITCH_LOG_EXIT,
65};
66
67struct switch_log {
5158e9b5
CH
68 wait_queue_head_t wait;
69 unsigned long head;
70 unsigned long tail;
71 struct switch_log_entry {
72 struct timespec tstamp;
73 s32 spu_id;
74 u32 type;
75 u32 val;
76 u64 timebase;
77 } log[];
78};
79
67207b96
AB
80struct spu_context {
81 struct spu *spu; /* pointer to a physical SPU */
5473af04 82 struct spu_state csa; /* SPU context save area. */
67207b96 83 spinlock_t mmio_lock; /* protects mmio access */
6df10a82
MN
84 struct address_space *local_store; /* local store mapping. */
85 struct address_space *mfc; /* 'mfc' area mappings. */
43c2bbd9
CH
86 struct address_space *cntl; /* 'control' area mappings. */
87 struct address_space *signal1; /* 'signal1' area mappings. */
88 struct address_space *signal2; /* 'signal2' area mappings. */
89 struct address_space *mss; /* 'mss' area mappings. */
90 struct address_space *psmap; /* 'psmap' area mappings. */
47d3a5fa 91 struct mutex mapping_lock;
86767277 92 u64 object_id; /* user space pointer for oprofile */
8b3d6663
AB
93
94 enum { SPU_STATE_RUNNABLE, SPU_STATE_SAVED } state;
650f8b02 95 struct mutex state_mutex;
e45d48a3 96 struct mutex run_mutex;
8b3d6663
AB
97
98 struct mm_struct *owner;
67207b96
AB
99
100 struct kref kref;
8b3d6663
AB
101 wait_queue_head_t ibox_wq;
102 wait_queue_head_t wbox_wq;
5110459f 103 wait_queue_head_t stop_wq;
a33a7d73 104 wait_queue_head_t mfc_wq;
33bfd7a7 105 wait_queue_head_t run_wq;
8b3d6663
AB
106 struct fasync_struct *ibox_fasync;
107 struct fasync_struct *wbox_fasync;
a33a7d73
AB
108 struct fasync_struct *mfc_fasync;
109 u32 tagwait;
8b3d6663 110 struct spu_context_ops *ops;
2a911f0b 111 struct work_struct reap_work;
9add11da
AB
112 unsigned long flags;
113 unsigned long event_return;
6263203e
AB
114
115 struct list_head gang_list;
116 struct spu_gang *gang;
1474855d
BN
117 struct kref *prof_priv_kref;
118 void ( * prof_priv_release) (struct kref *kref);
8389998a 119
476273ad
CH
120 /* owner thread */
121 pid_t tid;
122
8389998a 123 /* scheduler fields */
7022543e 124 struct list_head rq;
37901802 125 unsigned int time_slice;
26bec673 126 unsigned long sched_flags;
ea1ae594 127 cpumask_t cpus_allowed;
2eb1b120 128 int policy;
8389998a 129 int prio;
7a214200 130 int last_ran;
e9f8a0b6
CH
131
132 /* statistics */
133 struct {
134 /* updates protected by ctx->state_mutex */
27ec41d3
AD
135 enum spu_utilization_state util_state;
136 unsigned long long tstamp; /* time of last state switch */
137 unsigned long long times[SPU_UTIL_MAX];
e9f8a0b6
CH
138 unsigned long long vol_ctx_switch;
139 unsigned long long invol_ctx_switch;
140 unsigned long long min_flt;
141 unsigned long long maj_flt;
142 unsigned long long hash_flt;
143 unsigned long long slb_flt;
144 unsigned long long slb_flt_base; /* # at last ctx switch */
145 unsigned long long class2_intr;
146 unsigned long long class2_intr_base; /* # at last ctx switch */
147 unsigned long long libassist;
148 } stats;
8e68e2f2 149
5158e9b5
CH
150 /* context switch log */
151 struct switch_log *switch_log;
152
8e68e2f2
AB
153 struct list_head aff_list;
154 int aff_head;
c5fc8d2a 155 int aff_offset;
6263203e
AB
156};
157
158struct spu_gang {
159 struct list_head list;
160 struct mutex mutex;
161 struct kref kref;
162 int contexts;
8e68e2f2
AB
163
164 struct spu_context *aff_ref_ctx;
165 struct list_head aff_list_head;
166 struct mutex aff_mutex;
167 int aff_flags;
c5fc8d2a
AB
168 struct spu *aff_ref_spu;
169 atomic_t aff_sched_count;
8b3d6663
AB
170};
171
8e68e2f2
AB
172/* Flag bits for spu_gang aff_flags */
173#define AFF_OFFSETS_SET 1
174#define AFF_MERGED 2
175
a33a7d73
AB
176struct mfc_dma_command {
177 int32_t pad; /* reserved */
178 uint32_t lsa; /* local storage address */
179 uint64_t ea; /* effective address */
180 uint16_t size; /* transfer size */
181 uint16_t tag; /* command tag */
182 uint16_t class; /* class ID */
183 uint16_t cmd; /* command opcode */
184};
185
186
8b3d6663
AB
187/* SPU context query/set operations. */
188struct spu_context_ops {
189 int (*mbox_read) (struct spu_context * ctx, u32 * data);
190 u32(*mbox_stat_read) (struct spu_context * ctx);
3a843d7c
AB
191 unsigned int (*mbox_stat_poll)(struct spu_context *ctx,
192 unsigned int events);
8b3d6663
AB
193 int (*ibox_read) (struct spu_context * ctx, u32 * data);
194 int (*wbox_write) (struct spu_context * ctx, u32 data);
195 u32(*signal1_read) (struct spu_context * ctx);
196 void (*signal1_write) (struct spu_context * ctx, u32 data);
197 u32(*signal2_read) (struct spu_context * ctx);
198 void (*signal2_write) (struct spu_context * ctx, u32 data);
199 void (*signal1_type_set) (struct spu_context * ctx, u64 val);
200 u64(*signal1_type_get) (struct spu_context * ctx);
201 void (*signal2_type_set) (struct spu_context * ctx, u64 val);
202 u64(*signal2_type_get) (struct spu_context * ctx);
203 u32(*npc_read) (struct spu_context * ctx);
204 void (*npc_write) (struct spu_context * ctx, u32 data);
205 u32(*status_read) (struct spu_context * ctx);
206 char*(*get_ls) (struct spu_context * ctx);
cc210b3e 207 void (*privcntl_write) (struct spu_context *ctx, u64 data);
3960c260 208 u32 (*runcntl_read) (struct spu_context * ctx);
5110459f 209 void (*runcntl_write) (struct spu_context * ctx, u32 data);
c25620d7 210 void (*runcntl_stop) (struct spu_context * ctx);
ee2d7340
AB
211 void (*master_start) (struct spu_context * ctx);
212 void (*master_stop) (struct spu_context * ctx);
a33a7d73
AB
213 int (*set_mfc_query)(struct spu_context * ctx, u32 mask, u32 mode);
214 u32 (*read_mfc_tagstatus)(struct spu_context * ctx);
215 u32 (*get_mfc_free_elements)(struct spu_context *ctx);
b9e3bd77
DGM
216 int (*send_mfc_command)(struct spu_context * ctx,
217 struct mfc_dma_command * cmd);
218 void (*dma_info_read) (struct spu_context * ctx,
219 struct spu_dma_info * info);
220 void (*proxydma_info_read) (struct spu_context * ctx,
221 struct spu_proxydma_info * info);
57dace23 222 void (*restart_dma)(struct spu_context *ctx);
67207b96
AB
223};
224
8b3d6663
AB
225extern struct spu_context_ops spu_hw_ops;
226extern struct spu_context_ops spu_backing_ops;
227
67207b96
AB
228struct spufs_inode_info {
229 struct spu_context *i_ctx;
6263203e 230 struct spu_gang *i_gang;
67207b96 231 struct inode vfs_inode;
43c2bbd9 232 int i_openers;
67207b96
AB
233};
234#define SPUFS_I(inode) \
235 container_of(inode, struct spufs_inode_info, vfs_inode)
236
23d893f5
JK
237struct spufs_tree_descr {
238 const char *name;
239 const struct file_operations *ops;
240 int mode;
241 size_t size;
242};
243
74254647
JK
244extern const struct spufs_tree_descr spufs_dir_contents[];
245extern const struct spufs_tree_descr spufs_dir_nosched_contents[];
246extern const struct spufs_tree_descr spufs_dir_debug_contents[];
67207b96
AB
247
248/* system call implementation */
98f06978 249extern struct spufs_calls spufs_calls;
50af32a9 250long spufs_run_spu(struct spu_context *ctx, u32 *npc, u32 *status);
8e68e2f2
AB
251long spufs_create(struct nameidata *nd, unsigned int flags,
252 mode_t mode, struct file *filp);
48cad41f
ME
253/* ELF coredump callbacks for writing SPU ELF notes */
254extern int spufs_coredump_extra_notes_size(void);
7af1443a 255extern int spufs_coredump_extra_notes_write(struct file *file, loff_t *foffset);
48cad41f 256
9c2e08c5 257extern const struct file_operations spufs_context_fops;
67207b96 258
6263203e
AB
259/* gang management */
260struct spu_gang *alloc_spu_gang(void);
261struct spu_gang *get_spu_gang(struct spu_gang *gang);
262int put_spu_gang(struct spu_gang *gang);
263void spu_gang_remove_ctx(struct spu_gang *gang, struct spu_context *ctx);
264void spu_gang_add_ctx(struct spu_gang *gang, struct spu_context *ctx);
265
57dace23
AB
266/* fault handling */
267int spufs_handle_class1(struct spu_context *ctx);
d6ad39bc 268int spufs_handle_class0(struct spu_context *ctx);
57dace23 269
c5fc8d2a
AB
270/* affinity */
271struct spu *affinity_check(struct spu_context *ctx);
272
67207b96 273/* context management */
65de66f0 274extern atomic_t nr_spu_contexts;
c9101bdb 275static inline int __must_check spu_acquire(struct spu_context *ctx)
6a0641e5 276{
c9101bdb 277 return mutex_lock_interruptible(&ctx->state_mutex);
6a0641e5
CH
278}
279
280static inline void spu_release(struct spu_context *ctx)
281{
282 mutex_unlock(&ctx->state_mutex);
283}
284
6263203e 285struct spu_context * alloc_spu_context(struct spu_gang *gang);
67207b96
AB
286void destroy_spu_context(struct kref *kref);
287struct spu_context * get_spu_context(struct spu_context *ctx);
288int put_spu_context(struct spu_context *ctx);
5110459f 289void spu_unmap_mappings(struct spu_context *ctx);
67207b96 290
8b3d6663 291void spu_forget(struct spu_context *ctx);
c9101bdb 292int __must_check spu_acquire_saved(struct spu_context *ctx);
27b1ea09 293void spu_release_saved(struct spu_context *ctx);
50b520d4 294
e65c2f6f
LB
295int spu_stopped(struct spu_context *ctx, u32 * stat);
296void spu_del_from_rq(struct spu_context *ctx);
26bec673 297int spu_activate(struct spu_context *ctx, unsigned long flags);
8b3d6663
AB
298void spu_deactivate(struct spu_context *ctx);
299void spu_yield(struct spu_context *ctx);
36aaccc1 300void spu_switch_notify(struct spu *spu, struct spu_context *ctx);
5158e9b5
CH
301void spu_switch_log_notify(struct spu *spu, struct spu_context *ctx,
302 u32 type, u32 val);
fe443ef2 303void spu_set_timeslice(struct spu_context *ctx);
2cf2b3b4
CH
304void spu_update_sched_info(struct spu_context *ctx);
305void __spu_update_sched_info(struct spu_context *ctx);
8b3d6663 306int __init spu_sched_init(void);
d1450317 307void spu_sched_exit(void);
8b3d6663 308
c6730ed4
JK
309extern char *isolated_loader;
310
ce8ab854
AB
311/*
312 * spufs_wait
7022543e 313 * Same as wait_event_interruptible(), except that here
ce8ab854
AB
314 * we need to call spu_release(ctx) before sleeping, and
315 * then spu_acquire(ctx) when awoken.
eebead5b 316 *
73ac36ea 317 * Returns with state_mutex re-acquired when successful or
eebead5b 318 * with -ERESTARTSYS and the state_mutex dropped when interrupted.
ce8ab854
AB
319 */
320
321#define spufs_wait(wq, condition) \
322({ \
323 int __ret = 0; \
324 DEFINE_WAIT(__wait); \
325 for (;;) { \
326 prepare_to_wait(&(wq), &__wait, TASK_INTERRUPTIBLE); \
327 if (condition) \
328 break; \
eebead5b 329 spu_release(ctx); \
d3764397
JK
330 if (signal_pending(current)) { \
331 __ret = -ERESTARTSYS; \
332 break; \
ce8ab854 333 } \
d3764397 334 schedule(); \
c9101bdb
CH
335 __ret = spu_acquire(ctx); \
336 if (__ret) \
337 break; \
ce8ab854
AB
338 } \
339 finish_wait(&(wq), &__wait); \
340 __ret; \
341})
342
8b3d6663
AB
343size_t spu_wbox_write(struct spu_context *ctx, u32 data);
344size_t spu_ibox_read(struct spu_context *ctx, u32 *data);
345
346/* irq callback funcs. */
347void spufs_ibox_callback(struct spu *spu);
348void spufs_wbox_callback(struct spu *spu);
f3d69e05 349void spufs_stop_callback(struct spu *spu, int irq);
a33a7d73 350void spufs_mfc_callback(struct spu *spu);
9add11da 351void spufs_dma_callback(struct spu *spu, int type);
8b3d6663 352
bf1ab978
DGM
353extern struct spu_coredump_calls spufs_coredump_calls;
354struct spufs_coredump_reader {
355 char *name;
356 ssize_t (*read)(struct spu_context *ctx,
357 char __user *buffer, size_t size, loff_t *pos);
74de08bc 358 u64 (*get)(struct spu_context *ctx);
bf1ab978
DGM
359 size_t size;
360};
74254647 361extern const struct spufs_coredump_reader spufs_coredump_read[];
bf1ab978
DGM
362extern int spufs_coredump_num_notes;
363
7cd58e43
JK
364extern int spu_init_csa(struct spu_state *csa);
365extern void spu_fini_csa(struct spu_state *csa);
366extern int spu_save(struct spu_state *prev, struct spu *spu);
367extern int spu_restore(struct spu_state *new, struct spu *spu);
368extern int spu_switch(struct spu_state *prev, struct spu_state *new,
369 struct spu *spu);
370extern int spu_alloc_lscsa(struct spu_state *csa);
371extern void spu_free_lscsa(struct spu_state *csa);
372
373extern void spuctx_switch_state(struct spu_context *ctx,
374 enum spu_utilization_state new_state);
fe2f896d 375
038200cf 376#define spu_context_trace(name, ctx, spu) \
d6508aaf 377 trace_mark(name, "ctx %p spu %p", ctx, spu);
038200cf 378#define spu_context_nospu_trace(name, ctx) \
d6508aaf 379 trace_mark(name, "ctx %p", ctx);
038200cf 380
67207b96 381#endif
This page took 0.30052 seconds and 5 git commands to generate.