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