]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - 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
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
AB
34
35/* The magic number for our file system */
36enum {
37 SPUFS_MAGIC = 0x23c9b64e,
38};
39
8b3d6663 40struct spu_context_ops;
6263203e
AB
41struct spu_gang;
42
e9f8a0b6
CH
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
67207b96
AB
56struct spu_context {
57 struct spu *spu; /* pointer to a physical SPU */
5473af04 58 struct spu_state csa; /* SPU context save area. */
67207b96 59 spinlock_t mmio_lock; /* protects mmio access */
6df10a82
MN
60 struct address_space *local_store; /* local store mapping. */
61 struct address_space *mfc; /* 'mfc' area mappings. */
43c2bbd9
CH
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. */
47d3a5fa 67 struct mutex mapping_lock;
86767277 68 u64 object_id; /* user space pointer for oprofile */
8b3d6663
AB
69
70 enum { SPU_STATE_RUNNABLE, SPU_STATE_SAVED } state;
650f8b02 71 struct mutex state_mutex;
e45d48a3 72 struct mutex run_mutex;
8b3d6663
AB
73
74 struct mm_struct *owner;
67207b96
AB
75
76 struct kref kref;
8b3d6663
AB
77 wait_queue_head_t ibox_wq;
78 wait_queue_head_t wbox_wq;
5110459f 79 wait_queue_head_t stop_wq;
a33a7d73 80 wait_queue_head_t mfc_wq;
8b3d6663
AB
81 struct fasync_struct *ibox_fasync;
82 struct fasync_struct *wbox_fasync;
a33a7d73
AB
83 struct fasync_struct *mfc_fasync;
84 u32 tagwait;
8b3d6663 85 struct spu_context_ops *ops;
2a911f0b 86 struct work_struct reap_work;
9add11da
AB
87 unsigned long flags;
88 unsigned long event_return;
6263203e
AB
89
90 struct list_head gang_list;
91 struct spu_gang *gang;
8389998a 92
476273ad
CH
93 /* owner thread */
94 pid_t tid;
95
8389998a 96 /* scheduler fields */
7022543e 97 struct list_head rq;
37901802 98 unsigned int time_slice;
26bec673 99 unsigned long sched_flags;
ea1ae594 100 cpumask_t cpus_allowed;
2eb1b120 101 int policy;
8389998a 102 int prio;
e9f8a0b6
CH
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;
6263203e
AB
121};
122
123struct spu_gang {
124 struct list_head list;
125 struct mutex mutex;
126 struct kref kref;
127 int contexts;
8b3d6663
AB
128};
129
a33a7d73
AB
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
8b3d6663
AB
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);
3a843d7c
AB
145 unsigned int (*mbox_stat_poll)(struct spu_context *ctx,
146 unsigned int events);
8b3d6663
AB
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);
3960c260 161 u32 (*runcntl_read) (struct spu_context * ctx);
5110459f 162 void (*runcntl_write) (struct spu_context * ctx, u32 data);
ee2d7340
AB
163 void (*master_start) (struct spu_context * ctx);
164 void (*master_stop) (struct spu_context * ctx);
a33a7d73
AB
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);
b9e3bd77
DGM
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);
57dace23 174 void (*restart_dma)(struct spu_context *ctx);
67207b96
AB
175};
176
8b3d6663
AB
177extern struct spu_context_ops spu_hw_ops;
178extern struct spu_context_ops spu_backing_ops;
179
67207b96
AB
180struct spufs_inode_info {
181 struct spu_context *i_ctx;
6263203e 182 struct spu_gang *i_gang;
67207b96 183 struct inode vfs_inode;
43c2bbd9 184 int i_openers;
67207b96
AB
185};
186#define SPUFS_I(inode) \
187 container_of(inode, struct spufs_inode_info, vfs_inode)
188
189extern struct tree_descr spufs_dir_contents[];
5737edd1 190extern struct tree_descr spufs_dir_nosched_contents[];
67207b96
AB
191
192/* system call implementation */
193long spufs_run_spu(struct file *file,
194 struct spu_context *ctx, u32 *npc, u32 *status);
6263203e 195long spufs_create(struct nameidata *nd,
67207b96 196 unsigned int flags, mode_t mode);
9c2e08c5 197extern const struct file_operations spufs_context_fops;
67207b96 198
6263203e
AB
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
57dace23
AB
206/* fault handling */
207int spufs_handle_class1(struct spu_context *ctx);
208
67207b96 209/* context management */
65de66f0 210extern atomic_t nr_spu_contexts;
6a0641e5
CH
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
6263203e 221struct spu_context * alloc_spu_context(struct spu_gang *gang);
67207b96
AB
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);
5110459f 225void spu_unmap_mappings(struct spu_context *ctx);
67207b96 226
8b3d6663 227void spu_forget(struct spu_context *ctx);
26bec673 228int spu_acquire_runnable(struct spu_context *ctx, unsigned long flags);
67207b96 229void spu_acquire_saved(struct spu_context *ctx);
50b520d4 230
26bec673 231int spu_activate(struct spu_context *ctx, unsigned long flags);
8b3d6663
AB
232void spu_deactivate(struct spu_context *ctx);
233void spu_yield(struct spu_context *ctx);
fe443ef2 234void spu_set_timeslice(struct spu_context *ctx);
2cf2b3b4
CH
235void spu_update_sched_info(struct spu_context *ctx);
236void __spu_update_sched_info(struct spu_context *ctx);
8b3d6663
AB
237int __init spu_sched_init(void);
238void __exit spu_sched_exit(void);
239
c6730ed4
JK
240extern char *isolated_loader;
241
ce8ab854
AB
242/*
243 * spufs_wait
7022543e 244 * Same as wait_event_interruptible(), except that here
ce8ab854
AB
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; \
d3764397
JK
257 if (signal_pending(current)) { \
258 __ret = -ERESTARTSYS; \
259 break; \
ce8ab854 260 } \
d3764397
JK
261 spu_release(ctx); \
262 schedule(); \
263 spu_acquire(ctx); \
ce8ab854
AB
264 } \
265 finish_wait(&(wq), &__wait); \
266 __ret; \
267})
268
8b3d6663
AB
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);
5110459f 275void spufs_stop_callback(struct spu *spu);
a33a7d73 276void spufs_mfc_callback(struct spu *spu);
9add11da 277void spufs_dma_callback(struct spu *spu, int type);
8b3d6663 278
bf1ab978
DGM
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
e9f8a0b6
CH
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
fe2f896d
CH
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
67207b96 323#endif