1bd628c1bSjames qian wang (Arm Technology China) /* SPDX-License-Identifier: GPL-2.0 */
2bd628c1bSjames qian wang (Arm Technology China) /*
3bd628c1bSjames qian wang (Arm Technology China) * (C) COPYRIGHT 2018 ARM Limited. All rights reserved.
4bd628c1bSjames qian wang (Arm Technology China) * Author: James.Qian.Wang <james.qian.wang@arm.com>
5bd628c1bSjames qian wang (Arm Technology China) *
6bd628c1bSjames qian wang (Arm Technology China) */
7bd628c1bSjames qian wang (Arm Technology China) #ifndef _MALIDP_UTILS_
8bd628c1bSjames qian wang (Arm Technology China) #define _MALIDP_UTILS_
9bd628c1bSjames qian wang (Arm Technology China)
101f2367a3Sjames qian wang (Arm Technology China) #include <linux/delay.h>
11ebf68996SLiviu Dudau #include <linux/errno.h>
121f2367a3Sjames qian wang (Arm Technology China)
13bd628c1bSjames qian wang (Arm Technology China) #define has_bit(nr, mask) (BIT(nr) & (mask))
14bd628c1bSjames qian wang (Arm Technology China) #define has_bits(bits, mask) (((bits) & (mask)) == (bits))
15bd628c1bSjames qian wang (Arm Technology China)
161f2367a3Sjames qian wang (Arm Technology China) #define dp_wait_cond(__cond, __tries, __min_range, __max_range) \
171f2367a3Sjames qian wang (Arm Technology China) ({ \
181f2367a3Sjames qian wang (Arm Technology China) int num_tries = __tries; \
191f2367a3Sjames qian wang (Arm Technology China) while (!__cond && (num_tries > 0)) { \
201f2367a3Sjames qian wang (Arm Technology China) usleep_range(__min_range, __max_range); \
211f2367a3Sjames qian wang (Arm Technology China) num_tries--; \
221f2367a3Sjames qian wang (Arm Technology China) } \
23ebf68996SLiviu Dudau (__cond) ? 0 : -ETIMEDOUT; \
241f2367a3Sjames qian wang (Arm Technology China) })
251f2367a3Sjames qian wang (Arm Technology China)
2671c420b7Sjames qian wang (Arm Technology China) /* the restriction of range is [start, end] */
2771c420b7Sjames qian wang (Arm Technology China) struct malidp_range {
2871c420b7Sjames qian wang (Arm Technology China) u32 start;
2971c420b7Sjames qian wang (Arm Technology China) u32 end;
3071c420b7Sjames qian wang (Arm Technology China) };
3171c420b7Sjames qian wang (Arm Technology China)
set_range(struct malidp_range * rg,u32 start,u32 end)3271c420b7Sjames qian wang (Arm Technology China) static inline void set_range(struct malidp_range *rg, u32 start, u32 end)
3371c420b7Sjames qian wang (Arm Technology China) {
3471c420b7Sjames qian wang (Arm Technology China) rg->start = start;
3571c420b7Sjames qian wang (Arm Technology China) rg->end = end;
3671c420b7Sjames qian wang (Arm Technology China) }
3771c420b7Sjames qian wang (Arm Technology China)
malidp_in_range(struct malidp_range * rg,u32 v)38*f9bff0e3SMatthew Wilcox (Oracle) static inline bool malidp_in_range(struct malidp_range *rg, u32 v)
3971c420b7Sjames qian wang (Arm Technology China) {
4071c420b7Sjames qian wang (Arm Technology China) return (v >= rg->start) && (v <= rg->end);
4171c420b7Sjames qian wang (Arm Technology China) }
4271c420b7Sjames qian wang (Arm Technology China)
43bd628c1bSjames qian wang (Arm Technology China) #endif /* _MALIDP_UTILS_ */
44