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>
34 #include <asm/semaphore.h>
36 #include <asm/spu_info.h>
37 #include <asm/uaccess.h>
41 #define SPUFS_MMAP_4K (PAGE_SIZE == 0x1000)
45 spufs_mem_open(struct inode *inode, struct file *file)
47 struct spufs_inode_info *i = SPUFS_I(inode);
48 struct spu_context *ctx = i->i_ctx;
50 mutex_lock(&ctx->mapping_lock);
51 file->private_data = ctx;
53 ctx->local_store = inode->i_mapping;
54 mutex_unlock(&ctx->mapping_lock);
59 spufs_mem_release(struct inode *inode, struct file *file)
61 struct spufs_inode_info *i = SPUFS_I(inode);
62 struct spu_context *ctx = i->i_ctx;
64 mutex_lock(&ctx->mapping_lock);
66 ctx->local_store = NULL;
67 mutex_unlock(&ctx->mapping_lock);
72 __spufs_mem_read(struct spu_context *ctx, char __user *buffer,
73 size_t size, loff_t *pos)
75 char *local_store = ctx->ops->get_ls(ctx);
76 return simple_read_from_buffer(buffer, size, pos, local_store,
81 spufs_mem_read(struct file *file, char __user *buffer,
82 size_t size, loff_t *pos)
84 struct spu_context *ctx = file->private_data;
88 ret = __spufs_mem_read(ctx, buffer, size, pos);
94 spufs_mem_write(struct file *file, const char __user *buffer,
95 size_t size, loff_t *ppos)
97 struct spu_context *ctx = file->private_data;
106 if (size > LS_SIZE - pos)
107 size = LS_SIZE - pos;
110 local_store = ctx->ops->get_ls(ctx);
111 ret = copy_from_user(local_store + pos, buffer, size);
120 static unsigned long spufs_mem_mmap_nopfn(struct vm_area_struct *vma,
121 unsigned long address)
123 struct spu_context *ctx = vma->vm_file->private_data;
124 unsigned long pfn, offset, addr0 = address;
125 #ifdef CONFIG_SPU_FS_64K_LS
126 struct spu_state *csa = &ctx->csa;
129 /* Check what page size we are using */
130 psize = get_slice_psize(vma->vm_mm, address);
132 /* Some sanity checking */
133 BUG_ON(csa->use_big_pages != (psize == MMU_PAGE_64K));
135 /* Wow, 64K, cool, we need to align the address though */
136 if (csa->use_big_pages) {
137 BUG_ON(vma->vm_start & 0xffff);
138 address &= ~0xfffful;
140 #endif /* CONFIG_SPU_FS_64K_LS */
142 offset = (address - vma->vm_start) + (vma->vm_pgoff << PAGE_SHIFT);
143 if (offset >= LS_SIZE)
146 pr_debug("spufs_mem_mmap_nopfn address=0x%lx -> 0x%lx, offset=0x%lx\n",
147 addr0, address, offset);
151 if (ctx->state == SPU_STATE_SAVED) {
152 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
154 pfn = vmalloc_to_pfn(ctx->csa.lscsa->ls + offset);
156 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
158 pfn = (ctx->spu->local_store_phys + offset) >> PAGE_SHIFT;
160 vm_insert_pfn(vma, address, pfn);
164 return NOPFN_REFAULT;
168 static struct vm_operations_struct spufs_mem_mmap_vmops = {
169 .nopfn = spufs_mem_mmap_nopfn,
172 static int spufs_mem_mmap(struct file *file, struct vm_area_struct *vma)
174 #ifdef CONFIG_SPU_FS_64K_LS
175 struct spu_context *ctx = file->private_data;
176 struct spu_state *csa = &ctx->csa;
178 /* Sanity check VMA alignment */
179 if (csa->use_big_pages) {
180 pr_debug("spufs_mem_mmap 64K, start=0x%lx, end=0x%lx,"
181 " pgoff=0x%lx\n", vma->vm_start, vma->vm_end,
183 if (vma->vm_start & 0xffff)
185 if (vma->vm_pgoff & 0xf)
188 #endif /* CONFIG_SPU_FS_64K_LS */
190 if (!(vma->vm_flags & VM_SHARED))
193 vma->vm_flags |= VM_IO | VM_PFNMAP;
194 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
197 vma->vm_ops = &spufs_mem_mmap_vmops;
201 #ifdef CONFIG_SPU_FS_64K_LS
202 unsigned long spufs_get_unmapped_area(struct file *file, unsigned long addr,
203 unsigned long len, unsigned long pgoff,
206 struct spu_context *ctx = file->private_data;
207 struct spu_state *csa = &ctx->csa;
209 /* If not using big pages, fallback to normal MM g_u_a */
210 if (!csa->use_big_pages)
211 return current->mm->get_unmapped_area(file, addr, len,
214 /* Else, try to obtain a 64K pages slice */
215 return slice_get_unmapped_area(addr, len, flags,
218 #endif /* CONFIG_SPU_FS_64K_LS */
220 static const struct file_operations spufs_mem_fops = {
221 .open = spufs_mem_open,
222 .release = spufs_mem_release,
223 .read = spufs_mem_read,
224 .write = spufs_mem_write,
225 .llseek = generic_file_llseek,
226 .mmap = spufs_mem_mmap,
227 #ifdef CONFIG_SPU_FS_64K_LS
228 .get_unmapped_area = spufs_get_unmapped_area,
232 static unsigned long spufs_ps_nopfn(struct vm_area_struct *vma,
233 unsigned long address,
234 unsigned long ps_offs,
235 unsigned long ps_size)
237 struct spu_context *ctx = vma->vm_file->private_data;
238 unsigned long area, offset = address - vma->vm_start;
241 offset += vma->vm_pgoff << PAGE_SHIFT;
242 if (offset >= ps_size)
245 /* error here usually means a signal.. we might want to test
246 * the error code more precisely though
248 ret = spu_acquire_runnable(ctx, 0);
250 return NOPFN_REFAULT;
252 area = ctx->spu->problem_phys + ps_offs;
253 vm_insert_pfn(vma, address, (area + offset) >> PAGE_SHIFT);
256 return NOPFN_REFAULT;
260 static unsigned long spufs_cntl_mmap_nopfn(struct vm_area_struct *vma,
261 unsigned long address)
263 return spufs_ps_nopfn(vma, address, 0x4000, 0x1000);
266 static struct vm_operations_struct spufs_cntl_mmap_vmops = {
267 .nopfn = spufs_cntl_mmap_nopfn,
271 * mmap support for problem state control area [0x4000 - 0x4fff].
273 static int spufs_cntl_mmap(struct file *file, struct vm_area_struct *vma)
275 if (!(vma->vm_flags & VM_SHARED))
278 vma->vm_flags |= VM_IO | VM_PFNMAP;
279 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
280 | _PAGE_NO_CACHE | _PAGE_GUARDED);
282 vma->vm_ops = &spufs_cntl_mmap_vmops;
285 #else /* SPUFS_MMAP_4K */
286 #define spufs_cntl_mmap NULL
287 #endif /* !SPUFS_MMAP_4K */
289 static u64 spufs_cntl_get(void *data)
291 struct spu_context *ctx = data;
295 val = ctx->ops->status_read(ctx);
301 static void spufs_cntl_set(void *data, u64 val)
303 struct spu_context *ctx = data;
306 ctx->ops->runcntl_write(ctx, val);
310 static int spufs_cntl_open(struct inode *inode, struct file *file)
312 struct spufs_inode_info *i = SPUFS_I(inode);
313 struct spu_context *ctx = i->i_ctx;
315 mutex_lock(&ctx->mapping_lock);
316 file->private_data = ctx;
318 ctx->cntl = inode->i_mapping;
319 mutex_unlock(&ctx->mapping_lock);
320 return simple_attr_open(inode, file, spufs_cntl_get,
321 spufs_cntl_set, "0x%08lx");
325 spufs_cntl_release(struct inode *inode, struct file *file)
327 struct spufs_inode_info *i = SPUFS_I(inode);
328 struct spu_context *ctx = i->i_ctx;
330 simple_attr_close(inode, file);
332 mutex_lock(&ctx->mapping_lock);
335 mutex_unlock(&ctx->mapping_lock);
339 static const struct file_operations spufs_cntl_fops = {
340 .open = spufs_cntl_open,
341 .release = spufs_cntl_release,
342 .read = simple_attr_read,
343 .write = simple_attr_write,
344 .mmap = spufs_cntl_mmap,
348 spufs_regs_open(struct inode *inode, struct file *file)
350 struct spufs_inode_info *i = SPUFS_I(inode);
351 file->private_data = i->i_ctx;
356 __spufs_regs_read(struct spu_context *ctx, char __user *buffer,
357 size_t size, loff_t *pos)
359 struct spu_lscsa *lscsa = ctx->csa.lscsa;
360 return simple_read_from_buffer(buffer, size, pos,
361 lscsa->gprs, sizeof lscsa->gprs);
365 spufs_regs_read(struct file *file, char __user *buffer,
366 size_t size, loff_t *pos)
369 struct spu_context *ctx = file->private_data;
371 spu_acquire_saved(ctx);
372 ret = __spufs_regs_read(ctx, buffer, size, pos);
378 spufs_regs_write(struct file *file, const char __user *buffer,
379 size_t size, loff_t *pos)
381 struct spu_context *ctx = file->private_data;
382 struct spu_lscsa *lscsa = ctx->csa.lscsa;
385 size = min_t(ssize_t, sizeof lscsa->gprs - *pos, size);
390 spu_acquire_saved(ctx);
392 ret = copy_from_user(lscsa->gprs + *pos - size,
393 buffer, size) ? -EFAULT : size;
399 static const struct file_operations spufs_regs_fops = {
400 .open = spufs_regs_open,
401 .read = spufs_regs_read,
402 .write = spufs_regs_write,
403 .llseek = generic_file_llseek,
407 __spufs_fpcr_read(struct spu_context *ctx, char __user * buffer,
408 size_t size, loff_t * pos)
410 struct spu_lscsa *lscsa = ctx->csa.lscsa;
411 return simple_read_from_buffer(buffer, size, pos,
412 &lscsa->fpcr, sizeof(lscsa->fpcr));
416 spufs_fpcr_read(struct file *file, char __user * buffer,
417 size_t size, loff_t * pos)
420 struct spu_context *ctx = file->private_data;
422 spu_acquire_saved(ctx);
423 ret = __spufs_fpcr_read(ctx, buffer, size, pos);
429 spufs_fpcr_write(struct file *file, const char __user * buffer,
430 size_t size, loff_t * pos)
432 struct spu_context *ctx = file->private_data;
433 struct spu_lscsa *lscsa = ctx->csa.lscsa;
436 size = min_t(ssize_t, sizeof(lscsa->fpcr) - *pos, size);
441 spu_acquire_saved(ctx);
443 ret = copy_from_user((char *)&lscsa->fpcr + *pos - size,
444 buffer, size) ? -EFAULT : size;
450 static const struct file_operations spufs_fpcr_fops = {
451 .open = spufs_regs_open,
452 .read = spufs_fpcr_read,
453 .write = spufs_fpcr_write,
454 .llseek = generic_file_llseek,
457 /* generic open function for all pipe-like files */
458 static int spufs_pipe_open(struct inode *inode, struct file *file)
460 struct spufs_inode_info *i = SPUFS_I(inode);
461 file->private_data = i->i_ctx;
463 return nonseekable_open(inode, file);
467 * Read as many bytes from the mailbox as possible, until
468 * one of the conditions becomes true:
470 * - no more data available in the mailbox
471 * - end of the user provided buffer
472 * - end of the mapped area
474 static ssize_t spufs_mbox_read(struct file *file, char __user *buf,
475 size_t len, loff_t *pos)
477 struct spu_context *ctx = file->private_data;
478 u32 mbox_data, __user *udata;
484 if (!access_ok(VERIFY_WRITE, buf, len))
487 udata = (void __user *)buf;
490 for (count = 0; (count + 4) <= len; count += 4, udata++) {
492 ret = ctx->ops->mbox_read(ctx, &mbox_data);
497 * at the end of the mapped area, we can fault
498 * but still need to return the data we have
499 * read successfully so far.
501 ret = __put_user(mbox_data, udata);
516 static const struct file_operations spufs_mbox_fops = {
517 .open = spufs_pipe_open,
518 .read = spufs_mbox_read,
521 static ssize_t spufs_mbox_stat_read(struct file *file, char __user *buf,
522 size_t len, loff_t *pos)
524 struct spu_context *ctx = file->private_data;
532 mbox_stat = ctx->ops->mbox_stat_read(ctx) & 0xff;
536 if (copy_to_user(buf, &mbox_stat, sizeof mbox_stat))
542 static const struct file_operations spufs_mbox_stat_fops = {
543 .open = spufs_pipe_open,
544 .read = spufs_mbox_stat_read,
547 /* low-level ibox access function */
548 size_t spu_ibox_read(struct spu_context *ctx, u32 *data)
550 return ctx->ops->ibox_read(ctx, data);
553 static int spufs_ibox_fasync(int fd, struct file *file, int on)
555 struct spu_context *ctx = file->private_data;
557 return fasync_helper(fd, file, on, &ctx->ibox_fasync);
560 /* interrupt-level ibox callback function. */
561 void spufs_ibox_callback(struct spu *spu)
563 struct spu_context *ctx = spu->ctx;
565 wake_up_all(&ctx->ibox_wq);
566 kill_fasync(&ctx->ibox_fasync, SIGIO, POLLIN);
570 * Read as many bytes from the interrupt mailbox as possible, until
571 * one of the conditions becomes true:
573 * - no more data available in the mailbox
574 * - end of the user provided buffer
575 * - end of the mapped area
577 * If the file is opened without O_NONBLOCK, we wait here until
578 * any data is available, but return when we have been able to
581 static ssize_t spufs_ibox_read(struct file *file, char __user *buf,
582 size_t len, loff_t *pos)
584 struct spu_context *ctx = file->private_data;
585 u32 ibox_data, __user *udata;
591 if (!access_ok(VERIFY_WRITE, buf, len))
594 udata = (void __user *)buf;
598 /* wait only for the first element */
600 if (file->f_flags & O_NONBLOCK) {
601 if (!spu_ibox_read(ctx, &ibox_data))
604 count = spufs_wait(ctx->ibox_wq, spu_ibox_read(ctx, &ibox_data));
609 /* if we can't write at all, return -EFAULT */
610 count = __put_user(ibox_data, udata);
614 for (count = 4, udata++; (count + 4) <= len; count += 4, udata++) {
616 ret = ctx->ops->ibox_read(ctx, &ibox_data);
620 * at the end of the mapped area, we can fault
621 * but still need to return the data we have
622 * read successfully so far.
624 ret = __put_user(ibox_data, udata);
635 static unsigned int spufs_ibox_poll(struct file *file, poll_table *wait)
637 struct spu_context *ctx = file->private_data;
640 poll_wait(file, &ctx->ibox_wq, wait);
643 mask = ctx->ops->mbox_stat_poll(ctx, POLLIN | POLLRDNORM);
649 static const struct file_operations spufs_ibox_fops = {
650 .open = spufs_pipe_open,
651 .read = spufs_ibox_read,
652 .poll = spufs_ibox_poll,
653 .fasync = spufs_ibox_fasync,
656 static ssize_t spufs_ibox_stat_read(struct file *file, char __user *buf,
657 size_t len, loff_t *pos)
659 struct spu_context *ctx = file->private_data;
666 ibox_stat = (ctx->ops->mbox_stat_read(ctx) >> 16) & 0xff;
669 if (copy_to_user(buf, &ibox_stat, sizeof ibox_stat))
675 static const struct file_operations spufs_ibox_stat_fops = {
676 .open = spufs_pipe_open,
677 .read = spufs_ibox_stat_read,
680 /* low-level mailbox write */
681 size_t spu_wbox_write(struct spu_context *ctx, u32 data)
683 return ctx->ops->wbox_write(ctx, data);
686 static int spufs_wbox_fasync(int fd, struct file *file, int on)
688 struct spu_context *ctx = file->private_data;
691 ret = fasync_helper(fd, file, on, &ctx->wbox_fasync);
696 /* interrupt-level wbox callback function. */
697 void spufs_wbox_callback(struct spu *spu)
699 struct spu_context *ctx = spu->ctx;
701 wake_up_all(&ctx->wbox_wq);
702 kill_fasync(&ctx->wbox_fasync, SIGIO, POLLOUT);
706 * Write as many bytes to the interrupt mailbox as possible, until
707 * one of the conditions becomes true:
709 * - the mailbox is full
710 * - end of the user provided buffer
711 * - end of the mapped area
713 * If the file is opened without O_NONBLOCK, we wait here until
714 * space is availabyl, but return when we have been able to
717 static ssize_t spufs_wbox_write(struct file *file, const char __user *buf,
718 size_t len, loff_t *pos)
720 struct spu_context *ctx = file->private_data;
721 u32 wbox_data, __user *udata;
727 udata = (void __user *)buf;
728 if (!access_ok(VERIFY_READ, buf, len))
731 if (__get_user(wbox_data, udata))
737 * make sure we can at least write one element, by waiting
738 * in case of !O_NONBLOCK
741 if (file->f_flags & O_NONBLOCK) {
742 if (!spu_wbox_write(ctx, wbox_data))
745 count = spufs_wait(ctx->wbox_wq, spu_wbox_write(ctx, wbox_data));
751 /* write aѕ much as possible */
752 for (count = 4, udata++; (count + 4) <= len; count += 4, udata++) {
754 ret = __get_user(wbox_data, udata);
758 ret = spu_wbox_write(ctx, wbox_data);
768 static unsigned int spufs_wbox_poll(struct file *file, poll_table *wait)
770 struct spu_context *ctx = file->private_data;
773 poll_wait(file, &ctx->wbox_wq, wait);
776 mask = ctx->ops->mbox_stat_poll(ctx, POLLOUT | POLLWRNORM);
782 static const struct file_operations spufs_wbox_fops = {
783 .open = spufs_pipe_open,
784 .write = spufs_wbox_write,
785 .poll = spufs_wbox_poll,
786 .fasync = spufs_wbox_fasync,
789 static ssize_t spufs_wbox_stat_read(struct file *file, char __user *buf,
790 size_t len, loff_t *pos)
792 struct spu_context *ctx = file->private_data;
799 wbox_stat = (ctx->ops->mbox_stat_read(ctx) >> 8) & 0xff;
802 if (copy_to_user(buf, &wbox_stat, sizeof wbox_stat))
808 static const struct file_operations spufs_wbox_stat_fops = {
809 .open = spufs_pipe_open,
810 .read = spufs_wbox_stat_read,
813 static int spufs_signal1_open(struct inode *inode, struct file *file)
815 struct spufs_inode_info *i = SPUFS_I(inode);
816 struct spu_context *ctx = i->i_ctx;
818 mutex_lock(&ctx->mapping_lock);
819 file->private_data = ctx;
821 ctx->signal1 = inode->i_mapping;
822 mutex_unlock(&ctx->mapping_lock);
823 return nonseekable_open(inode, file);
827 spufs_signal1_release(struct inode *inode, struct file *file)
829 struct spufs_inode_info *i = SPUFS_I(inode);
830 struct spu_context *ctx = i->i_ctx;
832 mutex_lock(&ctx->mapping_lock);
835 mutex_unlock(&ctx->mapping_lock);
839 static ssize_t __spufs_signal1_read(struct spu_context *ctx, char __user *buf,
840 size_t len, loff_t *pos)
848 if (ctx->csa.spu_chnlcnt_RW[3]) {
849 data = ctx->csa.spu_chnldata_RW[3];
856 if (copy_to_user(buf, &data, 4))
863 static ssize_t spufs_signal1_read(struct file *file, char __user *buf,
864 size_t len, loff_t *pos)
867 struct spu_context *ctx = file->private_data;
869 spu_acquire_saved(ctx);
870 ret = __spufs_signal1_read(ctx, buf, len, pos);
876 static ssize_t spufs_signal1_write(struct file *file, const char __user *buf,
877 size_t len, loff_t *pos)
879 struct spu_context *ctx;
882 ctx = file->private_data;
887 if (copy_from_user(&data, buf, 4))
891 ctx->ops->signal1_write(ctx, data);
897 static unsigned long spufs_signal1_mmap_nopfn(struct vm_area_struct *vma,
898 unsigned long address)
900 #if PAGE_SIZE == 0x1000
901 return spufs_ps_nopfn(vma, address, 0x14000, 0x1000);
902 #elif PAGE_SIZE == 0x10000
903 /* For 64k pages, both signal1 and signal2 can be used to mmap the whole
904 * signal 1 and 2 area
906 return spufs_ps_nopfn(vma, address, 0x10000, 0x10000);
908 #error unsupported page size
912 static struct vm_operations_struct spufs_signal1_mmap_vmops = {
913 .nopfn = spufs_signal1_mmap_nopfn,
916 static int spufs_signal1_mmap(struct file *file, struct vm_area_struct *vma)
918 if (!(vma->vm_flags & VM_SHARED))
921 vma->vm_flags |= VM_IO | VM_PFNMAP;
922 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
923 | _PAGE_NO_CACHE | _PAGE_GUARDED);
925 vma->vm_ops = &spufs_signal1_mmap_vmops;
929 static const struct file_operations spufs_signal1_fops = {
930 .open = spufs_signal1_open,
931 .release = spufs_signal1_release,
932 .read = spufs_signal1_read,
933 .write = spufs_signal1_write,
934 .mmap = spufs_signal1_mmap,
937 static int spufs_signal2_open(struct inode *inode, struct file *file)
939 struct spufs_inode_info *i = SPUFS_I(inode);
940 struct spu_context *ctx = i->i_ctx;
942 mutex_lock(&ctx->mapping_lock);
943 file->private_data = ctx;
945 ctx->signal2 = inode->i_mapping;
946 mutex_unlock(&ctx->mapping_lock);
947 return nonseekable_open(inode, file);
951 spufs_signal2_release(struct inode *inode, struct file *file)
953 struct spufs_inode_info *i = SPUFS_I(inode);
954 struct spu_context *ctx = i->i_ctx;
956 mutex_lock(&ctx->mapping_lock);
959 mutex_unlock(&ctx->mapping_lock);
963 static ssize_t __spufs_signal2_read(struct spu_context *ctx, char __user *buf,
964 size_t len, loff_t *pos)
972 if (ctx->csa.spu_chnlcnt_RW[4]) {
973 data = ctx->csa.spu_chnldata_RW[4];
980 if (copy_to_user(buf, &data, 4))
987 static ssize_t spufs_signal2_read(struct file *file, char __user *buf,
988 size_t len, loff_t *pos)
990 struct spu_context *ctx = file->private_data;
993 spu_acquire_saved(ctx);
994 ret = __spufs_signal2_read(ctx, buf, len, pos);
1000 static ssize_t spufs_signal2_write(struct file *file, const char __user *buf,
1001 size_t len, loff_t *pos)
1003 struct spu_context *ctx;
1006 ctx = file->private_data;
1011 if (copy_from_user(&data, buf, 4))
1015 ctx->ops->signal2_write(ctx, data);
1022 static unsigned long spufs_signal2_mmap_nopfn(struct vm_area_struct *vma,
1023 unsigned long address)
1025 #if PAGE_SIZE == 0x1000
1026 return spufs_ps_nopfn(vma, address, 0x1c000, 0x1000);
1027 #elif PAGE_SIZE == 0x10000
1028 /* For 64k pages, both signal1 and signal2 can be used to mmap the whole
1029 * signal 1 and 2 area
1031 return spufs_ps_nopfn(vma, address, 0x10000, 0x10000);
1033 #error unsupported page size
1037 static struct vm_operations_struct spufs_signal2_mmap_vmops = {
1038 .nopfn = spufs_signal2_mmap_nopfn,
1041 static int spufs_signal2_mmap(struct file *file, struct vm_area_struct *vma)
1043 if (!(vma->vm_flags & VM_SHARED))
1046 vma->vm_flags |= VM_IO | VM_PFNMAP;
1047 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
1048 | _PAGE_NO_CACHE | _PAGE_GUARDED);
1050 vma->vm_ops = &spufs_signal2_mmap_vmops;
1053 #else /* SPUFS_MMAP_4K */
1054 #define spufs_signal2_mmap NULL
1055 #endif /* !SPUFS_MMAP_4K */
1057 static const struct file_operations spufs_signal2_fops = {
1058 .open = spufs_signal2_open,
1059 .release = spufs_signal2_release,
1060 .read = spufs_signal2_read,
1061 .write = spufs_signal2_write,
1062 .mmap = spufs_signal2_mmap,
1065 static void spufs_signal1_type_set(void *data, u64 val)
1067 struct spu_context *ctx = data;
1070 ctx->ops->signal1_type_set(ctx, val);
1074 static u64 __spufs_signal1_type_get(void *data)
1076 struct spu_context *ctx = data;
1077 return ctx->ops->signal1_type_get(ctx);
1080 static u64 spufs_signal1_type_get(void *data)
1082 struct spu_context *ctx = data;
1086 ret = __spufs_signal1_type_get(data);
1091 DEFINE_SIMPLE_ATTRIBUTE(spufs_signal1_type, spufs_signal1_type_get,
1092 spufs_signal1_type_set, "%llu");
1094 static void spufs_signal2_type_set(void *data, u64 val)
1096 struct spu_context *ctx = data;
1099 ctx->ops->signal2_type_set(ctx, val);
1103 static u64 __spufs_signal2_type_get(void *data)
1105 struct spu_context *ctx = data;
1106 return ctx->ops->signal2_type_get(ctx);
1109 static u64 spufs_signal2_type_get(void *data)
1111 struct spu_context *ctx = data;
1115 ret = __spufs_signal2_type_get(data);
1120 DEFINE_SIMPLE_ATTRIBUTE(spufs_signal2_type, spufs_signal2_type_get,
1121 spufs_signal2_type_set, "%llu");
1124 static unsigned long spufs_mss_mmap_nopfn(struct vm_area_struct *vma,
1125 unsigned long address)
1127 return spufs_ps_nopfn(vma, address, 0x0000, 0x1000);
1130 static struct vm_operations_struct spufs_mss_mmap_vmops = {
1131 .nopfn = spufs_mss_mmap_nopfn,
1135 * mmap support for problem state MFC DMA area [0x0000 - 0x0fff].
1137 static int spufs_mss_mmap(struct file *file, struct vm_area_struct *vma)
1139 if (!(vma->vm_flags & VM_SHARED))
1142 vma->vm_flags |= VM_IO | VM_PFNMAP;
1143 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
1144 | _PAGE_NO_CACHE | _PAGE_GUARDED);
1146 vma->vm_ops = &spufs_mss_mmap_vmops;
1149 #else /* SPUFS_MMAP_4K */
1150 #define spufs_mss_mmap NULL
1151 #endif /* !SPUFS_MMAP_4K */
1153 static int spufs_mss_open(struct inode *inode, struct file *file)
1155 struct spufs_inode_info *i = SPUFS_I(inode);
1156 struct spu_context *ctx = i->i_ctx;
1158 file->private_data = i->i_ctx;
1160 mutex_lock(&ctx->mapping_lock);
1161 if (!i->i_openers++)
1162 ctx->mss = inode->i_mapping;
1163 mutex_unlock(&ctx->mapping_lock);
1164 return nonseekable_open(inode, file);
1168 spufs_mss_release(struct inode *inode, struct file *file)
1170 struct spufs_inode_info *i = SPUFS_I(inode);
1171 struct spu_context *ctx = i->i_ctx;
1173 mutex_lock(&ctx->mapping_lock);
1174 if (!--i->i_openers)
1176 mutex_unlock(&ctx->mapping_lock);
1180 static const struct file_operations spufs_mss_fops = {
1181 .open = spufs_mss_open,
1182 .release = spufs_mss_release,
1183 .mmap = spufs_mss_mmap,
1186 static unsigned long spufs_psmap_mmap_nopfn(struct vm_area_struct *vma,
1187 unsigned long address)
1189 return spufs_ps_nopfn(vma, address, 0x0000, 0x20000);
1192 static struct vm_operations_struct spufs_psmap_mmap_vmops = {
1193 .nopfn = spufs_psmap_mmap_nopfn,
1197 * mmap support for full problem state area [0x00000 - 0x1ffff].
1199 static int spufs_psmap_mmap(struct file *file, struct vm_area_struct *vma)
1201 if (!(vma->vm_flags & VM_SHARED))
1204 vma->vm_flags |= VM_IO | VM_PFNMAP;
1205 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
1206 | _PAGE_NO_CACHE | _PAGE_GUARDED);
1208 vma->vm_ops = &spufs_psmap_mmap_vmops;
1212 static int spufs_psmap_open(struct inode *inode, struct file *file)
1214 struct spufs_inode_info *i = SPUFS_I(inode);
1215 struct spu_context *ctx = i->i_ctx;
1217 mutex_lock(&ctx->mapping_lock);
1218 file->private_data = i->i_ctx;
1219 if (!i->i_openers++)
1220 ctx->psmap = inode->i_mapping;
1221 mutex_unlock(&ctx->mapping_lock);
1222 return nonseekable_open(inode, file);
1226 spufs_psmap_release(struct inode *inode, struct file *file)
1228 struct spufs_inode_info *i = SPUFS_I(inode);
1229 struct spu_context *ctx = i->i_ctx;
1231 mutex_lock(&ctx->mapping_lock);
1232 if (!--i->i_openers)
1234 mutex_unlock(&ctx->mapping_lock);
1238 static const struct file_operations spufs_psmap_fops = {
1239 .open = spufs_psmap_open,
1240 .release = spufs_psmap_release,
1241 .mmap = spufs_psmap_mmap,
1246 static unsigned long spufs_mfc_mmap_nopfn(struct vm_area_struct *vma,
1247 unsigned long address)
1249 return spufs_ps_nopfn(vma, address, 0x3000, 0x1000);
1252 static struct vm_operations_struct spufs_mfc_mmap_vmops = {
1253 .nopfn = spufs_mfc_mmap_nopfn,
1257 * mmap support for problem state MFC DMA area [0x0000 - 0x0fff].
1259 static int spufs_mfc_mmap(struct file *file, struct vm_area_struct *vma)
1261 if (!(vma->vm_flags & VM_SHARED))
1264 vma->vm_flags |= VM_IO | VM_PFNMAP;
1265 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
1266 | _PAGE_NO_CACHE | _PAGE_GUARDED);
1268 vma->vm_ops = &spufs_mfc_mmap_vmops;
1271 #else /* SPUFS_MMAP_4K */
1272 #define spufs_mfc_mmap NULL
1273 #endif /* !SPUFS_MMAP_4K */
1275 static int spufs_mfc_open(struct inode *inode, struct file *file)
1277 struct spufs_inode_info *i = SPUFS_I(inode);
1278 struct spu_context *ctx = i->i_ctx;
1280 /* we don't want to deal with DMA into other processes */
1281 if (ctx->owner != current->mm)
1284 if (atomic_read(&inode->i_count) != 1)
1287 mutex_lock(&ctx->mapping_lock);
1288 file->private_data = ctx;
1289 if (!i->i_openers++)
1290 ctx->mfc = inode->i_mapping;
1291 mutex_unlock(&ctx->mapping_lock);
1292 return nonseekable_open(inode, file);
1296 spufs_mfc_release(struct inode *inode, struct file *file)
1298 struct spufs_inode_info *i = SPUFS_I(inode);
1299 struct spu_context *ctx = i->i_ctx;
1301 mutex_lock(&ctx->mapping_lock);
1302 if (!--i->i_openers)
1304 mutex_unlock(&ctx->mapping_lock);
1308 /* interrupt-level mfc callback function. */
1309 void spufs_mfc_callback(struct spu *spu)
1311 struct spu_context *ctx = spu->ctx;
1313 wake_up_all(&ctx->mfc_wq);
1315 pr_debug("%s %s\n", __FUNCTION__, spu->name);
1316 if (ctx->mfc_fasync) {
1317 u32 free_elements, tagstatus;
1320 /* no need for spu_acquire in interrupt context */
1321 free_elements = ctx->ops->get_mfc_free_elements(ctx);
1322 tagstatus = ctx->ops->read_mfc_tagstatus(ctx);
1325 if (free_elements & 0xffff)
1327 if (tagstatus & ctx->tagwait)
1330 kill_fasync(&ctx->mfc_fasync, SIGIO, mask);
1334 static int spufs_read_mfc_tagstatus(struct spu_context *ctx, u32 *status)
1336 /* See if there is one tag group is complete */
1337 /* FIXME we need locking around tagwait */
1338 *status = ctx->ops->read_mfc_tagstatus(ctx) & ctx->tagwait;
1339 ctx->tagwait &= ~*status;
1343 /* enable interrupt waiting for any tag group,
1344 may silently fail if interrupts are already enabled */
1345 ctx->ops->set_mfc_query(ctx, ctx->tagwait, 1);
1349 static ssize_t spufs_mfc_read(struct file *file, char __user *buffer,
1350 size_t size, loff_t *pos)
1352 struct spu_context *ctx = file->private_data;
1360 if (file->f_flags & O_NONBLOCK) {
1361 status = ctx->ops->read_mfc_tagstatus(ctx);
1362 if (!(status & ctx->tagwait))
1365 ctx->tagwait &= ~status;
1367 ret = spufs_wait(ctx->mfc_wq,
1368 spufs_read_mfc_tagstatus(ctx, &status));
1376 if (copy_to_user(buffer, &status, 4))
1383 static int spufs_check_valid_dma(struct mfc_dma_command *cmd)
1385 pr_debug("queueing DMA %x %lx %x %x %x\n", cmd->lsa,
1386 cmd->ea, cmd->size, cmd->tag, cmd->cmd);
1397 pr_debug("invalid DMA opcode %x\n", cmd->cmd);
1401 if ((cmd->lsa & 0xf) != (cmd->ea &0xf)) {
1402 pr_debug("invalid DMA alignment, ea %lx lsa %x\n",
1407 switch (cmd->size & 0xf) {
1428 pr_debug("invalid DMA alignment %x for size %x\n",
1429 cmd->lsa & 0xf, cmd->size);
1433 if (cmd->size > 16 * 1024) {
1434 pr_debug("invalid DMA size %x\n", cmd->size);
1438 if (cmd->tag & 0xfff0) {
1439 /* we reserve the higher tag numbers for kernel use */
1440 pr_debug("invalid DMA tag\n");
1445 /* not supported in this version */
1446 pr_debug("invalid DMA class\n");
1453 static int spu_send_mfc_command(struct spu_context *ctx,
1454 struct mfc_dma_command cmd,
1457 *error = ctx->ops->send_mfc_command(ctx, &cmd);
1458 if (*error == -EAGAIN) {
1459 /* wait for any tag group to complete
1460 so we have space for the new command */
1461 ctx->ops->set_mfc_query(ctx, ctx->tagwait, 1);
1462 /* try again, because the queue might be
1464 *error = ctx->ops->send_mfc_command(ctx, &cmd);
1465 if (*error == -EAGAIN)
1471 static ssize_t spufs_mfc_write(struct file *file, const char __user *buffer,
1472 size_t size, loff_t *pos)
1474 struct spu_context *ctx = file->private_data;
1475 struct mfc_dma_command cmd;
1478 if (size != sizeof cmd)
1482 if (copy_from_user(&cmd, buffer, sizeof cmd))
1485 ret = spufs_check_valid_dma(&cmd);
1489 ret = spu_acquire_runnable(ctx, 0);
1493 if (file->f_flags & O_NONBLOCK) {
1494 ret = ctx->ops->send_mfc_command(ctx, &cmd);
1497 ret = spufs_wait(ctx->mfc_wq,
1498 spu_send_mfc_command(ctx, cmd, &status));
1506 ctx->tagwait |= 1 << cmd.tag;
1515 static unsigned int spufs_mfc_poll(struct file *file,poll_table *wait)
1517 struct spu_context *ctx = file->private_data;
1518 u32 free_elements, tagstatus;
1521 poll_wait(file, &ctx->mfc_wq, wait);
1524 ctx->ops->set_mfc_query(ctx, ctx->tagwait, 2);
1525 free_elements = ctx->ops->get_mfc_free_elements(ctx);
1526 tagstatus = ctx->ops->read_mfc_tagstatus(ctx);
1530 if (free_elements & 0xffff)
1531 mask |= POLLOUT | POLLWRNORM;
1532 if (tagstatus & ctx->tagwait)
1533 mask |= POLLIN | POLLRDNORM;
1535 pr_debug("%s: free %d tagstatus %d tagwait %d\n", __FUNCTION__,
1536 free_elements, tagstatus, ctx->tagwait);
1541 static int spufs_mfc_flush(struct file *file, fl_owner_t id)
1543 struct spu_context *ctx = file->private_data;
1548 /* this currently hangs */
1549 ret = spufs_wait(ctx->mfc_wq,
1550 ctx->ops->set_mfc_query(ctx, ctx->tagwait, 2));
1553 ret = spufs_wait(ctx->mfc_wq,
1554 ctx->ops->read_mfc_tagstatus(ctx) == ctx->tagwait);
1564 static int spufs_mfc_fsync(struct file *file, struct dentry *dentry,
1567 return spufs_mfc_flush(file, NULL);
1570 static int spufs_mfc_fasync(int fd, struct file *file, int on)
1572 struct spu_context *ctx = file->private_data;
1574 return fasync_helper(fd, file, on, &ctx->mfc_fasync);
1577 static const struct file_operations spufs_mfc_fops = {
1578 .open = spufs_mfc_open,
1579 .release = spufs_mfc_release,
1580 .read = spufs_mfc_read,
1581 .write = spufs_mfc_write,
1582 .poll = spufs_mfc_poll,
1583 .flush = spufs_mfc_flush,
1584 .fsync = spufs_mfc_fsync,
1585 .fasync = spufs_mfc_fasync,
1586 .mmap = spufs_mfc_mmap,
1589 static void spufs_npc_set(void *data, u64 val)
1591 struct spu_context *ctx = data;
1593 ctx->ops->npc_write(ctx, val);
1597 static u64 spufs_npc_get(void *data)
1599 struct spu_context *ctx = data;
1602 ret = ctx->ops->npc_read(ctx);
1606 DEFINE_SIMPLE_ATTRIBUTE(spufs_npc_ops, spufs_npc_get, spufs_npc_set,
1609 static void spufs_decr_set(void *data, u64 val)
1611 struct spu_context *ctx = data;
1612 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1613 spu_acquire_saved(ctx);
1614 lscsa->decr.slot[0] = (u32) val;
1618 static u64 __spufs_decr_get(void *data)
1620 struct spu_context *ctx = data;
1621 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1622 return lscsa->decr.slot[0];
1625 static u64 spufs_decr_get(void *data)
1627 struct spu_context *ctx = data;
1629 spu_acquire_saved(ctx);
1630 ret = __spufs_decr_get(data);
1634 DEFINE_SIMPLE_ATTRIBUTE(spufs_decr_ops, spufs_decr_get, spufs_decr_set,
1637 static void spufs_decr_status_set(void *data, u64 val)
1639 struct spu_context *ctx = data;
1640 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1641 spu_acquire_saved(ctx);
1642 lscsa->decr_status.slot[0] = (u32) val;
1646 static u64 __spufs_decr_status_get(void *data)
1648 struct spu_context *ctx = data;
1649 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1650 return lscsa->decr_status.slot[0];
1653 static u64 spufs_decr_status_get(void *data)
1655 struct spu_context *ctx = data;
1657 spu_acquire_saved(ctx);
1658 ret = __spufs_decr_status_get(data);
1662 DEFINE_SIMPLE_ATTRIBUTE(spufs_decr_status_ops, spufs_decr_status_get,
1663 spufs_decr_status_set, "0x%llx\n")
1665 static void spufs_event_mask_set(void *data, u64 val)
1667 struct spu_context *ctx = data;
1668 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1669 spu_acquire_saved(ctx);
1670 lscsa->event_mask.slot[0] = (u32) val;
1674 static u64 __spufs_event_mask_get(void *data)
1676 struct spu_context *ctx = data;
1677 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1678 return lscsa->event_mask.slot[0];
1681 static u64 spufs_event_mask_get(void *data)
1683 struct spu_context *ctx = data;
1685 spu_acquire_saved(ctx);
1686 ret = __spufs_event_mask_get(data);
1690 DEFINE_SIMPLE_ATTRIBUTE(spufs_event_mask_ops, spufs_event_mask_get,
1691 spufs_event_mask_set, "0x%llx\n")
1693 static u64 __spufs_event_status_get(void *data)
1695 struct spu_context *ctx = data;
1696 struct spu_state *state = &ctx->csa;
1698 stat = state->spu_chnlcnt_RW[0];
1700 return state->spu_chnldata_RW[0];
1704 static u64 spufs_event_status_get(void *data)
1706 struct spu_context *ctx = data;
1709 spu_acquire_saved(ctx);
1710 ret = __spufs_event_status_get(data);
1714 DEFINE_SIMPLE_ATTRIBUTE(spufs_event_status_ops, spufs_event_status_get,
1717 static void spufs_srr0_set(void *data, u64 val)
1719 struct spu_context *ctx = data;
1720 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1721 spu_acquire_saved(ctx);
1722 lscsa->srr0.slot[0] = (u32) val;
1726 static u64 spufs_srr0_get(void *data)
1728 struct spu_context *ctx = data;
1729 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1731 spu_acquire_saved(ctx);
1732 ret = lscsa->srr0.slot[0];
1736 DEFINE_SIMPLE_ATTRIBUTE(spufs_srr0_ops, spufs_srr0_get, spufs_srr0_set,
1739 static u64 spufs_id_get(void *data)
1741 struct spu_context *ctx = data;
1745 if (ctx->state == SPU_STATE_RUNNABLE)
1746 num = ctx->spu->number;
1748 num = (unsigned int)-1;
1753 DEFINE_SIMPLE_ATTRIBUTE(spufs_id_ops, spufs_id_get, NULL, "0x%llx\n")
1755 static u64 __spufs_object_id_get(void *data)
1757 struct spu_context *ctx = data;
1758 return ctx->object_id;
1761 static u64 spufs_object_id_get(void *data)
1763 /* FIXME: Should there really be no locking here? */
1764 return __spufs_object_id_get(data);
1767 static void spufs_object_id_set(void *data, u64 id)
1769 struct spu_context *ctx = data;
1770 ctx->object_id = id;
1773 DEFINE_SIMPLE_ATTRIBUTE(spufs_object_id_ops, spufs_object_id_get,
1774 spufs_object_id_set, "0x%llx\n");
1776 static u64 __spufs_lslr_get(void *data)
1778 struct spu_context *ctx = data;
1779 return ctx->csa.priv2.spu_lslr_RW;
1782 static u64 spufs_lslr_get(void *data)
1784 struct spu_context *ctx = data;
1787 spu_acquire_saved(ctx);
1788 ret = __spufs_lslr_get(data);
1793 DEFINE_SIMPLE_ATTRIBUTE(spufs_lslr_ops, spufs_lslr_get, NULL, "0x%llx\n")
1795 static int spufs_info_open(struct inode *inode, struct file *file)
1797 struct spufs_inode_info *i = SPUFS_I(inode);
1798 struct spu_context *ctx = i->i_ctx;
1799 file->private_data = ctx;
1803 static int spufs_caps_show(struct seq_file *s, void *private)
1805 struct spu_context *ctx = s->private;
1807 if (!(ctx->flags & SPU_CREATE_NOSCHED))
1808 seq_puts(s, "sched\n");
1809 if (!(ctx->flags & SPU_CREATE_ISOLATE))
1810 seq_puts(s, "step\n");
1814 static int spufs_caps_open(struct inode *inode, struct file *file)
1816 return single_open(file, spufs_caps_show, SPUFS_I(inode)->i_ctx);
1819 static const struct file_operations spufs_caps_fops = {
1820 .open = spufs_caps_open,
1822 .llseek = seq_lseek,
1823 .release = single_release,
1826 static ssize_t __spufs_mbox_info_read(struct spu_context *ctx,
1827 char __user *buf, size_t len, loff_t *pos)
1832 mbox_stat = ctx->csa.prob.mb_stat_R;
1833 if (mbox_stat & 0x0000ff) {
1834 data = ctx->csa.prob.pu_mb_R;
1837 return simple_read_from_buffer(buf, len, pos, &data, sizeof data);
1840 static ssize_t spufs_mbox_info_read(struct file *file, char __user *buf,
1841 size_t len, loff_t *pos)
1844 struct spu_context *ctx = file->private_data;
1846 if (!access_ok(VERIFY_WRITE, buf, len))
1849 spu_acquire_saved(ctx);
1850 spin_lock(&ctx->csa.register_lock);
1851 ret = __spufs_mbox_info_read(ctx, buf, len, pos);
1852 spin_unlock(&ctx->csa.register_lock);
1858 static const struct file_operations spufs_mbox_info_fops = {
1859 .open = spufs_info_open,
1860 .read = spufs_mbox_info_read,
1861 .llseek = generic_file_llseek,
1864 static ssize_t __spufs_ibox_info_read(struct spu_context *ctx,
1865 char __user *buf, size_t len, loff_t *pos)
1870 ibox_stat = ctx->csa.prob.mb_stat_R;
1871 if (ibox_stat & 0xff0000) {
1872 data = ctx->csa.priv2.puint_mb_R;
1875 return simple_read_from_buffer(buf, len, pos, &data, sizeof data);
1878 static ssize_t spufs_ibox_info_read(struct file *file, char __user *buf,
1879 size_t len, loff_t *pos)
1881 struct spu_context *ctx = file->private_data;
1884 if (!access_ok(VERIFY_WRITE, buf, len))
1887 spu_acquire_saved(ctx);
1888 spin_lock(&ctx->csa.register_lock);
1889 ret = __spufs_ibox_info_read(ctx, buf, len, pos);
1890 spin_unlock(&ctx->csa.register_lock);
1896 static const struct file_operations spufs_ibox_info_fops = {
1897 .open = spufs_info_open,
1898 .read = spufs_ibox_info_read,
1899 .llseek = generic_file_llseek,
1902 static ssize_t __spufs_wbox_info_read(struct spu_context *ctx,
1903 char __user *buf, size_t len, loff_t *pos)
1909 wbox_stat = ctx->csa.prob.mb_stat_R;
1910 cnt = 4 - ((wbox_stat & 0x00ff00) >> 8);
1911 for (i = 0; i < cnt; i++) {
1912 data[i] = ctx->csa.spu_mailbox_data[i];
1915 return simple_read_from_buffer(buf, len, pos, &data,
1919 static ssize_t spufs_wbox_info_read(struct file *file, char __user *buf,
1920 size_t len, loff_t *pos)
1922 struct spu_context *ctx = file->private_data;
1925 if (!access_ok(VERIFY_WRITE, buf, len))
1928 spu_acquire_saved(ctx);
1929 spin_lock(&ctx->csa.register_lock);
1930 ret = __spufs_wbox_info_read(ctx, buf, len, pos);
1931 spin_unlock(&ctx->csa.register_lock);
1937 static const struct file_operations spufs_wbox_info_fops = {
1938 .open = spufs_info_open,
1939 .read = spufs_wbox_info_read,
1940 .llseek = generic_file_llseek,
1943 static ssize_t __spufs_dma_info_read(struct spu_context *ctx,
1944 char __user *buf, size_t len, loff_t *pos)
1946 struct spu_dma_info info;
1947 struct mfc_cq_sr *qp, *spuqp;
1950 info.dma_info_type = ctx->csa.priv2.spu_tag_status_query_RW;
1951 info.dma_info_mask = ctx->csa.lscsa->tag_mask.slot[0];
1952 info.dma_info_status = ctx->csa.spu_chnldata_RW[24];
1953 info.dma_info_stall_and_notify = ctx->csa.spu_chnldata_RW[25];
1954 info.dma_info_atomic_command_status = ctx->csa.spu_chnldata_RW[27];
1955 for (i = 0; i < 16; i++) {
1956 qp = &info.dma_info_command_data[i];
1957 spuqp = &ctx->csa.priv2.spuq[i];
1959 qp->mfc_cq_data0_RW = spuqp->mfc_cq_data0_RW;
1960 qp->mfc_cq_data1_RW = spuqp->mfc_cq_data1_RW;
1961 qp->mfc_cq_data2_RW = spuqp->mfc_cq_data2_RW;
1962 qp->mfc_cq_data3_RW = spuqp->mfc_cq_data3_RW;
1965 return simple_read_from_buffer(buf, len, pos, &info,
1969 static ssize_t spufs_dma_info_read(struct file *file, char __user *buf,
1970 size_t len, loff_t *pos)
1972 struct spu_context *ctx = file->private_data;
1975 if (!access_ok(VERIFY_WRITE, buf, len))
1978 spu_acquire_saved(ctx);
1979 spin_lock(&ctx->csa.register_lock);
1980 ret = __spufs_dma_info_read(ctx, buf, len, pos);
1981 spin_unlock(&ctx->csa.register_lock);
1987 static const struct file_operations spufs_dma_info_fops = {
1988 .open = spufs_info_open,
1989 .read = spufs_dma_info_read,
1992 static ssize_t __spufs_proxydma_info_read(struct spu_context *ctx,
1993 char __user *buf, size_t len, loff_t *pos)
1995 struct spu_proxydma_info info;
1996 struct mfc_cq_sr *qp, *puqp;
1997 int ret = sizeof info;
2003 if (!access_ok(VERIFY_WRITE, buf, len))
2006 info.proxydma_info_type = ctx->csa.prob.dma_querytype_RW;
2007 info.proxydma_info_mask = ctx->csa.prob.dma_querymask_RW;
2008 info.proxydma_info_status = ctx->csa.prob.dma_tagstatus_R;
2009 for (i = 0; i < 8; i++) {
2010 qp = &info.proxydma_info_command_data[i];
2011 puqp = &ctx->csa.priv2.puq[i];
2013 qp->mfc_cq_data0_RW = puqp->mfc_cq_data0_RW;
2014 qp->mfc_cq_data1_RW = puqp->mfc_cq_data1_RW;
2015 qp->mfc_cq_data2_RW = puqp->mfc_cq_data2_RW;
2016 qp->mfc_cq_data3_RW = puqp->mfc_cq_data3_RW;
2019 return simple_read_from_buffer(buf, len, pos, &info,
2023 static ssize_t spufs_proxydma_info_read(struct file *file, char __user *buf,
2024 size_t len, loff_t *pos)
2026 struct spu_context *ctx = file->private_data;
2029 spu_acquire_saved(ctx);
2030 spin_lock(&ctx->csa.register_lock);
2031 ret = __spufs_proxydma_info_read(ctx, buf, len, pos);
2032 spin_unlock(&ctx->csa.register_lock);
2038 static const struct file_operations spufs_proxydma_info_fops = {
2039 .open = spufs_info_open,
2040 .read = spufs_proxydma_info_read,
2043 static int spufs_show_tid(struct seq_file *s, void *private)
2045 struct spu_context *ctx = s->private;
2047 seq_printf(s, "%d\n", ctx->tid);
2051 static int spufs_tid_open(struct inode *inode, struct file *file)
2053 return single_open(file, spufs_show_tid, SPUFS_I(inode)->i_ctx);
2056 static const struct file_operations spufs_tid_fops = {
2057 .open = spufs_tid_open,
2059 .llseek = seq_lseek,
2060 .release = single_release,
2063 static const char *ctx_state_names[] = {
2064 "user", "system", "iowait", "loaded"
2067 static unsigned long long spufs_acct_time(struct spu_context *ctx,
2068 enum spuctx_execution_state state)
2070 unsigned long time = ctx->stats.times[state];
2072 if (ctx->stats.execution_state == state)
2073 time += jiffies - ctx->stats.tstamp;
2075 return jiffies_to_msecs(time);
2078 static unsigned long long spufs_slb_flts(struct spu_context *ctx)
2080 unsigned long long slb_flts = ctx->stats.slb_flt;
2082 if (ctx->state == SPU_STATE_RUNNABLE) {
2083 slb_flts += (ctx->spu->stats.slb_flt -
2084 ctx->stats.slb_flt_base);
2090 static unsigned long long spufs_class2_intrs(struct spu_context *ctx)
2092 unsigned long long class2_intrs = ctx->stats.class2_intr;
2094 if (ctx->state == SPU_STATE_RUNNABLE) {
2095 class2_intrs += (ctx->spu->stats.class2_intr -
2096 ctx->stats.class2_intr_base);
2099 return class2_intrs;
2103 static int spufs_show_stat(struct seq_file *s, void *private)
2105 struct spu_context *ctx = s->private;
2108 seq_printf(s, "%s %llu %llu %llu %llu "
2109 "%llu %llu %llu %llu %llu %llu %llu %llu\n",
2110 ctx_state_names[ctx->stats.execution_state],
2111 spufs_acct_time(ctx, SPUCTX_UTIL_USER),
2112 spufs_acct_time(ctx, SPUCTX_UTIL_SYSTEM),
2113 spufs_acct_time(ctx, SPUCTX_UTIL_IOWAIT),
2114 spufs_acct_time(ctx, SPUCTX_UTIL_LOADED),
2115 ctx->stats.vol_ctx_switch,
2116 ctx->stats.invol_ctx_switch,
2117 spufs_slb_flts(ctx),
2118 ctx->stats.hash_flt,
2121 spufs_class2_intrs(ctx),
2122 ctx->stats.libassist);
2127 static int spufs_stat_open(struct inode *inode, struct file *file)
2129 return single_open(file, spufs_show_stat, SPUFS_I(inode)->i_ctx);
2132 static const struct file_operations spufs_stat_fops = {
2133 .open = spufs_stat_open,
2135 .llseek = seq_lseek,
2136 .release = single_release,
2140 struct tree_descr spufs_dir_contents[] = {
2141 { "capabilities", &spufs_caps_fops, 0444, },
2142 { "mem", &spufs_mem_fops, 0666, },
2143 { "regs", &spufs_regs_fops, 0666, },
2144 { "mbox", &spufs_mbox_fops, 0444, },
2145 { "ibox", &spufs_ibox_fops, 0444, },
2146 { "wbox", &spufs_wbox_fops, 0222, },
2147 { "mbox_stat", &spufs_mbox_stat_fops, 0444, },
2148 { "ibox_stat", &spufs_ibox_stat_fops, 0444, },
2149 { "wbox_stat", &spufs_wbox_stat_fops, 0444, },
2150 { "signal1", &spufs_signal1_fops, 0666, },
2151 { "signal2", &spufs_signal2_fops, 0666, },
2152 { "signal1_type", &spufs_signal1_type, 0666, },
2153 { "signal2_type", &spufs_signal2_type, 0666, },
2154 { "cntl", &spufs_cntl_fops, 0666, },
2155 { "fpcr", &spufs_fpcr_fops, 0666, },
2156 { "lslr", &spufs_lslr_ops, 0444, },
2157 { "mfc", &spufs_mfc_fops, 0666, },
2158 { "mss", &spufs_mss_fops, 0666, },
2159 { "npc", &spufs_npc_ops, 0666, },
2160 { "srr0", &spufs_srr0_ops, 0666, },
2161 { "decr", &spufs_decr_ops, 0666, },
2162 { "decr_status", &spufs_decr_status_ops, 0666, },
2163 { "event_mask", &spufs_event_mask_ops, 0666, },
2164 { "event_status", &spufs_event_status_ops, 0444, },
2165 { "psmap", &spufs_psmap_fops, 0666, },
2166 { "phys-id", &spufs_id_ops, 0666, },
2167 { "object-id", &spufs_object_id_ops, 0666, },
2168 { "mbox_info", &spufs_mbox_info_fops, 0444, },
2169 { "ibox_info", &spufs_ibox_info_fops, 0444, },
2170 { "wbox_info", &spufs_wbox_info_fops, 0444, },
2171 { "dma_info", &spufs_dma_info_fops, 0444, },
2172 { "proxydma_info", &spufs_proxydma_info_fops, 0444, },
2173 { "tid", &spufs_tid_fops, 0444, },
2174 { "stat", &spufs_stat_fops, 0444, },
2178 struct tree_descr spufs_dir_nosched_contents[] = {
2179 { "capabilities", &spufs_caps_fops, 0444, },
2180 { "mem", &spufs_mem_fops, 0666, },
2181 { "mbox", &spufs_mbox_fops, 0444, },
2182 { "ibox", &spufs_ibox_fops, 0444, },
2183 { "wbox", &spufs_wbox_fops, 0222, },
2184 { "mbox_stat", &spufs_mbox_stat_fops, 0444, },
2185 { "ibox_stat", &spufs_ibox_stat_fops, 0444, },
2186 { "wbox_stat", &spufs_wbox_stat_fops, 0444, },
2187 { "signal1", &spufs_signal1_fops, 0666, },
2188 { "signal2", &spufs_signal2_fops, 0666, },
2189 { "signal1_type", &spufs_signal1_type, 0666, },
2190 { "signal2_type", &spufs_signal2_type, 0666, },
2191 { "mss", &spufs_mss_fops, 0666, },
2192 { "mfc", &spufs_mfc_fops, 0666, },
2193 { "cntl", &spufs_cntl_fops, 0666, },
2194 { "npc", &spufs_npc_ops, 0666, },
2195 { "psmap", &spufs_psmap_fops, 0666, },
2196 { "phys-id", &spufs_id_ops, 0666, },
2197 { "object-id", &spufs_object_id_ops, 0666, },
2198 { "tid", &spufs_tid_fops, 0444, },
2199 { "stat", &spufs_stat_fops, 0444, },
2203 struct spufs_coredump_reader spufs_coredump_read[] = {
2204 { "regs", __spufs_regs_read, NULL, 128 * 16 },
2205 { "fpcr", __spufs_fpcr_read, NULL, 16 },
2206 { "lslr", NULL, __spufs_lslr_get, 11 },
2207 { "decr", NULL, __spufs_decr_get, 11 },
2208 { "decr_status", NULL, __spufs_decr_status_get, 11 },
2209 { "mem", __spufs_mem_read, NULL, 256 * 1024, },
2210 { "signal1", __spufs_signal1_read, NULL, 4 },
2211 { "signal1_type", NULL, __spufs_signal1_type_get, 2 },
2212 { "signal2", __spufs_signal2_read, NULL, 4 },
2213 { "signal2_type", NULL, __spufs_signal2_type_get, 2 },
2214 { "event_mask", NULL, __spufs_event_mask_get, 8 },
2215 { "event_status", NULL, __spufs_event_status_get, 8 },
2216 { "mbox_info", __spufs_mbox_info_read, NULL, 4 },
2217 { "ibox_info", __spufs_ibox_info_read, NULL, 4 },
2218 { "wbox_info", __spufs_wbox_info_read, NULL, 16 },
2219 { "dma_info", __spufs_dma_info_read, NULL, 69 * 8 },
2220 { "proxydma_info", __spufs_proxydma_info_read, NULL, 35 * 8 },
2221 { "object-id", NULL, __spufs_object_id_get, 19 },
2224 int spufs_coredump_num_notes = ARRAY_SIZE(spufs_coredump_read) - 1;