file.c 63 KB

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