diff --git a/drivers/gpu/nvgpu/common/gr/global_ctx.c b/drivers/gpu/nvgpu/common/gr/global_ctx.c index fa77ae179..0b1dfdfdf 100644 --- a/drivers/gpu/nvgpu/common/gr/global_ctx.c +++ b/drivers/gpu/nvgpu/common/gr/global_ctx.c @@ -28,6 +28,8 @@ #include +#include "global_ctx_priv.h" + struct nvgpu_gr_global_ctx_buffer_desc * nvgpu_gr_global_ctx_desc_alloc(struct gk20a *g) { @@ -56,11 +58,9 @@ size_t nvgpu_gr_global_ctx_get_size(struct nvgpu_gr_global_ctx_buffer_desc *desc } static void nvgpu_gr_global_ctx_buffer_destroy(struct gk20a *g, - struct nvgpu_gr_global_ctx_buffer_desc *desc, - enum nvgpu_gr_global_ctx_index index) + struct nvgpu_mem *mem) { - nvgpu_dma_free(g, &desc[index].mem); - desc[index].destroy = NULL; + nvgpu_dma_free(g, mem); } void nvgpu_gr_global_ctx_buffer_free(struct gk20a *g, @@ -70,7 +70,8 @@ void nvgpu_gr_global_ctx_buffer_free(struct gk20a *g, for (i = 0U; i < NVGPU_GR_GLOBAL_CTX_COUNT; i++) { if (desc[i].destroy != NULL) { - desc[i].destroy(g, desc, i); + desc[i].destroy(g, &desc[i].mem); + desc[i].destroy = NULL; } } @@ -113,8 +114,9 @@ static int nvgpu_gr_global_ctx_buffer_alloc_vpr(struct gk20a *g, } if (g->ops.secure_alloc != NULL) { - err = g->ops.secure_alloc(g, &desc[index], - desc[index].size); + err = g->ops.secure_alloc(g, + &desc[index].mem, desc[index].size, + &desc[index].destroy); if (err != 0) { return err; } diff --git a/drivers/gpu/nvgpu/common/gr/global_ctx_priv.h b/drivers/gpu/nvgpu/common/gr/global_ctx_priv.h new file mode 100644 index 000000000..8980ae5f2 --- /dev/null +++ b/drivers/gpu/nvgpu/common/gr/global_ctx_priv.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#ifndef NVGPU_GR_GLOBAL_CTX_PRIV_H +#define NVGPU_GR_GLOBAL_CTX_PRIV_H + +struct nvgpu_gr_global_ctx_buffer_desc { + struct nvgpu_mem mem; + size_t size; + global_ctx_mem_destroy_fn destroy; +}; + +struct nvgpu_gr_global_ctx_local_golden_image { + u32 *context; + size_t size; +}; + +#endif /* NVGPU_GR_GLOBAL_CTX_PRIV_H */ diff --git a/drivers/gpu/nvgpu/include/nvgpu/gk20a.h b/drivers/gpu/nvgpu/include/nvgpu/gk20a.h index 9ec859ace..4a732492b 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/gk20a.h +++ b/drivers/gpu/nvgpu/include/nvgpu/gk20a.h @@ -75,6 +75,9 @@ struct nvgpu_pbdma_status_info; struct nvgpu_gr_config; enum nvgpu_nvlink_minion_dlcmd; struct nvgpu_cbc; +struct nvgpu_mem; +typedef void (*global_ctx_mem_destroy_fn)(struct gk20a *g, + struct nvgpu_mem *mem); #include #include @@ -1309,9 +1312,8 @@ struct gpu_ops { * context buffer descriptor (especially fields destroy, sgt, * size). */ - int (*secure_alloc)(struct gk20a *g, - struct nvgpu_gr_global_ctx_buffer_desc *desc, - size_t size); + int (*secure_alloc)(struct gk20a *g, struct nvgpu_mem *desc_mem, + size_t size, global_ctx_mem_destroy_fn *destroy); struct { void (*exit)(struct gk20a *g, struct nvgpu_mem *mem, struct nvgpu_sgl *sgl); diff --git a/drivers/gpu/nvgpu/include/nvgpu/gr/global_ctx.h b/drivers/gpu/nvgpu/include/nvgpu/gr/global_ctx.h index 7bb2b28ba..c879cdd40 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/gr/global_ctx.h +++ b/drivers/gpu/nvgpu/include/nvgpu/gr/global_ctx.h @@ -27,6 +27,11 @@ struct gk20a; struct nvgpu_mem; struct vm_gk20a; +struct nvgpu_gr_global_ctx_buffer_desc; +struct nvgpu_gr_global_ctx_local_golden_image; + +typedef void (*global_ctx_mem_destroy_fn)(struct gk20a *g, + struct nvgpu_mem *mem); enum nvgpu_gr_global_ctx_index { NVGPU_GR_GLOBAL_CTX_CIRCULAR = 0, @@ -41,20 +46,6 @@ enum nvgpu_gr_global_ctx_index { NVGPU_GR_GLOBAL_CTX_COUNT = 9 }; -struct nvgpu_gr_global_ctx_buffer_desc { - struct nvgpu_mem mem; - size_t size; - - void (*destroy)(struct gk20a *g, - struct nvgpu_gr_global_ctx_buffer_desc *desc, - enum nvgpu_gr_global_ctx_index index); -}; - -struct nvgpu_gr_global_ctx_local_golden_image { - u32 *context; - size_t size; -}; - struct nvgpu_gr_global_ctx_buffer_desc *nvgpu_gr_global_ctx_desc_alloc( struct gk20a *g); void nvgpu_gr_global_ctx_desc_free(struct gk20a *g, diff --git a/drivers/gpu/nvgpu/os/linux/platform_gk20a_tegra.c b/drivers/gpu/nvgpu/os/linux/platform_gk20a_tegra.c index ac5b9d7f2..bcc13c463 100644 --- a/drivers/gpu/nvgpu/os/linux/platform_gk20a_tegra.c +++ b/drivers/gpu/nvgpu/os/linux/platform_gk20a_tegra.c @@ -99,8 +99,8 @@ static void gk20a_tegra_secure_page_destroy(struct gk20a *g, } static int gk20a_tegra_secure_alloc(struct gk20a *g, - struct nvgpu_gr_global_ctx_buffer_desc *desc, - size_t size) + struct nvgpu_mem *desc_mem, size_t size, + global_ctx_mem_destroy_fn *destroy) { struct device *dev = dev_from_gk20a(g); struct gk20a_platform *platform = dev_get_drvdata(dev); @@ -111,7 +111,7 @@ static int gk20a_tegra_secure_alloc(struct gk20a *g, int err = 0; size_t aligned_size = PAGE_ALIGN(size); - if (nvgpu_mem_is_valid(&desc->mem)) + if (nvgpu_mem_is_valid(desc_mem)) return 0; /* We ran out of preallocated memory */ @@ -138,11 +138,11 @@ static int gk20a_tegra_secure_alloc(struct gk20a *g, /* This bypasses SMMU for VPR during gmmu_map. */ sg_dma_address(sgt->sgl) = 0; - desc->destroy = NULL; + *destroy = NULL; - desc->mem.priv.sgt = sgt; - desc->mem.size = size; - desc->mem.aperture = APERTURE_SYSMEM; + desc_mem->priv.sgt = sgt; + desc_mem->size = size; + desc_mem->aperture = APERTURE_SYSMEM; secure_buffer->used += aligned_size;