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/uaccess.h>
41 spufs_mem_open(struct inode *inode, struct file *file)
43 struct spufs_inode_info *i = SPUFS_I(inode);
44 struct spu_context *ctx = i->i_ctx;
45 file->private_data = ctx;
46 file->f_mapping = inode->i_mapping;
47 ctx->local_store = inode->i_mapping;
52 spufs_mem_read(struct file *file, char __user *buffer,
53 size_t size, loff_t *pos)
55 struct spu_context *ctx = file->private_data;
61 local_store = ctx->ops->get_ls(ctx);
62 ret = simple_read_from_buffer(buffer, size, pos, local_store, LS_SIZE);
69 spufs_mem_write(struct file *file, const char __user *buffer,
70 size_t size, loff_t *pos)
72 struct spu_context *ctx = file->private_data;
76 size = min_t(ssize_t, LS_SIZE - *pos, size);
83 local_store = ctx->ops->get_ls(ctx);
84 ret = copy_from_user(local_store + *pos - size,
85 buffer, size) ? -EFAULT : size;
91 #ifdef CONFIG_SPUFS_MMAP
93 spufs_mem_mmap_nopage(struct vm_area_struct *vma,
94 unsigned long address, int *type)
96 struct page *page = NOPAGE_SIGBUS;
98 struct spu_context *ctx = vma->vm_file->private_data;
99 unsigned long offset = address - vma->vm_start;
100 offset += vma->vm_pgoff << PAGE_SHIFT;
104 if (ctx->state == SPU_STATE_SAVED)
105 page = vmalloc_to_page(ctx->csa.lscsa->ls + offset);
107 page = pfn_to_page((ctx->spu->local_store_phys + offset)
113 *type = VM_FAULT_MINOR;
115 page_cache_get(page);
119 static struct vm_operations_struct spufs_mem_mmap_vmops = {
120 .nopage = spufs_mem_mmap_nopage,
124 spufs_mem_mmap(struct file *file, struct vm_area_struct *vma)
126 if (!(vma->vm_flags & VM_SHARED))
130 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
133 vma->vm_ops = &spufs_mem_mmap_vmops;
138 static struct file_operations spufs_mem_fops = {
139 .open = spufs_mem_open,
140 .read = spufs_mem_read,
141 .write = spufs_mem_write,
142 .llseek = generic_file_llseek,
143 #ifdef CONFIG_SPUFS_MMAP
144 .mmap = spufs_mem_mmap,
148 #ifdef CONFIG_SPUFS_MMAP
149 static struct page *spufs_ps_nopage(struct vm_area_struct *vma,
150 unsigned long address,
151 int *type, unsigned long ps_offs)
153 struct page *page = NOPAGE_SIGBUS;
154 int fault_type = VM_FAULT_SIGBUS;
155 struct spu_context *ctx = vma->vm_file->private_data;
156 unsigned long offset = address - vma->vm_start;
160 offset += vma->vm_pgoff << PAGE_SHIFT;
161 if (offset >= 0x4000)
164 ret = spu_acquire_runnable(ctx);
168 area = ctx->spu->problem_phys + ps_offs;
169 page = pfn_to_page((area + offset) >> PAGE_SHIFT);
170 fault_type = VM_FAULT_MINOR;
171 page_cache_get(page);
182 static struct page *spufs_cntl_mmap_nopage(struct vm_area_struct *vma,
183 unsigned long address, int *type)
185 return spufs_ps_nopage(vma, address, type, 0x4000);
188 static struct vm_operations_struct spufs_cntl_mmap_vmops = {
189 .nopage = spufs_cntl_mmap_nopage,
193 * mmap support for problem state control area [0x4000 - 0x4fff].
194 * Mapping this area requires that the application have CAP_SYS_RAWIO,
195 * as these registers require special care when read/writing.
197 static int spufs_cntl_mmap(struct file *file, struct vm_area_struct *vma)
199 if (!(vma->vm_flags & VM_SHARED))
202 if (!capable(CAP_SYS_RAWIO))
205 vma->vm_flags |= VM_RESERVED;
206 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
209 vma->vm_ops = &spufs_cntl_mmap_vmops;
214 static int spufs_cntl_open(struct inode *inode, struct file *file)
216 struct spufs_inode_info *i = SPUFS_I(inode);
217 struct spu_context *ctx = i->i_ctx;
219 file->private_data = ctx;
220 file->f_mapping = inode->i_mapping;
221 ctx->cntl = inode->i_mapping;
226 spufs_cntl_read(struct file *file, char __user *buffer,
227 size_t size, loff_t *pos)
229 /* FIXME: read from spu status */
234 spufs_cntl_write(struct file *file, const char __user *buffer,
235 size_t size, loff_t *pos)
237 /* FIXME: write to runctl bit */
241 static struct file_operations spufs_cntl_fops = {
242 .open = spufs_cntl_open,
243 .read = spufs_cntl_read,
244 .write = spufs_cntl_write,
245 #ifdef CONFIG_SPUFS_MMAP
246 .mmap = spufs_cntl_mmap,
251 spufs_regs_open(struct inode *inode, struct file *file)
253 struct spufs_inode_info *i = SPUFS_I(inode);
254 file->private_data = i->i_ctx;
259 spufs_regs_read(struct file *file, char __user *buffer,
260 size_t size, loff_t *pos)
262 struct spu_context *ctx = file->private_data;
263 struct spu_lscsa *lscsa = ctx->csa.lscsa;
266 spu_acquire_saved(ctx);
268 ret = simple_read_from_buffer(buffer, size, pos,
269 lscsa->gprs, sizeof lscsa->gprs);
276 spufs_regs_write(struct file *file, const char __user *buffer,
277 size_t size, loff_t *pos)
279 struct spu_context *ctx = file->private_data;
280 struct spu_lscsa *lscsa = ctx->csa.lscsa;
283 size = min_t(ssize_t, sizeof lscsa->gprs - *pos, size);
288 spu_acquire_saved(ctx);
290 ret = copy_from_user(lscsa->gprs + *pos - size,
291 buffer, size) ? -EFAULT : size;
297 static struct file_operations spufs_regs_fops = {
298 .open = spufs_regs_open,
299 .read = spufs_regs_read,
300 .write = spufs_regs_write,
301 .llseek = generic_file_llseek,
305 spufs_fpcr_read(struct file *file, char __user * buffer,
306 size_t size, loff_t * pos)
308 struct spu_context *ctx = file->private_data;
309 struct spu_lscsa *lscsa = ctx->csa.lscsa;
312 spu_acquire_saved(ctx);
314 ret = simple_read_from_buffer(buffer, size, pos,
315 &lscsa->fpcr, sizeof(lscsa->fpcr));
322 spufs_fpcr_write(struct file *file, const char __user * buffer,
323 size_t size, loff_t * pos)
325 struct spu_context *ctx = file->private_data;
326 struct spu_lscsa *lscsa = ctx->csa.lscsa;
329 size = min_t(ssize_t, sizeof(lscsa->fpcr) - *pos, size);
334 spu_acquire_saved(ctx);
336 ret = copy_from_user((char *)&lscsa->fpcr + *pos - size,
337 buffer, size) ? -EFAULT : size;
343 static struct file_operations spufs_fpcr_fops = {
344 .open = spufs_regs_open,
345 .read = spufs_fpcr_read,
346 .write = spufs_fpcr_write,
347 .llseek = generic_file_llseek,
350 /* generic open function for all pipe-like files */
351 static int spufs_pipe_open(struct inode *inode, struct file *file)
353 struct spufs_inode_info *i = SPUFS_I(inode);
354 file->private_data = i->i_ctx;
356 return nonseekable_open(inode, file);
359 static ssize_t spufs_mbox_read(struct file *file, char __user *buf,
360 size_t len, loff_t *pos)
362 struct spu_context *ctx = file->private_data;
370 ret = ctx->ops->mbox_read(ctx, &mbox_data);
376 if (copy_to_user(buf, &mbox_data, sizeof mbox_data))
382 static struct file_operations spufs_mbox_fops = {
383 .open = spufs_pipe_open,
384 .read = spufs_mbox_read,
387 static ssize_t spufs_mbox_stat_read(struct file *file, char __user *buf,
388 size_t len, loff_t *pos)
390 struct spu_context *ctx = file->private_data;
398 mbox_stat = ctx->ops->mbox_stat_read(ctx) & 0xff;
402 if (copy_to_user(buf, &mbox_stat, sizeof mbox_stat))
408 static struct file_operations spufs_mbox_stat_fops = {
409 .open = spufs_pipe_open,
410 .read = spufs_mbox_stat_read,
413 /* low-level ibox access function */
414 size_t spu_ibox_read(struct spu_context *ctx, u32 *data)
416 return ctx->ops->ibox_read(ctx, data);
419 static int spufs_ibox_fasync(int fd, struct file *file, int on)
421 struct spu_context *ctx = file->private_data;
423 return fasync_helper(fd, file, on, &ctx->ibox_fasync);
426 /* interrupt-level ibox callback function. */
427 void spufs_ibox_callback(struct spu *spu)
429 struct spu_context *ctx = spu->ctx;
431 wake_up_all(&ctx->ibox_wq);
432 kill_fasync(&ctx->ibox_fasync, SIGIO, POLLIN);
435 static ssize_t spufs_ibox_read(struct file *file, char __user *buf,
436 size_t len, loff_t *pos)
438 struct spu_context *ctx = file->private_data;
448 if (file->f_flags & O_NONBLOCK) {
449 if (!spu_ibox_read(ctx, &ibox_data))
452 ret = spufs_wait(ctx->ibox_wq, spu_ibox_read(ctx, &ibox_data));
461 if (copy_to_user(buf, &ibox_data, sizeof ibox_data))
467 static unsigned int spufs_ibox_poll(struct file *file, poll_table *wait)
469 struct spu_context *ctx = file->private_data;
472 poll_wait(file, &ctx->ibox_wq, wait);
475 mask = ctx->ops->mbox_stat_poll(ctx, POLLIN | POLLRDNORM);
481 static struct file_operations spufs_ibox_fops = {
482 .open = spufs_pipe_open,
483 .read = spufs_ibox_read,
484 .poll = spufs_ibox_poll,
485 .fasync = spufs_ibox_fasync,
488 static ssize_t spufs_ibox_stat_read(struct file *file, char __user *buf,
489 size_t len, loff_t *pos)
491 struct spu_context *ctx = file->private_data;
498 ibox_stat = (ctx->ops->mbox_stat_read(ctx) >> 16) & 0xff;
501 if (copy_to_user(buf, &ibox_stat, sizeof ibox_stat))
507 static struct file_operations spufs_ibox_stat_fops = {
508 .open = spufs_pipe_open,
509 .read = spufs_ibox_stat_read,
512 /* low-level mailbox write */
513 size_t spu_wbox_write(struct spu_context *ctx, u32 data)
515 return ctx->ops->wbox_write(ctx, data);
518 static int spufs_wbox_fasync(int fd, struct file *file, int on)
520 struct spu_context *ctx = file->private_data;
523 ret = fasync_helper(fd, file, on, &ctx->wbox_fasync);
528 /* interrupt-level wbox callback function. */
529 void spufs_wbox_callback(struct spu *spu)
531 struct spu_context *ctx = spu->ctx;
533 wake_up_all(&ctx->wbox_wq);
534 kill_fasync(&ctx->wbox_fasync, SIGIO, POLLOUT);
537 static ssize_t spufs_wbox_write(struct file *file, const char __user *buf,
538 size_t len, loff_t *pos)
540 struct spu_context *ctx = file->private_data;
547 if (copy_from_user(&wbox_data, buf, sizeof wbox_data))
553 if (file->f_flags & O_NONBLOCK) {
554 if (!spu_wbox_write(ctx, wbox_data))
557 ret = spufs_wait(ctx->wbox_wq, spu_wbox_write(ctx, wbox_data));
562 return ret ? ret : sizeof wbox_data;
565 static unsigned int spufs_wbox_poll(struct file *file, poll_table *wait)
567 struct spu_context *ctx = file->private_data;
570 poll_wait(file, &ctx->wbox_wq, wait);
573 mask = ctx->ops->mbox_stat_poll(ctx, POLLOUT | POLLWRNORM);
579 static struct file_operations spufs_wbox_fops = {
580 .open = spufs_pipe_open,
581 .write = spufs_wbox_write,
582 .poll = spufs_wbox_poll,
583 .fasync = spufs_wbox_fasync,
586 static ssize_t spufs_wbox_stat_read(struct file *file, char __user *buf,
587 size_t len, loff_t *pos)
589 struct spu_context *ctx = file->private_data;
596 wbox_stat = (ctx->ops->mbox_stat_read(ctx) >> 8) & 0xff;
599 if (copy_to_user(buf, &wbox_stat, sizeof wbox_stat))
605 static struct file_operations spufs_wbox_stat_fops = {
606 .open = spufs_pipe_open,
607 .read = spufs_wbox_stat_read,
610 static int spufs_signal1_open(struct inode *inode, struct file *file)
612 struct spufs_inode_info *i = SPUFS_I(inode);
613 struct spu_context *ctx = i->i_ctx;
614 file->private_data = ctx;
615 file->f_mapping = inode->i_mapping;
616 ctx->signal1 = inode->i_mapping;
617 return nonseekable_open(inode, file);
620 static ssize_t spufs_signal1_read(struct file *file, char __user *buf,
621 size_t len, loff_t *pos)
623 struct spu_context *ctx = file->private_data;
630 data = ctx->ops->signal1_read(ctx);
633 if (copy_to_user(buf, &data, 4))
639 static ssize_t spufs_signal1_write(struct file *file, const char __user *buf,
640 size_t len, loff_t *pos)
642 struct spu_context *ctx;
645 ctx = file->private_data;
650 if (copy_from_user(&data, buf, 4))
654 ctx->ops->signal1_write(ctx, data);
660 #ifdef CONFIG_SPUFS_MMAP
661 static struct page *spufs_signal1_mmap_nopage(struct vm_area_struct *vma,
662 unsigned long address, int *type)
664 return spufs_ps_nopage(vma, address, type, 0x14000);
667 static struct vm_operations_struct spufs_signal1_mmap_vmops = {
668 .nopage = spufs_signal1_mmap_nopage,
671 static int spufs_signal1_mmap(struct file *file, struct vm_area_struct *vma)
673 if (!(vma->vm_flags & VM_SHARED))
676 vma->vm_flags |= VM_RESERVED;
677 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
680 vma->vm_ops = &spufs_signal1_mmap_vmops;
685 static struct file_operations spufs_signal1_fops = {
686 .open = spufs_signal1_open,
687 .read = spufs_signal1_read,
688 .write = spufs_signal1_write,
689 #ifdef CONFIG_SPUFS_MMAP
690 .mmap = spufs_signal1_mmap,
694 static int spufs_signal2_open(struct inode *inode, struct file *file)
696 struct spufs_inode_info *i = SPUFS_I(inode);
697 struct spu_context *ctx = i->i_ctx;
698 file->private_data = ctx;
699 file->f_mapping = inode->i_mapping;
700 ctx->signal2 = inode->i_mapping;
701 return nonseekable_open(inode, file);
704 static ssize_t spufs_signal2_read(struct file *file, char __user *buf,
705 size_t len, loff_t *pos)
707 struct spu_context *ctx;
710 ctx = file->private_data;
716 data = ctx->ops->signal2_read(ctx);
719 if (copy_to_user(buf, &data, 4))
725 static ssize_t spufs_signal2_write(struct file *file, const char __user *buf,
726 size_t len, loff_t *pos)
728 struct spu_context *ctx;
731 ctx = file->private_data;
736 if (copy_from_user(&data, buf, 4))
740 ctx->ops->signal2_write(ctx, data);
746 #ifdef CONFIG_SPUFS_MMAP
747 static struct page *spufs_signal2_mmap_nopage(struct vm_area_struct *vma,
748 unsigned long address, int *type)
750 return spufs_ps_nopage(vma, address, type, 0x1c000);
753 static struct vm_operations_struct spufs_signal2_mmap_vmops = {
754 .nopage = spufs_signal2_mmap_nopage,
757 static int spufs_signal2_mmap(struct file *file, struct vm_area_struct *vma)
759 if (!(vma->vm_flags & VM_SHARED))
763 vma->vm_flags |= VM_RESERVED;
764 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
767 vma->vm_ops = &spufs_signal2_mmap_vmops;
772 static struct file_operations spufs_signal2_fops = {
773 .open = spufs_signal2_open,
774 .read = spufs_signal2_read,
775 .write = spufs_signal2_write,
776 #ifdef CONFIG_SPUFS_MMAP
777 .mmap = spufs_signal2_mmap,
781 static void spufs_signal1_type_set(void *data, u64 val)
783 struct spu_context *ctx = data;
786 ctx->ops->signal1_type_set(ctx, val);
790 static u64 spufs_signal1_type_get(void *data)
792 struct spu_context *ctx = data;
796 ret = ctx->ops->signal1_type_get(ctx);
801 DEFINE_SIMPLE_ATTRIBUTE(spufs_signal1_type, spufs_signal1_type_get,
802 spufs_signal1_type_set, "%llu");
804 static void spufs_signal2_type_set(void *data, u64 val)
806 struct spu_context *ctx = data;
809 ctx->ops->signal2_type_set(ctx, val);
813 static u64 spufs_signal2_type_get(void *data)
815 struct spu_context *ctx = data;
819 ret = ctx->ops->signal2_type_get(ctx);
824 DEFINE_SIMPLE_ATTRIBUTE(spufs_signal2_type, spufs_signal2_type_get,
825 spufs_signal2_type_set, "%llu");
827 #ifdef CONFIG_SPUFS_MMAP
828 static struct page *spufs_mfc_mmap_nopage(struct vm_area_struct *vma,
829 unsigned long address, int *type)
831 return spufs_ps_nopage(vma, address, type, 0x3000);
834 static struct vm_operations_struct spufs_mfc_mmap_vmops = {
835 .nopage = spufs_mfc_mmap_nopage,
839 * mmap support for problem state MFC DMA area [0x0000 - 0x0fff].
840 * Mapping this area requires that the application have CAP_SYS_RAWIO,
841 * as these registers require special care when read/writing.
843 static int spufs_mfc_mmap(struct file *file, struct vm_area_struct *vma)
845 if (!(vma->vm_flags & VM_SHARED))
848 if (!capable(CAP_SYS_RAWIO))
851 vma->vm_flags |= VM_RESERVED;
852 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
855 vma->vm_ops = &spufs_mfc_mmap_vmops;
860 static int spufs_mfc_open(struct inode *inode, struct file *file)
862 struct spufs_inode_info *i = SPUFS_I(inode);
863 struct spu_context *ctx = i->i_ctx;
865 /* we don't want to deal with DMA into other processes */
866 if (ctx->owner != current->mm)
869 if (atomic_read(&inode->i_count) != 1)
872 file->private_data = ctx;
873 return nonseekable_open(inode, file);
876 /* interrupt-level mfc callback function. */
877 void spufs_mfc_callback(struct spu *spu)
879 struct spu_context *ctx = spu->ctx;
881 wake_up_all(&ctx->mfc_wq);
883 pr_debug("%s %s\n", __FUNCTION__, spu->name);
884 if (ctx->mfc_fasync) {
885 u32 free_elements, tagstatus;
888 /* no need for spu_acquire in interrupt context */
889 free_elements = ctx->ops->get_mfc_free_elements(ctx);
890 tagstatus = ctx->ops->read_mfc_tagstatus(ctx);
893 if (free_elements & 0xffff)
895 if (tagstatus & ctx->tagwait)
898 kill_fasync(&ctx->mfc_fasync, SIGIO, mask);
902 static int spufs_read_mfc_tagstatus(struct spu_context *ctx, u32 *status)
904 /* See if there is one tag group is complete */
905 /* FIXME we need locking around tagwait */
906 *status = ctx->ops->read_mfc_tagstatus(ctx) & ctx->tagwait;
907 ctx->tagwait &= ~*status;
911 /* enable interrupt waiting for any tag group,
912 may silently fail if interrupts are already enabled */
913 ctx->ops->set_mfc_query(ctx, ctx->tagwait, 1);
917 static ssize_t spufs_mfc_read(struct file *file, char __user *buffer,
918 size_t size, loff_t *pos)
920 struct spu_context *ctx = file->private_data;
928 if (file->f_flags & O_NONBLOCK) {
929 status = ctx->ops->read_mfc_tagstatus(ctx);
930 if (!(status & ctx->tagwait))
933 ctx->tagwait &= ~status;
935 ret = spufs_wait(ctx->mfc_wq,
936 spufs_read_mfc_tagstatus(ctx, &status));
944 if (copy_to_user(buffer, &status, 4))
951 static int spufs_check_valid_dma(struct mfc_dma_command *cmd)
953 pr_debug("queueing DMA %x %lx %x %x %x\n", cmd->lsa,
954 cmd->ea, cmd->size, cmd->tag, cmd->cmd);
965 pr_debug("invalid DMA opcode %x\n", cmd->cmd);
969 if ((cmd->lsa & 0xf) != (cmd->ea &0xf)) {
970 pr_debug("invalid DMA alignment, ea %lx lsa %x\n",
975 switch (cmd->size & 0xf) {
996 pr_debug("invalid DMA alignment %x for size %x\n",
997 cmd->lsa & 0xf, cmd->size);
1001 if (cmd->size > 16 * 1024) {
1002 pr_debug("invalid DMA size %x\n", cmd->size);
1006 if (cmd->tag & 0xfff0) {
1007 /* we reserve the higher tag numbers for kernel use */
1008 pr_debug("invalid DMA tag\n");
1013 /* not supported in this version */
1014 pr_debug("invalid DMA class\n");
1021 static int spu_send_mfc_command(struct spu_context *ctx,
1022 struct mfc_dma_command cmd,
1025 *error = ctx->ops->send_mfc_command(ctx, &cmd);
1026 if (*error == -EAGAIN) {
1027 /* wait for any tag group to complete
1028 so we have space for the new command */
1029 ctx->ops->set_mfc_query(ctx, ctx->tagwait, 1);
1030 /* try again, because the queue might be
1032 *error = ctx->ops->send_mfc_command(ctx, &cmd);
1033 if (*error == -EAGAIN)
1039 static ssize_t spufs_mfc_write(struct file *file, const char __user *buffer,
1040 size_t size, loff_t *pos)
1042 struct spu_context *ctx = file->private_data;
1043 struct mfc_dma_command cmd;
1046 if (size != sizeof cmd)
1050 if (copy_from_user(&cmd, buffer, sizeof cmd))
1053 ret = spufs_check_valid_dma(&cmd);
1057 spu_acquire_runnable(ctx);
1058 if (file->f_flags & O_NONBLOCK) {
1059 ret = ctx->ops->send_mfc_command(ctx, &cmd);
1062 ret = spufs_wait(ctx->mfc_wq,
1063 spu_send_mfc_command(ctx, cmd, &status));
1072 ctx->tagwait |= 1 << cmd.tag;
1078 static unsigned int spufs_mfc_poll(struct file *file,poll_table *wait)
1080 struct spu_context *ctx = file->private_data;
1081 u32 free_elements, tagstatus;
1085 ctx->ops->set_mfc_query(ctx, ctx->tagwait, 2);
1086 free_elements = ctx->ops->get_mfc_free_elements(ctx);
1087 tagstatus = ctx->ops->read_mfc_tagstatus(ctx);
1090 poll_wait(file, &ctx->mfc_wq, wait);
1093 if (free_elements & 0xffff)
1094 mask |= POLLOUT | POLLWRNORM;
1095 if (tagstatus & ctx->tagwait)
1096 mask |= POLLIN | POLLRDNORM;
1098 pr_debug("%s: free %d tagstatus %d tagwait %d\n", __FUNCTION__,
1099 free_elements, tagstatus, ctx->tagwait);
1104 static int spufs_mfc_flush(struct file *file)
1106 struct spu_context *ctx = file->private_data;
1111 /* this currently hangs */
1112 ret = spufs_wait(ctx->mfc_wq,
1113 ctx->ops->set_mfc_query(ctx, ctx->tagwait, 2));
1116 ret = spufs_wait(ctx->mfc_wq,
1117 ctx->ops->read_mfc_tagstatus(ctx) == ctx->tagwait);
1127 static int spufs_mfc_fsync(struct file *file, struct dentry *dentry,
1130 return spufs_mfc_flush(file);
1133 static int spufs_mfc_fasync(int fd, struct file *file, int on)
1135 struct spu_context *ctx = file->private_data;
1137 return fasync_helper(fd, file, on, &ctx->mfc_fasync);
1140 static struct file_operations spufs_mfc_fops = {
1141 .open = spufs_mfc_open,
1142 .read = spufs_mfc_read,
1143 .write = spufs_mfc_write,
1144 .poll = spufs_mfc_poll,
1145 .flush = spufs_mfc_flush,
1146 .fsync = spufs_mfc_fsync,
1147 .fasync = spufs_mfc_fasync,
1148 #ifdef CONFIG_SPUFS_MMAP
1149 .mmap = spufs_mfc_mmap,
1153 static void spufs_npc_set(void *data, u64 val)
1155 struct spu_context *ctx = data;
1157 ctx->ops->npc_write(ctx, val);
1161 static u64 spufs_npc_get(void *data)
1163 struct spu_context *ctx = data;
1166 ret = ctx->ops->npc_read(ctx);
1170 DEFINE_SIMPLE_ATTRIBUTE(spufs_npc_ops, spufs_npc_get, spufs_npc_set, "%llx\n")
1172 static void spufs_decr_set(void *data, u64 val)
1174 struct spu_context *ctx = data;
1175 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1176 spu_acquire_saved(ctx);
1177 lscsa->decr.slot[0] = (u32) val;
1181 static u64 spufs_decr_get(void *data)
1183 struct spu_context *ctx = data;
1184 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1186 spu_acquire_saved(ctx);
1187 ret = lscsa->decr.slot[0];
1191 DEFINE_SIMPLE_ATTRIBUTE(spufs_decr_ops, spufs_decr_get, spufs_decr_set,
1194 static void spufs_decr_status_set(void *data, u64 val)
1196 struct spu_context *ctx = data;
1197 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1198 spu_acquire_saved(ctx);
1199 lscsa->decr_status.slot[0] = (u32) val;
1203 static u64 spufs_decr_status_get(void *data)
1205 struct spu_context *ctx = data;
1206 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1208 spu_acquire_saved(ctx);
1209 ret = lscsa->decr_status.slot[0];
1213 DEFINE_SIMPLE_ATTRIBUTE(spufs_decr_status_ops, spufs_decr_status_get,
1214 spufs_decr_status_set, "%llx\n")
1216 static void spufs_spu_tag_mask_set(void *data, u64 val)
1218 struct spu_context *ctx = data;
1219 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1220 spu_acquire_saved(ctx);
1221 lscsa->tag_mask.slot[0] = (u32) val;
1225 static u64 spufs_spu_tag_mask_get(void *data)
1227 struct spu_context *ctx = data;
1228 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1230 spu_acquire_saved(ctx);
1231 ret = lscsa->tag_mask.slot[0];
1235 DEFINE_SIMPLE_ATTRIBUTE(spufs_spu_tag_mask_ops, spufs_spu_tag_mask_get,
1236 spufs_spu_tag_mask_set, "%llx\n")
1238 static void spufs_event_mask_set(void *data, u64 val)
1240 struct spu_context *ctx = data;
1241 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1242 spu_acquire_saved(ctx);
1243 lscsa->event_mask.slot[0] = (u32) val;
1247 static u64 spufs_event_mask_get(void *data)
1249 struct spu_context *ctx = data;
1250 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1252 spu_acquire_saved(ctx);
1253 ret = lscsa->event_mask.slot[0];
1257 DEFINE_SIMPLE_ATTRIBUTE(spufs_event_mask_ops, spufs_event_mask_get,
1258 spufs_event_mask_set, "%llx\n")
1260 static void spufs_srr0_set(void *data, u64 val)
1262 struct spu_context *ctx = data;
1263 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1264 spu_acquire_saved(ctx);
1265 lscsa->srr0.slot[0] = (u32) val;
1269 static u64 spufs_srr0_get(void *data)
1271 struct spu_context *ctx = data;
1272 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1274 spu_acquire_saved(ctx);
1275 ret = lscsa->srr0.slot[0];
1279 DEFINE_SIMPLE_ATTRIBUTE(spufs_srr0_ops, spufs_srr0_get, spufs_srr0_set,
1282 struct tree_descr spufs_dir_contents[] = {
1283 { "mem", &spufs_mem_fops, 0666, },
1284 { "regs", &spufs_regs_fops, 0666, },
1285 { "mbox", &spufs_mbox_fops, 0444, },
1286 { "ibox", &spufs_ibox_fops, 0444, },
1287 { "wbox", &spufs_wbox_fops, 0222, },
1288 { "mbox_stat", &spufs_mbox_stat_fops, 0444, },
1289 { "ibox_stat", &spufs_ibox_stat_fops, 0444, },
1290 { "wbox_stat", &spufs_wbox_stat_fops, 0444, },
1291 { "signal1", &spufs_signal1_fops, 0666, },
1292 { "signal2", &spufs_signal2_fops, 0666, },
1293 { "signal1_type", &spufs_signal1_type, 0666, },
1294 { "signal2_type", &spufs_signal2_type, 0666, },
1295 { "mfc", &spufs_mfc_fops, 0666, },
1296 { "cntl", &spufs_cntl_fops, 0666, },
1297 { "npc", &spufs_npc_ops, 0666, },
1298 { "fpcr", &spufs_fpcr_fops, 0666, },
1299 { "decr", &spufs_decr_ops, 0666, },
1300 { "decr_status", &spufs_decr_status_ops, 0666, },
1301 { "spu_tag_mask", &spufs_spu_tag_mask_ops, 0666, },
1302 { "event_mask", &spufs_event_mask_ops, 0666, },
1303 { "srr0", &spufs_srr0_ops, 0666, },