| 1 | /* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only) |
| 2 | * |
| 3 | * lttng/kernel-version.h |
| 4 | * |
| 5 | * Contains helpers to check more complex kernel version conditions. |
| 6 | * |
| 7 | * Copyright (C) 2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 8 | */ |
| 9 | |
| 10 | #ifndef _LTTNG_KERNEL_VERSION_H |
| 11 | #define _LTTNG_KERNEL_VERSION_H |
| 12 | |
| 13 | #include <linux/version.h> |
| 14 | #include <generated/utsrelease.h> |
| 15 | |
| 16 | /* |
| 17 | * This macro checks if the kernel version is between the two specified |
| 18 | * versions (lower limit inclusive, upper limit exclusive). |
| 19 | */ |
| 20 | #define LTTNG_KERNEL_RANGE(a_low, b_low, c_low, a_high, b_high, c_high) \ |
| 21 | (LINUX_VERSION_CODE >= KERNEL_VERSION(a_low, b_low, c_low) && \ |
| 22 | LINUX_VERSION_CODE < KERNEL_VERSION(a_high, b_high, c_high)) |
| 23 | |
| 24 | /* Ubuntu */ |
| 25 | |
| 26 | #define LTTNG_UBUNTU_KERNEL_VERSION(a, b, c, d) \ |
| 27 | (((a) << 24) + ((b) << 16) + ((c) << 8) + (d)) |
| 28 | |
| 29 | #ifdef UTS_UBUNTU_RELEASE_ABI |
| 30 | #define LTTNG_UBUNTU_VERSION_CODE \ |
| 31 | ((LINUX_VERSION_CODE << 8) + UTS_UBUNTU_RELEASE_ABI) |
| 32 | #else |
| 33 | #define LTTNG_UBUNTU_VERSION_CODE 0 |
| 34 | #endif |
| 35 | |
| 36 | #define LTTNG_UBUNTU_KERNEL_RANGE(a_low, b_low, c_low, d_low, \ |
| 37 | a_high, b_high, c_high, d_high) \ |
| 38 | (LTTNG_UBUNTU_VERSION_CODE >= \ |
| 39 | LTTNG_UBUNTU_KERNEL_VERSION(a_low, b_low, c_low, d_low) && \ |
| 40 | LTTNG_UBUNTU_VERSION_CODE < \ |
| 41 | LTTNG_UBUNTU_KERNEL_VERSION(a_high, b_high, c_high, d_high)) |
| 42 | |
| 43 | /* Debian */ |
| 44 | |
| 45 | #define LTTNG_DEBIAN_KERNEL_VERSION(a, b, c, d, e, f) \ |
| 46 | (((((a) << 16) + ((b) << 8) + (c)) * 1000000ULL) + ((d) * 10000) + ((e) * 100) + (f)) |
| 47 | |
| 48 | #ifdef DEBIAN_API_VERSION |
| 49 | #define LTTNG_DEBIAN_VERSION_CODE \ |
| 50 | ((LINUX_VERSION_CODE * 1000000ULL) + DEBIAN_API_VERSION) |
| 51 | #else |
| 52 | #define LTTNG_DEBIAN_VERSION_CODE 0 |
| 53 | #endif |
| 54 | |
| 55 | #define LTTNG_DEBIAN_KERNEL_RANGE(a_low, b_low, c_low, d_low, e_low, f_low, \ |
| 56 | a_high, b_high, c_high, d_high, e_high, f_high) \ |
| 57 | (LTTNG_DEBIAN_VERSION_CODE >= \ |
| 58 | LTTNG_DEBIAN_KERNEL_VERSION(a_low, b_low, c_low, d_low, e_low, f_low) && \ |
| 59 | LTTNG_DEBIAN_VERSION_CODE < \ |
| 60 | LTTNG_DEBIAN_KERNEL_VERSION(a_high, b_high, c_high, d_high, e_high, f_high)) |
| 61 | |
| 62 | #define LTTNG_RHEL_KERNEL_VERSION(a, b, c, d, e, f) \ |
| 63 | (((((a) << 16) + ((b) << 8) + (c)) * 10000000ULL) + ((d) * 10000) + ((e) * 100) + (f)) |
| 64 | |
| 65 | /* RHEL */ |
| 66 | |
| 67 | #ifdef RHEL_API_VERSION |
| 68 | #define LTTNG_RHEL_VERSION_CODE \ |
| 69 | ((LINUX_VERSION_CODE * 10000000ULL) + RHEL_API_VERSION) |
| 70 | #else |
| 71 | #define LTTNG_RHEL_VERSION_CODE 0 |
| 72 | #endif |
| 73 | |
| 74 | #define LTTNG_RHEL_KERNEL_RANGE(a_low, b_low, c_low, d_low, e_low, f_low, \ |
| 75 | a_high, b_high, c_high, d_high, e_high, f_high) \ |
| 76 | (LTTNG_RHEL_VERSION_CODE >= \ |
| 77 | LTTNG_RHEL_KERNEL_VERSION(a_low, b_low, c_low, d_low, e_low, f_low) && \ |
| 78 | LTTNG_RHEL_VERSION_CODE < \ |
| 79 | LTTNG_RHEL_KERNEL_VERSION(a_high, b_high, c_high, d_high, e_high, f_high)) |
| 80 | |
| 81 | /* SUSE Linux enterprise */ |
| 82 | |
| 83 | #define LTTNG_SLE_KERNEL_VERSION(a, b, c, d, e, f) \ |
| 84 | (((((a) << 16) + ((b) << 8) + (c)) * 10000000ULL) + ((d) * 10000) + ((e) * 100) + (f)) |
| 85 | |
| 86 | #ifdef SLE_API_VERSION |
| 87 | #define LTTNG_SLE_VERSION_CODE \ |
| 88 | ((LINUX_VERSION_CODE * 10000000ULL) + SLE_API_VERSION) |
| 89 | #else |
| 90 | #define LTTNG_SLE_VERSION_CODE 0 |
| 91 | #endif |
| 92 | |
| 93 | #define LTTNG_SLE_KERNEL_RANGE(a_low, b_low, c_low, d_low, e_low, f_low, \ |
| 94 | a_high, b_high, c_high, d_high, e_high, f_high) \ |
| 95 | (LTTNG_SLE_VERSION_CODE >= \ |
| 96 | LTTNG_SLE_KERNEL_VERSION(a_low, b_low, c_low, d_low, e_low, f_low) && \ |
| 97 | LTTNG_SLE_VERSION_CODE < \ |
| 98 | LTTNG_SLE_KERNEL_VERSION(a_high, b_high, c_high, d_high, e_high, f_high)) |
| 99 | |
| 100 | /* Fedora */ |
| 101 | |
| 102 | #define LTTNG_FEDORA_KERNEL_VERSION(a, b, c, d) \ |
| 103 | (((((a) << 16) + ((b) << 8) + (c)) * 10000ULL) + (d)) |
| 104 | |
| 105 | #ifdef FEDORA_REVISION_VERSION |
| 106 | #define LTTNG_FEDORA_VERSION_CODE \ |
| 107 | ((LINUX_VERSION_CODE * 10000ULL) + FEDORA_REVISION_VERSION) |
| 108 | #else |
| 109 | #define LTTNG_FEDORA_VERSION_CODE 0 |
| 110 | #endif |
| 111 | |
| 112 | #define LTTNG_FEDORA_KERNEL_RANGE(a_low, b_low, c_low, d_low, \ |
| 113 | a_high, b_high, c_high, d_high) \ |
| 114 | (LTTNG_FEDORA_VERSION_CODE >= \ |
| 115 | LTTNG_FEDORA_KERNEL_VERSION(a_low, b_low, c_low, d_low) && \ |
| 116 | LTTNG_FEDORA_VERSION_CODE < \ |
| 117 | LTTNG_FEDORA_KERNEL_VERSION(a_high, b_high, c_high, d_high)) |
| 118 | |
| 119 | /* RT patch */ |
| 120 | |
| 121 | #define LTTNG_RT_KERNEL_VERSION(a, b, c, d) \ |
| 122 | (((a) << 24) + ((b) << 16) + ((c) << 8) + (d)) |
| 123 | |
| 124 | #ifdef RT_PATCH_VERSION |
| 125 | #define LTTNG_RT_VERSION_CODE \ |
| 126 | ((LINUX_VERSION_CODE << 8) + RT_PATCH_VERSION) |
| 127 | #else |
| 128 | #define LTTNG_RT_VERSION_CODE 0 |
| 129 | #endif |
| 130 | |
| 131 | #define LTTNG_RT_KERNEL_RANGE(a_low, b_low, c_low, d_low, \ |
| 132 | a_high, b_high, c_high, d_high) \ |
| 133 | (LTTNG_RT_VERSION_CODE >= \ |
| 134 | LTTNG_RT_KERNEL_VERSION(a_low, b_low, c_low, d_low) && \ |
| 135 | LTTNG_RT_VERSION_CODE < \ |
| 136 | LTTNG_RT_KERNEL_VERSION(a_high, b_high, c_high, d_high)) |
| 137 | |
| 138 | #endif /* _LTTNG_KERNEL_VERSION_H */ |