file.c 48 KB

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