GNU Radio 3.3.0 C++ API
atomic.h
Go to the documentation of this file.
00001 /* --------------------------------------------------------------  */
00002 /* (C)Copyright 2001,2007,                                         */
00003 /* International Business Machines Corporation,                    */
00004 /* Sony Computer Entertainment, Incorporated,                      */
00005 /* Toshiba Corporation,                                            */
00006 /*                                                                 */
00007 /* All Rights Reserved.                                            */
00008 /*                                                                 */
00009 /* Redistribution and use in source and binary forms, with or      */
00010 /* without modification, are permitted provided that the           */
00011 /* following conditions are met:                                   */
00012 /*                                                                 */
00013 /* - Redistributions of source code must retain the above copyright*/
00014 /*   notice, this list of conditions and the following disclaimer. */
00015 /*                                                                 */
00016 /* - Redistributions in binary form must reproduce the above       */
00017 /*   copyright notice, this list of conditions and the following   */
00018 /*   disclaimer in the documentation and/or other materials        */
00019 /*   provided with the distribution.                               */
00020 /*                                                                 */
00021 /* - Neither the name of IBM Corporation nor the names of its      */
00022 /*   contributors may be used to endorse or promote products       */
00023 /*   derived from this software without specific prior written     */
00024 /*   permission.                                                   */
00025 /*                                                                 */
00026 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND          */
00027 /* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,     */
00028 /* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF        */
00029 /* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE        */
00030 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR            */
00031 /* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,    */
00032 /* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT    */
00033 /* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;    */
00034 /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)        */
00035 /* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN       */
00036 /* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR    */
00037 /* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,  */
00038 /* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.              */
00039 /* --------------------------------------------------------------  */
00040 /* PROLOG END TAG zYx                                              */
00041 /*
00042  * atomic.h - SPU atomic SHM counter operations.
00043  *
00044  * Interfaces patterned after, and hopefully compatible
00045  * with PowerPC64-Linux atomic counter operations.  Uses
00046  * 32b values for various counters.
00047  */
00048 #ifndef _SPU_ATOMIC_H_
00049 #define _SPU_ATOMIC_H_
00050 
00051 #include <sync_utils.h>
00052 #include <spu_mfcio.h>
00053 
00054 
00055 /* atomic_eaddr_t is a 64bit effective address 
00056  * that points to an atomic_t variable */
00057 typedef unsigned long long atomic_ea_t;
00058 
00059 #define DECL_ATOMIC_VARS()                              \
00060     char _tmp[256];                                     \
00061     char *tmp = (char *) ALIGN(_tmp, 128);              \
00062     volatile s32 *buf = (volatile s32 *) &tmp[0];       \
00063     u32 size = 128, tagid = 0;                          \
00064     s32 ret_val;                                        \
00065     u32 offset;                                         \
00066     addr64 ea64
00067 
00068 /* __atomic_op                                              
00069 *    Internal routine to acquire lock line reservation
00070 *    then conditionally modify the counter variable 
00071 *    pointed to by 'v'.  The 'replace' flag indicates 
00072 *    whether or not this is to be an arithmetic R-M-W
00073 *    or a simple replace operation.
00074 */
00075 #define ATOMIC_OP(__v, __val, __replace, __final_val)           \
00076 {                                                               \
00077     char __tmp[256];                                            \
00078     char *_tmp = (char *) ALIGN(__tmp, 128);                    \
00079     volatile s32 *_buf = (volatile s32 *) &_tmp[0];             \
00080     u32 _size = 128, _tagid = 0;                                \
00081     s32 _status, _ret_val;                                      \
00082     u32 _offset;                                                \
00083     addr64 _ea64;                                               \
00084                                                                 \
00085     _ea64.ull = ALIGN128_EA(__v);                               \
00086     _offset = OFFSET128_EA_U32(__v);                            \
00087     do {                                                        \
00088         MFC_DMA(_buf, _ea64, _size, _tagid, MFC_GETLLAR_CMD);   \
00089         spu_readch (MFC_RdAtomicStat);                          \
00090                                                                 \
00091         _ret_val = _buf[_offset];                                \
00092         _buf[_offset] = (__replace) ? __val : _ret_val + __val;    \
00093         MFC_DMA(_buf, _ea64, _size, _tagid, MFC_PUTLLC_CMD);    \
00094         _status = spu_readch(MFC_RdAtomicStat);                  \
00095     } while (_status != 0);                                     \
00096                                                                 \
00097     __final_val = _ret_val;                                     \
00098 }                                                               
00099 
00100 #endif /* _SPU_ATOMIC_H_ */
00101