4 * Copyright (c) 2008-2016 Freescale Semiconductor, Inc.
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.
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.
30 #ifndef HEADER_COMPAT_H
31 #define HEADER_COMPAT_H
44 #include <net/ethernet.h>
49 #include <sys/types.h>
59 #include <rte_atomic.h>
61 /* The following definitions are primarily to allow the single-source driver
62 * interfaces to be included by arbitrary program code. Ie. for interfaces that
63 * are also available in kernel-space, these definitions provide compatibility
64 * with certain attributes and types used in those interfaces.
67 /* Required compiler attributes */
68 #define likely(x) __builtin_expect(!!(x), 1)
69 #define unlikely(x) __builtin_expect(!!(x), 0)
70 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
75 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
82 typedef uint64_t dma_addr_t;
83 typedef cpu_set_t cpumask_t;
84 typedef unsigned int gfp_t;
85 typedef uint32_t phandle;
88 static inline u32 in_be32(volatile void *__p)
90 volatile u32 *p = __p;
94 static inline void out_be32(volatile void *__p, u32 val)
96 volatile u32 *p = __p;
101 #define prflush(fmt, args...) \
103 printf(fmt, ##args); \
106 #define pr_crit(fmt, args...) prflush("CRIT:" fmt, ##args)
107 #define pr_err(fmt, args...) prflush("ERR:" fmt, ##args)
108 #define pr_warn(fmt, args...) prflush("WARN:" fmt, ##args)
109 #define pr_info(fmt, args...) prflush(fmt, ##args)
111 #ifdef RTE_LIBRTE_DPAA2_DEBUG_BUS
115 #define pr_debug(fmt, args...) {}
116 #define WARN_ON(c, str) \
118 static int warned_##__LINE__; \
119 if ((c) && !warned_##__LINE__) { \
120 pr_warn("%s\n", str); \
121 pr_warn("(%s:%d)\n", __FILE__, __LINE__); \
122 warned_##__LINE__ = 1; \
126 #define QBMAN_BUG_ON(c) WARN_ON(c, "BUG")
128 #define QBMAN_BUG_ON(c) {}
131 #define ALIGN(x, a) (((x) + ((typeof(x))(a) - 1)) & ~((typeof(x))(a) - 1))
133 /* Other miscellaneous interfaces our APIs depend on; */
134 #define lower_32_bits(x) ((u32)(x))
135 #define upper_32_bits(x) ((u32)(((x) >> 16) >> 16))
137 /* Compiler/type stuff */
141 #define __raw_readb(p) (*(const volatile unsigned char *)(p))
142 #define __raw_readl(p) (*(const volatile unsigned int *)(p))
143 #define __raw_writel(v, p) {*(volatile unsigned int *)(p) = (v); }
145 /* Allocator stuff */
146 #define kmalloc(sz, t) malloc(sz)
147 #define kfree(p) { if (p) free(p); }
148 static inline void *kzalloc(size_t sz, gfp_t __foo __rte_unused)
150 void *ptr = malloc(sz);
157 static inline unsigned long get_zeroed_page(gfp_t __foo __rte_unused)
161 if (posix_memalign(&p, 4096, 4096))
164 return (unsigned long)p;
167 static inline void free_page(unsigned long p)
172 #define atomic_t rte_atomic32_t
173 #define atomic_read(v) rte_atomic32_read(v)
174 #define atomic_set(v, i) rte_atomic32_set(v, i)
176 #define atomic_inc(v) rte_atomic32_add(v, 1)
177 #define atomic_dec(v) rte_atomic32_sub(v, 1)
179 #define atomic_inc_and_test(v) rte_atomic32_inc_and_test(v)
180 #define atomic_dec_and_test(v) rte_atomic32_dec_and_test(v)
182 #define atomic_inc_return(v) rte_atomic32_add_return(v, 1)
183 #define atomic_dec_return(v) rte_atomic32_sub_return(v, 1)
184 #define atomic_sub_and_test(i, v) (rte_atomic32_sub_return(v, i) == 0)
186 #endif /* HEADER_COMPAT_H */