xref: /dflybsd-src/sys/dev/drm/include/linux/kernel.h (revision 4badba3841ae9f4d60211d1c5ed006e17b38c299)
1 /*-
2  * Copyright (c) 2010 Isilon Systems, Inc.
3  * Copyright (c) 2010 iX Systems, Inc.
4  * Copyright (c) 2010 Panasas, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice unmodified, this list of conditions, and the following
12  *    disclaimer.
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.
16  *
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.
27  */
28 #ifndef	_LINUX_KERNEL_H_
29 #define	_LINUX_KERNEL_H_
30 
31 #include <sys/systm.h>
32 #include <sys/param.h>
33 #include <sys/libkern.h>
34 #include <sys/stat.h>
35 
36 #include <linux/bitops.h>
37 #include <linux/compiler.h>
38 #include <linux/types.h>
39 
40 #define KERN_CONT       ""
41 #define	KERN_EMERG	"<0>"
42 #define	KERN_ALERT	"<1>"
43 #define	KERN_CRIT	"<2>"
44 #define	KERN_ERR	"<3>"
45 #define	KERN_WARNING	"<4>"
46 #define	KERN_NOTICE	"<5>"
47 #define	KERN_INFO	"<6>"
48 #define	KERN_DEBUG	"<7>"
49 
50 #define BUG()			panic("BUG")
51 #define BUG_ON(condition)	do { if (condition) BUG(); } while(0)
52 #define	WARN_ON			BUG_ON
53 
54 #undef	ALIGN
55 #define	ALIGN(x, y)		roundup2((x), (y))
56 #define	DIV_ROUND_UP		howmany
57 
58 #define	printk(X...)		printf(X)
59 #define	pr_debug(fmt, ...)	printk(KERN_DEBUG # fmt, ##__VA_ARGS__)
60 #define udelay(t)       	DELAY(t)
61 
62 #ifndef pr_fmt
63 #define pr_fmt(fmt) fmt
64 #endif
65 
66 /*
67  * Print a one-time message (analogous to WARN_ONCE() et al):
68  */
69 #define printk_once(x...) ({                    \
70         static bool __print_once;               \
71                                                 \
72         if (!__print_once) {                    \
73                 __print_once = true;            \
74                 printk(x);                      \
75         }                                       \
76 })
77 
78 
79 
80 #define pr_emerg(fmt, ...) \
81         printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
82 #define pr_alert(fmt, ...) \
83         printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
84 #define pr_crit(fmt, ...) \
85         printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
86 #define pr_err(fmt, ...) \
87         printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
88 #define pr_warning(fmt, ...) \
89         printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
90 #define pr_warn pr_warning
91 #define pr_notice(fmt, ...) \
92         printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
93 #define pr_info(fmt, ...) \
94         printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
95 #define pr_cont(fmt, ...) \
96         printk(KERN_CONT fmt, ##__VA_ARGS__)
97 
98 /* pr_devel() should produce zero code unless DEBUG is defined */
99 #ifdef DEBUG
100 #define pr_devel(fmt, ...) \
101         printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
102 #else
103 #define pr_devel(fmt, ...) \
104         ({ if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); 0; })
105 #endif
106 
107 #ifndef WARN
108 #define WARN(condition, format...) ({                                   \
109         int __ret_warn_on = !!(condition);                              \
110         if (unlikely(__ret_warn_on))                                    \
111                 pr_warning(format);                                     \
112         unlikely(__ret_warn_on);                                        \
113 })
114 #endif
115 
116 #define container_of(ptr, type, member)				\
117 ({								\
118 	__typeof(((type *)0)->member) *_p = (ptr);		\
119 	(type *)((char *)_p - offsetof(type, member));		\
120 })
121 
122 #define	ARRAY_SIZE(x)	(sizeof(x) / sizeof((x)[0]))
123 
124 #define	simple_strtoul	strtoul
125 #define	simple_strtol	strtol
126 
127 #define min(x, y)	(x < y ? x : y)
128 #define max(x, y)	(x > y ? x : y)
129 #define min_t(type, _x, _y)	(type)(_x) < (type)(_y) ? (type)(_x) : (_y)
130 #define max_t(type, _x, _y)	(type)(_x) > (type)(_y) ? (type)(_x) : (_y)
131 
132 /*
133  * This looks more complex than it should be. But we need to
134  * get the type for the ~ right in round_down (it needs to be
135  * as wide as the result!), and we want to evaluate the macro
136  * arguments just once each.
137  */
138 #define __round_mask(x, y) ((__typeof__(x))((y)-1))
139 #define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
140 #define round_down(x, y) ((x) & ~__round_mask(x, y))
141 
142 #define	num_possible_cpus()	mp_ncpus
143 
144 typedef struct pm_message {
145         int event;
146 } pm_message_t;
147 
148 #endif	/* _LINUX_KERNEL_H_ */
149