xref: /dpdk/drivers/bus/dpaa/include/dpaa_bits.h (revision d81734caccade4dc17d24d2ffd8b71244d35a69f)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  *   Copyright 2017 NXP
4  *
5  */
6 
7 #ifndef __DPAA_BITS_H
8 #define __DPAA_BITS_H
9 
10 /* Bitfield stuff. */
11 #define BITS_PER_ULONG	(sizeof(unsigned long) << 3)
12 #define SHIFT_PER_ULONG	(((1 << 5) == BITS_PER_ULONG) ? 5 : 6)
13 #define BITS_MASK(idx)	(1UL << ((idx) & (BITS_PER_ULONG - 1)))
14 #define BITS_IDX(idx)	((idx) >> SHIFT_PER_ULONG)
15 
dpaa_set_bits(unsigned long mask,volatile unsigned long * p)16 static inline void dpaa_set_bits(unsigned long mask,
17 				 volatile unsigned long *p)
18 {
19 	*p |= mask;
20 }
21 
dpaa_set_bit(int idx,volatile unsigned long * bits)22 static inline void dpaa_set_bit(int idx, volatile unsigned long *bits)
23 {
24 	dpaa_set_bits(BITS_MASK(idx), bits + BITS_IDX(idx));
25 }
26 
dpaa_clear_bits(unsigned long mask,volatile unsigned long * p)27 static inline void dpaa_clear_bits(unsigned long mask,
28 				   volatile unsigned long *p)
29 {
30 	*p &= ~mask;
31 }
32 
dpaa_clear_bit(int idx,volatile unsigned long * bits)33 static inline void dpaa_clear_bit(int idx,
34 				  volatile unsigned long *bits)
35 {
36 	dpaa_clear_bits(BITS_MASK(idx), bits + BITS_IDX(idx));
37 }
38 
39 #endif /* __DPAA_BITS_H */
40