167207b96SArnd Bergmann /* 267207b96SArnd Bergmann * SPU file system -- file contents 367207b96SArnd Bergmann * 467207b96SArnd Bergmann * (C) Copyright IBM Deutschland Entwicklung GmbH 2005 567207b96SArnd Bergmann * 667207b96SArnd Bergmann * Author: Arnd Bergmann <arndb@de.ibm.com> 767207b96SArnd Bergmann * 867207b96SArnd Bergmann * This program is free software; you can redistribute it and/or modify 967207b96SArnd Bergmann * it under the terms of the GNU General Public License as published by 1067207b96SArnd Bergmann * the Free Software Foundation; either version 2, or (at your option) 1167207b96SArnd Bergmann * any later version. 1267207b96SArnd Bergmann * 1367207b96SArnd Bergmann * This program is distributed in the hope that it will be useful, 1467207b96SArnd Bergmann * but WITHOUT ANY WARRANTY; without even the implied warranty of 1567207b96SArnd Bergmann * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1667207b96SArnd Bergmann * GNU General Public License for more details. 1767207b96SArnd Bergmann * 1867207b96SArnd Bergmann * You should have received a copy of the GNU General Public License 1967207b96SArnd Bergmann * along with this program; if not, write to the Free Software 2067207b96SArnd Bergmann * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 2167207b96SArnd Bergmann */ 2267207b96SArnd Bergmann 23a33a7d73SArnd Bergmann #undef DEBUG 24a33a7d73SArnd Bergmann 2567207b96SArnd Bergmann #include <linux/fs.h> 2667207b96SArnd Bergmann #include <linux/ioctl.h> 2767207b96SArnd Bergmann #include <linux/module.h> 28d88cfffaSArnd Bergmann #include <linux/pagemap.h> 2967207b96SArnd Bergmann #include <linux/poll.h> 305110459fSArnd Bergmann #include <linux/ptrace.h> 3167207b96SArnd Bergmann 3267207b96SArnd Bergmann #include <asm/io.h> 3367207b96SArnd Bergmann #include <asm/semaphore.h> 3467207b96SArnd Bergmann #include <asm/spu.h> 3567207b96SArnd Bergmann #include <asm/uaccess.h> 3667207b96SArnd Bergmann 3767207b96SArnd Bergmann #include "spufs.h" 3867207b96SArnd Bergmann 3927d5bf2aSBenjamin Herrenschmidt #define SPUFS_MMAP_4K (PAGE_SIZE == 0x1000) 4027d5bf2aSBenjamin Herrenschmidt 418b3d6663SArnd Bergmann 4267207b96SArnd Bergmann static int 4367207b96SArnd Bergmann spufs_mem_open(struct inode *inode, struct file *file) 4467207b96SArnd Bergmann { 4567207b96SArnd Bergmann struct spufs_inode_info *i = SPUFS_I(inode); 466df10a82SMark Nutter struct spu_context *ctx = i->i_ctx; 476df10a82SMark Nutter file->private_data = ctx; 486df10a82SMark Nutter file->f_mapping = inode->i_mapping; 496df10a82SMark Nutter ctx->local_store = inode->i_mapping; 5067207b96SArnd Bergmann return 0; 5167207b96SArnd Bergmann } 5267207b96SArnd Bergmann 5367207b96SArnd Bergmann static ssize_t 5467207b96SArnd Bergmann spufs_mem_read(struct file *file, char __user *buffer, 5567207b96SArnd Bergmann size_t size, loff_t *pos) 5667207b96SArnd Bergmann { 578b3d6663SArnd Bergmann struct spu_context *ctx = file->private_data; 588b3d6663SArnd Bergmann char *local_store; 5967207b96SArnd Bergmann int ret; 6067207b96SArnd Bergmann 618b3d6663SArnd Bergmann spu_acquire(ctx); 6267207b96SArnd Bergmann 638b3d6663SArnd Bergmann local_store = ctx->ops->get_ls(ctx); 648b3d6663SArnd Bergmann ret = simple_read_from_buffer(buffer, size, pos, local_store, LS_SIZE); 6567207b96SArnd Bergmann 668b3d6663SArnd Bergmann spu_release(ctx); 6767207b96SArnd Bergmann return ret; 6867207b96SArnd Bergmann } 6967207b96SArnd Bergmann 7067207b96SArnd Bergmann static ssize_t 7167207b96SArnd Bergmann spufs_mem_write(struct file *file, const char __user *buffer, 7267207b96SArnd Bergmann size_t size, loff_t *pos) 7367207b96SArnd Bergmann { 7467207b96SArnd Bergmann struct spu_context *ctx = file->private_data; 758b3d6663SArnd Bergmann char *local_store; 768b3d6663SArnd Bergmann int ret; 7767207b96SArnd Bergmann 7867207b96SArnd Bergmann size = min_t(ssize_t, LS_SIZE - *pos, size); 7967207b96SArnd Bergmann if (size <= 0) 8067207b96SArnd Bergmann return -EFBIG; 8167207b96SArnd Bergmann *pos += size; 828b3d6663SArnd Bergmann 838b3d6663SArnd Bergmann spu_acquire(ctx); 848b3d6663SArnd Bergmann 858b3d6663SArnd Bergmann local_store = ctx->ops->get_ls(ctx); 868b3d6663SArnd Bergmann ret = copy_from_user(local_store + *pos - size, 8767207b96SArnd Bergmann buffer, size) ? -EFAULT : size; 888b3d6663SArnd Bergmann 898b3d6663SArnd Bergmann spu_release(ctx); 908b3d6663SArnd Bergmann return ret; 9167207b96SArnd Bergmann } 9267207b96SArnd Bergmann 938b3d6663SArnd Bergmann static struct page * 948b3d6663SArnd Bergmann spufs_mem_mmap_nopage(struct vm_area_struct *vma, 958b3d6663SArnd Bergmann unsigned long address, int *type) 968b3d6663SArnd Bergmann { 978b3d6663SArnd Bergmann struct page *page = NOPAGE_SIGBUS; 988b3d6663SArnd Bergmann 998b3d6663SArnd Bergmann struct spu_context *ctx = vma->vm_file->private_data; 1008b3d6663SArnd Bergmann unsigned long offset = address - vma->vm_start; 1018b3d6663SArnd Bergmann offset += vma->vm_pgoff << PAGE_SHIFT; 1028b3d6663SArnd Bergmann 1038b3d6663SArnd Bergmann spu_acquire(ctx); 1048b3d6663SArnd Bergmann 105ac91cb8dSArnd Bergmann if (ctx->state == SPU_STATE_SAVED) { 106ac91cb8dSArnd Bergmann vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot) 107ac91cb8dSArnd Bergmann & ~(_PAGE_NO_CACHE | _PAGE_GUARDED)); 1088b3d6663SArnd Bergmann page = vmalloc_to_page(ctx->csa.lscsa->ls + offset); 109ac91cb8dSArnd Bergmann } else { 110ac91cb8dSArnd Bergmann vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot) 111ac91cb8dSArnd Bergmann | _PAGE_NO_CACHE | _PAGE_GUARDED); 1128b3d6663SArnd Bergmann page = pfn_to_page((ctx->spu->local_store_phys + offset) 1138b3d6663SArnd Bergmann >> PAGE_SHIFT); 114ac91cb8dSArnd Bergmann } 1158b3d6663SArnd Bergmann spu_release(ctx); 1168b3d6663SArnd Bergmann 1178b3d6663SArnd Bergmann if (type) 1188b3d6663SArnd Bergmann *type = VM_FAULT_MINOR; 1198b3d6663SArnd Bergmann 120d88cfffaSArnd Bergmann page_cache_get(page); 1218b3d6663SArnd Bergmann return page; 1228b3d6663SArnd Bergmann } 1238b3d6663SArnd Bergmann 1248b3d6663SArnd Bergmann static struct vm_operations_struct spufs_mem_mmap_vmops = { 1258b3d6663SArnd Bergmann .nopage = spufs_mem_mmap_nopage, 1268b3d6663SArnd Bergmann }; 1278b3d6663SArnd Bergmann 12867207b96SArnd Bergmann static int 12967207b96SArnd Bergmann spufs_mem_mmap(struct file *file, struct vm_area_struct *vma) 13067207b96SArnd Bergmann { 1318b3d6663SArnd Bergmann if (!(vma->vm_flags & VM_SHARED)) 1328b3d6663SArnd Bergmann return -EINVAL; 13367207b96SArnd Bergmann 1348b3d6663SArnd Bergmann /* FIXME: */ 13567207b96SArnd Bergmann vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot) 13667207b96SArnd Bergmann | _PAGE_NO_CACHE); 1378b3d6663SArnd Bergmann 1388b3d6663SArnd Bergmann vma->vm_ops = &spufs_mem_mmap_vmops; 13967207b96SArnd Bergmann return 0; 14067207b96SArnd Bergmann } 14167207b96SArnd Bergmann 14267207b96SArnd Bergmann static struct file_operations spufs_mem_fops = { 14367207b96SArnd Bergmann .open = spufs_mem_open, 14467207b96SArnd Bergmann .read = spufs_mem_read, 14567207b96SArnd Bergmann .write = spufs_mem_write, 1468b3d6663SArnd Bergmann .llseek = generic_file_llseek, 14767207b96SArnd Bergmann .mmap = spufs_mem_mmap, 1488b3d6663SArnd Bergmann }; 1498b3d6663SArnd Bergmann 1506df10a82SMark Nutter static struct page *spufs_ps_nopage(struct vm_area_struct *vma, 1516df10a82SMark Nutter unsigned long address, 15227d5bf2aSBenjamin Herrenschmidt int *type, unsigned long ps_offs, 15327d5bf2aSBenjamin Herrenschmidt unsigned long ps_size) 1546df10a82SMark Nutter { 1556df10a82SMark Nutter struct page *page = NOPAGE_SIGBUS; 1566df10a82SMark Nutter int fault_type = VM_FAULT_SIGBUS; 1576df10a82SMark Nutter struct spu_context *ctx = vma->vm_file->private_data; 1586df10a82SMark Nutter unsigned long offset = address - vma->vm_start; 1596df10a82SMark Nutter unsigned long area; 1606df10a82SMark Nutter int ret; 1616df10a82SMark Nutter 1626df10a82SMark Nutter offset += vma->vm_pgoff << PAGE_SHIFT; 16327d5bf2aSBenjamin Herrenschmidt if (offset >= ps_size) 1646df10a82SMark Nutter goto out; 1656df10a82SMark Nutter 1666df10a82SMark Nutter ret = spu_acquire_runnable(ctx); 1676df10a82SMark Nutter if (ret) 1686df10a82SMark Nutter goto out; 1696df10a82SMark Nutter 1706df10a82SMark Nutter area = ctx->spu->problem_phys + ps_offs; 1716df10a82SMark Nutter page = pfn_to_page((area + offset) >> PAGE_SHIFT); 1726df10a82SMark Nutter fault_type = VM_FAULT_MINOR; 1736df10a82SMark Nutter page_cache_get(page); 1746df10a82SMark Nutter 1756df10a82SMark Nutter spu_release(ctx); 1766df10a82SMark Nutter 1776df10a82SMark Nutter out: 1786df10a82SMark Nutter if (type) 1796df10a82SMark Nutter *type = fault_type; 1806df10a82SMark Nutter 1816df10a82SMark Nutter return page; 1826df10a82SMark Nutter } 1836df10a82SMark Nutter 18427d5bf2aSBenjamin Herrenschmidt #if SPUFS_MMAP_4K 1856df10a82SMark Nutter static struct page *spufs_cntl_mmap_nopage(struct vm_area_struct *vma, 1866df10a82SMark Nutter unsigned long address, int *type) 1876df10a82SMark Nutter { 18827d5bf2aSBenjamin Herrenschmidt return spufs_ps_nopage(vma, address, type, 0x4000, 0x1000); 1896df10a82SMark Nutter } 1906df10a82SMark Nutter 1916df10a82SMark Nutter static struct vm_operations_struct spufs_cntl_mmap_vmops = { 1926df10a82SMark Nutter .nopage = spufs_cntl_mmap_nopage, 1936df10a82SMark Nutter }; 1946df10a82SMark Nutter 1956df10a82SMark Nutter /* 1966df10a82SMark Nutter * mmap support for problem state control area [0x4000 - 0x4fff]. 1976df10a82SMark Nutter */ 1986df10a82SMark Nutter static int spufs_cntl_mmap(struct file *file, struct vm_area_struct *vma) 1996df10a82SMark Nutter { 2006df10a82SMark Nutter if (!(vma->vm_flags & VM_SHARED)) 2016df10a82SMark Nutter return -EINVAL; 2026df10a82SMark Nutter 2036df10a82SMark Nutter vma->vm_flags |= VM_RESERVED; 2046df10a82SMark Nutter vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot) 20523cc7701SBenjamin Herrenschmidt | _PAGE_NO_CACHE | _PAGE_GUARDED); 2066df10a82SMark Nutter 2076df10a82SMark Nutter vma->vm_ops = &spufs_cntl_mmap_vmops; 2086df10a82SMark Nutter return 0; 2096df10a82SMark Nutter } 21027d5bf2aSBenjamin Herrenschmidt #else /* SPUFS_MMAP_4K */ 21127d5bf2aSBenjamin Herrenschmidt #define spufs_cntl_mmap NULL 21227d5bf2aSBenjamin Herrenschmidt #endif /* !SPUFS_MMAP_4K */ 2136df10a82SMark Nutter 2146df10a82SMark Nutter static int spufs_cntl_open(struct inode *inode, struct file *file) 2156df10a82SMark Nutter { 2166df10a82SMark Nutter struct spufs_inode_info *i = SPUFS_I(inode); 2176df10a82SMark Nutter struct spu_context *ctx = i->i_ctx; 2186df10a82SMark Nutter 2196df10a82SMark Nutter file->private_data = ctx; 2206df10a82SMark Nutter file->f_mapping = inode->i_mapping; 2216df10a82SMark Nutter ctx->cntl = inode->i_mapping; 2226df10a82SMark Nutter return 0; 2236df10a82SMark Nutter } 2246df10a82SMark Nutter 2256df10a82SMark Nutter static ssize_t 2266df10a82SMark Nutter spufs_cntl_read(struct file *file, char __user *buffer, 2276df10a82SMark Nutter size_t size, loff_t *pos) 2286df10a82SMark Nutter { 2296df10a82SMark Nutter /* FIXME: read from spu status */ 2306df10a82SMark Nutter return -EINVAL; 2316df10a82SMark Nutter } 2326df10a82SMark Nutter 2336df10a82SMark Nutter static ssize_t 2346df10a82SMark Nutter spufs_cntl_write(struct file *file, const char __user *buffer, 2356df10a82SMark Nutter size_t size, loff_t *pos) 2366df10a82SMark Nutter { 2376df10a82SMark Nutter /* FIXME: write to runctl bit */ 2386df10a82SMark Nutter return -EINVAL; 2396df10a82SMark Nutter } 2406df10a82SMark Nutter 2416df10a82SMark Nutter static struct file_operations spufs_cntl_fops = { 2426df10a82SMark Nutter .open = spufs_cntl_open, 2436df10a82SMark Nutter .read = spufs_cntl_read, 2446df10a82SMark Nutter .write = spufs_cntl_write, 2456df10a82SMark Nutter .mmap = spufs_cntl_mmap, 2466df10a82SMark Nutter }; 2476df10a82SMark Nutter 2488b3d6663SArnd Bergmann static int 2498b3d6663SArnd Bergmann spufs_regs_open(struct inode *inode, struct file *file) 2508b3d6663SArnd Bergmann { 2518b3d6663SArnd Bergmann struct spufs_inode_info *i = SPUFS_I(inode); 2528b3d6663SArnd Bergmann file->private_data = i->i_ctx; 2538b3d6663SArnd Bergmann return 0; 2548b3d6663SArnd Bergmann } 2558b3d6663SArnd Bergmann 2568b3d6663SArnd Bergmann static ssize_t 2578b3d6663SArnd Bergmann spufs_regs_read(struct file *file, char __user *buffer, 2588b3d6663SArnd Bergmann size_t size, loff_t *pos) 2598b3d6663SArnd Bergmann { 2608b3d6663SArnd Bergmann struct spu_context *ctx = file->private_data; 2618b3d6663SArnd Bergmann struct spu_lscsa *lscsa = ctx->csa.lscsa; 2628b3d6663SArnd Bergmann int ret; 2638b3d6663SArnd Bergmann 2648b3d6663SArnd Bergmann spu_acquire_saved(ctx); 2658b3d6663SArnd Bergmann 2668b3d6663SArnd Bergmann ret = simple_read_from_buffer(buffer, size, pos, 2678b3d6663SArnd Bergmann lscsa->gprs, sizeof lscsa->gprs); 2688b3d6663SArnd Bergmann 2698b3d6663SArnd Bergmann spu_release(ctx); 2708b3d6663SArnd Bergmann return ret; 2718b3d6663SArnd Bergmann } 2728b3d6663SArnd Bergmann 2738b3d6663SArnd Bergmann static ssize_t 2748b3d6663SArnd Bergmann spufs_regs_write(struct file *file, const char __user *buffer, 2758b3d6663SArnd Bergmann size_t size, loff_t *pos) 2768b3d6663SArnd Bergmann { 2778b3d6663SArnd Bergmann struct spu_context *ctx = file->private_data; 2788b3d6663SArnd Bergmann struct spu_lscsa *lscsa = ctx->csa.lscsa; 2798b3d6663SArnd Bergmann int ret; 2808b3d6663SArnd Bergmann 2818b3d6663SArnd Bergmann size = min_t(ssize_t, sizeof lscsa->gprs - *pos, size); 2828b3d6663SArnd Bergmann if (size <= 0) 2838b3d6663SArnd Bergmann return -EFBIG; 2848b3d6663SArnd Bergmann *pos += size; 2858b3d6663SArnd Bergmann 2868b3d6663SArnd Bergmann spu_acquire_saved(ctx); 2878b3d6663SArnd Bergmann 2888b3d6663SArnd Bergmann ret = copy_from_user(lscsa->gprs + *pos - size, 2898b3d6663SArnd Bergmann buffer, size) ? -EFAULT : size; 2908b3d6663SArnd Bergmann 2918b3d6663SArnd Bergmann spu_release(ctx); 2928b3d6663SArnd Bergmann return ret; 2938b3d6663SArnd Bergmann } 2948b3d6663SArnd Bergmann 2958b3d6663SArnd Bergmann static struct file_operations spufs_regs_fops = { 2968b3d6663SArnd Bergmann .open = spufs_regs_open, 2978b3d6663SArnd Bergmann .read = spufs_regs_read, 2988b3d6663SArnd Bergmann .write = spufs_regs_write, 2998b3d6663SArnd Bergmann .llseek = generic_file_llseek, 3008b3d6663SArnd Bergmann }; 3018b3d6663SArnd Bergmann 3028b3d6663SArnd Bergmann static ssize_t 3038b3d6663SArnd Bergmann spufs_fpcr_read(struct file *file, char __user * buffer, 3048b3d6663SArnd Bergmann size_t size, loff_t * pos) 3058b3d6663SArnd Bergmann { 3068b3d6663SArnd Bergmann struct spu_context *ctx = file->private_data; 3078b3d6663SArnd Bergmann struct spu_lscsa *lscsa = ctx->csa.lscsa; 3088b3d6663SArnd Bergmann int ret; 3098b3d6663SArnd Bergmann 3108b3d6663SArnd Bergmann spu_acquire_saved(ctx); 3118b3d6663SArnd Bergmann 3128b3d6663SArnd Bergmann ret = simple_read_from_buffer(buffer, size, pos, 3138b3d6663SArnd Bergmann &lscsa->fpcr, sizeof(lscsa->fpcr)); 3148b3d6663SArnd Bergmann 3158b3d6663SArnd Bergmann spu_release(ctx); 3168b3d6663SArnd Bergmann return ret; 3178b3d6663SArnd Bergmann } 3188b3d6663SArnd Bergmann 3198b3d6663SArnd Bergmann static ssize_t 3208b3d6663SArnd Bergmann spufs_fpcr_write(struct file *file, const char __user * buffer, 3218b3d6663SArnd Bergmann size_t size, loff_t * pos) 3228b3d6663SArnd Bergmann { 3238b3d6663SArnd Bergmann struct spu_context *ctx = file->private_data; 3248b3d6663SArnd Bergmann struct spu_lscsa *lscsa = ctx->csa.lscsa; 3258b3d6663SArnd Bergmann int ret; 3268b3d6663SArnd Bergmann 3278b3d6663SArnd Bergmann size = min_t(ssize_t, sizeof(lscsa->fpcr) - *pos, size); 3288b3d6663SArnd Bergmann if (size <= 0) 3298b3d6663SArnd Bergmann return -EFBIG; 3308b3d6663SArnd Bergmann *pos += size; 3318b3d6663SArnd Bergmann 3328b3d6663SArnd Bergmann spu_acquire_saved(ctx); 3338b3d6663SArnd Bergmann 3348b3d6663SArnd Bergmann ret = copy_from_user((char *)&lscsa->fpcr + *pos - size, 3358b3d6663SArnd Bergmann buffer, size) ? -EFAULT : size; 3368b3d6663SArnd Bergmann 3378b3d6663SArnd Bergmann spu_release(ctx); 3388b3d6663SArnd Bergmann return ret; 3398b3d6663SArnd Bergmann } 3408b3d6663SArnd Bergmann 3418b3d6663SArnd Bergmann static struct file_operations spufs_fpcr_fops = { 3428b3d6663SArnd Bergmann .open = spufs_regs_open, 3438b3d6663SArnd Bergmann .read = spufs_fpcr_read, 3448b3d6663SArnd Bergmann .write = spufs_fpcr_write, 34567207b96SArnd Bergmann .llseek = generic_file_llseek, 34667207b96SArnd Bergmann }; 34767207b96SArnd Bergmann 34867207b96SArnd Bergmann /* generic open function for all pipe-like files */ 34967207b96SArnd Bergmann static int spufs_pipe_open(struct inode *inode, struct file *file) 35067207b96SArnd Bergmann { 35167207b96SArnd Bergmann struct spufs_inode_info *i = SPUFS_I(inode); 35267207b96SArnd Bergmann file->private_data = i->i_ctx; 35367207b96SArnd Bergmann 35467207b96SArnd Bergmann return nonseekable_open(inode, file); 35567207b96SArnd Bergmann } 35667207b96SArnd Bergmann 357*cdcc89bbSArnd Bergmann /* 358*cdcc89bbSArnd Bergmann * Read as many bytes from the mailbox as possible, until 359*cdcc89bbSArnd Bergmann * one of the conditions becomes true: 360*cdcc89bbSArnd Bergmann * 361*cdcc89bbSArnd Bergmann * - no more data available in the mailbox 362*cdcc89bbSArnd Bergmann * - end of the user provided buffer 363*cdcc89bbSArnd Bergmann * - end of the mapped area 364*cdcc89bbSArnd Bergmann */ 36567207b96SArnd Bergmann static ssize_t spufs_mbox_read(struct file *file, char __user *buf, 36667207b96SArnd Bergmann size_t len, loff_t *pos) 36767207b96SArnd Bergmann { 3688b3d6663SArnd Bergmann struct spu_context *ctx = file->private_data; 369*cdcc89bbSArnd Bergmann u32 mbox_data, __user *udata; 370*cdcc89bbSArnd Bergmann ssize_t count; 37167207b96SArnd Bergmann 37267207b96SArnd Bergmann if (len < 4) 37367207b96SArnd Bergmann return -EINVAL; 37467207b96SArnd Bergmann 375*cdcc89bbSArnd Bergmann if (!access_ok(VERIFY_WRITE, buf, len)) 37667207b96SArnd Bergmann return -EFAULT; 37767207b96SArnd Bergmann 378*cdcc89bbSArnd Bergmann udata = (void __user *)buf; 379*cdcc89bbSArnd Bergmann 380*cdcc89bbSArnd Bergmann spu_acquire(ctx); 381*cdcc89bbSArnd Bergmann for (count = 0; count <= len; count += 4, udata++) { 382*cdcc89bbSArnd Bergmann int ret; 383*cdcc89bbSArnd Bergmann ret = ctx->ops->mbox_read(ctx, &mbox_data); 384*cdcc89bbSArnd Bergmann if (ret == 0) 385*cdcc89bbSArnd Bergmann break; 386*cdcc89bbSArnd Bergmann 387*cdcc89bbSArnd Bergmann /* 388*cdcc89bbSArnd Bergmann * at the end of the mapped area, we can fault 389*cdcc89bbSArnd Bergmann * but still need to return the data we have 390*cdcc89bbSArnd Bergmann * read successfully so far. 391*cdcc89bbSArnd Bergmann */ 392*cdcc89bbSArnd Bergmann ret = __put_user(mbox_data, udata); 393*cdcc89bbSArnd Bergmann if (ret) { 394*cdcc89bbSArnd Bergmann if (!count) 395*cdcc89bbSArnd Bergmann count = -EFAULT; 396*cdcc89bbSArnd Bergmann break; 397*cdcc89bbSArnd Bergmann } 398*cdcc89bbSArnd Bergmann } 399*cdcc89bbSArnd Bergmann spu_release(ctx); 400*cdcc89bbSArnd Bergmann 401*cdcc89bbSArnd Bergmann if (!count) 402*cdcc89bbSArnd Bergmann count = -EAGAIN; 403*cdcc89bbSArnd Bergmann 404*cdcc89bbSArnd Bergmann return count; 40567207b96SArnd Bergmann } 40667207b96SArnd Bergmann 40767207b96SArnd Bergmann static struct file_operations spufs_mbox_fops = { 40867207b96SArnd Bergmann .open = spufs_pipe_open, 40967207b96SArnd Bergmann .read = spufs_mbox_read, 41067207b96SArnd Bergmann }; 41167207b96SArnd Bergmann 41267207b96SArnd Bergmann static ssize_t spufs_mbox_stat_read(struct file *file, char __user *buf, 41367207b96SArnd Bergmann size_t len, loff_t *pos) 41467207b96SArnd Bergmann { 4158b3d6663SArnd Bergmann struct spu_context *ctx = file->private_data; 41667207b96SArnd Bergmann u32 mbox_stat; 41767207b96SArnd Bergmann 41867207b96SArnd Bergmann if (len < 4) 41967207b96SArnd Bergmann return -EINVAL; 42067207b96SArnd Bergmann 4218b3d6663SArnd Bergmann spu_acquire(ctx); 4228b3d6663SArnd Bergmann 4238b3d6663SArnd Bergmann mbox_stat = ctx->ops->mbox_stat_read(ctx) & 0xff; 4248b3d6663SArnd Bergmann 4258b3d6663SArnd Bergmann spu_release(ctx); 42667207b96SArnd Bergmann 42767207b96SArnd Bergmann if (copy_to_user(buf, &mbox_stat, sizeof mbox_stat)) 42867207b96SArnd Bergmann return -EFAULT; 42967207b96SArnd Bergmann 43067207b96SArnd Bergmann return 4; 43167207b96SArnd Bergmann } 43267207b96SArnd Bergmann 43367207b96SArnd Bergmann static struct file_operations spufs_mbox_stat_fops = { 43467207b96SArnd Bergmann .open = spufs_pipe_open, 43567207b96SArnd Bergmann .read = spufs_mbox_stat_read, 43667207b96SArnd Bergmann }; 43767207b96SArnd Bergmann 43867207b96SArnd Bergmann /* low-level ibox access function */ 4398b3d6663SArnd Bergmann size_t spu_ibox_read(struct spu_context *ctx, u32 *data) 44067207b96SArnd Bergmann { 4418b3d6663SArnd Bergmann return ctx->ops->ibox_read(ctx, data); 44267207b96SArnd Bergmann } 44367207b96SArnd Bergmann 44467207b96SArnd Bergmann static int spufs_ibox_fasync(int fd, struct file *file, int on) 44567207b96SArnd Bergmann { 4468b3d6663SArnd Bergmann struct spu_context *ctx = file->private_data; 4478b3d6663SArnd Bergmann 4488b3d6663SArnd Bergmann return fasync_helper(fd, file, on, &ctx->ibox_fasync); 4498b3d6663SArnd Bergmann } 4508b3d6663SArnd Bergmann 4518b3d6663SArnd Bergmann /* interrupt-level ibox callback function. */ 4528b3d6663SArnd Bergmann void spufs_ibox_callback(struct spu *spu) 4538b3d6663SArnd Bergmann { 4548b3d6663SArnd Bergmann struct spu_context *ctx = spu->ctx; 4558b3d6663SArnd Bergmann 4568b3d6663SArnd Bergmann wake_up_all(&ctx->ibox_wq); 4578b3d6663SArnd Bergmann kill_fasync(&ctx->ibox_fasync, SIGIO, POLLIN); 45867207b96SArnd Bergmann } 45967207b96SArnd Bergmann 460*cdcc89bbSArnd Bergmann /* 461*cdcc89bbSArnd Bergmann * Read as many bytes from the interrupt mailbox as possible, until 462*cdcc89bbSArnd Bergmann * one of the conditions becomes true: 463*cdcc89bbSArnd Bergmann * 464*cdcc89bbSArnd Bergmann * - no more data available in the mailbox 465*cdcc89bbSArnd Bergmann * - end of the user provided buffer 466*cdcc89bbSArnd Bergmann * - end of the mapped area 467*cdcc89bbSArnd Bergmann * 468*cdcc89bbSArnd Bergmann * If the file is opened without O_NONBLOCK, we wait here until 469*cdcc89bbSArnd Bergmann * any data is available, but return when we have been able to 470*cdcc89bbSArnd Bergmann * read something. 471*cdcc89bbSArnd Bergmann */ 47267207b96SArnd Bergmann static ssize_t spufs_ibox_read(struct file *file, char __user *buf, 47367207b96SArnd Bergmann size_t len, loff_t *pos) 47467207b96SArnd Bergmann { 4758b3d6663SArnd Bergmann struct spu_context *ctx = file->private_data; 476*cdcc89bbSArnd Bergmann u32 ibox_data, __user *udata; 477*cdcc89bbSArnd Bergmann ssize_t count; 47867207b96SArnd Bergmann 47967207b96SArnd Bergmann if (len < 4) 48067207b96SArnd Bergmann return -EINVAL; 48167207b96SArnd Bergmann 482*cdcc89bbSArnd Bergmann if (!access_ok(VERIFY_WRITE, buf, len)) 483*cdcc89bbSArnd Bergmann return -EFAULT; 484*cdcc89bbSArnd Bergmann 485*cdcc89bbSArnd Bergmann udata = (void __user *)buf; 486*cdcc89bbSArnd Bergmann 4878b3d6663SArnd Bergmann spu_acquire(ctx); 48867207b96SArnd Bergmann 489*cdcc89bbSArnd Bergmann /* wait only for the first element */ 490*cdcc89bbSArnd Bergmann count = 0; 49167207b96SArnd Bergmann if (file->f_flags & O_NONBLOCK) { 4928b3d6663SArnd Bergmann if (!spu_ibox_read(ctx, &ibox_data)) 493*cdcc89bbSArnd Bergmann count = -EAGAIN; 49467207b96SArnd Bergmann } else { 495*cdcc89bbSArnd Bergmann count = spufs_wait(ctx->ibox_wq, spu_ibox_read(ctx, &ibox_data)); 496*cdcc89bbSArnd Bergmann } 497*cdcc89bbSArnd Bergmann if (count) 498*cdcc89bbSArnd Bergmann goto out; 499*cdcc89bbSArnd Bergmann 500*cdcc89bbSArnd Bergmann /* if we can't write at all, return -EFAULT */ 501*cdcc89bbSArnd Bergmann count = __put_user(ibox_data, udata); 502*cdcc89bbSArnd Bergmann if (count) 503*cdcc89bbSArnd Bergmann goto out; 504*cdcc89bbSArnd Bergmann 505*cdcc89bbSArnd Bergmann for (count = 4, udata++; (count + 4) <= len; count += 4, udata++) { 506*cdcc89bbSArnd Bergmann int ret; 507*cdcc89bbSArnd Bergmann ret = ctx->ops->ibox_read(ctx, &ibox_data); 508*cdcc89bbSArnd Bergmann if (ret == 0) 509*cdcc89bbSArnd Bergmann break; 510*cdcc89bbSArnd Bergmann /* 511*cdcc89bbSArnd Bergmann * at the end of the mapped area, we can fault 512*cdcc89bbSArnd Bergmann * but still need to return the data we have 513*cdcc89bbSArnd Bergmann * read successfully so far. 514*cdcc89bbSArnd Bergmann */ 515*cdcc89bbSArnd Bergmann ret = __put_user(ibox_data, udata); 516*cdcc89bbSArnd Bergmann if (ret) 517*cdcc89bbSArnd Bergmann break; 51867207b96SArnd Bergmann } 51967207b96SArnd Bergmann 520*cdcc89bbSArnd Bergmann out: 5218b3d6663SArnd Bergmann spu_release(ctx); 5228b3d6663SArnd Bergmann 523*cdcc89bbSArnd Bergmann return count; 52467207b96SArnd Bergmann } 52567207b96SArnd Bergmann 52667207b96SArnd Bergmann static unsigned int spufs_ibox_poll(struct file *file, poll_table *wait) 52767207b96SArnd Bergmann { 5288b3d6663SArnd Bergmann struct spu_context *ctx = file->private_data; 52967207b96SArnd Bergmann unsigned int mask; 53067207b96SArnd Bergmann 5318b3d6663SArnd Bergmann poll_wait(file, &ctx->ibox_wq, wait); 53267207b96SArnd Bergmann 5333a843d7cSArnd Bergmann spu_acquire(ctx); 5343a843d7cSArnd Bergmann mask = ctx->ops->mbox_stat_poll(ctx, POLLIN | POLLRDNORM); 5353a843d7cSArnd Bergmann spu_release(ctx); 53667207b96SArnd Bergmann 53767207b96SArnd Bergmann return mask; 53867207b96SArnd Bergmann } 53967207b96SArnd Bergmann 54067207b96SArnd Bergmann static struct file_operations spufs_ibox_fops = { 54167207b96SArnd Bergmann .open = spufs_pipe_open, 54267207b96SArnd Bergmann .read = spufs_ibox_read, 54367207b96SArnd Bergmann .poll = spufs_ibox_poll, 54467207b96SArnd Bergmann .fasync = spufs_ibox_fasync, 54567207b96SArnd Bergmann }; 54667207b96SArnd Bergmann 54767207b96SArnd Bergmann static ssize_t spufs_ibox_stat_read(struct file *file, char __user *buf, 54867207b96SArnd Bergmann size_t len, loff_t *pos) 54967207b96SArnd Bergmann { 5508b3d6663SArnd Bergmann struct spu_context *ctx = file->private_data; 55167207b96SArnd Bergmann u32 ibox_stat; 55267207b96SArnd Bergmann 55367207b96SArnd Bergmann if (len < 4) 55467207b96SArnd Bergmann return -EINVAL; 55567207b96SArnd Bergmann 5568b3d6663SArnd Bergmann spu_acquire(ctx); 5578b3d6663SArnd Bergmann ibox_stat = (ctx->ops->mbox_stat_read(ctx) >> 16) & 0xff; 5588b3d6663SArnd Bergmann spu_release(ctx); 55967207b96SArnd Bergmann 56067207b96SArnd Bergmann if (copy_to_user(buf, &ibox_stat, sizeof ibox_stat)) 56167207b96SArnd Bergmann return -EFAULT; 56267207b96SArnd Bergmann 56367207b96SArnd Bergmann return 4; 56467207b96SArnd Bergmann } 56567207b96SArnd Bergmann 56667207b96SArnd Bergmann static struct file_operations spufs_ibox_stat_fops = { 56767207b96SArnd Bergmann .open = spufs_pipe_open, 56867207b96SArnd Bergmann .read = spufs_ibox_stat_read, 56967207b96SArnd Bergmann }; 57067207b96SArnd Bergmann 57167207b96SArnd Bergmann /* low-level mailbox write */ 5728b3d6663SArnd Bergmann size_t spu_wbox_write(struct spu_context *ctx, u32 data) 57367207b96SArnd Bergmann { 5748b3d6663SArnd Bergmann return ctx->ops->wbox_write(ctx, data); 57567207b96SArnd Bergmann } 57667207b96SArnd Bergmann 57767207b96SArnd Bergmann static int spufs_wbox_fasync(int fd, struct file *file, int on) 57867207b96SArnd Bergmann { 5798b3d6663SArnd Bergmann struct spu_context *ctx = file->private_data; 5808b3d6663SArnd Bergmann int ret; 5818b3d6663SArnd Bergmann 5828b3d6663SArnd Bergmann ret = fasync_helper(fd, file, on, &ctx->wbox_fasync); 5838b3d6663SArnd Bergmann 5848b3d6663SArnd Bergmann return ret; 5858b3d6663SArnd Bergmann } 5868b3d6663SArnd Bergmann 5878b3d6663SArnd Bergmann /* interrupt-level wbox callback function. */ 5888b3d6663SArnd Bergmann void spufs_wbox_callback(struct spu *spu) 5898b3d6663SArnd Bergmann { 5908b3d6663SArnd Bergmann struct spu_context *ctx = spu->ctx; 5918b3d6663SArnd Bergmann 5928b3d6663SArnd Bergmann wake_up_all(&ctx->wbox_wq); 5938b3d6663SArnd Bergmann kill_fasync(&ctx->wbox_fasync, SIGIO, POLLOUT); 59467207b96SArnd Bergmann } 59567207b96SArnd Bergmann 596*cdcc89bbSArnd Bergmann /* 597*cdcc89bbSArnd Bergmann * Write as many bytes to the interrupt mailbox as possible, until 598*cdcc89bbSArnd Bergmann * one of the conditions becomes true: 599*cdcc89bbSArnd Bergmann * 600*cdcc89bbSArnd Bergmann * - the mailbox is full 601*cdcc89bbSArnd Bergmann * - end of the user provided buffer 602*cdcc89bbSArnd Bergmann * - end of the mapped area 603*cdcc89bbSArnd Bergmann * 604*cdcc89bbSArnd Bergmann * If the file is opened without O_NONBLOCK, we wait here until 605*cdcc89bbSArnd Bergmann * space is availabyl, but return when we have been able to 606*cdcc89bbSArnd Bergmann * write something. 607*cdcc89bbSArnd Bergmann */ 60867207b96SArnd Bergmann static ssize_t spufs_wbox_write(struct file *file, const char __user *buf, 60967207b96SArnd Bergmann size_t len, loff_t *pos) 61067207b96SArnd Bergmann { 6118b3d6663SArnd Bergmann struct spu_context *ctx = file->private_data; 612*cdcc89bbSArnd Bergmann u32 wbox_data, __user *udata; 613*cdcc89bbSArnd Bergmann ssize_t count; 61467207b96SArnd Bergmann 61567207b96SArnd Bergmann if (len < 4) 61667207b96SArnd Bergmann return -EINVAL; 61767207b96SArnd Bergmann 618*cdcc89bbSArnd Bergmann udata = (void __user *)buf; 619*cdcc89bbSArnd Bergmann if (!access_ok(VERIFY_READ, buf, len)) 620*cdcc89bbSArnd Bergmann return -EFAULT; 621*cdcc89bbSArnd Bergmann 622*cdcc89bbSArnd Bergmann if (__get_user(wbox_data, udata)) 62367207b96SArnd Bergmann return -EFAULT; 62467207b96SArnd Bergmann 6258b3d6663SArnd Bergmann spu_acquire(ctx); 6268b3d6663SArnd Bergmann 627*cdcc89bbSArnd Bergmann /* 628*cdcc89bbSArnd Bergmann * make sure we can at least write one element, by waiting 629*cdcc89bbSArnd Bergmann * in case of !O_NONBLOCK 630*cdcc89bbSArnd Bergmann */ 631*cdcc89bbSArnd Bergmann count = 0; 63267207b96SArnd Bergmann if (file->f_flags & O_NONBLOCK) { 6338b3d6663SArnd Bergmann if (!spu_wbox_write(ctx, wbox_data)) 634*cdcc89bbSArnd Bergmann count = -EAGAIN; 63567207b96SArnd Bergmann } else { 636*cdcc89bbSArnd Bergmann count = spufs_wait(ctx->wbox_wq, spu_wbox_write(ctx, wbox_data)); 63767207b96SArnd Bergmann } 63867207b96SArnd Bergmann 639*cdcc89bbSArnd Bergmann if (count) 640*cdcc89bbSArnd Bergmann goto out; 6418b3d6663SArnd Bergmann 642*cdcc89bbSArnd Bergmann /* write aѕ much as possible */ 643*cdcc89bbSArnd Bergmann for (count = 4, udata++; (count + 4) <= len; count += 4, udata++) { 644*cdcc89bbSArnd Bergmann int ret; 645*cdcc89bbSArnd Bergmann ret = __get_user(wbox_data, udata); 646*cdcc89bbSArnd Bergmann if (ret) 647*cdcc89bbSArnd Bergmann break; 648*cdcc89bbSArnd Bergmann 649*cdcc89bbSArnd Bergmann ret = spu_wbox_write(ctx, wbox_data); 650*cdcc89bbSArnd Bergmann if (ret == 0) 651*cdcc89bbSArnd Bergmann break; 652*cdcc89bbSArnd Bergmann } 653*cdcc89bbSArnd Bergmann 654*cdcc89bbSArnd Bergmann out: 655*cdcc89bbSArnd Bergmann spu_release(ctx); 656*cdcc89bbSArnd Bergmann return count; 65767207b96SArnd Bergmann } 65867207b96SArnd Bergmann 65967207b96SArnd Bergmann static unsigned int spufs_wbox_poll(struct file *file, poll_table *wait) 66067207b96SArnd Bergmann { 6618b3d6663SArnd Bergmann struct spu_context *ctx = file->private_data; 66267207b96SArnd Bergmann unsigned int mask; 66367207b96SArnd Bergmann 6648b3d6663SArnd Bergmann poll_wait(file, &ctx->wbox_wq, wait); 66567207b96SArnd Bergmann 6663a843d7cSArnd Bergmann spu_acquire(ctx); 6673a843d7cSArnd Bergmann mask = ctx->ops->mbox_stat_poll(ctx, POLLOUT | POLLWRNORM); 6683a843d7cSArnd Bergmann spu_release(ctx); 66967207b96SArnd Bergmann 67067207b96SArnd Bergmann return mask; 67167207b96SArnd Bergmann } 67267207b96SArnd Bergmann 67367207b96SArnd Bergmann static struct file_operations spufs_wbox_fops = { 67467207b96SArnd Bergmann .open = spufs_pipe_open, 67567207b96SArnd Bergmann .write = spufs_wbox_write, 67667207b96SArnd Bergmann .poll = spufs_wbox_poll, 67767207b96SArnd Bergmann .fasync = spufs_wbox_fasync, 67867207b96SArnd Bergmann }; 67967207b96SArnd Bergmann 68067207b96SArnd Bergmann static ssize_t spufs_wbox_stat_read(struct file *file, char __user *buf, 68167207b96SArnd Bergmann size_t len, loff_t *pos) 68267207b96SArnd Bergmann { 6838b3d6663SArnd Bergmann struct spu_context *ctx = file->private_data; 68467207b96SArnd Bergmann u32 wbox_stat; 68567207b96SArnd Bergmann 68667207b96SArnd Bergmann if (len < 4) 68767207b96SArnd Bergmann return -EINVAL; 68867207b96SArnd Bergmann 6898b3d6663SArnd Bergmann spu_acquire(ctx); 6908b3d6663SArnd Bergmann wbox_stat = (ctx->ops->mbox_stat_read(ctx) >> 8) & 0xff; 6918b3d6663SArnd Bergmann spu_release(ctx); 69267207b96SArnd Bergmann 69367207b96SArnd Bergmann if (copy_to_user(buf, &wbox_stat, sizeof wbox_stat)) 69467207b96SArnd Bergmann return -EFAULT; 69567207b96SArnd Bergmann 69667207b96SArnd Bergmann return 4; 69767207b96SArnd Bergmann } 69867207b96SArnd Bergmann 69967207b96SArnd Bergmann static struct file_operations spufs_wbox_stat_fops = { 70067207b96SArnd Bergmann .open = spufs_pipe_open, 70167207b96SArnd Bergmann .read = spufs_wbox_stat_read, 70267207b96SArnd Bergmann }; 70367207b96SArnd Bergmann 7046df10a82SMark Nutter static int spufs_signal1_open(struct inode *inode, struct file *file) 7056df10a82SMark Nutter { 7066df10a82SMark Nutter struct spufs_inode_info *i = SPUFS_I(inode); 7076df10a82SMark Nutter struct spu_context *ctx = i->i_ctx; 7086df10a82SMark Nutter file->private_data = ctx; 7096df10a82SMark Nutter file->f_mapping = inode->i_mapping; 7106df10a82SMark Nutter ctx->signal1 = inode->i_mapping; 7116df10a82SMark Nutter return nonseekable_open(inode, file); 7126df10a82SMark Nutter } 7136df10a82SMark Nutter 71467207b96SArnd Bergmann static ssize_t spufs_signal1_read(struct file *file, char __user *buf, 71567207b96SArnd Bergmann size_t len, loff_t *pos) 71667207b96SArnd Bergmann { 7178b3d6663SArnd Bergmann struct spu_context *ctx = file->private_data; 71867207b96SArnd Bergmann u32 data; 71967207b96SArnd Bergmann 72067207b96SArnd Bergmann if (len < 4) 72167207b96SArnd Bergmann return -EINVAL; 72267207b96SArnd Bergmann 7238b3d6663SArnd Bergmann spu_acquire(ctx); 7248b3d6663SArnd Bergmann data = ctx->ops->signal1_read(ctx); 7258b3d6663SArnd Bergmann spu_release(ctx); 7268b3d6663SArnd Bergmann 72767207b96SArnd Bergmann if (copy_to_user(buf, &data, 4)) 72867207b96SArnd Bergmann return -EFAULT; 72967207b96SArnd Bergmann 73067207b96SArnd Bergmann return 4; 73167207b96SArnd Bergmann } 73267207b96SArnd Bergmann 73367207b96SArnd Bergmann static ssize_t spufs_signal1_write(struct file *file, const char __user *buf, 73467207b96SArnd Bergmann size_t len, loff_t *pos) 73567207b96SArnd Bergmann { 73667207b96SArnd Bergmann struct spu_context *ctx; 73767207b96SArnd Bergmann u32 data; 73867207b96SArnd Bergmann 73967207b96SArnd Bergmann ctx = file->private_data; 74067207b96SArnd Bergmann 74167207b96SArnd Bergmann if (len < 4) 74267207b96SArnd Bergmann return -EINVAL; 74367207b96SArnd Bergmann 74467207b96SArnd Bergmann if (copy_from_user(&data, buf, 4)) 74567207b96SArnd Bergmann return -EFAULT; 74667207b96SArnd Bergmann 7478b3d6663SArnd Bergmann spu_acquire(ctx); 7488b3d6663SArnd Bergmann ctx->ops->signal1_write(ctx, data); 7498b3d6663SArnd Bergmann spu_release(ctx); 75067207b96SArnd Bergmann 75167207b96SArnd Bergmann return 4; 75267207b96SArnd Bergmann } 75367207b96SArnd Bergmann 7546df10a82SMark Nutter static struct page *spufs_signal1_mmap_nopage(struct vm_area_struct *vma, 7556df10a82SMark Nutter unsigned long address, int *type) 7566df10a82SMark Nutter { 75727d5bf2aSBenjamin Herrenschmidt #if PAGE_SIZE == 0x1000 75827d5bf2aSBenjamin Herrenschmidt return spufs_ps_nopage(vma, address, type, 0x14000, 0x1000); 75927d5bf2aSBenjamin Herrenschmidt #elif PAGE_SIZE == 0x10000 76027d5bf2aSBenjamin Herrenschmidt /* For 64k pages, both signal1 and signal2 can be used to mmap the whole 76127d5bf2aSBenjamin Herrenschmidt * signal 1 and 2 area 76227d5bf2aSBenjamin Herrenschmidt */ 76327d5bf2aSBenjamin Herrenschmidt return spufs_ps_nopage(vma, address, type, 0x10000, 0x10000); 76427d5bf2aSBenjamin Herrenschmidt #else 76527d5bf2aSBenjamin Herrenschmidt #error unsupported page size 76627d5bf2aSBenjamin Herrenschmidt #endif 7676df10a82SMark Nutter } 7686df10a82SMark Nutter 7696df10a82SMark Nutter static struct vm_operations_struct spufs_signal1_mmap_vmops = { 7706df10a82SMark Nutter .nopage = spufs_signal1_mmap_nopage, 7716df10a82SMark Nutter }; 7726df10a82SMark Nutter 7736df10a82SMark Nutter static int spufs_signal1_mmap(struct file *file, struct vm_area_struct *vma) 7746df10a82SMark Nutter { 7756df10a82SMark Nutter if (!(vma->vm_flags & VM_SHARED)) 7766df10a82SMark Nutter return -EINVAL; 7776df10a82SMark Nutter 7786df10a82SMark Nutter vma->vm_flags |= VM_RESERVED; 7796df10a82SMark Nutter vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot) 78023cc7701SBenjamin Herrenschmidt | _PAGE_NO_CACHE | _PAGE_GUARDED); 7816df10a82SMark Nutter 7826df10a82SMark Nutter vma->vm_ops = &spufs_signal1_mmap_vmops; 7836df10a82SMark Nutter return 0; 7846df10a82SMark Nutter } 7856df10a82SMark Nutter 78667207b96SArnd Bergmann static struct file_operations spufs_signal1_fops = { 7876df10a82SMark Nutter .open = spufs_signal1_open, 78867207b96SArnd Bergmann .read = spufs_signal1_read, 78967207b96SArnd Bergmann .write = spufs_signal1_write, 7906df10a82SMark Nutter .mmap = spufs_signal1_mmap, 79167207b96SArnd Bergmann }; 79267207b96SArnd Bergmann 7936df10a82SMark Nutter static int spufs_signal2_open(struct inode *inode, struct file *file) 7946df10a82SMark Nutter { 7956df10a82SMark Nutter struct spufs_inode_info *i = SPUFS_I(inode); 7966df10a82SMark Nutter struct spu_context *ctx = i->i_ctx; 7976df10a82SMark Nutter file->private_data = ctx; 7986df10a82SMark Nutter file->f_mapping = inode->i_mapping; 7996df10a82SMark Nutter ctx->signal2 = inode->i_mapping; 8006df10a82SMark Nutter return nonseekable_open(inode, file); 8016df10a82SMark Nutter } 8026df10a82SMark Nutter 80367207b96SArnd Bergmann static ssize_t spufs_signal2_read(struct file *file, char __user *buf, 80467207b96SArnd Bergmann size_t len, loff_t *pos) 80567207b96SArnd Bergmann { 80667207b96SArnd Bergmann struct spu_context *ctx; 80767207b96SArnd Bergmann u32 data; 80867207b96SArnd Bergmann 80967207b96SArnd Bergmann ctx = file->private_data; 81067207b96SArnd Bergmann 81167207b96SArnd Bergmann if (len < 4) 81267207b96SArnd Bergmann return -EINVAL; 81367207b96SArnd Bergmann 8148b3d6663SArnd Bergmann spu_acquire(ctx); 8158b3d6663SArnd Bergmann data = ctx->ops->signal2_read(ctx); 8168b3d6663SArnd Bergmann spu_release(ctx); 8178b3d6663SArnd Bergmann 81867207b96SArnd Bergmann if (copy_to_user(buf, &data, 4)) 81967207b96SArnd Bergmann return -EFAULT; 82067207b96SArnd Bergmann 82167207b96SArnd Bergmann return 4; 82267207b96SArnd Bergmann } 82367207b96SArnd Bergmann 82467207b96SArnd Bergmann static ssize_t spufs_signal2_write(struct file *file, const char __user *buf, 82567207b96SArnd Bergmann size_t len, loff_t *pos) 82667207b96SArnd Bergmann { 82767207b96SArnd Bergmann struct spu_context *ctx; 82867207b96SArnd Bergmann u32 data; 82967207b96SArnd Bergmann 83067207b96SArnd Bergmann ctx = file->private_data; 83167207b96SArnd Bergmann 83267207b96SArnd Bergmann if (len < 4) 83367207b96SArnd Bergmann return -EINVAL; 83467207b96SArnd Bergmann 83567207b96SArnd Bergmann if (copy_from_user(&data, buf, 4)) 83667207b96SArnd Bergmann return -EFAULT; 83767207b96SArnd Bergmann 8388b3d6663SArnd Bergmann spu_acquire(ctx); 8398b3d6663SArnd Bergmann ctx->ops->signal2_write(ctx, data); 8408b3d6663SArnd Bergmann spu_release(ctx); 84167207b96SArnd Bergmann 84267207b96SArnd Bergmann return 4; 84367207b96SArnd Bergmann } 84467207b96SArnd Bergmann 84527d5bf2aSBenjamin Herrenschmidt #if SPUFS_MMAP_4K 8466df10a82SMark Nutter static struct page *spufs_signal2_mmap_nopage(struct vm_area_struct *vma, 8476df10a82SMark Nutter unsigned long address, int *type) 8486df10a82SMark Nutter { 84927d5bf2aSBenjamin Herrenschmidt #if PAGE_SIZE == 0x1000 85027d5bf2aSBenjamin Herrenschmidt return spufs_ps_nopage(vma, address, type, 0x1c000, 0x1000); 85127d5bf2aSBenjamin Herrenschmidt #elif PAGE_SIZE == 0x10000 85227d5bf2aSBenjamin Herrenschmidt /* For 64k pages, both signal1 and signal2 can be used to mmap the whole 85327d5bf2aSBenjamin Herrenschmidt * signal 1 and 2 area 85427d5bf2aSBenjamin Herrenschmidt */ 85527d5bf2aSBenjamin Herrenschmidt return spufs_ps_nopage(vma, address, type, 0x10000, 0x10000); 85627d5bf2aSBenjamin Herrenschmidt #else 85727d5bf2aSBenjamin Herrenschmidt #error unsupported page size 85827d5bf2aSBenjamin Herrenschmidt #endif 8596df10a82SMark Nutter } 8606df10a82SMark Nutter 8616df10a82SMark Nutter static struct vm_operations_struct spufs_signal2_mmap_vmops = { 8626df10a82SMark Nutter .nopage = spufs_signal2_mmap_nopage, 8636df10a82SMark Nutter }; 8646df10a82SMark Nutter 8656df10a82SMark Nutter static int spufs_signal2_mmap(struct file *file, struct vm_area_struct *vma) 8666df10a82SMark Nutter { 8676df10a82SMark Nutter if (!(vma->vm_flags & VM_SHARED)) 8686df10a82SMark Nutter return -EINVAL; 8696df10a82SMark Nutter 8706df10a82SMark Nutter /* FIXME: */ 8716df10a82SMark Nutter vma->vm_flags |= VM_RESERVED; 8726df10a82SMark Nutter vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot) 87323cc7701SBenjamin Herrenschmidt | _PAGE_NO_CACHE | _PAGE_GUARDED); 8746df10a82SMark Nutter 8756df10a82SMark Nutter vma->vm_ops = &spufs_signal2_mmap_vmops; 8766df10a82SMark Nutter return 0; 8776df10a82SMark Nutter } 87827d5bf2aSBenjamin Herrenschmidt #else /* SPUFS_MMAP_4K */ 87927d5bf2aSBenjamin Herrenschmidt #define spufs_signal2_mmap NULL 88027d5bf2aSBenjamin Herrenschmidt #endif /* !SPUFS_MMAP_4K */ 8816df10a82SMark Nutter 88267207b96SArnd Bergmann static struct file_operations spufs_signal2_fops = { 8836df10a82SMark Nutter .open = spufs_signal2_open, 88467207b96SArnd Bergmann .read = spufs_signal2_read, 88567207b96SArnd Bergmann .write = spufs_signal2_write, 8866df10a82SMark Nutter .mmap = spufs_signal2_mmap, 88767207b96SArnd Bergmann }; 88867207b96SArnd Bergmann 88967207b96SArnd Bergmann static void spufs_signal1_type_set(void *data, u64 val) 89067207b96SArnd Bergmann { 89167207b96SArnd Bergmann struct spu_context *ctx = data; 89267207b96SArnd Bergmann 8938b3d6663SArnd Bergmann spu_acquire(ctx); 8948b3d6663SArnd Bergmann ctx->ops->signal1_type_set(ctx, val); 8958b3d6663SArnd Bergmann spu_release(ctx); 89667207b96SArnd Bergmann } 89767207b96SArnd Bergmann 89867207b96SArnd Bergmann static u64 spufs_signal1_type_get(void *data) 89967207b96SArnd Bergmann { 90067207b96SArnd Bergmann struct spu_context *ctx = data; 9018b3d6663SArnd Bergmann u64 ret; 9028b3d6663SArnd Bergmann 9038b3d6663SArnd Bergmann spu_acquire(ctx); 9048b3d6663SArnd Bergmann ret = ctx->ops->signal1_type_get(ctx); 9058b3d6663SArnd Bergmann spu_release(ctx); 9068b3d6663SArnd Bergmann 9078b3d6663SArnd Bergmann return ret; 90867207b96SArnd Bergmann } 90967207b96SArnd Bergmann DEFINE_SIMPLE_ATTRIBUTE(spufs_signal1_type, spufs_signal1_type_get, 91067207b96SArnd Bergmann spufs_signal1_type_set, "%llu"); 91167207b96SArnd Bergmann 91267207b96SArnd Bergmann static void spufs_signal2_type_set(void *data, u64 val) 91367207b96SArnd Bergmann { 91467207b96SArnd Bergmann struct spu_context *ctx = data; 91567207b96SArnd Bergmann 9168b3d6663SArnd Bergmann spu_acquire(ctx); 9178b3d6663SArnd Bergmann ctx->ops->signal2_type_set(ctx, val); 9188b3d6663SArnd Bergmann spu_release(ctx); 91967207b96SArnd Bergmann } 92067207b96SArnd Bergmann 92167207b96SArnd Bergmann static u64 spufs_signal2_type_get(void *data) 92267207b96SArnd Bergmann { 92367207b96SArnd Bergmann struct spu_context *ctx = data; 9248b3d6663SArnd Bergmann u64 ret; 9258b3d6663SArnd Bergmann 9268b3d6663SArnd Bergmann spu_acquire(ctx); 9278b3d6663SArnd Bergmann ret = ctx->ops->signal2_type_get(ctx); 9288b3d6663SArnd Bergmann spu_release(ctx); 9298b3d6663SArnd Bergmann 9308b3d6663SArnd Bergmann return ret; 93167207b96SArnd Bergmann } 93267207b96SArnd Bergmann DEFINE_SIMPLE_ATTRIBUTE(spufs_signal2_type, spufs_signal2_type_get, 93367207b96SArnd Bergmann spufs_signal2_type_set, "%llu"); 93467207b96SArnd Bergmann 93527d5bf2aSBenjamin Herrenschmidt #if SPUFS_MMAP_4K 936d9379c4bSarnd@arndb.de static struct page *spufs_mss_mmap_nopage(struct vm_area_struct *vma, 937d9379c4bSarnd@arndb.de unsigned long address, int *type) 938d9379c4bSarnd@arndb.de { 93927d5bf2aSBenjamin Herrenschmidt return spufs_ps_nopage(vma, address, type, 0x0000, 0x1000); 940d9379c4bSarnd@arndb.de } 941d9379c4bSarnd@arndb.de 942d9379c4bSarnd@arndb.de static struct vm_operations_struct spufs_mss_mmap_vmops = { 943d9379c4bSarnd@arndb.de .nopage = spufs_mss_mmap_nopage, 944d9379c4bSarnd@arndb.de }; 945d9379c4bSarnd@arndb.de 946d9379c4bSarnd@arndb.de /* 947d9379c4bSarnd@arndb.de * mmap support for problem state MFC DMA area [0x0000 - 0x0fff]. 948d9379c4bSarnd@arndb.de */ 949d9379c4bSarnd@arndb.de static int spufs_mss_mmap(struct file *file, struct vm_area_struct *vma) 950d9379c4bSarnd@arndb.de { 951d9379c4bSarnd@arndb.de if (!(vma->vm_flags & VM_SHARED)) 952d9379c4bSarnd@arndb.de return -EINVAL; 953d9379c4bSarnd@arndb.de 954d9379c4bSarnd@arndb.de vma->vm_flags |= VM_RESERVED; 955d9379c4bSarnd@arndb.de vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot) 95623cc7701SBenjamin Herrenschmidt | _PAGE_NO_CACHE | _PAGE_GUARDED); 957d9379c4bSarnd@arndb.de 958d9379c4bSarnd@arndb.de vma->vm_ops = &spufs_mss_mmap_vmops; 959d9379c4bSarnd@arndb.de return 0; 960d9379c4bSarnd@arndb.de } 96127d5bf2aSBenjamin Herrenschmidt #else /* SPUFS_MMAP_4K */ 96227d5bf2aSBenjamin Herrenschmidt #define spufs_mss_mmap NULL 96327d5bf2aSBenjamin Herrenschmidt #endif /* !SPUFS_MMAP_4K */ 964d9379c4bSarnd@arndb.de 965d9379c4bSarnd@arndb.de static int spufs_mss_open(struct inode *inode, struct file *file) 966d9379c4bSarnd@arndb.de { 967d9379c4bSarnd@arndb.de struct spufs_inode_info *i = SPUFS_I(inode); 968d9379c4bSarnd@arndb.de 969d9379c4bSarnd@arndb.de file->private_data = i->i_ctx; 970d9379c4bSarnd@arndb.de return nonseekable_open(inode, file); 971d9379c4bSarnd@arndb.de } 972d9379c4bSarnd@arndb.de 973d9379c4bSarnd@arndb.de static struct file_operations spufs_mss_fops = { 974d9379c4bSarnd@arndb.de .open = spufs_mss_open, 975d9379c4bSarnd@arndb.de .mmap = spufs_mss_mmap, 97627d5bf2aSBenjamin Herrenschmidt }; 97727d5bf2aSBenjamin Herrenschmidt 97827d5bf2aSBenjamin Herrenschmidt static struct page *spufs_psmap_mmap_nopage(struct vm_area_struct *vma, 97927d5bf2aSBenjamin Herrenschmidt unsigned long address, int *type) 98027d5bf2aSBenjamin Herrenschmidt { 98127d5bf2aSBenjamin Herrenschmidt return spufs_ps_nopage(vma, address, type, 0x0000, 0x20000); 98227d5bf2aSBenjamin Herrenschmidt } 98327d5bf2aSBenjamin Herrenschmidt 98427d5bf2aSBenjamin Herrenschmidt static struct vm_operations_struct spufs_psmap_mmap_vmops = { 98527d5bf2aSBenjamin Herrenschmidt .nopage = spufs_psmap_mmap_nopage, 98627d5bf2aSBenjamin Herrenschmidt }; 98727d5bf2aSBenjamin Herrenschmidt 98827d5bf2aSBenjamin Herrenschmidt /* 98927d5bf2aSBenjamin Herrenschmidt * mmap support for full problem state area [0x00000 - 0x1ffff]. 99027d5bf2aSBenjamin Herrenschmidt */ 99127d5bf2aSBenjamin Herrenschmidt static int spufs_psmap_mmap(struct file *file, struct vm_area_struct *vma) 99227d5bf2aSBenjamin Herrenschmidt { 99327d5bf2aSBenjamin Herrenschmidt if (!(vma->vm_flags & VM_SHARED)) 99427d5bf2aSBenjamin Herrenschmidt return -EINVAL; 99527d5bf2aSBenjamin Herrenschmidt 99627d5bf2aSBenjamin Herrenschmidt vma->vm_flags |= VM_RESERVED; 99727d5bf2aSBenjamin Herrenschmidt vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot) 99827d5bf2aSBenjamin Herrenschmidt | _PAGE_NO_CACHE | _PAGE_GUARDED); 99927d5bf2aSBenjamin Herrenschmidt 100027d5bf2aSBenjamin Herrenschmidt vma->vm_ops = &spufs_psmap_mmap_vmops; 100127d5bf2aSBenjamin Herrenschmidt return 0; 100227d5bf2aSBenjamin Herrenschmidt } 100327d5bf2aSBenjamin Herrenschmidt 100427d5bf2aSBenjamin Herrenschmidt static int spufs_psmap_open(struct inode *inode, struct file *file) 100527d5bf2aSBenjamin Herrenschmidt { 100627d5bf2aSBenjamin Herrenschmidt struct spufs_inode_info *i = SPUFS_I(inode); 100727d5bf2aSBenjamin Herrenschmidt 100827d5bf2aSBenjamin Herrenschmidt file->private_data = i->i_ctx; 100927d5bf2aSBenjamin Herrenschmidt return nonseekable_open(inode, file); 101027d5bf2aSBenjamin Herrenschmidt } 101127d5bf2aSBenjamin Herrenschmidt 101227d5bf2aSBenjamin Herrenschmidt static struct file_operations spufs_psmap_fops = { 101327d5bf2aSBenjamin Herrenschmidt .open = spufs_psmap_open, 101427d5bf2aSBenjamin Herrenschmidt .mmap = spufs_psmap_mmap, 1015d9379c4bSarnd@arndb.de }; 1016d9379c4bSarnd@arndb.de 1017d9379c4bSarnd@arndb.de 101827d5bf2aSBenjamin Herrenschmidt #if SPUFS_MMAP_4K 10196df10a82SMark Nutter static struct page *spufs_mfc_mmap_nopage(struct vm_area_struct *vma, 10206df10a82SMark Nutter unsigned long address, int *type) 10216df10a82SMark Nutter { 102227d5bf2aSBenjamin Herrenschmidt return spufs_ps_nopage(vma, address, type, 0x3000, 0x1000); 10236df10a82SMark Nutter } 10246df10a82SMark Nutter 10256df10a82SMark Nutter static struct vm_operations_struct spufs_mfc_mmap_vmops = { 10266df10a82SMark Nutter .nopage = spufs_mfc_mmap_nopage, 10276df10a82SMark Nutter }; 10286df10a82SMark Nutter 10296df10a82SMark Nutter /* 10306df10a82SMark Nutter * mmap support for problem state MFC DMA area [0x0000 - 0x0fff]. 10316df10a82SMark Nutter */ 10326df10a82SMark Nutter static int spufs_mfc_mmap(struct file *file, struct vm_area_struct *vma) 10336df10a82SMark Nutter { 10346df10a82SMark Nutter if (!(vma->vm_flags & VM_SHARED)) 10356df10a82SMark Nutter return -EINVAL; 10366df10a82SMark Nutter 10376df10a82SMark Nutter vma->vm_flags |= VM_RESERVED; 10386df10a82SMark Nutter vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot) 103923cc7701SBenjamin Herrenschmidt | _PAGE_NO_CACHE | _PAGE_GUARDED); 10406df10a82SMark Nutter 10416df10a82SMark Nutter vma->vm_ops = &spufs_mfc_mmap_vmops; 10426df10a82SMark Nutter return 0; 10436df10a82SMark Nutter } 104427d5bf2aSBenjamin Herrenschmidt #else /* SPUFS_MMAP_4K */ 104527d5bf2aSBenjamin Herrenschmidt #define spufs_mfc_mmap NULL 104627d5bf2aSBenjamin Herrenschmidt #endif /* !SPUFS_MMAP_4K */ 1047a33a7d73SArnd Bergmann 1048a33a7d73SArnd Bergmann static int spufs_mfc_open(struct inode *inode, struct file *file) 1049a33a7d73SArnd Bergmann { 1050a33a7d73SArnd Bergmann struct spufs_inode_info *i = SPUFS_I(inode); 1051a33a7d73SArnd Bergmann struct spu_context *ctx = i->i_ctx; 1052a33a7d73SArnd Bergmann 1053a33a7d73SArnd Bergmann /* we don't want to deal with DMA into other processes */ 1054a33a7d73SArnd Bergmann if (ctx->owner != current->mm) 1055a33a7d73SArnd Bergmann return -EINVAL; 1056a33a7d73SArnd Bergmann 1057a33a7d73SArnd Bergmann if (atomic_read(&inode->i_count) != 1) 1058a33a7d73SArnd Bergmann return -EBUSY; 1059a33a7d73SArnd Bergmann 1060a33a7d73SArnd Bergmann file->private_data = ctx; 1061a33a7d73SArnd Bergmann return nonseekable_open(inode, file); 1062a33a7d73SArnd Bergmann } 1063a33a7d73SArnd Bergmann 1064a33a7d73SArnd Bergmann /* interrupt-level mfc callback function. */ 1065a33a7d73SArnd Bergmann void spufs_mfc_callback(struct spu *spu) 1066a33a7d73SArnd Bergmann { 1067a33a7d73SArnd Bergmann struct spu_context *ctx = spu->ctx; 1068a33a7d73SArnd Bergmann 1069a33a7d73SArnd Bergmann wake_up_all(&ctx->mfc_wq); 1070a33a7d73SArnd Bergmann 1071a33a7d73SArnd Bergmann pr_debug("%s %s\n", __FUNCTION__, spu->name); 1072a33a7d73SArnd Bergmann if (ctx->mfc_fasync) { 1073a33a7d73SArnd Bergmann u32 free_elements, tagstatus; 1074a33a7d73SArnd Bergmann unsigned int mask; 1075a33a7d73SArnd Bergmann 1076a33a7d73SArnd Bergmann /* no need for spu_acquire in interrupt context */ 1077a33a7d73SArnd Bergmann free_elements = ctx->ops->get_mfc_free_elements(ctx); 1078a33a7d73SArnd Bergmann tagstatus = ctx->ops->read_mfc_tagstatus(ctx); 1079a33a7d73SArnd Bergmann 1080a33a7d73SArnd Bergmann mask = 0; 1081a33a7d73SArnd Bergmann if (free_elements & 0xffff) 1082a33a7d73SArnd Bergmann mask |= POLLOUT; 1083a33a7d73SArnd Bergmann if (tagstatus & ctx->tagwait) 1084a33a7d73SArnd Bergmann mask |= POLLIN; 1085a33a7d73SArnd Bergmann 1086a33a7d73SArnd Bergmann kill_fasync(&ctx->mfc_fasync, SIGIO, mask); 1087a33a7d73SArnd Bergmann } 1088a33a7d73SArnd Bergmann } 1089a33a7d73SArnd Bergmann 1090a33a7d73SArnd Bergmann static int spufs_read_mfc_tagstatus(struct spu_context *ctx, u32 *status) 1091a33a7d73SArnd Bergmann { 1092a33a7d73SArnd Bergmann /* See if there is one tag group is complete */ 1093a33a7d73SArnd Bergmann /* FIXME we need locking around tagwait */ 1094a33a7d73SArnd Bergmann *status = ctx->ops->read_mfc_tagstatus(ctx) & ctx->tagwait; 1095a33a7d73SArnd Bergmann ctx->tagwait &= ~*status; 1096a33a7d73SArnd Bergmann if (*status) 1097a33a7d73SArnd Bergmann return 1; 1098a33a7d73SArnd Bergmann 1099a33a7d73SArnd Bergmann /* enable interrupt waiting for any tag group, 1100a33a7d73SArnd Bergmann may silently fail if interrupts are already enabled */ 1101a33a7d73SArnd Bergmann ctx->ops->set_mfc_query(ctx, ctx->tagwait, 1); 1102a33a7d73SArnd Bergmann return 0; 1103a33a7d73SArnd Bergmann } 1104a33a7d73SArnd Bergmann 1105a33a7d73SArnd Bergmann static ssize_t spufs_mfc_read(struct file *file, char __user *buffer, 1106a33a7d73SArnd Bergmann size_t size, loff_t *pos) 1107a33a7d73SArnd Bergmann { 1108a33a7d73SArnd Bergmann struct spu_context *ctx = file->private_data; 1109a33a7d73SArnd Bergmann int ret = -EINVAL; 1110a33a7d73SArnd Bergmann u32 status; 1111a33a7d73SArnd Bergmann 1112a33a7d73SArnd Bergmann if (size != 4) 1113a33a7d73SArnd Bergmann goto out; 1114a33a7d73SArnd Bergmann 1115a33a7d73SArnd Bergmann spu_acquire(ctx); 1116a33a7d73SArnd Bergmann if (file->f_flags & O_NONBLOCK) { 1117a33a7d73SArnd Bergmann status = ctx->ops->read_mfc_tagstatus(ctx); 1118a33a7d73SArnd Bergmann if (!(status & ctx->tagwait)) 1119a33a7d73SArnd Bergmann ret = -EAGAIN; 1120a33a7d73SArnd Bergmann else 1121a33a7d73SArnd Bergmann ctx->tagwait &= ~status; 1122a33a7d73SArnd Bergmann } else { 1123a33a7d73SArnd Bergmann ret = spufs_wait(ctx->mfc_wq, 1124a33a7d73SArnd Bergmann spufs_read_mfc_tagstatus(ctx, &status)); 1125a33a7d73SArnd Bergmann } 1126a33a7d73SArnd Bergmann spu_release(ctx); 1127a33a7d73SArnd Bergmann 1128a33a7d73SArnd Bergmann if (ret) 1129a33a7d73SArnd Bergmann goto out; 1130a33a7d73SArnd Bergmann 1131a33a7d73SArnd Bergmann ret = 4; 1132a33a7d73SArnd Bergmann if (copy_to_user(buffer, &status, 4)) 1133a33a7d73SArnd Bergmann ret = -EFAULT; 1134a33a7d73SArnd Bergmann 1135a33a7d73SArnd Bergmann out: 1136a33a7d73SArnd Bergmann return ret; 1137a33a7d73SArnd Bergmann } 1138a33a7d73SArnd Bergmann 1139a33a7d73SArnd Bergmann static int spufs_check_valid_dma(struct mfc_dma_command *cmd) 1140a33a7d73SArnd Bergmann { 1141a33a7d73SArnd Bergmann pr_debug("queueing DMA %x %lx %x %x %x\n", cmd->lsa, 1142a33a7d73SArnd Bergmann cmd->ea, cmd->size, cmd->tag, cmd->cmd); 1143a33a7d73SArnd Bergmann 1144a33a7d73SArnd Bergmann switch (cmd->cmd) { 1145a33a7d73SArnd Bergmann case MFC_PUT_CMD: 1146a33a7d73SArnd Bergmann case MFC_PUTF_CMD: 1147a33a7d73SArnd Bergmann case MFC_PUTB_CMD: 1148a33a7d73SArnd Bergmann case MFC_GET_CMD: 1149a33a7d73SArnd Bergmann case MFC_GETF_CMD: 1150a33a7d73SArnd Bergmann case MFC_GETB_CMD: 1151a33a7d73SArnd Bergmann break; 1152a33a7d73SArnd Bergmann default: 1153a33a7d73SArnd Bergmann pr_debug("invalid DMA opcode %x\n", cmd->cmd); 1154a33a7d73SArnd Bergmann return -EIO; 1155a33a7d73SArnd Bergmann } 1156a33a7d73SArnd Bergmann 1157a33a7d73SArnd Bergmann if ((cmd->lsa & 0xf) != (cmd->ea &0xf)) { 1158a33a7d73SArnd Bergmann pr_debug("invalid DMA alignment, ea %lx lsa %x\n", 1159a33a7d73SArnd Bergmann cmd->ea, cmd->lsa); 1160a33a7d73SArnd Bergmann return -EIO; 1161a33a7d73SArnd Bergmann } 1162a33a7d73SArnd Bergmann 1163a33a7d73SArnd Bergmann switch (cmd->size & 0xf) { 1164a33a7d73SArnd Bergmann case 1: 1165a33a7d73SArnd Bergmann break; 1166a33a7d73SArnd Bergmann case 2: 1167a33a7d73SArnd Bergmann if (cmd->lsa & 1) 1168a33a7d73SArnd Bergmann goto error; 1169a33a7d73SArnd Bergmann break; 1170a33a7d73SArnd Bergmann case 4: 1171a33a7d73SArnd Bergmann if (cmd->lsa & 3) 1172a33a7d73SArnd Bergmann goto error; 1173a33a7d73SArnd Bergmann break; 1174a33a7d73SArnd Bergmann case 8: 1175a33a7d73SArnd Bergmann if (cmd->lsa & 7) 1176a33a7d73SArnd Bergmann goto error; 1177a33a7d73SArnd Bergmann break; 1178a33a7d73SArnd Bergmann case 0: 1179a33a7d73SArnd Bergmann if (cmd->lsa & 15) 1180a33a7d73SArnd Bergmann goto error; 1181a33a7d73SArnd Bergmann break; 1182a33a7d73SArnd Bergmann error: 1183a33a7d73SArnd Bergmann default: 1184a33a7d73SArnd Bergmann pr_debug("invalid DMA alignment %x for size %x\n", 1185a33a7d73SArnd Bergmann cmd->lsa & 0xf, cmd->size); 1186a33a7d73SArnd Bergmann return -EIO; 1187a33a7d73SArnd Bergmann } 1188a33a7d73SArnd Bergmann 1189a33a7d73SArnd Bergmann if (cmd->size > 16 * 1024) { 1190a33a7d73SArnd Bergmann pr_debug("invalid DMA size %x\n", cmd->size); 1191a33a7d73SArnd Bergmann return -EIO; 1192a33a7d73SArnd Bergmann } 1193a33a7d73SArnd Bergmann 1194a33a7d73SArnd Bergmann if (cmd->tag & 0xfff0) { 1195a33a7d73SArnd Bergmann /* we reserve the higher tag numbers for kernel use */ 1196a33a7d73SArnd Bergmann pr_debug("invalid DMA tag\n"); 1197a33a7d73SArnd Bergmann return -EIO; 1198a33a7d73SArnd Bergmann } 1199a33a7d73SArnd Bergmann 1200a33a7d73SArnd Bergmann if (cmd->class) { 1201a33a7d73SArnd Bergmann /* not supported in this version */ 1202a33a7d73SArnd Bergmann pr_debug("invalid DMA class\n"); 1203a33a7d73SArnd Bergmann return -EIO; 1204a33a7d73SArnd Bergmann } 1205a33a7d73SArnd Bergmann 1206a33a7d73SArnd Bergmann return 0; 1207a33a7d73SArnd Bergmann } 1208a33a7d73SArnd Bergmann 1209a33a7d73SArnd Bergmann static int spu_send_mfc_command(struct spu_context *ctx, 1210a33a7d73SArnd Bergmann struct mfc_dma_command cmd, 1211a33a7d73SArnd Bergmann int *error) 1212a33a7d73SArnd Bergmann { 1213a33a7d73SArnd Bergmann *error = ctx->ops->send_mfc_command(ctx, &cmd); 1214a33a7d73SArnd Bergmann if (*error == -EAGAIN) { 1215a33a7d73SArnd Bergmann /* wait for any tag group to complete 1216a33a7d73SArnd Bergmann so we have space for the new command */ 1217a33a7d73SArnd Bergmann ctx->ops->set_mfc_query(ctx, ctx->tagwait, 1); 1218a33a7d73SArnd Bergmann /* try again, because the queue might be 1219a33a7d73SArnd Bergmann empty again */ 1220a33a7d73SArnd Bergmann *error = ctx->ops->send_mfc_command(ctx, &cmd); 1221a33a7d73SArnd Bergmann if (*error == -EAGAIN) 1222a33a7d73SArnd Bergmann return 0; 1223a33a7d73SArnd Bergmann } 1224a33a7d73SArnd Bergmann return 1; 1225a33a7d73SArnd Bergmann } 1226a33a7d73SArnd Bergmann 1227a33a7d73SArnd Bergmann static ssize_t spufs_mfc_write(struct file *file, const char __user *buffer, 1228a33a7d73SArnd Bergmann size_t size, loff_t *pos) 1229a33a7d73SArnd Bergmann { 1230a33a7d73SArnd Bergmann struct spu_context *ctx = file->private_data; 1231a33a7d73SArnd Bergmann struct mfc_dma_command cmd; 1232a33a7d73SArnd Bergmann int ret = -EINVAL; 1233a33a7d73SArnd Bergmann 1234a33a7d73SArnd Bergmann if (size != sizeof cmd) 1235a33a7d73SArnd Bergmann goto out; 1236a33a7d73SArnd Bergmann 1237a33a7d73SArnd Bergmann ret = -EFAULT; 1238a33a7d73SArnd Bergmann if (copy_from_user(&cmd, buffer, sizeof cmd)) 1239a33a7d73SArnd Bergmann goto out; 1240a33a7d73SArnd Bergmann 1241a33a7d73SArnd Bergmann ret = spufs_check_valid_dma(&cmd); 1242a33a7d73SArnd Bergmann if (ret) 1243a33a7d73SArnd Bergmann goto out; 1244a33a7d73SArnd Bergmann 1245a33a7d73SArnd Bergmann spu_acquire_runnable(ctx); 1246a33a7d73SArnd Bergmann if (file->f_flags & O_NONBLOCK) { 1247a33a7d73SArnd Bergmann ret = ctx->ops->send_mfc_command(ctx, &cmd); 1248a33a7d73SArnd Bergmann } else { 1249a33a7d73SArnd Bergmann int status; 1250a33a7d73SArnd Bergmann ret = spufs_wait(ctx->mfc_wq, 1251a33a7d73SArnd Bergmann spu_send_mfc_command(ctx, cmd, &status)); 1252a33a7d73SArnd Bergmann if (status) 1253a33a7d73SArnd Bergmann ret = status; 1254a33a7d73SArnd Bergmann } 1255a33a7d73SArnd Bergmann spu_release(ctx); 1256a33a7d73SArnd Bergmann 1257a33a7d73SArnd Bergmann if (ret) 1258a33a7d73SArnd Bergmann goto out; 1259a33a7d73SArnd Bergmann 1260a33a7d73SArnd Bergmann ctx->tagwait |= 1 << cmd.tag; 1261a33a7d73SArnd Bergmann 1262a33a7d73SArnd Bergmann out: 1263a33a7d73SArnd Bergmann return ret; 1264a33a7d73SArnd Bergmann } 1265a33a7d73SArnd Bergmann 1266a33a7d73SArnd Bergmann static unsigned int spufs_mfc_poll(struct file *file,poll_table *wait) 1267a33a7d73SArnd Bergmann { 1268a33a7d73SArnd Bergmann struct spu_context *ctx = file->private_data; 1269a33a7d73SArnd Bergmann u32 free_elements, tagstatus; 1270a33a7d73SArnd Bergmann unsigned int mask; 1271a33a7d73SArnd Bergmann 1272a33a7d73SArnd Bergmann spu_acquire(ctx); 1273a33a7d73SArnd Bergmann ctx->ops->set_mfc_query(ctx, ctx->tagwait, 2); 1274a33a7d73SArnd Bergmann free_elements = ctx->ops->get_mfc_free_elements(ctx); 1275a33a7d73SArnd Bergmann tagstatus = ctx->ops->read_mfc_tagstatus(ctx); 1276a33a7d73SArnd Bergmann spu_release(ctx); 1277a33a7d73SArnd Bergmann 1278a33a7d73SArnd Bergmann poll_wait(file, &ctx->mfc_wq, wait); 1279a33a7d73SArnd Bergmann 1280a33a7d73SArnd Bergmann mask = 0; 1281a33a7d73SArnd Bergmann if (free_elements & 0xffff) 1282a33a7d73SArnd Bergmann mask |= POLLOUT | POLLWRNORM; 1283a33a7d73SArnd Bergmann if (tagstatus & ctx->tagwait) 1284a33a7d73SArnd Bergmann mask |= POLLIN | POLLRDNORM; 1285a33a7d73SArnd Bergmann 1286a33a7d73SArnd Bergmann pr_debug("%s: free %d tagstatus %d tagwait %d\n", __FUNCTION__, 1287a33a7d73SArnd Bergmann free_elements, tagstatus, ctx->tagwait); 1288a33a7d73SArnd Bergmann 1289a33a7d73SArnd Bergmann return mask; 1290a33a7d73SArnd Bergmann } 1291a33a7d73SArnd Bergmann 129273b6af8aSAl Viro static int spufs_mfc_flush(struct file *file, fl_owner_t id) 1293a33a7d73SArnd Bergmann { 1294a33a7d73SArnd Bergmann struct spu_context *ctx = file->private_data; 1295a33a7d73SArnd Bergmann int ret; 1296a33a7d73SArnd Bergmann 1297a33a7d73SArnd Bergmann spu_acquire(ctx); 1298a33a7d73SArnd Bergmann #if 0 1299a33a7d73SArnd Bergmann /* this currently hangs */ 1300a33a7d73SArnd Bergmann ret = spufs_wait(ctx->mfc_wq, 1301a33a7d73SArnd Bergmann ctx->ops->set_mfc_query(ctx, ctx->tagwait, 2)); 1302a33a7d73SArnd Bergmann if (ret) 1303a33a7d73SArnd Bergmann goto out; 1304a33a7d73SArnd Bergmann ret = spufs_wait(ctx->mfc_wq, 1305a33a7d73SArnd Bergmann ctx->ops->read_mfc_tagstatus(ctx) == ctx->tagwait); 1306a33a7d73SArnd Bergmann out: 1307a33a7d73SArnd Bergmann #else 1308a33a7d73SArnd Bergmann ret = 0; 1309a33a7d73SArnd Bergmann #endif 1310a33a7d73SArnd Bergmann spu_release(ctx); 1311a33a7d73SArnd Bergmann 1312a33a7d73SArnd Bergmann return ret; 1313a33a7d73SArnd Bergmann } 1314a33a7d73SArnd Bergmann 1315a33a7d73SArnd Bergmann static int spufs_mfc_fsync(struct file *file, struct dentry *dentry, 1316a33a7d73SArnd Bergmann int datasync) 1317a33a7d73SArnd Bergmann { 131873b6af8aSAl Viro return spufs_mfc_flush(file, NULL); 1319a33a7d73SArnd Bergmann } 1320a33a7d73SArnd Bergmann 1321a33a7d73SArnd Bergmann static int spufs_mfc_fasync(int fd, struct file *file, int on) 1322a33a7d73SArnd Bergmann { 1323a33a7d73SArnd Bergmann struct spu_context *ctx = file->private_data; 1324a33a7d73SArnd Bergmann 1325a33a7d73SArnd Bergmann return fasync_helper(fd, file, on, &ctx->mfc_fasync); 1326a33a7d73SArnd Bergmann } 1327a33a7d73SArnd Bergmann 1328a33a7d73SArnd Bergmann static struct file_operations spufs_mfc_fops = { 1329a33a7d73SArnd Bergmann .open = spufs_mfc_open, 1330a33a7d73SArnd Bergmann .read = spufs_mfc_read, 1331a33a7d73SArnd Bergmann .write = spufs_mfc_write, 1332a33a7d73SArnd Bergmann .poll = spufs_mfc_poll, 1333a33a7d73SArnd Bergmann .flush = spufs_mfc_flush, 1334a33a7d73SArnd Bergmann .fsync = spufs_mfc_fsync, 1335a33a7d73SArnd Bergmann .fasync = spufs_mfc_fasync, 13366df10a82SMark Nutter .mmap = spufs_mfc_mmap, 1337a33a7d73SArnd Bergmann }; 1338a33a7d73SArnd Bergmann 133967207b96SArnd Bergmann static void spufs_npc_set(void *data, u64 val) 134067207b96SArnd Bergmann { 134167207b96SArnd Bergmann struct spu_context *ctx = data; 13428b3d6663SArnd Bergmann spu_acquire(ctx); 13438b3d6663SArnd Bergmann ctx->ops->npc_write(ctx, val); 13448b3d6663SArnd Bergmann spu_release(ctx); 134567207b96SArnd Bergmann } 134667207b96SArnd Bergmann 134767207b96SArnd Bergmann static u64 spufs_npc_get(void *data) 134867207b96SArnd Bergmann { 134967207b96SArnd Bergmann struct spu_context *ctx = data; 135067207b96SArnd Bergmann u64 ret; 13518b3d6663SArnd Bergmann spu_acquire(ctx); 13528b3d6663SArnd Bergmann ret = ctx->ops->npc_read(ctx); 13538b3d6663SArnd Bergmann spu_release(ctx); 135467207b96SArnd Bergmann return ret; 135567207b96SArnd Bergmann } 135667207b96SArnd Bergmann DEFINE_SIMPLE_ATTRIBUTE(spufs_npc_ops, spufs_npc_get, spufs_npc_set, "%llx\n") 135767207b96SArnd Bergmann 13588b3d6663SArnd Bergmann static void spufs_decr_set(void *data, u64 val) 13598b3d6663SArnd Bergmann { 13608b3d6663SArnd Bergmann struct spu_context *ctx = data; 13618b3d6663SArnd Bergmann struct spu_lscsa *lscsa = ctx->csa.lscsa; 13628b3d6663SArnd Bergmann spu_acquire_saved(ctx); 13638b3d6663SArnd Bergmann lscsa->decr.slot[0] = (u32) val; 13648b3d6663SArnd Bergmann spu_release(ctx); 13658b3d6663SArnd Bergmann } 13668b3d6663SArnd Bergmann 13678b3d6663SArnd Bergmann static u64 spufs_decr_get(void *data) 13688b3d6663SArnd Bergmann { 13698b3d6663SArnd Bergmann struct spu_context *ctx = data; 13708b3d6663SArnd Bergmann struct spu_lscsa *lscsa = ctx->csa.lscsa; 13718b3d6663SArnd Bergmann u64 ret; 13728b3d6663SArnd Bergmann spu_acquire_saved(ctx); 13738b3d6663SArnd Bergmann ret = lscsa->decr.slot[0]; 13748b3d6663SArnd Bergmann spu_release(ctx); 13758b3d6663SArnd Bergmann return ret; 13768b3d6663SArnd Bergmann } 13778b3d6663SArnd Bergmann DEFINE_SIMPLE_ATTRIBUTE(spufs_decr_ops, spufs_decr_get, spufs_decr_set, 13788b3d6663SArnd Bergmann "%llx\n") 13798b3d6663SArnd Bergmann 13808b3d6663SArnd Bergmann static void spufs_decr_status_set(void *data, u64 val) 13818b3d6663SArnd Bergmann { 13828b3d6663SArnd Bergmann struct spu_context *ctx = data; 13838b3d6663SArnd Bergmann struct spu_lscsa *lscsa = ctx->csa.lscsa; 13848b3d6663SArnd Bergmann spu_acquire_saved(ctx); 13858b3d6663SArnd Bergmann lscsa->decr_status.slot[0] = (u32) val; 13868b3d6663SArnd Bergmann spu_release(ctx); 13878b3d6663SArnd Bergmann } 13888b3d6663SArnd Bergmann 13898b3d6663SArnd Bergmann static u64 spufs_decr_status_get(void *data) 13908b3d6663SArnd Bergmann { 13918b3d6663SArnd Bergmann struct spu_context *ctx = data; 13928b3d6663SArnd Bergmann struct spu_lscsa *lscsa = ctx->csa.lscsa; 13938b3d6663SArnd Bergmann u64 ret; 13948b3d6663SArnd Bergmann spu_acquire_saved(ctx); 13958b3d6663SArnd Bergmann ret = lscsa->decr_status.slot[0]; 13968b3d6663SArnd Bergmann spu_release(ctx); 13978b3d6663SArnd Bergmann return ret; 13988b3d6663SArnd Bergmann } 13998b3d6663SArnd Bergmann DEFINE_SIMPLE_ATTRIBUTE(spufs_decr_status_ops, spufs_decr_status_get, 14008b3d6663SArnd Bergmann spufs_decr_status_set, "%llx\n") 14018b3d6663SArnd Bergmann 14028b3d6663SArnd Bergmann static void spufs_spu_tag_mask_set(void *data, u64 val) 14038b3d6663SArnd Bergmann { 14048b3d6663SArnd Bergmann struct spu_context *ctx = data; 14058b3d6663SArnd Bergmann struct spu_lscsa *lscsa = ctx->csa.lscsa; 14068b3d6663SArnd Bergmann spu_acquire_saved(ctx); 14078b3d6663SArnd Bergmann lscsa->tag_mask.slot[0] = (u32) val; 14088b3d6663SArnd Bergmann spu_release(ctx); 14098b3d6663SArnd Bergmann } 14108b3d6663SArnd Bergmann 14118b3d6663SArnd Bergmann static u64 spufs_spu_tag_mask_get(void *data) 14128b3d6663SArnd Bergmann { 14138b3d6663SArnd Bergmann struct spu_context *ctx = data; 14148b3d6663SArnd Bergmann struct spu_lscsa *lscsa = ctx->csa.lscsa; 14158b3d6663SArnd Bergmann u64 ret; 14168b3d6663SArnd Bergmann spu_acquire_saved(ctx); 14178b3d6663SArnd Bergmann ret = lscsa->tag_mask.slot[0]; 14188b3d6663SArnd Bergmann spu_release(ctx); 14198b3d6663SArnd Bergmann return ret; 14208b3d6663SArnd Bergmann } 14218b3d6663SArnd Bergmann DEFINE_SIMPLE_ATTRIBUTE(spufs_spu_tag_mask_ops, spufs_spu_tag_mask_get, 14228b3d6663SArnd Bergmann spufs_spu_tag_mask_set, "%llx\n") 14238b3d6663SArnd Bergmann 14248b3d6663SArnd Bergmann static void spufs_event_mask_set(void *data, u64 val) 14258b3d6663SArnd Bergmann { 14268b3d6663SArnd Bergmann struct spu_context *ctx = data; 14278b3d6663SArnd Bergmann struct spu_lscsa *lscsa = ctx->csa.lscsa; 14288b3d6663SArnd Bergmann spu_acquire_saved(ctx); 14298b3d6663SArnd Bergmann lscsa->event_mask.slot[0] = (u32) val; 14308b3d6663SArnd Bergmann spu_release(ctx); 14318b3d6663SArnd Bergmann } 14328b3d6663SArnd Bergmann 14338b3d6663SArnd Bergmann static u64 spufs_event_mask_get(void *data) 14348b3d6663SArnd Bergmann { 14358b3d6663SArnd Bergmann struct spu_context *ctx = data; 14368b3d6663SArnd Bergmann struct spu_lscsa *lscsa = ctx->csa.lscsa; 14378b3d6663SArnd Bergmann u64 ret; 14388b3d6663SArnd Bergmann spu_acquire_saved(ctx); 14398b3d6663SArnd Bergmann ret = lscsa->event_mask.slot[0]; 14408b3d6663SArnd Bergmann spu_release(ctx); 14418b3d6663SArnd Bergmann return ret; 14428b3d6663SArnd Bergmann } 14438b3d6663SArnd Bergmann DEFINE_SIMPLE_ATTRIBUTE(spufs_event_mask_ops, spufs_event_mask_get, 14448b3d6663SArnd Bergmann spufs_event_mask_set, "%llx\n") 14458b3d6663SArnd Bergmann 14468b3d6663SArnd Bergmann static void spufs_srr0_set(void *data, u64 val) 14478b3d6663SArnd Bergmann { 14488b3d6663SArnd Bergmann struct spu_context *ctx = data; 14498b3d6663SArnd Bergmann struct spu_lscsa *lscsa = ctx->csa.lscsa; 14508b3d6663SArnd Bergmann spu_acquire_saved(ctx); 14518b3d6663SArnd Bergmann lscsa->srr0.slot[0] = (u32) val; 14528b3d6663SArnd Bergmann spu_release(ctx); 14538b3d6663SArnd Bergmann } 14548b3d6663SArnd Bergmann 14558b3d6663SArnd Bergmann static u64 spufs_srr0_get(void *data) 14568b3d6663SArnd Bergmann { 14578b3d6663SArnd Bergmann struct spu_context *ctx = data; 14588b3d6663SArnd Bergmann struct spu_lscsa *lscsa = ctx->csa.lscsa; 14598b3d6663SArnd Bergmann u64 ret; 14608b3d6663SArnd Bergmann spu_acquire_saved(ctx); 14618b3d6663SArnd Bergmann ret = lscsa->srr0.slot[0]; 14628b3d6663SArnd Bergmann spu_release(ctx); 14638b3d6663SArnd Bergmann return ret; 14648b3d6663SArnd Bergmann } 14658b3d6663SArnd Bergmann DEFINE_SIMPLE_ATTRIBUTE(spufs_srr0_ops, spufs_srr0_get, spufs_srr0_set, 14668b3d6663SArnd Bergmann "%llx\n") 14678b3d6663SArnd Bergmann 14687b1a7014Sarnd@arndb.de static u64 spufs_id_get(void *data) 14697b1a7014Sarnd@arndb.de { 14707b1a7014Sarnd@arndb.de struct spu_context *ctx = data; 14717b1a7014Sarnd@arndb.de u64 num; 14727b1a7014Sarnd@arndb.de 14737b1a7014Sarnd@arndb.de spu_acquire(ctx); 14747b1a7014Sarnd@arndb.de if (ctx->state == SPU_STATE_RUNNABLE) 14757b1a7014Sarnd@arndb.de num = ctx->spu->number; 14767b1a7014Sarnd@arndb.de else 14777b1a7014Sarnd@arndb.de num = (unsigned int)-1; 14787b1a7014Sarnd@arndb.de spu_release(ctx); 14797b1a7014Sarnd@arndb.de 14807b1a7014Sarnd@arndb.de return num; 14817b1a7014Sarnd@arndb.de } 1482e45d6634SAl Viro DEFINE_SIMPLE_ATTRIBUTE(spufs_id_ops, spufs_id_get, NULL, "0x%llx\n") 14837b1a7014Sarnd@arndb.de 148467207b96SArnd Bergmann struct tree_descr spufs_dir_contents[] = { 148567207b96SArnd Bergmann { "mem", &spufs_mem_fops, 0666, }, 14868b3d6663SArnd Bergmann { "regs", &spufs_regs_fops, 0666, }, 148767207b96SArnd Bergmann { "mbox", &spufs_mbox_fops, 0444, }, 148867207b96SArnd Bergmann { "ibox", &spufs_ibox_fops, 0444, }, 148967207b96SArnd Bergmann { "wbox", &spufs_wbox_fops, 0222, }, 149067207b96SArnd Bergmann { "mbox_stat", &spufs_mbox_stat_fops, 0444, }, 149167207b96SArnd Bergmann { "ibox_stat", &spufs_ibox_stat_fops, 0444, }, 149267207b96SArnd Bergmann { "wbox_stat", &spufs_wbox_stat_fops, 0444, }, 149367207b96SArnd Bergmann { "signal1", &spufs_signal1_fops, 0666, }, 149467207b96SArnd Bergmann { "signal2", &spufs_signal2_fops, 0666, }, 149567207b96SArnd Bergmann { "signal1_type", &spufs_signal1_type, 0666, }, 149667207b96SArnd Bergmann { "signal2_type", &spufs_signal2_type, 0666, }, 1497d9379c4bSarnd@arndb.de { "mss", &spufs_mss_fops, 0666, }, 1498a33a7d73SArnd Bergmann { "mfc", &spufs_mfc_fops, 0666, }, 14996df10a82SMark Nutter { "cntl", &spufs_cntl_fops, 0666, }, 150067207b96SArnd Bergmann { "npc", &spufs_npc_ops, 0666, }, 15018b3d6663SArnd Bergmann { "fpcr", &spufs_fpcr_fops, 0666, }, 15028b3d6663SArnd Bergmann { "decr", &spufs_decr_ops, 0666, }, 15038b3d6663SArnd Bergmann { "decr_status", &spufs_decr_status_ops, 0666, }, 15048b3d6663SArnd Bergmann { "spu_tag_mask", &spufs_spu_tag_mask_ops, 0666, }, 15058b3d6663SArnd Bergmann { "event_mask", &spufs_event_mask_ops, 0666, }, 15068b3d6663SArnd Bergmann { "srr0", &spufs_srr0_ops, 0666, }, 15077b1a7014Sarnd@arndb.de { "phys-id", &spufs_id_ops, 0666, }, 150827d5bf2aSBenjamin Herrenschmidt { "psmap", &spufs_psmap_fops, 0666, }, 150967207b96SArnd Bergmann {}, 151067207b96SArnd Bergmann }; 1511