Statistics
| Branch: | Tag: | Revision:

root / gcell / src / ibm / sync / spu_source / atomic.h @ 28361a1b

History | View | Annotate | Download (5.4 kB)

1
/* --------------------------------------------------------------  */
2
/* (C)Copyright 2001,2007,                                         */
3
/* International Business Machines Corporation,                    */
4
/* Sony Computer Entertainment, Incorporated,                      */
5
/* Toshiba Corporation,                                            */
6
/*                                                                 */
7
/* All Rights Reserved.                                            */
8
/*                                                                 */
9
/* Redistribution and use in source and binary forms, with or      */
10
/* without modification, are permitted provided that the           */
11
/* following conditions are met:                                   */
12
/*                                                                 */
13
/* - Redistributions of source code must retain the above copyright*/
14
/*   notice, this list of conditions and the following disclaimer. */
15
/*                                                                 */
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.                               */
20
/*                                                                 */
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     */
24
/*   permission.                                                   */
25
/*                                                                 */
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                                              */
41
/*
42
 * atomic.h - SPU atomic SHM counter operations.
43
 *
44
 * Interfaces patterned after, and hopefully compatible
45
 * with PowerPC64-Linux atomic counter operations.  Uses
46
 * 32b values for various counters.
47
 */
48
#ifndef _SPU_ATOMIC_H_
49
#define _SPU_ATOMIC_H_
50
51
#include <sync_utils.h>
52
#include <spu_mfcio.h>
53
54
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;
58
59
#define DECL_ATOMIC_VARS()                              \
60
    char _tmp[256];                                         \
61
    char *tmp = (char *) ALIGN(_tmp, 128);                \
62
    volatile s32 *buf = (volatile s32 *) &tmp[0];       \
63
    u32 size = 128, tagid = 0;                          \
64
    s32 ret_val;                                        \
65
    u32 offset;                                         \
66
    addr64 ea64
67
68
/* __atomic_op                                              
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.
74
*/
75
#define ATOMIC_OP(__v, __val, __replace, __final_val)           \
76
{                                                               \
77
    char __tmp[256];                                            \
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;                                      \
82
    u32 _offset;                                                \
83
    addr64 _ea64;                                               \
84
                                                                \
85
    _ea64.ull = ALIGN128_EA(__v);                               \
86
    _offset = OFFSET128_EA_U32(__v);                            \
87
    do {                                                        \
88
        MFC_DMA(_buf, _ea64, _size, _tagid, MFC_GETLLAR_CMD);   \
89
        spu_readch (MFC_RdAtomicStat);                          \
90
                                                                \
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);                                     \
96
                                                                \
97
    __final_val = _ret_val;                                     \
98
}                                                               
99
100
#endif /* _SPU_ATOMIC_H_ */
101