Merge with Linux 2.5.48.
[linux-2.6/linux-mips.git] / include / linux / kernel.h
blobb26057b85ea0f148ce978bfe5a07076ab5be6458
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 <asm/byteorder.h>
17 /* Optimization barrier */
18 /* The "volatile" is due to gcc bugs */
19 #define barrier() __asm__ __volatile__("": : :"memory")
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]))
32 #define KERN_EMERG "<0>" /* system is unusable */
33 #define KERN_ALERT "<1>" /* action must be taken immediately */
34 #define KERN_CRIT "<2>" /* critical conditions */
35 #define KERN_ERR "<3>" /* error conditions */
36 #define KERN_WARNING "<4>" /* warning conditions */
37 #define KERN_NOTICE "<5>" /* normal but significant condition */
38 #define KERN_INFO "<6>" /* informational */
39 #define KERN_DEBUG "<7>" /* debug-level messages */
41 struct completion;
43 #ifdef CONFIG_DEBUG_KERNEL
44 void __might_sleep(char *file, int line);
45 #define might_sleep() __might_sleep(__FILE__, __LINE__)
46 #else
47 #define might_sleep() do {} while(0)
48 #endif
50 extern struct notifier_block *panic_notifier_list;
51 NORET_TYPE void panic(const char * fmt, ...)
52 __attribute__ ((NORET_AND format (printf, 1, 2)));
53 asmlinkage NORET_TYPE void do_exit(long error_code)
54 ATTRIB_NORET;
55 NORET_TYPE void complete_and_exit(struct completion *, long)
56 ATTRIB_NORET;
57 extern int abs(int);
58 extern unsigned long simple_strtoul(const char *,char **,unsigned int);
59 extern long simple_strtol(const char *,char **,unsigned int);
60 extern unsigned long long simple_strtoull(const char *,char **,unsigned int);
61 extern long long simple_strtoll(const char *,char **,unsigned int);
62 extern int sprintf(char * buf, const char * fmt, ...)
63 __attribute__ ((format (printf, 2, 3)));
64 extern int vsprintf(char *buf, const char *, va_list);
65 extern int snprintf(char * buf, size_t size, const char * fmt, ...)
66 __attribute__ ((format (printf, 3, 4)));
67 extern int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
69 extern int sscanf(const char *, const char *, ...)
70 __attribute__ ((format (scanf,2,3)));
71 extern int vsscanf(const char *, const char *, va_list);
73 extern int get_option(char **str, int *pint);
74 extern char *get_options(char *str, int nints, int *ints);
75 extern unsigned long long memparse(char *ptr, char **retptr);
76 extern void dev_probe_lock(void);
77 extern void dev_probe_unlock(void);
79 extern int session_of_pgrp(int pgrp);
81 asmlinkage int printk(const char * fmt, ...)
82 __attribute__ ((format (printf, 1, 2)));
84 extern int console_loglevel;
86 static inline void console_silent(void)
88 console_loglevel = 0;
91 static inline void console_verbose(void)
93 if (console_loglevel)
94 console_loglevel = 15;
97 extern void bust_spinlocks(int yes);
98 extern int oops_in_progress; /* If set, an oops, panic(), BUG() or die() is in progress */
100 extern int tainted;
101 extern const char *print_tainted(void);
102 #define TAINT_PROPRIETORY_MODULE (1<<0)
103 #define TAINT_FORCED_MODULE (1<<1)
104 #define TAINT_UNSAFE_SMP (1<<2)
105 #define TAINT_FORCED_RMMOD (1<<3)
107 extern void dump_stack(void);
109 #ifdef DEBUG
110 #define pr_debug(fmt,arg...) \
111 printk(KERN_DEBUG fmt,##arg)
112 #else
113 #define pr_debug(fmt,arg...) \
114 do { } while (0)
115 #endif
117 #define pr_info(fmt,arg...) \
118 printk(KERN_INFO fmt,##arg)
121 * Display an IP address in readable format.
124 #define NIPQUAD(addr) \
125 ((unsigned char *)&addr)[0], \
126 ((unsigned char *)&addr)[1], \
127 ((unsigned char *)&addr)[2], \
128 ((unsigned char *)&addr)[3]
130 #if defined(__LITTLE_ENDIAN)
131 #define HIPQUAD(addr) \
132 ((unsigned char *)&addr)[3], \
133 ((unsigned char *)&addr)[2], \
134 ((unsigned char *)&addr)[1], \
135 ((unsigned char *)&addr)[0]
136 #elif defined(__BIG_ENDIAN)
137 #define HIPQUAD NIPQUAD
138 #else
139 #error "Please fix asm/byteorder.h"
140 #endif /* __LITTLE_ENDIAN */
143 * min()/max() macros that also do
144 * strict type-checking.. See the
145 * "unnecessary" pointer comparison.
147 #define min(x,y) ({ \
148 const typeof(x) _x = (x); \
149 const typeof(y) _y = (y); \
150 (void) (&_x == &_y); \
151 _x < _y ? _x : _y; })
153 #define max(x,y) ({ \
154 const typeof(x) _x = (x); \
155 const typeof(y) _y = (y); \
156 (void) (&_x == &_y); \
157 _x > _y ? _x : _y; })
160 * ..and if you can't take the strict
161 * types, you can specify one yourself.
163 * Or not use min/max at all, of course.
165 #define min_t(type,x,y) \
166 ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
167 #define max_t(type,x,y) \
168 ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
172 * container_of - cast a member of a structure out to the containing structure
174 * @ptr: the pointer to the member.
175 * @type: the type of the container struct this is embedded in.
176 * @member: the name of the member within the struct.
179 #define container_of(ptr, type, member) ({ \
180 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
181 (type *)( (char *)__mptr - offsetof(type,member) );})
183 #endif /* __KERNEL__ */
185 #define SI_LOAD_SHIFT 16
186 struct sysinfo {
187 long uptime; /* Seconds since boot */
188 unsigned long loads[3]; /* 1, 5, and 15 minute load averages */
189 unsigned long totalram; /* Total usable main memory size */
190 unsigned long freeram; /* Available memory size */
191 unsigned long sharedram; /* Amount of shared memory */
192 unsigned long bufferram; /* Memory used by buffers */
193 unsigned long totalswap; /* Total swap space size */
194 unsigned long freeswap; /* swap space still available */
195 unsigned short procs; /* Number of current processes */
196 unsigned short pad; /* explicit padding for m68k */
197 unsigned long totalhigh; /* Total high memory size */
198 unsigned long freehigh; /* Available high memory size */
199 unsigned int mem_unit; /* Memory unit size in bytes */
200 char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding: libc5 uses this.. */
203 #define BUG_ON(condition) do { if (unlikely((condition)!=0)) BUG(); } while(0)
204 #define WARN_ON(condition) do { \
205 if (unlikely((condition)!=0)) { \
206 printk("Badness in %s at %s:%d\n", __FUNCTION__, __FILE__, __LINE__); \
207 dump_stack(); \
209 } while (0)
211 extern void BUILD_BUG(void);
212 #define BUILD_BUG_ON(condition) do { if (condition) BUILD_BUG(); } while(0)
214 /* Trap pasters of __FUNCTION__ at compile-time */
215 #if __GNUC__ > 2 || __GNUC_MINOR__ >= 95
216 #define __FUNCTION__ (__func__)
217 #endif
219 #endif