Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1 | /* |
| 2 | * SPU file system -- file contents |
| 3 | * |
| 4 | * (C) Copyright IBM Deutschland Entwicklung GmbH 2005 |
| 5 | * |
| 6 | * Author: Arnd Bergmann <arndb@de.ibm.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2, or (at your option) |
| 11 | * any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 21 | */ |
| 22 | |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 23 | #undef DEBUG |
| 24 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 25 | #include <linux/fs.h> |
| 26 | #include <linux/ioctl.h> |
| 27 | #include <linux/module.h> |
Arnd Bergmann | d88cfff | 2005-12-05 22:52:22 -0500 | [diff] [blame] | 28 | #include <linux/pagemap.h> |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 29 | #include <linux/poll.h> |
Arnd Bergmann | 5110459 | 2005-12-05 22:52:25 -0500 | [diff] [blame] | 30 | #include <linux/ptrace.h> |
Benjamin Herrenschmidt | cbe709c | 2007-06-04 15:15:38 +1000 | [diff] [blame] | 31 | #include <linux/seq_file.h> |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 32 | |
| 33 | #include <asm/io.h> |
| 34 | #include <asm/semaphore.h> |
| 35 | #include <asm/spu.h> |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 36 | #include <asm/spu_info.h> |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 37 | #include <asm/uaccess.h> |
| 38 | |
| 39 | #include "spufs.h" |
| 40 | |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 41 | #define SPUFS_MMAP_4K (PAGE_SIZE == 0x1000) |
| 42 | |
Benjamin Herrenschmidt | cbe709c | 2007-06-04 15:15:38 +1000 | [diff] [blame] | 43 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 44 | static int |
| 45 | spufs_mem_open(struct inode *inode, struct file *file) |
| 46 | { |
| 47 | struct spufs_inode_info *i = SPUFS_I(inode); |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 48 | struct spu_context *ctx = i->i_ctx; |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 49 | |
Christoph Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 50 | mutex_lock(&ctx->mapping_lock); |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 51 | file->private_data = ctx; |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 52 | if (!i->i_openers++) |
| 53 | ctx->local_store = inode->i_mapping; |
Christoph Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 54 | mutex_unlock(&ctx->mapping_lock); |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 55 | return 0; |
| 56 | } |
| 57 | |
| 58 | static int |
| 59 | spufs_mem_release(struct inode *inode, struct file *file) |
| 60 | { |
| 61 | struct spufs_inode_info *i = SPUFS_I(inode); |
| 62 | struct spu_context *ctx = i->i_ctx; |
| 63 | |
Christoph Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 64 | mutex_lock(&ctx->mapping_lock); |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 65 | if (!--i->i_openers) |
| 66 | ctx->local_store = NULL; |
Christoph Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 67 | mutex_unlock(&ctx->mapping_lock); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 68 | return 0; |
| 69 | } |
| 70 | |
| 71 | static ssize_t |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 72 | __spufs_mem_read(struct spu_context *ctx, char __user *buffer, |
| 73 | size_t size, loff_t *pos) |
| 74 | { |
| 75 | char *local_store = ctx->ops->get_ls(ctx); |
| 76 | return simple_read_from_buffer(buffer, size, pos, local_store, |
| 77 | LS_SIZE); |
| 78 | } |
| 79 | |
| 80 | static ssize_t |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 81 | spufs_mem_read(struct file *file, char __user *buffer, |
| 82 | size_t size, loff_t *pos) |
| 83 | { |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 84 | struct spu_context *ctx = file->private_data; |
Arnd Bergmann | aa0ed2b | 2007-03-10 00:05:35 +0100 | [diff] [blame] | 85 | ssize_t ret; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 86 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 87 | spu_acquire(ctx); |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 88 | ret = __spufs_mem_read(ctx, buffer, size, pos); |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 89 | spu_release(ctx); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 90 | return ret; |
| 91 | } |
| 92 | |
| 93 | static ssize_t |
| 94 | spufs_mem_write(struct file *file, const char __user *buffer, |
Arnd Bergmann | aa0ed2b | 2007-03-10 00:05:35 +0100 | [diff] [blame] | 95 | size_t size, loff_t *ppos) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 96 | { |
| 97 | struct spu_context *ctx = file->private_data; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 98 | char *local_store; |
Arnd Bergmann | aa0ed2b | 2007-03-10 00:05:35 +0100 | [diff] [blame] | 99 | loff_t pos = *ppos; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 100 | int ret; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 101 | |
Arnd Bergmann | aa0ed2b | 2007-03-10 00:05:35 +0100 | [diff] [blame] | 102 | if (pos < 0) |
| 103 | return -EINVAL; |
| 104 | if (pos > LS_SIZE) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 105 | return -EFBIG; |
Arnd Bergmann | aa0ed2b | 2007-03-10 00:05:35 +0100 | [diff] [blame] | 106 | if (size > LS_SIZE - pos) |
| 107 | size = LS_SIZE - pos; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 108 | |
| 109 | spu_acquire(ctx); |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 110 | local_store = ctx->ops->get_ls(ctx); |
Arnd Bergmann | aa0ed2b | 2007-03-10 00:05:35 +0100 | [diff] [blame] | 111 | ret = copy_from_user(local_store + pos, buffer, size); |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 112 | spu_release(ctx); |
Arnd Bergmann | aa0ed2b | 2007-03-10 00:05:35 +0100 | [diff] [blame] | 113 | |
| 114 | if (ret) |
| 115 | return -EFAULT; |
| 116 | *ppos = pos + size; |
| 117 | return size; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 118 | } |
| 119 | |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 120 | static unsigned long spufs_mem_mmap_nopfn(struct vm_area_struct *vma, |
| 121 | unsigned long address) |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 122 | { |
Benjamin Herrenschmidt | f1fa74f | 2007-05-08 16:27:29 +1000 | [diff] [blame] | 123 | struct spu_context *ctx = vma->vm_file->private_data; |
| 124 | unsigned long pfn, offset, addr0 = address; |
| 125 | #ifdef CONFIG_SPU_FS_64K_LS |
| 126 | struct spu_state *csa = &ctx->csa; |
| 127 | int psize; |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 128 | |
Benjamin Herrenschmidt | f1fa74f | 2007-05-08 16:27:29 +1000 | [diff] [blame] | 129 | /* Check what page size we are using */ |
| 130 | psize = get_slice_psize(vma->vm_mm, address); |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 131 | |
Benjamin Herrenschmidt | f1fa74f | 2007-05-08 16:27:29 +1000 | [diff] [blame] | 132 | /* Some sanity checking */ |
| 133 | BUG_ON(csa->use_big_pages != (psize == MMU_PAGE_64K)); |
| 134 | |
| 135 | /* Wow, 64K, cool, we need to align the address though */ |
| 136 | if (csa->use_big_pages) { |
| 137 | BUG_ON(vma->vm_start & 0xffff); |
| 138 | address &= ~0xfffful; |
| 139 | } |
| 140 | #endif /* CONFIG_SPU_FS_64K_LS */ |
| 141 | |
| 142 | offset = (address - vma->vm_start) + (vma->vm_pgoff << PAGE_SHIFT); |
Masato Noguchi | 128b854 | 2007-02-13 21:54:30 +0100 | [diff] [blame] | 143 | if (offset >= LS_SIZE) |
| 144 | return NOPFN_SIGBUS; |
| 145 | |
Benjamin Herrenschmidt | f1fa74f | 2007-05-08 16:27:29 +1000 | [diff] [blame] | 146 | pr_debug("spufs_mem_mmap_nopfn address=0x%lx -> 0x%lx, offset=0x%lx\n", |
| 147 | addr0, address, offset); |
| 148 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 149 | spu_acquire(ctx); |
| 150 | |
Arnd Bergmann | ac91cb8 | 2006-10-04 17:26:16 +0200 | [diff] [blame] | 151 | if (ctx->state == SPU_STATE_SAVED) { |
| 152 | vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot) |
Arnd Bergmann | 932f535d | 2006-11-20 18:45:06 +0100 | [diff] [blame] | 153 | & ~_PAGE_NO_CACHE); |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 154 | pfn = vmalloc_to_pfn(ctx->csa.lscsa->ls + offset); |
Arnd Bergmann | ac91cb8 | 2006-10-04 17:26:16 +0200 | [diff] [blame] | 155 | } else { |
| 156 | vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot) |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 157 | | _PAGE_NO_CACHE); |
| 158 | pfn = (ctx->spu->local_store_phys + offset) >> PAGE_SHIFT; |
Arnd Bergmann | ac91cb8 | 2006-10-04 17:26:16 +0200 | [diff] [blame] | 159 | } |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 160 | vm_insert_pfn(vma, address, pfn); |
| 161 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 162 | spu_release(ctx); |
| 163 | |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 164 | return NOPFN_REFAULT; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 165 | } |
| 166 | |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 167 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 168 | static struct vm_operations_struct spufs_mem_mmap_vmops = { |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 169 | .nopfn = spufs_mem_mmap_nopfn, |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 170 | }; |
| 171 | |
Benjamin Herrenschmidt | f1fa74f | 2007-05-08 16:27:29 +1000 | [diff] [blame] | 172 | static int spufs_mem_mmap(struct file *file, struct vm_area_struct *vma) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 173 | { |
Benjamin Herrenschmidt | f1fa74f | 2007-05-08 16:27:29 +1000 | [diff] [blame] | 174 | #ifdef CONFIG_SPU_FS_64K_LS |
| 175 | struct spu_context *ctx = file->private_data; |
| 176 | struct spu_state *csa = &ctx->csa; |
| 177 | |
| 178 | /* Sanity check VMA alignment */ |
| 179 | if (csa->use_big_pages) { |
| 180 | pr_debug("spufs_mem_mmap 64K, start=0x%lx, end=0x%lx," |
| 181 | " pgoff=0x%lx\n", vma->vm_start, vma->vm_end, |
| 182 | vma->vm_pgoff); |
| 183 | if (vma->vm_start & 0xffff) |
| 184 | return -EINVAL; |
| 185 | if (vma->vm_pgoff & 0xf) |
| 186 | return -EINVAL; |
| 187 | } |
| 188 | #endif /* CONFIG_SPU_FS_64K_LS */ |
| 189 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 190 | if (!(vma->vm_flags & VM_SHARED)) |
| 191 | return -EINVAL; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 192 | |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 193 | vma->vm_flags |= VM_IO | VM_PFNMAP; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 194 | vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot) |
| 195 | | _PAGE_NO_CACHE); |
| 196 | |
| 197 | vma->vm_ops = &spufs_mem_mmap_vmops; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 198 | return 0; |
| 199 | } |
| 200 | |
Benjamin Herrenschmidt | f1fa74f | 2007-05-08 16:27:29 +1000 | [diff] [blame] | 201 | #ifdef CONFIG_SPU_FS_64K_LS |
Sebastian Siewior | 1238819 | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 202 | static unsigned long spufs_get_unmapped_area(struct file *file, |
| 203 | unsigned long addr, unsigned long len, unsigned long pgoff, |
| 204 | unsigned long flags) |
Benjamin Herrenschmidt | f1fa74f | 2007-05-08 16:27:29 +1000 | [diff] [blame] | 205 | { |
| 206 | struct spu_context *ctx = file->private_data; |
| 207 | struct spu_state *csa = &ctx->csa; |
| 208 | |
| 209 | /* If not using big pages, fallback to normal MM g_u_a */ |
| 210 | if (!csa->use_big_pages) |
| 211 | return current->mm->get_unmapped_area(file, addr, len, |
| 212 | pgoff, flags); |
| 213 | |
| 214 | /* Else, try to obtain a 64K pages slice */ |
| 215 | return slice_get_unmapped_area(addr, len, flags, |
| 216 | MMU_PAGE_64K, 1, 0); |
| 217 | } |
| 218 | #endif /* CONFIG_SPU_FS_64K_LS */ |
| 219 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 220 | static const struct file_operations spufs_mem_fops = { |
Jeremy Kerr | 7022543 | 2007-06-29 10:58:00 +1000 | [diff] [blame] | 221 | .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 Herrenschmidt | f1fa74f | 2007-05-08 16:27:29 +1000 | [diff] [blame] | 227 | #ifdef CONFIG_SPU_FS_64K_LS |
| 228 | .get_unmapped_area = spufs_get_unmapped_area, |
| 229 | #endif |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 230 | }; |
| 231 | |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 232 | static unsigned long spufs_ps_nopfn(struct vm_area_struct *vma, |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 233 | unsigned long address, |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 234 | unsigned long ps_offs, |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 235 | unsigned long ps_size) |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 236 | { |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 237 | struct spu_context *ctx = vma->vm_file->private_data; |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 238 | unsigned long area, offset = address - vma->vm_start; |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 239 | |
| 240 | offset += vma->vm_pgoff << PAGE_SHIFT; |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 241 | if (offset >= ps_size) |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 242 | return NOPFN_SIGBUS; |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 243 | |
Arnd Bergmann | 33bfd7a | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 244 | /* |
| 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 Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 251 | */ |
Arnd Bergmann | 33bfd7a | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 252 | spu_acquire(ctx); |
| 253 | if (ctx->state == SPU_STATE_SAVED) { |
| 254 | up_read(¤t->mm->mmap_sem); |
| 255 | spufs_wait(ctx->run_wq, ctx->state == SPU_STATE_RUNNABLE); |
| 256 | down_read(¤t->mm->mmap_sem); |
| 257 | goto out; |
| 258 | } |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 259 | |
| 260 | area = ctx->spu->problem_phys + ps_offs; |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 261 | vm_insert_pfn(vma, address, (area + offset) >> PAGE_SHIFT); |
Arnd Bergmann | 33bfd7a | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 262 | |
| 263 | out: |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 264 | spu_release(ctx); |
| 265 | |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 266 | return NOPFN_REFAULT; |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 267 | } |
| 268 | |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 269 | #if SPUFS_MMAP_4K |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 270 | static unsigned long spufs_cntl_mmap_nopfn(struct vm_area_struct *vma, |
| 271 | unsigned long address) |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 272 | { |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 273 | return spufs_ps_nopfn(vma, address, 0x4000, 0x1000); |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | static struct vm_operations_struct spufs_cntl_mmap_vmops = { |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 277 | .nopfn = spufs_cntl_mmap_nopfn, |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 278 | }; |
| 279 | |
| 280 | /* |
| 281 | * mmap support for problem state control area [0x4000 - 0x4fff]. |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 282 | */ |
| 283 | static 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 Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 288 | vma->vm_flags |= VM_IO | VM_PFNMAP; |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 289 | vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot) |
Benjamin Herrenschmidt | 23cc770 | 2006-06-23 20:57:47 +0200 | [diff] [blame] | 290 | | _PAGE_NO_CACHE | _PAGE_GUARDED); |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 291 | |
| 292 | vma->vm_ops = &spufs_cntl_mmap_vmops; |
| 293 | return 0; |
| 294 | } |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 295 | #else /* SPUFS_MMAP_4K */ |
| 296 | #define spufs_cntl_mmap NULL |
| 297 | #endif /* !SPUFS_MMAP_4K */ |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 298 | |
Arnd Bergmann | e1dbff2 | 2006-10-04 17:26:19 +0200 | [diff] [blame] | 299 | static 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 | |
| 311 | static 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 Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 320 | static 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 Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 325 | mutex_lock(&ctx->mapping_lock); |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 326 | file->private_data = ctx; |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 327 | if (!i->i_openers++) |
| 328 | ctx->cntl = inode->i_mapping; |
Christoph Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 329 | mutex_unlock(&ctx->mapping_lock); |
Arnd Bergmann | e1dbff2 | 2006-10-04 17:26:19 +0200 | [diff] [blame] | 330 | return simple_attr_open(inode, file, spufs_cntl_get, |
| 331 | spufs_cntl_set, "0x%08lx"); |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 332 | } |
| 333 | |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 334 | static int |
| 335 | spufs_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 Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 342 | mutex_lock(&ctx->mapping_lock); |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 343 | if (!--i->i_openers) |
| 344 | ctx->cntl = NULL; |
Christoph Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 345 | mutex_unlock(&ctx->mapping_lock); |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 346 | return 0; |
| 347 | } |
| 348 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 349 | static const struct file_operations spufs_cntl_fops = { |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 350 | .open = spufs_cntl_open, |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 351 | .release = spufs_cntl_release, |
Arnd Bergmann | e1dbff2 | 2006-10-04 17:26:19 +0200 | [diff] [blame] | 352 | .read = simple_attr_read, |
| 353 | .write = simple_attr_write, |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 354 | .mmap = spufs_cntl_mmap, |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 355 | }; |
| 356 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 357 | static int |
| 358 | spufs_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 | |
| 365 | static ssize_t |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 366 | __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 | |
| 374 | static ssize_t |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 375 | spufs_regs_read(struct file *file, char __user *buffer, |
| 376 | size_t size, loff_t *pos) |
| 377 | { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 378 | int ret; |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 379 | struct spu_context *ctx = file->private_data; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 380 | |
| 381 | spu_acquire_saved(ctx); |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 382 | ret = __spufs_regs_read(ctx, buffer, size, pos); |
Christoph Hellwig | 27b1ea0 | 2007-07-20 21:39:34 +0200 | [diff] [blame] | 383 | spu_release_saved(ctx); |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 384 | return ret; |
| 385 | } |
| 386 | |
| 387 | static ssize_t |
| 388 | spufs_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 Hellwig | 27b1ea0 | 2007-07-20 21:39:34 +0200 | [diff] [blame] | 405 | spu_release_saved(ctx); |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 406 | return ret; |
| 407 | } |
| 408 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 409 | static const struct file_operations spufs_regs_fops = { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 410 | .open = spufs_regs_open, |
| 411 | .read = spufs_regs_read, |
| 412 | .write = spufs_regs_write, |
| 413 | .llseek = generic_file_llseek, |
| 414 | }; |
| 415 | |
| 416 | static ssize_t |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 417 | __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 | |
| 425 | static ssize_t |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 426 | spufs_fpcr_read(struct file *file, char __user * buffer, |
| 427 | size_t size, loff_t * pos) |
| 428 | { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 429 | int ret; |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 430 | struct spu_context *ctx = file->private_data; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 431 | |
| 432 | spu_acquire_saved(ctx); |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 433 | ret = __spufs_fpcr_read(ctx, buffer, size, pos); |
Christoph Hellwig | 27b1ea0 | 2007-07-20 21:39:34 +0200 | [diff] [blame] | 434 | spu_release_saved(ctx); |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 435 | return ret; |
| 436 | } |
| 437 | |
| 438 | static ssize_t |
| 439 | spufs_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 Hellwig | 27b1ea0 | 2007-07-20 21:39:34 +0200 | [diff] [blame] | 456 | spu_release_saved(ctx); |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 457 | return ret; |
| 458 | } |
| 459 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 460 | static const struct file_operations spufs_fpcr_fops = { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 461 | .open = spufs_regs_open, |
| 462 | .read = spufs_fpcr_read, |
| 463 | .write = spufs_fpcr_write, |
| 464 | .llseek = generic_file_llseek, |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 465 | }; |
| 466 | |
| 467 | /* generic open function for all pipe-like files */ |
| 468 | static 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 Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 476 | /* |
| 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 Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 484 | static ssize_t spufs_mbox_read(struct file *file, char __user *buf, |
| 485 | size_t len, loff_t *pos) |
| 486 | { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 487 | struct spu_context *ctx = file->private_data; |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 488 | u32 mbox_data, __user *udata; |
| 489 | ssize_t count; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 490 | |
| 491 | if (len < 4) |
| 492 | return -EINVAL; |
| 493 | |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 494 | if (!access_ok(VERIFY_WRITE, buf, len)) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 495 | return -EFAULT; |
| 496 | |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 497 | udata = (void __user *)buf; |
| 498 | |
| 499 | spu_acquire(ctx); |
Arnd Bergmann | 274cef5 | 2006-10-24 18:01:42 +0200 | [diff] [blame] | 500 | for (count = 0; (count + 4) <= len; count += 4, udata++) { |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 501 | 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 Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 524 | } |
| 525 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 526 | static const struct file_operations spufs_mbox_fops = { |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 527 | .open = spufs_pipe_open, |
| 528 | .read = spufs_mbox_read, |
| 529 | }; |
| 530 | |
| 531 | static ssize_t spufs_mbox_stat_read(struct file *file, char __user *buf, |
| 532 | size_t len, loff_t *pos) |
| 533 | { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 534 | struct spu_context *ctx = file->private_data; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 535 | u32 mbox_stat; |
| 536 | |
| 537 | if (len < 4) |
| 538 | return -EINVAL; |
| 539 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 540 | spu_acquire(ctx); |
| 541 | |
| 542 | mbox_stat = ctx->ops->mbox_stat_read(ctx) & 0xff; |
| 543 | |
| 544 | spu_release(ctx); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 545 | |
| 546 | if (copy_to_user(buf, &mbox_stat, sizeof mbox_stat)) |
| 547 | return -EFAULT; |
| 548 | |
| 549 | return 4; |
| 550 | } |
| 551 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 552 | static const struct file_operations spufs_mbox_stat_fops = { |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 553 | .open = spufs_pipe_open, |
| 554 | .read = spufs_mbox_stat_read, |
| 555 | }; |
| 556 | |
| 557 | /* low-level ibox access function */ |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 558 | size_t spu_ibox_read(struct spu_context *ctx, u32 *data) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 559 | { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 560 | return ctx->ops->ibox_read(ctx, data); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 561 | } |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 562 | |
| 563 | static int spufs_ibox_fasync(int fd, struct file *file, int on) |
| 564 | { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 565 | 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. */ |
| 571 | void spufs_ibox_callback(struct spu *spu) |
| 572 | { |
| 573 | struct spu_context *ctx = spu->ctx; |
| 574 | |
Luke Browning | e65c2f6 | 2007-12-20 16:39:59 +0900 | [diff] [blame^] | 575 | if (!ctx) |
| 576 | return; |
| 577 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 578 | wake_up_all(&ctx->ibox_wq); |
| 579 | kill_fasync(&ctx->ibox_fasync, SIGIO, POLLIN); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 580 | } |
| 581 | |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 582 | /* |
| 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 Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 594 | static ssize_t spufs_ibox_read(struct file *file, char __user *buf, |
| 595 | size_t len, loff_t *pos) |
| 596 | { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 597 | struct spu_context *ctx = file->private_data; |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 598 | u32 ibox_data, __user *udata; |
| 599 | ssize_t count; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 600 | |
| 601 | if (len < 4) |
| 602 | return -EINVAL; |
| 603 | |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 604 | if (!access_ok(VERIFY_WRITE, buf, len)) |
| 605 | return -EFAULT; |
| 606 | |
| 607 | udata = (void __user *)buf; |
| 608 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 609 | spu_acquire(ctx); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 610 | |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 611 | /* wait only for the first element */ |
| 612 | count = 0; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 613 | if (file->f_flags & O_NONBLOCK) { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 614 | if (!spu_ibox_read(ctx, &ibox_data)) |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 615 | count = -EAGAIN; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 616 | } else { |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 617 | 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 Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 640 | } |
| 641 | |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 642 | out: |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 643 | spu_release(ctx); |
| 644 | |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 645 | return count; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | static unsigned int spufs_ibox_poll(struct file *file, poll_table *wait) |
| 649 | { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 650 | struct spu_context *ctx = file->private_data; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 651 | unsigned int mask; |
| 652 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 653 | poll_wait(file, &ctx->ibox_wq, wait); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 654 | |
Arnd Bergmann | 3a843d7 | 2005-12-05 22:52:27 -0500 | [diff] [blame] | 655 | spu_acquire(ctx); |
| 656 | mask = ctx->ops->mbox_stat_poll(ctx, POLLIN | POLLRDNORM); |
| 657 | spu_release(ctx); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 658 | |
| 659 | return mask; |
| 660 | } |
| 661 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 662 | static const struct file_operations spufs_ibox_fops = { |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 663 | .open = spufs_pipe_open, |
| 664 | .read = spufs_ibox_read, |
| 665 | .poll = spufs_ibox_poll, |
| 666 | .fasync = spufs_ibox_fasync, |
| 667 | }; |
| 668 | |
| 669 | static ssize_t spufs_ibox_stat_read(struct file *file, char __user *buf, |
| 670 | size_t len, loff_t *pos) |
| 671 | { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 672 | struct spu_context *ctx = file->private_data; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 673 | u32 ibox_stat; |
| 674 | |
| 675 | if (len < 4) |
| 676 | return -EINVAL; |
| 677 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 678 | spu_acquire(ctx); |
| 679 | ibox_stat = (ctx->ops->mbox_stat_read(ctx) >> 16) & 0xff; |
| 680 | spu_release(ctx); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 681 | |
| 682 | if (copy_to_user(buf, &ibox_stat, sizeof ibox_stat)) |
| 683 | return -EFAULT; |
| 684 | |
| 685 | return 4; |
| 686 | } |
| 687 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 688 | static const struct file_operations spufs_ibox_stat_fops = { |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 689 | .open = spufs_pipe_open, |
| 690 | .read = spufs_ibox_stat_read, |
| 691 | }; |
| 692 | |
| 693 | /* low-level mailbox write */ |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 694 | size_t spu_wbox_write(struct spu_context *ctx, u32 data) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 695 | { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 696 | return ctx->ops->wbox_write(ctx, data); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 697 | } |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 698 | |
| 699 | static int spufs_wbox_fasync(int fd, struct file *file, int on) |
| 700 | { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 701 | 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. */ |
| 710 | void spufs_wbox_callback(struct spu *spu) |
| 711 | { |
| 712 | struct spu_context *ctx = spu->ctx; |
| 713 | |
Luke Browning | e65c2f6 | 2007-12-20 16:39:59 +0900 | [diff] [blame^] | 714 | if (!ctx) |
| 715 | return; |
| 716 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 717 | wake_up_all(&ctx->wbox_wq); |
| 718 | kill_fasync(&ctx->wbox_fasync, SIGIO, POLLOUT); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 719 | } |
| 720 | |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 721 | /* |
| 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 Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 733 | static ssize_t spufs_wbox_write(struct file *file, const char __user *buf, |
| 734 | size_t len, loff_t *pos) |
| 735 | { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 736 | struct spu_context *ctx = file->private_data; |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 737 | u32 wbox_data, __user *udata; |
| 738 | ssize_t count; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 739 | |
| 740 | if (len < 4) |
| 741 | return -EINVAL; |
| 742 | |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 743 | udata = (void __user *)buf; |
| 744 | if (!access_ok(VERIFY_READ, buf, len)) |
| 745 | return -EFAULT; |
| 746 | |
| 747 | if (__get_user(wbox_data, udata)) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 748 | return -EFAULT; |
| 749 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 750 | spu_acquire(ctx); |
| 751 | |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 752 | /* |
| 753 | * make sure we can at least write one element, by waiting |
| 754 | * in case of !O_NONBLOCK |
| 755 | */ |
| 756 | count = 0; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 757 | if (file->f_flags & O_NONBLOCK) { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 758 | if (!spu_wbox_write(ctx, wbox_data)) |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 759 | count = -EAGAIN; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 760 | } else { |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 761 | count = spufs_wait(ctx->wbox_wq, spu_wbox_write(ctx, wbox_data)); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 762 | } |
| 763 | |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 764 | if (count) |
| 765 | goto out; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 766 | |
Jan Engelhardt | 96de0e2 | 2007-10-19 23:21:04 +0200 | [diff] [blame] | 767 | /* write as much as possible */ |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 768 | 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 | |
| 779 | out: |
| 780 | spu_release(ctx); |
| 781 | return count; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | static unsigned int spufs_wbox_poll(struct file *file, poll_table *wait) |
| 785 | { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 786 | struct spu_context *ctx = file->private_data; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 787 | unsigned int mask; |
| 788 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 789 | poll_wait(file, &ctx->wbox_wq, wait); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 790 | |
Arnd Bergmann | 3a843d7 | 2005-12-05 22:52:27 -0500 | [diff] [blame] | 791 | spu_acquire(ctx); |
| 792 | mask = ctx->ops->mbox_stat_poll(ctx, POLLOUT | POLLWRNORM); |
| 793 | spu_release(ctx); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 794 | |
| 795 | return mask; |
| 796 | } |
| 797 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 798 | static const struct file_operations spufs_wbox_fops = { |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 799 | .open = spufs_pipe_open, |
| 800 | .write = spufs_wbox_write, |
| 801 | .poll = spufs_wbox_poll, |
| 802 | .fasync = spufs_wbox_fasync, |
| 803 | }; |
| 804 | |
| 805 | static ssize_t spufs_wbox_stat_read(struct file *file, char __user *buf, |
| 806 | size_t len, loff_t *pos) |
| 807 | { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 808 | struct spu_context *ctx = file->private_data; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 809 | u32 wbox_stat; |
| 810 | |
| 811 | if (len < 4) |
| 812 | return -EINVAL; |
| 813 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 814 | spu_acquire(ctx); |
| 815 | wbox_stat = (ctx->ops->mbox_stat_read(ctx) >> 8) & 0xff; |
| 816 | spu_release(ctx); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 817 | |
| 818 | if (copy_to_user(buf, &wbox_stat, sizeof wbox_stat)) |
| 819 | return -EFAULT; |
| 820 | |
| 821 | return 4; |
| 822 | } |
| 823 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 824 | static const struct file_operations spufs_wbox_stat_fops = { |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 825 | .open = spufs_pipe_open, |
| 826 | .read = spufs_wbox_stat_read, |
| 827 | }; |
| 828 | |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 829 | static 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 Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 833 | |
Christoph Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 834 | mutex_lock(&ctx->mapping_lock); |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 835 | file->private_data = ctx; |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 836 | if (!i->i_openers++) |
| 837 | ctx->signal1 = inode->i_mapping; |
Christoph Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 838 | mutex_unlock(&ctx->mapping_lock); |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 839 | return nonseekable_open(inode, file); |
| 840 | } |
| 841 | |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 842 | static int |
| 843 | spufs_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 Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 848 | mutex_lock(&ctx->mapping_lock); |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 849 | if (!--i->i_openers) |
| 850 | ctx->signal1 = NULL; |
Christoph Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 851 | mutex_unlock(&ctx->mapping_lock); |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 852 | return 0; |
| 853 | } |
| 854 | |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 855 | static ssize_t __spufs_signal1_read(struct spu_context *ctx, char __user *buf, |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 856 | size_t len, loff_t *pos) |
| 857 | { |
Dwayne Grant McConnell | 17f88ce | 2006-11-20 18:45:01 +0100 | [diff] [blame] | 858 | int ret = 0; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 859 | u32 data; |
| 860 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 861 | if (len < 4) |
| 862 | return -EINVAL; |
| 863 | |
Dwayne Grant McConnell | 17f88ce | 2006-11-20 18:45:01 +0100 | [diff] [blame] | 864 | if (ctx->csa.spu_chnlcnt_RW[3]) { |
| 865 | data = ctx->csa.spu_chnldata_RW[3]; |
| 866 | ret = 4; |
| 867 | } |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 868 | |
Dwayne Grant McConnell | 17f88ce | 2006-11-20 18:45:01 +0100 | [diff] [blame] | 869 | if (!ret) |
| 870 | goto out; |
| 871 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 872 | if (copy_to_user(buf, &data, 4)) |
| 873 | return -EFAULT; |
| 874 | |
Dwayne Grant McConnell | 17f88ce | 2006-11-20 18:45:01 +0100 | [diff] [blame] | 875 | out: |
| 876 | return ret; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 877 | } |
| 878 | |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 879 | static 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 Hellwig | 27b1ea0 | 2007-07-20 21:39:34 +0200 | [diff] [blame] | 887 | spu_release_saved(ctx); |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 888 | |
| 889 | return ret; |
| 890 | } |
| 891 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 892 | static 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 Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 896 | u32 data; |
| 897 | |
| 898 | ctx = file->private_data; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 899 | |
| 900 | if (len < 4) |
| 901 | return -EINVAL; |
| 902 | |
| 903 | if (copy_from_user(&data, buf, 4)) |
| 904 | return -EFAULT; |
| 905 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 906 | spu_acquire(ctx); |
| 907 | ctx->ops->signal1_write(ctx, data); |
| 908 | spu_release(ctx); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 909 | |
| 910 | return 4; |
| 911 | } |
| 912 | |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 913 | static unsigned long spufs_signal1_mmap_nopfn(struct vm_area_struct *vma, |
| 914 | unsigned long address) |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 915 | { |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 916 | #if PAGE_SIZE == 0x1000 |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 917 | return spufs_ps_nopfn(vma, address, 0x14000, 0x1000); |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 918 | #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 Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 922 | return spufs_ps_nopfn(vma, address, 0x10000, 0x10000); |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 923 | #else |
| 924 | #error unsupported page size |
| 925 | #endif |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 926 | } |
| 927 | |
| 928 | static struct vm_operations_struct spufs_signal1_mmap_vmops = { |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 929 | .nopfn = spufs_signal1_mmap_nopfn, |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 930 | }; |
| 931 | |
| 932 | static 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 Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 937 | vma->vm_flags |= VM_IO | VM_PFNMAP; |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 938 | vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot) |
Benjamin Herrenschmidt | 23cc770 | 2006-06-23 20:57:47 +0200 | [diff] [blame] | 939 | | _PAGE_NO_CACHE | _PAGE_GUARDED); |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 940 | |
| 941 | vma->vm_ops = &spufs_signal1_mmap_vmops; |
| 942 | return 0; |
| 943 | } |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 944 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 945 | static const struct file_operations spufs_signal1_fops = { |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 946 | .open = spufs_signal1_open, |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 947 | .release = spufs_signal1_release, |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 948 | .read = spufs_signal1_read, |
| 949 | .write = spufs_signal1_write, |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 950 | .mmap = spufs_signal1_mmap, |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 951 | }; |
| 952 | |
Jeremy Kerr | d054b36 | 2007-07-20 21:39:31 +0200 | [diff] [blame] | 953 | static 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 Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 960 | static 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 Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 964 | |
Christoph Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 965 | mutex_lock(&ctx->mapping_lock); |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 966 | file->private_data = ctx; |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 967 | if (!i->i_openers++) |
| 968 | ctx->signal2 = inode->i_mapping; |
Christoph Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 969 | mutex_unlock(&ctx->mapping_lock); |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 970 | return nonseekable_open(inode, file); |
| 971 | } |
| 972 | |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 973 | static int |
| 974 | spufs_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 Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 979 | mutex_lock(&ctx->mapping_lock); |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 980 | if (!--i->i_openers) |
| 981 | ctx->signal2 = NULL; |
Christoph Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 982 | mutex_unlock(&ctx->mapping_lock); |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 983 | return 0; |
| 984 | } |
| 985 | |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 986 | static ssize_t __spufs_signal2_read(struct spu_context *ctx, char __user *buf, |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 987 | size_t len, loff_t *pos) |
| 988 | { |
Dwayne Grant McConnell | 17f88ce | 2006-11-20 18:45:01 +0100 | [diff] [blame] | 989 | int ret = 0; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 990 | u32 data; |
| 991 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 992 | if (len < 4) |
| 993 | return -EINVAL; |
| 994 | |
Dwayne Grant McConnell | 17f88ce | 2006-11-20 18:45:01 +0100 | [diff] [blame] | 995 | if (ctx->csa.spu_chnlcnt_RW[4]) { |
| 996 | data = ctx->csa.spu_chnldata_RW[4]; |
| 997 | ret = 4; |
| 998 | } |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 999 | |
Dwayne Grant McConnell | 17f88ce | 2006-11-20 18:45:01 +0100 | [diff] [blame] | 1000 | if (!ret) |
| 1001 | goto out; |
| 1002 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1003 | if (copy_to_user(buf, &data, 4)) |
| 1004 | return -EFAULT; |
| 1005 | |
Dwayne Grant McConnell | 17f88ce | 2006-11-20 18:45:01 +0100 | [diff] [blame] | 1006 | out: |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1007 | return ret; |
| 1008 | } |
| 1009 | |
| 1010 | static 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 Hellwig | 27b1ea0 | 2007-07-20 21:39:34 +0200 | [diff] [blame] | 1018 | spu_release_saved(ctx); |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1019 | |
| 1020 | return ret; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1021 | } |
| 1022 | |
| 1023 | static 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 Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1027 | u32 data; |
| 1028 | |
| 1029 | ctx = file->private_data; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1030 | |
| 1031 | if (len < 4) |
| 1032 | return -EINVAL; |
| 1033 | |
| 1034 | if (copy_from_user(&data, buf, 4)) |
| 1035 | return -EFAULT; |
| 1036 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1037 | spu_acquire(ctx); |
| 1038 | ctx->ops->signal2_write(ctx, data); |
| 1039 | spu_release(ctx); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1040 | |
| 1041 | return 4; |
| 1042 | } |
| 1043 | |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 1044 | #if SPUFS_MMAP_4K |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 1045 | static unsigned long spufs_signal2_mmap_nopfn(struct vm_area_struct *vma, |
| 1046 | unsigned long address) |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 1047 | { |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 1048 | #if PAGE_SIZE == 0x1000 |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 1049 | return spufs_ps_nopfn(vma, address, 0x1c000, 0x1000); |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 1050 | #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 Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 1054 | return spufs_ps_nopfn(vma, address, 0x10000, 0x10000); |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 1055 | #else |
| 1056 | #error unsupported page size |
| 1057 | #endif |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 1058 | } |
| 1059 | |
| 1060 | static struct vm_operations_struct spufs_signal2_mmap_vmops = { |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 1061 | .nopfn = spufs_signal2_mmap_nopfn, |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 1062 | }; |
| 1063 | |
| 1064 | static 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 Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 1069 | vma->vm_flags |= VM_IO | VM_PFNMAP; |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 1070 | vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot) |
Benjamin Herrenschmidt | 23cc770 | 2006-06-23 20:57:47 +0200 | [diff] [blame] | 1071 | | _PAGE_NO_CACHE | _PAGE_GUARDED); |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 1072 | |
| 1073 | vma->vm_ops = &spufs_signal2_mmap_vmops; |
| 1074 | return 0; |
| 1075 | } |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 1076 | #else /* SPUFS_MMAP_4K */ |
| 1077 | #define spufs_signal2_mmap NULL |
| 1078 | #endif /* !SPUFS_MMAP_4K */ |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 1079 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 1080 | static const struct file_operations spufs_signal2_fops = { |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 1081 | .open = spufs_signal2_open, |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 1082 | .release = spufs_signal2_release, |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1083 | .read = spufs_signal2_read, |
| 1084 | .write = spufs_signal2_write, |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 1085 | .mmap = spufs_signal2_mmap, |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1086 | }; |
| 1087 | |
Jeremy Kerr | d054b36 | 2007-07-20 21:39:31 +0200 | [diff] [blame] | 1088 | static 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 Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 1095 | /* |
| 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) \ |
| 1105 | static 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 | } \ |
| 1123 | DEFINE_SIMPLE_ATTRIBUTE(__name, __##__get, __set, __fmt); |
| 1124 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1125 | static void spufs_signal1_type_set(void *data, u64 val) |
| 1126 | { |
| 1127 | struct spu_context *ctx = data; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1128 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1129 | spu_acquire(ctx); |
| 1130 | ctx->ops->signal1_type_set(ctx, val); |
| 1131 | spu_release(ctx); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1132 | } |
| 1133 | |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 1134 | static u64 spufs_signal1_type_get(struct spu_context *ctx) |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1135 | { |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1136 | return ctx->ops->signal1_type_get(ctx); |
| 1137 | } |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 1138 | DEFINE_SPUFS_ATTRIBUTE(spufs_signal1_type, spufs_signal1_type_get, |
| 1139 | spufs_signal1_type_set, "%llu", SPU_ATTR_ACQUIRE); |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1140 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1141 | |
| 1142 | static void spufs_signal2_type_set(void *data, u64 val) |
| 1143 | { |
| 1144 | struct spu_context *ctx = data; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1145 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1146 | spu_acquire(ctx); |
| 1147 | ctx->ops->signal2_type_set(ctx, val); |
| 1148 | spu_release(ctx); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1149 | } |
| 1150 | |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 1151 | static u64 spufs_signal2_type_get(struct spu_context *ctx) |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1152 | { |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1153 | return ctx->ops->signal2_type_get(ctx); |
| 1154 | } |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 1155 | DEFINE_SPUFS_ATTRIBUTE(spufs_signal2_type, spufs_signal2_type_get, |
| 1156 | spufs_signal2_type_set, "%llu", SPU_ATTR_ACQUIRE); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1157 | |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 1158 | #if SPUFS_MMAP_4K |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 1159 | static unsigned long spufs_mss_mmap_nopfn(struct vm_area_struct *vma, |
| 1160 | unsigned long address) |
arnd@arndb.de | d9379c4 | 2006-06-19 20:33:21 +0200 | [diff] [blame] | 1161 | { |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 1162 | return spufs_ps_nopfn(vma, address, 0x0000, 0x1000); |
arnd@arndb.de | d9379c4 | 2006-06-19 20:33:21 +0200 | [diff] [blame] | 1163 | } |
| 1164 | |
| 1165 | static struct vm_operations_struct spufs_mss_mmap_vmops = { |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 1166 | .nopfn = spufs_mss_mmap_nopfn, |
arnd@arndb.de | d9379c4 | 2006-06-19 20:33:21 +0200 | [diff] [blame] | 1167 | }; |
| 1168 | |
| 1169 | /* |
| 1170 | * mmap support for problem state MFC DMA area [0x0000 - 0x0fff]. |
arnd@arndb.de | d9379c4 | 2006-06-19 20:33:21 +0200 | [diff] [blame] | 1171 | */ |
| 1172 | static 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 Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 1177 | vma->vm_flags |= VM_IO | VM_PFNMAP; |
arnd@arndb.de | d9379c4 | 2006-06-19 20:33:21 +0200 | [diff] [blame] | 1178 | vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot) |
Benjamin Herrenschmidt | 23cc770 | 2006-06-23 20:57:47 +0200 | [diff] [blame] | 1179 | | _PAGE_NO_CACHE | _PAGE_GUARDED); |
arnd@arndb.de | d9379c4 | 2006-06-19 20:33:21 +0200 | [diff] [blame] | 1180 | |
| 1181 | vma->vm_ops = &spufs_mss_mmap_vmops; |
| 1182 | return 0; |
| 1183 | } |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 1184 | #else /* SPUFS_MMAP_4K */ |
| 1185 | #define spufs_mss_mmap NULL |
| 1186 | #endif /* !SPUFS_MMAP_4K */ |
arnd@arndb.de | d9379c4 | 2006-06-19 20:33:21 +0200 | [diff] [blame] | 1187 | |
| 1188 | static int spufs_mss_open(struct inode *inode, struct file *file) |
| 1189 | { |
| 1190 | struct spufs_inode_info *i = SPUFS_I(inode); |
Benjamin Herrenschmidt | 17e0e27 | 2007-02-13 11:46:08 +1100 | [diff] [blame] | 1191 | struct spu_context *ctx = i->i_ctx; |
arnd@arndb.de | d9379c4 | 2006-06-19 20:33:21 +0200 | [diff] [blame] | 1192 | |
| 1193 | file->private_data = i->i_ctx; |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 1194 | |
Christoph Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 1195 | mutex_lock(&ctx->mapping_lock); |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 1196 | if (!i->i_openers++) |
| 1197 | ctx->mss = inode->i_mapping; |
Christoph Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 1198 | mutex_unlock(&ctx->mapping_lock); |
arnd@arndb.de | d9379c4 | 2006-06-19 20:33:21 +0200 | [diff] [blame] | 1199 | return nonseekable_open(inode, file); |
| 1200 | } |
| 1201 | |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 1202 | static int |
| 1203 | spufs_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 Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 1208 | mutex_lock(&ctx->mapping_lock); |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 1209 | if (!--i->i_openers) |
| 1210 | ctx->mss = NULL; |
Christoph Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 1211 | mutex_unlock(&ctx->mapping_lock); |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 1212 | return 0; |
| 1213 | } |
| 1214 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 1215 | static const struct file_operations spufs_mss_fops = { |
arnd@arndb.de | d9379c4 | 2006-06-19 20:33:21 +0200 | [diff] [blame] | 1216 | .open = spufs_mss_open, |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 1217 | .release = spufs_mss_release, |
arnd@arndb.de | d9379c4 | 2006-06-19 20:33:21 +0200 | [diff] [blame] | 1218 | .mmap = spufs_mss_mmap, |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 1219 | }; |
| 1220 | |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 1221 | static unsigned long spufs_psmap_mmap_nopfn(struct vm_area_struct *vma, |
| 1222 | unsigned long address) |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 1223 | { |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 1224 | return spufs_ps_nopfn(vma, address, 0x0000, 0x20000); |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 1225 | } |
| 1226 | |
| 1227 | static struct vm_operations_struct spufs_psmap_mmap_vmops = { |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 1228 | .nopfn = spufs_psmap_mmap_nopfn, |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 1229 | }; |
| 1230 | |
| 1231 | /* |
| 1232 | * mmap support for full problem state area [0x00000 - 0x1ffff]. |
| 1233 | */ |
| 1234 | static 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 Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 1239 | vma->vm_flags |= VM_IO | VM_PFNMAP; |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 1240 | 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 | |
| 1247 | static int spufs_psmap_open(struct inode *inode, struct file *file) |
| 1248 | { |
| 1249 | struct spufs_inode_info *i = SPUFS_I(inode); |
Benjamin Herrenschmidt | 17e0e27 | 2007-02-13 11:46:08 +1100 | [diff] [blame] | 1250 | struct spu_context *ctx = i->i_ctx; |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 1251 | |
Christoph Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 1252 | mutex_lock(&ctx->mapping_lock); |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 1253 | file->private_data = i->i_ctx; |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 1254 | if (!i->i_openers++) |
| 1255 | ctx->psmap = inode->i_mapping; |
Christoph Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 1256 | mutex_unlock(&ctx->mapping_lock); |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 1257 | return nonseekable_open(inode, file); |
| 1258 | } |
| 1259 | |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 1260 | static int |
| 1261 | spufs_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 Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 1266 | mutex_lock(&ctx->mapping_lock); |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 1267 | if (!--i->i_openers) |
| 1268 | ctx->psmap = NULL; |
Christoph Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 1269 | mutex_unlock(&ctx->mapping_lock); |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 1270 | return 0; |
| 1271 | } |
| 1272 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 1273 | static const struct file_operations spufs_psmap_fops = { |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 1274 | .open = spufs_psmap_open, |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 1275 | .release = spufs_psmap_release, |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 1276 | .mmap = spufs_psmap_mmap, |
arnd@arndb.de | d9379c4 | 2006-06-19 20:33:21 +0200 | [diff] [blame] | 1277 | }; |
| 1278 | |
| 1279 | |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 1280 | #if SPUFS_MMAP_4K |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 1281 | static unsigned long spufs_mfc_mmap_nopfn(struct vm_area_struct *vma, |
| 1282 | unsigned long address) |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 1283 | { |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 1284 | return spufs_ps_nopfn(vma, address, 0x3000, 0x1000); |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 1285 | } |
| 1286 | |
| 1287 | static struct vm_operations_struct spufs_mfc_mmap_vmops = { |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 1288 | .nopfn = spufs_mfc_mmap_nopfn, |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 1289 | }; |
| 1290 | |
| 1291 | /* |
| 1292 | * mmap support for problem state MFC DMA area [0x0000 - 0x0fff]. |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 1293 | */ |
| 1294 | static 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 Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 1299 | vma->vm_flags |= VM_IO | VM_PFNMAP; |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 1300 | vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot) |
Benjamin Herrenschmidt | 23cc770 | 2006-06-23 20:57:47 +0200 | [diff] [blame] | 1301 | | _PAGE_NO_CACHE | _PAGE_GUARDED); |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 1302 | |
| 1303 | vma->vm_ops = &spufs_mfc_mmap_vmops; |
| 1304 | return 0; |
| 1305 | } |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 1306 | #else /* SPUFS_MMAP_4K */ |
| 1307 | #define spufs_mfc_mmap NULL |
| 1308 | #endif /* !SPUFS_MMAP_4K */ |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 1309 | |
| 1310 | static 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 Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 1322 | mutex_lock(&ctx->mapping_lock); |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 1323 | file->private_data = ctx; |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 1324 | if (!i->i_openers++) |
| 1325 | ctx->mfc = inode->i_mapping; |
Christoph Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 1326 | mutex_unlock(&ctx->mapping_lock); |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 1327 | return nonseekable_open(inode, file); |
| 1328 | } |
| 1329 | |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 1330 | static int |
| 1331 | spufs_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 Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 1336 | mutex_lock(&ctx->mapping_lock); |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 1337 | if (!--i->i_openers) |
| 1338 | ctx->mfc = NULL; |
Christoph Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 1339 | mutex_unlock(&ctx->mapping_lock); |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 1340 | return 0; |
| 1341 | } |
| 1342 | |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 1343 | /* interrupt-level mfc callback function. */ |
| 1344 | void spufs_mfc_callback(struct spu *spu) |
| 1345 | { |
| 1346 | struct spu_context *ctx = spu->ctx; |
| 1347 | |
Luke Browning | e65c2f6 | 2007-12-20 16:39:59 +0900 | [diff] [blame^] | 1348 | if (!ctx) |
| 1349 | return; |
| 1350 | |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 1351 | 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 | |
| 1372 | static 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 | |
| 1387 | static 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 | |
| 1417 | out: |
| 1418 | return ret; |
| 1419 | } |
| 1420 | |
| 1421 | static 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 | |
| 1491 | static 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 | |
| 1509 | static 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 Bergmann | 33bfd7a | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1527 | spu_acquire(ctx); |
| 1528 | ret = spufs_wait(ctx->run_wq, ctx->state == SPU_STATE_RUNNABLE); |
Akinobu Mita | 577f8f1 | 2007-04-23 21:08:18 +0200 | [diff] [blame] | 1529 | if (ret) |
| 1530 | goto out; |
| 1531 | |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 1532 | 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 Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 1541 | |
| 1542 | if (ret) |
Kazunori Asayama | 933b0e3 | 2007-06-29 10:58:08 +1000 | [diff] [blame] | 1543 | goto out_unlock; |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 1544 | |
| 1545 | ctx->tagwait |= 1 << cmd.tag; |
Masato Noguchi | 3692dc6 | 2006-11-20 18:45:07 +0100 | [diff] [blame] | 1546 | ret = size; |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 1547 | |
Kazunori Asayama | 933b0e3 | 2007-06-29 10:58:08 +1000 | [diff] [blame] | 1548 | out_unlock: |
| 1549 | spu_release(ctx); |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 1550 | out: |
| 1551 | return ret; |
| 1552 | } |
| 1553 | |
| 1554 | static 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 Asayama | 933b0e3 | 2007-06-29 10:58:08 +1000 | [diff] [blame] | 1560 | poll_wait(file, &ctx->mfc_wq, wait); |
| 1561 | |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 1562 | 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 Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 1568 | 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 Viro | 73b6af8 | 2006-06-25 16:42:33 -0700 | [diff] [blame] | 1580 | static int spufs_mfc_flush(struct file *file, fl_owner_t id) |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 1581 | { |
| 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); |
| 1594 | out: |
| 1595 | #else |
| 1596 | ret = 0; |
| 1597 | #endif |
| 1598 | spu_release(ctx); |
| 1599 | |
| 1600 | return ret; |
| 1601 | } |
| 1602 | |
| 1603 | static int spufs_mfc_fsync(struct file *file, struct dentry *dentry, |
| 1604 | int datasync) |
| 1605 | { |
Al Viro | 73b6af8 | 2006-06-25 16:42:33 -0700 | [diff] [blame] | 1606 | return spufs_mfc_flush(file, NULL); |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 1607 | } |
| 1608 | |
| 1609 | static 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 Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 1616 | static const struct file_operations spufs_mfc_fops = { |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 1617 | .open = spufs_mfc_open, |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 1618 | .release = spufs_mfc_release, |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 1619 | .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 Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 1625 | .mmap = spufs_mfc_mmap, |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 1626 | }; |
| 1627 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1628 | static void spufs_npc_set(void *data, u64 val) |
| 1629 | { |
| 1630 | struct spu_context *ctx = data; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1631 | spu_acquire(ctx); |
| 1632 | ctx->ops->npc_write(ctx, val); |
| 1633 | spu_release(ctx); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1634 | } |
| 1635 | |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 1636 | static u64 spufs_npc_get(struct spu_context *ctx) |
Michael Ellerman | 78810ff | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 1637 | { |
| 1638 | return ctx->ops->npc_read(ctx); |
| 1639 | } |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 1640 | DEFINE_SPUFS_ATTRIBUTE(spufs_npc_ops, spufs_npc_get, spufs_npc_set, |
| 1641 | "0x%llx\n", SPU_ATTR_ACQUIRE); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1642 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1643 | static 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 Hellwig | 27b1ea0 | 2007-07-20 21:39:34 +0200 | [diff] [blame] | 1649 | spu_release_saved(ctx); |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1650 | } |
| 1651 | |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 1652 | static u64 spufs_decr_get(struct spu_context *ctx) |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1653 | { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1654 | struct spu_lscsa *lscsa = ctx->csa.lscsa; |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1655 | return lscsa->decr.slot[0]; |
| 1656 | } |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 1657 | DEFINE_SPUFS_ATTRIBUTE(spufs_decr_ops, spufs_decr_get, spufs_decr_set, |
| 1658 | "0x%llx\n", SPU_ATTR_ACQUIRE_SAVED); |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1659 | |
| 1660 | static void spufs_decr_status_set(void *data, u64 val) |
| 1661 | { |
| 1662 | struct spu_context *ctx = data; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1663 | spu_acquire_saved(ctx); |
Masato Noguchi | d40a01d | 2007-07-20 21:39:38 +0200 | [diff] [blame] | 1664 | 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 Hellwig | 27b1ea0 | 2007-07-20 21:39:34 +0200 | [diff] [blame] | 1668 | spu_release_saved(ctx); |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1669 | } |
| 1670 | |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 1671 | static u64 spufs_decr_status_get(struct spu_context *ctx) |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1672 | { |
Masato Noguchi | d40a01d | 2007-07-20 21:39:38 +0200 | [diff] [blame] | 1673 | if (ctx->csa.priv2.mfc_control_RW & MFC_CNTL_DECREMENTER_RUNNING) |
| 1674 | return SPU_DECR_STATUS_RUNNING; |
| 1675 | else |
| 1676 | return 0; |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1677 | } |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 1678 | DEFINE_SPUFS_ATTRIBUTE(spufs_decr_status_ops, spufs_decr_status_get, |
| 1679 | spufs_decr_status_set, "0x%llx\n", |
| 1680 | SPU_ATTR_ACQUIRE_SAVED); |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1681 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1682 | static 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 Hellwig | 27b1ea0 | 2007-07-20 21:39:34 +0200 | [diff] [blame] | 1688 | spu_release_saved(ctx); |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1689 | } |
| 1690 | |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 1691 | static u64 spufs_event_mask_get(struct spu_context *ctx) |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1692 | { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1693 | struct spu_lscsa *lscsa = ctx->csa.lscsa; |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1694 | return lscsa->event_mask.slot[0]; |
| 1695 | } |
| 1696 | |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 1697 | DEFINE_SPUFS_ATTRIBUTE(spufs_event_mask_ops, spufs_event_mask_get, |
| 1698 | spufs_event_mask_set, "0x%llx\n", |
| 1699 | SPU_ATTR_ACQUIRE_SAVED); |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1700 | |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 1701 | static u64 spufs_event_status_get(struct spu_context *ctx) |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 1702 | { |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 1703 | struct spu_state *state = &ctx->csa; |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 1704 | u64 stat; |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 1705 | stat = state->spu_chnlcnt_RW[0]; |
| 1706 | if (stat) |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1707 | return state->spu_chnldata_RW[0]; |
| 1708 | return 0; |
| 1709 | } |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 1710 | DEFINE_SPUFS_ATTRIBUTE(spufs_event_status_ops, spufs_event_status_get, |
| 1711 | NULL, "0x%llx\n", SPU_ATTR_ACQUIRE_SAVED) |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 1712 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1713 | static 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 Hellwig | 27b1ea0 | 2007-07-20 21:39:34 +0200 | [diff] [blame] | 1719 | spu_release_saved(ctx); |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1720 | } |
| 1721 | |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 1722 | static u64 spufs_srr0_get(struct spu_context *ctx) |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1723 | { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1724 | struct spu_lscsa *lscsa = ctx->csa.lscsa; |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 1725 | return lscsa->srr0.slot[0]; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1726 | } |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 1727 | DEFINE_SPUFS_ATTRIBUTE(spufs_srr0_ops, spufs_srr0_get, spufs_srr0_set, |
| 1728 | "0x%llx\n", SPU_ATTR_ACQUIRE_SAVED) |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1729 | |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 1730 | static u64 spufs_id_get(struct spu_context *ctx) |
arnd@arndb.de | 7b1a701 | 2006-06-19 20:33:24 +0200 | [diff] [blame] | 1731 | { |
arnd@arndb.de | 7b1a701 | 2006-06-19 20:33:24 +0200 | [diff] [blame] | 1732 | u64 num; |
| 1733 | |
arnd@arndb.de | 7b1a701 | 2006-06-19 20:33:24 +0200 | [diff] [blame] | 1734 | if (ctx->state == SPU_STATE_RUNNABLE) |
| 1735 | num = ctx->spu->number; |
| 1736 | else |
| 1737 | num = (unsigned int)-1; |
arnd@arndb.de | 7b1a701 | 2006-06-19 20:33:24 +0200 | [diff] [blame] | 1738 | |
| 1739 | return num; |
| 1740 | } |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 1741 | DEFINE_SPUFS_ATTRIBUTE(spufs_id_ops, spufs_id_get, NULL, "0x%llx\n", |
| 1742 | SPU_ATTR_ACQUIRE) |
arnd@arndb.de | 7b1a701 | 2006-06-19 20:33:24 +0200 | [diff] [blame] | 1743 | |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 1744 | static u64 spufs_object_id_get(struct spu_context *ctx) |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1745 | { |
| 1746 | /* FIXME: Should there really be no locking here? */ |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 1747 | return ctx->object_id; |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1748 | } |
| 1749 | |
Arnd Bergmann | 8676727 | 2006-10-04 17:26:21 +0200 | [diff] [blame] | 1750 | static void spufs_object_id_set(void *data, u64 id) |
| 1751 | { |
| 1752 | struct spu_context *ctx = data; |
| 1753 | ctx->object_id = id; |
| 1754 | } |
| 1755 | |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 1756 | DEFINE_SPUFS_ATTRIBUTE(spufs_object_id_ops, spufs_object_id_get, |
| 1757 | spufs_object_id_set, "0x%llx\n", SPU_ATTR_NOACQUIRE); |
Arnd Bergmann | 8676727 | 2006-10-04 17:26:21 +0200 | [diff] [blame] | 1758 | |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 1759 | static u64 spufs_lslr_get(struct spu_context *ctx) |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1760 | { |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1761 | return ctx->csa.priv2.spu_lslr_RW; |
| 1762 | } |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 1763 | DEFINE_SPUFS_ATTRIBUTE(spufs_lslr_ops, spufs_lslr_get, NULL, "0x%llx\n", |
| 1764 | SPU_ATTR_ACQUIRE_SAVED); |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 1765 | |
| 1766 | static 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 Herrenschmidt | cbe709c | 2007-06-04 15:15:38 +1000 | [diff] [blame] | 1774 | static 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 | |
| 1785 | static 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 | |
| 1790 | static 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 McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1797 | static 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 McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 1811 | static ssize_t spufs_mbox_info_read(struct file *file, char __user *buf, |
| 1812 | size_t len, loff_t *pos) |
| 1813 | { |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1814 | int ret; |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 1815 | struct spu_context *ctx = file->private_data; |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 1816 | |
| 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 McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1822 | ret = __spufs_mbox_info_read(ctx, buf, len, pos); |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 1823 | spin_unlock(&ctx->csa.register_lock); |
Christoph Hellwig | 27b1ea0 | 2007-07-20 21:39:34 +0200 | [diff] [blame] | 1824 | spu_release_saved(ctx); |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 1825 | |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1826 | return ret; |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 1827 | } |
| 1828 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 1829 | static const struct file_operations spufs_mbox_info_fops = { |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 1830 | .open = spufs_info_open, |
| 1831 | .read = spufs_mbox_info_read, |
| 1832 | .llseek = generic_file_llseek, |
| 1833 | }; |
| 1834 | |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1835 | static 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 McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 1849 | static 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 McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1853 | int ret; |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 1854 | |
| 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 McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1860 | ret = __spufs_ibox_info_read(ctx, buf, len, pos); |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 1861 | spin_unlock(&ctx->csa.register_lock); |
Christoph Hellwig | 27b1ea0 | 2007-07-20 21:39:34 +0200 | [diff] [blame] | 1862 | spu_release_saved(ctx); |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 1863 | |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1864 | return ret; |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 1865 | } |
| 1866 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 1867 | static const struct file_operations spufs_ibox_info_fops = { |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 1868 | .open = spufs_info_open, |
| 1869 | .read = spufs_ibox_info_read, |
| 1870 | .llseek = generic_file_llseek, |
| 1871 | }; |
| 1872 | |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1873 | static 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 McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 1890 | static 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 McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1894 | int ret; |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 1895 | |
| 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 McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1901 | ret = __spufs_wbox_info_read(ctx, buf, len, pos); |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 1902 | spin_unlock(&ctx->csa.register_lock); |
Christoph Hellwig | 27b1ea0 | 2007-07-20 21:39:34 +0200 | [diff] [blame] | 1903 | spu_release_saved(ctx); |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 1904 | |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1905 | return ret; |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 1906 | } |
| 1907 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 1908 | static const struct file_operations spufs_wbox_info_fops = { |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 1909 | .open = spufs_info_open, |
| 1910 | .read = spufs_wbox_info_read, |
| 1911 | .llseek = generic_file_llseek, |
| 1912 | }; |
| 1913 | |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1914 | static ssize_t __spufs_dma_info_read(struct spu_context *ctx, |
| 1915 | char __user *buf, size_t len, loff_t *pos) |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 1916 | { |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 1917 | struct spu_dma_info info; |
| 1918 | struct mfc_cq_sr *qp, *spuqp; |
| 1919 | int i; |
| 1920 | |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 1921 | 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 McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 1935 | |
| 1936 | return simple_read_from_buffer(buf, len, pos, &info, |
| 1937 | sizeof info); |
| 1938 | } |
| 1939 | |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1940 | static 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 Hellwig | 27b1ea0 | 2007-07-20 21:39:34 +0200 | [diff] [blame] | 1953 | spu_release_saved(ctx); |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1954 | |
| 1955 | return ret; |
| 1956 | } |
| 1957 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 1958 | static const struct file_operations spufs_dma_info_fops = { |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 1959 | .open = spufs_info_open, |
| 1960 | .read = spufs_dma_info_read, |
| 1961 | }; |
| 1962 | |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1963 | static ssize_t __spufs_proxydma_info_read(struct spu_context *ctx, |
| 1964 | char __user *buf, size_t len, loff_t *pos) |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 1965 | { |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 1966 | struct spu_proxydma_info info; |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 1967 | struct mfc_cq_sr *qp, *puqp; |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1968 | int ret = sizeof info; |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 1969 | 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 McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 1977 | 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 McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1989 | |
| 1990 | return simple_read_from_buffer(buf, len, pos, &info, |
| 1991 | sizeof info); |
| 1992 | } |
| 1993 | |
| 1994 | static 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 McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 2003 | spin_unlock(&ctx->csa.register_lock); |
Christoph Hellwig | 27b1ea0 | 2007-07-20 21:39:34 +0200 | [diff] [blame] | 2004 | spu_release_saved(ctx); |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 2005 | |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 2006 | return ret; |
| 2007 | } |
| 2008 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 2009 | static const struct file_operations spufs_proxydma_info_fops = { |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 2010 | .open = spufs_info_open, |
| 2011 | .read = spufs_proxydma_info_read, |
| 2012 | }; |
| 2013 | |
Christoph Hellwig | 476273a | 2007-06-29 10:58:01 +1000 | [diff] [blame] | 2014 | static 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 | |
| 2022 | static 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 | |
| 2027 | static 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 Hellwig | e9f8a0b | 2007-06-29 10:58:03 +1000 | [diff] [blame] | 2034 | static const char *ctx_state_names[] = { |
| 2035 | "user", "system", "iowait", "loaded" |
| 2036 | }; |
| 2037 | |
| 2038 | static unsigned long long spufs_acct_time(struct spu_context *ctx, |
Andre Detsch | 27ec41d | 2007-07-20 21:39:33 +0200 | [diff] [blame] | 2039 | enum spu_utilization_state state) |
Christoph Hellwig | e9f8a0b | 2007-06-29 10:58:03 +1000 | [diff] [blame] | 2040 | { |
Andre Detsch | 27ec41d | 2007-07-20 21:39:33 +0200 | [diff] [blame] | 2041 | struct timespec ts; |
| 2042 | unsigned long long time = ctx->stats.times[state]; |
Christoph Hellwig | e9f8a0b | 2007-06-29 10:58:03 +1000 | [diff] [blame] | 2043 | |
Andre Detsch | 27ec41d | 2007-07-20 21:39:33 +0200 | [diff] [blame] | 2044 | /* |
| 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 Hellwig | e9f8a0b | 2007-06-29 10:58:03 +1000 | [diff] [blame] | 2057 | |
Andre Detsch | 27ec41d | 2007-07-20 21:39:33 +0200 | [diff] [blame] | 2058 | return time / NSEC_PER_MSEC; |
Christoph Hellwig | e9f8a0b | 2007-06-29 10:58:03 +1000 | [diff] [blame] | 2059 | } |
| 2060 | |
| 2061 | static 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 | |
| 2073 | static 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 | |
| 2086 | static 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 Detsch | 27ec41d | 2007-07-20 21:39:33 +0200 | [diff] [blame] | 2093 | 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 Hellwig | e9f8a0b | 2007-06-29 10:58:03 +1000 | [diff] [blame] | 2098 | 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 | |
| 2110 | static 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 | |
| 2115 | static 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 Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 2123 | struct tree_descr spufs_dir_contents[] = { |
Benjamin Herrenschmidt | cbe709c | 2007-06-04 15:15:38 +1000 | [diff] [blame] | 2124 | { "capabilities", &spufs_caps_fops, 0444, }, |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 2125 | { "mem", &spufs_mem_fops, 0666, }, |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 2126 | { "regs", &spufs_regs_fops, 0666, }, |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 2127 | { "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 Kerr | 603c461 | 2007-09-26 10:53:45 +1000 | [diff] [blame] | 2133 | { "signal1", &spufs_signal1_fops, 0666, }, |
| 2134 | { "signal2", &spufs_signal2_fops, 0666, }, |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 2135 | { "signal1_type", &spufs_signal1_type, 0666, }, |
| 2136 | { "signal2_type", &spufs_signal2_type, 0666, }, |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 2137 | { "cntl", &spufs_cntl_fops, 0666, }, |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 2138 | { "fpcr", &spufs_fpcr_fops, 0666, }, |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 2139 | { "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 Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 2144 | { "decr", &spufs_decr_ops, 0666, }, |
| 2145 | { "decr_status", &spufs_decr_status_ops, 0666, }, |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 2146 | { "event_mask", &spufs_event_mask_ops, 0666, }, |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 2147 | { "event_status", &spufs_event_status_ops, 0444, }, |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 2148 | { "psmap", &spufs_psmap_fops, 0666, }, |
Arnd Bergmann | 8676727 | 2006-10-04 17:26:21 +0200 | [diff] [blame] | 2149 | { "phys-id", &spufs_id_ops, 0666, }, |
| 2150 | { "object-id", &spufs_object_id_ops, 0666, }, |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 2151 | { "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 McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 2154 | { "dma_info", &spufs_dma_info_fops, 0444, }, |
| 2155 | { "proxydma_info", &spufs_proxydma_info_fops, 0444, }, |
Christoph Hellwig | 476273a | 2007-06-29 10:58:01 +1000 | [diff] [blame] | 2156 | { "tid", &spufs_tid_fops, 0444, }, |
Christoph Hellwig | e9f8a0b | 2007-06-29 10:58:03 +1000 | [diff] [blame] | 2157 | { "stat", &spufs_stat_fops, 0444, }, |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 2158 | {}, |
| 2159 | }; |
Mark Nutter | 5737edd | 2006-10-24 18:31:16 +0200 | [diff] [blame] | 2160 | |
| 2161 | struct tree_descr spufs_dir_nosched_contents[] = { |
Benjamin Herrenschmidt | cbe709c | 2007-06-04 15:15:38 +1000 | [diff] [blame] | 2162 | { "capabilities", &spufs_caps_fops, 0444, }, |
Mark Nutter | 5737edd | 2006-10-24 18:31:16 +0200 | [diff] [blame] | 2163 | { "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 Kerr | d054b36 | 2007-07-20 21:39:31 +0200 | [diff] [blame] | 2170 | { "signal1", &spufs_signal1_nosched_fops, 0222, }, |
| 2171 | { "signal2", &spufs_signal2_nosched_fops, 0222, }, |
Mark Nutter | 5737edd | 2006-10-24 18:31:16 +0200 | [diff] [blame] | 2172 | { "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 Hellwig | 476273a | 2007-06-29 10:58:01 +1000 | [diff] [blame] | 2181 | { "tid", &spufs_tid_fops, 0444, }, |
Christoph Hellwig | e9f8a0b | 2007-06-29 10:58:03 +1000 | [diff] [blame] | 2182 | { "stat", &spufs_stat_fops, 0444, }, |
Mark Nutter | 5737edd | 2006-10-24 18:31:16 +0200 | [diff] [blame] | 2183 | {}, |
| 2184 | }; |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 2185 | |
| 2186 | struct spufs_coredump_reader spufs_coredump_read[] = { |
Michael Ellerman | 4fca9c4 | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 2187 | { "regs", __spufs_regs_read, NULL, sizeof(struct spu_reg128[128])}, |
| 2188 | { "fpcr", __spufs_fpcr_read, NULL, sizeof(struct spu_reg128) }, |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 2189 | { "lslr", NULL, spufs_lslr_get, 19 }, |
| 2190 | { "decr", NULL, spufs_decr_get, 19 }, |
| 2191 | { "decr_status", NULL, spufs_decr_status_get, 19 }, |
Michael Ellerman | 4fca9c4 | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 2192 | { "mem", __spufs_mem_read, NULL, LS_SIZE, }, |
| 2193 | { "signal1", __spufs_signal1_read, NULL, sizeof(u32) }, |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 2194 | { "signal1_type", NULL, spufs_signal1_type_get, 19 }, |
Michael Ellerman | 4fca9c4 | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 2195 | { "signal2", __spufs_signal2_read, NULL, sizeof(u32) }, |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 2196 | { "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 Ellerman | 4fca9c4 | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 2199 | { "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 Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 2205 | { "object-id", NULL, spufs_object_id_get, 19 }, |
| 2206 | { "npc", NULL, spufs_npc_get, 19 }, |
Michael Ellerman | 936d5bf | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 2207 | { NULL }, |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 2208 | }; |