file.c 63 KB

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