blob: 78df905743b3d05d13e4b9b1c9acd629cdfe57d3 [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
240 offset += vma->vm_pgoff << PAGE_SHIFT;
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +0200241 if (offset >= ps_size)
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100242 return NOPFN_SIGBUS;
Mark Nutter6df10a82006-03-23 00:00:12 +0100243
Arnd Bergmann33bfd7a2007-12-20 16:39:59 +0900244 /*
245 * We have to wait for context to be loaded before we have
246 * pages to hand out to the user, but we don't want to wait
247 * with the mmap_sem held.
248 * It is possible to drop the mmap_sem here, but then we need
249 * to return NOPFN_REFAULT because the mappings may have
250 * hanged.
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100251 */
Arnd Bergmann33bfd7a2007-12-20 16:39:59 +0900252 spu_acquire(ctx);
253 if (ctx->state == SPU_STATE_SAVED) {
254 up_read(&current->mm->mmap_sem);
255 spufs_wait(ctx->run_wq, ctx->state == SPU_STATE_RUNNABLE);
256 down_read(&current->mm->mmap_sem);
257 goto out;
258 }
Mark Nutter6df10a82006-03-23 00:00:12 +0100259
260 area = ctx->spu->problem_phys + ps_offs;
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100261 vm_insert_pfn(vma, address, (area + offset) >> PAGE_SHIFT);
Arnd Bergmann33bfd7a2007-12-20 16:39:59 +0900262
263out:
Mark Nutter6df10a82006-03-23 00:00:12 +0100264 spu_release(ctx);
265
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100266 return NOPFN_REFAULT;
Mark Nutter6df10a82006-03-23 00:00:12 +0100267}
268
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +0200269#if SPUFS_MMAP_4K
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100270static unsigned long spufs_cntl_mmap_nopfn(struct vm_area_struct *vma,
271 unsigned long address)
Mark Nutter6df10a82006-03-23 00:00:12 +0100272{
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100273 return spufs_ps_nopfn(vma, address, 0x4000, 0x1000);
Mark Nutter6df10a82006-03-23 00:00:12 +0100274}
275
276static struct vm_operations_struct spufs_cntl_mmap_vmops = {
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100277 .nopfn = spufs_cntl_mmap_nopfn,
Mark Nutter6df10a82006-03-23 00:00:12 +0100278};
279
280/*
281 * mmap support for problem state control area [0x4000 - 0x4fff].
Mark Nutter6df10a82006-03-23 00:00:12 +0100282 */
283static int spufs_cntl_mmap(struct file *file, struct vm_area_struct *vma)
284{
285 if (!(vma->vm_flags & VM_SHARED))
286 return -EINVAL;
287
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100288 vma->vm_flags |= VM_IO | VM_PFNMAP;
Mark Nutter6df10a82006-03-23 00:00:12 +0100289 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
Benjamin Herrenschmidt23cc7702006-06-23 20:57:47 +0200290 | _PAGE_NO_CACHE | _PAGE_GUARDED);
Mark Nutter6df10a82006-03-23 00:00:12 +0100291
292 vma->vm_ops = &spufs_cntl_mmap_vmops;
293 return 0;
294}
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +0200295#else /* SPUFS_MMAP_4K */
296#define spufs_cntl_mmap NULL
297#endif /* !SPUFS_MMAP_4K */
Mark Nutter6df10a82006-03-23 00:00:12 +0100298
Arnd Bergmanne1dbff22006-10-04 17:26:19 +0200299static u64 spufs_cntl_get(void *data)
300{
301 struct spu_context *ctx = data;
302 u64 val;
303
304 spu_acquire(ctx);
305 val = ctx->ops->status_read(ctx);
306 spu_release(ctx);
307
308 return val;
309}
310
311static void spufs_cntl_set(void *data, u64 val)
312{
313 struct spu_context *ctx = data;
314
315 spu_acquire(ctx);
316 ctx->ops->runcntl_write(ctx, val);
317 spu_release(ctx);
318}
319
Mark Nutter6df10a82006-03-23 00:00:12 +0100320static int spufs_cntl_open(struct inode *inode, struct file *file)
321{
322 struct spufs_inode_info *i = SPUFS_I(inode);
323 struct spu_context *ctx = i->i_ctx;
324
Christoph Hellwig47d3a5f2007-06-04 23:26:51 +1000325 mutex_lock(&ctx->mapping_lock);
Mark Nutter6df10a82006-03-23 00:00:12 +0100326 file->private_data = ctx;
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +0200327 if (!i->i_openers++)
328 ctx->cntl = inode->i_mapping;
Christoph Hellwig47d3a5f2007-06-04 23:26:51 +1000329 mutex_unlock(&ctx->mapping_lock);
Arnd Bergmanne1dbff22006-10-04 17:26:19 +0200330 return simple_attr_open(inode, file, spufs_cntl_get,
331 spufs_cntl_set, "0x%08lx");
Mark Nutter6df10a82006-03-23 00:00:12 +0100332}
333
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +0200334static int
335spufs_cntl_release(struct inode *inode, struct file *file)
336{
337 struct spufs_inode_info *i = SPUFS_I(inode);
338 struct spu_context *ctx = i->i_ctx;
339
340 simple_attr_close(inode, file);
341
Christoph Hellwig47d3a5f2007-06-04 23:26:51 +1000342 mutex_lock(&ctx->mapping_lock);
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +0200343 if (!--i->i_openers)
344 ctx->cntl = NULL;
Christoph Hellwig47d3a5f2007-06-04 23:26:51 +1000345 mutex_unlock(&ctx->mapping_lock);
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +0200346 return 0;
347}
348
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -0800349static const struct file_operations spufs_cntl_fops = {
Mark Nutter6df10a82006-03-23 00:00:12 +0100350 .open = spufs_cntl_open,
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +0200351 .release = spufs_cntl_release,
Arnd Bergmanne1dbff22006-10-04 17:26:19 +0200352 .read = simple_attr_read,
353 .write = simple_attr_write,
Mark Nutter6df10a82006-03-23 00:00:12 +0100354 .mmap = spufs_cntl_mmap,
Mark Nutter6df10a82006-03-23 00:00:12 +0100355};
356
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500357static int
358spufs_regs_open(struct inode *inode, struct file *file)
359{
360 struct spufs_inode_info *i = SPUFS_I(inode);
361 file->private_data = i->i_ctx;
362 return 0;
363}
364
365static ssize_t
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100366__spufs_regs_read(struct spu_context *ctx, char __user *buffer,
367 size_t size, loff_t *pos)
368{
369 struct spu_lscsa *lscsa = ctx->csa.lscsa;
370 return simple_read_from_buffer(buffer, size, pos,
371 lscsa->gprs, sizeof lscsa->gprs);
372}
373
374static ssize_t
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500375spufs_regs_read(struct file *file, char __user *buffer,
376 size_t size, loff_t *pos)
377{
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500378 int ret;
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100379 struct spu_context *ctx = file->private_data;
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500380
381 spu_acquire_saved(ctx);
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100382 ret = __spufs_regs_read(ctx, buffer, size, pos);
Christoph Hellwig27b1ea02007-07-20 21:39:34 +0200383 spu_release_saved(ctx);
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500384 return ret;
385}
386
387static ssize_t
388spufs_regs_write(struct file *file, const char __user *buffer,
389 size_t size, loff_t *pos)
390{
391 struct spu_context *ctx = file->private_data;
392 struct spu_lscsa *lscsa = ctx->csa.lscsa;
393 int ret;
394
395 size = min_t(ssize_t, sizeof lscsa->gprs - *pos, size);
396 if (size <= 0)
397 return -EFBIG;
398 *pos += size;
399
400 spu_acquire_saved(ctx);
401
402 ret = copy_from_user(lscsa->gprs + *pos - size,
403 buffer, size) ? -EFAULT : size;
404
Christoph Hellwig27b1ea02007-07-20 21:39:34 +0200405 spu_release_saved(ctx);
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500406 return ret;
407}
408
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -0800409static const struct file_operations spufs_regs_fops = {
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500410 .open = spufs_regs_open,
411 .read = spufs_regs_read,
412 .write = spufs_regs_write,
413 .llseek = generic_file_llseek,
414};
415
416static ssize_t
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100417__spufs_fpcr_read(struct spu_context *ctx, char __user * buffer,
418 size_t size, loff_t * pos)
419{
420 struct spu_lscsa *lscsa = ctx->csa.lscsa;
421 return simple_read_from_buffer(buffer, size, pos,
422 &lscsa->fpcr, sizeof(lscsa->fpcr));
423}
424
425static ssize_t
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500426spufs_fpcr_read(struct file *file, char __user * buffer,
427 size_t size, loff_t * pos)
428{
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500429 int ret;
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100430 struct spu_context *ctx = file->private_data;
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500431
432 spu_acquire_saved(ctx);
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100433 ret = __spufs_fpcr_read(ctx, buffer, size, pos);
Christoph Hellwig27b1ea02007-07-20 21:39:34 +0200434 spu_release_saved(ctx);
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500435 return ret;
436}
437
438static ssize_t
439spufs_fpcr_write(struct file *file, const char __user * buffer,
440 size_t size, loff_t * pos)
441{
442 struct spu_context *ctx = file->private_data;
443 struct spu_lscsa *lscsa = ctx->csa.lscsa;
444 int ret;
445
446 size = min_t(ssize_t, sizeof(lscsa->fpcr) - *pos, size);
447 if (size <= 0)
448 return -EFBIG;
449 *pos += size;
450
451 spu_acquire_saved(ctx);
452
453 ret = copy_from_user((char *)&lscsa->fpcr + *pos - size,
454 buffer, size) ? -EFAULT : size;
455
Christoph Hellwig27b1ea02007-07-20 21:39:34 +0200456 spu_release_saved(ctx);
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500457 return ret;
458}
459
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -0800460static const struct file_operations spufs_fpcr_fops = {
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500461 .open = spufs_regs_open,
462 .read = spufs_fpcr_read,
463 .write = spufs_fpcr_write,
464 .llseek = generic_file_llseek,
Arnd Bergmann67207b92005-11-15 15:53:48 -0500465};
466
467/* generic open function for all pipe-like files */
468static int spufs_pipe_open(struct inode *inode, struct file *file)
469{
470 struct spufs_inode_info *i = SPUFS_I(inode);
471 file->private_data = i->i_ctx;
472
473 return nonseekable_open(inode, file);
474}
475
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200476/*
477 * Read as many bytes from the mailbox as possible, until
478 * one of the conditions becomes true:
479 *
480 * - no more data available in the mailbox
481 * - end of the user provided buffer
482 * - end of the mapped area
483 */
Arnd Bergmann67207b92005-11-15 15:53:48 -0500484static ssize_t spufs_mbox_read(struct file *file, char __user *buf,
485 size_t len, loff_t *pos)
486{
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500487 struct spu_context *ctx = file->private_data;
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200488 u32 mbox_data, __user *udata;
489 ssize_t count;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500490
491 if (len < 4)
492 return -EINVAL;
493
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200494 if (!access_ok(VERIFY_WRITE, buf, len))
Arnd Bergmann67207b92005-11-15 15:53:48 -0500495 return -EFAULT;
496
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200497 udata = (void __user *)buf;
498
499 spu_acquire(ctx);
Arnd Bergmann274cef52006-10-24 18:01:42 +0200500 for (count = 0; (count + 4) <= len; count += 4, udata++) {
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200501 int ret;
502 ret = ctx->ops->mbox_read(ctx, &mbox_data);
503 if (ret == 0)
504 break;
505
506 /*
507 * at the end of the mapped area, we can fault
508 * but still need to return the data we have
509 * read successfully so far.
510 */
511 ret = __put_user(mbox_data, udata);
512 if (ret) {
513 if (!count)
514 count = -EFAULT;
515 break;
516 }
517 }
518 spu_release(ctx);
519
520 if (!count)
521 count = -EAGAIN;
522
523 return count;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500524}
525
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -0800526static const struct file_operations spufs_mbox_fops = {
Arnd Bergmann67207b92005-11-15 15:53:48 -0500527 .open = spufs_pipe_open,
528 .read = spufs_mbox_read,
529};
530
531static ssize_t spufs_mbox_stat_read(struct file *file, char __user *buf,
532 size_t len, loff_t *pos)
533{
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500534 struct spu_context *ctx = file->private_data;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500535 u32 mbox_stat;
536
537 if (len < 4)
538 return -EINVAL;
539
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500540 spu_acquire(ctx);
541
542 mbox_stat = ctx->ops->mbox_stat_read(ctx) & 0xff;
543
544 spu_release(ctx);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500545
546 if (copy_to_user(buf, &mbox_stat, sizeof mbox_stat))
547 return -EFAULT;
548
549 return 4;
550}
551
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -0800552static const struct file_operations spufs_mbox_stat_fops = {
Arnd Bergmann67207b92005-11-15 15:53:48 -0500553 .open = spufs_pipe_open,
554 .read = spufs_mbox_stat_read,
555};
556
557/* low-level ibox access function */
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500558size_t spu_ibox_read(struct spu_context *ctx, u32 *data)
Arnd Bergmann67207b92005-11-15 15:53:48 -0500559{
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500560 return ctx->ops->ibox_read(ctx, data);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500561}
Arnd Bergmann67207b92005-11-15 15:53:48 -0500562
563static int spufs_ibox_fasync(int fd, struct file *file, int on)
564{
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500565 struct spu_context *ctx = file->private_data;
566
567 return fasync_helper(fd, file, on, &ctx->ibox_fasync);
568}
569
570/* interrupt-level ibox callback function. */
571void spufs_ibox_callback(struct spu *spu)
572{
573 struct spu_context *ctx = spu->ctx;
574
Luke Browninge65c2f62007-12-20 16:39:59 +0900575 if (!ctx)
576 return;
577
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500578 wake_up_all(&ctx->ibox_wq);
579 kill_fasync(&ctx->ibox_fasync, SIGIO, POLLIN);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500580}
581
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200582/*
583 * Read as many bytes from the interrupt mailbox as possible, until
584 * one of the conditions becomes true:
585 *
586 * - no more data available in the mailbox
587 * - end of the user provided buffer
588 * - end of the mapped area
589 *
590 * If the file is opened without O_NONBLOCK, we wait here until
591 * any data is available, but return when we have been able to
592 * read something.
593 */
Arnd Bergmann67207b92005-11-15 15:53:48 -0500594static ssize_t spufs_ibox_read(struct file *file, char __user *buf,
595 size_t len, loff_t *pos)
596{
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500597 struct spu_context *ctx = file->private_data;
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200598 u32 ibox_data, __user *udata;
599 ssize_t count;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500600
601 if (len < 4)
602 return -EINVAL;
603
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200604 if (!access_ok(VERIFY_WRITE, buf, len))
605 return -EFAULT;
606
607 udata = (void __user *)buf;
608
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500609 spu_acquire(ctx);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500610
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200611 /* wait only for the first element */
612 count = 0;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500613 if (file->f_flags & O_NONBLOCK) {
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500614 if (!spu_ibox_read(ctx, &ibox_data))
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200615 count = -EAGAIN;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500616 } else {
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200617 count = spufs_wait(ctx->ibox_wq, spu_ibox_read(ctx, &ibox_data));
618 }
619 if (count)
620 goto out;
621
622 /* if we can't write at all, return -EFAULT */
623 count = __put_user(ibox_data, udata);
624 if (count)
625 goto out;
626
627 for (count = 4, udata++; (count + 4) <= len; count += 4, udata++) {
628 int ret;
629 ret = ctx->ops->ibox_read(ctx, &ibox_data);
630 if (ret == 0)
631 break;
632 /*
633 * at the end of the mapped area, we can fault
634 * but still need to return the data we have
635 * read successfully so far.
636 */
637 ret = __put_user(ibox_data, udata);
638 if (ret)
639 break;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500640 }
641
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200642out:
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500643 spu_release(ctx);
644
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200645 return count;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500646}
647
648static unsigned int spufs_ibox_poll(struct file *file, poll_table *wait)
649{
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500650 struct spu_context *ctx = file->private_data;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500651 unsigned int mask;
652
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500653 poll_wait(file, &ctx->ibox_wq, wait);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500654
Arnd Bergmann3a843d72005-12-05 22:52:27 -0500655 spu_acquire(ctx);
656 mask = ctx->ops->mbox_stat_poll(ctx, POLLIN | POLLRDNORM);
657 spu_release(ctx);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500658
659 return mask;
660}
661
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -0800662static const struct file_operations spufs_ibox_fops = {
Arnd Bergmann67207b92005-11-15 15:53:48 -0500663 .open = spufs_pipe_open,
664 .read = spufs_ibox_read,
665 .poll = spufs_ibox_poll,
666 .fasync = spufs_ibox_fasync,
667};
668
669static ssize_t spufs_ibox_stat_read(struct file *file, char __user *buf,
670 size_t len, loff_t *pos)
671{
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500672 struct spu_context *ctx = file->private_data;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500673 u32 ibox_stat;
674
675 if (len < 4)
676 return -EINVAL;
677
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500678 spu_acquire(ctx);
679 ibox_stat = (ctx->ops->mbox_stat_read(ctx) >> 16) & 0xff;
680 spu_release(ctx);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500681
682 if (copy_to_user(buf, &ibox_stat, sizeof ibox_stat))
683 return -EFAULT;
684
685 return 4;
686}
687
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -0800688static const struct file_operations spufs_ibox_stat_fops = {
Arnd Bergmann67207b92005-11-15 15:53:48 -0500689 .open = spufs_pipe_open,
690 .read = spufs_ibox_stat_read,
691};
692
693/* low-level mailbox write */
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500694size_t spu_wbox_write(struct spu_context *ctx, u32 data)
Arnd Bergmann67207b92005-11-15 15:53:48 -0500695{
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500696 return ctx->ops->wbox_write(ctx, data);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500697}
Arnd Bergmann67207b92005-11-15 15:53:48 -0500698
699static int spufs_wbox_fasync(int fd, struct file *file, int on)
700{
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500701 struct spu_context *ctx = file->private_data;
702 int ret;
703
704 ret = fasync_helper(fd, file, on, &ctx->wbox_fasync);
705
706 return ret;
707}
708
709/* interrupt-level wbox callback function. */
710void spufs_wbox_callback(struct spu *spu)
711{
712 struct spu_context *ctx = spu->ctx;
713
Luke Browninge65c2f62007-12-20 16:39:59 +0900714 if (!ctx)
715 return;
716
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500717 wake_up_all(&ctx->wbox_wq);
718 kill_fasync(&ctx->wbox_fasync, SIGIO, POLLOUT);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500719}
720
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200721/*
722 * Write as many bytes to the interrupt mailbox as possible, until
723 * one of the conditions becomes true:
724 *
725 * - the mailbox is full
726 * - end of the user provided buffer
727 * - end of the mapped area
728 *
729 * If the file is opened without O_NONBLOCK, we wait here until
730 * space is availabyl, but return when we have been able to
731 * write something.
732 */
Arnd Bergmann67207b92005-11-15 15:53:48 -0500733static ssize_t spufs_wbox_write(struct file *file, const char __user *buf,
734 size_t len, loff_t *pos)
735{
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500736 struct spu_context *ctx = file->private_data;
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200737 u32 wbox_data, __user *udata;
738 ssize_t count;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500739
740 if (len < 4)
741 return -EINVAL;
742
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200743 udata = (void __user *)buf;
744 if (!access_ok(VERIFY_READ, buf, len))
745 return -EFAULT;
746
747 if (__get_user(wbox_data, udata))
Arnd Bergmann67207b92005-11-15 15:53:48 -0500748 return -EFAULT;
749
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500750 spu_acquire(ctx);
751
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200752 /*
753 * make sure we can at least write one element, by waiting
754 * in case of !O_NONBLOCK
755 */
756 count = 0;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500757 if (file->f_flags & O_NONBLOCK) {
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500758 if (!spu_wbox_write(ctx, wbox_data))
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200759 count = -EAGAIN;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500760 } else {
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200761 count = spufs_wait(ctx->wbox_wq, spu_wbox_write(ctx, wbox_data));
Arnd Bergmann67207b92005-11-15 15:53:48 -0500762 }
763
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200764 if (count)
765 goto out;
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500766
Jan Engelhardt96de0e22007-10-19 23:21:04 +0200767 /* write as much as possible */
Arnd Bergmanncdcc89b2006-10-04 17:26:17 +0200768 for (count = 4, udata++; (count + 4) <= len; count += 4, udata++) {
769 int ret;
770 ret = __get_user(wbox_data, udata);
771 if (ret)
772 break;
773
774 ret = spu_wbox_write(ctx, wbox_data);
775 if (ret == 0)
776 break;
777 }
778
779out:
780 spu_release(ctx);
781 return count;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500782}
783
784static unsigned int spufs_wbox_poll(struct file *file, poll_table *wait)
785{
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500786 struct spu_context *ctx = file->private_data;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500787 unsigned int mask;
788
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500789 poll_wait(file, &ctx->wbox_wq, wait);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500790
Arnd Bergmann3a843d72005-12-05 22:52:27 -0500791 spu_acquire(ctx);
792 mask = ctx->ops->mbox_stat_poll(ctx, POLLOUT | POLLWRNORM);
793 spu_release(ctx);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500794
795 return mask;
796}
797
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -0800798static const struct file_operations spufs_wbox_fops = {
Arnd Bergmann67207b92005-11-15 15:53:48 -0500799 .open = spufs_pipe_open,
800 .write = spufs_wbox_write,
801 .poll = spufs_wbox_poll,
802 .fasync = spufs_wbox_fasync,
803};
804
805static ssize_t spufs_wbox_stat_read(struct file *file, char __user *buf,
806 size_t len, loff_t *pos)
807{
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500808 struct spu_context *ctx = file->private_data;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500809 u32 wbox_stat;
810
811 if (len < 4)
812 return -EINVAL;
813
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500814 spu_acquire(ctx);
815 wbox_stat = (ctx->ops->mbox_stat_read(ctx) >> 8) & 0xff;
816 spu_release(ctx);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500817
818 if (copy_to_user(buf, &wbox_stat, sizeof wbox_stat))
819 return -EFAULT;
820
821 return 4;
822}
823
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -0800824static const struct file_operations spufs_wbox_stat_fops = {
Arnd Bergmann67207b92005-11-15 15:53:48 -0500825 .open = spufs_pipe_open,
826 .read = spufs_wbox_stat_read,
827};
828
Mark Nutter6df10a82006-03-23 00:00:12 +0100829static int spufs_signal1_open(struct inode *inode, struct file *file)
830{
831 struct spufs_inode_info *i = SPUFS_I(inode);
832 struct spu_context *ctx = i->i_ctx;
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +0200833
Christoph Hellwig47d3a5f2007-06-04 23:26:51 +1000834 mutex_lock(&ctx->mapping_lock);
Mark Nutter6df10a82006-03-23 00:00:12 +0100835 file->private_data = ctx;
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +0200836 if (!i->i_openers++)
837 ctx->signal1 = inode->i_mapping;
Christoph Hellwig47d3a5f2007-06-04 23:26:51 +1000838 mutex_unlock(&ctx->mapping_lock);
Mark Nutter6df10a82006-03-23 00:00:12 +0100839 return nonseekable_open(inode, file);
840}
841
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +0200842static int
843spufs_signal1_release(struct inode *inode, struct file *file)
844{
845 struct spufs_inode_info *i = SPUFS_I(inode);
846 struct spu_context *ctx = i->i_ctx;
847
Christoph Hellwig47d3a5f2007-06-04 23:26:51 +1000848 mutex_lock(&ctx->mapping_lock);
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +0200849 if (!--i->i_openers)
850 ctx->signal1 = NULL;
Christoph Hellwig47d3a5f2007-06-04 23:26:51 +1000851 mutex_unlock(&ctx->mapping_lock);
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +0200852 return 0;
853}
854
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100855static ssize_t __spufs_signal1_read(struct spu_context *ctx, char __user *buf,
Arnd Bergmann67207b92005-11-15 15:53:48 -0500856 size_t len, loff_t *pos)
857{
Dwayne Grant McConnell17f88ce2006-11-20 18:45:01 +0100858 int ret = 0;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500859 u32 data;
860
Arnd Bergmann67207b92005-11-15 15:53:48 -0500861 if (len < 4)
862 return -EINVAL;
863
Dwayne Grant McConnell17f88ce2006-11-20 18:45:01 +0100864 if (ctx->csa.spu_chnlcnt_RW[3]) {
865 data = ctx->csa.spu_chnldata_RW[3];
866 ret = 4;
867 }
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500868
Dwayne Grant McConnell17f88ce2006-11-20 18:45:01 +0100869 if (!ret)
870 goto out;
871
Arnd Bergmann67207b92005-11-15 15:53:48 -0500872 if (copy_to_user(buf, &data, 4))
873 return -EFAULT;
874
Dwayne Grant McConnell17f88ce2006-11-20 18:45:01 +0100875out:
876 return ret;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500877}
878
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100879static ssize_t spufs_signal1_read(struct file *file, char __user *buf,
880 size_t len, loff_t *pos)
881{
882 int ret;
883 struct spu_context *ctx = file->private_data;
884
885 spu_acquire_saved(ctx);
886 ret = __spufs_signal1_read(ctx, buf, len, pos);
Christoph Hellwig27b1ea02007-07-20 21:39:34 +0200887 spu_release_saved(ctx);
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100888
889 return ret;
890}
891
Arnd Bergmann67207b92005-11-15 15:53:48 -0500892static ssize_t spufs_signal1_write(struct file *file, const char __user *buf,
893 size_t len, loff_t *pos)
894{
895 struct spu_context *ctx;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500896 u32 data;
897
898 ctx = file->private_data;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500899
900 if (len < 4)
901 return -EINVAL;
902
903 if (copy_from_user(&data, buf, 4))
904 return -EFAULT;
905
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500906 spu_acquire(ctx);
907 ctx->ops->signal1_write(ctx, data);
908 spu_release(ctx);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500909
910 return 4;
911}
912
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100913static unsigned long spufs_signal1_mmap_nopfn(struct vm_area_struct *vma,
914 unsigned long address)
Mark Nutter6df10a82006-03-23 00:00:12 +0100915{
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +0200916#if PAGE_SIZE == 0x1000
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100917 return spufs_ps_nopfn(vma, address, 0x14000, 0x1000);
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +0200918#elif PAGE_SIZE == 0x10000
919 /* For 64k pages, both signal1 and signal2 can be used to mmap the whole
920 * signal 1 and 2 area
921 */
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100922 return spufs_ps_nopfn(vma, address, 0x10000, 0x10000);
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +0200923#else
924#error unsupported page size
925#endif
Mark Nutter6df10a82006-03-23 00:00:12 +0100926}
927
928static struct vm_operations_struct spufs_signal1_mmap_vmops = {
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100929 .nopfn = spufs_signal1_mmap_nopfn,
Mark Nutter6df10a82006-03-23 00:00:12 +0100930};
931
932static int spufs_signal1_mmap(struct file *file, struct vm_area_struct *vma)
933{
934 if (!(vma->vm_flags & VM_SHARED))
935 return -EINVAL;
936
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +1100937 vma->vm_flags |= VM_IO | VM_PFNMAP;
Mark Nutter6df10a82006-03-23 00:00:12 +0100938 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
Benjamin Herrenschmidt23cc7702006-06-23 20:57:47 +0200939 | _PAGE_NO_CACHE | _PAGE_GUARDED);
Mark Nutter6df10a82006-03-23 00:00:12 +0100940
941 vma->vm_ops = &spufs_signal1_mmap_vmops;
942 return 0;
943}
Mark Nutter6df10a82006-03-23 00:00:12 +0100944
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -0800945static const struct file_operations spufs_signal1_fops = {
Mark Nutter6df10a82006-03-23 00:00:12 +0100946 .open = spufs_signal1_open,
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +0200947 .release = spufs_signal1_release,
Arnd Bergmann67207b92005-11-15 15:53:48 -0500948 .read = spufs_signal1_read,
949 .write = spufs_signal1_write,
Mark Nutter6df10a82006-03-23 00:00:12 +0100950 .mmap = spufs_signal1_mmap,
Arnd Bergmann67207b92005-11-15 15:53:48 -0500951};
952
Jeremy Kerrd054b362007-07-20 21:39:31 +0200953static const struct file_operations spufs_signal1_nosched_fops = {
954 .open = spufs_signal1_open,
955 .release = spufs_signal1_release,
956 .write = spufs_signal1_write,
957 .mmap = spufs_signal1_mmap,
958};
959
Mark Nutter6df10a82006-03-23 00:00:12 +0100960static int spufs_signal2_open(struct inode *inode, struct file *file)
961{
962 struct spufs_inode_info *i = SPUFS_I(inode);
963 struct spu_context *ctx = i->i_ctx;
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +0200964
Christoph Hellwig47d3a5f2007-06-04 23:26:51 +1000965 mutex_lock(&ctx->mapping_lock);
Mark Nutter6df10a82006-03-23 00:00:12 +0100966 file->private_data = ctx;
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +0200967 if (!i->i_openers++)
968 ctx->signal2 = inode->i_mapping;
Christoph Hellwig47d3a5f2007-06-04 23:26:51 +1000969 mutex_unlock(&ctx->mapping_lock);
Mark Nutter6df10a82006-03-23 00:00:12 +0100970 return nonseekable_open(inode, file);
971}
972
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +0200973static int
974spufs_signal2_release(struct inode *inode, struct file *file)
975{
976 struct spufs_inode_info *i = SPUFS_I(inode);
977 struct spu_context *ctx = i->i_ctx;
978
Christoph Hellwig47d3a5f2007-06-04 23:26:51 +1000979 mutex_lock(&ctx->mapping_lock);
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +0200980 if (!--i->i_openers)
981 ctx->signal2 = NULL;
Christoph Hellwig47d3a5f2007-06-04 23:26:51 +1000982 mutex_unlock(&ctx->mapping_lock);
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +0200983 return 0;
984}
985
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +0100986static ssize_t __spufs_signal2_read(struct spu_context *ctx, char __user *buf,
Arnd Bergmann67207b92005-11-15 15:53:48 -0500987 size_t len, loff_t *pos)
988{
Dwayne Grant McConnell17f88ce2006-11-20 18:45:01 +0100989 int ret = 0;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500990 u32 data;
991
Arnd Bergmann67207b92005-11-15 15:53:48 -0500992 if (len < 4)
993 return -EINVAL;
994
Dwayne Grant McConnell17f88ce2006-11-20 18:45:01 +0100995 if (ctx->csa.spu_chnlcnt_RW[4]) {
996 data = ctx->csa.spu_chnldata_RW[4];
997 ret = 4;
998 }
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500999
Dwayne Grant McConnell17f88ce2006-11-20 18:45:01 +01001000 if (!ret)
1001 goto out;
1002
Arnd Bergmann67207b92005-11-15 15:53:48 -05001003 if (copy_to_user(buf, &data, 4))
1004 return -EFAULT;
1005
Dwayne Grant McConnell17f88ce2006-11-20 18:45:01 +01001006out:
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001007 return ret;
1008}
1009
1010static ssize_t spufs_signal2_read(struct file *file, char __user *buf,
1011 size_t len, loff_t *pos)
1012{
1013 struct spu_context *ctx = file->private_data;
1014 int ret;
1015
1016 spu_acquire_saved(ctx);
1017 ret = __spufs_signal2_read(ctx, buf, len, pos);
Christoph Hellwig27b1ea02007-07-20 21:39:34 +02001018 spu_release_saved(ctx);
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001019
1020 return ret;
Arnd Bergmann67207b92005-11-15 15:53:48 -05001021}
1022
1023static ssize_t spufs_signal2_write(struct file *file, const char __user *buf,
1024 size_t len, loff_t *pos)
1025{
1026 struct spu_context *ctx;
Arnd Bergmann67207b92005-11-15 15:53:48 -05001027 u32 data;
1028
1029 ctx = file->private_data;
Arnd Bergmann67207b92005-11-15 15:53:48 -05001030
1031 if (len < 4)
1032 return -EINVAL;
1033
1034 if (copy_from_user(&data, buf, 4))
1035 return -EFAULT;
1036
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001037 spu_acquire(ctx);
1038 ctx->ops->signal2_write(ctx, data);
1039 spu_release(ctx);
Arnd Bergmann67207b92005-11-15 15:53:48 -05001040
1041 return 4;
1042}
1043
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +02001044#if SPUFS_MMAP_4K
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +11001045static unsigned long spufs_signal2_mmap_nopfn(struct vm_area_struct *vma,
1046 unsigned long address)
Mark Nutter6df10a82006-03-23 00:00:12 +01001047{
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +02001048#if PAGE_SIZE == 0x1000
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +11001049 return spufs_ps_nopfn(vma, address, 0x1c000, 0x1000);
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +02001050#elif PAGE_SIZE == 0x10000
1051 /* For 64k pages, both signal1 and signal2 can be used to mmap the whole
1052 * signal 1 and 2 area
1053 */
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +11001054 return spufs_ps_nopfn(vma, address, 0x10000, 0x10000);
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +02001055#else
1056#error unsupported page size
1057#endif
Mark Nutter6df10a82006-03-23 00:00:12 +01001058}
1059
1060static struct vm_operations_struct spufs_signal2_mmap_vmops = {
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +11001061 .nopfn = spufs_signal2_mmap_nopfn,
Mark Nutter6df10a82006-03-23 00:00:12 +01001062};
1063
1064static int spufs_signal2_mmap(struct file *file, struct vm_area_struct *vma)
1065{
1066 if (!(vma->vm_flags & VM_SHARED))
1067 return -EINVAL;
1068
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +11001069 vma->vm_flags |= VM_IO | VM_PFNMAP;
Mark Nutter6df10a82006-03-23 00:00:12 +01001070 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
Benjamin Herrenschmidt23cc7702006-06-23 20:57:47 +02001071 | _PAGE_NO_CACHE | _PAGE_GUARDED);
Mark Nutter6df10a82006-03-23 00:00:12 +01001072
1073 vma->vm_ops = &spufs_signal2_mmap_vmops;
1074 return 0;
1075}
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +02001076#else /* SPUFS_MMAP_4K */
1077#define spufs_signal2_mmap NULL
1078#endif /* !SPUFS_MMAP_4K */
Mark Nutter6df10a82006-03-23 00:00:12 +01001079
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -08001080static const struct file_operations spufs_signal2_fops = {
Mark Nutter6df10a82006-03-23 00:00:12 +01001081 .open = spufs_signal2_open,
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +02001082 .release = spufs_signal2_release,
Arnd Bergmann67207b92005-11-15 15:53:48 -05001083 .read = spufs_signal2_read,
1084 .write = spufs_signal2_write,
Mark Nutter6df10a82006-03-23 00:00:12 +01001085 .mmap = spufs_signal2_mmap,
Arnd Bergmann67207b92005-11-15 15:53:48 -05001086};
1087
Jeremy Kerrd054b362007-07-20 21:39:31 +02001088static const struct file_operations spufs_signal2_nosched_fops = {
1089 .open = spufs_signal2_open,
1090 .release = spufs_signal2_release,
1091 .write = spufs_signal2_write,
1092 .mmap = spufs_signal2_mmap,
1093};
1094
Michael Ellerman104f0cc2007-09-19 14:38:12 +10001095/*
1096 * This is a wrapper around DEFINE_SIMPLE_ATTRIBUTE which does the
1097 * work of acquiring (or not) the SPU context before calling through
1098 * to the actual get routine. The set routine is called directly.
1099 */
1100#define SPU_ATTR_NOACQUIRE 0
1101#define SPU_ATTR_ACQUIRE 1
1102#define SPU_ATTR_ACQUIRE_SAVED 2
1103
1104#define DEFINE_SPUFS_ATTRIBUTE(__name, __get, __set, __fmt, __acquire) \
1105static u64 __##__get(void *data) \
1106{ \
1107 struct spu_context *ctx = data; \
1108 u64 ret; \
1109 \
1110 if (__acquire == SPU_ATTR_ACQUIRE) { \
1111 spu_acquire(ctx); \
1112 ret = __get(ctx); \
1113 spu_release(ctx); \
1114 } else if (__acquire == SPU_ATTR_ACQUIRE_SAVED) { \
1115 spu_acquire_saved(ctx); \
1116 ret = __get(ctx); \
1117 spu_release_saved(ctx); \
1118 } else \
1119 ret = __get(ctx); \
1120 \
1121 return ret; \
1122} \
1123DEFINE_SIMPLE_ATTRIBUTE(__name, __##__get, __set, __fmt);
1124
Arnd Bergmann67207b92005-11-15 15:53:48 -05001125static void spufs_signal1_type_set(void *data, u64 val)
1126{
1127 struct spu_context *ctx = data;
Arnd Bergmann67207b92005-11-15 15:53:48 -05001128
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001129 spu_acquire(ctx);
1130 ctx->ops->signal1_type_set(ctx, val);
1131 spu_release(ctx);
Arnd Bergmann67207b92005-11-15 15:53:48 -05001132}
1133
Michael Ellerman104f0cc2007-09-19 14:38:12 +10001134static u64 spufs_signal1_type_get(struct spu_context *ctx)
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001135{
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001136 return ctx->ops->signal1_type_get(ctx);
1137}
Michael Ellerman104f0cc2007-09-19 14:38:12 +10001138DEFINE_SPUFS_ATTRIBUTE(spufs_signal1_type, spufs_signal1_type_get,
1139 spufs_signal1_type_set, "%llu", SPU_ATTR_ACQUIRE);
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001140
Arnd Bergmann67207b92005-11-15 15:53:48 -05001141
1142static void spufs_signal2_type_set(void *data, u64 val)
1143{
1144 struct spu_context *ctx = data;
Arnd Bergmann67207b92005-11-15 15:53:48 -05001145
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001146 spu_acquire(ctx);
1147 ctx->ops->signal2_type_set(ctx, val);
1148 spu_release(ctx);
Arnd Bergmann67207b92005-11-15 15:53:48 -05001149}
1150
Michael Ellerman104f0cc2007-09-19 14:38:12 +10001151static u64 spufs_signal2_type_get(struct spu_context *ctx)
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001152{
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001153 return ctx->ops->signal2_type_get(ctx);
1154}
Michael Ellerman104f0cc2007-09-19 14:38:12 +10001155DEFINE_SPUFS_ATTRIBUTE(spufs_signal2_type, spufs_signal2_type_get,
1156 spufs_signal2_type_set, "%llu", SPU_ATTR_ACQUIRE);
Arnd Bergmann67207b92005-11-15 15:53:48 -05001157
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +02001158#if SPUFS_MMAP_4K
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +11001159static unsigned long spufs_mss_mmap_nopfn(struct vm_area_struct *vma,
1160 unsigned long address)
arnd@arndb.ded9379c42006-06-19 20:33:21 +02001161{
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +11001162 return spufs_ps_nopfn(vma, address, 0x0000, 0x1000);
arnd@arndb.ded9379c42006-06-19 20:33:21 +02001163}
1164
1165static struct vm_operations_struct spufs_mss_mmap_vmops = {
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +11001166 .nopfn = spufs_mss_mmap_nopfn,
arnd@arndb.ded9379c42006-06-19 20:33:21 +02001167};
1168
1169/*
1170 * mmap support for problem state MFC DMA area [0x0000 - 0x0fff].
arnd@arndb.ded9379c42006-06-19 20:33:21 +02001171 */
1172static int spufs_mss_mmap(struct file *file, struct vm_area_struct *vma)
1173{
1174 if (!(vma->vm_flags & VM_SHARED))
1175 return -EINVAL;
1176
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +11001177 vma->vm_flags |= VM_IO | VM_PFNMAP;
arnd@arndb.ded9379c42006-06-19 20:33:21 +02001178 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
Benjamin Herrenschmidt23cc7702006-06-23 20:57:47 +02001179 | _PAGE_NO_CACHE | _PAGE_GUARDED);
arnd@arndb.ded9379c42006-06-19 20:33:21 +02001180
1181 vma->vm_ops = &spufs_mss_mmap_vmops;
1182 return 0;
1183}
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +02001184#else /* SPUFS_MMAP_4K */
1185#define spufs_mss_mmap NULL
1186#endif /* !SPUFS_MMAP_4K */
arnd@arndb.ded9379c42006-06-19 20:33:21 +02001187
1188static int spufs_mss_open(struct inode *inode, struct file *file)
1189{
1190 struct spufs_inode_info *i = SPUFS_I(inode);
Benjamin Herrenschmidt17e0e272007-02-13 11:46:08 +11001191 struct spu_context *ctx = i->i_ctx;
arnd@arndb.ded9379c42006-06-19 20:33:21 +02001192
1193 file->private_data = i->i_ctx;
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +02001194
Christoph Hellwig47d3a5f2007-06-04 23:26:51 +10001195 mutex_lock(&ctx->mapping_lock);
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +02001196 if (!i->i_openers++)
1197 ctx->mss = inode->i_mapping;
Christoph Hellwig47d3a5f2007-06-04 23:26:51 +10001198 mutex_unlock(&ctx->mapping_lock);
arnd@arndb.ded9379c42006-06-19 20:33:21 +02001199 return nonseekable_open(inode, file);
1200}
1201
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +02001202static int
1203spufs_mss_release(struct inode *inode, struct file *file)
1204{
1205 struct spufs_inode_info *i = SPUFS_I(inode);
1206 struct spu_context *ctx = i->i_ctx;
1207
Christoph Hellwig47d3a5f2007-06-04 23:26:51 +10001208 mutex_lock(&ctx->mapping_lock);
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +02001209 if (!--i->i_openers)
1210 ctx->mss = NULL;
Christoph Hellwig47d3a5f2007-06-04 23:26:51 +10001211 mutex_unlock(&ctx->mapping_lock);
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +02001212 return 0;
1213}
1214
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -08001215static const struct file_operations spufs_mss_fops = {
arnd@arndb.ded9379c42006-06-19 20:33:21 +02001216 .open = spufs_mss_open,
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +02001217 .release = spufs_mss_release,
arnd@arndb.ded9379c42006-06-19 20:33:21 +02001218 .mmap = spufs_mss_mmap,
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +02001219};
1220
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +11001221static unsigned long spufs_psmap_mmap_nopfn(struct vm_area_struct *vma,
1222 unsigned long address)
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +02001223{
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +11001224 return spufs_ps_nopfn(vma, address, 0x0000, 0x20000);
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +02001225}
1226
1227static struct vm_operations_struct spufs_psmap_mmap_vmops = {
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +11001228 .nopfn = spufs_psmap_mmap_nopfn,
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +02001229};
1230
1231/*
1232 * mmap support for full problem state area [0x00000 - 0x1ffff].
1233 */
1234static int spufs_psmap_mmap(struct file *file, struct vm_area_struct *vma)
1235{
1236 if (!(vma->vm_flags & VM_SHARED))
1237 return -EINVAL;
1238
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +11001239 vma->vm_flags |= VM_IO | VM_PFNMAP;
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +02001240 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
1241 | _PAGE_NO_CACHE | _PAGE_GUARDED);
1242
1243 vma->vm_ops = &spufs_psmap_mmap_vmops;
1244 return 0;
1245}
1246
1247static int spufs_psmap_open(struct inode *inode, struct file *file)
1248{
1249 struct spufs_inode_info *i = SPUFS_I(inode);
Benjamin Herrenschmidt17e0e272007-02-13 11:46:08 +11001250 struct spu_context *ctx = i->i_ctx;
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +02001251
Christoph Hellwig47d3a5f2007-06-04 23:26:51 +10001252 mutex_lock(&ctx->mapping_lock);
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +02001253 file->private_data = i->i_ctx;
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +02001254 if (!i->i_openers++)
1255 ctx->psmap = inode->i_mapping;
Christoph Hellwig47d3a5f2007-06-04 23:26:51 +10001256 mutex_unlock(&ctx->mapping_lock);
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +02001257 return nonseekable_open(inode, file);
1258}
1259
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +02001260static int
1261spufs_psmap_release(struct inode *inode, struct file *file)
1262{
1263 struct spufs_inode_info *i = SPUFS_I(inode);
1264 struct spu_context *ctx = i->i_ctx;
1265
Christoph Hellwig47d3a5f2007-06-04 23:26:51 +10001266 mutex_lock(&ctx->mapping_lock);
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +02001267 if (!--i->i_openers)
1268 ctx->psmap = NULL;
Christoph Hellwig47d3a5f2007-06-04 23:26:51 +10001269 mutex_unlock(&ctx->mapping_lock);
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +02001270 return 0;
1271}
1272
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -08001273static const struct file_operations spufs_psmap_fops = {
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +02001274 .open = spufs_psmap_open,
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +02001275 .release = spufs_psmap_release,
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +02001276 .mmap = spufs_psmap_mmap,
arnd@arndb.ded9379c42006-06-19 20:33:21 +02001277};
1278
1279
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +02001280#if SPUFS_MMAP_4K
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +11001281static unsigned long spufs_mfc_mmap_nopfn(struct vm_area_struct *vma,
1282 unsigned long address)
Mark Nutter6df10a82006-03-23 00:00:12 +01001283{
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +11001284 return spufs_ps_nopfn(vma, address, 0x3000, 0x1000);
Mark Nutter6df10a82006-03-23 00:00:12 +01001285}
1286
1287static struct vm_operations_struct spufs_mfc_mmap_vmops = {
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +11001288 .nopfn = spufs_mfc_mmap_nopfn,
Mark Nutter6df10a82006-03-23 00:00:12 +01001289};
1290
1291/*
1292 * mmap support for problem state MFC DMA area [0x0000 - 0x0fff].
Mark Nutter6df10a82006-03-23 00:00:12 +01001293 */
1294static int spufs_mfc_mmap(struct file *file, struct vm_area_struct *vma)
1295{
1296 if (!(vma->vm_flags & VM_SHARED))
1297 return -EINVAL;
1298
Benjamin Herrenschmidt78bde532007-02-13 11:46:06 +11001299 vma->vm_flags |= VM_IO | VM_PFNMAP;
Mark Nutter6df10a82006-03-23 00:00:12 +01001300 vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
Benjamin Herrenschmidt23cc7702006-06-23 20:57:47 +02001301 | _PAGE_NO_CACHE | _PAGE_GUARDED);
Mark Nutter6df10a82006-03-23 00:00:12 +01001302
1303 vma->vm_ops = &spufs_mfc_mmap_vmops;
1304 return 0;
1305}
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +02001306#else /* SPUFS_MMAP_4K */
1307#define spufs_mfc_mmap NULL
1308#endif /* !SPUFS_MMAP_4K */
Arnd Bergmanna33a7d72006-03-23 00:00:11 +01001309
1310static int spufs_mfc_open(struct inode *inode, struct file *file)
1311{
1312 struct spufs_inode_info *i = SPUFS_I(inode);
1313 struct spu_context *ctx = i->i_ctx;
1314
1315 /* we don't want to deal with DMA into other processes */
1316 if (ctx->owner != current->mm)
1317 return -EINVAL;
1318
1319 if (atomic_read(&inode->i_count) != 1)
1320 return -EBUSY;
1321
Christoph Hellwig47d3a5f2007-06-04 23:26:51 +10001322 mutex_lock(&ctx->mapping_lock);
Arnd Bergmanna33a7d72006-03-23 00:00:11 +01001323 file->private_data = ctx;
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +02001324 if (!i->i_openers++)
1325 ctx->mfc = inode->i_mapping;
Christoph Hellwig47d3a5f2007-06-04 23:26:51 +10001326 mutex_unlock(&ctx->mapping_lock);
Arnd Bergmanna33a7d72006-03-23 00:00:11 +01001327 return nonseekable_open(inode, file);
1328}
1329
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +02001330static int
1331spufs_mfc_release(struct inode *inode, struct file *file)
1332{
1333 struct spufs_inode_info *i = SPUFS_I(inode);
1334 struct spu_context *ctx = i->i_ctx;
1335
Christoph Hellwig47d3a5f2007-06-04 23:26:51 +10001336 mutex_lock(&ctx->mapping_lock);
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +02001337 if (!--i->i_openers)
1338 ctx->mfc = NULL;
Christoph Hellwig47d3a5f2007-06-04 23:26:51 +10001339 mutex_unlock(&ctx->mapping_lock);
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +02001340 return 0;
1341}
1342
Arnd Bergmanna33a7d72006-03-23 00:00:11 +01001343/* interrupt-level mfc callback function. */
1344void spufs_mfc_callback(struct spu *spu)
1345{
1346 struct spu_context *ctx = spu->ctx;
1347
Luke Browninge65c2f62007-12-20 16:39:59 +09001348 if (!ctx)
1349 return;
1350
Arnd Bergmanna33a7d72006-03-23 00:00:11 +01001351 wake_up_all(&ctx->mfc_wq);
1352
1353 pr_debug("%s %s\n", __FUNCTION__, spu->name);
1354 if (ctx->mfc_fasync) {
1355 u32 free_elements, tagstatus;
1356 unsigned int mask;
1357
1358 /* no need for spu_acquire in interrupt context */
1359 free_elements = ctx->ops->get_mfc_free_elements(ctx);
1360 tagstatus = ctx->ops->read_mfc_tagstatus(ctx);
1361
1362 mask = 0;
1363 if (free_elements & 0xffff)
1364 mask |= POLLOUT;
1365 if (tagstatus & ctx->tagwait)
1366 mask |= POLLIN;
1367
1368 kill_fasync(&ctx->mfc_fasync, SIGIO, mask);
1369 }
1370}
1371
1372static int spufs_read_mfc_tagstatus(struct spu_context *ctx, u32 *status)
1373{
1374 /* See if there is one tag group is complete */
1375 /* FIXME we need locking around tagwait */
1376 *status = ctx->ops->read_mfc_tagstatus(ctx) & ctx->tagwait;
1377 ctx->tagwait &= ~*status;
1378 if (*status)
1379 return 1;
1380
1381 /* enable interrupt waiting for any tag group,
1382 may silently fail if interrupts are already enabled */
1383 ctx->ops->set_mfc_query(ctx, ctx->tagwait, 1);
1384 return 0;
1385}
1386
1387static ssize_t spufs_mfc_read(struct file *file, char __user *buffer,
1388 size_t size, loff_t *pos)
1389{
1390 struct spu_context *ctx = file->private_data;
1391 int ret = -EINVAL;
1392 u32 status;
1393
1394 if (size != 4)
1395 goto out;
1396
1397 spu_acquire(ctx);
1398 if (file->f_flags & O_NONBLOCK) {
1399 status = ctx->ops->read_mfc_tagstatus(ctx);
1400 if (!(status & ctx->tagwait))
1401 ret = -EAGAIN;
1402 else
1403 ctx->tagwait &= ~status;
1404 } else {
1405 ret = spufs_wait(ctx->mfc_wq,
1406 spufs_read_mfc_tagstatus(ctx, &status));
1407 }
1408 spu_release(ctx);
1409
1410 if (ret)
1411 goto out;
1412
1413 ret = 4;
1414 if (copy_to_user(buffer, &status, 4))
1415 ret = -EFAULT;
1416
1417out:
1418 return ret;
1419}
1420
1421static int spufs_check_valid_dma(struct mfc_dma_command *cmd)
1422{
1423 pr_debug("queueing DMA %x %lx %x %x %x\n", cmd->lsa,
1424 cmd->ea, cmd->size, cmd->tag, cmd->cmd);
1425
1426 switch (cmd->cmd) {
1427 case MFC_PUT_CMD:
1428 case MFC_PUTF_CMD:
1429 case MFC_PUTB_CMD:
1430 case MFC_GET_CMD:
1431 case MFC_GETF_CMD:
1432 case MFC_GETB_CMD:
1433 break;
1434 default:
1435 pr_debug("invalid DMA opcode %x\n", cmd->cmd);
1436 return -EIO;
1437 }
1438
1439 if ((cmd->lsa & 0xf) != (cmd->ea &0xf)) {
1440 pr_debug("invalid DMA alignment, ea %lx lsa %x\n",
1441 cmd->ea, cmd->lsa);
1442 return -EIO;
1443 }
1444
1445 switch (cmd->size & 0xf) {
1446 case 1:
1447 break;
1448 case 2:
1449 if (cmd->lsa & 1)
1450 goto error;
1451 break;
1452 case 4:
1453 if (cmd->lsa & 3)
1454 goto error;
1455 break;
1456 case 8:
1457 if (cmd->lsa & 7)
1458 goto error;
1459 break;
1460 case 0:
1461 if (cmd->lsa & 15)
1462 goto error;
1463 break;
1464 error:
1465 default:
1466 pr_debug("invalid DMA alignment %x for size %x\n",
1467 cmd->lsa & 0xf, cmd->size);
1468 return -EIO;
1469 }
1470
1471 if (cmd->size > 16 * 1024) {
1472 pr_debug("invalid DMA size %x\n", cmd->size);
1473 return -EIO;
1474 }
1475
1476 if (cmd->tag & 0xfff0) {
1477 /* we reserve the higher tag numbers for kernel use */
1478 pr_debug("invalid DMA tag\n");
1479 return -EIO;
1480 }
1481
1482 if (cmd->class) {
1483 /* not supported in this version */
1484 pr_debug("invalid DMA class\n");
1485 return -EIO;
1486 }
1487
1488 return 0;
1489}
1490
1491static int spu_send_mfc_command(struct spu_context *ctx,
1492 struct mfc_dma_command cmd,
1493 int *error)
1494{
1495 *error = ctx->ops->send_mfc_command(ctx, &cmd);
1496 if (*error == -EAGAIN) {
1497 /* wait for any tag group to complete
1498 so we have space for the new command */
1499 ctx->ops->set_mfc_query(ctx, ctx->tagwait, 1);
1500 /* try again, because the queue might be
1501 empty again */
1502 *error = ctx->ops->send_mfc_command(ctx, &cmd);
1503 if (*error == -EAGAIN)
1504 return 0;
1505 }
1506 return 1;
1507}
1508
1509static ssize_t spufs_mfc_write(struct file *file, const char __user *buffer,
1510 size_t size, loff_t *pos)
1511{
1512 struct spu_context *ctx = file->private_data;
1513 struct mfc_dma_command cmd;
1514 int ret = -EINVAL;
1515
1516 if (size != sizeof cmd)
1517 goto out;
1518
1519 ret = -EFAULT;
1520 if (copy_from_user(&cmd, buffer, sizeof cmd))
1521 goto out;
1522
1523 ret = spufs_check_valid_dma(&cmd);
1524 if (ret)
1525 goto out;
1526
Arnd Bergmann33bfd7a2007-12-20 16:39:59 +09001527 spu_acquire(ctx);
1528 ret = spufs_wait(ctx->run_wq, ctx->state == SPU_STATE_RUNNABLE);
Akinobu Mita577f8f12007-04-23 21:08:18 +02001529 if (ret)
1530 goto out;
1531
Arnd Bergmanna33a7d72006-03-23 00:00:11 +01001532 if (file->f_flags & O_NONBLOCK) {
1533 ret = ctx->ops->send_mfc_command(ctx, &cmd);
1534 } else {
1535 int status;
1536 ret = spufs_wait(ctx->mfc_wq,
1537 spu_send_mfc_command(ctx, cmd, &status));
1538 if (status)
1539 ret = status;
1540 }
Arnd Bergmanna33a7d72006-03-23 00:00:11 +01001541
1542 if (ret)
Kazunori Asayama933b0e32007-06-29 10:58:08 +10001543 goto out_unlock;
Arnd Bergmanna33a7d72006-03-23 00:00:11 +01001544
1545 ctx->tagwait |= 1 << cmd.tag;
Masato Noguchi3692dc62006-11-20 18:45:07 +01001546 ret = size;
Arnd Bergmanna33a7d72006-03-23 00:00:11 +01001547
Kazunori Asayama933b0e32007-06-29 10:58:08 +10001548out_unlock:
1549 spu_release(ctx);
Arnd Bergmanna33a7d72006-03-23 00:00:11 +01001550out:
1551 return ret;
1552}
1553
1554static unsigned int spufs_mfc_poll(struct file *file,poll_table *wait)
1555{
1556 struct spu_context *ctx = file->private_data;
1557 u32 free_elements, tagstatus;
1558 unsigned int mask;
1559
Kazunori Asayama933b0e32007-06-29 10:58:08 +10001560 poll_wait(file, &ctx->mfc_wq, wait);
1561
Arnd Bergmanna33a7d72006-03-23 00:00:11 +01001562 spu_acquire(ctx);
1563 ctx->ops->set_mfc_query(ctx, ctx->tagwait, 2);
1564 free_elements = ctx->ops->get_mfc_free_elements(ctx);
1565 tagstatus = ctx->ops->read_mfc_tagstatus(ctx);
1566 spu_release(ctx);
1567
Arnd Bergmanna33a7d72006-03-23 00:00:11 +01001568 mask = 0;
1569 if (free_elements & 0xffff)
1570 mask |= POLLOUT | POLLWRNORM;
1571 if (tagstatus & ctx->tagwait)
1572 mask |= POLLIN | POLLRDNORM;
1573
1574 pr_debug("%s: free %d tagstatus %d tagwait %d\n", __FUNCTION__,
1575 free_elements, tagstatus, ctx->tagwait);
1576
1577 return mask;
1578}
1579
Al Viro73b6af82006-06-25 16:42:33 -07001580static int spufs_mfc_flush(struct file *file, fl_owner_t id)
Arnd Bergmanna33a7d72006-03-23 00:00:11 +01001581{
1582 struct spu_context *ctx = file->private_data;
1583 int ret;
1584
1585 spu_acquire(ctx);
1586#if 0
1587/* this currently hangs */
1588 ret = spufs_wait(ctx->mfc_wq,
1589 ctx->ops->set_mfc_query(ctx, ctx->tagwait, 2));
1590 if (ret)
1591 goto out;
1592 ret = spufs_wait(ctx->mfc_wq,
1593 ctx->ops->read_mfc_tagstatus(ctx) == ctx->tagwait);
1594out:
1595#else
1596 ret = 0;
1597#endif
1598 spu_release(ctx);
1599
1600 return ret;
1601}
1602
1603static int spufs_mfc_fsync(struct file *file, struct dentry *dentry,
1604 int datasync)
1605{
Al Viro73b6af82006-06-25 16:42:33 -07001606 return spufs_mfc_flush(file, NULL);
Arnd Bergmanna33a7d72006-03-23 00:00:11 +01001607}
1608
1609static int spufs_mfc_fasync(int fd, struct file *file, int on)
1610{
1611 struct spu_context *ctx = file->private_data;
1612
1613 return fasync_helper(fd, file, on, &ctx->mfc_fasync);
1614}
1615
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -08001616static const struct file_operations spufs_mfc_fops = {
Arnd Bergmanna33a7d72006-03-23 00:00:11 +01001617 .open = spufs_mfc_open,
Christoph Hellwig43c2bbd2007-04-23 21:08:07 +02001618 .release = spufs_mfc_release,
Arnd Bergmanna33a7d72006-03-23 00:00:11 +01001619 .read = spufs_mfc_read,
1620 .write = spufs_mfc_write,
1621 .poll = spufs_mfc_poll,
1622 .flush = spufs_mfc_flush,
1623 .fsync = spufs_mfc_fsync,
1624 .fasync = spufs_mfc_fasync,
Mark Nutter6df10a82006-03-23 00:00:12 +01001625 .mmap = spufs_mfc_mmap,
Arnd Bergmanna33a7d72006-03-23 00:00:11 +01001626};
1627
Arnd Bergmann67207b92005-11-15 15:53:48 -05001628static void spufs_npc_set(void *data, u64 val)
1629{
1630 struct spu_context *ctx = data;
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001631 spu_acquire(ctx);
1632 ctx->ops->npc_write(ctx, val);
1633 spu_release(ctx);
Arnd Bergmann67207b92005-11-15 15:53:48 -05001634}
1635
Michael Ellerman104f0cc2007-09-19 14:38:12 +10001636static u64 spufs_npc_get(struct spu_context *ctx)
Michael Ellerman78810ff2007-09-19 14:38:12 +10001637{
1638 return ctx->ops->npc_read(ctx);
1639}
Michael Ellerman104f0cc2007-09-19 14:38:12 +10001640DEFINE_SPUFS_ATTRIBUTE(spufs_npc_ops, spufs_npc_get, spufs_npc_set,
1641 "0x%llx\n", SPU_ATTR_ACQUIRE);
Arnd Bergmann67207b92005-11-15 15:53:48 -05001642
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001643static void spufs_decr_set(void *data, u64 val)
1644{
1645 struct spu_context *ctx = data;
1646 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1647 spu_acquire_saved(ctx);
1648 lscsa->decr.slot[0] = (u32) val;
Christoph Hellwig27b1ea02007-07-20 21:39:34 +02001649 spu_release_saved(ctx);
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001650}
1651
Michael Ellerman104f0cc2007-09-19 14:38:12 +10001652static u64 spufs_decr_get(struct spu_context *ctx)
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001653{
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001654 struct spu_lscsa *lscsa = ctx->csa.lscsa;
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001655 return lscsa->decr.slot[0];
1656}
Michael Ellerman104f0cc2007-09-19 14:38:12 +10001657DEFINE_SPUFS_ATTRIBUTE(spufs_decr_ops, spufs_decr_get, spufs_decr_set,
1658 "0x%llx\n", SPU_ATTR_ACQUIRE_SAVED);
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001659
1660static void spufs_decr_status_set(void *data, u64 val)
1661{
1662 struct spu_context *ctx = data;
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001663 spu_acquire_saved(ctx);
Masato Noguchid40a01d2007-07-20 21:39:38 +02001664 if (val)
1665 ctx->csa.priv2.mfc_control_RW |= MFC_CNTL_DECREMENTER_RUNNING;
1666 else
1667 ctx->csa.priv2.mfc_control_RW &= ~MFC_CNTL_DECREMENTER_RUNNING;
Christoph Hellwig27b1ea02007-07-20 21:39:34 +02001668 spu_release_saved(ctx);
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001669}
1670
Michael Ellerman104f0cc2007-09-19 14:38:12 +10001671static u64 spufs_decr_status_get(struct spu_context *ctx)
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001672{
Masato Noguchid40a01d2007-07-20 21:39:38 +02001673 if (ctx->csa.priv2.mfc_control_RW & MFC_CNTL_DECREMENTER_RUNNING)
1674 return SPU_DECR_STATUS_RUNNING;
1675 else
1676 return 0;
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001677}
Michael Ellerman104f0cc2007-09-19 14:38:12 +10001678DEFINE_SPUFS_ATTRIBUTE(spufs_decr_status_ops, spufs_decr_status_get,
1679 spufs_decr_status_set, "0x%llx\n",
1680 SPU_ATTR_ACQUIRE_SAVED);
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001681
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001682static void spufs_event_mask_set(void *data, u64 val)
1683{
1684 struct spu_context *ctx = data;
1685 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1686 spu_acquire_saved(ctx);
1687 lscsa->event_mask.slot[0] = (u32) val;
Christoph Hellwig27b1ea02007-07-20 21:39:34 +02001688 spu_release_saved(ctx);
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001689}
1690
Michael Ellerman104f0cc2007-09-19 14:38:12 +10001691static u64 spufs_event_mask_get(struct spu_context *ctx)
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001692{
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001693 struct spu_lscsa *lscsa = ctx->csa.lscsa;
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001694 return lscsa->event_mask.slot[0];
1695}
1696
Michael Ellerman104f0cc2007-09-19 14:38:12 +10001697DEFINE_SPUFS_ATTRIBUTE(spufs_event_mask_ops, spufs_event_mask_get,
1698 spufs_event_mask_set, "0x%llx\n",
1699 SPU_ATTR_ACQUIRE_SAVED);
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001700
Michael Ellerman104f0cc2007-09-19 14:38:12 +10001701static u64 spufs_event_status_get(struct spu_context *ctx)
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01001702{
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01001703 struct spu_state *state = &ctx->csa;
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01001704 u64 stat;
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01001705 stat = state->spu_chnlcnt_RW[0];
1706 if (stat)
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001707 return state->spu_chnldata_RW[0];
1708 return 0;
1709}
Michael Ellerman104f0cc2007-09-19 14:38:12 +10001710DEFINE_SPUFS_ATTRIBUTE(spufs_event_status_ops, spufs_event_status_get,
1711 NULL, "0x%llx\n", SPU_ATTR_ACQUIRE_SAVED)
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01001712
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001713static void spufs_srr0_set(void *data, u64 val)
1714{
1715 struct spu_context *ctx = data;
1716 struct spu_lscsa *lscsa = ctx->csa.lscsa;
1717 spu_acquire_saved(ctx);
1718 lscsa->srr0.slot[0] = (u32) val;
Christoph Hellwig27b1ea02007-07-20 21:39:34 +02001719 spu_release_saved(ctx);
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001720}
1721
Michael Ellerman104f0cc2007-09-19 14:38:12 +10001722static u64 spufs_srr0_get(struct spu_context *ctx)
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001723{
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001724 struct spu_lscsa *lscsa = ctx->csa.lscsa;
Michael Ellerman104f0cc2007-09-19 14:38:12 +10001725 return lscsa->srr0.slot[0];
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001726}
Michael Ellerman104f0cc2007-09-19 14:38:12 +10001727DEFINE_SPUFS_ATTRIBUTE(spufs_srr0_ops, spufs_srr0_get, spufs_srr0_set,
1728 "0x%llx\n", SPU_ATTR_ACQUIRE_SAVED)
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05001729
Michael Ellerman104f0cc2007-09-19 14:38:12 +10001730static u64 spufs_id_get(struct spu_context *ctx)
arnd@arndb.de7b1a7012006-06-19 20:33:24 +02001731{
arnd@arndb.de7b1a7012006-06-19 20:33:24 +02001732 u64 num;
1733
arnd@arndb.de7b1a7012006-06-19 20:33:24 +02001734 if (ctx->state == SPU_STATE_RUNNABLE)
1735 num = ctx->spu->number;
1736 else
1737 num = (unsigned int)-1;
arnd@arndb.de7b1a7012006-06-19 20:33:24 +02001738
1739 return num;
1740}
Michael Ellerman104f0cc2007-09-19 14:38:12 +10001741DEFINE_SPUFS_ATTRIBUTE(spufs_id_ops, spufs_id_get, NULL, "0x%llx\n",
1742 SPU_ATTR_ACQUIRE)
arnd@arndb.de7b1a7012006-06-19 20:33:24 +02001743
Michael Ellerman104f0cc2007-09-19 14:38:12 +10001744static u64 spufs_object_id_get(struct spu_context *ctx)
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001745{
1746 /* FIXME: Should there really be no locking here? */
Michael Ellerman104f0cc2007-09-19 14:38:12 +10001747 return ctx->object_id;
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001748}
1749
Arnd Bergmann86767272006-10-04 17:26:21 +02001750static void spufs_object_id_set(void *data, u64 id)
1751{
1752 struct spu_context *ctx = data;
1753 ctx->object_id = id;
1754}
1755
Michael Ellerman104f0cc2007-09-19 14:38:12 +10001756DEFINE_SPUFS_ATTRIBUTE(spufs_object_id_ops, spufs_object_id_get,
1757 spufs_object_id_set, "0x%llx\n", SPU_ATTR_NOACQUIRE);
Arnd Bergmann86767272006-10-04 17:26:21 +02001758
Michael Ellerman104f0cc2007-09-19 14:38:12 +10001759static u64 spufs_lslr_get(struct spu_context *ctx)
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001760{
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001761 return ctx->csa.priv2.spu_lslr_RW;
1762}
Michael Ellerman104f0cc2007-09-19 14:38:12 +10001763DEFINE_SPUFS_ATTRIBUTE(spufs_lslr_ops, spufs_lslr_get, NULL, "0x%llx\n",
1764 SPU_ATTR_ACQUIRE_SAVED);
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01001765
1766static int spufs_info_open(struct inode *inode, struct file *file)
1767{
1768 struct spufs_inode_info *i = SPUFS_I(inode);
1769 struct spu_context *ctx = i->i_ctx;
1770 file->private_data = ctx;
1771 return 0;
1772}
1773
Benjamin Herrenschmidtcbe709c2007-06-04 15:15:38 +10001774static int spufs_caps_show(struct seq_file *s, void *private)
1775{
1776 struct spu_context *ctx = s->private;
1777
1778 if (!(ctx->flags & SPU_CREATE_NOSCHED))
1779 seq_puts(s, "sched\n");
1780 if (!(ctx->flags & SPU_CREATE_ISOLATE))
1781 seq_puts(s, "step\n");
1782 return 0;
1783}
1784
1785static int spufs_caps_open(struct inode *inode, struct file *file)
1786{
1787 return single_open(file, spufs_caps_show, SPUFS_I(inode)->i_ctx);
1788}
1789
1790static const struct file_operations spufs_caps_fops = {
1791 .open = spufs_caps_open,
1792 .read = seq_read,
1793 .llseek = seq_lseek,
1794 .release = single_release,
1795};
1796
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001797static ssize_t __spufs_mbox_info_read(struct spu_context *ctx,
1798 char __user *buf, size_t len, loff_t *pos)
1799{
1800 u32 mbox_stat;
1801 u32 data;
1802
1803 mbox_stat = ctx->csa.prob.mb_stat_R;
1804 if (mbox_stat & 0x0000ff) {
1805 data = ctx->csa.prob.pu_mb_R;
1806 }
1807
1808 return simple_read_from_buffer(buf, len, pos, &data, sizeof data);
1809}
1810
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01001811static ssize_t spufs_mbox_info_read(struct file *file, char __user *buf,
1812 size_t len, loff_t *pos)
1813{
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001814 int ret;
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01001815 struct spu_context *ctx = file->private_data;
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01001816
1817 if (!access_ok(VERIFY_WRITE, buf, len))
1818 return -EFAULT;
1819
1820 spu_acquire_saved(ctx);
1821 spin_lock(&ctx->csa.register_lock);
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001822 ret = __spufs_mbox_info_read(ctx, buf, len, pos);
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01001823 spin_unlock(&ctx->csa.register_lock);
Christoph Hellwig27b1ea02007-07-20 21:39:34 +02001824 spu_release_saved(ctx);
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01001825
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001826 return ret;
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01001827}
1828
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -08001829static const struct file_operations spufs_mbox_info_fops = {
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01001830 .open = spufs_info_open,
1831 .read = spufs_mbox_info_read,
1832 .llseek = generic_file_llseek,
1833};
1834
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001835static ssize_t __spufs_ibox_info_read(struct spu_context *ctx,
1836 char __user *buf, size_t len, loff_t *pos)
1837{
1838 u32 ibox_stat;
1839 u32 data;
1840
1841 ibox_stat = ctx->csa.prob.mb_stat_R;
1842 if (ibox_stat & 0xff0000) {
1843 data = ctx->csa.priv2.puint_mb_R;
1844 }
1845
1846 return simple_read_from_buffer(buf, len, pos, &data, sizeof data);
1847}
1848
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01001849static ssize_t spufs_ibox_info_read(struct file *file, char __user *buf,
1850 size_t len, loff_t *pos)
1851{
1852 struct spu_context *ctx = file->private_data;
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001853 int ret;
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01001854
1855 if (!access_ok(VERIFY_WRITE, buf, len))
1856 return -EFAULT;
1857
1858 spu_acquire_saved(ctx);
1859 spin_lock(&ctx->csa.register_lock);
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001860 ret = __spufs_ibox_info_read(ctx, buf, len, pos);
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01001861 spin_unlock(&ctx->csa.register_lock);
Christoph Hellwig27b1ea02007-07-20 21:39:34 +02001862 spu_release_saved(ctx);
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01001863
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001864 return ret;
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01001865}
1866
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -08001867static const struct file_operations spufs_ibox_info_fops = {
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01001868 .open = spufs_info_open,
1869 .read = spufs_ibox_info_read,
1870 .llseek = generic_file_llseek,
1871};
1872
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001873static ssize_t __spufs_wbox_info_read(struct spu_context *ctx,
1874 char __user *buf, size_t len, loff_t *pos)
1875{
1876 int i, cnt;
1877 u32 data[4];
1878 u32 wbox_stat;
1879
1880 wbox_stat = ctx->csa.prob.mb_stat_R;
1881 cnt = 4 - ((wbox_stat & 0x00ff00) >> 8);
1882 for (i = 0; i < cnt; i++) {
1883 data[i] = ctx->csa.spu_mailbox_data[i];
1884 }
1885
1886 return simple_read_from_buffer(buf, len, pos, &data,
1887 cnt * sizeof(u32));
1888}
1889
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01001890static ssize_t spufs_wbox_info_read(struct file *file, char __user *buf,
1891 size_t len, loff_t *pos)
1892{
1893 struct spu_context *ctx = file->private_data;
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001894 int ret;
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01001895
1896 if (!access_ok(VERIFY_WRITE, buf, len))
1897 return -EFAULT;
1898
1899 spu_acquire_saved(ctx);
1900 spin_lock(&ctx->csa.register_lock);
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001901 ret = __spufs_wbox_info_read(ctx, buf, len, pos);
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01001902 spin_unlock(&ctx->csa.register_lock);
Christoph Hellwig27b1ea02007-07-20 21:39:34 +02001903 spu_release_saved(ctx);
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01001904
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001905 return ret;
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01001906}
1907
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -08001908static const struct file_operations spufs_wbox_info_fops = {
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01001909 .open = spufs_info_open,
1910 .read = spufs_wbox_info_read,
1911 .llseek = generic_file_llseek,
1912};
1913
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001914static ssize_t __spufs_dma_info_read(struct spu_context *ctx,
1915 char __user *buf, size_t len, loff_t *pos)
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01001916{
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01001917 struct spu_dma_info info;
1918 struct mfc_cq_sr *qp, *spuqp;
1919 int i;
1920
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01001921 info.dma_info_type = ctx->csa.priv2.spu_tag_status_query_RW;
1922 info.dma_info_mask = ctx->csa.lscsa->tag_mask.slot[0];
1923 info.dma_info_status = ctx->csa.spu_chnldata_RW[24];
1924 info.dma_info_stall_and_notify = ctx->csa.spu_chnldata_RW[25];
1925 info.dma_info_atomic_command_status = ctx->csa.spu_chnldata_RW[27];
1926 for (i = 0; i < 16; i++) {
1927 qp = &info.dma_info_command_data[i];
1928 spuqp = &ctx->csa.priv2.spuq[i];
1929
1930 qp->mfc_cq_data0_RW = spuqp->mfc_cq_data0_RW;
1931 qp->mfc_cq_data1_RW = spuqp->mfc_cq_data1_RW;
1932 qp->mfc_cq_data2_RW = spuqp->mfc_cq_data2_RW;
1933 qp->mfc_cq_data3_RW = spuqp->mfc_cq_data3_RW;
1934 }
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01001935
1936 return simple_read_from_buffer(buf, len, pos, &info,
1937 sizeof info);
1938}
1939
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001940static ssize_t spufs_dma_info_read(struct file *file, char __user *buf,
1941 size_t len, loff_t *pos)
1942{
1943 struct spu_context *ctx = file->private_data;
1944 int ret;
1945
1946 if (!access_ok(VERIFY_WRITE, buf, len))
1947 return -EFAULT;
1948
1949 spu_acquire_saved(ctx);
1950 spin_lock(&ctx->csa.register_lock);
1951 ret = __spufs_dma_info_read(ctx, buf, len, pos);
1952 spin_unlock(&ctx->csa.register_lock);
Christoph Hellwig27b1ea02007-07-20 21:39:34 +02001953 spu_release_saved(ctx);
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001954
1955 return ret;
1956}
1957
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -08001958static const struct file_operations spufs_dma_info_fops = {
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01001959 .open = spufs_info_open,
1960 .read = spufs_dma_info_read,
1961};
1962
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001963static ssize_t __spufs_proxydma_info_read(struct spu_context *ctx,
1964 char __user *buf, size_t len, loff_t *pos)
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01001965{
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01001966 struct spu_proxydma_info info;
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01001967 struct mfc_cq_sr *qp, *puqp;
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001968 int ret = sizeof info;
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01001969 int i;
1970
1971 if (len < ret)
1972 return -EINVAL;
1973
1974 if (!access_ok(VERIFY_WRITE, buf, len))
1975 return -EFAULT;
1976
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01001977 info.proxydma_info_type = ctx->csa.prob.dma_querytype_RW;
1978 info.proxydma_info_mask = ctx->csa.prob.dma_querymask_RW;
1979 info.proxydma_info_status = ctx->csa.prob.dma_tagstatus_R;
1980 for (i = 0; i < 8; i++) {
1981 qp = &info.proxydma_info_command_data[i];
1982 puqp = &ctx->csa.priv2.puq[i];
1983
1984 qp->mfc_cq_data0_RW = puqp->mfc_cq_data0_RW;
1985 qp->mfc_cq_data1_RW = puqp->mfc_cq_data1_RW;
1986 qp->mfc_cq_data2_RW = puqp->mfc_cq_data2_RW;
1987 qp->mfc_cq_data3_RW = puqp->mfc_cq_data3_RW;
1988 }
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01001989
1990 return simple_read_from_buffer(buf, len, pos, &info,
1991 sizeof info);
1992}
1993
1994static ssize_t spufs_proxydma_info_read(struct file *file, char __user *buf,
1995 size_t len, loff_t *pos)
1996{
1997 struct spu_context *ctx = file->private_data;
1998 int ret;
1999
2000 spu_acquire_saved(ctx);
2001 spin_lock(&ctx->csa.register_lock);
2002 ret = __spufs_proxydma_info_read(ctx, buf, len, pos);
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01002003 spin_unlock(&ctx->csa.register_lock);
Christoph Hellwig27b1ea02007-07-20 21:39:34 +02002004 spu_release_saved(ctx);
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01002005
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01002006 return ret;
2007}
2008
Arjan van de Ven5dfe4c92007-02-12 00:55:31 -08002009static const struct file_operations spufs_proxydma_info_fops = {
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01002010 .open = spufs_info_open,
2011 .read = spufs_proxydma_info_read,
2012};
2013
Christoph Hellwig476273a2007-06-29 10:58:01 +10002014static int spufs_show_tid(struct seq_file *s, void *private)
2015{
2016 struct spu_context *ctx = s->private;
2017
2018 seq_printf(s, "%d\n", ctx->tid);
2019 return 0;
2020}
2021
2022static int spufs_tid_open(struct inode *inode, struct file *file)
2023{
2024 return single_open(file, spufs_show_tid, SPUFS_I(inode)->i_ctx);
2025}
2026
2027static const struct file_operations spufs_tid_fops = {
2028 .open = spufs_tid_open,
2029 .read = seq_read,
2030 .llseek = seq_lseek,
2031 .release = single_release,
2032};
2033
Christoph Hellwige9f8a0b2007-06-29 10:58:03 +10002034static const char *ctx_state_names[] = {
2035 "user", "system", "iowait", "loaded"
2036};
2037
2038static unsigned long long spufs_acct_time(struct spu_context *ctx,
Andre Detsch27ec41d2007-07-20 21:39:33 +02002039 enum spu_utilization_state state)
Christoph Hellwige9f8a0b2007-06-29 10:58:03 +10002040{
Andre Detsch27ec41d2007-07-20 21:39:33 +02002041 struct timespec ts;
2042 unsigned long long time = ctx->stats.times[state];
Christoph Hellwige9f8a0b2007-06-29 10:58:03 +10002043
Andre Detsch27ec41d2007-07-20 21:39:33 +02002044 /*
2045 * In general, utilization statistics are updated by the controlling
2046 * thread as the spu context moves through various well defined
2047 * state transitions, but if the context is lazily loaded its
2048 * utilization statistics are not updated as the controlling thread
2049 * is not tightly coupled with the execution of the spu context. We
2050 * calculate and apply the time delta from the last recorded state
2051 * of the spu context.
2052 */
2053 if (ctx->spu && ctx->stats.util_state == state) {
2054 ktime_get_ts(&ts);
2055 time += timespec_to_ns(&ts) - ctx->stats.tstamp;
2056 }
Christoph Hellwige9f8a0b2007-06-29 10:58:03 +10002057
Andre Detsch27ec41d2007-07-20 21:39:33 +02002058 return time / NSEC_PER_MSEC;
Christoph Hellwige9f8a0b2007-06-29 10:58:03 +10002059}
2060
2061static unsigned long long spufs_slb_flts(struct spu_context *ctx)
2062{
2063 unsigned long long slb_flts = ctx->stats.slb_flt;
2064
2065 if (ctx->state == SPU_STATE_RUNNABLE) {
2066 slb_flts += (ctx->spu->stats.slb_flt -
2067 ctx->stats.slb_flt_base);
2068 }
2069
2070 return slb_flts;
2071}
2072
2073static unsigned long long spufs_class2_intrs(struct spu_context *ctx)
2074{
2075 unsigned long long class2_intrs = ctx->stats.class2_intr;
2076
2077 if (ctx->state == SPU_STATE_RUNNABLE) {
2078 class2_intrs += (ctx->spu->stats.class2_intr -
2079 ctx->stats.class2_intr_base);
2080 }
2081
2082 return class2_intrs;
2083}
2084
2085
2086static int spufs_show_stat(struct seq_file *s, void *private)
2087{
2088 struct spu_context *ctx = s->private;
2089
2090 spu_acquire(ctx);
2091 seq_printf(s, "%s %llu %llu %llu %llu "
2092 "%llu %llu %llu %llu %llu %llu %llu %llu\n",
Andre Detsch27ec41d2007-07-20 21:39:33 +02002093 ctx_state_names[ctx->stats.util_state],
2094 spufs_acct_time(ctx, SPU_UTIL_USER),
2095 spufs_acct_time(ctx, SPU_UTIL_SYSTEM),
2096 spufs_acct_time(ctx, SPU_UTIL_IOWAIT),
2097 spufs_acct_time(ctx, SPU_UTIL_IDLE_LOADED),
Christoph Hellwige9f8a0b2007-06-29 10:58:03 +10002098 ctx->stats.vol_ctx_switch,
2099 ctx->stats.invol_ctx_switch,
2100 spufs_slb_flts(ctx),
2101 ctx->stats.hash_flt,
2102 ctx->stats.min_flt,
2103 ctx->stats.maj_flt,
2104 spufs_class2_intrs(ctx),
2105 ctx->stats.libassist);
2106 spu_release(ctx);
2107 return 0;
2108}
2109
2110static int spufs_stat_open(struct inode *inode, struct file *file)
2111{
2112 return single_open(file, spufs_show_stat, SPUFS_I(inode)->i_ctx);
2113}
2114
2115static const struct file_operations spufs_stat_fops = {
2116 .open = spufs_stat_open,
2117 .read = seq_read,
2118 .llseek = seq_lseek,
2119 .release = single_release,
2120};
2121
2122
Arnd Bergmann67207b92005-11-15 15:53:48 -05002123struct tree_descr spufs_dir_contents[] = {
Benjamin Herrenschmidtcbe709c2007-06-04 15:15:38 +10002124 { "capabilities", &spufs_caps_fops, 0444, },
Arnd Bergmann67207b92005-11-15 15:53:48 -05002125 { "mem", &spufs_mem_fops, 0666, },
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05002126 { "regs", &spufs_regs_fops, 0666, },
Arnd Bergmann67207b92005-11-15 15:53:48 -05002127 { "mbox", &spufs_mbox_fops, 0444, },
2128 { "ibox", &spufs_ibox_fops, 0444, },
2129 { "wbox", &spufs_wbox_fops, 0222, },
2130 { "mbox_stat", &spufs_mbox_stat_fops, 0444, },
2131 { "ibox_stat", &spufs_ibox_stat_fops, 0444, },
2132 { "wbox_stat", &spufs_wbox_stat_fops, 0444, },
Jeremy Kerr603c4612007-09-26 10:53:45 +10002133 { "signal1", &spufs_signal1_fops, 0666, },
2134 { "signal2", &spufs_signal2_fops, 0666, },
Arnd Bergmann67207b92005-11-15 15:53:48 -05002135 { "signal1_type", &spufs_signal1_type, 0666, },
2136 { "signal2_type", &spufs_signal2_type, 0666, },
Mark Nutter6df10a82006-03-23 00:00:12 +01002137 { "cntl", &spufs_cntl_fops, 0666, },
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05002138 { "fpcr", &spufs_fpcr_fops, 0666, },
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01002139 { "lslr", &spufs_lslr_ops, 0444, },
2140 { "mfc", &spufs_mfc_fops, 0666, },
2141 { "mss", &spufs_mss_fops, 0666, },
2142 { "npc", &spufs_npc_ops, 0666, },
2143 { "srr0", &spufs_srr0_ops, 0666, },
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05002144 { "decr", &spufs_decr_ops, 0666, },
2145 { "decr_status", &spufs_decr_status_ops, 0666, },
Arnd Bergmann8b3d6662005-11-15 15:53:52 -05002146 { "event_mask", &spufs_event_mask_ops, 0666, },
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01002147 { "event_status", &spufs_event_status_ops, 0444, },
Benjamin Herrenschmidt27d5bf22006-10-04 17:26:11 +02002148 { "psmap", &spufs_psmap_fops, 0666, },
Arnd Bergmann86767272006-10-04 17:26:21 +02002149 { "phys-id", &spufs_id_ops, 0666, },
2150 { "object-id", &spufs_object_id_ops, 0666, },
Dwayne Grant McConnell69a2f002006-11-20 18:45:00 +01002151 { "mbox_info", &spufs_mbox_info_fops, 0444, },
2152 { "ibox_info", &spufs_ibox_info_fops, 0444, },
2153 { "wbox_info", &spufs_wbox_info_fops, 0444, },
Dwayne Grant McConnellb9e3bd72006-11-20 18:44:58 +01002154 { "dma_info", &spufs_dma_info_fops, 0444, },
2155 { "proxydma_info", &spufs_proxydma_info_fops, 0444, },
Christoph Hellwig476273a2007-06-29 10:58:01 +10002156 { "tid", &spufs_tid_fops, 0444, },
Christoph Hellwige9f8a0b2007-06-29 10:58:03 +10002157 { "stat", &spufs_stat_fops, 0444, },
Arnd Bergmann67207b92005-11-15 15:53:48 -05002158 {},
2159};
Mark Nutter5737edd2006-10-24 18:31:16 +02002160
2161struct tree_descr spufs_dir_nosched_contents[] = {
Benjamin Herrenschmidtcbe709c2007-06-04 15:15:38 +10002162 { "capabilities", &spufs_caps_fops, 0444, },
Mark Nutter5737edd2006-10-24 18:31:16 +02002163 { "mem", &spufs_mem_fops, 0666, },
2164 { "mbox", &spufs_mbox_fops, 0444, },
2165 { "ibox", &spufs_ibox_fops, 0444, },
2166 { "wbox", &spufs_wbox_fops, 0222, },
2167 { "mbox_stat", &spufs_mbox_stat_fops, 0444, },
2168 { "ibox_stat", &spufs_ibox_stat_fops, 0444, },
2169 { "wbox_stat", &spufs_wbox_stat_fops, 0444, },
Jeremy Kerrd054b362007-07-20 21:39:31 +02002170 { "signal1", &spufs_signal1_nosched_fops, 0222, },
2171 { "signal2", &spufs_signal2_nosched_fops, 0222, },
Mark Nutter5737edd2006-10-24 18:31:16 +02002172 { "signal1_type", &spufs_signal1_type, 0666, },
2173 { "signal2_type", &spufs_signal2_type, 0666, },
2174 { "mss", &spufs_mss_fops, 0666, },
2175 { "mfc", &spufs_mfc_fops, 0666, },
2176 { "cntl", &spufs_cntl_fops, 0666, },
2177 { "npc", &spufs_npc_ops, 0666, },
2178 { "psmap", &spufs_psmap_fops, 0666, },
2179 { "phys-id", &spufs_id_ops, 0666, },
2180 { "object-id", &spufs_object_id_ops, 0666, },
Christoph Hellwig476273a2007-06-29 10:58:01 +10002181 { "tid", &spufs_tid_fops, 0444, },
Christoph Hellwige9f8a0b2007-06-29 10:58:03 +10002182 { "stat", &spufs_stat_fops, 0444, },
Mark Nutter5737edd2006-10-24 18:31:16 +02002183 {},
2184};
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01002185
2186struct spufs_coredump_reader spufs_coredump_read[] = {
Michael Ellerman4fca9c42007-09-19 14:38:12 +10002187 { "regs", __spufs_regs_read, NULL, sizeof(struct spu_reg128[128])},
2188 { "fpcr", __spufs_fpcr_read, NULL, sizeof(struct spu_reg128) },
Michael Ellerman104f0cc2007-09-19 14:38:12 +10002189 { "lslr", NULL, spufs_lslr_get, 19 },
2190 { "decr", NULL, spufs_decr_get, 19 },
2191 { "decr_status", NULL, spufs_decr_status_get, 19 },
Michael Ellerman4fca9c42007-09-19 14:38:12 +10002192 { "mem", __spufs_mem_read, NULL, LS_SIZE, },
2193 { "signal1", __spufs_signal1_read, NULL, sizeof(u32) },
Michael Ellerman104f0cc2007-09-19 14:38:12 +10002194 { "signal1_type", NULL, spufs_signal1_type_get, 19 },
Michael Ellerman4fca9c42007-09-19 14:38:12 +10002195 { "signal2", __spufs_signal2_read, NULL, sizeof(u32) },
Michael Ellerman104f0cc2007-09-19 14:38:12 +10002196 { "signal2_type", NULL, spufs_signal2_type_get, 19 },
2197 { "event_mask", NULL, spufs_event_mask_get, 19 },
2198 { "event_status", NULL, spufs_event_status_get, 19 },
Michael Ellerman4fca9c42007-09-19 14:38:12 +10002199 { "mbox_info", __spufs_mbox_info_read, NULL, sizeof(u32) },
2200 { "ibox_info", __spufs_ibox_info_read, NULL, sizeof(u32) },
2201 { "wbox_info", __spufs_wbox_info_read, NULL, 4 * sizeof(u32)},
2202 { "dma_info", __spufs_dma_info_read, NULL, sizeof(struct spu_dma_info)},
2203 { "proxydma_info", __spufs_proxydma_info_read,
2204 NULL, sizeof(struct spu_proxydma_info)},
Michael Ellerman104f0cc2007-09-19 14:38:12 +10002205 { "object-id", NULL, spufs_object_id_get, 19 },
2206 { "npc", NULL, spufs_npc_get, 19 },
Michael Ellerman936d5bf2007-09-19 14:38:12 +10002207 { NULL },
Dwayne Grant McConnellbf1ab972006-11-23 00:46:37 +01002208};