Linux Audio

Check our new training course

Loading...
v5.4
 1/* SPDX-License-Identifier: GPL-2.0 */
 2/* 32-bit atomic xchg() and cmpxchg() definitions.
 3 *
 4 * Copyright (C) 1996 David S. Miller (davem@davemloft.net)
 5 * Copyright (C) 2000 Anton Blanchard (anton@linuxcare.com.au)
 6 * Copyright (C) 2007 Kyle McMartin (kyle@parisc-linux.org)
 7 *
 8 * Additions by Keith M Wesolowski (wesolows@foobazco.org) based
 9 * on asm-parisc/atomic.h Copyright (C) 2000 Philipp Rumpf <prumpf@tux.org>.
10 */
11
12#ifndef __ARCH_SPARC_CMPXCHG__
13#define __ARCH_SPARC_CMPXCHG__
14
15unsigned long __xchg_u32(volatile u32 *m, u32 new);
16void __xchg_called_with_bad_pointer(void);
17
18static inline unsigned long __xchg(unsigned long x, __volatile__ void * ptr, int size)
19{
20	switch (size) {
21	case 4:
22		return __xchg_u32(ptr, x);
23	}
24	__xchg_called_with_bad_pointer();
25	return x;
26}
27
28#define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
29
30/* Emulate cmpxchg() the same way we emulate atomics,
31 * by hashing the object address and indexing into an array
32 * of spinlocks to get a bit of performance...
33 *
34 * See arch/sparc/lib/atomic32.c for implementation.
35 *
36 * Cribbed from <asm-parisc/atomic.h>
37 */
38
39/* bug catcher for when unsupported size is used - won't link */
40void __cmpxchg_called_with_bad_pointer(void);
41/* we only need to support cmpxchg of a u32 on sparc */
42unsigned long __cmpxchg_u32(volatile u32 *m, u32 old, u32 new_);
43
44/* don't worry...optimizer will get rid of most of this */
45static inline unsigned long
46__cmpxchg(volatile void *ptr, unsigned long old, unsigned long new_, int size)
47{
48	switch (size) {
49	case 4:
50		return __cmpxchg_u32((u32 *)ptr, (u32)old, (u32)new_);
51	default:
52		__cmpxchg_called_with_bad_pointer();
53		break;
54	}
55	return old;
56}
57
58#define cmpxchg(ptr, o, n)						\
59({									\
60	__typeof__(*(ptr)) _o_ = (o);					\
61	__typeof__(*(ptr)) _n_ = (n);					\
62	(__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_,	\
63			(unsigned long)_n_, sizeof(*(ptr)));		\
64})
65
66u64 __cmpxchg_u64(u64 *ptr, u64 old, u64 new);
67#define cmpxchg64(ptr, old, new)	__cmpxchg_u64(ptr, old, new)
68
69#include <asm-generic/cmpxchg-local.h>
70
71/*
72 * cmpxchg_local and cmpxchg64_local are atomic wrt current CPU. Always make
73 * them available.
74 */
75#define cmpxchg_local(ptr, o, n)				  	       \
76	((__typeof__(*(ptr)))__cmpxchg_local_generic((ptr), (unsigned long)(o),\
77			(unsigned long)(n), sizeof(*(ptr))))
78#define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
79
80#endif /* __ARCH_SPARC_CMPXCHG__ */
v4.6
 
 1/* 32-bit atomic xchg() and cmpxchg() definitions.
 2 *
 3 * Copyright (C) 1996 David S. Miller (davem@davemloft.net)
 4 * Copyright (C) 2000 Anton Blanchard (anton@linuxcare.com.au)
 5 * Copyright (C) 2007 Kyle McMartin (kyle@parisc-linux.org)
 6 *
 7 * Additions by Keith M Wesolowski (wesolows@foobazco.org) based
 8 * on asm-parisc/atomic.h Copyright (C) 2000 Philipp Rumpf <prumpf@tux.org>.
 9 */
10
11#ifndef __ARCH_SPARC_CMPXCHG__
12#define __ARCH_SPARC_CMPXCHG__
13
14unsigned long __xchg_u32(volatile u32 *m, u32 new);
15void __xchg_called_with_bad_pointer(void);
16
17static inline unsigned long __xchg(unsigned long x, __volatile__ void * ptr, int size)
18{
19	switch (size) {
20	case 4:
21		return __xchg_u32(ptr, x);
22	}
23	__xchg_called_with_bad_pointer();
24	return x;
25}
26
27#define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
28
29/* Emulate cmpxchg() the same way we emulate atomics,
30 * by hashing the object address and indexing into an array
31 * of spinlocks to get a bit of performance...
32 *
33 * See arch/sparc/lib/atomic32.c for implementation.
34 *
35 * Cribbed from <asm-parisc/atomic.h>
36 */
37
38/* bug catcher for when unsupported size is used - won't link */
39void __cmpxchg_called_with_bad_pointer(void);
40/* we only need to support cmpxchg of a u32 on sparc */
41unsigned long __cmpxchg_u32(volatile u32 *m, u32 old, u32 new_);
42
43/* don't worry...optimizer will get rid of most of this */
44static inline unsigned long
45__cmpxchg(volatile void *ptr, unsigned long old, unsigned long new_, int size)
46{
47	switch (size) {
48	case 4:
49		return __cmpxchg_u32((u32 *)ptr, (u32)old, (u32)new_);
50	default:
51		__cmpxchg_called_with_bad_pointer();
52		break;
53	}
54	return old;
55}
56
57#define cmpxchg(ptr, o, n)						\
58({									\
59	__typeof__(*(ptr)) _o_ = (o);					\
60	__typeof__(*(ptr)) _n_ = (n);					\
61	(__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_,	\
62			(unsigned long)_n_, sizeof(*(ptr)));		\
63})
 
 
 
64
65#include <asm-generic/cmpxchg-local.h>
66
67/*
68 * cmpxchg_local and cmpxchg64_local are atomic wrt current CPU. Always make
69 * them available.
70 */
71#define cmpxchg_local(ptr, o, n)				  	       \
72	((__typeof__(*(ptr)))__cmpxchg_local_generic((ptr), (unsigned long)(o),\
73			(unsigned long)(n), sizeof(*(ptr))))
74#define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
75
76#endif /* __ARCH_SPARC_CMPXCHG__ */