kbuild: Fix instrumentation removal breakage on avr32
[wrt350n-kernel.git] / arch / powerpc / platforms / cell / spufs / file.c
blob3fcd06418b01d165ba1d01f7d9930608d6d15c6d
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>
33 #include <asm/io.h>
34 #include <asm/semaphore.h>
35 #include <asm/spu.h>
36 #include <asm/spu_info.h>
37 #include <asm/uaccess.h>
39 #include "spufs.h"
41 #define SPUFS_MMAP_4K (PAGE_SIZE == 0x1000)
43 /* Simple attribute files */
44 struct spufs_attr {
45 int (*get)(void *, u64 *);
46 int (*set)(void *, u64);
47 char get_buf[24]; /* enough to store a u64 and "\n\0" */
48 char set_buf[24];
49 void *data;
50 const char *fmt; /* format for read operation */
51 struct mutex mutex; /* protects access to these buffers */
54 static int spufs_attr_open(struct inode *inode, struct file *file,
55 int (*get)(void *, u64 *), int (*set)(void *, u64),
56 const char *fmt)
58 struct spufs_attr *attr;
60 attr = kmalloc(sizeof(*attr), GFP_KERNEL);
61 if (!attr)
62 return -ENOMEM;
64 attr->get = get;
65 attr->set = set;
66 attr->data = inode->i_private;
67 attr->fmt = fmt;
68 mutex_init(&attr->mutex);
69 file->private_data = attr;
71 return nonseekable_open(inode, file);
74 static int spufs_attr_release(struct inode *inode, struct file *file)
76 kfree(file->private_data);
77 return 0;
80 static ssize_t spufs_attr_read(struct file *file, char __user *buf,
81 size_t len, loff_t *ppos)
83 struct spufs_attr *attr;
84 size_t size;
85 ssize_t ret;
87 attr = file->private_data;
88 if (!attr->get)
89 return -EACCES;
91 ret = mutex_lock_interruptible(&attr->mutex);
92 if (ret)
93 return ret;
95 if (*ppos) { /* continued read */
96 size = strlen(attr->get_buf);
97 } else { /* first read */
98 u64 val;
99 ret = attr->get(attr->data, &val);
100 if (ret)
101 goto out;
103 size = scnprintf(attr->get_buf, sizeof(attr->get_buf),
104 attr->fmt, (unsigned long long)val);
107 ret = simple_read_from_buffer(buf, len, ppos, attr->get_buf, size);
108 out:
109 mutex_unlock(&attr->mutex);
110 return ret;
113 static ssize_t spufs_attr_write(struct file *file, const char __user *buf,
114 size_t len, loff_t *ppos)
116 struct spufs_attr *attr;
117 u64 val;
118 size_t size;
119 ssize_t ret;
121 attr = file->private_data;
122 if (!attr->set)
123 return -EACCES;
125 ret = mutex_lock_interruptible(&attr->mutex);
126 if (ret)
127 return ret;
129 ret = -EFAULT;
130 size = min(sizeof(attr->set_buf) - 1, len);
131 if (copy_from_user(attr->set_buf, buf, size))
132 goto out;
134 ret = len; /* claim we got the whole input */
135 attr->set_buf[size] = '\0';
136 val = simple_strtol(attr->set_buf, NULL, 0);
137 attr->set(attr->data, val);
138 out:
139 mutex_unlock(&attr->mutex);
140 return ret;
143 #define DEFINE_SPUFS_SIMPLE_ATTRIBUTE(__fops, __get, __set, __fmt) \
144 static int __fops ## _open(struct inode *inode, struct file *file) \
146 __simple_attr_check_format(__fmt, 0ull); \
147 return spufs_attr_open(inode, file, __get, __set, __fmt); \
149 static struct file_operations __fops = { \
150 .owner = THIS_MODULE, \
151 .open = __fops ## _open, \
152 .release = spufs_attr_release, \
153 .read = spufs_attr_read, \
154 .write = spufs_attr_write, \
158 static int
159 spufs_mem_open(struct inode *inode, struct file *file)
161 struct spufs_inode_info *i = SPUFS_I(inode);
162 struct spu_context *ctx = i->i_ctx;
164 mutex_lock(&ctx->mapping_lock);
165 file->private_data = ctx;
166 if (!i->i_openers++)
167 ctx->local_store = inode->i_mapping;
168 mutex_unlock(&ctx->mapping_lock);
169 return 0;
172 static int
173 spufs_mem_release(struct inode *inode, struct file *file)
175 struct spufs_inode_info *i = SPUFS_I(inode);
176 struct spu_context *ctx = i->i_ctx;
178 mutex_lock(&ctx->mapping_lock);
179 if (!--i->i_openers)
180 ctx->local_store = NULL;
181 mutex_unlock(&ctx->mapping_lock);
182 return 0;
185 static ssize_t
186 __spufs_mem_read(struct spu_context *ctx, char __user *buffer,
187 size_t size, loff_t *pos)
189 char *local_store = ctx->ops->get_ls(ctx);
190 return simple_read_from_buffer(buffer, size, pos, local_store,
191 LS_SIZE);
194 static ssize_t
195 spufs_mem_read(struct file *file, char __user *buffer,
196 size_t size, loff_t *pos)
198 struct spu_context *ctx = file->private_data;
199 ssize_t ret;
201 ret = spu_acquire(ctx);
202 if (ret)
203 return ret;
204 ret = __spufs_mem_read(ctx, buffer, size, pos);
205 spu_release(ctx);
207 return ret;
210 static ssize_t
211 spufs_mem_write(struct file *file, const char __user *buffer,
212 size_t size, loff_t *ppos)
214 struct spu_context *ctx = file->private_data;
215 char *local_store;
216 loff_t pos = *ppos;
217 int ret;
219 if (pos < 0)
220 return -EINVAL;
221 if (pos > LS_SIZE)
222 return -EFBIG;
223 if (size > LS_SIZE - pos)
224 size = LS_SIZE - pos;
226 ret = spu_acquire(ctx);
227 if (ret)
228 return ret;
230 local_store = ctx->ops->get_ls(ctx);
231 ret = copy_from_user(local_store + pos, buffer, size);
232 spu_release(ctx);
234 if (ret)
235 return -EFAULT;
236 *ppos = pos + size;
237 return size;
240 static unsigned long spufs_mem_mmap_nopfn(struct vm_area_struct *vma,
241 unsigned long address)
243 struct spu_context *ctx = vma->vm_file->private_data;
244 unsigned long pfn, offset, addr0 = address;
245 #ifdef CONFIG_SPU_FS_64K_LS
246 struct spu_state *csa = &ctx->csa;
247 int psize;
249 /* Check what page size we are using */
250 psize = get_slice_psize(vma->vm_mm, address);
252 /* Some sanity checking */
253 BUG_ON(csa->use_big_pages != (psize == MMU_PAGE_64K));
255 /* Wow, 64K, cool, we need to align the address though */
256 if (csa->use_big_pages) {
257 BUG_ON(vma->vm_start & 0xffff);
258 address &= ~0xfffful;
260 #endif /* CONFIG_SPU_FS_64K_LS */
262 offset = (address - vma->vm_start) + (vma->vm_pgoff << PAGE_SHIFT);
263 if (offset >= LS_SIZE)
264 return NOPFN_SIGBUS;
266 pr_debug("spufs_mem_mmap_nopfn address=0x%lx -> 0x%lx, offset=0x%lx\n",
267 addr0, address, offset);
269 if (spu_acquire(ctx))
270 return NOPFN_REFAULT;
272 if (ctx->state == SPU_STATE_SAVED) {
273 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
274 & ~_PAGE_NO_CACHE);
275 pfn = vmalloc_to_pfn(ctx->csa.lscsa->ls + offset);
276 } else {
277 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
278 | _PAGE_NO_CACHE);
279 pfn = (ctx->spu->local_store_phys + offset) >> PAGE_SHIFT;
281 vm_insert_pfn(vma, address, pfn);
283 spu_release(ctx);
285 return NOPFN_REFAULT;
289 static struct vm_operations_struct spufs_mem_mmap_vmops = {
290 .nopfn = spufs_mem_mmap_nopfn,
293 static int spufs_mem_mmap(struct file *file, struct vm_area_struct *vma)
295 #ifdef CONFIG_SPU_FS_64K_LS
296 struct spu_context *ctx = file->private_data;
297 struct spu_state *csa = &ctx->csa;
299 /* Sanity check VMA alignment */
300 if (csa->use_big_pages) {
301 pr_debug("spufs_mem_mmap 64K, start=0x%lx, end=0x%lx,"
302 " pgoff=0x%lx\n", vma->vm_start, vma->vm_end,
303 vma->vm_pgoff);
304 if (vma->vm_start & 0xffff)
305 return -EINVAL;
306 if (vma->vm_pgoff & 0xf)
307 return -EINVAL;
309 #endif /* CONFIG_SPU_FS_64K_LS */
311 if (!(vma->vm_flags & VM_SHARED))
312 return -EINVAL;
314 vma->vm_flags |= VM_IO | VM_PFNMAP;
315 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
316 | _PAGE_NO_CACHE);
318 vma->vm_ops = &spufs_mem_mmap_vmops;
319 return 0;
322 #ifdef CONFIG_SPU_FS_64K_LS
323 static unsigned long spufs_get_unmapped_area(struct file *file,
324 unsigned long addr, unsigned long len, unsigned long pgoff,
325 unsigned long flags)
327 struct spu_context *ctx = file->private_data;
328 struct spu_state *csa = &ctx->csa;
330 /* If not using big pages, fallback to normal MM g_u_a */
331 if (!csa->use_big_pages)
332 return current->mm->get_unmapped_area(file, addr, len,
333 pgoff, flags);
335 /* Else, try to obtain a 64K pages slice */
336 return slice_get_unmapped_area(addr, len, flags,
337 MMU_PAGE_64K, 1, 0);
339 #endif /* CONFIG_SPU_FS_64K_LS */
341 static const struct file_operations spufs_mem_fops = {
342 .open = spufs_mem_open,
343 .release = spufs_mem_release,
344 .read = spufs_mem_read,
345 .write = spufs_mem_write,
346 .llseek = generic_file_llseek,
347 .mmap = spufs_mem_mmap,
348 #ifdef CONFIG_SPU_FS_64K_LS
349 .get_unmapped_area = spufs_get_unmapped_area,
350 #endif
353 static unsigned long spufs_ps_nopfn(struct vm_area_struct *vma,
354 unsigned long address,
355 unsigned long ps_offs,
356 unsigned long ps_size)
358 struct spu_context *ctx = vma->vm_file->private_data;
359 unsigned long area, offset = address - vma->vm_start;
361 offset += vma->vm_pgoff << PAGE_SHIFT;
362 if (offset >= ps_size)
363 return NOPFN_SIGBUS;
366 * We have to wait for context to be loaded before we have
367 * pages to hand out to the user, but we don't want to wait
368 * with the mmap_sem held.
369 * It is possible to drop the mmap_sem here, but then we need
370 * to return NOPFN_REFAULT because the mappings may have
371 * hanged.
373 if (spu_acquire(ctx))
374 return NOPFN_REFAULT;
376 if (ctx->state == SPU_STATE_SAVED) {
377 up_read(&current->mm->mmap_sem);
378 spufs_wait(ctx->run_wq, ctx->state == SPU_STATE_RUNNABLE);
379 down_read(&current->mm->mmap_sem);
380 } else {
381 area = ctx->spu->problem_phys + ps_offs;
382 vm_insert_pfn(vma, address, (area + offset) >> PAGE_SHIFT);
385 spu_release(ctx);
386 return NOPFN_REFAULT;
389 #if SPUFS_MMAP_4K
390 static unsigned long spufs_cntl_mmap_nopfn(struct vm_area_struct *vma,
391 unsigned long address)
393 return spufs_ps_nopfn(vma, address, 0x4000, 0x1000);
396 static struct vm_operations_struct spufs_cntl_mmap_vmops = {
397 .nopfn = spufs_cntl_mmap_nopfn,
401 * mmap support for problem state control area [0x4000 - 0x4fff].
403 static int spufs_cntl_mmap(struct file *file, struct vm_area_struct *vma)
405 if (!(vma->vm_flags & VM_SHARED))
406 return -EINVAL;
408 vma->vm_flags |= VM_IO | VM_PFNMAP;
409 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
410 | _PAGE_NO_CACHE | _PAGE_GUARDED);
412 vma->vm_ops = &spufs_cntl_mmap_vmops;
413 return 0;
415 #else /* SPUFS_MMAP_4K */
416 #define spufs_cntl_mmap NULL
417 #endif /* !SPUFS_MMAP_4K */
419 static int spufs_cntl_get(void *data, u64 *val)
421 struct spu_context *ctx = data;
422 int ret;
424 ret = spu_acquire(ctx);
425 if (ret)
426 return ret;
427 *val = ctx->ops->status_read(ctx);
428 spu_release(ctx);
430 return 0;
433 static int spufs_cntl_set(void *data, u64 val)
435 struct spu_context *ctx = data;
436 int ret;
438 ret = spu_acquire(ctx);
439 if (ret)
440 return ret;
441 ctx->ops->runcntl_write(ctx, val);
442 spu_release(ctx);
444 return 0;
447 static int spufs_cntl_open(struct inode *inode, struct file *file)
449 struct spufs_inode_info *i = SPUFS_I(inode);
450 struct spu_context *ctx = i->i_ctx;
452 mutex_lock(&ctx->mapping_lock);
453 file->private_data = ctx;
454 if (!i->i_openers++)
455 ctx->cntl = inode->i_mapping;
456 mutex_unlock(&ctx->mapping_lock);
457 return spufs_attr_open(inode, file, spufs_cntl_get,
458 spufs_cntl_set, "0x%08lx");
461 static int
462 spufs_cntl_release(struct inode *inode, struct file *file)
464 struct spufs_inode_info *i = SPUFS_I(inode);
465 struct spu_context *ctx = i->i_ctx;
467 spufs_attr_release(inode, file);
469 mutex_lock(&ctx->mapping_lock);
470 if (!--i->i_openers)
471 ctx->cntl = NULL;
472 mutex_unlock(&ctx->mapping_lock);
473 return 0;
476 static const struct file_operations spufs_cntl_fops = {
477 .open = spufs_cntl_open,
478 .release = spufs_cntl_release,
479 .read = spufs_attr_read,
480 .write = spufs_attr_write,
481 .mmap = spufs_cntl_mmap,
484 static int
485 spufs_regs_open(struct inode *inode, struct file *file)
487 struct spufs_inode_info *i = SPUFS_I(inode);
488 file->private_data = i->i_ctx;
489 return 0;
492 static ssize_t
493 __spufs_regs_read(struct spu_context *ctx, char __user *buffer,
494 size_t size, loff_t *pos)
496 struct spu_lscsa *lscsa = ctx->csa.lscsa;
497 return simple_read_from_buffer(buffer, size, pos,
498 lscsa->gprs, sizeof lscsa->gprs);
501 static ssize_t
502 spufs_regs_read(struct file *file, char __user *buffer,
503 size_t size, loff_t *pos)
505 int ret;
506 struct spu_context *ctx = file->private_data;
508 ret = spu_acquire_saved(ctx);
509 if (ret)
510 return ret;
511 ret = __spufs_regs_read(ctx, buffer, size, pos);
512 spu_release_saved(ctx);
513 return ret;
516 static ssize_t
517 spufs_regs_write(struct file *file, const char __user *buffer,
518 size_t size, loff_t *pos)
520 struct spu_context *ctx = file->private_data;
521 struct spu_lscsa *lscsa = ctx->csa.lscsa;
522 int ret;
524 size = min_t(ssize_t, sizeof lscsa->gprs - *pos, size);
525 if (size <= 0)
526 return -EFBIG;
527 *pos += size;
529 ret = spu_acquire_saved(ctx);
530 if (ret)
531 return ret;
533 ret = copy_from_user(lscsa->gprs + *pos - size,
534 buffer, size) ? -EFAULT : size;
536 spu_release_saved(ctx);
537 return ret;
540 static const struct file_operations spufs_regs_fops = {
541 .open = spufs_regs_open,
542 .read = spufs_regs_read,
543 .write = spufs_regs_write,
544 .llseek = generic_file_llseek,
547 static ssize_t
548 __spufs_fpcr_read(struct spu_context *ctx, char __user * buffer,
549 size_t size, loff_t * pos)
551 struct spu_lscsa *lscsa = ctx->csa.lscsa;
552 return simple_read_from_buffer(buffer, size, pos,
553 &lscsa->fpcr, sizeof(lscsa->fpcr));
556 static ssize_t
557 spufs_fpcr_read(struct file *file, char __user * buffer,
558 size_t size, loff_t * pos)
560 int ret;
561 struct spu_context *ctx = file->private_data;
563 ret = spu_acquire_saved(ctx);
564 if (ret)
565 return ret;
566 ret = __spufs_fpcr_read(ctx, buffer, size, pos);
567 spu_release_saved(ctx);
568 return ret;
571 static ssize_t
572 spufs_fpcr_write(struct file *file, const char __user * buffer,
573 size_t size, loff_t * pos)
575 struct spu_context *ctx = file->private_data;
576 struct spu_lscsa *lscsa = ctx->csa.lscsa;
577 int ret;
579 size = min_t(ssize_t, sizeof(lscsa->fpcr) - *pos, size);
580 if (size <= 0)
581 return -EFBIG;
583 ret = spu_acquire_saved(ctx);
584 if (ret)
585 return ret;
587 *pos += size;
588 ret = copy_from_user((char *)&lscsa->fpcr + *pos - size,
589 buffer, size) ? -EFAULT : size;
591 spu_release_saved(ctx);
592 return ret;
595 static const struct file_operations spufs_fpcr_fops = {
596 .open = spufs_regs_open,
597 .read = spufs_fpcr_read,
598 .write = spufs_fpcr_write,
599 .llseek = generic_file_llseek,
602 /* generic open function for all pipe-like files */
603 static int spufs_pipe_open(struct inode *inode, struct file *file)
605 struct spufs_inode_info *i = SPUFS_I(inode);
606 file->private_data = i->i_ctx;
608 return nonseekable_open(inode, file);
612 * Read as many bytes from the mailbox as possible, until
613 * one of the conditions becomes true:
615 * - no more data available in the mailbox
616 * - end of the user provided buffer
617 * - end of the mapped area
619 static ssize_t spufs_mbox_read(struct file *file, char __user *buf,
620 size_t len, loff_t *pos)
622 struct spu_context *ctx = file->private_data;
623 u32 mbox_data, __user *udata;
624 ssize_t count;
626 if (len < 4)
627 return -EINVAL;
629 if (!access_ok(VERIFY_WRITE, buf, len))
630 return -EFAULT;
632 udata = (void __user *)buf;
634 count = spu_acquire(ctx);
635 if (count)
636 return count;
638 for (count = 0; (count + 4) <= len; count += 4, udata++) {
639 int ret;
640 ret = ctx->ops->mbox_read(ctx, &mbox_data);
641 if (ret == 0)
642 break;
645 * at the end of the mapped area, we can fault
646 * but still need to return the data we have
647 * read successfully so far.
649 ret = __put_user(mbox_data, udata);
650 if (ret) {
651 if (!count)
652 count = -EFAULT;
653 break;
656 spu_release(ctx);
658 if (!count)
659 count = -EAGAIN;
661 return count;
664 static const struct file_operations spufs_mbox_fops = {
665 .open = spufs_pipe_open,
666 .read = spufs_mbox_read,
669 static ssize_t spufs_mbox_stat_read(struct file *file, char __user *buf,
670 size_t len, loff_t *pos)
672 struct spu_context *ctx = file->private_data;
673 ssize_t ret;
674 u32 mbox_stat;
676 if (len < 4)
677 return -EINVAL;
679 ret = spu_acquire(ctx);
680 if (ret)
681 return ret;
683 mbox_stat = ctx->ops->mbox_stat_read(ctx) & 0xff;
685 spu_release(ctx);
687 if (copy_to_user(buf, &mbox_stat, sizeof mbox_stat))
688 return -EFAULT;
690 return 4;
693 static const struct file_operations spufs_mbox_stat_fops = {
694 .open = spufs_pipe_open,
695 .read = spufs_mbox_stat_read,
698 /* low-level ibox access function */
699 size_t spu_ibox_read(struct spu_context *ctx, u32 *data)
701 return ctx->ops->ibox_read(ctx, data);
704 static int spufs_ibox_fasync(int fd, struct file *file, int on)
706 struct spu_context *ctx = file->private_data;
708 return fasync_helper(fd, file, on, &ctx->ibox_fasync);
711 /* interrupt-level ibox callback function. */
712 void spufs_ibox_callback(struct spu *spu)
714 struct spu_context *ctx = spu->ctx;
716 if (!ctx)
717 return;
719 wake_up_all(&ctx->ibox_wq);
720 kill_fasync(&ctx->ibox_fasync, SIGIO, POLLIN);
724 * Read as many bytes from the interrupt mailbox as possible, until
725 * one of the conditions becomes true:
727 * - no more data available in the mailbox
728 * - end of the user provided buffer
729 * - end of the mapped area
731 * If the file is opened without O_NONBLOCK, we wait here until
732 * any data is available, but return when we have been able to
733 * read something.
735 static ssize_t spufs_ibox_read(struct file *file, char __user *buf,
736 size_t len, loff_t *pos)
738 struct spu_context *ctx = file->private_data;
739 u32 ibox_data, __user *udata;
740 ssize_t count;
742 if (len < 4)
743 return -EINVAL;
745 if (!access_ok(VERIFY_WRITE, buf, len))
746 return -EFAULT;
748 udata = (void __user *)buf;
750 count = spu_acquire(ctx);
751 if (count)
752 return count;
754 /* wait only for the first element */
755 count = 0;
756 if (file->f_flags & O_NONBLOCK) {
757 if (!spu_ibox_read(ctx, &ibox_data))
758 count = -EAGAIN;
759 } else {
760 count = spufs_wait(ctx->ibox_wq, spu_ibox_read(ctx, &ibox_data));
762 if (count)
763 goto out;
765 /* if we can't write at all, return -EFAULT */
766 count = __put_user(ibox_data, udata);
767 if (count)
768 goto out;
770 for (count = 4, udata++; (count + 4) <= len; count += 4, udata++) {
771 int ret;
772 ret = ctx->ops->ibox_read(ctx, &ibox_data);
773 if (ret == 0)
774 break;
776 * at the end of the mapped area, we can fault
777 * but still need to return the data we have
778 * read successfully so far.
780 ret = __put_user(ibox_data, udata);
781 if (ret)
782 break;
785 out:
786 spu_release(ctx);
788 return count;
791 static unsigned int spufs_ibox_poll(struct file *file, poll_table *wait)
793 struct spu_context *ctx = file->private_data;
794 unsigned int mask;
796 poll_wait(file, &ctx->ibox_wq, wait);
799 * For now keep this uninterruptible and also ignore the rule
800 * that poll should not sleep. Will be fixed later.
802 mutex_lock(&ctx->state_mutex);
803 mask = ctx->ops->mbox_stat_poll(ctx, POLLIN | POLLRDNORM);
804 spu_release(ctx);
806 return mask;
809 static const struct file_operations spufs_ibox_fops = {
810 .open = spufs_pipe_open,
811 .read = spufs_ibox_read,
812 .poll = spufs_ibox_poll,
813 .fasync = spufs_ibox_fasync,
816 static ssize_t spufs_ibox_stat_read(struct file *file, char __user *buf,
817 size_t len, loff_t *pos)
819 struct spu_context *ctx = file->private_data;
820 ssize_t ret;
821 u32 ibox_stat;
823 if (len < 4)
824 return -EINVAL;
826 ret = spu_acquire(ctx);
827 if (ret)
828 return ret;
829 ibox_stat = (ctx->ops->mbox_stat_read(ctx) >> 16) & 0xff;
830 spu_release(ctx);
832 if (copy_to_user(buf, &ibox_stat, sizeof ibox_stat))
833 return -EFAULT;
835 return 4;
838 static const struct file_operations spufs_ibox_stat_fops = {
839 .open = spufs_pipe_open,
840 .read = spufs_ibox_stat_read,
843 /* low-level mailbox write */
844 size_t spu_wbox_write(struct spu_context *ctx, u32 data)
846 return ctx->ops->wbox_write(ctx, data);
849 static int spufs_wbox_fasync(int fd, struct file *file, int on)
851 struct spu_context *ctx = file->private_data;
852 int ret;
854 ret = fasync_helper(fd, file, on, &ctx->wbox_fasync);
856 return ret;
859 /* interrupt-level wbox callback function. */
860 void spufs_wbox_callback(struct spu *spu)
862 struct spu_context *ctx = spu->ctx;
864 if (!ctx)
865 return;
867 wake_up_all(&ctx->wbox_wq);
868 kill_fasync(&ctx->wbox_fasync, SIGIO, POLLOUT);
872 * Write as many bytes to the interrupt mailbox as possible, until
873 * one of the conditions becomes true:
875 * - the mailbox is full
876 * - end of the user provided buffer
877 * - end of the mapped area
879 * If the file is opened without O_NONBLOCK, we wait here until
880 * space is availabyl, but return when we have been able to
881 * write something.
883 static ssize_t spufs_wbox_write(struct file *file, const char __user *buf,
884 size_t len, loff_t *pos)
886 struct spu_context *ctx = file->private_data;
887 u32 wbox_data, __user *udata;
888 ssize_t count;
890 if (len < 4)
891 return -EINVAL;
893 udata = (void __user *)buf;
894 if (!access_ok(VERIFY_READ, buf, len))
895 return -EFAULT;
897 if (__get_user(wbox_data, udata))
898 return -EFAULT;
900 count = spu_acquire(ctx);
901 if (count)
902 return count;
905 * make sure we can at least write one element, by waiting
906 * in case of !O_NONBLOCK
908 count = 0;
909 if (file->f_flags & O_NONBLOCK) {
910 if (!spu_wbox_write(ctx, wbox_data))
911 count = -EAGAIN;
912 } else {
913 count = spufs_wait(ctx->wbox_wq, spu_wbox_write(ctx, wbox_data));
916 if (count)
917 goto out;
919 /* write as much as possible */
920 for (count = 4, udata++; (count + 4) <= len; count += 4, udata++) {
921 int ret;
922 ret = __get_user(wbox_data, udata);
923 if (ret)
924 break;
926 ret = spu_wbox_write(ctx, wbox_data);
927 if (ret == 0)
928 break;
931 out:
932 spu_release(ctx);
933 return count;
936 static unsigned int spufs_wbox_poll(struct file *file, poll_table *wait)
938 struct spu_context *ctx = file->private_data;
939 unsigned int mask;
941 poll_wait(file, &ctx->wbox_wq, wait);
944 * For now keep this uninterruptible and also ignore the rule
945 * that poll should not sleep. Will be fixed later.
947 mutex_lock(&ctx->state_mutex);
948 mask = ctx->ops->mbox_stat_poll(ctx, POLLOUT | POLLWRNORM);
949 spu_release(ctx);
951 return mask;
954 static const struct file_operations spufs_wbox_fops = {
955 .open = spufs_pipe_open,
956 .write = spufs_wbox_write,
957 .poll = spufs_wbox_poll,
958 .fasync = spufs_wbox_fasync,
961 static ssize_t spufs_wbox_stat_read(struct file *file, char __user *buf,
962 size_t len, loff_t *pos)
964 struct spu_context *ctx = file->private_data;
965 ssize_t ret;
966 u32 wbox_stat;
968 if (len < 4)
969 return -EINVAL;
971 ret = spu_acquire(ctx);
972 if (ret)
973 return ret;
974 wbox_stat = (ctx->ops->mbox_stat_read(ctx) >> 8) & 0xff;
975 spu_release(ctx);
977 if (copy_to_user(buf, &wbox_stat, sizeof wbox_stat))
978 return -EFAULT;
980 return 4;
983 static const struct file_operations spufs_wbox_stat_fops = {
984 .open = spufs_pipe_open,
985 .read = spufs_wbox_stat_read,
988 static int spufs_signal1_open(struct inode *inode, struct file *file)
990 struct spufs_inode_info *i = SPUFS_I(inode);
991 struct spu_context *ctx = i->i_ctx;
993 mutex_lock(&ctx->mapping_lock);
994 file->private_data = ctx;
995 if (!i->i_openers++)
996 ctx->signal1 = inode->i_mapping;
997 mutex_unlock(&ctx->mapping_lock);
998 return nonseekable_open(inode, file);
1001 static int
1002 spufs_signal1_release(struct inode *inode, struct file *file)
1004 struct spufs_inode_info *i = SPUFS_I(inode);
1005 struct spu_context *ctx = i->i_ctx;
1007 mutex_lock(&ctx->mapping_lock);
1008 if (!--i->i_openers)
1009 ctx->signal1 = NULL;
1010 mutex_unlock(&ctx->mapping_lock);
1011 return 0;
1014 static ssize_t __spufs_signal1_read(struct spu_context *ctx, char __user *buf,
1015 size_t len, loff_t *pos)
1017 int ret = 0;
1018 u32 data;
1020 if (len < 4)
1021 return -EINVAL;
1023 if (ctx->csa.spu_chnlcnt_RW[3]) {
1024 data = ctx->csa.spu_chnldata_RW[3];
1025 ret = 4;
1028 if (!ret)
1029 goto out;
1031 if (copy_to_user(buf, &data, 4))
1032 return -EFAULT;
1034 out:
1035 return ret;
1038 static ssize_t spufs_signal1_read(struct file *file, char __user *buf,
1039 size_t len, loff_t *pos)
1041 int ret;
1042 struct spu_context *ctx = file->private_data;
1044 ret = spu_acquire_saved(ctx);
1045 if (ret)
1046 return ret;
1047 ret = __spufs_signal1_read(ctx, buf, len, pos);
1048 spu_release_saved(ctx);
1050 return ret;
1053 static ssize_t spufs_signal1_write(struct file *file, const char __user *buf,
1054 size_t len, loff_t *pos)
1056 struct spu_context *ctx;
1057 ssize_t ret;
1058 u32 data;
1060 ctx = file->private_data;
1062 if (len < 4)
1063 return -EINVAL;
1065 if (copy_from_user(&data, buf, 4))
1066 return -EFAULT;
1068 ret = spu_acquire(ctx);
1069 if (ret)
1070 return ret;
1071 ctx->ops->signal1_write(ctx, data);
1072 spu_release(ctx);
1074 return 4;
1077 static unsigned long spufs_signal1_mmap_nopfn(struct vm_area_struct *vma,
1078 unsigned long address)
1080 #if PAGE_SIZE == 0x1000
1081 return spufs_ps_nopfn(vma, address, 0x14000, 0x1000);
1082 #elif PAGE_SIZE == 0x10000
1083 /* For 64k pages, both signal1 and signal2 can be used to mmap the whole
1084 * signal 1 and 2 area
1086 return spufs_ps_nopfn(vma, address, 0x10000, 0x10000);
1087 #else
1088 #error unsupported page size
1089 #endif
1092 static struct vm_operations_struct spufs_signal1_mmap_vmops = {
1093 .nopfn = spufs_signal1_mmap_nopfn,
1096 static int spufs_signal1_mmap(struct file *file, struct vm_area_struct *vma)
1098 if (!(vma->vm_flags & VM_SHARED))
1099 return -EINVAL;
1101 vma->vm_flags |= VM_IO | VM_PFNMAP;
1102 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
1103 | _PAGE_NO_CACHE | _PAGE_GUARDED);
1105 vma->vm_ops = &spufs_signal1_mmap_vmops;
1106 return 0;
1109 static const struct file_operations spufs_signal1_fops = {
1110 .open = spufs_signal1_open,
1111 .release = spufs_signal1_release,
1112 .read = spufs_signal1_read,
1113 .write = spufs_signal1_write,
1114 .mmap = spufs_signal1_mmap,
1117 static const struct file_operations spufs_signal1_nosched_fops = {
1118 .open = spufs_signal1_open,
1119 .release = spufs_signal1_release,
1120 .write = spufs_signal1_write,
1121 .mmap = spufs_signal1_mmap,
1124 static int spufs_signal2_open(struct inode *inode, struct file *file)
1126 struct spufs_inode_info *i = SPUFS_I(inode);
1127 struct spu_context *ctx = i->i_ctx;
1129 mutex_lock(&ctx->mapping_lock);
1130 file->private_data = ctx;
1131 if (!i->i_openers++)
1132 ctx->signal2 = inode->i_mapping;
1133 mutex_unlock(&ctx->mapping_lock);
1134 return nonseekable_open(inode, file);
1137 static int
1138 spufs_signal2_release(struct inode *inode, struct file *file)
1140 struct spufs_inode_info *i = SPUFS_I(inode);
1141 struct spu_context *ctx = i->i_ctx;
1143 mutex_lock(&ctx->mapping_lock);
1144 if (!--i->i_openers)
1145 ctx->signal2 = NULL;
1146 mutex_unlock(&ctx->mapping_lock);
1147 return 0;
1150 static ssize_t __spufs_signal2_read(struct spu_context *ctx, char __user *buf,
1151 size_t len, loff_t *pos)
1153 int ret = 0;
1154 u32 data;
1156 if (len < 4)
1157 return -EINVAL;
1159 if (ctx->csa.spu_chnlcnt_RW[4]) {
1160 data = ctx->csa.spu_chnldata_RW[4];
1161 ret = 4;
1164 if (!ret)
1165 goto out;
1167 if (copy_to_user(buf, &data, 4))
1168 return -EFAULT;
1170 out:
1171 return ret;
1174 static ssize_t spufs_signal2_read(struct file *file, char __user *buf,
1175 size_t len, loff_t *pos)
1177 struct spu_context *ctx = file->private_data;
1178 int ret;
1180 ret = spu_acquire_saved(ctx);
1181 if (ret)
1182 return ret;
1183 ret = __spufs_signal2_read(ctx, buf, len, pos);
1184 spu_release_saved(ctx);
1186 return ret;
1189 static ssize_t spufs_signal2_write(struct file *file, const char __user *buf,
1190 size_t len, loff_t *pos)
1192 struct spu_context *ctx;
1193 ssize_t ret;
1194 u32 data;
1196 ctx = file->private_data;
1198 if (len < 4)
1199 return -EINVAL;
1201 if (copy_from_user(&data, buf, 4))
1202 return -EFAULT;
1204 ret = spu_acquire(ctx);
1205 if (ret)
1206 return ret;
1207 ctx->ops->signal2_write(ctx, data);
1208 spu_release(ctx);
1210 return 4;
1213 #if SPUFS_MMAP_4K
1214 static unsigned long spufs_signal2_mmap_nopfn(struct vm_area_struct *vma,
1215 unsigned long address)
1217 #if PAGE_SIZE == 0x1000
1218 return spufs_ps_nopfn(vma, address, 0x1c000, 0x1000);
1219 #elif PAGE_SIZE == 0x10000
1220 /* For 64k pages, both signal1 and signal2 can be used to mmap the whole
1221 * signal 1 and 2 area
1223 return spufs_ps_nopfn(vma, address, 0x10000, 0x10000);
1224 #else
1225 #error unsupported page size
1226 #endif
1229 static struct vm_operations_struct spufs_signal2_mmap_vmops = {
1230 .nopfn = spufs_signal2_mmap_nopfn,
1233 static int spufs_signal2_mmap(struct file *file, struct vm_area_struct *vma)
1235 if (!(vma->vm_flags & VM_SHARED))
1236 return -EINVAL;
1238 vma->vm_flags |= VM_IO | VM_PFNMAP;
1239 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
1240 | _PAGE_NO_CACHE | _PAGE_GUARDED);
1242 vma->vm_ops = &spufs_signal2_mmap_vmops;
1243 return 0;
1245 #else /* SPUFS_MMAP_4K */
1246 #define spufs_signal2_mmap NULL
1247 #endif /* !SPUFS_MMAP_4K */
1249 static const struct file_operations spufs_signal2_fops = {
1250 .open = spufs_signal2_open,
1251 .release = spufs_signal2_release,
1252 .read = spufs_signal2_read,
1253 .write = spufs_signal2_write,
1254 .mmap = spufs_signal2_mmap,
1257 static const struct file_operations spufs_signal2_nosched_fops = {
1258 .open = spufs_signal2_open,
1259 .release = spufs_signal2_release,
1260 .write = spufs_signal2_write,
1261 .mmap = spufs_signal2_mmap,
1265 * This is a wrapper around DEFINE_SIMPLE_ATTRIBUTE which does the
1266 * work of acquiring (or not) the SPU context before calling through
1267 * to the actual get routine. The set routine is called directly.
1269 #define SPU_ATTR_NOACQUIRE 0
1270 #define SPU_ATTR_ACQUIRE 1
1271 #define SPU_ATTR_ACQUIRE_SAVED 2
1273 #define DEFINE_SPUFS_ATTRIBUTE(__name, __get, __set, __fmt, __acquire) \
1274 static int __##__get(void *data, u64 *val) \
1276 struct spu_context *ctx = data; \
1277 int ret = 0; \
1279 if (__acquire == SPU_ATTR_ACQUIRE) { \
1280 ret = spu_acquire(ctx); \
1281 if (ret) \
1282 return ret; \
1283 *val = __get(ctx); \
1284 spu_release(ctx); \
1285 } else if (__acquire == SPU_ATTR_ACQUIRE_SAVED) { \
1286 ret = spu_acquire_saved(ctx); \
1287 if (ret) \
1288 return ret; \
1289 *val = __get(ctx); \
1290 spu_release_saved(ctx); \
1291 } else \
1292 *val = __get(ctx); \
1294 return 0; \
1296 DEFINE_SPUFS_SIMPLE_ATTRIBUTE(__name, __##__get, __set, __fmt);
1298 static int spufs_signal1_type_set(void *data, u64 val)
1300 struct spu_context *ctx = data;
1301 int ret;
1303 ret = spu_acquire(ctx);
1304 if (ret)
1305 return ret;
1306 ctx->ops->signal1_type_set(ctx, val);
1307 spu_release(ctx);
1309 return 0;
1312 static u64 spufs_signal1_type_get(struct spu_context *ctx)
1314 return ctx->ops->signal1_type_get(ctx);
1316 DEFINE_SPUFS_ATTRIBUTE(spufs_signal1_type, spufs_signal1_type_get,
1317 spufs_signal1_type_set, "%llu", SPU_ATTR_ACQUIRE);
1320 static int spufs_signal2_type_set(void *data, u64 val)
1322 struct spu_context *ctx = data;
1323 int ret;
1325 ret = spu_acquire(ctx);
1326 if (ret)
1327 return ret;
1328 ctx->ops->signal2_type_set(ctx, val);
1329 spu_release(ctx);
1331 return 0;
1334 static u64 spufs_signal2_type_get(struct spu_context *ctx)
1336 return ctx->ops->signal2_type_get(ctx);
1338 DEFINE_SPUFS_ATTRIBUTE(spufs_signal2_type, spufs_signal2_type_get,
1339 spufs_signal2_type_set, "%llu", SPU_ATTR_ACQUIRE);
1341 #if SPUFS_MMAP_4K
1342 static unsigned long spufs_mss_mmap_nopfn(struct vm_area_struct *vma,
1343 unsigned long address)
1345 return spufs_ps_nopfn(vma, address, 0x0000, 0x1000);
1348 static struct vm_operations_struct spufs_mss_mmap_vmops = {
1349 .nopfn = spufs_mss_mmap_nopfn,
1353 * mmap support for problem state MFC DMA area [0x0000 - 0x0fff].
1355 static int spufs_mss_mmap(struct file *file, struct vm_area_struct *vma)
1357 if (!(vma->vm_flags & VM_SHARED))
1358 return -EINVAL;
1360 vma->vm_flags |= VM_IO | VM_PFNMAP;
1361 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
1362 | _PAGE_NO_CACHE | _PAGE_GUARDED);
1364 vma->vm_ops = &spufs_mss_mmap_vmops;
1365 return 0;
1367 #else /* SPUFS_MMAP_4K */
1368 #define spufs_mss_mmap NULL
1369 #endif /* !SPUFS_MMAP_4K */
1371 static int spufs_mss_open(struct inode *inode, struct file *file)
1373 struct spufs_inode_info *i = SPUFS_I(inode);
1374 struct spu_context *ctx = i->i_ctx;
1376 file->private_data = i->i_ctx;
1378 mutex_lock(&ctx->mapping_lock);
1379 if (!i->i_openers++)
1380 ctx->mss = inode->i_mapping;
1381 mutex_unlock(&ctx->mapping_lock);
1382 return nonseekable_open(inode, file);
1385 static int
1386 spufs_mss_release(struct inode *inode, struct file *file)
1388 struct spufs_inode_info *i = SPUFS_I(inode);
1389 struct spu_context *ctx = i->i_ctx;
1391 mutex_lock(&ctx->mapping_lock);
1392 if (!--i->i_openers)
1393 ctx->mss = NULL;
1394 mutex_unlock(&ctx->mapping_lock);
1395 return 0;
1398 static const struct file_operations spufs_mss_fops = {
1399 .open = spufs_mss_open,
1400 .release = spufs_mss_release,
1401 .mmap = spufs_mss_mmap,
1404 static unsigned long spufs_psmap_mmap_nopfn(struct vm_area_struct *vma,
1405 unsigned long address)
1407 return spufs_ps_nopfn(vma, address, 0x0000, 0x20000);
1410 static struct vm_operations_struct spufs_psmap_mmap_vmops = {
1411 .nopfn = spufs_psmap_mmap_nopfn,
1415 * mmap support for full problem state area [0x00000 - 0x1ffff].
1417 static int spufs_psmap_mmap(struct file *file, struct vm_area_struct *vma)
1419 if (!(vma->vm_flags & VM_SHARED))
1420 return -EINVAL;
1422 vma->vm_flags |= VM_IO | VM_PFNMAP;
1423 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
1424 | _PAGE_NO_CACHE | _PAGE_GUARDED);
1426 vma->vm_ops = &spufs_psmap_mmap_vmops;
1427 return 0;
1430 static int spufs_psmap_open(struct inode *inode, struct file *file)
1432 struct spufs_inode_info *i = SPUFS_I(inode);
1433 struct spu_context *ctx = i->i_ctx;
1435 mutex_lock(&ctx->mapping_lock);
1436 file->private_data = i->i_ctx;
1437 if (!i->i_openers++)
1438 ctx->psmap = inode->i_mapping;
1439 mutex_unlock(&ctx->mapping_lock);
1440 return nonseekable_open(inode, file);
1443 static int
1444 spufs_psmap_release(struct inode *inode, struct file *file)
1446 struct spufs_inode_info *i = SPUFS_I(inode);
1447 struct spu_context *ctx = i->i_ctx;
1449 mutex_lock(&ctx->mapping_lock);
1450 if (!--i->i_openers)
1451 ctx->psmap = NULL;
1452 mutex_unlock(&ctx->mapping_lock);
1453 return 0;
1456 static const struct file_operations spufs_psmap_fops = {
1457 .open = spufs_psmap_open,
1458 .release = spufs_psmap_release,
1459 .mmap = spufs_psmap_mmap,
1463 #if SPUFS_MMAP_4K
1464 static unsigned long spufs_mfc_mmap_nopfn(struct vm_area_struct *vma,
1465 unsigned long address)
1467 return spufs_ps_nopfn(vma, address, 0x3000, 0x1000);
1470 static struct vm_operations_struct spufs_mfc_mmap_vmops = {
1471 .nopfn = spufs_mfc_mmap_nopfn,
1475 * mmap support for problem state MFC DMA area [0x0000 - 0x0fff].
1477 static int spufs_mfc_mmap(struct file *file, struct vm_area_struct *vma)
1479 if (!(vma->vm_flags & VM_SHARED))
1480 return -EINVAL;
1482 vma->vm_flags |= VM_IO | VM_PFNMAP;
1483 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
1484 | _PAGE_NO_CACHE | _PAGE_GUARDED);
1486 vma->vm_ops = &spufs_mfc_mmap_vmops;
1487 return 0;
1489 #else /* SPUFS_MMAP_4K */
1490 #define spufs_mfc_mmap NULL
1491 #endif /* !SPUFS_MMAP_4K */
1493 static int spufs_mfc_open(struct inode *inode, struct file *file)
1495 struct spufs_inode_info *i = SPUFS_I(inode);
1496 struct spu_context *ctx = i->i_ctx;
1498 /* we don't want to deal with DMA into other processes */
1499 if (ctx->owner != current->mm)
1500 return -EINVAL;
1502 if (atomic_read(&inode->i_count) != 1)
1503 return -EBUSY;
1505 mutex_lock(&ctx->mapping_lock);
1506 file->private_data = ctx;
1507 if (!i->i_openers++)
1508 ctx->mfc = inode->i_mapping;
1509 mutex_unlock(&ctx->mapping_lock);
1510 return nonseekable_open(inode, file);
1513 static int
1514 spufs_mfc_release(struct inode *inode, struct file *file)
1516 struct spufs_inode_info *i = SPUFS_I(inode);
1517 struct spu_context *ctx = i->i_ctx;
1519 mutex_lock(&ctx->mapping_lock);
1520 if (!--i->i_openers)
1521 ctx->mfc = NULL;
1522 mutex_unlock(&ctx->mapping_lock);
1523 return 0;
1526 /* interrupt-level mfc callback function. */
1527 void spufs_mfc_callback(struct spu *spu)
1529 struct spu_context *ctx = spu->ctx;
1531 if (!ctx)
1532 return;
1534 wake_up_all(&ctx->mfc_wq);
1536 pr_debug("%s %s\n", __FUNCTION__, spu->name);
1537 if (ctx->mfc_fasync) {
1538 u32 free_elements, tagstatus;
1539 unsigned int mask;
1541 /* no need for spu_acquire in interrupt context */
1542 free_elements = ctx->ops->get_mfc_free_elements(ctx);
1543 tagstatus = ctx->ops->read_mfc_tagstatus(ctx);
1545 mask = 0;
1546 if (free_elements & 0xffff)
1547 mask |= POLLOUT;
1548 if (tagstatus & ctx->tagwait)
1549 mask |= POLLIN;
1551 kill_fasync(&ctx->mfc_fasync, SIGIO, mask);
1555 static int spufs_read_mfc_tagstatus(struct spu_context *ctx, u32 *status)
1557 /* See if there is one tag group is complete */
1558 /* FIXME we need locking around tagwait */
1559 *status = ctx->ops->read_mfc_tagstatus(ctx) & ctx->tagwait;
1560 ctx->tagwait &= ~*status;
1561 if (*status)
1562 return 1;
1564 /* enable interrupt waiting for any tag group,
1565 may silently fail if interrupts are already enabled */
1566 ctx->ops->set_mfc_query(ctx, ctx->tagwait, 1);
1567 return 0;
1570 static ssize_t spufs_mfc_read(struct file *file, char __user *buffer,
1571 size_t size, loff_t *pos)
1573 struct spu_context *ctx = file->private_data;
1574 int ret = -EINVAL;
1575 u32 status;
1577 if (size != 4)
1578 goto out;
1580 ret = spu_acquire(ctx);
1581 if (ret)
1582 return ret;
1584 ret = -EINVAL;
1585 if (file->f_flags & O_NONBLOCK) {
1586 status = ctx->ops->read_mfc_tagstatus(ctx);
1587 if (!(status & ctx->tagwait))
1588 ret = -EAGAIN;
1589 else
1590 /* XXX(hch): shouldn't we clear ret here? */
1591 ctx->tagwait &= ~status;
1592 } else {
1593 ret = spufs_wait(ctx->mfc_wq,
1594 spufs_read_mfc_tagstatus(ctx, &status));
1596 spu_release(ctx);
1598 if (ret)
1599 goto out;
1601 ret = 4;
1602 if (copy_to_user(buffer, &status, 4))
1603 ret = -EFAULT;
1605 out:
1606 return ret;
1609 static int spufs_check_valid_dma(struct mfc_dma_command *cmd)
1611 pr_debug("queueing DMA %x %lx %x %x %x\n", cmd->lsa,
1612 cmd->ea, cmd->size, cmd->tag, cmd->cmd);
1614 switch (cmd->cmd) {
1615 case MFC_PUT_CMD:
1616 case MFC_PUTF_CMD:
1617 case MFC_PUTB_CMD:
1618 case MFC_GET_CMD:
1619 case MFC_GETF_CMD:
1620 case MFC_GETB_CMD:
1621 break;
1622 default:
1623 pr_debug("invalid DMA opcode %x\n", cmd->cmd);
1624 return -EIO;
1627 if ((cmd->lsa & 0xf) != (cmd->ea &0xf)) {
1628 pr_debug("invalid DMA alignment, ea %lx lsa %x\n",
1629 cmd->ea, cmd->lsa);
1630 return -EIO;
1633 switch (cmd->size & 0xf) {
1634 case 1:
1635 break;
1636 case 2:
1637 if (cmd->lsa & 1)
1638 goto error;
1639 break;
1640 case 4:
1641 if (cmd->lsa & 3)
1642 goto error;
1643 break;
1644 case 8:
1645 if (cmd->lsa & 7)
1646 goto error;
1647 break;
1648 case 0:
1649 if (cmd->lsa & 15)
1650 goto error;
1651 break;
1652 error:
1653 default:
1654 pr_debug("invalid DMA alignment %x for size %x\n",
1655 cmd->lsa & 0xf, cmd->size);
1656 return -EIO;
1659 if (cmd->size > 16 * 1024) {
1660 pr_debug("invalid DMA size %x\n", cmd->size);
1661 return -EIO;
1664 if (cmd->tag & 0xfff0) {
1665 /* we reserve the higher tag numbers for kernel use */
1666 pr_debug("invalid DMA tag\n");
1667 return -EIO;
1670 if (cmd->class) {
1671 /* not supported in this version */
1672 pr_debug("invalid DMA class\n");
1673 return -EIO;
1676 return 0;
1679 static int spu_send_mfc_command(struct spu_context *ctx,
1680 struct mfc_dma_command cmd,
1681 int *error)
1683 *error = ctx->ops->send_mfc_command(ctx, &cmd);
1684 if (*error == -EAGAIN) {
1685 /* wait for any tag group to complete
1686 so we have space for the new command */
1687 ctx->ops->set_mfc_query(ctx, ctx->tagwait, 1);
1688 /* try again, because the queue might be
1689 empty again */
1690 *error = ctx->ops->send_mfc_command(ctx, &cmd);
1691 if (*error == -EAGAIN)
1692 return 0;
1694 return 1;
1697 static ssize_t spufs_mfc_write(struct file *file, const char __user *buffer,
1698 size_t size, loff_t *pos)
1700 struct spu_context *ctx = file->private_data;
1701 struct mfc_dma_command cmd;
1702 int ret = -EINVAL;
1704 if (size != sizeof cmd)
1705 goto out;
1707 ret = -EFAULT;
1708 if (copy_from_user(&cmd, buffer, sizeof cmd))
1709 goto out;
1711 ret = spufs_check_valid_dma(&cmd);
1712 if (ret)
1713 goto out;
1715 ret = spu_acquire(ctx);
1716 if (ret)
1717 goto out;
1719 ret = spufs_wait(ctx->run_wq, ctx->state == SPU_STATE_RUNNABLE);
1720 if (ret)
1721 goto out;
1723 if (file->f_flags & O_NONBLOCK) {
1724 ret = ctx->ops->send_mfc_command(ctx, &cmd);
1725 } else {
1726 int status;
1727 ret = spufs_wait(ctx->mfc_wq,
1728 spu_send_mfc_command(ctx, cmd, &status));
1729 if (status)
1730 ret = status;
1733 if (ret)
1734 goto out_unlock;
1736 ctx->tagwait |= 1 << cmd.tag;
1737 ret = size;
1739 out_unlock:
1740 spu_release(ctx);
1741 out:
1742 return ret;
1745 static unsigned int spufs_mfc_poll(struct file *file,poll_table *wait)
1747 struct spu_context *ctx = file->private_data;
1748 u32 free_elements, tagstatus;
1749 unsigned int mask;
1751 poll_wait(file, &ctx->mfc_wq, wait);
1754 * For now keep this uninterruptible and also ignore the rule
1755 * that poll should not sleep. Will be fixed later.
1757 mutex_lock(&ctx->state_mutex);
1758 ctx->ops->set_mfc_query(ctx, ctx->tagwait, 2);
1759 free_elements = ctx->ops->get_mfc_free_elements(ctx);
1760 tagstatus = ctx->ops->read_mfc_tagstatus(ctx);
1761 spu_release(ctx);
1763 mask = 0;
1764 if (free_elements & 0xffff)
1765 mask |= POLLOUT | POLLWRNORM;
1766 if (tagstatus & ctx->tagwait)
1767 mask |= POLLIN | POLLRDNORM;
1769 pr_debug("%s: free %d tagstatus %d tagwait %d\n", __FUNCTION__,
1770 free_elements, tagstatus, ctx->tagwait);
1772 return mask;
1775 static int spufs_mfc_flush(struct file *file, fl_owner_t id)
1777 struct spu_context *ctx = file->private_data;
1778 int ret;
1780 ret = spu_acquire(ctx);
1781 if (ret)
1782 return ret;
1783 #if 0
1784 /* this currently hangs */
1785 ret = spufs_wait(ctx->mfc_wq,
1786 ctx->ops->set_mfc_query(ctx, ctx->tagwait, 2));
1787 if (ret)
1788 goto out;
1789 ret = spufs_wait(ctx->mfc_wq,
1790 ctx->ops->read_mfc_tagstatus(ctx) == ctx->tagwait);
1791 out:
1792 #else
1793 ret = 0;
1794 #endif
1795 spu_release(ctx);
1797 return ret;
1800 static int spufs_mfc_fsync(struct file *file, struct dentry *dentry,
1801 int datasync)
1803 return spufs_mfc_flush(file, NULL);
1806 static int spufs_mfc_fasync(int fd, struct file *file, int on)
1808 struct spu_context *ctx = file->private_data;
1810 return fasync_helper(fd, file, on, &ctx->mfc_fasync);
1813 static const struct file_operations spufs_mfc_fops = {
1814 .open = spufs_mfc_open,
1815 .release = spufs_mfc_release,
1816 .read = spufs_mfc_read,
1817 .write = spufs_mfc_write,
1818 .poll = spufs_mfc_poll,
1819 .flush = spufs_mfc_flush,
1820 .fsync = spufs_mfc_fsync,
1821 .fasync = spufs_mfc_fasync,
1822 .mmap = spufs_mfc_mmap,
1825 static int spufs_npc_set(void *data, u64 val)
1827 struct spu_context *ctx = data;
1828 int ret;
1830 ret = spu_acquire(ctx);
1831 if (ret)
1832 return ret;
1833 ctx->ops->npc_write(ctx, val);
1834 spu_release(ctx);
1836 return 0;
1839 static u64 spufs_npc_get(struct spu_context *ctx)
1841 return ctx->ops->npc_read(ctx);
1843 DEFINE_SPUFS_ATTRIBUTE(spufs_npc_ops, spufs_npc_get, spufs_npc_set,
1844 "0x%llx\n", SPU_ATTR_ACQUIRE);
1846 static int spufs_decr_set(void *data, u64 val)
1848 struct spu_context *ctx = data;
1849 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1850 int ret;
1852 ret = spu_acquire_saved(ctx);
1853 if (ret)
1854 return ret;
1855 lscsa->decr.slot[0] = (u32) val;
1856 spu_release_saved(ctx);
1858 return 0;
1861 static u64 spufs_decr_get(struct spu_context *ctx)
1863 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1864 return lscsa->decr.slot[0];
1866 DEFINE_SPUFS_ATTRIBUTE(spufs_decr_ops, spufs_decr_get, spufs_decr_set,
1867 "0x%llx\n", SPU_ATTR_ACQUIRE_SAVED);
1869 static int spufs_decr_status_set(void *data, u64 val)
1871 struct spu_context *ctx = data;
1872 int ret;
1874 ret = spu_acquire_saved(ctx);
1875 if (ret)
1876 return ret;
1877 if (val)
1878 ctx->csa.priv2.mfc_control_RW |= MFC_CNTL_DECREMENTER_RUNNING;
1879 else
1880 ctx->csa.priv2.mfc_control_RW &= ~MFC_CNTL_DECREMENTER_RUNNING;
1881 spu_release_saved(ctx);
1883 return 0;
1886 static u64 spufs_decr_status_get(struct spu_context *ctx)
1888 if (ctx->csa.priv2.mfc_control_RW & MFC_CNTL_DECREMENTER_RUNNING)
1889 return SPU_DECR_STATUS_RUNNING;
1890 else
1891 return 0;
1893 DEFINE_SPUFS_ATTRIBUTE(spufs_decr_status_ops, spufs_decr_status_get,
1894 spufs_decr_status_set, "0x%llx\n",
1895 SPU_ATTR_ACQUIRE_SAVED);
1897 static int spufs_event_mask_set(void *data, u64 val)
1899 struct spu_context *ctx = data;
1900 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1901 int ret;
1903 ret = spu_acquire_saved(ctx);
1904 if (ret)
1905 return ret;
1906 lscsa->event_mask.slot[0] = (u32) val;
1907 spu_release_saved(ctx);
1909 return 0;
1912 static u64 spufs_event_mask_get(struct spu_context *ctx)
1914 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1915 return lscsa->event_mask.slot[0];
1918 DEFINE_SPUFS_ATTRIBUTE(spufs_event_mask_ops, spufs_event_mask_get,
1919 spufs_event_mask_set, "0x%llx\n",
1920 SPU_ATTR_ACQUIRE_SAVED);
1922 static u64 spufs_event_status_get(struct spu_context *ctx)
1924 struct spu_state *state = &ctx->csa;
1925 u64 stat;
1926 stat = state->spu_chnlcnt_RW[0];
1927 if (stat)
1928 return state->spu_chnldata_RW[0];
1929 return 0;
1931 DEFINE_SPUFS_ATTRIBUTE(spufs_event_status_ops, spufs_event_status_get,
1932 NULL, "0x%llx\n", SPU_ATTR_ACQUIRE_SAVED)
1934 static int spufs_srr0_set(void *data, u64 val)
1936 struct spu_context *ctx = data;
1937 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1938 int ret;
1940 ret = spu_acquire_saved(ctx);
1941 if (ret)
1942 return ret;
1943 lscsa->srr0.slot[0] = (u32) val;
1944 spu_release_saved(ctx);
1946 return 0;
1949 static u64 spufs_srr0_get(struct spu_context *ctx)
1951 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1952 return lscsa->srr0.slot[0];
1954 DEFINE_SPUFS_ATTRIBUTE(spufs_srr0_ops, spufs_srr0_get, spufs_srr0_set,
1955 "0x%llx\n", SPU_ATTR_ACQUIRE_SAVED)
1957 static u64 spufs_id_get(struct spu_context *ctx)
1959 u64 num;
1961 if (ctx->state == SPU_STATE_RUNNABLE)
1962 num = ctx->spu->number;
1963 else
1964 num = (unsigned int)-1;
1966 return num;
1968 DEFINE_SPUFS_ATTRIBUTE(spufs_id_ops, spufs_id_get, NULL, "0x%llx\n",
1969 SPU_ATTR_ACQUIRE)
1971 static u64 spufs_object_id_get(struct spu_context *ctx)
1973 /* FIXME: Should there really be no locking here? */
1974 return ctx->object_id;
1977 static int spufs_object_id_set(void *data, u64 id)
1979 struct spu_context *ctx = data;
1980 ctx->object_id = id;
1982 return 0;
1985 DEFINE_SPUFS_ATTRIBUTE(spufs_object_id_ops, spufs_object_id_get,
1986 spufs_object_id_set, "0x%llx\n", SPU_ATTR_NOACQUIRE);
1988 static u64 spufs_lslr_get(struct spu_context *ctx)
1990 return ctx->csa.priv2.spu_lslr_RW;
1992 DEFINE_SPUFS_ATTRIBUTE(spufs_lslr_ops, spufs_lslr_get, NULL, "0x%llx\n",
1993 SPU_ATTR_ACQUIRE_SAVED);
1995 static int spufs_info_open(struct inode *inode, struct file *file)
1997 struct spufs_inode_info *i = SPUFS_I(inode);
1998 struct spu_context *ctx = i->i_ctx;
1999 file->private_data = ctx;
2000 return 0;
2003 static int spufs_caps_show(struct seq_file *s, void *private)
2005 struct spu_context *ctx = s->private;
2007 if (!(ctx->flags & SPU_CREATE_NOSCHED))
2008 seq_puts(s, "sched\n");
2009 if (!(ctx->flags & SPU_CREATE_ISOLATE))
2010 seq_puts(s, "step\n");
2011 return 0;
2014 static int spufs_caps_open(struct inode *inode, struct file *file)
2016 return single_open(file, spufs_caps_show, SPUFS_I(inode)->i_ctx);
2019 static const struct file_operations spufs_caps_fops = {
2020 .open = spufs_caps_open,
2021 .read = seq_read,
2022 .llseek = seq_lseek,
2023 .release = single_release,
2026 static ssize_t __spufs_mbox_info_read(struct spu_context *ctx,
2027 char __user *buf, size_t len, loff_t *pos)
2029 u32 data;
2031 /* EOF if there's no entry in the mbox */
2032 if (!(ctx->csa.prob.mb_stat_R & 0x0000ff))
2033 return 0;
2035 data = ctx->csa.prob.pu_mb_R;
2037 return simple_read_from_buffer(buf, len, pos, &data, sizeof data);
2040 static ssize_t spufs_mbox_info_read(struct file *file, char __user *buf,
2041 size_t len, loff_t *pos)
2043 int ret;
2044 struct spu_context *ctx = file->private_data;
2046 if (!access_ok(VERIFY_WRITE, buf, len))
2047 return -EFAULT;
2049 ret = spu_acquire_saved(ctx);
2050 if (ret)
2051 return ret;
2052 spin_lock(&ctx->csa.register_lock);
2053 ret = __spufs_mbox_info_read(ctx, buf, len, pos);
2054 spin_unlock(&ctx->csa.register_lock);
2055 spu_release_saved(ctx);
2057 return ret;
2060 static const struct file_operations spufs_mbox_info_fops = {
2061 .open = spufs_info_open,
2062 .read = spufs_mbox_info_read,
2063 .llseek = generic_file_llseek,
2066 static ssize_t __spufs_ibox_info_read(struct spu_context *ctx,
2067 char __user *buf, size_t len, loff_t *pos)
2069 u32 data;
2071 /* EOF if there's no entry in the ibox */
2072 if (!(ctx->csa.prob.mb_stat_R & 0xff0000))
2073 return 0;
2075 data = ctx->csa.priv2.puint_mb_R;
2077 return simple_read_from_buffer(buf, len, pos, &data, sizeof data);
2080 static ssize_t spufs_ibox_info_read(struct file *file, char __user *buf,
2081 size_t len, loff_t *pos)
2083 struct spu_context *ctx = file->private_data;
2084 int ret;
2086 if (!access_ok(VERIFY_WRITE, buf, len))
2087 return -EFAULT;
2089 ret = spu_acquire_saved(ctx);
2090 if (ret)
2091 return ret;
2092 spin_lock(&ctx->csa.register_lock);
2093 ret = __spufs_ibox_info_read(ctx, buf, len, pos);
2094 spin_unlock(&ctx->csa.register_lock);
2095 spu_release_saved(ctx);
2097 return ret;
2100 static const struct file_operations spufs_ibox_info_fops = {
2101 .open = spufs_info_open,
2102 .read = spufs_ibox_info_read,
2103 .llseek = generic_file_llseek,
2106 static ssize_t __spufs_wbox_info_read(struct spu_context *ctx,
2107 char __user *buf, size_t len, loff_t *pos)
2109 int i, cnt;
2110 u32 data[4];
2111 u32 wbox_stat;
2113 wbox_stat = ctx->csa.prob.mb_stat_R;
2114 cnt = 4 - ((wbox_stat & 0x00ff00) >> 8);
2115 for (i = 0; i < cnt; i++) {
2116 data[i] = ctx->csa.spu_mailbox_data[i];
2119 return simple_read_from_buffer(buf, len, pos, &data,
2120 cnt * sizeof(u32));
2123 static ssize_t spufs_wbox_info_read(struct file *file, char __user *buf,
2124 size_t len, loff_t *pos)
2126 struct spu_context *ctx = file->private_data;
2127 int ret;
2129 if (!access_ok(VERIFY_WRITE, buf, len))
2130 return -EFAULT;
2132 ret = spu_acquire_saved(ctx);
2133 if (ret)
2134 return ret;
2135 spin_lock(&ctx->csa.register_lock);
2136 ret = __spufs_wbox_info_read(ctx, buf, len, pos);
2137 spin_unlock(&ctx->csa.register_lock);
2138 spu_release_saved(ctx);
2140 return ret;
2143 static const struct file_operations spufs_wbox_info_fops = {
2144 .open = spufs_info_open,
2145 .read = spufs_wbox_info_read,
2146 .llseek = generic_file_llseek,
2149 static ssize_t __spufs_dma_info_read(struct spu_context *ctx,
2150 char __user *buf, size_t len, loff_t *pos)
2152 struct spu_dma_info info;
2153 struct mfc_cq_sr *qp, *spuqp;
2154 int i;
2156 info.dma_info_type = ctx->csa.priv2.spu_tag_status_query_RW;
2157 info.dma_info_mask = ctx->csa.lscsa->tag_mask.slot[0];
2158 info.dma_info_status = ctx->csa.spu_chnldata_RW[24];
2159 info.dma_info_stall_and_notify = ctx->csa.spu_chnldata_RW[25];
2160 info.dma_info_atomic_command_status = ctx->csa.spu_chnldata_RW[27];
2161 for (i = 0; i < 16; i++) {
2162 qp = &info.dma_info_command_data[i];
2163 spuqp = &ctx->csa.priv2.spuq[i];
2165 qp->mfc_cq_data0_RW = spuqp->mfc_cq_data0_RW;
2166 qp->mfc_cq_data1_RW = spuqp->mfc_cq_data1_RW;
2167 qp->mfc_cq_data2_RW = spuqp->mfc_cq_data2_RW;
2168 qp->mfc_cq_data3_RW = spuqp->mfc_cq_data3_RW;
2171 return simple_read_from_buffer(buf, len, pos, &info,
2172 sizeof info);
2175 static ssize_t spufs_dma_info_read(struct file *file, char __user *buf,
2176 size_t len, loff_t *pos)
2178 struct spu_context *ctx = file->private_data;
2179 int ret;
2181 if (!access_ok(VERIFY_WRITE, buf, len))
2182 return -EFAULT;
2184 ret = spu_acquire_saved(ctx);
2185 if (ret)
2186 return ret;
2187 spin_lock(&ctx->csa.register_lock);
2188 ret = __spufs_dma_info_read(ctx, buf, len, pos);
2189 spin_unlock(&ctx->csa.register_lock);
2190 spu_release_saved(ctx);
2192 return ret;
2195 static const struct file_operations spufs_dma_info_fops = {
2196 .open = spufs_info_open,
2197 .read = spufs_dma_info_read,
2200 static ssize_t __spufs_proxydma_info_read(struct spu_context *ctx,
2201 char __user *buf, size_t len, loff_t *pos)
2203 struct spu_proxydma_info info;
2204 struct mfc_cq_sr *qp, *puqp;
2205 int ret = sizeof info;
2206 int i;
2208 if (len < ret)
2209 return -EINVAL;
2211 if (!access_ok(VERIFY_WRITE, buf, len))
2212 return -EFAULT;
2214 info.proxydma_info_type = ctx->csa.prob.dma_querytype_RW;
2215 info.proxydma_info_mask = ctx->csa.prob.dma_querymask_RW;
2216 info.proxydma_info_status = ctx->csa.prob.dma_tagstatus_R;
2217 for (i = 0; i < 8; i++) {
2218 qp = &info.proxydma_info_command_data[i];
2219 puqp = &ctx->csa.priv2.puq[i];
2221 qp->mfc_cq_data0_RW = puqp->mfc_cq_data0_RW;
2222 qp->mfc_cq_data1_RW = puqp->mfc_cq_data1_RW;
2223 qp->mfc_cq_data2_RW = puqp->mfc_cq_data2_RW;
2224 qp->mfc_cq_data3_RW = puqp->mfc_cq_data3_RW;
2227 return simple_read_from_buffer(buf, len, pos, &info,
2228 sizeof info);
2231 static ssize_t spufs_proxydma_info_read(struct file *file, char __user *buf,
2232 size_t len, loff_t *pos)
2234 struct spu_context *ctx = file->private_data;
2235 int ret;
2237 ret = spu_acquire_saved(ctx);
2238 if (ret)
2239 return ret;
2240 spin_lock(&ctx->csa.register_lock);
2241 ret = __spufs_proxydma_info_read(ctx, buf, len, pos);
2242 spin_unlock(&ctx->csa.register_lock);
2243 spu_release_saved(ctx);
2245 return ret;
2248 static const struct file_operations spufs_proxydma_info_fops = {
2249 .open = spufs_info_open,
2250 .read = spufs_proxydma_info_read,
2253 static int spufs_show_tid(struct seq_file *s, void *private)
2255 struct spu_context *ctx = s->private;
2257 seq_printf(s, "%d\n", ctx->tid);
2258 return 0;
2261 static int spufs_tid_open(struct inode *inode, struct file *file)
2263 return single_open(file, spufs_show_tid, SPUFS_I(inode)->i_ctx);
2266 static const struct file_operations spufs_tid_fops = {
2267 .open = spufs_tid_open,
2268 .read = seq_read,
2269 .llseek = seq_lseek,
2270 .release = single_release,
2273 static const char *ctx_state_names[] = {
2274 "user", "system", "iowait", "loaded"
2277 static unsigned long long spufs_acct_time(struct spu_context *ctx,
2278 enum spu_utilization_state state)
2280 struct timespec ts;
2281 unsigned long long time = ctx->stats.times[state];
2284 * In general, utilization statistics are updated by the controlling
2285 * thread as the spu context moves through various well defined
2286 * state transitions, but if the context is lazily loaded its
2287 * utilization statistics are not updated as the controlling thread
2288 * is not tightly coupled with the execution of the spu context. We
2289 * calculate and apply the time delta from the last recorded state
2290 * of the spu context.
2292 if (ctx->spu && ctx->stats.util_state == state) {
2293 ktime_get_ts(&ts);
2294 time += timespec_to_ns(&ts) - ctx->stats.tstamp;
2297 return time / NSEC_PER_MSEC;
2300 static unsigned long long spufs_slb_flts(struct spu_context *ctx)
2302 unsigned long long slb_flts = ctx->stats.slb_flt;
2304 if (ctx->state == SPU_STATE_RUNNABLE) {
2305 slb_flts += (ctx->spu->stats.slb_flt -
2306 ctx->stats.slb_flt_base);
2309 return slb_flts;
2312 static unsigned long long spufs_class2_intrs(struct spu_context *ctx)
2314 unsigned long long class2_intrs = ctx->stats.class2_intr;
2316 if (ctx->state == SPU_STATE_RUNNABLE) {
2317 class2_intrs += (ctx->spu->stats.class2_intr -
2318 ctx->stats.class2_intr_base);
2321 return class2_intrs;
2325 static int spufs_show_stat(struct seq_file *s, void *private)
2327 struct spu_context *ctx = s->private;
2328 int ret;
2330 ret = spu_acquire(ctx);
2331 if (ret)
2332 return ret;
2334 seq_printf(s, "%s %llu %llu %llu %llu "
2335 "%llu %llu %llu %llu %llu %llu %llu %llu\n",
2336 ctx_state_names[ctx->stats.util_state],
2337 spufs_acct_time(ctx, SPU_UTIL_USER),
2338 spufs_acct_time(ctx, SPU_UTIL_SYSTEM),
2339 spufs_acct_time(ctx, SPU_UTIL_IOWAIT),
2340 spufs_acct_time(ctx, SPU_UTIL_IDLE_LOADED),
2341 ctx->stats.vol_ctx_switch,
2342 ctx->stats.invol_ctx_switch,
2343 spufs_slb_flts(ctx),
2344 ctx->stats.hash_flt,
2345 ctx->stats.min_flt,
2346 ctx->stats.maj_flt,
2347 spufs_class2_intrs(ctx),
2348 ctx->stats.libassist);
2349 spu_release(ctx);
2350 return 0;
2353 static int spufs_stat_open(struct inode *inode, struct file *file)
2355 return single_open(file, spufs_show_stat, SPUFS_I(inode)->i_ctx);
2358 static const struct file_operations spufs_stat_fops = {
2359 .open = spufs_stat_open,
2360 .read = seq_read,
2361 .llseek = seq_lseek,
2362 .release = single_release,
2366 struct tree_descr spufs_dir_contents[] = {
2367 { "capabilities", &spufs_caps_fops, 0444, },
2368 { "mem", &spufs_mem_fops, 0666, },
2369 { "regs", &spufs_regs_fops, 0666, },
2370 { "mbox", &spufs_mbox_fops, 0444, },
2371 { "ibox", &spufs_ibox_fops, 0444, },
2372 { "wbox", &spufs_wbox_fops, 0222, },
2373 { "mbox_stat", &spufs_mbox_stat_fops, 0444, },
2374 { "ibox_stat", &spufs_ibox_stat_fops, 0444, },
2375 { "wbox_stat", &spufs_wbox_stat_fops, 0444, },
2376 { "signal1", &spufs_signal1_fops, 0666, },
2377 { "signal2", &spufs_signal2_fops, 0666, },
2378 { "signal1_type", &spufs_signal1_type, 0666, },
2379 { "signal2_type", &spufs_signal2_type, 0666, },
2380 { "cntl", &spufs_cntl_fops, 0666, },
2381 { "fpcr", &spufs_fpcr_fops, 0666, },
2382 { "lslr", &spufs_lslr_ops, 0444, },
2383 { "mfc", &spufs_mfc_fops, 0666, },
2384 { "mss", &spufs_mss_fops, 0666, },
2385 { "npc", &spufs_npc_ops, 0666, },
2386 { "srr0", &spufs_srr0_ops, 0666, },
2387 { "decr", &spufs_decr_ops, 0666, },
2388 { "decr_status", &spufs_decr_status_ops, 0666, },
2389 { "event_mask", &spufs_event_mask_ops, 0666, },
2390 { "event_status", &spufs_event_status_ops, 0444, },
2391 { "psmap", &spufs_psmap_fops, 0666, },
2392 { "phys-id", &spufs_id_ops, 0666, },
2393 { "object-id", &spufs_object_id_ops, 0666, },
2394 { "mbox_info", &spufs_mbox_info_fops, 0444, },
2395 { "ibox_info", &spufs_ibox_info_fops, 0444, },
2396 { "wbox_info", &spufs_wbox_info_fops, 0444, },
2397 { "dma_info", &spufs_dma_info_fops, 0444, },
2398 { "proxydma_info", &spufs_proxydma_info_fops, 0444, },
2399 { "tid", &spufs_tid_fops, 0444, },
2400 { "stat", &spufs_stat_fops, 0444, },
2404 struct tree_descr spufs_dir_nosched_contents[] = {
2405 { "capabilities", &spufs_caps_fops, 0444, },
2406 { "mem", &spufs_mem_fops, 0666, },
2407 { "mbox", &spufs_mbox_fops, 0444, },
2408 { "ibox", &spufs_ibox_fops, 0444, },
2409 { "wbox", &spufs_wbox_fops, 0222, },
2410 { "mbox_stat", &spufs_mbox_stat_fops, 0444, },
2411 { "ibox_stat", &spufs_ibox_stat_fops, 0444, },
2412 { "wbox_stat", &spufs_wbox_stat_fops, 0444, },
2413 { "signal1", &spufs_signal1_nosched_fops, 0222, },
2414 { "signal2", &spufs_signal2_nosched_fops, 0222, },
2415 { "signal1_type", &spufs_signal1_type, 0666, },
2416 { "signal2_type", &spufs_signal2_type, 0666, },
2417 { "mss", &spufs_mss_fops, 0666, },
2418 { "mfc", &spufs_mfc_fops, 0666, },
2419 { "cntl", &spufs_cntl_fops, 0666, },
2420 { "npc", &spufs_npc_ops, 0666, },
2421 { "psmap", &spufs_psmap_fops, 0666, },
2422 { "phys-id", &spufs_id_ops, 0666, },
2423 { "object-id", &spufs_object_id_ops, 0666, },
2424 { "tid", &spufs_tid_fops, 0444, },
2425 { "stat", &spufs_stat_fops, 0444, },
2429 struct spufs_coredump_reader spufs_coredump_read[] = {
2430 { "regs", __spufs_regs_read, NULL, sizeof(struct spu_reg128[128])},
2431 { "fpcr", __spufs_fpcr_read, NULL, sizeof(struct spu_reg128) },
2432 { "lslr", NULL, spufs_lslr_get, 19 },
2433 { "decr", NULL, spufs_decr_get, 19 },
2434 { "decr_status", NULL, spufs_decr_status_get, 19 },
2435 { "mem", __spufs_mem_read, NULL, LS_SIZE, },
2436 { "signal1", __spufs_signal1_read, NULL, sizeof(u32) },
2437 { "signal1_type", NULL, spufs_signal1_type_get, 19 },
2438 { "signal2", __spufs_signal2_read, NULL, sizeof(u32) },
2439 { "signal2_type", NULL, spufs_signal2_type_get, 19 },
2440 { "event_mask", NULL, spufs_event_mask_get, 19 },
2441 { "event_status", NULL, spufs_event_status_get, 19 },
2442 { "mbox_info", __spufs_mbox_info_read, NULL, sizeof(u32) },
2443 { "ibox_info", __spufs_ibox_info_read, NULL, sizeof(u32) },
2444 { "wbox_info", __spufs_wbox_info_read, NULL, 4 * sizeof(u32)},
2445 { "dma_info", __spufs_dma_info_read, NULL, sizeof(struct spu_dma_info)},
2446 { "proxydma_info", __spufs_proxydma_info_read,
2447 NULL, sizeof(struct spu_proxydma_info)},
2448 { "object-id", NULL, spufs_object_id_get, 19 },
2449 { "npc", NULL, spufs_npc_get, 19 },
2450 { NULL },