From 6af855f1d00bc805c59bc14b001b70828d2687a2 Mon Sep 17 00:00:00 2001 From: Ketan Patil Date: Thu, 28 Nov 2024 09:19:52 +0000 Subject: [PATCH] video: tegra: nvmap: Don't expose non-embedded code in embedded builds The following functions are exported from nvmap code and being used by nvgpu in non-DriveOS code like L4T. Hence we should not include these functions in embedded builds. - nvmap_get_vpr_dev - nvmap_get_vpr1_dev The following functions get used in DriveOS as well by nvmap, but no need to export to nvgpu, as they are not supposed to be used on DrivOS by other modules. Hence do not export this in embedded builds. - nvmap_dma_alloc_attrs - nvmap_dma_free_attrs In order to achieve this, define a new config file for embedded-linux and define config and ccflag which can be used in any OOT driver to differentiate between embedded-linux and non embedded-linux builds. JIRA TMM-5842 Change-Id: Ic52106709723910e03362977472fb3597dc255f0 Signed-off-by: Ketan Patil Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/3258866 Reviewed-by: Laxman Dewangan GVS: buildbot_gerritrpt --- configs/Makefile.config.embedded-linux | 7 +++++++ .../tegra/nvmap/include/linux/nvmap_exports.h | 3 +++ drivers/video/tegra/nvmap/nvmap_heap.c | 15 +++++++++++++++ drivers/video/tegra/nvmap/nvmap_init.c | 2 ++ 4 files changed, 27 insertions(+) create mode 100644 configs/Makefile.config.embedded-linux diff --git a/configs/Makefile.config.embedded-linux b/configs/Makefile.config.embedded-linux new file mode 100644 index 00000000..e79906e9 --- /dev/null +++ b/configs/Makefile.config.embedded-linux @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0-only +# SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved. + +# Embedded linux specific environment variables to distinguish between embedded-linux and non embedded-linux builds. + +export NV_OOT_NVMAP_IN_EMBEDDED_LINUX=y +subdir-ccflags-y += -DNV_CONFIG_NVMAP_IN_EMBEDDED_LINUX \ No newline at end of file diff --git a/drivers/video/tegra/nvmap/include/linux/nvmap_exports.h b/drivers/video/tegra/nvmap/include/linux/nvmap_exports.h index ec611948..96c2a883 100644 --- a/drivers/video/tegra/nvmap/include/linux/nvmap_exports.h +++ b/drivers/video/tegra/nvmap/include/linux/nvmap_exports.h @@ -5,9 +5,11 @@ #ifndef __NVMAP_EXPORTS_H #define __NVMAP_EXPORTS_H +#ifndef NV_CONFIG_NVMAP_IN_EMBEDDED_LINUX void *nvmap_dma_alloc_attrs(struct device *dev, size_t size, dma_addr_t *dma_handle, gfp_t flag, unsigned long attrs); + void nvmap_dma_free_attrs(struct device *dev, size_t size, void *cpu_addr, dma_addr_t dma_handle, unsigned long attrs); @@ -15,4 +17,5 @@ struct device *nvmap_get_vpr_dev(void); struct device *nvmap_get_vpr1_dev(void); +#endif /* !NV_CONFIG_NVMAP_IN_EMBEDDED_LINUX */ #endif /* __NVMAP_EXPORTS_H */ diff --git a/drivers/video/tegra/nvmap/nvmap_heap.c b/drivers/video/tegra/nvmap/nvmap_heap.c index 42e5308b..24927de3 100644 --- a/drivers/video/tegra/nvmap/nvmap_heap.c +++ b/drivers/video/tegra/nvmap/nvmap_heap.c @@ -476,9 +476,15 @@ err: return NULL; } +#ifndef NV_CONFIG_NVMAP_IN_EMBEDDED_LINUX void *nvmap_dma_alloc_attrs(struct device *dev, size_t size, dma_addr_t *dma_handle, gfp_t flag, unsigned long attrs) +#else +static void *nvmap_dma_alloc_attrs(struct device *dev, size_t size, + dma_addr_t *dma_handle, + gfp_t flag, unsigned long attrs) +#endif /* NV_CONFIG_NVMAP_IN_EMBEDDED_LINUX */ { struct dma_coherent_mem_replica *mem; @@ -492,7 +498,9 @@ void *nvmap_dma_alloc_attrs(struct device *dev, size_t size, return __nvmap_dma_alloc_from_coherent(dev, mem, size, dma_handle, attrs, 0); } +#ifndef NV_CONFIG_NVMAP_IN_EMBEDDED_LINUX EXPORT_SYMBOL(nvmap_dma_alloc_attrs); +#endif /* !NV_CONFIG_NVMAP_IN_EMBEDDED_LINUX */ #ifdef CONFIG_TEGRA_VIRTUALIZATION static void *nvmap_dma_mark_declared_memory_occupied(struct device *dev, @@ -578,8 +586,13 @@ static phys_addr_t nvmap_alloc_mem(struct nvmap_heap *h, size_t len, return pa; } +#ifndef NV_CONFIG_NVMAP_IN_EMBEDDED_LINUX void nvmap_dma_free_attrs(struct device *dev, size_t size, void *cpu_addr, dma_addr_t dma_handle, unsigned long attrs) +#else +static void nvmap_dma_free_attrs(struct device *dev, size_t size, void *cpu_addr, + dma_addr_t dma_handle, unsigned long attrs) +#endif /* NV_CONFIG_NVMAP_IN_EMBEDDED_LINUX */ { void *mem_addr; unsigned long flags; @@ -629,7 +642,9 @@ void nvmap_dma_free_attrs(struct device *dev, size_t size, void *cpu_addr, spin_unlock_irqrestore(&mem->spinlock, flags); } } +#ifndef NV_CONFIG_NVMAP_IN_EMBEDDED_LINUX EXPORT_SYMBOL(nvmap_dma_free_attrs); +#endif /* !NV_CONFIG_NVMAP_IN_EMBEDDED_LINUX */ static void nvmap_free_mem(struct nvmap_heap *h, phys_addr_t base, size_t len) diff --git a/drivers/video/tegra/nvmap/nvmap_init.c b/drivers/video/tegra/nvmap/nvmap_init.c index 414b0cf5..6ccabf34 100644 --- a/drivers/video/tegra/nvmap/nvmap_init.c +++ b/drivers/video/tegra/nvmap/nvmap_init.c @@ -255,6 +255,7 @@ static int __nvmap_init_dt(struct platform_device *pdev) return 0; } +#ifndef NV_CONFIG_NVMAP_IN_EMBEDDED_LINUX struct device *nvmap_get_vpr_dev(void) { struct device_node *dn = of_find_compatible_node(NULL, NULL, "nvidia,vpr-carveout"); @@ -288,6 +289,7 @@ struct device *nvmap_get_vpr1_dev(void) return &tegra_vpr1_dev; } EXPORT_SYMBOL(nvmap_get_vpr1_dev); +#endif /* !NV_CONFIG_NVMAP_IN_EMBEDDED_LINUX */ static int __init nvmap_co_device_init(struct reserved_mem *rmem, struct device *dev)