switch.c 62 KB

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