2 * include/asm-s390/spinlock.h
5 * Copyright (C) 1999 IBM Deutschland Entwicklung GmbH, IBM Corporation
6 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com)
8 * Derived from "include/asm-i386/spinlock.h"
11 #ifndef __ASM_SPINLOCK_H
12 #define __ASM_SPINLOCK_H
15 * Simple spin lock operations. There are two variants, one clears IRQ's
16 * on the local processor, one does not.
18 * We make no fairness assumptions. They have a cost.
22 volatile unsigned long lock;
25 #define SPIN_LOCK_UNLOCKED (spinlock_t) { 0 }
26 #define spin_lock_init(lp) do { (lp)->lock = 0; } while(0)
27 #define spin_unlock_wait(lp) do { barrier(); } while(((volatile spinlock_t *)(lp))->lock)
28 #define spin_is_locked(x) ((x)->lock != 0)
30 extern inline void spin_lock(spinlock_t *lp)
32 unsigned int reg1, reg2;
33 __asm__ __volatile(" bras %0,1f\n"
38 : "=&d" (reg1), "=&d" (reg2)
39 : "a" (&lp->lock) : "cc", "memory" );
42 extern inline int spin_trylock(spinlock_t *lp)
44 unsigned long result, reg;
45 __asm__ __volatile(" slr %0,%0\n"
48 : "=&d" (result), "=&d" (reg)
49 : "a" (&lp->lock) : "cc", "memory" );
53 extern inline void spin_unlock(spinlock_t *lp)
55 __asm__ __volatile(" xc 0(4,%0),0(%0)\n"
57 : : "a" (&lp->lock) : "memory", "cc" );
61 * Read-write spinlocks, allowing multiple readers
62 * but only one writer.
64 * NOTE! it is quite common to have readers in interrupts
65 * but no interrupt writers. For those circumstances we
66 * can "mix" irq-safe locks - any writer needs to get a
67 * irq-safe write-lock, but readers can get non-irqsafe
71 volatile unsigned long lock;
72 volatile unsigned long owner_pc;
75 #define RW_LOCK_UNLOCKED (rwlock_t) { 0, 0 }
77 #define rwlock_init(x) do { *(x) = RW_LOCK_UNLOCKED; } while(0)
79 #define read_lock(rw) \
80 asm volatile(" l 2,0(%0)\n" \
83 "1: la 2,0(2)\n" /* clear high (=write) bit */ \
84 " la 3,1(2)\n" /* one more reader */ \
85 " cs 2,3,0(%0)\n" /* try to write new value */ \
87 : : "a" (&(rw)->lock) : "2", "3", "cc", "memory" )
89 #define read_unlock(rw) \
90 asm volatile(" l 2,0(%0)\n" \
94 " ahi 3,-1\n" /* one less reader */ \
97 : : "a" (&(rw)->lock) : "2", "3", "cc", "memory" )
99 #define write_lock(rw) \
100 asm volatile(" lhi 3,1\n" \
101 " sll 3,31\n" /* new lock value = 0x80000000 */ \
104 "1: slr 2,2\n" /* old lock value must be 0 */ \
107 : : "a" (&(rw)->lock) : "2", "3", "cc", "memory" )
109 #define write_unlock(rw) \
110 asm volatile(" slr 3,3\n" /* new lock value = 0 */ \
114 " sll 2,31\n" /* old lock value must be 0x80000000 */ \
117 : : "a" (&(rw)->lock) : "2", "3", "cc", "memory" )
119 #endif /* __ASM_SPINLOCK_H */