1 /* -------------------------------------------------------------- */
2 /* (C)Copyright 2001,2007, */
3 /* International Business Machines Corporation, */
4 /* Sony Computer Entertainment, Incorporated, */
5 /* Toshiba Corporation, */
7 /* All Rights Reserved. */
9 /* Redistribution and use in source and binary forms, with or */
10 /* without modification, are permitted provided that the */
11 /* following conditions are met: */
13 /* - Redistributions of source code must retain the above copyright*/
14 /* notice, this list of conditions and the following disclaimer. */
16 /* - Redistributions in binary form must reproduce the above */
17 /* copyright notice, this list of conditions and the following */
18 /* disclaimer in the documentation and/or other materials */
19 /* provided with the distribution. */
21 /* - Neither the name of IBM Corporation nor the names of its */
22 /* contributors may be used to endorse or promote products */
23 /* derived from this software without specific prior written */
26 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
27 /* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
28 /* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
29 /* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
30 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
31 /* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
32 /* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
33 /* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
34 /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
35 /* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
36 /* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
37 /* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
38 /* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
39 /* -------------------------------------------------------------- */
40 /* PROLOG END TAG zYx */
42 * atomic.h - SPU atomic SHM counter operations.
44 * Interfaces patterned after, and hopefully compatible
45 * with PowerPC64-Linux atomic counter operations. Uses
46 * 32b values for various counters.
48 #ifndef _SPU_ATOMIC_H_
49 #define _SPU_ATOMIC_H_
51 #include <sync_utils.h>
52 #include <spu_mfcio.h>
55 /* atomic_eaddr_t is a 64bit effective address
56 * that points to an atomic_t variable */
57 typedef unsigned long long atomic_ea_t;
59 #define DECL_ATOMIC_VARS() \
61 char *tmp = (char *) ALIGN(_tmp, 128); \
62 volatile s32 *buf = (volatile s32 *) &tmp[0]; \
63 u32 size = 128, tagid = 0; \
69 * Internal routine to acquire lock line reservation
70 * then conditionally modify the counter variable
71 * pointed to by 'v'. The 'replace' flag indicates
72 * whether or not this is to be an arithmetic R-M-W
73 * or a simple replace operation.
75 #define ATOMIC_OP(__v, __val, __replace, __final_val) \
78 char *_tmp = (char *) ALIGN(__tmp, 128); \
79 volatile s32 *_buf = (volatile s32 *) &_tmp[0]; \
80 u32 _size = 128, _tagid = 0; \
81 s32 _status, _ret_val; \
85 _ea64.ull = ALIGN128_EA(__v); \
86 _offset = OFFSET128_EA_U32(__v); \
88 MFC_DMA(_buf, _ea64, _size, _tagid, MFC_GETLLAR_CMD); \
89 spu_readch (MFC_RdAtomicStat); \
91 _ret_val = _buf[_offset]; \
92 _buf[_offset] = (__replace) ? __val : _ret_val + __val; \
93 MFC_DMA(_buf, _ea64, _size, _tagid, MFC_PUTLLC_CMD); \
94 _status = spu_readch(MFC_RdAtomicStat); \
95 } while (_status != 0); \
97 __final_val = _ret_val; \
100 #endif /* _SPU_ATOMIC_H_ */