xref: /openbmc/u-boot/arch/xtensa/include/asm/bitops.h (revision a3b36c84)
1 /*
2  * Copyright (C) 2001 - 2012 Tensilica Inc.
3  * Copyright (C) 2014 - 2016 Cadence Design Systems Inc.
4  *
5  * SPDX-License-Identifier:	GPL-2.0+
6  */
7 
8 #ifndef _XTENSA_BITOPS_H
9 #define _XTENSA_BITOPS_H
10 
11 #include <asm/system.h>
12 #include <asm-generic/bitops/fls.h>
13 #include <asm-generic/bitops/__fls.h>
14 #include <asm-generic/bitops/fls64.h>
15 #include <asm-generic/bitops/__ffs.h>
16 
17 static inline int test_bit(int nr, const void *addr)
18 {
19 	return ((unsigned char *)addr)[nr >> 3] & (1u << (nr & 7));
20 }
21 
22 static inline int test_and_set_bit(int nr, volatile void *addr)
23 {
24 	unsigned long flags;
25 	unsigned char tmp;
26 	unsigned char mask = 1u << (nr & 7);
27 
28 	local_irq_save(flags);
29 	tmp = ((unsigned char *)addr)[nr >> 3];
30 	((unsigned char *)addr)[nr >> 3] |= mask;
31 	local_irq_restore(flags);
32 
33 	return tmp & mask;
34 }
35 
36 #endif	/* _XTENSA_BITOPS_H */
37