xref: /dflybsd-src/sys/dev/drm/include/asm/bitops.h (revision 02ce2f14df089c402bae6a52f0a603efca5ef1d1)
1a9f40f57SFrançois Tigeot /*
2a9f40f57SFrançois Tigeot  * Copyright (c) 2020 François Tigeot <ftigeot@wolfpond.org>
3a9f40f57SFrançois Tigeot  * All rights reserved.
4a9f40f57SFrançois Tigeot  *
5a9f40f57SFrançois Tigeot  * Redistribution and use in source and binary forms, with or without
6a9f40f57SFrançois Tigeot  * modification, are permitted provided that the following conditions
7a9f40f57SFrançois Tigeot  * are met:
8a9f40f57SFrançois Tigeot  * 1. Redistributions of source code must retain the above copyright
9a9f40f57SFrançois Tigeot  *    notice unmodified, this list of conditions, and the following
10a9f40f57SFrançois Tigeot  *    disclaimer.
11a9f40f57SFrançois Tigeot  * 2. Redistributions in binary form must reproduce the above copyright
12a9f40f57SFrançois Tigeot  *    notice, this list of conditions and the following disclaimer in the
13a9f40f57SFrançois Tigeot  *    documentation and/or other materials provided with the distribution.
14a9f40f57SFrançois Tigeot  *
15a9f40f57SFrançois Tigeot  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16a9f40f57SFrançois Tigeot  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17a9f40f57SFrançois Tigeot  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18a9f40f57SFrançois Tigeot  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19a9f40f57SFrançois Tigeot  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20a9f40f57SFrançois Tigeot  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21a9f40f57SFrançois Tigeot  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22a9f40f57SFrançois Tigeot  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23a9f40f57SFrançois Tigeot  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24a9f40f57SFrançois Tigeot  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25a9f40f57SFrançois Tigeot  */
26a9f40f57SFrançois Tigeot 
27a9f40f57SFrançois Tigeot #ifndef _ASM_BITOPS_H
28a9f40f57SFrançois Tigeot #define _ASM_BITOPS_H
29a9f40f57SFrançois Tigeot 
30a9f40f57SFrançois Tigeot #include <linux/compiler.h>
31a9f40f57SFrançois Tigeot #include <asm/barrier.h>
32a9f40f57SFrançois Tigeot 
33a9f40f57SFrançois Tigeot /* Like atomic_testandset_long() but not atomic */
34a9f40f57SFrançois Tigeot static inline bool
__test_and_set_bit(long nr,volatile unsigned long * addr)35a9f40f57SFrançois Tigeot __test_and_set_bit(long nr, volatile unsigned long *addr)
36a9f40f57SFrançois Tigeot {
37a9f40f57SFrançois Tigeot 	bool previous_bit;
38a9f40f57SFrançois Tigeot 
39a9f40f57SFrançois Tigeot 	__asm __volatile(
40*02ce2f14SFrançois Tigeot 		"btsq	%2,%1 ;"
41a9f40f57SFrançois Tigeot 		"setc	%0 ;"
42a9f40f57SFrançois Tigeot 		: "=q" (previous_bit),	/* %0 */
43a9f40f57SFrançois Tigeot 		  "+m" (*addr)		/* %1 */
44a9f40f57SFrançois Tigeot 		: "Jr" (nr)		/* %2 */
45a9f40f57SFrançois Tigeot 		: "cc");
46a9f40f57SFrançois Tigeot 
47a9f40f57SFrançois Tigeot 	return previous_bit;
48a9f40f57SFrançois Tigeot }
49a9f40f57SFrançois Tigeot 
50a9f40f57SFrançois Tigeot #endif /* _ASM_BITOPS_H */
51