source: rtems-libbsd/rtemsbsd/powerpc/include/linux/kernel.h @ 9789434

55-freebsd-126-freebsd-12
Last change on this file since 9789434 was 9789434, checked in by Sebastian Huber <sebastian.huber@…>, on Jun 27, 2017 at 7:31:34 AM

linux: Move upper_32_bits() and lower_32_bits()

  • Property mode set to 100644
File size: 6.9 KB
Line 
1/*-
2 * Copyright (c) 2010 Isilon Systems, Inc.
3 * Copyright (c) 2010 iX Systems, Inc.
4 * Copyright (c) 2010 Panasas, Inc.
5 * Copyright (c) 2013-2015 Mellanox Technologies, Ltd.
6 * Copyright (c) 2014-2015 François Tigeot
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 *    notice unmodified, this list of conditions, and the following
14 *    disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 *    notice, this list of conditions and the following disclaimer in the
17 *    documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 *
30 * $FreeBSD$
31 */
32#ifndef _LINUX_KERNEL_H_
33#define _LINUX_KERNEL_H_
34
35#include <sys/cdefs.h>
36#include <sys/types.h>
37#include <sys/systm.h>
38#include <sys/param.h>
39#include <sys/libkern.h>
40#include <sys/stat.h>
41#include <sys/smp.h>
42#include <sys/stddef.h>
43#include <sys/syslog.h>
44
45#include <linux/bitops.h>
46#include <linux/compiler.h>
47#include <linux/err.h>
48#include <linux/errno.h>
49#include <linux/kthread.h>
50#include <linux/types.h>
51#include <linux/jiffies.h>
52#include <linux/wait.h>
53#include <linux/log2.h> 
54#include <asm/byteorder.h>
55
56#define KERN_CONT       ""
57#define KERN_EMERG      "<0>"
58#define KERN_ALERT      "<1>"
59#define KERN_CRIT       "<2>"
60#define KERN_ERR        "<3>"
61#define KERN_WARNING    "<4>"
62#define KERN_NOTICE     "<5>"
63#define KERN_INFO       "<6>"
64#define KERN_DEBUG      "<7>"
65
66#define BUILD_BUG_ON(x)         CTASSERT(!(x))
67
68#define BUG()                   panic("BUG")
69#define BUG_ON(condition)       do { if (__predict_false(condition)) BUG(); } while(0)
70#define WARN_ON(condition)      ({ int _warn_on = !!(condition); \
71    __predict_false(_warn_on); })
72
73#undef  ALIGN
74#define ALIGN(x, y)             roundup2((x), (y))
75#undef PTR_ALIGN
76#define PTR_ALIGN(p, a)         ((__typeof(p))ALIGN((uintptr_t)(p), (a)))
77#define DIV_ROUND_UP(x, n)      howmany(x, n)
78#define DIV_ROUND_UP_ULL(x, n)  DIV_ROUND_UP((unsigned long long)(x), (n))
79#define FIELD_SIZEOF(t, f)      sizeof(((t *)0)->f)
80
81#define printk(X...)            printf(X)
82
83/*
84 * The "pr_debug()" and "pr_devel()" macros should produce zero code
85 * unless DEBUG is defined:
86 */
87#ifdef DEBUG
88#define pr_debug(fmt, ...) \
89        log(LOG_DEBUG, fmt, ##__VA_ARGS__)
90#define pr_devel(fmt, ...) \
91        log(LOG_DEBUG, pr_fmt(fmt), ##__VA_ARGS__)
92#else
93#define pr_debug(fmt, ...) \
94        ({ if (0) log(LOG_DEBUG, fmt, ##__VA_ARGS__); 0; })
95#define pr_devel(fmt, ...) \
96        ({ if (0) log(LOG_DEBUG, pr_fmt(fmt), ##__VA_ARGS__); 0; })
97#endif
98
99#ifndef pr_fmt
100#define pr_fmt(fmt) fmt
101#endif
102
103/*
104 * Print a one-time message (analogous to WARN_ONCE() et al):
105 */
106#define printk_once(...) do {                   \
107        static bool __print_once;               \
108                                                \
109        if (!__print_once) {                    \
110                __print_once = true;            \
111                printk(__VA_ARGS__);            \
112        }                                       \
113} while (0)
114
115/*
116 * Log a one-time message (analogous to WARN_ONCE() et al):
117 */
118#define log_once(level,...) do {                \
119        static bool __log_once;                 \
120                                                \
121        if (!__log_once) {                      \
122                __log_once = true;              \
123                log(level, __VA_ARGS__);        \
124        }                                       \
125} while (0)
126
127#define pr_emerg(fmt, ...) \
128        log(LOG_EMERG, pr_fmt(fmt), ##__VA_ARGS__)
129#define pr_alert(fmt, ...) \
130        log(LOG_ALERT, pr_fmt(fmt), ##__VA_ARGS__)
131#define pr_crit(fmt, ...) \
132        log(LOG_CRIT, pr_fmt(fmt), ##__VA_ARGS__)
133#define pr_crit_once(fmt, ...) \
134        log_once(LOG_CRIT, pr_fmt(fmt), ##__VA_ARGS__)
135#define pr_err(fmt, ...) \
136        log(LOG_ERR, pr_fmt(fmt), ##__VA_ARGS__)
137#define pr_warning(fmt, ...) \
138        log(LOG_WARNING, pr_fmt(fmt), ##__VA_ARGS__)
139#define pr_warn pr_warning
140#define pr_warn_once(fmt, ...) \
141        log_once(LOG_WARNING, pr_fmt(fmt), ##__VA_ARGS__)
142#define pr_notice(fmt, ...) \
143        log(LOG_NOTICE, pr_fmt(fmt), ##__VA_ARGS__)
144#define pr_info(fmt, ...) \
145        log(LOG_INFO, pr_fmt(fmt), ##__VA_ARGS__)
146#define pr_info_once(fmt, ...) \
147        log_once(LOG_INFO, pr_fmt(fmt), ##__VA_ARGS__)
148#define pr_cont(fmt, ...) \
149        printk(KERN_CONT fmt, ##__VA_ARGS__)
150
151#ifndef WARN
152#define WARN(condition, format...) ({                                   \
153        int __ret_warn_on = !!(condition);                              \
154        if (unlikely(__ret_warn_on))                                    \
155                pr_warning(format);                                     \
156        unlikely(__ret_warn_on);                                        \
157})
158#endif
159
160#define container_of(ptr, type, member)                         \
161({                                                              \
162        __typeof(((type *)0)->member) *_p = (ptr);              \
163        (type *)((char *)_p - offsetof(type, member));          \
164})
165 
166#define ARRAY_SIZE(x)   (sizeof(x) / sizeof((x)[0]))
167
168#define simple_strtoul  strtoul
169#define simple_strtol   strtol
170#define kstrtol(a,b,c) ({*(c) = strtol(a,0,b);})
171int __must_check kstrtoint(const char *, unsigned int, int *);
172
173#define min(x, y)       ((x) < (y) ? (x) : (y))
174#define max(x, y)       ((x) > (y) ? (x) : (y))
175
176#define min3(a, b, c)   min(a, min(b,c))
177#define max3(a, b, c)   max(a, max(b,c))
178
179#define min_t(type, _x, _y)     ((type)(_x) < (type)(_y) ? (type)(_x) : (type)(_y))
180#define max_t(type, _x, _y)     ((type)(_x) > (type)(_y) ? (type)(_x) : (type)(_y))
181
182#define clamp_t(type, _x, min, max)     min_t(type, max_t(type, _x, min), max)
183#define clamp(x, lo, hi)                min( max(x,lo), hi)
184
185/*
186 * This looks more complex than it should be. But we need to
187 * get the type for the ~ right in round_down (it needs to be
188 * as wide as the result!), and we want to evaluate the macro
189 * arguments just once each.
190 */
191#define __round_mask(x, y) ((__typeof__(x))((y)-1))
192#define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
193#define round_down(x, y) ((x) & ~__round_mask(x, y))
194
195#define num_possible_cpus()     mp_ncpus
196#define num_online_cpus()       mp_ncpus
197
198typedef struct pm_message {
199        int event;
200} pm_message_t;
201
202/* Swap values of a and b */
203#define swap(a, b) do {                 \
204        typeof(a) _swap_tmp = a;        \
205        a = b;                          \
206        b = _swap_tmp;                  \
207} while (0)
208
209#define DIV_ROUND_CLOSEST(x, divisor)   (((x) + ((divisor) / 2)) / (divisor))
210
211static inline uintmax_t
212mult_frac(uintmax_t x, uintmax_t multiplier, uintmax_t divisor)
213{
214        uintmax_t q = (x / divisor);
215        uintmax_t r = (x % divisor);
216
217        return ((q * multiplier) + ((r * multiplier) / divisor));
218}
219
220static inline int64_t
221abs64(int64_t x)
222{
223        return (x < 0 ? -x : x);
224}
225
226#define cpu_relax() RTEMS_COMPILER_MEMORY_BARRIER()
227
228#define udelay(x) DELAY(x)
229
230#define usleep_range(x, y) usleep(x)
231
232#endif  /* _LINUX_KERNEL_H_ */
Note: See TracBrowser for help on using the repository browser.