162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 262306a36Sopenharmony_ci#ifndef __ASM_SYNC_BITOPS_H__ 362306a36Sopenharmony_ci#define __ASM_SYNC_BITOPS_H__ 462306a36Sopenharmony_ci 562306a36Sopenharmony_ci#include <asm/bitops.h> 662306a36Sopenharmony_ci 762306a36Sopenharmony_ci/* sync_bitops functions are equivalent to the SMP implementation of the 862306a36Sopenharmony_ci * original functions, independently from CONFIG_SMP being defined. 962306a36Sopenharmony_ci * 1062306a36Sopenharmony_ci * We need them because _set_bit etc are not SMP safe if !CONFIG_SMP. But 1162306a36Sopenharmony_ci * under Xen you might be communicating with a completely external entity 1262306a36Sopenharmony_ci * who might be on another CPU (e.g. two uniprocessor guests communicating 1362306a36Sopenharmony_ci * via event channels and grant tables). So we need a variant of the bit 1462306a36Sopenharmony_ci * ops which are SMP safe even on a UP kernel. 1562306a36Sopenharmony_ci */ 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_ci/* 1862306a36Sopenharmony_ci * Unordered 1962306a36Sopenharmony_ci */ 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_ci#define sync_set_bit(nr, p) _set_bit(nr, p) 2262306a36Sopenharmony_ci#define sync_clear_bit(nr, p) _clear_bit(nr, p) 2362306a36Sopenharmony_ci#define sync_change_bit(nr, p) _change_bit(nr, p) 2462306a36Sopenharmony_ci#define sync_test_bit(nr, addr) test_bit(nr, addr) 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_ci/* 2762306a36Sopenharmony_ci * Fully ordered 2862306a36Sopenharmony_ci */ 2962306a36Sopenharmony_ci 3062306a36Sopenharmony_ciint _sync_test_and_set_bit(int nr, volatile unsigned long * p); 3162306a36Sopenharmony_ci#define sync_test_and_set_bit(nr, p) _sync_test_and_set_bit(nr, p) 3262306a36Sopenharmony_ci 3362306a36Sopenharmony_ciint _sync_test_and_clear_bit(int nr, volatile unsigned long * p); 3462306a36Sopenharmony_ci#define sync_test_and_clear_bit(nr, p) _sync_test_and_clear_bit(nr, p) 3562306a36Sopenharmony_ci 3662306a36Sopenharmony_ciint _sync_test_and_change_bit(int nr, volatile unsigned long * p); 3762306a36Sopenharmony_ci#define sync_test_and_change_bit(nr, p) _sync_test_and_change_bit(nr, p) 3862306a36Sopenharmony_ci 3962306a36Sopenharmony_ci#define arch_sync_cmpxchg(ptr, old, new) \ 4062306a36Sopenharmony_ci({ \ 4162306a36Sopenharmony_ci __typeof__(*(ptr)) __ret; \ 4262306a36Sopenharmony_ci __smp_mb__before_atomic(); \ 4362306a36Sopenharmony_ci __ret = arch_cmpxchg_relaxed((ptr), (old), (new)); \ 4462306a36Sopenharmony_ci __smp_mb__after_atomic(); \ 4562306a36Sopenharmony_ci __ret; \ 4662306a36Sopenharmony_ci}) 4762306a36Sopenharmony_ci 4862306a36Sopenharmony_ci#endif 49