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/hardirq.h>
38 #include <linux/sched.h>
39 #include <linux/kernel.h>
41 #include <linux/vmalloc.h>
42 #include <linux/smp.h>
43 #include <linux/stddef.h>
44 #include <linux/unistd.h>
48 #include <asm/spu_priv1.h>
49 #include <asm/spu_csa.h>
50 #include <asm/mmu_context.h>
54 #include "spu_save_dump.h"
55 #include "spu_restore_dump.h"
58 #define POLL_WHILE_TRUE(_c) { \
63 #define RELAX_SPIN_COUNT 1000
64 #define POLL_WHILE_TRUE(_c) { \
67 for (_i=0; _i<RELAX_SPIN_COUNT && (_c); _i++) { \
70 if (unlikely(_c)) yield(); \
76 #define POLL_WHILE_FALSE(_c) POLL_WHILE_TRUE(!(_c))
78 static inline void acquire_spu_lock(struct spu
*spu
)
82 * Acquire SPU-specific mutual exclusion lock.
87 static inline void release_spu_lock(struct spu
*spu
)
90 * Release SPU-specific mutual exclusion lock.
95 static inline int check_spu_isolate(struct spu_state
*csa
, struct spu
*spu
)
97 struct spu_problem __iomem
*prob
= spu
->problem
;
102 * If SPU_Status[E,L,IS] any field is '1', this
103 * SPU is in isolate state and cannot be context
104 * saved at this time.
106 isolate_state
= SPU_STATUS_ISOLATED_STATE
|
107 SPU_STATUS_ISOLATED_LOAD_STATUS
| SPU_STATUS_ISOLATED_EXIT_STATUS
;
108 return (in_be32(&prob
->spu_status_R
) & isolate_state
) ? 1 : 0;
111 static inline void disable_interrupts(struct spu_state
*csa
, struct spu
*spu
)
115 * Save INT_Mask_class0 in CSA.
116 * Write INT_MASK_class0 with value of 0.
117 * Save INT_Mask_class1 in CSA.
118 * Write INT_MASK_class1 with value of 0.
119 * Save INT_Mask_class2 in CSA.
120 * Write INT_MASK_class2 with value of 0.
121 * Synchronize all three interrupts to be sure
122 * we no longer execute a handler on another CPU.
124 spin_lock_irq(&spu
->register_lock
);
126 csa
->priv1
.int_mask_class0_RW
= spu_int_mask_get(spu
, 0);
127 csa
->priv1
.int_mask_class1_RW
= spu_int_mask_get(spu
, 1);
128 csa
->priv1
.int_mask_class2_RW
= spu_int_mask_get(spu
, 2);
130 spu_int_mask_set(spu
, 0, 0ul);
131 spu_int_mask_set(spu
, 1, 0ul);
132 spu_int_mask_set(spu
, 2, 0ul);
134 spin_unlock_irq(&spu
->register_lock
);
135 synchronize_irq(spu
->irqs
[0]);
136 synchronize_irq(spu
->irqs
[1]);
137 synchronize_irq(spu
->irqs
[2]);
140 static inline void set_watchdog_timer(struct spu_state
*csa
, struct spu
*spu
)
144 * Set a software watchdog timer, which specifies the
145 * maximum allowable time for a context save sequence.
147 * For present, this implementation will not set a global
148 * watchdog timer, as virtualization & variable system load
149 * may cause unpredictable execution times.
153 static inline void inhibit_user_access(struct spu_state
*csa
, struct spu
*spu
)
157 * Inhibit user-space access (if provided) to this
158 * SPU by unmapping the virtual pages assigned to
159 * the SPU memory-mapped I/O (MMIO) for problem
164 static inline void set_switch_pending(struct spu_state
*csa
, struct spu
*spu
)
168 * Set a software context switch pending flag.
170 set_bit(SPU_CONTEXT_SWITCH_PENDING
, &spu
->flags
);
174 static inline void save_mfc_cntl(struct spu_state
*csa
, struct spu
*spu
)
176 struct spu_priv2 __iomem
*priv2
= spu
->priv2
;
179 * Suspend DMA and save MFC_CNTL.
181 switch (in_be64(&priv2
->mfc_control_RW
) &
182 MFC_CNTL_SUSPEND_DMA_STATUS_MASK
) {
183 case MFC_CNTL_SUSPEND_IN_PROGRESS
:
184 POLL_WHILE_FALSE((in_be64(&priv2
->mfc_control_RW
) &
185 MFC_CNTL_SUSPEND_DMA_STATUS_MASK
) ==
186 MFC_CNTL_SUSPEND_COMPLETE
);
188 case MFC_CNTL_SUSPEND_COMPLETE
:
190 csa
->priv2
.mfc_control_RW
=
191 MFC_CNTL_SUSPEND_MASK
|
192 MFC_CNTL_SUSPEND_DMA_QUEUE
;
195 case MFC_CNTL_NORMAL_DMA_QUEUE_OPERATION
:
196 out_be64(&priv2
->mfc_control_RW
, MFC_CNTL_SUSPEND_DMA_QUEUE
);
197 POLL_WHILE_FALSE((in_be64(&priv2
->mfc_control_RW
) &
198 MFC_CNTL_SUSPEND_DMA_STATUS_MASK
) ==
199 MFC_CNTL_SUSPEND_COMPLETE
);
201 csa
->priv2
.mfc_control_RW
= 0;
207 static inline void save_spu_runcntl(struct spu_state
*csa
, struct spu
*spu
)
209 struct spu_problem __iomem
*prob
= spu
->problem
;
212 * Save SPU_Runcntl in the CSA. This value contains
213 * the "Application Desired State".
215 csa
->prob
.spu_runcntl_RW
= in_be32(&prob
->spu_runcntl_RW
);
218 static inline void save_mfc_sr1(struct spu_state
*csa
, struct spu
*spu
)
221 * Save MFC_SR1 in the CSA.
223 csa
->priv1
.mfc_sr1_RW
= spu_mfc_sr1_get(spu
);
226 static inline void save_spu_status(struct spu_state
*csa
, struct spu
*spu
)
228 struct spu_problem __iomem
*prob
= spu
->problem
;
231 * Read SPU_Status[R], and save to CSA.
233 if ((in_be32(&prob
->spu_status_R
) & SPU_STATUS_RUNNING
) == 0) {
234 csa
->prob
.spu_status_R
= in_be32(&prob
->spu_status_R
);
238 out_be32(&prob
->spu_runcntl_RW
, SPU_RUNCNTL_STOP
);
240 POLL_WHILE_TRUE(in_be32(&prob
->spu_status_R
) &
243 SPU_STATUS_INVALID_INSTR
| SPU_STATUS_SINGLE_STEP
|
244 SPU_STATUS_STOPPED_BY_HALT
| SPU_STATUS_STOPPED_BY_STOP
;
245 if ((in_be32(&prob
->spu_status_R
) & stopped
) == 0)
246 csa
->prob
.spu_status_R
= SPU_STATUS_RUNNING
;
248 csa
->prob
.spu_status_R
= in_be32(&prob
->spu_status_R
);
252 static inline void save_mfc_decr(struct spu_state
*csa
, struct spu
*spu
)
254 struct spu_priv2 __iomem
*priv2
= spu
->priv2
;
257 * Read MFC_CNTL[Ds]. Update saved copy of
260 csa
->priv2
.mfc_control_RW
|=
261 in_be64(&priv2
->mfc_control_RW
) & MFC_CNTL_DECREMENTER_RUNNING
;
264 static inline void halt_mfc_decr(struct spu_state
*csa
, struct spu
*spu
)
266 struct spu_priv2 __iomem
*priv2
= spu
->priv2
;
269 * Write MFC_CNTL[Dh] set to a '1' to halt
272 out_be64(&priv2
->mfc_control_RW
,
273 MFC_CNTL_DECREMENTER_HALTED
| MFC_CNTL_SUSPEND_MASK
);
277 static inline void save_timebase(struct spu_state
*csa
, struct spu
*spu
)
280 * Read PPE Timebase High and Timebase low registers
281 * and save in CSA. TBD.
283 csa
->suspend_time
= get_cycles();
286 static inline void remove_other_spu_access(struct spu_state
*csa
,
290 * Remove other SPU access to this SPU by unmapping
291 * this SPU's pages from their address space. TBD.
295 static inline void do_mfc_mssync(struct spu_state
*csa
, struct spu
*spu
)
297 struct spu_problem __iomem
*prob
= spu
->problem
;
301 * Write SPU_MSSync register. Poll SPU_MSSync[P]
304 out_be64(&prob
->spc_mssync_RW
, 1UL);
305 POLL_WHILE_TRUE(in_be64(&prob
->spc_mssync_RW
) & MS_SYNC_PENDING
);
308 static inline void issue_mfc_tlbie(struct spu_state
*csa
, struct spu
*spu
)
313 * Write TLB_Invalidate_Entry[IS,VPN,L,Lp]=0 register.
314 * Then issue a PPE sync instruction.
316 spu_tlb_invalidate(spu
);
320 static inline void handle_pending_interrupts(struct spu_state
*csa
,
324 * Handle any pending interrupts from this SPU
325 * here. This is OS or hypervisor specific. One
326 * option is to re-enable interrupts to handle any
327 * pending interrupts, with the interrupt handlers
328 * recognizing the software Context Switch Pending
329 * flag, to ensure the SPU execution or MFC command
330 * queue is not restarted. TBD.
334 static inline void save_mfc_queues(struct spu_state
*csa
, struct spu
*spu
)
336 struct spu_priv2 __iomem
*priv2
= spu
->priv2
;
340 * If MFC_Cntl[Se]=0 then save
341 * MFC command queues.
343 if ((in_be64(&priv2
->mfc_control_RW
) & MFC_CNTL_DMA_QUEUES_EMPTY
) == 0) {
344 for (i
= 0; i
< 8; i
++) {
345 csa
->priv2
.puq
[i
].mfc_cq_data0_RW
=
346 in_be64(&priv2
->puq
[i
].mfc_cq_data0_RW
);
347 csa
->priv2
.puq
[i
].mfc_cq_data1_RW
=
348 in_be64(&priv2
->puq
[i
].mfc_cq_data1_RW
);
349 csa
->priv2
.puq
[i
].mfc_cq_data2_RW
=
350 in_be64(&priv2
->puq
[i
].mfc_cq_data2_RW
);
351 csa
->priv2
.puq
[i
].mfc_cq_data3_RW
=
352 in_be64(&priv2
->puq
[i
].mfc_cq_data3_RW
);
354 for (i
= 0; i
< 16; i
++) {
355 csa
->priv2
.spuq
[i
].mfc_cq_data0_RW
=
356 in_be64(&priv2
->spuq
[i
].mfc_cq_data0_RW
);
357 csa
->priv2
.spuq
[i
].mfc_cq_data1_RW
=
358 in_be64(&priv2
->spuq
[i
].mfc_cq_data1_RW
);
359 csa
->priv2
.spuq
[i
].mfc_cq_data2_RW
=
360 in_be64(&priv2
->spuq
[i
].mfc_cq_data2_RW
);
361 csa
->priv2
.spuq
[i
].mfc_cq_data3_RW
=
362 in_be64(&priv2
->spuq
[i
].mfc_cq_data3_RW
);
367 static inline void save_ppu_querymask(struct spu_state
*csa
, struct spu
*spu
)
369 struct spu_problem __iomem
*prob
= spu
->problem
;
372 * Save the PPU_QueryMask register
375 csa
->prob
.dma_querymask_RW
= in_be32(&prob
->dma_querymask_RW
);
378 static inline void save_ppu_querytype(struct spu_state
*csa
, struct spu
*spu
)
380 struct spu_problem __iomem
*prob
= spu
->problem
;
383 * Save the PPU_QueryType register
386 csa
->prob
.dma_querytype_RW
= in_be32(&prob
->dma_querytype_RW
);
389 static inline void save_ppu_tagstatus(struct spu_state
*csa
, struct spu
*spu
)
391 struct spu_problem __iomem
*prob
= spu
->problem
;
393 /* Save the Prxy_TagStatus register in the CSA.
395 * It is unnecessary to restore dma_tagstatus_R, however,
396 * dma_tagstatus_R in the CSA is accessed via backing_ops, so
399 csa
->prob
.dma_tagstatus_R
= in_be32(&prob
->dma_tagstatus_R
);
402 static inline void save_mfc_csr_tsq(struct spu_state
*csa
, struct spu
*spu
)
404 struct spu_priv2 __iomem
*priv2
= spu
->priv2
;
407 * Save the MFC_CSR_TSQ register
410 csa
->priv2
.spu_tag_status_query_RW
=
411 in_be64(&priv2
->spu_tag_status_query_RW
);
414 static inline void save_mfc_csr_cmd(struct spu_state
*csa
, struct spu
*spu
)
416 struct spu_priv2 __iomem
*priv2
= spu
->priv2
;
419 * Save the MFC_CSR_CMD1 and MFC_CSR_CMD2
420 * registers in the CSA.
422 csa
->priv2
.spu_cmd_buf1_RW
= in_be64(&priv2
->spu_cmd_buf1_RW
);
423 csa
->priv2
.spu_cmd_buf2_RW
= in_be64(&priv2
->spu_cmd_buf2_RW
);
426 static inline void save_mfc_csr_ato(struct spu_state
*csa
, struct spu
*spu
)
428 struct spu_priv2 __iomem
*priv2
= spu
->priv2
;
431 * Save the MFC_CSR_ATO register in
434 csa
->priv2
.spu_atomic_status_RW
= in_be64(&priv2
->spu_atomic_status_RW
);
437 static inline void save_mfc_tclass_id(struct spu_state
*csa
, struct spu
*spu
)
440 * Save the MFC_TCLASS_ID register in
443 csa
->priv1
.mfc_tclass_id_RW
= spu_mfc_tclass_id_get(spu
);
446 static inline void set_mfc_tclass_id(struct spu_state
*csa
, struct spu
*spu
)
450 * Write the MFC_TCLASS_ID register with
451 * the value 0x10000000.
453 spu_mfc_tclass_id_set(spu
, 0x10000000);
457 static inline void purge_mfc_queue(struct spu_state
*csa
, struct spu
*spu
)
459 struct spu_priv2 __iomem
*priv2
= spu
->priv2
;
463 * Write MFC_CNTL[Pc]=1 (purge queue).
465 out_be64(&priv2
->mfc_control_RW
, MFC_CNTL_PURGE_DMA_REQUEST
);
469 static inline void wait_purge_complete(struct spu_state
*csa
, struct spu
*spu
)
471 struct spu_priv2 __iomem
*priv2
= spu
->priv2
;
474 * Poll MFC_CNTL[Ps] until value '11' is read
477 POLL_WHILE_FALSE((in_be64(&priv2
->mfc_control_RW
) &
478 MFC_CNTL_PURGE_DMA_STATUS_MASK
) ==
479 MFC_CNTL_PURGE_DMA_COMPLETE
);
482 static inline void setup_mfc_sr1(struct spu_state
*csa
, struct spu
*spu
)
486 * Write MFC_SR1 with MFC_SR1[D=0,S=1] and
487 * MFC_SR1[TL,R,Pr,T] set correctly for the
488 * OS specific environment.
490 * Implementation note: The SPU-side code
491 * for save/restore is privileged, so the
492 * MFC_SR1[Pr] bit is not set.
495 spu_mfc_sr1_set(spu
, (MFC_STATE1_MASTER_RUN_CONTROL_MASK
|
496 MFC_STATE1_RELOCATE_MASK
|
497 MFC_STATE1_BUS_TLBIE_MASK
));
500 static inline void save_spu_npc(struct spu_state
*csa
, struct spu
*spu
)
502 struct spu_problem __iomem
*prob
= spu
->problem
;
505 * Save SPU_NPC in the CSA.
507 csa
->prob
.spu_npc_RW
= in_be32(&prob
->spu_npc_RW
);
510 static inline void save_spu_privcntl(struct spu_state
*csa
, struct spu
*spu
)
512 struct spu_priv2 __iomem
*priv2
= spu
->priv2
;
515 * Save SPU_PrivCntl in the CSA.
517 csa
->priv2
.spu_privcntl_RW
= in_be64(&priv2
->spu_privcntl_RW
);
520 static inline void reset_spu_privcntl(struct spu_state
*csa
, struct spu
*spu
)
522 struct spu_priv2 __iomem
*priv2
= spu
->priv2
;
526 * Write SPU_PrivCntl[S,Le,A] fields reset to 0.
528 out_be64(&priv2
->spu_privcntl_RW
, 0UL);
532 static inline void save_spu_lslr(struct spu_state
*csa
, struct spu
*spu
)
534 struct spu_priv2 __iomem
*priv2
= spu
->priv2
;
537 * Save SPU_LSLR in the CSA.
539 csa
->priv2
.spu_lslr_RW
= in_be64(&priv2
->spu_lslr_RW
);
542 static inline void reset_spu_lslr(struct spu_state
*csa
, struct spu
*spu
)
544 struct spu_priv2 __iomem
*priv2
= spu
->priv2
;
550 out_be64(&priv2
->spu_lslr_RW
, LS_ADDR_MASK
);
554 static inline void save_spu_cfg(struct spu_state
*csa
, struct spu
*spu
)
556 struct spu_priv2 __iomem
*priv2
= spu
->priv2
;
559 * Save SPU_Cfg in the CSA.
561 csa
->priv2
.spu_cfg_RW
= in_be64(&priv2
->spu_cfg_RW
);
564 static inline void save_pm_trace(struct spu_state
*csa
, struct spu
*spu
)
567 * Save PM_Trace_Tag_Wait_Mask in the CSA.
568 * Not performed by this implementation.
572 static inline void save_mfc_rag(struct spu_state
*csa
, struct spu
*spu
)
575 * Save RA_GROUP_ID register and the
576 * RA_ENABLE reigster in the CSA.
578 csa
->priv1
.resource_allocation_groupID_RW
=
579 spu_resource_allocation_groupID_get(spu
);
580 csa
->priv1
.resource_allocation_enable_RW
=
581 spu_resource_allocation_enable_get(spu
);
584 static inline void save_ppu_mb_stat(struct spu_state
*csa
, struct spu
*spu
)
586 struct spu_problem __iomem
*prob
= spu
->problem
;
589 * Save MB_Stat register in the CSA.
591 csa
->prob
.mb_stat_R
= in_be32(&prob
->mb_stat_R
);
594 static inline void save_ppu_mb(struct spu_state
*csa
, struct spu
*spu
)
596 struct spu_problem __iomem
*prob
= spu
->problem
;
599 * Save the PPU_MB register in the CSA.
601 csa
->prob
.pu_mb_R
= in_be32(&prob
->pu_mb_R
);
604 static inline void save_ppuint_mb(struct spu_state
*csa
, struct spu
*spu
)
606 struct spu_priv2 __iomem
*priv2
= spu
->priv2
;
609 * Save the PPUINT_MB register in the CSA.
611 csa
->priv2
.puint_mb_R
= in_be64(&priv2
->puint_mb_R
);
614 static inline void save_ch_part1(struct spu_state
*csa
, struct spu
*spu
)
616 struct spu_priv2 __iomem
*priv2
= spu
->priv2
;
617 u64 idx
, ch_indices
[] = { 0UL, 3UL, 4UL, 24UL, 25UL, 27UL };
623 /* Save CH 1, without channel count */
624 out_be64(&priv2
->spu_chnlcntptr_RW
, 1);
625 csa
->spu_chnldata_RW
[1] = in_be64(&priv2
->spu_chnldata_RW
);
627 /* Save the following CH: [0,3,4,24,25,27] */
628 for (i
= 0; i
< ARRAY_SIZE(ch_indices
); i
++) {
630 out_be64(&priv2
->spu_chnlcntptr_RW
, idx
);
632 csa
->spu_chnldata_RW
[idx
] = in_be64(&priv2
->spu_chnldata_RW
);
633 csa
->spu_chnlcnt_RW
[idx
] = in_be64(&priv2
->spu_chnlcnt_RW
);
634 out_be64(&priv2
->spu_chnldata_RW
, 0UL);
635 out_be64(&priv2
->spu_chnlcnt_RW
, 0UL);
640 static inline void save_spu_mb(struct spu_state
*csa
, struct spu
*spu
)
642 struct spu_priv2 __iomem
*priv2
= spu
->priv2
;
646 * Save SPU Read Mailbox Channel.
648 out_be64(&priv2
->spu_chnlcntptr_RW
, 29UL);
650 csa
->spu_chnlcnt_RW
[29] = in_be64(&priv2
->spu_chnlcnt_RW
);
651 for (i
= 0; i
< 4; i
++) {
652 csa
->spu_mailbox_data
[i
] = in_be64(&priv2
->spu_chnldata_RW
);
654 out_be64(&priv2
->spu_chnlcnt_RW
, 0UL);
658 static inline void save_mfc_cmd(struct spu_state
*csa
, struct spu
*spu
)
660 struct spu_priv2 __iomem
*priv2
= spu
->priv2
;
663 * Save MFC_CMD Channel.
665 out_be64(&priv2
->spu_chnlcntptr_RW
, 21UL);
667 csa
->spu_chnlcnt_RW
[21] = in_be64(&priv2
->spu_chnlcnt_RW
);
671 static inline void reset_ch(struct spu_state
*csa
, struct spu
*spu
)
673 struct spu_priv2 __iomem
*priv2
= spu
->priv2
;
674 u64 ch_indices
[4] = { 21UL, 23UL, 28UL, 30UL };
675 u64 ch_counts
[4] = { 16UL, 1UL, 1UL, 1UL };
680 * Reset the following CH: [21, 23, 28, 30]
682 for (i
= 0; i
< 4; i
++) {
684 out_be64(&priv2
->spu_chnlcntptr_RW
, idx
);
686 out_be64(&priv2
->spu_chnlcnt_RW
, ch_counts
[i
]);
691 static inline void resume_mfc_queue(struct spu_state
*csa
, struct spu
*spu
)
693 struct spu_priv2 __iomem
*priv2
= spu
->priv2
;
697 * Write MFC_CNTL[Sc]=0 (resume queue processing).
699 out_be64(&priv2
->mfc_control_RW
, MFC_CNTL_RESUME_DMA_QUEUE
);
702 static inline void setup_mfc_slbs(struct spu_state
*csa
, struct spu
*spu
,
703 unsigned int *code
, int code_size
)
707 * If MFC_SR1[R]=1, write 0 to SLB_Invalidate_All
708 * register, then initialize SLB_VSID and SLB_ESID
709 * to provide access to SPU context save code and
712 * This implementation places both the context
713 * switch code and LSCSA in kernel address space.
715 * Further this implementation assumes that the
716 * MFC_SR1[R]=1 (in other words, assume that
717 * translation is desired by OS environment).
719 spu_invalidate_slbs(spu
);
720 spu_setup_kernel_slbs(spu
, csa
->lscsa
, code
, code_size
);
723 static inline void set_switch_active(struct spu_state
*csa
, struct spu
*spu
)
727 * Change the software context switch pending flag
728 * to context switch active.
730 * This implementation does not uses a switch active flag.
732 clear_bit(SPU_CONTEXT_SWITCH_PENDING
, &spu
->flags
);
736 static inline void enable_interrupts(struct spu_state
*csa
, struct spu
*spu
)
738 unsigned long class1_mask
= CLASS1_ENABLE_SEGMENT_FAULT_INTR
|
739 CLASS1_ENABLE_STORAGE_FAULT_INTR
;
743 * Reset and then enable interrupts, as
746 * This implementation enables only class1
747 * (translation) interrupts.
749 spin_lock_irq(&spu
->register_lock
);
750 spu_int_stat_clear(spu
, 0, CLASS0_INTR_MASK
);
751 spu_int_stat_clear(spu
, 1, CLASS1_INTR_MASK
);
752 spu_int_stat_clear(spu
, 2, CLASS2_INTR_MASK
);
753 spu_int_mask_set(spu
, 0, 0ul);
754 spu_int_mask_set(spu
, 1, class1_mask
);
755 spu_int_mask_set(spu
, 2, 0ul);
756 spin_unlock_irq(&spu
->register_lock
);
759 static inline int send_mfc_dma(struct spu
*spu
, unsigned long ea
,
760 unsigned int ls_offset
, unsigned int size
,
761 unsigned int tag
, unsigned int rclass
,
764 struct spu_problem __iomem
*prob
= spu
->problem
;
765 union mfc_tag_size_class_cmd command
;
766 unsigned int transfer_size
;
767 volatile unsigned int status
= 0x0;
771 (size
> MFC_MAX_DMA_SIZE
) ? MFC_MAX_DMA_SIZE
: size
;
772 command
.u
.mfc_size
= transfer_size
;
773 command
.u
.mfc_tag
= tag
;
774 command
.u
.mfc_rclassid
= rclass
;
775 command
.u
.mfc_cmd
= cmd
;
777 out_be32(&prob
->mfc_lsa_W
, ls_offset
);
778 out_be64(&prob
->mfc_ea_W
, ea
);
779 out_be64(&prob
->mfc_union_W
.all64
, command
.all64
);
781 in_be32(&prob
->mfc_union_W
.by32
.mfc_class_cmd32
);
782 if (unlikely(status
& 0x2)) {
785 } while (status
& 0x3);
786 size
-= transfer_size
;
788 ls_offset
+= transfer_size
;
793 static inline void save_ls_16kb(struct spu_state
*csa
, struct spu
*spu
)
795 unsigned long addr
= (unsigned long)&csa
->lscsa
->ls
[0];
796 unsigned int ls_offset
= 0x0;
797 unsigned int size
= 16384;
798 unsigned int tag
= 0;
799 unsigned int rclass
= 0;
800 unsigned int cmd
= MFC_PUT_CMD
;
803 * Issue a DMA command to copy the first 16K bytes
804 * of local storage to the CSA.
806 send_mfc_dma(spu
, addr
, ls_offset
, size
, tag
, rclass
, cmd
);
809 static inline void set_spu_npc(struct spu_state
*csa
, struct spu
*spu
)
811 struct spu_problem __iomem
*prob
= spu
->problem
;
815 * Write SPU_NPC[IE]=0 and SPU_NPC[LSA] to entry
816 * point address of context save code in local
819 * This implementation uses SPU-side save/restore
820 * programs with entry points at LSA of 0.
822 out_be32(&prob
->spu_npc_RW
, 0);
826 static inline void set_signot1(struct spu_state
*csa
, struct spu
*spu
)
828 struct spu_problem __iomem
*prob
= spu
->problem
;
836 * Write SPU_Sig_Notify_1 register with upper 32-bits
837 * of the CSA.LSCSA effective address.
839 addr64
.ull
= (u64
) csa
->lscsa
;
840 out_be32(&prob
->signal_notify1
, addr64
.ui
[0]);
844 static inline void set_signot2(struct spu_state
*csa
, struct spu
*spu
)
846 struct spu_problem __iomem
*prob
= spu
->problem
;
854 * Write SPU_Sig_Notify_2 register with lower 32-bits
855 * of the CSA.LSCSA effective address.
857 addr64
.ull
= (u64
) csa
->lscsa
;
858 out_be32(&prob
->signal_notify2
, addr64
.ui
[1]);
862 static inline void send_save_code(struct spu_state
*csa
, struct spu
*spu
)
864 unsigned long addr
= (unsigned long)&spu_save_code
[0];
865 unsigned int ls_offset
= 0x0;
866 unsigned int size
= sizeof(spu_save_code
);
867 unsigned int tag
= 0;
868 unsigned int rclass
= 0;
869 unsigned int cmd
= MFC_GETFS_CMD
;
872 * Issue a DMA command to copy context save code
873 * to local storage and start SPU.
875 send_mfc_dma(spu
, addr
, ls_offset
, size
, tag
, rclass
, cmd
);
878 static inline void set_ppu_querymask(struct spu_state
*csa
, struct spu
*spu
)
880 struct spu_problem __iomem
*prob
= spu
->problem
;
884 * Write PPU_QueryMask=1 (enable Tag Group 0)
885 * and issue eieio instruction.
887 out_be32(&prob
->dma_querymask_RW
, MFC_TAGID_TO_TAGMASK(0));
891 static inline void wait_tag_complete(struct spu_state
*csa
, struct spu
*spu
)
893 struct spu_problem __iomem
*prob
= spu
->problem
;
894 u32 mask
= MFC_TAGID_TO_TAGMASK(0);
901 * Poll PPU_TagStatus[gn] until 01 (Tag group 0 complete)
902 * or write PPU_QueryType[TS]=01 and wait for Tag Group
903 * Complete Interrupt. Write INT_Stat_Class0 or
904 * INT_Stat_Class2 with value of 'handled'.
906 POLL_WHILE_FALSE(in_be32(&prob
->dma_tagstatus_R
) & mask
);
908 local_irq_save(flags
);
909 spu_int_stat_clear(spu
, 0, CLASS0_INTR_MASK
);
910 spu_int_stat_clear(spu
, 2, CLASS2_INTR_MASK
);
911 local_irq_restore(flags
);
914 static inline void wait_spu_stopped(struct spu_state
*csa
, struct spu
*spu
)
916 struct spu_problem __iomem
*prob
= spu
->problem
;
921 * Poll until SPU_Status[R]=0 or wait for SPU Class 0
922 * or SPU Class 2 interrupt. Write INT_Stat_class0
923 * or INT_Stat_class2 with value of handled.
925 POLL_WHILE_TRUE(in_be32(&prob
->spu_status_R
) & SPU_STATUS_RUNNING
);
927 local_irq_save(flags
);
928 spu_int_stat_clear(spu
, 0, CLASS0_INTR_MASK
);
929 spu_int_stat_clear(spu
, 2, CLASS2_INTR_MASK
);
930 local_irq_restore(flags
);
933 static inline int check_save_status(struct spu_state
*csa
, struct spu
*spu
)
935 struct spu_problem __iomem
*prob
= spu
->problem
;
939 * If SPU_Status[P]=1 and SPU_Status[SC] = "success",
940 * context save succeeded, otherwise context save
943 complete
= ((SPU_SAVE_COMPLETE
<< SPU_STOP_STATUS_SHIFT
) |
944 SPU_STATUS_STOPPED_BY_STOP
);
945 return (in_be32(&prob
->spu_status_R
) != complete
) ? 1 : 0;
948 static inline void terminate_spu_app(struct spu_state
*csa
, struct spu
*spu
)
951 * If required, notify the "using application" that
952 * the SPU task has been terminated. TBD.
956 static inline void suspend_mfc_and_halt_decr(struct spu_state
*csa
,
959 struct spu_priv2 __iomem
*priv2
= spu
->priv2
;
962 * Write MFC_Cntl[Dh,Sc,Sm]='1','1','0' to suspend
963 * the queue and halt the decrementer.
965 out_be64(&priv2
->mfc_control_RW
, MFC_CNTL_SUSPEND_DMA_QUEUE
|
966 MFC_CNTL_DECREMENTER_HALTED
);
970 static inline void wait_suspend_mfc_complete(struct spu_state
*csa
,
973 struct spu_priv2 __iomem
*priv2
= spu
->priv2
;
977 * Poll MFC_CNTL[Ss] until 11 is returned.
979 POLL_WHILE_FALSE((in_be64(&priv2
->mfc_control_RW
) &
980 MFC_CNTL_SUSPEND_DMA_STATUS_MASK
) ==
981 MFC_CNTL_SUSPEND_COMPLETE
);
984 static inline int suspend_spe(struct spu_state
*csa
, struct spu
*spu
)
986 struct spu_problem __iomem
*prob
= spu
->problem
;
989 * If SPU_Status[R]=1, stop SPU execution
990 * and wait for stop to complete.
992 * Returns 1 if SPU_Status[R]=1 on entry.
995 if (in_be32(&prob
->spu_status_R
) & SPU_STATUS_RUNNING
) {
996 if (in_be32(&prob
->spu_status_R
) &
997 SPU_STATUS_ISOLATED_EXIT_STATUS
) {
998 POLL_WHILE_TRUE(in_be32(&prob
->spu_status_R
) &
1001 if ((in_be32(&prob
->spu_status_R
) &
1002 SPU_STATUS_ISOLATED_LOAD_STATUS
)
1003 || (in_be32(&prob
->spu_status_R
) &
1004 SPU_STATUS_ISOLATED_STATE
)) {
1005 out_be32(&prob
->spu_runcntl_RW
, SPU_RUNCNTL_STOP
);
1007 POLL_WHILE_TRUE(in_be32(&prob
->spu_status_R
) &
1008 SPU_STATUS_RUNNING
);
1009 out_be32(&prob
->spu_runcntl_RW
, 0x2);
1011 POLL_WHILE_TRUE(in_be32(&prob
->spu_status_R
) &
1012 SPU_STATUS_RUNNING
);
1014 if (in_be32(&prob
->spu_status_R
) &
1015 SPU_STATUS_WAITING_FOR_CHANNEL
) {
1016 out_be32(&prob
->spu_runcntl_RW
, SPU_RUNCNTL_STOP
);
1018 POLL_WHILE_TRUE(in_be32(&prob
->spu_status_R
) &
1019 SPU_STATUS_RUNNING
);
1026 static inline void clear_spu_status(struct spu_state
*csa
, struct spu
*spu
)
1028 struct spu_problem __iomem
*prob
= spu
->problem
;
1030 /* Restore, Step 10:
1031 * If SPU_Status[R]=0 and SPU_Status[E,L,IS]=1,
1032 * release SPU from isolate state.
1034 if (!(in_be32(&prob
->spu_status_R
) & SPU_STATUS_RUNNING
)) {
1035 if (in_be32(&prob
->spu_status_R
) &
1036 SPU_STATUS_ISOLATED_EXIT_STATUS
) {
1037 spu_mfc_sr1_set(spu
,
1038 MFC_STATE1_MASTER_RUN_CONTROL_MASK
);
1040 out_be32(&prob
->spu_runcntl_RW
, SPU_RUNCNTL_RUNNABLE
);
1042 POLL_WHILE_TRUE(in_be32(&prob
->spu_status_R
) &
1043 SPU_STATUS_RUNNING
);
1045 if ((in_be32(&prob
->spu_status_R
) &
1046 SPU_STATUS_ISOLATED_LOAD_STATUS
)
1047 || (in_be32(&prob
->spu_status_R
) &
1048 SPU_STATUS_ISOLATED_STATE
)) {
1049 spu_mfc_sr1_set(spu
,
1050 MFC_STATE1_MASTER_RUN_CONTROL_MASK
);
1052 out_be32(&prob
->spu_runcntl_RW
, 0x2);
1054 POLL_WHILE_TRUE(in_be32(&prob
->spu_status_R
) &
1055 SPU_STATUS_RUNNING
);
1060 static inline void reset_ch_part1(struct spu_state
*csa
, struct spu
*spu
)
1062 struct spu_priv2 __iomem
*priv2
= spu
->priv2
;
1063 u64 ch_indices
[] = { 0UL, 3UL, 4UL, 24UL, 25UL, 27UL };
1067 /* Restore, Step 20:
1071 out_be64(&priv2
->spu_chnlcntptr_RW
, 1);
1072 out_be64(&priv2
->spu_chnldata_RW
, 0UL);
1074 /* Reset the following CH: [0,3,4,24,25,27] */
1075 for (i
= 0; i
< ARRAY_SIZE(ch_indices
); i
++) {
1076 idx
= ch_indices
[i
];
1077 out_be64(&priv2
->spu_chnlcntptr_RW
, idx
);
1079 out_be64(&priv2
->spu_chnldata_RW
, 0UL);
1080 out_be64(&priv2
->spu_chnlcnt_RW
, 0UL);
1085 static inline void reset_ch_part2(struct spu_state
*csa
, struct spu
*spu
)
1087 struct spu_priv2 __iomem
*priv2
= spu
->priv2
;
1088 u64 ch_indices
[5] = { 21UL, 23UL, 28UL, 29UL, 30UL };
1089 u64 ch_counts
[5] = { 16UL, 1UL, 1UL, 0UL, 1UL };
1093 /* Restore, Step 21:
1094 * Reset the following CH: [21, 23, 28, 29, 30]
1096 for (i
= 0; i
< 5; i
++) {
1097 idx
= ch_indices
[i
];
1098 out_be64(&priv2
->spu_chnlcntptr_RW
, idx
);
1100 out_be64(&priv2
->spu_chnlcnt_RW
, ch_counts
[i
]);
1105 static inline void setup_spu_status_part1(struct spu_state
*csa
,
1108 u32 status_P
= SPU_STATUS_STOPPED_BY_STOP
;
1109 u32 status_I
= SPU_STATUS_INVALID_INSTR
;
1110 u32 status_H
= SPU_STATUS_STOPPED_BY_HALT
;
1111 u32 status_S
= SPU_STATUS_SINGLE_STEP
;
1112 u32 status_S_I
= SPU_STATUS_SINGLE_STEP
| SPU_STATUS_INVALID_INSTR
;
1113 u32 status_S_P
= SPU_STATUS_SINGLE_STEP
| SPU_STATUS_STOPPED_BY_STOP
;
1114 u32 status_P_H
= SPU_STATUS_STOPPED_BY_HALT
|SPU_STATUS_STOPPED_BY_STOP
;
1115 u32 status_P_I
= SPU_STATUS_STOPPED_BY_STOP
|SPU_STATUS_INVALID_INSTR
;
1118 /* Restore, Step 27:
1119 * If the CSA.SPU_Status[I,S,H,P]=1 then add the correct
1120 * instruction sequence to the end of the SPU based restore
1121 * code (after the "context restored" stop and signal) to
1122 * restore the correct SPU status.
1124 * NOTE: Rather than modifying the SPU executable, we
1125 * instead add a new 'stopped_status' field to the
1126 * LSCSA. The SPU-side restore reads this field and
1127 * takes the appropriate action when exiting.
1131 (csa
->prob
.spu_status_R
>> SPU_STOP_STATUS_SHIFT
) & 0xFFFF;
1132 if ((csa
->prob
.spu_status_R
& status_P_I
) == status_P_I
) {
1134 /* SPU_Status[P,I]=1 - Illegal Instruction followed
1135 * by Stop and Signal instruction, followed by 'br -4'.
1138 csa
->lscsa
->stopped_status
.slot
[0] = SPU_STOPPED_STATUS_P_I
;
1139 csa
->lscsa
->stopped_status
.slot
[1] = status_code
;
1141 } else if ((csa
->prob
.spu_status_R
& status_P_H
) == status_P_H
) {
1143 /* SPU_Status[P,H]=1 - Halt Conditional, followed
1144 * by Stop and Signal instruction, followed by
1147 csa
->lscsa
->stopped_status
.slot
[0] = SPU_STOPPED_STATUS_P_H
;
1148 csa
->lscsa
->stopped_status
.slot
[1] = status_code
;
1150 } else if ((csa
->prob
.spu_status_R
& status_S_P
) == status_S_P
) {
1152 /* SPU_Status[S,P]=1 - Stop and Signal instruction
1153 * followed by 'br -4'.
1155 csa
->lscsa
->stopped_status
.slot
[0] = SPU_STOPPED_STATUS_S_P
;
1156 csa
->lscsa
->stopped_status
.slot
[1] = status_code
;
1158 } else if ((csa
->prob
.spu_status_R
& status_S_I
) == status_S_I
) {
1160 /* SPU_Status[S,I]=1 - Illegal instruction followed
1163 csa
->lscsa
->stopped_status
.slot
[0] = SPU_STOPPED_STATUS_S_I
;
1164 csa
->lscsa
->stopped_status
.slot
[1] = status_code
;
1166 } else if ((csa
->prob
.spu_status_R
& status_P
) == status_P
) {
1168 /* SPU_Status[P]=1 - Stop and Signal instruction
1169 * followed by 'br -4'.
1171 csa
->lscsa
->stopped_status
.slot
[0] = SPU_STOPPED_STATUS_P
;
1172 csa
->lscsa
->stopped_status
.slot
[1] = status_code
;
1174 } else if ((csa
->prob
.spu_status_R
& status_H
) == status_H
) {
1176 /* SPU_Status[H]=1 - Halt Conditional, followed
1179 csa
->lscsa
->stopped_status
.slot
[0] = SPU_STOPPED_STATUS_H
;
1181 } else if ((csa
->prob
.spu_status_R
& status_S
) == status_S
) {
1183 /* SPU_Status[S]=1 - Two nop instructions.
1185 csa
->lscsa
->stopped_status
.slot
[0] = SPU_STOPPED_STATUS_S
;
1187 } else if ((csa
->prob
.spu_status_R
& status_I
) == status_I
) {
1189 /* SPU_Status[I]=1 - Illegal instruction followed
1192 csa
->lscsa
->stopped_status
.slot
[0] = SPU_STOPPED_STATUS_I
;
1197 static inline void setup_spu_status_part2(struct spu_state
*csa
,
1202 /* Restore, Step 28:
1203 * If the CSA.SPU_Status[I,S,H,P,R]=0 then
1204 * add a 'br *' instruction to the end of
1205 * the SPU based restore code.
1207 * NOTE: Rather than modifying the SPU executable, we
1208 * instead add a new 'stopped_status' field to the
1209 * LSCSA. The SPU-side restore reads this field and
1210 * takes the appropriate action when exiting.
1212 mask
= SPU_STATUS_INVALID_INSTR
|
1213 SPU_STATUS_SINGLE_STEP
|
1214 SPU_STATUS_STOPPED_BY_HALT
|
1215 SPU_STATUS_STOPPED_BY_STOP
| SPU_STATUS_RUNNING
;
1216 if (!(csa
->prob
.spu_status_R
& mask
)) {
1217 csa
->lscsa
->stopped_status
.slot
[0] = SPU_STOPPED_STATUS_R
;
1221 static inline void restore_mfc_rag(struct spu_state
*csa
, struct spu
*spu
)
1223 /* Restore, Step 29:
1224 * Restore RA_GROUP_ID register and the
1225 * RA_ENABLE reigster from the CSA.
1227 spu_resource_allocation_groupID_set(spu
,
1228 csa
->priv1
.resource_allocation_groupID_RW
);
1229 spu_resource_allocation_enable_set(spu
,
1230 csa
->priv1
.resource_allocation_enable_RW
);
1233 static inline void send_restore_code(struct spu_state
*csa
, struct spu
*spu
)
1235 unsigned long addr
= (unsigned long)&spu_restore_code
[0];
1236 unsigned int ls_offset
= 0x0;
1237 unsigned int size
= sizeof(spu_restore_code
);
1238 unsigned int tag
= 0;
1239 unsigned int rclass
= 0;
1240 unsigned int cmd
= MFC_GETFS_CMD
;
1242 /* Restore, Step 37:
1243 * Issue MFC DMA command to copy context
1244 * restore code to local storage.
1246 send_mfc_dma(spu
, addr
, ls_offset
, size
, tag
, rclass
, cmd
);
1249 static inline void setup_decr(struct spu_state
*csa
, struct spu
*spu
)
1251 /* Restore, Step 34:
1252 * If CSA.MFC_CNTL[Ds]=1 (decrementer was
1253 * running) then adjust decrementer, set
1254 * decrementer running status in LSCSA,
1255 * and set decrementer "wrapped" status
1258 if (csa
->priv2
.mfc_control_RW
& MFC_CNTL_DECREMENTER_RUNNING
) {
1259 cycles_t resume_time
= get_cycles();
1260 cycles_t delta_time
= resume_time
- csa
->suspend_time
;
1262 csa
->lscsa
->decr_status
.slot
[0] = SPU_DECR_STATUS_RUNNING
;
1263 if (csa
->lscsa
->decr
.slot
[0] < delta_time
) {
1264 csa
->lscsa
->decr_status
.slot
[0] |=
1265 SPU_DECR_STATUS_WRAPPED
;
1268 csa
->lscsa
->decr
.slot
[0] -= delta_time
;
1270 csa
->lscsa
->decr_status
.slot
[0] = 0;
1274 static inline void setup_ppu_mb(struct spu_state
*csa
, struct spu
*spu
)
1276 /* Restore, Step 35:
1277 * Copy the CSA.PU_MB data into the LSCSA.
1279 csa
->lscsa
->ppu_mb
.slot
[0] = csa
->prob
.pu_mb_R
;
1282 static inline void setup_ppuint_mb(struct spu_state
*csa
, struct spu
*spu
)
1284 /* Restore, Step 36:
1285 * Copy the CSA.PUINT_MB data into the LSCSA.
1287 csa
->lscsa
->ppuint_mb
.slot
[0] = csa
->priv2
.puint_mb_R
;
1290 static inline int check_restore_status(struct spu_state
*csa
, struct spu
*spu
)
1292 struct spu_problem __iomem
*prob
= spu
->problem
;
1295 /* Restore, Step 40:
1296 * If SPU_Status[P]=1 and SPU_Status[SC] = "success",
1297 * context restore succeeded, otherwise context restore
1300 complete
= ((SPU_RESTORE_COMPLETE
<< SPU_STOP_STATUS_SHIFT
) |
1301 SPU_STATUS_STOPPED_BY_STOP
);
1302 return (in_be32(&prob
->spu_status_R
) != complete
) ? 1 : 0;
1305 static inline void restore_spu_privcntl(struct spu_state
*csa
, struct spu
*spu
)
1307 struct spu_priv2 __iomem
*priv2
= spu
->priv2
;
1309 /* Restore, Step 41:
1310 * Restore SPU_PrivCntl from the CSA.
1312 out_be64(&priv2
->spu_privcntl_RW
, csa
->priv2
.spu_privcntl_RW
);
1316 static inline void restore_status_part1(struct spu_state
*csa
, struct spu
*spu
)
1318 struct spu_problem __iomem
*prob
= spu
->problem
;
1321 /* Restore, Step 42:
1322 * If any CSA.SPU_Status[I,S,H,P]=1, then
1323 * restore the error or single step state.
1325 mask
= SPU_STATUS_INVALID_INSTR
|
1326 SPU_STATUS_SINGLE_STEP
|
1327 SPU_STATUS_STOPPED_BY_HALT
| SPU_STATUS_STOPPED_BY_STOP
;
1328 if (csa
->prob
.spu_status_R
& mask
) {
1329 out_be32(&prob
->spu_runcntl_RW
, SPU_RUNCNTL_RUNNABLE
);
1331 POLL_WHILE_TRUE(in_be32(&prob
->spu_status_R
) &
1332 SPU_STATUS_RUNNING
);
1336 static inline void restore_status_part2(struct spu_state
*csa
, struct spu
*spu
)
1338 struct spu_problem __iomem
*prob
= spu
->problem
;
1341 /* Restore, Step 43:
1342 * If all CSA.SPU_Status[I,S,H,P,R]=0 then write
1343 * SPU_RunCntl[R0R1]='01', wait for SPU_Status[R]=1,
1344 * then write '00' to SPU_RunCntl[R0R1] and wait
1345 * for SPU_Status[R]=0.
1347 mask
= SPU_STATUS_INVALID_INSTR
|
1348 SPU_STATUS_SINGLE_STEP
|
1349 SPU_STATUS_STOPPED_BY_HALT
|
1350 SPU_STATUS_STOPPED_BY_STOP
| SPU_STATUS_RUNNING
;
1351 if (!(csa
->prob
.spu_status_R
& mask
)) {
1352 out_be32(&prob
->spu_runcntl_RW
, SPU_RUNCNTL_RUNNABLE
);
1354 POLL_WHILE_FALSE(in_be32(&prob
->spu_status_R
) &
1355 SPU_STATUS_RUNNING
);
1356 out_be32(&prob
->spu_runcntl_RW
, SPU_RUNCNTL_STOP
);
1358 POLL_WHILE_TRUE(in_be32(&prob
->spu_status_R
) &
1359 SPU_STATUS_RUNNING
);
1363 static inline void restore_ls_16kb(struct spu_state
*csa
, struct spu
*spu
)
1365 unsigned long addr
= (unsigned long)&csa
->lscsa
->ls
[0];
1366 unsigned int ls_offset
= 0x0;
1367 unsigned int size
= 16384;
1368 unsigned int tag
= 0;
1369 unsigned int rclass
= 0;
1370 unsigned int cmd
= MFC_GET_CMD
;
1372 /* Restore, Step 44:
1373 * Issue a DMA command to restore the first
1374 * 16kb of local storage from CSA.
1376 send_mfc_dma(spu
, addr
, ls_offset
, size
, tag
, rclass
, cmd
);
1379 static inline void suspend_mfc(struct spu_state
*csa
, struct spu
*spu
)
1381 struct spu_priv2 __iomem
*priv2
= spu
->priv2
;
1383 /* Restore, Step 47.
1384 * Write MFC_Cntl[Sc,Sm]='1','0' to suspend
1387 out_be64(&priv2
->mfc_control_RW
, MFC_CNTL_SUSPEND_DMA_QUEUE
);
1391 static inline void clear_interrupts(struct spu_state
*csa
, struct spu
*spu
)
1393 /* Restore, Step 49:
1394 * Write INT_MASK_class0 with value of 0.
1395 * Write INT_MASK_class1 with value of 0.
1396 * Write INT_MASK_class2 with value of 0.
1397 * Write INT_STAT_class0 with value of -1.
1398 * Write INT_STAT_class1 with value of -1.
1399 * Write INT_STAT_class2 with value of -1.
1401 spin_lock_irq(&spu
->register_lock
);
1402 spu_int_mask_set(spu
, 0, 0ul);
1403 spu_int_mask_set(spu
, 1, 0ul);
1404 spu_int_mask_set(spu
, 2, 0ul);
1405 spu_int_stat_clear(spu
, 0, CLASS0_INTR_MASK
);
1406 spu_int_stat_clear(spu
, 1, CLASS1_INTR_MASK
);
1407 spu_int_stat_clear(spu
, 2, CLASS2_INTR_MASK
);
1408 spin_unlock_irq(&spu
->register_lock
);
1411 static inline void restore_mfc_queues(struct spu_state
*csa
, struct spu
*spu
)
1413 struct spu_priv2 __iomem
*priv2
= spu
->priv2
;
1416 /* Restore, Step 50:
1417 * If MFC_Cntl[Se]!=0 then restore
1418 * MFC command queues.
1420 if ((csa
->priv2
.mfc_control_RW
& MFC_CNTL_DMA_QUEUES_EMPTY_MASK
) == 0) {
1421 for (i
= 0; i
< 8; i
++) {
1422 out_be64(&priv2
->puq
[i
].mfc_cq_data0_RW
,
1423 csa
->priv2
.puq
[i
].mfc_cq_data0_RW
);
1424 out_be64(&priv2
->puq
[i
].mfc_cq_data1_RW
,
1425 csa
->priv2
.puq
[i
].mfc_cq_data1_RW
);
1426 out_be64(&priv2
->puq
[i
].mfc_cq_data2_RW
,
1427 csa
->priv2
.puq
[i
].mfc_cq_data2_RW
);
1428 out_be64(&priv2
->puq
[i
].mfc_cq_data3_RW
,
1429 csa
->priv2
.puq
[i
].mfc_cq_data3_RW
);
1431 for (i
= 0; i
< 16; i
++) {
1432 out_be64(&priv2
->spuq
[i
].mfc_cq_data0_RW
,
1433 csa
->priv2
.spuq
[i
].mfc_cq_data0_RW
);
1434 out_be64(&priv2
->spuq
[i
].mfc_cq_data1_RW
,
1435 csa
->priv2
.spuq
[i
].mfc_cq_data1_RW
);
1436 out_be64(&priv2
->spuq
[i
].mfc_cq_data2_RW
,
1437 csa
->priv2
.spuq
[i
].mfc_cq_data2_RW
);
1438 out_be64(&priv2
->spuq
[i
].mfc_cq_data3_RW
,
1439 csa
->priv2
.spuq
[i
].mfc_cq_data3_RW
);
1445 static inline void restore_ppu_querymask(struct spu_state
*csa
, struct spu
*spu
)
1447 struct spu_problem __iomem
*prob
= spu
->problem
;
1449 /* Restore, Step 51:
1450 * Restore the PPU_QueryMask register from CSA.
1452 out_be32(&prob
->dma_querymask_RW
, csa
->prob
.dma_querymask_RW
);
1456 static inline void restore_ppu_querytype(struct spu_state
*csa
, struct spu
*spu
)
1458 struct spu_problem __iomem
*prob
= spu
->problem
;
1460 /* Restore, Step 52:
1461 * Restore the PPU_QueryType register from CSA.
1463 out_be32(&prob
->dma_querytype_RW
, csa
->prob
.dma_querytype_RW
);
1467 static inline void restore_mfc_csr_tsq(struct spu_state
*csa
, struct spu
*spu
)
1469 struct spu_priv2 __iomem
*priv2
= spu
->priv2
;
1471 /* Restore, Step 53:
1472 * Restore the MFC_CSR_TSQ register from CSA.
1474 out_be64(&priv2
->spu_tag_status_query_RW
,
1475 csa
->priv2
.spu_tag_status_query_RW
);
1479 static inline void restore_mfc_csr_cmd(struct spu_state
*csa
, struct spu
*spu
)
1481 struct spu_priv2 __iomem
*priv2
= spu
->priv2
;
1483 /* Restore, Step 54:
1484 * Restore the MFC_CSR_CMD1 and MFC_CSR_CMD2
1485 * registers from CSA.
1487 out_be64(&priv2
->spu_cmd_buf1_RW
, csa
->priv2
.spu_cmd_buf1_RW
);
1488 out_be64(&priv2
->spu_cmd_buf2_RW
, csa
->priv2
.spu_cmd_buf2_RW
);
1492 static inline void restore_mfc_csr_ato(struct spu_state
*csa
, struct spu
*spu
)
1494 struct spu_priv2 __iomem
*priv2
= spu
->priv2
;
1496 /* Restore, Step 55:
1497 * Restore the MFC_CSR_ATO register from CSA.
1499 out_be64(&priv2
->spu_atomic_status_RW
, csa
->priv2
.spu_atomic_status_RW
);
1502 static inline void restore_mfc_tclass_id(struct spu_state
*csa
, struct spu
*spu
)
1504 /* Restore, Step 56:
1505 * Restore the MFC_TCLASS_ID register from CSA.
1507 spu_mfc_tclass_id_set(spu
, csa
->priv1
.mfc_tclass_id_RW
);
1511 static inline void set_llr_event(struct spu_state
*csa
, struct spu
*spu
)
1513 u64 ch0_cnt
, ch0_data
;
1516 /* Restore, Step 57:
1517 * Set the Lock Line Reservation Lost Event by:
1518 * 1. OR CSA.SPU_Event_Status with bit 21 (Lr) set to 1.
1519 * 2. If CSA.SPU_Channel_0_Count=0 and
1520 * CSA.SPU_Wr_Event_Mask[Lr]=1 and
1521 * CSA.SPU_Event_Status[Lr]=0 then set
1522 * CSA.SPU_Event_Status_Count=1.
1524 ch0_cnt
= csa
->spu_chnlcnt_RW
[0];
1525 ch0_data
= csa
->spu_chnldata_RW
[0];
1526 ch1_data
= csa
->spu_chnldata_RW
[1];
1527 csa
->spu_chnldata_RW
[0] |= MFC_LLR_LOST_EVENT
;
1528 if ((ch0_cnt
== 0) && !(ch0_data
& MFC_LLR_LOST_EVENT
) &&
1529 (ch1_data
& MFC_LLR_LOST_EVENT
)) {
1530 csa
->spu_chnlcnt_RW
[0] = 1;
1534 static inline void restore_decr_wrapped(struct spu_state
*csa
, struct spu
*spu
)
1536 /* Restore, Step 58:
1537 * If the status of the CSA software decrementer
1538 * "wrapped" flag is set, OR in a '1' to
1539 * CSA.SPU_Event_Status[Tm].
1541 if (!(csa
->lscsa
->decr_status
.slot
[0] & SPU_DECR_STATUS_WRAPPED
))
1544 if ((csa
->spu_chnlcnt_RW
[0] == 0) &&
1545 (csa
->spu_chnldata_RW
[1] & 0x20) &&
1546 !(csa
->spu_chnldata_RW
[0] & 0x20))
1547 csa
->spu_chnlcnt_RW
[0] = 1;
1549 csa
->spu_chnldata_RW
[0] |= 0x20;
1552 static inline void restore_ch_part1(struct spu_state
*csa
, struct spu
*spu
)
1554 struct spu_priv2 __iomem
*priv2
= spu
->priv2
;
1555 u64 idx
, ch_indices
[] = { 0UL, 3UL, 4UL, 24UL, 25UL, 27UL };
1558 /* Restore, Step 59:
1559 * Restore the following CH: [0,3,4,24,25,27]
1561 for (i
= 0; i
< ARRAY_SIZE(ch_indices
); i
++) {
1562 idx
= ch_indices
[i
];
1563 out_be64(&priv2
->spu_chnlcntptr_RW
, idx
);
1565 out_be64(&priv2
->spu_chnldata_RW
, csa
->spu_chnldata_RW
[idx
]);
1566 out_be64(&priv2
->spu_chnlcnt_RW
, csa
->spu_chnlcnt_RW
[idx
]);
1571 static inline void restore_ch_part2(struct spu_state
*csa
, struct spu
*spu
)
1573 struct spu_priv2 __iomem
*priv2
= spu
->priv2
;
1574 u64 ch_indices
[3] = { 9UL, 21UL, 23UL };
1575 u64 ch_counts
[3] = { 1UL, 16UL, 1UL };
1579 /* Restore, Step 60:
1580 * Restore the following CH: [9,21,23].
1583 ch_counts
[1] = csa
->spu_chnlcnt_RW
[21];
1585 for (i
= 0; i
< 3; i
++) {
1586 idx
= ch_indices
[i
];
1587 out_be64(&priv2
->spu_chnlcntptr_RW
, idx
);
1589 out_be64(&priv2
->spu_chnlcnt_RW
, ch_counts
[i
]);
1594 static inline void restore_spu_lslr(struct spu_state
*csa
, struct spu
*spu
)
1596 struct spu_priv2 __iomem
*priv2
= spu
->priv2
;
1598 /* Restore, Step 61:
1599 * Restore the SPU_LSLR register from CSA.
1601 out_be64(&priv2
->spu_lslr_RW
, csa
->priv2
.spu_lslr_RW
);
1605 static inline void restore_spu_cfg(struct spu_state
*csa
, struct spu
*spu
)
1607 struct spu_priv2 __iomem
*priv2
= spu
->priv2
;
1609 /* Restore, Step 62:
1610 * Restore the SPU_Cfg register from CSA.
1612 out_be64(&priv2
->spu_cfg_RW
, csa
->priv2
.spu_cfg_RW
);
1616 static inline void restore_pm_trace(struct spu_state
*csa
, struct spu
*spu
)
1618 /* Restore, Step 63:
1619 * Restore PM_Trace_Tag_Wait_Mask from CSA.
1620 * Not performed by this implementation.
1624 static inline void restore_spu_npc(struct spu_state
*csa
, struct spu
*spu
)
1626 struct spu_problem __iomem
*prob
= spu
->problem
;
1628 /* Restore, Step 64:
1629 * Restore SPU_NPC from CSA.
1631 out_be32(&prob
->spu_npc_RW
, csa
->prob
.spu_npc_RW
);
1635 static inline void restore_spu_mb(struct spu_state
*csa
, struct spu
*spu
)
1637 struct spu_priv2 __iomem
*priv2
= spu
->priv2
;
1640 /* Restore, Step 65:
1641 * Restore MFC_RdSPU_MB from CSA.
1643 out_be64(&priv2
->spu_chnlcntptr_RW
, 29UL);
1645 out_be64(&priv2
->spu_chnlcnt_RW
, csa
->spu_chnlcnt_RW
[29]);
1646 for (i
= 0; i
< 4; i
++) {
1647 out_be64(&priv2
->spu_chnldata_RW
, csa
->spu_mailbox_data
[i
]);
1652 static inline void check_ppu_mb_stat(struct spu_state
*csa
, struct spu
*spu
)
1654 struct spu_problem __iomem
*prob
= spu
->problem
;
1657 /* Restore, Step 66:
1658 * If CSA.MB_Stat[P]=0 (mailbox empty) then
1659 * read from the PPU_MB register.
1661 if ((csa
->prob
.mb_stat_R
& 0xFF) == 0) {
1662 dummy
= in_be32(&prob
->pu_mb_R
);
1667 static inline void check_ppuint_mb_stat(struct spu_state
*csa
, struct spu
*spu
)
1669 struct spu_priv2 __iomem
*priv2
= spu
->priv2
;
1672 /* Restore, Step 66:
1673 * If CSA.MB_Stat[I]=0 (mailbox empty) then
1674 * read from the PPUINT_MB register.
1676 if ((csa
->prob
.mb_stat_R
& 0xFF0000) == 0) {
1677 dummy
= in_be64(&priv2
->puint_mb_R
);
1679 spu_int_stat_clear(spu
, 2, CLASS2_ENABLE_MAILBOX_INTR
);
1684 static inline void restore_mfc_sr1(struct spu_state
*csa
, struct spu
*spu
)
1686 /* Restore, Step 69:
1687 * Restore the MFC_SR1 register from CSA.
1689 spu_mfc_sr1_set(spu
, csa
->priv1
.mfc_sr1_RW
);
1693 static inline void restore_other_spu_access(struct spu_state
*csa
,
1696 /* Restore, Step 70:
1697 * Restore other SPU mappings to this SPU. TBD.
1701 static inline void restore_spu_runcntl(struct spu_state
*csa
, struct spu
*spu
)
1703 struct spu_problem __iomem
*prob
= spu
->problem
;
1705 /* Restore, Step 71:
1706 * If CSA.SPU_Status[R]=1 then write
1707 * SPU_RunCntl[R0R1]='01'.
1709 if (csa
->prob
.spu_status_R
& SPU_STATUS_RUNNING
) {
1710 out_be32(&prob
->spu_runcntl_RW
, SPU_RUNCNTL_RUNNABLE
);
1715 static inline void restore_mfc_cntl(struct spu_state
*csa
, struct spu
*spu
)
1717 struct spu_priv2 __iomem
*priv2
= spu
->priv2
;
1719 /* Restore, Step 72:
1720 * Restore the MFC_CNTL register for the CSA.
1722 out_be64(&priv2
->mfc_control_RW
, csa
->priv2
.mfc_control_RW
);
1725 * FIXME: this is to restart a DMA that we were processing
1726 * before the save. better remember the fault information
1727 * in the csa instead.
1729 if ((csa
->priv2
.mfc_control_RW
& MFC_CNTL_SUSPEND_DMA_QUEUE_MASK
)) {
1730 out_be64(&priv2
->mfc_control_RW
, MFC_CNTL_RESTART_DMA_COMMAND
);
1735 static inline void enable_user_access(struct spu_state
*csa
, struct spu
*spu
)
1737 /* Restore, Step 73:
1738 * Enable user-space access (if provided) to this
1739 * SPU by mapping the virtual pages assigned to
1740 * the SPU memory-mapped I/O (MMIO) for problem
1745 static inline void reset_switch_active(struct spu_state
*csa
, struct spu
*spu
)
1747 /* Restore, Step 74:
1748 * Reset the "context switch active" flag.
1749 * Not performed by this implementation.
1753 static inline void reenable_interrupts(struct spu_state
*csa
, struct spu
*spu
)
1755 /* Restore, Step 75:
1756 * Re-enable SPU interrupts.
1758 spin_lock_irq(&spu
->register_lock
);
1759 spu_int_mask_set(spu
, 0, csa
->priv1
.int_mask_class0_RW
);
1760 spu_int_mask_set(spu
, 1, csa
->priv1
.int_mask_class1_RW
);
1761 spu_int_mask_set(spu
, 2, csa
->priv1
.int_mask_class2_RW
);
1762 spin_unlock_irq(&spu
->register_lock
);
1765 static int quiece_spu(struct spu_state
*prev
, struct spu
*spu
)
1768 * Combined steps 2-18 of SPU context save sequence, which
1769 * quiesce the SPU state (disable SPU execution, MFC command
1770 * queues, decrementer, SPU interrupts, etc.).
1772 * Returns 0 on success.
1773 * 2 if failed step 2.
1774 * 6 if failed step 6.
1777 if (check_spu_isolate(prev
, spu
)) { /* Step 2. */
1780 disable_interrupts(prev
, spu
); /* Step 3. */
1781 set_watchdog_timer(prev
, spu
); /* Step 4. */
1782 inhibit_user_access(prev
, spu
); /* Step 5. */
1783 if (check_spu_isolate(prev
, spu
)) { /* Step 6. */
1786 set_switch_pending(prev
, spu
); /* Step 7. */
1787 save_mfc_cntl(prev
, spu
); /* Step 8. */
1788 save_spu_runcntl(prev
, spu
); /* Step 9. */
1789 save_mfc_sr1(prev
, spu
); /* Step 10. */
1790 save_spu_status(prev
, spu
); /* Step 11. */
1791 save_mfc_decr(prev
, spu
); /* Step 12. */
1792 halt_mfc_decr(prev
, spu
); /* Step 13. */
1793 save_timebase(prev
, spu
); /* Step 14. */
1794 remove_other_spu_access(prev
, spu
); /* Step 15. */
1795 do_mfc_mssync(prev
, spu
); /* Step 16. */
1796 issue_mfc_tlbie(prev
, spu
); /* Step 17. */
1797 handle_pending_interrupts(prev
, spu
); /* Step 18. */
1802 static void save_csa(struct spu_state
*prev
, struct spu
*spu
)
1805 * Combine steps 19-44 of SPU context save sequence, which
1806 * save regions of the privileged & problem state areas.
1809 save_mfc_queues(prev
, spu
); /* Step 19. */
1810 save_ppu_querymask(prev
, spu
); /* Step 20. */
1811 save_ppu_querytype(prev
, spu
); /* Step 21. */
1812 save_ppu_tagstatus(prev
, spu
); /* NEW. */
1813 save_mfc_csr_tsq(prev
, spu
); /* Step 22. */
1814 save_mfc_csr_cmd(prev
, spu
); /* Step 23. */
1815 save_mfc_csr_ato(prev
, spu
); /* Step 24. */
1816 save_mfc_tclass_id(prev
, spu
); /* Step 25. */
1817 set_mfc_tclass_id(prev
, spu
); /* Step 26. */
1818 purge_mfc_queue(prev
, spu
); /* Step 27. */
1819 wait_purge_complete(prev
, spu
); /* Step 28. */
1820 setup_mfc_sr1(prev
, spu
); /* Step 30. */
1821 save_spu_npc(prev
, spu
); /* Step 31. */
1822 save_spu_privcntl(prev
, spu
); /* Step 32. */
1823 reset_spu_privcntl(prev
, spu
); /* Step 33. */
1824 save_spu_lslr(prev
, spu
); /* Step 34. */
1825 reset_spu_lslr(prev
, spu
); /* Step 35. */
1826 save_spu_cfg(prev
, spu
); /* Step 36. */
1827 save_pm_trace(prev
, spu
); /* Step 37. */
1828 save_mfc_rag(prev
, spu
); /* Step 38. */
1829 save_ppu_mb_stat(prev
, spu
); /* Step 39. */
1830 save_ppu_mb(prev
, spu
); /* Step 40. */
1831 save_ppuint_mb(prev
, spu
); /* Step 41. */
1832 save_ch_part1(prev
, spu
); /* Step 42. */
1833 save_spu_mb(prev
, spu
); /* Step 43. */
1834 save_mfc_cmd(prev
, spu
); /* Step 44. */
1835 reset_ch(prev
, spu
); /* Step 45. */
1838 static void save_lscsa(struct spu_state
*prev
, struct spu
*spu
)
1841 * Perform steps 46-57 of SPU context save sequence,
1842 * which save regions of the local store and register
1846 resume_mfc_queue(prev
, spu
); /* Step 46. */
1848 setup_mfc_slbs(prev
, spu
, spu_save_code
, sizeof(spu_save_code
));
1849 set_switch_active(prev
, spu
); /* Step 48. */
1850 enable_interrupts(prev
, spu
); /* Step 49. */
1851 save_ls_16kb(prev
, spu
); /* Step 50. */
1852 set_spu_npc(prev
, spu
); /* Step 51. */
1853 set_signot1(prev
, spu
); /* Step 52. */
1854 set_signot2(prev
, spu
); /* Step 53. */
1855 send_save_code(prev
, spu
); /* Step 54. */
1856 set_ppu_querymask(prev
, spu
); /* Step 55. */
1857 wait_tag_complete(prev
, spu
); /* Step 56. */
1858 wait_spu_stopped(prev
, spu
); /* Step 57. */
1861 static void force_spu_isolate_exit(struct spu
*spu
)
1863 struct spu_problem __iomem
*prob
= spu
->problem
;
1864 struct spu_priv2 __iomem
*priv2
= spu
->priv2
;
1866 /* Stop SPE execution and wait for completion. */
1867 out_be32(&prob
->spu_runcntl_RW
, SPU_RUNCNTL_STOP
);
1869 POLL_WHILE_TRUE(in_be32(&prob
->spu_status_R
) & SPU_STATUS_RUNNING
);
1871 /* Restart SPE master runcntl. */
1872 spu_mfc_sr1_set(spu
, MFC_STATE1_MASTER_RUN_CONTROL_MASK
);
1875 /* Initiate isolate exit request and wait for completion. */
1876 out_be64(&priv2
->spu_privcntl_RW
, 4LL);
1878 out_be32(&prob
->spu_runcntl_RW
, 2);
1880 POLL_WHILE_FALSE((in_be32(&prob
->spu_status_R
)
1881 & SPU_STATUS_STOPPED_BY_STOP
));
1883 /* Reset load request to normal. */
1884 out_be64(&priv2
->spu_privcntl_RW
, SPU_PRIVCNT_LOAD_REQUEST_NORMAL
);
1890 * Check SPU run-control state and force isolated
1891 * exit function as necessary.
1893 static void stop_spu_isolate(struct spu
*spu
)
1895 struct spu_problem __iomem
*prob
= spu
->problem
;
1897 if (in_be32(&prob
->spu_status_R
) & SPU_STATUS_ISOLATED_STATE
) {
1898 /* The SPU is in isolated state; the only way
1899 * to get it out is to perform an isolated
1900 * exit (clean) operation.
1902 force_spu_isolate_exit(spu
);
1906 static void harvest(struct spu_state
*prev
, struct spu
*spu
)
1909 * Perform steps 2-25 of SPU context restore sequence,
1910 * which resets an SPU either after a failed save, or
1911 * when using SPU for first time.
1914 disable_interrupts(prev
, spu
); /* Step 2. */
1915 inhibit_user_access(prev
, spu
); /* Step 3. */
1916 terminate_spu_app(prev
, spu
); /* Step 4. */
1917 set_switch_pending(prev
, spu
); /* Step 5. */
1918 stop_spu_isolate(spu
); /* NEW. */
1919 remove_other_spu_access(prev
, spu
); /* Step 6. */
1920 suspend_mfc_and_halt_decr(prev
, spu
); /* Step 7. */
1921 wait_suspend_mfc_complete(prev
, spu
); /* Step 8. */
1922 if (!suspend_spe(prev
, spu
)) /* Step 9. */
1923 clear_spu_status(prev
, spu
); /* Step 10. */
1924 do_mfc_mssync(prev
, spu
); /* Step 11. */
1925 issue_mfc_tlbie(prev
, spu
); /* Step 12. */
1926 handle_pending_interrupts(prev
, spu
); /* Step 13. */
1927 purge_mfc_queue(prev
, spu
); /* Step 14. */
1928 wait_purge_complete(prev
, spu
); /* Step 15. */
1929 reset_spu_privcntl(prev
, spu
); /* Step 16. */
1930 reset_spu_lslr(prev
, spu
); /* Step 17. */
1931 setup_mfc_sr1(prev
, spu
); /* Step 18. */
1932 spu_invalidate_slbs(spu
); /* Step 19. */
1933 reset_ch_part1(prev
, spu
); /* Step 20. */
1934 reset_ch_part2(prev
, spu
); /* Step 21. */
1935 enable_interrupts(prev
, spu
); /* Step 22. */
1936 set_switch_active(prev
, spu
); /* Step 23. */
1937 set_mfc_tclass_id(prev
, spu
); /* Step 24. */
1938 resume_mfc_queue(prev
, spu
); /* Step 25. */
1941 static void restore_lscsa(struct spu_state
*next
, struct spu
*spu
)
1944 * Perform steps 26-40 of SPU context restore sequence,
1945 * which restores regions of the local store and register
1949 set_watchdog_timer(next
, spu
); /* Step 26. */
1950 setup_spu_status_part1(next
, spu
); /* Step 27. */
1951 setup_spu_status_part2(next
, spu
); /* Step 28. */
1952 restore_mfc_rag(next
, spu
); /* Step 29. */
1954 setup_mfc_slbs(next
, spu
, spu_restore_code
, sizeof(spu_restore_code
));
1955 set_spu_npc(next
, spu
); /* Step 31. */
1956 set_signot1(next
, spu
); /* Step 32. */
1957 set_signot2(next
, spu
); /* Step 33. */
1958 setup_decr(next
, spu
); /* Step 34. */
1959 setup_ppu_mb(next
, spu
); /* Step 35. */
1960 setup_ppuint_mb(next
, spu
); /* Step 36. */
1961 send_restore_code(next
, spu
); /* Step 37. */
1962 set_ppu_querymask(next
, spu
); /* Step 38. */
1963 wait_tag_complete(next
, spu
); /* Step 39. */
1964 wait_spu_stopped(next
, spu
); /* Step 40. */
1967 static void restore_csa(struct spu_state
*next
, struct spu
*spu
)
1970 * Combine steps 41-76 of SPU context restore sequence, which
1971 * restore regions of the privileged & problem state areas.
1974 restore_spu_privcntl(next
, spu
); /* Step 41. */
1975 restore_status_part1(next
, spu
); /* Step 42. */
1976 restore_status_part2(next
, spu
); /* Step 43. */
1977 restore_ls_16kb(next
, spu
); /* Step 44. */
1978 wait_tag_complete(next
, spu
); /* Step 45. */
1979 suspend_mfc(next
, spu
); /* Step 46. */
1980 wait_suspend_mfc_complete(next
, spu
); /* Step 47. */
1981 issue_mfc_tlbie(next
, spu
); /* Step 48. */
1982 clear_interrupts(next
, spu
); /* Step 49. */
1983 restore_mfc_queues(next
, spu
); /* Step 50. */
1984 restore_ppu_querymask(next
, spu
); /* Step 51. */
1985 restore_ppu_querytype(next
, spu
); /* Step 52. */
1986 restore_mfc_csr_tsq(next
, spu
); /* Step 53. */
1987 restore_mfc_csr_cmd(next
, spu
); /* Step 54. */
1988 restore_mfc_csr_ato(next
, spu
); /* Step 55. */
1989 restore_mfc_tclass_id(next
, spu
); /* Step 56. */
1990 set_llr_event(next
, spu
); /* Step 57. */
1991 restore_decr_wrapped(next
, spu
); /* Step 58. */
1992 restore_ch_part1(next
, spu
); /* Step 59. */
1993 restore_ch_part2(next
, spu
); /* Step 60. */
1994 restore_spu_lslr(next
, spu
); /* Step 61. */
1995 restore_spu_cfg(next
, spu
); /* Step 62. */
1996 restore_pm_trace(next
, spu
); /* Step 63. */
1997 restore_spu_npc(next
, spu
); /* Step 64. */
1998 restore_spu_mb(next
, spu
); /* Step 65. */
1999 check_ppu_mb_stat(next
, spu
); /* Step 66. */
2000 check_ppuint_mb_stat(next
, spu
); /* Step 67. */
2001 spu_invalidate_slbs(spu
); /* Modified Step 68. */
2002 restore_mfc_sr1(next
, spu
); /* Step 69. */
2003 restore_other_spu_access(next
, spu
); /* Step 70. */
2004 restore_spu_runcntl(next
, spu
); /* Step 71. */
2005 restore_mfc_cntl(next
, spu
); /* Step 72. */
2006 enable_user_access(next
, spu
); /* Step 73. */
2007 reset_switch_active(next
, spu
); /* Step 74. */
2008 reenable_interrupts(next
, spu
); /* Step 75. */
2011 static int __do_spu_save(struct spu_state
*prev
, struct spu
*spu
)
2016 * SPU context save can be broken into three phases:
2018 * (a) quiesce [steps 2-16].
2019 * (b) save of CSA, performed by PPE [steps 17-42]
2020 * (c) save of LSCSA, mostly performed by SPU [steps 43-52].
2022 * Returns 0 on success.
2023 * 2,6 if failed to quiece SPU
2024 * 53 if SPU-side of save failed.
2027 rc
= quiece_spu(prev
, spu
); /* Steps 2-16. */
2038 save_csa(prev
, spu
); /* Steps 17-43. */
2039 save_lscsa(prev
, spu
); /* Steps 44-53. */
2040 return check_save_status(prev
, spu
); /* Step 54. */
2043 static int __do_spu_restore(struct spu_state
*next
, struct spu
*spu
)
2048 * SPU context restore can be broken into three phases:
2050 * (a) harvest (or reset) SPU [steps 2-24].
2051 * (b) restore LSCSA [steps 25-40], mostly performed by SPU.
2052 * (c) restore CSA [steps 41-76], performed by PPE.
2054 * The 'harvest' step is not performed here, but rather
2058 restore_lscsa(next
, spu
); /* Steps 24-39. */
2059 rc
= check_restore_status(next
, spu
); /* Step 40. */
2062 /* Failed. Return now. */
2066 /* Fall through to next step. */
2069 restore_csa(next
, spu
);
2075 * spu_save - SPU context save, with locking.
2076 * @prev: pointer to SPU context save area, to be saved.
2077 * @spu: pointer to SPU iomem structure.
2079 * Acquire locks, perform the save operation then return.
2081 int spu_save(struct spu_state
*prev
, struct spu
*spu
)
2085 acquire_spu_lock(spu
); /* Step 1. */
2086 rc
= __do_spu_save(prev
, spu
); /* Steps 2-53. */
2087 release_spu_lock(spu
);
2088 if (rc
!= 0 && rc
!= 2 && rc
!= 6) {
2089 panic("%s failed on SPU[%d], rc=%d.\n",
2090 __func__
, spu
->number
, rc
);
2094 EXPORT_SYMBOL_GPL(spu_save
);
2097 * spu_restore - SPU context restore, with harvest and locking.
2098 * @new: pointer to SPU context save area, to be restored.
2099 * @spu: pointer to SPU iomem structure.
2101 * Perform harvest + restore, as we may not be coming
2102 * from a previous successful save operation, and the
2103 * hardware state is unknown.
2105 int spu_restore(struct spu_state
*new, struct spu
*spu
)
2109 acquire_spu_lock(spu
);
2111 spu
->slb_replace
= 0;
2112 rc
= __do_spu_restore(new, spu
);
2113 release_spu_lock(spu
);
2115 panic("%s failed on SPU[%d] rc=%d.\n",
2116 __func__
, spu
->number
, rc
);
2120 EXPORT_SYMBOL_GPL(spu_restore
);
2122 static void init_prob(struct spu_state
*csa
)
2124 csa
->spu_chnlcnt_RW
[9] = 1;
2125 csa
->spu_chnlcnt_RW
[21] = 16;
2126 csa
->spu_chnlcnt_RW
[23] = 1;
2127 csa
->spu_chnlcnt_RW
[28] = 1;
2128 csa
->spu_chnlcnt_RW
[30] = 1;
2129 csa
->prob
.spu_runcntl_RW
= SPU_RUNCNTL_STOP
;
2130 csa
->prob
.mb_stat_R
= 0x000400;
2133 static void init_priv1(struct spu_state
*csa
)
2135 /* Enable decode, relocate, tlbie response, master runcntl. */
2136 csa
->priv1
.mfc_sr1_RW
= MFC_STATE1_LOCAL_STORAGE_DECODE_MASK
|
2137 MFC_STATE1_MASTER_RUN_CONTROL_MASK
|
2138 MFC_STATE1_PROBLEM_STATE_MASK
|
2139 MFC_STATE1_RELOCATE_MASK
| MFC_STATE1_BUS_TLBIE_MASK
;
2141 /* Enable OS-specific set of interrupts. */
2142 csa
->priv1
.int_mask_class0_RW
= CLASS0_ENABLE_DMA_ALIGNMENT_INTR
|
2143 CLASS0_ENABLE_INVALID_DMA_COMMAND_INTR
|
2144 CLASS0_ENABLE_SPU_ERROR_INTR
;
2145 csa
->priv1
.int_mask_class1_RW
= CLASS1_ENABLE_SEGMENT_FAULT_INTR
|
2146 CLASS1_ENABLE_STORAGE_FAULT_INTR
;
2147 csa
->priv1
.int_mask_class2_RW
= CLASS2_ENABLE_SPU_STOP_INTR
|
2148 CLASS2_ENABLE_SPU_HALT_INTR
|
2149 CLASS2_ENABLE_SPU_DMA_TAG_GROUP_COMPLETE_INTR
;
2152 static void init_priv2(struct spu_state
*csa
)
2154 csa
->priv2
.spu_lslr_RW
= LS_ADDR_MASK
;
2155 csa
->priv2
.mfc_control_RW
= MFC_CNTL_RESUME_DMA_QUEUE
|
2156 MFC_CNTL_NORMAL_DMA_QUEUE_OPERATION
|
2157 MFC_CNTL_DMA_QUEUES_EMPTY_MASK
;
2161 * spu_alloc_csa - allocate and initialize an SPU context save area.
2163 * Allocate and initialize the contents of an SPU context save area.
2164 * This includes enabling address translation, interrupt masks, etc.,
2165 * as appropriate for the given OS environment.
2167 * Note that storage for the 'lscsa' is allocated separately,
2168 * as it is by far the largest of the context save regions,
2169 * and may need to be pinned or otherwise specially aligned.
2171 int spu_init_csa(struct spu_state
*csa
)
2177 memset(csa
, 0, sizeof(struct spu_state
));
2179 rc
= spu_alloc_lscsa(csa
);
2183 spin_lock_init(&csa
->register_lock
);
2192 void spu_fini_csa(struct spu_state
*csa
)
2194 spu_free_lscsa(csa
);