switch.c 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193
  1. /*
  2. * spu_switch.c
  3. *
  4. * (C) Copyright IBM Corp. 2005
  5. *
  6. * Author: Mark Nutter <mnutter@us.ibm.com>
  7. *
  8. * Host-side part of SPU context switch sequence outlined in
  9. * Synergistic Processor Element, Book IV.
  10. *
  11. * A fully premptive switch of an SPE is very expensive in terms
  12. * of time and system resources. SPE Book IV indicates that SPE
  13. * allocation should follow a "serially reusable device" model,
  14. * in which the SPE is assigned a task until it completes. When
  15. * this is not possible, this sequence may be used to premptively
  16. * save, and then later (optionally) restore the context of a
  17. * program executing on an SPE.
  18. *
  19. *
  20. * This program is free software; you can redistribute it and/or modify
  21. * it under the terms of the GNU General Public License as published by
  22. * the Free Software Foundation; either version 2, or (at your option)
  23. * any later version.
  24. *
  25. * This program is distributed in the hope that it will be useful,
  26. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  27. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  28. * GNU General Public License for more details.
  29. *
  30. * You should have received a copy of the GNU General Public License
  31. * along with this program; if not, write to the Free Software
  32. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  33. */
  34. #include <linux/module.h>
  35. #include <linux/errno.h>
  36. #include <linux/sched.h>
  37. #include <linux/kernel.h>
  38. #include <linux/mm.h>
  39. #include <linux/vmalloc.h>
  40. #include <linux/smp.h>
  41. #include <linux/stddef.h>
  42. #include <linux/unistd.h>
  43. #include <asm/io.h>
  44. #include <asm/spu.h>
  45. #include <asm/spu_priv1.h>
  46. #include <asm/spu_csa.h>
  47. #include <asm/mmu_context.h>
  48. #include "spu_save_dump.h"
  49. #include "spu_restore_dump.h"
  50. #if 0
  51. #define POLL_WHILE_TRUE(_c) { \
  52. do { \
  53. } while (_c); \
  54. }
  55. #else
  56. #define RELAX_SPIN_COUNT 1000
  57. #define POLL_WHILE_TRUE(_c) { \
  58. do { \
  59. int _i; \
  60. for (_i=0; _i<RELAX_SPIN_COUNT && (_c); _i++) { \
  61. cpu_relax(); \
  62. } \
  63. if (unlikely(_c)) yield(); \
  64. else break; \
  65. } while (_c); \
  66. }
  67. #endif /* debug */
  68. #define POLL_WHILE_FALSE(_c) POLL_WHILE_TRUE(!(_c))
  69. static inline void acquire_spu_lock(struct spu *spu)
  70. {
  71. /* Save, Step 1:
  72. * Restore, Step 1:
  73. * Acquire SPU-specific mutual exclusion lock.
  74. * TBD.
  75. */
  76. }
  77. static inline void release_spu_lock(struct spu *spu)
  78. {
  79. /* Restore, Step 76:
  80. * Release SPU-specific mutual exclusion lock.
  81. * TBD.
  82. */
  83. }
  84. static inline int check_spu_isolate(struct spu_state *csa, struct spu *spu)
  85. {
  86. struct spu_problem __iomem *prob = spu->problem;
  87. u32 isolate_state;
  88. /* Save, Step 2:
  89. * Save, Step 6:
  90. * If SPU_Status[E,L,IS] any field is '1', this
  91. * SPU is in isolate state and cannot be context
  92. * saved at this time.
  93. */
  94. isolate_state = SPU_STATUS_ISOLATED_STATE |
  95. SPU_STATUS_ISOLATED_LOAD_STATUS | SPU_STATUS_ISOLATED_EXIT_STATUS;
  96. return (in_be32(&prob->spu_status_R) & isolate_state) ? 1 : 0;
  97. }
  98. static inline void disable_interrupts(struct spu_state *csa, struct spu *spu)
  99. {
  100. /* Save, Step 3:
  101. * Restore, Step 2:
  102. * Save INT_Mask_class0 in CSA.
  103. * Write INT_MASK_class0 with value of 0.
  104. * Save INT_Mask_class1 in CSA.
  105. * Write INT_MASK_class1 with value of 0.
  106. * Save INT_Mask_class2 in CSA.
  107. * Write INT_MASK_class2 with value of 0.
  108. */
  109. spin_lock_irq(&spu->register_lock);
  110. if (csa) {
  111. csa->priv1.int_mask_class0_RW = spu_int_mask_get(spu, 0);
  112. csa->priv1.int_mask_class1_RW = spu_int_mask_get(spu, 1);
  113. csa->priv1.int_mask_class2_RW = spu_int_mask_get(spu, 2);
  114. }
  115. spu_int_mask_set(spu, 0, 0ul);
  116. spu_int_mask_set(spu, 1, 0ul);
  117. spu_int_mask_set(spu, 2, 0ul);
  118. eieio();
  119. spin_unlock_irq(&spu->register_lock);
  120. }
  121. static inline void set_watchdog_timer(struct spu_state *csa, struct spu *spu)
  122. {
  123. /* Save, Step 4:
  124. * Restore, Step 25.
  125. * Set a software watchdog timer, which specifies the
  126. * maximum allowable time for a context save sequence.
  127. *
  128. * For present, this implementation will not set a global
  129. * watchdog timer, as virtualization & variable system load
  130. * may cause unpredictable execution times.
  131. */
  132. }
  133. static inline void inhibit_user_access(struct spu_state *csa, struct spu *spu)
  134. {
  135. /* Save, Step 5:
  136. * Restore, Step 3:
  137. * Inhibit user-space access (if provided) to this
  138. * SPU by unmapping the virtual pages assigned to
  139. * the SPU memory-mapped I/O (MMIO) for problem
  140. * state. TBD.
  141. */
  142. }
  143. static inline void set_switch_pending(struct spu_state *csa, struct spu *spu)
  144. {
  145. /* Save, Step 7:
  146. * Restore, Step 5:
  147. * Set a software context switch pending flag.
  148. */
  149. set_bit(SPU_CONTEXT_SWITCH_PENDING, &spu->flags);
  150. mb();
  151. }
  152. static inline void save_mfc_cntl(struct spu_state *csa, struct spu *spu)
  153. {
  154. struct spu_priv2 __iomem *priv2 = spu->priv2;
  155. /* Save, Step 8:
  156. * Suspend DMA and save MFC_CNTL.
  157. */
  158. switch (in_be64(&priv2->mfc_control_RW) &
  159. MFC_CNTL_SUSPEND_DMA_STATUS_MASK) {
  160. case MFC_CNTL_SUSPEND_IN_PROGRESS:
  161. POLL_WHILE_FALSE((in_be64(&priv2->mfc_control_RW) &
  162. MFC_CNTL_SUSPEND_DMA_STATUS_MASK) ==
  163. MFC_CNTL_SUSPEND_COMPLETE);
  164. /* fall through */
  165. case MFC_CNTL_SUSPEND_COMPLETE:
  166. if (csa) {
  167. csa->priv2.mfc_control_RW =
  168. MFC_CNTL_SUSPEND_MASK |
  169. MFC_CNTL_SUSPEND_DMA_QUEUE;
  170. }
  171. break;
  172. case MFC_CNTL_NORMAL_DMA_QUEUE_OPERATION:
  173. out_be64(&priv2->mfc_control_RW, MFC_CNTL_SUSPEND_DMA_QUEUE);
  174. POLL_WHILE_FALSE((in_be64(&priv2->mfc_control_RW) &
  175. MFC_CNTL_SUSPEND_DMA_STATUS_MASK) ==
  176. MFC_CNTL_SUSPEND_COMPLETE);
  177. if (csa) {
  178. csa->priv2.mfc_control_RW = 0;
  179. }
  180. break;
  181. }
  182. }
  183. static inline void save_spu_runcntl(struct spu_state *csa, struct spu *spu)
  184. {
  185. struct spu_problem __iomem *prob = spu->problem;
  186. /* Save, Step 9:
  187. * Save SPU_Runcntl in the CSA. This value contains
  188. * the "Application Desired State".
  189. */
  190. csa->prob.spu_runcntl_RW = in_be32(&prob->spu_runcntl_RW);
  191. }
  192. static inline void save_mfc_sr1(struct spu_state *csa, struct spu *spu)
  193. {
  194. /* Save, Step 10:
  195. * Save MFC_SR1 in the CSA.
  196. */
  197. csa->priv1.mfc_sr1_RW = spu_mfc_sr1_get(spu);
  198. }
  199. static inline void save_spu_status(struct spu_state *csa, struct spu *spu)
  200. {
  201. struct spu_problem __iomem *prob = spu->problem;
  202. /* Save, Step 11:
  203. * Read SPU_Status[R], and save to CSA.
  204. */
  205. if ((in_be32(&prob->spu_status_R) & SPU_STATUS_RUNNING) == 0) {
  206. csa->prob.spu_status_R = in_be32(&prob->spu_status_R);
  207. } else {
  208. u32 stopped;
  209. out_be32(&prob->spu_runcntl_RW, SPU_RUNCNTL_STOP);
  210. eieio();
  211. POLL_WHILE_TRUE(in_be32(&prob->spu_status_R) &
  212. SPU_STATUS_RUNNING);
  213. stopped =
  214. SPU_STATUS_INVALID_INSTR | SPU_STATUS_SINGLE_STEP |
  215. SPU_STATUS_STOPPED_BY_HALT | SPU_STATUS_STOPPED_BY_STOP;
  216. if ((in_be32(&prob->spu_status_R) & stopped) == 0)
  217. csa->prob.spu_status_R = SPU_STATUS_RUNNING;
  218. else
  219. csa->prob.spu_status_R = in_be32(&prob->spu_status_R);
  220. }
  221. }
  222. static inline void save_mfc_decr(struct spu_state *csa, struct spu *spu)
  223. {
  224. struct spu_priv2 __iomem *priv2 = spu->priv2;
  225. /* Save, Step 12:
  226. * Read MFC_CNTL[Ds]. Update saved copy of
  227. * CSA.MFC_CNTL[Ds].
  228. */
  229. csa->priv2.mfc_control_RW |=
  230. in_be64(&priv2->mfc_control_RW) & MFC_CNTL_DECREMENTER_RUNNING;
  231. }
  232. static inline void halt_mfc_decr(struct spu_state *csa, struct spu *spu)
  233. {
  234. struct spu_priv2 __iomem *priv2 = spu->priv2;
  235. /* Save, Step 13:
  236. * Write MFC_CNTL[Dh] set to a '1' to halt
  237. * the decrementer.
  238. */
  239. out_be64(&priv2->mfc_control_RW,
  240. MFC_CNTL_DECREMENTER_HALTED | MFC_CNTL_SUSPEND_MASK);
  241. eieio();
  242. }
  243. static inline void save_timebase(struct spu_state *csa, struct spu *spu)
  244. {
  245. /* Save, Step 14:
  246. * Read PPE Timebase High and Timebase low registers
  247. * and save in CSA. TBD.
  248. */
  249. csa->suspend_time = get_cycles();
  250. }
  251. static inline void remove_other_spu_access(struct spu_state *csa,
  252. struct spu *spu)
  253. {
  254. /* Save, Step 15:
  255. * Remove other SPU access to this SPU by unmapping
  256. * this SPU's pages from their address space. TBD.
  257. */
  258. }
  259. static inline void do_mfc_mssync(struct spu_state *csa, struct spu *spu)
  260. {
  261. struct spu_problem __iomem *prob = spu->problem;
  262. /* Save, Step 16:
  263. * Restore, Step 11.
  264. * Write SPU_MSSync register. Poll SPU_MSSync[P]
  265. * for a value of 0.
  266. */
  267. out_be64(&prob->spc_mssync_RW, 1UL);
  268. POLL_WHILE_TRUE(in_be64(&prob->spc_mssync_RW) & MS_SYNC_PENDING);
  269. }
  270. static inline void issue_mfc_tlbie(struct spu_state *csa, struct spu *spu)
  271. {
  272. /* Save, Step 17:
  273. * Restore, Step 12.
  274. * Restore, Step 48.
  275. * Write TLB_Invalidate_Entry[IS,VPN,L,Lp]=0 register.
  276. * Then issue a PPE sync instruction.
  277. */
  278. spu_tlb_invalidate(spu);
  279. mb();
  280. }
  281. static inline void handle_pending_interrupts(struct spu_state *csa,
  282. struct spu *spu)
  283. {
  284. /* Save, Step 18:
  285. * Handle any pending interrupts from this SPU
  286. * here. This is OS or hypervisor specific. One
  287. * option is to re-enable interrupts to handle any
  288. * pending interrupts, with the interrupt handlers
  289. * recognizing the software Context Switch Pending
  290. * flag, to ensure the SPU execution or MFC command
  291. * queue is not restarted. TBD.
  292. */
  293. }
  294. static inline void save_mfc_queues(struct spu_state *csa, struct spu *spu)
  295. {
  296. struct spu_priv2 __iomem *priv2 = spu->priv2;
  297. int i;
  298. /* Save, Step 19:
  299. * If MFC_Cntl[Se]=0 then save
  300. * MFC command queues.
  301. */
  302. if ((in_be64(&priv2->mfc_control_RW) & MFC_CNTL_DMA_QUEUES_EMPTY) == 0) {
  303. for (i = 0; i < 8; i++) {
  304. csa->priv2.puq[i].mfc_cq_data0_RW =
  305. in_be64(&priv2->puq[i].mfc_cq_data0_RW);
  306. csa->priv2.puq[i].mfc_cq_data1_RW =
  307. in_be64(&priv2->puq[i].mfc_cq_data1_RW);
  308. csa->priv2.puq[i].mfc_cq_data2_RW =
  309. in_be64(&priv2->puq[i].mfc_cq_data2_RW);
  310. csa->priv2.puq[i].mfc_cq_data3_RW =
  311. in_be64(&priv2->puq[i].mfc_cq_data3_RW);
  312. }
  313. for (i = 0; i < 16; i++) {
  314. csa->priv2.spuq[i].mfc_cq_data0_RW =
  315. in_be64(&priv2->spuq[i].mfc_cq_data0_RW);
  316. csa->priv2.spuq[i].mfc_cq_data1_RW =
  317. in_be64(&priv2->spuq[i].mfc_cq_data1_RW);
  318. csa->priv2.spuq[i].mfc_cq_data2_RW =
  319. in_be64(&priv2->spuq[i].mfc_cq_data2_RW);
  320. csa->priv2.spuq[i].mfc_cq_data3_RW =
  321. in_be64(&priv2->spuq[i].mfc_cq_data3_RW);
  322. }
  323. }
  324. }
  325. static inline void save_ppu_querymask(struct spu_state *csa, struct spu *spu)
  326. {
  327. struct spu_problem __iomem *prob = spu->problem;
  328. /* Save, Step 20:
  329. * Save the PPU_QueryMask register
  330. * in the CSA.
  331. */
  332. csa->prob.dma_querymask_RW = in_be32(&prob->dma_querymask_RW);
  333. }
  334. static inline void save_ppu_querytype(struct spu_state *csa, struct spu *spu)
  335. {
  336. struct spu_problem __iomem *prob = spu->problem;
  337. /* Save, Step 21:
  338. * Save the PPU_QueryType register
  339. * in the CSA.
  340. */
  341. csa->prob.dma_querytype_RW = in_be32(&prob->dma_querytype_RW);
  342. }
  343. static inline void save_ppu_tagstatus(struct spu_state *csa, struct spu *spu)
  344. {
  345. struct spu_problem __iomem *prob = spu->problem;
  346. /* Save the Prxy_TagStatus register in the CSA.
  347. *
  348. * It is unnecessary to restore dma_tagstatus_R, however,
  349. * dma_tagstatus_R in the CSA is accessed via backing_ops, so
  350. * we must save it.
  351. */
  352. csa->prob.dma_tagstatus_R = in_be32(&prob->dma_tagstatus_R);
  353. }
  354. static inline void save_mfc_csr_tsq(struct spu_state *csa, struct spu *spu)
  355. {
  356. struct spu_priv2 __iomem *priv2 = spu->priv2;
  357. /* Save, Step 22:
  358. * Save the MFC_CSR_TSQ register
  359. * in the LSCSA.
  360. */
  361. csa->priv2.spu_tag_status_query_RW =
  362. in_be64(&priv2->spu_tag_status_query_RW);
  363. }
  364. static inline void save_mfc_csr_cmd(struct spu_state *csa, struct spu *spu)
  365. {
  366. struct spu_priv2 __iomem *priv2 = spu->priv2;
  367. /* Save, Step 23:
  368. * Save the MFC_CSR_CMD1 and MFC_CSR_CMD2
  369. * registers in the CSA.
  370. */
  371. csa->priv2.spu_cmd_buf1_RW = in_be64(&priv2->spu_cmd_buf1_RW);
  372. csa->priv2.spu_cmd_buf2_RW = in_be64(&priv2->spu_cmd_buf2_RW);
  373. }
  374. static inline void save_mfc_csr_ato(struct spu_state *csa, struct spu *spu)
  375. {
  376. struct spu_priv2 __iomem *priv2 = spu->priv2;
  377. /* Save, Step 24:
  378. * Save the MFC_CSR_ATO register in
  379. * the CSA.
  380. */
  381. csa->priv2.spu_atomic_status_RW = in_be64(&priv2->spu_atomic_status_RW);
  382. }
  383. static inline void save_mfc_tclass_id(struct spu_state *csa, struct spu *spu)
  384. {
  385. /* Save, Step 25:
  386. * Save the MFC_TCLASS_ID register in
  387. * the CSA.
  388. */
  389. csa->priv1.mfc_tclass_id_RW = spu_mfc_tclass_id_get(spu);
  390. }
  391. static inline void set_mfc_tclass_id(struct spu_state *csa, struct spu *spu)
  392. {
  393. /* Save, Step 26:
  394. * Restore, Step 23.
  395. * Write the MFC_TCLASS_ID register with
  396. * the value 0x10000000.
  397. */
  398. spu_mfc_tclass_id_set(spu, 0x10000000);
  399. eieio();
  400. }
  401. static inline void purge_mfc_queue(struct spu_state *csa, struct spu *spu)
  402. {
  403. struct spu_priv2 __iomem *priv2 = spu->priv2;
  404. /* Save, Step 27:
  405. * Restore, Step 14.
  406. * Write MFC_CNTL[Pc]=1 (purge queue).
  407. */
  408. out_be64(&priv2->mfc_control_RW, MFC_CNTL_PURGE_DMA_REQUEST);
  409. eieio();
  410. }
  411. static inline void wait_purge_complete(struct spu_state *csa, struct spu *spu)
  412. {
  413. struct spu_priv2 __iomem *priv2 = spu->priv2;
  414. /* Save, Step 28:
  415. * Poll MFC_CNTL[Ps] until value '11' is read
  416. * (purge complete).
  417. */
  418. POLL_WHILE_FALSE((in_be64(&priv2->mfc_control_RW) &
  419. MFC_CNTL_PURGE_DMA_STATUS_MASK) ==
  420. MFC_CNTL_PURGE_DMA_COMPLETE);
  421. }
  422. static inline void setup_mfc_sr1(struct spu_state *csa, struct spu *spu)
  423. {
  424. /* Save, Step 30:
  425. * Restore, Step 18:
  426. * Write MFC_SR1 with MFC_SR1[D=0,S=1] and
  427. * MFC_SR1[TL,R,Pr,T] set correctly for the
  428. * OS specific environment.
  429. *
  430. * Implementation note: The SPU-side code
  431. * for save/restore is privileged, so the
  432. * MFC_SR1[Pr] bit is not set.
  433. *
  434. */
  435. spu_mfc_sr1_set(spu, (MFC_STATE1_MASTER_RUN_CONTROL_MASK |
  436. MFC_STATE1_RELOCATE_MASK |
  437. MFC_STATE1_BUS_TLBIE_MASK));
  438. }
  439. static inline void save_spu_npc(struct spu_state *csa, struct spu *spu)
  440. {
  441. struct spu_problem __iomem *prob = spu->problem;
  442. /* Save, Step 31:
  443. * Save SPU_NPC in the CSA.
  444. */
  445. csa->prob.spu_npc_RW = in_be32(&prob->spu_npc_RW);
  446. }
  447. static inline void save_spu_privcntl(struct spu_state *csa, struct spu *spu)
  448. {
  449. struct spu_priv2 __iomem *priv2 = spu->priv2;
  450. /* Save, Step 32:
  451. * Save SPU_PrivCntl in the CSA.
  452. */
  453. csa->priv2.spu_privcntl_RW = in_be64(&priv2->spu_privcntl_RW);
  454. }
  455. static inline void reset_spu_privcntl(struct spu_state *csa, struct spu *spu)
  456. {
  457. struct spu_priv2 __iomem *priv2 = spu->priv2;
  458. /* Save, Step 33:
  459. * Restore, Step 16:
  460. * Write SPU_PrivCntl[S,Le,A] fields reset to 0.
  461. */
  462. out_be64(&priv2->spu_privcntl_RW, 0UL);
  463. eieio();
  464. }
  465. static inline void save_spu_lslr(struct spu_state *csa, struct spu *spu)
  466. {
  467. struct spu_priv2 __iomem *priv2 = spu->priv2;
  468. /* Save, Step 34:
  469. * Save SPU_LSLR in the CSA.
  470. */
  471. csa->priv2.spu_lslr_RW = in_be64(&priv2->spu_lslr_RW);
  472. }
  473. static inline void reset_spu_lslr(struct spu_state *csa, struct spu *spu)
  474. {
  475. struct spu_priv2 __iomem *priv2 = spu->priv2;
  476. /* Save, Step 35:
  477. * Restore, Step 17.
  478. * Reset SPU_LSLR.
  479. */
  480. out_be64(&priv2->spu_lslr_RW, LS_ADDR_MASK);
  481. eieio();
  482. }
  483. static inline void save_spu_cfg(struct spu_state *csa, struct spu *spu)
  484. {
  485. struct spu_priv2 __iomem *priv2 = spu->priv2;
  486. /* Save, Step 36:
  487. * Save SPU_Cfg in the CSA.
  488. */
  489. csa->priv2.spu_cfg_RW = in_be64(&priv2->spu_cfg_RW);
  490. }
  491. static inline void save_pm_trace(struct spu_state *csa, struct spu *spu)
  492. {
  493. /* Save, Step 37:
  494. * Save PM_Trace_Tag_Wait_Mask in the CSA.
  495. * Not performed by this implementation.
  496. */
  497. }
  498. static inline void save_mfc_rag(struct spu_state *csa, struct spu *spu)
  499. {
  500. /* Save, Step 38:
  501. * Save RA_GROUP_ID register and the
  502. * RA_ENABLE reigster in the CSA.
  503. */
  504. csa->priv1.resource_allocation_groupID_RW =
  505. spu_resource_allocation_groupID_get(spu);
  506. csa->priv1.resource_allocation_enable_RW =
  507. spu_resource_allocation_enable_get(spu);
  508. }
  509. static inline void save_ppu_mb_stat(struct spu_state *csa, struct spu *spu)
  510. {
  511. struct spu_problem __iomem *prob = spu->problem;
  512. /* Save, Step 39:
  513. * Save MB_Stat register in the CSA.
  514. */
  515. csa->prob.mb_stat_R = in_be32(&prob->mb_stat_R);
  516. }
  517. static inline void save_ppu_mb(struct spu_state *csa, struct spu *spu)
  518. {
  519. struct spu_problem __iomem *prob = spu->problem;
  520. /* Save, Step 40:
  521. * Save the PPU_MB register in the CSA.
  522. */
  523. csa->prob.pu_mb_R = in_be32(&prob->pu_mb_R);
  524. }
  525. static inline void save_ppuint_mb(struct spu_state *csa, struct spu *spu)
  526. {
  527. struct spu_priv2 __iomem *priv2 = spu->priv2;
  528. /* Save, Step 41:
  529. * Save the PPUINT_MB register in the CSA.
  530. */
  531. csa->priv2.puint_mb_R = in_be64(&priv2->puint_mb_R);
  532. }
  533. static inline void save_ch_part1(struct spu_state *csa, struct spu *spu)
  534. {
  535. struct spu_priv2 __iomem *priv2 = spu->priv2;
  536. u64 idx, ch_indices[] = { 0UL, 3UL, 4UL, 24UL, 25UL, 27UL };
  537. int i;
  538. /* Save, Step 42:
  539. */
  540. /* Save CH 1, without channel count */
  541. out_be64(&priv2->spu_chnlcntptr_RW, 1);
  542. csa->spu_chnldata_RW[1] = in_be64(&priv2->spu_chnldata_RW);
  543. /* Save the following CH: [0,3,4,24,25,27] */
  544. for (i = 0; i < ARRAY_SIZE(ch_indices); i++) {
  545. idx = ch_indices[i];
  546. out_be64(&priv2->spu_chnlcntptr_RW, idx);
  547. eieio();
  548. csa->spu_chnldata_RW[idx] = in_be64(&priv2->spu_chnldata_RW);
  549. csa->spu_chnlcnt_RW[idx] = in_be64(&priv2->spu_chnlcnt_RW);
  550. out_be64(&priv2->spu_chnldata_RW, 0UL);
  551. out_be64(&priv2->spu_chnlcnt_RW, 0UL);
  552. eieio();
  553. }
  554. }
  555. static inline void save_spu_mb(struct spu_state *csa, struct spu *spu)
  556. {
  557. struct spu_priv2 __iomem *priv2 = spu->priv2;
  558. int i;
  559. /* Save, Step 43:
  560. * Save SPU Read Mailbox Channel.
  561. */
  562. out_be64(&priv2->spu_chnlcntptr_RW, 29UL);
  563. eieio();
  564. csa->spu_chnlcnt_RW[29] = in_be64(&priv2->spu_chnlcnt_RW);
  565. for (i = 0; i < 4; i++) {
  566. csa->spu_mailbox_data[i] = in_be64(&priv2->spu_chnldata_RW);
  567. }
  568. out_be64(&priv2->spu_chnlcnt_RW, 0UL);
  569. eieio();
  570. }
  571. static inline void save_mfc_cmd(struct spu_state *csa, struct spu *spu)
  572. {
  573. struct spu_priv2 __iomem *priv2 = spu->priv2;
  574. /* Save, Step 44:
  575. * Save MFC_CMD Channel.
  576. */
  577. out_be64(&priv2->spu_chnlcntptr_RW, 21UL);
  578. eieio();
  579. csa->spu_chnlcnt_RW[21] = in_be64(&priv2->spu_chnlcnt_RW);
  580. eieio();
  581. }
  582. static inline void reset_ch(struct spu_state *csa, struct spu *spu)
  583. {
  584. struct spu_priv2 __iomem *priv2 = spu->priv2;
  585. u64 ch_indices[4] = { 21UL, 23UL, 28UL, 30UL };
  586. u64 ch_counts[4] = { 16UL, 1UL, 1UL, 1UL };
  587. u64 idx;
  588. int i;
  589. /* Save, Step 45:
  590. * Reset the following CH: [21, 23, 28, 30]
  591. */
  592. for (i = 0; i < 4; i++) {
  593. idx = ch_indices[i];
  594. out_be64(&priv2->spu_chnlcntptr_RW, idx);
  595. eieio();
  596. out_be64(&priv2->spu_chnlcnt_RW, ch_counts[i]);
  597. eieio();
  598. }
  599. }
  600. static inline void resume_mfc_queue(struct spu_state *csa, struct spu *spu)
  601. {
  602. struct spu_priv2 __iomem *priv2 = spu->priv2;
  603. /* Save, Step 46:
  604. * Restore, Step 25.
  605. * Write MFC_CNTL[Sc]=0 (resume queue processing).
  606. */
  607. out_be64(&priv2->mfc_control_RW, MFC_CNTL_RESUME_DMA_QUEUE);
  608. }
  609. static inline void setup_mfc_slbs(struct spu_state *csa, struct spu *spu)
  610. {
  611. /* Save, Step 47:
  612. * Restore, Step 30.
  613. * If MFC_SR1[R]=1, write 0 to SLB_Invalidate_All
  614. * register, then initialize SLB_VSID and SLB_ESID
  615. * to provide access to SPU context save code and
  616. * LSCSA.
  617. *
  618. * This implementation places both the context
  619. * switch code and LSCSA in kernel address space.
  620. *
  621. * Further this implementation assumes that the
  622. * MFC_SR1[R]=1 (in other words, assume that
  623. * translation is desired by OS environment).
  624. */
  625. spu_invalidate_slbs(spu);
  626. spu_setup_kernel_slbs(spu, csa->lscsa, &spu_save_code);
  627. }
  628. static inline void set_switch_active(struct spu_state *csa, struct spu *spu)
  629. {
  630. /* Save, Step 48:
  631. * Restore, Step 23.
  632. * Change the software context switch pending flag
  633. * to context switch active.
  634. */
  635. set_bit(SPU_CONTEXT_SWITCH_ACTIVE, &spu->flags);
  636. clear_bit(SPU_CONTEXT_SWITCH_PENDING, &spu->flags);
  637. mb();
  638. }
  639. static inline void enable_interrupts(struct spu_state *csa, struct spu *spu)
  640. {
  641. unsigned long class1_mask = CLASS1_ENABLE_SEGMENT_FAULT_INTR |
  642. CLASS1_ENABLE_STORAGE_FAULT_INTR;
  643. /* Save, Step 49:
  644. * Restore, Step 22:
  645. * Reset and then enable interrupts, as
  646. * needed by OS.
  647. *
  648. * This implementation enables only class1
  649. * (translation) interrupts.
  650. */
  651. spin_lock_irq(&spu->register_lock);
  652. spu_int_stat_clear(spu, 0, ~0ul);
  653. spu_int_stat_clear(spu, 1, ~0ul);
  654. spu_int_stat_clear(spu, 2, ~0ul);
  655. spu_int_mask_set(spu, 0, 0ul);
  656. spu_int_mask_set(spu, 1, class1_mask);
  657. spu_int_mask_set(spu, 2, 0ul);
  658. spin_unlock_irq(&spu->register_lock);
  659. }
  660. static inline int send_mfc_dma(struct spu *spu, unsigned long ea,
  661. unsigned int ls_offset, unsigned int size,
  662. unsigned int tag, unsigned int rclass,
  663. unsigned int cmd)
  664. {
  665. struct spu_problem __iomem *prob = spu->problem;
  666. union mfc_tag_size_class_cmd command;
  667. unsigned int transfer_size;
  668. volatile unsigned int status = 0x0;
  669. while (size > 0) {
  670. transfer_size =
  671. (size > MFC_MAX_DMA_SIZE) ? MFC_MAX_DMA_SIZE : size;
  672. command.u.mfc_size = transfer_size;
  673. command.u.mfc_tag = tag;
  674. command.u.mfc_rclassid = rclass;
  675. command.u.mfc_cmd = cmd;
  676. do {
  677. out_be32(&prob->mfc_lsa_W, ls_offset);
  678. out_be64(&prob->mfc_ea_W, ea);
  679. out_be64(&prob->mfc_union_W.all64, command.all64);
  680. status =
  681. in_be32(&prob->mfc_union_W.by32.mfc_class_cmd32);
  682. if (unlikely(status & 0x2)) {
  683. cpu_relax();
  684. }
  685. } while (status & 0x3);
  686. size -= transfer_size;
  687. ea += transfer_size;
  688. ls_offset += transfer_size;
  689. }
  690. return 0;
  691. }
  692. static inline void save_ls_16kb(struct spu_state *csa, struct spu *spu)
  693. {
  694. unsigned long addr = (unsigned long)&csa->lscsa->ls[0];
  695. unsigned int ls_offset = 0x0;
  696. unsigned int size = 16384;
  697. unsigned int tag = 0;
  698. unsigned int rclass = 0;
  699. unsigned int cmd = MFC_PUT_CMD;
  700. /* Save, Step 50:
  701. * Issue a DMA command to copy the first 16K bytes
  702. * of local storage to the CSA.
  703. */
  704. send_mfc_dma(spu, addr, ls_offset, size, tag, rclass, cmd);
  705. }
  706. static inline void set_spu_npc(struct spu_state *csa, struct spu *spu)
  707. {
  708. struct spu_problem __iomem *prob = spu->problem;
  709. /* Save, Step 51:
  710. * Restore, Step 31.
  711. * Write SPU_NPC[IE]=0 and SPU_NPC[LSA] to entry
  712. * point address of context save code in local
  713. * storage.
  714. *
  715. * This implementation uses SPU-side save/restore
  716. * programs with entry points at LSA of 0.
  717. */
  718. out_be32(&prob->spu_npc_RW, 0);
  719. eieio();
  720. }
  721. static inline void set_signot1(struct spu_state *csa, struct spu *spu)
  722. {
  723. struct spu_problem __iomem *prob = spu->problem;
  724. union {
  725. u64 ull;
  726. u32 ui[2];
  727. } addr64;
  728. /* Save, Step 52:
  729. * Restore, Step 32:
  730. * Write SPU_Sig_Notify_1 register with upper 32-bits
  731. * of the CSA.LSCSA effective address.
  732. */
  733. addr64.ull = (u64) csa->lscsa;
  734. out_be32(&prob->signal_notify1, addr64.ui[0]);
  735. eieio();
  736. }
  737. static inline void set_signot2(struct spu_state *csa, struct spu *spu)
  738. {
  739. struct spu_problem __iomem *prob = spu->problem;
  740. union {
  741. u64 ull;
  742. u32 ui[2];
  743. } addr64;
  744. /* Save, Step 53:
  745. * Restore, Step 33:
  746. * Write SPU_Sig_Notify_2 register with lower 32-bits
  747. * of the CSA.LSCSA effective address.
  748. */
  749. addr64.ull = (u64) csa->lscsa;
  750. out_be32(&prob->signal_notify2, addr64.ui[1]);
  751. eieio();
  752. }
  753. static inline void send_save_code(struct spu_state *csa, struct spu *spu)
  754. {
  755. unsigned long addr = (unsigned long)&spu_save_code[0];
  756. unsigned int ls_offset = 0x0;
  757. unsigned int size = sizeof(spu_save_code);
  758. unsigned int tag = 0;
  759. unsigned int rclass = 0;
  760. unsigned int cmd = MFC_GETFS_CMD;
  761. /* Save, Step 54:
  762. * Issue a DMA command to copy context save code
  763. * to local storage and start SPU.
  764. */
  765. send_mfc_dma(spu, addr, ls_offset, size, tag, rclass, cmd);
  766. }
  767. static inline void set_ppu_querymask(struct spu_state *csa, struct spu *spu)
  768. {
  769. struct spu_problem __iomem *prob = spu->problem;
  770. /* Save, Step 55:
  771. * Restore, Step 38.
  772. * Write PPU_QueryMask=1 (enable Tag Group 0)
  773. * and issue eieio instruction.
  774. */
  775. out_be32(&prob->dma_querymask_RW, MFC_TAGID_TO_TAGMASK(0));
  776. eieio();
  777. }
  778. static inline void wait_tag_complete(struct spu_state *csa, struct spu *spu)
  779. {
  780. struct spu_problem __iomem *prob = spu->problem;
  781. u32 mask = MFC_TAGID_TO_TAGMASK(0);
  782. unsigned long flags;
  783. /* Save, Step 56:
  784. * Restore, Step 39.
  785. * Restore, Step 39.
  786. * Restore, Step 46.
  787. * Poll PPU_TagStatus[gn] until 01 (Tag group 0 complete)
  788. * or write PPU_QueryType[TS]=01 and wait for Tag Group
  789. * Complete Interrupt. Write INT_Stat_Class0 or
  790. * INT_Stat_Class2 with value of 'handled'.
  791. */
  792. POLL_WHILE_FALSE(in_be32(&prob->dma_tagstatus_R) & mask);
  793. local_irq_save(flags);
  794. spu_int_stat_clear(spu, 0, ~(0ul));
  795. spu_int_stat_clear(spu, 2, ~(0ul));
  796. local_irq_restore(flags);
  797. }
  798. static inline void wait_spu_stopped(struct spu_state *csa, struct spu *spu)
  799. {
  800. struct spu_problem __iomem *prob = spu->problem;
  801. unsigned long flags;
  802. /* Save, Step 57:
  803. * Restore, Step 40.
  804. * Poll until SPU_Status[R]=0 or wait for SPU Class 0
  805. * or SPU Class 2 interrupt. Write INT_Stat_class0
  806. * or INT_Stat_class2 with value of handled.
  807. */
  808. POLL_WHILE_TRUE(in_be32(&prob->spu_status_R) & SPU_STATUS_RUNNING);
  809. local_irq_save(flags);
  810. spu_int_stat_clear(spu, 0, ~(0ul));
  811. spu_int_stat_clear(spu, 2, ~(0ul));
  812. local_irq_restore(flags);
  813. }
  814. static inline int check_save_status(struct spu_state *csa, struct spu *spu)
  815. {
  816. struct spu_problem __iomem *prob = spu->problem;
  817. u32 complete;
  818. /* Save, Step 54:
  819. * If SPU_Status[P]=1 and SPU_Status[SC] = "success",
  820. * context save succeeded, otherwise context save
  821. * failed.
  822. */
  823. complete = ((SPU_SAVE_COMPLETE << SPU_STOP_STATUS_SHIFT) |
  824. SPU_STATUS_STOPPED_BY_STOP);
  825. return (in_be32(&prob->spu_status_R) != complete) ? 1 : 0;
  826. }
  827. static inline void terminate_spu_app(struct spu_state *csa, struct spu *spu)
  828. {
  829. /* Restore, Step 4:
  830. * If required, notify the "using application" that
  831. * the SPU task has been terminated. TBD.
  832. */
  833. }
  834. static inline void suspend_mfc_and_halt_decr(struct spu_state *csa,
  835. struct spu *spu)
  836. {
  837. struct spu_priv2 __iomem *priv2 = spu->priv2;
  838. /* Restore, Step 7:
  839. * Write MFC_Cntl[Dh,Sc,Sm]='1','1','0' to suspend
  840. * the queue and halt the decrementer.
  841. */
  842. out_be64(&priv2->mfc_control_RW, MFC_CNTL_SUSPEND_DMA_QUEUE |
  843. MFC_CNTL_DECREMENTER_HALTED);
  844. eieio();
  845. }
  846. static inline void wait_suspend_mfc_complete(struct spu_state *csa,
  847. struct spu *spu)
  848. {
  849. struct spu_priv2 __iomem *priv2 = spu->priv2;
  850. /* Restore, Step 8:
  851. * Restore, Step 47.
  852. * Poll MFC_CNTL[Ss] until 11 is returned.
  853. */
  854. POLL_WHILE_FALSE((in_be64(&priv2->mfc_control_RW) &
  855. MFC_CNTL_SUSPEND_DMA_STATUS_MASK) ==
  856. MFC_CNTL_SUSPEND_COMPLETE);
  857. }
  858. static inline int suspend_spe(struct spu_state *csa, struct spu *spu)
  859. {
  860. struct spu_problem __iomem *prob = spu->problem;
  861. /* Restore, Step 9:
  862. * If SPU_Status[R]=1, stop SPU execution
  863. * and wait for stop to complete.
  864. *
  865. * Returns 1 if SPU_Status[R]=1 on entry.
  866. * 0 otherwise
  867. */
  868. if (in_be32(&prob->spu_status_R) & SPU_STATUS_RUNNING) {
  869. if (in_be32(&prob->spu_status_R) &
  870. SPU_STATUS_ISOLATED_EXIT_STATUS) {
  871. POLL_WHILE_TRUE(in_be32(&prob->spu_status_R) &
  872. SPU_STATUS_RUNNING);
  873. }
  874. if ((in_be32(&prob->spu_status_R) &
  875. SPU_STATUS_ISOLATED_LOAD_STATUS)
  876. || (in_be32(&prob->spu_status_R) &
  877. SPU_STATUS_ISOLATED_STATE)) {
  878. out_be32(&prob->spu_runcntl_RW, SPU_RUNCNTL_STOP);
  879. eieio();
  880. POLL_WHILE_TRUE(in_be32(&prob->spu_status_R) &
  881. SPU_STATUS_RUNNING);
  882. out_be32(&prob->spu_runcntl_RW, 0x2);
  883. eieio();
  884. POLL_WHILE_TRUE(in_be32(&prob->spu_status_R) &
  885. SPU_STATUS_RUNNING);
  886. }
  887. if (in_be32(&prob->spu_status_R) &
  888. SPU_STATUS_WAITING_FOR_CHANNEL) {
  889. out_be32(&prob->spu_runcntl_RW, SPU_RUNCNTL_STOP);
  890. eieio();
  891. POLL_WHILE_TRUE(in_be32(&prob->spu_status_R) &
  892. SPU_STATUS_RUNNING);
  893. }
  894. return 1;
  895. }
  896. return 0;
  897. }
  898. static inline void clear_spu_status(struct spu_state *csa, struct spu *spu)
  899. {
  900. struct spu_problem __iomem *prob = spu->problem;
  901. /* Restore, Step 10:
  902. * If SPU_Status[R]=0 and SPU_Status[E,L,IS]=1,
  903. * release SPU from isolate state.
  904. */
  905. if (!(in_be32(&prob->spu_status_R) & SPU_STATUS_RUNNING)) {
  906. if (in_be32(&prob->spu_status_R) &
  907. SPU_STATUS_ISOLATED_EXIT_STATUS) {
  908. spu_mfc_sr1_set(spu,
  909. MFC_STATE1_MASTER_RUN_CONTROL_MASK);
  910. eieio();
  911. out_be32(&prob->spu_runcntl_RW, SPU_RUNCNTL_RUNNABLE);
  912. eieio();
  913. POLL_WHILE_TRUE(in_be32(&prob->spu_status_R) &
  914. SPU_STATUS_RUNNING);
  915. }
  916. if ((in_be32(&prob->spu_status_R) &
  917. SPU_STATUS_ISOLATED_LOAD_STATUS)
  918. || (in_be32(&prob->spu_status_R) &
  919. SPU_STATUS_ISOLATED_STATE)) {
  920. spu_mfc_sr1_set(spu,
  921. MFC_STATE1_MASTER_RUN_CONTROL_MASK);
  922. eieio();
  923. out_be32(&prob->spu_runcntl_RW, 0x2);
  924. eieio();
  925. POLL_WHILE_TRUE(in_be32(&prob->spu_status_R) &
  926. SPU_STATUS_RUNNING);
  927. }
  928. }
  929. }
  930. static inline void reset_ch_part1(struct spu_state *csa, struct spu *spu)
  931. {
  932. struct spu_priv2 __iomem *priv2 = spu->priv2;
  933. u64 ch_indices[] = { 0UL, 3UL, 4UL, 24UL, 25UL, 27UL };
  934. u64 idx;
  935. int i;
  936. /* Restore, Step 20:
  937. */
  938. /* Reset CH 1 */
  939. out_be64(&priv2->spu_chnlcntptr_RW, 1);
  940. out_be64(&priv2->spu_chnldata_RW, 0UL);
  941. /* Reset the following CH: [0,3,4,24,25,27] */
  942. for (i = 0; i < ARRAY_SIZE(ch_indices); i++) {
  943. idx = ch_indices[i];
  944. out_be64(&priv2->spu_chnlcntptr_RW, idx);
  945. eieio();
  946. out_be64(&priv2->spu_chnldata_RW, 0UL);
  947. out_be64(&priv2->spu_chnlcnt_RW, 0UL);
  948. eieio();
  949. }
  950. }
  951. static inline void reset_ch_part2(struct spu_state *csa, struct spu *spu)
  952. {
  953. struct spu_priv2 __iomem *priv2 = spu->priv2;
  954. u64 ch_indices[5] = { 21UL, 23UL, 28UL, 29UL, 30UL };
  955. u64 ch_counts[5] = { 16UL, 1UL, 1UL, 0UL, 1UL };
  956. u64 idx;
  957. int i;
  958. /* Restore, Step 21:
  959. * Reset the following CH: [21, 23, 28, 29, 30]
  960. */
  961. for (i = 0; i < 5; i++) {
  962. idx = ch_indices[i];
  963. out_be64(&priv2->spu_chnlcntptr_RW, idx);
  964. eieio();
  965. out_be64(&priv2->spu_chnlcnt_RW, ch_counts[i]);
  966. eieio();
  967. }
  968. }
  969. static inline void setup_spu_status_part1(struct spu_state *csa,
  970. struct spu *spu)
  971. {
  972. u32 status_P = SPU_STATUS_STOPPED_BY_STOP;
  973. u32 status_I = SPU_STATUS_INVALID_INSTR;
  974. u32 status_H = SPU_STATUS_STOPPED_BY_HALT;
  975. u32 status_S = SPU_STATUS_SINGLE_STEP;
  976. u32 status_S_I = SPU_STATUS_SINGLE_STEP | SPU_STATUS_INVALID_INSTR;
  977. u32 status_S_P = SPU_STATUS_SINGLE_STEP | SPU_STATUS_STOPPED_BY_STOP;
  978. u32 status_P_H = SPU_STATUS_STOPPED_BY_HALT |SPU_STATUS_STOPPED_BY_STOP;
  979. u32 status_P_I = SPU_STATUS_STOPPED_BY_STOP |SPU_STATUS_INVALID_INSTR;
  980. u32 status_code;
  981. /* Restore, Step 27:
  982. * If the CSA.SPU_Status[I,S,H,P]=1 then add the correct
  983. * instruction sequence to the end of the SPU based restore
  984. * code (after the "context restored" stop and signal) to
  985. * restore the correct SPU status.
  986. *
  987. * NOTE: Rather than modifying the SPU executable, we
  988. * instead add a new 'stopped_status' field to the
  989. * LSCSA. The SPU-side restore reads this field and
  990. * takes the appropriate action when exiting.
  991. */
  992. status_code =
  993. (csa->prob.spu_status_R >> SPU_STOP_STATUS_SHIFT) & 0xFFFF;
  994. if ((csa->prob.spu_status_R & status_P_I) == status_P_I) {
  995. /* SPU_Status[P,I]=1 - Illegal Instruction followed
  996. * by Stop and Signal instruction, followed by 'br -4'.
  997. *
  998. */
  999. csa->lscsa->stopped_status.slot[0] = SPU_STOPPED_STATUS_P_I;
  1000. csa->lscsa->stopped_status.slot[1] = status_code;
  1001. } else if ((csa->prob.spu_status_R & status_P_H) == status_P_H) {
  1002. /* SPU_Status[P,H]=1 - Halt Conditional, followed
  1003. * by Stop and Signal instruction, followed by
  1004. * 'br -4'.
  1005. */
  1006. csa->lscsa->stopped_status.slot[0] = SPU_STOPPED_STATUS_P_H;
  1007. csa->lscsa->stopped_status.slot[1] = status_code;
  1008. } else if ((csa->prob.spu_status_R & status_S_P) == status_S_P) {
  1009. /* SPU_Status[S,P]=1 - Stop and Signal instruction
  1010. * followed by 'br -4'.
  1011. */
  1012. csa->lscsa->stopped_status.slot[0] = SPU_STOPPED_STATUS_S_P;
  1013. csa->lscsa->stopped_status.slot[1] = status_code;
  1014. } else if ((csa->prob.spu_status_R & status_S_I) == status_S_I) {
  1015. /* SPU_Status[S,I]=1 - Illegal instruction followed
  1016. * by 'br -4'.
  1017. */
  1018. csa->lscsa->stopped_status.slot[0] = SPU_STOPPED_STATUS_S_I;
  1019. csa->lscsa->stopped_status.slot[1] = status_code;
  1020. } else if ((csa->prob.spu_status_R & status_P) == status_P) {
  1021. /* SPU_Status[P]=1 - Stop and Signal instruction
  1022. * followed by 'br -4'.
  1023. */
  1024. csa->lscsa->stopped_status.slot[0] = SPU_STOPPED_STATUS_P;
  1025. csa->lscsa->stopped_status.slot[1] = status_code;
  1026. } else if ((csa->prob.spu_status_R & status_H) == status_H) {
  1027. /* SPU_Status[H]=1 - Halt Conditional, followed
  1028. * by 'br -4'.
  1029. */
  1030. csa->lscsa->stopped_status.slot[0] = SPU_STOPPED_STATUS_H;
  1031. } else if ((csa->prob.spu_status_R & status_S) == status_S) {
  1032. /* SPU_Status[S]=1 - Two nop instructions.
  1033. */
  1034. csa->lscsa->stopped_status.slot[0] = SPU_STOPPED_STATUS_S;
  1035. } else if ((csa->prob.spu_status_R & status_I) == status_I) {
  1036. /* SPU_Status[I]=1 - Illegal instruction followed
  1037. * by 'br -4'.
  1038. */
  1039. csa->lscsa->stopped_status.slot[0] = SPU_STOPPED_STATUS_I;
  1040. }
  1041. }
  1042. static inline void setup_spu_status_part2(struct spu_state *csa,
  1043. struct spu *spu)
  1044. {
  1045. u32 mask;
  1046. /* Restore, Step 28:
  1047. * If the CSA.SPU_Status[I,S,H,P,R]=0 then
  1048. * add a 'br *' instruction to the end of
  1049. * the SPU based restore code.
  1050. *
  1051. * NOTE: Rather than modifying the SPU executable, we
  1052. * instead add a new 'stopped_status' field to the
  1053. * LSCSA. The SPU-side restore reads this field and
  1054. * takes the appropriate action when exiting.
  1055. */
  1056. mask = SPU_STATUS_INVALID_INSTR |
  1057. SPU_STATUS_SINGLE_STEP |
  1058. SPU_STATUS_STOPPED_BY_HALT |
  1059. SPU_STATUS_STOPPED_BY_STOP | SPU_STATUS_RUNNING;
  1060. if (!(csa->prob.spu_status_R & mask)) {
  1061. csa->lscsa->stopped_status.slot[0] = SPU_STOPPED_STATUS_R;
  1062. }
  1063. }
  1064. static inline void restore_mfc_rag(struct spu_state *csa, struct spu *spu)
  1065. {
  1066. /* Restore, Step 29:
  1067. * Restore RA_GROUP_ID register and the
  1068. * RA_ENABLE reigster from the CSA.
  1069. */
  1070. spu_resource_allocation_groupID_set(spu,
  1071. csa->priv1.resource_allocation_groupID_RW);
  1072. spu_resource_allocation_enable_set(spu,
  1073. csa->priv1.resource_allocation_enable_RW);
  1074. }
  1075. static inline void send_restore_code(struct spu_state *csa, struct spu *spu)
  1076. {
  1077. unsigned long addr = (unsigned long)&spu_restore_code[0];
  1078. unsigned int ls_offset = 0x0;
  1079. unsigned int size = sizeof(spu_restore_code);
  1080. unsigned int tag = 0;
  1081. unsigned int rclass = 0;
  1082. unsigned int cmd = MFC_GETFS_CMD;
  1083. /* Restore, Step 37:
  1084. * Issue MFC DMA command to copy context
  1085. * restore code to local storage.
  1086. */
  1087. send_mfc_dma(spu, addr, ls_offset, size, tag, rclass, cmd);
  1088. }
  1089. static inline void setup_decr(struct spu_state *csa, struct spu *spu)
  1090. {
  1091. /* Restore, Step 34:
  1092. * If CSA.MFC_CNTL[Ds]=1 (decrementer was
  1093. * running) then adjust decrementer, set
  1094. * decrementer running status in LSCSA,
  1095. * and set decrementer "wrapped" status
  1096. * in LSCSA.
  1097. */
  1098. if (csa->priv2.mfc_control_RW & MFC_CNTL_DECREMENTER_RUNNING) {
  1099. cycles_t resume_time = get_cycles();
  1100. cycles_t delta_time = resume_time - csa->suspend_time;
  1101. csa->lscsa->decr_status.slot[0] = SPU_DECR_STATUS_RUNNING;
  1102. if (csa->lscsa->decr.slot[0] < delta_time) {
  1103. csa->lscsa->decr_status.slot[0] |=
  1104. SPU_DECR_STATUS_WRAPPED;
  1105. }
  1106. csa->lscsa->decr.slot[0] -= delta_time;
  1107. } else {
  1108. csa->lscsa->decr_status.slot[0] = 0;
  1109. }
  1110. }
  1111. static inline void setup_ppu_mb(struct spu_state *csa, struct spu *spu)
  1112. {
  1113. /* Restore, Step 35:
  1114. * Copy the CSA.PU_MB data into the LSCSA.
  1115. */
  1116. csa->lscsa->ppu_mb.slot[0] = csa->prob.pu_mb_R;
  1117. }
  1118. static inline void setup_ppuint_mb(struct spu_state *csa, struct spu *spu)
  1119. {
  1120. /* Restore, Step 36:
  1121. * Copy the CSA.PUINT_MB data into the LSCSA.
  1122. */
  1123. csa->lscsa->ppuint_mb.slot[0] = csa->priv2.puint_mb_R;
  1124. }
  1125. static inline int check_restore_status(struct spu_state *csa, struct spu *spu)
  1126. {
  1127. struct spu_problem __iomem *prob = spu->problem;
  1128. u32 complete;
  1129. /* Restore, Step 40:
  1130. * If SPU_Status[P]=1 and SPU_Status[SC] = "success",
  1131. * context restore succeeded, otherwise context restore
  1132. * failed.
  1133. */
  1134. complete = ((SPU_RESTORE_COMPLETE << SPU_STOP_STATUS_SHIFT) |
  1135. SPU_STATUS_STOPPED_BY_STOP);
  1136. return (in_be32(&prob->spu_status_R) != complete) ? 1 : 0;
  1137. }
  1138. static inline void restore_spu_privcntl(struct spu_state *csa, struct spu *spu)
  1139. {
  1140. struct spu_priv2 __iomem *priv2 = spu->priv2;
  1141. /* Restore, Step 41:
  1142. * Restore SPU_PrivCntl from the CSA.
  1143. */
  1144. out_be64(&priv2->spu_privcntl_RW, csa->priv2.spu_privcntl_RW);
  1145. eieio();
  1146. }
  1147. static inline void restore_status_part1(struct spu_state *csa, struct spu *spu)
  1148. {
  1149. struct spu_problem __iomem *prob = spu->problem;
  1150. u32 mask;
  1151. /* Restore, Step 42:
  1152. * If any CSA.SPU_Status[I,S,H,P]=1, then
  1153. * restore the error or single step state.
  1154. */
  1155. mask = SPU_STATUS_INVALID_INSTR |
  1156. SPU_STATUS_SINGLE_STEP |
  1157. SPU_STATUS_STOPPED_BY_HALT | SPU_STATUS_STOPPED_BY_STOP;
  1158. if (csa->prob.spu_status_R & mask) {
  1159. out_be32(&prob->spu_runcntl_RW, SPU_RUNCNTL_RUNNABLE);
  1160. eieio();
  1161. POLL_WHILE_TRUE(in_be32(&prob->spu_status_R) &
  1162. SPU_STATUS_RUNNING);
  1163. }
  1164. }
  1165. static inline void restore_status_part2(struct spu_state *csa, struct spu *spu)
  1166. {
  1167. struct spu_problem __iomem *prob = spu->problem;
  1168. u32 mask;
  1169. /* Restore, Step 43:
  1170. * If all CSA.SPU_Status[I,S,H,P,R]=0 then write
  1171. * SPU_RunCntl[R0R1]='01', wait for SPU_Status[R]=1,
  1172. * then write '00' to SPU_RunCntl[R0R1] and wait
  1173. * for SPU_Status[R]=0.
  1174. */
  1175. mask = SPU_STATUS_INVALID_INSTR |
  1176. SPU_STATUS_SINGLE_STEP |
  1177. SPU_STATUS_STOPPED_BY_HALT |
  1178. SPU_STATUS_STOPPED_BY_STOP | SPU_STATUS_RUNNING;
  1179. if (!(csa->prob.spu_status_R & mask)) {
  1180. out_be32(&prob->spu_runcntl_RW, SPU_RUNCNTL_RUNNABLE);
  1181. eieio();
  1182. POLL_WHILE_FALSE(in_be32(&prob->spu_status_R) &
  1183. SPU_STATUS_RUNNING);
  1184. out_be32(&prob->spu_runcntl_RW, SPU_RUNCNTL_STOP);
  1185. eieio();
  1186. POLL_WHILE_TRUE(in_be32(&prob->spu_status_R) &
  1187. SPU_STATUS_RUNNING);
  1188. }
  1189. }
  1190. static inline void restore_ls_16kb(struct spu_state *csa, struct spu *spu)
  1191. {
  1192. unsigned long addr = (unsigned long)&csa->lscsa->ls[0];
  1193. unsigned int ls_offset = 0x0;
  1194. unsigned int size = 16384;
  1195. unsigned int tag = 0;
  1196. unsigned int rclass = 0;
  1197. unsigned int cmd = MFC_GET_CMD;
  1198. /* Restore, Step 44:
  1199. * Issue a DMA command to restore the first
  1200. * 16kb of local storage from CSA.
  1201. */
  1202. send_mfc_dma(spu, addr, ls_offset, size, tag, rclass, cmd);
  1203. }
  1204. static inline void suspend_mfc(struct spu_state *csa, struct spu *spu)
  1205. {
  1206. struct spu_priv2 __iomem *priv2 = spu->priv2;
  1207. /* Restore, Step 47.
  1208. * Write MFC_Cntl[Sc,Sm]='1','0' to suspend
  1209. * the queue.
  1210. */
  1211. out_be64(&priv2->mfc_control_RW, MFC_CNTL_SUSPEND_DMA_QUEUE);
  1212. eieio();
  1213. }
  1214. static inline void clear_interrupts(struct spu_state *csa, struct spu *spu)
  1215. {
  1216. /* Restore, Step 49:
  1217. * Write INT_MASK_class0 with value of 0.
  1218. * Write INT_MASK_class1 with value of 0.
  1219. * Write INT_MASK_class2 with value of 0.
  1220. * Write INT_STAT_class0 with value of -1.
  1221. * Write INT_STAT_class1 with value of -1.
  1222. * Write INT_STAT_class2 with value of -1.
  1223. */
  1224. spin_lock_irq(&spu->register_lock);
  1225. spu_int_mask_set(spu, 0, 0ul);
  1226. spu_int_mask_set(spu, 1, 0ul);
  1227. spu_int_mask_set(spu, 2, 0ul);
  1228. spu_int_stat_clear(spu, 0, ~0ul);
  1229. spu_int_stat_clear(spu, 1, ~0ul);
  1230. spu_int_stat_clear(spu, 2, ~0ul);
  1231. spin_unlock_irq(&spu->register_lock);
  1232. }
  1233. static inline void restore_mfc_queues(struct spu_state *csa, struct spu *spu)
  1234. {
  1235. struct spu_priv2 __iomem *priv2 = spu->priv2;
  1236. int i;
  1237. /* Restore, Step 50:
  1238. * If MFC_Cntl[Se]!=0 then restore
  1239. * MFC command queues.
  1240. */
  1241. if ((csa->priv2.mfc_control_RW & MFC_CNTL_DMA_QUEUES_EMPTY_MASK) == 0) {
  1242. for (i = 0; i < 8; i++) {
  1243. out_be64(&priv2->puq[i].mfc_cq_data0_RW,
  1244. csa->priv2.puq[i].mfc_cq_data0_RW);
  1245. out_be64(&priv2->puq[i].mfc_cq_data1_RW,
  1246. csa->priv2.puq[i].mfc_cq_data1_RW);
  1247. out_be64(&priv2->puq[i].mfc_cq_data2_RW,
  1248. csa->priv2.puq[i].mfc_cq_data2_RW);
  1249. out_be64(&priv2->puq[i].mfc_cq_data3_RW,
  1250. csa->priv2.puq[i].mfc_cq_data3_RW);
  1251. }
  1252. for (i = 0; i < 16; i++) {
  1253. out_be64(&priv2->spuq[i].mfc_cq_data0_RW,
  1254. csa->priv2.spuq[i].mfc_cq_data0_RW);
  1255. out_be64(&priv2->spuq[i].mfc_cq_data1_RW,
  1256. csa->priv2.spuq[i].mfc_cq_data1_RW);
  1257. out_be64(&priv2->spuq[i].mfc_cq_data2_RW,
  1258. csa->priv2.spuq[i].mfc_cq_data2_RW);
  1259. out_be64(&priv2->spuq[i].mfc_cq_data3_RW,
  1260. csa->priv2.spuq[i].mfc_cq_data3_RW);
  1261. }
  1262. }
  1263. eieio();
  1264. }
  1265. static inline void restore_ppu_querymask(struct spu_state *csa, struct spu *spu)
  1266. {
  1267. struct spu_problem __iomem *prob = spu->problem;
  1268. /* Restore, Step 51:
  1269. * Restore the PPU_QueryMask register from CSA.
  1270. */
  1271. out_be32(&prob->dma_querymask_RW, csa->prob.dma_querymask_RW);
  1272. eieio();
  1273. }
  1274. static inline void restore_ppu_querytype(struct spu_state *csa, struct spu *spu)
  1275. {
  1276. struct spu_problem __iomem *prob = spu->problem;
  1277. /* Restore, Step 52:
  1278. * Restore the PPU_QueryType register from CSA.
  1279. */
  1280. out_be32(&prob->dma_querytype_RW, csa->prob.dma_querytype_RW);
  1281. eieio();
  1282. }
  1283. static inline void restore_mfc_csr_tsq(struct spu_state *csa, struct spu *spu)
  1284. {
  1285. struct spu_priv2 __iomem *priv2 = spu->priv2;
  1286. /* Restore, Step 53:
  1287. * Restore the MFC_CSR_TSQ register from CSA.
  1288. */
  1289. out_be64(&priv2->spu_tag_status_query_RW,
  1290. csa->priv2.spu_tag_status_query_RW);
  1291. eieio();
  1292. }
  1293. static inline void restore_mfc_csr_cmd(struct spu_state *csa, struct spu *spu)
  1294. {
  1295. struct spu_priv2 __iomem *priv2 = spu->priv2;
  1296. /* Restore, Step 54:
  1297. * Restore the MFC_CSR_CMD1 and MFC_CSR_CMD2
  1298. * registers from CSA.
  1299. */
  1300. out_be64(&priv2->spu_cmd_buf1_RW, csa->priv2.spu_cmd_buf1_RW);
  1301. out_be64(&priv2->spu_cmd_buf2_RW, csa->priv2.spu_cmd_buf2_RW);
  1302. eieio();
  1303. }
  1304. static inline void restore_mfc_csr_ato(struct spu_state *csa, struct spu *spu)
  1305. {
  1306. struct spu_priv2 __iomem *priv2 = spu->priv2;
  1307. /* Restore, Step 55:
  1308. * Restore the MFC_CSR_ATO register from CSA.
  1309. */
  1310. out_be64(&priv2->spu_atomic_status_RW, csa->priv2.spu_atomic_status_RW);
  1311. }
  1312. static inline void restore_mfc_tclass_id(struct spu_state *csa, struct spu *spu)
  1313. {
  1314. /* Restore, Step 56:
  1315. * Restore the MFC_TCLASS_ID register from CSA.
  1316. */
  1317. spu_mfc_tclass_id_set(spu, csa->priv1.mfc_tclass_id_RW);
  1318. eieio();
  1319. }
  1320. static inline void set_llr_event(struct spu_state *csa, struct spu *spu)
  1321. {
  1322. u64 ch0_cnt, ch0_data;
  1323. u64 ch1_data;
  1324. /* Restore, Step 57:
  1325. * Set the Lock Line Reservation Lost Event by:
  1326. * 1. OR CSA.SPU_Event_Status with bit 21 (Lr) set to 1.
  1327. * 2. If CSA.SPU_Channel_0_Count=0 and
  1328. * CSA.SPU_Wr_Event_Mask[Lr]=1 and
  1329. * CSA.SPU_Event_Status[Lr]=0 then set
  1330. * CSA.SPU_Event_Status_Count=1.
  1331. */
  1332. ch0_cnt = csa->spu_chnlcnt_RW[0];
  1333. ch0_data = csa->spu_chnldata_RW[0];
  1334. ch1_data = csa->spu_chnldata_RW[1];
  1335. csa->spu_chnldata_RW[0] |= MFC_LLR_LOST_EVENT;
  1336. if ((ch0_cnt == 0) && !(ch0_data & MFC_LLR_LOST_EVENT) &&
  1337. (ch1_data & MFC_LLR_LOST_EVENT)) {
  1338. csa->spu_chnlcnt_RW[0] = 1;
  1339. }
  1340. }
  1341. static inline void restore_decr_wrapped(struct spu_state *csa, struct spu *spu)
  1342. {
  1343. /* Restore, Step 58:
  1344. * If the status of the CSA software decrementer
  1345. * "wrapped" flag is set, OR in a '1' to
  1346. * CSA.SPU_Event_Status[Tm].
  1347. */
  1348. if (!(csa->lscsa->decr_status.slot[0] & SPU_DECR_STATUS_WRAPPED))
  1349. return;
  1350. if ((csa->spu_chnlcnt_RW[0] == 0) &&
  1351. (csa->spu_chnldata_RW[1] & 0x20) &&
  1352. !(csa->spu_chnldata_RW[0] & 0x20))
  1353. csa->spu_chnlcnt_RW[0] = 1;
  1354. csa->spu_chnldata_RW[0] |= 0x20;
  1355. }
  1356. static inline void restore_ch_part1(struct spu_state *csa, struct spu *spu)
  1357. {
  1358. struct spu_priv2 __iomem *priv2 = spu->priv2;
  1359. u64 idx, ch_indices[] = { 0UL, 3UL, 4UL, 24UL, 25UL, 27UL };
  1360. int i;
  1361. /* Restore, Step 59:
  1362. * Restore the following CH: [0,3,4,24,25,27]
  1363. */
  1364. for (i = 0; i < ARRAY_SIZE(ch_indices); i++) {
  1365. idx = ch_indices[i];
  1366. out_be64(&priv2->spu_chnlcntptr_RW, idx);
  1367. eieio();
  1368. out_be64(&priv2->spu_chnldata_RW, csa->spu_chnldata_RW[idx]);
  1369. out_be64(&priv2->spu_chnlcnt_RW, csa->spu_chnlcnt_RW[idx]);
  1370. eieio();
  1371. }
  1372. }
  1373. static inline void restore_ch_part2(struct spu_state *csa, struct spu *spu)
  1374. {
  1375. struct spu_priv2 __iomem *priv2 = spu->priv2;
  1376. u64 ch_indices[3] = { 9UL, 21UL, 23UL };
  1377. u64 ch_counts[3] = { 1UL, 16UL, 1UL };
  1378. u64 idx;
  1379. int i;
  1380. /* Restore, Step 60:
  1381. * Restore the following CH: [9,21,23].
  1382. */
  1383. ch_counts[0] = 1UL;
  1384. ch_counts[1] = csa->spu_chnlcnt_RW[21];
  1385. ch_counts[2] = 1UL;
  1386. for (i = 0; i < 3; i++) {
  1387. idx = ch_indices[i];
  1388. out_be64(&priv2->spu_chnlcntptr_RW, idx);
  1389. eieio();
  1390. out_be64(&priv2->spu_chnlcnt_RW, ch_counts[i]);
  1391. eieio();
  1392. }
  1393. }
  1394. static inline void restore_spu_lslr(struct spu_state *csa, struct spu *spu)
  1395. {
  1396. struct spu_priv2 __iomem *priv2 = spu->priv2;
  1397. /* Restore, Step 61:
  1398. * Restore the SPU_LSLR register from CSA.
  1399. */
  1400. out_be64(&priv2->spu_lslr_RW, csa->priv2.spu_lslr_RW);
  1401. eieio();
  1402. }
  1403. static inline void restore_spu_cfg(struct spu_state *csa, struct spu *spu)
  1404. {
  1405. struct spu_priv2 __iomem *priv2 = spu->priv2;
  1406. /* Restore, Step 62:
  1407. * Restore the SPU_Cfg register from CSA.
  1408. */
  1409. out_be64(&priv2->spu_cfg_RW, csa->priv2.spu_cfg_RW);
  1410. eieio();
  1411. }
  1412. static inline void restore_pm_trace(struct spu_state *csa, struct spu *spu)
  1413. {
  1414. /* Restore, Step 63:
  1415. * Restore PM_Trace_Tag_Wait_Mask from CSA.
  1416. * Not performed by this implementation.
  1417. */
  1418. }
  1419. static inline void restore_spu_npc(struct spu_state *csa, struct spu *spu)
  1420. {
  1421. struct spu_problem __iomem *prob = spu->problem;
  1422. /* Restore, Step 64:
  1423. * Restore SPU_NPC from CSA.
  1424. */
  1425. out_be32(&prob->spu_npc_RW, csa->prob.spu_npc_RW);
  1426. eieio();
  1427. }
  1428. static inline void restore_spu_mb(struct spu_state *csa, struct spu *spu)
  1429. {
  1430. struct spu_priv2 __iomem *priv2 = spu->priv2;
  1431. int i;
  1432. /* Restore, Step 65:
  1433. * Restore MFC_RdSPU_MB from CSA.
  1434. */
  1435. out_be64(&priv2->spu_chnlcntptr_RW, 29UL);
  1436. eieio();
  1437. out_be64(&priv2->spu_chnlcnt_RW, csa->spu_chnlcnt_RW[29]);
  1438. for (i = 0; i < 4; i++) {
  1439. out_be64(&priv2->spu_chnldata_RW, csa->spu_mailbox_data[i]);
  1440. }
  1441. eieio();
  1442. }
  1443. static inline void check_ppu_mb_stat(struct spu_state *csa, struct spu *spu)
  1444. {
  1445. struct spu_problem __iomem *prob = spu->problem;
  1446. u32 dummy = 0;
  1447. /* Restore, Step 66:
  1448. * If CSA.MB_Stat[P]=0 (mailbox empty) then
  1449. * read from the PPU_MB register.
  1450. */
  1451. if ((csa->prob.mb_stat_R & 0xFF) == 0) {
  1452. dummy = in_be32(&prob->pu_mb_R);
  1453. eieio();
  1454. }
  1455. }
  1456. static inline void check_ppuint_mb_stat(struct spu_state *csa, struct spu *spu)
  1457. {
  1458. struct spu_priv2 __iomem *priv2 = spu->priv2;
  1459. u64 dummy = 0UL;
  1460. /* Restore, Step 66:
  1461. * If CSA.MB_Stat[I]=0 (mailbox empty) then
  1462. * read from the PPUINT_MB register.
  1463. */
  1464. if ((csa->prob.mb_stat_R & 0xFF0000) == 0) {
  1465. dummy = in_be64(&priv2->puint_mb_R);
  1466. eieio();
  1467. spu_int_stat_clear(spu, 2, CLASS2_ENABLE_MAILBOX_INTR);
  1468. eieio();
  1469. }
  1470. }
  1471. static inline void restore_mfc_sr1(struct spu_state *csa, struct spu *spu)
  1472. {
  1473. /* Restore, Step 69:
  1474. * Restore the MFC_SR1 register from CSA.
  1475. */
  1476. spu_mfc_sr1_set(spu, csa->priv1.mfc_sr1_RW);
  1477. eieio();
  1478. }
  1479. static inline void restore_other_spu_access(struct spu_state *csa,
  1480. struct spu *spu)
  1481. {
  1482. /* Restore, Step 70:
  1483. * Restore other SPU mappings to this SPU. TBD.
  1484. */
  1485. }
  1486. static inline void restore_spu_runcntl(struct spu_state *csa, struct spu *spu)
  1487. {
  1488. struct spu_problem __iomem *prob = spu->problem;
  1489. /* Restore, Step 71:
  1490. * If CSA.SPU_Status[R]=1 then write
  1491. * SPU_RunCntl[R0R1]='01'.
  1492. */
  1493. if (csa->prob.spu_status_R & SPU_STATUS_RUNNING) {
  1494. out_be32(&prob->spu_runcntl_RW, SPU_RUNCNTL_RUNNABLE);
  1495. eieio();
  1496. }
  1497. }
  1498. static inline void restore_mfc_cntl(struct spu_state *csa, struct spu *spu)
  1499. {
  1500. struct spu_priv2 __iomem *priv2 = spu->priv2;
  1501. /* Restore, Step 72:
  1502. * Restore the MFC_CNTL register for the CSA.
  1503. */
  1504. out_be64(&priv2->mfc_control_RW, csa->priv2.mfc_control_RW);
  1505. eieio();
  1506. /*
  1507. * FIXME: this is to restart a DMA that we were processing
  1508. * before the save. better remember the fault information
  1509. * in the csa instead.
  1510. */
  1511. if ((csa->priv2.mfc_control_RW & MFC_CNTL_SUSPEND_DMA_QUEUE_MASK)) {
  1512. out_be64(&priv2->mfc_control_RW, MFC_CNTL_RESTART_DMA_COMMAND);
  1513. eieio();
  1514. }
  1515. }
  1516. static inline void enable_user_access(struct spu_state *csa, struct spu *spu)
  1517. {
  1518. /* Restore, Step 73:
  1519. * Enable user-space access (if provided) to this
  1520. * SPU by mapping the virtual pages assigned to
  1521. * the SPU memory-mapped I/O (MMIO) for problem
  1522. * state. TBD.
  1523. */
  1524. }
  1525. static inline void reset_switch_active(struct spu_state *csa, struct spu *spu)
  1526. {
  1527. /* Restore, Step 74:
  1528. * Reset the "context switch active" flag.
  1529. */
  1530. clear_bit(SPU_CONTEXT_SWITCH_ACTIVE, &spu->flags);
  1531. mb();
  1532. }
  1533. static inline void reenable_interrupts(struct spu_state *csa, struct spu *spu)
  1534. {
  1535. /* Restore, Step 75:
  1536. * Re-enable SPU interrupts.
  1537. */
  1538. spin_lock_irq(&spu->register_lock);
  1539. spu_int_mask_set(spu, 0, csa->priv1.int_mask_class0_RW);
  1540. spu_int_mask_set(spu, 1, csa->priv1.int_mask_class1_RW);
  1541. spu_int_mask_set(spu, 2, csa->priv1.int_mask_class2_RW);
  1542. spin_unlock_irq(&spu->register_lock);
  1543. }
  1544. static int quiece_spu(struct spu_state *prev, struct spu *spu)
  1545. {
  1546. /*
  1547. * Combined steps 2-18 of SPU context save sequence, which
  1548. * quiesce the SPU state (disable SPU execution, MFC command
  1549. * queues, decrementer, SPU interrupts, etc.).
  1550. *
  1551. * Returns 0 on success.
  1552. * 2 if failed step 2.
  1553. * 6 if failed step 6.
  1554. */
  1555. if (check_spu_isolate(prev, spu)) { /* Step 2. */
  1556. return 2;
  1557. }
  1558. disable_interrupts(prev, spu); /* Step 3. */
  1559. set_watchdog_timer(prev, spu); /* Step 4. */
  1560. inhibit_user_access(prev, spu); /* Step 5. */
  1561. if (check_spu_isolate(prev, spu)) { /* Step 6. */
  1562. return 6;
  1563. }
  1564. set_switch_pending(prev, spu); /* Step 7. */
  1565. save_mfc_cntl(prev, spu); /* Step 8. */
  1566. save_spu_runcntl(prev, spu); /* Step 9. */
  1567. save_mfc_sr1(prev, spu); /* Step 10. */
  1568. save_spu_status(prev, spu); /* Step 11. */
  1569. save_mfc_decr(prev, spu); /* Step 12. */
  1570. halt_mfc_decr(prev, spu); /* Step 13. */
  1571. save_timebase(prev, spu); /* Step 14. */
  1572. remove_other_spu_access(prev, spu); /* Step 15. */
  1573. do_mfc_mssync(prev, spu); /* Step 16. */
  1574. issue_mfc_tlbie(prev, spu); /* Step 17. */
  1575. handle_pending_interrupts(prev, spu); /* Step 18. */
  1576. return 0;
  1577. }
  1578. static void save_csa(struct spu_state *prev, struct spu *spu)
  1579. {
  1580. /*
  1581. * Combine steps 19-44 of SPU context save sequence, which
  1582. * save regions of the privileged & problem state areas.
  1583. */
  1584. save_mfc_queues(prev, spu); /* Step 19. */
  1585. save_ppu_querymask(prev, spu); /* Step 20. */
  1586. save_ppu_querytype(prev, spu); /* Step 21. */
  1587. save_ppu_tagstatus(prev, spu); /* NEW. */
  1588. save_mfc_csr_tsq(prev, spu); /* Step 22. */
  1589. save_mfc_csr_cmd(prev, spu); /* Step 23. */
  1590. save_mfc_csr_ato(prev, spu); /* Step 24. */
  1591. save_mfc_tclass_id(prev, spu); /* Step 25. */
  1592. set_mfc_tclass_id(prev, spu); /* Step 26. */
  1593. purge_mfc_queue(prev, spu); /* Step 27. */
  1594. wait_purge_complete(prev, spu); /* Step 28. */
  1595. setup_mfc_sr1(prev, spu); /* Step 30. */
  1596. save_spu_npc(prev, spu); /* Step 31. */
  1597. save_spu_privcntl(prev, spu); /* Step 32. */
  1598. reset_spu_privcntl(prev, spu); /* Step 33. */
  1599. save_spu_lslr(prev, spu); /* Step 34. */
  1600. reset_spu_lslr(prev, spu); /* Step 35. */
  1601. save_spu_cfg(prev, spu); /* Step 36. */
  1602. save_pm_trace(prev, spu); /* Step 37. */
  1603. save_mfc_rag(prev, spu); /* Step 38. */
  1604. save_ppu_mb_stat(prev, spu); /* Step 39. */
  1605. save_ppu_mb(prev, spu); /* Step 40. */
  1606. save_ppuint_mb(prev, spu); /* Step 41. */
  1607. save_ch_part1(prev, spu); /* Step 42. */
  1608. save_spu_mb(prev, spu); /* Step 43. */
  1609. save_mfc_cmd(prev, spu); /* Step 44. */
  1610. reset_ch(prev, spu); /* Step 45. */
  1611. }
  1612. static void save_lscsa(struct spu_state *prev, struct spu *spu)
  1613. {
  1614. /*
  1615. * Perform steps 46-57 of SPU context save sequence,
  1616. * which save regions of the local store and register
  1617. * file.
  1618. */
  1619. resume_mfc_queue(prev, spu); /* Step 46. */
  1620. setup_mfc_slbs(prev, spu); /* Step 47. */
  1621. set_switch_active(prev, spu); /* Step 48. */
  1622. enable_interrupts(prev, spu); /* Step 49. */
  1623. save_ls_16kb(prev, spu); /* Step 50. */
  1624. set_spu_npc(prev, spu); /* Step 51. */
  1625. set_signot1(prev, spu); /* Step 52. */
  1626. set_signot2(prev, spu); /* Step 53. */
  1627. send_save_code(prev, spu); /* Step 54. */
  1628. set_ppu_querymask(prev, spu); /* Step 55. */
  1629. wait_tag_complete(prev, spu); /* Step 56. */
  1630. wait_spu_stopped(prev, spu); /* Step 57. */
  1631. }
  1632. static void force_spu_isolate_exit(struct spu *spu)
  1633. {
  1634. struct spu_problem __iomem *prob = spu->problem;
  1635. struct spu_priv2 __iomem *priv2 = spu->priv2;
  1636. /* Stop SPE execution and wait for completion. */
  1637. out_be32(&prob->spu_runcntl_RW, SPU_RUNCNTL_STOP);
  1638. iobarrier_rw();
  1639. POLL_WHILE_TRUE(in_be32(&prob->spu_status_R) & SPU_STATUS_RUNNING);
  1640. /* Restart SPE master runcntl. */
  1641. spu_mfc_sr1_set(spu, MFC_STATE1_MASTER_RUN_CONTROL_MASK);
  1642. iobarrier_w();
  1643. /* Initiate isolate exit request and wait for completion. */
  1644. out_be64(&priv2->spu_privcntl_RW, 4LL);
  1645. iobarrier_w();
  1646. out_be32(&prob->spu_runcntl_RW, 2);
  1647. iobarrier_rw();
  1648. POLL_WHILE_FALSE((in_be32(&prob->spu_status_R)
  1649. & SPU_STATUS_STOPPED_BY_STOP));
  1650. /* Reset load request to normal. */
  1651. out_be64(&priv2->spu_privcntl_RW, SPU_PRIVCNT_LOAD_REQUEST_NORMAL);
  1652. iobarrier_w();
  1653. }
  1654. /**
  1655. * stop_spu_isolate
  1656. * Check SPU run-control state and force isolated
  1657. * exit function as necessary.
  1658. */
  1659. static void stop_spu_isolate(struct spu *spu)
  1660. {
  1661. struct spu_problem __iomem *prob = spu->problem;
  1662. if (in_be32(&prob->spu_status_R) & SPU_STATUS_ISOLATED_STATE) {
  1663. /* The SPU is in isolated state; the only way
  1664. * to get it out is to perform an isolated
  1665. * exit (clean) operation.
  1666. */
  1667. force_spu_isolate_exit(spu);
  1668. }
  1669. }
  1670. static void harvest(struct spu_state *prev, struct spu *spu)
  1671. {
  1672. /*
  1673. * Perform steps 2-25 of SPU context restore sequence,
  1674. * which resets an SPU either after a failed save, or
  1675. * when using SPU for first time.
  1676. */
  1677. disable_interrupts(prev, spu); /* Step 2. */
  1678. inhibit_user_access(prev, spu); /* Step 3. */
  1679. terminate_spu_app(prev, spu); /* Step 4. */
  1680. set_switch_pending(prev, spu); /* Step 5. */
  1681. stop_spu_isolate(spu); /* NEW. */
  1682. remove_other_spu_access(prev, spu); /* Step 6. */
  1683. suspend_mfc_and_halt_decr(prev, spu); /* Step 7. */
  1684. wait_suspend_mfc_complete(prev, spu); /* Step 8. */
  1685. if (!suspend_spe(prev, spu)) /* Step 9. */
  1686. clear_spu_status(prev, spu); /* Step 10. */
  1687. do_mfc_mssync(prev, spu); /* Step 11. */
  1688. issue_mfc_tlbie(prev, spu); /* Step 12. */
  1689. handle_pending_interrupts(prev, spu); /* Step 13. */
  1690. purge_mfc_queue(prev, spu); /* Step 14. */
  1691. wait_purge_complete(prev, spu); /* Step 15. */
  1692. reset_spu_privcntl(prev, spu); /* Step 16. */
  1693. reset_spu_lslr(prev, spu); /* Step 17. */
  1694. setup_mfc_sr1(prev, spu); /* Step 18. */
  1695. spu_invalidate_slbs(spu); /* Step 19. */
  1696. reset_ch_part1(prev, spu); /* Step 20. */
  1697. reset_ch_part2(prev, spu); /* Step 21. */
  1698. enable_interrupts(prev, spu); /* Step 22. */
  1699. set_switch_active(prev, spu); /* Step 23. */
  1700. set_mfc_tclass_id(prev, spu); /* Step 24. */
  1701. resume_mfc_queue(prev, spu); /* Step 25. */
  1702. }
  1703. static void restore_lscsa(struct spu_state *next, struct spu *spu)
  1704. {
  1705. /*
  1706. * Perform steps 26-40 of SPU context restore sequence,
  1707. * which restores regions of the local store and register
  1708. * file.
  1709. */
  1710. set_watchdog_timer(next, spu); /* Step 26. */
  1711. setup_spu_status_part1(next, spu); /* Step 27. */
  1712. setup_spu_status_part2(next, spu); /* Step 28. */
  1713. restore_mfc_rag(next, spu); /* Step 29. */
  1714. setup_mfc_slbs(next, spu); /* Step 30. */
  1715. set_spu_npc(next, spu); /* Step 31. */
  1716. set_signot1(next, spu); /* Step 32. */
  1717. set_signot2(next, spu); /* Step 33. */
  1718. setup_decr(next, spu); /* Step 34. */
  1719. setup_ppu_mb(next, spu); /* Step 35. */
  1720. setup_ppuint_mb(next, spu); /* Step 36. */
  1721. send_restore_code(next, spu); /* Step 37. */
  1722. set_ppu_querymask(next, spu); /* Step 38. */
  1723. wait_tag_complete(next, spu); /* Step 39. */
  1724. wait_spu_stopped(next, spu); /* Step 40. */
  1725. }
  1726. static void restore_csa(struct spu_state *next, struct spu *spu)
  1727. {
  1728. /*
  1729. * Combine steps 41-76 of SPU context restore sequence, which
  1730. * restore regions of the privileged & problem state areas.
  1731. */
  1732. restore_spu_privcntl(next, spu); /* Step 41. */
  1733. restore_status_part1(next, spu); /* Step 42. */
  1734. restore_status_part2(next, spu); /* Step 43. */
  1735. restore_ls_16kb(next, spu); /* Step 44. */
  1736. wait_tag_complete(next, spu); /* Step 45. */
  1737. suspend_mfc(next, spu); /* Step 46. */
  1738. wait_suspend_mfc_complete(next, spu); /* Step 47. */
  1739. issue_mfc_tlbie(next, spu); /* Step 48. */
  1740. clear_interrupts(next, spu); /* Step 49. */
  1741. restore_mfc_queues(next, spu); /* Step 50. */
  1742. restore_ppu_querymask(next, spu); /* Step 51. */
  1743. restore_ppu_querytype(next, spu); /* Step 52. */
  1744. restore_mfc_csr_tsq(next, spu); /* Step 53. */
  1745. restore_mfc_csr_cmd(next, spu); /* Step 54. */
  1746. restore_mfc_csr_ato(next, spu); /* Step 55. */
  1747. restore_mfc_tclass_id(next, spu); /* Step 56. */
  1748. set_llr_event(next, spu); /* Step 57. */
  1749. restore_decr_wrapped(next, spu); /* Step 58. */
  1750. restore_ch_part1(next, spu); /* Step 59. */
  1751. restore_ch_part2(next, spu); /* Step 60. */
  1752. restore_spu_lslr(next, spu); /* Step 61. */
  1753. restore_spu_cfg(next, spu); /* Step 62. */
  1754. restore_pm_trace(next, spu); /* Step 63. */
  1755. restore_spu_npc(next, spu); /* Step 64. */
  1756. restore_spu_mb(next, spu); /* Step 65. */
  1757. check_ppu_mb_stat(next, spu); /* Step 66. */
  1758. check_ppuint_mb_stat(next, spu); /* Step 67. */
  1759. spu_invalidate_slbs(spu); /* Modified Step 68. */
  1760. restore_mfc_sr1(next, spu); /* Step 69. */
  1761. restore_other_spu_access(next, spu); /* Step 70. */
  1762. restore_spu_runcntl(next, spu); /* Step 71. */
  1763. restore_mfc_cntl(next, spu); /* Step 72. */
  1764. enable_user_access(next, spu); /* Step 73. */
  1765. reset_switch_active(next, spu); /* Step 74. */
  1766. reenable_interrupts(next, spu); /* Step 75. */
  1767. }
  1768. static int __do_spu_save(struct spu_state *prev, struct spu *spu)
  1769. {
  1770. int rc;
  1771. /*
  1772. * SPU context save can be broken into three phases:
  1773. *
  1774. * (a) quiesce [steps 2-16].
  1775. * (b) save of CSA, performed by PPE [steps 17-42]
  1776. * (c) save of LSCSA, mostly performed by SPU [steps 43-52].
  1777. *
  1778. * Returns 0 on success.
  1779. * 2,6 if failed to quiece SPU
  1780. * 53 if SPU-side of save failed.
  1781. */
  1782. rc = quiece_spu(prev, spu); /* Steps 2-16. */
  1783. switch (rc) {
  1784. default:
  1785. case 2:
  1786. case 6:
  1787. harvest(prev, spu);
  1788. return rc;
  1789. break;
  1790. case 0:
  1791. break;
  1792. }
  1793. save_csa(prev, spu); /* Steps 17-43. */
  1794. save_lscsa(prev, spu); /* Steps 44-53. */
  1795. return check_save_status(prev, spu); /* Step 54. */
  1796. }
  1797. static int __do_spu_restore(struct spu_state *next, struct spu *spu)
  1798. {
  1799. int rc;
  1800. /*
  1801. * SPU context restore can be broken into three phases:
  1802. *
  1803. * (a) harvest (or reset) SPU [steps 2-24].
  1804. * (b) restore LSCSA [steps 25-40], mostly performed by SPU.
  1805. * (c) restore CSA [steps 41-76], performed by PPE.
  1806. *
  1807. * The 'harvest' step is not performed here, but rather
  1808. * as needed below.
  1809. */
  1810. restore_lscsa(next, spu); /* Steps 24-39. */
  1811. rc = check_restore_status(next, spu); /* Step 40. */
  1812. switch (rc) {
  1813. default:
  1814. /* Failed. Return now. */
  1815. return rc;
  1816. break;
  1817. case 0:
  1818. /* Fall through to next step. */
  1819. break;
  1820. }
  1821. restore_csa(next, spu);
  1822. return 0;
  1823. }
  1824. /**
  1825. * spu_save - SPU context save, with locking.
  1826. * @prev: pointer to SPU context save area, to be saved.
  1827. * @spu: pointer to SPU iomem structure.
  1828. *
  1829. * Acquire locks, perform the save operation then return.
  1830. */
  1831. int spu_save(struct spu_state *prev, struct spu *spu)
  1832. {
  1833. int rc;
  1834. acquire_spu_lock(spu); /* Step 1. */
  1835. prev->dar = spu->dar;
  1836. prev->dsisr = spu->dsisr;
  1837. spu->dar = 0;
  1838. spu->dsisr = 0;
  1839. rc = __do_spu_save(prev, spu); /* Steps 2-53. */
  1840. release_spu_lock(spu);
  1841. if (rc != 0 && rc != 2 && rc != 6) {
  1842. panic("%s failed on SPU[%d], rc=%d.\n",
  1843. __func__, spu->number, rc);
  1844. }
  1845. return 0;
  1846. }
  1847. EXPORT_SYMBOL_GPL(spu_save);
  1848. /**
  1849. * spu_restore - SPU context restore, with harvest and locking.
  1850. * @new: pointer to SPU context save area, to be restored.
  1851. * @spu: pointer to SPU iomem structure.
  1852. *
  1853. * Perform harvest + restore, as we may not be coming
  1854. * from a previous successful save operation, and the
  1855. * hardware state is unknown.
  1856. */
  1857. int spu_restore(struct spu_state *new, struct spu *spu)
  1858. {
  1859. int rc;
  1860. acquire_spu_lock(spu);
  1861. harvest(NULL, spu);
  1862. spu->slb_replace = 0;
  1863. new->dar = 0;
  1864. new->dsisr = 0;
  1865. spu->class_0_pending = 0;
  1866. rc = __do_spu_restore(new, spu);
  1867. release_spu_lock(spu);
  1868. if (rc) {
  1869. panic("%s failed on SPU[%d] rc=%d.\n",
  1870. __func__, spu->number, rc);
  1871. }
  1872. return rc;
  1873. }
  1874. EXPORT_SYMBOL_GPL(spu_restore);
  1875. static void init_prob(struct spu_state *csa)
  1876. {
  1877. csa->spu_chnlcnt_RW[9] = 1;
  1878. csa->spu_chnlcnt_RW[21] = 16;
  1879. csa->spu_chnlcnt_RW[23] = 1;
  1880. csa->spu_chnlcnt_RW[28] = 1;
  1881. csa->spu_chnlcnt_RW[30] = 1;
  1882. csa->prob.spu_runcntl_RW = SPU_RUNCNTL_STOP;
  1883. csa->prob.mb_stat_R = 0x000400;
  1884. }
  1885. static void init_priv1(struct spu_state *csa)
  1886. {
  1887. /* Enable decode, relocate, tlbie response, master runcntl. */
  1888. csa->priv1.mfc_sr1_RW = MFC_STATE1_LOCAL_STORAGE_DECODE_MASK |
  1889. MFC_STATE1_MASTER_RUN_CONTROL_MASK |
  1890. MFC_STATE1_PROBLEM_STATE_MASK |
  1891. MFC_STATE1_RELOCATE_MASK | MFC_STATE1_BUS_TLBIE_MASK;
  1892. /* Enable OS-specific set of interrupts. */
  1893. csa->priv1.int_mask_class0_RW = CLASS0_ENABLE_DMA_ALIGNMENT_INTR |
  1894. CLASS0_ENABLE_INVALID_DMA_COMMAND_INTR |
  1895. CLASS0_ENABLE_SPU_ERROR_INTR;
  1896. csa->priv1.int_mask_class1_RW = CLASS1_ENABLE_SEGMENT_FAULT_INTR |
  1897. CLASS1_ENABLE_STORAGE_FAULT_INTR;
  1898. csa->priv1.int_mask_class2_RW = CLASS2_ENABLE_SPU_STOP_INTR |
  1899. CLASS2_ENABLE_SPU_HALT_INTR |
  1900. CLASS2_ENABLE_SPU_DMA_TAG_GROUP_COMPLETE_INTR;
  1901. }
  1902. static void init_priv2(struct spu_state *csa)
  1903. {
  1904. csa->priv2.spu_lslr_RW = LS_ADDR_MASK;
  1905. csa->priv2.mfc_control_RW = MFC_CNTL_RESUME_DMA_QUEUE |
  1906. MFC_CNTL_NORMAL_DMA_QUEUE_OPERATION |
  1907. MFC_CNTL_DMA_QUEUES_EMPTY_MASK;
  1908. }
  1909. /**
  1910. * spu_alloc_csa - allocate and initialize an SPU context save area.
  1911. *
  1912. * Allocate and initialize the contents of an SPU context save area.
  1913. * This includes enabling address translation, interrupt masks, etc.,
  1914. * as appropriate for the given OS environment.
  1915. *
  1916. * Note that storage for the 'lscsa' is allocated separately,
  1917. * as it is by far the largest of the context save regions,
  1918. * and may need to be pinned or otherwise specially aligned.
  1919. */
  1920. int spu_init_csa(struct spu_state *csa)
  1921. {
  1922. int rc;
  1923. if (!csa)
  1924. return -EINVAL;
  1925. memset(csa, 0, sizeof(struct spu_state));
  1926. rc = spu_alloc_lscsa(csa);
  1927. if (rc)
  1928. return rc;
  1929. spin_lock_init(&csa->register_lock);
  1930. init_prob(csa);
  1931. init_priv1(csa);
  1932. init_priv2(csa);
  1933. return 0;
  1934. }
  1935. EXPORT_SYMBOL_GPL(spu_init_csa);
  1936. void spu_fini_csa(struct spu_state *csa)
  1937. {
  1938. spu_free_lscsa(csa);
  1939. }
  1940. EXPORT_SYMBOL_GPL(spu_fini_csa);