From b3446bc0b6fca6cb992667f80a95f8503b6a652a Mon Sep 17 00:00:00 2001 From: Alex Waterman Date: Thu, 7 Sep 2017 15:27:55 -0700 Subject: gpu: nvgpu: Move dma_buf usage from mm_gk20a.c Move most of the dma_buf usage present in the mm_gk20a.c code out to Linux specific code and some commom/mm code. There's two primary groups of code: 1. dma_buf priv field code (for holding comptag data) 2. Comptag usage that relies on dma_buf pointers For (1) the dma_buf code was simply moved to common/linux/dmabuf.c since most of this code is clearly Linux specific. The comptag code was a bit more complicated since there is two parts to the comptag code. Firstly there's the code that manages the comptag memory. This is essentially a simple allocator. This was moved to common/mm/comptags.c since it can be shared across all chips. The second set of code is moved to common/linux/comptags.c since it is the interface between dma_bufs and the comptag memory. Two other fixes were done as well: - Add struct gk20a to the comptag allocator init so that the proper nvgpu_vzalloc() function could be used. - Add necessary includes to common/linux/vm_priv.h. JIRA NVGPU-30 JIRA NVGPU-138 Change-Id: I96c57f2763e5ebe18a2f2ee4b33e0e1a2597848c Signed-off-by: Alex Waterman Reviewed-on: https://git-master.nvidia.com/r/1566628 Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/common/linux/comptags.c | 70 +++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 drivers/gpu/nvgpu/common/linux/comptags.c (limited to 'drivers/gpu/nvgpu/common/linux/comptags.c') diff --git a/drivers/gpu/nvgpu/common/linux/comptags.c b/drivers/gpu/nvgpu/common/linux/comptags.c new file mode 100644 index 00000000..517429d8 --- /dev/null +++ b/drivers/gpu/nvgpu/common/linux/comptags.c @@ -0,0 +1,70 @@ +/* +* Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include + +#include + +#include "dmabuf.h" + +void gk20a_get_comptags(struct device *dev, struct dma_buf *dmabuf, + struct gk20a_comptags *comptags) +{ + struct gk20a_dmabuf_priv *priv = dma_buf_get_drvdata(dmabuf, dev); + + if (!comptags) + return; + + if (!priv) { + memset(comptags, 0, sizeof(*comptags)); + return; + } + + *comptags = priv->comptags; +} + +int gk20a_alloc_comptags(struct gk20a *g, + struct device *dev, + struct dma_buf *dmabuf, + struct gk20a_comptag_allocator *allocator, + u32 lines) +{ + struct gk20a_dmabuf_priv *priv = dma_buf_get_drvdata(dmabuf, dev); + u32 ctaglines_allocsize; + u32 offset; + int err; + + if (!priv) + return -ENOSYS; + + if (!lines) + return -EINVAL; + + ctaglines_allocsize = lines; + + /* store the allocator so we can use it when we free the ctags */ + priv->comptag_allocator = allocator; + err = gk20a_comptaglines_alloc(allocator, &offset, + ctaglines_allocsize); + if (err) + return err; + + priv->comptags.offset = offset; + priv->comptags.lines = lines; + priv->comptags.allocated_lines = ctaglines_allocsize; + + return 0; +} -- cgit v1.2.2