blob: 985c86bb16d09b663b9ff1bcccb93bb76796dc09 [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>
Benjamin Herrenschmidtcbe709c2007-06-04 15:15:38 +100031#include <linux/seq_file.h>
Arnd Bergmann67207b92005-11-15 15:53:48 -050032
33#include <asm/io.h>
34#include <asm/semaphore.h>
35#include <asm/spu.h>
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +010036#include <asm/spu_info.h>
Arnd Bergmann67207b92005-11-15 15:53:48 -050037#include <asm/uaccess.h>
38
39#include "spufs.h"
40
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +020041#define SPUFS_MMAP_4K (PAGE_SIZE == 0x1000)
42
Benjamin Herrenschmidtcbe709c2007-06-04 15:15:38 +100043
Arnd Bergmann67207b92005-11-15 15:53:48 -050044static int
45spufs_mem_open(struct inode *inode, struct file *file)
46{
47 struct spufs_inode_info *i = SPUFS_I(inode);
Mark Nutter6df10a82006-03-23 00:00:12 +010048 struct spu_context *ctx = i->i_ctx;
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +020049
Christoph Hellwig47d3a5f2007-06-04 23:26:51 +100050 mutex_lock(&ctx->mapping_lock);
Mark Nutter6df10a82006-03-23 00:00:12 +010051 file->private_data = ctx;
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +020052 if (!i->i_openers++)
53 ctx->local_store = inode->i_mapping;
Christoph Hellwig47d3a5f2007-06-04 23:26:51 +100054 mutex_unlock(&ctx->mapping_lock);
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +020055 return 0;
56}
57
58static int
59spufs_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
Christoph Hellwig47d3a5f2007-06-04 23:26:51 +100064 mutex_lock(&ctx->mapping_lock);
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +020065 if (!--i->i_openers)
66 ctx->local_store = NULL;
Christoph Hellwig47d3a5f2007-06-04 23:26:51 +100067 mutex_unlock(&ctx->mapping_lock);
Arnd Bergmann67207b92005-11-15 15:53:48 -050068 return 0;
69}
70
71static ssize_t
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +010072__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
80static ssize_t
Arnd Bergmann67207b92005-11-15 15:53:48 -050081spufs_mem_read(struct file *file, char __user *buffer,
82 size_t size, loff_t *pos)
83{
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +010084 struct spu_context *ctx = file->private_data;
Arnd Bergmannaa0ed2b2007-03-10 00:05:35 +010085 ssize_t ret;
Arnd Bergmann67207b92005-11-15 15:53:48 -050086
Arnd Bergmann8b3d6662005-11-15 15:53:52 -050087 spu_acquire(ctx);
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +010088 ret = __spufs_mem_read(ctx, buffer, size, pos);
Arnd Bergmann8b3d6662005-11-15 15:53:52 -050089 spu_release(ctx);
Arnd Bergmann67207b92005-11-15 15:53:48 -050090 return ret;
91}
92
93static ssize_t
94spufs_mem_write(struct file *file, const char __user *buffer,
Arnd Bergmannaa0ed2b2007-03-10 00:05:35 +010095 size_t size, loff_t *ppos)
Arnd Bergmann67207b92005-11-15 15:53:48 -050096{
97 struct spu_context *ctx = file->private_data;
Arnd Bergmann8b3d6662005-11-15 15:53:52 -050098 char *local_store;
Arnd Bergmannaa0ed2b2007-03-10 00:05:35 +010099 loff_t pos = *ppos;
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500100 int ret;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500101
Arnd Bergmannaa0ed2b2007-03-10 00:05:35 +0100102 if (pos < 0)
103 return -EINVAL;
104 if (pos > LS_SIZE)
Arnd Bergmann67207b92005-11-15 15:53:48 -0500105 return -EFBIG;
Arnd Bergmannaa0ed2b2007-03-10 00:05:35 +0100106 if (size > LS_SIZE - pos)
107 size = LS_SIZE - pos;
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500108
109 spu_acquire(ctx);
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500110 local_store = ctx->ops->get_ls(ctx);
Arnd Bergmannaa0ed2b2007-03-10 00:05:35 +0100111 ret = copy_from_user(local_store + pos, buffer, size);
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500112 spu_release(ctx);
Arnd Bergmannaa0ed2b2007-03-10 00:05:35 +0100113
114 if (ret)
115 return -EFAULT;
116 *ppos = pos + size;
117 return size;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500118}
119
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100120static unsigned long spufs_mem_mmap_nopfn(struct vm_area_struct *vma,
121 unsigned long address)
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500122{
Benjamin Herrenschmidtf1fa74f2007-05-08 16:27:29 +1000123 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;
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100128
Benjamin Herrenschmidtf1fa74f2007-05-08 16:27:29 +1000129 /* Check what page size we are using */
130 psize = get_slice_psize(vma->vm_mm, address);
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500131
Benjamin Herrenschmidtf1fa74f2007-05-08 16:27:29 +1000132 /* 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 */
141
142 offset = (address - vma->vm_start) + (vma->vm_pgoff << PAGE_SHIFT);
Masato Noguchi128b8542007-02-13 21:54:30 +0100143 if (offset >= LS_SIZE)
144 return NOPFN_SIGBUS;
145
Benjamin Herrenschmidtf1fa74f2007-05-08 16:27:29 +1000146 pr_debug("spufs_mem_mmap_nopfn address=0x%lx -> 0x%lx, offset=0x%lx\n",
147 addr0, address, offset);
148
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500149 spu_acquire(ctx);
150
Arnd Bergmannac91cb82006-10-04 17:26:16 +0200151 if (ctx->state == SPU_STATE_SAVED) {
152 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
Arnd Bergmann932f535d2006-11-20 18:45:06 +0100153 & ~_PAGE_NO_CACHE);
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100154 pfn = vmalloc_to_pfn(ctx->csa.lscsa->ls + offset);
Arnd Bergmannac91cb82006-10-04 17:26:16 +0200155 } else {
156 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100157 | _PAGE_NO_CACHE);
158 pfn = (ctx->spu->local_store_phys + offset) >> PAGE_SHIFT;
Arnd Bergmannac91cb82006-10-04 17:26:16 +0200159 }
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100160 vm_insert_pfn(vma, address, pfn);
161
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500162 spu_release(ctx);
163
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100164 return NOPFN_REFAULT;
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500165}
166
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100167
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500168static struct vm_operations_struct spufs_mem_mmap_vmops = {
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100169 .nopfn = spufs_mem_mmap_nopfn,
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500170};
171
Benjamin Herrenschmidtf1fa74f2007-05-08 16:27:29 +1000172static int spufs_mem_mmap(struct file *file, struct vm_area_struct *vma)
Arnd Bergmann67207b92005-11-15 15:53:48 -0500173{
Benjamin Herrenschmidtf1fa74f2007-05-08 16:27:29 +1000174#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
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500190 if (!(vma->vm_flags & VM_SHARED))
191 return -EINVAL;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500192
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100193 vma->vm_flags |= VM_IO | VM_PFNMAP;
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500194 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
195 | _PAGE_NO_CACHE);
196
197 vma->vm_ops = &spufs_mem_mmap_vmops;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500198 return 0;
199}
200
Benjamin Herrenschmidtf1fa74f2007-05-08 16:27:29 +1000201#ifdef CONFIG_SPU_FS_64K_LS
Sebastian Siewior12388192007-09-19 14:38:12 +1000202static unsigned long spufs_get_unmapped_area(struct file *file,
203 unsigned long addr, unsigned long len, unsigned long pgoff,
204 unsigned long flags)
Benjamin Herrenschmidtf1fa74f2007-05-08 16:27:29 +1000205{
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
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -0800220static const struct file_operations spufs_mem_fops = {
Jeremy Kerr70225432007-06-29 10:58:00 +1000221 .open = spufs_mem_open,
222 .release = spufs_mem_release,
223 .read = spufs_mem_read,
224 .write = spufs_mem_write,
225 .llseek = generic_file_llseek,
226 .mmap = spufs_mem_mmap,
Benjamin Herrenschmidtf1fa74f2007-05-08 16:27:29 +1000227#ifdef CONFIG_SPU_FS_64K_LS
228 .get_unmapped_area = spufs_get_unmapped_area,
229#endif
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500230};
231
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100232static unsigned long spufs_ps_nopfn(struct vm_area_struct *vma,
Mark Nutter6df10a82006-03-23 00:00:12 +0100233 unsigned long address,
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100234 unsigned long ps_offs,
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +0200235 unsigned long ps_size)
Mark Nutter6df10a82006-03-23 00:00:12 +0100236{
Mark Nutter6df10a82006-03-23 00:00:12 +0100237 struct spu_context *ctx = vma->vm_file->private_data;
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100238 unsigned long area, offset = address - vma->vm_start;
Mark Nutter6df10a82006-03-23 00:00:12 +0100239 int ret;
240
241 offset += vma->vm_pgoff << PAGE_SHIFT;
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +0200242 if (offset >= ps_size)
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100243 return NOPFN_SIGBUS;
Mark Nutter6df10a82006-03-23 00:00:12 +0100244
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100245 /* error here usually means a signal.. we might want to test
246 * the error code more precisely though
247 */
Christoph Hellwig26bec672007-02-13 21:54:24 +0100248 ret = spu_acquire_runnable(ctx, 0);
Mark Nutter6df10a82006-03-23 00:00:12 +0100249 if (ret)
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100250 return NOPFN_REFAULT;
Mark Nutter6df10a82006-03-23 00:00:12 +0100251
252 area = ctx->spu->problem_phys + ps_offs;
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100253 vm_insert_pfn(vma, address, (area + offset) >> PAGE_SHIFT);
Mark Nutter6df10a82006-03-23 00:00:12 +0100254 spu_release(ctx);
255
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100256 return NOPFN_REFAULT;
Mark Nutter6df10a82006-03-23 00:00:12 +0100257}
258
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +0200259#if SPUFS_MMAP_4K
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100260static unsigned long spufs_cntl_mmap_nopfn(struct vm_area_struct *vma,
261 unsigned long address)
Mark Nutter6df10a82006-03-23 00:00:12 +0100262{
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100263 return spufs_ps_nopfn(vma, address, 0x4000, 0x1000);
Mark Nutter6df10a82006-03-23 00:00:12 +0100264}
265
266static struct vm_operations_struct spufs_cntl_mmap_vmops = {
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100267 .nopfn = spufs_cntl_mmap_nopfn,
Mark Nutter6df10a82006-03-23 00:00:12 +0100268};
269
270/*
271 * mmap support for problem state control area [0x4000 - 0x4fff].
Mark Nutter6df10a82006-03-23 00:00:12 +0100272 */
273static int spufs_cntl_mmap(struct file *file, struct vm_area_struct *vma)
274{
275 if (!(vma->vm_flags & VM_SHARED))
276 return -EINVAL;
277
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100278 vma->vm_flags |= VM_IO | VM_PFNMAP;
Mark Nutter6df10a82006-03-23 00:00:12 +0100279 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
Benjamin Herrenschmidt23cc7702006-06-23 20:57:47 +0200280 | _PAGE_NO_CACHE | _PAGE_GUARDED);
Mark Nutter6df10a82006-03-23 00:00:12 +0100281
282 vma->vm_ops = &spufs_cntl_mmap_vmops;
283 return 0;
284}
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +0200285#else /* SPUFS_MMAP_4K */
286#define spufs_cntl_mmap NULL
287#endif /* !SPUFS_MMAP_4K */
Mark Nutter6df10a82006-03-23 00:00:12 +0100288
Arnd Bergmanne1dbff22006-10-04 17:26:19 +0200289static u64 spufs_cntl_get(void *data)
290{
291 struct spu_context *ctx = data;
292 u64 val;
293
294 spu_acquire(ctx);
295 val = ctx->ops->status_read(ctx);
296 spu_release(ctx);
297
298 return val;
299}
300
301static void spufs_cntl_set(void *data, u64 val)
302{
303 struct spu_context *ctx = data;
304
305 spu_acquire(ctx);
306 ctx->ops->runcntl_write(ctx, val);
307 spu_release(ctx);
308}
309
Mark Nutter6df10a82006-03-23 00:00:12 +0100310static int spufs_cntl_open(struct inode *inode, struct file *file)
311{
312 struct spufs_inode_info *i = SPUFS_I(inode);
313 struct spu_context *ctx = i->i_ctx;
314
Christoph Hellwig47d3a5f2007-06-04 23:26:51 +1000315 mutex_lock(&ctx->mapping_lock);
Mark Nutter6df10a82006-03-23 00:00:12 +0100316 file->private_data = ctx;
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +0200317 if (!i->i_openers++)
318 ctx->cntl = inode->i_mapping;
Christoph Hellwig47d3a5f2007-06-04 23:26:51 +1000319 mutex_unlock(&ctx->mapping_lock);
Arnd Bergmanne1dbff22006-10-04 17:26:19 +0200320 return simple_attr_open(inode, file, spufs_cntl_get,
321 spufs_cntl_set, "0x%08lx");
Mark Nutter6df10a82006-03-23 00:00:12 +0100322}
323
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +0200324static int
325spufs_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
Christoph Hellwig47d3a5f2007-06-04 23:26:51 +1000332 mutex_lock(&ctx->mapping_lock);
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +0200333 if (!--i->i_openers)
334 ctx->cntl = NULL;
Christoph Hellwig47d3a5f2007-06-04 23:26:51 +1000335 mutex_unlock(&ctx->mapping_lock);
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +0200336 return 0;
337}
338
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -0800339static const struct file_operations spufs_cntl_fops = {
Mark Nutter6df10a82006-03-23 00:00:12 +0100340 .open = spufs_cntl_open,
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +0200341 .release = spufs_cntl_release,
Arnd Bergmanne1dbff22006-10-04 17:26:19 +0200342 .read = simple_attr_read,
343 .write = simple_attr_write,
Mark Nutter6df10a82006-03-23 00:00:12 +0100344 .mmap = spufs_cntl_mmap,
Mark Nutter6df10a82006-03-23 00:00:12 +0100345};
346
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500347static int
348spufs_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
355static ssize_t
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100356__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
364static ssize_t
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500365spufs_regs_read(struct file *file, char __user *buffer,
366 size_t size, loff_t *pos)
367{
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500368 int ret;
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100369 struct spu_context *ctx = file->private_data;
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500370
371 spu_acquire_saved(ctx);
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100372 ret = __spufs_regs_read(ctx, buffer, size, pos);
Christoph Hellwig27b1ea02007-07-20 21:39:34 +0200373 spu_release_saved(ctx);
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500374 return ret;
375}
376
377static ssize_t
378spufs_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
Christoph Hellwig27b1ea02007-07-20 21:39:34 +0200395 spu_release_saved(ctx);
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500396 return ret;
397}
398
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -0800399static const struct file_operations spufs_regs_fops = {
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500400 .open = spufs_regs_open,
401 .read = spufs_regs_read,
402 .write = spufs_regs_write,
403 .llseek = generic_file_llseek,
404};
405
406static ssize_t
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100407__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
415static ssize_t
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500416spufs_fpcr_read(struct file *file, char __user * buffer,
417 size_t size, loff_t * pos)
418{
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500419 int ret;
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100420 struct spu_context *ctx = file->private_data;
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500421
422 spu_acquire_saved(ctx);
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100423 ret = __spufs_fpcr_read(ctx, buffer, size, pos);
Christoph Hellwig27b1ea02007-07-20 21:39:34 +0200424 spu_release_saved(ctx);
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500425 return ret;
426}
427
428static ssize_t
429spufs_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
Christoph Hellwig27b1ea02007-07-20 21:39:34 +0200446 spu_release_saved(ctx);
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500447 return ret;
448}
449
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -0800450static const struct file_operations spufs_fpcr_fops = {
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500451 .open = spufs_regs_open,
452 .read = spufs_fpcr_read,
453 .write = spufs_fpcr_write,
454 .llseek = generic_file_llseek,
Arnd Bergmann67207b92005-11-15 15:53:48 -0500455};
456
457/* generic open function for all pipe-like files */
458static 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
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200466/*
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 */
Arnd Bergmann67207b92005-11-15 15:53:48 -0500474static ssize_t spufs_mbox_read(struct file *file, char __user *buf,
475 size_t len, loff_t *pos)
476{
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500477 struct spu_context *ctx = file->private_data;
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200478 u32 mbox_data, __user *udata;
479 ssize_t count;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500480
481 if (len < 4)
482 return -EINVAL;
483
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200484 if (!access_ok(VERIFY_WRITE, buf, len))
Arnd Bergmann67207b92005-11-15 15:53:48 -0500485 return -EFAULT;
486
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200487 udata = (void __user *)buf;
488
489 spu_acquire(ctx);
Arnd Bergmann274cef52006-10-24 18:01:42 +0200490 for (count = 0; (count + 4) <= len; count += 4, udata++) {
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200491 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 }
508 spu_release(ctx);
509
510 if (!count)
511 count = -EAGAIN;
512
513 return count;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500514}
515
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -0800516static const struct file_operations spufs_mbox_fops = {
Arnd Bergmann67207b92005-11-15 15:53:48 -0500517 .open = spufs_pipe_open,
518 .read = spufs_mbox_read,
519};
520
521static ssize_t spufs_mbox_stat_read(struct file *file, char __user *buf,
522 size_t len, loff_t *pos)
523{
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500524 struct spu_context *ctx = file->private_data;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500525 u32 mbox_stat;
526
527 if (len < 4)
528 return -EINVAL;
529
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500530 spu_acquire(ctx);
531
532 mbox_stat = ctx->ops->mbox_stat_read(ctx) & 0xff;
533
534 spu_release(ctx);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500535
536 if (copy_to_user(buf, &mbox_stat, sizeof mbox_stat))
537 return -EFAULT;
538
539 return 4;
540}
541
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -0800542static const struct file_operations spufs_mbox_stat_fops = {
Arnd Bergmann67207b92005-11-15 15:53:48 -0500543 .open = spufs_pipe_open,
544 .read = spufs_mbox_stat_read,
545};
546
547/* low-level ibox access function */
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500548size_t spu_ibox_read(struct spu_context *ctx, u32 *data)
Arnd Bergmann67207b92005-11-15 15:53:48 -0500549{
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500550 return ctx->ops->ibox_read(ctx, data);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500551}
Arnd Bergmann67207b92005-11-15 15:53:48 -0500552
553static int spufs_ibox_fasync(int fd, struct file *file, int on)
554{
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500555 struct spu_context *ctx = file->private_data;
556
557 return fasync_helper(fd, file, on, &ctx->ibox_fasync);
558}
559
560/* interrupt-level ibox callback function. */
561void spufs_ibox_callback(struct spu *spu)
562{
563 struct spu_context *ctx = spu->ctx;
564
565 wake_up_all(&ctx->ibox_wq);
566 kill_fasync(&ctx->ibox_fasync, SIGIO, POLLIN);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500567}
568
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200569/*
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 */
Arnd Bergmann67207b92005-11-15 15:53:48 -0500581static ssize_t spufs_ibox_read(struct file *file, char __user *buf,
582 size_t len, loff_t *pos)
583{
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500584 struct spu_context *ctx = file->private_data;
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200585 u32 ibox_data, __user *udata;
586 ssize_t count;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500587
588 if (len < 4)
589 return -EINVAL;
590
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200591 if (!access_ok(VERIFY_WRITE, buf, len))
592 return -EFAULT;
593
594 udata = (void __user *)buf;
595
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500596 spu_acquire(ctx);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500597
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200598 /* wait only for the first element */
599 count = 0;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500600 if (file->f_flags & O_NONBLOCK) {
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500601 if (!spu_ibox_read(ctx, &ibox_data))
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200602 count = -EAGAIN;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500603 } else {
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200604 count = spufs_wait(ctx->ibox_wq, spu_ibox_read(ctx, &ibox_data));
605 }
606 if (count)
607 goto out;
608
609 /* if we can't write at all, return -EFAULT */
610 count = __put_user(ibox_data, udata);
611 if (count)
612 goto out;
613
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;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500627 }
628
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200629out:
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500630 spu_release(ctx);
631
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200632 return count;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500633}
634
635static unsigned int spufs_ibox_poll(struct file *file, poll_table *wait)
636{
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500637 struct spu_context *ctx = file->private_data;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500638 unsigned int mask;
639
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500640 poll_wait(file, &ctx->ibox_wq, wait);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500641
Arnd Bergmann3a843d72005-12-05 22:52:27 -0500642 spu_acquire(ctx);
643 mask = ctx->ops->mbox_stat_poll(ctx, POLLIN | POLLRDNORM);
644 spu_release(ctx);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500645
646 return mask;
647}
648
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -0800649static const struct file_operations spufs_ibox_fops = {
Arnd Bergmann67207b92005-11-15 15:53:48 -0500650 .open = spufs_pipe_open,
651 .read = spufs_ibox_read,
652 .poll = spufs_ibox_poll,
653 .fasync = spufs_ibox_fasync,
654};
655
656static ssize_t spufs_ibox_stat_read(struct file *file, char __user *buf,
657 size_t len, loff_t *pos)
658{
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500659 struct spu_context *ctx = file->private_data;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500660 u32 ibox_stat;
661
662 if (len < 4)
663 return -EINVAL;
664
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500665 spu_acquire(ctx);
666 ibox_stat = (ctx->ops->mbox_stat_read(ctx) >> 16) & 0xff;
667 spu_release(ctx);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500668
669 if (copy_to_user(buf, &ibox_stat, sizeof ibox_stat))
670 return -EFAULT;
671
672 return 4;
673}
674
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -0800675static const struct file_operations spufs_ibox_stat_fops = {
Arnd Bergmann67207b92005-11-15 15:53:48 -0500676 .open = spufs_pipe_open,
677 .read = spufs_ibox_stat_read,
678};
679
680/* low-level mailbox write */
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500681size_t spu_wbox_write(struct spu_context *ctx, u32 data)
Arnd Bergmann67207b92005-11-15 15:53:48 -0500682{
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500683 return ctx->ops->wbox_write(ctx, data);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500684}
Arnd Bergmann67207b92005-11-15 15:53:48 -0500685
686static int spufs_wbox_fasync(int fd, struct file *file, int on)
687{
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500688 struct spu_context *ctx = file->private_data;
689 int ret;
690
691 ret = fasync_helper(fd, file, on, &ctx->wbox_fasync);
692
693 return ret;
694}
695
696/* interrupt-level wbox callback function. */
697void spufs_wbox_callback(struct spu *spu)
698{
699 struct spu_context *ctx = spu->ctx;
700
701 wake_up_all(&ctx->wbox_wq);
702 kill_fasync(&ctx->wbox_fasync, SIGIO, POLLOUT);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500703}
704
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200705/*
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 */
Arnd Bergmann67207b92005-11-15 15:53:48 -0500717static ssize_t spufs_wbox_write(struct file *file, const char __user *buf,
718 size_t len, loff_t *pos)
719{
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500720 struct spu_context *ctx = file->private_data;
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200721 u32 wbox_data, __user *udata;
722 ssize_t count;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500723
724 if (len < 4)
725 return -EINVAL;
726
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200727 udata = (void __user *)buf;
728 if (!access_ok(VERIFY_READ, buf, len))
729 return -EFAULT;
730
731 if (__get_user(wbox_data, udata))
Arnd Bergmann67207b92005-11-15 15:53:48 -0500732 return -EFAULT;
733
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500734 spu_acquire(ctx);
735
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200736 /*
737 * make sure we can at least write one element, by waiting
738 * in case of !O_NONBLOCK
739 */
740 count = 0;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500741 if (file->f_flags & O_NONBLOCK) {
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500742 if (!spu_wbox_write(ctx, wbox_data))
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200743 count = -EAGAIN;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500744 } else {
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200745 count = spufs_wait(ctx->wbox_wq, spu_wbox_write(ctx, wbox_data));
Arnd Bergmann67207b92005-11-15 15:53:48 -0500746 }
747
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200748 if (count)
749 goto out;
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500750
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200751 /* 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
763out:
764 spu_release(ctx);
765 return count;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500766}
767
768static unsigned int spufs_wbox_poll(struct file *file, poll_table *wait)
769{
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500770 struct spu_context *ctx = file->private_data;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500771 unsigned int mask;
772
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500773 poll_wait(file, &ctx->wbox_wq, wait);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500774
Arnd Bergmann3a843d72005-12-05 22:52:27 -0500775 spu_acquire(ctx);
776 mask = ctx->ops->mbox_stat_poll(ctx, POLLOUT | POLLWRNORM);
777 spu_release(ctx);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500778
779 return mask;
780}
781
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -0800782static const struct file_operations spufs_wbox_fops = {
Arnd Bergmann67207b92005-11-15 15:53:48 -0500783 .open = spufs_pipe_open,
784 .write = spufs_wbox_write,
785 .poll = spufs_wbox_poll,
786 .fasync = spufs_wbox_fasync,
787};
788
789static ssize_t spufs_wbox_stat_read(struct file *file, char __user *buf,
790 size_t len, loff_t *pos)
791{
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500792 struct spu_context *ctx = file->private_data;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500793 u32 wbox_stat;
794
795 if (len < 4)
796 return -EINVAL;
797
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500798 spu_acquire(ctx);
799 wbox_stat = (ctx->ops->mbox_stat_read(ctx) >> 8) & 0xff;
800 spu_release(ctx);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500801
802 if (copy_to_user(buf, &wbox_stat, sizeof wbox_stat))
803 return -EFAULT;
804
805 return 4;
806}
807
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -0800808static const struct file_operations spufs_wbox_stat_fops = {
Arnd Bergmann67207b92005-11-15 15:53:48 -0500809 .open = spufs_pipe_open,
810 .read = spufs_wbox_stat_read,
811};
812
Mark Nutter6df10a82006-03-23 00:00:12 +0100813static 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;
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +0200817
Christoph Hellwig47d3a5f2007-06-04 23:26:51 +1000818 mutex_lock(&ctx->mapping_lock);
Mark Nutter6df10a82006-03-23 00:00:12 +0100819 file->private_data = ctx;
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +0200820 if (!i->i_openers++)
821 ctx->signal1 = inode->i_mapping;
Christoph Hellwig47d3a5f2007-06-04 23:26:51 +1000822 mutex_unlock(&ctx->mapping_lock);
Mark Nutter6df10a82006-03-23 00:00:12 +0100823 return nonseekable_open(inode, file);
824}
825
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +0200826static int
827spufs_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
Christoph Hellwig47d3a5f2007-06-04 23:26:51 +1000832 mutex_lock(&ctx->mapping_lock);
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +0200833 if (!--i->i_openers)
834 ctx->signal1 = NULL;
Christoph Hellwig47d3a5f2007-06-04 23:26:51 +1000835 mutex_unlock(&ctx->mapping_lock);
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +0200836 return 0;
837}
838
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100839static ssize_t __spufs_signal1_read(struct spu_context *ctx, char __user *buf,
Arnd Bergmann67207b92005-11-15 15:53:48 -0500840 size_t len, loff_t *pos)
841{
Dwayne Grant McConnell17f88ce2006-11-20 18:45:01 +0100842 int ret = 0;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500843 u32 data;
844
Arnd Bergmann67207b92005-11-15 15:53:48 -0500845 if (len < 4)
846 return -EINVAL;
847
Dwayne Grant McConnell17f88ce2006-11-20 18:45:01 +0100848 if (ctx->csa.spu_chnlcnt_RW[3]) {
849 data = ctx->csa.spu_chnldata_RW[3];
850 ret = 4;
851 }
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500852
Dwayne Grant McConnell17f88ce2006-11-20 18:45:01 +0100853 if (!ret)
854 goto out;
855
Arnd Bergmann67207b92005-11-15 15:53:48 -0500856 if (copy_to_user(buf, &data, 4))
857 return -EFAULT;
858
Dwayne Grant McConnell17f88ce2006-11-20 18:45:01 +0100859out:
860 return ret;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500861}
862
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100863static 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);
Christoph Hellwig27b1ea02007-07-20 21:39:34 +0200871 spu_release_saved(ctx);
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100872
873 return ret;
874}
875
Arnd Bergmann67207b92005-11-15 15:53:48 -0500876static 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;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500880 u32 data;
881
882 ctx = file->private_data;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500883
884 if (len < 4)
885 return -EINVAL;
886
887 if (copy_from_user(&data, buf, 4))
888 return -EFAULT;
889
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500890 spu_acquire(ctx);
891 ctx->ops->signal1_write(ctx, data);
892 spu_release(ctx);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500893
894 return 4;
895}
896
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100897static unsigned long spufs_signal1_mmap_nopfn(struct vm_area_struct *vma,
898 unsigned long address)
Mark Nutter6df10a82006-03-23 00:00:12 +0100899{
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +0200900#if PAGE_SIZE == 0x1000
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100901 return spufs_ps_nopfn(vma, address, 0x14000, 0x1000);
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +0200902#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 */
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100906 return spufs_ps_nopfn(vma, address, 0x10000, 0x10000);
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +0200907#else
908#error unsupported page size
909#endif
Mark Nutter6df10a82006-03-23 00:00:12 +0100910}
911
912static struct vm_operations_struct spufs_signal1_mmap_vmops = {
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100913 .nopfn = spufs_signal1_mmap_nopfn,
Mark Nutter6df10a82006-03-23 00:00:12 +0100914};
915
916static int spufs_signal1_mmap(struct file *file, struct vm_area_struct *vma)
917{
918 if (!(vma->vm_flags & VM_SHARED))
919 return -EINVAL;
920
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100921 vma->vm_flags |= VM_IO | VM_PFNMAP;
Mark Nutter6df10a82006-03-23 00:00:12 +0100922 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
Benjamin Herrenschmidt23cc7702006-06-23 20:57:47 +0200923 | _PAGE_NO_CACHE | _PAGE_GUARDED);
Mark Nutter6df10a82006-03-23 00:00:12 +0100924
925 vma->vm_ops = &spufs_signal1_mmap_vmops;
926 return 0;
927}
Mark Nutter6df10a82006-03-23 00:00:12 +0100928
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -0800929static const struct file_operations spufs_signal1_fops = {
Mark Nutter6df10a82006-03-23 00:00:12 +0100930 .open = spufs_signal1_open,
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +0200931 .release = spufs_signal1_release,
Arnd Bergmann67207b92005-11-15 15:53:48 -0500932 .read = spufs_signal1_read,
933 .write = spufs_signal1_write,
Mark Nutter6df10a82006-03-23 00:00:12 +0100934 .mmap = spufs_signal1_mmap,
Arnd Bergmann67207b92005-11-15 15:53:48 -0500935};
936
Jeremy Kerrd054b362007-07-20 21:39:31 +0200937static const struct file_operations spufs_signal1_nosched_fops = {
938 .open = spufs_signal1_open,
939 .release = spufs_signal1_release,
940 .write = spufs_signal1_write,
941 .mmap = spufs_signal1_mmap,
942};
943
Mark Nutter6df10a82006-03-23 00:00:12 +0100944static int spufs_signal2_open(struct inode *inode, struct file *file)
945{
946 struct spufs_inode_info *i = SPUFS_I(inode);
947 struct spu_context *ctx = i->i_ctx;
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +0200948
Christoph Hellwig47d3a5f2007-06-04 23:26:51 +1000949 mutex_lock(&ctx->mapping_lock);
Mark Nutter6df10a82006-03-23 00:00:12 +0100950 file->private_data = ctx;
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +0200951 if (!i->i_openers++)
952 ctx->signal2 = inode->i_mapping;
Christoph Hellwig47d3a5f2007-06-04 23:26:51 +1000953 mutex_unlock(&ctx->mapping_lock);
Mark Nutter6df10a82006-03-23 00:00:12 +0100954 return nonseekable_open(inode, file);
955}
956
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +0200957static int
958spufs_signal2_release(struct inode *inode, struct file *file)
959{
960 struct spufs_inode_info *i = SPUFS_I(inode);
961 struct spu_context *ctx = i->i_ctx;
962
Christoph Hellwig47d3a5f2007-06-04 23:26:51 +1000963 mutex_lock(&ctx->mapping_lock);
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +0200964 if (!--i->i_openers)
965 ctx->signal2 = NULL;
Christoph Hellwig47d3a5f2007-06-04 23:26:51 +1000966 mutex_unlock(&ctx->mapping_lock);
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +0200967 return 0;
968}
969
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100970static ssize_t __spufs_signal2_read(struct spu_context *ctx, char __user *buf,
Arnd Bergmann67207b92005-11-15 15:53:48 -0500971 size_t len, loff_t *pos)
972{
Dwayne Grant McConnell17f88ce2006-11-20 18:45:01 +0100973 int ret = 0;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500974 u32 data;
975
Arnd Bergmann67207b92005-11-15 15:53:48 -0500976 if (len < 4)
977 return -EINVAL;
978
Dwayne Grant McConnell17f88ce2006-11-20 18:45:01 +0100979 if (ctx->csa.spu_chnlcnt_RW[4]) {
980 data = ctx->csa.spu_chnldata_RW[4];
981 ret = 4;
982 }
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500983
Dwayne Grant McConnell17f88ce2006-11-20 18:45:01 +0100984 if (!ret)
985 goto out;
986
Arnd Bergmann67207b92005-11-15 15:53:48 -0500987 if (copy_to_user(buf, &data, 4))
988 return -EFAULT;
989
Dwayne Grant McConnell17f88ce2006-11-20 18:45:01 +0100990out:
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100991 return ret;
992}
993
994static ssize_t spufs_signal2_read(struct file *file, char __user *buf,
995 size_t len, loff_t *pos)
996{
997 struct spu_context *ctx = file->private_data;
998 int ret;
999
1000 spu_acquire_saved(ctx);
1001 ret = __spufs_signal2_read(ctx, buf, len, pos);
Christoph Hellwig27b1ea02007-07-20 21:39:34 +02001002 spu_release_saved(ctx);
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001003
1004 return ret;
Arnd Bergmann67207b92005-11-15 15:53:48 -05001005}
1006
1007static ssize_t spufs_signal2_write(struct file *file, const char __user *buf,
1008 size_t len, loff_t *pos)
1009{
1010 struct spu_context *ctx;
Arnd Bergmann67207b92005-11-15 15:53:48 -05001011 u32 data;
1012
1013 ctx = file->private_data;
Arnd Bergmann67207b92005-11-15 15:53:48 -05001014
1015 if (len < 4)
1016 return -EINVAL;
1017
1018 if (copy_from_user(&data, buf, 4))
1019 return -EFAULT;
1020
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001021 spu_acquire(ctx);
1022 ctx->ops->signal2_write(ctx, data);
1023 spu_release(ctx);
Arnd Bergmann67207b92005-11-15 15:53:48 -05001024
1025 return 4;
1026}
1027
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +02001028#if SPUFS_MMAP_4K
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +11001029static unsigned long spufs_signal2_mmap_nopfn(struct vm_area_struct *vma,
1030 unsigned long address)
Mark Nutter6df10a82006-03-23 00:00:12 +01001031{
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +02001032#if PAGE_SIZE == 0x1000
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +11001033 return spufs_ps_nopfn(vma, address, 0x1c000, 0x1000);
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +02001034#elif PAGE_SIZE == 0x10000
1035 /* For 64k pages, both signal1 and signal2 can be used to mmap the whole
1036 * signal 1 and 2 area
1037 */
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +11001038 return spufs_ps_nopfn(vma, address, 0x10000, 0x10000);
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +02001039#else
1040#error unsupported page size
1041#endif
Mark Nutter6df10a82006-03-23 00:00:12 +01001042}
1043
1044static struct vm_operations_struct spufs_signal2_mmap_vmops = {
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +11001045 .nopfn = spufs_signal2_mmap_nopfn,
Mark Nutter6df10a82006-03-23 00:00:12 +01001046};
1047
1048static int spufs_signal2_mmap(struct file *file, struct vm_area_struct *vma)
1049{
1050 if (!(vma->vm_flags & VM_SHARED))
1051 return -EINVAL;
1052
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +11001053 vma->vm_flags |= VM_IO | VM_PFNMAP;
Mark Nutter6df10a82006-03-23 00:00:12 +01001054 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
Benjamin Herrenschmidt23cc7702006-06-23 20:57:47 +02001055 | _PAGE_NO_CACHE | _PAGE_GUARDED);
Mark Nutter6df10a82006-03-23 00:00:12 +01001056
1057 vma->vm_ops = &spufs_signal2_mmap_vmops;
1058 return 0;
1059}
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +02001060#else /* SPUFS_MMAP_4K */
1061#define spufs_signal2_mmap NULL
1062#endif /* !SPUFS_MMAP_4K */
Mark Nutter6df10a82006-03-23 00:00:12 +01001063
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -08001064static const struct file_operations spufs_signal2_fops = {
Mark Nutter6df10a82006-03-23 00:00:12 +01001065 .open = spufs_signal2_open,
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +02001066 .release = spufs_signal2_release,
Arnd Bergmann67207b92005-11-15 15:53:48 -05001067 .read = spufs_signal2_read,
1068 .write = spufs_signal2_write,
Mark Nutter6df10a82006-03-23 00:00:12 +01001069 .mmap = spufs_signal2_mmap,
Arnd Bergmann67207b92005-11-15 15:53:48 -05001070};
1071
Jeremy Kerrd054b362007-07-20 21:39:31 +02001072static const struct file_operations spufs_signal2_nosched_fops = {
1073 .open = spufs_signal2_open,
1074 .release = spufs_signal2_release,
1075 .write = spufs_signal2_write,
1076 .mmap = spufs_signal2_mmap,
1077};
1078
Arnd Bergmann67207b92005-11-15 15:53:48 -05001079static void spufs_signal1_type_set(void *data, u64 val)
1080{
1081 struct spu_context *ctx = data;
Arnd Bergmann67207b92005-11-15 15:53:48 -05001082
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001083 spu_acquire(ctx);
1084 ctx->ops->signal1_type_set(ctx, val);
1085 spu_release(ctx);
Arnd Bergmann67207b92005-11-15 15:53:48 -05001086}
1087
Michael Ellerman74de08b2007-09-19 14:38:12 +10001088static u64 __spufs_signal1_type_get(struct spu_context *ctx)
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001089{
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001090 return ctx->ops->signal1_type_get(ctx);
1091}
1092
Arnd Bergmann67207b92005-11-15 15:53:48 -05001093static u64 spufs_signal1_type_get(void *data)
1094{
1095 struct spu_context *ctx = data;
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001096 u64 ret;
1097
1098 spu_acquire(ctx);
Michael Ellerman74de08b2007-09-19 14:38:12 +10001099 ret = __spufs_signal1_type_get(ctx);
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001100 spu_release(ctx);
1101
1102 return ret;
Arnd Bergmann67207b92005-11-15 15:53:48 -05001103}
1104DEFINE_SIMPLE_ATTRIBUTE(spufs_signal1_type, spufs_signal1_type_get,
1105 spufs_signal1_type_set, "%llu");
1106
1107static void spufs_signal2_type_set(void *data, u64 val)
1108{
1109 struct spu_context *ctx = data;
Arnd Bergmann67207b92005-11-15 15:53:48 -05001110
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001111 spu_acquire(ctx);
1112 ctx->ops->signal2_type_set(ctx, val);
1113 spu_release(ctx);
Arnd Bergmann67207b92005-11-15 15:53:48 -05001114}
1115
Michael Ellerman74de08b2007-09-19 14:38:12 +10001116static u64 __spufs_signal2_type_get(struct spu_context *ctx)
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001117{
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001118 return ctx->ops->signal2_type_get(ctx);
1119}
1120
Arnd Bergmann67207b92005-11-15 15:53:48 -05001121static u64 spufs_signal2_type_get(void *data)
1122{
1123 struct spu_context *ctx = data;
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001124 u64 ret;
1125
1126 spu_acquire(ctx);
Michael Ellerman74de08b2007-09-19 14:38:12 +10001127 ret = __spufs_signal2_type_get(ctx);
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001128 spu_release(ctx);
1129
1130 return ret;
Arnd Bergmann67207b92005-11-15 15:53:48 -05001131}
1132DEFINE_SIMPLE_ATTRIBUTE(spufs_signal2_type, spufs_signal2_type_get,
1133 spufs_signal2_type_set, "%llu");
1134
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +02001135#if SPUFS_MMAP_4K
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +11001136static unsigned long spufs_mss_mmap_nopfn(struct vm_area_struct *vma,
1137 unsigned long address)
arnd@arndb.ded9379c42006-06-19 20:33:21 +02001138{
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +11001139 return spufs_ps_nopfn(vma, address, 0x0000, 0x1000);
arnd@arndb.ded9379c42006-06-19 20:33:21 +02001140}
1141
1142static struct vm_operations_struct spufs_mss_mmap_vmops = {
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +11001143 .nopfn = spufs_mss_mmap_nopfn,
arnd@arndb.ded9379c42006-06-19 20:33:21 +02001144};
1145
1146/*
1147 * mmap support for problem state MFC DMA area [0x0000 - 0x0fff].
arnd@arndb.ded9379c42006-06-19 20:33:21 +02001148 */
1149static int spufs_mss_mmap(struct file *file, struct vm_area_struct *vma)
1150{
1151 if (!(vma->vm_flags & VM_SHARED))
1152 return -EINVAL;
1153
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +11001154 vma->vm_flags |= VM_IO | VM_PFNMAP;
arnd@arndb.ded9379c42006-06-19 20:33:21 +02001155 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
Benjamin Herrenschmidt23cc7702006-06-23 20:57:47 +02001156 | _PAGE_NO_CACHE | _PAGE_GUARDED);
arnd@arndb.ded9379c42006-06-19 20:33:21 +02001157
1158 vma->vm_ops = &spufs_mss_mmap_vmops;
1159 return 0;
1160}
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +02001161#else /* SPUFS_MMAP_4K */
1162#define spufs_mss_mmap NULL
1163#endif /* !SPUFS_MMAP_4K */
arnd@arndb.ded9379c42006-06-19 20:33:21 +02001164
1165static int spufs_mss_open(struct inode *inode, struct file *file)
1166{
1167 struct spufs_inode_info *i = SPUFS_I(inode);
Benjamin Herrenschmidt17e0e272007-02-13 11:46:08 +11001168 struct spu_context *ctx = i->i_ctx;
arnd@arndb.ded9379c42006-06-19 20:33:21 +02001169
1170 file->private_data = i->i_ctx;
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +02001171
Christoph Hellwig47d3a5f2007-06-04 23:26:51 +10001172 mutex_lock(&ctx->mapping_lock);
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +02001173 if (!i->i_openers++)
1174 ctx->mss = inode->i_mapping;
Christoph Hellwig47d3a5f2007-06-04 23:26:51 +10001175 mutex_unlock(&ctx->mapping_lock);
arnd@arndb.ded9379c42006-06-19 20:33:21 +02001176 return nonseekable_open(inode, file);
1177}
1178
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +02001179static int
1180spufs_mss_release(struct inode *inode, struct file *file)
1181{
1182 struct spufs_inode_info *i = SPUFS_I(inode);
1183 struct spu_context *ctx = i->i_ctx;
1184
Christoph Hellwig47d3a5f2007-06-04 23:26:51 +10001185 mutex_lock(&ctx->mapping_lock);
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +02001186 if (!--i->i_openers)
1187 ctx->mss = NULL;
Christoph Hellwig47d3a5f2007-06-04 23:26:51 +10001188 mutex_unlock(&ctx->mapping_lock);
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +02001189 return 0;
1190}
1191
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -08001192static const struct file_operations spufs_mss_fops = {
arnd@arndb.ded9379c42006-06-19 20:33:21 +02001193 .open = spufs_mss_open,
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +02001194 .release = spufs_mss_release,
arnd@arndb.ded9379c42006-06-19 20:33:21 +02001195 .mmap = spufs_mss_mmap,
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +02001196};
1197
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +11001198static unsigned long spufs_psmap_mmap_nopfn(struct vm_area_struct *vma,
1199 unsigned long address)
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +02001200{
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +11001201 return spufs_ps_nopfn(vma, address, 0x0000, 0x20000);
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +02001202}
1203
1204static struct vm_operations_struct spufs_psmap_mmap_vmops = {
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +11001205 .nopfn = spufs_psmap_mmap_nopfn,
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +02001206};
1207
1208/*
1209 * mmap support for full problem state area [0x00000 - 0x1ffff].
1210 */
1211static int spufs_psmap_mmap(struct file *file, struct vm_area_struct *vma)
1212{
1213 if (!(vma->vm_flags & VM_SHARED))
1214 return -EINVAL;
1215
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +11001216 vma->vm_flags |= VM_IO | VM_PFNMAP;
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +02001217 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
1218 | _PAGE_NO_CACHE | _PAGE_GUARDED);
1219
1220 vma->vm_ops = &spufs_psmap_mmap_vmops;
1221 return 0;
1222}
1223
1224static int spufs_psmap_open(struct inode *inode, struct file *file)
1225{
1226 struct spufs_inode_info *i = SPUFS_I(inode);
Benjamin Herrenschmidt17e0e272007-02-13 11:46:08 +11001227 struct spu_context *ctx = i->i_ctx;
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +02001228
Christoph Hellwig47d3a5f2007-06-04 23:26:51 +10001229 mutex_lock(&ctx->mapping_lock);
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +02001230 file->private_data = i->i_ctx;
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +02001231 if (!i->i_openers++)
1232 ctx->psmap = inode->i_mapping;
Christoph Hellwig47d3a5f2007-06-04 23:26:51 +10001233 mutex_unlock(&ctx->mapping_lock);
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +02001234 return nonseekable_open(inode, file);
1235}
1236
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +02001237static int
1238spufs_psmap_release(struct inode *inode, struct file *file)
1239{
1240 struct spufs_inode_info *i = SPUFS_I(inode);
1241 struct spu_context *ctx = i->i_ctx;
1242
Christoph Hellwig47d3a5f2007-06-04 23:26:51 +10001243 mutex_lock(&ctx->mapping_lock);
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +02001244 if (!--i->i_openers)
1245 ctx->psmap = NULL;
Christoph Hellwig47d3a5f2007-06-04 23:26:51 +10001246 mutex_unlock(&ctx->mapping_lock);
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +02001247 return 0;
1248}
1249
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -08001250static const struct file_operations spufs_psmap_fops = {
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +02001251 .open = spufs_psmap_open,
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +02001252 .release = spufs_psmap_release,
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +02001253 .mmap = spufs_psmap_mmap,
arnd@arndb.ded9379c42006-06-19 20:33:21 +02001254};
1255
1256
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +02001257#if SPUFS_MMAP_4K
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +11001258static unsigned long spufs_mfc_mmap_nopfn(struct vm_area_struct *vma,
1259 unsigned long address)
Mark Nutter6df10a82006-03-23 00:00:12 +01001260{
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +11001261 return spufs_ps_nopfn(vma, address, 0x3000, 0x1000);
Mark Nutter6df10a82006-03-23 00:00:12 +01001262}
1263
1264static struct vm_operations_struct spufs_mfc_mmap_vmops = {
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +11001265 .nopfn = spufs_mfc_mmap_nopfn,
Mark Nutter6df10a82006-03-23 00:00:12 +01001266};
1267
1268/*
1269 * mmap support for problem state MFC DMA area [0x0000 - 0x0fff].
Mark Nutter6df10a82006-03-23 00:00:12 +01001270 */
1271static int spufs_mfc_mmap(struct file *file, struct vm_area_struct *vma)
1272{
1273 if (!(vma->vm_flags & VM_SHARED))
1274 return -EINVAL;
1275
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +11001276 vma->vm_flags |= VM_IO | VM_PFNMAP;
Mark Nutter6df10a82006-03-23 00:00:12 +01001277 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
Benjamin Herrenschmidt23cc7702006-06-23 20:57:47 +02001278 | _PAGE_NO_CACHE | _PAGE_GUARDED);
Mark Nutter6df10a82006-03-23 00:00:12 +01001279
1280 vma->vm_ops = &spufs_mfc_mmap_vmops;
1281 return 0;
1282}
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +02001283#else /* SPUFS_MMAP_4K */
1284#define spufs_mfc_mmap NULL
1285#endif /* !SPUFS_MMAP_4K */
Arnd Bergmanna33a7d72006-03-23 00:00:11 +01001286
1287static int spufs_mfc_open(struct inode *inode, struct file *file)
1288{
1289 struct spufs_inode_info *i = SPUFS_I(inode);
1290 struct spu_context *ctx = i->i_ctx;
1291
1292 /* we don't want to deal with DMA into other processes */
1293 if (ctx->owner != current->mm)
1294 return -EINVAL;
1295
1296 if (atomic_read(&inode->i_count) != 1)
1297 return -EBUSY;
1298
Christoph Hellwig47d3a5f2007-06-04 23:26:51 +10001299 mutex_lock(&ctx->mapping_lock);
Arnd Bergmanna33a7d72006-03-23 00:00:11 +01001300 file->private_data = ctx;
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +02001301 if (!i->i_openers++)
1302 ctx->mfc = inode->i_mapping;
Christoph Hellwig47d3a5f2007-06-04 23:26:51 +10001303 mutex_unlock(&ctx->mapping_lock);
Arnd Bergmanna33a7d72006-03-23 00:00:11 +01001304 return nonseekable_open(inode, file);
1305}
1306
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +02001307static int
1308spufs_mfc_release(struct inode *inode, struct file *file)
1309{
1310 struct spufs_inode_info *i = SPUFS_I(inode);
1311 struct spu_context *ctx = i->i_ctx;
1312
Christoph Hellwig47d3a5f2007-06-04 23:26:51 +10001313 mutex_lock(&ctx->mapping_lock);
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +02001314 if (!--i->i_openers)
1315 ctx->mfc = NULL;
Christoph Hellwig47d3a5f2007-06-04 23:26:51 +10001316 mutex_unlock(&ctx->mapping_lock);
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +02001317 return 0;
1318}
1319
Arnd Bergmanna33a7d72006-03-23 00:00:11 +01001320/* interrupt-level mfc callback function. */
1321void spufs_mfc_callback(struct spu *spu)
1322{
1323 struct spu_context *ctx = spu->ctx;
1324
1325 wake_up_all(&ctx->mfc_wq);
1326
1327 pr_debug("%s %s\n", __FUNCTION__, spu->name);
1328 if (ctx->mfc_fasync) {
1329 u32 free_elements, tagstatus;
1330 unsigned int mask;
1331
1332 /* no need for spu_acquire in interrupt context */
1333 free_elements = ctx->ops->get_mfc_free_elements(ctx);
1334 tagstatus = ctx->ops->read_mfc_tagstatus(ctx);
1335
1336 mask = 0;
1337 if (free_elements & 0xffff)
1338 mask |= POLLOUT;
1339 if (tagstatus & ctx->tagwait)
1340 mask |= POLLIN;
1341
1342 kill_fasync(&ctx->mfc_fasync, SIGIO, mask);
1343 }
1344}
1345
1346static int spufs_read_mfc_tagstatus(struct spu_context *ctx, u32 *status)
1347{
1348 /* See if there is one tag group is complete */
1349 /* FIXME we need locking around tagwait */
1350 *status = ctx->ops->read_mfc_tagstatus(ctx) & ctx->tagwait;
1351 ctx->tagwait &= ~*status;
1352 if (*status)
1353 return 1;
1354
1355 /* enable interrupt waiting for any tag group,
1356 may silently fail if interrupts are already enabled */
1357 ctx->ops->set_mfc_query(ctx, ctx->tagwait, 1);
1358 return 0;
1359}
1360
1361static ssize_t spufs_mfc_read(struct file *file, char __user *buffer,
1362 size_t size, loff_t *pos)
1363{
1364 struct spu_context *ctx = file->private_data;
1365 int ret = -EINVAL;
1366 u32 status;
1367
1368 if (size != 4)
1369 goto out;
1370
1371 spu_acquire(ctx);
1372 if (file->f_flags & O_NONBLOCK) {
1373 status = ctx->ops->read_mfc_tagstatus(ctx);
1374 if (!(status & ctx->tagwait))
1375 ret = -EAGAIN;
1376 else
1377 ctx->tagwait &= ~status;
1378 } else {
1379 ret = spufs_wait(ctx->mfc_wq,
1380 spufs_read_mfc_tagstatus(ctx, &status));
1381 }
1382 spu_release(ctx);
1383
1384 if (ret)
1385 goto out;
1386
1387 ret = 4;
1388 if (copy_to_user(buffer, &status, 4))
1389 ret = -EFAULT;
1390
1391out:
1392 return ret;
1393}
1394
1395static int spufs_check_valid_dma(struct mfc_dma_command *cmd)
1396{
1397 pr_debug("queueing DMA %x %lx %x %x %x\n", cmd->lsa,
1398 cmd->ea, cmd->size, cmd->tag, cmd->cmd);
1399
1400 switch (cmd->cmd) {
1401 case MFC_PUT_CMD:
1402 case MFC_PUTF_CMD:
1403 case MFC_PUTB_CMD:
1404 case MFC_GET_CMD:
1405 case MFC_GETF_CMD:
1406 case MFC_GETB_CMD:
1407 break;
1408 default:
1409 pr_debug("invalid DMA opcode %x\n", cmd->cmd);
1410 return -EIO;
1411 }
1412
1413 if ((cmd->lsa & 0xf) != (cmd->ea &0xf)) {
1414 pr_debug("invalid DMA alignment, ea %lx lsa %x\n",
1415 cmd->ea, cmd->lsa);
1416 return -EIO;
1417 }
1418
1419 switch (cmd->size & 0xf) {
1420 case 1:
1421 break;
1422 case 2:
1423 if (cmd->lsa & 1)
1424 goto error;
1425 break;
1426 case 4:
1427 if (cmd->lsa & 3)
1428 goto error;
1429 break;
1430 case 8:
1431 if (cmd->lsa & 7)
1432 goto error;
1433 break;
1434 case 0:
1435 if (cmd->lsa & 15)
1436 goto error;
1437 break;
1438 error:
1439 default:
1440 pr_debug("invalid DMA alignment %x for size %x\n",
1441 cmd->lsa & 0xf, cmd->size);
1442 return -EIO;
1443 }
1444
1445 if (cmd->size > 16 * 1024) {
1446 pr_debug("invalid DMA size %x\n", cmd->size);
1447 return -EIO;
1448 }
1449
1450 if (cmd->tag & 0xfff0) {
1451 /* we reserve the higher tag numbers for kernel use */
1452 pr_debug("invalid DMA tag\n");
1453 return -EIO;
1454 }
1455
1456 if (cmd->class) {
1457 /* not supported in this version */
1458 pr_debug("invalid DMA class\n");
1459 return -EIO;
1460 }
1461
1462 return 0;
1463}
1464
1465static int spu_send_mfc_command(struct spu_context *ctx,
1466 struct mfc_dma_command cmd,
1467 int *error)
1468{
1469 *error = ctx->ops->send_mfc_command(ctx, &cmd);
1470 if (*error == -EAGAIN) {
1471 /* wait for any tag group to complete
1472 so we have space for the new command */
1473 ctx->ops->set_mfc_query(ctx, ctx->tagwait, 1);
1474 /* try again, because the queue might be
1475 empty again */
1476 *error = ctx->ops->send_mfc_command(ctx, &cmd);
1477 if (*error == -EAGAIN)
1478 return 0;
1479 }
1480 return 1;
1481}
1482
1483static ssize_t spufs_mfc_write(struct file *file, const char __user *buffer,
1484 size_t size, loff_t *pos)
1485{
1486 struct spu_context *ctx = file->private_data;
1487 struct mfc_dma_command cmd;
1488 int ret = -EINVAL;
1489
1490 if (size != sizeof cmd)
1491 goto out;
1492
1493 ret = -EFAULT;
1494 if (copy_from_user(&cmd, buffer, sizeof cmd))
1495 goto out;
1496
1497 ret = spufs_check_valid_dma(&cmd);
1498 if (ret)
1499 goto out;
1500
Akinobu Mita577f8f12007-04-23 21:08:18 +02001501 ret = spu_acquire_runnable(ctx, 0);
1502 if (ret)
1503 goto out;
1504
Arnd Bergmanna33a7d72006-03-23 00:00:11 +01001505 if (file->f_flags & O_NONBLOCK) {
1506 ret = ctx->ops->send_mfc_command(ctx, &cmd);
1507 } else {
1508 int status;
1509 ret = spufs_wait(ctx->mfc_wq,
1510 spu_send_mfc_command(ctx, cmd, &status));
1511 if (status)
1512 ret = status;
1513 }
Arnd Bergmanna33a7d72006-03-23 00:00:11 +01001514
1515 if (ret)
Kazunori Asayama933b0e32007-06-29 10:58:08 +10001516 goto out_unlock;
Arnd Bergmanna33a7d72006-03-23 00:00:11 +01001517
1518 ctx->tagwait |= 1 << cmd.tag;
Masato Noguchi3692dc62006-11-20 18:45:07 +01001519 ret = size;
Arnd Bergmanna33a7d72006-03-23 00:00:11 +01001520
Kazunori Asayama933b0e32007-06-29 10:58:08 +10001521out_unlock:
1522 spu_release(ctx);
Arnd Bergmanna33a7d72006-03-23 00:00:11 +01001523out:
1524 return ret;
1525}
1526
1527static unsigned int spufs_mfc_poll(struct file *file,poll_table *wait)
1528{
1529 struct spu_context *ctx = file->private_data;
1530 u32 free_elements, tagstatus;
1531 unsigned int mask;
1532
Kazunori Asayama933b0e32007-06-29 10:58:08 +10001533 poll_wait(file, &ctx->mfc_wq, wait);
1534
Arnd Bergmanna33a7d72006-03-23 00:00:11 +01001535 spu_acquire(ctx);
1536 ctx->ops->set_mfc_query(ctx, ctx->tagwait, 2);
1537 free_elements = ctx->ops->get_mfc_free_elements(ctx);
1538 tagstatus = ctx->ops->read_mfc_tagstatus(ctx);
1539 spu_release(ctx);
1540
Arnd Bergmanna33a7d72006-03-23 00:00:11 +01001541 mask = 0;
1542 if (free_elements & 0xffff)
1543 mask |= POLLOUT | POLLWRNORM;
1544 if (tagstatus & ctx->tagwait)
1545 mask |= POLLIN | POLLRDNORM;
1546
1547 pr_debug("%s: free %d tagstatus %d tagwait %d\n", __FUNCTION__,
1548 free_elements, tagstatus, ctx->tagwait);
1549
1550 return mask;
1551}
1552
Al Viro73b6af82006-06-25 16:42:33 -07001553static int spufs_mfc_flush(struct file *file, fl_owner_t id)
Arnd Bergmanna33a7d72006-03-23 00:00:11 +01001554{
1555 struct spu_context *ctx = file->private_data;
1556 int ret;
1557
1558 spu_acquire(ctx);
1559#if 0
1560/* this currently hangs */
1561 ret = spufs_wait(ctx->mfc_wq,
1562 ctx->ops->set_mfc_query(ctx, ctx->tagwait, 2));
1563 if (ret)
1564 goto out;
1565 ret = spufs_wait(ctx->mfc_wq,
1566 ctx->ops->read_mfc_tagstatus(ctx) == ctx->tagwait);
1567out:
1568#else
1569 ret = 0;
1570#endif
1571 spu_release(ctx);
1572
1573 return ret;
1574}
1575
1576static int spufs_mfc_fsync(struct file *file, struct dentry *dentry,
1577 int datasync)
1578{
Al Viro73b6af82006-06-25 16:42:33 -07001579 return spufs_mfc_flush(file, NULL);
Arnd Bergmanna33a7d72006-03-23 00:00:11 +01001580}
1581
1582static int spufs_mfc_fasync(int fd, struct file *file, int on)
1583{
1584 struct spu_context *ctx = file->private_data;
1585
1586 return fasync_helper(fd, file, on, &ctx->mfc_fasync);
1587}
1588
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -08001589static const struct file_operations spufs_mfc_fops = {
Arnd Bergmanna33a7d72006-03-23 00:00:11 +01001590 .open = spufs_mfc_open,
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +02001591 .release = spufs_mfc_release,
Arnd Bergmanna33a7d72006-03-23 00:00:11 +01001592 .read = spufs_mfc_read,
1593 .write = spufs_mfc_write,
1594 .poll = spufs_mfc_poll,
1595 .flush = spufs_mfc_flush,
1596 .fsync = spufs_mfc_fsync,
1597 .fasync = spufs_mfc_fasync,
Mark Nutter6df10a82006-03-23 00:00:12 +01001598 .mmap = spufs_mfc_mmap,
Arnd Bergmanna33a7d72006-03-23 00:00:11 +01001599};
1600
Arnd Bergmann67207b92005-11-15 15:53:48 -05001601static void spufs_npc_set(void *data, u64 val)
1602{
1603 struct spu_context *ctx = data;
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001604 spu_acquire(ctx);
1605 ctx->ops->npc_write(ctx, val);
1606 spu_release(ctx);
Arnd Bergmann67207b92005-11-15 15:53:48 -05001607}
1608
Michael Ellerman78810ff2007-09-19 14:38:12 +10001609static u64 __spufs_npc_get(struct spu_context *ctx)
1610{
1611 return ctx->ops->npc_read(ctx);
1612}
1613
Arnd Bergmann67207b92005-11-15 15:53:48 -05001614static u64 spufs_npc_get(void *data)
1615{
1616 struct spu_context *ctx = data;
1617 u64 ret;
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001618 spu_acquire(ctx);
Michael Ellerman78810ff2007-09-19 14:38:12 +10001619 ret = __spufs_npc_get(ctx);
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001620 spu_release(ctx);
Arnd Bergmann67207b92005-11-15 15:53:48 -05001621 return ret;
1622}
Dwayne Grant McConnell9b5047e2006-11-20 18:44:57 +01001623DEFINE_SIMPLE_ATTRIBUTE(spufs_npc_ops, spufs_npc_get, spufs_npc_set,
1624 "0x%llx\n")
Arnd Bergmann67207b92005-11-15 15:53:48 -05001625
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001626static void spufs_decr_set(void *data, u64 val)
1627{
1628 struct spu_context *ctx = data;
1629 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1630 spu_acquire_saved(ctx);
1631 lscsa->decr.slot[0] = (u32) val;
Christoph Hellwig27b1ea02007-07-20 21:39:34 +02001632 spu_release_saved(ctx);
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001633}
1634
Michael Ellerman74de08b2007-09-19 14:38:12 +10001635static u64 __spufs_decr_get(struct spu_context *ctx)
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001636{
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001637 struct spu_lscsa *lscsa = ctx->csa.lscsa;
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001638 return lscsa->decr.slot[0];
1639}
1640
1641static u64 spufs_decr_get(void *data)
1642{
1643 struct spu_context *ctx = data;
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001644 u64 ret;
1645 spu_acquire_saved(ctx);
Michael Ellerman74de08b2007-09-19 14:38:12 +10001646 ret = __spufs_decr_get(ctx);
Christoph Hellwig27b1ea02007-07-20 21:39:34 +02001647 spu_release_saved(ctx);
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001648 return ret;
1649}
1650DEFINE_SIMPLE_ATTRIBUTE(spufs_decr_ops, spufs_decr_get, spufs_decr_set,
Dwayne Grant McConnell9b5047e2006-11-20 18:44:57 +01001651 "0x%llx\n")
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001652
1653static void spufs_decr_status_set(void *data, u64 val)
1654{
1655 struct spu_context *ctx = data;
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001656 spu_acquire_saved(ctx);
Masato Noguchid40a01d2007-07-20 21:39:38 +02001657 if (val)
1658 ctx->csa.priv2.mfc_control_RW |= MFC_CNTL_DECREMENTER_RUNNING;
1659 else
1660 ctx->csa.priv2.mfc_control_RW &= ~MFC_CNTL_DECREMENTER_RUNNING;
Christoph Hellwig27b1ea02007-07-20 21:39:34 +02001661 spu_release_saved(ctx);
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001662}
1663
Michael Ellerman74de08b2007-09-19 14:38:12 +10001664static u64 __spufs_decr_status_get(struct spu_context *ctx)
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001665{
Masato Noguchid40a01d2007-07-20 21:39:38 +02001666 if (ctx->csa.priv2.mfc_control_RW & MFC_CNTL_DECREMENTER_RUNNING)
1667 return SPU_DECR_STATUS_RUNNING;
1668 else
1669 return 0;
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001670}
1671
1672static u64 spufs_decr_status_get(void *data)
1673{
1674 struct spu_context *ctx = data;
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001675 u64 ret;
1676 spu_acquire_saved(ctx);
Michael Ellerman74de08b2007-09-19 14:38:12 +10001677 ret = __spufs_decr_status_get(ctx);
Christoph Hellwig27b1ea02007-07-20 21:39:34 +02001678 spu_release_saved(ctx);
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001679 return ret;
1680}
1681DEFINE_SIMPLE_ATTRIBUTE(spufs_decr_status_ops, spufs_decr_status_get,
Dwayne Grant McConnell9b5047e2006-11-20 18:44:57 +01001682 spufs_decr_status_set, "0x%llx\n")
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001683
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001684static void spufs_event_mask_set(void *data, u64 val)
1685{
1686 struct spu_context *ctx = data;
1687 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1688 spu_acquire_saved(ctx);
1689 lscsa->event_mask.slot[0] = (u32) val;
Christoph Hellwig27b1ea02007-07-20 21:39:34 +02001690 spu_release_saved(ctx);
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001691}
1692
Michael Ellerman74de08b2007-09-19 14:38:12 +10001693static u64 __spufs_event_mask_get(struct spu_context *ctx)
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001694{
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001695 struct spu_lscsa *lscsa = ctx->csa.lscsa;
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001696 return lscsa->event_mask.slot[0];
1697}
1698
1699static u64 spufs_event_mask_get(void *data)
1700{
1701 struct spu_context *ctx = data;
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001702 u64 ret;
1703 spu_acquire_saved(ctx);
Michael Ellerman74de08b2007-09-19 14:38:12 +10001704 ret = __spufs_event_mask_get(ctx);
Christoph Hellwig27b1ea02007-07-20 21:39:34 +02001705 spu_release_saved(ctx);
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001706 return ret;
1707}
1708DEFINE_SIMPLE_ATTRIBUTE(spufs_event_mask_ops, spufs_event_mask_get,
Dwayne Grant McConnell9b5047e2006-11-20 18:44:57 +01001709 spufs_event_mask_set, "0x%llx\n")
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001710
Michael Ellerman74de08b2007-09-19 14:38:12 +10001711static u64 __spufs_event_status_get(struct spu_context *ctx)
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01001712{
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01001713 struct spu_state *state = &ctx->csa;
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01001714 u64 stat;
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01001715 stat = state->spu_chnlcnt_RW[0];
1716 if (stat)
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001717 return state->spu_chnldata_RW[0];
1718 return 0;
1719}
1720
1721static u64 spufs_event_status_get(void *data)
1722{
1723 struct spu_context *ctx = data;
1724 u64 ret = 0;
1725
1726 spu_acquire_saved(ctx);
Michael Ellerman74de08b2007-09-19 14:38:12 +10001727 ret = __spufs_event_status_get(ctx);
Christoph Hellwig27b1ea02007-07-20 21:39:34 +02001728 spu_release_saved(ctx);
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01001729 return ret;
1730}
1731DEFINE_SIMPLE_ATTRIBUTE(spufs_event_status_ops, spufs_event_status_get,
1732 NULL, "0x%llx\n")
1733
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001734static void spufs_srr0_set(void *data, u64 val)
1735{
1736 struct spu_context *ctx = data;
1737 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1738 spu_acquire_saved(ctx);
1739 lscsa->srr0.slot[0] = (u32) val;
Christoph Hellwig27b1ea02007-07-20 21:39:34 +02001740 spu_release_saved(ctx);
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001741}
1742
1743static u64 spufs_srr0_get(void *data)
1744{
1745 struct spu_context *ctx = data;
1746 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1747 u64 ret;
1748 spu_acquire_saved(ctx);
1749 ret = lscsa->srr0.slot[0];
Christoph Hellwig27b1ea02007-07-20 21:39:34 +02001750 spu_release_saved(ctx);
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001751 return ret;
1752}
1753DEFINE_SIMPLE_ATTRIBUTE(spufs_srr0_ops, spufs_srr0_get, spufs_srr0_set,
Dwayne Grant McConnell9b5047e2006-11-20 18:44:57 +01001754 "0x%llx\n")
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001755
arnd@arndb.de7b1a7012006-06-19 20:33:24 +02001756static u64 spufs_id_get(void *data)
1757{
1758 struct spu_context *ctx = data;
1759 u64 num;
1760
1761 spu_acquire(ctx);
1762 if (ctx->state == SPU_STATE_RUNNABLE)
1763 num = ctx->spu->number;
1764 else
1765 num = (unsigned int)-1;
1766 spu_release(ctx);
1767
1768 return num;
1769}
Al Viroe45d6632006-09-23 01:37:41 +01001770DEFINE_SIMPLE_ATTRIBUTE(spufs_id_ops, spufs_id_get, NULL, "0x%llx\n")
arnd@arndb.de7b1a7012006-06-19 20:33:24 +02001771
Michael Ellerman74de08b2007-09-19 14:38:12 +10001772static u64 __spufs_object_id_get(struct spu_context *ctx)
Arnd Bergmann86767272006-10-04 17:26:21 +02001773{
Arnd Bergmann86767272006-10-04 17:26:21 +02001774 return ctx->object_id;
1775}
1776
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001777static u64 spufs_object_id_get(void *data)
1778{
1779 /* FIXME: Should there really be no locking here? */
Michael Ellerman74de08b2007-09-19 14:38:12 +10001780 return __spufs_object_id_get((struct spu_context *)data);
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001781}
1782
Arnd Bergmann86767272006-10-04 17:26:21 +02001783static void spufs_object_id_set(void *data, u64 id)
1784{
1785 struct spu_context *ctx = data;
1786 ctx->object_id = id;
1787}
1788
1789DEFINE_SIMPLE_ATTRIBUTE(spufs_object_id_ops, spufs_object_id_get,
1790 spufs_object_id_set, "0x%llx\n");
1791
Michael Ellerman74de08b2007-09-19 14:38:12 +10001792static u64 __spufs_lslr_get(struct spu_context *ctx)
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001793{
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001794 return ctx->csa.priv2.spu_lslr_RW;
1795}
1796
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01001797static u64 spufs_lslr_get(void *data)
1798{
1799 struct spu_context *ctx = data;
1800 u64 ret;
1801
1802 spu_acquire_saved(ctx);
Michael Ellerman74de08b2007-09-19 14:38:12 +10001803 ret = __spufs_lslr_get(ctx);
Christoph Hellwig27b1ea02007-07-20 21:39:34 +02001804 spu_release_saved(ctx);
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01001805
1806 return ret;
1807}
1808DEFINE_SIMPLE_ATTRIBUTE(spufs_lslr_ops, spufs_lslr_get, NULL, "0x%llx\n")
1809
1810static int spufs_info_open(struct inode *inode, struct file *file)
1811{
1812 struct spufs_inode_info *i = SPUFS_I(inode);
1813 struct spu_context *ctx = i->i_ctx;
1814 file->private_data = ctx;
1815 return 0;
1816}
1817
Benjamin Herrenschmidtcbe709c2007-06-04 15:15:38 +10001818static int spufs_caps_show(struct seq_file *s, void *private)
1819{
1820 struct spu_context *ctx = s->private;
1821
1822 if (!(ctx->flags & SPU_CREATE_NOSCHED))
1823 seq_puts(s, "sched\n");
1824 if (!(ctx->flags & SPU_CREATE_ISOLATE))
1825 seq_puts(s, "step\n");
1826 return 0;
1827}
1828
1829static int spufs_caps_open(struct inode *inode, struct file *file)
1830{
1831 return single_open(file, spufs_caps_show, SPUFS_I(inode)->i_ctx);
1832}
1833
1834static const struct file_operations spufs_caps_fops = {
1835 .open = spufs_caps_open,
1836 .read = seq_read,
1837 .llseek = seq_lseek,
1838 .release = single_release,
1839};
1840
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001841static ssize_t __spufs_mbox_info_read(struct spu_context *ctx,
1842 char __user *buf, size_t len, loff_t *pos)
1843{
1844 u32 mbox_stat;
1845 u32 data;
1846
1847 mbox_stat = ctx->csa.prob.mb_stat_R;
1848 if (mbox_stat & 0x0000ff) {
1849 data = ctx->csa.prob.pu_mb_R;
1850 }
1851
1852 return simple_read_from_buffer(buf, len, pos, &data, sizeof data);
1853}
1854
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01001855static ssize_t spufs_mbox_info_read(struct file *file, char __user *buf,
1856 size_t len, loff_t *pos)
1857{
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001858 int ret;
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01001859 struct spu_context *ctx = file->private_data;
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01001860
1861 if (!access_ok(VERIFY_WRITE, buf, len))
1862 return -EFAULT;
1863
1864 spu_acquire_saved(ctx);
1865 spin_lock(&ctx->csa.register_lock);
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001866 ret = __spufs_mbox_info_read(ctx, buf, len, pos);
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01001867 spin_unlock(&ctx->csa.register_lock);
Christoph Hellwig27b1ea02007-07-20 21:39:34 +02001868 spu_release_saved(ctx);
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01001869
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001870 return ret;
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01001871}
1872
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -08001873static const struct file_operations spufs_mbox_info_fops = {
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01001874 .open = spufs_info_open,
1875 .read = spufs_mbox_info_read,
1876 .llseek = generic_file_llseek,
1877};
1878
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001879static ssize_t __spufs_ibox_info_read(struct spu_context *ctx,
1880 char __user *buf, size_t len, loff_t *pos)
1881{
1882 u32 ibox_stat;
1883 u32 data;
1884
1885 ibox_stat = ctx->csa.prob.mb_stat_R;
1886 if (ibox_stat & 0xff0000) {
1887 data = ctx->csa.priv2.puint_mb_R;
1888 }
1889
1890 return simple_read_from_buffer(buf, len, pos, &data, sizeof data);
1891}
1892
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01001893static ssize_t spufs_ibox_info_read(struct file *file, char __user *buf,
1894 size_t len, loff_t *pos)
1895{
1896 struct spu_context *ctx = file->private_data;
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001897 int ret;
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01001898
1899 if (!access_ok(VERIFY_WRITE, buf, len))
1900 return -EFAULT;
1901
1902 spu_acquire_saved(ctx);
1903 spin_lock(&ctx->csa.register_lock);
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001904 ret = __spufs_ibox_info_read(ctx, buf, len, pos);
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01001905 spin_unlock(&ctx->csa.register_lock);
Christoph Hellwig27b1ea02007-07-20 21:39:34 +02001906 spu_release_saved(ctx);
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01001907
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001908 return ret;
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01001909}
1910
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -08001911static const struct file_operations spufs_ibox_info_fops = {
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01001912 .open = spufs_info_open,
1913 .read = spufs_ibox_info_read,
1914 .llseek = generic_file_llseek,
1915};
1916
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001917static ssize_t __spufs_wbox_info_read(struct spu_context *ctx,
1918 char __user *buf, size_t len, loff_t *pos)
1919{
1920 int i, cnt;
1921 u32 data[4];
1922 u32 wbox_stat;
1923
1924 wbox_stat = ctx->csa.prob.mb_stat_R;
1925 cnt = 4 - ((wbox_stat & 0x00ff00) >> 8);
1926 for (i = 0; i < cnt; i++) {
1927 data[i] = ctx->csa.spu_mailbox_data[i];
1928 }
1929
1930 return simple_read_from_buffer(buf, len, pos, &data,
1931 cnt * sizeof(u32));
1932}
1933
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01001934static ssize_t spufs_wbox_info_read(struct file *file, char __user *buf,
1935 size_t len, loff_t *pos)
1936{
1937 struct spu_context *ctx = file->private_data;
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001938 int ret;
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01001939
1940 if (!access_ok(VERIFY_WRITE, buf, len))
1941 return -EFAULT;
1942
1943 spu_acquire_saved(ctx);
1944 spin_lock(&ctx->csa.register_lock);
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001945 ret = __spufs_wbox_info_read(ctx, buf, len, pos);
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01001946 spin_unlock(&ctx->csa.register_lock);
Christoph Hellwig27b1ea02007-07-20 21:39:34 +02001947 spu_release_saved(ctx);
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01001948
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001949 return ret;
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01001950}
1951
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -08001952static const struct file_operations spufs_wbox_info_fops = {
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01001953 .open = spufs_info_open,
1954 .read = spufs_wbox_info_read,
1955 .llseek = generic_file_llseek,
1956};
1957
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001958static ssize_t __spufs_dma_info_read(struct spu_context *ctx,
1959 char __user *buf, size_t len, loff_t *pos)
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01001960{
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01001961 struct spu_dma_info info;
1962 struct mfc_cq_sr *qp, *spuqp;
1963 int i;
1964
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01001965 info.dma_info_type = ctx->csa.priv2.spu_tag_status_query_RW;
1966 info.dma_info_mask = ctx->csa.lscsa->tag_mask.slot[0];
1967 info.dma_info_status = ctx->csa.spu_chnldata_RW[24];
1968 info.dma_info_stall_and_notify = ctx->csa.spu_chnldata_RW[25];
1969 info.dma_info_atomic_command_status = ctx->csa.spu_chnldata_RW[27];
1970 for (i = 0; i < 16; i++) {
1971 qp = &info.dma_info_command_data[i];
1972 spuqp = &ctx->csa.priv2.spuq[i];
1973
1974 qp->mfc_cq_data0_RW = spuqp->mfc_cq_data0_RW;
1975 qp->mfc_cq_data1_RW = spuqp->mfc_cq_data1_RW;
1976 qp->mfc_cq_data2_RW = spuqp->mfc_cq_data2_RW;
1977 qp->mfc_cq_data3_RW = spuqp->mfc_cq_data3_RW;
1978 }
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01001979
1980 return simple_read_from_buffer(buf, len, pos, &info,
1981 sizeof info);
1982}
1983
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001984static ssize_t spufs_dma_info_read(struct file *file, char __user *buf,
1985 size_t len, loff_t *pos)
1986{
1987 struct spu_context *ctx = file->private_data;
1988 int ret;
1989
1990 if (!access_ok(VERIFY_WRITE, buf, len))
1991 return -EFAULT;
1992
1993 spu_acquire_saved(ctx);
1994 spin_lock(&ctx->csa.register_lock);
1995 ret = __spufs_dma_info_read(ctx, buf, len, pos);
1996 spin_unlock(&ctx->csa.register_lock);
Christoph Hellwig27b1ea02007-07-20 21:39:34 +02001997 spu_release_saved(ctx);
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001998
1999 return ret;
2000}
2001
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -08002002static const struct file_operations spufs_dma_info_fops = {
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01002003 .open = spufs_info_open,
2004 .read = spufs_dma_info_read,
2005};
2006
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01002007static ssize_t __spufs_proxydma_info_read(struct spu_context *ctx,
2008 char __user *buf, size_t len, loff_t *pos)
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01002009{
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01002010 struct spu_proxydma_info info;
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01002011 struct mfc_cq_sr *qp, *puqp;
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01002012 int ret = sizeof info;
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01002013 int i;
2014
2015 if (len < ret)
2016 return -EINVAL;
2017
2018 if (!access_ok(VERIFY_WRITE, buf, len))
2019 return -EFAULT;
2020
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01002021 info.proxydma_info_type = ctx->csa.prob.dma_querytype_RW;
2022 info.proxydma_info_mask = ctx->csa.prob.dma_querymask_RW;
2023 info.proxydma_info_status = ctx->csa.prob.dma_tagstatus_R;
2024 for (i = 0; i < 8; i++) {
2025 qp = &info.proxydma_info_command_data[i];
2026 puqp = &ctx->csa.priv2.puq[i];
2027
2028 qp->mfc_cq_data0_RW = puqp->mfc_cq_data0_RW;
2029 qp->mfc_cq_data1_RW = puqp->mfc_cq_data1_RW;
2030 qp->mfc_cq_data2_RW = puqp->mfc_cq_data2_RW;
2031 qp->mfc_cq_data3_RW = puqp->mfc_cq_data3_RW;
2032 }
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01002033
2034 return simple_read_from_buffer(buf, len, pos, &info,
2035 sizeof info);
2036}
2037
2038static ssize_t spufs_proxydma_info_read(struct file *file, char __user *buf,
2039 size_t len, loff_t *pos)
2040{
2041 struct spu_context *ctx = file->private_data;
2042 int ret;
2043
2044 spu_acquire_saved(ctx);
2045 spin_lock(&ctx->csa.register_lock);
2046 ret = __spufs_proxydma_info_read(ctx, buf, len, pos);
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01002047 spin_unlock(&ctx->csa.register_lock);
Christoph Hellwig27b1ea02007-07-20 21:39:34 +02002048 spu_release_saved(ctx);
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01002049
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01002050 return ret;
2051}
2052
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -08002053static const struct file_operations spufs_proxydma_info_fops = {
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01002054 .open = spufs_info_open,
2055 .read = spufs_proxydma_info_read,
2056};
2057
Christoph Hellwig476273a2007-06-29 10:58:01 +10002058static int spufs_show_tid(struct seq_file *s, void *private)
2059{
2060 struct spu_context *ctx = s->private;
2061
2062 seq_printf(s, "%d\n", ctx->tid);
2063 return 0;
2064}
2065
2066static int spufs_tid_open(struct inode *inode, struct file *file)
2067{
2068 return single_open(file, spufs_show_tid, SPUFS_I(inode)->i_ctx);
2069}
2070
2071static const struct file_operations spufs_tid_fops = {
2072 .open = spufs_tid_open,
2073 .read = seq_read,
2074 .llseek = seq_lseek,
2075 .release = single_release,
2076};
2077
Christoph Hellwige9f8a0b2007-06-29 10:58:03 +10002078static const char *ctx_state_names[] = {
2079 "user", "system", "iowait", "loaded"
2080};
2081
2082static unsigned long long spufs_acct_time(struct spu_context *ctx,
Andre Detsch27ec41d2007-07-20 21:39:33 +02002083 enum spu_utilization_state state)
Christoph Hellwige9f8a0b2007-06-29 10:58:03 +10002084{
Andre Detsch27ec41d2007-07-20 21:39:33 +02002085 struct timespec ts;
2086 unsigned long long time = ctx->stats.times[state];
Christoph Hellwige9f8a0b2007-06-29 10:58:03 +10002087
Andre Detsch27ec41d2007-07-20 21:39:33 +02002088 /*
2089 * In general, utilization statistics are updated by the controlling
2090 * thread as the spu context moves through various well defined
2091 * state transitions, but if the context is lazily loaded its
2092 * utilization statistics are not updated as the controlling thread
2093 * is not tightly coupled with the execution of the spu context. We
2094 * calculate and apply the time delta from the last recorded state
2095 * of the spu context.
2096 */
2097 if (ctx->spu && ctx->stats.util_state == state) {
2098 ktime_get_ts(&ts);
2099 time += timespec_to_ns(&ts) - ctx->stats.tstamp;
2100 }
Christoph Hellwige9f8a0b2007-06-29 10:58:03 +10002101
Andre Detsch27ec41d2007-07-20 21:39:33 +02002102 return time / NSEC_PER_MSEC;
Christoph Hellwige9f8a0b2007-06-29 10:58:03 +10002103}
2104
2105static unsigned long long spufs_slb_flts(struct spu_context *ctx)
2106{
2107 unsigned long long slb_flts = ctx->stats.slb_flt;
2108
2109 if (ctx->state == SPU_STATE_RUNNABLE) {
2110 slb_flts += (ctx->spu->stats.slb_flt -
2111 ctx->stats.slb_flt_base);
2112 }
2113
2114 return slb_flts;
2115}
2116
2117static unsigned long long spufs_class2_intrs(struct spu_context *ctx)
2118{
2119 unsigned long long class2_intrs = ctx->stats.class2_intr;
2120
2121 if (ctx->state == SPU_STATE_RUNNABLE) {
2122 class2_intrs += (ctx->spu->stats.class2_intr -
2123 ctx->stats.class2_intr_base);
2124 }
2125
2126 return class2_intrs;
2127}
2128
2129
2130static int spufs_show_stat(struct seq_file *s, void *private)
2131{
2132 struct spu_context *ctx = s->private;
2133
2134 spu_acquire(ctx);
2135 seq_printf(s, "%s %llu %llu %llu %llu "
2136 "%llu %llu %llu %llu %llu %llu %llu %llu\n",
Andre Detsch27ec41d2007-07-20 21:39:33 +02002137 ctx_state_names[ctx->stats.util_state],
2138 spufs_acct_time(ctx, SPU_UTIL_USER),
2139 spufs_acct_time(ctx, SPU_UTIL_SYSTEM),
2140 spufs_acct_time(ctx, SPU_UTIL_IOWAIT),
2141 spufs_acct_time(ctx, SPU_UTIL_IDLE_LOADED),
Christoph Hellwige9f8a0b2007-06-29 10:58:03 +10002142 ctx->stats.vol_ctx_switch,
2143 ctx->stats.invol_ctx_switch,
2144 spufs_slb_flts(ctx),
2145 ctx->stats.hash_flt,
2146 ctx->stats.min_flt,
2147 ctx->stats.maj_flt,
2148 spufs_class2_intrs(ctx),
2149 ctx->stats.libassist);
2150 spu_release(ctx);
2151 return 0;
2152}
2153
2154static int spufs_stat_open(struct inode *inode, struct file *file)
2155{
2156 return single_open(file, spufs_show_stat, SPUFS_I(inode)->i_ctx);
2157}
2158
2159static const struct file_operations spufs_stat_fops = {
2160 .open = spufs_stat_open,
2161 .read = seq_read,
2162 .llseek = seq_lseek,
2163 .release = single_release,
2164};
2165
2166
Arnd Bergmann67207b92005-11-15 15:53:48 -05002167struct tree_descr spufs_dir_contents[] = {
Benjamin Herrenschmidtcbe709c2007-06-04 15:15:38 +10002168 { "capabilities", &spufs_caps_fops, 0444, },
Arnd Bergmann67207b92005-11-15 15:53:48 -05002169 { "mem", &spufs_mem_fops, 0666, },
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05002170 { "regs", &spufs_regs_fops, 0666, },
Arnd Bergmann67207b92005-11-15 15:53:48 -05002171 { "mbox", &spufs_mbox_fops, 0444, },
2172 { "ibox", &spufs_ibox_fops, 0444, },
2173 { "wbox", &spufs_wbox_fops, 0222, },
2174 { "mbox_stat", &spufs_mbox_stat_fops, 0444, },
2175 { "ibox_stat", &spufs_ibox_stat_fops, 0444, },
2176 { "wbox_stat", &spufs_wbox_stat_fops, 0444, },
Jeremy Kerr8b6f50e2007-07-21 04:37:51 -07002177 { "signal1", &spufs_signal1_nosched_fops, 0222, },
2178 { "signal2", &spufs_signal2_nosched_fops, 0222, },
Arnd Bergmann67207b92005-11-15 15:53:48 -05002179 { "signal1_type", &spufs_signal1_type, 0666, },
2180 { "signal2_type", &spufs_signal2_type, 0666, },
Mark Nutter6df10a82006-03-23 00:00:12 +01002181 { "cntl", &spufs_cntl_fops, 0666, },
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05002182 { "fpcr", &spufs_fpcr_fops, 0666, },
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01002183 { "lslr", &spufs_lslr_ops, 0444, },
2184 { "mfc", &spufs_mfc_fops, 0666, },
2185 { "mss", &spufs_mss_fops, 0666, },
2186 { "npc", &spufs_npc_ops, 0666, },
2187 { "srr0", &spufs_srr0_ops, 0666, },
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05002188 { "decr", &spufs_decr_ops, 0666, },
2189 { "decr_status", &spufs_decr_status_ops, 0666, },
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05002190 { "event_mask", &spufs_event_mask_ops, 0666, },
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01002191 { "event_status", &spufs_event_status_ops, 0444, },
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +02002192 { "psmap", &spufs_psmap_fops, 0666, },
Arnd Bergmann86767272006-10-04 17:26:21 +02002193 { "phys-id", &spufs_id_ops, 0666, },
2194 { "object-id", &spufs_object_id_ops, 0666, },
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01002195 { "mbox_info", &spufs_mbox_info_fops, 0444, },
2196 { "ibox_info", &spufs_ibox_info_fops, 0444, },
2197 { "wbox_info", &spufs_wbox_info_fops, 0444, },
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01002198 { "dma_info", &spufs_dma_info_fops, 0444, },
2199 { "proxydma_info", &spufs_proxydma_info_fops, 0444, },
Christoph Hellwig476273a2007-06-29 10:58:01 +10002200 { "tid", &spufs_tid_fops, 0444, },
Christoph Hellwige9f8a0b2007-06-29 10:58:03 +10002201 { "stat", &spufs_stat_fops, 0444, },
Arnd Bergmann67207b92005-11-15 15:53:48 -05002202 {},
2203};
Mark Nutter5737edd2006-10-24 18:31:16 +02002204
2205struct tree_descr spufs_dir_nosched_contents[] = {
Benjamin Herrenschmidtcbe709c2007-06-04 15:15:38 +10002206 { "capabilities", &spufs_caps_fops, 0444, },
Mark Nutter5737edd2006-10-24 18:31:16 +02002207 { "mem", &spufs_mem_fops, 0666, },
2208 { "mbox", &spufs_mbox_fops, 0444, },
2209 { "ibox", &spufs_ibox_fops, 0444, },
2210 { "wbox", &spufs_wbox_fops, 0222, },
2211 { "mbox_stat", &spufs_mbox_stat_fops, 0444, },
2212 { "ibox_stat", &spufs_ibox_stat_fops, 0444, },
2213 { "wbox_stat", &spufs_wbox_stat_fops, 0444, },
Jeremy Kerrd054b362007-07-20 21:39:31 +02002214 { "signal1", &spufs_signal1_nosched_fops, 0222, },
2215 { "signal2", &spufs_signal2_nosched_fops, 0222, },
Mark Nutter5737edd2006-10-24 18:31:16 +02002216 { "signal1_type", &spufs_signal1_type, 0666, },
2217 { "signal2_type", &spufs_signal2_type, 0666, },
2218 { "mss", &spufs_mss_fops, 0666, },
2219 { "mfc", &spufs_mfc_fops, 0666, },
2220 { "cntl", &spufs_cntl_fops, 0666, },
2221 { "npc", &spufs_npc_ops, 0666, },
2222 { "psmap", &spufs_psmap_fops, 0666, },
2223 { "phys-id", &spufs_id_ops, 0666, },
2224 { "object-id", &spufs_object_id_ops, 0666, },
Christoph Hellwig476273a2007-06-29 10:58:01 +10002225 { "tid", &spufs_tid_fops, 0444, },
Christoph Hellwige9f8a0b2007-06-29 10:58:03 +10002226 { "stat", &spufs_stat_fops, 0444, },
Mark Nutter5737edd2006-10-24 18:31:16 +02002227 {},
2228};
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01002229
2230struct spufs_coredump_reader spufs_coredump_read[] = {
Michael Ellerman4fca9c42007-09-19 14:38:12 +10002231 { "regs", __spufs_regs_read, NULL, sizeof(struct spu_reg128[128])},
2232 { "fpcr", __spufs_fpcr_read, NULL, sizeof(struct spu_reg128) },
Michael Ellermand464fb42007-09-19 14:38:12 +10002233 { "lslr", NULL, __spufs_lslr_get, 19 },
2234 { "decr", NULL, __spufs_decr_get, 19 },
2235 { "decr_status", NULL, __spufs_decr_status_get, 19 },
Michael Ellerman4fca9c42007-09-19 14:38:12 +10002236 { "mem", __spufs_mem_read, NULL, LS_SIZE, },
2237 { "signal1", __spufs_signal1_read, NULL, sizeof(u32) },
Michael Ellermand464fb42007-09-19 14:38:12 +10002238 { "signal1_type", NULL, __spufs_signal1_type_get, 19 },
Michael Ellerman4fca9c42007-09-19 14:38:12 +10002239 { "signal2", __spufs_signal2_read, NULL, sizeof(u32) },
Michael Ellermand464fb42007-09-19 14:38:12 +10002240 { "signal2_type", NULL, __spufs_signal2_type_get, 19 },
2241 { "event_mask", NULL, __spufs_event_mask_get, 19 },
2242 { "event_status", NULL, __spufs_event_status_get, 19 },
Michael Ellerman4fca9c42007-09-19 14:38:12 +10002243 { "mbox_info", __spufs_mbox_info_read, NULL, sizeof(u32) },
2244 { "ibox_info", __spufs_ibox_info_read, NULL, sizeof(u32) },
2245 { "wbox_info", __spufs_wbox_info_read, NULL, 4 * sizeof(u32)},
2246 { "dma_info", __spufs_dma_info_read, NULL, sizeof(struct spu_dma_info)},
2247 { "proxydma_info", __spufs_proxydma_info_read,
2248 NULL, sizeof(struct spu_proxydma_info)},
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01002249 { "object-id", NULL, __spufs_object_id_get, 19 },
Michael Ellerman78810ff2007-09-19 14:38:12 +10002250 { "npc", NULL, __spufs_npc_get, 19 },
Michael Ellerman936d5bf2007-09-19 14:38:12 +10002251 { NULL },
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01002252};