blob: 7fb9a6dc4f184bdd49f8e00b7d6773e56a6dc95d [file] [log] [blame]
Arnd Bergmann67207b92005-11-15 15:53:48 -05001/*
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 Bergmanna33a7d72006-03-23 00:00:11 +010023#undef DEBUG
24
Arnd Bergmann67207b92005-11-15 15:53:48 -050025#include <linux/fs.h>
26#include <linux/ioctl.h>
27#include <linux/module.h>
Arnd Bergmannd88cfff2005-12-05 22:52:22 -050028#include <linux/pagemap.h>
Arnd Bergmann67207b92005-11-15 15:53:48 -050029#include <linux/poll.h>
Arnd Bergmann51104592005-12-05 22:52:25 -050030#include <linux/ptrace.h>
Arnd Bergmann67207b92005-11-15 15:53:48 -050031
32#include <asm/io.h>
33#include <asm/semaphore.h>
34#include <asm/spu.h>
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +010035#include <asm/spu_info.h>
Arnd Bergmann67207b92005-11-15 15:53:48 -050036#include <asm/uaccess.h>
37
38#include "spufs.h"
39
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +020040#define SPUFS_MMAP_4K (PAGE_SIZE == 0x1000)
41
Arnd Bergmann67207b92005-11-15 15:53:48 -050042static int
43spufs_mem_open(struct inode *inode, struct file *file)
44{
45 struct spufs_inode_info *i = SPUFS_I(inode);
Mark Nutter6df10a82006-03-23 00:00:12 +010046 struct spu_context *ctx = i->i_ctx;
47 file->private_data = ctx;
48 file->f_mapping = inode->i_mapping;
49 ctx->local_store = inode->i_mapping;
Arnd Bergmann67207b92005-11-15 15:53:48 -050050 return 0;
51}
52
53static ssize_t
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +010054__spufs_mem_read(struct spu_context *ctx, char __user *buffer,
55 size_t size, loff_t *pos)
56{
57 char *local_store = ctx->ops->get_ls(ctx);
58 return simple_read_from_buffer(buffer, size, pos, local_store,
59 LS_SIZE);
60}
61
62static ssize_t
Arnd Bergmann67207b92005-11-15 15:53:48 -050063spufs_mem_read(struct file *file, char __user *buffer,
64 size_t size, loff_t *pos)
65{
Arnd Bergmann67207b92005-11-15 15:53:48 -050066 int ret;
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +010067 struct spu_context *ctx = file->private_data;
Arnd Bergmann67207b92005-11-15 15:53:48 -050068
Arnd Bergmann8b3d6662005-11-15 15:53:52 -050069 spu_acquire(ctx);
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +010070 ret = __spufs_mem_read(ctx, buffer, size, pos);
Arnd Bergmann8b3d6662005-11-15 15:53:52 -050071 spu_release(ctx);
Arnd Bergmann67207b92005-11-15 15:53:48 -050072 return ret;
73}
74
75static ssize_t
76spufs_mem_write(struct file *file, const char __user *buffer,
77 size_t size, loff_t *pos)
78{
79 struct spu_context *ctx = file->private_data;
Arnd Bergmann8b3d6662005-11-15 15:53:52 -050080 char *local_store;
81 int ret;
Arnd Bergmann67207b92005-11-15 15:53:48 -050082
83 size = min_t(ssize_t, LS_SIZE - *pos, size);
84 if (size <= 0)
85 return -EFBIG;
86 *pos += size;
Arnd Bergmann8b3d6662005-11-15 15:53:52 -050087
88 spu_acquire(ctx);
89
90 local_store = ctx->ops->get_ls(ctx);
91 ret = copy_from_user(local_store + *pos - size,
92 buffer, size) ? -EFAULT : size;
93
94 spu_release(ctx);
95 return ret;
Arnd Bergmann67207b92005-11-15 15:53:48 -050096}
97
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +110098static unsigned long spufs_mem_mmap_nopfn(struct vm_area_struct *vma,
99 unsigned long address)
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500100{
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500101 struct spu_context *ctx = vma->vm_file->private_data;
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100102 unsigned long pfn, offset = address - vma->vm_start;
103
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500104 offset += vma->vm_pgoff << PAGE_SHIFT;
105
106 spu_acquire(ctx);
107
Arnd Bergmannac91cb82006-10-04 17:26:16 +0200108 if (ctx->state == SPU_STATE_SAVED) {
109 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
Arnd Bergmann932f535d2006-11-20 18:45:06 +0100110 & ~_PAGE_NO_CACHE);
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100111 pfn = vmalloc_to_pfn(ctx->csa.lscsa->ls + offset);
Arnd Bergmannac91cb82006-10-04 17:26:16 +0200112 } else {
113 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100114 | _PAGE_NO_CACHE);
115 pfn = (ctx->spu->local_store_phys + offset) >> PAGE_SHIFT;
Arnd Bergmannac91cb82006-10-04 17:26:16 +0200116 }
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100117 vm_insert_pfn(vma, address, pfn);
118
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500119 spu_release(ctx);
120
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100121 return NOPFN_REFAULT;
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500122}
123
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100124
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500125static struct vm_operations_struct spufs_mem_mmap_vmops = {
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100126 .nopfn = spufs_mem_mmap_nopfn,
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500127};
128
Arnd Bergmann67207b92005-11-15 15:53:48 -0500129static int
130spufs_mem_mmap(struct file *file, struct vm_area_struct *vma)
131{
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500132 if (!(vma->vm_flags & VM_SHARED))
133 return -EINVAL;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500134
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100135 vma->vm_flags |= VM_IO | VM_PFNMAP;
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500136 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 Bergmann67207b92005-11-15 15:53:48 -0500140 return 0;
141}
142
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -0800143static const struct file_operations spufs_mem_fops = {
Arnd Bergmann67207b92005-11-15 15:53:48 -0500144 .open = spufs_mem_open,
145 .read = spufs_mem_read,
146 .write = spufs_mem_write,
Arnd Bergmann67207b92005-11-15 15:53:48 -0500147 .llseek = generic_file_llseek,
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500148 .mmap = spufs_mem_mmap,
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500149};
150
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100151static unsigned long spufs_ps_nopfn(struct vm_area_struct *vma,
Mark Nutter6df10a82006-03-23 00:00:12 +0100152 unsigned long address,
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100153 unsigned long ps_offs,
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +0200154 unsigned long ps_size)
Mark Nutter6df10a82006-03-23 00:00:12 +0100155{
Mark Nutter6df10a82006-03-23 00:00:12 +0100156 struct spu_context *ctx = vma->vm_file->private_data;
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100157 unsigned long area, offset = address - vma->vm_start;
Mark Nutter6df10a82006-03-23 00:00:12 +0100158 int ret;
159
160 offset += vma->vm_pgoff << PAGE_SHIFT;
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +0200161 if (offset >= ps_size)
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100162 return NOPFN_SIGBUS;
Mark Nutter6df10a82006-03-23 00:00:12 +0100163
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100164 /* error here usually means a signal.. we might want to test
165 * the error code more precisely though
166 */
Mark Nutter6df10a82006-03-23 00:00:12 +0100167 ret = spu_acquire_runnable(ctx);
168 if (ret)
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100169 return NOPFN_REFAULT;
Mark Nutter6df10a82006-03-23 00:00:12 +0100170
171 area = ctx->spu->problem_phys + ps_offs;
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100172 vm_insert_pfn(vma, address, (area + offset) >> PAGE_SHIFT);
Mark Nutter6df10a82006-03-23 00:00:12 +0100173 spu_release(ctx);
174
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100175 return NOPFN_REFAULT;
Mark Nutter6df10a82006-03-23 00:00:12 +0100176}
177
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +0200178#if SPUFS_MMAP_4K
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100179static unsigned long spufs_cntl_mmap_nopfn(struct vm_area_struct *vma,
180 unsigned long address)
Mark Nutter6df10a82006-03-23 00:00:12 +0100181{
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100182 return spufs_ps_nopfn(vma, address, 0x4000, 0x1000);
Mark Nutter6df10a82006-03-23 00:00:12 +0100183}
184
185static struct vm_operations_struct spufs_cntl_mmap_vmops = {
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100186 .nopfn = spufs_cntl_mmap_nopfn,
Mark Nutter6df10a82006-03-23 00:00:12 +0100187};
188
189/*
190 * mmap support for problem state control area [0x4000 - 0x4fff].
Mark Nutter6df10a82006-03-23 00:00:12 +0100191 */
192static int spufs_cntl_mmap(struct file *file, struct vm_area_struct *vma)
193{
194 if (!(vma->vm_flags & VM_SHARED))
195 return -EINVAL;
196
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100197 vma->vm_flags |= VM_IO | VM_PFNMAP;
Mark Nutter6df10a82006-03-23 00:00:12 +0100198 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
Benjamin Herrenschmidt23cc7702006-06-23 20:57:47 +0200199 | _PAGE_NO_CACHE | _PAGE_GUARDED);
Mark Nutter6df10a82006-03-23 00:00:12 +0100200
201 vma->vm_ops = &spufs_cntl_mmap_vmops;
202 return 0;
203}
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +0200204#else /* SPUFS_MMAP_4K */
205#define spufs_cntl_mmap NULL
206#endif /* !SPUFS_MMAP_4K */
Mark Nutter6df10a82006-03-23 00:00:12 +0100207
Arnd Bergmanne1dbff22006-10-04 17:26:19 +0200208static u64 spufs_cntl_get(void *data)
209{
210 struct spu_context *ctx = data;
211 u64 val;
212
213 spu_acquire(ctx);
214 val = ctx->ops->status_read(ctx);
215 spu_release(ctx);
216
217 return val;
218}
219
220static void spufs_cntl_set(void *data, u64 val)
221{
222 struct spu_context *ctx = data;
223
224 spu_acquire(ctx);
225 ctx->ops->runcntl_write(ctx, val);
226 spu_release(ctx);
227}
228
Mark Nutter6df10a82006-03-23 00:00:12 +0100229static int spufs_cntl_open(struct inode *inode, struct file *file)
230{
231 struct spufs_inode_info *i = SPUFS_I(inode);
232 struct spu_context *ctx = i->i_ctx;
233
234 file->private_data = ctx;
235 file->f_mapping = inode->i_mapping;
236 ctx->cntl = inode->i_mapping;
Arnd Bergmanne1dbff22006-10-04 17:26:19 +0200237 return simple_attr_open(inode, file, spufs_cntl_get,
238 spufs_cntl_set, "0x%08lx");
Mark Nutter6df10a82006-03-23 00:00:12 +0100239}
240
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -0800241static const struct file_operations spufs_cntl_fops = {
Mark Nutter6df10a82006-03-23 00:00:12 +0100242 .open = spufs_cntl_open,
Noguchi, Masato654e4ae2006-10-10 10:27:29 +0200243 .release = simple_attr_close,
Arnd Bergmanne1dbff22006-10-04 17:26:19 +0200244 .read = simple_attr_read,
245 .write = simple_attr_write,
Mark Nutter6df10a82006-03-23 00:00:12 +0100246 .mmap = spufs_cntl_mmap,
Mark Nutter6df10a82006-03-23 00:00:12 +0100247};
248
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500249static int
250spufs_regs_open(struct inode *inode, struct file *file)
251{
252 struct spufs_inode_info *i = SPUFS_I(inode);
253 file->private_data = i->i_ctx;
254 return 0;
255}
256
257static ssize_t
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100258__spufs_regs_read(struct spu_context *ctx, char __user *buffer,
259 size_t size, loff_t *pos)
260{
261 struct spu_lscsa *lscsa = ctx->csa.lscsa;
262 return simple_read_from_buffer(buffer, size, pos,
263 lscsa->gprs, sizeof lscsa->gprs);
264}
265
266static ssize_t
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500267spufs_regs_read(struct file *file, char __user *buffer,
268 size_t size, loff_t *pos)
269{
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500270 int ret;
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100271 struct spu_context *ctx = file->private_data;
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500272
273 spu_acquire_saved(ctx);
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100274 ret = __spufs_regs_read(ctx, buffer, size, pos);
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500275 spu_release(ctx);
276 return ret;
277}
278
279static ssize_t
280spufs_regs_write(struct file *file, const char __user *buffer,
281 size_t size, loff_t *pos)
282{
283 struct spu_context *ctx = file->private_data;
284 struct spu_lscsa *lscsa = ctx->csa.lscsa;
285 int ret;
286
287 size = min_t(ssize_t, sizeof lscsa->gprs - *pos, size);
288 if (size <= 0)
289 return -EFBIG;
290 *pos += size;
291
292 spu_acquire_saved(ctx);
293
294 ret = copy_from_user(lscsa->gprs + *pos - size,
295 buffer, size) ? -EFAULT : size;
296
297 spu_release(ctx);
298 return ret;
299}
300
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -0800301static const struct file_operations spufs_regs_fops = {
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500302 .open = spufs_regs_open,
303 .read = spufs_regs_read,
304 .write = spufs_regs_write,
305 .llseek = generic_file_llseek,
306};
307
308static ssize_t
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100309__spufs_fpcr_read(struct spu_context *ctx, char __user * buffer,
310 size_t size, loff_t * pos)
311{
312 struct spu_lscsa *lscsa = ctx->csa.lscsa;
313 return simple_read_from_buffer(buffer, size, pos,
314 &lscsa->fpcr, sizeof(lscsa->fpcr));
315}
316
317static ssize_t
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500318spufs_fpcr_read(struct file *file, char __user * buffer,
319 size_t size, loff_t * pos)
320{
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500321 int ret;
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100322 struct spu_context *ctx = file->private_data;
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500323
324 spu_acquire_saved(ctx);
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100325 ret = __spufs_fpcr_read(ctx, buffer, size, pos);
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500326 spu_release(ctx);
327 return ret;
328}
329
330static ssize_t
331spufs_fpcr_write(struct file *file, const char __user * buffer,
332 size_t size, loff_t * pos)
333{
334 struct spu_context *ctx = file->private_data;
335 struct spu_lscsa *lscsa = ctx->csa.lscsa;
336 int ret;
337
338 size = min_t(ssize_t, sizeof(lscsa->fpcr) - *pos, size);
339 if (size <= 0)
340 return -EFBIG;
341 *pos += size;
342
343 spu_acquire_saved(ctx);
344
345 ret = copy_from_user((char *)&lscsa->fpcr + *pos - size,
346 buffer, size) ? -EFAULT : size;
347
348 spu_release(ctx);
349 return ret;
350}
351
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -0800352static const struct file_operations spufs_fpcr_fops = {
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500353 .open = spufs_regs_open,
354 .read = spufs_fpcr_read,
355 .write = spufs_fpcr_write,
356 .llseek = generic_file_llseek,
Arnd Bergmann67207b92005-11-15 15:53:48 -0500357};
358
359/* generic open function for all pipe-like files */
360static int spufs_pipe_open(struct inode *inode, struct file *file)
361{
362 struct spufs_inode_info *i = SPUFS_I(inode);
363 file->private_data = i->i_ctx;
364
365 return nonseekable_open(inode, file);
366}
367
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200368/*
369 * Read as many bytes from the mailbox as possible, until
370 * one of the conditions becomes true:
371 *
372 * - no more data available in the mailbox
373 * - end of the user provided buffer
374 * - end of the mapped area
375 */
Arnd Bergmann67207b92005-11-15 15:53:48 -0500376static ssize_t spufs_mbox_read(struct file *file, char __user *buf,
377 size_t len, loff_t *pos)
378{
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500379 struct spu_context *ctx = file->private_data;
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200380 u32 mbox_data, __user *udata;
381 ssize_t count;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500382
383 if (len < 4)
384 return -EINVAL;
385
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200386 if (!access_ok(VERIFY_WRITE, buf, len))
Arnd Bergmann67207b92005-11-15 15:53:48 -0500387 return -EFAULT;
388
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200389 udata = (void __user *)buf;
390
391 spu_acquire(ctx);
Arnd Bergmann274cef52006-10-24 18:01:42 +0200392 for (count = 0; (count + 4) <= len; count += 4, udata++) {
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200393 int ret;
394 ret = ctx->ops->mbox_read(ctx, &mbox_data);
395 if (ret == 0)
396 break;
397
398 /*
399 * at the end of the mapped area, we can fault
400 * but still need to return the data we have
401 * read successfully so far.
402 */
403 ret = __put_user(mbox_data, udata);
404 if (ret) {
405 if (!count)
406 count = -EFAULT;
407 break;
408 }
409 }
410 spu_release(ctx);
411
412 if (!count)
413 count = -EAGAIN;
414
415 return count;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500416}
417
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -0800418static const struct file_operations spufs_mbox_fops = {
Arnd Bergmann67207b92005-11-15 15:53:48 -0500419 .open = spufs_pipe_open,
420 .read = spufs_mbox_read,
421};
422
423static ssize_t spufs_mbox_stat_read(struct file *file, char __user *buf,
424 size_t len, loff_t *pos)
425{
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500426 struct spu_context *ctx = file->private_data;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500427 u32 mbox_stat;
428
429 if (len < 4)
430 return -EINVAL;
431
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500432 spu_acquire(ctx);
433
434 mbox_stat = ctx->ops->mbox_stat_read(ctx) & 0xff;
435
436 spu_release(ctx);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500437
438 if (copy_to_user(buf, &mbox_stat, sizeof mbox_stat))
439 return -EFAULT;
440
441 return 4;
442}
443
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -0800444static const struct file_operations spufs_mbox_stat_fops = {
Arnd Bergmann67207b92005-11-15 15:53:48 -0500445 .open = spufs_pipe_open,
446 .read = spufs_mbox_stat_read,
447};
448
449/* low-level ibox access function */
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500450size_t spu_ibox_read(struct spu_context *ctx, u32 *data)
Arnd Bergmann67207b92005-11-15 15:53:48 -0500451{
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500452 return ctx->ops->ibox_read(ctx, data);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500453}
Arnd Bergmann67207b92005-11-15 15:53:48 -0500454
455static int spufs_ibox_fasync(int fd, struct file *file, int on)
456{
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500457 struct spu_context *ctx = file->private_data;
458
459 return fasync_helper(fd, file, on, &ctx->ibox_fasync);
460}
461
462/* interrupt-level ibox callback function. */
463void spufs_ibox_callback(struct spu *spu)
464{
465 struct spu_context *ctx = spu->ctx;
466
467 wake_up_all(&ctx->ibox_wq);
468 kill_fasync(&ctx->ibox_fasync, SIGIO, POLLIN);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500469}
470
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200471/*
472 * Read as many bytes from the interrupt mailbox as possible, until
473 * one of the conditions becomes true:
474 *
475 * - no more data available in the mailbox
476 * - end of the user provided buffer
477 * - end of the mapped area
478 *
479 * If the file is opened without O_NONBLOCK, we wait here until
480 * any data is available, but return when we have been able to
481 * read something.
482 */
Arnd Bergmann67207b92005-11-15 15:53:48 -0500483static ssize_t spufs_ibox_read(struct file *file, char __user *buf,
484 size_t len, loff_t *pos)
485{
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500486 struct spu_context *ctx = file->private_data;
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200487 u32 ibox_data, __user *udata;
488 ssize_t count;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500489
490 if (len < 4)
491 return -EINVAL;
492
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200493 if (!access_ok(VERIFY_WRITE, buf, len))
494 return -EFAULT;
495
496 udata = (void __user *)buf;
497
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500498 spu_acquire(ctx);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500499
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200500 /* wait only for the first element */
501 count = 0;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500502 if (file->f_flags & O_NONBLOCK) {
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500503 if (!spu_ibox_read(ctx, &ibox_data))
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200504 count = -EAGAIN;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500505 } else {
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200506 count = spufs_wait(ctx->ibox_wq, spu_ibox_read(ctx, &ibox_data));
507 }
508 if (count)
509 goto out;
510
511 /* if we can't write at all, return -EFAULT */
512 count = __put_user(ibox_data, udata);
513 if (count)
514 goto out;
515
516 for (count = 4, udata++; (count + 4) <= len; count += 4, udata++) {
517 int ret;
518 ret = ctx->ops->ibox_read(ctx, &ibox_data);
519 if (ret == 0)
520 break;
521 /*
522 * at the end of the mapped area, we can fault
523 * but still need to return the data we have
524 * read successfully so far.
525 */
526 ret = __put_user(ibox_data, udata);
527 if (ret)
528 break;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500529 }
530
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200531out:
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500532 spu_release(ctx);
533
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200534 return count;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500535}
536
537static unsigned int spufs_ibox_poll(struct file *file, poll_table *wait)
538{
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500539 struct spu_context *ctx = file->private_data;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500540 unsigned int mask;
541
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500542 poll_wait(file, &ctx->ibox_wq, wait);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500543
Arnd Bergmann3a843d72005-12-05 22:52:27 -0500544 spu_acquire(ctx);
545 mask = ctx->ops->mbox_stat_poll(ctx, POLLIN | POLLRDNORM);
546 spu_release(ctx);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500547
548 return mask;
549}
550
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -0800551static const struct file_operations spufs_ibox_fops = {
Arnd Bergmann67207b92005-11-15 15:53:48 -0500552 .open = spufs_pipe_open,
553 .read = spufs_ibox_read,
554 .poll = spufs_ibox_poll,
555 .fasync = spufs_ibox_fasync,
556};
557
558static ssize_t spufs_ibox_stat_read(struct file *file, char __user *buf,
559 size_t len, loff_t *pos)
560{
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500561 struct spu_context *ctx = file->private_data;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500562 u32 ibox_stat;
563
564 if (len < 4)
565 return -EINVAL;
566
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500567 spu_acquire(ctx);
568 ibox_stat = (ctx->ops->mbox_stat_read(ctx) >> 16) & 0xff;
569 spu_release(ctx);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500570
571 if (copy_to_user(buf, &ibox_stat, sizeof ibox_stat))
572 return -EFAULT;
573
574 return 4;
575}
576
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -0800577static const struct file_operations spufs_ibox_stat_fops = {
Arnd Bergmann67207b92005-11-15 15:53:48 -0500578 .open = spufs_pipe_open,
579 .read = spufs_ibox_stat_read,
580};
581
582/* low-level mailbox write */
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500583size_t spu_wbox_write(struct spu_context *ctx, u32 data)
Arnd Bergmann67207b92005-11-15 15:53:48 -0500584{
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500585 return ctx->ops->wbox_write(ctx, data);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500586}
Arnd Bergmann67207b92005-11-15 15:53:48 -0500587
588static int spufs_wbox_fasync(int fd, struct file *file, int on)
589{
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500590 struct spu_context *ctx = file->private_data;
591 int ret;
592
593 ret = fasync_helper(fd, file, on, &ctx->wbox_fasync);
594
595 return ret;
596}
597
598/* interrupt-level wbox callback function. */
599void spufs_wbox_callback(struct spu *spu)
600{
601 struct spu_context *ctx = spu->ctx;
602
603 wake_up_all(&ctx->wbox_wq);
604 kill_fasync(&ctx->wbox_fasync, SIGIO, POLLOUT);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500605}
606
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200607/*
608 * Write as many bytes to the interrupt mailbox as possible, until
609 * one of the conditions becomes true:
610 *
611 * - the mailbox is full
612 * - end of the user provided buffer
613 * - end of the mapped area
614 *
615 * If the file is opened without O_NONBLOCK, we wait here until
616 * space is availabyl, but return when we have been able to
617 * write something.
618 */
Arnd Bergmann67207b92005-11-15 15:53:48 -0500619static ssize_t spufs_wbox_write(struct file *file, const char __user *buf,
620 size_t len, loff_t *pos)
621{
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500622 struct spu_context *ctx = file->private_data;
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200623 u32 wbox_data, __user *udata;
624 ssize_t count;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500625
626 if (len < 4)
627 return -EINVAL;
628
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200629 udata = (void __user *)buf;
630 if (!access_ok(VERIFY_READ, buf, len))
631 return -EFAULT;
632
633 if (__get_user(wbox_data, udata))
Arnd Bergmann67207b92005-11-15 15:53:48 -0500634 return -EFAULT;
635
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500636 spu_acquire(ctx);
637
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200638 /*
639 * make sure we can at least write one element, by waiting
640 * in case of !O_NONBLOCK
641 */
642 count = 0;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500643 if (file->f_flags & O_NONBLOCK) {
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500644 if (!spu_wbox_write(ctx, wbox_data))
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200645 count = -EAGAIN;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500646 } else {
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200647 count = spufs_wait(ctx->wbox_wq, spu_wbox_write(ctx, wbox_data));
Arnd Bergmann67207b92005-11-15 15:53:48 -0500648 }
649
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200650 if (count)
651 goto out;
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500652
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200653 /* write aѕ much as possible */
654 for (count = 4, udata++; (count + 4) <= len; count += 4, udata++) {
655 int ret;
656 ret = __get_user(wbox_data, udata);
657 if (ret)
658 break;
659
660 ret = spu_wbox_write(ctx, wbox_data);
661 if (ret == 0)
662 break;
663 }
664
665out:
666 spu_release(ctx);
667 return count;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500668}
669
670static unsigned int spufs_wbox_poll(struct file *file, poll_table *wait)
671{
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500672 struct spu_context *ctx = file->private_data;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500673 unsigned int mask;
674
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500675 poll_wait(file, &ctx->wbox_wq, wait);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500676
Arnd Bergmann3a843d72005-12-05 22:52:27 -0500677 spu_acquire(ctx);
678 mask = ctx->ops->mbox_stat_poll(ctx, POLLOUT | POLLWRNORM);
679 spu_release(ctx);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500680
681 return mask;
682}
683
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -0800684static const struct file_operations spufs_wbox_fops = {
Arnd Bergmann67207b92005-11-15 15:53:48 -0500685 .open = spufs_pipe_open,
686 .write = spufs_wbox_write,
687 .poll = spufs_wbox_poll,
688 .fasync = spufs_wbox_fasync,
689};
690
691static ssize_t spufs_wbox_stat_read(struct file *file, char __user *buf,
692 size_t len, loff_t *pos)
693{
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500694 struct spu_context *ctx = file->private_data;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500695 u32 wbox_stat;
696
697 if (len < 4)
698 return -EINVAL;
699
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500700 spu_acquire(ctx);
701 wbox_stat = (ctx->ops->mbox_stat_read(ctx) >> 8) & 0xff;
702 spu_release(ctx);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500703
704 if (copy_to_user(buf, &wbox_stat, sizeof wbox_stat))
705 return -EFAULT;
706
707 return 4;
708}
709
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -0800710static const struct file_operations spufs_wbox_stat_fops = {
Arnd Bergmann67207b92005-11-15 15:53:48 -0500711 .open = spufs_pipe_open,
712 .read = spufs_wbox_stat_read,
713};
714
Mark Nutter6df10a82006-03-23 00:00:12 +0100715static int spufs_signal1_open(struct inode *inode, struct file *file)
716{
717 struct spufs_inode_info *i = SPUFS_I(inode);
718 struct spu_context *ctx = i->i_ctx;
719 file->private_data = ctx;
720 file->f_mapping = inode->i_mapping;
721 ctx->signal1 = inode->i_mapping;
722 return nonseekable_open(inode, file);
723}
724
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100725static ssize_t __spufs_signal1_read(struct spu_context *ctx, char __user *buf,
Arnd Bergmann67207b92005-11-15 15:53:48 -0500726 size_t len, loff_t *pos)
727{
Dwayne Grant McConnell17f88ce2006-11-20 18:45:01 +0100728 int ret = 0;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500729 u32 data;
730
Arnd Bergmann67207b92005-11-15 15:53:48 -0500731 if (len < 4)
732 return -EINVAL;
733
Dwayne Grant McConnell17f88ce2006-11-20 18:45:01 +0100734 if (ctx->csa.spu_chnlcnt_RW[3]) {
735 data = ctx->csa.spu_chnldata_RW[3];
736 ret = 4;
737 }
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500738
Dwayne Grant McConnell17f88ce2006-11-20 18:45:01 +0100739 if (!ret)
740 goto out;
741
Arnd Bergmann67207b92005-11-15 15:53:48 -0500742 if (copy_to_user(buf, &data, 4))
743 return -EFAULT;
744
Dwayne Grant McConnell17f88ce2006-11-20 18:45:01 +0100745out:
746 return ret;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500747}
748
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100749static ssize_t spufs_signal1_read(struct file *file, char __user *buf,
750 size_t len, loff_t *pos)
751{
752 int ret;
753 struct spu_context *ctx = file->private_data;
754
755 spu_acquire_saved(ctx);
756 ret = __spufs_signal1_read(ctx, buf, len, pos);
757 spu_release(ctx);
758
759 return ret;
760}
761
Arnd Bergmann67207b92005-11-15 15:53:48 -0500762static ssize_t spufs_signal1_write(struct file *file, const char __user *buf,
763 size_t len, loff_t *pos)
764{
765 struct spu_context *ctx;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500766 u32 data;
767
768 ctx = file->private_data;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500769
770 if (len < 4)
771 return -EINVAL;
772
773 if (copy_from_user(&data, buf, 4))
774 return -EFAULT;
775
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500776 spu_acquire(ctx);
777 ctx->ops->signal1_write(ctx, data);
778 spu_release(ctx);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500779
780 return 4;
781}
782
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100783static unsigned long spufs_signal1_mmap_nopfn(struct vm_area_struct *vma,
784 unsigned long address)
Mark Nutter6df10a82006-03-23 00:00:12 +0100785{
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +0200786#if PAGE_SIZE == 0x1000
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100787 return spufs_ps_nopfn(vma, address, 0x14000, 0x1000);
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +0200788#elif PAGE_SIZE == 0x10000
789 /* For 64k pages, both signal1 and signal2 can be used to mmap the whole
790 * signal 1 and 2 area
791 */
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100792 return spufs_ps_nopfn(vma, address, 0x10000, 0x10000);
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +0200793#else
794#error unsupported page size
795#endif
Mark Nutter6df10a82006-03-23 00:00:12 +0100796}
797
798static struct vm_operations_struct spufs_signal1_mmap_vmops = {
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100799 .nopfn = spufs_signal1_mmap_nopfn,
Mark Nutter6df10a82006-03-23 00:00:12 +0100800};
801
802static int spufs_signal1_mmap(struct file *file, struct vm_area_struct *vma)
803{
804 if (!(vma->vm_flags & VM_SHARED))
805 return -EINVAL;
806
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100807 vma->vm_flags |= VM_IO | VM_PFNMAP;
Mark Nutter6df10a82006-03-23 00:00:12 +0100808 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
Benjamin Herrenschmidt23cc7702006-06-23 20:57:47 +0200809 | _PAGE_NO_CACHE | _PAGE_GUARDED);
Mark Nutter6df10a82006-03-23 00:00:12 +0100810
811 vma->vm_ops = &spufs_signal1_mmap_vmops;
812 return 0;
813}
Mark Nutter6df10a82006-03-23 00:00:12 +0100814
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -0800815static const struct file_operations spufs_signal1_fops = {
Mark Nutter6df10a82006-03-23 00:00:12 +0100816 .open = spufs_signal1_open,
Arnd Bergmann67207b92005-11-15 15:53:48 -0500817 .read = spufs_signal1_read,
818 .write = spufs_signal1_write,
Mark Nutter6df10a82006-03-23 00:00:12 +0100819 .mmap = spufs_signal1_mmap,
Arnd Bergmann67207b92005-11-15 15:53:48 -0500820};
821
Mark Nutter6df10a82006-03-23 00:00:12 +0100822static int spufs_signal2_open(struct inode *inode, struct file *file)
823{
824 struct spufs_inode_info *i = SPUFS_I(inode);
825 struct spu_context *ctx = i->i_ctx;
826 file->private_data = ctx;
827 file->f_mapping = inode->i_mapping;
828 ctx->signal2 = inode->i_mapping;
829 return nonseekable_open(inode, file);
830}
831
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100832static ssize_t __spufs_signal2_read(struct spu_context *ctx, char __user *buf,
Arnd Bergmann67207b92005-11-15 15:53:48 -0500833 size_t len, loff_t *pos)
834{
Dwayne Grant McConnell17f88ce2006-11-20 18:45:01 +0100835 int ret = 0;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500836 u32 data;
837
Arnd Bergmann67207b92005-11-15 15:53:48 -0500838 if (len < 4)
839 return -EINVAL;
840
Dwayne Grant McConnell17f88ce2006-11-20 18:45:01 +0100841 if (ctx->csa.spu_chnlcnt_RW[4]) {
842 data = ctx->csa.spu_chnldata_RW[4];
843 ret = 4;
844 }
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500845
Dwayne Grant McConnell17f88ce2006-11-20 18:45:01 +0100846 if (!ret)
847 goto out;
848
Arnd Bergmann67207b92005-11-15 15:53:48 -0500849 if (copy_to_user(buf, &data, 4))
850 return -EFAULT;
851
Dwayne Grant McConnell17f88ce2006-11-20 18:45:01 +0100852out:
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100853 return ret;
854}
855
856static ssize_t spufs_signal2_read(struct file *file, char __user *buf,
857 size_t len, loff_t *pos)
858{
859 struct spu_context *ctx = file->private_data;
860 int ret;
861
862 spu_acquire_saved(ctx);
863 ret = __spufs_signal2_read(ctx, buf, len, pos);
864 spu_release(ctx);
865
866 return ret;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500867}
868
869static ssize_t spufs_signal2_write(struct file *file, const char __user *buf,
870 size_t len, loff_t *pos)
871{
872 struct spu_context *ctx;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500873 u32 data;
874
875 ctx = file->private_data;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500876
877 if (len < 4)
878 return -EINVAL;
879
880 if (copy_from_user(&data, buf, 4))
881 return -EFAULT;
882
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500883 spu_acquire(ctx);
884 ctx->ops->signal2_write(ctx, data);
885 spu_release(ctx);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500886
887 return 4;
888}
889
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +0200890#if SPUFS_MMAP_4K
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100891static unsigned long spufs_signal2_mmap_nopfn(struct vm_area_struct *vma,
892 unsigned long address)
Mark Nutter6df10a82006-03-23 00:00:12 +0100893{
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +0200894#if PAGE_SIZE == 0x1000
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100895 return spufs_ps_nopfn(vma, address, 0x1c000, 0x1000);
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +0200896#elif PAGE_SIZE == 0x10000
897 /* For 64k pages, both signal1 and signal2 can be used to mmap the whole
898 * signal 1 and 2 area
899 */
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100900 return spufs_ps_nopfn(vma, address, 0x10000, 0x10000);
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +0200901#else
902#error unsupported page size
903#endif
Mark Nutter6df10a82006-03-23 00:00:12 +0100904}
905
906static struct vm_operations_struct spufs_signal2_mmap_vmops = {
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100907 .nopfn = spufs_signal2_mmap_nopfn,
Mark Nutter6df10a82006-03-23 00:00:12 +0100908};
909
910static int spufs_signal2_mmap(struct file *file, struct vm_area_struct *vma)
911{
912 if (!(vma->vm_flags & VM_SHARED))
913 return -EINVAL;
914
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100915 vma->vm_flags |= VM_IO | VM_PFNMAP;
Mark Nutter6df10a82006-03-23 00:00:12 +0100916 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
Benjamin Herrenschmidt23cc7702006-06-23 20:57:47 +0200917 | _PAGE_NO_CACHE | _PAGE_GUARDED);
Mark Nutter6df10a82006-03-23 00:00:12 +0100918
919 vma->vm_ops = &spufs_signal2_mmap_vmops;
920 return 0;
921}
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +0200922#else /* SPUFS_MMAP_4K */
923#define spufs_signal2_mmap NULL
924#endif /* !SPUFS_MMAP_4K */
Mark Nutter6df10a82006-03-23 00:00:12 +0100925
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -0800926static const struct file_operations spufs_signal2_fops = {
Mark Nutter6df10a82006-03-23 00:00:12 +0100927 .open = spufs_signal2_open,
Arnd Bergmann67207b92005-11-15 15:53:48 -0500928 .read = spufs_signal2_read,
929 .write = spufs_signal2_write,
Mark Nutter6df10a82006-03-23 00:00:12 +0100930 .mmap = spufs_signal2_mmap,
Arnd Bergmann67207b92005-11-15 15:53:48 -0500931};
932
933static void spufs_signal1_type_set(void *data, u64 val)
934{
935 struct spu_context *ctx = data;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500936
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500937 spu_acquire(ctx);
938 ctx->ops->signal1_type_set(ctx, val);
939 spu_release(ctx);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500940}
941
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100942static u64 __spufs_signal1_type_get(void *data)
943{
944 struct spu_context *ctx = data;
945 return ctx->ops->signal1_type_get(ctx);
946}
947
Arnd Bergmann67207b92005-11-15 15:53:48 -0500948static u64 spufs_signal1_type_get(void *data)
949{
950 struct spu_context *ctx = data;
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500951 u64 ret;
952
953 spu_acquire(ctx);
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100954 ret = __spufs_signal1_type_get(data);
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500955 spu_release(ctx);
956
957 return ret;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500958}
959DEFINE_SIMPLE_ATTRIBUTE(spufs_signal1_type, spufs_signal1_type_get,
960 spufs_signal1_type_set, "%llu");
961
962static void spufs_signal2_type_set(void *data, u64 val)
963{
964 struct spu_context *ctx = data;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500965
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500966 spu_acquire(ctx);
967 ctx->ops->signal2_type_set(ctx, val);
968 spu_release(ctx);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500969}
970
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100971static u64 __spufs_signal2_type_get(void *data)
972{
973 struct spu_context *ctx = data;
974 return ctx->ops->signal2_type_get(ctx);
975}
976
Arnd Bergmann67207b92005-11-15 15:53:48 -0500977static u64 spufs_signal2_type_get(void *data)
978{
979 struct spu_context *ctx = data;
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500980 u64 ret;
981
982 spu_acquire(ctx);
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100983 ret = __spufs_signal2_type_get(data);
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500984 spu_release(ctx);
985
986 return ret;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500987}
988DEFINE_SIMPLE_ATTRIBUTE(spufs_signal2_type, spufs_signal2_type_get,
989 spufs_signal2_type_set, "%llu");
990
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +0200991#if SPUFS_MMAP_4K
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100992static unsigned long spufs_mss_mmap_nopfn(struct vm_area_struct *vma,
993 unsigned long address)
arnd@arndb.ded9379c42006-06-19 20:33:21 +0200994{
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100995 return spufs_ps_nopfn(vma, address, 0x0000, 0x1000);
arnd@arndb.ded9379c42006-06-19 20:33:21 +0200996}
997
998static struct vm_operations_struct spufs_mss_mmap_vmops = {
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100999 .nopfn = spufs_mss_mmap_nopfn,
arnd@arndb.ded9379c42006-06-19 20:33:21 +02001000};
1001
1002/*
1003 * mmap support for problem state MFC DMA area [0x0000 - 0x0fff].
arnd@arndb.ded9379c42006-06-19 20:33:21 +02001004 */
1005static int spufs_mss_mmap(struct file *file, struct vm_area_struct *vma)
1006{
1007 if (!(vma->vm_flags & VM_SHARED))
1008 return -EINVAL;
1009
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +11001010 vma->vm_flags |= VM_IO | VM_PFNMAP;
arnd@arndb.ded9379c42006-06-19 20:33:21 +02001011 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
Benjamin Herrenschmidt23cc7702006-06-23 20:57:47 +02001012 | _PAGE_NO_CACHE | _PAGE_GUARDED);
arnd@arndb.ded9379c42006-06-19 20:33:21 +02001013
1014 vma->vm_ops = &spufs_mss_mmap_vmops;
1015 return 0;
1016}
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +02001017#else /* SPUFS_MMAP_4K */
1018#define spufs_mss_mmap NULL
1019#endif /* !SPUFS_MMAP_4K */
arnd@arndb.ded9379c42006-06-19 20:33:21 +02001020
1021static int spufs_mss_open(struct inode *inode, struct file *file)
1022{
1023 struct spufs_inode_info *i = SPUFS_I(inode);
1024
1025 file->private_data = i->i_ctx;
1026 return nonseekable_open(inode, file);
1027}
1028
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -08001029static const struct file_operations spufs_mss_fops = {
arnd@arndb.ded9379c42006-06-19 20:33:21 +02001030 .open = spufs_mss_open,
arnd@arndb.ded9379c42006-06-19 20:33:21 +02001031 .mmap = spufs_mss_mmap,
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +02001032};
1033
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +11001034static unsigned long spufs_psmap_mmap_nopfn(struct vm_area_struct *vma,
1035 unsigned long address)
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +02001036{
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +11001037 return spufs_ps_nopfn(vma, address, 0x0000, 0x20000);
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +02001038}
1039
1040static struct vm_operations_struct spufs_psmap_mmap_vmops = {
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +11001041 .nopfn = spufs_psmap_mmap_nopfn,
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +02001042};
1043
1044/*
1045 * mmap support for full problem state area [0x00000 - 0x1ffff].
1046 */
1047static int spufs_psmap_mmap(struct file *file, struct vm_area_struct *vma)
1048{
1049 if (!(vma->vm_flags & VM_SHARED))
1050 return -EINVAL;
1051
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +11001052 vma->vm_flags |= VM_IO | VM_PFNMAP;
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +02001053 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
1054 | _PAGE_NO_CACHE | _PAGE_GUARDED);
1055
1056 vma->vm_ops = &spufs_psmap_mmap_vmops;
1057 return 0;
1058}
1059
1060static int spufs_psmap_open(struct inode *inode, struct file *file)
1061{
1062 struct spufs_inode_info *i = SPUFS_I(inode);
1063
1064 file->private_data = i->i_ctx;
1065 return nonseekable_open(inode, file);
1066}
1067
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -08001068static const struct file_operations spufs_psmap_fops = {
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +02001069 .open = spufs_psmap_open,
1070 .mmap = spufs_psmap_mmap,
arnd@arndb.ded9379c42006-06-19 20:33:21 +02001071};
1072
1073
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +02001074#if SPUFS_MMAP_4K
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +11001075static unsigned long spufs_mfc_mmap_nopfn(struct vm_area_struct *vma,
1076 unsigned long address)
Mark Nutter6df10a82006-03-23 00:00:12 +01001077{
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +11001078 return spufs_ps_nopfn(vma, address, 0x3000, 0x1000);
Mark Nutter6df10a82006-03-23 00:00:12 +01001079}
1080
1081static struct vm_operations_struct spufs_mfc_mmap_vmops = {
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +11001082 .nopfn = spufs_mfc_mmap_nopfn,
Mark Nutter6df10a82006-03-23 00:00:12 +01001083};
1084
1085/*
1086 * mmap support for problem state MFC DMA area [0x0000 - 0x0fff].
Mark Nutter6df10a82006-03-23 00:00:12 +01001087 */
1088static int spufs_mfc_mmap(struct file *file, struct vm_area_struct *vma)
1089{
1090 if (!(vma->vm_flags & VM_SHARED))
1091 return -EINVAL;
1092
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +11001093 vma->vm_flags |= VM_IO | VM_PFNMAP;
Mark Nutter6df10a82006-03-23 00:00:12 +01001094 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
Benjamin Herrenschmidt23cc7702006-06-23 20:57:47 +02001095 | _PAGE_NO_CACHE | _PAGE_GUARDED);
Mark Nutter6df10a82006-03-23 00:00:12 +01001096
1097 vma->vm_ops = &spufs_mfc_mmap_vmops;
1098 return 0;
1099}
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +02001100#else /* SPUFS_MMAP_4K */
1101#define spufs_mfc_mmap NULL
1102#endif /* !SPUFS_MMAP_4K */
Arnd Bergmanna33a7d72006-03-23 00:00:11 +01001103
1104static int spufs_mfc_open(struct inode *inode, struct file *file)
1105{
1106 struct spufs_inode_info *i = SPUFS_I(inode);
1107 struct spu_context *ctx = i->i_ctx;
1108
1109 /* we don't want to deal with DMA into other processes */
1110 if (ctx->owner != current->mm)
1111 return -EINVAL;
1112
1113 if (atomic_read(&inode->i_count) != 1)
1114 return -EBUSY;
1115
1116 file->private_data = ctx;
1117 return nonseekable_open(inode, file);
1118}
1119
1120/* interrupt-level mfc callback function. */
1121void spufs_mfc_callback(struct spu *spu)
1122{
1123 struct spu_context *ctx = spu->ctx;
1124
1125 wake_up_all(&ctx->mfc_wq);
1126
1127 pr_debug("%s %s\n", __FUNCTION__, spu->name);
1128 if (ctx->mfc_fasync) {
1129 u32 free_elements, tagstatus;
1130 unsigned int mask;
1131
1132 /* no need for spu_acquire in interrupt context */
1133 free_elements = ctx->ops->get_mfc_free_elements(ctx);
1134 tagstatus = ctx->ops->read_mfc_tagstatus(ctx);
1135
1136 mask = 0;
1137 if (free_elements & 0xffff)
1138 mask |= POLLOUT;
1139 if (tagstatus & ctx->tagwait)
1140 mask |= POLLIN;
1141
1142 kill_fasync(&ctx->mfc_fasync, SIGIO, mask);
1143 }
1144}
1145
1146static int spufs_read_mfc_tagstatus(struct spu_context *ctx, u32 *status)
1147{
1148 /* See if there is one tag group is complete */
1149 /* FIXME we need locking around tagwait */
1150 *status = ctx->ops->read_mfc_tagstatus(ctx) & ctx->tagwait;
1151 ctx->tagwait &= ~*status;
1152 if (*status)
1153 return 1;
1154
1155 /* enable interrupt waiting for any tag group,
1156 may silently fail if interrupts are already enabled */
1157 ctx->ops->set_mfc_query(ctx, ctx->tagwait, 1);
1158 return 0;
1159}
1160
1161static ssize_t spufs_mfc_read(struct file *file, char __user *buffer,
1162 size_t size, loff_t *pos)
1163{
1164 struct spu_context *ctx = file->private_data;
1165 int ret = -EINVAL;
1166 u32 status;
1167
1168 if (size != 4)
1169 goto out;
1170
1171 spu_acquire(ctx);
1172 if (file->f_flags & O_NONBLOCK) {
1173 status = ctx->ops->read_mfc_tagstatus(ctx);
1174 if (!(status & ctx->tagwait))
1175 ret = -EAGAIN;
1176 else
1177 ctx->tagwait &= ~status;
1178 } else {
1179 ret = spufs_wait(ctx->mfc_wq,
1180 spufs_read_mfc_tagstatus(ctx, &status));
1181 }
1182 spu_release(ctx);
1183
1184 if (ret)
1185 goto out;
1186
1187 ret = 4;
1188 if (copy_to_user(buffer, &status, 4))
1189 ret = -EFAULT;
1190
1191out:
1192 return ret;
1193}
1194
1195static int spufs_check_valid_dma(struct mfc_dma_command *cmd)
1196{
1197 pr_debug("queueing DMA %x %lx %x %x %x\n", cmd->lsa,
1198 cmd->ea, cmd->size, cmd->tag, cmd->cmd);
1199
1200 switch (cmd->cmd) {
1201 case MFC_PUT_CMD:
1202 case MFC_PUTF_CMD:
1203 case MFC_PUTB_CMD:
1204 case MFC_GET_CMD:
1205 case MFC_GETF_CMD:
1206 case MFC_GETB_CMD:
1207 break;
1208 default:
1209 pr_debug("invalid DMA opcode %x\n", cmd->cmd);
1210 return -EIO;
1211 }
1212
1213 if ((cmd->lsa & 0xf) != (cmd->ea &0xf)) {
1214 pr_debug("invalid DMA alignment, ea %lx lsa %x\n",
1215 cmd->ea, cmd->lsa);
1216 return -EIO;
1217 }
1218
1219 switch (cmd->size & 0xf) {
1220 case 1:
1221 break;
1222 case 2:
1223 if (cmd->lsa & 1)
1224 goto error;
1225 break;
1226 case 4:
1227 if (cmd->lsa & 3)
1228 goto error;
1229 break;
1230 case 8:
1231 if (cmd->lsa & 7)
1232 goto error;
1233 break;
1234 case 0:
1235 if (cmd->lsa & 15)
1236 goto error;
1237 break;
1238 error:
1239 default:
1240 pr_debug("invalid DMA alignment %x for size %x\n",
1241 cmd->lsa & 0xf, cmd->size);
1242 return -EIO;
1243 }
1244
1245 if (cmd->size > 16 * 1024) {
1246 pr_debug("invalid DMA size %x\n", cmd->size);
1247 return -EIO;
1248 }
1249
1250 if (cmd->tag & 0xfff0) {
1251 /* we reserve the higher tag numbers for kernel use */
1252 pr_debug("invalid DMA tag\n");
1253 return -EIO;
1254 }
1255
1256 if (cmd->class) {
1257 /* not supported in this version */
1258 pr_debug("invalid DMA class\n");
1259 return -EIO;
1260 }
1261
1262 return 0;
1263}
1264
1265static int spu_send_mfc_command(struct spu_context *ctx,
1266 struct mfc_dma_command cmd,
1267 int *error)
1268{
1269 *error = ctx->ops->send_mfc_command(ctx, &cmd);
1270 if (*error == -EAGAIN) {
1271 /* wait for any tag group to complete
1272 so we have space for the new command */
1273 ctx->ops->set_mfc_query(ctx, ctx->tagwait, 1);
1274 /* try again, because the queue might be
1275 empty again */
1276 *error = ctx->ops->send_mfc_command(ctx, &cmd);
1277 if (*error == -EAGAIN)
1278 return 0;
1279 }
1280 return 1;
1281}
1282
1283static ssize_t spufs_mfc_write(struct file *file, const char __user *buffer,
1284 size_t size, loff_t *pos)
1285{
1286 struct spu_context *ctx = file->private_data;
1287 struct mfc_dma_command cmd;
1288 int ret = -EINVAL;
1289
1290 if (size != sizeof cmd)
1291 goto out;
1292
1293 ret = -EFAULT;
1294 if (copy_from_user(&cmd, buffer, sizeof cmd))
1295 goto out;
1296
1297 ret = spufs_check_valid_dma(&cmd);
1298 if (ret)
1299 goto out;
1300
1301 spu_acquire_runnable(ctx);
1302 if (file->f_flags & O_NONBLOCK) {
1303 ret = ctx->ops->send_mfc_command(ctx, &cmd);
1304 } else {
1305 int status;
1306 ret = spufs_wait(ctx->mfc_wq,
1307 spu_send_mfc_command(ctx, cmd, &status));
1308 if (status)
1309 ret = status;
1310 }
1311 spu_release(ctx);
1312
1313 if (ret)
1314 goto out;
1315
1316 ctx->tagwait |= 1 << cmd.tag;
Masato Noguchi3692dc62006-11-20 18:45:07 +01001317 ret = size;
Arnd Bergmanna33a7d72006-03-23 00:00:11 +01001318
1319out:
1320 return ret;
1321}
1322
1323static unsigned int spufs_mfc_poll(struct file *file,poll_table *wait)
1324{
1325 struct spu_context *ctx = file->private_data;
1326 u32 free_elements, tagstatus;
1327 unsigned int mask;
1328
1329 spu_acquire(ctx);
1330 ctx->ops->set_mfc_query(ctx, ctx->tagwait, 2);
1331 free_elements = ctx->ops->get_mfc_free_elements(ctx);
1332 tagstatus = ctx->ops->read_mfc_tagstatus(ctx);
1333 spu_release(ctx);
1334
1335 poll_wait(file, &ctx->mfc_wq, wait);
1336
1337 mask = 0;
1338 if (free_elements & 0xffff)
1339 mask |= POLLOUT | POLLWRNORM;
1340 if (tagstatus & ctx->tagwait)
1341 mask |= POLLIN | POLLRDNORM;
1342
1343 pr_debug("%s: free %d tagstatus %d tagwait %d\n", __FUNCTION__,
1344 free_elements, tagstatus, ctx->tagwait);
1345
1346 return mask;
1347}
1348
Al Viro73b6af82006-06-25 16:42:33 -07001349static int spufs_mfc_flush(struct file *file, fl_owner_t id)
Arnd Bergmanna33a7d72006-03-23 00:00:11 +01001350{
1351 struct spu_context *ctx = file->private_data;
1352 int ret;
1353
1354 spu_acquire(ctx);
1355#if 0
1356/* this currently hangs */
1357 ret = spufs_wait(ctx->mfc_wq,
1358 ctx->ops->set_mfc_query(ctx, ctx->tagwait, 2));
1359 if (ret)
1360 goto out;
1361 ret = spufs_wait(ctx->mfc_wq,
1362 ctx->ops->read_mfc_tagstatus(ctx) == ctx->tagwait);
1363out:
1364#else
1365 ret = 0;
1366#endif
1367 spu_release(ctx);
1368
1369 return ret;
1370}
1371
1372static int spufs_mfc_fsync(struct file *file, struct dentry *dentry,
1373 int datasync)
1374{
Al Viro73b6af82006-06-25 16:42:33 -07001375 return spufs_mfc_flush(file, NULL);
Arnd Bergmanna33a7d72006-03-23 00:00:11 +01001376}
1377
1378static int spufs_mfc_fasync(int fd, struct file *file, int on)
1379{
1380 struct spu_context *ctx = file->private_data;
1381
1382 return fasync_helper(fd, file, on, &ctx->mfc_fasync);
1383}
1384
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -08001385static const struct file_operations spufs_mfc_fops = {
Arnd Bergmanna33a7d72006-03-23 00:00:11 +01001386 .open = spufs_mfc_open,
1387 .read = spufs_mfc_read,
1388 .write = spufs_mfc_write,
1389 .poll = spufs_mfc_poll,
1390 .flush = spufs_mfc_flush,
1391 .fsync = spufs_mfc_fsync,
1392 .fasync = spufs_mfc_fasync,
Mark Nutter6df10a82006-03-23 00:00:12 +01001393 .mmap = spufs_mfc_mmap,
Arnd Bergmanna33a7d72006-03-23 00:00:11 +01001394};
1395
Arnd Bergmann67207b92005-11-15 15:53:48 -05001396static void spufs_npc_set(void *data, u64 val)
1397{
1398 struct spu_context *ctx = data;
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001399 spu_acquire(ctx);
1400 ctx->ops->npc_write(ctx, val);
1401 spu_release(ctx);
Arnd Bergmann67207b92005-11-15 15:53:48 -05001402}
1403
1404static u64 spufs_npc_get(void *data)
1405{
1406 struct spu_context *ctx = data;
1407 u64 ret;
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001408 spu_acquire(ctx);
1409 ret = ctx->ops->npc_read(ctx);
1410 spu_release(ctx);
Arnd Bergmann67207b92005-11-15 15:53:48 -05001411 return ret;
1412}
Dwayne Grant McConnell9b5047e2006-11-20 18:44:57 +01001413DEFINE_SIMPLE_ATTRIBUTE(spufs_npc_ops, spufs_npc_get, spufs_npc_set,
1414 "0x%llx\n")
Arnd Bergmann67207b92005-11-15 15:53:48 -05001415
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001416static void spufs_decr_set(void *data, u64 val)
1417{
1418 struct spu_context *ctx = data;
1419 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1420 spu_acquire_saved(ctx);
1421 lscsa->decr.slot[0] = (u32) val;
1422 spu_release(ctx);
1423}
1424
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001425static u64 __spufs_decr_get(void *data)
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001426{
1427 struct spu_context *ctx = data;
1428 struct spu_lscsa *lscsa = ctx->csa.lscsa;
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001429 return lscsa->decr.slot[0];
1430}
1431
1432static u64 spufs_decr_get(void *data)
1433{
1434 struct spu_context *ctx = data;
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001435 u64 ret;
1436 spu_acquire_saved(ctx);
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001437 ret = __spufs_decr_get(data);
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001438 spu_release(ctx);
1439 return ret;
1440}
1441DEFINE_SIMPLE_ATTRIBUTE(spufs_decr_ops, spufs_decr_get, spufs_decr_set,
Dwayne Grant McConnell9b5047e2006-11-20 18:44:57 +01001442 "0x%llx\n")
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001443
1444static void spufs_decr_status_set(void *data, u64 val)
1445{
1446 struct spu_context *ctx = data;
1447 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1448 spu_acquire_saved(ctx);
1449 lscsa->decr_status.slot[0] = (u32) val;
1450 spu_release(ctx);
1451}
1452
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001453static u64 __spufs_decr_status_get(void *data)
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001454{
1455 struct spu_context *ctx = data;
1456 struct spu_lscsa *lscsa = ctx->csa.lscsa;
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001457 return lscsa->decr_status.slot[0];
1458}
1459
1460static u64 spufs_decr_status_get(void *data)
1461{
1462 struct spu_context *ctx = data;
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001463 u64 ret;
1464 spu_acquire_saved(ctx);
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001465 ret = __spufs_decr_status_get(data);
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001466 spu_release(ctx);
1467 return ret;
1468}
1469DEFINE_SIMPLE_ATTRIBUTE(spufs_decr_status_ops, spufs_decr_status_get,
Dwayne Grant McConnell9b5047e2006-11-20 18:44:57 +01001470 spufs_decr_status_set, "0x%llx\n")
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001471
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001472static void spufs_event_mask_set(void *data, u64 val)
1473{
1474 struct spu_context *ctx = data;
1475 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1476 spu_acquire_saved(ctx);
1477 lscsa->event_mask.slot[0] = (u32) val;
1478 spu_release(ctx);
1479}
1480
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001481static u64 __spufs_event_mask_get(void *data)
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001482{
1483 struct spu_context *ctx = data;
1484 struct spu_lscsa *lscsa = ctx->csa.lscsa;
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001485 return lscsa->event_mask.slot[0];
1486}
1487
1488static u64 spufs_event_mask_get(void *data)
1489{
1490 struct spu_context *ctx = data;
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001491 u64 ret;
1492 spu_acquire_saved(ctx);
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001493 ret = __spufs_event_mask_get(data);
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001494 spu_release(ctx);
1495 return ret;
1496}
1497DEFINE_SIMPLE_ATTRIBUTE(spufs_event_mask_ops, spufs_event_mask_get,
Dwayne Grant McConnell9b5047e2006-11-20 18:44:57 +01001498 spufs_event_mask_set, "0x%llx\n")
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001499
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001500static u64 __spufs_event_status_get(void *data)
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01001501{
1502 struct spu_context *ctx = data;
1503 struct spu_state *state = &ctx->csa;
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01001504 u64 stat;
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01001505 stat = state->spu_chnlcnt_RW[0];
1506 if (stat)
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001507 return state->spu_chnldata_RW[0];
1508 return 0;
1509}
1510
1511static u64 spufs_event_status_get(void *data)
1512{
1513 struct spu_context *ctx = data;
1514 u64 ret = 0;
1515
1516 spu_acquire_saved(ctx);
1517 ret = __spufs_event_status_get(data);
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01001518 spu_release(ctx);
1519 return ret;
1520}
1521DEFINE_SIMPLE_ATTRIBUTE(spufs_event_status_ops, spufs_event_status_get,
1522 NULL, "0x%llx\n")
1523
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001524static void spufs_srr0_set(void *data, u64 val)
1525{
1526 struct spu_context *ctx = data;
1527 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1528 spu_acquire_saved(ctx);
1529 lscsa->srr0.slot[0] = (u32) val;
1530 spu_release(ctx);
1531}
1532
1533static u64 spufs_srr0_get(void *data)
1534{
1535 struct spu_context *ctx = data;
1536 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1537 u64 ret;
1538 spu_acquire_saved(ctx);
1539 ret = lscsa->srr0.slot[0];
1540 spu_release(ctx);
1541 return ret;
1542}
1543DEFINE_SIMPLE_ATTRIBUTE(spufs_srr0_ops, spufs_srr0_get, spufs_srr0_set,
Dwayne Grant McConnell9b5047e2006-11-20 18:44:57 +01001544 "0x%llx\n")
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001545
arnd@arndb.de7b1a7012006-06-19 20:33:24 +02001546static u64 spufs_id_get(void *data)
1547{
1548 struct spu_context *ctx = data;
1549 u64 num;
1550
1551 spu_acquire(ctx);
1552 if (ctx->state == SPU_STATE_RUNNABLE)
1553 num = ctx->spu->number;
1554 else
1555 num = (unsigned int)-1;
1556 spu_release(ctx);
1557
1558 return num;
1559}
Al Viroe45d6632006-09-23 01:37:41 +01001560DEFINE_SIMPLE_ATTRIBUTE(spufs_id_ops, spufs_id_get, NULL, "0x%llx\n")
arnd@arndb.de7b1a7012006-06-19 20:33:24 +02001561
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001562static u64 __spufs_object_id_get(void *data)
Arnd Bergmann86767272006-10-04 17:26:21 +02001563{
1564 struct spu_context *ctx = data;
1565 return ctx->object_id;
1566}
1567
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001568static u64 spufs_object_id_get(void *data)
1569{
1570 /* FIXME: Should there really be no locking here? */
1571 return __spufs_object_id_get(data);
1572}
1573
Arnd Bergmann86767272006-10-04 17:26:21 +02001574static void spufs_object_id_set(void *data, u64 id)
1575{
1576 struct spu_context *ctx = data;
1577 ctx->object_id = id;
1578}
1579
1580DEFINE_SIMPLE_ATTRIBUTE(spufs_object_id_ops, spufs_object_id_get,
1581 spufs_object_id_set, "0x%llx\n");
1582
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001583static u64 __spufs_lslr_get(void *data)
1584{
1585 struct spu_context *ctx = data;
1586 return ctx->csa.priv2.spu_lslr_RW;
1587}
1588
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01001589static u64 spufs_lslr_get(void *data)
1590{
1591 struct spu_context *ctx = data;
1592 u64 ret;
1593
1594 spu_acquire_saved(ctx);
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001595 ret = __spufs_lslr_get(data);
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01001596 spu_release(ctx);
1597
1598 return ret;
1599}
1600DEFINE_SIMPLE_ATTRIBUTE(spufs_lslr_ops, spufs_lslr_get, NULL, "0x%llx\n")
1601
1602static int spufs_info_open(struct inode *inode, struct file *file)
1603{
1604 struct spufs_inode_info *i = SPUFS_I(inode);
1605 struct spu_context *ctx = i->i_ctx;
1606 file->private_data = ctx;
1607 return 0;
1608}
1609
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001610static ssize_t __spufs_mbox_info_read(struct spu_context *ctx,
1611 char __user *buf, size_t len, loff_t *pos)
1612{
1613 u32 mbox_stat;
1614 u32 data;
1615
1616 mbox_stat = ctx->csa.prob.mb_stat_R;
1617 if (mbox_stat & 0x0000ff) {
1618 data = ctx->csa.prob.pu_mb_R;
1619 }
1620
1621 return simple_read_from_buffer(buf, len, pos, &data, sizeof data);
1622}
1623
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01001624static ssize_t spufs_mbox_info_read(struct file *file, char __user *buf,
1625 size_t len, loff_t *pos)
1626{
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001627 int ret;
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01001628 struct spu_context *ctx = file->private_data;
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01001629
1630 if (!access_ok(VERIFY_WRITE, buf, len))
1631 return -EFAULT;
1632
1633 spu_acquire_saved(ctx);
1634 spin_lock(&ctx->csa.register_lock);
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001635 ret = __spufs_mbox_info_read(ctx, buf, len, pos);
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01001636 spin_unlock(&ctx->csa.register_lock);
1637 spu_release(ctx);
1638
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001639 return ret;
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01001640}
1641
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -08001642static const struct file_operations spufs_mbox_info_fops = {
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01001643 .open = spufs_info_open,
1644 .read = spufs_mbox_info_read,
1645 .llseek = generic_file_llseek,
1646};
1647
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001648static ssize_t __spufs_ibox_info_read(struct spu_context *ctx,
1649 char __user *buf, size_t len, loff_t *pos)
1650{
1651 u32 ibox_stat;
1652 u32 data;
1653
1654 ibox_stat = ctx->csa.prob.mb_stat_R;
1655 if (ibox_stat & 0xff0000) {
1656 data = ctx->csa.priv2.puint_mb_R;
1657 }
1658
1659 return simple_read_from_buffer(buf, len, pos, &data, sizeof data);
1660}
1661
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01001662static ssize_t spufs_ibox_info_read(struct file *file, char __user *buf,
1663 size_t len, loff_t *pos)
1664{
1665 struct spu_context *ctx = file->private_data;
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001666 int ret;
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01001667
1668 if (!access_ok(VERIFY_WRITE, buf, len))
1669 return -EFAULT;
1670
1671 spu_acquire_saved(ctx);
1672 spin_lock(&ctx->csa.register_lock);
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001673 ret = __spufs_ibox_info_read(ctx, buf, len, pos);
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01001674 spin_unlock(&ctx->csa.register_lock);
1675 spu_release(ctx);
1676
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001677 return ret;
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01001678}
1679
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -08001680static const struct file_operations spufs_ibox_info_fops = {
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01001681 .open = spufs_info_open,
1682 .read = spufs_ibox_info_read,
1683 .llseek = generic_file_llseek,
1684};
1685
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001686static ssize_t __spufs_wbox_info_read(struct spu_context *ctx,
1687 char __user *buf, size_t len, loff_t *pos)
1688{
1689 int i, cnt;
1690 u32 data[4];
1691 u32 wbox_stat;
1692
1693 wbox_stat = ctx->csa.prob.mb_stat_R;
1694 cnt = 4 - ((wbox_stat & 0x00ff00) >> 8);
1695 for (i = 0; i < cnt; i++) {
1696 data[i] = ctx->csa.spu_mailbox_data[i];
1697 }
1698
1699 return simple_read_from_buffer(buf, len, pos, &data,
1700 cnt * sizeof(u32));
1701}
1702
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01001703static ssize_t spufs_wbox_info_read(struct file *file, char __user *buf,
1704 size_t len, loff_t *pos)
1705{
1706 struct spu_context *ctx = file->private_data;
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001707 int ret;
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01001708
1709 if (!access_ok(VERIFY_WRITE, buf, len))
1710 return -EFAULT;
1711
1712 spu_acquire_saved(ctx);
1713 spin_lock(&ctx->csa.register_lock);
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001714 ret = __spufs_wbox_info_read(ctx, buf, len, pos);
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01001715 spin_unlock(&ctx->csa.register_lock);
1716 spu_release(ctx);
1717
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001718 return ret;
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01001719}
1720
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -08001721static const struct file_operations spufs_wbox_info_fops = {
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01001722 .open = spufs_info_open,
1723 .read = spufs_wbox_info_read,
1724 .llseek = generic_file_llseek,
1725};
1726
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001727static ssize_t __spufs_dma_info_read(struct spu_context *ctx,
1728 char __user *buf, size_t len, loff_t *pos)
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01001729{
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01001730 struct spu_dma_info info;
1731 struct mfc_cq_sr *qp, *spuqp;
1732 int i;
1733
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01001734 info.dma_info_type = ctx->csa.priv2.spu_tag_status_query_RW;
1735 info.dma_info_mask = ctx->csa.lscsa->tag_mask.slot[0];
1736 info.dma_info_status = ctx->csa.spu_chnldata_RW[24];
1737 info.dma_info_stall_and_notify = ctx->csa.spu_chnldata_RW[25];
1738 info.dma_info_atomic_command_status = ctx->csa.spu_chnldata_RW[27];
1739 for (i = 0; i < 16; i++) {
1740 qp = &info.dma_info_command_data[i];
1741 spuqp = &ctx->csa.priv2.spuq[i];
1742
1743 qp->mfc_cq_data0_RW = spuqp->mfc_cq_data0_RW;
1744 qp->mfc_cq_data1_RW = spuqp->mfc_cq_data1_RW;
1745 qp->mfc_cq_data2_RW = spuqp->mfc_cq_data2_RW;
1746 qp->mfc_cq_data3_RW = spuqp->mfc_cq_data3_RW;
1747 }
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01001748
1749 return simple_read_from_buffer(buf, len, pos, &info,
1750 sizeof info);
1751}
1752
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001753static ssize_t spufs_dma_info_read(struct file *file, char __user *buf,
1754 size_t len, loff_t *pos)
1755{
1756 struct spu_context *ctx = file->private_data;
1757 int ret;
1758
1759 if (!access_ok(VERIFY_WRITE, buf, len))
1760 return -EFAULT;
1761
1762 spu_acquire_saved(ctx);
1763 spin_lock(&ctx->csa.register_lock);
1764 ret = __spufs_dma_info_read(ctx, buf, len, pos);
1765 spin_unlock(&ctx->csa.register_lock);
1766 spu_release(ctx);
1767
1768 return ret;
1769}
1770
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -08001771static const struct file_operations spufs_dma_info_fops = {
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01001772 .open = spufs_info_open,
1773 .read = spufs_dma_info_read,
1774};
1775
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001776static ssize_t __spufs_proxydma_info_read(struct spu_context *ctx,
1777 char __user *buf, size_t len, loff_t *pos)
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01001778{
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01001779 struct spu_proxydma_info info;
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01001780 struct mfc_cq_sr *qp, *puqp;
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001781 int ret = sizeof info;
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01001782 int i;
1783
1784 if (len < ret)
1785 return -EINVAL;
1786
1787 if (!access_ok(VERIFY_WRITE, buf, len))
1788 return -EFAULT;
1789
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01001790 info.proxydma_info_type = ctx->csa.prob.dma_querytype_RW;
1791 info.proxydma_info_mask = ctx->csa.prob.dma_querymask_RW;
1792 info.proxydma_info_status = ctx->csa.prob.dma_tagstatus_R;
1793 for (i = 0; i < 8; i++) {
1794 qp = &info.proxydma_info_command_data[i];
1795 puqp = &ctx->csa.priv2.puq[i];
1796
1797 qp->mfc_cq_data0_RW = puqp->mfc_cq_data0_RW;
1798 qp->mfc_cq_data1_RW = puqp->mfc_cq_data1_RW;
1799 qp->mfc_cq_data2_RW = puqp->mfc_cq_data2_RW;
1800 qp->mfc_cq_data3_RW = puqp->mfc_cq_data3_RW;
1801 }
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001802
1803 return simple_read_from_buffer(buf, len, pos, &info,
1804 sizeof info);
1805}
1806
1807static ssize_t spufs_proxydma_info_read(struct file *file, char __user *buf,
1808 size_t len, loff_t *pos)
1809{
1810 struct spu_context *ctx = file->private_data;
1811 int ret;
1812
1813 spu_acquire_saved(ctx);
1814 spin_lock(&ctx->csa.register_lock);
1815 ret = __spufs_proxydma_info_read(ctx, buf, len, pos);
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01001816 spin_unlock(&ctx->csa.register_lock);
1817 spu_release(ctx);
1818
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01001819 return ret;
1820}
1821
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -08001822static const struct file_operations spufs_proxydma_info_fops = {
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01001823 .open = spufs_info_open,
1824 .read = spufs_proxydma_info_read,
1825};
1826
Arnd Bergmann67207b92005-11-15 15:53:48 -05001827struct tree_descr spufs_dir_contents[] = {
1828 { "mem", &spufs_mem_fops, 0666, },
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001829 { "regs", &spufs_regs_fops, 0666, },
Arnd Bergmann67207b92005-11-15 15:53:48 -05001830 { "mbox", &spufs_mbox_fops, 0444, },
1831 { "ibox", &spufs_ibox_fops, 0444, },
1832 { "wbox", &spufs_wbox_fops, 0222, },
1833 { "mbox_stat", &spufs_mbox_stat_fops, 0444, },
1834 { "ibox_stat", &spufs_ibox_stat_fops, 0444, },
1835 { "wbox_stat", &spufs_wbox_stat_fops, 0444, },
1836 { "signal1", &spufs_signal1_fops, 0666, },
1837 { "signal2", &spufs_signal2_fops, 0666, },
1838 { "signal1_type", &spufs_signal1_type, 0666, },
1839 { "signal2_type", &spufs_signal2_type, 0666, },
Mark Nutter6df10a82006-03-23 00:00:12 +01001840 { "cntl", &spufs_cntl_fops, 0666, },
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001841 { "fpcr", &spufs_fpcr_fops, 0666, },
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01001842 { "lslr", &spufs_lslr_ops, 0444, },
1843 { "mfc", &spufs_mfc_fops, 0666, },
1844 { "mss", &spufs_mss_fops, 0666, },
1845 { "npc", &spufs_npc_ops, 0666, },
1846 { "srr0", &spufs_srr0_ops, 0666, },
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001847 { "decr", &spufs_decr_ops, 0666, },
1848 { "decr_status", &spufs_decr_status_ops, 0666, },
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001849 { "event_mask", &spufs_event_mask_ops, 0666, },
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01001850 { "event_status", &spufs_event_status_ops, 0444, },
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +02001851 { "psmap", &spufs_psmap_fops, 0666, },
Arnd Bergmann86767272006-10-04 17:26:21 +02001852 { "phys-id", &spufs_id_ops, 0666, },
1853 { "object-id", &spufs_object_id_ops, 0666, },
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01001854 { "mbox_info", &spufs_mbox_info_fops, 0444, },
1855 { "ibox_info", &spufs_ibox_info_fops, 0444, },
1856 { "wbox_info", &spufs_wbox_info_fops, 0444, },
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01001857 { "dma_info", &spufs_dma_info_fops, 0444, },
1858 { "proxydma_info", &spufs_proxydma_info_fops, 0444, },
Arnd Bergmann67207b92005-11-15 15:53:48 -05001859 {},
1860};
Mark Nutter5737edd2006-10-24 18:31:16 +02001861
1862struct tree_descr spufs_dir_nosched_contents[] = {
1863 { "mem", &spufs_mem_fops, 0666, },
1864 { "mbox", &spufs_mbox_fops, 0444, },
1865 { "ibox", &spufs_ibox_fops, 0444, },
1866 { "wbox", &spufs_wbox_fops, 0222, },
1867 { "mbox_stat", &spufs_mbox_stat_fops, 0444, },
1868 { "ibox_stat", &spufs_ibox_stat_fops, 0444, },
1869 { "wbox_stat", &spufs_wbox_stat_fops, 0444, },
1870 { "signal1", &spufs_signal1_fops, 0666, },
1871 { "signal2", &spufs_signal2_fops, 0666, },
1872 { "signal1_type", &spufs_signal1_type, 0666, },
1873 { "signal2_type", &spufs_signal2_type, 0666, },
1874 { "mss", &spufs_mss_fops, 0666, },
1875 { "mfc", &spufs_mfc_fops, 0666, },
1876 { "cntl", &spufs_cntl_fops, 0666, },
1877 { "npc", &spufs_npc_ops, 0666, },
1878 { "psmap", &spufs_psmap_fops, 0666, },
1879 { "phys-id", &spufs_id_ops, 0666, },
1880 { "object-id", &spufs_object_id_ops, 0666, },
1881 {},
1882};
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001883
1884struct spufs_coredump_reader spufs_coredump_read[] = {
1885 { "regs", __spufs_regs_read, NULL, 128 * 16 },
1886 { "fpcr", __spufs_fpcr_read, NULL, 16 },
1887 { "lslr", NULL, __spufs_lslr_get, 11 },
1888 { "decr", NULL, __spufs_decr_get, 11 },
1889 { "decr_status", NULL, __spufs_decr_status_get, 11 },
1890 { "mem", __spufs_mem_read, NULL, 256 * 1024, },
1891 { "signal1", __spufs_signal1_read, NULL, 4 },
1892 { "signal1_type", NULL, __spufs_signal1_type_get, 2 },
1893 { "signal2", __spufs_signal2_read, NULL, 4 },
1894 { "signal2_type", NULL, __spufs_signal2_type_get, 2 },
1895 { "event_mask", NULL, __spufs_event_mask_get, 8 },
1896 { "event_status", NULL, __spufs_event_status_get, 8 },
1897 { "mbox_info", __spufs_mbox_info_read, NULL, 4 },
1898 { "ibox_info", __spufs_ibox_info_read, NULL, 4 },
1899 { "wbox_info", __spufs_wbox_info_read, NULL, 16 },
1900 { "dma_info", __spufs_dma_info_read, NULL, 69 * 8 },
1901 { "proxydma_info", __spufs_proxydma_info_read, NULL, 35 * 8 },
1902 { "object-id", NULL, __spufs_object_id_get, 19 },
1903 { },
1904};
1905int spufs_coredump_num_notes = ARRAY_SIZE(spufs_coredump_read) - 1;
1906