file.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410
  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/uaccess.h>
  33. #include "spufs.h"
  34. #define SPUFS_MMAP_4K (PAGE_SIZE == 0x1000)
  35. static int
  36. spufs_mem_open(struct inode *inode, struct file *file)
  37. {
  38. struct spufs_inode_info *i = SPUFS_I(inode);
  39. struct spu_context *ctx = i->i_ctx;
  40. file->private_data = ctx;
  41. file->f_mapping = inode->i_mapping;
  42. ctx->local_store = inode->i_mapping;
  43. return 0;
  44. }
  45. static ssize_t
  46. spufs_mem_read(struct file *file, char __user *buffer,
  47. size_t size, loff_t *pos)
  48. {
  49. struct spu_context *ctx = file->private_data;
  50. char *local_store;
  51. int ret;
  52. spu_acquire(ctx);
  53. local_store = ctx->ops->get_ls(ctx);
  54. ret = simple_read_from_buffer(buffer, size, pos, local_store, LS_SIZE);
  55. spu_release(ctx);
  56. return ret;
  57. }
  58. static ssize_t
  59. spufs_mem_write(struct file *file, const char __user *buffer,
  60. size_t size, loff_t *pos)
  61. {
  62. struct spu_context *ctx = file->private_data;
  63. char *local_store;
  64. int ret;
  65. size = min_t(ssize_t, LS_SIZE - *pos, size);
  66. if (size <= 0)
  67. return -EFBIG;
  68. *pos += size;
  69. spu_acquire(ctx);
  70. local_store = ctx->ops->get_ls(ctx);
  71. ret = copy_from_user(local_store + *pos - size,
  72. buffer, size) ? -EFAULT : size;
  73. spu_release(ctx);
  74. return ret;
  75. }
  76. static struct page *
  77. spufs_mem_mmap_nopage(struct vm_area_struct *vma,
  78. unsigned long address, int *type)
  79. {
  80. struct page *page = NOPAGE_SIGBUS;
  81. struct spu_context *ctx = vma->vm_file->private_data;
  82. unsigned long offset = address - vma->vm_start;
  83. offset += vma->vm_pgoff << PAGE_SHIFT;
  84. spu_acquire(ctx);
  85. if (ctx->state == SPU_STATE_SAVED)
  86. page = vmalloc_to_page(ctx->csa.lscsa->ls + offset);
  87. else
  88. page = pfn_to_page((ctx->spu->local_store_phys + offset)
  89. >> PAGE_SHIFT);
  90. spu_release(ctx);
  91. if (type)
  92. *type = VM_FAULT_MINOR;
  93. page_cache_get(page);
  94. return page;
  95. }
  96. static struct vm_operations_struct spufs_mem_mmap_vmops = {
  97. .nopage = spufs_mem_mmap_nopage,
  98. };
  99. static int
  100. spufs_mem_mmap(struct file *file, struct vm_area_struct *vma)
  101. {
  102. if (!(vma->vm_flags & VM_SHARED))
  103. return -EINVAL;
  104. /* FIXME: */
  105. vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
  106. | _PAGE_NO_CACHE);
  107. vma->vm_ops = &spufs_mem_mmap_vmops;
  108. return 0;
  109. }
  110. static struct file_operations spufs_mem_fops = {
  111. .open = spufs_mem_open,
  112. .read = spufs_mem_read,
  113. .write = spufs_mem_write,
  114. .llseek = generic_file_llseek,
  115. .mmap = spufs_mem_mmap,
  116. };
  117. static struct page *spufs_ps_nopage(struct vm_area_struct *vma,
  118. unsigned long address,
  119. int *type, unsigned long ps_offs,
  120. unsigned long ps_size)
  121. {
  122. struct page *page = NOPAGE_SIGBUS;
  123. int fault_type = VM_FAULT_SIGBUS;
  124. struct spu_context *ctx = vma->vm_file->private_data;
  125. unsigned long offset = address - vma->vm_start;
  126. unsigned long area;
  127. int ret;
  128. offset += vma->vm_pgoff << PAGE_SHIFT;
  129. if (offset >= ps_size)
  130. goto out;
  131. ret = spu_acquire_runnable(ctx);
  132. if (ret)
  133. goto out;
  134. area = ctx->spu->problem_phys + ps_offs;
  135. page = pfn_to_page((area + offset) >> PAGE_SHIFT);
  136. fault_type = VM_FAULT_MINOR;
  137. page_cache_get(page);
  138. spu_release(ctx);
  139. out:
  140. if (type)
  141. *type = fault_type;
  142. return page;
  143. }
  144. #if SPUFS_MMAP_4K
  145. static struct page *spufs_cntl_mmap_nopage(struct vm_area_struct *vma,
  146. unsigned long address, int *type)
  147. {
  148. return spufs_ps_nopage(vma, address, type, 0x4000, 0x1000);
  149. }
  150. static struct vm_operations_struct spufs_cntl_mmap_vmops = {
  151. .nopage = spufs_cntl_mmap_nopage,
  152. };
  153. /*
  154. * mmap support for problem state control area [0x4000 - 0x4fff].
  155. */
  156. static int spufs_cntl_mmap(struct file *file, struct vm_area_struct *vma)
  157. {
  158. if (!(vma->vm_flags & VM_SHARED))
  159. return -EINVAL;
  160. vma->vm_flags |= VM_RESERVED;
  161. vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
  162. | _PAGE_NO_CACHE | _PAGE_GUARDED);
  163. vma->vm_ops = &spufs_cntl_mmap_vmops;
  164. return 0;
  165. }
  166. #else /* SPUFS_MMAP_4K */
  167. #define spufs_cntl_mmap NULL
  168. #endif /* !SPUFS_MMAP_4K */
  169. static int spufs_cntl_open(struct inode *inode, struct file *file)
  170. {
  171. struct spufs_inode_info *i = SPUFS_I(inode);
  172. struct spu_context *ctx = i->i_ctx;
  173. file->private_data = ctx;
  174. file->f_mapping = inode->i_mapping;
  175. ctx->cntl = inode->i_mapping;
  176. return 0;
  177. }
  178. static ssize_t
  179. spufs_cntl_read(struct file *file, char __user *buffer,
  180. size_t size, loff_t *pos)
  181. {
  182. /* FIXME: read from spu status */
  183. return -EINVAL;
  184. }
  185. static ssize_t
  186. spufs_cntl_write(struct file *file, const char __user *buffer,
  187. size_t size, loff_t *pos)
  188. {
  189. /* FIXME: write to runctl bit */
  190. return -EINVAL;
  191. }
  192. static struct file_operations spufs_cntl_fops = {
  193. .open = spufs_cntl_open,
  194. .read = spufs_cntl_read,
  195. .write = spufs_cntl_write,
  196. .mmap = spufs_cntl_mmap,
  197. };
  198. static int
  199. spufs_regs_open(struct inode *inode, struct file *file)
  200. {
  201. struct spufs_inode_info *i = SPUFS_I(inode);
  202. file->private_data = i->i_ctx;
  203. return 0;
  204. }
  205. static ssize_t
  206. spufs_regs_read(struct file *file, char __user *buffer,
  207. size_t size, loff_t *pos)
  208. {
  209. struct spu_context *ctx = file->private_data;
  210. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  211. int ret;
  212. spu_acquire_saved(ctx);
  213. ret = simple_read_from_buffer(buffer, size, pos,
  214. lscsa->gprs, sizeof lscsa->gprs);
  215. spu_release(ctx);
  216. return ret;
  217. }
  218. static ssize_t
  219. spufs_regs_write(struct file *file, const char __user *buffer,
  220. size_t size, loff_t *pos)
  221. {
  222. struct spu_context *ctx = file->private_data;
  223. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  224. int ret;
  225. size = min_t(ssize_t, sizeof lscsa->gprs - *pos, size);
  226. if (size <= 0)
  227. return -EFBIG;
  228. *pos += size;
  229. spu_acquire_saved(ctx);
  230. ret = copy_from_user(lscsa->gprs + *pos - size,
  231. buffer, size) ? -EFAULT : size;
  232. spu_release(ctx);
  233. return ret;
  234. }
  235. static struct file_operations spufs_regs_fops = {
  236. .open = spufs_regs_open,
  237. .read = spufs_regs_read,
  238. .write = spufs_regs_write,
  239. .llseek = generic_file_llseek,
  240. };
  241. static ssize_t
  242. spufs_fpcr_read(struct file *file, char __user * buffer,
  243. size_t size, loff_t * pos)
  244. {
  245. struct spu_context *ctx = file->private_data;
  246. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  247. int ret;
  248. spu_acquire_saved(ctx);
  249. ret = simple_read_from_buffer(buffer, size, pos,
  250. &lscsa->fpcr, sizeof(lscsa->fpcr));
  251. spu_release(ctx);
  252. return ret;
  253. }
  254. static ssize_t
  255. spufs_fpcr_write(struct file *file, const char __user * buffer,
  256. size_t size, loff_t * pos)
  257. {
  258. struct spu_context *ctx = file->private_data;
  259. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  260. int ret;
  261. size = min_t(ssize_t, sizeof(lscsa->fpcr) - *pos, size);
  262. if (size <= 0)
  263. return -EFBIG;
  264. *pos += size;
  265. spu_acquire_saved(ctx);
  266. ret = copy_from_user((char *)&lscsa->fpcr + *pos - size,
  267. buffer, size) ? -EFAULT : size;
  268. spu_release(ctx);
  269. return ret;
  270. }
  271. static struct file_operations spufs_fpcr_fops = {
  272. .open = spufs_regs_open,
  273. .read = spufs_fpcr_read,
  274. .write = spufs_fpcr_write,
  275. .llseek = generic_file_llseek,
  276. };
  277. /* generic open function for all pipe-like files */
  278. static int spufs_pipe_open(struct inode *inode, struct file *file)
  279. {
  280. struct spufs_inode_info *i = SPUFS_I(inode);
  281. file->private_data = i->i_ctx;
  282. return nonseekable_open(inode, file);
  283. }
  284. static ssize_t spufs_mbox_read(struct file *file, char __user *buf,
  285. size_t len, loff_t *pos)
  286. {
  287. struct spu_context *ctx = file->private_data;
  288. u32 mbox_data;
  289. int ret;
  290. if (len < 4)
  291. return -EINVAL;
  292. spu_acquire(ctx);
  293. ret = ctx->ops->mbox_read(ctx, &mbox_data);
  294. spu_release(ctx);
  295. if (!ret)
  296. return -EAGAIN;
  297. if (copy_to_user(buf, &mbox_data, sizeof mbox_data))
  298. return -EFAULT;
  299. return 4;
  300. }
  301. static struct file_operations spufs_mbox_fops = {
  302. .open = spufs_pipe_open,
  303. .read = spufs_mbox_read,
  304. };
  305. static ssize_t spufs_mbox_stat_read(struct file *file, char __user *buf,
  306. size_t len, loff_t *pos)
  307. {
  308. struct spu_context *ctx = file->private_data;
  309. u32 mbox_stat;
  310. if (len < 4)
  311. return -EINVAL;
  312. spu_acquire(ctx);
  313. mbox_stat = ctx->ops->mbox_stat_read(ctx) & 0xff;
  314. spu_release(ctx);
  315. if (copy_to_user(buf, &mbox_stat, sizeof mbox_stat))
  316. return -EFAULT;
  317. return 4;
  318. }
  319. static struct file_operations spufs_mbox_stat_fops = {
  320. .open = spufs_pipe_open,
  321. .read = spufs_mbox_stat_read,
  322. };
  323. /* low-level ibox access function */
  324. size_t spu_ibox_read(struct spu_context *ctx, u32 *data)
  325. {
  326. return ctx->ops->ibox_read(ctx, data);
  327. }
  328. static int spufs_ibox_fasync(int fd, struct file *file, int on)
  329. {
  330. struct spu_context *ctx = file->private_data;
  331. return fasync_helper(fd, file, on, &ctx->ibox_fasync);
  332. }
  333. /* interrupt-level ibox callback function. */
  334. void spufs_ibox_callback(struct spu *spu)
  335. {
  336. struct spu_context *ctx = spu->ctx;
  337. wake_up_all(&ctx->ibox_wq);
  338. kill_fasync(&ctx->ibox_fasync, SIGIO, POLLIN);
  339. }
  340. static ssize_t spufs_ibox_read(struct file *file, char __user *buf,
  341. size_t len, loff_t *pos)
  342. {
  343. struct spu_context *ctx = file->private_data;
  344. u32 ibox_data;
  345. ssize_t ret;
  346. if (len < 4)
  347. return -EINVAL;
  348. spu_acquire(ctx);
  349. ret = 0;
  350. if (file->f_flags & O_NONBLOCK) {
  351. if (!spu_ibox_read(ctx, &ibox_data))
  352. ret = -EAGAIN;
  353. } else {
  354. ret = spufs_wait(ctx->ibox_wq, spu_ibox_read(ctx, &ibox_data));
  355. }
  356. spu_release(ctx);
  357. if (ret)
  358. return ret;
  359. ret = 4;
  360. if (copy_to_user(buf, &ibox_data, sizeof ibox_data))
  361. ret = -EFAULT;
  362. return ret;
  363. }
  364. static unsigned int spufs_ibox_poll(struct file *file, poll_table *wait)
  365. {
  366. struct spu_context *ctx = file->private_data;
  367. unsigned int mask;
  368. poll_wait(file, &ctx->ibox_wq, wait);
  369. spu_acquire(ctx);
  370. mask = ctx->ops->mbox_stat_poll(ctx, POLLIN | POLLRDNORM);
  371. spu_release(ctx);
  372. return mask;
  373. }
  374. static struct file_operations spufs_ibox_fops = {
  375. .open = spufs_pipe_open,
  376. .read = spufs_ibox_read,
  377. .poll = spufs_ibox_poll,
  378. .fasync = spufs_ibox_fasync,
  379. };
  380. static ssize_t spufs_ibox_stat_read(struct file *file, char __user *buf,
  381. size_t len, loff_t *pos)
  382. {
  383. struct spu_context *ctx = file->private_data;
  384. u32 ibox_stat;
  385. if (len < 4)
  386. return -EINVAL;
  387. spu_acquire(ctx);
  388. ibox_stat = (ctx->ops->mbox_stat_read(ctx) >> 16) & 0xff;
  389. spu_release(ctx);
  390. if (copy_to_user(buf, &ibox_stat, sizeof ibox_stat))
  391. return -EFAULT;
  392. return 4;
  393. }
  394. static struct file_operations spufs_ibox_stat_fops = {
  395. .open = spufs_pipe_open,
  396. .read = spufs_ibox_stat_read,
  397. };
  398. /* low-level mailbox write */
  399. size_t spu_wbox_write(struct spu_context *ctx, u32 data)
  400. {
  401. return ctx->ops->wbox_write(ctx, data);
  402. }
  403. static int spufs_wbox_fasync(int fd, struct file *file, int on)
  404. {
  405. struct spu_context *ctx = file->private_data;
  406. int ret;
  407. ret = fasync_helper(fd, file, on, &ctx->wbox_fasync);
  408. return ret;
  409. }
  410. /* interrupt-level wbox callback function. */
  411. void spufs_wbox_callback(struct spu *spu)
  412. {
  413. struct spu_context *ctx = spu->ctx;
  414. wake_up_all(&ctx->wbox_wq);
  415. kill_fasync(&ctx->wbox_fasync, SIGIO, POLLOUT);
  416. }
  417. static ssize_t spufs_wbox_write(struct file *file, const char __user *buf,
  418. size_t len, loff_t *pos)
  419. {
  420. struct spu_context *ctx = file->private_data;
  421. u32 wbox_data;
  422. int ret;
  423. if (len < 4)
  424. return -EINVAL;
  425. if (copy_from_user(&wbox_data, buf, sizeof wbox_data))
  426. return -EFAULT;
  427. spu_acquire(ctx);
  428. ret = 0;
  429. if (file->f_flags & O_NONBLOCK) {
  430. if (!spu_wbox_write(ctx, wbox_data))
  431. ret = -EAGAIN;
  432. } else {
  433. ret = spufs_wait(ctx->wbox_wq, spu_wbox_write(ctx, wbox_data));
  434. }
  435. spu_release(ctx);
  436. return ret ? ret : sizeof wbox_data;
  437. }
  438. static unsigned int spufs_wbox_poll(struct file *file, poll_table *wait)
  439. {
  440. struct spu_context *ctx = file->private_data;
  441. unsigned int mask;
  442. poll_wait(file, &ctx->wbox_wq, wait);
  443. spu_acquire(ctx);
  444. mask = ctx->ops->mbox_stat_poll(ctx, POLLOUT | POLLWRNORM);
  445. spu_release(ctx);
  446. return mask;
  447. }
  448. static struct file_operations spufs_wbox_fops = {
  449. .open = spufs_pipe_open,
  450. .write = spufs_wbox_write,
  451. .poll = spufs_wbox_poll,
  452. .fasync = spufs_wbox_fasync,
  453. };
  454. static ssize_t spufs_wbox_stat_read(struct file *file, char __user *buf,
  455. size_t len, loff_t *pos)
  456. {
  457. struct spu_context *ctx = file->private_data;
  458. u32 wbox_stat;
  459. if (len < 4)
  460. return -EINVAL;
  461. spu_acquire(ctx);
  462. wbox_stat = (ctx->ops->mbox_stat_read(ctx) >> 8) & 0xff;
  463. spu_release(ctx);
  464. if (copy_to_user(buf, &wbox_stat, sizeof wbox_stat))
  465. return -EFAULT;
  466. return 4;
  467. }
  468. static struct file_operations spufs_wbox_stat_fops = {
  469. .open = spufs_pipe_open,
  470. .read = spufs_wbox_stat_read,
  471. };
  472. static int spufs_signal1_open(struct inode *inode, struct file *file)
  473. {
  474. struct spufs_inode_info *i = SPUFS_I(inode);
  475. struct spu_context *ctx = i->i_ctx;
  476. file->private_data = ctx;
  477. file->f_mapping = inode->i_mapping;
  478. ctx->signal1 = inode->i_mapping;
  479. return nonseekable_open(inode, file);
  480. }
  481. static ssize_t spufs_signal1_read(struct file *file, char __user *buf,
  482. size_t len, loff_t *pos)
  483. {
  484. struct spu_context *ctx = file->private_data;
  485. u32 data;
  486. if (len < 4)
  487. return -EINVAL;
  488. spu_acquire(ctx);
  489. data = ctx->ops->signal1_read(ctx);
  490. spu_release(ctx);
  491. if (copy_to_user(buf, &data, 4))
  492. return -EFAULT;
  493. return 4;
  494. }
  495. static ssize_t spufs_signal1_write(struct file *file, const char __user *buf,
  496. size_t len, loff_t *pos)
  497. {
  498. struct spu_context *ctx;
  499. u32 data;
  500. ctx = file->private_data;
  501. if (len < 4)
  502. return -EINVAL;
  503. if (copy_from_user(&data, buf, 4))
  504. return -EFAULT;
  505. spu_acquire(ctx);
  506. ctx->ops->signal1_write(ctx, data);
  507. spu_release(ctx);
  508. return 4;
  509. }
  510. static struct page *spufs_signal1_mmap_nopage(struct vm_area_struct *vma,
  511. unsigned long address, int *type)
  512. {
  513. #if PAGE_SIZE == 0x1000
  514. return spufs_ps_nopage(vma, address, type, 0x14000, 0x1000);
  515. #elif PAGE_SIZE == 0x10000
  516. /* For 64k pages, both signal1 and signal2 can be used to mmap the whole
  517. * signal 1 and 2 area
  518. */
  519. return spufs_ps_nopage(vma, address, type, 0x10000, 0x10000);
  520. #else
  521. #error unsupported page size
  522. #endif
  523. }
  524. static struct vm_operations_struct spufs_signal1_mmap_vmops = {
  525. .nopage = spufs_signal1_mmap_nopage,
  526. };
  527. static int spufs_signal1_mmap(struct file *file, struct vm_area_struct *vma)
  528. {
  529. if (!(vma->vm_flags & VM_SHARED))
  530. return -EINVAL;
  531. vma->vm_flags |= VM_RESERVED;
  532. vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
  533. | _PAGE_NO_CACHE | _PAGE_GUARDED);
  534. vma->vm_ops = &spufs_signal1_mmap_vmops;
  535. return 0;
  536. }
  537. static struct file_operations spufs_signal1_fops = {
  538. .open = spufs_signal1_open,
  539. .read = spufs_signal1_read,
  540. .write = spufs_signal1_write,
  541. .mmap = spufs_signal1_mmap,
  542. };
  543. static int spufs_signal2_open(struct inode *inode, struct file *file)
  544. {
  545. struct spufs_inode_info *i = SPUFS_I(inode);
  546. struct spu_context *ctx = i->i_ctx;
  547. file->private_data = ctx;
  548. file->f_mapping = inode->i_mapping;
  549. ctx->signal2 = inode->i_mapping;
  550. return nonseekable_open(inode, file);
  551. }
  552. static ssize_t spufs_signal2_read(struct file *file, char __user *buf,
  553. size_t len, loff_t *pos)
  554. {
  555. struct spu_context *ctx;
  556. u32 data;
  557. ctx = file->private_data;
  558. if (len < 4)
  559. return -EINVAL;
  560. spu_acquire(ctx);
  561. data = ctx->ops->signal2_read(ctx);
  562. spu_release(ctx);
  563. if (copy_to_user(buf, &data, 4))
  564. return -EFAULT;
  565. return 4;
  566. }
  567. static ssize_t spufs_signal2_write(struct file *file, const char __user *buf,
  568. size_t len, loff_t *pos)
  569. {
  570. struct spu_context *ctx;
  571. u32 data;
  572. ctx = file->private_data;
  573. if (len < 4)
  574. return -EINVAL;
  575. if (copy_from_user(&data, buf, 4))
  576. return -EFAULT;
  577. spu_acquire(ctx);
  578. ctx->ops->signal2_write(ctx, data);
  579. spu_release(ctx);
  580. return 4;
  581. }
  582. #if SPUFS_MMAP_4K
  583. static struct page *spufs_signal2_mmap_nopage(struct vm_area_struct *vma,
  584. unsigned long address, int *type)
  585. {
  586. #if PAGE_SIZE == 0x1000
  587. return spufs_ps_nopage(vma, address, type, 0x1c000, 0x1000);
  588. #elif PAGE_SIZE == 0x10000
  589. /* For 64k pages, both signal1 and signal2 can be used to mmap the whole
  590. * signal 1 and 2 area
  591. */
  592. return spufs_ps_nopage(vma, address, type, 0x10000, 0x10000);
  593. #else
  594. #error unsupported page size
  595. #endif
  596. }
  597. static struct vm_operations_struct spufs_signal2_mmap_vmops = {
  598. .nopage = spufs_signal2_mmap_nopage,
  599. };
  600. static int spufs_signal2_mmap(struct file *file, struct vm_area_struct *vma)
  601. {
  602. if (!(vma->vm_flags & VM_SHARED))
  603. return -EINVAL;
  604. /* FIXME: */
  605. vma->vm_flags |= VM_RESERVED;
  606. vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
  607. | _PAGE_NO_CACHE | _PAGE_GUARDED);
  608. vma->vm_ops = &spufs_signal2_mmap_vmops;
  609. return 0;
  610. }
  611. #else /* SPUFS_MMAP_4K */
  612. #define spufs_signal2_mmap NULL
  613. #endif /* !SPUFS_MMAP_4K */
  614. static struct file_operations spufs_signal2_fops = {
  615. .open = spufs_signal2_open,
  616. .read = spufs_signal2_read,
  617. .write = spufs_signal2_write,
  618. .mmap = spufs_signal2_mmap,
  619. };
  620. static void spufs_signal1_type_set(void *data, u64 val)
  621. {
  622. struct spu_context *ctx = data;
  623. spu_acquire(ctx);
  624. ctx->ops->signal1_type_set(ctx, val);
  625. spu_release(ctx);
  626. }
  627. static u64 spufs_signal1_type_get(void *data)
  628. {
  629. struct spu_context *ctx = data;
  630. u64 ret;
  631. spu_acquire(ctx);
  632. ret = ctx->ops->signal1_type_get(ctx);
  633. spu_release(ctx);
  634. return ret;
  635. }
  636. DEFINE_SIMPLE_ATTRIBUTE(spufs_signal1_type, spufs_signal1_type_get,
  637. spufs_signal1_type_set, "%llu");
  638. static void spufs_signal2_type_set(void *data, u64 val)
  639. {
  640. struct spu_context *ctx = data;
  641. spu_acquire(ctx);
  642. ctx->ops->signal2_type_set(ctx, val);
  643. spu_release(ctx);
  644. }
  645. static u64 spufs_signal2_type_get(void *data)
  646. {
  647. struct spu_context *ctx = data;
  648. u64 ret;
  649. spu_acquire(ctx);
  650. ret = ctx->ops->signal2_type_get(ctx);
  651. spu_release(ctx);
  652. return ret;
  653. }
  654. DEFINE_SIMPLE_ATTRIBUTE(spufs_signal2_type, spufs_signal2_type_get,
  655. spufs_signal2_type_set, "%llu");
  656. #if SPUFS_MMAP_4K
  657. static struct page *spufs_mss_mmap_nopage(struct vm_area_struct *vma,
  658. unsigned long address, int *type)
  659. {
  660. return spufs_ps_nopage(vma, address, type, 0x0000, 0x1000);
  661. }
  662. static struct vm_operations_struct spufs_mss_mmap_vmops = {
  663. .nopage = spufs_mss_mmap_nopage,
  664. };
  665. /*
  666. * mmap support for problem state MFC DMA area [0x0000 - 0x0fff].
  667. */
  668. static int spufs_mss_mmap(struct file *file, struct vm_area_struct *vma)
  669. {
  670. if (!(vma->vm_flags & VM_SHARED))
  671. return -EINVAL;
  672. vma->vm_flags |= VM_RESERVED;
  673. vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
  674. | _PAGE_NO_CACHE | _PAGE_GUARDED);
  675. vma->vm_ops = &spufs_mss_mmap_vmops;
  676. return 0;
  677. }
  678. #else /* SPUFS_MMAP_4K */
  679. #define spufs_mss_mmap NULL
  680. #endif /* !SPUFS_MMAP_4K */
  681. static int spufs_mss_open(struct inode *inode, struct file *file)
  682. {
  683. struct spufs_inode_info *i = SPUFS_I(inode);
  684. file->private_data = i->i_ctx;
  685. return nonseekable_open(inode, file);
  686. }
  687. static struct file_operations spufs_mss_fops = {
  688. .open = spufs_mss_open,
  689. .mmap = spufs_mss_mmap,
  690. };
  691. static struct page *spufs_psmap_mmap_nopage(struct vm_area_struct *vma,
  692. unsigned long address, int *type)
  693. {
  694. return spufs_ps_nopage(vma, address, type, 0x0000, 0x20000);
  695. }
  696. static struct vm_operations_struct spufs_psmap_mmap_vmops = {
  697. .nopage = spufs_psmap_mmap_nopage,
  698. };
  699. /*
  700. * mmap support for full problem state area [0x00000 - 0x1ffff].
  701. */
  702. static int spufs_psmap_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_RESERVED;
  707. vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
  708. | _PAGE_NO_CACHE | _PAGE_GUARDED);
  709. vma->vm_ops = &spufs_psmap_mmap_vmops;
  710. return 0;
  711. }
  712. static int spufs_psmap_open(struct inode *inode, struct file *file)
  713. {
  714. struct spufs_inode_info *i = SPUFS_I(inode);
  715. file->private_data = i->i_ctx;
  716. return nonseekable_open(inode, file);
  717. }
  718. static struct file_operations spufs_psmap_fops = {
  719. .open = spufs_psmap_open,
  720. .mmap = spufs_psmap_mmap,
  721. };
  722. #if SPUFS_MMAP_4K
  723. static struct page *spufs_mfc_mmap_nopage(struct vm_area_struct *vma,
  724. unsigned long address, int *type)
  725. {
  726. return spufs_ps_nopage(vma, address, type, 0x3000, 0x1000);
  727. }
  728. static struct vm_operations_struct spufs_mfc_mmap_vmops = {
  729. .nopage = spufs_mfc_mmap_nopage,
  730. };
  731. /*
  732. * mmap support for problem state MFC DMA area [0x0000 - 0x0fff].
  733. */
  734. static int spufs_mfc_mmap(struct file *file, struct vm_area_struct *vma)
  735. {
  736. if (!(vma->vm_flags & VM_SHARED))
  737. return -EINVAL;
  738. vma->vm_flags |= VM_RESERVED;
  739. vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
  740. | _PAGE_NO_CACHE | _PAGE_GUARDED);
  741. vma->vm_ops = &spufs_mfc_mmap_vmops;
  742. return 0;
  743. }
  744. #else /* SPUFS_MMAP_4K */
  745. #define spufs_mfc_mmap NULL
  746. #endif /* !SPUFS_MMAP_4K */
  747. static int spufs_mfc_open(struct inode *inode, struct file *file)
  748. {
  749. struct spufs_inode_info *i = SPUFS_I(inode);
  750. struct spu_context *ctx = i->i_ctx;
  751. /* we don't want to deal with DMA into other processes */
  752. if (ctx->owner != current->mm)
  753. return -EINVAL;
  754. if (atomic_read(&inode->i_count) != 1)
  755. return -EBUSY;
  756. file->private_data = ctx;
  757. return nonseekable_open(inode, file);
  758. }
  759. /* interrupt-level mfc callback function. */
  760. void spufs_mfc_callback(struct spu *spu)
  761. {
  762. struct spu_context *ctx = spu->ctx;
  763. wake_up_all(&ctx->mfc_wq);
  764. pr_debug("%s %s\n", __FUNCTION__, spu->name);
  765. if (ctx->mfc_fasync) {
  766. u32 free_elements, tagstatus;
  767. unsigned int mask;
  768. /* no need for spu_acquire in interrupt context */
  769. free_elements = ctx->ops->get_mfc_free_elements(ctx);
  770. tagstatus = ctx->ops->read_mfc_tagstatus(ctx);
  771. mask = 0;
  772. if (free_elements & 0xffff)
  773. mask |= POLLOUT;
  774. if (tagstatus & ctx->tagwait)
  775. mask |= POLLIN;
  776. kill_fasync(&ctx->mfc_fasync, SIGIO, mask);
  777. }
  778. }
  779. static int spufs_read_mfc_tagstatus(struct spu_context *ctx, u32 *status)
  780. {
  781. /* See if there is one tag group is complete */
  782. /* FIXME we need locking around tagwait */
  783. *status = ctx->ops->read_mfc_tagstatus(ctx) & ctx->tagwait;
  784. ctx->tagwait &= ~*status;
  785. if (*status)
  786. return 1;
  787. /* enable interrupt waiting for any tag group,
  788. may silently fail if interrupts are already enabled */
  789. ctx->ops->set_mfc_query(ctx, ctx->tagwait, 1);
  790. return 0;
  791. }
  792. static ssize_t spufs_mfc_read(struct file *file, char __user *buffer,
  793. size_t size, loff_t *pos)
  794. {
  795. struct spu_context *ctx = file->private_data;
  796. int ret = -EINVAL;
  797. u32 status;
  798. if (size != 4)
  799. goto out;
  800. spu_acquire(ctx);
  801. if (file->f_flags & O_NONBLOCK) {
  802. status = ctx->ops->read_mfc_tagstatus(ctx);
  803. if (!(status & ctx->tagwait))
  804. ret = -EAGAIN;
  805. else
  806. ctx->tagwait &= ~status;
  807. } else {
  808. ret = spufs_wait(ctx->mfc_wq,
  809. spufs_read_mfc_tagstatus(ctx, &status));
  810. }
  811. spu_release(ctx);
  812. if (ret)
  813. goto out;
  814. ret = 4;
  815. if (copy_to_user(buffer, &status, 4))
  816. ret = -EFAULT;
  817. out:
  818. return ret;
  819. }
  820. static int spufs_check_valid_dma(struct mfc_dma_command *cmd)
  821. {
  822. pr_debug("queueing DMA %x %lx %x %x %x\n", cmd->lsa,
  823. cmd->ea, cmd->size, cmd->tag, cmd->cmd);
  824. switch (cmd->cmd) {
  825. case MFC_PUT_CMD:
  826. case MFC_PUTF_CMD:
  827. case MFC_PUTB_CMD:
  828. case MFC_GET_CMD:
  829. case MFC_GETF_CMD:
  830. case MFC_GETB_CMD:
  831. break;
  832. default:
  833. pr_debug("invalid DMA opcode %x\n", cmd->cmd);
  834. return -EIO;
  835. }
  836. if ((cmd->lsa & 0xf) != (cmd->ea &0xf)) {
  837. pr_debug("invalid DMA alignment, ea %lx lsa %x\n",
  838. cmd->ea, cmd->lsa);
  839. return -EIO;
  840. }
  841. switch (cmd->size & 0xf) {
  842. case 1:
  843. break;
  844. case 2:
  845. if (cmd->lsa & 1)
  846. goto error;
  847. break;
  848. case 4:
  849. if (cmd->lsa & 3)
  850. goto error;
  851. break;
  852. case 8:
  853. if (cmd->lsa & 7)
  854. goto error;
  855. break;
  856. case 0:
  857. if (cmd->lsa & 15)
  858. goto error;
  859. break;
  860. error:
  861. default:
  862. pr_debug("invalid DMA alignment %x for size %x\n",
  863. cmd->lsa & 0xf, cmd->size);
  864. return -EIO;
  865. }
  866. if (cmd->size > 16 * 1024) {
  867. pr_debug("invalid DMA size %x\n", cmd->size);
  868. return -EIO;
  869. }
  870. if (cmd->tag & 0xfff0) {
  871. /* we reserve the higher tag numbers for kernel use */
  872. pr_debug("invalid DMA tag\n");
  873. return -EIO;
  874. }
  875. if (cmd->class) {
  876. /* not supported in this version */
  877. pr_debug("invalid DMA class\n");
  878. return -EIO;
  879. }
  880. return 0;
  881. }
  882. static int spu_send_mfc_command(struct spu_context *ctx,
  883. struct mfc_dma_command cmd,
  884. int *error)
  885. {
  886. *error = ctx->ops->send_mfc_command(ctx, &cmd);
  887. if (*error == -EAGAIN) {
  888. /* wait for any tag group to complete
  889. so we have space for the new command */
  890. ctx->ops->set_mfc_query(ctx, ctx->tagwait, 1);
  891. /* try again, because the queue might be
  892. empty again */
  893. *error = ctx->ops->send_mfc_command(ctx, &cmd);
  894. if (*error == -EAGAIN)
  895. return 0;
  896. }
  897. return 1;
  898. }
  899. static ssize_t spufs_mfc_write(struct file *file, const char __user *buffer,
  900. size_t size, loff_t *pos)
  901. {
  902. struct spu_context *ctx = file->private_data;
  903. struct mfc_dma_command cmd;
  904. int ret = -EINVAL;
  905. if (size != sizeof cmd)
  906. goto out;
  907. ret = -EFAULT;
  908. if (copy_from_user(&cmd, buffer, sizeof cmd))
  909. goto out;
  910. ret = spufs_check_valid_dma(&cmd);
  911. if (ret)
  912. goto out;
  913. spu_acquire_runnable(ctx);
  914. if (file->f_flags & O_NONBLOCK) {
  915. ret = ctx->ops->send_mfc_command(ctx, &cmd);
  916. } else {
  917. int status;
  918. ret = spufs_wait(ctx->mfc_wq,
  919. spu_send_mfc_command(ctx, cmd, &status));
  920. if (status)
  921. ret = status;
  922. }
  923. spu_release(ctx);
  924. if (ret)
  925. goto out;
  926. ctx->tagwait |= 1 << cmd.tag;
  927. out:
  928. return ret;
  929. }
  930. static unsigned int spufs_mfc_poll(struct file *file,poll_table *wait)
  931. {
  932. struct spu_context *ctx = file->private_data;
  933. u32 free_elements, tagstatus;
  934. unsigned int mask;
  935. spu_acquire(ctx);
  936. ctx->ops->set_mfc_query(ctx, ctx->tagwait, 2);
  937. free_elements = ctx->ops->get_mfc_free_elements(ctx);
  938. tagstatus = ctx->ops->read_mfc_tagstatus(ctx);
  939. spu_release(ctx);
  940. poll_wait(file, &ctx->mfc_wq, wait);
  941. mask = 0;
  942. if (free_elements & 0xffff)
  943. mask |= POLLOUT | POLLWRNORM;
  944. if (tagstatus & ctx->tagwait)
  945. mask |= POLLIN | POLLRDNORM;
  946. pr_debug("%s: free %d tagstatus %d tagwait %d\n", __FUNCTION__,
  947. free_elements, tagstatus, ctx->tagwait);
  948. return mask;
  949. }
  950. static int spufs_mfc_flush(struct file *file, fl_owner_t id)
  951. {
  952. struct spu_context *ctx = file->private_data;
  953. int ret;
  954. spu_acquire(ctx);
  955. #if 0
  956. /* this currently hangs */
  957. ret = spufs_wait(ctx->mfc_wq,
  958. ctx->ops->set_mfc_query(ctx, ctx->tagwait, 2));
  959. if (ret)
  960. goto out;
  961. ret = spufs_wait(ctx->mfc_wq,
  962. ctx->ops->read_mfc_tagstatus(ctx) == ctx->tagwait);
  963. out:
  964. #else
  965. ret = 0;
  966. #endif
  967. spu_release(ctx);
  968. return ret;
  969. }
  970. static int spufs_mfc_fsync(struct file *file, struct dentry *dentry,
  971. int datasync)
  972. {
  973. return spufs_mfc_flush(file, NULL);
  974. }
  975. static int spufs_mfc_fasync(int fd, struct file *file, int on)
  976. {
  977. struct spu_context *ctx = file->private_data;
  978. return fasync_helper(fd, file, on, &ctx->mfc_fasync);
  979. }
  980. static struct file_operations spufs_mfc_fops = {
  981. .open = spufs_mfc_open,
  982. .read = spufs_mfc_read,
  983. .write = spufs_mfc_write,
  984. .poll = spufs_mfc_poll,
  985. .flush = spufs_mfc_flush,
  986. .fsync = spufs_mfc_fsync,
  987. .fasync = spufs_mfc_fasync,
  988. .mmap = spufs_mfc_mmap,
  989. };
  990. static void spufs_npc_set(void *data, u64 val)
  991. {
  992. struct spu_context *ctx = data;
  993. spu_acquire(ctx);
  994. ctx->ops->npc_write(ctx, val);
  995. spu_release(ctx);
  996. }
  997. static u64 spufs_npc_get(void *data)
  998. {
  999. struct spu_context *ctx = data;
  1000. u64 ret;
  1001. spu_acquire(ctx);
  1002. ret = ctx->ops->npc_read(ctx);
  1003. spu_release(ctx);
  1004. return ret;
  1005. }
  1006. DEFINE_SIMPLE_ATTRIBUTE(spufs_npc_ops, spufs_npc_get, spufs_npc_set, "%llx\n")
  1007. static void spufs_decr_set(void *data, u64 val)
  1008. {
  1009. struct spu_context *ctx = data;
  1010. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  1011. spu_acquire_saved(ctx);
  1012. lscsa->decr.slot[0] = (u32) val;
  1013. spu_release(ctx);
  1014. }
  1015. static u64 spufs_decr_get(void *data)
  1016. {
  1017. struct spu_context *ctx = data;
  1018. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  1019. u64 ret;
  1020. spu_acquire_saved(ctx);
  1021. ret = lscsa->decr.slot[0];
  1022. spu_release(ctx);
  1023. return ret;
  1024. }
  1025. DEFINE_SIMPLE_ATTRIBUTE(spufs_decr_ops, spufs_decr_get, spufs_decr_set,
  1026. "%llx\n")
  1027. static void spufs_decr_status_set(void *data, u64 val)
  1028. {
  1029. struct spu_context *ctx = data;
  1030. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  1031. spu_acquire_saved(ctx);
  1032. lscsa->decr_status.slot[0] = (u32) val;
  1033. spu_release(ctx);
  1034. }
  1035. static u64 spufs_decr_status_get(void *data)
  1036. {
  1037. struct spu_context *ctx = data;
  1038. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  1039. u64 ret;
  1040. spu_acquire_saved(ctx);
  1041. ret = lscsa->decr_status.slot[0];
  1042. spu_release(ctx);
  1043. return ret;
  1044. }
  1045. DEFINE_SIMPLE_ATTRIBUTE(spufs_decr_status_ops, spufs_decr_status_get,
  1046. spufs_decr_status_set, "%llx\n")
  1047. static void spufs_spu_tag_mask_set(void *data, u64 val)
  1048. {
  1049. struct spu_context *ctx = data;
  1050. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  1051. spu_acquire_saved(ctx);
  1052. lscsa->tag_mask.slot[0] = (u32) val;
  1053. spu_release(ctx);
  1054. }
  1055. static u64 spufs_spu_tag_mask_get(void *data)
  1056. {
  1057. struct spu_context *ctx = data;
  1058. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  1059. u64 ret;
  1060. spu_acquire_saved(ctx);
  1061. ret = lscsa->tag_mask.slot[0];
  1062. spu_release(ctx);
  1063. return ret;
  1064. }
  1065. DEFINE_SIMPLE_ATTRIBUTE(spufs_spu_tag_mask_ops, spufs_spu_tag_mask_get,
  1066. spufs_spu_tag_mask_set, "%llx\n")
  1067. static void spufs_event_mask_set(void *data, u64 val)
  1068. {
  1069. struct spu_context *ctx = data;
  1070. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  1071. spu_acquire_saved(ctx);
  1072. lscsa->event_mask.slot[0] = (u32) val;
  1073. spu_release(ctx);
  1074. }
  1075. static u64 spufs_event_mask_get(void *data)
  1076. {
  1077. struct spu_context *ctx = data;
  1078. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  1079. u64 ret;
  1080. spu_acquire_saved(ctx);
  1081. ret = lscsa->event_mask.slot[0];
  1082. spu_release(ctx);
  1083. return ret;
  1084. }
  1085. DEFINE_SIMPLE_ATTRIBUTE(spufs_event_mask_ops, spufs_event_mask_get,
  1086. spufs_event_mask_set, "%llx\n")
  1087. static void spufs_srr0_set(void *data, u64 val)
  1088. {
  1089. struct spu_context *ctx = data;
  1090. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  1091. spu_acquire_saved(ctx);
  1092. lscsa->srr0.slot[0] = (u32) val;
  1093. spu_release(ctx);
  1094. }
  1095. static u64 spufs_srr0_get(void *data)
  1096. {
  1097. struct spu_context *ctx = data;
  1098. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  1099. u64 ret;
  1100. spu_acquire_saved(ctx);
  1101. ret = lscsa->srr0.slot[0];
  1102. spu_release(ctx);
  1103. return ret;
  1104. }
  1105. DEFINE_SIMPLE_ATTRIBUTE(spufs_srr0_ops, spufs_srr0_get, spufs_srr0_set,
  1106. "%llx\n")
  1107. static u64 spufs_id_get(void *data)
  1108. {
  1109. struct spu_context *ctx = data;
  1110. u64 num;
  1111. spu_acquire(ctx);
  1112. if (ctx->state == SPU_STATE_RUNNABLE)
  1113. num = ctx->spu->number;
  1114. else
  1115. num = (unsigned int)-1;
  1116. spu_release(ctx);
  1117. return num;
  1118. }
  1119. DEFINE_SIMPLE_ATTRIBUTE(spufs_id_ops, spufs_id_get, NULL, "0x%llx\n")
  1120. struct tree_descr spufs_dir_contents[] = {
  1121. { "mem", &spufs_mem_fops, 0666, },
  1122. { "regs", &spufs_regs_fops, 0666, },
  1123. { "mbox", &spufs_mbox_fops, 0444, },
  1124. { "ibox", &spufs_ibox_fops, 0444, },
  1125. { "wbox", &spufs_wbox_fops, 0222, },
  1126. { "mbox_stat", &spufs_mbox_stat_fops, 0444, },
  1127. { "ibox_stat", &spufs_ibox_stat_fops, 0444, },
  1128. { "wbox_stat", &spufs_wbox_stat_fops, 0444, },
  1129. { "signal1", &spufs_signal1_fops, 0666, },
  1130. { "signal2", &spufs_signal2_fops, 0666, },
  1131. { "signal1_type", &spufs_signal1_type, 0666, },
  1132. { "signal2_type", &spufs_signal2_type, 0666, },
  1133. { "mss", &spufs_mss_fops, 0666, },
  1134. { "mfc", &spufs_mfc_fops, 0666, },
  1135. { "cntl", &spufs_cntl_fops, 0666, },
  1136. { "npc", &spufs_npc_ops, 0666, },
  1137. { "fpcr", &spufs_fpcr_fops, 0666, },
  1138. { "decr", &spufs_decr_ops, 0666, },
  1139. { "decr_status", &spufs_decr_status_ops, 0666, },
  1140. { "spu_tag_mask", &spufs_spu_tag_mask_ops, 0666, },
  1141. { "event_mask", &spufs_event_mask_ops, 0666, },
  1142. { "srr0", &spufs_srr0_ops, 0666, },
  1143. { "phys-id", &spufs_id_ops, 0666, },
  1144. { "psmap", &spufs_psmap_fops, 0666, },
  1145. {},
  1146. };