#ifndef _POWERPC_LOCK_H_
#define _POWERPC_LOCK_H_
#ifdef _KERNEL_OPT
#include "opt_ppcarch.h"
#endif
static __inline int
__SIMPLELOCK_LOCKED_P(const __cpu_simple_lock_t *__ptr)
{
return *__ptr == __SIMPLELOCK_LOCKED;
}
static __inline int
__SIMPLELOCK_UNLOCKED_P(const __cpu_simple_lock_t *__ptr)
{
return *__ptr == __SIMPLELOCK_UNLOCKED;
}
static __inline void
__cpu_simple_lock_clear(__cpu_simple_lock_t *__ptr)
{
*__ptr = __SIMPLELOCK_UNLOCKED;
}
static __inline void
__cpu_simple_lock_set(__cpu_simple_lock_t *__ptr)
{
*__ptr = __SIMPLELOCK_LOCKED;
}
static __inline void
__cpu_simple_lock_init(__cpu_simple_lock_t *alp)
{
*alp = __SIMPLELOCK_UNLOCKED;
}
static __inline void
__cpu_simple_lock(__cpu_simple_lock_t *alp)
{
int old;
__asm volatile (" \
\n\
1: lwarx %0,0,%1 \n\
cmpwi %0,%2 \n\
beq+ 3f \n\
2: lwzx %0,0,%1 \n\
cmpwi %0,%2 \n\
beq+ 1b \n\
b 2b \n\
3: \n"
#ifdef IBM405_ERRATA77
"dcbt 0,%1 \n"
#elif defined(PPC_IBMESPRESSO)
"dcbst 0,%1 \n"
#endif
"stwcx. %3,0,%1 \n\
bne- 1b \n\
isync \n\
\n"
: "=&r"(old)
: "r"(alp), "I"(__SIMPLELOCK_UNLOCKED), "r"(__SIMPLELOCK_LOCKED)
: "memory");
}
static __inline int
__cpu_simple_lock_try(__cpu_simple_lock_t *alp)
{
int old, dummy;
__asm volatile (" \
\n\
1: lwarx %0,0,%1 \n\
cmpwi %0,%2 \n\
bne 2f \n"
#ifdef IBM405_ERRATA77
"dcbt 0,%1 \n"
#elif defined(PPC_IBMESPRESSO)
"dcbst 0,%1 \n"
#endif
"stwcx. %3,0,%1 \n\
bne- 1b \n\
2: \n"
#ifdef IBM405_ERRATA77
"dcbt 0,%4 \n"
#elif defined(PPC_IBMESPRESSO)
"dcbst 0,%4 \n"
#endif
"stwcx. %3,0,%4 \n\
isync \n\
\n"
: "=&r"(old)
: "r"(alp), "I"(__SIMPLELOCK_UNLOCKED), "r"(__SIMPLELOCK_LOCKED),
"r"(&dummy)
: "memory");
return (old == __SIMPLELOCK_UNLOCKED);
}
static __inline void
__cpu_simple_unlock(__cpu_simple_lock_t *alp)
{
__asm volatile ("sync");
*alp = __SIMPLELOCK_UNLOCKED;
}
#endif