1 /* smpprim.h: SMP locking primitives on the Sparc 2 * 3 * God knows we won't be actually using this code for some time 4 * but I thought I'd write it since I knew how. 5 * 6 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu) 7 */ 8
9 #ifndef__SPARC_SMPPRIM_H 10 #define__SPARC_SMPPRIM_H 11
12 /* Test and set the unsigned byte at ADDR to 1. Returns the previous 13 * value. On the Sparc we use the ldstub instruction since it is 14 * atomic. 15 */ 16
17 externinlinevolatilechartest_and_set(void *addr)
/* */ 18 { 19 charstate = 0;
20
21 __asm____volatile__("ldstub [%0], %1 ! test_and_set\n\t"
22 "=r" (addr), "=r" (state) :
23 "0" (addr), "1" (state) : "memory");
24
25 returnstate;
26 } 27
28 /* Initialize a spin-lock. */ 29 externinlinevolatile smp_initlock(void *spinlock)
/* */ 30 { 31 /* Unset the lock. */ 32 *((unsignedchar *) spinlock) = 0;
33
34 return;
35 } 36
37 /* This routine spins until it acquires the lock at ADDR. */ 38 externinlinevolatile smp_lock(void *addr)
/* */ 39 { 40 while(test_and_set(addr) == 0xff)
41 ;
42
43 /* We now have the lock */ 44 return;
45 } 46
47 /* This routine releases the lock at ADDR. */ 48 externinlinevolatile smp_unlock(void *addr)
/* */ 49 { 50 *((unsignedchar *) addr) = 0;
51 } 52
53 #endif/* !(__SPARC_SMPPRIM_H) */