From ae64ed46c822388bbc90a6b1a42abeb5ccb8db25 Mon Sep 17 00:00:00 2001 From: Jon Hunter Date: Sun, 24 Sep 2023 15:40:41 +0100 Subject: [PATCH] gpu: host1x: Add conftest support Instead of relying on kernel version to determine if certain functions or structure are present in the kernel, use the conftest.sh script to test which functions, structures, etc are present at compile time. This is beneficial for working with 3rd party Linux kernels that may have back-ported upstream changes into their kernel and so the kernel version checks do not work. Bug 4119327 Change-Id: I56281fa5d95862338bd8a43d6e22225c27590462 Signed-off-by: Jon Hunter Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/2984422 Tested-by: mobile promotions Reviewed-by: mobile promotions --- drivers/gpu/host1x-fence/dev.c | 8 +++++--- drivers/gpu/host1x/cdma.c | 3 ++- scripts/conftest/Makefile | 1 + scripts/conftest/conftest.sh | 20 ++++++++++++++++++++ 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/host1x-fence/dev.c b/drivers/gpu/host1x-fence/dev.c index c9c2655d..ddbc7713 100644 --- a/drivers/gpu/host1x-fence/dev.c +++ b/drivers/gpu/host1x-fence/dev.c @@ -5,6 +5,8 @@ * Copyright (c) 2022-2023, NVIDIA CORPORATION. All rights reserved. */ +#include + #include #include #include @@ -415,10 +417,10 @@ static const struct file_operations dev_file_fops = { .compat_ioctl = dev_file_ioctl, }; -#if (LINUX_VERSION_CODE < KERNEL_VERSION(6, 2, 0)) -static char *host1x_fence_devnode(struct device *dev, umode_t *mode) -#else +#if defined(NV_CLASS_STRUCT_DEVNODE_HAS_CONST_DEV_ARG) /* Linux v6.2 */ static char *host1x_fence_devnode(const struct device *dev, umode_t *mode) +#else +static char *host1x_fence_devnode(struct device *dev, umode_t *mode) #endif { *mode = 0666; diff --git a/drivers/gpu/host1x/cdma.c b/drivers/gpu/host1x/cdma.c index 256fc395..59a1e18b 100644 --- a/drivers/gpu/host1x/cdma.c +++ b/drivers/gpu/host1x/cdma.c @@ -5,6 +5,7 @@ * Copyright (c) 2010-2013, NVIDIA Corporation. */ +#include #include #include @@ -106,7 +107,7 @@ static int host1x_pushbuffer_init(struct push_buffer *pb) pb->dma = iova_dma_addr(&host1x->iova, alloc); err = iommu_map(host1x->domain, pb->dma, pb->phys, size, -#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 3, 0) +#if defined(NV_IOMMU_MAP_HAS_GFP_ARG) /* Linux v6.3 */ IOMMU_READ, GFP_KERNEL); #else IOMMU_READ); diff --git a/scripts/conftest/Makefile b/scripts/conftest/Makefile index e77a07ae..28b83344 100644 --- a/scripts/conftest/Makefile +++ b/scripts/conftest/Makefile @@ -88,6 +88,7 @@ endef # provided by the module-specific Kbuild files. # +NV_CONFTEST_FUNCTION_COMPILE_TESTS += class_struct_devnode_has_const_dev_arg NV_CONFTEST_FUNCTION_COMPILE_TESTS += devm_thermal_of_zone_register NV_CONFTEST_FUNCTION_COMPILE_TESTS += drm_aperture_remove_framebuffers_has_drm_driver_arg NV_CONFTEST_FUNCTION_COMPILE_TESTS += drm_driver_struct_has_irq_enabled_arg diff --git a/scripts/conftest/conftest.sh b/scripts/conftest/conftest.sh index 74afb507..a61fea28 100755 --- a/scripts/conftest/conftest.sh +++ b/scripts/conftest/conftest.sh @@ -6293,6 +6293,26 @@ compile_test() { compile_check_conftest "$CODE" "NV_CRYPTO_PRESENT" "" "symbols" ;; + class_struct_devnode_has_const_dev_arg) + # + # Determine if the 'class' structure devnode function pointer + # has const 'struct dev' argument. + # + # Commit 43a7206b0963 ("driver core: class: make class_register() + # take a const *") updated the class_register function to take a + # const class structure in Linux v6.2. + # + CODE=" + #include + #include + #include + void conftest_class_struct_devnode_has_const_dev_arg(struct class *c) { + char *(*fn)(const struct device *dev, umode_t *mode) = c->devnode; + }" + + compile_check_conftest "$CODE" "NV_CLASS_STRUCT_DEVNODE_HAS_CONST_DEV_ARG" "" "types" + ;; + devm_thermal_of_zone_register) # # Determine whether devm_thermal_of_zone_register is present.