fix: double defined LTTNG_KERNEL_VERSION
[lttng-modules.git] / include / lttng / kernel-version.h
CommitLineData
b7cdc182 1/* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
9f36eaed 2 *
2df37e95 3 * lttng/kernel-version.h
5fa38800 4 *
7b25fa17 5 * Contains helpers to check kernel version conditions.
5fa38800
MD
6 *
7 * Copyright (C) 2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5fa38800
MD
8 */
9
9f36eaed
MJ
10#ifndef _LTTNG_KERNEL_VERSION_H
11#define _LTTNG_KERNEL_VERSION_H
12
5fa38800 13#include <linux/version.h>
9f61c55f 14#include <generated/utsrelease.h>
5fa38800 15
7b25fa17
MJ
16/*
17 * The following defines are extracted from the toplevel Linux Makefile and
18 * passed on the command line -with '-D'.
19 */
20
21#ifndef LTTNG_LINUX_MAJOR
22#define LTTNG_LINUX_MAJOR 0
23#endif
24
25#ifndef LTTNG_LINUX_MINOR
26#define LTTNG_LINUX_MINOR 0
27#endif
28
29#ifndef LTTNG_LINUX_PATCH
30#define LTTNG_LINUX_PATCH 0
31#endif
32
33/*
34 * Some stable releases have overflowed the 8bits allocated to the sublevel in
35 * the version code. To determine if the current kernel is affected, use the
36 * sublevel version from the Makefile. This is currently true for the 4.4.256
37 * and 4.9.256 stable releases.
38 *
39 * When the sublevel has overflowed, use the values from the Makefile instead
40 * of LINUX_VERSION_CODE from the kernel headers and allocate 16bits.
41 * Otherwise, keep using the version code from the headers to minimise the
42 * behavior change and avoid regressions.
43 */
44#if (LTTNG_LINUX_PATCH >= 256)
45
46#define LTTNG_KERNEL_VERSION(a, b, c) \
47 (((a) << 24) + ((b) << 16) + (c))
48
49#define LTTNG_LINUX_VERSION_CODE \
50 LTTNG_KERNEL_VERSION(LTTNG_LINUX_MAJOR, LTTNG_LINUX_MINOR, LTTNG_LINUX_PATCH)
51
52#else
53
54#define LTTNG_KERNEL_VERSION(a, b, c) KERNEL_VERSION(a, b, c)
55#define LTTNG_LINUX_VERSION_CODE LINUX_VERSION_CODE
56
57#endif
58
5fa38800
MD
59/*
60 * This macro checks if the kernel version is between the two specified
144bbfd5 61 * versions (lower limit inclusive, upper limit exclusive).
5fa38800
MD
62 */
63#define LTTNG_KERNEL_RANGE(a_low, b_low, c_low, a_high, b_high, c_high) \
5f4c791e
MJ
64 (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(a_low, b_low, c_low) && \
65 LTTNG_LINUX_VERSION_CODE < LTTNG_KERNEL_VERSION(a_high, b_high, c_high))
5fa38800 66
c94ac1ac
MJ
67/* Ubuntu */
68
3e5941df 69#define LTTNG_UBUNTU_KERNEL_VERSION(a, b, c, d) \
af590311 70 (((LTTNG_KERNEL_VERSION(a, b, c)) << 16) + (d))
3e5941df 71
05732a66 72#ifdef UTS_UBUNTU_RELEASE_ABI
3e5941df 73#define LTTNG_UBUNTU_VERSION_CODE \
af590311 74 ((LTTNG_LINUX_VERSION_CODE << 16) + UTS_UBUNTU_RELEASE_ABI)
05732a66
MD
75#else
76#define LTTNG_UBUNTU_VERSION_CODE 0
77#endif
3e5941df
JD
78
79#define LTTNG_UBUNTU_KERNEL_RANGE(a_low, b_low, c_low, d_low, \
80 a_high, b_high, c_high, d_high) \
05732a66 81 (LTTNG_UBUNTU_VERSION_CODE >= \
3e5941df
JD
82 LTTNG_UBUNTU_KERNEL_VERSION(a_low, b_low, c_low, d_low) && \
83 LTTNG_UBUNTU_VERSION_CODE < \
84 LTTNG_UBUNTU_KERNEL_VERSION(a_high, b_high, c_high, d_high))
85
c94ac1ac
MJ
86/* Debian */
87
72e6c528 88#define LTTNG_DEBIAN_KERNEL_VERSION(a, b, c, d, e, f) \
5f4c791e 89 (((LTTNG_KERNEL_VERSION(a, b, c)) * 1000000ULL) + ((d) * 10000) + ((e) * 100) + (f))
72e6c528 90
05732a66 91#ifdef DEBIAN_API_VERSION
72e6c528 92#define LTTNG_DEBIAN_VERSION_CODE \
5f4c791e 93 ((LTTNG_LINUX_VERSION_CODE * 1000000ULL) + DEBIAN_API_VERSION)
05732a66
MD
94#else
95#define LTTNG_DEBIAN_VERSION_CODE 0
96#endif
72e6c528
MD
97
98#define LTTNG_DEBIAN_KERNEL_RANGE(a_low, b_low, c_low, d_low, e_low, f_low, \
99 a_high, b_high, c_high, d_high, e_high, f_high) \
05732a66 100 (LTTNG_DEBIAN_VERSION_CODE >= \
72e6c528
MD
101 LTTNG_DEBIAN_KERNEL_VERSION(a_low, b_low, c_low, d_low, e_low, f_low) && \
102 LTTNG_DEBIAN_VERSION_CODE < \
103 LTTNG_DEBIAN_KERNEL_VERSION(a_high, b_high, c_high, d_high, e_high, f_high))
104
c94ac1ac 105/* RHEL */
f30ae671 106
5f4c791e
MJ
107#define LTTNG_RHEL_KERNEL_VERSION(a, b, c, d, e, f) \
108 (((LTTNG_KERNEL_VERSION(a, b, c)) * 10000000ULL) + ((d) * 10000) + ((e) * 100) + (f))
109
c94ac1ac 110#ifdef RHEL_API_VERSION
f30ae671 111#define LTTNG_RHEL_VERSION_CODE \
5f4c791e 112 ((LTTNG_LINUX_VERSION_CODE * 10000000ULL) + RHEL_API_VERSION)
f30ae671
MD
113#else
114#define LTTNG_RHEL_VERSION_CODE 0
115#endif
116
c94ac1ac
MJ
117#define LTTNG_RHEL_KERNEL_RANGE(a_low, b_low, c_low, d_low, e_low, f_low, \
118 a_high, b_high, c_high, d_high, e_high, f_high) \
f30ae671 119 (LTTNG_RHEL_VERSION_CODE >= \
c94ac1ac 120 LTTNG_RHEL_KERNEL_VERSION(a_low, b_low, c_low, d_low, e_low, f_low) && \
f30ae671 121 LTTNG_RHEL_VERSION_CODE < \
c94ac1ac
MJ
122 LTTNG_RHEL_KERNEL_VERSION(a_high, b_high, c_high, d_high, e_high, f_high))
123
ce66b486
MJ
124/* SUSE Linux enterprise */
125
126#define LTTNG_SLE_KERNEL_VERSION(a, b, c, d, e, f) \
5f4c791e 127 (((LTTNG_KERNEL_VERSION(a, b, c)) * 10000000ULL) + ((d) * 10000) + ((e) * 100) + (f))
ce66b486
MJ
128
129#ifdef SLE_API_VERSION
130#define LTTNG_SLE_VERSION_CODE \
5f4c791e 131 ((LTTNG_LINUX_VERSION_CODE * 10000000ULL) + SLE_API_VERSION)
ce66b486
MJ
132#else
133#define LTTNG_SLE_VERSION_CODE 0
134#endif
135
136#define LTTNG_SLE_KERNEL_RANGE(a_low, b_low, c_low, d_low, e_low, f_low, \
137 a_high, b_high, c_high, d_high, e_high, f_high) \
138 (LTTNG_SLE_VERSION_CODE >= \
139 LTTNG_SLE_KERNEL_VERSION(a_low, b_low, c_low, d_low, e_low, f_low) && \
140 LTTNG_SLE_VERSION_CODE < \
141 LTTNG_SLE_KERNEL_VERSION(a_high, b_high, c_high, d_high, e_high, f_high))
142
e4838da1
LG
143/* Fedora */
144
145#define LTTNG_FEDORA_KERNEL_VERSION(a, b, c, d) \
5f4c791e 146 (((LTTNG_KERNEL_VERSION(a, b, c)) * 10000ULL) + (d))
e4838da1
LG
147
148#ifdef FEDORA_REVISION_VERSION
149#define LTTNG_FEDORA_VERSION_CODE \
5f4c791e 150 ((LTTNG_LINUX_VERSION_CODE * 10000ULL) + FEDORA_REVISION_VERSION)
e4838da1
LG
151#else
152#define LTTNG_FEDORA_VERSION_CODE 0
153#endif
154
155#define LTTNG_FEDORA_KERNEL_RANGE(a_low, b_low, c_low, d_low, \
156 a_high, b_high, c_high, d_high) \
157 (LTTNG_FEDORA_VERSION_CODE >= \
158 LTTNG_FEDORA_KERNEL_VERSION(a_low, b_low, c_low, d_low) && \
159 LTTNG_FEDORA_VERSION_CODE < \
160 LTTNG_FEDORA_KERNEL_VERSION(a_high, b_high, c_high, d_high))
161
c94ac1ac 162/* RT patch */
f30ae671 163
b4c8e4d3 164#define LTTNG_RT_KERNEL_VERSION(a, b, c, d) \
5f4c791e 165 (((LTTNG_KERNEL_VERSION(a, b, c)) << 8) + (d))
b4c8e4d3
MJ
166
167#ifdef RT_PATCH_VERSION
168#define LTTNG_RT_VERSION_CODE \
5f4c791e 169 ((LTTNG_LINUX_VERSION_CODE << 8) + RT_PATCH_VERSION)
b4c8e4d3
MJ
170#else
171#define LTTNG_RT_VERSION_CODE 0
172#endif
173
174#define LTTNG_RT_KERNEL_RANGE(a_low, b_low, c_low, d_low, \
175 a_high, b_high, c_high, d_high) \
176 (LTTNG_RT_VERSION_CODE >= \
177 LTTNG_RT_KERNEL_VERSION(a_low, b_low, c_low, d_low) && \
178 LTTNG_RT_VERSION_CODE < \
179 LTTNG_RT_KERNEL_VERSION(a_high, b_high, c_high, d_high))
180
5fa38800 181#endif /* _LTTNG_KERNEL_VERSION_H */
This page took 0.048325 seconds and 4 git commands to generate.