1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * utils.h: Utilities for SPU-side of the context switch operation.
5 * (C) Copyright IBM 2005
8 #ifndef _SPU_CONTEXT_UTILS_H_
9 #define _SPU_CONTEXT_UTILS_H_
15 unsigned long long ull;
20 * 128-bit register template.
24 vector unsigned int v;
30 struct dma_list_elem {
36 * Declare storage for 8-byte aligned DMA list.
38 struct dma_list_elem dma_list[15] __attribute__ ((aligned(8)));
41 * External definition for storage
44 extern spu_reg128v regs_spill[NR_SPU_SPILL_REGS];
47 * Compute LSCSA byte offset for a given field.
49 static struct spu_lscsa *dummy = (struct spu_lscsa *)0;
50 #define LSCSA_BYTE_OFFSET(_field) \
51 ((char *)(&(dummy->_field)) - (char *)(&(dummy->gprs[0].slot[0])))
52 #define LSCSA_QW_OFFSET(_field) (LSCSA_BYTE_OFFSET(_field) >> 4)
54 static inline void set_event_mask(void)
56 unsigned int event_mask = 0;
60 * Set the SPU_RdEventMsk channel to zero to mask
63 spu_writech(SPU_WrEventMask, event_mask);
66 static inline void set_tag_mask(void)
68 unsigned int tag_mask = 1;
72 * Set the SPU_WrTagMsk channel to '01' to unmask
75 spu_writech(MFC_WrTagMask, tag_mask);
78 static inline void build_dma_list(addr64 lscsa_ea)
85 * Update the effective address for the CSA in the
86 * pre-canned DMA-list in local storage.
88 ea_low = lscsa_ea.ui[1];
89 ea_low += LSCSA_BYTE_OFFSET(ls[16384]);
91 for (i = 0; i < 15; i++, ea_low += 16384) {
92 dma_list[i].size = 16384;
93 dma_list[i].ea_low = ea_low;
97 static inline void enqueue_putllc(addr64 lscsa_ea)
100 unsigned int size = 128;
101 unsigned int tag_id = 0;
102 unsigned int cmd = 0xB4; /* PUTLLC */
106 * Send a PUTLLC (tag 0) command to the MFC using
107 * an effective address in the CSA in order to
108 * remove any possible lock-line reservation.
110 spu_writech(MFC_LSA, ls);
111 spu_writech(MFC_EAH, lscsa_ea.ui[0]);
112 spu_writech(MFC_EAL, lscsa_ea.ui[1]);
113 spu_writech(MFC_Size, size);
114 spu_writech(MFC_TagID, tag_id);
115 spu_writech(MFC_Cmd, cmd);
118 static inline void set_tag_update(void)
120 unsigned int update_any = 1;
124 * Write the MFC_TagUpdate channel with '01'.
126 spu_writech(MFC_WrTagUpdate, update_any);
129 static inline void read_tag_status(void)
133 * Read the MFC_TagStat channel data.
135 spu_readch(MFC_RdTagStat);
138 static inline void read_llar_status(void)
142 * Read the MFC_AtomicStat channel data.
144 spu_readch(MFC_RdAtomicStat);
147 #endif /* _SPU_CONTEXT_UTILS_H_ */