• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * (C) COPYRIGHT 2018 ARM Limited. All rights reserved.
4  * Author: James.Qian.Wang <james.qian.wang@arm.com>
5  *
6  */
7 #ifndef _MALIDP_UTILS_
8 #define _MALIDP_UTILS_
9 
10 #include <linux/delay.h>
11 #include <linux/errno.h>
12 
13 #define has_bit(nr, mask)	(BIT(nr) & (mask))
14 #define has_bits(bits, mask)	(((bits) & (mask)) == (bits))
15 
16 #define dp_wait_cond(__cond, __tries, __min_range, __max_range)	\
17 ({							\
18 	int num_tries = __tries;			\
19 	while (!__cond && (num_tries > 0)) {		\
20 		usleep_range(__min_range, __max_range);	\
21 		num_tries--;				\
22 	}						\
23 	(__cond) ? 0 : -ETIMEDOUT;			\
24 })
25 
26 /* the restriction of range is [start, end] */
27 struct malidp_range {
28 	u32 start;
29 	u32 end;
30 };
31 
set_range(struct malidp_range * rg,u32 start,u32 end)32 static inline void set_range(struct malidp_range *rg, u32 start, u32 end)
33 {
34 	rg->start = start;
35 	rg->end   = end;
36 }
37 
in_range(struct malidp_range * rg,u32 v)38 static inline bool in_range(struct malidp_range *rg, u32 v)
39 {
40 	return (v >= rg->start) && (v <= rg->end);
41 }
42 
43 #endif /* _MALIDP_UTILS_ */
44