drivers/raw: remove rawdev from directory names
[dpdk.git] / drivers / raw / ifpga / base / opae_osdep.h
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
11 #ifdef RTE_LIBRTE_EAL
12 #include "osdep_rte/osdep_generic.h"
13 #else
14 #include "osdep_raw/osdep_generic.h"
15 #endif
16
17 #define __iomem
18
19 typedef uint8_t         u8;
20 typedef int8_t          s8;
21 typedef uint16_t        u16;
22 typedef uint32_t        u32;
23 typedef int32_t         s32;
24 typedef uint64_t        u64;
25 typedef uint64_t        dma_addr_t;
26
27 struct uuid {
28         u8 b[16];
29 };
30
31 #ifndef LINUX_MACROS
32 #ifndef BITS_PER_LONG
33 #define BITS_PER_LONG   (__SIZEOF_LONG__ * 8)
34 #endif
35 #ifndef BIT
36 #define BIT(a) (1UL << (a))
37 #endif /* BIT */
38 #define U64_C(x) x ## ULL
39 #ifndef BIT_ULL
40 #define BIT_ULL(a) (1ULL << (a))
41 #endif /* BIT_ULL */
42 #ifndef GENMASK
43 #define GENMASK(h, l)   (((~0UL) << (l)) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
44 #endif /* GENMASK */
45 #ifndef GENMASK_ULL
46 #define GENMASK_ULL(h, l) (((U64_C(1) << ((h) - (l) + 1)) - 1) << (l))
47 #endif /* GENMASK_ULL */
48 #endif /* LINUX_MACROS */
49
50 #define SET_FIELD(m, v) (((v) << (__builtin_ffsll(m) - 1)) & (m))
51 #define GET_FIELD(m, v) (((v) & (m)) >> (__builtin_ffsll(m) - 1))
52
53 #define dev_err(x, args...) dev_printf(ERR, args)
54 #define dev_info(x, args...) dev_printf(INFO, args)
55 #define dev_warn(x, args...) dev_printf(WARNING, args)
56 #define dev_debug(x, args...) dev_printf(DEBUG, args)
57
58 #define pr_err(y, args...) dev_err(0, y, ##args)
59 #define pr_warn(y, args...) dev_warn(0, y, ##args)
60 #define pr_info(y, args...) dev_info(0, y, ##args)
61
62 #ifndef WARN_ON
63 #define WARN_ON(x) do { \
64         int ret = !!(x); \
65         if (unlikely(ret)) \
66                 pr_warn("WARN_ON: \"" #x "\" at %s:%d\n", __func__, __LINE__); \
67 } while (0)
68 #endif
69
70 #define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
71 #define udelay(x) opae_udelay(x)
72 #define msleep(x) opae_udelay(1000 * (x))
73 #define usleep_range(min, max) msleep(DIV_ROUND_UP(min, 1000))
74
75 #define time_after(a, b)        ((long)((b) - (a)) < 0)
76 #define time_before(a, b)       time_after(b, a)
77 #define opae_memset(a, b, c)    memset((a), (b), (c))
78
79 #define opae_readq_poll_timeout(addr, val, cond, invl, timeout)\
80 ({                                                                           \
81         int wait = 0;                                                        \
82         for (; wait <= timeout; wait += invl) {                      \
83                 (val) = opae_readq(addr);                                    \
84                 if (cond)                  \
85                         break;                                               \
86                 udelay(invl);                                                \
87         }                                                                    \
88         (cond) ? 0 : -ETIMEDOUT;          \
89 })
90 #endif