From 4bf47b32fcbde18222f1f82d039a08591952d35a Mon Sep 17 00:00:00 2001 From: Sagar Kamble Date: Thu, 30 Dec 2021 16:43:41 +0530 Subject: [PATCH] gpu: nvgpu: use nvmap exported APIs for dma_alloc|free_attrs on kstable To support nvmap as OOT module in kstable it implemented the APIs nvmap_dma_alloc_attrs and nvmap_dma_free_attrs to replace usage of kernel dma_alloc_attrs and dma_free_attrs. nvmap APIs have special handling for VPR carveout. Use those exported APIs in nvgpu when CONFIG_NVGPU_NVMAP_NEXT is defined. This config will be defined only for kstable builds. JIRA LS-458 Bug 200754700 Change-Id: I717aa579d29ee10c006b044f6b0fafbedc57dba8 Signed-off-by: Sagar Kamble Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2647951 (cherry picked from commit 4e227b3e804be4a17ec949717e0b44714c317f21) Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2650378 Tested-by: Omprakash Shewale Reviewed-by: Omprakash Shewale --- drivers/gpu/nvgpu/Makefile | 7 +++++++ drivers/gpu/nvgpu/Makefile.linux.configs | 7 +++++++ .../gpu/nvgpu/os/linux/platform_gk20a_tegra.c | 16 ++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/drivers/gpu/nvgpu/Makefile b/drivers/gpu/nvgpu/Makefile index f362eda8c..2c1ca89c6 100644 --- a/drivers/gpu/nvgpu/Makefile +++ b/drivers/gpu/nvgpu/Makefile @@ -42,6 +42,13 @@ ifeq ($(CONFIG_TEGRA_GK20A_NVHOST_HOST1X),y) ccflags-y += -I$(srctree.host1x)/include endif +# When using the upstream nvmap driver, the Makefile must define the +# srctree.nvmap path in order to find the necessary header files for +# the upstream nvmap driver. +ifeq ($(CONFIG_NVGPU_NVMAP_NEXT),y) +ccflags-y += -I$(srctree.nvmap)/include +endif + ifeq ($(CONFIG_NVGPU_DEBUGGER),y) ccflags-y += -DCONFIG_NVGPU_DEBUGGER ccflags-y += -DCONFIG_NVGPU_ENGINE_RESET diff --git a/drivers/gpu/nvgpu/Makefile.linux.configs b/drivers/gpu/nvgpu/Makefile.linux.configs index 5515b1b16..66137d9f3 100644 --- a/drivers/gpu/nvgpu/Makefile.linux.configs +++ b/drivers/gpu/nvgpu/Makefile.linux.configs @@ -94,6 +94,10 @@ CONFIG_TEGRA_GK20A_NVHOST := y CONFIG_TEGRA_GK20A_NVHOST_HOST1X := y endif +ifdef CONFIG_TEGRA_NVMAP_NEXT +CONFIG_NVGPU_NVMAP_NEXT := y +endif + # Enable support for GPUs on PCIe bus. ifeq ($(CONFIG_PCI),y) # Support for NVGPU DGPU @@ -216,6 +220,9 @@ endif ifeq ($(CONFIG_TEGRA_GK20A_NVHOST_HOST1X),y) ccflags-y += -DCONFIG_TEGRA_GK20A_NVHOST_HOST1X endif +ifeq ($(CONFIG_NVGPU_NVMAP_NEXT),y) +ccflags-y += -DCONFIG_NVGPU_NVMAP_NEXT +endif ifeq ($(CONFIG_NVGPU_DGPU),y) ccflags-y += -DCONFIG_NVGPU_DGPU endif diff --git a/drivers/gpu/nvgpu/os/linux/platform_gk20a_tegra.c b/drivers/gpu/nvgpu/os/linux/platform_gk20a_tegra.c index d20017d0c..de1b4e825 100644 --- a/drivers/gpu/nvgpu/os/linux/platform_gk20a_tegra.c +++ b/drivers/gpu/nvgpu/os/linux/platform_gk20a_tegra.c @@ -30,6 +30,10 @@ #include #endif +#if defined(CONFIG_NVGPU_NVMAP_NEXT) +#include +#endif + #ifdef CONFIG_NV_TEGRA_MC #include #endif /* CONFIG_NV_TEGRA_MC */ @@ -111,9 +115,15 @@ struct gk20a_emc_params { static void gk20a_tegra_secure_page_destroy(struct gk20a *g, struct secure_page_buffer *secure_buffer) { +#if defined(CONFIG_NVGPU_NVMAP_NEXT) + nvmap_dma_free_attrs(&tegra_vpr_dev, secure_buffer->size, + (void *)(uintptr_t)secure_buffer->phys, + secure_buffer->phys, DMA_ATTR_NO_KERNEL_MAPPING); +#else dma_free_attrs(&tegra_vpr_dev, secure_buffer->size, (void *)(uintptr_t)secure_buffer->phys, secure_buffer->phys, DMA_ATTR_NO_KERNEL_MAPPING); +#endif secure_buffer->destroy = NULL; } @@ -699,8 +709,14 @@ int gk20a_tegra_init_secure_alloc(struct gk20a_platform *platform) #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 8, 0) tegra_vpr_dev.coherent_dma_mask = DMA_BIT_MASK(32); #endif +#if defined(CONFIG_NVGPU_NVMAP_NEXT) + (void)nvmap_dma_alloc_attrs(&tegra_vpr_dev, + platform->secure_buffer_size, &iova, + GFP_KERNEL, DMA_ATTR_NO_KERNEL_MAPPING); +#else (void)dma_alloc_attrs(&tegra_vpr_dev, platform->secure_buffer_size, &iova, GFP_KERNEL, DMA_ATTR_NO_KERNEL_MAPPING); +#endif /* Some platforms disable VPR. In that case VPR allocations always * fail. Just disable VPR usage in nvgpu in that case. */ if (dma_mapping_error(&tegra_vpr_dev, iova)) {