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_LIB_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 BITS_PER_LONG_LONG 36 #define BITS_PER_LONG_LONG (__SIZEOF_LONG_LONG__ * 8) 37 #endif 38 #ifndef BIT 39 #define BIT(a) (1UL << (a)) 40 #endif /* BIT */ 41 #ifndef BIT_ULL 42 #define BIT_ULL(a) (1ULL << (a)) 43 #endif /* BIT_ULL */ 44 #ifndef GENMASK 45 #define GENMASK(h, l) (((~0UL) << (l)) & (~0UL >> (BITS_PER_LONG - 1 - (h)))) 46 #endif /* GENMASK */ 47 #ifndef GENMASK_ULL 48 #define GENMASK_ULL(h, l) \ 49 (((~0ULL) << (l)) & (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h)))) 50 #endif /* GENMASK_ULL */ 51 #endif /* LINUX_MACROS */ 52 53 #define SET_FIELD(m, v) (((v) << (__builtin_ffsll(m) - 1)) & (m)) 54 #define GET_FIELD(m, v) (((v) & (m)) >> (__builtin_ffsll(m) - 1)) 55 56 #define dev_err(x, args...) dev_printf(ERR, args) 57 #define dev_info(x, args...) dev_printf(INFO, args) 58 #define dev_warn(x, args...) dev_printf(WARNING, args) 59 #define dev_debug(x, args...) dev_printf(DEBUG, args) 60 61 #define pr_err(y, args...) dev_err(0, y, ##args) 62 #define pr_warn(y, args...) dev_warn(0, y, ##args) 63 #define pr_info(y, args...) dev_info(0, y, ##args) 64 65 #ifndef WARN_ON 66 #define WARN_ON(x) do { \ 67 int ret = !!(x); \ 68 if (unlikely(ret)) \ 69 pr_warn("WARN_ON: \"" #x "\" at %s:%d\n", __func__, __LINE__); \ 70 } while (0) 71 #endif 72 73 #define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) 74 #define udelay(x) opae_udelay(x) 75 #define msleep(x) opae_udelay(1000 * (x)) 76 #define usleep_range(min, max) msleep(DIV_ROUND_UP(min, 1000)) 77 78 #define time_after(a, b) ((long)((b) - (a)) < 0) 79 #define time_before(a, b) time_after(b, a) 80 #define opae_memset(a, b, c) memset((a), (b), (c)) 81 82 #define readx_poll_timeout(op, val, cond, invl, timeout, args...) \ 83 ({ \ 84 unsigned long __wait = 0; \ 85 unsigned long __invl = (invl); \ 86 unsigned long __timeout = (timeout); \ 87 for (; __wait <= __timeout; __wait += __invl) { \ 88 (val) = op(args); \ 89 if (cond) \ 90 break; \ 91 udelay(__invl); \ 92 } \ 93 (cond) ? 0 : -ETIMEDOUT; \ 94 }) 95 96 #define opae_readq_poll_timeout(addr, val, cond, invl, timeout) \ 97 readx_poll_timeout(opae_readq, val, cond, invl, timeout, addr) 98 99 #define opae_readl_poll_timeout(addr, val, cond, invl, timeout) \ 100 readx_poll_timeout(opae_readl, val, cond, invl, timeout, addr) 101 102 #define opae_readw_poll_timeout(addr, val, cond, invl, timeout) \ 103 readx_poll_timeout(opae_readw, val, cond, invl, timeout, addr) 104 105 #define opae_readb_poll_timeout(addr, val, cond, invl, timeout) \ 106 readx_poll_timeout(opae_readb, val, cond, invl, timeout, addr) 107 108 #define opae_max10_read_poll_timeout(dev, addr, value, cond, invl, timeout) \ 109 ({ \ 110 int __ret, __tmp; \ 111 __tmp = readx_poll_timeout(max10_sys_read, __ret, __ret || (cond), \ 112 invl, timeout, (dev), (addr), &(value)); \ 113 __ret?:__tmp; \ 114 }) 115 116 #endif 117