2 * utils.h: Utilities for SPU-side of the context switch operation.
4 * (C) Copyright IBM 2005
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #ifndef _SPU_CONTEXT_UTILS_H_
22 #define _SPU_CONTEXT_UTILS_H_
28 unsigned long long ull;
33 * 128-bit register template.
37 vector unsigned int v;
43 struct dma_list_elem {
49 * Declare storage for 8-byte aligned DMA list.
51 struct dma_list_elem dma_list[15] __attribute__ ((aligned(8)));
54 * External definition for storage
57 extern spu_reg128v regs_spill[NR_SPU_SPILL_REGS];
60 * Compute LSCSA byte offset for a given field.
62 static struct spu_lscsa *dummy = (struct spu_lscsa *)0;
63 #define LSCSA_BYTE_OFFSET(_field) \
64 ((char *)(&(dummy->_field)) - (char *)(&(dummy->gprs[0].slot[0])))
65 #define LSCSA_QW_OFFSET(_field) (LSCSA_BYTE_OFFSET(_field) >> 4)
67 static inline void set_event_mask(void)
69 unsigned int event_mask = 0;
73 * Set the SPU_RdEventMsk channel to zero to mask
76 spu_writech(SPU_WrEventMask, event_mask);
79 static inline void set_tag_mask(void)
81 unsigned int tag_mask = 1;
85 * Set the SPU_WrTagMsk channel to '01' to unmask
88 spu_writech(MFC_WrTagMask, tag_mask);
91 static inline void build_dma_list(addr64 lscsa_ea)
98 * Update the effective address for the CSA in the
99 * pre-canned DMA-list in local storage.
101 ea_low = lscsa_ea.ui[1];
102 ea_low += LSCSA_BYTE_OFFSET(ls[16384]);
104 for (i = 0; i < 15; i++, ea_low += 16384) {
105 dma_list[i].size = 16384;
106 dma_list[i].ea_low = ea_low;
110 static inline void enqueue_putllc(addr64 lscsa_ea)
113 unsigned int size = 128;
114 unsigned int tag_id = 0;
115 unsigned int cmd = 0xB4; /* PUTLLC */
119 * Send a PUTLLC (tag 0) command to the MFC using
120 * an effective address in the CSA in order to
121 * remove any possible lock-line reservation.
123 spu_writech(MFC_LSA, ls);
124 spu_writech(MFC_EAH, lscsa_ea.ui[0]);
125 spu_writech(MFC_EAL, lscsa_ea.ui[1]);
126 spu_writech(MFC_Size, size);
127 spu_writech(MFC_TagID, tag_id);
128 spu_writech(MFC_Cmd, cmd);
131 static inline void set_tag_update(void)
133 unsigned int update_any = 1;
137 * Write the MFC_TagUpdate channel with '01'.
139 spu_writech(MFC_WrTagUpdate, update_any);
142 static inline void read_tag_status(void)
146 * Read the MFC_TagStat channel data.
148 spu_readch(MFC_RdTagStat);
151 static inline void read_llar_status(void)
155 * Read the MFC_AtomicStat channel data.
157 spu_readch(MFC_RdAtomicStat);
160 #endif /* _SPU_CONTEXT_UTILS_H_ */