]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - tools/include/linux/kernel.h
Merge remote-tracking branches 'spi/topic/imx', 'spi/topic/mxs', 'spi/topic/orion...
[mirror_ubuntu-bionic-kernel.git] / tools / include / linux / kernel.h
CommitLineData
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>
8607c1ee 8#include <linux/compiler.h>
07fda552
AH
9#include <endian.h>
10#include <byteswap.h>
5a116dd2 11
eaa75b51
ACM
12#ifndef UINT_MAX
13#define UINT_MAX (~0U)
14#endif
15
5a116dd2
FW
16#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
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
e58e871b 38#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
1967936d
ACM
39#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
40
52d422de
ACM
41#ifndef max
42#define max(x, y) ({ \
43 typeof(x) _max1 = (x); \
44 typeof(y) _max2 = (y); \
45 (void) (&_max1 == &_max2); \
46 _max1 > _max2 ? _max1 : _max2; })
47#endif
48
5a116dd2
FW
49#ifndef min
50#define min(x, y) ({ \
51 typeof(x) _min1 = (x); \
52 typeof(y) _min2 = (y); \
53 (void) (&_min1 == &_min2); \
54 _min1 < _min2 ? _min1 : _min2; })
55#endif
56
86d5a70c
IT
57#ifndef roundup
58#define roundup(x, y) ( \
59{ \
60 const typeof(y) __y = y; \
61 (((x) + (__y - 1)) / __y) * __y; \
62} \
63)
64#endif
65
5a116dd2 66#ifndef BUG_ON
8bf98b89
IT
67#ifdef NDEBUG
68#define BUG_ON(cond) do { if (cond) {} } while (0)
69#else
5a116dd2
FW
70#define BUG_ON(cond) assert(!(cond))
71#endif
8bf98b89 72#endif
5a116dd2 73
07fda552
AH
74#if __BYTE_ORDER == __BIG_ENDIAN
75#define cpu_to_le16 bswap_16
76#define cpu_to_le32 bswap_32
77#define cpu_to_le64 bswap_64
78#define le16_to_cpu bswap_16
79#define le32_to_cpu bswap_32
80#define le64_to_cpu bswap_64
81#define cpu_to_be16
82#define cpu_to_be32
83#define cpu_to_be64
84#define be16_to_cpu
85#define be32_to_cpu
86#define be64_to_cpu
87#else
88#define cpu_to_le16
89#define cpu_to_le32
90#define cpu_to_le64
91#define le16_to_cpu
92#define le32_to_cpu
93#define le64_to_cpu
94#define cpu_to_be16 bswap_16
95#define cpu_to_be32 bswap_32
96#define cpu_to_be64 bswap_64
97#define be16_to_cpu bswap_16
98#define be32_to_cpu bswap_32
99#define be64_to_cpu bswap_64
100#endif
5a116dd2 101
d0761e37
ACM
102int vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
103int scnprintf(char * buf, size_t size, const char * fmt, ...);
5a116dd2 104
8607c1ee
ACM
105#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
106
339ce005
JO
107/*
108 * This looks more complex than it should be. But we need to
109 * get the type for the ~ right in round_down (it needs to be
110 * as wide as the result!), and we want to evaluate the macro
111 * arguments just once each.
112 */
113#define __round_mask(x, y) ((__typeof__(x))((y)-1))
114#define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
115#define round_down(x, y) ((x) & ~__round_mask(x, y))
116
e58e871b
LASL
117#define current_gfp_context(k) 0
118#define synchronize_sched()
119
43cbcd8a 120#endif