Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef _LINUX_KERNEL_H |
| 2 | #define _LINUX_KERNEL_H |
| 3 | |
| 4 | /* |
| 5 | * 'kernel.h' contains some often-used function prototypes etc |
| 6 | */ |
| 7 | |
| 8 | #ifdef __KERNEL__ |
| 9 | |
| 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> |
David Howells | f0d1b0b | 2006-12-08 02:37:49 -0800 | [diff] [blame] | 16 | #include <linux/log2.h> |
Andrew Morton | e0deaff4 | 2008-07-25 01:45:24 -0700 | [diff] [blame^] | 17 | #include <linux/typecheck.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <asm/byteorder.h> |
| 19 | #include <asm/bug.h> |
| 20 | |
Roman Zippel | 3eb3c74 | 2007-01-10 14:45:28 +0100 | [diff] [blame] | 21 | extern const char linux_banner[]; |
| 22 | extern const char linux_proc_banner[]; |
| 23 | |
Zhang, Yanmin | 44f564a | 2008-04-29 01:00:55 -0700 | [diff] [blame] | 24 | #define USHORT_MAX ((u16)(~0U)) |
| 25 | #define SHORT_MAX ((s16)(USHORT_MAX>>1)) |
| 26 | #define SHORT_MIN (-SHORT_MAX - 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #define INT_MAX ((int)(~0U>>1)) |
| 28 | #define INT_MIN (-INT_MAX - 1) |
| 29 | #define UINT_MAX (~0U) |
| 30 | #define LONG_MAX ((long)(~0UL>>1)) |
| 31 | #define LONG_MIN (-LONG_MAX - 1) |
| 32 | #define ULONG_MAX (~0UL) |
OGAWA Hirofumi | 111ebb6 | 2006-06-23 02:03:26 -0700 | [diff] [blame] | 33 | #define LLONG_MAX ((long long)(~0ULL>>1)) |
| 34 | #define LLONG_MIN (-LLONG_MAX - 1) |
| 35 | #define ULLONG_MAX (~0ULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
| 37 | #define STACK_MAGIC 0xdeadbeef |
| 38 | |
Linus Torvalds | 2ea5814 | 2006-11-26 19:05:22 -0800 | [diff] [blame] | 39 | #define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1) |
| 40 | #define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask)) |
Matthew Wilcox | a83308e | 2007-09-11 15:23:47 -0700 | [diff] [blame] | 41 | #define PTR_ALIGN(p, a) ((typeof(p))ALIGN((unsigned long)(p), (a))) |
Herbert Xu | f10db62 | 2008-02-06 01:37:05 -0800 | [diff] [blame] | 42 | #define IS_ALIGNED(x, a) (((x) & ((typeof(x))(a) - 1)) == 0) |
Linus Torvalds | 2ea5814 | 2006-11-26 19:05:22 -0800 | [diff] [blame] | 43 | |
Rusty Russell | c5e631cf | 2007-05-06 14:51:05 -0700 | [diff] [blame] | 44 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr)) |
| 45 | |
Jan Beulich | 4552d5d | 2006-06-26 13:57:28 +0200 | [diff] [blame] | 46 | #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f)) |
Steven Whitehouse | 930631e | 2006-09-25 23:32:40 -0700 | [diff] [blame] | 47 | #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) |
David Howells | b4cac1a | 2006-07-10 04:44:54 -0700 | [diff] [blame] | 48 | #define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
Eduard - Gabriel Munteanu | ca31e14 | 2008-07-05 12:14:23 +0300 | [diff] [blame] | 50 | #define _RET_IP_ (unsigned long)__builtin_return_address(0) |
| 51 | #define _THIS_IP_ ({ __label__ __here; __here: (unsigned long)&&__here; }) |
| 52 | |
Jens Axboe | 2da96ac | 2007-10-12 12:40:38 +0200 | [diff] [blame] | 53 | #ifdef CONFIG_LBD |
| 54 | # include <asm/div64.h> |
| 55 | # define sector_div(a, b) do_div(a, b) |
| 56 | #else |
| 57 | # define sector_div(n, b)( \ |
| 58 | { \ |
| 59 | int _res; \ |
| 60 | _res = (n) % (b); \ |
| 61 | (n) /= (b); \ |
| 62 | _res; \ |
| 63 | } \ |
| 64 | ) |
| 65 | #endif |
| 66 | |
Andrew Morton | 218e180 | 2007-05-10 03:15:18 -0700 | [diff] [blame] | 67 | /** |
| 68 | * upper_32_bits - return bits 32-63 of a number |
| 69 | * @n: the number we're accessing |
| 70 | * |
| 71 | * A basic shift-right of a 64- or 32-bit quantity. Use this to suppress |
| 72 | * the "right shift count >= width of type" warning when that quantity is |
| 73 | * 32-bits. |
| 74 | */ |
| 75 | #define upper_32_bits(n) ((u32)(((n) >> 16) >> 16)) |
| 76 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | #define KERN_EMERG "<0>" /* system is unusable */ |
| 78 | #define KERN_ALERT "<1>" /* action must be taken immediately */ |
| 79 | #define KERN_CRIT "<2>" /* critical conditions */ |
| 80 | #define KERN_ERR "<3>" /* error conditions */ |
| 81 | #define KERN_WARNING "<4>" /* warning conditions */ |
| 82 | #define KERN_NOTICE "<5>" /* normal but significant condition */ |
| 83 | #define KERN_INFO "<6>" /* informational */ |
| 84 | #define KERN_DEBUG "<7>" /* debug-level messages */ |
| 85 | |
Ingo Molnar | 4749252 | 2007-10-16 23:30:29 -0700 | [diff] [blame] | 86 | /* |
| 87 | * Annotation for a "continued" line of log printout (only done after a |
| 88 | * line that had no enclosing \n). Only to be used by core/arch code |
| 89 | * during early bootup (a continued line is not SMP-safe otherwise). |
| 90 | */ |
| 91 | #define KERN_CONT "" |
| 92 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | extern int console_printk[]; |
| 94 | |
| 95 | #define console_loglevel (console_printk[0]) |
| 96 | #define default_message_loglevel (console_printk[1]) |
| 97 | #define minimum_console_loglevel (console_printk[2]) |
| 98 | #define default_console_loglevel (console_printk[3]) |
| 99 | |
| 100 | struct completion; |
akpm@osdl.org | df2e71f | 2006-01-09 20:51:37 -0800 | [diff] [blame] | 101 | struct pt_regs; |
| 102 | struct user; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | |
| 104 | /** |
| 105 | * might_sleep - annotation for functions that can sleep |
| 106 | * |
| 107 | * this macro will print a stack trace if it is executed in an atomic |
| 108 | * context (spinlock, irq-handler, ...). |
| 109 | * |
| 110 | * This is a useful debugging help to be able to catch problems early and not |
Jim Cromie | e20ec99 | 2006-11-30 04:46:13 +0100 | [diff] [blame] | 111 | * be bitten later when the calling function happens to sleep when it is not |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | * supposed to. |
| 113 | */ |
Ingo Molnar | f8cbd99 | 2005-06-25 14:57:39 -0700 | [diff] [blame] | 114 | #ifdef CONFIG_PREEMPT_VOLUNTARY |
Herbert Xu | 02b67cc3 | 2008-01-25 21:08:28 +0100 | [diff] [blame] | 115 | extern int _cond_resched(void); |
| 116 | # define might_resched() _cond_resched() |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | #else |
Ingo Molnar | f8cbd99 | 2005-06-25 14:57:39 -0700 | [diff] [blame] | 118 | # define might_resched() do { } while (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | #endif |
| 120 | |
Ingo Molnar | f8cbd99 | 2005-06-25 14:57:39 -0700 | [diff] [blame] | 121 | #ifdef CONFIG_DEBUG_SPINLOCK_SLEEP |
| 122 | void __might_sleep(char *file, int line); |
| 123 | # define might_sleep() \ |
| 124 | do { __might_sleep(__FILE__, __LINE__); might_resched(); } while (0) |
| 125 | #else |
| 126 | # define might_sleep() do { might_resched(); } while (0) |
| 127 | #endif |
| 128 | |
Hua Zhong | 368a5fa | 2006-06-23 02:05:42 -0700 | [diff] [blame] | 129 | #define might_sleep_if(cond) do { if (cond) might_sleep(); } while (0) |
Ingo Molnar | f8cbd99 | 2005-06-25 14:57:39 -0700 | [diff] [blame] | 130 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | #define abs(x) ({ \ |
| 132 | int __x = (x); \ |
| 133 | (__x < 0) ? -__x : __x; \ |
| 134 | }) |
| 135 | |
Alan Stern | e041c68 | 2006-03-27 01:16:30 -0800 | [diff] [blame] | 136 | extern struct atomic_notifier_head panic_notifier_list; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | extern long (*panic_blink)(long time); |
| 138 | NORET_TYPE void panic(const char * fmt, ...) |
Andi Kleen | a586df0 | 2007-07-21 17:10:00 +0200 | [diff] [blame] | 139 | __attribute__ ((NORET_AND format (printf, 1, 2))) __cold; |
Andrew Morton | dd28779 | 2006-03-23 03:00:57 -0800 | [diff] [blame] | 140 | extern void oops_enter(void); |
| 141 | extern void oops_exit(void); |
| 142 | extern int oops_may_print(void); |
Harvey Harrison | ec70158 | 2008-02-08 04:19:55 -0800 | [diff] [blame] | 143 | NORET_TYPE void do_exit(long error_code) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | ATTRIB_NORET; |
| 145 | NORET_TYPE void complete_and_exit(struct completion *, long) |
| 146 | ATTRIB_NORET; |
| 147 | extern unsigned long simple_strtoul(const char *,char **,unsigned int); |
| 148 | extern long simple_strtol(const char *,char **,unsigned int); |
| 149 | extern unsigned long long simple_strtoull(const char *,char **,unsigned int); |
| 150 | extern long long simple_strtoll(const char *,char **,unsigned int); |
Yi Yang | 06b2a76 | 2008-02-08 04:21:57 -0800 | [diff] [blame] | 151 | extern int strict_strtoul(const char *, unsigned int, unsigned long *); |
| 152 | extern int strict_strtol(const char *, unsigned int, long *); |
| 153 | extern int strict_strtoull(const char *, unsigned int, unsigned long long *); |
| 154 | extern int strict_strtoll(const char *, unsigned int, long long *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | extern int sprintf(char * buf, const char * fmt, ...) |
| 156 | __attribute__ ((format (printf, 2, 3))); |
| 157 | extern int vsprintf(char *buf, const char *, va_list) |
| 158 | __attribute__ ((format (printf, 2, 0))); |
| 159 | extern int snprintf(char * buf, size_t size, const char * fmt, ...) |
| 160 | __attribute__ ((format (printf, 3, 4))); |
| 161 | extern int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) |
| 162 | __attribute__ ((format (printf, 3, 0))); |
| 163 | extern int scnprintf(char * buf, size_t size, const char * fmt, ...) |
| 164 | __attribute__ ((format (printf, 3, 4))); |
| 165 | extern int vscnprintf(char *buf, size_t size, const char *fmt, va_list args) |
| 166 | __attribute__ ((format (printf, 3, 0))); |
Jeremy Fitzhardinge | e905914 | 2006-06-25 05:49:17 -0700 | [diff] [blame] | 167 | extern char *kasprintf(gfp_t gfp, const char *fmt, ...) |
| 168 | __attribute__ ((format (printf, 2, 3))); |
Jeremy Fitzhardinge | 11443ec | 2007-04-30 15:09:56 -0700 | [diff] [blame] | 169 | extern char *kvasprintf(gfp_t gfp, const char *fmt, va_list args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | |
| 171 | extern int sscanf(const char *, const char *, ...) |
| 172 | __attribute__ ((format (scanf, 2, 3))); |
| 173 | extern int vsscanf(const char *, const char *, va_list) |
| 174 | __attribute__ ((format (scanf, 2, 0))); |
| 175 | |
| 176 | extern int get_option(char **str, int *pint); |
| 177 | extern char *get_options(const char *str, int nints, int *ints); |
| 178 | extern unsigned long long memparse(char *ptr, char **retptr); |
| 179 | |
Trent Piepho | 5e37661 | 2006-05-15 09:44:06 -0700 | [diff] [blame] | 180 | extern int core_kernel_text(unsigned long addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | extern int __kernel_text_address(unsigned long addr); |
| 182 | extern int kernel_text_address(unsigned long addr); |
Eric W. Biederman | 04a2e6a | 2007-02-12 00:52:56 -0800 | [diff] [blame] | 183 | struct pid; |
| 184 | extern struct pid *session_of_pgrp(struct pid *pgrp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | |
Matt Mackall | d59745c | 2005-05-01 08:59:02 -0700 | [diff] [blame] | 186 | #ifdef CONFIG_PRINTK |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | asmlinkage int vprintk(const char *fmt, va_list args) |
| 188 | __attribute__ ((format (printf, 1, 0))); |
| 189 | asmlinkage int printk(const char * fmt, ...) |
Andi Kleen | a586df0 | 2007-07-21 17:10:00 +0200 | [diff] [blame] | 190 | __attribute__ ((format (printf, 1, 2))) __cold; |
Joe Perches | 7ef3d2f | 2008-02-08 04:21:25 -0800 | [diff] [blame] | 191 | |
| 192 | extern int printk_ratelimit_jiffies; |
| 193 | extern int printk_ratelimit_burst; |
| 194 | extern int printk_ratelimit(void); |
Dave Young | 5f97a5a | 2008-04-29 00:59:43 -0700 | [diff] [blame] | 195 | extern int __ratelimit(int ratelimit_jiffies, int ratelimit_burst); |
Joe Perches | 7ef3d2f | 2008-02-08 04:21:25 -0800 | [diff] [blame] | 196 | extern int __printk_ratelimit(int ratelimit_jiffies, int ratelimit_burst); |
| 197 | extern bool printk_timed_ratelimit(unsigned long *caller_jiffies, |
| 198 | unsigned int interval_msec); |
Matt Mackall | d59745c | 2005-05-01 08:59:02 -0700 | [diff] [blame] | 199 | #else |
| 200 | static inline int vprintk(const char *s, va_list args) |
| 201 | __attribute__ ((format (printf, 1, 0))); |
| 202 | static inline int vprintk(const char *s, va_list args) { return 0; } |
| 203 | static inline int printk(const char *s, ...) |
| 204 | __attribute__ ((format (printf, 1, 2))); |
Andi Kleen | a586df0 | 2007-07-21 17:10:00 +0200 | [diff] [blame] | 205 | static inline int __cold printk(const char *s, ...) { return 0; } |
Joe Perches | 7ef3d2f | 2008-02-08 04:21:25 -0800 | [diff] [blame] | 206 | static inline int printk_ratelimit(void) { return 0; } |
| 207 | static inline int __printk_ratelimit(int ratelimit_jiffies, \ |
| 208 | int ratelimit_burst) { return 0; } |
| 209 | static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies, \ |
| 210 | unsigned int interval_msec) \ |
| 211 | { return false; } |
Matt Mackall | d59745c | 2005-05-01 08:59:02 -0700 | [diff] [blame] | 212 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | |
Jiri Slaby | e17ba73 | 2008-05-12 15:44:40 +0200 | [diff] [blame] | 214 | extern void asmlinkage __attribute__((format(printf, 1, 2))) |
Ingo Molnar | 076f977 | 2008-01-30 13:33:06 +0100 | [diff] [blame] | 215 | early_printk(const char *fmt, ...); |
| 216 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | unsigned long int_sqrt(unsigned long); |
| 218 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | static inline void console_silent(void) |
| 220 | { |
| 221 | console_loglevel = 0; |
| 222 | } |
| 223 | |
| 224 | static inline void console_verbose(void) |
| 225 | { |
| 226 | if (console_loglevel) |
| 227 | console_loglevel = 15; |
| 228 | } |
| 229 | |
| 230 | extern void bust_spinlocks(int yes); |
Kirill Korotaev | e3e8a75 | 2007-02-10 01:46:19 -0800 | [diff] [blame] | 231 | extern void wake_up_klogd(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | extern int oops_in_progress; /* If set, an oops, panic(), BUG() or die() is in progress */ |
Adrian Bunk | aa72710 | 2006-04-10 22:53:59 -0700 | [diff] [blame] | 233 | extern int panic_timeout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | extern int panic_on_oops; |
Don Zickus | 8da5add | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 235 | extern int panic_on_unrecovered_nmi; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | extern int tainted; |
| 237 | extern const char *print_tainted(void); |
| 238 | extern void add_taint(unsigned); |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 239 | extern int root_mountflags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | |
| 241 | /* Values used for system_state */ |
| 242 | extern enum system_states { |
| 243 | SYSTEM_BOOTING, |
| 244 | SYSTEM_RUNNING, |
| 245 | SYSTEM_HALT, |
| 246 | SYSTEM_POWER_OFF, |
| 247 | SYSTEM_RESTART, |
Alexey Starikovskiy | 729b4d4 | 2005-12-01 04:29:00 -0500 | [diff] [blame] | 248 | SYSTEM_SUSPEND_DISK, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | } system_state; |
| 250 | |
| 251 | #define TAINT_PROPRIETARY_MODULE (1<<0) |
| 252 | #define TAINT_FORCED_MODULE (1<<1) |
| 253 | #define TAINT_UNSAFE_SMP (1<<2) |
| 254 | #define TAINT_FORCED_RMMOD (1<<3) |
| 255 | #define TAINT_MACHINE_CHECK (1<<4) |
| 256 | #define TAINT_BAD_PAGE (1<<5) |
Theodore Ts'o | 34f5a39 | 2007-02-10 01:45:24 -0800 | [diff] [blame] | 257 | #define TAINT_USER (1<<6) |
Pavel Emelianov | bcdcd8e | 2007-07-17 04:03:42 -0700 | [diff] [blame] | 258 | #define TAINT_DIE (1<<7) |
Éric Piel | 6ed31e9 | 2008-02-05 00:04:50 +0100 | [diff] [blame] | 259 | #define TAINT_OVERRIDDEN_ACPI_TABLE (1<<8) |
Nur Hussein | 95b570c | 2008-04-29 00:58:39 -0700 | [diff] [blame] | 260 | #define TAINT_WARN (1<<9) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | |
Andi Kleen | a586df0 | 2007-07-21 17:10:00 +0200 | [diff] [blame] | 262 | extern void dump_stack(void) __cold; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | |
Randy Dunlap | 99eaf3c | 2007-05-10 22:22:39 -0700 | [diff] [blame] | 264 | enum { |
| 265 | DUMP_PREFIX_NONE, |
| 266 | DUMP_PREFIX_ADDRESS, |
| 267 | DUMP_PREFIX_OFFSET |
| 268 | }; |
Randy Dunlap | c790923 | 2007-06-08 13:47:04 -0700 | [diff] [blame] | 269 | extern void hex_dump_to_buffer(const void *buf, size_t len, |
| 270 | int rowsize, int groupsize, |
| 271 | char *linebuf, size_t linebuflen, bool ascii); |
| 272 | extern void print_hex_dump(const char *level, const char *prefix_str, |
| 273 | int prefix_type, int rowsize, int groupsize, |
Artem Bityutskiy | 6a0ed91 | 2007-08-07 23:43:14 +0300 | [diff] [blame] | 274 | const void *buf, size_t len, bool ascii); |
Randy Dunlap | c790923 | 2007-06-08 13:47:04 -0700 | [diff] [blame] | 275 | extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type, |
Alan Stern | eb9a9a5 | 2007-08-10 13:01:07 -0700 | [diff] [blame] | 276 | const void *buf, size_t len); |
Harvey Harrison | 3fc9577 | 2008-05-14 16:05:49 -0700 | [diff] [blame] | 277 | |
| 278 | extern const char hex_asc[]; |
| 279 | #define hex_asc_lo(x) hex_asc[((x) & 0x0f)] |
| 280 | #define hex_asc_hi(x) hex_asc[((x) & 0xf0) >> 4] |
| 281 | |
| 282 | static inline char *pack_hex_byte(char *buf, u8 byte) |
| 283 | { |
| 284 | *buf++ = hex_asc_hi(byte); |
| 285 | *buf++ = hex_asc_lo(byte); |
| 286 | return buf; |
| 287 | } |
Randy Dunlap | 99eaf3c | 2007-05-10 22:22:39 -0700 | [diff] [blame] | 288 | |
Emil Medve | 1f7c823 | 2007-10-16 23:29:48 -0700 | [diff] [blame] | 289 | #define pr_emerg(fmt, arg...) \ |
| 290 | printk(KERN_EMERG fmt, ##arg) |
| 291 | #define pr_alert(fmt, arg...) \ |
| 292 | printk(KERN_ALERT fmt, ##arg) |
| 293 | #define pr_crit(fmt, arg...) \ |
| 294 | printk(KERN_CRIT fmt, ##arg) |
| 295 | #define pr_err(fmt, arg...) \ |
| 296 | printk(KERN_ERR fmt, ##arg) |
| 297 | #define pr_warning(fmt, arg...) \ |
| 298 | printk(KERN_WARNING fmt, ##arg) |
| 299 | #define pr_notice(fmt, arg...) \ |
| 300 | printk(KERN_NOTICE fmt, ##arg) |
| 301 | #define pr_info(fmt, arg...) \ |
| 302 | printk(KERN_INFO fmt, ##arg) |
| 303 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | #ifdef DEBUG |
Pavel Machek | 1cc6daf | 2006-08-08 01:37:15 +0200 | [diff] [blame] | 305 | /* If you are writing a driver, please use dev_dbg instead */ |
Emil Medve | 1f7c823 | 2007-10-16 23:29:48 -0700 | [diff] [blame] | 306 | #define pr_debug(fmt, arg...) \ |
| 307 | printk(KERN_DEBUG fmt, ##arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | #else |
Joe Perches | 1429db8 | 2008-02-26 19:08:42 -0800 | [diff] [blame] | 309 | #define pr_debug(fmt, arg...) \ |
| 310 | ({ if (0) printk(KERN_DEBUG fmt, ##arg); 0; }) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | #endif |
| 312 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | /* |
| 314 | * Display an IP address in readable format. |
| 315 | */ |
| 316 | |
| 317 | #define NIPQUAD(addr) \ |
| 318 | ((unsigned char *)&addr)[0], \ |
| 319 | ((unsigned char *)&addr)[1], \ |
| 320 | ((unsigned char *)&addr)[2], \ |
| 321 | ((unsigned char *)&addr)[3] |
Joe Perches | 46b86a2 | 2006-01-13 14:29:07 -0800 | [diff] [blame] | 322 | #define NIPQUAD_FMT "%u.%u.%u.%u" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | |
| 324 | #define NIP6(addr) \ |
| 325 | ntohs((addr).s6_addr16[0]), \ |
| 326 | ntohs((addr).s6_addr16[1]), \ |
| 327 | ntohs((addr).s6_addr16[2]), \ |
| 328 | ntohs((addr).s6_addr16[3]), \ |
| 329 | ntohs((addr).s6_addr16[4]), \ |
| 330 | ntohs((addr).s6_addr16[5]), \ |
| 331 | ntohs((addr).s6_addr16[6]), \ |
| 332 | ntohs((addr).s6_addr16[7]) |
Joe Perches | 46b86a2 | 2006-01-13 14:29:07 -0800 | [diff] [blame] | 333 | #define NIP6_FMT "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x" |
YOSHIFUJI Hideaki | 9343e79 | 2006-01-17 02:10:53 -0800 | [diff] [blame] | 334 | #define NIP6_SEQFMT "%04x%04x%04x%04x%04x%04x%04x%04x" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | |
| 336 | #if defined(__LITTLE_ENDIAN) |
| 337 | #define HIPQUAD(addr) \ |
| 338 | ((unsigned char *)&addr)[3], \ |
| 339 | ((unsigned char *)&addr)[2], \ |
| 340 | ((unsigned char *)&addr)[1], \ |
| 341 | ((unsigned char *)&addr)[0] |
| 342 | #elif defined(__BIG_ENDIAN) |
| 343 | #define HIPQUAD NIPQUAD |
| 344 | #else |
| 345 | #error "Please fix asm/byteorder.h" |
| 346 | #endif /* __LITTLE_ENDIAN */ |
| 347 | |
| 348 | /* |
Harvey Harrison | bdf4bba | 2008-04-30 00:54:55 -0700 | [diff] [blame] | 349 | * min()/max()/clamp() macros that also do |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | * strict type-checking.. See the |
| 351 | * "unnecessary" pointer comparison. |
| 352 | */ |
Harvey Harrison | bdf4bba | 2008-04-30 00:54:55 -0700 | [diff] [blame] | 353 | #define min(x, y) ({ \ |
| 354 | typeof(x) _min1 = (x); \ |
| 355 | typeof(y) _min2 = (y); \ |
| 356 | (void) (&_min1 == &_min2); \ |
| 357 | _min1 < _min2 ? _min1 : _min2; }) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | |
Harvey Harrison | bdf4bba | 2008-04-30 00:54:55 -0700 | [diff] [blame] | 359 | #define max(x, y) ({ \ |
| 360 | typeof(x) _max1 = (x); \ |
| 361 | typeof(y) _max2 = (y); \ |
| 362 | (void) (&_max1 == &_max2); \ |
| 363 | _max1 > _max2 ? _max1 : _max2; }) |
| 364 | |
| 365 | /** |
| 366 | * clamp - return a value clamped to a given range with strict typechecking |
| 367 | * @val: current value |
| 368 | * @min: minimum allowable value |
| 369 | * @max: maximum allowable value |
| 370 | * |
| 371 | * This macro does strict typechecking of min/max to make sure they are of the |
| 372 | * same type as val. See the unnecessary pointer comparisons. |
| 373 | */ |
| 374 | #define clamp(val, min, max) ({ \ |
| 375 | typeof(val) __val = (val); \ |
| 376 | typeof(min) __min = (min); \ |
| 377 | typeof(max) __max = (max); \ |
| 378 | (void) (&__val == &__min); \ |
| 379 | (void) (&__val == &__max); \ |
| 380 | __val = __val < __min ? __min: __val; \ |
| 381 | __val > __max ? __max: __val; }) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | |
| 383 | /* |
| 384 | * ..and if you can't take the strict |
| 385 | * types, you can specify one yourself. |
| 386 | * |
Harvey Harrison | bdf4bba | 2008-04-30 00:54:55 -0700 | [diff] [blame] | 387 | * Or not use min/max/clamp at all, of course. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | */ |
Harvey Harrison | bdf4bba | 2008-04-30 00:54:55 -0700 | [diff] [blame] | 389 | #define min_t(type, x, y) ({ \ |
| 390 | type __min1 = (x); \ |
| 391 | type __min2 = (y); \ |
| 392 | __min1 < __min2 ? __min1: __min2; }) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | |
Harvey Harrison | bdf4bba | 2008-04-30 00:54:55 -0700 | [diff] [blame] | 394 | #define max_t(type, x, y) ({ \ |
| 395 | type __max1 = (x); \ |
| 396 | type __max2 = (y); \ |
| 397 | __max1 > __max2 ? __max1: __max2; }) |
| 398 | |
| 399 | /** |
| 400 | * clamp_t - return a value clamped to a given range using a given type |
| 401 | * @type: the type of variable to use |
| 402 | * @val: current value |
| 403 | * @min: minimum allowable value |
| 404 | * @max: maximum allowable value |
| 405 | * |
| 406 | * This macro does no typechecking and uses temporary variables of type |
| 407 | * 'type' to make all the comparisons. |
| 408 | */ |
| 409 | #define clamp_t(type, val, min, max) ({ \ |
| 410 | type __val = (val); \ |
| 411 | type __min = (min); \ |
| 412 | type __max = (max); \ |
| 413 | __val = __val < __min ? __min: __val; \ |
| 414 | __val > __max ? __max: __val; }) |
| 415 | |
| 416 | /** |
| 417 | * clamp_val - return a value clamped to a given range using val's type |
| 418 | * @val: current value |
| 419 | * @min: minimum allowable value |
| 420 | * @max: maximum allowable value |
| 421 | * |
| 422 | * This macro does no typechecking and uses temporary variables of whatever |
| 423 | * type the input argument 'val' is. This is useful when val is an unsigned |
| 424 | * type and min and max are literals that will otherwise be assigned a signed |
| 425 | * integer type. |
| 426 | */ |
| 427 | #define clamp_val(val, min, max) ({ \ |
| 428 | typeof(val) __val = (val); \ |
| 429 | typeof(val) __min = (min); \ |
| 430 | typeof(val) __max = (max); \ |
| 431 | __val = __val < __min ? __min: __val; \ |
| 432 | __val > __max ? __max: __val; }) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | |
| 434 | /** |
| 435 | * container_of - cast a member of a structure out to the containing structure |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | * @ptr: the pointer to the member. |
| 437 | * @type: the type of the container struct this is embedded in. |
| 438 | * @member: the name of the member within the struct. |
| 439 | * |
| 440 | */ |
| 441 | #define container_of(ptr, type, member) ({ \ |
Daniel Walker | 78db2ad | 2007-05-12 16:28:35 -0700 | [diff] [blame] | 442 | const typeof( ((type *)0)->member ) *__mptr = (ptr); \ |
| 443 | (type *)( (char *)__mptr - offsetof(type,member) );}) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | |
Kyle McMartin | d4d23ad | 2007-02-10 01:46:00 -0800 | [diff] [blame] | 445 | struct sysinfo; |
| 446 | extern int do_sysinfo(struct sysinfo *info); |
| 447 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | #endif /* __KERNEL__ */ |
| 449 | |
| 450 | #define SI_LOAD_SHIFT 16 |
| 451 | struct sysinfo { |
| 452 | long uptime; /* Seconds since boot */ |
| 453 | unsigned long loads[3]; /* 1, 5, and 15 minute load averages */ |
| 454 | unsigned long totalram; /* Total usable main memory size */ |
| 455 | unsigned long freeram; /* Available memory size */ |
| 456 | unsigned long sharedram; /* Amount of shared memory */ |
| 457 | unsigned long bufferram; /* Memory used by buffers */ |
| 458 | unsigned long totalswap; /* Total swap space size */ |
| 459 | unsigned long freeswap; /* swap space still available */ |
| 460 | unsigned short procs; /* Number of current processes */ |
| 461 | unsigned short pad; /* explicit padding for m68k */ |
| 462 | unsigned long totalhigh; /* Total high memory size */ |
| 463 | unsigned long freehigh; /* Available high memory size */ |
| 464 | unsigned int mem_unit; /* Memory unit size in bytes */ |
| 465 | char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding: libc5 uses this.. */ |
| 466 | }; |
| 467 | |
Nikita Danilov | c0398ee | 2005-10-30 15:03:10 -0800 | [diff] [blame] | 468 | /* Force a compilation error if condition is true */ |
Andi Kleen | 921717a | 2005-09-13 01:25:13 -0700 | [diff] [blame] | 469 | #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)])) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | |
Jan Beulich | 4552d5d | 2006-06-26 13:57:28 +0200 | [diff] [blame] | 471 | /* Force a compilation error if condition is true, but also produce a |
| 472 | result (of value 0 and type size_t), so the expression can be used |
| 473 | e.g. in a structure initializer (or where-ever else comma expressions |
| 474 | aren't permitted). */ |
| 475 | #define BUILD_BUG_ON_ZERO(e) (sizeof(char[1 - 2 * !!(e)]) - 1) |
| 476 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | /* Trap pasters of __FUNCTION__ at compile-time */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | #define __FUNCTION__ (__func__) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | |
Christoph Lameter | 08e0f6a | 2006-09-27 01:50:06 -0700 | [diff] [blame] | 480 | /* This helps us to avoid #ifdef CONFIG_NUMA */ |
| 481 | #ifdef CONFIG_NUMA |
| 482 | #define NUMA_BUILD 1 |
| 483 | #else |
| 484 | #define NUMA_BUILD 0 |
| 485 | #endif |
| 486 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | #endif |