file.c 48 KB

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