[PATCH] w1: Adds a sysfs entry (w1_master_search) that allows you to disable/enable...
[linux-2.6/verdex.git] / include / linux / kernel.h
blobe25b97062ce1ac942d14301335584bd66e3d331d
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 extern const char linux_banner[];
21 #define INT_MAX ((int)(~0U>>1))
22 #define INT_MIN (-INT_MAX - 1)
23 #define UINT_MAX (~0U)
24 #define LONG_MAX ((long)(~0UL>>1))
25 #define LONG_MIN (-LONG_MAX - 1)
26 #define ULONG_MAX (~0UL)
28 #define STACK_MAGIC 0xdeadbeef
30 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
31 #define ALIGN(x,a) (((x)+(a)-1)&~((a)-1))
33 #define KERN_EMERG "<0>" /* system is unusable */
34 #define KERN_ALERT "<1>" /* action must be taken immediately */
35 #define KERN_CRIT "<2>" /* critical conditions */
36 #define KERN_ERR "<3>" /* error conditions */
37 #define KERN_WARNING "<4>" /* warning conditions */
38 #define KERN_NOTICE "<5>" /* normal but significant condition */
39 #define KERN_INFO "<6>" /* informational */
40 #define KERN_DEBUG "<7>" /* debug-level messages */
42 extern int console_printk[];
44 #define console_loglevel (console_printk[0])
45 #define default_message_loglevel (console_printk[1])
46 #define minimum_console_loglevel (console_printk[2])
47 #define default_console_loglevel (console_printk[3])
49 struct completion;
51 /**
52 * might_sleep - annotation for functions that can sleep
54 * this macro will print a stack trace if it is executed in an atomic
55 * context (spinlock, irq-handler, ...).
57 * This is a useful debugging help to be able to catch problems early and not
58 * be biten later when the calling function happens to sleep when it is not
59 * supposed to.
61 #ifdef CONFIG_DEBUG_SPINLOCK_SLEEP
62 #define might_sleep() __might_sleep(__FILE__, __LINE__)
63 #define might_sleep_if(cond) do { if (unlikely(cond)) might_sleep(); } while (0)
64 void __might_sleep(char *file, int line);
65 #else
66 #define might_sleep() do {} while(0)
67 #define might_sleep_if(cond) do {} while (0)
68 #endif
70 #define abs(x) ({ \
71 int __x = (x); \
72 (__x < 0) ? -__x : __x; \
75 #define labs(x) ({ \
76 long __x = (x); \
77 (__x < 0) ? -__x : __x; \
80 extern struct notifier_block *panic_notifier_list;
81 extern long (*panic_blink)(long time);
82 NORET_TYPE void panic(const char * fmt, ...)
83 __attribute__ ((NORET_AND format (printf, 1, 2)));
84 fastcall NORET_TYPE void do_exit(long error_code)
85 ATTRIB_NORET;
86 NORET_TYPE void complete_and_exit(struct completion *, long)
87 ATTRIB_NORET;
88 extern unsigned long simple_strtoul(const char *,char **,unsigned int);
89 extern long simple_strtol(const char *,char **,unsigned int);
90 extern unsigned long long simple_strtoull(const char *,char **,unsigned int);
91 extern long long simple_strtoll(const char *,char **,unsigned int);
92 extern int sprintf(char * buf, const char * fmt, ...)
93 __attribute__ ((format (printf, 2, 3)));
94 extern int vsprintf(char *buf, const char *, va_list)
95 __attribute__ ((format (printf, 2, 0)));
96 extern int snprintf(char * buf, size_t size, const char * fmt, ...)
97 __attribute__ ((format (printf, 3, 4)));
98 extern int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
99 __attribute__ ((format (printf, 3, 0)));
100 extern int scnprintf(char * buf, size_t size, const char * fmt, ...)
101 __attribute__ ((format (printf, 3, 4)));
102 extern int vscnprintf(char *buf, size_t size, const char *fmt, va_list args)
103 __attribute__ ((format (printf, 3, 0)));
105 extern int sscanf(const char *, const char *, ...)
106 __attribute__ ((format (scanf, 2, 3)));
107 extern int vsscanf(const char *, const char *, va_list)
108 __attribute__ ((format (scanf, 2, 0)));
110 extern int get_option(char **str, int *pint);
111 extern char *get_options(const char *str, int nints, int *ints);
112 extern unsigned long long memparse(char *ptr, char **retptr);
114 extern int __kernel_text_address(unsigned long addr);
115 extern int kernel_text_address(unsigned long addr);
116 extern int session_of_pgrp(int pgrp);
118 #ifdef CONFIG_PRINTK
119 asmlinkage int vprintk(const char *fmt, va_list args)
120 __attribute__ ((format (printf, 1, 0)));
121 asmlinkage int printk(const char * fmt, ...)
122 __attribute__ ((format (printf, 1, 2)));
123 #else
124 static inline int vprintk(const char *s, va_list args)
125 __attribute__ ((format (printf, 1, 0)));
126 static inline int vprintk(const char *s, va_list args) { return 0; }
127 static inline int printk(const char *s, ...)
128 __attribute__ ((format (printf, 1, 2)));
129 static inline int printk(const char *s, ...) { return 0; }
130 #endif
132 unsigned long int_sqrt(unsigned long);
134 static inline int __attribute_pure__ long_log2(unsigned long x)
136 int r = 0;
137 for (x >>= 1; x > 0; x >>= 1)
138 r++;
139 return r;
142 static inline unsigned long __attribute_const__ roundup_pow_of_two(unsigned long x)
144 return (1UL << fls(x - 1));
147 extern int printk_ratelimit(void);
148 extern int __printk_ratelimit(int ratelimit_jiffies, int ratelimit_burst);
150 static inline void console_silent(void)
152 console_loglevel = 0;
155 static inline void console_verbose(void)
157 if (console_loglevel)
158 console_loglevel = 15;
161 extern void bust_spinlocks(int yes);
162 extern int oops_in_progress; /* If set, an oops, panic(), BUG() or die() is in progress */
163 extern int panic_timeout;
164 extern int panic_on_oops;
165 extern int tainted;
166 extern const char *print_tainted(void);
167 extern void add_taint(unsigned);
169 /* Values used for system_state */
170 extern enum system_states {
171 SYSTEM_BOOTING,
172 SYSTEM_RUNNING,
173 SYSTEM_HALT,
174 SYSTEM_POWER_OFF,
175 SYSTEM_RESTART,
176 } system_state;
178 #define TAINT_PROPRIETARY_MODULE (1<<0)
179 #define TAINT_FORCED_MODULE (1<<1)
180 #define TAINT_UNSAFE_SMP (1<<2)
181 #define TAINT_FORCED_RMMOD (1<<3)
182 #define TAINT_MACHINE_CHECK (1<<4)
183 #define TAINT_BAD_PAGE (1<<5)
185 extern void dump_stack(void);
187 #ifdef DEBUG
188 #define pr_debug(fmt,arg...) \
189 printk(KERN_DEBUG fmt,##arg)
190 #else
191 #define pr_debug(fmt,arg...) \
192 do { } while (0)
193 #endif
195 #define pr_info(fmt,arg...) \
196 printk(KERN_INFO fmt,##arg)
199 * Display an IP address in readable format.
202 #define NIPQUAD(addr) \
203 ((unsigned char *)&addr)[0], \
204 ((unsigned char *)&addr)[1], \
205 ((unsigned char *)&addr)[2], \
206 ((unsigned char *)&addr)[3]
208 #define NIP6(addr) \
209 ntohs((addr).s6_addr16[0]), \
210 ntohs((addr).s6_addr16[1]), \
211 ntohs((addr).s6_addr16[2]), \
212 ntohs((addr).s6_addr16[3]), \
213 ntohs((addr).s6_addr16[4]), \
214 ntohs((addr).s6_addr16[5]), \
215 ntohs((addr).s6_addr16[6]), \
216 ntohs((addr).s6_addr16[7])
218 #if defined(__LITTLE_ENDIAN)
219 #define HIPQUAD(addr) \
220 ((unsigned char *)&addr)[3], \
221 ((unsigned char *)&addr)[2], \
222 ((unsigned char *)&addr)[1], \
223 ((unsigned char *)&addr)[0]
224 #elif defined(__BIG_ENDIAN)
225 #define HIPQUAD NIPQUAD
226 #else
227 #error "Please fix asm/byteorder.h"
228 #endif /* __LITTLE_ENDIAN */
231 * min()/max() macros that also do
232 * strict type-checking.. See the
233 * "unnecessary" pointer comparison.
235 #define min(x,y) ({ \
236 typeof(x) _x = (x); \
237 typeof(y) _y = (y); \
238 (void) (&_x == &_y); \
239 _x < _y ? _x : _y; })
241 #define max(x,y) ({ \
242 typeof(x) _x = (x); \
243 typeof(y) _y = (y); \
244 (void) (&_x == &_y); \
245 _x > _y ? _x : _y; })
248 * ..and if you can't take the strict
249 * types, you can specify one yourself.
251 * Or not use min/max at all, of course.
253 #define min_t(type,x,y) \
254 ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
255 #define max_t(type,x,y) \
256 ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
260 * container_of - cast a member of a structure out to the containing structure
262 * @ptr: the pointer to the member.
263 * @type: the type of the container struct this is embedded in.
264 * @member: the name of the member within the struct.
267 #define container_of(ptr, type, member) ({ \
268 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
269 (type *)( (char *)__mptr - offsetof(type,member) );})
272 * Check at compile time that something is of a particular type.
273 * Always evaluates to 1 so you may use it easily in comparisons.
275 #define typecheck(type,x) \
276 ({ type __dummy; \
277 typeof(x) __dummy2; \
278 (void)(&__dummy == &__dummy2); \
279 1; \
282 #endif /* __KERNEL__ */
284 #define SI_LOAD_SHIFT 16
285 struct sysinfo {
286 long uptime; /* Seconds since boot */
287 unsigned long loads[3]; /* 1, 5, and 15 minute load averages */
288 unsigned long totalram; /* Total usable main memory size */
289 unsigned long freeram; /* Available memory size */
290 unsigned long sharedram; /* Amount of shared memory */
291 unsigned long bufferram; /* Memory used by buffers */
292 unsigned long totalswap; /* Total swap space size */
293 unsigned long freeswap; /* swap space still available */
294 unsigned short procs; /* Number of current processes */
295 unsigned short pad; /* explicit padding for m68k */
296 unsigned long totalhigh; /* Total high memory size */
297 unsigned long freehigh; /* Available high memory size */
298 unsigned int mem_unit; /* Memory unit size in bytes */
299 char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding: libc5 uses this.. */
302 extern void BUILD_BUG(void);
303 #define BUILD_BUG_ON(condition) do { if (condition) BUILD_BUG(); } while(0)
305 #ifdef CONFIG_SYSCTL
306 extern int randomize_va_space;
307 #else
308 #define randomize_va_space 1
309 #endif
311 /* Trap pasters of __FUNCTION__ at compile-time */
312 #if __GNUC__ > 2 || __GNUC_MINOR__ >= 95
313 #define __FUNCTION__ (__func__)
314 #endif
316 #endif