Linux Audio

Check our new training course

Loading...
v6.2
 1/* SPDX-License-Identifier: GPL-2.0 */
 2#ifndef __ASM_SH_CMPXCHG_H
 3#define __ASM_SH_CMPXCHG_H
 4
 5/*
 6 * Atomic operations that C can't guarantee us.  Useful for
 7 * resource counting etc..
 8 */
 9
10#include <linux/compiler.h>
11#include <linux/types.h>
 
12
13#if defined(CONFIG_GUSA_RB)
14#include <asm/cmpxchg-grb.h>
15#elif defined(CONFIG_CPU_SH4A)
16#include <asm/cmpxchg-llsc.h>
17#elif defined(CONFIG_CPU_J2) && defined(CONFIG_SMP)
18#include <asm/cmpxchg-cas.h>
19#else
20#include <asm/cmpxchg-irq.h>
21#endif
22
23extern void __xchg_called_with_bad_pointer(void);
24
25#define __xchg(ptr, x, size)				\
26({							\
27	unsigned long __xchg__res;			\
28	volatile void *__xchg_ptr = (ptr);		\
29	switch (size) {					\
30	case 4:						\
31		__xchg__res = xchg_u32(__xchg_ptr, x);	\
32		break;					\
33	case 2:						\
34		__xchg__res = xchg_u16(__xchg_ptr, x);	\
35		break;					\
36	case 1:						\
37		__xchg__res = xchg_u8(__xchg_ptr, x);	\
38		break;					\
39	default:					\
40		__xchg_called_with_bad_pointer();	\
41		__xchg__res = x;			\
42		break;					\
43	}						\
44							\
45	__xchg__res;					\
46})
47
48#define arch_xchg(ptr,x)	\
49	((__typeof__(*(ptr)))__xchg((ptr),(unsigned long)(x), sizeof(*(ptr))))
50
51/* This function doesn't exist, so you'll get a linker error
52 * if something tries to do an invalid cmpxchg(). */
53extern void __cmpxchg_called_with_bad_pointer(void);
54
55static inline unsigned long __cmpxchg(volatile void * ptr, unsigned long old,
56		unsigned long new, int size)
57{
58	switch (size) {
 
 
59	case 4:
60		return __cmpxchg_u32(ptr, old, new);
61	}
62	__cmpxchg_called_with_bad_pointer();
63	return old;
64}
65
66#define arch_cmpxchg(ptr,o,n)						 \
67  ({									 \
68     __typeof__(*(ptr)) _o_ = (o);					 \
69     __typeof__(*(ptr)) _n_ = (n);					 \
70     (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_,		 \
71				    (unsigned long)_n_, sizeof(*(ptr))); \
72  })
 
 
 
 
 
 
 
 
 
73
74#endif /* __ASM_SH_CMPXCHG_H */
v6.13.7
 1/* SPDX-License-Identifier: GPL-2.0 */
 2#ifndef __ASM_SH_CMPXCHG_H
 3#define __ASM_SH_CMPXCHG_H
 4
 5/*
 6 * Atomic operations that C can't guarantee us.  Useful for
 7 * resource counting etc..
 8 */
 9
10#include <linux/compiler.h>
11#include <linux/types.h>
12#include <linux/cmpxchg-emu.h>
13
14#if defined(CONFIG_GUSA_RB)
15#include <asm/cmpxchg-grb.h>
16#elif defined(CONFIG_CPU_SH4A)
17#include <asm/cmpxchg-llsc.h>
18#elif defined(CONFIG_CPU_J2) && defined(CONFIG_SMP)
19#include <asm/cmpxchg-cas.h>
20#else
21#include <asm/cmpxchg-irq.h>
22#endif
23
24extern void __xchg_called_with_bad_pointer(void);
25
26#define __arch_xchg(ptr, x, size)				\
27({							\
28	unsigned long __xchg__res;			\
29	volatile void *__xchg_ptr = (ptr);		\
30	switch (size) {					\
31	case 4:						\
32		__xchg__res = xchg_u32(__xchg_ptr, x);	\
33		break;					\
34	case 2:						\
35		__xchg__res = xchg_u16(__xchg_ptr, x);	\
36		break;					\
37	case 1:						\
38		__xchg__res = xchg_u8(__xchg_ptr, x);	\
39		break;					\
40	default:					\
41		__xchg_called_with_bad_pointer();	\
42		__xchg__res = x;			\
43		break;					\
44	}						\
45							\
46	__xchg__res;					\
47})
48
49#define arch_xchg(ptr,x)	\
50	((__typeof__(*(ptr)))__arch_xchg((ptr),(unsigned long)(x), sizeof(*(ptr))))
51
52/* This function doesn't exist, so you'll get a linker error
53 * if something tries to do an invalid cmpxchg(). */
54extern void __cmpxchg_called_with_bad_pointer(void);
55
56static inline unsigned long __cmpxchg(volatile void * ptr, unsigned long old,
57		unsigned long new, int size)
58{
59	switch (size) {
60	case 1:
61		return cmpxchg_emu_u8(ptr, old, new);
62	case 4:
63		return __cmpxchg_u32(ptr, old, new);
64	}
65	__cmpxchg_called_with_bad_pointer();
66	return old;
67}
68
69#define arch_cmpxchg(ptr,o,n)						 \
70  ({									 \
71     __typeof__(*(ptr)) _o_ = (o);					 \
72     __typeof__(*(ptr)) _n_ = (n);					 \
73     (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_,		 \
74				    (unsigned long)_n_, sizeof(*(ptr))); \
75  })
76
77#include <asm-generic/cmpxchg-local.h>
78
79#define arch_cmpxchg_local(ptr, o, n) ({				\
80	(__typeof__(*ptr))__generic_cmpxchg_local((ptr),		\
81						  (unsigned long)(o),	\
82						  (unsigned long)(n),	\
83						  sizeof(*(ptr)));	\
84})
85
86#endif /* __ASM_SH_CMPXCHG_H */