xref: /dpdk/drivers/raw/ifpga/base/opae_osdep.h (revision fd51012de5369679e807be1d6a81d63ef15015ce)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2018 Intel Corporation
3  */
4 
5 #ifndef _OPAE_OSDEP_H
6 #define _OPAE_OSDEP_H
7 
8 #include <string.h>
9 #include <stdbool.h>
10 #include <pthread.h>
11 
12 #ifdef RTE_LIB_EAL
13 #include "osdep_rte/osdep_generic.h"
14 #else
15 #include "osdep_raw/osdep_generic.h"
16 #endif
17 
18 #define __iomem
19 
20 typedef uint8_t		u8;
21 typedef int8_t		s8;
22 typedef uint16_t	u16;
23 typedef uint32_t	u32;
24 typedef int32_t		s32;
25 typedef uint64_t	u64;
26 typedef uint64_t	dma_addr_t;
27 
28 struct uuid {
29 	u8 b[16];
30 };
31 
32 #ifndef LINUX_MACROS
33 #ifndef BITS_PER_LONG
34 #define BITS_PER_LONG	(__SIZEOF_LONG__ * 8)
35 #endif
36 #ifndef BITS_PER_LONG_LONG
37 #define BITS_PER_LONG_LONG  (__SIZEOF_LONG_LONG__ * 8)
38 #endif
39 #ifndef BIT
40 #define BIT(a) (1UL << (a))
41 #endif /* BIT */
42 #ifndef BIT_ULL
43 #define BIT_ULL(a) (1ULL << (a))
44 #endif /* BIT_ULL */
45 #ifndef GENMASK
46 #define GENMASK(h, l)	(((~0UL) << (l)) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
47 #endif /* GENMASK */
48 #ifndef GENMASK_ULL
49 #define GENMASK_ULL(h, l) \
50 	(((~0ULL) << (l)) & (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h))))
51 #endif /* GENMASK_ULL */
52 #endif /* LINUX_MACROS */
53 
54 #define SET_FIELD(m, v) (((v) << (__builtin_ffsll(m) - 1)) & (m))
55 #define GET_FIELD(m, v) (((v) & (m)) >> (__builtin_ffsll(m) - 1))
56 
57 #define dev_err(x, ...) dev_printf(ERR, __VA_ARGS__)
58 #define dev_info(x, ...) dev_printf(INFO, __VA_ARGS__)
59 #define dev_warn(x, ...) dev_printf(WARNING, __VA_ARGS__)
60 #define dev_debug(x, ...) dev_printf(DEBUG, __VA_ARGS__)
61 
62 #define pr_err(y, ...) dev_err(0, y, ##__VA_ARGS__)
63 #define pr_warn(y, ...) dev_warn(0, y, ##__VA_ARGS__)
64 #define pr_info(y, ...) dev_info(0, y, ##__VA_ARGS__)
65 
66 #ifndef WARN_ON
67 #define WARN_ON(x) do { \
68 	int ret = !!(x); \
69 	if (unlikely(ret)) \
70 		pr_warn("WARN_ON: \"" #x "\" at %s:%d\n", __func__, __LINE__); \
71 } while (0)
72 #endif
73 
74 #define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
75 #define udelay(x) opae_udelay(x)
76 #define msleep(x) opae_udelay(1000 * (x))
77 #define usleep_range(min, max) msleep(DIV_ROUND_UP(min, 1000))
78 
79 #define time_after(a, b)	((long)((b) - (a)) < 0)
80 #define time_before(a, b)	time_after(b, a)
81 #define opae_memset(a, b, c)    memset((a), (b), (c))
82 
83 #define readx_poll_timeout(op, val, cond, invl, timeout, ...)         \
84 __extension__ ({                                                      \
85 	unsigned long __wait = 0;                                     \
86 	unsigned long __invl = (invl);                                \
87 	unsigned long __timeout = (timeout);                          \
88 	for (; __wait <= __timeout; __wait += __invl) {               \
89 		(val) = op(__VA_ARGS__);                                  \
90 		if (cond)                                                 \
91 			break;                                                \
92 		udelay(__invl);                                           \
93 	}                                                             \
94 	(cond) ? 0 : -ETIMEDOUT;                                      \
95 })
96 
97 #define opae_readq_poll_timeout(addr, val, cond, invl, timeout) \
98 	readx_poll_timeout(opae_readq, val, cond, invl, timeout, addr)
99 
100 #define opae_readl_poll_timeout(addr, val, cond, invl, timeout) \
101 	readx_poll_timeout(opae_readl, val, cond, invl, timeout, addr)
102 
103 #define opae_readw_poll_timeout(addr, val, cond, invl, timeout) \
104 	readx_poll_timeout(opae_readw, val, cond, invl, timeout, addr)
105 
106 #define opae_readb_poll_timeout(addr, val, cond, invl, timeout) \
107 	readx_poll_timeout(opae_readb, val, cond, invl, timeout, addr)
108 
109 #define opae_max10_read_poll_timeout(dev, addr, value, cond, invl, timeout) \
110 __extension__ ({ \
111 	int __ret, __tmp; \
112 	__tmp = readx_poll_timeout(max10_sys_read, __ret, __ret || (cond), \
113 			invl, timeout, (dev), (addr), &(value)); \
114 	__ret?:__tmp; \
115 })
116 
117 #endif
118