summaryrefslogtreecommitdiff
path: root/gcell/ibm/sync/spu_source
diff options
context:
space:
mode:
Diffstat (limited to 'gcell/ibm/sync/spu_source')
-rw-r--r--gcell/ibm/sync/spu_source/atomic.h101
-rw-r--r--gcell/ibm/sync/spu_source/atomic_add.h62
-rw-r--r--gcell/ibm/sync/spu_source/atomic_add_return.h69
-rw-r--r--gcell/ibm/sync/spu_source/atomic_dec.h61
-rw-r--r--gcell/ibm/sync/spu_source/atomic_dec_and_test.h64
-rw-r--r--gcell/ibm/sync/spu_source/atomic_dec_if_positive.h86
-rw-r--r--gcell/ibm/sync/spu_source/atomic_dec_return.h70
-rw-r--r--gcell/ibm/sync/spu_source/atomic_inc.h61
-rw-r--r--gcell/ibm/sync/spu_source/atomic_inc_return.h70
-rw-r--r--gcell/ibm/sync/spu_source/atomic_read.h78
-rw-r--r--gcell/ibm/sync/spu_source/atomic_set.h68
-rw-r--r--gcell/ibm/sync/spu_source/atomic_sub.h64
-rw-r--r--gcell/ibm/sync/spu_source/atomic_sub_and_test.h66
-rw-r--r--gcell/ibm/sync/spu_source/atomic_sub_return.h69
-rw-r--r--gcell/ibm/sync/spu_source/complete.h67
-rw-r--r--gcell/ibm/sync/spu_source/complete_all.h74
-rw-r--r--gcell/ibm/sync/spu_source/completion.h68
-rw-r--r--gcell/ibm/sync/spu_source/cond.h69
-rw-r--r--gcell/ibm/sync/spu_source/cond_broadcast.h73
-rw-r--r--gcell/ibm/sync/spu_source/cond_init.h127
-rw-r--r--gcell/ibm/sync/spu_source/cond_signal.h88
-rw-r--r--gcell/ibm/sync/spu_source/cond_wait.h103
-rw-r--r--gcell/ibm/sync/spu_source/init_completion.h82
-rw-r--r--gcell/ibm/sync/spu_source/libsync.h116
-rw-r--r--gcell/ibm/sync/spu_source/mutex.h178
-rw-r--r--gcell/ibm/sync/spu_source/mutex_init.h64
-rw-r--r--gcell/ibm/sync/spu_source/mutex_lock.h66
-rw-r--r--gcell/ibm/sync/spu_source/mutex_trylock.h70
-rw-r--r--gcell/ibm/sync/spu_source/mutex_unlock.h59
-rw-r--r--gcell/ibm/sync/spu_source/read_lock.h66
-rw-r--r--gcell/ibm/sync/spu_source/read_trylock.h71
-rw-r--r--gcell/ibm/sync/spu_source/read_unlock.h88
-rw-r--r--gcell/ibm/sync/spu_source/rwlock_init.h60
-rw-r--r--gcell/ibm/sync/spu_source/sync_irq.h76
-rw-r--r--gcell/ibm/sync/spu_source/sync_utils.h103
-rw-r--r--gcell/ibm/sync/spu_source/trace_libsync.h117
-rw-r--r--gcell/ibm/sync/spu_source/wait_for_completion.h82
-rw-r--r--gcell/ibm/sync/spu_source/write_lock.h67
-rw-r--r--gcell/ibm/sync/spu_source/write_trylock.h72
-rw-r--r--gcell/ibm/sync/spu_source/write_unlock.h69
40 files changed, 3164 insertions, 0 deletions
diff --git a/gcell/ibm/sync/spu_source/atomic.h b/gcell/ibm/sync/spu_source/atomic.h
new file mode 100644
index 000000000..951c26e3f
--- /dev/null
+++ b/gcell/ibm/sync/spu_source/atomic.h
@@ -0,0 +1,101 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+/*
+ * atomic.h - SPU atomic SHM counter operations.
+ *
+ * Interfaces patterned after, and hopefully compatible
+ * with PowerPC64-Linux atomic counter operations. Uses
+ * 32b values for various counters.
+ */
+#ifndef _SPU_ATOMIC_H_
+#define _SPU_ATOMIC_H_
+
+#include <sync_utils.h>
+#include <spu_mfcio.h>
+
+
+/* atomic_eaddr_t is a 64bit effective address
+ * that points to an atomic_t variable */
+typedef unsigned long long atomic_ea_t;
+
+#define DECL_ATOMIC_VARS() \
+ char _tmp[256]; \
+ char *tmp = (char *) ALIGN(_tmp, 128); \
+ volatile s32 *buf = (volatile s32 *) &tmp[0]; \
+ u32 size = 128, tagid = 0; \
+ s32 ret_val; \
+ u32 offset; \
+ addr64 ea64
+
+/* __atomic_op
+* Internal routine to acquire lock line reservation
+* then conditionally modify the counter variable
+* pointed to by 'v'. The 'replace' flag indicates
+* whether or not this is to be an arithmetic R-M-W
+* or a simple replace operation.
+*/
+#define ATOMIC_OP(__v, __val, __replace, __final_val) \
+{ \
+ char __tmp[256]; \
+ char *_tmp = (char *) ALIGN(__tmp, 128); \
+ volatile s32 *_buf = (volatile s32 *) &_tmp[0]; \
+ u32 _size = 128, _tagid = 0; \
+ s32 _status, _ret_val; \
+ u32 _offset; \
+ addr64 _ea64; \
+ \
+ _ea64.ull = ALIGN128_EA(__v); \
+ _offset = OFFSET128_EA_U32(__v); \
+ do { \
+ MFC_DMA(_buf, _ea64, _size, _tagid, MFC_GETLLAR_CMD); \
+ spu_readch (MFC_RdAtomicStat); \
+ \
+ _ret_val = _buf[_offset]; \
+ _buf[_offset] = (__replace) ? __val : _ret_val + __val; \
+ MFC_DMA(_buf, _ea64, _size, _tagid, MFC_PUTLLC_CMD); \
+ _status = spu_readch(MFC_RdAtomicStat); \
+ } while (_status != 0); \
+ \
+ __final_val = _ret_val; \
+}
+
+#endif /* _SPU_ATOMIC_H_ */
+
diff --git a/gcell/ibm/sync/spu_source/atomic_add.h b/gcell/ibm/sync/spu_source/atomic_add.h
new file mode 100644
index 000000000..7606ae05b
--- /dev/null
+++ b/gcell/ibm/sync/spu_source/atomic_add.h
@@ -0,0 +1,62 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _SPU_ATOMIC_ADD_H_
+#define _SPU_ATOMIC_ADD_H_
+
+#include <sync_utils.h>
+#include <atomic.h>
+
+/**
+ * atomic_add - atomically add to a counter.
+ * @v: handle to effective address of counter.
+ * @a: value to be added.
+ *
+ * Atomically add a value to a counter in system memory.
+ * The only restriction is that @v must be word aligned.
+ */
+static __inline void _atomic_add(int a, atomic_ea_t v)
+{
+ int ret_val;
+ ATOMIC_OP (v, a, 0, ret_val);
+}
+
+
+#endif /* _SPU_ATOMIC_ADD_H_ */
diff --git a/gcell/ibm/sync/spu_source/atomic_add_return.h b/gcell/ibm/sync/spu_source/atomic_add_return.h
new file mode 100644
index 000000000..35f07adf6
--- /dev/null
+++ b/gcell/ibm/sync/spu_source/atomic_add_return.h
@@ -0,0 +1,69 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _SPU_ATOMIC_ADD_RETURN_H_
+#define _SPU_ATOMIC_ADD_RETURN_H_
+
+#include <sync_utils.h>
+#include <atomic.h>
+/**
+ * atomic_add_return - atomically add to a counter and return previous value.
+ * @v: handle to effective address of counter.
+ * @a: value to be added.
+ *
+ * Atomically add a value to a counter in system memory.
+ * The only restriction is that @v must be word aligned.
+ *
+ * This routine implements the "fetch and add" primitive
+ * that is described in "Book I PowerPC User Instruction
+ * Set Architecture", but uses MFC lock line reservation
+ * operations instead of lwarx/stwcx.
+ *
+ * Returns the previous value from system memory.
+ */
+static __inline int _atomic_add_return(int a, atomic_ea_t v)
+{
+ int ret_val;
+ ATOMIC_OP(v, a, 0, ret_val);
+ return ret_val;
+}
+
+
+#endif /* _SPU_ATOMIC_ADD_RETURN_H_ */
diff --git a/gcell/ibm/sync/spu_source/atomic_dec.h b/gcell/ibm/sync/spu_source/atomic_dec.h
new file mode 100644
index 000000000..30ca7c514
--- /dev/null
+++ b/gcell/ibm/sync/spu_source/atomic_dec.h
@@ -0,0 +1,61 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _SPU_ATOMIC_DEC_H_
+#define _SPU_ATOMIC_DEC_H_
+
+#include <sync_utils.h>
+#include <atomic.h>
+
+/**
+ * atomic_dec - atomically decrement a counter.
+ * @v: handle to effective address of location to be modified.
+ *
+ * Atomically decrement a counter in system memory. The only
+ * restriction is that @v must be word aligned.
+ */
+static __inline void _atomic_dec(atomic_ea_t v)
+{
+ int ret_val;
+ ATOMIC_OP (v, -1, 0, ret_val);
+}
+
+
+#endif /* _SPU_ATOMIC_DEC_H_ */
diff --git a/gcell/ibm/sync/spu_source/atomic_dec_and_test.h b/gcell/ibm/sync/spu_source/atomic_dec_and_test.h
new file mode 100644
index 000000000..b3c829820
--- /dev/null
+++ b/gcell/ibm/sync/spu_source/atomic_dec_and_test.h
@@ -0,0 +1,64 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _SPU_ATOMIC_DEC_AND_TEST_H_
+#define _SPU_ATOMIC_DEC_AND_TEST_H_
+
+#include <sync_utils.h>
+#include <atomic.h>
+
+/**
+ * atomic_dec_and_test - atomically decrement and test if previous==0.
+ * @v: handle to effective address of counter.
+ *
+ * Atomically decrement a counter in system memory and test
+ * if previous==0. The only restriction is that @v must be
+ * word aligned.
+ *
+ * Returns the previous value from system memory.
+ */
+static __inline int _atomic_dec_and_test(atomic_ea_t v)
+{
+ int ret_val;
+ ATOMIC_OP(v, -1, 0, ret_val);
+ return (ret_val == 0) ? 1 : 0;
+}
+
+#endif /* _SPU_ATOMIC_DEC_AND_TEST_H_ */
diff --git a/gcell/ibm/sync/spu_source/atomic_dec_if_positive.h b/gcell/ibm/sync/spu_source/atomic_dec_if_positive.h
new file mode 100644
index 000000000..2a01ec307
--- /dev/null
+++ b/gcell/ibm/sync/spu_source/atomic_dec_if_positive.h
@@ -0,0 +1,86 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _SPU_ATOMIC_DEC_IF_POSITIVE_H_
+#define _SPU_ATOMIC_DEC_IF_POSITIVE_H_
+
+#include <sync_utils.h>
+#include <atomic.h>
+
+/**
+ * atomic_dec_if_positive - atomically decrement if counter is positive.
+ * @v: handle to effective address of counter.
+ *
+ * Atomically decrement a counter if its value is positive.
+ * The only restriction is that @v must be word aligned.
+ *
+*
+ * Returns the old value of the counter, minus 1.
+ */
+static __inline int _atomic_dec_if_positive(atomic_ea_t v)
+{
+ DECL_ATOMIC_VARS();
+ s32 status;
+
+ ea64.ull = ALIGN128_EA(v);
+ offset = OFFSET128_EA_U32(v);
+ do {
+ MFC_DMA(buf, ea64, size, tagid, MFC_GETLLAR_CMD);
+ spu_readch(MFC_RdAtomicStat);
+
+ ret_val = buf[offset] - 1;
+ if (likely(ret_val >= 0)) {
+ buf[offset] = ret_val;
+ MFC_DMA(buf, ea64, size, tagid, MFC_PUTLLC_CMD);
+ status = spu_readch(MFC_RdAtomicStat);
+ } else {
+ MFC_DMA(buf, ea64, size, tagid, MFC_PUTLLC_CMD);
+ spu_readch(MFC_RdAtomicStat);
+ status = 0;
+ break;
+ }
+ } while (status != 0);
+
+ return ret_val;
+}
+
+
+
+#endif /* _SPU_ATOMIC_DEC_IF_POSITIVE_H_ */
diff --git a/gcell/ibm/sync/spu_source/atomic_dec_return.h b/gcell/ibm/sync/spu_source/atomic_dec_return.h
new file mode 100644
index 000000000..45effb689
--- /dev/null
+++ b/gcell/ibm/sync/spu_source/atomic_dec_return.h
@@ -0,0 +1,70 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _SPU_ATOMIC_DEC_RETURN_H_
+#define _SPU_ATOMIC_DEC_RETURN_H_
+
+#include <sync_utils.h>
+#include <atomic.h>
+
+/**
+ * atomic_dec_return - atomically decrement a counter and return previous value.
+ * @v: handle to effective address of counter.
+ *
+ * Atomically decrement a counter in system memory and return its
+ * previous value. The only restriction is that @v must be word
+ * aligned.
+ *
+ * This routine implements the "fetch and decrement"
+ * primitive that is described in "Book I PowerPC User
+ * Instruction Set Architecture", but uses MFC lock line
+ * reservation operations instead of lwarx/stwcx.
+ *
+ * Returns the previous value from system memory.
+ */
+static __inline int _atomic_dec_return(atomic_ea_t v)
+{
+ int ret_val;
+ ATOMIC_OP(v, -1, 0, ret_val);
+ return ret_val;
+}
+
+
+#endif /* _SPU_ATOMIC_DEC_RETURN_H_ */
diff --git a/gcell/ibm/sync/spu_source/atomic_inc.h b/gcell/ibm/sync/spu_source/atomic_inc.h
new file mode 100644
index 000000000..6800efea3
--- /dev/null
+++ b/gcell/ibm/sync/spu_source/atomic_inc.h
@@ -0,0 +1,61 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _SPU_ATOMIC_INC_H_
+#define _SPU_ATOMIC_INC_H_
+
+#include <sync_utils.h>
+#include <atomic.h>
+
+/**
+ * atomic_inc - atomically increment a counter in system memory.
+ * @v: handle to effective address of counter.
+ *
+ * Atomically increment a counter in system memory.
+ * The only restriction is that @v must be word aligned.
+ */
+static __inline void _atomic_inc(atomic_ea_t v)
+{
+ int ret_val;
+ ATOMIC_OP (v, 1, 0, ret_val);
+}
+
+
+#endif /* _SPU_ATOMIC_INC_H_ */
diff --git a/gcell/ibm/sync/spu_source/atomic_inc_return.h b/gcell/ibm/sync/spu_source/atomic_inc_return.h
new file mode 100644
index 000000000..89361a0a1
--- /dev/null
+++ b/gcell/ibm/sync/spu_source/atomic_inc_return.h
@@ -0,0 +1,70 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _SPU_ATOMIC_INC_RETURN_H_
+#define _SPU_ATOMIC_INC_RETURN_H_
+
+#include <sync_utils.h>
+#include <atomic.h>
+
+
+/**
+ * atomic_inc_return - atomically increment a counter and return previous.
+ * @v: handle to effective address of counter.
+ *
+ * Atomically increment a counter in system memory.
+ * The only restriction is that @v must be word aligned.
+ *
+ * This routine implements the "fetch and increment"
+ * primitive that is described in "Book I PowerPC User
+ * Instruction Set Architecture", but uses MFC lock line
+ * reservation operations instead of lwarx/stwcx.
+ *
+ * Returns the previous value from system memory.
+ */
+static __inline int _atomic_inc_return(atomic_ea_t v)
+{
+ int ret_val;
+ ATOMIC_OP(v, 1, 0, ret_val);
+ return ret_val;
+}
+
+
+#endif /* _SPU_ATOMIC_INC_RETURN_H_ */
diff --git a/gcell/ibm/sync/spu_source/atomic_read.h b/gcell/ibm/sync/spu_source/atomic_read.h
new file mode 100644
index 000000000..711a0ad26
--- /dev/null
+++ b/gcell/ibm/sync/spu_source/atomic_read.h
@@ -0,0 +1,78 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _SPU_ATOMIC_READ_H_
+#define _SPU_ATOMIC_READ_H_
+
+#include <sync_utils.h>
+#include <atomic.h>
+
+/**
+ * atomic_read - read an atomic counter.
+ * @v: handle to effective address of counter.
+ *
+ * Read the current value of an atomic counter.
+ */
+static __inline int _atomic_read(atomic_ea_t v)
+{
+ DECL_ATOMIC_VARS();
+
+ /* reserve a tag for use */
+ tagid = mfc_tag_reserve();
+
+ u32 oldtmask, tagmask = 1 << (tagid & 31);
+
+ ea64.ull = ALIGN128_EA(v);
+ offset = OFFSET128_EA_U32(v);
+
+ MFC_DMA(buf, ea64, size, tagid & 31, MFC_GET_CMD);
+ oldtmask = spu_readch(MFC_RdTagMask);
+ spu_writech(MFC_WrTagMask, tagmask);
+ spu_writech(MFC_WrTagUpdate, MFC_TAG_UPDATE_ANY);
+ spu_readch(MFC_RdTagStat);
+ spu_writech(MFC_WrTagMask, oldtmask);
+
+ mfc_tag_release (tagid);
+ ret_val = buf[offset];
+ return ret_val;
+}
+
+
+#endif /* _SPU_ATOMIC_READ_H_ */
diff --git a/gcell/ibm/sync/spu_source/atomic_set.h b/gcell/ibm/sync/spu_source/atomic_set.h
new file mode 100644
index 000000000..261d28a3d
--- /dev/null
+++ b/gcell/ibm/sync/spu_source/atomic_set.h
@@ -0,0 +1,68 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _SPU_ATOMIC_SET_H_
+#define _SPU_ATOMIC_SET_H_
+
+#include <sync_utils.h>
+#include <atomic.h>
+
+/**
+ * atomic_set - atomically set a counter in system memory.
+ * @v: handle to effective address of counter.
+ *
+ * Atomically set a counter to a given value. The only
+ * restriction is that @v must be word aligned.
+ *
+ * This routine implements the "fetch and store"
+ * primitive that is described in "Book I PowerPC User
+ * Instruction Set Architecture", but uses MFC lock line
+ * reservation operations instead of lwarx/stwcx.
+ *
+ * Returns the previous value from system memory.
+ */
+static __inline void _atomic_set(atomic_ea_t v, int val)
+{
+ int ret_val;
+ ATOMIC_OP(v, val, 1, ret_val);
+}
+
+
+#endif /* _SPU_ATOMIC_SET_H_ */
diff --git a/gcell/ibm/sync/spu_source/atomic_sub.h b/gcell/ibm/sync/spu_source/atomic_sub.h
new file mode 100644
index 000000000..f366e1dee
--- /dev/null
+++ b/gcell/ibm/sync/spu_source/atomic_sub.h
@@ -0,0 +1,64 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _SPU_ATOMIC_SUB_H_
+#define _SPU_ATOMIC_SUB_H_
+
+#include <sync_utils.h>
+#include <atomic.h>
+
+/**
+ * atomic_sub - atomically subtract from a counter.
+ * @v: handle to effective address of counter.
+ * @a: value to be subtracted.
+ *
+ * Atomically subtract a value from a counter in system memory.
+ * The only restriction is that @v must be word aligned.
+ */
+static __inline void _atomic_sub(int a, atomic_ea_t v)
+{
+ int ret_val;
+
+ ATOMIC_OP (v, -a, 0, ret_val);
+}
+
+
+
+#endif /* _SPU_ATOMIC_SUB_H_ */
diff --git a/gcell/ibm/sync/spu_source/atomic_sub_and_test.h b/gcell/ibm/sync/spu_source/atomic_sub_and_test.h
new file mode 100644
index 000000000..fe5824a43
--- /dev/null
+++ b/gcell/ibm/sync/spu_source/atomic_sub_and_test.h
@@ -0,0 +1,66 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _SPU_ATOMIC_SUB_AND_TEST_H_
+#define _SPU_ATOMIC_SUB_AND_TEST_H_
+
+#include <sync_utils.h>
+#include <atomic.h>
+
+/**
+ * atomic_sub_and_test - atomically subtract and test if previous==0.
+ * @v: handle to effective address of counter.
+ * @a: value to be subtracted.
+ *
+ * Atomically subtract a value from a counter in system memory
+ * and test if previous==0. The only restriction is that @v
+ * must be word aligned.
+ *
+ * Returns the previous value from system memory.
+ */
+static __inline int _atomic_sub_and_test(int a, atomic_ea_t v)
+{
+ int ret_val;
+ ATOMIC_OP(v, -a, 0, ret_val);
+ return (ret_val == 0) ? 1 : 0;
+}
+
+
+#endif /* _SPU_ATOMIC_SUB_AND_TEST_H_ */
diff --git a/gcell/ibm/sync/spu_source/atomic_sub_return.h b/gcell/ibm/sync/spu_source/atomic_sub_return.h
new file mode 100644
index 000000000..5dbed5b85
--- /dev/null
+++ b/gcell/ibm/sync/spu_source/atomic_sub_return.h
@@ -0,0 +1,69 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _SPU_ATOMIC_SUB_RETURN_H_
+#define _SPU_ATOMIC_SUB_RETURN_H_
+
+#include <sync_utils.h>
+#include <atomic.h>
+
+
+/**
+ * atomic_sub_return - atomically subtract from a counter & return previous.
+ * @v: handle to effective address of counter.
+ * @a: value to be subtracted.
+ *
+ * Atomically subtract a value from a counter in system memory.
+ * The only restriction is that @v must be word aligned.
+ *
+ * Returns the previous value from system memory.
+ */
+static __inline int _atomic_sub_return(int a, atomic_ea_t v)
+{
+ int ret_val;
+ ATOMIC_OP(v, -a, 0, ret_val);
+ return ret_val;
+ //return __atomic_op(v, -a, 0);
+}
+
+
+
+
+#endif /* _SPU_ATOMIC_SUB_RETURN_H_ */
diff --git a/gcell/ibm/sync/spu_source/complete.h b/gcell/ibm/sync/spu_source/complete.h
new file mode 100644
index 000000000..6a7808650
--- /dev/null
+++ b/gcell/ibm/sync/spu_source/complete.h
@@ -0,0 +1,67 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _SPU_COMPLETE_H_
+#define _SPU_COMPLETE_H_
+
+#include "sync_utils.h"
+#include <spu_mfcio.h>
+#include "completion.h"
+
+static __inline void _complete(completion_ea_t completion)
+{
+ DECL_COMPLETION_VARS();
+
+ ea64.ull = ALIGN128_EA(completion);
+ offset = OFFSET128_EA_U32(completion);
+ MFC_DMA(buf, ea64, size, tagid, MFC_GETLLAR_CMD);
+ spu_readch(MFC_RdAtomicStat);
+
+ /* set the completionition variable to exactly one so
+ * only one thread can be awaken */
+ buf[offset] = 1;
+ MFC_DMA(buf, ea64, size, tagid, MFC_PUTLLUC_CMD);
+ spu_readch(MFC_RdAtomicStat);
+}
+
+
+
+
+#endif /* _SPU_COMPLETE_H_ */
diff --git a/gcell/ibm/sync/spu_source/complete_all.h b/gcell/ibm/sync/spu_source/complete_all.h
new file mode 100644
index 000000000..5f9c3dcfa
--- /dev/null
+++ b/gcell/ibm/sync/spu_source/complete_all.h
@@ -0,0 +1,74 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _SPU_COMPLETE_ALL_H_
+#define _SPU_COMPLETE_ALL_H_
+
+#include "sync_utils.h"
+#include <spu_mfcio.h>
+#include "completion.h"
+
+/**
+ * completion_broadcast - indicate that a completion is true.
+ * @completion: handle to effective address of completion variable.
+ *
+ * Indicate that a completionition is true by storing '1' to the
+ * completionition variable.
+ */
+static __inline void _complete_all(completion_ea_t completion)
+{
+ DECL_COMPLETION_VARS();
+
+ ea64.ull = ALIGN128_EA(completion);
+ offset = OFFSET128_EA_U32(completion);
+ MFC_DMA(buf, ea64, size, tagid, MFC_GETLLAR_CMD);
+ spu_readch(MFC_RdAtomicStat);
+
+ /* set the completionition variable to the count. So that
+ * all the threads */
+ buf[offset] = MAX_THREADS_WAITING;
+ MFC_DMA(buf, ea64, size, tagid, MFC_PUTLLUC_CMD);
+ spu_readch(MFC_RdAtomicStat);
+}
+
+
+
+
+#endif /* _SPU_COMPLETE_ALL_H_ */
diff --git a/gcell/ibm/sync/spu_source/completion.h b/gcell/ibm/sync/spu_source/completion.h
new file mode 100644
index 000000000..4a302d25c
--- /dev/null
+++ b/gcell/ibm/sync/spu_source/completion.h
@@ -0,0 +1,68 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+/*
+ * cond.h - simple condition wait & broadcast operations.
+ *
+ * Interrupt aware versions of the routines are supported.
+ * Applications should call either '_irq' or '_irqsave'
+ * forms of the functions when interrupts are enabled.
+ */
+
+#ifndef __SPU_COMPLETION_H__
+#define __SPU_COMPLETION_H__
+
+#include "sync_utils.h"
+
+#define MAX_THREADS_WAITING 32000
+typedef unsigned long long completion_ea_t;
+
+
+#define DECL_COMPLETION_VARS() \
+ char _tmp[256]; \
+ char *tmp = (char *) ALIGN(_tmp, 128); \
+ volatile s32 *buf = (volatile s32 *) &tmp[0]; \
+ u32 size = 128, tagid = 0; \
+ u32 offset; \
+ addr64 ea64
+
+
+
+#endif /* __SPU_COMPLETION_H__ */
diff --git a/gcell/ibm/sync/spu_source/cond.h b/gcell/ibm/sync/spu_source/cond.h
new file mode 100644
index 000000000..ceb3285d9
--- /dev/null
+++ b/gcell/ibm/sync/spu_source/cond.h
@@ -0,0 +1,69 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _SPU_COND_VAR_H_
+#define _SPU_COND_VAR_H_
+
+#include "sync_utils.h"
+typedef struct
+{
+ int num_threads_signal; /* the number of threads that are going to be waken up.
+ There are 3 values possible for this parameter, 0, 1,
+ or num_threads_waiting*/
+ int num_threads_waiting; /* the number of threads that are waiting to be awaken */
+} condition_variable_t __attribute__ ((aligned (128)));
+
+typedef eaddr_t cond_ea_t; /* a system memory 64 bit address that points to
+ * a valid condition_variable_t */
+
+
+
+
+#define DECL_COND_VARS() \
+ char _tmp[256]; \
+ char *tmp = (char *) ALIGN(_tmp, 128); \
+ volatile s32 *buf = (volatile s32 *) &tmp[0]; \
+ u32 size = 128, tagid = 0; \
+ s32 status, ret_val; \
+ u32 offset; \
+ addr64 ea64; \
+ condition_variable_t cond_var
+
+#endif /* _SPU_COND_VAR_H_ */
diff --git a/gcell/ibm/sync/spu_source/cond_broadcast.h b/gcell/ibm/sync/spu_source/cond_broadcast.h
new file mode 100644
index 000000000..15a1da330
--- /dev/null
+++ b/gcell/ibm/sync/spu_source/cond_broadcast.h
@@ -0,0 +1,73 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _SPU_COND_BROADCAST_H_
+#define _SPU_COND_BROADCAST_H_
+
+#include "sync_utils.h"
+#include "cond.h"
+#include <spu_mfcio.h>
+
+/**
+ * cond_broadcast - indicate that a condition is true.
+ * @cond: handle to effective address of condition variable.
+ */
+static __inline void _cond_broadcast(cond_ea_t cond)
+{
+ char _tmp[256];
+ char *tmp = (char *) ALIGN(_tmp, 128);
+ volatile unsigned short *buf = (volatile unsigned short *) &tmp[0];
+ unsigned int size = 128, tagid = 0;
+ u32 offset;
+ addr64 ea64;
+
+ ea64.ull = ALIGN128_EA(cond);
+ offset = OFFSET128_EA_U16(cond);
+ MFC_DMA(buf, ea64, size, tagid, MFC_GETLLAR_CMD);
+ spu_readch(MFC_RdAtomicStat);
+
+ /* set the condition variable to the count. So that
+ * all the threads */
+ buf[offset] = buf[offset + 1];
+ MFC_DMA(buf, ea64, size, tagid, MFC_PUTLLUC_CMD);
+ spu_readch(MFC_RdAtomicStat);
+}
+
+#endif /* _SPU_COND_BROADCAST_H_ */
diff --git a/gcell/ibm/sync/spu_source/cond_init.h b/gcell/ibm/sync/spu_source/cond_init.h
new file mode 100644
index 000000000..7202e5352
--- /dev/null
+++ b/gcell/ibm/sync/spu_source/cond_init.h
@@ -0,0 +1,127 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _SPU_COND_INIT_H_
+#define _SPU_COND_INIT_H_
+
+#include "sync_utils.h"
+#include "cond.h"
+#include <spu_mfcio.h>
+
+
+/**
+ * cond_init - initialize condition variable.
+ * @cond: handle to effective address of condition variable.
+ *
+ *
+ * Conditional Variable - is a synchronization device that allows
+ * SPE and PPE threads to suspend execution and relinquish the
+ * processors until some predicate on shared data is satisfied.
+ * The basic operations on conditions are: signal the condition
+ * (when the predicate becomes true), and wait for the condition,
+ * suspending the thread execution until anoter thread signals the
+ * condition
+ *
+ * A condition variable must always be associated with a mutex, to
+ * avoid the race condition where a thread prepares to wait on a
+ * condition variable and another thread signals the condition just
+ * before the first thread actually waits on it.
+ *
+ * cond_init initializes the condition variable cond.
+ *
+ * cond_signal restarts one of the threads that are waiting on the
+ * condition variable cond. If no threads are waiting on cond, nothing
+ * happens. If several threads are waiting on cond, exactly one
+ * is restarted, but it is not specified which
+ *
+ * cond_broadcast restarts all the threads that are waiting on the
+ * condition variable cond. Nothing happens if no threads are waiting
+ * on cond
+ *
+ * cond_wait atomically unlocks the mutex and waits for the condition
+ * variable cond to be signaled. The mutex must be lock locked by
+ * the calling thread on the entrance to cond_wait. Before returning
+ * to the calling thread, cond_wait re-acquires mutex.
+ *
+ * Only one thread initializes a condition variable. Usually, the
+ * PPE thread initializes a condidtion variable, however, a cond_init
+ * function is provided here for completeness
+ *
+ * Description: Initialize a cond variable to false.
+ */
+static __inline void _cond_init(cond_ea_t cond )
+{
+ char _tmp[256];
+ char *tmp = (char *) ALIGN(_tmp, 128);
+ volatile unsigned short *buf = (volatile unsigned short *) &tmp[0];
+ unsigned int size = 128, tagid;
+ unsigned int offset;
+ addr64 ea64;
+ unsigned int oldtmask;
+ unsigned int tagmask;
+
+ tagid = mfc_tag_reserve();
+
+ tagmask = 1 << (tagid & 31);
+
+ ea64.ull = ALIGN128_EA(cond);
+ offset = OFFSET128_EA_U16(cond);
+
+ MFC_DMA(buf, ea64, size, tagid & 31, MFC_GET_CMD);
+ oldtmask = spu_readch(MFC_RdTagMask);
+ spu_writech(MFC_WrTagMask, tagmask);
+ spu_writech(MFC_WrTagUpdate, MFC_TAG_UPDATE_ANY);
+ spu_readch(MFC_RdTagStat);
+
+ /* this is still just one word. since buf is of type
+ * short, we fit both counts into one word. */
+ buf[offset] = 0;
+ buf[offset+1] = 0;
+ MFC_DMA(buf, ea64, size, (tagid & 31), MFC_PUT_CMD);
+ spu_writech(MFC_WrTagMask, tagmask);
+ spu_writech(MFC_WrTagUpdate, MFC_TAG_UPDATE_ANY);
+ spu_readch(MFC_RdTagStat);
+ spu_writech(MFC_WrTagMask, oldtmask);
+ mfc_tag_release (tagid);
+}
+
+
+
+#endif /* _SPU_COND_INIT_H_ */
diff --git a/gcell/ibm/sync/spu_source/cond_signal.h b/gcell/ibm/sync/spu_source/cond_signal.h
new file mode 100644
index 000000000..a035d2875
--- /dev/null
+++ b/gcell/ibm/sync/spu_source/cond_signal.h
@@ -0,0 +1,88 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _SPU_COND_SIGNAL_H_
+#define _SPU_COND_SIGNAL_H_
+#include <stdio.h>
+#include "sync_utils.h"
+#include "cond.h"
+#include "atomic.h"
+#include <spu_mfcio.h>
+
+/*
+ * _cond_signal: signalling any of the waiting threads to wake up.
+ */
+static __inline void _cond_signal(cond_ea_t cond)
+{
+ char _tmp[256];
+ char *tmp = (char *) ALIGN(_tmp, 128);
+ volatile unsigned short *buf = (volatile unsigned short *) &tmp[0];
+ unsigned int size = 128, tagid = 0;
+ u32 offset;
+ addr64 ea64;
+ int status;
+
+ ea64.ull = ALIGN128_EA(cond);
+ offset = OFFSET128_EA_U16(cond);
+
+ do {
+ MFC_DMA(buf, ea64, size, tagid, MFC_GETLLAR_CMD);
+ (void)spu_readch(MFC_RdAtomicStat);
+
+ /* Check for waiting threads.
+ */
+ if (buf[offset] != buf[offset+1]) {
+ /* Increment the signaled count to release the next waiting
+ * thread.
+ */
+ buf[offset]++;
+
+ MFC_DMA(buf, ea64, size, tagid, MFC_PUTLLC_CMD);
+ status = spu_readch(MFC_RdAtomicStat);
+ } else {
+ /* Nobody is waiting, do nothing.
+ */
+ status = 0;
+ }
+ } while (status);
+}
+
+
+#endif /* _SPU_COND_SIGNAL_H_ */
diff --git a/gcell/ibm/sync/spu_source/cond_wait.h b/gcell/ibm/sync/spu_source/cond_wait.h
new file mode 100644
index 000000000..cf4b880f5
--- /dev/null
+++ b/gcell/ibm/sync/spu_source/cond_wait.h
@@ -0,0 +1,103 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _SPU_COND_WAIT_H_
+#define _SPU_COND_WAIT_H_
+#include <stdio.h>
+#include "sync_irq.h"
+#include "sync_utils.h"
+#include "mutex_lock.h"
+#include "mutex_unlock.h"
+#include "cond.h"
+#include <spu_mfcio.h>
+
+static __inline void _cond_wait (cond_ea_t cond, mutex_ea_t mutex)
+{
+ char _tmp[256];
+ char *tmp = (char *) ALIGN(_tmp, 128);
+ volatile signed short *buf = (volatile signed short *) &tmp[0];
+ unsigned int size = 128, tagid = 0;
+ int status;
+ unsigned int offset;
+ addr64 ea64;
+ signed short delta, cur_delta, signaled_cnt;
+
+ ea64.ull = ALIGN128_EA(cond);
+ offset = OFFSET128_EA_U16(cond);
+
+ /* increment the waiting halfword of the condition variable.
+ */
+ do {
+ MFC_DMA(buf, ea64, size, tagid, MFC_GETLLAR_CMD);
+ (void)spu_readch(MFC_RdAtomicStat);
+
+ buf[offset+1]++;
+
+ MFC_DMA(buf, ea64, size, tagid, MFC_PUTLLC_CMD);
+ status = spu_readch(MFC_RdAtomicStat);
+ } while (status);
+
+ _mutex_unlock(mutex);
+
+ /* keep track of the change in count needed to be signaled. This
+ * is delta.
+ */
+ signaled_cnt = buf[offset];
+ delta = buf[offset+1] - signaled_cnt;
+ if (delta < 0) delta = -delta;
+
+ while (1) {
+ MFC_DMA(buf, ea64, size, tagid, MFC_GETLLAR_CMD);
+ (void)spu_readch(MFC_RdAtomicStat);
+
+ cur_delta = buf[offset] - signaled_cnt;
+ if (cur_delta < 0) cur_delta = -cur_delta;
+
+
+ if (cur_delta >= delta) {
+ /* the counts indicate that this thread has been signaled.
+ */
+ break;
+ }
+ }
+ _mutex_lock (mutex);
+}
+
+#endif /* _SPU_COND_WAIT_H_ */
diff --git a/gcell/ibm/sync/spu_source/init_completion.h b/gcell/ibm/sync/spu_source/init_completion.h
new file mode 100644
index 000000000..bf93e72af
--- /dev/null
+++ b/gcell/ibm/sync/spu_source/init_completion.h
@@ -0,0 +1,82 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _SPU_INIT_COMPLETION_H_
+#define _SPU_INIT_COMPLETION_H_
+
+#include "sync_utils.h"
+#include <spu_mfcio.h>
+#include "completion.h"
+
+/**
+ * completion_init - initialize completion variable.
+ * @completion: handle to effective address of completion variable.
+ *
+ * Description: Initialize a completion variable to false.
+ */
+static __inline void _init_completion(completion_ea_t completion)
+{
+ DECL_COMPLETION_VARS();
+ u32 oldtmask, tagmask;
+
+ tagid = mfc_tag_reserve();
+ tagmask = 1 << (tagid & 31);
+
+ ea64.ull = ALIGN128_EA(completion);
+ offset = OFFSET128_EA_U32(completion);
+
+ MFC_DMA(buf, ea64, size, tagid & 31, MFC_GET_CMD);
+ oldtmask = spu_readch(MFC_RdTagMask);
+ spu_writech(MFC_WrTagMask, tagmask);
+ spu_writech(MFC_WrTagUpdate, MFC_TAG_UPDATE_ANY);
+ spu_readch(MFC_RdTagStat);
+
+ buf[offset] = 0;
+ MFC_DMA(buf, ea64, size, tagid & 31, MFC_PUT_CMD);
+ spu_writech(MFC_WrTagMask, tagmask);
+ spu_writech(MFC_WrTagUpdate, MFC_TAG_UPDATE_ANY);
+ spu_readch(MFC_RdTagStat);
+ spu_writech(MFC_WrTagMask, oldtmask);
+ mfc_tag_release(tagid);
+}
+
+
+
+#endif /* _SPU_INIT_COMPLETION_H_ */
diff --git a/gcell/ibm/sync/spu_source/libsync.h b/gcell/ibm/sync/spu_source/libsync.h
new file mode 100644
index 000000000..48cc722bd
--- /dev/null
+++ b/gcell/ibm/sync/spu_source/libsync.h
@@ -0,0 +1,116 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _SPU_LIB_SYNC_H_
+#define _SPU_LIB_SYNC_H_
+#include "sync_utils.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef unsigned long long atomic_ea_t;
+
+extern void atomic_set(atomic_ea_t v, int val);
+extern void atomic_add(int a, atomic_ea_t v);
+extern void atomic_sub(int a, atomic_ea_t v);
+extern void atomic_inc(atomic_ea_t v);
+extern void atomic_dec(atomic_ea_t v);
+
+extern int atomic_read(atomic_ea_t v);
+extern int atomic_add_return(int a, atomic_ea_t v);
+extern int atomic_sub_return(int a, atomic_ea_t v);
+extern int atomic_inc_return(atomic_ea_t v);
+extern int atomic_dec_return(atomic_ea_t v);
+extern int atomic_sub_and_test(int a, atomic_ea_t v);
+extern int atomic_dec_and_test(atomic_ea_t v);
+extern int atomic_dec_if_positive(atomic_ea_t v);
+
+typedef unsigned long long mutex_ea_t;
+
+extern void mutex_init(mutex_ea_t lock);
+extern void mutex_lock(mutex_ea_t lock);
+extern int mutex_trylock(mutex_ea_t ea);
+extern void mutex_unlock(mutex_ea_t lock);
+
+
+typedef struct
+{
+ int num_threads_signal; /* the number of threads that are going to be waken up.
+ * There are 3 values possible for this parameter, 0, 1,
+ * or num_threads_waiting
+ */
+ int num_threads_waiting; /* the number of threads that are waiting to be awaken
+ */
+} condition_variable_t __attribute__ ((aligned (128)));
+
+typedef eaddr_t cond_ea_t; /* a system memory 64 bit address that points to
+ * a valid condition_variable_t
+ */
+
+
+extern void cond_init (cond_ea_t cond);
+extern void cond_signal (cond_ea_t cond);
+extern void cond_broadcast (cond_ea_t cond);
+extern void cond_wait (cond_ea_t cond, mutex_ea_t mutex);
+
+typedef unsigned long long completion_ea_t;
+
+extern void init_completion(completion_ea_t completion);
+extern void wait_for_completion(completion_ea_t completion);
+extern void complete(completion_ea_t completion);
+extern void complete_all(completion_ea_t completion);
+
+#ifdef __SPU__
+ /* Function only implemented for the SPU
+ */
+ extern void read_lock(eaddr_t ea);
+ extern void read_unlock(eaddr_t ea);
+ extern int read_trylock(eaddr_t ea);
+ extern void write_lock(eaddr_t ea);
+ extern void write_unlock(eaddr_t ea);
+ extern int write_trylock(eaddr_t ea);
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _SPU_LIB_SYNC_H_ */
diff --git a/gcell/ibm/sync/spu_source/mutex.h b/gcell/ibm/sync/spu_source/mutex.h
new file mode 100644
index 000000000..37f2b4d62
--- /dev/null
+++ b/gcell/ibm/sync/spu_source/mutex.h
@@ -0,0 +1,178 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _SPU_MUTEX_H_
+#define _SPU_MUTEX_H_ 1
+
+#include "sync_utils.h"
+#include "sync_irq.h"
+#include <spu_mfcio.h>
+
+typedef eaddr_t mutex_ea_t;
+
+#define DECL_MUTEX_VARS() \
+ char _tmp[256]; \
+ char *tmp = (char *) ALIGN(_tmp, 128); \
+ volatile s32 *buf = (volatile s32 *) &tmp[0]; \
+ u32 size = 128, tagid = 0; \
+ u32 offset; \
+ addr64 ea64
+
+/* RAW_TEST_AND_SET
+ * Macro implementing the test and set primitive.
+ *
+ * RAW_TEST_AND_SET(==, 1) used by spin_try_lock()
+ * RAW_TEST_AND_SET(>=, 1) used by read_try_lock()
+ * RAW_TEST_AND_SET(==, -1) used by write_try_lock()
+ */
+#define RAW_TEST_AND_SET(_RELOP_, _val) \
+ ea64.ull = ALIGN128_EA(ea); \
+ offset = OFFSET128_EA_U32(ea); \
+ do { \
+ MFC_DMA(buf, ea64, size, tagid, MFC_GETLLAR_CMD); \
+ spu_readch(MFC_RdAtomicStat); \
+ SET_HIT; \
+ if (likely(buf[offset] _RELOP_ 0)) { \
+ buf[offset] += _val; \
+ MFC_DMA(buf, ea64, size, tagid, MFC_PUTLLC_CMD); \
+ status = spu_readch(MFC_RdAtomicStat); \
+ ret_val = 1; \
+ } else { \
+ MFC_DMA(buf, ea64, size, tagid, MFC_PUTLLC_CMD); \
+ spu_readch(MFC_RdAtomicStat); \
+ status = ret_val = 0; \
+ break; \
+ } \
+ } while (status != 0)
+
+/* RAW_SPINLOCK
+ * Macro implementing the spinlock primitive.
+ *
+ * RAW_SPINLOCK(==, 1) used by spin_lock()
+ * RAW_SPINLOCK(>=, 1) used by read_lock()
+ * RAW_SPINLOCK(==, -1) used by write_lock()
+ */
+
+
+#define RAW_SPINLOCK(_RELOP_, _val) \
+ ea64.ull = ALIGN128_EA(ea); \
+ offset = OFFSET128_EA_U32(ea); \
+ do { \
+ MFC_DMA(buf, ea64, size, tagid, MFC_GETLLAR_CMD); \
+ spu_readch(MFC_RdAtomicStat); \
+ SET_HIT; \
+ status = 1; \
+ if (likely(buf[offset] _RELOP_ 0)) { \
+ buf[offset] += _val; \
+ MFC_DMA(buf, ea64, size, tagid, MFC_PUTLLC_CMD); \
+ status = spu_readch(MFC_RdAtomicStat); \
+ } \
+ } while (status != 0);
+
+
+static inline void _lock_init(eaddr_t ea)
+{
+ DECL_MUTEX_VARS();
+ u32 oldtmask, tagmask;
+
+ tagid = mfc_tag_reserve();
+
+ tagmask = 1 << (tagid & 31);
+
+ /* __lock_init
+ * Internal routine to initialize a spinlock or
+ * reader/writer lock.
+ */
+ ea64.ull = ALIGN128_EA(ea);
+ offset = OFFSET128_EA_U32(ea);
+ MFC_DMA(buf, ea64, size, tagid & 31, MFC_GET_CMD);
+ oldtmask = spu_readch(MFC_RdTagMask);
+ spu_writech(MFC_WrTagMask, tagmask);
+ spu_writech(MFC_WrTagUpdate, MFC_TAG_UPDATE_ANY);
+ spu_readch(MFC_RdTagStat);
+
+ buf[offset] = 0;
+ MFC_DMA(buf, ea64, size, tagid & 31, MFC_PUT_CMD);
+ spu_writech(MFC_WrTagMask, tagmask);
+ spu_writech(MFC_WrTagUpdate, MFC_TAG_UPDATE_ANY);
+ spu_readch(MFC_RdTagStat);
+ spu_writech(MFC_WrTagMask, oldtmask);
+ mfc_tag_release(tagid);
+}
+
+static inline void _spin_lock(eaddr_t ea)
+{
+ DECL_MUTEX_VARS();
+ s32 status;
+
+ /* _spin_lock
+ * Internal routine to acquire spinlock.
+ */
+/* non trace - no hit/miss indicator */
+#define SET_HIT
+ RAW_SPINLOCK(==, 1);
+}
+
+#ifdef LIBSYNC_TRACE
+static inline s32 _spin_lock_trace(eaddr_t ea)
+{
+ DECL_MUTEX_VARS();
+ s32 status = 0;
+/* trace - need hit/miss indicator */
+#undef SET_HIT
+#define SET_HIT if (status == 0) hit = buf[offset]
+ s32 hit;
+
+ hit = 0;
+ /* _spin_lock_trace for trace
+ * Internal routine to acquire spinlock.
+ */
+ RAW_SPINLOCK(==, 1);
+
+ return hit;
+
+#undef SET_HIT
+#define SET_HIT
+}
+
+#endif /* LIBSYNC_TRACE */
+
+
+#endif /* SPU_MUTEX_H */
diff --git a/gcell/ibm/sync/spu_source/mutex_init.h b/gcell/ibm/sync/spu_source/mutex_init.h
new file mode 100644
index 000000000..9bddb1456
--- /dev/null
+++ b/gcell/ibm/sync/spu_source/mutex_init.h
@@ -0,0 +1,64 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _SPU_MUTEX_INIT_H_
+#define _SPU_MUTEX_INIT_H_
+
+#include "sync_utils.h"
+#include "mutex.h"
+#include "trace_libsync.h"
+
+/***************************************************************************/
+/**
+ * mutex_init - initialize the mutex by setting the value
+ * to 0.
+ * @lock: handle to effective address of lock variable.
+ *
+ * Description: Initialize a mutex.
+ */
+static __inline void _mutex_init(mutex_ea_t lock)
+{
+ _lock_init(lock);
+
+ TRACE_MUTEX_INIT(lock);
+}
+
+
+#endif /* _SPU_MUTEX_INIT_H_ */
diff --git a/gcell/ibm/sync/spu_source/mutex_lock.h b/gcell/ibm/sync/spu_source/mutex_lock.h
new file mode 100644
index 000000000..63bdbc36a
--- /dev/null
+++ b/gcell/ibm/sync/spu_source/mutex_lock.h
@@ -0,0 +1,66 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _SPU_MUTEX_LOCK_H_
+#define _SPU_MUTEX_LOCK_H_
+
+#include "sync_utils.h"
+#include "mutex.h"
+#include "trace_libsync.h"
+
+static __inline void _mutex_lock(mutex_ea_t ea)
+{
+
+#ifdef LIBSYNC_TRACE
+ s32 miss = 0;
+
+ TRACE_MUTEX_LOCK_ENTRY(interval);
+ miss = _spin_lock_trace(ea);
+ TRACE_MUTEX_LOCK_EXIT(interval, ea, miss);
+
+#else /* LIBSYNC_TRACE */
+
+ _spin_lock(ea);
+
+#endif /* LIBSYNC_TRACE */
+
+}
+
+#endif /* _SPU_MUTEX_LOCK_H_ */
diff --git a/gcell/ibm/sync/spu_source/mutex_trylock.h b/gcell/ibm/sync/spu_source/mutex_trylock.h
new file mode 100644
index 000000000..3c8df4662
--- /dev/null
+++ b/gcell/ibm/sync/spu_source/mutex_trylock.h
@@ -0,0 +1,70 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _SPU_MUTEX_TRYLOCK_H_
+#define _SPU_MUTEX_TRYLOCK_H_
+
+#include "sync_utils.h"
+#include "mutex.h"
+#include "trace_libsync.h"
+
+/**
+ * mutex_trylock - acquire a lock, or return immediately.
+ * @ea: handle to effective address of lock variable.
+ *
+ * Description: Acquire a lock, or return immediately
+ * without polling for availability.
+ *
+ * Context: The application should not call this interface
+ * from a tight loop!! Use spin_lock() instead.
+ */
+static __inline int _mutex_trylock(mutex_ea_t ea)
+{
+ DECL_MUTEX_VARS();
+ s32 status, ret_val;
+
+ RAW_TEST_AND_SET(==, 1);
+
+ TRACE_MUTEX_TRYLOCK(ea, ret_val);
+
+ return ret_val;
+}
+
+#endif /* _SPU_MUTEX_TRYLOCK_H_ */
diff --git a/gcell/ibm/sync/spu_source/mutex_unlock.h b/gcell/ibm/sync/spu_source/mutex_unlock.h
new file mode 100644
index 000000000..87d6bbaef
--- /dev/null
+++ b/gcell/ibm/sync/spu_source/mutex_unlock.h
@@ -0,0 +1,59 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _SPU_MUTEX_UNLOCK_H_
+#define _SPU_MUTEX_UNLOCK_H_
+
+#include "sync_utils.h"
+#include "mutex.h"
+#include "atomic.h"
+#include "trace_libsync.h"
+
+static __inline void _mutex_unlock(mutex_ea_t ea)
+{
+ int ret_val;
+
+ ATOMIC_OP((atomic_ea_t)ea, 0, 1, ret_val);
+
+ TRACE_MUTEX_UNLOCK(ea);
+}
+
+
+#endif /* _SPU_MUTEX_UNLOCK_H_ */
diff --git a/gcell/ibm/sync/spu_source/read_lock.h b/gcell/ibm/sync/spu_source/read_lock.h
new file mode 100644
index 000000000..0e1d97182
--- /dev/null
+++ b/gcell/ibm/sync/spu_source/read_lock.h
@@ -0,0 +1,66 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _SPU_READ_LOCK_H_
+#define _SPU_READ_LOCK_H_
+
+#include "sync_utils.h"
+#include "mutex.h"
+
+/**
+ * read_lock - acquire reader lock, or spin until available.
+ * @ea: handle to effective address of lock variable.
+ *
+ * Description: Acquire a non-exclusive reader lock, or spin
+ * until available. The only restriction here is that @ea
+ * must be word aligned.
+ *
+ * Context: This routine should not be called if SPU
+ * asynchronous interrupts are enabled.
+ */
+static __inline void _read_lock(eaddr_t ea)
+{
+ DECL_MUTEX_VARS();
+ s32 status;
+
+ RAW_SPINLOCK(>=, 1);
+}
+
+#endif /* _SPU_READ_LOCK_H_ */
diff --git a/gcell/ibm/sync/spu_source/read_trylock.h b/gcell/ibm/sync/spu_source/read_trylock.h
new file mode 100644
index 000000000..d03278351
--- /dev/null
+++ b/gcell/ibm/sync/spu_source/read_trylock.h
@@ -0,0 +1,71 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _SPU_READ_TRYLOCK_H_
+#define _SPU_READ_TRYLOCK_H_
+
+#include "sync_utils.h"
+#include "mutex.h"
+
+/**
+ * read_trylock - acquire a reader lock, or return immediately.
+ * @ea: handle to effective address of lock variable.
+ *
+ * Acquire a non-exclusive reader lock, or return
+ * immediately. The only restriction here is that
+ * @ea must be word aligned.
+ *
+ * Returns 1 on success, or 0 on failure.
+ *
+ * Context: The application should not call this interface
+ * from a tight loop!! Use read_lock() instead.
+ */
+static __inline int _read_trylock(eaddr_t ea)
+{
+ DECL_MUTEX_VARS();
+ s32 status, ret_val;
+
+ RAW_TEST_AND_SET(>=, 1);
+
+ return ret_val;
+}
+
+
+#endif /* _SPU_READ_TRYLOCK_H_ */
diff --git a/gcell/ibm/sync/spu_source/read_unlock.h b/gcell/ibm/sync/spu_source/read_unlock.h
new file mode 100644
index 000000000..f011550e5
--- /dev/null
+++ b/gcell/ibm/sync/spu_source/read_unlock.h
@@ -0,0 +1,88 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _SPU_READ_UNLOCK_H_
+#define _SPU_READ_UNLOCK_H_
+
+#include "sync_utils.h"
+#include "mutex.h"
+#include <spu_mfcio.h>
+
+
+/**
+ * read_unlock - release reader lock.
+ * @ea: handle to effective address of lock variable.
+ *
+ * Description: Release a reader lock. The only restriction
+ * here is that @ea must be word aligned.
+ *
+ * Context: This routine should be used when interrupts
+ * do not need to be re-enabled --either because interrupts
+ * are not being used, or because the application will take
+ * steps to re-enable them later.
+ */
+static __inline void _read_unlock(eaddr_t ea)
+{
+ DECL_MUTEX_VARS();
+ s32 status;
+
+ /* _read_unlock
+ *
+ * Reader locks must use PUTLLC when releasing, instead of
+ * the more traditional PUTLLUC because of the non-exclusive
+ * nature of the lock. The reason for this is that other
+ * readers may have incremented the counter, and we don't
+ * want to corrupt it by blindly issuing PUTLLUC!!
+ */
+ ea64.ull = ALIGN128_EA(ea);
+ offset = OFFSET128_EA_U32(ea);
+ do {
+ MFC_DMA(buf, ea64, size, tagid, MFC_GETLLAR_CMD);
+ spu_readch(MFC_RdAtomicStat);
+
+ buf[offset] -= 1;
+ MFC_DMA(buf, ea64, size, tagid, MFC_PUTLLC_CMD);
+ status = spu_readch(MFC_RdAtomicStat);
+ } while (status != 0);
+
+}
+
+
+#endif /* _SPU_READ_UNLOCK_H_ */
diff --git a/gcell/ibm/sync/spu_source/rwlock_init.h b/gcell/ibm/sync/spu_source/rwlock_init.h
new file mode 100644
index 000000000..6b05533bb
--- /dev/null
+++ b/gcell/ibm/sync/spu_source/rwlock_init.h
@@ -0,0 +1,60 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _SPU_RWLOCK_INIT_H_
+#define _SPU_RWLOCK_INIT_H_
+
+#include "sync_utils.h"
+#include "mutex.h"
+
+/**
+ * rwlock_init - initialize a reader/writer lock.
+ * @ea: handle to effective address of lock variable.
+ *
+ * Description: Initialize a reader/writer lock.
+ */
+static __inline void _rwlock_init(eaddr_t rwlock)
+{
+ _lock_init(rwlock);
+}
+
+
+
+#endif /* _SPU_RWLOCK_INIT_H_ */
diff --git a/gcell/ibm/sync/spu_source/sync_irq.h b/gcell/ibm/sync/spu_source/sync_irq.h
new file mode 100644
index 000000000..feae65e50
--- /dev/null
+++ b/gcell/ibm/sync/spu_source/sync_irq.h
@@ -0,0 +1,76 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+/*
+ * irq.h - SPU interrupt management facilities.
+ *
+ * These utilities help an "interrupt aware" library to manage
+ * state of SPU interrupts.
+ */
+
+#ifndef __SPU_IRQ_H__
+#define __SPU_IRQ_H__
+
+#include <spu_intrinsics.h>
+#include "sync_utils.h"
+
+static inline u32 irq_mask(u32 newmask)
+{
+ u32 old, tmp = 0;
+
+ /* irq_mask
+ * Set the interrupt mask to the newmask value,
+ * and return its previous setting. Will
+ * detect and discard potential phantom
+ * events.
+ */
+
+ old = spu_readch(SPU_RdEventMask);
+ spu_writech(SPU_WrEventMask, tmp);
+ if (spu_readchcnt(SPU_RdEventStat)) {
+ tmp = spu_readch(SPU_RdEventStat);
+ spu_writech(SPU_WrEventAck, tmp);
+ }
+ spu_writech(SPU_WrEventMask, newmask);
+
+ return old;
+}
+
+#endif /* __SPU_IRQ_H__ */
diff --git a/gcell/ibm/sync/spu_source/sync_utils.h b/gcell/ibm/sync/spu_source/sync_utils.h
new file mode 100644
index 000000000..516b41f74
--- /dev/null
+++ b/gcell/ibm/sync/spu_source/sync_utils.h
@@ -0,0 +1,103 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+/*
+ * sync_utils.h - SPU sync-library internal utilities.
+ *
+ * These utilities are used internally by the SPU sync library.
+ */
+#ifndef __SPU_SYNC_UTILS_H__
+#define __SPU_SYNC_UTILS_H__
+
+#include <spu_intrinsics.h>
+
+typedef unsigned int u32;
+typedef signed int s32;
+typedef unsigned long long u64;
+typedef unsigned long long eaddr_t;
+
+
+typedef union {
+ u64 ull;
+ u32 ui[2];
+} addr64;
+
+#ifndef likely
+#define likely(_c) \
+ __builtin_expect((_c), 1)
+#define unlikely(_c) \
+ __builtin_expect((_c), 0)
+#endif
+
+#define ALLOCA(_nbytes, _size) \
+ alloca((_nbytes) + (_size)-1)
+
+#define ALIGN(_ptr, _size) \
+ ((((u32) _ptr) + (_size)-1) & ~((_size)-1))
+
+#define ALIGN128_EA(_ull) \
+ ((_ull) & ~(127ULL))
+/*
+#define OFFSET128_EA(_ull, _type) \
+ (((_ull) & 127ULL) / sizeof(_type))
+ */
+
+#define OFFSET128_EA_U32(_ull) \
+ (((_ull) & 127ULL) >> 2)
+
+#define OFFSET128_EA_U16(_ull) \
+ (((_ull) & 127ULL) >> 1)
+
+#define MFC_DMA(_ls, _ea, _sz, _tg, _cmd) \
+ spu_mfcdma64(_ls, _ea.ui[0], _ea.ui[1], _sz, _tg, _cmd)
+
+#define MFC_SYNC() { \
+ u32 _tagid = 0; \
+ spu_writech(mfc_tag_id, _tagid); \
+ spu_writech(mfc_cmd_queue, MFC_SYNC_CMD); \
+}
+
+#define MFC_EIEIO() { \
+ u32 _tagid = 0; \
+ spu_writech(mfc_tag_id, _tagid); \
+ spu_writech(mfc_cmd_queue, MFC_EIEIO_CMD); \
+}
+
+#endif /* __SPU_SYNC_UTILS_H__ */
diff --git a/gcell/ibm/sync/spu_source/trace_libsync.h b/gcell/ibm/sync/spu_source/trace_libsync.h
new file mode 100644
index 000000000..47887c9dc
--- /dev/null
+++ b/gcell/ibm/sync/spu_source/trace_libsync.h
@@ -0,0 +1,117 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2007 */
+/* International Business Machines Corporation */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef __LIBSYNC_SPU_TRACEHOOKS_H__
+#define __LIBSYNC_SPU_TRACEHOOKS_H__
+
+#ifdef LIBSYNC_TRACE
+
+#include <trace_events.h>
+
+/*
+ * last parameter in the trace_even and trace_interval_entry call is
+ * the stack level to report the PC in the trace record. so 0 means
+ * the PC of the current frame, 1 means the PC of the caller, etc.
+ * there's a dilemma here - these macros are included in the inline
+ * _mutex calls which get called from the (created during build)
+ * mutex functions in the mutex .c files. in that case, the level
+ * should be 1 - we don't want the PC of where in the mutex function
+ * the trace call is happening, we want the PC of whomever is calling
+ * the mutex function.
+ *
+ * but.. an app can call the inline functions - it can #include the
+ * appropriate libsync mutex .h files, and call the inlined _mutex
+ * function in their code. in that case, the appropriate level for the
+ * trace calls would be 0 - the user would want to know where in their
+ * code the call to the _mutex function is.
+ *
+ * so, we'll assume _LEVEL of 0 which is what the inline funtions need.
+ * when we build the files for libsync, we'll do a -D_LEVEL=1
+ */
+#ifndef _LEVEL
+#define _LEVEL 0
+#endif
+
+
+#define TRACE_EVENT_MUTEX_INIT 0x0403
+
+#define TRACE_MUTEX_INIT(lock) { \
+ trace_payload_t payload; \
+ payload.dword[0]=(unsigned long)lock; \
+ trace_event(TRACE_EVENT_MUTEX_INIT, 1, &payload, "Event=%d, lock=0x%x", _LEVEL); \
+}
+
+#define TRACE_EVENT_MUTEX_LOCK 0x0503
+
+#define TRACE_MUTEX_LOCK_ENTRY(_INTERVAL) \
+trace_interval_p _INTERVAL = trace_interval_entry(TRACE_EVENT_MUTEX_LOCK, _LEVEL)
+
+#define TRACE_MUTEX_LOCK_EXIT(_INTERVAL,lock,miss) { \
+ trace_payload_t payload; \
+ payload.dword[0]=(unsigned long)lock; \
+ payload.word[2]=(unsigned int)miss; \
+ trace_interval_exit(_INTERVAL, 2, &payload, "Event=%d, lock=0x%x, miss=0x%x"); \
+}
+
+#define TRACE_EVENT_MUTEX_TRYLOCK 0x0603
+
+#define TRACE_MUTEX_TRYLOCK(lock,ret_val) { \
+ trace_payload_t payload; \
+ payload.dword[0]=(unsigned long)lock; \
+ payload.word[2]=(unsigned int)ret_val; \
+ trace_event(TRACE_EVENT_MUTEX_TRYLOCK, 2, &payload, "Event=%d, lock=0x%x, ret_val=0x%x", _LEVEL); \
+}
+
+#define TRACE_EVENT_MUTEX_UNLOCK 0x0703
+
+#define TRACE_MUTEX_UNLOCK(lock) { \
+ trace_payload_t payload; \
+ payload.dword[0]=(unsigned long)lock; \
+ trace_event(TRACE_EVENT_MUTEX_UNLOCK, 1, &payload, "Event=%d, lock=0x%x", _LEVEL); \
+}
+
+#else /* LIBSYNC_TRACE */
+
+#define TRACE_MUTEX_INIT(lock)
+#define TRACE_MUTEX_LOCK_ENTRY(_INTERVAL)
+#define TRACE_MUTEX_LOCK_EXIT(_INTERVAL,lock,miss)
+#define TRACE_MUTEX_TRYLOCK(lock,ret_val)
+#define TRACE_MUTEX_UNLOCK(lock)
+
+#endif /* LIBSYNC_TRACE */
+
+#endif /* __LIBSYNC_SPU_TRACEHOOKS_H__ */
diff --git a/gcell/ibm/sync/spu_source/wait_for_completion.h b/gcell/ibm/sync/spu_source/wait_for_completion.h
new file mode 100644
index 000000000..ea7bdbe6d
--- /dev/null
+++ b/gcell/ibm/sync/spu_source/wait_for_completion.h
@@ -0,0 +1,82 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _SPU_WAIT_FOR_COMPLETION_H_
+#define _SPU_WAIT_FOR_COMPLETION_H_
+
+#include "sync_utils.h"
+#include <spu_mfcio.h>
+#include "sync_irq.h"
+#include "completion.h"
+
+/* _wait_for_completion
+ * Internal routine to wait for completion to
+ * become true (!0). When completion is false,
+ * uses lock line reservation lost event to
+ * sleep until the variable has been changed.
+ */
+static __inline void _wait_for_completion(completion_ea_t completion)
+{
+ DECL_COMPLETION_VARS();
+ s32 status;
+
+ status = 1;
+
+ ea64.ull = ALIGN128_EA(completion);
+ offset = OFFSET128_EA_U32(completion);
+ do {
+ MFC_DMA(buf, ea64, size, tagid, MFC_GETLLAR_CMD);
+ spu_readch(MFC_RdAtomicStat);
+ /* if the completion variable has been set elsewhere
+ * (a signal or broadcast function has been called
+ * then we get out of the loop, and reset the variable */
+ if (likely(buf[offset] != 0)) {
+ /* decrement the variable */
+ buf[offset]--;
+ MFC_DMA(buf, ea64, size, tagid, MFC_PUTLLC_CMD);
+ spu_readch(MFC_RdAtomicStat);
+ status = 0;
+ }
+ } while (status != 0);
+}
+
+
+
+#endif /* _SPU_WAIT_FOR_COMPLETION_H_ */
diff --git a/gcell/ibm/sync/spu_source/write_lock.h b/gcell/ibm/sync/spu_source/write_lock.h
new file mode 100644
index 000000000..7af5175f0
--- /dev/null
+++ b/gcell/ibm/sync/spu_source/write_lock.h
@@ -0,0 +1,67 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _SPU_WRITE_LOCK_H_
+#define _SPU_WRITE_LOCK_H_
+
+#include "sync_utils.h"
+#include "mutex.h"
+
+/**
+ * write_lock - acquire writer lock, or spin until available.
+ * @ea: handle to effective address of lock variable.
+ *
+ * Description: Acquire an exclusive writer lock,
+ * or spin until available. The only restriction
+ * here is that @ea must be word aligned.
+ *
+ * Context: This routine should not be called if SPU
+ * asynchronous interrupts are enabled.
+ */
+static __inline void _write_lock(eaddr_t ea)
+{
+ DECL_MUTEX_VARS();
+ s32 status;
+
+ RAW_SPINLOCK(==, -1);
+}
+
+
+#endif /* _SPU_WRITE_LOCK_H_ */
diff --git a/gcell/ibm/sync/spu_source/write_trylock.h b/gcell/ibm/sync/spu_source/write_trylock.h
new file mode 100644
index 000000000..b3799b37e
--- /dev/null
+++ b/gcell/ibm/sync/spu_source/write_trylock.h
@@ -0,0 +1,72 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _SPU_WRITE_TRYLOCK_H_
+#define _SPU_WRITE_TRYLOCK_H_
+
+#include "sync_utils.h"
+#include "mutex.h"
+
+/**
+ * write_trylock - acquire a writer lock, or return immediately.
+ * @ea: handle to effective address of lock variable.
+ *
+ * Try to acquire an exclusive writer lock, or return
+ * immediately. The only restriction here is that @ea
+ * must be word aligned.
+ *
+ * Returns 1 on success, or 0 on failure.
+ *
+ * Caution:
+ * The application should not call this interface from a tight
+ * loop!! Use write_lock() instead.
+ */
+static __inline int _write_trylock(eaddr_t ea)
+{
+ DECL_MUTEX_VARS();
+ s32 status, ret_val;
+
+ RAW_TEST_AND_SET(==, -1);
+
+ return ret_val;
+}
+
+
+#endif /* _SPU_WRITE_TRYLOCK_H_ */
diff --git a/gcell/ibm/sync/spu_source/write_unlock.h b/gcell/ibm/sync/spu_source/write_unlock.h
new file mode 100644
index 000000000..25b24e181
--- /dev/null
+++ b/gcell/ibm/sync/spu_source/write_unlock.h
@@ -0,0 +1,69 @@
+/* -------------------------------------------------------------- */
+/* (C)Copyright 2001,2007, */
+/* International Business Machines Corporation, */
+/* Sony Computer Entertainment, Incorporated, */
+/* Toshiba Corporation, */
+/* */
+/* All Rights Reserved. */
+/* */
+/* Redistribution and use in source and binary forms, with or */
+/* without modification, are permitted provided that the */
+/* following conditions are met: */
+/* */
+/* - Redistributions of source code must retain the above copyright*/
+/* notice, this list of conditions and the following disclaimer. */
+/* */
+/* - Redistributions in binary form must reproduce the above */
+/* copyright notice, this list of conditions and the following */
+/* disclaimer in the documentation and/or other materials */
+/* provided with the distribution. */
+/* */
+/* - Neither the name of IBM Corporation nor the names of its */
+/* contributors may be used to endorse or promote products */
+/* derived from this software without specific prior written */
+/* permission. */
+/* */
+/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
+/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
+/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
+/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
+/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR */
+/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
+/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT */
+/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
+/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) */
+/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN */
+/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
+/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */
+/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+/* -------------------------------------------------------------- */
+/* PROLOG END TAG zYx */
+#ifndef _SPU_WRITE_UNLOCK_H_
+#define _SPU_WRITE_UNLOCK_H_
+
+#include "sync_utils.h"
+#include "mutex.h"
+#include <spu_mfcio.h>
+
+/**
+ * write_unlock - release writer lock.
+ * @rwlock: handle to effective address of lock variable.
+ *
+ * Release a single writer lock.
+ */
+static __inline void _write_unlock(eaddr_t rwlock)
+{
+ DECL_MUTEX_VARS();
+
+ ea64.ull = ALIGN128_EA(rwlock);
+ offset = OFFSET128_EA_U32(rwlock);
+ MFC_DMA(buf, ea64, size, tagid, MFC_GETLLAR_CMD);
+ spu_readch(MFC_RdAtomicStat);
+
+ buf[offset] = 0;
+ MFC_DMA(buf, ea64, size, tagid, MFC_PUTLLUC_CMD);
+ spu_readch(MFC_RdAtomicStat);
+}
+
+
+#endif /* _SPU_WRITE_UNLOCK_H_ */