Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
37fbe0a4 WN |
2 | #ifndef __TOOLS_LINUX_KERNEL_H |
3 | #define __TOOLS_LINUX_KERNEL_H | |
43cbcd8a | 4 | |
5a116dd2 | 5 | #include <stdarg.h> |
d0761e37 | 6 | #include <stddef.h> |
5a116dd2 | 7 | #include <assert.h> |
e3698b23 | 8 | #include <linux/build_bug.h> |
8607c1ee | 9 | #include <linux/compiler.h> |
d6e6a27d | 10 | #include <linux/math.h> |
07fda552 AH |
11 | #include <endian.h> |
12 | #include <byteswap.h> | |
5a116dd2 | 13 | |
eaa75b51 ACM |
14 | #ifndef UINT_MAX |
15 | #define UINT_MAX (~0U) | |
16 | #endif | |
17 | ||
9ac3e487 IT |
18 | #define PERF_ALIGN(x, a) __PERF_ALIGN_MASK(x, (typeof(x))(a)-1) |
19 | #define __PERF_ALIGN_MASK(x, mask) (((x)+(mask))&~(mask)) | |
5a116dd2 | 20 | |
43cbcd8a ACM |
21 | #ifndef offsetof |
22 | #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) | |
23 | #endif | |
24 | ||
25 | #ifndef container_of | |
26 | /** | |
27 | * container_of - cast a member of a structure out to the containing structure | |
28 | * @ptr: the pointer to the member. | |
29 | * @type: the type of the container struct this is embedded in. | |
30 | * @member: the name of the member within the struct. | |
31 | * | |
32 | */ | |
33 | #define container_of(ptr, type, member) ({ \ | |
34 | const typeof(((type *)0)->member) * __mptr = (ptr); \ | |
35 | (type *)((char *)__mptr - offsetof(type, member)); }) | |
36 | #endif | |
37 | ||
52d422de ACM |
38 | #ifndef max |
39 | #define max(x, y) ({ \ | |
40 | typeof(x) _max1 = (x); \ | |
41 | typeof(y) _max2 = (y); \ | |
42 | (void) (&_max1 == &_max2); \ | |
43 | _max1 > _max2 ? _max1 : _max2; }) | |
44 | #endif | |
45 | ||
5a116dd2 FW |
46 | #ifndef min |
47 | #define min(x, y) ({ \ | |
48 | typeof(x) _min1 = (x); \ | |
49 | typeof(y) _min2 = (y); \ | |
50 | (void) (&_min1 == &_min2); \ | |
51 | _min1 < _min2 ? _min1 : _min2; }) | |
52 | #endif | |
53 | ||
54 | #ifndef BUG_ON | |
8bf98b89 IT |
55 | #ifdef NDEBUG |
56 | #define BUG_ON(cond) do { if (cond) {} } while (0) | |
57 | #else | |
5a116dd2 FW |
58 | #define BUG_ON(cond) assert(!(cond)) |
59 | #endif | |
8bf98b89 | 60 | #endif |
ad3d6c72 | 61 | #define BUG() BUG_ON(1) |
5a116dd2 | 62 | |
07fda552 AH |
63 | #if __BYTE_ORDER == __BIG_ENDIAN |
64 | #define cpu_to_le16 bswap_16 | |
65 | #define cpu_to_le32 bswap_32 | |
66 | #define cpu_to_le64 bswap_64 | |
67 | #define le16_to_cpu bswap_16 | |
68 | #define le32_to_cpu bswap_32 | |
69 | #define le64_to_cpu bswap_64 | |
70 | #define cpu_to_be16 | |
71 | #define cpu_to_be32 | |
72 | #define cpu_to_be64 | |
73 | #define be16_to_cpu | |
74 | #define be32_to_cpu | |
75 | #define be64_to_cpu | |
76 | #else | |
77 | #define cpu_to_le16 | |
78 | #define cpu_to_le32 | |
79 | #define cpu_to_le64 | |
80 | #define le16_to_cpu | |
81 | #define le32_to_cpu | |
82 | #define le64_to_cpu | |
83 | #define cpu_to_be16 bswap_16 | |
84 | #define cpu_to_be32 bswap_32 | |
85 | #define cpu_to_be64 bswap_64 | |
86 | #define be16_to_cpu bswap_16 | |
87 | #define be32_to_cpu bswap_32 | |
88 | #define be64_to_cpu bswap_64 | |
89 | #endif | |
5a116dd2 | 90 | |
d0761e37 ACM |
91 | int vscnprintf(char *buf, size_t size, const char *fmt, va_list args); |
92 | int scnprintf(char * buf, size_t size, const char * fmt, ...); | |
1c492422 | 93 | int scnprintf_pad(char * buf, size_t size, const char * fmt, ...); |
5a116dd2 | 94 | |
066b34aa | 95 | #ifndef ARRAY_SIZE |
8607c1ee | 96 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr)) |
066b34aa | 97 | #endif |
8607c1ee | 98 | |
e58e871b | 99 | #define current_gfp_context(k) 0 |
4a67e3a7 | 100 | #define synchronize_rcu() |
e58e871b | 101 | |
43cbcd8a | 102 | #endif |