file.c 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052
  1. /*
  2. * SPU file system -- file contents
  3. *
  4. * (C) Copyright IBM Deutschland Entwicklung GmbH 2005
  5. *
  6. * Author: Arnd Bergmann <arndb@de.ibm.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2, or (at your option)
  11. * any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. */
  22. #undef DEBUG
  23. #include <linux/fs.h>
  24. #include <linux/ioctl.h>
  25. #include <linux/module.h>
  26. #include <linux/pagemap.h>
  27. #include <linux/poll.h>
  28. #include <linux/ptrace.h>
  29. #include <asm/io.h>
  30. #include <asm/semaphore.h>
  31. #include <asm/spu.h>
  32. #include <asm/spu_info.h>
  33. #include <asm/uaccess.h>
  34. #include "spufs.h"
  35. #define SPUFS_MMAP_4K (PAGE_SIZE == 0x1000)
  36. static int
  37. spufs_mem_open(struct inode *inode, struct file *file)
  38. {
  39. struct spufs_inode_info *i = SPUFS_I(inode);
  40. struct spu_context *ctx = i->i_ctx;
  41. spin_lock(&ctx->mapping_lock);
  42. file->private_data = ctx;
  43. if (!i->i_openers++)
  44. ctx->local_store = inode->i_mapping;
  45. spin_unlock(&ctx->mapping_lock);
  46. smp_wmb();
  47. return 0;
  48. }
  49. static int
  50. spufs_mem_release(struct inode *inode, struct file *file)
  51. {
  52. struct spufs_inode_info *i = SPUFS_I(inode);
  53. struct spu_context *ctx = i->i_ctx;
  54. spin_lock(&ctx->mapping_lock);
  55. if (!--i->i_openers)
  56. ctx->local_store = NULL;
  57. spin_unlock(&ctx->mapping_lock);
  58. smp_wmb();
  59. return 0;
  60. }
  61. static ssize_t
  62. __spufs_mem_read(struct spu_context *ctx, char __user *buffer,
  63. size_t size, loff_t *pos)
  64. {
  65. char *local_store = ctx->ops->get_ls(ctx);
  66. return simple_read_from_buffer(buffer, size, pos, local_store,
  67. LS_SIZE);
  68. }
  69. static ssize_t
  70. spufs_mem_read(struct file *file, char __user *buffer,
  71. size_t size, loff_t *pos)
  72. {
  73. struct spu_context *ctx = file->private_data;
  74. ssize_t ret;
  75. spu_acquire(ctx);
  76. ret = __spufs_mem_read(ctx, buffer, size, pos);
  77. spu_release(ctx);
  78. return ret;
  79. }
  80. static ssize_t
  81. spufs_mem_write(struct file *file, const char __user *buffer,
  82. size_t size, loff_t *ppos)
  83. {
  84. struct spu_context *ctx = file->private_data;
  85. char *local_store;
  86. loff_t pos = *ppos;
  87. int ret;
  88. if (pos < 0)
  89. return -EINVAL;
  90. if (pos > LS_SIZE)
  91. return -EFBIG;
  92. if (size > LS_SIZE - pos)
  93. size = LS_SIZE - pos;
  94. spu_acquire(ctx);
  95. local_store = ctx->ops->get_ls(ctx);
  96. ret = copy_from_user(local_store + pos, buffer, size);
  97. spu_release(ctx);
  98. if (ret)
  99. return -EFAULT;
  100. *ppos = pos + size;
  101. return size;
  102. }
  103. static unsigned long spufs_mem_mmap_nopfn(struct vm_area_struct *vma,
  104. unsigned long address)
  105. {
  106. struct spu_context *ctx = vma->vm_file->private_data;
  107. unsigned long pfn, offset = address - vma->vm_start;
  108. offset += vma->vm_pgoff << PAGE_SHIFT;
  109. if (offset >= LS_SIZE)
  110. return NOPFN_SIGBUS;
  111. spu_acquire(ctx);
  112. if (ctx->state == SPU_STATE_SAVED) {
  113. vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
  114. & ~_PAGE_NO_CACHE);
  115. pfn = vmalloc_to_pfn(ctx->csa.lscsa->ls + offset);
  116. } else {
  117. vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
  118. | _PAGE_NO_CACHE);
  119. pfn = (ctx->spu->local_store_phys + offset) >> PAGE_SHIFT;
  120. }
  121. vm_insert_pfn(vma, address, pfn);
  122. spu_release(ctx);
  123. return NOPFN_REFAULT;
  124. }
  125. static struct vm_operations_struct spufs_mem_mmap_vmops = {
  126. .nopfn = spufs_mem_mmap_nopfn,
  127. };
  128. static int
  129. spufs_mem_mmap(struct file *file, struct vm_area_struct *vma)
  130. {
  131. if (!(vma->vm_flags & VM_SHARED))
  132. return -EINVAL;
  133. vma->vm_flags |= VM_IO | VM_PFNMAP;
  134. vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
  135. | _PAGE_NO_CACHE);
  136. vma->vm_ops = &spufs_mem_mmap_vmops;
  137. return 0;
  138. }
  139. static const struct file_operations spufs_mem_fops = {
  140. .open = spufs_mem_open,
  141. .release = spufs_mem_release,
  142. .read = spufs_mem_read,
  143. .write = spufs_mem_write,
  144. .llseek = generic_file_llseek,
  145. .mmap = spufs_mem_mmap,
  146. };
  147. static unsigned long spufs_ps_nopfn(struct vm_area_struct *vma,
  148. unsigned long address,
  149. unsigned long ps_offs,
  150. unsigned long ps_size)
  151. {
  152. struct spu_context *ctx = vma->vm_file->private_data;
  153. unsigned long area, offset = address - vma->vm_start;
  154. int ret;
  155. offset += vma->vm_pgoff << PAGE_SHIFT;
  156. if (offset >= ps_size)
  157. return NOPFN_SIGBUS;
  158. /* error here usually means a signal.. we might want to test
  159. * the error code more precisely though
  160. */
  161. ret = spu_acquire_runnable(ctx, 0);
  162. if (ret)
  163. return NOPFN_REFAULT;
  164. area = ctx->spu->problem_phys + ps_offs;
  165. vm_insert_pfn(vma, address, (area + offset) >> PAGE_SHIFT);
  166. spu_release(ctx);
  167. return NOPFN_REFAULT;
  168. }
  169. #if SPUFS_MMAP_4K
  170. static unsigned long spufs_cntl_mmap_nopfn(struct vm_area_struct *vma,
  171. unsigned long address)
  172. {
  173. return spufs_ps_nopfn(vma, address, 0x4000, 0x1000);
  174. }
  175. static struct vm_operations_struct spufs_cntl_mmap_vmops = {
  176. .nopfn = spufs_cntl_mmap_nopfn,
  177. };
  178. /*
  179. * mmap support for problem state control area [0x4000 - 0x4fff].
  180. */
  181. static int spufs_cntl_mmap(struct file *file, struct vm_area_struct *vma)
  182. {
  183. if (!(vma->vm_flags & VM_SHARED))
  184. return -EINVAL;
  185. vma->vm_flags |= VM_IO | VM_PFNMAP;
  186. vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
  187. | _PAGE_NO_CACHE | _PAGE_GUARDED);
  188. vma->vm_ops = &spufs_cntl_mmap_vmops;
  189. return 0;
  190. }
  191. #else /* SPUFS_MMAP_4K */
  192. #define spufs_cntl_mmap NULL
  193. #endif /* !SPUFS_MMAP_4K */
  194. static u64 spufs_cntl_get(void *data)
  195. {
  196. struct spu_context *ctx = data;
  197. u64 val;
  198. spu_acquire(ctx);
  199. val = ctx->ops->status_read(ctx);
  200. spu_release(ctx);
  201. return val;
  202. }
  203. static void spufs_cntl_set(void *data, u64 val)
  204. {
  205. struct spu_context *ctx = data;
  206. spu_acquire(ctx);
  207. ctx->ops->runcntl_write(ctx, val);
  208. spu_release(ctx);
  209. }
  210. static int spufs_cntl_open(struct inode *inode, struct file *file)
  211. {
  212. struct spufs_inode_info *i = SPUFS_I(inode);
  213. struct spu_context *ctx = i->i_ctx;
  214. spin_lock(&ctx->mapping_lock);
  215. file->private_data = ctx;
  216. if (!i->i_openers++)
  217. ctx->cntl = inode->i_mapping;
  218. spin_unlock(&ctx->mapping_lock);
  219. smp_wmb();
  220. return simple_attr_open(inode, file, spufs_cntl_get,
  221. spufs_cntl_set, "0x%08lx");
  222. }
  223. static int
  224. spufs_cntl_release(struct inode *inode, struct file *file)
  225. {
  226. struct spufs_inode_info *i = SPUFS_I(inode);
  227. struct spu_context *ctx = i->i_ctx;
  228. simple_attr_close(inode, file);
  229. spin_lock(&ctx->mapping_lock);
  230. if (!--i->i_openers)
  231. ctx->cntl = NULL;
  232. spin_unlock(&ctx->mapping_lock);
  233. smp_wmb();
  234. return 0;
  235. }
  236. static const struct file_operations spufs_cntl_fops = {
  237. .open = spufs_cntl_open,
  238. .release = spufs_cntl_release,
  239. .read = simple_attr_read,
  240. .write = simple_attr_write,
  241. .mmap = spufs_cntl_mmap,
  242. };
  243. static int
  244. spufs_regs_open(struct inode *inode, struct file *file)
  245. {
  246. struct spufs_inode_info *i = SPUFS_I(inode);
  247. file->private_data = i->i_ctx;
  248. return 0;
  249. }
  250. static ssize_t
  251. __spufs_regs_read(struct spu_context *ctx, char __user *buffer,
  252. size_t size, loff_t *pos)
  253. {
  254. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  255. return simple_read_from_buffer(buffer, size, pos,
  256. lscsa->gprs, sizeof lscsa->gprs);
  257. }
  258. static ssize_t
  259. spufs_regs_read(struct file *file, char __user *buffer,
  260. size_t size, loff_t *pos)
  261. {
  262. int ret;
  263. struct spu_context *ctx = file->private_data;
  264. spu_acquire_saved(ctx);
  265. ret = __spufs_regs_read(ctx, buffer, size, pos);
  266. spu_release(ctx);
  267. return ret;
  268. }
  269. static ssize_t
  270. spufs_regs_write(struct file *file, const char __user *buffer,
  271. size_t size, loff_t *pos)
  272. {
  273. struct spu_context *ctx = file->private_data;
  274. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  275. int ret;
  276. size = min_t(ssize_t, sizeof lscsa->gprs - *pos, size);
  277. if (size <= 0)
  278. return -EFBIG;
  279. *pos += size;
  280. spu_acquire_saved(ctx);
  281. ret = copy_from_user(lscsa->gprs + *pos - size,
  282. buffer, size) ? -EFAULT : size;
  283. spu_release(ctx);
  284. return ret;
  285. }
  286. static const struct file_operations spufs_regs_fops = {
  287. .open = spufs_regs_open,
  288. .read = spufs_regs_read,
  289. .write = spufs_regs_write,
  290. .llseek = generic_file_llseek,
  291. };
  292. static ssize_t
  293. __spufs_fpcr_read(struct spu_context *ctx, char __user * buffer,
  294. size_t size, loff_t * pos)
  295. {
  296. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  297. return simple_read_from_buffer(buffer, size, pos,
  298. &lscsa->fpcr, sizeof(lscsa->fpcr));
  299. }
  300. static ssize_t
  301. spufs_fpcr_read(struct file *file, char __user * buffer,
  302. size_t size, loff_t * pos)
  303. {
  304. int ret;
  305. struct spu_context *ctx = file->private_data;
  306. spu_acquire_saved(ctx);
  307. ret = __spufs_fpcr_read(ctx, buffer, size, pos);
  308. spu_release(ctx);
  309. return ret;
  310. }
  311. static ssize_t
  312. spufs_fpcr_write(struct file *file, const char __user * buffer,
  313. size_t size, loff_t * pos)
  314. {
  315. struct spu_context *ctx = file->private_data;
  316. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  317. int ret;
  318. size = min_t(ssize_t, sizeof(lscsa->fpcr) - *pos, size);
  319. if (size <= 0)
  320. return -EFBIG;
  321. *pos += size;
  322. spu_acquire_saved(ctx);
  323. ret = copy_from_user((char *)&lscsa->fpcr + *pos - size,
  324. buffer, size) ? -EFAULT : size;
  325. spu_release(ctx);
  326. return ret;
  327. }
  328. static const struct file_operations spufs_fpcr_fops = {
  329. .open = spufs_regs_open,
  330. .read = spufs_fpcr_read,
  331. .write = spufs_fpcr_write,
  332. .llseek = generic_file_llseek,
  333. };
  334. /* generic open function for all pipe-like files */
  335. static int spufs_pipe_open(struct inode *inode, struct file *file)
  336. {
  337. struct spufs_inode_info *i = SPUFS_I(inode);
  338. file->private_data = i->i_ctx;
  339. return nonseekable_open(inode, file);
  340. }
  341. /*
  342. * Read as many bytes from the mailbox as possible, until
  343. * one of the conditions becomes true:
  344. *
  345. * - no more data available in the mailbox
  346. * - end of the user provided buffer
  347. * - end of the mapped area
  348. */
  349. static ssize_t spufs_mbox_read(struct file *file, char __user *buf,
  350. size_t len, loff_t *pos)
  351. {
  352. struct spu_context *ctx = file->private_data;
  353. u32 mbox_data, __user *udata;
  354. ssize_t count;
  355. if (len < 4)
  356. return -EINVAL;
  357. if (!access_ok(VERIFY_WRITE, buf, len))
  358. return -EFAULT;
  359. udata = (void __user *)buf;
  360. spu_acquire(ctx);
  361. for (count = 0; (count + 4) <= len; count += 4, udata++) {
  362. int ret;
  363. ret = ctx->ops->mbox_read(ctx, &mbox_data);
  364. if (ret == 0)
  365. break;
  366. /*
  367. * at the end of the mapped area, we can fault
  368. * but still need to return the data we have
  369. * read successfully so far.
  370. */
  371. ret = __put_user(mbox_data, udata);
  372. if (ret) {
  373. if (!count)
  374. count = -EFAULT;
  375. break;
  376. }
  377. }
  378. spu_release(ctx);
  379. if (!count)
  380. count = -EAGAIN;
  381. return count;
  382. }
  383. static const struct file_operations spufs_mbox_fops = {
  384. .open = spufs_pipe_open,
  385. .read = spufs_mbox_read,
  386. };
  387. static ssize_t spufs_mbox_stat_read(struct file *file, char __user *buf,
  388. size_t len, loff_t *pos)
  389. {
  390. struct spu_context *ctx = file->private_data;
  391. u32 mbox_stat;
  392. if (len < 4)
  393. return -EINVAL;
  394. spu_acquire(ctx);
  395. mbox_stat = ctx->ops->mbox_stat_read(ctx) & 0xff;
  396. spu_release(ctx);
  397. if (copy_to_user(buf, &mbox_stat, sizeof mbox_stat))
  398. return -EFAULT;
  399. return 4;
  400. }
  401. static const struct file_operations spufs_mbox_stat_fops = {
  402. .open = spufs_pipe_open,
  403. .read = spufs_mbox_stat_read,
  404. };
  405. /* low-level ibox access function */
  406. size_t spu_ibox_read(struct spu_context *ctx, u32 *data)
  407. {
  408. return ctx->ops->ibox_read(ctx, data);
  409. }
  410. static int spufs_ibox_fasync(int fd, struct file *file, int on)
  411. {
  412. struct spu_context *ctx = file->private_data;
  413. return fasync_helper(fd, file, on, &ctx->ibox_fasync);
  414. }
  415. /* interrupt-level ibox callback function. */
  416. void spufs_ibox_callback(struct spu *spu)
  417. {
  418. struct spu_context *ctx = spu->ctx;
  419. wake_up_all(&ctx->ibox_wq);
  420. kill_fasync(&ctx->ibox_fasync, SIGIO, POLLIN);
  421. }
  422. /*
  423. * Read as many bytes from the interrupt mailbox as possible, until
  424. * one of the conditions becomes true:
  425. *
  426. * - no more data available in the mailbox
  427. * - end of the user provided buffer
  428. * - end of the mapped area
  429. *
  430. * If the file is opened without O_NONBLOCK, we wait here until
  431. * any data is available, but return when we have been able to
  432. * read something.
  433. */
  434. static ssize_t spufs_ibox_read(struct file *file, char __user *buf,
  435. size_t len, loff_t *pos)
  436. {
  437. struct spu_context *ctx = file->private_data;
  438. u32 ibox_data, __user *udata;
  439. ssize_t count;
  440. if (len < 4)
  441. return -EINVAL;
  442. if (!access_ok(VERIFY_WRITE, buf, len))
  443. return -EFAULT;
  444. udata = (void __user *)buf;
  445. spu_acquire(ctx);
  446. /* wait only for the first element */
  447. count = 0;
  448. if (file->f_flags & O_NONBLOCK) {
  449. if (!spu_ibox_read(ctx, &ibox_data))
  450. count = -EAGAIN;
  451. } else {
  452. count = spufs_wait(ctx->ibox_wq, spu_ibox_read(ctx, &ibox_data));
  453. }
  454. if (count)
  455. goto out;
  456. /* if we can't write at all, return -EFAULT */
  457. count = __put_user(ibox_data, udata);
  458. if (count)
  459. goto out;
  460. for (count = 4, udata++; (count + 4) <= len; count += 4, udata++) {
  461. int ret;
  462. ret = ctx->ops->ibox_read(ctx, &ibox_data);
  463. if (ret == 0)
  464. break;
  465. /*
  466. * at the end of the mapped area, we can fault
  467. * but still need to return the data we have
  468. * read successfully so far.
  469. */
  470. ret = __put_user(ibox_data, udata);
  471. if (ret)
  472. break;
  473. }
  474. out:
  475. spu_release(ctx);
  476. return count;
  477. }
  478. static unsigned int spufs_ibox_poll(struct file *file, poll_table *wait)
  479. {
  480. struct spu_context *ctx = file->private_data;
  481. unsigned int mask;
  482. poll_wait(file, &ctx->ibox_wq, wait);
  483. spu_acquire(ctx);
  484. mask = ctx->ops->mbox_stat_poll(ctx, POLLIN | POLLRDNORM);
  485. spu_release(ctx);
  486. return mask;
  487. }
  488. static const struct file_operations spufs_ibox_fops = {
  489. .open = spufs_pipe_open,
  490. .read = spufs_ibox_read,
  491. .poll = spufs_ibox_poll,
  492. .fasync = spufs_ibox_fasync,
  493. };
  494. static ssize_t spufs_ibox_stat_read(struct file *file, char __user *buf,
  495. size_t len, loff_t *pos)
  496. {
  497. struct spu_context *ctx = file->private_data;
  498. u32 ibox_stat;
  499. if (len < 4)
  500. return -EINVAL;
  501. spu_acquire(ctx);
  502. ibox_stat = (ctx->ops->mbox_stat_read(ctx) >> 16) & 0xff;
  503. spu_release(ctx);
  504. if (copy_to_user(buf, &ibox_stat, sizeof ibox_stat))
  505. return -EFAULT;
  506. return 4;
  507. }
  508. static const struct file_operations spufs_ibox_stat_fops = {
  509. .open = spufs_pipe_open,
  510. .read = spufs_ibox_stat_read,
  511. };
  512. /* low-level mailbox write */
  513. size_t spu_wbox_write(struct spu_context *ctx, u32 data)
  514. {
  515. return ctx->ops->wbox_write(ctx, data);
  516. }
  517. static int spufs_wbox_fasync(int fd, struct file *file, int on)
  518. {
  519. struct spu_context *ctx = file->private_data;
  520. int ret;
  521. ret = fasync_helper(fd, file, on, &ctx->wbox_fasync);
  522. return ret;
  523. }
  524. /* interrupt-level wbox callback function. */
  525. void spufs_wbox_callback(struct spu *spu)
  526. {
  527. struct spu_context *ctx = spu->ctx;
  528. wake_up_all(&ctx->wbox_wq);
  529. kill_fasync(&ctx->wbox_fasync, SIGIO, POLLOUT);
  530. }
  531. /*
  532. * Write as many bytes to the interrupt mailbox as possible, until
  533. * one of the conditions becomes true:
  534. *
  535. * - the mailbox is full
  536. * - end of the user provided buffer
  537. * - end of the mapped area
  538. *
  539. * If the file is opened without O_NONBLOCK, we wait here until
  540. * space is availabyl, but return when we have been able to
  541. * write something.
  542. */
  543. static ssize_t spufs_wbox_write(struct file *file, const char __user *buf,
  544. size_t len, loff_t *pos)
  545. {
  546. struct spu_context *ctx = file->private_data;
  547. u32 wbox_data, __user *udata;
  548. ssize_t count;
  549. if (len < 4)
  550. return -EINVAL;
  551. udata = (void __user *)buf;
  552. if (!access_ok(VERIFY_READ, buf, len))
  553. return -EFAULT;
  554. if (__get_user(wbox_data, udata))
  555. return -EFAULT;
  556. spu_acquire(ctx);
  557. /*
  558. * make sure we can at least write one element, by waiting
  559. * in case of !O_NONBLOCK
  560. */
  561. count = 0;
  562. if (file->f_flags & O_NONBLOCK) {
  563. if (!spu_wbox_write(ctx, wbox_data))
  564. count = -EAGAIN;
  565. } else {
  566. count = spufs_wait(ctx->wbox_wq, spu_wbox_write(ctx, wbox_data));
  567. }
  568. if (count)
  569. goto out;
  570. /* write aѕ much as possible */
  571. for (count = 4, udata++; (count + 4) <= len; count += 4, udata++) {
  572. int ret;
  573. ret = __get_user(wbox_data, udata);
  574. if (ret)
  575. break;
  576. ret = spu_wbox_write(ctx, wbox_data);
  577. if (ret == 0)
  578. break;
  579. }
  580. out:
  581. spu_release(ctx);
  582. return count;
  583. }
  584. static unsigned int spufs_wbox_poll(struct file *file, poll_table *wait)
  585. {
  586. struct spu_context *ctx = file->private_data;
  587. unsigned int mask;
  588. poll_wait(file, &ctx->wbox_wq, wait);
  589. spu_acquire(ctx);
  590. mask = ctx->ops->mbox_stat_poll(ctx, POLLOUT | POLLWRNORM);
  591. spu_release(ctx);
  592. return mask;
  593. }
  594. static const struct file_operations spufs_wbox_fops = {
  595. .open = spufs_pipe_open,
  596. .write = spufs_wbox_write,
  597. .poll = spufs_wbox_poll,
  598. .fasync = spufs_wbox_fasync,
  599. };
  600. static ssize_t spufs_wbox_stat_read(struct file *file, char __user *buf,
  601. size_t len, loff_t *pos)
  602. {
  603. struct spu_context *ctx = file->private_data;
  604. u32 wbox_stat;
  605. if (len < 4)
  606. return -EINVAL;
  607. spu_acquire(ctx);
  608. wbox_stat = (ctx->ops->mbox_stat_read(ctx) >> 8) & 0xff;
  609. spu_release(ctx);
  610. if (copy_to_user(buf, &wbox_stat, sizeof wbox_stat))
  611. return -EFAULT;
  612. return 4;
  613. }
  614. static const struct file_operations spufs_wbox_stat_fops = {
  615. .open = spufs_pipe_open,
  616. .read = spufs_wbox_stat_read,
  617. };
  618. static int spufs_signal1_open(struct inode *inode, struct file *file)
  619. {
  620. struct spufs_inode_info *i = SPUFS_I(inode);
  621. struct spu_context *ctx = i->i_ctx;
  622. spin_lock(&ctx->mapping_lock);
  623. file->private_data = ctx;
  624. if (!i->i_openers++)
  625. ctx->signal1 = inode->i_mapping;
  626. spin_unlock(&ctx->mapping_lock);
  627. smp_wmb();
  628. return nonseekable_open(inode, file);
  629. }
  630. static int
  631. spufs_signal1_release(struct inode *inode, struct file *file)
  632. {
  633. struct spufs_inode_info *i = SPUFS_I(inode);
  634. struct spu_context *ctx = i->i_ctx;
  635. spin_lock(&ctx->mapping_lock);
  636. if (!--i->i_openers)
  637. ctx->signal1 = NULL;
  638. spin_unlock(&ctx->mapping_lock);
  639. smp_wmb();
  640. return 0;
  641. }
  642. static ssize_t __spufs_signal1_read(struct spu_context *ctx, char __user *buf,
  643. size_t len, loff_t *pos)
  644. {
  645. int ret = 0;
  646. u32 data;
  647. if (len < 4)
  648. return -EINVAL;
  649. if (ctx->csa.spu_chnlcnt_RW[3]) {
  650. data = ctx->csa.spu_chnldata_RW[3];
  651. ret = 4;
  652. }
  653. if (!ret)
  654. goto out;
  655. if (copy_to_user(buf, &data, 4))
  656. return -EFAULT;
  657. out:
  658. return ret;
  659. }
  660. static ssize_t spufs_signal1_read(struct file *file, char __user *buf,
  661. size_t len, loff_t *pos)
  662. {
  663. int ret;
  664. struct spu_context *ctx = file->private_data;
  665. spu_acquire_saved(ctx);
  666. ret = __spufs_signal1_read(ctx, buf, len, pos);
  667. spu_release(ctx);
  668. return ret;
  669. }
  670. static ssize_t spufs_signal1_write(struct file *file, const char __user *buf,
  671. size_t len, loff_t *pos)
  672. {
  673. struct spu_context *ctx;
  674. u32 data;
  675. ctx = file->private_data;
  676. if (len < 4)
  677. return -EINVAL;
  678. if (copy_from_user(&data, buf, 4))
  679. return -EFAULT;
  680. spu_acquire(ctx);
  681. ctx->ops->signal1_write(ctx, data);
  682. spu_release(ctx);
  683. return 4;
  684. }
  685. static unsigned long spufs_signal1_mmap_nopfn(struct vm_area_struct *vma,
  686. unsigned long address)
  687. {
  688. #if PAGE_SIZE == 0x1000
  689. return spufs_ps_nopfn(vma, address, 0x14000, 0x1000);
  690. #elif PAGE_SIZE == 0x10000
  691. /* For 64k pages, both signal1 and signal2 can be used to mmap the whole
  692. * signal 1 and 2 area
  693. */
  694. return spufs_ps_nopfn(vma, address, 0x10000, 0x10000);
  695. #else
  696. #error unsupported page size
  697. #endif
  698. }
  699. static struct vm_operations_struct spufs_signal1_mmap_vmops = {
  700. .nopfn = spufs_signal1_mmap_nopfn,
  701. };
  702. static int spufs_signal1_mmap(struct file *file, struct vm_area_struct *vma)
  703. {
  704. if (!(vma->vm_flags & VM_SHARED))
  705. return -EINVAL;
  706. vma->vm_flags |= VM_IO | VM_PFNMAP;
  707. vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
  708. | _PAGE_NO_CACHE | _PAGE_GUARDED);
  709. vma->vm_ops = &spufs_signal1_mmap_vmops;
  710. return 0;
  711. }
  712. static const struct file_operations spufs_signal1_fops = {
  713. .open = spufs_signal1_open,
  714. .release = spufs_signal1_release,
  715. .read = spufs_signal1_read,
  716. .write = spufs_signal1_write,
  717. .mmap = spufs_signal1_mmap,
  718. };
  719. static int spufs_signal2_open(struct inode *inode, struct file *file)
  720. {
  721. struct spufs_inode_info *i = SPUFS_I(inode);
  722. struct spu_context *ctx = i->i_ctx;
  723. spin_lock(&ctx->mapping_lock);
  724. file->private_data = ctx;
  725. if (!i->i_openers++)
  726. ctx->signal2 = inode->i_mapping;
  727. spin_unlock(&ctx->mapping_lock);
  728. smp_wmb();
  729. return nonseekable_open(inode, file);
  730. }
  731. static int
  732. spufs_signal2_release(struct inode *inode, struct file *file)
  733. {
  734. struct spufs_inode_info *i = SPUFS_I(inode);
  735. struct spu_context *ctx = i->i_ctx;
  736. spin_lock(&ctx->mapping_lock);
  737. if (!--i->i_openers)
  738. ctx->signal2 = NULL;
  739. spin_unlock(&ctx->mapping_lock);
  740. smp_wmb();
  741. return 0;
  742. }
  743. static ssize_t __spufs_signal2_read(struct spu_context *ctx, char __user *buf,
  744. size_t len, loff_t *pos)
  745. {
  746. int ret = 0;
  747. u32 data;
  748. if (len < 4)
  749. return -EINVAL;
  750. if (ctx->csa.spu_chnlcnt_RW[4]) {
  751. data = ctx->csa.spu_chnldata_RW[4];
  752. ret = 4;
  753. }
  754. if (!ret)
  755. goto out;
  756. if (copy_to_user(buf, &data, 4))
  757. return -EFAULT;
  758. out:
  759. return ret;
  760. }
  761. static ssize_t spufs_signal2_read(struct file *file, char __user *buf,
  762. size_t len, loff_t *pos)
  763. {
  764. struct spu_context *ctx = file->private_data;
  765. int ret;
  766. spu_acquire_saved(ctx);
  767. ret = __spufs_signal2_read(ctx, buf, len, pos);
  768. spu_release(ctx);
  769. return ret;
  770. }
  771. static ssize_t spufs_signal2_write(struct file *file, const char __user *buf,
  772. size_t len, loff_t *pos)
  773. {
  774. struct spu_context *ctx;
  775. u32 data;
  776. ctx = file->private_data;
  777. if (len < 4)
  778. return -EINVAL;
  779. if (copy_from_user(&data, buf, 4))
  780. return -EFAULT;
  781. spu_acquire(ctx);
  782. ctx->ops->signal2_write(ctx, data);
  783. spu_release(ctx);
  784. return 4;
  785. }
  786. #if SPUFS_MMAP_4K
  787. static unsigned long spufs_signal2_mmap_nopfn(struct vm_area_struct *vma,
  788. unsigned long address)
  789. {
  790. #if PAGE_SIZE == 0x1000
  791. return spufs_ps_nopfn(vma, address, 0x1c000, 0x1000);
  792. #elif PAGE_SIZE == 0x10000
  793. /* For 64k pages, both signal1 and signal2 can be used to mmap the whole
  794. * signal 1 and 2 area
  795. */
  796. return spufs_ps_nopfn(vma, address, 0x10000, 0x10000);
  797. #else
  798. #error unsupported page size
  799. #endif
  800. }
  801. static struct vm_operations_struct spufs_signal2_mmap_vmops = {
  802. .nopfn = spufs_signal2_mmap_nopfn,
  803. };
  804. static int spufs_signal2_mmap(struct file *file, struct vm_area_struct *vma)
  805. {
  806. if (!(vma->vm_flags & VM_SHARED))
  807. return -EINVAL;
  808. vma->vm_flags |= VM_IO | VM_PFNMAP;
  809. vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
  810. | _PAGE_NO_CACHE | _PAGE_GUARDED);
  811. vma->vm_ops = &spufs_signal2_mmap_vmops;
  812. return 0;
  813. }
  814. #else /* SPUFS_MMAP_4K */
  815. #define spufs_signal2_mmap NULL
  816. #endif /* !SPUFS_MMAP_4K */
  817. static const struct file_operations spufs_signal2_fops = {
  818. .open = spufs_signal2_open,
  819. .release = spufs_signal2_release,
  820. .read = spufs_signal2_read,
  821. .write = spufs_signal2_write,
  822. .mmap = spufs_signal2_mmap,
  823. };
  824. static void spufs_signal1_type_set(void *data, u64 val)
  825. {
  826. struct spu_context *ctx = data;
  827. spu_acquire(ctx);
  828. ctx->ops->signal1_type_set(ctx, val);
  829. spu_release(ctx);
  830. }
  831. static u64 __spufs_signal1_type_get(void *data)
  832. {
  833. struct spu_context *ctx = data;
  834. return ctx->ops->signal1_type_get(ctx);
  835. }
  836. static u64 spufs_signal1_type_get(void *data)
  837. {
  838. struct spu_context *ctx = data;
  839. u64 ret;
  840. spu_acquire(ctx);
  841. ret = __spufs_signal1_type_get(data);
  842. spu_release(ctx);
  843. return ret;
  844. }
  845. DEFINE_SIMPLE_ATTRIBUTE(spufs_signal1_type, spufs_signal1_type_get,
  846. spufs_signal1_type_set, "%llu");
  847. static void spufs_signal2_type_set(void *data, u64 val)
  848. {
  849. struct spu_context *ctx = data;
  850. spu_acquire(ctx);
  851. ctx->ops->signal2_type_set(ctx, val);
  852. spu_release(ctx);
  853. }
  854. static u64 __spufs_signal2_type_get(void *data)
  855. {
  856. struct spu_context *ctx = data;
  857. return ctx->ops->signal2_type_get(ctx);
  858. }
  859. static u64 spufs_signal2_type_get(void *data)
  860. {
  861. struct spu_context *ctx = data;
  862. u64 ret;
  863. spu_acquire(ctx);
  864. ret = __spufs_signal2_type_get(data);
  865. spu_release(ctx);
  866. return ret;
  867. }
  868. DEFINE_SIMPLE_ATTRIBUTE(spufs_signal2_type, spufs_signal2_type_get,
  869. spufs_signal2_type_set, "%llu");
  870. #if SPUFS_MMAP_4K
  871. static unsigned long spufs_mss_mmap_nopfn(struct vm_area_struct *vma,
  872. unsigned long address)
  873. {
  874. return spufs_ps_nopfn(vma, address, 0x0000, 0x1000);
  875. }
  876. static struct vm_operations_struct spufs_mss_mmap_vmops = {
  877. .nopfn = spufs_mss_mmap_nopfn,
  878. };
  879. /*
  880. * mmap support for problem state MFC DMA area [0x0000 - 0x0fff].
  881. */
  882. static int spufs_mss_mmap(struct file *file, struct vm_area_struct *vma)
  883. {
  884. if (!(vma->vm_flags & VM_SHARED))
  885. return -EINVAL;
  886. vma->vm_flags |= VM_IO | VM_PFNMAP;
  887. vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
  888. | _PAGE_NO_CACHE | _PAGE_GUARDED);
  889. vma->vm_ops = &spufs_mss_mmap_vmops;
  890. return 0;
  891. }
  892. #else /* SPUFS_MMAP_4K */
  893. #define spufs_mss_mmap NULL
  894. #endif /* !SPUFS_MMAP_4K */
  895. static int spufs_mss_open(struct inode *inode, struct file *file)
  896. {
  897. struct spufs_inode_info *i = SPUFS_I(inode);
  898. struct spu_context *ctx = i->i_ctx;
  899. file->private_data = i->i_ctx;
  900. spin_lock(&ctx->mapping_lock);
  901. if (!i->i_openers++)
  902. ctx->mss = inode->i_mapping;
  903. spin_unlock(&ctx->mapping_lock);
  904. smp_wmb();
  905. return nonseekable_open(inode, file);
  906. }
  907. static int
  908. spufs_mss_release(struct inode *inode, struct file *file)
  909. {
  910. struct spufs_inode_info *i = SPUFS_I(inode);
  911. struct spu_context *ctx = i->i_ctx;
  912. spin_lock(&ctx->mapping_lock);
  913. if (!--i->i_openers)
  914. ctx->mss = NULL;
  915. spin_unlock(&ctx->mapping_lock);
  916. smp_wmb();
  917. return 0;
  918. }
  919. static const struct file_operations spufs_mss_fops = {
  920. .open = spufs_mss_open,
  921. .release = spufs_mss_release,
  922. .mmap = spufs_mss_mmap,
  923. };
  924. static unsigned long spufs_psmap_mmap_nopfn(struct vm_area_struct *vma,
  925. unsigned long address)
  926. {
  927. return spufs_ps_nopfn(vma, address, 0x0000, 0x20000);
  928. }
  929. static struct vm_operations_struct spufs_psmap_mmap_vmops = {
  930. .nopfn = spufs_psmap_mmap_nopfn,
  931. };
  932. /*
  933. * mmap support for full problem state area [0x00000 - 0x1ffff].
  934. */
  935. static int spufs_psmap_mmap(struct file *file, struct vm_area_struct *vma)
  936. {
  937. if (!(vma->vm_flags & VM_SHARED))
  938. return -EINVAL;
  939. vma->vm_flags |= VM_IO | VM_PFNMAP;
  940. vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
  941. | _PAGE_NO_CACHE | _PAGE_GUARDED);
  942. vma->vm_ops = &spufs_psmap_mmap_vmops;
  943. return 0;
  944. }
  945. static int spufs_psmap_open(struct inode *inode, struct file *file)
  946. {
  947. struct spufs_inode_info *i = SPUFS_I(inode);
  948. struct spu_context *ctx = i->i_ctx;
  949. spin_lock(&ctx->mapping_lock);
  950. file->private_data = i->i_ctx;
  951. if (!i->i_openers++)
  952. ctx->psmap = inode->i_mapping;
  953. spin_unlock(&ctx->mapping_lock);
  954. smp_wmb();
  955. return nonseekable_open(inode, file);
  956. }
  957. static int
  958. spufs_psmap_release(struct inode *inode, struct file *file)
  959. {
  960. struct spufs_inode_info *i = SPUFS_I(inode);
  961. struct spu_context *ctx = i->i_ctx;
  962. spin_lock(&ctx->mapping_lock);
  963. if (!--i->i_openers)
  964. ctx->psmap = NULL;
  965. spin_unlock(&ctx->mapping_lock);
  966. smp_wmb();
  967. return 0;
  968. }
  969. static const struct file_operations spufs_psmap_fops = {
  970. .open = spufs_psmap_open,
  971. .release = spufs_psmap_release,
  972. .mmap = spufs_psmap_mmap,
  973. };
  974. #if SPUFS_MMAP_4K
  975. static unsigned long spufs_mfc_mmap_nopfn(struct vm_area_struct *vma,
  976. unsigned long address)
  977. {
  978. return spufs_ps_nopfn(vma, address, 0x3000, 0x1000);
  979. }
  980. static struct vm_operations_struct spufs_mfc_mmap_vmops = {
  981. .nopfn = spufs_mfc_mmap_nopfn,
  982. };
  983. /*
  984. * mmap support for problem state MFC DMA area [0x0000 - 0x0fff].
  985. */
  986. static int spufs_mfc_mmap(struct file *file, struct vm_area_struct *vma)
  987. {
  988. if (!(vma->vm_flags & VM_SHARED))
  989. return -EINVAL;
  990. vma->vm_flags |= VM_IO | VM_PFNMAP;
  991. vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
  992. | _PAGE_NO_CACHE | _PAGE_GUARDED);
  993. vma->vm_ops = &spufs_mfc_mmap_vmops;
  994. return 0;
  995. }
  996. #else /* SPUFS_MMAP_4K */
  997. #define spufs_mfc_mmap NULL
  998. #endif /* !SPUFS_MMAP_4K */
  999. static int spufs_mfc_open(struct inode *inode, struct file *file)
  1000. {
  1001. struct spufs_inode_info *i = SPUFS_I(inode);
  1002. struct spu_context *ctx = i->i_ctx;
  1003. /* we don't want to deal with DMA into other processes */
  1004. if (ctx->owner != current->mm)
  1005. return -EINVAL;
  1006. if (atomic_read(&inode->i_count) != 1)
  1007. return -EBUSY;
  1008. spin_lock(&ctx->mapping_lock);
  1009. file->private_data = ctx;
  1010. if (!i->i_openers++)
  1011. ctx->mfc = inode->i_mapping;
  1012. spin_unlock(&ctx->mapping_lock);
  1013. smp_wmb();
  1014. return nonseekable_open(inode, file);
  1015. }
  1016. static int
  1017. spufs_mfc_release(struct inode *inode, struct file *file)
  1018. {
  1019. struct spufs_inode_info *i = SPUFS_I(inode);
  1020. struct spu_context *ctx = i->i_ctx;
  1021. spin_lock(&ctx->mapping_lock);
  1022. if (!--i->i_openers)
  1023. ctx->mfc = NULL;
  1024. spin_unlock(&ctx->mapping_lock);
  1025. smp_wmb();
  1026. return 0;
  1027. }
  1028. /* interrupt-level mfc callback function. */
  1029. void spufs_mfc_callback(struct spu *spu)
  1030. {
  1031. struct spu_context *ctx = spu->ctx;
  1032. wake_up_all(&ctx->mfc_wq);
  1033. pr_debug("%s %s\n", __FUNCTION__, spu->name);
  1034. if (ctx->mfc_fasync) {
  1035. u32 free_elements, tagstatus;
  1036. unsigned int mask;
  1037. /* no need for spu_acquire in interrupt context */
  1038. free_elements = ctx->ops->get_mfc_free_elements(ctx);
  1039. tagstatus = ctx->ops->read_mfc_tagstatus(ctx);
  1040. mask = 0;
  1041. if (free_elements & 0xffff)
  1042. mask |= POLLOUT;
  1043. if (tagstatus & ctx->tagwait)
  1044. mask |= POLLIN;
  1045. kill_fasync(&ctx->mfc_fasync, SIGIO, mask);
  1046. }
  1047. }
  1048. static int spufs_read_mfc_tagstatus(struct spu_context *ctx, u32 *status)
  1049. {
  1050. /* See if there is one tag group is complete */
  1051. /* FIXME we need locking around tagwait */
  1052. *status = ctx->ops->read_mfc_tagstatus(ctx) & ctx->tagwait;
  1053. ctx->tagwait &= ~*status;
  1054. if (*status)
  1055. return 1;
  1056. /* enable interrupt waiting for any tag group,
  1057. may silently fail if interrupts are already enabled */
  1058. ctx->ops->set_mfc_query(ctx, ctx->tagwait, 1);
  1059. return 0;
  1060. }
  1061. static ssize_t spufs_mfc_read(struct file *file, char __user *buffer,
  1062. size_t size, loff_t *pos)
  1063. {
  1064. struct spu_context *ctx = file->private_data;
  1065. int ret = -EINVAL;
  1066. u32 status;
  1067. if (size != 4)
  1068. goto out;
  1069. spu_acquire(ctx);
  1070. if (file->f_flags & O_NONBLOCK) {
  1071. status = ctx->ops->read_mfc_tagstatus(ctx);
  1072. if (!(status & ctx->tagwait))
  1073. ret = -EAGAIN;
  1074. else
  1075. ctx->tagwait &= ~status;
  1076. } else {
  1077. ret = spufs_wait(ctx->mfc_wq,
  1078. spufs_read_mfc_tagstatus(ctx, &status));
  1079. }
  1080. spu_release(ctx);
  1081. if (ret)
  1082. goto out;
  1083. ret = 4;
  1084. if (copy_to_user(buffer, &status, 4))
  1085. ret = -EFAULT;
  1086. out:
  1087. return ret;
  1088. }
  1089. static int spufs_check_valid_dma(struct mfc_dma_command *cmd)
  1090. {
  1091. pr_debug("queueing DMA %x %lx %x %x %x\n", cmd->lsa,
  1092. cmd->ea, cmd->size, cmd->tag, cmd->cmd);
  1093. switch (cmd->cmd) {
  1094. case MFC_PUT_CMD:
  1095. case MFC_PUTF_CMD:
  1096. case MFC_PUTB_CMD:
  1097. case MFC_GET_CMD:
  1098. case MFC_GETF_CMD:
  1099. case MFC_GETB_CMD:
  1100. break;
  1101. default:
  1102. pr_debug("invalid DMA opcode %x\n", cmd->cmd);
  1103. return -EIO;
  1104. }
  1105. if ((cmd->lsa & 0xf) != (cmd->ea &0xf)) {
  1106. pr_debug("invalid DMA alignment, ea %lx lsa %x\n",
  1107. cmd->ea, cmd->lsa);
  1108. return -EIO;
  1109. }
  1110. switch (cmd->size & 0xf) {
  1111. case 1:
  1112. break;
  1113. case 2:
  1114. if (cmd->lsa & 1)
  1115. goto error;
  1116. break;
  1117. case 4:
  1118. if (cmd->lsa & 3)
  1119. goto error;
  1120. break;
  1121. case 8:
  1122. if (cmd->lsa & 7)
  1123. goto error;
  1124. break;
  1125. case 0:
  1126. if (cmd->lsa & 15)
  1127. goto error;
  1128. break;
  1129. error:
  1130. default:
  1131. pr_debug("invalid DMA alignment %x for size %x\n",
  1132. cmd->lsa & 0xf, cmd->size);
  1133. return -EIO;
  1134. }
  1135. if (cmd->size > 16 * 1024) {
  1136. pr_debug("invalid DMA size %x\n", cmd->size);
  1137. return -EIO;
  1138. }
  1139. if (cmd->tag & 0xfff0) {
  1140. /* we reserve the higher tag numbers for kernel use */
  1141. pr_debug("invalid DMA tag\n");
  1142. return -EIO;
  1143. }
  1144. if (cmd->class) {
  1145. /* not supported in this version */
  1146. pr_debug("invalid DMA class\n");
  1147. return -EIO;
  1148. }
  1149. return 0;
  1150. }
  1151. static int spu_send_mfc_command(struct spu_context *ctx,
  1152. struct mfc_dma_command cmd,
  1153. int *error)
  1154. {
  1155. *error = ctx->ops->send_mfc_command(ctx, &cmd);
  1156. if (*error == -EAGAIN) {
  1157. /* wait for any tag group to complete
  1158. so we have space for the new command */
  1159. ctx->ops->set_mfc_query(ctx, ctx->tagwait, 1);
  1160. /* try again, because the queue might be
  1161. empty again */
  1162. *error = ctx->ops->send_mfc_command(ctx, &cmd);
  1163. if (*error == -EAGAIN)
  1164. return 0;
  1165. }
  1166. return 1;
  1167. }
  1168. static ssize_t spufs_mfc_write(struct file *file, const char __user *buffer,
  1169. size_t size, loff_t *pos)
  1170. {
  1171. struct spu_context *ctx = file->private_data;
  1172. struct mfc_dma_command cmd;
  1173. int ret = -EINVAL;
  1174. if (size != sizeof cmd)
  1175. goto out;
  1176. ret = -EFAULT;
  1177. if (copy_from_user(&cmd, buffer, sizeof cmd))
  1178. goto out;
  1179. ret = spufs_check_valid_dma(&cmd);
  1180. if (ret)
  1181. goto out;
  1182. spu_acquire_runnable(ctx, 0);
  1183. if (file->f_flags & O_NONBLOCK) {
  1184. ret = ctx->ops->send_mfc_command(ctx, &cmd);
  1185. } else {
  1186. int status;
  1187. ret = spufs_wait(ctx->mfc_wq,
  1188. spu_send_mfc_command(ctx, cmd, &status));
  1189. if (status)
  1190. ret = status;
  1191. }
  1192. spu_release(ctx);
  1193. if (ret)
  1194. goto out;
  1195. ctx->tagwait |= 1 << cmd.tag;
  1196. ret = size;
  1197. out:
  1198. return ret;
  1199. }
  1200. static unsigned int spufs_mfc_poll(struct file *file,poll_table *wait)
  1201. {
  1202. struct spu_context *ctx = file->private_data;
  1203. u32 free_elements, tagstatus;
  1204. unsigned int mask;
  1205. spu_acquire(ctx);
  1206. ctx->ops->set_mfc_query(ctx, ctx->tagwait, 2);
  1207. free_elements = ctx->ops->get_mfc_free_elements(ctx);
  1208. tagstatus = ctx->ops->read_mfc_tagstatus(ctx);
  1209. spu_release(ctx);
  1210. poll_wait(file, &ctx->mfc_wq, wait);
  1211. mask = 0;
  1212. if (free_elements & 0xffff)
  1213. mask |= POLLOUT | POLLWRNORM;
  1214. if (tagstatus & ctx->tagwait)
  1215. mask |= POLLIN | POLLRDNORM;
  1216. pr_debug("%s: free %d tagstatus %d tagwait %d\n", __FUNCTION__,
  1217. free_elements, tagstatus, ctx->tagwait);
  1218. return mask;
  1219. }
  1220. static int spufs_mfc_flush(struct file *file, fl_owner_t id)
  1221. {
  1222. struct spu_context *ctx = file->private_data;
  1223. int ret;
  1224. spu_acquire(ctx);
  1225. #if 0
  1226. /* this currently hangs */
  1227. ret = spufs_wait(ctx->mfc_wq,
  1228. ctx->ops->set_mfc_query(ctx, ctx->tagwait, 2));
  1229. if (ret)
  1230. goto out;
  1231. ret = spufs_wait(ctx->mfc_wq,
  1232. ctx->ops->read_mfc_tagstatus(ctx) == ctx->tagwait);
  1233. out:
  1234. #else
  1235. ret = 0;
  1236. #endif
  1237. spu_release(ctx);
  1238. return ret;
  1239. }
  1240. static int spufs_mfc_fsync(struct file *file, struct dentry *dentry,
  1241. int datasync)
  1242. {
  1243. return spufs_mfc_flush(file, NULL);
  1244. }
  1245. static int spufs_mfc_fasync(int fd, struct file *file, int on)
  1246. {
  1247. struct spu_context *ctx = file->private_data;
  1248. return fasync_helper(fd, file, on, &ctx->mfc_fasync);
  1249. }
  1250. static const struct file_operations spufs_mfc_fops = {
  1251. .open = spufs_mfc_open,
  1252. .release = spufs_mfc_release,
  1253. .read = spufs_mfc_read,
  1254. .write = spufs_mfc_write,
  1255. .poll = spufs_mfc_poll,
  1256. .flush = spufs_mfc_flush,
  1257. .fsync = spufs_mfc_fsync,
  1258. .fasync = spufs_mfc_fasync,
  1259. .mmap = spufs_mfc_mmap,
  1260. };
  1261. static void spufs_npc_set(void *data, u64 val)
  1262. {
  1263. struct spu_context *ctx = data;
  1264. spu_acquire(ctx);
  1265. ctx->ops->npc_write(ctx, val);
  1266. spu_release(ctx);
  1267. }
  1268. static u64 spufs_npc_get(void *data)
  1269. {
  1270. struct spu_context *ctx = data;
  1271. u64 ret;
  1272. spu_acquire(ctx);
  1273. ret = ctx->ops->npc_read(ctx);
  1274. spu_release(ctx);
  1275. return ret;
  1276. }
  1277. DEFINE_SIMPLE_ATTRIBUTE(spufs_npc_ops, spufs_npc_get, spufs_npc_set,
  1278. "0x%llx\n")
  1279. static void spufs_decr_set(void *data, u64 val)
  1280. {
  1281. struct spu_context *ctx = data;
  1282. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  1283. spu_acquire_saved(ctx);
  1284. lscsa->decr.slot[0] = (u32) val;
  1285. spu_release(ctx);
  1286. }
  1287. static u64 __spufs_decr_get(void *data)
  1288. {
  1289. struct spu_context *ctx = data;
  1290. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  1291. return lscsa->decr.slot[0];
  1292. }
  1293. static u64 spufs_decr_get(void *data)
  1294. {
  1295. struct spu_context *ctx = data;
  1296. u64 ret;
  1297. spu_acquire_saved(ctx);
  1298. ret = __spufs_decr_get(data);
  1299. spu_release(ctx);
  1300. return ret;
  1301. }
  1302. DEFINE_SIMPLE_ATTRIBUTE(spufs_decr_ops, spufs_decr_get, spufs_decr_set,
  1303. "0x%llx\n")
  1304. static void spufs_decr_status_set(void *data, u64 val)
  1305. {
  1306. struct spu_context *ctx = data;
  1307. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  1308. spu_acquire_saved(ctx);
  1309. lscsa->decr_status.slot[0] = (u32) val;
  1310. spu_release(ctx);
  1311. }
  1312. static u64 __spufs_decr_status_get(void *data)
  1313. {
  1314. struct spu_context *ctx = data;
  1315. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  1316. return lscsa->decr_status.slot[0];
  1317. }
  1318. static u64 spufs_decr_status_get(void *data)
  1319. {
  1320. struct spu_context *ctx = data;
  1321. u64 ret;
  1322. spu_acquire_saved(ctx);
  1323. ret = __spufs_decr_status_get(data);
  1324. spu_release(ctx);
  1325. return ret;
  1326. }
  1327. DEFINE_SIMPLE_ATTRIBUTE(spufs_decr_status_ops, spufs_decr_status_get,
  1328. spufs_decr_status_set, "0x%llx\n")
  1329. static void spufs_event_mask_set(void *data, u64 val)
  1330. {
  1331. struct spu_context *ctx = data;
  1332. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  1333. spu_acquire_saved(ctx);
  1334. lscsa->event_mask.slot[0] = (u32) val;
  1335. spu_release(ctx);
  1336. }
  1337. static u64 __spufs_event_mask_get(void *data)
  1338. {
  1339. struct spu_context *ctx = data;
  1340. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  1341. return lscsa->event_mask.slot[0];
  1342. }
  1343. static u64 spufs_event_mask_get(void *data)
  1344. {
  1345. struct spu_context *ctx = data;
  1346. u64 ret;
  1347. spu_acquire_saved(ctx);
  1348. ret = __spufs_event_mask_get(data);
  1349. spu_release(ctx);
  1350. return ret;
  1351. }
  1352. DEFINE_SIMPLE_ATTRIBUTE(spufs_event_mask_ops, spufs_event_mask_get,
  1353. spufs_event_mask_set, "0x%llx\n")
  1354. static u64 __spufs_event_status_get(void *data)
  1355. {
  1356. struct spu_context *ctx = data;
  1357. struct spu_state *state = &ctx->csa;
  1358. u64 stat;
  1359. stat = state->spu_chnlcnt_RW[0];
  1360. if (stat)
  1361. return state->spu_chnldata_RW[0];
  1362. return 0;
  1363. }
  1364. static u64 spufs_event_status_get(void *data)
  1365. {
  1366. struct spu_context *ctx = data;
  1367. u64 ret = 0;
  1368. spu_acquire_saved(ctx);
  1369. ret = __spufs_event_status_get(data);
  1370. spu_release(ctx);
  1371. return ret;
  1372. }
  1373. DEFINE_SIMPLE_ATTRIBUTE(spufs_event_status_ops, spufs_event_status_get,
  1374. NULL, "0x%llx\n")
  1375. static void spufs_srr0_set(void *data, u64 val)
  1376. {
  1377. struct spu_context *ctx = data;
  1378. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  1379. spu_acquire_saved(ctx);
  1380. lscsa->srr0.slot[0] = (u32) val;
  1381. spu_release(ctx);
  1382. }
  1383. static u64 spufs_srr0_get(void *data)
  1384. {
  1385. struct spu_context *ctx = data;
  1386. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  1387. u64 ret;
  1388. spu_acquire_saved(ctx);
  1389. ret = lscsa->srr0.slot[0];
  1390. spu_release(ctx);
  1391. return ret;
  1392. }
  1393. DEFINE_SIMPLE_ATTRIBUTE(spufs_srr0_ops, spufs_srr0_get, spufs_srr0_set,
  1394. "0x%llx\n")
  1395. static u64 spufs_id_get(void *data)
  1396. {
  1397. struct spu_context *ctx = data;
  1398. u64 num;
  1399. spu_acquire(ctx);
  1400. if (ctx->state == SPU_STATE_RUNNABLE)
  1401. num = ctx->spu->number;
  1402. else
  1403. num = (unsigned int)-1;
  1404. spu_release(ctx);
  1405. return num;
  1406. }
  1407. DEFINE_SIMPLE_ATTRIBUTE(spufs_id_ops, spufs_id_get, NULL, "0x%llx\n")
  1408. static u64 __spufs_object_id_get(void *data)
  1409. {
  1410. struct spu_context *ctx = data;
  1411. return ctx->object_id;
  1412. }
  1413. static u64 spufs_object_id_get(void *data)
  1414. {
  1415. /* FIXME: Should there really be no locking here? */
  1416. return __spufs_object_id_get(data);
  1417. }
  1418. static void spufs_object_id_set(void *data, u64 id)
  1419. {
  1420. struct spu_context *ctx = data;
  1421. ctx->object_id = id;
  1422. }
  1423. DEFINE_SIMPLE_ATTRIBUTE(spufs_object_id_ops, spufs_object_id_get,
  1424. spufs_object_id_set, "0x%llx\n");
  1425. static u64 __spufs_lslr_get(void *data)
  1426. {
  1427. struct spu_context *ctx = data;
  1428. return ctx->csa.priv2.spu_lslr_RW;
  1429. }
  1430. static u64 spufs_lslr_get(void *data)
  1431. {
  1432. struct spu_context *ctx = data;
  1433. u64 ret;
  1434. spu_acquire_saved(ctx);
  1435. ret = __spufs_lslr_get(data);
  1436. spu_release(ctx);
  1437. return ret;
  1438. }
  1439. DEFINE_SIMPLE_ATTRIBUTE(spufs_lslr_ops, spufs_lslr_get, NULL, "0x%llx\n")
  1440. static int spufs_info_open(struct inode *inode, struct file *file)
  1441. {
  1442. struct spufs_inode_info *i = SPUFS_I(inode);
  1443. struct spu_context *ctx = i->i_ctx;
  1444. file->private_data = ctx;
  1445. return 0;
  1446. }
  1447. static ssize_t __spufs_mbox_info_read(struct spu_context *ctx,
  1448. char __user *buf, size_t len, loff_t *pos)
  1449. {
  1450. u32 mbox_stat;
  1451. u32 data;
  1452. mbox_stat = ctx->csa.prob.mb_stat_R;
  1453. if (mbox_stat & 0x0000ff) {
  1454. data = ctx->csa.prob.pu_mb_R;
  1455. }
  1456. return simple_read_from_buffer(buf, len, pos, &data, sizeof data);
  1457. }
  1458. static ssize_t spufs_mbox_info_read(struct file *file, char __user *buf,
  1459. size_t len, loff_t *pos)
  1460. {
  1461. int ret;
  1462. struct spu_context *ctx = file->private_data;
  1463. if (!access_ok(VERIFY_WRITE, buf, len))
  1464. return -EFAULT;
  1465. spu_acquire_saved(ctx);
  1466. spin_lock(&ctx->csa.register_lock);
  1467. ret = __spufs_mbox_info_read(ctx, buf, len, pos);
  1468. spin_unlock(&ctx->csa.register_lock);
  1469. spu_release(ctx);
  1470. return ret;
  1471. }
  1472. static const struct file_operations spufs_mbox_info_fops = {
  1473. .open = spufs_info_open,
  1474. .read = spufs_mbox_info_read,
  1475. .llseek = generic_file_llseek,
  1476. };
  1477. static ssize_t __spufs_ibox_info_read(struct spu_context *ctx,
  1478. char __user *buf, size_t len, loff_t *pos)
  1479. {
  1480. u32 ibox_stat;
  1481. u32 data;
  1482. ibox_stat = ctx->csa.prob.mb_stat_R;
  1483. if (ibox_stat & 0xff0000) {
  1484. data = ctx->csa.priv2.puint_mb_R;
  1485. }
  1486. return simple_read_from_buffer(buf, len, pos, &data, sizeof data);
  1487. }
  1488. static ssize_t spufs_ibox_info_read(struct file *file, char __user *buf,
  1489. size_t len, loff_t *pos)
  1490. {
  1491. struct spu_context *ctx = file->private_data;
  1492. int ret;
  1493. if (!access_ok(VERIFY_WRITE, buf, len))
  1494. return -EFAULT;
  1495. spu_acquire_saved(ctx);
  1496. spin_lock(&ctx->csa.register_lock);
  1497. ret = __spufs_ibox_info_read(ctx, buf, len, pos);
  1498. spin_unlock(&ctx->csa.register_lock);
  1499. spu_release(ctx);
  1500. return ret;
  1501. }
  1502. static const struct file_operations spufs_ibox_info_fops = {
  1503. .open = spufs_info_open,
  1504. .read = spufs_ibox_info_read,
  1505. .llseek = generic_file_llseek,
  1506. };
  1507. static ssize_t __spufs_wbox_info_read(struct spu_context *ctx,
  1508. char __user *buf, size_t len, loff_t *pos)
  1509. {
  1510. int i, cnt;
  1511. u32 data[4];
  1512. u32 wbox_stat;
  1513. wbox_stat = ctx->csa.prob.mb_stat_R;
  1514. cnt = 4 - ((wbox_stat & 0x00ff00) >> 8);
  1515. for (i = 0; i < cnt; i++) {
  1516. data[i] = ctx->csa.spu_mailbox_data[i];
  1517. }
  1518. return simple_read_from_buffer(buf, len, pos, &data,
  1519. cnt * sizeof(u32));
  1520. }
  1521. static ssize_t spufs_wbox_info_read(struct file *file, char __user *buf,
  1522. size_t len, loff_t *pos)
  1523. {
  1524. struct spu_context *ctx = file->private_data;
  1525. int ret;
  1526. if (!access_ok(VERIFY_WRITE, buf, len))
  1527. return -EFAULT;
  1528. spu_acquire_saved(ctx);
  1529. spin_lock(&ctx->csa.register_lock);
  1530. ret = __spufs_wbox_info_read(ctx, buf, len, pos);
  1531. spin_unlock(&ctx->csa.register_lock);
  1532. spu_release(ctx);
  1533. return ret;
  1534. }
  1535. static const struct file_operations spufs_wbox_info_fops = {
  1536. .open = spufs_info_open,
  1537. .read = spufs_wbox_info_read,
  1538. .llseek = generic_file_llseek,
  1539. };
  1540. static ssize_t __spufs_dma_info_read(struct spu_context *ctx,
  1541. char __user *buf, size_t len, loff_t *pos)
  1542. {
  1543. struct spu_dma_info info;
  1544. struct mfc_cq_sr *qp, *spuqp;
  1545. int i;
  1546. info.dma_info_type = ctx->csa.priv2.spu_tag_status_query_RW;
  1547. info.dma_info_mask = ctx->csa.lscsa->tag_mask.slot[0];
  1548. info.dma_info_status = ctx->csa.spu_chnldata_RW[24];
  1549. info.dma_info_stall_and_notify = ctx->csa.spu_chnldata_RW[25];
  1550. info.dma_info_atomic_command_status = ctx->csa.spu_chnldata_RW[27];
  1551. for (i = 0; i < 16; i++) {
  1552. qp = &info.dma_info_command_data[i];
  1553. spuqp = &ctx->csa.priv2.spuq[i];
  1554. qp->mfc_cq_data0_RW = spuqp->mfc_cq_data0_RW;
  1555. qp->mfc_cq_data1_RW = spuqp->mfc_cq_data1_RW;
  1556. qp->mfc_cq_data2_RW = spuqp->mfc_cq_data2_RW;
  1557. qp->mfc_cq_data3_RW = spuqp->mfc_cq_data3_RW;
  1558. }
  1559. return simple_read_from_buffer(buf, len, pos, &info,
  1560. sizeof info);
  1561. }
  1562. static ssize_t spufs_dma_info_read(struct file *file, char __user *buf,
  1563. size_t len, loff_t *pos)
  1564. {
  1565. struct spu_context *ctx = file->private_data;
  1566. int ret;
  1567. if (!access_ok(VERIFY_WRITE, buf, len))
  1568. return -EFAULT;
  1569. spu_acquire_saved(ctx);
  1570. spin_lock(&ctx->csa.register_lock);
  1571. ret = __spufs_dma_info_read(ctx, buf, len, pos);
  1572. spin_unlock(&ctx->csa.register_lock);
  1573. spu_release(ctx);
  1574. return ret;
  1575. }
  1576. static const struct file_operations spufs_dma_info_fops = {
  1577. .open = spufs_info_open,
  1578. .read = spufs_dma_info_read,
  1579. };
  1580. static ssize_t __spufs_proxydma_info_read(struct spu_context *ctx,
  1581. char __user *buf, size_t len, loff_t *pos)
  1582. {
  1583. struct spu_proxydma_info info;
  1584. struct mfc_cq_sr *qp, *puqp;
  1585. int ret = sizeof info;
  1586. int i;
  1587. if (len < ret)
  1588. return -EINVAL;
  1589. if (!access_ok(VERIFY_WRITE, buf, len))
  1590. return -EFAULT;
  1591. info.proxydma_info_type = ctx->csa.prob.dma_querytype_RW;
  1592. info.proxydma_info_mask = ctx->csa.prob.dma_querymask_RW;
  1593. info.proxydma_info_status = ctx->csa.prob.dma_tagstatus_R;
  1594. for (i = 0; i < 8; i++) {
  1595. qp = &info.proxydma_info_command_data[i];
  1596. puqp = &ctx->csa.priv2.puq[i];
  1597. qp->mfc_cq_data0_RW = puqp->mfc_cq_data0_RW;
  1598. qp->mfc_cq_data1_RW = puqp->mfc_cq_data1_RW;
  1599. qp->mfc_cq_data2_RW = puqp->mfc_cq_data2_RW;
  1600. qp->mfc_cq_data3_RW = puqp->mfc_cq_data3_RW;
  1601. }
  1602. return simple_read_from_buffer(buf, len, pos, &info,
  1603. sizeof info);
  1604. }
  1605. static ssize_t spufs_proxydma_info_read(struct file *file, char __user *buf,
  1606. size_t len, loff_t *pos)
  1607. {
  1608. struct spu_context *ctx = file->private_data;
  1609. int ret;
  1610. spu_acquire_saved(ctx);
  1611. spin_lock(&ctx->csa.register_lock);
  1612. ret = __spufs_proxydma_info_read(ctx, buf, len, pos);
  1613. spin_unlock(&ctx->csa.register_lock);
  1614. spu_release(ctx);
  1615. return ret;
  1616. }
  1617. static const struct file_operations spufs_proxydma_info_fops = {
  1618. .open = spufs_info_open,
  1619. .read = spufs_proxydma_info_read,
  1620. };
  1621. struct tree_descr spufs_dir_contents[] = {
  1622. { "mem", &spufs_mem_fops, 0666, },
  1623. { "regs", &spufs_regs_fops, 0666, },
  1624. { "mbox", &spufs_mbox_fops, 0444, },
  1625. { "ibox", &spufs_ibox_fops, 0444, },
  1626. { "wbox", &spufs_wbox_fops, 0222, },
  1627. { "mbox_stat", &spufs_mbox_stat_fops, 0444, },
  1628. { "ibox_stat", &spufs_ibox_stat_fops, 0444, },
  1629. { "wbox_stat", &spufs_wbox_stat_fops, 0444, },
  1630. { "signal1", &spufs_signal1_fops, 0666, },
  1631. { "signal2", &spufs_signal2_fops, 0666, },
  1632. { "signal1_type", &spufs_signal1_type, 0666, },
  1633. { "signal2_type", &spufs_signal2_type, 0666, },
  1634. { "cntl", &spufs_cntl_fops, 0666, },
  1635. { "fpcr", &spufs_fpcr_fops, 0666, },
  1636. { "lslr", &spufs_lslr_ops, 0444, },
  1637. { "mfc", &spufs_mfc_fops, 0666, },
  1638. { "mss", &spufs_mss_fops, 0666, },
  1639. { "npc", &spufs_npc_ops, 0666, },
  1640. { "srr0", &spufs_srr0_ops, 0666, },
  1641. { "decr", &spufs_decr_ops, 0666, },
  1642. { "decr_status", &spufs_decr_status_ops, 0666, },
  1643. { "event_mask", &spufs_event_mask_ops, 0666, },
  1644. { "event_status", &spufs_event_status_ops, 0444, },
  1645. { "psmap", &spufs_psmap_fops, 0666, },
  1646. { "phys-id", &spufs_id_ops, 0666, },
  1647. { "object-id", &spufs_object_id_ops, 0666, },
  1648. { "mbox_info", &spufs_mbox_info_fops, 0444, },
  1649. { "ibox_info", &spufs_ibox_info_fops, 0444, },
  1650. { "wbox_info", &spufs_wbox_info_fops, 0444, },
  1651. { "dma_info", &spufs_dma_info_fops, 0444, },
  1652. { "proxydma_info", &spufs_proxydma_info_fops, 0444, },
  1653. {},
  1654. };
  1655. struct tree_descr spufs_dir_nosched_contents[] = {
  1656. { "mem", &spufs_mem_fops, 0666, },
  1657. { "mbox", &spufs_mbox_fops, 0444, },
  1658. { "ibox", &spufs_ibox_fops, 0444, },
  1659. { "wbox", &spufs_wbox_fops, 0222, },
  1660. { "mbox_stat", &spufs_mbox_stat_fops, 0444, },
  1661. { "ibox_stat", &spufs_ibox_stat_fops, 0444, },
  1662. { "wbox_stat", &spufs_wbox_stat_fops, 0444, },
  1663. { "signal1", &spufs_signal1_fops, 0666, },
  1664. { "signal2", &spufs_signal2_fops, 0666, },
  1665. { "signal1_type", &spufs_signal1_type, 0666, },
  1666. { "signal2_type", &spufs_signal2_type, 0666, },
  1667. { "mss", &spufs_mss_fops, 0666, },
  1668. { "mfc", &spufs_mfc_fops, 0666, },
  1669. { "cntl", &spufs_cntl_fops, 0666, },
  1670. { "npc", &spufs_npc_ops, 0666, },
  1671. { "psmap", &spufs_psmap_fops, 0666, },
  1672. { "phys-id", &spufs_id_ops, 0666, },
  1673. { "object-id", &spufs_object_id_ops, 0666, },
  1674. {},
  1675. };
  1676. struct spufs_coredump_reader spufs_coredump_read[] = {
  1677. { "regs", __spufs_regs_read, NULL, 128 * 16 },
  1678. { "fpcr", __spufs_fpcr_read, NULL, 16 },
  1679. { "lslr", NULL, __spufs_lslr_get, 11 },
  1680. { "decr", NULL, __spufs_decr_get, 11 },
  1681. { "decr_status", NULL, __spufs_decr_status_get, 11 },
  1682. { "mem", __spufs_mem_read, NULL, 256 * 1024, },
  1683. { "signal1", __spufs_signal1_read, NULL, 4 },
  1684. { "signal1_type", NULL, __spufs_signal1_type_get, 2 },
  1685. { "signal2", __spufs_signal2_read, NULL, 4 },
  1686. { "signal2_type", NULL, __spufs_signal2_type_get, 2 },
  1687. { "event_mask", NULL, __spufs_event_mask_get, 8 },
  1688. { "event_status", NULL, __spufs_event_status_get, 8 },
  1689. { "mbox_info", __spufs_mbox_info_read, NULL, 4 },
  1690. { "ibox_info", __spufs_ibox_info_read, NULL, 4 },
  1691. { "wbox_info", __spufs_wbox_info_read, NULL, 16 },
  1692. { "dma_info", __spufs_dma_info_read, NULL, 69 * 8 },
  1693. { "proxydma_info", __spufs_proxydma_info_read, NULL, 35 * 8 },
  1694. { "object-id", NULL, __spufs_object_id_get, 19 },
  1695. { },
  1696. };
  1697. int spufs_coredump_num_notes = ARRAY_SIZE(spufs_coredump_read) - 1;