switch.c 62 KB

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