1
2
3
4
5
6#ifndef _LINUX_IOPOLL_H
7#define _LINUX_IOPOLL_H
8
9#include <linux/delay.h>
10#include <linux/errno.h>
11#include <linux/io.h>
12#include <time.h>
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29#define read_poll_timeout(op, val, cond, sleep_us, timeout_us, args...) \
30({ \
31 unsigned long timeout = timer_get_us() + timeout_us; \
32 for (;;) { \
33 (val) = op(args); \
34 if (cond) \
35 break; \
36 if (timeout_us && time_after(timer_get_us(), timeout)) { \
37 (val) = op(args); \
38 break; \
39 } \
40 if (sleep_us) \
41 udelay(sleep_us); \
42 } \
43 (cond) ? 0 : -ETIMEDOUT; \
44})
45
46#define readx_poll_sleep_timeout(op, addr, val, cond, sleep_us, timeout_us) \
47 read_poll_timeout(op, val, cond, sleep_us, timeout_us, addr)
48
49#define readl_poll_sleep_timeout(addr, val, cond, sleep_us, timeout_us) \
50 readx_poll_sleep_timeout(readl, addr, val, cond, sleep_us, timeout_us)
51
52#define readx_poll_timeout(op, addr, val, cond, timeout_us) \
53 read_poll_timeout(op, val, cond, false, timeout_us, addr)
54
55#define readb_poll_timeout(addr, val, cond, timeout_us) \
56 readx_poll_timeout(readb, addr, val, cond, timeout_us)
57
58#define readw_poll_timeout(addr, val, cond, timeout_us) \
59 readx_poll_timeout(readw, addr, val, cond, timeout_us)
60
61#define readl_poll_timeout(addr, val, cond, timeout_us) \
62 readx_poll_timeout(readl, addr, val, cond, timeout_us)
63
64#define readq_poll_timeout(addr, val, cond, timeout_us) \
65 readx_poll_timeout(readq, addr, val, cond, timeout_us)
66
67#define readb_relaxed_poll_timeout(addr, val, cond, timeout_us) \
68 readx_poll_timeout(readb_relaxed, addr, val, cond, timeout_us)
69
70#define readw_relaxed_poll_timeout(addr, val, cond, timeout_us) \
71 readx_poll_timeout(readw_relaxed, addr, val, cond, timeout_us)
72
73#define readl_relaxed_poll_timeout(addr, val, cond, timeout_us) \
74 readx_poll_timeout(readl_relaxed, addr, val, cond, timeout_us)
75
76#define readq_relaxed_poll_timeout(addr, val, cond, timeout_us) \
77 readx_poll_timeout(readq_relaxed, addr, val, cond, timeout_us)
78
79#endif
80