2 * Copyright (c) 2010 Isilon Systems, Inc.
3 * Copyright (c) 2010 iX Systems, Inc.
4 * Copyright (c) 2010 Panasas, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice unmodified, this list of conditions, and the following
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #ifndef _LINUX_KERNEL_H_
29 #define _LINUX_KERNEL_H_
31 #include <sys/systm.h>
32 #include <sys/param.h>
33 #include <sys/libkern.h>
37 #include <linux/bitops.h>
38 #include <linux/compiler.h>
39 #include <linux/errno.h>
40 #include <linux/stddef.h>
41 #include <linux/kthread.h>
42 #include <linux/types.h>
43 #include <linux/jiffies.h>
44 #include <linux/wait.h>
46 #include <linux/notifier.h>
47 #include <linux/log2.h>
48 #include <asm/byteorder.h>
51 #define KERN_EMERG "<0>"
52 #define KERN_ALERT "<1>"
53 #define KERN_CRIT "<2>"
54 #define KERN_ERR "<3>"
55 #define KERN_WARNING "<4>"
56 #define KERN_NOTICE "<5>"
57 #define KERN_INFO "<6>"
58 #define KERN_DEBUG "<7>"
60 #define BUG() panic("BUG")
61 #define BUG_ON(condition) do { if (condition) BUG(); } while(0)
62 #define WARN_ON BUG_ON
65 #define ALIGN(x, y) roundup2((x), (y))
66 #define DIV_ROUND_UP howmany
68 #define printk(X...) printf(X)
69 #define pr_debug(fmt, ...) printk(KERN_DEBUG # fmt, ##__VA_ARGS__)
70 #define udelay(t) DELAY(t)
73 #define pr_fmt(fmt) fmt
77 * Print a one-time message (analogous to WARN_ONCE() et al):
79 #define printk_once(x...) ({ \
80 static bool __print_once; \
82 if (!__print_once) { \
83 __print_once = true; \
90 #define pr_emerg(fmt, ...) \
91 printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
92 #define pr_alert(fmt, ...) \
93 printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
94 #define pr_crit(fmt, ...) \
95 printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
96 #define pr_err(fmt, ...) \
97 printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
98 #define pr_warning(fmt, ...) \
99 printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
100 #define pr_warn pr_warning
101 #define pr_notice(fmt, ...) \
102 printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
103 #define pr_info(fmt, ...) \
104 printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
105 #define pr_cont(fmt, ...) \
106 printk(KERN_CONT fmt, ##__VA_ARGS__)
108 /* pr_devel() should produce zero code unless DEBUG is defined */
110 #define pr_devel(fmt, ...) \
111 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
113 #define pr_devel(fmt, ...) \
114 ({ if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); 0; })
118 #define WARN(condition, format...) ({ \
119 int __ret_warn_on = !!(condition); \
120 if (unlikely(__ret_warn_on)) \
121 pr_warning(format); \
122 unlikely(__ret_warn_on); \
126 #define container_of(ptr, type, member) \
128 __typeof(((type *)0)->member) *_p = (ptr); \
129 (type *)((char *)_p - offsetof(type, member)); \
132 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
134 #define simple_strtoul strtoul
135 #define simple_strtol strtol
137 #define min(x, y) (x < y ? x : y)
138 #define max(x, y) (x > y ? x : y)
139 #define min_t(type, _x, _y) (type)(_x) < (type)(_y) ? (type)(_x) : (_y)
140 #define max_t(type, _x, _y) (type)(_x) > (type)(_y) ? (type)(_x) : (_y)
143 * This looks more complex than it should be. But we need to
144 * get the type for the ~ right in round_down (it needs to be
145 * as wide as the result!), and we want to evaluate the macro
146 * arguments just once each.
148 #define __round_mask(x, y) ((__typeof__(x))((y)-1))
149 #define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
150 #define round_down(x, y) ((x) & ~__round_mask(x, y))
152 #define num_possible_cpus() mp_ncpus
154 typedef struct pm_message {
158 #endif /* _LINUX_KERNEL_H_ */