From 8428c82c816f361ce7bbb1fe4804f350b8cbea2f Mon Sep 17 00:00:00 2001 From: Alex Waterman Date: Thu, 19 Oct 2017 15:34:47 -0700 Subject: gpu: nvgpu: Add nvgpu_os_buffer Add a generic nvgpu_os_buffer type, defined by each OS, to abstract a "user" buffer. This allows the comptag interface to be used in the core code. The end goal of this patch is to allow the OS specific mapping code to call a generic mapping function that handles most of the mapping logic. The problem is a lot of the logic involves comptags which are highly dependent on the operating systems buffer management scheme. With this, each OS can implement the buffer comptag mechanics however it wishes without the core MM code caring. JIRA NVGPU-30 JIRA NVGPU-223 Change-Id: Iaf64bc52e01ef3f262b4f8f9173a84384db7dc3e Signed-off-by: Alex Waterman Reviewed-on: https://git-master.nvidia.com/r/1583986 Reviewed-by: Automatic_Commit_Validation_User GVS: Gerrit_Virtual_Submit Reviewed-by: Terje Bergstrom Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/common/linux/cde.c | 6 +++++- drivers/gpu/nvgpu/common/linux/comptags.c | 13 ++++++++----- drivers/gpu/nvgpu/common/linux/dmabuf.h | 13 ------------- drivers/gpu/nvgpu/common/linux/vm.c | 8 ++++---- 4 files changed, 17 insertions(+), 23 deletions(-) (limited to 'drivers/gpu/nvgpu/common') diff --git a/drivers/gpu/nvgpu/common/linux/cde.c b/drivers/gpu/nvgpu/common/linux/cde.c index 5063ba88..003da143 100644 --- a/drivers/gpu/nvgpu/common/linux/cde.c +++ b/drivers/gpu/nvgpu/common/linux/cde.c @@ -973,6 +973,10 @@ __releases(&l->cde_app->mutex) struct gk20a *g = &l->g; struct gk20a_cde_ctx *cde_ctx = NULL; struct gk20a_comptags comptags; + struct nvgpu_os_buffer os_buf = { + compbits_scatter_buf, + dev_from_gk20a(g) + }; u64 mapped_compbits_offset = 0; u64 compbits_size = 0; u64 mapped_scatterbuffer_offset = 0; @@ -1103,7 +1107,7 @@ __releases(&l->cde_app->mutex) } /* store source buffer compression tags */ - gk20a_get_comptags(dev_from_gk20a(g), compbits_scatter_buf, &comptags); + gk20a_get_comptags(&os_buf, &comptags); cde_ctx->surf_param_offset = comptags.offset; cde_ctx->surf_param_lines = comptags.lines; diff --git a/drivers/gpu/nvgpu/common/linux/comptags.c b/drivers/gpu/nvgpu/common/linux/comptags.c index 517429d8..f55989f7 100644 --- a/drivers/gpu/nvgpu/common/linux/comptags.c +++ b/drivers/gpu/nvgpu/common/linux/comptags.c @@ -18,12 +18,15 @@ #include +#include + #include "dmabuf.h" -void gk20a_get_comptags(struct device *dev, struct dma_buf *dmabuf, +void gk20a_get_comptags(struct nvgpu_os_buffer *buf, struct gk20a_comptags *comptags) { - struct gk20a_dmabuf_priv *priv = dma_buf_get_drvdata(dmabuf, dev); + struct gk20a_dmabuf_priv *priv = dma_buf_get_drvdata(buf->dmabuf, + buf->dev); if (!comptags) return; @@ -37,12 +40,12 @@ void gk20a_get_comptags(struct device *dev, struct dma_buf *dmabuf, } int gk20a_alloc_comptags(struct gk20a *g, - struct device *dev, - struct dma_buf *dmabuf, + struct nvgpu_os_buffer *buf, struct gk20a_comptag_allocator *allocator, u32 lines) { - struct gk20a_dmabuf_priv *priv = dma_buf_get_drvdata(dmabuf, dev); + struct gk20a_dmabuf_priv *priv = dma_buf_get_drvdata(buf->dmabuf, + buf->dev); u32 ctaglines_allocsize; u32 offset; int err; diff --git a/drivers/gpu/nvgpu/common/linux/dmabuf.h b/drivers/gpu/nvgpu/common/linux/dmabuf.h index b4b61459..8e6c139b 100644 --- a/drivers/gpu/nvgpu/common/linux/dmabuf.h +++ b/drivers/gpu/nvgpu/common/linux/dmabuf.h @@ -48,19 +48,6 @@ struct gk20a_dmabuf_priv { u64 buffer_id; }; -/* - * These are implemented in common/linux/comptags.c - these are dmabuf related - * functions though so they are defined here. They cannot be defined in - * since that file must be OS agnostic. - */ -int gk20a_alloc_comptags(struct gk20a *g, - struct device *dev, - struct dma_buf *dmabuf, - struct gk20a_comptag_allocator *allocator, - u32 lines); -void gk20a_get_comptags(struct device *dev, struct dma_buf *dmabuf, - struct gk20a_comptags *comptags); - struct sg_table *gk20a_mm_pin(struct device *dev, struct dma_buf *dmabuf); void gk20a_mm_unpin(struct device *dev, struct dma_buf *dmabuf, struct sg_table *sgt); diff --git a/drivers/gpu/nvgpu/common/linux/vm.c b/drivers/gpu/nvgpu/common/linux/vm.c index 006216c2..9178a0b0 100644 --- a/drivers/gpu/nvgpu/common/linux/vm.c +++ b/drivers/gpu/nvgpu/common/linux/vm.c @@ -165,6 +165,7 @@ int nvgpu_vm_map_linux(struct vm_gk20a *vm, struct nvgpu_sgt *nvgpu_sgt = NULL; struct sg_table *sgt; struct nvgpu_mapped_buf *mapped_buffer = NULL; + struct nvgpu_os_buffer os_buf = { dmabuf, dev }; enum nvgpu_aperture aperture; bool va_allocated = false; bool clear_ctags = false; @@ -277,11 +278,11 @@ int nvgpu_vm_map_linux(struct vm_gk20a *vm, if (!vm->enable_ctag) binfo.ctag_lines = 0; - gk20a_get_comptags(dev, dmabuf, &comptags); + gk20a_get_comptags(&os_buf, &comptags); if (binfo.ctag_lines && !comptags.lines) { /* allocate compression resources if needed */ - err = gk20a_alloc_comptags(g, dev, dmabuf, + err = gk20a_alloc_comptags(g, &os_buf, &g->gr.comp_tags, binfo.ctag_lines); if (err) { @@ -296,8 +297,7 @@ int nvgpu_vm_map_linux(struct vm_gk20a *vm, goto clean_up; } } else { - gk20a_get_comptags(dev, - dmabuf, &comptags); + gk20a_get_comptags(&os_buf, &comptags); if (g->ops.ltc.cbc_ctrl) g->ops.ltc.cbc_ctrl(g, gk20a_cbc_op_clear, -- cgit v1.2.2