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_for_each_set_bit(bit, mask) \ 17 for_each_set_bit((bit), ((unsigned long *)&(mask)), sizeof(mask) * 8) 18 19 #define dp_wait_cond(__cond, __tries, __min_range, __max_range) \ 20 ({ \ 21 int num_tries = __tries; \ 22 while (!__cond && (num_tries > 0)) { \ 23 usleep_range(__min_range, __max_range); \ 24 num_tries--; \ 25 } \ 26 (__cond) ? 0 : -ETIMEDOUT; \ 27 }) 28 29 /* the restriction of range is [start, end] */ 30 struct malidp_range { 31 u32 start; 32 u32 end; 33 }; 34 35 static inline void set_range(struct malidp_range *rg, u32 start, u32 end) 36 { 37 rg->start = start; 38 rg->end = end; 39 } 40 41 static inline bool in_range(struct malidp_range *rg, u32 v) 42 { 43 return (v >= rg->start) && (v <= rg->end); 44 } 45 46 #endif /* _MALIDP_UTILS_ */ 47