file.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856
  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. #include <linux/fs.h>
  23. #include <linux/ioctl.h>
  24. #include <linux/module.h>
  25. #include <linux/pagemap.h>
  26. #include <linux/poll.h>
  27. #include <asm/io.h>
  28. #include <asm/semaphore.h>
  29. #include <asm/spu.h>
  30. #include <asm/uaccess.h>
  31. #include "spufs.h"
  32. static int
  33. spufs_mem_open(struct inode *inode, struct file *file)
  34. {
  35. struct spufs_inode_info *i = SPUFS_I(inode);
  36. file->private_data = i->i_ctx;
  37. file->f_mapping = i->i_ctx->local_store;
  38. return 0;
  39. }
  40. static ssize_t
  41. spufs_mem_read(struct file *file, char __user *buffer,
  42. size_t size, loff_t *pos)
  43. {
  44. struct spu_context *ctx = file->private_data;
  45. char *local_store;
  46. int ret;
  47. spu_acquire(ctx);
  48. local_store = ctx->ops->get_ls(ctx);
  49. ret = simple_read_from_buffer(buffer, size, pos, local_store, LS_SIZE);
  50. spu_release(ctx);
  51. return ret;
  52. }
  53. static ssize_t
  54. spufs_mem_write(struct file *file, const char __user *buffer,
  55. size_t size, loff_t *pos)
  56. {
  57. struct spu_context *ctx = file->private_data;
  58. char *local_store;
  59. int ret;
  60. size = min_t(ssize_t, LS_SIZE - *pos, size);
  61. if (size <= 0)
  62. return -EFBIG;
  63. *pos += size;
  64. spu_acquire(ctx);
  65. local_store = ctx->ops->get_ls(ctx);
  66. ret = copy_from_user(local_store + *pos - size,
  67. buffer, size) ? -EFAULT : size;
  68. spu_release(ctx);
  69. return ret;
  70. }
  71. #ifdef CONFIG_SPARSEMEM
  72. static struct page *
  73. spufs_mem_mmap_nopage(struct vm_area_struct *vma,
  74. unsigned long address, int *type)
  75. {
  76. struct page *page = NOPAGE_SIGBUS;
  77. struct spu_context *ctx = vma->vm_file->private_data;
  78. unsigned long offset = address - vma->vm_start;
  79. offset += vma->vm_pgoff << PAGE_SHIFT;
  80. spu_acquire(ctx);
  81. if (ctx->state == SPU_STATE_SAVED)
  82. page = vmalloc_to_page(ctx->csa.lscsa->ls + offset);
  83. else
  84. page = pfn_to_page((ctx->spu->local_store_phys + offset)
  85. >> PAGE_SHIFT);
  86. spu_release(ctx);
  87. if (type)
  88. *type = VM_FAULT_MINOR;
  89. page_cache_get(page);
  90. return page;
  91. }
  92. static struct vm_operations_struct spufs_mem_mmap_vmops = {
  93. .nopage = spufs_mem_mmap_nopage,
  94. };
  95. static int
  96. spufs_mem_mmap(struct file *file, struct vm_area_struct *vma)
  97. {
  98. if (!(vma->vm_flags & VM_SHARED))
  99. return -EINVAL;
  100. /* FIXME: */
  101. vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
  102. | _PAGE_NO_CACHE);
  103. vma->vm_ops = &spufs_mem_mmap_vmops;
  104. return 0;
  105. }
  106. #endif
  107. static struct file_operations spufs_mem_fops = {
  108. .open = spufs_mem_open,
  109. .read = spufs_mem_read,
  110. .write = spufs_mem_write,
  111. .llseek = generic_file_llseek,
  112. #ifdef CONFIG_SPARSEMEM
  113. .mmap = spufs_mem_mmap,
  114. #endif
  115. };
  116. static int
  117. spufs_regs_open(struct inode *inode, struct file *file)
  118. {
  119. struct spufs_inode_info *i = SPUFS_I(inode);
  120. file->private_data = i->i_ctx;
  121. return 0;
  122. }
  123. static ssize_t
  124. spufs_regs_read(struct file *file, char __user *buffer,
  125. size_t size, loff_t *pos)
  126. {
  127. struct spu_context *ctx = file->private_data;
  128. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  129. int ret;
  130. spu_acquire_saved(ctx);
  131. ret = simple_read_from_buffer(buffer, size, pos,
  132. lscsa->gprs, sizeof lscsa->gprs);
  133. spu_release(ctx);
  134. return ret;
  135. }
  136. static ssize_t
  137. spufs_regs_write(struct file *file, const char __user *buffer,
  138. size_t size, loff_t *pos)
  139. {
  140. struct spu_context *ctx = file->private_data;
  141. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  142. int ret;
  143. size = min_t(ssize_t, sizeof lscsa->gprs - *pos, size);
  144. if (size <= 0)
  145. return -EFBIG;
  146. *pos += size;
  147. spu_acquire_saved(ctx);
  148. ret = copy_from_user(lscsa->gprs + *pos - size,
  149. buffer, size) ? -EFAULT : size;
  150. spu_release(ctx);
  151. return ret;
  152. }
  153. static struct file_operations spufs_regs_fops = {
  154. .open = spufs_regs_open,
  155. .read = spufs_regs_read,
  156. .write = spufs_regs_write,
  157. .llseek = generic_file_llseek,
  158. };
  159. static ssize_t
  160. spufs_fpcr_read(struct file *file, char __user * buffer,
  161. size_t size, loff_t * pos)
  162. {
  163. struct spu_context *ctx = file->private_data;
  164. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  165. int ret;
  166. spu_acquire_saved(ctx);
  167. ret = simple_read_from_buffer(buffer, size, pos,
  168. &lscsa->fpcr, sizeof(lscsa->fpcr));
  169. spu_release(ctx);
  170. return ret;
  171. }
  172. static ssize_t
  173. spufs_fpcr_write(struct file *file, const char __user * buffer,
  174. size_t size, loff_t * pos)
  175. {
  176. struct spu_context *ctx = file->private_data;
  177. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  178. int ret;
  179. size = min_t(ssize_t, sizeof(lscsa->fpcr) - *pos, size);
  180. if (size <= 0)
  181. return -EFBIG;
  182. *pos += size;
  183. spu_acquire_saved(ctx);
  184. ret = copy_from_user((char *)&lscsa->fpcr + *pos - size,
  185. buffer, size) ? -EFAULT : size;
  186. spu_release(ctx);
  187. return ret;
  188. }
  189. static struct file_operations spufs_fpcr_fops = {
  190. .open = spufs_regs_open,
  191. .read = spufs_fpcr_read,
  192. .write = spufs_fpcr_write,
  193. .llseek = generic_file_llseek,
  194. };
  195. /* generic open function for all pipe-like files */
  196. static int spufs_pipe_open(struct inode *inode, struct file *file)
  197. {
  198. struct spufs_inode_info *i = SPUFS_I(inode);
  199. file->private_data = i->i_ctx;
  200. return nonseekable_open(inode, file);
  201. }
  202. static ssize_t spufs_mbox_read(struct file *file, char __user *buf,
  203. size_t len, loff_t *pos)
  204. {
  205. struct spu_context *ctx = file->private_data;
  206. u32 mbox_data;
  207. int ret;
  208. if (len < 4)
  209. return -EINVAL;
  210. spu_acquire(ctx);
  211. ret = ctx->ops->mbox_read(ctx, &mbox_data);
  212. spu_release(ctx);
  213. if (!ret)
  214. return -EAGAIN;
  215. if (copy_to_user(buf, &mbox_data, sizeof mbox_data))
  216. return -EFAULT;
  217. return 4;
  218. }
  219. static struct file_operations spufs_mbox_fops = {
  220. .open = spufs_pipe_open,
  221. .read = spufs_mbox_read,
  222. };
  223. static ssize_t spufs_mbox_stat_read(struct file *file, char __user *buf,
  224. size_t len, loff_t *pos)
  225. {
  226. struct spu_context *ctx = file->private_data;
  227. u32 mbox_stat;
  228. if (len < 4)
  229. return -EINVAL;
  230. spu_acquire(ctx);
  231. mbox_stat = ctx->ops->mbox_stat_read(ctx) & 0xff;
  232. spu_release(ctx);
  233. if (copy_to_user(buf, &mbox_stat, sizeof mbox_stat))
  234. return -EFAULT;
  235. return 4;
  236. }
  237. static struct file_operations spufs_mbox_stat_fops = {
  238. .open = spufs_pipe_open,
  239. .read = spufs_mbox_stat_read,
  240. };
  241. /*
  242. * spufs_wait
  243. * Same as wait_event_interruptible(), except that here
  244. * we need to call spu_release(ctx) before sleeping, and
  245. * then spu_acquire(ctx) when awoken.
  246. */
  247. #define spufs_wait(wq, condition) \
  248. ({ \
  249. int __ret = 0; \
  250. DEFINE_WAIT(__wait); \
  251. for (;;) { \
  252. prepare_to_wait(&(wq), &__wait, TASK_INTERRUPTIBLE); \
  253. if (condition) \
  254. break; \
  255. if (!signal_pending(current)) { \
  256. spu_release(ctx); \
  257. schedule(); \
  258. spu_acquire(ctx); \
  259. continue; \
  260. } \
  261. __ret = -ERESTARTSYS; \
  262. break; \
  263. } \
  264. finish_wait(&(wq), &__wait); \
  265. __ret; \
  266. })
  267. /* low-level ibox access function */
  268. size_t spu_ibox_read(struct spu_context *ctx, u32 *data)
  269. {
  270. return ctx->ops->ibox_read(ctx, data);
  271. }
  272. static int spufs_ibox_fasync(int fd, struct file *file, int on)
  273. {
  274. struct spu_context *ctx = file->private_data;
  275. return fasync_helper(fd, file, on, &ctx->ibox_fasync);
  276. }
  277. /* interrupt-level ibox callback function. */
  278. void spufs_ibox_callback(struct spu *spu)
  279. {
  280. struct spu_context *ctx = spu->ctx;
  281. wake_up_all(&ctx->ibox_wq);
  282. kill_fasync(&ctx->ibox_fasync, SIGIO, POLLIN);
  283. }
  284. static ssize_t spufs_ibox_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 ibox_data;
  289. ssize_t ret;
  290. if (len < 4)
  291. return -EINVAL;
  292. spu_acquire(ctx);
  293. ret = 0;
  294. if (file->f_flags & O_NONBLOCK) {
  295. if (!spu_ibox_read(ctx, &ibox_data))
  296. ret = -EAGAIN;
  297. } else {
  298. ret = spufs_wait(ctx->ibox_wq, spu_ibox_read(ctx, &ibox_data));
  299. }
  300. spu_release(ctx);
  301. if (ret)
  302. return ret;
  303. ret = 4;
  304. if (copy_to_user(buf, &ibox_data, sizeof ibox_data))
  305. ret = -EFAULT;
  306. return ret;
  307. }
  308. static unsigned int spufs_ibox_poll(struct file *file, poll_table *wait)
  309. {
  310. struct spu_context *ctx = file->private_data;
  311. u32 mbox_stat;
  312. unsigned int mask;
  313. spu_acquire(ctx);
  314. mbox_stat = ctx->ops->mbox_stat_read(ctx);
  315. spu_release(ctx);
  316. poll_wait(file, &ctx->ibox_wq, wait);
  317. mask = 0;
  318. if (mbox_stat & 0xff0000)
  319. mask |= POLLIN | POLLRDNORM;
  320. return mask;
  321. }
  322. static struct file_operations spufs_ibox_fops = {
  323. .open = spufs_pipe_open,
  324. .read = spufs_ibox_read,
  325. .poll = spufs_ibox_poll,
  326. .fasync = spufs_ibox_fasync,
  327. };
  328. static ssize_t spufs_ibox_stat_read(struct file *file, char __user *buf,
  329. size_t len, loff_t *pos)
  330. {
  331. struct spu_context *ctx = file->private_data;
  332. u32 ibox_stat;
  333. if (len < 4)
  334. return -EINVAL;
  335. spu_acquire(ctx);
  336. ibox_stat = (ctx->ops->mbox_stat_read(ctx) >> 16) & 0xff;
  337. spu_release(ctx);
  338. if (copy_to_user(buf, &ibox_stat, sizeof ibox_stat))
  339. return -EFAULT;
  340. return 4;
  341. }
  342. static struct file_operations spufs_ibox_stat_fops = {
  343. .open = spufs_pipe_open,
  344. .read = spufs_ibox_stat_read,
  345. };
  346. /* low-level mailbox write */
  347. size_t spu_wbox_write(struct spu_context *ctx, u32 data)
  348. {
  349. return ctx->ops->wbox_write(ctx, data);
  350. }
  351. static int spufs_wbox_fasync(int fd, struct file *file, int on)
  352. {
  353. struct spu_context *ctx = file->private_data;
  354. int ret;
  355. ret = fasync_helper(fd, file, on, &ctx->wbox_fasync);
  356. return ret;
  357. }
  358. /* interrupt-level wbox callback function. */
  359. void spufs_wbox_callback(struct spu *spu)
  360. {
  361. struct spu_context *ctx = spu->ctx;
  362. wake_up_all(&ctx->wbox_wq);
  363. kill_fasync(&ctx->wbox_fasync, SIGIO, POLLOUT);
  364. }
  365. static ssize_t spufs_wbox_write(struct file *file, const char __user *buf,
  366. size_t len, loff_t *pos)
  367. {
  368. struct spu_context *ctx = file->private_data;
  369. u32 wbox_data;
  370. int ret;
  371. if (len < 4)
  372. return -EINVAL;
  373. if (copy_from_user(&wbox_data, buf, sizeof wbox_data))
  374. return -EFAULT;
  375. spu_acquire(ctx);
  376. ret = 0;
  377. if (file->f_flags & O_NONBLOCK) {
  378. if (!spu_wbox_write(ctx, wbox_data))
  379. ret = -EAGAIN;
  380. } else {
  381. ret = spufs_wait(ctx->wbox_wq, spu_wbox_write(ctx, wbox_data));
  382. }
  383. spu_release(ctx);
  384. return ret ? ret : sizeof wbox_data;
  385. }
  386. static unsigned int spufs_wbox_poll(struct file *file, poll_table *wait)
  387. {
  388. struct spu_context *ctx = file->private_data;
  389. u32 mbox_stat;
  390. unsigned int mask;
  391. spu_acquire(ctx);
  392. mbox_stat = ctx->ops->mbox_stat_read(ctx);
  393. spu_release(ctx);
  394. poll_wait(file, &ctx->wbox_wq, wait);
  395. mask = 0;
  396. if (mbox_stat & 0x00ff00)
  397. mask = POLLOUT | POLLWRNORM;
  398. return mask;
  399. }
  400. static struct file_operations spufs_wbox_fops = {
  401. .open = spufs_pipe_open,
  402. .write = spufs_wbox_write,
  403. .poll = spufs_wbox_poll,
  404. .fasync = spufs_wbox_fasync,
  405. };
  406. static ssize_t spufs_wbox_stat_read(struct file *file, char __user *buf,
  407. size_t len, loff_t *pos)
  408. {
  409. struct spu_context *ctx = file->private_data;
  410. u32 wbox_stat;
  411. if (len < 4)
  412. return -EINVAL;
  413. spu_acquire(ctx);
  414. wbox_stat = (ctx->ops->mbox_stat_read(ctx) >> 8) & 0xff;
  415. spu_release(ctx);
  416. if (copy_to_user(buf, &wbox_stat, sizeof wbox_stat))
  417. return -EFAULT;
  418. return 4;
  419. }
  420. static struct file_operations spufs_wbox_stat_fops = {
  421. .open = spufs_pipe_open,
  422. .read = spufs_wbox_stat_read,
  423. };
  424. long spufs_run_spu(struct file *file, struct spu_context *ctx,
  425. u32 *npc, u32 *status)
  426. {
  427. int ret;
  428. ret = spu_acquire_runnable(ctx);
  429. if (ret)
  430. return ret;
  431. ctx->ops->npc_write(ctx, *npc);
  432. ret = spu_run(ctx->spu);
  433. if (!ret)
  434. ret = ctx->ops->status_read(ctx);
  435. *npc = ctx->ops->npc_read(ctx);
  436. spu_release(ctx);
  437. spu_yield(ctx);
  438. return ret;
  439. }
  440. static ssize_t spufs_signal1_read(struct file *file, char __user *buf,
  441. size_t len, loff_t *pos)
  442. {
  443. struct spu_context *ctx = file->private_data;
  444. u32 data;
  445. if (len < 4)
  446. return -EINVAL;
  447. spu_acquire(ctx);
  448. data = ctx->ops->signal1_read(ctx);
  449. spu_release(ctx);
  450. if (copy_to_user(buf, &data, 4))
  451. return -EFAULT;
  452. return 4;
  453. }
  454. static ssize_t spufs_signal1_write(struct file *file, const char __user *buf,
  455. size_t len, loff_t *pos)
  456. {
  457. struct spu_context *ctx;
  458. u32 data;
  459. ctx = file->private_data;
  460. if (len < 4)
  461. return -EINVAL;
  462. if (copy_from_user(&data, buf, 4))
  463. return -EFAULT;
  464. spu_acquire(ctx);
  465. ctx->ops->signal1_write(ctx, data);
  466. spu_release(ctx);
  467. return 4;
  468. }
  469. static struct file_operations spufs_signal1_fops = {
  470. .open = spufs_pipe_open,
  471. .read = spufs_signal1_read,
  472. .write = spufs_signal1_write,
  473. };
  474. static ssize_t spufs_signal2_read(struct file *file, char __user *buf,
  475. size_t len, loff_t *pos)
  476. {
  477. struct spu_context *ctx;
  478. u32 data;
  479. ctx = file->private_data;
  480. if (len < 4)
  481. return -EINVAL;
  482. spu_acquire(ctx);
  483. data = ctx->ops->signal2_read(ctx);
  484. spu_release(ctx);
  485. if (copy_to_user(buf, &data, 4))
  486. return -EFAULT;
  487. return 4;
  488. }
  489. static ssize_t spufs_signal2_write(struct file *file, const char __user *buf,
  490. size_t len, loff_t *pos)
  491. {
  492. struct spu_context *ctx;
  493. u32 data;
  494. ctx = file->private_data;
  495. if (len < 4)
  496. return -EINVAL;
  497. if (copy_from_user(&data, buf, 4))
  498. return -EFAULT;
  499. spu_acquire(ctx);
  500. ctx->ops->signal2_write(ctx, data);
  501. spu_release(ctx);
  502. return 4;
  503. }
  504. static struct file_operations spufs_signal2_fops = {
  505. .open = spufs_pipe_open,
  506. .read = spufs_signal2_read,
  507. .write = spufs_signal2_write,
  508. };
  509. static void spufs_signal1_type_set(void *data, u64 val)
  510. {
  511. struct spu_context *ctx = data;
  512. spu_acquire(ctx);
  513. ctx->ops->signal1_type_set(ctx, val);
  514. spu_release(ctx);
  515. }
  516. static u64 spufs_signal1_type_get(void *data)
  517. {
  518. struct spu_context *ctx = data;
  519. u64 ret;
  520. spu_acquire(ctx);
  521. ret = ctx->ops->signal1_type_get(ctx);
  522. spu_release(ctx);
  523. return ret;
  524. }
  525. DEFINE_SIMPLE_ATTRIBUTE(spufs_signal1_type, spufs_signal1_type_get,
  526. spufs_signal1_type_set, "%llu");
  527. static void spufs_signal2_type_set(void *data, u64 val)
  528. {
  529. struct spu_context *ctx = data;
  530. spu_acquire(ctx);
  531. ctx->ops->signal2_type_set(ctx, val);
  532. spu_release(ctx);
  533. }
  534. static u64 spufs_signal2_type_get(void *data)
  535. {
  536. struct spu_context *ctx = data;
  537. u64 ret;
  538. spu_acquire(ctx);
  539. ret = ctx->ops->signal2_type_get(ctx);
  540. spu_release(ctx);
  541. return ret;
  542. }
  543. DEFINE_SIMPLE_ATTRIBUTE(spufs_signal2_type, spufs_signal2_type_get,
  544. spufs_signal2_type_set, "%llu");
  545. static void spufs_npc_set(void *data, u64 val)
  546. {
  547. struct spu_context *ctx = data;
  548. spu_acquire(ctx);
  549. ctx->ops->npc_write(ctx, val);
  550. spu_release(ctx);
  551. }
  552. static u64 spufs_npc_get(void *data)
  553. {
  554. struct spu_context *ctx = data;
  555. u64 ret;
  556. spu_acquire(ctx);
  557. ret = ctx->ops->npc_read(ctx);
  558. spu_release(ctx);
  559. return ret;
  560. }
  561. DEFINE_SIMPLE_ATTRIBUTE(spufs_npc_ops, spufs_npc_get, spufs_npc_set, "%llx\n")
  562. static void spufs_decr_set(void *data, u64 val)
  563. {
  564. struct spu_context *ctx = data;
  565. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  566. spu_acquire_saved(ctx);
  567. lscsa->decr.slot[0] = (u32) val;
  568. spu_release(ctx);
  569. }
  570. static u64 spufs_decr_get(void *data)
  571. {
  572. struct spu_context *ctx = data;
  573. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  574. u64 ret;
  575. spu_acquire_saved(ctx);
  576. ret = lscsa->decr.slot[0];
  577. spu_release(ctx);
  578. return ret;
  579. }
  580. DEFINE_SIMPLE_ATTRIBUTE(spufs_decr_ops, spufs_decr_get, spufs_decr_set,
  581. "%llx\n")
  582. static void spufs_decr_status_set(void *data, u64 val)
  583. {
  584. struct spu_context *ctx = data;
  585. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  586. spu_acquire_saved(ctx);
  587. lscsa->decr_status.slot[0] = (u32) val;
  588. spu_release(ctx);
  589. }
  590. static u64 spufs_decr_status_get(void *data)
  591. {
  592. struct spu_context *ctx = data;
  593. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  594. u64 ret;
  595. spu_acquire_saved(ctx);
  596. ret = lscsa->decr_status.slot[0];
  597. spu_release(ctx);
  598. return ret;
  599. }
  600. DEFINE_SIMPLE_ATTRIBUTE(spufs_decr_status_ops, spufs_decr_status_get,
  601. spufs_decr_status_set, "%llx\n")
  602. static void spufs_spu_tag_mask_set(void *data, u64 val)
  603. {
  604. struct spu_context *ctx = data;
  605. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  606. spu_acquire_saved(ctx);
  607. lscsa->tag_mask.slot[0] = (u32) val;
  608. spu_release(ctx);
  609. }
  610. static u64 spufs_spu_tag_mask_get(void *data)
  611. {
  612. struct spu_context *ctx = data;
  613. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  614. u64 ret;
  615. spu_acquire_saved(ctx);
  616. ret = lscsa->tag_mask.slot[0];
  617. spu_release(ctx);
  618. return ret;
  619. }
  620. DEFINE_SIMPLE_ATTRIBUTE(spufs_spu_tag_mask_ops, spufs_spu_tag_mask_get,
  621. spufs_spu_tag_mask_set, "%llx\n")
  622. static void spufs_event_mask_set(void *data, u64 val)
  623. {
  624. struct spu_context *ctx = data;
  625. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  626. spu_acquire_saved(ctx);
  627. lscsa->event_mask.slot[0] = (u32) val;
  628. spu_release(ctx);
  629. }
  630. static u64 spufs_event_mask_get(void *data)
  631. {
  632. struct spu_context *ctx = data;
  633. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  634. u64 ret;
  635. spu_acquire_saved(ctx);
  636. ret = lscsa->event_mask.slot[0];
  637. spu_release(ctx);
  638. return ret;
  639. }
  640. DEFINE_SIMPLE_ATTRIBUTE(spufs_event_mask_ops, spufs_event_mask_get,
  641. spufs_event_mask_set, "%llx\n")
  642. static void spufs_srr0_set(void *data, u64 val)
  643. {
  644. struct spu_context *ctx = data;
  645. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  646. spu_acquire_saved(ctx);
  647. lscsa->srr0.slot[0] = (u32) val;
  648. spu_release(ctx);
  649. }
  650. static u64 spufs_srr0_get(void *data)
  651. {
  652. struct spu_context *ctx = data;
  653. struct spu_lscsa *lscsa = ctx->csa.lscsa;
  654. u64 ret;
  655. spu_acquire_saved(ctx);
  656. ret = lscsa->srr0.slot[0];
  657. spu_release(ctx);
  658. return ret;
  659. }
  660. DEFINE_SIMPLE_ATTRIBUTE(spufs_srr0_ops, spufs_srr0_get, spufs_srr0_set,
  661. "%llx\n")
  662. struct tree_descr spufs_dir_contents[] = {
  663. { "mem", &spufs_mem_fops, 0666, },
  664. { "regs", &spufs_regs_fops, 0666, },
  665. { "mbox", &spufs_mbox_fops, 0444, },
  666. { "ibox", &spufs_ibox_fops, 0444, },
  667. { "wbox", &spufs_wbox_fops, 0222, },
  668. { "mbox_stat", &spufs_mbox_stat_fops, 0444, },
  669. { "ibox_stat", &spufs_ibox_stat_fops, 0444, },
  670. { "wbox_stat", &spufs_wbox_stat_fops, 0444, },
  671. { "signal1", &spufs_signal1_fops, 0666, },
  672. { "signal2", &spufs_signal2_fops, 0666, },
  673. { "signal1_type", &spufs_signal1_type, 0666, },
  674. { "signal2_type", &spufs_signal2_type, 0666, },
  675. { "npc", &spufs_npc_ops, 0666, },
  676. { "fpcr", &spufs_fpcr_fops, 0666, },
  677. { "decr", &spufs_decr_ops, 0666, },
  678. { "decr_status", &spufs_decr_status_ops, 0666, },
  679. { "spu_tag_mask", &spufs_spu_tag_mask_ops, 0666, },
  680. { "event_mask", &spufs_event_mask_ops, 0666, },
  681. { "srr0", &spufs_srr0_ops, 0666, },
  682. {},
  683. };