1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * (C) Copyright IBM Corp. 2005
7 * SPU-side context save sequence outlined in
8 * Synergistic Processor Element Book IV
10 * Author: Mark Nutter <mnutter@us.ibm.com>
15 #define LS_SIZE 0x40000 /* 256K (in bytes) */
18 typedef unsigned int u32
;
19 typedef unsigned long long u64
;
21 #include <spu_intrinsics.h>
22 #include <asm/spu_csa.h>
23 #include "spu_utils.h"
25 static inline void save_event_mask(void)
30 * Read the SPU_RdEventMsk channel and save to the LSCSA.
32 offset
= LSCSA_QW_OFFSET(event_mask
);
33 regs_spill
[offset
].slot
[0] = spu_readch(SPU_RdEventMask
);
36 static inline void save_tag_mask(void)
41 * Read the SPU_RdTagMsk channel and save to the LSCSA.
43 offset
= LSCSA_QW_OFFSET(tag_mask
);
44 regs_spill
[offset
].slot
[0] = spu_readch(MFC_RdTagMask
);
47 static inline void save_upper_240kb(addr64 lscsa_ea
)
49 unsigned int ls
= 16384;
50 unsigned int list
= (unsigned int)&dma_list
[0];
51 unsigned int size
= sizeof(dma_list
);
52 unsigned int tag_id
= 0;
53 unsigned int cmd
= 0x24; /* PUTL */
56 * Enqueue the PUTL command (tag 0) to the MFC SPU command
57 * queue to transfer the remaining 240 kb of LS to CSA.
59 spu_writech(MFC_LSA
, ls
);
60 spu_writech(MFC_EAH
, lscsa_ea
.ui
[0]);
61 spu_writech(MFC_EAL
, list
);
62 spu_writech(MFC_Size
, size
);
63 spu_writech(MFC_TagID
, tag_id
);
64 spu_writech(MFC_Cmd
, cmd
);
67 static inline void save_fpcr(void)
69 // vector unsigned int fpcr;
73 * Issue the floating-point status and control register
74 * read instruction, and save to the LSCSA.
76 offset
= LSCSA_QW_OFFSET(fpcr
);
77 regs_spill
[offset
].v
= spu_mffpscr();
80 static inline void save_decr(void)
85 * Read and save the SPU_RdDec channel data to
88 offset
= LSCSA_QW_OFFSET(decr
);
89 regs_spill
[offset
].slot
[0] = spu_readch(SPU_RdDec
);
92 static inline void save_srr0(void)
97 * Read and save the SPU_WSRR0 channel data to
100 offset
= LSCSA_QW_OFFSET(srr0
);
101 regs_spill
[offset
].slot
[0] = spu_readch(SPU_RdSRR0
);
104 static inline void spill_regs_to_mem(addr64 lscsa_ea
)
106 unsigned int ls
= (unsigned int)®s_spill
[0];
107 unsigned int size
= sizeof(regs_spill
);
108 unsigned int tag_id
= 0;
109 unsigned int cmd
= 0x20; /* PUT */
112 * Enqueue a PUT command (tag 0) to send the LSCSA
115 spu_writech(MFC_LSA
, ls
);
116 spu_writech(MFC_EAH
, lscsa_ea
.ui
[0]);
117 spu_writech(MFC_EAL
, lscsa_ea
.ui
[1]);
118 spu_writech(MFC_Size
, size
);
119 spu_writech(MFC_TagID
, tag_id
);
120 spu_writech(MFC_Cmd
, cmd
);
123 static inline void enqueue_sync(addr64 lscsa_ea
)
125 unsigned int tag_id
= 0;
126 unsigned int cmd
= 0xCC;
129 * Enqueue an MFC_SYNC command (tag 0).
131 spu_writech(MFC_TagID
, tag_id
);
132 spu_writech(MFC_Cmd
, cmd
);
135 static inline void save_complete(void)
138 * Issue a stop-and-signal instruction indicating
139 * "save complete". Note: This function will not
142 spu_stop(SPU_SAVE_COMPLETE
);
146 * main - entry point for SPU-side context save.
148 * This code deviates from the documented sequence as follows:
150 * 1. The EA for LSCSA is passed from PPE in the
151 * signal notification channels.
152 * 2. All 128 registers are saved by crt0.o.
158 lscsa_ea
.ui
[0] = spu_readch(SPU_RdSigNotify1
);
159 lscsa_ea
.ui
[1] = spu_readch(SPU_RdSigNotify2
);
161 /* Step 1: done by exit(). */
162 save_event_mask(); /* Step 2. */
163 save_tag_mask(); /* Step 3. */
164 set_event_mask(); /* Step 4. */
165 set_tag_mask(); /* Step 5. */
166 build_dma_list(lscsa_ea
); /* Step 6. */
167 save_upper_240kb(lscsa_ea
); /* Step 7. */
168 /* Step 8: done by exit(). */
169 save_fpcr(); /* Step 9. */
170 save_decr(); /* Step 10. */
171 save_srr0(); /* Step 11. */
172 enqueue_putllc(lscsa_ea
); /* Step 12. */
173 spill_regs_to_mem(lscsa_ea
); /* Step 13. */
174 enqueue_sync(lscsa_ea
); /* Step 14. */
175 set_tag_update(); /* Step 15. */
176 read_tag_status(); /* Step 16. */
177 read_llar_status(); /* Step 17. */
178 save_complete(); /* Step 18. */