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>
39 #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
;
47 file
->private_data
= ctx
;
48 file
->f_mapping
= inode
->i_mapping
;
49 ctx
->local_store
= inode
->i_mapping
;
54 spufs_mem_read(struct file
*file
, char __user
*buffer
,
55 size_t size
, loff_t
*pos
)
57 struct spu_context
*ctx
= file
->private_data
;
63 local_store
= ctx
->ops
->get_ls(ctx
);
64 ret
= simple_read_from_buffer(buffer
, size
, pos
, local_store
, LS_SIZE
);
71 spufs_mem_write(struct file
*file
, const char __user
*buffer
,
72 size_t size
, loff_t
*pos
)
74 struct spu_context
*ctx
= file
->private_data
;
78 size
= min_t(ssize_t
, LS_SIZE
- *pos
, size
);
85 local_store
= ctx
->ops
->get_ls(ctx
);
86 ret
= copy_from_user(local_store
+ *pos
- size
,
87 buffer
, size
) ? -EFAULT
: size
;
94 spufs_mem_mmap_nopage(struct vm_area_struct
*vma
,
95 unsigned long address
, int *type
)
97 struct page
*page
= NOPAGE_SIGBUS
;
99 struct spu_context
*ctx
= vma
->vm_file
->private_data
;
100 unsigned long offset
= address
- vma
->vm_start
;
101 offset
+= vma
->vm_pgoff
<< PAGE_SHIFT
;
105 if (ctx
->state
== SPU_STATE_SAVED
)
106 page
= vmalloc_to_page(ctx
->csa
.lscsa
->ls
+ offset
);
108 page
= pfn_to_page((ctx
->spu
->local_store_phys
+ offset
)
114 *type
= VM_FAULT_MINOR
;
116 page_cache_get(page
);
120 static struct vm_operations_struct spufs_mem_mmap_vmops
= {
121 .nopage
= spufs_mem_mmap_nopage
,
125 spufs_mem_mmap(struct file
*file
, struct vm_area_struct
*vma
)
127 if (!(vma
->vm_flags
& VM_SHARED
))
131 vma
->vm_page_prot
= __pgprot(pgprot_val(vma
->vm_page_prot
)
134 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 .mmap
= spufs_mem_mmap
,
146 static struct page
*spufs_ps_nopage(struct vm_area_struct
*vma
,
147 unsigned long address
,
148 int *type
, unsigned long ps_offs
,
149 unsigned long ps_size
)
151 struct page
*page
= NOPAGE_SIGBUS
;
152 int fault_type
= VM_FAULT_SIGBUS
;
153 struct spu_context
*ctx
= vma
->vm_file
->private_data
;
154 unsigned long offset
= address
- vma
->vm_start
;
158 offset
+= vma
->vm_pgoff
<< PAGE_SHIFT
;
159 if (offset
>= ps_size
)
162 ret
= spu_acquire_runnable(ctx
);
166 area
= ctx
->spu
->problem_phys
+ ps_offs
;
167 page
= pfn_to_page((area
+ offset
) >> PAGE_SHIFT
);
168 fault_type
= VM_FAULT_MINOR
;
169 page_cache_get(page
);
181 static struct page
*spufs_cntl_mmap_nopage(struct vm_area_struct
*vma
,
182 unsigned long address
, int *type
)
184 return spufs_ps_nopage(vma
, address
, type
, 0x4000, 0x1000);
187 static struct vm_operations_struct spufs_cntl_mmap_vmops
= {
188 .nopage
= spufs_cntl_mmap_nopage
,
192 * mmap support for problem state control area [0x4000 - 0x4fff].
194 static int spufs_cntl_mmap(struct file
*file
, struct vm_area_struct
*vma
)
196 if (!(vma
->vm_flags
& VM_SHARED
))
199 vma
->vm_flags
|= VM_RESERVED
;
200 vma
->vm_page_prot
= __pgprot(pgprot_val(vma
->vm_page_prot
)
201 | _PAGE_NO_CACHE
| _PAGE_GUARDED
);
203 vma
->vm_ops
= &spufs_cntl_mmap_vmops
;
206 #else /* SPUFS_MMAP_4K */
207 #define spufs_cntl_mmap NULL
208 #endif /* !SPUFS_MMAP_4K */
210 static int spufs_cntl_open(struct inode
*inode
, struct file
*file
)
212 struct spufs_inode_info
*i
= SPUFS_I(inode
);
213 struct spu_context
*ctx
= i
->i_ctx
;
215 file
->private_data
= ctx
;
216 file
->f_mapping
= inode
->i_mapping
;
217 ctx
->cntl
= inode
->i_mapping
;
222 spufs_cntl_read(struct file
*file
, char __user
*buffer
,
223 size_t size
, loff_t
*pos
)
225 /* FIXME: read from spu status */
230 spufs_cntl_write(struct file
*file
, const char __user
*buffer
,
231 size_t size
, loff_t
*pos
)
233 /* FIXME: write to runctl bit */
237 static struct file_operations spufs_cntl_fops
= {
238 .open
= spufs_cntl_open
,
239 .read
= spufs_cntl_read
,
240 .write
= spufs_cntl_write
,
241 .mmap
= spufs_cntl_mmap
,
245 spufs_regs_open(struct inode
*inode
, struct file
*file
)
247 struct spufs_inode_info
*i
= SPUFS_I(inode
);
248 file
->private_data
= i
->i_ctx
;
253 spufs_regs_read(struct file
*file
, char __user
*buffer
,
254 size_t size
, loff_t
*pos
)
256 struct spu_context
*ctx
= file
->private_data
;
257 struct spu_lscsa
*lscsa
= ctx
->csa
.lscsa
;
260 spu_acquire_saved(ctx
);
262 ret
= simple_read_from_buffer(buffer
, size
, pos
,
263 lscsa
->gprs
, sizeof lscsa
->gprs
);
270 spufs_regs_write(struct file
*file
, const char __user
*buffer
,
271 size_t size
, loff_t
*pos
)
273 struct spu_context
*ctx
= file
->private_data
;
274 struct spu_lscsa
*lscsa
= ctx
->csa
.lscsa
;
277 size
= min_t(ssize_t
, sizeof lscsa
->gprs
- *pos
, size
);
282 spu_acquire_saved(ctx
);
284 ret
= copy_from_user(lscsa
->gprs
+ *pos
- size
,
285 buffer
, size
) ? -EFAULT
: size
;
291 static struct file_operations spufs_regs_fops
= {
292 .open
= spufs_regs_open
,
293 .read
= spufs_regs_read
,
294 .write
= spufs_regs_write
,
295 .llseek
= generic_file_llseek
,
299 spufs_fpcr_read(struct file
*file
, char __user
* buffer
,
300 size_t size
, loff_t
* pos
)
302 struct spu_context
*ctx
= file
->private_data
;
303 struct spu_lscsa
*lscsa
= ctx
->csa
.lscsa
;
306 spu_acquire_saved(ctx
);
308 ret
= simple_read_from_buffer(buffer
, size
, pos
,
309 &lscsa
->fpcr
, sizeof(lscsa
->fpcr
));
316 spufs_fpcr_write(struct file
*file
, const char __user
* buffer
,
317 size_t size
, loff_t
* pos
)
319 struct spu_context
*ctx
= file
->private_data
;
320 struct spu_lscsa
*lscsa
= ctx
->csa
.lscsa
;
323 size
= min_t(ssize_t
, sizeof(lscsa
->fpcr
) - *pos
, size
);
328 spu_acquire_saved(ctx
);
330 ret
= copy_from_user((char *)&lscsa
->fpcr
+ *pos
- size
,
331 buffer
, size
) ? -EFAULT
: size
;
337 static struct file_operations spufs_fpcr_fops
= {
338 .open
= spufs_regs_open
,
339 .read
= spufs_fpcr_read
,
340 .write
= spufs_fpcr_write
,
341 .llseek
= generic_file_llseek
,
344 /* generic open function for all pipe-like files */
345 static int spufs_pipe_open(struct inode
*inode
, struct file
*file
)
347 struct spufs_inode_info
*i
= SPUFS_I(inode
);
348 file
->private_data
= i
->i_ctx
;
350 return nonseekable_open(inode
, file
);
353 static ssize_t
spufs_mbox_read(struct file
*file
, char __user
*buf
,
354 size_t len
, loff_t
*pos
)
356 struct spu_context
*ctx
= file
->private_data
;
364 ret
= ctx
->ops
->mbox_read(ctx
, &mbox_data
);
370 if (copy_to_user(buf
, &mbox_data
, sizeof mbox_data
))
376 static struct file_operations spufs_mbox_fops
= {
377 .open
= spufs_pipe_open
,
378 .read
= spufs_mbox_read
,
381 static ssize_t
spufs_mbox_stat_read(struct file
*file
, char __user
*buf
,
382 size_t len
, loff_t
*pos
)
384 struct spu_context
*ctx
= file
->private_data
;
392 mbox_stat
= ctx
->ops
->mbox_stat_read(ctx
) & 0xff;
396 if (copy_to_user(buf
, &mbox_stat
, sizeof mbox_stat
))
402 static struct file_operations spufs_mbox_stat_fops
= {
403 .open
= spufs_pipe_open
,
404 .read
= spufs_mbox_stat_read
,
407 /* low-level ibox access function */
408 size_t spu_ibox_read(struct spu_context
*ctx
, u32
*data
)
410 return ctx
->ops
->ibox_read(ctx
, data
);
413 static int spufs_ibox_fasync(int fd
, struct file
*file
, int on
)
415 struct spu_context
*ctx
= file
->private_data
;
417 return fasync_helper(fd
, file
, on
, &ctx
->ibox_fasync
);
420 /* interrupt-level ibox callback function. */
421 void spufs_ibox_callback(struct spu
*spu
)
423 struct spu_context
*ctx
= spu
->ctx
;
425 wake_up_all(&ctx
->ibox_wq
);
426 kill_fasync(&ctx
->ibox_fasync
, SIGIO
, POLLIN
);
429 static ssize_t
spufs_ibox_read(struct file
*file
, char __user
*buf
,
430 size_t len
, loff_t
*pos
)
432 struct spu_context
*ctx
= file
->private_data
;
442 if (file
->f_flags
& O_NONBLOCK
) {
443 if (!spu_ibox_read(ctx
, &ibox_data
))
446 ret
= spufs_wait(ctx
->ibox_wq
, spu_ibox_read(ctx
, &ibox_data
));
455 if (copy_to_user(buf
, &ibox_data
, sizeof ibox_data
))
461 static unsigned int spufs_ibox_poll(struct file
*file
, poll_table
*wait
)
463 struct spu_context
*ctx
= file
->private_data
;
466 poll_wait(file
, &ctx
->ibox_wq
, wait
);
469 mask
= ctx
->ops
->mbox_stat_poll(ctx
, POLLIN
| POLLRDNORM
);
475 static struct file_operations spufs_ibox_fops
= {
476 .open
= spufs_pipe_open
,
477 .read
= spufs_ibox_read
,
478 .poll
= spufs_ibox_poll
,
479 .fasync
= spufs_ibox_fasync
,
482 static ssize_t
spufs_ibox_stat_read(struct file
*file
, char __user
*buf
,
483 size_t len
, loff_t
*pos
)
485 struct spu_context
*ctx
= file
->private_data
;
492 ibox_stat
= (ctx
->ops
->mbox_stat_read(ctx
) >> 16) & 0xff;
495 if (copy_to_user(buf
, &ibox_stat
, sizeof ibox_stat
))
501 static struct file_operations spufs_ibox_stat_fops
= {
502 .open
= spufs_pipe_open
,
503 .read
= spufs_ibox_stat_read
,
506 /* low-level mailbox write */
507 size_t spu_wbox_write(struct spu_context
*ctx
, u32 data
)
509 return ctx
->ops
->wbox_write(ctx
, data
);
512 static int spufs_wbox_fasync(int fd
, struct file
*file
, int on
)
514 struct spu_context
*ctx
= file
->private_data
;
517 ret
= fasync_helper(fd
, file
, on
, &ctx
->wbox_fasync
);
522 /* interrupt-level wbox callback function. */
523 void spufs_wbox_callback(struct spu
*spu
)
525 struct spu_context
*ctx
= spu
->ctx
;
527 wake_up_all(&ctx
->wbox_wq
);
528 kill_fasync(&ctx
->wbox_fasync
, SIGIO
, POLLOUT
);
531 static ssize_t
spufs_wbox_write(struct file
*file
, const char __user
*buf
,
532 size_t len
, loff_t
*pos
)
534 struct spu_context
*ctx
= file
->private_data
;
541 if (copy_from_user(&wbox_data
, buf
, sizeof wbox_data
))
547 if (file
->f_flags
& O_NONBLOCK
) {
548 if (!spu_wbox_write(ctx
, wbox_data
))
551 ret
= spufs_wait(ctx
->wbox_wq
, spu_wbox_write(ctx
, wbox_data
));
556 return ret
? ret
: sizeof wbox_data
;
559 static unsigned int spufs_wbox_poll(struct file
*file
, poll_table
*wait
)
561 struct spu_context
*ctx
= file
->private_data
;
564 poll_wait(file
, &ctx
->wbox_wq
, wait
);
567 mask
= ctx
->ops
->mbox_stat_poll(ctx
, POLLOUT
| POLLWRNORM
);
573 static struct file_operations spufs_wbox_fops
= {
574 .open
= spufs_pipe_open
,
575 .write
= spufs_wbox_write
,
576 .poll
= spufs_wbox_poll
,
577 .fasync
= spufs_wbox_fasync
,
580 static ssize_t
spufs_wbox_stat_read(struct file
*file
, char __user
*buf
,
581 size_t len
, loff_t
*pos
)
583 struct spu_context
*ctx
= file
->private_data
;
590 wbox_stat
= (ctx
->ops
->mbox_stat_read(ctx
) >> 8) & 0xff;
593 if (copy_to_user(buf
, &wbox_stat
, sizeof wbox_stat
))
599 static struct file_operations spufs_wbox_stat_fops
= {
600 .open
= spufs_pipe_open
,
601 .read
= spufs_wbox_stat_read
,
604 static int spufs_signal1_open(struct inode
*inode
, struct file
*file
)
606 struct spufs_inode_info
*i
= SPUFS_I(inode
);
607 struct spu_context
*ctx
= i
->i_ctx
;
608 file
->private_data
= ctx
;
609 file
->f_mapping
= inode
->i_mapping
;
610 ctx
->signal1
= inode
->i_mapping
;
611 return nonseekable_open(inode
, file
);
614 static ssize_t
spufs_signal1_read(struct file
*file
, char __user
*buf
,
615 size_t len
, loff_t
*pos
)
617 struct spu_context
*ctx
= file
->private_data
;
624 data
= ctx
->ops
->signal1_read(ctx
);
627 if (copy_to_user(buf
, &data
, 4))
633 static ssize_t
spufs_signal1_write(struct file
*file
, const char __user
*buf
,
634 size_t len
, loff_t
*pos
)
636 struct spu_context
*ctx
;
639 ctx
= file
->private_data
;
644 if (copy_from_user(&data
, buf
, 4))
648 ctx
->ops
->signal1_write(ctx
, data
);
654 static struct page
*spufs_signal1_mmap_nopage(struct vm_area_struct
*vma
,
655 unsigned long address
, int *type
)
657 #if PAGE_SIZE == 0x1000
658 return spufs_ps_nopage(vma
, address
, type
, 0x14000, 0x1000);
659 #elif PAGE_SIZE == 0x10000
660 /* For 64k pages, both signal1 and signal2 can be used to mmap the whole
661 * signal 1 and 2 area
663 return spufs_ps_nopage(vma
, address
, type
, 0x10000, 0x10000);
665 #error unsupported page size
669 static struct vm_operations_struct spufs_signal1_mmap_vmops
= {
670 .nopage
= spufs_signal1_mmap_nopage
,
673 static int spufs_signal1_mmap(struct file
*file
, struct vm_area_struct
*vma
)
675 if (!(vma
->vm_flags
& VM_SHARED
))
678 vma
->vm_flags
|= VM_RESERVED
;
679 vma
->vm_page_prot
= __pgprot(pgprot_val(vma
->vm_page_prot
)
680 | _PAGE_NO_CACHE
| _PAGE_GUARDED
);
682 vma
->vm_ops
= &spufs_signal1_mmap_vmops
;
686 static struct file_operations spufs_signal1_fops
= {
687 .open
= spufs_signal1_open
,
688 .read
= spufs_signal1_read
,
689 .write
= spufs_signal1_write
,
690 .mmap
= spufs_signal1_mmap
,
693 static int spufs_signal2_open(struct inode
*inode
, struct file
*file
)
695 struct spufs_inode_info
*i
= SPUFS_I(inode
);
696 struct spu_context
*ctx
= i
->i_ctx
;
697 file
->private_data
= ctx
;
698 file
->f_mapping
= inode
->i_mapping
;
699 ctx
->signal2
= inode
->i_mapping
;
700 return nonseekable_open(inode
, file
);
703 static ssize_t
spufs_signal2_read(struct file
*file
, char __user
*buf
,
704 size_t len
, loff_t
*pos
)
706 struct spu_context
*ctx
;
709 ctx
= file
->private_data
;
715 data
= ctx
->ops
->signal2_read(ctx
);
718 if (copy_to_user(buf
, &data
, 4))
724 static ssize_t
spufs_signal2_write(struct file
*file
, const char __user
*buf
,
725 size_t len
, loff_t
*pos
)
727 struct spu_context
*ctx
;
730 ctx
= file
->private_data
;
735 if (copy_from_user(&data
, buf
, 4))
739 ctx
->ops
->signal2_write(ctx
, data
);
746 static struct page
*spufs_signal2_mmap_nopage(struct vm_area_struct
*vma
,
747 unsigned long address
, int *type
)
749 #if PAGE_SIZE == 0x1000
750 return spufs_ps_nopage(vma
, address
, type
, 0x1c000, 0x1000);
751 #elif PAGE_SIZE == 0x10000
752 /* For 64k pages, both signal1 and signal2 can be used to mmap the whole
753 * signal 1 and 2 area
755 return spufs_ps_nopage(vma
, address
, type
, 0x10000, 0x10000);
757 #error unsupported page size
761 static struct vm_operations_struct spufs_signal2_mmap_vmops
= {
762 .nopage
= spufs_signal2_mmap_nopage
,
765 static int spufs_signal2_mmap(struct file
*file
, struct vm_area_struct
*vma
)
767 if (!(vma
->vm_flags
& VM_SHARED
))
771 vma
->vm_flags
|= VM_RESERVED
;
772 vma
->vm_page_prot
= __pgprot(pgprot_val(vma
->vm_page_prot
)
773 | _PAGE_NO_CACHE
| _PAGE_GUARDED
);
775 vma
->vm_ops
= &spufs_signal2_mmap_vmops
;
778 #else /* SPUFS_MMAP_4K */
779 #define spufs_signal2_mmap NULL
780 #endif /* !SPUFS_MMAP_4K */
782 static struct file_operations spufs_signal2_fops
= {
783 .open
= spufs_signal2_open
,
784 .read
= spufs_signal2_read
,
785 .write
= spufs_signal2_write
,
786 .mmap
= spufs_signal2_mmap
,
789 static void spufs_signal1_type_set(void *data
, u64 val
)
791 struct spu_context
*ctx
= data
;
794 ctx
->ops
->signal1_type_set(ctx
, val
);
798 static u64
spufs_signal1_type_get(void *data
)
800 struct spu_context
*ctx
= data
;
804 ret
= ctx
->ops
->signal1_type_get(ctx
);
809 DEFINE_SIMPLE_ATTRIBUTE(spufs_signal1_type
, spufs_signal1_type_get
,
810 spufs_signal1_type_set
, "%llu");
812 static void spufs_signal2_type_set(void *data
, u64 val
)
814 struct spu_context
*ctx
= data
;
817 ctx
->ops
->signal2_type_set(ctx
, val
);
821 static u64
spufs_signal2_type_get(void *data
)
823 struct spu_context
*ctx
= data
;
827 ret
= ctx
->ops
->signal2_type_get(ctx
);
832 DEFINE_SIMPLE_ATTRIBUTE(spufs_signal2_type
, spufs_signal2_type_get
,
833 spufs_signal2_type_set
, "%llu");
836 static struct page
*spufs_mss_mmap_nopage(struct vm_area_struct
*vma
,
837 unsigned long address
, int *type
)
839 return spufs_ps_nopage(vma
, address
, type
, 0x0000, 0x1000);
842 static struct vm_operations_struct spufs_mss_mmap_vmops
= {
843 .nopage
= spufs_mss_mmap_nopage
,
847 * mmap support for problem state MFC DMA area [0x0000 - 0x0fff].
849 static int spufs_mss_mmap(struct file
*file
, struct vm_area_struct
*vma
)
851 if (!(vma
->vm_flags
& VM_SHARED
))
854 vma
->vm_flags
|= VM_RESERVED
;
855 vma
->vm_page_prot
= __pgprot(pgprot_val(vma
->vm_page_prot
)
856 | _PAGE_NO_CACHE
| _PAGE_GUARDED
);
858 vma
->vm_ops
= &spufs_mss_mmap_vmops
;
861 #else /* SPUFS_MMAP_4K */
862 #define spufs_mss_mmap NULL
863 #endif /* !SPUFS_MMAP_4K */
865 static int spufs_mss_open(struct inode
*inode
, struct file
*file
)
867 struct spufs_inode_info
*i
= SPUFS_I(inode
);
869 file
->private_data
= i
->i_ctx
;
870 return nonseekable_open(inode
, file
);
873 static struct file_operations spufs_mss_fops
= {
874 .open
= spufs_mss_open
,
875 .mmap
= spufs_mss_mmap
,
878 static struct page
*spufs_psmap_mmap_nopage(struct vm_area_struct
*vma
,
879 unsigned long address
, int *type
)
881 return spufs_ps_nopage(vma
, address
, type
, 0x0000, 0x20000);
884 static struct vm_operations_struct spufs_psmap_mmap_vmops
= {
885 .nopage
= spufs_psmap_mmap_nopage
,
889 * mmap support for full problem state area [0x00000 - 0x1ffff].
891 static int spufs_psmap_mmap(struct file
*file
, struct vm_area_struct
*vma
)
893 if (!(vma
->vm_flags
& VM_SHARED
))
896 vma
->vm_flags
|= VM_RESERVED
;
897 vma
->vm_page_prot
= __pgprot(pgprot_val(vma
->vm_page_prot
)
898 | _PAGE_NO_CACHE
| _PAGE_GUARDED
);
900 vma
->vm_ops
= &spufs_psmap_mmap_vmops
;
904 static int spufs_psmap_open(struct inode
*inode
, struct file
*file
)
906 struct spufs_inode_info
*i
= SPUFS_I(inode
);
908 file
->private_data
= i
->i_ctx
;
909 return nonseekable_open(inode
, file
);
912 static struct file_operations spufs_psmap_fops
= {
913 .open
= spufs_psmap_open
,
914 .mmap
= spufs_psmap_mmap
,
919 static struct page
*spufs_mfc_mmap_nopage(struct vm_area_struct
*vma
,
920 unsigned long address
, int *type
)
922 return spufs_ps_nopage(vma
, address
, type
, 0x3000, 0x1000);
925 static struct vm_operations_struct spufs_mfc_mmap_vmops
= {
926 .nopage
= spufs_mfc_mmap_nopage
,
930 * mmap support for problem state MFC DMA area [0x0000 - 0x0fff].
932 static int spufs_mfc_mmap(struct file
*file
, struct vm_area_struct
*vma
)
934 if (!(vma
->vm_flags
& VM_SHARED
))
937 vma
->vm_flags
|= VM_RESERVED
;
938 vma
->vm_page_prot
= __pgprot(pgprot_val(vma
->vm_page_prot
)
939 | _PAGE_NO_CACHE
| _PAGE_GUARDED
);
941 vma
->vm_ops
= &spufs_mfc_mmap_vmops
;
944 #else /* SPUFS_MMAP_4K */
945 #define spufs_mfc_mmap NULL
946 #endif /* !SPUFS_MMAP_4K */
948 static int spufs_mfc_open(struct inode
*inode
, struct file
*file
)
950 struct spufs_inode_info
*i
= SPUFS_I(inode
);
951 struct spu_context
*ctx
= i
->i_ctx
;
953 /* we don't want to deal with DMA into other processes */
954 if (ctx
->owner
!= current
->mm
)
957 if (atomic_read(&inode
->i_count
) != 1)
960 file
->private_data
= ctx
;
961 return nonseekable_open(inode
, file
);
964 /* interrupt-level mfc callback function. */
965 void spufs_mfc_callback(struct spu
*spu
)
967 struct spu_context
*ctx
= spu
->ctx
;
969 wake_up_all(&ctx
->mfc_wq
);
971 pr_debug("%s %s\n", __FUNCTION__
, spu
->name
);
972 if (ctx
->mfc_fasync
) {
973 u32 free_elements
, tagstatus
;
976 /* no need for spu_acquire in interrupt context */
977 free_elements
= ctx
->ops
->get_mfc_free_elements(ctx
);
978 tagstatus
= ctx
->ops
->read_mfc_tagstatus(ctx
);
981 if (free_elements
& 0xffff)
983 if (tagstatus
& ctx
->tagwait
)
986 kill_fasync(&ctx
->mfc_fasync
, SIGIO
, mask
);
990 static int spufs_read_mfc_tagstatus(struct spu_context
*ctx
, u32
*status
)
992 /* See if there is one tag group is complete */
993 /* FIXME we need locking around tagwait */
994 *status
= ctx
->ops
->read_mfc_tagstatus(ctx
) & ctx
->tagwait
;
995 ctx
->tagwait
&= ~*status
;
999 /* enable interrupt waiting for any tag group,
1000 may silently fail if interrupts are already enabled */
1001 ctx
->ops
->set_mfc_query(ctx
, ctx
->tagwait
, 1);
1005 static ssize_t
spufs_mfc_read(struct file
*file
, char __user
*buffer
,
1006 size_t size
, loff_t
*pos
)
1008 struct spu_context
*ctx
= file
->private_data
;
1016 if (file
->f_flags
& O_NONBLOCK
) {
1017 status
= ctx
->ops
->read_mfc_tagstatus(ctx
);
1018 if (!(status
& ctx
->tagwait
))
1021 ctx
->tagwait
&= ~status
;
1023 ret
= spufs_wait(ctx
->mfc_wq
,
1024 spufs_read_mfc_tagstatus(ctx
, &status
));
1032 if (copy_to_user(buffer
, &status
, 4))
1039 static int spufs_check_valid_dma(struct mfc_dma_command
*cmd
)
1041 pr_debug("queueing DMA %x %lx %x %x %x\n", cmd
->lsa
,
1042 cmd
->ea
, cmd
->size
, cmd
->tag
, cmd
->cmd
);
1053 pr_debug("invalid DMA opcode %x\n", cmd
->cmd
);
1057 if ((cmd
->lsa
& 0xf) != (cmd
->ea
&0xf)) {
1058 pr_debug("invalid DMA alignment, ea %lx lsa %x\n",
1063 switch (cmd
->size
& 0xf) {
1084 pr_debug("invalid DMA alignment %x for size %x\n",
1085 cmd
->lsa
& 0xf, cmd
->size
);
1089 if (cmd
->size
> 16 * 1024) {
1090 pr_debug("invalid DMA size %x\n", cmd
->size
);
1094 if (cmd
->tag
& 0xfff0) {
1095 /* we reserve the higher tag numbers for kernel use */
1096 pr_debug("invalid DMA tag\n");
1101 /* not supported in this version */
1102 pr_debug("invalid DMA class\n");
1109 static int spu_send_mfc_command(struct spu_context
*ctx
,
1110 struct mfc_dma_command cmd
,
1113 *error
= ctx
->ops
->send_mfc_command(ctx
, &cmd
);
1114 if (*error
== -EAGAIN
) {
1115 /* wait for any tag group to complete
1116 so we have space for the new command */
1117 ctx
->ops
->set_mfc_query(ctx
, ctx
->tagwait
, 1);
1118 /* try again, because the queue might be
1120 *error
= ctx
->ops
->send_mfc_command(ctx
, &cmd
);
1121 if (*error
== -EAGAIN
)
1127 static ssize_t
spufs_mfc_write(struct file
*file
, const char __user
*buffer
,
1128 size_t size
, loff_t
*pos
)
1130 struct spu_context
*ctx
= file
->private_data
;
1131 struct mfc_dma_command cmd
;
1134 if (size
!= sizeof cmd
)
1138 if (copy_from_user(&cmd
, buffer
, sizeof cmd
))
1141 ret
= spufs_check_valid_dma(&cmd
);
1145 spu_acquire_runnable(ctx
);
1146 if (file
->f_flags
& O_NONBLOCK
) {
1147 ret
= ctx
->ops
->send_mfc_command(ctx
, &cmd
);
1150 ret
= spufs_wait(ctx
->mfc_wq
,
1151 spu_send_mfc_command(ctx
, cmd
, &status
));
1160 ctx
->tagwait
|= 1 << cmd
.tag
;
1166 static unsigned int spufs_mfc_poll(struct file
*file
,poll_table
*wait
)
1168 struct spu_context
*ctx
= file
->private_data
;
1169 u32 free_elements
, tagstatus
;
1173 ctx
->ops
->set_mfc_query(ctx
, ctx
->tagwait
, 2);
1174 free_elements
= ctx
->ops
->get_mfc_free_elements(ctx
);
1175 tagstatus
= ctx
->ops
->read_mfc_tagstatus(ctx
);
1178 poll_wait(file
, &ctx
->mfc_wq
, wait
);
1181 if (free_elements
& 0xffff)
1182 mask
|= POLLOUT
| POLLWRNORM
;
1183 if (tagstatus
& ctx
->tagwait
)
1184 mask
|= POLLIN
| POLLRDNORM
;
1186 pr_debug("%s: free %d tagstatus %d tagwait %d\n", __FUNCTION__
,
1187 free_elements
, tagstatus
, ctx
->tagwait
);
1192 static int spufs_mfc_flush(struct file
*file
, fl_owner_t id
)
1194 struct spu_context
*ctx
= file
->private_data
;
1199 /* this currently hangs */
1200 ret
= spufs_wait(ctx
->mfc_wq
,
1201 ctx
->ops
->set_mfc_query(ctx
, ctx
->tagwait
, 2));
1204 ret
= spufs_wait(ctx
->mfc_wq
,
1205 ctx
->ops
->read_mfc_tagstatus(ctx
) == ctx
->tagwait
);
1215 static int spufs_mfc_fsync(struct file
*file
, struct dentry
*dentry
,
1218 return spufs_mfc_flush(file
, NULL
);
1221 static int spufs_mfc_fasync(int fd
, struct file
*file
, int on
)
1223 struct spu_context
*ctx
= file
->private_data
;
1225 return fasync_helper(fd
, file
, on
, &ctx
->mfc_fasync
);
1228 static struct file_operations spufs_mfc_fops
= {
1229 .open
= spufs_mfc_open
,
1230 .read
= spufs_mfc_read
,
1231 .write
= spufs_mfc_write
,
1232 .poll
= spufs_mfc_poll
,
1233 .flush
= spufs_mfc_flush
,
1234 .fsync
= spufs_mfc_fsync
,
1235 .fasync
= spufs_mfc_fasync
,
1236 .mmap
= spufs_mfc_mmap
,
1239 static void spufs_npc_set(void *data
, u64 val
)
1241 struct spu_context
*ctx
= data
;
1243 ctx
->ops
->npc_write(ctx
, val
);
1247 static u64
spufs_npc_get(void *data
)
1249 struct spu_context
*ctx
= data
;
1252 ret
= ctx
->ops
->npc_read(ctx
);
1256 DEFINE_SIMPLE_ATTRIBUTE(spufs_npc_ops
, spufs_npc_get
, spufs_npc_set
, "%llx\n")
1258 static void spufs_decr_set(void *data
, u64 val
)
1260 struct spu_context
*ctx
= data
;
1261 struct spu_lscsa
*lscsa
= ctx
->csa
.lscsa
;
1262 spu_acquire_saved(ctx
);
1263 lscsa
->decr
.slot
[0] = (u32
) val
;
1267 static u64
spufs_decr_get(void *data
)
1269 struct spu_context
*ctx
= data
;
1270 struct spu_lscsa
*lscsa
= ctx
->csa
.lscsa
;
1272 spu_acquire_saved(ctx
);
1273 ret
= lscsa
->decr
.slot
[0];
1277 DEFINE_SIMPLE_ATTRIBUTE(spufs_decr_ops
, spufs_decr_get
, spufs_decr_set
,
1280 static void spufs_decr_status_set(void *data
, u64 val
)
1282 struct spu_context
*ctx
= data
;
1283 struct spu_lscsa
*lscsa
= ctx
->csa
.lscsa
;
1284 spu_acquire_saved(ctx
);
1285 lscsa
->decr_status
.slot
[0] = (u32
) val
;
1289 static u64
spufs_decr_status_get(void *data
)
1291 struct spu_context
*ctx
= data
;
1292 struct spu_lscsa
*lscsa
= ctx
->csa
.lscsa
;
1294 spu_acquire_saved(ctx
);
1295 ret
= lscsa
->decr_status
.slot
[0];
1299 DEFINE_SIMPLE_ATTRIBUTE(spufs_decr_status_ops
, spufs_decr_status_get
,
1300 spufs_decr_status_set
, "%llx\n")
1302 static void spufs_spu_tag_mask_set(void *data
, u64 val
)
1304 struct spu_context
*ctx
= data
;
1305 struct spu_lscsa
*lscsa
= ctx
->csa
.lscsa
;
1306 spu_acquire_saved(ctx
);
1307 lscsa
->tag_mask
.slot
[0] = (u32
) val
;
1311 static u64
spufs_spu_tag_mask_get(void *data
)
1313 struct spu_context
*ctx
= data
;
1314 struct spu_lscsa
*lscsa
= ctx
->csa
.lscsa
;
1316 spu_acquire_saved(ctx
);
1317 ret
= lscsa
->tag_mask
.slot
[0];
1321 DEFINE_SIMPLE_ATTRIBUTE(spufs_spu_tag_mask_ops
, spufs_spu_tag_mask_get
,
1322 spufs_spu_tag_mask_set
, "%llx\n")
1324 static void spufs_event_mask_set(void *data
, u64 val
)
1326 struct spu_context
*ctx
= data
;
1327 struct spu_lscsa
*lscsa
= ctx
->csa
.lscsa
;
1328 spu_acquire_saved(ctx
);
1329 lscsa
->event_mask
.slot
[0] = (u32
) val
;
1333 static u64
spufs_event_mask_get(void *data
)
1335 struct spu_context
*ctx
= data
;
1336 struct spu_lscsa
*lscsa
= ctx
->csa
.lscsa
;
1338 spu_acquire_saved(ctx
);
1339 ret
= lscsa
->event_mask
.slot
[0];
1343 DEFINE_SIMPLE_ATTRIBUTE(spufs_event_mask_ops
, spufs_event_mask_get
,
1344 spufs_event_mask_set
, "%llx\n")
1346 static void spufs_srr0_set(void *data
, u64 val
)
1348 struct spu_context
*ctx
= data
;
1349 struct spu_lscsa
*lscsa
= ctx
->csa
.lscsa
;
1350 spu_acquire_saved(ctx
);
1351 lscsa
->srr0
.slot
[0] = (u32
) val
;
1355 static u64
spufs_srr0_get(void *data
)
1357 struct spu_context
*ctx
= data
;
1358 struct spu_lscsa
*lscsa
= ctx
->csa
.lscsa
;
1360 spu_acquire_saved(ctx
);
1361 ret
= lscsa
->srr0
.slot
[0];
1365 DEFINE_SIMPLE_ATTRIBUTE(spufs_srr0_ops
, spufs_srr0_get
, spufs_srr0_set
,
1368 static u64
spufs_id_get(void *data
)
1370 struct spu_context
*ctx
= data
;
1374 if (ctx
->state
== SPU_STATE_RUNNABLE
)
1375 num
= ctx
->spu
->number
;
1377 num
= (unsigned int)-1;
1382 DEFINE_SIMPLE_ATTRIBUTE(spufs_id_ops
, spufs_id_get
, NULL
, "0x%llx\n")
1384 struct tree_descr spufs_dir_contents
[] = {
1385 { "mem", &spufs_mem_fops
, 0666, },
1386 { "regs", &spufs_regs_fops
, 0666, },
1387 { "mbox", &spufs_mbox_fops
, 0444, },
1388 { "ibox", &spufs_ibox_fops
, 0444, },
1389 { "wbox", &spufs_wbox_fops
, 0222, },
1390 { "mbox_stat", &spufs_mbox_stat_fops
, 0444, },
1391 { "ibox_stat", &spufs_ibox_stat_fops
, 0444, },
1392 { "wbox_stat", &spufs_wbox_stat_fops
, 0444, },
1393 { "signal1", &spufs_signal1_fops
, 0666, },
1394 { "signal2", &spufs_signal2_fops
, 0666, },
1395 { "signal1_type", &spufs_signal1_type
, 0666, },
1396 { "signal2_type", &spufs_signal2_type
, 0666, },
1397 { "mss", &spufs_mss_fops
, 0666, },
1398 { "mfc", &spufs_mfc_fops
, 0666, },
1399 { "cntl", &spufs_cntl_fops
, 0666, },
1400 { "npc", &spufs_npc_ops
, 0666, },
1401 { "fpcr", &spufs_fpcr_fops
, 0666, },
1402 { "decr", &spufs_decr_ops
, 0666, },
1403 { "decr_status", &spufs_decr_status_ops
, 0666, },
1404 { "spu_tag_mask", &spufs_spu_tag_mask_ops
, 0666, },
1405 { "event_mask", &spufs_event_mask_ops
, 0666, },
1406 { "srr0", &spufs_srr0_ops
, 0666, },
1407 { "phys-id", &spufs_id_ops
, 0666, },
1408 { "psmap", &spufs_psmap_fops
, 0666, },