file.c 61 KB

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