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)
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.
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>
37 #include <asm/spu_info.h>
38 #include <asm/uaccess.h>
42 #define SPUFS_MMAP_4K (PAGE_SIZE == 0x1000)
44 /* Simple attribute files */
46 int (*get)(void *, u64 *);
47 int (*set)(void *, u64);
48 char get_buf[24]; /* enough to store a u64 and "\n\0" */
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),
59 struct spufs_attr *attr;
61 attr = kmalloc(sizeof(*attr), GFP_KERNEL);
67 attr->data = inode->i_private;
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);
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;
88 attr = file->private_data;
92 ret = mutex_lock_interruptible(&attr->mutex);
96 if (*ppos) { /* continued read */
97 size = strlen(attr->get_buf);
98 } else { /* first read */
100 ret = attr->get(attr->data, &val);
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);
110 mutex_unlock(&attr->mutex);
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;
122 attr = file->private_data;
126 ret = mutex_lock_interruptible(&attr->mutex);
131 size = min(sizeof(attr->set_buf) - 1, len);
132 if (copy_from_user(attr->set_buf, buf, size))
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);
140 mutex_unlock(&attr->mutex);
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, \
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;
168 ctx->local_store = inode->i_mapping;
169 mutex_unlock(&ctx->mapping_lock);
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);
181 ctx->local_store = NULL;
182 mutex_unlock(&ctx->mapping_lock);
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,
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;
202 ret = spu_acquire(ctx);
205 ret = __spufs_mem_read(ctx, buffer, size, pos);
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;
224 if (size > LS_SIZE - pos)
225 size = LS_SIZE - pos;
227 ret = spu_acquire(ctx);
231 local_store = ctx->ops->get_ls(ctx);
232 ret = copy_from_user(local_store + pos, buffer, size);
242 spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
244 struct spu_context *ctx = vma->vm_file->private_data;
245 unsigned long address = (unsigned long)vmf->virtual_address;
246 unsigned long pfn, offset;
248 #ifdef CONFIG_SPU_FS_64K_LS
249 struct spu_state *csa = &ctx->csa;
252 /* Check what page size we are using */
253 psize = get_slice_psize(vma->vm_mm, address);
255 /* Some sanity checking */
256 BUG_ON(csa->use_big_pages != (psize == MMU_PAGE_64K));
258 /* Wow, 64K, cool, we need to align the address though */
259 if (csa->use_big_pages) {
260 BUG_ON(vma->vm_start & 0xffff);
261 address &= ~0xfffful;
263 #endif /* CONFIG_SPU_FS_64K_LS */
265 offset = vmf->pgoff << PAGE_SHIFT;
266 if (offset >= LS_SIZE)
267 return VM_FAULT_SIGBUS;
269 pr_debug("spufs_mem_mmap_fault address=0x%lx, offset=0x%lx\n",
272 if (spu_acquire(ctx))
273 return VM_FAULT_NOPAGE;
275 if (ctx->state == SPU_STATE_SAVED) {
276 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
278 pfn = vmalloc_to_pfn(ctx->csa.lscsa->ls + offset);
280 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
282 pfn = (ctx->spu->local_store_phys + offset) >> PAGE_SHIFT;
284 vm_insert_pfn(vma, address, pfn);
288 return VM_FAULT_NOPAGE;
291 static int spufs_mem_mmap_access(struct vm_area_struct *vma,
292 unsigned long address,
293 void *buf, int len, int write)
295 struct spu_context *ctx = vma->vm_file->private_data;
296 unsigned long offset = address - vma->vm_start;
299 if (write && !(vma->vm_flags & VM_WRITE))
301 if (spu_acquire(ctx))
303 if ((offset + len) > vma->vm_end)
304 len = vma->vm_end - offset;
305 local_store = ctx->ops->get_ls(ctx);
307 memcpy_toio(local_store + offset, buf, len);
309 memcpy_fromio(buf, local_store + offset, len);
314 static struct vm_operations_struct spufs_mem_mmap_vmops = {
315 .fault = spufs_mem_mmap_fault,
316 .access = spufs_mem_mmap_access,
319 static int spufs_mem_mmap(struct file *file, struct vm_area_struct *vma)
321 #ifdef CONFIG_SPU_FS_64K_LS
322 struct spu_context *ctx = file->private_data;
323 struct spu_state *csa = &ctx->csa;
325 /* Sanity check VMA alignment */
326 if (csa->use_big_pages) {
327 pr_debug("spufs_mem_mmap 64K, start=0x%lx, end=0x%lx,"
328 " pgoff=0x%lx\n", vma->vm_start, vma->vm_end,
330 if (vma->vm_start & 0xffff)
332 if (vma->vm_pgoff & 0xf)
335 #endif /* CONFIG_SPU_FS_64K_LS */
337 if (!(vma->vm_flags & VM_SHARED))
340 vma->vm_flags |= VM_IO | VM_PFNMAP;
341 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
344 vma->vm_ops = &spufs_mem_mmap_vmops;
348 #ifdef CONFIG_SPU_FS_64K_LS
349 static unsigned long spufs_get_unmapped_area(struct file *file,
350 unsigned long addr, unsigned long len, unsigned long pgoff,
353 struct spu_context *ctx = file->private_data;
354 struct spu_state *csa = &ctx->csa;
356 /* If not using big pages, fallback to normal MM g_u_a */
357 if (!csa->use_big_pages)
358 return current->mm->get_unmapped_area(file, addr, len,
361 /* Else, try to obtain a 64K pages slice */
362 return slice_get_unmapped_area(addr, len, flags,
365 #endif /* CONFIG_SPU_FS_64K_LS */
367 static const struct file_operations spufs_mem_fops = {
368 .open = spufs_mem_open,
369 .release = spufs_mem_release,
370 .read = spufs_mem_read,
371 .write = spufs_mem_write,
372 .llseek = generic_file_llseek,
373 .mmap = spufs_mem_mmap,
374 #ifdef CONFIG_SPU_FS_64K_LS
375 .get_unmapped_area = spufs_get_unmapped_area,
379 static int spufs_ps_fault(struct vm_area_struct *vma,
380 struct vm_fault *vmf,
381 unsigned long ps_offs,
382 unsigned long ps_size)
384 struct spu_context *ctx = vma->vm_file->private_data;
385 unsigned long area, offset = vmf->pgoff << PAGE_SHIFT;
388 spu_context_nospu_trace(spufs_ps_fault__enter, ctx);
390 if (offset >= ps_size)
391 return VM_FAULT_SIGBUS;
394 * Because we release the mmap_sem, the context may be destroyed while
395 * we're in spu_wait. Grab an extra reference so it isn't destroyed
398 get_spu_context(ctx);
401 * We have to wait for context to be loaded before we have
402 * pages to hand out to the user, but we don't want to wait
403 * with the mmap_sem held.
404 * It is possible to drop the mmap_sem here, but then we need
405 * to return VM_FAULT_NOPAGE because the mappings may have
408 if (spu_acquire(ctx))
411 if (ctx->state == SPU_STATE_SAVED) {
412 up_read(¤t->mm->mmap_sem);
413 spu_context_nospu_trace(spufs_ps_fault__sleep, ctx);
414 ret = spufs_wait(ctx->run_wq, ctx->state == SPU_STATE_RUNNABLE);
415 spu_context_trace(spufs_ps_fault__wake, ctx, ctx->spu);
416 down_read(¤t->mm->mmap_sem);
418 area = ctx->spu->problem_phys + ps_offs;
419 vm_insert_pfn(vma, (unsigned long)vmf->virtual_address,
420 (area + offset) >> PAGE_SHIFT);
421 spu_context_trace(spufs_ps_fault__insert, ctx, ctx->spu);
428 put_spu_context(ctx);
429 return VM_FAULT_NOPAGE;
433 static int spufs_cntl_mmap_fault(struct vm_area_struct *vma,
434 struct vm_fault *vmf)
436 return spufs_ps_fault(vma, vmf, 0x4000, SPUFS_CNTL_MAP_SIZE);
439 static struct vm_operations_struct spufs_cntl_mmap_vmops = {
440 .fault = spufs_cntl_mmap_fault,
444 * mmap support for problem state control area [0x4000 - 0x4fff].
446 static int spufs_cntl_mmap(struct file *file, struct vm_area_struct *vma)
448 if (!(vma->vm_flags & VM_SHARED))
451 vma->vm_flags |= VM_IO | VM_PFNMAP;
452 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
453 | _PAGE_NO_CACHE | _PAGE_GUARDED);
455 vma->vm_ops = &spufs_cntl_mmap_vmops;
458 #else /* SPUFS_MMAP_4K */
459 #define spufs_cntl_mmap NULL
460 #endif /* !SPUFS_MMAP_4K */
462 static int spufs_cntl_get(void *data, u64 *val)
464 struct spu_context *ctx = data;
467 ret = spu_acquire(ctx);
470 *val = ctx->ops->status_read(ctx);
476 static int spufs_cntl_set(void *data, u64 val)
478 struct spu_context *ctx = data;
481 ret = spu_acquire(ctx);
484 ctx->ops->runcntl_write(ctx, val);
490 static int spufs_cntl_open(struct inode *inode, struct file *file)
492 struct spufs_inode_info *i = SPUFS_I(inode);
493 struct spu_context *ctx = i->i_ctx;
495 mutex_lock(&ctx->mapping_lock);
496 file->private_data = ctx;
498 ctx->cntl = inode->i_mapping;
499 mutex_unlock(&ctx->mapping_lock);
500 return simple_attr_open(inode, file, spufs_cntl_get,
501 spufs_cntl_set, "0x%08lx");
505 spufs_cntl_release(struct inode *inode, struct file *file)
507 struct spufs_inode_info *i = SPUFS_I(inode);
508 struct spu_context *ctx = i->i_ctx;
510 simple_attr_release(inode, file);
512 mutex_lock(&ctx->mapping_lock);
515 mutex_unlock(&ctx->mapping_lock);
519 static const struct file_operations spufs_cntl_fops = {
520 .open = spufs_cntl_open,
521 .release = spufs_cntl_release,
522 .read = simple_attr_read,
523 .write = simple_attr_write,
524 .mmap = spufs_cntl_mmap,
528 spufs_regs_open(struct inode *inode, struct file *file)
530 struct spufs_inode_info *i = SPUFS_I(inode);
531 file->private_data = i->i_ctx;
536 __spufs_regs_read(struct spu_context *ctx, char __user *buffer,
537 size_t size, loff_t *pos)
539 struct spu_lscsa *lscsa = ctx->csa.lscsa;
540 return simple_read_from_buffer(buffer, size, pos,
541 lscsa->gprs, sizeof lscsa->gprs);
545 spufs_regs_read(struct file *file, char __user *buffer,
546 size_t size, loff_t *pos)
549 struct spu_context *ctx = file->private_data;
551 ret = spu_acquire_saved(ctx);
554 ret = __spufs_regs_read(ctx, buffer, size, pos);
555 spu_release_saved(ctx);
560 spufs_regs_write(struct file *file, const char __user *buffer,
561 size_t size, loff_t *pos)
563 struct spu_context *ctx = file->private_data;
564 struct spu_lscsa *lscsa = ctx->csa.lscsa;
567 size = min_t(ssize_t, sizeof lscsa->gprs - *pos, size);
572 ret = spu_acquire_saved(ctx);
576 ret = copy_from_user(lscsa->gprs + *pos - size,
577 buffer, size) ? -EFAULT : size;
579 spu_release_saved(ctx);
583 static const struct file_operations spufs_regs_fops = {
584 .open = spufs_regs_open,
585 .read = spufs_regs_read,
586 .write = spufs_regs_write,
587 .llseek = generic_file_llseek,
591 __spufs_fpcr_read(struct spu_context *ctx, char __user * buffer,
592 size_t size, loff_t * pos)
594 struct spu_lscsa *lscsa = ctx->csa.lscsa;
595 return simple_read_from_buffer(buffer, size, pos,
596 &lscsa->fpcr, sizeof(lscsa->fpcr));
600 spufs_fpcr_read(struct file *file, char __user * buffer,
601 size_t size, loff_t * pos)
604 struct spu_context *ctx = file->private_data;
606 ret = spu_acquire_saved(ctx);
609 ret = __spufs_fpcr_read(ctx, buffer, size, pos);
610 spu_release_saved(ctx);
615 spufs_fpcr_write(struct file *file, const char __user * buffer,
616 size_t size, loff_t * pos)
618 struct spu_context *ctx = file->private_data;
619 struct spu_lscsa *lscsa = ctx->csa.lscsa;
622 size = min_t(ssize_t, sizeof(lscsa->fpcr) - *pos, size);
626 ret = spu_acquire_saved(ctx);
631 ret = copy_from_user((char *)&lscsa->fpcr + *pos - size,
632 buffer, size) ? -EFAULT : size;
634 spu_release_saved(ctx);
638 static const struct file_operations spufs_fpcr_fops = {
639 .open = spufs_regs_open,
640 .read = spufs_fpcr_read,
641 .write = spufs_fpcr_write,
642 .llseek = generic_file_llseek,
645 /* generic open function for all pipe-like files */
646 static int spufs_pipe_open(struct inode *inode, struct file *file)
648 struct spufs_inode_info *i = SPUFS_I(inode);
649 file->private_data = i->i_ctx;
651 return nonseekable_open(inode, file);
655 * Read as many bytes from the mailbox as possible, until
656 * one of the conditions becomes true:
658 * - no more data available in the mailbox
659 * - end of the user provided buffer
660 * - end of the mapped area
662 static ssize_t spufs_mbox_read(struct file *file, char __user *buf,
663 size_t len, loff_t *pos)
665 struct spu_context *ctx = file->private_data;
666 u32 mbox_data, __user *udata;
672 if (!access_ok(VERIFY_WRITE, buf, len))
675 udata = (void __user *)buf;
677 count = spu_acquire(ctx);
681 for (count = 0; (count + 4) <= len; count += 4, udata++) {
683 ret = ctx->ops->mbox_read(ctx, &mbox_data);
688 * at the end of the mapped area, we can fault
689 * but still need to return the data we have
690 * read successfully so far.
692 ret = __put_user(mbox_data, udata);
707 static const struct file_operations spufs_mbox_fops = {
708 .open = spufs_pipe_open,
709 .read = spufs_mbox_read,
712 static ssize_t spufs_mbox_stat_read(struct file *file, char __user *buf,
713 size_t len, loff_t *pos)
715 struct spu_context *ctx = file->private_data;
722 ret = spu_acquire(ctx);
726 mbox_stat = ctx->ops->mbox_stat_read(ctx) & 0xff;
730 if (copy_to_user(buf, &mbox_stat, sizeof mbox_stat))
736 static const struct file_operations spufs_mbox_stat_fops = {
737 .open = spufs_pipe_open,
738 .read = spufs_mbox_stat_read,
741 /* low-level ibox access function */
742 size_t spu_ibox_read(struct spu_context *ctx, u32 *data)
744 return ctx->ops->ibox_read(ctx, data);
747 static int spufs_ibox_fasync(int fd, struct file *file, int on)
749 struct spu_context *ctx = file->private_data;
751 return fasync_helper(fd, file, on, &ctx->ibox_fasync);
754 /* interrupt-level ibox callback function. */
755 void spufs_ibox_callback(struct spu *spu)
757 struct spu_context *ctx = spu->ctx;
762 wake_up_all(&ctx->ibox_wq);
763 kill_fasync(&ctx->ibox_fasync, SIGIO, POLLIN);
767 * Read as many bytes from the interrupt mailbox as possible, until
768 * one of the conditions becomes true:
770 * - no more data available in the mailbox
771 * - end of the user provided buffer
772 * - end of the mapped area
774 * If the file is opened without O_NONBLOCK, we wait here until
775 * any data is available, but return when we have been able to
778 static ssize_t spufs_ibox_read(struct file *file, char __user *buf,
779 size_t len, loff_t *pos)
781 struct spu_context *ctx = file->private_data;
782 u32 ibox_data, __user *udata;
788 if (!access_ok(VERIFY_WRITE, buf, len))
791 udata = (void __user *)buf;
793 count = spu_acquire(ctx);
797 /* wait only for the first element */
799 if (file->f_flags & O_NONBLOCK) {
800 if (!spu_ibox_read(ctx, &ibox_data)) {
805 count = spufs_wait(ctx->ibox_wq, spu_ibox_read(ctx, &ibox_data));
810 /* if we can't write at all, return -EFAULT */
811 count = __put_user(ibox_data, udata);
815 for (count = 4, udata++; (count + 4) <= len; count += 4, udata++) {
817 ret = ctx->ops->ibox_read(ctx, &ibox_data);
821 * at the end of the mapped area, we can fault
822 * but still need to return the data we have
823 * read successfully so far.
825 ret = __put_user(ibox_data, udata);
836 static unsigned int spufs_ibox_poll(struct file *file, poll_table *wait)
838 struct spu_context *ctx = file->private_data;
841 poll_wait(file, &ctx->ibox_wq, wait);
844 * For now keep this uninterruptible and also ignore the rule
845 * that poll should not sleep. Will be fixed later.
847 mutex_lock(&ctx->state_mutex);
848 mask = ctx->ops->mbox_stat_poll(ctx, POLLIN | POLLRDNORM);
854 static const struct file_operations spufs_ibox_fops = {
855 .open = spufs_pipe_open,
856 .read = spufs_ibox_read,
857 .poll = spufs_ibox_poll,
858 .fasync = spufs_ibox_fasync,
861 static ssize_t spufs_ibox_stat_read(struct file *file, char __user *buf,
862 size_t len, loff_t *pos)
864 struct spu_context *ctx = file->private_data;
871 ret = spu_acquire(ctx);
874 ibox_stat = (ctx->ops->mbox_stat_read(ctx) >> 16) & 0xff;
877 if (copy_to_user(buf, &ibox_stat, sizeof ibox_stat))
883 static const struct file_operations spufs_ibox_stat_fops = {
884 .open = spufs_pipe_open,
885 .read = spufs_ibox_stat_read,
888 /* low-level mailbox write */
889 size_t spu_wbox_write(struct spu_context *ctx, u32 data)
891 return ctx->ops->wbox_write(ctx, data);
894 static int spufs_wbox_fasync(int fd, struct file *file, int on)
896 struct spu_context *ctx = file->private_data;
899 ret = fasync_helper(fd, file, on, &ctx->wbox_fasync);
904 /* interrupt-level wbox callback function. */
905 void spufs_wbox_callback(struct spu *spu)
907 struct spu_context *ctx = spu->ctx;
912 wake_up_all(&ctx->wbox_wq);
913 kill_fasync(&ctx->wbox_fasync, SIGIO, POLLOUT);
917 * Write as many bytes to the interrupt mailbox as possible, until
918 * one of the conditions becomes true:
920 * - the mailbox is full
921 * - end of the user provided buffer
922 * - end of the mapped area
924 * If the file is opened without O_NONBLOCK, we wait here until
925 * space is availabyl, but return when we have been able to
928 static ssize_t spufs_wbox_write(struct file *file, const char __user *buf,
929 size_t len, loff_t *pos)
931 struct spu_context *ctx = file->private_data;
932 u32 wbox_data, __user *udata;
938 udata = (void __user *)buf;
939 if (!access_ok(VERIFY_READ, buf, len))
942 if (__get_user(wbox_data, udata))
945 count = spu_acquire(ctx);
950 * make sure we can at least write one element, by waiting
951 * in case of !O_NONBLOCK
954 if (file->f_flags & O_NONBLOCK) {
955 if (!spu_wbox_write(ctx, wbox_data)) {
960 count = spufs_wait(ctx->wbox_wq, spu_wbox_write(ctx, wbox_data));
966 /* write as much as possible */
967 for (count = 4, udata++; (count + 4) <= len; count += 4, udata++) {
969 ret = __get_user(wbox_data, udata);
973 ret = spu_wbox_write(ctx, wbox_data);
984 static unsigned int spufs_wbox_poll(struct file *file, poll_table *wait)
986 struct spu_context *ctx = file->private_data;
989 poll_wait(file, &ctx->wbox_wq, wait);
992 * For now keep this uninterruptible and also ignore the rule
993 * that poll should not sleep. Will be fixed later.
995 mutex_lock(&ctx->state_mutex);
996 mask = ctx->ops->mbox_stat_poll(ctx, POLLOUT | POLLWRNORM);
1002 static const struct file_operations spufs_wbox_fops = {
1003 .open = spufs_pipe_open,
1004 .write = spufs_wbox_write,
1005 .poll = spufs_wbox_poll,
1006 .fasync = spufs_wbox_fasync,
1009 static ssize_t spufs_wbox_stat_read(struct file *file, char __user *buf,
1010 size_t len, loff_t *pos)
1012 struct spu_context *ctx = file->private_data;
1019 ret = spu_acquire(ctx);
1022 wbox_stat = (ctx->ops->mbox_stat_read(ctx) >> 8) & 0xff;
1025 if (copy_to_user(buf, &wbox_stat, sizeof wbox_stat))
1031 static const struct file_operations spufs_wbox_stat_fops = {
1032 .open = spufs_pipe_open,
1033 .read = spufs_wbox_stat_read,
1036 static int spufs_signal1_open(struct inode *inode, struct file *file)
1038 struct spufs_inode_info *i = SPUFS_I(inode);
1039 struct spu_context *ctx = i->i_ctx;
1041 mutex_lock(&ctx->mapping_lock);
1042 file->private_data = ctx;
1043 if (!i->i_openers++)
1044 ctx->signal1 = inode->i_mapping;
1045 mutex_unlock(&ctx->mapping_lock);
1046 return nonseekable_open(inode, file);
1050 spufs_signal1_release(struct inode *inode, struct file *file)
1052 struct spufs_inode_info *i = SPUFS_I(inode);
1053 struct spu_context *ctx = i->i_ctx;
1055 mutex_lock(&ctx->mapping_lock);
1056 if (!--i->i_openers)
1057 ctx->signal1 = NULL;
1058 mutex_unlock(&ctx->mapping_lock);
1062 static ssize_t __spufs_signal1_read(struct spu_context *ctx, char __user *buf,
1063 size_t len, loff_t *pos)
1071 if (ctx->csa.spu_chnlcnt_RW[3]) {
1072 data = ctx->csa.spu_chnldata_RW[3];
1079 if (copy_to_user(buf, &data, 4))
1086 static ssize_t spufs_signal1_read(struct file *file, char __user *buf,
1087 size_t len, loff_t *pos)
1090 struct spu_context *ctx = file->private_data;
1092 ret = spu_acquire_saved(ctx);
1095 ret = __spufs_signal1_read(ctx, buf, len, pos);
1096 spu_release_saved(ctx);
1101 static ssize_t spufs_signal1_write(struct file *file, const char __user *buf,
1102 size_t len, loff_t *pos)
1104 struct spu_context *ctx;
1108 ctx = file->private_data;
1113 if (copy_from_user(&data, buf, 4))
1116 ret = spu_acquire(ctx);
1119 ctx->ops->signal1_write(ctx, data);
1126 spufs_signal1_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
1128 #if SPUFS_SIGNAL_MAP_SIZE == 0x1000
1129 return spufs_ps_fault(vma, vmf, 0x14000, SPUFS_SIGNAL_MAP_SIZE);
1130 #elif SPUFS_SIGNAL_MAP_SIZE == 0x10000
1131 /* For 64k pages, both signal1 and signal2 can be used to mmap the whole
1132 * signal 1 and 2 area
1134 return spufs_ps_fault(vma, vmf, 0x10000, SPUFS_SIGNAL_MAP_SIZE);
1136 #error unsupported page size
1140 static struct vm_operations_struct spufs_signal1_mmap_vmops = {
1141 .fault = spufs_signal1_mmap_fault,
1144 static int spufs_signal1_mmap(struct file *file, struct vm_area_struct *vma)
1146 if (!(vma->vm_flags & VM_SHARED))
1149 vma->vm_flags |= VM_IO | VM_PFNMAP;
1150 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
1151 | _PAGE_NO_CACHE | _PAGE_GUARDED);
1153 vma->vm_ops = &spufs_signal1_mmap_vmops;
1157 static const struct file_operations spufs_signal1_fops = {
1158 .open = spufs_signal1_open,
1159 .release = spufs_signal1_release,
1160 .read = spufs_signal1_read,
1161 .write = spufs_signal1_write,
1162 .mmap = spufs_signal1_mmap,
1165 static const struct file_operations spufs_signal1_nosched_fops = {
1166 .open = spufs_signal1_open,
1167 .release = spufs_signal1_release,
1168 .write = spufs_signal1_write,
1169 .mmap = spufs_signal1_mmap,
1172 static int spufs_signal2_open(struct inode *inode, struct file *file)
1174 struct spufs_inode_info *i = SPUFS_I(inode);
1175 struct spu_context *ctx = i->i_ctx;
1177 mutex_lock(&ctx->mapping_lock);
1178 file->private_data = ctx;
1179 if (!i->i_openers++)
1180 ctx->signal2 = inode->i_mapping;
1181 mutex_unlock(&ctx->mapping_lock);
1182 return nonseekable_open(inode, file);
1186 spufs_signal2_release(struct inode *inode, struct file *file)
1188 struct spufs_inode_info *i = SPUFS_I(inode);
1189 struct spu_context *ctx = i->i_ctx;
1191 mutex_lock(&ctx->mapping_lock);
1192 if (!--i->i_openers)
1193 ctx->signal2 = NULL;
1194 mutex_unlock(&ctx->mapping_lock);
1198 static ssize_t __spufs_signal2_read(struct spu_context *ctx, char __user *buf,
1199 size_t len, loff_t *pos)
1207 if (ctx->csa.spu_chnlcnt_RW[4]) {
1208 data = ctx->csa.spu_chnldata_RW[4];
1215 if (copy_to_user(buf, &data, 4))
1222 static ssize_t spufs_signal2_read(struct file *file, char __user *buf,
1223 size_t len, loff_t *pos)
1225 struct spu_context *ctx = file->private_data;
1228 ret = spu_acquire_saved(ctx);
1231 ret = __spufs_signal2_read(ctx, buf, len, pos);
1232 spu_release_saved(ctx);
1237 static ssize_t spufs_signal2_write(struct file *file, const char __user *buf,
1238 size_t len, loff_t *pos)
1240 struct spu_context *ctx;
1244 ctx = file->private_data;
1249 if (copy_from_user(&data, buf, 4))
1252 ret = spu_acquire(ctx);
1255 ctx->ops->signal2_write(ctx, data);
1263 spufs_signal2_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
1265 #if SPUFS_SIGNAL_MAP_SIZE == 0x1000
1266 return spufs_ps_fault(vma, vmf, 0x1c000, SPUFS_SIGNAL_MAP_SIZE);
1267 #elif SPUFS_SIGNAL_MAP_SIZE == 0x10000
1268 /* For 64k pages, both signal1 and signal2 can be used to mmap the whole
1269 * signal 1 and 2 area
1271 return spufs_ps_fault(vma, vmf, 0x10000, SPUFS_SIGNAL_MAP_SIZE);
1273 #error unsupported page size
1277 static struct vm_operations_struct spufs_signal2_mmap_vmops = {
1278 .fault = spufs_signal2_mmap_fault,
1281 static int spufs_signal2_mmap(struct file *file, struct vm_area_struct *vma)
1283 if (!(vma->vm_flags & VM_SHARED))
1286 vma->vm_flags |= VM_IO | VM_PFNMAP;
1287 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
1288 | _PAGE_NO_CACHE | _PAGE_GUARDED);
1290 vma->vm_ops = &spufs_signal2_mmap_vmops;
1293 #else /* SPUFS_MMAP_4K */
1294 #define spufs_signal2_mmap NULL
1295 #endif /* !SPUFS_MMAP_4K */
1297 static const struct file_operations spufs_signal2_fops = {
1298 .open = spufs_signal2_open,
1299 .release = spufs_signal2_release,
1300 .read = spufs_signal2_read,
1301 .write = spufs_signal2_write,
1302 .mmap = spufs_signal2_mmap,
1305 static const struct file_operations spufs_signal2_nosched_fops = {
1306 .open = spufs_signal2_open,
1307 .release = spufs_signal2_release,
1308 .write = spufs_signal2_write,
1309 .mmap = spufs_signal2_mmap,
1313 * This is a wrapper around DEFINE_SIMPLE_ATTRIBUTE which does the
1314 * work of acquiring (or not) the SPU context before calling through
1315 * to the actual get routine. The set routine is called directly.
1317 #define SPU_ATTR_NOACQUIRE 0
1318 #define SPU_ATTR_ACQUIRE 1
1319 #define SPU_ATTR_ACQUIRE_SAVED 2
1321 #define DEFINE_SPUFS_ATTRIBUTE(__name, __get, __set, __fmt, __acquire) \
1322 static int __##__get(void *data, u64 *val) \
1324 struct spu_context *ctx = data; \
1327 if (__acquire == SPU_ATTR_ACQUIRE) { \
1328 ret = spu_acquire(ctx); \
1331 *val = __get(ctx); \
1333 } else if (__acquire == SPU_ATTR_ACQUIRE_SAVED) { \
1334 ret = spu_acquire_saved(ctx); \
1337 *val = __get(ctx); \
1338 spu_release_saved(ctx); \
1340 *val = __get(ctx); \
1344 DEFINE_SPUFS_SIMPLE_ATTRIBUTE(__name, __##__get, __set, __fmt);
1346 static int spufs_signal1_type_set(void *data, u64 val)
1348 struct spu_context *ctx = data;
1351 ret = spu_acquire(ctx);
1354 ctx->ops->signal1_type_set(ctx, val);
1360 static u64 spufs_signal1_type_get(struct spu_context *ctx)
1362 return ctx->ops->signal1_type_get(ctx);
1364 DEFINE_SPUFS_ATTRIBUTE(spufs_signal1_type, spufs_signal1_type_get,
1365 spufs_signal1_type_set, "%llu\n", SPU_ATTR_ACQUIRE);
1368 static int spufs_signal2_type_set(void *data, u64 val)
1370 struct spu_context *ctx = data;
1373 ret = spu_acquire(ctx);
1376 ctx->ops->signal2_type_set(ctx, val);
1382 static u64 spufs_signal2_type_get(struct spu_context *ctx)
1384 return ctx->ops->signal2_type_get(ctx);
1386 DEFINE_SPUFS_ATTRIBUTE(spufs_signal2_type, spufs_signal2_type_get,
1387 spufs_signal2_type_set, "%llu\n", SPU_ATTR_ACQUIRE);
1391 spufs_mss_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
1393 return spufs_ps_fault(vma, vmf, 0x0000, SPUFS_MSS_MAP_SIZE);
1396 static struct vm_operations_struct spufs_mss_mmap_vmops = {
1397 .fault = spufs_mss_mmap_fault,
1401 * mmap support for problem state MFC DMA area [0x0000 - 0x0fff].
1403 static int spufs_mss_mmap(struct file *file, struct vm_area_struct *vma)
1405 if (!(vma->vm_flags & VM_SHARED))
1408 vma->vm_flags |= VM_IO | VM_PFNMAP;
1409 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
1410 | _PAGE_NO_CACHE | _PAGE_GUARDED);
1412 vma->vm_ops = &spufs_mss_mmap_vmops;
1415 #else /* SPUFS_MMAP_4K */
1416 #define spufs_mss_mmap NULL
1417 #endif /* !SPUFS_MMAP_4K */
1419 static int spufs_mss_open(struct inode *inode, struct file *file)
1421 struct spufs_inode_info *i = SPUFS_I(inode);
1422 struct spu_context *ctx = i->i_ctx;
1424 file->private_data = i->i_ctx;
1426 mutex_lock(&ctx->mapping_lock);
1427 if (!i->i_openers++)
1428 ctx->mss = inode->i_mapping;
1429 mutex_unlock(&ctx->mapping_lock);
1430 return nonseekable_open(inode, file);
1434 spufs_mss_release(struct inode *inode, struct file *file)
1436 struct spufs_inode_info *i = SPUFS_I(inode);
1437 struct spu_context *ctx = i->i_ctx;
1439 mutex_lock(&ctx->mapping_lock);
1440 if (!--i->i_openers)
1442 mutex_unlock(&ctx->mapping_lock);
1446 static const struct file_operations spufs_mss_fops = {
1447 .open = spufs_mss_open,
1448 .release = spufs_mss_release,
1449 .mmap = spufs_mss_mmap,
1453 spufs_psmap_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
1455 return spufs_ps_fault(vma, vmf, 0x0000, SPUFS_PS_MAP_SIZE);
1458 static struct vm_operations_struct spufs_psmap_mmap_vmops = {
1459 .fault = spufs_psmap_mmap_fault,
1463 * mmap support for full problem state area [0x00000 - 0x1ffff].
1465 static int spufs_psmap_mmap(struct file *file, struct vm_area_struct *vma)
1467 if (!(vma->vm_flags & VM_SHARED))
1470 vma->vm_flags |= VM_IO | VM_PFNMAP;
1471 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
1472 | _PAGE_NO_CACHE | _PAGE_GUARDED);
1474 vma->vm_ops = &spufs_psmap_mmap_vmops;
1478 static int spufs_psmap_open(struct inode *inode, struct file *file)
1480 struct spufs_inode_info *i = SPUFS_I(inode);
1481 struct spu_context *ctx = i->i_ctx;
1483 mutex_lock(&ctx->mapping_lock);
1484 file->private_data = i->i_ctx;
1485 if (!i->i_openers++)
1486 ctx->psmap = inode->i_mapping;
1487 mutex_unlock(&ctx->mapping_lock);
1488 return nonseekable_open(inode, file);
1492 spufs_psmap_release(struct inode *inode, struct file *file)
1494 struct spufs_inode_info *i = SPUFS_I(inode);
1495 struct spu_context *ctx = i->i_ctx;
1497 mutex_lock(&ctx->mapping_lock);
1498 if (!--i->i_openers)
1500 mutex_unlock(&ctx->mapping_lock);
1504 static const struct file_operations spufs_psmap_fops = {
1505 .open = spufs_psmap_open,
1506 .release = spufs_psmap_release,
1507 .mmap = spufs_psmap_mmap,
1513 spufs_mfc_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
1515 return spufs_ps_fault(vma, vmf, 0x3000, SPUFS_MFC_MAP_SIZE);
1518 static struct vm_operations_struct spufs_mfc_mmap_vmops = {
1519 .fault = spufs_mfc_mmap_fault,
1523 * mmap support for problem state MFC DMA area [0x0000 - 0x0fff].
1525 static int spufs_mfc_mmap(struct file *file, struct vm_area_struct *vma)
1527 if (!(vma->vm_flags & VM_SHARED))
1530 vma->vm_flags |= VM_IO | VM_PFNMAP;
1531 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
1532 | _PAGE_NO_CACHE | _PAGE_GUARDED);
1534 vma->vm_ops = &spufs_mfc_mmap_vmops;
1537 #else /* SPUFS_MMAP_4K */
1538 #define spufs_mfc_mmap NULL
1539 #endif /* !SPUFS_MMAP_4K */
1541 static int spufs_mfc_open(struct inode *inode, struct file *file)
1543 struct spufs_inode_info *i = SPUFS_I(inode);
1544 struct spu_context *ctx = i->i_ctx;
1546 /* we don't want to deal with DMA into other processes */
1547 if (ctx->owner != current->mm)
1550 if (atomic_read(&inode->i_count) != 1)
1553 mutex_lock(&ctx->mapping_lock);
1554 file->private_data = ctx;
1555 if (!i->i_openers++)
1556 ctx->mfc = inode->i_mapping;
1557 mutex_unlock(&ctx->mapping_lock);
1558 return nonseekable_open(inode, file);
1562 spufs_mfc_release(struct inode *inode, struct file *file)
1564 struct spufs_inode_info *i = SPUFS_I(inode);
1565 struct spu_context *ctx = i->i_ctx;
1567 mutex_lock(&ctx->mapping_lock);
1568 if (!--i->i_openers)
1570 mutex_unlock(&ctx->mapping_lock);
1574 /* interrupt-level mfc callback function. */
1575 void spufs_mfc_callback(struct spu *spu)
1577 struct spu_context *ctx = spu->ctx;
1582 wake_up_all(&ctx->mfc_wq);
1584 pr_debug("%s %s\n", __func__, spu->name);
1585 if (ctx->mfc_fasync) {
1586 u32 free_elements, tagstatus;
1589 /* no need for spu_acquire in interrupt context */
1590 free_elements = ctx->ops->get_mfc_free_elements(ctx);
1591 tagstatus = ctx->ops->read_mfc_tagstatus(ctx);
1594 if (free_elements & 0xffff)
1596 if (tagstatus & ctx->tagwait)
1599 kill_fasync(&ctx->mfc_fasync, SIGIO, mask);
1603 static int spufs_read_mfc_tagstatus(struct spu_context *ctx, u32 *status)
1605 /* See if there is one tag group is complete */
1606 /* FIXME we need locking around tagwait */
1607 *status = ctx->ops->read_mfc_tagstatus(ctx) & ctx->tagwait;
1608 ctx->tagwait &= ~*status;
1612 /* enable interrupt waiting for any tag group,
1613 may silently fail if interrupts are already enabled */
1614 ctx->ops->set_mfc_query(ctx, ctx->tagwait, 1);
1618 static ssize_t spufs_mfc_read(struct file *file, char __user *buffer,
1619 size_t size, loff_t *pos)
1621 struct spu_context *ctx = file->private_data;
1628 ret = spu_acquire(ctx);
1633 if (file->f_flags & O_NONBLOCK) {
1634 status = ctx->ops->read_mfc_tagstatus(ctx);
1635 if (!(status & ctx->tagwait))
1638 /* XXX(hch): shouldn't we clear ret here? */
1639 ctx->tagwait &= ~status;
1641 ret = spufs_wait(ctx->mfc_wq,
1642 spufs_read_mfc_tagstatus(ctx, &status));
1649 if (copy_to_user(buffer, &status, 4))
1656 static int spufs_check_valid_dma(struct mfc_dma_command *cmd)
1658 pr_debug("queueing DMA %x %lx %x %x %x\n", cmd->lsa,
1659 cmd->ea, cmd->size, cmd->tag, cmd->cmd);
1670 pr_debug("invalid DMA opcode %x\n", cmd->cmd);
1674 if ((cmd->lsa & 0xf) != (cmd->ea &0xf)) {
1675 pr_debug("invalid DMA alignment, ea %lx lsa %x\n",
1680 switch (cmd->size & 0xf) {
1701 pr_debug("invalid DMA alignment %x for size %x\n",
1702 cmd->lsa & 0xf, cmd->size);
1706 if (cmd->size > 16 * 1024) {
1707 pr_debug("invalid DMA size %x\n", cmd->size);
1711 if (cmd->tag & 0xfff0) {
1712 /* we reserve the higher tag numbers for kernel use */
1713 pr_debug("invalid DMA tag\n");
1718 /* not supported in this version */
1719 pr_debug("invalid DMA class\n");
1726 static int spu_send_mfc_command(struct spu_context *ctx,
1727 struct mfc_dma_command cmd,
1730 *error = ctx->ops->send_mfc_command(ctx, &cmd);
1731 if (*error == -EAGAIN) {
1732 /* wait for any tag group to complete
1733 so we have space for the new command */
1734 ctx->ops->set_mfc_query(ctx, ctx->tagwait, 1);
1735 /* try again, because the queue might be
1737 *error = ctx->ops->send_mfc_command(ctx, &cmd);
1738 if (*error == -EAGAIN)
1744 static ssize_t spufs_mfc_write(struct file *file, const char __user *buffer,
1745 size_t size, loff_t *pos)
1747 struct spu_context *ctx = file->private_data;
1748 struct mfc_dma_command cmd;
1751 if (size != sizeof cmd)
1755 if (copy_from_user(&cmd, buffer, sizeof cmd))
1758 ret = spufs_check_valid_dma(&cmd);
1762 ret = spu_acquire(ctx);
1766 ret = spufs_wait(ctx->run_wq, ctx->state == SPU_STATE_RUNNABLE);
1770 if (file->f_flags & O_NONBLOCK) {
1771 ret = ctx->ops->send_mfc_command(ctx, &cmd);
1774 ret = spufs_wait(ctx->mfc_wq,
1775 spu_send_mfc_command(ctx, cmd, &status));
1785 ctx->tagwait |= 1 << cmd.tag;
1794 static unsigned int spufs_mfc_poll(struct file *file,poll_table *wait)
1796 struct spu_context *ctx = file->private_data;
1797 u32 free_elements, tagstatus;
1800 poll_wait(file, &ctx->mfc_wq, wait);
1803 * For now keep this uninterruptible and also ignore the rule
1804 * that poll should not sleep. Will be fixed later.
1806 mutex_lock(&ctx->state_mutex);
1807 ctx->ops->set_mfc_query(ctx, ctx->tagwait, 2);
1808 free_elements = ctx->ops->get_mfc_free_elements(ctx);
1809 tagstatus = ctx->ops->read_mfc_tagstatus(ctx);
1813 if (free_elements & 0xffff)
1814 mask |= POLLOUT | POLLWRNORM;
1815 if (tagstatus & ctx->tagwait)
1816 mask |= POLLIN | POLLRDNORM;
1818 pr_debug("%s: free %d tagstatus %d tagwait %d\n", __func__,
1819 free_elements, tagstatus, ctx->tagwait);
1824 static int spufs_mfc_flush(struct file *file, fl_owner_t id)
1826 struct spu_context *ctx = file->private_data;
1829 ret = spu_acquire(ctx);
1833 /* this currently hangs */
1834 ret = spufs_wait(ctx->mfc_wq,
1835 ctx->ops->set_mfc_query(ctx, ctx->tagwait, 2));
1838 ret = spufs_wait(ctx->mfc_wq,
1839 ctx->ops->read_mfc_tagstatus(ctx) == ctx->tagwait);
1850 static int spufs_mfc_fsync(struct file *file, struct dentry *dentry,
1853 return spufs_mfc_flush(file, NULL);
1856 static int spufs_mfc_fasync(int fd, struct file *file, int on)
1858 struct spu_context *ctx = file->private_data;
1860 return fasync_helper(fd, file, on, &ctx->mfc_fasync);
1863 static const struct file_operations spufs_mfc_fops = {
1864 .open = spufs_mfc_open,
1865 .release = spufs_mfc_release,
1866 .read = spufs_mfc_read,
1867 .write = spufs_mfc_write,
1868 .poll = spufs_mfc_poll,
1869 .flush = spufs_mfc_flush,
1870 .fsync = spufs_mfc_fsync,
1871 .fasync = spufs_mfc_fasync,
1872 .mmap = spufs_mfc_mmap,
1875 static int spufs_npc_set(void *data, u64 val)
1877 struct spu_context *ctx = data;
1880 ret = spu_acquire(ctx);
1883 ctx->ops->npc_write(ctx, val);
1889 static u64 spufs_npc_get(struct spu_context *ctx)
1891 return ctx->ops->npc_read(ctx);
1893 DEFINE_SPUFS_ATTRIBUTE(spufs_npc_ops, spufs_npc_get, spufs_npc_set,
1894 "0x%llx\n", SPU_ATTR_ACQUIRE);
1896 static int spufs_decr_set(void *data, u64 val)
1898 struct spu_context *ctx = data;
1899 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1902 ret = spu_acquire_saved(ctx);
1905 lscsa->decr.slot[0] = (u32) val;
1906 spu_release_saved(ctx);
1911 static u64 spufs_decr_get(struct spu_context *ctx)
1913 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1914 return lscsa->decr.slot[0];
1916 DEFINE_SPUFS_ATTRIBUTE(spufs_decr_ops, spufs_decr_get, spufs_decr_set,
1917 "0x%llx\n", SPU_ATTR_ACQUIRE_SAVED);
1919 static int spufs_decr_status_set(void *data, u64 val)
1921 struct spu_context *ctx = data;
1924 ret = spu_acquire_saved(ctx);
1928 ctx->csa.priv2.mfc_control_RW |= MFC_CNTL_DECREMENTER_RUNNING;
1930 ctx->csa.priv2.mfc_control_RW &= ~MFC_CNTL_DECREMENTER_RUNNING;
1931 spu_release_saved(ctx);
1936 static u64 spufs_decr_status_get(struct spu_context *ctx)
1938 if (ctx->csa.priv2.mfc_control_RW & MFC_CNTL_DECREMENTER_RUNNING)
1939 return SPU_DECR_STATUS_RUNNING;
1943 DEFINE_SPUFS_ATTRIBUTE(spufs_decr_status_ops, spufs_decr_status_get,
1944 spufs_decr_status_set, "0x%llx\n",
1945 SPU_ATTR_ACQUIRE_SAVED);
1947 static int spufs_event_mask_set(void *data, u64 val)
1949 struct spu_context *ctx = data;
1950 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1953 ret = spu_acquire_saved(ctx);
1956 lscsa->event_mask.slot[0] = (u32) val;
1957 spu_release_saved(ctx);
1962 static u64 spufs_event_mask_get(struct spu_context *ctx)
1964 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1965 return lscsa->event_mask.slot[0];
1968 DEFINE_SPUFS_ATTRIBUTE(spufs_event_mask_ops, spufs_event_mask_get,
1969 spufs_event_mask_set, "0x%llx\n",
1970 SPU_ATTR_ACQUIRE_SAVED);
1972 static u64 spufs_event_status_get(struct spu_context *ctx)
1974 struct spu_state *state = &ctx->csa;
1976 stat = state->spu_chnlcnt_RW[0];
1978 return state->spu_chnldata_RW[0];
1981 DEFINE_SPUFS_ATTRIBUTE(spufs_event_status_ops, spufs_event_status_get,
1982 NULL, "0x%llx\n", SPU_ATTR_ACQUIRE_SAVED)
1984 static int spufs_srr0_set(void *data, u64 val)
1986 struct spu_context *ctx = data;
1987 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1990 ret = spu_acquire_saved(ctx);
1993 lscsa->srr0.slot[0] = (u32) val;
1994 spu_release_saved(ctx);
1999 static u64 spufs_srr0_get(struct spu_context *ctx)
2001 struct spu_lscsa *lscsa = ctx->csa.lscsa;
2002 return lscsa->srr0.slot[0];
2004 DEFINE_SPUFS_ATTRIBUTE(spufs_srr0_ops, spufs_srr0_get, spufs_srr0_set,
2005 "0x%llx\n", SPU_ATTR_ACQUIRE_SAVED)
2007 static u64 spufs_id_get(struct spu_context *ctx)
2011 if (ctx->state == SPU_STATE_RUNNABLE)
2012 num = ctx->spu->number;
2014 num = (unsigned int)-1;
2018 DEFINE_SPUFS_ATTRIBUTE(spufs_id_ops, spufs_id_get, NULL, "0x%llx\n",
2021 static u64 spufs_object_id_get(struct spu_context *ctx)
2023 /* FIXME: Should there really be no locking here? */
2024 return ctx->object_id;
2027 static int spufs_object_id_set(void *data, u64 id)
2029 struct spu_context *ctx = data;
2030 ctx->object_id = id;
2035 DEFINE_SPUFS_ATTRIBUTE(spufs_object_id_ops, spufs_object_id_get,
2036 spufs_object_id_set, "0x%llx\n", SPU_ATTR_NOACQUIRE);
2038 static u64 spufs_lslr_get(struct spu_context *ctx)
2040 return ctx->csa.priv2.spu_lslr_RW;
2042 DEFINE_SPUFS_ATTRIBUTE(spufs_lslr_ops, spufs_lslr_get, NULL, "0x%llx\n",
2043 SPU_ATTR_ACQUIRE_SAVED);
2045 static int spufs_info_open(struct inode *inode, struct file *file)
2047 struct spufs_inode_info *i = SPUFS_I(inode);
2048 struct spu_context *ctx = i->i_ctx;
2049 file->private_data = ctx;
2053 static int spufs_caps_show(struct seq_file *s, void *private)
2055 struct spu_context *ctx = s->private;
2057 if (!(ctx->flags & SPU_CREATE_NOSCHED))
2058 seq_puts(s, "sched\n");
2059 if (!(ctx->flags & SPU_CREATE_ISOLATE))
2060 seq_puts(s, "step\n");
2064 static int spufs_caps_open(struct inode *inode, struct file *file)
2066 return single_open(file, spufs_caps_show, SPUFS_I(inode)->i_ctx);
2069 static const struct file_operations spufs_caps_fops = {
2070 .open = spufs_caps_open,
2072 .llseek = seq_lseek,
2073 .release = single_release,
2076 static ssize_t __spufs_mbox_info_read(struct spu_context *ctx,
2077 char __user *buf, size_t len, loff_t *pos)
2081 /* EOF if there's no entry in the mbox */
2082 if (!(ctx->csa.prob.mb_stat_R & 0x0000ff))
2085 data = ctx->csa.prob.pu_mb_R;
2087 return simple_read_from_buffer(buf, len, pos, &data, sizeof data);
2090 static ssize_t spufs_mbox_info_read(struct file *file, char __user *buf,
2091 size_t len, loff_t *pos)
2094 struct spu_context *ctx = file->private_data;
2096 if (!access_ok(VERIFY_WRITE, buf, len))
2099 ret = spu_acquire_saved(ctx);
2102 spin_lock(&ctx->csa.register_lock);
2103 ret = __spufs_mbox_info_read(ctx, buf, len, pos);
2104 spin_unlock(&ctx->csa.register_lock);
2105 spu_release_saved(ctx);
2110 static const struct file_operations spufs_mbox_info_fops = {
2111 .open = spufs_info_open,
2112 .read = spufs_mbox_info_read,
2113 .llseek = generic_file_llseek,
2116 static ssize_t __spufs_ibox_info_read(struct spu_context *ctx,
2117 char __user *buf, size_t len, loff_t *pos)
2121 /* EOF if there's no entry in the ibox */
2122 if (!(ctx->csa.prob.mb_stat_R & 0xff0000))
2125 data = ctx->csa.priv2.puint_mb_R;
2127 return simple_read_from_buffer(buf, len, pos, &data, sizeof data);
2130 static ssize_t spufs_ibox_info_read(struct file *file, char __user *buf,
2131 size_t len, loff_t *pos)
2133 struct spu_context *ctx = file->private_data;
2136 if (!access_ok(VERIFY_WRITE, buf, len))
2139 ret = spu_acquire_saved(ctx);
2142 spin_lock(&ctx->csa.register_lock);
2143 ret = __spufs_ibox_info_read(ctx, buf, len, pos);
2144 spin_unlock(&ctx->csa.register_lock);
2145 spu_release_saved(ctx);
2150 static const struct file_operations spufs_ibox_info_fops = {
2151 .open = spufs_info_open,
2152 .read = spufs_ibox_info_read,
2153 .llseek = generic_file_llseek,
2156 static ssize_t __spufs_wbox_info_read(struct spu_context *ctx,
2157 char __user *buf, size_t len, loff_t *pos)
2163 wbox_stat = ctx->csa.prob.mb_stat_R;
2164 cnt = 4 - ((wbox_stat & 0x00ff00) >> 8);
2165 for (i = 0; i < cnt; i++) {
2166 data[i] = ctx->csa.spu_mailbox_data[i];
2169 return simple_read_from_buffer(buf, len, pos, &data,
2173 static ssize_t spufs_wbox_info_read(struct file *file, char __user *buf,
2174 size_t len, loff_t *pos)
2176 struct spu_context *ctx = file->private_data;
2179 if (!access_ok(VERIFY_WRITE, buf, len))
2182 ret = spu_acquire_saved(ctx);
2185 spin_lock(&ctx->csa.register_lock);
2186 ret = __spufs_wbox_info_read(ctx, buf, len, pos);
2187 spin_unlock(&ctx->csa.register_lock);
2188 spu_release_saved(ctx);
2193 static const struct file_operations spufs_wbox_info_fops = {
2194 .open = spufs_info_open,
2195 .read = spufs_wbox_info_read,
2196 .llseek = generic_file_llseek,
2199 static ssize_t __spufs_dma_info_read(struct spu_context *ctx,
2200 char __user *buf, size_t len, loff_t *pos)
2202 struct spu_dma_info info;
2203 struct mfc_cq_sr *qp, *spuqp;
2206 info.dma_info_type = ctx->csa.priv2.spu_tag_status_query_RW;
2207 info.dma_info_mask = ctx->csa.lscsa->tag_mask.slot[0];
2208 info.dma_info_status = ctx->csa.spu_chnldata_RW[24];
2209 info.dma_info_stall_and_notify = ctx->csa.spu_chnldata_RW[25];
2210 info.dma_info_atomic_command_status = ctx->csa.spu_chnldata_RW[27];
2211 for (i = 0; i < 16; i++) {
2212 qp = &info.dma_info_command_data[i];
2213 spuqp = &ctx->csa.priv2.spuq[i];
2215 qp->mfc_cq_data0_RW = spuqp->mfc_cq_data0_RW;
2216 qp->mfc_cq_data1_RW = spuqp->mfc_cq_data1_RW;
2217 qp->mfc_cq_data2_RW = spuqp->mfc_cq_data2_RW;
2218 qp->mfc_cq_data3_RW = spuqp->mfc_cq_data3_RW;
2221 return simple_read_from_buffer(buf, len, pos, &info,
2225 static ssize_t spufs_dma_info_read(struct file *file, char __user *buf,
2226 size_t len, loff_t *pos)
2228 struct spu_context *ctx = file->private_data;
2231 if (!access_ok(VERIFY_WRITE, buf, len))
2234 ret = spu_acquire_saved(ctx);
2237 spin_lock(&ctx->csa.register_lock);
2238 ret = __spufs_dma_info_read(ctx, buf, len, pos);
2239 spin_unlock(&ctx->csa.register_lock);
2240 spu_release_saved(ctx);
2245 static const struct file_operations spufs_dma_info_fops = {
2246 .open = spufs_info_open,
2247 .read = spufs_dma_info_read,
2250 static ssize_t __spufs_proxydma_info_read(struct spu_context *ctx,
2251 char __user *buf, size_t len, loff_t *pos)
2253 struct spu_proxydma_info info;
2254 struct mfc_cq_sr *qp, *puqp;
2255 int ret = sizeof info;
2261 if (!access_ok(VERIFY_WRITE, buf, len))
2264 info.proxydma_info_type = ctx->csa.prob.dma_querytype_RW;
2265 info.proxydma_info_mask = ctx->csa.prob.dma_querymask_RW;
2266 info.proxydma_info_status = ctx->csa.prob.dma_tagstatus_R;
2267 for (i = 0; i < 8; i++) {
2268 qp = &info.proxydma_info_command_data[i];
2269 puqp = &ctx->csa.priv2.puq[i];
2271 qp->mfc_cq_data0_RW = puqp->mfc_cq_data0_RW;
2272 qp->mfc_cq_data1_RW = puqp->mfc_cq_data1_RW;
2273 qp->mfc_cq_data2_RW = puqp->mfc_cq_data2_RW;
2274 qp->mfc_cq_data3_RW = puqp->mfc_cq_data3_RW;
2277 return simple_read_from_buffer(buf, len, pos, &info,
2281 static ssize_t spufs_proxydma_info_read(struct file *file, char __user *buf,
2282 size_t len, loff_t *pos)
2284 struct spu_context *ctx = file->private_data;
2287 ret = spu_acquire_saved(ctx);
2290 spin_lock(&ctx->csa.register_lock);
2291 ret = __spufs_proxydma_info_read(ctx, buf, len, pos);
2292 spin_unlock(&ctx->csa.register_lock);
2293 spu_release_saved(ctx);
2298 static const struct file_operations spufs_proxydma_info_fops = {
2299 .open = spufs_info_open,
2300 .read = spufs_proxydma_info_read,
2303 static int spufs_show_tid(struct seq_file *s, void *private)
2305 struct spu_context *ctx = s->private;
2307 seq_printf(s, "%d\n", ctx->tid);
2311 static int spufs_tid_open(struct inode *inode, struct file *file)
2313 return single_open(file, spufs_show_tid, SPUFS_I(inode)->i_ctx);
2316 static const struct file_operations spufs_tid_fops = {
2317 .open = spufs_tid_open,
2319 .llseek = seq_lseek,
2320 .release = single_release,
2323 static const char *ctx_state_names[] = {
2324 "user", "system", "iowait", "loaded"
2327 static unsigned long long spufs_acct_time(struct spu_context *ctx,
2328 enum spu_utilization_state state)
2331 unsigned long long time = ctx->stats.times[state];
2334 * In general, utilization statistics are updated by the controlling
2335 * thread as the spu context moves through various well defined
2336 * state transitions, but if the context is lazily loaded its
2337 * utilization statistics are not updated as the controlling thread
2338 * is not tightly coupled with the execution of the spu context. We
2339 * calculate and apply the time delta from the last recorded state
2340 * of the spu context.
2342 if (ctx->spu && ctx->stats.util_state == state) {
2344 time += timespec_to_ns(&ts) - ctx->stats.tstamp;
2347 return time / NSEC_PER_MSEC;
2350 static unsigned long long spufs_slb_flts(struct spu_context *ctx)
2352 unsigned long long slb_flts = ctx->stats.slb_flt;
2354 if (ctx->state == SPU_STATE_RUNNABLE) {
2355 slb_flts += (ctx->spu->stats.slb_flt -
2356 ctx->stats.slb_flt_base);
2362 static unsigned long long spufs_class2_intrs(struct spu_context *ctx)
2364 unsigned long long class2_intrs = ctx->stats.class2_intr;
2366 if (ctx->state == SPU_STATE_RUNNABLE) {
2367 class2_intrs += (ctx->spu->stats.class2_intr -
2368 ctx->stats.class2_intr_base);
2371 return class2_intrs;
2375 static int spufs_show_stat(struct seq_file *s, void *private)
2377 struct spu_context *ctx = s->private;
2380 ret = spu_acquire(ctx);
2384 seq_printf(s, "%s %llu %llu %llu %llu "
2385 "%llu %llu %llu %llu %llu %llu %llu %llu\n",
2386 ctx_state_names[ctx->stats.util_state],
2387 spufs_acct_time(ctx, SPU_UTIL_USER),
2388 spufs_acct_time(ctx, SPU_UTIL_SYSTEM),
2389 spufs_acct_time(ctx, SPU_UTIL_IOWAIT),
2390 spufs_acct_time(ctx, SPU_UTIL_IDLE_LOADED),
2391 ctx->stats.vol_ctx_switch,
2392 ctx->stats.invol_ctx_switch,
2393 spufs_slb_flts(ctx),
2394 ctx->stats.hash_flt,
2397 spufs_class2_intrs(ctx),
2398 ctx->stats.libassist);
2403 static int spufs_stat_open(struct inode *inode, struct file *file)
2405 return single_open(file, spufs_show_stat, SPUFS_I(inode)->i_ctx);
2408 static const struct file_operations spufs_stat_fops = {
2409 .open = spufs_stat_open,
2411 .llseek = seq_lseek,
2412 .release = single_release,
2415 static inline int spufs_switch_log_used(struct spu_context *ctx)
2417 return (ctx->switch_log->head - ctx->switch_log->tail) %
2421 static inline int spufs_switch_log_avail(struct spu_context *ctx)
2423 return SWITCH_LOG_BUFSIZE - spufs_switch_log_used(ctx);
2426 static int spufs_switch_log_open(struct inode *inode, struct file *file)
2428 struct spu_context *ctx = SPUFS_I(inode)->i_ctx;
2431 * We (ab-)use the mapping_lock here because it serves the similar
2432 * purpose for synchronizing open/close elsewhere. Maybe it should
2433 * be renamed eventually.
2435 mutex_lock(&ctx->mapping_lock);
2436 if (ctx->switch_log) {
2437 spin_lock(&ctx->switch_log->lock);
2438 ctx->switch_log->head = 0;
2439 ctx->switch_log->tail = 0;
2440 spin_unlock(&ctx->switch_log->lock);
2443 * We allocate the switch log data structures on first open.
2444 * They will never be free because we assume a context will
2445 * be traced until it goes away.
2447 ctx->switch_log = kzalloc(sizeof(struct switch_log) +
2448 SWITCH_LOG_BUFSIZE * sizeof(struct switch_log_entry),
2450 if (!ctx->switch_log)
2452 spin_lock_init(&ctx->switch_log->lock);
2453 init_waitqueue_head(&ctx->switch_log->wait);
2455 mutex_unlock(&ctx->mapping_lock);
2459 mutex_unlock(&ctx->mapping_lock);
2463 static int switch_log_sprint(struct spu_context *ctx, char *tbuf, int n)
2465 struct switch_log_entry *p;
2467 p = ctx->switch_log->log + ctx->switch_log->tail % SWITCH_LOG_BUFSIZE;
2469 return snprintf(tbuf, n, "%u.%09u %d %u %u %llu\n",
2470 (unsigned int) p->tstamp.tv_sec,
2471 (unsigned int) p->tstamp.tv_nsec,
2473 (unsigned int) p->type,
2474 (unsigned int) p->val,
2475 (unsigned long long) p->timebase);
2478 static ssize_t spufs_switch_log_read(struct file *file, char __user *buf,
2479 size_t len, loff_t *ppos)
2481 struct inode *inode = file->f_path.dentry->d_inode;
2482 struct spu_context *ctx = SPUFS_I(inode)->i_ctx;
2483 int error = 0, cnt = 0;
2485 if (!buf || len < 0)
2492 if (file->f_flags & O_NONBLOCK) {
2493 if (spufs_switch_log_used(ctx) <= 0)
2494 return cnt ? cnt : -EAGAIN;
2496 /* Wait for data in buffer */
2497 error = wait_event_interruptible(ctx->switch_log->wait,
2498 spufs_switch_log_used(ctx) > 0);
2503 spin_lock(&ctx->switch_log->lock);
2504 if (ctx->switch_log->head == ctx->switch_log->tail) {
2505 /* multiple readers race? */
2506 spin_unlock(&ctx->switch_log->lock);
2510 width = switch_log_sprint(ctx, tbuf, sizeof(tbuf));
2512 ctx->switch_log->tail =
2513 (ctx->switch_log->tail + 1) %
2517 spin_unlock(&ctx->switch_log->lock);
2520 * If the record is greater than space available return
2521 * partial buffer (so far)
2526 error = copy_to_user(buf + cnt, tbuf, width);
2532 return cnt == 0 ? error : cnt;
2535 static unsigned int spufs_switch_log_poll(struct file *file, poll_table *wait)
2537 struct inode *inode = file->f_path.dentry->d_inode;
2538 struct spu_context *ctx = SPUFS_I(inode)->i_ctx;
2539 unsigned int mask = 0;
2541 poll_wait(file, &ctx->switch_log->wait, wait);
2543 if (spufs_switch_log_used(ctx) > 0)
2549 static const struct file_operations spufs_switch_log_fops = {
2550 .owner = THIS_MODULE,
2551 .open = spufs_switch_log_open,
2552 .read = spufs_switch_log_read,
2553 .poll = spufs_switch_log_poll,
2556 void spu_switch_log_notify(struct spu *spu, struct spu_context *ctx,
2559 if (!ctx->switch_log)
2562 spin_lock(&ctx->switch_log->lock);
2563 if (spufs_switch_log_avail(ctx) > 1) {
2564 struct switch_log_entry *p;
2566 p = ctx->switch_log->log + ctx->switch_log->head;
2567 ktime_get_ts(&p->tstamp);
2568 p->timebase = get_tb();
2569 p->spu_id = spu ? spu->number : -1;
2573 ctx->switch_log->head =
2574 (ctx->switch_log->head + 1) % SWITCH_LOG_BUFSIZE;
2576 spin_unlock(&ctx->switch_log->lock);
2578 wake_up(&ctx->switch_log->wait);
2581 static int spufs_show_ctx(struct seq_file *s, void *private)
2583 struct spu_context *ctx = s->private;
2586 mutex_lock(&ctx->state_mutex);
2588 struct spu *spu = ctx->spu;
2589 struct spu_priv2 __iomem *priv2 = spu->priv2;
2591 spin_lock_irq(&spu->register_lock);
2592 mfc_control_RW = in_be64(&priv2->mfc_control_RW);
2593 spin_unlock_irq(&spu->register_lock);
2595 struct spu_state *csa = &ctx->csa;
2597 mfc_control_RW = csa->priv2.mfc_control_RW;
2600 seq_printf(s, "%c flgs(%lx) sflgs(%lx) pri(%d) ts(%d) spu(%02d)"
2601 " %c %lx %lx %lx %lx %x %x\n",
2602 ctx->state == SPU_STATE_SAVED ? 'S' : 'R',
2607 ctx->spu ? ctx->spu->number : -1,
2608 !list_empty(&ctx->rq) ? 'q' : ' ',
2609 ctx->csa.class_0_pending,
2610 ctx->csa.class_0_dar,
2611 ctx->csa.class_1_dsisr,
2613 ctx->ops->runcntl_read(ctx),
2614 ctx->ops->status_read(ctx));
2616 mutex_unlock(&ctx->state_mutex);
2621 static int spufs_ctx_open(struct inode *inode, struct file *file)
2623 return single_open(file, spufs_show_ctx, SPUFS_I(inode)->i_ctx);
2626 static const struct file_operations spufs_ctx_fops = {
2627 .open = spufs_ctx_open,
2629 .llseek = seq_lseek,
2630 .release = single_release,
2633 struct spufs_tree_descr spufs_dir_contents[] = {
2634 { "capabilities", &spufs_caps_fops, 0444, },
2635 { "mem", &spufs_mem_fops, 0666, LS_SIZE, },
2636 { "regs", &spufs_regs_fops, 0666, sizeof(struct spu_reg128[128]), },
2637 { "mbox", &spufs_mbox_fops, 0444, },
2638 { "ibox", &spufs_ibox_fops, 0444, },
2639 { "wbox", &spufs_wbox_fops, 0222, },
2640 { "mbox_stat", &spufs_mbox_stat_fops, 0444, sizeof(u32), },
2641 { "ibox_stat", &spufs_ibox_stat_fops, 0444, sizeof(u32), },
2642 { "wbox_stat", &spufs_wbox_stat_fops, 0444, sizeof(u32), },
2643 { "signal1", &spufs_signal1_fops, 0666, },
2644 { "signal2", &spufs_signal2_fops, 0666, },
2645 { "signal1_type", &spufs_signal1_type, 0666, },
2646 { "signal2_type", &spufs_signal2_type, 0666, },
2647 { "cntl", &spufs_cntl_fops, 0666, },
2648 { "fpcr", &spufs_fpcr_fops, 0666, sizeof(struct spu_reg128), },
2649 { "lslr", &spufs_lslr_ops, 0444, },
2650 { "mfc", &spufs_mfc_fops, 0666, },
2651 { "mss", &spufs_mss_fops, 0666, },
2652 { "npc", &spufs_npc_ops, 0666, },
2653 { "srr0", &spufs_srr0_ops, 0666, },
2654 { "decr", &spufs_decr_ops, 0666, },
2655 { "decr_status", &spufs_decr_status_ops, 0666, },
2656 { "event_mask", &spufs_event_mask_ops, 0666, },
2657 { "event_status", &spufs_event_status_ops, 0444, },
2658 { "psmap", &spufs_psmap_fops, 0666, SPUFS_PS_MAP_SIZE, },
2659 { "phys-id", &spufs_id_ops, 0666, },
2660 { "object-id", &spufs_object_id_ops, 0666, },
2661 { "mbox_info", &spufs_mbox_info_fops, 0444, sizeof(u32), },
2662 { "ibox_info", &spufs_ibox_info_fops, 0444, sizeof(u32), },
2663 { "wbox_info", &spufs_wbox_info_fops, 0444, sizeof(u32), },
2664 { "dma_info", &spufs_dma_info_fops, 0444,
2665 sizeof(struct spu_dma_info), },
2666 { "proxydma_info", &spufs_proxydma_info_fops, 0444,
2667 sizeof(struct spu_proxydma_info)},
2668 { "tid", &spufs_tid_fops, 0444, },
2669 { "stat", &spufs_stat_fops, 0444, },
2670 { "switch_log", &spufs_switch_log_fops, 0444 },
2674 struct spufs_tree_descr spufs_dir_nosched_contents[] = {
2675 { "capabilities", &spufs_caps_fops, 0444, },
2676 { "mem", &spufs_mem_fops, 0666, LS_SIZE, },
2677 { "mbox", &spufs_mbox_fops, 0444, },
2678 { "ibox", &spufs_ibox_fops, 0444, },
2679 { "wbox", &spufs_wbox_fops, 0222, },
2680 { "mbox_stat", &spufs_mbox_stat_fops, 0444, sizeof(u32), },
2681 { "ibox_stat", &spufs_ibox_stat_fops, 0444, sizeof(u32), },
2682 { "wbox_stat", &spufs_wbox_stat_fops, 0444, sizeof(u32), },
2683 { "signal1", &spufs_signal1_nosched_fops, 0222, },
2684 { "signal2", &spufs_signal2_nosched_fops, 0222, },
2685 { "signal1_type", &spufs_signal1_type, 0666, },
2686 { "signal2_type", &spufs_signal2_type, 0666, },
2687 { "mss", &spufs_mss_fops, 0666, },
2688 { "mfc", &spufs_mfc_fops, 0666, },
2689 { "cntl", &spufs_cntl_fops, 0666, },
2690 { "npc", &spufs_npc_ops, 0666, },
2691 { "psmap", &spufs_psmap_fops, 0666, SPUFS_PS_MAP_SIZE, },
2692 { "phys-id", &spufs_id_ops, 0666, },
2693 { "object-id", &spufs_object_id_ops, 0666, },
2694 { "tid", &spufs_tid_fops, 0444, },
2695 { "stat", &spufs_stat_fops, 0444, },
2699 struct spufs_tree_descr spufs_dir_debug_contents[] = {
2700 { ".ctx", &spufs_ctx_fops, 0444, },
2704 struct spufs_coredump_reader spufs_coredump_read[] = {
2705 { "regs", __spufs_regs_read, NULL, sizeof(struct spu_reg128[128])},
2706 { "fpcr", __spufs_fpcr_read, NULL, sizeof(struct spu_reg128) },
2707 { "lslr", NULL, spufs_lslr_get, 19 },
2708 { "decr", NULL, spufs_decr_get, 19 },
2709 { "decr_status", NULL, spufs_decr_status_get, 19 },
2710 { "mem", __spufs_mem_read, NULL, LS_SIZE, },
2711 { "signal1", __spufs_signal1_read, NULL, sizeof(u32) },
2712 { "signal1_type", NULL, spufs_signal1_type_get, 19 },
2713 { "signal2", __spufs_signal2_read, NULL, sizeof(u32) },
2714 { "signal2_type", NULL, spufs_signal2_type_get, 19 },
2715 { "event_mask", NULL, spufs_event_mask_get, 19 },
2716 { "event_status", NULL, spufs_event_status_get, 19 },
2717 { "mbox_info", __spufs_mbox_info_read, NULL, sizeof(u32) },
2718 { "ibox_info", __spufs_ibox_info_read, NULL, sizeof(u32) },
2719 { "wbox_info", __spufs_wbox_info_read, NULL, 4 * sizeof(u32)},
2720 { "dma_info", __spufs_dma_info_read, NULL, sizeof(struct spu_dma_info)},
2721 { "proxydma_info", __spufs_proxydma_info_read,
2722 NULL, sizeof(struct spu_proxydma_info)},
2723 { "object-id", NULL, spufs_object_id_get, 19 },
2724 { "npc", NULL, spufs_npc_get, 19 },