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>
33 #include <asm/semaphore.h>
35 #include <asm/spu_info.h>
36 #include <asm/uaccess.h>
40 #define SPUFS_MMAP_4K (PAGE_SIZE == 0x1000)
43 spufs_mem_open(struct inode *inode, struct file *file)
45 struct spufs_inode_info *i = SPUFS_I(inode);
46 struct spu_context *ctx = i->i_ctx;
48 spin_lock(&ctx->mapping_lock);
49 file->private_data = ctx;
51 ctx->local_store = inode->i_mapping;
52 spin_unlock(&ctx->mapping_lock);
57 spufs_mem_release(struct inode *inode, struct file *file)
59 struct spufs_inode_info *i = SPUFS_I(inode);
60 struct spu_context *ctx = i->i_ctx;
62 spin_lock(&ctx->mapping_lock);
64 ctx->local_store = NULL;
65 spin_unlock(&ctx->mapping_lock);
70 __spufs_mem_read(struct spu_context *ctx, char __user *buffer,
71 size_t size, loff_t *pos)
73 char *local_store = ctx->ops->get_ls(ctx);
74 return simple_read_from_buffer(buffer, size, pos, local_store,
79 spufs_mem_read(struct file *file, char __user *buffer,
80 size_t size, loff_t *pos)
82 struct spu_context *ctx = file->private_data;
86 ret = __spufs_mem_read(ctx, buffer, size, pos);
92 spufs_mem_write(struct file *file, const char __user *buffer,
93 size_t size, loff_t *ppos)
95 struct spu_context *ctx = file->private_data;
104 if (size > LS_SIZE - pos)
105 size = LS_SIZE - pos;
108 local_store = ctx->ops->get_ls(ctx);
109 ret = copy_from_user(local_store + pos, buffer, size);
118 static unsigned long spufs_mem_mmap_nopfn(struct vm_area_struct *vma,
119 unsigned long address)
121 struct spu_context *ctx = vma->vm_file->private_data;
122 unsigned long pfn, offset, addr0 = address;
123 #ifdef CONFIG_SPU_FS_64K_LS
124 struct spu_state *csa = &ctx->csa;
127 /* Check what page size we are using */
128 psize = get_slice_psize(vma->vm_mm, address);
130 /* Some sanity checking */
131 BUG_ON(csa->use_big_pages != (psize == MMU_PAGE_64K));
133 /* Wow, 64K, cool, we need to align the address though */
134 if (csa->use_big_pages) {
135 BUG_ON(vma->vm_start & 0xffff);
136 address &= ~0xfffful;
138 #endif /* CONFIG_SPU_FS_64K_LS */
140 offset = (address - vma->vm_start) + (vma->vm_pgoff << PAGE_SHIFT);
141 if (offset >= LS_SIZE)
144 pr_debug("spufs_mem_mmap_nopfn address=0x%lx -> 0x%lx, offset=0x%lx\n",
145 addr0, address, offset);
149 if (ctx->state == SPU_STATE_SAVED) {
150 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
152 pfn = vmalloc_to_pfn(ctx->csa.lscsa->ls + offset);
154 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
156 pfn = (ctx->spu->local_store_phys + offset) >> PAGE_SHIFT;
158 vm_insert_pfn(vma, address, pfn);
162 return NOPFN_REFAULT;
166 static struct vm_operations_struct spufs_mem_mmap_vmops = {
167 .nopfn = spufs_mem_mmap_nopfn,
170 static int spufs_mem_mmap(struct file *file, struct vm_area_struct *vma)
172 #ifdef CONFIG_SPU_FS_64K_LS
173 struct spu_context *ctx = file->private_data;
174 struct spu_state *csa = &ctx->csa;
176 /* Sanity check VMA alignment */
177 if (csa->use_big_pages) {
178 pr_debug("spufs_mem_mmap 64K, start=0x%lx, end=0x%lx,"
179 " pgoff=0x%lx\n", vma->vm_start, vma->vm_end,
181 if (vma->vm_start & 0xffff)
183 if (vma->vm_pgoff & 0xf)
186 #endif /* CONFIG_SPU_FS_64K_LS */
188 if (!(vma->vm_flags & VM_SHARED))
191 vma->vm_flags |= VM_IO | VM_PFNMAP;
192 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
195 vma->vm_ops = &spufs_mem_mmap_vmops;
199 #ifdef CONFIG_SPU_FS_64K_LS
200 unsigned long spufs_get_unmapped_area(struct file *file, unsigned long addr,
201 unsigned long len, unsigned long pgoff,
204 struct spu_context *ctx = file->private_data;
205 struct spu_state *csa = &ctx->csa;
207 /* If not using big pages, fallback to normal MM g_u_a */
208 if (!csa->use_big_pages)
209 return current->mm->get_unmapped_area(file, addr, len,
212 /* Else, try to obtain a 64K pages slice */
213 return slice_get_unmapped_area(addr, len, flags,
216 #endif /* CONFIG_SPU_FS_64K_LS */
218 static const struct file_operations spufs_mem_fops = {
219 .open = spufs_mem_open,
220 .read = spufs_mem_read,
221 .write = spufs_mem_write,
222 .llseek = generic_file_llseek,
223 .mmap = spufs_mem_mmap,
224 #ifdef CONFIG_SPU_FS_64K_LS
225 .get_unmapped_area = spufs_get_unmapped_area,
229 static unsigned long spufs_ps_nopfn(struct vm_area_struct *vma,
230 unsigned long address,
231 unsigned long ps_offs,
232 unsigned long ps_size)
234 struct spu_context *ctx = vma->vm_file->private_data;
235 unsigned long area, offset = address - vma->vm_start;
238 offset += vma->vm_pgoff << PAGE_SHIFT;
239 if (offset >= ps_size)
242 /* error here usually means a signal.. we might want to test
243 * the error code more precisely though
245 ret = spu_acquire_runnable(ctx, 0);
247 return NOPFN_REFAULT;
249 area = ctx->spu->problem_phys + ps_offs;
250 vm_insert_pfn(vma, address, (area + offset) >> PAGE_SHIFT);
253 return NOPFN_REFAULT;
257 static unsigned long spufs_cntl_mmap_nopfn(struct vm_area_struct *vma,
258 unsigned long address)
260 return spufs_ps_nopfn(vma, address, 0x4000, 0x1000);
263 static struct vm_operations_struct spufs_cntl_mmap_vmops = {
264 .nopfn = spufs_cntl_mmap_nopfn,
268 * mmap support for problem state control area [0x4000 - 0x4fff].
270 static int spufs_cntl_mmap(struct file *file, struct vm_area_struct *vma)
272 if (!(vma->vm_flags & VM_SHARED))
275 vma->vm_flags |= VM_IO | VM_PFNMAP;
276 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
277 | _PAGE_NO_CACHE | _PAGE_GUARDED);
279 vma->vm_ops = &spufs_cntl_mmap_vmops;
282 #else /* SPUFS_MMAP_4K */
283 #define spufs_cntl_mmap NULL
284 #endif /* !SPUFS_MMAP_4K */
286 static u64 spufs_cntl_get(void *data)
288 struct spu_context *ctx = data;
292 val = ctx->ops->status_read(ctx);
298 static void spufs_cntl_set(void *data, u64 val)
300 struct spu_context *ctx = data;
303 ctx->ops->runcntl_write(ctx, val);
307 static int spufs_cntl_open(struct inode *inode, struct file *file)
309 struct spufs_inode_info *i = SPUFS_I(inode);
310 struct spu_context *ctx = i->i_ctx;
312 spin_lock(&ctx->mapping_lock);
313 file->private_data = ctx;
315 ctx->cntl = inode->i_mapping;
316 spin_unlock(&ctx->mapping_lock);
317 return simple_attr_open(inode, file, spufs_cntl_get,
318 spufs_cntl_set, "0x%08lx");
322 spufs_cntl_release(struct inode *inode, struct file *file)
324 struct spufs_inode_info *i = SPUFS_I(inode);
325 struct spu_context *ctx = i->i_ctx;
327 simple_attr_close(inode, file);
329 spin_lock(&ctx->mapping_lock);
332 spin_unlock(&ctx->mapping_lock);
336 static const struct file_operations spufs_cntl_fops = {
337 .open = spufs_cntl_open,
338 .release = spufs_cntl_release,
339 .read = simple_attr_read,
340 .write = simple_attr_write,
341 .mmap = spufs_cntl_mmap,
345 spufs_regs_open(struct inode *inode, struct file *file)
347 struct spufs_inode_info *i = SPUFS_I(inode);
348 file->private_data = i->i_ctx;
353 __spufs_regs_read(struct spu_context *ctx, char __user *buffer,
354 size_t size, loff_t *pos)
356 struct spu_lscsa *lscsa = ctx->csa.lscsa;
357 return simple_read_from_buffer(buffer, size, pos,
358 lscsa->gprs, sizeof lscsa->gprs);
362 spufs_regs_read(struct file *file, char __user *buffer,
363 size_t size, loff_t *pos)
366 struct spu_context *ctx = file->private_data;
368 spu_acquire_saved(ctx);
369 ret = __spufs_regs_read(ctx, buffer, size, pos);
375 spufs_regs_write(struct file *file, const char __user *buffer,
376 size_t size, loff_t *pos)
378 struct spu_context *ctx = file->private_data;
379 struct spu_lscsa *lscsa = ctx->csa.lscsa;
382 size = min_t(ssize_t, sizeof lscsa->gprs - *pos, size);
387 spu_acquire_saved(ctx);
389 ret = copy_from_user(lscsa->gprs + *pos - size,
390 buffer, size) ? -EFAULT : size;
396 static const struct file_operations spufs_regs_fops = {
397 .open = spufs_regs_open,
398 .read = spufs_regs_read,
399 .write = spufs_regs_write,
400 .llseek = generic_file_llseek,
404 __spufs_fpcr_read(struct spu_context *ctx, char __user * buffer,
405 size_t size, loff_t * pos)
407 struct spu_lscsa *lscsa = ctx->csa.lscsa;
408 return simple_read_from_buffer(buffer, size, pos,
409 &lscsa->fpcr, sizeof(lscsa->fpcr));
413 spufs_fpcr_read(struct file *file, char __user * buffer,
414 size_t size, loff_t * pos)
417 struct spu_context *ctx = file->private_data;
419 spu_acquire_saved(ctx);
420 ret = __spufs_fpcr_read(ctx, buffer, size, pos);
426 spufs_fpcr_write(struct file *file, const char __user * buffer,
427 size_t size, loff_t * pos)
429 struct spu_context *ctx = file->private_data;
430 struct spu_lscsa *lscsa = ctx->csa.lscsa;
433 size = min_t(ssize_t, sizeof(lscsa->fpcr) - *pos, size);
438 spu_acquire_saved(ctx);
440 ret = copy_from_user((char *)&lscsa->fpcr + *pos - size,
441 buffer, size) ? -EFAULT : size;
447 static const struct file_operations spufs_fpcr_fops = {
448 .open = spufs_regs_open,
449 .read = spufs_fpcr_read,
450 .write = spufs_fpcr_write,
451 .llseek = generic_file_llseek,
454 /* generic open function for all pipe-like files */
455 static int spufs_pipe_open(struct inode *inode, struct file *file)
457 struct spufs_inode_info *i = SPUFS_I(inode);
458 file->private_data = i->i_ctx;
460 return nonseekable_open(inode, file);
464 * Read as many bytes from the mailbox as possible, until
465 * one of the conditions becomes true:
467 * - no more data available in the mailbox
468 * - end of the user provided buffer
469 * - end of the mapped area
471 static ssize_t spufs_mbox_read(struct file *file, char __user *buf,
472 size_t len, loff_t *pos)
474 struct spu_context *ctx = file->private_data;
475 u32 mbox_data, __user *udata;
481 if (!access_ok(VERIFY_WRITE, buf, len))
484 udata = (void __user *)buf;
487 for (count = 0; (count + 4) <= len; count += 4, udata++) {
489 ret = ctx->ops->mbox_read(ctx, &mbox_data);
494 * at the end of the mapped area, we can fault
495 * but still need to return the data we have
496 * read successfully so far.
498 ret = __put_user(mbox_data, udata);
513 static const struct file_operations spufs_mbox_fops = {
514 .open = spufs_pipe_open,
515 .read = spufs_mbox_read,
518 static ssize_t spufs_mbox_stat_read(struct file *file, char __user *buf,
519 size_t len, loff_t *pos)
521 struct spu_context *ctx = file->private_data;
529 mbox_stat = ctx->ops->mbox_stat_read(ctx) & 0xff;
533 if (copy_to_user(buf, &mbox_stat, sizeof mbox_stat))
539 static const struct file_operations spufs_mbox_stat_fops = {
540 .open = spufs_pipe_open,
541 .read = spufs_mbox_stat_read,
544 /* low-level ibox access function */
545 size_t spu_ibox_read(struct spu_context *ctx, u32 *data)
547 return ctx->ops->ibox_read(ctx, data);
550 static int spufs_ibox_fasync(int fd, struct file *file, int on)
552 struct spu_context *ctx = file->private_data;
554 return fasync_helper(fd, file, on, &ctx->ibox_fasync);
557 /* interrupt-level ibox callback function. */
558 void spufs_ibox_callback(struct spu *spu)
560 struct spu_context *ctx = spu->ctx;
562 wake_up_all(&ctx->ibox_wq);
563 kill_fasync(&ctx->ibox_fasync, SIGIO, POLLIN);
567 * Read as many bytes from the interrupt mailbox as possible, until
568 * one of the conditions becomes true:
570 * - no more data available in the mailbox
571 * - end of the user provided buffer
572 * - end of the mapped area
574 * If the file is opened without O_NONBLOCK, we wait here until
575 * any data is available, but return when we have been able to
578 static ssize_t spufs_ibox_read(struct file *file, char __user *buf,
579 size_t len, loff_t *pos)
581 struct spu_context *ctx = file->private_data;
582 u32 ibox_data, __user *udata;
588 if (!access_ok(VERIFY_WRITE, buf, len))
591 udata = (void __user *)buf;
595 /* wait only for the first element */
597 if (file->f_flags & O_NONBLOCK) {
598 if (!spu_ibox_read(ctx, &ibox_data))
601 count = spufs_wait(ctx->ibox_wq, spu_ibox_read(ctx, &ibox_data));
606 /* if we can't write at all, return -EFAULT */
607 count = __put_user(ibox_data, udata);
611 for (count = 4, udata++; (count + 4) <= len; count += 4, udata++) {
613 ret = ctx->ops->ibox_read(ctx, &ibox_data);
617 * at the end of the mapped area, we can fault
618 * but still need to return the data we have
619 * read successfully so far.
621 ret = __put_user(ibox_data, udata);
632 static unsigned int spufs_ibox_poll(struct file *file, poll_table *wait)
634 struct spu_context *ctx = file->private_data;
637 poll_wait(file, &ctx->ibox_wq, wait);
640 mask = ctx->ops->mbox_stat_poll(ctx, POLLIN | POLLRDNORM);
646 static const struct file_operations spufs_ibox_fops = {
647 .open = spufs_pipe_open,
648 .read = spufs_ibox_read,
649 .poll = spufs_ibox_poll,
650 .fasync = spufs_ibox_fasync,
653 static ssize_t spufs_ibox_stat_read(struct file *file, char __user *buf,
654 size_t len, loff_t *pos)
656 struct spu_context *ctx = file->private_data;
663 ibox_stat = (ctx->ops->mbox_stat_read(ctx) >> 16) & 0xff;
666 if (copy_to_user(buf, &ibox_stat, sizeof ibox_stat))
672 static const struct file_operations spufs_ibox_stat_fops = {
673 .open = spufs_pipe_open,
674 .read = spufs_ibox_stat_read,
677 /* low-level mailbox write */
678 size_t spu_wbox_write(struct spu_context *ctx, u32 data)
680 return ctx->ops->wbox_write(ctx, data);
683 static int spufs_wbox_fasync(int fd, struct file *file, int on)
685 struct spu_context *ctx = file->private_data;
688 ret = fasync_helper(fd, file, on, &ctx->wbox_fasync);
693 /* interrupt-level wbox callback function. */
694 void spufs_wbox_callback(struct spu *spu)
696 struct spu_context *ctx = spu->ctx;
698 wake_up_all(&ctx->wbox_wq);
699 kill_fasync(&ctx->wbox_fasync, SIGIO, POLLOUT);
703 * Write as many bytes to the interrupt mailbox as possible, until
704 * one of the conditions becomes true:
706 * - the mailbox is full
707 * - end of the user provided buffer
708 * - end of the mapped area
710 * If the file is opened without O_NONBLOCK, we wait here until
711 * space is availabyl, but return when we have been able to
714 static ssize_t spufs_wbox_write(struct file *file, const char __user *buf,
715 size_t len, loff_t *pos)
717 struct spu_context *ctx = file->private_data;
718 u32 wbox_data, __user *udata;
724 udata = (void __user *)buf;
725 if (!access_ok(VERIFY_READ, buf, len))
728 if (__get_user(wbox_data, udata))
734 * make sure we can at least write one element, by waiting
735 * in case of !O_NONBLOCK
738 if (file->f_flags & O_NONBLOCK) {
739 if (!spu_wbox_write(ctx, wbox_data))
742 count = spufs_wait(ctx->wbox_wq, spu_wbox_write(ctx, wbox_data));
748 /* write aѕ much as possible */
749 for (count = 4, udata++; (count + 4) <= len; count += 4, udata++) {
751 ret = __get_user(wbox_data, udata);
755 ret = spu_wbox_write(ctx, wbox_data);
765 static unsigned int spufs_wbox_poll(struct file *file, poll_table *wait)
767 struct spu_context *ctx = file->private_data;
770 poll_wait(file, &ctx->wbox_wq, wait);
773 mask = ctx->ops->mbox_stat_poll(ctx, POLLOUT | POLLWRNORM);
779 static const struct file_operations spufs_wbox_fops = {
780 .open = spufs_pipe_open,
781 .write = spufs_wbox_write,
782 .poll = spufs_wbox_poll,
783 .fasync = spufs_wbox_fasync,
786 static ssize_t spufs_wbox_stat_read(struct file *file, char __user *buf,
787 size_t len, loff_t *pos)
789 struct spu_context *ctx = file->private_data;
796 wbox_stat = (ctx->ops->mbox_stat_read(ctx) >> 8) & 0xff;
799 if (copy_to_user(buf, &wbox_stat, sizeof wbox_stat))
805 static const struct file_operations spufs_wbox_stat_fops = {
806 .open = spufs_pipe_open,
807 .read = spufs_wbox_stat_read,
810 static int spufs_signal1_open(struct inode *inode, struct file *file)
812 struct spufs_inode_info *i = SPUFS_I(inode);
813 struct spu_context *ctx = i->i_ctx;
815 spin_lock(&ctx->mapping_lock);
816 file->private_data = ctx;
818 ctx->signal1 = inode->i_mapping;
819 spin_unlock(&ctx->mapping_lock);
820 return nonseekable_open(inode, file);
824 spufs_signal1_release(struct inode *inode, struct file *file)
826 struct spufs_inode_info *i = SPUFS_I(inode);
827 struct spu_context *ctx = i->i_ctx;
829 spin_lock(&ctx->mapping_lock);
832 spin_unlock(&ctx->mapping_lock);
836 static ssize_t __spufs_signal1_read(struct spu_context *ctx, char __user *buf,
837 size_t len, loff_t *pos)
845 if (ctx->csa.spu_chnlcnt_RW[3]) {
846 data = ctx->csa.spu_chnldata_RW[3];
853 if (copy_to_user(buf, &data, 4))
860 static ssize_t spufs_signal1_read(struct file *file, char __user *buf,
861 size_t len, loff_t *pos)
864 struct spu_context *ctx = file->private_data;
866 spu_acquire_saved(ctx);
867 ret = __spufs_signal1_read(ctx, buf, len, pos);
873 static ssize_t spufs_signal1_write(struct file *file, const char __user *buf,
874 size_t len, loff_t *pos)
876 struct spu_context *ctx;
879 ctx = file->private_data;
884 if (copy_from_user(&data, buf, 4))
888 ctx->ops->signal1_write(ctx, data);
894 static unsigned long spufs_signal1_mmap_nopfn(struct vm_area_struct *vma,
895 unsigned long address)
897 #if PAGE_SIZE == 0x1000
898 return spufs_ps_nopfn(vma, address, 0x14000, 0x1000);
899 #elif PAGE_SIZE == 0x10000
900 /* For 64k pages, both signal1 and signal2 can be used to mmap the whole
901 * signal 1 and 2 area
903 return spufs_ps_nopfn(vma, address, 0x10000, 0x10000);
905 #error unsupported page size
909 static struct vm_operations_struct spufs_signal1_mmap_vmops = {
910 .nopfn = spufs_signal1_mmap_nopfn,
913 static int spufs_signal1_mmap(struct file *file, struct vm_area_struct *vma)
915 if (!(vma->vm_flags & VM_SHARED))
918 vma->vm_flags |= VM_IO | VM_PFNMAP;
919 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
920 | _PAGE_NO_CACHE | _PAGE_GUARDED);
922 vma->vm_ops = &spufs_signal1_mmap_vmops;
926 static const struct file_operations spufs_signal1_fops = {
927 .open = spufs_signal1_open,
928 .release = spufs_signal1_release,
929 .read = spufs_signal1_read,
930 .write = spufs_signal1_write,
931 .mmap = spufs_signal1_mmap,
934 static int spufs_signal2_open(struct inode *inode, struct file *file)
936 struct spufs_inode_info *i = SPUFS_I(inode);
937 struct spu_context *ctx = i->i_ctx;
939 spin_lock(&ctx->mapping_lock);
940 file->private_data = ctx;
942 ctx->signal2 = inode->i_mapping;
943 spin_unlock(&ctx->mapping_lock);
944 return nonseekable_open(inode, file);
948 spufs_signal2_release(struct inode *inode, struct file *file)
950 struct spufs_inode_info *i = SPUFS_I(inode);
951 struct spu_context *ctx = i->i_ctx;
953 spin_lock(&ctx->mapping_lock);
956 spin_unlock(&ctx->mapping_lock);
960 static ssize_t __spufs_signal2_read(struct spu_context *ctx, char __user *buf,
961 size_t len, loff_t *pos)
969 if (ctx->csa.spu_chnlcnt_RW[4]) {
970 data = ctx->csa.spu_chnldata_RW[4];
977 if (copy_to_user(buf, &data, 4))
984 static ssize_t spufs_signal2_read(struct file *file, char __user *buf,
985 size_t len, loff_t *pos)
987 struct spu_context *ctx = file->private_data;
990 spu_acquire_saved(ctx);
991 ret = __spufs_signal2_read(ctx, buf, len, pos);
997 static ssize_t spufs_signal2_write(struct file *file, const char __user *buf,
998 size_t len, loff_t *pos)
1000 struct spu_context *ctx;
1003 ctx = file->private_data;
1008 if (copy_from_user(&data, buf, 4))
1012 ctx->ops->signal2_write(ctx, data);
1019 static unsigned long spufs_signal2_mmap_nopfn(struct vm_area_struct *vma,
1020 unsigned long address)
1022 #if PAGE_SIZE == 0x1000
1023 return spufs_ps_nopfn(vma, address, 0x1c000, 0x1000);
1024 #elif PAGE_SIZE == 0x10000
1025 /* For 64k pages, both signal1 and signal2 can be used to mmap the whole
1026 * signal 1 and 2 area
1028 return spufs_ps_nopfn(vma, address, 0x10000, 0x10000);
1030 #error unsupported page size
1034 static struct vm_operations_struct spufs_signal2_mmap_vmops = {
1035 .nopfn = spufs_signal2_mmap_nopfn,
1038 static int spufs_signal2_mmap(struct file *file, struct vm_area_struct *vma)
1040 if (!(vma->vm_flags & VM_SHARED))
1043 vma->vm_flags |= VM_IO | VM_PFNMAP;
1044 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
1045 | _PAGE_NO_CACHE | _PAGE_GUARDED);
1047 vma->vm_ops = &spufs_signal2_mmap_vmops;
1050 #else /* SPUFS_MMAP_4K */
1051 #define spufs_signal2_mmap NULL
1052 #endif /* !SPUFS_MMAP_4K */
1054 static const struct file_operations spufs_signal2_fops = {
1055 .open = spufs_signal2_open,
1056 .release = spufs_signal2_release,
1057 .read = spufs_signal2_read,
1058 .write = spufs_signal2_write,
1059 .mmap = spufs_signal2_mmap,
1062 static void spufs_signal1_type_set(void *data, u64 val)
1064 struct spu_context *ctx = data;
1067 ctx->ops->signal1_type_set(ctx, val);
1071 static u64 __spufs_signal1_type_get(void *data)
1073 struct spu_context *ctx = data;
1074 return ctx->ops->signal1_type_get(ctx);
1077 static u64 spufs_signal1_type_get(void *data)
1079 struct spu_context *ctx = data;
1083 ret = __spufs_signal1_type_get(data);
1088 DEFINE_SIMPLE_ATTRIBUTE(spufs_signal1_type, spufs_signal1_type_get,
1089 spufs_signal1_type_set, "%llu");
1091 static void spufs_signal2_type_set(void *data, u64 val)
1093 struct spu_context *ctx = data;
1096 ctx->ops->signal2_type_set(ctx, val);
1100 static u64 __spufs_signal2_type_get(void *data)
1102 struct spu_context *ctx = data;
1103 return ctx->ops->signal2_type_get(ctx);
1106 static u64 spufs_signal2_type_get(void *data)
1108 struct spu_context *ctx = data;
1112 ret = __spufs_signal2_type_get(data);
1117 DEFINE_SIMPLE_ATTRIBUTE(spufs_signal2_type, spufs_signal2_type_get,
1118 spufs_signal2_type_set, "%llu");
1121 static unsigned long spufs_mss_mmap_nopfn(struct vm_area_struct *vma,
1122 unsigned long address)
1124 return spufs_ps_nopfn(vma, address, 0x0000, 0x1000);
1127 static struct vm_operations_struct spufs_mss_mmap_vmops = {
1128 .nopfn = spufs_mss_mmap_nopfn,
1132 * mmap support for problem state MFC DMA area [0x0000 - 0x0fff].
1134 static int spufs_mss_mmap(struct file *file, struct vm_area_struct *vma)
1136 if (!(vma->vm_flags & VM_SHARED))
1139 vma->vm_flags |= VM_IO | VM_PFNMAP;
1140 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
1141 | _PAGE_NO_CACHE | _PAGE_GUARDED);
1143 vma->vm_ops = &spufs_mss_mmap_vmops;
1146 #else /* SPUFS_MMAP_4K */
1147 #define spufs_mss_mmap NULL
1148 #endif /* !SPUFS_MMAP_4K */
1150 static int spufs_mss_open(struct inode *inode, struct file *file)
1152 struct spufs_inode_info *i = SPUFS_I(inode);
1153 struct spu_context *ctx = i->i_ctx;
1155 file->private_data = i->i_ctx;
1157 spin_lock(&ctx->mapping_lock);
1158 if (!i->i_openers++)
1159 ctx->mss = inode->i_mapping;
1160 spin_unlock(&ctx->mapping_lock);
1161 return nonseekable_open(inode, file);
1165 spufs_mss_release(struct inode *inode, struct file *file)
1167 struct spufs_inode_info *i = SPUFS_I(inode);
1168 struct spu_context *ctx = i->i_ctx;
1170 spin_lock(&ctx->mapping_lock);
1171 if (!--i->i_openers)
1173 spin_unlock(&ctx->mapping_lock);
1177 static const struct file_operations spufs_mss_fops = {
1178 .open = spufs_mss_open,
1179 .release = spufs_mss_release,
1180 .mmap = spufs_mss_mmap,
1183 static unsigned long spufs_psmap_mmap_nopfn(struct vm_area_struct *vma,
1184 unsigned long address)
1186 return spufs_ps_nopfn(vma, address, 0x0000, 0x20000);
1189 static struct vm_operations_struct spufs_psmap_mmap_vmops = {
1190 .nopfn = spufs_psmap_mmap_nopfn,
1194 * mmap support for full problem state area [0x00000 - 0x1ffff].
1196 static int spufs_psmap_mmap(struct file *file, struct vm_area_struct *vma)
1198 if (!(vma->vm_flags & VM_SHARED))
1201 vma->vm_flags |= VM_IO | VM_PFNMAP;
1202 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
1203 | _PAGE_NO_CACHE | _PAGE_GUARDED);
1205 vma->vm_ops = &spufs_psmap_mmap_vmops;
1209 static int spufs_psmap_open(struct inode *inode, struct file *file)
1211 struct spufs_inode_info *i = SPUFS_I(inode);
1212 struct spu_context *ctx = i->i_ctx;
1214 spin_lock(&ctx->mapping_lock);
1215 file->private_data = i->i_ctx;
1216 if (!i->i_openers++)
1217 ctx->psmap = inode->i_mapping;
1218 spin_unlock(&ctx->mapping_lock);
1219 return nonseekable_open(inode, file);
1223 spufs_psmap_release(struct inode *inode, struct file *file)
1225 struct spufs_inode_info *i = SPUFS_I(inode);
1226 struct spu_context *ctx = i->i_ctx;
1228 spin_lock(&ctx->mapping_lock);
1229 if (!--i->i_openers)
1231 spin_unlock(&ctx->mapping_lock);
1235 static const struct file_operations spufs_psmap_fops = {
1236 .open = spufs_psmap_open,
1237 .release = spufs_psmap_release,
1238 .mmap = spufs_psmap_mmap,
1243 static unsigned long spufs_mfc_mmap_nopfn(struct vm_area_struct *vma,
1244 unsigned long address)
1246 return spufs_ps_nopfn(vma, address, 0x3000, 0x1000);
1249 static struct vm_operations_struct spufs_mfc_mmap_vmops = {
1250 .nopfn = spufs_mfc_mmap_nopfn,
1254 * mmap support for problem state MFC DMA area [0x0000 - 0x0fff].
1256 static int spufs_mfc_mmap(struct file *file, struct vm_area_struct *vma)
1258 if (!(vma->vm_flags & VM_SHARED))
1261 vma->vm_flags |= VM_IO | VM_PFNMAP;
1262 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
1263 | _PAGE_NO_CACHE | _PAGE_GUARDED);
1265 vma->vm_ops = &spufs_mfc_mmap_vmops;
1268 #else /* SPUFS_MMAP_4K */
1269 #define spufs_mfc_mmap NULL
1270 #endif /* !SPUFS_MMAP_4K */
1272 static int spufs_mfc_open(struct inode *inode, struct file *file)
1274 struct spufs_inode_info *i = SPUFS_I(inode);
1275 struct spu_context *ctx = i->i_ctx;
1277 /* we don't want to deal with DMA into other processes */
1278 if (ctx->owner != current->mm)
1281 if (atomic_read(&inode->i_count) != 1)
1284 spin_lock(&ctx->mapping_lock);
1285 file->private_data = ctx;
1286 if (!i->i_openers++)
1287 ctx->mfc = inode->i_mapping;
1288 spin_unlock(&ctx->mapping_lock);
1289 return nonseekable_open(inode, file);
1293 spufs_mfc_release(struct inode *inode, struct file *file)
1295 struct spufs_inode_info *i = SPUFS_I(inode);
1296 struct spu_context *ctx = i->i_ctx;
1298 spin_lock(&ctx->mapping_lock);
1299 if (!--i->i_openers)
1301 spin_unlock(&ctx->mapping_lock);
1305 /* interrupt-level mfc callback function. */
1306 void spufs_mfc_callback(struct spu *spu)
1308 struct spu_context *ctx = spu->ctx;
1310 wake_up_all(&ctx->mfc_wq);
1312 pr_debug("%s %s\n", __FUNCTION__, spu->name);
1313 if (ctx->mfc_fasync) {
1314 u32 free_elements, tagstatus;
1317 /* no need for spu_acquire in interrupt context */
1318 free_elements = ctx->ops->get_mfc_free_elements(ctx);
1319 tagstatus = ctx->ops->read_mfc_tagstatus(ctx);
1322 if (free_elements & 0xffff)
1324 if (tagstatus & ctx->tagwait)
1327 kill_fasync(&ctx->mfc_fasync, SIGIO, mask);
1331 static int spufs_read_mfc_tagstatus(struct spu_context *ctx, u32 *status)
1333 /* See if there is one tag group is complete */
1334 /* FIXME we need locking around tagwait */
1335 *status = ctx->ops->read_mfc_tagstatus(ctx) & ctx->tagwait;
1336 ctx->tagwait &= ~*status;
1340 /* enable interrupt waiting for any tag group,
1341 may silently fail if interrupts are already enabled */
1342 ctx->ops->set_mfc_query(ctx, ctx->tagwait, 1);
1346 static ssize_t spufs_mfc_read(struct file *file, char __user *buffer,
1347 size_t size, loff_t *pos)
1349 struct spu_context *ctx = file->private_data;
1357 if (file->f_flags & O_NONBLOCK) {
1358 status = ctx->ops->read_mfc_tagstatus(ctx);
1359 if (!(status & ctx->tagwait))
1362 ctx->tagwait &= ~status;
1364 ret = spufs_wait(ctx->mfc_wq,
1365 spufs_read_mfc_tagstatus(ctx, &status));
1373 if (copy_to_user(buffer, &status, 4))
1380 static int spufs_check_valid_dma(struct mfc_dma_command *cmd)
1382 pr_debug("queueing DMA %x %lx %x %x %x\n", cmd->lsa,
1383 cmd->ea, cmd->size, cmd->tag, cmd->cmd);
1394 pr_debug("invalid DMA opcode %x\n", cmd->cmd);
1398 if ((cmd->lsa & 0xf) != (cmd->ea &0xf)) {
1399 pr_debug("invalid DMA alignment, ea %lx lsa %x\n",
1404 switch (cmd->size & 0xf) {
1425 pr_debug("invalid DMA alignment %x for size %x\n",
1426 cmd->lsa & 0xf, cmd->size);
1430 if (cmd->size > 16 * 1024) {
1431 pr_debug("invalid DMA size %x\n", cmd->size);
1435 if (cmd->tag & 0xfff0) {
1436 /* we reserve the higher tag numbers for kernel use */
1437 pr_debug("invalid DMA tag\n");
1442 /* not supported in this version */
1443 pr_debug("invalid DMA class\n");
1450 static int spu_send_mfc_command(struct spu_context *ctx,
1451 struct mfc_dma_command cmd,
1454 *error = ctx->ops->send_mfc_command(ctx, &cmd);
1455 if (*error == -EAGAIN) {
1456 /* wait for any tag group to complete
1457 so we have space for the new command */
1458 ctx->ops->set_mfc_query(ctx, ctx->tagwait, 1);
1459 /* try again, because the queue might be
1461 *error = ctx->ops->send_mfc_command(ctx, &cmd);
1462 if (*error == -EAGAIN)
1468 static ssize_t spufs_mfc_write(struct file *file, const char __user *buffer,
1469 size_t size, loff_t *pos)
1471 struct spu_context *ctx = file->private_data;
1472 struct mfc_dma_command cmd;
1475 if (size != sizeof cmd)
1479 if (copy_from_user(&cmd, buffer, sizeof cmd))
1482 ret = spufs_check_valid_dma(&cmd);
1486 ret = spu_acquire_runnable(ctx, 0);
1490 if (file->f_flags & O_NONBLOCK) {
1491 ret = ctx->ops->send_mfc_command(ctx, &cmd);
1494 ret = spufs_wait(ctx->mfc_wq,
1495 spu_send_mfc_command(ctx, cmd, &status));
1504 ctx->tagwait |= 1 << cmd.tag;
1511 static unsigned int spufs_mfc_poll(struct file *file,poll_table *wait)
1513 struct spu_context *ctx = file->private_data;
1514 u32 free_elements, tagstatus;
1518 ctx->ops->set_mfc_query(ctx, ctx->tagwait, 2);
1519 free_elements = ctx->ops->get_mfc_free_elements(ctx);
1520 tagstatus = ctx->ops->read_mfc_tagstatus(ctx);
1523 poll_wait(file, &ctx->mfc_wq, wait);
1526 if (free_elements & 0xffff)
1527 mask |= POLLOUT | POLLWRNORM;
1528 if (tagstatus & ctx->tagwait)
1529 mask |= POLLIN | POLLRDNORM;
1531 pr_debug("%s: free %d tagstatus %d tagwait %d\n", __FUNCTION__,
1532 free_elements, tagstatus, ctx->tagwait);
1537 static int spufs_mfc_flush(struct file *file, fl_owner_t id)
1539 struct spu_context *ctx = file->private_data;
1544 /* this currently hangs */
1545 ret = spufs_wait(ctx->mfc_wq,
1546 ctx->ops->set_mfc_query(ctx, ctx->tagwait, 2));
1549 ret = spufs_wait(ctx->mfc_wq,
1550 ctx->ops->read_mfc_tagstatus(ctx) == ctx->tagwait);
1560 static int spufs_mfc_fsync(struct file *file, struct dentry *dentry,
1563 return spufs_mfc_flush(file, NULL);
1566 static int spufs_mfc_fasync(int fd, struct file *file, int on)
1568 struct spu_context *ctx = file->private_data;
1570 return fasync_helper(fd, file, on, &ctx->mfc_fasync);
1573 static const struct file_operations spufs_mfc_fops = {
1574 .open = spufs_mfc_open,
1575 .release = spufs_mfc_release,
1576 .read = spufs_mfc_read,
1577 .write = spufs_mfc_write,
1578 .poll = spufs_mfc_poll,
1579 .flush = spufs_mfc_flush,
1580 .fsync = spufs_mfc_fsync,
1581 .fasync = spufs_mfc_fasync,
1582 .mmap = spufs_mfc_mmap,
1585 static void spufs_npc_set(void *data, u64 val)
1587 struct spu_context *ctx = data;
1589 ctx->ops->npc_write(ctx, val);
1593 static u64 spufs_npc_get(void *data)
1595 struct spu_context *ctx = data;
1598 ret = ctx->ops->npc_read(ctx);
1602 DEFINE_SIMPLE_ATTRIBUTE(spufs_npc_ops, spufs_npc_get, spufs_npc_set,
1605 static void spufs_decr_set(void *data, u64 val)
1607 struct spu_context *ctx = data;
1608 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1609 spu_acquire_saved(ctx);
1610 lscsa->decr.slot[0] = (u32) val;
1614 static u64 __spufs_decr_get(void *data)
1616 struct spu_context *ctx = data;
1617 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1618 return lscsa->decr.slot[0];
1621 static u64 spufs_decr_get(void *data)
1623 struct spu_context *ctx = data;
1625 spu_acquire_saved(ctx);
1626 ret = __spufs_decr_get(data);
1630 DEFINE_SIMPLE_ATTRIBUTE(spufs_decr_ops, spufs_decr_get, spufs_decr_set,
1633 static void spufs_decr_status_set(void *data, u64 val)
1635 struct spu_context *ctx = data;
1636 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1637 spu_acquire_saved(ctx);
1638 lscsa->decr_status.slot[0] = (u32) val;
1642 static u64 __spufs_decr_status_get(void *data)
1644 struct spu_context *ctx = data;
1645 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1646 return lscsa->decr_status.slot[0];
1649 static u64 spufs_decr_status_get(void *data)
1651 struct spu_context *ctx = data;
1653 spu_acquire_saved(ctx);
1654 ret = __spufs_decr_status_get(data);
1658 DEFINE_SIMPLE_ATTRIBUTE(spufs_decr_status_ops, spufs_decr_status_get,
1659 spufs_decr_status_set, "0x%llx\n")
1661 static void spufs_event_mask_set(void *data, u64 val)
1663 struct spu_context *ctx = data;
1664 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1665 spu_acquire_saved(ctx);
1666 lscsa->event_mask.slot[0] = (u32) val;
1670 static u64 __spufs_event_mask_get(void *data)
1672 struct spu_context *ctx = data;
1673 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1674 return lscsa->event_mask.slot[0];
1677 static u64 spufs_event_mask_get(void *data)
1679 struct spu_context *ctx = data;
1681 spu_acquire_saved(ctx);
1682 ret = __spufs_event_mask_get(data);
1686 DEFINE_SIMPLE_ATTRIBUTE(spufs_event_mask_ops, spufs_event_mask_get,
1687 spufs_event_mask_set, "0x%llx\n")
1689 static u64 __spufs_event_status_get(void *data)
1691 struct spu_context *ctx = data;
1692 struct spu_state *state = &ctx->csa;
1694 stat = state->spu_chnlcnt_RW[0];
1696 return state->spu_chnldata_RW[0];
1700 static u64 spufs_event_status_get(void *data)
1702 struct spu_context *ctx = data;
1705 spu_acquire_saved(ctx);
1706 ret = __spufs_event_status_get(data);
1710 DEFINE_SIMPLE_ATTRIBUTE(spufs_event_status_ops, spufs_event_status_get,
1713 static void spufs_srr0_set(void *data, u64 val)
1715 struct spu_context *ctx = data;
1716 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1717 spu_acquire_saved(ctx);
1718 lscsa->srr0.slot[0] = (u32) val;
1722 static u64 spufs_srr0_get(void *data)
1724 struct spu_context *ctx = data;
1725 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1727 spu_acquire_saved(ctx);
1728 ret = lscsa->srr0.slot[0];
1732 DEFINE_SIMPLE_ATTRIBUTE(spufs_srr0_ops, spufs_srr0_get, spufs_srr0_set,
1735 static u64 spufs_id_get(void *data)
1737 struct spu_context *ctx = data;
1741 if (ctx->state == SPU_STATE_RUNNABLE)
1742 num = ctx->spu->number;
1744 num = (unsigned int)-1;
1749 DEFINE_SIMPLE_ATTRIBUTE(spufs_id_ops, spufs_id_get, NULL, "0x%llx\n")
1751 static u64 __spufs_object_id_get(void *data)
1753 struct spu_context *ctx = data;
1754 return ctx->object_id;
1757 static u64 spufs_object_id_get(void *data)
1759 /* FIXME: Should there really be no locking here? */
1760 return __spufs_object_id_get(data);
1763 static void spufs_object_id_set(void *data, u64 id)
1765 struct spu_context *ctx = data;
1766 ctx->object_id = id;
1769 DEFINE_SIMPLE_ATTRIBUTE(spufs_object_id_ops, spufs_object_id_get,
1770 spufs_object_id_set, "0x%llx\n");
1772 static u64 __spufs_lslr_get(void *data)
1774 struct spu_context *ctx = data;
1775 return ctx->csa.priv2.spu_lslr_RW;
1778 static u64 spufs_lslr_get(void *data)
1780 struct spu_context *ctx = data;
1783 spu_acquire_saved(ctx);
1784 ret = __spufs_lslr_get(data);
1789 DEFINE_SIMPLE_ATTRIBUTE(spufs_lslr_ops, spufs_lslr_get, NULL, "0x%llx\n")
1791 static int spufs_info_open(struct inode *inode, struct file *file)
1793 struct spufs_inode_info *i = SPUFS_I(inode);
1794 struct spu_context *ctx = i->i_ctx;
1795 file->private_data = ctx;
1799 static ssize_t __spufs_mbox_info_read(struct spu_context *ctx,
1800 char __user *buf, size_t len, loff_t *pos)
1805 mbox_stat = ctx->csa.prob.mb_stat_R;
1806 if (mbox_stat & 0x0000ff) {
1807 data = ctx->csa.prob.pu_mb_R;
1810 return simple_read_from_buffer(buf, len, pos, &data, sizeof data);
1813 static ssize_t spufs_mbox_info_read(struct file *file, char __user *buf,
1814 size_t len, loff_t *pos)
1817 struct spu_context *ctx = file->private_data;
1819 if (!access_ok(VERIFY_WRITE, buf, len))
1822 spu_acquire_saved(ctx);
1823 spin_lock(&ctx->csa.register_lock);
1824 ret = __spufs_mbox_info_read(ctx, buf, len, pos);
1825 spin_unlock(&ctx->csa.register_lock);
1831 static const struct file_operations spufs_mbox_info_fops = {
1832 .open = spufs_info_open,
1833 .read = spufs_mbox_info_read,
1834 .llseek = generic_file_llseek,
1837 static ssize_t __spufs_ibox_info_read(struct spu_context *ctx,
1838 char __user *buf, size_t len, loff_t *pos)
1843 ibox_stat = ctx->csa.prob.mb_stat_R;
1844 if (ibox_stat & 0xff0000) {
1845 data = ctx->csa.priv2.puint_mb_R;
1848 return simple_read_from_buffer(buf, len, pos, &data, sizeof data);
1851 static ssize_t spufs_ibox_info_read(struct file *file, char __user *buf,
1852 size_t len, loff_t *pos)
1854 struct spu_context *ctx = file->private_data;
1857 if (!access_ok(VERIFY_WRITE, buf, len))
1860 spu_acquire_saved(ctx);
1861 spin_lock(&ctx->csa.register_lock);
1862 ret = __spufs_ibox_info_read(ctx, buf, len, pos);
1863 spin_unlock(&ctx->csa.register_lock);
1869 static const struct file_operations spufs_ibox_info_fops = {
1870 .open = spufs_info_open,
1871 .read = spufs_ibox_info_read,
1872 .llseek = generic_file_llseek,
1875 static ssize_t __spufs_wbox_info_read(struct spu_context *ctx,
1876 char __user *buf, size_t len, loff_t *pos)
1882 wbox_stat = ctx->csa.prob.mb_stat_R;
1883 cnt = 4 - ((wbox_stat & 0x00ff00) >> 8);
1884 for (i = 0; i < cnt; i++) {
1885 data[i] = ctx->csa.spu_mailbox_data[i];
1888 return simple_read_from_buffer(buf, len, pos, &data,
1892 static ssize_t spufs_wbox_info_read(struct file *file, char __user *buf,
1893 size_t len, loff_t *pos)
1895 struct spu_context *ctx = file->private_data;
1898 if (!access_ok(VERIFY_WRITE, buf, len))
1901 spu_acquire_saved(ctx);
1902 spin_lock(&ctx->csa.register_lock);
1903 ret = __spufs_wbox_info_read(ctx, buf, len, pos);
1904 spin_unlock(&ctx->csa.register_lock);
1910 static const struct file_operations spufs_wbox_info_fops = {
1911 .open = spufs_info_open,
1912 .read = spufs_wbox_info_read,
1913 .llseek = generic_file_llseek,
1916 static ssize_t __spufs_dma_info_read(struct spu_context *ctx,
1917 char __user *buf, size_t len, loff_t *pos)
1919 struct spu_dma_info info;
1920 struct mfc_cq_sr *qp, *spuqp;
1923 info.dma_info_type = ctx->csa.priv2.spu_tag_status_query_RW;
1924 info.dma_info_mask = ctx->csa.lscsa->tag_mask.slot[0];
1925 info.dma_info_status = ctx->csa.spu_chnldata_RW[24];
1926 info.dma_info_stall_and_notify = ctx->csa.spu_chnldata_RW[25];
1927 info.dma_info_atomic_command_status = ctx->csa.spu_chnldata_RW[27];
1928 for (i = 0; i < 16; i++) {
1929 qp = &info.dma_info_command_data[i];
1930 spuqp = &ctx->csa.priv2.spuq[i];
1932 qp->mfc_cq_data0_RW = spuqp->mfc_cq_data0_RW;
1933 qp->mfc_cq_data1_RW = spuqp->mfc_cq_data1_RW;
1934 qp->mfc_cq_data2_RW = spuqp->mfc_cq_data2_RW;
1935 qp->mfc_cq_data3_RW = spuqp->mfc_cq_data3_RW;
1938 return simple_read_from_buffer(buf, len, pos, &info,
1942 static ssize_t spufs_dma_info_read(struct file *file, char __user *buf,
1943 size_t len, loff_t *pos)
1945 struct spu_context *ctx = file->private_data;
1948 if (!access_ok(VERIFY_WRITE, buf, len))
1951 spu_acquire_saved(ctx);
1952 spin_lock(&ctx->csa.register_lock);
1953 ret = __spufs_dma_info_read(ctx, buf, len, pos);
1954 spin_unlock(&ctx->csa.register_lock);
1960 static const struct file_operations spufs_dma_info_fops = {
1961 .open = spufs_info_open,
1962 .read = spufs_dma_info_read,
1965 static ssize_t __spufs_proxydma_info_read(struct spu_context *ctx,
1966 char __user *buf, size_t len, loff_t *pos)
1968 struct spu_proxydma_info info;
1969 struct mfc_cq_sr *qp, *puqp;
1970 int ret = sizeof info;
1976 if (!access_ok(VERIFY_WRITE, buf, len))
1979 info.proxydma_info_type = ctx->csa.prob.dma_querytype_RW;
1980 info.proxydma_info_mask = ctx->csa.prob.dma_querymask_RW;
1981 info.proxydma_info_status = ctx->csa.prob.dma_tagstatus_R;
1982 for (i = 0; i < 8; i++) {
1983 qp = &info.proxydma_info_command_data[i];
1984 puqp = &ctx->csa.priv2.puq[i];
1986 qp->mfc_cq_data0_RW = puqp->mfc_cq_data0_RW;
1987 qp->mfc_cq_data1_RW = puqp->mfc_cq_data1_RW;
1988 qp->mfc_cq_data2_RW = puqp->mfc_cq_data2_RW;
1989 qp->mfc_cq_data3_RW = puqp->mfc_cq_data3_RW;
1992 return simple_read_from_buffer(buf, len, pos, &info,
1996 static ssize_t spufs_proxydma_info_read(struct file *file, char __user *buf,
1997 size_t len, loff_t *pos)
1999 struct spu_context *ctx = file->private_data;
2002 spu_acquire_saved(ctx);
2003 spin_lock(&ctx->csa.register_lock);
2004 ret = __spufs_proxydma_info_read(ctx, buf, len, pos);
2005 spin_unlock(&ctx->csa.register_lock);
2011 static const struct file_operations spufs_proxydma_info_fops = {
2012 .open = spufs_info_open,
2013 .read = spufs_proxydma_info_read,
2016 struct tree_descr spufs_dir_contents[] = {
2017 { "mem", &spufs_mem_fops, 0666, },
2018 { "regs", &spufs_regs_fops, 0666, },
2019 { "mbox", &spufs_mbox_fops, 0444, },
2020 { "ibox", &spufs_ibox_fops, 0444, },
2021 { "wbox", &spufs_wbox_fops, 0222, },
2022 { "mbox_stat", &spufs_mbox_stat_fops, 0444, },
2023 { "ibox_stat", &spufs_ibox_stat_fops, 0444, },
2024 { "wbox_stat", &spufs_wbox_stat_fops, 0444, },
2025 { "signal1", &spufs_signal1_fops, 0666, },
2026 { "signal2", &spufs_signal2_fops, 0666, },
2027 { "signal1_type", &spufs_signal1_type, 0666, },
2028 { "signal2_type", &spufs_signal2_type, 0666, },
2029 { "cntl", &spufs_cntl_fops, 0666, },
2030 { "fpcr", &spufs_fpcr_fops, 0666, },
2031 { "lslr", &spufs_lslr_ops, 0444, },
2032 { "mfc", &spufs_mfc_fops, 0666, },
2033 { "mss", &spufs_mss_fops, 0666, },
2034 { "npc", &spufs_npc_ops, 0666, },
2035 { "srr0", &spufs_srr0_ops, 0666, },
2036 { "decr", &spufs_decr_ops, 0666, },
2037 { "decr_status", &spufs_decr_status_ops, 0666, },
2038 { "event_mask", &spufs_event_mask_ops, 0666, },
2039 { "event_status", &spufs_event_status_ops, 0444, },
2040 { "psmap", &spufs_psmap_fops, 0666, },
2041 { "phys-id", &spufs_id_ops, 0666, },
2042 { "object-id", &spufs_object_id_ops, 0666, },
2043 { "mbox_info", &spufs_mbox_info_fops, 0444, },
2044 { "ibox_info", &spufs_ibox_info_fops, 0444, },
2045 { "wbox_info", &spufs_wbox_info_fops, 0444, },
2046 { "dma_info", &spufs_dma_info_fops, 0444, },
2047 { "proxydma_info", &spufs_proxydma_info_fops, 0444, },
2051 struct tree_descr spufs_dir_nosched_contents[] = {
2052 { "mem", &spufs_mem_fops, 0666, },
2053 { "mbox", &spufs_mbox_fops, 0444, },
2054 { "ibox", &spufs_ibox_fops, 0444, },
2055 { "wbox", &spufs_wbox_fops, 0222, },
2056 { "mbox_stat", &spufs_mbox_stat_fops, 0444, },
2057 { "ibox_stat", &spufs_ibox_stat_fops, 0444, },
2058 { "wbox_stat", &spufs_wbox_stat_fops, 0444, },
2059 { "signal1", &spufs_signal1_fops, 0666, },
2060 { "signal2", &spufs_signal2_fops, 0666, },
2061 { "signal1_type", &spufs_signal1_type, 0666, },
2062 { "signal2_type", &spufs_signal2_type, 0666, },
2063 { "mss", &spufs_mss_fops, 0666, },
2064 { "mfc", &spufs_mfc_fops, 0666, },
2065 { "cntl", &spufs_cntl_fops, 0666, },
2066 { "npc", &spufs_npc_ops, 0666, },
2067 { "psmap", &spufs_psmap_fops, 0666, },
2068 { "phys-id", &spufs_id_ops, 0666, },
2069 { "object-id", &spufs_object_id_ops, 0666, },
2073 struct spufs_coredump_reader spufs_coredump_read[] = {
2074 { "regs", __spufs_regs_read, NULL, 128 * 16 },
2075 { "fpcr", __spufs_fpcr_read, NULL, 16 },
2076 { "lslr", NULL, __spufs_lslr_get, 11 },
2077 { "decr", NULL, __spufs_decr_get, 11 },
2078 { "decr_status", NULL, __spufs_decr_status_get, 11 },
2079 { "mem", __spufs_mem_read, NULL, 256 * 1024, },
2080 { "signal1", __spufs_signal1_read, NULL, 4 },
2081 { "signal1_type", NULL, __spufs_signal1_type_get, 2 },
2082 { "signal2", __spufs_signal2_read, NULL, 4 },
2083 { "signal2_type", NULL, __spufs_signal2_type_get, 2 },
2084 { "event_mask", NULL, __spufs_event_mask_get, 8 },
2085 { "event_status", NULL, __spufs_event_status_get, 8 },
2086 { "mbox_info", __spufs_mbox_info_read, NULL, 4 },
2087 { "ibox_info", __spufs_ibox_info_read, NULL, 4 },
2088 { "wbox_info", __spufs_wbox_info_read, NULL, 16 },
2089 { "dma_info", __spufs_dma_info_read, NULL, 69 * 8 },
2090 { "proxydma_info", __spufs_proxydma_info_read, NULL, 35 * 8 },
2091 { "object-id", NULL, __spufs_object_id_get, 19 },
2094 int spufs_coredump_num_notes = ARRAY_SIZE(spufs_coredump_read) - 1;