diff options
Diffstat (limited to 'include/linux/kernel.h')
| -rw-r--r-- | include/linux/kernel.h | 73 |
1 files changed, 44 insertions, 29 deletions
diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 2451f1f7a1d9..c566927efcbd 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h | |||
| @@ -1,15 +1,6 @@ | |||
| 1 | #ifndef _LINUX_KERNEL_H | 1 | #ifndef _LINUX_KERNEL_H |
| 2 | #define _LINUX_KERNEL_H | 2 | #define _LINUX_KERNEL_H |
| 3 | 3 | ||
| 4 | #include <linux/sysinfo.h> | ||
| 5 | |||
| 6 | /* | ||
| 7 | * 'kernel.h' contains some often-used function prototypes etc | ||
| 8 | */ | ||
| 9 | #define __ALIGN_KERNEL(x, a) __ALIGN_KERNEL_MASK(x, (typeof(x))(a) - 1) | ||
| 10 | #define __ALIGN_KERNEL_MASK(x, mask) (((x) + (mask)) & ~(mask)) | ||
| 11 | |||
| 12 | #ifdef __KERNEL__ | ||
| 13 | 4 | ||
| 14 | #include <stdarg.h> | 5 | #include <stdarg.h> |
| 15 | #include <linux/linkage.h> | 6 | #include <linux/linkage.h> |
| @@ -22,6 +13,7 @@ | |||
| 22 | #include <linux/printk.h> | 13 | #include <linux/printk.h> |
| 23 | #include <linux/dynamic_debug.h> | 14 | #include <linux/dynamic_debug.h> |
| 24 | #include <asm/byteorder.h> | 15 | #include <asm/byteorder.h> |
| 16 | #include <uapi/linux/kernel.h> | ||
| 25 | 17 | ||
| 26 | #define USHRT_MAX ((u16)(~0U)) | 18 | #define USHRT_MAX ((u16)(~0U)) |
| 27 | #define SHRT_MAX ((s16)(USHRT_MAX>>1)) | 19 | #define SHRT_MAX ((s16)(USHRT_MAX>>1)) |
| @@ -85,13 +77,15 @@ | |||
| 85 | 77 | ||
| 86 | /* | 78 | /* |
| 87 | * Divide positive or negative dividend by positive divisor and round | 79 | * Divide positive or negative dividend by positive divisor and round |
| 88 | * to closest integer. Result is undefined for negative divisors. | 80 | * to closest integer. Result is undefined for negative divisors and |
| 81 | * for negative dividends if the divisor variable type is unsigned. | ||
| 89 | */ | 82 | */ |
| 90 | #define DIV_ROUND_CLOSEST(x, divisor)( \ | 83 | #define DIV_ROUND_CLOSEST(x, divisor)( \ |
| 91 | { \ | 84 | { \ |
| 92 | typeof(x) __x = x; \ | 85 | typeof(x) __x = x; \ |
| 93 | typeof(divisor) __d = divisor; \ | 86 | typeof(divisor) __d = divisor; \ |
| 94 | (((typeof(x))-1) > 0 || (__x) > 0) ? \ | 87 | (((typeof(x))-1) > 0 || \ |
| 88 | ((typeof(divisor))-1) > 0 || (__x) > 0) ? \ | ||
| 95 | (((__x) + ((__d) / 2)) / (__d)) : \ | 89 | (((__x) + ((__d) / 2)) / (__d)) : \ |
| 96 | (((__x) - ((__d) / 2)) / (__d)); \ | 90 | (((__x) - ((__d) / 2)) / (__d)); \ |
| 97 | } \ | 91 | } \ |
| @@ -228,6 +222,23 @@ int __must_check _kstrtol(const char *s, unsigned int base, long *res); | |||
| 228 | 222 | ||
| 229 | int __must_check kstrtoull(const char *s, unsigned int base, unsigned long long *res); | 223 | int __must_check kstrtoull(const char *s, unsigned int base, unsigned long long *res); |
| 230 | int __must_check kstrtoll(const char *s, unsigned int base, long long *res); | 224 | int __must_check kstrtoll(const char *s, unsigned int base, long long *res); |
| 225 | |||
| 226 | /** | ||
| 227 | * kstrtoul - convert a string to an unsigned long | ||
| 228 | * @s: The start of the string. The string must be null-terminated, and may also | ||
| 229 | * include a single newline before its terminating null. The first character | ||
| 230 | * may also be a plus sign, but not a minus sign. | ||
| 231 | * @base: The number base to use. The maximum supported base is 16. If base is | ||
| 232 | * given as 0, then the base of the string is automatically detected with the | ||
| 233 | * conventional semantics - If it begins with 0x the number will be parsed as a | ||
| 234 | * hexadecimal (case insensitive), if it otherwise begins with 0, it will be | ||
| 235 | * parsed as an octal number. Otherwise it will be parsed as a decimal. | ||
| 236 | * @res: Where to write the result of the conversion on success. | ||
| 237 | * | ||
| 238 | * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error. | ||
| 239 | * Used as a replacement for the obsolete simple_strtoull. Return code must | ||
| 240 | * be checked. | ||
| 241 | */ | ||
| 231 | static inline int __must_check kstrtoul(const char *s, unsigned int base, unsigned long *res) | 242 | static inline int __must_check kstrtoul(const char *s, unsigned int base, unsigned long *res) |
| 232 | { | 243 | { |
| 233 | /* | 244 | /* |
| @@ -241,6 +252,22 @@ static inline int __must_check kstrtoul(const char *s, unsigned int base, unsign | |||
| 241 | return _kstrtoul(s, base, res); | 252 | return _kstrtoul(s, base, res); |
| 242 | } | 253 | } |
| 243 | 254 | ||
| 255 | /** | ||
| 256 | * kstrtol - convert a string to a long | ||
| 257 | * @s: The start of the string. The string must be null-terminated, and may also | ||
| 258 | * include a single newline before its terminating null. The first character | ||
| 259 | * may also be a plus sign or a minus sign. | ||
| 260 | * @base: The number base to use. The maximum supported base is 16. If base is | ||
| 261 | * given as 0, then the base of the string is automatically detected with the | ||
| 262 | * conventional semantics - If it begins with 0x the number will be parsed as a | ||
| 263 | * hexadecimal (case insensitive), if it otherwise begins with 0, it will be | ||
| 264 | * parsed as an octal number. Otherwise it will be parsed as a decimal. | ||
| 265 | * @res: Where to write the result of the conversion on success. | ||
| 266 | * | ||
| 267 | * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error. | ||
| 268 | * Used as a replacement for the obsolete simple_strtoull. Return code must | ||
| 269 | * be checked. | ||
| 270 | */ | ||
| 244 | static inline int __must_check kstrtol(const char *s, unsigned int base, long *res) | 271 | static inline int __must_check kstrtol(const char *s, unsigned int base, long *res) |
| 245 | { | 272 | { |
| 246 | /* | 273 | /* |
| @@ -535,9 +562,6 @@ __ftrace_vprintk(unsigned long ip, const char *fmt, va_list ap); | |||
| 535 | 562 | ||
| 536 | extern void ftrace_dump(enum ftrace_dump_mode oops_dump_mode); | 563 | extern void ftrace_dump(enum ftrace_dump_mode oops_dump_mode); |
| 537 | #else | 564 | #else |
| 538 | static inline __printf(1, 2) | ||
| 539 | int trace_printk(const char *fmt, ...); | ||
| 540 | |||
| 541 | static inline void tracing_start(void) { } | 565 | static inline void tracing_start(void) { } |
| 542 | static inline void tracing_stop(void) { } | 566 | static inline void tracing_stop(void) { } |
| 543 | static inline void ftrace_off_permanent(void) { } | 567 | static inline void ftrace_off_permanent(void) { } |
| @@ -547,8 +571,8 @@ static inline void tracing_on(void) { } | |||
| 547 | static inline void tracing_off(void) { } | 571 | static inline void tracing_off(void) { } |
| 548 | static inline int tracing_is_on(void) { return 0; } | 572 | static inline int tracing_is_on(void) { return 0; } |
| 549 | 573 | ||
| 550 | static inline int | 574 | static inline __printf(1, 2) |
| 551 | trace_printk(const char *fmt, ...) | 575 | int trace_printk(const char *fmt, ...) |
| 552 | { | 576 | { |
| 553 | return 0; | 577 | return 0; |
| 554 | } | 578 | } |
| @@ -695,18 +719,11 @@ static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { } | |||
| 695 | /* Trap pasters of __FUNCTION__ at compile-time */ | 719 | /* Trap pasters of __FUNCTION__ at compile-time */ |
| 696 | #define __FUNCTION__ (__func__) | 720 | #define __FUNCTION__ (__func__) |
| 697 | 721 | ||
| 698 | /* This helps us to avoid #ifdef CONFIG_NUMA */ | 722 | /* This helps us to avoid #ifdef CONFIG_SYMBOL_PREFIX */ |
| 699 | #ifdef CONFIG_NUMA | 723 | #ifdef CONFIG_SYMBOL_PREFIX |
| 700 | #define NUMA_BUILD 1 | 724 | #define SYMBOL_PREFIX CONFIG_SYMBOL_PREFIX |
| 701 | #else | 725 | #else |
| 702 | #define NUMA_BUILD 0 | 726 | #define SYMBOL_PREFIX "" |
| 703 | #endif | ||
| 704 | |||
| 705 | /* This helps us avoid #ifdef CONFIG_COMPACTION */ | ||
| 706 | #ifdef CONFIG_COMPACTION | ||
| 707 | #define COMPACTION_BUILD 1 | ||
| 708 | #else | ||
| 709 | #define COMPACTION_BUILD 0 | ||
| 710 | #endif | 727 | #endif |
| 711 | 728 | ||
| 712 | /* Rebuild everything on CONFIG_FTRACE_MCOUNT_RECORD */ | 729 | /* Rebuild everything on CONFIG_FTRACE_MCOUNT_RECORD */ |
| @@ -716,6 +733,4 @@ static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { } | |||
| 716 | 733 | ||
| 717 | extern int do_sysinfo(struct sysinfo *info); | 734 | extern int do_sysinfo(struct sysinfo *info); |
| 718 | 735 | ||
| 719 | #endif /* __KERNEL__ */ | ||
| 720 | |||
| 721 | #endif | 736 | #endif |
