file.c 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041
  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/spu_info.h>
  33. #include <asm/uaccess.h>
  34. #include "spufs.h"
  35. #define SPUFS_MMAP_4K (PAGE_SIZE == 0x1000)
  36. static int
  37. spufs_mem_open(struct inode *inode, struct file *file)
  38. {
  39. struct spufs_inode_info *i = SPUFS_I(inode);
  40. struct spu_context *ctx = i->i_ctx;
  41. spin_lock(&ctx->mapping_lock);
  42. file->private_data = ctx;
  43. if (!i->i_openers++)
  44. ctx->local_store = inode->i_mapping;
  45. spin_unlock(&ctx->mapping_lock);
  46. return 0;
  47. }
  48. static int
  49. spufs_mem_release(struct inode *inode, struct file *file)
  50. {
  51. struct spufs_inode_info *i = SPUFS_I(inode);
  52. struct spu_context *ctx = i->i_ctx;
  53. spin_lock(&ctx->mapping_lock);
  54. if (!--i->i_openers)
  55. ctx->local_store = NULL;
  56. spin_unlock(&ctx->mapping_lock);
  57. return 0;
  58. }
  59. static ssize_t
  60. __spufs_mem_read(struct spu_context *ctx, char __user *buffer,
  61. size_t size, loff_t *pos)
  62. {
  63. char *local_store = ctx->ops->get_ls(ctx);
  64. return simple_read_from_buffer(buffer, size, pos, local_store,
  65. LS_SIZE);
  66. }
  67. static ssize_t
  68. spufs_mem_read(struct file *file, char __user *buffer,
  69. size_t size, loff_t *pos)
  70. {
  71. struct spu_context *ctx = file->private_data;
  72. ssize_t ret;
  73. spu_acquire(ctx);
  74. ret = __spufs_mem_read(ctx, buffer, size, pos);
  75. spu_release(ctx);
  76. return ret;
  77. }
  78. static ssize_t
  79. spufs_mem_write(struct file *file, const char __user *buffer,
  80. size_t size, loff_t *ppos)
  81. {
  82. struct spu_context *ctx = file->private_data;
  83. char *local_store;
  84. loff_t pos = *ppos;
  85. int ret;
  86. if (pos < 0)
  87. return -EINVAL;
  88. if (pos > LS_SIZE)
  89. return -EFBIG;
  90. if (size > LS_SIZE - pos)
  91. size = LS_SIZE - pos;
  92. spu_acquire(ctx);
  93. local_store = ctx->ops->get_ls(ctx);
  94. ret = copy_from_user(local_store + pos, buffer, size);
  95. spu_release(ctx);
  96. if (ret)
  97. return -EFAULT;
  98. *ppos = pos + size;
  99. return size;
  100. }
  101. static unsigned long spufs_mem_mmap_nopfn(struct vm_area_struct *vma,
  102. unsigned long address)
  103. {
  104. struct spu_context *ctx = vma->vm_file->private_data;
  105. unsigned long pfn, offset = address - vma->vm_start;
  106. offset += vma->vm_pgoff << PAGE_SHIFT;
  107. if (offset >= LS_SIZE)
  108. return NOPFN_SIGBUS;
  109. spu_acquire(ctx);
  110. if (ctx->state == SPU_STATE_SAVED) {
  111. vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
  112. & ~_PAGE_NO_CACHE);
  113. pfn = vmalloc_to_pfn(ctx->csa.lscsa->ls + offset);
  114. } else {
  115. vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
  116. | _PAGE_NO_CACHE);
  117. pfn = (ctx->spu->local_store_phys + offset) >> PAGE_SHIFT;
  118. }
  119. vm_insert_pfn(vma, address, pfn);
  120. spu_release(ctx);
  121. return NOPFN_REFAULT;
  122. }
  123. static struct vm_operations_struct spufs_mem_mmap_vmops = {
  124. .nopfn = spufs_mem_mmap_nopfn,
  125. };
  126. static int
  127. spufs_mem_mmap(struct file *file, struct vm_area_struct *vma)
  128. {
  129. if (!(vma->vm_flags & VM_SHARED))
  130. return -EINVAL;
  131. vma->vm_flags |= VM_IO | VM_PFNMAP;
  132. vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
  133. | _PAGE_NO_CACHE);
  134. vma->vm_ops = &spufs_mem_mmap_vmops;
  135. return 0;
  136. }
  137. static const struct file_operations spufs_mem_fops = {
  138. .open = spufs_mem_open,
  139. .release = spufs_mem_release,
  140. .read = spufs_mem_read,
  141. .write = spufs_mem_write,
  142. .llseek = generic_file_llseek,
  143. .mmap = spufs_mem_mmap,
  144. };
  145. static unsigned long spufs_ps_nopfn(struct vm_area_struct *vma,
  146. unsigned long address,
  147. unsigned long ps_offs,
  148. unsigned long ps_size)
  149. {
  150. struct spu_context *ctx = vma->vm_file->private_data;
  151. unsigned long area, offset = address - vma->vm_start;
  152. int ret;
  153. offset += vma->vm_pgoff << PAGE_SHIFT;
  154. if (offset >= ps_size)
  155. return NOPFN_SIGBUS;
  156. /* error here usually means a signal.. we might want to test
  157. * the error code more precisely though
  158. */
  159. ret = spu_acquire_runnable(ctx, 0);
  160. if (ret)
  161. return NOPFN_REFAULT;
  162. area = ctx->spu->problem_phys + ps_offs;
  163. vm_insert_pfn(vma, address, (area + offset) >> PAGE_SHIFT);
  164. spu_release(ctx);
  165. return NOPFN_REFAULT;
  166. }
  167. #if SPUFS_MMAP_4K
  168. static unsigned long spufs_cntl_mmap_nopfn(struct vm_area_struct *vma,
  169. unsigned long address)
  170. {
  171. return spufs_ps_nopfn(vma, address, 0x4000, 0x1000);
  172. }
  173. static struct vm_operations_struct spufs_cntl_mmap_vmops = {
  174. .nopfn = spufs_cntl_mmap_nopfn,
  175. };
  176. /*
  177. * mmap support for problem state control area [0x4000 - 0x4fff].
  178. */
  179. static int spufs_cntl_mmap(struct file *file, struct vm_area_struct *vma)
  180. {
  181. if (!(vma->vm_flags & VM_SHARED))
  182. return -EINVAL;
  183. vma->vm_flags |= VM_IO | VM_PFNMAP;
  184. vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
  185. | _PAGE_NO_CACHE | _PAGE_GUARDED);
  186. vma->vm_ops = &spufs_cntl_mmap_vmops;
  187. return 0;
  188. }
  189. #else /* SPUFS_MMAP_4K */
  190. #define spufs_cntl_mmap NULL
  191. #endif /* !SPUFS_MMAP_4K */
  192. static u64 spufs_cntl_get(void *data)
  193. {
  194. struct spu_context *ctx = data;
  195. u64 val;
  196. spu_acquire(ctx);
  197. val = ctx->ops->status_read(ctx);
  198. spu_release(ctx);
  199. return val;
  200. }
  201. static void spufs_cntl_set(void *data, u64 val)
  202. {
  203. struct spu_context *ctx = data;
  204. spu_acquire(ctx);
  205. ctx->ops->runcntl_write(ctx, val);
  206. spu_release(ctx);
  207. }
  208. static int spufs_cntl_open(struct inode *inode, struct file *file)
  209. {
  210. struct spufs_inode_info *i = SPUFS_I(inode);
  211. struct spu_context *ctx = i->i_ctx;
  212. spin_lock(&ctx->mapping_lock);
  213. file->private_data = ctx;
  214. if (!i->i_openers++)
  215. ctx->cntl = inode->i_mapping;
  216. spin_unlock(&ctx->mapping_lock);
  217. return simple_attr_open(inode, file, spufs_cntl_get,
  218. spufs_cntl_set, "0x%08lx");
  219. }
  220. static int
  221. spufs_cntl_release(struct inode *inode, struct file *file)
  222. {
  223. struct spufs_inode_info *i = SPUFS_I(inode);
  224. struct spu_context *ctx = i->i_ctx;
  225. simple_attr_close(inode, file);
  226. spin_lock(&ctx->mapping_lock);
  227. if (!--i->i_openers)
  228. ctx->cntl = NULL;
  229. spin_unlock(&ctx->mapping_lock);
  230. return 0;
  231. }
  232. static const struct file_operations spufs_cntl_fops = {
  233. .open = spufs_cntl_open,
  234. .release = spufs_cntl_release,
  235. .read = simple_attr_read,
  236. .write = simple_attr_write,
  237. .mmap = spufs_cntl_mmap,
  238. };
  239. static int
  240. spufs_regs_open(struct inode *inode, struct file *file)
  241. {
  242. struct spufs_inode_info *i = SPUFS_I(inode);
  243. file->private_data = i->i_ctx;
  244. return 0;
  245. }
  246. static ssize_t
  247. __spufs_regs_read(struct spu_context *ctx, char __user *buffer,
  248. size_t size, loff_t *pos)
  249. {
  250. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  251. return simple_read_from_buffer(buffer, size, pos,
  252. lscsa->gprs, sizeof lscsa->gprs);
  253. }
  254. static ssize_t
  255. spufs_regs_read(struct file *file, char __user *buffer,
  256. size_t size, loff_t *pos)
  257. {
  258. int ret;
  259. struct spu_context *ctx = file->private_data;
  260. spu_acquire_saved(ctx);
  261. ret = __spufs_regs_read(ctx, buffer, size, pos);
  262. spu_release(ctx);
  263. return ret;
  264. }
  265. static ssize_t
  266. spufs_regs_write(struct file *file, const char __user *buffer,
  267. size_t size, loff_t *pos)
  268. {
  269. struct spu_context *ctx = file->private_data;
  270. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  271. int ret;
  272. size = min_t(ssize_t, sizeof lscsa->gprs - *pos, size);
  273. if (size <= 0)
  274. return -EFBIG;
  275. *pos += size;
  276. spu_acquire_saved(ctx);
  277. ret = copy_from_user(lscsa->gprs + *pos - size,
  278. buffer, size) ? -EFAULT : size;
  279. spu_release(ctx);
  280. return ret;
  281. }
  282. static const struct file_operations spufs_regs_fops = {
  283. .open = spufs_regs_open,
  284. .read = spufs_regs_read,
  285. .write = spufs_regs_write,
  286. .llseek = generic_file_llseek,
  287. };
  288. static ssize_t
  289. __spufs_fpcr_read(struct spu_context *ctx, char __user * buffer,
  290. size_t size, loff_t * pos)
  291. {
  292. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  293. return simple_read_from_buffer(buffer, size, pos,
  294. &lscsa->fpcr, sizeof(lscsa->fpcr));
  295. }
  296. static ssize_t
  297. spufs_fpcr_read(struct file *file, char __user * buffer,
  298. size_t size, loff_t * pos)
  299. {
  300. int ret;
  301. struct spu_context *ctx = file->private_data;
  302. spu_acquire_saved(ctx);
  303. ret = __spufs_fpcr_read(ctx, buffer, size, pos);
  304. spu_release(ctx);
  305. return ret;
  306. }
  307. static ssize_t
  308. spufs_fpcr_write(struct file *file, const char __user * buffer,
  309. size_t size, loff_t * pos)
  310. {
  311. struct spu_context *ctx = file->private_data;
  312. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  313. int ret;
  314. size = min_t(ssize_t, sizeof(lscsa->fpcr) - *pos, size);
  315. if (size <= 0)
  316. return -EFBIG;
  317. *pos += size;
  318. spu_acquire_saved(ctx);
  319. ret = copy_from_user((char *)&lscsa->fpcr + *pos - size,
  320. buffer, size) ? -EFAULT : size;
  321. spu_release(ctx);
  322. return ret;
  323. }
  324. static const struct file_operations spufs_fpcr_fops = {
  325. .open = spufs_regs_open,
  326. .read = spufs_fpcr_read,
  327. .write = spufs_fpcr_write,
  328. .llseek = generic_file_llseek,
  329. };
  330. /* generic open function for all pipe-like files */
  331. static int spufs_pipe_open(struct inode *inode, struct file *file)
  332. {
  333. struct spufs_inode_info *i = SPUFS_I(inode);
  334. file->private_data = i->i_ctx;
  335. return nonseekable_open(inode, file);
  336. }
  337. /*
  338. * Read as many bytes from the mailbox as possible, until
  339. * one of the conditions becomes true:
  340. *
  341. * - no more data available in the mailbox
  342. * - end of the user provided buffer
  343. * - end of the mapped area
  344. */
  345. static ssize_t spufs_mbox_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 mbox_data, __user *udata;
  350. ssize_t count;
  351. if (len < 4)
  352. return -EINVAL;
  353. if (!access_ok(VERIFY_WRITE, buf, len))
  354. return -EFAULT;
  355. udata = (void __user *)buf;
  356. spu_acquire(ctx);
  357. for (count = 0; (count + 4) <= len; count += 4, udata++) {
  358. int ret;
  359. ret = ctx->ops->mbox_read(ctx, &mbox_data);
  360. if (ret == 0)
  361. break;
  362. /*
  363. * at the end of the mapped area, we can fault
  364. * but still need to return the data we have
  365. * read successfully so far.
  366. */
  367. ret = __put_user(mbox_data, udata);
  368. if (ret) {
  369. if (!count)
  370. count = -EFAULT;
  371. break;
  372. }
  373. }
  374. spu_release(ctx);
  375. if (!count)
  376. count = -EAGAIN;
  377. return count;
  378. }
  379. static const struct file_operations spufs_mbox_fops = {
  380. .open = spufs_pipe_open,
  381. .read = spufs_mbox_read,
  382. };
  383. static ssize_t spufs_mbox_stat_read(struct file *file, char __user *buf,
  384. size_t len, loff_t *pos)
  385. {
  386. struct spu_context *ctx = file->private_data;
  387. u32 mbox_stat;
  388. if (len < 4)
  389. return -EINVAL;
  390. spu_acquire(ctx);
  391. mbox_stat = ctx->ops->mbox_stat_read(ctx) & 0xff;
  392. spu_release(ctx);
  393. if (copy_to_user(buf, &mbox_stat, sizeof mbox_stat))
  394. return -EFAULT;
  395. return 4;
  396. }
  397. static const struct file_operations spufs_mbox_stat_fops = {
  398. .open = spufs_pipe_open,
  399. .read = spufs_mbox_stat_read,
  400. };
  401. /* low-level ibox access function */
  402. size_t spu_ibox_read(struct spu_context *ctx, u32 *data)
  403. {
  404. return ctx->ops->ibox_read(ctx, data);
  405. }
  406. static int spufs_ibox_fasync(int fd, struct file *file, int on)
  407. {
  408. struct spu_context *ctx = file->private_data;
  409. return fasync_helper(fd, file, on, &ctx->ibox_fasync);
  410. }
  411. /* interrupt-level ibox callback function. */
  412. void spufs_ibox_callback(struct spu *spu)
  413. {
  414. struct spu_context *ctx = spu->ctx;
  415. wake_up_all(&ctx->ibox_wq);
  416. kill_fasync(&ctx->ibox_fasync, SIGIO, POLLIN);
  417. }
  418. /*
  419. * Read as many bytes from the interrupt mailbox as possible, until
  420. * one of the conditions becomes true:
  421. *
  422. * - no more data available in the mailbox
  423. * - end of the user provided buffer
  424. * - end of the mapped area
  425. *
  426. * If the file is opened without O_NONBLOCK, we wait here until
  427. * any data is available, but return when we have been able to
  428. * read something.
  429. */
  430. static ssize_t spufs_ibox_read(struct file *file, char __user *buf,
  431. size_t len, loff_t *pos)
  432. {
  433. struct spu_context *ctx = file->private_data;
  434. u32 ibox_data, __user *udata;
  435. ssize_t count;
  436. if (len < 4)
  437. return -EINVAL;
  438. if (!access_ok(VERIFY_WRITE, buf, len))
  439. return -EFAULT;
  440. udata = (void __user *)buf;
  441. spu_acquire(ctx);
  442. /* wait only for the first element */
  443. count = 0;
  444. if (file->f_flags & O_NONBLOCK) {
  445. if (!spu_ibox_read(ctx, &ibox_data))
  446. count = -EAGAIN;
  447. } else {
  448. count = spufs_wait(ctx->ibox_wq, spu_ibox_read(ctx, &ibox_data));
  449. }
  450. if (count)
  451. goto out;
  452. /* if we can't write at all, return -EFAULT */
  453. count = __put_user(ibox_data, udata);
  454. if (count)
  455. goto out;
  456. for (count = 4, udata++; (count + 4) <= len; count += 4, udata++) {
  457. int ret;
  458. ret = ctx->ops->ibox_read(ctx, &ibox_data);
  459. if (ret == 0)
  460. break;
  461. /*
  462. * at the end of the mapped area, we can fault
  463. * but still need to return the data we have
  464. * read successfully so far.
  465. */
  466. ret = __put_user(ibox_data, udata);
  467. if (ret)
  468. break;
  469. }
  470. out:
  471. spu_release(ctx);
  472. return count;
  473. }
  474. static unsigned int spufs_ibox_poll(struct file *file, poll_table *wait)
  475. {
  476. struct spu_context *ctx = file->private_data;
  477. unsigned int mask;
  478. poll_wait(file, &ctx->ibox_wq, wait);
  479. spu_acquire(ctx);
  480. mask = ctx->ops->mbox_stat_poll(ctx, POLLIN | POLLRDNORM);
  481. spu_release(ctx);
  482. return mask;
  483. }
  484. static const struct file_operations spufs_ibox_fops = {
  485. .open = spufs_pipe_open,
  486. .read = spufs_ibox_read,
  487. .poll = spufs_ibox_poll,
  488. .fasync = spufs_ibox_fasync,
  489. };
  490. static ssize_t spufs_ibox_stat_read(struct file *file, char __user *buf,
  491. size_t len, loff_t *pos)
  492. {
  493. struct spu_context *ctx = file->private_data;
  494. u32 ibox_stat;
  495. if (len < 4)
  496. return -EINVAL;
  497. spu_acquire(ctx);
  498. ibox_stat = (ctx->ops->mbox_stat_read(ctx) >> 16) & 0xff;
  499. spu_release(ctx);
  500. if (copy_to_user(buf, &ibox_stat, sizeof ibox_stat))
  501. return -EFAULT;
  502. return 4;
  503. }
  504. static const struct file_operations spufs_ibox_stat_fops = {
  505. .open = spufs_pipe_open,
  506. .read = spufs_ibox_stat_read,
  507. };
  508. /* low-level mailbox write */
  509. size_t spu_wbox_write(struct spu_context *ctx, u32 data)
  510. {
  511. return ctx->ops->wbox_write(ctx, data);
  512. }
  513. static int spufs_wbox_fasync(int fd, struct file *file, int on)
  514. {
  515. struct spu_context *ctx = file->private_data;
  516. int ret;
  517. ret = fasync_helper(fd, file, on, &ctx->wbox_fasync);
  518. return ret;
  519. }
  520. /* interrupt-level wbox callback function. */
  521. void spufs_wbox_callback(struct spu *spu)
  522. {
  523. struct spu_context *ctx = spu->ctx;
  524. wake_up_all(&ctx->wbox_wq);
  525. kill_fasync(&ctx->wbox_fasync, SIGIO, POLLOUT);
  526. }
  527. /*
  528. * Write as many bytes to the interrupt mailbox as possible, until
  529. * one of the conditions becomes true:
  530. *
  531. * - the mailbox is full
  532. * - end of the user provided buffer
  533. * - end of the mapped area
  534. *
  535. * If the file is opened without O_NONBLOCK, we wait here until
  536. * space is availabyl, but return when we have been able to
  537. * write something.
  538. */
  539. static ssize_t spufs_wbox_write(struct file *file, const char __user *buf,
  540. size_t len, loff_t *pos)
  541. {
  542. struct spu_context *ctx = file->private_data;
  543. u32 wbox_data, __user *udata;
  544. ssize_t count;
  545. if (len < 4)
  546. return -EINVAL;
  547. udata = (void __user *)buf;
  548. if (!access_ok(VERIFY_READ, buf, len))
  549. return -EFAULT;
  550. if (__get_user(wbox_data, udata))
  551. return -EFAULT;
  552. spu_acquire(ctx);
  553. /*
  554. * make sure we can at least write one element, by waiting
  555. * in case of !O_NONBLOCK
  556. */
  557. count = 0;
  558. if (file->f_flags & O_NONBLOCK) {
  559. if (!spu_wbox_write(ctx, wbox_data))
  560. count = -EAGAIN;
  561. } else {
  562. count = spufs_wait(ctx->wbox_wq, spu_wbox_write(ctx, wbox_data));
  563. }
  564. if (count)
  565. goto out;
  566. /* write aѕ much as possible */
  567. for (count = 4, udata++; (count + 4) <= len; count += 4, udata++) {
  568. int ret;
  569. ret = __get_user(wbox_data, udata);
  570. if (ret)
  571. break;
  572. ret = spu_wbox_write(ctx, wbox_data);
  573. if (ret == 0)
  574. break;
  575. }
  576. out:
  577. spu_release(ctx);
  578. return count;
  579. }
  580. static unsigned int spufs_wbox_poll(struct file *file, poll_table *wait)
  581. {
  582. struct spu_context *ctx = file->private_data;
  583. unsigned int mask;
  584. poll_wait(file, &ctx->wbox_wq, wait);
  585. spu_acquire(ctx);
  586. mask = ctx->ops->mbox_stat_poll(ctx, POLLOUT | POLLWRNORM);
  587. spu_release(ctx);
  588. return mask;
  589. }
  590. static const struct file_operations spufs_wbox_fops = {
  591. .open = spufs_pipe_open,
  592. .write = spufs_wbox_write,
  593. .poll = spufs_wbox_poll,
  594. .fasync = spufs_wbox_fasync,
  595. };
  596. static ssize_t spufs_wbox_stat_read(struct file *file, char __user *buf,
  597. size_t len, loff_t *pos)
  598. {
  599. struct spu_context *ctx = file->private_data;
  600. u32 wbox_stat;
  601. if (len < 4)
  602. return -EINVAL;
  603. spu_acquire(ctx);
  604. wbox_stat = (ctx->ops->mbox_stat_read(ctx) >> 8) & 0xff;
  605. spu_release(ctx);
  606. if (copy_to_user(buf, &wbox_stat, sizeof wbox_stat))
  607. return -EFAULT;
  608. return 4;
  609. }
  610. static const struct file_operations spufs_wbox_stat_fops = {
  611. .open = spufs_pipe_open,
  612. .read = spufs_wbox_stat_read,
  613. };
  614. static int spufs_signal1_open(struct inode *inode, struct file *file)
  615. {
  616. struct spufs_inode_info *i = SPUFS_I(inode);
  617. struct spu_context *ctx = i->i_ctx;
  618. spin_lock(&ctx->mapping_lock);
  619. file->private_data = ctx;
  620. if (!i->i_openers++)
  621. ctx->signal1 = inode->i_mapping;
  622. spin_unlock(&ctx->mapping_lock);
  623. return nonseekable_open(inode, file);
  624. }
  625. static int
  626. spufs_signal1_release(struct inode *inode, struct file *file)
  627. {
  628. struct spufs_inode_info *i = SPUFS_I(inode);
  629. struct spu_context *ctx = i->i_ctx;
  630. spin_lock(&ctx->mapping_lock);
  631. if (!--i->i_openers)
  632. ctx->signal1 = NULL;
  633. spin_unlock(&ctx->mapping_lock);
  634. return 0;
  635. }
  636. static ssize_t __spufs_signal1_read(struct spu_context *ctx, char __user *buf,
  637. size_t len, loff_t *pos)
  638. {
  639. int ret = 0;
  640. u32 data;
  641. if (len < 4)
  642. return -EINVAL;
  643. if (ctx->csa.spu_chnlcnt_RW[3]) {
  644. data = ctx->csa.spu_chnldata_RW[3];
  645. ret = 4;
  646. }
  647. if (!ret)
  648. goto out;
  649. if (copy_to_user(buf, &data, 4))
  650. return -EFAULT;
  651. out:
  652. return ret;
  653. }
  654. static ssize_t spufs_signal1_read(struct file *file, char __user *buf,
  655. size_t len, loff_t *pos)
  656. {
  657. int ret;
  658. struct spu_context *ctx = file->private_data;
  659. spu_acquire_saved(ctx);
  660. ret = __spufs_signal1_read(ctx, buf, len, pos);
  661. spu_release(ctx);
  662. return ret;
  663. }
  664. static ssize_t spufs_signal1_write(struct file *file, const char __user *buf,
  665. size_t len, loff_t *pos)
  666. {
  667. struct spu_context *ctx;
  668. u32 data;
  669. ctx = file->private_data;
  670. if (len < 4)
  671. return -EINVAL;
  672. if (copy_from_user(&data, buf, 4))
  673. return -EFAULT;
  674. spu_acquire(ctx);
  675. ctx->ops->signal1_write(ctx, data);
  676. spu_release(ctx);
  677. return 4;
  678. }
  679. static unsigned long spufs_signal1_mmap_nopfn(struct vm_area_struct *vma,
  680. unsigned long address)
  681. {
  682. #if PAGE_SIZE == 0x1000
  683. return spufs_ps_nopfn(vma, address, 0x14000, 0x1000);
  684. #elif PAGE_SIZE == 0x10000
  685. /* For 64k pages, both signal1 and signal2 can be used to mmap the whole
  686. * signal 1 and 2 area
  687. */
  688. return spufs_ps_nopfn(vma, address, 0x10000, 0x10000);
  689. #else
  690. #error unsupported page size
  691. #endif
  692. }
  693. static struct vm_operations_struct spufs_signal1_mmap_vmops = {
  694. .nopfn = spufs_signal1_mmap_nopfn,
  695. };
  696. static int spufs_signal1_mmap(struct file *file, struct vm_area_struct *vma)
  697. {
  698. if (!(vma->vm_flags & VM_SHARED))
  699. return -EINVAL;
  700. vma->vm_flags |= VM_IO | VM_PFNMAP;
  701. vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
  702. | _PAGE_NO_CACHE | _PAGE_GUARDED);
  703. vma->vm_ops = &spufs_signal1_mmap_vmops;
  704. return 0;
  705. }
  706. static const struct file_operations spufs_signal1_fops = {
  707. .open = spufs_signal1_open,
  708. .release = spufs_signal1_release,
  709. .read = spufs_signal1_read,
  710. .write = spufs_signal1_write,
  711. .mmap = spufs_signal1_mmap,
  712. };
  713. static int spufs_signal2_open(struct inode *inode, struct file *file)
  714. {
  715. struct spufs_inode_info *i = SPUFS_I(inode);
  716. struct spu_context *ctx = i->i_ctx;
  717. spin_lock(&ctx->mapping_lock);
  718. file->private_data = ctx;
  719. if (!i->i_openers++)
  720. ctx->signal2 = inode->i_mapping;
  721. spin_unlock(&ctx->mapping_lock);
  722. return nonseekable_open(inode, file);
  723. }
  724. static int
  725. spufs_signal2_release(struct inode *inode, struct file *file)
  726. {
  727. struct spufs_inode_info *i = SPUFS_I(inode);
  728. struct spu_context *ctx = i->i_ctx;
  729. spin_lock(&ctx->mapping_lock);
  730. if (!--i->i_openers)
  731. ctx->signal2 = NULL;
  732. spin_unlock(&ctx->mapping_lock);
  733. return 0;
  734. }
  735. static ssize_t __spufs_signal2_read(struct spu_context *ctx, char __user *buf,
  736. size_t len, loff_t *pos)
  737. {
  738. int ret = 0;
  739. u32 data;
  740. if (len < 4)
  741. return -EINVAL;
  742. if (ctx->csa.spu_chnlcnt_RW[4]) {
  743. data = ctx->csa.spu_chnldata_RW[4];
  744. ret = 4;
  745. }
  746. if (!ret)
  747. goto out;
  748. if (copy_to_user(buf, &data, 4))
  749. return -EFAULT;
  750. out:
  751. return ret;
  752. }
  753. static ssize_t spufs_signal2_read(struct file *file, char __user *buf,
  754. size_t len, loff_t *pos)
  755. {
  756. struct spu_context *ctx = file->private_data;
  757. int ret;
  758. spu_acquire_saved(ctx);
  759. ret = __spufs_signal2_read(ctx, buf, len, pos);
  760. spu_release(ctx);
  761. return ret;
  762. }
  763. static ssize_t spufs_signal2_write(struct file *file, const char __user *buf,
  764. size_t len, loff_t *pos)
  765. {
  766. struct spu_context *ctx;
  767. u32 data;
  768. ctx = file->private_data;
  769. if (len < 4)
  770. return -EINVAL;
  771. if (copy_from_user(&data, buf, 4))
  772. return -EFAULT;
  773. spu_acquire(ctx);
  774. ctx->ops->signal2_write(ctx, data);
  775. spu_release(ctx);
  776. return 4;
  777. }
  778. #if SPUFS_MMAP_4K
  779. static unsigned long spufs_signal2_mmap_nopfn(struct vm_area_struct *vma,
  780. unsigned long address)
  781. {
  782. #if PAGE_SIZE == 0x1000
  783. return spufs_ps_nopfn(vma, address, 0x1c000, 0x1000);
  784. #elif PAGE_SIZE == 0x10000
  785. /* For 64k pages, both signal1 and signal2 can be used to mmap the whole
  786. * signal 1 and 2 area
  787. */
  788. return spufs_ps_nopfn(vma, address, 0x10000, 0x10000);
  789. #else
  790. #error unsupported page size
  791. #endif
  792. }
  793. static struct vm_operations_struct spufs_signal2_mmap_vmops = {
  794. .nopfn = spufs_signal2_mmap_nopfn,
  795. };
  796. static int spufs_signal2_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_IO | VM_PFNMAP;
  801. vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
  802. | _PAGE_NO_CACHE | _PAGE_GUARDED);
  803. vma->vm_ops = &spufs_signal2_mmap_vmops;
  804. return 0;
  805. }
  806. #else /* SPUFS_MMAP_4K */
  807. #define spufs_signal2_mmap NULL
  808. #endif /* !SPUFS_MMAP_4K */
  809. static const struct file_operations spufs_signal2_fops = {
  810. .open = spufs_signal2_open,
  811. .release = spufs_signal2_release,
  812. .read = spufs_signal2_read,
  813. .write = spufs_signal2_write,
  814. .mmap = spufs_signal2_mmap,
  815. };
  816. static void spufs_signal1_type_set(void *data, u64 val)
  817. {
  818. struct spu_context *ctx = data;
  819. spu_acquire(ctx);
  820. ctx->ops->signal1_type_set(ctx, val);
  821. spu_release(ctx);
  822. }
  823. static u64 __spufs_signal1_type_get(void *data)
  824. {
  825. struct spu_context *ctx = data;
  826. return ctx->ops->signal1_type_get(ctx);
  827. }
  828. static u64 spufs_signal1_type_get(void *data)
  829. {
  830. struct spu_context *ctx = data;
  831. u64 ret;
  832. spu_acquire(ctx);
  833. ret = __spufs_signal1_type_get(data);
  834. spu_release(ctx);
  835. return ret;
  836. }
  837. DEFINE_SIMPLE_ATTRIBUTE(spufs_signal1_type, spufs_signal1_type_get,
  838. spufs_signal1_type_set, "%llu");
  839. static void spufs_signal2_type_set(void *data, u64 val)
  840. {
  841. struct spu_context *ctx = data;
  842. spu_acquire(ctx);
  843. ctx->ops->signal2_type_set(ctx, val);
  844. spu_release(ctx);
  845. }
  846. static u64 __spufs_signal2_type_get(void *data)
  847. {
  848. struct spu_context *ctx = data;
  849. return ctx->ops->signal2_type_get(ctx);
  850. }
  851. static u64 spufs_signal2_type_get(void *data)
  852. {
  853. struct spu_context *ctx = data;
  854. u64 ret;
  855. spu_acquire(ctx);
  856. ret = __spufs_signal2_type_get(data);
  857. spu_release(ctx);
  858. return ret;
  859. }
  860. DEFINE_SIMPLE_ATTRIBUTE(spufs_signal2_type, spufs_signal2_type_get,
  861. spufs_signal2_type_set, "%llu");
  862. #if SPUFS_MMAP_4K
  863. static unsigned long spufs_mss_mmap_nopfn(struct vm_area_struct *vma,
  864. unsigned long address)
  865. {
  866. return spufs_ps_nopfn(vma, address, 0x0000, 0x1000);
  867. }
  868. static struct vm_operations_struct spufs_mss_mmap_vmops = {
  869. .nopfn = spufs_mss_mmap_nopfn,
  870. };
  871. /*
  872. * mmap support for problem state MFC DMA area [0x0000 - 0x0fff].
  873. */
  874. static int spufs_mss_mmap(struct file *file, struct vm_area_struct *vma)
  875. {
  876. if (!(vma->vm_flags & VM_SHARED))
  877. return -EINVAL;
  878. vma->vm_flags |= VM_IO | VM_PFNMAP;
  879. vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
  880. | _PAGE_NO_CACHE | _PAGE_GUARDED);
  881. vma->vm_ops = &spufs_mss_mmap_vmops;
  882. return 0;
  883. }
  884. #else /* SPUFS_MMAP_4K */
  885. #define spufs_mss_mmap NULL
  886. #endif /* !SPUFS_MMAP_4K */
  887. static int spufs_mss_open(struct inode *inode, struct file *file)
  888. {
  889. struct spufs_inode_info *i = SPUFS_I(inode);
  890. struct spu_context *ctx = i->i_ctx;
  891. file->private_data = i->i_ctx;
  892. spin_lock(&ctx->mapping_lock);
  893. if (!i->i_openers++)
  894. ctx->mss = inode->i_mapping;
  895. spin_unlock(&ctx->mapping_lock);
  896. return nonseekable_open(inode, file);
  897. }
  898. static int
  899. spufs_mss_release(struct inode *inode, struct file *file)
  900. {
  901. struct spufs_inode_info *i = SPUFS_I(inode);
  902. struct spu_context *ctx = i->i_ctx;
  903. spin_lock(&ctx->mapping_lock);
  904. if (!--i->i_openers)
  905. ctx->mss = NULL;
  906. spin_unlock(&ctx->mapping_lock);
  907. return 0;
  908. }
  909. static const struct file_operations spufs_mss_fops = {
  910. .open = spufs_mss_open,
  911. .release = spufs_mss_release,
  912. .mmap = spufs_mss_mmap,
  913. };
  914. static unsigned long spufs_psmap_mmap_nopfn(struct vm_area_struct *vma,
  915. unsigned long address)
  916. {
  917. return spufs_ps_nopfn(vma, address, 0x0000, 0x20000);
  918. }
  919. static struct vm_operations_struct spufs_psmap_mmap_vmops = {
  920. .nopfn = spufs_psmap_mmap_nopfn,
  921. };
  922. /*
  923. * mmap support for full problem state area [0x00000 - 0x1ffff].
  924. */
  925. static int spufs_psmap_mmap(struct file *file, struct vm_area_struct *vma)
  926. {
  927. if (!(vma->vm_flags & VM_SHARED))
  928. return -EINVAL;
  929. vma->vm_flags |= VM_IO | VM_PFNMAP;
  930. vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
  931. | _PAGE_NO_CACHE | _PAGE_GUARDED);
  932. vma->vm_ops = &spufs_psmap_mmap_vmops;
  933. return 0;
  934. }
  935. static int spufs_psmap_open(struct inode *inode, struct file *file)
  936. {
  937. struct spufs_inode_info *i = SPUFS_I(inode);
  938. struct spu_context *ctx = i->i_ctx;
  939. spin_lock(&ctx->mapping_lock);
  940. file->private_data = i->i_ctx;
  941. if (!i->i_openers++)
  942. ctx->psmap = inode->i_mapping;
  943. spin_unlock(&ctx->mapping_lock);
  944. return nonseekable_open(inode, file);
  945. }
  946. static int
  947. spufs_psmap_release(struct inode *inode, struct file *file)
  948. {
  949. struct spufs_inode_info *i = SPUFS_I(inode);
  950. struct spu_context *ctx = i->i_ctx;
  951. spin_lock(&ctx->mapping_lock);
  952. if (!--i->i_openers)
  953. ctx->psmap = NULL;
  954. spin_unlock(&ctx->mapping_lock);
  955. return 0;
  956. }
  957. static const struct file_operations spufs_psmap_fops = {
  958. .open = spufs_psmap_open,
  959. .release = spufs_psmap_release,
  960. .mmap = spufs_psmap_mmap,
  961. };
  962. #if SPUFS_MMAP_4K
  963. static unsigned long spufs_mfc_mmap_nopfn(struct vm_area_struct *vma,
  964. unsigned long address)
  965. {
  966. return spufs_ps_nopfn(vma, address, 0x3000, 0x1000);
  967. }
  968. static struct vm_operations_struct spufs_mfc_mmap_vmops = {
  969. .nopfn = spufs_mfc_mmap_nopfn,
  970. };
  971. /*
  972. * mmap support for problem state MFC DMA area [0x0000 - 0x0fff].
  973. */
  974. static int spufs_mfc_mmap(struct file *file, struct vm_area_struct *vma)
  975. {
  976. if (!(vma->vm_flags & VM_SHARED))
  977. return -EINVAL;
  978. vma->vm_flags |= VM_IO | VM_PFNMAP;
  979. vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
  980. | _PAGE_NO_CACHE | _PAGE_GUARDED);
  981. vma->vm_ops = &spufs_mfc_mmap_vmops;
  982. return 0;
  983. }
  984. #else /* SPUFS_MMAP_4K */
  985. #define spufs_mfc_mmap NULL
  986. #endif /* !SPUFS_MMAP_4K */
  987. static int spufs_mfc_open(struct inode *inode, struct file *file)
  988. {
  989. struct spufs_inode_info *i = SPUFS_I(inode);
  990. struct spu_context *ctx = i->i_ctx;
  991. /* we don't want to deal with DMA into other processes */
  992. if (ctx->owner != current->mm)
  993. return -EINVAL;
  994. if (atomic_read(&inode->i_count) != 1)
  995. return -EBUSY;
  996. spin_lock(&ctx->mapping_lock);
  997. file->private_data = ctx;
  998. if (!i->i_openers++)
  999. ctx->mfc = inode->i_mapping;
  1000. spin_unlock(&ctx->mapping_lock);
  1001. return nonseekable_open(inode, file);
  1002. }
  1003. static int
  1004. spufs_mfc_release(struct inode *inode, struct file *file)
  1005. {
  1006. struct spufs_inode_info *i = SPUFS_I(inode);
  1007. struct spu_context *ctx = i->i_ctx;
  1008. spin_lock(&ctx->mapping_lock);
  1009. if (!--i->i_openers)
  1010. ctx->mfc = NULL;
  1011. spin_unlock(&ctx->mapping_lock);
  1012. return 0;
  1013. }
  1014. /* interrupt-level mfc callback function. */
  1015. void spufs_mfc_callback(struct spu *spu)
  1016. {
  1017. struct spu_context *ctx = spu->ctx;
  1018. wake_up_all(&ctx->mfc_wq);
  1019. pr_debug("%s %s\n", __FUNCTION__, spu->name);
  1020. if (ctx->mfc_fasync) {
  1021. u32 free_elements, tagstatus;
  1022. unsigned int mask;
  1023. /* no need for spu_acquire in interrupt context */
  1024. free_elements = ctx->ops->get_mfc_free_elements(ctx);
  1025. tagstatus = ctx->ops->read_mfc_tagstatus(ctx);
  1026. mask = 0;
  1027. if (free_elements & 0xffff)
  1028. mask |= POLLOUT;
  1029. if (tagstatus & ctx->tagwait)
  1030. mask |= POLLIN;
  1031. kill_fasync(&ctx->mfc_fasync, SIGIO, mask);
  1032. }
  1033. }
  1034. static int spufs_read_mfc_tagstatus(struct spu_context *ctx, u32 *status)
  1035. {
  1036. /* See if there is one tag group is complete */
  1037. /* FIXME we need locking around tagwait */
  1038. *status = ctx->ops->read_mfc_tagstatus(ctx) & ctx->tagwait;
  1039. ctx->tagwait &= ~*status;
  1040. if (*status)
  1041. return 1;
  1042. /* enable interrupt waiting for any tag group,
  1043. may silently fail if interrupts are already enabled */
  1044. ctx->ops->set_mfc_query(ctx, ctx->tagwait, 1);
  1045. return 0;
  1046. }
  1047. static ssize_t spufs_mfc_read(struct file *file, char __user *buffer,
  1048. size_t size, loff_t *pos)
  1049. {
  1050. struct spu_context *ctx = file->private_data;
  1051. int ret = -EINVAL;
  1052. u32 status;
  1053. if (size != 4)
  1054. goto out;
  1055. spu_acquire(ctx);
  1056. if (file->f_flags & O_NONBLOCK) {
  1057. status = ctx->ops->read_mfc_tagstatus(ctx);
  1058. if (!(status & ctx->tagwait))
  1059. ret = -EAGAIN;
  1060. else
  1061. ctx->tagwait &= ~status;
  1062. } else {
  1063. ret = spufs_wait(ctx->mfc_wq,
  1064. spufs_read_mfc_tagstatus(ctx, &status));
  1065. }
  1066. spu_release(ctx);
  1067. if (ret)
  1068. goto out;
  1069. ret = 4;
  1070. if (copy_to_user(buffer, &status, 4))
  1071. ret = -EFAULT;
  1072. out:
  1073. return ret;
  1074. }
  1075. static int spufs_check_valid_dma(struct mfc_dma_command *cmd)
  1076. {
  1077. pr_debug("queueing DMA %x %lx %x %x %x\n", cmd->lsa,
  1078. cmd->ea, cmd->size, cmd->tag, cmd->cmd);
  1079. switch (cmd->cmd) {
  1080. case MFC_PUT_CMD:
  1081. case MFC_PUTF_CMD:
  1082. case MFC_PUTB_CMD:
  1083. case MFC_GET_CMD:
  1084. case MFC_GETF_CMD:
  1085. case MFC_GETB_CMD:
  1086. break;
  1087. default:
  1088. pr_debug("invalid DMA opcode %x\n", cmd->cmd);
  1089. return -EIO;
  1090. }
  1091. if ((cmd->lsa & 0xf) != (cmd->ea &0xf)) {
  1092. pr_debug("invalid DMA alignment, ea %lx lsa %x\n",
  1093. cmd->ea, cmd->lsa);
  1094. return -EIO;
  1095. }
  1096. switch (cmd->size & 0xf) {
  1097. case 1:
  1098. break;
  1099. case 2:
  1100. if (cmd->lsa & 1)
  1101. goto error;
  1102. break;
  1103. case 4:
  1104. if (cmd->lsa & 3)
  1105. goto error;
  1106. break;
  1107. case 8:
  1108. if (cmd->lsa & 7)
  1109. goto error;
  1110. break;
  1111. case 0:
  1112. if (cmd->lsa & 15)
  1113. goto error;
  1114. break;
  1115. error:
  1116. default:
  1117. pr_debug("invalid DMA alignment %x for size %x\n",
  1118. cmd->lsa & 0xf, cmd->size);
  1119. return -EIO;
  1120. }
  1121. if (cmd->size > 16 * 1024) {
  1122. pr_debug("invalid DMA size %x\n", cmd->size);
  1123. return -EIO;
  1124. }
  1125. if (cmd->tag & 0xfff0) {
  1126. /* we reserve the higher tag numbers for kernel use */
  1127. pr_debug("invalid DMA tag\n");
  1128. return -EIO;
  1129. }
  1130. if (cmd->class) {
  1131. /* not supported in this version */
  1132. pr_debug("invalid DMA class\n");
  1133. return -EIO;
  1134. }
  1135. return 0;
  1136. }
  1137. static int spu_send_mfc_command(struct spu_context *ctx,
  1138. struct mfc_dma_command cmd,
  1139. int *error)
  1140. {
  1141. *error = ctx->ops->send_mfc_command(ctx, &cmd);
  1142. if (*error == -EAGAIN) {
  1143. /* wait for any tag group to complete
  1144. so we have space for the new command */
  1145. ctx->ops->set_mfc_query(ctx, ctx->tagwait, 1);
  1146. /* try again, because the queue might be
  1147. empty again */
  1148. *error = ctx->ops->send_mfc_command(ctx, &cmd);
  1149. if (*error == -EAGAIN)
  1150. return 0;
  1151. }
  1152. return 1;
  1153. }
  1154. static ssize_t spufs_mfc_write(struct file *file, const char __user *buffer,
  1155. size_t size, loff_t *pos)
  1156. {
  1157. struct spu_context *ctx = file->private_data;
  1158. struct mfc_dma_command cmd;
  1159. int ret = -EINVAL;
  1160. if (size != sizeof cmd)
  1161. goto out;
  1162. ret = -EFAULT;
  1163. if (copy_from_user(&cmd, buffer, sizeof cmd))
  1164. goto out;
  1165. ret = spufs_check_valid_dma(&cmd);
  1166. if (ret)
  1167. goto out;
  1168. ret = spu_acquire_runnable(ctx, 0);
  1169. if (ret)
  1170. goto out;
  1171. if (file->f_flags & O_NONBLOCK) {
  1172. ret = ctx->ops->send_mfc_command(ctx, &cmd);
  1173. } else {
  1174. int status;
  1175. ret = spufs_wait(ctx->mfc_wq,
  1176. spu_send_mfc_command(ctx, cmd, &status));
  1177. if (status)
  1178. ret = status;
  1179. }
  1180. spu_release(ctx);
  1181. if (ret)
  1182. goto out;
  1183. ctx->tagwait |= 1 << cmd.tag;
  1184. ret = size;
  1185. out:
  1186. return ret;
  1187. }
  1188. static unsigned int spufs_mfc_poll(struct file *file,poll_table *wait)
  1189. {
  1190. struct spu_context *ctx = file->private_data;
  1191. u32 free_elements, tagstatus;
  1192. unsigned int mask;
  1193. spu_acquire(ctx);
  1194. ctx->ops->set_mfc_query(ctx, ctx->tagwait, 2);
  1195. free_elements = ctx->ops->get_mfc_free_elements(ctx);
  1196. tagstatus = ctx->ops->read_mfc_tagstatus(ctx);
  1197. spu_release(ctx);
  1198. poll_wait(file, &ctx->mfc_wq, wait);
  1199. mask = 0;
  1200. if (free_elements & 0xffff)
  1201. mask |= POLLOUT | POLLWRNORM;
  1202. if (tagstatus & ctx->tagwait)
  1203. mask |= POLLIN | POLLRDNORM;
  1204. pr_debug("%s: free %d tagstatus %d tagwait %d\n", __FUNCTION__,
  1205. free_elements, tagstatus, ctx->tagwait);
  1206. return mask;
  1207. }
  1208. static int spufs_mfc_flush(struct file *file, fl_owner_t id)
  1209. {
  1210. struct spu_context *ctx = file->private_data;
  1211. int ret;
  1212. spu_acquire(ctx);
  1213. #if 0
  1214. /* this currently hangs */
  1215. ret = spufs_wait(ctx->mfc_wq,
  1216. ctx->ops->set_mfc_query(ctx, ctx->tagwait, 2));
  1217. if (ret)
  1218. goto out;
  1219. ret = spufs_wait(ctx->mfc_wq,
  1220. ctx->ops->read_mfc_tagstatus(ctx) == ctx->tagwait);
  1221. out:
  1222. #else
  1223. ret = 0;
  1224. #endif
  1225. spu_release(ctx);
  1226. return ret;
  1227. }
  1228. static int spufs_mfc_fsync(struct file *file, struct dentry *dentry,
  1229. int datasync)
  1230. {
  1231. return spufs_mfc_flush(file, NULL);
  1232. }
  1233. static int spufs_mfc_fasync(int fd, struct file *file, int on)
  1234. {
  1235. struct spu_context *ctx = file->private_data;
  1236. return fasync_helper(fd, file, on, &ctx->mfc_fasync);
  1237. }
  1238. static const struct file_operations spufs_mfc_fops = {
  1239. .open = spufs_mfc_open,
  1240. .release = spufs_mfc_release,
  1241. .read = spufs_mfc_read,
  1242. .write = spufs_mfc_write,
  1243. .poll = spufs_mfc_poll,
  1244. .flush = spufs_mfc_flush,
  1245. .fsync = spufs_mfc_fsync,
  1246. .fasync = spufs_mfc_fasync,
  1247. .mmap = spufs_mfc_mmap,
  1248. };
  1249. static void spufs_npc_set(void *data, u64 val)
  1250. {
  1251. struct spu_context *ctx = data;
  1252. spu_acquire(ctx);
  1253. ctx->ops->npc_write(ctx, val);
  1254. spu_release(ctx);
  1255. }
  1256. static u64 spufs_npc_get(void *data)
  1257. {
  1258. struct spu_context *ctx = data;
  1259. u64 ret;
  1260. spu_acquire(ctx);
  1261. ret = ctx->ops->npc_read(ctx);
  1262. spu_release(ctx);
  1263. return ret;
  1264. }
  1265. DEFINE_SIMPLE_ATTRIBUTE(spufs_npc_ops, spufs_npc_get, spufs_npc_set,
  1266. "0x%llx\n")
  1267. static void spufs_decr_set(void *data, u64 val)
  1268. {
  1269. struct spu_context *ctx = data;
  1270. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  1271. spu_acquire_saved(ctx);
  1272. lscsa->decr.slot[0] = (u32) val;
  1273. spu_release(ctx);
  1274. }
  1275. static u64 __spufs_decr_get(void *data)
  1276. {
  1277. struct spu_context *ctx = data;
  1278. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  1279. return lscsa->decr.slot[0];
  1280. }
  1281. static u64 spufs_decr_get(void *data)
  1282. {
  1283. struct spu_context *ctx = data;
  1284. u64 ret;
  1285. spu_acquire_saved(ctx);
  1286. ret = __spufs_decr_get(data);
  1287. spu_release(ctx);
  1288. return ret;
  1289. }
  1290. DEFINE_SIMPLE_ATTRIBUTE(spufs_decr_ops, spufs_decr_get, spufs_decr_set,
  1291. "0x%llx\n")
  1292. static void spufs_decr_status_set(void *data, u64 val)
  1293. {
  1294. struct spu_context *ctx = data;
  1295. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  1296. spu_acquire_saved(ctx);
  1297. lscsa->decr_status.slot[0] = (u32) val;
  1298. spu_release(ctx);
  1299. }
  1300. static u64 __spufs_decr_status_get(void *data)
  1301. {
  1302. struct spu_context *ctx = data;
  1303. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  1304. return lscsa->decr_status.slot[0];
  1305. }
  1306. static u64 spufs_decr_status_get(void *data)
  1307. {
  1308. struct spu_context *ctx = data;
  1309. u64 ret;
  1310. spu_acquire_saved(ctx);
  1311. ret = __spufs_decr_status_get(data);
  1312. spu_release(ctx);
  1313. return ret;
  1314. }
  1315. DEFINE_SIMPLE_ATTRIBUTE(spufs_decr_status_ops, spufs_decr_status_get,
  1316. spufs_decr_status_set, "0x%llx\n")
  1317. static void spufs_event_mask_set(void *data, u64 val)
  1318. {
  1319. struct spu_context *ctx = data;
  1320. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  1321. spu_acquire_saved(ctx);
  1322. lscsa->event_mask.slot[0] = (u32) val;
  1323. spu_release(ctx);
  1324. }
  1325. static u64 __spufs_event_mask_get(void *data)
  1326. {
  1327. struct spu_context *ctx = data;
  1328. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  1329. return lscsa->event_mask.slot[0];
  1330. }
  1331. static u64 spufs_event_mask_get(void *data)
  1332. {
  1333. struct spu_context *ctx = data;
  1334. u64 ret;
  1335. spu_acquire_saved(ctx);
  1336. ret = __spufs_event_mask_get(data);
  1337. spu_release(ctx);
  1338. return ret;
  1339. }
  1340. DEFINE_SIMPLE_ATTRIBUTE(spufs_event_mask_ops, spufs_event_mask_get,
  1341. spufs_event_mask_set, "0x%llx\n")
  1342. static u64 __spufs_event_status_get(void *data)
  1343. {
  1344. struct spu_context *ctx = data;
  1345. struct spu_state *state = &ctx->csa;
  1346. u64 stat;
  1347. stat = state->spu_chnlcnt_RW[0];
  1348. if (stat)
  1349. return state->spu_chnldata_RW[0];
  1350. return 0;
  1351. }
  1352. static u64 spufs_event_status_get(void *data)
  1353. {
  1354. struct spu_context *ctx = data;
  1355. u64 ret = 0;
  1356. spu_acquire_saved(ctx);
  1357. ret = __spufs_event_status_get(data);
  1358. spu_release(ctx);
  1359. return ret;
  1360. }
  1361. DEFINE_SIMPLE_ATTRIBUTE(spufs_event_status_ops, spufs_event_status_get,
  1362. NULL, "0x%llx\n")
  1363. static void spufs_srr0_set(void *data, u64 val)
  1364. {
  1365. struct spu_context *ctx = data;
  1366. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  1367. spu_acquire_saved(ctx);
  1368. lscsa->srr0.slot[0] = (u32) val;
  1369. spu_release(ctx);
  1370. }
  1371. static u64 spufs_srr0_get(void *data)
  1372. {
  1373. struct spu_context *ctx = data;
  1374. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  1375. u64 ret;
  1376. spu_acquire_saved(ctx);
  1377. ret = lscsa->srr0.slot[0];
  1378. spu_release(ctx);
  1379. return ret;
  1380. }
  1381. DEFINE_SIMPLE_ATTRIBUTE(spufs_srr0_ops, spufs_srr0_get, spufs_srr0_set,
  1382. "0x%llx\n")
  1383. static u64 spufs_id_get(void *data)
  1384. {
  1385. struct spu_context *ctx = data;
  1386. u64 num;
  1387. spu_acquire(ctx);
  1388. if (ctx->state == SPU_STATE_RUNNABLE)
  1389. num = ctx->spu->number;
  1390. else
  1391. num = (unsigned int)-1;
  1392. spu_release(ctx);
  1393. return num;
  1394. }
  1395. DEFINE_SIMPLE_ATTRIBUTE(spufs_id_ops, spufs_id_get, NULL, "0x%llx\n")
  1396. static u64 __spufs_object_id_get(void *data)
  1397. {
  1398. struct spu_context *ctx = data;
  1399. return ctx->object_id;
  1400. }
  1401. static u64 spufs_object_id_get(void *data)
  1402. {
  1403. /* FIXME: Should there really be no locking here? */
  1404. return __spufs_object_id_get(data);
  1405. }
  1406. static void spufs_object_id_set(void *data, u64 id)
  1407. {
  1408. struct spu_context *ctx = data;
  1409. ctx->object_id = id;
  1410. }
  1411. DEFINE_SIMPLE_ATTRIBUTE(spufs_object_id_ops, spufs_object_id_get,
  1412. spufs_object_id_set, "0x%llx\n");
  1413. static u64 __spufs_lslr_get(void *data)
  1414. {
  1415. struct spu_context *ctx = data;
  1416. return ctx->csa.priv2.spu_lslr_RW;
  1417. }
  1418. static u64 spufs_lslr_get(void *data)
  1419. {
  1420. struct spu_context *ctx = data;
  1421. u64 ret;
  1422. spu_acquire_saved(ctx);
  1423. ret = __spufs_lslr_get(data);
  1424. spu_release(ctx);
  1425. return ret;
  1426. }
  1427. DEFINE_SIMPLE_ATTRIBUTE(spufs_lslr_ops, spufs_lslr_get, NULL, "0x%llx\n")
  1428. static int spufs_info_open(struct inode *inode, struct file *file)
  1429. {
  1430. struct spufs_inode_info *i = SPUFS_I(inode);
  1431. struct spu_context *ctx = i->i_ctx;
  1432. file->private_data = ctx;
  1433. return 0;
  1434. }
  1435. static ssize_t __spufs_mbox_info_read(struct spu_context *ctx,
  1436. char __user *buf, size_t len, loff_t *pos)
  1437. {
  1438. u32 mbox_stat;
  1439. u32 data;
  1440. mbox_stat = ctx->csa.prob.mb_stat_R;
  1441. if (mbox_stat & 0x0000ff) {
  1442. data = ctx->csa.prob.pu_mb_R;
  1443. }
  1444. return simple_read_from_buffer(buf, len, pos, &data, sizeof data);
  1445. }
  1446. static ssize_t spufs_mbox_info_read(struct file *file, char __user *buf,
  1447. size_t len, loff_t *pos)
  1448. {
  1449. int ret;
  1450. struct spu_context *ctx = file->private_data;
  1451. if (!access_ok(VERIFY_WRITE, buf, len))
  1452. return -EFAULT;
  1453. spu_acquire_saved(ctx);
  1454. spin_lock(&ctx->csa.register_lock);
  1455. ret = __spufs_mbox_info_read(ctx, buf, len, pos);
  1456. spin_unlock(&ctx->csa.register_lock);
  1457. spu_release(ctx);
  1458. return ret;
  1459. }
  1460. static const struct file_operations spufs_mbox_info_fops = {
  1461. .open = spufs_info_open,
  1462. .read = spufs_mbox_info_read,
  1463. .llseek = generic_file_llseek,
  1464. };
  1465. static ssize_t __spufs_ibox_info_read(struct spu_context *ctx,
  1466. char __user *buf, size_t len, loff_t *pos)
  1467. {
  1468. u32 ibox_stat;
  1469. u32 data;
  1470. ibox_stat = ctx->csa.prob.mb_stat_R;
  1471. if (ibox_stat & 0xff0000) {
  1472. data = ctx->csa.priv2.puint_mb_R;
  1473. }
  1474. return simple_read_from_buffer(buf, len, pos, &data, sizeof data);
  1475. }
  1476. static ssize_t spufs_ibox_info_read(struct file *file, char __user *buf,
  1477. size_t len, loff_t *pos)
  1478. {
  1479. struct spu_context *ctx = file->private_data;
  1480. int ret;
  1481. if (!access_ok(VERIFY_WRITE, buf, len))
  1482. return -EFAULT;
  1483. spu_acquire_saved(ctx);
  1484. spin_lock(&ctx->csa.register_lock);
  1485. ret = __spufs_ibox_info_read(ctx, buf, len, pos);
  1486. spin_unlock(&ctx->csa.register_lock);
  1487. spu_release(ctx);
  1488. return ret;
  1489. }
  1490. static const struct file_operations spufs_ibox_info_fops = {
  1491. .open = spufs_info_open,
  1492. .read = spufs_ibox_info_read,
  1493. .llseek = generic_file_llseek,
  1494. };
  1495. static ssize_t __spufs_wbox_info_read(struct spu_context *ctx,
  1496. char __user *buf, size_t len, loff_t *pos)
  1497. {
  1498. int i, cnt;
  1499. u32 data[4];
  1500. u32 wbox_stat;
  1501. wbox_stat = ctx->csa.prob.mb_stat_R;
  1502. cnt = 4 - ((wbox_stat & 0x00ff00) >> 8);
  1503. for (i = 0; i < cnt; i++) {
  1504. data[i] = ctx->csa.spu_mailbox_data[i];
  1505. }
  1506. return simple_read_from_buffer(buf, len, pos, &data,
  1507. cnt * sizeof(u32));
  1508. }
  1509. static ssize_t spufs_wbox_info_read(struct file *file, char __user *buf,
  1510. size_t len, loff_t *pos)
  1511. {
  1512. struct spu_context *ctx = file->private_data;
  1513. int ret;
  1514. if (!access_ok(VERIFY_WRITE, buf, len))
  1515. return -EFAULT;
  1516. spu_acquire_saved(ctx);
  1517. spin_lock(&ctx->csa.register_lock);
  1518. ret = __spufs_wbox_info_read(ctx, buf, len, pos);
  1519. spin_unlock(&ctx->csa.register_lock);
  1520. spu_release(ctx);
  1521. return ret;
  1522. }
  1523. static const struct file_operations spufs_wbox_info_fops = {
  1524. .open = spufs_info_open,
  1525. .read = spufs_wbox_info_read,
  1526. .llseek = generic_file_llseek,
  1527. };
  1528. static ssize_t __spufs_dma_info_read(struct spu_context *ctx,
  1529. char __user *buf, size_t len, loff_t *pos)
  1530. {
  1531. struct spu_dma_info info;
  1532. struct mfc_cq_sr *qp, *spuqp;
  1533. int i;
  1534. info.dma_info_type = ctx->csa.priv2.spu_tag_status_query_RW;
  1535. info.dma_info_mask = ctx->csa.lscsa->tag_mask.slot[0];
  1536. info.dma_info_status = ctx->csa.spu_chnldata_RW[24];
  1537. info.dma_info_stall_and_notify = ctx->csa.spu_chnldata_RW[25];
  1538. info.dma_info_atomic_command_status = ctx->csa.spu_chnldata_RW[27];
  1539. for (i = 0; i < 16; i++) {
  1540. qp = &info.dma_info_command_data[i];
  1541. spuqp = &ctx->csa.priv2.spuq[i];
  1542. qp->mfc_cq_data0_RW = spuqp->mfc_cq_data0_RW;
  1543. qp->mfc_cq_data1_RW = spuqp->mfc_cq_data1_RW;
  1544. qp->mfc_cq_data2_RW = spuqp->mfc_cq_data2_RW;
  1545. qp->mfc_cq_data3_RW = spuqp->mfc_cq_data3_RW;
  1546. }
  1547. return simple_read_from_buffer(buf, len, pos, &info,
  1548. sizeof info);
  1549. }
  1550. static ssize_t spufs_dma_info_read(struct file *file, char __user *buf,
  1551. size_t len, loff_t *pos)
  1552. {
  1553. struct spu_context *ctx = file->private_data;
  1554. int ret;
  1555. if (!access_ok(VERIFY_WRITE, buf, len))
  1556. return -EFAULT;
  1557. spu_acquire_saved(ctx);
  1558. spin_lock(&ctx->csa.register_lock);
  1559. ret = __spufs_dma_info_read(ctx, buf, len, pos);
  1560. spin_unlock(&ctx->csa.register_lock);
  1561. spu_release(ctx);
  1562. return ret;
  1563. }
  1564. static const struct file_operations spufs_dma_info_fops = {
  1565. .open = spufs_info_open,
  1566. .read = spufs_dma_info_read,
  1567. };
  1568. static ssize_t __spufs_proxydma_info_read(struct spu_context *ctx,
  1569. char __user *buf, size_t len, loff_t *pos)
  1570. {
  1571. struct spu_proxydma_info info;
  1572. struct mfc_cq_sr *qp, *puqp;
  1573. int ret = sizeof info;
  1574. int i;
  1575. if (len < ret)
  1576. return -EINVAL;
  1577. if (!access_ok(VERIFY_WRITE, buf, len))
  1578. return -EFAULT;
  1579. info.proxydma_info_type = ctx->csa.prob.dma_querytype_RW;
  1580. info.proxydma_info_mask = ctx->csa.prob.dma_querymask_RW;
  1581. info.proxydma_info_status = ctx->csa.prob.dma_tagstatus_R;
  1582. for (i = 0; i < 8; i++) {
  1583. qp = &info.proxydma_info_command_data[i];
  1584. puqp = &ctx->csa.priv2.puq[i];
  1585. qp->mfc_cq_data0_RW = puqp->mfc_cq_data0_RW;
  1586. qp->mfc_cq_data1_RW = puqp->mfc_cq_data1_RW;
  1587. qp->mfc_cq_data2_RW = puqp->mfc_cq_data2_RW;
  1588. qp->mfc_cq_data3_RW = puqp->mfc_cq_data3_RW;
  1589. }
  1590. return simple_read_from_buffer(buf, len, pos, &info,
  1591. sizeof info);
  1592. }
  1593. static ssize_t spufs_proxydma_info_read(struct file *file, char __user *buf,
  1594. size_t len, loff_t *pos)
  1595. {
  1596. struct spu_context *ctx = file->private_data;
  1597. int ret;
  1598. spu_acquire_saved(ctx);
  1599. spin_lock(&ctx->csa.register_lock);
  1600. ret = __spufs_proxydma_info_read(ctx, buf, len, pos);
  1601. spin_unlock(&ctx->csa.register_lock);
  1602. spu_release(ctx);
  1603. return ret;
  1604. }
  1605. static const struct file_operations spufs_proxydma_info_fops = {
  1606. .open = spufs_info_open,
  1607. .read = spufs_proxydma_info_read,
  1608. };
  1609. struct tree_descr spufs_dir_contents[] = {
  1610. { "mem", &spufs_mem_fops, 0666, },
  1611. { "regs", &spufs_regs_fops, 0666, },
  1612. { "mbox", &spufs_mbox_fops, 0444, },
  1613. { "ibox", &spufs_ibox_fops, 0444, },
  1614. { "wbox", &spufs_wbox_fops, 0222, },
  1615. { "mbox_stat", &spufs_mbox_stat_fops, 0444, },
  1616. { "ibox_stat", &spufs_ibox_stat_fops, 0444, },
  1617. { "wbox_stat", &spufs_wbox_stat_fops, 0444, },
  1618. { "signal1", &spufs_signal1_fops, 0666, },
  1619. { "signal2", &spufs_signal2_fops, 0666, },
  1620. { "signal1_type", &spufs_signal1_type, 0666, },
  1621. { "signal2_type", &spufs_signal2_type, 0666, },
  1622. { "cntl", &spufs_cntl_fops, 0666, },
  1623. { "fpcr", &spufs_fpcr_fops, 0666, },
  1624. { "lslr", &spufs_lslr_ops, 0444, },
  1625. { "mfc", &spufs_mfc_fops, 0666, },
  1626. { "mss", &spufs_mss_fops, 0666, },
  1627. { "npc", &spufs_npc_ops, 0666, },
  1628. { "srr0", &spufs_srr0_ops, 0666, },
  1629. { "decr", &spufs_decr_ops, 0666, },
  1630. { "decr_status", &spufs_decr_status_ops, 0666, },
  1631. { "event_mask", &spufs_event_mask_ops, 0666, },
  1632. { "event_status", &spufs_event_status_ops, 0444, },
  1633. { "psmap", &spufs_psmap_fops, 0666, },
  1634. { "phys-id", &spufs_id_ops, 0666, },
  1635. { "object-id", &spufs_object_id_ops, 0666, },
  1636. { "mbox_info", &spufs_mbox_info_fops, 0444, },
  1637. { "ibox_info", &spufs_ibox_info_fops, 0444, },
  1638. { "wbox_info", &spufs_wbox_info_fops, 0444, },
  1639. { "dma_info", &spufs_dma_info_fops, 0444, },
  1640. { "proxydma_info", &spufs_proxydma_info_fops, 0444, },
  1641. {},
  1642. };
  1643. struct tree_descr spufs_dir_nosched_contents[] = {
  1644. { "mem", &spufs_mem_fops, 0666, },
  1645. { "mbox", &spufs_mbox_fops, 0444, },
  1646. { "ibox", &spufs_ibox_fops, 0444, },
  1647. { "wbox", &spufs_wbox_fops, 0222, },
  1648. { "mbox_stat", &spufs_mbox_stat_fops, 0444, },
  1649. { "ibox_stat", &spufs_ibox_stat_fops, 0444, },
  1650. { "wbox_stat", &spufs_wbox_stat_fops, 0444, },
  1651. { "signal1", &spufs_signal1_fops, 0666, },
  1652. { "signal2", &spufs_signal2_fops, 0666, },
  1653. { "signal1_type", &spufs_signal1_type, 0666, },
  1654. { "signal2_type", &spufs_signal2_type, 0666, },
  1655. { "mss", &spufs_mss_fops, 0666, },
  1656. { "mfc", &spufs_mfc_fops, 0666, },
  1657. { "cntl", &spufs_cntl_fops, 0666, },
  1658. { "npc", &spufs_npc_ops, 0666, },
  1659. { "psmap", &spufs_psmap_fops, 0666, },
  1660. { "phys-id", &spufs_id_ops, 0666, },
  1661. { "object-id", &spufs_object_id_ops, 0666, },
  1662. {},
  1663. };
  1664. struct spufs_coredump_reader spufs_coredump_read[] = {
  1665. { "regs", __spufs_regs_read, NULL, 128 * 16 },
  1666. { "fpcr", __spufs_fpcr_read, NULL, 16 },
  1667. { "lslr", NULL, __spufs_lslr_get, 11 },
  1668. { "decr", NULL, __spufs_decr_get, 11 },
  1669. { "decr_status", NULL, __spufs_decr_status_get, 11 },
  1670. { "mem", __spufs_mem_read, NULL, 256 * 1024, },
  1671. { "signal1", __spufs_signal1_read, NULL, 4 },
  1672. { "signal1_type", NULL, __spufs_signal1_type_get, 2 },
  1673. { "signal2", __spufs_signal2_read, NULL, 4 },
  1674. { "signal2_type", NULL, __spufs_signal2_type_get, 2 },
  1675. { "event_mask", NULL, __spufs_event_mask_get, 8 },
  1676. { "event_status", NULL, __spufs_event_status_get, 8 },
  1677. { "mbox_info", __spufs_mbox_info_read, NULL, 4 },
  1678. { "ibox_info", __spufs_ibox_info_read, NULL, 4 },
  1679. { "wbox_info", __spufs_wbox_info_read, NULL, 16 },
  1680. { "dma_info", __spufs_dma_info_read, NULL, 69 * 8 },
  1681. { "proxydma_info", __spufs_proxydma_info_read, NULL, 35 * 8 },
  1682. { "object-id", NULL, __spufs_object_id_get, 19 },
  1683. { },
  1684. };
  1685. int spufs_coredump_num_notes = ARRAY_SIZE(spufs_coredump_read) - 1;