4 * (C) Copyright IBM Corp. 2005
6 * Author: Mark Nutter <mnutter@us.ibm.com>
8 * Host-side part of SPU context switch sequence outlined in
9 * Synergistic Processor Element, Book IV.
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.
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)
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.
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.
35 #include <linux/module.h>
36 #include <linux/errno.h>
37 #include <linux/sched.h>
38 #include <linux/kernel.h>
40 #include <linux/vmalloc.h>
41 #include <linux/smp.h>
42 #include <linux/stddef.h>
43 #include <linux/unistd.h>
47 #include <asm/spu_priv1.h>
48 #include <asm/spu_csa.h>
49 #include <asm/mmu_context.h>
51 #include "spu_save_dump.h"
52 #include "spu_restore_dump.h"
55 #define POLL_WHILE_TRUE(_c) { \
60 #define RELAX_SPIN_COUNT 1000
61 #define POLL_WHILE_TRUE(_c) { \
64 for (_i=0; _i<RELAX_SPIN_COUNT && (_c); _i++) { \
67 if (unlikely(_c)) yield(); \
73 #define POLL_WHILE_FALSE(_c) POLL_WHILE_TRUE(!(_c))
75 static inline void acquire_spu_lock(struct spu *spu)
79 * Acquire SPU-specific mutual exclusion lock.
84 static inline void release_spu_lock(struct spu *spu)
87 * Release SPU-specific mutual exclusion lock.
92 static inline int check_spu_isolate(struct spu_state *csa, struct spu *spu)
94 struct spu_problem __iomem *prob = spu->problem;
99 * If SPU_Status[E,L,IS] any field is '1', this
100 * SPU is in isolate state and cannot be context
101 * saved at this time.
103 isolate_state = SPU_STATUS_ISOLATED_STATE |
104 SPU_STATUS_ISOLATED_LOAD_STATUS | SPU_STATUS_ISOLATED_EXIT_STATUS;
105 return (in_be32(&prob->spu_status_R) & isolate_state) ? 1 : 0;
108 static inline void disable_interrupts(struct spu_state *csa, struct spu *spu)
112 * Save INT_Mask_class0 in CSA.
113 * Write INT_MASK_class0 with value of 0.
114 * Save INT_Mask_class1 in CSA.
115 * Write INT_MASK_class1 with value of 0.
116 * Save INT_Mask_class2 in CSA.
117 * Write INT_MASK_class2 with value of 0.
119 spin_lock_irq(&spu->register_lock);
121 csa->priv1.int_mask_class0_RW = spu_int_mask_get(spu, 0);
122 csa->priv1.int_mask_class1_RW = spu_int_mask_get(spu, 1);
123 csa->priv1.int_mask_class2_RW = spu_int_mask_get(spu, 2);
125 spu_int_mask_set(spu, 0, 0ul);
126 spu_int_mask_set(spu, 1, 0ul);
127 spu_int_mask_set(spu, 2, 0ul);
129 spin_unlock_irq(&spu->register_lock);
132 static inline void set_watchdog_timer(struct spu_state *csa, struct spu *spu)
136 * Set a software watchdog timer, which specifies the
137 * maximum allowable time for a context save sequence.
139 * For present, this implementation will not set a global
140 * watchdog timer, as virtualization & variable system load
141 * may cause unpredictable execution times.
145 static inline void inhibit_user_access(struct spu_state *csa, struct spu *spu)
149 * Inhibit user-space access (if provided) to this
150 * SPU by unmapping the virtual pages assigned to
151 * the SPU memory-mapped I/O (MMIO) for problem
156 static inline void set_switch_pending(struct spu_state *csa, struct spu *spu)
160 * Set a software context switch pending flag.
162 set_bit(SPU_CONTEXT_SWITCH_PENDING, &spu->flags);
166 static inline void save_mfc_cntl(struct spu_state *csa, struct spu *spu)
168 struct spu_priv2 __iomem *priv2 = spu->priv2;
171 * Suspend DMA and save MFC_CNTL.
173 switch (in_be64(&priv2->mfc_control_RW) &
174 MFC_CNTL_SUSPEND_DMA_STATUS_MASK) {
175 case MFC_CNTL_SUSPEND_IN_PROGRESS:
176 POLL_WHILE_FALSE((in_be64(&priv2->mfc_control_RW) &
177 MFC_CNTL_SUSPEND_DMA_STATUS_MASK) ==
178 MFC_CNTL_SUSPEND_COMPLETE);
180 case MFC_CNTL_SUSPEND_COMPLETE:
182 csa->priv2.mfc_control_RW =
183 MFC_CNTL_SUSPEND_MASK |
184 MFC_CNTL_SUSPEND_DMA_QUEUE;
187 case MFC_CNTL_NORMAL_DMA_QUEUE_OPERATION:
188 out_be64(&priv2->mfc_control_RW, MFC_CNTL_SUSPEND_DMA_QUEUE);
189 POLL_WHILE_FALSE((in_be64(&priv2->mfc_control_RW) &
190 MFC_CNTL_SUSPEND_DMA_STATUS_MASK) ==
191 MFC_CNTL_SUSPEND_COMPLETE);
193 csa->priv2.mfc_control_RW = 0;
199 static inline void save_spu_runcntl(struct spu_state *csa, struct spu *spu)
201 struct spu_problem __iomem *prob = spu->problem;
204 * Save SPU_Runcntl in the CSA. This value contains
205 * the "Application Desired State".
207 csa->prob.spu_runcntl_RW = in_be32(&prob->spu_runcntl_RW);
210 static inline void save_mfc_sr1(struct spu_state *csa, struct spu *spu)
213 * Save MFC_SR1 in the CSA.
215 csa->priv1.mfc_sr1_RW = spu_mfc_sr1_get(spu);
218 static inline void save_spu_status(struct spu_state *csa, struct spu *spu)
220 struct spu_problem __iomem *prob = spu->problem;
223 * Read SPU_Status[R], and save to CSA.
225 if ((in_be32(&prob->spu_status_R) & SPU_STATUS_RUNNING) == 0) {
226 csa->prob.spu_status_R = in_be32(&prob->spu_status_R);
230 out_be32(&prob->spu_runcntl_RW, SPU_RUNCNTL_STOP);
232 POLL_WHILE_TRUE(in_be32(&prob->spu_status_R) &
235 SPU_STATUS_INVALID_INSTR | SPU_STATUS_SINGLE_STEP |
236 SPU_STATUS_STOPPED_BY_HALT | SPU_STATUS_STOPPED_BY_STOP;
237 if ((in_be32(&prob->spu_status_R) & stopped) == 0)
238 csa->prob.spu_status_R = SPU_STATUS_RUNNING;
240 csa->prob.spu_status_R = in_be32(&prob->spu_status_R);
244 static inline void save_mfc_decr(struct spu_state *csa, struct spu *spu)
246 struct spu_priv2 __iomem *priv2 = spu->priv2;
249 * Read MFC_CNTL[Ds]. Update saved copy of
252 csa->priv2.mfc_control_RW |=
253 in_be64(&priv2->mfc_control_RW) & MFC_CNTL_DECREMENTER_RUNNING;
256 static inline void halt_mfc_decr(struct spu_state *csa, struct spu *spu)
258 struct spu_priv2 __iomem *priv2 = spu->priv2;
261 * Write MFC_CNTL[Dh] set to a '1' to halt
264 out_be64(&priv2->mfc_control_RW,
265 MFC_CNTL_DECREMENTER_HALTED | MFC_CNTL_SUSPEND_MASK);
269 static inline void save_timebase(struct spu_state *csa, struct spu *spu)
272 * Read PPE Timebase High and Timebase low registers
273 * and save in CSA. TBD.
275 csa->suspend_time = get_cycles();
278 static inline void remove_other_spu_access(struct spu_state *csa,
282 * Remove other SPU access to this SPU by unmapping
283 * this SPU's pages from their address space. TBD.
287 static inline void do_mfc_mssync(struct spu_state *csa, struct spu *spu)
289 struct spu_problem __iomem *prob = spu->problem;
293 * Write SPU_MSSync register. Poll SPU_MSSync[P]
296 out_be64(&prob->spc_mssync_RW, 1UL);
297 POLL_WHILE_TRUE(in_be64(&prob->spc_mssync_RW) & MS_SYNC_PENDING);
300 static inline void issue_mfc_tlbie(struct spu_state *csa, struct spu *spu)
305 * Write TLB_Invalidate_Entry[IS,VPN,L,Lp]=0 register.
306 * Then issue a PPE sync instruction.
308 spu_tlb_invalidate(spu);
312 static inline void handle_pending_interrupts(struct spu_state *csa,
316 * Handle any pending interrupts from this SPU
317 * here. This is OS or hypervisor specific. One
318 * option is to re-enable interrupts to handle any
319 * pending interrupts, with the interrupt handlers
320 * recognizing the software Context Switch Pending
321 * flag, to ensure the SPU execution or MFC command
322 * queue is not restarted. TBD.
326 static inline void save_mfc_queues(struct spu_state *csa, struct spu *spu)
328 struct spu_priv2 __iomem *priv2 = spu->priv2;
332 * If MFC_Cntl[Se]=0 then save
333 * MFC command queues.
335 if ((in_be64(&priv2->mfc_control_RW) & MFC_CNTL_DMA_QUEUES_EMPTY) == 0) {
336 for (i = 0; i < 8; i++) {
337 csa->priv2.puq[i].mfc_cq_data0_RW =
338 in_be64(&priv2->puq[i].mfc_cq_data0_RW);
339 csa->priv2.puq[i].mfc_cq_data1_RW =
340 in_be64(&priv2->puq[i].mfc_cq_data1_RW);
341 csa->priv2.puq[i].mfc_cq_data2_RW =
342 in_be64(&priv2->puq[i].mfc_cq_data2_RW);
343 csa->priv2.puq[i].mfc_cq_data3_RW =
344 in_be64(&priv2->puq[i].mfc_cq_data3_RW);
346 for (i = 0; i < 16; i++) {
347 csa->priv2.spuq[i].mfc_cq_data0_RW =
348 in_be64(&priv2->spuq[i].mfc_cq_data0_RW);
349 csa->priv2.spuq[i].mfc_cq_data1_RW =
350 in_be64(&priv2->spuq[i].mfc_cq_data1_RW);
351 csa->priv2.spuq[i].mfc_cq_data2_RW =
352 in_be64(&priv2->spuq[i].mfc_cq_data2_RW);
353 csa->priv2.spuq[i].mfc_cq_data3_RW =
354 in_be64(&priv2->spuq[i].mfc_cq_data3_RW);
359 static inline void save_ppu_querymask(struct spu_state *csa, struct spu *spu)
361 struct spu_problem __iomem *prob = spu->problem;
364 * Save the PPU_QueryMask register
367 csa->prob.dma_querymask_RW = in_be32(&prob->dma_querymask_RW);
370 static inline void save_ppu_querytype(struct spu_state *csa, struct spu *spu)
372 struct spu_problem __iomem *prob = spu->problem;
375 * Save the PPU_QueryType register
378 csa->prob.dma_querytype_RW = in_be32(&prob->dma_querytype_RW);
381 static inline void save_ppu_tagstatus(struct spu_state *csa, struct spu *spu)
383 struct spu_problem __iomem *prob = spu->problem;
385 /* Save the Prxy_TagStatus register in the CSA.
387 * It is unnecessary to restore dma_tagstatus_R, however,
388 * dma_tagstatus_R in the CSA is accessed via backing_ops, so
391 csa->prob.dma_tagstatus_R = in_be32(&prob->dma_tagstatus_R);
394 static inline void save_mfc_csr_tsq(struct spu_state *csa, struct spu *spu)
396 struct spu_priv2 __iomem *priv2 = spu->priv2;
399 * Save the MFC_CSR_TSQ register
402 csa->priv2.spu_tag_status_query_RW =
403 in_be64(&priv2->spu_tag_status_query_RW);
406 static inline void save_mfc_csr_cmd(struct spu_state *csa, struct spu *spu)
408 struct spu_priv2 __iomem *priv2 = spu->priv2;
411 * Save the MFC_CSR_CMD1 and MFC_CSR_CMD2
412 * registers in the CSA.
414 csa->priv2.spu_cmd_buf1_RW = in_be64(&priv2->spu_cmd_buf1_RW);
415 csa->priv2.spu_cmd_buf2_RW = in_be64(&priv2->spu_cmd_buf2_RW);
418 static inline void save_mfc_csr_ato(struct spu_state *csa, struct spu *spu)
420 struct spu_priv2 __iomem *priv2 = spu->priv2;
423 * Save the MFC_CSR_ATO register in
426 csa->priv2.spu_atomic_status_RW = in_be64(&priv2->spu_atomic_status_RW);
429 static inline void save_mfc_tclass_id(struct spu_state *csa, struct spu *spu)
432 * Save the MFC_TCLASS_ID register in
435 csa->priv1.mfc_tclass_id_RW = spu_mfc_tclass_id_get(spu);
438 static inline void set_mfc_tclass_id(struct spu_state *csa, struct spu *spu)
442 * Write the MFC_TCLASS_ID register with
443 * the value 0x10000000.
445 spu_mfc_tclass_id_set(spu, 0x10000000);
449 static inline void purge_mfc_queue(struct spu_state *csa, struct spu *spu)
451 struct spu_priv2 __iomem *priv2 = spu->priv2;
455 * Write MFC_CNTL[Pc]=1 (purge queue).
457 out_be64(&priv2->mfc_control_RW, MFC_CNTL_PURGE_DMA_REQUEST);
461 static inline void wait_purge_complete(struct spu_state *csa, struct spu *spu)
463 struct spu_priv2 __iomem *priv2 = spu->priv2;
466 * Poll MFC_CNTL[Ps] until value '11' is read
469 POLL_WHILE_FALSE((in_be64(&priv2->mfc_control_RW) &
470 MFC_CNTL_PURGE_DMA_STATUS_MASK) ==
471 MFC_CNTL_PURGE_DMA_COMPLETE);
474 static inline void setup_mfc_sr1(struct spu_state *csa, struct spu *spu)
478 * Write MFC_SR1 with MFC_SR1[D=0,S=1] and
479 * MFC_SR1[TL,R,Pr,T] set correctly for the
480 * OS specific environment.
482 * Implementation note: The SPU-side code
483 * for save/restore is privileged, so the
484 * MFC_SR1[Pr] bit is not set.
487 spu_mfc_sr1_set(spu, (MFC_STATE1_MASTER_RUN_CONTROL_MASK |
488 MFC_STATE1_RELOCATE_MASK |
489 MFC_STATE1_BUS_TLBIE_MASK));
492 static inline void save_spu_npc(struct spu_state *csa, struct spu *spu)
494 struct spu_problem __iomem *prob = spu->problem;
497 * Save SPU_NPC in the CSA.
499 csa->prob.spu_npc_RW = in_be32(&prob->spu_npc_RW);
502 static inline void save_spu_privcntl(struct spu_state *csa, struct spu *spu)
504 struct spu_priv2 __iomem *priv2 = spu->priv2;
507 * Save SPU_PrivCntl in the CSA.
509 csa->priv2.spu_privcntl_RW = in_be64(&priv2->spu_privcntl_RW);
512 static inline void reset_spu_privcntl(struct spu_state *csa, struct spu *spu)
514 struct spu_priv2 __iomem *priv2 = spu->priv2;
518 * Write SPU_PrivCntl[S,Le,A] fields reset to 0.
520 out_be64(&priv2->spu_privcntl_RW, 0UL);
524 static inline void save_spu_lslr(struct spu_state *csa, struct spu *spu)
526 struct spu_priv2 __iomem *priv2 = spu->priv2;
529 * Save SPU_LSLR in the CSA.
531 csa->priv2.spu_lslr_RW = in_be64(&priv2->spu_lslr_RW);
534 static inline void reset_spu_lslr(struct spu_state *csa, struct spu *spu)
536 struct spu_priv2 __iomem *priv2 = spu->priv2;
542 out_be64(&priv2->spu_lslr_RW, LS_ADDR_MASK);
546 static inline void save_spu_cfg(struct spu_state *csa, struct spu *spu)
548 struct spu_priv2 __iomem *priv2 = spu->priv2;
551 * Save SPU_Cfg in the CSA.
553 csa->priv2.spu_cfg_RW = in_be64(&priv2->spu_cfg_RW);
556 static inline void save_pm_trace(struct spu_state *csa, struct spu *spu)
559 * Save PM_Trace_Tag_Wait_Mask in the CSA.
560 * Not performed by this implementation.
564 static inline void save_mfc_rag(struct spu_state *csa, struct spu *spu)
567 * Save RA_GROUP_ID register and the
568 * RA_ENABLE reigster in the CSA.
570 csa->priv1.resource_allocation_groupID_RW =
571 spu_resource_allocation_groupID_get(spu);
572 csa->priv1.resource_allocation_enable_RW =
573 spu_resource_allocation_enable_get(spu);
576 static inline void save_ppu_mb_stat(struct spu_state *csa, struct spu *spu)
578 struct spu_problem __iomem *prob = spu->problem;
581 * Save MB_Stat register in the CSA.
583 csa->prob.mb_stat_R = in_be32(&prob->mb_stat_R);
586 static inline void save_ppu_mb(struct spu_state *csa, struct spu *spu)
588 struct spu_problem __iomem *prob = spu->problem;
591 * Save the PPU_MB register in the CSA.
593 csa->prob.pu_mb_R = in_be32(&prob->pu_mb_R);
596 static inline void save_ppuint_mb(struct spu_state *csa, struct spu *spu)
598 struct spu_priv2 __iomem *priv2 = spu->priv2;
601 * Save the PPUINT_MB register in the CSA.
603 csa->priv2.puint_mb_R = in_be64(&priv2->puint_mb_R);
606 static inline void save_ch_part1(struct spu_state *csa, struct spu *spu)
608 struct spu_priv2 __iomem *priv2 = spu->priv2;
609 u64 idx, ch_indices[] = { 0UL, 3UL, 4UL, 24UL, 25UL, 27UL };
615 /* Save CH 1, without channel count */
616 out_be64(&priv2->spu_chnlcntptr_RW, 1);
617 csa->spu_chnldata_RW[1] = in_be64(&priv2->spu_chnldata_RW);
619 /* Save the following CH: [0,3,4,24,25,27] */
620 for (i = 0; i < ARRAY_SIZE(ch_indices); i++) {
622 out_be64(&priv2->spu_chnlcntptr_RW, idx);
624 csa->spu_chnldata_RW[idx] = in_be64(&priv2->spu_chnldata_RW);
625 csa->spu_chnlcnt_RW[idx] = in_be64(&priv2->spu_chnlcnt_RW);
626 out_be64(&priv2->spu_chnldata_RW, 0UL);
627 out_be64(&priv2->spu_chnlcnt_RW, 0UL);
632 static inline void save_spu_mb(struct spu_state *csa, struct spu *spu)
634 struct spu_priv2 __iomem *priv2 = spu->priv2;
638 * Save SPU Read Mailbox Channel.
640 out_be64(&priv2->spu_chnlcntptr_RW, 29UL);
642 csa->spu_chnlcnt_RW[29] = in_be64(&priv2->spu_chnlcnt_RW);
643 for (i = 0; i < 4; i++) {
644 csa->spu_mailbox_data[i] = in_be64(&priv2->spu_chnldata_RW);
646 out_be64(&priv2->spu_chnlcnt_RW, 0UL);
650 static inline void save_mfc_cmd(struct spu_state *csa, struct spu *spu)
652 struct spu_priv2 __iomem *priv2 = spu->priv2;
655 * Save MFC_CMD Channel.
657 out_be64(&priv2->spu_chnlcntptr_RW, 21UL);
659 csa->spu_chnlcnt_RW[21] = in_be64(&priv2->spu_chnlcnt_RW);
663 static inline void reset_ch(struct spu_state *csa, struct spu *spu)
665 struct spu_priv2 __iomem *priv2 = spu->priv2;
666 u64 ch_indices[4] = { 21UL, 23UL, 28UL, 30UL };
667 u64 ch_counts[4] = { 16UL, 1UL, 1UL, 1UL };
672 * Reset the following CH: [21, 23, 28, 30]
674 for (i = 0; i < 4; i++) {
676 out_be64(&priv2->spu_chnlcntptr_RW, idx);
678 out_be64(&priv2->spu_chnlcnt_RW, ch_counts[i]);
683 static inline void resume_mfc_queue(struct spu_state *csa, struct spu *spu)
685 struct spu_priv2 __iomem *priv2 = spu->priv2;
689 * Write MFC_CNTL[Sc]=0 (resume queue processing).
691 out_be64(&priv2->mfc_control_RW, MFC_CNTL_RESUME_DMA_QUEUE);
694 static inline void setup_mfc_slbs(struct spu_state *csa, struct spu *spu)
698 * If MFC_SR1[R]=1, write 0 to SLB_Invalidate_All
699 * register, then initialize SLB_VSID and SLB_ESID
700 * to provide access to SPU context save code and
703 * This implementation places both the context
704 * switch code and LSCSA in kernel address space.
706 * Further this implementation assumes that the
707 * MFC_SR1[R]=1 (in other words, assume that
708 * translation is desired by OS environment).
710 spu_invalidate_slbs(spu);
711 spu_setup_kernel_slbs(spu, csa->lscsa, &spu_save_code);
714 static inline void set_switch_active(struct spu_state *csa, struct spu *spu)
718 * Change the software context switch pending flag
719 * to context switch active.
721 set_bit(SPU_CONTEXT_SWITCH_ACTIVE, &spu->flags);
722 clear_bit(SPU_CONTEXT_SWITCH_PENDING, &spu->flags);
726 static inline void enable_interrupts(struct spu_state *csa, struct spu *spu)
728 unsigned long class1_mask = CLASS1_ENABLE_SEGMENT_FAULT_INTR |
729 CLASS1_ENABLE_STORAGE_FAULT_INTR;
733 * Reset and then enable interrupts, as
736 * This implementation enables only class1
737 * (translation) interrupts.
739 spin_lock_irq(&spu->register_lock);
740 spu_int_stat_clear(spu, 0, ~0ul);
741 spu_int_stat_clear(spu, 1, ~0ul);
742 spu_int_stat_clear(spu, 2, ~0ul);
743 spu_int_mask_set(spu, 0, 0ul);
744 spu_int_mask_set(spu, 1, class1_mask);
745 spu_int_mask_set(spu, 2, 0ul);
746 spin_unlock_irq(&spu->register_lock);
749 static inline int send_mfc_dma(struct spu *spu, unsigned long ea,
750 unsigned int ls_offset, unsigned int size,
751 unsigned int tag, unsigned int rclass,
754 struct spu_problem __iomem *prob = spu->problem;
755 union mfc_tag_size_class_cmd command;
756 unsigned int transfer_size;
757 volatile unsigned int status = 0x0;
761 (size > MFC_MAX_DMA_SIZE) ? MFC_MAX_DMA_SIZE : size;
762 command.u.mfc_size = transfer_size;
763 command.u.mfc_tag = tag;
764 command.u.mfc_rclassid = rclass;
765 command.u.mfc_cmd = cmd;
767 out_be32(&prob->mfc_lsa_W, ls_offset);
768 out_be64(&prob->mfc_ea_W, ea);
769 out_be64(&prob->mfc_union_W.all64, command.all64);
771 in_be32(&prob->mfc_union_W.by32.mfc_class_cmd32);
772 if (unlikely(status & 0x2)) {
775 } while (status & 0x3);
776 size -= transfer_size;
778 ls_offset += transfer_size;
783 static inline void save_ls_16kb(struct spu_state *csa, struct spu *spu)
785 unsigned long addr = (unsigned long)&csa->lscsa->ls[0];
786 unsigned int ls_offset = 0x0;
787 unsigned int size = 16384;
788 unsigned int tag = 0;
789 unsigned int rclass = 0;
790 unsigned int cmd = MFC_PUT_CMD;
793 * Issue a DMA command to copy the first 16K bytes
794 * of local storage to the CSA.
796 send_mfc_dma(spu, addr, ls_offset, size, tag, rclass, cmd);
799 static inline void set_spu_npc(struct spu_state *csa, struct spu *spu)
801 struct spu_problem __iomem *prob = spu->problem;
805 * Write SPU_NPC[IE]=0 and SPU_NPC[LSA] to entry
806 * point address of context save code in local
809 * This implementation uses SPU-side save/restore
810 * programs with entry points at LSA of 0.
812 out_be32(&prob->spu_npc_RW, 0);
816 static inline void set_signot1(struct spu_state *csa, struct spu *spu)
818 struct spu_problem __iomem *prob = spu->problem;
826 * Write SPU_Sig_Notify_1 register with upper 32-bits
827 * of the CSA.LSCSA effective address.
829 addr64.ull = (u64) csa->lscsa;
830 out_be32(&prob->signal_notify1, addr64.ui[0]);
834 static inline void set_signot2(struct spu_state *csa, struct spu *spu)
836 struct spu_problem __iomem *prob = spu->problem;
844 * Write SPU_Sig_Notify_2 register with lower 32-bits
845 * of the CSA.LSCSA effective address.
847 addr64.ull = (u64) csa->lscsa;
848 out_be32(&prob->signal_notify2, addr64.ui[1]);
852 static inline void send_save_code(struct spu_state *csa, struct spu *spu)
854 unsigned long addr = (unsigned long)&spu_save_code[0];
855 unsigned int ls_offset = 0x0;
856 unsigned int size = sizeof(spu_save_code);
857 unsigned int tag = 0;
858 unsigned int rclass = 0;
859 unsigned int cmd = MFC_GETFS_CMD;
862 * Issue a DMA command to copy context save code
863 * to local storage and start SPU.
865 send_mfc_dma(spu, addr, ls_offset, size, tag, rclass, cmd);
868 static inline void set_ppu_querymask(struct spu_state *csa, struct spu *spu)
870 struct spu_problem __iomem *prob = spu->problem;
874 * Write PPU_QueryMask=1 (enable Tag Group 0)
875 * and issue eieio instruction.
877 out_be32(&prob->dma_querymask_RW, MFC_TAGID_TO_TAGMASK(0));
881 static inline void wait_tag_complete(struct spu_state *csa, struct spu *spu)
883 struct spu_problem __iomem *prob = spu->problem;
884 u32 mask = MFC_TAGID_TO_TAGMASK(0);
891 * Poll PPU_TagStatus[gn] until 01 (Tag group 0 complete)
892 * or write PPU_QueryType[TS]=01 and wait for Tag Group
893 * Complete Interrupt. Write INT_Stat_Class0 or
894 * INT_Stat_Class2 with value of 'handled'.
896 POLL_WHILE_FALSE(in_be32(&prob->dma_tagstatus_R) & mask);
898 local_irq_save(flags);
899 spu_int_stat_clear(spu, 0, ~(0ul));
900 spu_int_stat_clear(spu, 2, ~(0ul));
901 local_irq_restore(flags);
904 static inline void wait_spu_stopped(struct spu_state *csa, struct spu *spu)
906 struct spu_problem __iomem *prob = spu->problem;
911 * Poll until SPU_Status[R]=0 or wait for SPU Class 0
912 * or SPU Class 2 interrupt. Write INT_Stat_class0
913 * or INT_Stat_class2 with value of handled.
915 POLL_WHILE_TRUE(in_be32(&prob->spu_status_R) & SPU_STATUS_RUNNING);
917 local_irq_save(flags);
918 spu_int_stat_clear(spu, 0, ~(0ul));
919 spu_int_stat_clear(spu, 2, ~(0ul));
920 local_irq_restore(flags);
923 static inline int check_save_status(struct spu_state *csa, struct spu *spu)
925 struct spu_problem __iomem *prob = spu->problem;
929 * If SPU_Status[P]=1 and SPU_Status[SC] = "success",
930 * context save succeeded, otherwise context save
933 complete = ((SPU_SAVE_COMPLETE << SPU_STOP_STATUS_SHIFT) |
934 SPU_STATUS_STOPPED_BY_STOP);
935 return (in_be32(&prob->spu_status_R) != complete) ? 1 : 0;
938 static inline void terminate_spu_app(struct spu_state *csa, struct spu *spu)
941 * If required, notify the "using application" that
942 * the SPU task has been terminated. TBD.
946 static inline void suspend_mfc_and_halt_decr(struct spu_state *csa,
949 struct spu_priv2 __iomem *priv2 = spu->priv2;
952 * Write MFC_Cntl[Dh,Sc,Sm]='1','1','0' to suspend
953 * the queue and halt the decrementer.
955 out_be64(&priv2->mfc_control_RW, MFC_CNTL_SUSPEND_DMA_QUEUE |
956 MFC_CNTL_DECREMENTER_HALTED);
960 static inline void wait_suspend_mfc_complete(struct spu_state *csa,
963 struct spu_priv2 __iomem *priv2 = spu->priv2;
967 * Poll MFC_CNTL[Ss] until 11 is returned.
969 POLL_WHILE_FALSE((in_be64(&priv2->mfc_control_RW) &
970 MFC_CNTL_SUSPEND_DMA_STATUS_MASK) ==
971 MFC_CNTL_SUSPEND_COMPLETE);
974 static inline int suspend_spe(struct spu_state *csa, struct spu *spu)
976 struct spu_problem __iomem *prob = spu->problem;
979 * If SPU_Status[R]=1, stop SPU execution
980 * and wait for stop to complete.
982 * Returns 1 if SPU_Status[R]=1 on entry.
985 if (in_be32(&prob->spu_status_R) & SPU_STATUS_RUNNING) {
986 if (in_be32(&prob->spu_status_R) &
987 SPU_STATUS_ISOLATED_EXIT_STATUS) {
988 POLL_WHILE_TRUE(in_be32(&prob->spu_status_R) &
991 if ((in_be32(&prob->spu_status_R) &
992 SPU_STATUS_ISOLATED_LOAD_STATUS)
993 || (in_be32(&prob->spu_status_R) &
994 SPU_STATUS_ISOLATED_STATE)) {
995 out_be32(&prob->spu_runcntl_RW, SPU_RUNCNTL_STOP);
997 POLL_WHILE_TRUE(in_be32(&prob->spu_status_R) &
999 out_be32(&prob->spu_runcntl_RW, 0x2);
1001 POLL_WHILE_TRUE(in_be32(&prob->spu_status_R) &
1002 SPU_STATUS_RUNNING);
1004 if (in_be32(&prob->spu_status_R) &
1005 SPU_STATUS_WAITING_FOR_CHANNEL) {
1006 out_be32(&prob->spu_runcntl_RW, SPU_RUNCNTL_STOP);
1008 POLL_WHILE_TRUE(in_be32(&prob->spu_status_R) &
1009 SPU_STATUS_RUNNING);
1016 static inline void clear_spu_status(struct spu_state *csa, struct spu *spu)
1018 struct spu_problem __iomem *prob = spu->problem;
1020 /* Restore, Step 10:
1021 * If SPU_Status[R]=0 and SPU_Status[E,L,IS]=1,
1022 * release SPU from isolate state.
1024 if (!(in_be32(&prob->spu_status_R) & SPU_STATUS_RUNNING)) {
1025 if (in_be32(&prob->spu_status_R) &
1026 SPU_STATUS_ISOLATED_EXIT_STATUS) {
1027 spu_mfc_sr1_set(spu,
1028 MFC_STATE1_MASTER_RUN_CONTROL_MASK);
1030 out_be32(&prob->spu_runcntl_RW, SPU_RUNCNTL_RUNNABLE);
1032 POLL_WHILE_TRUE(in_be32(&prob->spu_status_R) &
1033 SPU_STATUS_RUNNING);
1035 if ((in_be32(&prob->spu_status_R) &
1036 SPU_STATUS_ISOLATED_LOAD_STATUS)
1037 || (in_be32(&prob->spu_status_R) &
1038 SPU_STATUS_ISOLATED_STATE)) {
1039 spu_mfc_sr1_set(spu,
1040 MFC_STATE1_MASTER_RUN_CONTROL_MASK);
1042 out_be32(&prob->spu_runcntl_RW, 0x2);
1044 POLL_WHILE_TRUE(in_be32(&prob->spu_status_R) &
1045 SPU_STATUS_RUNNING);
1050 static inline void reset_ch_part1(struct spu_state *csa, struct spu *spu)
1052 struct spu_priv2 __iomem *priv2 = spu->priv2;
1053 u64 ch_indices[] = { 0UL, 3UL, 4UL, 24UL, 25UL, 27UL };
1057 /* Restore, Step 20:
1061 out_be64(&priv2->spu_chnlcntptr_RW, 1);
1062 out_be64(&priv2->spu_chnldata_RW, 0UL);
1064 /* Reset the following CH: [0,3,4,24,25,27] */
1065 for (i = 0; i < ARRAY_SIZE(ch_indices); i++) {
1066 idx = ch_indices[i];
1067 out_be64(&priv2->spu_chnlcntptr_RW, idx);
1069 out_be64(&priv2->spu_chnldata_RW, 0UL);
1070 out_be64(&priv2->spu_chnlcnt_RW, 0UL);
1075 static inline void reset_ch_part2(struct spu_state *csa, struct spu *spu)
1077 struct spu_priv2 __iomem *priv2 = spu->priv2;
1078 u64 ch_indices[5] = { 21UL, 23UL, 28UL, 29UL, 30UL };
1079 u64 ch_counts[5] = { 16UL, 1UL, 1UL, 0UL, 1UL };
1083 /* Restore, Step 21:
1084 * Reset the following CH: [21, 23, 28, 29, 30]
1086 for (i = 0; i < 5; i++) {
1087 idx = ch_indices[i];
1088 out_be64(&priv2->spu_chnlcntptr_RW, idx);
1090 out_be64(&priv2->spu_chnlcnt_RW, ch_counts[i]);
1095 static inline void setup_spu_status_part1(struct spu_state *csa,
1098 u32 status_P = SPU_STATUS_STOPPED_BY_STOP;
1099 u32 status_I = SPU_STATUS_INVALID_INSTR;
1100 u32 status_H = SPU_STATUS_STOPPED_BY_HALT;
1101 u32 status_S = SPU_STATUS_SINGLE_STEP;
1102 u32 status_S_I = SPU_STATUS_SINGLE_STEP | SPU_STATUS_INVALID_INSTR;
1103 u32 status_S_P = SPU_STATUS_SINGLE_STEP | SPU_STATUS_STOPPED_BY_STOP;
1104 u32 status_P_H = SPU_STATUS_STOPPED_BY_HALT |SPU_STATUS_STOPPED_BY_STOP;
1105 u32 status_P_I = SPU_STATUS_STOPPED_BY_STOP |SPU_STATUS_INVALID_INSTR;
1108 /* Restore, Step 27:
1109 * If the CSA.SPU_Status[I,S,H,P]=1 then add the correct
1110 * instruction sequence to the end of the SPU based restore
1111 * code (after the "context restored" stop and signal) to
1112 * restore the correct SPU status.
1114 * NOTE: Rather than modifying the SPU executable, we
1115 * instead add a new 'stopped_status' field to the
1116 * LSCSA. The SPU-side restore reads this field and
1117 * takes the appropriate action when exiting.
1121 (csa->prob.spu_status_R >> SPU_STOP_STATUS_SHIFT) & 0xFFFF;
1122 if ((csa->prob.spu_status_R & status_P_I) == status_P_I) {
1124 /* SPU_Status[P,I]=1 - Illegal Instruction followed
1125 * by Stop and Signal instruction, followed by 'br -4'.
1128 csa->lscsa->stopped_status.slot[0] = SPU_STOPPED_STATUS_P_I;
1129 csa->lscsa->stopped_status.slot[1] = status_code;
1131 } else if ((csa->prob.spu_status_R & status_P_H) == status_P_H) {
1133 /* SPU_Status[P,H]=1 - Halt Conditional, followed
1134 * by Stop and Signal instruction, followed by
1137 csa->lscsa->stopped_status.slot[0] = SPU_STOPPED_STATUS_P_H;
1138 csa->lscsa->stopped_status.slot[1] = status_code;
1140 } else if ((csa->prob.spu_status_R & status_S_P) == status_S_P) {
1142 /* SPU_Status[S,P]=1 - Stop and Signal instruction
1143 * followed by 'br -4'.
1145 csa->lscsa->stopped_status.slot[0] = SPU_STOPPED_STATUS_S_P;
1146 csa->lscsa->stopped_status.slot[1] = status_code;
1148 } else if ((csa->prob.spu_status_R & status_S_I) == status_S_I) {
1150 /* SPU_Status[S,I]=1 - Illegal instruction followed
1153 csa->lscsa->stopped_status.slot[0] = SPU_STOPPED_STATUS_S_I;
1154 csa->lscsa->stopped_status.slot[1] = status_code;
1156 } else if ((csa->prob.spu_status_R & status_P) == status_P) {
1158 /* SPU_Status[P]=1 - Stop and Signal instruction
1159 * followed by 'br -4'.
1161 csa->lscsa->stopped_status.slot[0] = SPU_STOPPED_STATUS_P;
1162 csa->lscsa->stopped_status.slot[1] = status_code;
1164 } else if ((csa->prob.spu_status_R & status_H) == status_H) {
1166 /* SPU_Status[H]=1 - Halt Conditional, followed
1169 csa->lscsa->stopped_status.slot[0] = SPU_STOPPED_STATUS_H;
1171 } else if ((csa->prob.spu_status_R & status_S) == status_S) {
1173 /* SPU_Status[S]=1 - Two nop instructions.
1175 csa->lscsa->stopped_status.slot[0] = SPU_STOPPED_STATUS_S;
1177 } else if ((csa->prob.spu_status_R & status_I) == status_I) {
1179 /* SPU_Status[I]=1 - Illegal instruction followed
1182 csa->lscsa->stopped_status.slot[0] = SPU_STOPPED_STATUS_I;
1187 static inline void setup_spu_status_part2(struct spu_state *csa,
1192 /* Restore, Step 28:
1193 * If the CSA.SPU_Status[I,S,H,P,R]=0 then
1194 * add a 'br *' instruction to the end of
1195 * the SPU based restore code.
1197 * NOTE: Rather than modifying the SPU executable, we
1198 * instead add a new 'stopped_status' field to the
1199 * LSCSA. The SPU-side restore reads this field and
1200 * takes the appropriate action when exiting.
1202 mask = SPU_STATUS_INVALID_INSTR |
1203 SPU_STATUS_SINGLE_STEP |
1204 SPU_STATUS_STOPPED_BY_HALT |
1205 SPU_STATUS_STOPPED_BY_STOP | SPU_STATUS_RUNNING;
1206 if (!(csa->prob.spu_status_R & mask)) {
1207 csa->lscsa->stopped_status.slot[0] = SPU_STOPPED_STATUS_R;
1211 static inline void restore_mfc_rag(struct spu_state *csa, struct spu *spu)
1213 /* Restore, Step 29:
1214 * Restore RA_GROUP_ID register and the
1215 * RA_ENABLE reigster from the CSA.
1217 spu_resource_allocation_groupID_set(spu,
1218 csa->priv1.resource_allocation_groupID_RW);
1219 spu_resource_allocation_enable_set(spu,
1220 csa->priv1.resource_allocation_enable_RW);
1223 static inline void send_restore_code(struct spu_state *csa, struct spu *spu)
1225 unsigned long addr = (unsigned long)&spu_restore_code[0];
1226 unsigned int ls_offset = 0x0;
1227 unsigned int size = sizeof(spu_restore_code);
1228 unsigned int tag = 0;
1229 unsigned int rclass = 0;
1230 unsigned int cmd = MFC_GETFS_CMD;
1232 /* Restore, Step 37:
1233 * Issue MFC DMA command to copy context
1234 * restore code to local storage.
1236 send_mfc_dma(spu, addr, ls_offset, size, tag, rclass, cmd);
1239 static inline void setup_decr(struct spu_state *csa, struct spu *spu)
1241 /* Restore, Step 34:
1242 * If CSA.MFC_CNTL[Ds]=1 (decrementer was
1243 * running) then adjust decrementer, set
1244 * decrementer running status in LSCSA,
1245 * and set decrementer "wrapped" status
1248 if (csa->priv2.mfc_control_RW & MFC_CNTL_DECREMENTER_RUNNING) {
1249 cycles_t resume_time = get_cycles();
1250 cycles_t delta_time = resume_time - csa->suspend_time;
1252 csa->lscsa->decr_status.slot[0] = SPU_DECR_STATUS_RUNNING;
1253 if (csa->lscsa->decr.slot[0] < delta_time) {
1254 csa->lscsa->decr_status.slot[0] |=
1255 SPU_DECR_STATUS_WRAPPED;
1258 csa->lscsa->decr.slot[0] -= delta_time;
1260 csa->lscsa->decr_status.slot[0] = 0;
1264 static inline void setup_ppu_mb(struct spu_state *csa, struct spu *spu)
1266 /* Restore, Step 35:
1267 * Copy the CSA.PU_MB data into the LSCSA.
1269 csa->lscsa->ppu_mb.slot[0] = csa->prob.pu_mb_R;
1272 static inline void setup_ppuint_mb(struct spu_state *csa, struct spu *spu)
1274 /* Restore, Step 36:
1275 * Copy the CSA.PUINT_MB data into the LSCSA.
1277 csa->lscsa->ppuint_mb.slot[0] = csa->priv2.puint_mb_R;
1280 static inline int check_restore_status(struct spu_state *csa, struct spu *spu)
1282 struct spu_problem __iomem *prob = spu->problem;
1285 /* Restore, Step 40:
1286 * If SPU_Status[P]=1 and SPU_Status[SC] = "success",
1287 * context restore succeeded, otherwise context restore
1290 complete = ((SPU_RESTORE_COMPLETE << SPU_STOP_STATUS_SHIFT) |
1291 SPU_STATUS_STOPPED_BY_STOP);
1292 return (in_be32(&prob->spu_status_R) != complete) ? 1 : 0;
1295 static inline void restore_spu_privcntl(struct spu_state *csa, struct spu *spu)
1297 struct spu_priv2 __iomem *priv2 = spu->priv2;
1299 /* Restore, Step 41:
1300 * Restore SPU_PrivCntl from the CSA.
1302 out_be64(&priv2->spu_privcntl_RW, csa->priv2.spu_privcntl_RW);
1306 static inline void restore_status_part1(struct spu_state *csa, struct spu *spu)
1308 struct spu_problem __iomem *prob = spu->problem;
1311 /* Restore, Step 42:
1312 * If any CSA.SPU_Status[I,S,H,P]=1, then
1313 * restore the error or single step state.
1315 mask = SPU_STATUS_INVALID_INSTR |
1316 SPU_STATUS_SINGLE_STEP |
1317 SPU_STATUS_STOPPED_BY_HALT | SPU_STATUS_STOPPED_BY_STOP;
1318 if (csa->prob.spu_status_R & mask) {
1319 out_be32(&prob->spu_runcntl_RW, SPU_RUNCNTL_RUNNABLE);
1321 POLL_WHILE_TRUE(in_be32(&prob->spu_status_R) &
1322 SPU_STATUS_RUNNING);
1326 static inline void restore_status_part2(struct spu_state *csa, struct spu *spu)
1328 struct spu_problem __iomem *prob = spu->problem;
1331 /* Restore, Step 43:
1332 * If all CSA.SPU_Status[I,S,H,P,R]=0 then write
1333 * SPU_RunCntl[R0R1]='01', wait for SPU_Status[R]=1,
1334 * then write '00' to SPU_RunCntl[R0R1] and wait
1335 * for SPU_Status[R]=0.
1337 mask = SPU_STATUS_INVALID_INSTR |
1338 SPU_STATUS_SINGLE_STEP |
1339 SPU_STATUS_STOPPED_BY_HALT |
1340 SPU_STATUS_STOPPED_BY_STOP | SPU_STATUS_RUNNING;
1341 if (!(csa->prob.spu_status_R & mask)) {
1342 out_be32(&prob->spu_runcntl_RW, SPU_RUNCNTL_RUNNABLE);
1344 POLL_WHILE_FALSE(in_be32(&prob->spu_status_R) &
1345 SPU_STATUS_RUNNING);
1346 out_be32(&prob->spu_runcntl_RW, SPU_RUNCNTL_STOP);
1348 POLL_WHILE_TRUE(in_be32(&prob->spu_status_R) &
1349 SPU_STATUS_RUNNING);
1353 static inline void restore_ls_16kb(struct spu_state *csa, struct spu *spu)
1355 unsigned long addr = (unsigned long)&csa->lscsa->ls[0];
1356 unsigned int ls_offset = 0x0;
1357 unsigned int size = 16384;
1358 unsigned int tag = 0;
1359 unsigned int rclass = 0;
1360 unsigned int cmd = MFC_GET_CMD;
1362 /* Restore, Step 44:
1363 * Issue a DMA command to restore the first
1364 * 16kb of local storage from CSA.
1366 send_mfc_dma(spu, addr, ls_offset, size, tag, rclass, cmd);
1369 static inline void suspend_mfc(struct spu_state *csa, struct spu *spu)
1371 struct spu_priv2 __iomem *priv2 = spu->priv2;
1373 /* Restore, Step 47.
1374 * Write MFC_Cntl[Sc,Sm]='1','0' to suspend
1377 out_be64(&priv2->mfc_control_RW, MFC_CNTL_SUSPEND_DMA_QUEUE);
1381 static inline void clear_interrupts(struct spu_state *csa, struct spu *spu)
1383 /* Restore, Step 49:
1384 * Write INT_MASK_class0 with value of 0.
1385 * Write INT_MASK_class1 with value of 0.
1386 * Write INT_MASK_class2 with value of 0.
1387 * Write INT_STAT_class0 with value of -1.
1388 * Write INT_STAT_class1 with value of -1.
1389 * Write INT_STAT_class2 with value of -1.
1391 spin_lock_irq(&spu->register_lock);
1392 spu_int_mask_set(spu, 0, 0ul);
1393 spu_int_mask_set(spu, 1, 0ul);
1394 spu_int_mask_set(spu, 2, 0ul);
1395 spu_int_stat_clear(spu, 0, ~0ul);
1396 spu_int_stat_clear(spu, 1, ~0ul);
1397 spu_int_stat_clear(spu, 2, ~0ul);
1398 spin_unlock_irq(&spu->register_lock);
1401 static inline void restore_mfc_queues(struct spu_state *csa, struct spu *spu)
1403 struct spu_priv2 __iomem *priv2 = spu->priv2;
1406 /* Restore, Step 50:
1407 * If MFC_Cntl[Se]!=0 then restore
1408 * MFC command queues.
1410 if ((csa->priv2.mfc_control_RW & MFC_CNTL_DMA_QUEUES_EMPTY_MASK) == 0) {
1411 for (i = 0; i < 8; i++) {
1412 out_be64(&priv2->puq[i].mfc_cq_data0_RW,
1413 csa->priv2.puq[i].mfc_cq_data0_RW);
1414 out_be64(&priv2->puq[i].mfc_cq_data1_RW,
1415 csa->priv2.puq[i].mfc_cq_data1_RW);
1416 out_be64(&priv2->puq[i].mfc_cq_data2_RW,
1417 csa->priv2.puq[i].mfc_cq_data2_RW);
1418 out_be64(&priv2->puq[i].mfc_cq_data3_RW,
1419 csa->priv2.puq[i].mfc_cq_data3_RW);
1421 for (i = 0; i < 16; i++) {
1422 out_be64(&priv2->spuq[i].mfc_cq_data0_RW,
1423 csa->priv2.spuq[i].mfc_cq_data0_RW);
1424 out_be64(&priv2->spuq[i].mfc_cq_data1_RW,
1425 csa->priv2.spuq[i].mfc_cq_data1_RW);
1426 out_be64(&priv2->spuq[i].mfc_cq_data2_RW,
1427 csa->priv2.spuq[i].mfc_cq_data2_RW);
1428 out_be64(&priv2->spuq[i].mfc_cq_data3_RW,
1429 csa->priv2.spuq[i].mfc_cq_data3_RW);
1435 static inline void restore_ppu_querymask(struct spu_state *csa, struct spu *spu)
1437 struct spu_problem __iomem *prob = spu->problem;
1439 /* Restore, Step 51:
1440 * Restore the PPU_QueryMask register from CSA.
1442 out_be32(&prob->dma_querymask_RW, csa->prob.dma_querymask_RW);
1446 static inline void restore_ppu_querytype(struct spu_state *csa, struct spu *spu)
1448 struct spu_problem __iomem *prob = spu->problem;
1450 /* Restore, Step 52:
1451 * Restore the PPU_QueryType register from CSA.
1453 out_be32(&prob->dma_querytype_RW, csa->prob.dma_querytype_RW);
1457 static inline void restore_mfc_csr_tsq(struct spu_state *csa, struct spu *spu)
1459 struct spu_priv2 __iomem *priv2 = spu->priv2;
1461 /* Restore, Step 53:
1462 * Restore the MFC_CSR_TSQ register from CSA.
1464 out_be64(&priv2->spu_tag_status_query_RW,
1465 csa->priv2.spu_tag_status_query_RW);
1469 static inline void restore_mfc_csr_cmd(struct spu_state *csa, struct spu *spu)
1471 struct spu_priv2 __iomem *priv2 = spu->priv2;
1473 /* Restore, Step 54:
1474 * Restore the MFC_CSR_CMD1 and MFC_CSR_CMD2
1475 * registers from CSA.
1477 out_be64(&priv2->spu_cmd_buf1_RW, csa->priv2.spu_cmd_buf1_RW);
1478 out_be64(&priv2->spu_cmd_buf2_RW, csa->priv2.spu_cmd_buf2_RW);
1482 static inline void restore_mfc_csr_ato(struct spu_state *csa, struct spu *spu)
1484 struct spu_priv2 __iomem *priv2 = spu->priv2;
1486 /* Restore, Step 55:
1487 * Restore the MFC_CSR_ATO register from CSA.
1489 out_be64(&priv2->spu_atomic_status_RW, csa->priv2.spu_atomic_status_RW);
1492 static inline void restore_mfc_tclass_id(struct spu_state *csa, struct spu *spu)
1494 /* Restore, Step 56:
1495 * Restore the MFC_TCLASS_ID register from CSA.
1497 spu_mfc_tclass_id_set(spu, csa->priv1.mfc_tclass_id_RW);
1501 static inline void set_llr_event(struct spu_state *csa, struct spu *spu)
1503 u64 ch0_cnt, ch0_data;
1506 /* Restore, Step 57:
1507 * Set the Lock Line Reservation Lost Event by:
1508 * 1. OR CSA.SPU_Event_Status with bit 21 (Lr) set to 1.
1509 * 2. If CSA.SPU_Channel_0_Count=0 and
1510 * CSA.SPU_Wr_Event_Mask[Lr]=1 and
1511 * CSA.SPU_Event_Status[Lr]=0 then set
1512 * CSA.SPU_Event_Status_Count=1.
1514 ch0_cnt = csa->spu_chnlcnt_RW[0];
1515 ch0_data = csa->spu_chnldata_RW[0];
1516 ch1_data = csa->spu_chnldata_RW[1];
1517 csa->spu_chnldata_RW[0] |= MFC_LLR_LOST_EVENT;
1518 if ((ch0_cnt == 0) && !(ch0_data & MFC_LLR_LOST_EVENT) &&
1519 (ch1_data & MFC_LLR_LOST_EVENT)) {
1520 csa->spu_chnlcnt_RW[0] = 1;
1524 static inline void restore_decr_wrapped(struct spu_state *csa, struct spu *spu)
1526 /* Restore, Step 58:
1527 * If the status of the CSA software decrementer
1528 * "wrapped" flag is set, OR in a '1' to
1529 * CSA.SPU_Event_Status[Tm].
1531 if (!(csa->lscsa->decr_status.slot[0] & SPU_DECR_STATUS_WRAPPED))
1534 if ((csa->spu_chnlcnt_RW[0] == 0) &&
1535 (csa->spu_chnldata_RW[1] & 0x20) &&
1536 !(csa->spu_chnldata_RW[0] & 0x20))
1537 csa->spu_chnlcnt_RW[0] = 1;
1539 csa->spu_chnldata_RW[0] |= 0x20;
1542 static inline void restore_ch_part1(struct spu_state *csa, struct spu *spu)
1544 struct spu_priv2 __iomem *priv2 = spu->priv2;
1545 u64 idx, ch_indices[] = { 0UL, 3UL, 4UL, 24UL, 25UL, 27UL };
1548 /* Restore, Step 59:
1549 * Restore the following CH: [0,3,4,24,25,27]
1551 for (i = 0; i < ARRAY_SIZE(ch_indices); i++) {
1552 idx = ch_indices[i];
1553 out_be64(&priv2->spu_chnlcntptr_RW, idx);
1555 out_be64(&priv2->spu_chnldata_RW, csa->spu_chnldata_RW[idx]);
1556 out_be64(&priv2->spu_chnlcnt_RW, csa->spu_chnlcnt_RW[idx]);
1561 static inline void restore_ch_part2(struct spu_state *csa, struct spu *spu)
1563 struct spu_priv2 __iomem *priv2 = spu->priv2;
1564 u64 ch_indices[3] = { 9UL, 21UL, 23UL };
1565 u64 ch_counts[3] = { 1UL, 16UL, 1UL };
1569 /* Restore, Step 60:
1570 * Restore the following CH: [9,21,23].
1573 ch_counts[1] = csa->spu_chnlcnt_RW[21];
1575 for (i = 0; i < 3; i++) {
1576 idx = ch_indices[i];
1577 out_be64(&priv2->spu_chnlcntptr_RW, idx);
1579 out_be64(&priv2->spu_chnlcnt_RW, ch_counts[i]);
1584 static inline void restore_spu_lslr(struct spu_state *csa, struct spu *spu)
1586 struct spu_priv2 __iomem *priv2 = spu->priv2;
1588 /* Restore, Step 61:
1589 * Restore the SPU_LSLR register from CSA.
1591 out_be64(&priv2->spu_lslr_RW, csa->priv2.spu_lslr_RW);
1595 static inline void restore_spu_cfg(struct spu_state *csa, struct spu *spu)
1597 struct spu_priv2 __iomem *priv2 = spu->priv2;
1599 /* Restore, Step 62:
1600 * Restore the SPU_Cfg register from CSA.
1602 out_be64(&priv2->spu_cfg_RW, csa->priv2.spu_cfg_RW);
1606 static inline void restore_pm_trace(struct spu_state *csa, struct spu *spu)
1608 /* Restore, Step 63:
1609 * Restore PM_Trace_Tag_Wait_Mask from CSA.
1610 * Not performed by this implementation.
1614 static inline void restore_spu_npc(struct spu_state *csa, struct spu *spu)
1616 struct spu_problem __iomem *prob = spu->problem;
1618 /* Restore, Step 64:
1619 * Restore SPU_NPC from CSA.
1621 out_be32(&prob->spu_npc_RW, csa->prob.spu_npc_RW);
1625 static inline void restore_spu_mb(struct spu_state *csa, struct spu *spu)
1627 struct spu_priv2 __iomem *priv2 = spu->priv2;
1630 /* Restore, Step 65:
1631 * Restore MFC_RdSPU_MB from CSA.
1633 out_be64(&priv2->spu_chnlcntptr_RW, 29UL);
1635 out_be64(&priv2->spu_chnlcnt_RW, csa->spu_chnlcnt_RW[29]);
1636 for (i = 0; i < 4; i++) {
1637 out_be64(&priv2->spu_chnldata_RW, csa->spu_mailbox_data[i]);
1642 static inline void check_ppu_mb_stat(struct spu_state *csa, struct spu *spu)
1644 struct spu_problem __iomem *prob = spu->problem;
1647 /* Restore, Step 66:
1648 * If CSA.MB_Stat[P]=0 (mailbox empty) then
1649 * read from the PPU_MB register.
1651 if ((csa->prob.mb_stat_R & 0xFF) == 0) {
1652 dummy = in_be32(&prob->pu_mb_R);
1657 static inline void check_ppuint_mb_stat(struct spu_state *csa, struct spu *spu)
1659 struct spu_priv2 __iomem *priv2 = spu->priv2;
1662 /* Restore, Step 66:
1663 * If CSA.MB_Stat[I]=0 (mailbox empty) then
1664 * read from the PPUINT_MB register.
1666 if ((csa->prob.mb_stat_R & 0xFF0000) == 0) {
1667 dummy = in_be64(&priv2->puint_mb_R);
1669 spu_int_stat_clear(spu, 2, CLASS2_ENABLE_MAILBOX_INTR);
1674 static inline void restore_mfc_sr1(struct spu_state *csa, struct spu *spu)
1676 /* Restore, Step 69:
1677 * Restore the MFC_SR1 register from CSA.
1679 spu_mfc_sr1_set(spu, csa->priv1.mfc_sr1_RW);
1683 static inline void restore_other_spu_access(struct spu_state *csa,
1686 /* Restore, Step 70:
1687 * Restore other SPU mappings to this SPU. TBD.
1691 static inline void restore_spu_runcntl(struct spu_state *csa, struct spu *spu)
1693 struct spu_problem __iomem *prob = spu->problem;
1695 /* Restore, Step 71:
1696 * If CSA.SPU_Status[R]=1 then write
1697 * SPU_RunCntl[R0R1]='01'.
1699 if (csa->prob.spu_status_R & SPU_STATUS_RUNNING) {
1700 out_be32(&prob->spu_runcntl_RW, SPU_RUNCNTL_RUNNABLE);
1705 static inline void restore_mfc_cntl(struct spu_state *csa, struct spu *spu)
1707 struct spu_priv2 __iomem *priv2 = spu->priv2;
1709 /* Restore, Step 72:
1710 * Restore the MFC_CNTL register for the CSA.
1712 out_be64(&priv2->mfc_control_RW, csa->priv2.mfc_control_RW);
1715 * FIXME: this is to restart a DMA that we were processing
1716 * before the save. better remember the fault information
1717 * in the csa instead.
1719 if ((csa->priv2.mfc_control_RW & MFC_CNTL_SUSPEND_DMA_QUEUE_MASK)) {
1720 out_be64(&priv2->mfc_control_RW, MFC_CNTL_RESTART_DMA_COMMAND);
1725 static inline void enable_user_access(struct spu_state *csa, struct spu *spu)
1727 /* Restore, Step 73:
1728 * Enable user-space access (if provided) to this
1729 * SPU by mapping the virtual pages assigned to
1730 * the SPU memory-mapped I/O (MMIO) for problem
1735 static inline void reset_switch_active(struct spu_state *csa, struct spu *spu)
1737 /* Restore, Step 74:
1738 * Reset the "context switch active" flag.
1740 clear_bit(SPU_CONTEXT_SWITCH_ACTIVE, &spu->flags);
1744 static inline void reenable_interrupts(struct spu_state *csa, struct spu *spu)
1746 /* Restore, Step 75:
1747 * Re-enable SPU interrupts.
1749 spin_lock_irq(&spu->register_lock);
1750 spu_int_mask_set(spu, 0, csa->priv1.int_mask_class0_RW);
1751 spu_int_mask_set(spu, 1, csa->priv1.int_mask_class1_RW);
1752 spu_int_mask_set(spu, 2, csa->priv1.int_mask_class2_RW);
1753 spin_unlock_irq(&spu->register_lock);
1756 static int quiece_spu(struct spu_state *prev, struct spu *spu)
1759 * Combined steps 2-18 of SPU context save sequence, which
1760 * quiesce the SPU state (disable SPU execution, MFC command
1761 * queues, decrementer, SPU interrupts, etc.).
1763 * Returns 0 on success.
1764 * 2 if failed step 2.
1765 * 6 if failed step 6.
1768 if (check_spu_isolate(prev, spu)) { /* Step 2. */
1771 disable_interrupts(prev, spu); /* Step 3. */
1772 set_watchdog_timer(prev, spu); /* Step 4. */
1773 inhibit_user_access(prev, spu); /* Step 5. */
1774 if (check_spu_isolate(prev, spu)) { /* Step 6. */
1777 set_switch_pending(prev, spu); /* Step 7. */
1778 save_mfc_cntl(prev, spu); /* Step 8. */
1779 save_spu_runcntl(prev, spu); /* Step 9. */
1780 save_mfc_sr1(prev, spu); /* Step 10. */
1781 save_spu_status(prev, spu); /* Step 11. */
1782 save_mfc_decr(prev, spu); /* Step 12. */
1783 halt_mfc_decr(prev, spu); /* Step 13. */
1784 save_timebase(prev, spu); /* Step 14. */
1785 remove_other_spu_access(prev, spu); /* Step 15. */
1786 do_mfc_mssync(prev, spu); /* Step 16. */
1787 issue_mfc_tlbie(prev, spu); /* Step 17. */
1788 handle_pending_interrupts(prev, spu); /* Step 18. */
1793 static void save_csa(struct spu_state *prev, struct spu *spu)
1796 * Combine steps 19-44 of SPU context save sequence, which
1797 * save regions of the privileged & problem state areas.
1800 save_mfc_queues(prev, spu); /* Step 19. */
1801 save_ppu_querymask(prev, spu); /* Step 20. */
1802 save_ppu_querytype(prev, spu); /* Step 21. */
1803 save_ppu_tagstatus(prev, spu); /* NEW. */
1804 save_mfc_csr_tsq(prev, spu); /* Step 22. */
1805 save_mfc_csr_cmd(prev, spu); /* Step 23. */
1806 save_mfc_csr_ato(prev, spu); /* Step 24. */
1807 save_mfc_tclass_id(prev, spu); /* Step 25. */
1808 set_mfc_tclass_id(prev, spu); /* Step 26. */
1809 purge_mfc_queue(prev, spu); /* Step 27. */
1810 wait_purge_complete(prev, spu); /* Step 28. */
1811 setup_mfc_sr1(prev, spu); /* Step 30. */
1812 save_spu_npc(prev, spu); /* Step 31. */
1813 save_spu_privcntl(prev, spu); /* Step 32. */
1814 reset_spu_privcntl(prev, spu); /* Step 33. */
1815 save_spu_lslr(prev, spu); /* Step 34. */
1816 reset_spu_lslr(prev, spu); /* Step 35. */
1817 save_spu_cfg(prev, spu); /* Step 36. */
1818 save_pm_trace(prev, spu); /* Step 37. */
1819 save_mfc_rag(prev, spu); /* Step 38. */
1820 save_ppu_mb_stat(prev, spu); /* Step 39. */
1821 save_ppu_mb(prev, spu); /* Step 40. */
1822 save_ppuint_mb(prev, spu); /* Step 41. */
1823 save_ch_part1(prev, spu); /* Step 42. */
1824 save_spu_mb(prev, spu); /* Step 43. */
1825 save_mfc_cmd(prev, spu); /* Step 44. */
1826 reset_ch(prev, spu); /* Step 45. */
1829 static void save_lscsa(struct spu_state *prev, struct spu *spu)
1832 * Perform steps 46-57 of SPU context save sequence,
1833 * which save regions of the local store and register
1837 resume_mfc_queue(prev, spu); /* Step 46. */
1838 setup_mfc_slbs(prev, spu); /* Step 47. */
1839 set_switch_active(prev, spu); /* Step 48. */
1840 enable_interrupts(prev, spu); /* Step 49. */
1841 save_ls_16kb(prev, spu); /* Step 50. */
1842 set_spu_npc(prev, spu); /* Step 51. */
1843 set_signot1(prev, spu); /* Step 52. */
1844 set_signot2(prev, spu); /* Step 53. */
1845 send_save_code(prev, spu); /* Step 54. */
1846 set_ppu_querymask(prev, spu); /* Step 55. */
1847 wait_tag_complete(prev, spu); /* Step 56. */
1848 wait_spu_stopped(prev, spu); /* Step 57. */
1851 static void force_spu_isolate_exit(struct spu *spu)
1853 struct spu_problem __iomem *prob = spu->problem;
1854 struct spu_priv2 __iomem *priv2 = spu->priv2;
1856 /* Stop SPE execution and wait for completion. */
1857 out_be32(&prob->spu_runcntl_RW, SPU_RUNCNTL_STOP);
1859 POLL_WHILE_TRUE(in_be32(&prob->spu_status_R) & SPU_STATUS_RUNNING);
1861 /* Restart SPE master runcntl. */
1862 spu_mfc_sr1_set(spu, MFC_STATE1_MASTER_RUN_CONTROL_MASK);
1865 /* Initiate isolate exit request and wait for completion. */
1866 out_be64(&priv2->spu_privcntl_RW, 4LL);
1868 out_be32(&prob->spu_runcntl_RW, 2);
1870 POLL_WHILE_FALSE((in_be32(&prob->spu_status_R)
1871 & SPU_STATUS_STOPPED_BY_STOP));
1873 /* Reset load request to normal. */
1874 out_be64(&priv2->spu_privcntl_RW, SPU_PRIVCNT_LOAD_REQUEST_NORMAL);
1880 * Check SPU run-control state and force isolated
1881 * exit function as necessary.
1883 static void stop_spu_isolate(struct spu *spu)
1885 struct spu_problem __iomem *prob = spu->problem;
1887 if (in_be32(&prob->spu_status_R) & SPU_STATUS_ISOLATED_STATE) {
1888 /* The SPU is in isolated state; the only way
1889 * to get it out is to perform an isolated
1890 * exit (clean) operation.
1892 force_spu_isolate_exit(spu);
1896 static void harvest(struct spu_state *prev, struct spu *spu)
1899 * Perform steps 2-25 of SPU context restore sequence,
1900 * which resets an SPU either after a failed save, or
1901 * when using SPU for first time.
1904 disable_interrupts(prev, spu); /* Step 2. */
1905 inhibit_user_access(prev, spu); /* Step 3. */
1906 terminate_spu_app(prev, spu); /* Step 4. */
1907 set_switch_pending(prev, spu); /* Step 5. */
1908 stop_spu_isolate(spu); /* NEW. */
1909 remove_other_spu_access(prev, spu); /* Step 6. */
1910 suspend_mfc_and_halt_decr(prev, spu); /* Step 7. */
1911 wait_suspend_mfc_complete(prev, spu); /* Step 8. */
1912 if (!suspend_spe(prev, spu)) /* Step 9. */
1913 clear_spu_status(prev, spu); /* Step 10. */
1914 do_mfc_mssync(prev, spu); /* Step 11. */
1915 issue_mfc_tlbie(prev, spu); /* Step 12. */
1916 handle_pending_interrupts(prev, spu); /* Step 13. */
1917 purge_mfc_queue(prev, spu); /* Step 14. */
1918 wait_purge_complete(prev, spu); /* Step 15. */
1919 reset_spu_privcntl(prev, spu); /* Step 16. */
1920 reset_spu_lslr(prev, spu); /* Step 17. */
1921 setup_mfc_sr1(prev, spu); /* Step 18. */
1922 spu_invalidate_slbs(spu); /* Step 19. */
1923 reset_ch_part1(prev, spu); /* Step 20. */
1924 reset_ch_part2(prev, spu); /* Step 21. */
1925 enable_interrupts(prev, spu); /* Step 22. */
1926 set_switch_active(prev, spu); /* Step 23. */
1927 set_mfc_tclass_id(prev, spu); /* Step 24. */
1928 resume_mfc_queue(prev, spu); /* Step 25. */
1931 static void restore_lscsa(struct spu_state *next, struct spu *spu)
1934 * Perform steps 26-40 of SPU context restore sequence,
1935 * which restores regions of the local store and register
1939 set_watchdog_timer(next, spu); /* Step 26. */
1940 setup_spu_status_part1(next, spu); /* Step 27. */
1941 setup_spu_status_part2(next, spu); /* Step 28. */
1942 restore_mfc_rag(next, spu); /* Step 29. */
1943 setup_mfc_slbs(next, spu); /* Step 30. */
1944 set_spu_npc(next, spu); /* Step 31. */
1945 set_signot1(next, spu); /* Step 32. */
1946 set_signot2(next, spu); /* Step 33. */
1947 setup_decr(next, spu); /* Step 34. */
1948 setup_ppu_mb(next, spu); /* Step 35. */
1949 setup_ppuint_mb(next, spu); /* Step 36. */
1950 send_restore_code(next, spu); /* Step 37. */
1951 set_ppu_querymask(next, spu); /* Step 38. */
1952 wait_tag_complete(next, spu); /* Step 39. */
1953 wait_spu_stopped(next, spu); /* Step 40. */
1956 static void restore_csa(struct spu_state *next, struct spu *spu)
1959 * Combine steps 41-76 of SPU context restore sequence, which
1960 * restore regions of the privileged & problem state areas.
1963 restore_spu_privcntl(next, spu); /* Step 41. */
1964 restore_status_part1(next, spu); /* Step 42. */
1965 restore_status_part2(next, spu); /* Step 43. */
1966 restore_ls_16kb(next, spu); /* Step 44. */
1967 wait_tag_complete(next, spu); /* Step 45. */
1968 suspend_mfc(next, spu); /* Step 46. */
1969 wait_suspend_mfc_complete(next, spu); /* Step 47. */
1970 issue_mfc_tlbie(next, spu); /* Step 48. */
1971 clear_interrupts(next, spu); /* Step 49. */
1972 restore_mfc_queues(next, spu); /* Step 50. */
1973 restore_ppu_querymask(next, spu); /* Step 51. */
1974 restore_ppu_querytype(next, spu); /* Step 52. */
1975 restore_mfc_csr_tsq(next, spu); /* Step 53. */
1976 restore_mfc_csr_cmd(next, spu); /* Step 54. */
1977 restore_mfc_csr_ato(next, spu); /* Step 55. */
1978 restore_mfc_tclass_id(next, spu); /* Step 56. */
1979 set_llr_event(next, spu); /* Step 57. */
1980 restore_decr_wrapped(next, spu); /* Step 58. */
1981 restore_ch_part1(next, spu); /* Step 59. */
1982 restore_ch_part2(next, spu); /* Step 60. */
1983 restore_spu_lslr(next, spu); /* Step 61. */
1984 restore_spu_cfg(next, spu); /* Step 62. */
1985 restore_pm_trace(next, spu); /* Step 63. */
1986 restore_spu_npc(next, spu); /* Step 64. */
1987 restore_spu_mb(next, spu); /* Step 65. */
1988 check_ppu_mb_stat(next, spu); /* Step 66. */
1989 check_ppuint_mb_stat(next, spu); /* Step 67. */
1990 spu_invalidate_slbs(spu); /* Modified Step 68. */
1991 restore_mfc_sr1(next, spu); /* Step 69. */
1992 restore_other_spu_access(next, spu); /* Step 70. */
1993 restore_spu_runcntl(next, spu); /* Step 71. */
1994 restore_mfc_cntl(next, spu); /* Step 72. */
1995 enable_user_access(next, spu); /* Step 73. */
1996 reset_switch_active(next, spu); /* Step 74. */
1997 reenable_interrupts(next, spu); /* Step 75. */
2000 static int __do_spu_save(struct spu_state *prev, struct spu *spu)
2005 * SPU context save can be broken into three phases:
2007 * (a) quiesce [steps 2-16].
2008 * (b) save of CSA, performed by PPE [steps 17-42]
2009 * (c) save of LSCSA, mostly performed by SPU [steps 43-52].
2011 * Returns 0 on success.
2012 * 2,6 if failed to quiece SPU
2013 * 53 if SPU-side of save failed.
2016 rc = quiece_spu(prev, spu); /* Steps 2-16. */
2027 save_csa(prev, spu); /* Steps 17-43. */
2028 save_lscsa(prev, spu); /* Steps 44-53. */
2029 return check_save_status(prev, spu); /* Step 54. */
2032 static int __do_spu_restore(struct spu_state *next, struct spu *spu)
2037 * SPU context restore can be broken into three phases:
2039 * (a) harvest (or reset) SPU [steps 2-24].
2040 * (b) restore LSCSA [steps 25-40], mostly performed by SPU.
2041 * (c) restore CSA [steps 41-76], performed by PPE.
2043 * The 'harvest' step is not performed here, but rather
2047 restore_lscsa(next, spu); /* Steps 24-39. */
2048 rc = check_restore_status(next, spu); /* Step 40. */
2051 /* Failed. Return now. */
2055 /* Fall through to next step. */
2058 restore_csa(next, spu);
2064 * spu_save - SPU context save, with locking.
2065 * @prev: pointer to SPU context save area, to be saved.
2066 * @spu: pointer to SPU iomem structure.
2068 * Acquire locks, perform the save operation then return.
2070 int spu_save(struct spu_state *prev, struct spu *spu)
2074 acquire_spu_lock(spu); /* Step 1. */
2075 prev->dar = spu->dar;
2076 prev->dsisr = spu->dsisr;
2079 rc = __do_spu_save(prev, spu); /* Steps 2-53. */
2080 release_spu_lock(spu);
2081 if (rc != 0 && rc != 2 && rc != 6) {
2082 panic("%s failed on SPU[%d], rc=%d.\n",
2083 __func__, spu->number, rc);
2087 EXPORT_SYMBOL_GPL(spu_save);
2090 * spu_restore - SPU context restore, with harvest and locking.
2091 * @new: pointer to SPU context save area, to be restored.
2092 * @spu: pointer to SPU iomem structure.
2094 * Perform harvest + restore, as we may not be coming
2095 * from a previous successful save operation, and the
2096 * hardware state is unknown.
2098 int spu_restore(struct spu_state *new, struct spu *spu)
2102 acquire_spu_lock(spu);
2104 spu->slb_replace = 0;
2107 spu->class_0_pending = 0;
2108 rc = __do_spu_restore(new, spu);
2109 release_spu_lock(spu);
2111 panic("%s failed on SPU[%d] rc=%d.\n",
2112 __func__, spu->number, rc);
2116 EXPORT_SYMBOL_GPL(spu_restore);
2118 static void init_prob(struct spu_state *csa)
2120 csa->spu_chnlcnt_RW[9] = 1;
2121 csa->spu_chnlcnt_RW[21] = 16;
2122 csa->spu_chnlcnt_RW[23] = 1;
2123 csa->spu_chnlcnt_RW[28] = 1;
2124 csa->spu_chnlcnt_RW[30] = 1;
2125 csa->prob.spu_runcntl_RW = SPU_RUNCNTL_STOP;
2126 csa->prob.mb_stat_R = 0x000400;
2129 static void init_priv1(struct spu_state *csa)
2131 /* Enable decode, relocate, tlbie response, master runcntl. */
2132 csa->priv1.mfc_sr1_RW = MFC_STATE1_LOCAL_STORAGE_DECODE_MASK |
2133 MFC_STATE1_MASTER_RUN_CONTROL_MASK |
2134 MFC_STATE1_PROBLEM_STATE_MASK |
2135 MFC_STATE1_RELOCATE_MASK | MFC_STATE1_BUS_TLBIE_MASK;
2137 /* Enable OS-specific set of interrupts. */
2138 csa->priv1.int_mask_class0_RW = CLASS0_ENABLE_DMA_ALIGNMENT_INTR |
2139 CLASS0_ENABLE_INVALID_DMA_COMMAND_INTR |
2140 CLASS0_ENABLE_SPU_ERROR_INTR;
2141 csa->priv1.int_mask_class1_RW = CLASS1_ENABLE_SEGMENT_FAULT_INTR |
2142 CLASS1_ENABLE_STORAGE_FAULT_INTR;
2143 csa->priv1.int_mask_class2_RW = CLASS2_ENABLE_SPU_STOP_INTR |
2144 CLASS2_ENABLE_SPU_HALT_INTR |
2145 CLASS2_ENABLE_SPU_DMA_TAG_GROUP_COMPLETE_INTR;
2148 static void init_priv2(struct spu_state *csa)
2150 csa->priv2.spu_lslr_RW = LS_ADDR_MASK;
2151 csa->priv2.mfc_control_RW = MFC_CNTL_RESUME_DMA_QUEUE |
2152 MFC_CNTL_NORMAL_DMA_QUEUE_OPERATION |
2153 MFC_CNTL_DMA_QUEUES_EMPTY_MASK;
2157 * spu_alloc_csa - allocate and initialize an SPU context save area.
2159 * Allocate and initialize the contents of an SPU context save area.
2160 * This includes enabling address translation, interrupt masks, etc.,
2161 * as appropriate for the given OS environment.
2163 * Note that storage for the 'lscsa' is allocated separately,
2164 * as it is by far the largest of the context save regions,
2165 * and may need to be pinned or otherwise specially aligned.
2167 int spu_init_csa(struct spu_state *csa)
2173 memset(csa, 0, sizeof(struct spu_state));
2175 rc = spu_alloc_lscsa(csa);
2179 spin_lock_init(&csa->register_lock);
2187 EXPORT_SYMBOL_GPL(spu_init_csa);
2189 void spu_fini_csa(struct spu_state *csa)
2191 spu_free_lscsa(csa);
2193 EXPORT_SYMBOL_GPL(spu_fini_csa);