Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1 | /* |
| 2 | * SPU file system -- file contents |
| 3 | * |
| 4 | * (C) Copyright IBM Deutschland Entwicklung GmbH 2005 |
| 5 | * |
| 6 | * Author: Arnd Bergmann <arndb@de.ibm.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2, or (at your option) |
| 11 | * any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 21 | */ |
| 22 | |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 23 | #undef DEBUG |
| 24 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 25 | #include <linux/fs.h> |
| 26 | #include <linux/ioctl.h> |
| 27 | #include <linux/module.h> |
Arnd Bergmann | d88cfff | 2005-12-05 22:52:22 -0500 | [diff] [blame] | 28 | #include <linux/pagemap.h> |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 29 | #include <linux/poll.h> |
Arnd Bergmann | 5110459 | 2005-12-05 22:52:25 -0500 | [diff] [blame] | 30 | #include <linux/ptrace.h> |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 31 | |
| 32 | #include <asm/io.h> |
| 33 | #include <asm/semaphore.h> |
| 34 | #include <asm/spu.h> |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 35 | #include <asm/spu_info.h> |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 36 | #include <asm/uaccess.h> |
| 37 | |
| 38 | #include "spufs.h" |
| 39 | |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 40 | #define SPUFS_MMAP_4K (PAGE_SIZE == 0x1000) |
| 41 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 42 | static int |
| 43 | spufs_mem_open(struct inode *inode, struct file *file) |
| 44 | { |
| 45 | struct spufs_inode_info *i = SPUFS_I(inode); |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 46 | struct spu_context *ctx = i->i_ctx; |
| 47 | file->private_data = ctx; |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 48 | ctx->local_store = inode->i_mapping; |
Benjamin Herrenschmidt | 17e0e27 | 2007-02-13 11:46:08 +1100 | [diff] [blame^] | 49 | smp_wmb(); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 50 | return 0; |
| 51 | } |
| 52 | |
| 53 | static ssize_t |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 54 | __spufs_mem_read(struct spu_context *ctx, char __user *buffer, |
| 55 | size_t size, loff_t *pos) |
| 56 | { |
| 57 | char *local_store = ctx->ops->get_ls(ctx); |
| 58 | return simple_read_from_buffer(buffer, size, pos, local_store, |
| 59 | LS_SIZE); |
| 60 | } |
| 61 | |
| 62 | static ssize_t |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 63 | spufs_mem_read(struct file *file, char __user *buffer, |
| 64 | size_t size, loff_t *pos) |
| 65 | { |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 66 | int ret; |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 67 | struct spu_context *ctx = file->private_data; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 68 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 69 | spu_acquire(ctx); |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 70 | ret = __spufs_mem_read(ctx, buffer, size, pos); |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 71 | spu_release(ctx); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 72 | return ret; |
| 73 | } |
| 74 | |
| 75 | static ssize_t |
| 76 | spufs_mem_write(struct file *file, const char __user *buffer, |
| 77 | size_t size, loff_t *pos) |
| 78 | { |
| 79 | struct spu_context *ctx = file->private_data; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 80 | char *local_store; |
| 81 | int ret; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 82 | |
| 83 | size = min_t(ssize_t, LS_SIZE - *pos, size); |
| 84 | if (size <= 0) |
| 85 | return -EFBIG; |
| 86 | *pos += size; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 87 | |
| 88 | spu_acquire(ctx); |
| 89 | |
| 90 | local_store = ctx->ops->get_ls(ctx); |
| 91 | ret = copy_from_user(local_store + *pos - size, |
| 92 | buffer, size) ? -EFAULT : size; |
| 93 | |
| 94 | spu_release(ctx); |
| 95 | return ret; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 96 | } |
| 97 | |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 98 | static unsigned long spufs_mem_mmap_nopfn(struct vm_area_struct *vma, |
| 99 | unsigned long address) |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 100 | { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 101 | struct spu_context *ctx = vma->vm_file->private_data; |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 102 | unsigned long pfn, offset = address - vma->vm_start; |
| 103 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 104 | offset += vma->vm_pgoff << PAGE_SHIFT; |
| 105 | |
| 106 | spu_acquire(ctx); |
| 107 | |
Arnd Bergmann | ac91cb8 | 2006-10-04 17:26:16 +0200 | [diff] [blame] | 108 | if (ctx->state == SPU_STATE_SAVED) { |
| 109 | vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot) |
Arnd Bergmann | 932f535d | 2006-11-20 18:45:06 +0100 | [diff] [blame] | 110 | & ~_PAGE_NO_CACHE); |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 111 | pfn = vmalloc_to_pfn(ctx->csa.lscsa->ls + offset); |
Arnd Bergmann | ac91cb8 | 2006-10-04 17:26:16 +0200 | [diff] [blame] | 112 | } else { |
| 113 | vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot) |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 114 | | _PAGE_NO_CACHE); |
| 115 | pfn = (ctx->spu->local_store_phys + offset) >> PAGE_SHIFT; |
Arnd Bergmann | ac91cb8 | 2006-10-04 17:26:16 +0200 | [diff] [blame] | 116 | } |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 117 | vm_insert_pfn(vma, address, pfn); |
| 118 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 119 | spu_release(ctx); |
| 120 | |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 121 | return NOPFN_REFAULT; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 122 | } |
| 123 | |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 124 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 125 | static struct vm_operations_struct spufs_mem_mmap_vmops = { |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 126 | .nopfn = spufs_mem_mmap_nopfn, |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 127 | }; |
| 128 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 129 | static int |
| 130 | spufs_mem_mmap(struct file *file, struct vm_area_struct *vma) |
| 131 | { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 132 | if (!(vma->vm_flags & VM_SHARED)) |
| 133 | return -EINVAL; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 134 | |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 135 | vma->vm_flags |= VM_IO | VM_PFNMAP; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 136 | vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot) |
| 137 | | _PAGE_NO_CACHE); |
| 138 | |
| 139 | vma->vm_ops = &spufs_mem_mmap_vmops; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 140 | return 0; |
| 141 | } |
| 142 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 143 | static const struct file_operations spufs_mem_fops = { |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 144 | .open = spufs_mem_open, |
| 145 | .read = spufs_mem_read, |
| 146 | .write = spufs_mem_write, |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 147 | .llseek = generic_file_llseek, |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 148 | .mmap = spufs_mem_mmap, |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 149 | }; |
| 150 | |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 151 | static unsigned long spufs_ps_nopfn(struct vm_area_struct *vma, |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 152 | unsigned long address, |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 153 | unsigned long ps_offs, |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 154 | unsigned long ps_size) |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 155 | { |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 156 | struct spu_context *ctx = vma->vm_file->private_data; |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 157 | unsigned long area, offset = address - vma->vm_start; |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 158 | int ret; |
| 159 | |
| 160 | offset += vma->vm_pgoff << PAGE_SHIFT; |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 161 | if (offset >= ps_size) |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 162 | return NOPFN_SIGBUS; |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 163 | |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 164 | /* error here usually means a signal.. we might want to test |
| 165 | * the error code more precisely though |
| 166 | */ |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 167 | ret = spu_acquire_runnable(ctx); |
| 168 | if (ret) |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 169 | return NOPFN_REFAULT; |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 170 | |
| 171 | area = ctx->spu->problem_phys + ps_offs; |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 172 | vm_insert_pfn(vma, address, (area + offset) >> PAGE_SHIFT); |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 173 | spu_release(ctx); |
| 174 | |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 175 | return NOPFN_REFAULT; |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 176 | } |
| 177 | |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 178 | #if SPUFS_MMAP_4K |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 179 | static unsigned long spufs_cntl_mmap_nopfn(struct vm_area_struct *vma, |
| 180 | unsigned long address) |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 181 | { |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 182 | return spufs_ps_nopfn(vma, address, 0x4000, 0x1000); |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | static struct vm_operations_struct spufs_cntl_mmap_vmops = { |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 186 | .nopfn = spufs_cntl_mmap_nopfn, |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 187 | }; |
| 188 | |
| 189 | /* |
| 190 | * mmap support for problem state control area [0x4000 - 0x4fff]. |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 191 | */ |
| 192 | static int spufs_cntl_mmap(struct file *file, struct vm_area_struct *vma) |
| 193 | { |
| 194 | if (!(vma->vm_flags & VM_SHARED)) |
| 195 | return -EINVAL; |
| 196 | |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 197 | vma->vm_flags |= VM_IO | VM_PFNMAP; |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 198 | vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot) |
Benjamin Herrenschmidt | 23cc770 | 2006-06-23 20:57:47 +0200 | [diff] [blame] | 199 | | _PAGE_NO_CACHE | _PAGE_GUARDED); |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 200 | |
| 201 | vma->vm_ops = &spufs_cntl_mmap_vmops; |
| 202 | return 0; |
| 203 | } |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 204 | #else /* SPUFS_MMAP_4K */ |
| 205 | #define spufs_cntl_mmap NULL |
| 206 | #endif /* !SPUFS_MMAP_4K */ |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 207 | |
Arnd Bergmann | e1dbff2 | 2006-10-04 17:26:19 +0200 | [diff] [blame] | 208 | static u64 spufs_cntl_get(void *data) |
| 209 | { |
| 210 | struct spu_context *ctx = data; |
| 211 | u64 val; |
| 212 | |
| 213 | spu_acquire(ctx); |
| 214 | val = ctx->ops->status_read(ctx); |
| 215 | spu_release(ctx); |
| 216 | |
| 217 | return val; |
| 218 | } |
| 219 | |
| 220 | static void spufs_cntl_set(void *data, u64 val) |
| 221 | { |
| 222 | struct spu_context *ctx = data; |
| 223 | |
| 224 | spu_acquire(ctx); |
| 225 | ctx->ops->runcntl_write(ctx, val); |
| 226 | spu_release(ctx); |
| 227 | } |
| 228 | |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 229 | static int spufs_cntl_open(struct inode *inode, struct file *file) |
| 230 | { |
| 231 | struct spufs_inode_info *i = SPUFS_I(inode); |
| 232 | struct spu_context *ctx = i->i_ctx; |
| 233 | |
| 234 | file->private_data = ctx; |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 235 | ctx->cntl = inode->i_mapping; |
Benjamin Herrenschmidt | 17e0e27 | 2007-02-13 11:46:08 +1100 | [diff] [blame^] | 236 | smp_wmb(); |
Arnd Bergmann | e1dbff2 | 2006-10-04 17:26:19 +0200 | [diff] [blame] | 237 | return simple_attr_open(inode, file, spufs_cntl_get, |
| 238 | spufs_cntl_set, "0x%08lx"); |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 239 | } |
| 240 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 241 | static const struct file_operations spufs_cntl_fops = { |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 242 | .open = spufs_cntl_open, |
Noguchi, Masato | 654e4ae | 2006-10-10 10:27:29 +0200 | [diff] [blame] | 243 | .release = simple_attr_close, |
Arnd Bergmann | e1dbff2 | 2006-10-04 17:26:19 +0200 | [diff] [blame] | 244 | .read = simple_attr_read, |
| 245 | .write = simple_attr_write, |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 246 | .mmap = spufs_cntl_mmap, |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 247 | }; |
| 248 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 249 | static int |
| 250 | spufs_regs_open(struct inode *inode, struct file *file) |
| 251 | { |
| 252 | struct spufs_inode_info *i = SPUFS_I(inode); |
| 253 | file->private_data = i->i_ctx; |
| 254 | return 0; |
| 255 | } |
| 256 | |
| 257 | static ssize_t |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 258 | __spufs_regs_read(struct spu_context *ctx, char __user *buffer, |
| 259 | size_t size, loff_t *pos) |
| 260 | { |
| 261 | struct spu_lscsa *lscsa = ctx->csa.lscsa; |
| 262 | return simple_read_from_buffer(buffer, size, pos, |
| 263 | lscsa->gprs, sizeof lscsa->gprs); |
| 264 | } |
| 265 | |
| 266 | static ssize_t |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 267 | spufs_regs_read(struct file *file, char __user *buffer, |
| 268 | size_t size, loff_t *pos) |
| 269 | { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 270 | int ret; |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 271 | struct spu_context *ctx = file->private_data; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 272 | |
| 273 | spu_acquire_saved(ctx); |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 274 | ret = __spufs_regs_read(ctx, buffer, size, pos); |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 275 | spu_release(ctx); |
| 276 | return ret; |
| 277 | } |
| 278 | |
| 279 | static ssize_t |
| 280 | spufs_regs_write(struct file *file, const char __user *buffer, |
| 281 | size_t size, loff_t *pos) |
| 282 | { |
| 283 | struct spu_context *ctx = file->private_data; |
| 284 | struct spu_lscsa *lscsa = ctx->csa.lscsa; |
| 285 | int ret; |
| 286 | |
| 287 | size = min_t(ssize_t, sizeof lscsa->gprs - *pos, size); |
| 288 | if (size <= 0) |
| 289 | return -EFBIG; |
| 290 | *pos += size; |
| 291 | |
| 292 | spu_acquire_saved(ctx); |
| 293 | |
| 294 | ret = copy_from_user(lscsa->gprs + *pos - size, |
| 295 | buffer, size) ? -EFAULT : size; |
| 296 | |
| 297 | spu_release(ctx); |
| 298 | return ret; |
| 299 | } |
| 300 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 301 | static const struct file_operations spufs_regs_fops = { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 302 | .open = spufs_regs_open, |
| 303 | .read = spufs_regs_read, |
| 304 | .write = spufs_regs_write, |
| 305 | .llseek = generic_file_llseek, |
| 306 | }; |
| 307 | |
| 308 | static ssize_t |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 309 | __spufs_fpcr_read(struct spu_context *ctx, char __user * buffer, |
| 310 | size_t size, loff_t * pos) |
| 311 | { |
| 312 | struct spu_lscsa *lscsa = ctx->csa.lscsa; |
| 313 | return simple_read_from_buffer(buffer, size, pos, |
| 314 | &lscsa->fpcr, sizeof(lscsa->fpcr)); |
| 315 | } |
| 316 | |
| 317 | static ssize_t |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 318 | spufs_fpcr_read(struct file *file, char __user * buffer, |
| 319 | size_t size, loff_t * pos) |
| 320 | { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 321 | int ret; |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 322 | struct spu_context *ctx = file->private_data; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 323 | |
| 324 | spu_acquire_saved(ctx); |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 325 | ret = __spufs_fpcr_read(ctx, buffer, size, pos); |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 326 | spu_release(ctx); |
| 327 | return ret; |
| 328 | } |
| 329 | |
| 330 | static ssize_t |
| 331 | spufs_fpcr_write(struct file *file, const char __user * buffer, |
| 332 | size_t size, loff_t * pos) |
| 333 | { |
| 334 | struct spu_context *ctx = file->private_data; |
| 335 | struct spu_lscsa *lscsa = ctx->csa.lscsa; |
| 336 | int ret; |
| 337 | |
| 338 | size = min_t(ssize_t, sizeof(lscsa->fpcr) - *pos, size); |
| 339 | if (size <= 0) |
| 340 | return -EFBIG; |
| 341 | *pos += size; |
| 342 | |
| 343 | spu_acquire_saved(ctx); |
| 344 | |
| 345 | ret = copy_from_user((char *)&lscsa->fpcr + *pos - size, |
| 346 | buffer, size) ? -EFAULT : size; |
| 347 | |
| 348 | spu_release(ctx); |
| 349 | return ret; |
| 350 | } |
| 351 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 352 | static const struct file_operations spufs_fpcr_fops = { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 353 | .open = spufs_regs_open, |
| 354 | .read = spufs_fpcr_read, |
| 355 | .write = spufs_fpcr_write, |
| 356 | .llseek = generic_file_llseek, |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 357 | }; |
| 358 | |
| 359 | /* generic open function for all pipe-like files */ |
| 360 | static int spufs_pipe_open(struct inode *inode, struct file *file) |
| 361 | { |
| 362 | struct spufs_inode_info *i = SPUFS_I(inode); |
| 363 | file->private_data = i->i_ctx; |
| 364 | |
| 365 | return nonseekable_open(inode, file); |
| 366 | } |
| 367 | |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 368 | /* |
| 369 | * Read as many bytes from the mailbox as possible, until |
| 370 | * one of the conditions becomes true: |
| 371 | * |
| 372 | * - no more data available in the mailbox |
| 373 | * - end of the user provided buffer |
| 374 | * - end of the mapped area |
| 375 | */ |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 376 | static ssize_t spufs_mbox_read(struct file *file, char __user *buf, |
| 377 | size_t len, loff_t *pos) |
| 378 | { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 379 | struct spu_context *ctx = file->private_data; |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 380 | u32 mbox_data, __user *udata; |
| 381 | ssize_t count; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 382 | |
| 383 | if (len < 4) |
| 384 | return -EINVAL; |
| 385 | |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 386 | if (!access_ok(VERIFY_WRITE, buf, len)) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 387 | return -EFAULT; |
| 388 | |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 389 | udata = (void __user *)buf; |
| 390 | |
| 391 | spu_acquire(ctx); |
Arnd Bergmann | 274cef5 | 2006-10-24 18:01:42 +0200 | [diff] [blame] | 392 | for (count = 0; (count + 4) <= len; count += 4, udata++) { |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 393 | int ret; |
| 394 | ret = ctx->ops->mbox_read(ctx, &mbox_data); |
| 395 | if (ret == 0) |
| 396 | break; |
| 397 | |
| 398 | /* |
| 399 | * at the end of the mapped area, we can fault |
| 400 | * but still need to return the data we have |
| 401 | * read successfully so far. |
| 402 | */ |
| 403 | ret = __put_user(mbox_data, udata); |
| 404 | if (ret) { |
| 405 | if (!count) |
| 406 | count = -EFAULT; |
| 407 | break; |
| 408 | } |
| 409 | } |
| 410 | spu_release(ctx); |
| 411 | |
| 412 | if (!count) |
| 413 | count = -EAGAIN; |
| 414 | |
| 415 | return count; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 416 | } |
| 417 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 418 | static const struct file_operations spufs_mbox_fops = { |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 419 | .open = spufs_pipe_open, |
| 420 | .read = spufs_mbox_read, |
| 421 | }; |
| 422 | |
| 423 | static ssize_t spufs_mbox_stat_read(struct file *file, char __user *buf, |
| 424 | size_t len, loff_t *pos) |
| 425 | { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 426 | struct spu_context *ctx = file->private_data; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 427 | u32 mbox_stat; |
| 428 | |
| 429 | if (len < 4) |
| 430 | return -EINVAL; |
| 431 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 432 | spu_acquire(ctx); |
| 433 | |
| 434 | mbox_stat = ctx->ops->mbox_stat_read(ctx) & 0xff; |
| 435 | |
| 436 | spu_release(ctx); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 437 | |
| 438 | if (copy_to_user(buf, &mbox_stat, sizeof mbox_stat)) |
| 439 | return -EFAULT; |
| 440 | |
| 441 | return 4; |
| 442 | } |
| 443 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 444 | static const struct file_operations spufs_mbox_stat_fops = { |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 445 | .open = spufs_pipe_open, |
| 446 | .read = spufs_mbox_stat_read, |
| 447 | }; |
| 448 | |
| 449 | /* low-level ibox access function */ |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 450 | size_t spu_ibox_read(struct spu_context *ctx, u32 *data) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 451 | { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 452 | return ctx->ops->ibox_read(ctx, data); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 453 | } |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 454 | |
| 455 | static int spufs_ibox_fasync(int fd, struct file *file, int on) |
| 456 | { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 457 | struct spu_context *ctx = file->private_data; |
| 458 | |
| 459 | return fasync_helper(fd, file, on, &ctx->ibox_fasync); |
| 460 | } |
| 461 | |
| 462 | /* interrupt-level ibox callback function. */ |
| 463 | void spufs_ibox_callback(struct spu *spu) |
| 464 | { |
| 465 | struct spu_context *ctx = spu->ctx; |
| 466 | |
| 467 | wake_up_all(&ctx->ibox_wq); |
| 468 | kill_fasync(&ctx->ibox_fasync, SIGIO, POLLIN); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 469 | } |
| 470 | |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 471 | /* |
| 472 | * Read as many bytes from the interrupt mailbox as possible, until |
| 473 | * one of the conditions becomes true: |
| 474 | * |
| 475 | * - no more data available in the mailbox |
| 476 | * - end of the user provided buffer |
| 477 | * - end of the mapped area |
| 478 | * |
| 479 | * If the file is opened without O_NONBLOCK, we wait here until |
| 480 | * any data is available, but return when we have been able to |
| 481 | * read something. |
| 482 | */ |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 483 | static ssize_t spufs_ibox_read(struct file *file, char __user *buf, |
| 484 | size_t len, loff_t *pos) |
| 485 | { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 486 | struct spu_context *ctx = file->private_data; |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 487 | u32 ibox_data, __user *udata; |
| 488 | ssize_t count; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 489 | |
| 490 | if (len < 4) |
| 491 | return -EINVAL; |
| 492 | |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 493 | if (!access_ok(VERIFY_WRITE, buf, len)) |
| 494 | return -EFAULT; |
| 495 | |
| 496 | udata = (void __user *)buf; |
| 497 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 498 | spu_acquire(ctx); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 499 | |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 500 | /* wait only for the first element */ |
| 501 | count = 0; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 502 | if (file->f_flags & O_NONBLOCK) { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 503 | if (!spu_ibox_read(ctx, &ibox_data)) |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 504 | count = -EAGAIN; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 505 | } else { |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 506 | count = spufs_wait(ctx->ibox_wq, spu_ibox_read(ctx, &ibox_data)); |
| 507 | } |
| 508 | if (count) |
| 509 | goto out; |
| 510 | |
| 511 | /* if we can't write at all, return -EFAULT */ |
| 512 | count = __put_user(ibox_data, udata); |
| 513 | if (count) |
| 514 | goto out; |
| 515 | |
| 516 | for (count = 4, udata++; (count + 4) <= len; count += 4, udata++) { |
| 517 | int ret; |
| 518 | ret = ctx->ops->ibox_read(ctx, &ibox_data); |
| 519 | if (ret == 0) |
| 520 | break; |
| 521 | /* |
| 522 | * at the end of the mapped area, we can fault |
| 523 | * but still need to return the data we have |
| 524 | * read successfully so far. |
| 525 | */ |
| 526 | ret = __put_user(ibox_data, udata); |
| 527 | if (ret) |
| 528 | break; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 529 | } |
| 530 | |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 531 | out: |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 532 | spu_release(ctx); |
| 533 | |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 534 | return count; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | static unsigned int spufs_ibox_poll(struct file *file, poll_table *wait) |
| 538 | { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 539 | struct spu_context *ctx = file->private_data; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 540 | unsigned int mask; |
| 541 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 542 | poll_wait(file, &ctx->ibox_wq, wait); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 543 | |
Arnd Bergmann | 3a843d7 | 2005-12-05 22:52:27 -0500 | [diff] [blame] | 544 | spu_acquire(ctx); |
| 545 | mask = ctx->ops->mbox_stat_poll(ctx, POLLIN | POLLRDNORM); |
| 546 | spu_release(ctx); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 547 | |
| 548 | return mask; |
| 549 | } |
| 550 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 551 | static const struct file_operations spufs_ibox_fops = { |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 552 | .open = spufs_pipe_open, |
| 553 | .read = spufs_ibox_read, |
| 554 | .poll = spufs_ibox_poll, |
| 555 | .fasync = spufs_ibox_fasync, |
| 556 | }; |
| 557 | |
| 558 | static ssize_t spufs_ibox_stat_read(struct file *file, char __user *buf, |
| 559 | size_t len, loff_t *pos) |
| 560 | { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 561 | struct spu_context *ctx = file->private_data; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 562 | u32 ibox_stat; |
| 563 | |
| 564 | if (len < 4) |
| 565 | return -EINVAL; |
| 566 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 567 | spu_acquire(ctx); |
| 568 | ibox_stat = (ctx->ops->mbox_stat_read(ctx) >> 16) & 0xff; |
| 569 | spu_release(ctx); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 570 | |
| 571 | if (copy_to_user(buf, &ibox_stat, sizeof ibox_stat)) |
| 572 | return -EFAULT; |
| 573 | |
| 574 | return 4; |
| 575 | } |
| 576 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 577 | static const struct file_operations spufs_ibox_stat_fops = { |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 578 | .open = spufs_pipe_open, |
| 579 | .read = spufs_ibox_stat_read, |
| 580 | }; |
| 581 | |
| 582 | /* low-level mailbox write */ |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 583 | size_t spu_wbox_write(struct spu_context *ctx, u32 data) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 584 | { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 585 | return ctx->ops->wbox_write(ctx, data); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 586 | } |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 587 | |
| 588 | static int spufs_wbox_fasync(int fd, struct file *file, int on) |
| 589 | { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 590 | struct spu_context *ctx = file->private_data; |
| 591 | int ret; |
| 592 | |
| 593 | ret = fasync_helper(fd, file, on, &ctx->wbox_fasync); |
| 594 | |
| 595 | return ret; |
| 596 | } |
| 597 | |
| 598 | /* interrupt-level wbox callback function. */ |
| 599 | void spufs_wbox_callback(struct spu *spu) |
| 600 | { |
| 601 | struct spu_context *ctx = spu->ctx; |
| 602 | |
| 603 | wake_up_all(&ctx->wbox_wq); |
| 604 | kill_fasync(&ctx->wbox_fasync, SIGIO, POLLOUT); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 605 | } |
| 606 | |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 607 | /* |
| 608 | * Write as many bytes to the interrupt mailbox as possible, until |
| 609 | * one of the conditions becomes true: |
| 610 | * |
| 611 | * - the mailbox is full |
| 612 | * - end of the user provided buffer |
| 613 | * - end of the mapped area |
| 614 | * |
| 615 | * If the file is opened without O_NONBLOCK, we wait here until |
| 616 | * space is availabyl, but return when we have been able to |
| 617 | * write something. |
| 618 | */ |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 619 | static ssize_t spufs_wbox_write(struct file *file, const char __user *buf, |
| 620 | size_t len, loff_t *pos) |
| 621 | { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 622 | struct spu_context *ctx = file->private_data; |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 623 | u32 wbox_data, __user *udata; |
| 624 | ssize_t count; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 625 | |
| 626 | if (len < 4) |
| 627 | return -EINVAL; |
| 628 | |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 629 | udata = (void __user *)buf; |
| 630 | if (!access_ok(VERIFY_READ, buf, len)) |
| 631 | return -EFAULT; |
| 632 | |
| 633 | if (__get_user(wbox_data, udata)) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 634 | return -EFAULT; |
| 635 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 636 | spu_acquire(ctx); |
| 637 | |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 638 | /* |
| 639 | * make sure we can at least write one element, by waiting |
| 640 | * in case of !O_NONBLOCK |
| 641 | */ |
| 642 | count = 0; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 643 | if (file->f_flags & O_NONBLOCK) { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 644 | if (!spu_wbox_write(ctx, wbox_data)) |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 645 | count = -EAGAIN; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 646 | } else { |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 647 | count = spufs_wait(ctx->wbox_wq, spu_wbox_write(ctx, wbox_data)); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 648 | } |
| 649 | |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 650 | if (count) |
| 651 | goto out; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 652 | |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 653 | /* write aѕ much as possible */ |
| 654 | for (count = 4, udata++; (count + 4) <= len; count += 4, udata++) { |
| 655 | int ret; |
| 656 | ret = __get_user(wbox_data, udata); |
| 657 | if (ret) |
| 658 | break; |
| 659 | |
| 660 | ret = spu_wbox_write(ctx, wbox_data); |
| 661 | if (ret == 0) |
| 662 | break; |
| 663 | } |
| 664 | |
| 665 | out: |
| 666 | spu_release(ctx); |
| 667 | return count; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | static unsigned int spufs_wbox_poll(struct file *file, poll_table *wait) |
| 671 | { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 672 | struct spu_context *ctx = file->private_data; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 673 | unsigned int mask; |
| 674 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 675 | poll_wait(file, &ctx->wbox_wq, wait); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 676 | |
Arnd Bergmann | 3a843d7 | 2005-12-05 22:52:27 -0500 | [diff] [blame] | 677 | spu_acquire(ctx); |
| 678 | mask = ctx->ops->mbox_stat_poll(ctx, POLLOUT | POLLWRNORM); |
| 679 | spu_release(ctx); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 680 | |
| 681 | return mask; |
| 682 | } |
| 683 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 684 | static const struct file_operations spufs_wbox_fops = { |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 685 | .open = spufs_pipe_open, |
| 686 | .write = spufs_wbox_write, |
| 687 | .poll = spufs_wbox_poll, |
| 688 | .fasync = spufs_wbox_fasync, |
| 689 | }; |
| 690 | |
| 691 | static ssize_t spufs_wbox_stat_read(struct file *file, char __user *buf, |
| 692 | size_t len, loff_t *pos) |
| 693 | { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 694 | struct spu_context *ctx = file->private_data; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 695 | u32 wbox_stat; |
| 696 | |
| 697 | if (len < 4) |
| 698 | return -EINVAL; |
| 699 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 700 | spu_acquire(ctx); |
| 701 | wbox_stat = (ctx->ops->mbox_stat_read(ctx) >> 8) & 0xff; |
| 702 | spu_release(ctx); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 703 | |
| 704 | if (copy_to_user(buf, &wbox_stat, sizeof wbox_stat)) |
| 705 | return -EFAULT; |
| 706 | |
| 707 | return 4; |
| 708 | } |
| 709 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 710 | static const struct file_operations spufs_wbox_stat_fops = { |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 711 | .open = spufs_pipe_open, |
| 712 | .read = spufs_wbox_stat_read, |
| 713 | }; |
| 714 | |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 715 | static int spufs_signal1_open(struct inode *inode, struct file *file) |
| 716 | { |
| 717 | struct spufs_inode_info *i = SPUFS_I(inode); |
| 718 | struct spu_context *ctx = i->i_ctx; |
| 719 | file->private_data = ctx; |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 720 | ctx->signal1 = inode->i_mapping; |
Benjamin Herrenschmidt | 17e0e27 | 2007-02-13 11:46:08 +1100 | [diff] [blame^] | 721 | smp_wmb(); |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 722 | return nonseekable_open(inode, file); |
| 723 | } |
| 724 | |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 725 | static ssize_t __spufs_signal1_read(struct spu_context *ctx, char __user *buf, |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 726 | size_t len, loff_t *pos) |
| 727 | { |
Dwayne Grant McConnell | 17f88ce | 2006-11-20 18:45:01 +0100 | [diff] [blame] | 728 | int ret = 0; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 729 | u32 data; |
| 730 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 731 | if (len < 4) |
| 732 | return -EINVAL; |
| 733 | |
Dwayne Grant McConnell | 17f88ce | 2006-11-20 18:45:01 +0100 | [diff] [blame] | 734 | if (ctx->csa.spu_chnlcnt_RW[3]) { |
| 735 | data = ctx->csa.spu_chnldata_RW[3]; |
| 736 | ret = 4; |
| 737 | } |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 738 | |
Dwayne Grant McConnell | 17f88ce | 2006-11-20 18:45:01 +0100 | [diff] [blame] | 739 | if (!ret) |
| 740 | goto out; |
| 741 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 742 | if (copy_to_user(buf, &data, 4)) |
| 743 | return -EFAULT; |
| 744 | |
Dwayne Grant McConnell | 17f88ce | 2006-11-20 18:45:01 +0100 | [diff] [blame] | 745 | out: |
| 746 | return ret; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 747 | } |
| 748 | |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 749 | static ssize_t spufs_signal1_read(struct file *file, char __user *buf, |
| 750 | size_t len, loff_t *pos) |
| 751 | { |
| 752 | int ret; |
| 753 | struct spu_context *ctx = file->private_data; |
| 754 | |
| 755 | spu_acquire_saved(ctx); |
| 756 | ret = __spufs_signal1_read(ctx, buf, len, pos); |
| 757 | spu_release(ctx); |
| 758 | |
| 759 | return ret; |
| 760 | } |
| 761 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 762 | static ssize_t spufs_signal1_write(struct file *file, const char __user *buf, |
| 763 | size_t len, loff_t *pos) |
| 764 | { |
| 765 | struct spu_context *ctx; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 766 | u32 data; |
| 767 | |
| 768 | ctx = file->private_data; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 769 | |
| 770 | if (len < 4) |
| 771 | return -EINVAL; |
| 772 | |
| 773 | if (copy_from_user(&data, buf, 4)) |
| 774 | return -EFAULT; |
| 775 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 776 | spu_acquire(ctx); |
| 777 | ctx->ops->signal1_write(ctx, data); |
| 778 | spu_release(ctx); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 779 | |
| 780 | return 4; |
| 781 | } |
| 782 | |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 783 | static unsigned long spufs_signal1_mmap_nopfn(struct vm_area_struct *vma, |
| 784 | unsigned long address) |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 785 | { |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 786 | #if PAGE_SIZE == 0x1000 |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 787 | return spufs_ps_nopfn(vma, address, 0x14000, 0x1000); |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 788 | #elif PAGE_SIZE == 0x10000 |
| 789 | /* For 64k pages, both signal1 and signal2 can be used to mmap the whole |
| 790 | * signal 1 and 2 area |
| 791 | */ |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 792 | return spufs_ps_nopfn(vma, address, 0x10000, 0x10000); |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 793 | #else |
| 794 | #error unsupported page size |
| 795 | #endif |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | static struct vm_operations_struct spufs_signal1_mmap_vmops = { |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 799 | .nopfn = spufs_signal1_mmap_nopfn, |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 800 | }; |
| 801 | |
| 802 | static int spufs_signal1_mmap(struct file *file, struct vm_area_struct *vma) |
| 803 | { |
| 804 | if (!(vma->vm_flags & VM_SHARED)) |
| 805 | return -EINVAL; |
| 806 | |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 807 | vma->vm_flags |= VM_IO | VM_PFNMAP; |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 808 | vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot) |
Benjamin Herrenschmidt | 23cc770 | 2006-06-23 20:57:47 +0200 | [diff] [blame] | 809 | | _PAGE_NO_CACHE | _PAGE_GUARDED); |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 810 | |
| 811 | vma->vm_ops = &spufs_signal1_mmap_vmops; |
| 812 | return 0; |
| 813 | } |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 814 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 815 | static const struct file_operations spufs_signal1_fops = { |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 816 | .open = spufs_signal1_open, |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 817 | .read = spufs_signal1_read, |
| 818 | .write = spufs_signal1_write, |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 819 | .mmap = spufs_signal1_mmap, |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 820 | }; |
| 821 | |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 822 | static int spufs_signal2_open(struct inode *inode, struct file *file) |
| 823 | { |
| 824 | struct spufs_inode_info *i = SPUFS_I(inode); |
| 825 | struct spu_context *ctx = i->i_ctx; |
| 826 | file->private_data = ctx; |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 827 | ctx->signal2 = inode->i_mapping; |
Benjamin Herrenschmidt | 17e0e27 | 2007-02-13 11:46:08 +1100 | [diff] [blame^] | 828 | smp_wmb(); |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 829 | return nonseekable_open(inode, file); |
| 830 | } |
| 831 | |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 832 | static ssize_t __spufs_signal2_read(struct spu_context *ctx, char __user *buf, |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 833 | size_t len, loff_t *pos) |
| 834 | { |
Dwayne Grant McConnell | 17f88ce | 2006-11-20 18:45:01 +0100 | [diff] [blame] | 835 | int ret = 0; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 836 | u32 data; |
| 837 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 838 | if (len < 4) |
| 839 | return -EINVAL; |
| 840 | |
Dwayne Grant McConnell | 17f88ce | 2006-11-20 18:45:01 +0100 | [diff] [blame] | 841 | if (ctx->csa.spu_chnlcnt_RW[4]) { |
| 842 | data = ctx->csa.spu_chnldata_RW[4]; |
| 843 | ret = 4; |
| 844 | } |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 845 | |
Dwayne Grant McConnell | 17f88ce | 2006-11-20 18:45:01 +0100 | [diff] [blame] | 846 | if (!ret) |
| 847 | goto out; |
| 848 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 849 | if (copy_to_user(buf, &data, 4)) |
| 850 | return -EFAULT; |
| 851 | |
Dwayne Grant McConnell | 17f88ce | 2006-11-20 18:45:01 +0100 | [diff] [blame] | 852 | out: |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 853 | return ret; |
| 854 | } |
| 855 | |
| 856 | static ssize_t spufs_signal2_read(struct file *file, char __user *buf, |
| 857 | size_t len, loff_t *pos) |
| 858 | { |
| 859 | struct spu_context *ctx = file->private_data; |
| 860 | int ret; |
| 861 | |
| 862 | spu_acquire_saved(ctx); |
| 863 | ret = __spufs_signal2_read(ctx, buf, len, pos); |
| 864 | spu_release(ctx); |
| 865 | |
| 866 | return ret; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 867 | } |
| 868 | |
| 869 | static ssize_t spufs_signal2_write(struct file *file, const char __user *buf, |
| 870 | size_t len, loff_t *pos) |
| 871 | { |
| 872 | struct spu_context *ctx; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 873 | u32 data; |
| 874 | |
| 875 | ctx = file->private_data; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 876 | |
| 877 | if (len < 4) |
| 878 | return -EINVAL; |
| 879 | |
| 880 | if (copy_from_user(&data, buf, 4)) |
| 881 | return -EFAULT; |
| 882 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 883 | spu_acquire(ctx); |
| 884 | ctx->ops->signal2_write(ctx, data); |
| 885 | spu_release(ctx); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 886 | |
| 887 | return 4; |
| 888 | } |
| 889 | |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 890 | #if SPUFS_MMAP_4K |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 891 | static unsigned long spufs_signal2_mmap_nopfn(struct vm_area_struct *vma, |
| 892 | unsigned long address) |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 893 | { |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 894 | #if PAGE_SIZE == 0x1000 |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 895 | return spufs_ps_nopfn(vma, address, 0x1c000, 0x1000); |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 896 | #elif PAGE_SIZE == 0x10000 |
| 897 | /* For 64k pages, both signal1 and signal2 can be used to mmap the whole |
| 898 | * signal 1 and 2 area |
| 899 | */ |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 900 | return spufs_ps_nopfn(vma, address, 0x10000, 0x10000); |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 901 | #else |
| 902 | #error unsupported page size |
| 903 | #endif |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 904 | } |
| 905 | |
| 906 | static struct vm_operations_struct spufs_signal2_mmap_vmops = { |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 907 | .nopfn = spufs_signal2_mmap_nopfn, |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 908 | }; |
| 909 | |
| 910 | static int spufs_signal2_mmap(struct file *file, struct vm_area_struct *vma) |
| 911 | { |
| 912 | if (!(vma->vm_flags & VM_SHARED)) |
| 913 | return -EINVAL; |
| 914 | |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 915 | vma->vm_flags |= VM_IO | VM_PFNMAP; |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 916 | vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot) |
Benjamin Herrenschmidt | 23cc770 | 2006-06-23 20:57:47 +0200 | [diff] [blame] | 917 | | _PAGE_NO_CACHE | _PAGE_GUARDED); |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 918 | |
| 919 | vma->vm_ops = &spufs_signal2_mmap_vmops; |
| 920 | return 0; |
| 921 | } |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 922 | #else /* SPUFS_MMAP_4K */ |
| 923 | #define spufs_signal2_mmap NULL |
| 924 | #endif /* !SPUFS_MMAP_4K */ |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 925 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 926 | static const struct file_operations spufs_signal2_fops = { |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 927 | .open = spufs_signal2_open, |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 928 | .read = spufs_signal2_read, |
| 929 | .write = spufs_signal2_write, |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 930 | .mmap = spufs_signal2_mmap, |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 931 | }; |
| 932 | |
| 933 | static void spufs_signal1_type_set(void *data, u64 val) |
| 934 | { |
| 935 | struct spu_context *ctx = data; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 936 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 937 | spu_acquire(ctx); |
| 938 | ctx->ops->signal1_type_set(ctx, val); |
| 939 | spu_release(ctx); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 940 | } |
| 941 | |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 942 | static u64 __spufs_signal1_type_get(void *data) |
| 943 | { |
| 944 | struct spu_context *ctx = data; |
| 945 | return ctx->ops->signal1_type_get(ctx); |
| 946 | } |
| 947 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 948 | static u64 spufs_signal1_type_get(void *data) |
| 949 | { |
| 950 | struct spu_context *ctx = data; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 951 | u64 ret; |
| 952 | |
| 953 | spu_acquire(ctx); |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 954 | ret = __spufs_signal1_type_get(data); |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 955 | spu_release(ctx); |
| 956 | |
| 957 | return ret; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 958 | } |
| 959 | DEFINE_SIMPLE_ATTRIBUTE(spufs_signal1_type, spufs_signal1_type_get, |
| 960 | spufs_signal1_type_set, "%llu"); |
| 961 | |
| 962 | static void spufs_signal2_type_set(void *data, u64 val) |
| 963 | { |
| 964 | struct spu_context *ctx = data; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 965 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 966 | spu_acquire(ctx); |
| 967 | ctx->ops->signal2_type_set(ctx, val); |
| 968 | spu_release(ctx); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 969 | } |
| 970 | |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 971 | static u64 __spufs_signal2_type_get(void *data) |
| 972 | { |
| 973 | struct spu_context *ctx = data; |
| 974 | return ctx->ops->signal2_type_get(ctx); |
| 975 | } |
| 976 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 977 | static u64 spufs_signal2_type_get(void *data) |
| 978 | { |
| 979 | struct spu_context *ctx = data; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 980 | u64 ret; |
| 981 | |
| 982 | spu_acquire(ctx); |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 983 | ret = __spufs_signal2_type_get(data); |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 984 | spu_release(ctx); |
| 985 | |
| 986 | return ret; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 987 | } |
| 988 | DEFINE_SIMPLE_ATTRIBUTE(spufs_signal2_type, spufs_signal2_type_get, |
| 989 | spufs_signal2_type_set, "%llu"); |
| 990 | |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 991 | #if SPUFS_MMAP_4K |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 992 | static unsigned long spufs_mss_mmap_nopfn(struct vm_area_struct *vma, |
| 993 | unsigned long address) |
arnd@arndb.de | d9379c4 | 2006-06-19 20:33:21 +0200 | [diff] [blame] | 994 | { |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 995 | return spufs_ps_nopfn(vma, address, 0x0000, 0x1000); |
arnd@arndb.de | d9379c4 | 2006-06-19 20:33:21 +0200 | [diff] [blame] | 996 | } |
| 997 | |
| 998 | static struct vm_operations_struct spufs_mss_mmap_vmops = { |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 999 | .nopfn = spufs_mss_mmap_nopfn, |
arnd@arndb.de | d9379c4 | 2006-06-19 20:33:21 +0200 | [diff] [blame] | 1000 | }; |
| 1001 | |
| 1002 | /* |
| 1003 | * mmap support for problem state MFC DMA area [0x0000 - 0x0fff]. |
arnd@arndb.de | d9379c4 | 2006-06-19 20:33:21 +0200 | [diff] [blame] | 1004 | */ |
| 1005 | static int spufs_mss_mmap(struct file *file, struct vm_area_struct *vma) |
| 1006 | { |
| 1007 | if (!(vma->vm_flags & VM_SHARED)) |
| 1008 | return -EINVAL; |
| 1009 | |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 1010 | vma->vm_flags |= VM_IO | VM_PFNMAP; |
arnd@arndb.de | d9379c4 | 2006-06-19 20:33:21 +0200 | [diff] [blame] | 1011 | vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot) |
Benjamin Herrenschmidt | 23cc770 | 2006-06-23 20:57:47 +0200 | [diff] [blame] | 1012 | | _PAGE_NO_CACHE | _PAGE_GUARDED); |
arnd@arndb.de | d9379c4 | 2006-06-19 20:33:21 +0200 | [diff] [blame] | 1013 | |
| 1014 | vma->vm_ops = &spufs_mss_mmap_vmops; |
| 1015 | return 0; |
| 1016 | } |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 1017 | #else /* SPUFS_MMAP_4K */ |
| 1018 | #define spufs_mss_mmap NULL |
| 1019 | #endif /* !SPUFS_MMAP_4K */ |
arnd@arndb.de | d9379c4 | 2006-06-19 20:33:21 +0200 | [diff] [blame] | 1020 | |
| 1021 | static int spufs_mss_open(struct inode *inode, struct file *file) |
| 1022 | { |
| 1023 | struct spufs_inode_info *i = SPUFS_I(inode); |
Benjamin Herrenschmidt | 17e0e27 | 2007-02-13 11:46:08 +1100 | [diff] [blame^] | 1024 | struct spu_context *ctx = i->i_ctx; |
arnd@arndb.de | d9379c4 | 2006-06-19 20:33:21 +0200 | [diff] [blame] | 1025 | |
| 1026 | file->private_data = i->i_ctx; |
Benjamin Herrenschmidt | 17e0e27 | 2007-02-13 11:46:08 +1100 | [diff] [blame^] | 1027 | ctx->mss = inode->i_mapping; |
| 1028 | smp_wmb(); |
arnd@arndb.de | d9379c4 | 2006-06-19 20:33:21 +0200 | [diff] [blame] | 1029 | return nonseekable_open(inode, file); |
| 1030 | } |
| 1031 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 1032 | static const struct file_operations spufs_mss_fops = { |
arnd@arndb.de | d9379c4 | 2006-06-19 20:33:21 +0200 | [diff] [blame] | 1033 | .open = spufs_mss_open, |
arnd@arndb.de | d9379c4 | 2006-06-19 20:33:21 +0200 | [diff] [blame] | 1034 | .mmap = spufs_mss_mmap, |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 1035 | }; |
| 1036 | |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 1037 | static unsigned long spufs_psmap_mmap_nopfn(struct vm_area_struct *vma, |
| 1038 | unsigned long address) |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 1039 | { |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 1040 | return spufs_ps_nopfn(vma, address, 0x0000, 0x20000); |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 1041 | } |
| 1042 | |
| 1043 | static struct vm_operations_struct spufs_psmap_mmap_vmops = { |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 1044 | .nopfn = spufs_psmap_mmap_nopfn, |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 1045 | }; |
| 1046 | |
| 1047 | /* |
| 1048 | * mmap support for full problem state area [0x00000 - 0x1ffff]. |
| 1049 | */ |
| 1050 | static int spufs_psmap_mmap(struct file *file, struct vm_area_struct *vma) |
| 1051 | { |
| 1052 | if (!(vma->vm_flags & VM_SHARED)) |
| 1053 | return -EINVAL; |
| 1054 | |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 1055 | vma->vm_flags |= VM_IO | VM_PFNMAP; |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 1056 | vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot) |
| 1057 | | _PAGE_NO_CACHE | _PAGE_GUARDED); |
| 1058 | |
| 1059 | vma->vm_ops = &spufs_psmap_mmap_vmops; |
| 1060 | return 0; |
| 1061 | } |
| 1062 | |
| 1063 | static int spufs_psmap_open(struct inode *inode, struct file *file) |
| 1064 | { |
| 1065 | struct spufs_inode_info *i = SPUFS_I(inode); |
Benjamin Herrenschmidt | 17e0e27 | 2007-02-13 11:46:08 +1100 | [diff] [blame^] | 1066 | struct spu_context *ctx = i->i_ctx; |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 1067 | |
| 1068 | file->private_data = i->i_ctx; |
Benjamin Herrenschmidt | 17e0e27 | 2007-02-13 11:46:08 +1100 | [diff] [blame^] | 1069 | ctx->psmap = inode->i_mapping; |
| 1070 | smp_wmb(); |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 1071 | return nonseekable_open(inode, file); |
| 1072 | } |
| 1073 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 1074 | static const struct file_operations spufs_psmap_fops = { |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 1075 | .open = spufs_psmap_open, |
| 1076 | .mmap = spufs_psmap_mmap, |
arnd@arndb.de | d9379c4 | 2006-06-19 20:33:21 +0200 | [diff] [blame] | 1077 | }; |
| 1078 | |
| 1079 | |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 1080 | #if SPUFS_MMAP_4K |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 1081 | static unsigned long spufs_mfc_mmap_nopfn(struct vm_area_struct *vma, |
| 1082 | unsigned long address) |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 1083 | { |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 1084 | return spufs_ps_nopfn(vma, address, 0x3000, 0x1000); |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 1085 | } |
| 1086 | |
| 1087 | static struct vm_operations_struct spufs_mfc_mmap_vmops = { |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 1088 | .nopfn = spufs_mfc_mmap_nopfn, |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 1089 | }; |
| 1090 | |
| 1091 | /* |
| 1092 | * mmap support for problem state MFC DMA area [0x0000 - 0x0fff]. |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 1093 | */ |
| 1094 | static int spufs_mfc_mmap(struct file *file, struct vm_area_struct *vma) |
| 1095 | { |
| 1096 | if (!(vma->vm_flags & VM_SHARED)) |
| 1097 | return -EINVAL; |
| 1098 | |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 1099 | vma->vm_flags |= VM_IO | VM_PFNMAP; |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 1100 | vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot) |
Benjamin Herrenschmidt | 23cc770 | 2006-06-23 20:57:47 +0200 | [diff] [blame] | 1101 | | _PAGE_NO_CACHE | _PAGE_GUARDED); |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 1102 | |
| 1103 | vma->vm_ops = &spufs_mfc_mmap_vmops; |
| 1104 | return 0; |
| 1105 | } |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 1106 | #else /* SPUFS_MMAP_4K */ |
| 1107 | #define spufs_mfc_mmap NULL |
| 1108 | #endif /* !SPUFS_MMAP_4K */ |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 1109 | |
| 1110 | static int spufs_mfc_open(struct inode *inode, struct file *file) |
| 1111 | { |
| 1112 | struct spufs_inode_info *i = SPUFS_I(inode); |
| 1113 | struct spu_context *ctx = i->i_ctx; |
| 1114 | |
| 1115 | /* we don't want to deal with DMA into other processes */ |
| 1116 | if (ctx->owner != current->mm) |
| 1117 | return -EINVAL; |
| 1118 | |
| 1119 | if (atomic_read(&inode->i_count) != 1) |
| 1120 | return -EBUSY; |
| 1121 | |
| 1122 | file->private_data = ctx; |
Benjamin Herrenschmidt | 17e0e27 | 2007-02-13 11:46:08 +1100 | [diff] [blame^] | 1123 | ctx->mfc = inode->i_mapping; |
| 1124 | smp_wmb(); |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 1125 | return nonseekable_open(inode, file); |
| 1126 | } |
| 1127 | |
| 1128 | /* interrupt-level mfc callback function. */ |
| 1129 | void spufs_mfc_callback(struct spu *spu) |
| 1130 | { |
| 1131 | struct spu_context *ctx = spu->ctx; |
| 1132 | |
| 1133 | wake_up_all(&ctx->mfc_wq); |
| 1134 | |
| 1135 | pr_debug("%s %s\n", __FUNCTION__, spu->name); |
| 1136 | if (ctx->mfc_fasync) { |
| 1137 | u32 free_elements, tagstatus; |
| 1138 | unsigned int mask; |
| 1139 | |
| 1140 | /* no need for spu_acquire in interrupt context */ |
| 1141 | free_elements = ctx->ops->get_mfc_free_elements(ctx); |
| 1142 | tagstatus = ctx->ops->read_mfc_tagstatus(ctx); |
| 1143 | |
| 1144 | mask = 0; |
| 1145 | if (free_elements & 0xffff) |
| 1146 | mask |= POLLOUT; |
| 1147 | if (tagstatus & ctx->tagwait) |
| 1148 | mask |= POLLIN; |
| 1149 | |
| 1150 | kill_fasync(&ctx->mfc_fasync, SIGIO, mask); |
| 1151 | } |
| 1152 | } |
| 1153 | |
| 1154 | static int spufs_read_mfc_tagstatus(struct spu_context *ctx, u32 *status) |
| 1155 | { |
| 1156 | /* See if there is one tag group is complete */ |
| 1157 | /* FIXME we need locking around tagwait */ |
| 1158 | *status = ctx->ops->read_mfc_tagstatus(ctx) & ctx->tagwait; |
| 1159 | ctx->tagwait &= ~*status; |
| 1160 | if (*status) |
| 1161 | return 1; |
| 1162 | |
| 1163 | /* enable interrupt waiting for any tag group, |
| 1164 | may silently fail if interrupts are already enabled */ |
| 1165 | ctx->ops->set_mfc_query(ctx, ctx->tagwait, 1); |
| 1166 | return 0; |
| 1167 | } |
| 1168 | |
| 1169 | static ssize_t spufs_mfc_read(struct file *file, char __user *buffer, |
| 1170 | size_t size, loff_t *pos) |
| 1171 | { |
| 1172 | struct spu_context *ctx = file->private_data; |
| 1173 | int ret = -EINVAL; |
| 1174 | u32 status; |
| 1175 | |
| 1176 | if (size != 4) |
| 1177 | goto out; |
| 1178 | |
| 1179 | spu_acquire(ctx); |
| 1180 | if (file->f_flags & O_NONBLOCK) { |
| 1181 | status = ctx->ops->read_mfc_tagstatus(ctx); |
| 1182 | if (!(status & ctx->tagwait)) |
| 1183 | ret = -EAGAIN; |
| 1184 | else |
| 1185 | ctx->tagwait &= ~status; |
| 1186 | } else { |
| 1187 | ret = spufs_wait(ctx->mfc_wq, |
| 1188 | spufs_read_mfc_tagstatus(ctx, &status)); |
| 1189 | } |
| 1190 | spu_release(ctx); |
| 1191 | |
| 1192 | if (ret) |
| 1193 | goto out; |
| 1194 | |
| 1195 | ret = 4; |
| 1196 | if (copy_to_user(buffer, &status, 4)) |
| 1197 | ret = -EFAULT; |
| 1198 | |
| 1199 | out: |
| 1200 | return ret; |
| 1201 | } |
| 1202 | |
| 1203 | static int spufs_check_valid_dma(struct mfc_dma_command *cmd) |
| 1204 | { |
| 1205 | pr_debug("queueing DMA %x %lx %x %x %x\n", cmd->lsa, |
| 1206 | cmd->ea, cmd->size, cmd->tag, cmd->cmd); |
| 1207 | |
| 1208 | switch (cmd->cmd) { |
| 1209 | case MFC_PUT_CMD: |
| 1210 | case MFC_PUTF_CMD: |
| 1211 | case MFC_PUTB_CMD: |
| 1212 | case MFC_GET_CMD: |
| 1213 | case MFC_GETF_CMD: |
| 1214 | case MFC_GETB_CMD: |
| 1215 | break; |
| 1216 | default: |
| 1217 | pr_debug("invalid DMA opcode %x\n", cmd->cmd); |
| 1218 | return -EIO; |
| 1219 | } |
| 1220 | |
| 1221 | if ((cmd->lsa & 0xf) != (cmd->ea &0xf)) { |
| 1222 | pr_debug("invalid DMA alignment, ea %lx lsa %x\n", |
| 1223 | cmd->ea, cmd->lsa); |
| 1224 | return -EIO; |
| 1225 | } |
| 1226 | |
| 1227 | switch (cmd->size & 0xf) { |
| 1228 | case 1: |
| 1229 | break; |
| 1230 | case 2: |
| 1231 | if (cmd->lsa & 1) |
| 1232 | goto error; |
| 1233 | break; |
| 1234 | case 4: |
| 1235 | if (cmd->lsa & 3) |
| 1236 | goto error; |
| 1237 | break; |
| 1238 | case 8: |
| 1239 | if (cmd->lsa & 7) |
| 1240 | goto error; |
| 1241 | break; |
| 1242 | case 0: |
| 1243 | if (cmd->lsa & 15) |
| 1244 | goto error; |
| 1245 | break; |
| 1246 | error: |
| 1247 | default: |
| 1248 | pr_debug("invalid DMA alignment %x for size %x\n", |
| 1249 | cmd->lsa & 0xf, cmd->size); |
| 1250 | return -EIO; |
| 1251 | } |
| 1252 | |
| 1253 | if (cmd->size > 16 * 1024) { |
| 1254 | pr_debug("invalid DMA size %x\n", cmd->size); |
| 1255 | return -EIO; |
| 1256 | } |
| 1257 | |
| 1258 | if (cmd->tag & 0xfff0) { |
| 1259 | /* we reserve the higher tag numbers for kernel use */ |
| 1260 | pr_debug("invalid DMA tag\n"); |
| 1261 | return -EIO; |
| 1262 | } |
| 1263 | |
| 1264 | if (cmd->class) { |
| 1265 | /* not supported in this version */ |
| 1266 | pr_debug("invalid DMA class\n"); |
| 1267 | return -EIO; |
| 1268 | } |
| 1269 | |
| 1270 | return 0; |
| 1271 | } |
| 1272 | |
| 1273 | static int spu_send_mfc_command(struct spu_context *ctx, |
| 1274 | struct mfc_dma_command cmd, |
| 1275 | int *error) |
| 1276 | { |
| 1277 | *error = ctx->ops->send_mfc_command(ctx, &cmd); |
| 1278 | if (*error == -EAGAIN) { |
| 1279 | /* wait for any tag group to complete |
| 1280 | so we have space for the new command */ |
| 1281 | ctx->ops->set_mfc_query(ctx, ctx->tagwait, 1); |
| 1282 | /* try again, because the queue might be |
| 1283 | empty again */ |
| 1284 | *error = ctx->ops->send_mfc_command(ctx, &cmd); |
| 1285 | if (*error == -EAGAIN) |
| 1286 | return 0; |
| 1287 | } |
| 1288 | return 1; |
| 1289 | } |
| 1290 | |
| 1291 | static ssize_t spufs_mfc_write(struct file *file, const char __user *buffer, |
| 1292 | size_t size, loff_t *pos) |
| 1293 | { |
| 1294 | struct spu_context *ctx = file->private_data; |
| 1295 | struct mfc_dma_command cmd; |
| 1296 | int ret = -EINVAL; |
| 1297 | |
| 1298 | if (size != sizeof cmd) |
| 1299 | goto out; |
| 1300 | |
| 1301 | ret = -EFAULT; |
| 1302 | if (copy_from_user(&cmd, buffer, sizeof cmd)) |
| 1303 | goto out; |
| 1304 | |
| 1305 | ret = spufs_check_valid_dma(&cmd); |
| 1306 | if (ret) |
| 1307 | goto out; |
| 1308 | |
| 1309 | spu_acquire_runnable(ctx); |
| 1310 | if (file->f_flags & O_NONBLOCK) { |
| 1311 | ret = ctx->ops->send_mfc_command(ctx, &cmd); |
| 1312 | } else { |
| 1313 | int status; |
| 1314 | ret = spufs_wait(ctx->mfc_wq, |
| 1315 | spu_send_mfc_command(ctx, cmd, &status)); |
| 1316 | if (status) |
| 1317 | ret = status; |
| 1318 | } |
| 1319 | spu_release(ctx); |
| 1320 | |
| 1321 | if (ret) |
| 1322 | goto out; |
| 1323 | |
| 1324 | ctx->tagwait |= 1 << cmd.tag; |
Masato Noguchi | 3692dc6 | 2006-11-20 18:45:07 +0100 | [diff] [blame] | 1325 | ret = size; |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 1326 | |
| 1327 | out: |
| 1328 | return ret; |
| 1329 | } |
| 1330 | |
| 1331 | static unsigned int spufs_mfc_poll(struct file *file,poll_table *wait) |
| 1332 | { |
| 1333 | struct spu_context *ctx = file->private_data; |
| 1334 | u32 free_elements, tagstatus; |
| 1335 | unsigned int mask; |
| 1336 | |
| 1337 | spu_acquire(ctx); |
| 1338 | ctx->ops->set_mfc_query(ctx, ctx->tagwait, 2); |
| 1339 | free_elements = ctx->ops->get_mfc_free_elements(ctx); |
| 1340 | tagstatus = ctx->ops->read_mfc_tagstatus(ctx); |
| 1341 | spu_release(ctx); |
| 1342 | |
| 1343 | poll_wait(file, &ctx->mfc_wq, wait); |
| 1344 | |
| 1345 | mask = 0; |
| 1346 | if (free_elements & 0xffff) |
| 1347 | mask |= POLLOUT | POLLWRNORM; |
| 1348 | if (tagstatus & ctx->tagwait) |
| 1349 | mask |= POLLIN | POLLRDNORM; |
| 1350 | |
| 1351 | pr_debug("%s: free %d tagstatus %d tagwait %d\n", __FUNCTION__, |
| 1352 | free_elements, tagstatus, ctx->tagwait); |
| 1353 | |
| 1354 | return mask; |
| 1355 | } |
| 1356 | |
Al Viro | 73b6af8 | 2006-06-25 16:42:33 -0700 | [diff] [blame] | 1357 | static int spufs_mfc_flush(struct file *file, fl_owner_t id) |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 1358 | { |
| 1359 | struct spu_context *ctx = file->private_data; |
| 1360 | int ret; |
| 1361 | |
| 1362 | spu_acquire(ctx); |
| 1363 | #if 0 |
| 1364 | /* this currently hangs */ |
| 1365 | ret = spufs_wait(ctx->mfc_wq, |
| 1366 | ctx->ops->set_mfc_query(ctx, ctx->tagwait, 2)); |
| 1367 | if (ret) |
| 1368 | goto out; |
| 1369 | ret = spufs_wait(ctx->mfc_wq, |
| 1370 | ctx->ops->read_mfc_tagstatus(ctx) == ctx->tagwait); |
| 1371 | out: |
| 1372 | #else |
| 1373 | ret = 0; |
| 1374 | #endif |
| 1375 | spu_release(ctx); |
| 1376 | |
| 1377 | return ret; |
| 1378 | } |
| 1379 | |
| 1380 | static int spufs_mfc_fsync(struct file *file, struct dentry *dentry, |
| 1381 | int datasync) |
| 1382 | { |
Al Viro | 73b6af8 | 2006-06-25 16:42:33 -0700 | [diff] [blame] | 1383 | return spufs_mfc_flush(file, NULL); |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 1384 | } |
| 1385 | |
| 1386 | static int spufs_mfc_fasync(int fd, struct file *file, int on) |
| 1387 | { |
| 1388 | struct spu_context *ctx = file->private_data; |
| 1389 | |
| 1390 | return fasync_helper(fd, file, on, &ctx->mfc_fasync); |
| 1391 | } |
| 1392 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 1393 | static const struct file_operations spufs_mfc_fops = { |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 1394 | .open = spufs_mfc_open, |
| 1395 | .read = spufs_mfc_read, |
| 1396 | .write = spufs_mfc_write, |
| 1397 | .poll = spufs_mfc_poll, |
| 1398 | .flush = spufs_mfc_flush, |
| 1399 | .fsync = spufs_mfc_fsync, |
| 1400 | .fasync = spufs_mfc_fasync, |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 1401 | .mmap = spufs_mfc_mmap, |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 1402 | }; |
| 1403 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1404 | static void spufs_npc_set(void *data, u64 val) |
| 1405 | { |
| 1406 | struct spu_context *ctx = data; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1407 | spu_acquire(ctx); |
| 1408 | ctx->ops->npc_write(ctx, val); |
| 1409 | spu_release(ctx); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1410 | } |
| 1411 | |
| 1412 | static u64 spufs_npc_get(void *data) |
| 1413 | { |
| 1414 | struct spu_context *ctx = data; |
| 1415 | u64 ret; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1416 | spu_acquire(ctx); |
| 1417 | ret = ctx->ops->npc_read(ctx); |
| 1418 | spu_release(ctx); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1419 | return ret; |
| 1420 | } |
Dwayne Grant McConnell | 9b5047e | 2006-11-20 18:44:57 +0100 | [diff] [blame] | 1421 | DEFINE_SIMPLE_ATTRIBUTE(spufs_npc_ops, spufs_npc_get, spufs_npc_set, |
| 1422 | "0x%llx\n") |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1423 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1424 | static void spufs_decr_set(void *data, u64 val) |
| 1425 | { |
| 1426 | struct spu_context *ctx = data; |
| 1427 | struct spu_lscsa *lscsa = ctx->csa.lscsa; |
| 1428 | spu_acquire_saved(ctx); |
| 1429 | lscsa->decr.slot[0] = (u32) val; |
| 1430 | spu_release(ctx); |
| 1431 | } |
| 1432 | |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1433 | static u64 __spufs_decr_get(void *data) |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1434 | { |
| 1435 | struct spu_context *ctx = data; |
| 1436 | struct spu_lscsa *lscsa = ctx->csa.lscsa; |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1437 | return lscsa->decr.slot[0]; |
| 1438 | } |
| 1439 | |
| 1440 | static u64 spufs_decr_get(void *data) |
| 1441 | { |
| 1442 | struct spu_context *ctx = data; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1443 | u64 ret; |
| 1444 | spu_acquire_saved(ctx); |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1445 | ret = __spufs_decr_get(data); |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1446 | spu_release(ctx); |
| 1447 | return ret; |
| 1448 | } |
| 1449 | DEFINE_SIMPLE_ATTRIBUTE(spufs_decr_ops, spufs_decr_get, spufs_decr_set, |
Dwayne Grant McConnell | 9b5047e | 2006-11-20 18:44:57 +0100 | [diff] [blame] | 1450 | "0x%llx\n") |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1451 | |
| 1452 | static void spufs_decr_status_set(void *data, u64 val) |
| 1453 | { |
| 1454 | struct spu_context *ctx = data; |
| 1455 | struct spu_lscsa *lscsa = ctx->csa.lscsa; |
| 1456 | spu_acquire_saved(ctx); |
| 1457 | lscsa->decr_status.slot[0] = (u32) val; |
| 1458 | spu_release(ctx); |
| 1459 | } |
| 1460 | |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1461 | static u64 __spufs_decr_status_get(void *data) |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1462 | { |
| 1463 | struct spu_context *ctx = data; |
| 1464 | struct spu_lscsa *lscsa = ctx->csa.lscsa; |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1465 | return lscsa->decr_status.slot[0]; |
| 1466 | } |
| 1467 | |
| 1468 | static u64 spufs_decr_status_get(void *data) |
| 1469 | { |
| 1470 | struct spu_context *ctx = data; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1471 | u64 ret; |
| 1472 | spu_acquire_saved(ctx); |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1473 | ret = __spufs_decr_status_get(data); |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1474 | spu_release(ctx); |
| 1475 | return ret; |
| 1476 | } |
| 1477 | DEFINE_SIMPLE_ATTRIBUTE(spufs_decr_status_ops, spufs_decr_status_get, |
Dwayne Grant McConnell | 9b5047e | 2006-11-20 18:44:57 +0100 | [diff] [blame] | 1478 | spufs_decr_status_set, "0x%llx\n") |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1479 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1480 | static void spufs_event_mask_set(void *data, u64 val) |
| 1481 | { |
| 1482 | struct spu_context *ctx = data; |
| 1483 | struct spu_lscsa *lscsa = ctx->csa.lscsa; |
| 1484 | spu_acquire_saved(ctx); |
| 1485 | lscsa->event_mask.slot[0] = (u32) val; |
| 1486 | spu_release(ctx); |
| 1487 | } |
| 1488 | |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1489 | static u64 __spufs_event_mask_get(void *data) |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1490 | { |
| 1491 | struct spu_context *ctx = data; |
| 1492 | struct spu_lscsa *lscsa = ctx->csa.lscsa; |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1493 | return lscsa->event_mask.slot[0]; |
| 1494 | } |
| 1495 | |
| 1496 | static u64 spufs_event_mask_get(void *data) |
| 1497 | { |
| 1498 | struct spu_context *ctx = data; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1499 | u64 ret; |
| 1500 | spu_acquire_saved(ctx); |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1501 | ret = __spufs_event_mask_get(data); |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1502 | spu_release(ctx); |
| 1503 | return ret; |
| 1504 | } |
| 1505 | DEFINE_SIMPLE_ATTRIBUTE(spufs_event_mask_ops, spufs_event_mask_get, |
Dwayne Grant McConnell | 9b5047e | 2006-11-20 18:44:57 +0100 | [diff] [blame] | 1506 | spufs_event_mask_set, "0x%llx\n") |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1507 | |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1508 | static u64 __spufs_event_status_get(void *data) |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 1509 | { |
| 1510 | struct spu_context *ctx = data; |
| 1511 | struct spu_state *state = &ctx->csa; |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 1512 | u64 stat; |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 1513 | stat = state->spu_chnlcnt_RW[0]; |
| 1514 | if (stat) |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1515 | return state->spu_chnldata_RW[0]; |
| 1516 | return 0; |
| 1517 | } |
| 1518 | |
| 1519 | static u64 spufs_event_status_get(void *data) |
| 1520 | { |
| 1521 | struct spu_context *ctx = data; |
| 1522 | u64 ret = 0; |
| 1523 | |
| 1524 | spu_acquire_saved(ctx); |
| 1525 | ret = __spufs_event_status_get(data); |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 1526 | spu_release(ctx); |
| 1527 | return ret; |
| 1528 | } |
| 1529 | DEFINE_SIMPLE_ATTRIBUTE(spufs_event_status_ops, spufs_event_status_get, |
| 1530 | NULL, "0x%llx\n") |
| 1531 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1532 | static void spufs_srr0_set(void *data, u64 val) |
| 1533 | { |
| 1534 | struct spu_context *ctx = data; |
| 1535 | struct spu_lscsa *lscsa = ctx->csa.lscsa; |
| 1536 | spu_acquire_saved(ctx); |
| 1537 | lscsa->srr0.slot[0] = (u32) val; |
| 1538 | spu_release(ctx); |
| 1539 | } |
| 1540 | |
| 1541 | static u64 spufs_srr0_get(void *data) |
| 1542 | { |
| 1543 | struct spu_context *ctx = data; |
| 1544 | struct spu_lscsa *lscsa = ctx->csa.lscsa; |
| 1545 | u64 ret; |
| 1546 | spu_acquire_saved(ctx); |
| 1547 | ret = lscsa->srr0.slot[0]; |
| 1548 | spu_release(ctx); |
| 1549 | return ret; |
| 1550 | } |
| 1551 | DEFINE_SIMPLE_ATTRIBUTE(spufs_srr0_ops, spufs_srr0_get, spufs_srr0_set, |
Dwayne Grant McConnell | 9b5047e | 2006-11-20 18:44:57 +0100 | [diff] [blame] | 1552 | "0x%llx\n") |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1553 | |
arnd@arndb.de | 7b1a701 | 2006-06-19 20:33:24 +0200 | [diff] [blame] | 1554 | static u64 spufs_id_get(void *data) |
| 1555 | { |
| 1556 | struct spu_context *ctx = data; |
| 1557 | u64 num; |
| 1558 | |
| 1559 | spu_acquire(ctx); |
| 1560 | if (ctx->state == SPU_STATE_RUNNABLE) |
| 1561 | num = ctx->spu->number; |
| 1562 | else |
| 1563 | num = (unsigned int)-1; |
| 1564 | spu_release(ctx); |
| 1565 | |
| 1566 | return num; |
| 1567 | } |
Al Viro | e45d663 | 2006-09-23 01:37:41 +0100 | [diff] [blame] | 1568 | DEFINE_SIMPLE_ATTRIBUTE(spufs_id_ops, spufs_id_get, NULL, "0x%llx\n") |
arnd@arndb.de | 7b1a701 | 2006-06-19 20:33:24 +0200 | [diff] [blame] | 1569 | |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1570 | static u64 __spufs_object_id_get(void *data) |
Arnd Bergmann | 8676727 | 2006-10-04 17:26:21 +0200 | [diff] [blame] | 1571 | { |
| 1572 | struct spu_context *ctx = data; |
| 1573 | return ctx->object_id; |
| 1574 | } |
| 1575 | |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1576 | static u64 spufs_object_id_get(void *data) |
| 1577 | { |
| 1578 | /* FIXME: Should there really be no locking here? */ |
| 1579 | return __spufs_object_id_get(data); |
| 1580 | } |
| 1581 | |
Arnd Bergmann | 8676727 | 2006-10-04 17:26:21 +0200 | [diff] [blame] | 1582 | static void spufs_object_id_set(void *data, u64 id) |
| 1583 | { |
| 1584 | struct spu_context *ctx = data; |
| 1585 | ctx->object_id = id; |
| 1586 | } |
| 1587 | |
| 1588 | DEFINE_SIMPLE_ATTRIBUTE(spufs_object_id_ops, spufs_object_id_get, |
| 1589 | spufs_object_id_set, "0x%llx\n"); |
| 1590 | |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1591 | static u64 __spufs_lslr_get(void *data) |
| 1592 | { |
| 1593 | struct spu_context *ctx = data; |
| 1594 | return ctx->csa.priv2.spu_lslr_RW; |
| 1595 | } |
| 1596 | |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 1597 | static u64 spufs_lslr_get(void *data) |
| 1598 | { |
| 1599 | struct spu_context *ctx = data; |
| 1600 | u64 ret; |
| 1601 | |
| 1602 | spu_acquire_saved(ctx); |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1603 | ret = __spufs_lslr_get(data); |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 1604 | spu_release(ctx); |
| 1605 | |
| 1606 | return ret; |
| 1607 | } |
| 1608 | DEFINE_SIMPLE_ATTRIBUTE(spufs_lslr_ops, spufs_lslr_get, NULL, "0x%llx\n") |
| 1609 | |
| 1610 | static int spufs_info_open(struct inode *inode, struct file *file) |
| 1611 | { |
| 1612 | struct spufs_inode_info *i = SPUFS_I(inode); |
| 1613 | struct spu_context *ctx = i->i_ctx; |
| 1614 | file->private_data = ctx; |
| 1615 | return 0; |
| 1616 | } |
| 1617 | |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1618 | static ssize_t __spufs_mbox_info_read(struct spu_context *ctx, |
| 1619 | char __user *buf, size_t len, loff_t *pos) |
| 1620 | { |
| 1621 | u32 mbox_stat; |
| 1622 | u32 data; |
| 1623 | |
| 1624 | mbox_stat = ctx->csa.prob.mb_stat_R; |
| 1625 | if (mbox_stat & 0x0000ff) { |
| 1626 | data = ctx->csa.prob.pu_mb_R; |
| 1627 | } |
| 1628 | |
| 1629 | return simple_read_from_buffer(buf, len, pos, &data, sizeof data); |
| 1630 | } |
| 1631 | |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 1632 | static ssize_t spufs_mbox_info_read(struct file *file, char __user *buf, |
| 1633 | size_t len, loff_t *pos) |
| 1634 | { |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1635 | int ret; |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 1636 | struct spu_context *ctx = file->private_data; |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 1637 | |
| 1638 | if (!access_ok(VERIFY_WRITE, buf, len)) |
| 1639 | return -EFAULT; |
| 1640 | |
| 1641 | spu_acquire_saved(ctx); |
| 1642 | spin_lock(&ctx->csa.register_lock); |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1643 | ret = __spufs_mbox_info_read(ctx, buf, len, pos); |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 1644 | spin_unlock(&ctx->csa.register_lock); |
| 1645 | spu_release(ctx); |
| 1646 | |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1647 | return ret; |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 1648 | } |
| 1649 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 1650 | static const struct file_operations spufs_mbox_info_fops = { |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 1651 | .open = spufs_info_open, |
| 1652 | .read = spufs_mbox_info_read, |
| 1653 | .llseek = generic_file_llseek, |
| 1654 | }; |
| 1655 | |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1656 | static ssize_t __spufs_ibox_info_read(struct spu_context *ctx, |
| 1657 | char __user *buf, size_t len, loff_t *pos) |
| 1658 | { |
| 1659 | u32 ibox_stat; |
| 1660 | u32 data; |
| 1661 | |
| 1662 | ibox_stat = ctx->csa.prob.mb_stat_R; |
| 1663 | if (ibox_stat & 0xff0000) { |
| 1664 | data = ctx->csa.priv2.puint_mb_R; |
| 1665 | } |
| 1666 | |
| 1667 | return simple_read_from_buffer(buf, len, pos, &data, sizeof data); |
| 1668 | } |
| 1669 | |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 1670 | static ssize_t spufs_ibox_info_read(struct file *file, char __user *buf, |
| 1671 | size_t len, loff_t *pos) |
| 1672 | { |
| 1673 | struct spu_context *ctx = file->private_data; |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1674 | int ret; |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 1675 | |
| 1676 | if (!access_ok(VERIFY_WRITE, buf, len)) |
| 1677 | return -EFAULT; |
| 1678 | |
| 1679 | spu_acquire_saved(ctx); |
| 1680 | spin_lock(&ctx->csa.register_lock); |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1681 | ret = __spufs_ibox_info_read(ctx, buf, len, pos); |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 1682 | spin_unlock(&ctx->csa.register_lock); |
| 1683 | spu_release(ctx); |
| 1684 | |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1685 | return ret; |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 1686 | } |
| 1687 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 1688 | static const struct file_operations spufs_ibox_info_fops = { |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 1689 | .open = spufs_info_open, |
| 1690 | .read = spufs_ibox_info_read, |
| 1691 | .llseek = generic_file_llseek, |
| 1692 | }; |
| 1693 | |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1694 | static ssize_t __spufs_wbox_info_read(struct spu_context *ctx, |
| 1695 | char __user *buf, size_t len, loff_t *pos) |
| 1696 | { |
| 1697 | int i, cnt; |
| 1698 | u32 data[4]; |
| 1699 | u32 wbox_stat; |
| 1700 | |
| 1701 | wbox_stat = ctx->csa.prob.mb_stat_R; |
| 1702 | cnt = 4 - ((wbox_stat & 0x00ff00) >> 8); |
| 1703 | for (i = 0; i < cnt; i++) { |
| 1704 | data[i] = ctx->csa.spu_mailbox_data[i]; |
| 1705 | } |
| 1706 | |
| 1707 | return simple_read_from_buffer(buf, len, pos, &data, |
| 1708 | cnt * sizeof(u32)); |
| 1709 | } |
| 1710 | |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 1711 | static ssize_t spufs_wbox_info_read(struct file *file, char __user *buf, |
| 1712 | size_t len, loff_t *pos) |
| 1713 | { |
| 1714 | struct spu_context *ctx = file->private_data; |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1715 | int ret; |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 1716 | |
| 1717 | if (!access_ok(VERIFY_WRITE, buf, len)) |
| 1718 | return -EFAULT; |
| 1719 | |
| 1720 | spu_acquire_saved(ctx); |
| 1721 | spin_lock(&ctx->csa.register_lock); |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1722 | ret = __spufs_wbox_info_read(ctx, buf, len, pos); |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 1723 | spin_unlock(&ctx->csa.register_lock); |
| 1724 | spu_release(ctx); |
| 1725 | |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1726 | return ret; |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 1727 | } |
| 1728 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 1729 | static const struct file_operations spufs_wbox_info_fops = { |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 1730 | .open = spufs_info_open, |
| 1731 | .read = spufs_wbox_info_read, |
| 1732 | .llseek = generic_file_llseek, |
| 1733 | }; |
| 1734 | |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1735 | static ssize_t __spufs_dma_info_read(struct spu_context *ctx, |
| 1736 | char __user *buf, size_t len, loff_t *pos) |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 1737 | { |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 1738 | struct spu_dma_info info; |
| 1739 | struct mfc_cq_sr *qp, *spuqp; |
| 1740 | int i; |
| 1741 | |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 1742 | info.dma_info_type = ctx->csa.priv2.spu_tag_status_query_RW; |
| 1743 | info.dma_info_mask = ctx->csa.lscsa->tag_mask.slot[0]; |
| 1744 | info.dma_info_status = ctx->csa.spu_chnldata_RW[24]; |
| 1745 | info.dma_info_stall_and_notify = ctx->csa.spu_chnldata_RW[25]; |
| 1746 | info.dma_info_atomic_command_status = ctx->csa.spu_chnldata_RW[27]; |
| 1747 | for (i = 0; i < 16; i++) { |
| 1748 | qp = &info.dma_info_command_data[i]; |
| 1749 | spuqp = &ctx->csa.priv2.spuq[i]; |
| 1750 | |
| 1751 | qp->mfc_cq_data0_RW = spuqp->mfc_cq_data0_RW; |
| 1752 | qp->mfc_cq_data1_RW = spuqp->mfc_cq_data1_RW; |
| 1753 | qp->mfc_cq_data2_RW = spuqp->mfc_cq_data2_RW; |
| 1754 | qp->mfc_cq_data3_RW = spuqp->mfc_cq_data3_RW; |
| 1755 | } |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 1756 | |
| 1757 | return simple_read_from_buffer(buf, len, pos, &info, |
| 1758 | sizeof info); |
| 1759 | } |
| 1760 | |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1761 | static ssize_t spufs_dma_info_read(struct file *file, char __user *buf, |
| 1762 | size_t len, loff_t *pos) |
| 1763 | { |
| 1764 | struct spu_context *ctx = file->private_data; |
| 1765 | int ret; |
| 1766 | |
| 1767 | if (!access_ok(VERIFY_WRITE, buf, len)) |
| 1768 | return -EFAULT; |
| 1769 | |
| 1770 | spu_acquire_saved(ctx); |
| 1771 | spin_lock(&ctx->csa.register_lock); |
| 1772 | ret = __spufs_dma_info_read(ctx, buf, len, pos); |
| 1773 | spin_unlock(&ctx->csa.register_lock); |
| 1774 | spu_release(ctx); |
| 1775 | |
| 1776 | return ret; |
| 1777 | } |
| 1778 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 1779 | static const struct file_operations spufs_dma_info_fops = { |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 1780 | .open = spufs_info_open, |
| 1781 | .read = spufs_dma_info_read, |
| 1782 | }; |
| 1783 | |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1784 | static ssize_t __spufs_proxydma_info_read(struct spu_context *ctx, |
| 1785 | char __user *buf, size_t len, loff_t *pos) |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 1786 | { |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 1787 | struct spu_proxydma_info info; |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 1788 | struct mfc_cq_sr *qp, *puqp; |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1789 | int ret = sizeof info; |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 1790 | int i; |
| 1791 | |
| 1792 | if (len < ret) |
| 1793 | return -EINVAL; |
| 1794 | |
| 1795 | if (!access_ok(VERIFY_WRITE, buf, len)) |
| 1796 | return -EFAULT; |
| 1797 | |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 1798 | info.proxydma_info_type = ctx->csa.prob.dma_querytype_RW; |
| 1799 | info.proxydma_info_mask = ctx->csa.prob.dma_querymask_RW; |
| 1800 | info.proxydma_info_status = ctx->csa.prob.dma_tagstatus_R; |
| 1801 | for (i = 0; i < 8; i++) { |
| 1802 | qp = &info.proxydma_info_command_data[i]; |
| 1803 | puqp = &ctx->csa.priv2.puq[i]; |
| 1804 | |
| 1805 | qp->mfc_cq_data0_RW = puqp->mfc_cq_data0_RW; |
| 1806 | qp->mfc_cq_data1_RW = puqp->mfc_cq_data1_RW; |
| 1807 | qp->mfc_cq_data2_RW = puqp->mfc_cq_data2_RW; |
| 1808 | qp->mfc_cq_data3_RW = puqp->mfc_cq_data3_RW; |
| 1809 | } |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1810 | |
| 1811 | return simple_read_from_buffer(buf, len, pos, &info, |
| 1812 | sizeof info); |
| 1813 | } |
| 1814 | |
| 1815 | static ssize_t spufs_proxydma_info_read(struct file *file, char __user *buf, |
| 1816 | size_t len, loff_t *pos) |
| 1817 | { |
| 1818 | struct spu_context *ctx = file->private_data; |
| 1819 | int ret; |
| 1820 | |
| 1821 | spu_acquire_saved(ctx); |
| 1822 | spin_lock(&ctx->csa.register_lock); |
| 1823 | ret = __spufs_proxydma_info_read(ctx, buf, len, pos); |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 1824 | spin_unlock(&ctx->csa.register_lock); |
| 1825 | spu_release(ctx); |
| 1826 | |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 1827 | return ret; |
| 1828 | } |
| 1829 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 1830 | static const struct file_operations spufs_proxydma_info_fops = { |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 1831 | .open = spufs_info_open, |
| 1832 | .read = spufs_proxydma_info_read, |
| 1833 | }; |
| 1834 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1835 | struct tree_descr spufs_dir_contents[] = { |
| 1836 | { "mem", &spufs_mem_fops, 0666, }, |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1837 | { "regs", &spufs_regs_fops, 0666, }, |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1838 | { "mbox", &spufs_mbox_fops, 0444, }, |
| 1839 | { "ibox", &spufs_ibox_fops, 0444, }, |
| 1840 | { "wbox", &spufs_wbox_fops, 0222, }, |
| 1841 | { "mbox_stat", &spufs_mbox_stat_fops, 0444, }, |
| 1842 | { "ibox_stat", &spufs_ibox_stat_fops, 0444, }, |
| 1843 | { "wbox_stat", &spufs_wbox_stat_fops, 0444, }, |
| 1844 | { "signal1", &spufs_signal1_fops, 0666, }, |
| 1845 | { "signal2", &spufs_signal2_fops, 0666, }, |
| 1846 | { "signal1_type", &spufs_signal1_type, 0666, }, |
| 1847 | { "signal2_type", &spufs_signal2_type, 0666, }, |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 1848 | { "cntl", &spufs_cntl_fops, 0666, }, |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1849 | { "fpcr", &spufs_fpcr_fops, 0666, }, |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 1850 | { "lslr", &spufs_lslr_ops, 0444, }, |
| 1851 | { "mfc", &spufs_mfc_fops, 0666, }, |
| 1852 | { "mss", &spufs_mss_fops, 0666, }, |
| 1853 | { "npc", &spufs_npc_ops, 0666, }, |
| 1854 | { "srr0", &spufs_srr0_ops, 0666, }, |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1855 | { "decr", &spufs_decr_ops, 0666, }, |
| 1856 | { "decr_status", &spufs_decr_status_ops, 0666, }, |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1857 | { "event_mask", &spufs_event_mask_ops, 0666, }, |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 1858 | { "event_status", &spufs_event_status_ops, 0444, }, |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 1859 | { "psmap", &spufs_psmap_fops, 0666, }, |
Arnd Bergmann | 8676727 | 2006-10-04 17:26:21 +0200 | [diff] [blame] | 1860 | { "phys-id", &spufs_id_ops, 0666, }, |
| 1861 | { "object-id", &spufs_object_id_ops, 0666, }, |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 1862 | { "mbox_info", &spufs_mbox_info_fops, 0444, }, |
| 1863 | { "ibox_info", &spufs_ibox_info_fops, 0444, }, |
| 1864 | { "wbox_info", &spufs_wbox_info_fops, 0444, }, |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 1865 | { "dma_info", &spufs_dma_info_fops, 0444, }, |
| 1866 | { "proxydma_info", &spufs_proxydma_info_fops, 0444, }, |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1867 | {}, |
| 1868 | }; |
Mark Nutter | 5737edd | 2006-10-24 18:31:16 +0200 | [diff] [blame] | 1869 | |
| 1870 | struct tree_descr spufs_dir_nosched_contents[] = { |
| 1871 | { "mem", &spufs_mem_fops, 0666, }, |
| 1872 | { "mbox", &spufs_mbox_fops, 0444, }, |
| 1873 | { "ibox", &spufs_ibox_fops, 0444, }, |
| 1874 | { "wbox", &spufs_wbox_fops, 0222, }, |
| 1875 | { "mbox_stat", &spufs_mbox_stat_fops, 0444, }, |
| 1876 | { "ibox_stat", &spufs_ibox_stat_fops, 0444, }, |
| 1877 | { "wbox_stat", &spufs_wbox_stat_fops, 0444, }, |
| 1878 | { "signal1", &spufs_signal1_fops, 0666, }, |
| 1879 | { "signal2", &spufs_signal2_fops, 0666, }, |
| 1880 | { "signal1_type", &spufs_signal1_type, 0666, }, |
| 1881 | { "signal2_type", &spufs_signal2_type, 0666, }, |
| 1882 | { "mss", &spufs_mss_fops, 0666, }, |
| 1883 | { "mfc", &spufs_mfc_fops, 0666, }, |
| 1884 | { "cntl", &spufs_cntl_fops, 0666, }, |
| 1885 | { "npc", &spufs_npc_ops, 0666, }, |
| 1886 | { "psmap", &spufs_psmap_fops, 0666, }, |
| 1887 | { "phys-id", &spufs_id_ops, 0666, }, |
| 1888 | { "object-id", &spufs_object_id_ops, 0666, }, |
| 1889 | {}, |
| 1890 | }; |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1891 | |
| 1892 | struct spufs_coredump_reader spufs_coredump_read[] = { |
| 1893 | { "regs", __spufs_regs_read, NULL, 128 * 16 }, |
| 1894 | { "fpcr", __spufs_fpcr_read, NULL, 16 }, |
| 1895 | { "lslr", NULL, __spufs_lslr_get, 11 }, |
| 1896 | { "decr", NULL, __spufs_decr_get, 11 }, |
| 1897 | { "decr_status", NULL, __spufs_decr_status_get, 11 }, |
| 1898 | { "mem", __spufs_mem_read, NULL, 256 * 1024, }, |
| 1899 | { "signal1", __spufs_signal1_read, NULL, 4 }, |
| 1900 | { "signal1_type", NULL, __spufs_signal1_type_get, 2 }, |
| 1901 | { "signal2", __spufs_signal2_read, NULL, 4 }, |
| 1902 | { "signal2_type", NULL, __spufs_signal2_type_get, 2 }, |
| 1903 | { "event_mask", NULL, __spufs_event_mask_get, 8 }, |
| 1904 | { "event_status", NULL, __spufs_event_status_get, 8 }, |
| 1905 | { "mbox_info", __spufs_mbox_info_read, NULL, 4 }, |
| 1906 | { "ibox_info", __spufs_ibox_info_read, NULL, 4 }, |
| 1907 | { "wbox_info", __spufs_wbox_info_read, NULL, 16 }, |
| 1908 | { "dma_info", __spufs_dma_info_read, NULL, 69 * 8 }, |
| 1909 | { "proxydma_info", __spufs_proxydma_info_read, NULL, 35 * 8 }, |
| 1910 | { "object-id", NULL, __spufs_object_id_get, 19 }, |
| 1911 | { }, |
| 1912 | }; |
| 1913 | int spufs_coredump_num_notes = ARRAY_SIZE(spufs_coredump_read) - 1; |
| 1914 | |