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> |
FUJITA Tomonori | dfe1e09 | 2008-05-13 19:07:42 +1000 | [diff] [blame] | 34 | #include <asm/time.h> |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 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" |
Christoph Hellwig | ae142e0 | 2009-06-12 04:31:52 +0000 | [diff] [blame] | 40 | #include "sputrace.h" |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 41 | |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 42 | #define SPUFS_MMAP_4K (PAGE_SIZE == 0x1000) |
| 43 | |
Christoph Hellwig | 197b1a8 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 44 | /* Simple attribute files */ |
| 45 | struct spufs_attr { |
| 46 | int (*get)(void *, u64 *); |
| 47 | int (*set)(void *, u64); |
| 48 | char get_buf[24]; /* enough to store a u64 and "\n\0" */ |
| 49 | char set_buf[24]; |
| 50 | void *data; |
| 51 | const char *fmt; /* format for read operation */ |
| 52 | struct mutex mutex; /* protects access to these buffers */ |
| 53 | }; |
| 54 | |
| 55 | static int spufs_attr_open(struct inode *inode, struct file *file, |
| 56 | int (*get)(void *, u64 *), int (*set)(void *, u64), |
| 57 | const char *fmt) |
| 58 | { |
| 59 | struct spufs_attr *attr; |
| 60 | |
| 61 | attr = kmalloc(sizeof(*attr), GFP_KERNEL); |
| 62 | if (!attr) |
| 63 | return -ENOMEM; |
| 64 | |
| 65 | attr->get = get; |
| 66 | attr->set = set; |
| 67 | attr->data = inode->i_private; |
| 68 | attr->fmt = fmt; |
| 69 | mutex_init(&attr->mutex); |
| 70 | file->private_data = attr; |
| 71 | |
| 72 | return nonseekable_open(inode, file); |
| 73 | } |
| 74 | |
| 75 | static int spufs_attr_release(struct inode *inode, struct file *file) |
| 76 | { |
| 77 | kfree(file->private_data); |
| 78 | return 0; |
| 79 | } |
| 80 | |
| 81 | static ssize_t spufs_attr_read(struct file *file, char __user *buf, |
| 82 | size_t len, loff_t *ppos) |
| 83 | { |
| 84 | struct spufs_attr *attr; |
| 85 | size_t size; |
| 86 | ssize_t ret; |
| 87 | |
| 88 | attr = file->private_data; |
| 89 | if (!attr->get) |
| 90 | return -EACCES; |
| 91 | |
| 92 | ret = mutex_lock_interruptible(&attr->mutex); |
| 93 | if (ret) |
| 94 | return ret; |
| 95 | |
| 96 | if (*ppos) { /* continued read */ |
| 97 | size = strlen(attr->get_buf); |
| 98 | } else { /* first read */ |
| 99 | u64 val; |
| 100 | ret = attr->get(attr->data, &val); |
| 101 | if (ret) |
| 102 | goto out; |
| 103 | |
| 104 | size = scnprintf(attr->get_buf, sizeof(attr->get_buf), |
| 105 | attr->fmt, (unsigned long long)val); |
| 106 | } |
| 107 | |
| 108 | ret = simple_read_from_buffer(buf, len, ppos, attr->get_buf, size); |
| 109 | out: |
| 110 | mutex_unlock(&attr->mutex); |
| 111 | return ret; |
| 112 | } |
| 113 | |
| 114 | static ssize_t spufs_attr_write(struct file *file, const char __user *buf, |
| 115 | size_t len, loff_t *ppos) |
| 116 | { |
| 117 | struct spufs_attr *attr; |
| 118 | u64 val; |
| 119 | size_t size; |
| 120 | ssize_t ret; |
| 121 | |
| 122 | attr = file->private_data; |
| 123 | if (!attr->set) |
| 124 | return -EACCES; |
| 125 | |
| 126 | ret = mutex_lock_interruptible(&attr->mutex); |
| 127 | if (ret) |
| 128 | return ret; |
| 129 | |
| 130 | ret = -EFAULT; |
| 131 | size = min(sizeof(attr->set_buf) - 1, len); |
| 132 | if (copy_from_user(attr->set_buf, buf, size)) |
| 133 | goto out; |
| 134 | |
| 135 | ret = len; /* claim we got the whole input */ |
| 136 | attr->set_buf[size] = '\0'; |
| 137 | val = simple_strtol(attr->set_buf, NULL, 0); |
| 138 | attr->set(attr->data, val); |
| 139 | out: |
| 140 | mutex_unlock(&attr->mutex); |
| 141 | return ret; |
| 142 | } |
| 143 | |
| 144 | #define DEFINE_SPUFS_SIMPLE_ATTRIBUTE(__fops, __get, __set, __fmt) \ |
| 145 | static int __fops ## _open(struct inode *inode, struct file *file) \ |
| 146 | { \ |
| 147 | __simple_attr_check_format(__fmt, 0ull); \ |
| 148 | return spufs_attr_open(inode, file, __get, __set, __fmt); \ |
| 149 | } \ |
Alexey Dobriyan | 828c095 | 2009-10-01 15:43:56 -0700 | [diff] [blame] | 150 | static const struct file_operations __fops = { \ |
Christoph Hellwig | 197b1a8 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 151 | .owner = THIS_MODULE, \ |
| 152 | .open = __fops ## _open, \ |
| 153 | .release = spufs_attr_release, \ |
| 154 | .read = spufs_attr_read, \ |
| 155 | .write = spufs_attr_write, \ |
| 156 | }; |
| 157 | |
Benjamin Herrenschmidt | cbe709c | 2007-06-04 15:15:38 +1000 | [diff] [blame] | 158 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 159 | static int |
| 160 | spufs_mem_open(struct inode *inode, struct file *file) |
| 161 | { |
| 162 | struct spufs_inode_info *i = SPUFS_I(inode); |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 163 | struct spu_context *ctx = i->i_ctx; |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 164 | |
Christoph Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 165 | mutex_lock(&ctx->mapping_lock); |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 166 | file->private_data = ctx; |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 167 | if (!i->i_openers++) |
| 168 | ctx->local_store = inode->i_mapping; |
Christoph Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 169 | mutex_unlock(&ctx->mapping_lock); |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 170 | return 0; |
| 171 | } |
| 172 | |
| 173 | static int |
| 174 | spufs_mem_release(struct inode *inode, struct file *file) |
| 175 | { |
| 176 | struct spufs_inode_info *i = SPUFS_I(inode); |
| 177 | struct spu_context *ctx = i->i_ctx; |
| 178 | |
Christoph Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 179 | mutex_lock(&ctx->mapping_lock); |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 180 | if (!--i->i_openers) |
| 181 | ctx->local_store = NULL; |
Christoph Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 182 | mutex_unlock(&ctx->mapping_lock); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 183 | return 0; |
| 184 | } |
| 185 | |
| 186 | static ssize_t |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 187 | __spufs_mem_read(struct spu_context *ctx, char __user *buffer, |
| 188 | size_t size, loff_t *pos) |
| 189 | { |
| 190 | char *local_store = ctx->ops->get_ls(ctx); |
| 191 | return simple_read_from_buffer(buffer, size, pos, local_store, |
| 192 | LS_SIZE); |
| 193 | } |
| 194 | |
| 195 | static ssize_t |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 196 | spufs_mem_read(struct file *file, char __user *buffer, |
| 197 | size_t size, loff_t *pos) |
| 198 | { |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 199 | struct spu_context *ctx = file->private_data; |
Arnd Bergmann | aa0ed2b | 2007-03-10 00:05:35 +0100 | [diff] [blame] | 200 | ssize_t ret; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 201 | |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 202 | ret = spu_acquire(ctx); |
| 203 | if (ret) |
| 204 | return ret; |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 205 | ret = __spufs_mem_read(ctx, buffer, size, pos); |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 206 | spu_release(ctx); |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 207 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 208 | return ret; |
| 209 | } |
| 210 | |
| 211 | static ssize_t |
| 212 | spufs_mem_write(struct file *file, const char __user *buffer, |
Arnd Bergmann | aa0ed2b | 2007-03-10 00:05:35 +0100 | [diff] [blame] | 213 | size_t size, loff_t *ppos) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 214 | { |
| 215 | struct spu_context *ctx = file->private_data; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 216 | char *local_store; |
Arnd Bergmann | aa0ed2b | 2007-03-10 00:05:35 +0100 | [diff] [blame] | 217 | loff_t pos = *ppos; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 218 | int ret; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 219 | |
Arnd Bergmann | aa0ed2b | 2007-03-10 00:05:35 +0100 | [diff] [blame] | 220 | if (pos < 0) |
| 221 | return -EINVAL; |
| 222 | if (pos > LS_SIZE) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 223 | return -EFBIG; |
Arnd Bergmann | aa0ed2b | 2007-03-10 00:05:35 +0100 | [diff] [blame] | 224 | if (size > LS_SIZE - pos) |
| 225 | size = LS_SIZE - pos; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 226 | |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 227 | ret = spu_acquire(ctx); |
| 228 | if (ret) |
| 229 | return ret; |
| 230 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 231 | local_store = ctx->ops->get_ls(ctx); |
Arnd Bergmann | aa0ed2b | 2007-03-10 00:05:35 +0100 | [diff] [blame] | 232 | ret = copy_from_user(local_store + pos, buffer, size); |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 233 | spu_release(ctx); |
Arnd Bergmann | aa0ed2b | 2007-03-10 00:05:35 +0100 | [diff] [blame] | 234 | |
| 235 | if (ret) |
| 236 | return -EFAULT; |
| 237 | *ppos = pos + size; |
| 238 | return size; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 239 | } |
| 240 | |
Nick Piggin | b1e2270 | 2008-06-10 09:26:08 +1000 | [diff] [blame] | 241 | static int |
| 242 | spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf) |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 243 | { |
Benjamin Herrenschmidt | f1fa74f | 2007-05-08 16:27:29 +1000 | [diff] [blame] | 244 | struct spu_context *ctx = vma->vm_file->private_data; |
Nick Piggin | b1e2270 | 2008-06-10 09:26:08 +1000 | [diff] [blame] | 245 | unsigned long address = (unsigned long)vmf->virtual_address; |
| 246 | unsigned long pfn, offset; |
| 247 | |
Benjamin Herrenschmidt | f1fa74f | 2007-05-08 16:27:29 +1000 | [diff] [blame] | 248 | #ifdef CONFIG_SPU_FS_64K_LS |
| 249 | struct spu_state *csa = &ctx->csa; |
| 250 | int psize; |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 251 | |
Benjamin Herrenschmidt | f1fa74f | 2007-05-08 16:27:29 +1000 | [diff] [blame] | 252 | /* Check what page size we are using */ |
| 253 | psize = get_slice_psize(vma->vm_mm, address); |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 254 | |
Benjamin Herrenschmidt | f1fa74f | 2007-05-08 16:27:29 +1000 | [diff] [blame] | 255 | /* Some sanity checking */ |
| 256 | BUG_ON(csa->use_big_pages != (psize == MMU_PAGE_64K)); |
| 257 | |
| 258 | /* Wow, 64K, cool, we need to align the address though */ |
| 259 | if (csa->use_big_pages) { |
| 260 | BUG_ON(vma->vm_start & 0xffff); |
| 261 | address &= ~0xfffful; |
| 262 | } |
| 263 | #endif /* CONFIG_SPU_FS_64K_LS */ |
| 264 | |
Nick Piggin | b1e2270 | 2008-06-10 09:26:08 +1000 | [diff] [blame] | 265 | offset = vmf->pgoff << PAGE_SHIFT; |
Masato Noguchi | 128b854 | 2007-02-13 21:54:30 +0100 | [diff] [blame] | 266 | if (offset >= LS_SIZE) |
Nick Piggin | b1e2270 | 2008-06-10 09:26:08 +1000 | [diff] [blame] | 267 | return VM_FAULT_SIGBUS; |
Masato Noguchi | 128b854 | 2007-02-13 21:54:30 +0100 | [diff] [blame] | 268 | |
Nick Piggin | b1e2270 | 2008-06-10 09:26:08 +1000 | [diff] [blame] | 269 | pr_debug("spufs_mem_mmap_fault address=0x%lx, offset=0x%lx\n", |
| 270 | address, offset); |
Benjamin Herrenschmidt | f1fa74f | 2007-05-08 16:27:29 +1000 | [diff] [blame] | 271 | |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 272 | if (spu_acquire(ctx)) |
Nick Piggin | b1e2270 | 2008-06-10 09:26:08 +1000 | [diff] [blame] | 273 | return VM_FAULT_NOPAGE; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 274 | |
Arnd Bergmann | ac91cb8 | 2006-10-04 17:26:16 +0200 | [diff] [blame] | 275 | if (ctx->state == SPU_STATE_SAVED) { |
Benjamin Herrenschmidt | 64b3d0e | 2008-12-18 19:13:51 +0000 | [diff] [blame] | 276 | vma->vm_page_prot = pgprot_cached(vma->vm_page_prot); |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 277 | pfn = vmalloc_to_pfn(ctx->csa.lscsa->ls + offset); |
Arnd Bergmann | ac91cb8 | 2006-10-04 17:26:16 +0200 | [diff] [blame] | 278 | } else { |
Benjamin Herrenschmidt | 64b3d0e | 2008-12-18 19:13:51 +0000 | [diff] [blame] | 279 | vma->vm_page_prot = pgprot_noncached_wc(vma->vm_page_prot); |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 280 | pfn = (ctx->spu->local_store_phys + offset) >> PAGE_SHIFT; |
Arnd Bergmann | ac91cb8 | 2006-10-04 17:26:16 +0200 | [diff] [blame] | 281 | } |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 282 | vm_insert_pfn(vma, address, pfn); |
| 283 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 284 | spu_release(ctx); |
| 285 | |
Nick Piggin | b1e2270 | 2008-06-10 09:26:08 +1000 | [diff] [blame] | 286 | return VM_FAULT_NOPAGE; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 287 | } |
| 288 | |
Benjamin Herrenschmidt | a352894 | 2008-07-23 21:27:09 -0700 | [diff] [blame] | 289 | static int spufs_mem_mmap_access(struct vm_area_struct *vma, |
| 290 | unsigned long address, |
| 291 | void *buf, int len, int write) |
| 292 | { |
| 293 | struct spu_context *ctx = vma->vm_file->private_data; |
| 294 | unsigned long offset = address - vma->vm_start; |
| 295 | char *local_store; |
| 296 | |
| 297 | if (write && !(vma->vm_flags & VM_WRITE)) |
| 298 | return -EACCES; |
| 299 | if (spu_acquire(ctx)) |
| 300 | return -EINTR; |
| 301 | if ((offset + len) > vma->vm_end) |
| 302 | len = vma->vm_end - offset; |
| 303 | local_store = ctx->ops->get_ls(ctx); |
| 304 | if (write) |
| 305 | memcpy_toio(local_store + offset, buf, len); |
| 306 | else |
| 307 | memcpy_fromio(buf, local_store + offset, len); |
| 308 | spu_release(ctx); |
| 309 | return len; |
| 310 | } |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 311 | |
Alexey Dobriyan | f0f37e2 | 2009-09-27 22:29:37 +0400 | [diff] [blame] | 312 | static const struct vm_operations_struct spufs_mem_mmap_vmops = { |
Nick Piggin | b1e2270 | 2008-06-10 09:26:08 +1000 | [diff] [blame] | 313 | .fault = spufs_mem_mmap_fault, |
Benjamin Herrenschmidt | a352894 | 2008-07-23 21:27:09 -0700 | [diff] [blame] | 314 | .access = spufs_mem_mmap_access, |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 315 | }; |
| 316 | |
Benjamin Herrenschmidt | f1fa74f | 2007-05-08 16:27:29 +1000 | [diff] [blame] | 317 | 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] | 318 | { |
Benjamin Herrenschmidt | f1fa74f | 2007-05-08 16:27:29 +1000 | [diff] [blame] | 319 | #ifdef CONFIG_SPU_FS_64K_LS |
| 320 | struct spu_context *ctx = file->private_data; |
| 321 | struct spu_state *csa = &ctx->csa; |
| 322 | |
| 323 | /* Sanity check VMA alignment */ |
| 324 | if (csa->use_big_pages) { |
| 325 | pr_debug("spufs_mem_mmap 64K, start=0x%lx, end=0x%lx," |
| 326 | " pgoff=0x%lx\n", vma->vm_start, vma->vm_end, |
| 327 | vma->vm_pgoff); |
| 328 | if (vma->vm_start & 0xffff) |
| 329 | return -EINVAL; |
| 330 | if (vma->vm_pgoff & 0xf) |
| 331 | return -EINVAL; |
| 332 | } |
| 333 | #endif /* CONFIG_SPU_FS_64K_LS */ |
| 334 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 335 | if (!(vma->vm_flags & VM_SHARED)) |
| 336 | return -EINVAL; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 337 | |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 338 | vma->vm_flags |= VM_IO | VM_PFNMAP; |
Benjamin Herrenschmidt | 64b3d0e | 2008-12-18 19:13:51 +0000 | [diff] [blame] | 339 | vma->vm_page_prot = pgprot_noncached_wc(vma->vm_page_prot); |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 340 | |
| 341 | vma->vm_ops = &spufs_mem_mmap_vmops; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 342 | return 0; |
| 343 | } |
| 344 | |
Benjamin Herrenschmidt | f1fa74f | 2007-05-08 16:27:29 +1000 | [diff] [blame] | 345 | #ifdef CONFIG_SPU_FS_64K_LS |
Sebastian Siewior | 1238819 | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 346 | static unsigned long spufs_get_unmapped_area(struct file *file, |
| 347 | unsigned long addr, unsigned long len, unsigned long pgoff, |
| 348 | unsigned long flags) |
Benjamin Herrenschmidt | f1fa74f | 2007-05-08 16:27:29 +1000 | [diff] [blame] | 349 | { |
| 350 | struct spu_context *ctx = file->private_data; |
| 351 | struct spu_state *csa = &ctx->csa; |
| 352 | |
| 353 | /* If not using big pages, fallback to normal MM g_u_a */ |
| 354 | if (!csa->use_big_pages) |
| 355 | return current->mm->get_unmapped_area(file, addr, len, |
| 356 | pgoff, flags); |
| 357 | |
| 358 | /* Else, try to obtain a 64K pages slice */ |
| 359 | return slice_get_unmapped_area(addr, len, flags, |
| 360 | MMU_PAGE_64K, 1, 0); |
| 361 | } |
| 362 | #endif /* CONFIG_SPU_FS_64K_LS */ |
| 363 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 364 | static const struct file_operations spufs_mem_fops = { |
Jeremy Kerr | 7022543 | 2007-06-29 10:58:00 +1000 | [diff] [blame] | 365 | .open = spufs_mem_open, |
| 366 | .release = spufs_mem_release, |
| 367 | .read = spufs_mem_read, |
| 368 | .write = spufs_mem_write, |
| 369 | .llseek = generic_file_llseek, |
| 370 | .mmap = spufs_mem_mmap, |
Benjamin Herrenschmidt | f1fa74f | 2007-05-08 16:27:29 +1000 | [diff] [blame] | 371 | #ifdef CONFIG_SPU_FS_64K_LS |
| 372 | .get_unmapped_area = spufs_get_unmapped_area, |
| 373 | #endif |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 374 | }; |
| 375 | |
Nick Piggin | b1e2270 | 2008-06-10 09:26:08 +1000 | [diff] [blame] | 376 | static int spufs_ps_fault(struct vm_area_struct *vma, |
| 377 | struct vm_fault *vmf, |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 378 | unsigned long ps_offs, |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 379 | unsigned long ps_size) |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 380 | { |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 381 | struct spu_context *ctx = vma->vm_file->private_data; |
Nick Piggin | b1e2270 | 2008-06-10 09:26:08 +1000 | [diff] [blame] | 382 | unsigned long area, offset = vmf->pgoff << PAGE_SHIFT; |
Christoph Hellwig | eebead5 | 2008-02-08 15:50:41 +1100 | [diff] [blame] | 383 | int ret = 0; |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 384 | |
Nick Piggin | b1e2270 | 2008-06-10 09:26:08 +1000 | [diff] [blame] | 385 | spu_context_nospu_trace(spufs_ps_fault__enter, ctx); |
Christoph Hellwig | 038200c | 2008-01-11 15:03:26 +1100 | [diff] [blame] | 386 | |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 387 | if (offset >= ps_size) |
Nick Piggin | b1e2270 | 2008-06-10 09:26:08 +1000 | [diff] [blame] | 388 | return VM_FAULT_SIGBUS; |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 389 | |
Jeremy Kerr | 6065726 | 2008-11-11 10:22:22 +1100 | [diff] [blame] | 390 | if (fatal_signal_pending(current)) |
| 391 | return VM_FAULT_SIGBUS; |
| 392 | |
Arnd Bergmann | 33bfd7a | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 393 | /* |
Jeremy Kerr | d588313 | 2008-02-26 13:31:42 +1100 | [diff] [blame] | 394 | * Because we release the mmap_sem, the context may be destroyed while |
| 395 | * we're in spu_wait. Grab an extra reference so it isn't destroyed |
| 396 | * in the meantime. |
| 397 | */ |
| 398 | get_spu_context(ctx); |
| 399 | |
| 400 | /* |
Arnd Bergmann | 33bfd7a | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 401 | * We have to wait for context to be loaded before we have |
| 402 | * pages to hand out to the user, but we don't want to wait |
| 403 | * with the mmap_sem held. |
| 404 | * It is possible to drop the mmap_sem here, but then we need |
Nick Piggin | b1e2270 | 2008-06-10 09:26:08 +1000 | [diff] [blame] | 405 | * to return VM_FAULT_NOPAGE because the mappings may have |
Arnd Bergmann | 33bfd7a | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 406 | * hanged. |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 407 | */ |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 408 | if (spu_acquire(ctx)) |
Jeremy Kerr | d588313 | 2008-02-26 13:31:42 +1100 | [diff] [blame] | 409 | goto refault; |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 410 | |
Arnd Bergmann | 33bfd7a | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 411 | if (ctx->state == SPU_STATE_SAVED) { |
| 412 | up_read(¤t->mm->mmap_sem); |
Nick Piggin | b1e2270 | 2008-06-10 09:26:08 +1000 | [diff] [blame] | 413 | spu_context_nospu_trace(spufs_ps_fault__sleep, ctx); |
Christoph Hellwig | eebead5 | 2008-02-08 15:50:41 +1100 | [diff] [blame] | 414 | ret = spufs_wait(ctx->run_wq, ctx->state == SPU_STATE_RUNNABLE); |
Nick Piggin | b1e2270 | 2008-06-10 09:26:08 +1000 | [diff] [blame] | 415 | spu_context_trace(spufs_ps_fault__wake, ctx, ctx->spu); |
Arnd Bergmann | 33bfd7a | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 416 | down_read(¤t->mm->mmap_sem); |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 417 | } else { |
| 418 | area = ctx->spu->problem_phys + ps_offs; |
Nick Piggin | b1e2270 | 2008-06-10 09:26:08 +1000 | [diff] [blame] | 419 | vm_insert_pfn(vma, (unsigned long)vmf->virtual_address, |
| 420 | (area + offset) >> PAGE_SHIFT); |
| 421 | spu_context_trace(spufs_ps_fault__insert, ctx, ctx->spu); |
Arnd Bergmann | 33bfd7a | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 422 | } |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 423 | |
Christoph Hellwig | eebead5 | 2008-02-08 15:50:41 +1100 | [diff] [blame] | 424 | if (!ret) |
| 425 | spu_release(ctx); |
Jeremy Kerr | d588313 | 2008-02-26 13:31:42 +1100 | [diff] [blame] | 426 | |
| 427 | refault: |
| 428 | put_spu_context(ctx); |
Nick Piggin | b1e2270 | 2008-06-10 09:26:08 +1000 | [diff] [blame] | 429 | return VM_FAULT_NOPAGE; |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 430 | } |
| 431 | |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 432 | #if SPUFS_MMAP_4K |
Nick Piggin | b1e2270 | 2008-06-10 09:26:08 +1000 | [diff] [blame] | 433 | static int spufs_cntl_mmap_fault(struct vm_area_struct *vma, |
| 434 | struct vm_fault *vmf) |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 435 | { |
Jeremy Kerr | 87ff609 | 2008-07-01 10:22:50 +1000 | [diff] [blame] | 436 | return spufs_ps_fault(vma, vmf, 0x4000, SPUFS_CNTL_MAP_SIZE); |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 437 | } |
| 438 | |
Alexey Dobriyan | f0f37e2 | 2009-09-27 22:29:37 +0400 | [diff] [blame] | 439 | static const struct vm_operations_struct spufs_cntl_mmap_vmops = { |
Nick Piggin | b1e2270 | 2008-06-10 09:26:08 +1000 | [diff] [blame] | 440 | .fault = spufs_cntl_mmap_fault, |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 441 | }; |
| 442 | |
| 443 | /* |
| 444 | * mmap support for problem state control area [0x4000 - 0x4fff]. |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 445 | */ |
| 446 | static int spufs_cntl_mmap(struct file *file, struct vm_area_struct *vma) |
| 447 | { |
| 448 | if (!(vma->vm_flags & VM_SHARED)) |
| 449 | return -EINVAL; |
| 450 | |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 451 | vma->vm_flags |= VM_IO | VM_PFNMAP; |
Benjamin Herrenschmidt | 64b3d0e | 2008-12-18 19:13:51 +0000 | [diff] [blame] | 452 | vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 453 | |
| 454 | vma->vm_ops = &spufs_cntl_mmap_vmops; |
| 455 | return 0; |
| 456 | } |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 457 | #else /* SPUFS_MMAP_4K */ |
| 458 | #define spufs_cntl_mmap NULL |
| 459 | #endif /* !SPUFS_MMAP_4K */ |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 460 | |
Christoph Hellwig | 197b1a8 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 461 | static int spufs_cntl_get(void *data, u64 *val) |
Arnd Bergmann | e1dbff2 | 2006-10-04 17:26:19 +0200 | [diff] [blame] | 462 | { |
| 463 | struct spu_context *ctx = data; |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 464 | int ret; |
Arnd Bergmann | e1dbff2 | 2006-10-04 17:26:19 +0200 | [diff] [blame] | 465 | |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 466 | ret = spu_acquire(ctx); |
| 467 | if (ret) |
| 468 | return ret; |
Christoph Hellwig | 197b1a8 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 469 | *val = ctx->ops->status_read(ctx); |
Arnd Bergmann | e1dbff2 | 2006-10-04 17:26:19 +0200 | [diff] [blame] | 470 | spu_release(ctx); |
| 471 | |
Christoph Hellwig | 197b1a8 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 472 | return 0; |
Arnd Bergmann | e1dbff2 | 2006-10-04 17:26:19 +0200 | [diff] [blame] | 473 | } |
| 474 | |
Christoph Hellwig | 197b1a8 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 475 | static int spufs_cntl_set(void *data, u64 val) |
Arnd Bergmann | e1dbff2 | 2006-10-04 17:26:19 +0200 | [diff] [blame] | 476 | { |
| 477 | struct spu_context *ctx = data; |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 478 | int ret; |
Arnd Bergmann | e1dbff2 | 2006-10-04 17:26:19 +0200 | [diff] [blame] | 479 | |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 480 | ret = spu_acquire(ctx); |
| 481 | if (ret) |
| 482 | return ret; |
Arnd Bergmann | e1dbff2 | 2006-10-04 17:26:19 +0200 | [diff] [blame] | 483 | ctx->ops->runcntl_write(ctx, val); |
| 484 | spu_release(ctx); |
Christoph Hellwig | 197b1a8 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 485 | |
| 486 | return 0; |
Arnd Bergmann | e1dbff2 | 2006-10-04 17:26:19 +0200 | [diff] [blame] | 487 | } |
| 488 | |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 489 | static int spufs_cntl_open(struct inode *inode, struct file *file) |
| 490 | { |
| 491 | struct spufs_inode_info *i = SPUFS_I(inode); |
| 492 | struct spu_context *ctx = i->i_ctx; |
| 493 | |
Christoph Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 494 | mutex_lock(&ctx->mapping_lock); |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 495 | file->private_data = ctx; |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 496 | if (!i->i_openers++) |
| 497 | ctx->cntl = inode->i_mapping; |
Christoph Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 498 | mutex_unlock(&ctx->mapping_lock); |
Christoph Hellwig | 8b88b09 | 2008-02-08 04:20:26 -0800 | [diff] [blame] | 499 | return simple_attr_open(inode, file, spufs_cntl_get, |
Arnd Bergmann | e1dbff2 | 2006-10-04 17:26:19 +0200 | [diff] [blame] | 500 | spufs_cntl_set, "0x%08lx"); |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 501 | } |
| 502 | |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 503 | static int |
| 504 | spufs_cntl_release(struct inode *inode, struct file *file) |
| 505 | { |
| 506 | struct spufs_inode_info *i = SPUFS_I(inode); |
| 507 | struct spu_context *ctx = i->i_ctx; |
| 508 | |
Christoph Hellwig | 74bedc4 | 2008-02-08 04:20:28 -0800 | [diff] [blame] | 509 | simple_attr_release(inode, file); |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 510 | |
Christoph Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 511 | mutex_lock(&ctx->mapping_lock); |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 512 | if (!--i->i_openers) |
| 513 | ctx->cntl = NULL; |
Christoph Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 514 | mutex_unlock(&ctx->mapping_lock); |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 515 | return 0; |
| 516 | } |
| 517 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 518 | static const struct file_operations spufs_cntl_fops = { |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 519 | .open = spufs_cntl_open, |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 520 | .release = spufs_cntl_release, |
Christoph Hellwig | 8b88b09 | 2008-02-08 04:20:26 -0800 | [diff] [blame] | 521 | .read = simple_attr_read, |
| 522 | .write = simple_attr_write, |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 523 | .mmap = spufs_cntl_mmap, |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 524 | }; |
| 525 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 526 | static int |
| 527 | spufs_regs_open(struct inode *inode, struct file *file) |
| 528 | { |
| 529 | struct spufs_inode_info *i = SPUFS_I(inode); |
| 530 | file->private_data = i->i_ctx; |
| 531 | return 0; |
| 532 | } |
| 533 | |
| 534 | static ssize_t |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 535 | __spufs_regs_read(struct spu_context *ctx, char __user *buffer, |
| 536 | size_t size, loff_t *pos) |
| 537 | { |
| 538 | struct spu_lscsa *lscsa = ctx->csa.lscsa; |
| 539 | return simple_read_from_buffer(buffer, size, pos, |
| 540 | lscsa->gprs, sizeof lscsa->gprs); |
| 541 | } |
| 542 | |
| 543 | static ssize_t |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 544 | spufs_regs_read(struct file *file, char __user *buffer, |
| 545 | size_t size, loff_t *pos) |
| 546 | { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 547 | int ret; |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 548 | struct spu_context *ctx = file->private_data; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 549 | |
Jeremy Kerr | f027faa | 2008-10-16 11:11:12 +1100 | [diff] [blame] | 550 | /* pre-check for file position: if we'd return EOF, there's no point |
| 551 | * causing a deschedule */ |
| 552 | if (*pos >= sizeof(ctx->csa.lscsa->gprs)) |
| 553 | return 0; |
| 554 | |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 555 | ret = spu_acquire_saved(ctx); |
| 556 | if (ret) |
| 557 | return ret; |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 558 | ret = __spufs_regs_read(ctx, buffer, size, pos); |
Christoph Hellwig | 27b1ea0 | 2007-07-20 21:39:34 +0200 | [diff] [blame] | 559 | spu_release_saved(ctx); |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 560 | return ret; |
| 561 | } |
| 562 | |
| 563 | static ssize_t |
| 564 | spufs_regs_write(struct file *file, const char __user *buffer, |
| 565 | size_t size, loff_t *pos) |
| 566 | { |
| 567 | struct spu_context *ctx = file->private_data; |
| 568 | struct spu_lscsa *lscsa = ctx->csa.lscsa; |
| 569 | int ret; |
| 570 | |
Jeremy Kerr | d219889 | 2009-03-03 19:38:07 +0000 | [diff] [blame] | 571 | if (*pos >= sizeof(lscsa->gprs)) |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 572 | return -EFBIG; |
Jeremy Kerr | d219889 | 2009-03-03 19:38:07 +0000 | [diff] [blame] | 573 | |
| 574 | size = min_t(ssize_t, sizeof(lscsa->gprs) - *pos, size); |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 575 | *pos += size; |
| 576 | |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 577 | ret = spu_acquire_saved(ctx); |
| 578 | if (ret) |
| 579 | return ret; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 580 | |
Jeremy Kerr | 2fb4423 | 2009-03-03 19:39:32 +0000 | [diff] [blame] | 581 | ret = copy_from_user((char *)lscsa->gprs + *pos - size, |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 582 | buffer, size) ? -EFAULT : size; |
| 583 | |
Christoph Hellwig | 27b1ea0 | 2007-07-20 21:39:34 +0200 | [diff] [blame] | 584 | spu_release_saved(ctx); |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 585 | return ret; |
| 586 | } |
| 587 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 588 | static const struct file_operations spufs_regs_fops = { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 589 | .open = spufs_regs_open, |
| 590 | .read = spufs_regs_read, |
| 591 | .write = spufs_regs_write, |
| 592 | .llseek = generic_file_llseek, |
| 593 | }; |
| 594 | |
| 595 | static ssize_t |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 596 | __spufs_fpcr_read(struct spu_context *ctx, char __user * buffer, |
| 597 | size_t size, loff_t * pos) |
| 598 | { |
| 599 | struct spu_lscsa *lscsa = ctx->csa.lscsa; |
| 600 | return simple_read_from_buffer(buffer, size, pos, |
| 601 | &lscsa->fpcr, sizeof(lscsa->fpcr)); |
| 602 | } |
| 603 | |
| 604 | static ssize_t |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 605 | spufs_fpcr_read(struct file *file, char __user * buffer, |
| 606 | size_t size, loff_t * pos) |
| 607 | { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 608 | int ret; |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 609 | struct spu_context *ctx = file->private_data; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 610 | |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 611 | ret = spu_acquire_saved(ctx); |
| 612 | if (ret) |
| 613 | return ret; |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 614 | ret = __spufs_fpcr_read(ctx, buffer, size, pos); |
Christoph Hellwig | 27b1ea0 | 2007-07-20 21:39:34 +0200 | [diff] [blame] | 615 | spu_release_saved(ctx); |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 616 | return ret; |
| 617 | } |
| 618 | |
| 619 | static ssize_t |
| 620 | spufs_fpcr_write(struct file *file, const char __user * buffer, |
| 621 | size_t size, loff_t * pos) |
| 622 | { |
| 623 | struct spu_context *ctx = file->private_data; |
| 624 | struct spu_lscsa *lscsa = ctx->csa.lscsa; |
| 625 | int ret; |
| 626 | |
Jeremy Kerr | d219889 | 2009-03-03 19:38:07 +0000 | [diff] [blame] | 627 | if (*pos >= sizeof(lscsa->fpcr)) |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 628 | return -EFBIG; |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 629 | |
Jeremy Kerr | d219889 | 2009-03-03 19:38:07 +0000 | [diff] [blame] | 630 | size = min_t(ssize_t, sizeof(lscsa->fpcr) - *pos, size); |
| 631 | |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 632 | ret = spu_acquire_saved(ctx); |
| 633 | if (ret) |
| 634 | return ret; |
| 635 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 636 | *pos += size; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 637 | ret = copy_from_user((char *)&lscsa->fpcr + *pos - size, |
| 638 | buffer, size) ? -EFAULT : size; |
| 639 | |
Christoph Hellwig | 27b1ea0 | 2007-07-20 21:39:34 +0200 | [diff] [blame] | 640 | spu_release_saved(ctx); |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 641 | return ret; |
| 642 | } |
| 643 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 644 | static const struct file_operations spufs_fpcr_fops = { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 645 | .open = spufs_regs_open, |
| 646 | .read = spufs_fpcr_read, |
| 647 | .write = spufs_fpcr_write, |
| 648 | .llseek = generic_file_llseek, |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 649 | }; |
| 650 | |
| 651 | /* generic open function for all pipe-like files */ |
| 652 | static int spufs_pipe_open(struct inode *inode, struct file *file) |
| 653 | { |
| 654 | struct spufs_inode_info *i = SPUFS_I(inode); |
| 655 | file->private_data = i->i_ctx; |
| 656 | |
| 657 | return nonseekable_open(inode, file); |
| 658 | } |
| 659 | |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 660 | /* |
| 661 | * Read as many bytes from the mailbox as possible, until |
| 662 | * one of the conditions becomes true: |
| 663 | * |
| 664 | * - no more data available in the mailbox |
| 665 | * - end of the user provided buffer |
| 666 | * - end of the mapped area |
| 667 | */ |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 668 | static ssize_t spufs_mbox_read(struct file *file, char __user *buf, |
| 669 | size_t len, loff_t *pos) |
| 670 | { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 671 | struct spu_context *ctx = file->private_data; |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 672 | u32 mbox_data, __user *udata; |
| 673 | ssize_t count; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 674 | |
| 675 | if (len < 4) |
| 676 | return -EINVAL; |
| 677 | |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 678 | if (!access_ok(VERIFY_WRITE, buf, len)) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 679 | return -EFAULT; |
| 680 | |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 681 | udata = (void __user *)buf; |
| 682 | |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 683 | count = spu_acquire(ctx); |
| 684 | if (count) |
| 685 | return count; |
| 686 | |
Arnd Bergmann | 274cef5 | 2006-10-24 18:01:42 +0200 | [diff] [blame] | 687 | for (count = 0; (count + 4) <= len; count += 4, udata++) { |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 688 | int ret; |
| 689 | ret = ctx->ops->mbox_read(ctx, &mbox_data); |
| 690 | if (ret == 0) |
| 691 | break; |
| 692 | |
| 693 | /* |
| 694 | * at the end of the mapped area, we can fault |
| 695 | * but still need to return the data we have |
| 696 | * read successfully so far. |
| 697 | */ |
| 698 | ret = __put_user(mbox_data, udata); |
| 699 | if (ret) { |
| 700 | if (!count) |
| 701 | count = -EFAULT; |
| 702 | break; |
| 703 | } |
| 704 | } |
| 705 | spu_release(ctx); |
| 706 | |
| 707 | if (!count) |
| 708 | count = -EAGAIN; |
| 709 | |
| 710 | return count; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 711 | } |
| 712 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 713 | static const struct file_operations spufs_mbox_fops = { |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 714 | .open = spufs_pipe_open, |
| 715 | .read = spufs_mbox_read, |
| 716 | }; |
| 717 | |
| 718 | static ssize_t spufs_mbox_stat_read(struct file *file, char __user *buf, |
| 719 | size_t len, loff_t *pos) |
| 720 | { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 721 | struct spu_context *ctx = file->private_data; |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 722 | ssize_t ret; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 723 | u32 mbox_stat; |
| 724 | |
| 725 | if (len < 4) |
| 726 | return -EINVAL; |
| 727 | |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 728 | ret = spu_acquire(ctx); |
| 729 | if (ret) |
| 730 | return ret; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 731 | |
| 732 | mbox_stat = ctx->ops->mbox_stat_read(ctx) & 0xff; |
| 733 | |
| 734 | spu_release(ctx); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 735 | |
| 736 | if (copy_to_user(buf, &mbox_stat, sizeof mbox_stat)) |
| 737 | return -EFAULT; |
| 738 | |
| 739 | return 4; |
| 740 | } |
| 741 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 742 | static const struct file_operations spufs_mbox_stat_fops = { |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 743 | .open = spufs_pipe_open, |
| 744 | .read = spufs_mbox_stat_read, |
| 745 | }; |
| 746 | |
| 747 | /* low-level ibox access function */ |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 748 | size_t spu_ibox_read(struct spu_context *ctx, u32 *data) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 749 | { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 750 | return ctx->ops->ibox_read(ctx, data); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 751 | } |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 752 | |
| 753 | static int spufs_ibox_fasync(int fd, struct file *file, int on) |
| 754 | { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 755 | struct spu_context *ctx = file->private_data; |
| 756 | |
| 757 | return fasync_helper(fd, file, on, &ctx->ibox_fasync); |
| 758 | } |
| 759 | |
| 760 | /* interrupt-level ibox callback function. */ |
| 761 | void spufs_ibox_callback(struct spu *spu) |
| 762 | { |
| 763 | struct spu_context *ctx = spu->ctx; |
| 764 | |
Luke Browning | e65c2f6 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 765 | if (!ctx) |
| 766 | return; |
| 767 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 768 | wake_up_all(&ctx->ibox_wq); |
| 769 | kill_fasync(&ctx->ibox_fasync, SIGIO, POLLIN); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 770 | } |
| 771 | |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 772 | /* |
| 773 | * Read as many bytes from the interrupt mailbox as possible, until |
| 774 | * one of the conditions becomes true: |
| 775 | * |
| 776 | * - no more data available in the mailbox |
| 777 | * - end of the user provided buffer |
| 778 | * - end of the mapped area |
| 779 | * |
| 780 | * If the file is opened without O_NONBLOCK, we wait here until |
| 781 | * any data is available, but return when we have been able to |
| 782 | * read something. |
| 783 | */ |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 784 | static ssize_t spufs_ibox_read(struct file *file, char __user *buf, |
| 785 | size_t len, loff_t *pos) |
| 786 | { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 787 | struct spu_context *ctx = file->private_data; |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 788 | u32 ibox_data, __user *udata; |
| 789 | ssize_t count; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 790 | |
| 791 | if (len < 4) |
| 792 | return -EINVAL; |
| 793 | |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 794 | if (!access_ok(VERIFY_WRITE, buf, len)) |
| 795 | return -EFAULT; |
| 796 | |
| 797 | udata = (void __user *)buf; |
| 798 | |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 799 | count = spu_acquire(ctx); |
| 800 | if (count) |
Christoph Hellwig | eebead5 | 2008-02-08 15:50:41 +1100 | [diff] [blame] | 801 | goto out; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 802 | |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 803 | /* wait only for the first element */ |
| 804 | count = 0; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 805 | if (file->f_flags & O_NONBLOCK) { |
Christoph Hellwig | eebead5 | 2008-02-08 15:50:41 +1100 | [diff] [blame] | 806 | if (!spu_ibox_read(ctx, &ibox_data)) { |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 807 | count = -EAGAIN; |
Christoph Hellwig | eebead5 | 2008-02-08 15:50:41 +1100 | [diff] [blame] | 808 | goto out_unlock; |
| 809 | } |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 810 | } else { |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 811 | count = spufs_wait(ctx->ibox_wq, spu_ibox_read(ctx, &ibox_data)); |
Christoph Hellwig | eebead5 | 2008-02-08 15:50:41 +1100 | [diff] [blame] | 812 | if (count) |
| 813 | goto out; |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 814 | } |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 815 | |
| 816 | /* if we can't write at all, return -EFAULT */ |
| 817 | count = __put_user(ibox_data, udata); |
| 818 | if (count) |
Christoph Hellwig | eebead5 | 2008-02-08 15:50:41 +1100 | [diff] [blame] | 819 | goto out_unlock; |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 820 | |
| 821 | for (count = 4, udata++; (count + 4) <= len; count += 4, udata++) { |
| 822 | int ret; |
| 823 | ret = ctx->ops->ibox_read(ctx, &ibox_data); |
| 824 | if (ret == 0) |
| 825 | break; |
| 826 | /* |
| 827 | * at the end of the mapped area, we can fault |
| 828 | * but still need to return the data we have |
| 829 | * read successfully so far. |
| 830 | */ |
| 831 | ret = __put_user(ibox_data, udata); |
| 832 | if (ret) |
| 833 | break; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 834 | } |
| 835 | |
Christoph Hellwig | eebead5 | 2008-02-08 15:50:41 +1100 | [diff] [blame] | 836 | out_unlock: |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 837 | spu_release(ctx); |
Christoph Hellwig | eebead5 | 2008-02-08 15:50:41 +1100 | [diff] [blame] | 838 | out: |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 839 | return count; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 840 | } |
| 841 | |
| 842 | static unsigned int spufs_ibox_poll(struct file *file, poll_table *wait) |
| 843 | { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 844 | struct spu_context *ctx = file->private_data; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 845 | unsigned int mask; |
| 846 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 847 | poll_wait(file, &ctx->ibox_wq, wait); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 848 | |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 849 | /* |
| 850 | * For now keep this uninterruptible and also ignore the rule |
| 851 | * that poll should not sleep. Will be fixed later. |
| 852 | */ |
| 853 | mutex_lock(&ctx->state_mutex); |
Arnd Bergmann | 3a843d7 | 2005-12-05 22:52:27 -0500 | [diff] [blame] | 854 | mask = ctx->ops->mbox_stat_poll(ctx, POLLIN | POLLRDNORM); |
| 855 | spu_release(ctx); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 856 | |
| 857 | return mask; |
| 858 | } |
| 859 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 860 | static const struct file_operations spufs_ibox_fops = { |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 861 | .open = spufs_pipe_open, |
| 862 | .read = spufs_ibox_read, |
| 863 | .poll = spufs_ibox_poll, |
| 864 | .fasync = spufs_ibox_fasync, |
| 865 | }; |
| 866 | |
| 867 | static ssize_t spufs_ibox_stat_read(struct file *file, char __user *buf, |
| 868 | size_t len, loff_t *pos) |
| 869 | { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 870 | struct spu_context *ctx = file->private_data; |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 871 | ssize_t ret; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 872 | u32 ibox_stat; |
| 873 | |
| 874 | if (len < 4) |
| 875 | return -EINVAL; |
| 876 | |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 877 | ret = spu_acquire(ctx); |
| 878 | if (ret) |
| 879 | return ret; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 880 | ibox_stat = (ctx->ops->mbox_stat_read(ctx) >> 16) & 0xff; |
| 881 | spu_release(ctx); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 882 | |
| 883 | if (copy_to_user(buf, &ibox_stat, sizeof ibox_stat)) |
| 884 | return -EFAULT; |
| 885 | |
| 886 | return 4; |
| 887 | } |
| 888 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 889 | static const struct file_operations spufs_ibox_stat_fops = { |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 890 | .open = spufs_pipe_open, |
| 891 | .read = spufs_ibox_stat_read, |
| 892 | }; |
| 893 | |
| 894 | /* low-level mailbox write */ |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 895 | size_t spu_wbox_write(struct spu_context *ctx, u32 data) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 896 | { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 897 | return ctx->ops->wbox_write(ctx, data); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 898 | } |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 899 | |
| 900 | static int spufs_wbox_fasync(int fd, struct file *file, int on) |
| 901 | { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 902 | struct spu_context *ctx = file->private_data; |
| 903 | int ret; |
| 904 | |
| 905 | ret = fasync_helper(fd, file, on, &ctx->wbox_fasync); |
| 906 | |
| 907 | return ret; |
| 908 | } |
| 909 | |
| 910 | /* interrupt-level wbox callback function. */ |
| 911 | void spufs_wbox_callback(struct spu *spu) |
| 912 | { |
| 913 | struct spu_context *ctx = spu->ctx; |
| 914 | |
Luke Browning | e65c2f6 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 915 | if (!ctx) |
| 916 | return; |
| 917 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 918 | wake_up_all(&ctx->wbox_wq); |
| 919 | kill_fasync(&ctx->wbox_fasync, SIGIO, POLLOUT); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 920 | } |
| 921 | |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 922 | /* |
| 923 | * Write as many bytes to the interrupt mailbox as possible, until |
| 924 | * one of the conditions becomes true: |
| 925 | * |
| 926 | * - the mailbox is full |
| 927 | * - end of the user provided buffer |
| 928 | * - end of the mapped area |
| 929 | * |
| 930 | * If the file is opened without O_NONBLOCK, we wait here until |
| 931 | * space is availabyl, but return when we have been able to |
| 932 | * write something. |
| 933 | */ |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 934 | static ssize_t spufs_wbox_write(struct file *file, const char __user *buf, |
| 935 | size_t len, loff_t *pos) |
| 936 | { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 937 | struct spu_context *ctx = file->private_data; |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 938 | u32 wbox_data, __user *udata; |
| 939 | ssize_t count; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 940 | |
| 941 | if (len < 4) |
| 942 | return -EINVAL; |
| 943 | |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 944 | udata = (void __user *)buf; |
| 945 | if (!access_ok(VERIFY_READ, buf, len)) |
| 946 | return -EFAULT; |
| 947 | |
| 948 | if (__get_user(wbox_data, udata)) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 949 | return -EFAULT; |
| 950 | |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 951 | count = spu_acquire(ctx); |
| 952 | if (count) |
Christoph Hellwig | eebead5 | 2008-02-08 15:50:41 +1100 | [diff] [blame] | 953 | goto out; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 954 | |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 955 | /* |
| 956 | * make sure we can at least write one element, by waiting |
| 957 | * in case of !O_NONBLOCK |
| 958 | */ |
| 959 | count = 0; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 960 | if (file->f_flags & O_NONBLOCK) { |
Christoph Hellwig | eebead5 | 2008-02-08 15:50:41 +1100 | [diff] [blame] | 961 | if (!spu_wbox_write(ctx, wbox_data)) { |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 962 | count = -EAGAIN; |
Christoph Hellwig | eebead5 | 2008-02-08 15:50:41 +1100 | [diff] [blame] | 963 | goto out_unlock; |
| 964 | } |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 965 | } else { |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 966 | count = spufs_wait(ctx->wbox_wq, spu_wbox_write(ctx, wbox_data)); |
Christoph Hellwig | eebead5 | 2008-02-08 15:50:41 +1100 | [diff] [blame] | 967 | if (count) |
| 968 | goto out; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 969 | } |
| 970 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 971 | |
Jan Engelhardt | 96de0e2 | 2007-10-19 23:21:04 +0200 | [diff] [blame] | 972 | /* write as much as possible */ |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 973 | for (count = 4, udata++; (count + 4) <= len; count += 4, udata++) { |
| 974 | int ret; |
| 975 | ret = __get_user(wbox_data, udata); |
| 976 | if (ret) |
| 977 | break; |
| 978 | |
| 979 | ret = spu_wbox_write(ctx, wbox_data); |
| 980 | if (ret == 0) |
| 981 | break; |
| 982 | } |
| 983 | |
Christoph Hellwig | eebead5 | 2008-02-08 15:50:41 +1100 | [diff] [blame] | 984 | out_unlock: |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 985 | spu_release(ctx); |
Christoph Hellwig | eebead5 | 2008-02-08 15:50:41 +1100 | [diff] [blame] | 986 | out: |
Arnd Bergmann | cdcc89b | 2006-10-04 17:26:17 +0200 | [diff] [blame] | 987 | return count; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 988 | } |
| 989 | |
| 990 | static unsigned int spufs_wbox_poll(struct file *file, poll_table *wait) |
| 991 | { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 992 | struct spu_context *ctx = file->private_data; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 993 | unsigned int mask; |
| 994 | |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 995 | poll_wait(file, &ctx->wbox_wq, wait); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 996 | |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 997 | /* |
| 998 | * For now keep this uninterruptible and also ignore the rule |
| 999 | * that poll should not sleep. Will be fixed later. |
| 1000 | */ |
| 1001 | mutex_lock(&ctx->state_mutex); |
Arnd Bergmann | 3a843d7 | 2005-12-05 22:52:27 -0500 | [diff] [blame] | 1002 | mask = ctx->ops->mbox_stat_poll(ctx, POLLOUT | POLLWRNORM); |
| 1003 | spu_release(ctx); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1004 | |
| 1005 | return mask; |
| 1006 | } |
| 1007 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 1008 | static const struct file_operations spufs_wbox_fops = { |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1009 | .open = spufs_pipe_open, |
| 1010 | .write = spufs_wbox_write, |
| 1011 | .poll = spufs_wbox_poll, |
| 1012 | .fasync = spufs_wbox_fasync, |
| 1013 | }; |
| 1014 | |
| 1015 | static ssize_t spufs_wbox_stat_read(struct file *file, char __user *buf, |
| 1016 | size_t len, loff_t *pos) |
| 1017 | { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1018 | struct spu_context *ctx = file->private_data; |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1019 | ssize_t ret; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1020 | u32 wbox_stat; |
| 1021 | |
| 1022 | if (len < 4) |
| 1023 | return -EINVAL; |
| 1024 | |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1025 | ret = spu_acquire(ctx); |
| 1026 | if (ret) |
| 1027 | return ret; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1028 | wbox_stat = (ctx->ops->mbox_stat_read(ctx) >> 8) & 0xff; |
| 1029 | spu_release(ctx); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1030 | |
| 1031 | if (copy_to_user(buf, &wbox_stat, sizeof wbox_stat)) |
| 1032 | return -EFAULT; |
| 1033 | |
| 1034 | return 4; |
| 1035 | } |
| 1036 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 1037 | static const struct file_operations spufs_wbox_stat_fops = { |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1038 | .open = spufs_pipe_open, |
| 1039 | .read = spufs_wbox_stat_read, |
| 1040 | }; |
| 1041 | |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 1042 | static int spufs_signal1_open(struct inode *inode, struct file *file) |
| 1043 | { |
| 1044 | struct spufs_inode_info *i = SPUFS_I(inode); |
| 1045 | struct spu_context *ctx = i->i_ctx; |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 1046 | |
Christoph Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 1047 | mutex_lock(&ctx->mapping_lock); |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 1048 | file->private_data = ctx; |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 1049 | if (!i->i_openers++) |
| 1050 | ctx->signal1 = inode->i_mapping; |
Christoph Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 1051 | mutex_unlock(&ctx->mapping_lock); |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 1052 | return nonseekable_open(inode, file); |
| 1053 | } |
| 1054 | |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 1055 | static int |
| 1056 | spufs_signal1_release(struct inode *inode, struct file *file) |
| 1057 | { |
| 1058 | struct spufs_inode_info *i = SPUFS_I(inode); |
| 1059 | struct spu_context *ctx = i->i_ctx; |
| 1060 | |
Christoph Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 1061 | mutex_lock(&ctx->mapping_lock); |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 1062 | if (!--i->i_openers) |
| 1063 | ctx->signal1 = NULL; |
Christoph Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 1064 | mutex_unlock(&ctx->mapping_lock); |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 1065 | return 0; |
| 1066 | } |
| 1067 | |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1068 | 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] | 1069 | size_t len, loff_t *pos) |
| 1070 | { |
Dwayne Grant McConnell | 17f88ce | 2006-11-20 18:45:01 +0100 | [diff] [blame] | 1071 | int ret = 0; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1072 | u32 data; |
| 1073 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1074 | if (len < 4) |
| 1075 | return -EINVAL; |
| 1076 | |
Dwayne Grant McConnell | 17f88ce | 2006-11-20 18:45:01 +0100 | [diff] [blame] | 1077 | if (ctx->csa.spu_chnlcnt_RW[3]) { |
| 1078 | data = ctx->csa.spu_chnldata_RW[3]; |
| 1079 | ret = 4; |
| 1080 | } |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1081 | |
Dwayne Grant McConnell | 17f88ce | 2006-11-20 18:45:01 +0100 | [diff] [blame] | 1082 | if (!ret) |
| 1083 | goto out; |
| 1084 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1085 | if (copy_to_user(buf, &data, 4)) |
| 1086 | return -EFAULT; |
| 1087 | |
Dwayne Grant McConnell | 17f88ce | 2006-11-20 18:45:01 +0100 | [diff] [blame] | 1088 | out: |
| 1089 | return ret; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1090 | } |
| 1091 | |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1092 | static ssize_t spufs_signal1_read(struct file *file, char __user *buf, |
| 1093 | size_t len, loff_t *pos) |
| 1094 | { |
| 1095 | int ret; |
| 1096 | struct spu_context *ctx = file->private_data; |
| 1097 | |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1098 | ret = spu_acquire_saved(ctx); |
| 1099 | if (ret) |
| 1100 | return ret; |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1101 | ret = __spufs_signal1_read(ctx, buf, len, pos); |
Christoph Hellwig | 27b1ea0 | 2007-07-20 21:39:34 +0200 | [diff] [blame] | 1102 | spu_release_saved(ctx); |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1103 | |
| 1104 | return ret; |
| 1105 | } |
| 1106 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1107 | static ssize_t spufs_signal1_write(struct file *file, const char __user *buf, |
| 1108 | size_t len, loff_t *pos) |
| 1109 | { |
| 1110 | struct spu_context *ctx; |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1111 | ssize_t ret; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1112 | u32 data; |
| 1113 | |
| 1114 | ctx = file->private_data; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1115 | |
| 1116 | if (len < 4) |
| 1117 | return -EINVAL; |
| 1118 | |
| 1119 | if (copy_from_user(&data, buf, 4)) |
| 1120 | return -EFAULT; |
| 1121 | |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1122 | ret = spu_acquire(ctx); |
| 1123 | if (ret) |
| 1124 | return ret; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1125 | ctx->ops->signal1_write(ctx, data); |
| 1126 | spu_release(ctx); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1127 | |
| 1128 | return 4; |
| 1129 | } |
| 1130 | |
Nick Piggin | b1e2270 | 2008-06-10 09:26:08 +1000 | [diff] [blame] | 1131 | static int |
| 1132 | spufs_signal1_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf) |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 1133 | { |
Jeremy Kerr | 87ff609 | 2008-07-01 10:22:50 +1000 | [diff] [blame] | 1134 | #if SPUFS_SIGNAL_MAP_SIZE == 0x1000 |
| 1135 | return spufs_ps_fault(vma, vmf, 0x14000, SPUFS_SIGNAL_MAP_SIZE); |
| 1136 | #elif SPUFS_SIGNAL_MAP_SIZE == 0x10000 |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 1137 | /* For 64k pages, both signal1 and signal2 can be used to mmap the whole |
| 1138 | * signal 1 and 2 area |
| 1139 | */ |
Jeremy Kerr | 87ff609 | 2008-07-01 10:22:50 +1000 | [diff] [blame] | 1140 | return spufs_ps_fault(vma, vmf, 0x10000, SPUFS_SIGNAL_MAP_SIZE); |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 1141 | #else |
| 1142 | #error unsupported page size |
| 1143 | #endif |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 1144 | } |
| 1145 | |
Alexey Dobriyan | f0f37e2 | 2009-09-27 22:29:37 +0400 | [diff] [blame] | 1146 | static const struct vm_operations_struct spufs_signal1_mmap_vmops = { |
Nick Piggin | b1e2270 | 2008-06-10 09:26:08 +1000 | [diff] [blame] | 1147 | .fault = spufs_signal1_mmap_fault, |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 1148 | }; |
| 1149 | |
| 1150 | static int spufs_signal1_mmap(struct file *file, struct vm_area_struct *vma) |
| 1151 | { |
| 1152 | if (!(vma->vm_flags & VM_SHARED)) |
| 1153 | return -EINVAL; |
| 1154 | |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 1155 | vma->vm_flags |= VM_IO | VM_PFNMAP; |
Benjamin Herrenschmidt | 64b3d0e | 2008-12-18 19:13:51 +0000 | [diff] [blame] | 1156 | vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 1157 | |
| 1158 | vma->vm_ops = &spufs_signal1_mmap_vmops; |
| 1159 | return 0; |
| 1160 | } |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 1161 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 1162 | static const struct file_operations spufs_signal1_fops = { |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 1163 | .open = spufs_signal1_open, |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 1164 | .release = spufs_signal1_release, |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1165 | .read = spufs_signal1_read, |
| 1166 | .write = spufs_signal1_write, |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 1167 | .mmap = spufs_signal1_mmap, |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1168 | }; |
| 1169 | |
Jeremy Kerr | d054b36 | 2007-07-20 21:39:31 +0200 | [diff] [blame] | 1170 | static const struct file_operations spufs_signal1_nosched_fops = { |
| 1171 | .open = spufs_signal1_open, |
| 1172 | .release = spufs_signal1_release, |
| 1173 | .write = spufs_signal1_write, |
| 1174 | .mmap = spufs_signal1_mmap, |
| 1175 | }; |
| 1176 | |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 1177 | static int spufs_signal2_open(struct inode *inode, struct file *file) |
| 1178 | { |
| 1179 | struct spufs_inode_info *i = SPUFS_I(inode); |
| 1180 | struct spu_context *ctx = i->i_ctx; |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 1181 | |
Christoph Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 1182 | mutex_lock(&ctx->mapping_lock); |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 1183 | file->private_data = ctx; |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 1184 | if (!i->i_openers++) |
| 1185 | ctx->signal2 = inode->i_mapping; |
Christoph Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 1186 | mutex_unlock(&ctx->mapping_lock); |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 1187 | return nonseekable_open(inode, file); |
| 1188 | } |
| 1189 | |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 1190 | static int |
| 1191 | spufs_signal2_release(struct inode *inode, struct file *file) |
| 1192 | { |
| 1193 | struct spufs_inode_info *i = SPUFS_I(inode); |
| 1194 | struct spu_context *ctx = i->i_ctx; |
| 1195 | |
Christoph Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 1196 | mutex_lock(&ctx->mapping_lock); |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 1197 | if (!--i->i_openers) |
| 1198 | ctx->signal2 = NULL; |
Christoph Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 1199 | mutex_unlock(&ctx->mapping_lock); |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 1200 | return 0; |
| 1201 | } |
| 1202 | |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1203 | 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] | 1204 | size_t len, loff_t *pos) |
| 1205 | { |
Dwayne Grant McConnell | 17f88ce | 2006-11-20 18:45:01 +0100 | [diff] [blame] | 1206 | int ret = 0; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1207 | u32 data; |
| 1208 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1209 | if (len < 4) |
| 1210 | return -EINVAL; |
| 1211 | |
Dwayne Grant McConnell | 17f88ce | 2006-11-20 18:45:01 +0100 | [diff] [blame] | 1212 | if (ctx->csa.spu_chnlcnt_RW[4]) { |
| 1213 | data = ctx->csa.spu_chnldata_RW[4]; |
| 1214 | ret = 4; |
| 1215 | } |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1216 | |
Dwayne Grant McConnell | 17f88ce | 2006-11-20 18:45:01 +0100 | [diff] [blame] | 1217 | if (!ret) |
| 1218 | goto out; |
| 1219 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1220 | if (copy_to_user(buf, &data, 4)) |
| 1221 | return -EFAULT; |
| 1222 | |
Dwayne Grant McConnell | 17f88ce | 2006-11-20 18:45:01 +0100 | [diff] [blame] | 1223 | out: |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1224 | return ret; |
| 1225 | } |
| 1226 | |
| 1227 | static ssize_t spufs_signal2_read(struct file *file, char __user *buf, |
| 1228 | size_t len, loff_t *pos) |
| 1229 | { |
| 1230 | struct spu_context *ctx = file->private_data; |
| 1231 | int ret; |
| 1232 | |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1233 | ret = spu_acquire_saved(ctx); |
| 1234 | if (ret) |
| 1235 | return ret; |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1236 | ret = __spufs_signal2_read(ctx, buf, len, pos); |
Christoph Hellwig | 27b1ea0 | 2007-07-20 21:39:34 +0200 | [diff] [blame] | 1237 | spu_release_saved(ctx); |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1238 | |
| 1239 | return ret; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1240 | } |
| 1241 | |
| 1242 | static ssize_t spufs_signal2_write(struct file *file, const char __user *buf, |
| 1243 | size_t len, loff_t *pos) |
| 1244 | { |
| 1245 | struct spu_context *ctx; |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1246 | ssize_t ret; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1247 | u32 data; |
| 1248 | |
| 1249 | ctx = file->private_data; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1250 | |
| 1251 | if (len < 4) |
| 1252 | return -EINVAL; |
| 1253 | |
| 1254 | if (copy_from_user(&data, buf, 4)) |
| 1255 | return -EFAULT; |
| 1256 | |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1257 | ret = spu_acquire(ctx); |
| 1258 | if (ret) |
| 1259 | return ret; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1260 | ctx->ops->signal2_write(ctx, data); |
| 1261 | spu_release(ctx); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1262 | |
| 1263 | return 4; |
| 1264 | } |
| 1265 | |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 1266 | #if SPUFS_MMAP_4K |
Nick Piggin | b1e2270 | 2008-06-10 09:26:08 +1000 | [diff] [blame] | 1267 | static int |
| 1268 | spufs_signal2_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf) |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 1269 | { |
Jeremy Kerr | 87ff609 | 2008-07-01 10:22:50 +1000 | [diff] [blame] | 1270 | #if SPUFS_SIGNAL_MAP_SIZE == 0x1000 |
| 1271 | return spufs_ps_fault(vma, vmf, 0x1c000, SPUFS_SIGNAL_MAP_SIZE); |
| 1272 | #elif SPUFS_SIGNAL_MAP_SIZE == 0x10000 |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 1273 | /* For 64k pages, both signal1 and signal2 can be used to mmap the whole |
| 1274 | * signal 1 and 2 area |
| 1275 | */ |
Jeremy Kerr | 87ff609 | 2008-07-01 10:22:50 +1000 | [diff] [blame] | 1276 | return spufs_ps_fault(vma, vmf, 0x10000, SPUFS_SIGNAL_MAP_SIZE); |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 1277 | #else |
| 1278 | #error unsupported page size |
| 1279 | #endif |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 1280 | } |
| 1281 | |
Alexey Dobriyan | f0f37e2 | 2009-09-27 22:29:37 +0400 | [diff] [blame] | 1282 | static const struct vm_operations_struct spufs_signal2_mmap_vmops = { |
Nick Piggin | b1e2270 | 2008-06-10 09:26:08 +1000 | [diff] [blame] | 1283 | .fault = spufs_signal2_mmap_fault, |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 1284 | }; |
| 1285 | |
| 1286 | static int spufs_signal2_mmap(struct file *file, struct vm_area_struct *vma) |
| 1287 | { |
| 1288 | if (!(vma->vm_flags & VM_SHARED)) |
| 1289 | return -EINVAL; |
| 1290 | |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 1291 | vma->vm_flags |= VM_IO | VM_PFNMAP; |
Benjamin Herrenschmidt | 64b3d0e | 2008-12-18 19:13:51 +0000 | [diff] [blame] | 1292 | vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 1293 | |
| 1294 | vma->vm_ops = &spufs_signal2_mmap_vmops; |
| 1295 | return 0; |
| 1296 | } |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 1297 | #else /* SPUFS_MMAP_4K */ |
| 1298 | #define spufs_signal2_mmap NULL |
| 1299 | #endif /* !SPUFS_MMAP_4K */ |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 1300 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 1301 | static const struct file_operations spufs_signal2_fops = { |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 1302 | .open = spufs_signal2_open, |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 1303 | .release = spufs_signal2_release, |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1304 | .read = spufs_signal2_read, |
| 1305 | .write = spufs_signal2_write, |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 1306 | .mmap = spufs_signal2_mmap, |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1307 | }; |
| 1308 | |
Jeremy Kerr | d054b36 | 2007-07-20 21:39:31 +0200 | [diff] [blame] | 1309 | static const struct file_operations spufs_signal2_nosched_fops = { |
| 1310 | .open = spufs_signal2_open, |
| 1311 | .release = spufs_signal2_release, |
| 1312 | .write = spufs_signal2_write, |
| 1313 | .mmap = spufs_signal2_mmap, |
| 1314 | }; |
| 1315 | |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 1316 | /* |
| 1317 | * This is a wrapper around DEFINE_SIMPLE_ATTRIBUTE which does the |
| 1318 | * work of acquiring (or not) the SPU context before calling through |
| 1319 | * to the actual get routine. The set routine is called directly. |
| 1320 | */ |
| 1321 | #define SPU_ATTR_NOACQUIRE 0 |
| 1322 | #define SPU_ATTR_ACQUIRE 1 |
| 1323 | #define SPU_ATTR_ACQUIRE_SAVED 2 |
| 1324 | |
| 1325 | #define DEFINE_SPUFS_ATTRIBUTE(__name, __get, __set, __fmt, __acquire) \ |
Christoph Hellwig | 197b1a8 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1326 | static int __##__get(void *data, u64 *val) \ |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 1327 | { \ |
| 1328 | struct spu_context *ctx = data; \ |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1329 | int ret = 0; \ |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 1330 | \ |
| 1331 | if (__acquire == SPU_ATTR_ACQUIRE) { \ |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1332 | ret = spu_acquire(ctx); \ |
| 1333 | if (ret) \ |
| 1334 | return ret; \ |
Christoph Hellwig | 197b1a8 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1335 | *val = __get(ctx); \ |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 1336 | spu_release(ctx); \ |
| 1337 | } else if (__acquire == SPU_ATTR_ACQUIRE_SAVED) { \ |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1338 | ret = spu_acquire_saved(ctx); \ |
| 1339 | if (ret) \ |
| 1340 | return ret; \ |
Christoph Hellwig | 197b1a8 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1341 | *val = __get(ctx); \ |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 1342 | spu_release_saved(ctx); \ |
| 1343 | } else \ |
Christoph Hellwig | 197b1a8 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1344 | *val = __get(ctx); \ |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 1345 | \ |
Christoph Hellwig | 197b1a8 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1346 | return 0; \ |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 1347 | } \ |
Christoph Hellwig | 197b1a8 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1348 | DEFINE_SPUFS_SIMPLE_ATTRIBUTE(__name, __##__get, __set, __fmt); |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 1349 | |
Christoph Hellwig | 197b1a8 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1350 | static int spufs_signal1_type_set(void *data, u64 val) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1351 | { |
| 1352 | struct spu_context *ctx = data; |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1353 | int ret; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1354 | |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1355 | ret = spu_acquire(ctx); |
| 1356 | if (ret) |
| 1357 | return ret; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1358 | ctx->ops->signal1_type_set(ctx, val); |
| 1359 | spu_release(ctx); |
Christoph Hellwig | 197b1a8 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1360 | |
| 1361 | return 0; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1362 | } |
| 1363 | |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 1364 | static u64 spufs_signal1_type_get(struct spu_context *ctx) |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1365 | { |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1366 | return ctx->ops->signal1_type_get(ctx); |
| 1367 | } |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 1368 | DEFINE_SPUFS_ATTRIBUTE(spufs_signal1_type, spufs_signal1_type_get, |
Jeremy Kerr | af8b44e | 2008-03-25 13:15:11 +1100 | [diff] [blame] | 1369 | spufs_signal1_type_set, "%llu\n", SPU_ATTR_ACQUIRE); |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1370 | |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1371 | |
Christoph Hellwig | 197b1a8 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1372 | static int spufs_signal2_type_set(void *data, u64 val) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1373 | { |
| 1374 | struct spu_context *ctx = data; |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1375 | int ret; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1376 | |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1377 | ret = spu_acquire(ctx); |
| 1378 | if (ret) |
| 1379 | return ret; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1380 | ctx->ops->signal2_type_set(ctx, val); |
| 1381 | spu_release(ctx); |
Christoph Hellwig | 197b1a8 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1382 | |
| 1383 | return 0; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1384 | } |
| 1385 | |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 1386 | static u64 spufs_signal2_type_get(struct spu_context *ctx) |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1387 | { |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1388 | return ctx->ops->signal2_type_get(ctx); |
| 1389 | } |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 1390 | DEFINE_SPUFS_ATTRIBUTE(spufs_signal2_type, spufs_signal2_type_get, |
Jeremy Kerr | af8b44e | 2008-03-25 13:15:11 +1100 | [diff] [blame] | 1391 | spufs_signal2_type_set, "%llu\n", SPU_ATTR_ACQUIRE); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1392 | |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 1393 | #if SPUFS_MMAP_4K |
Nick Piggin | b1e2270 | 2008-06-10 09:26:08 +1000 | [diff] [blame] | 1394 | static int |
| 1395 | spufs_mss_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf) |
arnd@arndb.de | d9379c4 | 2006-06-19 20:33:21 +0200 | [diff] [blame] | 1396 | { |
Jeremy Kerr | 87ff609 | 2008-07-01 10:22:50 +1000 | [diff] [blame] | 1397 | return spufs_ps_fault(vma, vmf, 0x0000, SPUFS_MSS_MAP_SIZE); |
arnd@arndb.de | d9379c4 | 2006-06-19 20:33:21 +0200 | [diff] [blame] | 1398 | } |
| 1399 | |
Alexey Dobriyan | f0f37e2 | 2009-09-27 22:29:37 +0400 | [diff] [blame] | 1400 | static const struct vm_operations_struct spufs_mss_mmap_vmops = { |
Nick Piggin | b1e2270 | 2008-06-10 09:26:08 +1000 | [diff] [blame] | 1401 | .fault = spufs_mss_mmap_fault, |
arnd@arndb.de | d9379c4 | 2006-06-19 20:33:21 +0200 | [diff] [blame] | 1402 | }; |
| 1403 | |
| 1404 | /* |
| 1405 | * mmap support for problem state MFC DMA area [0x0000 - 0x0fff]. |
arnd@arndb.de | d9379c4 | 2006-06-19 20:33:21 +0200 | [diff] [blame] | 1406 | */ |
| 1407 | static int spufs_mss_mmap(struct file *file, struct vm_area_struct *vma) |
| 1408 | { |
| 1409 | if (!(vma->vm_flags & VM_SHARED)) |
| 1410 | return -EINVAL; |
| 1411 | |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 1412 | vma->vm_flags |= VM_IO | VM_PFNMAP; |
Benjamin Herrenschmidt | 64b3d0e | 2008-12-18 19:13:51 +0000 | [diff] [blame] | 1413 | vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); |
arnd@arndb.de | d9379c4 | 2006-06-19 20:33:21 +0200 | [diff] [blame] | 1414 | |
| 1415 | vma->vm_ops = &spufs_mss_mmap_vmops; |
| 1416 | return 0; |
| 1417 | } |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 1418 | #else /* SPUFS_MMAP_4K */ |
| 1419 | #define spufs_mss_mmap NULL |
| 1420 | #endif /* !SPUFS_MMAP_4K */ |
arnd@arndb.de | d9379c4 | 2006-06-19 20:33:21 +0200 | [diff] [blame] | 1421 | |
| 1422 | static int spufs_mss_open(struct inode *inode, struct file *file) |
| 1423 | { |
| 1424 | struct spufs_inode_info *i = SPUFS_I(inode); |
Benjamin Herrenschmidt | 17e0e27 | 2007-02-13 11:46:08 +1100 | [diff] [blame] | 1425 | struct spu_context *ctx = i->i_ctx; |
arnd@arndb.de | d9379c4 | 2006-06-19 20:33:21 +0200 | [diff] [blame] | 1426 | |
| 1427 | file->private_data = i->i_ctx; |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 1428 | |
Christoph Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 1429 | mutex_lock(&ctx->mapping_lock); |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 1430 | if (!i->i_openers++) |
| 1431 | ctx->mss = inode->i_mapping; |
Christoph Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 1432 | mutex_unlock(&ctx->mapping_lock); |
arnd@arndb.de | d9379c4 | 2006-06-19 20:33:21 +0200 | [diff] [blame] | 1433 | return nonseekable_open(inode, file); |
| 1434 | } |
| 1435 | |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 1436 | static int |
| 1437 | spufs_mss_release(struct inode *inode, struct file *file) |
| 1438 | { |
| 1439 | struct spufs_inode_info *i = SPUFS_I(inode); |
| 1440 | struct spu_context *ctx = i->i_ctx; |
| 1441 | |
Christoph Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 1442 | mutex_lock(&ctx->mapping_lock); |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 1443 | if (!--i->i_openers) |
| 1444 | ctx->mss = NULL; |
Christoph Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 1445 | mutex_unlock(&ctx->mapping_lock); |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 1446 | return 0; |
| 1447 | } |
| 1448 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 1449 | static const struct file_operations spufs_mss_fops = { |
arnd@arndb.de | d9379c4 | 2006-06-19 20:33:21 +0200 | [diff] [blame] | 1450 | .open = spufs_mss_open, |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 1451 | .release = spufs_mss_release, |
arnd@arndb.de | d9379c4 | 2006-06-19 20:33:21 +0200 | [diff] [blame] | 1452 | .mmap = spufs_mss_mmap, |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 1453 | }; |
| 1454 | |
Nick Piggin | b1e2270 | 2008-06-10 09:26:08 +1000 | [diff] [blame] | 1455 | static int |
| 1456 | spufs_psmap_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf) |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 1457 | { |
Jeremy Kerr | 87ff609 | 2008-07-01 10:22:50 +1000 | [diff] [blame] | 1458 | return spufs_ps_fault(vma, vmf, 0x0000, SPUFS_PS_MAP_SIZE); |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 1459 | } |
| 1460 | |
Alexey Dobriyan | f0f37e2 | 2009-09-27 22:29:37 +0400 | [diff] [blame] | 1461 | static const struct vm_operations_struct spufs_psmap_mmap_vmops = { |
Nick Piggin | b1e2270 | 2008-06-10 09:26:08 +1000 | [diff] [blame] | 1462 | .fault = spufs_psmap_mmap_fault, |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 1463 | }; |
| 1464 | |
| 1465 | /* |
| 1466 | * mmap support for full problem state area [0x00000 - 0x1ffff]. |
| 1467 | */ |
| 1468 | static int spufs_psmap_mmap(struct file *file, struct vm_area_struct *vma) |
| 1469 | { |
| 1470 | if (!(vma->vm_flags & VM_SHARED)) |
| 1471 | return -EINVAL; |
| 1472 | |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 1473 | vma->vm_flags |= VM_IO | VM_PFNMAP; |
Benjamin Herrenschmidt | 64b3d0e | 2008-12-18 19:13:51 +0000 | [diff] [blame] | 1474 | vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 1475 | |
| 1476 | vma->vm_ops = &spufs_psmap_mmap_vmops; |
| 1477 | return 0; |
| 1478 | } |
| 1479 | |
| 1480 | static int spufs_psmap_open(struct inode *inode, struct file *file) |
| 1481 | { |
| 1482 | struct spufs_inode_info *i = SPUFS_I(inode); |
Benjamin Herrenschmidt | 17e0e27 | 2007-02-13 11:46:08 +1100 | [diff] [blame] | 1483 | struct spu_context *ctx = i->i_ctx; |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 1484 | |
Christoph Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 1485 | mutex_lock(&ctx->mapping_lock); |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 1486 | file->private_data = i->i_ctx; |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 1487 | if (!i->i_openers++) |
| 1488 | ctx->psmap = inode->i_mapping; |
Christoph Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 1489 | mutex_unlock(&ctx->mapping_lock); |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 1490 | return nonseekable_open(inode, file); |
| 1491 | } |
| 1492 | |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 1493 | static int |
| 1494 | spufs_psmap_release(struct inode *inode, struct file *file) |
| 1495 | { |
| 1496 | struct spufs_inode_info *i = SPUFS_I(inode); |
| 1497 | struct spu_context *ctx = i->i_ctx; |
| 1498 | |
Christoph Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 1499 | mutex_lock(&ctx->mapping_lock); |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 1500 | if (!--i->i_openers) |
| 1501 | ctx->psmap = NULL; |
Christoph Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 1502 | mutex_unlock(&ctx->mapping_lock); |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 1503 | return 0; |
| 1504 | } |
| 1505 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 1506 | static const struct file_operations spufs_psmap_fops = { |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 1507 | .open = spufs_psmap_open, |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 1508 | .release = spufs_psmap_release, |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 1509 | .mmap = spufs_psmap_mmap, |
arnd@arndb.de | d9379c4 | 2006-06-19 20:33:21 +0200 | [diff] [blame] | 1510 | }; |
| 1511 | |
| 1512 | |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 1513 | #if SPUFS_MMAP_4K |
Nick Piggin | b1e2270 | 2008-06-10 09:26:08 +1000 | [diff] [blame] | 1514 | static int |
| 1515 | spufs_mfc_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf) |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 1516 | { |
Jeremy Kerr | 87ff609 | 2008-07-01 10:22:50 +1000 | [diff] [blame] | 1517 | return spufs_ps_fault(vma, vmf, 0x3000, SPUFS_MFC_MAP_SIZE); |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 1518 | } |
| 1519 | |
Alexey Dobriyan | f0f37e2 | 2009-09-27 22:29:37 +0400 | [diff] [blame] | 1520 | static const struct vm_operations_struct spufs_mfc_mmap_vmops = { |
Nick Piggin | b1e2270 | 2008-06-10 09:26:08 +1000 | [diff] [blame] | 1521 | .fault = spufs_mfc_mmap_fault, |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 1522 | }; |
| 1523 | |
| 1524 | /* |
| 1525 | * mmap support for problem state MFC DMA area [0x0000 - 0x0fff]. |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 1526 | */ |
| 1527 | static int spufs_mfc_mmap(struct file *file, struct vm_area_struct *vma) |
| 1528 | { |
| 1529 | if (!(vma->vm_flags & VM_SHARED)) |
| 1530 | return -EINVAL; |
| 1531 | |
Benjamin Herrenschmidt | 78bde53 | 2007-02-13 11:46:06 +1100 | [diff] [blame] | 1532 | vma->vm_flags |= VM_IO | VM_PFNMAP; |
Benjamin Herrenschmidt | 64b3d0e | 2008-12-18 19:13:51 +0000 | [diff] [blame] | 1533 | vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 1534 | |
| 1535 | vma->vm_ops = &spufs_mfc_mmap_vmops; |
| 1536 | return 0; |
| 1537 | } |
Benjamin Herrenschmidt | 27d5bf2 | 2006-10-04 17:26:11 +0200 | [diff] [blame] | 1538 | #else /* SPUFS_MMAP_4K */ |
| 1539 | #define spufs_mfc_mmap NULL |
| 1540 | #endif /* !SPUFS_MMAP_4K */ |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 1541 | |
| 1542 | static int spufs_mfc_open(struct inode *inode, struct file *file) |
| 1543 | { |
| 1544 | struct spufs_inode_info *i = SPUFS_I(inode); |
| 1545 | struct spu_context *ctx = i->i_ctx; |
| 1546 | |
| 1547 | /* we don't want to deal with DMA into other processes */ |
| 1548 | if (ctx->owner != current->mm) |
| 1549 | return -EINVAL; |
| 1550 | |
| 1551 | if (atomic_read(&inode->i_count) != 1) |
| 1552 | return -EBUSY; |
| 1553 | |
Christoph Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 1554 | mutex_lock(&ctx->mapping_lock); |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 1555 | file->private_data = ctx; |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 1556 | if (!i->i_openers++) |
| 1557 | ctx->mfc = inode->i_mapping; |
Christoph Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 1558 | mutex_unlock(&ctx->mapping_lock); |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 1559 | return nonseekable_open(inode, file); |
| 1560 | } |
| 1561 | |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 1562 | static int |
| 1563 | spufs_mfc_release(struct inode *inode, struct file *file) |
| 1564 | { |
| 1565 | struct spufs_inode_info *i = SPUFS_I(inode); |
| 1566 | struct spu_context *ctx = i->i_ctx; |
| 1567 | |
Christoph Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 1568 | mutex_lock(&ctx->mapping_lock); |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 1569 | if (!--i->i_openers) |
| 1570 | ctx->mfc = NULL; |
Christoph Hellwig | 47d3a5f | 2007-06-04 23:26:51 +1000 | [diff] [blame] | 1571 | mutex_unlock(&ctx->mapping_lock); |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 1572 | return 0; |
| 1573 | } |
| 1574 | |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 1575 | /* interrupt-level mfc callback function. */ |
| 1576 | void spufs_mfc_callback(struct spu *spu) |
| 1577 | { |
| 1578 | struct spu_context *ctx = spu->ctx; |
| 1579 | |
Luke Browning | e65c2f6 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1580 | if (!ctx) |
| 1581 | return; |
| 1582 | |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 1583 | wake_up_all(&ctx->mfc_wq); |
| 1584 | |
Harvey Harrison | e48b1b4 | 2008-03-29 08:21:07 +1100 | [diff] [blame] | 1585 | pr_debug("%s %s\n", __func__, spu->name); |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 1586 | if (ctx->mfc_fasync) { |
| 1587 | u32 free_elements, tagstatus; |
| 1588 | unsigned int mask; |
| 1589 | |
| 1590 | /* no need for spu_acquire in interrupt context */ |
| 1591 | free_elements = ctx->ops->get_mfc_free_elements(ctx); |
| 1592 | tagstatus = ctx->ops->read_mfc_tagstatus(ctx); |
| 1593 | |
| 1594 | mask = 0; |
| 1595 | if (free_elements & 0xffff) |
| 1596 | mask |= POLLOUT; |
| 1597 | if (tagstatus & ctx->tagwait) |
| 1598 | mask |= POLLIN; |
| 1599 | |
| 1600 | kill_fasync(&ctx->mfc_fasync, SIGIO, mask); |
| 1601 | } |
| 1602 | } |
| 1603 | |
| 1604 | static int spufs_read_mfc_tagstatus(struct spu_context *ctx, u32 *status) |
| 1605 | { |
| 1606 | /* See if there is one tag group is complete */ |
| 1607 | /* FIXME we need locking around tagwait */ |
| 1608 | *status = ctx->ops->read_mfc_tagstatus(ctx) & ctx->tagwait; |
| 1609 | ctx->tagwait &= ~*status; |
| 1610 | if (*status) |
| 1611 | return 1; |
| 1612 | |
| 1613 | /* enable interrupt waiting for any tag group, |
| 1614 | may silently fail if interrupts are already enabled */ |
| 1615 | ctx->ops->set_mfc_query(ctx, ctx->tagwait, 1); |
| 1616 | return 0; |
| 1617 | } |
| 1618 | |
| 1619 | static ssize_t spufs_mfc_read(struct file *file, char __user *buffer, |
| 1620 | size_t size, loff_t *pos) |
| 1621 | { |
| 1622 | struct spu_context *ctx = file->private_data; |
| 1623 | int ret = -EINVAL; |
| 1624 | u32 status; |
| 1625 | |
| 1626 | if (size != 4) |
| 1627 | goto out; |
| 1628 | |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1629 | ret = spu_acquire(ctx); |
| 1630 | if (ret) |
| 1631 | return ret; |
| 1632 | |
| 1633 | ret = -EINVAL; |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 1634 | if (file->f_flags & O_NONBLOCK) { |
| 1635 | status = ctx->ops->read_mfc_tagstatus(ctx); |
| 1636 | if (!(status & ctx->tagwait)) |
| 1637 | ret = -EAGAIN; |
| 1638 | else |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1639 | /* XXX(hch): shouldn't we clear ret here? */ |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 1640 | ctx->tagwait &= ~status; |
| 1641 | } else { |
| 1642 | ret = spufs_wait(ctx->mfc_wq, |
| 1643 | spufs_read_mfc_tagstatus(ctx, &status)); |
Christoph Hellwig | eebead5 | 2008-02-08 15:50:41 +1100 | [diff] [blame] | 1644 | if (ret) |
| 1645 | goto out; |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 1646 | } |
| 1647 | spu_release(ctx); |
| 1648 | |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 1649 | ret = 4; |
| 1650 | if (copy_to_user(buffer, &status, 4)) |
| 1651 | ret = -EFAULT; |
| 1652 | |
| 1653 | out: |
| 1654 | return ret; |
| 1655 | } |
| 1656 | |
| 1657 | static int spufs_check_valid_dma(struct mfc_dma_command *cmd) |
| 1658 | { |
Stephen Rothwell | 9477e45 | 2009-01-06 14:27:38 +0000 | [diff] [blame] | 1659 | pr_debug("queueing DMA %x %llx %x %x %x\n", cmd->lsa, |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 1660 | cmd->ea, cmd->size, cmd->tag, cmd->cmd); |
| 1661 | |
| 1662 | switch (cmd->cmd) { |
| 1663 | case MFC_PUT_CMD: |
| 1664 | case MFC_PUTF_CMD: |
| 1665 | case MFC_PUTB_CMD: |
| 1666 | case MFC_GET_CMD: |
| 1667 | case MFC_GETF_CMD: |
| 1668 | case MFC_GETB_CMD: |
| 1669 | break; |
| 1670 | default: |
| 1671 | pr_debug("invalid DMA opcode %x\n", cmd->cmd); |
| 1672 | return -EIO; |
| 1673 | } |
| 1674 | |
| 1675 | if ((cmd->lsa & 0xf) != (cmd->ea &0xf)) { |
Stephen Rothwell | 9477e45 | 2009-01-06 14:27:38 +0000 | [diff] [blame] | 1676 | pr_debug("invalid DMA alignment, ea %llx lsa %x\n", |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 1677 | cmd->ea, cmd->lsa); |
| 1678 | return -EIO; |
| 1679 | } |
| 1680 | |
| 1681 | switch (cmd->size & 0xf) { |
| 1682 | case 1: |
| 1683 | break; |
| 1684 | case 2: |
| 1685 | if (cmd->lsa & 1) |
| 1686 | goto error; |
| 1687 | break; |
| 1688 | case 4: |
| 1689 | if (cmd->lsa & 3) |
| 1690 | goto error; |
| 1691 | break; |
| 1692 | case 8: |
| 1693 | if (cmd->lsa & 7) |
| 1694 | goto error; |
| 1695 | break; |
| 1696 | case 0: |
| 1697 | if (cmd->lsa & 15) |
| 1698 | goto error; |
| 1699 | break; |
| 1700 | error: |
| 1701 | default: |
| 1702 | pr_debug("invalid DMA alignment %x for size %x\n", |
| 1703 | cmd->lsa & 0xf, cmd->size); |
| 1704 | return -EIO; |
| 1705 | } |
| 1706 | |
| 1707 | if (cmd->size > 16 * 1024) { |
| 1708 | pr_debug("invalid DMA size %x\n", cmd->size); |
| 1709 | return -EIO; |
| 1710 | } |
| 1711 | |
| 1712 | if (cmd->tag & 0xfff0) { |
| 1713 | /* we reserve the higher tag numbers for kernel use */ |
| 1714 | pr_debug("invalid DMA tag\n"); |
| 1715 | return -EIO; |
| 1716 | } |
| 1717 | |
| 1718 | if (cmd->class) { |
| 1719 | /* not supported in this version */ |
| 1720 | pr_debug("invalid DMA class\n"); |
| 1721 | return -EIO; |
| 1722 | } |
| 1723 | |
| 1724 | return 0; |
| 1725 | } |
| 1726 | |
| 1727 | static int spu_send_mfc_command(struct spu_context *ctx, |
| 1728 | struct mfc_dma_command cmd, |
| 1729 | int *error) |
| 1730 | { |
| 1731 | *error = ctx->ops->send_mfc_command(ctx, &cmd); |
| 1732 | if (*error == -EAGAIN) { |
| 1733 | /* wait for any tag group to complete |
| 1734 | so we have space for the new command */ |
| 1735 | ctx->ops->set_mfc_query(ctx, ctx->tagwait, 1); |
| 1736 | /* try again, because the queue might be |
| 1737 | empty again */ |
| 1738 | *error = ctx->ops->send_mfc_command(ctx, &cmd); |
| 1739 | if (*error == -EAGAIN) |
| 1740 | return 0; |
| 1741 | } |
| 1742 | return 1; |
| 1743 | } |
| 1744 | |
| 1745 | static ssize_t spufs_mfc_write(struct file *file, const char __user *buffer, |
| 1746 | size_t size, loff_t *pos) |
| 1747 | { |
| 1748 | struct spu_context *ctx = file->private_data; |
| 1749 | struct mfc_dma_command cmd; |
| 1750 | int ret = -EINVAL; |
| 1751 | |
| 1752 | if (size != sizeof cmd) |
| 1753 | goto out; |
| 1754 | |
| 1755 | ret = -EFAULT; |
| 1756 | if (copy_from_user(&cmd, buffer, sizeof cmd)) |
| 1757 | goto out; |
| 1758 | |
| 1759 | ret = spufs_check_valid_dma(&cmd); |
| 1760 | if (ret) |
| 1761 | goto out; |
| 1762 | |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1763 | ret = spu_acquire(ctx); |
| 1764 | if (ret) |
| 1765 | goto out; |
| 1766 | |
Arnd Bergmann | 33bfd7a | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1767 | ret = spufs_wait(ctx->run_wq, ctx->state == SPU_STATE_RUNNABLE); |
Akinobu Mita | 577f8f1 | 2007-04-23 21:08:18 +0200 | [diff] [blame] | 1768 | if (ret) |
| 1769 | goto out; |
| 1770 | |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 1771 | if (file->f_flags & O_NONBLOCK) { |
| 1772 | ret = ctx->ops->send_mfc_command(ctx, &cmd); |
| 1773 | } else { |
| 1774 | int status; |
| 1775 | ret = spufs_wait(ctx->mfc_wq, |
| 1776 | spu_send_mfc_command(ctx, cmd, &status)); |
Christoph Hellwig | eebead5 | 2008-02-08 15:50:41 +1100 | [diff] [blame] | 1777 | if (ret) |
| 1778 | goto out; |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 1779 | if (status) |
| 1780 | ret = status; |
| 1781 | } |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 1782 | |
| 1783 | if (ret) |
Kazunori Asayama | 933b0e3 | 2007-06-29 10:58:08 +1000 | [diff] [blame] | 1784 | goto out_unlock; |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 1785 | |
| 1786 | ctx->tagwait |= 1 << cmd.tag; |
Masato Noguchi | 3692dc6 | 2006-11-20 18:45:07 +0100 | [diff] [blame] | 1787 | ret = size; |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 1788 | |
Kazunori Asayama | 933b0e3 | 2007-06-29 10:58:08 +1000 | [diff] [blame] | 1789 | out_unlock: |
| 1790 | spu_release(ctx); |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 1791 | out: |
| 1792 | return ret; |
| 1793 | } |
| 1794 | |
| 1795 | static unsigned int spufs_mfc_poll(struct file *file,poll_table *wait) |
| 1796 | { |
| 1797 | struct spu_context *ctx = file->private_data; |
| 1798 | u32 free_elements, tagstatus; |
| 1799 | unsigned int mask; |
| 1800 | |
Kazunori Asayama | 933b0e3 | 2007-06-29 10:58:08 +1000 | [diff] [blame] | 1801 | poll_wait(file, &ctx->mfc_wq, wait); |
| 1802 | |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1803 | /* |
| 1804 | * For now keep this uninterruptible and also ignore the rule |
| 1805 | * that poll should not sleep. Will be fixed later. |
| 1806 | */ |
| 1807 | mutex_lock(&ctx->state_mutex); |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 1808 | ctx->ops->set_mfc_query(ctx, ctx->tagwait, 2); |
| 1809 | free_elements = ctx->ops->get_mfc_free_elements(ctx); |
| 1810 | tagstatus = ctx->ops->read_mfc_tagstatus(ctx); |
| 1811 | spu_release(ctx); |
| 1812 | |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 1813 | mask = 0; |
| 1814 | if (free_elements & 0xffff) |
| 1815 | mask |= POLLOUT | POLLWRNORM; |
| 1816 | if (tagstatus & ctx->tagwait) |
| 1817 | mask |= POLLIN | POLLRDNORM; |
| 1818 | |
Harvey Harrison | e48b1b4 | 2008-03-29 08:21:07 +1100 | [diff] [blame] | 1819 | pr_debug("%s: free %d tagstatus %d tagwait %d\n", __func__, |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 1820 | free_elements, tagstatus, ctx->tagwait); |
| 1821 | |
| 1822 | return mask; |
| 1823 | } |
| 1824 | |
Al Viro | 73b6af8 | 2006-06-25 16:42:33 -0700 | [diff] [blame] | 1825 | static int spufs_mfc_flush(struct file *file, fl_owner_t id) |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 1826 | { |
| 1827 | struct spu_context *ctx = file->private_data; |
| 1828 | int ret; |
| 1829 | |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1830 | ret = spu_acquire(ctx); |
| 1831 | if (ret) |
Christoph Hellwig | eebead5 | 2008-02-08 15:50:41 +1100 | [diff] [blame] | 1832 | goto out; |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 1833 | #if 0 |
| 1834 | /* this currently hangs */ |
| 1835 | ret = spufs_wait(ctx->mfc_wq, |
| 1836 | ctx->ops->set_mfc_query(ctx, ctx->tagwait, 2)); |
| 1837 | if (ret) |
| 1838 | goto out; |
| 1839 | ret = spufs_wait(ctx->mfc_wq, |
| 1840 | ctx->ops->read_mfc_tagstatus(ctx) == ctx->tagwait); |
Christoph Hellwig | eebead5 | 2008-02-08 15:50:41 +1100 | [diff] [blame] | 1841 | if (ret) |
| 1842 | goto out; |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 1843 | #else |
| 1844 | ret = 0; |
| 1845 | #endif |
| 1846 | spu_release(ctx); |
Christoph Hellwig | eebead5 | 2008-02-08 15:50:41 +1100 | [diff] [blame] | 1847 | out: |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 1848 | return ret; |
| 1849 | } |
| 1850 | |
| 1851 | static int spufs_mfc_fsync(struct file *file, struct dentry *dentry, |
| 1852 | int datasync) |
| 1853 | { |
Al Viro | 73b6af8 | 2006-06-25 16:42:33 -0700 | [diff] [blame] | 1854 | return spufs_mfc_flush(file, NULL); |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 1855 | } |
| 1856 | |
| 1857 | static int spufs_mfc_fasync(int fd, struct file *file, int on) |
| 1858 | { |
| 1859 | struct spu_context *ctx = file->private_data; |
| 1860 | |
| 1861 | return fasync_helper(fd, file, on, &ctx->mfc_fasync); |
| 1862 | } |
| 1863 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 1864 | static const struct file_operations spufs_mfc_fops = { |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 1865 | .open = spufs_mfc_open, |
Christoph Hellwig | 43c2bbd | 2007-04-23 21:08:07 +0200 | [diff] [blame] | 1866 | .release = spufs_mfc_release, |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 1867 | .read = spufs_mfc_read, |
| 1868 | .write = spufs_mfc_write, |
| 1869 | .poll = spufs_mfc_poll, |
| 1870 | .flush = spufs_mfc_flush, |
| 1871 | .fsync = spufs_mfc_fsync, |
| 1872 | .fasync = spufs_mfc_fasync, |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 1873 | .mmap = spufs_mfc_mmap, |
Arnd Bergmann | a33a7d7 | 2006-03-23 00:00:11 +0100 | [diff] [blame] | 1874 | }; |
| 1875 | |
Christoph Hellwig | 197b1a8 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1876 | static int spufs_npc_set(void *data, u64 val) |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1877 | { |
| 1878 | struct spu_context *ctx = data; |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1879 | int ret; |
| 1880 | |
| 1881 | ret = spu_acquire(ctx); |
| 1882 | if (ret) |
| 1883 | return ret; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1884 | ctx->ops->npc_write(ctx, val); |
| 1885 | spu_release(ctx); |
Christoph Hellwig | 197b1a8 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1886 | |
| 1887 | return 0; |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1888 | } |
| 1889 | |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 1890 | static u64 spufs_npc_get(struct spu_context *ctx) |
Michael Ellerman | 78810ff | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 1891 | { |
| 1892 | return ctx->ops->npc_read(ctx); |
| 1893 | } |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 1894 | DEFINE_SPUFS_ATTRIBUTE(spufs_npc_ops, spufs_npc_get, spufs_npc_set, |
| 1895 | "0x%llx\n", SPU_ATTR_ACQUIRE); |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 1896 | |
Christoph Hellwig | 197b1a8 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1897 | static int spufs_decr_set(void *data, u64 val) |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1898 | { |
| 1899 | struct spu_context *ctx = data; |
| 1900 | struct spu_lscsa *lscsa = ctx->csa.lscsa; |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1901 | int ret; |
| 1902 | |
| 1903 | ret = spu_acquire_saved(ctx); |
| 1904 | if (ret) |
| 1905 | return ret; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1906 | lscsa->decr.slot[0] = (u32) val; |
Christoph Hellwig | 27b1ea0 | 2007-07-20 21:39:34 +0200 | [diff] [blame] | 1907 | spu_release_saved(ctx); |
Christoph Hellwig | 197b1a8 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1908 | |
| 1909 | return 0; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1910 | } |
| 1911 | |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 1912 | static u64 spufs_decr_get(struct spu_context *ctx) |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1913 | { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1914 | struct spu_lscsa *lscsa = ctx->csa.lscsa; |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1915 | return lscsa->decr.slot[0]; |
| 1916 | } |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 1917 | DEFINE_SPUFS_ATTRIBUTE(spufs_decr_ops, spufs_decr_get, spufs_decr_set, |
| 1918 | "0x%llx\n", SPU_ATTR_ACQUIRE_SAVED); |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1919 | |
Christoph Hellwig | 197b1a8 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1920 | static int spufs_decr_status_set(void *data, u64 val) |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1921 | { |
| 1922 | struct spu_context *ctx = data; |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1923 | int ret; |
| 1924 | |
| 1925 | ret = spu_acquire_saved(ctx); |
| 1926 | if (ret) |
| 1927 | return ret; |
Masato Noguchi | d40a01d | 2007-07-20 21:39:38 +0200 | [diff] [blame] | 1928 | if (val) |
| 1929 | ctx->csa.priv2.mfc_control_RW |= MFC_CNTL_DECREMENTER_RUNNING; |
| 1930 | else |
| 1931 | ctx->csa.priv2.mfc_control_RW &= ~MFC_CNTL_DECREMENTER_RUNNING; |
Christoph Hellwig | 27b1ea0 | 2007-07-20 21:39:34 +0200 | [diff] [blame] | 1932 | spu_release_saved(ctx); |
Christoph Hellwig | 197b1a8 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1933 | |
| 1934 | return 0; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1935 | } |
| 1936 | |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 1937 | static u64 spufs_decr_status_get(struct spu_context *ctx) |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1938 | { |
Masato Noguchi | d40a01d | 2007-07-20 21:39:38 +0200 | [diff] [blame] | 1939 | if (ctx->csa.priv2.mfc_control_RW & MFC_CNTL_DECREMENTER_RUNNING) |
| 1940 | return SPU_DECR_STATUS_RUNNING; |
| 1941 | else |
| 1942 | return 0; |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1943 | } |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 1944 | DEFINE_SPUFS_ATTRIBUTE(spufs_decr_status_ops, spufs_decr_status_get, |
| 1945 | spufs_decr_status_set, "0x%llx\n", |
| 1946 | SPU_ATTR_ACQUIRE_SAVED); |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1947 | |
Christoph Hellwig | 197b1a8 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1948 | static int spufs_event_mask_set(void *data, u64 val) |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1949 | { |
| 1950 | struct spu_context *ctx = data; |
| 1951 | struct spu_lscsa *lscsa = ctx->csa.lscsa; |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1952 | int ret; |
| 1953 | |
| 1954 | ret = spu_acquire_saved(ctx); |
| 1955 | if (ret) |
| 1956 | return ret; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1957 | lscsa->event_mask.slot[0] = (u32) val; |
Christoph Hellwig | 27b1ea0 | 2007-07-20 21:39:34 +0200 | [diff] [blame] | 1958 | spu_release_saved(ctx); |
Christoph Hellwig | 197b1a8 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1959 | |
| 1960 | return 0; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1961 | } |
| 1962 | |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 1963 | static u64 spufs_event_mask_get(struct spu_context *ctx) |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1964 | { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1965 | struct spu_lscsa *lscsa = ctx->csa.lscsa; |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1966 | return lscsa->event_mask.slot[0]; |
| 1967 | } |
| 1968 | |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 1969 | DEFINE_SPUFS_ATTRIBUTE(spufs_event_mask_ops, spufs_event_mask_get, |
| 1970 | spufs_event_mask_set, "0x%llx\n", |
| 1971 | SPU_ATTR_ACQUIRE_SAVED); |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1972 | |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 1973 | static u64 spufs_event_status_get(struct spu_context *ctx) |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 1974 | { |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 1975 | struct spu_state *state = &ctx->csa; |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 1976 | u64 stat; |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 1977 | stat = state->spu_chnlcnt_RW[0]; |
| 1978 | if (stat) |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 1979 | return state->spu_chnldata_RW[0]; |
| 1980 | return 0; |
| 1981 | } |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 1982 | DEFINE_SPUFS_ATTRIBUTE(spufs_event_status_ops, spufs_event_status_get, |
| 1983 | NULL, "0x%llx\n", SPU_ATTR_ACQUIRE_SAVED) |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 1984 | |
Christoph Hellwig | 197b1a8 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1985 | static int spufs_srr0_set(void *data, u64 val) |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1986 | { |
| 1987 | struct spu_context *ctx = data; |
| 1988 | struct spu_lscsa *lscsa = ctx->csa.lscsa; |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1989 | int ret; |
| 1990 | |
| 1991 | ret = spu_acquire_saved(ctx); |
| 1992 | if (ret) |
| 1993 | return ret; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1994 | lscsa->srr0.slot[0] = (u32) val; |
Christoph Hellwig | 27b1ea0 | 2007-07-20 21:39:34 +0200 | [diff] [blame] | 1995 | spu_release_saved(ctx); |
Christoph Hellwig | 197b1a8 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 1996 | |
| 1997 | return 0; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 1998 | } |
| 1999 | |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 2000 | static u64 spufs_srr0_get(struct spu_context *ctx) |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 2001 | { |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 2002 | struct spu_lscsa *lscsa = ctx->csa.lscsa; |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 2003 | return lscsa->srr0.slot[0]; |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 2004 | } |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 2005 | DEFINE_SPUFS_ATTRIBUTE(spufs_srr0_ops, spufs_srr0_get, spufs_srr0_set, |
| 2006 | "0x%llx\n", SPU_ATTR_ACQUIRE_SAVED) |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 2007 | |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 2008 | static u64 spufs_id_get(struct spu_context *ctx) |
arnd@arndb.de | 7b1a701 | 2006-06-19 20:33:24 +0200 | [diff] [blame] | 2009 | { |
arnd@arndb.de | 7b1a701 | 2006-06-19 20:33:24 +0200 | [diff] [blame] | 2010 | u64 num; |
| 2011 | |
arnd@arndb.de | 7b1a701 | 2006-06-19 20:33:24 +0200 | [diff] [blame] | 2012 | if (ctx->state == SPU_STATE_RUNNABLE) |
| 2013 | num = ctx->spu->number; |
| 2014 | else |
| 2015 | num = (unsigned int)-1; |
arnd@arndb.de | 7b1a701 | 2006-06-19 20:33:24 +0200 | [diff] [blame] | 2016 | |
| 2017 | return num; |
| 2018 | } |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 2019 | DEFINE_SPUFS_ATTRIBUTE(spufs_id_ops, spufs_id_get, NULL, "0x%llx\n", |
| 2020 | SPU_ATTR_ACQUIRE) |
arnd@arndb.de | 7b1a701 | 2006-06-19 20:33:24 +0200 | [diff] [blame] | 2021 | |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 2022 | static u64 spufs_object_id_get(struct spu_context *ctx) |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 2023 | { |
| 2024 | /* FIXME: Should there really be no locking here? */ |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 2025 | return ctx->object_id; |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 2026 | } |
| 2027 | |
Christoph Hellwig | 197b1a8 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 2028 | static int spufs_object_id_set(void *data, u64 id) |
Arnd Bergmann | 8676727 | 2006-10-04 17:26:21 +0200 | [diff] [blame] | 2029 | { |
| 2030 | struct spu_context *ctx = data; |
| 2031 | ctx->object_id = id; |
Christoph Hellwig | 197b1a8 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 2032 | |
| 2033 | return 0; |
Arnd Bergmann | 8676727 | 2006-10-04 17:26:21 +0200 | [diff] [blame] | 2034 | } |
| 2035 | |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 2036 | DEFINE_SPUFS_ATTRIBUTE(spufs_object_id_ops, spufs_object_id_get, |
| 2037 | spufs_object_id_set, "0x%llx\n", SPU_ATTR_NOACQUIRE); |
Arnd Bergmann | 8676727 | 2006-10-04 17:26:21 +0200 | [diff] [blame] | 2038 | |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 2039 | static u64 spufs_lslr_get(struct spu_context *ctx) |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 2040 | { |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 2041 | return ctx->csa.priv2.spu_lslr_RW; |
| 2042 | } |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 2043 | DEFINE_SPUFS_ATTRIBUTE(spufs_lslr_ops, spufs_lslr_get, NULL, "0x%llx\n", |
| 2044 | SPU_ATTR_ACQUIRE_SAVED); |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 2045 | |
| 2046 | static int spufs_info_open(struct inode *inode, struct file *file) |
| 2047 | { |
| 2048 | struct spufs_inode_info *i = SPUFS_I(inode); |
| 2049 | struct spu_context *ctx = i->i_ctx; |
| 2050 | file->private_data = ctx; |
| 2051 | return 0; |
| 2052 | } |
| 2053 | |
Benjamin Herrenschmidt | cbe709c | 2007-06-04 15:15:38 +1000 | [diff] [blame] | 2054 | static int spufs_caps_show(struct seq_file *s, void *private) |
| 2055 | { |
| 2056 | struct spu_context *ctx = s->private; |
| 2057 | |
| 2058 | if (!(ctx->flags & SPU_CREATE_NOSCHED)) |
| 2059 | seq_puts(s, "sched\n"); |
| 2060 | if (!(ctx->flags & SPU_CREATE_ISOLATE)) |
| 2061 | seq_puts(s, "step\n"); |
| 2062 | return 0; |
| 2063 | } |
| 2064 | |
| 2065 | static int spufs_caps_open(struct inode *inode, struct file *file) |
| 2066 | { |
| 2067 | return single_open(file, spufs_caps_show, SPUFS_I(inode)->i_ctx); |
| 2068 | } |
| 2069 | |
| 2070 | static const struct file_operations spufs_caps_fops = { |
| 2071 | .open = spufs_caps_open, |
| 2072 | .read = seq_read, |
| 2073 | .llseek = seq_lseek, |
| 2074 | .release = single_release, |
| 2075 | }; |
| 2076 | |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 2077 | static ssize_t __spufs_mbox_info_read(struct spu_context *ctx, |
| 2078 | char __user *buf, size_t len, loff_t *pos) |
| 2079 | { |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 2080 | u32 data; |
| 2081 | |
Jeremy Kerr | cbea923 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 2082 | /* EOF if there's no entry in the mbox */ |
| 2083 | if (!(ctx->csa.prob.mb_stat_R & 0x0000ff)) |
| 2084 | return 0; |
| 2085 | |
| 2086 | data = ctx->csa.prob.pu_mb_R; |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 2087 | |
| 2088 | return simple_read_from_buffer(buf, len, pos, &data, sizeof data); |
| 2089 | } |
| 2090 | |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 2091 | static ssize_t spufs_mbox_info_read(struct file *file, char __user *buf, |
| 2092 | size_t len, loff_t *pos) |
| 2093 | { |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 2094 | int ret; |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 2095 | struct spu_context *ctx = file->private_data; |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 2096 | |
| 2097 | if (!access_ok(VERIFY_WRITE, buf, len)) |
| 2098 | return -EFAULT; |
| 2099 | |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 2100 | ret = spu_acquire_saved(ctx); |
| 2101 | if (ret) |
| 2102 | return ret; |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 2103 | spin_lock(&ctx->csa.register_lock); |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 2104 | ret = __spufs_mbox_info_read(ctx, buf, len, pos); |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 2105 | spin_unlock(&ctx->csa.register_lock); |
Christoph Hellwig | 27b1ea0 | 2007-07-20 21:39:34 +0200 | [diff] [blame] | 2106 | spu_release_saved(ctx); |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 2107 | |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 2108 | return ret; |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 2109 | } |
| 2110 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 2111 | static const struct file_operations spufs_mbox_info_fops = { |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 2112 | .open = spufs_info_open, |
| 2113 | .read = spufs_mbox_info_read, |
| 2114 | .llseek = generic_file_llseek, |
| 2115 | }; |
| 2116 | |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 2117 | static ssize_t __spufs_ibox_info_read(struct spu_context *ctx, |
| 2118 | char __user *buf, size_t len, loff_t *pos) |
| 2119 | { |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 2120 | u32 data; |
| 2121 | |
Jeremy Kerr | cbea923 | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 2122 | /* EOF if there's no entry in the ibox */ |
| 2123 | if (!(ctx->csa.prob.mb_stat_R & 0xff0000)) |
| 2124 | return 0; |
| 2125 | |
| 2126 | data = ctx->csa.priv2.puint_mb_R; |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 2127 | |
| 2128 | return simple_read_from_buffer(buf, len, pos, &data, sizeof data); |
| 2129 | } |
| 2130 | |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 2131 | static ssize_t spufs_ibox_info_read(struct file *file, char __user *buf, |
| 2132 | size_t len, loff_t *pos) |
| 2133 | { |
| 2134 | struct spu_context *ctx = file->private_data; |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 2135 | int ret; |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 2136 | |
| 2137 | if (!access_ok(VERIFY_WRITE, buf, len)) |
| 2138 | return -EFAULT; |
| 2139 | |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 2140 | ret = spu_acquire_saved(ctx); |
| 2141 | if (ret) |
| 2142 | return ret; |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 2143 | spin_lock(&ctx->csa.register_lock); |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 2144 | ret = __spufs_ibox_info_read(ctx, buf, len, pos); |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 2145 | spin_unlock(&ctx->csa.register_lock); |
Christoph Hellwig | 27b1ea0 | 2007-07-20 21:39:34 +0200 | [diff] [blame] | 2146 | spu_release_saved(ctx); |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 2147 | |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 2148 | return ret; |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 2149 | } |
| 2150 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 2151 | static const struct file_operations spufs_ibox_info_fops = { |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 2152 | .open = spufs_info_open, |
| 2153 | .read = spufs_ibox_info_read, |
| 2154 | .llseek = generic_file_llseek, |
| 2155 | }; |
| 2156 | |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 2157 | static ssize_t __spufs_wbox_info_read(struct spu_context *ctx, |
| 2158 | char __user *buf, size_t len, loff_t *pos) |
| 2159 | { |
| 2160 | int i, cnt; |
| 2161 | u32 data[4]; |
| 2162 | u32 wbox_stat; |
| 2163 | |
| 2164 | wbox_stat = ctx->csa.prob.mb_stat_R; |
| 2165 | cnt = 4 - ((wbox_stat & 0x00ff00) >> 8); |
| 2166 | for (i = 0; i < cnt; i++) { |
| 2167 | data[i] = ctx->csa.spu_mailbox_data[i]; |
| 2168 | } |
| 2169 | |
| 2170 | return simple_read_from_buffer(buf, len, pos, &data, |
| 2171 | cnt * sizeof(u32)); |
| 2172 | } |
| 2173 | |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 2174 | static ssize_t spufs_wbox_info_read(struct file *file, char __user *buf, |
| 2175 | size_t len, loff_t *pos) |
| 2176 | { |
| 2177 | struct spu_context *ctx = file->private_data; |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 2178 | int ret; |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 2179 | |
| 2180 | if (!access_ok(VERIFY_WRITE, buf, len)) |
| 2181 | return -EFAULT; |
| 2182 | |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 2183 | ret = spu_acquire_saved(ctx); |
| 2184 | if (ret) |
| 2185 | return ret; |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 2186 | spin_lock(&ctx->csa.register_lock); |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 2187 | ret = __spufs_wbox_info_read(ctx, buf, len, pos); |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 2188 | spin_unlock(&ctx->csa.register_lock); |
Christoph Hellwig | 27b1ea0 | 2007-07-20 21:39:34 +0200 | [diff] [blame] | 2189 | spu_release_saved(ctx); |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 2190 | |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 2191 | return ret; |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 2192 | } |
| 2193 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 2194 | static const struct file_operations spufs_wbox_info_fops = { |
Dwayne Grant McConnell | 69a2f00 | 2006-11-20 18:45:00 +0100 | [diff] [blame] | 2195 | .open = spufs_info_open, |
| 2196 | .read = spufs_wbox_info_read, |
| 2197 | .llseek = generic_file_llseek, |
| 2198 | }; |
| 2199 | |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 2200 | static ssize_t __spufs_dma_info_read(struct spu_context *ctx, |
| 2201 | char __user *buf, size_t len, loff_t *pos) |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 2202 | { |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 2203 | struct spu_dma_info info; |
| 2204 | struct mfc_cq_sr *qp, *spuqp; |
| 2205 | int i; |
| 2206 | |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 2207 | info.dma_info_type = ctx->csa.priv2.spu_tag_status_query_RW; |
| 2208 | info.dma_info_mask = ctx->csa.lscsa->tag_mask.slot[0]; |
| 2209 | info.dma_info_status = ctx->csa.spu_chnldata_RW[24]; |
| 2210 | info.dma_info_stall_and_notify = ctx->csa.spu_chnldata_RW[25]; |
| 2211 | info.dma_info_atomic_command_status = ctx->csa.spu_chnldata_RW[27]; |
| 2212 | for (i = 0; i < 16; i++) { |
| 2213 | qp = &info.dma_info_command_data[i]; |
| 2214 | spuqp = &ctx->csa.priv2.spuq[i]; |
| 2215 | |
| 2216 | qp->mfc_cq_data0_RW = spuqp->mfc_cq_data0_RW; |
| 2217 | qp->mfc_cq_data1_RW = spuqp->mfc_cq_data1_RW; |
| 2218 | qp->mfc_cq_data2_RW = spuqp->mfc_cq_data2_RW; |
| 2219 | qp->mfc_cq_data3_RW = spuqp->mfc_cq_data3_RW; |
| 2220 | } |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 2221 | |
| 2222 | return simple_read_from_buffer(buf, len, pos, &info, |
| 2223 | sizeof info); |
| 2224 | } |
| 2225 | |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 2226 | static ssize_t spufs_dma_info_read(struct file *file, char __user *buf, |
| 2227 | size_t len, loff_t *pos) |
| 2228 | { |
| 2229 | struct spu_context *ctx = file->private_data; |
| 2230 | int ret; |
| 2231 | |
| 2232 | if (!access_ok(VERIFY_WRITE, buf, len)) |
| 2233 | return -EFAULT; |
| 2234 | |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 2235 | ret = spu_acquire_saved(ctx); |
| 2236 | if (ret) |
| 2237 | return ret; |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 2238 | spin_lock(&ctx->csa.register_lock); |
| 2239 | ret = __spufs_dma_info_read(ctx, buf, len, pos); |
| 2240 | spin_unlock(&ctx->csa.register_lock); |
Christoph Hellwig | 27b1ea0 | 2007-07-20 21:39:34 +0200 | [diff] [blame] | 2241 | spu_release_saved(ctx); |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 2242 | |
| 2243 | return ret; |
| 2244 | } |
| 2245 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 2246 | static const struct file_operations spufs_dma_info_fops = { |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 2247 | .open = spufs_info_open, |
| 2248 | .read = spufs_dma_info_read, |
| 2249 | }; |
| 2250 | |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 2251 | static ssize_t __spufs_proxydma_info_read(struct spu_context *ctx, |
| 2252 | char __user *buf, size_t len, loff_t *pos) |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 2253 | { |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 2254 | struct spu_proxydma_info info; |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 2255 | struct mfc_cq_sr *qp, *puqp; |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 2256 | int ret = sizeof info; |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 2257 | int i; |
| 2258 | |
| 2259 | if (len < ret) |
| 2260 | return -EINVAL; |
| 2261 | |
| 2262 | if (!access_ok(VERIFY_WRITE, buf, len)) |
| 2263 | return -EFAULT; |
| 2264 | |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 2265 | info.proxydma_info_type = ctx->csa.prob.dma_querytype_RW; |
| 2266 | info.proxydma_info_mask = ctx->csa.prob.dma_querymask_RW; |
| 2267 | info.proxydma_info_status = ctx->csa.prob.dma_tagstatus_R; |
| 2268 | for (i = 0; i < 8; i++) { |
| 2269 | qp = &info.proxydma_info_command_data[i]; |
| 2270 | puqp = &ctx->csa.priv2.puq[i]; |
| 2271 | |
| 2272 | qp->mfc_cq_data0_RW = puqp->mfc_cq_data0_RW; |
| 2273 | qp->mfc_cq_data1_RW = puqp->mfc_cq_data1_RW; |
| 2274 | qp->mfc_cq_data2_RW = puqp->mfc_cq_data2_RW; |
| 2275 | qp->mfc_cq_data3_RW = puqp->mfc_cq_data3_RW; |
| 2276 | } |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 2277 | |
| 2278 | return simple_read_from_buffer(buf, len, pos, &info, |
| 2279 | sizeof info); |
| 2280 | } |
| 2281 | |
| 2282 | static ssize_t spufs_proxydma_info_read(struct file *file, char __user *buf, |
| 2283 | size_t len, loff_t *pos) |
| 2284 | { |
| 2285 | struct spu_context *ctx = file->private_data; |
| 2286 | int ret; |
| 2287 | |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 2288 | ret = spu_acquire_saved(ctx); |
| 2289 | if (ret) |
| 2290 | return ret; |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 2291 | spin_lock(&ctx->csa.register_lock); |
| 2292 | ret = __spufs_proxydma_info_read(ctx, buf, len, pos); |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 2293 | spin_unlock(&ctx->csa.register_lock); |
Christoph Hellwig | 27b1ea0 | 2007-07-20 21:39:34 +0200 | [diff] [blame] | 2294 | spu_release_saved(ctx); |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 2295 | |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 2296 | return ret; |
| 2297 | } |
| 2298 | |
Arjan van de Ven | 5dfe4c9 | 2007-02-12 00:55:31 -0800 | [diff] [blame] | 2299 | static const struct file_operations spufs_proxydma_info_fops = { |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 2300 | .open = spufs_info_open, |
| 2301 | .read = spufs_proxydma_info_read, |
| 2302 | }; |
| 2303 | |
Christoph Hellwig | 476273a | 2007-06-29 10:58:01 +1000 | [diff] [blame] | 2304 | static int spufs_show_tid(struct seq_file *s, void *private) |
| 2305 | { |
| 2306 | struct spu_context *ctx = s->private; |
| 2307 | |
| 2308 | seq_printf(s, "%d\n", ctx->tid); |
| 2309 | return 0; |
| 2310 | } |
| 2311 | |
| 2312 | static int spufs_tid_open(struct inode *inode, struct file *file) |
| 2313 | { |
| 2314 | return single_open(file, spufs_show_tid, SPUFS_I(inode)->i_ctx); |
| 2315 | } |
| 2316 | |
| 2317 | static const struct file_operations spufs_tid_fops = { |
| 2318 | .open = spufs_tid_open, |
| 2319 | .read = seq_read, |
| 2320 | .llseek = seq_lseek, |
| 2321 | .release = single_release, |
| 2322 | }; |
| 2323 | |
Christoph Hellwig | e9f8a0b | 2007-06-29 10:58:03 +1000 | [diff] [blame] | 2324 | static const char *ctx_state_names[] = { |
| 2325 | "user", "system", "iowait", "loaded" |
| 2326 | }; |
| 2327 | |
| 2328 | static unsigned long long spufs_acct_time(struct spu_context *ctx, |
Andre Detsch | 27ec41d | 2007-07-20 21:39:33 +0200 | [diff] [blame] | 2329 | enum spu_utilization_state state) |
Christoph Hellwig | e9f8a0b | 2007-06-29 10:58:03 +1000 | [diff] [blame] | 2330 | { |
Andre Detsch | 27ec41d | 2007-07-20 21:39:33 +0200 | [diff] [blame] | 2331 | struct timespec ts; |
| 2332 | unsigned long long time = ctx->stats.times[state]; |
Christoph Hellwig | e9f8a0b | 2007-06-29 10:58:03 +1000 | [diff] [blame] | 2333 | |
Andre Detsch | 27ec41d | 2007-07-20 21:39:33 +0200 | [diff] [blame] | 2334 | /* |
| 2335 | * In general, utilization statistics are updated by the controlling |
| 2336 | * thread as the spu context moves through various well defined |
| 2337 | * state transitions, but if the context is lazily loaded its |
| 2338 | * utilization statistics are not updated as the controlling thread |
| 2339 | * is not tightly coupled with the execution of the spu context. We |
| 2340 | * calculate and apply the time delta from the last recorded state |
| 2341 | * of the spu context. |
| 2342 | */ |
| 2343 | if (ctx->spu && ctx->stats.util_state == state) { |
| 2344 | ktime_get_ts(&ts); |
| 2345 | time += timespec_to_ns(&ts) - ctx->stats.tstamp; |
| 2346 | } |
Christoph Hellwig | e9f8a0b | 2007-06-29 10:58:03 +1000 | [diff] [blame] | 2347 | |
Andre Detsch | 27ec41d | 2007-07-20 21:39:33 +0200 | [diff] [blame] | 2348 | return time / NSEC_PER_MSEC; |
Christoph Hellwig | e9f8a0b | 2007-06-29 10:58:03 +1000 | [diff] [blame] | 2349 | } |
| 2350 | |
| 2351 | static unsigned long long spufs_slb_flts(struct spu_context *ctx) |
| 2352 | { |
| 2353 | unsigned long long slb_flts = ctx->stats.slb_flt; |
| 2354 | |
| 2355 | if (ctx->state == SPU_STATE_RUNNABLE) { |
| 2356 | slb_flts += (ctx->spu->stats.slb_flt - |
| 2357 | ctx->stats.slb_flt_base); |
| 2358 | } |
| 2359 | |
| 2360 | return slb_flts; |
| 2361 | } |
| 2362 | |
| 2363 | static unsigned long long spufs_class2_intrs(struct spu_context *ctx) |
| 2364 | { |
| 2365 | unsigned long long class2_intrs = ctx->stats.class2_intr; |
| 2366 | |
| 2367 | if (ctx->state == SPU_STATE_RUNNABLE) { |
| 2368 | class2_intrs += (ctx->spu->stats.class2_intr - |
| 2369 | ctx->stats.class2_intr_base); |
| 2370 | } |
| 2371 | |
| 2372 | return class2_intrs; |
| 2373 | } |
| 2374 | |
| 2375 | |
| 2376 | static int spufs_show_stat(struct seq_file *s, void *private) |
| 2377 | { |
| 2378 | struct spu_context *ctx = s->private; |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 2379 | int ret; |
Christoph Hellwig | e9f8a0b | 2007-06-29 10:58:03 +1000 | [diff] [blame] | 2380 | |
Christoph Hellwig | c9101bd | 2007-12-20 16:39:59 +0900 | [diff] [blame] | 2381 | ret = spu_acquire(ctx); |
| 2382 | if (ret) |
| 2383 | return ret; |
| 2384 | |
Christoph Hellwig | e9f8a0b | 2007-06-29 10:58:03 +1000 | [diff] [blame] | 2385 | seq_printf(s, "%s %llu %llu %llu %llu " |
| 2386 | "%llu %llu %llu %llu %llu %llu %llu %llu\n", |
Andre Detsch | 27ec41d | 2007-07-20 21:39:33 +0200 | [diff] [blame] | 2387 | ctx_state_names[ctx->stats.util_state], |
| 2388 | spufs_acct_time(ctx, SPU_UTIL_USER), |
| 2389 | spufs_acct_time(ctx, SPU_UTIL_SYSTEM), |
| 2390 | spufs_acct_time(ctx, SPU_UTIL_IOWAIT), |
| 2391 | spufs_acct_time(ctx, SPU_UTIL_IDLE_LOADED), |
Christoph Hellwig | e9f8a0b | 2007-06-29 10:58:03 +1000 | [diff] [blame] | 2392 | ctx->stats.vol_ctx_switch, |
| 2393 | ctx->stats.invol_ctx_switch, |
| 2394 | spufs_slb_flts(ctx), |
| 2395 | ctx->stats.hash_flt, |
| 2396 | ctx->stats.min_flt, |
| 2397 | ctx->stats.maj_flt, |
| 2398 | spufs_class2_intrs(ctx), |
| 2399 | ctx->stats.libassist); |
| 2400 | spu_release(ctx); |
| 2401 | return 0; |
| 2402 | } |
| 2403 | |
| 2404 | static int spufs_stat_open(struct inode *inode, struct file *file) |
| 2405 | { |
| 2406 | return single_open(file, spufs_show_stat, SPUFS_I(inode)->i_ctx); |
| 2407 | } |
| 2408 | |
| 2409 | static const struct file_operations spufs_stat_fops = { |
| 2410 | .open = spufs_stat_open, |
| 2411 | .read = seq_read, |
| 2412 | .llseek = seq_lseek, |
| 2413 | .release = single_release, |
| 2414 | }; |
| 2415 | |
Christoph Hellwig | 5158e9b | 2008-04-29 17:08:38 +1000 | [diff] [blame] | 2416 | static inline int spufs_switch_log_used(struct spu_context *ctx) |
| 2417 | { |
| 2418 | return (ctx->switch_log->head - ctx->switch_log->tail) % |
| 2419 | SWITCH_LOG_BUFSIZE; |
| 2420 | } |
| 2421 | |
| 2422 | static inline int spufs_switch_log_avail(struct spu_context *ctx) |
| 2423 | { |
| 2424 | return SWITCH_LOG_BUFSIZE - spufs_switch_log_used(ctx); |
| 2425 | } |
| 2426 | |
| 2427 | static int spufs_switch_log_open(struct inode *inode, struct file *file) |
| 2428 | { |
| 2429 | struct spu_context *ctx = SPUFS_I(inode)->i_ctx; |
Jeremy Kerr | f5ed0eb | 2008-10-16 10:03:46 +1100 | [diff] [blame] | 2430 | int rc; |
Christoph Hellwig | 5158e9b | 2008-04-29 17:08:38 +1000 | [diff] [blame] | 2431 | |
Jeremy Kerr | f5ed0eb | 2008-10-16 10:03:46 +1100 | [diff] [blame] | 2432 | rc = spu_acquire(ctx); |
| 2433 | if (rc) |
| 2434 | return rc; |
| 2435 | |
Christoph Hellwig | 5158e9b | 2008-04-29 17:08:38 +1000 | [diff] [blame] | 2436 | if (ctx->switch_log) { |
Jeremy Kerr | f5ed0eb | 2008-10-16 10:03:46 +1100 | [diff] [blame] | 2437 | rc = -EBUSY; |
| 2438 | goto out; |
Christoph Hellwig | 5158e9b | 2008-04-29 17:08:38 +1000 | [diff] [blame] | 2439 | } |
Jeremy Kerr | f5ed0eb | 2008-10-16 10:03:46 +1100 | [diff] [blame] | 2440 | |
Jeremy Kerr | 837ef88 | 2008-10-17 12:02:31 +1100 | [diff] [blame] | 2441 | ctx->switch_log = kmalloc(sizeof(struct switch_log) + |
Jeremy Kerr | f5ed0eb | 2008-10-16 10:03:46 +1100 | [diff] [blame] | 2442 | SWITCH_LOG_BUFSIZE * sizeof(struct switch_log_entry), |
| 2443 | GFP_KERNEL); |
| 2444 | |
| 2445 | if (!ctx->switch_log) { |
| 2446 | rc = -ENOMEM; |
| 2447 | goto out; |
| 2448 | } |
| 2449 | |
Jeremy Kerr | 837ef88 | 2008-10-17 12:02:31 +1100 | [diff] [blame] | 2450 | ctx->switch_log->head = ctx->switch_log->tail = 0; |
Jeremy Kerr | f5ed0eb | 2008-10-16 10:03:46 +1100 | [diff] [blame] | 2451 | init_waitqueue_head(&ctx->switch_log->wait); |
| 2452 | rc = 0; |
| 2453 | |
| 2454 | out: |
| 2455 | spu_release(ctx); |
| 2456 | return rc; |
| 2457 | } |
| 2458 | |
| 2459 | static int spufs_switch_log_release(struct inode *inode, struct file *file) |
| 2460 | { |
| 2461 | struct spu_context *ctx = SPUFS_I(inode)->i_ctx; |
| 2462 | int rc; |
| 2463 | |
| 2464 | rc = spu_acquire(ctx); |
| 2465 | if (rc) |
| 2466 | return rc; |
| 2467 | |
| 2468 | kfree(ctx->switch_log); |
| 2469 | ctx->switch_log = NULL; |
| 2470 | spu_release(ctx); |
Christoph Hellwig | 5158e9b | 2008-04-29 17:08:38 +1000 | [diff] [blame] | 2471 | |
| 2472 | return 0; |
Christoph Hellwig | 5158e9b | 2008-04-29 17:08:38 +1000 | [diff] [blame] | 2473 | } |
| 2474 | |
| 2475 | static int switch_log_sprint(struct spu_context *ctx, char *tbuf, int n) |
| 2476 | { |
| 2477 | struct switch_log_entry *p; |
| 2478 | |
| 2479 | p = ctx->switch_log->log + ctx->switch_log->tail % SWITCH_LOG_BUFSIZE; |
| 2480 | |
| 2481 | return snprintf(tbuf, n, "%u.%09u %d %u %u %llu\n", |
| 2482 | (unsigned int) p->tstamp.tv_sec, |
| 2483 | (unsigned int) p->tstamp.tv_nsec, |
| 2484 | p->spu_id, |
| 2485 | (unsigned int) p->type, |
| 2486 | (unsigned int) p->val, |
| 2487 | (unsigned long long) p->timebase); |
| 2488 | } |
| 2489 | |
| 2490 | static ssize_t spufs_switch_log_read(struct file *file, char __user *buf, |
| 2491 | size_t len, loff_t *ppos) |
| 2492 | { |
| 2493 | struct inode *inode = file->f_path.dentry->d_inode; |
| 2494 | struct spu_context *ctx = SPUFS_I(inode)->i_ctx; |
| 2495 | int error = 0, cnt = 0; |
| 2496 | |
roel kluin | 17e3767 | 2009-10-14 05:32:28 +0000 | [diff] [blame^] | 2497 | if (!buf) |
Christoph Hellwig | 5158e9b | 2008-04-29 17:08:38 +1000 | [diff] [blame] | 2498 | return -EINVAL; |
| 2499 | |
Jeremy Kerr | f5ed0eb | 2008-10-16 10:03:46 +1100 | [diff] [blame] | 2500 | error = spu_acquire(ctx); |
| 2501 | if (error) |
| 2502 | return error; |
| 2503 | |
Christoph Hellwig | 5158e9b | 2008-04-29 17:08:38 +1000 | [diff] [blame] | 2504 | while (cnt < len) { |
| 2505 | char tbuf[128]; |
| 2506 | int width; |
| 2507 | |
Jeremy Kerr | 14f693e | 2008-10-16 10:51:46 +1100 | [diff] [blame] | 2508 | if (spufs_switch_log_used(ctx) == 0) { |
| 2509 | if (cnt > 0) { |
| 2510 | /* If there's data ready to go, we can |
| 2511 | * just return straight away */ |
| 2512 | break; |
| 2513 | |
| 2514 | } else if (file->f_flags & O_NONBLOCK) { |
Jeremy Kerr | f5ed0eb | 2008-10-16 10:03:46 +1100 | [diff] [blame] | 2515 | error = -EAGAIN; |
Christoph Hellwig | 5158e9b | 2008-04-29 17:08:38 +1000 | [diff] [blame] | 2516 | break; |
Jeremy Kerr | 14f693e | 2008-10-16 10:51:46 +1100 | [diff] [blame] | 2517 | |
| 2518 | } else { |
| 2519 | /* spufs_wait will drop the mutex and |
| 2520 | * re-acquire, but since we're in read(), the |
| 2521 | * file cannot be _released (and so |
| 2522 | * ctx->switch_log is stable). |
| 2523 | */ |
| 2524 | error = spufs_wait(ctx->switch_log->wait, |
| 2525 | spufs_switch_log_used(ctx) > 0); |
| 2526 | |
| 2527 | /* On error, spufs_wait returns without the |
| 2528 | * state mutex held */ |
| 2529 | if (error) |
| 2530 | return error; |
| 2531 | |
| 2532 | /* We may have had entries read from underneath |
| 2533 | * us while we dropped the mutex in spufs_wait, |
| 2534 | * so re-check */ |
| 2535 | if (spufs_switch_log_used(ctx) == 0) |
| 2536 | continue; |
Jeremy Kerr | f5ed0eb | 2008-10-16 10:03:46 +1100 | [diff] [blame] | 2537 | } |
Christoph Hellwig | 5158e9b | 2008-04-29 17:08:38 +1000 | [diff] [blame] | 2538 | } |
| 2539 | |
Christoph Hellwig | 5158e9b | 2008-04-29 17:08:38 +1000 | [diff] [blame] | 2540 | width = switch_log_sprint(ctx, tbuf, sizeof(tbuf)); |
Jeremy Kerr | f5ed0eb | 2008-10-16 10:03:46 +1100 | [diff] [blame] | 2541 | if (width < len) |
Christoph Hellwig | 5158e9b | 2008-04-29 17:08:38 +1000 | [diff] [blame] | 2542 | ctx->switch_log->tail = |
| 2543 | (ctx->switch_log->tail + 1) % |
| 2544 | SWITCH_LOG_BUFSIZE; |
Jeremy Kerr | f5ed0eb | 2008-10-16 10:03:46 +1100 | [diff] [blame] | 2545 | else |
| 2546 | /* If the record is greater than space available return |
| 2547 | * partial buffer (so far) */ |
Christoph Hellwig | 5158e9b | 2008-04-29 17:08:38 +1000 | [diff] [blame] | 2548 | break; |
| 2549 | |
| 2550 | error = copy_to_user(buf + cnt, tbuf, width); |
| 2551 | if (error) |
| 2552 | break; |
| 2553 | cnt += width; |
| 2554 | } |
| 2555 | |
Jeremy Kerr | f5ed0eb | 2008-10-16 10:03:46 +1100 | [diff] [blame] | 2556 | spu_release(ctx); |
| 2557 | |
Christoph Hellwig | 5158e9b | 2008-04-29 17:08:38 +1000 | [diff] [blame] | 2558 | return cnt == 0 ? error : cnt; |
| 2559 | } |
| 2560 | |
| 2561 | static unsigned int spufs_switch_log_poll(struct file *file, poll_table *wait) |
| 2562 | { |
| 2563 | struct inode *inode = file->f_path.dentry->d_inode; |
| 2564 | struct spu_context *ctx = SPUFS_I(inode)->i_ctx; |
| 2565 | unsigned int mask = 0; |
Jeremy Kerr | f5ed0eb | 2008-10-16 10:03:46 +1100 | [diff] [blame] | 2566 | int rc; |
Christoph Hellwig | 5158e9b | 2008-04-29 17:08:38 +1000 | [diff] [blame] | 2567 | |
| 2568 | poll_wait(file, &ctx->switch_log->wait, wait); |
| 2569 | |
Jeremy Kerr | f5ed0eb | 2008-10-16 10:03:46 +1100 | [diff] [blame] | 2570 | rc = spu_acquire(ctx); |
| 2571 | if (rc) |
| 2572 | return rc; |
| 2573 | |
Christoph Hellwig | 5158e9b | 2008-04-29 17:08:38 +1000 | [diff] [blame] | 2574 | if (spufs_switch_log_used(ctx) > 0) |
| 2575 | mask |= POLLIN; |
| 2576 | |
Jeremy Kerr | f5ed0eb | 2008-10-16 10:03:46 +1100 | [diff] [blame] | 2577 | spu_release(ctx); |
| 2578 | |
Christoph Hellwig | 5158e9b | 2008-04-29 17:08:38 +1000 | [diff] [blame] | 2579 | return mask; |
| 2580 | } |
| 2581 | |
| 2582 | static const struct file_operations spufs_switch_log_fops = { |
Jeremy Kerr | f5ed0eb | 2008-10-16 10:03:46 +1100 | [diff] [blame] | 2583 | .owner = THIS_MODULE, |
| 2584 | .open = spufs_switch_log_open, |
| 2585 | .read = spufs_switch_log_read, |
| 2586 | .poll = spufs_switch_log_poll, |
| 2587 | .release = spufs_switch_log_release, |
Christoph Hellwig | 5158e9b | 2008-04-29 17:08:38 +1000 | [diff] [blame] | 2588 | }; |
| 2589 | |
Jeremy Kerr | f5ed0eb | 2008-10-16 10:03:46 +1100 | [diff] [blame] | 2590 | /** |
| 2591 | * Log a context switch event to a switch log reader. |
| 2592 | * |
| 2593 | * Must be called with ctx->state_mutex held. |
| 2594 | */ |
Christoph Hellwig | 5158e9b | 2008-04-29 17:08:38 +1000 | [diff] [blame] | 2595 | void spu_switch_log_notify(struct spu *spu, struct spu_context *ctx, |
| 2596 | u32 type, u32 val) |
| 2597 | { |
| 2598 | if (!ctx->switch_log) |
| 2599 | return; |
| 2600 | |
Christoph Hellwig | 5158e9b | 2008-04-29 17:08:38 +1000 | [diff] [blame] | 2601 | if (spufs_switch_log_avail(ctx) > 1) { |
| 2602 | struct switch_log_entry *p; |
| 2603 | |
| 2604 | p = ctx->switch_log->log + ctx->switch_log->head; |
| 2605 | ktime_get_ts(&p->tstamp); |
| 2606 | p->timebase = get_tb(); |
| 2607 | p->spu_id = spu ? spu->number : -1; |
| 2608 | p->type = type; |
| 2609 | p->val = val; |
| 2610 | |
| 2611 | ctx->switch_log->head = |
| 2612 | (ctx->switch_log->head + 1) % SWITCH_LOG_BUFSIZE; |
| 2613 | } |
Christoph Hellwig | 5158e9b | 2008-04-29 17:08:38 +1000 | [diff] [blame] | 2614 | |
| 2615 | wake_up(&ctx->switch_log->wait); |
| 2616 | } |
Christoph Hellwig | e9f8a0b | 2007-06-29 10:58:03 +1000 | [diff] [blame] | 2617 | |
Luke Browning | 46deed6 | 2008-06-16 11:36:43 +1000 | [diff] [blame] | 2618 | static int spufs_show_ctx(struct seq_file *s, void *private) |
| 2619 | { |
| 2620 | struct spu_context *ctx = s->private; |
| 2621 | u64 mfc_control_RW; |
| 2622 | |
| 2623 | mutex_lock(&ctx->state_mutex); |
| 2624 | if (ctx->spu) { |
| 2625 | struct spu *spu = ctx->spu; |
| 2626 | struct spu_priv2 __iomem *priv2 = spu->priv2; |
| 2627 | |
| 2628 | spin_lock_irq(&spu->register_lock); |
| 2629 | mfc_control_RW = in_be64(&priv2->mfc_control_RW); |
| 2630 | spin_unlock_irq(&spu->register_lock); |
| 2631 | } else { |
| 2632 | struct spu_state *csa = &ctx->csa; |
| 2633 | |
| 2634 | mfc_control_RW = csa->priv2.mfc_control_RW; |
| 2635 | } |
| 2636 | |
| 2637 | seq_printf(s, "%c flgs(%lx) sflgs(%lx) pri(%d) ts(%d) spu(%02d)" |
Stephen Rothwell | 9477e45 | 2009-01-06 14:27:38 +0000 | [diff] [blame] | 2638 | " %c %llx %llx %llx %llx %x %x\n", |
Luke Browning | 46deed6 | 2008-06-16 11:36:43 +1000 | [diff] [blame] | 2639 | ctx->state == SPU_STATE_SAVED ? 'S' : 'R', |
| 2640 | ctx->flags, |
| 2641 | ctx->sched_flags, |
| 2642 | ctx->prio, |
| 2643 | ctx->time_slice, |
| 2644 | ctx->spu ? ctx->spu->number : -1, |
| 2645 | !list_empty(&ctx->rq) ? 'q' : ' ', |
| 2646 | ctx->csa.class_0_pending, |
| 2647 | ctx->csa.class_0_dar, |
| 2648 | ctx->csa.class_1_dsisr, |
| 2649 | mfc_control_RW, |
| 2650 | ctx->ops->runcntl_read(ctx), |
| 2651 | ctx->ops->status_read(ctx)); |
| 2652 | |
| 2653 | mutex_unlock(&ctx->state_mutex); |
| 2654 | |
| 2655 | return 0; |
| 2656 | } |
| 2657 | |
| 2658 | static int spufs_ctx_open(struct inode *inode, struct file *file) |
| 2659 | { |
| 2660 | return single_open(file, spufs_show_ctx, SPUFS_I(inode)->i_ctx); |
| 2661 | } |
| 2662 | |
| 2663 | static const struct file_operations spufs_ctx_fops = { |
| 2664 | .open = spufs_ctx_open, |
| 2665 | .read = seq_read, |
| 2666 | .llseek = seq_lseek, |
| 2667 | .release = single_release, |
| 2668 | }; |
| 2669 | |
Jeremy Kerr | 7425464 | 2009-02-17 11:44:14 +1100 | [diff] [blame] | 2670 | const struct spufs_tree_descr spufs_dir_contents[] = { |
Benjamin Herrenschmidt | cbe709c | 2007-06-04 15:15:38 +1000 | [diff] [blame] | 2671 | { "capabilities", &spufs_caps_fops, 0444, }, |
Jeremy Kerr | 6f7dde8 | 2008-06-30 14:38:37 +1000 | [diff] [blame] | 2672 | { "mem", &spufs_mem_fops, 0666, LS_SIZE, }, |
| 2673 | { "regs", &spufs_regs_fops, 0666, sizeof(struct spu_reg128[128]), }, |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 2674 | { "mbox", &spufs_mbox_fops, 0444, }, |
| 2675 | { "ibox", &spufs_ibox_fops, 0444, }, |
| 2676 | { "wbox", &spufs_wbox_fops, 0222, }, |
Jeremy Kerr | 6f7dde8 | 2008-06-30 14:38:37 +1000 | [diff] [blame] | 2677 | { "mbox_stat", &spufs_mbox_stat_fops, 0444, sizeof(u32), }, |
| 2678 | { "ibox_stat", &spufs_ibox_stat_fops, 0444, sizeof(u32), }, |
| 2679 | { "wbox_stat", &spufs_wbox_stat_fops, 0444, sizeof(u32), }, |
Jeremy Kerr | 603c461 | 2007-09-26 10:53:45 +1000 | [diff] [blame] | 2680 | { "signal1", &spufs_signal1_fops, 0666, }, |
| 2681 | { "signal2", &spufs_signal2_fops, 0666, }, |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 2682 | { "signal1_type", &spufs_signal1_type, 0666, }, |
| 2683 | { "signal2_type", &spufs_signal2_type, 0666, }, |
Mark Nutter | 6df10a8 | 2006-03-23 00:00:12 +0100 | [diff] [blame] | 2684 | { "cntl", &spufs_cntl_fops, 0666, }, |
Jeremy Kerr | 6f7dde8 | 2008-06-30 14:38:37 +1000 | [diff] [blame] | 2685 | { "fpcr", &spufs_fpcr_fops, 0666, sizeof(struct spu_reg128), }, |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 2686 | { "lslr", &spufs_lslr_ops, 0444, }, |
| 2687 | { "mfc", &spufs_mfc_fops, 0666, }, |
| 2688 | { "mss", &spufs_mss_fops, 0666, }, |
| 2689 | { "npc", &spufs_npc_ops, 0666, }, |
| 2690 | { "srr0", &spufs_srr0_ops, 0666, }, |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 2691 | { "decr", &spufs_decr_ops, 0666, }, |
| 2692 | { "decr_status", &spufs_decr_status_ops, 0666, }, |
Arnd Bergmann | 8b3d666 | 2005-11-15 15:53:52 -0500 | [diff] [blame] | 2693 | { "event_mask", &spufs_event_mask_ops, 0666, }, |
Dwayne Grant McConnell | b9e3bd7 | 2006-11-20 18:44:58 +0100 | [diff] [blame] | 2694 | { "event_status", &spufs_event_status_ops, 0444, }, |
Jeremy Kerr | 6f7dde8 | 2008-06-30 14:38:37 +1000 | [diff] [blame] | 2695 | { "psmap", &spufs_psmap_fops, 0666, SPUFS_PS_MAP_SIZE, }, |
Arnd Bergmann | 8676727 | 2006-10-04 17:26:21 +0200 | [diff] [blame] | 2696 | { "phys-id", &spufs_id_ops, 0666, }, |
| 2697 | { "object-id", &spufs_object_id_ops, 0666, }, |
Jeremy Kerr | 6f7dde8 | 2008-06-30 14:38:37 +1000 | [diff] [blame] | 2698 | { "mbox_info", &spufs_mbox_info_fops, 0444, sizeof(u32), }, |
| 2699 | { "ibox_info", &spufs_ibox_info_fops, 0444, sizeof(u32), }, |
| 2700 | { "wbox_info", &spufs_wbox_info_fops, 0444, sizeof(u32), }, |
| 2701 | { "dma_info", &spufs_dma_info_fops, 0444, |
| 2702 | sizeof(struct spu_dma_info), }, |
| 2703 | { "proxydma_info", &spufs_proxydma_info_fops, 0444, |
| 2704 | sizeof(struct spu_proxydma_info)}, |
Christoph Hellwig | 476273a | 2007-06-29 10:58:01 +1000 | [diff] [blame] | 2705 | { "tid", &spufs_tid_fops, 0444, }, |
Christoph Hellwig | e9f8a0b | 2007-06-29 10:58:03 +1000 | [diff] [blame] | 2706 | { "stat", &spufs_stat_fops, 0444, }, |
Christoph Hellwig | 5158e9b | 2008-04-29 17:08:38 +1000 | [diff] [blame] | 2707 | { "switch_log", &spufs_switch_log_fops, 0444 }, |
Arnd Bergmann | 67207b9 | 2005-11-15 15:53:48 -0500 | [diff] [blame] | 2708 | {}, |
| 2709 | }; |
Mark Nutter | 5737edd | 2006-10-24 18:31:16 +0200 | [diff] [blame] | 2710 | |
Jeremy Kerr | 7425464 | 2009-02-17 11:44:14 +1100 | [diff] [blame] | 2711 | const struct spufs_tree_descr spufs_dir_nosched_contents[] = { |
Benjamin Herrenschmidt | cbe709c | 2007-06-04 15:15:38 +1000 | [diff] [blame] | 2712 | { "capabilities", &spufs_caps_fops, 0444, }, |
Jeremy Kerr | 6f7dde8 | 2008-06-30 14:38:37 +1000 | [diff] [blame] | 2713 | { "mem", &spufs_mem_fops, 0666, LS_SIZE, }, |
Mark Nutter | 5737edd | 2006-10-24 18:31:16 +0200 | [diff] [blame] | 2714 | { "mbox", &spufs_mbox_fops, 0444, }, |
| 2715 | { "ibox", &spufs_ibox_fops, 0444, }, |
| 2716 | { "wbox", &spufs_wbox_fops, 0222, }, |
Jeremy Kerr | 6f7dde8 | 2008-06-30 14:38:37 +1000 | [diff] [blame] | 2717 | { "mbox_stat", &spufs_mbox_stat_fops, 0444, sizeof(u32), }, |
| 2718 | { "ibox_stat", &spufs_ibox_stat_fops, 0444, sizeof(u32), }, |
| 2719 | { "wbox_stat", &spufs_wbox_stat_fops, 0444, sizeof(u32), }, |
Jeremy Kerr | d054b36 | 2007-07-20 21:39:31 +0200 | [diff] [blame] | 2720 | { "signal1", &spufs_signal1_nosched_fops, 0222, }, |
| 2721 | { "signal2", &spufs_signal2_nosched_fops, 0222, }, |
Mark Nutter | 5737edd | 2006-10-24 18:31:16 +0200 | [diff] [blame] | 2722 | { "signal1_type", &spufs_signal1_type, 0666, }, |
| 2723 | { "signal2_type", &spufs_signal2_type, 0666, }, |
| 2724 | { "mss", &spufs_mss_fops, 0666, }, |
| 2725 | { "mfc", &spufs_mfc_fops, 0666, }, |
| 2726 | { "cntl", &spufs_cntl_fops, 0666, }, |
| 2727 | { "npc", &spufs_npc_ops, 0666, }, |
Jeremy Kerr | 6f7dde8 | 2008-06-30 14:38:37 +1000 | [diff] [blame] | 2728 | { "psmap", &spufs_psmap_fops, 0666, SPUFS_PS_MAP_SIZE, }, |
Mark Nutter | 5737edd | 2006-10-24 18:31:16 +0200 | [diff] [blame] | 2729 | { "phys-id", &spufs_id_ops, 0666, }, |
| 2730 | { "object-id", &spufs_object_id_ops, 0666, }, |
Christoph Hellwig | 476273a | 2007-06-29 10:58:01 +1000 | [diff] [blame] | 2731 | { "tid", &spufs_tid_fops, 0444, }, |
Christoph Hellwig | e9f8a0b | 2007-06-29 10:58:03 +1000 | [diff] [blame] | 2732 | { "stat", &spufs_stat_fops, 0444, }, |
Jeremy Kerr | 2c3e478 | 2008-07-03 11:42:20 +1000 | [diff] [blame] | 2733 | {}, |
| 2734 | }; |
| 2735 | |
Jeremy Kerr | 7425464 | 2009-02-17 11:44:14 +1100 | [diff] [blame] | 2736 | const struct spufs_tree_descr spufs_dir_debug_contents[] = { |
Luke Browning | 46deed6 | 2008-06-16 11:36:43 +1000 | [diff] [blame] | 2737 | { ".ctx", &spufs_ctx_fops, 0444, }, |
Mark Nutter | 5737edd | 2006-10-24 18:31:16 +0200 | [diff] [blame] | 2738 | {}, |
| 2739 | }; |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 2740 | |
Jeremy Kerr | 7425464 | 2009-02-17 11:44:14 +1100 | [diff] [blame] | 2741 | const struct spufs_coredump_reader spufs_coredump_read[] = { |
Michael Ellerman | 4fca9c4 | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 2742 | { "regs", __spufs_regs_read, NULL, sizeof(struct spu_reg128[128])}, |
| 2743 | { "fpcr", __spufs_fpcr_read, NULL, sizeof(struct spu_reg128) }, |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 2744 | { "lslr", NULL, spufs_lslr_get, 19 }, |
| 2745 | { "decr", NULL, spufs_decr_get, 19 }, |
| 2746 | { "decr_status", NULL, spufs_decr_status_get, 19 }, |
Michael Ellerman | 4fca9c4 | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 2747 | { "mem", __spufs_mem_read, NULL, LS_SIZE, }, |
| 2748 | { "signal1", __spufs_signal1_read, NULL, sizeof(u32) }, |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 2749 | { "signal1_type", NULL, spufs_signal1_type_get, 19 }, |
Michael Ellerman | 4fca9c4 | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 2750 | { "signal2", __spufs_signal2_read, NULL, sizeof(u32) }, |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 2751 | { "signal2_type", NULL, spufs_signal2_type_get, 19 }, |
| 2752 | { "event_mask", NULL, spufs_event_mask_get, 19 }, |
| 2753 | { "event_status", NULL, spufs_event_status_get, 19 }, |
Michael Ellerman | 4fca9c4 | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 2754 | { "mbox_info", __spufs_mbox_info_read, NULL, sizeof(u32) }, |
| 2755 | { "ibox_info", __spufs_ibox_info_read, NULL, sizeof(u32) }, |
| 2756 | { "wbox_info", __spufs_wbox_info_read, NULL, 4 * sizeof(u32)}, |
| 2757 | { "dma_info", __spufs_dma_info_read, NULL, sizeof(struct spu_dma_info)}, |
| 2758 | { "proxydma_info", __spufs_proxydma_info_read, |
| 2759 | NULL, sizeof(struct spu_proxydma_info)}, |
Michael Ellerman | 104f0cc | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 2760 | { "object-id", NULL, spufs_object_id_get, 19 }, |
| 2761 | { "npc", NULL, spufs_npc_get, 19 }, |
Michael Ellerman | 936d5bf | 2007-09-19 14:38:12 +1000 | [diff] [blame] | 2762 | { NULL }, |
Dwayne Grant McConnell | bf1ab97 | 2006-11-23 00:46:37 +0100 | [diff] [blame] | 2763 | }; |