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/slab.h>
37 #include <asm/spu_info.h>
38 #include <asm/uaccess.h>
43 #define SPUFS_MMAP_4K (PAGE_SIZE == 0x1000)
45 /* Simple attribute files */
47 int (*get)(void *, u64 *);
48 int (*set)(void *, u64);
49 char get_buf[24]; /* enough to store a u64 and "\n\0" */
52 const char *fmt; /* format for read operation */
53 struct mutex mutex; /* protects access to these buffers */
56 static int spufs_attr_open(struct inode *inode, struct file *file,
57 int (*get)(void *, u64 *), int (*set)(void *, u64),
60 struct spufs_attr *attr;
62 attr = kmalloc(sizeof(*attr), GFP_KERNEL);
68 attr->data = inode->i_private;
70 mutex_init(&attr->mutex);
71 file->private_data = attr;
73 return nonseekable_open(inode, file);
76 static int spufs_attr_release(struct inode *inode, struct file *file)
78 kfree(file->private_data);
82 static ssize_t spufs_attr_read(struct file *file, char __user *buf,
83 size_t len, loff_t *ppos)
85 struct spufs_attr *attr;
89 attr = file->private_data;
93 ret = mutex_lock_interruptible(&attr->mutex);
97 if (*ppos) { /* continued read */
98 size = strlen(attr->get_buf);
99 } else { /* first read */
101 ret = attr->get(attr->data, &val);
105 size = scnprintf(attr->get_buf, sizeof(attr->get_buf),
106 attr->fmt, (unsigned long long)val);
109 ret = simple_read_from_buffer(buf, len, ppos, attr->get_buf, size);
111 mutex_unlock(&attr->mutex);
115 static ssize_t spufs_attr_write(struct file *file, const char __user *buf,
116 size_t len, loff_t *ppos)
118 struct spufs_attr *attr;
123 attr = file->private_data;
127 ret = mutex_lock_interruptible(&attr->mutex);
132 size = min(sizeof(attr->set_buf) - 1, len);
133 if (copy_from_user(attr->set_buf, buf, size))
136 ret = len; /* claim we got the whole input */
137 attr->set_buf[size] = '\0';
138 val = simple_strtol(attr->set_buf, NULL, 0);
139 attr->set(attr->data, val);
141 mutex_unlock(&attr->mutex);
145 #define DEFINE_SPUFS_SIMPLE_ATTRIBUTE(__fops, __get, __set, __fmt) \
146 static int __fops ## _open(struct inode *inode, struct file *file) \
148 __simple_attr_check_format(__fmt, 0ull); \
149 return spufs_attr_open(inode, file, __get, __set, __fmt); \
151 static const struct file_operations __fops = { \
152 .owner = THIS_MODULE, \
153 .open = __fops ## _open, \
154 .release = spufs_attr_release, \
155 .read = spufs_attr_read, \
156 .write = spufs_attr_write, \
157 .llseek = generic_file_llseek, \
162 spufs_mem_open(struct inode *inode, struct file *file)
164 struct spufs_inode_info *i = SPUFS_I(inode);
165 struct spu_context *ctx = i->i_ctx;
167 mutex_lock(&ctx->mapping_lock);
168 file->private_data = ctx;
170 ctx->local_store = inode->i_mapping;
171 mutex_unlock(&ctx->mapping_lock);
176 spufs_mem_release(struct inode *inode, struct file *file)
178 struct spufs_inode_info *i = SPUFS_I(inode);
179 struct spu_context *ctx = i->i_ctx;
181 mutex_lock(&ctx->mapping_lock);
183 ctx->local_store = NULL;
184 mutex_unlock(&ctx->mapping_lock);
189 __spufs_mem_read(struct spu_context *ctx, char __user *buffer,
190 size_t size, loff_t *pos)
192 char *local_store = ctx->ops->get_ls(ctx);
193 return simple_read_from_buffer(buffer, size, pos, local_store,
198 spufs_mem_read(struct file *file, char __user *buffer,
199 size_t size, loff_t *pos)
201 struct spu_context *ctx = file->private_data;
204 ret = spu_acquire(ctx);
207 ret = __spufs_mem_read(ctx, buffer, size, pos);
214 spufs_mem_write(struct file *file, const char __user *buffer,
215 size_t size, loff_t *ppos)
217 struct spu_context *ctx = file->private_data;
226 if (size > LS_SIZE - pos)
227 size = LS_SIZE - pos;
229 ret = spu_acquire(ctx);
233 local_store = ctx->ops->get_ls(ctx);
234 ret = copy_from_user(local_store + pos, buffer, size);
244 spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
246 struct spu_context *ctx = vma->vm_file->private_data;
247 unsigned long address = (unsigned long)vmf->virtual_address;
248 unsigned long pfn, offset;
250 #ifdef CONFIG_SPU_FS_64K_LS
251 struct spu_state *csa = &ctx->csa;
254 /* Check what page size we are using */
255 psize = get_slice_psize(vma->vm_mm, address);
257 /* Some sanity checking */
258 BUG_ON(csa->use_big_pages != (psize == MMU_PAGE_64K));
260 /* Wow, 64K, cool, we need to align the address though */
261 if (csa->use_big_pages) {
262 BUG_ON(vma->vm_start & 0xffff);
263 address &= ~0xfffful;
265 #endif /* CONFIG_SPU_FS_64K_LS */
267 offset = vmf->pgoff << PAGE_SHIFT;
268 if (offset >= LS_SIZE)
269 return VM_FAULT_SIGBUS;
271 pr_debug("spufs_mem_mmap_fault address=0x%lx, offset=0x%lx\n",
274 if (spu_acquire(ctx))
275 return VM_FAULT_NOPAGE;
277 if (ctx->state == SPU_STATE_SAVED) {
278 vma->vm_page_prot = pgprot_cached(vma->vm_page_prot);
279 pfn = vmalloc_to_pfn(ctx->csa.lscsa->ls + offset);
281 vma->vm_page_prot = pgprot_noncached_wc(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 const 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_noncached_wc(vma->vm_page_prot);
343 vma->vm_ops = &spufs_mem_mmap_vmops;
347 #ifdef CONFIG_SPU_FS_64K_LS
348 static unsigned long spufs_get_unmapped_area(struct file *file,
349 unsigned long addr, unsigned long len, unsigned long pgoff,
352 struct spu_context *ctx = file->private_data;
353 struct spu_state *csa = &ctx->csa;
355 /* If not using big pages, fallback to normal MM g_u_a */
356 if (!csa->use_big_pages)
357 return current->mm->get_unmapped_area(file, addr, len,
360 /* Else, try to obtain a 64K pages slice */
361 return slice_get_unmapped_area(addr, len, flags,
364 #endif /* CONFIG_SPU_FS_64K_LS */
366 static const struct file_operations spufs_mem_fops = {
367 .open = spufs_mem_open,
368 .release = spufs_mem_release,
369 .read = spufs_mem_read,
370 .write = spufs_mem_write,
371 .llseek = generic_file_llseek,
372 .mmap = spufs_mem_mmap,
373 #ifdef CONFIG_SPU_FS_64K_LS
374 .get_unmapped_area = spufs_get_unmapped_area,
378 static int spufs_ps_fault(struct vm_area_struct *vma,
379 struct vm_fault *vmf,
380 unsigned long ps_offs,
381 unsigned long ps_size)
383 struct spu_context *ctx = vma->vm_file->private_data;
384 unsigned long area, offset = vmf->pgoff << PAGE_SHIFT;
387 spu_context_nospu_trace(spufs_ps_fault__enter, ctx);
389 if (offset >= ps_size)
390 return VM_FAULT_SIGBUS;
392 if (fatal_signal_pending(current))
393 return VM_FAULT_SIGBUS;
396 * Because we release the mmap_sem, the context may be destroyed while
397 * we're in spu_wait. Grab an extra reference so it isn't destroyed
400 get_spu_context(ctx);
403 * We have to wait for context to be loaded before we have
404 * pages to hand out to the user, but we don't want to wait
405 * with the mmap_sem held.
406 * It is possible to drop the mmap_sem here, but then we need
407 * to return VM_FAULT_NOPAGE because the mappings may have
410 if (spu_acquire(ctx))
413 if (ctx->state == SPU_STATE_SAVED) {
414 up_read(¤t->mm->mmap_sem);
415 spu_context_nospu_trace(spufs_ps_fault__sleep, ctx);
416 ret = spufs_wait(ctx->run_wq, ctx->state == SPU_STATE_RUNNABLE);
417 spu_context_trace(spufs_ps_fault__wake, ctx, ctx->spu);
418 down_read(¤t->mm->mmap_sem);
420 area = ctx->spu->problem_phys + ps_offs;
421 vm_insert_pfn(vma, (unsigned long)vmf->virtual_address,
422 (area + offset) >> PAGE_SHIFT);
423 spu_context_trace(spufs_ps_fault__insert, ctx, ctx->spu);
430 put_spu_context(ctx);
431 return VM_FAULT_NOPAGE;
435 static int spufs_cntl_mmap_fault(struct vm_area_struct *vma,
436 struct vm_fault *vmf)
438 return spufs_ps_fault(vma, vmf, 0x4000, SPUFS_CNTL_MAP_SIZE);
441 static const struct vm_operations_struct spufs_cntl_mmap_vmops = {
442 .fault = spufs_cntl_mmap_fault,
446 * mmap support for problem state control area [0x4000 - 0x4fff].
448 static int spufs_cntl_mmap(struct file *file, struct vm_area_struct *vma)
450 if (!(vma->vm_flags & VM_SHARED))
453 vma->vm_flags |= VM_IO | VM_PFNMAP;
454 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
456 vma->vm_ops = &spufs_cntl_mmap_vmops;
459 #else /* SPUFS_MMAP_4K */
460 #define spufs_cntl_mmap NULL
461 #endif /* !SPUFS_MMAP_4K */
463 static int spufs_cntl_get(void *data, u64 *val)
465 struct spu_context *ctx = data;
468 ret = spu_acquire(ctx);
471 *val = ctx->ops->status_read(ctx);
477 static int spufs_cntl_set(void *data, u64 val)
479 struct spu_context *ctx = data;
482 ret = spu_acquire(ctx);
485 ctx->ops->runcntl_write(ctx, val);
491 static int spufs_cntl_open(struct inode *inode, struct file *file)
493 struct spufs_inode_info *i = SPUFS_I(inode);
494 struct spu_context *ctx = i->i_ctx;
496 mutex_lock(&ctx->mapping_lock);
497 file->private_data = ctx;
499 ctx->cntl = inode->i_mapping;
500 mutex_unlock(&ctx->mapping_lock);
501 return simple_attr_open(inode, file, spufs_cntl_get,
502 spufs_cntl_set, "0x%08lx");
506 spufs_cntl_release(struct inode *inode, struct file *file)
508 struct spufs_inode_info *i = SPUFS_I(inode);
509 struct spu_context *ctx = i->i_ctx;
511 simple_attr_release(inode, file);
513 mutex_lock(&ctx->mapping_lock);
516 mutex_unlock(&ctx->mapping_lock);
520 static const struct file_operations spufs_cntl_fops = {
521 .open = spufs_cntl_open,
522 .release = spufs_cntl_release,
523 .read = simple_attr_read,
524 .write = simple_attr_write,
525 .llseek = generic_file_llseek,
526 .mmap = spufs_cntl_mmap,
530 spufs_regs_open(struct inode *inode, struct file *file)
532 struct spufs_inode_info *i = SPUFS_I(inode);
533 file->private_data = i->i_ctx;
538 __spufs_regs_read(struct spu_context *ctx, char __user *buffer,
539 size_t size, loff_t *pos)
541 struct spu_lscsa *lscsa = ctx->csa.lscsa;
542 return simple_read_from_buffer(buffer, size, pos,
543 lscsa->gprs, sizeof lscsa->gprs);
547 spufs_regs_read(struct file *file, char __user *buffer,
548 size_t size, loff_t *pos)
551 struct spu_context *ctx = file->private_data;
553 /* pre-check for file position: if we'd return EOF, there's no point
554 * causing a deschedule */
555 if (*pos >= sizeof(ctx->csa.lscsa->gprs))
558 ret = spu_acquire_saved(ctx);
561 ret = __spufs_regs_read(ctx, buffer, size, pos);
562 spu_release_saved(ctx);
567 spufs_regs_write(struct file *file, const char __user *buffer,
568 size_t size, loff_t *pos)
570 struct spu_context *ctx = file->private_data;
571 struct spu_lscsa *lscsa = ctx->csa.lscsa;
574 if (*pos >= sizeof(lscsa->gprs))
577 size = min_t(ssize_t, sizeof(lscsa->gprs) - *pos, size);
580 ret = spu_acquire_saved(ctx);
584 ret = copy_from_user((char *)lscsa->gprs + *pos - size,
585 buffer, size) ? -EFAULT : size;
587 spu_release_saved(ctx);
591 static const struct file_operations spufs_regs_fops = {
592 .open = spufs_regs_open,
593 .read = spufs_regs_read,
594 .write = spufs_regs_write,
595 .llseek = generic_file_llseek,
599 __spufs_fpcr_read(struct spu_context *ctx, char __user * buffer,
600 size_t size, loff_t * pos)
602 struct spu_lscsa *lscsa = ctx->csa.lscsa;
603 return simple_read_from_buffer(buffer, size, pos,
604 &lscsa->fpcr, sizeof(lscsa->fpcr));
608 spufs_fpcr_read(struct file *file, char __user * buffer,
609 size_t size, loff_t * pos)
612 struct spu_context *ctx = file->private_data;
614 ret = spu_acquire_saved(ctx);
617 ret = __spufs_fpcr_read(ctx, buffer, size, pos);
618 spu_release_saved(ctx);
623 spufs_fpcr_write(struct file *file, const char __user * buffer,
624 size_t size, loff_t * pos)
626 struct spu_context *ctx = file->private_data;
627 struct spu_lscsa *lscsa = ctx->csa.lscsa;
630 if (*pos >= sizeof(lscsa->fpcr))
633 size = min_t(ssize_t, sizeof(lscsa->fpcr) - *pos, size);
635 ret = spu_acquire_saved(ctx);
640 ret = copy_from_user((char *)&lscsa->fpcr + *pos - size,
641 buffer, size) ? -EFAULT : size;
643 spu_release_saved(ctx);
647 static const struct file_operations spufs_fpcr_fops = {
648 .open = spufs_regs_open,
649 .read = spufs_fpcr_read,
650 .write = spufs_fpcr_write,
651 .llseek = generic_file_llseek,
654 /* generic open function for all pipe-like files */
655 static int spufs_pipe_open(struct inode *inode, struct file *file)
657 struct spufs_inode_info *i = SPUFS_I(inode);
658 file->private_data = i->i_ctx;
660 return nonseekable_open(inode, file);
664 * Read as many bytes from the mailbox as possible, until
665 * one of the conditions becomes true:
667 * - no more data available in the mailbox
668 * - end of the user provided buffer
669 * - end of the mapped area
671 static ssize_t spufs_mbox_read(struct file *file, char __user *buf,
672 size_t len, loff_t *pos)
674 struct spu_context *ctx = file->private_data;
675 u32 mbox_data, __user *udata;
681 if (!access_ok(VERIFY_WRITE, buf, len))
684 udata = (void __user *)buf;
686 count = spu_acquire(ctx);
690 for (count = 0; (count + 4) <= len; count += 4, udata++) {
692 ret = ctx->ops->mbox_read(ctx, &mbox_data);
697 * at the end of the mapped area, we can fault
698 * but still need to return the data we have
699 * read successfully so far.
701 ret = __put_user(mbox_data, udata);
716 static const struct file_operations spufs_mbox_fops = {
717 .open = spufs_pipe_open,
718 .read = spufs_mbox_read,
722 static ssize_t spufs_mbox_stat_read(struct file *file, char __user *buf,
723 size_t len, loff_t *pos)
725 struct spu_context *ctx = file->private_data;
732 ret = spu_acquire(ctx);
736 mbox_stat = ctx->ops->mbox_stat_read(ctx) & 0xff;
740 if (copy_to_user(buf, &mbox_stat, sizeof mbox_stat))
746 static const struct file_operations spufs_mbox_stat_fops = {
747 .open = spufs_pipe_open,
748 .read = spufs_mbox_stat_read,
752 /* low-level ibox access function */
753 size_t spu_ibox_read(struct spu_context *ctx, u32 *data)
755 return ctx->ops->ibox_read(ctx, data);
758 static int spufs_ibox_fasync(int fd, struct file *file, int on)
760 struct spu_context *ctx = file->private_data;
762 return fasync_helper(fd, file, on, &ctx->ibox_fasync);
765 /* interrupt-level ibox callback function. */
766 void spufs_ibox_callback(struct spu *spu)
768 struct spu_context *ctx = spu->ctx;
773 wake_up_all(&ctx->ibox_wq);
774 kill_fasync(&ctx->ibox_fasync, SIGIO, POLLIN);
778 * Read as many bytes from the interrupt mailbox as possible, until
779 * one of the conditions becomes true:
781 * - no more data available in the mailbox
782 * - end of the user provided buffer
783 * - end of the mapped area
785 * If the file is opened without O_NONBLOCK, we wait here until
786 * any data is available, but return when we have been able to
789 static ssize_t spufs_ibox_read(struct file *file, char __user *buf,
790 size_t len, loff_t *pos)
792 struct spu_context *ctx = file->private_data;
793 u32 ibox_data, __user *udata;
799 if (!access_ok(VERIFY_WRITE, buf, len))
802 udata = (void __user *)buf;
804 count = spu_acquire(ctx);
808 /* wait only for the first element */
810 if (file->f_flags & O_NONBLOCK) {
811 if (!spu_ibox_read(ctx, &ibox_data)) {
816 count = spufs_wait(ctx->ibox_wq, spu_ibox_read(ctx, &ibox_data));
821 /* if we can't write at all, return -EFAULT */
822 count = __put_user(ibox_data, udata);
826 for (count = 4, udata++; (count + 4) <= len; count += 4, udata++) {
828 ret = ctx->ops->ibox_read(ctx, &ibox_data);
832 * at the end of the mapped area, we can fault
833 * but still need to return the data we have
834 * read successfully so far.
836 ret = __put_user(ibox_data, udata);
847 static unsigned int spufs_ibox_poll(struct file *file, poll_table *wait)
849 struct spu_context *ctx = file->private_data;
852 poll_wait(file, &ctx->ibox_wq, wait);
855 * For now keep this uninterruptible and also ignore the rule
856 * that poll should not sleep. Will be fixed later.
858 mutex_lock(&ctx->state_mutex);
859 mask = ctx->ops->mbox_stat_poll(ctx, POLLIN | POLLRDNORM);
865 static const struct file_operations spufs_ibox_fops = {
866 .open = spufs_pipe_open,
867 .read = spufs_ibox_read,
868 .poll = spufs_ibox_poll,
869 .fasync = spufs_ibox_fasync,
873 static ssize_t spufs_ibox_stat_read(struct file *file, char __user *buf,
874 size_t len, loff_t *pos)
876 struct spu_context *ctx = file->private_data;
883 ret = spu_acquire(ctx);
886 ibox_stat = (ctx->ops->mbox_stat_read(ctx) >> 16) & 0xff;
889 if (copy_to_user(buf, &ibox_stat, sizeof ibox_stat))
895 static const struct file_operations spufs_ibox_stat_fops = {
896 .open = spufs_pipe_open,
897 .read = spufs_ibox_stat_read,
901 /* low-level mailbox write */
902 size_t spu_wbox_write(struct spu_context *ctx, u32 data)
904 return ctx->ops->wbox_write(ctx, data);
907 static int spufs_wbox_fasync(int fd, struct file *file, int on)
909 struct spu_context *ctx = file->private_data;
912 ret = fasync_helper(fd, file, on, &ctx->wbox_fasync);
917 /* interrupt-level wbox callback function. */
918 void spufs_wbox_callback(struct spu *spu)
920 struct spu_context *ctx = spu->ctx;
925 wake_up_all(&ctx->wbox_wq);
926 kill_fasync(&ctx->wbox_fasync, SIGIO, POLLOUT);
930 * Write as many bytes to the interrupt mailbox as possible, until
931 * one of the conditions becomes true:
933 * - the mailbox is full
934 * - end of the user provided buffer
935 * - end of the mapped area
937 * If the file is opened without O_NONBLOCK, we wait here until
938 * space is availabyl, but return when we have been able to
941 static ssize_t spufs_wbox_write(struct file *file, const char __user *buf,
942 size_t len, loff_t *pos)
944 struct spu_context *ctx = file->private_data;
945 u32 wbox_data, __user *udata;
951 udata = (void __user *)buf;
952 if (!access_ok(VERIFY_READ, buf, len))
955 if (__get_user(wbox_data, udata))
958 count = spu_acquire(ctx);
963 * make sure we can at least write one element, by waiting
964 * in case of !O_NONBLOCK
967 if (file->f_flags & O_NONBLOCK) {
968 if (!spu_wbox_write(ctx, wbox_data)) {
973 count = spufs_wait(ctx->wbox_wq, spu_wbox_write(ctx, wbox_data));
979 /* write as much as possible */
980 for (count = 4, udata++; (count + 4) <= len; count += 4, udata++) {
982 ret = __get_user(wbox_data, udata);
986 ret = spu_wbox_write(ctx, wbox_data);
997 static unsigned int spufs_wbox_poll(struct file *file, poll_table *wait)
999 struct spu_context *ctx = file->private_data;
1002 poll_wait(file, &ctx->wbox_wq, wait);
1005 * For now keep this uninterruptible and also ignore the rule
1006 * that poll should not sleep. Will be fixed later.
1008 mutex_lock(&ctx->state_mutex);
1009 mask = ctx->ops->mbox_stat_poll(ctx, POLLOUT | POLLWRNORM);
1015 static const struct file_operations spufs_wbox_fops = {
1016 .open = spufs_pipe_open,
1017 .write = spufs_wbox_write,
1018 .poll = spufs_wbox_poll,
1019 .fasync = spufs_wbox_fasync,
1020 .llseek = no_llseek,
1023 static ssize_t spufs_wbox_stat_read(struct file *file, char __user *buf,
1024 size_t len, loff_t *pos)
1026 struct spu_context *ctx = file->private_data;
1033 ret = spu_acquire(ctx);
1036 wbox_stat = (ctx->ops->mbox_stat_read(ctx) >> 8) & 0xff;
1039 if (copy_to_user(buf, &wbox_stat, sizeof wbox_stat))
1045 static const struct file_operations spufs_wbox_stat_fops = {
1046 .open = spufs_pipe_open,
1047 .read = spufs_wbox_stat_read,
1048 .llseek = no_llseek,
1051 static int spufs_signal1_open(struct inode *inode, struct file *file)
1053 struct spufs_inode_info *i = SPUFS_I(inode);
1054 struct spu_context *ctx = i->i_ctx;
1056 mutex_lock(&ctx->mapping_lock);
1057 file->private_data = ctx;
1058 if (!i->i_openers++)
1059 ctx->signal1 = inode->i_mapping;
1060 mutex_unlock(&ctx->mapping_lock);
1061 return nonseekable_open(inode, file);
1065 spufs_signal1_release(struct inode *inode, struct file *file)
1067 struct spufs_inode_info *i = SPUFS_I(inode);
1068 struct spu_context *ctx = i->i_ctx;
1070 mutex_lock(&ctx->mapping_lock);
1071 if (!--i->i_openers)
1072 ctx->signal1 = NULL;
1073 mutex_unlock(&ctx->mapping_lock);
1077 static ssize_t __spufs_signal1_read(struct spu_context *ctx, char __user *buf,
1078 size_t len, loff_t *pos)
1086 if (ctx->csa.spu_chnlcnt_RW[3]) {
1087 data = ctx->csa.spu_chnldata_RW[3];
1094 if (copy_to_user(buf, &data, 4))
1101 static ssize_t spufs_signal1_read(struct file *file, char __user *buf,
1102 size_t len, loff_t *pos)
1105 struct spu_context *ctx = file->private_data;
1107 ret = spu_acquire_saved(ctx);
1110 ret = __spufs_signal1_read(ctx, buf, len, pos);
1111 spu_release_saved(ctx);
1116 static ssize_t spufs_signal1_write(struct file *file, const char __user *buf,
1117 size_t len, loff_t *pos)
1119 struct spu_context *ctx;
1123 ctx = file->private_data;
1128 if (copy_from_user(&data, buf, 4))
1131 ret = spu_acquire(ctx);
1134 ctx->ops->signal1_write(ctx, data);
1141 spufs_signal1_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
1143 #if SPUFS_SIGNAL_MAP_SIZE == 0x1000
1144 return spufs_ps_fault(vma, vmf, 0x14000, SPUFS_SIGNAL_MAP_SIZE);
1145 #elif SPUFS_SIGNAL_MAP_SIZE == 0x10000
1146 /* For 64k pages, both signal1 and signal2 can be used to mmap the whole
1147 * signal 1 and 2 area
1149 return spufs_ps_fault(vma, vmf, 0x10000, SPUFS_SIGNAL_MAP_SIZE);
1151 #error unsupported page size
1155 static const struct vm_operations_struct spufs_signal1_mmap_vmops = {
1156 .fault = spufs_signal1_mmap_fault,
1159 static int spufs_signal1_mmap(struct file *file, struct vm_area_struct *vma)
1161 if (!(vma->vm_flags & VM_SHARED))
1164 vma->vm_flags |= VM_IO | VM_PFNMAP;
1165 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
1167 vma->vm_ops = &spufs_signal1_mmap_vmops;
1171 static const struct file_operations spufs_signal1_fops = {
1172 .open = spufs_signal1_open,
1173 .release = spufs_signal1_release,
1174 .read = spufs_signal1_read,
1175 .write = spufs_signal1_write,
1176 .mmap = spufs_signal1_mmap,
1177 .llseek = no_llseek,
1180 static const struct file_operations spufs_signal1_nosched_fops = {
1181 .open = spufs_signal1_open,
1182 .release = spufs_signal1_release,
1183 .write = spufs_signal1_write,
1184 .mmap = spufs_signal1_mmap,
1185 .llseek = no_llseek,
1188 static int spufs_signal2_open(struct inode *inode, struct file *file)
1190 struct spufs_inode_info *i = SPUFS_I(inode);
1191 struct spu_context *ctx = i->i_ctx;
1193 mutex_lock(&ctx->mapping_lock);
1194 file->private_data = ctx;
1195 if (!i->i_openers++)
1196 ctx->signal2 = inode->i_mapping;
1197 mutex_unlock(&ctx->mapping_lock);
1198 return nonseekable_open(inode, file);
1202 spufs_signal2_release(struct inode *inode, struct file *file)
1204 struct spufs_inode_info *i = SPUFS_I(inode);
1205 struct spu_context *ctx = i->i_ctx;
1207 mutex_lock(&ctx->mapping_lock);
1208 if (!--i->i_openers)
1209 ctx->signal2 = NULL;
1210 mutex_unlock(&ctx->mapping_lock);
1214 static ssize_t __spufs_signal2_read(struct spu_context *ctx, char __user *buf,
1215 size_t len, loff_t *pos)
1223 if (ctx->csa.spu_chnlcnt_RW[4]) {
1224 data = ctx->csa.spu_chnldata_RW[4];
1231 if (copy_to_user(buf, &data, 4))
1238 static ssize_t spufs_signal2_read(struct file *file, char __user *buf,
1239 size_t len, loff_t *pos)
1241 struct spu_context *ctx = file->private_data;
1244 ret = spu_acquire_saved(ctx);
1247 ret = __spufs_signal2_read(ctx, buf, len, pos);
1248 spu_release_saved(ctx);
1253 static ssize_t spufs_signal2_write(struct file *file, const char __user *buf,
1254 size_t len, loff_t *pos)
1256 struct spu_context *ctx;
1260 ctx = file->private_data;
1265 if (copy_from_user(&data, buf, 4))
1268 ret = spu_acquire(ctx);
1271 ctx->ops->signal2_write(ctx, data);
1279 spufs_signal2_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
1281 #if SPUFS_SIGNAL_MAP_SIZE == 0x1000
1282 return spufs_ps_fault(vma, vmf, 0x1c000, SPUFS_SIGNAL_MAP_SIZE);
1283 #elif SPUFS_SIGNAL_MAP_SIZE == 0x10000
1284 /* For 64k pages, both signal1 and signal2 can be used to mmap the whole
1285 * signal 1 and 2 area
1287 return spufs_ps_fault(vma, vmf, 0x10000, SPUFS_SIGNAL_MAP_SIZE);
1289 #error unsupported page size
1293 static const struct vm_operations_struct spufs_signal2_mmap_vmops = {
1294 .fault = spufs_signal2_mmap_fault,
1297 static int spufs_signal2_mmap(struct file *file, struct vm_area_struct *vma)
1299 if (!(vma->vm_flags & VM_SHARED))
1302 vma->vm_flags |= VM_IO | VM_PFNMAP;
1303 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
1305 vma->vm_ops = &spufs_signal2_mmap_vmops;
1308 #else /* SPUFS_MMAP_4K */
1309 #define spufs_signal2_mmap NULL
1310 #endif /* !SPUFS_MMAP_4K */
1312 static const struct file_operations spufs_signal2_fops = {
1313 .open = spufs_signal2_open,
1314 .release = spufs_signal2_release,
1315 .read = spufs_signal2_read,
1316 .write = spufs_signal2_write,
1317 .mmap = spufs_signal2_mmap,
1318 .llseek = no_llseek,
1321 static const struct file_operations spufs_signal2_nosched_fops = {
1322 .open = spufs_signal2_open,
1323 .release = spufs_signal2_release,
1324 .write = spufs_signal2_write,
1325 .mmap = spufs_signal2_mmap,
1326 .llseek = no_llseek,
1330 * This is a wrapper around DEFINE_SIMPLE_ATTRIBUTE which does the
1331 * work of acquiring (or not) the SPU context before calling through
1332 * to the actual get routine. The set routine is called directly.
1334 #define SPU_ATTR_NOACQUIRE 0
1335 #define SPU_ATTR_ACQUIRE 1
1336 #define SPU_ATTR_ACQUIRE_SAVED 2
1338 #define DEFINE_SPUFS_ATTRIBUTE(__name, __get, __set, __fmt, __acquire) \
1339 static int __##__get(void *data, u64 *val) \
1341 struct spu_context *ctx = data; \
1344 if (__acquire == SPU_ATTR_ACQUIRE) { \
1345 ret = spu_acquire(ctx); \
1348 *val = __get(ctx); \
1350 } else if (__acquire == SPU_ATTR_ACQUIRE_SAVED) { \
1351 ret = spu_acquire_saved(ctx); \
1354 *val = __get(ctx); \
1355 spu_release_saved(ctx); \
1357 *val = __get(ctx); \
1361 DEFINE_SPUFS_SIMPLE_ATTRIBUTE(__name, __##__get, __set, __fmt);
1363 static int spufs_signal1_type_set(void *data, u64 val)
1365 struct spu_context *ctx = data;
1368 ret = spu_acquire(ctx);
1371 ctx->ops->signal1_type_set(ctx, val);
1377 static u64 spufs_signal1_type_get(struct spu_context *ctx)
1379 return ctx->ops->signal1_type_get(ctx);
1381 DEFINE_SPUFS_ATTRIBUTE(spufs_signal1_type, spufs_signal1_type_get,
1382 spufs_signal1_type_set, "%llu\n", SPU_ATTR_ACQUIRE);
1385 static int spufs_signal2_type_set(void *data, u64 val)
1387 struct spu_context *ctx = data;
1390 ret = spu_acquire(ctx);
1393 ctx->ops->signal2_type_set(ctx, val);
1399 static u64 spufs_signal2_type_get(struct spu_context *ctx)
1401 return ctx->ops->signal2_type_get(ctx);
1403 DEFINE_SPUFS_ATTRIBUTE(spufs_signal2_type, spufs_signal2_type_get,
1404 spufs_signal2_type_set, "%llu\n", SPU_ATTR_ACQUIRE);
1408 spufs_mss_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
1410 return spufs_ps_fault(vma, vmf, 0x0000, SPUFS_MSS_MAP_SIZE);
1413 static const struct vm_operations_struct spufs_mss_mmap_vmops = {
1414 .fault = spufs_mss_mmap_fault,
1418 * mmap support for problem state MFC DMA area [0x0000 - 0x0fff].
1420 static int spufs_mss_mmap(struct file *file, struct vm_area_struct *vma)
1422 if (!(vma->vm_flags & VM_SHARED))
1425 vma->vm_flags |= VM_IO | VM_PFNMAP;
1426 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
1428 vma->vm_ops = &spufs_mss_mmap_vmops;
1431 #else /* SPUFS_MMAP_4K */
1432 #define spufs_mss_mmap NULL
1433 #endif /* !SPUFS_MMAP_4K */
1435 static int spufs_mss_open(struct inode *inode, struct file *file)
1437 struct spufs_inode_info *i = SPUFS_I(inode);
1438 struct spu_context *ctx = i->i_ctx;
1440 file->private_data = i->i_ctx;
1442 mutex_lock(&ctx->mapping_lock);
1443 if (!i->i_openers++)
1444 ctx->mss = inode->i_mapping;
1445 mutex_unlock(&ctx->mapping_lock);
1446 return nonseekable_open(inode, file);
1450 spufs_mss_release(struct inode *inode, struct file *file)
1452 struct spufs_inode_info *i = SPUFS_I(inode);
1453 struct spu_context *ctx = i->i_ctx;
1455 mutex_lock(&ctx->mapping_lock);
1456 if (!--i->i_openers)
1458 mutex_unlock(&ctx->mapping_lock);
1462 static const struct file_operations spufs_mss_fops = {
1463 .open = spufs_mss_open,
1464 .release = spufs_mss_release,
1465 .mmap = spufs_mss_mmap,
1466 .llseek = no_llseek,
1470 spufs_psmap_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
1472 return spufs_ps_fault(vma, vmf, 0x0000, SPUFS_PS_MAP_SIZE);
1475 static const struct vm_operations_struct spufs_psmap_mmap_vmops = {
1476 .fault = spufs_psmap_mmap_fault,
1480 * mmap support for full problem state area [0x00000 - 0x1ffff].
1482 static int spufs_psmap_mmap(struct file *file, struct vm_area_struct *vma)
1484 if (!(vma->vm_flags & VM_SHARED))
1487 vma->vm_flags |= VM_IO | VM_PFNMAP;
1488 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
1490 vma->vm_ops = &spufs_psmap_mmap_vmops;
1494 static int spufs_psmap_open(struct inode *inode, struct file *file)
1496 struct spufs_inode_info *i = SPUFS_I(inode);
1497 struct spu_context *ctx = i->i_ctx;
1499 mutex_lock(&ctx->mapping_lock);
1500 file->private_data = i->i_ctx;
1501 if (!i->i_openers++)
1502 ctx->psmap = inode->i_mapping;
1503 mutex_unlock(&ctx->mapping_lock);
1504 return nonseekable_open(inode, file);
1508 spufs_psmap_release(struct inode *inode, struct file *file)
1510 struct spufs_inode_info *i = SPUFS_I(inode);
1511 struct spu_context *ctx = i->i_ctx;
1513 mutex_lock(&ctx->mapping_lock);
1514 if (!--i->i_openers)
1516 mutex_unlock(&ctx->mapping_lock);
1520 static const struct file_operations spufs_psmap_fops = {
1521 .open = spufs_psmap_open,
1522 .release = spufs_psmap_release,
1523 .mmap = spufs_psmap_mmap,
1524 .llseek = no_llseek,
1530 spufs_mfc_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
1532 return spufs_ps_fault(vma, vmf, 0x3000, SPUFS_MFC_MAP_SIZE);
1535 static const struct vm_operations_struct spufs_mfc_mmap_vmops = {
1536 .fault = spufs_mfc_mmap_fault,
1540 * mmap support for problem state MFC DMA area [0x0000 - 0x0fff].
1542 static int spufs_mfc_mmap(struct file *file, struct vm_area_struct *vma)
1544 if (!(vma->vm_flags & VM_SHARED))
1547 vma->vm_flags |= VM_IO | VM_PFNMAP;
1548 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
1550 vma->vm_ops = &spufs_mfc_mmap_vmops;
1553 #else /* SPUFS_MMAP_4K */
1554 #define spufs_mfc_mmap NULL
1555 #endif /* !SPUFS_MMAP_4K */
1557 static int spufs_mfc_open(struct inode *inode, struct file *file)
1559 struct spufs_inode_info *i = SPUFS_I(inode);
1560 struct spu_context *ctx = i->i_ctx;
1562 /* we don't want to deal with DMA into other processes */
1563 if (ctx->owner != current->mm)
1566 if (atomic_read(&inode->i_count) != 1)
1569 mutex_lock(&ctx->mapping_lock);
1570 file->private_data = ctx;
1571 if (!i->i_openers++)
1572 ctx->mfc = inode->i_mapping;
1573 mutex_unlock(&ctx->mapping_lock);
1574 return nonseekable_open(inode, file);
1578 spufs_mfc_release(struct inode *inode, struct file *file)
1580 struct spufs_inode_info *i = SPUFS_I(inode);
1581 struct spu_context *ctx = i->i_ctx;
1583 mutex_lock(&ctx->mapping_lock);
1584 if (!--i->i_openers)
1586 mutex_unlock(&ctx->mapping_lock);
1590 /* interrupt-level mfc callback function. */
1591 void spufs_mfc_callback(struct spu *spu)
1593 struct spu_context *ctx = spu->ctx;
1598 wake_up_all(&ctx->mfc_wq);
1600 pr_debug("%s %s\n", __func__, spu->name);
1601 if (ctx->mfc_fasync) {
1602 u32 free_elements, tagstatus;
1605 /* no need for spu_acquire in interrupt context */
1606 free_elements = ctx->ops->get_mfc_free_elements(ctx);
1607 tagstatus = ctx->ops->read_mfc_tagstatus(ctx);
1610 if (free_elements & 0xffff)
1612 if (tagstatus & ctx->tagwait)
1615 kill_fasync(&ctx->mfc_fasync, SIGIO, mask);
1619 static int spufs_read_mfc_tagstatus(struct spu_context *ctx, u32 *status)
1621 /* See if there is one tag group is complete */
1622 /* FIXME we need locking around tagwait */
1623 *status = ctx->ops->read_mfc_tagstatus(ctx) & ctx->tagwait;
1624 ctx->tagwait &= ~*status;
1628 /* enable interrupt waiting for any tag group,
1629 may silently fail if interrupts are already enabled */
1630 ctx->ops->set_mfc_query(ctx, ctx->tagwait, 1);
1634 static ssize_t spufs_mfc_read(struct file *file, char __user *buffer,
1635 size_t size, loff_t *pos)
1637 struct spu_context *ctx = file->private_data;
1644 ret = spu_acquire(ctx);
1649 if (file->f_flags & O_NONBLOCK) {
1650 status = ctx->ops->read_mfc_tagstatus(ctx);
1651 if (!(status & ctx->tagwait))
1654 /* XXX(hch): shouldn't we clear ret here? */
1655 ctx->tagwait &= ~status;
1657 ret = spufs_wait(ctx->mfc_wq,
1658 spufs_read_mfc_tagstatus(ctx, &status));
1665 if (copy_to_user(buffer, &status, 4))
1672 static int spufs_check_valid_dma(struct mfc_dma_command *cmd)
1674 pr_debug("queueing DMA %x %llx %x %x %x\n", cmd->lsa,
1675 cmd->ea, cmd->size, cmd->tag, cmd->cmd);
1686 pr_debug("invalid DMA opcode %x\n", cmd->cmd);
1690 if ((cmd->lsa & 0xf) != (cmd->ea &0xf)) {
1691 pr_debug("invalid DMA alignment, ea %llx lsa %x\n",
1696 switch (cmd->size & 0xf) {
1717 pr_debug("invalid DMA alignment %x for size %x\n",
1718 cmd->lsa & 0xf, cmd->size);
1722 if (cmd->size > 16 * 1024) {
1723 pr_debug("invalid DMA size %x\n", cmd->size);
1727 if (cmd->tag & 0xfff0) {
1728 /* we reserve the higher tag numbers for kernel use */
1729 pr_debug("invalid DMA tag\n");
1734 /* not supported in this version */
1735 pr_debug("invalid DMA class\n");
1742 static int spu_send_mfc_command(struct spu_context *ctx,
1743 struct mfc_dma_command cmd,
1746 *error = ctx->ops->send_mfc_command(ctx, &cmd);
1747 if (*error == -EAGAIN) {
1748 /* wait for any tag group to complete
1749 so we have space for the new command */
1750 ctx->ops->set_mfc_query(ctx, ctx->tagwait, 1);
1751 /* try again, because the queue might be
1753 *error = ctx->ops->send_mfc_command(ctx, &cmd);
1754 if (*error == -EAGAIN)
1760 static ssize_t spufs_mfc_write(struct file *file, const char __user *buffer,
1761 size_t size, loff_t *pos)
1763 struct spu_context *ctx = file->private_data;
1764 struct mfc_dma_command cmd;
1767 if (size != sizeof cmd)
1771 if (copy_from_user(&cmd, buffer, sizeof cmd))
1774 ret = spufs_check_valid_dma(&cmd);
1778 ret = spu_acquire(ctx);
1782 ret = spufs_wait(ctx->run_wq, ctx->state == SPU_STATE_RUNNABLE);
1786 if (file->f_flags & O_NONBLOCK) {
1787 ret = ctx->ops->send_mfc_command(ctx, &cmd);
1790 ret = spufs_wait(ctx->mfc_wq,
1791 spu_send_mfc_command(ctx, cmd, &status));
1801 ctx->tagwait |= 1 << cmd.tag;
1810 static unsigned int spufs_mfc_poll(struct file *file,poll_table *wait)
1812 struct spu_context *ctx = file->private_data;
1813 u32 free_elements, tagstatus;
1816 poll_wait(file, &ctx->mfc_wq, wait);
1819 * For now keep this uninterruptible and also ignore the rule
1820 * that poll should not sleep. Will be fixed later.
1822 mutex_lock(&ctx->state_mutex);
1823 ctx->ops->set_mfc_query(ctx, ctx->tagwait, 2);
1824 free_elements = ctx->ops->get_mfc_free_elements(ctx);
1825 tagstatus = ctx->ops->read_mfc_tagstatus(ctx);
1829 if (free_elements & 0xffff)
1830 mask |= POLLOUT | POLLWRNORM;
1831 if (tagstatus & ctx->tagwait)
1832 mask |= POLLIN | POLLRDNORM;
1834 pr_debug("%s: free %d tagstatus %d tagwait %d\n", __func__,
1835 free_elements, tagstatus, ctx->tagwait);
1840 static int spufs_mfc_flush(struct file *file, fl_owner_t id)
1842 struct spu_context *ctx = file->private_data;
1845 ret = spu_acquire(ctx);
1849 /* this currently hangs */
1850 ret = spufs_wait(ctx->mfc_wq,
1851 ctx->ops->set_mfc_query(ctx, ctx->tagwait, 2));
1854 ret = spufs_wait(ctx->mfc_wq,
1855 ctx->ops->read_mfc_tagstatus(ctx) == ctx->tagwait);
1866 static int spufs_mfc_fsync(struct file *file, int datasync)
1868 return spufs_mfc_flush(file, NULL);
1871 static int spufs_mfc_fasync(int fd, struct file *file, int on)
1873 struct spu_context *ctx = file->private_data;
1875 return fasync_helper(fd, file, on, &ctx->mfc_fasync);
1878 static const struct file_operations spufs_mfc_fops = {
1879 .open = spufs_mfc_open,
1880 .release = spufs_mfc_release,
1881 .read = spufs_mfc_read,
1882 .write = spufs_mfc_write,
1883 .poll = spufs_mfc_poll,
1884 .flush = spufs_mfc_flush,
1885 .fsync = spufs_mfc_fsync,
1886 .fasync = spufs_mfc_fasync,
1887 .mmap = spufs_mfc_mmap,
1888 .llseek = no_llseek,
1891 static int spufs_npc_set(void *data, u64 val)
1893 struct spu_context *ctx = data;
1896 ret = spu_acquire(ctx);
1899 ctx->ops->npc_write(ctx, val);
1905 static u64 spufs_npc_get(struct spu_context *ctx)
1907 return ctx->ops->npc_read(ctx);
1909 DEFINE_SPUFS_ATTRIBUTE(spufs_npc_ops, spufs_npc_get, spufs_npc_set,
1910 "0x%llx\n", SPU_ATTR_ACQUIRE);
1912 static int spufs_decr_set(void *data, u64 val)
1914 struct spu_context *ctx = data;
1915 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1918 ret = spu_acquire_saved(ctx);
1921 lscsa->decr.slot[0] = (u32) val;
1922 spu_release_saved(ctx);
1927 static u64 spufs_decr_get(struct spu_context *ctx)
1929 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1930 return lscsa->decr.slot[0];
1932 DEFINE_SPUFS_ATTRIBUTE(spufs_decr_ops, spufs_decr_get, spufs_decr_set,
1933 "0x%llx\n", SPU_ATTR_ACQUIRE_SAVED);
1935 static int spufs_decr_status_set(void *data, u64 val)
1937 struct spu_context *ctx = data;
1940 ret = spu_acquire_saved(ctx);
1944 ctx->csa.priv2.mfc_control_RW |= MFC_CNTL_DECREMENTER_RUNNING;
1946 ctx->csa.priv2.mfc_control_RW &= ~MFC_CNTL_DECREMENTER_RUNNING;
1947 spu_release_saved(ctx);
1952 static u64 spufs_decr_status_get(struct spu_context *ctx)
1954 if (ctx->csa.priv2.mfc_control_RW & MFC_CNTL_DECREMENTER_RUNNING)
1955 return SPU_DECR_STATUS_RUNNING;
1959 DEFINE_SPUFS_ATTRIBUTE(spufs_decr_status_ops, spufs_decr_status_get,
1960 spufs_decr_status_set, "0x%llx\n",
1961 SPU_ATTR_ACQUIRE_SAVED);
1963 static int spufs_event_mask_set(void *data, u64 val)
1965 struct spu_context *ctx = data;
1966 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1969 ret = spu_acquire_saved(ctx);
1972 lscsa->event_mask.slot[0] = (u32) val;
1973 spu_release_saved(ctx);
1978 static u64 spufs_event_mask_get(struct spu_context *ctx)
1980 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1981 return lscsa->event_mask.slot[0];
1984 DEFINE_SPUFS_ATTRIBUTE(spufs_event_mask_ops, spufs_event_mask_get,
1985 spufs_event_mask_set, "0x%llx\n",
1986 SPU_ATTR_ACQUIRE_SAVED);
1988 static u64 spufs_event_status_get(struct spu_context *ctx)
1990 struct spu_state *state = &ctx->csa;
1992 stat = state->spu_chnlcnt_RW[0];
1994 return state->spu_chnldata_RW[0];
1997 DEFINE_SPUFS_ATTRIBUTE(spufs_event_status_ops, spufs_event_status_get,
1998 NULL, "0x%llx\n", SPU_ATTR_ACQUIRE_SAVED)
2000 static int spufs_srr0_set(void *data, u64 val)
2002 struct spu_context *ctx = data;
2003 struct spu_lscsa *lscsa = ctx->csa.lscsa;
2006 ret = spu_acquire_saved(ctx);
2009 lscsa->srr0.slot[0] = (u32) val;
2010 spu_release_saved(ctx);
2015 static u64 spufs_srr0_get(struct spu_context *ctx)
2017 struct spu_lscsa *lscsa = ctx->csa.lscsa;
2018 return lscsa->srr0.slot[0];
2020 DEFINE_SPUFS_ATTRIBUTE(spufs_srr0_ops, spufs_srr0_get, spufs_srr0_set,
2021 "0x%llx\n", SPU_ATTR_ACQUIRE_SAVED)
2023 static u64 spufs_id_get(struct spu_context *ctx)
2027 if (ctx->state == SPU_STATE_RUNNABLE)
2028 num = ctx->spu->number;
2030 num = (unsigned int)-1;
2034 DEFINE_SPUFS_ATTRIBUTE(spufs_id_ops, spufs_id_get, NULL, "0x%llx\n",
2037 static u64 spufs_object_id_get(struct spu_context *ctx)
2039 /* FIXME: Should there really be no locking here? */
2040 return ctx->object_id;
2043 static int spufs_object_id_set(void *data, u64 id)
2045 struct spu_context *ctx = data;
2046 ctx->object_id = id;
2051 DEFINE_SPUFS_ATTRIBUTE(spufs_object_id_ops, spufs_object_id_get,
2052 spufs_object_id_set, "0x%llx\n", SPU_ATTR_NOACQUIRE);
2054 static u64 spufs_lslr_get(struct spu_context *ctx)
2056 return ctx->csa.priv2.spu_lslr_RW;
2058 DEFINE_SPUFS_ATTRIBUTE(spufs_lslr_ops, spufs_lslr_get, NULL, "0x%llx\n",
2059 SPU_ATTR_ACQUIRE_SAVED);
2061 static int spufs_info_open(struct inode *inode, struct file *file)
2063 struct spufs_inode_info *i = SPUFS_I(inode);
2064 struct spu_context *ctx = i->i_ctx;
2065 file->private_data = ctx;
2069 static int spufs_caps_show(struct seq_file *s, void *private)
2071 struct spu_context *ctx = s->private;
2073 if (!(ctx->flags & SPU_CREATE_NOSCHED))
2074 seq_puts(s, "sched\n");
2075 if (!(ctx->flags & SPU_CREATE_ISOLATE))
2076 seq_puts(s, "step\n");
2080 static int spufs_caps_open(struct inode *inode, struct file *file)
2082 return single_open(file, spufs_caps_show, SPUFS_I(inode)->i_ctx);
2085 static const struct file_operations spufs_caps_fops = {
2086 .open = spufs_caps_open,
2088 .llseek = seq_lseek,
2089 .release = single_release,
2092 static ssize_t __spufs_mbox_info_read(struct spu_context *ctx,
2093 char __user *buf, size_t len, loff_t *pos)
2097 /* EOF if there's no entry in the mbox */
2098 if (!(ctx->csa.prob.mb_stat_R & 0x0000ff))
2101 data = ctx->csa.prob.pu_mb_R;
2103 return simple_read_from_buffer(buf, len, pos, &data, sizeof data);
2106 static ssize_t spufs_mbox_info_read(struct file *file, char __user *buf,
2107 size_t len, loff_t *pos)
2110 struct spu_context *ctx = file->private_data;
2112 if (!access_ok(VERIFY_WRITE, buf, len))
2115 ret = spu_acquire_saved(ctx);
2118 spin_lock(&ctx->csa.register_lock);
2119 ret = __spufs_mbox_info_read(ctx, buf, len, pos);
2120 spin_unlock(&ctx->csa.register_lock);
2121 spu_release_saved(ctx);
2126 static const struct file_operations spufs_mbox_info_fops = {
2127 .open = spufs_info_open,
2128 .read = spufs_mbox_info_read,
2129 .llseek = generic_file_llseek,
2132 static ssize_t __spufs_ibox_info_read(struct spu_context *ctx,
2133 char __user *buf, size_t len, loff_t *pos)
2137 /* EOF if there's no entry in the ibox */
2138 if (!(ctx->csa.prob.mb_stat_R & 0xff0000))
2141 data = ctx->csa.priv2.puint_mb_R;
2143 return simple_read_from_buffer(buf, len, pos, &data, sizeof data);
2146 static ssize_t spufs_ibox_info_read(struct file *file, char __user *buf,
2147 size_t len, loff_t *pos)
2149 struct spu_context *ctx = file->private_data;
2152 if (!access_ok(VERIFY_WRITE, buf, len))
2155 ret = spu_acquire_saved(ctx);
2158 spin_lock(&ctx->csa.register_lock);
2159 ret = __spufs_ibox_info_read(ctx, buf, len, pos);
2160 spin_unlock(&ctx->csa.register_lock);
2161 spu_release_saved(ctx);
2166 static const struct file_operations spufs_ibox_info_fops = {
2167 .open = spufs_info_open,
2168 .read = spufs_ibox_info_read,
2169 .llseek = generic_file_llseek,
2172 static ssize_t __spufs_wbox_info_read(struct spu_context *ctx,
2173 char __user *buf, size_t len, loff_t *pos)
2179 wbox_stat = ctx->csa.prob.mb_stat_R;
2180 cnt = 4 - ((wbox_stat & 0x00ff00) >> 8);
2181 for (i = 0; i < cnt; i++) {
2182 data[i] = ctx->csa.spu_mailbox_data[i];
2185 return simple_read_from_buffer(buf, len, pos, &data,
2189 static ssize_t spufs_wbox_info_read(struct file *file, char __user *buf,
2190 size_t len, loff_t *pos)
2192 struct spu_context *ctx = file->private_data;
2195 if (!access_ok(VERIFY_WRITE, buf, len))
2198 ret = spu_acquire_saved(ctx);
2201 spin_lock(&ctx->csa.register_lock);
2202 ret = __spufs_wbox_info_read(ctx, buf, len, pos);
2203 spin_unlock(&ctx->csa.register_lock);
2204 spu_release_saved(ctx);
2209 static const struct file_operations spufs_wbox_info_fops = {
2210 .open = spufs_info_open,
2211 .read = spufs_wbox_info_read,
2212 .llseek = generic_file_llseek,
2215 static ssize_t __spufs_dma_info_read(struct spu_context *ctx,
2216 char __user *buf, size_t len, loff_t *pos)
2218 struct spu_dma_info info;
2219 struct mfc_cq_sr *qp, *spuqp;
2222 info.dma_info_type = ctx->csa.priv2.spu_tag_status_query_RW;
2223 info.dma_info_mask = ctx->csa.lscsa->tag_mask.slot[0];
2224 info.dma_info_status = ctx->csa.spu_chnldata_RW[24];
2225 info.dma_info_stall_and_notify = ctx->csa.spu_chnldata_RW[25];
2226 info.dma_info_atomic_command_status = ctx->csa.spu_chnldata_RW[27];
2227 for (i = 0; i < 16; i++) {
2228 qp = &info.dma_info_command_data[i];
2229 spuqp = &ctx->csa.priv2.spuq[i];
2231 qp->mfc_cq_data0_RW = spuqp->mfc_cq_data0_RW;
2232 qp->mfc_cq_data1_RW = spuqp->mfc_cq_data1_RW;
2233 qp->mfc_cq_data2_RW = spuqp->mfc_cq_data2_RW;
2234 qp->mfc_cq_data3_RW = spuqp->mfc_cq_data3_RW;
2237 return simple_read_from_buffer(buf, len, pos, &info,
2241 static ssize_t spufs_dma_info_read(struct file *file, char __user *buf,
2242 size_t len, loff_t *pos)
2244 struct spu_context *ctx = file->private_data;
2247 if (!access_ok(VERIFY_WRITE, buf, len))
2250 ret = spu_acquire_saved(ctx);
2253 spin_lock(&ctx->csa.register_lock);
2254 ret = __spufs_dma_info_read(ctx, buf, len, pos);
2255 spin_unlock(&ctx->csa.register_lock);
2256 spu_release_saved(ctx);
2261 static const struct file_operations spufs_dma_info_fops = {
2262 .open = spufs_info_open,
2263 .read = spufs_dma_info_read,
2264 .llseek = no_llseek,
2267 static ssize_t __spufs_proxydma_info_read(struct spu_context *ctx,
2268 char __user *buf, size_t len, loff_t *pos)
2270 struct spu_proxydma_info info;
2271 struct mfc_cq_sr *qp, *puqp;
2272 int ret = sizeof info;
2278 if (!access_ok(VERIFY_WRITE, buf, len))
2281 info.proxydma_info_type = ctx->csa.prob.dma_querytype_RW;
2282 info.proxydma_info_mask = ctx->csa.prob.dma_querymask_RW;
2283 info.proxydma_info_status = ctx->csa.prob.dma_tagstatus_R;
2284 for (i = 0; i < 8; i++) {
2285 qp = &info.proxydma_info_command_data[i];
2286 puqp = &ctx->csa.priv2.puq[i];
2288 qp->mfc_cq_data0_RW = puqp->mfc_cq_data0_RW;
2289 qp->mfc_cq_data1_RW = puqp->mfc_cq_data1_RW;
2290 qp->mfc_cq_data2_RW = puqp->mfc_cq_data2_RW;
2291 qp->mfc_cq_data3_RW = puqp->mfc_cq_data3_RW;
2294 return simple_read_from_buffer(buf, len, pos, &info,
2298 static ssize_t spufs_proxydma_info_read(struct file *file, char __user *buf,
2299 size_t len, loff_t *pos)
2301 struct spu_context *ctx = file->private_data;
2304 ret = spu_acquire_saved(ctx);
2307 spin_lock(&ctx->csa.register_lock);
2308 ret = __spufs_proxydma_info_read(ctx, buf, len, pos);
2309 spin_unlock(&ctx->csa.register_lock);
2310 spu_release_saved(ctx);
2315 static const struct file_operations spufs_proxydma_info_fops = {
2316 .open = spufs_info_open,
2317 .read = spufs_proxydma_info_read,
2318 .llseek = no_llseek,
2321 static int spufs_show_tid(struct seq_file *s, void *private)
2323 struct spu_context *ctx = s->private;
2325 seq_printf(s, "%d\n", ctx->tid);
2329 static int spufs_tid_open(struct inode *inode, struct file *file)
2331 return single_open(file, spufs_show_tid, SPUFS_I(inode)->i_ctx);
2334 static const struct file_operations spufs_tid_fops = {
2335 .open = spufs_tid_open,
2337 .llseek = seq_lseek,
2338 .release = single_release,
2341 static const char *ctx_state_names[] = {
2342 "user", "system", "iowait", "loaded"
2345 static unsigned long long spufs_acct_time(struct spu_context *ctx,
2346 enum spu_utilization_state state)
2349 unsigned long long time = ctx->stats.times[state];
2352 * In general, utilization statistics are updated by the controlling
2353 * thread as the spu context moves through various well defined
2354 * state transitions, but if the context is lazily loaded its
2355 * utilization statistics are not updated as the controlling thread
2356 * is not tightly coupled with the execution of the spu context. We
2357 * calculate and apply the time delta from the last recorded state
2358 * of the spu context.
2360 if (ctx->spu && ctx->stats.util_state == state) {
2362 time += timespec_to_ns(&ts) - ctx->stats.tstamp;
2365 return time / NSEC_PER_MSEC;
2368 static unsigned long long spufs_slb_flts(struct spu_context *ctx)
2370 unsigned long long slb_flts = ctx->stats.slb_flt;
2372 if (ctx->state == SPU_STATE_RUNNABLE) {
2373 slb_flts += (ctx->spu->stats.slb_flt -
2374 ctx->stats.slb_flt_base);
2380 static unsigned long long spufs_class2_intrs(struct spu_context *ctx)
2382 unsigned long long class2_intrs = ctx->stats.class2_intr;
2384 if (ctx->state == SPU_STATE_RUNNABLE) {
2385 class2_intrs += (ctx->spu->stats.class2_intr -
2386 ctx->stats.class2_intr_base);
2389 return class2_intrs;
2393 static int spufs_show_stat(struct seq_file *s, void *private)
2395 struct spu_context *ctx = s->private;
2398 ret = spu_acquire(ctx);
2402 seq_printf(s, "%s %llu %llu %llu %llu "
2403 "%llu %llu %llu %llu %llu %llu %llu %llu\n",
2404 ctx_state_names[ctx->stats.util_state],
2405 spufs_acct_time(ctx, SPU_UTIL_USER),
2406 spufs_acct_time(ctx, SPU_UTIL_SYSTEM),
2407 spufs_acct_time(ctx, SPU_UTIL_IOWAIT),
2408 spufs_acct_time(ctx, SPU_UTIL_IDLE_LOADED),
2409 ctx->stats.vol_ctx_switch,
2410 ctx->stats.invol_ctx_switch,
2411 spufs_slb_flts(ctx),
2412 ctx->stats.hash_flt,
2415 spufs_class2_intrs(ctx),
2416 ctx->stats.libassist);
2421 static int spufs_stat_open(struct inode *inode, struct file *file)
2423 return single_open(file, spufs_show_stat, SPUFS_I(inode)->i_ctx);
2426 static const struct file_operations spufs_stat_fops = {
2427 .open = spufs_stat_open,
2429 .llseek = seq_lseek,
2430 .release = single_release,
2433 static inline int spufs_switch_log_used(struct spu_context *ctx)
2435 return (ctx->switch_log->head - ctx->switch_log->tail) %
2439 static inline int spufs_switch_log_avail(struct spu_context *ctx)
2441 return SWITCH_LOG_BUFSIZE - spufs_switch_log_used(ctx);
2444 static int spufs_switch_log_open(struct inode *inode, struct file *file)
2446 struct spu_context *ctx = SPUFS_I(inode)->i_ctx;
2449 rc = spu_acquire(ctx);
2453 if (ctx->switch_log) {
2458 ctx->switch_log = kmalloc(sizeof(struct switch_log) +
2459 SWITCH_LOG_BUFSIZE * sizeof(struct switch_log_entry),
2462 if (!ctx->switch_log) {
2467 ctx->switch_log->head = ctx->switch_log->tail = 0;
2468 init_waitqueue_head(&ctx->switch_log->wait);
2476 static int spufs_switch_log_release(struct inode *inode, struct file *file)
2478 struct spu_context *ctx = SPUFS_I(inode)->i_ctx;
2481 rc = spu_acquire(ctx);
2485 kfree(ctx->switch_log);
2486 ctx->switch_log = NULL;
2492 static int switch_log_sprint(struct spu_context *ctx, char *tbuf, int n)
2494 struct switch_log_entry *p;
2496 p = ctx->switch_log->log + ctx->switch_log->tail % SWITCH_LOG_BUFSIZE;
2498 return snprintf(tbuf, n, "%u.%09u %d %u %u %llu\n",
2499 (unsigned int) p->tstamp.tv_sec,
2500 (unsigned int) p->tstamp.tv_nsec,
2502 (unsigned int) p->type,
2503 (unsigned int) p->val,
2504 (unsigned long long) p->timebase);
2507 static ssize_t spufs_switch_log_read(struct file *file, char __user *buf,
2508 size_t len, loff_t *ppos)
2510 struct inode *inode = file->f_path.dentry->d_inode;
2511 struct spu_context *ctx = SPUFS_I(inode)->i_ctx;
2512 int error = 0, cnt = 0;
2517 error = spu_acquire(ctx);
2525 if (spufs_switch_log_used(ctx) == 0) {
2527 /* If there's data ready to go, we can
2528 * just return straight away */
2531 } else if (file->f_flags & O_NONBLOCK) {
2536 /* spufs_wait will drop the mutex and
2537 * re-acquire, but since we're in read(), the
2538 * file cannot be _released (and so
2539 * ctx->switch_log is stable).
2541 error = spufs_wait(ctx->switch_log->wait,
2542 spufs_switch_log_used(ctx) > 0);
2544 /* On error, spufs_wait returns without the
2545 * state mutex held */
2549 /* We may have had entries read from underneath
2550 * us while we dropped the mutex in spufs_wait,
2552 if (spufs_switch_log_used(ctx) == 0)
2557 width = switch_log_sprint(ctx, tbuf, sizeof(tbuf));
2559 ctx->switch_log->tail =
2560 (ctx->switch_log->tail + 1) %
2563 /* If the record is greater than space available return
2564 * partial buffer (so far) */
2567 error = copy_to_user(buf + cnt, tbuf, width);
2575 return cnt == 0 ? error : cnt;
2578 static unsigned int spufs_switch_log_poll(struct file *file, poll_table *wait)
2580 struct inode *inode = file->f_path.dentry->d_inode;
2581 struct spu_context *ctx = SPUFS_I(inode)->i_ctx;
2582 unsigned int mask = 0;
2585 poll_wait(file, &ctx->switch_log->wait, wait);
2587 rc = spu_acquire(ctx);
2591 if (spufs_switch_log_used(ctx) > 0)
2599 static const struct file_operations spufs_switch_log_fops = {
2600 .owner = THIS_MODULE,
2601 .open = spufs_switch_log_open,
2602 .read = spufs_switch_log_read,
2603 .poll = spufs_switch_log_poll,
2604 .release = spufs_switch_log_release,
2605 .llseek = no_llseek,
2609 * Log a context switch event to a switch log reader.
2611 * Must be called with ctx->state_mutex held.
2613 void spu_switch_log_notify(struct spu *spu, struct spu_context *ctx,
2616 if (!ctx->switch_log)
2619 if (spufs_switch_log_avail(ctx) > 1) {
2620 struct switch_log_entry *p;
2622 p = ctx->switch_log->log + ctx->switch_log->head;
2623 ktime_get_ts(&p->tstamp);
2624 p->timebase = get_tb();
2625 p->spu_id = spu ? spu->number : -1;
2629 ctx->switch_log->head =
2630 (ctx->switch_log->head + 1) % SWITCH_LOG_BUFSIZE;
2633 wake_up(&ctx->switch_log->wait);
2636 static int spufs_show_ctx(struct seq_file *s, void *private)
2638 struct spu_context *ctx = s->private;
2641 mutex_lock(&ctx->state_mutex);
2643 struct spu *spu = ctx->spu;
2644 struct spu_priv2 __iomem *priv2 = spu->priv2;
2646 spin_lock_irq(&spu->register_lock);
2647 mfc_control_RW = in_be64(&priv2->mfc_control_RW);
2648 spin_unlock_irq(&spu->register_lock);
2650 struct spu_state *csa = &ctx->csa;
2652 mfc_control_RW = csa->priv2.mfc_control_RW;
2655 seq_printf(s, "%c flgs(%lx) sflgs(%lx) pri(%d) ts(%d) spu(%02d)"
2656 " %c %llx %llx %llx %llx %x %x\n",
2657 ctx->state == SPU_STATE_SAVED ? 'S' : 'R',
2662 ctx->spu ? ctx->spu->number : -1,
2663 !list_empty(&ctx->rq) ? 'q' : ' ',
2664 ctx->csa.class_0_pending,
2665 ctx->csa.class_0_dar,
2666 ctx->csa.class_1_dsisr,
2668 ctx->ops->runcntl_read(ctx),
2669 ctx->ops->status_read(ctx));
2671 mutex_unlock(&ctx->state_mutex);
2676 static int spufs_ctx_open(struct inode *inode, struct file *file)
2678 return single_open(file, spufs_show_ctx, SPUFS_I(inode)->i_ctx);
2681 static const struct file_operations spufs_ctx_fops = {
2682 .open = spufs_ctx_open,
2684 .llseek = seq_lseek,
2685 .release = single_release,
2688 const struct spufs_tree_descr spufs_dir_contents[] = {
2689 { "capabilities", &spufs_caps_fops, 0444, },
2690 { "mem", &spufs_mem_fops, 0666, LS_SIZE, },
2691 { "regs", &spufs_regs_fops, 0666, sizeof(struct spu_reg128[128]), },
2692 { "mbox", &spufs_mbox_fops, 0444, },
2693 { "ibox", &spufs_ibox_fops, 0444, },
2694 { "wbox", &spufs_wbox_fops, 0222, },
2695 { "mbox_stat", &spufs_mbox_stat_fops, 0444, sizeof(u32), },
2696 { "ibox_stat", &spufs_ibox_stat_fops, 0444, sizeof(u32), },
2697 { "wbox_stat", &spufs_wbox_stat_fops, 0444, sizeof(u32), },
2698 { "signal1", &spufs_signal1_fops, 0666, },
2699 { "signal2", &spufs_signal2_fops, 0666, },
2700 { "signal1_type", &spufs_signal1_type, 0666, },
2701 { "signal2_type", &spufs_signal2_type, 0666, },
2702 { "cntl", &spufs_cntl_fops, 0666, },
2703 { "fpcr", &spufs_fpcr_fops, 0666, sizeof(struct spu_reg128), },
2704 { "lslr", &spufs_lslr_ops, 0444, },
2705 { "mfc", &spufs_mfc_fops, 0666, },
2706 { "mss", &spufs_mss_fops, 0666, },
2707 { "npc", &spufs_npc_ops, 0666, },
2708 { "srr0", &spufs_srr0_ops, 0666, },
2709 { "decr", &spufs_decr_ops, 0666, },
2710 { "decr_status", &spufs_decr_status_ops, 0666, },
2711 { "event_mask", &spufs_event_mask_ops, 0666, },
2712 { "event_status", &spufs_event_status_ops, 0444, },
2713 { "psmap", &spufs_psmap_fops, 0666, SPUFS_PS_MAP_SIZE, },
2714 { "phys-id", &spufs_id_ops, 0666, },
2715 { "object-id", &spufs_object_id_ops, 0666, },
2716 { "mbox_info", &spufs_mbox_info_fops, 0444, sizeof(u32), },
2717 { "ibox_info", &spufs_ibox_info_fops, 0444, sizeof(u32), },
2718 { "wbox_info", &spufs_wbox_info_fops, 0444, sizeof(u32), },
2719 { "dma_info", &spufs_dma_info_fops, 0444,
2720 sizeof(struct spu_dma_info), },
2721 { "proxydma_info", &spufs_proxydma_info_fops, 0444,
2722 sizeof(struct spu_proxydma_info)},
2723 { "tid", &spufs_tid_fops, 0444, },
2724 { "stat", &spufs_stat_fops, 0444, },
2725 { "switch_log", &spufs_switch_log_fops, 0444 },
2729 const struct spufs_tree_descr spufs_dir_nosched_contents[] = {
2730 { "capabilities", &spufs_caps_fops, 0444, },
2731 { "mem", &spufs_mem_fops, 0666, LS_SIZE, },
2732 { "mbox", &spufs_mbox_fops, 0444, },
2733 { "ibox", &spufs_ibox_fops, 0444, },
2734 { "wbox", &spufs_wbox_fops, 0222, },
2735 { "mbox_stat", &spufs_mbox_stat_fops, 0444, sizeof(u32), },
2736 { "ibox_stat", &spufs_ibox_stat_fops, 0444, sizeof(u32), },
2737 { "wbox_stat", &spufs_wbox_stat_fops, 0444, sizeof(u32), },
2738 { "signal1", &spufs_signal1_nosched_fops, 0222, },
2739 { "signal2", &spufs_signal2_nosched_fops, 0222, },
2740 { "signal1_type", &spufs_signal1_type, 0666, },
2741 { "signal2_type", &spufs_signal2_type, 0666, },
2742 { "mss", &spufs_mss_fops, 0666, },
2743 { "mfc", &spufs_mfc_fops, 0666, },
2744 { "cntl", &spufs_cntl_fops, 0666, },
2745 { "npc", &spufs_npc_ops, 0666, },
2746 { "psmap", &spufs_psmap_fops, 0666, SPUFS_PS_MAP_SIZE, },
2747 { "phys-id", &spufs_id_ops, 0666, },
2748 { "object-id", &spufs_object_id_ops, 0666, },
2749 { "tid", &spufs_tid_fops, 0444, },
2750 { "stat", &spufs_stat_fops, 0444, },
2754 const struct spufs_tree_descr spufs_dir_debug_contents[] = {
2755 { ".ctx", &spufs_ctx_fops, 0444, },
2759 const struct spufs_coredump_reader spufs_coredump_read[] = {
2760 { "regs", __spufs_regs_read, NULL, sizeof(struct spu_reg128[128])},
2761 { "fpcr", __spufs_fpcr_read, NULL, sizeof(struct spu_reg128) },
2762 { "lslr", NULL, spufs_lslr_get, 19 },
2763 { "decr", NULL, spufs_decr_get, 19 },
2764 { "decr_status", NULL, spufs_decr_status_get, 19 },
2765 { "mem", __spufs_mem_read, NULL, LS_SIZE, },
2766 { "signal1", __spufs_signal1_read, NULL, sizeof(u32) },
2767 { "signal1_type", NULL, spufs_signal1_type_get, 19 },
2768 { "signal2", __spufs_signal2_read, NULL, sizeof(u32) },
2769 { "signal2_type", NULL, spufs_signal2_type_get, 19 },
2770 { "event_mask", NULL, spufs_event_mask_get, 19 },
2771 { "event_status", NULL, spufs_event_status_get, 19 },
2772 { "mbox_info", __spufs_mbox_info_read, NULL, sizeof(u32) },
2773 { "ibox_info", __spufs_ibox_info_read, NULL, sizeof(u32) },
2774 { "wbox_info", __spufs_wbox_info_read, NULL, 4 * sizeof(u32)},
2775 { "dma_info", __spufs_dma_info_read, NULL, sizeof(struct spu_dma_info)},
2776 { "proxydma_info", __spufs_proxydma_info_read,
2777 NULL, sizeof(struct spu_proxydma_info)},
2778 { "object-id", NULL, spufs_object_id_get, 19 },
2779 { "npc", NULL, spufs_npc_get, 19 },