xref: /linux-6.15/include/linux/kernel.h (revision 7ef3d2fd)
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>
171da177e4SLinus Torvalds #include <asm/byteorder.h>
181da177e4SLinus Torvalds #include <asm/bug.h>
191da177e4SLinus Torvalds 
203eb3c740SRoman Zippel extern const char linux_banner[];
213eb3c740SRoman Zippel extern const char linux_proc_banner[];
223eb3c740SRoman Zippel 
231da177e4SLinus Torvalds #define INT_MAX		((int)(~0U>>1))
241da177e4SLinus Torvalds #define INT_MIN		(-INT_MAX - 1)
251da177e4SLinus Torvalds #define UINT_MAX	(~0U)
261da177e4SLinus Torvalds #define LONG_MAX	((long)(~0UL>>1))
271da177e4SLinus Torvalds #define LONG_MIN	(-LONG_MAX - 1)
281da177e4SLinus Torvalds #define ULONG_MAX	(~0UL)
29111ebb6eSOGAWA Hirofumi #define LLONG_MAX	((long long)(~0ULL>>1))
30111ebb6eSOGAWA Hirofumi #define LLONG_MIN	(-LLONG_MAX - 1)
31111ebb6eSOGAWA Hirofumi #define ULLONG_MAX	(~0ULL)
321da177e4SLinus Torvalds 
331da177e4SLinus Torvalds #define STACK_MAGIC	0xdeadbeef
341da177e4SLinus Torvalds 
352ea58144SLinus Torvalds #define ALIGN(x,a)		__ALIGN_MASK(x,(typeof(x))(a)-1)
362ea58144SLinus Torvalds #define __ALIGN_MASK(x,mask)	(((x)+(mask))&~(mask))
37a83308e6SMatthew Wilcox #define PTR_ALIGN(p, a)		((typeof(p))ALIGN((unsigned long)(p), (a)))
38f10db627SHerbert Xu #define IS_ALIGNED(x, a)		(((x) & ((typeof(x))(a) - 1)) == 0)
392ea58144SLinus Torvalds 
40c5e631cfSRusty Russell #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
41c5e631cfSRusty Russell 
424552d5dcSJan Beulich #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
43930631edSSteven Whitehouse #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
44b4cac1a0SDavid Howells #define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
451da177e4SLinus Torvalds 
462da96acdSJens Axboe #ifdef CONFIG_LBD
472da96acdSJens Axboe # include <asm/div64.h>
482da96acdSJens Axboe # define sector_div(a, b) do_div(a, b)
492da96acdSJens Axboe #else
502da96acdSJens Axboe # define sector_div(n, b)( \
512da96acdSJens Axboe { \
522da96acdSJens Axboe 	int _res; \
532da96acdSJens Axboe 	_res = (n) % (b); \
542da96acdSJens Axboe 	(n) /= (b); \
552da96acdSJens Axboe 	_res; \
562da96acdSJens Axboe } \
572da96acdSJens Axboe )
582da96acdSJens Axboe #endif
592da96acdSJens Axboe 
60218e180eSAndrew Morton /**
61218e180eSAndrew Morton  * upper_32_bits - return bits 32-63 of a number
62218e180eSAndrew Morton  * @n: the number we're accessing
63218e180eSAndrew Morton  *
64218e180eSAndrew Morton  * A basic shift-right of a 64- or 32-bit quantity.  Use this to suppress
65218e180eSAndrew Morton  * the "right shift count >= width of type" warning when that quantity is
66218e180eSAndrew Morton  * 32-bits.
67218e180eSAndrew Morton  */
68218e180eSAndrew Morton #define upper_32_bits(n) ((u32)(((n) >> 16) >> 16))
69218e180eSAndrew Morton 
701da177e4SLinus Torvalds #define	KERN_EMERG	"<0>"	/* system is unusable			*/
711da177e4SLinus Torvalds #define	KERN_ALERT	"<1>"	/* action must be taken immediately	*/
721da177e4SLinus Torvalds #define	KERN_CRIT	"<2>"	/* critical conditions			*/
731da177e4SLinus Torvalds #define	KERN_ERR	"<3>"	/* error conditions			*/
741da177e4SLinus Torvalds #define	KERN_WARNING	"<4>"	/* warning conditions			*/
751da177e4SLinus Torvalds #define	KERN_NOTICE	"<5>"	/* normal but significant condition	*/
761da177e4SLinus Torvalds #define	KERN_INFO	"<6>"	/* informational			*/
771da177e4SLinus Torvalds #define	KERN_DEBUG	"<7>"	/* debug-level messages			*/
781da177e4SLinus Torvalds 
7947492527SIngo Molnar /*
8047492527SIngo Molnar  * Annotation for a "continued" line of log printout (only done after a
8147492527SIngo Molnar  * line that had no enclosing \n). Only to be used by core/arch code
8247492527SIngo Molnar  * during early bootup (a continued line is not SMP-safe otherwise).
8347492527SIngo Molnar  */
8447492527SIngo Molnar #define	KERN_CONT	""
8547492527SIngo Molnar 
861da177e4SLinus Torvalds extern int console_printk[];
871da177e4SLinus Torvalds 
881da177e4SLinus Torvalds #define console_loglevel (console_printk[0])
891da177e4SLinus Torvalds #define default_message_loglevel (console_printk[1])
901da177e4SLinus Torvalds #define minimum_console_loglevel (console_printk[2])
911da177e4SLinus Torvalds #define default_console_loglevel (console_printk[3])
921da177e4SLinus Torvalds 
931da177e4SLinus Torvalds struct completion;
94df2e71fbS[email protected] struct pt_regs;
95df2e71fbS[email protected] struct user;
961da177e4SLinus Torvalds 
971da177e4SLinus Torvalds /**
981da177e4SLinus Torvalds  * might_sleep - annotation for functions that can sleep
991da177e4SLinus Torvalds  *
1001da177e4SLinus Torvalds  * this macro will print a stack trace if it is executed in an atomic
1011da177e4SLinus Torvalds  * context (spinlock, irq-handler, ...).
1021da177e4SLinus Torvalds  *
1031da177e4SLinus Torvalds  * This is a useful debugging help to be able to catch problems early and not
104e20ec991SJim Cromie  * be bitten later when the calling function happens to sleep when it is not
1051da177e4SLinus Torvalds  * supposed to.
1061da177e4SLinus Torvalds  */
107f8cbd99bSIngo Molnar #ifdef CONFIG_PREEMPT_VOLUNTARY
10802b67cc3SHerbert Xu extern int _cond_resched(void);
10902b67cc3SHerbert Xu # define might_resched() _cond_resched()
1101da177e4SLinus Torvalds #else
111f8cbd99bSIngo Molnar # define might_resched() do { } while (0)
1121da177e4SLinus Torvalds #endif
1131da177e4SLinus Torvalds 
114f8cbd99bSIngo Molnar #ifdef CONFIG_DEBUG_SPINLOCK_SLEEP
115f8cbd99bSIngo Molnar   void __might_sleep(char *file, int line);
116f8cbd99bSIngo Molnar # define might_sleep() \
117f8cbd99bSIngo Molnar 	do { __might_sleep(__FILE__, __LINE__); might_resched(); } while (0)
118f8cbd99bSIngo Molnar #else
119f8cbd99bSIngo Molnar # define might_sleep() do { might_resched(); } while (0)
120f8cbd99bSIngo Molnar #endif
121f8cbd99bSIngo Molnar 
122368a5fa1SHua Zhong #define might_sleep_if(cond) do { if (cond) might_sleep(); } while (0)
123f8cbd99bSIngo Molnar 
1241da177e4SLinus Torvalds #define abs(x) ({				\
1251da177e4SLinus Torvalds 		int __x = (x);			\
1261da177e4SLinus Torvalds 		(__x < 0) ? -__x : __x;		\
1271da177e4SLinus Torvalds 	})
1281da177e4SLinus Torvalds 
129e041c683SAlan Stern extern struct atomic_notifier_head panic_notifier_list;
1301da177e4SLinus Torvalds extern long (*panic_blink)(long time);
1311da177e4SLinus Torvalds NORET_TYPE void panic(const char * fmt, ...)
132a586df06SAndi Kleen 	__attribute__ ((NORET_AND format (printf, 1, 2))) __cold;
133dd287796SAndrew Morton extern void oops_enter(void);
134dd287796SAndrew Morton extern void oops_exit(void);
135dd287796SAndrew Morton extern int oops_may_print(void);
136ec701584SHarvey Harrison NORET_TYPE void do_exit(long error_code)
1371da177e4SLinus Torvalds 	ATTRIB_NORET;
1381da177e4SLinus Torvalds NORET_TYPE void complete_and_exit(struct completion *, long)
1391da177e4SLinus Torvalds 	ATTRIB_NORET;
1401da177e4SLinus Torvalds extern unsigned long simple_strtoul(const char *,char **,unsigned int);
1411da177e4SLinus Torvalds extern long simple_strtol(const char *,char **,unsigned int);
1421da177e4SLinus Torvalds extern unsigned long long simple_strtoull(const char *,char **,unsigned int);
1431da177e4SLinus Torvalds extern long long simple_strtoll(const char *,char **,unsigned int);
1441da177e4SLinus Torvalds extern int sprintf(char * buf, const char * fmt, ...)
1451da177e4SLinus Torvalds 	__attribute__ ((format (printf, 2, 3)));
1461da177e4SLinus Torvalds extern int vsprintf(char *buf, const char *, va_list)
1471da177e4SLinus Torvalds 	__attribute__ ((format (printf, 2, 0)));
1481da177e4SLinus Torvalds extern int snprintf(char * buf, size_t size, const char * fmt, ...)
1491da177e4SLinus Torvalds 	__attribute__ ((format (printf, 3, 4)));
1501da177e4SLinus Torvalds extern int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
1511da177e4SLinus Torvalds 	__attribute__ ((format (printf, 3, 0)));
1521da177e4SLinus Torvalds extern int scnprintf(char * buf, size_t size, const char * fmt, ...)
1531da177e4SLinus Torvalds 	__attribute__ ((format (printf, 3, 4)));
1541da177e4SLinus Torvalds extern int vscnprintf(char *buf, size_t size, const char *fmt, va_list args)
1551da177e4SLinus Torvalds 	__attribute__ ((format (printf, 3, 0)));
156e905914fSJeremy Fitzhardinge extern char *kasprintf(gfp_t gfp, const char *fmt, ...)
157e905914fSJeremy Fitzhardinge 	__attribute__ ((format (printf, 2, 3)));
15811443ec7SJeremy Fitzhardinge extern char *kvasprintf(gfp_t gfp, const char *fmt, va_list args);
1591da177e4SLinus Torvalds 
1601da177e4SLinus Torvalds extern int sscanf(const char *, const char *, ...)
1611da177e4SLinus Torvalds 	__attribute__ ((format (scanf, 2, 3)));
1621da177e4SLinus Torvalds extern int vsscanf(const char *, const char *, va_list)
1631da177e4SLinus Torvalds 	__attribute__ ((format (scanf, 2, 0)));
1641da177e4SLinus Torvalds 
1651da177e4SLinus Torvalds extern int get_option(char **str, int *pint);
1661da177e4SLinus Torvalds extern char *get_options(const char *str, int nints, int *ints);
1671da177e4SLinus Torvalds extern unsigned long long memparse(char *ptr, char **retptr);
1681da177e4SLinus Torvalds 
1695e376613STrent Piepho extern int core_kernel_text(unsigned long addr);
1701da177e4SLinus Torvalds extern int __kernel_text_address(unsigned long addr);
1711da177e4SLinus Torvalds extern int kernel_text_address(unsigned long addr);
17204a2e6a5SEric W. Biederman struct pid;
17304a2e6a5SEric W. Biederman extern struct pid *session_of_pgrp(struct pid *pgrp);
1741da177e4SLinus Torvalds 
175d59745ceSMatt Mackall #ifdef CONFIG_PRINTK
1761da177e4SLinus Torvalds asmlinkage int vprintk(const char *fmt, va_list args)
1771da177e4SLinus Torvalds 	__attribute__ ((format (printf, 1, 0)));
1781da177e4SLinus Torvalds asmlinkage int printk(const char * fmt, ...)
179a586df06SAndi Kleen 	__attribute__ ((format (printf, 1, 2))) __cold;
1800b15d04aSMike Frysinger extern int log_buf_get_len(void);
1810b15d04aSMike Frysinger extern int log_buf_read(int idx);
1820b15d04aSMike Frysinger extern int log_buf_copy(char *dest, int idx, int len);
183*7ef3d2fdSJoe Perches 
184*7ef3d2fdSJoe Perches extern int printk_ratelimit_jiffies;
185*7ef3d2fdSJoe Perches extern int printk_ratelimit_burst;
186*7ef3d2fdSJoe Perches extern int printk_ratelimit(void);
187*7ef3d2fdSJoe Perches extern int __printk_ratelimit(int ratelimit_jiffies, int ratelimit_burst);
188*7ef3d2fdSJoe Perches extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
189*7ef3d2fdSJoe Perches 				   unsigned int interval_msec);
190d59745ceSMatt Mackall #else
191d59745ceSMatt Mackall static inline int vprintk(const char *s, va_list args)
192d59745ceSMatt Mackall 	__attribute__ ((format (printf, 1, 0)));
193d59745ceSMatt Mackall static inline int vprintk(const char *s, va_list args) { return 0; }
194d59745ceSMatt Mackall static inline int printk(const char *s, ...)
195d59745ceSMatt Mackall 	__attribute__ ((format (printf, 1, 2)));
196a586df06SAndi Kleen static inline int __cold printk(const char *s, ...) { return 0; }
1970b15d04aSMike Frysinger static inline int log_buf_get_len(void) { return 0; }
1980b15d04aSMike Frysinger static inline int log_buf_read(int idx) { return 0; }
1990b15d04aSMike Frysinger static inline int log_buf_copy(char *dest, int idx, int len) { return 0; }
200*7ef3d2fdSJoe Perches static inline int printk_ratelimit(void) { return 0; }
201*7ef3d2fdSJoe Perches static inline int __printk_ratelimit(int ratelimit_jiffies, \
202*7ef3d2fdSJoe Perches 				     int ratelimit_burst) { return 0; }
203*7ef3d2fdSJoe Perches static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies, \
204*7ef3d2fdSJoe Perches 					  unsigned int interval_msec)	\
205*7ef3d2fdSJoe Perches 		{ return false; }
206d59745ceSMatt Mackall #endif
2071da177e4SLinus Torvalds 
208076f9776SIngo Molnar extern void __attribute__((format(printf, 1, 2)))
209076f9776SIngo Molnar 	early_printk(const char *fmt, ...);
210076f9776SIngo Molnar 
2111da177e4SLinus Torvalds unsigned long int_sqrt(unsigned long);
2121da177e4SLinus Torvalds 
2131da177e4SLinus Torvalds static inline void console_silent(void)
2141da177e4SLinus Torvalds {
2151da177e4SLinus Torvalds 	console_loglevel = 0;
2161da177e4SLinus Torvalds }
2171da177e4SLinus Torvalds 
2181da177e4SLinus Torvalds static inline void console_verbose(void)
2191da177e4SLinus Torvalds {
2201da177e4SLinus Torvalds 	if (console_loglevel)
2211da177e4SLinus Torvalds 		console_loglevel = 15;
2221da177e4SLinus Torvalds }
2231da177e4SLinus Torvalds 
2241da177e4SLinus Torvalds extern void bust_spinlocks(int yes);
225e3e8a75dSKirill Korotaev extern void wake_up_klogd(void);
2261da177e4SLinus Torvalds extern int oops_in_progress;		/* If set, an oops, panic(), BUG() or die() is in progress */
227aa727107SAdrian Bunk extern int panic_timeout;
2281da177e4SLinus Torvalds extern int panic_on_oops;
2298da5addaSDon Zickus extern int panic_on_unrecovered_nmi;
2301da177e4SLinus Torvalds extern int tainted;
2311da177e4SLinus Torvalds extern const char *print_tainted(void);
2321da177e4SLinus Torvalds extern void add_taint(unsigned);
233b920de1bSDavid Howells extern int root_mountflags;
2341da177e4SLinus Torvalds 
2351da177e4SLinus Torvalds /* Values used for system_state */
2361da177e4SLinus Torvalds extern enum system_states {
2371da177e4SLinus Torvalds 	SYSTEM_BOOTING,
2381da177e4SLinus Torvalds 	SYSTEM_RUNNING,
2391da177e4SLinus Torvalds 	SYSTEM_HALT,
2401da177e4SLinus Torvalds 	SYSTEM_POWER_OFF,
2411da177e4SLinus Torvalds 	SYSTEM_RESTART,
242729b4d4cSAlexey Starikovskiy 	SYSTEM_SUSPEND_DISK,
2431da177e4SLinus Torvalds } system_state;
2441da177e4SLinus Torvalds 
2451da177e4SLinus Torvalds #define TAINT_PROPRIETARY_MODULE	(1<<0)
2461da177e4SLinus Torvalds #define TAINT_FORCED_MODULE		(1<<1)
2471da177e4SLinus Torvalds #define TAINT_UNSAFE_SMP		(1<<2)
2481da177e4SLinus Torvalds #define TAINT_FORCED_RMMOD		(1<<3)
2491da177e4SLinus Torvalds #define TAINT_MACHINE_CHECK		(1<<4)
2501da177e4SLinus Torvalds #define TAINT_BAD_PAGE			(1<<5)
25134f5a398STheodore Ts'o #define TAINT_USER			(1<<6)
252bcdcd8e7SPavel Emelianov #define TAINT_DIE			(1<<7)
2536ed31e92SÉric Piel #define TAINT_OVERRIDDEN_ACPI_TABLE	(1<<8)
2541da177e4SLinus Torvalds 
255a586df06SAndi Kleen extern void dump_stack(void) __cold;
2561da177e4SLinus Torvalds 
25799eaf3c4SRandy Dunlap enum {
25899eaf3c4SRandy Dunlap 	DUMP_PREFIX_NONE,
25999eaf3c4SRandy Dunlap 	DUMP_PREFIX_ADDRESS,
26099eaf3c4SRandy Dunlap 	DUMP_PREFIX_OFFSET
26199eaf3c4SRandy Dunlap };
262c7909234SRandy Dunlap extern void hex_dump_to_buffer(const void *buf, size_t len,
263c7909234SRandy Dunlap 				int rowsize, int groupsize,
264c7909234SRandy Dunlap 				char *linebuf, size_t linebuflen, bool ascii);
265c7909234SRandy Dunlap extern void print_hex_dump(const char *level, const char *prefix_str,
266c7909234SRandy Dunlap 				int prefix_type, int rowsize, int groupsize,
2676a0ed91eSArtem Bityutskiy 				const void *buf, size_t len, bool ascii);
268c7909234SRandy Dunlap extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
269eb9a9a56SAlan Stern 			const void *buf, size_t len);
27099eaf3c4SRandy Dunlap #define hex_asc(x)	"0123456789abcdef"[x]
27199eaf3c4SRandy Dunlap 
2721f7c8234SEmil Medve #define pr_emerg(fmt, arg...) \
2731f7c8234SEmil Medve 	printk(KERN_EMERG fmt, ##arg)
2741f7c8234SEmil Medve #define pr_alert(fmt, arg...) \
2751f7c8234SEmil Medve 	printk(KERN_ALERT fmt, ##arg)
2761f7c8234SEmil Medve #define pr_crit(fmt, arg...) \
2771f7c8234SEmil Medve 	printk(KERN_CRIT fmt, ##arg)
2781f7c8234SEmil Medve #define pr_err(fmt, arg...) \
2791f7c8234SEmil Medve 	printk(KERN_ERR fmt, ##arg)
2801f7c8234SEmil Medve #define pr_warning(fmt, arg...) \
2811f7c8234SEmil Medve 	printk(KERN_WARNING fmt, ##arg)
2821f7c8234SEmil Medve #define pr_notice(fmt, arg...) \
2831f7c8234SEmil Medve 	printk(KERN_NOTICE fmt, ##arg)
2841f7c8234SEmil Medve #define pr_info(fmt, arg...) \
2851f7c8234SEmil Medve 	printk(KERN_INFO fmt, ##arg)
2861f7c8234SEmil Medve 
2871da177e4SLinus Torvalds #ifdef DEBUG
2881cc6daf2SPavel Machek /* If you are writing a driver, please use dev_dbg instead */
2891da177e4SLinus Torvalds #define pr_debug(fmt, arg...) \
2901da177e4SLinus Torvalds 	printk(KERN_DEBUG fmt, ##arg)
2911da177e4SLinus Torvalds #else
2928b2a1fd1SZach Brown static inline int __attribute__ ((format (printf, 1, 2))) pr_debug(const char * fmt, ...)
2938b2a1fd1SZach Brown {
2948b2a1fd1SZach Brown 	return 0;
2958b2a1fd1SZach Brown }
2961da177e4SLinus Torvalds #endif
2971da177e4SLinus Torvalds 
2981da177e4SLinus Torvalds /*
2991da177e4SLinus Torvalds  *      Display an IP address in readable format.
3001da177e4SLinus Torvalds  */
3011da177e4SLinus Torvalds 
3021da177e4SLinus Torvalds #define NIPQUAD(addr) \
3031da177e4SLinus Torvalds 	((unsigned char *)&addr)[0], \
3041da177e4SLinus Torvalds 	((unsigned char *)&addr)[1], \
3051da177e4SLinus Torvalds 	((unsigned char *)&addr)[2], \
3061da177e4SLinus Torvalds 	((unsigned char *)&addr)[3]
30746b86a2dSJoe Perches #define NIPQUAD_FMT "%u.%u.%u.%u"
3081da177e4SLinus Torvalds 
3091da177e4SLinus Torvalds #define NIP6(addr) \
3101da177e4SLinus Torvalds 	ntohs((addr).s6_addr16[0]), \
3111da177e4SLinus Torvalds 	ntohs((addr).s6_addr16[1]), \
3121da177e4SLinus Torvalds 	ntohs((addr).s6_addr16[2]), \
3131da177e4SLinus Torvalds 	ntohs((addr).s6_addr16[3]), \
3141da177e4SLinus Torvalds 	ntohs((addr).s6_addr16[4]), \
3151da177e4SLinus Torvalds 	ntohs((addr).s6_addr16[5]), \
3161da177e4SLinus Torvalds 	ntohs((addr).s6_addr16[6]), \
3171da177e4SLinus Torvalds 	ntohs((addr).s6_addr16[7])
31846b86a2dSJoe Perches #define NIP6_FMT "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x"
3199343e79aSYOSHIFUJI Hideaki #define NIP6_SEQFMT "%04x%04x%04x%04x%04x%04x%04x%04x"
3201da177e4SLinus Torvalds 
3211da177e4SLinus Torvalds #if defined(__LITTLE_ENDIAN)
3221da177e4SLinus Torvalds #define HIPQUAD(addr) \
3231da177e4SLinus Torvalds 	((unsigned char *)&addr)[3], \
3241da177e4SLinus Torvalds 	((unsigned char *)&addr)[2], \
3251da177e4SLinus Torvalds 	((unsigned char *)&addr)[1], \
3261da177e4SLinus Torvalds 	((unsigned char *)&addr)[0]
3271da177e4SLinus Torvalds #elif defined(__BIG_ENDIAN)
3281da177e4SLinus Torvalds #define HIPQUAD	NIPQUAD
3291da177e4SLinus Torvalds #else
3301da177e4SLinus Torvalds #error "Please fix asm/byteorder.h"
3311da177e4SLinus Torvalds #endif /* __LITTLE_ENDIAN */
3321da177e4SLinus Torvalds 
3331da177e4SLinus Torvalds /*
3341da177e4SLinus Torvalds  * min()/max() macros that also do
3351da177e4SLinus Torvalds  * strict type-checking.. See the
3361da177e4SLinus Torvalds  * "unnecessary" pointer comparison.
3371da177e4SLinus Torvalds  */
3381da177e4SLinus Torvalds #define min(x,y) ({ \
3391da177e4SLinus Torvalds 	typeof(x) _x = (x);	\
3401da177e4SLinus Torvalds 	typeof(y) _y = (y);	\
3411da177e4SLinus Torvalds 	(void) (&_x == &_y);		\
3421da177e4SLinus Torvalds 	_x < _y ? _x : _y; })
3431da177e4SLinus Torvalds 
3441da177e4SLinus Torvalds #define max(x,y) ({ \
3451da177e4SLinus Torvalds 	typeof(x) _x = (x);	\
3461da177e4SLinus Torvalds 	typeof(y) _y = (y);	\
3471da177e4SLinus Torvalds 	(void) (&_x == &_y);		\
3481da177e4SLinus Torvalds 	_x > _y ? _x : _y; })
3491da177e4SLinus Torvalds 
3501da177e4SLinus Torvalds /*
3511da177e4SLinus Torvalds  * ..and if you can't take the strict
3521da177e4SLinus Torvalds  * types, you can specify one yourself.
3531da177e4SLinus Torvalds  *
3541da177e4SLinus Torvalds  * Or not use min/max at all, of course.
3551da177e4SLinus Torvalds  */
3561da177e4SLinus Torvalds #define min_t(type,x,y) \
3571da177e4SLinus Torvalds 	({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
3581da177e4SLinus Torvalds #define max_t(type,x,y) \
3591da177e4SLinus Torvalds 	({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
3601da177e4SLinus Torvalds 
3611da177e4SLinus Torvalds 
3621da177e4SLinus Torvalds /**
3631da177e4SLinus Torvalds  * container_of - cast a member of a structure out to the containing structure
3641da177e4SLinus Torvalds  * @ptr:	the pointer to the member.
3651da177e4SLinus Torvalds  * @type:	the type of the container struct this is embedded in.
3661da177e4SLinus Torvalds  * @member:	the name of the member within the struct.
3671da177e4SLinus Torvalds  *
3681da177e4SLinus Torvalds  */
3691da177e4SLinus Torvalds #define container_of(ptr, type, member) ({			\
3701da177e4SLinus Torvalds 	const typeof( ((type *)0)->member ) *__mptr = (ptr);	\
3711da177e4SLinus Torvalds 	(type *)( (char *)__mptr - offsetof(type,member) );})
3721da177e4SLinus Torvalds 
3731da177e4SLinus Torvalds /*
3741da177e4SLinus Torvalds  * Check at compile time that something is of a particular type.
3751da177e4SLinus Torvalds  * Always evaluates to 1 so you may use it easily in comparisons.
3761da177e4SLinus Torvalds  */
3771da177e4SLinus Torvalds #define typecheck(type,x) \
3781da177e4SLinus Torvalds ({	type __dummy; \
3791da177e4SLinus Torvalds 	typeof(x) __dummy2; \
3801da177e4SLinus Torvalds 	(void)(&__dummy == &__dummy2); \
3811da177e4SLinus Torvalds 	1; \
3821da177e4SLinus Torvalds })
3831da177e4SLinus Torvalds 
384711a660dSChuck Ebbert /*
385711a660dSChuck Ebbert  * Check at compile time that 'function' is a certain type, or is a pointer
386711a660dSChuck Ebbert  * to that type (needs to use typedef for the function type.)
387711a660dSChuck Ebbert  */
388711a660dSChuck Ebbert #define typecheck_fn(type,function) \
389711a660dSChuck Ebbert ({	typeof(type) __tmp = function; \
390711a660dSChuck Ebbert 	(void)__tmp; \
391711a660dSChuck Ebbert })
392711a660dSChuck Ebbert 
393d4d23addSKyle McMartin struct sysinfo;
394d4d23addSKyle McMartin extern int do_sysinfo(struct sysinfo *info);
395d4d23addSKyle McMartin 
3961da177e4SLinus Torvalds #endif /* __KERNEL__ */
3971da177e4SLinus Torvalds 
3981da177e4SLinus Torvalds #define SI_LOAD_SHIFT	16
3991da177e4SLinus Torvalds struct sysinfo {
4001da177e4SLinus Torvalds 	long uptime;			/* Seconds since boot */
4011da177e4SLinus Torvalds 	unsigned long loads[3];		/* 1, 5, and 15 minute load averages */
4021da177e4SLinus Torvalds 	unsigned long totalram;		/* Total usable main memory size */
4031da177e4SLinus Torvalds 	unsigned long freeram;		/* Available memory size */
4041da177e4SLinus Torvalds 	unsigned long sharedram;	/* Amount of shared memory */
4051da177e4SLinus Torvalds 	unsigned long bufferram;	/* Memory used by buffers */
4061da177e4SLinus Torvalds 	unsigned long totalswap;	/* Total swap space size */
4071da177e4SLinus Torvalds 	unsigned long freeswap;		/* swap space still available */
4081da177e4SLinus Torvalds 	unsigned short procs;		/* Number of current processes */
4091da177e4SLinus Torvalds 	unsigned short pad;		/* explicit padding for m68k */
4101da177e4SLinus Torvalds 	unsigned long totalhigh;	/* Total high memory size */
4111da177e4SLinus Torvalds 	unsigned long freehigh;		/* Available high memory size */
4121da177e4SLinus Torvalds 	unsigned int mem_unit;		/* Memory unit size in bytes */
4131da177e4SLinus Torvalds 	char _f[20-2*sizeof(long)-sizeof(int)];	/* Padding: libc5 uses this.. */
4141da177e4SLinus Torvalds };
4151da177e4SLinus Torvalds 
416c0398ee6SNikita Danilov /* Force a compilation error if condition is true */
417921717a2SAndi Kleen #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
4181da177e4SLinus Torvalds 
4194552d5dcSJan Beulich /* Force a compilation error if condition is true, but also produce a
4204552d5dcSJan Beulich    result (of value 0 and type size_t), so the expression can be used
4214552d5dcSJan Beulich    e.g. in a structure initializer (or where-ever else comma expressions
4224552d5dcSJan Beulich    aren't permitted). */
4234552d5dcSJan Beulich #define BUILD_BUG_ON_ZERO(e) (sizeof(char[1 - 2 * !!(e)]) - 1)
4244552d5dcSJan Beulich 
4251da177e4SLinus Torvalds /* Trap pasters of __FUNCTION__ at compile-time */
4261da177e4SLinus Torvalds #define __FUNCTION__ (__func__)
4271da177e4SLinus Torvalds 
42808e0f6a9SChristoph Lameter /* This helps us to avoid #ifdef CONFIG_NUMA */
42908e0f6a9SChristoph Lameter #ifdef CONFIG_NUMA
43008e0f6a9SChristoph Lameter #define NUMA_BUILD 1
43108e0f6a9SChristoph Lameter #else
43208e0f6a9SChristoph Lameter #define NUMA_BUILD 0
43308e0f6a9SChristoph Lameter #endif
43408e0f6a9SChristoph Lameter 
4351da177e4SLinus Torvalds #endif
436