xref: /openbsd/sys/dev/pci/drm/include/linux/iopoll.h (revision 4cfece93)
1 /* Public domain. */
2 
3 #ifndef _LINUX_IOPOLL_H
4 #define _LINUX_IOPOLL_H
5 
6 #define readx_poll_timeout(op, addr, val, cond, sleep_us, timeout_us)	\
7 ({									\
8 	struct timeval __end, __now, __timeout_tv;			\
9 	int __timed_out = 0;						\
10 									\
11 	if (timeout_us) {						\
12 		microuptime(&__now);					\
13 		USEC_TO_TIMEVAL(timeout_us, &__timeout_tv);		\
14 		timeradd(&__now, &__timeout_tv, &__end);		\
15 	}								\
16 									\
17 	for (;;) {							\
18 		(val) = (op)(addr);					\
19 		if (cond)						\
20 			break;						\
21 		if (timeout_us) {					\
22 			microuptime(&__now);				\
23 			if (timercmp(&__end, &__now, <=)) {		\
24 				__timed_out = 1;			\
25 				break;					\
26 			}						\
27 		}							\
28 		if (sleep_us)						\
29 			delay((sleep_us) / 2);				\
30 	}								\
31 	(__timed_out) ? -ETIMEDOUT : 0;					\
32 })
33 
34 #endif
35