mirror of
git://nv-tegra.nvidia.com/linux-nvgpu.git
synced 2025-12-22 17:36:20 +03:00
The last major item preventing the core MM code in the nvgpu driver from being platform agnostic is the usage of Linux scattergather tables and scattergather lists. These data structures are used throughout the mapping code to handle discontiguous DMA allocations and also overloaded to represent VIDMEM allocs. The notion of a scatter gather table is crucial to a HW device that can handle discontiguous DMA. The GPU has a MMU which allows the GPU to do page gathering and present a virtually contiguous buffer to the GPU HW. As a result it makes sense for the GPU driver to use some sort of scatter gather concept so maximize memory usage efficiency. To that end this patch keeps the notion of a scatter gather list but implements it in the nvgpu common code. It is based heavily on the Linux SGL concept. It is a singly linked list of blocks - each representing a chunk of memory. To map or use a DMA allocation SW must iterate over each block in the SGL. This patch implements the most basic level of support for this data structure. There are certainly easy optimizations that could be done to speed up the current implementation. However, this patches' goal is to simply divest the core MM code from any last Linux'isms. Speed and efficiency come next. Change-Id: Icf44641db22d87fa1d003debbd9f71b605258e42 Signed-off-by: Alex Waterman <alexw@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/1530867 Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com> Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
74 lines
1.9 KiB
C
74 lines
1.9 KiB
C
/*
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include <nvgpu/kmem.h>
|
|
#include <nvgpu/nvgpu_mem.h>
|
|
|
|
#include "gk20a/gk20a.h"
|
|
|
|
struct nvgpu_mem_sgl *nvgpu_mem_sgl_next(struct nvgpu_mem_sgl *sgl)
|
|
{
|
|
return sgl->next;
|
|
}
|
|
|
|
u64 nvgpu_mem_sgl_phys(struct nvgpu_mem_sgl *sgl)
|
|
{
|
|
return sgl->phys;
|
|
}
|
|
|
|
u64 nvgpu_mem_sgl_dma(struct nvgpu_mem_sgl *sgl)
|
|
{
|
|
return sgl->dma;
|
|
}
|
|
|
|
u64 nvgpu_mem_sgl_length(struct nvgpu_mem_sgl *sgl)
|
|
{
|
|
return sgl->length;
|
|
}
|
|
|
|
/*
|
|
* This builds a GPU address for the %sgl based on whether an IOMMU is present
|
|
* or not. It also handles turning the physical address into the true GPU
|
|
* physical address that should be programmed into the page tables.
|
|
*/
|
|
u64 nvgpu_mem_sgl_gpu_addr(struct gk20a *g, struct nvgpu_mem_sgl *sgl,
|
|
struct nvgpu_gmmu_attrs *attrs)
|
|
{
|
|
if (nvgpu_mem_sgl_dma(sgl) == 0)
|
|
return g->ops.mm.gpu_phys_addr(g, attrs,
|
|
nvgpu_mem_sgl_phys(sgl));
|
|
|
|
if (nvgpu_mem_sgl_dma(sgl) == DMA_ERROR_CODE)
|
|
return 0;
|
|
|
|
return gk20a_mm_smmu_vaddr_translate(g, nvgpu_mem_sgl_dma(sgl));
|
|
}
|
|
|
|
void nvgpu_mem_sgl_free(struct gk20a *g, struct nvgpu_mem_sgl *sgl)
|
|
{
|
|
struct nvgpu_mem_sgl *next;
|
|
|
|
/*
|
|
* Free each of the elements. We expect each element to have been
|
|
* nvgpu_k[mz]alloc()ed.
|
|
*/
|
|
while (sgl) {
|
|
next = nvgpu_mem_sgl_next(sgl);
|
|
nvgpu_kfree(g, sgl);
|
|
sgl = next;
|
|
}
|
|
}
|