xref: /linux-6.15/include/linux/kernel.h (revision e4aafea2)
11da177e4SLinus Torvalds #ifndef _LINUX_KERNEL_H
21da177e4SLinus Torvalds #define _LINUX_KERNEL_H
31da177e4SLinus Torvalds 
41da177e4SLinus Torvalds /*
51da177e4SLinus Torvalds  * 'kernel.h' contains some often-used function prototypes etc
61da177e4SLinus Torvalds  */
71da177e4SLinus Torvalds 
81da177e4SLinus Torvalds #ifdef __KERNEL__
91da177e4SLinus Torvalds 
101da177e4SLinus Torvalds #include <stdarg.h>
111da177e4SLinus Torvalds #include <linux/linkage.h>
121da177e4SLinus Torvalds #include <linux/stddef.h>
131da177e4SLinus Torvalds #include <linux/types.h>
141da177e4SLinus Torvalds #include <linux/compiler.h>
151da177e4SLinus Torvalds #include <linux/bitops.h>
16f0d1b0b3SDavid Howells #include <linux/log2.h>
17e0deaff4SAndrew Morton #include <linux/typecheck.h>
18717115e1SDave Young #include <linux/ratelimit.h>
19e9d376f0SJason Baron #include <linux/dynamic_debug.h>
201da177e4SLinus Torvalds #include <asm/byteorder.h>
211da177e4SLinus Torvalds #include <asm/bug.h>
221da177e4SLinus Torvalds 
233eb3c740SRoman Zippel extern const char linux_banner[];
243eb3c740SRoman Zippel extern const char linux_proc_banner[];
253eb3c740SRoman Zippel 
2644f564a4SZhang, Yanmin #define USHORT_MAX	((u16)(~0U))
2744f564a4SZhang, Yanmin #define SHORT_MAX	((s16)(USHORT_MAX>>1))
2844f564a4SZhang, Yanmin #define SHORT_MIN	(-SHORT_MAX - 1)
291da177e4SLinus Torvalds #define INT_MAX		((int)(~0U>>1))
301da177e4SLinus Torvalds #define INT_MIN		(-INT_MAX - 1)
311da177e4SLinus Torvalds #define UINT_MAX	(~0U)
321da177e4SLinus Torvalds #define LONG_MAX	((long)(~0UL>>1))
331da177e4SLinus Torvalds #define LONG_MIN	(-LONG_MAX - 1)
341da177e4SLinus Torvalds #define ULONG_MAX	(~0UL)
35111ebb6eSOGAWA Hirofumi #define LLONG_MAX	((long long)(~0ULL>>1))
36111ebb6eSOGAWA Hirofumi #define LLONG_MIN	(-LLONG_MAX - 1)
37111ebb6eSOGAWA Hirofumi #define ULLONG_MAX	(~0ULL)
381da177e4SLinus Torvalds 
391da177e4SLinus Torvalds #define STACK_MAGIC	0xdeadbeef
401da177e4SLinus Torvalds 
412ea58144SLinus Torvalds #define ALIGN(x,a)		__ALIGN_MASK(x,(typeof(x))(a)-1)
422ea58144SLinus Torvalds #define __ALIGN_MASK(x,mask)	(((x)+(mask))&~(mask))
43a83308e6SMatthew Wilcox #define PTR_ALIGN(p, a)		((typeof(p))ALIGN((unsigned long)(p), (a)))
44f10db627SHerbert Xu #define IS_ALIGNED(x, a)		(((x) & ((typeof(x))(a) - 1)) == 0)
452ea58144SLinus Torvalds 
46c5e631cfSRusty Russell #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
47c5e631cfSRusty Russell 
484552d5dcSJan Beulich #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
49930631edSSteven Whitehouse #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
50b4cac1a0SDavid Howells #define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
519fe06081SDarrick J. Wong #define DIV_ROUND_CLOSEST(x, divisor)(			\
529fe06081SDarrick J. Wong {							\
539fe06081SDarrick J. Wong 	typeof(divisor) __divisor = divisor;		\
549fe06081SDarrick J. Wong 	(((x) + ((__divisor) / 2)) / (__divisor));	\
559fe06081SDarrick J. Wong }							\
569fe06081SDarrick J. Wong )
571da177e4SLinus Torvalds 
58ca31e146SEduard - Gabriel Munteanu #define _RET_IP_		(unsigned long)__builtin_return_address(0)
59ca31e146SEduard - Gabriel Munteanu #define _THIS_IP_  ({ __label__ __here; __here: (unsigned long)&&__here; })
60ca31e146SEduard - Gabriel Munteanu 
6190c699a9SBartlomiej Zolnierkiewicz #ifdef CONFIG_LBDAF
622da96acdSJens Axboe # include <asm/div64.h>
632da96acdSJens Axboe # define sector_div(a, b) do_div(a, b)
642da96acdSJens Axboe #else
652da96acdSJens Axboe # define sector_div(n, b)( \
662da96acdSJens Axboe { \
672da96acdSJens Axboe 	int _res; \
682da96acdSJens Axboe 	_res = (n) % (b); \
692da96acdSJens Axboe 	(n) /= (b); \
702da96acdSJens Axboe 	_res; \
712da96acdSJens Axboe } \
722da96acdSJens Axboe )
732da96acdSJens Axboe #endif
742da96acdSJens Axboe 
75218e180eSAndrew Morton /**
76218e180eSAndrew Morton  * upper_32_bits - return bits 32-63 of a number
77218e180eSAndrew Morton  * @n: the number we're accessing
78218e180eSAndrew Morton  *
79218e180eSAndrew Morton  * A basic shift-right of a 64- or 32-bit quantity.  Use this to suppress
80218e180eSAndrew Morton  * the "right shift count >= width of type" warning when that quantity is
81218e180eSAndrew Morton  * 32-bits.
82218e180eSAndrew Morton  */
83218e180eSAndrew Morton #define upper_32_bits(n) ((u32)(((n) >> 16) >> 16))
84218e180eSAndrew Morton 
85204b885eSJoerg Roedel /**
86204b885eSJoerg Roedel  * lower_32_bits - return bits 0-31 of a number
87204b885eSJoerg Roedel  * @n: the number we're accessing
88204b885eSJoerg Roedel  */
89204b885eSJoerg Roedel #define lower_32_bits(n) ((u32)(n))
90204b885eSJoerg Roedel 
911da177e4SLinus Torvalds #define	KERN_EMERG	"<0>"	/* system is unusable			*/
921da177e4SLinus Torvalds #define	KERN_ALERT	"<1>"	/* action must be taken immediately	*/
931da177e4SLinus Torvalds #define	KERN_CRIT	"<2>"	/* critical conditions			*/
941da177e4SLinus Torvalds #define	KERN_ERR	"<3>"	/* error conditions			*/
951da177e4SLinus Torvalds #define	KERN_WARNING	"<4>"	/* warning conditions			*/
961da177e4SLinus Torvalds #define	KERN_NOTICE	"<5>"	/* normal but significant condition	*/
971da177e4SLinus Torvalds #define	KERN_INFO	"<6>"	/* informational			*/
981da177e4SLinus Torvalds #define	KERN_DEBUG	"<7>"	/* debug-level messages			*/
991da177e4SLinus Torvalds 
100e28d7137SLinus Torvalds /* Use the default kernel loglevel */
101e28d7137SLinus Torvalds #define KERN_DEFAULT	"<d>"
10247492527SIngo Molnar /*
10347492527SIngo Molnar  * Annotation for a "continued" line of log printout (only done after a
10447492527SIngo Molnar  * line that had no enclosing \n). Only to be used by core/arch code
10547492527SIngo Molnar  * during early bootup (a continued line is not SMP-safe otherwise).
10647492527SIngo Molnar  */
1075fd29d6cSLinus Torvalds #define	KERN_CONT	"<c>"
10847492527SIngo Molnar 
1091da177e4SLinus Torvalds extern int console_printk[];
1101da177e4SLinus Torvalds 
1111da177e4SLinus Torvalds #define console_loglevel (console_printk[0])
1121da177e4SLinus Torvalds #define default_message_loglevel (console_printk[1])
1131da177e4SLinus Torvalds #define minimum_console_loglevel (console_printk[2])
1141da177e4SLinus Torvalds #define default_console_loglevel (console_printk[3])
1151da177e4SLinus Torvalds 
1161da177e4SLinus Torvalds struct completion;
117df2e71fbS[email protected] struct pt_regs;
118df2e71fbS[email protected] struct user;
1191da177e4SLinus Torvalds 
120070cb065SUwe Kleine-König #ifdef CONFIG_PREEMPT_VOLUNTARY
121070cb065SUwe Kleine-König extern int _cond_resched(void);
122070cb065SUwe Kleine-König # define might_resched() _cond_resched()
123070cb065SUwe Kleine-König #else
124070cb065SUwe Kleine-König # define might_resched() do { } while (0)
125070cb065SUwe Kleine-König #endif
126070cb065SUwe Kleine-König 
1277106a27bSRandy Dunlap #ifdef CONFIG_DEBUG_SPINLOCK_SLEEP
128*e4aafea2SFrederic Weisbecker   void __might_sleep(char *file, int line, int preempt_offset);
1291da177e4SLinus Torvalds /**
1301da177e4SLinus Torvalds  * might_sleep - annotation for functions that can sleep
1311da177e4SLinus Torvalds  *
1321da177e4SLinus Torvalds  * this macro will print a stack trace if it is executed in an atomic
1331da177e4SLinus Torvalds  * context (spinlock, irq-handler, ...).
1341da177e4SLinus Torvalds  *
1351da177e4SLinus Torvalds  * This is a useful debugging help to be able to catch problems early and not
136e20ec991SJim Cromie  * be bitten later when the calling function happens to sleep when it is not
1371da177e4SLinus Torvalds  * supposed to.
1381da177e4SLinus Torvalds  */
139f8cbd99bSIngo Molnar # define might_sleep() \
140*e4aafea2SFrederic Weisbecker 	do { __might_sleep(__FILE__, __LINE__, 0); might_resched(); } while (0)
141f8cbd99bSIngo Molnar #else
142*e4aafea2SFrederic Weisbecker   static inline void __might_sleep(char *file, int line, int preempt_offset) { }
143f8cbd99bSIngo Molnar # define might_sleep() do { might_resched(); } while (0)
144f8cbd99bSIngo Molnar #endif
145f8cbd99bSIngo Molnar 
146368a5fa1SHua Zhong #define might_sleep_if(cond) do { if (cond) might_sleep(); } while (0)
147f8cbd99bSIngo Molnar 
1481da177e4SLinus Torvalds #define abs(x) ({				\
1491da177e4SLinus Torvalds 		int __x = (x);			\
1501da177e4SLinus Torvalds 		(__x < 0) ? -__x : __x;		\
1511da177e4SLinus Torvalds 	})
1521da177e4SLinus Torvalds 
1533ee1afa3SNick Piggin #ifdef CONFIG_PROVE_LOCKING
1543ee1afa3SNick Piggin void might_fault(void);
1553ee1afa3SNick Piggin #else
1563ee1afa3SNick Piggin static inline void might_fault(void)
1573ee1afa3SNick Piggin {
1583ee1afa3SNick Piggin 	might_sleep();
1593ee1afa3SNick Piggin }
1603ee1afa3SNick Piggin #endif
1613ee1afa3SNick Piggin 
162e041c683SAlan Stern extern struct atomic_notifier_head panic_notifier_list;
1631da177e4SLinus Torvalds extern long (*panic_blink)(long time);
1641da177e4SLinus Torvalds NORET_TYPE void panic(const char * fmt, ...)
165a586df06SAndi Kleen 	__attribute__ ((NORET_AND format (printf, 1, 2))) __cold;
166dd287796SAndrew Morton extern void oops_enter(void);
167dd287796SAndrew Morton extern void oops_exit(void);
168dd287796SAndrew Morton extern int oops_may_print(void);
169ec701584SHarvey Harrison NORET_TYPE void do_exit(long error_code)
1701da177e4SLinus Torvalds 	ATTRIB_NORET;
1711da177e4SLinus Torvalds NORET_TYPE void complete_and_exit(struct completion *, long)
1721da177e4SLinus Torvalds 	ATTRIB_NORET;
1731da177e4SLinus Torvalds extern unsigned long simple_strtoul(const char *,char **,unsigned int);
1741da177e4SLinus Torvalds extern long simple_strtol(const char *,char **,unsigned int);
1751da177e4SLinus Torvalds extern unsigned long long simple_strtoull(const char *,char **,unsigned int);
1761da177e4SLinus Torvalds extern long long simple_strtoll(const char *,char **,unsigned int);
17706b2a76dSYi Yang extern int strict_strtoul(const char *, unsigned int, unsigned long *);
17806b2a76dSYi Yang extern int strict_strtol(const char *, unsigned int, long *);
17906b2a76dSYi Yang extern int strict_strtoull(const char *, unsigned int, unsigned long long *);
18006b2a76dSYi Yang extern int strict_strtoll(const char *, unsigned int, long long *);
1811da177e4SLinus Torvalds extern int sprintf(char * buf, const char * fmt, ...)
1821da177e4SLinus Torvalds 	__attribute__ ((format (printf, 2, 3)));
1831da177e4SLinus Torvalds extern int vsprintf(char *buf, const char *, va_list)
1841da177e4SLinus Torvalds 	__attribute__ ((format (printf, 2, 0)));
1851da177e4SLinus Torvalds extern int snprintf(char * buf, size_t size, const char * fmt, ...)
1861da177e4SLinus Torvalds 	__attribute__ ((format (printf, 3, 4)));
1871da177e4SLinus Torvalds extern int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
1881da177e4SLinus Torvalds 	__attribute__ ((format (printf, 3, 0)));
1891da177e4SLinus Torvalds extern int scnprintf(char * buf, size_t size, const char * fmt, ...)
1901da177e4SLinus Torvalds 	__attribute__ ((format (printf, 3, 4)));
1911da177e4SLinus Torvalds extern int vscnprintf(char *buf, size_t size, const char *fmt, va_list args)
1921da177e4SLinus Torvalds 	__attribute__ ((format (printf, 3, 0)));
193e905914fSJeremy Fitzhardinge extern char *kasprintf(gfp_t gfp, const char *fmt, ...)
194e905914fSJeremy Fitzhardinge 	__attribute__ ((format (printf, 2, 3)));
19511443ec7SJeremy Fitzhardinge extern char *kvasprintf(gfp_t gfp, const char *fmt, va_list args);
1961da177e4SLinus Torvalds 
1971da177e4SLinus Torvalds extern int sscanf(const char *, const char *, ...)
1981da177e4SLinus Torvalds 	__attribute__ ((format (scanf, 2, 3)));
1991da177e4SLinus Torvalds extern int vsscanf(const char *, const char *, va_list)
2001da177e4SLinus Torvalds 	__attribute__ ((format (scanf, 2, 0)));
2011da177e4SLinus Torvalds 
2021da177e4SLinus Torvalds extern int get_option(char **str, int *pint);
2031da177e4SLinus Torvalds extern char *get_options(const char *str, int nints, int *ints);
204d974ae37SJeremy Fitzhardinge extern unsigned long long memparse(const char *ptr, char **retptr);
2051da177e4SLinus Torvalds 
2065e376613STrent Piepho extern int core_kernel_text(unsigned long addr);
2071da177e4SLinus Torvalds extern int __kernel_text_address(unsigned long addr);
2081da177e4SLinus Torvalds extern int kernel_text_address(unsigned long addr);
209ab7476cfSArjan van de Ven extern int func_ptr_is_kernel_text(void *ptr);
210ab7476cfSArjan van de Ven 
21104a2e6a5SEric W. Biederman struct pid;
21204a2e6a5SEric W. Biederman extern struct pid *session_of_pgrp(struct pid *pgrp);
2131da177e4SLinus Torvalds 
214a0ad05c7SThomas Renninger /*
215a0ad05c7SThomas Renninger  * FW_BUG
216a0ad05c7SThomas Renninger  * Add this to a message where you are sure the firmware is buggy or behaves
217a0ad05c7SThomas Renninger  * really stupid or out of spec. Be aware that the responsible BIOS developer
218a0ad05c7SThomas Renninger  * should be able to fix this issue or at least get a concrete idea of the
219a0ad05c7SThomas Renninger  * problem by reading your message without the need of looking at the kernel
220a0ad05c7SThomas Renninger  * code.
221a0ad05c7SThomas Renninger  *
222a0ad05c7SThomas Renninger  * Use it for definite and high priority BIOS bugs.
223a0ad05c7SThomas Renninger  *
224a0ad05c7SThomas Renninger  * FW_WARN
225a0ad05c7SThomas Renninger  * Use it for not that clear (e.g. could the kernel messed up things already?)
226a0ad05c7SThomas Renninger  * and medium priority BIOS bugs.
227a0ad05c7SThomas Renninger  *
228a0ad05c7SThomas Renninger  * FW_INFO
229a0ad05c7SThomas Renninger  * Use this one if you want to tell the user or vendor about something
230a0ad05c7SThomas Renninger  * suspicious, but generally harmless related to the firmware.
231a0ad05c7SThomas Renninger  *
232a0ad05c7SThomas Renninger  * Use it for information or very low priority BIOS bugs.
233a0ad05c7SThomas Renninger  */
234a0ad05c7SThomas Renninger #define FW_BUG		"[Firmware Bug]: "
235a0ad05c7SThomas Renninger #define FW_WARN		"[Firmware Warn]: "
236a0ad05c7SThomas Renninger #define FW_INFO		"[Firmware Info]: "
237a0ad05c7SThomas Renninger 
238d59745ceSMatt Mackall #ifdef CONFIG_PRINTK
2391da177e4SLinus Torvalds asmlinkage int vprintk(const char *fmt, va_list args)
2401da177e4SLinus Torvalds 	__attribute__ ((format (printf, 1, 0)));
2411da177e4SLinus Torvalds asmlinkage int printk(const char * fmt, ...)
242a586df06SAndi Kleen 	__attribute__ ((format (printf, 1, 2))) __cold;
2437ef3d2fdSJoe Perches 
244717115e1SDave Young extern struct ratelimit_state printk_ratelimit_state;
2457ef3d2fdSJoe Perches extern int printk_ratelimit(void);
2467ef3d2fdSJoe Perches extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
2477ef3d2fdSJoe Perches 				   unsigned int interval_msec);
248f036be96SIngo Molnar 
249f036be96SIngo Molnar /*
250f036be96SIngo Molnar  * Print a one-time message (analogous to WARN_ONCE() et al):
251f036be96SIngo Molnar  */
252f036be96SIngo Molnar #define printk_once(x...) ({			\
253f036be96SIngo Molnar 	static int __print_once = 1;		\
254f036be96SIngo Molnar 						\
255f036be96SIngo Molnar 	if (__print_once) {			\
256f036be96SIngo Molnar 		__print_once = 0;		\
257f036be96SIngo Molnar 		printk(x);			\
258f036be96SIngo Molnar 	}					\
259f036be96SIngo Molnar })
260f036be96SIngo Molnar 
26104d491abSNeil Horman void log_buf_kexec_setup(void);
262d59745ceSMatt Mackall #else
263d59745ceSMatt Mackall static inline int vprintk(const char *s, va_list args)
264d59745ceSMatt Mackall 	__attribute__ ((format (printf, 1, 0)));
265d59745ceSMatt Mackall static inline int vprintk(const char *s, va_list args) { return 0; }
266d59745ceSMatt Mackall static inline int printk(const char *s, ...)
267d59745ceSMatt Mackall 	__attribute__ ((format (printf, 1, 2)));
268a586df06SAndi Kleen static inline int __cold printk(const char *s, ...) { return 0; }
2697ef3d2fdSJoe Perches static inline int printk_ratelimit(void) { return 0; }
2707ef3d2fdSJoe Perches static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies, \
2717ef3d2fdSJoe Perches 					  unsigned int interval_msec)	\
2727ef3d2fdSJoe Perches 		{ return false; }
273f036be96SIngo Molnar 
274f036be96SIngo Molnar /* No effect, but we still get type checking even in the !PRINTK case: */
275f036be96SIngo Molnar #define printk_once(x...) printk(x)
276f036be96SIngo Molnar 
27704d491abSNeil Horman static inline void log_buf_kexec_setup(void)
27804d491abSNeil Horman {
27904d491abSNeil Horman }
280d59745ceSMatt Mackall #endif
2811da177e4SLinus Torvalds 
282ced9cd40SIngo Molnar extern int printk_needs_cpu(int cpu);
283ced9cd40SIngo Molnar extern void printk_tick(void);
284ced9cd40SIngo Molnar 
285e17ba73bSJiri Slaby extern void asmlinkage __attribute__((format(printf, 1, 2)))
286076f9776SIngo Molnar 	early_printk(const char *fmt, ...);
287076f9776SIngo Molnar 
2881da177e4SLinus Torvalds unsigned long int_sqrt(unsigned long);
2891da177e4SLinus Torvalds 
2901da177e4SLinus Torvalds static inline void console_silent(void)
2911da177e4SLinus Torvalds {
2921da177e4SLinus Torvalds 	console_loglevel = 0;
2931da177e4SLinus Torvalds }
2941da177e4SLinus Torvalds 
2951da177e4SLinus Torvalds static inline void console_verbose(void)
2961da177e4SLinus Torvalds {
2971da177e4SLinus Torvalds 	if (console_loglevel)
2981da177e4SLinus Torvalds 		console_loglevel = 15;
2991da177e4SLinus Torvalds }
3001da177e4SLinus Torvalds 
3011da177e4SLinus Torvalds extern void bust_spinlocks(int yes);
302e3e8a75dSKirill Korotaev extern void wake_up_klogd(void);
3031da177e4SLinus Torvalds extern int oops_in_progress;		/* If set, an oops, panic(), BUG() or die() is in progress */
304aa727107SAdrian Bunk extern int panic_timeout;
3051da177e4SLinus Torvalds extern int panic_on_oops;
3068da5addaSDon Zickus extern int panic_on_unrecovered_nmi;
3075211a242SKurt Garloff extern int panic_on_io_nmi;
3081da177e4SLinus Torvalds extern const char *print_tainted(void);
30925ddbb18SAndi Kleen extern void add_taint(unsigned flag);
31025ddbb18SAndi Kleen extern int test_taint(unsigned flag);
31125ddbb18SAndi Kleen extern unsigned long get_taint(void);
312b920de1bSDavid Howells extern int root_mountflags;
3131da177e4SLinus Torvalds 
3141da177e4SLinus Torvalds /* Values used for system_state */
3151da177e4SLinus Torvalds extern enum system_states {
3161da177e4SLinus Torvalds 	SYSTEM_BOOTING,
3171da177e4SLinus Torvalds 	SYSTEM_RUNNING,
3181da177e4SLinus Torvalds 	SYSTEM_HALT,
3191da177e4SLinus Torvalds 	SYSTEM_POWER_OFF,
3201da177e4SLinus Torvalds 	SYSTEM_RESTART,
321729b4d4cSAlexey Starikovskiy 	SYSTEM_SUSPEND_DISK,
3221da177e4SLinus Torvalds } system_state;
3231da177e4SLinus Torvalds 
32425ddbb18SAndi Kleen #define TAINT_PROPRIETARY_MODULE	0
32525ddbb18SAndi Kleen #define TAINT_FORCED_MODULE		1
32625ddbb18SAndi Kleen #define TAINT_UNSAFE_SMP		2
32725ddbb18SAndi Kleen #define TAINT_FORCED_RMMOD		3
32825ddbb18SAndi Kleen #define TAINT_MACHINE_CHECK		4
32925ddbb18SAndi Kleen #define TAINT_BAD_PAGE			5
33025ddbb18SAndi Kleen #define TAINT_USER			6
33125ddbb18SAndi Kleen #define TAINT_DIE			7
33225ddbb18SAndi Kleen #define TAINT_OVERRIDDEN_ACPI_TABLE	8
33325ddbb18SAndi Kleen #define TAINT_WARN			9
33426e9a397SLinus Torvalds #define TAINT_CRAP			10
3351da177e4SLinus Torvalds 
336a586df06SAndi Kleen extern void dump_stack(void) __cold;
3371da177e4SLinus Torvalds 
33899eaf3c4SRandy Dunlap enum {
33999eaf3c4SRandy Dunlap 	DUMP_PREFIX_NONE,
34099eaf3c4SRandy Dunlap 	DUMP_PREFIX_ADDRESS,
34199eaf3c4SRandy Dunlap 	DUMP_PREFIX_OFFSET
34299eaf3c4SRandy Dunlap };
343c7909234SRandy Dunlap extern void hex_dump_to_buffer(const void *buf, size_t len,
344c7909234SRandy Dunlap 				int rowsize, int groupsize,
345c7909234SRandy Dunlap 				char *linebuf, size_t linebuflen, bool ascii);
346c7909234SRandy Dunlap extern void print_hex_dump(const char *level, const char *prefix_str,
347c7909234SRandy Dunlap 				int prefix_type, int rowsize, int groupsize,
3486a0ed91eSArtem Bityutskiy 				const void *buf, size_t len, bool ascii);
349c7909234SRandy Dunlap extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
350eb9a9a56SAlan Stern 			const void *buf, size_t len);
3513fc95772SHarvey Harrison 
3523fc95772SHarvey Harrison extern const char hex_asc[];
3533fc95772SHarvey Harrison #define hex_asc_lo(x)	hex_asc[((x) & 0x0f)]
3543fc95772SHarvey Harrison #define hex_asc_hi(x)	hex_asc[((x) & 0xf0) >> 4]
3553fc95772SHarvey Harrison 
3563fc95772SHarvey Harrison static inline char *pack_hex_byte(char *buf, u8 byte)
3573fc95772SHarvey Harrison {
3583fc95772SHarvey Harrison 	*buf++ = hex_asc_hi(byte);
3593fc95772SHarvey Harrison 	*buf++ = hex_asc_lo(byte);
3603fc95772SHarvey Harrison 	return buf;
3613fc95772SHarvey Harrison }
36299eaf3c4SRandy Dunlap 
363d091c2f5SMartin Schwidefsky #ifndef pr_fmt
364d091c2f5SMartin Schwidefsky #define pr_fmt(fmt) fmt
365d091c2f5SMartin Schwidefsky #endif
366d091c2f5SMartin Schwidefsky 
367d091c2f5SMartin Schwidefsky #define pr_emerg(fmt, ...) \
368d091c2f5SMartin Schwidefsky         printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
369d091c2f5SMartin Schwidefsky #define pr_alert(fmt, ...) \
370d091c2f5SMartin Schwidefsky         printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
371d091c2f5SMartin Schwidefsky #define pr_crit(fmt, ...) \
372d091c2f5SMartin Schwidefsky         printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
373d091c2f5SMartin Schwidefsky #define pr_err(fmt, ...) \
374d091c2f5SMartin Schwidefsky         printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
375d091c2f5SMartin Schwidefsky #define pr_warning(fmt, ...) \
376d091c2f5SMartin Schwidefsky         printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
377d091c2f5SMartin Schwidefsky #define pr_notice(fmt, ...) \
378d091c2f5SMartin Schwidefsky         printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
379d091c2f5SMartin Schwidefsky #define pr_info(fmt, ...) \
380d091c2f5SMartin Schwidefsky         printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
381311d0761SCyrill Gorcunov #define pr_cont(fmt, ...) \
382311d0761SCyrill Gorcunov 	printk(KERN_CONT fmt, ##__VA_ARGS__)
3831f7c8234SEmil Medve 
3844ccb4579SMichael Ellerman /* pr_devel() should produce zero code unless DEBUG is defined */
3854ccb4579SMichael Ellerman #ifdef DEBUG
3864ccb4579SMichael Ellerman #define pr_devel(fmt, ...) \
3874ccb4579SMichael Ellerman 	printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
3884ccb4579SMichael Ellerman #else
3894ccb4579SMichael Ellerman #define pr_devel(fmt, ...) \
3904ccb4579SMichael Ellerman 	({ if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); 0; })
3914ccb4579SMichael Ellerman #endif
3924ccb4579SMichael Ellerman 
3931cc6daf2SPavel Machek /* If you are writing a driver, please use dev_dbg instead */
394d0d85ff9SCornelia Huck #if defined(DEBUG)
395d0d85ff9SCornelia Huck #define pr_debug(fmt, ...) \
396d0d85ff9SCornelia Huck 	printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
397e9d376f0SJason Baron #elif defined(CONFIG_DYNAMIC_DEBUG)
398e6e66b02SGreg Banks /* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
399346e15beSJason Baron #define pr_debug(fmt, ...) do { \
400e6e66b02SGreg Banks 	dynamic_pr_debug(fmt, ##__VA_ARGS__); \
401346e15beSJason Baron 	} while (0)
4021da177e4SLinus Torvalds #else
403d091c2f5SMartin Schwidefsky #define pr_debug(fmt, ...) \
404d091c2f5SMartin Schwidefsky 	({ if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); 0; })
4051da177e4SLinus Torvalds #endif
4061da177e4SLinus Torvalds 
4071da177e4SLinus Torvalds /*
408526211bcSIngo Molnar  * General tracing related utility functions - trace_printk(),
4092002c258SSteven Rostedt  * tracing_on/tracing_off and tracing_start()/tracing_stop
4102002c258SSteven Rostedt  *
4112002c258SSteven Rostedt  * Use tracing_on/tracing_off when you want to quickly turn on or off
4122002c258SSteven Rostedt  * tracing. It simply enables or disables the recording of the trace events.
413156f5a78SGeunSik Lim  * This also corresponds to the user space /sys/kernel/debug/tracing/tracing_on
4142002c258SSteven Rostedt  * file, which gives a means for the kernel and userspace to interact.
4152002c258SSteven Rostedt  * Place a tracing_off() in the kernel where you want tracing to end.
4162002c258SSteven Rostedt  * From user space, examine the trace, and then echo 1 > tracing_on
4172002c258SSteven Rostedt  * to continue tracing.
4182002c258SSteven Rostedt  *
4192002c258SSteven Rostedt  * tracing_stop/tracing_start has slightly more overhead. It is used
4202002c258SSteven Rostedt  * by things like suspend to ram where disabling the recording of the
4212002c258SSteven Rostedt  * trace is not enough, but tracing must actually stop because things
4222002c258SSteven Rostedt  * like calling smp_processor_id() may crash the system.
4232002c258SSteven Rostedt  *
4242002c258SSteven Rostedt  * Most likely, you want to use tracing_on/tracing_off.
425526211bcSIngo Molnar  */
4262002c258SSteven Rostedt #ifdef CONFIG_RING_BUFFER
4272002c258SSteven Rostedt void tracing_on(void);
4282002c258SSteven Rostedt void tracing_off(void);
4292002c258SSteven Rostedt /* trace_off_permanent stops recording with no way to bring it back */
4302002c258SSteven Rostedt void tracing_off_permanent(void);
4312002c258SSteven Rostedt int tracing_is_on(void);
4322002c258SSteven Rostedt #else
4332002c258SSteven Rostedt static inline void tracing_on(void) { }
4342002c258SSteven Rostedt static inline void tracing_off(void) { }
4352002c258SSteven Rostedt static inline void tracing_off_permanent(void) { }
4362002c258SSteven Rostedt static inline int tracing_is_on(void) { return 0; }
4372002c258SSteven Rostedt #endif
438526211bcSIngo Molnar #ifdef CONFIG_TRACING
439526211bcSIngo Molnar extern void tracing_start(void);
440526211bcSIngo Molnar extern void tracing_stop(void);
441526211bcSIngo Molnar extern void ftrace_off_permanent(void);
442526211bcSIngo Molnar 
443526211bcSIngo Molnar extern void
444526211bcSIngo Molnar ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3);
445526211bcSIngo Molnar 
446769b0441SFrederic Weisbecker static inline void __attribute__ ((format (printf, 1, 2)))
447769b0441SFrederic Weisbecker ____trace_printk_check_format(const char *fmt, ...)
448769b0441SFrederic Weisbecker {
449769b0441SFrederic Weisbecker }
450769b0441SFrederic Weisbecker #define __trace_printk_check_format(fmt, args...)			\
451769b0441SFrederic Weisbecker do {									\
452769b0441SFrederic Weisbecker 	if (0)								\
453769b0441SFrederic Weisbecker 		____trace_printk_check_format(fmt, ##args);		\
454769b0441SFrederic Weisbecker } while (0)
455769b0441SFrederic Weisbecker 
456526211bcSIngo Molnar /**
457526211bcSIngo Molnar  * trace_printk - printf formatting in the ftrace buffer
458526211bcSIngo Molnar  * @fmt: the printf format for printing
459526211bcSIngo Molnar  *
460526211bcSIngo Molnar  * Note: __trace_printk is an internal function for trace_printk and
461526211bcSIngo Molnar  *       the @ip is passed in via the trace_printk macro.
462526211bcSIngo Molnar  *
463526211bcSIngo Molnar  * This function allows a kernel developer to debug fast path sections
464526211bcSIngo Molnar  * that printk is not appropriate for. By scattering in various
465526211bcSIngo Molnar  * printk like tracing in the code, a developer can quickly see
466526211bcSIngo Molnar  * where problems are occurring.
467526211bcSIngo Molnar  *
468526211bcSIngo Molnar  * This is intended as a debugging tool for the developer only.
469526211bcSIngo Molnar  * Please refrain from leaving trace_printks scattered around in
470526211bcSIngo Molnar  * your code.
471526211bcSIngo Molnar  */
472769b0441SFrederic Weisbecker 
473769b0441SFrederic Weisbecker #define trace_printk(fmt, args...)					\
474769b0441SFrederic Weisbecker do {									\
475769b0441SFrederic Weisbecker 	__trace_printk_check_format(fmt, ##args);			\
47648ead020SFrederic Weisbecker 	if (__builtin_constant_p(fmt)) {				\
47748ead020SFrederic Weisbecker 		static const char *trace_printk_fmt			\
47848ead020SFrederic Weisbecker 		  __attribute__((section("__trace_printk_fmt"))) =	\
47948ead020SFrederic Weisbecker 			__builtin_constant_p(fmt) ? fmt : NULL;		\
48048ead020SFrederic Weisbecker 									\
48148ead020SFrederic Weisbecker 		__trace_bprintk(_THIS_IP_, trace_printk_fmt, ##args);	\
48248ead020SFrederic Weisbecker 	} else								\
48348ead020SFrederic Weisbecker 		__trace_printk(_THIS_IP_, fmt, ##args);		\
484769b0441SFrederic Weisbecker } while (0)
485769b0441SFrederic Weisbecker 
486526211bcSIngo Molnar extern int
48748ead020SFrederic Weisbecker __trace_bprintk(unsigned long ip, const char *fmt, ...)
48848ead020SFrederic Weisbecker 	__attribute__ ((format (printf, 2, 3)));
48948ead020SFrederic Weisbecker 
49048ead020SFrederic Weisbecker extern int
491526211bcSIngo Molnar __trace_printk(unsigned long ip, const char *fmt, ...)
492526211bcSIngo Molnar 	__attribute__ ((format (printf, 2, 3)));
493769b0441SFrederic Weisbecker 
49448ead020SFrederic Weisbecker /*
49548ead020SFrederic Weisbecker  * The double __builtin_constant_p is because gcc will give us an error
49648ead020SFrederic Weisbecker  * if we try to allocate the static variable to fmt if it is not a
49748ead020SFrederic Weisbecker  * constant. Even with the outer if statement.
49848ead020SFrederic Weisbecker  */
499769b0441SFrederic Weisbecker #define ftrace_vprintk(fmt, vargs)					\
500769b0441SFrederic Weisbecker do {									\
50148ead020SFrederic Weisbecker 	if (__builtin_constant_p(fmt)) {				\
502769b0441SFrederic Weisbecker 		static const char *trace_printk_fmt			\
50348ead020SFrederic Weisbecker 		  __attribute__((section("__trace_printk_fmt"))) =	\
50448ead020SFrederic Weisbecker 			__builtin_constant_p(fmt) ? fmt : NULL;		\
5057bffc23eSIngo Molnar 									\
50648ead020SFrederic Weisbecker 		__ftrace_vbprintk(_THIS_IP_, trace_printk_fmt, vargs);	\
50748ead020SFrederic Weisbecker 	} else								\
50848ead020SFrederic Weisbecker 		__ftrace_vprintk(_THIS_IP_, fmt, vargs);		\
509769b0441SFrederic Weisbecker } while (0)
510769b0441SFrederic Weisbecker 
511526211bcSIngo Molnar extern int
51248ead020SFrederic Weisbecker __ftrace_vbprintk(unsigned long ip, const char *fmt, va_list ap);
51348ead020SFrederic Weisbecker 
51448ead020SFrederic Weisbecker extern int
515526211bcSIngo Molnar __ftrace_vprintk(unsigned long ip, const char *fmt, va_list ap);
516769b0441SFrederic Weisbecker 
517526211bcSIngo Molnar extern void ftrace_dump(void);
518526211bcSIngo Molnar #else
519526211bcSIngo Molnar static inline void
520526211bcSIngo Molnar ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3) { }
521526211bcSIngo Molnar static inline int
522526211bcSIngo Molnar trace_printk(const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
523526211bcSIngo Molnar 
524526211bcSIngo Molnar static inline void tracing_start(void) { }
525526211bcSIngo Molnar static inline void tracing_stop(void) { }
526526211bcSIngo Molnar static inline void ftrace_off_permanent(void) { }
527526211bcSIngo Molnar static inline int
528526211bcSIngo Molnar trace_printk(const char *fmt, ...)
529526211bcSIngo Molnar {
530526211bcSIngo Molnar 	return 0;
531526211bcSIngo Molnar }
532526211bcSIngo Molnar static inline int
533526211bcSIngo Molnar ftrace_vprintk(const char *fmt, va_list ap)
534526211bcSIngo Molnar {
535526211bcSIngo Molnar 	return 0;
536526211bcSIngo Molnar }
537526211bcSIngo Molnar static inline void ftrace_dump(void) { }
538769b0441SFrederic Weisbecker #endif /* CONFIG_TRACING */
539526211bcSIngo Molnar 
540526211bcSIngo Molnar /*
5411da177e4SLinus Torvalds  *      Display an IP address in readable format.
5421da177e4SLinus Torvalds  */
5431da177e4SLinus Torvalds 
5441da177e4SLinus Torvalds #define NIPQUAD(addr) \
5451da177e4SLinus Torvalds 	((unsigned char *)&addr)[0], \
5461da177e4SLinus Torvalds 	((unsigned char *)&addr)[1], \
5471da177e4SLinus Torvalds 	((unsigned char *)&addr)[2], \
5481da177e4SLinus Torvalds 	((unsigned char *)&addr)[3]
54946b86a2dSJoe Perches #define NIPQUAD_FMT "%u.%u.%u.%u"
5501da177e4SLinus Torvalds 
5511da177e4SLinus Torvalds /*
552bdf4bbaaSHarvey Harrison  * min()/max()/clamp() macros that also do
5531da177e4SLinus Torvalds  * strict type-checking.. See the
5541da177e4SLinus Torvalds  * "unnecessary" pointer comparison.
5551da177e4SLinus Torvalds  */
5561da177e4SLinus Torvalds #define min(x, y) ({				\
557bdf4bbaaSHarvey Harrison 	typeof(x) _min1 = (x);			\
558bdf4bbaaSHarvey Harrison 	typeof(y) _min2 = (y);			\
559bdf4bbaaSHarvey Harrison 	(void) (&_min1 == &_min2);		\
560bdf4bbaaSHarvey Harrison 	_min1 < _min2 ? _min1 : _min2; })
5611da177e4SLinus Torvalds 
5621da177e4SLinus Torvalds #define max(x, y) ({				\
563bdf4bbaaSHarvey Harrison 	typeof(x) _max1 = (x);			\
564bdf4bbaaSHarvey Harrison 	typeof(y) _max2 = (y);			\
565bdf4bbaaSHarvey Harrison 	(void) (&_max1 == &_max2);		\
566bdf4bbaaSHarvey Harrison 	_max1 > _max2 ? _max1 : _max2; })
567bdf4bbaaSHarvey Harrison 
568bdf4bbaaSHarvey Harrison /**
569bdf4bbaaSHarvey Harrison  * clamp - return a value clamped to a given range with strict typechecking
570bdf4bbaaSHarvey Harrison  * @val: current value
571bdf4bbaaSHarvey Harrison  * @min: minimum allowable value
572bdf4bbaaSHarvey Harrison  * @max: maximum allowable value
573bdf4bbaaSHarvey Harrison  *
574bdf4bbaaSHarvey Harrison  * This macro does strict typechecking of min/max to make sure they are of the
575bdf4bbaaSHarvey Harrison  * same type as val.  See the unnecessary pointer comparisons.
576bdf4bbaaSHarvey Harrison  */
577bdf4bbaaSHarvey Harrison #define clamp(val, min, max) ({			\
578bdf4bbaaSHarvey Harrison 	typeof(val) __val = (val);		\
579bdf4bbaaSHarvey Harrison 	typeof(min) __min = (min);		\
580bdf4bbaaSHarvey Harrison 	typeof(max) __max = (max);		\
581bdf4bbaaSHarvey Harrison 	(void) (&__val == &__min);		\
582bdf4bbaaSHarvey Harrison 	(void) (&__val == &__max);		\
583bdf4bbaaSHarvey Harrison 	__val = __val < __min ? __min: __val;	\
584bdf4bbaaSHarvey Harrison 	__val > __max ? __max: __val; })
5851da177e4SLinus Torvalds 
5861da177e4SLinus Torvalds /*
5871da177e4SLinus Torvalds  * ..and if you can't take the strict
5881da177e4SLinus Torvalds  * types, you can specify one yourself.
5891da177e4SLinus Torvalds  *
590bdf4bbaaSHarvey Harrison  * Or not use min/max/clamp at all, of course.
5911da177e4SLinus Torvalds  */
592bdf4bbaaSHarvey Harrison #define min_t(type, x, y) ({			\
593bdf4bbaaSHarvey Harrison 	type __min1 = (x);			\
594bdf4bbaaSHarvey Harrison 	type __min2 = (y);			\
595bdf4bbaaSHarvey Harrison 	__min1 < __min2 ? __min1: __min2; })
5961da177e4SLinus Torvalds 
597bdf4bbaaSHarvey Harrison #define max_t(type, x, y) ({			\
598bdf4bbaaSHarvey Harrison 	type __max1 = (x);			\
599bdf4bbaaSHarvey Harrison 	type __max2 = (y);			\
600bdf4bbaaSHarvey Harrison 	__max1 > __max2 ? __max1: __max2; })
601bdf4bbaaSHarvey Harrison 
602bdf4bbaaSHarvey Harrison /**
603bdf4bbaaSHarvey Harrison  * clamp_t - return a value clamped to a given range using a given type
604bdf4bbaaSHarvey Harrison  * @type: the type of variable to use
605bdf4bbaaSHarvey Harrison  * @val: current value
606bdf4bbaaSHarvey Harrison  * @min: minimum allowable value
607bdf4bbaaSHarvey Harrison  * @max: maximum allowable value
608bdf4bbaaSHarvey Harrison  *
609bdf4bbaaSHarvey Harrison  * This macro does no typechecking and uses temporary variables of type
610bdf4bbaaSHarvey Harrison  * 'type' to make all the comparisons.
611bdf4bbaaSHarvey Harrison  */
612bdf4bbaaSHarvey Harrison #define clamp_t(type, val, min, max) ({		\
613bdf4bbaaSHarvey Harrison 	type __val = (val);			\
614bdf4bbaaSHarvey Harrison 	type __min = (min);			\
615bdf4bbaaSHarvey Harrison 	type __max = (max);			\
616bdf4bbaaSHarvey Harrison 	__val = __val < __min ? __min: __val;	\
617bdf4bbaaSHarvey Harrison 	__val > __max ? __max: __val; })
618bdf4bbaaSHarvey Harrison 
619bdf4bbaaSHarvey Harrison /**
620bdf4bbaaSHarvey Harrison  * clamp_val - return a value clamped to a given range using val's type
621bdf4bbaaSHarvey Harrison  * @val: current value
622bdf4bbaaSHarvey Harrison  * @min: minimum allowable value
623bdf4bbaaSHarvey Harrison  * @max: maximum allowable value
624bdf4bbaaSHarvey Harrison  *
625bdf4bbaaSHarvey Harrison  * This macro does no typechecking and uses temporary variables of whatever
626bdf4bbaaSHarvey Harrison  * type the input argument 'val' is.  This is useful when val is an unsigned
627bdf4bbaaSHarvey Harrison  * type and min and max are literals that will otherwise be assigned a signed
628bdf4bbaaSHarvey Harrison  * integer type.
629bdf4bbaaSHarvey Harrison  */
630bdf4bbaaSHarvey Harrison #define clamp_val(val, min, max) ({		\
631bdf4bbaaSHarvey Harrison 	typeof(val) __val = (val);		\
632bdf4bbaaSHarvey Harrison 	typeof(val) __min = (min);		\
633bdf4bbaaSHarvey Harrison 	typeof(val) __max = (max);		\
634bdf4bbaaSHarvey Harrison 	__val = __val < __min ? __min: __val;	\
635bdf4bbaaSHarvey Harrison 	__val > __max ? __max: __val; })
6361da177e4SLinus Torvalds 
63791f68b73SWu Fengguang 
63891f68b73SWu Fengguang /*
63991f68b73SWu Fengguang  * swap - swap value of @a and @b
64091f68b73SWu Fengguang  */
641ac7b9004SPeter Zijlstra #define swap(a, b) \
642ac7b9004SPeter Zijlstra 	do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0)
64391f68b73SWu Fengguang 
6441da177e4SLinus Torvalds /**
6451da177e4SLinus Torvalds  * container_of - cast a member of a structure out to the containing structure
6461da177e4SLinus Torvalds  * @ptr:	the pointer to the member.
6471da177e4SLinus Torvalds  * @type:	the type of the container struct this is embedded in.
6481da177e4SLinus Torvalds  * @member:	the name of the member within the struct.
6491da177e4SLinus Torvalds  *
6501da177e4SLinus Torvalds  */
6511da177e4SLinus Torvalds #define container_of(ptr, type, member) ({			\
6521da177e4SLinus Torvalds 	const typeof( ((type *)0)->member ) *__mptr = (ptr);	\
6531da177e4SLinus Torvalds 	(type *)( (char *)__mptr - offsetof(type,member) );})
6541da177e4SLinus Torvalds 
655d4d23addSKyle McMartin struct sysinfo;
656d4d23addSKyle McMartin extern int do_sysinfo(struct sysinfo *info);
657d4d23addSKyle McMartin 
6581da177e4SLinus Torvalds #endif /* __KERNEL__ */
6591da177e4SLinus Torvalds 
6601da177e4SLinus Torvalds #define SI_LOAD_SHIFT	16
6611da177e4SLinus Torvalds struct sysinfo {
6621da177e4SLinus Torvalds 	long uptime;			/* Seconds since boot */
6631da177e4SLinus Torvalds 	unsigned long loads[3];		/* 1, 5, and 15 minute load averages */
6641da177e4SLinus Torvalds 	unsigned long totalram;		/* Total usable main memory size */
6651da177e4SLinus Torvalds 	unsigned long freeram;		/* Available memory size */
6661da177e4SLinus Torvalds 	unsigned long sharedram;	/* Amount of shared memory */
6671da177e4SLinus Torvalds 	unsigned long bufferram;	/* Memory used by buffers */
6681da177e4SLinus Torvalds 	unsigned long totalswap;	/* Total swap space size */
6691da177e4SLinus Torvalds 	unsigned long freeswap;		/* swap space still available */
6701da177e4SLinus Torvalds 	unsigned short procs;		/* Number of current processes */
6711da177e4SLinus Torvalds 	unsigned short pad;		/* explicit padding for m68k */
6721da177e4SLinus Torvalds 	unsigned long totalhigh;	/* Total high memory size */
6731da177e4SLinus Torvalds 	unsigned long freehigh;		/* Available high memory size */
6741da177e4SLinus Torvalds 	unsigned int mem_unit;		/* Memory unit size in bytes */
6751da177e4SLinus Torvalds 	char _f[20-2*sizeof(long)-sizeof(int)];	/* Padding: libc5 uses this.. */
6761da177e4SLinus Torvalds };
6771da177e4SLinus Torvalds 
678c0398ee6SNikita Danilov /* Force a compilation error if condition is true */
679921717a2SAndi Kleen #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
6801da177e4SLinus Torvalds 
6814552d5dcSJan Beulich /* Force a compilation error if condition is true, but also produce a
6824552d5dcSJan Beulich    result (of value 0 and type size_t), so the expression can be used
6834552d5dcSJan Beulich    e.g. in a structure initializer (or where-ever else comma expressions
6844552d5dcSJan Beulich    aren't permitted). */
6854552d5dcSJan Beulich #define BUILD_BUG_ON_ZERO(e) (sizeof(char[1 - 2 * !!(e)]) - 1)
6864552d5dcSJan Beulich 
6871da177e4SLinus Torvalds /* Trap pasters of __FUNCTION__ at compile-time */
6881da177e4SLinus Torvalds #define __FUNCTION__ (__func__)
6891da177e4SLinus Torvalds 
69008e0f6a9SChristoph Lameter /* This helps us to avoid #ifdef CONFIG_NUMA */
69108e0f6a9SChristoph Lameter #ifdef CONFIG_NUMA
69208e0f6a9SChristoph Lameter #define NUMA_BUILD 1
69308e0f6a9SChristoph Lameter #else
69408e0f6a9SChristoph Lameter #define NUMA_BUILD 0
69508e0f6a9SChristoph Lameter #endif
69608e0f6a9SChristoph Lameter 
69729e71abfSSteven Rostedt /* Rebuild everything on CONFIG_FTRACE_MCOUNT_RECORD */
69829e71abfSSteven Rostedt #ifdef CONFIG_FTRACE_MCOUNT_RECORD
69929e71abfSSteven Rostedt # define REBUILD_DUE_TO_FTRACE_MCOUNT_RECORD
70029e71abfSSteven Rostedt #endif
70129e71abfSSteven Rostedt 
7021da177e4SLinus Torvalds #endif
703