initial commit with v2.6.9
[linux-2.6.9-moxart.git] / include / linux / kernel.h
blob40307a28bb4b764550a8f86395613d5596e914e1
1 #ifndef _LINUX_KERNEL_H
2 #define _LINUX_KERNEL_H
4 /*
5 * 'kernel.h' contains some often-used function prototypes etc
6 */
8 #ifdef __KERNEL__
10 #include <stdarg.h>
11 #include <linux/linkage.h>
12 #include <linux/stddef.h>
13 #include <linux/types.h>
14 #include <linux/compiler.h>
15 #include <linux/bitops.h>
16 #include <asm/byteorder.h>
17 #include <asm/bug.h>
19 #define INT_MAX ((int)(~0U>>1))
20 #define INT_MIN (-INT_MAX - 1)
21 #define UINT_MAX (~0U)
22 #define LONG_MAX ((long)(~0UL>>1))
23 #define LONG_MIN (-LONG_MAX - 1)
24 #define ULONG_MAX (~0UL)
26 #define STACK_MAGIC 0xdeadbeef
28 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
29 #define ALIGN(x,a) (((x)+(a)-1)&~((a)-1))
31 #define KERN_EMERG "<0>" /* system is unusable */
32 #define KERN_ALERT "<1>" /* action must be taken immediately */
33 #define KERN_CRIT "<2>" /* critical conditions */
34 #define KERN_ERR "<3>" /* error conditions */
35 #define KERN_WARNING "<4>" /* warning conditions */
36 #define KERN_NOTICE "<5>" /* normal but significant condition */
37 #define KERN_INFO "<6>" /* informational */
38 #define KERN_DEBUG "<7>" /* debug-level messages */
40 extern int console_printk[];
42 #define console_loglevel (console_printk[0])
43 #define default_message_loglevel (console_printk[1])
44 #define minimum_console_loglevel (console_printk[2])
45 #define default_console_loglevel (console_printk[3])
47 struct completion;
49 #ifdef CONFIG_DEBUG_SPINLOCK_SLEEP
50 void __might_sleep(char *file, int line);
51 #define might_sleep() __might_sleep(__FILE__, __LINE__)
52 #define might_sleep_if(cond) do { if (unlikely(cond)) might_sleep(); } while (0)
53 #else
54 #define might_sleep() do {} while(0)
55 #define might_sleep_if(cond) do {} while (0)
56 #endif
58 #define abs(x) ({ \
59 int __x = (x); \
60 (__x < 0) ? -__x : __x; \
63 #define labs(x) ({ \
64 long __x = (x); \
65 (__x < 0) ? -__x : __x; \
68 extern struct notifier_block *panic_notifier_list;
69 NORET_TYPE void panic(const char * fmt, ...)
70 __attribute__ ((NORET_AND format (printf, 1, 2)));
71 asmlinkage NORET_TYPE void do_exit(long error_code)
72 ATTRIB_NORET;
73 NORET_TYPE void complete_and_exit(struct completion *, long)
74 ATTRIB_NORET;
75 extern unsigned long simple_strtoul(const char *,char **,unsigned int);
76 extern long simple_strtol(const char *,char **,unsigned int);
77 extern unsigned long long simple_strtoull(const char *,char **,unsigned int);
78 extern long long simple_strtoll(const char *,char **,unsigned int);
79 extern int sprintf(char * buf, const char * fmt, ...)
80 __attribute__ ((format (printf, 2, 3)));
81 extern int vsprintf(char *buf, const char *, va_list);
82 extern int snprintf(char * buf, size_t size, const char * fmt, ...)
83 __attribute__ ((format (printf, 3, 4)));
84 extern int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
85 extern int scnprintf(char * buf, size_t size, const char * fmt, ...)
86 __attribute__ ((format (printf, 3, 4)));
87 extern int vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
89 extern int sscanf(const char *, const char *, ...)
90 __attribute__ ((format (scanf,2,3)));
91 extern int vsscanf(const char *, const char *, va_list);
93 extern int get_option(char **str, int *pint);
94 extern char *get_options(const char *str, int nints, int *ints);
95 extern unsigned long long memparse(char *ptr, char **retptr);
97 extern int __kernel_text_address(unsigned long addr);
98 extern int kernel_text_address(unsigned long addr);
99 extern int session_of_pgrp(int pgrp);
101 asmlinkage int vprintk(const char *fmt, va_list args);
102 asmlinkage int printk(const char * fmt, ...)
103 __attribute__ ((format (printf, 1, 2)));
105 unsigned long int_sqrt(unsigned long);
107 static inline int __attribute_pure__ long_log2(unsigned long x)
109 int r = 0;
110 for (x >>= 1; x > 0; x >>= 1)
111 r++;
112 return r;
115 static inline unsigned long __attribute_const__ roundup_pow_of_two(unsigned long x)
117 return (1UL << fls(x - 1));
120 extern int printk_ratelimit(void);
121 extern int __printk_ratelimit(int ratelimit_jiffies, int ratelimit_burst);
123 static inline void console_silent(void)
125 console_loglevel = 0;
128 static inline void console_verbose(void)
130 if (console_loglevel)
131 console_loglevel = 15;
134 extern void bust_spinlocks(int yes);
135 extern int oops_in_progress; /* If set, an oops, panic(), BUG() or die() is in progress */
136 extern int panic_on_oops;
137 extern int tainted;
138 extern const char *print_tainted(void);
140 /* Values used for system_state */
141 extern enum system_states {
142 SYSTEM_BOOTING,
143 SYSTEM_RUNNING,
144 SYSTEM_HALT,
145 SYSTEM_POWER_OFF,
146 SYSTEM_RESTART,
147 } system_state;
149 #define TAINT_PROPRIETARY_MODULE (1<<0)
150 #define TAINT_FORCED_MODULE (1<<1)
151 #define TAINT_UNSAFE_SMP (1<<2)
152 #define TAINT_FORCED_RMMOD (1<<3)
154 extern void dump_stack(void);
156 #ifdef DEBUG
157 #define pr_debug(fmt,arg...) \
158 printk(KERN_DEBUG fmt,##arg)
159 #else
160 #define pr_debug(fmt,arg...) \
161 do { } while (0)
162 #endif
164 #define pr_info(fmt,arg...) \
165 printk(KERN_INFO fmt,##arg)
168 * Display an IP address in readable format.
171 #define NIPQUAD(addr) \
172 ((unsigned char *)&addr)[0], \
173 ((unsigned char *)&addr)[1], \
174 ((unsigned char *)&addr)[2], \
175 ((unsigned char *)&addr)[3]
177 #define NIP6(addr) \
178 ntohs((addr).s6_addr16[0]), \
179 ntohs((addr).s6_addr16[1]), \
180 ntohs((addr).s6_addr16[2]), \
181 ntohs((addr).s6_addr16[3]), \
182 ntohs((addr).s6_addr16[4]), \
183 ntohs((addr).s6_addr16[5]), \
184 ntohs((addr).s6_addr16[6]), \
185 ntohs((addr).s6_addr16[7])
187 #if defined(__LITTLE_ENDIAN)
188 #define HIPQUAD(addr) \
189 ((unsigned char *)&addr)[3], \
190 ((unsigned char *)&addr)[2], \
191 ((unsigned char *)&addr)[1], \
192 ((unsigned char *)&addr)[0]
193 #elif defined(__BIG_ENDIAN)
194 #define HIPQUAD NIPQUAD
195 #else
196 #error "Please fix asm/byteorder.h"
197 #endif /* __LITTLE_ENDIAN */
200 * min()/max() macros that also do
201 * strict type-checking.. See the
202 * "unnecessary" pointer comparison.
204 #define min(x,y) ({ \
205 typeof(x) _x = (x); \
206 typeof(y) _y = (y); \
207 (void) (&_x == &_y); \
208 _x < _y ? _x : _y; })
210 #define max(x,y) ({ \
211 typeof(x) _x = (x); \
212 typeof(y) _y = (y); \
213 (void) (&_x == &_y); \
214 _x > _y ? _x : _y; })
217 * ..and if you can't take the strict
218 * types, you can specify one yourself.
220 * Or not use min/max at all, of course.
222 #define min_t(type,x,y) \
223 ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
224 #define max_t(type,x,y) \
225 ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
229 * container_of - cast a member of a structure out to the containing structure
231 * @ptr: the pointer to the member.
232 * @type: the type of the container struct this is embedded in.
233 * @member: the name of the member within the struct.
236 #define container_of(ptr, type, member) ({ \
237 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
238 (type *)( (char *)__mptr - offsetof(type,member) );})
241 * Check at compile time that something is of a particular type.
242 * Always evaluates to 1 so you may use it easily in comparisons.
244 #define typecheck(type,x) \
245 ({ type __dummy; \
246 typeof(x) __dummy2; \
247 (void)(&__dummy == &__dummy2); \
248 1; \
251 #endif /* __KERNEL__ */
253 #define SI_LOAD_SHIFT 16
254 struct sysinfo {
255 long uptime; /* Seconds since boot */
256 unsigned long loads[3]; /* 1, 5, and 15 minute load averages */
257 unsigned long totalram; /* Total usable main memory size */
258 unsigned long freeram; /* Available memory size */
259 unsigned long sharedram; /* Amount of shared memory */
260 unsigned long bufferram; /* Memory used by buffers */
261 unsigned long totalswap; /* Total swap space size */
262 unsigned long freeswap; /* swap space still available */
263 unsigned short procs; /* Number of current processes */
264 unsigned short pad; /* explicit padding for m68k */
265 unsigned long totalhigh; /* Total high memory size */
266 unsigned long freehigh; /* Available high memory size */
267 unsigned int mem_unit; /* Memory unit size in bytes */
268 char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding: libc5 uses this.. */
271 extern void BUILD_BUG(void);
272 #define BUILD_BUG_ON(condition) do { if (condition) BUILD_BUG(); } while(0)
274 /* Trap pasters of __FUNCTION__ at compile-time */
275 #if __GNUC__ > 2 || __GNUC_MINOR__ >= 95
276 #define __FUNCTION__ (__func__)
277 #endif
279 #endif