summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Burnicki <martin.burnicki@meinberg.de>2024-05-13 16:22:55 +0200
committerMartin Burnicki <martin.burnicki@meinberg.de>2024-05-13 16:22:55 +0200
commit06ada9594d25ec56f21582ce55f777a7372cfca2 (patch)
tree2945bcf978da694a7d9cd97ccd17bca05a967ed4
parent67bd4d0532bcbf4b124fbdf78de9d8ff46061f85 (diff)
downloadmbgtools-lx-devel.tar.gz
mbgtools-lx-devel.zip
New 'make' parameters to override automatic defaultsdevel
KERNEL_CLASS_WITHOUT_OWNER is normally set for kernels 6.4 and newer where the 'owner' member has been removed from the device class structure. Some distros, however, may have this backported to kernels with lower numbers. KERNEL_HAS_VMA_VM_FLAGS_WRAPPER_FUNCTIONS is normally set for kernels 6.3 and newer which provide inline wrapper functions to set VMA VM flags. In earlier kernel versions these flags had to be set directly.
-rw-r--r--Makefile24
-rw-r--r--mbgclock/mbgclock_main.c28
2 files changed, 40 insertions, 12 deletions
diff --git a/Makefile b/Makefile
index cda3c37..6990c4a 100644
--- a/Makefile
+++ b/Makefile
@@ -1,12 +1,16 @@
#########################################################################
#
-# $Id: Makefile 1.40 2023/12/04 14:49:57 martin.burnicki REL_M $
+# $Id: Makefile 1.41 2024/05/13 14:11:39 martin.burnicki REL_M $
#
# Makefile for mbgtools-lx which recurses into the subdirectories.
#
# -----------------------------------------------------------------------
# $Log: Makefile $
+# Revision 1.41 2024/05/13 14:11:39 martin.burnicki
+# New make parameters KERNEL_CLASS_WITHOUT_OWNER and
+# KERNEL_HAS_VMA_VM_FLAGS_WRAPPER_FUNCTIONS to allow
+# overriding the defaults determined by the kernel driver.
# Revision 1.40 2023/12/04 14:49:57 martin.burnicki
# Better support for staged builds, and cleanup.
# Revision 1.39 2022/09/07 16:55:49 martin.burnicki
@@ -919,6 +923,10 @@ else
endif
endif
+# The definitions below can be used to override the default detection
+# of kernel API changes. Can be required, for example, to override the
+# detection by the driver code in case a distibutor broke compatibility
+# by backporting new changes to older kernels.
# The 'bool' type is supported by the vanilla Linux kernel 2.6.19 and later.
# However, looks like the RedHat folks have backported this to 2.6.18,
@@ -932,6 +940,20 @@ ifdef KERNEL_HAS_TRUE_FALSE
EXTRA_CFLAGS += -DKERNEL_HAS_TRUE_FALSE=$(KERNEL_HAS_TRUE_FALSE)
endif
+# Vanilla kernels 6.3.0 and newer provide inline functions
+# to set VMA VM flags. For older kernels, the flags usually
+# need to be set directly.
+ifdef KERNEL_HAS_VMA_VM_FLAGS_WRAPPER_FUNCTIONS
+ EXTRA_CFLAGS += -DKERNEL_HAS_VMA_VM_FLAGS_WRAPPER_FUNCTIONS=$(KERNEL_HAS_VMA_VM_FLAGS_WRAPPER_FUNCTIONS)
+endif
+
+# Vanilla kernels 6.4.0 and newer have dropped the 'owner' field in the device class.
+# to set VMA VM flags. For older kernels, the flags usually
+# need to be set directly.
+ifdef KERNEL_CLASS_WITHOUT_OWNER
+ EXTRA_CFLAGS += -DKERNEL_CLASS_WITHOUT_OWNER=$(KERNEL_CLASS_WITHOUT_OWNER)
+endif
+
# Specify our current working directory and the kernel source directory,
# and call the kernel build system.
diff --git a/mbgclock/mbgclock_main.c b/mbgclock/mbgclock_main.c
index 0d11f25..36e5f7e 100644
--- a/mbgclock/mbgclock_main.c
+++ b/mbgclock/mbgclock_main.c
@@ -1,7 +1,7 @@
/**************************************************************************
*
- * $Id: mbgclock_main.c 1.47 2024/04/26 13:43:27 martin.burnicki REL_M $
+ * $Id: mbgclock_main.c 1.48 2024/05/13 14:08:16 martin.burnicki REL_M $
*
* Description:
* Main file for the mbgclock driver for Linux which allows access to
@@ -12,6 +12,8 @@
*
* -----------------------------------------------------------------------
* $Log: mbgclock_main.c $
+ * Revision 1.48 2024/05/13 14:08:16 martin.burnicki
+ * Renamed some preprocessor symbols and allow to override the defaults.
* Revision 1.47 2024/04/26 13:43:27 martin.burnicki
* Account for changed macro names.
* Revision 1.46 2024/01/04 16:45:36 martin.burnicki
@@ -271,10 +273,12 @@
// https://lore.kernel.org/lkml/2023041123-tractor-quake-c44d@gregkh/
// The change first appeared in v6.4-rc1~115^2~102
-#if ( LINUX_VERSION_CODE >= KERNEL_VERSION( 6, 4, 0 ) )
- #define HAVE_CLASS_WITHOUT_OWNER 1
-#else
- #define HAVE_CLASS_WITHOUT_OWNER 0
+#if !defined( KERNEL_CLASS_WITHOUT_OWNER )
+ #if ( LINUX_VERSION_CODE >= KERNEL_VERSION( 6, 4, 0 ) )
+ #define KERNEL_CLASS_WITHOUT_OWNER 1
+ #else
+ #define KERNEL_CLASS_WITHOUT_OWNER 0
+ #endif
#endif
@@ -284,10 +288,12 @@
// https://lore.kernel.org/lkml/ZA7x9y60sfGOanHl@kroah.com/T/
// These wrapper functions first appeared in v6.3-rc1~113^2~116.
-#if ( LINUX_VERSION_CODE >= KERNEL_VERSION( 6, 3, 0 ) )
- #define HAVE_VMA_VM_FLAGS_WRAPPER_FUNCTIONS 1
-#else
- #define HAVE_VMA_VM_FLAGS_WRAPPER_FUNCTIONS 0
+#if !defined( KERNEL_HAS_VMA_VM_FLAGS_WRAPPER_FUNCTIONS )
+ #if ( LINUX_VERSION_CODE >= KERNEL_VERSION( 6, 3, 0 ) )
+ #define KERNEL_HAS_VMA_VM_FLAGS_WRAPPER_FUNCTIONS 1
+ #else
+ #define KERNEL_HAS_VMA_VM_FLAGS_WRAPPER_FUNCTIONS 0
+ #endif
#endif
@@ -1974,7 +1980,7 @@ int mbgclock_mmap( struct file * filp, struct vm_area_struct *vma )
vma->vm_end, vma->vm_start, (unsigned long) PAGE_SIZE );
#endif
- #if HAVE_VMA_VM_FLAGS_WRAPPER_FUNCTIONS
+ #if KERNEL_HAS_VMA_VM_FLAGS_WRAPPER_FUNCTIONS
vm_flags_set( vma, VM_IO );
#else
vma->vm_flags |= VM_IO;
@@ -2746,7 +2752,7 @@ int __init mbgclock_init_module( void )
#if _PCPS_HAVE_LINUX_CLASS
#if _PCPS_HAVE_LINUX_CLASS_CREATE
- #if HAVE_CLASS_WITHOUT_OWNER
+ #if KERNEL_CLASS_WITHOUT_OWNER
mbgclock_class = class_create( mbgclock_class_name );
#else
mbgclock_class = class_create( THIS_MODULE, mbgclock_class_name );