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_fault
*vmf
)
238 struct vm_area_struct
*vma
= vmf
->vma
;
239 struct spu_context
*ctx
= vma
->vm_file
->private_data
;
240 unsigned long pfn
, offset
;
242 offset
= vmf
->pgoff
<< PAGE_SHIFT
;
243 if (offset
>= LS_SIZE
)
244 return VM_FAULT_SIGBUS
;
246 pr_debug("spufs_mem_mmap_fault address=0x%lx, offset=0x%lx\n",
247 vmf
->address
, offset
);
249 if (spu_acquire(ctx
))
250 return VM_FAULT_NOPAGE
;
252 if (ctx
->state
== SPU_STATE_SAVED
) {
253 vma
->vm_page_prot
= pgprot_cached(vma
->vm_page_prot
);
254 pfn
= vmalloc_to_pfn(ctx
->csa
.lscsa
->ls
+ offset
);
256 vma
->vm_page_prot
= pgprot_noncached_wc(vma
->vm_page_prot
);
257 pfn
= (ctx
->spu
->local_store_phys
+ offset
) >> PAGE_SHIFT
;
259 vm_insert_pfn(vma
, vmf
->address
, pfn
);
263 return VM_FAULT_NOPAGE
;
266 static int spufs_mem_mmap_access(struct vm_area_struct
*vma
,
267 unsigned long address
,
268 void *buf
, int len
, int write
)
270 struct spu_context
*ctx
= vma
->vm_file
->private_data
;
271 unsigned long offset
= address
- vma
->vm_start
;
274 if (write
&& !(vma
->vm_flags
& VM_WRITE
))
276 if (spu_acquire(ctx
))
278 if ((offset
+ len
) > vma
->vm_end
)
279 len
= vma
->vm_end
- offset
;
280 local_store
= ctx
->ops
->get_ls(ctx
);
282 memcpy_toio(local_store
+ offset
, buf
, len
);
284 memcpy_fromio(buf
, local_store
+ offset
, len
);
289 static const struct vm_operations_struct spufs_mem_mmap_vmops
= {
290 .fault
= spufs_mem_mmap_fault
,
291 .access
= spufs_mem_mmap_access
,
294 static int spufs_mem_mmap(struct file
*file
, struct vm_area_struct
*vma
)
296 if (!(vma
->vm_flags
& VM_SHARED
))
299 vma
->vm_flags
|= VM_IO
| VM_PFNMAP
;
300 vma
->vm_page_prot
= pgprot_noncached_wc(vma
->vm_page_prot
);
302 vma
->vm_ops
= &spufs_mem_mmap_vmops
;
306 static const struct file_operations spufs_mem_fops
= {
307 .open
= spufs_mem_open
,
308 .release
= spufs_mem_release
,
309 .read
= spufs_mem_read
,
310 .write
= spufs_mem_write
,
311 .llseek
= generic_file_llseek
,
312 .mmap
= spufs_mem_mmap
,
315 static int spufs_ps_fault(struct vm_fault
*vmf
,
316 unsigned long ps_offs
,
317 unsigned long ps_size
)
319 struct spu_context
*ctx
= vmf
->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(vmf
->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_fault
*vmf
)
372 return spufs_ps_fault(vmf
, 0x4000, SPUFS_CNTL_MAP_SIZE
);
375 static const struct vm_operations_struct spufs_cntl_mmap_vmops
= {
376 .fault
= spufs_cntl_mmap_fault
,
380 * mmap support for problem state control area [0x4000 - 0x4fff].
382 static int spufs_cntl_mmap(struct file
*file
, struct vm_area_struct
*vma
)
384 if (!(vma
->vm_flags
& VM_SHARED
))
387 vma
->vm_flags
|= VM_IO
| VM_PFNMAP
;
388 vma
->vm_page_prot
= pgprot_noncached(vma
->vm_page_prot
);
390 vma
->vm_ops
= &spufs_cntl_mmap_vmops
;
393 #else /* SPUFS_MMAP_4K */
394 #define spufs_cntl_mmap NULL
395 #endif /* !SPUFS_MMAP_4K */
397 static int spufs_cntl_get(void *data
, u64
*val
)
399 struct spu_context
*ctx
= data
;
402 ret
= spu_acquire(ctx
);
405 *val
= ctx
->ops
->status_read(ctx
);
411 static int spufs_cntl_set(void *data
, u64 val
)
413 struct spu_context
*ctx
= data
;
416 ret
= spu_acquire(ctx
);
419 ctx
->ops
->runcntl_write(ctx
, val
);
425 static int spufs_cntl_open(struct inode
*inode
, struct file
*file
)
427 struct spufs_inode_info
*i
= SPUFS_I(inode
);
428 struct spu_context
*ctx
= i
->i_ctx
;
430 mutex_lock(&ctx
->mapping_lock
);
431 file
->private_data
= ctx
;
433 ctx
->cntl
= inode
->i_mapping
;
434 mutex_unlock(&ctx
->mapping_lock
);
435 return simple_attr_open(inode
, file
, spufs_cntl_get
,
436 spufs_cntl_set
, "0x%08lx");
440 spufs_cntl_release(struct inode
*inode
, struct file
*file
)
442 struct spufs_inode_info
*i
= SPUFS_I(inode
);
443 struct spu_context
*ctx
= i
->i_ctx
;
445 simple_attr_release(inode
, file
);
447 mutex_lock(&ctx
->mapping_lock
);
450 mutex_unlock(&ctx
->mapping_lock
);
454 static const struct file_operations spufs_cntl_fops
= {
455 .open
= spufs_cntl_open
,
456 .release
= spufs_cntl_release
,
457 .read
= simple_attr_read
,
458 .write
= simple_attr_write
,
459 .llseek
= generic_file_llseek
,
460 .mmap
= spufs_cntl_mmap
,
464 spufs_regs_open(struct inode
*inode
, struct file
*file
)
466 struct spufs_inode_info
*i
= SPUFS_I(inode
);
467 file
->private_data
= i
->i_ctx
;
472 __spufs_regs_read(struct spu_context
*ctx
, char __user
*buffer
,
473 size_t size
, loff_t
*pos
)
475 struct spu_lscsa
*lscsa
= ctx
->csa
.lscsa
;
476 return simple_read_from_buffer(buffer
, size
, pos
,
477 lscsa
->gprs
, sizeof lscsa
->gprs
);
481 spufs_regs_read(struct file
*file
, char __user
*buffer
,
482 size_t size
, loff_t
*pos
)
485 struct spu_context
*ctx
= file
->private_data
;
487 /* pre-check for file position: if we'd return EOF, there's no point
488 * causing a deschedule */
489 if (*pos
>= sizeof(ctx
->csa
.lscsa
->gprs
))
492 ret
= spu_acquire_saved(ctx
);
495 ret
= __spufs_regs_read(ctx
, buffer
, size
, pos
);
496 spu_release_saved(ctx
);
501 spufs_regs_write(struct file
*file
, const char __user
*buffer
,
502 size_t size
, loff_t
*pos
)
504 struct spu_context
*ctx
= file
->private_data
;
505 struct spu_lscsa
*lscsa
= ctx
->csa
.lscsa
;
508 if (*pos
>= sizeof(lscsa
->gprs
))
511 ret
= spu_acquire_saved(ctx
);
515 size
= simple_write_to_buffer(lscsa
->gprs
, sizeof(lscsa
->gprs
), pos
,
518 spu_release_saved(ctx
);
522 static const struct file_operations spufs_regs_fops
= {
523 .open
= spufs_regs_open
,
524 .read
= spufs_regs_read
,
525 .write
= spufs_regs_write
,
526 .llseek
= generic_file_llseek
,
530 __spufs_fpcr_read(struct spu_context
*ctx
, char __user
* buffer
,
531 size_t size
, loff_t
* pos
)
533 struct spu_lscsa
*lscsa
= ctx
->csa
.lscsa
;
534 return simple_read_from_buffer(buffer
, size
, pos
,
535 &lscsa
->fpcr
, sizeof(lscsa
->fpcr
));
539 spufs_fpcr_read(struct file
*file
, char __user
* buffer
,
540 size_t size
, loff_t
* pos
)
543 struct spu_context
*ctx
= file
->private_data
;
545 ret
= spu_acquire_saved(ctx
);
548 ret
= __spufs_fpcr_read(ctx
, buffer
, size
, pos
);
549 spu_release_saved(ctx
);
554 spufs_fpcr_write(struct file
*file
, const char __user
* buffer
,
555 size_t size
, loff_t
* pos
)
557 struct spu_context
*ctx
= file
->private_data
;
558 struct spu_lscsa
*lscsa
= ctx
->csa
.lscsa
;
561 if (*pos
>= sizeof(lscsa
->fpcr
))
564 ret
= spu_acquire_saved(ctx
);
568 size
= simple_write_to_buffer(&lscsa
->fpcr
, sizeof(lscsa
->fpcr
), pos
,
571 spu_release_saved(ctx
);
575 static const struct file_operations spufs_fpcr_fops
= {
576 .open
= spufs_regs_open
,
577 .read
= spufs_fpcr_read
,
578 .write
= spufs_fpcr_write
,
579 .llseek
= generic_file_llseek
,
582 /* generic open function for all pipe-like files */
583 static int spufs_pipe_open(struct inode
*inode
, struct file
*file
)
585 struct spufs_inode_info
*i
= SPUFS_I(inode
);
586 file
->private_data
= i
->i_ctx
;
588 return nonseekable_open(inode
, file
);
592 * Read as many bytes from the mailbox as possible, until
593 * one of the conditions becomes true:
595 * - no more data available in the mailbox
596 * - end of the user provided buffer
597 * - end of the mapped area
599 static ssize_t
spufs_mbox_read(struct file
*file
, char __user
*buf
,
600 size_t len
, loff_t
*pos
)
602 struct spu_context
*ctx
= file
->private_data
;
603 u32 mbox_data
, __user
*udata
;
609 if (!access_ok(VERIFY_WRITE
, buf
, len
))
612 udata
= (void __user
*)buf
;
614 count
= spu_acquire(ctx
);
618 for (count
= 0; (count
+ 4) <= len
; count
+= 4, udata
++) {
620 ret
= ctx
->ops
->mbox_read(ctx
, &mbox_data
);
625 * at the end of the mapped area, we can fault
626 * but still need to return the data we have
627 * read successfully so far.
629 ret
= __put_user(mbox_data
, udata
);
644 static const struct file_operations spufs_mbox_fops
= {
645 .open
= spufs_pipe_open
,
646 .read
= spufs_mbox_read
,
650 static ssize_t
spufs_mbox_stat_read(struct file
*file
, char __user
*buf
,
651 size_t len
, loff_t
*pos
)
653 struct spu_context
*ctx
= file
->private_data
;
660 ret
= spu_acquire(ctx
);
664 mbox_stat
= ctx
->ops
->mbox_stat_read(ctx
) & 0xff;
668 if (copy_to_user(buf
, &mbox_stat
, sizeof mbox_stat
))
674 static const struct file_operations spufs_mbox_stat_fops
= {
675 .open
= spufs_pipe_open
,
676 .read
= spufs_mbox_stat_read
,
680 /* low-level ibox access function */
681 size_t spu_ibox_read(struct spu_context
*ctx
, u32
*data
)
683 return ctx
->ops
->ibox_read(ctx
, data
);
686 static int spufs_ibox_fasync(int fd
, struct file
*file
, int on
)
688 struct spu_context
*ctx
= file
->private_data
;
690 return fasync_helper(fd
, file
, on
, &ctx
->ibox_fasync
);
693 /* interrupt-level ibox callback function. */
694 void spufs_ibox_callback(struct spu
*spu
)
696 struct spu_context
*ctx
= spu
->ctx
;
701 wake_up_all(&ctx
->ibox_wq
);
702 kill_fasync(&ctx
->ibox_fasync
, SIGIO
, POLLIN
);
706 * Read as many bytes from the interrupt mailbox as possible, until
707 * one of the conditions becomes true:
709 * - no more data available in the mailbox
710 * - end of the user provided buffer
711 * - end of the mapped area
713 * If the file is opened without O_NONBLOCK, we wait here until
714 * any data is available, but return when we have been able to
717 static ssize_t
spufs_ibox_read(struct file
*file
, char __user
*buf
,
718 size_t len
, loff_t
*pos
)
720 struct spu_context
*ctx
= file
->private_data
;
721 u32 ibox_data
, __user
*udata
;
727 if (!access_ok(VERIFY_WRITE
, buf
, len
))
730 udata
= (void __user
*)buf
;
732 count
= spu_acquire(ctx
);
736 /* wait only for the first element */
738 if (file
->f_flags
& O_NONBLOCK
) {
739 if (!spu_ibox_read(ctx
, &ibox_data
)) {
744 count
= spufs_wait(ctx
->ibox_wq
, spu_ibox_read(ctx
, &ibox_data
));
749 /* if we can't write at all, return -EFAULT */
750 count
= __put_user(ibox_data
, udata
);
754 for (count
= 4, udata
++; (count
+ 4) <= len
; count
+= 4, udata
++) {
756 ret
= ctx
->ops
->ibox_read(ctx
, &ibox_data
);
760 * at the end of the mapped area, we can fault
761 * but still need to return the data we have
762 * read successfully so far.
764 ret
= __put_user(ibox_data
, udata
);
775 static unsigned int spufs_ibox_poll(struct file
*file
, poll_table
*wait
)
777 struct spu_context
*ctx
= file
->private_data
;
780 poll_wait(file
, &ctx
->ibox_wq
, wait
);
783 * For now keep this uninterruptible and also ignore the rule
784 * that poll should not sleep. Will be fixed later.
786 mutex_lock(&ctx
->state_mutex
);
787 mask
= ctx
->ops
->mbox_stat_poll(ctx
, POLLIN
| POLLRDNORM
);
793 static const struct file_operations spufs_ibox_fops
= {
794 .open
= spufs_pipe_open
,
795 .read
= spufs_ibox_read
,
796 .poll
= spufs_ibox_poll
,
797 .fasync
= spufs_ibox_fasync
,
801 static ssize_t
spufs_ibox_stat_read(struct file
*file
, char __user
*buf
,
802 size_t len
, loff_t
*pos
)
804 struct spu_context
*ctx
= file
->private_data
;
811 ret
= spu_acquire(ctx
);
814 ibox_stat
= (ctx
->ops
->mbox_stat_read(ctx
) >> 16) & 0xff;
817 if (copy_to_user(buf
, &ibox_stat
, sizeof ibox_stat
))
823 static const struct file_operations spufs_ibox_stat_fops
= {
824 .open
= spufs_pipe_open
,
825 .read
= spufs_ibox_stat_read
,
829 /* low-level mailbox write */
830 size_t spu_wbox_write(struct spu_context
*ctx
, u32 data
)
832 return ctx
->ops
->wbox_write(ctx
, data
);
835 static int spufs_wbox_fasync(int fd
, struct file
*file
, int on
)
837 struct spu_context
*ctx
= file
->private_data
;
840 ret
= fasync_helper(fd
, file
, on
, &ctx
->wbox_fasync
);
845 /* interrupt-level wbox callback function. */
846 void spufs_wbox_callback(struct spu
*spu
)
848 struct spu_context
*ctx
= spu
->ctx
;
853 wake_up_all(&ctx
->wbox_wq
);
854 kill_fasync(&ctx
->wbox_fasync
, SIGIO
, POLLOUT
);
858 * Write as many bytes to the interrupt mailbox as possible, until
859 * one of the conditions becomes true:
861 * - the mailbox is full
862 * - end of the user provided buffer
863 * - end of the mapped area
865 * If the file is opened without O_NONBLOCK, we wait here until
866 * space is available, but return when we have been able to
869 static ssize_t
spufs_wbox_write(struct file
*file
, const char __user
*buf
,
870 size_t len
, loff_t
*pos
)
872 struct spu_context
*ctx
= file
->private_data
;
873 u32 wbox_data
, __user
*udata
;
879 udata
= (void __user
*)buf
;
880 if (!access_ok(VERIFY_READ
, buf
, len
))
883 if (__get_user(wbox_data
, udata
))
886 count
= spu_acquire(ctx
);
891 * make sure we can at least write one element, by waiting
892 * in case of !O_NONBLOCK
895 if (file
->f_flags
& O_NONBLOCK
) {
896 if (!spu_wbox_write(ctx
, wbox_data
)) {
901 count
= spufs_wait(ctx
->wbox_wq
, spu_wbox_write(ctx
, wbox_data
));
907 /* write as much as possible */
908 for (count
= 4, udata
++; (count
+ 4) <= len
; count
+= 4, udata
++) {
910 ret
= __get_user(wbox_data
, udata
);
914 ret
= spu_wbox_write(ctx
, wbox_data
);
925 static unsigned int spufs_wbox_poll(struct file
*file
, poll_table
*wait
)
927 struct spu_context
*ctx
= file
->private_data
;
930 poll_wait(file
, &ctx
->wbox_wq
, wait
);
933 * For now keep this uninterruptible and also ignore the rule
934 * that poll should not sleep. Will be fixed later.
936 mutex_lock(&ctx
->state_mutex
);
937 mask
= ctx
->ops
->mbox_stat_poll(ctx
, POLLOUT
| POLLWRNORM
);
943 static const struct file_operations spufs_wbox_fops
= {
944 .open
= spufs_pipe_open
,
945 .write
= spufs_wbox_write
,
946 .poll
= spufs_wbox_poll
,
947 .fasync
= spufs_wbox_fasync
,
951 static ssize_t
spufs_wbox_stat_read(struct file
*file
, char __user
*buf
,
952 size_t len
, loff_t
*pos
)
954 struct spu_context
*ctx
= file
->private_data
;
961 ret
= spu_acquire(ctx
);
964 wbox_stat
= (ctx
->ops
->mbox_stat_read(ctx
) >> 8) & 0xff;
967 if (copy_to_user(buf
, &wbox_stat
, sizeof wbox_stat
))
973 static const struct file_operations spufs_wbox_stat_fops
= {
974 .open
= spufs_pipe_open
,
975 .read
= spufs_wbox_stat_read
,
979 static int spufs_signal1_open(struct inode
*inode
, struct file
*file
)
981 struct spufs_inode_info
*i
= SPUFS_I(inode
);
982 struct spu_context
*ctx
= i
->i_ctx
;
984 mutex_lock(&ctx
->mapping_lock
);
985 file
->private_data
= ctx
;
987 ctx
->signal1
= inode
->i_mapping
;
988 mutex_unlock(&ctx
->mapping_lock
);
989 return nonseekable_open(inode
, file
);
993 spufs_signal1_release(struct inode
*inode
, struct file
*file
)
995 struct spufs_inode_info
*i
= SPUFS_I(inode
);
996 struct spu_context
*ctx
= i
->i_ctx
;
998 mutex_lock(&ctx
->mapping_lock
);
1000 ctx
->signal1
= NULL
;
1001 mutex_unlock(&ctx
->mapping_lock
);
1005 static ssize_t
__spufs_signal1_read(struct spu_context
*ctx
, char __user
*buf
,
1006 size_t len
, loff_t
*pos
)
1014 if (ctx
->csa
.spu_chnlcnt_RW
[3]) {
1015 data
= ctx
->csa
.spu_chnldata_RW
[3];
1022 if (copy_to_user(buf
, &data
, 4))
1029 static ssize_t
spufs_signal1_read(struct file
*file
, char __user
*buf
,
1030 size_t len
, loff_t
*pos
)
1033 struct spu_context
*ctx
= file
->private_data
;
1035 ret
= spu_acquire_saved(ctx
);
1038 ret
= __spufs_signal1_read(ctx
, buf
, len
, pos
);
1039 spu_release_saved(ctx
);
1044 static ssize_t
spufs_signal1_write(struct file
*file
, const char __user
*buf
,
1045 size_t len
, loff_t
*pos
)
1047 struct spu_context
*ctx
;
1051 ctx
= file
->private_data
;
1056 if (copy_from_user(&data
, buf
, 4))
1059 ret
= spu_acquire(ctx
);
1062 ctx
->ops
->signal1_write(ctx
, data
);
1069 spufs_signal1_mmap_fault(struct vm_fault
*vmf
)
1071 #if SPUFS_SIGNAL_MAP_SIZE == 0x1000
1072 return spufs_ps_fault(vmf
, 0x14000, SPUFS_SIGNAL_MAP_SIZE
);
1073 #elif SPUFS_SIGNAL_MAP_SIZE == 0x10000
1074 /* For 64k pages, both signal1 and signal2 can be used to mmap the whole
1075 * signal 1 and 2 area
1077 return spufs_ps_fault(vmf
, 0x10000, SPUFS_SIGNAL_MAP_SIZE
);
1079 #error unsupported page size
1083 static const struct vm_operations_struct spufs_signal1_mmap_vmops
= {
1084 .fault
= spufs_signal1_mmap_fault
,
1087 static int spufs_signal1_mmap(struct file
*file
, struct vm_area_struct
*vma
)
1089 if (!(vma
->vm_flags
& VM_SHARED
))
1092 vma
->vm_flags
|= VM_IO
| VM_PFNMAP
;
1093 vma
->vm_page_prot
= pgprot_noncached(vma
->vm_page_prot
);
1095 vma
->vm_ops
= &spufs_signal1_mmap_vmops
;
1099 static const struct file_operations spufs_signal1_fops
= {
1100 .open
= spufs_signal1_open
,
1101 .release
= spufs_signal1_release
,
1102 .read
= spufs_signal1_read
,
1103 .write
= spufs_signal1_write
,
1104 .mmap
= spufs_signal1_mmap
,
1105 .llseek
= no_llseek
,
1108 static const struct file_operations spufs_signal1_nosched_fops
= {
1109 .open
= spufs_signal1_open
,
1110 .release
= spufs_signal1_release
,
1111 .write
= spufs_signal1_write
,
1112 .mmap
= spufs_signal1_mmap
,
1113 .llseek
= no_llseek
,
1116 static int spufs_signal2_open(struct inode
*inode
, struct file
*file
)
1118 struct spufs_inode_info
*i
= SPUFS_I(inode
);
1119 struct spu_context
*ctx
= i
->i_ctx
;
1121 mutex_lock(&ctx
->mapping_lock
);
1122 file
->private_data
= ctx
;
1123 if (!i
->i_openers
++)
1124 ctx
->signal2
= inode
->i_mapping
;
1125 mutex_unlock(&ctx
->mapping_lock
);
1126 return nonseekable_open(inode
, file
);
1130 spufs_signal2_release(struct inode
*inode
, struct file
*file
)
1132 struct spufs_inode_info
*i
= SPUFS_I(inode
);
1133 struct spu_context
*ctx
= i
->i_ctx
;
1135 mutex_lock(&ctx
->mapping_lock
);
1136 if (!--i
->i_openers
)
1137 ctx
->signal2
= NULL
;
1138 mutex_unlock(&ctx
->mapping_lock
);
1142 static ssize_t
__spufs_signal2_read(struct spu_context
*ctx
, char __user
*buf
,
1143 size_t len
, loff_t
*pos
)
1151 if (ctx
->csa
.spu_chnlcnt_RW
[4]) {
1152 data
= ctx
->csa
.spu_chnldata_RW
[4];
1159 if (copy_to_user(buf
, &data
, 4))
1166 static ssize_t
spufs_signal2_read(struct file
*file
, char __user
*buf
,
1167 size_t len
, loff_t
*pos
)
1169 struct spu_context
*ctx
= file
->private_data
;
1172 ret
= spu_acquire_saved(ctx
);
1175 ret
= __spufs_signal2_read(ctx
, buf
, len
, pos
);
1176 spu_release_saved(ctx
);
1181 static ssize_t
spufs_signal2_write(struct file
*file
, const char __user
*buf
,
1182 size_t len
, loff_t
*pos
)
1184 struct spu_context
*ctx
;
1188 ctx
= file
->private_data
;
1193 if (copy_from_user(&data
, buf
, 4))
1196 ret
= spu_acquire(ctx
);
1199 ctx
->ops
->signal2_write(ctx
, data
);
1207 spufs_signal2_mmap_fault(struct vm_fault
*vmf
)
1209 #if SPUFS_SIGNAL_MAP_SIZE == 0x1000
1210 return spufs_ps_fault(vmf
, 0x1c000, SPUFS_SIGNAL_MAP_SIZE
);
1211 #elif SPUFS_SIGNAL_MAP_SIZE == 0x10000
1212 /* For 64k pages, both signal1 and signal2 can be used to mmap the whole
1213 * signal 1 and 2 area
1215 return spufs_ps_fault(vmf
, 0x10000, SPUFS_SIGNAL_MAP_SIZE
);
1217 #error unsupported page size
1221 static const struct vm_operations_struct spufs_signal2_mmap_vmops
= {
1222 .fault
= spufs_signal2_mmap_fault
,
1225 static int spufs_signal2_mmap(struct file
*file
, struct vm_area_struct
*vma
)
1227 if (!(vma
->vm_flags
& VM_SHARED
))
1230 vma
->vm_flags
|= VM_IO
| VM_PFNMAP
;
1231 vma
->vm_page_prot
= pgprot_noncached(vma
->vm_page_prot
);
1233 vma
->vm_ops
= &spufs_signal2_mmap_vmops
;
1236 #else /* SPUFS_MMAP_4K */
1237 #define spufs_signal2_mmap NULL
1238 #endif /* !SPUFS_MMAP_4K */
1240 static const struct file_operations spufs_signal2_fops
= {
1241 .open
= spufs_signal2_open
,
1242 .release
= spufs_signal2_release
,
1243 .read
= spufs_signal2_read
,
1244 .write
= spufs_signal2_write
,
1245 .mmap
= spufs_signal2_mmap
,
1246 .llseek
= no_llseek
,
1249 static const struct file_operations spufs_signal2_nosched_fops
= {
1250 .open
= spufs_signal2_open
,
1251 .release
= spufs_signal2_release
,
1252 .write
= spufs_signal2_write
,
1253 .mmap
= spufs_signal2_mmap
,
1254 .llseek
= no_llseek
,
1258 * This is a wrapper around DEFINE_SIMPLE_ATTRIBUTE which does the
1259 * work of acquiring (or not) the SPU context before calling through
1260 * to the actual get routine. The set routine is called directly.
1262 #define SPU_ATTR_NOACQUIRE 0
1263 #define SPU_ATTR_ACQUIRE 1
1264 #define SPU_ATTR_ACQUIRE_SAVED 2
1266 #define DEFINE_SPUFS_ATTRIBUTE(__name, __get, __set, __fmt, __acquire) \
1267 static int __##__get(void *data, u64 *val) \
1269 struct spu_context *ctx = data; \
1272 if (__acquire == SPU_ATTR_ACQUIRE) { \
1273 ret = spu_acquire(ctx); \
1276 *val = __get(ctx); \
1278 } else if (__acquire == SPU_ATTR_ACQUIRE_SAVED) { \
1279 ret = spu_acquire_saved(ctx); \
1282 *val = __get(ctx); \
1283 spu_release_saved(ctx); \
1285 *val = __get(ctx); \
1289 DEFINE_SPUFS_SIMPLE_ATTRIBUTE(__name, __##__get, __set, __fmt);
1291 static int spufs_signal1_type_set(void *data
, u64 val
)
1293 struct spu_context
*ctx
= data
;
1296 ret
= spu_acquire(ctx
);
1299 ctx
->ops
->signal1_type_set(ctx
, val
);
1305 static u64
spufs_signal1_type_get(struct spu_context
*ctx
)
1307 return ctx
->ops
->signal1_type_get(ctx
);
1309 DEFINE_SPUFS_ATTRIBUTE(spufs_signal1_type
, spufs_signal1_type_get
,
1310 spufs_signal1_type_set
, "%llu\n", SPU_ATTR_ACQUIRE
);
1313 static int spufs_signal2_type_set(void *data
, u64 val
)
1315 struct spu_context
*ctx
= data
;
1318 ret
= spu_acquire(ctx
);
1321 ctx
->ops
->signal2_type_set(ctx
, val
);
1327 static u64
spufs_signal2_type_get(struct spu_context
*ctx
)
1329 return ctx
->ops
->signal2_type_get(ctx
);
1331 DEFINE_SPUFS_ATTRIBUTE(spufs_signal2_type
, spufs_signal2_type_get
,
1332 spufs_signal2_type_set
, "%llu\n", SPU_ATTR_ACQUIRE
);
1336 spufs_mss_mmap_fault(struct vm_fault
*vmf
)
1338 return spufs_ps_fault(vmf
, 0x0000, SPUFS_MSS_MAP_SIZE
);
1341 static const struct vm_operations_struct spufs_mss_mmap_vmops
= {
1342 .fault
= spufs_mss_mmap_fault
,
1346 * mmap support for problem state MFC DMA area [0x0000 - 0x0fff].
1348 static int spufs_mss_mmap(struct file
*file
, struct vm_area_struct
*vma
)
1350 if (!(vma
->vm_flags
& VM_SHARED
))
1353 vma
->vm_flags
|= VM_IO
| VM_PFNMAP
;
1354 vma
->vm_page_prot
= pgprot_noncached(vma
->vm_page_prot
);
1356 vma
->vm_ops
= &spufs_mss_mmap_vmops
;
1359 #else /* SPUFS_MMAP_4K */
1360 #define spufs_mss_mmap NULL
1361 #endif /* !SPUFS_MMAP_4K */
1363 static int spufs_mss_open(struct inode
*inode
, struct file
*file
)
1365 struct spufs_inode_info
*i
= SPUFS_I(inode
);
1366 struct spu_context
*ctx
= i
->i_ctx
;
1368 file
->private_data
= i
->i_ctx
;
1370 mutex_lock(&ctx
->mapping_lock
);
1371 if (!i
->i_openers
++)
1372 ctx
->mss
= inode
->i_mapping
;
1373 mutex_unlock(&ctx
->mapping_lock
);
1374 return nonseekable_open(inode
, file
);
1378 spufs_mss_release(struct inode
*inode
, struct file
*file
)
1380 struct spufs_inode_info
*i
= SPUFS_I(inode
);
1381 struct spu_context
*ctx
= i
->i_ctx
;
1383 mutex_lock(&ctx
->mapping_lock
);
1384 if (!--i
->i_openers
)
1386 mutex_unlock(&ctx
->mapping_lock
);
1390 static const struct file_operations spufs_mss_fops
= {
1391 .open
= spufs_mss_open
,
1392 .release
= spufs_mss_release
,
1393 .mmap
= spufs_mss_mmap
,
1394 .llseek
= no_llseek
,
1398 spufs_psmap_mmap_fault(struct vm_fault
*vmf
)
1400 return spufs_ps_fault(vmf
, 0x0000, SPUFS_PS_MAP_SIZE
);
1403 static const struct vm_operations_struct spufs_psmap_mmap_vmops
= {
1404 .fault
= spufs_psmap_mmap_fault
,
1408 * mmap support for full problem state area [0x00000 - 0x1ffff].
1410 static int spufs_psmap_mmap(struct file
*file
, struct vm_area_struct
*vma
)
1412 if (!(vma
->vm_flags
& VM_SHARED
))
1415 vma
->vm_flags
|= VM_IO
| VM_PFNMAP
;
1416 vma
->vm_page_prot
= pgprot_noncached(vma
->vm_page_prot
);
1418 vma
->vm_ops
= &spufs_psmap_mmap_vmops
;
1422 static int spufs_psmap_open(struct inode
*inode
, struct file
*file
)
1424 struct spufs_inode_info
*i
= SPUFS_I(inode
);
1425 struct spu_context
*ctx
= i
->i_ctx
;
1427 mutex_lock(&ctx
->mapping_lock
);
1428 file
->private_data
= i
->i_ctx
;
1429 if (!i
->i_openers
++)
1430 ctx
->psmap
= inode
->i_mapping
;
1431 mutex_unlock(&ctx
->mapping_lock
);
1432 return nonseekable_open(inode
, file
);
1436 spufs_psmap_release(struct inode
*inode
, struct file
*file
)
1438 struct spufs_inode_info
*i
= SPUFS_I(inode
);
1439 struct spu_context
*ctx
= i
->i_ctx
;
1441 mutex_lock(&ctx
->mapping_lock
);
1442 if (!--i
->i_openers
)
1444 mutex_unlock(&ctx
->mapping_lock
);
1448 static const struct file_operations spufs_psmap_fops
= {
1449 .open
= spufs_psmap_open
,
1450 .release
= spufs_psmap_release
,
1451 .mmap
= spufs_psmap_mmap
,
1452 .llseek
= no_llseek
,
1458 spufs_mfc_mmap_fault(struct vm_fault
*vmf
)
1460 return spufs_ps_fault(vmf
, 0x3000, SPUFS_MFC_MAP_SIZE
);
1463 static const struct vm_operations_struct spufs_mfc_mmap_vmops
= {
1464 .fault
= spufs_mfc_mmap_fault
,
1468 * mmap support for problem state MFC DMA area [0x0000 - 0x0fff].
1470 static int spufs_mfc_mmap(struct file
*file
, struct vm_area_struct
*vma
)
1472 if (!(vma
->vm_flags
& VM_SHARED
))
1475 vma
->vm_flags
|= VM_IO
| VM_PFNMAP
;
1476 vma
->vm_page_prot
= pgprot_noncached(vma
->vm_page_prot
);
1478 vma
->vm_ops
= &spufs_mfc_mmap_vmops
;
1481 #else /* SPUFS_MMAP_4K */
1482 #define spufs_mfc_mmap NULL
1483 #endif /* !SPUFS_MMAP_4K */
1485 static int spufs_mfc_open(struct inode
*inode
, struct file
*file
)
1487 struct spufs_inode_info
*i
= SPUFS_I(inode
);
1488 struct spu_context
*ctx
= i
->i_ctx
;
1490 /* we don't want to deal with DMA into other processes */
1491 if (ctx
->owner
!= current
->mm
)
1494 if (atomic_read(&inode
->i_count
) != 1)
1497 mutex_lock(&ctx
->mapping_lock
);
1498 file
->private_data
= ctx
;
1499 if (!i
->i_openers
++)
1500 ctx
->mfc
= inode
->i_mapping
;
1501 mutex_unlock(&ctx
->mapping_lock
);
1502 return nonseekable_open(inode
, file
);
1506 spufs_mfc_release(struct inode
*inode
, struct file
*file
)
1508 struct spufs_inode_info
*i
= SPUFS_I(inode
);
1509 struct spu_context
*ctx
= i
->i_ctx
;
1511 mutex_lock(&ctx
->mapping_lock
);
1512 if (!--i
->i_openers
)
1514 mutex_unlock(&ctx
->mapping_lock
);
1518 /* interrupt-level mfc callback function. */
1519 void spufs_mfc_callback(struct spu
*spu
)
1521 struct spu_context
*ctx
= spu
->ctx
;
1526 wake_up_all(&ctx
->mfc_wq
);
1528 pr_debug("%s %s\n", __func__
, spu
->name
);
1529 if (ctx
->mfc_fasync
) {
1530 u32 free_elements
, tagstatus
;
1533 /* no need for spu_acquire in interrupt context */
1534 free_elements
= ctx
->ops
->get_mfc_free_elements(ctx
);
1535 tagstatus
= ctx
->ops
->read_mfc_tagstatus(ctx
);
1538 if (free_elements
& 0xffff)
1540 if (tagstatus
& ctx
->tagwait
)
1543 kill_fasync(&ctx
->mfc_fasync
, SIGIO
, mask
);
1547 static int spufs_read_mfc_tagstatus(struct spu_context
*ctx
, u32
*status
)
1549 /* See if there is one tag group is complete */
1550 /* FIXME we need locking around tagwait */
1551 *status
= ctx
->ops
->read_mfc_tagstatus(ctx
) & ctx
->tagwait
;
1552 ctx
->tagwait
&= ~*status
;
1556 /* enable interrupt waiting for any tag group,
1557 may silently fail if interrupts are already enabled */
1558 ctx
->ops
->set_mfc_query(ctx
, ctx
->tagwait
, 1);
1562 static ssize_t
spufs_mfc_read(struct file
*file
, char __user
*buffer
,
1563 size_t size
, loff_t
*pos
)
1565 struct spu_context
*ctx
= file
->private_data
;
1572 ret
= spu_acquire(ctx
);
1577 if (file
->f_flags
& O_NONBLOCK
) {
1578 status
= ctx
->ops
->read_mfc_tagstatus(ctx
);
1579 if (!(status
& ctx
->tagwait
))
1582 /* XXX(hch): shouldn't we clear ret here? */
1583 ctx
->tagwait
&= ~status
;
1585 ret
= spufs_wait(ctx
->mfc_wq
,
1586 spufs_read_mfc_tagstatus(ctx
, &status
));
1593 if (copy_to_user(buffer
, &status
, 4))
1600 static int spufs_check_valid_dma(struct mfc_dma_command
*cmd
)
1602 pr_debug("queueing DMA %x %llx %x %x %x\n", cmd
->lsa
,
1603 cmd
->ea
, cmd
->size
, cmd
->tag
, cmd
->cmd
);
1614 pr_debug("invalid DMA opcode %x\n", cmd
->cmd
);
1618 if ((cmd
->lsa
& 0xf) != (cmd
->ea
&0xf)) {
1619 pr_debug("invalid DMA alignment, ea %llx lsa %x\n",
1624 switch (cmd
->size
& 0xf) {
1645 pr_debug("invalid DMA alignment %x for size %x\n",
1646 cmd
->lsa
& 0xf, cmd
->size
);
1650 if (cmd
->size
> 16 * 1024) {
1651 pr_debug("invalid DMA size %x\n", cmd
->size
);
1655 if (cmd
->tag
& 0xfff0) {
1656 /* we reserve the higher tag numbers for kernel use */
1657 pr_debug("invalid DMA tag\n");
1662 /* not supported in this version */
1663 pr_debug("invalid DMA class\n");
1670 static int spu_send_mfc_command(struct spu_context
*ctx
,
1671 struct mfc_dma_command cmd
,
1674 *error
= ctx
->ops
->send_mfc_command(ctx
, &cmd
);
1675 if (*error
== -EAGAIN
) {
1676 /* wait for any tag group to complete
1677 so we have space for the new command */
1678 ctx
->ops
->set_mfc_query(ctx
, ctx
->tagwait
, 1);
1679 /* try again, because the queue might be
1681 *error
= ctx
->ops
->send_mfc_command(ctx
, &cmd
);
1682 if (*error
== -EAGAIN
)
1688 static ssize_t
spufs_mfc_write(struct file
*file
, const char __user
*buffer
,
1689 size_t size
, loff_t
*pos
)
1691 struct spu_context
*ctx
= file
->private_data
;
1692 struct mfc_dma_command cmd
;
1695 if (size
!= sizeof cmd
)
1699 if (copy_from_user(&cmd
, buffer
, sizeof cmd
))
1702 ret
= spufs_check_valid_dma(&cmd
);
1706 ret
= spu_acquire(ctx
);
1710 ret
= spufs_wait(ctx
->run_wq
, ctx
->state
== SPU_STATE_RUNNABLE
);
1714 if (file
->f_flags
& O_NONBLOCK
) {
1715 ret
= ctx
->ops
->send_mfc_command(ctx
, &cmd
);
1718 ret
= spufs_wait(ctx
->mfc_wq
,
1719 spu_send_mfc_command(ctx
, cmd
, &status
));
1729 ctx
->tagwait
|= 1 << cmd
.tag
;
1738 static unsigned int spufs_mfc_poll(struct file
*file
,poll_table
*wait
)
1740 struct spu_context
*ctx
= file
->private_data
;
1741 u32 free_elements
, tagstatus
;
1744 poll_wait(file
, &ctx
->mfc_wq
, wait
);
1747 * For now keep this uninterruptible and also ignore the rule
1748 * that poll should not sleep. Will be fixed later.
1750 mutex_lock(&ctx
->state_mutex
);
1751 ctx
->ops
->set_mfc_query(ctx
, ctx
->tagwait
, 2);
1752 free_elements
= ctx
->ops
->get_mfc_free_elements(ctx
);
1753 tagstatus
= ctx
->ops
->read_mfc_tagstatus(ctx
);
1757 if (free_elements
& 0xffff)
1758 mask
|= POLLOUT
| POLLWRNORM
;
1759 if (tagstatus
& ctx
->tagwait
)
1760 mask
|= POLLIN
| POLLRDNORM
;
1762 pr_debug("%s: free %d tagstatus %d tagwait %d\n", __func__
,
1763 free_elements
, tagstatus
, ctx
->tagwait
);
1768 static int spufs_mfc_flush(struct file
*file
, fl_owner_t id
)
1770 struct spu_context
*ctx
= file
->private_data
;
1773 ret
= spu_acquire(ctx
);
1777 /* this currently hangs */
1778 ret
= spufs_wait(ctx
->mfc_wq
,
1779 ctx
->ops
->set_mfc_query(ctx
, ctx
->tagwait
, 2));
1782 ret
= spufs_wait(ctx
->mfc_wq
,
1783 ctx
->ops
->read_mfc_tagstatus(ctx
) == ctx
->tagwait
);
1794 static int spufs_mfc_fsync(struct file
*file
, loff_t start
, loff_t end
, int datasync
)
1796 struct inode
*inode
= file_inode(file
);
1797 int err
= filemap_write_and_wait_range(inode
->i_mapping
, start
, end
);
1800 err
= spufs_mfc_flush(file
, NULL
);
1801 inode_unlock(inode
);
1806 static int spufs_mfc_fasync(int fd
, struct file
*file
, int on
)
1808 struct spu_context
*ctx
= file
->private_data
;
1810 return fasync_helper(fd
, file
, on
, &ctx
->mfc_fasync
);
1813 static const struct file_operations spufs_mfc_fops
= {
1814 .open
= spufs_mfc_open
,
1815 .release
= spufs_mfc_release
,
1816 .read
= spufs_mfc_read
,
1817 .write
= spufs_mfc_write
,
1818 .poll
= spufs_mfc_poll
,
1819 .flush
= spufs_mfc_flush
,
1820 .fsync
= spufs_mfc_fsync
,
1821 .fasync
= spufs_mfc_fasync
,
1822 .mmap
= spufs_mfc_mmap
,
1823 .llseek
= no_llseek
,
1826 static int spufs_npc_set(void *data
, u64 val
)
1828 struct spu_context
*ctx
= data
;
1831 ret
= spu_acquire(ctx
);
1834 ctx
->ops
->npc_write(ctx
, val
);
1840 static u64
spufs_npc_get(struct spu_context
*ctx
)
1842 return ctx
->ops
->npc_read(ctx
);
1844 DEFINE_SPUFS_ATTRIBUTE(spufs_npc_ops
, spufs_npc_get
, spufs_npc_set
,
1845 "0x%llx\n", SPU_ATTR_ACQUIRE
);
1847 static int spufs_decr_set(void *data
, u64 val
)
1849 struct spu_context
*ctx
= data
;
1850 struct spu_lscsa
*lscsa
= ctx
->csa
.lscsa
;
1853 ret
= spu_acquire_saved(ctx
);
1856 lscsa
->decr
.slot
[0] = (u32
) val
;
1857 spu_release_saved(ctx
);
1862 static u64
spufs_decr_get(struct spu_context
*ctx
)
1864 struct spu_lscsa
*lscsa
= ctx
->csa
.lscsa
;
1865 return lscsa
->decr
.slot
[0];
1867 DEFINE_SPUFS_ATTRIBUTE(spufs_decr_ops
, spufs_decr_get
, spufs_decr_set
,
1868 "0x%llx\n", SPU_ATTR_ACQUIRE_SAVED
);
1870 static int spufs_decr_status_set(void *data
, u64 val
)
1872 struct spu_context
*ctx
= data
;
1875 ret
= spu_acquire_saved(ctx
);
1879 ctx
->csa
.priv2
.mfc_control_RW
|= MFC_CNTL_DECREMENTER_RUNNING
;
1881 ctx
->csa
.priv2
.mfc_control_RW
&= ~MFC_CNTL_DECREMENTER_RUNNING
;
1882 spu_release_saved(ctx
);
1887 static u64
spufs_decr_status_get(struct spu_context
*ctx
)
1889 if (ctx
->csa
.priv2
.mfc_control_RW
& MFC_CNTL_DECREMENTER_RUNNING
)
1890 return SPU_DECR_STATUS_RUNNING
;
1894 DEFINE_SPUFS_ATTRIBUTE(spufs_decr_status_ops
, spufs_decr_status_get
,
1895 spufs_decr_status_set
, "0x%llx\n",
1896 SPU_ATTR_ACQUIRE_SAVED
);
1898 static int spufs_event_mask_set(void *data
, u64 val
)
1900 struct spu_context
*ctx
= data
;
1901 struct spu_lscsa
*lscsa
= ctx
->csa
.lscsa
;
1904 ret
= spu_acquire_saved(ctx
);
1907 lscsa
->event_mask
.slot
[0] = (u32
) val
;
1908 spu_release_saved(ctx
);
1913 static u64
spufs_event_mask_get(struct spu_context
*ctx
)
1915 struct spu_lscsa
*lscsa
= ctx
->csa
.lscsa
;
1916 return lscsa
->event_mask
.slot
[0];
1919 DEFINE_SPUFS_ATTRIBUTE(spufs_event_mask_ops
, spufs_event_mask_get
,
1920 spufs_event_mask_set
, "0x%llx\n",
1921 SPU_ATTR_ACQUIRE_SAVED
);
1923 static u64
spufs_event_status_get(struct spu_context
*ctx
)
1925 struct spu_state
*state
= &ctx
->csa
;
1927 stat
= state
->spu_chnlcnt_RW
[0];
1929 return state
->spu_chnldata_RW
[0];
1932 DEFINE_SPUFS_ATTRIBUTE(spufs_event_status_ops
, spufs_event_status_get
,
1933 NULL
, "0x%llx\n", SPU_ATTR_ACQUIRE_SAVED
)
1935 static int spufs_srr0_set(void *data
, u64 val
)
1937 struct spu_context
*ctx
= data
;
1938 struct spu_lscsa
*lscsa
= ctx
->csa
.lscsa
;
1941 ret
= spu_acquire_saved(ctx
);
1944 lscsa
->srr0
.slot
[0] = (u32
) val
;
1945 spu_release_saved(ctx
);
1950 static u64
spufs_srr0_get(struct spu_context
*ctx
)
1952 struct spu_lscsa
*lscsa
= ctx
->csa
.lscsa
;
1953 return lscsa
->srr0
.slot
[0];
1955 DEFINE_SPUFS_ATTRIBUTE(spufs_srr0_ops
, spufs_srr0_get
, spufs_srr0_set
,
1956 "0x%llx\n", SPU_ATTR_ACQUIRE_SAVED
)
1958 static u64
spufs_id_get(struct spu_context
*ctx
)
1962 if (ctx
->state
== SPU_STATE_RUNNABLE
)
1963 num
= ctx
->spu
->number
;
1965 num
= (unsigned int)-1;
1969 DEFINE_SPUFS_ATTRIBUTE(spufs_id_ops
, spufs_id_get
, NULL
, "0x%llx\n",
1972 static u64
spufs_object_id_get(struct spu_context
*ctx
)
1974 /* FIXME: Should there really be no locking here? */
1975 return ctx
->object_id
;
1978 static int spufs_object_id_set(void *data
, u64 id
)
1980 struct spu_context
*ctx
= data
;
1981 ctx
->object_id
= id
;
1986 DEFINE_SPUFS_ATTRIBUTE(spufs_object_id_ops
, spufs_object_id_get
,
1987 spufs_object_id_set
, "0x%llx\n", SPU_ATTR_NOACQUIRE
);
1989 static u64
spufs_lslr_get(struct spu_context
*ctx
)
1991 return ctx
->csa
.priv2
.spu_lslr_RW
;
1993 DEFINE_SPUFS_ATTRIBUTE(spufs_lslr_ops
, spufs_lslr_get
, NULL
, "0x%llx\n",
1994 SPU_ATTR_ACQUIRE_SAVED
);
1996 static int spufs_info_open(struct inode
*inode
, struct file
*file
)
1998 struct spufs_inode_info
*i
= SPUFS_I(inode
);
1999 struct spu_context
*ctx
= i
->i_ctx
;
2000 file
->private_data
= ctx
;
2004 static int spufs_caps_show(struct seq_file
*s
, void *private)
2006 struct spu_context
*ctx
= s
->private;
2008 if (!(ctx
->flags
& SPU_CREATE_NOSCHED
))
2009 seq_puts(s
, "sched\n");
2010 if (!(ctx
->flags
& SPU_CREATE_ISOLATE
))
2011 seq_puts(s
, "step\n");
2015 static int spufs_caps_open(struct inode
*inode
, struct file
*file
)
2017 return single_open(file
, spufs_caps_show
, SPUFS_I(inode
)->i_ctx
);
2020 static const struct file_operations spufs_caps_fops
= {
2021 .open
= spufs_caps_open
,
2023 .llseek
= seq_lseek
,
2024 .release
= single_release
,
2027 static ssize_t
__spufs_mbox_info_read(struct spu_context
*ctx
,
2028 char __user
*buf
, size_t len
, loff_t
*pos
)
2032 /* EOF if there's no entry in the mbox */
2033 if (!(ctx
->csa
.prob
.mb_stat_R
& 0x0000ff))
2036 data
= ctx
->csa
.prob
.pu_mb_R
;
2038 return simple_read_from_buffer(buf
, len
, pos
, &data
, sizeof data
);
2041 static ssize_t
spufs_mbox_info_read(struct file
*file
, char __user
*buf
,
2042 size_t len
, loff_t
*pos
)
2045 struct spu_context
*ctx
= file
->private_data
;
2047 if (!access_ok(VERIFY_WRITE
, buf
, len
))
2050 ret
= spu_acquire_saved(ctx
);
2053 spin_lock(&ctx
->csa
.register_lock
);
2054 ret
= __spufs_mbox_info_read(ctx
, buf
, len
, pos
);
2055 spin_unlock(&ctx
->csa
.register_lock
);
2056 spu_release_saved(ctx
);
2061 static const struct file_operations spufs_mbox_info_fops
= {
2062 .open
= spufs_info_open
,
2063 .read
= spufs_mbox_info_read
,
2064 .llseek
= generic_file_llseek
,
2067 static ssize_t
__spufs_ibox_info_read(struct spu_context
*ctx
,
2068 char __user
*buf
, size_t len
, loff_t
*pos
)
2072 /* EOF if there's no entry in the ibox */
2073 if (!(ctx
->csa
.prob
.mb_stat_R
& 0xff0000))
2076 data
= ctx
->csa
.priv2
.puint_mb_R
;
2078 return simple_read_from_buffer(buf
, len
, pos
, &data
, sizeof data
);
2081 static ssize_t
spufs_ibox_info_read(struct file
*file
, char __user
*buf
,
2082 size_t len
, loff_t
*pos
)
2084 struct spu_context
*ctx
= file
->private_data
;
2087 if (!access_ok(VERIFY_WRITE
, buf
, len
))
2090 ret
= spu_acquire_saved(ctx
);
2093 spin_lock(&ctx
->csa
.register_lock
);
2094 ret
= __spufs_ibox_info_read(ctx
, buf
, len
, pos
);
2095 spin_unlock(&ctx
->csa
.register_lock
);
2096 spu_release_saved(ctx
);
2101 static const struct file_operations spufs_ibox_info_fops
= {
2102 .open
= spufs_info_open
,
2103 .read
= spufs_ibox_info_read
,
2104 .llseek
= generic_file_llseek
,
2107 static ssize_t
__spufs_wbox_info_read(struct spu_context
*ctx
,
2108 char __user
*buf
, size_t len
, loff_t
*pos
)
2114 wbox_stat
= ctx
->csa
.prob
.mb_stat_R
;
2115 cnt
= 4 - ((wbox_stat
& 0x00ff00) >> 8);
2116 for (i
= 0; i
< cnt
; i
++) {
2117 data
[i
] = ctx
->csa
.spu_mailbox_data
[i
];
2120 return simple_read_from_buffer(buf
, len
, pos
, &data
,
2124 static ssize_t
spufs_wbox_info_read(struct file
*file
, char __user
*buf
,
2125 size_t len
, loff_t
*pos
)
2127 struct spu_context
*ctx
= file
->private_data
;
2130 if (!access_ok(VERIFY_WRITE
, buf
, len
))
2133 ret
= spu_acquire_saved(ctx
);
2136 spin_lock(&ctx
->csa
.register_lock
);
2137 ret
= __spufs_wbox_info_read(ctx
, buf
, len
, pos
);
2138 spin_unlock(&ctx
->csa
.register_lock
);
2139 spu_release_saved(ctx
);
2144 static const struct file_operations spufs_wbox_info_fops
= {
2145 .open
= spufs_info_open
,
2146 .read
= spufs_wbox_info_read
,
2147 .llseek
= generic_file_llseek
,
2150 static ssize_t
__spufs_dma_info_read(struct spu_context
*ctx
,
2151 char __user
*buf
, size_t len
, loff_t
*pos
)
2153 struct spu_dma_info info
;
2154 struct mfc_cq_sr
*qp
, *spuqp
;
2157 info
.dma_info_type
= ctx
->csa
.priv2
.spu_tag_status_query_RW
;
2158 info
.dma_info_mask
= ctx
->csa
.lscsa
->tag_mask
.slot
[0];
2159 info
.dma_info_status
= ctx
->csa
.spu_chnldata_RW
[24];
2160 info
.dma_info_stall_and_notify
= ctx
->csa
.spu_chnldata_RW
[25];
2161 info
.dma_info_atomic_command_status
= ctx
->csa
.spu_chnldata_RW
[27];
2162 for (i
= 0; i
< 16; i
++) {
2163 qp
= &info
.dma_info_command_data
[i
];
2164 spuqp
= &ctx
->csa
.priv2
.spuq
[i
];
2166 qp
->mfc_cq_data0_RW
= spuqp
->mfc_cq_data0_RW
;
2167 qp
->mfc_cq_data1_RW
= spuqp
->mfc_cq_data1_RW
;
2168 qp
->mfc_cq_data2_RW
= spuqp
->mfc_cq_data2_RW
;
2169 qp
->mfc_cq_data3_RW
= spuqp
->mfc_cq_data3_RW
;
2172 return simple_read_from_buffer(buf
, len
, pos
, &info
,
2176 static ssize_t
spufs_dma_info_read(struct file
*file
, char __user
*buf
,
2177 size_t len
, loff_t
*pos
)
2179 struct spu_context
*ctx
= file
->private_data
;
2182 if (!access_ok(VERIFY_WRITE
, buf
, len
))
2185 ret
= spu_acquire_saved(ctx
);
2188 spin_lock(&ctx
->csa
.register_lock
);
2189 ret
= __spufs_dma_info_read(ctx
, buf
, len
, pos
);
2190 spin_unlock(&ctx
->csa
.register_lock
);
2191 spu_release_saved(ctx
);
2196 static const struct file_operations spufs_dma_info_fops
= {
2197 .open
= spufs_info_open
,
2198 .read
= spufs_dma_info_read
,
2199 .llseek
= no_llseek
,
2202 static ssize_t
__spufs_proxydma_info_read(struct spu_context
*ctx
,
2203 char __user
*buf
, size_t len
, loff_t
*pos
)
2205 struct spu_proxydma_info info
;
2206 struct mfc_cq_sr
*qp
, *puqp
;
2207 int ret
= sizeof info
;
2213 if (!access_ok(VERIFY_WRITE
, buf
, len
))
2216 info
.proxydma_info_type
= ctx
->csa
.prob
.dma_querytype_RW
;
2217 info
.proxydma_info_mask
= ctx
->csa
.prob
.dma_querymask_RW
;
2218 info
.proxydma_info_status
= ctx
->csa
.prob
.dma_tagstatus_R
;
2219 for (i
= 0; i
< 8; i
++) {
2220 qp
= &info
.proxydma_info_command_data
[i
];
2221 puqp
= &ctx
->csa
.priv2
.puq
[i
];
2223 qp
->mfc_cq_data0_RW
= puqp
->mfc_cq_data0_RW
;
2224 qp
->mfc_cq_data1_RW
= puqp
->mfc_cq_data1_RW
;
2225 qp
->mfc_cq_data2_RW
= puqp
->mfc_cq_data2_RW
;
2226 qp
->mfc_cq_data3_RW
= puqp
->mfc_cq_data3_RW
;
2229 return simple_read_from_buffer(buf
, len
, pos
, &info
,
2233 static ssize_t
spufs_proxydma_info_read(struct file
*file
, char __user
*buf
,
2234 size_t len
, loff_t
*pos
)
2236 struct spu_context
*ctx
= file
->private_data
;
2239 ret
= spu_acquire_saved(ctx
);
2242 spin_lock(&ctx
->csa
.register_lock
);
2243 ret
= __spufs_proxydma_info_read(ctx
, buf
, len
, pos
);
2244 spin_unlock(&ctx
->csa
.register_lock
);
2245 spu_release_saved(ctx
);
2250 static const struct file_operations spufs_proxydma_info_fops
= {
2251 .open
= spufs_info_open
,
2252 .read
= spufs_proxydma_info_read
,
2253 .llseek
= no_llseek
,
2256 static int spufs_show_tid(struct seq_file
*s
, void *private)
2258 struct spu_context
*ctx
= s
->private;
2260 seq_printf(s
, "%d\n", ctx
->tid
);
2264 static int spufs_tid_open(struct inode
*inode
, struct file
*file
)
2266 return single_open(file
, spufs_show_tid
, SPUFS_I(inode
)->i_ctx
);
2269 static const struct file_operations spufs_tid_fops
= {
2270 .open
= spufs_tid_open
,
2272 .llseek
= seq_lseek
,
2273 .release
= single_release
,
2276 static const char *ctx_state_names
[] = {
2277 "user", "system", "iowait", "loaded"
2280 static unsigned long long spufs_acct_time(struct spu_context
*ctx
,
2281 enum spu_utilization_state state
)
2283 unsigned long long time
= ctx
->stats
.times
[state
];
2286 * In general, utilization statistics are updated by the controlling
2287 * thread as the spu context moves through various well defined
2288 * state transitions, but if the context is lazily loaded its
2289 * utilization statistics are not updated as the controlling thread
2290 * is not tightly coupled with the execution of the spu context. We
2291 * calculate and apply the time delta from the last recorded state
2292 * of the spu context.
2294 if (ctx
->spu
&& ctx
->stats
.util_state
== state
) {
2295 time
+= ktime_get_ns() - ctx
->stats
.tstamp
;
2298 return time
/ NSEC_PER_MSEC
;
2301 static unsigned long long spufs_slb_flts(struct spu_context
*ctx
)
2303 unsigned long long slb_flts
= ctx
->stats
.slb_flt
;
2305 if (ctx
->state
== SPU_STATE_RUNNABLE
) {
2306 slb_flts
+= (ctx
->spu
->stats
.slb_flt
-
2307 ctx
->stats
.slb_flt_base
);
2313 static unsigned long long spufs_class2_intrs(struct spu_context
*ctx
)
2315 unsigned long long class2_intrs
= ctx
->stats
.class2_intr
;
2317 if (ctx
->state
== SPU_STATE_RUNNABLE
) {
2318 class2_intrs
+= (ctx
->spu
->stats
.class2_intr
-
2319 ctx
->stats
.class2_intr_base
);
2322 return class2_intrs
;
2326 static int spufs_show_stat(struct seq_file
*s
, void *private)
2328 struct spu_context
*ctx
= s
->private;
2331 ret
= spu_acquire(ctx
);
2335 seq_printf(s
, "%s %llu %llu %llu %llu "
2336 "%llu %llu %llu %llu %llu %llu %llu %llu\n",
2337 ctx_state_names
[ctx
->stats
.util_state
],
2338 spufs_acct_time(ctx
, SPU_UTIL_USER
),
2339 spufs_acct_time(ctx
, SPU_UTIL_SYSTEM
),
2340 spufs_acct_time(ctx
, SPU_UTIL_IOWAIT
),
2341 spufs_acct_time(ctx
, SPU_UTIL_IDLE_LOADED
),
2342 ctx
->stats
.vol_ctx_switch
,
2343 ctx
->stats
.invol_ctx_switch
,
2344 spufs_slb_flts(ctx
),
2345 ctx
->stats
.hash_flt
,
2348 spufs_class2_intrs(ctx
),
2349 ctx
->stats
.libassist
);
2354 static int spufs_stat_open(struct inode
*inode
, struct file
*file
)
2356 return single_open(file
, spufs_show_stat
, SPUFS_I(inode
)->i_ctx
);
2359 static const struct file_operations spufs_stat_fops
= {
2360 .open
= spufs_stat_open
,
2362 .llseek
= seq_lseek
,
2363 .release
= single_release
,
2366 static inline int spufs_switch_log_used(struct spu_context
*ctx
)
2368 return (ctx
->switch_log
->head
- ctx
->switch_log
->tail
) %
2372 static inline int spufs_switch_log_avail(struct spu_context
*ctx
)
2374 return SWITCH_LOG_BUFSIZE
- spufs_switch_log_used(ctx
);
2377 static int spufs_switch_log_open(struct inode
*inode
, struct file
*file
)
2379 struct spu_context
*ctx
= SPUFS_I(inode
)->i_ctx
;
2382 rc
= spu_acquire(ctx
);
2386 if (ctx
->switch_log
) {
2391 ctx
->switch_log
= kmalloc(sizeof(struct switch_log
) +
2392 SWITCH_LOG_BUFSIZE
* sizeof(struct switch_log_entry
),
2395 if (!ctx
->switch_log
) {
2400 ctx
->switch_log
->head
= ctx
->switch_log
->tail
= 0;
2401 init_waitqueue_head(&ctx
->switch_log
->wait
);
2409 static int spufs_switch_log_release(struct inode
*inode
, struct file
*file
)
2411 struct spu_context
*ctx
= SPUFS_I(inode
)->i_ctx
;
2414 rc
= spu_acquire(ctx
);
2418 kfree(ctx
->switch_log
);
2419 ctx
->switch_log
= NULL
;
2425 static int switch_log_sprint(struct spu_context
*ctx
, char *tbuf
, int n
)
2427 struct switch_log_entry
*p
;
2429 p
= ctx
->switch_log
->log
+ ctx
->switch_log
->tail
% SWITCH_LOG_BUFSIZE
;
2431 return snprintf(tbuf
, n
, "%u.%09u %d %u %u %llu\n",
2432 (unsigned int) p
->tstamp
.tv_sec
,
2433 (unsigned int) p
->tstamp
.tv_nsec
,
2435 (unsigned int) p
->type
,
2436 (unsigned int) p
->val
,
2437 (unsigned long long) p
->timebase
);
2440 static ssize_t
spufs_switch_log_read(struct file
*file
, char __user
*buf
,
2441 size_t len
, loff_t
*ppos
)
2443 struct inode
*inode
= file_inode(file
);
2444 struct spu_context
*ctx
= SPUFS_I(inode
)->i_ctx
;
2445 int error
= 0, cnt
= 0;
2450 error
= spu_acquire(ctx
);
2458 if (spufs_switch_log_used(ctx
) == 0) {
2460 /* If there's data ready to go, we can
2461 * just return straight away */
2464 } else if (file
->f_flags
& O_NONBLOCK
) {
2469 /* spufs_wait will drop the mutex and
2470 * re-acquire, but since we're in read(), the
2471 * file cannot be _released (and so
2472 * ctx->switch_log is stable).
2474 error
= spufs_wait(ctx
->switch_log
->wait
,
2475 spufs_switch_log_used(ctx
) > 0);
2477 /* On error, spufs_wait returns without the
2478 * state mutex held */
2482 /* We may have had entries read from underneath
2483 * us while we dropped the mutex in spufs_wait,
2485 if (spufs_switch_log_used(ctx
) == 0)
2490 width
= switch_log_sprint(ctx
, tbuf
, sizeof(tbuf
));
2492 ctx
->switch_log
->tail
=
2493 (ctx
->switch_log
->tail
+ 1) %
2496 /* If the record is greater than space available return
2497 * partial buffer (so far) */
2500 error
= copy_to_user(buf
+ cnt
, tbuf
, width
);
2508 return cnt
== 0 ? error
: cnt
;
2511 static unsigned int spufs_switch_log_poll(struct file
*file
, poll_table
*wait
)
2513 struct inode
*inode
= file_inode(file
);
2514 struct spu_context
*ctx
= SPUFS_I(inode
)->i_ctx
;
2515 unsigned int mask
= 0;
2518 poll_wait(file
, &ctx
->switch_log
->wait
, wait
);
2520 rc
= spu_acquire(ctx
);
2524 if (spufs_switch_log_used(ctx
) > 0)
2532 static const struct file_operations spufs_switch_log_fops
= {
2533 .open
= spufs_switch_log_open
,
2534 .read
= spufs_switch_log_read
,
2535 .poll
= spufs_switch_log_poll
,
2536 .release
= spufs_switch_log_release
,
2537 .llseek
= no_llseek
,
2541 * Log a context switch event to a switch log reader.
2543 * Must be called with ctx->state_mutex held.
2545 void spu_switch_log_notify(struct spu
*spu
, struct spu_context
*ctx
,
2548 if (!ctx
->switch_log
)
2551 if (spufs_switch_log_avail(ctx
) > 1) {
2552 struct switch_log_entry
*p
;
2554 p
= ctx
->switch_log
->log
+ ctx
->switch_log
->head
;
2555 ktime_get_ts(&p
->tstamp
);
2556 p
->timebase
= get_tb();
2557 p
->spu_id
= spu
? spu
->number
: -1;
2561 ctx
->switch_log
->head
=
2562 (ctx
->switch_log
->head
+ 1) % SWITCH_LOG_BUFSIZE
;
2565 wake_up(&ctx
->switch_log
->wait
);
2568 static int spufs_show_ctx(struct seq_file
*s
, void *private)
2570 struct spu_context
*ctx
= s
->private;
2573 mutex_lock(&ctx
->state_mutex
);
2575 struct spu
*spu
= ctx
->spu
;
2576 struct spu_priv2 __iomem
*priv2
= spu
->priv2
;
2578 spin_lock_irq(&spu
->register_lock
);
2579 mfc_control_RW
= in_be64(&priv2
->mfc_control_RW
);
2580 spin_unlock_irq(&spu
->register_lock
);
2582 struct spu_state
*csa
= &ctx
->csa
;
2584 mfc_control_RW
= csa
->priv2
.mfc_control_RW
;
2587 seq_printf(s
, "%c flgs(%lx) sflgs(%lx) pri(%d) ts(%d) spu(%02d)"
2588 " %c %llx %llx %llx %llx %x %x\n",
2589 ctx
->state
== SPU_STATE_SAVED
? 'S' : 'R',
2594 ctx
->spu
? ctx
->spu
->number
: -1,
2595 !list_empty(&ctx
->rq
) ? 'q' : ' ',
2596 ctx
->csa
.class_0_pending
,
2597 ctx
->csa
.class_0_dar
,
2598 ctx
->csa
.class_1_dsisr
,
2600 ctx
->ops
->runcntl_read(ctx
),
2601 ctx
->ops
->status_read(ctx
));
2603 mutex_unlock(&ctx
->state_mutex
);
2608 static int spufs_ctx_open(struct inode
*inode
, struct file
*file
)
2610 return single_open(file
, spufs_show_ctx
, SPUFS_I(inode
)->i_ctx
);
2613 static const struct file_operations spufs_ctx_fops
= {
2614 .open
= spufs_ctx_open
,
2616 .llseek
= seq_lseek
,
2617 .release
= single_release
,
2620 const struct spufs_tree_descr spufs_dir_contents
[] = {
2621 { "capabilities", &spufs_caps_fops
, 0444, },
2622 { "mem", &spufs_mem_fops
, 0666, LS_SIZE
, },
2623 { "regs", &spufs_regs_fops
, 0666, sizeof(struct spu_reg128
[128]), },
2624 { "mbox", &spufs_mbox_fops
, 0444, },
2625 { "ibox", &spufs_ibox_fops
, 0444, },
2626 { "wbox", &spufs_wbox_fops
, 0222, },
2627 { "mbox_stat", &spufs_mbox_stat_fops
, 0444, sizeof(u32
), },
2628 { "ibox_stat", &spufs_ibox_stat_fops
, 0444, sizeof(u32
), },
2629 { "wbox_stat", &spufs_wbox_stat_fops
, 0444, sizeof(u32
), },
2630 { "signal1", &spufs_signal1_fops
, 0666, },
2631 { "signal2", &spufs_signal2_fops
, 0666, },
2632 { "signal1_type", &spufs_signal1_type
, 0666, },
2633 { "signal2_type", &spufs_signal2_type
, 0666, },
2634 { "cntl", &spufs_cntl_fops
, 0666, },
2635 { "fpcr", &spufs_fpcr_fops
, 0666, sizeof(struct spu_reg128
), },
2636 { "lslr", &spufs_lslr_ops
, 0444, },
2637 { "mfc", &spufs_mfc_fops
, 0666, },
2638 { "mss", &spufs_mss_fops
, 0666, },
2639 { "npc", &spufs_npc_ops
, 0666, },
2640 { "srr0", &spufs_srr0_ops
, 0666, },
2641 { "decr", &spufs_decr_ops
, 0666, },
2642 { "decr_status", &spufs_decr_status_ops
, 0666, },
2643 { "event_mask", &spufs_event_mask_ops
, 0666, },
2644 { "event_status", &spufs_event_status_ops
, 0444, },
2645 { "psmap", &spufs_psmap_fops
, 0666, SPUFS_PS_MAP_SIZE
, },
2646 { "phys-id", &spufs_id_ops
, 0666, },
2647 { "object-id", &spufs_object_id_ops
, 0666, },
2648 { "mbox_info", &spufs_mbox_info_fops
, 0444, sizeof(u32
), },
2649 { "ibox_info", &spufs_ibox_info_fops
, 0444, sizeof(u32
), },
2650 { "wbox_info", &spufs_wbox_info_fops
, 0444, sizeof(u32
), },
2651 { "dma_info", &spufs_dma_info_fops
, 0444,
2652 sizeof(struct spu_dma_info
), },
2653 { "proxydma_info", &spufs_proxydma_info_fops
, 0444,
2654 sizeof(struct spu_proxydma_info
)},
2655 { "tid", &spufs_tid_fops
, 0444, },
2656 { "stat", &spufs_stat_fops
, 0444, },
2657 { "switch_log", &spufs_switch_log_fops
, 0444 },
2661 const struct spufs_tree_descr spufs_dir_nosched_contents
[] = {
2662 { "capabilities", &spufs_caps_fops
, 0444, },
2663 { "mem", &spufs_mem_fops
, 0666, LS_SIZE
, },
2664 { "mbox", &spufs_mbox_fops
, 0444, },
2665 { "ibox", &spufs_ibox_fops
, 0444, },
2666 { "wbox", &spufs_wbox_fops
, 0222, },
2667 { "mbox_stat", &spufs_mbox_stat_fops
, 0444, sizeof(u32
), },
2668 { "ibox_stat", &spufs_ibox_stat_fops
, 0444, sizeof(u32
), },
2669 { "wbox_stat", &spufs_wbox_stat_fops
, 0444, sizeof(u32
), },
2670 { "signal1", &spufs_signal1_nosched_fops
, 0222, },
2671 { "signal2", &spufs_signal2_nosched_fops
, 0222, },
2672 { "signal1_type", &spufs_signal1_type
, 0666, },
2673 { "signal2_type", &spufs_signal2_type
, 0666, },
2674 { "mss", &spufs_mss_fops
, 0666, },
2675 { "mfc", &spufs_mfc_fops
, 0666, },
2676 { "cntl", &spufs_cntl_fops
, 0666, },
2677 { "npc", &spufs_npc_ops
, 0666, },
2678 { "psmap", &spufs_psmap_fops
, 0666, SPUFS_PS_MAP_SIZE
, },
2679 { "phys-id", &spufs_id_ops
, 0666, },
2680 { "object-id", &spufs_object_id_ops
, 0666, },
2681 { "tid", &spufs_tid_fops
, 0444, },
2682 { "stat", &spufs_stat_fops
, 0444, },
2686 const struct spufs_tree_descr spufs_dir_debug_contents
[] = {
2687 { ".ctx", &spufs_ctx_fops
, 0444, },
2691 const struct spufs_coredump_reader spufs_coredump_read
[] = {
2692 { "regs", __spufs_regs_read
, NULL
, sizeof(struct spu_reg128
[128])},
2693 { "fpcr", __spufs_fpcr_read
, NULL
, sizeof(struct spu_reg128
) },
2694 { "lslr", NULL
, spufs_lslr_get
, 19 },
2695 { "decr", NULL
, spufs_decr_get
, 19 },
2696 { "decr_status", NULL
, spufs_decr_status_get
, 19 },
2697 { "mem", __spufs_mem_read
, NULL
, LS_SIZE
, },
2698 { "signal1", __spufs_signal1_read
, NULL
, sizeof(u32
) },
2699 { "signal1_type", NULL
, spufs_signal1_type_get
, 19 },
2700 { "signal2", __spufs_signal2_read
, NULL
, sizeof(u32
) },
2701 { "signal2_type", NULL
, spufs_signal2_type_get
, 19 },
2702 { "event_mask", NULL
, spufs_event_mask_get
, 19 },
2703 { "event_status", NULL
, spufs_event_status_get
, 19 },
2704 { "mbox_info", __spufs_mbox_info_read
, NULL
, sizeof(u32
) },
2705 { "ibox_info", __spufs_ibox_info_read
, NULL
, sizeof(u32
) },
2706 { "wbox_info", __spufs_wbox_info_read
, NULL
, 4 * sizeof(u32
)},
2707 { "dma_info", __spufs_dma_info_read
, NULL
, sizeof(struct spu_dma_info
)},
2708 { "proxydma_info", __spufs_proxydma_info_read
,
2709 NULL
, sizeof(struct spu_proxydma_info
)},
2710 { "object-id", NULL
, spufs_object_id_get
, 19 },
2711 { "npc", NULL
, spufs_npc_get
, 19 },