New upstream version 17.11-rc3
[deb_dpdk.git] / drivers / bus / fslmc / qbman / include / compat.h
1 /*-
2  *   BSD LICENSE
3  *
4  * Copyright (c) 2008-2016 Freescale Semiconductor, Inc.
5  * Copyright 2017 NXP.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *     * Redistributions of source code must retain the above copyright
10  *       notice, this list of conditions and the following disclaimer.
11  *     * Redistributions in binary form must reproduce the above copyright
12  *       notice, this list of conditions and the following disclaimer in the
13  *       documentation and/or other materials provided with the distribution.
14  *     * Neither the name of Freescale Semiconductor nor the
15  *       names of its contributors may be used to endorse or promote products
16  *       derived from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
19  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21  * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
22  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29
30 #ifndef HEADER_COMPAT_H
31 #define HEADER_COMPAT_H
32
33 #ifndef _GNU_SOURCE
34 #define _GNU_SOURCE
35 #endif
36 #include <stdint.h>
37 #include <stdlib.h>
38 #include <errno.h>
39 #include <string.h>
40 #include <malloc.h>
41 #include <unistd.h>
42 #include <error.h>
43 #include <linux/types.h>
44 #include <rte_atomic.h>
45
46 /* The following definitions are primarily to allow the single-source driver
47  * interfaces to be included by arbitrary program code. Ie. for interfaces that
48  * are also available in kernel-space, these definitions provide compatibility
49  * with certain attributes and types used in those interfaces.
50  */
51
52 /* Required compiler attributes */
53 #define likely(x)       __builtin_expect(!!(x), 1)
54 #define unlikely(x)     __builtin_expect(!!(x), 0)
55
56 /* Required types */
57 typedef uint64_t        dma_addr_t;
58
59 /* Debugging */
60 #define prflush(fmt, args...) \
61         do { \
62                 printf(fmt, ##args); \
63                 fflush(stdout); \
64         } while (0)
65 #define pr_crit(fmt, args...)    prflush("CRIT:" fmt, ##args)
66 #define pr_err(fmt, args...)     prflush("ERR:" fmt, ##args)
67 #define pr_warn(fmt, args...)    prflush("WARN:" fmt, ##args)
68 #define pr_info(fmt, args...)    prflush(fmt, ##args)
69
70 #ifdef RTE_LIBRTE_DPAA2_DEBUG_BUS
71
72 /* Trace the 3 different classes of read/write access to QBMan. #undef as
73  * required.
74  */
75 #define QBMAN_CCSR_TRACE
76 #define QBMAN_CINH_TRACE
77 #define QBMAN_CENA_TRACE
78
79 #define QBMAN_CHECKING
80
81 #ifdef pr_debug
82 #undef pr_debug
83 #endif
84 #define pr_debug(fmt, args...)  printf(fmt, ##args)
85 #define QBMAN_BUG_ON(c) \
86 do { \
87         static int warned_##__LINE__; \
88         if ((c) && !warned_##__LINE__) { \
89                 pr_warn("(%s:%d)\n", __FILE__, __LINE__); \
90                 warned_##__LINE__ = 1; \
91         } \
92 } while (0)
93 #else
94 #define QBMAN_BUG_ON(c) {}
95 #define pr_debug(fmt, args...) {}
96 #endif
97
98 /* Other miscellaneous interfaces our APIs depend on; */
99
100 #define lower_32_bits(x) ((uint32_t)(x))
101 #define upper_32_bits(x) ((uint32_t)(((x) >> 16) >> 16))
102
103
104 #define __iomem
105
106 #define __raw_readb(p)  (*(const volatile unsigned char *)(p))
107 #define __raw_readl(p)  (*(const volatile unsigned int *)(p))
108 #define __raw_writel(v, p) {*(volatile unsigned int *)(p) = (v); }
109
110 #define atomic_t                rte_atomic32_t
111 #define atomic_read(v)          rte_atomic32_read(v)
112 #define atomic_set(v, i)        rte_atomic32_set(v, i)
113
114 #define atomic_inc(v)           rte_atomic32_add(v, 1)
115 #define atomic_dec(v)           rte_atomic32_sub(v, 1)
116
117 #define atomic_inc_and_test(v)  rte_atomic32_inc_and_test(v)
118 #define atomic_dec_and_test(v)  rte_atomic32_dec_and_test(v)
119
120 #define atomic_inc_return(v)    rte_atomic32_add_return(v, 1)
121 #define atomic_dec_return(v)    rte_atomic32_sub_return(v, 1)
122 #define atomic_sub_and_test(i, v) (rte_atomic32_sub_return(v, i) == 0)
123
124 #endif /* HEADER_COMPAT_H */