file.c 34 KB

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