1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (c) 2012-2014 The Linux Foundation. All rights reserved.
6 #ifndef _LINUX_IOPOLL_H
7 #define _LINUX_IOPOLL_H
9 #include <linux/delay.h>
10 #include <linux/errno.h>
15 * read_poll_timeout - Periodically poll an address until a condition is met or a timeout occurs
16 * @op: accessor function (takes @addr as its only argument)
17 * @addr: Address to poll
18 * @val: Variable to read the value into
19 * @cond: Break condition (usually involving @val)
20 * @sleep_us: Maximum time to sleep in us
21 * @timeout_us: Timeout in us, 0 means never timeout
23 * Returns 0 on success and -ETIMEDOUT upon a timeout. In either
24 * case, the last read value at @addr is stored in @val.
26 * When available, you'll probably want to use one of the specialized
27 * macros defined below rather than this macro directly.
29 #define read_poll_timeout(op, addr, val, cond, sleep_us, timeout_us) \
31 unsigned long timeout = timer_get_us() + timeout_us; \
36 if (timeout_us && time_after(timer_get_us(), timeout)) { \
43 (cond) ? 0 : -ETIMEDOUT; \
46 #define readx_poll_timeout(op, addr, val, cond, timeout_us) \
47 read_poll_timeout(op, addr, val, cond, false, timeout_us)
49 #define readb_poll_timeout(addr, val, cond, timeout_us) \
50 readx_poll_timeout(readb, addr, val, cond, timeout_us)
52 #define readw_poll_timeout(addr, val, cond, timeout_us) \
53 readx_poll_timeout(readw, addr, val, cond, timeout_us)
55 #define readl_poll_timeout(addr, val, cond, timeout_us) \
56 readx_poll_timeout(readl, addr, val, cond, timeout_us)
58 #define readq_poll_timeout(addr, val, cond, timeout_us) \
59 readx_poll_timeout(readq, addr, val, cond, timeout_us)
61 #define readb_relaxed_poll_timeout(addr, val, cond, timeout_us) \
62 readx_poll_timeout(readb_relaxed, addr, val, cond, timeout_us)
64 #define readw_relaxed_poll_timeout(addr, val, cond, timeout_us) \
65 readx_poll_timeout(readw_relaxed, addr, val, cond, timeout_us)
67 #define readl_relaxed_poll_timeout(addr, val, cond, timeout_us) \
68 readx_poll_timeout(readl_relaxed, addr, val, cond, timeout_us)
70 #define readq_relaxed_poll_timeout(addr, val, cond, timeout_us) \
71 readx_poll_timeout(readq_relaxed, addr, val, cond, timeout_us)
73 #endif /* _LINUX_IOPOLL_H */