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 /* pre-check for file position: if we'd return EOF, there's no point
552 * causing a deschedule */
553 if (*pos >= sizeof(ctx->csa.lscsa->gprs))
556 ret = spu_acquire_saved(ctx);
559 ret = __spufs_regs_read(ctx, buffer, size, pos);
560 spu_release_saved(ctx);
565 spufs_regs_write(struct file *file, const char __user *buffer,
566 size_t size, loff_t *pos)
568 struct spu_context *ctx = file->private_data;
569 struct spu_lscsa *lscsa = ctx->csa.lscsa;
572 size = min_t(ssize_t, sizeof lscsa->gprs - *pos, size);
577 ret = spu_acquire_saved(ctx);
581 ret = copy_from_user(lscsa->gprs + *pos - size,
582 buffer, size) ? -EFAULT : size;
584 spu_release_saved(ctx);
588 static const struct file_operations spufs_regs_fops = {
589 .open = spufs_regs_open,
590 .read = spufs_regs_read,
591 .write = spufs_regs_write,
592 .llseek = generic_file_llseek,
596 __spufs_fpcr_read(struct spu_context *ctx, char __user * buffer,
597 size_t size, loff_t * pos)
599 struct spu_lscsa *lscsa = ctx->csa.lscsa;
600 return simple_read_from_buffer(buffer, size, pos,
601 &lscsa->fpcr, sizeof(lscsa->fpcr));
605 spufs_fpcr_read(struct file *file, char __user * buffer,
606 size_t size, loff_t * pos)
609 struct spu_context *ctx = file->private_data;
611 ret = spu_acquire_saved(ctx);
614 ret = __spufs_fpcr_read(ctx, buffer, size, pos);
615 spu_release_saved(ctx);
620 spufs_fpcr_write(struct file *file, const char __user * buffer,
621 size_t size, loff_t * pos)
623 struct spu_context *ctx = file->private_data;
624 struct spu_lscsa *lscsa = ctx->csa.lscsa;
627 size = min_t(ssize_t, sizeof(lscsa->fpcr) - *pos, size);
631 ret = spu_acquire_saved(ctx);
636 ret = copy_from_user((char *)&lscsa->fpcr + *pos - size,
637 buffer, size) ? -EFAULT : size;
639 spu_release_saved(ctx);
643 static const struct file_operations spufs_fpcr_fops = {
644 .open = spufs_regs_open,
645 .read = spufs_fpcr_read,
646 .write = spufs_fpcr_write,
647 .llseek = generic_file_llseek,
650 /* generic open function for all pipe-like files */
651 static int spufs_pipe_open(struct inode *inode, struct file *file)
653 struct spufs_inode_info *i = SPUFS_I(inode);
654 file->private_data = i->i_ctx;
656 return nonseekable_open(inode, file);
660 * Read as many bytes from the mailbox as possible, until
661 * one of the conditions becomes true:
663 * - no more data available in the mailbox
664 * - end of the user provided buffer
665 * - end of the mapped area
667 static ssize_t spufs_mbox_read(struct file *file, char __user *buf,
668 size_t len, loff_t *pos)
670 struct spu_context *ctx = file->private_data;
671 u32 mbox_data, __user *udata;
677 if (!access_ok(VERIFY_WRITE, buf, len))
680 udata = (void __user *)buf;
682 count = spu_acquire(ctx);
686 for (count = 0; (count + 4) <= len; count += 4, udata++) {
688 ret = ctx->ops->mbox_read(ctx, &mbox_data);
693 * at the end of the mapped area, we can fault
694 * but still need to return the data we have
695 * read successfully so far.
697 ret = __put_user(mbox_data, udata);
712 static const struct file_operations spufs_mbox_fops = {
713 .open = spufs_pipe_open,
714 .read = spufs_mbox_read,
717 static ssize_t spufs_mbox_stat_read(struct file *file, char __user *buf,
718 size_t len, loff_t *pos)
720 struct spu_context *ctx = file->private_data;
727 ret = spu_acquire(ctx);
731 mbox_stat = ctx->ops->mbox_stat_read(ctx) & 0xff;
735 if (copy_to_user(buf, &mbox_stat, sizeof mbox_stat))
741 static const struct file_operations spufs_mbox_stat_fops = {
742 .open = spufs_pipe_open,
743 .read = spufs_mbox_stat_read,
746 /* low-level ibox access function */
747 size_t spu_ibox_read(struct spu_context *ctx, u32 *data)
749 return ctx->ops->ibox_read(ctx, data);
752 static int spufs_ibox_fasync(int fd, struct file *file, int on)
754 struct spu_context *ctx = file->private_data;
756 return fasync_helper(fd, file, on, &ctx->ibox_fasync);
759 /* interrupt-level ibox callback function. */
760 void spufs_ibox_callback(struct spu *spu)
762 struct spu_context *ctx = spu->ctx;
767 wake_up_all(&ctx->ibox_wq);
768 kill_fasync(&ctx->ibox_fasync, SIGIO, POLLIN);
772 * Read as many bytes from the interrupt mailbox as possible, until
773 * one of the conditions becomes true:
775 * - no more data available in the mailbox
776 * - end of the user provided buffer
777 * - end of the mapped area
779 * If the file is opened without O_NONBLOCK, we wait here until
780 * any data is available, but return when we have been able to
783 static ssize_t spufs_ibox_read(struct file *file, char __user *buf,
784 size_t len, loff_t *pos)
786 struct spu_context *ctx = file->private_data;
787 u32 ibox_data, __user *udata;
793 if (!access_ok(VERIFY_WRITE, buf, len))
796 udata = (void __user *)buf;
798 count = spu_acquire(ctx);
802 /* wait only for the first element */
804 if (file->f_flags & O_NONBLOCK) {
805 if (!spu_ibox_read(ctx, &ibox_data)) {
810 count = spufs_wait(ctx->ibox_wq, spu_ibox_read(ctx, &ibox_data));
815 /* if we can't write at all, return -EFAULT */
816 count = __put_user(ibox_data, udata);
820 for (count = 4, udata++; (count + 4) <= len; count += 4, udata++) {
822 ret = ctx->ops->ibox_read(ctx, &ibox_data);
826 * at the end of the mapped area, we can fault
827 * but still need to return the data we have
828 * read successfully so far.
830 ret = __put_user(ibox_data, udata);
841 static unsigned int spufs_ibox_poll(struct file *file, poll_table *wait)
843 struct spu_context *ctx = file->private_data;
846 poll_wait(file, &ctx->ibox_wq, wait);
849 * For now keep this uninterruptible and also ignore the rule
850 * that poll should not sleep. Will be fixed later.
852 mutex_lock(&ctx->state_mutex);
853 mask = ctx->ops->mbox_stat_poll(ctx, POLLIN | POLLRDNORM);
859 static const struct file_operations spufs_ibox_fops = {
860 .open = spufs_pipe_open,
861 .read = spufs_ibox_read,
862 .poll = spufs_ibox_poll,
863 .fasync = spufs_ibox_fasync,
866 static ssize_t spufs_ibox_stat_read(struct file *file, char __user *buf,
867 size_t len, loff_t *pos)
869 struct spu_context *ctx = file->private_data;
876 ret = spu_acquire(ctx);
879 ibox_stat = (ctx->ops->mbox_stat_read(ctx) >> 16) & 0xff;
882 if (copy_to_user(buf, &ibox_stat, sizeof ibox_stat))
888 static const struct file_operations spufs_ibox_stat_fops = {
889 .open = spufs_pipe_open,
890 .read = spufs_ibox_stat_read,
893 /* low-level mailbox write */
894 size_t spu_wbox_write(struct spu_context *ctx, u32 data)
896 return ctx->ops->wbox_write(ctx, data);
899 static int spufs_wbox_fasync(int fd, struct file *file, int on)
901 struct spu_context *ctx = file->private_data;
904 ret = fasync_helper(fd, file, on, &ctx->wbox_fasync);
909 /* interrupt-level wbox callback function. */
910 void spufs_wbox_callback(struct spu *spu)
912 struct spu_context *ctx = spu->ctx;
917 wake_up_all(&ctx->wbox_wq);
918 kill_fasync(&ctx->wbox_fasync, SIGIO, POLLOUT);
922 * Write as many bytes to the interrupt mailbox as possible, until
923 * one of the conditions becomes true:
925 * - the mailbox is full
926 * - end of the user provided buffer
927 * - end of the mapped area
929 * If the file is opened without O_NONBLOCK, we wait here until
930 * space is availabyl, but return when we have been able to
933 static ssize_t spufs_wbox_write(struct file *file, const char __user *buf,
934 size_t len, loff_t *pos)
936 struct spu_context *ctx = file->private_data;
937 u32 wbox_data, __user *udata;
943 udata = (void __user *)buf;
944 if (!access_ok(VERIFY_READ, buf, len))
947 if (__get_user(wbox_data, udata))
950 count = spu_acquire(ctx);
955 * make sure we can at least write one element, by waiting
956 * in case of !O_NONBLOCK
959 if (file->f_flags & O_NONBLOCK) {
960 if (!spu_wbox_write(ctx, wbox_data)) {
965 count = spufs_wait(ctx->wbox_wq, spu_wbox_write(ctx, wbox_data));
971 /* write as much as possible */
972 for (count = 4, udata++; (count + 4) <= len; count += 4, udata++) {
974 ret = __get_user(wbox_data, udata);
978 ret = spu_wbox_write(ctx, wbox_data);
989 static unsigned int spufs_wbox_poll(struct file *file, poll_table *wait)
991 struct spu_context *ctx = file->private_data;
994 poll_wait(file, &ctx->wbox_wq, wait);
997 * For now keep this uninterruptible and also ignore the rule
998 * that poll should not sleep. Will be fixed later.
1000 mutex_lock(&ctx->state_mutex);
1001 mask = ctx->ops->mbox_stat_poll(ctx, POLLOUT | POLLWRNORM);
1007 static const struct file_operations spufs_wbox_fops = {
1008 .open = spufs_pipe_open,
1009 .write = spufs_wbox_write,
1010 .poll = spufs_wbox_poll,
1011 .fasync = spufs_wbox_fasync,
1014 static ssize_t spufs_wbox_stat_read(struct file *file, char __user *buf,
1015 size_t len, loff_t *pos)
1017 struct spu_context *ctx = file->private_data;
1024 ret = spu_acquire(ctx);
1027 wbox_stat = (ctx->ops->mbox_stat_read(ctx) >> 8) & 0xff;
1030 if (copy_to_user(buf, &wbox_stat, sizeof wbox_stat))
1036 static const struct file_operations spufs_wbox_stat_fops = {
1037 .open = spufs_pipe_open,
1038 .read = spufs_wbox_stat_read,
1041 static int spufs_signal1_open(struct inode *inode, struct file *file)
1043 struct spufs_inode_info *i = SPUFS_I(inode);
1044 struct spu_context *ctx = i->i_ctx;
1046 mutex_lock(&ctx->mapping_lock);
1047 file->private_data = ctx;
1048 if (!i->i_openers++)
1049 ctx->signal1 = inode->i_mapping;
1050 mutex_unlock(&ctx->mapping_lock);
1051 return nonseekable_open(inode, file);
1055 spufs_signal1_release(struct inode *inode, struct file *file)
1057 struct spufs_inode_info *i = SPUFS_I(inode);
1058 struct spu_context *ctx = i->i_ctx;
1060 mutex_lock(&ctx->mapping_lock);
1061 if (!--i->i_openers)
1062 ctx->signal1 = NULL;
1063 mutex_unlock(&ctx->mapping_lock);
1067 static ssize_t __spufs_signal1_read(struct spu_context *ctx, char __user *buf,
1068 size_t len, loff_t *pos)
1076 if (ctx->csa.spu_chnlcnt_RW[3]) {
1077 data = ctx->csa.spu_chnldata_RW[3];
1084 if (copy_to_user(buf, &data, 4))
1091 static ssize_t spufs_signal1_read(struct file *file, char __user *buf,
1092 size_t len, loff_t *pos)
1095 struct spu_context *ctx = file->private_data;
1097 ret = spu_acquire_saved(ctx);
1100 ret = __spufs_signal1_read(ctx, buf, len, pos);
1101 spu_release_saved(ctx);
1106 static ssize_t spufs_signal1_write(struct file *file, const char __user *buf,
1107 size_t len, loff_t *pos)
1109 struct spu_context *ctx;
1113 ctx = file->private_data;
1118 if (copy_from_user(&data, buf, 4))
1121 ret = spu_acquire(ctx);
1124 ctx->ops->signal1_write(ctx, data);
1131 spufs_signal1_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
1133 #if SPUFS_SIGNAL_MAP_SIZE == 0x1000
1134 return spufs_ps_fault(vma, vmf, 0x14000, SPUFS_SIGNAL_MAP_SIZE);
1135 #elif SPUFS_SIGNAL_MAP_SIZE == 0x10000
1136 /* For 64k pages, both signal1 and signal2 can be used to mmap the whole
1137 * signal 1 and 2 area
1139 return spufs_ps_fault(vma, vmf, 0x10000, SPUFS_SIGNAL_MAP_SIZE);
1141 #error unsupported page size
1145 static struct vm_operations_struct spufs_signal1_mmap_vmops = {
1146 .fault = spufs_signal1_mmap_fault,
1149 static int spufs_signal1_mmap(struct file *file, struct vm_area_struct *vma)
1151 if (!(vma->vm_flags & VM_SHARED))
1154 vma->vm_flags |= VM_IO | VM_PFNMAP;
1155 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
1156 | _PAGE_NO_CACHE | _PAGE_GUARDED);
1158 vma->vm_ops = &spufs_signal1_mmap_vmops;
1162 static const struct file_operations spufs_signal1_fops = {
1163 .open = spufs_signal1_open,
1164 .release = spufs_signal1_release,
1165 .read = spufs_signal1_read,
1166 .write = spufs_signal1_write,
1167 .mmap = spufs_signal1_mmap,
1170 static const struct file_operations spufs_signal1_nosched_fops = {
1171 .open = spufs_signal1_open,
1172 .release = spufs_signal1_release,
1173 .write = spufs_signal1_write,
1174 .mmap = spufs_signal1_mmap,
1177 static int spufs_signal2_open(struct inode *inode, struct file *file)
1179 struct spufs_inode_info *i = SPUFS_I(inode);
1180 struct spu_context *ctx = i->i_ctx;
1182 mutex_lock(&ctx->mapping_lock);
1183 file->private_data = ctx;
1184 if (!i->i_openers++)
1185 ctx->signal2 = inode->i_mapping;
1186 mutex_unlock(&ctx->mapping_lock);
1187 return nonseekable_open(inode, file);
1191 spufs_signal2_release(struct inode *inode, struct file *file)
1193 struct spufs_inode_info *i = SPUFS_I(inode);
1194 struct spu_context *ctx = i->i_ctx;
1196 mutex_lock(&ctx->mapping_lock);
1197 if (!--i->i_openers)
1198 ctx->signal2 = NULL;
1199 mutex_unlock(&ctx->mapping_lock);
1203 static ssize_t __spufs_signal2_read(struct spu_context *ctx, char __user *buf,
1204 size_t len, loff_t *pos)
1212 if (ctx->csa.spu_chnlcnt_RW[4]) {
1213 data = ctx->csa.spu_chnldata_RW[4];
1220 if (copy_to_user(buf, &data, 4))
1227 static ssize_t spufs_signal2_read(struct file *file, char __user *buf,
1228 size_t len, loff_t *pos)
1230 struct spu_context *ctx = file->private_data;
1233 ret = spu_acquire_saved(ctx);
1236 ret = __spufs_signal2_read(ctx, buf, len, pos);
1237 spu_release_saved(ctx);
1242 static ssize_t spufs_signal2_write(struct file *file, const char __user *buf,
1243 size_t len, loff_t *pos)
1245 struct spu_context *ctx;
1249 ctx = file->private_data;
1254 if (copy_from_user(&data, buf, 4))
1257 ret = spu_acquire(ctx);
1260 ctx->ops->signal2_write(ctx, data);
1268 spufs_signal2_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
1270 #if SPUFS_SIGNAL_MAP_SIZE == 0x1000
1271 return spufs_ps_fault(vma, vmf, 0x1c000, SPUFS_SIGNAL_MAP_SIZE);
1272 #elif SPUFS_SIGNAL_MAP_SIZE == 0x10000
1273 /* For 64k pages, both signal1 and signal2 can be used to mmap the whole
1274 * signal 1 and 2 area
1276 return spufs_ps_fault(vma, vmf, 0x10000, SPUFS_SIGNAL_MAP_SIZE);
1278 #error unsupported page size
1282 static struct vm_operations_struct spufs_signal2_mmap_vmops = {
1283 .fault = spufs_signal2_mmap_fault,
1286 static int spufs_signal2_mmap(struct file *file, struct vm_area_struct *vma)
1288 if (!(vma->vm_flags & VM_SHARED))
1291 vma->vm_flags |= VM_IO | VM_PFNMAP;
1292 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
1293 | _PAGE_NO_CACHE | _PAGE_GUARDED);
1295 vma->vm_ops = &spufs_signal2_mmap_vmops;
1298 #else /* SPUFS_MMAP_4K */
1299 #define spufs_signal2_mmap NULL
1300 #endif /* !SPUFS_MMAP_4K */
1302 static const struct file_operations spufs_signal2_fops = {
1303 .open = spufs_signal2_open,
1304 .release = spufs_signal2_release,
1305 .read = spufs_signal2_read,
1306 .write = spufs_signal2_write,
1307 .mmap = spufs_signal2_mmap,
1310 static const struct file_operations spufs_signal2_nosched_fops = {
1311 .open = spufs_signal2_open,
1312 .release = spufs_signal2_release,
1313 .write = spufs_signal2_write,
1314 .mmap = spufs_signal2_mmap,
1318 * This is a wrapper around DEFINE_SIMPLE_ATTRIBUTE which does the
1319 * work of acquiring (or not) the SPU context before calling through
1320 * to the actual get routine. The set routine is called directly.
1322 #define SPU_ATTR_NOACQUIRE 0
1323 #define SPU_ATTR_ACQUIRE 1
1324 #define SPU_ATTR_ACQUIRE_SAVED 2
1326 #define DEFINE_SPUFS_ATTRIBUTE(__name, __get, __set, __fmt, __acquire) \
1327 static int __##__get(void *data, u64 *val) \
1329 struct spu_context *ctx = data; \
1332 if (__acquire == SPU_ATTR_ACQUIRE) { \
1333 ret = spu_acquire(ctx); \
1336 *val = __get(ctx); \
1338 } else if (__acquire == SPU_ATTR_ACQUIRE_SAVED) { \
1339 ret = spu_acquire_saved(ctx); \
1342 *val = __get(ctx); \
1343 spu_release_saved(ctx); \
1345 *val = __get(ctx); \
1349 DEFINE_SPUFS_SIMPLE_ATTRIBUTE(__name, __##__get, __set, __fmt);
1351 static int spufs_signal1_type_set(void *data, u64 val)
1353 struct spu_context *ctx = data;
1356 ret = spu_acquire(ctx);
1359 ctx->ops->signal1_type_set(ctx, val);
1365 static u64 spufs_signal1_type_get(struct spu_context *ctx)
1367 return ctx->ops->signal1_type_get(ctx);
1369 DEFINE_SPUFS_ATTRIBUTE(spufs_signal1_type, spufs_signal1_type_get,
1370 spufs_signal1_type_set, "%llu\n", SPU_ATTR_ACQUIRE);
1373 static int spufs_signal2_type_set(void *data, u64 val)
1375 struct spu_context *ctx = data;
1378 ret = spu_acquire(ctx);
1381 ctx->ops->signal2_type_set(ctx, val);
1387 static u64 spufs_signal2_type_get(struct spu_context *ctx)
1389 return ctx->ops->signal2_type_get(ctx);
1391 DEFINE_SPUFS_ATTRIBUTE(spufs_signal2_type, spufs_signal2_type_get,
1392 spufs_signal2_type_set, "%llu\n", SPU_ATTR_ACQUIRE);
1396 spufs_mss_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
1398 return spufs_ps_fault(vma, vmf, 0x0000, SPUFS_MSS_MAP_SIZE);
1401 static struct vm_operations_struct spufs_mss_mmap_vmops = {
1402 .fault = spufs_mss_mmap_fault,
1406 * mmap support for problem state MFC DMA area [0x0000 - 0x0fff].
1408 static int spufs_mss_mmap(struct file *file, struct vm_area_struct *vma)
1410 if (!(vma->vm_flags & VM_SHARED))
1413 vma->vm_flags |= VM_IO | VM_PFNMAP;
1414 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
1415 | _PAGE_NO_CACHE | _PAGE_GUARDED);
1417 vma->vm_ops = &spufs_mss_mmap_vmops;
1420 #else /* SPUFS_MMAP_4K */
1421 #define spufs_mss_mmap NULL
1422 #endif /* !SPUFS_MMAP_4K */
1424 static int spufs_mss_open(struct inode *inode, struct file *file)
1426 struct spufs_inode_info *i = SPUFS_I(inode);
1427 struct spu_context *ctx = i->i_ctx;
1429 file->private_data = i->i_ctx;
1431 mutex_lock(&ctx->mapping_lock);
1432 if (!i->i_openers++)
1433 ctx->mss = inode->i_mapping;
1434 mutex_unlock(&ctx->mapping_lock);
1435 return nonseekable_open(inode, file);
1439 spufs_mss_release(struct inode *inode, struct file *file)
1441 struct spufs_inode_info *i = SPUFS_I(inode);
1442 struct spu_context *ctx = i->i_ctx;
1444 mutex_lock(&ctx->mapping_lock);
1445 if (!--i->i_openers)
1447 mutex_unlock(&ctx->mapping_lock);
1451 static const struct file_operations spufs_mss_fops = {
1452 .open = spufs_mss_open,
1453 .release = spufs_mss_release,
1454 .mmap = spufs_mss_mmap,
1458 spufs_psmap_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
1460 return spufs_ps_fault(vma, vmf, 0x0000, SPUFS_PS_MAP_SIZE);
1463 static struct vm_operations_struct spufs_psmap_mmap_vmops = {
1464 .fault = spufs_psmap_mmap_fault,
1468 * mmap support for full problem state area [0x00000 - 0x1ffff].
1470 static int spufs_psmap_mmap(struct file *file, struct vm_area_struct *vma)
1472 if (!(vma->vm_flags & VM_SHARED))
1475 vma->vm_flags |= VM_IO | VM_PFNMAP;
1476 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
1477 | _PAGE_NO_CACHE | _PAGE_GUARDED);
1479 vma->vm_ops = &spufs_psmap_mmap_vmops;
1483 static int spufs_psmap_open(struct inode *inode, struct file *file)
1485 struct spufs_inode_info *i = SPUFS_I(inode);
1486 struct spu_context *ctx = i->i_ctx;
1488 mutex_lock(&ctx->mapping_lock);
1489 file->private_data = i->i_ctx;
1490 if (!i->i_openers++)
1491 ctx->psmap = inode->i_mapping;
1492 mutex_unlock(&ctx->mapping_lock);
1493 return nonseekable_open(inode, file);
1497 spufs_psmap_release(struct inode *inode, struct file *file)
1499 struct spufs_inode_info *i = SPUFS_I(inode);
1500 struct spu_context *ctx = i->i_ctx;
1502 mutex_lock(&ctx->mapping_lock);
1503 if (!--i->i_openers)
1505 mutex_unlock(&ctx->mapping_lock);
1509 static const struct file_operations spufs_psmap_fops = {
1510 .open = spufs_psmap_open,
1511 .release = spufs_psmap_release,
1512 .mmap = spufs_psmap_mmap,
1518 spufs_mfc_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
1520 return spufs_ps_fault(vma, vmf, 0x3000, SPUFS_MFC_MAP_SIZE);
1523 static struct vm_operations_struct spufs_mfc_mmap_vmops = {
1524 .fault = spufs_mfc_mmap_fault,
1528 * mmap support for problem state MFC DMA area [0x0000 - 0x0fff].
1530 static int spufs_mfc_mmap(struct file *file, struct vm_area_struct *vma)
1532 if (!(vma->vm_flags & VM_SHARED))
1535 vma->vm_flags |= VM_IO | VM_PFNMAP;
1536 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
1537 | _PAGE_NO_CACHE | _PAGE_GUARDED);
1539 vma->vm_ops = &spufs_mfc_mmap_vmops;
1542 #else /* SPUFS_MMAP_4K */
1543 #define spufs_mfc_mmap NULL
1544 #endif /* !SPUFS_MMAP_4K */
1546 static int spufs_mfc_open(struct inode *inode, struct file *file)
1548 struct spufs_inode_info *i = SPUFS_I(inode);
1549 struct spu_context *ctx = i->i_ctx;
1551 /* we don't want to deal with DMA into other processes */
1552 if (ctx->owner != current->mm)
1555 if (atomic_read(&inode->i_count) != 1)
1558 mutex_lock(&ctx->mapping_lock);
1559 file->private_data = ctx;
1560 if (!i->i_openers++)
1561 ctx->mfc = inode->i_mapping;
1562 mutex_unlock(&ctx->mapping_lock);
1563 return nonseekable_open(inode, file);
1567 spufs_mfc_release(struct inode *inode, struct file *file)
1569 struct spufs_inode_info *i = SPUFS_I(inode);
1570 struct spu_context *ctx = i->i_ctx;
1572 mutex_lock(&ctx->mapping_lock);
1573 if (!--i->i_openers)
1575 mutex_unlock(&ctx->mapping_lock);
1579 /* interrupt-level mfc callback function. */
1580 void spufs_mfc_callback(struct spu *spu)
1582 struct spu_context *ctx = spu->ctx;
1587 wake_up_all(&ctx->mfc_wq);
1589 pr_debug("%s %s\n", __func__, spu->name);
1590 if (ctx->mfc_fasync) {
1591 u32 free_elements, tagstatus;
1594 /* no need for spu_acquire in interrupt context */
1595 free_elements = ctx->ops->get_mfc_free_elements(ctx);
1596 tagstatus = ctx->ops->read_mfc_tagstatus(ctx);
1599 if (free_elements & 0xffff)
1601 if (tagstatus & ctx->tagwait)
1604 kill_fasync(&ctx->mfc_fasync, SIGIO, mask);
1608 static int spufs_read_mfc_tagstatus(struct spu_context *ctx, u32 *status)
1610 /* See if there is one tag group is complete */
1611 /* FIXME we need locking around tagwait */
1612 *status = ctx->ops->read_mfc_tagstatus(ctx) & ctx->tagwait;
1613 ctx->tagwait &= ~*status;
1617 /* enable interrupt waiting for any tag group,
1618 may silently fail if interrupts are already enabled */
1619 ctx->ops->set_mfc_query(ctx, ctx->tagwait, 1);
1623 static ssize_t spufs_mfc_read(struct file *file, char __user *buffer,
1624 size_t size, loff_t *pos)
1626 struct spu_context *ctx = file->private_data;
1633 ret = spu_acquire(ctx);
1638 if (file->f_flags & O_NONBLOCK) {
1639 status = ctx->ops->read_mfc_tagstatus(ctx);
1640 if (!(status & ctx->tagwait))
1643 /* XXX(hch): shouldn't we clear ret here? */
1644 ctx->tagwait &= ~status;
1646 ret = spufs_wait(ctx->mfc_wq,
1647 spufs_read_mfc_tagstatus(ctx, &status));
1654 if (copy_to_user(buffer, &status, 4))
1661 static int spufs_check_valid_dma(struct mfc_dma_command *cmd)
1663 pr_debug("queueing DMA %x %lx %x %x %x\n", cmd->lsa,
1664 cmd->ea, cmd->size, cmd->tag, cmd->cmd);
1675 pr_debug("invalid DMA opcode %x\n", cmd->cmd);
1679 if ((cmd->lsa & 0xf) != (cmd->ea &0xf)) {
1680 pr_debug("invalid DMA alignment, ea %lx lsa %x\n",
1685 switch (cmd->size & 0xf) {
1706 pr_debug("invalid DMA alignment %x for size %x\n",
1707 cmd->lsa & 0xf, cmd->size);
1711 if (cmd->size > 16 * 1024) {
1712 pr_debug("invalid DMA size %x\n", cmd->size);
1716 if (cmd->tag & 0xfff0) {
1717 /* we reserve the higher tag numbers for kernel use */
1718 pr_debug("invalid DMA tag\n");
1723 /* not supported in this version */
1724 pr_debug("invalid DMA class\n");
1731 static int spu_send_mfc_command(struct spu_context *ctx,
1732 struct mfc_dma_command cmd,
1735 *error = ctx->ops->send_mfc_command(ctx, &cmd);
1736 if (*error == -EAGAIN) {
1737 /* wait for any tag group to complete
1738 so we have space for the new command */
1739 ctx->ops->set_mfc_query(ctx, ctx->tagwait, 1);
1740 /* try again, because the queue might be
1742 *error = ctx->ops->send_mfc_command(ctx, &cmd);
1743 if (*error == -EAGAIN)
1749 static ssize_t spufs_mfc_write(struct file *file, const char __user *buffer,
1750 size_t size, loff_t *pos)
1752 struct spu_context *ctx = file->private_data;
1753 struct mfc_dma_command cmd;
1756 if (size != sizeof cmd)
1760 if (copy_from_user(&cmd, buffer, sizeof cmd))
1763 ret = spufs_check_valid_dma(&cmd);
1767 ret = spu_acquire(ctx);
1771 ret = spufs_wait(ctx->run_wq, ctx->state == SPU_STATE_RUNNABLE);
1775 if (file->f_flags & O_NONBLOCK) {
1776 ret = ctx->ops->send_mfc_command(ctx, &cmd);
1779 ret = spufs_wait(ctx->mfc_wq,
1780 spu_send_mfc_command(ctx, cmd, &status));
1790 ctx->tagwait |= 1 << cmd.tag;
1799 static unsigned int spufs_mfc_poll(struct file *file,poll_table *wait)
1801 struct spu_context *ctx = file->private_data;
1802 u32 free_elements, tagstatus;
1805 poll_wait(file, &ctx->mfc_wq, wait);
1808 * For now keep this uninterruptible and also ignore the rule
1809 * that poll should not sleep. Will be fixed later.
1811 mutex_lock(&ctx->state_mutex);
1812 ctx->ops->set_mfc_query(ctx, ctx->tagwait, 2);
1813 free_elements = ctx->ops->get_mfc_free_elements(ctx);
1814 tagstatus = ctx->ops->read_mfc_tagstatus(ctx);
1818 if (free_elements & 0xffff)
1819 mask |= POLLOUT | POLLWRNORM;
1820 if (tagstatus & ctx->tagwait)
1821 mask |= POLLIN | POLLRDNORM;
1823 pr_debug("%s: free %d tagstatus %d tagwait %d\n", __func__,
1824 free_elements, tagstatus, ctx->tagwait);
1829 static int spufs_mfc_flush(struct file *file, fl_owner_t id)
1831 struct spu_context *ctx = file->private_data;
1834 ret = spu_acquire(ctx);
1838 /* this currently hangs */
1839 ret = spufs_wait(ctx->mfc_wq,
1840 ctx->ops->set_mfc_query(ctx, ctx->tagwait, 2));
1843 ret = spufs_wait(ctx->mfc_wq,
1844 ctx->ops->read_mfc_tagstatus(ctx) == ctx->tagwait);
1855 static int spufs_mfc_fsync(struct file *file, struct dentry *dentry,
1858 return spufs_mfc_flush(file, NULL);
1861 static int spufs_mfc_fasync(int fd, struct file *file, int on)
1863 struct spu_context *ctx = file->private_data;
1865 return fasync_helper(fd, file, on, &ctx->mfc_fasync);
1868 static const struct file_operations spufs_mfc_fops = {
1869 .open = spufs_mfc_open,
1870 .release = spufs_mfc_release,
1871 .read = spufs_mfc_read,
1872 .write = spufs_mfc_write,
1873 .poll = spufs_mfc_poll,
1874 .flush = spufs_mfc_flush,
1875 .fsync = spufs_mfc_fsync,
1876 .fasync = spufs_mfc_fasync,
1877 .mmap = spufs_mfc_mmap,
1880 static int spufs_npc_set(void *data, u64 val)
1882 struct spu_context *ctx = data;
1885 ret = spu_acquire(ctx);
1888 ctx->ops->npc_write(ctx, val);
1894 static u64 spufs_npc_get(struct spu_context *ctx)
1896 return ctx->ops->npc_read(ctx);
1898 DEFINE_SPUFS_ATTRIBUTE(spufs_npc_ops, spufs_npc_get, spufs_npc_set,
1899 "0x%llx\n", SPU_ATTR_ACQUIRE);
1901 static int spufs_decr_set(void *data, u64 val)
1903 struct spu_context *ctx = data;
1904 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1907 ret = spu_acquire_saved(ctx);
1910 lscsa->decr.slot[0] = (u32) val;
1911 spu_release_saved(ctx);
1916 static u64 spufs_decr_get(struct spu_context *ctx)
1918 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1919 return lscsa->decr.slot[0];
1921 DEFINE_SPUFS_ATTRIBUTE(spufs_decr_ops, spufs_decr_get, spufs_decr_set,
1922 "0x%llx\n", SPU_ATTR_ACQUIRE_SAVED);
1924 static int spufs_decr_status_set(void *data, u64 val)
1926 struct spu_context *ctx = data;
1929 ret = spu_acquire_saved(ctx);
1933 ctx->csa.priv2.mfc_control_RW |= MFC_CNTL_DECREMENTER_RUNNING;
1935 ctx->csa.priv2.mfc_control_RW &= ~MFC_CNTL_DECREMENTER_RUNNING;
1936 spu_release_saved(ctx);
1941 static u64 spufs_decr_status_get(struct spu_context *ctx)
1943 if (ctx->csa.priv2.mfc_control_RW & MFC_CNTL_DECREMENTER_RUNNING)
1944 return SPU_DECR_STATUS_RUNNING;
1948 DEFINE_SPUFS_ATTRIBUTE(spufs_decr_status_ops, spufs_decr_status_get,
1949 spufs_decr_status_set, "0x%llx\n",
1950 SPU_ATTR_ACQUIRE_SAVED);
1952 static int spufs_event_mask_set(void *data, u64 val)
1954 struct spu_context *ctx = data;
1955 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1958 ret = spu_acquire_saved(ctx);
1961 lscsa->event_mask.slot[0] = (u32) val;
1962 spu_release_saved(ctx);
1967 static u64 spufs_event_mask_get(struct spu_context *ctx)
1969 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1970 return lscsa->event_mask.slot[0];
1973 DEFINE_SPUFS_ATTRIBUTE(spufs_event_mask_ops, spufs_event_mask_get,
1974 spufs_event_mask_set, "0x%llx\n",
1975 SPU_ATTR_ACQUIRE_SAVED);
1977 static u64 spufs_event_status_get(struct spu_context *ctx)
1979 struct spu_state *state = &ctx->csa;
1981 stat = state->spu_chnlcnt_RW[0];
1983 return state->spu_chnldata_RW[0];
1986 DEFINE_SPUFS_ATTRIBUTE(spufs_event_status_ops, spufs_event_status_get,
1987 NULL, "0x%llx\n", SPU_ATTR_ACQUIRE_SAVED)
1989 static int spufs_srr0_set(void *data, u64 val)
1991 struct spu_context *ctx = data;
1992 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1995 ret = spu_acquire_saved(ctx);
1998 lscsa->srr0.slot[0] = (u32) val;
1999 spu_release_saved(ctx);
2004 static u64 spufs_srr0_get(struct spu_context *ctx)
2006 struct spu_lscsa *lscsa = ctx->csa.lscsa;
2007 return lscsa->srr0.slot[0];
2009 DEFINE_SPUFS_ATTRIBUTE(spufs_srr0_ops, spufs_srr0_get, spufs_srr0_set,
2010 "0x%llx\n", SPU_ATTR_ACQUIRE_SAVED)
2012 static u64 spufs_id_get(struct spu_context *ctx)
2016 if (ctx->state == SPU_STATE_RUNNABLE)
2017 num = ctx->spu->number;
2019 num = (unsigned int)-1;
2023 DEFINE_SPUFS_ATTRIBUTE(spufs_id_ops, spufs_id_get, NULL, "0x%llx\n",
2026 static u64 spufs_object_id_get(struct spu_context *ctx)
2028 /* FIXME: Should there really be no locking here? */
2029 return ctx->object_id;
2032 static int spufs_object_id_set(void *data, u64 id)
2034 struct spu_context *ctx = data;
2035 ctx->object_id = id;
2040 DEFINE_SPUFS_ATTRIBUTE(spufs_object_id_ops, spufs_object_id_get,
2041 spufs_object_id_set, "0x%llx\n", SPU_ATTR_NOACQUIRE);
2043 static u64 spufs_lslr_get(struct spu_context *ctx)
2045 return ctx->csa.priv2.spu_lslr_RW;
2047 DEFINE_SPUFS_ATTRIBUTE(spufs_lslr_ops, spufs_lslr_get, NULL, "0x%llx\n",
2048 SPU_ATTR_ACQUIRE_SAVED);
2050 static int spufs_info_open(struct inode *inode, struct file *file)
2052 struct spufs_inode_info *i = SPUFS_I(inode);
2053 struct spu_context *ctx = i->i_ctx;
2054 file->private_data = ctx;
2058 static int spufs_caps_show(struct seq_file *s, void *private)
2060 struct spu_context *ctx = s->private;
2062 if (!(ctx->flags & SPU_CREATE_NOSCHED))
2063 seq_puts(s, "sched\n");
2064 if (!(ctx->flags & SPU_CREATE_ISOLATE))
2065 seq_puts(s, "step\n");
2069 static int spufs_caps_open(struct inode *inode, struct file *file)
2071 return single_open(file, spufs_caps_show, SPUFS_I(inode)->i_ctx);
2074 static const struct file_operations spufs_caps_fops = {
2075 .open = spufs_caps_open,
2077 .llseek = seq_lseek,
2078 .release = single_release,
2081 static ssize_t __spufs_mbox_info_read(struct spu_context *ctx,
2082 char __user *buf, size_t len, loff_t *pos)
2086 /* EOF if there's no entry in the mbox */
2087 if (!(ctx->csa.prob.mb_stat_R & 0x0000ff))
2090 data = ctx->csa.prob.pu_mb_R;
2092 return simple_read_from_buffer(buf, len, pos, &data, sizeof data);
2095 static ssize_t spufs_mbox_info_read(struct file *file, char __user *buf,
2096 size_t len, loff_t *pos)
2099 struct spu_context *ctx = file->private_data;
2101 if (!access_ok(VERIFY_WRITE, buf, len))
2104 ret = spu_acquire_saved(ctx);
2107 spin_lock(&ctx->csa.register_lock);
2108 ret = __spufs_mbox_info_read(ctx, buf, len, pos);
2109 spin_unlock(&ctx->csa.register_lock);
2110 spu_release_saved(ctx);
2115 static const struct file_operations spufs_mbox_info_fops = {
2116 .open = spufs_info_open,
2117 .read = spufs_mbox_info_read,
2118 .llseek = generic_file_llseek,
2121 static ssize_t __spufs_ibox_info_read(struct spu_context *ctx,
2122 char __user *buf, size_t len, loff_t *pos)
2126 /* EOF if there's no entry in the ibox */
2127 if (!(ctx->csa.prob.mb_stat_R & 0xff0000))
2130 data = ctx->csa.priv2.puint_mb_R;
2132 return simple_read_from_buffer(buf, len, pos, &data, sizeof data);
2135 static ssize_t spufs_ibox_info_read(struct file *file, char __user *buf,
2136 size_t len, loff_t *pos)
2138 struct spu_context *ctx = file->private_data;
2141 if (!access_ok(VERIFY_WRITE, buf, len))
2144 ret = spu_acquire_saved(ctx);
2147 spin_lock(&ctx->csa.register_lock);
2148 ret = __spufs_ibox_info_read(ctx, buf, len, pos);
2149 spin_unlock(&ctx->csa.register_lock);
2150 spu_release_saved(ctx);
2155 static const struct file_operations spufs_ibox_info_fops = {
2156 .open = spufs_info_open,
2157 .read = spufs_ibox_info_read,
2158 .llseek = generic_file_llseek,
2161 static ssize_t __spufs_wbox_info_read(struct spu_context *ctx,
2162 char __user *buf, size_t len, loff_t *pos)
2168 wbox_stat = ctx->csa.prob.mb_stat_R;
2169 cnt = 4 - ((wbox_stat & 0x00ff00) >> 8);
2170 for (i = 0; i < cnt; i++) {
2171 data[i] = ctx->csa.spu_mailbox_data[i];
2174 return simple_read_from_buffer(buf, len, pos, &data,
2178 static ssize_t spufs_wbox_info_read(struct file *file, char __user *buf,
2179 size_t len, loff_t *pos)
2181 struct spu_context *ctx = file->private_data;
2184 if (!access_ok(VERIFY_WRITE, buf, len))
2187 ret = spu_acquire_saved(ctx);
2190 spin_lock(&ctx->csa.register_lock);
2191 ret = __spufs_wbox_info_read(ctx, buf, len, pos);
2192 spin_unlock(&ctx->csa.register_lock);
2193 spu_release_saved(ctx);
2198 static const struct file_operations spufs_wbox_info_fops = {
2199 .open = spufs_info_open,
2200 .read = spufs_wbox_info_read,
2201 .llseek = generic_file_llseek,
2204 static ssize_t __spufs_dma_info_read(struct spu_context *ctx,
2205 char __user *buf, size_t len, loff_t *pos)
2207 struct spu_dma_info info;
2208 struct mfc_cq_sr *qp, *spuqp;
2211 info.dma_info_type = ctx->csa.priv2.spu_tag_status_query_RW;
2212 info.dma_info_mask = ctx->csa.lscsa->tag_mask.slot[0];
2213 info.dma_info_status = ctx->csa.spu_chnldata_RW[24];
2214 info.dma_info_stall_and_notify = ctx->csa.spu_chnldata_RW[25];
2215 info.dma_info_atomic_command_status = ctx->csa.spu_chnldata_RW[27];
2216 for (i = 0; i < 16; i++) {
2217 qp = &info.dma_info_command_data[i];
2218 spuqp = &ctx->csa.priv2.spuq[i];
2220 qp->mfc_cq_data0_RW = spuqp->mfc_cq_data0_RW;
2221 qp->mfc_cq_data1_RW = spuqp->mfc_cq_data1_RW;
2222 qp->mfc_cq_data2_RW = spuqp->mfc_cq_data2_RW;
2223 qp->mfc_cq_data3_RW = spuqp->mfc_cq_data3_RW;
2226 return simple_read_from_buffer(buf, len, pos, &info,
2230 static ssize_t spufs_dma_info_read(struct file *file, char __user *buf,
2231 size_t len, loff_t *pos)
2233 struct spu_context *ctx = file->private_data;
2236 if (!access_ok(VERIFY_WRITE, buf, len))
2239 ret = spu_acquire_saved(ctx);
2242 spin_lock(&ctx->csa.register_lock);
2243 ret = __spufs_dma_info_read(ctx, buf, len, pos);
2244 spin_unlock(&ctx->csa.register_lock);
2245 spu_release_saved(ctx);
2250 static const struct file_operations spufs_dma_info_fops = {
2251 .open = spufs_info_open,
2252 .read = spufs_dma_info_read,
2255 static ssize_t __spufs_proxydma_info_read(struct spu_context *ctx,
2256 char __user *buf, size_t len, loff_t *pos)
2258 struct spu_proxydma_info info;
2259 struct mfc_cq_sr *qp, *puqp;
2260 int ret = sizeof info;
2266 if (!access_ok(VERIFY_WRITE, buf, len))
2269 info.proxydma_info_type = ctx->csa.prob.dma_querytype_RW;
2270 info.proxydma_info_mask = ctx->csa.prob.dma_querymask_RW;
2271 info.proxydma_info_status = ctx->csa.prob.dma_tagstatus_R;
2272 for (i = 0; i < 8; i++) {
2273 qp = &info.proxydma_info_command_data[i];
2274 puqp = &ctx->csa.priv2.puq[i];
2276 qp->mfc_cq_data0_RW = puqp->mfc_cq_data0_RW;
2277 qp->mfc_cq_data1_RW = puqp->mfc_cq_data1_RW;
2278 qp->mfc_cq_data2_RW = puqp->mfc_cq_data2_RW;
2279 qp->mfc_cq_data3_RW = puqp->mfc_cq_data3_RW;
2282 return simple_read_from_buffer(buf, len, pos, &info,
2286 static ssize_t spufs_proxydma_info_read(struct file *file, char __user *buf,
2287 size_t len, loff_t *pos)
2289 struct spu_context *ctx = file->private_data;
2292 ret = spu_acquire_saved(ctx);
2295 spin_lock(&ctx->csa.register_lock);
2296 ret = __spufs_proxydma_info_read(ctx, buf, len, pos);
2297 spin_unlock(&ctx->csa.register_lock);
2298 spu_release_saved(ctx);
2303 static const struct file_operations spufs_proxydma_info_fops = {
2304 .open = spufs_info_open,
2305 .read = spufs_proxydma_info_read,
2308 static int spufs_show_tid(struct seq_file *s, void *private)
2310 struct spu_context *ctx = s->private;
2312 seq_printf(s, "%d\n", ctx->tid);
2316 static int spufs_tid_open(struct inode *inode, struct file *file)
2318 return single_open(file, spufs_show_tid, SPUFS_I(inode)->i_ctx);
2321 static const struct file_operations spufs_tid_fops = {
2322 .open = spufs_tid_open,
2324 .llseek = seq_lseek,
2325 .release = single_release,
2328 static const char *ctx_state_names[] = {
2329 "user", "system", "iowait", "loaded"
2332 static unsigned long long spufs_acct_time(struct spu_context *ctx,
2333 enum spu_utilization_state state)
2336 unsigned long long time = ctx->stats.times[state];
2339 * In general, utilization statistics are updated by the controlling
2340 * thread as the spu context moves through various well defined
2341 * state transitions, but if the context is lazily loaded its
2342 * utilization statistics are not updated as the controlling thread
2343 * is not tightly coupled with the execution of the spu context. We
2344 * calculate and apply the time delta from the last recorded state
2345 * of the spu context.
2347 if (ctx->spu && ctx->stats.util_state == state) {
2349 time += timespec_to_ns(&ts) - ctx->stats.tstamp;
2352 return time / NSEC_PER_MSEC;
2355 static unsigned long long spufs_slb_flts(struct spu_context *ctx)
2357 unsigned long long slb_flts = ctx->stats.slb_flt;
2359 if (ctx->state == SPU_STATE_RUNNABLE) {
2360 slb_flts += (ctx->spu->stats.slb_flt -
2361 ctx->stats.slb_flt_base);
2367 static unsigned long long spufs_class2_intrs(struct spu_context *ctx)
2369 unsigned long long class2_intrs = ctx->stats.class2_intr;
2371 if (ctx->state == SPU_STATE_RUNNABLE) {
2372 class2_intrs += (ctx->spu->stats.class2_intr -
2373 ctx->stats.class2_intr_base);
2376 return class2_intrs;
2380 static int spufs_show_stat(struct seq_file *s, void *private)
2382 struct spu_context *ctx = s->private;
2385 ret = spu_acquire(ctx);
2389 seq_printf(s, "%s %llu %llu %llu %llu "
2390 "%llu %llu %llu %llu %llu %llu %llu %llu\n",
2391 ctx_state_names[ctx->stats.util_state],
2392 spufs_acct_time(ctx, SPU_UTIL_USER),
2393 spufs_acct_time(ctx, SPU_UTIL_SYSTEM),
2394 spufs_acct_time(ctx, SPU_UTIL_IOWAIT),
2395 spufs_acct_time(ctx, SPU_UTIL_IDLE_LOADED),
2396 ctx->stats.vol_ctx_switch,
2397 ctx->stats.invol_ctx_switch,
2398 spufs_slb_flts(ctx),
2399 ctx->stats.hash_flt,
2402 spufs_class2_intrs(ctx),
2403 ctx->stats.libassist);
2408 static int spufs_stat_open(struct inode *inode, struct file *file)
2410 return single_open(file, spufs_show_stat, SPUFS_I(inode)->i_ctx);
2413 static const struct file_operations spufs_stat_fops = {
2414 .open = spufs_stat_open,
2416 .llseek = seq_lseek,
2417 .release = single_release,
2420 static inline int spufs_switch_log_used(struct spu_context *ctx)
2422 return (ctx->switch_log->head - ctx->switch_log->tail) %
2426 static inline int spufs_switch_log_avail(struct spu_context *ctx)
2428 return SWITCH_LOG_BUFSIZE - spufs_switch_log_used(ctx);
2431 static int spufs_switch_log_open(struct inode *inode, struct file *file)
2433 struct spu_context *ctx = SPUFS_I(inode)->i_ctx;
2436 rc = spu_acquire(ctx);
2440 if (ctx->switch_log) {
2445 ctx->switch_log = kmalloc(sizeof(struct switch_log) +
2446 SWITCH_LOG_BUFSIZE * sizeof(struct switch_log_entry),
2449 if (!ctx->switch_log) {
2454 ctx->switch_log->head = ctx->switch_log->tail = 0;
2455 init_waitqueue_head(&ctx->switch_log->wait);
2463 static int spufs_switch_log_release(struct inode *inode, struct file *file)
2465 struct spu_context *ctx = SPUFS_I(inode)->i_ctx;
2468 rc = spu_acquire(ctx);
2472 kfree(ctx->switch_log);
2473 ctx->switch_log = NULL;
2479 static int switch_log_sprint(struct spu_context *ctx, char *tbuf, int n)
2481 struct switch_log_entry *p;
2483 p = ctx->switch_log->log + ctx->switch_log->tail % SWITCH_LOG_BUFSIZE;
2485 return snprintf(tbuf, n, "%u.%09u %d %u %u %llu\n",
2486 (unsigned int) p->tstamp.tv_sec,
2487 (unsigned int) p->tstamp.tv_nsec,
2489 (unsigned int) p->type,
2490 (unsigned int) p->val,
2491 (unsigned long long) p->timebase);
2494 static ssize_t spufs_switch_log_read(struct file *file, char __user *buf,
2495 size_t len, loff_t *ppos)
2497 struct inode *inode = file->f_path.dentry->d_inode;
2498 struct spu_context *ctx = SPUFS_I(inode)->i_ctx;
2499 int error = 0, cnt = 0;
2501 if (!buf || len < 0)
2504 error = spu_acquire(ctx);
2512 if (spufs_switch_log_used(ctx) == 0) {
2514 /* If there's data ready to go, we can
2515 * just return straight away */
2518 } else if (file->f_flags & O_NONBLOCK) {
2523 /* spufs_wait will drop the mutex and
2524 * re-acquire, but since we're in read(), the
2525 * file cannot be _released (and so
2526 * ctx->switch_log is stable).
2528 error = spufs_wait(ctx->switch_log->wait,
2529 spufs_switch_log_used(ctx) > 0);
2531 /* On error, spufs_wait returns without the
2532 * state mutex held */
2536 /* We may have had entries read from underneath
2537 * us while we dropped the mutex in spufs_wait,
2539 if (spufs_switch_log_used(ctx) == 0)
2544 width = switch_log_sprint(ctx, tbuf, sizeof(tbuf));
2546 ctx->switch_log->tail =
2547 (ctx->switch_log->tail + 1) %
2550 /* If the record is greater than space available return
2551 * partial buffer (so far) */
2554 error = copy_to_user(buf + cnt, tbuf, width);
2562 return cnt == 0 ? error : cnt;
2565 static unsigned int spufs_switch_log_poll(struct file *file, poll_table *wait)
2567 struct inode *inode = file->f_path.dentry->d_inode;
2568 struct spu_context *ctx = SPUFS_I(inode)->i_ctx;
2569 unsigned int mask = 0;
2572 poll_wait(file, &ctx->switch_log->wait, wait);
2574 rc = spu_acquire(ctx);
2578 if (spufs_switch_log_used(ctx) > 0)
2586 static const struct file_operations spufs_switch_log_fops = {
2587 .owner = THIS_MODULE,
2588 .open = spufs_switch_log_open,
2589 .read = spufs_switch_log_read,
2590 .poll = spufs_switch_log_poll,
2591 .release = spufs_switch_log_release,
2595 * Log a context switch event to a switch log reader.
2597 * Must be called with ctx->state_mutex held.
2599 void spu_switch_log_notify(struct spu *spu, struct spu_context *ctx,
2602 if (!ctx->switch_log)
2605 if (spufs_switch_log_avail(ctx) > 1) {
2606 struct switch_log_entry *p;
2608 p = ctx->switch_log->log + ctx->switch_log->head;
2609 ktime_get_ts(&p->tstamp);
2610 p->timebase = get_tb();
2611 p->spu_id = spu ? spu->number : -1;
2615 ctx->switch_log->head =
2616 (ctx->switch_log->head + 1) % SWITCH_LOG_BUFSIZE;
2619 wake_up(&ctx->switch_log->wait);
2622 static int spufs_show_ctx(struct seq_file *s, void *private)
2624 struct spu_context *ctx = s->private;
2627 mutex_lock(&ctx->state_mutex);
2629 struct spu *spu = ctx->spu;
2630 struct spu_priv2 __iomem *priv2 = spu->priv2;
2632 spin_lock_irq(&spu->register_lock);
2633 mfc_control_RW = in_be64(&priv2->mfc_control_RW);
2634 spin_unlock_irq(&spu->register_lock);
2636 struct spu_state *csa = &ctx->csa;
2638 mfc_control_RW = csa->priv2.mfc_control_RW;
2641 seq_printf(s, "%c flgs(%lx) sflgs(%lx) pri(%d) ts(%d) spu(%02d)"
2642 " %c %lx %lx %lx %lx %x %x\n",
2643 ctx->state == SPU_STATE_SAVED ? 'S' : 'R',
2648 ctx->spu ? ctx->spu->number : -1,
2649 !list_empty(&ctx->rq) ? 'q' : ' ',
2650 ctx->csa.class_0_pending,
2651 ctx->csa.class_0_dar,
2652 ctx->csa.class_1_dsisr,
2654 ctx->ops->runcntl_read(ctx),
2655 ctx->ops->status_read(ctx));
2657 mutex_unlock(&ctx->state_mutex);
2662 static int spufs_ctx_open(struct inode *inode, struct file *file)
2664 return single_open(file, spufs_show_ctx, SPUFS_I(inode)->i_ctx);
2667 static const struct file_operations spufs_ctx_fops = {
2668 .open = spufs_ctx_open,
2670 .llseek = seq_lseek,
2671 .release = single_release,
2674 struct spufs_tree_descr spufs_dir_contents[] = {
2675 { "capabilities", &spufs_caps_fops, 0444, },
2676 { "mem", &spufs_mem_fops, 0666, LS_SIZE, },
2677 { "regs", &spufs_regs_fops, 0666, sizeof(struct spu_reg128[128]), },
2678 { "mbox", &spufs_mbox_fops, 0444, },
2679 { "ibox", &spufs_ibox_fops, 0444, },
2680 { "wbox", &spufs_wbox_fops, 0222, },
2681 { "mbox_stat", &spufs_mbox_stat_fops, 0444, sizeof(u32), },
2682 { "ibox_stat", &spufs_ibox_stat_fops, 0444, sizeof(u32), },
2683 { "wbox_stat", &spufs_wbox_stat_fops, 0444, sizeof(u32), },
2684 { "signal1", &spufs_signal1_fops, 0666, },
2685 { "signal2", &spufs_signal2_fops, 0666, },
2686 { "signal1_type", &spufs_signal1_type, 0666, },
2687 { "signal2_type", &spufs_signal2_type, 0666, },
2688 { "cntl", &spufs_cntl_fops, 0666, },
2689 { "fpcr", &spufs_fpcr_fops, 0666, sizeof(struct spu_reg128), },
2690 { "lslr", &spufs_lslr_ops, 0444, },
2691 { "mfc", &spufs_mfc_fops, 0666, },
2692 { "mss", &spufs_mss_fops, 0666, },
2693 { "npc", &spufs_npc_ops, 0666, },
2694 { "srr0", &spufs_srr0_ops, 0666, },
2695 { "decr", &spufs_decr_ops, 0666, },
2696 { "decr_status", &spufs_decr_status_ops, 0666, },
2697 { "event_mask", &spufs_event_mask_ops, 0666, },
2698 { "event_status", &spufs_event_status_ops, 0444, },
2699 { "psmap", &spufs_psmap_fops, 0666, SPUFS_PS_MAP_SIZE, },
2700 { "phys-id", &spufs_id_ops, 0666, },
2701 { "object-id", &spufs_object_id_ops, 0666, },
2702 { "mbox_info", &spufs_mbox_info_fops, 0444, sizeof(u32), },
2703 { "ibox_info", &spufs_ibox_info_fops, 0444, sizeof(u32), },
2704 { "wbox_info", &spufs_wbox_info_fops, 0444, sizeof(u32), },
2705 { "dma_info", &spufs_dma_info_fops, 0444,
2706 sizeof(struct spu_dma_info), },
2707 { "proxydma_info", &spufs_proxydma_info_fops, 0444,
2708 sizeof(struct spu_proxydma_info)},
2709 { "tid", &spufs_tid_fops, 0444, },
2710 { "stat", &spufs_stat_fops, 0444, },
2711 { "switch_log", &spufs_switch_log_fops, 0444 },
2715 struct spufs_tree_descr spufs_dir_nosched_contents[] = {
2716 { "capabilities", &spufs_caps_fops, 0444, },
2717 { "mem", &spufs_mem_fops, 0666, LS_SIZE, },
2718 { "mbox", &spufs_mbox_fops, 0444, },
2719 { "ibox", &spufs_ibox_fops, 0444, },
2720 { "wbox", &spufs_wbox_fops, 0222, },
2721 { "mbox_stat", &spufs_mbox_stat_fops, 0444, sizeof(u32), },
2722 { "ibox_stat", &spufs_ibox_stat_fops, 0444, sizeof(u32), },
2723 { "wbox_stat", &spufs_wbox_stat_fops, 0444, sizeof(u32), },
2724 { "signal1", &spufs_signal1_nosched_fops, 0222, },
2725 { "signal2", &spufs_signal2_nosched_fops, 0222, },
2726 { "signal1_type", &spufs_signal1_type, 0666, },
2727 { "signal2_type", &spufs_signal2_type, 0666, },
2728 { "mss", &spufs_mss_fops, 0666, },
2729 { "mfc", &spufs_mfc_fops, 0666, },
2730 { "cntl", &spufs_cntl_fops, 0666, },
2731 { "npc", &spufs_npc_ops, 0666, },
2732 { "psmap", &spufs_psmap_fops, 0666, SPUFS_PS_MAP_SIZE, },
2733 { "phys-id", &spufs_id_ops, 0666, },
2734 { "object-id", &spufs_object_id_ops, 0666, },
2735 { "tid", &spufs_tid_fops, 0444, },
2736 { "stat", &spufs_stat_fops, 0444, },
2740 struct spufs_tree_descr spufs_dir_debug_contents[] = {
2741 { ".ctx", &spufs_ctx_fops, 0444, },
2745 struct spufs_coredump_reader spufs_coredump_read[] = {
2746 { "regs", __spufs_regs_read, NULL, sizeof(struct spu_reg128[128])},
2747 { "fpcr", __spufs_fpcr_read, NULL, sizeof(struct spu_reg128) },
2748 { "lslr", NULL, spufs_lslr_get, 19 },
2749 { "decr", NULL, spufs_decr_get, 19 },
2750 { "decr_status", NULL, spufs_decr_status_get, 19 },
2751 { "mem", __spufs_mem_read, NULL, LS_SIZE, },
2752 { "signal1", __spufs_signal1_read, NULL, sizeof(u32) },
2753 { "signal1_type", NULL, spufs_signal1_type_get, 19 },
2754 { "signal2", __spufs_signal2_read, NULL, sizeof(u32) },
2755 { "signal2_type", NULL, spufs_signal2_type_get, 19 },
2756 { "event_mask", NULL, spufs_event_mask_get, 19 },
2757 { "event_status", NULL, spufs_event_status_get, 19 },
2758 { "mbox_info", __spufs_mbox_info_read, NULL, sizeof(u32) },
2759 { "ibox_info", __spufs_ibox_info_read, NULL, sizeof(u32) },
2760 { "wbox_info", __spufs_wbox_info_read, NULL, 4 * sizeof(u32)},
2761 { "dma_info", __spufs_dma_info_read, NULL, sizeof(struct spu_dma_info)},
2762 { "proxydma_info", __spufs_proxydma_info_read,
2763 NULL, sizeof(struct spu_proxydma_info)},
2764 { "object-id", NULL, spufs_object_id_get, 19 },
2765 { "npc", NULL, spufs_npc_get, 19 },