file.c 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642
  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 <linux/seq_file.h>
  30. #include <linux/marker.h>
  31. #include <asm/io.h>
  32. #include <asm/time.h>
  33. #include <asm/spu.h>
  34. #include <asm/spu_info.h>
  35. #include <asm/uaccess.h>
  36. #include "spufs.h"
  37. #define SPUFS_MMAP_4K (PAGE_SIZE == 0x1000)
  38. /* Simple attribute files */
  39. struct spufs_attr {
  40. int (*get)(void *, u64 *);
  41. int (*set)(void *, u64);
  42. char get_buf[24]; /* enough to store a u64 and "\n\0" */
  43. char set_buf[24];
  44. void *data;
  45. const char *fmt; /* format for read operation */
  46. struct mutex mutex; /* protects access to these buffers */
  47. };
  48. static int spufs_attr_open(struct inode *inode, struct file *file,
  49. int (*get)(void *, u64 *), int (*set)(void *, u64),
  50. const char *fmt)
  51. {
  52. struct spufs_attr *attr;
  53. attr = kmalloc(sizeof(*attr), GFP_KERNEL);
  54. if (!attr)
  55. return -ENOMEM;
  56. attr->get = get;
  57. attr->set = set;
  58. attr->data = inode->i_private;
  59. attr->fmt = fmt;
  60. mutex_init(&attr->mutex);
  61. file->private_data = attr;
  62. return nonseekable_open(inode, file);
  63. }
  64. static int spufs_attr_release(struct inode *inode, struct file *file)
  65. {
  66. kfree(file->private_data);
  67. return 0;
  68. }
  69. static ssize_t spufs_attr_read(struct file *file, char __user *buf,
  70. size_t len, loff_t *ppos)
  71. {
  72. struct spufs_attr *attr;
  73. size_t size;
  74. ssize_t ret;
  75. attr = file->private_data;
  76. if (!attr->get)
  77. return -EACCES;
  78. ret = mutex_lock_interruptible(&attr->mutex);
  79. if (ret)
  80. return ret;
  81. if (*ppos) { /* continued read */
  82. size = strlen(attr->get_buf);
  83. } else { /* first read */
  84. u64 val;
  85. ret = attr->get(attr->data, &val);
  86. if (ret)
  87. goto out;
  88. size = scnprintf(attr->get_buf, sizeof(attr->get_buf),
  89. attr->fmt, (unsigned long long)val);
  90. }
  91. ret = simple_read_from_buffer(buf, len, ppos, attr->get_buf, size);
  92. out:
  93. mutex_unlock(&attr->mutex);
  94. return ret;
  95. }
  96. static ssize_t spufs_attr_write(struct file *file, const char __user *buf,
  97. size_t len, loff_t *ppos)
  98. {
  99. struct spufs_attr *attr;
  100. u64 val;
  101. size_t size;
  102. ssize_t ret;
  103. attr = file->private_data;
  104. if (!attr->set)
  105. return -EACCES;
  106. ret = mutex_lock_interruptible(&attr->mutex);
  107. if (ret)
  108. return ret;
  109. ret = -EFAULT;
  110. size = min(sizeof(attr->set_buf) - 1, len);
  111. if (copy_from_user(attr->set_buf, buf, size))
  112. goto out;
  113. ret = len; /* claim we got the whole input */
  114. attr->set_buf[size] = '\0';
  115. val = simple_strtol(attr->set_buf, NULL, 0);
  116. attr->set(attr->data, val);
  117. out:
  118. mutex_unlock(&attr->mutex);
  119. return ret;
  120. }
  121. #define DEFINE_SPUFS_SIMPLE_ATTRIBUTE(__fops, __get, __set, __fmt) \
  122. static int __fops ## _open(struct inode *inode, struct file *file) \
  123. { \
  124. __simple_attr_check_format(__fmt, 0ull); \
  125. return spufs_attr_open(inode, file, __get, __set, __fmt); \
  126. } \
  127. static struct file_operations __fops = { \
  128. .owner = THIS_MODULE, \
  129. .open = __fops ## _open, \
  130. .release = spufs_attr_release, \
  131. .read = spufs_attr_read, \
  132. .write = spufs_attr_write, \
  133. };
  134. static int
  135. spufs_mem_open(struct inode *inode, struct file *file)
  136. {
  137. struct spufs_inode_info *i = SPUFS_I(inode);
  138. struct spu_context *ctx = i->i_ctx;
  139. mutex_lock(&ctx->mapping_lock);
  140. file->private_data = ctx;
  141. if (!i->i_openers++)
  142. ctx->local_store = inode->i_mapping;
  143. mutex_unlock(&ctx->mapping_lock);
  144. return 0;
  145. }
  146. static int
  147. spufs_mem_release(struct inode *inode, struct file *file)
  148. {
  149. struct spufs_inode_info *i = SPUFS_I(inode);
  150. struct spu_context *ctx = i->i_ctx;
  151. mutex_lock(&ctx->mapping_lock);
  152. if (!--i->i_openers)
  153. ctx->local_store = NULL;
  154. mutex_unlock(&ctx->mapping_lock);
  155. return 0;
  156. }
  157. static ssize_t
  158. __spufs_mem_read(struct spu_context *ctx, char __user *buffer,
  159. size_t size, loff_t *pos)
  160. {
  161. char *local_store = ctx->ops->get_ls(ctx);
  162. return simple_read_from_buffer(buffer, size, pos, local_store,
  163. LS_SIZE);
  164. }
  165. static ssize_t
  166. spufs_mem_read(struct file *file, char __user *buffer,
  167. size_t size, loff_t *pos)
  168. {
  169. struct spu_context *ctx = file->private_data;
  170. ssize_t ret;
  171. ret = spu_acquire(ctx);
  172. if (ret)
  173. return ret;
  174. ret = __spufs_mem_read(ctx, buffer, size, pos);
  175. spu_release(ctx);
  176. return ret;
  177. }
  178. static ssize_t
  179. spufs_mem_write(struct file *file, const char __user *buffer,
  180. size_t size, loff_t *ppos)
  181. {
  182. struct spu_context *ctx = file->private_data;
  183. char *local_store;
  184. loff_t pos = *ppos;
  185. int ret;
  186. if (pos < 0)
  187. return -EINVAL;
  188. if (pos > LS_SIZE)
  189. return -EFBIG;
  190. if (size > LS_SIZE - pos)
  191. size = LS_SIZE - pos;
  192. ret = spu_acquire(ctx);
  193. if (ret)
  194. return ret;
  195. local_store = ctx->ops->get_ls(ctx);
  196. ret = copy_from_user(local_store + pos, buffer, size);
  197. spu_release(ctx);
  198. if (ret)
  199. return -EFAULT;
  200. *ppos = pos + size;
  201. return size;
  202. }
  203. static unsigned long spufs_mem_mmap_nopfn(struct vm_area_struct *vma,
  204. unsigned long address)
  205. {
  206. struct spu_context *ctx = vma->vm_file->private_data;
  207. unsigned long pfn, offset, addr0 = address;
  208. #ifdef CONFIG_SPU_FS_64K_LS
  209. struct spu_state *csa = &ctx->csa;
  210. int psize;
  211. /* Check what page size we are using */
  212. psize = get_slice_psize(vma->vm_mm, address);
  213. /* Some sanity checking */
  214. BUG_ON(csa->use_big_pages != (psize == MMU_PAGE_64K));
  215. /* Wow, 64K, cool, we need to align the address though */
  216. if (csa->use_big_pages) {
  217. BUG_ON(vma->vm_start & 0xffff);
  218. address &= ~0xfffful;
  219. }
  220. #endif /* CONFIG_SPU_FS_64K_LS */
  221. offset = (address - vma->vm_start) + (vma->vm_pgoff << PAGE_SHIFT);
  222. if (offset >= LS_SIZE)
  223. return NOPFN_SIGBUS;
  224. pr_debug("spufs_mem_mmap_nopfn address=0x%lx -> 0x%lx, offset=0x%lx\n",
  225. addr0, address, offset);
  226. if (spu_acquire(ctx))
  227. return NOPFN_REFAULT;
  228. if (ctx->state == SPU_STATE_SAVED) {
  229. vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
  230. & ~_PAGE_NO_CACHE);
  231. pfn = vmalloc_to_pfn(ctx->csa.lscsa->ls + offset);
  232. } else {
  233. vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
  234. | _PAGE_NO_CACHE);
  235. pfn = (ctx->spu->local_store_phys + offset) >> PAGE_SHIFT;
  236. }
  237. vm_insert_pfn(vma, address, pfn);
  238. spu_release(ctx);
  239. return NOPFN_REFAULT;
  240. }
  241. static struct vm_operations_struct spufs_mem_mmap_vmops = {
  242. .nopfn = spufs_mem_mmap_nopfn,
  243. };
  244. static int spufs_mem_mmap(struct file *file, struct vm_area_struct *vma)
  245. {
  246. #ifdef CONFIG_SPU_FS_64K_LS
  247. struct spu_context *ctx = file->private_data;
  248. struct spu_state *csa = &ctx->csa;
  249. /* Sanity check VMA alignment */
  250. if (csa->use_big_pages) {
  251. pr_debug("spufs_mem_mmap 64K, start=0x%lx, end=0x%lx,"
  252. " pgoff=0x%lx\n", vma->vm_start, vma->vm_end,
  253. vma->vm_pgoff);
  254. if (vma->vm_start & 0xffff)
  255. return -EINVAL;
  256. if (vma->vm_pgoff & 0xf)
  257. return -EINVAL;
  258. }
  259. #endif /* CONFIG_SPU_FS_64K_LS */
  260. if (!(vma->vm_flags & VM_SHARED))
  261. return -EINVAL;
  262. vma->vm_flags |= VM_IO | VM_PFNMAP;
  263. vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
  264. | _PAGE_NO_CACHE);
  265. vma->vm_ops = &spufs_mem_mmap_vmops;
  266. return 0;
  267. }
  268. #ifdef CONFIG_SPU_FS_64K_LS
  269. static unsigned long spufs_get_unmapped_area(struct file *file,
  270. unsigned long addr, unsigned long len, unsigned long pgoff,
  271. unsigned long flags)
  272. {
  273. struct spu_context *ctx = file->private_data;
  274. struct spu_state *csa = &ctx->csa;
  275. /* If not using big pages, fallback to normal MM g_u_a */
  276. if (!csa->use_big_pages)
  277. return current->mm->get_unmapped_area(file, addr, len,
  278. pgoff, flags);
  279. /* Else, try to obtain a 64K pages slice */
  280. return slice_get_unmapped_area(addr, len, flags,
  281. MMU_PAGE_64K, 1, 0);
  282. }
  283. #endif /* CONFIG_SPU_FS_64K_LS */
  284. static const struct file_operations spufs_mem_fops = {
  285. .open = spufs_mem_open,
  286. .release = spufs_mem_release,
  287. .read = spufs_mem_read,
  288. .write = spufs_mem_write,
  289. .llseek = generic_file_llseek,
  290. .mmap = spufs_mem_mmap,
  291. #ifdef CONFIG_SPU_FS_64K_LS
  292. .get_unmapped_area = spufs_get_unmapped_area,
  293. #endif
  294. };
  295. static unsigned long spufs_ps_nopfn(struct vm_area_struct *vma,
  296. unsigned long address,
  297. unsigned long ps_offs,
  298. unsigned long ps_size)
  299. {
  300. struct spu_context *ctx = vma->vm_file->private_data;
  301. unsigned long area, offset = address - vma->vm_start;
  302. int ret = 0;
  303. spu_context_nospu_trace(spufs_ps_nopfn__enter, ctx);
  304. offset += vma->vm_pgoff << PAGE_SHIFT;
  305. if (offset >= ps_size)
  306. return NOPFN_SIGBUS;
  307. /*
  308. * Because we release the mmap_sem, the context may be destroyed while
  309. * we're in spu_wait. Grab an extra reference so it isn't destroyed
  310. * in the meantime.
  311. */
  312. get_spu_context(ctx);
  313. /*
  314. * We have to wait for context to be loaded before we have
  315. * pages to hand out to the user, but we don't want to wait
  316. * with the mmap_sem held.
  317. * It is possible to drop the mmap_sem here, but then we need
  318. * to return NOPFN_REFAULT because the mappings may have
  319. * hanged.
  320. */
  321. if (spu_acquire(ctx))
  322. goto refault;
  323. if (ctx->state == SPU_STATE_SAVED) {
  324. up_read(&current->mm->mmap_sem);
  325. spu_context_nospu_trace(spufs_ps_nopfn__sleep, ctx);
  326. ret = spufs_wait(ctx->run_wq, ctx->state == SPU_STATE_RUNNABLE);
  327. spu_context_trace(spufs_ps_nopfn__wake, ctx, ctx->spu);
  328. down_read(&current->mm->mmap_sem);
  329. } else {
  330. area = ctx->spu->problem_phys + ps_offs;
  331. vm_insert_pfn(vma, address, (area + offset) >> PAGE_SHIFT);
  332. spu_context_trace(spufs_ps_nopfn__insert, ctx, ctx->spu);
  333. }
  334. if (!ret)
  335. spu_release(ctx);
  336. refault:
  337. put_spu_context(ctx);
  338. return NOPFN_REFAULT;
  339. }
  340. #if SPUFS_MMAP_4K
  341. static unsigned long spufs_cntl_mmap_nopfn(struct vm_area_struct *vma,
  342. unsigned long address)
  343. {
  344. return spufs_ps_nopfn(vma, address, 0x4000, 0x1000);
  345. }
  346. static struct vm_operations_struct spufs_cntl_mmap_vmops = {
  347. .nopfn = spufs_cntl_mmap_nopfn,
  348. };
  349. /*
  350. * mmap support for problem state control area [0x4000 - 0x4fff].
  351. */
  352. static int spufs_cntl_mmap(struct file *file, struct vm_area_struct *vma)
  353. {
  354. if (!(vma->vm_flags & VM_SHARED))
  355. return -EINVAL;
  356. vma->vm_flags |= VM_IO | VM_PFNMAP;
  357. vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
  358. | _PAGE_NO_CACHE | _PAGE_GUARDED);
  359. vma->vm_ops = &spufs_cntl_mmap_vmops;
  360. return 0;
  361. }
  362. #else /* SPUFS_MMAP_4K */
  363. #define spufs_cntl_mmap NULL
  364. #endif /* !SPUFS_MMAP_4K */
  365. static int spufs_cntl_get(void *data, u64 *val)
  366. {
  367. struct spu_context *ctx = data;
  368. int ret;
  369. ret = spu_acquire(ctx);
  370. if (ret)
  371. return ret;
  372. *val = ctx->ops->status_read(ctx);
  373. spu_release(ctx);
  374. return 0;
  375. }
  376. static int spufs_cntl_set(void *data, u64 val)
  377. {
  378. struct spu_context *ctx = data;
  379. int ret;
  380. ret = spu_acquire(ctx);
  381. if (ret)
  382. return ret;
  383. ctx->ops->runcntl_write(ctx, val);
  384. spu_release(ctx);
  385. return 0;
  386. }
  387. static int spufs_cntl_open(struct inode *inode, struct file *file)
  388. {
  389. struct spufs_inode_info *i = SPUFS_I(inode);
  390. struct spu_context *ctx = i->i_ctx;
  391. mutex_lock(&ctx->mapping_lock);
  392. file->private_data = ctx;
  393. if (!i->i_openers++)
  394. ctx->cntl = inode->i_mapping;
  395. mutex_unlock(&ctx->mapping_lock);
  396. return simple_attr_open(inode, file, spufs_cntl_get,
  397. spufs_cntl_set, "0x%08lx");
  398. }
  399. static int
  400. spufs_cntl_release(struct inode *inode, struct file *file)
  401. {
  402. struct spufs_inode_info *i = SPUFS_I(inode);
  403. struct spu_context *ctx = i->i_ctx;
  404. simple_attr_release(inode, file);
  405. mutex_lock(&ctx->mapping_lock);
  406. if (!--i->i_openers)
  407. ctx->cntl = NULL;
  408. mutex_unlock(&ctx->mapping_lock);
  409. return 0;
  410. }
  411. static const struct file_operations spufs_cntl_fops = {
  412. .open = spufs_cntl_open,
  413. .release = spufs_cntl_release,
  414. .read = simple_attr_read,
  415. .write = simple_attr_write,
  416. .mmap = spufs_cntl_mmap,
  417. };
  418. static int
  419. spufs_regs_open(struct inode *inode, struct file *file)
  420. {
  421. struct spufs_inode_info *i = SPUFS_I(inode);
  422. file->private_data = i->i_ctx;
  423. return 0;
  424. }
  425. static ssize_t
  426. __spufs_regs_read(struct spu_context *ctx, char __user *buffer,
  427. size_t size, loff_t *pos)
  428. {
  429. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  430. return simple_read_from_buffer(buffer, size, pos,
  431. lscsa->gprs, sizeof lscsa->gprs);
  432. }
  433. static ssize_t
  434. spufs_regs_read(struct file *file, char __user *buffer,
  435. size_t size, loff_t *pos)
  436. {
  437. int ret;
  438. struct spu_context *ctx = file->private_data;
  439. ret = spu_acquire_saved(ctx);
  440. if (ret)
  441. return ret;
  442. ret = __spufs_regs_read(ctx, buffer, size, pos);
  443. spu_release_saved(ctx);
  444. return ret;
  445. }
  446. static ssize_t
  447. spufs_regs_write(struct file *file, const char __user *buffer,
  448. size_t size, loff_t *pos)
  449. {
  450. struct spu_context *ctx = file->private_data;
  451. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  452. int ret;
  453. size = min_t(ssize_t, sizeof lscsa->gprs - *pos, size);
  454. if (size <= 0)
  455. return -EFBIG;
  456. *pos += size;
  457. ret = spu_acquire_saved(ctx);
  458. if (ret)
  459. return ret;
  460. ret = copy_from_user(lscsa->gprs + *pos - size,
  461. buffer, size) ? -EFAULT : size;
  462. spu_release_saved(ctx);
  463. return ret;
  464. }
  465. static const struct file_operations spufs_regs_fops = {
  466. .open = spufs_regs_open,
  467. .read = spufs_regs_read,
  468. .write = spufs_regs_write,
  469. .llseek = generic_file_llseek,
  470. };
  471. static ssize_t
  472. __spufs_fpcr_read(struct spu_context *ctx, char __user * buffer,
  473. size_t size, loff_t * pos)
  474. {
  475. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  476. return simple_read_from_buffer(buffer, size, pos,
  477. &lscsa->fpcr, sizeof(lscsa->fpcr));
  478. }
  479. static ssize_t
  480. spufs_fpcr_read(struct file *file, char __user * buffer,
  481. size_t size, loff_t * pos)
  482. {
  483. int ret;
  484. struct spu_context *ctx = file->private_data;
  485. ret = spu_acquire_saved(ctx);
  486. if (ret)
  487. return ret;
  488. ret = __spufs_fpcr_read(ctx, buffer, size, pos);
  489. spu_release_saved(ctx);
  490. return ret;
  491. }
  492. static ssize_t
  493. spufs_fpcr_write(struct file *file, const char __user * buffer,
  494. size_t size, loff_t * pos)
  495. {
  496. struct spu_context *ctx = file->private_data;
  497. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  498. int ret;
  499. size = min_t(ssize_t, sizeof(lscsa->fpcr) - *pos, size);
  500. if (size <= 0)
  501. return -EFBIG;
  502. ret = spu_acquire_saved(ctx);
  503. if (ret)
  504. return ret;
  505. *pos += size;
  506. ret = copy_from_user((char *)&lscsa->fpcr + *pos - size,
  507. buffer, size) ? -EFAULT : size;
  508. spu_release_saved(ctx);
  509. return ret;
  510. }
  511. static const struct file_operations spufs_fpcr_fops = {
  512. .open = spufs_regs_open,
  513. .read = spufs_fpcr_read,
  514. .write = spufs_fpcr_write,
  515. .llseek = generic_file_llseek,
  516. };
  517. /* generic open function for all pipe-like files */
  518. static int spufs_pipe_open(struct inode *inode, struct file *file)
  519. {
  520. struct spufs_inode_info *i = SPUFS_I(inode);
  521. file->private_data = i->i_ctx;
  522. return nonseekable_open(inode, file);
  523. }
  524. /*
  525. * Read as many bytes from the mailbox as possible, until
  526. * one of the conditions becomes true:
  527. *
  528. * - no more data available in the mailbox
  529. * - end of the user provided buffer
  530. * - end of the mapped area
  531. */
  532. static ssize_t spufs_mbox_read(struct file *file, char __user *buf,
  533. size_t len, loff_t *pos)
  534. {
  535. struct spu_context *ctx = file->private_data;
  536. u32 mbox_data, __user *udata;
  537. ssize_t count;
  538. if (len < 4)
  539. return -EINVAL;
  540. if (!access_ok(VERIFY_WRITE, buf, len))
  541. return -EFAULT;
  542. udata = (void __user *)buf;
  543. count = spu_acquire(ctx);
  544. if (count)
  545. return count;
  546. for (count = 0; (count + 4) <= len; count += 4, udata++) {
  547. int ret;
  548. ret = ctx->ops->mbox_read(ctx, &mbox_data);
  549. if (ret == 0)
  550. break;
  551. /*
  552. * at the end of the mapped area, we can fault
  553. * but still need to return the data we have
  554. * read successfully so far.
  555. */
  556. ret = __put_user(mbox_data, udata);
  557. if (ret) {
  558. if (!count)
  559. count = -EFAULT;
  560. break;
  561. }
  562. }
  563. spu_release(ctx);
  564. if (!count)
  565. count = -EAGAIN;
  566. return count;
  567. }
  568. static const struct file_operations spufs_mbox_fops = {
  569. .open = spufs_pipe_open,
  570. .read = spufs_mbox_read,
  571. };
  572. static ssize_t spufs_mbox_stat_read(struct file *file, char __user *buf,
  573. size_t len, loff_t *pos)
  574. {
  575. struct spu_context *ctx = file->private_data;
  576. ssize_t ret;
  577. u32 mbox_stat;
  578. if (len < 4)
  579. return -EINVAL;
  580. ret = spu_acquire(ctx);
  581. if (ret)
  582. return ret;
  583. mbox_stat = ctx->ops->mbox_stat_read(ctx) & 0xff;
  584. spu_release(ctx);
  585. if (copy_to_user(buf, &mbox_stat, sizeof mbox_stat))
  586. return -EFAULT;
  587. return 4;
  588. }
  589. static const struct file_operations spufs_mbox_stat_fops = {
  590. .open = spufs_pipe_open,
  591. .read = spufs_mbox_stat_read,
  592. };
  593. /* low-level ibox access function */
  594. size_t spu_ibox_read(struct spu_context *ctx, u32 *data)
  595. {
  596. return ctx->ops->ibox_read(ctx, data);
  597. }
  598. static int spufs_ibox_fasync(int fd, struct file *file, int on)
  599. {
  600. struct spu_context *ctx = file->private_data;
  601. return fasync_helper(fd, file, on, &ctx->ibox_fasync);
  602. }
  603. /* interrupt-level ibox callback function. */
  604. void spufs_ibox_callback(struct spu *spu)
  605. {
  606. struct spu_context *ctx = spu->ctx;
  607. if (!ctx)
  608. return;
  609. wake_up_all(&ctx->ibox_wq);
  610. kill_fasync(&ctx->ibox_fasync, SIGIO, POLLIN);
  611. }
  612. /*
  613. * Read as many bytes from the interrupt mailbox as possible, until
  614. * one of the conditions becomes true:
  615. *
  616. * - no more data available in the mailbox
  617. * - end of the user provided buffer
  618. * - end of the mapped area
  619. *
  620. * If the file is opened without O_NONBLOCK, we wait here until
  621. * any data is available, but return when we have been able to
  622. * read something.
  623. */
  624. static ssize_t spufs_ibox_read(struct file *file, char __user *buf,
  625. size_t len, loff_t *pos)
  626. {
  627. struct spu_context *ctx = file->private_data;
  628. u32 ibox_data, __user *udata;
  629. ssize_t count;
  630. if (len < 4)
  631. return -EINVAL;
  632. if (!access_ok(VERIFY_WRITE, buf, len))
  633. return -EFAULT;
  634. udata = (void __user *)buf;
  635. count = spu_acquire(ctx);
  636. if (count)
  637. goto out;
  638. /* wait only for the first element */
  639. count = 0;
  640. if (file->f_flags & O_NONBLOCK) {
  641. if (!spu_ibox_read(ctx, &ibox_data)) {
  642. count = -EAGAIN;
  643. goto out_unlock;
  644. }
  645. } else {
  646. count = spufs_wait(ctx->ibox_wq, spu_ibox_read(ctx, &ibox_data));
  647. if (count)
  648. goto out;
  649. }
  650. /* if we can't write at all, return -EFAULT */
  651. count = __put_user(ibox_data, udata);
  652. if (count)
  653. goto out_unlock;
  654. for (count = 4, udata++; (count + 4) <= len; count += 4, udata++) {
  655. int ret;
  656. ret = ctx->ops->ibox_read(ctx, &ibox_data);
  657. if (ret == 0)
  658. break;
  659. /*
  660. * at the end of the mapped area, we can fault
  661. * but still need to return the data we have
  662. * read successfully so far.
  663. */
  664. ret = __put_user(ibox_data, udata);
  665. if (ret)
  666. break;
  667. }
  668. out_unlock:
  669. spu_release(ctx);
  670. out:
  671. return count;
  672. }
  673. static unsigned int spufs_ibox_poll(struct file *file, poll_table *wait)
  674. {
  675. struct spu_context *ctx = file->private_data;
  676. unsigned int mask;
  677. poll_wait(file, &ctx->ibox_wq, wait);
  678. /*
  679. * For now keep this uninterruptible and also ignore the rule
  680. * that poll should not sleep. Will be fixed later.
  681. */
  682. mutex_lock(&ctx->state_mutex);
  683. mask = ctx->ops->mbox_stat_poll(ctx, POLLIN | POLLRDNORM);
  684. spu_release(ctx);
  685. return mask;
  686. }
  687. static const struct file_operations spufs_ibox_fops = {
  688. .open = spufs_pipe_open,
  689. .read = spufs_ibox_read,
  690. .poll = spufs_ibox_poll,
  691. .fasync = spufs_ibox_fasync,
  692. };
  693. static ssize_t spufs_ibox_stat_read(struct file *file, char __user *buf,
  694. size_t len, loff_t *pos)
  695. {
  696. struct spu_context *ctx = file->private_data;
  697. ssize_t ret;
  698. u32 ibox_stat;
  699. if (len < 4)
  700. return -EINVAL;
  701. ret = spu_acquire(ctx);
  702. if (ret)
  703. return ret;
  704. ibox_stat = (ctx->ops->mbox_stat_read(ctx) >> 16) & 0xff;
  705. spu_release(ctx);
  706. if (copy_to_user(buf, &ibox_stat, sizeof ibox_stat))
  707. return -EFAULT;
  708. return 4;
  709. }
  710. static const struct file_operations spufs_ibox_stat_fops = {
  711. .open = spufs_pipe_open,
  712. .read = spufs_ibox_stat_read,
  713. };
  714. /* low-level mailbox write */
  715. size_t spu_wbox_write(struct spu_context *ctx, u32 data)
  716. {
  717. return ctx->ops->wbox_write(ctx, data);
  718. }
  719. static int spufs_wbox_fasync(int fd, struct file *file, int on)
  720. {
  721. struct spu_context *ctx = file->private_data;
  722. int ret;
  723. ret = fasync_helper(fd, file, on, &ctx->wbox_fasync);
  724. return ret;
  725. }
  726. /* interrupt-level wbox callback function. */
  727. void spufs_wbox_callback(struct spu *spu)
  728. {
  729. struct spu_context *ctx = spu->ctx;
  730. if (!ctx)
  731. return;
  732. wake_up_all(&ctx->wbox_wq);
  733. kill_fasync(&ctx->wbox_fasync, SIGIO, POLLOUT);
  734. }
  735. /*
  736. * Write as many bytes to the interrupt mailbox as possible, until
  737. * one of the conditions becomes true:
  738. *
  739. * - the mailbox is full
  740. * - end of the user provided buffer
  741. * - end of the mapped area
  742. *
  743. * If the file is opened without O_NONBLOCK, we wait here until
  744. * space is availabyl, but return when we have been able to
  745. * write something.
  746. */
  747. static ssize_t spufs_wbox_write(struct file *file, const char __user *buf,
  748. size_t len, loff_t *pos)
  749. {
  750. struct spu_context *ctx = file->private_data;
  751. u32 wbox_data, __user *udata;
  752. ssize_t count;
  753. if (len < 4)
  754. return -EINVAL;
  755. udata = (void __user *)buf;
  756. if (!access_ok(VERIFY_READ, buf, len))
  757. return -EFAULT;
  758. if (__get_user(wbox_data, udata))
  759. return -EFAULT;
  760. count = spu_acquire(ctx);
  761. if (count)
  762. goto out;
  763. /*
  764. * make sure we can at least write one element, by waiting
  765. * in case of !O_NONBLOCK
  766. */
  767. count = 0;
  768. if (file->f_flags & O_NONBLOCK) {
  769. if (!spu_wbox_write(ctx, wbox_data)) {
  770. count = -EAGAIN;
  771. goto out_unlock;
  772. }
  773. } else {
  774. count = spufs_wait(ctx->wbox_wq, spu_wbox_write(ctx, wbox_data));
  775. if (count)
  776. goto out;
  777. }
  778. /* write as much as possible */
  779. for (count = 4, udata++; (count + 4) <= len; count += 4, udata++) {
  780. int ret;
  781. ret = __get_user(wbox_data, udata);
  782. if (ret)
  783. break;
  784. ret = spu_wbox_write(ctx, wbox_data);
  785. if (ret == 0)
  786. break;
  787. }
  788. out_unlock:
  789. spu_release(ctx);
  790. out:
  791. return count;
  792. }
  793. static unsigned int spufs_wbox_poll(struct file *file, poll_table *wait)
  794. {
  795. struct spu_context *ctx = file->private_data;
  796. unsigned int mask;
  797. poll_wait(file, &ctx->wbox_wq, wait);
  798. /*
  799. * For now keep this uninterruptible and also ignore the rule
  800. * that poll should not sleep. Will be fixed later.
  801. */
  802. mutex_lock(&ctx->state_mutex);
  803. mask = ctx->ops->mbox_stat_poll(ctx, POLLOUT | POLLWRNORM);
  804. spu_release(ctx);
  805. return mask;
  806. }
  807. static const struct file_operations spufs_wbox_fops = {
  808. .open = spufs_pipe_open,
  809. .write = spufs_wbox_write,
  810. .poll = spufs_wbox_poll,
  811. .fasync = spufs_wbox_fasync,
  812. };
  813. static ssize_t spufs_wbox_stat_read(struct file *file, char __user *buf,
  814. size_t len, loff_t *pos)
  815. {
  816. struct spu_context *ctx = file->private_data;
  817. ssize_t ret;
  818. u32 wbox_stat;
  819. if (len < 4)
  820. return -EINVAL;
  821. ret = spu_acquire(ctx);
  822. if (ret)
  823. return ret;
  824. wbox_stat = (ctx->ops->mbox_stat_read(ctx) >> 8) & 0xff;
  825. spu_release(ctx);
  826. if (copy_to_user(buf, &wbox_stat, sizeof wbox_stat))
  827. return -EFAULT;
  828. return 4;
  829. }
  830. static const struct file_operations spufs_wbox_stat_fops = {
  831. .open = spufs_pipe_open,
  832. .read = spufs_wbox_stat_read,
  833. };
  834. static int spufs_signal1_open(struct inode *inode, struct file *file)
  835. {
  836. struct spufs_inode_info *i = SPUFS_I(inode);
  837. struct spu_context *ctx = i->i_ctx;
  838. mutex_lock(&ctx->mapping_lock);
  839. file->private_data = ctx;
  840. if (!i->i_openers++)
  841. ctx->signal1 = inode->i_mapping;
  842. mutex_unlock(&ctx->mapping_lock);
  843. return nonseekable_open(inode, file);
  844. }
  845. static int
  846. spufs_signal1_release(struct inode *inode, struct file *file)
  847. {
  848. struct spufs_inode_info *i = SPUFS_I(inode);
  849. struct spu_context *ctx = i->i_ctx;
  850. mutex_lock(&ctx->mapping_lock);
  851. if (!--i->i_openers)
  852. ctx->signal1 = NULL;
  853. mutex_unlock(&ctx->mapping_lock);
  854. return 0;
  855. }
  856. static ssize_t __spufs_signal1_read(struct spu_context *ctx, char __user *buf,
  857. size_t len, loff_t *pos)
  858. {
  859. int ret = 0;
  860. u32 data;
  861. if (len < 4)
  862. return -EINVAL;
  863. if (ctx->csa.spu_chnlcnt_RW[3]) {
  864. data = ctx->csa.spu_chnldata_RW[3];
  865. ret = 4;
  866. }
  867. if (!ret)
  868. goto out;
  869. if (copy_to_user(buf, &data, 4))
  870. return -EFAULT;
  871. out:
  872. return ret;
  873. }
  874. static ssize_t spufs_signal1_read(struct file *file, char __user *buf,
  875. size_t len, loff_t *pos)
  876. {
  877. int ret;
  878. struct spu_context *ctx = file->private_data;
  879. ret = spu_acquire_saved(ctx);
  880. if (ret)
  881. return ret;
  882. ret = __spufs_signal1_read(ctx, buf, len, pos);
  883. spu_release_saved(ctx);
  884. return ret;
  885. }
  886. static ssize_t spufs_signal1_write(struct file *file, const char __user *buf,
  887. size_t len, loff_t *pos)
  888. {
  889. struct spu_context *ctx;
  890. ssize_t ret;
  891. u32 data;
  892. ctx = file->private_data;
  893. if (len < 4)
  894. return -EINVAL;
  895. if (copy_from_user(&data, buf, 4))
  896. return -EFAULT;
  897. ret = spu_acquire(ctx);
  898. if (ret)
  899. return ret;
  900. ctx->ops->signal1_write(ctx, data);
  901. spu_release(ctx);
  902. return 4;
  903. }
  904. static unsigned long spufs_signal1_mmap_nopfn(struct vm_area_struct *vma,
  905. unsigned long address)
  906. {
  907. #if PAGE_SIZE == 0x1000
  908. return spufs_ps_nopfn(vma, address, 0x14000, 0x1000);
  909. #elif PAGE_SIZE == 0x10000
  910. /* For 64k pages, both signal1 and signal2 can be used to mmap the whole
  911. * signal 1 and 2 area
  912. */
  913. return spufs_ps_nopfn(vma, address, 0x10000, 0x10000);
  914. #else
  915. #error unsupported page size
  916. #endif
  917. }
  918. static struct vm_operations_struct spufs_signal1_mmap_vmops = {
  919. .nopfn = spufs_signal1_mmap_nopfn,
  920. };
  921. static int spufs_signal1_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_signal1_mmap_vmops;
  929. return 0;
  930. }
  931. static const struct file_operations spufs_signal1_fops = {
  932. .open = spufs_signal1_open,
  933. .release = spufs_signal1_release,
  934. .read = spufs_signal1_read,
  935. .write = spufs_signal1_write,
  936. .mmap = spufs_signal1_mmap,
  937. };
  938. static const struct file_operations spufs_signal1_nosched_fops = {
  939. .open = spufs_signal1_open,
  940. .release = spufs_signal1_release,
  941. .write = spufs_signal1_write,
  942. .mmap = spufs_signal1_mmap,
  943. };
  944. static int spufs_signal2_open(struct inode *inode, struct file *file)
  945. {
  946. struct spufs_inode_info *i = SPUFS_I(inode);
  947. struct spu_context *ctx = i->i_ctx;
  948. mutex_lock(&ctx->mapping_lock);
  949. file->private_data = ctx;
  950. if (!i->i_openers++)
  951. ctx->signal2 = inode->i_mapping;
  952. mutex_unlock(&ctx->mapping_lock);
  953. return nonseekable_open(inode, file);
  954. }
  955. static int
  956. spufs_signal2_release(struct inode *inode, struct file *file)
  957. {
  958. struct spufs_inode_info *i = SPUFS_I(inode);
  959. struct spu_context *ctx = i->i_ctx;
  960. mutex_lock(&ctx->mapping_lock);
  961. if (!--i->i_openers)
  962. ctx->signal2 = NULL;
  963. mutex_unlock(&ctx->mapping_lock);
  964. return 0;
  965. }
  966. static ssize_t __spufs_signal2_read(struct spu_context *ctx, char __user *buf,
  967. size_t len, loff_t *pos)
  968. {
  969. int ret = 0;
  970. u32 data;
  971. if (len < 4)
  972. return -EINVAL;
  973. if (ctx->csa.spu_chnlcnt_RW[4]) {
  974. data = ctx->csa.spu_chnldata_RW[4];
  975. ret = 4;
  976. }
  977. if (!ret)
  978. goto out;
  979. if (copy_to_user(buf, &data, 4))
  980. return -EFAULT;
  981. out:
  982. return ret;
  983. }
  984. static ssize_t spufs_signal2_read(struct file *file, char __user *buf,
  985. size_t len, loff_t *pos)
  986. {
  987. struct spu_context *ctx = file->private_data;
  988. int ret;
  989. ret = spu_acquire_saved(ctx);
  990. if (ret)
  991. return ret;
  992. ret = __spufs_signal2_read(ctx, buf, len, pos);
  993. spu_release_saved(ctx);
  994. return ret;
  995. }
  996. static ssize_t spufs_signal2_write(struct file *file, const char __user *buf,
  997. size_t len, loff_t *pos)
  998. {
  999. struct spu_context *ctx;
  1000. ssize_t ret;
  1001. u32 data;
  1002. ctx = file->private_data;
  1003. if (len < 4)
  1004. return -EINVAL;
  1005. if (copy_from_user(&data, buf, 4))
  1006. return -EFAULT;
  1007. ret = spu_acquire(ctx);
  1008. if (ret)
  1009. return ret;
  1010. ctx->ops->signal2_write(ctx, data);
  1011. spu_release(ctx);
  1012. return 4;
  1013. }
  1014. #if SPUFS_MMAP_4K
  1015. static unsigned long spufs_signal2_mmap_nopfn(struct vm_area_struct *vma,
  1016. unsigned long address)
  1017. {
  1018. #if PAGE_SIZE == 0x1000
  1019. return spufs_ps_nopfn(vma, address, 0x1c000, 0x1000);
  1020. #elif PAGE_SIZE == 0x10000
  1021. /* For 64k pages, both signal1 and signal2 can be used to mmap the whole
  1022. * signal 1 and 2 area
  1023. */
  1024. return spufs_ps_nopfn(vma, address, 0x10000, 0x10000);
  1025. #else
  1026. #error unsupported page size
  1027. #endif
  1028. }
  1029. static struct vm_operations_struct spufs_signal2_mmap_vmops = {
  1030. .nopfn = spufs_signal2_mmap_nopfn,
  1031. };
  1032. static int spufs_signal2_mmap(struct file *file, struct vm_area_struct *vma)
  1033. {
  1034. if (!(vma->vm_flags & VM_SHARED))
  1035. return -EINVAL;
  1036. vma->vm_flags |= VM_IO | VM_PFNMAP;
  1037. vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
  1038. | _PAGE_NO_CACHE | _PAGE_GUARDED);
  1039. vma->vm_ops = &spufs_signal2_mmap_vmops;
  1040. return 0;
  1041. }
  1042. #else /* SPUFS_MMAP_4K */
  1043. #define spufs_signal2_mmap NULL
  1044. #endif /* !SPUFS_MMAP_4K */
  1045. static const struct file_operations spufs_signal2_fops = {
  1046. .open = spufs_signal2_open,
  1047. .release = spufs_signal2_release,
  1048. .read = spufs_signal2_read,
  1049. .write = spufs_signal2_write,
  1050. .mmap = spufs_signal2_mmap,
  1051. };
  1052. static const struct file_operations spufs_signal2_nosched_fops = {
  1053. .open = spufs_signal2_open,
  1054. .release = spufs_signal2_release,
  1055. .write = spufs_signal2_write,
  1056. .mmap = spufs_signal2_mmap,
  1057. };
  1058. /*
  1059. * This is a wrapper around DEFINE_SIMPLE_ATTRIBUTE which does the
  1060. * work of acquiring (or not) the SPU context before calling through
  1061. * to the actual get routine. The set routine is called directly.
  1062. */
  1063. #define SPU_ATTR_NOACQUIRE 0
  1064. #define SPU_ATTR_ACQUIRE 1
  1065. #define SPU_ATTR_ACQUIRE_SAVED 2
  1066. #define DEFINE_SPUFS_ATTRIBUTE(__name, __get, __set, __fmt, __acquire) \
  1067. static int __##__get(void *data, u64 *val) \
  1068. { \
  1069. struct spu_context *ctx = data; \
  1070. int ret = 0; \
  1071. \
  1072. if (__acquire == SPU_ATTR_ACQUIRE) { \
  1073. ret = spu_acquire(ctx); \
  1074. if (ret) \
  1075. return ret; \
  1076. *val = __get(ctx); \
  1077. spu_release(ctx); \
  1078. } else if (__acquire == SPU_ATTR_ACQUIRE_SAVED) { \
  1079. ret = spu_acquire_saved(ctx); \
  1080. if (ret) \
  1081. return ret; \
  1082. *val = __get(ctx); \
  1083. spu_release_saved(ctx); \
  1084. } else \
  1085. *val = __get(ctx); \
  1086. \
  1087. return 0; \
  1088. } \
  1089. DEFINE_SPUFS_SIMPLE_ATTRIBUTE(__name, __##__get, __set, __fmt);
  1090. static int spufs_signal1_type_set(void *data, u64 val)
  1091. {
  1092. struct spu_context *ctx = data;
  1093. int ret;
  1094. ret = spu_acquire(ctx);
  1095. if (ret)
  1096. return ret;
  1097. ctx->ops->signal1_type_set(ctx, val);
  1098. spu_release(ctx);
  1099. return 0;
  1100. }
  1101. static u64 spufs_signal1_type_get(struct spu_context *ctx)
  1102. {
  1103. return ctx->ops->signal1_type_get(ctx);
  1104. }
  1105. DEFINE_SPUFS_ATTRIBUTE(spufs_signal1_type, spufs_signal1_type_get,
  1106. spufs_signal1_type_set, "%llu\n", SPU_ATTR_ACQUIRE);
  1107. static int spufs_signal2_type_set(void *data, u64 val)
  1108. {
  1109. struct spu_context *ctx = data;
  1110. int ret;
  1111. ret = spu_acquire(ctx);
  1112. if (ret)
  1113. return ret;
  1114. ctx->ops->signal2_type_set(ctx, val);
  1115. spu_release(ctx);
  1116. return 0;
  1117. }
  1118. static u64 spufs_signal2_type_get(struct spu_context *ctx)
  1119. {
  1120. return ctx->ops->signal2_type_get(ctx);
  1121. }
  1122. DEFINE_SPUFS_ATTRIBUTE(spufs_signal2_type, spufs_signal2_type_get,
  1123. spufs_signal2_type_set, "%llu\n", SPU_ATTR_ACQUIRE);
  1124. #if SPUFS_MMAP_4K
  1125. static unsigned long spufs_mss_mmap_nopfn(struct vm_area_struct *vma,
  1126. unsigned long address)
  1127. {
  1128. return spufs_ps_nopfn(vma, address, 0x0000, 0x1000);
  1129. }
  1130. static struct vm_operations_struct spufs_mss_mmap_vmops = {
  1131. .nopfn = spufs_mss_mmap_nopfn,
  1132. };
  1133. /*
  1134. * mmap support for problem state MFC DMA area [0x0000 - 0x0fff].
  1135. */
  1136. static int spufs_mss_mmap(struct file *file, struct vm_area_struct *vma)
  1137. {
  1138. if (!(vma->vm_flags & VM_SHARED))
  1139. return -EINVAL;
  1140. vma->vm_flags |= VM_IO | VM_PFNMAP;
  1141. vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
  1142. | _PAGE_NO_CACHE | _PAGE_GUARDED);
  1143. vma->vm_ops = &spufs_mss_mmap_vmops;
  1144. return 0;
  1145. }
  1146. #else /* SPUFS_MMAP_4K */
  1147. #define spufs_mss_mmap NULL
  1148. #endif /* !SPUFS_MMAP_4K */
  1149. static int spufs_mss_open(struct inode *inode, struct file *file)
  1150. {
  1151. struct spufs_inode_info *i = SPUFS_I(inode);
  1152. struct spu_context *ctx = i->i_ctx;
  1153. file->private_data = i->i_ctx;
  1154. mutex_lock(&ctx->mapping_lock);
  1155. if (!i->i_openers++)
  1156. ctx->mss = inode->i_mapping;
  1157. mutex_unlock(&ctx->mapping_lock);
  1158. return nonseekable_open(inode, file);
  1159. }
  1160. static int
  1161. spufs_mss_release(struct inode *inode, struct file *file)
  1162. {
  1163. struct spufs_inode_info *i = SPUFS_I(inode);
  1164. struct spu_context *ctx = i->i_ctx;
  1165. mutex_lock(&ctx->mapping_lock);
  1166. if (!--i->i_openers)
  1167. ctx->mss = NULL;
  1168. mutex_unlock(&ctx->mapping_lock);
  1169. return 0;
  1170. }
  1171. static const struct file_operations spufs_mss_fops = {
  1172. .open = spufs_mss_open,
  1173. .release = spufs_mss_release,
  1174. .mmap = spufs_mss_mmap,
  1175. };
  1176. static unsigned long spufs_psmap_mmap_nopfn(struct vm_area_struct *vma,
  1177. unsigned long address)
  1178. {
  1179. return spufs_ps_nopfn(vma, address, 0x0000, 0x20000);
  1180. }
  1181. static struct vm_operations_struct spufs_psmap_mmap_vmops = {
  1182. .nopfn = spufs_psmap_mmap_nopfn,
  1183. };
  1184. /*
  1185. * mmap support for full problem state area [0x00000 - 0x1ffff].
  1186. */
  1187. static int spufs_psmap_mmap(struct file *file, struct vm_area_struct *vma)
  1188. {
  1189. if (!(vma->vm_flags & VM_SHARED))
  1190. return -EINVAL;
  1191. vma->vm_flags |= VM_IO | VM_PFNMAP;
  1192. vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
  1193. | _PAGE_NO_CACHE | _PAGE_GUARDED);
  1194. vma->vm_ops = &spufs_psmap_mmap_vmops;
  1195. return 0;
  1196. }
  1197. static int spufs_psmap_open(struct inode *inode, struct file *file)
  1198. {
  1199. struct spufs_inode_info *i = SPUFS_I(inode);
  1200. struct spu_context *ctx = i->i_ctx;
  1201. mutex_lock(&ctx->mapping_lock);
  1202. file->private_data = i->i_ctx;
  1203. if (!i->i_openers++)
  1204. ctx->psmap = inode->i_mapping;
  1205. mutex_unlock(&ctx->mapping_lock);
  1206. return nonseekable_open(inode, file);
  1207. }
  1208. static int
  1209. spufs_psmap_release(struct inode *inode, struct file *file)
  1210. {
  1211. struct spufs_inode_info *i = SPUFS_I(inode);
  1212. struct spu_context *ctx = i->i_ctx;
  1213. mutex_lock(&ctx->mapping_lock);
  1214. if (!--i->i_openers)
  1215. ctx->psmap = NULL;
  1216. mutex_unlock(&ctx->mapping_lock);
  1217. return 0;
  1218. }
  1219. static const struct file_operations spufs_psmap_fops = {
  1220. .open = spufs_psmap_open,
  1221. .release = spufs_psmap_release,
  1222. .mmap = spufs_psmap_mmap,
  1223. };
  1224. #if SPUFS_MMAP_4K
  1225. static unsigned long spufs_mfc_mmap_nopfn(struct vm_area_struct *vma,
  1226. unsigned long address)
  1227. {
  1228. return spufs_ps_nopfn(vma, address, 0x3000, 0x1000);
  1229. }
  1230. static struct vm_operations_struct spufs_mfc_mmap_vmops = {
  1231. .nopfn = spufs_mfc_mmap_nopfn,
  1232. };
  1233. /*
  1234. * mmap support for problem state MFC DMA area [0x0000 - 0x0fff].
  1235. */
  1236. static int spufs_mfc_mmap(struct file *file, struct vm_area_struct *vma)
  1237. {
  1238. if (!(vma->vm_flags & VM_SHARED))
  1239. return -EINVAL;
  1240. vma->vm_flags |= VM_IO | VM_PFNMAP;
  1241. vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
  1242. | _PAGE_NO_CACHE | _PAGE_GUARDED);
  1243. vma->vm_ops = &spufs_mfc_mmap_vmops;
  1244. return 0;
  1245. }
  1246. #else /* SPUFS_MMAP_4K */
  1247. #define spufs_mfc_mmap NULL
  1248. #endif /* !SPUFS_MMAP_4K */
  1249. static int spufs_mfc_open(struct inode *inode, struct file *file)
  1250. {
  1251. struct spufs_inode_info *i = SPUFS_I(inode);
  1252. struct spu_context *ctx = i->i_ctx;
  1253. /* we don't want to deal with DMA into other processes */
  1254. if (ctx->owner != current->mm)
  1255. return -EINVAL;
  1256. if (atomic_read(&inode->i_count) != 1)
  1257. return -EBUSY;
  1258. mutex_lock(&ctx->mapping_lock);
  1259. file->private_data = ctx;
  1260. if (!i->i_openers++)
  1261. ctx->mfc = inode->i_mapping;
  1262. mutex_unlock(&ctx->mapping_lock);
  1263. return nonseekable_open(inode, file);
  1264. }
  1265. static int
  1266. spufs_mfc_release(struct inode *inode, struct file *file)
  1267. {
  1268. struct spufs_inode_info *i = SPUFS_I(inode);
  1269. struct spu_context *ctx = i->i_ctx;
  1270. mutex_lock(&ctx->mapping_lock);
  1271. if (!--i->i_openers)
  1272. ctx->mfc = NULL;
  1273. mutex_unlock(&ctx->mapping_lock);
  1274. return 0;
  1275. }
  1276. /* interrupt-level mfc callback function. */
  1277. void spufs_mfc_callback(struct spu *spu)
  1278. {
  1279. struct spu_context *ctx = spu->ctx;
  1280. if (!ctx)
  1281. return;
  1282. wake_up_all(&ctx->mfc_wq);
  1283. pr_debug("%s %s\n", __func__, spu->name);
  1284. if (ctx->mfc_fasync) {
  1285. u32 free_elements, tagstatus;
  1286. unsigned int mask;
  1287. /* no need for spu_acquire in interrupt context */
  1288. free_elements = ctx->ops->get_mfc_free_elements(ctx);
  1289. tagstatus = ctx->ops->read_mfc_tagstatus(ctx);
  1290. mask = 0;
  1291. if (free_elements & 0xffff)
  1292. mask |= POLLOUT;
  1293. if (tagstatus & ctx->tagwait)
  1294. mask |= POLLIN;
  1295. kill_fasync(&ctx->mfc_fasync, SIGIO, mask);
  1296. }
  1297. }
  1298. static int spufs_read_mfc_tagstatus(struct spu_context *ctx, u32 *status)
  1299. {
  1300. /* See if there is one tag group is complete */
  1301. /* FIXME we need locking around tagwait */
  1302. *status = ctx->ops->read_mfc_tagstatus(ctx) & ctx->tagwait;
  1303. ctx->tagwait &= ~*status;
  1304. if (*status)
  1305. return 1;
  1306. /* enable interrupt waiting for any tag group,
  1307. may silently fail if interrupts are already enabled */
  1308. ctx->ops->set_mfc_query(ctx, ctx->tagwait, 1);
  1309. return 0;
  1310. }
  1311. static ssize_t spufs_mfc_read(struct file *file, char __user *buffer,
  1312. size_t size, loff_t *pos)
  1313. {
  1314. struct spu_context *ctx = file->private_data;
  1315. int ret = -EINVAL;
  1316. u32 status;
  1317. if (size != 4)
  1318. goto out;
  1319. ret = spu_acquire(ctx);
  1320. if (ret)
  1321. return ret;
  1322. ret = -EINVAL;
  1323. if (file->f_flags & O_NONBLOCK) {
  1324. status = ctx->ops->read_mfc_tagstatus(ctx);
  1325. if (!(status & ctx->tagwait))
  1326. ret = -EAGAIN;
  1327. else
  1328. /* XXX(hch): shouldn't we clear ret here? */
  1329. ctx->tagwait &= ~status;
  1330. } else {
  1331. ret = spufs_wait(ctx->mfc_wq,
  1332. spufs_read_mfc_tagstatus(ctx, &status));
  1333. if (ret)
  1334. goto out;
  1335. }
  1336. spu_release(ctx);
  1337. ret = 4;
  1338. if (copy_to_user(buffer, &status, 4))
  1339. ret = -EFAULT;
  1340. out:
  1341. return ret;
  1342. }
  1343. static int spufs_check_valid_dma(struct mfc_dma_command *cmd)
  1344. {
  1345. pr_debug("queueing DMA %x %lx %x %x %x\n", cmd->lsa,
  1346. cmd->ea, cmd->size, cmd->tag, cmd->cmd);
  1347. switch (cmd->cmd) {
  1348. case MFC_PUT_CMD:
  1349. case MFC_PUTF_CMD:
  1350. case MFC_PUTB_CMD:
  1351. case MFC_GET_CMD:
  1352. case MFC_GETF_CMD:
  1353. case MFC_GETB_CMD:
  1354. break;
  1355. default:
  1356. pr_debug("invalid DMA opcode %x\n", cmd->cmd);
  1357. return -EIO;
  1358. }
  1359. if ((cmd->lsa & 0xf) != (cmd->ea &0xf)) {
  1360. pr_debug("invalid DMA alignment, ea %lx lsa %x\n",
  1361. cmd->ea, cmd->lsa);
  1362. return -EIO;
  1363. }
  1364. switch (cmd->size & 0xf) {
  1365. case 1:
  1366. break;
  1367. case 2:
  1368. if (cmd->lsa & 1)
  1369. goto error;
  1370. break;
  1371. case 4:
  1372. if (cmd->lsa & 3)
  1373. goto error;
  1374. break;
  1375. case 8:
  1376. if (cmd->lsa & 7)
  1377. goto error;
  1378. break;
  1379. case 0:
  1380. if (cmd->lsa & 15)
  1381. goto error;
  1382. break;
  1383. error:
  1384. default:
  1385. pr_debug("invalid DMA alignment %x for size %x\n",
  1386. cmd->lsa & 0xf, cmd->size);
  1387. return -EIO;
  1388. }
  1389. if (cmd->size > 16 * 1024) {
  1390. pr_debug("invalid DMA size %x\n", cmd->size);
  1391. return -EIO;
  1392. }
  1393. if (cmd->tag & 0xfff0) {
  1394. /* we reserve the higher tag numbers for kernel use */
  1395. pr_debug("invalid DMA tag\n");
  1396. return -EIO;
  1397. }
  1398. if (cmd->class) {
  1399. /* not supported in this version */
  1400. pr_debug("invalid DMA class\n");
  1401. return -EIO;
  1402. }
  1403. return 0;
  1404. }
  1405. static int spu_send_mfc_command(struct spu_context *ctx,
  1406. struct mfc_dma_command cmd,
  1407. int *error)
  1408. {
  1409. *error = ctx->ops->send_mfc_command(ctx, &cmd);
  1410. if (*error == -EAGAIN) {
  1411. /* wait for any tag group to complete
  1412. so we have space for the new command */
  1413. ctx->ops->set_mfc_query(ctx, ctx->tagwait, 1);
  1414. /* try again, because the queue might be
  1415. empty again */
  1416. *error = ctx->ops->send_mfc_command(ctx, &cmd);
  1417. if (*error == -EAGAIN)
  1418. return 0;
  1419. }
  1420. return 1;
  1421. }
  1422. static ssize_t spufs_mfc_write(struct file *file, const char __user *buffer,
  1423. size_t size, loff_t *pos)
  1424. {
  1425. struct spu_context *ctx = file->private_data;
  1426. struct mfc_dma_command cmd;
  1427. int ret = -EINVAL;
  1428. if (size != sizeof cmd)
  1429. goto out;
  1430. ret = -EFAULT;
  1431. if (copy_from_user(&cmd, buffer, sizeof cmd))
  1432. goto out;
  1433. ret = spufs_check_valid_dma(&cmd);
  1434. if (ret)
  1435. goto out;
  1436. ret = spu_acquire(ctx);
  1437. if (ret)
  1438. goto out;
  1439. ret = spufs_wait(ctx->run_wq, ctx->state == SPU_STATE_RUNNABLE);
  1440. if (ret)
  1441. goto out;
  1442. if (file->f_flags & O_NONBLOCK) {
  1443. ret = ctx->ops->send_mfc_command(ctx, &cmd);
  1444. } else {
  1445. int status;
  1446. ret = spufs_wait(ctx->mfc_wq,
  1447. spu_send_mfc_command(ctx, cmd, &status));
  1448. if (ret)
  1449. goto out;
  1450. if (status)
  1451. ret = status;
  1452. }
  1453. if (ret)
  1454. goto out_unlock;
  1455. ctx->tagwait |= 1 << cmd.tag;
  1456. ret = size;
  1457. out_unlock:
  1458. spu_release(ctx);
  1459. out:
  1460. return ret;
  1461. }
  1462. static unsigned int spufs_mfc_poll(struct file *file,poll_table *wait)
  1463. {
  1464. struct spu_context *ctx = file->private_data;
  1465. u32 free_elements, tagstatus;
  1466. unsigned int mask;
  1467. poll_wait(file, &ctx->mfc_wq, wait);
  1468. /*
  1469. * For now keep this uninterruptible and also ignore the rule
  1470. * that poll should not sleep. Will be fixed later.
  1471. */
  1472. mutex_lock(&ctx->state_mutex);
  1473. ctx->ops->set_mfc_query(ctx, ctx->tagwait, 2);
  1474. free_elements = ctx->ops->get_mfc_free_elements(ctx);
  1475. tagstatus = ctx->ops->read_mfc_tagstatus(ctx);
  1476. spu_release(ctx);
  1477. mask = 0;
  1478. if (free_elements & 0xffff)
  1479. mask |= POLLOUT | POLLWRNORM;
  1480. if (tagstatus & ctx->tagwait)
  1481. mask |= POLLIN | POLLRDNORM;
  1482. pr_debug("%s: free %d tagstatus %d tagwait %d\n", __func__,
  1483. free_elements, tagstatus, ctx->tagwait);
  1484. return mask;
  1485. }
  1486. static int spufs_mfc_flush(struct file *file, fl_owner_t id)
  1487. {
  1488. struct spu_context *ctx = file->private_data;
  1489. int ret;
  1490. ret = spu_acquire(ctx);
  1491. if (ret)
  1492. goto out;
  1493. #if 0
  1494. /* this currently hangs */
  1495. ret = spufs_wait(ctx->mfc_wq,
  1496. ctx->ops->set_mfc_query(ctx, ctx->tagwait, 2));
  1497. if (ret)
  1498. goto out;
  1499. ret = spufs_wait(ctx->mfc_wq,
  1500. ctx->ops->read_mfc_tagstatus(ctx) == ctx->tagwait);
  1501. if (ret)
  1502. goto out;
  1503. #else
  1504. ret = 0;
  1505. #endif
  1506. spu_release(ctx);
  1507. out:
  1508. return ret;
  1509. }
  1510. static int spufs_mfc_fsync(struct file *file, struct dentry *dentry,
  1511. int datasync)
  1512. {
  1513. return spufs_mfc_flush(file, NULL);
  1514. }
  1515. static int spufs_mfc_fasync(int fd, struct file *file, int on)
  1516. {
  1517. struct spu_context *ctx = file->private_data;
  1518. return fasync_helper(fd, file, on, &ctx->mfc_fasync);
  1519. }
  1520. static const struct file_operations spufs_mfc_fops = {
  1521. .open = spufs_mfc_open,
  1522. .release = spufs_mfc_release,
  1523. .read = spufs_mfc_read,
  1524. .write = spufs_mfc_write,
  1525. .poll = spufs_mfc_poll,
  1526. .flush = spufs_mfc_flush,
  1527. .fsync = spufs_mfc_fsync,
  1528. .fasync = spufs_mfc_fasync,
  1529. .mmap = spufs_mfc_mmap,
  1530. };
  1531. static int spufs_npc_set(void *data, u64 val)
  1532. {
  1533. struct spu_context *ctx = data;
  1534. int ret;
  1535. ret = spu_acquire(ctx);
  1536. if (ret)
  1537. return ret;
  1538. ctx->ops->npc_write(ctx, val);
  1539. spu_release(ctx);
  1540. return 0;
  1541. }
  1542. static u64 spufs_npc_get(struct spu_context *ctx)
  1543. {
  1544. return ctx->ops->npc_read(ctx);
  1545. }
  1546. DEFINE_SPUFS_ATTRIBUTE(spufs_npc_ops, spufs_npc_get, spufs_npc_set,
  1547. "0x%llx\n", SPU_ATTR_ACQUIRE);
  1548. static int spufs_decr_set(void *data, u64 val)
  1549. {
  1550. struct spu_context *ctx = data;
  1551. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  1552. int ret;
  1553. ret = spu_acquire_saved(ctx);
  1554. if (ret)
  1555. return ret;
  1556. lscsa->decr.slot[0] = (u32) val;
  1557. spu_release_saved(ctx);
  1558. return 0;
  1559. }
  1560. static u64 spufs_decr_get(struct spu_context *ctx)
  1561. {
  1562. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  1563. return lscsa->decr.slot[0];
  1564. }
  1565. DEFINE_SPUFS_ATTRIBUTE(spufs_decr_ops, spufs_decr_get, spufs_decr_set,
  1566. "0x%llx\n", SPU_ATTR_ACQUIRE_SAVED);
  1567. static int spufs_decr_status_set(void *data, u64 val)
  1568. {
  1569. struct spu_context *ctx = data;
  1570. int ret;
  1571. ret = spu_acquire_saved(ctx);
  1572. if (ret)
  1573. return ret;
  1574. if (val)
  1575. ctx->csa.priv2.mfc_control_RW |= MFC_CNTL_DECREMENTER_RUNNING;
  1576. else
  1577. ctx->csa.priv2.mfc_control_RW &= ~MFC_CNTL_DECREMENTER_RUNNING;
  1578. spu_release_saved(ctx);
  1579. return 0;
  1580. }
  1581. static u64 spufs_decr_status_get(struct spu_context *ctx)
  1582. {
  1583. if (ctx->csa.priv2.mfc_control_RW & MFC_CNTL_DECREMENTER_RUNNING)
  1584. return SPU_DECR_STATUS_RUNNING;
  1585. else
  1586. return 0;
  1587. }
  1588. DEFINE_SPUFS_ATTRIBUTE(spufs_decr_status_ops, spufs_decr_status_get,
  1589. spufs_decr_status_set, "0x%llx\n",
  1590. SPU_ATTR_ACQUIRE_SAVED);
  1591. static int spufs_event_mask_set(void *data, u64 val)
  1592. {
  1593. struct spu_context *ctx = data;
  1594. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  1595. int ret;
  1596. ret = spu_acquire_saved(ctx);
  1597. if (ret)
  1598. return ret;
  1599. lscsa->event_mask.slot[0] = (u32) val;
  1600. spu_release_saved(ctx);
  1601. return 0;
  1602. }
  1603. static u64 spufs_event_mask_get(struct spu_context *ctx)
  1604. {
  1605. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  1606. return lscsa->event_mask.slot[0];
  1607. }
  1608. DEFINE_SPUFS_ATTRIBUTE(spufs_event_mask_ops, spufs_event_mask_get,
  1609. spufs_event_mask_set, "0x%llx\n",
  1610. SPU_ATTR_ACQUIRE_SAVED);
  1611. static u64 spufs_event_status_get(struct spu_context *ctx)
  1612. {
  1613. struct spu_state *state = &ctx->csa;
  1614. u64 stat;
  1615. stat = state->spu_chnlcnt_RW[0];
  1616. if (stat)
  1617. return state->spu_chnldata_RW[0];
  1618. return 0;
  1619. }
  1620. DEFINE_SPUFS_ATTRIBUTE(spufs_event_status_ops, spufs_event_status_get,
  1621. NULL, "0x%llx\n", SPU_ATTR_ACQUIRE_SAVED)
  1622. static int spufs_srr0_set(void *data, u64 val)
  1623. {
  1624. struct spu_context *ctx = data;
  1625. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  1626. int ret;
  1627. ret = spu_acquire_saved(ctx);
  1628. if (ret)
  1629. return ret;
  1630. lscsa->srr0.slot[0] = (u32) val;
  1631. spu_release_saved(ctx);
  1632. return 0;
  1633. }
  1634. static u64 spufs_srr0_get(struct spu_context *ctx)
  1635. {
  1636. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  1637. return lscsa->srr0.slot[0];
  1638. }
  1639. DEFINE_SPUFS_ATTRIBUTE(spufs_srr0_ops, spufs_srr0_get, spufs_srr0_set,
  1640. "0x%llx\n", SPU_ATTR_ACQUIRE_SAVED)
  1641. static u64 spufs_id_get(struct spu_context *ctx)
  1642. {
  1643. u64 num;
  1644. if (ctx->state == SPU_STATE_RUNNABLE)
  1645. num = ctx->spu->number;
  1646. else
  1647. num = (unsigned int)-1;
  1648. return num;
  1649. }
  1650. DEFINE_SPUFS_ATTRIBUTE(spufs_id_ops, spufs_id_get, NULL, "0x%llx\n",
  1651. SPU_ATTR_ACQUIRE)
  1652. static u64 spufs_object_id_get(struct spu_context *ctx)
  1653. {
  1654. /* FIXME: Should there really be no locking here? */
  1655. return ctx->object_id;
  1656. }
  1657. static int spufs_object_id_set(void *data, u64 id)
  1658. {
  1659. struct spu_context *ctx = data;
  1660. ctx->object_id = id;
  1661. return 0;
  1662. }
  1663. DEFINE_SPUFS_ATTRIBUTE(spufs_object_id_ops, spufs_object_id_get,
  1664. spufs_object_id_set, "0x%llx\n", SPU_ATTR_NOACQUIRE);
  1665. static u64 spufs_lslr_get(struct spu_context *ctx)
  1666. {
  1667. return ctx->csa.priv2.spu_lslr_RW;
  1668. }
  1669. DEFINE_SPUFS_ATTRIBUTE(spufs_lslr_ops, spufs_lslr_get, NULL, "0x%llx\n",
  1670. SPU_ATTR_ACQUIRE_SAVED);
  1671. static int spufs_info_open(struct inode *inode, struct file *file)
  1672. {
  1673. struct spufs_inode_info *i = SPUFS_I(inode);
  1674. struct spu_context *ctx = i->i_ctx;
  1675. file->private_data = ctx;
  1676. return 0;
  1677. }
  1678. static int spufs_caps_show(struct seq_file *s, void *private)
  1679. {
  1680. struct spu_context *ctx = s->private;
  1681. if (!(ctx->flags & SPU_CREATE_NOSCHED))
  1682. seq_puts(s, "sched\n");
  1683. if (!(ctx->flags & SPU_CREATE_ISOLATE))
  1684. seq_puts(s, "step\n");
  1685. return 0;
  1686. }
  1687. static int spufs_caps_open(struct inode *inode, struct file *file)
  1688. {
  1689. return single_open(file, spufs_caps_show, SPUFS_I(inode)->i_ctx);
  1690. }
  1691. static const struct file_operations spufs_caps_fops = {
  1692. .open = spufs_caps_open,
  1693. .read = seq_read,
  1694. .llseek = seq_lseek,
  1695. .release = single_release,
  1696. };
  1697. static ssize_t __spufs_mbox_info_read(struct spu_context *ctx,
  1698. char __user *buf, size_t len, loff_t *pos)
  1699. {
  1700. u32 data;
  1701. /* EOF if there's no entry in the mbox */
  1702. if (!(ctx->csa.prob.mb_stat_R & 0x0000ff))
  1703. return 0;
  1704. data = ctx->csa.prob.pu_mb_R;
  1705. return simple_read_from_buffer(buf, len, pos, &data, sizeof data);
  1706. }
  1707. static ssize_t spufs_mbox_info_read(struct file *file, char __user *buf,
  1708. size_t len, loff_t *pos)
  1709. {
  1710. int ret;
  1711. struct spu_context *ctx = file->private_data;
  1712. if (!access_ok(VERIFY_WRITE, buf, len))
  1713. return -EFAULT;
  1714. ret = spu_acquire_saved(ctx);
  1715. if (ret)
  1716. return ret;
  1717. spin_lock(&ctx->csa.register_lock);
  1718. ret = __spufs_mbox_info_read(ctx, buf, len, pos);
  1719. spin_unlock(&ctx->csa.register_lock);
  1720. spu_release_saved(ctx);
  1721. return ret;
  1722. }
  1723. static const struct file_operations spufs_mbox_info_fops = {
  1724. .open = spufs_info_open,
  1725. .read = spufs_mbox_info_read,
  1726. .llseek = generic_file_llseek,
  1727. };
  1728. static ssize_t __spufs_ibox_info_read(struct spu_context *ctx,
  1729. char __user *buf, size_t len, loff_t *pos)
  1730. {
  1731. u32 data;
  1732. /* EOF if there's no entry in the ibox */
  1733. if (!(ctx->csa.prob.mb_stat_R & 0xff0000))
  1734. return 0;
  1735. data = ctx->csa.priv2.puint_mb_R;
  1736. return simple_read_from_buffer(buf, len, pos, &data, sizeof data);
  1737. }
  1738. static ssize_t spufs_ibox_info_read(struct file *file, char __user *buf,
  1739. size_t len, loff_t *pos)
  1740. {
  1741. struct spu_context *ctx = file->private_data;
  1742. int ret;
  1743. if (!access_ok(VERIFY_WRITE, buf, len))
  1744. return -EFAULT;
  1745. ret = spu_acquire_saved(ctx);
  1746. if (ret)
  1747. return ret;
  1748. spin_lock(&ctx->csa.register_lock);
  1749. ret = __spufs_ibox_info_read(ctx, buf, len, pos);
  1750. spin_unlock(&ctx->csa.register_lock);
  1751. spu_release_saved(ctx);
  1752. return ret;
  1753. }
  1754. static const struct file_operations spufs_ibox_info_fops = {
  1755. .open = spufs_info_open,
  1756. .read = spufs_ibox_info_read,
  1757. .llseek = generic_file_llseek,
  1758. };
  1759. static ssize_t __spufs_wbox_info_read(struct spu_context *ctx,
  1760. char __user *buf, size_t len, loff_t *pos)
  1761. {
  1762. int i, cnt;
  1763. u32 data[4];
  1764. u32 wbox_stat;
  1765. wbox_stat = ctx->csa.prob.mb_stat_R;
  1766. cnt = 4 - ((wbox_stat & 0x00ff00) >> 8);
  1767. for (i = 0; i < cnt; i++) {
  1768. data[i] = ctx->csa.spu_mailbox_data[i];
  1769. }
  1770. return simple_read_from_buffer(buf, len, pos, &data,
  1771. cnt * sizeof(u32));
  1772. }
  1773. static ssize_t spufs_wbox_info_read(struct file *file, char __user *buf,
  1774. size_t len, loff_t *pos)
  1775. {
  1776. struct spu_context *ctx = file->private_data;
  1777. int ret;
  1778. if (!access_ok(VERIFY_WRITE, buf, len))
  1779. return -EFAULT;
  1780. ret = spu_acquire_saved(ctx);
  1781. if (ret)
  1782. return ret;
  1783. spin_lock(&ctx->csa.register_lock);
  1784. ret = __spufs_wbox_info_read(ctx, buf, len, pos);
  1785. spin_unlock(&ctx->csa.register_lock);
  1786. spu_release_saved(ctx);
  1787. return ret;
  1788. }
  1789. static const struct file_operations spufs_wbox_info_fops = {
  1790. .open = spufs_info_open,
  1791. .read = spufs_wbox_info_read,
  1792. .llseek = generic_file_llseek,
  1793. };
  1794. static ssize_t __spufs_dma_info_read(struct spu_context *ctx,
  1795. char __user *buf, size_t len, loff_t *pos)
  1796. {
  1797. struct spu_dma_info info;
  1798. struct mfc_cq_sr *qp, *spuqp;
  1799. int i;
  1800. info.dma_info_type = ctx->csa.priv2.spu_tag_status_query_RW;
  1801. info.dma_info_mask = ctx->csa.lscsa->tag_mask.slot[0];
  1802. info.dma_info_status = ctx->csa.spu_chnldata_RW[24];
  1803. info.dma_info_stall_and_notify = ctx->csa.spu_chnldata_RW[25];
  1804. info.dma_info_atomic_command_status = ctx->csa.spu_chnldata_RW[27];
  1805. for (i = 0; i < 16; i++) {
  1806. qp = &info.dma_info_command_data[i];
  1807. spuqp = &ctx->csa.priv2.spuq[i];
  1808. qp->mfc_cq_data0_RW = spuqp->mfc_cq_data0_RW;
  1809. qp->mfc_cq_data1_RW = spuqp->mfc_cq_data1_RW;
  1810. qp->mfc_cq_data2_RW = spuqp->mfc_cq_data2_RW;
  1811. qp->mfc_cq_data3_RW = spuqp->mfc_cq_data3_RW;
  1812. }
  1813. return simple_read_from_buffer(buf, len, pos, &info,
  1814. sizeof info);
  1815. }
  1816. static ssize_t spufs_dma_info_read(struct file *file, char __user *buf,
  1817. size_t len, loff_t *pos)
  1818. {
  1819. struct spu_context *ctx = file->private_data;
  1820. int ret;
  1821. if (!access_ok(VERIFY_WRITE, buf, len))
  1822. return -EFAULT;
  1823. ret = spu_acquire_saved(ctx);
  1824. if (ret)
  1825. return ret;
  1826. spin_lock(&ctx->csa.register_lock);
  1827. ret = __spufs_dma_info_read(ctx, buf, len, pos);
  1828. spin_unlock(&ctx->csa.register_lock);
  1829. spu_release_saved(ctx);
  1830. return ret;
  1831. }
  1832. static const struct file_operations spufs_dma_info_fops = {
  1833. .open = spufs_info_open,
  1834. .read = spufs_dma_info_read,
  1835. };
  1836. static ssize_t __spufs_proxydma_info_read(struct spu_context *ctx,
  1837. char __user *buf, size_t len, loff_t *pos)
  1838. {
  1839. struct spu_proxydma_info info;
  1840. struct mfc_cq_sr *qp, *puqp;
  1841. int ret = sizeof info;
  1842. int i;
  1843. if (len < ret)
  1844. return -EINVAL;
  1845. if (!access_ok(VERIFY_WRITE, buf, len))
  1846. return -EFAULT;
  1847. info.proxydma_info_type = ctx->csa.prob.dma_querytype_RW;
  1848. info.proxydma_info_mask = ctx->csa.prob.dma_querymask_RW;
  1849. info.proxydma_info_status = ctx->csa.prob.dma_tagstatus_R;
  1850. for (i = 0; i < 8; i++) {
  1851. qp = &info.proxydma_info_command_data[i];
  1852. puqp = &ctx->csa.priv2.puq[i];
  1853. qp->mfc_cq_data0_RW = puqp->mfc_cq_data0_RW;
  1854. qp->mfc_cq_data1_RW = puqp->mfc_cq_data1_RW;
  1855. qp->mfc_cq_data2_RW = puqp->mfc_cq_data2_RW;
  1856. qp->mfc_cq_data3_RW = puqp->mfc_cq_data3_RW;
  1857. }
  1858. return simple_read_from_buffer(buf, len, pos, &info,
  1859. sizeof info);
  1860. }
  1861. static ssize_t spufs_proxydma_info_read(struct file *file, char __user *buf,
  1862. size_t len, loff_t *pos)
  1863. {
  1864. struct spu_context *ctx = file->private_data;
  1865. int ret;
  1866. ret = spu_acquire_saved(ctx);
  1867. if (ret)
  1868. return ret;
  1869. spin_lock(&ctx->csa.register_lock);
  1870. ret = __spufs_proxydma_info_read(ctx, buf, len, pos);
  1871. spin_unlock(&ctx->csa.register_lock);
  1872. spu_release_saved(ctx);
  1873. return ret;
  1874. }
  1875. static const struct file_operations spufs_proxydma_info_fops = {
  1876. .open = spufs_info_open,
  1877. .read = spufs_proxydma_info_read,
  1878. };
  1879. static int spufs_show_tid(struct seq_file *s, void *private)
  1880. {
  1881. struct spu_context *ctx = s->private;
  1882. seq_printf(s, "%d\n", ctx->tid);
  1883. return 0;
  1884. }
  1885. static int spufs_tid_open(struct inode *inode, struct file *file)
  1886. {
  1887. return single_open(file, spufs_show_tid, SPUFS_I(inode)->i_ctx);
  1888. }
  1889. static const struct file_operations spufs_tid_fops = {
  1890. .open = spufs_tid_open,
  1891. .read = seq_read,
  1892. .llseek = seq_lseek,
  1893. .release = single_release,
  1894. };
  1895. static const char *ctx_state_names[] = {
  1896. "user", "system", "iowait", "loaded"
  1897. };
  1898. static unsigned long long spufs_acct_time(struct spu_context *ctx,
  1899. enum spu_utilization_state state)
  1900. {
  1901. struct timespec ts;
  1902. unsigned long long time = ctx->stats.times[state];
  1903. /*
  1904. * In general, utilization statistics are updated by the controlling
  1905. * thread as the spu context moves through various well defined
  1906. * state transitions, but if the context is lazily loaded its
  1907. * utilization statistics are not updated as the controlling thread
  1908. * is not tightly coupled with the execution of the spu context. We
  1909. * calculate and apply the time delta from the last recorded state
  1910. * of the spu context.
  1911. */
  1912. if (ctx->spu && ctx->stats.util_state == state) {
  1913. ktime_get_ts(&ts);
  1914. time += timespec_to_ns(&ts) - ctx->stats.tstamp;
  1915. }
  1916. return time / NSEC_PER_MSEC;
  1917. }
  1918. static unsigned long long spufs_slb_flts(struct spu_context *ctx)
  1919. {
  1920. unsigned long long slb_flts = ctx->stats.slb_flt;
  1921. if (ctx->state == SPU_STATE_RUNNABLE) {
  1922. slb_flts += (ctx->spu->stats.slb_flt -
  1923. ctx->stats.slb_flt_base);
  1924. }
  1925. return slb_flts;
  1926. }
  1927. static unsigned long long spufs_class2_intrs(struct spu_context *ctx)
  1928. {
  1929. unsigned long long class2_intrs = ctx->stats.class2_intr;
  1930. if (ctx->state == SPU_STATE_RUNNABLE) {
  1931. class2_intrs += (ctx->spu->stats.class2_intr -
  1932. ctx->stats.class2_intr_base);
  1933. }
  1934. return class2_intrs;
  1935. }
  1936. static int spufs_show_stat(struct seq_file *s, void *private)
  1937. {
  1938. struct spu_context *ctx = s->private;
  1939. int ret;
  1940. ret = spu_acquire(ctx);
  1941. if (ret)
  1942. return ret;
  1943. seq_printf(s, "%s %llu %llu %llu %llu "
  1944. "%llu %llu %llu %llu %llu %llu %llu %llu\n",
  1945. ctx_state_names[ctx->stats.util_state],
  1946. spufs_acct_time(ctx, SPU_UTIL_USER),
  1947. spufs_acct_time(ctx, SPU_UTIL_SYSTEM),
  1948. spufs_acct_time(ctx, SPU_UTIL_IOWAIT),
  1949. spufs_acct_time(ctx, SPU_UTIL_IDLE_LOADED),
  1950. ctx->stats.vol_ctx_switch,
  1951. ctx->stats.invol_ctx_switch,
  1952. spufs_slb_flts(ctx),
  1953. ctx->stats.hash_flt,
  1954. ctx->stats.min_flt,
  1955. ctx->stats.maj_flt,
  1956. spufs_class2_intrs(ctx),
  1957. ctx->stats.libassist);
  1958. spu_release(ctx);
  1959. return 0;
  1960. }
  1961. static int spufs_stat_open(struct inode *inode, struct file *file)
  1962. {
  1963. return single_open(file, spufs_show_stat, SPUFS_I(inode)->i_ctx);
  1964. }
  1965. static const struct file_operations spufs_stat_fops = {
  1966. .open = spufs_stat_open,
  1967. .read = seq_read,
  1968. .llseek = seq_lseek,
  1969. .release = single_release,
  1970. };
  1971. static inline int spufs_switch_log_used(struct spu_context *ctx)
  1972. {
  1973. return (ctx->switch_log->head - ctx->switch_log->tail) %
  1974. SWITCH_LOG_BUFSIZE;
  1975. }
  1976. static inline int spufs_switch_log_avail(struct spu_context *ctx)
  1977. {
  1978. return SWITCH_LOG_BUFSIZE - spufs_switch_log_used(ctx);
  1979. }
  1980. static int spufs_switch_log_open(struct inode *inode, struct file *file)
  1981. {
  1982. struct spu_context *ctx = SPUFS_I(inode)->i_ctx;
  1983. /*
  1984. * We (ab-)use the mapping_lock here because it serves the similar
  1985. * purpose for synchronizing open/close elsewhere. Maybe it should
  1986. * be renamed eventually.
  1987. */
  1988. mutex_lock(&ctx->mapping_lock);
  1989. if (ctx->switch_log) {
  1990. spin_lock(&ctx->switch_log->lock);
  1991. ctx->switch_log->head = 0;
  1992. ctx->switch_log->tail = 0;
  1993. spin_unlock(&ctx->switch_log->lock);
  1994. } else {
  1995. /*
  1996. * We allocate the switch log data structures on first open.
  1997. * They will never be free because we assume a context will
  1998. * be traced until it goes away.
  1999. */
  2000. ctx->switch_log = kzalloc(sizeof(struct switch_log) +
  2001. SWITCH_LOG_BUFSIZE * sizeof(struct switch_log_entry),
  2002. GFP_KERNEL);
  2003. if (!ctx->switch_log)
  2004. goto out;
  2005. spin_lock_init(&ctx->switch_log->lock);
  2006. init_waitqueue_head(&ctx->switch_log->wait);
  2007. }
  2008. mutex_unlock(&ctx->mapping_lock);
  2009. return 0;
  2010. out:
  2011. mutex_unlock(&ctx->mapping_lock);
  2012. return -ENOMEM;
  2013. }
  2014. static int switch_log_sprint(struct spu_context *ctx, char *tbuf, int n)
  2015. {
  2016. struct switch_log_entry *p;
  2017. p = ctx->switch_log->log + ctx->switch_log->tail % SWITCH_LOG_BUFSIZE;
  2018. return snprintf(tbuf, n, "%u.%09u %d %u %u %llu\n",
  2019. (unsigned int) p->tstamp.tv_sec,
  2020. (unsigned int) p->tstamp.tv_nsec,
  2021. p->spu_id,
  2022. (unsigned int) p->type,
  2023. (unsigned int) p->val,
  2024. (unsigned long long) p->timebase);
  2025. }
  2026. static ssize_t spufs_switch_log_read(struct file *file, char __user *buf,
  2027. size_t len, loff_t *ppos)
  2028. {
  2029. struct inode *inode = file->f_path.dentry->d_inode;
  2030. struct spu_context *ctx = SPUFS_I(inode)->i_ctx;
  2031. int error = 0, cnt = 0;
  2032. if (!buf || len < 0)
  2033. return -EINVAL;
  2034. while (cnt < len) {
  2035. char tbuf[128];
  2036. int width;
  2037. if (file->f_flags & O_NONBLOCK) {
  2038. if (spufs_switch_log_used(ctx) <= 0)
  2039. return cnt ? cnt : -EAGAIN;
  2040. } else {
  2041. /* Wait for data in buffer */
  2042. error = wait_event_interruptible(ctx->switch_log->wait,
  2043. spufs_switch_log_used(ctx) > 0);
  2044. if (error)
  2045. break;
  2046. }
  2047. spin_lock(&ctx->switch_log->lock);
  2048. if (ctx->switch_log->head == ctx->switch_log->tail) {
  2049. /* multiple readers race? */
  2050. spin_unlock(&ctx->switch_log->lock);
  2051. continue;
  2052. }
  2053. width = switch_log_sprint(ctx, tbuf, sizeof(tbuf));
  2054. if (width < len) {
  2055. ctx->switch_log->tail =
  2056. (ctx->switch_log->tail + 1) %
  2057. SWITCH_LOG_BUFSIZE;
  2058. }
  2059. spin_unlock(&ctx->switch_log->lock);
  2060. /*
  2061. * If the record is greater than space available return
  2062. * partial buffer (so far)
  2063. */
  2064. if (width >= len)
  2065. break;
  2066. error = copy_to_user(buf + cnt, tbuf, width);
  2067. if (error)
  2068. break;
  2069. cnt += width;
  2070. }
  2071. return cnt == 0 ? error : cnt;
  2072. }
  2073. static unsigned int spufs_switch_log_poll(struct file *file, poll_table *wait)
  2074. {
  2075. struct inode *inode = file->f_path.dentry->d_inode;
  2076. struct spu_context *ctx = SPUFS_I(inode)->i_ctx;
  2077. unsigned int mask = 0;
  2078. poll_wait(file, &ctx->switch_log->wait, wait);
  2079. if (spufs_switch_log_used(ctx) > 0)
  2080. mask |= POLLIN;
  2081. return mask;
  2082. }
  2083. static const struct file_operations spufs_switch_log_fops = {
  2084. .owner = THIS_MODULE,
  2085. .open = spufs_switch_log_open,
  2086. .read = spufs_switch_log_read,
  2087. .poll = spufs_switch_log_poll,
  2088. };
  2089. void spu_switch_log_notify(struct spu *spu, struct spu_context *ctx,
  2090. u32 type, u32 val)
  2091. {
  2092. if (!ctx->switch_log)
  2093. return;
  2094. spin_lock(&ctx->switch_log->lock);
  2095. if (spufs_switch_log_avail(ctx) > 1) {
  2096. struct switch_log_entry *p;
  2097. p = ctx->switch_log->log + ctx->switch_log->head;
  2098. ktime_get_ts(&p->tstamp);
  2099. p->timebase = get_tb();
  2100. p->spu_id = spu ? spu->number : -1;
  2101. p->type = type;
  2102. p->val = val;
  2103. ctx->switch_log->head =
  2104. (ctx->switch_log->head + 1) % SWITCH_LOG_BUFSIZE;
  2105. }
  2106. spin_unlock(&ctx->switch_log->lock);
  2107. wake_up(&ctx->switch_log->wait);
  2108. }
  2109. struct tree_descr spufs_dir_contents[] = {
  2110. { "capabilities", &spufs_caps_fops, 0444, },
  2111. { "mem", &spufs_mem_fops, 0666, },
  2112. { "regs", &spufs_regs_fops, 0666, },
  2113. { "mbox", &spufs_mbox_fops, 0444, },
  2114. { "ibox", &spufs_ibox_fops, 0444, },
  2115. { "wbox", &spufs_wbox_fops, 0222, },
  2116. { "mbox_stat", &spufs_mbox_stat_fops, 0444, },
  2117. { "ibox_stat", &spufs_ibox_stat_fops, 0444, },
  2118. { "wbox_stat", &spufs_wbox_stat_fops, 0444, },
  2119. { "signal1", &spufs_signal1_fops, 0666, },
  2120. { "signal2", &spufs_signal2_fops, 0666, },
  2121. { "signal1_type", &spufs_signal1_type, 0666, },
  2122. { "signal2_type", &spufs_signal2_type, 0666, },
  2123. { "cntl", &spufs_cntl_fops, 0666, },
  2124. { "fpcr", &spufs_fpcr_fops, 0666, },
  2125. { "lslr", &spufs_lslr_ops, 0444, },
  2126. { "mfc", &spufs_mfc_fops, 0666, },
  2127. { "mss", &spufs_mss_fops, 0666, },
  2128. { "npc", &spufs_npc_ops, 0666, },
  2129. { "srr0", &spufs_srr0_ops, 0666, },
  2130. { "decr", &spufs_decr_ops, 0666, },
  2131. { "decr_status", &spufs_decr_status_ops, 0666, },
  2132. { "event_mask", &spufs_event_mask_ops, 0666, },
  2133. { "event_status", &spufs_event_status_ops, 0444, },
  2134. { "psmap", &spufs_psmap_fops, 0666, },
  2135. { "phys-id", &spufs_id_ops, 0666, },
  2136. { "object-id", &spufs_object_id_ops, 0666, },
  2137. { "mbox_info", &spufs_mbox_info_fops, 0444, },
  2138. { "ibox_info", &spufs_ibox_info_fops, 0444, },
  2139. { "wbox_info", &spufs_wbox_info_fops, 0444, },
  2140. { "dma_info", &spufs_dma_info_fops, 0444, },
  2141. { "proxydma_info", &spufs_proxydma_info_fops, 0444, },
  2142. { "tid", &spufs_tid_fops, 0444, },
  2143. { "stat", &spufs_stat_fops, 0444, },
  2144. { "switch_log", &spufs_switch_log_fops, 0444 },
  2145. {},
  2146. };
  2147. struct tree_descr spufs_dir_nosched_contents[] = {
  2148. { "capabilities", &spufs_caps_fops, 0444, },
  2149. { "mem", &spufs_mem_fops, 0666, },
  2150. { "mbox", &spufs_mbox_fops, 0444, },
  2151. { "ibox", &spufs_ibox_fops, 0444, },
  2152. { "wbox", &spufs_wbox_fops, 0222, },
  2153. { "mbox_stat", &spufs_mbox_stat_fops, 0444, },
  2154. { "ibox_stat", &spufs_ibox_stat_fops, 0444, },
  2155. { "wbox_stat", &spufs_wbox_stat_fops, 0444, },
  2156. { "signal1", &spufs_signal1_nosched_fops, 0222, },
  2157. { "signal2", &spufs_signal2_nosched_fops, 0222, },
  2158. { "signal1_type", &spufs_signal1_type, 0666, },
  2159. { "signal2_type", &spufs_signal2_type, 0666, },
  2160. { "mss", &spufs_mss_fops, 0666, },
  2161. { "mfc", &spufs_mfc_fops, 0666, },
  2162. { "cntl", &spufs_cntl_fops, 0666, },
  2163. { "npc", &spufs_npc_ops, 0666, },
  2164. { "psmap", &spufs_psmap_fops, 0666, },
  2165. { "phys-id", &spufs_id_ops, 0666, },
  2166. { "object-id", &spufs_object_id_ops, 0666, },
  2167. { "tid", &spufs_tid_fops, 0444, },
  2168. { "stat", &spufs_stat_fops, 0444, },
  2169. {},
  2170. };
  2171. struct spufs_coredump_reader spufs_coredump_read[] = {
  2172. { "regs", __spufs_regs_read, NULL, sizeof(struct spu_reg128[128])},
  2173. { "fpcr", __spufs_fpcr_read, NULL, sizeof(struct spu_reg128) },
  2174. { "lslr", NULL, spufs_lslr_get, 19 },
  2175. { "decr", NULL, spufs_decr_get, 19 },
  2176. { "decr_status", NULL, spufs_decr_status_get, 19 },
  2177. { "mem", __spufs_mem_read, NULL, LS_SIZE, },
  2178. { "signal1", __spufs_signal1_read, NULL, sizeof(u32) },
  2179. { "signal1_type", NULL, spufs_signal1_type_get, 19 },
  2180. { "signal2", __spufs_signal2_read, NULL, sizeof(u32) },
  2181. { "signal2_type", NULL, spufs_signal2_type_get, 19 },
  2182. { "event_mask", NULL, spufs_event_mask_get, 19 },
  2183. { "event_status", NULL, spufs_event_status_get, 19 },
  2184. { "mbox_info", __spufs_mbox_info_read, NULL, sizeof(u32) },
  2185. { "ibox_info", __spufs_ibox_info_read, NULL, sizeof(u32) },
  2186. { "wbox_info", __spufs_wbox_info_read, NULL, 4 * sizeof(u32)},
  2187. { "dma_info", __spufs_dma_info_read, NULL, sizeof(struct spu_dma_info)},
  2188. { "proxydma_info", __spufs_proxydma_info_read,
  2189. NULL, sizeof(struct spu_proxydma_info)},
  2190. { "object-id", NULL, spufs_object_id_get, 19 },
  2191. { "npc", NULL, spufs_npc_get, 19 },
  2192. { NULL },
  2193. };