]> bbs.cooldavid.org Git - net-next-2.6.git/blame - arch/powerpc/platforms/cell/spufs/file.c
libfs: allow error return from simple attributes
[net-next-2.6.git] / arch / powerpc / platforms / cell / spufs / file.c
CommitLineData
67207b96
AB
1/*
2 * SPU file system -- file contents
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
a33a7d73
AB
23#undef DEBUG
24
67207b96
AB
25#include <linux/fs.h>
26#include <linux/ioctl.h>
27#include <linux/module.h>
d88cfffa 28#include <linux/pagemap.h>
67207b96 29#include <linux/poll.h>
5110459f 30#include <linux/ptrace.h>
cbe709c1 31#include <linux/seq_file.h>
038200cf 32#include <linux/marker.h>
67207b96
AB
33
34#include <asm/io.h>
35#include <asm/semaphore.h>
36#include <asm/spu.h>
b9e3bd77 37#include <asm/spu_info.h>
67207b96
AB
38#include <asm/uaccess.h>
39
40#include "spufs.h"
41
27d5bf2a
BH
42#define SPUFS_MMAP_4K (PAGE_SIZE == 0x1000)
43
197b1a82
CH
44/* Simple attribute files */
45struct spufs_attr {
46 int (*get)(void *, u64 *);
47 int (*set)(void *, u64);
48 char get_buf[24]; /* enough to store a u64 and "\n\0" */
49 char set_buf[24];
50 void *data;
51 const char *fmt; /* format for read operation */
52 struct mutex mutex; /* protects access to these buffers */
53};
54
55static int spufs_attr_open(struct inode *inode, struct file *file,
56 int (*get)(void *, u64 *), int (*set)(void *, u64),
57 const char *fmt)
58{
59 struct spufs_attr *attr;
60
61 attr = kmalloc(sizeof(*attr), GFP_KERNEL);
62 if (!attr)
63 return -ENOMEM;
64
65 attr->get = get;
66 attr->set = set;
67 attr->data = inode->i_private;
68 attr->fmt = fmt;
69 mutex_init(&attr->mutex);
70 file->private_data = attr;
71
72 return nonseekable_open(inode, file);
73}
74
75static int spufs_attr_release(struct inode *inode, struct file *file)
76{
77 kfree(file->private_data);
78 return 0;
79}
80
81static ssize_t spufs_attr_read(struct file *file, char __user *buf,
82 size_t len, loff_t *ppos)
83{
84 struct spufs_attr *attr;
85 size_t size;
86 ssize_t ret;
87
88 attr = file->private_data;
89 if (!attr->get)
90 return -EACCES;
91
92 ret = mutex_lock_interruptible(&attr->mutex);
93 if (ret)
94 return ret;
95
96 if (*ppos) { /* continued read */
97 size = strlen(attr->get_buf);
98 } else { /* first read */
99 u64 val;
100 ret = attr->get(attr->data, &val);
101 if (ret)
102 goto out;
103
104 size = scnprintf(attr->get_buf, sizeof(attr->get_buf),
105 attr->fmt, (unsigned long long)val);
106 }
107
108 ret = simple_read_from_buffer(buf, len, ppos, attr->get_buf, size);
109out:
110 mutex_unlock(&attr->mutex);
111 return ret;
112}
113
114static ssize_t spufs_attr_write(struct file *file, const char __user *buf,
115 size_t len, loff_t *ppos)
116{
117 struct spufs_attr *attr;
118 u64 val;
119 size_t size;
120 ssize_t ret;
121
122 attr = file->private_data;
123 if (!attr->set)
124 return -EACCES;
125
126 ret = mutex_lock_interruptible(&attr->mutex);
127 if (ret)
128 return ret;
129
130 ret = -EFAULT;
131 size = min(sizeof(attr->set_buf) - 1, len);
132 if (copy_from_user(attr->set_buf, buf, size))
133 goto out;
134
135 ret = len; /* claim we got the whole input */
136 attr->set_buf[size] = '\0';
137 val = simple_strtol(attr->set_buf, NULL, 0);
138 attr->set(attr->data, val);
139out:
140 mutex_unlock(&attr->mutex);
141 return ret;
142}
143
144#define DEFINE_SPUFS_SIMPLE_ATTRIBUTE(__fops, __get, __set, __fmt) \
145static int __fops ## _open(struct inode *inode, struct file *file) \
146{ \
147 __simple_attr_check_format(__fmt, 0ull); \
148 return spufs_attr_open(inode, file, __get, __set, __fmt); \
149} \
150static struct file_operations __fops = { \
151 .owner = THIS_MODULE, \
152 .open = __fops ## _open, \
153 .release = spufs_attr_release, \
154 .read = spufs_attr_read, \
155 .write = spufs_attr_write, \
156};
157
cbe709c1 158
67207b96
AB
159static int
160spufs_mem_open(struct inode *inode, struct file *file)
161{
162 struct spufs_inode_info *i = SPUFS_I(inode);
6df10a82 163 struct spu_context *ctx = i->i_ctx;
43c2bbd9 164
47d3a5fa 165 mutex_lock(&ctx->mapping_lock);
6df10a82 166 file->private_data = ctx;
43c2bbd9
CH
167 if (!i->i_openers++)
168 ctx->local_store = inode->i_mapping;
47d3a5fa 169 mutex_unlock(&ctx->mapping_lock);
43c2bbd9
CH
170 return 0;
171}
172
173static int
174spufs_mem_release(struct inode *inode, struct file *file)
175{
176 struct spufs_inode_info *i = SPUFS_I(inode);
177 struct spu_context *ctx = i->i_ctx;
178
47d3a5fa 179 mutex_lock(&ctx->mapping_lock);
43c2bbd9
CH
180 if (!--i->i_openers)
181 ctx->local_store = NULL;
47d3a5fa 182 mutex_unlock(&ctx->mapping_lock);
67207b96
AB
183 return 0;
184}
185
bf1ab978
DGM
186static ssize_t
187__spufs_mem_read(struct spu_context *ctx, char __user *buffer,
188 size_t size, loff_t *pos)
189{
190 char *local_store = ctx->ops->get_ls(ctx);
191 return simple_read_from_buffer(buffer, size, pos, local_store,
192 LS_SIZE);
193}
194
67207b96
AB
195static ssize_t
196spufs_mem_read(struct file *file, char __user *buffer,
197 size_t size, loff_t *pos)
198{
bf1ab978 199 struct spu_context *ctx = file->private_data;
aa0ed2bd 200 ssize_t ret;
67207b96 201
c9101bdb
CH
202 ret = spu_acquire(ctx);
203 if (ret)
204 return ret;
bf1ab978 205 ret = __spufs_mem_read(ctx, buffer, size, pos);
8b3d6663 206 spu_release(ctx);
c9101bdb 207
67207b96
AB
208 return ret;
209}
210
211static ssize_t
212spufs_mem_write(struct file *file, const char __user *buffer,
aa0ed2bd 213 size_t size, loff_t *ppos)
67207b96
AB
214{
215 struct spu_context *ctx = file->private_data;
8b3d6663 216 char *local_store;
aa0ed2bd 217 loff_t pos = *ppos;
8b3d6663 218 int ret;
67207b96 219
aa0ed2bd
AB
220 if (pos < 0)
221 return -EINVAL;
222 if (pos > LS_SIZE)
67207b96 223 return -EFBIG;
aa0ed2bd
AB
224 if (size > LS_SIZE - pos)
225 size = LS_SIZE - pos;
8b3d6663 226
c9101bdb
CH
227 ret = spu_acquire(ctx);
228 if (ret)
229 return ret;
230
8b3d6663 231 local_store = ctx->ops->get_ls(ctx);
aa0ed2bd 232 ret = copy_from_user(local_store + pos, buffer, size);
8b3d6663 233 spu_release(ctx);
aa0ed2bd
AB
234
235 if (ret)
236 return -EFAULT;
237 *ppos = pos + size;
238 return size;
67207b96
AB
239}
240
78bde53e
BH
241static unsigned long spufs_mem_mmap_nopfn(struct vm_area_struct *vma,
242 unsigned long address)
8b3d6663 243{
f1fa74f4
BH
244 struct spu_context *ctx = vma->vm_file->private_data;
245 unsigned long pfn, offset, addr0 = address;
246#ifdef CONFIG_SPU_FS_64K_LS
247 struct spu_state *csa = &ctx->csa;
248 int psize;
249
250 /* Check what page size we are using */
251 psize = get_slice_psize(vma->vm_mm, address);
252
253 /* Some sanity checking */
254 BUG_ON(csa->use_big_pages != (psize == MMU_PAGE_64K));
255
256 /* Wow, 64K, cool, we need to align the address though */
257 if (csa->use_big_pages) {
258 BUG_ON(vma->vm_start & 0xffff);
259 address &= ~0xfffful;
260 }
261#endif /* CONFIG_SPU_FS_64K_LS */
8b3d6663 262
f1fa74f4 263 offset = (address - vma->vm_start) + (vma->vm_pgoff << PAGE_SHIFT);
128b8546
MN
264 if (offset >= LS_SIZE)
265 return NOPFN_SIGBUS;
266
f1fa74f4
BH
267 pr_debug("spufs_mem_mmap_nopfn address=0x%lx -> 0x%lx, offset=0x%lx\n",
268 addr0, address, offset);
269
c9101bdb
CH
270 if (spu_acquire(ctx))
271 return NOPFN_REFAULT;
8b3d6663 272
ac91cb8d
AB
273 if (ctx->state == SPU_STATE_SAVED) {
274 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
932f535d 275 & ~_PAGE_NO_CACHE);
78bde53e 276 pfn = vmalloc_to_pfn(ctx->csa.lscsa->ls + offset);
ac91cb8d
AB
277 } else {
278 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
78bde53e
BH
279 | _PAGE_NO_CACHE);
280 pfn = (ctx->spu->local_store_phys + offset) >> PAGE_SHIFT;
ac91cb8d 281 }
78bde53e 282 vm_insert_pfn(vma, address, pfn);
8b3d6663 283
78bde53e 284 spu_release(ctx);
8b3d6663 285
78bde53e 286 return NOPFN_REFAULT;
8b3d6663
AB
287}
288
78bde53e 289
8b3d6663 290static struct vm_operations_struct spufs_mem_mmap_vmops = {
78bde53e 291 .nopfn = spufs_mem_mmap_nopfn,
8b3d6663
AB
292};
293
f1fa74f4 294static int spufs_mem_mmap(struct file *file, struct vm_area_struct *vma)
67207b96 295{
f1fa74f4
BH
296#ifdef CONFIG_SPU_FS_64K_LS
297 struct spu_context *ctx = file->private_data;
298 struct spu_state *csa = &ctx->csa;
299
300 /* Sanity check VMA alignment */
301 if (csa->use_big_pages) {
302 pr_debug("spufs_mem_mmap 64K, start=0x%lx, end=0x%lx,"
303 " pgoff=0x%lx\n", vma->vm_start, vma->vm_end,
304 vma->vm_pgoff);
305 if (vma->vm_start & 0xffff)
306 return -EINVAL;
307 if (vma->vm_pgoff & 0xf)
308 return -EINVAL;
309 }
310#endif /* CONFIG_SPU_FS_64K_LS */
311
8b3d6663
AB
312 if (!(vma->vm_flags & VM_SHARED))
313 return -EINVAL;
67207b96 314
78bde53e 315 vma->vm_flags |= VM_IO | VM_PFNMAP;
8b3d6663
AB
316 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
317 | _PAGE_NO_CACHE);
318
319 vma->vm_ops = &spufs_mem_mmap_vmops;
67207b96
AB
320 return 0;
321}
322
f1fa74f4 323#ifdef CONFIG_SPU_FS_64K_LS
1238819a
SS
324static unsigned long spufs_get_unmapped_area(struct file *file,
325 unsigned long addr, unsigned long len, unsigned long pgoff,
326 unsigned long flags)
f1fa74f4
BH
327{
328 struct spu_context *ctx = file->private_data;
329 struct spu_state *csa = &ctx->csa;
330
331 /* If not using big pages, fallback to normal MM g_u_a */
332 if (!csa->use_big_pages)
333 return current->mm->get_unmapped_area(file, addr, len,
334 pgoff, flags);
335
336 /* Else, try to obtain a 64K pages slice */
337 return slice_get_unmapped_area(addr, len, flags,
338 MMU_PAGE_64K, 1, 0);
339}
340#endif /* CONFIG_SPU_FS_64K_LS */
341
5dfe4c96 342static const struct file_operations spufs_mem_fops = {
7022543e
JK
343 .open = spufs_mem_open,
344 .release = spufs_mem_release,
345 .read = spufs_mem_read,
346 .write = spufs_mem_write,
347 .llseek = generic_file_llseek,
348 .mmap = spufs_mem_mmap,
f1fa74f4
BH
349#ifdef CONFIG_SPU_FS_64K_LS
350 .get_unmapped_area = spufs_get_unmapped_area,
351#endif
8b3d6663
AB
352};
353
78bde53e 354static unsigned long spufs_ps_nopfn(struct vm_area_struct *vma,
6df10a82 355 unsigned long address,
78bde53e 356 unsigned long ps_offs,
27d5bf2a 357 unsigned long ps_size)
6df10a82 358{
6df10a82 359 struct spu_context *ctx = vma->vm_file->private_data;
78bde53e 360 unsigned long area, offset = address - vma->vm_start;
6df10a82 361
038200cf
CH
362 spu_context_nospu_trace(spufs_ps_nopfn__enter, ctx);
363
6df10a82 364 offset += vma->vm_pgoff << PAGE_SHIFT;
27d5bf2a 365 if (offset >= ps_size)
78bde53e 366 return NOPFN_SIGBUS;
6df10a82 367
33bfd7a7
AB
368 /*
369 * We have to wait for context to be loaded before we have
370 * pages to hand out to the user, but we don't want to wait
371 * with the mmap_sem held.
372 * It is possible to drop the mmap_sem here, but then we need
373 * to return NOPFN_REFAULT because the mappings may have
374 * hanged.
78bde53e 375 */
c9101bdb
CH
376 if (spu_acquire(ctx))
377 return NOPFN_REFAULT;
378
33bfd7a7
AB
379 if (ctx->state == SPU_STATE_SAVED) {
380 up_read(&current->mm->mmap_sem);
038200cf 381 spu_context_nospu_trace(spufs_ps_nopfn__sleep, ctx);
33bfd7a7 382 spufs_wait(ctx->run_wq, ctx->state == SPU_STATE_RUNNABLE);
038200cf 383 spu_context_trace(spufs_ps_nopfn__wake, ctx, ctx->spu);
33bfd7a7 384 down_read(&current->mm->mmap_sem);
c9101bdb
CH
385 } else {
386 area = ctx->spu->problem_phys + ps_offs;
387 vm_insert_pfn(vma, address, (area + offset) >> PAGE_SHIFT);
038200cf 388 spu_context_trace(spufs_ps_nopfn__insert, ctx, ctx->spu);
33bfd7a7 389 }
6df10a82 390
6df10a82 391 spu_release(ctx);
78bde53e 392 return NOPFN_REFAULT;
6df10a82
MN
393}
394
27d5bf2a 395#if SPUFS_MMAP_4K
78bde53e
BH
396static unsigned long spufs_cntl_mmap_nopfn(struct vm_area_struct *vma,
397 unsigned long address)
6df10a82 398{
78bde53e 399 return spufs_ps_nopfn(vma, address, 0x4000, 0x1000);
6df10a82
MN
400}
401
402static struct vm_operations_struct spufs_cntl_mmap_vmops = {
78bde53e 403 .nopfn = spufs_cntl_mmap_nopfn,
6df10a82
MN
404};
405
406/*
407 * mmap support for problem state control area [0x4000 - 0x4fff].
6df10a82
MN
408 */
409static int spufs_cntl_mmap(struct file *file, struct vm_area_struct *vma)
410{
411 if (!(vma->vm_flags & VM_SHARED))
412 return -EINVAL;
413
78bde53e 414 vma->vm_flags |= VM_IO | VM_PFNMAP;
6df10a82 415 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
23cc7701 416 | _PAGE_NO_CACHE | _PAGE_GUARDED);
6df10a82
MN
417
418 vma->vm_ops = &spufs_cntl_mmap_vmops;
419 return 0;
420}
27d5bf2a
BH
421#else /* SPUFS_MMAP_4K */
422#define spufs_cntl_mmap NULL
423#endif /* !SPUFS_MMAP_4K */
6df10a82 424
197b1a82 425static int spufs_cntl_get(void *data, u64 *val)
6df10a82 426{
e1dbff2b 427 struct spu_context *ctx = data;
c9101bdb 428 int ret;
6df10a82 429
c9101bdb
CH
430 ret = spu_acquire(ctx);
431 if (ret)
432 return ret;
197b1a82 433 *val = ctx->ops->status_read(ctx);
e1dbff2b
AB
434 spu_release(ctx);
435
197b1a82 436 return 0;
6df10a82
MN
437}
438
197b1a82 439static int spufs_cntl_set(void *data, u64 val)
6df10a82 440{
e1dbff2b 441 struct spu_context *ctx = data;
c9101bdb 442 int ret;
e1dbff2b 443
c9101bdb
CH
444 ret = spu_acquire(ctx);
445 if (ret)
446 return ret;
e1dbff2b
AB
447 ctx->ops->runcntl_write(ctx, val);
448 spu_release(ctx);
197b1a82
CH
449
450 return 0;
6df10a82
MN
451}
452
e1dbff2b 453static int spufs_cntl_open(struct inode *inode, struct file *file)
6df10a82 454{
e1dbff2b
AB
455 struct spufs_inode_info *i = SPUFS_I(inode);
456 struct spu_context *ctx = i->i_ctx;
457
47d3a5fa 458 mutex_lock(&ctx->mapping_lock);
e1dbff2b 459 file->private_data = ctx;
43c2bbd9
CH
460 if (!i->i_openers++)
461 ctx->cntl = inode->i_mapping;
47d3a5fa 462 mutex_unlock(&ctx->mapping_lock);
8b88b099 463 return simple_attr_open(inode, file, spufs_cntl_get,
e1dbff2b 464 spufs_cntl_set, "0x%08lx");
6df10a82
MN
465}
466
43c2bbd9
CH
467static int
468spufs_cntl_release(struct inode *inode, struct file *file)
469{
470 struct spufs_inode_info *i = SPUFS_I(inode);
471 struct spu_context *ctx = i->i_ctx;
472
8b88b099 473 simple_attr_close(inode, file);
43c2bbd9 474
47d3a5fa 475 mutex_lock(&ctx->mapping_lock);
43c2bbd9
CH
476 if (!--i->i_openers)
477 ctx->cntl = NULL;
47d3a5fa 478 mutex_unlock(&ctx->mapping_lock);
43c2bbd9
CH
479 return 0;
480}
481
5dfe4c96 482static const struct file_operations spufs_cntl_fops = {
6df10a82 483 .open = spufs_cntl_open,
43c2bbd9 484 .release = spufs_cntl_release,
8b88b099
CH
485 .read = simple_attr_read,
486 .write = simple_attr_write,
6df10a82 487 .mmap = spufs_cntl_mmap,
6df10a82
MN
488};
489
8b3d6663
AB
490static int
491spufs_regs_open(struct inode *inode, struct file *file)
492{
493 struct spufs_inode_info *i = SPUFS_I(inode);
494 file->private_data = i->i_ctx;
495 return 0;
496}
497
bf1ab978
DGM
498static ssize_t
499__spufs_regs_read(struct spu_context *ctx, char __user *buffer,
500 size_t size, loff_t *pos)
501{
502 struct spu_lscsa *lscsa = ctx->csa.lscsa;
503 return simple_read_from_buffer(buffer, size, pos,
504 lscsa->gprs, sizeof lscsa->gprs);
505}
506
8b3d6663
AB
507static ssize_t
508spufs_regs_read(struct file *file, char __user *buffer,
509 size_t size, loff_t *pos)
510{
8b3d6663 511 int ret;
bf1ab978 512 struct spu_context *ctx = file->private_data;
8b3d6663 513
c9101bdb
CH
514 ret = spu_acquire_saved(ctx);
515 if (ret)
516 return ret;
bf1ab978 517 ret = __spufs_regs_read(ctx, buffer, size, pos);
27b1ea09 518 spu_release_saved(ctx);
8b3d6663
AB
519 return ret;
520}
521
522static ssize_t
523spufs_regs_write(struct file *file, const char __user *buffer,
524 size_t size, loff_t *pos)
525{
526 struct spu_context *ctx = file->private_data;
527 struct spu_lscsa *lscsa = ctx->csa.lscsa;
528 int ret;
529
530 size = min_t(ssize_t, sizeof lscsa->gprs - *pos, size);
531 if (size <= 0)
532 return -EFBIG;
533 *pos += size;
534
c9101bdb
CH
535 ret = spu_acquire_saved(ctx);
536 if (ret)
537 return ret;
8b3d6663
AB
538
539 ret = copy_from_user(lscsa->gprs + *pos - size,
540 buffer, size) ? -EFAULT : size;
541
27b1ea09 542 spu_release_saved(ctx);
8b3d6663
AB
543 return ret;
544}
545
5dfe4c96 546static const struct file_operations spufs_regs_fops = {
8b3d6663
AB
547 .open = spufs_regs_open,
548 .read = spufs_regs_read,
549 .write = spufs_regs_write,
67207b96
AB
550 .llseek = generic_file_llseek,
551};
552
bf1ab978
DGM
553static ssize_t
554__spufs_fpcr_read(struct spu_context *ctx, char __user * buffer,
555 size_t size, loff_t * pos)
556{
557 struct spu_lscsa *lscsa = ctx->csa.lscsa;
558 return simple_read_from_buffer(buffer, size, pos,
559 &lscsa->fpcr, sizeof(lscsa->fpcr));
560}
561
8b3d6663
AB
562static ssize_t
563spufs_fpcr_read(struct file *file, char __user * buffer,
564 size_t size, loff_t * pos)
565{
8b3d6663 566 int ret;
bf1ab978 567 struct spu_context *ctx = file->private_data;
8b3d6663 568
c9101bdb
CH
569 ret = spu_acquire_saved(ctx);
570 if (ret)
571 return ret;
bf1ab978 572 ret = __spufs_fpcr_read(ctx, buffer, size, pos);
27b1ea09 573 spu_release_saved(ctx);
8b3d6663
AB
574 return ret;
575}
576
577static ssize_t
578spufs_fpcr_write(struct file *file, const char __user * buffer,
579 size_t size, loff_t * pos)
580{
581 struct spu_context *ctx = file->private_data;
582 struct spu_lscsa *lscsa = ctx->csa.lscsa;
583 int ret;
584
585 size = min_t(ssize_t, sizeof(lscsa->fpcr) - *pos, size);
586 if (size <= 0)
587 return -EFBIG;
8b3d6663 588
c9101bdb
CH
589 ret = spu_acquire_saved(ctx);
590 if (ret)
591 return ret;
8b3d6663 592
c9101bdb 593 *pos += size;
8b3d6663
AB
594 ret = copy_from_user((char *)&lscsa->fpcr + *pos - size,
595 buffer, size) ? -EFAULT : size;
596
27b1ea09 597 spu_release_saved(ctx);
8b3d6663
AB
598 return ret;
599}
600
5dfe4c96 601static const struct file_operations spufs_fpcr_fops = {
8b3d6663
AB
602 .open = spufs_regs_open,
603 .read = spufs_fpcr_read,
604 .write = spufs_fpcr_write,
605 .llseek = generic_file_llseek,
606};
607
67207b96
AB
608/* generic open function for all pipe-like files */
609static int spufs_pipe_open(struct inode *inode, struct file *file)
610{
611 struct spufs_inode_info *i = SPUFS_I(inode);
612 file->private_data = i->i_ctx;
613
614 return nonseekable_open(inode, file);
615}
616
cdcc89bb
AB
617/*
618 * Read as many bytes from the mailbox as possible, until
619 * one of the conditions becomes true:
620 *
621 * - no more data available in the mailbox
622 * - end of the user provided buffer
623 * - end of the mapped area
624 */
67207b96
AB
625static ssize_t spufs_mbox_read(struct file *file, char __user *buf,
626 size_t len, loff_t *pos)
627{
8b3d6663 628 struct spu_context *ctx = file->private_data;
cdcc89bb
AB
629 u32 mbox_data, __user *udata;
630 ssize_t count;
67207b96
AB
631
632 if (len < 4)
633 return -EINVAL;
634
cdcc89bb
AB
635 if (!access_ok(VERIFY_WRITE, buf, len))
636 return -EFAULT;
637
638 udata = (void __user *)buf;
639
c9101bdb
CH
640 count = spu_acquire(ctx);
641 if (count)
642 return count;
643
274cef5e 644 for (count = 0; (count + 4) <= len; count += 4, udata++) {
cdcc89bb
AB
645 int ret;
646 ret = ctx->ops->mbox_read(ctx, &mbox_data);
647 if (ret == 0)
648 break;
649
650 /*
651 * at the end of the mapped area, we can fault
652 * but still need to return the data we have
653 * read successfully so far.
654 */
655 ret = __put_user(mbox_data, udata);
656 if (ret) {
657 if (!count)
658 count = -EFAULT;
659 break;
660 }
661 }
8b3d6663 662 spu_release(ctx);
67207b96 663
cdcc89bb
AB
664 if (!count)
665 count = -EAGAIN;
67207b96 666
cdcc89bb 667 return count;
67207b96
AB
668}
669
5dfe4c96 670static const struct file_operations spufs_mbox_fops = {
67207b96
AB
671 .open = spufs_pipe_open,
672 .read = spufs_mbox_read,
673};
674
675static ssize_t spufs_mbox_stat_read(struct file *file, char __user *buf,
676 size_t len, loff_t *pos)
677{
8b3d6663 678 struct spu_context *ctx = file->private_data;
c9101bdb 679 ssize_t ret;
67207b96
AB
680 u32 mbox_stat;
681
682 if (len < 4)
683 return -EINVAL;
684
c9101bdb
CH
685 ret = spu_acquire(ctx);
686 if (ret)
687 return ret;
8b3d6663
AB
688
689 mbox_stat = ctx->ops->mbox_stat_read(ctx) & 0xff;
690
691 spu_release(ctx);
67207b96
AB
692
693 if (copy_to_user(buf, &mbox_stat, sizeof mbox_stat))
694 return -EFAULT;
695
696 return 4;
697}
698
5dfe4c96 699static const struct file_operations spufs_mbox_stat_fops = {
67207b96
AB
700 .open = spufs_pipe_open,
701 .read = spufs_mbox_stat_read,
702};
703
704/* low-level ibox access function */
8b3d6663 705size_t spu_ibox_read(struct spu_context *ctx, u32 *data)
67207b96 706{
8b3d6663
AB
707 return ctx->ops->ibox_read(ctx, data);
708}
67207b96 709
8b3d6663
AB
710static int spufs_ibox_fasync(int fd, struct file *file, int on)
711{
712 struct spu_context *ctx = file->private_data;
67207b96 713
8b3d6663 714 return fasync_helper(fd, file, on, &ctx->ibox_fasync);
67207b96 715}
67207b96 716
8b3d6663
AB
717/* interrupt-level ibox callback function. */
718void spufs_ibox_callback(struct spu *spu)
67207b96 719{
8b3d6663
AB
720 struct spu_context *ctx = spu->ctx;
721
e65c2f6f
LB
722 if (!ctx)
723 return;
724
8b3d6663
AB
725 wake_up_all(&ctx->ibox_wq);
726 kill_fasync(&ctx->ibox_fasync, SIGIO, POLLIN);
67207b96
AB
727}
728
cdcc89bb
AB
729/*
730 * Read as many bytes from the interrupt mailbox as possible, until
731 * one of the conditions becomes true:
732 *
733 * - no more data available in the mailbox
734 * - end of the user provided buffer
735 * - end of the mapped area
736 *
737 * If the file is opened without O_NONBLOCK, we wait here until
738 * any data is available, but return when we have been able to
739 * read something.
740 */
67207b96
AB
741static ssize_t spufs_ibox_read(struct file *file, char __user *buf,
742 size_t len, loff_t *pos)
743{
8b3d6663 744 struct spu_context *ctx = file->private_data;
cdcc89bb
AB
745 u32 ibox_data, __user *udata;
746 ssize_t count;
67207b96
AB
747
748 if (len < 4)
749 return -EINVAL;
750
cdcc89bb
AB
751 if (!access_ok(VERIFY_WRITE, buf, len))
752 return -EFAULT;
753
754 udata = (void __user *)buf;
755
c9101bdb
CH
756 count = spu_acquire(ctx);
757 if (count)
758 return count;
67207b96 759
cdcc89bb
AB
760 /* wait only for the first element */
761 count = 0;
67207b96 762 if (file->f_flags & O_NONBLOCK) {
8b3d6663 763 if (!spu_ibox_read(ctx, &ibox_data))
cdcc89bb 764 count = -EAGAIN;
67207b96 765 } else {
cdcc89bb 766 count = spufs_wait(ctx->ibox_wq, spu_ibox_read(ctx, &ibox_data));
67207b96 767 }
cdcc89bb
AB
768 if (count)
769 goto out;
67207b96 770
cdcc89bb
AB
771 /* if we can't write at all, return -EFAULT */
772 count = __put_user(ibox_data, udata);
773 if (count)
774 goto out;
8b3d6663 775
cdcc89bb
AB
776 for (count = 4, udata++; (count + 4) <= len; count += 4, udata++) {
777 int ret;
778 ret = ctx->ops->ibox_read(ctx, &ibox_data);
779 if (ret == 0)
780 break;
781 /*
782 * at the end of the mapped area, we can fault
783 * but still need to return the data we have
784 * read successfully so far.
785 */
786 ret = __put_user(ibox_data, udata);
787 if (ret)
788 break;
789 }
67207b96 790
cdcc89bb
AB
791out:
792 spu_release(ctx);
67207b96 793
cdcc89bb 794 return count;
67207b96
AB
795}
796
797static unsigned int spufs_ibox_poll(struct file *file, poll_table *wait)
798{
8b3d6663 799 struct spu_context *ctx = file->private_data;
67207b96
AB
800 unsigned int mask;
801
8b3d6663 802 poll_wait(file, &ctx->ibox_wq, wait);
67207b96 803
c9101bdb
CH
804 /*
805 * For now keep this uninterruptible and also ignore the rule
806 * that poll should not sleep. Will be fixed later.
807 */
808 mutex_lock(&ctx->state_mutex);
3a843d7c
AB
809 mask = ctx->ops->mbox_stat_poll(ctx, POLLIN | POLLRDNORM);
810 spu_release(ctx);
67207b96
AB
811
812 return mask;
813}
814
5dfe4c96 815static const struct file_operations spufs_ibox_fops = {
67207b96
AB
816 .open = spufs_pipe_open,
817 .read = spufs_ibox_read,
818 .poll = spufs_ibox_poll,
819 .fasync = spufs_ibox_fasync,
820};
821
822static ssize_t spufs_ibox_stat_read(struct file *file, char __user *buf,
823 size_t len, loff_t *pos)
824{
8b3d6663 825 struct spu_context *ctx = file->private_data;
c9101bdb 826 ssize_t ret;
67207b96
AB
827 u32 ibox_stat;
828
829 if (len < 4)
830 return -EINVAL;
831
c9101bdb
CH
832 ret = spu_acquire(ctx);
833 if (ret)
834 return ret;
8b3d6663
AB
835 ibox_stat = (ctx->ops->mbox_stat_read(ctx) >> 16) & 0xff;
836 spu_release(ctx);
67207b96
AB
837
838 if (copy_to_user(buf, &ibox_stat, sizeof ibox_stat))
839 return -EFAULT;
840
841 return 4;
842}
843
5dfe4c96 844static const struct file_operations spufs_ibox_stat_fops = {
67207b96
AB
845 .open = spufs_pipe_open,
846 .read = spufs_ibox_stat_read,
847};
848
849/* low-level mailbox write */
8b3d6663 850size_t spu_wbox_write(struct spu_context *ctx, u32 data)
67207b96 851{
8b3d6663
AB
852 return ctx->ops->wbox_write(ctx, data);
853}
67207b96 854
8b3d6663
AB
855static int spufs_wbox_fasync(int fd, struct file *file, int on)
856{
857 struct spu_context *ctx = file->private_data;
858 int ret;
67207b96 859
8b3d6663 860 ret = fasync_helper(fd, file, on, &ctx->wbox_fasync);
67207b96 861
67207b96
AB
862 return ret;
863}
67207b96 864
8b3d6663
AB
865/* interrupt-level wbox callback function. */
866void spufs_wbox_callback(struct spu *spu)
67207b96 867{
8b3d6663
AB
868 struct spu_context *ctx = spu->ctx;
869
e65c2f6f
LB
870 if (!ctx)
871 return;
872
8b3d6663
AB
873 wake_up_all(&ctx->wbox_wq);
874 kill_fasync(&ctx->wbox_fasync, SIGIO, POLLOUT);
67207b96
AB
875}
876
cdcc89bb
AB
877/*
878 * Write as many bytes to the interrupt mailbox as possible, until
879 * one of the conditions becomes true:
880 *
881 * - the mailbox is full
882 * - end of the user provided buffer
883 * - end of the mapped area
884 *
885 * If the file is opened without O_NONBLOCK, we wait here until
886 * space is availabyl, but return when we have been able to
887 * write something.
888 */
67207b96
AB
889static ssize_t spufs_wbox_write(struct file *file, const char __user *buf,
890 size_t len, loff_t *pos)
891{
8b3d6663 892 struct spu_context *ctx = file->private_data;
cdcc89bb
AB
893 u32 wbox_data, __user *udata;
894 ssize_t count;
67207b96
AB
895
896 if (len < 4)
897 return -EINVAL;
898
cdcc89bb
AB
899 udata = (void __user *)buf;
900 if (!access_ok(VERIFY_READ, buf, len))
901 return -EFAULT;
902
903 if (__get_user(wbox_data, udata))
67207b96
AB
904 return -EFAULT;
905
c9101bdb
CH
906 count = spu_acquire(ctx);
907 if (count)
908 return count;
8b3d6663 909
cdcc89bb
AB
910 /*
911 * make sure we can at least write one element, by waiting
912 * in case of !O_NONBLOCK
913 */
914 count = 0;
67207b96 915 if (file->f_flags & O_NONBLOCK) {
8b3d6663 916 if (!spu_wbox_write(ctx, wbox_data))
cdcc89bb 917 count = -EAGAIN;
67207b96 918 } else {
cdcc89bb 919 count = spufs_wait(ctx->wbox_wq, spu_wbox_write(ctx, wbox_data));
67207b96
AB
920 }
921
cdcc89bb
AB
922 if (count)
923 goto out;
8b3d6663 924
96de0e25 925 /* write as much as possible */
cdcc89bb
AB
926 for (count = 4, udata++; (count + 4) <= len; count += 4, udata++) {
927 int ret;
928 ret = __get_user(wbox_data, udata);
929 if (ret)
930 break;
931
932 ret = spu_wbox_write(ctx, wbox_data);
933 if (ret == 0)
934 break;
935 }
936
937out:
938 spu_release(ctx);
939 return count;
67207b96
AB
940}
941
942static unsigned int spufs_wbox_poll(struct file *file, poll_table *wait)
943{
8b3d6663 944 struct spu_context *ctx = file->private_data;
67207b96
AB
945 unsigned int mask;
946
8b3d6663 947 poll_wait(file, &ctx->wbox_wq, wait);
67207b96 948
c9101bdb
CH
949 /*
950 * For now keep this uninterruptible and also ignore the rule
951 * that poll should not sleep. Will be fixed later.
952 */
953 mutex_lock(&ctx->state_mutex);
3a843d7c
AB
954 mask = ctx->ops->mbox_stat_poll(ctx, POLLOUT | POLLWRNORM);
955 spu_release(ctx);
67207b96
AB
956
957 return mask;
958}
959
5dfe4c96 960static const struct file_operations spufs_wbox_fops = {
67207b96
AB
961 .open = spufs_pipe_open,
962 .write = spufs_wbox_write,
963 .poll = spufs_wbox_poll,
964 .fasync = spufs_wbox_fasync,
965};
966
967static ssize_t spufs_wbox_stat_read(struct file *file, char __user *buf,
968 size_t len, loff_t *pos)
969{
8b3d6663 970 struct spu_context *ctx = file->private_data;
c9101bdb 971 ssize_t ret;
67207b96
AB
972 u32 wbox_stat;
973
974 if (len < 4)
975 return -EINVAL;
976
c9101bdb
CH
977 ret = spu_acquire(ctx);
978 if (ret)
979 return ret;
8b3d6663
AB
980 wbox_stat = (ctx->ops->mbox_stat_read(ctx) >> 8) & 0xff;
981 spu_release(ctx);
67207b96
AB
982
983 if (copy_to_user(buf, &wbox_stat, sizeof wbox_stat))
984 return -EFAULT;
985
986 return 4;
987}
988
5dfe4c96 989static const struct file_operations spufs_wbox_stat_fops = {
67207b96
AB
990 .open = spufs_pipe_open,
991 .read = spufs_wbox_stat_read,
992};
993
6df10a82
MN
994static int spufs_signal1_open(struct inode *inode, struct file *file)
995{
996 struct spufs_inode_info *i = SPUFS_I(inode);
997 struct spu_context *ctx = i->i_ctx;
43c2bbd9 998
47d3a5fa 999 mutex_lock(&ctx->mapping_lock);
6df10a82 1000 file->private_data = ctx;
43c2bbd9
CH
1001 if (!i->i_openers++)
1002 ctx->signal1 = inode->i_mapping;
47d3a5fa 1003 mutex_unlock(&ctx->mapping_lock);
6df10a82
MN
1004 return nonseekable_open(inode, file);
1005}
1006
43c2bbd9
CH
1007static int
1008spufs_signal1_release(struct inode *inode, struct file *file)
1009{
1010 struct spufs_inode_info *i = SPUFS_I(inode);
1011 struct spu_context *ctx = i->i_ctx;
1012
47d3a5fa 1013 mutex_lock(&ctx->mapping_lock);
43c2bbd9
CH
1014 if (!--i->i_openers)
1015 ctx->signal1 = NULL;
47d3a5fa 1016 mutex_unlock(&ctx->mapping_lock);
43c2bbd9
CH
1017 return 0;
1018}
1019
bf1ab978 1020static ssize_t __spufs_signal1_read(struct spu_context *ctx, char __user *buf,
67207b96
AB
1021 size_t len, loff_t *pos)
1022{
17f88ceb 1023 int ret = 0;
67207b96
AB
1024 u32 data;
1025
67207b96
AB
1026 if (len < 4)
1027 return -EINVAL;
1028
17f88ceb
DGM
1029 if (ctx->csa.spu_chnlcnt_RW[3]) {
1030 data = ctx->csa.spu_chnldata_RW[3];
1031 ret = 4;
1032 }
8b3d6663 1033
17f88ceb
DGM
1034 if (!ret)
1035 goto out;
1036
67207b96
AB
1037 if (copy_to_user(buf, &data, 4))
1038 return -EFAULT;
1039
17f88ceb
DGM
1040out:
1041 return ret;
67207b96
AB
1042}
1043
bf1ab978
DGM
1044static ssize_t spufs_signal1_read(struct file *file, char __user *buf,
1045 size_t len, loff_t *pos)
1046{
1047 int ret;
1048 struct spu_context *ctx = file->private_data;
1049
c9101bdb
CH
1050 ret = spu_acquire_saved(ctx);
1051 if (ret)
1052 return ret;
bf1ab978 1053 ret = __spufs_signal1_read(ctx, buf, len, pos);
27b1ea09 1054 spu_release_saved(ctx);
bf1ab978
DGM
1055
1056 return ret;
1057}
1058
67207b96
AB
1059static ssize_t spufs_signal1_write(struct file *file, const char __user *buf,
1060 size_t len, loff_t *pos)
1061{
1062 struct spu_context *ctx;
c9101bdb 1063 ssize_t ret;
67207b96
AB
1064 u32 data;
1065
1066 ctx = file->private_data;
67207b96
AB
1067
1068 if (len < 4)
1069 return -EINVAL;
1070
1071 if (copy_from_user(&data, buf, 4))
1072 return -EFAULT;
1073
c9101bdb
CH
1074 ret = spu_acquire(ctx);
1075 if (ret)
1076 return ret;
8b3d6663
AB
1077 ctx->ops->signal1_write(ctx, data);
1078 spu_release(ctx);
67207b96
AB
1079
1080 return 4;
1081}
1082
78bde53e
BH
1083static unsigned long spufs_signal1_mmap_nopfn(struct vm_area_struct *vma,
1084 unsigned long address)
6df10a82 1085{
27d5bf2a 1086#if PAGE_SIZE == 0x1000
78bde53e 1087 return spufs_ps_nopfn(vma, address, 0x14000, 0x1000);
27d5bf2a
BH
1088#elif PAGE_SIZE == 0x10000
1089 /* For 64k pages, both signal1 and signal2 can be used to mmap the whole
1090 * signal 1 and 2 area
1091 */
78bde53e 1092 return spufs_ps_nopfn(vma, address, 0x10000, 0x10000);
27d5bf2a
BH
1093#else
1094#error unsupported page size
1095#endif
6df10a82
MN
1096}
1097
1098static struct vm_operations_struct spufs_signal1_mmap_vmops = {
78bde53e 1099 .nopfn = spufs_signal1_mmap_nopfn,
6df10a82
MN
1100};
1101
1102static int spufs_signal1_mmap(struct file *file, struct vm_area_struct *vma)
1103{
1104 if (!(vma->vm_flags & VM_SHARED))
1105 return -EINVAL;
1106
78bde53e 1107 vma->vm_flags |= VM_IO | VM_PFNMAP;
6df10a82 1108 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
23cc7701 1109 | _PAGE_NO_CACHE | _PAGE_GUARDED);
6df10a82
MN
1110
1111 vma->vm_ops = &spufs_signal1_mmap_vmops;
1112 return 0;
1113}
6df10a82 1114
5dfe4c96 1115static const struct file_operations spufs_signal1_fops = {
6df10a82 1116 .open = spufs_signal1_open,
43c2bbd9 1117 .release = spufs_signal1_release,
67207b96
AB
1118 .read = spufs_signal1_read,
1119 .write = spufs_signal1_write,
6df10a82 1120 .mmap = spufs_signal1_mmap,
67207b96
AB
1121};
1122
d054b36f
JK
1123static const struct file_operations spufs_signal1_nosched_fops = {
1124 .open = spufs_signal1_open,
1125 .release = spufs_signal1_release,
1126 .write = spufs_signal1_write,
1127 .mmap = spufs_signal1_mmap,
1128};
1129
6df10a82
MN
1130static int spufs_signal2_open(struct inode *inode, struct file *file)
1131{
1132 struct spufs_inode_info *i = SPUFS_I(inode);
1133 struct spu_context *ctx = i->i_ctx;
43c2bbd9 1134
47d3a5fa 1135 mutex_lock(&ctx->mapping_lock);
6df10a82 1136 file->private_data = ctx;
43c2bbd9
CH
1137 if (!i->i_openers++)
1138 ctx->signal2 = inode->i_mapping;
47d3a5fa 1139 mutex_unlock(&ctx->mapping_lock);
6df10a82
MN
1140 return nonseekable_open(inode, file);
1141}
1142
43c2bbd9
CH
1143static int
1144spufs_signal2_release(struct inode *inode, struct file *file)
1145{
1146 struct spufs_inode_info *i = SPUFS_I(inode);
1147 struct spu_context *ctx = i->i_ctx;
1148
47d3a5fa 1149 mutex_lock(&ctx->mapping_lock);
43c2bbd9
CH
1150 if (!--i->i_openers)
1151 ctx->signal2 = NULL;
47d3a5fa 1152 mutex_unlock(&ctx->mapping_lock);
43c2bbd9
CH
1153 return 0;
1154}
1155
bf1ab978 1156static ssize_t __spufs_signal2_read(struct spu_context *ctx, char __user *buf,
67207b96
AB
1157 size_t len, loff_t *pos)
1158{
17f88ceb 1159 int ret = 0;
67207b96
AB
1160 u32 data;
1161
67207b96
AB
1162 if (len < 4)
1163 return -EINVAL;
1164
17f88ceb
DGM
1165 if (ctx->csa.spu_chnlcnt_RW[4]) {
1166 data = ctx->csa.spu_chnldata_RW[4];
1167 ret = 4;
1168 }
8b3d6663 1169
17f88ceb
DGM
1170 if (!ret)
1171 goto out;
1172
67207b96
AB
1173 if (copy_to_user(buf, &data, 4))
1174 return -EFAULT;
1175
17f88ceb 1176out:
bf1ab978
DGM
1177 return ret;
1178}
1179
1180static ssize_t spufs_signal2_read(struct file *file, char __user *buf,
1181 size_t len, loff_t *pos)
1182{
1183 struct spu_context *ctx = file->private_data;
1184 int ret;
1185
c9101bdb
CH
1186 ret = spu_acquire_saved(ctx);
1187 if (ret)
1188 return ret;
bf1ab978 1189 ret = __spufs_signal2_read(ctx, buf, len, pos);
27b1ea09 1190 spu_release_saved(ctx);
bf1ab978
DGM
1191
1192 return ret;
67207b96
AB
1193}
1194
1195static ssize_t spufs_signal2_write(struct file *file, const char __user *buf,
1196 size_t len, loff_t *pos)
1197{
1198 struct spu_context *ctx;
c9101bdb 1199 ssize_t ret;
67207b96
AB
1200 u32 data;
1201
1202 ctx = file->private_data;
67207b96
AB
1203
1204 if (len < 4)
1205 return -EINVAL;
1206
1207 if (copy_from_user(&data, buf, 4))
1208 return -EFAULT;
1209
c9101bdb
CH
1210 ret = spu_acquire(ctx);
1211 if (ret)
1212 return ret;
8b3d6663
AB
1213 ctx->ops->signal2_write(ctx, data);
1214 spu_release(ctx);
67207b96
AB
1215
1216 return 4;
1217}
1218
27d5bf2a 1219#if SPUFS_MMAP_4K
78bde53e
BH
1220static unsigned long spufs_signal2_mmap_nopfn(struct vm_area_struct *vma,
1221 unsigned long address)
6df10a82 1222{
27d5bf2a 1223#if PAGE_SIZE == 0x1000
78bde53e 1224 return spufs_ps_nopfn(vma, address, 0x1c000, 0x1000);
27d5bf2a
BH
1225#elif PAGE_SIZE == 0x10000
1226 /* For 64k pages, both signal1 and signal2 can be used to mmap the whole
1227 * signal 1 and 2 area
1228 */
78bde53e 1229 return spufs_ps_nopfn(vma, address, 0x10000, 0x10000);
27d5bf2a
BH
1230#else
1231#error unsupported page size
1232#endif
6df10a82
MN
1233}
1234
1235static struct vm_operations_struct spufs_signal2_mmap_vmops = {
78bde53e 1236 .nopfn = spufs_signal2_mmap_nopfn,
6df10a82
MN
1237};
1238
1239static int spufs_signal2_mmap(struct file *file, struct vm_area_struct *vma)
1240{
1241 if (!(vma->vm_flags & VM_SHARED))
1242 return -EINVAL;
1243
78bde53e 1244 vma->vm_flags |= VM_IO | VM_PFNMAP;
6df10a82 1245 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
23cc7701 1246 | _PAGE_NO_CACHE | _PAGE_GUARDED);
6df10a82
MN
1247
1248 vma->vm_ops = &spufs_signal2_mmap_vmops;
1249 return 0;
1250}
27d5bf2a
BH
1251#else /* SPUFS_MMAP_4K */
1252#define spufs_signal2_mmap NULL
1253#endif /* !SPUFS_MMAP_4K */
6df10a82 1254
5dfe4c96 1255static const struct file_operations spufs_signal2_fops = {
6df10a82 1256 .open = spufs_signal2_open,
43c2bbd9 1257 .release = spufs_signal2_release,
67207b96
AB
1258 .read = spufs_signal2_read,
1259 .write = spufs_signal2_write,
6df10a82 1260 .mmap = spufs_signal2_mmap,
67207b96
AB
1261};
1262
d054b36f
JK
1263static const struct file_operations spufs_signal2_nosched_fops = {
1264 .open = spufs_signal2_open,
1265 .release = spufs_signal2_release,
1266 .write = spufs_signal2_write,
1267 .mmap = spufs_signal2_mmap,
1268};
1269
104f0cc2
ME
1270/*
1271 * This is a wrapper around DEFINE_SIMPLE_ATTRIBUTE which does the
1272 * work of acquiring (or not) the SPU context before calling through
1273 * to the actual get routine. The set routine is called directly.
1274 */
1275#define SPU_ATTR_NOACQUIRE 0
1276#define SPU_ATTR_ACQUIRE 1
1277#define SPU_ATTR_ACQUIRE_SAVED 2
1278
1279#define DEFINE_SPUFS_ATTRIBUTE(__name, __get, __set, __fmt, __acquire) \
197b1a82 1280static int __##__get(void *data, u64 *val) \
104f0cc2
ME
1281{ \
1282 struct spu_context *ctx = data; \
c9101bdb 1283 int ret = 0; \
104f0cc2
ME
1284 \
1285 if (__acquire == SPU_ATTR_ACQUIRE) { \
c9101bdb
CH
1286 ret = spu_acquire(ctx); \
1287 if (ret) \
1288 return ret; \
197b1a82 1289 *val = __get(ctx); \
104f0cc2
ME
1290 spu_release(ctx); \
1291 } else if (__acquire == SPU_ATTR_ACQUIRE_SAVED) { \
c9101bdb
CH
1292 ret = spu_acquire_saved(ctx); \
1293 if (ret) \
1294 return ret; \
197b1a82 1295 *val = __get(ctx); \
104f0cc2
ME
1296 spu_release_saved(ctx); \
1297 } else \
197b1a82 1298 *val = __get(ctx); \
104f0cc2 1299 \
197b1a82 1300 return 0; \
104f0cc2 1301} \
197b1a82 1302DEFINE_SPUFS_SIMPLE_ATTRIBUTE(__name, __##__get, __set, __fmt);
104f0cc2 1303
197b1a82 1304static int spufs_signal1_type_set(void *data, u64 val)
67207b96
AB
1305{
1306 struct spu_context *ctx = data;
c9101bdb 1307 int ret;
67207b96 1308
c9101bdb
CH
1309 ret = spu_acquire(ctx);
1310 if (ret)
1311 return ret;
8b3d6663
AB
1312 ctx->ops->signal1_type_set(ctx, val);
1313 spu_release(ctx);
197b1a82
CH
1314
1315 return 0;
67207b96
AB
1316}
1317
104f0cc2 1318static u64 spufs_signal1_type_get(struct spu_context *ctx)
bf1ab978 1319{
bf1ab978
DGM
1320 return ctx->ops->signal1_type_get(ctx);
1321}
104f0cc2
ME
1322DEFINE_SPUFS_ATTRIBUTE(spufs_signal1_type, spufs_signal1_type_get,
1323 spufs_signal1_type_set, "%llu", SPU_ATTR_ACQUIRE);
bf1ab978 1324
67207b96 1325
197b1a82 1326static int spufs_signal2_type_set(void *data, u64 val)
67207b96
AB
1327{
1328 struct spu_context *ctx = data;
c9101bdb 1329 int ret;
67207b96 1330
c9101bdb
CH
1331 ret = spu_acquire(ctx);
1332 if (ret)
1333 return ret;
8b3d6663
AB
1334 ctx->ops->signal2_type_set(ctx, val);
1335 spu_release(ctx);
197b1a82
CH
1336
1337 return 0;
67207b96
AB
1338}
1339
104f0cc2 1340static u64 spufs_signal2_type_get(struct spu_context *ctx)
bf1ab978 1341{
bf1ab978
DGM
1342 return ctx->ops->signal2_type_get(ctx);
1343}
104f0cc2
ME
1344DEFINE_SPUFS_ATTRIBUTE(spufs_signal2_type, spufs_signal2_type_get,
1345 spufs_signal2_type_set, "%llu", SPU_ATTR_ACQUIRE);
67207b96 1346
27d5bf2a 1347#if SPUFS_MMAP_4K
78bde53e
BH
1348static unsigned long spufs_mss_mmap_nopfn(struct vm_area_struct *vma,
1349 unsigned long address)
d9379c4b 1350{
78bde53e 1351 return spufs_ps_nopfn(vma, address, 0x0000, 0x1000);
d9379c4b
AB
1352}
1353
1354static struct vm_operations_struct spufs_mss_mmap_vmops = {
78bde53e 1355 .nopfn = spufs_mss_mmap_nopfn,
d9379c4b
AB
1356};
1357
1358/*
1359 * mmap support for problem state MFC DMA area [0x0000 - 0x0fff].
d9379c4b
AB
1360 */
1361static int spufs_mss_mmap(struct file *file, struct vm_area_struct *vma)
1362{
1363 if (!(vma->vm_flags & VM_SHARED))
1364 return -EINVAL;
1365
78bde53e 1366 vma->vm_flags |= VM_IO | VM_PFNMAP;
d9379c4b 1367 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
23cc7701 1368 | _PAGE_NO_CACHE | _PAGE_GUARDED);
d9379c4b
AB
1369
1370 vma->vm_ops = &spufs_mss_mmap_vmops;
1371 return 0;
1372}
27d5bf2a
BH
1373#else /* SPUFS_MMAP_4K */
1374#define spufs_mss_mmap NULL
1375#endif /* !SPUFS_MMAP_4K */
d9379c4b
AB
1376
1377static int spufs_mss_open(struct inode *inode, struct file *file)
1378{
1379 struct spufs_inode_info *i = SPUFS_I(inode);
17e0e270 1380 struct spu_context *ctx = i->i_ctx;
d9379c4b
AB
1381
1382 file->private_data = i->i_ctx;
43c2bbd9 1383
47d3a5fa 1384 mutex_lock(&ctx->mapping_lock);
43c2bbd9
CH
1385 if (!i->i_openers++)
1386 ctx->mss = inode->i_mapping;
47d3a5fa 1387 mutex_unlock(&ctx->mapping_lock);
d9379c4b
AB
1388 return nonseekable_open(inode, file);
1389}
1390
43c2bbd9
CH
1391static int
1392spufs_mss_release(struct inode *inode, struct file *file)
1393{
1394 struct spufs_inode_info *i = SPUFS_I(inode);
1395 struct spu_context *ctx = i->i_ctx;
1396
47d3a5fa 1397 mutex_lock(&ctx->mapping_lock);
43c2bbd9
CH
1398 if (!--i->i_openers)
1399 ctx->mss = NULL;
47d3a5fa 1400 mutex_unlock(&ctx->mapping_lock);
43c2bbd9
CH
1401 return 0;
1402}
1403
5dfe4c96 1404static const struct file_operations spufs_mss_fops = {
d9379c4b 1405 .open = spufs_mss_open,
43c2bbd9 1406 .release = spufs_mss_release,
d9379c4b 1407 .mmap = spufs_mss_mmap,
27d5bf2a
BH
1408};
1409
78bde53e
BH
1410static unsigned long spufs_psmap_mmap_nopfn(struct vm_area_struct *vma,
1411 unsigned long address)
27d5bf2a 1412{
78bde53e 1413 return spufs_ps_nopfn(vma, address, 0x0000, 0x20000);
27d5bf2a
BH
1414}
1415
1416static struct vm_operations_struct spufs_psmap_mmap_vmops = {
78bde53e 1417 .nopfn = spufs_psmap_mmap_nopfn,
27d5bf2a
BH
1418};
1419
1420/*
1421 * mmap support for full problem state area [0x00000 - 0x1ffff].
1422 */
1423static int spufs_psmap_mmap(struct file *file, struct vm_area_struct *vma)
1424{
1425 if (!(vma->vm_flags & VM_SHARED))
1426 return -EINVAL;
1427
78bde53e 1428 vma->vm_flags |= VM_IO | VM_PFNMAP;
27d5bf2a
BH
1429 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
1430 | _PAGE_NO_CACHE | _PAGE_GUARDED);
1431
1432 vma->vm_ops = &spufs_psmap_mmap_vmops;
1433 return 0;
1434}
1435
1436static int spufs_psmap_open(struct inode *inode, struct file *file)
1437{
1438 struct spufs_inode_info *i = SPUFS_I(inode);
17e0e270 1439 struct spu_context *ctx = i->i_ctx;
27d5bf2a 1440
47d3a5fa 1441 mutex_lock(&ctx->mapping_lock);
27d5bf2a 1442 file->private_data = i->i_ctx;
43c2bbd9
CH
1443 if (!i->i_openers++)
1444 ctx->psmap = inode->i_mapping;
47d3a5fa 1445 mutex_unlock(&ctx->mapping_lock);
27d5bf2a
BH
1446 return nonseekable_open(inode, file);
1447}
1448
43c2bbd9
CH
1449static int
1450spufs_psmap_release(struct inode *inode, struct file *file)
1451{
1452 struct spufs_inode_info *i = SPUFS_I(inode);
1453 struct spu_context *ctx = i->i_ctx;
1454
47d3a5fa 1455 mutex_lock(&ctx->mapping_lock);
43c2bbd9
CH
1456 if (!--i->i_openers)
1457 ctx->psmap = NULL;
47d3a5fa 1458 mutex_unlock(&ctx->mapping_lock);
43c2bbd9
CH
1459 return 0;
1460}
1461
5dfe4c96 1462static const struct file_operations spufs_psmap_fops = {
27d5bf2a 1463 .open = spufs_psmap_open,
43c2bbd9 1464 .release = spufs_psmap_release,
27d5bf2a 1465 .mmap = spufs_psmap_mmap,
d9379c4b
AB
1466};
1467
1468
27d5bf2a 1469#if SPUFS_MMAP_4K
78bde53e
BH
1470static unsigned long spufs_mfc_mmap_nopfn(struct vm_area_struct *vma,
1471 unsigned long address)
6df10a82 1472{
78bde53e 1473 return spufs_ps_nopfn(vma, address, 0x3000, 0x1000);
6df10a82
MN
1474}
1475
1476static struct vm_operations_struct spufs_mfc_mmap_vmops = {
78bde53e 1477 .nopfn = spufs_mfc_mmap_nopfn,
6df10a82
MN
1478};
1479
1480/*
1481 * mmap support for problem state MFC DMA area [0x0000 - 0x0fff].
6df10a82
MN
1482 */
1483static int spufs_mfc_mmap(struct file *file, struct vm_area_struct *vma)
1484{
1485 if (!(vma->vm_flags & VM_SHARED))
1486 return -EINVAL;
1487
78bde53e 1488 vma->vm_flags |= VM_IO | VM_PFNMAP;
6df10a82 1489 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
23cc7701 1490 | _PAGE_NO_CACHE | _PAGE_GUARDED);
6df10a82
MN
1491
1492 vma->vm_ops = &spufs_mfc_mmap_vmops;
1493 return 0;
1494}
27d5bf2a
BH
1495#else /* SPUFS_MMAP_4K */
1496#define spufs_mfc_mmap NULL
1497#endif /* !SPUFS_MMAP_4K */
a33a7d73
AB
1498
1499static int spufs_mfc_open(struct inode *inode, struct file *file)
1500{
1501 struct spufs_inode_info *i = SPUFS_I(inode);
1502 struct spu_context *ctx = i->i_ctx;
1503
1504 /* we don't want to deal with DMA into other processes */
1505 if (ctx->owner != current->mm)
1506 return -EINVAL;
1507
1508 if (atomic_read(&inode->i_count) != 1)
1509 return -EBUSY;
1510
47d3a5fa 1511 mutex_lock(&ctx->mapping_lock);
a33a7d73 1512 file->private_data = ctx;
43c2bbd9
CH
1513 if (!i->i_openers++)
1514 ctx->mfc = inode->i_mapping;
47d3a5fa 1515 mutex_unlock(&ctx->mapping_lock);
a33a7d73
AB
1516 return nonseekable_open(inode, file);
1517}
1518
43c2bbd9
CH
1519static int
1520spufs_mfc_release(struct inode *inode, struct file *file)
1521{
1522 struct spufs_inode_info *i = SPUFS_I(inode);
1523 struct spu_context *ctx = i->i_ctx;
1524
47d3a5fa 1525 mutex_lock(&ctx->mapping_lock);
43c2bbd9
CH
1526 if (!--i->i_openers)
1527 ctx->mfc = NULL;
47d3a5fa 1528 mutex_unlock(&ctx->mapping_lock);
43c2bbd9
CH
1529 return 0;
1530}
1531
a33a7d73
AB
1532/* interrupt-level mfc callback function. */
1533void spufs_mfc_callback(struct spu *spu)
1534{
1535 struct spu_context *ctx = spu->ctx;
1536
e65c2f6f
LB
1537 if (!ctx)
1538 return;
1539
a33a7d73
AB
1540 wake_up_all(&ctx->mfc_wq);
1541
1542 pr_debug("%s %s\n", __FUNCTION__, spu->name);
1543 if (ctx->mfc_fasync) {
1544 u32 free_elements, tagstatus;
1545 unsigned int mask;
1546
1547 /* no need for spu_acquire in interrupt context */
1548 free_elements = ctx->ops->get_mfc_free_elements(ctx);
1549 tagstatus = ctx->ops->read_mfc_tagstatus(ctx);
1550
1551 mask = 0;
1552 if (free_elements & 0xffff)
1553 mask |= POLLOUT;
1554 if (tagstatus & ctx->tagwait)
1555 mask |= POLLIN;
1556
1557 kill_fasync(&ctx->mfc_fasync, SIGIO, mask);
1558 }
1559}
1560
1561static int spufs_read_mfc_tagstatus(struct spu_context *ctx, u32 *status)
1562{
1563 /* See if there is one tag group is complete */
1564 /* FIXME we need locking around tagwait */
1565 *status = ctx->ops->read_mfc_tagstatus(ctx) & ctx->tagwait;
1566 ctx->tagwait &= ~*status;
1567 if (*status)
1568 return 1;
1569
1570 /* enable interrupt waiting for any tag group,
1571 may silently fail if interrupts are already enabled */
1572 ctx->ops->set_mfc_query(ctx, ctx->tagwait, 1);
1573 return 0;
1574}
1575
1576static ssize_t spufs_mfc_read(struct file *file, char __user *buffer,
1577 size_t size, loff_t *pos)
1578{
1579 struct spu_context *ctx = file->private_data;
1580 int ret = -EINVAL;
1581 u32 status;
1582
1583 if (size != 4)
1584 goto out;
1585
c9101bdb
CH
1586 ret = spu_acquire(ctx);
1587 if (ret)
1588 return ret;
1589
1590 ret = -EINVAL;
a33a7d73
AB
1591 if (file->f_flags & O_NONBLOCK) {
1592 status = ctx->ops->read_mfc_tagstatus(ctx);
1593 if (!(status & ctx->tagwait))
1594 ret = -EAGAIN;
1595 else
c9101bdb 1596 /* XXX(hch): shouldn't we clear ret here? */
a33a7d73
AB
1597 ctx->tagwait &= ~status;
1598 } else {
1599 ret = spufs_wait(ctx->mfc_wq,
1600 spufs_read_mfc_tagstatus(ctx, &status));
1601 }
1602 spu_release(ctx);
1603
1604 if (ret)
1605 goto out;
1606
1607 ret = 4;
1608 if (copy_to_user(buffer, &status, 4))
1609 ret = -EFAULT;
1610
1611out:
1612 return ret;
1613}
1614
1615static int spufs_check_valid_dma(struct mfc_dma_command *cmd)
1616{
1617 pr_debug("queueing DMA %x %lx %x %x %x\n", cmd->lsa,
1618 cmd->ea, cmd->size, cmd->tag, cmd->cmd);
1619
1620 switch (cmd->cmd) {
1621 case MFC_PUT_CMD:
1622 case MFC_PUTF_CMD:
1623 case MFC_PUTB_CMD:
1624 case MFC_GET_CMD:
1625 case MFC_GETF_CMD:
1626 case MFC_GETB_CMD:
1627 break;
1628 default:
1629 pr_debug("invalid DMA opcode %x\n", cmd->cmd);
1630 return -EIO;
1631 }
1632
1633 if ((cmd->lsa & 0xf) != (cmd->ea &0xf)) {
1634 pr_debug("invalid DMA alignment, ea %lx lsa %x\n",
1635 cmd->ea, cmd->lsa);
1636 return -EIO;
1637 }
1638
1639 switch (cmd->size & 0xf) {
1640 case 1:
1641 break;
1642 case 2:
1643 if (cmd->lsa & 1)
1644 goto error;
1645 break;
1646 case 4:
1647 if (cmd->lsa & 3)
1648 goto error;
1649 break;
1650 case 8:
1651 if (cmd->lsa & 7)
1652 goto error;
1653 break;
1654 case 0:
1655 if (cmd->lsa & 15)
1656 goto error;
1657 break;
1658 error:
1659 default:
1660 pr_debug("invalid DMA alignment %x for size %x\n",
1661 cmd->lsa & 0xf, cmd->size);
1662 return -EIO;
1663 }
1664
1665 if (cmd->size > 16 * 1024) {
1666 pr_debug("invalid DMA size %x\n", cmd->size);
1667 return -EIO;
1668 }
1669
1670 if (cmd->tag & 0xfff0) {
1671 /* we reserve the higher tag numbers for kernel use */
1672 pr_debug("invalid DMA tag\n");
1673 return -EIO;
1674 }
1675
1676 if (cmd->class) {
1677 /* not supported in this version */
1678 pr_debug("invalid DMA class\n");
1679 return -EIO;
1680 }
1681
1682 return 0;
1683}
1684
1685static int spu_send_mfc_command(struct spu_context *ctx,
1686 struct mfc_dma_command cmd,
1687 int *error)
1688{
1689 *error = ctx->ops->send_mfc_command(ctx, &cmd);
1690 if (*error == -EAGAIN) {
1691 /* wait for any tag group to complete
1692 so we have space for the new command */
1693 ctx->ops->set_mfc_query(ctx, ctx->tagwait, 1);
1694 /* try again, because the queue might be
1695 empty again */
1696 *error = ctx->ops->send_mfc_command(ctx, &cmd);
1697 if (*error == -EAGAIN)
1698 return 0;
1699 }
1700 return 1;
1701}
1702
1703static ssize_t spufs_mfc_write(struct file *file, const char __user *buffer,
1704 size_t size, loff_t *pos)
1705{
1706 struct spu_context *ctx = file->private_data;
1707 struct mfc_dma_command cmd;
1708 int ret = -EINVAL;
1709
1710 if (size != sizeof cmd)
1711 goto out;
1712
1713 ret = -EFAULT;
1714 if (copy_from_user(&cmd, buffer, sizeof cmd))
1715 goto out;
1716
1717 ret = spufs_check_valid_dma(&cmd);
1718 if (ret)
1719 goto out;
1720
c9101bdb
CH
1721 ret = spu_acquire(ctx);
1722 if (ret)
1723 goto out;
1724
33bfd7a7 1725 ret = spufs_wait(ctx->run_wq, ctx->state == SPU_STATE_RUNNABLE);
577f8f10
AM
1726 if (ret)
1727 goto out;
1728
a33a7d73
AB
1729 if (file->f_flags & O_NONBLOCK) {
1730 ret = ctx->ops->send_mfc_command(ctx, &cmd);
1731 } else {
1732 int status;
1733 ret = spufs_wait(ctx->mfc_wq,
1734 spu_send_mfc_command(ctx, cmd, &status));
1735 if (status)
1736 ret = status;
1737 }
a33a7d73
AB
1738
1739 if (ret)
933b0e35 1740 goto out_unlock;
a33a7d73
AB
1741
1742 ctx->tagwait |= 1 << cmd.tag;
3692dc66 1743 ret = size;
a33a7d73 1744
933b0e35
KA
1745out_unlock:
1746 spu_release(ctx);
a33a7d73
AB
1747out:
1748 return ret;
1749}
1750
1751static unsigned int spufs_mfc_poll(struct file *file,poll_table *wait)
1752{
1753 struct spu_context *ctx = file->private_data;
1754 u32 free_elements, tagstatus;
1755 unsigned int mask;
1756
933b0e35
KA
1757 poll_wait(file, &ctx->mfc_wq, wait);
1758
c9101bdb
CH
1759 /*
1760 * For now keep this uninterruptible and also ignore the rule
1761 * that poll should not sleep. Will be fixed later.
1762 */
1763 mutex_lock(&ctx->state_mutex);
a33a7d73
AB
1764 ctx->ops->set_mfc_query(ctx, ctx->tagwait, 2);
1765 free_elements = ctx->ops->get_mfc_free_elements(ctx);
1766 tagstatus = ctx->ops->read_mfc_tagstatus(ctx);
1767 spu_release(ctx);
1768
a33a7d73
AB
1769 mask = 0;
1770 if (free_elements & 0xffff)
1771 mask |= POLLOUT | POLLWRNORM;
1772 if (tagstatus & ctx->tagwait)
1773 mask |= POLLIN | POLLRDNORM;
1774
1775 pr_debug("%s: free %d tagstatus %d tagwait %d\n", __FUNCTION__,
1776 free_elements, tagstatus, ctx->tagwait);
1777
1778 return mask;
1779}
1780
73b6af8a 1781static int spufs_mfc_flush(struct file *file, fl_owner_t id)
a33a7d73
AB
1782{
1783 struct spu_context *ctx = file->private_data;
1784 int ret;
1785
c9101bdb
CH
1786 ret = spu_acquire(ctx);
1787 if (ret)
1788 return ret;
a33a7d73
AB
1789#if 0
1790/* this currently hangs */
1791 ret = spufs_wait(ctx->mfc_wq,
1792 ctx->ops->set_mfc_query(ctx, ctx->tagwait, 2));
1793 if (ret)
1794 goto out;
1795 ret = spufs_wait(ctx->mfc_wq,
1796 ctx->ops->read_mfc_tagstatus(ctx) == ctx->tagwait);
1797out:
1798#else
1799 ret = 0;
1800#endif
1801 spu_release(ctx);
1802
1803 return ret;
1804}
1805
1806static int spufs_mfc_fsync(struct file *file, struct dentry *dentry,
1807 int datasync)
1808{
73b6af8a 1809 return spufs_mfc_flush(file, NULL);
a33a7d73
AB
1810}
1811
1812static int spufs_mfc_fasync(int fd, struct file *file, int on)
1813{
1814 struct spu_context *ctx = file->private_data;
1815
1816 return fasync_helper(fd, file, on, &ctx->mfc_fasync);
1817}
1818
5dfe4c96 1819static const struct file_operations spufs_mfc_fops = {
a33a7d73 1820 .open = spufs_mfc_open,
43c2bbd9 1821 .release = spufs_mfc_release,
a33a7d73
AB
1822 .read = spufs_mfc_read,
1823 .write = spufs_mfc_write,
1824 .poll = spufs_mfc_poll,
1825 .flush = spufs_mfc_flush,
1826 .fsync = spufs_mfc_fsync,
1827 .fasync = spufs_mfc_fasync,
6df10a82 1828 .mmap = spufs_mfc_mmap,
a33a7d73
AB
1829};
1830
197b1a82 1831static int spufs_npc_set(void *data, u64 val)
67207b96
AB
1832{
1833 struct spu_context *ctx = data;
c9101bdb
CH
1834 int ret;
1835
1836 ret = spu_acquire(ctx);
1837 if (ret)
1838 return ret;
8b3d6663
AB
1839 ctx->ops->npc_write(ctx, val);
1840 spu_release(ctx);
197b1a82
CH
1841
1842 return 0;
67207b96
AB
1843}
1844
104f0cc2 1845static u64 spufs_npc_get(struct spu_context *ctx)
78810ff6
ME
1846{
1847 return ctx->ops->npc_read(ctx);
1848}
104f0cc2
ME
1849DEFINE_SPUFS_ATTRIBUTE(spufs_npc_ops, spufs_npc_get, spufs_npc_set,
1850 "0x%llx\n", SPU_ATTR_ACQUIRE);
67207b96 1851
197b1a82 1852static int spufs_decr_set(void *data, u64 val)
8b3d6663
AB
1853{
1854 struct spu_context *ctx = data;
1855 struct spu_lscsa *lscsa = ctx->csa.lscsa;
c9101bdb
CH
1856 int ret;
1857
1858 ret = spu_acquire_saved(ctx);
1859 if (ret)
1860 return ret;
8b3d6663 1861 lscsa->decr.slot[0] = (u32) val;
27b1ea09 1862 spu_release_saved(ctx);
197b1a82
CH
1863
1864 return 0;
8b3d6663
AB
1865}
1866
104f0cc2 1867static u64 spufs_decr_get(struct spu_context *ctx)
8b3d6663 1868{
8b3d6663 1869 struct spu_lscsa *lscsa = ctx->csa.lscsa;
bf1ab978
DGM
1870 return lscsa->decr.slot[0];
1871}
104f0cc2
ME
1872DEFINE_SPUFS_ATTRIBUTE(spufs_decr_ops, spufs_decr_get, spufs_decr_set,
1873 "0x%llx\n", SPU_ATTR_ACQUIRE_SAVED);
8b3d6663 1874
197b1a82 1875static int spufs_decr_status_set(void *data, u64 val)
8b3d6663
AB
1876{
1877 struct spu_context *ctx = data;
c9101bdb
CH
1878 int ret;
1879
1880 ret = spu_acquire_saved(ctx);
1881 if (ret)
1882 return ret;
d40a01d4
MN
1883 if (val)
1884 ctx->csa.priv2.mfc_control_RW |= MFC_CNTL_DECREMENTER_RUNNING;
1885 else
1886 ctx->csa.priv2.mfc_control_RW &= ~MFC_CNTL_DECREMENTER_RUNNING;
27b1ea09 1887 spu_release_saved(ctx);
197b1a82
CH
1888
1889 return 0;
8b3d6663
AB
1890}
1891
104f0cc2 1892static u64 spufs_decr_status_get(struct spu_context *ctx)
8b3d6663 1893{
d40a01d4
MN
1894 if (ctx->csa.priv2.mfc_control_RW & MFC_CNTL_DECREMENTER_RUNNING)
1895 return SPU_DECR_STATUS_RUNNING;
1896 else
1897 return 0;
bf1ab978 1898}
104f0cc2
ME
1899DEFINE_SPUFS_ATTRIBUTE(spufs_decr_status_ops, spufs_decr_status_get,
1900 spufs_decr_status_set, "0x%llx\n",
1901 SPU_ATTR_ACQUIRE_SAVED);
8b3d6663 1902
197b1a82 1903static int spufs_event_mask_set(void *data, u64 val)
8b3d6663
AB
1904{
1905 struct spu_context *ctx = data;
1906 struct spu_lscsa *lscsa = ctx->csa.lscsa;
c9101bdb
CH
1907 int ret;
1908
1909 ret = spu_acquire_saved(ctx);
1910 if (ret)
1911 return ret;
8b3d6663 1912 lscsa->event_mask.slot[0] = (u32) val;
27b1ea09 1913 spu_release_saved(ctx);
197b1a82
CH
1914
1915 return 0;
8b3d6663
AB
1916}
1917
104f0cc2 1918static u64 spufs_event_mask_get(struct spu_context *ctx)
8b3d6663 1919{
8b3d6663 1920 struct spu_lscsa *lscsa = ctx->csa.lscsa;
bf1ab978
DGM
1921 return lscsa->event_mask.slot[0];
1922}
1923
104f0cc2
ME
1924DEFINE_SPUFS_ATTRIBUTE(spufs_event_mask_ops, spufs_event_mask_get,
1925 spufs_event_mask_set, "0x%llx\n",
1926 SPU_ATTR_ACQUIRE_SAVED);
8b3d6663 1927
104f0cc2 1928static u64 spufs_event_status_get(struct spu_context *ctx)
b9e3bd77 1929{
b9e3bd77 1930 struct spu_state *state = &ctx->csa;
b9e3bd77 1931 u64 stat;
b9e3bd77
DGM
1932 stat = state->spu_chnlcnt_RW[0];
1933 if (stat)
bf1ab978
DGM
1934 return state->spu_chnldata_RW[0];
1935 return 0;
1936}
104f0cc2
ME
1937DEFINE_SPUFS_ATTRIBUTE(spufs_event_status_ops, spufs_event_status_get,
1938 NULL, "0x%llx\n", SPU_ATTR_ACQUIRE_SAVED)
b9e3bd77 1939
197b1a82 1940static int spufs_srr0_set(void *data, u64 val)
8b3d6663
AB
1941{
1942 struct spu_context *ctx = data;
1943 struct spu_lscsa *lscsa = ctx->csa.lscsa;
c9101bdb
CH
1944 int ret;
1945
1946 ret = spu_acquire_saved(ctx);
1947 if (ret)
1948 return ret;
8b3d6663 1949 lscsa->srr0.slot[0] = (u32) val;
27b1ea09 1950 spu_release_saved(ctx);
197b1a82
CH
1951
1952 return 0;
8b3d6663
AB
1953}
1954
104f0cc2 1955static u64 spufs_srr0_get(struct spu_context *ctx)
8b3d6663 1956{
8b3d6663 1957 struct spu_lscsa *lscsa = ctx->csa.lscsa;
104f0cc2 1958 return lscsa->srr0.slot[0];
8b3d6663 1959}
104f0cc2
ME
1960DEFINE_SPUFS_ATTRIBUTE(spufs_srr0_ops, spufs_srr0_get, spufs_srr0_set,
1961 "0x%llx\n", SPU_ATTR_ACQUIRE_SAVED)
8b3d6663 1962
104f0cc2 1963static u64 spufs_id_get(struct spu_context *ctx)
7b1a7014 1964{
7b1a7014
AB
1965 u64 num;
1966
7b1a7014
AB
1967 if (ctx->state == SPU_STATE_RUNNABLE)
1968 num = ctx->spu->number;
1969 else
1970 num = (unsigned int)-1;
7b1a7014
AB
1971
1972 return num;
1973}
104f0cc2
ME
1974DEFINE_SPUFS_ATTRIBUTE(spufs_id_ops, spufs_id_get, NULL, "0x%llx\n",
1975 SPU_ATTR_ACQUIRE)
7b1a7014 1976
104f0cc2 1977static u64 spufs_object_id_get(struct spu_context *ctx)
bf1ab978
DGM
1978{
1979 /* FIXME: Should there really be no locking here? */
104f0cc2 1980 return ctx->object_id;
bf1ab978
DGM
1981}
1982
197b1a82 1983static int spufs_object_id_set(void *data, u64 id)
86767277
AB
1984{
1985 struct spu_context *ctx = data;
1986 ctx->object_id = id;
197b1a82
CH
1987
1988 return 0;
86767277
AB
1989}
1990
104f0cc2
ME
1991DEFINE_SPUFS_ATTRIBUTE(spufs_object_id_ops, spufs_object_id_get,
1992 spufs_object_id_set, "0x%llx\n", SPU_ATTR_NOACQUIRE);
86767277 1993
104f0cc2 1994static u64 spufs_lslr_get(struct spu_context *ctx)
bf1ab978 1995{
bf1ab978
DGM
1996 return ctx->csa.priv2.spu_lslr_RW;
1997}
104f0cc2
ME
1998DEFINE_SPUFS_ATTRIBUTE(spufs_lslr_ops, spufs_lslr_get, NULL, "0x%llx\n",
1999 SPU_ATTR_ACQUIRE_SAVED);
b9e3bd77
DGM
2000
2001static int spufs_info_open(struct inode *inode, struct file *file)
2002{
2003 struct spufs_inode_info *i = SPUFS_I(inode);
2004 struct spu_context *ctx = i->i_ctx;
2005 file->private_data = ctx;
2006 return 0;
2007}
2008
cbe709c1
BH
2009static int spufs_caps_show(struct seq_file *s, void *private)
2010{
2011 struct spu_context *ctx = s->private;
2012
2013 if (!(ctx->flags & SPU_CREATE_NOSCHED))
2014 seq_puts(s, "sched\n");
2015 if (!(ctx->flags & SPU_CREATE_ISOLATE))
2016 seq_puts(s, "step\n");
2017 return 0;
2018}
2019
2020static int spufs_caps_open(struct inode *inode, struct file *file)
2021{
2022 return single_open(file, spufs_caps_show, SPUFS_I(inode)->i_ctx);
2023}
2024
2025static const struct file_operations spufs_caps_fops = {
2026 .open = spufs_caps_open,
2027 .read = seq_read,
2028 .llseek = seq_lseek,
2029 .release = single_release,
2030};
2031
bf1ab978
DGM
2032static ssize_t __spufs_mbox_info_read(struct spu_context *ctx,
2033 char __user *buf, size_t len, loff_t *pos)
2034{
bf1ab978
DGM
2035 u32 data;
2036
cbea9238
JK
2037 /* EOF if there's no entry in the mbox */
2038 if (!(ctx->csa.prob.mb_stat_R & 0x0000ff))
2039 return 0;
2040
2041 data = ctx->csa.prob.pu_mb_R;
bf1ab978
DGM
2042
2043 return simple_read_from_buffer(buf, len, pos, &data, sizeof data);
2044}
2045
69a2f00c
DGM
2046static ssize_t spufs_mbox_info_read(struct file *file, char __user *buf,
2047 size_t len, loff_t *pos)
2048{
bf1ab978 2049 int ret;
69a2f00c 2050 struct spu_context *ctx = file->private_data;
69a2f00c
DGM
2051
2052 if (!access_ok(VERIFY_WRITE, buf, len))
2053 return -EFAULT;
2054
c9101bdb
CH
2055 ret = spu_acquire_saved(ctx);
2056 if (ret)
2057 return ret;
69a2f00c 2058 spin_lock(&ctx->csa.register_lock);
bf1ab978 2059 ret = __spufs_mbox_info_read(ctx, buf, len, pos);
69a2f00c 2060 spin_unlock(&ctx->csa.register_lock);
27b1ea09 2061 spu_release_saved(ctx);
69a2f00c 2062
bf1ab978 2063 return ret;
69a2f00c
DGM
2064}
2065
5dfe4c96 2066static const struct file_operations spufs_mbox_info_fops = {
69a2f00c
DGM
2067 .open = spufs_info_open,
2068 .read = spufs_mbox_info_read,
2069 .llseek = generic_file_llseek,
2070};
2071
bf1ab978
DGM
2072static ssize_t __spufs_ibox_info_read(struct spu_context *ctx,
2073 char __user *buf, size_t len, loff_t *pos)
2074{
bf1ab978
DGM
2075 u32 data;
2076
cbea9238
JK
2077 /* EOF if there's no entry in the ibox */
2078 if (!(ctx->csa.prob.mb_stat_R & 0xff0000))
2079 return 0;
2080
2081 data = ctx->csa.priv2.puint_mb_R;
bf1ab978
DGM
2082
2083 return simple_read_from_buffer(buf, len, pos, &data, sizeof data);
2084}
2085
69a2f00c
DGM
2086static ssize_t spufs_ibox_info_read(struct file *file, char __user *buf,
2087 size_t len, loff_t *pos)
2088{
2089 struct spu_context *ctx = file->private_data;
bf1ab978 2090 int ret;
69a2f00c
DGM
2091
2092 if (!access_ok(VERIFY_WRITE, buf, len))
2093 return -EFAULT;
2094
c9101bdb
CH
2095 ret = spu_acquire_saved(ctx);
2096 if (ret)
2097 return ret;
69a2f00c 2098 spin_lock(&ctx->csa.register_lock);
bf1ab978 2099 ret = __spufs_ibox_info_read(ctx, buf, len, pos);
69a2f00c 2100 spin_unlock(&ctx->csa.register_lock);
27b1ea09 2101 spu_release_saved(ctx);
69a2f00c 2102
bf1ab978 2103 return ret;
69a2f00c
DGM
2104}
2105
5dfe4c96 2106static const struct file_operations spufs_ibox_info_fops = {
69a2f00c
DGM
2107 .open = spufs_info_open,
2108 .read = spufs_ibox_info_read,
2109 .llseek = generic_file_llseek,
2110};
2111
bf1ab978
DGM
2112static ssize_t __spufs_wbox_info_read(struct spu_context *ctx,
2113 char __user *buf, size_t len, loff_t *pos)
69a2f00c 2114{
69a2f00c
DGM
2115 int i, cnt;
2116 u32 data[4];
2117 u32 wbox_stat;
2118
bf1ab978
DGM
2119 wbox_stat = ctx->csa.prob.mb_stat_R;
2120 cnt = 4 - ((wbox_stat & 0x00ff00) >> 8);
2121 for (i = 0; i < cnt; i++) {
2122 data[i] = ctx->csa.spu_mailbox_data[i];
2123 }
2124
2125 return simple_read_from_buffer(buf, len, pos, &data,
2126 cnt * sizeof(u32));
2127}
2128
2129static ssize_t spufs_wbox_info_read(struct file *file, char __user *buf,
2130 size_t len, loff_t *pos)
2131{
2132 struct spu_context *ctx = file->private_data;
2133 int ret;
2134
69a2f00c
DGM
2135 if (!access_ok(VERIFY_WRITE, buf, len))
2136 return -EFAULT;
2137
c9101bdb
CH
2138 ret = spu_acquire_saved(ctx);
2139 if (ret)
2140 return ret;
69a2f00c 2141 spin_lock(&ctx->csa.register_lock);
bf1ab978 2142 ret = __spufs_wbox_info_read(ctx, buf, len, pos);
69a2f00c 2143 spin_unlock(&ctx->csa.register_lock);
27b1ea09 2144 spu_release_saved(ctx);
69a2f00c 2145
bf1ab978 2146 return ret;
69a2f00c
DGM
2147}
2148
5dfe4c96 2149static const struct file_operations spufs_wbox_info_fops = {
69a2f00c
DGM
2150 .open = spufs_info_open,
2151 .read = spufs_wbox_info_read,
2152 .llseek = generic_file_llseek,
2153};
2154
bf1ab978
DGM
2155static ssize_t __spufs_dma_info_read(struct spu_context *ctx,
2156 char __user *buf, size_t len, loff_t *pos)
b9e3bd77 2157{
b9e3bd77
DGM
2158 struct spu_dma_info info;
2159 struct mfc_cq_sr *qp, *spuqp;
2160 int i;
2161
b9e3bd77
DGM
2162 info.dma_info_type = ctx->csa.priv2.spu_tag_status_query_RW;
2163 info.dma_info_mask = ctx->csa.lscsa->tag_mask.slot[0];
2164 info.dma_info_status = ctx->csa.spu_chnldata_RW[24];
2165 info.dma_info_stall_and_notify = ctx->csa.spu_chnldata_RW[25];
2166 info.dma_info_atomic_command_status = ctx->csa.spu_chnldata_RW[27];
2167 for (i = 0; i < 16; i++) {
2168 qp = &info.dma_info_command_data[i];
2169 spuqp = &ctx->csa.priv2.spuq[i];
2170
2171 qp->mfc_cq_data0_RW = spuqp->mfc_cq_data0_RW;
2172 qp->mfc_cq_data1_RW = spuqp->mfc_cq_data1_RW;
2173 qp->mfc_cq_data2_RW = spuqp->mfc_cq_data2_RW;
2174 qp->mfc_cq_data3_RW = spuqp->mfc_cq_data3_RW;
2175 }
b9e3bd77
DGM
2176
2177 return simple_read_from_buffer(buf, len, pos, &info,
2178 sizeof info);
2179}
2180
bf1ab978
DGM
2181static ssize_t spufs_dma_info_read(struct file *file, char __user *buf,
2182 size_t len, loff_t *pos)
2183{
2184 struct spu_context *ctx = file->private_data;
2185 int ret;
2186
2187 if (!access_ok(VERIFY_WRITE, buf, len))
2188 return -EFAULT;
2189
c9101bdb
CH
2190 ret = spu_acquire_saved(ctx);
2191 if (ret)
2192 return ret;
bf1ab978
DGM
2193 spin_lock(&ctx->csa.register_lock);
2194 ret = __spufs_dma_info_read(ctx, buf, len, pos);
2195 spin_unlock(&ctx->csa.register_lock);
27b1ea09 2196 spu_release_saved(ctx);
bf1ab978
DGM
2197
2198 return ret;
2199}
2200
5dfe4c96 2201static const struct file_operations spufs_dma_info_fops = {
b9e3bd77
DGM
2202 .open = spufs_info_open,
2203 .read = spufs_dma_info_read,
2204};
2205
bf1ab978
DGM
2206static ssize_t __spufs_proxydma_info_read(struct spu_context *ctx,
2207 char __user *buf, size_t len, loff_t *pos)
b9e3bd77 2208{
b9e3bd77 2209 struct spu_proxydma_info info;
b9e3bd77 2210 struct mfc_cq_sr *qp, *puqp;
bf1ab978 2211 int ret = sizeof info;
b9e3bd77
DGM
2212 int i;
2213
2214 if (len < ret)
2215 return -EINVAL;
2216
2217 if (!access_ok(VERIFY_WRITE, buf, len))
2218 return -EFAULT;
2219
b9e3bd77
DGM
2220 info.proxydma_info_type = ctx->csa.prob.dma_querytype_RW;
2221 info.proxydma_info_mask = ctx->csa.prob.dma_querymask_RW;
2222 info.proxydma_info_status = ctx->csa.prob.dma_tagstatus_R;
2223 for (i = 0; i < 8; i++) {
2224 qp = &info.proxydma_info_command_data[i];
2225 puqp = &ctx->csa.priv2.puq[i];
2226
2227 qp->mfc_cq_data0_RW = puqp->mfc_cq_data0_RW;
2228 qp->mfc_cq_data1_RW = puqp->mfc_cq_data1_RW;
2229 qp->mfc_cq_data2_RW = puqp->mfc_cq_data2_RW;
2230 qp->mfc_cq_data3_RW = puqp->mfc_cq_data3_RW;
2231 }
bf1ab978
DGM
2232
2233 return simple_read_from_buffer(buf, len, pos, &info,
2234 sizeof info);
2235}
2236
2237static ssize_t spufs_proxydma_info_read(struct file *file, char __user *buf,
2238 size_t len, loff_t *pos)
2239{
2240 struct spu_context *ctx = file->private_data;
2241 int ret;
2242
c9101bdb
CH
2243 ret = spu_acquire_saved(ctx);
2244 if (ret)
2245 return ret;
bf1ab978
DGM
2246 spin_lock(&ctx->csa.register_lock);
2247 ret = __spufs_proxydma_info_read(ctx, buf, len, pos);
b9e3bd77 2248 spin_unlock(&ctx->csa.register_lock);
27b1ea09 2249 spu_release_saved(ctx);
b9e3bd77 2250
b9e3bd77
DGM
2251 return ret;
2252}
2253
5dfe4c96 2254static const struct file_operations spufs_proxydma_info_fops = {
b9e3bd77
DGM
2255 .open = spufs_info_open,
2256 .read = spufs_proxydma_info_read,
2257};
2258
476273ad
CH
2259static int spufs_show_tid(struct seq_file *s, void *private)
2260{
2261 struct spu_context *ctx = s->private;
2262
2263 seq_printf(s, "%d\n", ctx->tid);
2264 return 0;
2265}
2266
2267static int spufs_tid_open(struct inode *inode, struct file *file)
2268{
2269 return single_open(file, spufs_show_tid, SPUFS_I(inode)->i_ctx);
2270}
2271
2272static const struct file_operations spufs_tid_fops = {
2273 .open = spufs_tid_open,
2274 .read = seq_read,
2275 .llseek = seq_lseek,
2276 .release = single_release,
2277};
2278
e9f8a0b6
CH
2279static const char *ctx_state_names[] = {
2280 "user", "system", "iowait", "loaded"
2281};
2282
2283static unsigned long long spufs_acct_time(struct spu_context *ctx,
27ec41d3 2284 enum spu_utilization_state state)
e9f8a0b6 2285{
27ec41d3
AD
2286 struct timespec ts;
2287 unsigned long long time = ctx->stats.times[state];
e9f8a0b6 2288
27ec41d3
AD
2289 /*
2290 * In general, utilization statistics are updated by the controlling
2291 * thread as the spu context moves through various well defined
2292 * state transitions, but if the context is lazily loaded its
2293 * utilization statistics are not updated as the controlling thread
2294 * is not tightly coupled with the execution of the spu context. We
2295 * calculate and apply the time delta from the last recorded state
2296 * of the spu context.
2297 */
2298 if (ctx->spu && ctx->stats.util_state == state) {
2299 ktime_get_ts(&ts);
2300 time += timespec_to_ns(&ts) - ctx->stats.tstamp;
2301 }
e9f8a0b6 2302
27ec41d3 2303 return time / NSEC_PER_MSEC;
e9f8a0b6
CH
2304}
2305
2306static unsigned long long spufs_slb_flts(struct spu_context *ctx)
2307{
2308 unsigned long long slb_flts = ctx->stats.slb_flt;
2309
2310 if (ctx->state == SPU_STATE_RUNNABLE) {
2311 slb_flts += (ctx->spu->stats.slb_flt -
2312 ctx->stats.slb_flt_base);
2313 }
2314
2315 return slb_flts;
2316}
2317
2318static unsigned long long spufs_class2_intrs(struct spu_context *ctx)
2319{
2320 unsigned long long class2_intrs = ctx->stats.class2_intr;
2321
2322 if (ctx->state == SPU_STATE_RUNNABLE) {
2323 class2_intrs += (ctx->spu->stats.class2_intr -
2324 ctx->stats.class2_intr_base);
2325 }
2326
2327 return class2_intrs;
2328}
2329
2330
2331static int spufs_show_stat(struct seq_file *s, void *private)
2332{
2333 struct spu_context *ctx = s->private;
c9101bdb
CH
2334 int ret;
2335
2336 ret = spu_acquire(ctx);
2337 if (ret)
2338 return ret;
e9f8a0b6 2339
e9f8a0b6
CH
2340 seq_printf(s, "%s %llu %llu %llu %llu "
2341 "%llu %llu %llu %llu %llu %llu %llu %llu\n",
27ec41d3
AD
2342 ctx_state_names[ctx->stats.util_state],
2343 spufs_acct_time(ctx, SPU_UTIL_USER),
2344 spufs_acct_time(ctx, SPU_UTIL_SYSTEM),
2345 spufs_acct_time(ctx, SPU_UTIL_IOWAIT),
2346 spufs_acct_time(ctx, SPU_UTIL_IDLE_LOADED),
e9f8a0b6
CH
2347 ctx->stats.vol_ctx_switch,
2348 ctx->stats.invol_ctx_switch,
2349 spufs_slb_flts(ctx),
2350 ctx->stats.hash_flt,
2351 ctx->stats.min_flt,
2352 ctx->stats.maj_flt,
2353 spufs_class2_intrs(ctx),
2354 ctx->stats.libassist);
2355 spu_release(ctx);
2356 return 0;
2357}
2358
2359static int spufs_stat_open(struct inode *inode, struct file *file)
2360{
2361 return single_open(file, spufs_show_stat, SPUFS_I(inode)->i_ctx);
2362}
2363
2364static const struct file_operations spufs_stat_fops = {
2365 .open = spufs_stat_open,
2366 .read = seq_read,
2367 .llseek = seq_lseek,
2368 .release = single_release,
2369};
2370
2371
67207b96 2372struct tree_descr spufs_dir_contents[] = {
cbe709c1 2373 { "capabilities", &spufs_caps_fops, 0444, },
67207b96 2374 { "mem", &spufs_mem_fops, 0666, },
8b3d6663 2375 { "regs", &spufs_regs_fops, 0666, },
67207b96
AB
2376 { "mbox", &spufs_mbox_fops, 0444, },
2377 { "ibox", &spufs_ibox_fops, 0444, },
2378 { "wbox", &spufs_wbox_fops, 0222, },
2379 { "mbox_stat", &spufs_mbox_stat_fops, 0444, },
2380 { "ibox_stat", &spufs_ibox_stat_fops, 0444, },
2381 { "wbox_stat", &spufs_wbox_stat_fops, 0444, },
603c4612
JK
2382 { "signal1", &spufs_signal1_fops, 0666, },
2383 { "signal2", &spufs_signal2_fops, 0666, },
67207b96
AB
2384 { "signal1_type", &spufs_signal1_type, 0666, },
2385 { "signal2_type", &spufs_signal2_type, 0666, },
6df10a82 2386 { "cntl", &spufs_cntl_fops, 0666, },
8b3d6663 2387 { "fpcr", &spufs_fpcr_fops, 0666, },
b9e3bd77
DGM
2388 { "lslr", &spufs_lslr_ops, 0444, },
2389 { "mfc", &spufs_mfc_fops, 0666, },
2390 { "mss", &spufs_mss_fops, 0666, },
2391 { "npc", &spufs_npc_ops, 0666, },
2392 { "srr0", &spufs_srr0_ops, 0666, },
8b3d6663
AB
2393 { "decr", &spufs_decr_ops, 0666, },
2394 { "decr_status", &spufs_decr_status_ops, 0666, },
8b3d6663 2395 { "event_mask", &spufs_event_mask_ops, 0666, },
b9e3bd77 2396 { "event_status", &spufs_event_status_ops, 0444, },
27d5bf2a 2397 { "psmap", &spufs_psmap_fops, 0666, },
86767277
AB
2398 { "phys-id", &spufs_id_ops, 0666, },
2399 { "object-id", &spufs_object_id_ops, 0666, },
69a2f00c
DGM
2400 { "mbox_info", &spufs_mbox_info_fops, 0444, },
2401 { "ibox_info", &spufs_ibox_info_fops, 0444, },
2402 { "wbox_info", &spufs_wbox_info_fops, 0444, },
b9e3bd77
DGM
2403 { "dma_info", &spufs_dma_info_fops, 0444, },
2404 { "proxydma_info", &spufs_proxydma_info_fops, 0444, },
476273ad 2405 { "tid", &spufs_tid_fops, 0444, },
e9f8a0b6 2406 { "stat", &spufs_stat_fops, 0444, },
67207b96
AB
2407 {},
2408};
5737edd1
MN
2409
2410struct tree_descr spufs_dir_nosched_contents[] = {
cbe709c1 2411 { "capabilities", &spufs_caps_fops, 0444, },
5737edd1
MN
2412 { "mem", &spufs_mem_fops, 0666, },
2413 { "mbox", &spufs_mbox_fops, 0444, },
2414 { "ibox", &spufs_ibox_fops, 0444, },
2415 { "wbox", &spufs_wbox_fops, 0222, },
2416 { "mbox_stat", &spufs_mbox_stat_fops, 0444, },
2417 { "ibox_stat", &spufs_ibox_stat_fops, 0444, },
2418 { "wbox_stat", &spufs_wbox_stat_fops, 0444, },
d054b36f
JK
2419 { "signal1", &spufs_signal1_nosched_fops, 0222, },
2420 { "signal2", &spufs_signal2_nosched_fops, 0222, },
5737edd1
MN
2421 { "signal1_type", &spufs_signal1_type, 0666, },
2422 { "signal2_type", &spufs_signal2_type, 0666, },
2423 { "mss", &spufs_mss_fops, 0666, },
2424 { "mfc", &spufs_mfc_fops, 0666, },
2425 { "cntl", &spufs_cntl_fops, 0666, },
2426 { "npc", &spufs_npc_ops, 0666, },
2427 { "psmap", &spufs_psmap_fops, 0666, },
2428 { "phys-id", &spufs_id_ops, 0666, },
2429 { "object-id", &spufs_object_id_ops, 0666, },
476273ad 2430 { "tid", &spufs_tid_fops, 0444, },
e9f8a0b6 2431 { "stat", &spufs_stat_fops, 0444, },
5737edd1
MN
2432 {},
2433};
bf1ab978
DGM
2434
2435struct spufs_coredump_reader spufs_coredump_read[] = {
4fca9c42
ME
2436 { "regs", __spufs_regs_read, NULL, sizeof(struct spu_reg128[128])},
2437 { "fpcr", __spufs_fpcr_read, NULL, sizeof(struct spu_reg128) },
104f0cc2
ME
2438 { "lslr", NULL, spufs_lslr_get, 19 },
2439 { "decr", NULL, spufs_decr_get, 19 },
2440 { "decr_status", NULL, spufs_decr_status_get, 19 },
4fca9c42
ME
2441 { "mem", __spufs_mem_read, NULL, LS_SIZE, },
2442 { "signal1", __spufs_signal1_read, NULL, sizeof(u32) },
104f0cc2 2443 { "signal1_type", NULL, spufs_signal1_type_get, 19 },
4fca9c42 2444 { "signal2", __spufs_signal2_read, NULL, sizeof(u32) },
104f0cc2
ME
2445 { "signal2_type", NULL, spufs_signal2_type_get, 19 },
2446 { "event_mask", NULL, spufs_event_mask_get, 19 },
2447 { "event_status", NULL, spufs_event_status_get, 19 },
4fca9c42
ME
2448 { "mbox_info", __spufs_mbox_info_read, NULL, sizeof(u32) },
2449 { "ibox_info", __spufs_ibox_info_read, NULL, sizeof(u32) },
2450 { "wbox_info", __spufs_wbox_info_read, NULL, 4 * sizeof(u32)},
2451 { "dma_info", __spufs_dma_info_read, NULL, sizeof(struct spu_dma_info)},
2452 { "proxydma_info", __spufs_proxydma_info_read,
2453 NULL, sizeof(struct spu_proxydma_info)},
104f0cc2
ME
2454 { "object-id", NULL, spufs_object_id_get, 19 },
2455 { "npc", NULL, spufs_npc_get, 19 },
936d5bf1 2456 { NULL },
bf1ab978 2457};