file.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414
  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. static ssize_t spufs_mbox_read(struct file *file, char __user *buf,
  290. size_t len, loff_t *pos)
  291. {
  292. struct spu_context *ctx = file->private_data;
  293. u32 mbox_data;
  294. int ret;
  295. if (len < 4)
  296. return -EINVAL;
  297. spu_acquire(ctx);
  298. ret = ctx->ops->mbox_read(ctx, &mbox_data);
  299. spu_release(ctx);
  300. if (!ret)
  301. return -EAGAIN;
  302. if (copy_to_user(buf, &mbox_data, sizeof mbox_data))
  303. return -EFAULT;
  304. return 4;
  305. }
  306. static struct file_operations spufs_mbox_fops = {
  307. .open = spufs_pipe_open,
  308. .read = spufs_mbox_read,
  309. };
  310. static ssize_t spufs_mbox_stat_read(struct file *file, char __user *buf,
  311. size_t len, loff_t *pos)
  312. {
  313. struct spu_context *ctx = file->private_data;
  314. u32 mbox_stat;
  315. if (len < 4)
  316. return -EINVAL;
  317. spu_acquire(ctx);
  318. mbox_stat = ctx->ops->mbox_stat_read(ctx) & 0xff;
  319. spu_release(ctx);
  320. if (copy_to_user(buf, &mbox_stat, sizeof mbox_stat))
  321. return -EFAULT;
  322. return 4;
  323. }
  324. static struct file_operations spufs_mbox_stat_fops = {
  325. .open = spufs_pipe_open,
  326. .read = spufs_mbox_stat_read,
  327. };
  328. /* low-level ibox access function */
  329. size_t spu_ibox_read(struct spu_context *ctx, u32 *data)
  330. {
  331. return ctx->ops->ibox_read(ctx, data);
  332. }
  333. static int spufs_ibox_fasync(int fd, struct file *file, int on)
  334. {
  335. struct spu_context *ctx = file->private_data;
  336. return fasync_helper(fd, file, on, &ctx->ibox_fasync);
  337. }
  338. /* interrupt-level ibox callback function. */
  339. void spufs_ibox_callback(struct spu *spu)
  340. {
  341. struct spu_context *ctx = spu->ctx;
  342. wake_up_all(&ctx->ibox_wq);
  343. kill_fasync(&ctx->ibox_fasync, SIGIO, POLLIN);
  344. }
  345. static ssize_t spufs_ibox_read(struct file *file, char __user *buf,
  346. size_t len, loff_t *pos)
  347. {
  348. struct spu_context *ctx = file->private_data;
  349. u32 ibox_data;
  350. ssize_t ret;
  351. if (len < 4)
  352. return -EINVAL;
  353. spu_acquire(ctx);
  354. ret = 0;
  355. if (file->f_flags & O_NONBLOCK) {
  356. if (!spu_ibox_read(ctx, &ibox_data))
  357. ret = -EAGAIN;
  358. } else {
  359. ret = spufs_wait(ctx->ibox_wq, spu_ibox_read(ctx, &ibox_data));
  360. }
  361. spu_release(ctx);
  362. if (ret)
  363. return ret;
  364. ret = 4;
  365. if (copy_to_user(buf, &ibox_data, sizeof ibox_data))
  366. ret = -EFAULT;
  367. return ret;
  368. }
  369. static unsigned int spufs_ibox_poll(struct file *file, poll_table *wait)
  370. {
  371. struct spu_context *ctx = file->private_data;
  372. unsigned int mask;
  373. poll_wait(file, &ctx->ibox_wq, wait);
  374. spu_acquire(ctx);
  375. mask = ctx->ops->mbox_stat_poll(ctx, POLLIN | POLLRDNORM);
  376. spu_release(ctx);
  377. return mask;
  378. }
  379. static struct file_operations spufs_ibox_fops = {
  380. .open = spufs_pipe_open,
  381. .read = spufs_ibox_read,
  382. .poll = spufs_ibox_poll,
  383. .fasync = spufs_ibox_fasync,
  384. };
  385. static ssize_t spufs_ibox_stat_read(struct file *file, char __user *buf,
  386. size_t len, loff_t *pos)
  387. {
  388. struct spu_context *ctx = file->private_data;
  389. u32 ibox_stat;
  390. if (len < 4)
  391. return -EINVAL;
  392. spu_acquire(ctx);
  393. ibox_stat = (ctx->ops->mbox_stat_read(ctx) >> 16) & 0xff;
  394. spu_release(ctx);
  395. if (copy_to_user(buf, &ibox_stat, sizeof ibox_stat))
  396. return -EFAULT;
  397. return 4;
  398. }
  399. static struct file_operations spufs_ibox_stat_fops = {
  400. .open = spufs_pipe_open,
  401. .read = spufs_ibox_stat_read,
  402. };
  403. /* low-level mailbox write */
  404. size_t spu_wbox_write(struct spu_context *ctx, u32 data)
  405. {
  406. return ctx->ops->wbox_write(ctx, data);
  407. }
  408. static int spufs_wbox_fasync(int fd, struct file *file, int on)
  409. {
  410. struct spu_context *ctx = file->private_data;
  411. int ret;
  412. ret = fasync_helper(fd, file, on, &ctx->wbox_fasync);
  413. return ret;
  414. }
  415. /* interrupt-level wbox callback function. */
  416. void spufs_wbox_callback(struct spu *spu)
  417. {
  418. struct spu_context *ctx = spu->ctx;
  419. wake_up_all(&ctx->wbox_wq);
  420. kill_fasync(&ctx->wbox_fasync, SIGIO, POLLOUT);
  421. }
  422. static ssize_t spufs_wbox_write(struct file *file, const char __user *buf,
  423. size_t len, loff_t *pos)
  424. {
  425. struct spu_context *ctx = file->private_data;
  426. u32 wbox_data;
  427. int ret;
  428. if (len < 4)
  429. return -EINVAL;
  430. if (copy_from_user(&wbox_data, buf, sizeof wbox_data))
  431. return -EFAULT;
  432. spu_acquire(ctx);
  433. ret = 0;
  434. if (file->f_flags & O_NONBLOCK) {
  435. if (!spu_wbox_write(ctx, wbox_data))
  436. ret = -EAGAIN;
  437. } else {
  438. ret = spufs_wait(ctx->wbox_wq, spu_wbox_write(ctx, wbox_data));
  439. }
  440. spu_release(ctx);
  441. return ret ? ret : sizeof wbox_data;
  442. }
  443. static unsigned int spufs_wbox_poll(struct file *file, poll_table *wait)
  444. {
  445. struct spu_context *ctx = file->private_data;
  446. unsigned int mask;
  447. poll_wait(file, &ctx->wbox_wq, wait);
  448. spu_acquire(ctx);
  449. mask = ctx->ops->mbox_stat_poll(ctx, POLLOUT | POLLWRNORM);
  450. spu_release(ctx);
  451. return mask;
  452. }
  453. static struct file_operations spufs_wbox_fops = {
  454. .open = spufs_pipe_open,
  455. .write = spufs_wbox_write,
  456. .poll = spufs_wbox_poll,
  457. .fasync = spufs_wbox_fasync,
  458. };
  459. static ssize_t spufs_wbox_stat_read(struct file *file, char __user *buf,
  460. size_t len, loff_t *pos)
  461. {
  462. struct spu_context *ctx = file->private_data;
  463. u32 wbox_stat;
  464. if (len < 4)
  465. return -EINVAL;
  466. spu_acquire(ctx);
  467. wbox_stat = (ctx->ops->mbox_stat_read(ctx) >> 8) & 0xff;
  468. spu_release(ctx);
  469. if (copy_to_user(buf, &wbox_stat, sizeof wbox_stat))
  470. return -EFAULT;
  471. return 4;
  472. }
  473. static struct file_operations spufs_wbox_stat_fops = {
  474. .open = spufs_pipe_open,
  475. .read = spufs_wbox_stat_read,
  476. };
  477. static int spufs_signal1_open(struct inode *inode, struct file *file)
  478. {
  479. struct spufs_inode_info *i = SPUFS_I(inode);
  480. struct spu_context *ctx = i->i_ctx;
  481. file->private_data = ctx;
  482. file->f_mapping = inode->i_mapping;
  483. ctx->signal1 = inode->i_mapping;
  484. return nonseekable_open(inode, file);
  485. }
  486. static ssize_t spufs_signal1_read(struct file *file, char __user *buf,
  487. size_t len, loff_t *pos)
  488. {
  489. struct spu_context *ctx = file->private_data;
  490. u32 data;
  491. if (len < 4)
  492. return -EINVAL;
  493. spu_acquire(ctx);
  494. data = ctx->ops->signal1_read(ctx);
  495. spu_release(ctx);
  496. if (copy_to_user(buf, &data, 4))
  497. return -EFAULT;
  498. return 4;
  499. }
  500. static ssize_t spufs_signal1_write(struct file *file, const char __user *buf,
  501. size_t len, loff_t *pos)
  502. {
  503. struct spu_context *ctx;
  504. u32 data;
  505. ctx = file->private_data;
  506. if (len < 4)
  507. return -EINVAL;
  508. if (copy_from_user(&data, buf, 4))
  509. return -EFAULT;
  510. spu_acquire(ctx);
  511. ctx->ops->signal1_write(ctx, data);
  512. spu_release(ctx);
  513. return 4;
  514. }
  515. static struct page *spufs_signal1_mmap_nopage(struct vm_area_struct *vma,
  516. unsigned long address, int *type)
  517. {
  518. #if PAGE_SIZE == 0x1000
  519. return spufs_ps_nopage(vma, address, type, 0x14000, 0x1000);
  520. #elif PAGE_SIZE == 0x10000
  521. /* For 64k pages, both signal1 and signal2 can be used to mmap the whole
  522. * signal 1 and 2 area
  523. */
  524. return spufs_ps_nopage(vma, address, type, 0x10000, 0x10000);
  525. #else
  526. #error unsupported page size
  527. #endif
  528. }
  529. static struct vm_operations_struct spufs_signal1_mmap_vmops = {
  530. .nopage = spufs_signal1_mmap_nopage,
  531. };
  532. static int spufs_signal1_mmap(struct file *file, struct vm_area_struct *vma)
  533. {
  534. if (!(vma->vm_flags & VM_SHARED))
  535. return -EINVAL;
  536. vma->vm_flags |= VM_RESERVED;
  537. vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
  538. | _PAGE_NO_CACHE | _PAGE_GUARDED);
  539. vma->vm_ops = &spufs_signal1_mmap_vmops;
  540. return 0;
  541. }
  542. static struct file_operations spufs_signal1_fops = {
  543. .open = spufs_signal1_open,
  544. .read = spufs_signal1_read,
  545. .write = spufs_signal1_write,
  546. .mmap = spufs_signal1_mmap,
  547. };
  548. static int spufs_signal2_open(struct inode *inode, struct file *file)
  549. {
  550. struct spufs_inode_info *i = SPUFS_I(inode);
  551. struct spu_context *ctx = i->i_ctx;
  552. file->private_data = ctx;
  553. file->f_mapping = inode->i_mapping;
  554. ctx->signal2 = inode->i_mapping;
  555. return nonseekable_open(inode, file);
  556. }
  557. static ssize_t spufs_signal2_read(struct file *file, char __user *buf,
  558. size_t len, loff_t *pos)
  559. {
  560. struct spu_context *ctx;
  561. u32 data;
  562. ctx = file->private_data;
  563. if (len < 4)
  564. return -EINVAL;
  565. spu_acquire(ctx);
  566. data = ctx->ops->signal2_read(ctx);
  567. spu_release(ctx);
  568. if (copy_to_user(buf, &data, 4))
  569. return -EFAULT;
  570. return 4;
  571. }
  572. static ssize_t spufs_signal2_write(struct file *file, const char __user *buf,
  573. size_t len, loff_t *pos)
  574. {
  575. struct spu_context *ctx;
  576. u32 data;
  577. ctx = file->private_data;
  578. if (len < 4)
  579. return -EINVAL;
  580. if (copy_from_user(&data, buf, 4))
  581. return -EFAULT;
  582. spu_acquire(ctx);
  583. ctx->ops->signal2_write(ctx, data);
  584. spu_release(ctx);
  585. return 4;
  586. }
  587. #if SPUFS_MMAP_4K
  588. static struct page *spufs_signal2_mmap_nopage(struct vm_area_struct *vma,
  589. unsigned long address, int *type)
  590. {
  591. #if PAGE_SIZE == 0x1000
  592. return spufs_ps_nopage(vma, address, type, 0x1c000, 0x1000);
  593. #elif PAGE_SIZE == 0x10000
  594. /* For 64k pages, both signal1 and signal2 can be used to mmap the whole
  595. * signal 1 and 2 area
  596. */
  597. return spufs_ps_nopage(vma, address, type, 0x10000, 0x10000);
  598. #else
  599. #error unsupported page size
  600. #endif
  601. }
  602. static struct vm_operations_struct spufs_signal2_mmap_vmops = {
  603. .nopage = spufs_signal2_mmap_nopage,
  604. };
  605. static int spufs_signal2_mmap(struct file *file, struct vm_area_struct *vma)
  606. {
  607. if (!(vma->vm_flags & VM_SHARED))
  608. return -EINVAL;
  609. /* FIXME: */
  610. vma->vm_flags |= VM_RESERVED;
  611. vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
  612. | _PAGE_NO_CACHE | _PAGE_GUARDED);
  613. vma->vm_ops = &spufs_signal2_mmap_vmops;
  614. return 0;
  615. }
  616. #else /* SPUFS_MMAP_4K */
  617. #define spufs_signal2_mmap NULL
  618. #endif /* !SPUFS_MMAP_4K */
  619. static struct file_operations spufs_signal2_fops = {
  620. .open = spufs_signal2_open,
  621. .read = spufs_signal2_read,
  622. .write = spufs_signal2_write,
  623. .mmap = spufs_signal2_mmap,
  624. };
  625. static void spufs_signal1_type_set(void *data, u64 val)
  626. {
  627. struct spu_context *ctx = data;
  628. spu_acquire(ctx);
  629. ctx->ops->signal1_type_set(ctx, val);
  630. spu_release(ctx);
  631. }
  632. static u64 spufs_signal1_type_get(void *data)
  633. {
  634. struct spu_context *ctx = data;
  635. u64 ret;
  636. spu_acquire(ctx);
  637. ret = ctx->ops->signal1_type_get(ctx);
  638. spu_release(ctx);
  639. return ret;
  640. }
  641. DEFINE_SIMPLE_ATTRIBUTE(spufs_signal1_type, spufs_signal1_type_get,
  642. spufs_signal1_type_set, "%llu");
  643. static void spufs_signal2_type_set(void *data, u64 val)
  644. {
  645. struct spu_context *ctx = data;
  646. spu_acquire(ctx);
  647. ctx->ops->signal2_type_set(ctx, val);
  648. spu_release(ctx);
  649. }
  650. static u64 spufs_signal2_type_get(void *data)
  651. {
  652. struct spu_context *ctx = data;
  653. u64 ret;
  654. spu_acquire(ctx);
  655. ret = ctx->ops->signal2_type_get(ctx);
  656. spu_release(ctx);
  657. return ret;
  658. }
  659. DEFINE_SIMPLE_ATTRIBUTE(spufs_signal2_type, spufs_signal2_type_get,
  660. spufs_signal2_type_set, "%llu");
  661. #if SPUFS_MMAP_4K
  662. static struct page *spufs_mss_mmap_nopage(struct vm_area_struct *vma,
  663. unsigned long address, int *type)
  664. {
  665. return spufs_ps_nopage(vma, address, type, 0x0000, 0x1000);
  666. }
  667. static struct vm_operations_struct spufs_mss_mmap_vmops = {
  668. .nopage = spufs_mss_mmap_nopage,
  669. };
  670. /*
  671. * mmap support for problem state MFC DMA area [0x0000 - 0x0fff].
  672. */
  673. static int spufs_mss_mmap(struct file *file, struct vm_area_struct *vma)
  674. {
  675. if (!(vma->vm_flags & VM_SHARED))
  676. return -EINVAL;
  677. vma->vm_flags |= VM_RESERVED;
  678. vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
  679. | _PAGE_NO_CACHE | _PAGE_GUARDED);
  680. vma->vm_ops = &spufs_mss_mmap_vmops;
  681. return 0;
  682. }
  683. #else /* SPUFS_MMAP_4K */
  684. #define spufs_mss_mmap NULL
  685. #endif /* !SPUFS_MMAP_4K */
  686. static int spufs_mss_open(struct inode *inode, struct file *file)
  687. {
  688. struct spufs_inode_info *i = SPUFS_I(inode);
  689. file->private_data = i->i_ctx;
  690. return nonseekable_open(inode, file);
  691. }
  692. static struct file_operations spufs_mss_fops = {
  693. .open = spufs_mss_open,
  694. .mmap = spufs_mss_mmap,
  695. };
  696. static struct page *spufs_psmap_mmap_nopage(struct vm_area_struct *vma,
  697. unsigned long address, int *type)
  698. {
  699. return spufs_ps_nopage(vma, address, type, 0x0000, 0x20000);
  700. }
  701. static struct vm_operations_struct spufs_psmap_mmap_vmops = {
  702. .nopage = spufs_psmap_mmap_nopage,
  703. };
  704. /*
  705. * mmap support for full problem state area [0x00000 - 0x1ffff].
  706. */
  707. static int spufs_psmap_mmap(struct file *file, struct vm_area_struct *vma)
  708. {
  709. if (!(vma->vm_flags & VM_SHARED))
  710. return -EINVAL;
  711. vma->vm_flags |= VM_RESERVED;
  712. vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
  713. | _PAGE_NO_CACHE | _PAGE_GUARDED);
  714. vma->vm_ops = &spufs_psmap_mmap_vmops;
  715. return 0;
  716. }
  717. static int spufs_psmap_open(struct inode *inode, struct file *file)
  718. {
  719. struct spufs_inode_info *i = SPUFS_I(inode);
  720. file->private_data = i->i_ctx;
  721. return nonseekable_open(inode, file);
  722. }
  723. static struct file_operations spufs_psmap_fops = {
  724. .open = spufs_psmap_open,
  725. .mmap = spufs_psmap_mmap,
  726. };
  727. #if SPUFS_MMAP_4K
  728. static struct page *spufs_mfc_mmap_nopage(struct vm_area_struct *vma,
  729. unsigned long address, int *type)
  730. {
  731. return spufs_ps_nopage(vma, address, type, 0x3000, 0x1000);
  732. }
  733. static struct vm_operations_struct spufs_mfc_mmap_vmops = {
  734. .nopage = spufs_mfc_mmap_nopage,
  735. };
  736. /*
  737. * mmap support for problem state MFC DMA area [0x0000 - 0x0fff].
  738. */
  739. static int spufs_mfc_mmap(struct file *file, struct vm_area_struct *vma)
  740. {
  741. if (!(vma->vm_flags & VM_SHARED))
  742. return -EINVAL;
  743. vma->vm_flags |= VM_RESERVED;
  744. vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
  745. | _PAGE_NO_CACHE | _PAGE_GUARDED);
  746. vma->vm_ops = &spufs_mfc_mmap_vmops;
  747. return 0;
  748. }
  749. #else /* SPUFS_MMAP_4K */
  750. #define spufs_mfc_mmap NULL
  751. #endif /* !SPUFS_MMAP_4K */
  752. static int spufs_mfc_open(struct inode *inode, struct file *file)
  753. {
  754. struct spufs_inode_info *i = SPUFS_I(inode);
  755. struct spu_context *ctx = i->i_ctx;
  756. /* we don't want to deal with DMA into other processes */
  757. if (ctx->owner != current->mm)
  758. return -EINVAL;
  759. if (atomic_read(&inode->i_count) != 1)
  760. return -EBUSY;
  761. file->private_data = ctx;
  762. return nonseekable_open(inode, file);
  763. }
  764. /* interrupt-level mfc callback function. */
  765. void spufs_mfc_callback(struct spu *spu)
  766. {
  767. struct spu_context *ctx = spu->ctx;
  768. wake_up_all(&ctx->mfc_wq);
  769. pr_debug("%s %s\n", __FUNCTION__, spu->name);
  770. if (ctx->mfc_fasync) {
  771. u32 free_elements, tagstatus;
  772. unsigned int mask;
  773. /* no need for spu_acquire in interrupt context */
  774. free_elements = ctx->ops->get_mfc_free_elements(ctx);
  775. tagstatus = ctx->ops->read_mfc_tagstatus(ctx);
  776. mask = 0;
  777. if (free_elements & 0xffff)
  778. mask |= POLLOUT;
  779. if (tagstatus & ctx->tagwait)
  780. mask |= POLLIN;
  781. kill_fasync(&ctx->mfc_fasync, SIGIO, mask);
  782. }
  783. }
  784. static int spufs_read_mfc_tagstatus(struct spu_context *ctx, u32 *status)
  785. {
  786. /* See if there is one tag group is complete */
  787. /* FIXME we need locking around tagwait */
  788. *status = ctx->ops->read_mfc_tagstatus(ctx) & ctx->tagwait;
  789. ctx->tagwait &= ~*status;
  790. if (*status)
  791. return 1;
  792. /* enable interrupt waiting for any tag group,
  793. may silently fail if interrupts are already enabled */
  794. ctx->ops->set_mfc_query(ctx, ctx->tagwait, 1);
  795. return 0;
  796. }
  797. static ssize_t spufs_mfc_read(struct file *file, char __user *buffer,
  798. size_t size, loff_t *pos)
  799. {
  800. struct spu_context *ctx = file->private_data;
  801. int ret = -EINVAL;
  802. u32 status;
  803. if (size != 4)
  804. goto out;
  805. spu_acquire(ctx);
  806. if (file->f_flags & O_NONBLOCK) {
  807. status = ctx->ops->read_mfc_tagstatus(ctx);
  808. if (!(status & ctx->tagwait))
  809. ret = -EAGAIN;
  810. else
  811. ctx->tagwait &= ~status;
  812. } else {
  813. ret = spufs_wait(ctx->mfc_wq,
  814. spufs_read_mfc_tagstatus(ctx, &status));
  815. }
  816. spu_release(ctx);
  817. if (ret)
  818. goto out;
  819. ret = 4;
  820. if (copy_to_user(buffer, &status, 4))
  821. ret = -EFAULT;
  822. out:
  823. return ret;
  824. }
  825. static int spufs_check_valid_dma(struct mfc_dma_command *cmd)
  826. {
  827. pr_debug("queueing DMA %x %lx %x %x %x\n", cmd->lsa,
  828. cmd->ea, cmd->size, cmd->tag, cmd->cmd);
  829. switch (cmd->cmd) {
  830. case MFC_PUT_CMD:
  831. case MFC_PUTF_CMD:
  832. case MFC_PUTB_CMD:
  833. case MFC_GET_CMD:
  834. case MFC_GETF_CMD:
  835. case MFC_GETB_CMD:
  836. break;
  837. default:
  838. pr_debug("invalid DMA opcode %x\n", cmd->cmd);
  839. return -EIO;
  840. }
  841. if ((cmd->lsa & 0xf) != (cmd->ea &0xf)) {
  842. pr_debug("invalid DMA alignment, ea %lx lsa %x\n",
  843. cmd->ea, cmd->lsa);
  844. return -EIO;
  845. }
  846. switch (cmd->size & 0xf) {
  847. case 1:
  848. break;
  849. case 2:
  850. if (cmd->lsa & 1)
  851. goto error;
  852. break;
  853. case 4:
  854. if (cmd->lsa & 3)
  855. goto error;
  856. break;
  857. case 8:
  858. if (cmd->lsa & 7)
  859. goto error;
  860. break;
  861. case 0:
  862. if (cmd->lsa & 15)
  863. goto error;
  864. break;
  865. error:
  866. default:
  867. pr_debug("invalid DMA alignment %x for size %x\n",
  868. cmd->lsa & 0xf, cmd->size);
  869. return -EIO;
  870. }
  871. if (cmd->size > 16 * 1024) {
  872. pr_debug("invalid DMA size %x\n", cmd->size);
  873. return -EIO;
  874. }
  875. if (cmd->tag & 0xfff0) {
  876. /* we reserve the higher tag numbers for kernel use */
  877. pr_debug("invalid DMA tag\n");
  878. return -EIO;
  879. }
  880. if (cmd->class) {
  881. /* not supported in this version */
  882. pr_debug("invalid DMA class\n");
  883. return -EIO;
  884. }
  885. return 0;
  886. }
  887. static int spu_send_mfc_command(struct spu_context *ctx,
  888. struct mfc_dma_command cmd,
  889. int *error)
  890. {
  891. *error = ctx->ops->send_mfc_command(ctx, &cmd);
  892. if (*error == -EAGAIN) {
  893. /* wait for any tag group to complete
  894. so we have space for the new command */
  895. ctx->ops->set_mfc_query(ctx, ctx->tagwait, 1);
  896. /* try again, because the queue might be
  897. empty again */
  898. *error = ctx->ops->send_mfc_command(ctx, &cmd);
  899. if (*error == -EAGAIN)
  900. return 0;
  901. }
  902. return 1;
  903. }
  904. static ssize_t spufs_mfc_write(struct file *file, const char __user *buffer,
  905. size_t size, loff_t *pos)
  906. {
  907. struct spu_context *ctx = file->private_data;
  908. struct mfc_dma_command cmd;
  909. int ret = -EINVAL;
  910. if (size != sizeof cmd)
  911. goto out;
  912. ret = -EFAULT;
  913. if (copy_from_user(&cmd, buffer, sizeof cmd))
  914. goto out;
  915. ret = spufs_check_valid_dma(&cmd);
  916. if (ret)
  917. goto out;
  918. spu_acquire_runnable(ctx);
  919. if (file->f_flags & O_NONBLOCK) {
  920. ret = ctx->ops->send_mfc_command(ctx, &cmd);
  921. } else {
  922. int status;
  923. ret = spufs_wait(ctx->mfc_wq,
  924. spu_send_mfc_command(ctx, cmd, &status));
  925. if (status)
  926. ret = status;
  927. }
  928. spu_release(ctx);
  929. if (ret)
  930. goto out;
  931. ctx->tagwait |= 1 << cmd.tag;
  932. out:
  933. return ret;
  934. }
  935. static unsigned int spufs_mfc_poll(struct file *file,poll_table *wait)
  936. {
  937. struct spu_context *ctx = file->private_data;
  938. u32 free_elements, tagstatus;
  939. unsigned int mask;
  940. spu_acquire(ctx);
  941. ctx->ops->set_mfc_query(ctx, ctx->tagwait, 2);
  942. free_elements = ctx->ops->get_mfc_free_elements(ctx);
  943. tagstatus = ctx->ops->read_mfc_tagstatus(ctx);
  944. spu_release(ctx);
  945. poll_wait(file, &ctx->mfc_wq, wait);
  946. mask = 0;
  947. if (free_elements & 0xffff)
  948. mask |= POLLOUT | POLLWRNORM;
  949. if (tagstatus & ctx->tagwait)
  950. mask |= POLLIN | POLLRDNORM;
  951. pr_debug("%s: free %d tagstatus %d tagwait %d\n", __FUNCTION__,
  952. free_elements, tagstatus, ctx->tagwait);
  953. return mask;
  954. }
  955. static int spufs_mfc_flush(struct file *file, fl_owner_t id)
  956. {
  957. struct spu_context *ctx = file->private_data;
  958. int ret;
  959. spu_acquire(ctx);
  960. #if 0
  961. /* this currently hangs */
  962. ret = spufs_wait(ctx->mfc_wq,
  963. ctx->ops->set_mfc_query(ctx, ctx->tagwait, 2));
  964. if (ret)
  965. goto out;
  966. ret = spufs_wait(ctx->mfc_wq,
  967. ctx->ops->read_mfc_tagstatus(ctx) == ctx->tagwait);
  968. out:
  969. #else
  970. ret = 0;
  971. #endif
  972. spu_release(ctx);
  973. return ret;
  974. }
  975. static int spufs_mfc_fsync(struct file *file, struct dentry *dentry,
  976. int datasync)
  977. {
  978. return spufs_mfc_flush(file, NULL);
  979. }
  980. static int spufs_mfc_fasync(int fd, struct file *file, int on)
  981. {
  982. struct spu_context *ctx = file->private_data;
  983. return fasync_helper(fd, file, on, &ctx->mfc_fasync);
  984. }
  985. static struct file_operations spufs_mfc_fops = {
  986. .open = spufs_mfc_open,
  987. .read = spufs_mfc_read,
  988. .write = spufs_mfc_write,
  989. .poll = spufs_mfc_poll,
  990. .flush = spufs_mfc_flush,
  991. .fsync = spufs_mfc_fsync,
  992. .fasync = spufs_mfc_fasync,
  993. .mmap = spufs_mfc_mmap,
  994. };
  995. static void spufs_npc_set(void *data, u64 val)
  996. {
  997. struct spu_context *ctx = data;
  998. spu_acquire(ctx);
  999. ctx->ops->npc_write(ctx, val);
  1000. spu_release(ctx);
  1001. }
  1002. static u64 spufs_npc_get(void *data)
  1003. {
  1004. struct spu_context *ctx = data;
  1005. u64 ret;
  1006. spu_acquire(ctx);
  1007. ret = ctx->ops->npc_read(ctx);
  1008. spu_release(ctx);
  1009. return ret;
  1010. }
  1011. DEFINE_SIMPLE_ATTRIBUTE(spufs_npc_ops, spufs_npc_get, spufs_npc_set, "%llx\n")
  1012. static void spufs_decr_set(void *data, u64 val)
  1013. {
  1014. struct spu_context *ctx = data;
  1015. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  1016. spu_acquire_saved(ctx);
  1017. lscsa->decr.slot[0] = (u32) val;
  1018. spu_release(ctx);
  1019. }
  1020. static u64 spufs_decr_get(void *data)
  1021. {
  1022. struct spu_context *ctx = data;
  1023. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  1024. u64 ret;
  1025. spu_acquire_saved(ctx);
  1026. ret = lscsa->decr.slot[0];
  1027. spu_release(ctx);
  1028. return ret;
  1029. }
  1030. DEFINE_SIMPLE_ATTRIBUTE(spufs_decr_ops, spufs_decr_get, spufs_decr_set,
  1031. "%llx\n")
  1032. static void spufs_decr_status_set(void *data, u64 val)
  1033. {
  1034. struct spu_context *ctx = data;
  1035. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  1036. spu_acquire_saved(ctx);
  1037. lscsa->decr_status.slot[0] = (u32) val;
  1038. spu_release(ctx);
  1039. }
  1040. static u64 spufs_decr_status_get(void *data)
  1041. {
  1042. struct spu_context *ctx = data;
  1043. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  1044. u64 ret;
  1045. spu_acquire_saved(ctx);
  1046. ret = lscsa->decr_status.slot[0];
  1047. spu_release(ctx);
  1048. return ret;
  1049. }
  1050. DEFINE_SIMPLE_ATTRIBUTE(spufs_decr_status_ops, spufs_decr_status_get,
  1051. spufs_decr_status_set, "%llx\n")
  1052. static void spufs_spu_tag_mask_set(void *data, u64 val)
  1053. {
  1054. struct spu_context *ctx = data;
  1055. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  1056. spu_acquire_saved(ctx);
  1057. lscsa->tag_mask.slot[0] = (u32) val;
  1058. spu_release(ctx);
  1059. }
  1060. static u64 spufs_spu_tag_mask_get(void *data)
  1061. {
  1062. struct spu_context *ctx = data;
  1063. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  1064. u64 ret;
  1065. spu_acquire_saved(ctx);
  1066. ret = lscsa->tag_mask.slot[0];
  1067. spu_release(ctx);
  1068. return ret;
  1069. }
  1070. DEFINE_SIMPLE_ATTRIBUTE(spufs_spu_tag_mask_ops, spufs_spu_tag_mask_get,
  1071. spufs_spu_tag_mask_set, "%llx\n")
  1072. static void spufs_event_mask_set(void *data, u64 val)
  1073. {
  1074. struct spu_context *ctx = data;
  1075. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  1076. spu_acquire_saved(ctx);
  1077. lscsa->event_mask.slot[0] = (u32) val;
  1078. spu_release(ctx);
  1079. }
  1080. static u64 spufs_event_mask_get(void *data)
  1081. {
  1082. struct spu_context *ctx = data;
  1083. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  1084. u64 ret;
  1085. spu_acquire_saved(ctx);
  1086. ret = lscsa->event_mask.slot[0];
  1087. spu_release(ctx);
  1088. return ret;
  1089. }
  1090. DEFINE_SIMPLE_ATTRIBUTE(spufs_event_mask_ops, spufs_event_mask_get,
  1091. spufs_event_mask_set, "%llx\n")
  1092. static void spufs_srr0_set(void *data, u64 val)
  1093. {
  1094. struct spu_context *ctx = data;
  1095. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  1096. spu_acquire_saved(ctx);
  1097. lscsa->srr0.slot[0] = (u32) val;
  1098. spu_release(ctx);
  1099. }
  1100. static u64 spufs_srr0_get(void *data)
  1101. {
  1102. struct spu_context *ctx = data;
  1103. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  1104. u64 ret;
  1105. spu_acquire_saved(ctx);
  1106. ret = lscsa->srr0.slot[0];
  1107. spu_release(ctx);
  1108. return ret;
  1109. }
  1110. DEFINE_SIMPLE_ATTRIBUTE(spufs_srr0_ops, spufs_srr0_get, spufs_srr0_set,
  1111. "%llx\n")
  1112. static u64 spufs_id_get(void *data)
  1113. {
  1114. struct spu_context *ctx = data;
  1115. u64 num;
  1116. spu_acquire(ctx);
  1117. if (ctx->state == SPU_STATE_RUNNABLE)
  1118. num = ctx->spu->number;
  1119. else
  1120. num = (unsigned int)-1;
  1121. spu_release(ctx);
  1122. return num;
  1123. }
  1124. DEFINE_SIMPLE_ATTRIBUTE(spufs_id_ops, spufs_id_get, NULL, "0x%llx\n")
  1125. struct tree_descr spufs_dir_contents[] = {
  1126. { "mem", &spufs_mem_fops, 0666, },
  1127. { "regs", &spufs_regs_fops, 0666, },
  1128. { "mbox", &spufs_mbox_fops, 0444, },
  1129. { "ibox", &spufs_ibox_fops, 0444, },
  1130. { "wbox", &spufs_wbox_fops, 0222, },
  1131. { "mbox_stat", &spufs_mbox_stat_fops, 0444, },
  1132. { "ibox_stat", &spufs_ibox_stat_fops, 0444, },
  1133. { "wbox_stat", &spufs_wbox_stat_fops, 0444, },
  1134. { "signal1", &spufs_signal1_fops, 0666, },
  1135. { "signal2", &spufs_signal2_fops, 0666, },
  1136. { "signal1_type", &spufs_signal1_type, 0666, },
  1137. { "signal2_type", &spufs_signal2_type, 0666, },
  1138. { "mss", &spufs_mss_fops, 0666, },
  1139. { "mfc", &spufs_mfc_fops, 0666, },
  1140. { "cntl", &spufs_cntl_fops, 0666, },
  1141. { "npc", &spufs_npc_ops, 0666, },
  1142. { "fpcr", &spufs_fpcr_fops, 0666, },
  1143. { "decr", &spufs_decr_ops, 0666, },
  1144. { "decr_status", &spufs_decr_status_ops, 0666, },
  1145. { "spu_tag_mask", &spufs_spu_tag_mask_ops, 0666, },
  1146. { "event_mask", &spufs_event_mask_ops, 0666, },
  1147. { "srr0", &spufs_srr0_ops, 0666, },
  1148. { "phys-id", &spufs_id_ops, 0666, },
  1149. { "psmap", &spufs_psmap_fops, 0666, },
  1150. {},
  1151. };