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/export.h>
28 #include <linux/pagemap.h>
29 #include <linux/poll.h>
30 #include <linux/ptrace.h>
31 #include <linux/seq_file.h>
32 #include <linux/slab.h>
37 #include <asm/spu_info.h>
38 #include <linux/uaccess.h>
43 #define SPUFS_MMAP_4K (PAGE_SIZE == 0x1000)
45 /* Simple attribute files */
47 int (*get
)(void *, u64
*);
48 int (*set
)(void *, u64
);
49 char get_buf
[24]; /* enough to store a u64 and "\n\0" */
52 const char *fmt
; /* format for read operation */
53 struct mutex mutex
; /* protects access to these buffers */
56 static int spufs_attr_open(struct inode
*inode
, struct file
*file
,
57 int (*get
)(void *, u64
*), int (*set
)(void *, u64
),
60 struct spufs_attr
*attr
;
62 attr
= kmalloc(sizeof(*attr
), GFP_KERNEL
);
68 attr
->data
= inode
->i_private
;
70 mutex_init(&attr
->mutex
);
71 file
->private_data
= attr
;
73 return nonseekable_open(inode
, file
);
76 static int spufs_attr_release(struct inode
*inode
, struct file
*file
)
78 kfree(file
->private_data
);
82 static ssize_t
spufs_attr_read(struct file
*file
, char __user
*buf
,
83 size_t len
, loff_t
*ppos
)
85 struct spufs_attr
*attr
;
89 attr
= file
->private_data
;
93 ret
= mutex_lock_interruptible(&attr
->mutex
);
97 if (*ppos
) { /* continued read */
98 size
= strlen(attr
->get_buf
);
99 } else { /* first read */
101 ret
= attr
->get(attr
->data
, &val
);
105 size
= scnprintf(attr
->get_buf
, sizeof(attr
->get_buf
),
106 attr
->fmt
, (unsigned long long)val
);
109 ret
= simple_read_from_buffer(buf
, len
, ppos
, attr
->get_buf
, size
);
111 mutex_unlock(&attr
->mutex
);
115 static ssize_t
spufs_attr_write(struct file
*file
, const char __user
*buf
,
116 size_t len
, loff_t
*ppos
)
118 struct spufs_attr
*attr
;
123 attr
= file
->private_data
;
127 ret
= mutex_lock_interruptible(&attr
->mutex
);
132 size
= min(sizeof(attr
->set_buf
) - 1, len
);
133 if (copy_from_user(attr
->set_buf
, buf
, size
))
136 ret
= len
; /* claim we got the whole input */
137 attr
->set_buf
[size
] = '\0';
138 val
= simple_strtol(attr
->set_buf
, NULL
, 0);
139 attr
->set(attr
->data
, val
);
141 mutex_unlock(&attr
->mutex
);
145 #define DEFINE_SPUFS_SIMPLE_ATTRIBUTE(__fops, __get, __set, __fmt) \
146 static int __fops ## _open(struct inode *inode, struct file *file) \
148 __simple_attr_check_format(__fmt, 0ull); \
149 return spufs_attr_open(inode, file, __get, __set, __fmt); \
151 static const struct file_operations __fops = { \
152 .open = __fops ## _open, \
153 .release = spufs_attr_release, \
154 .read = spufs_attr_read, \
155 .write = spufs_attr_write, \
156 .llseek = generic_file_llseek, \
161 spufs_mem_open(struct inode
*inode
, struct file
*file
)
163 struct spufs_inode_info
*i
= SPUFS_I(inode
);
164 struct spu_context
*ctx
= i
->i_ctx
;
166 mutex_lock(&ctx
->mapping_lock
);
167 file
->private_data
= ctx
;
169 ctx
->local_store
= inode
->i_mapping
;
170 mutex_unlock(&ctx
->mapping_lock
);
175 spufs_mem_release(struct inode
*inode
, struct file
*file
)
177 struct spufs_inode_info
*i
= SPUFS_I(inode
);
178 struct spu_context
*ctx
= i
->i_ctx
;
180 mutex_lock(&ctx
->mapping_lock
);
182 ctx
->local_store
= NULL
;
183 mutex_unlock(&ctx
->mapping_lock
);
188 __spufs_mem_read(struct spu_context
*ctx
, char __user
*buffer
,
189 size_t size
, loff_t
*pos
)
191 char *local_store
= ctx
->ops
->get_ls(ctx
);
192 return simple_read_from_buffer(buffer
, size
, pos
, local_store
,
197 spufs_mem_read(struct file
*file
, char __user
*buffer
,
198 size_t size
, loff_t
*pos
)
200 struct spu_context
*ctx
= file
->private_data
;
203 ret
= spu_acquire(ctx
);
206 ret
= __spufs_mem_read(ctx
, buffer
, size
, pos
);
213 spufs_mem_write(struct file
*file
, const char __user
*buffer
,
214 size_t size
, loff_t
*ppos
)
216 struct spu_context
*ctx
= file
->private_data
;
224 ret
= spu_acquire(ctx
);
228 local_store
= ctx
->ops
->get_ls(ctx
);
229 size
= simple_write_to_buffer(local_store
, LS_SIZE
, ppos
, buffer
, size
);
236 spufs_mem_mmap_fault(struct vm_area_struct
*vma
, struct vm_fault
*vmf
)
238 struct spu_context
*ctx
= vma
->vm_file
->private_data
;
239 unsigned long pfn
, offset
;
241 offset
= vmf
->pgoff
<< PAGE_SHIFT
;
242 if (offset
>= LS_SIZE
)
243 return VM_FAULT_SIGBUS
;
245 pr_debug("spufs_mem_mmap_fault address=0x%lx, offset=0x%lx\n",
246 vmf
->address
, offset
);
248 if (spu_acquire(ctx
))
249 return VM_FAULT_NOPAGE
;
251 if (ctx
->state
== SPU_STATE_SAVED
) {
252 vma
->vm_page_prot
= pgprot_cached(vma
->vm_page_prot
);
253 pfn
= vmalloc_to_pfn(ctx
->csa
.lscsa
->ls
+ offset
);
255 vma
->vm_page_prot
= pgprot_noncached_wc(vma
->vm_page_prot
);
256 pfn
= (ctx
->spu
->local_store_phys
+ offset
) >> PAGE_SHIFT
;
258 vm_insert_pfn(vma
, vmf
->address
, pfn
);
262 return VM_FAULT_NOPAGE
;
265 static int spufs_mem_mmap_access(struct vm_area_struct
*vma
,
266 unsigned long address
,
267 void *buf
, int len
, int write
)
269 struct spu_context
*ctx
= vma
->vm_file
->private_data
;
270 unsigned long offset
= address
- vma
->vm_start
;
273 if (write
&& !(vma
->vm_flags
& VM_WRITE
))
275 if (spu_acquire(ctx
))
277 if ((offset
+ len
) > vma
->vm_end
)
278 len
= vma
->vm_end
- offset
;
279 local_store
= ctx
->ops
->get_ls(ctx
);
281 memcpy_toio(local_store
+ offset
, buf
, len
);
283 memcpy_fromio(buf
, local_store
+ offset
, len
);
288 static const struct vm_operations_struct spufs_mem_mmap_vmops
= {
289 .fault
= spufs_mem_mmap_fault
,
290 .access
= spufs_mem_mmap_access
,
293 static int spufs_mem_mmap(struct file
*file
, struct vm_area_struct
*vma
)
295 if (!(vma
->vm_flags
& VM_SHARED
))
298 vma
->vm_flags
|= VM_IO
| VM_PFNMAP
;
299 vma
->vm_page_prot
= pgprot_noncached_wc(vma
->vm_page_prot
);
301 vma
->vm_ops
= &spufs_mem_mmap_vmops
;
305 static const struct file_operations spufs_mem_fops
= {
306 .open
= spufs_mem_open
,
307 .release
= spufs_mem_release
,
308 .read
= spufs_mem_read
,
309 .write
= spufs_mem_write
,
310 .llseek
= generic_file_llseek
,
311 .mmap
= spufs_mem_mmap
,
314 static int spufs_ps_fault(struct vm_area_struct
*vma
,
315 struct vm_fault
*vmf
,
316 unsigned long ps_offs
,
317 unsigned long ps_size
)
319 struct spu_context
*ctx
= vma
->vm_file
->private_data
;
320 unsigned long area
, offset
= vmf
->pgoff
<< PAGE_SHIFT
;
323 spu_context_nospu_trace(spufs_ps_fault__enter
, ctx
);
325 if (offset
>= ps_size
)
326 return VM_FAULT_SIGBUS
;
328 if (fatal_signal_pending(current
))
329 return VM_FAULT_SIGBUS
;
332 * Because we release the mmap_sem, the context may be destroyed while
333 * we're in spu_wait. Grab an extra reference so it isn't destroyed
336 get_spu_context(ctx
);
339 * We have to wait for context to be loaded before we have
340 * pages to hand out to the user, but we don't want to wait
341 * with the mmap_sem held.
342 * It is possible to drop the mmap_sem here, but then we need
343 * to return VM_FAULT_NOPAGE because the mappings may have
346 if (spu_acquire(ctx
))
349 if (ctx
->state
== SPU_STATE_SAVED
) {
350 up_read(¤t
->mm
->mmap_sem
);
351 spu_context_nospu_trace(spufs_ps_fault__sleep
, ctx
);
352 ret
= spufs_wait(ctx
->run_wq
, ctx
->state
== SPU_STATE_RUNNABLE
);
353 spu_context_trace(spufs_ps_fault__wake
, ctx
, ctx
->spu
);
354 down_read(¤t
->mm
->mmap_sem
);
356 area
= ctx
->spu
->problem_phys
+ ps_offs
;
357 vm_insert_pfn(vma
, vmf
->address
, (area
+ offset
) >> PAGE_SHIFT
);
358 spu_context_trace(spufs_ps_fault__insert
, ctx
, ctx
->spu
);
365 put_spu_context(ctx
);
366 return VM_FAULT_NOPAGE
;
370 static int spufs_cntl_mmap_fault(struct vm_area_struct
*vma
,
371 struct vm_fault
*vmf
)
373 return spufs_ps_fault(vma
, vmf
, 0x4000, SPUFS_CNTL_MAP_SIZE
);
376 static const struct vm_operations_struct spufs_cntl_mmap_vmops
= {
377 .fault
= spufs_cntl_mmap_fault
,
381 * mmap support for problem state control area [0x4000 - 0x4fff].
383 static int spufs_cntl_mmap(struct file
*file
, struct vm_area_struct
*vma
)
385 if (!(vma
->vm_flags
& VM_SHARED
))
388 vma
->vm_flags
|= VM_IO
| VM_PFNMAP
;
389 vma
->vm_page_prot
= pgprot_noncached(vma
->vm_page_prot
);
391 vma
->vm_ops
= &spufs_cntl_mmap_vmops
;
394 #else /* SPUFS_MMAP_4K */
395 #define spufs_cntl_mmap NULL
396 #endif /* !SPUFS_MMAP_4K */
398 static int spufs_cntl_get(void *data
, u64
*val
)
400 struct spu_context
*ctx
= data
;
403 ret
= spu_acquire(ctx
);
406 *val
= ctx
->ops
->status_read(ctx
);
412 static int spufs_cntl_set(void *data
, u64 val
)
414 struct spu_context
*ctx
= data
;
417 ret
= spu_acquire(ctx
);
420 ctx
->ops
->runcntl_write(ctx
, val
);
426 static int spufs_cntl_open(struct inode
*inode
, struct file
*file
)
428 struct spufs_inode_info
*i
= SPUFS_I(inode
);
429 struct spu_context
*ctx
= i
->i_ctx
;
431 mutex_lock(&ctx
->mapping_lock
);
432 file
->private_data
= ctx
;
434 ctx
->cntl
= inode
->i_mapping
;
435 mutex_unlock(&ctx
->mapping_lock
);
436 return simple_attr_open(inode
, file
, spufs_cntl_get
,
437 spufs_cntl_set
, "0x%08lx");
441 spufs_cntl_release(struct inode
*inode
, struct file
*file
)
443 struct spufs_inode_info
*i
= SPUFS_I(inode
);
444 struct spu_context
*ctx
= i
->i_ctx
;
446 simple_attr_release(inode
, file
);
448 mutex_lock(&ctx
->mapping_lock
);
451 mutex_unlock(&ctx
->mapping_lock
);
455 static const struct file_operations spufs_cntl_fops
= {
456 .open
= spufs_cntl_open
,
457 .release
= spufs_cntl_release
,
458 .read
= simple_attr_read
,
459 .write
= simple_attr_write
,
460 .llseek
= generic_file_llseek
,
461 .mmap
= spufs_cntl_mmap
,
465 spufs_regs_open(struct inode
*inode
, struct file
*file
)
467 struct spufs_inode_info
*i
= SPUFS_I(inode
);
468 file
->private_data
= i
->i_ctx
;
473 __spufs_regs_read(struct spu_context
*ctx
, char __user
*buffer
,
474 size_t size
, loff_t
*pos
)
476 struct spu_lscsa
*lscsa
= ctx
->csa
.lscsa
;
477 return simple_read_from_buffer(buffer
, size
, pos
,
478 lscsa
->gprs
, sizeof lscsa
->gprs
);
482 spufs_regs_read(struct file
*file
, char __user
*buffer
,
483 size_t size
, loff_t
*pos
)
486 struct spu_context
*ctx
= file
->private_data
;
488 /* pre-check for file position: if we'd return EOF, there's no point
489 * causing a deschedule */
490 if (*pos
>= sizeof(ctx
->csa
.lscsa
->gprs
))
493 ret
= spu_acquire_saved(ctx
);
496 ret
= __spufs_regs_read(ctx
, buffer
, size
, pos
);
497 spu_release_saved(ctx
);
502 spufs_regs_write(struct file
*file
, const char __user
*buffer
,
503 size_t size
, loff_t
*pos
)
505 struct spu_context
*ctx
= file
->private_data
;
506 struct spu_lscsa
*lscsa
= ctx
->csa
.lscsa
;
509 if (*pos
>= sizeof(lscsa
->gprs
))
512 ret
= spu_acquire_saved(ctx
);
516 size
= simple_write_to_buffer(lscsa
->gprs
, sizeof(lscsa
->gprs
), pos
,
519 spu_release_saved(ctx
);
523 static const struct file_operations spufs_regs_fops
= {
524 .open
= spufs_regs_open
,
525 .read
= spufs_regs_read
,
526 .write
= spufs_regs_write
,
527 .llseek
= generic_file_llseek
,
531 __spufs_fpcr_read(struct spu_context
*ctx
, char __user
* buffer
,
532 size_t size
, loff_t
* pos
)
534 struct spu_lscsa
*lscsa
= ctx
->csa
.lscsa
;
535 return simple_read_from_buffer(buffer
, size
, pos
,
536 &lscsa
->fpcr
, sizeof(lscsa
->fpcr
));
540 spufs_fpcr_read(struct file
*file
, char __user
* buffer
,
541 size_t size
, loff_t
* pos
)
544 struct spu_context
*ctx
= file
->private_data
;
546 ret
= spu_acquire_saved(ctx
);
549 ret
= __spufs_fpcr_read(ctx
, buffer
, size
, pos
);
550 spu_release_saved(ctx
);
555 spufs_fpcr_write(struct file
*file
, const char __user
* buffer
,
556 size_t size
, loff_t
* pos
)
558 struct spu_context
*ctx
= file
->private_data
;
559 struct spu_lscsa
*lscsa
= ctx
->csa
.lscsa
;
562 if (*pos
>= sizeof(lscsa
->fpcr
))
565 ret
= spu_acquire_saved(ctx
);
569 size
= simple_write_to_buffer(&lscsa
->fpcr
, sizeof(lscsa
->fpcr
), pos
,
572 spu_release_saved(ctx
);
576 static const struct file_operations spufs_fpcr_fops
= {
577 .open
= spufs_regs_open
,
578 .read
= spufs_fpcr_read
,
579 .write
= spufs_fpcr_write
,
580 .llseek
= generic_file_llseek
,
583 /* generic open function for all pipe-like files */
584 static int spufs_pipe_open(struct inode
*inode
, struct file
*file
)
586 struct spufs_inode_info
*i
= SPUFS_I(inode
);
587 file
->private_data
= i
->i_ctx
;
589 return nonseekable_open(inode
, file
);
593 * Read as many bytes from the mailbox as possible, until
594 * one of the conditions becomes true:
596 * - no more data available in the mailbox
597 * - end of the user provided buffer
598 * - end of the mapped area
600 static ssize_t
spufs_mbox_read(struct file
*file
, char __user
*buf
,
601 size_t len
, loff_t
*pos
)
603 struct spu_context
*ctx
= file
->private_data
;
604 u32 mbox_data
, __user
*udata
;
610 if (!access_ok(VERIFY_WRITE
, buf
, len
))
613 udata
= (void __user
*)buf
;
615 count
= spu_acquire(ctx
);
619 for (count
= 0; (count
+ 4) <= len
; count
+= 4, udata
++) {
621 ret
= ctx
->ops
->mbox_read(ctx
, &mbox_data
);
626 * at the end of the mapped area, we can fault
627 * but still need to return the data we have
628 * read successfully so far.
630 ret
= __put_user(mbox_data
, udata
);
645 static const struct file_operations spufs_mbox_fops
= {
646 .open
= spufs_pipe_open
,
647 .read
= spufs_mbox_read
,
651 static ssize_t
spufs_mbox_stat_read(struct file
*file
, char __user
*buf
,
652 size_t len
, loff_t
*pos
)
654 struct spu_context
*ctx
= file
->private_data
;
661 ret
= spu_acquire(ctx
);
665 mbox_stat
= ctx
->ops
->mbox_stat_read(ctx
) & 0xff;
669 if (copy_to_user(buf
, &mbox_stat
, sizeof mbox_stat
))
675 static const struct file_operations spufs_mbox_stat_fops
= {
676 .open
= spufs_pipe_open
,
677 .read
= spufs_mbox_stat_read
,
681 /* low-level ibox access function */
682 size_t spu_ibox_read(struct spu_context
*ctx
, u32
*data
)
684 return ctx
->ops
->ibox_read(ctx
, data
);
687 static int spufs_ibox_fasync(int fd
, struct file
*file
, int on
)
689 struct spu_context
*ctx
= file
->private_data
;
691 return fasync_helper(fd
, file
, on
, &ctx
->ibox_fasync
);
694 /* interrupt-level ibox callback function. */
695 void spufs_ibox_callback(struct spu
*spu
)
697 struct spu_context
*ctx
= spu
->ctx
;
702 wake_up_all(&ctx
->ibox_wq
);
703 kill_fasync(&ctx
->ibox_fasync
, SIGIO
, POLLIN
);
707 * Read as many bytes from the interrupt mailbox as possible, until
708 * one of the conditions becomes true:
710 * - no more data available in the mailbox
711 * - end of the user provided buffer
712 * - end of the mapped area
714 * If the file is opened without O_NONBLOCK, we wait here until
715 * any data is available, but return when we have been able to
718 static ssize_t
spufs_ibox_read(struct file
*file
, char __user
*buf
,
719 size_t len
, loff_t
*pos
)
721 struct spu_context
*ctx
= file
->private_data
;
722 u32 ibox_data
, __user
*udata
;
728 if (!access_ok(VERIFY_WRITE
, buf
, len
))
731 udata
= (void __user
*)buf
;
733 count
= spu_acquire(ctx
);
737 /* wait only for the first element */
739 if (file
->f_flags
& O_NONBLOCK
) {
740 if (!spu_ibox_read(ctx
, &ibox_data
)) {
745 count
= spufs_wait(ctx
->ibox_wq
, spu_ibox_read(ctx
, &ibox_data
));
750 /* if we can't write at all, return -EFAULT */
751 count
= __put_user(ibox_data
, udata
);
755 for (count
= 4, udata
++; (count
+ 4) <= len
; count
+= 4, udata
++) {
757 ret
= ctx
->ops
->ibox_read(ctx
, &ibox_data
);
761 * at the end of the mapped area, we can fault
762 * but still need to return the data we have
763 * read successfully so far.
765 ret
= __put_user(ibox_data
, udata
);
776 static unsigned int spufs_ibox_poll(struct file
*file
, poll_table
*wait
)
778 struct spu_context
*ctx
= file
->private_data
;
781 poll_wait(file
, &ctx
->ibox_wq
, wait
);
784 * For now keep this uninterruptible and also ignore the rule
785 * that poll should not sleep. Will be fixed later.
787 mutex_lock(&ctx
->state_mutex
);
788 mask
= ctx
->ops
->mbox_stat_poll(ctx
, POLLIN
| POLLRDNORM
);
794 static const struct file_operations spufs_ibox_fops
= {
795 .open
= spufs_pipe_open
,
796 .read
= spufs_ibox_read
,
797 .poll
= spufs_ibox_poll
,
798 .fasync
= spufs_ibox_fasync
,
802 static ssize_t
spufs_ibox_stat_read(struct file
*file
, char __user
*buf
,
803 size_t len
, loff_t
*pos
)
805 struct spu_context
*ctx
= file
->private_data
;
812 ret
= spu_acquire(ctx
);
815 ibox_stat
= (ctx
->ops
->mbox_stat_read(ctx
) >> 16) & 0xff;
818 if (copy_to_user(buf
, &ibox_stat
, sizeof ibox_stat
))
824 static const struct file_operations spufs_ibox_stat_fops
= {
825 .open
= spufs_pipe_open
,
826 .read
= spufs_ibox_stat_read
,
830 /* low-level mailbox write */
831 size_t spu_wbox_write(struct spu_context
*ctx
, u32 data
)
833 return ctx
->ops
->wbox_write(ctx
, data
);
836 static int spufs_wbox_fasync(int fd
, struct file
*file
, int on
)
838 struct spu_context
*ctx
= file
->private_data
;
841 ret
= fasync_helper(fd
, file
, on
, &ctx
->wbox_fasync
);
846 /* interrupt-level wbox callback function. */
847 void spufs_wbox_callback(struct spu
*spu
)
849 struct spu_context
*ctx
= spu
->ctx
;
854 wake_up_all(&ctx
->wbox_wq
);
855 kill_fasync(&ctx
->wbox_fasync
, SIGIO
, POLLOUT
);
859 * Write as many bytes to the interrupt mailbox as possible, until
860 * one of the conditions becomes true:
862 * - the mailbox is full
863 * - end of the user provided buffer
864 * - end of the mapped area
866 * If the file is opened without O_NONBLOCK, we wait here until
867 * space is available, but return when we have been able to
870 static ssize_t
spufs_wbox_write(struct file
*file
, const char __user
*buf
,
871 size_t len
, loff_t
*pos
)
873 struct spu_context
*ctx
= file
->private_data
;
874 u32 wbox_data
, __user
*udata
;
880 udata
= (void __user
*)buf
;
881 if (!access_ok(VERIFY_READ
, buf
, len
))
884 if (__get_user(wbox_data
, udata
))
887 count
= spu_acquire(ctx
);
892 * make sure we can at least write one element, by waiting
893 * in case of !O_NONBLOCK
896 if (file
->f_flags
& O_NONBLOCK
) {
897 if (!spu_wbox_write(ctx
, wbox_data
)) {
902 count
= spufs_wait(ctx
->wbox_wq
, spu_wbox_write(ctx
, wbox_data
));
908 /* write as much as possible */
909 for (count
= 4, udata
++; (count
+ 4) <= len
; count
+= 4, udata
++) {
911 ret
= __get_user(wbox_data
, udata
);
915 ret
= spu_wbox_write(ctx
, wbox_data
);
926 static unsigned int spufs_wbox_poll(struct file
*file
, poll_table
*wait
)
928 struct spu_context
*ctx
= file
->private_data
;
931 poll_wait(file
, &ctx
->wbox_wq
, wait
);
934 * For now keep this uninterruptible and also ignore the rule
935 * that poll should not sleep. Will be fixed later.
937 mutex_lock(&ctx
->state_mutex
);
938 mask
= ctx
->ops
->mbox_stat_poll(ctx
, POLLOUT
| POLLWRNORM
);
944 static const struct file_operations spufs_wbox_fops
= {
945 .open
= spufs_pipe_open
,
946 .write
= spufs_wbox_write
,
947 .poll
= spufs_wbox_poll
,
948 .fasync
= spufs_wbox_fasync
,
952 static ssize_t
spufs_wbox_stat_read(struct file
*file
, char __user
*buf
,
953 size_t len
, loff_t
*pos
)
955 struct spu_context
*ctx
= file
->private_data
;
962 ret
= spu_acquire(ctx
);
965 wbox_stat
= (ctx
->ops
->mbox_stat_read(ctx
) >> 8) & 0xff;
968 if (copy_to_user(buf
, &wbox_stat
, sizeof wbox_stat
))
974 static const struct file_operations spufs_wbox_stat_fops
= {
975 .open
= spufs_pipe_open
,
976 .read
= spufs_wbox_stat_read
,
980 static int spufs_signal1_open(struct inode
*inode
, struct file
*file
)
982 struct spufs_inode_info
*i
= SPUFS_I(inode
);
983 struct spu_context
*ctx
= i
->i_ctx
;
985 mutex_lock(&ctx
->mapping_lock
);
986 file
->private_data
= ctx
;
988 ctx
->signal1
= inode
->i_mapping
;
989 mutex_unlock(&ctx
->mapping_lock
);
990 return nonseekable_open(inode
, file
);
994 spufs_signal1_release(struct inode
*inode
, struct file
*file
)
996 struct spufs_inode_info
*i
= SPUFS_I(inode
);
997 struct spu_context
*ctx
= i
->i_ctx
;
999 mutex_lock(&ctx
->mapping_lock
);
1000 if (!--i
->i_openers
)
1001 ctx
->signal1
= NULL
;
1002 mutex_unlock(&ctx
->mapping_lock
);
1006 static ssize_t
__spufs_signal1_read(struct spu_context
*ctx
, char __user
*buf
,
1007 size_t len
, loff_t
*pos
)
1015 if (ctx
->csa
.spu_chnlcnt_RW
[3]) {
1016 data
= ctx
->csa
.spu_chnldata_RW
[3];
1023 if (copy_to_user(buf
, &data
, 4))
1030 static ssize_t
spufs_signal1_read(struct file
*file
, char __user
*buf
,
1031 size_t len
, loff_t
*pos
)
1034 struct spu_context
*ctx
= file
->private_data
;
1036 ret
= spu_acquire_saved(ctx
);
1039 ret
= __spufs_signal1_read(ctx
, buf
, len
, pos
);
1040 spu_release_saved(ctx
);
1045 static ssize_t
spufs_signal1_write(struct file
*file
, const char __user
*buf
,
1046 size_t len
, loff_t
*pos
)
1048 struct spu_context
*ctx
;
1052 ctx
= file
->private_data
;
1057 if (copy_from_user(&data
, buf
, 4))
1060 ret
= spu_acquire(ctx
);
1063 ctx
->ops
->signal1_write(ctx
, data
);
1070 spufs_signal1_mmap_fault(struct vm_area_struct
*vma
, struct vm_fault
*vmf
)
1072 #if SPUFS_SIGNAL_MAP_SIZE == 0x1000
1073 return spufs_ps_fault(vma
, vmf
, 0x14000, SPUFS_SIGNAL_MAP_SIZE
);
1074 #elif SPUFS_SIGNAL_MAP_SIZE == 0x10000
1075 /* For 64k pages, both signal1 and signal2 can be used to mmap the whole
1076 * signal 1 and 2 area
1078 return spufs_ps_fault(vma
, vmf
, 0x10000, SPUFS_SIGNAL_MAP_SIZE
);
1080 #error unsupported page size
1084 static const struct vm_operations_struct spufs_signal1_mmap_vmops
= {
1085 .fault
= spufs_signal1_mmap_fault
,
1088 static int spufs_signal1_mmap(struct file
*file
, struct vm_area_struct
*vma
)
1090 if (!(vma
->vm_flags
& VM_SHARED
))
1093 vma
->vm_flags
|= VM_IO
| VM_PFNMAP
;
1094 vma
->vm_page_prot
= pgprot_noncached(vma
->vm_page_prot
);
1096 vma
->vm_ops
= &spufs_signal1_mmap_vmops
;
1100 static const struct file_operations spufs_signal1_fops
= {
1101 .open
= spufs_signal1_open
,
1102 .release
= spufs_signal1_release
,
1103 .read
= spufs_signal1_read
,
1104 .write
= spufs_signal1_write
,
1105 .mmap
= spufs_signal1_mmap
,
1106 .llseek
= no_llseek
,
1109 static const struct file_operations spufs_signal1_nosched_fops
= {
1110 .open
= spufs_signal1_open
,
1111 .release
= spufs_signal1_release
,
1112 .write
= spufs_signal1_write
,
1113 .mmap
= spufs_signal1_mmap
,
1114 .llseek
= no_llseek
,
1117 static int spufs_signal2_open(struct inode
*inode
, struct file
*file
)
1119 struct spufs_inode_info
*i
= SPUFS_I(inode
);
1120 struct spu_context
*ctx
= i
->i_ctx
;
1122 mutex_lock(&ctx
->mapping_lock
);
1123 file
->private_data
= ctx
;
1124 if (!i
->i_openers
++)
1125 ctx
->signal2
= inode
->i_mapping
;
1126 mutex_unlock(&ctx
->mapping_lock
);
1127 return nonseekable_open(inode
, file
);
1131 spufs_signal2_release(struct inode
*inode
, struct file
*file
)
1133 struct spufs_inode_info
*i
= SPUFS_I(inode
);
1134 struct spu_context
*ctx
= i
->i_ctx
;
1136 mutex_lock(&ctx
->mapping_lock
);
1137 if (!--i
->i_openers
)
1138 ctx
->signal2
= NULL
;
1139 mutex_unlock(&ctx
->mapping_lock
);
1143 static ssize_t
__spufs_signal2_read(struct spu_context
*ctx
, char __user
*buf
,
1144 size_t len
, loff_t
*pos
)
1152 if (ctx
->csa
.spu_chnlcnt_RW
[4]) {
1153 data
= ctx
->csa
.spu_chnldata_RW
[4];
1160 if (copy_to_user(buf
, &data
, 4))
1167 static ssize_t
spufs_signal2_read(struct file
*file
, char __user
*buf
,
1168 size_t len
, loff_t
*pos
)
1170 struct spu_context
*ctx
= file
->private_data
;
1173 ret
= spu_acquire_saved(ctx
);
1176 ret
= __spufs_signal2_read(ctx
, buf
, len
, pos
);
1177 spu_release_saved(ctx
);
1182 static ssize_t
spufs_signal2_write(struct file
*file
, const char __user
*buf
,
1183 size_t len
, loff_t
*pos
)
1185 struct spu_context
*ctx
;
1189 ctx
= file
->private_data
;
1194 if (copy_from_user(&data
, buf
, 4))
1197 ret
= spu_acquire(ctx
);
1200 ctx
->ops
->signal2_write(ctx
, data
);
1208 spufs_signal2_mmap_fault(struct vm_area_struct
*vma
, struct vm_fault
*vmf
)
1210 #if SPUFS_SIGNAL_MAP_SIZE == 0x1000
1211 return spufs_ps_fault(vma
, vmf
, 0x1c000, SPUFS_SIGNAL_MAP_SIZE
);
1212 #elif SPUFS_SIGNAL_MAP_SIZE == 0x10000
1213 /* For 64k pages, both signal1 and signal2 can be used to mmap the whole
1214 * signal 1 and 2 area
1216 return spufs_ps_fault(vma
, vmf
, 0x10000, SPUFS_SIGNAL_MAP_SIZE
);
1218 #error unsupported page size
1222 static const struct vm_operations_struct spufs_signal2_mmap_vmops
= {
1223 .fault
= spufs_signal2_mmap_fault
,
1226 static int spufs_signal2_mmap(struct file
*file
, struct vm_area_struct
*vma
)
1228 if (!(vma
->vm_flags
& VM_SHARED
))
1231 vma
->vm_flags
|= VM_IO
| VM_PFNMAP
;
1232 vma
->vm_page_prot
= pgprot_noncached(vma
->vm_page_prot
);
1234 vma
->vm_ops
= &spufs_signal2_mmap_vmops
;
1237 #else /* SPUFS_MMAP_4K */
1238 #define spufs_signal2_mmap NULL
1239 #endif /* !SPUFS_MMAP_4K */
1241 static const struct file_operations spufs_signal2_fops
= {
1242 .open
= spufs_signal2_open
,
1243 .release
= spufs_signal2_release
,
1244 .read
= spufs_signal2_read
,
1245 .write
= spufs_signal2_write
,
1246 .mmap
= spufs_signal2_mmap
,
1247 .llseek
= no_llseek
,
1250 static const struct file_operations spufs_signal2_nosched_fops
= {
1251 .open
= spufs_signal2_open
,
1252 .release
= spufs_signal2_release
,
1253 .write
= spufs_signal2_write
,
1254 .mmap
= spufs_signal2_mmap
,
1255 .llseek
= no_llseek
,
1259 * This is a wrapper around DEFINE_SIMPLE_ATTRIBUTE which does the
1260 * work of acquiring (or not) the SPU context before calling through
1261 * to the actual get routine. The set routine is called directly.
1263 #define SPU_ATTR_NOACQUIRE 0
1264 #define SPU_ATTR_ACQUIRE 1
1265 #define SPU_ATTR_ACQUIRE_SAVED 2
1267 #define DEFINE_SPUFS_ATTRIBUTE(__name, __get, __set, __fmt, __acquire) \
1268 static int __##__get(void *data, u64 *val) \
1270 struct spu_context *ctx = data; \
1273 if (__acquire == SPU_ATTR_ACQUIRE) { \
1274 ret = spu_acquire(ctx); \
1277 *val = __get(ctx); \
1279 } else if (__acquire == SPU_ATTR_ACQUIRE_SAVED) { \
1280 ret = spu_acquire_saved(ctx); \
1283 *val = __get(ctx); \
1284 spu_release_saved(ctx); \
1286 *val = __get(ctx); \
1290 DEFINE_SPUFS_SIMPLE_ATTRIBUTE(__name, __##__get, __set, __fmt);
1292 static int spufs_signal1_type_set(void *data
, u64 val
)
1294 struct spu_context
*ctx
= data
;
1297 ret
= spu_acquire(ctx
);
1300 ctx
->ops
->signal1_type_set(ctx
, val
);
1306 static u64
spufs_signal1_type_get(struct spu_context
*ctx
)
1308 return ctx
->ops
->signal1_type_get(ctx
);
1310 DEFINE_SPUFS_ATTRIBUTE(spufs_signal1_type
, spufs_signal1_type_get
,
1311 spufs_signal1_type_set
, "%llu\n", SPU_ATTR_ACQUIRE
);
1314 static int spufs_signal2_type_set(void *data
, u64 val
)
1316 struct spu_context
*ctx
= data
;
1319 ret
= spu_acquire(ctx
);
1322 ctx
->ops
->signal2_type_set(ctx
, val
);
1328 static u64
spufs_signal2_type_get(struct spu_context
*ctx
)
1330 return ctx
->ops
->signal2_type_get(ctx
);
1332 DEFINE_SPUFS_ATTRIBUTE(spufs_signal2_type
, spufs_signal2_type_get
,
1333 spufs_signal2_type_set
, "%llu\n", SPU_ATTR_ACQUIRE
);
1337 spufs_mss_mmap_fault(struct vm_area_struct
*vma
, struct vm_fault
*vmf
)
1339 return spufs_ps_fault(vma
, vmf
, 0x0000, SPUFS_MSS_MAP_SIZE
);
1342 static const struct vm_operations_struct spufs_mss_mmap_vmops
= {
1343 .fault
= spufs_mss_mmap_fault
,
1347 * mmap support for problem state MFC DMA area [0x0000 - 0x0fff].
1349 static int spufs_mss_mmap(struct file
*file
, struct vm_area_struct
*vma
)
1351 if (!(vma
->vm_flags
& VM_SHARED
))
1354 vma
->vm_flags
|= VM_IO
| VM_PFNMAP
;
1355 vma
->vm_page_prot
= pgprot_noncached(vma
->vm_page_prot
);
1357 vma
->vm_ops
= &spufs_mss_mmap_vmops
;
1360 #else /* SPUFS_MMAP_4K */
1361 #define spufs_mss_mmap NULL
1362 #endif /* !SPUFS_MMAP_4K */
1364 static int spufs_mss_open(struct inode
*inode
, struct file
*file
)
1366 struct spufs_inode_info
*i
= SPUFS_I(inode
);
1367 struct spu_context
*ctx
= i
->i_ctx
;
1369 file
->private_data
= i
->i_ctx
;
1371 mutex_lock(&ctx
->mapping_lock
);
1372 if (!i
->i_openers
++)
1373 ctx
->mss
= inode
->i_mapping
;
1374 mutex_unlock(&ctx
->mapping_lock
);
1375 return nonseekable_open(inode
, file
);
1379 spufs_mss_release(struct inode
*inode
, struct file
*file
)
1381 struct spufs_inode_info
*i
= SPUFS_I(inode
);
1382 struct spu_context
*ctx
= i
->i_ctx
;
1384 mutex_lock(&ctx
->mapping_lock
);
1385 if (!--i
->i_openers
)
1387 mutex_unlock(&ctx
->mapping_lock
);
1391 static const struct file_operations spufs_mss_fops
= {
1392 .open
= spufs_mss_open
,
1393 .release
= spufs_mss_release
,
1394 .mmap
= spufs_mss_mmap
,
1395 .llseek
= no_llseek
,
1399 spufs_psmap_mmap_fault(struct vm_area_struct
*vma
, struct vm_fault
*vmf
)
1401 return spufs_ps_fault(vma
, vmf
, 0x0000, SPUFS_PS_MAP_SIZE
);
1404 static const struct vm_operations_struct spufs_psmap_mmap_vmops
= {
1405 .fault
= spufs_psmap_mmap_fault
,
1409 * mmap support for full problem state area [0x00000 - 0x1ffff].
1411 static int spufs_psmap_mmap(struct file
*file
, struct vm_area_struct
*vma
)
1413 if (!(vma
->vm_flags
& VM_SHARED
))
1416 vma
->vm_flags
|= VM_IO
| VM_PFNMAP
;
1417 vma
->vm_page_prot
= pgprot_noncached(vma
->vm_page_prot
);
1419 vma
->vm_ops
= &spufs_psmap_mmap_vmops
;
1423 static int spufs_psmap_open(struct inode
*inode
, struct file
*file
)
1425 struct spufs_inode_info
*i
= SPUFS_I(inode
);
1426 struct spu_context
*ctx
= i
->i_ctx
;
1428 mutex_lock(&ctx
->mapping_lock
);
1429 file
->private_data
= i
->i_ctx
;
1430 if (!i
->i_openers
++)
1431 ctx
->psmap
= inode
->i_mapping
;
1432 mutex_unlock(&ctx
->mapping_lock
);
1433 return nonseekable_open(inode
, file
);
1437 spufs_psmap_release(struct inode
*inode
, struct file
*file
)
1439 struct spufs_inode_info
*i
= SPUFS_I(inode
);
1440 struct spu_context
*ctx
= i
->i_ctx
;
1442 mutex_lock(&ctx
->mapping_lock
);
1443 if (!--i
->i_openers
)
1445 mutex_unlock(&ctx
->mapping_lock
);
1449 static const struct file_operations spufs_psmap_fops
= {
1450 .open
= spufs_psmap_open
,
1451 .release
= spufs_psmap_release
,
1452 .mmap
= spufs_psmap_mmap
,
1453 .llseek
= no_llseek
,
1459 spufs_mfc_mmap_fault(struct vm_area_struct
*vma
, struct vm_fault
*vmf
)
1461 return spufs_ps_fault(vma
, vmf
, 0x3000, SPUFS_MFC_MAP_SIZE
);
1464 static const struct vm_operations_struct spufs_mfc_mmap_vmops
= {
1465 .fault
= spufs_mfc_mmap_fault
,
1469 * mmap support for problem state MFC DMA area [0x0000 - 0x0fff].
1471 static int spufs_mfc_mmap(struct file
*file
, struct vm_area_struct
*vma
)
1473 if (!(vma
->vm_flags
& VM_SHARED
))
1476 vma
->vm_flags
|= VM_IO
| VM_PFNMAP
;
1477 vma
->vm_page_prot
= pgprot_noncached(vma
->vm_page_prot
);
1479 vma
->vm_ops
= &spufs_mfc_mmap_vmops
;
1482 #else /* SPUFS_MMAP_4K */
1483 #define spufs_mfc_mmap NULL
1484 #endif /* !SPUFS_MMAP_4K */
1486 static int spufs_mfc_open(struct inode
*inode
, struct file
*file
)
1488 struct spufs_inode_info
*i
= SPUFS_I(inode
);
1489 struct spu_context
*ctx
= i
->i_ctx
;
1491 /* we don't want to deal with DMA into other processes */
1492 if (ctx
->owner
!= current
->mm
)
1495 if (atomic_read(&inode
->i_count
) != 1)
1498 mutex_lock(&ctx
->mapping_lock
);
1499 file
->private_data
= ctx
;
1500 if (!i
->i_openers
++)
1501 ctx
->mfc
= inode
->i_mapping
;
1502 mutex_unlock(&ctx
->mapping_lock
);
1503 return nonseekable_open(inode
, file
);
1507 spufs_mfc_release(struct inode
*inode
, struct file
*file
)
1509 struct spufs_inode_info
*i
= SPUFS_I(inode
);
1510 struct spu_context
*ctx
= i
->i_ctx
;
1512 mutex_lock(&ctx
->mapping_lock
);
1513 if (!--i
->i_openers
)
1515 mutex_unlock(&ctx
->mapping_lock
);
1519 /* interrupt-level mfc callback function. */
1520 void spufs_mfc_callback(struct spu
*spu
)
1522 struct spu_context
*ctx
= spu
->ctx
;
1527 wake_up_all(&ctx
->mfc_wq
);
1529 pr_debug("%s %s\n", __func__
, spu
->name
);
1530 if (ctx
->mfc_fasync
) {
1531 u32 free_elements
, tagstatus
;
1534 /* no need for spu_acquire in interrupt context */
1535 free_elements
= ctx
->ops
->get_mfc_free_elements(ctx
);
1536 tagstatus
= ctx
->ops
->read_mfc_tagstatus(ctx
);
1539 if (free_elements
& 0xffff)
1541 if (tagstatus
& ctx
->tagwait
)
1544 kill_fasync(&ctx
->mfc_fasync
, SIGIO
, mask
);
1548 static int spufs_read_mfc_tagstatus(struct spu_context
*ctx
, u32
*status
)
1550 /* See if there is one tag group is complete */
1551 /* FIXME we need locking around tagwait */
1552 *status
= ctx
->ops
->read_mfc_tagstatus(ctx
) & ctx
->tagwait
;
1553 ctx
->tagwait
&= ~*status
;
1557 /* enable interrupt waiting for any tag group,
1558 may silently fail if interrupts are already enabled */
1559 ctx
->ops
->set_mfc_query(ctx
, ctx
->tagwait
, 1);
1563 static ssize_t
spufs_mfc_read(struct file
*file
, char __user
*buffer
,
1564 size_t size
, loff_t
*pos
)
1566 struct spu_context
*ctx
= file
->private_data
;
1573 ret
= spu_acquire(ctx
);
1578 if (file
->f_flags
& O_NONBLOCK
) {
1579 status
= ctx
->ops
->read_mfc_tagstatus(ctx
);
1580 if (!(status
& ctx
->tagwait
))
1583 /* XXX(hch): shouldn't we clear ret here? */
1584 ctx
->tagwait
&= ~status
;
1586 ret
= spufs_wait(ctx
->mfc_wq
,
1587 spufs_read_mfc_tagstatus(ctx
, &status
));
1594 if (copy_to_user(buffer
, &status
, 4))
1601 static int spufs_check_valid_dma(struct mfc_dma_command
*cmd
)
1603 pr_debug("queueing DMA %x %llx %x %x %x\n", cmd
->lsa
,
1604 cmd
->ea
, cmd
->size
, cmd
->tag
, cmd
->cmd
);
1615 pr_debug("invalid DMA opcode %x\n", cmd
->cmd
);
1619 if ((cmd
->lsa
& 0xf) != (cmd
->ea
&0xf)) {
1620 pr_debug("invalid DMA alignment, ea %llx lsa %x\n",
1625 switch (cmd
->size
& 0xf) {
1646 pr_debug("invalid DMA alignment %x for size %x\n",
1647 cmd
->lsa
& 0xf, cmd
->size
);
1651 if (cmd
->size
> 16 * 1024) {
1652 pr_debug("invalid DMA size %x\n", cmd
->size
);
1656 if (cmd
->tag
& 0xfff0) {
1657 /* we reserve the higher tag numbers for kernel use */
1658 pr_debug("invalid DMA tag\n");
1663 /* not supported in this version */
1664 pr_debug("invalid DMA class\n");
1671 static int spu_send_mfc_command(struct spu_context
*ctx
,
1672 struct mfc_dma_command cmd
,
1675 *error
= ctx
->ops
->send_mfc_command(ctx
, &cmd
);
1676 if (*error
== -EAGAIN
) {
1677 /* wait for any tag group to complete
1678 so we have space for the new command */
1679 ctx
->ops
->set_mfc_query(ctx
, ctx
->tagwait
, 1);
1680 /* try again, because the queue might be
1682 *error
= ctx
->ops
->send_mfc_command(ctx
, &cmd
);
1683 if (*error
== -EAGAIN
)
1689 static ssize_t
spufs_mfc_write(struct file
*file
, const char __user
*buffer
,
1690 size_t size
, loff_t
*pos
)
1692 struct spu_context
*ctx
= file
->private_data
;
1693 struct mfc_dma_command cmd
;
1696 if (size
!= sizeof cmd
)
1700 if (copy_from_user(&cmd
, buffer
, sizeof cmd
))
1703 ret
= spufs_check_valid_dma(&cmd
);
1707 ret
= spu_acquire(ctx
);
1711 ret
= spufs_wait(ctx
->run_wq
, ctx
->state
== SPU_STATE_RUNNABLE
);
1715 if (file
->f_flags
& O_NONBLOCK
) {
1716 ret
= ctx
->ops
->send_mfc_command(ctx
, &cmd
);
1719 ret
= spufs_wait(ctx
->mfc_wq
,
1720 spu_send_mfc_command(ctx
, cmd
, &status
));
1730 ctx
->tagwait
|= 1 << cmd
.tag
;
1739 static unsigned int spufs_mfc_poll(struct file
*file
,poll_table
*wait
)
1741 struct spu_context
*ctx
= file
->private_data
;
1742 u32 free_elements
, tagstatus
;
1745 poll_wait(file
, &ctx
->mfc_wq
, wait
);
1748 * For now keep this uninterruptible and also ignore the rule
1749 * that poll should not sleep. Will be fixed later.
1751 mutex_lock(&ctx
->state_mutex
);
1752 ctx
->ops
->set_mfc_query(ctx
, ctx
->tagwait
, 2);
1753 free_elements
= ctx
->ops
->get_mfc_free_elements(ctx
);
1754 tagstatus
= ctx
->ops
->read_mfc_tagstatus(ctx
);
1758 if (free_elements
& 0xffff)
1759 mask
|= POLLOUT
| POLLWRNORM
;
1760 if (tagstatus
& ctx
->tagwait
)
1761 mask
|= POLLIN
| POLLRDNORM
;
1763 pr_debug("%s: free %d tagstatus %d tagwait %d\n", __func__
,
1764 free_elements
, tagstatus
, ctx
->tagwait
);
1769 static int spufs_mfc_flush(struct file
*file
, fl_owner_t id
)
1771 struct spu_context
*ctx
= file
->private_data
;
1774 ret
= spu_acquire(ctx
);
1778 /* this currently hangs */
1779 ret
= spufs_wait(ctx
->mfc_wq
,
1780 ctx
->ops
->set_mfc_query(ctx
, ctx
->tagwait
, 2));
1783 ret
= spufs_wait(ctx
->mfc_wq
,
1784 ctx
->ops
->read_mfc_tagstatus(ctx
) == ctx
->tagwait
);
1795 static int spufs_mfc_fsync(struct file
*file
, loff_t start
, loff_t end
, int datasync
)
1797 struct inode
*inode
= file_inode(file
);
1798 int err
= filemap_write_and_wait_range(inode
->i_mapping
, start
, end
);
1801 err
= spufs_mfc_flush(file
, NULL
);
1802 inode_unlock(inode
);
1807 static int spufs_mfc_fasync(int fd
, struct file
*file
, int on
)
1809 struct spu_context
*ctx
= file
->private_data
;
1811 return fasync_helper(fd
, file
, on
, &ctx
->mfc_fasync
);
1814 static const struct file_operations spufs_mfc_fops
= {
1815 .open
= spufs_mfc_open
,
1816 .release
= spufs_mfc_release
,
1817 .read
= spufs_mfc_read
,
1818 .write
= spufs_mfc_write
,
1819 .poll
= spufs_mfc_poll
,
1820 .flush
= spufs_mfc_flush
,
1821 .fsync
= spufs_mfc_fsync
,
1822 .fasync
= spufs_mfc_fasync
,
1823 .mmap
= spufs_mfc_mmap
,
1824 .llseek
= no_llseek
,
1827 static int spufs_npc_set(void *data
, u64 val
)
1829 struct spu_context
*ctx
= data
;
1832 ret
= spu_acquire(ctx
);
1835 ctx
->ops
->npc_write(ctx
, val
);
1841 static u64
spufs_npc_get(struct spu_context
*ctx
)
1843 return ctx
->ops
->npc_read(ctx
);
1845 DEFINE_SPUFS_ATTRIBUTE(spufs_npc_ops
, spufs_npc_get
, spufs_npc_set
,
1846 "0x%llx\n", SPU_ATTR_ACQUIRE
);
1848 static int spufs_decr_set(void *data
, u64 val
)
1850 struct spu_context
*ctx
= data
;
1851 struct spu_lscsa
*lscsa
= ctx
->csa
.lscsa
;
1854 ret
= spu_acquire_saved(ctx
);
1857 lscsa
->decr
.slot
[0] = (u32
) val
;
1858 spu_release_saved(ctx
);
1863 static u64
spufs_decr_get(struct spu_context
*ctx
)
1865 struct spu_lscsa
*lscsa
= ctx
->csa
.lscsa
;
1866 return lscsa
->decr
.slot
[0];
1868 DEFINE_SPUFS_ATTRIBUTE(spufs_decr_ops
, spufs_decr_get
, spufs_decr_set
,
1869 "0x%llx\n", SPU_ATTR_ACQUIRE_SAVED
);
1871 static int spufs_decr_status_set(void *data
, u64 val
)
1873 struct spu_context
*ctx
= data
;
1876 ret
= spu_acquire_saved(ctx
);
1880 ctx
->csa
.priv2
.mfc_control_RW
|= MFC_CNTL_DECREMENTER_RUNNING
;
1882 ctx
->csa
.priv2
.mfc_control_RW
&= ~MFC_CNTL_DECREMENTER_RUNNING
;
1883 spu_release_saved(ctx
);
1888 static u64
spufs_decr_status_get(struct spu_context
*ctx
)
1890 if (ctx
->csa
.priv2
.mfc_control_RW
& MFC_CNTL_DECREMENTER_RUNNING
)
1891 return SPU_DECR_STATUS_RUNNING
;
1895 DEFINE_SPUFS_ATTRIBUTE(spufs_decr_status_ops
, spufs_decr_status_get
,
1896 spufs_decr_status_set
, "0x%llx\n",
1897 SPU_ATTR_ACQUIRE_SAVED
);
1899 static int spufs_event_mask_set(void *data
, u64 val
)
1901 struct spu_context
*ctx
= data
;
1902 struct spu_lscsa
*lscsa
= ctx
->csa
.lscsa
;
1905 ret
= spu_acquire_saved(ctx
);
1908 lscsa
->event_mask
.slot
[0] = (u32
) val
;
1909 spu_release_saved(ctx
);
1914 static u64
spufs_event_mask_get(struct spu_context
*ctx
)
1916 struct spu_lscsa
*lscsa
= ctx
->csa
.lscsa
;
1917 return lscsa
->event_mask
.slot
[0];
1920 DEFINE_SPUFS_ATTRIBUTE(spufs_event_mask_ops
, spufs_event_mask_get
,
1921 spufs_event_mask_set
, "0x%llx\n",
1922 SPU_ATTR_ACQUIRE_SAVED
);
1924 static u64
spufs_event_status_get(struct spu_context
*ctx
)
1926 struct spu_state
*state
= &ctx
->csa
;
1928 stat
= state
->spu_chnlcnt_RW
[0];
1930 return state
->spu_chnldata_RW
[0];
1933 DEFINE_SPUFS_ATTRIBUTE(spufs_event_status_ops
, spufs_event_status_get
,
1934 NULL
, "0x%llx\n", SPU_ATTR_ACQUIRE_SAVED
)
1936 static int spufs_srr0_set(void *data
, u64 val
)
1938 struct spu_context
*ctx
= data
;
1939 struct spu_lscsa
*lscsa
= ctx
->csa
.lscsa
;
1942 ret
= spu_acquire_saved(ctx
);
1945 lscsa
->srr0
.slot
[0] = (u32
) val
;
1946 spu_release_saved(ctx
);
1951 static u64
spufs_srr0_get(struct spu_context
*ctx
)
1953 struct spu_lscsa
*lscsa
= ctx
->csa
.lscsa
;
1954 return lscsa
->srr0
.slot
[0];
1956 DEFINE_SPUFS_ATTRIBUTE(spufs_srr0_ops
, spufs_srr0_get
, spufs_srr0_set
,
1957 "0x%llx\n", SPU_ATTR_ACQUIRE_SAVED
)
1959 static u64
spufs_id_get(struct spu_context
*ctx
)
1963 if (ctx
->state
== SPU_STATE_RUNNABLE
)
1964 num
= ctx
->spu
->number
;
1966 num
= (unsigned int)-1;
1970 DEFINE_SPUFS_ATTRIBUTE(spufs_id_ops
, spufs_id_get
, NULL
, "0x%llx\n",
1973 static u64
spufs_object_id_get(struct spu_context
*ctx
)
1975 /* FIXME: Should there really be no locking here? */
1976 return ctx
->object_id
;
1979 static int spufs_object_id_set(void *data
, u64 id
)
1981 struct spu_context
*ctx
= data
;
1982 ctx
->object_id
= id
;
1987 DEFINE_SPUFS_ATTRIBUTE(spufs_object_id_ops
, spufs_object_id_get
,
1988 spufs_object_id_set
, "0x%llx\n", SPU_ATTR_NOACQUIRE
);
1990 static u64
spufs_lslr_get(struct spu_context
*ctx
)
1992 return ctx
->csa
.priv2
.spu_lslr_RW
;
1994 DEFINE_SPUFS_ATTRIBUTE(spufs_lslr_ops
, spufs_lslr_get
, NULL
, "0x%llx\n",
1995 SPU_ATTR_ACQUIRE_SAVED
);
1997 static int spufs_info_open(struct inode
*inode
, struct file
*file
)
1999 struct spufs_inode_info
*i
= SPUFS_I(inode
);
2000 struct spu_context
*ctx
= i
->i_ctx
;
2001 file
->private_data
= ctx
;
2005 static int spufs_caps_show(struct seq_file
*s
, void *private)
2007 struct spu_context
*ctx
= s
->private;
2009 if (!(ctx
->flags
& SPU_CREATE_NOSCHED
))
2010 seq_puts(s
, "sched\n");
2011 if (!(ctx
->flags
& SPU_CREATE_ISOLATE
))
2012 seq_puts(s
, "step\n");
2016 static int spufs_caps_open(struct inode
*inode
, struct file
*file
)
2018 return single_open(file
, spufs_caps_show
, SPUFS_I(inode
)->i_ctx
);
2021 static const struct file_operations spufs_caps_fops
= {
2022 .open
= spufs_caps_open
,
2024 .llseek
= seq_lseek
,
2025 .release
= single_release
,
2028 static ssize_t
__spufs_mbox_info_read(struct spu_context
*ctx
,
2029 char __user
*buf
, size_t len
, loff_t
*pos
)
2033 /* EOF if there's no entry in the mbox */
2034 if (!(ctx
->csa
.prob
.mb_stat_R
& 0x0000ff))
2037 data
= ctx
->csa
.prob
.pu_mb_R
;
2039 return simple_read_from_buffer(buf
, len
, pos
, &data
, sizeof data
);
2042 static ssize_t
spufs_mbox_info_read(struct file
*file
, char __user
*buf
,
2043 size_t len
, loff_t
*pos
)
2046 struct spu_context
*ctx
= file
->private_data
;
2048 if (!access_ok(VERIFY_WRITE
, buf
, len
))
2051 ret
= spu_acquire_saved(ctx
);
2054 spin_lock(&ctx
->csa
.register_lock
);
2055 ret
= __spufs_mbox_info_read(ctx
, buf
, len
, pos
);
2056 spin_unlock(&ctx
->csa
.register_lock
);
2057 spu_release_saved(ctx
);
2062 static const struct file_operations spufs_mbox_info_fops
= {
2063 .open
= spufs_info_open
,
2064 .read
= spufs_mbox_info_read
,
2065 .llseek
= generic_file_llseek
,
2068 static ssize_t
__spufs_ibox_info_read(struct spu_context
*ctx
,
2069 char __user
*buf
, size_t len
, loff_t
*pos
)
2073 /* EOF if there's no entry in the ibox */
2074 if (!(ctx
->csa
.prob
.mb_stat_R
& 0xff0000))
2077 data
= ctx
->csa
.priv2
.puint_mb_R
;
2079 return simple_read_from_buffer(buf
, len
, pos
, &data
, sizeof data
);
2082 static ssize_t
spufs_ibox_info_read(struct file
*file
, char __user
*buf
,
2083 size_t len
, loff_t
*pos
)
2085 struct spu_context
*ctx
= file
->private_data
;
2088 if (!access_ok(VERIFY_WRITE
, buf
, len
))
2091 ret
= spu_acquire_saved(ctx
);
2094 spin_lock(&ctx
->csa
.register_lock
);
2095 ret
= __spufs_ibox_info_read(ctx
, buf
, len
, pos
);
2096 spin_unlock(&ctx
->csa
.register_lock
);
2097 spu_release_saved(ctx
);
2102 static const struct file_operations spufs_ibox_info_fops
= {
2103 .open
= spufs_info_open
,
2104 .read
= spufs_ibox_info_read
,
2105 .llseek
= generic_file_llseek
,
2108 static ssize_t
__spufs_wbox_info_read(struct spu_context
*ctx
,
2109 char __user
*buf
, size_t len
, loff_t
*pos
)
2115 wbox_stat
= ctx
->csa
.prob
.mb_stat_R
;
2116 cnt
= 4 - ((wbox_stat
& 0x00ff00) >> 8);
2117 for (i
= 0; i
< cnt
; i
++) {
2118 data
[i
] = ctx
->csa
.spu_mailbox_data
[i
];
2121 return simple_read_from_buffer(buf
, len
, pos
, &data
,
2125 static ssize_t
spufs_wbox_info_read(struct file
*file
, char __user
*buf
,
2126 size_t len
, loff_t
*pos
)
2128 struct spu_context
*ctx
= file
->private_data
;
2131 if (!access_ok(VERIFY_WRITE
, buf
, len
))
2134 ret
= spu_acquire_saved(ctx
);
2137 spin_lock(&ctx
->csa
.register_lock
);
2138 ret
= __spufs_wbox_info_read(ctx
, buf
, len
, pos
);
2139 spin_unlock(&ctx
->csa
.register_lock
);
2140 spu_release_saved(ctx
);
2145 static const struct file_operations spufs_wbox_info_fops
= {
2146 .open
= spufs_info_open
,
2147 .read
= spufs_wbox_info_read
,
2148 .llseek
= generic_file_llseek
,
2151 static ssize_t
__spufs_dma_info_read(struct spu_context
*ctx
,
2152 char __user
*buf
, size_t len
, loff_t
*pos
)
2154 struct spu_dma_info info
;
2155 struct mfc_cq_sr
*qp
, *spuqp
;
2158 info
.dma_info_type
= ctx
->csa
.priv2
.spu_tag_status_query_RW
;
2159 info
.dma_info_mask
= ctx
->csa
.lscsa
->tag_mask
.slot
[0];
2160 info
.dma_info_status
= ctx
->csa
.spu_chnldata_RW
[24];
2161 info
.dma_info_stall_and_notify
= ctx
->csa
.spu_chnldata_RW
[25];
2162 info
.dma_info_atomic_command_status
= ctx
->csa
.spu_chnldata_RW
[27];
2163 for (i
= 0; i
< 16; i
++) {
2164 qp
= &info
.dma_info_command_data
[i
];
2165 spuqp
= &ctx
->csa
.priv2
.spuq
[i
];
2167 qp
->mfc_cq_data0_RW
= spuqp
->mfc_cq_data0_RW
;
2168 qp
->mfc_cq_data1_RW
= spuqp
->mfc_cq_data1_RW
;
2169 qp
->mfc_cq_data2_RW
= spuqp
->mfc_cq_data2_RW
;
2170 qp
->mfc_cq_data3_RW
= spuqp
->mfc_cq_data3_RW
;
2173 return simple_read_from_buffer(buf
, len
, pos
, &info
,
2177 static ssize_t
spufs_dma_info_read(struct file
*file
, char __user
*buf
,
2178 size_t len
, loff_t
*pos
)
2180 struct spu_context
*ctx
= file
->private_data
;
2183 if (!access_ok(VERIFY_WRITE
, buf
, len
))
2186 ret
= spu_acquire_saved(ctx
);
2189 spin_lock(&ctx
->csa
.register_lock
);
2190 ret
= __spufs_dma_info_read(ctx
, buf
, len
, pos
);
2191 spin_unlock(&ctx
->csa
.register_lock
);
2192 spu_release_saved(ctx
);
2197 static const struct file_operations spufs_dma_info_fops
= {
2198 .open
= spufs_info_open
,
2199 .read
= spufs_dma_info_read
,
2200 .llseek
= no_llseek
,
2203 static ssize_t
__spufs_proxydma_info_read(struct spu_context
*ctx
,
2204 char __user
*buf
, size_t len
, loff_t
*pos
)
2206 struct spu_proxydma_info info
;
2207 struct mfc_cq_sr
*qp
, *puqp
;
2208 int ret
= sizeof info
;
2214 if (!access_ok(VERIFY_WRITE
, buf
, len
))
2217 info
.proxydma_info_type
= ctx
->csa
.prob
.dma_querytype_RW
;
2218 info
.proxydma_info_mask
= ctx
->csa
.prob
.dma_querymask_RW
;
2219 info
.proxydma_info_status
= ctx
->csa
.prob
.dma_tagstatus_R
;
2220 for (i
= 0; i
< 8; i
++) {
2221 qp
= &info
.proxydma_info_command_data
[i
];
2222 puqp
= &ctx
->csa
.priv2
.puq
[i
];
2224 qp
->mfc_cq_data0_RW
= puqp
->mfc_cq_data0_RW
;
2225 qp
->mfc_cq_data1_RW
= puqp
->mfc_cq_data1_RW
;
2226 qp
->mfc_cq_data2_RW
= puqp
->mfc_cq_data2_RW
;
2227 qp
->mfc_cq_data3_RW
= puqp
->mfc_cq_data3_RW
;
2230 return simple_read_from_buffer(buf
, len
, pos
, &info
,
2234 static ssize_t
spufs_proxydma_info_read(struct file
*file
, char __user
*buf
,
2235 size_t len
, loff_t
*pos
)
2237 struct spu_context
*ctx
= file
->private_data
;
2240 ret
= spu_acquire_saved(ctx
);
2243 spin_lock(&ctx
->csa
.register_lock
);
2244 ret
= __spufs_proxydma_info_read(ctx
, buf
, len
, pos
);
2245 spin_unlock(&ctx
->csa
.register_lock
);
2246 spu_release_saved(ctx
);
2251 static const struct file_operations spufs_proxydma_info_fops
= {
2252 .open
= spufs_info_open
,
2253 .read
= spufs_proxydma_info_read
,
2254 .llseek
= no_llseek
,
2257 static int spufs_show_tid(struct seq_file
*s
, void *private)
2259 struct spu_context
*ctx
= s
->private;
2261 seq_printf(s
, "%d\n", ctx
->tid
);
2265 static int spufs_tid_open(struct inode
*inode
, struct file
*file
)
2267 return single_open(file
, spufs_show_tid
, SPUFS_I(inode
)->i_ctx
);
2270 static const struct file_operations spufs_tid_fops
= {
2271 .open
= spufs_tid_open
,
2273 .llseek
= seq_lseek
,
2274 .release
= single_release
,
2277 static const char *ctx_state_names
[] = {
2278 "user", "system", "iowait", "loaded"
2281 static unsigned long long spufs_acct_time(struct spu_context
*ctx
,
2282 enum spu_utilization_state state
)
2284 unsigned long long time
= ctx
->stats
.times
[state
];
2287 * In general, utilization statistics are updated by the controlling
2288 * thread as the spu context moves through various well defined
2289 * state transitions, but if the context is lazily loaded its
2290 * utilization statistics are not updated as the controlling thread
2291 * is not tightly coupled with the execution of the spu context. We
2292 * calculate and apply the time delta from the last recorded state
2293 * of the spu context.
2295 if (ctx
->spu
&& ctx
->stats
.util_state
== state
) {
2296 time
+= ktime_get_ns() - ctx
->stats
.tstamp
;
2299 return time
/ NSEC_PER_MSEC
;
2302 static unsigned long long spufs_slb_flts(struct spu_context
*ctx
)
2304 unsigned long long slb_flts
= ctx
->stats
.slb_flt
;
2306 if (ctx
->state
== SPU_STATE_RUNNABLE
) {
2307 slb_flts
+= (ctx
->spu
->stats
.slb_flt
-
2308 ctx
->stats
.slb_flt_base
);
2314 static unsigned long long spufs_class2_intrs(struct spu_context
*ctx
)
2316 unsigned long long class2_intrs
= ctx
->stats
.class2_intr
;
2318 if (ctx
->state
== SPU_STATE_RUNNABLE
) {
2319 class2_intrs
+= (ctx
->spu
->stats
.class2_intr
-
2320 ctx
->stats
.class2_intr_base
);
2323 return class2_intrs
;
2327 static int spufs_show_stat(struct seq_file
*s
, void *private)
2329 struct spu_context
*ctx
= s
->private;
2332 ret
= spu_acquire(ctx
);
2336 seq_printf(s
, "%s %llu %llu %llu %llu "
2337 "%llu %llu %llu %llu %llu %llu %llu %llu\n",
2338 ctx_state_names
[ctx
->stats
.util_state
],
2339 spufs_acct_time(ctx
, SPU_UTIL_USER
),
2340 spufs_acct_time(ctx
, SPU_UTIL_SYSTEM
),
2341 spufs_acct_time(ctx
, SPU_UTIL_IOWAIT
),
2342 spufs_acct_time(ctx
, SPU_UTIL_IDLE_LOADED
),
2343 ctx
->stats
.vol_ctx_switch
,
2344 ctx
->stats
.invol_ctx_switch
,
2345 spufs_slb_flts(ctx
),
2346 ctx
->stats
.hash_flt
,
2349 spufs_class2_intrs(ctx
),
2350 ctx
->stats
.libassist
);
2355 static int spufs_stat_open(struct inode
*inode
, struct file
*file
)
2357 return single_open(file
, spufs_show_stat
, SPUFS_I(inode
)->i_ctx
);
2360 static const struct file_operations spufs_stat_fops
= {
2361 .open
= spufs_stat_open
,
2363 .llseek
= seq_lseek
,
2364 .release
= single_release
,
2367 static inline int spufs_switch_log_used(struct spu_context
*ctx
)
2369 return (ctx
->switch_log
->head
- ctx
->switch_log
->tail
) %
2373 static inline int spufs_switch_log_avail(struct spu_context
*ctx
)
2375 return SWITCH_LOG_BUFSIZE
- spufs_switch_log_used(ctx
);
2378 static int spufs_switch_log_open(struct inode
*inode
, struct file
*file
)
2380 struct spu_context
*ctx
= SPUFS_I(inode
)->i_ctx
;
2383 rc
= spu_acquire(ctx
);
2387 if (ctx
->switch_log
) {
2392 ctx
->switch_log
= kmalloc(sizeof(struct switch_log
) +
2393 SWITCH_LOG_BUFSIZE
* sizeof(struct switch_log_entry
),
2396 if (!ctx
->switch_log
) {
2401 ctx
->switch_log
->head
= ctx
->switch_log
->tail
= 0;
2402 init_waitqueue_head(&ctx
->switch_log
->wait
);
2410 static int spufs_switch_log_release(struct inode
*inode
, struct file
*file
)
2412 struct spu_context
*ctx
= SPUFS_I(inode
)->i_ctx
;
2415 rc
= spu_acquire(ctx
);
2419 kfree(ctx
->switch_log
);
2420 ctx
->switch_log
= NULL
;
2426 static int switch_log_sprint(struct spu_context
*ctx
, char *tbuf
, int n
)
2428 struct switch_log_entry
*p
;
2430 p
= ctx
->switch_log
->log
+ ctx
->switch_log
->tail
% SWITCH_LOG_BUFSIZE
;
2432 return snprintf(tbuf
, n
, "%u.%09u %d %u %u %llu\n",
2433 (unsigned int) p
->tstamp
.tv_sec
,
2434 (unsigned int) p
->tstamp
.tv_nsec
,
2436 (unsigned int) p
->type
,
2437 (unsigned int) p
->val
,
2438 (unsigned long long) p
->timebase
);
2441 static ssize_t
spufs_switch_log_read(struct file
*file
, char __user
*buf
,
2442 size_t len
, loff_t
*ppos
)
2444 struct inode
*inode
= file_inode(file
);
2445 struct spu_context
*ctx
= SPUFS_I(inode
)->i_ctx
;
2446 int error
= 0, cnt
= 0;
2451 error
= spu_acquire(ctx
);
2459 if (spufs_switch_log_used(ctx
) == 0) {
2461 /* If there's data ready to go, we can
2462 * just return straight away */
2465 } else if (file
->f_flags
& O_NONBLOCK
) {
2470 /* spufs_wait will drop the mutex and
2471 * re-acquire, but since we're in read(), the
2472 * file cannot be _released (and so
2473 * ctx->switch_log is stable).
2475 error
= spufs_wait(ctx
->switch_log
->wait
,
2476 spufs_switch_log_used(ctx
) > 0);
2478 /* On error, spufs_wait returns without the
2479 * state mutex held */
2483 /* We may have had entries read from underneath
2484 * us while we dropped the mutex in spufs_wait,
2486 if (spufs_switch_log_used(ctx
) == 0)
2491 width
= switch_log_sprint(ctx
, tbuf
, sizeof(tbuf
));
2493 ctx
->switch_log
->tail
=
2494 (ctx
->switch_log
->tail
+ 1) %
2497 /* If the record is greater than space available return
2498 * partial buffer (so far) */
2501 error
= copy_to_user(buf
+ cnt
, tbuf
, width
);
2509 return cnt
== 0 ? error
: cnt
;
2512 static unsigned int spufs_switch_log_poll(struct file
*file
, poll_table
*wait
)
2514 struct inode
*inode
= file_inode(file
);
2515 struct spu_context
*ctx
= SPUFS_I(inode
)->i_ctx
;
2516 unsigned int mask
= 0;
2519 poll_wait(file
, &ctx
->switch_log
->wait
, wait
);
2521 rc
= spu_acquire(ctx
);
2525 if (spufs_switch_log_used(ctx
) > 0)
2533 static const struct file_operations spufs_switch_log_fops
= {
2534 .open
= spufs_switch_log_open
,
2535 .read
= spufs_switch_log_read
,
2536 .poll
= spufs_switch_log_poll
,
2537 .release
= spufs_switch_log_release
,
2538 .llseek
= no_llseek
,
2542 * Log a context switch event to a switch log reader.
2544 * Must be called with ctx->state_mutex held.
2546 void spu_switch_log_notify(struct spu
*spu
, struct spu_context
*ctx
,
2549 if (!ctx
->switch_log
)
2552 if (spufs_switch_log_avail(ctx
) > 1) {
2553 struct switch_log_entry
*p
;
2555 p
= ctx
->switch_log
->log
+ ctx
->switch_log
->head
;
2556 ktime_get_ts(&p
->tstamp
);
2557 p
->timebase
= get_tb();
2558 p
->spu_id
= spu
? spu
->number
: -1;
2562 ctx
->switch_log
->head
=
2563 (ctx
->switch_log
->head
+ 1) % SWITCH_LOG_BUFSIZE
;
2566 wake_up(&ctx
->switch_log
->wait
);
2569 static int spufs_show_ctx(struct seq_file
*s
, void *private)
2571 struct spu_context
*ctx
= s
->private;
2574 mutex_lock(&ctx
->state_mutex
);
2576 struct spu
*spu
= ctx
->spu
;
2577 struct spu_priv2 __iomem
*priv2
= spu
->priv2
;
2579 spin_lock_irq(&spu
->register_lock
);
2580 mfc_control_RW
= in_be64(&priv2
->mfc_control_RW
);
2581 spin_unlock_irq(&spu
->register_lock
);
2583 struct spu_state
*csa
= &ctx
->csa
;
2585 mfc_control_RW
= csa
->priv2
.mfc_control_RW
;
2588 seq_printf(s
, "%c flgs(%lx) sflgs(%lx) pri(%d) ts(%d) spu(%02d)"
2589 " %c %llx %llx %llx %llx %x %x\n",
2590 ctx
->state
== SPU_STATE_SAVED
? 'S' : 'R',
2595 ctx
->spu
? ctx
->spu
->number
: -1,
2596 !list_empty(&ctx
->rq
) ? 'q' : ' ',
2597 ctx
->csa
.class_0_pending
,
2598 ctx
->csa
.class_0_dar
,
2599 ctx
->csa
.class_1_dsisr
,
2601 ctx
->ops
->runcntl_read(ctx
),
2602 ctx
->ops
->status_read(ctx
));
2604 mutex_unlock(&ctx
->state_mutex
);
2609 static int spufs_ctx_open(struct inode
*inode
, struct file
*file
)
2611 return single_open(file
, spufs_show_ctx
, SPUFS_I(inode
)->i_ctx
);
2614 static const struct file_operations spufs_ctx_fops
= {
2615 .open
= spufs_ctx_open
,
2617 .llseek
= seq_lseek
,
2618 .release
= single_release
,
2621 const struct spufs_tree_descr spufs_dir_contents
[] = {
2622 { "capabilities", &spufs_caps_fops
, 0444, },
2623 { "mem", &spufs_mem_fops
, 0666, LS_SIZE
, },
2624 { "regs", &spufs_regs_fops
, 0666, sizeof(struct spu_reg128
[128]), },
2625 { "mbox", &spufs_mbox_fops
, 0444, },
2626 { "ibox", &spufs_ibox_fops
, 0444, },
2627 { "wbox", &spufs_wbox_fops
, 0222, },
2628 { "mbox_stat", &spufs_mbox_stat_fops
, 0444, sizeof(u32
), },
2629 { "ibox_stat", &spufs_ibox_stat_fops
, 0444, sizeof(u32
), },
2630 { "wbox_stat", &spufs_wbox_stat_fops
, 0444, sizeof(u32
), },
2631 { "signal1", &spufs_signal1_fops
, 0666, },
2632 { "signal2", &spufs_signal2_fops
, 0666, },
2633 { "signal1_type", &spufs_signal1_type
, 0666, },
2634 { "signal2_type", &spufs_signal2_type
, 0666, },
2635 { "cntl", &spufs_cntl_fops
, 0666, },
2636 { "fpcr", &spufs_fpcr_fops
, 0666, sizeof(struct spu_reg128
), },
2637 { "lslr", &spufs_lslr_ops
, 0444, },
2638 { "mfc", &spufs_mfc_fops
, 0666, },
2639 { "mss", &spufs_mss_fops
, 0666, },
2640 { "npc", &spufs_npc_ops
, 0666, },
2641 { "srr0", &spufs_srr0_ops
, 0666, },
2642 { "decr", &spufs_decr_ops
, 0666, },
2643 { "decr_status", &spufs_decr_status_ops
, 0666, },
2644 { "event_mask", &spufs_event_mask_ops
, 0666, },
2645 { "event_status", &spufs_event_status_ops
, 0444, },
2646 { "psmap", &spufs_psmap_fops
, 0666, SPUFS_PS_MAP_SIZE
, },
2647 { "phys-id", &spufs_id_ops
, 0666, },
2648 { "object-id", &spufs_object_id_ops
, 0666, },
2649 { "mbox_info", &spufs_mbox_info_fops
, 0444, sizeof(u32
), },
2650 { "ibox_info", &spufs_ibox_info_fops
, 0444, sizeof(u32
), },
2651 { "wbox_info", &spufs_wbox_info_fops
, 0444, sizeof(u32
), },
2652 { "dma_info", &spufs_dma_info_fops
, 0444,
2653 sizeof(struct spu_dma_info
), },
2654 { "proxydma_info", &spufs_proxydma_info_fops
, 0444,
2655 sizeof(struct spu_proxydma_info
)},
2656 { "tid", &spufs_tid_fops
, 0444, },
2657 { "stat", &spufs_stat_fops
, 0444, },
2658 { "switch_log", &spufs_switch_log_fops
, 0444 },
2662 const struct spufs_tree_descr spufs_dir_nosched_contents
[] = {
2663 { "capabilities", &spufs_caps_fops
, 0444, },
2664 { "mem", &spufs_mem_fops
, 0666, LS_SIZE
, },
2665 { "mbox", &spufs_mbox_fops
, 0444, },
2666 { "ibox", &spufs_ibox_fops
, 0444, },
2667 { "wbox", &spufs_wbox_fops
, 0222, },
2668 { "mbox_stat", &spufs_mbox_stat_fops
, 0444, sizeof(u32
), },
2669 { "ibox_stat", &spufs_ibox_stat_fops
, 0444, sizeof(u32
), },
2670 { "wbox_stat", &spufs_wbox_stat_fops
, 0444, sizeof(u32
), },
2671 { "signal1", &spufs_signal1_nosched_fops
, 0222, },
2672 { "signal2", &spufs_signal2_nosched_fops
, 0222, },
2673 { "signal1_type", &spufs_signal1_type
, 0666, },
2674 { "signal2_type", &spufs_signal2_type
, 0666, },
2675 { "mss", &spufs_mss_fops
, 0666, },
2676 { "mfc", &spufs_mfc_fops
, 0666, },
2677 { "cntl", &spufs_cntl_fops
, 0666, },
2678 { "npc", &spufs_npc_ops
, 0666, },
2679 { "psmap", &spufs_psmap_fops
, 0666, SPUFS_PS_MAP_SIZE
, },
2680 { "phys-id", &spufs_id_ops
, 0666, },
2681 { "object-id", &spufs_object_id_ops
, 0666, },
2682 { "tid", &spufs_tid_fops
, 0444, },
2683 { "stat", &spufs_stat_fops
, 0444, },
2687 const struct spufs_tree_descr spufs_dir_debug_contents
[] = {
2688 { ".ctx", &spufs_ctx_fops
, 0444, },
2692 const struct spufs_coredump_reader spufs_coredump_read
[] = {
2693 { "regs", __spufs_regs_read
, NULL
, sizeof(struct spu_reg128
[128])},
2694 { "fpcr", __spufs_fpcr_read
, NULL
, sizeof(struct spu_reg128
) },
2695 { "lslr", NULL
, spufs_lslr_get
, 19 },
2696 { "decr", NULL
, spufs_decr_get
, 19 },
2697 { "decr_status", NULL
, spufs_decr_status_get
, 19 },
2698 { "mem", __spufs_mem_read
, NULL
, LS_SIZE
, },
2699 { "signal1", __spufs_signal1_read
, NULL
, sizeof(u32
) },
2700 { "signal1_type", NULL
, spufs_signal1_type_get
, 19 },
2701 { "signal2", __spufs_signal2_read
, NULL
, sizeof(u32
) },
2702 { "signal2_type", NULL
, spufs_signal2_type_get
, 19 },
2703 { "event_mask", NULL
, spufs_event_mask_get
, 19 },
2704 { "event_status", NULL
, spufs_event_status_get
, 19 },
2705 { "mbox_info", __spufs_mbox_info_read
, NULL
, sizeof(u32
) },
2706 { "ibox_info", __spufs_ibox_info_read
, NULL
, sizeof(u32
) },
2707 { "wbox_info", __spufs_wbox_info_read
, NULL
, 4 * sizeof(u32
)},
2708 { "dma_info", __spufs_dma_info_read
, NULL
, sizeof(struct spu_dma_info
)},
2709 { "proxydma_info", __spufs_proxydma_info_read
,
2710 NULL
, sizeof(struct spu_proxydma_info
)},
2711 { "object-id", NULL
, spufs_object_id_get
, 19 },
2712 { "npc", NULL
, spufs_npc_get
, 19 },