file.c 63 KB

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