From 0a8d8b47c79e53a6042404467d61af44424ad6cd Mon Sep 17 00:00:00 2001 From: Jon Hunter Date: Wed, 4 Dec 2024 10:40:41 +0000 Subject: [PATCH] drivers: gpu: Fix IOMMU support for Linux v6.13 In Linux v6.13, commit f6440fcc9c7b ("iommu: Remove iommu_domain_alloc()") removed iommu_domain_alloc() and was replaced by iommu_paging_domain_alloc(). Use conftest to detect if the function iommu_paging_domain_alloc() is supported by the kernel and update the Tegra DRM and Host1x drivers accordingly. Bug 4991705 Change-Id: I86221d96232396fdb6bdccf40c412e029881c513 Signed-off-by: Jon Hunter Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/3261695 (cherry picked from commit e374ac996dceee884296c9f1e53fdd0f281b3e0c) Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/3499750 Reviewed-by: Brad Griffis Tested-by: Brad Griffis GVS: buildbot_gerritrpt --- drivers/gpu/drm/tegra/drm.c | 8 ++++++++ drivers/gpu/host1x/dev.c | 7 +++++++ scripts/conftest/Makefile | 1 + scripts/conftest/conftest.sh | 17 +++++++++++++++++ 4 files changed, 33 insertions(+) diff --git a/drivers/gpu/drm/tegra/drm.c b/drivers/gpu/drm/tegra/drm.c index df7e33d3..605bbe68 100644 --- a/drivers/gpu/drm/tegra/drm.c +++ b/drivers/gpu/drm/tegra/drm.c @@ -1182,6 +1182,9 @@ static bool host1x_drm_wants_iommu(struct host1x_device *dev) static int host1x_drm_probe(struct host1x_device *dev) { +#if defined(NV_IOMMU_PAGING_DOMAIN_ALLOC_PRESENT) /* Linux v6.11 */ + struct device *dma_dev = dev->dev.parent; +#endif struct tegra_drm *tegra; struct drm_device *drm; int err; @@ -1196,8 +1199,13 @@ static int host1x_drm_probe(struct host1x_device *dev) goto put; } +#if defined(NV_IOMMU_PAGING_DOMAIN_ALLOC_PRESENT) /* Linux v6.11 */ + if (host1x_drm_wants_iommu(dev) && device_iommu_mapped(dma_dev)) { + tegra->domain = iommu_paging_domain_alloc(dma_dev); +#else if (host1x_drm_wants_iommu(dev) && iommu_present(&platform_bus_type)) { tegra->domain = iommu_domain_alloc(&platform_bus_type); +#endif if (!tegra->domain) { err = -ENOMEM; goto free; diff --git a/drivers/gpu/host1x/dev.c b/drivers/gpu/host1x/dev.c index 452dd79d..40338da6 100644 --- a/drivers/gpu/host1x/dev.c +++ b/drivers/gpu/host1x/dev.c @@ -620,9 +620,16 @@ static struct iommu_domain *host1x_iommu_attach(struct host1x *host) if (err < 0) goto put_group; +#if defined(NV_IOMMU_PAGING_DOMAIN_ALLOC_PRESENT) /* Linux v6.11 */ + host->domain = iommu_paging_domain_alloc(host->dev); + if (IS_ERR(host->domain)) { + err = PTR_ERR(host->domain); + host->domain = NULL; +#else host->domain = iommu_domain_alloc(&platform_bus_type); if (!host->domain) { err = -ENOMEM; +#endif goto put_cache; } diff --git a/scripts/conftest/Makefile b/scripts/conftest/Makefile index 66ddd78a..49c4475a 100644 --- a/scripts/conftest/Makefile +++ b/scripts/conftest/Makefile @@ -140,6 +140,7 @@ NV_CONFTEST_FUNCTION_COMPILE_TESTS += i2c_driver_struct_remove_return_type_int NV_CONFTEST_FUNCTION_COMPILE_TESTS += i2c_mux_add_adapter_has_no_class_argument 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 += iommu_paging_domain_alloc NV_CONFTEST_FUNCTION_COMPILE_TESTS += irq_get_nr_irqs NV_CONFTEST_FUNCTION_COMPILE_TESTS += kthread_complete_and_exit NV_CONFTEST_FUNCTION_COMPILE_TESTS += media_entity_remote_pad diff --git a/scripts/conftest/conftest.sh b/scripts/conftest/conftest.sh index bd13fb02..4b22822e 100755 --- a/scripts/conftest/conftest.sh +++ b/scripts/conftest/conftest.sh @@ -7437,6 +7437,23 @@ compile_test() { compile_check_conftest "$CODE" "NV_NETIF_NAPI_ADD_WEIGHT_PRESENT" "" "functions" ;; + iommu_paging_domain_alloc) + # + # Determine if iommu_paging_domain_alloc() function is present + # + # Added by commit a27bf2743cb8 ("iommu: Add iommu_paging_domain_alloc() + # interface") in Linux v6.11. + # + CODE=" + #include + void conftest_iommu_paging_domain_alloc(void) + { + iommu_paging_domain_alloc(); + } + " + compile_check_conftest "$CODE" "NV_IOMMU_PAGING_DOMAIN_ALLOC_PRESENT" "" "functions" + ;; + iommu_map_has_gfp_arg) # # Determine if iommu_map() has 'gfp' argument.