xref: /dpdk/drivers/common/nfp/nfp_platform.h (revision 191128d7f6a02b816deaa86d761fbde4483724e9)
1a3460357SChaoyong He /* SPDX-License-Identifier: BSD-3-Clause
2a3460357SChaoyong He  * Copyright(c) 2023 Corigine, Inc.
3a3460357SChaoyong He  * All rights reserved.
4a3460357SChaoyong He  */
5a3460357SChaoyong He 
6a3460357SChaoyong He #ifndef __NFP_PLATFORM_H__
7a3460357SChaoyong He #define __NFP_PLATFORM_H__
8a3460357SChaoyong He 
9a3460357SChaoyong He #include <stdint.h>
10a3460357SChaoyong He 
11*191128d7SDavid Marchand #include <rte_bitops.h>
12*191128d7SDavid Marchand 
13a3460357SChaoyong He #define DIV_ROUND_UP(n, d)             (((n) + (d) - 1) / (d))
14a3460357SChaoyong He 
15a3460357SChaoyong He #define DMA_BIT_MASK(n)    ((1ULL << (n)) - 1)
16a3460357SChaoyong He 
17a3460357SChaoyong He #define BITS_PER_LONG      (__SIZEOF_LONG__ * 8)
18a3460357SChaoyong He #define BITS_PER_LONG_LONG (__SIZEOF_LONG_LONG__ * 8)
19a3460357SChaoyong He 
20a3460357SChaoyong He #define GENMASK(h, l) \
21a3460357SChaoyong He 	((~0UL << (l)) & (~0UL >> (BITS_PER_LONG - (h) - 1)))
22a3460357SChaoyong He 
23a3460357SChaoyong He #define GENMASK_ULL(h, l) \
24a3460357SChaoyong He 	((~0ULL << (l)) & (~0ULL >> (BITS_PER_LONG_LONG - (h) - 1)))
25a3460357SChaoyong He 
26*191128d7SDavid Marchand #define __bf_shf(x) rte_bsf64(x)
27a3460357SChaoyong He 
28a3460357SChaoyong He #define FIELD_GET(_mask, _reg) \
29a3460357SChaoyong He 	(__extension__ ({ \
30a3460357SChaoyong He 		typeof(_mask) _x = (_mask); \
31a3460357SChaoyong He 		(typeof(_x))(((_reg) & (_x)) >> __bf_shf(_x)); \
32a3460357SChaoyong He 	}))
33a3460357SChaoyong He 
34a3460357SChaoyong He #define FIELD_FIT(_mask, _val) \
35a3460357SChaoyong He 	(__extension__ ({ \
36a3460357SChaoyong He 		typeof(_mask) _x = (_mask); \
37a3460357SChaoyong He 		!((((typeof(_x))_val) << __bf_shf(_x)) & ~(_x)); \
38a3460357SChaoyong He 	}))
39a3460357SChaoyong He 
40a3460357SChaoyong He #define FIELD_PREP(_mask, _val) \
41a3460357SChaoyong He 	(__extension__ ({ \
42a3460357SChaoyong He 		typeof(_mask) _x = (_mask); \
43a3460357SChaoyong He 		((typeof(_x))(_val) << __bf_shf(_x)) & (_x); \
44a3460357SChaoyong He 	}))
45a3460357SChaoyong He 
46a3460357SChaoyong He #endif /* __NFP_PLATFORM_H__ */
47