From 069925e74b1078ea0dbd5cb948264dd49e2ba904 Mon Sep 17 00:00:00 2001 From: Jon Hunter Date: Wed, 20 Sep 2023 10:40:54 +0100 Subject: [PATCH] video: tegra: nvmap: Make ioremap_prot depend on GENERIC_IOREMAP The function ioremap_prot() has been exported by the Linux kernel since v5.9. However, it is only available if GENERIC_IOREMAP is enabled. Since Linux v6.0, when the ARM64 __ioremap() function was removed, was GENERIC_IOREMAP enabled for ARM64 by default. Rather than depend on kernel version for selecting if ioremap_prot is used, use ioremap_prot if GENERIC_IOREMAP is enabled. This is a better solution for working with 3rd party Linux kernels that may backport upstream changes to the kernel and hence are not compatible with these existing version checks. Bug 4119327 Change-Id: I2f5f9a691c66c5fbd83d4aa51062c749d39dd447 Signed-off-by: Jon Hunter Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/2982126 Reviewed-by: Ketan Patil GVS: Gerrit_Virtual_Submit --- drivers/video/tegra/nvmap/Makefile | 6 ++++++ drivers/video/tegra/nvmap/nvmap_cache.c | 2 +- drivers/video/tegra/nvmap/nvmap_core.c | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/video/tegra/nvmap/Makefile b/drivers/video/tegra/nvmap/Makefile index d27e44fe..100c97c4 100644 --- a/drivers/video/tegra/nvmap/Makefile +++ b/drivers/video/tegra/nvmap/Makefile @@ -7,6 +7,12 @@ subdir-ccflags-y += -Werror include $(srctree.nvidia-oot)/drivers/video/tegra/nvmap/Makefile.memory.configs +# If the kernel enables CONFIG_GENERIC_IOREMAP, +# then pass this flag for building NVMAP. +ifdef CONFIG_GENERIC_IOREMAP +ccflags-y += -DCONFIG_GENERIC_IOREMAP +endif + ifeq ($(NVMAP_CONFIG), y) # Build NvMap only when NVMAP_CONFIG is set to y nvmap-y := nvmap_core.o \ diff --git a/drivers/video/tegra/nvmap/nvmap_cache.c b/drivers/video/tegra/nvmap/nvmap_cache.c index aa56b61e..937f508c 100644 --- a/drivers/video/tegra/nvmap/nvmap_cache.c +++ b/drivers/video/tegra/nvmap/nvmap_cache.c @@ -147,7 +147,7 @@ int nvmap_cache_maint_phys_range(unsigned int op, phys_addr_t pstart, phys_addr_t next = (loop + PAGE_SIZE) & PAGE_MASK; void *base; next = min(next, pend); -#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 0, 0) +#if defined(CONFIG_GENERIC_IOREMAP) io_addr = ioremap_prot(loop, PAGE_SIZE, pgprot_val(PAGE_KERNEL)); #else io_addr = __ioremap(loop, PAGE_SIZE, PG_PROT_KERNEL); diff --git a/drivers/video/tegra/nvmap/nvmap_core.c b/drivers/video/tegra/nvmap/nvmap_core.c index e54e429f..c91d26a6 100644 --- a/drivers/video/tegra/nvmap/nvmap_core.c +++ b/drivers/video/tegra/nvmap/nvmap_core.c @@ -200,7 +200,7 @@ void *__nvmap_mmap(struct nvmap_handle *h) vaddr = vmap(pages, nr_pages, VM_MAP, prot); } else { -#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 0, 0) +#if defined(CONFIG_GENERIC_IOREMAP) vaddr = ioremap_prot(h->carveout->base, adj_size, pgprot_val(prot)); #else vaddr = (__force void *)__ioremap(h->carveout->base, adj_size,