From 5449531f1c056e3df0b1d0893bdba22b66a68513 Mon Sep 17 00:00:00 2001 From: Simone Caronni Date: Wed, 3 Jun 2026 07:27:57 +0200 Subject: [PATCH 1/2] Use probes instead of version/distribution conditionals --- .gitignore | 2 + module/Makefile | 45 +++-- module/conftest.sh | 353 +++++++++++++++++++++++++++++++++++++ module/evdi_connector.c | 12 +- module/evdi_cursor.c | 9 +- module/evdi_cursor.h | 3 +- module/evdi_debug.h | 3 +- module/evdi_drm_drv.c | 52 +++--- module/evdi_drm_drv.h | 18 +- module/evdi_encoder.c | 3 +- module/evdi_fb.c | 26 ++- module/evdi_gem.c | 54 +++--- module/evdi_i2c.c | 3 +- module/evdi_ioc32.c | 5 +- module/evdi_modeset.c | 50 +++--- module/evdi_painter.c | 47 ++--- module/evdi_platform_dev.c | 10 +- module/evdi_platform_dev.h | 3 +- module/evdi_platform_drv.h | 3 +- 19 files changed, 524 insertions(+), 177 deletions(-) create mode 100755 module/conftest.sh diff --git a/.gitignore b/.gitignore index ff1c082b..e06f3dcd 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,8 @@ module/.tmp_versions/ module/built-in.a module/evdi.mod module/evdi.mod.c +module/evdi_detect.h +module/evdi_detect.h.tmp site/ tmp/ diff --git a/module/Makefile b/module/Makefile index 823d8614..818a60f1 100644 --- a/module/Makefile +++ b/module/Makefile @@ -6,20 +6,29 @@ # more details. # -include /etc/os-release - -ifneq (,$(findstring rhel,$(ID_LIKE))) -ELFLAG := -DEL$(shell echo $(VERSION_ID) | cut -d. -f1) -endif - -ifneq (,$(findstring centos,$(ID))) -CENTOSFLAG := -DCENTOS$(shell echo $(VERSION_ID) | cut -d. -f1) -endif - -Raspbian := $(shell grep -Eic 'raspb(erry|ian)' /proc/cpuinfo /etc/os-release 2>/dev/null ) -ifeq (,$(findstring 0, $(Raspbian))) -RPIFLAG := -DRPI -endif +# Kernel API differences are detected at build time by conftest.sh (which +# test-compiles probes against the target kernel headers) rather than guessed +# from the distribution. See conftest.sh and the EVDI_HAVE_* macros it emits +# into the generated evdi_detect.h. +# +# Generate evdi_detect.h, force-include it into every object, and make every +# object depend on it. Used from the kbuild-context branches below, where the +# kernel compiler ($(CC)) and its include/cflags are available. The header is +# regenerated each build but only rewritten when its contents change, so +# incremental builds and kernel switches both behave correctly. +define evdi_conftest +ccflags-y += -include $$(obj)/evdi_detect.h +clean-files := evdi_detect.h evdi_detect.h.tmp +# Explicit (not pattern) prerequisite: GNU make merges prerequisites from +# explicit rules with kbuild's own $(obj)/%.o pattern rule, so the header is +# generated before any object is compiled. Cover the optional COMPAT object too. +$$(addprefix $$(obj)/, $$(evdi-y) evdi_ioc32.o): $$(obj)/evdi_detect.h +$$(obj)/evdi_detect.h: $$(src)/conftest.sh FORCE + $$(Q)$$(CONFIG_SHELL) $$(src)/conftest.sh "$$(CC)" \ + "$$(NOSTDINC_FLAGS) $$(LINUXINCLUDE) $$(KBUILD_CPPFLAGS) $$(KBUILD_CFLAGS) -DMODULE" \ + $$@.tmp + $$(Q)cmp -s $$@.tmp $$@ 2>/dev/null && rm -f $$@.tmp || mv $$@.tmp $$@ +endef ifneq ($(DKMS_BUILD),) @@ -27,10 +36,11 @@ ifneq ($(DKMS_BUILD),) KERN_DIR := /lib/modules/$(KERNELRELEASE)/build -ccflags-y := -Iinclude/uapi/drm -Iinclude/drm $(ELFLAG) $(CENTOSFLAG) $(RPIFLAG) +ccflags-y := -Iinclude/uapi/drm -Iinclude/drm evdi-y := evdi_platform_drv.o evdi_platform_dev.o evdi_sysfs.o evdi_modeset.o evdi_connector.o evdi_encoder.o evdi_drm_drv.o evdi_fb.o evdi_gem.o evdi_painter.o evdi_params.o evdi_cursor.o evdi_debug.o evdi_i2c.o evdi-$(CONFIG_COMPAT) += evdi_ioc32.o obj-m := evdi.o +$(eval $(call evdi_conftest)) KBUILD_VERBOSE ?= 1 @@ -49,12 +59,13 @@ ifneq ($(KERNELRELEASE),) # inside kbuild # Note: this can be removed once it is in kernel tree and Kconfig is properly used -ccflags-y := -isystem include/uapi/drm $(CFLAGS) $(ELFLAG) $(CENTOSFLAG) $(RPIFLAG) +ccflags-y := -isystem include/uapi/drm $(CFLAGS) evdi-y := evdi_platform_drv.o evdi_platform_dev.o evdi_sysfs.o evdi_modeset.o evdi_connector.o evdi_encoder.o evdi_drm_drv.o evdi_fb.o evdi_gem.o evdi_painter.o evdi_params.o evdi_cursor.o evdi_debug.o evdi_i2c.o evdi-$(CONFIG_COMPAT) += evdi_ioc32.o CONFIG_DRM_EVDI ?= m obj-$(CONFIG_DRM_EVDI) := evdi.o obj-y += tests/ +$(eval $(call evdi_conftest)) else @@ -87,7 +98,7 @@ module: $(MAKE) -C $(KDIR) M=$$PWD clean: - $(RM) -rf *.o *.a *.ko .tmp* .*.*.cmd Module.symvers evdi.mod.c modules.order + $(RM) -rf *.o *.a *.ko .tmp* .*.*.cmd Module.symvers evdi.mod.c modules.order evdi_detect.h evdi_detect.h.tmp install: $(MAKE) -C $(KDIR) M=$$PWD INSTALL_MOD_PATH=$(DESTDIR) INSTALL_MOD_DIR=$(MOD_KERNEL_PATH) modules_install diff --git a/module/conftest.sh b/module/conftest.sh new file mode 100755 index 00000000..f33f6661 --- /dev/null +++ b/module/conftest.sh @@ -0,0 +1,353 @@ +#!/bin/sh +# +# Copyright (c) 2026 DisplayLink (UK) Ltd. +# +# This file is subject to the terms and conditions of the GNU General Public +# License v2. See the file COPYING in the main directory of this archive for +# more details. +# +# Compile-time kernel feature detection for the evdi module. +# +# To support a new kernel API change, add a compile_test block below and use +# the resulting EVDI_HAVE_* macro in the source. Never add another distro flag. +# +# Usage: conftest.sh "" "" + +set -u + +CC="$1" +CFLAGS="$2" +OUT="$3" + +WORKDIR="$(mktemp -d)" +trap 'rm -rf "$WORKDIR"' EXIT +SRC="$WORKDIR/conftest.c" + +# compile_test (snippet read from stdin) +# +# Defines to 1 if the snippet compiles cleanly against the kernel +# headers, otherwise emits a comment so the generated header is self-documenting. +# -fsyntax-only does a full parse + typecheck (no codegen): it catches missing +# headers, unknown struct members, wrong argument counts and -- together with +# -Werror=implicit-function-declaration -- calls to functions that do not exist. +compile_test() { + macro="$1" + cat > "$SRC" + if $CC $CFLAGS -Werror=implicit-function-declaration \ + -Werror=incompatible-pointer-types \ + -fsyntax-only "$SRC" >/dev/null 2>&1; then + printf '#define %s 1\n' "$macro" >> "$OUT" + else + printf '/* %s not detected */\n' "$macro" >> "$OUT" + fi +} + +{ + echo "/* Automatically generated by conftest.sh -- do not edit. */" + echo "#ifndef EVDI_DETECT_H" + echo "#define EVDI_DETECT_H" +} > "$OUT" + +# --------------------------------------------------------------------------- +# Feature probes +# --------------------------------------------------------------------------- + +# was removed in 5.5. Present only on old kernels. +compile_test EVDI_HAVE_DRMP_H <<'EOF' +#include +void conftest(void) { } +EOF + +# drm_atomic_helper_dirtyfb() and arrived in 5.0. +compile_test EVDI_HAVE_ATOMIC_DIRTYFB <<'EOF' +#include +#include +void *conftest = (void *)&drm_atomic_helper_dirtyfb; +EOF + +# drm_gem_object_put_unlocked() was folded into drm_gem_object_put() in 5.9. +# Present only on old kernels. +compile_test EVDI_HAVE_GEM_OBJECT_PUT_UNLOCKED <<'EOF' +#include +void conftest(struct drm_gem_object *obj) { drm_gem_object_put_unlocked(obj); } +EOF + +# kzalloc_obj() became a kernel-provided helper in 6.20; before that evdi +# defines its own fallback. +compile_test EVDI_HAVE_KZALLOC_OBJ <<'EOF' +#include +void conftest(void) { int *p = kzalloc_obj(*p, 0); (void)p; } +EOF + +# The atomic helper callbacks switched to taking a struct drm_atomic_state *: +# the CRTC callbacks (.atomic_flush) in 5.11, the plane callbacks +# (.atomic_update) in 5.13. Detected via the vtable field signatures (some +# vendor/RPi kernels backport these independently). +compile_test EVDI_HAVE_CRTC_ATOMIC_STATE_ARG <<'EOF' +#include +static void conftest_flush(struct drm_crtc *c, struct drm_atomic_state *s) { } +struct drm_crtc_helper_funcs conftest = { .atomic_flush = conftest_flush }; +EOF +compile_test EVDI_HAVE_PLANE_ATOMIC_STATE_ARG <<'EOF' +#include +static void conftest_update(struct drm_plane *p, struct drm_atomic_state *s) { } +struct drm_plane_helper_funcs conftest = { .atomic_update = conftest_update }; +EOF + +# drm_gem_plane_helper_prepare_fb() (in ) replaced +# drm_gem_fb_prepare_fb in 5.13. +compile_test EVDI_HAVE_DRM_GEM_PLANE_HELPER_PREPARE_FB <<'EOF' +#include +void *conftest = (void *)&drm_gem_plane_helper_prepare_fb; +EOF + +# drm_mode_config_funcs lost its .output_poll_changed member in 6.12. +compile_test EVDI_HAVE_OUTPUT_POLL_CHANGED <<'EOF' +#include +void conftest(struct drm_mode_config_funcs *f) { f->output_poll_changed = (void *)0; } +EOF + +# DRIVER_PRIME feature flag was removed in 5.4 (PRIME is always available now). +compile_test EVDI_HAVE_DRIVER_PRIME <<'EOF' +#include +unsigned int conftest(void) { return DRIVER_PRIME; } +EOF + +# drmm_add_action_or_reset() / arrived in 5.8 (managed +# device cleanup); before it the release callback is invoked by hand. +compile_test EVDI_HAVE_DRMM_ADD_ACTION <<'EOF' +#include +static void conftest_cb(struct drm_device *dev, void *p) { } +void conftest(struct drm_device *dev) { (void)drmm_add_action_or_reset(dev, conftest_cb, NULL); } +EOF + +# DRM_UNLOCKED was removed in 6.8 (all ioctls are unlocked). Present on old kernels. +compile_test EVDI_HAVE_DRM_UNLOCKED <<'EOF' +#include +unsigned int conftest(void) { return DRM_UNLOCKED; } +EOF + +# struct drm_driver lost the GEM/dumb callbacks as they moved to +# drm_gem_object_funcs: .gem_free_object in 5.9, .dumb_destroy in 5.12. +compile_test EVDI_HAVE_DRM_DRIVER_GEM_FREE <<'EOF' +#include +void conftest(struct drm_driver *d) { (void)d->gem_free_object; } +EOF +compile_test EVDI_HAVE_DRM_DRIVER_DUMB_DESTROY <<'EOF' +#include +void conftest(struct drm_driver *d) { (void)d->dumb_destroy; } +EOF + +# In 6.6 drm_gem_prime_fd_to_handle/_handle_to_fd became the implicit defaults, +# so evdi stopped assigning them. Both helper and field still exist upstream, +# leaving no removal to detect, so we set them whenever the helper is available +# (redundant-but-correct where defaulted). REVISIT during EL9/CentOS testing. +compile_test EVDI_HAVE_GEM_PRIME_FD_TO_HANDLE <<'EOF' +#include +void conftest(struct drm_device *dev, struct drm_file *f, int fd, uint32_t *h) +{ + (void)drm_gem_prime_fd_to_handle(dev, f, fd, h); +} +EOF + +# The drm_mode_ prefix was dropped from these connector helpers in 4.19 +# (drm_mode_connector_update_edid_property -> drm_connector_update_edid_property, +# and likewise for attach_encoder). Probed separately though they share a release. +compile_test EVDI_HAVE_DRM_CONNECTOR_UPDATE_EDID <<'EOF' +#include +void conftest(struct drm_connector *c) { (void)drm_connector_update_edid_property(c, NULL); } +EOF +compile_test EVDI_HAVE_DRM_CONNECTOR_ATTACH_ENCODER <<'EOF' +#include +void conftest(struct drm_connector *c, struct drm_encoder *e) { (void)drm_connector_attach_encoder(c, e); } +EOF + +# The connector helper .mode_valid callback took a const drm_display_mode * from 6.15. +compile_test EVDI_HAVE_CONNECTOR_MODE_VALID_CONST <<'EOF' +#include +static enum drm_mode_status conftest_mv(struct drm_connector *c, + const struct drm_display_mode *m) { return MODE_OK; } +struct drm_connector_helper_funcs conftest = { .mode_valid = conftest_mv }; +EOF + +# drm_connector_for_each_possible_encoder() (2-arg form) replaced +# connector->encoder_ids[] iteration in 5.5. +compile_test EVDI_HAVE_CONNECTOR_FOR_EACH_ENCODER <<'EOF' +#include +#include +void conftest(struct drm_connector *c) +{ + struct drm_encoder *e; + + drm_connector_for_each_possible_encoder(c, e) { } +} +EOF + +# vm_flags_mod() (6.3) is required once vma->vm_flags became immutable. Note +# some vendor kernels (EL8) reverted this, hence detection over version. +compile_test EVDI_HAVE_VM_FLAGS_MOD <<'EOF' +#include +void conftest(struct vm_area_struct *vma) { vm_flags_mod(vma, 0, 0); } +EOF + +# dma_buf_vmap_unlocked() / dma_buf_vunmap_unlocked() were added in 6.2. +compile_test EVDI_HAVE_DMA_BUF_VMAP_UNLOCKED <<'EOF' +#include +void conftest(struct dma_buf *db, struct iosys_map *map) +{ + (void)dma_buf_vmap_unlocked(db, map); +} +EOF + +# for_each_sgtable_page() was added in 5.8 (open-coded via for_each_sg_page +# before that). +compile_test EVDI_HAVE_FOR_EACH_SGTABLE_PAGE <<'EOF' +#include +void conftest(struct sg_table *sgt) +{ + struct sg_page_iter it; + + for_each_sgtable_page(sgt, &it, 0) { } +} +EOF + +# drm_prime_sg_to_page_addr_arrays() was renamed drm_prime_sg_to_page_array() +# in 5.12. +compile_test EVDI_HAVE_DRM_PRIME_SG_TO_PAGE_ARRAY <<'EOF' +#include +void conftest(struct sg_table *sg, struct page **pages, unsigned int n) +{ + (void)drm_prime_sg_to_page_array(sg, pages, n); +} +EOF + +# (4.20) and the fallthrough pseudo-keyword it +# provides (5.4) -- probed separately because the header predates the macro. +compile_test EVDI_HAVE_COMPILER_ATTRIBUTES_H <<'EOF' +#include +void conftest(void) { } +EOF +compile_test EVDI_HAVE_FALLTHROUGH <<'EOF' +#include +void conftest(int x) { switch (x) { case 0: fallthrough; default: break; } } +EOF + +# MODULE_IMPORT_NS took a bare token until 6.13, when it began requiring a +# string literal. The bare-token form stops compiling at 6.13, so it is the +# discriminator; the string form alone tells old (<5.4, macro absent) apart. +compile_test EVDI_HAVE_MODULE_IMPORT_NS <<'EOF' +#include +MODULE_IMPORT_NS(DMA_BUF); +EOF +compile_test EVDI_HAVE_MODULE_IMPORT_NS_STRING <<'EOF' +#include +MODULE_IMPORT_NS("DMA_BUF"); +EOF + +# was split out in 5.1. +compile_test EVDI_HAVE_DRM_PROBE_HELPER_H <<'EOF' +#include +void conftest(void) { } +EOF + +# struct drm_device gained a .debugfs_root member in 6.7 (along with +# debugfs_lookup_and_remove) -- gates the measure_copy debugfs feature. +compile_test EVDI_HAVE_DRM_DEBUGFS_ROOT <<'EOF' +#include +void conftest(struct drm_device *dev) { (void)dev->debugfs_root; } +EOF + +# drm_prime_pages_to_sg() gained a leading struct drm_device * in 5.10. Also +# used as the marker for the 5.10 DRM line by the cursor-plane num_dirts logic, +# which has no API surface of its own but shares this exact boundary. +compile_test EVDI_HAVE_DRM_PRIME_PAGES_TO_SG_DEV <<'EOF' +#include +void conftest(struct drm_device *dev, struct page **pages, unsigned int n) +{ + (void)drm_prime_pages_to_sg(dev, pages, n); +} +EOF + +# struct drm_format_name_buf and drm_get_format_name() were removed in 5.14 +# when the %p4cc printf format took over. Present only on old kernels. +compile_test EVDI_HAVE_DRM_FORMAT_NAME_BUF <<'EOF' +#include +struct drm_format_name_buf conftest; +EOF + +# was removed in 5.15. Present only on old kernels. +compile_test EVDI_HAVE_DRM_IRQ_H <<'EOF' +#include +void conftest(void) { } +EOF + +# The GEM vmap callback moved to a map descriptor: struct dma_buf_map in 5.11, +# renamed struct iosys_map in 5.18. Either implies the vmap_is_iomem path. +compile_test EVDI_HAVE_IOSYS_MAP <<'EOF' +#include +struct iosys_map conftest; +EOF +compile_test EVDI_HAVE_DMA_BUF_MAP <<'EOF' +#include +struct dma_buf_map conftest; +EOF + +# vm_fault_t was introduced in 4.17 (fault handlers returned int before). +compile_test EVDI_HAVE_VM_FAULT_T <<'EOF' +#include +vm_fault_t conftest; +EOF + +# The platform_driver .remove callback returns void since 6.11 (it returned +# int before). Detect the actual signature rather than the version -- some +# vendor kernels (e.g. EL9) backport this independently of the version number. +compile_test EVDI_HAVE_PLATFORM_REMOVE_VOID <<'EOF' +#include +static void conftest_remove(struct platform_device *pdev) { } +struct platform_driver conftest = { .remove = conftest_remove }; +EOF + +# struct dev_archdata gained/kept an .iommu member on x86 before 5.9; the +# Intel-IOMMU dummy-domain workaround only applies where that field exists. +compile_test EVDI_HAVE_DEV_ARCHDATA_IOMMU <<'EOF' +#include +void conftest(struct platform_device *pdev) { pdev->dev.archdata.iommu = (void *)0; } +EOF + +# struct drm_driver lost its .date member in 6.14 (DRIVER_DATE removal). +# Present only on old kernels. +compile_test EVDI_HAVE_DRM_DRIVER_DATE <<'EOF' +#include +void conftest(struct drm_driver *drv) { (void)drv->date; } +EOF + +# drm_ioctl_compat_t moved into in 5.16. When this is not +# available the typedef comes from (<5.5) or the default include +# chain (5.5-5.15). +compile_test EVDI_HAVE_DRM_IOCTL_COMPAT_T <<'EOF' +#include +drm_ioctl_compat_t *conftest; +EOF + +# I2C_CLASS_DDC was removed in 6.8. Note the struct i2c_adapter .class member +# itself outlived it, so probe the constant the code actually assigns, not the +# field. Present only on old kernels. +compile_test EVDI_HAVE_I2C_CLASS_DDC <<'EOF' +#include +unsigned int conftest(void) { return I2C_CLASS_DDC; } +EOF + +# drm_helper_mode_fill_fb_struct() and the .fb_create hook gained a +# "const struct drm_format_info *" parameter in 6.17. +compile_test EVDI_HAVE_FB_FORMAT_INFO <<'EOF' +#include +#include +void conftest(struct drm_device *dev, struct drm_framebuffer *fb, + const struct drm_format_info *info, + const struct drm_mode_fb_cmd2 *mode_cmd) +{ + drm_helper_mode_fill_fb_struct(dev, fb, info, mode_cmd); +} +EOF + +echo "#endif /* EVDI_DETECT_H */" >> "$OUT" diff --git a/module/evdi_connector.c b/module/evdi_connector.c index 945de255..18689217 100644 --- a/module/evdi_connector.c +++ b/module/evdi_connector.c @@ -18,7 +18,7 @@ #include #include "evdi_drm_drv.h" -#if KERNEL_VERSION(5, 1, 0) <= LINUX_VERSION_CODE || defined(EL8) +#ifdef EVDI_HAVE_DRM_PROBE_HELPER_H #include #endif @@ -36,7 +36,7 @@ static int evdi_get_modes(struct drm_connector *connector) edid = (struct edid *)evdi_painter_get_edid_copy(evdi); if (!edid) { -#if KERNEL_VERSION(4, 19, 0) <= LINUX_VERSION_CODE || defined(EL8) +#ifdef EVDI_HAVE_DRM_CONNECTOR_UPDATE_EDID drm_connector_update_edid_property(connector, NULL); #else drm_mode_connector_update_edid_property(connector, NULL); @@ -44,7 +44,7 @@ static int evdi_get_modes(struct drm_connector *connector) return 0; } -#if KERNEL_VERSION(4, 19, 0) <= LINUX_VERSION_CODE || defined(EL8) +#ifdef EVDI_HAVE_DRM_CONNECTOR_UPDATE_EDID ret = drm_connector_update_edid_property(connector, edid); #else ret = drm_mode_connector_update_edid_property(connector, edid); @@ -78,7 +78,7 @@ static bool is_lowest_frequency_mode_of_given_resolution( } static enum drm_mode_status evdi_mode_valid(struct drm_connector *connector, -#if KERNEL_VERSION(6, 15, 0) <= LINUX_VERSION_CODE || defined(EL9) || defined(EL10) +#ifdef EVDI_HAVE_CONNECTOR_MODE_VALID_CONST const struct drm_display_mode *mode) #else struct drm_display_mode *mode) @@ -149,7 +149,7 @@ static void evdi_connector_destroy(struct drm_connector *connector) static struct drm_encoder *evdi_best_encoder(struct drm_connector *connector) { -#if KERNEL_VERSION(5, 5, 0) <= LINUX_VERSION_CODE || defined(EL8) +#ifdef EVDI_HAVE_CONNECTOR_FOR_EACH_ENCODER struct drm_encoder *encoder; drm_connector_for_each_possible_encoder(connector, encoder) { @@ -198,7 +198,7 @@ int evdi_connector_init(struct drm_device *dev, struct drm_encoder *encoder) evdi->conn = connector; -#if KERNEL_VERSION(4, 19, 0) <= LINUX_VERSION_CODE || defined(EL8) +#ifdef EVDI_HAVE_DRM_CONNECTOR_ATTACH_ENCODER drm_connector_attach_encoder(connector, encoder); #else drm_mode_connector_attach_encoder(connector, encoder); diff --git a/module/evdi_cursor.c b/module/evdi_cursor.c index 3450f205..74c2a480 100644 --- a/module/evdi_cursor.c +++ b/module/evdi_cursor.c @@ -23,8 +23,7 @@ #include #include -#if KERNEL_VERSION(5, 5, 0) <= LINUX_VERSION_CODE || defined(EL8) -#else +#ifdef EVDI_HAVE_DRMP_H #include #endif #include @@ -55,10 +54,10 @@ static void evdi_cursor_set_gem(struct evdi_cursor *cursor, if (obj) drm_gem_object_get(&obj->base); if (cursor->obj) -#if KERNEL_VERSION(5, 9, 0) <= LINUX_VERSION_CODE || defined(EL8) - drm_gem_object_put(&cursor->obj->base); -#else +#ifdef EVDI_HAVE_GEM_OBJECT_PUT_UNLOCKED drm_gem_object_put_unlocked(&cursor->obj->base); +#else + drm_gem_object_put(&cursor->obj->base); #endif cursor->obj = obj; diff --git a/module/evdi_cursor.h b/module/evdi_cursor.h index 13d8a8ab..789efc57 100644 --- a/module/evdi_cursor.h +++ b/module/evdi_cursor.h @@ -23,8 +23,7 @@ #include #include -#if KERNEL_VERSION(5, 5, 0) <= LINUX_VERSION_CODE || defined(EL8) -#else +#ifdef EVDI_HAVE_DRMP_H #include #endif #include diff --git a/module/evdi_debug.h b/module/evdi_debug.h index ed3ad885..fff629b5 100644 --- a/module/evdi_debug.h +++ b/module/evdi_debug.h @@ -56,8 +56,7 @@ void evdi_log_process(char *buf, size_t size); -#if KERNEL_VERSION(6, 20, 0) <= LINUX_VERSION_CODE -#else +#ifndef EVDI_HAVE_KZALLOC_OBJ #define kzalloc_obj(obj, flags) kzalloc(sizeof(typeof(obj)), flags) #endif diff --git a/module/evdi_drm_drv.c b/module/evdi_drm_drv.c index 3ce1af2d..09326c8a 100644 --- a/module/evdi_drm_drv.c +++ b/module/evdi_drm_drv.c @@ -12,19 +12,18 @@ */ #include -#if KERNEL_VERSION(5, 16, 0) <= LINUX_VERSION_CODE || defined(EL8) || defined(EL9) +#ifdef EVDI_HAVE_DRM_IOCTL_COMPAT_T #include #include #include #include -#elif KERNEL_VERSION(5, 5, 0) <= LINUX_VERSION_CODE -#else +#elif defined(EVDI_HAVE_DRMP_H) #include #endif -#if KERNEL_VERSION(5, 1, 0) <= LINUX_VERSION_CODE || defined(EL8) +#ifdef EVDI_HAVE_DRM_PROBE_HELPER_H #include #endif -#if KERNEL_VERSION(5, 8, 0) <= LINUX_VERSION_CODE || defined(EL8) +#ifdef EVDI_HAVE_DRMM_ADD_ACTION #include #endif #include @@ -34,10 +33,10 @@ #include "evdi_debug.h" #include "evdi_drm.h" -#if KERNEL_VERSION(6, 8, 0) <= LINUX_VERSION_CODE || defined(EL9) -#define EVDI_DRM_UNLOCKED 0 -#else +#ifdef EVDI_HAVE_DRM_UNLOCKED #define EVDI_DRM_UNLOCKED DRM_UNLOCKED +#else +#define EVDI_DRM_UNLOCKED 0 #endif static struct drm_driver driver; @@ -50,7 +49,7 @@ struct drm_ioctl_desc evdi_painter_ioctls[] = { DRM_IOCTL_DEF_DRV(EVDI_ENABLE_CURSOR_EVENTS, evdi_painter_enable_cursor_events_ioctl, EVDI_DRM_UNLOCKED), }; -#if KERNEL_VERSION(5, 11, 0) <= LINUX_VERSION_CODE || defined(EL8) +#if defined(EVDI_HAVE_IOSYS_MAP) || defined(EVDI_HAVE_DMA_BUF_MAP) #else static const struct vm_operations_struct evdi_gem_vm_ops = { .fault = evdi_gem_fault, @@ -79,7 +78,7 @@ static const struct file_operations evdi_driver_fops = { #endif }; -#if KERNEL_VERSION(5, 11, 0) <= LINUX_VERSION_CODE || defined(EL8) +#if defined(EVDI_HAVE_IOSYS_MAP) || defined(EVDI_HAVE_DMA_BUF_MAP) #else static int evdi_enable_vblank(__always_unused struct drm_device *dev, __always_unused unsigned int pipe) @@ -94,33 +93,33 @@ static void evdi_disable_vblank(__always_unused struct drm_device *dev, #endif static struct drm_driver driver = { -#if KERNEL_VERSION(5, 4, 0) <= LINUX_VERSION_CODE || defined(EL8) - .driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_ATOMIC, -#else +#ifdef EVDI_HAVE_DRIVER_PRIME .driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_PRIME | DRIVER_ATOMIC, +#else + .driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_ATOMIC, #endif .open = evdi_driver_open, .postclose = evdi_driver_postclose, /* gem hooks */ -#if KERNEL_VERSION(5, 11, 0) <= LINUX_VERSION_CODE || defined(EL8) -#elif KERNEL_VERSION(5, 9, 0) <= LINUX_VERSION_CODE - .gem_free_object_unlocked = evdi_gem_free_object, -#else +#if defined(EVDI_HAVE_IOSYS_MAP) || defined(EVDI_HAVE_DMA_BUF_MAP) + /* GEM hooks live in drm_gem_object_funcs (5.11+) */ +#elif defined(EVDI_HAVE_DRM_DRIVER_GEM_FREE) .gem_free_object = evdi_gem_free_object, +#else + .gem_free_object_unlocked = evdi_gem_free_object, #endif -#if KERNEL_VERSION(5, 11, 0) <= LINUX_VERSION_CODE || defined(EL8) +#if defined(EVDI_HAVE_IOSYS_MAP) || defined(EVDI_HAVE_DMA_BUF_MAP) #else .gem_vm_ops = &evdi_gem_vm_ops, #endif .dumb_create = evdi_dumb_create, .dumb_map_offset = evdi_gem_mmap, -#if KERNEL_VERSION(5, 12, 0) <= LINUX_VERSION_CODE || defined(EL8) -#else +#ifdef EVDI_HAVE_DRM_DRIVER_DUMB_DESTROY .dumb_destroy = drm_gem_dumb_destroy, #endif @@ -130,12 +129,11 @@ static struct drm_driver driver = { .fops = &evdi_driver_fops, .gem_prime_import = drm_gem_prime_import, -#if KERNEL_VERSION(6, 6, 0) <= LINUX_VERSION_CODE || defined(EL9) -#else +#ifdef EVDI_HAVE_GEM_PRIME_FD_TO_HANDLE .prime_fd_to_handle = drm_gem_prime_fd_to_handle, .prime_handle_to_fd = drm_gem_prime_handle_to_fd, #endif -#if KERNEL_VERSION(5, 11, 0) <= LINUX_VERSION_CODE || defined(EL8) +#if defined(EVDI_HAVE_IOSYS_MAP) || defined(EVDI_HAVE_DMA_BUF_MAP) #else .preclose = evdi_driver_preclose, .gem_prime_export = drm_gem_prime_export, @@ -147,8 +145,7 @@ static struct drm_driver driver = { .name = DRIVER_NAME, .desc = DRIVER_DESC, -#if KERNEL_VERSION(6, 14, 0) <= LINUX_VERSION_CODE || defined(EL9) || defined(EL10) -#else +#ifdef EVDI_HAVE_DRM_DRIVER_DATE .date = DRIVER_DATE, #endif .major = DRIVER_MAJOR, @@ -198,7 +195,7 @@ static int evdi_drm_device_init(struct drm_device *dev) goto err_init; drm_kms_helper_poll_init(dev); -#if KERNEL_VERSION(5, 8, 0) <= LINUX_VERSION_CODE || defined(EL8) +#ifdef EVDI_HAVE_DRMM_ADD_ACTION ret = drmm_add_action_or_reset(dev, evdi_drm_device_release_cb, NULL); if (ret) goto err_init; @@ -283,8 +280,7 @@ int evdi_drm_device_remove(struct drm_device *dev) { drm_dev_unplug(dev); evdi_drm_device_deinit(dev); -#if KERNEL_VERSION(5, 8, 0) <= LINUX_VERSION_CODE || defined(EL8) -#else +#ifndef EVDI_HAVE_DRMM_ADD_ACTION evdi_drm_device_release_cb(dev, NULL); #endif drm_dev_put(dev); diff --git a/module/evdi_drm_drv.h b/module/evdi_drm_drv.h index e67fca2c..ad6ff9e6 100644 --- a/module/evdi_drm_drv.h +++ b/module/evdi_drm_drv.h @@ -18,18 +18,18 @@ #include #include #include -#if KERNEL_VERSION(5, 5, 0) <= LINUX_VERSION_CODE || defined(EL8) +#ifdef EVDI_HAVE_DRMP_H +#include +#else #include #include #include #include -#else -#include #endif -#if KERNEL_VERSION(5, 15, 0) <= LINUX_VERSION_CODE || defined(EL8) || defined(EL9) -#include -#else +#ifdef EVDI_HAVE_DRM_IRQ_H #include +#else +#include #endif #include #include @@ -66,7 +66,7 @@ struct evdi_gem_object { unsigned int pages_pin_count; struct mutex pages_lock; void *vmapping; -#if KERNEL_VERSION(5, 11, 0) <= LINUX_VERSION_CODE || defined(EL8) +#if defined(EVDI_HAVE_IOSYS_MAP) || defined(EVDI_HAVE_DMA_BUF_MAP) bool vmap_is_iomem; #endif struct sg_table *sg; @@ -102,7 +102,7 @@ long evdi_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); struct drm_framebuffer *evdi_fb_user_fb_create( struct drm_device *dev, struct drm_file *file, -#if KERNEL_VERSION(6, 17, 0) <= LINUX_VERSION_CODE || defined(CENTOS9) || defined(CENTOS10) +#ifdef EVDI_HAVE_FB_FORMAT_INFO const struct drm_format_info *info, #endif const struct drm_mode_fb_cmd2 *mode_cmd); @@ -128,7 +128,7 @@ int evdi_gem_vmap(struct evdi_gem_object *obj); void evdi_gem_vunmap(struct evdi_gem_object *obj); int evdi_drm_gem_mmap(struct file *filp, struct vm_area_struct *vma); -#if KERNEL_VERSION(4, 17, 0) <= LINUX_VERSION_CODE +#ifdef EVDI_HAVE_VM_FAULT_T vm_fault_t evdi_gem_fault(struct vm_fault *vmf); #else int evdi_gem_fault(struct vm_fault *vmf); diff --git a/module/evdi_encoder.c b/module/evdi_encoder.c index e35dfc5a..9424b38b 100644 --- a/module/evdi_encoder.c +++ b/module/evdi_encoder.c @@ -12,8 +12,7 @@ */ #include -#if KERNEL_VERSION(5, 5, 0) <= LINUX_VERSION_CODE || defined(EL8) -#else +#ifdef EVDI_HAVE_DRMP_H #include #endif #include diff --git a/module/evdi_fb.c b/module/evdi_fb.c index c13c94ef..b53405d3 100644 --- a/module/evdi_fb.c +++ b/module/evdi_fb.c @@ -14,8 +14,7 @@ #include #include #include -#if KERNEL_VERSION(5, 5, 0) <= LINUX_VERSION_CODE || defined(EL8) -#else +#ifdef EVDI_HAVE_DRMP_H #include #endif #include @@ -23,7 +22,7 @@ #include #include #include -#if KERNEL_VERSION(5, 0, 0) <= LINUX_VERSION_CODE || defined(EL8) +#ifdef EVDI_HAVE_ATOMIC_DIRTYFB #include #endif #include "evdi_drm_drv.h" @@ -83,8 +82,7 @@ struct drm_clip_rect evdi_framebuffer_sanitize_rect( return rect; } -#if KERNEL_VERSION(5, 0, 0) <= LINUX_VERSION_CODE || defined(EL8) -#else +#ifndef EVDI_HAVE_ATOMIC_DIRTYFB /* * Function taken from * https://lore.kernel.org/dri-devel/20180905233901.2321-5-drawat@vmware.com/ @@ -181,10 +179,10 @@ static void evdi_user_framebuffer_destroy(struct drm_framebuffer *fb) EVDI_CHECKPT(); if (efb->obj) -#if KERNEL_VERSION(5, 9, 0) <= LINUX_VERSION_CODE || defined(EL8) - drm_gem_object_put(&efb->obj->base); -#else +#ifdef EVDI_HAVE_GEM_OBJECT_PUT_UNLOCKED drm_gem_object_put_unlocked(&efb->obj->base); +#else + drm_gem_object_put(&efb->obj->base); #endif drm_framebuffer_cleanup(fb); kfree(efb); @@ -193,7 +191,7 @@ static void evdi_user_framebuffer_destroy(struct drm_framebuffer *fb) static const struct drm_framebuffer_funcs evdifb_funcs = { .create_handle = evdi_user_framebuffer_create_handle, .destroy = evdi_user_framebuffer_destroy, -#if KERNEL_VERSION(5, 0, 0) <= LINUX_VERSION_CODE || defined(EL8) +#ifdef EVDI_HAVE_ATOMIC_DIRTYFB .dirty = drm_atomic_helper_dirtyfb, #else .dirty = evdi_user_framebuffer_dirty, @@ -203,20 +201,20 @@ static const struct drm_framebuffer_funcs evdifb_funcs = { static int evdi_framebuffer_init(struct drm_device *dev, struct evdi_framebuffer *efb, -#if KERNEL_VERSION(6, 17, 0) <= LINUX_VERSION_CODE || defined(CENTOS9) || defined(CENTOS10) +#ifdef EVDI_HAVE_FB_FORMAT_INFO const struct drm_format_info *info, #endif const struct drm_mode_fb_cmd2 *mode_cmd, struct evdi_gem_object *obj) { efb->obj = obj; -#if KERNEL_VERSION(6, 17, 0) <= LINUX_VERSION_CODE || defined(CENTOS9) || defined(CENTOS10) +#ifdef EVDI_HAVE_FB_FORMAT_INFO if (info == NULL) info = drm_get_format_info(dev, mode_cmd->pixel_format, mode_cmd->modifier[0]); #endif drm_helper_mode_fill_fb_struct(dev, &efb->base, -#if KERNEL_VERSION(6, 17, 0) <= LINUX_VERSION_CODE || defined(CENTOS9) || defined(CENTOS10) +#ifdef EVDI_HAVE_FB_FORMAT_INFO info, #endif mode_cmd); @@ -253,7 +251,7 @@ static bool is_xe_gem(struct dma_buf *dmabuf) struct drm_framebuffer *evdi_fb_user_fb_create( struct drm_device *dev, struct drm_file *file, -#if KERNEL_VERSION(6, 17, 0) <= LINUX_VERSION_CODE || defined(CENTOS9) || defined(CENTOS10) +#ifdef EVDI_HAVE_FB_FORMAT_INFO const struct drm_format_info *info, #endif const struct drm_mode_fb_cmd2 *mode_cmd) @@ -289,7 +287,7 @@ struct drm_framebuffer *evdi_fb_user_fb_create( efb->base.obj[0] = obj; ret = evdi_framebuffer_init(dev, efb, -#if KERNEL_VERSION(6, 17, 0) <= LINUX_VERSION_CODE || defined(CENTOS9) || defined(CENTOS10) +#ifdef EVDI_HAVE_FB_FORMAT_INFO info, #endif mode_cmd, to_evdi_bo(obj)); diff --git a/module/evdi_gem.c b/module/evdi_gem.c index edebd529..1276bd87 100644 --- a/module/evdi_gem.c +++ b/module/evdi_gem.c @@ -10,17 +10,15 @@ #include #include -#if KERNEL_VERSION(5, 18, 0) <= LINUX_VERSION_CODE || defined(EL8) || defined(EL9) -#elif KERNEL_VERSION(5, 11, 0) <= LINUX_VERSION_CODE +#if defined(EVDI_HAVE_DMA_BUF_MAP) && !defined(EVDI_HAVE_IOSYS_MAP) #include #endif -#if KERNEL_VERSION(5, 16, 0) <= LINUX_VERSION_CODE || defined(EL8) || defined(EL9) +#ifdef EVDI_HAVE_DRM_IOCTL_COMPAT_T #include #include #include #include -#elif KERNEL_VERSION(5, 5, 0) <= LINUX_VERSION_CODE -#else +#elif defined(EVDI_HAVE_DRMP_H) #include #endif #include @@ -32,13 +30,13 @@ #include -#if KERNEL_VERSION(6, 13, 0) <= LINUX_VERSION_CODE || defined(EL10) -MODULE_IMPORT_NS("DMA_BUF"); -#elif KERNEL_VERSION(5, 16, 0) <= LINUX_VERSION_CODE || defined(EL9) +#ifdef EVDI_HAVE_MODULE_IMPORT_NS MODULE_IMPORT_NS(DMA_BUF); +#elif defined(EVDI_HAVE_MODULE_IMPORT_NS_STRING) +MODULE_IMPORT_NS("DMA_BUF"); #endif -#if KERNEL_VERSION(5, 11, 0) <= LINUX_VERSION_CODE || defined(EL8) +#if defined(EVDI_HAVE_IOSYS_MAP) || defined(EVDI_HAVE_DMA_BUF_MAP) static int evdi_prime_pin(struct drm_gem_object *obj); static void evdi_prime_unpin(struct drm_gem_object *obj); @@ -109,7 +107,7 @@ struct evdi_gem_object *evdi_gem_alloc_object(struct drm_device *dev, } -#if KERNEL_VERSION(5, 11, 0) <= LINUX_VERSION_CODE || defined(EL8) +#if defined(EVDI_HAVE_IOSYS_MAP) || defined(EVDI_HAVE_DMA_BUF_MAP) obj->base.funcs = &gem_obj_funcs; #endif @@ -141,10 +139,10 @@ evdi_gem_create(struct drm_file *file, kfree(obj); return ret; } -#if KERNEL_VERSION(5, 9, 0) <= LINUX_VERSION_CODE || defined(EL8) - drm_gem_object_put(&obj->base); -#else +#ifdef EVDI_HAVE_GEM_OBJECT_PUT_UNLOCKED drm_gem_object_put_unlocked(&obj->base); +#else + drm_gem_object_put(&obj->base); #endif *handle_p = handle; return 0; @@ -190,8 +188,7 @@ int evdi_drm_gem_mmap(struct file *filp, struct vm_area_struct *vma) if (ret) return ret; -/* Some VMA modifier function patches present in 6.3 were reverted in EL8 kernels */ -#if KERNEL_VERSION(6, 3, 0) <= LINUX_VERSION_CODE || defined(EL9) +#ifdef EVDI_HAVE_VM_FLAGS_MOD vm_flags_mod(vma, VM_MIXEDMAP, VM_PFNMAP); #else vma->vm_flags &= ~VM_PFNMAP; @@ -201,7 +198,7 @@ int evdi_drm_gem_mmap(struct file *filp, struct vm_area_struct *vma) return ret; } -#if KERNEL_VERSION(4, 17, 0) <= LINUX_VERSION_CODE +#ifdef EVDI_HAVE_VM_FAULT_T vm_fault_t evdi_gem_fault(struct vm_fault *vmf) { struct vm_area_struct *vma = vmf->vma; @@ -292,7 +289,7 @@ static void evdi_unpin_pages(struct evdi_gem_object *obj) evdi_gem_put_pages(obj); mutex_unlock(&obj->pages_lock); } -# if KERNEL_VERSION(6, 2, 0) <= LINUX_VERSION_CODE || defined(EL8) || defined(EL9) +#ifdef EVDI_HAVE_DMA_BUF_VMAP_UNLOCKED #if IS_ENABLED(CONFIG_DRM_TTM_HELPER) static bool is_xe_gem_ttm_object_without_vmap(struct dma_buf *dmabuf) { @@ -370,14 +367,14 @@ int evdi_gem_vmap(struct evdi_gem_object *obj) int ret; if (evdi_drm_gem_object_use_import_attach(&obj->base)) { -#if KERNEL_VERSION(5, 18, 0) <= LINUX_VERSION_CODE || defined(EL8) || defined(EL9) +#ifdef EVDI_HAVE_IOSYS_MAP struct iosys_map map = IOSYS_MAP_INIT_VADDR(NULL); -#elif KERNEL_VERSION(5, 11, 0) <= LINUX_VERSION_CODE +#elif defined(EVDI_HAVE_DMA_BUF_MAP) struct dma_buf_map map = DMA_BUF_MAP_INIT_VADDR(NULL); #endif -#if KERNEL_VERSION(5, 11, 0) <= LINUX_VERSION_CODE || defined(EL8) -# if KERNEL_VERSION(6, 2, 0) <= LINUX_VERSION_CODE || defined(EL8) || defined(EL9) +#if defined(EVDI_HAVE_IOSYS_MAP) || defined(EVDI_HAVE_DMA_BUF_MAP) +# ifdef EVDI_HAVE_DMA_BUF_VMAP_UNLOCKED ret = evdi_dma_buf_vmap_unlocked(obj->base.import_attach->dmabuf, &map); # else ret = dma_buf_vmap(obj->base.import_attach->dmabuf, &map); @@ -407,7 +404,7 @@ int evdi_gem_vmap(struct evdi_gem_object *obj) void evdi_gem_vunmap(struct evdi_gem_object *obj) { if (evdi_drm_gem_object_use_import_attach(&obj->base)) { -#if KERNEL_VERSION(5, 18, 0) <= LINUX_VERSION_CODE || defined(EL8) || defined(EL9) +#ifdef EVDI_HAVE_IOSYS_MAP struct iosys_map map = IOSYS_MAP_INIT_VADDR(NULL); if (obj->vmap_is_iomem) @@ -415,13 +412,13 @@ void evdi_gem_vunmap(struct evdi_gem_object *obj) else iosys_map_set_vaddr(&map, obj->vmapping); -# if KERNEL_VERSION(6, 2, 0) <= LINUX_VERSION_CODE || defined(EL8) || defined(EL9) +# ifdef EVDI_HAVE_DMA_BUF_VMAP_UNLOCKED evdi_dma_buf_vunmap_unlocked(obj->base.import_attach->dmabuf, &map); # else dma_buf_vunmap(obj->base.import_attach->dmabuf, &map); # endif -#elif KERNEL_VERSION(5, 11, 0) <= LINUX_VERSION_CODE +#elif defined(EVDI_HAVE_DMA_BUF_MAP) struct dma_buf_map map; if (obj->vmap_is_iomem) @@ -503,8 +500,7 @@ int evdi_gem_mmap(struct drm_file *file, return ret; } -#if KERNEL_VERSION(5, 8, 0) <= LINUX_VERSION_CODE -#else +#ifndef EVDI_HAVE_FOR_EACH_SGTABLE_PAGE #define for_each_sgtable_page(sgt, piter, pgoffset) \ for_each_sg_page(sgt->sgl, piter, sgt->orig_nents, pgoffset) #endif @@ -547,7 +543,7 @@ evdi_prime_import_sg_table(struct drm_device *dev, return ERR_PTR(-ENOMEM); } -#if KERNEL_VERSION(5, 12, 0) <= LINUX_VERSION_CODE || defined(EL8) +#ifdef EVDI_HAVE_DRM_PRIME_SG_TO_PAGE_ARRAY drm_prime_sg_to_page_array(sg, obj->pages, npages); #else drm_prime_sg_to_page_addr_arrays(sg, obj->pages, NULL, npages); @@ -557,7 +553,7 @@ evdi_prime_import_sg_table(struct drm_device *dev, return &obj->base; } -#if KERNEL_VERSION(5, 11, 0) <= LINUX_VERSION_CODE || defined(EL8) +#if defined(EVDI_HAVE_IOSYS_MAP) || defined(EVDI_HAVE_DMA_BUF_MAP) static int evdi_prime_pin(struct drm_gem_object *obj) { struct evdi_gem_object *bo = to_evdi_bo(obj); @@ -577,7 +573,7 @@ struct sg_table *evdi_prime_get_sg_table(struct drm_gem_object *obj) { struct evdi_gem_object *bo = to_evdi_bo(obj); -#if KERNEL_VERSION(5, 10, 0) <= LINUX_VERSION_CODE || defined(EL8) +#ifdef EVDI_HAVE_DRM_PRIME_PAGES_TO_SG_DEV return drm_prime_pages_to_sg(obj->dev, bo->pages, bo->base.size >> PAGE_SHIFT); #else return drm_prime_pages_to_sg(bo->pages, bo->base.size >> PAGE_SHIFT); diff --git a/module/evdi_i2c.c b/module/evdi_i2c.c index 1616c212..633d344d 100644 --- a/module/evdi_i2c.c +++ b/module/evdi_i2c.c @@ -40,8 +40,7 @@ int evdi_i2c_add(struct i2c_adapter *adapter, struct device *parent, void *ddev) { adapter->owner = THIS_MODULE; -#if KERNEL_VERSION(6, 8, 0) <= LINUX_VERSION_CODE || defined(EL9) -#else +#ifdef EVDI_HAVE_I2C_CLASS_DDC adapter->class = I2C_CLASS_DDC; #endif adapter->algo = &dli2c_algorithm; diff --git a/module/evdi_ioc32.c b/module/evdi_ioc32.c index 896b9d40..04d9f40f 100644 --- a/module/evdi_ioc32.c +++ b/module/evdi_ioc32.c @@ -22,10 +22,9 @@ #include #include -#if KERNEL_VERSION(5, 16, 0) <= LINUX_VERSION_CODE || defined(EL8) || defined(EL9) +#ifdef EVDI_HAVE_DRM_IOCTL_COMPAT_T #include -#elif KERNEL_VERSION(5, 5, 0) <= LINUX_VERSION_CODE -#else +#elif defined(EVDI_HAVE_DRMP_H) #include #endif #include diff --git a/module/evdi_modeset.c b/module/evdi_modeset.c index fd7e31a3..e0a98270 100644 --- a/module/evdi_modeset.c +++ b/module/evdi_modeset.c @@ -12,10 +12,10 @@ */ #include -#if KERNEL_VERSION(5, 16, 0) <= LINUX_VERSION_CODE || defined(EL8) || defined(EL9) +#ifdef EVDI_HAVE_DRM_IOCTL_COMPAT_T #include #include -#elif KERNEL_VERSION(5, 0, 0) <= LINUX_VERSION_CODE +#elif defined(EVDI_HAVE_ATOMIC_DIRTYFB) #include #else #include @@ -29,7 +29,7 @@ #include "evdi_drm_drv.h" #include "evdi_cursor.h" #include "evdi_params.h" -#if KERNEL_VERSION(5, 13, 0) <= LINUX_VERSION_CODE || defined(EL8) +#ifdef EVDI_HAVE_DRM_GEM_PLANE_HELPER_PREPARE_FB #include #else #include @@ -65,14 +65,14 @@ static void evdi_crtc_set_nofb(__always_unused struct drm_crtc *crtc) static void evdi_crtc_atomic_flush( struct drm_crtc *crtc -#if KERNEL_VERSION(5, 11, 0) <= LINUX_VERSION_CODE || defined(RPI) || defined(EL8) +#ifdef EVDI_HAVE_CRTC_ATOMIC_STATE_ARG , struct drm_atomic_state *state #else , __always_unused struct drm_crtc_state *old_state #endif ) { -#if KERNEL_VERSION(5, 11, 0) <= LINUX_VERSION_CODE || defined(RPI) || defined(EL8) +#ifdef EVDI_HAVE_CRTC_ATOMIC_STATE_ARG struct drm_crtc_state *crtc_state = drm_atomic_get_new_crtc_state(state, crtc); #else struct drm_crtc_state *crtc_state = crtc->state; @@ -94,7 +94,7 @@ static void evdi_crtc_atomic_flush( crtc_state->event = NULL; } -#if KERNEL_VERSION(5, 10, 0) <= LINUX_VERSION_CODE || defined(EL8) +#ifdef EVDI_HAVE_DRM_PRIME_PAGES_TO_SG_DEV #else static void evdi_mark_full_screen_dirty(struct evdi_device *evdi) { @@ -144,10 +144,10 @@ static int evdi_crtc_cursor_set(struct drm_crtc *crtc, evdi_cursor_set(evdi->cursor, eobj, width, height, hot_x, hot_y, format, stride); - #if KERNEL_VERSION(5, 9, 0) <= LINUX_VERSION_CODE || defined(EL8) - drm_gem_object_put(obj); - #else + #ifdef EVDI_HAVE_GEM_OBJECT_PUT_UNLOCKED drm_gem_object_put_unlocked(obj); + #else + drm_gem_object_put(obj); #endif /* @@ -187,7 +187,7 @@ static struct drm_crtc_helper_funcs evdi_helper_funcs = { .disable = evdi_crtc_disable }; -#if KERNEL_VERSION(5, 11, 0) <= LINUX_VERSION_CODE || defined(RPI) || defined(EL8) +#ifdef EVDI_HAVE_CRTC_ATOMIC_STATE_ARG static int evdi_enable_vblank(__always_unused struct drm_crtc *crtc) { return 1; @@ -206,26 +206,26 @@ static const struct drm_crtc_funcs evdi_crtc_funcs = { .atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state, .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state, -#if KERNEL_VERSION(5, 10, 0) <= LINUX_VERSION_CODE || defined(EL8) +#ifdef EVDI_HAVE_DRM_PRIME_PAGES_TO_SG_DEV #else .cursor_set2 = evdi_crtc_cursor_set, .cursor_move = evdi_crtc_cursor_move, #endif -#if KERNEL_VERSION(5, 11, 0) <= LINUX_VERSION_CODE || defined(RPI) || defined(EL8) +#ifdef EVDI_HAVE_CRTC_ATOMIC_STATE_ARG .enable_vblank = evdi_enable_vblank, .disable_vblank = evdi_disable_vblank, #endif }; static void evdi_plane_atomic_update(struct drm_plane *plane, -#if KERNEL_VERSION(5, 13, 0) <= LINUX_VERSION_CODE || defined(EL8) +#ifdef EVDI_HAVE_PLANE_ATOMIC_STATE_ARG struct drm_atomic_state *atom_state #else struct drm_plane_state *old_state #endif ) { -#if KERNEL_VERSION(5, 13, 0) <= LINUX_VERSION_CODE || defined(EL8) +#ifdef EVDI_HAVE_PLANE_ATOMIC_STATE_ARG struct drm_plane_state *old_state = drm_atomic_get_old_plane_state(atom_state, plane); #else #endif @@ -234,7 +234,7 @@ static void evdi_plane_atomic_update(struct drm_plane *plane, struct evdi_painter *painter; struct drm_crtc *crtc; -#if KERNEL_VERSION(5, 0, 0) <= LINUX_VERSION_CODE || defined(EL8) +#ifdef EVDI_HAVE_ATOMIC_DIRTYFB struct drm_atomic_helper_damage_iter iter; struct drm_rect rect; struct drm_clip_rect clip_rect; @@ -282,7 +282,7 @@ static void evdi_plane_atomic_update(struct drm_plane *plane, evdi_painter_set_scanout_buffer(painter, efb); -#if KERNEL_VERSION(5, 0, 0) <= LINUX_VERSION_CODE || defined(EL8) +#ifdef EVDI_HAVE_ATOMIC_DIRTYFB state->visible = true; state->src.x1 = 0; state->src.y1 = 0; @@ -316,14 +316,14 @@ static void evdi_cursor_atomic_get_rect(struct drm_clip_rect *rect, } static void evdi_cursor_atomic_update(struct drm_plane *plane, -#if KERNEL_VERSION(5, 13, 0) <= LINUX_VERSION_CODE || defined(EL8) +#ifdef EVDI_HAVE_PLANE_ATOMIC_STATE_ARG struct drm_atomic_state *atom_state #else struct drm_plane_state *old_state #endif ) { -#if KERNEL_VERSION(5, 13, 0) <= LINUX_VERSION_CODE || defined(EL8) +#ifdef EVDI_HAVE_PLANE_ATOMIC_STATE_ARG struct drm_plane_state *old_state = drm_atomic_get_old_plane_state(atom_state, plane); #else @@ -391,7 +391,7 @@ static void evdi_cursor_atomic_update(struct drm_plane *plane, static const struct drm_plane_helper_funcs evdi_plane_helper_funcs = { .atomic_update = evdi_plane_atomic_update, -#if KERNEL_VERSION(5, 13, 0) <= LINUX_VERSION_CODE || defined(EL8) +#ifdef EVDI_HAVE_DRM_GEM_PLANE_HELPER_PREPARE_FB .prepare_fb = drm_gem_plane_helper_prepare_fb #else .prepare_fb = drm_gem_fb_prepare_fb @@ -400,7 +400,7 @@ static const struct drm_plane_helper_funcs evdi_plane_helper_funcs = { static const struct drm_plane_helper_funcs evdi_cursor_helper_funcs = { .atomic_update = evdi_cursor_atomic_update, -#if KERNEL_VERSION(5, 13, 0) <= LINUX_VERSION_CODE || defined(EL8) +#ifdef EVDI_HAVE_DRM_GEM_PLANE_HELPER_PREPARE_FB .prepare_fb = drm_gem_plane_helper_prepare_fb #else .prepare_fb = drm_gem_fb_prepare_fb @@ -476,12 +476,12 @@ static int evdi_crtc_init(struct drm_device *dev) primary_plane = evdi_create_plane(dev, DRM_PLANE_TYPE_PRIMARY, &evdi_plane_helper_funcs); -#if KERNEL_VERSION(5, 10, 0) <= LINUX_VERSION_CODE || defined(EL8) +#ifdef EVDI_HAVE_DRM_PRIME_PAGES_TO_SG_DEV cursor_plane = evdi_create_plane(dev, DRM_PLANE_TYPE_CURSOR, &evdi_cursor_helper_funcs); #endif -#if KERNEL_VERSION(5, 0, 0) <= LINUX_VERSION_CODE || defined(EL8) +#ifdef EVDI_HAVE_ATOMIC_DIRTYFB drm_plane_enable_fb_damage_clips(primary_plane); #endif @@ -499,8 +499,7 @@ static int evdi_crtc_init(struct drm_device *dev) static const struct drm_mode_config_funcs evdi_mode_funcs = { .fb_create = evdi_fb_user_fb_create, -#if KERNEL_VERSION(6, 11, 0) < LINUX_VERSION_CODE || defined(EL9) -#else +#ifdef EVDI_HAVE_OUTPUT_POLL_CHANGED .output_poll_changed = NULL, #endif .atomic_commit = drm_atomic_helper_commit, @@ -537,8 +536,7 @@ void evdi_modeset_init(struct drm_device *dev) void evdi_modeset_cleanup(__maybe_unused struct drm_device *dev) { -#if KERNEL_VERSION(5, 8, 0) <= LINUX_VERSION_CODE || defined(EL8) -#else +#ifndef EVDI_HAVE_DRMM_ADD_ACTION drm_mode_config_cleanup(dev); #endif } diff --git a/module/evdi_painter.c b/module/evdi_painter.c index 4ce51ea7..aee94512 100644 --- a/module/evdi_painter.c +++ b/module/evdi_painter.c @@ -10,13 +10,12 @@ #include "linux/thread_info.h" #include "linux/mm.h" #include -#if KERNEL_VERSION(5, 16, 0) <= LINUX_VERSION_CODE || defined(EL8) || defined(EL9) +#ifdef EVDI_HAVE_DRM_IOCTL_COMPAT_T #include #include #include #include -#elif KERNEL_VERSION(5, 5, 0) <= LINUX_VERSION_CODE -#else +#elif defined(EVDI_HAVE_DRMP_H) #include #endif #include @@ -35,18 +34,22 @@ #include #include #include -#if KERNEL_VERSION(5, 4, 0) <= LINUX_VERSION_CODE || defined(EL8) +#ifdef EVDI_HAVE_COMPILER_ATTRIBUTES_H #include #endif -/* Import of DMA_BUF namespace was reverted in EL8 */ -#if KERNEL_VERSION(6, 13, 0) <= LINUX_VERSION_CODE || defined(EL9) || defined(EL10) -MODULE_IMPORT_NS("DMA_BUF"); -#elif KERNEL_VERSION(5, 16, 0) <= LINUX_VERSION_CODE +/* + * MODULE_IMPORT_NS requires a string literal since 6.13; before that it took a + * bare token. The bare-token probe stops compiling exactly at 6.13, so prefer + * it; fall back to the string form for the macro's earlier (token) era. + */ +#ifdef EVDI_HAVE_MODULE_IMPORT_NS MODULE_IMPORT_NS(DMA_BUF); +#elif defined(EVDI_HAVE_MODULE_IMPORT_NS_STRING) +MODULE_IMPORT_NS("DMA_BUF"); #endif -#if KERNEL_VERSION(5, 1, 0) <= LINUX_VERSION_CODE || defined(EL8) +#ifdef EVDI_HAVE_DRM_PROBE_HELPER_H #include #endif @@ -117,7 +120,7 @@ struct evdi_painter { unsigned int ddcci_buffer_length; struct notifier_block vt_notifier; int fg_console; -#if KERNEL_VERSION(6, 7, 0) <= LINUX_VERSION_CODE +#ifdef EVDI_HAVE_DRM_DEBUGFS_ROOT struct dentry *debugfs_measure_copy; #endif }; @@ -173,7 +176,7 @@ static void collapse_dirty_rects(struct drm_clip_rect *rects, int *count) *count = 1; } -#if (KERNEL_VERSION(5, 18, 0) <= LINUX_VERSION_CODE || defined(EL8) || defined(EL9)) && defined(CONFIG_X86) +#if defined(EVDI_HAVE_IOSYS_MAP) && defined(CONFIG_X86) static int copy_primary_pixels_on_xe(struct evdi_framebuffer *efb, char __user *buffer, int buf_byte_stride, @@ -223,7 +226,7 @@ static int copy_primary_pixels(struct evdi_framebuffer *efb, EVDI_CHECKPT(); -#if (KERNEL_VERSION(5, 18, 0) <= LINUX_VERSION_CODE || defined(EL8) || defined(EL9)) && defined(CONFIG_X86) +#if defined(EVDI_HAVE_IOSYS_MAP) && defined(CONFIG_X86) if (efb->is_from_xe) return copy_primary_pixels_on_xe(efb, buffer, buf_byte_stride, max_x, max_y); #endif @@ -742,7 +745,10 @@ void evdi_painter_send_update_ready_if_needed(struct evdi_painter *painter) EVDI_CHECKPT(); if (painter) { painter_lock(painter); -#if KERNEL_VERSION(5, 10, 0) <= LINUX_VERSION_CODE || defined(EL8) +/* Cursor-plane behaviour from the 5.10 DRM line; no API of its own, so it is + * keyed to the same boundary as the drm_prime_pages_to_sg() signature change. + */ +#ifdef EVDI_HAVE_DRM_PRIME_PAGES_TO_SG_DEV if (painter->was_update_requested && painter->num_dirts) { #else if (painter->was_update_requested) { @@ -774,9 +780,8 @@ void evdi_painter_dpms_notify(struct evdi_painter *painter, int mode) switch (mode) { case DRM_MODE_DPMS_ON: painter->fg_console = fg_console; -#if KERNEL_VERSION(5, 4, 0) <= LINUX_VERSION_CODE || defined(EL8) +#ifdef EVDI_HAVE_FALLTHROUGH fallthrough; -#else #endif case DRM_MODE_DPMS_STANDBY: case DRM_MODE_DPMS_SUSPEND: @@ -794,13 +799,13 @@ void evdi_painter_dpms_notify(struct evdi_painter *painter, int mode) static void evdi_log_pixel_format(uint32_t pixel_format, char *buf, size_t size) { -#if KERNEL_VERSION(5, 14, 0) <= LINUX_VERSION_CODE || defined(EL8) - snprintf(buf, size, "pixel format %p4cc", &pixel_format); -#else +#ifdef EVDI_HAVE_DRM_FORMAT_NAME_BUF struct drm_format_name_buf format_name; drm_get_format_name(pixel_format, &format_name); snprintf(buf, size, "pixel format %s", format_name.str); +#else + snprintf(buf, size, "pixel format %p4cc", &pixel_format); #endif } @@ -1266,7 +1271,7 @@ static void evdi_painter_unregister_from_vt(struct evdi_painter *painter) EVDI_TEST_HOOK(evdi_testhook_painter_vt_register(&painter->vt_notifier)); } -#if KERNEL_VERSION(6, 7, 0) <= LINUX_VERSION_CODE +#ifdef EVDI_HAVE_DRM_DEBUGFS_ROOT static int evdi_painter_debugfs_measure_copy_fb(void *data, u64 val) { struct evdi_painter *painter = (struct evdi_painter *)data; @@ -1330,7 +1335,7 @@ int evdi_painter_init(struct evdi_device *dev) dev->painter->vblank = NULL; dev->painter->drm_device = dev->ddev; evdi_painter_register_to_vt(dev->painter); -#if KERNEL_VERSION(6, 7, 0) <= LINUX_VERSION_CODE +#ifdef EVDI_HAVE_DRM_DEBUGFS_ROOT dev->painter->debugfs_measure_copy = debugfs_create_file("measure_copy_fb", 0400, dev->ddev->debugfs_root, dev->painter, &evdi_painter_debug_test_ops); #endif @@ -1352,7 +1357,7 @@ void evdi_painter_cleanup(struct evdi_painter *painter) } painter_lock(painter); -#if KERNEL_VERSION(6, 7, 0) <= LINUX_VERSION_CODE +#ifdef EVDI_HAVE_DRM_DEBUGFS_ROOT debugfs_lookup_and_remove("measure_copy_fb", painter->drm_device->debugfs_root); #endif evdi_painter_unregister_from_vt(painter); diff --git a/module/evdi_platform_dev.c b/module/evdi_platform_dev.c index 35d38113..62140c5e 100644 --- a/module/evdi_platform_dev.c +++ b/module/evdi_platform_dev.c @@ -62,8 +62,7 @@ int evdi_platform_device_probe(struct platform_device *pdev) data = kzalloc_obj(*data, GFP_KERNEL); if (!data) return -ENOMEM; -#if KERNEL_VERSION(5, 9, 0) <= LINUX_VERSION_CODE || defined(EL8) -#else +#ifdef EVDI_HAVE_DEV_ARCHDATA_IOMMU #if IS_ENABLED(CONFIG_IOMMU_API) && defined(CONFIG_INTEL_IOMMU) /* Intel-IOMMU workaround: platform-bus unsupported, force ID-mapping */ #define INTEL_IOMMU_DUMMY_DOMAIN ((void *)-1) @@ -85,8 +84,7 @@ int evdi_platform_device_probe(struct platform_device *pdev) return PTR_ERR_OR_ZERO(dev); } -/* EL9 kernel removed the callback that was returning void. Do not use for EL9 */ -#if KERNEL_VERSION(6, 11, 0) <= LINUX_VERSION_CODE +#ifdef EVDI_HAVE_PLATFORM_REMOVE_VOID void evdi_platform_device_remove(struct platform_device *pdev) #else int evdi_platform_device_remove(struct platform_device *pdev) @@ -98,9 +96,7 @@ int evdi_platform_device_remove(struct platform_device *pdev) evdi_drm_device_remove(data->drm_dev); kfree(data); -/* Need to return int for EL9 kernels */ -#if KERNEL_VERSION(6, 11, 0) <= LINUX_VERSION_CODE -#else +#ifndef EVDI_HAVE_PLATFORM_REMOVE_VOID return 0; #endif } diff --git a/module/evdi_platform_dev.h b/module/evdi_platform_dev.h index 9c178ab7..73bd399d 100644 --- a/module/evdi_platform_dev.h +++ b/module/evdi_platform_dev.h @@ -32,8 +32,7 @@ struct platform_device *evdi_platform_dev_create(struct platform_device_info *in void evdi_platform_dev_destroy(struct platform_device *dev); int evdi_platform_device_probe(struct platform_device *pdev); -/* EL9 kernel removed the callback that was returning void. Do not use for EL9 */ -#if KERNEL_VERSION(6, 11, 0) <= LINUX_VERSION_CODE +#ifdef EVDI_HAVE_PLATFORM_REMOVE_VOID void evdi_platform_device_remove(struct platform_device *pdev); #else int evdi_platform_device_remove(struct platform_device *pdev); diff --git a/module/evdi_platform_drv.h b/module/evdi_platform_drv.h index 278b2010..e1134c88 100644 --- a/module/evdi_platform_drv.h +++ b/module/evdi_platform_drv.h @@ -27,8 +27,7 @@ struct platform_device_info; #define DRIVER_NAME "evdi" #define DRIVER_DESC "Extensible Virtual Display Interface" -#if KERNEL_VERSION(6, 14, 0) <= LINUX_VERSION_CODE || defined(EL9) || defined(EL10) -#else +#ifdef EVDI_HAVE_DRM_DRIVER_DATE #define DRIVER_DATE "20260428" #endif From e63ebe5d9f0cc91f19d5b443524e207b4c0fc594 Mon Sep 17 00:00:00 2001 From: Simone Caronni Date: Thu, 4 Jun 2026 10:06:04 +0200 Subject: [PATCH 2/2] el8 and aarch64 (64k) fixes --- module/Makefile | 5 ++--- module/conftest.sh | 34 +++++++++++++++++++++++++++------- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/module/Makefile b/module/Makefile index 818a60f1..174ebe5a 100644 --- a/module/Makefile +++ b/module/Makefile @@ -24,9 +24,8 @@ clean-files := evdi_detect.h evdi_detect.h.tmp # generated before any object is compiled. Cover the optional COMPAT object too. $$(addprefix $$(obj)/, $$(evdi-y) evdi_ioc32.o): $$(obj)/evdi_detect.h $$(obj)/evdi_detect.h: $$(src)/conftest.sh FORCE - $$(Q)$$(CONFIG_SHELL) $$(src)/conftest.sh "$$(CC)" \ - "$$(NOSTDINC_FLAGS) $$(LINUXINCLUDE) $$(KBUILD_CPPFLAGS) $$(KBUILD_CFLAGS) -DMODULE" \ - $$@.tmp + $$(Q)$$(CONFIG_SHELL) $$(src)/conftest.sh "$$(CC)" $$@.tmp \ + $$(NOSTDINC_FLAGS) $$(LINUXINCLUDE) $$(KBUILD_CPPFLAGS) $$(KBUILD_CFLAGS) -DMODULE $$(Q)cmp -s $$@.tmp $$@ 2>/dev/null && rm -f $$@.tmp || mv $$@.tmp $$@ endef diff --git a/module/conftest.sh b/module/conftest.sh index f33f6661..a23f0046 100755 --- a/module/conftest.sh +++ b/module/conftest.sh @@ -16,8 +16,22 @@ set -u CC="$1" -CFLAGS="$2" -OUT="$3" +OUT="$2" +shift 2 + +# The kernel cflags are passed as separate arguments (unquoted in the Makefile +# recipe) so the shell tokenises them honouring kbuild's own quoting -- e.g. on +# arm64 -DARM64_ASM_ARCH='"armv8.5-a"'. Wrapping them in one quoted argument +# would let that embedded " break the quoting and corrupt every probe. We +# requote each one here so it can be replayed verbatim through eval. +requote() { + for _a in "$@"; do + printf "'" + printf '%s' "$_a" | sed "s/'/'\\\\''/g" + printf "' " + done +} +CFLAGS=$(requote "$@") WORKDIR="$(mktemp -d)" trap 'rm -rf "$WORKDIR"' EXIT @@ -33,9 +47,14 @@ SRC="$WORKDIR/conftest.c" compile_test() { macro="$1" cat > "$SRC" - if $CC $CFLAGS -Werror=implicit-function-declaration \ - -Werror=incompatible-pointer-types \ - -fsyntax-only "$SRC" >/dev/null 2>&1; then + # CFLAGS comes from the kernel build and can contain -D options whose + # values carry embedded shell quoting (e.g. on arm64 + # -DARM64_ASM_ARCH='"armv8.5-a"'). Re-parse via eval so that quoting is + # honoured exactly as kbuild intended; expanding $CFLAGS unquoted would + # mangle it and break every probe on such architectures. + if eval "$CC $CFLAGS -Werror=implicit-function-declaration \ + -Werror=incompatible-pointer-types \ + -fsyntax-only $SRC" >/dev/null 2>&1; then printf '#define %s 1\n' "$macro" >> "$OUT" else printf '/* %s not detected */\n' "$macro" >> "$OUT" @@ -135,7 +154,8 @@ void conftest(struct drm_driver *d) { (void)d->gem_free_object; } EOF compile_test EVDI_HAVE_DRM_DRIVER_DUMB_DESTROY <<'EOF' #include -void conftest(struct drm_driver *d) { (void)d->dumb_destroy; } +#include +struct drm_driver conftest = { .dumb_destroy = drm_gem_dumb_destroy }; EOF # In 6.6 drm_gem_prime_fd_to_handle/_handle_to_fd became the implicit defaults, @@ -228,7 +248,7 @@ compile_test EVDI_HAVE_COMPILER_ATTRIBUTES_H <<'EOF' void conftest(void) { } EOF compile_test EVDI_HAVE_FALLTHROUGH <<'EOF' -#include +#include void conftest(int x) { switch (x) { case 0: fallthrough; default: break; } } EOF