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