file.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510
  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. #undef DEBUG
  23. #include <linux/fs.h>
  24. #include <linux/ioctl.h>
  25. #include <linux/module.h>
  26. #include <linux/pagemap.h>
  27. #include <linux/poll.h>
  28. #include <linux/ptrace.h>
  29. #include <asm/io.h>
  30. #include <asm/semaphore.h>
  31. #include <asm/spu.h>
  32. #include <asm/uaccess.h>
  33. #include "spufs.h"
  34. #define SPUFS_MMAP_4K (PAGE_SIZE == 0x1000)
  35. static int
  36. spufs_mem_open(struct inode *inode, struct file *file)
  37. {
  38. struct spufs_inode_info *i = SPUFS_I(inode);
  39. struct spu_context *ctx = i->i_ctx;
  40. file->private_data = ctx;
  41. file->f_mapping = inode->i_mapping;
  42. ctx->local_store = inode->i_mapping;
  43. return 0;
  44. }
  45. static ssize_t
  46. spufs_mem_read(struct file *file, char __user *buffer,
  47. size_t size, loff_t *pos)
  48. {
  49. struct spu_context *ctx = file->private_data;
  50. char *local_store;
  51. int ret;
  52. spu_acquire(ctx);
  53. local_store = ctx->ops->get_ls(ctx);
  54. ret = simple_read_from_buffer(buffer, size, pos, local_store, LS_SIZE);
  55. spu_release(ctx);
  56. return ret;
  57. }
  58. static ssize_t
  59. spufs_mem_write(struct file *file, const char __user *buffer,
  60. size_t size, loff_t *pos)
  61. {
  62. struct spu_context *ctx = file->private_data;
  63. char *local_store;
  64. int ret;
  65. size = min_t(ssize_t, LS_SIZE - *pos, size);
  66. if (size <= 0)
  67. return -EFBIG;
  68. *pos += size;
  69. spu_acquire(ctx);
  70. local_store = ctx->ops->get_ls(ctx);
  71. ret = copy_from_user(local_store + *pos - size,
  72. buffer, size) ? -EFAULT : size;
  73. spu_release(ctx);
  74. return ret;
  75. }
  76. static struct page *
  77. spufs_mem_mmap_nopage(struct vm_area_struct *vma,
  78. unsigned long address, int *type)
  79. {
  80. struct page *page = NOPAGE_SIGBUS;
  81. struct spu_context *ctx = vma->vm_file->private_data;
  82. unsigned long offset = address - vma->vm_start;
  83. offset += vma->vm_pgoff << PAGE_SHIFT;
  84. spu_acquire(ctx);
  85. if (ctx->state == SPU_STATE_SAVED) {
  86. vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
  87. & ~(_PAGE_NO_CACHE | _PAGE_GUARDED));
  88. page = vmalloc_to_page(ctx->csa.lscsa->ls + offset);
  89. } else {
  90. vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
  91. | _PAGE_NO_CACHE | _PAGE_GUARDED);
  92. page = pfn_to_page((ctx->spu->local_store_phys + offset)
  93. >> PAGE_SHIFT);
  94. }
  95. spu_release(ctx);
  96. if (type)
  97. *type = VM_FAULT_MINOR;
  98. page_cache_get(page);
  99. return page;
  100. }
  101. static struct vm_operations_struct spufs_mem_mmap_vmops = {
  102. .nopage = spufs_mem_mmap_nopage,
  103. };
  104. static int
  105. spufs_mem_mmap(struct file *file, struct vm_area_struct *vma)
  106. {
  107. if (!(vma->vm_flags & VM_SHARED))
  108. return -EINVAL;
  109. /* FIXME: */
  110. vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
  111. | _PAGE_NO_CACHE);
  112. vma->vm_ops = &spufs_mem_mmap_vmops;
  113. return 0;
  114. }
  115. static struct file_operations spufs_mem_fops = {
  116. .open = spufs_mem_open,
  117. .read = spufs_mem_read,
  118. .write = spufs_mem_write,
  119. .llseek = generic_file_llseek,
  120. .mmap = spufs_mem_mmap,
  121. };
  122. static struct page *spufs_ps_nopage(struct vm_area_struct *vma,
  123. unsigned long address,
  124. int *type, unsigned long ps_offs,
  125. unsigned long ps_size)
  126. {
  127. struct page *page = NOPAGE_SIGBUS;
  128. int fault_type = VM_FAULT_SIGBUS;
  129. struct spu_context *ctx = vma->vm_file->private_data;
  130. unsigned long offset = address - vma->vm_start;
  131. unsigned long area;
  132. int ret;
  133. offset += vma->vm_pgoff << PAGE_SHIFT;
  134. if (offset >= ps_size)
  135. goto out;
  136. ret = spu_acquire_runnable(ctx);
  137. if (ret)
  138. goto out;
  139. area = ctx->spu->problem_phys + ps_offs;
  140. page = pfn_to_page((area + offset) >> PAGE_SHIFT);
  141. fault_type = VM_FAULT_MINOR;
  142. page_cache_get(page);
  143. spu_release(ctx);
  144. out:
  145. if (type)
  146. *type = fault_type;
  147. return page;
  148. }
  149. #if SPUFS_MMAP_4K
  150. static struct page *spufs_cntl_mmap_nopage(struct vm_area_struct *vma,
  151. unsigned long address, int *type)
  152. {
  153. return spufs_ps_nopage(vma, address, type, 0x4000, 0x1000);
  154. }
  155. static struct vm_operations_struct spufs_cntl_mmap_vmops = {
  156. .nopage = spufs_cntl_mmap_nopage,
  157. };
  158. /*
  159. * mmap support for problem state control area [0x4000 - 0x4fff].
  160. */
  161. static int spufs_cntl_mmap(struct file *file, struct vm_area_struct *vma)
  162. {
  163. if (!(vma->vm_flags & VM_SHARED))
  164. return -EINVAL;
  165. vma->vm_flags |= VM_RESERVED;
  166. vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
  167. | _PAGE_NO_CACHE | _PAGE_GUARDED);
  168. vma->vm_ops = &spufs_cntl_mmap_vmops;
  169. return 0;
  170. }
  171. #else /* SPUFS_MMAP_4K */
  172. #define spufs_cntl_mmap NULL
  173. #endif /* !SPUFS_MMAP_4K */
  174. static int spufs_cntl_open(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. file->private_data = ctx;
  179. file->f_mapping = inode->i_mapping;
  180. ctx->cntl = inode->i_mapping;
  181. return 0;
  182. }
  183. static ssize_t
  184. spufs_cntl_read(struct file *file, char __user *buffer,
  185. size_t size, loff_t *pos)
  186. {
  187. /* FIXME: read from spu status */
  188. return -EINVAL;
  189. }
  190. static ssize_t
  191. spufs_cntl_write(struct file *file, const char __user *buffer,
  192. size_t size, loff_t *pos)
  193. {
  194. /* FIXME: write to runctl bit */
  195. return -EINVAL;
  196. }
  197. static struct file_operations spufs_cntl_fops = {
  198. .open = spufs_cntl_open,
  199. .read = spufs_cntl_read,
  200. .write = spufs_cntl_write,
  201. .mmap = spufs_cntl_mmap,
  202. };
  203. static int
  204. spufs_regs_open(struct inode *inode, struct file *file)
  205. {
  206. struct spufs_inode_info *i = SPUFS_I(inode);
  207. file->private_data = i->i_ctx;
  208. return 0;
  209. }
  210. static ssize_t
  211. spufs_regs_read(struct file *file, char __user *buffer,
  212. size_t size, loff_t *pos)
  213. {
  214. struct spu_context *ctx = file->private_data;
  215. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  216. int ret;
  217. spu_acquire_saved(ctx);
  218. ret = simple_read_from_buffer(buffer, size, pos,
  219. lscsa->gprs, sizeof lscsa->gprs);
  220. spu_release(ctx);
  221. return ret;
  222. }
  223. static ssize_t
  224. spufs_regs_write(struct file *file, const char __user *buffer,
  225. size_t size, loff_t *pos)
  226. {
  227. struct spu_context *ctx = file->private_data;
  228. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  229. int ret;
  230. size = min_t(ssize_t, sizeof lscsa->gprs - *pos, size);
  231. if (size <= 0)
  232. return -EFBIG;
  233. *pos += size;
  234. spu_acquire_saved(ctx);
  235. ret = copy_from_user(lscsa->gprs + *pos - size,
  236. buffer, size) ? -EFAULT : size;
  237. spu_release(ctx);
  238. return ret;
  239. }
  240. static struct file_operations spufs_regs_fops = {
  241. .open = spufs_regs_open,
  242. .read = spufs_regs_read,
  243. .write = spufs_regs_write,
  244. .llseek = generic_file_llseek,
  245. };
  246. static ssize_t
  247. spufs_fpcr_read(struct file *file, char __user * buffer,
  248. size_t size, loff_t * pos)
  249. {
  250. struct spu_context *ctx = file->private_data;
  251. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  252. int ret;
  253. spu_acquire_saved(ctx);
  254. ret = simple_read_from_buffer(buffer, size, pos,
  255. &lscsa->fpcr, sizeof(lscsa->fpcr));
  256. spu_release(ctx);
  257. return ret;
  258. }
  259. static ssize_t
  260. spufs_fpcr_write(struct file *file, const char __user * buffer,
  261. size_t size, loff_t * pos)
  262. {
  263. struct spu_context *ctx = file->private_data;
  264. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  265. int ret;
  266. size = min_t(ssize_t, sizeof(lscsa->fpcr) - *pos, size);
  267. if (size <= 0)
  268. return -EFBIG;
  269. *pos += size;
  270. spu_acquire_saved(ctx);
  271. ret = copy_from_user((char *)&lscsa->fpcr + *pos - size,
  272. buffer, size) ? -EFAULT : size;
  273. spu_release(ctx);
  274. return ret;
  275. }
  276. static struct file_operations spufs_fpcr_fops = {
  277. .open = spufs_regs_open,
  278. .read = spufs_fpcr_read,
  279. .write = spufs_fpcr_write,
  280. .llseek = generic_file_llseek,
  281. };
  282. /* generic open function for all pipe-like files */
  283. static int spufs_pipe_open(struct inode *inode, struct file *file)
  284. {
  285. struct spufs_inode_info *i = SPUFS_I(inode);
  286. file->private_data = i->i_ctx;
  287. return nonseekable_open(inode, file);
  288. }
  289. /*
  290. * Read as many bytes from the mailbox as possible, until
  291. * one of the conditions becomes true:
  292. *
  293. * - no more data available in the mailbox
  294. * - end of the user provided buffer
  295. * - end of the mapped area
  296. */
  297. static ssize_t spufs_mbox_read(struct file *file, char __user *buf,
  298. size_t len, loff_t *pos)
  299. {
  300. struct spu_context *ctx = file->private_data;
  301. u32 mbox_data, __user *udata;
  302. ssize_t count;
  303. if (len < 4)
  304. return -EINVAL;
  305. if (!access_ok(VERIFY_WRITE, buf, len))
  306. return -EFAULT;
  307. udata = (void __user *)buf;
  308. spu_acquire(ctx);
  309. for (count = 0; count <= len; count += 4, udata++) {
  310. int ret;
  311. ret = ctx->ops->mbox_read(ctx, &mbox_data);
  312. if (ret == 0)
  313. break;
  314. /*
  315. * at the end of the mapped area, we can fault
  316. * but still need to return the data we have
  317. * read successfully so far.
  318. */
  319. ret = __put_user(mbox_data, udata);
  320. if (ret) {
  321. if (!count)
  322. count = -EFAULT;
  323. break;
  324. }
  325. }
  326. spu_release(ctx);
  327. if (!count)
  328. count = -EAGAIN;
  329. return count;
  330. }
  331. static struct file_operations spufs_mbox_fops = {
  332. .open = spufs_pipe_open,
  333. .read = spufs_mbox_read,
  334. };
  335. static ssize_t spufs_mbox_stat_read(struct file *file, char __user *buf,
  336. size_t len, loff_t *pos)
  337. {
  338. struct spu_context *ctx = file->private_data;
  339. u32 mbox_stat;
  340. if (len < 4)
  341. return -EINVAL;
  342. spu_acquire(ctx);
  343. mbox_stat = ctx->ops->mbox_stat_read(ctx) & 0xff;
  344. spu_release(ctx);
  345. if (copy_to_user(buf, &mbox_stat, sizeof mbox_stat))
  346. return -EFAULT;
  347. return 4;
  348. }
  349. static struct file_operations spufs_mbox_stat_fops = {
  350. .open = spufs_pipe_open,
  351. .read = spufs_mbox_stat_read,
  352. };
  353. /* low-level ibox access function */
  354. size_t spu_ibox_read(struct spu_context *ctx, u32 *data)
  355. {
  356. return ctx->ops->ibox_read(ctx, data);
  357. }
  358. static int spufs_ibox_fasync(int fd, struct file *file, int on)
  359. {
  360. struct spu_context *ctx = file->private_data;
  361. return fasync_helper(fd, file, on, &ctx->ibox_fasync);
  362. }
  363. /* interrupt-level ibox callback function. */
  364. void spufs_ibox_callback(struct spu *spu)
  365. {
  366. struct spu_context *ctx = spu->ctx;
  367. wake_up_all(&ctx->ibox_wq);
  368. kill_fasync(&ctx->ibox_fasync, SIGIO, POLLIN);
  369. }
  370. /*
  371. * Read as many bytes from the interrupt mailbox as possible, until
  372. * one of the conditions becomes true:
  373. *
  374. * - no more data available in the mailbox
  375. * - end of the user provided buffer
  376. * - end of the mapped area
  377. *
  378. * If the file is opened without O_NONBLOCK, we wait here until
  379. * any data is available, but return when we have been able to
  380. * read something.
  381. */
  382. static ssize_t spufs_ibox_read(struct file *file, char __user *buf,
  383. size_t len, loff_t *pos)
  384. {
  385. struct spu_context *ctx = file->private_data;
  386. u32 ibox_data, __user *udata;
  387. ssize_t count;
  388. if (len < 4)
  389. return -EINVAL;
  390. if (!access_ok(VERIFY_WRITE, buf, len))
  391. return -EFAULT;
  392. udata = (void __user *)buf;
  393. spu_acquire(ctx);
  394. /* wait only for the first element */
  395. count = 0;
  396. if (file->f_flags & O_NONBLOCK) {
  397. if (!spu_ibox_read(ctx, &ibox_data))
  398. count = -EAGAIN;
  399. } else {
  400. count = spufs_wait(ctx->ibox_wq, spu_ibox_read(ctx, &ibox_data));
  401. }
  402. if (count)
  403. goto out;
  404. /* if we can't write at all, return -EFAULT */
  405. count = __put_user(ibox_data, udata);
  406. if (count)
  407. goto out;
  408. for (count = 4, udata++; (count + 4) <= len; count += 4, udata++) {
  409. int ret;
  410. ret = ctx->ops->ibox_read(ctx, &ibox_data);
  411. if (ret == 0)
  412. break;
  413. /*
  414. * at the end of the mapped area, we can fault
  415. * but still need to return the data we have
  416. * read successfully so far.
  417. */
  418. ret = __put_user(ibox_data, udata);
  419. if (ret)
  420. break;
  421. }
  422. out:
  423. spu_release(ctx);
  424. return count;
  425. }
  426. static unsigned int spufs_ibox_poll(struct file *file, poll_table *wait)
  427. {
  428. struct spu_context *ctx = file->private_data;
  429. unsigned int mask;
  430. poll_wait(file, &ctx->ibox_wq, wait);
  431. spu_acquire(ctx);
  432. mask = ctx->ops->mbox_stat_poll(ctx, POLLIN | POLLRDNORM);
  433. spu_release(ctx);
  434. return mask;
  435. }
  436. static struct file_operations spufs_ibox_fops = {
  437. .open = spufs_pipe_open,
  438. .read = spufs_ibox_read,
  439. .poll = spufs_ibox_poll,
  440. .fasync = spufs_ibox_fasync,
  441. };
  442. static ssize_t spufs_ibox_stat_read(struct file *file, char __user *buf,
  443. size_t len, loff_t *pos)
  444. {
  445. struct spu_context *ctx = file->private_data;
  446. u32 ibox_stat;
  447. if (len < 4)
  448. return -EINVAL;
  449. spu_acquire(ctx);
  450. ibox_stat = (ctx->ops->mbox_stat_read(ctx) >> 16) & 0xff;
  451. spu_release(ctx);
  452. if (copy_to_user(buf, &ibox_stat, sizeof ibox_stat))
  453. return -EFAULT;
  454. return 4;
  455. }
  456. static struct file_operations spufs_ibox_stat_fops = {
  457. .open = spufs_pipe_open,
  458. .read = spufs_ibox_stat_read,
  459. };
  460. /* low-level mailbox write */
  461. size_t spu_wbox_write(struct spu_context *ctx, u32 data)
  462. {
  463. return ctx->ops->wbox_write(ctx, data);
  464. }
  465. static int spufs_wbox_fasync(int fd, struct file *file, int on)
  466. {
  467. struct spu_context *ctx = file->private_data;
  468. int ret;
  469. ret = fasync_helper(fd, file, on, &ctx->wbox_fasync);
  470. return ret;
  471. }
  472. /* interrupt-level wbox callback function. */
  473. void spufs_wbox_callback(struct spu *spu)
  474. {
  475. struct spu_context *ctx = spu->ctx;
  476. wake_up_all(&ctx->wbox_wq);
  477. kill_fasync(&ctx->wbox_fasync, SIGIO, POLLOUT);
  478. }
  479. /*
  480. * Write as many bytes to the interrupt mailbox as possible, until
  481. * one of the conditions becomes true:
  482. *
  483. * - the mailbox is full
  484. * - end of the user provided buffer
  485. * - end of the mapped area
  486. *
  487. * If the file is opened without O_NONBLOCK, we wait here until
  488. * space is availabyl, but return when we have been able to
  489. * write something.
  490. */
  491. static ssize_t spufs_wbox_write(struct file *file, const char __user *buf,
  492. size_t len, loff_t *pos)
  493. {
  494. struct spu_context *ctx = file->private_data;
  495. u32 wbox_data, __user *udata;
  496. ssize_t count;
  497. if (len < 4)
  498. return -EINVAL;
  499. udata = (void __user *)buf;
  500. if (!access_ok(VERIFY_READ, buf, len))
  501. return -EFAULT;
  502. if (__get_user(wbox_data, udata))
  503. return -EFAULT;
  504. spu_acquire(ctx);
  505. /*
  506. * make sure we can at least write one element, by waiting
  507. * in case of !O_NONBLOCK
  508. */
  509. count = 0;
  510. if (file->f_flags & O_NONBLOCK) {
  511. if (!spu_wbox_write(ctx, wbox_data))
  512. count = -EAGAIN;
  513. } else {
  514. count = spufs_wait(ctx->wbox_wq, spu_wbox_write(ctx, wbox_data));
  515. }
  516. if (count)
  517. goto out;
  518. /* write aѕ much as possible */
  519. for (count = 4, udata++; (count + 4) <= len; count += 4, udata++) {
  520. int ret;
  521. ret = __get_user(wbox_data, udata);
  522. if (ret)
  523. break;
  524. ret = spu_wbox_write(ctx, wbox_data);
  525. if (ret == 0)
  526. break;
  527. }
  528. out:
  529. spu_release(ctx);
  530. return count;
  531. }
  532. static unsigned int spufs_wbox_poll(struct file *file, poll_table *wait)
  533. {
  534. struct spu_context *ctx = file->private_data;
  535. unsigned int mask;
  536. poll_wait(file, &ctx->wbox_wq, wait);
  537. spu_acquire(ctx);
  538. mask = ctx->ops->mbox_stat_poll(ctx, POLLOUT | POLLWRNORM);
  539. spu_release(ctx);
  540. return mask;
  541. }
  542. static struct file_operations spufs_wbox_fops = {
  543. .open = spufs_pipe_open,
  544. .write = spufs_wbox_write,
  545. .poll = spufs_wbox_poll,
  546. .fasync = spufs_wbox_fasync,
  547. };
  548. static ssize_t spufs_wbox_stat_read(struct file *file, char __user *buf,
  549. size_t len, loff_t *pos)
  550. {
  551. struct spu_context *ctx = file->private_data;
  552. u32 wbox_stat;
  553. if (len < 4)
  554. return -EINVAL;
  555. spu_acquire(ctx);
  556. wbox_stat = (ctx->ops->mbox_stat_read(ctx) >> 8) & 0xff;
  557. spu_release(ctx);
  558. if (copy_to_user(buf, &wbox_stat, sizeof wbox_stat))
  559. return -EFAULT;
  560. return 4;
  561. }
  562. static struct file_operations spufs_wbox_stat_fops = {
  563. .open = spufs_pipe_open,
  564. .read = spufs_wbox_stat_read,
  565. };
  566. static int spufs_signal1_open(struct inode *inode, struct file *file)
  567. {
  568. struct spufs_inode_info *i = SPUFS_I(inode);
  569. struct spu_context *ctx = i->i_ctx;
  570. file->private_data = ctx;
  571. file->f_mapping = inode->i_mapping;
  572. ctx->signal1 = inode->i_mapping;
  573. return nonseekable_open(inode, file);
  574. }
  575. static ssize_t spufs_signal1_read(struct file *file, char __user *buf,
  576. size_t len, loff_t *pos)
  577. {
  578. struct spu_context *ctx = file->private_data;
  579. u32 data;
  580. if (len < 4)
  581. return -EINVAL;
  582. spu_acquire(ctx);
  583. data = ctx->ops->signal1_read(ctx);
  584. spu_release(ctx);
  585. if (copy_to_user(buf, &data, 4))
  586. return -EFAULT;
  587. return 4;
  588. }
  589. static ssize_t spufs_signal1_write(struct file *file, const char __user *buf,
  590. size_t len, loff_t *pos)
  591. {
  592. struct spu_context *ctx;
  593. u32 data;
  594. ctx = file->private_data;
  595. if (len < 4)
  596. return -EINVAL;
  597. if (copy_from_user(&data, buf, 4))
  598. return -EFAULT;
  599. spu_acquire(ctx);
  600. ctx->ops->signal1_write(ctx, data);
  601. spu_release(ctx);
  602. return 4;
  603. }
  604. static struct page *spufs_signal1_mmap_nopage(struct vm_area_struct *vma,
  605. unsigned long address, int *type)
  606. {
  607. #if PAGE_SIZE == 0x1000
  608. return spufs_ps_nopage(vma, address, type, 0x14000, 0x1000);
  609. #elif PAGE_SIZE == 0x10000
  610. /* For 64k pages, both signal1 and signal2 can be used to mmap the whole
  611. * signal 1 and 2 area
  612. */
  613. return spufs_ps_nopage(vma, address, type, 0x10000, 0x10000);
  614. #else
  615. #error unsupported page size
  616. #endif
  617. }
  618. static struct vm_operations_struct spufs_signal1_mmap_vmops = {
  619. .nopage = spufs_signal1_mmap_nopage,
  620. };
  621. static int spufs_signal1_mmap(struct file *file, struct vm_area_struct *vma)
  622. {
  623. if (!(vma->vm_flags & VM_SHARED))
  624. return -EINVAL;
  625. vma->vm_flags |= VM_RESERVED;
  626. vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
  627. | _PAGE_NO_CACHE | _PAGE_GUARDED);
  628. vma->vm_ops = &spufs_signal1_mmap_vmops;
  629. return 0;
  630. }
  631. static struct file_operations spufs_signal1_fops = {
  632. .open = spufs_signal1_open,
  633. .read = spufs_signal1_read,
  634. .write = spufs_signal1_write,
  635. .mmap = spufs_signal1_mmap,
  636. };
  637. static int spufs_signal2_open(struct inode *inode, struct file *file)
  638. {
  639. struct spufs_inode_info *i = SPUFS_I(inode);
  640. struct spu_context *ctx = i->i_ctx;
  641. file->private_data = ctx;
  642. file->f_mapping = inode->i_mapping;
  643. ctx->signal2 = inode->i_mapping;
  644. return nonseekable_open(inode, file);
  645. }
  646. static ssize_t spufs_signal2_read(struct file *file, char __user *buf,
  647. size_t len, loff_t *pos)
  648. {
  649. struct spu_context *ctx;
  650. u32 data;
  651. ctx = file->private_data;
  652. if (len < 4)
  653. return -EINVAL;
  654. spu_acquire(ctx);
  655. data = ctx->ops->signal2_read(ctx);
  656. spu_release(ctx);
  657. if (copy_to_user(buf, &data, 4))
  658. return -EFAULT;
  659. return 4;
  660. }
  661. static ssize_t spufs_signal2_write(struct file *file, const char __user *buf,
  662. size_t len, loff_t *pos)
  663. {
  664. struct spu_context *ctx;
  665. u32 data;
  666. ctx = file->private_data;
  667. if (len < 4)
  668. return -EINVAL;
  669. if (copy_from_user(&data, buf, 4))
  670. return -EFAULT;
  671. spu_acquire(ctx);
  672. ctx->ops->signal2_write(ctx, data);
  673. spu_release(ctx);
  674. return 4;
  675. }
  676. #if SPUFS_MMAP_4K
  677. static struct page *spufs_signal2_mmap_nopage(struct vm_area_struct *vma,
  678. unsigned long address, int *type)
  679. {
  680. #if PAGE_SIZE == 0x1000
  681. return spufs_ps_nopage(vma, address, type, 0x1c000, 0x1000);
  682. #elif PAGE_SIZE == 0x10000
  683. /* For 64k pages, both signal1 and signal2 can be used to mmap the whole
  684. * signal 1 and 2 area
  685. */
  686. return spufs_ps_nopage(vma, address, type, 0x10000, 0x10000);
  687. #else
  688. #error unsupported page size
  689. #endif
  690. }
  691. static struct vm_operations_struct spufs_signal2_mmap_vmops = {
  692. .nopage = spufs_signal2_mmap_nopage,
  693. };
  694. static int spufs_signal2_mmap(struct file *file, struct vm_area_struct *vma)
  695. {
  696. if (!(vma->vm_flags & VM_SHARED))
  697. return -EINVAL;
  698. /* FIXME: */
  699. vma->vm_flags |= VM_RESERVED;
  700. vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
  701. | _PAGE_NO_CACHE | _PAGE_GUARDED);
  702. vma->vm_ops = &spufs_signal2_mmap_vmops;
  703. return 0;
  704. }
  705. #else /* SPUFS_MMAP_4K */
  706. #define spufs_signal2_mmap NULL
  707. #endif /* !SPUFS_MMAP_4K */
  708. static struct file_operations spufs_signal2_fops = {
  709. .open = spufs_signal2_open,
  710. .read = spufs_signal2_read,
  711. .write = spufs_signal2_write,
  712. .mmap = spufs_signal2_mmap,
  713. };
  714. static void spufs_signal1_type_set(void *data, u64 val)
  715. {
  716. struct spu_context *ctx = data;
  717. spu_acquire(ctx);
  718. ctx->ops->signal1_type_set(ctx, val);
  719. spu_release(ctx);
  720. }
  721. static u64 spufs_signal1_type_get(void *data)
  722. {
  723. struct spu_context *ctx = data;
  724. u64 ret;
  725. spu_acquire(ctx);
  726. ret = ctx->ops->signal1_type_get(ctx);
  727. spu_release(ctx);
  728. return ret;
  729. }
  730. DEFINE_SIMPLE_ATTRIBUTE(spufs_signal1_type, spufs_signal1_type_get,
  731. spufs_signal1_type_set, "%llu");
  732. static void spufs_signal2_type_set(void *data, u64 val)
  733. {
  734. struct spu_context *ctx = data;
  735. spu_acquire(ctx);
  736. ctx->ops->signal2_type_set(ctx, val);
  737. spu_release(ctx);
  738. }
  739. static u64 spufs_signal2_type_get(void *data)
  740. {
  741. struct spu_context *ctx = data;
  742. u64 ret;
  743. spu_acquire(ctx);
  744. ret = ctx->ops->signal2_type_get(ctx);
  745. spu_release(ctx);
  746. return ret;
  747. }
  748. DEFINE_SIMPLE_ATTRIBUTE(spufs_signal2_type, spufs_signal2_type_get,
  749. spufs_signal2_type_set, "%llu");
  750. #if SPUFS_MMAP_4K
  751. static struct page *spufs_mss_mmap_nopage(struct vm_area_struct *vma,
  752. unsigned long address, int *type)
  753. {
  754. return spufs_ps_nopage(vma, address, type, 0x0000, 0x1000);
  755. }
  756. static struct vm_operations_struct spufs_mss_mmap_vmops = {
  757. .nopage = spufs_mss_mmap_nopage,
  758. };
  759. /*
  760. * mmap support for problem state MFC DMA area [0x0000 - 0x0fff].
  761. */
  762. static int spufs_mss_mmap(struct file *file, struct vm_area_struct *vma)
  763. {
  764. if (!(vma->vm_flags & VM_SHARED))
  765. return -EINVAL;
  766. vma->vm_flags |= VM_RESERVED;
  767. vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
  768. | _PAGE_NO_CACHE | _PAGE_GUARDED);
  769. vma->vm_ops = &spufs_mss_mmap_vmops;
  770. return 0;
  771. }
  772. #else /* SPUFS_MMAP_4K */
  773. #define spufs_mss_mmap NULL
  774. #endif /* !SPUFS_MMAP_4K */
  775. static int spufs_mss_open(struct inode *inode, struct file *file)
  776. {
  777. struct spufs_inode_info *i = SPUFS_I(inode);
  778. file->private_data = i->i_ctx;
  779. return nonseekable_open(inode, file);
  780. }
  781. static struct file_operations spufs_mss_fops = {
  782. .open = spufs_mss_open,
  783. .mmap = spufs_mss_mmap,
  784. };
  785. static struct page *spufs_psmap_mmap_nopage(struct vm_area_struct *vma,
  786. unsigned long address, int *type)
  787. {
  788. return spufs_ps_nopage(vma, address, type, 0x0000, 0x20000);
  789. }
  790. static struct vm_operations_struct spufs_psmap_mmap_vmops = {
  791. .nopage = spufs_psmap_mmap_nopage,
  792. };
  793. /*
  794. * mmap support for full problem state area [0x00000 - 0x1ffff].
  795. */
  796. static int spufs_psmap_mmap(struct file *file, struct vm_area_struct *vma)
  797. {
  798. if (!(vma->vm_flags & VM_SHARED))
  799. return -EINVAL;
  800. vma->vm_flags |= VM_RESERVED;
  801. vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
  802. | _PAGE_NO_CACHE | _PAGE_GUARDED);
  803. vma->vm_ops = &spufs_psmap_mmap_vmops;
  804. return 0;
  805. }
  806. static int spufs_psmap_open(struct inode *inode, struct file *file)
  807. {
  808. struct spufs_inode_info *i = SPUFS_I(inode);
  809. file->private_data = i->i_ctx;
  810. return nonseekable_open(inode, file);
  811. }
  812. static struct file_operations spufs_psmap_fops = {
  813. .open = spufs_psmap_open,
  814. .mmap = spufs_psmap_mmap,
  815. };
  816. #if SPUFS_MMAP_4K
  817. static struct page *spufs_mfc_mmap_nopage(struct vm_area_struct *vma,
  818. unsigned long address, int *type)
  819. {
  820. return spufs_ps_nopage(vma, address, type, 0x3000, 0x1000);
  821. }
  822. static struct vm_operations_struct spufs_mfc_mmap_vmops = {
  823. .nopage = spufs_mfc_mmap_nopage,
  824. };
  825. /*
  826. * mmap support for problem state MFC DMA area [0x0000 - 0x0fff].
  827. */
  828. static int spufs_mfc_mmap(struct file *file, struct vm_area_struct *vma)
  829. {
  830. if (!(vma->vm_flags & VM_SHARED))
  831. return -EINVAL;
  832. vma->vm_flags |= VM_RESERVED;
  833. vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
  834. | _PAGE_NO_CACHE | _PAGE_GUARDED);
  835. vma->vm_ops = &spufs_mfc_mmap_vmops;
  836. return 0;
  837. }
  838. #else /* SPUFS_MMAP_4K */
  839. #define spufs_mfc_mmap NULL
  840. #endif /* !SPUFS_MMAP_4K */
  841. static int spufs_mfc_open(struct inode *inode, struct file *file)
  842. {
  843. struct spufs_inode_info *i = SPUFS_I(inode);
  844. struct spu_context *ctx = i->i_ctx;
  845. /* we don't want to deal with DMA into other processes */
  846. if (ctx->owner != current->mm)
  847. return -EINVAL;
  848. if (atomic_read(&inode->i_count) != 1)
  849. return -EBUSY;
  850. file->private_data = ctx;
  851. return nonseekable_open(inode, file);
  852. }
  853. /* interrupt-level mfc callback function. */
  854. void spufs_mfc_callback(struct spu *spu)
  855. {
  856. struct spu_context *ctx = spu->ctx;
  857. wake_up_all(&ctx->mfc_wq);
  858. pr_debug("%s %s\n", __FUNCTION__, spu->name);
  859. if (ctx->mfc_fasync) {
  860. u32 free_elements, tagstatus;
  861. unsigned int mask;
  862. /* no need for spu_acquire in interrupt context */
  863. free_elements = ctx->ops->get_mfc_free_elements(ctx);
  864. tagstatus = ctx->ops->read_mfc_tagstatus(ctx);
  865. mask = 0;
  866. if (free_elements & 0xffff)
  867. mask |= POLLOUT;
  868. if (tagstatus & ctx->tagwait)
  869. mask |= POLLIN;
  870. kill_fasync(&ctx->mfc_fasync, SIGIO, mask);
  871. }
  872. }
  873. static int spufs_read_mfc_tagstatus(struct spu_context *ctx, u32 *status)
  874. {
  875. /* See if there is one tag group is complete */
  876. /* FIXME we need locking around tagwait */
  877. *status = ctx->ops->read_mfc_tagstatus(ctx) & ctx->tagwait;
  878. ctx->tagwait &= ~*status;
  879. if (*status)
  880. return 1;
  881. /* enable interrupt waiting for any tag group,
  882. may silently fail if interrupts are already enabled */
  883. ctx->ops->set_mfc_query(ctx, ctx->tagwait, 1);
  884. return 0;
  885. }
  886. static ssize_t spufs_mfc_read(struct file *file, char __user *buffer,
  887. size_t size, loff_t *pos)
  888. {
  889. struct spu_context *ctx = file->private_data;
  890. int ret = -EINVAL;
  891. u32 status;
  892. if (size != 4)
  893. goto out;
  894. spu_acquire(ctx);
  895. if (file->f_flags & O_NONBLOCK) {
  896. status = ctx->ops->read_mfc_tagstatus(ctx);
  897. if (!(status & ctx->tagwait))
  898. ret = -EAGAIN;
  899. else
  900. ctx->tagwait &= ~status;
  901. } else {
  902. ret = spufs_wait(ctx->mfc_wq,
  903. spufs_read_mfc_tagstatus(ctx, &status));
  904. }
  905. spu_release(ctx);
  906. if (ret)
  907. goto out;
  908. ret = 4;
  909. if (copy_to_user(buffer, &status, 4))
  910. ret = -EFAULT;
  911. out:
  912. return ret;
  913. }
  914. static int spufs_check_valid_dma(struct mfc_dma_command *cmd)
  915. {
  916. pr_debug("queueing DMA %x %lx %x %x %x\n", cmd->lsa,
  917. cmd->ea, cmd->size, cmd->tag, cmd->cmd);
  918. switch (cmd->cmd) {
  919. case MFC_PUT_CMD:
  920. case MFC_PUTF_CMD:
  921. case MFC_PUTB_CMD:
  922. case MFC_GET_CMD:
  923. case MFC_GETF_CMD:
  924. case MFC_GETB_CMD:
  925. break;
  926. default:
  927. pr_debug("invalid DMA opcode %x\n", cmd->cmd);
  928. return -EIO;
  929. }
  930. if ((cmd->lsa & 0xf) != (cmd->ea &0xf)) {
  931. pr_debug("invalid DMA alignment, ea %lx lsa %x\n",
  932. cmd->ea, cmd->lsa);
  933. return -EIO;
  934. }
  935. switch (cmd->size & 0xf) {
  936. case 1:
  937. break;
  938. case 2:
  939. if (cmd->lsa & 1)
  940. goto error;
  941. break;
  942. case 4:
  943. if (cmd->lsa & 3)
  944. goto error;
  945. break;
  946. case 8:
  947. if (cmd->lsa & 7)
  948. goto error;
  949. break;
  950. case 0:
  951. if (cmd->lsa & 15)
  952. goto error;
  953. break;
  954. error:
  955. default:
  956. pr_debug("invalid DMA alignment %x for size %x\n",
  957. cmd->lsa & 0xf, cmd->size);
  958. return -EIO;
  959. }
  960. if (cmd->size > 16 * 1024) {
  961. pr_debug("invalid DMA size %x\n", cmd->size);
  962. return -EIO;
  963. }
  964. if (cmd->tag & 0xfff0) {
  965. /* we reserve the higher tag numbers for kernel use */
  966. pr_debug("invalid DMA tag\n");
  967. return -EIO;
  968. }
  969. if (cmd->class) {
  970. /* not supported in this version */
  971. pr_debug("invalid DMA class\n");
  972. return -EIO;
  973. }
  974. return 0;
  975. }
  976. static int spu_send_mfc_command(struct spu_context *ctx,
  977. struct mfc_dma_command cmd,
  978. int *error)
  979. {
  980. *error = ctx->ops->send_mfc_command(ctx, &cmd);
  981. if (*error == -EAGAIN) {
  982. /* wait for any tag group to complete
  983. so we have space for the new command */
  984. ctx->ops->set_mfc_query(ctx, ctx->tagwait, 1);
  985. /* try again, because the queue might be
  986. empty again */
  987. *error = ctx->ops->send_mfc_command(ctx, &cmd);
  988. if (*error == -EAGAIN)
  989. return 0;
  990. }
  991. return 1;
  992. }
  993. static ssize_t spufs_mfc_write(struct file *file, const char __user *buffer,
  994. size_t size, loff_t *pos)
  995. {
  996. struct spu_context *ctx = file->private_data;
  997. struct mfc_dma_command cmd;
  998. int ret = -EINVAL;
  999. if (size != sizeof cmd)
  1000. goto out;
  1001. ret = -EFAULT;
  1002. if (copy_from_user(&cmd, buffer, sizeof cmd))
  1003. goto out;
  1004. ret = spufs_check_valid_dma(&cmd);
  1005. if (ret)
  1006. goto out;
  1007. spu_acquire_runnable(ctx);
  1008. if (file->f_flags & O_NONBLOCK) {
  1009. ret = ctx->ops->send_mfc_command(ctx, &cmd);
  1010. } else {
  1011. int status;
  1012. ret = spufs_wait(ctx->mfc_wq,
  1013. spu_send_mfc_command(ctx, cmd, &status));
  1014. if (status)
  1015. ret = status;
  1016. }
  1017. spu_release(ctx);
  1018. if (ret)
  1019. goto out;
  1020. ctx->tagwait |= 1 << cmd.tag;
  1021. out:
  1022. return ret;
  1023. }
  1024. static unsigned int spufs_mfc_poll(struct file *file,poll_table *wait)
  1025. {
  1026. struct spu_context *ctx = file->private_data;
  1027. u32 free_elements, tagstatus;
  1028. unsigned int mask;
  1029. spu_acquire(ctx);
  1030. ctx->ops->set_mfc_query(ctx, ctx->tagwait, 2);
  1031. free_elements = ctx->ops->get_mfc_free_elements(ctx);
  1032. tagstatus = ctx->ops->read_mfc_tagstatus(ctx);
  1033. spu_release(ctx);
  1034. poll_wait(file, &ctx->mfc_wq, wait);
  1035. mask = 0;
  1036. if (free_elements & 0xffff)
  1037. mask |= POLLOUT | POLLWRNORM;
  1038. if (tagstatus & ctx->tagwait)
  1039. mask |= POLLIN | POLLRDNORM;
  1040. pr_debug("%s: free %d tagstatus %d tagwait %d\n", __FUNCTION__,
  1041. free_elements, tagstatus, ctx->tagwait);
  1042. return mask;
  1043. }
  1044. static int spufs_mfc_flush(struct file *file, fl_owner_t id)
  1045. {
  1046. struct spu_context *ctx = file->private_data;
  1047. int ret;
  1048. spu_acquire(ctx);
  1049. #if 0
  1050. /* this currently hangs */
  1051. ret = spufs_wait(ctx->mfc_wq,
  1052. ctx->ops->set_mfc_query(ctx, ctx->tagwait, 2));
  1053. if (ret)
  1054. goto out;
  1055. ret = spufs_wait(ctx->mfc_wq,
  1056. ctx->ops->read_mfc_tagstatus(ctx) == ctx->tagwait);
  1057. out:
  1058. #else
  1059. ret = 0;
  1060. #endif
  1061. spu_release(ctx);
  1062. return ret;
  1063. }
  1064. static int spufs_mfc_fsync(struct file *file, struct dentry *dentry,
  1065. int datasync)
  1066. {
  1067. return spufs_mfc_flush(file, NULL);
  1068. }
  1069. static int spufs_mfc_fasync(int fd, struct file *file, int on)
  1070. {
  1071. struct spu_context *ctx = file->private_data;
  1072. return fasync_helper(fd, file, on, &ctx->mfc_fasync);
  1073. }
  1074. static struct file_operations spufs_mfc_fops = {
  1075. .open = spufs_mfc_open,
  1076. .read = spufs_mfc_read,
  1077. .write = spufs_mfc_write,
  1078. .poll = spufs_mfc_poll,
  1079. .flush = spufs_mfc_flush,
  1080. .fsync = spufs_mfc_fsync,
  1081. .fasync = spufs_mfc_fasync,
  1082. .mmap = spufs_mfc_mmap,
  1083. };
  1084. static void spufs_npc_set(void *data, u64 val)
  1085. {
  1086. struct spu_context *ctx = data;
  1087. spu_acquire(ctx);
  1088. ctx->ops->npc_write(ctx, val);
  1089. spu_release(ctx);
  1090. }
  1091. static u64 spufs_npc_get(void *data)
  1092. {
  1093. struct spu_context *ctx = data;
  1094. u64 ret;
  1095. spu_acquire(ctx);
  1096. ret = ctx->ops->npc_read(ctx);
  1097. spu_release(ctx);
  1098. return ret;
  1099. }
  1100. DEFINE_SIMPLE_ATTRIBUTE(spufs_npc_ops, spufs_npc_get, spufs_npc_set, "%llx\n")
  1101. static void spufs_decr_set(void *data, u64 val)
  1102. {
  1103. struct spu_context *ctx = data;
  1104. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  1105. spu_acquire_saved(ctx);
  1106. lscsa->decr.slot[0] = (u32) val;
  1107. spu_release(ctx);
  1108. }
  1109. static u64 spufs_decr_get(void *data)
  1110. {
  1111. struct spu_context *ctx = data;
  1112. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  1113. u64 ret;
  1114. spu_acquire_saved(ctx);
  1115. ret = lscsa->decr.slot[0];
  1116. spu_release(ctx);
  1117. return ret;
  1118. }
  1119. DEFINE_SIMPLE_ATTRIBUTE(spufs_decr_ops, spufs_decr_get, spufs_decr_set,
  1120. "%llx\n")
  1121. static void spufs_decr_status_set(void *data, u64 val)
  1122. {
  1123. struct spu_context *ctx = data;
  1124. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  1125. spu_acquire_saved(ctx);
  1126. lscsa->decr_status.slot[0] = (u32) val;
  1127. spu_release(ctx);
  1128. }
  1129. static u64 spufs_decr_status_get(void *data)
  1130. {
  1131. struct spu_context *ctx = data;
  1132. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  1133. u64 ret;
  1134. spu_acquire_saved(ctx);
  1135. ret = lscsa->decr_status.slot[0];
  1136. spu_release(ctx);
  1137. return ret;
  1138. }
  1139. DEFINE_SIMPLE_ATTRIBUTE(spufs_decr_status_ops, spufs_decr_status_get,
  1140. spufs_decr_status_set, "%llx\n")
  1141. static void spufs_spu_tag_mask_set(void *data, u64 val)
  1142. {
  1143. struct spu_context *ctx = data;
  1144. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  1145. spu_acquire_saved(ctx);
  1146. lscsa->tag_mask.slot[0] = (u32) val;
  1147. spu_release(ctx);
  1148. }
  1149. static u64 spufs_spu_tag_mask_get(void *data)
  1150. {
  1151. struct spu_context *ctx = data;
  1152. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  1153. u64 ret;
  1154. spu_acquire_saved(ctx);
  1155. ret = lscsa->tag_mask.slot[0];
  1156. spu_release(ctx);
  1157. return ret;
  1158. }
  1159. DEFINE_SIMPLE_ATTRIBUTE(spufs_spu_tag_mask_ops, spufs_spu_tag_mask_get,
  1160. spufs_spu_tag_mask_set, "%llx\n")
  1161. static void spufs_event_mask_set(void *data, u64 val)
  1162. {
  1163. struct spu_context *ctx = data;
  1164. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  1165. spu_acquire_saved(ctx);
  1166. lscsa->event_mask.slot[0] = (u32) val;
  1167. spu_release(ctx);
  1168. }
  1169. static u64 spufs_event_mask_get(void *data)
  1170. {
  1171. struct spu_context *ctx = data;
  1172. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  1173. u64 ret;
  1174. spu_acquire_saved(ctx);
  1175. ret = lscsa->event_mask.slot[0];
  1176. spu_release(ctx);
  1177. return ret;
  1178. }
  1179. DEFINE_SIMPLE_ATTRIBUTE(spufs_event_mask_ops, spufs_event_mask_get,
  1180. spufs_event_mask_set, "%llx\n")
  1181. static void spufs_srr0_set(void *data, u64 val)
  1182. {
  1183. struct spu_context *ctx = data;
  1184. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  1185. spu_acquire_saved(ctx);
  1186. lscsa->srr0.slot[0] = (u32) val;
  1187. spu_release(ctx);
  1188. }
  1189. static u64 spufs_srr0_get(void *data)
  1190. {
  1191. struct spu_context *ctx = data;
  1192. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  1193. u64 ret;
  1194. spu_acquire_saved(ctx);
  1195. ret = lscsa->srr0.slot[0];
  1196. spu_release(ctx);
  1197. return ret;
  1198. }
  1199. DEFINE_SIMPLE_ATTRIBUTE(spufs_srr0_ops, spufs_srr0_get, spufs_srr0_set,
  1200. "%llx\n")
  1201. static u64 spufs_id_get(void *data)
  1202. {
  1203. struct spu_context *ctx = data;
  1204. u64 num;
  1205. spu_acquire(ctx);
  1206. if (ctx->state == SPU_STATE_RUNNABLE)
  1207. num = ctx->spu->number;
  1208. else
  1209. num = (unsigned int)-1;
  1210. spu_release(ctx);
  1211. return num;
  1212. }
  1213. DEFINE_SIMPLE_ATTRIBUTE(spufs_id_ops, spufs_id_get, NULL, "0x%llx\n")
  1214. struct tree_descr spufs_dir_contents[] = {
  1215. { "mem", &spufs_mem_fops, 0666, },
  1216. { "regs", &spufs_regs_fops, 0666, },
  1217. { "mbox", &spufs_mbox_fops, 0444, },
  1218. { "ibox", &spufs_ibox_fops, 0444, },
  1219. { "wbox", &spufs_wbox_fops, 0222, },
  1220. { "mbox_stat", &spufs_mbox_stat_fops, 0444, },
  1221. { "ibox_stat", &spufs_ibox_stat_fops, 0444, },
  1222. { "wbox_stat", &spufs_wbox_stat_fops, 0444, },
  1223. { "signal1", &spufs_signal1_fops, 0666, },
  1224. { "signal2", &spufs_signal2_fops, 0666, },
  1225. { "signal1_type", &spufs_signal1_type, 0666, },
  1226. { "signal2_type", &spufs_signal2_type, 0666, },
  1227. { "mss", &spufs_mss_fops, 0666, },
  1228. { "mfc", &spufs_mfc_fops, 0666, },
  1229. { "cntl", &spufs_cntl_fops, 0666, },
  1230. { "npc", &spufs_npc_ops, 0666, },
  1231. { "fpcr", &spufs_fpcr_fops, 0666, },
  1232. { "decr", &spufs_decr_ops, 0666, },
  1233. { "decr_status", &spufs_decr_status_ops, 0666, },
  1234. { "spu_tag_mask", &spufs_spu_tag_mask_ops, 0666, },
  1235. { "event_mask", &spufs_event_mask_ops, 0666, },
  1236. { "srr0", &spufs_srr0_ops, 0666, },
  1237. { "phys-id", &spufs_id_ops, 0666, },
  1238. { "psmap", &spufs_psmap_fops, 0666, },
  1239. {},
  1240. };