Merge branch 'for-2.6.25' of git://git.kernel.org/pub/scm/linux/kernel/git/paulus...
[linux-2.6/cjktty.git] / arch / powerpc / platforms / cell / spufs / file.c
blobc66c3756970d53d52ae56df931e38219a9e79ade
1 /*
2 * SPU file system -- file contents
4 * (C) Copyright IBM Deutschland Entwicklung GmbH 2005
6 * Author: Arnd Bergmann <arndb@de.ibm.com>
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.
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.
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.
23 #undef DEBUG
25 #include <linux/fs.h>
26 #include <linux/ioctl.h>
27 #include <linux/module.h>
28 #include <linux/pagemap.h>
29 #include <linux/poll.h>
30 #include <linux/ptrace.h>
31 #include <linux/seq_file.h>
32 #include <linux/marker.h>
34 #include <asm/io.h>
35 #include <asm/semaphore.h>
36 #include <asm/spu.h>
37 #include <asm/spu_info.h>
38 #include <asm/uaccess.h>
40 #include "spufs.h"
42 #define SPUFS_MMAP_4K (PAGE_SIZE == 0x1000)
44 /* Simple attribute files */
45 struct 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 */
55 static int spufs_attr_open(struct inode *inode, struct file *file,
56 int (*get)(void *, u64 *), int (*set)(void *, u64),
57 const char *fmt)
59 struct spufs_attr *attr;
61 attr = kmalloc(sizeof(*attr), GFP_KERNEL);
62 if (!attr)
63 return -ENOMEM;
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;
72 return nonseekable_open(inode, file);
75 static int spufs_attr_release(struct inode *inode, struct file *file)
77 kfree(file->private_data);
78 return 0;
81 static ssize_t spufs_attr_read(struct file *file, char __user *buf,
82 size_t len, loff_t *ppos)
84 struct spufs_attr *attr;
85 size_t size;
86 ssize_t ret;
88 attr = file->private_data;
89 if (!attr->get)
90 return -EACCES;
92 ret = mutex_lock_interruptible(&attr->mutex);
93 if (ret)
94 return ret;
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;
104 size = scnprintf(attr->get_buf, sizeof(attr->get_buf),
105 attr->fmt, (unsigned long long)val);
108 ret = simple_read_from_buffer(buf, len, ppos, attr->get_buf, size);
109 out:
110 mutex_unlock(&attr->mutex);
111 return ret;
114 static ssize_t spufs_attr_write(struct file *file, const char __user *buf,
115 size_t len, loff_t *ppos)
117 struct spufs_attr *attr;
118 u64 val;
119 size_t size;
120 ssize_t ret;
122 attr = file->private_data;
123 if (!attr->set)
124 return -EACCES;
126 ret = mutex_lock_interruptible(&attr->mutex);
127 if (ret)
128 return ret;
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;
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);
139 out:
140 mutex_unlock(&attr->mutex);
141 return ret;
144 #define DEFINE_SPUFS_SIMPLE_ATTRIBUTE(__fops, __get, __set, __fmt) \
145 static int __fops ## _open(struct inode *inode, struct file *file) \
147 __simple_attr_check_format(__fmt, 0ull); \
148 return spufs_attr_open(inode, file, __get, __set, __fmt); \
150 static 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, \
159 static int
160 spufs_mem_open(struct inode *inode, struct file *file)
162 struct spufs_inode_info *i = SPUFS_I(inode);
163 struct spu_context *ctx = i->i_ctx;
165 mutex_lock(&ctx->mapping_lock);
166 file->private_data = ctx;
167 if (!i->i_openers++)
168 ctx->local_store = inode->i_mapping;
169 mutex_unlock(&ctx->mapping_lock);
170 return 0;
173 static int
174 spufs_mem_release(struct inode *inode, struct file *file)
176 struct spufs_inode_info *i = SPUFS_I(inode);
177 struct spu_context *ctx = i->i_ctx;
179 mutex_lock(&ctx->mapping_lock);
180 if (!--i->i_openers)
181 ctx->local_store = NULL;
182 mutex_unlock(&ctx->mapping_lock);
183 return 0;
186 static ssize_t
187 __spufs_mem_read(struct spu_context *ctx, char __user *buffer,
188 size_t size, loff_t *pos)
190 char *local_store = ctx->ops->get_ls(ctx);
191 return simple_read_from_buffer(buffer, size, pos, local_store,
192 LS_SIZE);
195 static ssize_t
196 spufs_mem_read(struct file *file, char __user *buffer,
197 size_t size, loff_t *pos)
199 struct spu_context *ctx = file->private_data;
200 ssize_t ret;
202 ret = spu_acquire(ctx);
203 if (ret)
204 return ret;
205 ret = __spufs_mem_read(ctx, buffer, size, pos);
206 spu_release(ctx);
208 return ret;
211 static ssize_t
212 spufs_mem_write(struct file *file, const char __user *buffer,
213 size_t size, loff_t *ppos)
215 struct spu_context *ctx = file->private_data;
216 char *local_store;
217 loff_t pos = *ppos;
218 int ret;
220 if (pos < 0)
221 return -EINVAL;
222 if (pos > LS_SIZE)
223 return -EFBIG;
224 if (size > LS_SIZE - pos)
225 size = LS_SIZE - pos;
227 ret = spu_acquire(ctx);
228 if (ret)
229 return ret;
231 local_store = ctx->ops->get_ls(ctx);
232 ret = copy_from_user(local_store + pos, buffer, size);
233 spu_release(ctx);
235 if (ret)
236 return -EFAULT;
237 *ppos = pos + size;
238 return size;
241 static unsigned long spufs_mem_mmap_nopfn(struct vm_area_struct *vma,
242 unsigned long address)
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;
250 /* Check what page size we are using */
251 psize = get_slice_psize(vma->vm_mm, address);
253 /* Some sanity checking */
254 BUG_ON(csa->use_big_pages != (psize == MMU_PAGE_64K));
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;
261 #endif /* CONFIG_SPU_FS_64K_LS */
263 offset = (address - vma->vm_start) + (vma->vm_pgoff << PAGE_SHIFT);
264 if (offset >= LS_SIZE)
265 return NOPFN_SIGBUS;
267 pr_debug("spufs_mem_mmap_nopfn address=0x%lx -> 0x%lx, offset=0x%lx\n",
268 addr0, address, offset);
270 if (spu_acquire(ctx))
271 return NOPFN_REFAULT;
273 if (ctx->state == SPU_STATE_SAVED) {
274 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
275 & ~_PAGE_NO_CACHE);
276 pfn = vmalloc_to_pfn(ctx->csa.lscsa->ls + offset);
277 } else {
278 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
279 | _PAGE_NO_CACHE);
280 pfn = (ctx->spu->local_store_phys + offset) >> PAGE_SHIFT;
282 vm_insert_pfn(vma, address, pfn);
284 spu_release(ctx);
286 return NOPFN_REFAULT;
290 static struct vm_operations_struct spufs_mem_mmap_vmops = {
291 .nopfn = spufs_mem_mmap_nopfn,
294 static int spufs_mem_mmap(struct file *file, struct vm_area_struct *vma)
296 #ifdef CONFIG_SPU_FS_64K_LS
297 struct spu_context *ctx = file->private_data;
298 struct spu_state *csa = &ctx->csa;
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;
310 #endif /* CONFIG_SPU_FS_64K_LS */
312 if (!(vma->vm_flags & VM_SHARED))
313 return -EINVAL;
315 vma->vm_flags |= VM_IO | VM_PFNMAP;
316 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
317 | _PAGE_NO_CACHE);
319 vma->vm_ops = &spufs_mem_mmap_vmops;
320 return 0;
323 #ifdef CONFIG_SPU_FS_64K_LS
324 static unsigned long spufs_get_unmapped_area(struct file *file,
325 unsigned long addr, unsigned long len, unsigned long pgoff,
326 unsigned long flags)
328 struct spu_context *ctx = file->private_data;
329 struct spu_state *csa = &ctx->csa;
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);
336 /* Else, try to obtain a 64K pages slice */
337 return slice_get_unmapped_area(addr, len, flags,
338 MMU_PAGE_64K, 1, 0);
340 #endif /* CONFIG_SPU_FS_64K_LS */
342 static const struct file_operations spufs_mem_fops = {
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,
349 #ifdef CONFIG_SPU_FS_64K_LS
350 .get_unmapped_area = spufs_get_unmapped_area,
351 #endif
354 static unsigned long spufs_ps_nopfn(struct vm_area_struct *vma,
355 unsigned long address,
356 unsigned long ps_offs,
357 unsigned long ps_size)
359 struct spu_context *ctx = vma->vm_file->private_data;
360 unsigned long area, offset = address - vma->vm_start;
361 int ret = 0;
363 spu_context_nospu_trace(spufs_ps_nopfn__enter, ctx);
365 offset += vma->vm_pgoff << PAGE_SHIFT;
366 if (offset >= ps_size)
367 return NOPFN_SIGBUS;
370 * We have to wait for context to be loaded before we have
371 * pages to hand out to the user, but we don't want to wait
372 * with the mmap_sem held.
373 * It is possible to drop the mmap_sem here, but then we need
374 * to return NOPFN_REFAULT because the mappings may have
375 * hanged.
377 if (spu_acquire(ctx))
378 return NOPFN_REFAULT;
380 if (ctx->state == SPU_STATE_SAVED) {
381 up_read(&current->mm->mmap_sem);
382 spu_context_nospu_trace(spufs_ps_nopfn__sleep, ctx);
383 ret = spufs_wait(ctx->run_wq, ctx->state == SPU_STATE_RUNNABLE);
384 spu_context_trace(spufs_ps_nopfn__wake, ctx, ctx->spu);
385 down_read(&current->mm->mmap_sem);
386 } else {
387 area = ctx->spu->problem_phys + ps_offs;
388 vm_insert_pfn(vma, address, (area + offset) >> PAGE_SHIFT);
389 spu_context_trace(spufs_ps_nopfn__insert, ctx, ctx->spu);
392 if (!ret)
393 spu_release(ctx);
394 return NOPFN_REFAULT;
397 #if SPUFS_MMAP_4K
398 static unsigned long spufs_cntl_mmap_nopfn(struct vm_area_struct *vma,
399 unsigned long address)
401 return spufs_ps_nopfn(vma, address, 0x4000, 0x1000);
404 static struct vm_operations_struct spufs_cntl_mmap_vmops = {
405 .nopfn = spufs_cntl_mmap_nopfn,
409 * mmap support for problem state control area [0x4000 - 0x4fff].
411 static int spufs_cntl_mmap(struct file *file, struct vm_area_struct *vma)
413 if (!(vma->vm_flags & VM_SHARED))
414 return -EINVAL;
416 vma->vm_flags |= VM_IO | VM_PFNMAP;
417 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
418 | _PAGE_NO_CACHE | _PAGE_GUARDED);
420 vma->vm_ops = &spufs_cntl_mmap_vmops;
421 return 0;
423 #else /* SPUFS_MMAP_4K */
424 #define spufs_cntl_mmap NULL
425 #endif /* !SPUFS_MMAP_4K */
427 static int spufs_cntl_get(void *data, u64 *val)
429 struct spu_context *ctx = data;
430 int ret;
432 ret = spu_acquire(ctx);
433 if (ret)
434 return ret;
435 *val = ctx->ops->status_read(ctx);
436 spu_release(ctx);
438 return 0;
441 static int spufs_cntl_set(void *data, u64 val)
443 struct spu_context *ctx = data;
444 int ret;
446 ret = spu_acquire(ctx);
447 if (ret)
448 return ret;
449 ctx->ops->runcntl_write(ctx, val);
450 spu_release(ctx);
452 return 0;
455 static int spufs_cntl_open(struct inode *inode, struct file *file)
457 struct spufs_inode_info *i = SPUFS_I(inode);
458 struct spu_context *ctx = i->i_ctx;
460 mutex_lock(&ctx->mapping_lock);
461 file->private_data = ctx;
462 if (!i->i_openers++)
463 ctx->cntl = inode->i_mapping;
464 mutex_unlock(&ctx->mapping_lock);
465 return simple_attr_open(inode, file, spufs_cntl_get,
466 spufs_cntl_set, "0x%08lx");
469 static int
470 spufs_cntl_release(struct inode *inode, struct file *file)
472 struct spufs_inode_info *i = SPUFS_I(inode);
473 struct spu_context *ctx = i->i_ctx;
475 simple_attr_release(inode, file);
477 mutex_lock(&ctx->mapping_lock);
478 if (!--i->i_openers)
479 ctx->cntl = NULL;
480 mutex_unlock(&ctx->mapping_lock);
481 return 0;
484 static const struct file_operations spufs_cntl_fops = {
485 .open = spufs_cntl_open,
486 .release = spufs_cntl_release,
487 .read = simple_attr_read,
488 .write = simple_attr_write,
489 .mmap = spufs_cntl_mmap,
492 static int
493 spufs_regs_open(struct inode *inode, struct file *file)
495 struct spufs_inode_info *i = SPUFS_I(inode);
496 file->private_data = i->i_ctx;
497 return 0;
500 static ssize_t
501 __spufs_regs_read(struct spu_context *ctx, char __user *buffer,
502 size_t size, loff_t *pos)
504 struct spu_lscsa *lscsa = ctx->csa.lscsa;
505 return simple_read_from_buffer(buffer, size, pos,
506 lscsa->gprs, sizeof lscsa->gprs);
509 static ssize_t
510 spufs_regs_read(struct file *file, char __user *buffer,
511 size_t size, loff_t *pos)
513 int ret;
514 struct spu_context *ctx = file->private_data;
516 ret = spu_acquire_saved(ctx);
517 if (ret)
518 return ret;
519 ret = __spufs_regs_read(ctx, buffer, size, pos);
520 spu_release_saved(ctx);
521 return ret;
524 static ssize_t
525 spufs_regs_write(struct file *file, const char __user *buffer,
526 size_t size, loff_t *pos)
528 struct spu_context *ctx = file->private_data;
529 struct spu_lscsa *lscsa = ctx->csa.lscsa;
530 int ret;
532 size = min_t(ssize_t, sizeof lscsa->gprs - *pos, size);
533 if (size <= 0)
534 return -EFBIG;
535 *pos += size;
537 ret = spu_acquire_saved(ctx);
538 if (ret)
539 return ret;
541 ret = copy_from_user(lscsa->gprs + *pos - size,
542 buffer, size) ? -EFAULT : size;
544 spu_release_saved(ctx);
545 return ret;
548 static const struct file_operations spufs_regs_fops = {
549 .open = spufs_regs_open,
550 .read = spufs_regs_read,
551 .write = spufs_regs_write,
552 .llseek = generic_file_llseek,
555 static ssize_t
556 __spufs_fpcr_read(struct spu_context *ctx, char __user * buffer,
557 size_t size, loff_t * pos)
559 struct spu_lscsa *lscsa = ctx->csa.lscsa;
560 return simple_read_from_buffer(buffer, size, pos,
561 &lscsa->fpcr, sizeof(lscsa->fpcr));
564 static ssize_t
565 spufs_fpcr_read(struct file *file, char __user * buffer,
566 size_t size, loff_t * pos)
568 int ret;
569 struct spu_context *ctx = file->private_data;
571 ret = spu_acquire_saved(ctx);
572 if (ret)
573 return ret;
574 ret = __spufs_fpcr_read(ctx, buffer, size, pos);
575 spu_release_saved(ctx);
576 return ret;
579 static ssize_t
580 spufs_fpcr_write(struct file *file, const char __user * buffer,
581 size_t size, loff_t * pos)
583 struct spu_context *ctx = file->private_data;
584 struct spu_lscsa *lscsa = ctx->csa.lscsa;
585 int ret;
587 size = min_t(ssize_t, sizeof(lscsa->fpcr) - *pos, size);
588 if (size <= 0)
589 return -EFBIG;
591 ret = spu_acquire_saved(ctx);
592 if (ret)
593 return ret;
595 *pos += size;
596 ret = copy_from_user((char *)&lscsa->fpcr + *pos - size,
597 buffer, size) ? -EFAULT : size;
599 spu_release_saved(ctx);
600 return ret;
603 static const struct file_operations spufs_fpcr_fops = {
604 .open = spufs_regs_open,
605 .read = spufs_fpcr_read,
606 .write = spufs_fpcr_write,
607 .llseek = generic_file_llseek,
610 /* generic open function for all pipe-like files */
611 static int spufs_pipe_open(struct inode *inode, struct file *file)
613 struct spufs_inode_info *i = SPUFS_I(inode);
614 file->private_data = i->i_ctx;
616 return nonseekable_open(inode, file);
620 * Read as many bytes from the mailbox as possible, until
621 * one of the conditions becomes true:
623 * - no more data available in the mailbox
624 * - end of the user provided buffer
625 * - end of the mapped area
627 static ssize_t spufs_mbox_read(struct file *file, char __user *buf,
628 size_t len, loff_t *pos)
630 struct spu_context *ctx = file->private_data;
631 u32 mbox_data, __user *udata;
632 ssize_t count;
634 if (len < 4)
635 return -EINVAL;
637 if (!access_ok(VERIFY_WRITE, buf, len))
638 return -EFAULT;
640 udata = (void __user *)buf;
642 count = spu_acquire(ctx);
643 if (count)
644 return count;
646 for (count = 0; (count + 4) <= len; count += 4, udata++) {
647 int ret;
648 ret = ctx->ops->mbox_read(ctx, &mbox_data);
649 if (ret == 0)
650 break;
653 * at the end of the mapped area, we can fault
654 * but still need to return the data we have
655 * read successfully so far.
657 ret = __put_user(mbox_data, udata);
658 if (ret) {
659 if (!count)
660 count = -EFAULT;
661 break;
664 spu_release(ctx);
666 if (!count)
667 count = -EAGAIN;
669 return count;
672 static const struct file_operations spufs_mbox_fops = {
673 .open = spufs_pipe_open,
674 .read = spufs_mbox_read,
677 static ssize_t spufs_mbox_stat_read(struct file *file, char __user *buf,
678 size_t len, loff_t *pos)
680 struct spu_context *ctx = file->private_data;
681 ssize_t ret;
682 u32 mbox_stat;
684 if (len < 4)
685 return -EINVAL;
687 ret = spu_acquire(ctx);
688 if (ret)
689 return ret;
691 mbox_stat = ctx->ops->mbox_stat_read(ctx) & 0xff;
693 spu_release(ctx);
695 if (copy_to_user(buf, &mbox_stat, sizeof mbox_stat))
696 return -EFAULT;
698 return 4;
701 static const struct file_operations spufs_mbox_stat_fops = {
702 .open = spufs_pipe_open,
703 .read = spufs_mbox_stat_read,
706 /* low-level ibox access function */
707 size_t spu_ibox_read(struct spu_context *ctx, u32 *data)
709 return ctx->ops->ibox_read(ctx, data);
712 static int spufs_ibox_fasync(int fd, struct file *file, int on)
714 struct spu_context *ctx = file->private_data;
716 return fasync_helper(fd, file, on, &ctx->ibox_fasync);
719 /* interrupt-level ibox callback function. */
720 void spufs_ibox_callback(struct spu *spu)
722 struct spu_context *ctx = spu->ctx;
724 if (!ctx)
725 return;
727 wake_up_all(&ctx->ibox_wq);
728 kill_fasync(&ctx->ibox_fasync, SIGIO, POLLIN);
732 * Read as many bytes from the interrupt mailbox as possible, until
733 * one of the conditions becomes true:
735 * - no more data available in the mailbox
736 * - end of the user provided buffer
737 * - end of the mapped area
739 * If the file is opened without O_NONBLOCK, we wait here until
740 * any data is available, but return when we have been able to
741 * read something.
743 static ssize_t spufs_ibox_read(struct file *file, char __user *buf,
744 size_t len, loff_t *pos)
746 struct spu_context *ctx = file->private_data;
747 u32 ibox_data, __user *udata;
748 ssize_t count;
750 if (len < 4)
751 return -EINVAL;
753 if (!access_ok(VERIFY_WRITE, buf, len))
754 return -EFAULT;
756 udata = (void __user *)buf;
758 count = spu_acquire(ctx);
759 if (count)
760 goto out;
762 /* wait only for the first element */
763 count = 0;
764 if (file->f_flags & O_NONBLOCK) {
765 if (!spu_ibox_read(ctx, &ibox_data)) {
766 count = -EAGAIN;
767 goto out_unlock;
769 } else {
770 count = spufs_wait(ctx->ibox_wq, spu_ibox_read(ctx, &ibox_data));
771 if (count)
772 goto out;
775 /* if we can't write at all, return -EFAULT */
776 count = __put_user(ibox_data, udata);
777 if (count)
778 goto out_unlock;
780 for (count = 4, udata++; (count + 4) <= len; count += 4, udata++) {
781 int ret;
782 ret = ctx->ops->ibox_read(ctx, &ibox_data);
783 if (ret == 0)
784 break;
786 * at the end of the mapped area, we can fault
787 * but still need to return the data we have
788 * read successfully so far.
790 ret = __put_user(ibox_data, udata);
791 if (ret)
792 break;
795 out_unlock:
796 spu_release(ctx);
797 out:
798 return count;
801 static unsigned int spufs_ibox_poll(struct file *file, poll_table *wait)
803 struct spu_context *ctx = file->private_data;
804 unsigned int mask;
806 poll_wait(file, &ctx->ibox_wq, wait);
809 * For now keep this uninterruptible and also ignore the rule
810 * that poll should not sleep. Will be fixed later.
812 mutex_lock(&ctx->state_mutex);
813 mask = ctx->ops->mbox_stat_poll(ctx, POLLIN | POLLRDNORM);
814 spu_release(ctx);
816 return mask;
819 static const struct file_operations spufs_ibox_fops = {
820 .open = spufs_pipe_open,
821 .read = spufs_ibox_read,
822 .poll = spufs_ibox_poll,
823 .fasync = spufs_ibox_fasync,
826 static ssize_t spufs_ibox_stat_read(struct file *file, char __user *buf,
827 size_t len, loff_t *pos)
829 struct spu_context *ctx = file->private_data;
830 ssize_t ret;
831 u32 ibox_stat;
833 if (len < 4)
834 return -EINVAL;
836 ret = spu_acquire(ctx);
837 if (ret)
838 return ret;
839 ibox_stat = (ctx->ops->mbox_stat_read(ctx) >> 16) & 0xff;
840 spu_release(ctx);
842 if (copy_to_user(buf, &ibox_stat, sizeof ibox_stat))
843 return -EFAULT;
845 return 4;
848 static const struct file_operations spufs_ibox_stat_fops = {
849 .open = spufs_pipe_open,
850 .read = spufs_ibox_stat_read,
853 /* low-level mailbox write */
854 size_t spu_wbox_write(struct spu_context *ctx, u32 data)
856 return ctx->ops->wbox_write(ctx, data);
859 static int spufs_wbox_fasync(int fd, struct file *file, int on)
861 struct spu_context *ctx = file->private_data;
862 int ret;
864 ret = fasync_helper(fd, file, on, &ctx->wbox_fasync);
866 return ret;
869 /* interrupt-level wbox callback function. */
870 void spufs_wbox_callback(struct spu *spu)
872 struct spu_context *ctx = spu->ctx;
874 if (!ctx)
875 return;
877 wake_up_all(&ctx->wbox_wq);
878 kill_fasync(&ctx->wbox_fasync, SIGIO, POLLOUT);
882 * Write as many bytes to the interrupt mailbox as possible, until
883 * one of the conditions becomes true:
885 * - the mailbox is full
886 * - end of the user provided buffer
887 * - end of the mapped area
889 * If the file is opened without O_NONBLOCK, we wait here until
890 * space is availabyl, but return when we have been able to
891 * write something.
893 static ssize_t spufs_wbox_write(struct file *file, const char __user *buf,
894 size_t len, loff_t *pos)
896 struct spu_context *ctx = file->private_data;
897 u32 wbox_data, __user *udata;
898 ssize_t count;
900 if (len < 4)
901 return -EINVAL;
903 udata = (void __user *)buf;
904 if (!access_ok(VERIFY_READ, buf, len))
905 return -EFAULT;
907 if (__get_user(wbox_data, udata))
908 return -EFAULT;
910 count = spu_acquire(ctx);
911 if (count)
912 goto out;
915 * make sure we can at least write one element, by waiting
916 * in case of !O_NONBLOCK
918 count = 0;
919 if (file->f_flags & O_NONBLOCK) {
920 if (!spu_wbox_write(ctx, wbox_data)) {
921 count = -EAGAIN;
922 goto out_unlock;
924 } else {
925 count = spufs_wait(ctx->wbox_wq, spu_wbox_write(ctx, wbox_data));
926 if (count)
927 goto out;
931 /* write as much as possible */
932 for (count = 4, udata++; (count + 4) <= len; count += 4, udata++) {
933 int ret;
934 ret = __get_user(wbox_data, udata);
935 if (ret)
936 break;
938 ret = spu_wbox_write(ctx, wbox_data);
939 if (ret == 0)
940 break;
943 out_unlock:
944 spu_release(ctx);
945 out:
946 return count;
949 static unsigned int spufs_wbox_poll(struct file *file, poll_table *wait)
951 struct spu_context *ctx = file->private_data;
952 unsigned int mask;
954 poll_wait(file, &ctx->wbox_wq, wait);
957 * For now keep this uninterruptible and also ignore the rule
958 * that poll should not sleep. Will be fixed later.
960 mutex_lock(&ctx->state_mutex);
961 mask = ctx->ops->mbox_stat_poll(ctx, POLLOUT | POLLWRNORM);
962 spu_release(ctx);
964 return mask;
967 static const struct file_operations spufs_wbox_fops = {
968 .open = spufs_pipe_open,
969 .write = spufs_wbox_write,
970 .poll = spufs_wbox_poll,
971 .fasync = spufs_wbox_fasync,
974 static ssize_t spufs_wbox_stat_read(struct file *file, char __user *buf,
975 size_t len, loff_t *pos)
977 struct spu_context *ctx = file->private_data;
978 ssize_t ret;
979 u32 wbox_stat;
981 if (len < 4)
982 return -EINVAL;
984 ret = spu_acquire(ctx);
985 if (ret)
986 return ret;
987 wbox_stat = (ctx->ops->mbox_stat_read(ctx) >> 8) & 0xff;
988 spu_release(ctx);
990 if (copy_to_user(buf, &wbox_stat, sizeof wbox_stat))
991 return -EFAULT;
993 return 4;
996 static const struct file_operations spufs_wbox_stat_fops = {
997 .open = spufs_pipe_open,
998 .read = spufs_wbox_stat_read,
1001 static int spufs_signal1_open(struct inode *inode, struct file *file)
1003 struct spufs_inode_info *i = SPUFS_I(inode);
1004 struct spu_context *ctx = i->i_ctx;
1006 mutex_lock(&ctx->mapping_lock);
1007 file->private_data = ctx;
1008 if (!i->i_openers++)
1009 ctx->signal1 = inode->i_mapping;
1010 mutex_unlock(&ctx->mapping_lock);
1011 return nonseekable_open(inode, file);
1014 static int
1015 spufs_signal1_release(struct inode *inode, struct file *file)
1017 struct spufs_inode_info *i = SPUFS_I(inode);
1018 struct spu_context *ctx = i->i_ctx;
1020 mutex_lock(&ctx->mapping_lock);
1021 if (!--i->i_openers)
1022 ctx->signal1 = NULL;
1023 mutex_unlock(&ctx->mapping_lock);
1024 return 0;
1027 static ssize_t __spufs_signal1_read(struct spu_context *ctx, char __user *buf,
1028 size_t len, loff_t *pos)
1030 int ret = 0;
1031 u32 data;
1033 if (len < 4)
1034 return -EINVAL;
1036 if (ctx->csa.spu_chnlcnt_RW[3]) {
1037 data = ctx->csa.spu_chnldata_RW[3];
1038 ret = 4;
1041 if (!ret)
1042 goto out;
1044 if (copy_to_user(buf, &data, 4))
1045 return -EFAULT;
1047 out:
1048 return ret;
1051 static ssize_t spufs_signal1_read(struct file *file, char __user *buf,
1052 size_t len, loff_t *pos)
1054 int ret;
1055 struct spu_context *ctx = file->private_data;
1057 ret = spu_acquire_saved(ctx);
1058 if (ret)
1059 return ret;
1060 ret = __spufs_signal1_read(ctx, buf, len, pos);
1061 spu_release_saved(ctx);
1063 return ret;
1066 static ssize_t spufs_signal1_write(struct file *file, const char __user *buf,
1067 size_t len, loff_t *pos)
1069 struct spu_context *ctx;
1070 ssize_t ret;
1071 u32 data;
1073 ctx = file->private_data;
1075 if (len < 4)
1076 return -EINVAL;
1078 if (copy_from_user(&data, buf, 4))
1079 return -EFAULT;
1081 ret = spu_acquire(ctx);
1082 if (ret)
1083 return ret;
1084 ctx->ops->signal1_write(ctx, data);
1085 spu_release(ctx);
1087 return 4;
1090 static unsigned long spufs_signal1_mmap_nopfn(struct vm_area_struct *vma,
1091 unsigned long address)
1093 #if PAGE_SIZE == 0x1000
1094 return spufs_ps_nopfn(vma, address, 0x14000, 0x1000);
1095 #elif PAGE_SIZE == 0x10000
1096 /* For 64k pages, both signal1 and signal2 can be used to mmap the whole
1097 * signal 1 and 2 area
1099 return spufs_ps_nopfn(vma, address, 0x10000, 0x10000);
1100 #else
1101 #error unsupported page size
1102 #endif
1105 static struct vm_operations_struct spufs_signal1_mmap_vmops = {
1106 .nopfn = spufs_signal1_mmap_nopfn,
1109 static int spufs_signal1_mmap(struct file *file, struct vm_area_struct *vma)
1111 if (!(vma->vm_flags & VM_SHARED))
1112 return -EINVAL;
1114 vma->vm_flags |= VM_IO | VM_PFNMAP;
1115 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
1116 | _PAGE_NO_CACHE | _PAGE_GUARDED);
1118 vma->vm_ops = &spufs_signal1_mmap_vmops;
1119 return 0;
1122 static const struct file_operations spufs_signal1_fops = {
1123 .open = spufs_signal1_open,
1124 .release = spufs_signal1_release,
1125 .read = spufs_signal1_read,
1126 .write = spufs_signal1_write,
1127 .mmap = spufs_signal1_mmap,
1130 static const struct file_operations spufs_signal1_nosched_fops = {
1131 .open = spufs_signal1_open,
1132 .release = spufs_signal1_release,
1133 .write = spufs_signal1_write,
1134 .mmap = spufs_signal1_mmap,
1137 static int spufs_signal2_open(struct inode *inode, struct file *file)
1139 struct spufs_inode_info *i = SPUFS_I(inode);
1140 struct spu_context *ctx = i->i_ctx;
1142 mutex_lock(&ctx->mapping_lock);
1143 file->private_data = ctx;
1144 if (!i->i_openers++)
1145 ctx->signal2 = inode->i_mapping;
1146 mutex_unlock(&ctx->mapping_lock);
1147 return nonseekable_open(inode, file);
1150 static int
1151 spufs_signal2_release(struct inode *inode, struct file *file)
1153 struct spufs_inode_info *i = SPUFS_I(inode);
1154 struct spu_context *ctx = i->i_ctx;
1156 mutex_lock(&ctx->mapping_lock);
1157 if (!--i->i_openers)
1158 ctx->signal2 = NULL;
1159 mutex_unlock(&ctx->mapping_lock);
1160 return 0;
1163 static ssize_t __spufs_signal2_read(struct spu_context *ctx, char __user *buf,
1164 size_t len, loff_t *pos)
1166 int ret = 0;
1167 u32 data;
1169 if (len < 4)
1170 return -EINVAL;
1172 if (ctx->csa.spu_chnlcnt_RW[4]) {
1173 data = ctx->csa.spu_chnldata_RW[4];
1174 ret = 4;
1177 if (!ret)
1178 goto out;
1180 if (copy_to_user(buf, &data, 4))
1181 return -EFAULT;
1183 out:
1184 return ret;
1187 static ssize_t spufs_signal2_read(struct file *file, char __user *buf,
1188 size_t len, loff_t *pos)
1190 struct spu_context *ctx = file->private_data;
1191 int ret;
1193 ret = spu_acquire_saved(ctx);
1194 if (ret)
1195 return ret;
1196 ret = __spufs_signal2_read(ctx, buf, len, pos);
1197 spu_release_saved(ctx);
1199 return ret;
1202 static ssize_t spufs_signal2_write(struct file *file, const char __user *buf,
1203 size_t len, loff_t *pos)
1205 struct spu_context *ctx;
1206 ssize_t ret;
1207 u32 data;
1209 ctx = file->private_data;
1211 if (len < 4)
1212 return -EINVAL;
1214 if (copy_from_user(&data, buf, 4))
1215 return -EFAULT;
1217 ret = spu_acquire(ctx);
1218 if (ret)
1219 return ret;
1220 ctx->ops->signal2_write(ctx, data);
1221 spu_release(ctx);
1223 return 4;
1226 #if SPUFS_MMAP_4K
1227 static unsigned long spufs_signal2_mmap_nopfn(struct vm_area_struct *vma,
1228 unsigned long address)
1230 #if PAGE_SIZE == 0x1000
1231 return spufs_ps_nopfn(vma, address, 0x1c000, 0x1000);
1232 #elif PAGE_SIZE == 0x10000
1233 /* For 64k pages, both signal1 and signal2 can be used to mmap the whole
1234 * signal 1 and 2 area
1236 return spufs_ps_nopfn(vma, address, 0x10000, 0x10000);
1237 #else
1238 #error unsupported page size
1239 #endif
1242 static struct vm_operations_struct spufs_signal2_mmap_vmops = {
1243 .nopfn = spufs_signal2_mmap_nopfn,
1246 static int spufs_signal2_mmap(struct file *file, struct vm_area_struct *vma)
1248 if (!(vma->vm_flags & VM_SHARED))
1249 return -EINVAL;
1251 vma->vm_flags |= VM_IO | VM_PFNMAP;
1252 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
1253 | _PAGE_NO_CACHE | _PAGE_GUARDED);
1255 vma->vm_ops = &spufs_signal2_mmap_vmops;
1256 return 0;
1258 #else /* SPUFS_MMAP_4K */
1259 #define spufs_signal2_mmap NULL
1260 #endif /* !SPUFS_MMAP_4K */
1262 static const struct file_operations spufs_signal2_fops = {
1263 .open = spufs_signal2_open,
1264 .release = spufs_signal2_release,
1265 .read = spufs_signal2_read,
1266 .write = spufs_signal2_write,
1267 .mmap = spufs_signal2_mmap,
1270 static const struct file_operations spufs_signal2_nosched_fops = {
1271 .open = spufs_signal2_open,
1272 .release = spufs_signal2_release,
1273 .write = spufs_signal2_write,
1274 .mmap = spufs_signal2_mmap,
1278 * This is a wrapper around DEFINE_SIMPLE_ATTRIBUTE which does the
1279 * work of acquiring (or not) the SPU context before calling through
1280 * to the actual get routine. The set routine is called directly.
1282 #define SPU_ATTR_NOACQUIRE 0
1283 #define SPU_ATTR_ACQUIRE 1
1284 #define SPU_ATTR_ACQUIRE_SAVED 2
1286 #define DEFINE_SPUFS_ATTRIBUTE(__name, __get, __set, __fmt, __acquire) \
1287 static int __##__get(void *data, u64 *val) \
1289 struct spu_context *ctx = data; \
1290 int ret = 0; \
1292 if (__acquire == SPU_ATTR_ACQUIRE) { \
1293 ret = spu_acquire(ctx); \
1294 if (ret) \
1295 return ret; \
1296 *val = __get(ctx); \
1297 spu_release(ctx); \
1298 } else if (__acquire == SPU_ATTR_ACQUIRE_SAVED) { \
1299 ret = spu_acquire_saved(ctx); \
1300 if (ret) \
1301 return ret; \
1302 *val = __get(ctx); \
1303 spu_release_saved(ctx); \
1304 } else \
1305 *val = __get(ctx); \
1307 return 0; \
1309 DEFINE_SPUFS_SIMPLE_ATTRIBUTE(__name, __##__get, __set, __fmt);
1311 static int spufs_signal1_type_set(void *data, u64 val)
1313 struct spu_context *ctx = data;
1314 int ret;
1316 ret = spu_acquire(ctx);
1317 if (ret)
1318 return ret;
1319 ctx->ops->signal1_type_set(ctx, val);
1320 spu_release(ctx);
1322 return 0;
1325 static u64 spufs_signal1_type_get(struct spu_context *ctx)
1327 return ctx->ops->signal1_type_get(ctx);
1329 DEFINE_SPUFS_ATTRIBUTE(spufs_signal1_type, spufs_signal1_type_get,
1330 spufs_signal1_type_set, "%llu", SPU_ATTR_ACQUIRE);
1333 static int spufs_signal2_type_set(void *data, u64 val)
1335 struct spu_context *ctx = data;
1336 int ret;
1338 ret = spu_acquire(ctx);
1339 if (ret)
1340 return ret;
1341 ctx->ops->signal2_type_set(ctx, val);
1342 spu_release(ctx);
1344 return 0;
1347 static u64 spufs_signal2_type_get(struct spu_context *ctx)
1349 return ctx->ops->signal2_type_get(ctx);
1351 DEFINE_SPUFS_ATTRIBUTE(spufs_signal2_type, spufs_signal2_type_get,
1352 spufs_signal2_type_set, "%llu", SPU_ATTR_ACQUIRE);
1354 #if SPUFS_MMAP_4K
1355 static unsigned long spufs_mss_mmap_nopfn(struct vm_area_struct *vma,
1356 unsigned long address)
1358 return spufs_ps_nopfn(vma, address, 0x0000, 0x1000);
1361 static struct vm_operations_struct spufs_mss_mmap_vmops = {
1362 .nopfn = spufs_mss_mmap_nopfn,
1366 * mmap support for problem state MFC DMA area [0x0000 - 0x0fff].
1368 static int spufs_mss_mmap(struct file *file, struct vm_area_struct *vma)
1370 if (!(vma->vm_flags & VM_SHARED))
1371 return -EINVAL;
1373 vma->vm_flags |= VM_IO | VM_PFNMAP;
1374 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
1375 | _PAGE_NO_CACHE | _PAGE_GUARDED);
1377 vma->vm_ops = &spufs_mss_mmap_vmops;
1378 return 0;
1380 #else /* SPUFS_MMAP_4K */
1381 #define spufs_mss_mmap NULL
1382 #endif /* !SPUFS_MMAP_4K */
1384 static int spufs_mss_open(struct inode *inode, struct file *file)
1386 struct spufs_inode_info *i = SPUFS_I(inode);
1387 struct spu_context *ctx = i->i_ctx;
1389 file->private_data = i->i_ctx;
1391 mutex_lock(&ctx->mapping_lock);
1392 if (!i->i_openers++)
1393 ctx->mss = inode->i_mapping;
1394 mutex_unlock(&ctx->mapping_lock);
1395 return nonseekable_open(inode, file);
1398 static int
1399 spufs_mss_release(struct inode *inode, struct file *file)
1401 struct spufs_inode_info *i = SPUFS_I(inode);
1402 struct spu_context *ctx = i->i_ctx;
1404 mutex_lock(&ctx->mapping_lock);
1405 if (!--i->i_openers)
1406 ctx->mss = NULL;
1407 mutex_unlock(&ctx->mapping_lock);
1408 return 0;
1411 static const struct file_operations spufs_mss_fops = {
1412 .open = spufs_mss_open,
1413 .release = spufs_mss_release,
1414 .mmap = spufs_mss_mmap,
1417 static unsigned long spufs_psmap_mmap_nopfn(struct vm_area_struct *vma,
1418 unsigned long address)
1420 return spufs_ps_nopfn(vma, address, 0x0000, 0x20000);
1423 static struct vm_operations_struct spufs_psmap_mmap_vmops = {
1424 .nopfn = spufs_psmap_mmap_nopfn,
1428 * mmap support for full problem state area [0x00000 - 0x1ffff].
1430 static int spufs_psmap_mmap(struct file *file, struct vm_area_struct *vma)
1432 if (!(vma->vm_flags & VM_SHARED))
1433 return -EINVAL;
1435 vma->vm_flags |= VM_IO | VM_PFNMAP;
1436 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
1437 | _PAGE_NO_CACHE | _PAGE_GUARDED);
1439 vma->vm_ops = &spufs_psmap_mmap_vmops;
1440 return 0;
1443 static int spufs_psmap_open(struct inode *inode, struct file *file)
1445 struct spufs_inode_info *i = SPUFS_I(inode);
1446 struct spu_context *ctx = i->i_ctx;
1448 mutex_lock(&ctx->mapping_lock);
1449 file->private_data = i->i_ctx;
1450 if (!i->i_openers++)
1451 ctx->psmap = inode->i_mapping;
1452 mutex_unlock(&ctx->mapping_lock);
1453 return nonseekable_open(inode, file);
1456 static int
1457 spufs_psmap_release(struct inode *inode, struct file *file)
1459 struct spufs_inode_info *i = SPUFS_I(inode);
1460 struct spu_context *ctx = i->i_ctx;
1462 mutex_lock(&ctx->mapping_lock);
1463 if (!--i->i_openers)
1464 ctx->psmap = NULL;
1465 mutex_unlock(&ctx->mapping_lock);
1466 return 0;
1469 static const struct file_operations spufs_psmap_fops = {
1470 .open = spufs_psmap_open,
1471 .release = spufs_psmap_release,
1472 .mmap = spufs_psmap_mmap,
1476 #if SPUFS_MMAP_4K
1477 static unsigned long spufs_mfc_mmap_nopfn(struct vm_area_struct *vma,
1478 unsigned long address)
1480 return spufs_ps_nopfn(vma, address, 0x3000, 0x1000);
1483 static struct vm_operations_struct spufs_mfc_mmap_vmops = {
1484 .nopfn = spufs_mfc_mmap_nopfn,
1488 * mmap support for problem state MFC DMA area [0x0000 - 0x0fff].
1490 static int spufs_mfc_mmap(struct file *file, struct vm_area_struct *vma)
1492 if (!(vma->vm_flags & VM_SHARED))
1493 return -EINVAL;
1495 vma->vm_flags |= VM_IO | VM_PFNMAP;
1496 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
1497 | _PAGE_NO_CACHE | _PAGE_GUARDED);
1499 vma->vm_ops = &spufs_mfc_mmap_vmops;
1500 return 0;
1502 #else /* SPUFS_MMAP_4K */
1503 #define spufs_mfc_mmap NULL
1504 #endif /* !SPUFS_MMAP_4K */
1506 static int spufs_mfc_open(struct inode *inode, struct file *file)
1508 struct spufs_inode_info *i = SPUFS_I(inode);
1509 struct spu_context *ctx = i->i_ctx;
1511 /* we don't want to deal with DMA into other processes */
1512 if (ctx->owner != current->mm)
1513 return -EINVAL;
1515 if (atomic_read(&inode->i_count) != 1)
1516 return -EBUSY;
1518 mutex_lock(&ctx->mapping_lock);
1519 file->private_data = ctx;
1520 if (!i->i_openers++)
1521 ctx->mfc = inode->i_mapping;
1522 mutex_unlock(&ctx->mapping_lock);
1523 return nonseekable_open(inode, file);
1526 static int
1527 spufs_mfc_release(struct inode *inode, struct file *file)
1529 struct spufs_inode_info *i = SPUFS_I(inode);
1530 struct spu_context *ctx = i->i_ctx;
1532 mutex_lock(&ctx->mapping_lock);
1533 if (!--i->i_openers)
1534 ctx->mfc = NULL;
1535 mutex_unlock(&ctx->mapping_lock);
1536 return 0;
1539 /* interrupt-level mfc callback function. */
1540 void spufs_mfc_callback(struct spu *spu)
1542 struct spu_context *ctx = spu->ctx;
1544 if (!ctx)
1545 return;
1547 wake_up_all(&ctx->mfc_wq);
1549 pr_debug("%s %s\n", __FUNCTION__, spu->name);
1550 if (ctx->mfc_fasync) {
1551 u32 free_elements, tagstatus;
1552 unsigned int mask;
1554 /* no need for spu_acquire in interrupt context */
1555 free_elements = ctx->ops->get_mfc_free_elements(ctx);
1556 tagstatus = ctx->ops->read_mfc_tagstatus(ctx);
1558 mask = 0;
1559 if (free_elements & 0xffff)
1560 mask |= POLLOUT;
1561 if (tagstatus & ctx->tagwait)
1562 mask |= POLLIN;
1564 kill_fasync(&ctx->mfc_fasync, SIGIO, mask);
1568 static int spufs_read_mfc_tagstatus(struct spu_context *ctx, u32 *status)
1570 /* See if there is one tag group is complete */
1571 /* FIXME we need locking around tagwait */
1572 *status = ctx->ops->read_mfc_tagstatus(ctx) & ctx->tagwait;
1573 ctx->tagwait &= ~*status;
1574 if (*status)
1575 return 1;
1577 /* enable interrupt waiting for any tag group,
1578 may silently fail if interrupts are already enabled */
1579 ctx->ops->set_mfc_query(ctx, ctx->tagwait, 1);
1580 return 0;
1583 static ssize_t spufs_mfc_read(struct file *file, char __user *buffer,
1584 size_t size, loff_t *pos)
1586 struct spu_context *ctx = file->private_data;
1587 int ret = -EINVAL;
1588 u32 status;
1590 if (size != 4)
1591 goto out;
1593 ret = spu_acquire(ctx);
1594 if (ret)
1595 return ret;
1597 ret = -EINVAL;
1598 if (file->f_flags & O_NONBLOCK) {
1599 status = ctx->ops->read_mfc_tagstatus(ctx);
1600 if (!(status & ctx->tagwait))
1601 ret = -EAGAIN;
1602 else
1603 /* XXX(hch): shouldn't we clear ret here? */
1604 ctx->tagwait &= ~status;
1605 } else {
1606 ret = spufs_wait(ctx->mfc_wq,
1607 spufs_read_mfc_tagstatus(ctx, &status));
1608 if (ret)
1609 goto out;
1611 spu_release(ctx);
1613 ret = 4;
1614 if (copy_to_user(buffer, &status, 4))
1615 ret = -EFAULT;
1617 out:
1618 return ret;
1621 static int spufs_check_valid_dma(struct mfc_dma_command *cmd)
1623 pr_debug("queueing DMA %x %lx %x %x %x\n", cmd->lsa,
1624 cmd->ea, cmd->size, cmd->tag, cmd->cmd);
1626 switch (cmd->cmd) {
1627 case MFC_PUT_CMD:
1628 case MFC_PUTF_CMD:
1629 case MFC_PUTB_CMD:
1630 case MFC_GET_CMD:
1631 case MFC_GETF_CMD:
1632 case MFC_GETB_CMD:
1633 break;
1634 default:
1635 pr_debug("invalid DMA opcode %x\n", cmd->cmd);
1636 return -EIO;
1639 if ((cmd->lsa & 0xf) != (cmd->ea &0xf)) {
1640 pr_debug("invalid DMA alignment, ea %lx lsa %x\n",
1641 cmd->ea, cmd->lsa);
1642 return -EIO;
1645 switch (cmd->size & 0xf) {
1646 case 1:
1647 break;
1648 case 2:
1649 if (cmd->lsa & 1)
1650 goto error;
1651 break;
1652 case 4:
1653 if (cmd->lsa & 3)
1654 goto error;
1655 break;
1656 case 8:
1657 if (cmd->lsa & 7)
1658 goto error;
1659 break;
1660 case 0:
1661 if (cmd->lsa & 15)
1662 goto error;
1663 break;
1664 error:
1665 default:
1666 pr_debug("invalid DMA alignment %x for size %x\n",
1667 cmd->lsa & 0xf, cmd->size);
1668 return -EIO;
1671 if (cmd->size > 16 * 1024) {
1672 pr_debug("invalid DMA size %x\n", cmd->size);
1673 return -EIO;
1676 if (cmd->tag & 0xfff0) {
1677 /* we reserve the higher tag numbers for kernel use */
1678 pr_debug("invalid DMA tag\n");
1679 return -EIO;
1682 if (cmd->class) {
1683 /* not supported in this version */
1684 pr_debug("invalid DMA class\n");
1685 return -EIO;
1688 return 0;
1691 static int spu_send_mfc_command(struct spu_context *ctx,
1692 struct mfc_dma_command cmd,
1693 int *error)
1695 *error = ctx->ops->send_mfc_command(ctx, &cmd);
1696 if (*error == -EAGAIN) {
1697 /* wait for any tag group to complete
1698 so we have space for the new command */
1699 ctx->ops->set_mfc_query(ctx, ctx->tagwait, 1);
1700 /* try again, because the queue might be
1701 empty again */
1702 *error = ctx->ops->send_mfc_command(ctx, &cmd);
1703 if (*error == -EAGAIN)
1704 return 0;
1706 return 1;
1709 static ssize_t spufs_mfc_write(struct file *file, const char __user *buffer,
1710 size_t size, loff_t *pos)
1712 struct spu_context *ctx = file->private_data;
1713 struct mfc_dma_command cmd;
1714 int ret = -EINVAL;
1716 if (size != sizeof cmd)
1717 goto out;
1719 ret = -EFAULT;
1720 if (copy_from_user(&cmd, buffer, sizeof cmd))
1721 goto out;
1723 ret = spufs_check_valid_dma(&cmd);
1724 if (ret)
1725 goto out;
1727 ret = spu_acquire(ctx);
1728 if (ret)
1729 goto out;
1731 ret = spufs_wait(ctx->run_wq, ctx->state == SPU_STATE_RUNNABLE);
1732 if (ret)
1733 goto out;
1735 if (file->f_flags & O_NONBLOCK) {
1736 ret = ctx->ops->send_mfc_command(ctx, &cmd);
1737 } else {
1738 int status;
1739 ret = spufs_wait(ctx->mfc_wq,
1740 spu_send_mfc_command(ctx, cmd, &status));
1741 if (ret)
1742 goto out;
1743 if (status)
1744 ret = status;
1747 if (ret)
1748 goto out_unlock;
1750 ctx->tagwait |= 1 << cmd.tag;
1751 ret = size;
1753 out_unlock:
1754 spu_release(ctx);
1755 out:
1756 return ret;
1759 static unsigned int spufs_mfc_poll(struct file *file,poll_table *wait)
1761 struct spu_context *ctx = file->private_data;
1762 u32 free_elements, tagstatus;
1763 unsigned int mask;
1765 poll_wait(file, &ctx->mfc_wq, wait);
1768 * For now keep this uninterruptible and also ignore the rule
1769 * that poll should not sleep. Will be fixed later.
1771 mutex_lock(&ctx->state_mutex);
1772 ctx->ops->set_mfc_query(ctx, ctx->tagwait, 2);
1773 free_elements = ctx->ops->get_mfc_free_elements(ctx);
1774 tagstatus = ctx->ops->read_mfc_tagstatus(ctx);
1775 spu_release(ctx);
1777 mask = 0;
1778 if (free_elements & 0xffff)
1779 mask |= POLLOUT | POLLWRNORM;
1780 if (tagstatus & ctx->tagwait)
1781 mask |= POLLIN | POLLRDNORM;
1783 pr_debug("%s: free %d tagstatus %d tagwait %d\n", __FUNCTION__,
1784 free_elements, tagstatus, ctx->tagwait);
1786 return mask;
1789 static int spufs_mfc_flush(struct file *file, fl_owner_t id)
1791 struct spu_context *ctx = file->private_data;
1792 int ret;
1794 ret = spu_acquire(ctx);
1795 if (ret)
1796 goto out;
1797 #if 0
1798 /* this currently hangs */
1799 ret = spufs_wait(ctx->mfc_wq,
1800 ctx->ops->set_mfc_query(ctx, ctx->tagwait, 2));
1801 if (ret)
1802 goto out;
1803 ret = spufs_wait(ctx->mfc_wq,
1804 ctx->ops->read_mfc_tagstatus(ctx) == ctx->tagwait);
1805 if (ret)
1806 goto out;
1807 #else
1808 ret = 0;
1809 #endif
1810 spu_release(ctx);
1811 out:
1812 return ret;
1815 static int spufs_mfc_fsync(struct file *file, struct dentry *dentry,
1816 int datasync)
1818 return spufs_mfc_flush(file, NULL);
1821 static int spufs_mfc_fasync(int fd, struct file *file, int on)
1823 struct spu_context *ctx = file->private_data;
1825 return fasync_helper(fd, file, on, &ctx->mfc_fasync);
1828 static const struct file_operations spufs_mfc_fops = {
1829 .open = spufs_mfc_open,
1830 .release = spufs_mfc_release,
1831 .read = spufs_mfc_read,
1832 .write = spufs_mfc_write,
1833 .poll = spufs_mfc_poll,
1834 .flush = spufs_mfc_flush,
1835 .fsync = spufs_mfc_fsync,
1836 .fasync = spufs_mfc_fasync,
1837 .mmap = spufs_mfc_mmap,
1840 static int spufs_npc_set(void *data, u64 val)
1842 struct spu_context *ctx = data;
1843 int ret;
1845 ret = spu_acquire(ctx);
1846 if (ret)
1847 return ret;
1848 ctx->ops->npc_write(ctx, val);
1849 spu_release(ctx);
1851 return 0;
1854 static u64 spufs_npc_get(struct spu_context *ctx)
1856 return ctx->ops->npc_read(ctx);
1858 DEFINE_SPUFS_ATTRIBUTE(spufs_npc_ops, spufs_npc_get, spufs_npc_set,
1859 "0x%llx\n", SPU_ATTR_ACQUIRE);
1861 static int spufs_decr_set(void *data, u64 val)
1863 struct spu_context *ctx = data;
1864 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1865 int ret;
1867 ret = spu_acquire_saved(ctx);
1868 if (ret)
1869 return ret;
1870 lscsa->decr.slot[0] = (u32) val;
1871 spu_release_saved(ctx);
1873 return 0;
1876 static u64 spufs_decr_get(struct spu_context *ctx)
1878 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1879 return lscsa->decr.slot[0];
1881 DEFINE_SPUFS_ATTRIBUTE(spufs_decr_ops, spufs_decr_get, spufs_decr_set,
1882 "0x%llx\n", SPU_ATTR_ACQUIRE_SAVED);
1884 static int spufs_decr_status_set(void *data, u64 val)
1886 struct spu_context *ctx = data;
1887 int ret;
1889 ret = spu_acquire_saved(ctx);
1890 if (ret)
1891 return ret;
1892 if (val)
1893 ctx->csa.priv2.mfc_control_RW |= MFC_CNTL_DECREMENTER_RUNNING;
1894 else
1895 ctx->csa.priv2.mfc_control_RW &= ~MFC_CNTL_DECREMENTER_RUNNING;
1896 spu_release_saved(ctx);
1898 return 0;
1901 static u64 spufs_decr_status_get(struct spu_context *ctx)
1903 if (ctx->csa.priv2.mfc_control_RW & MFC_CNTL_DECREMENTER_RUNNING)
1904 return SPU_DECR_STATUS_RUNNING;
1905 else
1906 return 0;
1908 DEFINE_SPUFS_ATTRIBUTE(spufs_decr_status_ops, spufs_decr_status_get,
1909 spufs_decr_status_set, "0x%llx\n",
1910 SPU_ATTR_ACQUIRE_SAVED);
1912 static int spufs_event_mask_set(void *data, u64 val)
1914 struct spu_context *ctx = data;
1915 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1916 int ret;
1918 ret = spu_acquire_saved(ctx);
1919 if (ret)
1920 return ret;
1921 lscsa->event_mask.slot[0] = (u32) val;
1922 spu_release_saved(ctx);
1924 return 0;
1927 static u64 spufs_event_mask_get(struct spu_context *ctx)
1929 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1930 return lscsa->event_mask.slot[0];
1933 DEFINE_SPUFS_ATTRIBUTE(spufs_event_mask_ops, spufs_event_mask_get,
1934 spufs_event_mask_set, "0x%llx\n",
1935 SPU_ATTR_ACQUIRE_SAVED);
1937 static u64 spufs_event_status_get(struct spu_context *ctx)
1939 struct spu_state *state = &ctx->csa;
1940 u64 stat;
1941 stat = state->spu_chnlcnt_RW[0];
1942 if (stat)
1943 return state->spu_chnldata_RW[0];
1944 return 0;
1946 DEFINE_SPUFS_ATTRIBUTE(spufs_event_status_ops, spufs_event_status_get,
1947 NULL, "0x%llx\n", SPU_ATTR_ACQUIRE_SAVED)
1949 static int spufs_srr0_set(void *data, u64 val)
1951 struct spu_context *ctx = data;
1952 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1953 int ret;
1955 ret = spu_acquire_saved(ctx);
1956 if (ret)
1957 return ret;
1958 lscsa->srr0.slot[0] = (u32) val;
1959 spu_release_saved(ctx);
1961 return 0;
1964 static u64 spufs_srr0_get(struct spu_context *ctx)
1966 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1967 return lscsa->srr0.slot[0];
1969 DEFINE_SPUFS_ATTRIBUTE(spufs_srr0_ops, spufs_srr0_get, spufs_srr0_set,
1970 "0x%llx\n", SPU_ATTR_ACQUIRE_SAVED)
1972 static u64 spufs_id_get(struct spu_context *ctx)
1974 u64 num;
1976 if (ctx->state == SPU_STATE_RUNNABLE)
1977 num = ctx->spu->number;
1978 else
1979 num = (unsigned int)-1;
1981 return num;
1983 DEFINE_SPUFS_ATTRIBUTE(spufs_id_ops, spufs_id_get, NULL, "0x%llx\n",
1984 SPU_ATTR_ACQUIRE)
1986 static u64 spufs_object_id_get(struct spu_context *ctx)
1988 /* FIXME: Should there really be no locking here? */
1989 return ctx->object_id;
1992 static int spufs_object_id_set(void *data, u64 id)
1994 struct spu_context *ctx = data;
1995 ctx->object_id = id;
1997 return 0;
2000 DEFINE_SPUFS_ATTRIBUTE(spufs_object_id_ops, spufs_object_id_get,
2001 spufs_object_id_set, "0x%llx\n", SPU_ATTR_NOACQUIRE);
2003 static u64 spufs_lslr_get(struct spu_context *ctx)
2005 return ctx->csa.priv2.spu_lslr_RW;
2007 DEFINE_SPUFS_ATTRIBUTE(spufs_lslr_ops, spufs_lslr_get, NULL, "0x%llx\n",
2008 SPU_ATTR_ACQUIRE_SAVED);
2010 static int spufs_info_open(struct inode *inode, struct file *file)
2012 struct spufs_inode_info *i = SPUFS_I(inode);
2013 struct spu_context *ctx = i->i_ctx;
2014 file->private_data = ctx;
2015 return 0;
2018 static int spufs_caps_show(struct seq_file *s, void *private)
2020 struct spu_context *ctx = s->private;
2022 if (!(ctx->flags & SPU_CREATE_NOSCHED))
2023 seq_puts(s, "sched\n");
2024 if (!(ctx->flags & SPU_CREATE_ISOLATE))
2025 seq_puts(s, "step\n");
2026 return 0;
2029 static int spufs_caps_open(struct inode *inode, struct file *file)
2031 return single_open(file, spufs_caps_show, SPUFS_I(inode)->i_ctx);
2034 static const struct file_operations spufs_caps_fops = {
2035 .open = spufs_caps_open,
2036 .read = seq_read,
2037 .llseek = seq_lseek,
2038 .release = single_release,
2041 static ssize_t __spufs_mbox_info_read(struct spu_context *ctx,
2042 char __user *buf, size_t len, loff_t *pos)
2044 u32 data;
2046 /* EOF if there's no entry in the mbox */
2047 if (!(ctx->csa.prob.mb_stat_R & 0x0000ff))
2048 return 0;
2050 data = ctx->csa.prob.pu_mb_R;
2052 return simple_read_from_buffer(buf, len, pos, &data, sizeof data);
2055 static ssize_t spufs_mbox_info_read(struct file *file, char __user *buf,
2056 size_t len, loff_t *pos)
2058 int ret;
2059 struct spu_context *ctx = file->private_data;
2061 if (!access_ok(VERIFY_WRITE, buf, len))
2062 return -EFAULT;
2064 ret = spu_acquire_saved(ctx);
2065 if (ret)
2066 return ret;
2067 spin_lock(&ctx->csa.register_lock);
2068 ret = __spufs_mbox_info_read(ctx, buf, len, pos);
2069 spin_unlock(&ctx->csa.register_lock);
2070 spu_release_saved(ctx);
2072 return ret;
2075 static const struct file_operations spufs_mbox_info_fops = {
2076 .open = spufs_info_open,
2077 .read = spufs_mbox_info_read,
2078 .llseek = generic_file_llseek,
2081 static ssize_t __spufs_ibox_info_read(struct spu_context *ctx,
2082 char __user *buf, size_t len, loff_t *pos)
2084 u32 data;
2086 /* EOF if there's no entry in the ibox */
2087 if (!(ctx->csa.prob.mb_stat_R & 0xff0000))
2088 return 0;
2090 data = ctx->csa.priv2.puint_mb_R;
2092 return simple_read_from_buffer(buf, len, pos, &data, sizeof data);
2095 static ssize_t spufs_ibox_info_read(struct file *file, char __user *buf,
2096 size_t len, loff_t *pos)
2098 struct spu_context *ctx = file->private_data;
2099 int ret;
2101 if (!access_ok(VERIFY_WRITE, buf, len))
2102 return -EFAULT;
2104 ret = spu_acquire_saved(ctx);
2105 if (ret)
2106 return ret;
2107 spin_lock(&ctx->csa.register_lock);
2108 ret = __spufs_ibox_info_read(ctx, buf, len, pos);
2109 spin_unlock(&ctx->csa.register_lock);
2110 spu_release_saved(ctx);
2112 return ret;
2115 static const struct file_operations spufs_ibox_info_fops = {
2116 .open = spufs_info_open,
2117 .read = spufs_ibox_info_read,
2118 .llseek = generic_file_llseek,
2121 static ssize_t __spufs_wbox_info_read(struct spu_context *ctx,
2122 char __user *buf, size_t len, loff_t *pos)
2124 int i, cnt;
2125 u32 data[4];
2126 u32 wbox_stat;
2128 wbox_stat = ctx->csa.prob.mb_stat_R;
2129 cnt = 4 - ((wbox_stat & 0x00ff00) >> 8);
2130 for (i = 0; i < cnt; i++) {
2131 data[i] = ctx->csa.spu_mailbox_data[i];
2134 return simple_read_from_buffer(buf, len, pos, &data,
2135 cnt * sizeof(u32));
2138 static ssize_t spufs_wbox_info_read(struct file *file, char __user *buf,
2139 size_t len, loff_t *pos)
2141 struct spu_context *ctx = file->private_data;
2142 int ret;
2144 if (!access_ok(VERIFY_WRITE, buf, len))
2145 return -EFAULT;
2147 ret = spu_acquire_saved(ctx);
2148 if (ret)
2149 return ret;
2150 spin_lock(&ctx->csa.register_lock);
2151 ret = __spufs_wbox_info_read(ctx, buf, len, pos);
2152 spin_unlock(&ctx->csa.register_lock);
2153 spu_release_saved(ctx);
2155 return ret;
2158 static const struct file_operations spufs_wbox_info_fops = {
2159 .open = spufs_info_open,
2160 .read = spufs_wbox_info_read,
2161 .llseek = generic_file_llseek,
2164 static ssize_t __spufs_dma_info_read(struct spu_context *ctx,
2165 char __user *buf, size_t len, loff_t *pos)
2167 struct spu_dma_info info;
2168 struct mfc_cq_sr *qp, *spuqp;
2169 int i;
2171 info.dma_info_type = ctx->csa.priv2.spu_tag_status_query_RW;
2172 info.dma_info_mask = ctx->csa.lscsa->tag_mask.slot[0];
2173 info.dma_info_status = ctx->csa.spu_chnldata_RW[24];
2174 info.dma_info_stall_and_notify = ctx->csa.spu_chnldata_RW[25];
2175 info.dma_info_atomic_command_status = ctx->csa.spu_chnldata_RW[27];
2176 for (i = 0; i < 16; i++) {
2177 qp = &info.dma_info_command_data[i];
2178 spuqp = &ctx->csa.priv2.spuq[i];
2180 qp->mfc_cq_data0_RW = spuqp->mfc_cq_data0_RW;
2181 qp->mfc_cq_data1_RW = spuqp->mfc_cq_data1_RW;
2182 qp->mfc_cq_data2_RW = spuqp->mfc_cq_data2_RW;
2183 qp->mfc_cq_data3_RW = spuqp->mfc_cq_data3_RW;
2186 return simple_read_from_buffer(buf, len, pos, &info,
2187 sizeof info);
2190 static ssize_t spufs_dma_info_read(struct file *file, char __user *buf,
2191 size_t len, loff_t *pos)
2193 struct spu_context *ctx = file->private_data;
2194 int ret;
2196 if (!access_ok(VERIFY_WRITE, buf, len))
2197 return -EFAULT;
2199 ret = spu_acquire_saved(ctx);
2200 if (ret)
2201 return ret;
2202 spin_lock(&ctx->csa.register_lock);
2203 ret = __spufs_dma_info_read(ctx, buf, len, pos);
2204 spin_unlock(&ctx->csa.register_lock);
2205 spu_release_saved(ctx);
2207 return ret;
2210 static const struct file_operations spufs_dma_info_fops = {
2211 .open = spufs_info_open,
2212 .read = spufs_dma_info_read,
2215 static ssize_t __spufs_proxydma_info_read(struct spu_context *ctx,
2216 char __user *buf, size_t len, loff_t *pos)
2218 struct spu_proxydma_info info;
2219 struct mfc_cq_sr *qp, *puqp;
2220 int ret = sizeof info;
2221 int i;
2223 if (len < ret)
2224 return -EINVAL;
2226 if (!access_ok(VERIFY_WRITE, buf, len))
2227 return -EFAULT;
2229 info.proxydma_info_type = ctx->csa.prob.dma_querytype_RW;
2230 info.proxydma_info_mask = ctx->csa.prob.dma_querymask_RW;
2231 info.proxydma_info_status = ctx->csa.prob.dma_tagstatus_R;
2232 for (i = 0; i < 8; i++) {
2233 qp = &info.proxydma_info_command_data[i];
2234 puqp = &ctx->csa.priv2.puq[i];
2236 qp->mfc_cq_data0_RW = puqp->mfc_cq_data0_RW;
2237 qp->mfc_cq_data1_RW = puqp->mfc_cq_data1_RW;
2238 qp->mfc_cq_data2_RW = puqp->mfc_cq_data2_RW;
2239 qp->mfc_cq_data3_RW = puqp->mfc_cq_data3_RW;
2242 return simple_read_from_buffer(buf, len, pos, &info,
2243 sizeof info);
2246 static ssize_t spufs_proxydma_info_read(struct file *file, char __user *buf,
2247 size_t len, loff_t *pos)
2249 struct spu_context *ctx = file->private_data;
2250 int ret;
2252 ret = spu_acquire_saved(ctx);
2253 if (ret)
2254 return ret;
2255 spin_lock(&ctx->csa.register_lock);
2256 ret = __spufs_proxydma_info_read(ctx, buf, len, pos);
2257 spin_unlock(&ctx->csa.register_lock);
2258 spu_release_saved(ctx);
2260 return ret;
2263 static const struct file_operations spufs_proxydma_info_fops = {
2264 .open = spufs_info_open,
2265 .read = spufs_proxydma_info_read,
2268 static int spufs_show_tid(struct seq_file *s, void *private)
2270 struct spu_context *ctx = s->private;
2272 seq_printf(s, "%d\n", ctx->tid);
2273 return 0;
2276 static int spufs_tid_open(struct inode *inode, struct file *file)
2278 return single_open(file, spufs_show_tid, SPUFS_I(inode)->i_ctx);
2281 static const struct file_operations spufs_tid_fops = {
2282 .open = spufs_tid_open,
2283 .read = seq_read,
2284 .llseek = seq_lseek,
2285 .release = single_release,
2288 static const char *ctx_state_names[] = {
2289 "user", "system", "iowait", "loaded"
2292 static unsigned long long spufs_acct_time(struct spu_context *ctx,
2293 enum spu_utilization_state state)
2295 struct timespec ts;
2296 unsigned long long time = ctx->stats.times[state];
2299 * In general, utilization statistics are updated by the controlling
2300 * thread as the spu context moves through various well defined
2301 * state transitions, but if the context is lazily loaded its
2302 * utilization statistics are not updated as the controlling thread
2303 * is not tightly coupled with the execution of the spu context. We
2304 * calculate and apply the time delta from the last recorded state
2305 * of the spu context.
2307 if (ctx->spu && ctx->stats.util_state == state) {
2308 ktime_get_ts(&ts);
2309 time += timespec_to_ns(&ts) - ctx->stats.tstamp;
2312 return time / NSEC_PER_MSEC;
2315 static unsigned long long spufs_slb_flts(struct spu_context *ctx)
2317 unsigned long long slb_flts = ctx->stats.slb_flt;
2319 if (ctx->state == SPU_STATE_RUNNABLE) {
2320 slb_flts += (ctx->spu->stats.slb_flt -
2321 ctx->stats.slb_flt_base);
2324 return slb_flts;
2327 static unsigned long long spufs_class2_intrs(struct spu_context *ctx)
2329 unsigned long long class2_intrs = ctx->stats.class2_intr;
2331 if (ctx->state == SPU_STATE_RUNNABLE) {
2332 class2_intrs += (ctx->spu->stats.class2_intr -
2333 ctx->stats.class2_intr_base);
2336 return class2_intrs;
2340 static int spufs_show_stat(struct seq_file *s, void *private)
2342 struct spu_context *ctx = s->private;
2343 int ret;
2345 ret = spu_acquire(ctx);
2346 if (ret)
2347 return ret;
2349 seq_printf(s, "%s %llu %llu %llu %llu "
2350 "%llu %llu %llu %llu %llu %llu %llu %llu\n",
2351 ctx_state_names[ctx->stats.util_state],
2352 spufs_acct_time(ctx, SPU_UTIL_USER),
2353 spufs_acct_time(ctx, SPU_UTIL_SYSTEM),
2354 spufs_acct_time(ctx, SPU_UTIL_IOWAIT),
2355 spufs_acct_time(ctx, SPU_UTIL_IDLE_LOADED),
2356 ctx->stats.vol_ctx_switch,
2357 ctx->stats.invol_ctx_switch,
2358 spufs_slb_flts(ctx),
2359 ctx->stats.hash_flt,
2360 ctx->stats.min_flt,
2361 ctx->stats.maj_flt,
2362 spufs_class2_intrs(ctx),
2363 ctx->stats.libassist);
2364 spu_release(ctx);
2365 return 0;
2368 static int spufs_stat_open(struct inode *inode, struct file *file)
2370 return single_open(file, spufs_show_stat, SPUFS_I(inode)->i_ctx);
2373 static const struct file_operations spufs_stat_fops = {
2374 .open = spufs_stat_open,
2375 .read = seq_read,
2376 .llseek = seq_lseek,
2377 .release = single_release,
2381 struct tree_descr spufs_dir_contents[] = {
2382 { "capabilities", &spufs_caps_fops, 0444, },
2383 { "mem", &spufs_mem_fops, 0666, },
2384 { "regs", &spufs_regs_fops, 0666, },
2385 { "mbox", &spufs_mbox_fops, 0444, },
2386 { "ibox", &spufs_ibox_fops, 0444, },
2387 { "wbox", &spufs_wbox_fops, 0222, },
2388 { "mbox_stat", &spufs_mbox_stat_fops, 0444, },
2389 { "ibox_stat", &spufs_ibox_stat_fops, 0444, },
2390 { "wbox_stat", &spufs_wbox_stat_fops, 0444, },
2391 { "signal1", &spufs_signal1_fops, 0666, },
2392 { "signal2", &spufs_signal2_fops, 0666, },
2393 { "signal1_type", &spufs_signal1_type, 0666, },
2394 { "signal2_type", &spufs_signal2_type, 0666, },
2395 { "cntl", &spufs_cntl_fops, 0666, },
2396 { "fpcr", &spufs_fpcr_fops, 0666, },
2397 { "lslr", &spufs_lslr_ops, 0444, },
2398 { "mfc", &spufs_mfc_fops, 0666, },
2399 { "mss", &spufs_mss_fops, 0666, },
2400 { "npc", &spufs_npc_ops, 0666, },
2401 { "srr0", &spufs_srr0_ops, 0666, },
2402 { "decr", &spufs_decr_ops, 0666, },
2403 { "decr_status", &spufs_decr_status_ops, 0666, },
2404 { "event_mask", &spufs_event_mask_ops, 0666, },
2405 { "event_status", &spufs_event_status_ops, 0444, },
2406 { "psmap", &spufs_psmap_fops, 0666, },
2407 { "phys-id", &spufs_id_ops, 0666, },
2408 { "object-id", &spufs_object_id_ops, 0666, },
2409 { "mbox_info", &spufs_mbox_info_fops, 0444, },
2410 { "ibox_info", &spufs_ibox_info_fops, 0444, },
2411 { "wbox_info", &spufs_wbox_info_fops, 0444, },
2412 { "dma_info", &spufs_dma_info_fops, 0444, },
2413 { "proxydma_info", &spufs_proxydma_info_fops, 0444, },
2414 { "tid", &spufs_tid_fops, 0444, },
2415 { "stat", &spufs_stat_fops, 0444, },
2419 struct tree_descr spufs_dir_nosched_contents[] = {
2420 { "capabilities", &spufs_caps_fops, 0444, },
2421 { "mem", &spufs_mem_fops, 0666, },
2422 { "mbox", &spufs_mbox_fops, 0444, },
2423 { "ibox", &spufs_ibox_fops, 0444, },
2424 { "wbox", &spufs_wbox_fops, 0222, },
2425 { "mbox_stat", &spufs_mbox_stat_fops, 0444, },
2426 { "ibox_stat", &spufs_ibox_stat_fops, 0444, },
2427 { "wbox_stat", &spufs_wbox_stat_fops, 0444, },
2428 { "signal1", &spufs_signal1_nosched_fops, 0222, },
2429 { "signal2", &spufs_signal2_nosched_fops, 0222, },
2430 { "signal1_type", &spufs_signal1_type, 0666, },
2431 { "signal2_type", &spufs_signal2_type, 0666, },
2432 { "mss", &spufs_mss_fops, 0666, },
2433 { "mfc", &spufs_mfc_fops, 0666, },
2434 { "cntl", &spufs_cntl_fops, 0666, },
2435 { "npc", &spufs_npc_ops, 0666, },
2436 { "psmap", &spufs_psmap_fops, 0666, },
2437 { "phys-id", &spufs_id_ops, 0666, },
2438 { "object-id", &spufs_object_id_ops, 0666, },
2439 { "tid", &spufs_tid_fops, 0444, },
2440 { "stat", &spufs_stat_fops, 0444, },
2444 struct spufs_coredump_reader spufs_coredump_read[] = {
2445 { "regs", __spufs_regs_read, NULL, sizeof(struct spu_reg128[128])},
2446 { "fpcr", __spufs_fpcr_read, NULL, sizeof(struct spu_reg128) },
2447 { "lslr", NULL, spufs_lslr_get, 19 },
2448 { "decr", NULL, spufs_decr_get, 19 },
2449 { "decr_status", NULL, spufs_decr_status_get, 19 },
2450 { "mem", __spufs_mem_read, NULL, LS_SIZE, },
2451 { "signal1", __spufs_signal1_read, NULL, sizeof(u32) },
2452 { "signal1_type", NULL, spufs_signal1_type_get, 19 },
2453 { "signal2", __spufs_signal2_read, NULL, sizeof(u32) },
2454 { "signal2_type", NULL, spufs_signal2_type_get, 19 },
2455 { "event_mask", NULL, spufs_event_mask_get, 19 },
2456 { "event_status", NULL, spufs_event_status_get, 19 },
2457 { "mbox_info", __spufs_mbox_info_read, NULL, sizeof(u32) },
2458 { "ibox_info", __spufs_ibox_info_read, NULL, sizeof(u32) },
2459 { "wbox_info", __spufs_wbox_info_read, NULL, 4 * sizeof(u32)},
2460 { "dma_info", __spufs_dma_info_read, NULL, sizeof(struct spu_dma_info)},
2461 { "proxydma_info", __spufs_proxydma_info_read,
2462 NULL, sizeof(struct spu_proxydma_info)},
2463 { "object-id", NULL, spufs_object_id_get, 19 },
2464 { "npc", NULL, spufs_npc_get, 19 },
2465 { NULL },