From 19fb93666d675552e4bd8e4df9d2f46bdda8eeb0 Mon Sep 17 00:00:00 2001 From: Jon Hunter Date: Tue, 26 Sep 2023 11:13:28 +0100 Subject: [PATCH] platform: tegra: dce: Use conftest Instead of relying on kernel version to determine if the 'tegra_ivc' structure has a member that is of type 'struct iosys_map', add a compile time test to the conftest.sh script to determine this at compile time for the kernel being used. 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: Ia993ca9df7694347252a795c7dee1e95f2f9fa2f Signed-off-by: Jon Hunter Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/2985743 Tested-by: mobile promotions Reviewed-by: mobile promotions --- drivers/platform/tegra/dce/dce-ipc.c | 18 +++++++++--------- drivers/platform/tegra/dce/include/dce-ipc.h | 5 +++-- scripts/conftest/Makefile | 1 + scripts/conftest/conftest.sh | 19 +++++++++++++++++++ 4 files changed, 32 insertions(+), 11 deletions(-) diff --git a/drivers/platform/tegra/dce/dce-ipc.c b/drivers/platform/tegra/dce/dce-ipc.c index ad65f9b0..cd63ba45 100644 --- a/drivers/platform/tegra/dce/dce-ipc.c +++ b/drivers/platform/tegra/dce/dce-ipc.c @@ -3,7 +3,7 @@ * Copyright (c) 2019-2023, NVIDIA CORPORATION. All rights reserved. */ -#include +#include #include #include @@ -281,7 +281,7 @@ int dce_ipc_channel_init(struct tegra_dce *d, u32 ch_type) struct dce_ipc_region *r; struct dce_ipc_channel *ch; struct dce_ipc_queue_info *q_info; -#if (KERNEL_VERSION(6, 2, 0) <= LINUX_VERSION_CODE) +#if defined(NV_TEGRA_IVC_STRUCT_HAS_IOSYS_MAP) /* Linux v6.2 */ struct iosys_map rx, tx; #endif @@ -333,7 +333,7 @@ int dce_ipc_channel_init(struct tegra_dce *d, u32 ch_type) dev = dev_from_dce(d); -#if (KERNEL_VERSION(6, 2, 0) <= LINUX_VERSION_CODE) +#if defined(NV_TEGRA_IVC_STRUCT_HAS_IOSYS_MAP) /* Linux v6.2 */ iosys_map_set_vaddr(&rx, r->base + r->s_offset); iosys_map_set_vaddr(&tx, r->base + r->s_offset + q_sz); @@ -516,7 +516,7 @@ void dce_ipc_channel_reset(struct tegra_dce *d, u32 ch_type) */ static int _dce_ipc_get_next_write_buff(struct dce_ipc_channel *ch) { -#if (KERNEL_VERSION(6, 2, 0) <= LINUX_VERSION_CODE) +#if defined(NV_TEGRA_IVC_STRUCT_HAS_IOSYS_MAP) /* Linux v6.2 */ int err; err = tegra_ivc_write_get_next_frame(&ch->d_ivc, &ch->obuff); @@ -558,7 +558,7 @@ static int _dce_ipc_write_channel(struct dce_ipc_channel *ch, * of the IVC frame */ -#if (KERNEL_VERSION(6, 2, 0) <= LINUX_VERSION_CODE) +#if defined(NV_TEGRA_IVC_STRUCT_HAS_IOSYS_MAP) /* Linux v6.2 */ if ((ch->flags & DCE_IPC_CHANNEL_MSG_HEADER) != 0U) { iosys_map_wr_field(&ch->obuff, 0, struct dce_ipc_header, length, size); @@ -633,7 +633,7 @@ out: */ static int _dce_ipc_get_next_read_buff(struct dce_ipc_channel *ch) { -#if (KERNEL_VERSION(6, 2, 0) <= LINUX_VERSION_CODE) +#if defined(NV_TEGRA_IVC_STRUCT_HAS_IOSYS_MAP) /* Linux v6.2 */ int err; err = tegra_ivc_read_get_next_frame(&ch->d_ivc, &ch->ibuff); @@ -674,7 +674,7 @@ static int _dce_ipc_read_channel(struct dce_ipc_channel *ch, * Get actual length information from the top * of the IVC frame */ -#if (KERNEL_VERSION(6, 2, 0) <= LINUX_VERSION_CODE) +#if defined(NV_TEGRA_IVC_STRUCT_HAS_IOSYS_MAP) /* Linux v6.2 */ if ((ch->flags & DCE_IPC_CHANNEL_MSG_HEADER) != 0U) { iosys_map_wr_field(&ch->ibuff, 0, struct dce_ipc_header, length, size); @@ -837,7 +837,7 @@ int dce_ipc_get_region_iova_info(struct tegra_dce *d, u64 *iova, u32 *size) bool dce_ipc_is_data_available(struct tegra_dce *d, u32 ch_type) { bool ret = false; -#if (KERNEL_VERSION(6, 2, 0) <= LINUX_VERSION_CODE) +#if defined(NV_TEGRA_IVC_STRUCT_HAS_IOSYS_MAP) /* Linux v6.2 */ struct iosys_map map; #else void *frame; @@ -846,7 +846,7 @@ bool dce_ipc_is_data_available(struct tegra_dce *d, u32 ch_type) dce_mutex_lock(&ch->lock); -#if (KERNEL_VERSION(6, 2, 0) <= LINUX_VERSION_CODE) +#if defined(NV_TEGRA_IVC_STRUCT_HAS_IOSYS_MAP) /* Linux v6.2 */ if (!tegra_ivc_read_get_next_frame(&ch->d_ivc, &map)) ret = true; #else diff --git a/drivers/platform/tegra/dce/include/dce-ipc.h b/drivers/platform/tegra/dce/include/dce-ipc.h index dee9baa9..47981c80 100644 --- a/drivers/platform/tegra/dce/include/dce-ipc.h +++ b/drivers/platform/tegra/dce/include/dce-ipc.h @@ -6,7 +6,8 @@ #ifndef DCE_IPC_H #define DCE_IPC_H -#include +#include + #include #include #include @@ -121,7 +122,7 @@ struct dce_ipc_channel { u32 w_type; u32 ch_type; u32 ipc_type; -#if (KERNEL_VERSION(6, 2, 0) <= LINUX_VERSION_CODE) +#if defined(NV_TEGRA_IVC_STRUCT_HAS_IOSYS_MAP) struct iosys_map ibuff; struct iosys_map obuff; #else diff --git a/scripts/conftest/Makefile b/scripts/conftest/Makefile index 1c708552..14c2b00a 100644 --- a/scripts/conftest/Makefile +++ b/scripts/conftest/Makefile @@ -101,6 +101,7 @@ NV_CONFTEST_FUNCTION_COMPILE_TESTS += drm_mode_config_struct_has_fb_base_arg NV_CONFTEST_FUNCTION_COMPILE_TESTS += iio_dev_opaque_has_mlock NV_CONFTEST_FUNCTION_COMPILE_TESTS += iommu_map_has_gfp_arg NV_CONFTEST_FUNCTION_COMPILE_TESTS += register_shrinker_has_fmt_arg +NV_CONFTEST_FUNCTION_COMPILE_TESTS += tegra_ivc_struct_has_iosys_map NV_CONFTEST_GENERIC_COMPILE_TESTS ?= NV_CONFTEST_MACRO_COMPILE_TESTS ?= NV_CONFTEST_SYMBOL_COMPILE_TESTS ?= diff --git a/scripts/conftest/conftest.sh b/scripts/conftest/conftest.sh index 8bd93e6a..29b639fc 100755 --- a/scripts/conftest/conftest.sh +++ b/scripts/conftest/conftest.sh @@ -6544,6 +6544,25 @@ compile_test() { compile_check_conftest "$CODE" "NV_REGISTER_SHRINKER_HAS_FMT_ARG" "" "types" ;; + tegra_ivc_struct_has_iosys_map) + # + # Determine if the 'tegra_ivc' structure has the 'map' argument. + # + # Commit 4c1e0a97351a ("firmware: tegra: bpmp: Use iosys-map + # helpers") update the Tegra IVC driver to use iosys-map in Linux v6.2. + # + CODE=" + #if defined(NV_LINUX_IOSYS_MAP_H_PRESENT) + #include + #endif + #include + struct iosys_map *conftest_tegra_ivc_struct_has_iosys_map(struct tegra_ivc *ivc) { + return &ivc->rx.map; + }" + + compile_check_conftest "$CODE" "NV_TEGRA_IVC_STRUCT_HAS_IOSYS_MAP" "" "types" + ;; + # When adding a new conftest entry, please use the correct format for # specifying the relevant upstream Linux kernel commit. #