file.c 62 KB

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