27 #include <linux/export.h>
29 #include <linux/poll.h>
30 #include <linux/ptrace.h>
32 #include <linux/slab.h>
37 #include <asm/spu_info.h>
38 #include <asm/uaccess.h>
43 #define SPUFS_MMAP_4K (PAGE_SIZE == 0x1000)
57 int (*
get)(
void *,
u64 *),
int (*
set)(
void *,
u64),
76 static int spufs_attr_release(
struct inode *inode,
struct file *file)
82 static ssize_t spufs_attr_read(
struct file *file,
char __user *
buf,
83 size_t len, loff_t *ppos)
101 ret = attr->
get(attr->
data, &val);
106 attr->
fmt, (
unsigned long long)val);
115 static ssize_t spufs_attr_write(
struct file *file,
const char __user *buf,
116 size_t len, loff_t *ppos)
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 .owner = THIS_MODULE, \
153 .open = __fops ## _open, \
154 .release = spufs_attr_release, \
155 .read = spufs_attr_read, \
156 .write = spufs_attr_write, \
157 .llseek = generic_file_llseek, \
162 spufs_mem_open(
struct inode *inode,
struct file *file)
176 spufs_mem_release(
struct inode *inode,
struct file *file)
190 size_t size, loff_t *
pos)
198 spufs_mem_read(
struct file *file,
char __user *buffer,
199 size_t size, loff_t *pos)
204 ret = spu_acquire(ctx);
207 ret = __spufs_mem_read(ctx, buffer, size, pos);
214 spufs_mem_write(
struct file *file,
const char __user *buffer,
215 size_t size, loff_t *ppos)
225 ret = spu_acquire(ctx);
229 local_store = ctx->
ops->get_ls(ctx);
237 spufs_mem_mmap_fault(
struct vm_area_struct *vma,
struct vm_fault *vmf)
240 unsigned long address = (
unsigned long)vmf->virtual_address;
241 unsigned long pfn,
offset;
243 #ifdef CONFIG_SPU_FS_64K_LS
244 struct spu_state *
csa = &ctx->
csa;
251 BUG_ON(
csa->use_big_pages != (psize == MMU_PAGE_64K));
254 if (
csa->use_big_pages) {
256 address &= ~0xfffful;
262 return VM_FAULT_SIGBUS;
264 pr_debug(
"spufs_mem_mmap_fault address=0x%lx, offset=0x%lx\n",
267 if (spu_acquire(ctx))
268 return VM_FAULT_NOPAGE;
281 return VM_FAULT_NOPAGE;
285 unsigned long address,
286 void *buf,
int len,
int write)
292 if (write && !(vma->
vm_flags & VM_WRITE))
294 if (spu_acquire(ctx))
296 if ((offset + len) > vma->
vm_end)
298 local_store = ctx->
ops->get_ls(ctx);
307 static const struct vm_operations_struct spufs_mem_mmap_vmops = {
308 .fault = spufs_mem_mmap_fault,
309 .access = spufs_mem_mmap_access,
312 static int spufs_mem_mmap(
struct file *file,
struct vm_area_struct *vma)
314 #ifdef CONFIG_SPU_FS_64K_LS
316 struct spu_state *csa = &ctx->
csa;
319 if (csa->use_big_pages) {
320 pr_debug(
"spufs_mem_mmap 64K, start=0x%lx, end=0x%lx,"
336 vma->
vm_ops = &spufs_mem_mmap_vmops;
340 #ifdef CONFIG_SPU_FS_64K_LS
341 static unsigned long spufs_get_unmapped_area(
struct file *file,
342 unsigned long addr,
unsigned long len,
unsigned long pgoff,
346 struct spu_state *csa = &ctx->
csa;
349 if (!csa->use_big_pages)
350 return current->mm->get_unmapped_area(file, addr, len,
360 .open = spufs_mem_open,
361 .release = spufs_mem_release,
362 .read = spufs_mem_read,
363 .write = spufs_mem_write,
365 .mmap = spufs_mem_mmap,
366 #ifdef CONFIG_SPU_FS_64K_LS
367 .get_unmapped_area = spufs_get_unmapped_area,
372 struct vm_fault *vmf,
373 unsigned long ps_offs,
374 unsigned long ps_size)
377 unsigned long area, offset = vmf->pgoff <<
PAGE_SHIFT;
382 if (offset >= ps_size)
383 return VM_FAULT_SIGBUS;
385 if (fatal_signal_pending(
current))
386 return VM_FAULT_SIGBUS;
403 if (spu_acquire(ctx))
413 area = ctx->
spu->problem_phys + ps_offs;
424 return VM_FAULT_NOPAGE;
429 struct vm_fault *vmf)
434 static const struct vm_operations_struct spufs_cntl_mmap_vmops = {
435 .fault = spufs_cntl_mmap_fault,
449 vma->
vm_ops = &spufs_cntl_mmap_vmops;
453 #define spufs_cntl_mmap NULL
456 static int spufs_cntl_get(
void *
data,
u64 *val)
461 ret = spu_acquire(ctx);
464 *val = ctx->
ops->status_read(ctx);
470 static int spufs_cntl_set(
void *
data,
u64 val)
475 ret = spu_acquire(ctx);
478 ctx->
ops->runcntl_write(ctx, val);
484 static int spufs_cntl_open(
struct inode *inode,
struct file *file)
495 spufs_cntl_set,
"0x%08lx");
499 spufs_cntl_release(
struct inode *inode,
struct file *file)
514 .open = spufs_cntl_open,
515 .release = spufs_cntl_release,
523 spufs_regs_open(
struct inode *inode,
struct file *file)
531 __spufs_regs_read(
struct spu_context *ctx,
char __user *buffer,
532 size_t size, loff_t *pos)
534 struct spu_lscsa *lscsa = ctx->
csa.lscsa;
536 lscsa->gprs,
sizeof lscsa->gprs);
540 spufs_regs_read(
struct file *file,
char __user *buffer,
541 size_t size, loff_t *pos)
548 if (*pos >=
sizeof(ctx->
csa.lscsa->gprs))
554 ret = __spufs_regs_read(ctx, buffer, size, pos);
560 spufs_regs_write(
struct file *file,
const char __user *buffer,
561 size_t size, loff_t *pos)
564 struct spu_lscsa *lscsa = ctx->
csa.lscsa;
567 if (*pos >=
sizeof(lscsa->gprs))
582 .open = spufs_regs_open,
583 .read = spufs_regs_read,
584 .write = spufs_regs_write,
589 __spufs_fpcr_read(
struct spu_context *ctx,
char __user * buffer,
590 size_t size, loff_t * pos)
592 struct spu_lscsa *lscsa = ctx->
csa.lscsa;
594 &lscsa->fpcr,
sizeof(lscsa->fpcr));
598 spufs_fpcr_read(
struct file *file,
char __user * buffer,
599 size_t size, loff_t * pos)
607 ret = __spufs_fpcr_read(ctx, buffer, size, pos);
613 spufs_fpcr_write(
struct file *file,
const char __user * buffer,
614 size_t size, loff_t * pos)
617 struct spu_lscsa *lscsa = ctx->
csa.lscsa;
620 if (*pos >=
sizeof(lscsa->fpcr))
635 .open = spufs_regs_open,
636 .read = spufs_fpcr_read,
637 .write = spufs_fpcr_write,
642 static int spufs_pipe_open(
struct inode *inode,
struct file *file)
658 static ssize_t spufs_mbox_read(
struct file *file,
char __user *buf,
659 size_t len, loff_t *pos)
671 udata = (
void __user *)buf;
673 count = spu_acquire(ctx);
677 for (count = 0; (count + 4) <= len; count += 4, udata++) {
679 ret = ctx->
ops->mbox_read(ctx, &mbox_data);
704 .open = spufs_pipe_open,
705 .read = spufs_mbox_read,
709 static ssize_t spufs_mbox_stat_read(
struct file *file,
char __user *buf,
710 size_t len, loff_t *pos)
719 ret = spu_acquire(ctx);
723 mbox_stat = ctx->
ops->mbox_stat_read(ctx) & 0xff;
734 .open = spufs_pipe_open,
735 .read = spufs_mbox_stat_read,
742 return ctx->
ops->ibox_read(ctx, data);
745 static int spufs_ibox_fasync(
int fd,
struct file *file,
int on)
776 static ssize_t spufs_ibox_read(
struct file *file,
char __user *buf,
777 size_t len, loff_t *pos)
789 udata = (
void __user *)buf;
791 count = spu_acquire(ctx);
813 for (count = 4, udata++; (count + 4) <= len; count += 4, udata++) {
815 ret = ctx->
ops->ibox_read(ctx, &ibox_data);
834 static unsigned int spufs_ibox_poll(
struct file *file,
poll_table *
wait)
839 poll_wait(file, &ctx->
ibox_wq, wait);
853 .open = spufs_pipe_open,
854 .read = spufs_ibox_read,
855 .poll = spufs_ibox_poll,
856 .fasync = spufs_ibox_fasync,
860 static ssize_t spufs_ibox_stat_read(
struct file *file,
char __user *buf,
861 size_t len, loff_t *pos)
870 ret = spu_acquire(ctx);
873 ibox_stat = (ctx->
ops->mbox_stat_read(ctx) >> 16) & 0xff;
883 .open = spufs_pipe_open,
884 .read = spufs_ibox_stat_read,
891 return ctx->
ops->wbox_write(ctx, data);
894 static int spufs_wbox_fasync(
int fd,
struct file *file,
int on)
928 static ssize_t spufs_wbox_write(
struct file *file,
const char __user *buf,
929 size_t len, loff_t *pos)
938 udata = (
void __user *)buf;
945 count = spu_acquire(ctx);
967 for (count = 4, udata++; (count + 4) <= len; count += 4, udata++) {
984 static unsigned int spufs_wbox_poll(
struct file *file,
poll_table *wait)
989 poll_wait(file, &ctx->
wbox_wq, wait);
1003 .open = spufs_pipe_open,
1004 .write = spufs_wbox_write,
1005 .poll = spufs_wbox_poll,
1006 .fasync = spufs_wbox_fasync,
1010 static ssize_t spufs_wbox_stat_read(
struct file *file,
char __user *buf,
1011 size_t len, loff_t *pos)
1020 ret = spu_acquire(ctx);
1023 wbox_stat = (ctx->
ops->mbox_stat_read(ctx) >> 8) & 0xff;
1033 .open = spufs_pipe_open,
1034 .read = spufs_wbox_stat_read,
1038 static int spufs_signal1_open(
struct inode *inode,
struct file *file)
1052 spufs_signal1_release(
struct inode *inode,
struct file *file)
1065 size_t len, loff_t *pos)
1073 if (ctx->
csa.spu_chnlcnt_RW[3]) {
1074 data = ctx->
csa.spu_chnldata_RW[3];
1088 static ssize_t spufs_signal1_read(
struct file *file,
char __user *buf,
1089 size_t len, loff_t *pos)
1097 ret = __spufs_signal1_read(ctx, buf, len, pos);
1103 static ssize_t spufs_signal1_write(
struct file *file,
const char __user *buf,
1104 size_t len, loff_t *pos)
1118 ret = spu_acquire(ctx);
1121 ctx->
ops->signal1_write(ctx, data);
1128 spufs_signal1_mmap_fault(
struct vm_area_struct *vma,
struct vm_fault *vmf)
1130 #if SPUFS_SIGNAL_MAP_SIZE == 0x1000
1132 #elif SPUFS_SIGNAL_MAP_SIZE == 0x10000
1138 #error unsupported page size
1142 static const struct vm_operations_struct spufs_signal1_mmap_vmops = {
1143 .fault = spufs_signal1_mmap_fault,
1146 static int spufs_signal1_mmap(
struct file *file,
struct vm_area_struct *vma)
1151 vma->
vm_flags |= VM_IO | VM_PFNMAP;
1154 vma->
vm_ops = &spufs_signal1_mmap_vmops;
1159 .open = spufs_signal1_open,
1160 .release = spufs_signal1_release,
1161 .read = spufs_signal1_read,
1162 .write = spufs_signal1_write,
1163 .mmap = spufs_signal1_mmap,
1168 .open = spufs_signal1_open,
1169 .release = spufs_signal1_release,
1170 .write = spufs_signal1_write,
1171 .mmap = spufs_signal1_mmap,
1175 static int spufs_signal2_open(
struct inode *inode,
struct file *file)
1189 spufs_signal2_release(
struct inode *inode,
struct file *file)
1202 size_t len, loff_t *pos)
1210 if (ctx->
csa.spu_chnlcnt_RW[4]) {
1211 data = ctx->
csa.spu_chnldata_RW[4];
1225 static ssize_t spufs_signal2_read(
struct file *file,
char __user *buf,
1226 size_t len, loff_t *pos)
1234 ret = __spufs_signal2_read(ctx, buf, len, pos);
1240 static ssize_t spufs_signal2_write(
struct file *file,
const char __user *buf,
1241 size_t len, loff_t *pos)
1255 ret = spu_acquire(ctx);
1258 ctx->
ops->signal2_write(ctx, data);
1266 spufs_signal2_mmap_fault(
struct vm_area_struct *vma,
struct vm_fault *vmf)
1268 #if SPUFS_SIGNAL_MAP_SIZE == 0x1000
1270 #elif SPUFS_SIGNAL_MAP_SIZE == 0x10000
1276 #error unsupported page size
1280 static const struct vm_operations_struct spufs_signal2_mmap_vmops = {
1281 .fault = spufs_signal2_mmap_fault,
1289 vma->
vm_flags |= VM_IO | VM_PFNMAP;
1292 vma->
vm_ops = &spufs_signal2_mmap_vmops;
1296 #define spufs_signal2_mmap NULL
1300 .open = spufs_signal2_open,
1301 .release = spufs_signal2_release,
1302 .read = spufs_signal2_read,
1303 .write = spufs_signal2_write,
1309 .open = spufs_signal2_open,
1310 .release = spufs_signal2_release,
1311 .write = spufs_signal2_write,
1321 #define SPU_ATTR_NOACQUIRE 0
1322 #define SPU_ATTR_ACQUIRE 1
1323 #define SPU_ATTR_ACQUIRE_SAVED 2
1325 #define DEFINE_SPUFS_ATTRIBUTE(__name, __get, __set, __fmt, __acquire) \
1326 static int __##__get(void *data, u64 *val) \
1328 struct spu_context *ctx = data; \
1331 if (__acquire == SPU_ATTR_ACQUIRE) { \
1332 ret = spu_acquire(ctx); \
1335 *val = __get(ctx); \
1337 } else if (__acquire == SPU_ATTR_ACQUIRE_SAVED) { \
1338 ret = spu_acquire_saved(ctx); \
1341 *val = __get(ctx); \
1342 spu_release_saved(ctx); \
1344 *val = __get(ctx); \
1348 DEFINE_SPUFS_SIMPLE_ATTRIBUTE(__name, __##__get, __set, __fmt);
1350 static int spufs_signal1_type_set(
void *data,
u64 val)
1355 ret = spu_acquire(ctx);
1358 ctx->
ops->signal1_type_set(ctx, val);
1366 return ctx->
ops->signal1_type_get(ctx);
1372 static int spufs_signal2_type_set(
void *data,
u64 val)
1377 ret = spu_acquire(ctx);
1380 ctx->
ops->signal2_type_set(ctx, val);
1388 return ctx->
ops->signal2_type_get(ctx);
1395 spufs_mss_mmap_fault(
struct vm_area_struct *vma,
struct vm_fault *vmf)
1400 static const struct vm_operations_struct spufs_mss_mmap_vmops = {
1401 .fault = spufs_mss_mmap_fault,
1412 vma->
vm_flags |= VM_IO | VM_PFNMAP;
1415 vma->
vm_ops = &spufs_mss_mmap_vmops;
1419 #define spufs_mss_mmap NULL
1422 static int spufs_mss_open(
struct inode *inode,
struct file *file)
1437 spufs_mss_release(
struct inode *inode,
struct file *file)
1450 .open = spufs_mss_open,
1451 .release = spufs_mss_release,
1457 spufs_psmap_mmap_fault(
struct vm_area_struct *vma,
struct vm_fault *vmf)
1462 static const struct vm_operations_struct spufs_psmap_mmap_vmops = {
1463 .fault = spufs_psmap_mmap_fault,
1469 static int spufs_psmap_mmap(
struct file *file,
struct vm_area_struct *vma)
1474 vma->
vm_flags |= VM_IO | VM_PFNMAP;
1477 vma->
vm_ops = &spufs_psmap_mmap_vmops;
1481 static int spufs_psmap_open(
struct inode *inode,
struct file *file)
1495 spufs_psmap_release(
struct inode *inode,
struct file *file)
1508 .open = spufs_psmap_open,
1509 .release = spufs_psmap_release,
1510 .mmap = spufs_psmap_mmap,
1517 spufs_mfc_mmap_fault(
struct vm_area_struct *vma,
struct vm_fault *vmf)
1522 static const struct vm_operations_struct spufs_mfc_mmap_vmops = {
1523 .fault = spufs_mfc_mmap_fault,
1534 vma->
vm_flags |= VM_IO | VM_PFNMAP;
1537 vma->
vm_ops = &spufs_mfc_mmap_vmops;
1541 #define spufs_mfc_mmap NULL
1544 static int spufs_mfc_open(
struct inode *inode,
struct file *file)
1565 spufs_mfc_release(
struct inode *inode,
struct file *file)
1587 pr_debug(
"%s %s\n", __func__, spu->name);
1589 u32 free_elements, tagstatus;
1593 free_elements = ctx->
ops->get_mfc_free_elements(ctx);
1594 tagstatus = ctx->
ops->read_mfc_tagstatus(ctx);
1597 if (free_elements & 0xffff)
1610 *status = ctx->
ops->read_mfc_tagstatus(ctx) & ctx->
tagwait;
1617 ctx->
ops->set_mfc_query(ctx, ctx->
tagwait, 1);
1621 static ssize_t spufs_mfc_read(
struct file *file,
char __user *buffer,
1622 size_t size, loff_t *pos)
1631 ret = spu_acquire(ctx);
1637 status = ctx->
ops->read_mfc_tagstatus(ctx);
1645 spufs_read_mfc_tagstatus(ctx, &status));
1661 pr_debug(
"queueing DMA %x %llx %x %x %x\n", cmd->
lsa,
1677 if ((cmd->
lsa & 0xf) != (cmd->
ea &0xf)) {
1678 pr_debug(
"invalid DMA alignment, ea %llx lsa %x\n",
1683 switch (cmd->
size & 0xf) {
1704 pr_debug(
"invalid DMA alignment %x for size %x\n",
1709 if (cmd->
size > 16 * 1024) {
1714 if (cmd->
tag & 0xfff0) {
1729 static int spu_send_mfc_command(
struct spu_context *ctx,
1733 *error = ctx->
ops->send_mfc_command(ctx, &cmd);
1737 ctx->
ops->set_mfc_query(ctx, ctx->
tagwait, 1);
1740 *error = ctx->
ops->send_mfc_command(ctx, &cmd);
1747 static ssize_t spufs_mfc_write(
struct file *file,
const char __user *buffer,
1748 size_t size, loff_t *pos)
1754 if (size !=
sizeof cmd)
1761 ret = spufs_check_valid_dma(&cmd);
1765 ret = spu_acquire(ctx);
1774 ret = ctx->
ops->send_mfc_command(ctx, &cmd);
1778 spu_send_mfc_command(ctx, cmd, &status));
1797 static unsigned int spufs_mfc_poll(
struct file *file,
poll_table *wait)
1800 u32 free_elements, tagstatus;
1803 poll_wait(file, &ctx->
mfc_wq, wait);
1810 ctx->
ops->set_mfc_query(ctx, ctx->
tagwait, 2);
1811 free_elements = ctx->
ops->get_mfc_free_elements(ctx);
1812 tagstatus = ctx->
ops->read_mfc_tagstatus(ctx);
1816 if (free_elements & 0xffff)
1821 pr_debug(
"%s: free %d tagstatus %d tagwait %d\n", __func__,
1822 free_elements, tagstatus, ctx->
tagwait);
1827 static int spufs_mfc_flush(
struct file *file,
fl_owner_t id)
1832 ret = spu_acquire(ctx);
1838 ctx->
ops->set_mfc_query(ctx, ctx->
tagwait, 2));
1842 ctx->
ops->read_mfc_tagstatus(ctx) == ctx->
tagwait);
1853 static int spufs_mfc_fsync(
struct file *file, loff_t
start, loff_t
end,
int datasync)
1855 struct inode *inode = file->
f_path.dentry->d_inode;
1859 err = spufs_mfc_flush(file,
NULL);
1865 static int spufs_mfc_fasync(
int fd,
struct file *file,
int on)
1873 .open = spufs_mfc_open,
1874 .release = spufs_mfc_release,
1875 .read = spufs_mfc_read,
1876 .write = spufs_mfc_write,
1877 .poll = spufs_mfc_poll,
1878 .flush = spufs_mfc_flush,
1879 .fsync = spufs_mfc_fsync,
1880 .fasync = spufs_mfc_fasync,
1885 static int spufs_npc_set(
void *data,
u64 val)
1890 ret = spu_acquire(ctx);
1893 ctx->
ops->npc_write(ctx, val);
1901 return ctx->
ops->npc_read(ctx);
1906 static int spufs_decr_set(
void *data,
u64 val)
1909 struct spu_lscsa *lscsa = ctx->
csa.lscsa;
1915 lscsa->decr.slot[0] = (
u32) val;
1923 struct spu_lscsa *lscsa = ctx->
csa.lscsa;
1924 return lscsa->decr.slot[0];
1929 static int spufs_decr_status_set(
void *data,
u64 val)
1938 ctx->
csa.priv2.mfc_control_RW |= MFC_CNTL_DECREMENTER_RUNNING;
1940 ctx->
csa.priv2.mfc_control_RW &= ~MFC_CNTL_DECREMENTER_RUNNING;
1948 if (ctx->
csa.priv2.mfc_control_RW & MFC_CNTL_DECREMENTER_RUNNING)
1949 return SPU_DECR_STATUS_RUNNING;
1954 spufs_decr_status_set,
"0x%llx\n",
1957 static int spufs_event_mask_set(
void *data,
u64 val)
1960 struct spu_lscsa *lscsa = ctx->
csa.lscsa;
1966 lscsa->event_mask.slot[0] = (
u32) val;
1974 struct spu_lscsa *lscsa = ctx->
csa.lscsa;
1975 return lscsa->event_mask.slot[0];
1979 spufs_event_mask_set,
"0x%llx\n",
1984 struct spu_state *
state = &ctx->
csa;
1986 stat = state->spu_chnlcnt_RW[0];
1988 return state->spu_chnldata_RW[0];
1994 static
int spufs_srr0_set(
void *data,
u64 val)
1997 struct spu_lscsa *lscsa = ctx->
csa.lscsa;
2003 lscsa->srr0.slot[0] = (
u32) val;
2011 struct spu_lscsa *lscsa = ctx->
csa.lscsa;
2012 return lscsa->srr0.slot[0];
2021 if (ctx->state == SPU_STATE_RUNNABLE)
2022 num = ctx->spu->number;
2024 num = (
unsigned int)-1;
2034 return ctx->object_id;
2037 static int spufs_object_id_set(
void *data,
u64 id)
2050 return ctx->
csa.priv2.spu_lslr_RW;
2055 static int spufs_info_open(
struct inode *inode,
struct file *file)
2063 static int spufs_caps_show(
struct seq_file *
s,
void *
private)
2067 if (!(ctx->
flags & SPU_CREATE_NOSCHED))
2069 if (!(ctx->
flags & SPU_CREATE_ISOLATE))
2074 static int spufs_caps_open(
struct inode *inode,
struct file *file)
2080 .open = spufs_caps_open,
2087 char __user *buf,
size_t len, loff_t *pos)
2092 if (!(ctx->
csa.prob.mb_stat_R & 0x0000ff))
2095 data = ctx->
csa.prob.pu_mb_R;
2100 static ssize_t spufs_mbox_info_read(
struct file *file,
char __user *buf,
2101 size_t len, loff_t *pos)
2112 spin_lock(&ctx->
csa.register_lock);
2113 ret = __spufs_mbox_info_read(ctx, buf, len, pos);
2114 spin_unlock(&ctx->
csa.register_lock);
2121 .open = spufs_info_open,
2122 .read = spufs_mbox_info_read,
2127 char __user *buf,
size_t len, loff_t *pos)
2132 if (!(ctx->
csa.prob.mb_stat_R & 0xff0000))
2135 data = ctx->
csa.priv2.puint_mb_R;
2140 static ssize_t spufs_ibox_info_read(
struct file *file,
char __user *buf,
2141 size_t len, loff_t *pos)
2152 spin_lock(&ctx->
csa.register_lock);
2153 ret = __spufs_ibox_info_read(ctx, buf, len, pos);
2154 spin_unlock(&ctx->
csa.register_lock);
2161 .open = spufs_info_open,
2162 .read = spufs_ibox_info_read,
2167 char __user *buf,
size_t len, loff_t *pos)
2173 wbox_stat = ctx->
csa.prob.mb_stat_R;
2174 cnt = 4 - ((wbox_stat & 0x00ff00) >> 8);
2175 for (i = 0; i <
cnt; i++) {
2176 data[
i] = ctx->
csa.spu_mailbox_data[
i];
2183 static ssize_t spufs_wbox_info_read(
struct file *file,
char __user *buf,
2184 size_t len, loff_t *pos)
2195 spin_lock(&ctx->
csa.register_lock);
2196 ret = __spufs_wbox_info_read(ctx, buf, len, pos);
2197 spin_unlock(&ctx->
csa.register_lock);
2204 .open = spufs_info_open,
2205 .read = spufs_wbox_info_read,
2210 char __user *buf,
size_t len, loff_t *pos)
2216 info.dma_info_type = ctx->
csa.priv2.spu_tag_status_query_RW;
2217 info.dma_info_mask = ctx->
csa.lscsa->tag_mask.slot[0];
2218 info.dma_info_status = ctx->
csa.spu_chnldata_RW[24];
2219 info.dma_info_stall_and_notify = ctx->
csa.spu_chnldata_RW[25];
2220 info.dma_info_atomic_command_status = ctx->
csa.spu_chnldata_RW[27];
2221 for (i = 0; i < 16; i++) {
2222 qp = &
info.dma_info_command_data[
i];
2223 spuqp = &ctx->
csa.priv2.spuq[
i];
2235 static ssize_t spufs_dma_info_read(
struct file *file,
char __user *buf,
2236 size_t len, loff_t *pos)
2247 spin_lock(&ctx->
csa.register_lock);
2248 ret = __spufs_dma_info_read(ctx, buf, len, pos);
2249 spin_unlock(&ctx->
csa.register_lock);
2256 .open = spufs_info_open,
2257 .read = spufs_dma_info_read,
2262 char __user *buf,
size_t len, loff_t *pos)
2266 int ret =
sizeof info;
2275 info.proxydma_info_type = ctx->
csa.prob.dma_querytype_RW;
2276 info.proxydma_info_mask = ctx->
csa.prob.dma_querymask_RW;
2277 info.proxydma_info_status = ctx->
csa.prob.dma_tagstatus_R;
2278 for (i = 0; i < 8; i++) {
2279 qp = &
info.proxydma_info_command_data[
i];
2280 puqp = &ctx->
csa.priv2.puq[
i];
2292 static ssize_t spufs_proxydma_info_read(
struct file *file,
char __user *buf,
2293 size_t len, loff_t *pos)
2301 spin_lock(&ctx->
csa.register_lock);
2302 ret = __spufs_proxydma_info_read(ctx, buf, len, pos);
2303 spin_unlock(&ctx->
csa.register_lock);
2310 .open = spufs_info_open,
2311 .read = spufs_proxydma_info_read,
2315 static int spufs_show_tid(
struct seq_file *s,
void *
private)
2323 static int spufs_tid_open(
struct inode *inode,
struct file *file)
2329 .open = spufs_tid_open,
2335 static const char *ctx_state_names[] = {
2336 "user",
"system",
"iowait",
"loaded"
2339 static unsigned long long spufs_acct_time(
struct spu_context *ctx,
2340 enum spu_utilization_state state)
2354 if (ctx->
spu && ctx->
stats.util_state == state) {
2356 time += timespec_to_ns(&
ts) - ctx->
stats.tstamp;
2362 static unsigned long long spufs_slb_flts(
struct spu_context *ctx)
2364 unsigned long long slb_flts = ctx->
stats.slb_flt;
2366 if (ctx->
state == SPU_STATE_RUNNABLE) {
2367 slb_flts += (ctx->
spu->stats.slb_flt -
2368 ctx->
stats.slb_flt_base);
2374 static unsigned long long spufs_class2_intrs(
struct spu_context *ctx)
2376 unsigned long long class2_intrs = ctx->
stats.class2_intr;
2378 if (ctx->
state == SPU_STATE_RUNNABLE) {
2379 class2_intrs += (ctx->
spu->stats.class2_intr -
2380 ctx->
stats.class2_intr_base);
2383 return class2_intrs;
2387 static int spufs_show_stat(
struct seq_file *s,
void *
private)
2392 ret = spu_acquire(ctx);
2397 "%llu %llu %llu %llu %llu %llu %llu %llu\n",
2398 ctx_state_names[ctx->
stats.util_state],
2399 spufs_acct_time(ctx, SPU_UTIL_USER),
2400 spufs_acct_time(ctx, SPU_UTIL_SYSTEM),
2401 spufs_acct_time(ctx, SPU_UTIL_IOWAIT),
2402 spufs_acct_time(ctx, SPU_UTIL_IDLE_LOADED),
2403 ctx->
stats.vol_ctx_switch,
2404 ctx->
stats.invol_ctx_switch,
2405 spufs_slb_flts(ctx),
2406 ctx->
stats.hash_flt,
2409 spufs_class2_intrs(ctx),
2410 ctx->
stats.libassist);
2415 static int spufs_stat_open(
struct inode *inode,
struct file *file)
2421 .open = spufs_stat_open,
2427 static inline int spufs_switch_log_used(
struct spu_context *ctx)
2433 static inline int spufs_switch_log_avail(
struct spu_context *ctx)
2438 static int spufs_switch_log_open(
struct inode *inode,
struct file *file)
2443 rc = spu_acquire(ctx);
2470 static int spufs_switch_log_release(
struct inode *inode,
struct file *file)
2475 rc = spu_acquire(ctx);
2486 static int switch_log_sprint(
struct spu_context *ctx,
char *tbuf,
int n)
2488 struct switch_log_entry *
p;
2492 return snprintf(tbuf, n,
"%u.%09u %d %u %u %llu\n",
2493 (
unsigned int) p->tstamp.tv_sec,
2494 (
unsigned int) p->tstamp.tv_nsec,
2496 (
unsigned int) p->type,
2497 (
unsigned int) p->val,
2498 (
unsigned long long) p->timebase);
2501 static ssize_t spufs_switch_log_read(
struct file *file,
char __user *buf,
2502 size_t len, loff_t *ppos)
2504 struct inode *inode = file->
f_path.dentry->d_inode;
2506 int error = 0, cnt = 0;
2511 error = spu_acquire(ctx);
2519 if (spufs_switch_log_used(ctx) == 0) {
2536 spufs_switch_log_used(ctx) > 0);
2546 if (spufs_switch_log_used(ctx) == 0)
2551 width = switch_log_sprint(ctx, tbuf,
sizeof(tbuf));
2569 return cnt == 0 ? error :
cnt;
2572 static unsigned int spufs_switch_log_poll(
struct file *file,
poll_table *wait)
2574 struct inode *inode = file->
f_path.dentry->d_inode;
2576 unsigned int mask = 0;
2579 poll_wait(file, &ctx->
switch_log->wait, wait);
2581 rc = spu_acquire(ctx);
2585 if (spufs_switch_log_used(ctx) > 0)
2595 .open = spufs_switch_log_open,
2596 .read = spufs_switch_log_read,
2597 .poll = spufs_switch_log_poll,
2598 .release = spufs_switch_log_release,
2613 if (spufs_switch_log_avail(ctx) > 1) {
2614 struct switch_log_entry *
p;
2618 p->timebase = get_tb();
2619 p->spu_id = spu ? spu->number : -1;
2630 static int spufs_show_ctx(
struct seq_file *s,
void *
private)
2637 struct spu *spu = ctx->
spu;
2638 struct spu_priv2
__iomem *priv2 = spu->priv2;
2640 spin_lock_irq(&spu->register_lock);
2641 mfc_control_RW = in_be64(&priv2->mfc_control_RW);
2642 spin_unlock_irq(&spu->register_lock);
2644 struct spu_state *csa = &ctx->
csa;
2646 mfc_control_RW = csa->priv2.mfc_control_RW;
2649 seq_printf(s,
"%c flgs(%lx) sflgs(%lx) pri(%d) ts(%d) spu(%02d)"
2650 " %c %llx %llx %llx %llx %x %x\n",
2651 ctx->
state == SPU_STATE_SAVED ?
'S' :
'R',
2656 ctx->
spu ? ctx->
spu->number : -1,
2657 !list_empty(&ctx->
rq) ?
'q' :
' ',
2658 ctx->
csa.class_0_pending,
2659 ctx->
csa.class_0_dar,
2660 ctx->
csa.class_1_dsisr,
2662 ctx->
ops->runcntl_read(ctx),
2663 ctx->
ops->status_read(ctx));
2670 static int spufs_ctx_open(
struct inode *inode,
struct file *file)
2676 .open = spufs_ctx_open,
2683 {
"capabilities", &spufs_caps_fops, 0444, },
2684 {
"mem", &spufs_mem_fops, 0666,
LS_SIZE, },
2685 {
"regs", &spufs_regs_fops, 0666,
sizeof(
struct spu_reg128[128]), },
2686 {
"mbox", &spufs_mbox_fops, 0444, },
2687 {
"ibox", &spufs_ibox_fops, 0444, },
2688 {
"wbox", &spufs_wbox_fops, 0222, },
2689 {
"mbox_stat", &spufs_mbox_stat_fops, 0444,
sizeof(
u32), },
2690 {
"ibox_stat", &spufs_ibox_stat_fops, 0444,
sizeof(
u32), },
2691 {
"wbox_stat", &spufs_wbox_stat_fops, 0444,
sizeof(
u32), },
2692 {
"signal1", &spufs_signal1_fops, 0666, },
2693 {
"signal2", &spufs_signal2_fops, 0666, },
2694 {
"signal1_type", &spufs_signal1_type, 0666, },
2695 {
"signal2_type", &spufs_signal2_type, 0666, },
2696 {
"cntl", &spufs_cntl_fops, 0666, },
2697 {
"fpcr", &spufs_fpcr_fops, 0666,
sizeof(
struct spu_reg128), },
2698 {
"lslr", &spufs_lslr_ops, 0444, },
2699 {
"mfc", &spufs_mfc_fops, 0666, },
2700 {
"mss", &spufs_mss_fops, 0666, },
2701 {
"npc", &spufs_npc_ops, 0666, },
2702 {
"srr0", &spufs_srr0_ops, 0666, },
2703 {
"decr", &spufs_decr_ops, 0666, },
2704 {
"decr_status", &spufs_decr_status_ops, 0666, },
2705 {
"event_mask", &spufs_event_mask_ops, 0666, },
2706 {
"event_status", &spufs_event_status_ops, 0444, },
2708 {
"phys-id", &spufs_id_ops, 0666, },
2709 {
"object-id", &spufs_object_id_ops, 0666, },
2710 {
"mbox_info", &spufs_mbox_info_fops, 0444,
sizeof(
u32), },
2711 {
"ibox_info", &spufs_ibox_info_fops, 0444,
sizeof(
u32), },
2712 {
"wbox_info", &spufs_wbox_info_fops, 0444,
sizeof(
u32), },
2713 {
"dma_info", &spufs_dma_info_fops, 0444,
2715 {
"proxydma_info", &spufs_proxydma_info_fops, 0444,
2717 {
"tid", &spufs_tid_fops, 0444, },
2718 {
"stat", &spufs_stat_fops, 0444, },
2719 {
"switch_log", &spufs_switch_log_fops, 0444 },
2724 {
"capabilities", &spufs_caps_fops, 0444, },
2725 {
"mem", &spufs_mem_fops, 0666,
LS_SIZE, },
2726 {
"mbox", &spufs_mbox_fops, 0444, },
2727 {
"ibox", &spufs_ibox_fops, 0444, },
2728 {
"wbox", &spufs_wbox_fops, 0222, },
2729 {
"mbox_stat", &spufs_mbox_stat_fops, 0444,
sizeof(
u32), },
2730 {
"ibox_stat", &spufs_ibox_stat_fops, 0444,
sizeof(
u32), },
2731 {
"wbox_stat", &spufs_wbox_stat_fops, 0444,
sizeof(
u32), },
2732 {
"signal1", &spufs_signal1_nosched_fops, 0222, },
2733 {
"signal2", &spufs_signal2_nosched_fops, 0222, },
2734 {
"signal1_type", &spufs_signal1_type, 0666, },
2735 {
"signal2_type", &spufs_signal2_type, 0666, },
2736 {
"mss", &spufs_mss_fops, 0666, },
2737 {
"mfc", &spufs_mfc_fops, 0666, },
2738 {
"cntl", &spufs_cntl_fops, 0666, },
2739 {
"npc", &spufs_npc_ops, 0666, },
2741 {
"phys-id", &spufs_id_ops, 0666, },
2742 {
"object-id", &spufs_object_id_ops, 0666, },
2743 {
"tid", &spufs_tid_fops, 0444, },
2744 {
"stat", &spufs_stat_fops, 0444, },
2749 {
".ctx", &spufs_ctx_fops, 0444, },
2754 {
"regs", __spufs_regs_read,
NULL,
sizeof(
struct spu_reg128[128])},
2755 {
"fpcr", __spufs_fpcr_read,
NULL,
sizeof(
struct spu_reg128) },
2756 {
"lslr",
NULL, spufs_lslr_get, 19 },
2757 {
"decr",
NULL, spufs_decr_get, 19 },
2758 {
"decr_status",
NULL, spufs_decr_status_get, 19 },
2760 {
"signal1", __spufs_signal1_read,
NULL,
sizeof(
u32) },
2761 {
"signal1_type",
NULL, spufs_signal1_type_get, 19 },
2762 {
"signal2", __spufs_signal2_read,
NULL,
sizeof(
u32) },
2763 {
"signal2_type",
NULL, spufs_signal2_type_get, 19 },
2764 {
"event_mask",
NULL, spufs_event_mask_get, 19 },
2765 {
"event_status",
NULL, spufs_event_status_get, 19 },
2766 {
"mbox_info", __spufs_mbox_info_read,
NULL,
sizeof(
u32) },
2767 {
"ibox_info", __spufs_ibox_info_read,
NULL,
sizeof(
u32) },
2768 {
"wbox_info", __spufs_wbox_info_read,
NULL, 4 *
sizeof(
u32)},
2770 {
"proxydma_info", __spufs_proxydma_info_read,
2772 {
"object-id",
NULL, spufs_object_id_get, 19 },
2773 {
"npc",
NULL, spufs_npc_get, 19 },